mirror of
https://github.com/block/goose.git
synced 2026-07-17 12:56:20 +02:00
fix(acp): Use ACP schema types for session/list (#7409)
Signed-off-by: rabi <ramishra@redhat.com>
This commit is contained in:
@@ -23,7 +23,7 @@ goose = { path = "../goose" }
|
||||
goose-mcp = { path = "../goose-mcp" }
|
||||
rmcp = { workspace = true }
|
||||
sacp = "10.1.0"
|
||||
agent-client-protocol-schema = { version = "0.10", features = ["unstable_session_model"] }
|
||||
agent-client-protocol-schema = { version = "0.10", features = ["unstable_session_model", "unstable_session_list"] }
|
||||
anyhow = { workspace = true }
|
||||
tokio = { workspace = true }
|
||||
tokio-util = { workspace = true, features = ["compat", "rt"] }
|
||||
|
||||
@@ -82,12 +82,6 @@ pub struct GetSessionResponse {
|
||||
pub session: serde_json::Value,
|
||||
}
|
||||
|
||||
/// List all sessions.
|
||||
#[derive(Debug, Serialize, JsonSchema)]
|
||||
pub struct ListSessionsResponse {
|
||||
pub sessions: Vec<serde_json::Value>,
|
||||
}
|
||||
|
||||
/// Delete a session.
|
||||
#[derive(Debug, Deserialize, JsonSchema)]
|
||||
pub struct DeleteSessionRequest {
|
||||
|
||||
@@ -24,10 +24,11 @@ use sacp::schema::{
|
||||
AgentCapabilities, AuthMethod, AuthenticateRequest, AuthenticateResponse, BlobResourceContents,
|
||||
CancelNotification, Content, ContentBlock, ContentChunk, EmbeddedResource,
|
||||
EmbeddedResourceResource, ImageContent, InitializeRequest, InitializeResponse,
|
||||
LoadSessionRequest, LoadSessionResponse, McpCapabilities, McpServer, ModelId, ModelInfo,
|
||||
NewSessionRequest, NewSessionResponse, PermissionOption, PermissionOptionKind,
|
||||
PromptCapabilities, PromptRequest, PromptResponse, RequestPermissionOutcome,
|
||||
RequestPermissionRequest, ResourceLink, SessionId, SessionModelState, SessionNotification,
|
||||
ListSessionsResponse, LoadSessionRequest, LoadSessionResponse, McpCapabilities, McpServer,
|
||||
ModelId, ModelInfo, NewSessionRequest, NewSessionResponse, PermissionOption,
|
||||
PermissionOptionKind, PromptCapabilities, PromptRequest, PromptResponse,
|
||||
RequestPermissionOutcome, RequestPermissionRequest, ResourceLink, SessionCapabilities,
|
||||
SessionId, SessionInfo, SessionListCapabilities, SessionModelState, SessionNotification,
|
||||
SessionUpdate, SetSessionModelRequest, SetSessionModelResponse, StopReason, TextContent,
|
||||
TextResourceContents, ToolCall, ToolCallContent, ToolCallId, ToolCallLocation, ToolCallStatus,
|
||||
ToolCallUpdate, ToolCallUpdateFields, ToolKind,
|
||||
@@ -664,6 +665,7 @@ impl GooseAcpAgent {
|
||||
|
||||
let capabilities = AgentCapabilities::new()
|
||||
.load_session(true)
|
||||
.session_capabilities(SessionCapabilities::new().list(SessionListCapabilities::new()))
|
||||
.prompt_capabilities(
|
||||
PromptCapabilities::new()
|
||||
.image(true)
|
||||
@@ -1097,14 +1099,15 @@ impl GooseAcpAgent {
|
||||
.list_sessions()
|
||||
.await
|
||||
.map_err(|e| sacp::Error::internal_error().data(e.to_string()))?;
|
||||
let sessions_json = sessions
|
||||
let session_infos: Vec<SessionInfo> = sessions
|
||||
.into_iter()
|
||||
.map(|s| serde_json::to_value(&s))
|
||||
.collect::<Result<Vec<_>, _>>()
|
||||
.map_err(|e| sacp::Error::internal_error().data(e.to_string()))?;
|
||||
Ok(ListSessionsResponse {
|
||||
sessions: sessions_json,
|
||||
})
|
||||
.map(|s| {
|
||||
SessionInfo::new(SessionId::new(s.id), s.working_dir)
|
||||
.title(s.name)
|
||||
.updated_at(s.updated_at.to_rfc3339())
|
||||
})
|
||||
.collect();
|
||||
Ok(ListSessionsResponse::new(session_infos))
|
||||
}
|
||||
|
||||
#[custom_method("session/get")]
|
||||
@@ -1286,6 +1289,14 @@ impl JrMessageHandler for GooseAcpHandler {
|
||||
request_cx.respond(json)?;
|
||||
Ok(())
|
||||
}
|
||||
MessageCx::Request(req, request_cx) if req.method == "session/list" => {
|
||||
let resp = agent.on_list_sessions().await?;
|
||||
let json = serde_json::to_value(resp).map_err(|e| {
|
||||
sacp::Error::internal_error().data(e.to_string())
|
||||
})?;
|
||||
request_cx.respond(json)?;
|
||||
Ok(())
|
||||
}
|
||||
MessageCx::Request(req, request_cx) if req.method.starts_with('_') => {
|
||||
match agent.handle_custom_request(&req.method, req.params).await {
|
||||
Ok(json) => request_cx.respond(json)?,
|
||||
|
||||
Reference in New Issue
Block a user