@1agents/acp-service 0.5.0 → 0.5.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -104,12 +104,19 @@ function envelope(value) {
104
104
  const { event: _event, ...fields } = value;
105
105
  return { [NS]: fields };
106
106
  }
107
- function updateFor(event) {
107
+ function updateFor(event, toolUpdate = false) {
108
108
  const common = { _meta: envelope(event) };
109
109
  switch (event.event) {
110
110
  case 'text_delta': return { ...common, sessionUpdate: event.type === 'thought' ? 'agent_thought_chunk' : 'agent_message_chunk', content: { type: 'text', text: event.text || '' } };
111
- case 'tool_call': return { ...common, sessionUpdate: 'tool_call', toolCallId: event.toolCallId, title: event.toolName || 'Tool', status: event.status || 'pending', kind: event.kind, rawInput: event.arguments, content: event.content, locations: event.locations };
112
- case 'tool_result': return { ...common, sessionUpdate: 'tool_call_update', toolCallId: event.toolCallId, status: event.isError ? 'failed' : 'completed', rawOutput: event.text, content: [{ type: 'content', content: { type: 'text', text: event.text || '' } }] };
111
+ case 'tool_call': {
112
+ const fields = { ...common, toolCallId: event.toolCallId, title: event.title ?? event.toolName, status: event.status,
113
+ kind: event.kind, rawInput: event.arguments, rawOutput: event.rawOutput, content: event.content, locations: event.locations };
114
+ return toolUpdate ? { ...fields, sessionUpdate: 'tool_call_update' }
115
+ : { ...fields, sessionUpdate: 'tool_call', title: fields.title ?? 'Tool', status: fields.status ?? 'pending' };
116
+ }
117
+ case 'tool_result': return { ...common, sessionUpdate: 'tool_call_update', toolCallId: event.toolCallId, status: event.isError ? 'failed' : 'completed',
118
+ ...(event.rawOutput !== undefined ? { rawOutput: event.rawOutput } : event.text ? { rawOutput: event.text } : {}),
119
+ ...(event.content !== undefined ? { content: event.content } : event.text ? { content: [{ type: 'content', content: { type: 'text', text: event.text } }] } : {}) };
113
120
  case 'mode_changed': return { ...common, sessionUpdate: 'current_mode_update', currentModeId: event.payload.currentModeId };
114
121
  case 'available_commands_update': return { ...common, sessionUpdate: 'available_commands_update', availableCommands: event.payload.availableCommands.map((c) => ({ name: c.name, description: c.description || '', ...(c.hasInput ? { input: { hint: c.inputHint || 'Arguments' } } : {}) })) };
115
122
  case 'plan': return { ...common, sessionUpdate: 'plan', entries: event.entries || event.payload?.entries || [] };
@@ -241,11 +248,9 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
241
248
  const summary = backend.sessions.get(sessionId)?.acpResponsePolicy === 'summary';
242
249
  if (event.event === 'text_delta' && event.type !== 'thought')
243
250
  answers.set(sessionId, (answers.get(sessionId) || '') + (event.text || ''));
244
- let update = updateFor(event);
251
+ let update = updateFor(event, event.event === 'tool_call' && toolsSeen.has(`${sessionId}:${event.toolCallId}`));
245
252
  if (update?.sessionUpdate === 'tool_call') {
246
253
  const key = `${sessionId}:${update.toolCallId}`;
247
- if (toolsSeen.has(key))
248
- update = { ...update, sessionUpdate: 'tool_call_update' };
249
254
  toolsSeen.add(key);
250
255
  }
251
256
  if (update) {
@@ -2487,10 +2487,17 @@ async function runPromptTurn(session, sessionId, promptItem) {
2487
2487
  // so the frontend can treat status as authoritative over heuristics.
2488
2488
  const rawStatus = typeof event.status === "string" ? event.status : undefined;
2489
2489
  const toolStatus = rawStatus === "success" ? "completed" : rawStatus || undefined;
2490
+ // The runtime synthesizes "tool call" for sparse ACP updates.
2491
+ // Do not replace a previously supplied title with that display fallback.
2492
+ const toolTitle = event.tag === "tool_call_update" && event.title === "tool call"
2493
+ ? undefined : event.title;
2490
2494
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2491
2495
  event: "tool_call",
2492
2496
  content: event.content,
2493
- toolName: resolveToolDisplayName(event),
2497
+ ...(event.toolName || event.kind || toolTitle
2498
+ ? { toolName: resolveToolDisplayName(event) } : {}),
2499
+ ...(toolTitle !== undefined ? { title: toolTitle } : {}),
2500
+ ...(event.rawOutput !== undefined ? { rawOutput: event.rawOutput } : {}),
2494
2501
  toolCallId: event.toolCallId,
2495
2502
  ...(event.agentTurnId ? { agentTurnId: event.agentTurnId } : {}),
2496
2503
  ...(event.rawInput !== undefined ? { arguments: event.rawInput } : {}),
@@ -2519,6 +2526,8 @@ async function runPromptTurn(session, sessionId, promptItem) {
2519
2526
  toolCallId: event.toolCallId,
2520
2527
  toolName: resolveToolDisplayName(event),
2521
2528
  text: textContent,
2529
+ ...(event.rawOutput !== undefined ? { rawOutput: event.rawOutput } : {}),
2530
+ ...(event.content !== undefined ? { content: event.content } : {}),
2522
2531
  isError: toolStatus === "failed",
2523
2532
  ...(event.agentTurnId ? { agentTurnId: event.agentTurnId } : {}),
2524
2533
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.5.0",
3
+ "version": "0.5.1",
4
4
  "description": "ACP runtime, CLI, HTTP/WebSocket service and DeepSeek Harness plugin in one package.",
5
5
  "keywords": [
6
6
  "dreammate",
@@ -99,6 +99,7 @@
99
99
  "inject": [
100
100
  "@deepseek-ai/dsh-client-ui-commands",
101
101
  "@deepseek-ai/dsh-client-ui-conversation",
102
+ "@deepseek-ai/dsh-client-ui-chat",
102
103
  "@deepseek-ai/dsh-client-locale",
103
104
  "@deepseek-ai/dsh-api-remotes"
104
105
  ]
@@ -26,7 +26,7 @@ The service requires each native Agent’s CLI and credentials. Installing the p
26
26
 
27
27
  Choose a discovered **ACP · Agent** in the new-session Agent preset picker, choose a workspace, then send a message. ACP routes are not listed as ordinary DSH models, and the adapter rejects requests from ordinary presets, including previously saved ACP routes. Before the first turn, switching the Agent preset replaces the discovery connection and its native commands. Once a turn starts, the session keeps its remote Agent and workspace; start a new session to change Agent. Native Agent binaries and authentication belong to acp-service.
28
28
 
29
- The bundle registers an ACP adapter through DSH's public streaming extension and routes the ACP presets to it. It sends newly admitted messages whose source is `user` to `session/prompt`, not to `subagent-acp`; there is no coordinating DeepSeek model call. DSH-generated workspace instructions and runtime-context messages are excluded. The external Agent owns its model, prompt, tools and native history, including any project instructions it discovers itself. DSH owns its UI and local user/assistant transcript. External tool progress appears in the thinking stream; it is never dispatched as a DSH tool call.
29
+ The bundle registers an ACP adapter through DSH's public streaming extension and routes the ACP presets to it. It sends newly admitted messages whose source is `user` to `session/prompt`, not to `subagent-acp`; there is no coordinating DeepSeek model call. DSH-generated workspace instructions and runtime-context messages are excluded. The external Agent owns its model, prompt, tools and native history, including any project instructions it discovers itself. DSH owns its UI and local user/assistant transcript. External tool progress is preserved as display metadata on empty text blocks in DSH's existing assistant stream records and projected onto expandable ACP tool cards. ACP updates retain previously supplied fields, and replay is deduplicated by the managed turn sequence. These snapshots contain no visible text and never dispatch local tools; they use the existing persisted session format so conversations can reopen normally. Only Agent thought chunks enter the thinking stream.
30
30
 
31
31
  ## Continue imported native sessions
32
32
 
@@ -4,6 +4,7 @@ import { randomUUID } from 'node:crypto';
4
4
  import { setTimeout as delay } from 'node:timers/promises';
5
5
  import { connect, object } from './transport.js';
6
6
  import { State } from './state.js';
7
+ import { mergeTool } from './tool-events.js';
7
8
  /** Producer/consumer queue; errors are delivered after already received chunks. */
8
9
  class Queue {
9
10
  values = [];
@@ -364,6 +365,11 @@ export class AcpAdapter {
364
365
  if (binding && (binding.agent !== options.model || binding.cwd !== cwd || binding.endpoint !== endpoint.href))
365
366
  throw new Error('This session is bound to another ACP Agent or endpoint; start a new session');
366
367
  const seen = new Set();
368
+ const tools = new Map();
369
+ const boundary = this.ctx.sessionProjections.stateOf(agent.session, 'turnBoundary');
370
+ const stepStart = boundary?.lastStepStartSeq == null ? undefined : agent.session.eventAt(boundary.lastStepStartSeq);
371
+ const turn = boundary?.lastTurn ?? 0;
372
+ const step = stepStart?.type === 'step/start' ? stepStart.data.step : 0;
367
373
  let index = 0, current, content = '', answer = '';
368
374
  const endBlock = () => { if (current) {
369
375
  queue.push({ type: 'block-end', index, block: { type: current, text: content } });
@@ -396,10 +402,15 @@ export class AcpAdapter {
396
402
  if ((u.sessionUpdate === 'agent_message_chunk' || u.sessionUpdate === 'agent_thought_chunk') && u.content.type === 'text')
397
403
  emit(u.sessionUpdate === 'agent_message_chunk' ? 'text' : 'reasoning', u.content.text);
398
404
  else if (u.sessionUpdate === 'tool_call' || u.sessionUpdate === 'tool_call_update') {
399
- // External tools execute inside the remote Agent. Never emit local
400
- // tool-call chunks: DSH would execute those calls a second time.
401
- const title = 'title' in u && u.title ? u.title : u.toolCallId;
402
- emit('reasoning', `\n[ACP ${u.status ?? 'tool'}] ${title}\n`);
405
+ const tool = mergeTool(tools.get(u.toolCallId), u);
406
+ tools.set(u.toolCallId, tool);
407
+ // Known stream records preserve plugin metadata across save/reload.
408
+ // Empty text is inert; only the plugin projects it into remote Tool cards.
409
+ endBlock();
410
+ const block = { type: 'text', text: '', acpTool: { turn, step, requestId, sequence: meta.sequence, tool } };
411
+ queue.push({ type: 'block-start', index, blockType: 'text' });
412
+ queue.push({ type: 'block-end', index, block });
413
+ index++;
403
414
  }
404
415
  };
405
416
  let active;
@@ -21,16 +21,100 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
21
21
  // src/client.js
22
22
  var client_exports = {};
23
23
  __export(client_exports, {
24
+ AcpTools: () => AcpTools,
24
25
  apply: () => apply,
25
26
  choices: () => choices,
26
27
  inject: () => inject
27
28
  });
28
29
  module.exports = __toCommonJS(client_exports);
29
30
  var import_react = require("react");
30
- var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale"];
31
+
32
+ // src/tool-conversation.js
33
+ var names = { execute: "Bash", read: "Read", edit: "Edit", delete: "Delete", move: "Move", search: "Search", fetch: "Fetch", think: "Think" };
34
+ function contentOf(tool) {
35
+ if (tool.content?.length) return tool.content.flatMap((item) => {
36
+ if (item.type === "content" && item.content.type === "text") return [item.content];
37
+ if (item.type === "diff") return [{ type: "text", text: `${item.path}
38
+ ---
39
+ ${item.oldText ?? ""}
40
+ +++
41
+ ${item.newText}` }];
42
+ return [];
43
+ });
44
+ if (tool.rawOutput === void 0 || tool.rawOutput === null) return [];
45
+ return [{ type: "text", text: typeof tool.rawOutput === "string" ? tool.rawOutput : JSON.stringify(tool.rawOutput, null, 2) }];
46
+ }
47
+ function rootOf(state, location) {
48
+ const { tool, requestId, turn, step } = state.data;
49
+ const name = tool.name && tool.name !== "Tool" ? tool.name : names[tool.kind] ?? tool.title ?? tool.name ?? "Tool";
50
+ const argsRaw = JSON.stringify(tool.rawInput ?? {});
51
+ const head = { callId: `${requestId}:${tool.toolCallId}`, name, argsRaw, turn, step, time: state.time, subCalls: [] };
52
+ const settled = tool.status === "completed" || tool.status === "failed";
53
+ const closed = location?.kind === "step" && location.step.status === "closed" ? location.step.end : (location?.kind === "step" || location?.kind === "turn") && location.turn.status === "closed" ? location.turn.end : void 0;
54
+ if (!settled && !closed) return { ...head, phase: "start" };
55
+ return {
56
+ kind: "tool-result",
57
+ seq: state.seq,
58
+ time: settled ? state.updatedAt : closed.time,
59
+ callId: head.callId,
60
+ call: { name, argsRaw },
61
+ callTime: state.time,
62
+ content: contentOf(tool),
63
+ isError: tool.status === "failed" || !settled,
64
+ ...!settled ? { error: { name: "Interrupted", code: "interrupted" } } : {},
65
+ meta: { acp: tool },
66
+ subCalls: []
67
+ };
68
+ }
69
+ function snapshots(event) {
70
+ const fromChunk = (chunk, time) => chunk?.type === "block-end" && chunk.block?.acpTool ? [{ data: chunk.block.acpTool, time }] : [];
71
+ if (event.type === "assistant/live-chunk") return fromChunk(event.data.chunk, event.time);
72
+ if (event.type === "assistant/message" || event.type === "assistant/attempt") {
73
+ return (event.data.stream ?? []).flatMap((record) => record.type === "chunk" ? fromChunk(record.chunk, record.time) : []);
74
+ }
75
+ return [];
76
+ }
77
+ function fold(previous, match) {
78
+ const tools = new Map(previous?.tools);
79
+ for (const { data, time } of snapshots(match.event)) {
80
+ const current = tools.get(data.tool.toolCallId);
81
+ if (current && current.data.sequence >= data.sequence) continue;
82
+ tools.set(data.tool.toolCallId, { data, seq: current?.seq ?? match.event.seq, time: current?.time ?? time, updatedAt: time });
83
+ }
84
+ return { tools, seq: previous?.seq ?? match.event.seq };
85
+ }
86
+ var toolConversationDefinition = {
87
+ kind: "oneagents-acp-tools",
88
+ target: "chat",
89
+ match: (event) => {
90
+ const first = snapshots(event)[0];
91
+ return first ? { id: first.data.requestId, role: "start" } : null;
92
+ },
93
+ start: (_context, match) => fold(void 0, match),
94
+ update: (context, match) => fold(context.state, match),
95
+ publication: () => "immediate",
96
+ buildViewNode: (context) => {
97
+ const state = context.state;
98
+ if (!state) return null;
99
+ const location = context.start?.location ?? context.matches[0]?.location ?? { kind: "unresolved" };
100
+ return {
101
+ key: context.key,
102
+ id: context.id,
103
+ kind: "oneagents-acp-tools",
104
+ target: "chat",
105
+ anchorSeq: state.seq,
106
+ location,
107
+ visibility: "visible",
108
+ data: { roots: [...state.tools.values()].map((tool) => rootOf(tool, location)) }
109
+ };
110
+ }
111
+ };
112
+
113
+ // src/client.js
114
+ var inject = ["slots", "sessions", "commandUi", "remote", "remote.session", "locale", "uiConversation"];
31
115
  var dictionaries = {
32
- zh: { model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E" },
33
- en: { model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings" }
116
+ zh: { toolRunning: "\u6267\u884C\u4E2D", toolFailed: "\u5931\u8D25", toolCompleted: "\u5DF2\u5B8C\u6210", toolNoOutput: "\u65E0\u8F93\u51FA", model: "\u6A21\u578B", choose: "\u9009\u62E9\u6A21\u578B", loading: "\u6B63\u5728\u8FDE\u63A5 Agent\u2026", retry: "\u91CD\u8BD5", mode: "\u6A21\u5F0F", command: "Agent \u6307\u4EE4", effort: "\u601D\u8003\u5F3A\u5EA6", unsupported: "Agent \u672A\u63D0\u4F9B\u53EF\u5207\u6362\u7684\u6A21\u578B", description: "\u9009\u62E9\u5F53\u524D Agent \u7684\u6A21\u578B", error: "\u8FDE\u63A5\u5931\u8D25", noCommands: "Agent \u5C1A\u672A\u63D0\u4F9B\u6307\u4EE4", native: "ACP \u8BBE\u7F6E" },
117
+ en: { toolRunning: "Running", toolFailed: "Failed", toolCompleted: "Completed", toolNoOutput: "No output", model: "Model", choose: "Select model", loading: "Connecting to Agent\u2026", retry: "Retry", mode: "Mode", command: "Agent commands", effort: "Reasoning effort", unsupported: "This Agent does not advertise model selection", description: "Select this Agent\u2019s model", error: "Connection failed", noCommands: "No commands advertised", native: "ACP settings" }
34
118
  };
35
119
  function choices(option) {
36
120
  return (option.options ?? []).flatMap((item) => "group" in item ? item.options.map((value) => ({ ...value, group: item.name ?? item.group })) : [item]);
@@ -58,7 +142,52 @@ function Select({ title, value, rows, disabled, onSelect, placeholder }) {
58
142
  )
59
143
  );
60
144
  }
145
+ function AcpTools({ node, t }) {
146
+ return (0, import_react.createElement)("div", { "data-oneagents-acp-tools": "", style: { display: "grid", gap: 6 } }, node.data.roots.map((root) => {
147
+ const running = root.phase === "start";
148
+ const tool = running ? root : root.call;
149
+ const output = running ? [] : root.content;
150
+ const acp = root.meta?.acp;
151
+ let args;
152
+ try {
153
+ args = JSON.parse(tool.argsRaw);
154
+ } catch {
155
+ args = tool.argsRaw;
156
+ }
157
+ const input = args?.command ?? args?.path ?? args?.file_path ?? acp?.title ?? tool.argsRaw;
158
+ const state = running ? "running" : root.isError ? "failed" : "completed";
159
+ const labels = { running: t("toolRunning"), failed: t("toolFailed"), completed: t("toolCompleted"), noOutput: t("toolNoOutput") };
160
+ return (0, import_react.createElement)(
161
+ "details",
162
+ {
163
+ key: root.callId,
164
+ "data-acp-call": root.callId,
165
+ "data-acp-status": state,
166
+ style: { border: "1px solid var(--dsw-alias-border-l1, #8883)", borderRadius: 8, padding: "7px 10px" }
167
+ },
168
+ (0, import_react.createElement)(
169
+ "summary",
170
+ { style: { cursor: "pointer", fontSize: 13 } },
171
+ (0, import_react.createElement)("strong", null, tool.name),
172
+ " ",
173
+ (0, import_react.createElement)("span", { style: { opacity: 0.65 } }, labels[state]),
174
+ (0, import_react.createElement)("code", { style: { display: "block", whiteSpace: "pre-wrap", overflowWrap: "anywhere", marginTop: 4 } }, typeof input === "string" ? input : JSON.stringify(input))
175
+ ),
176
+ (0, import_react.createElement)(
177
+ "pre",
178
+ { style: { whiteSpace: "pre-wrap", overflowWrap: "anywhere", maxHeight: 360, overflow: "auto", fontSize: 12 } },
179
+ output.length ? output.map((block) => block.text ?? "").join("\n") : running ? labels.running : labels.noOutput
180
+ )
181
+ );
182
+ }));
183
+ }
61
184
  function apply(ctx) {
185
+ ctx.uiConversation.events.register(toolConversationDefinition);
186
+ ctx.slots.inject("conversation.chat.node", () => ctx.slots.register({
187
+ name: "conversation.chat.node",
188
+ key: "oneagents-acp-tools",
189
+ locale: "oneagentsAcp"
190
+ }, AcpTools));
62
191
  ctx.effect(() => ctx.locale.register("oneagentsAcp", dictionaries));
63
192
  const t = ctx.locale.bind("oneagentsAcp");
64
193
  const native = /* @__PURE__ */ new Map();
@@ -0,0 +1,26 @@
1
+ /** Display metadata on empty stream blocks never becomes a local tool request. */
2
+ import type { SessionUpdate } from '@agentclientprotocol/sdk';
3
+ type ToolUpdate = Extract<SessionUpdate, {
4
+ sessionUpdate: 'tool_call' | 'tool_call_update';
5
+ }>;
6
+ export interface RemoteTool {
7
+ toolCallId: string;
8
+ title?: string | null;
9
+ name?: string;
10
+ status?: ToolUpdate['status'];
11
+ kind?: ToolUpdate['kind'];
12
+ rawInput?: unknown;
13
+ rawOutput?: unknown;
14
+ content?: ToolUpdate['content'];
15
+ locations?: ToolUpdate['locations'];
16
+ }
17
+ export interface ToolEvent {
18
+ turn: number;
19
+ step: number;
20
+ requestId: string;
21
+ sequence: number;
22
+ tool: RemoteTool;
23
+ }
24
+ /** ACP updates replace supplied fields and leave omitted fields intact. */
25
+ export declare function mergeTool(previous: RemoteTool | undefined, update: ToolUpdate): RemoteTool;
26
+ export {};
@@ -0,0 +1,13 @@
1
+ /** ACP updates replace supplied fields and leave omitted fields intact. */
2
+ export function mergeTool(previous, update) {
3
+ const tool = { ...previous, toolCallId: update.toolCallId };
4
+ for (const key of ['title', 'status', 'kind', 'rawInput', 'rawOutput', 'content', 'locations']) {
5
+ if (update[key] !== undefined && (update[key] !== null || key === 'rawInput' || key === 'rawOutput'))
6
+ Object.assign(tool, { [key]: update[key] });
7
+ }
8
+ // The service's friendly name is display metadata, separate from ACP's title.
9
+ const name = update._meta?.['1agents']?.toolName;
10
+ if (name && (name !== 'Tool' || !tool.name))
11
+ tool.name = name;
12
+ return tool;
13
+ }