@1agents/acp-service 0.7.0 → 0.8.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.
Files changed (83) hide show
  1. package/README.md +10 -0
  2. package/dist/src/a2a/executor.js +34 -9
  3. package/dist/src/a2a/index.d.ts +1 -0
  4. package/dist/src/a2a/index.js +1 -0
  5. package/dist/src/a2a/lease.d.ts +13 -0
  6. package/dist/src/a2a/lease.js +149 -0
  7. package/dist/src/a2a/request-id.d.ts +2 -0
  8. package/dist/src/a2a/request-id.js +6 -0
  9. package/dist/src/a2a/server.js +13 -1
  10. package/dist/src/a2a/store.d.ts +4 -6
  11. package/dist/src/a2a/store.js +14 -114
  12. package/dist/src/a2a/types.d.ts +9 -0
  13. package/dist/src/acp-connection.d.ts +2 -1
  14. package/dist/src/acp-connection.js +52 -9
  15. package/dist/src/bridge.js +38 -39
  16. package/package.json +15 -13
  17. package/vendor/dsh/README.md +12 -2
  18. package/vendor/dsh/a2a-executor.d.ts +7 -1
  19. package/vendor/dsh/a2a-executor.js +56 -15
  20. package/vendor/dsh/a2a.d.ts +2 -1
  21. package/vendor/dsh/a2a.js +9 -5
  22. package/vendor/dsh/adapter.d.ts +3 -1
  23. package/vendor/dsh/adapter.js +144 -16
  24. package/vendor/dsh/diagnostics.d.ts +42 -0
  25. package/vendor/dsh/diagnostics.js +176 -0
  26. package/vendor/dsh/index.d.ts +1 -0
  27. package/vendor/dsh/index.js +16 -4
  28. package/vendor/runtime/dist/{cli-DUHyAADv.js → cli-Bdzplbpj.js} +4 -4
  29. package/vendor/runtime/dist/{cli-DUHyAADv.js.map → cli-Bdzplbpj.js.map} +1 -1
  30. package/vendor/runtime/dist/cli.d.ts +1 -1
  31. package/vendor/runtime/dist/cli.js +8 -8
  32. package/vendor/runtime/dist/{client-DjkWknf7.d.ts → client-BXOiB0ND.d.ts} +2 -2
  33. package/vendor/runtime/dist/{client-DjkWknf7.d.ts.map → client-BXOiB0ND.d.ts.map} +1 -1
  34. package/vendor/runtime/dist/{flows-CiJSCy4D.js → flows-BKlAuzM8.js} +4 -4
  35. package/vendor/runtime/dist/{flows-CiJSCy4D.js.map → flows-BKlAuzM8.js.map} +1 -1
  36. package/vendor/runtime/dist/flows.d.ts +2 -2
  37. package/vendor/runtime/dist/flows.js +1 -1
  38. package/vendor/runtime/dist/{invocation-options-BlIySxIw.js → invocation-options-DMy77sEU.js} +4 -4
  39. package/vendor/runtime/dist/{invocation-options-BlIySxIw.js.map → invocation-options-DMy77sEU.js.map} +1 -1
  40. package/vendor/runtime/dist/{ipc-BlljKR2b.js → ipc-CLv2iL89.js} +260 -2
  41. package/vendor/runtime/dist/ipc-CLv2iL89.js.map +1 -0
  42. package/vendor/runtime/dist/{output-BzXQKArM.js → output-I-t-v55D.js} +3 -3
  43. package/vendor/runtime/dist/{output-BzXQKArM.js.map → output-I-t-v55D.js.map} +1 -1
  44. package/vendor/runtime/dist/{queue-owner-runtime-DSFdsS_y.js → queue-owner-runtime-RN3uSid0.js} +2 -2
  45. package/vendor/runtime/dist/{queue-owner-runtime-DSFdsS_y.js.map → queue-owner-runtime-RN3uSid0.js.map} +1 -1
  46. package/vendor/runtime/dist/runtime.d.ts +25 -15
  47. package/vendor/runtime/dist/runtime.d.ts.map +1 -1
  48. package/vendor/runtime/dist/runtime.js +57 -37
  49. package/vendor/runtime/dist/runtime.js.map +1 -1
  50. package/vendor/runtime/dist/{session-options-ORCchZGk.d.ts → session-options-DNnDfiUt.d.ts} +18 -2
  51. package/vendor/runtime/dist/session-options-DNnDfiUt.d.ts.map +1 -0
  52. package/vendor/runtime/dist/{session-watch-BiBTBMz4.js → session-watch-CmHbH0jS.js} +4 -4
  53. package/vendor/runtime/dist/{session-watch-BiBTBMz4.js.map → session-watch-CmHbH0jS.js.map} +1 -1
  54. package/vendor/runtime/dist/{watch-iYiP-lOo.js → watch-BE-kKa7o.js} +2 -2
  55. package/vendor/runtime/dist/{watch-iYiP-lOo.js.map → watch-BE-kKa7o.js.map} +1 -1
  56. package/vendor/runtime/skills/acpx/SKILL.md +1 -0
  57. package/vendor/runtime/dist/docs-site/.nojekyll +0 -0
  58. package/vendor/runtime/dist/docs-site/CLI.html +0 -832
  59. package/vendor/runtime/dist/docs-site/CNAME +0 -1
  60. package/vendor/runtime/dist/docs-site/VISION.html +0 -415
  61. package/vendor/runtime/dist/docs-site/agents.html +0 -391
  62. package/vendor/runtime/dist/docs-site/compare.html +0 -359
  63. package/vendor/runtime/dist/docs-site/config.html +0 -450
  64. package/vendor/runtime/dist/docs-site/custom-agents.html +0 -408
  65. package/vendor/runtime/dist/docs-site/exit-codes.html +0 -347
  66. package/vendor/runtime/dist/docs-site/favicon.svg +0 -21
  67. package/vendor/runtime/dist/docs-site/flows.html +0 -497
  68. package/vendor/runtime/dist/docs-site/index.html +0 -367
  69. package/vendor/runtime/dist/docs-site/install.html +0 -386
  70. package/vendor/runtime/dist/docs-site/llms.txt +0 -35
  71. package/vendor/runtime/dist/docs-site/output-formats.html +0 -406
  72. package/vendor/runtime/dist/docs-site/permissions.html +0 -413
  73. package/vendor/runtime/dist/docs-site/prompting.html +0 -460
  74. package/vendor/runtime/dist/docs-site/proof-2026-07-18-grok-ext-methods/index.html +0 -336
  75. package/vendor/runtime/dist/docs-site/quickstart.html +0 -382
  76. package/vendor/runtime/dist/docs-site/runtime-environment.html +0 -329
  77. package/vendor/runtime/dist/docs-site/runtime-process-lifecycle.html +0 -335
  78. package/vendor/runtime/dist/docs-site/session-control.html +0 -406
  79. package/vendor/runtime/dist/docs-site/session-watch.html +0 -354
  80. package/vendor/runtime/dist/docs-site/sessions.html +0 -486
  81. package/vendor/runtime/dist/docs-site/shared-sessions.html +0 -377
  82. package/vendor/runtime/dist/ipc-BlljKR2b.js.map +0 -1
  83. package/vendor/runtime/dist/session-options-ORCchZGk.d.ts.map +0 -1
@@ -4,11 +4,45 @@ import { randomUUID } from 'node:crypto';
4
4
  import { isAbsolute } from 'node:path';
5
5
  import { realpathSync } from 'node:fs';
6
6
  import { agent, RequestError, PROTOCOL_VERSION } from '@agentclientprotocol/sdk';
7
+ import { toSafeError } from '@1agents/acp-service/runtime';
7
8
  import { AcpState } from './acp-state.js';
8
9
  import { dispatchCommand, activeSessions, runtime, loadSessionHistory, readRuntimeRecord } from './bridge.js';
9
10
  const calls = new AsyncLocalStorage();
10
11
  const NS = '1agents';
11
12
  const EXT = '_1agents/';
13
+ /** Error envelopes have a closed projection; provider data never becomes metadata. */
14
+ function safeFailureEvent(event, trustedRuntimeErrors) {
15
+ if (['tool_call', 'tool_call_update', 'tool_result'].includes(event.event)) {
16
+ if (event.error === undefined && event.errorCode === undefined && event.errorText === undefined)
17
+ return event;
18
+ const error = toSafeError(event.error ?? (trustedRuntimeErrors ? { code: event.errorCode, message: event.errorText } : undefined), { origin: 'service' });
19
+ return { ...event,
20
+ ...(event.error !== undefined ? { error } : {}),
21
+ ...(event.errorCode !== undefined ? { errorCode: error.providerCode ?? error.code } : {}),
22
+ ...(event.errorText !== undefined ? { errorText: error.message } : {}),
23
+ };
24
+ }
25
+ const failedTurn = event.status === 'failed' && ['turn_state', 'turn_terminal', 'turn_complete', 'done'].includes(event.event);
26
+ if (!event.error && !failedTurn && event.event !== 'error' && event.event !== 'protocol_error' && event.type !== 'error')
27
+ return event;
28
+ const safe = toSafeError(event.error ?? (trustedRuntimeErrors ? { ...event, code: event.code ?? event.errorCode } : undefined), {
29
+ origin: 'service', operationId: event.runtimeRequestId ?? event.requestId, trustedProjection: trustedRuntimeErrors,
30
+ });
31
+ const value = {};
32
+ for (const key of ['event', 'type', 'sessionId', 'turnId', 'requestId', 'runtimeRequestId', 'promptMessageId',
33
+ 'sequence', 'journalSequence', 'scope', 'terminal', 'status', 'responsePolicy', 'stopReason', 'stopped',
34
+ 'completedAt', 'createdAt', 'updatedAt', 'finalAnswer', 'resultText', 'sessionRef', 'summary']) {
35
+ if (event[key] !== undefined)
36
+ value[key] = event[key];
37
+ }
38
+ if (event.error || event.status === 'failed')
39
+ return { ...value, error: safe, errorCode: safe.providerCode ?? safe.code, errorText: safe.message };
40
+ return { ...value, ...safe, error: safe };
41
+ }
42
+ function failure(error, options) {
43
+ const safe = toSafeError(error, { origin: 'service', ...options });
44
+ return new RequestError(-32000, safe.message, safe);
45
+ }
12
46
  const production = {
13
47
  dispatch: dispatchCommand,
14
48
  get sessions() { return activeSessions; },
@@ -72,13 +106,15 @@ export function webSocketStream(ws) {
72
106
  /** A runtime subscriber owned by exactly one live ACP connection. */
73
107
  export class RuntimePeer {
74
108
  receive;
109
+ trustedRuntimeErrors;
75
110
  readyState = 1;
76
111
  _acpxReqHost;
77
- constructor(receive) {
112
+ constructor(receive, trustedRuntimeErrors = false) {
78
113
  this.receive = receive;
114
+ this.trustedRuntimeErrors = trustedRuntimeErrors;
79
115
  }
80
116
  send(raw) {
81
- const event = JSON.parse(raw);
117
+ const event = safeFailureEvent(JSON.parse(raw), this.trustedRuntimeErrors);
82
118
  const call = calls.getStore();
83
119
  if (call?.active)
84
120
  call.events.push(event);
@@ -90,12 +126,17 @@ export class RuntimePeer {
90
126
  try {
91
127
  await calls.run(call, () => backend.dispatch(this, payload));
92
128
  }
129
+ catch (error) {
130
+ throw failure(error, { operationId: payload.requestId });
131
+ }
93
132
  finally {
94
133
  call.active = false;
95
134
  }
96
- const failure = events.find(e => (e.event === 'error' || e.type === 'error' || e.event === 'protocol_error') && e.scope !== 'turn');
97
- if (failure)
98
- throw new RequestError(-32000, failure.message || 'Runtime command failed', { code: failure.code });
135
+ const failureEvent = events.find(e => (e.event === 'error' || e.type === 'error' || e.event === 'protocol_error') && e.scope !== 'turn');
136
+ if (failureEvent) {
137
+ const safe = toSafeError(failureEvent.error ?? failureEvent, { origin: 'service', operationId: payload.requestId });
138
+ throw new RequestError(-32000, safe.message, safe);
139
+ }
99
140
  return events;
100
141
  }
101
142
  }
@@ -151,7 +192,9 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
151
192
  const interactive = new Map();
152
193
  const answers = new Map();
153
194
  const toolsSeen = new Set();
154
- const peer = new RuntimePeer(receive);
195
+ // The production bridge already projects runtime errors before serialization.
196
+ // Injected backends do not inherit that provenance for self-asserted fields.
197
+ const peer = new RuntimePeer(receive, backend === production);
155
198
  peer._acpxReqHost = req?.headers.host?.split(':')[0];
156
199
  function notify(method, params) {
157
200
  if (!connected)
@@ -160,7 +203,7 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
160
203
  if (!connected)
161
204
  return;
162
205
  for (const pending of prompts.values())
163
- pending.reject(error);
206
+ pending.reject(failure(error, { origin: 'transport', operationId: pending.requestId, outcomeUnknown: true }));
164
207
  prompts.clear();
165
208
  ws.close(1011, 'ACP update delivery failed');
166
209
  });
@@ -284,7 +327,7 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
284
327
  prompts.delete(key);
285
328
  void output.then(() => {
286
329
  if (event.status === 'failed' || event.event === 'error')
287
- pending.reject(new RequestError(-32000, event.error?.message || event.message || 'Turn failed', { code: event.error?.code }));
330
+ pending.reject(failure(event.error ?? event, { operationId: pending.requestId }));
288
331
  else
289
332
  pending.resolve({ stopReason: event.stopped || event.status === 'cancelled' ? 'cancelled' : ['end_turn', 'max_tokens', 'max_turn_requests', 'refusal', 'cancelled'].includes(event.stopReason) ? event.stopReason : 'end_turn', _meta: envelope(event) });
290
333
  });
@@ -509,7 +552,7 @@ export function attachAcpConnection(ws, req, backend = production, state = new A
509
552
  for (const item of interactive.values())
510
553
  item.abort.abort();
511
554
  for (const pending of prompts.values())
512
- pending.reject(new Error('Connection closed; resume the session to observe the retained turn'));
555
+ pending.reject(failure(undefined, { origin: 'transport', operationId: pending.requestId, outcomeUnknown: true }));
513
556
  prompts.clear();
514
557
  });
515
558
  const connection = app.connect(webSocketStream(ws));
@@ -5,7 +5,7 @@ import * as path from "node:path";
5
5
  import { WebSocketServer } from "ws";
6
6
  import { attachAcpConnection } from "./acp-connection.js";
7
7
  import { createServiceAgentRegistry } from "./catalog.js";
8
- import { createAcpRuntime, createRuntimeStore, createTurnJournal, } from "@1agents/acp-service/runtime";
8
+ import { createAcpRuntime, createRuntimeStore, createTurnJournal, toSafeError, } from "@1agents/acp-service/runtime";
9
9
  import { historyToolInput, resolveRuntimeTurnId, stampHistoryTurnIds, } from "./history-turn-ids.js";
10
10
  // ----------------------------------------------------
11
11
  // Configurations
@@ -930,6 +930,7 @@ function sendSummaryTerminal(ws, session, sessionId, payload) {
930
930
  sessionReaderPort: 7777,
931
931
  };
932
932
  const resultText = payload.resultText || "";
933
+ const error = payload.error ? toSafeError(payload.error, { origin: "service" }) : undefined;
933
934
  ws.send(JSON.stringify({
934
935
  event: "turn_complete",
935
936
  sessionId,
@@ -939,7 +940,7 @@ function sendSummaryTerminal(ws, session, sessionId, payload) {
939
940
  finalAnswer: resultText,
940
941
  sessionRef,
941
942
  completedAt: new Date().toISOString(),
942
- ...(payload.error ? { error: payload.error } : {}),
943
+ ...(error ? { error } : {}),
943
944
  }));
944
945
  ws.send(JSON.stringify({
945
946
  event: "done",
@@ -954,6 +955,7 @@ function sendSummaryTerminal(ws, session, sessionId, payload) {
954
955
  ? "Execution failed."
955
956
  : "Execution completed successfully."),
956
957
  ...(payload.stopped ? { stopped: true } : {}),
958
+ ...(error ? { error } : {}),
957
959
  }));
958
960
  }
959
961
  function sendTurnState(ws, sessionId, turn, queuePosition, acceptedNew = false) {
@@ -2160,7 +2162,21 @@ export async function dispatchCommand(ws, payload) {
2160
2162
  }
2161
2163
  }
2162
2164
  catch (err) {
2163
- console.error(`[acpx-server] Action execution failed:`, err);
2165
+ if (action === "prompt") {
2166
+ const error = toSafeError(err, { origin: "service", operationId: payload.requestId });
2167
+ console.error("[acpx-server] Prompt dispatch failed:", error);
2168
+ const session = activeSessions.get(sessionId);
2169
+ if (resolveResponsePolicy(payload.responsePolicy, session?.responsePolicy) === "summary") {
2170
+ sendSummaryTerminal(ws, session, sessionId, {
2171
+ status: "failed", resultText: "", turnId: payload.turnId || payload.requestId, error,
2172
+ });
2173
+ }
2174
+ else {
2175
+ ws.send(JSON.stringify({ event: "error", sessionId, scope: "turn", ...error }));
2176
+ }
2177
+ return;
2178
+ }
2179
+ console.error(`[acpx-server] Action execution failed:`, toSafeError(err, { origin: "service", operationId: payload.requestId }));
2164
2180
  // An AgentStartupError with exit 127 / "command not found" means the
2165
2181
  // agent's ACP adapter binary could not be launched — almost always
2166
2182
  // because the adapter package isn't installed for 1acp (the bare
@@ -2545,12 +2561,12 @@ async function runPromptTurn(session, sessionId, promptItem) {
2545
2561
  }
2546
2562
  }
2547
2563
  else if (event.type === "error") {
2564
+ const error = toSafeError(event, { origin: "service", operationId: requestId, trustedProjection: true });
2548
2565
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2549
2566
  event: "error",
2550
2567
  scope: "turn",
2551
2568
  terminal: false,
2552
- code: event.code,
2553
- message: event.message,
2569
+ ...error,
2554
2570
  });
2555
2571
  }
2556
2572
  else if (event.type === "status" &&
@@ -2607,6 +2623,9 @@ async function runPromptTurn(session, sessionId, promptItem) {
2607
2623
  // Otherwise select only final-answer phases, while retaining every message
2608
2624
  // in the execution log. Unphased agents keep their legacy stream fallback.
2609
2625
  const finalResultText = result.finalAnswer ?? (hasMessagePhase ? finalAnswer : accumulatedAnswer);
2626
+ const error = result.status === "failed"
2627
+ ? toSafeError(result.error, { origin: "service", operationId: requestId, trustedProjection: true })
2628
+ : undefined;
2610
2629
  const journalTerminal = turn.hostTurnId
2611
2630
  ? await turnJournal.record({
2612
2631
  sessionId,
@@ -2616,8 +2635,8 @@ async function runPromptTurn(session, sessionId, promptItem) {
2616
2635
  promptText: promptItem.text,
2617
2636
  agentType: currentSession?.agentType || session.agentType,
2618
2637
  finalAnswer: finalResultText,
2619
- errorCode: result.status === "failed" ? result.error?.code || "ACP_PROMPT_FAILED" : undefined,
2620
- errorText: result.status === "failed" ? result.error?.message : undefined,
2638
+ errorCode: error?.providerCode || error?.code,
2639
+ errorText: error?.message,
2621
2640
  runtimeRecordId: currentSession?.handle?.acpxRecordId || session.handle?.acpxRecordId || sessionId,
2622
2641
  runtimeRequestId: result.runtimeRequestId || requestId,
2623
2642
  promptMessageId: result.promptMessageId || requestId,
@@ -2630,12 +2649,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2630
2649
  status: result.status,
2631
2650
  resultText: finalResultText,
2632
2651
  turnId: turn.hostTurnId || result.agentTurnId || result.runtimeRequestId || requestId,
2633
- error: result.status === "failed"
2634
- ? {
2635
- code: result.error?.code || "ACP_PROMPT_FAILED",
2636
- message: result.error?.message || "Turn execution failed",
2637
- }
2638
- : undefined,
2652
+ error,
2639
2653
  stopped: result.status === "cancelled",
2640
2654
  });
2641
2655
  if (targetWs && targetWs.readyState === 1 /* OPEN */) {
@@ -2655,14 +2669,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2655
2669
  runtimeRequestId: result.runtimeRequestId || requestId,
2656
2670
  promptMessageId: result.promptMessageId || requestId,
2657
2671
  completedAt: new Date().toISOString(),
2658
- ...(result.status === "failed"
2659
- ? {
2660
- error: {
2661
- code: result.error?.code || "ACP_PROMPT_FAILED",
2662
- message: result.error?.message || "Turn execution failed",
2663
- },
2664
- }
2665
- : {}),
2672
+ ...(error ? { error } : {}),
2666
2673
  });
2667
2674
  terminalSent = true;
2668
2675
  void sendSessionMeta(targetWs, sessionId, currentSession.handle);
@@ -2672,7 +2679,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2672
2679
  event: "error",
2673
2680
  scope: "turn",
2674
2681
  sessionId,
2675
- message: result.error?.message || "Turn execution failed",
2682
+ ...error,
2676
2683
  }));
2677
2684
  }
2678
2685
  else {
@@ -2708,7 +2715,8 @@ async function runPromptTurn(session, sessionId, promptItem) {
2708
2715
  }
2709
2716
  }
2710
2717
  catch (err) {
2711
- console.error(`[acpx-server] Error executing turn:`, err);
2718
+ const error = toSafeError(err, { origin: "service", operationId: requestId });
2719
+ console.error(`[acpx-server] Error executing turn:`, error);
2712
2720
  const currentSession = activeSessions.get(sessionId);
2713
2721
  const targetWs = currentSession ? currentSession.ws : null;
2714
2722
  if (turn.hostTurnId && !terminalSent) {
@@ -2720,8 +2728,8 @@ async function runPromptTurn(session, sessionId, promptItem) {
2720
2728
  status: "failed",
2721
2729
  promptText: promptItem.text,
2722
2730
  agentType: currentSession?.agentType,
2723
- errorCode: "ACP_PROMPT_FAILED",
2724
- errorText: err?.message || String(err),
2731
+ errorCode: error.providerCode || error.code,
2732
+ errorText: error.message,
2725
2733
  runtimeRecordId: currentSession?.handle?.acpxRecordId || sessionId,
2726
2734
  runtimeRequestId: requestId,
2727
2735
  promptMessageId: requestId,
@@ -2733,10 +2741,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2733
2741
  status: "failed",
2734
2742
  resultText: accumulatedAnswer,
2735
2743
  turnId: turn.hostTurnId,
2736
- error: {
2737
- code: "ACP_PROMPT_FAILED",
2738
- message: err?.message || String(err),
2739
- },
2744
+ error,
2740
2745
  });
2741
2746
  }
2742
2747
  else {
@@ -2749,16 +2754,13 @@ async function runPromptTurn(session, sessionId, promptItem) {
2749
2754
  runtimeRequestId: requestId,
2750
2755
  promptMessageId: requestId,
2751
2756
  completedAt: new Date().toISOString(),
2752
- error: {
2753
- code: "ACP_PROMPT_FAILED",
2754
- message: err?.message || String(err),
2755
- },
2757
+ error,
2756
2758
  });
2757
2759
  }
2758
2760
  terminalSent = true;
2759
2761
  }
2760
2762
  catch (journalError) {
2761
- sendError(targetWs, sessionId, "TURN_JOURNAL_FAILED", journalError?.message || String(journalError));
2763
+ sendError(targetWs, sessionId, "TURN_JOURNAL_FAILED", toSafeError(journalError, { origin: "service", operationId: requestId }).message);
2762
2764
  }
2763
2765
  }
2764
2766
  else if (isSummaryMode) {
@@ -2766,10 +2768,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2766
2768
  status: "failed",
2767
2769
  resultText: accumulatedAnswer,
2768
2770
  turnId: turn.hostTurnId || requestId,
2769
- error: {
2770
- code: "ACP_PROMPT_FAILED",
2771
- message: err?.message || String(err),
2772
- },
2771
+ error,
2773
2772
  });
2774
2773
  }
2775
2774
  else if (targetWs && targetWs.readyState === 1 /* OPEN */) {
@@ -2777,7 +2776,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2777
2776
  event: "error",
2778
2777
  scope: "turn",
2779
2778
  sessionId,
2780
- message: err.message,
2779
+ ...error,
2781
2780
  }));
2782
2781
  }
2783
2782
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.7.0",
3
+ "version": "0.8.1",
4
4
  "description": "ACP runtime, CLI, HTTP/WebSocket service and DeepSeek Harness ACP/A2A plugins in one package.",
5
5
  "keywords": [
6
6
  "dreammate",
@@ -75,13 +75,21 @@
75
75
  "skills",
76
76
  "vendor"
77
77
  ],
78
+ "scripts": {
79
+ "build": "node ../../scripts/embed-runtime.mjs && tsc -p tsconfig.build.json",
80
+ "typecheck": "tsc -p tsconfig.json --noEmit",
81
+ "test": "npm run build && npm run test:only",
82
+ "prepack": "node ../../scripts/verify-package-build.mjs",
83
+ "start": "tsx bin/acp-service.ts",
84
+ "test:only": "node --import tsx --test test/*.test.ts"
85
+ },
78
86
  "engines": {
79
87
  "node": ">=22.13.0"
80
88
  },
81
89
  "dependencies": {
82
90
  "@1agents/acp-runtime-sdk": "npm:@agentclientprotocol/sdk@^1.5.0",
83
- "@1agents/dreammate-network": "^0.3.1",
84
- "@1agents/dreammate-node": "^0.4.0",
91
+ "@1agents/dreammate-network": "^0.5.0",
92
+ "@1agents/dreammate-node": "^0.15.0",
85
93
  "@a2a-js/sdk": "1.3.0",
86
94
  "@agentclientprotocol/sdk": "1.4.0",
87
95
  "@openclaw/fs-safe": "^0.20.0",
@@ -89,10 +97,11 @@
89
97
  "skillflag": "^0.2.1",
90
98
  "tsx": "^4.23.15",
91
99
  "ws": "^8.18.0",
92
- "zod": "^4.6.5"
100
+ "zod": "^4.6.5",
101
+ "dsh-zod": "npm:zod@4.4.3"
93
102
  },
94
103
  "devDependencies": {
95
- "@scottzx/1acp": "0.16.0",
104
+ "@scottzx/1acp": "workspace:*",
96
105
  "@types/node": "^22.10.2",
97
106
  "@types/ws": "^8.5.14",
98
107
  "typescript": "^5.7.2"
@@ -112,12 +121,5 @@
112
121
  "@deepseek-ai/dsh-api-remotes"
113
122
  ]
114
123
  }
115
- },
116
- "scripts": {
117
- "build": "node ../../scripts/embed-runtime.mjs && tsc -p tsconfig.build.json",
118
- "typecheck": "tsc -p tsconfig.json --noEmit",
119
- "test": "npm run build && npm run test:only",
120
- "start": "tsx bin/acp-service.ts",
121
- "test:only": "node --import tsx --test test/*.test.ts"
122
124
  }
123
- }
125
+ }
@@ -83,11 +83,21 @@ ACP one-shot tool permissions use DSH's approval UI and policy. Grok questions a
83
83
 
84
84
  Transport reconnects load the same service session and replay the current managed turn. Stable request IDs prevent duplicate execution, and update sequence numbers suppress duplicate output. A browser refresh leaves the Host request running. Stopping a DSH turn sends ACP cancellation. Provider errors fail the turn without automatic resubmission.
85
85
 
86
+ The owned ACP Adapter sanitizes provider failures before the official DSH host normalizes them. Category, provider code, retryability, outcome uncertainty, origin and request identity are persisted in the plugin's `oneagents_acp_diagnostics` domain, using official `storageDomain` and JSON storage plugins. The plugin owns their lifetime so cancellation and A2A drain before storage closes. DSH source, native `LlmFailure` and Session event schemas stay unchanged; its ordinary logs can retain only code and message. Complete diagnostics appear under A2A `metadata['1agents'].error`, with the A2A caller's operation identity. Host error properties and arbitrary in-band metadata cannot supply missing diagnostics.
87
+
88
+ Each attempt is bound to its DSH session, turn/start sequence, step/start sequence, input message identities and native request identity. Only user messages admitted in the current turn establish association; each identity is at most 256 characters and each identity list at most 128 entries. Oversized identities fail before native delivery. Records contain only bounded safe fields, never provider text, credentials or authentication URLs. A newer pending attempt cannot borrow an older failure. The storage owner-token lease rejects concurrent writers and reclaims only demonstrably dead owners after restart. Invalid versions or records fail initialization without deleting evidence. Writes resolve after durability; a storage failure fails the call instead of acknowledging diagnostics that were not saved.
89
+
90
+ Confirmed remote cancellation reports `cancelled` with `outcomeUnknown: false`. A received terminal RPC reply establishes the outcome even when local cancellation races with its delivery; no further output is emitted after cancellation. A submitted request without a terminal reply remains uncertain, while work cancelled before delivery is certain. Claimed disposal without a result remains uncertain. Root teardown waits for the official Agent idle barrier if subscriptions disappear before the final event. Cancellation does not automatically resubmit, and a racing local abort does not replace a received provider error.
91
+
92
+ A2A startup reconciles interrupted tasks using their saved context and exact task/message request identity. A durable plugin failure restores its safe fields; an unfinished submitted attempt stays unknown. Reconciliation records a failed interrupted task and never dispatches execution. Already terminal tasks remain unchanged. Historical host logs without plugin diagnostics cannot reconstruct missing fields, and other DSH providers are not classified from host error text.
93
+
86
94
  This plugin supports **text prompts**. Attachments and specialized external-tool cards are not implemented. Auxiliary DSH title/compaction calls cannot use this adapter; an advertised native compaction command runs in the external Agent. Existing standard-preset sessions that selected an old ACP route must choose a normal DSH model or start a new ACP-preset session.
87
95
 
88
96
  ## Configuration
89
97
 
90
- The bundle's `oneagents-acp` row accepts `serviceUrl`, `serviceMode`, `serviceStartupTimeoutMs`, `serviceShutdownTimeoutMs`, `agents`, `stateDirectory`, `reconnectAttempts` and `reconnectDelayMs`. Change it through the profile's `cordis.patch.yml`, not the DSH repository. Use a new session after changing endpoint or workspace. When `agents` is omitted, plugin startup fetches `GET /agents` from acp-service and registers presets for entries with `chat_ready: true`, using their service-provided names. Discovery runs on the service host. Restart the plugin after installing or removing a harness. An explicit `agents` list bypasses discovery and preserves manual registry selection; `[]` registers no presets. Service startup, connection errors and invalid inventory responses fail plugin initialization instead of selecting fallback agents.
98
+ The bundle's `oneagents-acp` row accepts `serviceUrl`, `serviceMode`, `serviceStartupTimeoutMs`, `serviceShutdownTimeoutMs`, `agents`, `stateDirectory`, `diagnosticsDirectory`, `reconnectAttempts` and `reconnectDelayMs`. Change it through the profile's `cordis.patch.yml`, not the DSH repository. Use a new session after changing endpoint or workspace. When `agents` is omitted, plugin startup fetches `GET /agents` from acp-service and registers presets for entries with `chat_ready: true`, using their service-provided names. Discovery runs on the service host. Restart the plugin after installing or removing a harness. An explicit `agents` list bypasses discovery and preserves manual registry selection; `[]` registers no presets. Service startup, connection errors and invalid inventory responses fail plugin initialization instead of selecting fallback agents.
99
+
100
+ Diagnostic storage defaults to `stateDirectory/diagnostics`; `diagnosticsDirectory` selects a separate explicit location. Keep this directory with the A2A state when moving a host. Its version is independent of DSH Session formats. The plugin privately mounts official storage components; it does not require a shared host storage-domain configuration. Only one plugin instance may write the directory at a time.
91
101
 
92
102
  ### Local service lifecycle
93
103
 
@@ -110,7 +120,7 @@ pnpm build
110
120
  pnpm test:integration
111
121
  ```
112
122
 
113
- The DSH checkout must already have its dependencies installed and declaration outputs built. Development type checking links its matching packages into `node_modules/@deepseek-ai`; generated JavaScript has no runtime imports of those packages and uses the Host's provided services. Tests cover real-WebSocket streaming, permissions, questions, cancellation, reconnection and saved bindings.
123
+ The DSH checkout must already have its dependencies installed and declaration outputs built. Development type checking links its matching packages into `node_modules/@deepseek-ai`; generated JavaScript uses the Host's public packages and services. The `dsh-zod` dependency alias pins the record-schema dialect to Zod 4.4.3 for the tested official DSH 0.1.7-rc.2 API, independently of the service's Zod dependency. A different DSH version requires its own compile and lifecycle compatibility checks. Tests cover real-WebSocket streaming, permissions, questions, cancellation, reconnection and saved bindings.
114
124
 
115
125
  For manual service debugging on this machine, start it from `../service` with:
116
126
 
@@ -1,11 +1,17 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { A2ABackend, A2APrepareInput, A2ARunResult, A2ATarget } from '@1agents/acp-service/a2a';
3
+ import type { Diagnostics } from './diagnostics.js';
3
4
  /** Uses public session-controller and inbox events to account for one A2A prompt's exact DSH turn. */
4
5
  export declare class DshA2ABackend implements A2ABackend {
5
6
  private readonly ctx;
7
+ private readonly diagnostics?;
6
8
  private readonly executions;
7
9
  /** @param ctx DSH plugin context that owns session-controller and execution event registrations. */
8
- constructor(ctx: Context);
10
+ constructor(ctx: Context, diagnostics?: Diagnostics | undefined);
11
+ /** Restart reconciliation reads the plugin domain and never dispatches another prompt. */
12
+ recover(target: A2ATarget, options: {
13
+ requestId: string;
14
+ }): Promise<import("@1agents/acp-service/runtime").SafeError | undefined>;
9
15
  /** Create a new session or restore an explicitly addressed session without changing its workspace or preset.
10
16
  * @param input Remote host directory, preset, and optional existing DSH session identity.
11
17
  * @returns The resolved DSH session and its durable workspace and preset.
@@ -1,19 +1,25 @@
1
1
  /** DSH session execution behind the shared A2A service's transport-independent backend. */
2
2
  import { realpath, stat } from 'node:fs/promises';
3
3
  import { isAbsolute } from 'node:path';
4
- function resultOf(reason, text, finalAnswerExpected) {
4
+ import { toSafeError } from '@1agents/acp-service/runtime';
5
+ function resultOf(reason, text, finalAnswerExpected, operationId, diagnostic) {
5
6
  switch (reason.kind) {
6
7
  case 'completed': return finalAnswerExpected && !text.trim()
7
- ? { outcome: 'failed', text, detail: 'DSH completed the task without a final answer; ACP final-answer metadata contained no final output' }
8
+ ? { outcome: 'failed', text, failureReason: 'missing-final-answer', detail: 'DSH completed the task without a final answer; ACP final-answer metadata contained no final output' }
8
9
  : { outcome: 'completed', text };
9
10
  case 'blocked': return { outcome: 'input-required', text, detail: 'DSH blocked the task before its next model step' };
10
- case 'error': return { outcome: 'failed', text, detail: reason.error.message };
11
- case 'max-tokens': return { outcome: 'failed', text, detail: 'DSH reached the model output token limit' };
12
- case 'aborted': return { outcome: 'failed', text, detail: 'DSH task execution was canceled' };
13
- case 'interrupted': return { outcome: 'failed', text, detail: 'DSH task execution was interrupted' };
14
- case 'forked': return { outcome: 'failed', text, detail: 'DSH task turn was closed by a session fork' };
11
+ case 'error': {
12
+ const error = diagnostic ?? toSafeError(undefined, { origin: 'dsh', operationId });
13
+ return { outcome: 'failed', text, detail: error.message, error };
14
+ }
15
+ case 'max-tokens': return { outcome: 'failed', text, failureReason: 'max-tokens', detail: 'DSH reached the model output token limit' };
16
+ case 'aborted': return { outcome: 'failed', text, failureReason: 'aborted', detail: 'DSH task execution was canceled',
17
+ error: diagnostic ?? toSafeError(new DOMException('ACP execution cancelled.', 'AbortError'), { origin: 'dsh', operationId, outcomeUnknown: true }) };
18
+ case 'interrupted': return { outcome: 'failed', text, failureReason: 'interrupted', detail: 'DSH task execution was interrupted',
19
+ error: toSafeError(undefined, { origin: 'dsh', operationId, outcomeUnknown: true }) };
20
+ case 'forked': return { outcome: 'failed', text, failureReason: 'forked', detail: 'DSH task turn was closed by a session fork' };
15
21
  // DSH's turn reasons are merge-extensible; an unknown ending cannot report success.
16
- default: return { outcome: 'failed', text, detail: 'DSH returned an unsupported turn ending' };
22
+ default: return { outcome: 'failed', text, failureReason: 'unsupported-ending', detail: 'DSH returned an unsupported turn ending' };
17
23
  }
18
24
  }
19
25
  /** Read durable ACP metadata, leaving ordinary DSH messages compatible. */
@@ -32,10 +38,16 @@ function answerOf(content, turn) {
32
38
  /** Uses public session-controller and inbox events to account for one A2A prompt's exact DSH turn. */
33
39
  export class DshA2ABackend {
34
40
  ctx;
41
+ diagnostics;
35
42
  executions = new Map();
36
43
  /** @param ctx DSH plugin context that owns session-controller and execution event registrations. */
37
- constructor(ctx) {
44
+ constructor(ctx, diagnostics) {
38
45
  this.ctx = ctx;
46
+ this.diagnostics = diagnostics;
47
+ }
48
+ /** Restart reconciliation reads the plugin domain and never dispatches another prompt. */
49
+ async recover(target, options) {
50
+ return this.diagnostics?.find(target.sessionId, options.requestId);
39
51
  }
40
52
  /** Create a new session or restore an explicitly addressed session without changing its workspace or preset.
41
53
  * @param input Remote host directory, preset, and optional existing DSH session identity.
@@ -111,13 +123,40 @@ export class DshA2ABackend {
111
123
  options.signal.removeEventListener('abort', cancel);
112
124
  completion.resolve(result);
113
125
  };
126
+ const finishTurn = (reason) => {
127
+ const start = agent.session.snapshotEvents().findLast(event => event.type === 'turn/start' && event.data.turn === turn);
128
+ let diagnostic;
129
+ try {
130
+ diagnostic = this.diagnostics?.find(agent.id, options.requestId, turn, start?.seq);
131
+ }
132
+ catch { /* A stopping storage provider cannot supply durable diagnostics. */ }
133
+ settle(resultOf(reason, text, finalAnswerExpected, options.requestId, diagnostic));
134
+ };
114
135
  const cancel = () => {
115
136
  if (settled)
116
137
  return;
117
- if (turn !== undefined)
138
+ if (turn !== undefined) {
118
139
  agent.cancel({ kind: 'user' }, { keepInbox: true });
119
- else if (messageId !== undefined)
120
- agent.inbox.remove(messageId);
140
+ // Root shutdown can remove event subscriptions before the final turn is
141
+ // published. The public idle barrier still drains that exact activity.
142
+ void agent.whenIdle().then(() => {
143
+ if (settled)
144
+ return;
145
+ const ended = agent.session.snapshotEvents().findLast(event => event.type === 'turn/end' && event.data.turn === turn);
146
+ if (ended?.type === 'turn/end')
147
+ finishTurn(ended.data.reason);
148
+ else
149
+ settle({ outcome: 'failed', text, failureReason: 'disposed',
150
+ error: toSafeError(undefined, { origin: 'dsh', operationId: options.requestId, outcomeUnknown: true }) });
151
+ }, () => {
152
+ settle({ outcome: 'failed', text, failureReason: 'disposed',
153
+ error: toSafeError(undefined, { origin: 'dsh', operationId: options.requestId, outcomeUnknown: true }) });
154
+ });
155
+ }
156
+ else if (messageId !== undefined && agent.inbox.remove(messageId)) {
157
+ settle({ outcome: 'failed', text, failureReason: 'discarded',
158
+ error: toSafeError(new DOMException('ACP execution cancelled.', 'AbortError'), { origin: 'dsh', operationId: options.requestId, outcomeUnknown: false }) });
159
+ }
121
160
  };
122
161
  // The session owns these temporary listeners until its turn settles. Plugin
123
162
  // unloading removes plugin effects concurrently with the server's cancel/drain.
@@ -138,12 +177,14 @@ export class DshA2ABackend {
138
177
  }));
139
178
  listeners.push(agent.ctx.on('agent/inbox/discarded', event => {
140
179
  if (event.agent === agent && owns(event.message)) {
141
- settle({ outcome: 'failed', text, detail: 'DSH discarded the queued task before execution' });
180
+ settle({ outcome: 'failed', text, failureReason: 'discarded', detail: 'DSH discarded the queued task before execution',
181
+ ...(options.signal.aborted ? { error: toSafeError(new DOMException('ACP execution cancelled.', 'AbortError'), { origin: 'dsh', operationId: options.requestId, outcomeUnknown: false }) } : {}) });
142
182
  }
143
183
  }));
144
184
  listeners.push(agent.ctx.on('agent/disposed', event => {
145
185
  if (event.agent === agent)
146
- settle({ outcome: 'failed', text, detail: 'DSH session was disposed before the task finished' });
186
+ settle({ outcome: 'failed', text, failureReason: 'disposed', detail: 'DSH session was disposed before the task finished',
187
+ error: toSafeError(undefined, { origin: 'dsh', operationId: options.requestId, outcomeUnknown: turn !== undefined }) });
147
188
  }));
148
189
  listeners.push(agent.ctx.on('session/event', (session, event) => {
149
190
  if (session !== agent.session || turn === undefined)
@@ -163,7 +204,7 @@ export class DshA2ABackend {
163
204
  text = next.text;
164
205
  }
165
206
  else if (event.type === 'turn/end' && event.data.turn === turn) {
166
- settle(resultOf(event.data.reason, text, finalAnswerExpected));
207
+ finishTurn(event.data.reason);
167
208
  }
168
209
  }));
169
210
  options.signal.addEventListener('abort', cancel, { once: true });
@@ -1,6 +1,7 @@
1
1
  /** Mount the shared A2A implementation on the current DSH web host. */
2
2
  import { type A2AServerOptions } from '@1agents/acp-service/a2a';
3
3
  import type { Context } from '@deepseek-ai/cordis';
4
+ import type { Diagnostics } from './diagnostics.js';
4
5
  /** Optional host configuration; omitted configuration leaves A2A disabled. */
5
6
  export interface DshA2AOptions extends Omit<A2AServerOptions, 'backend' | 'token' | 'stateDirectory' | 'publicUrl'> {
6
7
  enabled?: boolean;
@@ -12,4 +13,4 @@ export interface DshA2AOptions extends Omit<A2AServerOptions, 'backend' | 'token
12
13
  publicUrl?: string;
13
14
  }
14
15
  /** Routes and in-flight turns are released with the owning Cordis plugin. */
15
- export declare function mountDshA2A(ctx: Context, options: DshA2AOptions, stateDirectory: string): Promise<void>;
16
+ export declare function mountDshA2A(ctx: Context, options: DshA2AOptions, stateDirectory: string, diagnostics?: Diagnostics): Promise<() => Promise<void>>;
package/vendor/dsh/a2a.js CHANGED
@@ -2,14 +2,15 @@
2
2
  import { createA2AServer } from '@1agents/acp-service/a2a';
3
3
  import { DshA2ABackend } from './a2a-executor.js';
4
4
  /** Routes and in-flight turns are released with the owning Cordis plugin. */
5
- export async function mountDshA2A(ctx, options, stateDirectory) {
5
+ export async function mountDshA2A(ctx, options, stateDirectory, diagnostics) {
6
6
  if (options.enabled === false)
7
- return;
7
+ return async () => { };
8
8
  const token = options.token ?? process.env[options.tokenEnv ?? 'DSH_A2A_TOKEN'];
9
9
  if (!token)
10
10
  throw new Error('Set DSH_A2A_TOKEN or a2a.token before enabling DSH A2A');
11
+ let close = async () => { };
11
12
  await ctx.effect(async () => {
12
- const server = await createA2AServer({ ...options, token, backend: new DshA2ABackend(ctx),
13
+ const server = await createA2AServer({ ...options, token, backend: new DshA2ABackend(ctx, diagnostics),
13
14
  stateDirectory: options.stateDirectory ?? stateDirectory,
14
15
  publicUrl: options.publicUrl ?? `http://127.0.0.1:${ctx.webServer.port}` });
15
16
  const routes = [];
@@ -23,10 +24,13 @@ export async function mountDshA2A(ctx, options, stateDirectory) {
23
24
  await server.close();
24
25
  throw error;
25
26
  }
26
- return async () => {
27
+ let closing;
28
+ close = () => closing ??= (async () => {
27
29
  for (const dispose of routes.reverse())
28
30
  dispose();
29
31
  await server.close();
30
- };
32
+ })();
33
+ return close;
31
34
  });
35
+ return close;
32
36
  }
@@ -1,6 +1,7 @@
1
1
  import type { Context } from '@deepseek-ai/cordis';
2
2
  import type { Agent } from '@deepseek-ai/dsh-agent';
3
3
  import type { LlmAdapter, GenerateOptions, StreamChunk, LlmModelInfo } from '@deepseek-ai/dsh-llm';
4
+ import type { Diagnostics } from './diagnostics.js';
4
5
  import type { SessionConfigOption, SessionModeState, AvailableCommand } from '@agentclientprotocol/sdk';
5
6
  import { type Binding } from './state.js';
6
7
  export interface Config {
@@ -21,6 +22,7 @@ export interface Capabilities {
21
22
  export declare class AcpAdapter implements LlmAdapter {
22
23
  private ctx;
23
24
  private config;
25
+ private readonly diagnostics?;
24
26
  private state;
25
27
  private controllers;
26
28
  private jobs;
@@ -32,7 +34,7 @@ export declare class AcpAdapter implements LlmAdapter {
32
34
  private commandDisposers;
33
35
  private output;
34
36
  private lifetime;
35
- constructor(ctx: Context, config: Config);
37
+ constructor(ctx: Context, config: Config, diagnostics?: Diagnostics | undefined);
36
38
  providerInfo(provider: string): {
37
39
  id: string;
38
40
  name: string;