feat: page console history across compaction
This commit is contained in:
@@ -1188,6 +1188,19 @@ pub trait WorkspaceWorkerRuntime: Send + Sync {
|
||||
})
|
||||
}
|
||||
|
||||
fn worker_session_history(
|
||||
&self,
|
||||
_workspace_id: &str,
|
||||
_worker_ref: &EmbeddedWorkerRef,
|
||||
_cursor: Option<String>,
|
||||
_limit: Option<usize>,
|
||||
) -> Result<runtime_api::WorkerSessionHistoryAvailability, String> {
|
||||
Ok(runtime_api::WorkerSessionHistoryAvailability::Unavailable {
|
||||
reason: runtime_api::WorkerSessionHistoryUnavailableReason::Unsupported,
|
||||
message: "session history paging is not supported by this Runtime".to_string(),
|
||||
})
|
||||
}
|
||||
|
||||
fn observation_source(
|
||||
&self,
|
||||
_worker_id: &str,
|
||||
@@ -2017,6 +2030,31 @@ impl RuntimeRegistry {
|
||||
})
|
||||
}
|
||||
|
||||
pub fn worker_session_history(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
worker: &RuntimeWorkerRef,
|
||||
cursor: Option<String>,
|
||||
limit: Option<usize>,
|
||||
) -> Result<runtime_api::WorkerSessionHistoryAvailability, RuntimeRegistryError> {
|
||||
validate_backend_identifier("runtime_id", &worker.runtime_id)?;
|
||||
validate_backend_identifier("worker_id", &worker.worker_id)?;
|
||||
let runtime = self.runtime(&worker.runtime_id)?;
|
||||
let worker_ref =
|
||||
EmbeddedWorkerRef::new(EmbeddedWorkerId::parse(&worker.worker_id).ok_or_else(
|
||||
|| RuntimeRegistryError::UnknownWorker {
|
||||
worker: worker.clone(),
|
||||
},
|
||||
)?);
|
||||
runtime
|
||||
.worker_session_history(workspace_id, &worker_ref, cursor, limit)
|
||||
.map_err(|message| RuntimeRegistryError::RuntimeOperationFailed {
|
||||
runtime_id: worker.runtime_id.clone(),
|
||||
code: "worker_session_history_failed".to_string(),
|
||||
message,
|
||||
})
|
||||
}
|
||||
|
||||
pub fn observation_source(
|
||||
&self,
|
||||
worker: &RuntimeWorkerRef,
|
||||
@@ -2909,6 +2947,19 @@ impl WorkspaceWorkerRuntime for EmbeddedWorkerRuntime {
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn worker_session_history(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
worker_ref: &EmbeddedWorkerRef,
|
||||
cursor: Option<String>,
|
||||
limit: Option<usize>,
|
||||
) -> Result<runtime_api::WorkerSessionHistoryAvailability, String> {
|
||||
let scope = RuntimeWorkspaceScope::new(workspace_id, "embedded-backend");
|
||||
self.runtime
|
||||
.worker_session_history_scoped(&scope, worker_ref, cursor, limit)
|
||||
.map_err(|error| error.to_string())
|
||||
}
|
||||
|
||||
fn observation_source(
|
||||
&self,
|
||||
worker_id: &str,
|
||||
@@ -4924,6 +4975,27 @@ impl WorkspaceWorkerRuntime for RemoteWorkerRuntime {
|
||||
.map_err(|diagnostic| diagnostic.message)
|
||||
}
|
||||
|
||||
fn worker_session_history(
|
||||
&self,
|
||||
workspace_id: &str,
|
||||
worker_ref: &EmbeddedWorkerRef,
|
||||
cursor: Option<String>,
|
||||
limit: Option<usize>,
|
||||
) -> Result<runtime_api::WorkerSessionHistoryAvailability, String> {
|
||||
let worker_id = worker_ref.worker_id.to_string();
|
||||
let request = runtime_api::WorkerSessionHistoryRequest {
|
||||
workspace_id: workspace_id.to_string(),
|
||||
cursor,
|
||||
limit,
|
||||
};
|
||||
self.run_runtime_api(
|
||||
self.request_timeout,
|
||||
MAX_REMOTE_RUNTIME_RESPONSE_BYTES,
|
||||
move |client| async move { client.worker_session_history(worker_id, request).await },
|
||||
)
|
||||
.map_err(|diagnostic| diagnostic.message)
|
||||
}
|
||||
|
||||
fn observation_source(
|
||||
&self,
|
||||
worker_id: &str,
|
||||
|
||||
@@ -4584,6 +4584,9 @@ fn generated_workspace_contract_router(service: ServerApiContractService) -> Rou
|
||||
.merge(server_api::server_api_axum::skill_get(service.clone()))
|
||||
.merge(server_api::server_api_axum::skill_activate(service.clone()))
|
||||
.merge(server_api::server_api_axum::worker_session(service.clone()))
|
||||
.merge(server_api::server_api_axum::worker_session_history(
|
||||
service.clone(),
|
||||
))
|
||||
.merge(server_api::server_api_axum::repository_list(
|
||||
service.clone(),
|
||||
))
|
||||
@@ -6248,6 +6251,50 @@ impl server_api::ServerApi for ServerApiContractService {
|
||||
})
|
||||
}
|
||||
|
||||
async fn worker_session_history(
|
||||
&self,
|
||||
workspace_id: String,
|
||||
runtime_id: String,
|
||||
worker_id: String,
|
||||
query: server_api::WorkspaceWorkerSessionHistoryQuery,
|
||||
) -> std::result::Result<
|
||||
server_api::WorkspaceWorkerSessionHistoryResponse,
|
||||
server_api::ServerApiError,
|
||||
> {
|
||||
let api = self.workspace_api().map_err(|_| {
|
||||
runtime_api::RuntimeApiError::new(
|
||||
StatusCode::NOT_FOUND.as_u16(),
|
||||
"workspace_not_found",
|
||||
"Workspace was not found",
|
||||
)
|
||||
})?;
|
||||
if workspace_id != api.config.workspace_id {
|
||||
return Err(runtime_api::RuntimeApiError::new(
|
||||
StatusCode::NOT_FOUND.as_u16(),
|
||||
"workspace_not_found",
|
||||
"Workspace was not found",
|
||||
));
|
||||
}
|
||||
let worker = RuntimeWorkerRef::new(runtime_id.clone(), worker_id.clone());
|
||||
let observation = api
|
||||
.runtime
|
||||
.worker_session_history(&workspace_id, &worker, query.cursor, query.limit)
|
||||
.map_err(|_error| {
|
||||
runtime_api::RuntimeApiError::new(
|
||||
StatusCode::BAD_GATEWAY.as_u16(),
|
||||
"worker_session_history_failed",
|
||||
"Worker Session history request failed",
|
||||
)
|
||||
})?;
|
||||
Ok(server_api::WorkspaceWorkerSessionHistoryResponse {
|
||||
subject: server_api::WorkspaceWorkerSubject::RuntimeWorker {
|
||||
runtime_id,
|
||||
worker_id,
|
||||
},
|
||||
observation,
|
||||
})
|
||||
}
|
||||
|
||||
async fn workspace_worker_list_alias(
|
||||
&self,
|
||||
) -> std::result::Result<server_api::WorkerListResponse, server_api::RepositoryApiError> {
|
||||
|
||||
Reference in New Issue
Block a user