feat: enrich page ai ACP runtime UI

This commit is contained in:
lix-2026
2026-05-17 21:21:59 +08:00
parent bb2f190f50
commit ee0643041a
5 changed files with 282 additions and 30 deletions
+56 -2
View File
@@ -194,25 +194,38 @@ pub fn acp_event_to_sse(event: AcpSessionEvent) -> Option<SseEvent> {
tool_call_id,
title,
kind,
..
status,
raw_input,
} => Some(SseEvent {
event: "tool.started".into(),
data: json!({
"tool": title,
"toolCallId": tool_call_id,
"kind": kind,
"status": status,
"input": raw_input,
}),
}),
AcpSessionEvent::ToolCallUpdate {
tool_call_id,
status,
content,
} => {
let error = status == crate::acp_types::ToolCallStatus::Failed;
let event = if error {
"tool.failed"
} else if status == crate::acp_types::ToolCallStatus::Completed {
"tool.completed"
} else {
"tool.started"
};
Some(SseEvent {
event: "tool.completed".into(),
event: event.into(),
data: json!({
"toolCallId": tool_call_id,
"status": status,
"error": error,
"output": content,
}),
})
}
@@ -278,4 +291,45 @@ mod tests {
assert_eq!(sse.event, "thought.delta");
assert_eq!(sse.data["delta"], "internal reasoning");
}
#[test]
fn acp_tool_events_keep_detail_for_collapsible_ui() {
let started = acp_event_to_sse(AcpSessionEvent::ToolCall {
tool_call_id: "tool_1".into(),
title: "mnote.page.get".into(),
kind: "read".into(),
status: crate::acp_types::ToolCallStatus::InProgress,
raw_input: Some(json!({"documentId": "doc_1", "includeBody": true})),
})
.expect("tool start");
assert_eq!(started.event, "tool.started");
assert_eq!(started.data["tool"], "mnote.page.get");
assert_eq!(started.data["status"], "in_progress");
assert_eq!(started.data["input"]["documentId"], "doc_1");
let completed = acp_event_to_sse(AcpSessionEvent::ToolCallUpdate {
tool_call_id: "tool_1".into(),
status: crate::acp_types::ToolCallStatus::Completed,
content: Some(vec![crate::acp_types::ContentBlockWrapper {
wrapper_type: "content".into(),
content: crate::acp_types::TextContent {
content_type: "text".into(),
text: "读取完成".into(),
},
}]),
})
.expect("tool complete");
assert_eq!(completed.event, "tool.completed");
assert_eq!(completed.data["status"], "completed");
assert_eq!(completed.data["output"][0]["content"]["text"], "读取完成");
let running = acp_event_to_sse(AcpSessionEvent::ToolCallUpdate {
tool_call_id: "tool_1".into(),
status: crate::acp_types::ToolCallStatus::InProgress,
content: None,
})
.expect("tool running");
assert_eq!(running.event, "tool.started");
assert_eq!(running.data["status"], "in_progress");
}
}