@1agents/acp-service 0.1.3 → 0.1.4

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.
package/README.md CHANGED
@@ -97,8 +97,8 @@ console.log(`ACP Service running on port ${port}`);
97
97
 
98
98
  | 动作 (`action`) | 描述 | 关键参数 |
99
99
  | :--- | :--- | :--- |
100
- | `ensure_session` | 创建或恢复 ACP 会话 | `sessionId`, `workspacePath`, `agentType`, `permissionMode` |
101
- | `prompt` | 发送用户提示词与附件 | `sessionId`, `prompt`, `attachments` |
100
+ | `ensure_session` | 创建或恢复 ACP 会话 | `sessionId`, `workspacePath`, `agentType`, `permissionMode`, `responsePolicy` |
101
+ | `prompt` | 发送用户提示词与附件 | `sessionId`, `text`, `attachments`, `responsePolicy` |
102
102
  | `respond_permission` | 响应工具调用的权限审批 | `sessionId`, `requestId`, `decision` |
103
103
  | `respond_ask_user_question` | 响应 Grok `_x.ai/ask_user_question` | `sessionId`, `requestId`, `answers` |
104
104
  | `respond_exit_plan_mode` | 响应 Grok `_x.ai/exit_plan_mode` | `sessionId`, `requestId`, `decision` |
@@ -107,6 +107,45 @@ console.log(`ACP Service running on port ${port}`);
107
107
  | `get_history` | 获取当前会话权威历史切片 | `sessionId` |
108
108
  | `close_session` | 结束并销毁会话 | `sessionId` |
109
109
 
110
+ ### 3. `responsePolicy`:人机流式 vs 智能体摘要
111
+
112
+ `ensure_session` 与 `prompt` 都接受可选字段 `responsePolicy`:
113
+
114
+ | 值 | 默认 | 适用 | 线上推送 |
115
+ | :--- | :--- | :--- | :--- |
116
+ | `stream` | 是 | 人类 UI(Web Chat、终端) | 全量 `text_delta` / `tool_call` / `turn_state` |
117
+ | `summary` | 否 | 设备 B 上的调度 Agent | 轮次结束只推 `turn_complete` + `done`,附带 `sessionRef` |
118
+
119
+ ```json
120
+ {
121
+ "action": "prompt",
122
+ "sessionId": "task-456",
123
+ "text": "重构 backend/server.go 的鉴权逻辑",
124
+ "responsePolicy": "summary"
125
+ }
126
+ ```
127
+
128
+ `summary` 结束时的收敛事件:
129
+
130
+ ```json
131
+ {
132
+ "event": "turn_complete",
133
+ "sessionId": "task-456",
134
+ "status": "completed",
135
+ "responsePolicy": "summary",
136
+ "resultText": "已重构鉴权逻辑,修改了 2 个文件,测试通过。",
137
+ "sessionRef": {
138
+ "sessionId": "task-456",
139
+ "turnId": 5,
140
+ "sessionReaderUrl": "http://<device-A>:7777"
141
+ }
142
+ }
143
+ ```
144
+
145
+ 权限审批、`ask_user_question`、`exit_plan_mode` 仍会实时下发——否则轮次会卡住。需要推理日志或工具细节时,用 `sessionRef.sessionReaderUrl` 走 `1session` / session-reader 按需下钻。
146
+
147
+ Manifest 能力位:`agent.response_policy`。
148
+
110
149
  ---
111
150
 
112
151
  ## 协议与底层支持
@@ -12,13 +12,22 @@ function getAcpxCliPath() {
12
12
  }
13
13
  function getPackageVersion() {
14
14
  try {
15
- const pkgPath = new URL('../package.json', import.meta.url);
16
- const pkg = JSON.parse(fs.readFileSync(pkgPath, 'utf-8'));
17
- return pkg.version || '0.1.1';
18
- }
19
- catch {
20
- return '0.1.1';
15
+ const candidates = [
16
+ new URL('../../package.json', import.meta.url),
17
+ new URL('../package.json', import.meta.url),
18
+ ];
19
+ for (const url of candidates) {
20
+ try {
21
+ const content = fs.readFileSync(url, 'utf-8');
22
+ const pkg = JSON.parse(content);
23
+ if (pkg.version)
24
+ return pkg.version;
25
+ }
26
+ catch { }
27
+ }
21
28
  }
29
+ catch { }
30
+ return '0.1.4';
22
31
  }
23
32
  function printServeHelp(binName) {
24
33
  console.log(`用法: ${binName} serve [选项]
@@ -1,10 +1,11 @@
1
+ export function resolveResponsePolicy(explicitPolicy: any, sessionPolicy: any): any;
1
2
  export function attachBridgeServer(serverOrOptions?: {}): {
2
3
  wss: null;
3
4
  runtime: import("@scottzx/1acp/runtime").AcpxRuntime;
4
5
  activeSessions: Map<any, any>;
5
6
  close: typeof killAllManagedAgents;
6
7
  };
7
- export function setupConnection(ws: any): void;
8
+ export function setupConnection(ws: any, req: any): void;
8
9
  export function attachProcessSignalHandlers(): void;
9
10
  export let wss: null;
10
11
  export function killAllManagedAgents(): Promise<void>;
@@ -910,6 +910,48 @@ async function reconcileTurnJournal(sessionId, session, recoverOutstanding) {
910
910
  }
911
911
  return await turnJournal.snapshot(sessionId);
912
912
  }
913
+ export function resolveResponsePolicy(explicitPolicy, sessionPolicy) {
914
+ if (explicitPolicy === "summary" || explicitPolicy === "stream") {
915
+ return explicitPolicy;
916
+ }
917
+ return sessionPolicy === "summary" ? "summary" : "stream";
918
+ }
919
+ function sendSummaryTerminal(ws, session, sessionId, payload) {
920
+ if (!ws || ws.readyState !== 1 /* OPEN */) {
921
+ return;
922
+ }
923
+ const host = session?.reqHost || ws._acpxReqHost || "127.0.0.1";
924
+ const sessionRef = {
925
+ sessionId,
926
+ turnId: payload.turnId,
927
+ sessionReaderUrl: `http://${host}:7777`,
928
+ sessionReaderPort: 7777,
929
+ };
930
+ const resultText = payload.resultText || "";
931
+ ws.send(JSON.stringify({
932
+ event: "turn_complete",
933
+ sessionId,
934
+ status: payload.status,
935
+ responsePolicy: "summary",
936
+ resultText,
937
+ sessionRef,
938
+ completedAt: new Date().toISOString(),
939
+ ...(payload.error ? { error: payload.error } : {}),
940
+ }));
941
+ ws.send(JSON.stringify({
942
+ event: "done",
943
+ sessionId,
944
+ status: payload.status,
945
+ responsePolicy: "summary",
946
+ resultText,
947
+ sessionRef,
948
+ summary: resultText ||
949
+ (payload.status === "failed"
950
+ ? "Execution failed."
951
+ : "Execution completed successfully."),
952
+ ...(payload.stopped ? { stopped: true } : {}),
953
+ }));
954
+ }
913
955
  function sendTurnState(ws, sessionId, turn, queuePosition, acceptedNew = false) {
914
956
  if (!ws || ws.readyState !== 1 /* OPEN */) {
915
957
  return;
@@ -959,6 +1001,10 @@ function clearSessionHistoryPush(sessionId) {
959
1001
  historyPushStates.delete(sessionId);
960
1002
  }
961
1003
  function scheduleSessionHistoryPush(sessionId) {
1004
+ const currentSession = activeSessions.get(sessionId);
1005
+ if (currentSession?.responsePolicy === "summary") {
1006
+ return;
1007
+ }
962
1008
  let state = historyPushStates.get(sessionId);
963
1009
  if (!state) {
964
1010
  state = {
@@ -1038,7 +1084,7 @@ export function attachBridgeServer(serverOrOptions = {}) {
1038
1084
  wss.on("error", (err) => {
1039
1085
  console.error("[acpx-server] WebSocketServer error:", err);
1040
1086
  });
1041
- wss.on("connection", setupConnection);
1087
+ wss.on("connection", (ws, req) => setupConnection(ws, req));
1042
1088
  return {
1043
1089
  wss,
1044
1090
  runtime,
@@ -1046,7 +1092,11 @@ export function attachBridgeServer(serverOrOptions = {}) {
1046
1092
  close: killAllManagedAgents,
1047
1093
  };
1048
1094
  }
1049
- export function setupConnection(ws) {
1095
+ export function setupConnection(ws, req) {
1096
+ if (req) {
1097
+ const hostHeader = req.headers?.host;
1098
+ ws._acpxReqHost = hostHeader ? hostHeader.split(":")[0] : undefined;
1099
+ }
1050
1100
  console.log("[acpx-server] Client connected to ACP bridge.");
1051
1101
  ws.on("message", async (messageData) => {
1052
1102
  let payload;
@@ -1066,7 +1116,8 @@ export function setupConnection(ws) {
1066
1116
  try {
1067
1117
  switch (action) {
1068
1118
  case "ensure_session": {
1069
- const { workspacePath, agentType, systemContext, mcpServers, resumeSessionId, acpSessionId, permissionMode, env, } = payload;
1119
+ const { workspacePath, agentType, systemContext, mcpServers, resumeSessionId, acpSessionId, permissionMode, responsePolicy, env, } = payload;
1120
+ const normalizedResponsePolicy = responsePolicy === "summary" ? "summary" : "stream";
1070
1121
  console.time(`ensure_session_${sessionId}`);
1071
1122
  console.log(`[DEBUG] ensure_session started for agent=${agentType || "unknown"}, session=${sessionId}`);
1072
1123
  if (!sessionId || !workspacePath || !agentType) {
@@ -1121,6 +1172,12 @@ export function setupConnection(ws) {
1121
1172
  if (seededMode && !existingSession.permissionMode) {
1122
1173
  existingSession.permissionMode = seededMode;
1123
1174
  }
1175
+ if (responsePolicy) {
1176
+ existingSession.responsePolicy = normalizedResponsePolicy;
1177
+ }
1178
+ if (ws._acpxReqHost) {
1179
+ existingSession.reqHost = ws._acpxReqHost;
1180
+ }
1124
1181
  // Re-deliver any interactive prompts that were in-flight when the
1125
1182
  // previous WebSocket dropped. The ACP runtime is still blocked
1126
1183
  // waiting for the response; re-sending the event lets the newly
@@ -1143,11 +1200,14 @@ export function setupConnection(ws) {
1143
1200
  }
1144
1201
  }
1145
1202
  registerAgentSessionMapping(sessionId, existingSession.handle);
1146
- await sendAuthoritativeTurnSync(ws, sessionId, existingSession);
1203
+ if (existingSession.responsePolicy !== "summary") {
1204
+ await sendAuthoritativeTurnSync(ws, sessionId, existingSession);
1205
+ }
1147
1206
  ws.send(JSON.stringify({
1148
1207
  event: "session_ready",
1149
1208
  sessionId,
1150
1209
  turnProtocolVersion: 3,
1210
+ responsePolicy: existingSession.responsePolicy || "stream",
1151
1211
  agentSessionId: existingSession.handle.agentSessionId || existingSession.handle.backendSessionId,
1152
1212
  }));
1153
1213
  void sendSessionMeta(ws, sessionId, existingSession.handle);
@@ -1209,13 +1269,18 @@ export function setupConnection(ws) {
1209
1269
  agentType,
1210
1270
  sessionMode: await resolveGrokPermissionMode(handle, agentType),
1211
1271
  permissionMode: seededMode ?? "approve-reads",
1272
+ responsePolicy: normalizedResponsePolicy,
1273
+ reqHost: ws._acpxReqHost,
1212
1274
  });
1213
1275
  registerAgentSessionMapping(sessionId, handle);
1214
- await sendAuthoritativeTurnSync(ws, sessionId, activeSessions.get(sessionId), true);
1276
+ if (normalizedResponsePolicy !== "summary") {
1277
+ await sendAuthoritativeTurnSync(ws, sessionId, activeSessions.get(sessionId), true);
1278
+ }
1215
1279
  ws.send(JSON.stringify({
1216
1280
  event: "session_ready",
1217
1281
  sessionId,
1218
1282
  turnProtocolVersion: 3,
1283
+ responsePolicy: normalizedResponsePolicy,
1219
1284
  agentSessionId: handle.agentSessionId || handle.backendSessionId,
1220
1285
  }));
1221
1286
  void sendSessionMeta(ws, sessionId, handle);
@@ -1263,16 +1328,21 @@ export function setupConnection(ws) {
1263
1328
  // default in handlePermissionRequestCallback. The Composer's
1264
1329
  // mode toggle later updates this via set_permission_mode.
1265
1330
  // Default to approve-reads when the store has nothing (e.g.
1266
- // brand-new session) so the mode check at line ~925 never
1267
- // has to special-case null/undefined.
1331
+ // brand-new session) so the mode check never has to
1332
+ // special-case null/undefined.
1268
1333
  permissionMode: seededMode ?? "approve-reads",
1334
+ responsePolicy: normalizedResponsePolicy,
1335
+ reqHost: ws._acpxReqHost,
1269
1336
  });
1270
1337
  registerAgentSessionMapping(sessionId, handle);
1271
- await sendAuthoritativeTurnSync(ws, sessionId, activeSessions.get(sessionId), true);
1338
+ if (normalizedResponsePolicy !== "summary") {
1339
+ await sendAuthoritativeTurnSync(ws, sessionId, activeSessions.get(sessionId), true);
1340
+ }
1272
1341
  ws.send(JSON.stringify({
1273
1342
  event: "session_ready",
1274
1343
  sessionId,
1275
1344
  turnProtocolVersion: 3,
1345
+ responsePolicy: normalizedResponsePolicy,
1276
1346
  agentSessionId: handle.agentSessionId || handle.backendSessionId,
1277
1347
  }));
1278
1348
  void sendSessionMeta(ws, sessionId, handle);
@@ -1286,7 +1356,10 @@ export function setupConnection(ws) {
1286
1356
  // attachments: optional [{ mediaType, data }] (base64) — forwarded
1287
1357
  // to runtime.startTurn, which maps image/* and audio/* onto ACP
1288
1358
  // content blocks. Other media types are rejected by the runtime.
1289
- const { text, attachments, turnId: requestedTurnId, requestId: requestedRuntimeId, turnManaged, } = payload;
1359
+ const { text, attachments, turnId: requestedTurnId, requestId: requestedRuntimeId, turnManaged, responsePolicy, } = payload;
1360
+ const parsedPromptPolicy = responsePolicy === "summary" || responsePolicy === "stream"
1361
+ ? responsePolicy
1362
+ : undefined;
1290
1363
  if (!sessionId || text === undefined) {
1291
1364
  sendError(ws, sessionId, "INVALID_PARAMS", "sessionId and text are required");
1292
1365
  return;
@@ -1296,6 +1369,7 @@ export function setupConnection(ws) {
1296
1369
  sendError(ws, sessionId, "SESSION_NOT_FOUND", "Session not initialized");
1297
1370
  return;
1298
1371
  }
1372
+ const promptIsSummary = resolveResponsePolicy(parsedPromptPolicy, session.responsePolicy) === "summary";
1299
1373
  if (turnManaged || requestedTurnId) {
1300
1374
  if (!requestedRuntimeId) {
1301
1375
  ws.send(JSON.stringify({
@@ -1336,6 +1410,7 @@ export function setupConnection(ws) {
1336
1410
  requestId: requestedRuntimeId,
1337
1411
  requestFingerprint,
1338
1412
  ws,
1413
+ responsePolicy: parsedPromptPolicy,
1339
1414
  };
1340
1415
  if (session.activeTurn || session.promptQueue.length > 0) {
1341
1416
  const queued = await turnJournal.record({
@@ -1349,7 +1424,9 @@ export function setupConnection(ws) {
1349
1424
  runtimeRecordId: session.handle?.acpxRecordId || sessionId,
1350
1425
  });
1351
1426
  session.promptQueue.push(promptItem);
1352
- sendTurnState(ws, sessionId, queued.turn, session.promptQueue.length, queued.created);
1427
+ if (!promptIsSummary) {
1428
+ sendTurnState(ws, sessionId, queued.turn, session.promptQueue.length, queued.created);
1429
+ }
1353
1430
  return;
1354
1431
  }
1355
1432
  await runPromptTurn(session, sessionId, promptItem);
@@ -1366,6 +1443,7 @@ export function setupConnection(ws) {
1366
1443
  attachments,
1367
1444
  queuedRequestId,
1368
1445
  ws,
1446
+ responsePolicy: parsedPromptPolicy,
1369
1447
  });
1370
1448
  ws.send(JSON.stringify({
1371
1449
  event: "prompt_queued",
@@ -1377,7 +1455,11 @@ export function setupConnection(ws) {
1377
1455
  console.log(`[acpx-server] Prompt queued for session ${sessionId} (queue depth=${session.promptQueue.length})`);
1378
1456
  return;
1379
1457
  }
1380
- await runPromptTurn(session, sessionId, { text, attachments });
1458
+ await runPromptTurn(session, sessionId, {
1459
+ text,
1460
+ attachments,
1461
+ responsePolicy: parsedPromptPolicy,
1462
+ });
1381
1463
  break;
1382
1464
  }
1383
1465
  case "respond_permission": {
@@ -2215,6 +2297,8 @@ function sendRuntimeTurnEvent(ws, sessionId, turn, payload) {
2215
2297
  // are journaled before execution or queue acknowledgement.
2216
2298
  async function runPromptTurn(session, sessionId, promptItem) {
2217
2299
  const requestId = promptItem.requestId || `turn_${Date.now()}`;
2300
+ const effectiveResponsePolicy = resolveResponsePolicy(promptItem.responsePolicy, session.responsePolicy);
2301
+ const isSummaryMode = effectiveResponsePolicy === "summary";
2218
2302
  if (promptItem.turnId) {
2219
2303
  const running = await turnJournal.record({
2220
2304
  sessionId,
@@ -2229,8 +2313,10 @@ async function runPromptTurn(session, sessionId, promptItem) {
2229
2313
  promptMessageId: requestId,
2230
2314
  terminalSource: "turn_journal",
2231
2315
  });
2232
- const currentSession = activeSessions.get(sessionId);
2233
- sendTurnState(currentSession?.ws || promptItem.ws, sessionId, running.turn, 0, running.created);
2316
+ if (!isSummaryMode) {
2317
+ const currentSession = activeSessions.get(sessionId);
2318
+ sendTurnState(currentSession?.ws || promptItem.ws, sessionId, running.turn, 0, running.created);
2319
+ }
2234
2320
  }
2235
2321
  const attachments = Array.isArray(promptItem.attachments)
2236
2322
  ? promptItem.attachments.filter((a) => a && typeof a.mediaType === "string" && typeof a.data === "string")
@@ -2246,9 +2332,27 @@ async function runPromptTurn(session, sessionId, promptItem) {
2246
2332
  turn.eventSequence = 0;
2247
2333
  session.activeTurn = turn;
2248
2334
  let terminalSent = false;
2335
+ let accumulatedAnswer = "";
2249
2336
  void (async () => {
2250
2337
  try {
2251
2338
  for await (const event of turn.events) {
2339
+ if (event.type === "text_delta") {
2340
+ const streamType = event.stream || "output";
2341
+ if (streamType === "output") {
2342
+ accumulatedAnswer += event.text || "";
2343
+ }
2344
+ }
2345
+ else if (event.type === "status" &&
2346
+ event.tag === "current_mode_update" &&
2347
+ event.currentModeId) {
2348
+ const liveSession = activeSessions.get(sessionId);
2349
+ if (liveSession) {
2350
+ liveSession.sessionMode = event.currentModeId;
2351
+ }
2352
+ }
2353
+ if (isSummaryMode) {
2354
+ continue;
2355
+ }
2252
2356
  const currentSession = activeSessions.get(sessionId);
2253
2357
  const targetWs = currentSession ? currentSession.ws : null;
2254
2358
  if (!targetWs || targetWs.readyState !== 1 /* OPEN */) {
@@ -2260,7 +2364,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2260
2364
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2261
2365
  event: "text_delta",
2262
2366
  text: event.text,
2263
- type: event.stream || "output", // 'thought' or 'output'
2367
+ type: event.stream || "output",
2264
2368
  ...(event.agentTurnId ? { agentTurnId: event.agentTurnId } : {}),
2265
2369
  });
2266
2370
  }
@@ -2326,14 +2430,6 @@ async function runPromptTurn(session, sessionId, promptItem) {
2326
2430
  else if (event.type === "status" &&
2327
2431
  event.tag === "current_mode_update" &&
2328
2432
  event.currentModeId) {
2329
- // The agent switched its own native mode mid-turn (e.g. ExitPlanMode
2330
- // flips plan → default). Mirror it so the client's mode picker
2331
- // follows without a reconnect, and keep the bridge permission gate
2332
- // (session.sessionMode) aligned for Grok short-circuit checks.
2333
- const liveSession = activeSessions.get(sessionId);
2334
- if (liveSession) {
2335
- liveSession.sessionMode = event.currentModeId;
2336
- }
2337
2433
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2338
2434
  event: "mode_changed",
2339
2435
  payload: { currentModeId: event.currentModeId },
@@ -2342,8 +2438,6 @@ async function runPromptTurn(session, sessionId, promptItem) {
2342
2438
  else if (event.type === "status" &&
2343
2439
  event.tag === "available_commands_update" &&
2344
2440
  Array.isArray(event.availableCommands)) {
2345
- // Live refresh of the slash-command list (rare mid-session; the
2346
- // session_meta snapshot covers the common case at session start).
2347
2441
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2348
2442
  event: "available_commands_update",
2349
2443
  payload: { availableCommands: event.availableCommands },
@@ -2352,26 +2446,18 @@ async function runPromptTurn(session, sessionId, promptItem) {
2352
2446
  else if (event.type === "status" &&
2353
2447
  event.tag === "plan" &&
2354
2448
  Array.isArray(event.planEntries)) {
2355
- // The agent's execution plan (TodoWrite / Codex plan). Full list on
2356
- // every update — the client replaces its checklist wholesale.
2357
2449
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2358
2450
  event: "plan",
2359
2451
  payload: { entries: event.planEntries },
2360
2452
  });
2361
2453
  }
2362
2454
  else if (event.type === "background_task" && Array.isArray(event.tasks)) {
2363
- // Background bash task snapshots (Grok Build runtime): full list on
2364
- // every update — the client replaces its task cards wholesale.
2365
2455
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2366
2456
  event: "background_task",
2367
2457
  payload: { tasks: event.tasks },
2368
2458
  });
2369
2459
  }
2370
2460
  else if (event.type === "status" && event.tag === "usage_update") {
2371
- // Token/context usage + cost for the composer badge. used/size feed
2372
- // the context-window % gauge; cost (when the adapter reports it) is
2373
- // cumulative USD; breakdown is the hover detail. Live-only state —
2374
- // the badge naturally refreshes each turn and resets on reconnect.
2375
2461
  const usage = {
2376
2462
  ...(event.used != null ? { used: event.used } : {}),
2377
2463
  ...(event.size != null ? { size: event.size } : {}),
@@ -2383,9 +2469,6 @@ async function runPromptTurn(session, sessionId, promptItem) {
2383
2469
  }
2384
2470
  }
2385
2471
  else if (event.type === "status" && event.tag === "config_option_update") {
2386
- // The agent changed a config option itself (rare — model/effort are
2387
- // usually user-driven). The update is folded into the record, so
2388
- // re-send the authoritative snapshot to refresh the pickers.
2389
2472
  void sendSessionMeta(targetWs, sessionId, currentSession.handle);
2390
2473
  }
2391
2474
  }
@@ -2394,6 +2477,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2394
2477
  console.log(`[acpx-server] Turn finished for session: ${sessionId}. Status: ${result.status}`);
2395
2478
  const currentSession = activeSessions.get(sessionId);
2396
2479
  const targetWs = currentSession ? currentSession.ws : null;
2480
+ const finalResultText = result.finalAnswer || accumulatedAnswer || "";
2397
2481
  const journalTerminal = turn.hostTurnId
2398
2482
  ? await turnJournal.record({
2399
2483
  sessionId,
@@ -2402,7 +2486,7 @@ async function runPromptTurn(session, sessionId, promptItem) {
2402
2486
  status: result.status,
2403
2487
  promptText: promptItem.text,
2404
2488
  agentType: currentSession?.agentType || session.agentType,
2405
- finalAnswer: result.finalAnswer,
2489
+ finalAnswer: result.finalAnswer || finalResultText || undefined,
2406
2490
  errorCode: result.status === "failed" ? result.error?.code || "ACP_PROMPT_FAILED" : undefined,
2407
2491
  errorText: result.status === "failed" ? result.error?.message : undefined,
2408
2492
  runtimeRecordId: currentSession?.handle?.acpxRecordId || session.handle?.acpxRecordId || sessionId,
@@ -2412,7 +2496,25 @@ async function runPromptTurn(session, sessionId, promptItem) {
2412
2496
  terminalSource: "live_runtime",
2413
2497
  })
2414
2498
  : undefined;
2415
- if (targetWs && targetWs.readyState === 1 /* OPEN */) {
2499
+ if (isSummaryMode) {
2500
+ sendSummaryTerminal(targetWs, currentSession, sessionId, {
2501
+ status: result.status,
2502
+ resultText: finalResultText,
2503
+ turnId: turn.hostTurnId || result.agentTurnId || result.runtimeRequestId || requestId,
2504
+ error: result.status === "failed"
2505
+ ? {
2506
+ code: result.error?.code || "ACP_PROMPT_FAILED",
2507
+ message: result.error?.message || "Turn execution failed",
2508
+ }
2509
+ : undefined,
2510
+ stopped: result.status === "cancelled",
2511
+ });
2512
+ if (targetWs && targetWs.readyState === 1 /* OPEN */) {
2513
+ void sendSessionMeta(targetWs, sessionId, currentSession?.handle);
2514
+ }
2515
+ terminalSent = true;
2516
+ }
2517
+ else if (targetWs && targetWs.readyState === 1 /* OPEN */) {
2416
2518
  if (turn.hostTurnId) {
2417
2519
  sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2418
2520
  ...journalTerminal.turn,
@@ -2494,26 +2596,50 @@ async function runPromptTurn(session, sessionId, promptItem) {
2494
2596
  stopReason: "runtime_error",
2495
2597
  terminalSource: "bridge_error",
2496
2598
  });
2497
- sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2498
- ...terminal.turn,
2499
- event: "turn_terminal",
2500
- status: "failed",
2501
- journalSequence: terminal.turn.lastEventSeq,
2502
- stopReason: "runtime_error",
2503
- runtimeRequestId: requestId,
2504
- promptMessageId: requestId,
2505
- completedAt: new Date().toISOString(),
2506
- error: {
2507
- code: "ACP_PROMPT_FAILED",
2508
- message: err?.message || String(err),
2509
- },
2510
- });
2599
+ if (isSummaryMode) {
2600
+ sendSummaryTerminal(targetWs, currentSession, sessionId, {
2601
+ status: "failed",
2602
+ resultText: accumulatedAnswer,
2603
+ turnId: turn.hostTurnId,
2604
+ error: {
2605
+ code: "ACP_PROMPT_FAILED",
2606
+ message: err?.message || String(err),
2607
+ },
2608
+ });
2609
+ }
2610
+ else {
2611
+ sendRuntimeTurnEvent(targetWs, sessionId, turn, {
2612
+ ...terminal.turn,
2613
+ event: "turn_terminal",
2614
+ status: "failed",
2615
+ journalSequence: terminal.turn.lastEventSeq,
2616
+ stopReason: "runtime_error",
2617
+ runtimeRequestId: requestId,
2618
+ promptMessageId: requestId,
2619
+ completedAt: new Date().toISOString(),
2620
+ error: {
2621
+ code: "ACP_PROMPT_FAILED",
2622
+ message: err?.message || String(err),
2623
+ },
2624
+ });
2625
+ }
2511
2626
  terminalSent = true;
2512
2627
  }
2513
2628
  catch (journalError) {
2514
2629
  sendError(targetWs, sessionId, "TURN_JOURNAL_FAILED", journalError?.message || String(journalError));
2515
2630
  }
2516
2631
  }
2632
+ else if (isSummaryMode) {
2633
+ sendSummaryTerminal(targetWs, currentSession, sessionId, {
2634
+ status: "failed",
2635
+ resultText: accumulatedAnswer,
2636
+ turnId: turn.hostTurnId || requestId,
2637
+ error: {
2638
+ code: "ACP_PROMPT_FAILED",
2639
+ message: err?.message || String(err),
2640
+ },
2641
+ });
2642
+ }
2517
2643
  else if (targetWs && targetWs.readyState === 1 /* OPEN */) {
2518
2644
  targetWs.send(JSON.stringify({
2519
2645
  event: "error",
@@ -15,5 +15,5 @@ export declare const DEFAULT_ACP_PORT = 36812;
15
15
  /**
16
16
  * 该 Agent Runtime Service 支持的能力列表
17
17
  */
18
- export declare const ACP_CAPABILITIES: readonly ["agent.prompt", "agent.session", "agent.cancel", "agent.mode", "runtime.claude", "runtime.grok", "runtime.codex"];
18
+ export declare const ACP_CAPABILITIES: readonly ["agent.prompt", "agent.session", "agent.cancel", "agent.mode", "agent.response_policy", "runtime.claude", "runtime.grok", "runtime.codex"];
19
19
  export declare function buildManifest(baseUrl: string): Promise<NodeManifest>;
@@ -19,6 +19,7 @@ export const ACP_CAPABILITIES = [
19
19
  'agent.session',
20
20
  'agent.cancel',
21
21
  'agent.mode',
22
+ 'agent.response_policy',
22
23
  'runtime.claude',
23
24
  'runtime.grok',
24
25
  'runtime.codex',
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@1agents/acp-service",
3
- "version": "0.1.3",
3
+ "version": "0.1.4",
4
4
  "description": "DreamMate Network ACP Agent Runtime Service: cross-agent execution runtime for Claude Code, Grok, Codex and ACP-compatible agents.",
5
5
  "keywords": [
6
6
  "dreammate",