@downcity/agent 1.1.217 → 1.1.224

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 (184) hide show
  1. package/bin/agent/local/Agent.d.ts +1 -34
  2. package/bin/agent/local/Agent.d.ts.map +1 -1
  3. package/bin/agent/local/Agent.js +1 -44
  4. package/bin/agent/local/Agent.js.map +1 -1
  5. package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
  6. package/bin/agent/local/services/AgentAssemblyService.js +35 -2
  7. package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
  8. package/bin/agent/local/services/AgentSessions.d.ts +6 -0
  9. package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
  10. package/bin/agent/local/services/AgentSessions.js +43 -4
  11. package/bin/agent/local/services/AgentSessions.js.map +1 -1
  12. package/bin/agent/remote/RemoteAgent.d.ts +1 -35
  13. package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
  14. package/bin/agent/remote/RemoteAgent.js +1 -37
  15. package/bin/agent/remote/RemoteAgent.js.map +1 -1
  16. package/bin/agent/remote/RemoteSession.d.ts +26 -41
  17. package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
  18. package/bin/agent/remote/RemoteSession.js +75 -107
  19. package/bin/agent/remote/RemoteSession.js.map +1 -1
  20. package/bin/agent/remote/RemoteTransport.d.ts +15 -27
  21. package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
  22. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +10 -21
  23. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
  24. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +24 -46
  25. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
  26. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +10 -20
  27. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
  28. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +10 -16
  29. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
  30. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +2 -2
  31. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  32. package/bin/executor/types/SessionHistoryPaths.d.ts +1 -1
  33. package/bin/executor/types/SessionRecords.d.ts +2 -0
  34. package/bin/executor/types/SessionRecords.d.ts.map +1 -1
  35. package/bin/executor/types/SessionRecords.js.map +1 -1
  36. package/bin/index.d.ts +6 -3
  37. package/bin/index.d.ts.map +1 -1
  38. package/bin/index.js +1 -0
  39. package/bin/index.js.map +1 -1
  40. package/bin/rpc/Client.d.ts +12 -34
  41. package/bin/rpc/Client.d.ts.map +1 -1
  42. package/bin/rpc/Client.js +31 -70
  43. package/bin/rpc/Client.js.map +1 -1
  44. package/bin/session/Session.d.ts +22 -4
  45. package/bin/session/Session.d.ts.map +1 -1
  46. package/bin/session/Session.js +95 -21
  47. package/bin/session/Session.js.map +1 -1
  48. package/bin/session/browse/Browse.d.ts.map +1 -1
  49. package/bin/session/browse/Browse.js +49 -18
  50. package/bin/session/browse/Browse.js.map +1 -1
  51. package/bin/session/recorder/JsonlSessionMessageStore.d.ts +51 -0
  52. package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -0
  53. package/bin/session/recorder/JsonlSessionMessageStore.js +231 -0
  54. package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -0
  55. package/bin/session/recorder/SessionMessageCodec.d.ts +20 -0
  56. package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -0
  57. package/bin/session/recorder/SessionMessageCodec.js +257 -0
  58. package/bin/session/recorder/SessionMessageCodec.js.map +1 -0
  59. package/bin/session/recorder/SessionRecorder.d.ts +186 -0
  60. package/bin/session/recorder/SessionRecorder.d.ts.map +1 -0
  61. package/bin/session/recorder/SessionRecorder.js +655 -0
  62. package/bin/session/recorder/SessionRecorder.js.map +1 -0
  63. package/bin/session/recorder/SessionRecorderCompaction.d.ts +18 -0
  64. package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -0
  65. package/bin/session/recorder/SessionRecorderCompaction.js +142 -0
  66. package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -0
  67. package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +66 -0
  68. package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -0
  69. package/bin/session/recorder/SessionRecorderHistoryStore.js +195 -0
  70. package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -0
  71. package/bin/session/runtime/SessionEventHub.d.ts +12 -5
  72. package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
  73. package/bin/session/runtime/SessionEventHub.js +11 -6
  74. package/bin/session/runtime/SessionEventHub.js.map +1 -1
  75. package/bin/session/runtime/SessionPromptRuntime.d.ts +9 -15
  76. package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
  77. package/bin/session/runtime/SessionPromptRuntime.js +48 -30
  78. package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
  79. package/bin/session/services/SessionStateService.d.ts +9 -5
  80. package/bin/session/services/SessionStateService.d.ts.map +1 -1
  81. package/bin/session/services/SessionStateService.js +138 -74
  82. package/bin/session/services/SessionStateService.js.map +1 -1
  83. package/bin/session/services/SessionTurnService.d.ts +6 -7
  84. package/bin/session/services/SessionTurnService.d.ts.map +1 -1
  85. package/bin/session/services/SessionTurnService.js +84 -60
  86. package/bin/session/services/SessionTurnService.js.map +1 -1
  87. package/bin/session/services/SessionViewService.d.ts +8 -3
  88. package/bin/session/services/SessionViewService.d.ts.map +1 -1
  89. package/bin/session/services/SessionViewService.js +10 -5
  90. package/bin/session/services/SessionViewService.js.map +1 -1
  91. package/bin/session/storage/Paths.d.ts +1 -1
  92. package/bin/session/storage/Paths.d.ts.map +1 -1
  93. package/bin/session/storage/Paths.js +2 -2
  94. package/bin/session/storage/Paths.js.map +1 -1
  95. package/bin/session/storage/Persistence.d.ts +6 -0
  96. package/bin/session/storage/Persistence.d.ts.map +1 -1
  97. package/bin/session/storage/Persistence.js +7 -0
  98. package/bin/session/storage/Persistence.js.map +1 -1
  99. package/bin/session/storage/RuntimeSessionPort.d.ts +3 -3
  100. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  101. package/bin/session/storage/RuntimeSessionPort.js +2 -2
  102. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  103. package/bin/types/agent/SessionActor.d.ts +15 -5
  104. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  105. package/bin/types/rpc/RpcProtocol.d.ts +48 -61
  106. package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
  107. package/bin/types/runtime/agent/AgentContext.d.ts +5 -4
  108. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  109. package/bin/types/runtime/agent/AgentContext.js.map +1 -1
  110. package/bin/types/session/SessionApproval.d.ts +97 -0
  111. package/bin/types/session/SessionApproval.d.ts.map +1 -0
  112. package/bin/types/session/SessionApproval.js +7 -0
  113. package/bin/types/session/SessionApproval.js.map +1 -0
  114. package/bin/types/session/SessionMessage.d.ts +223 -0
  115. package/bin/types/session/SessionMessage.d.ts.map +1 -0
  116. package/bin/types/session/SessionMessage.js +8 -0
  117. package/bin/types/session/SessionMessage.js.map +1 -0
  118. package/bin/types/session/SessionMutation.d.ts +116 -0
  119. package/bin/types/session/SessionMutation.d.ts.map +1 -0
  120. package/bin/types/session/SessionMutation.js +19 -0
  121. package/bin/types/session/SessionMutation.js.map +1 -0
  122. package/bin/types/session/SessionOptions.d.ts +9 -0
  123. package/bin/types/session/SessionOptions.d.ts.map +1 -1
  124. package/package.json +3 -3
  125. package/scripts/agent-env.test.mjs +4 -4
  126. package/scripts/remote-session-reconnect.test.mjs +7 -3
  127. package/scripts/session-action-message.test.mjs +98 -27
  128. package/scripts/session-history-inflight.test.mjs +2 -2
  129. package/scripts/session-list-title.test.mjs +6 -19
  130. package/scripts/session-prompt-runtime.test.mjs +7 -19
  131. package/scripts/session-recorder.test.mjs +199 -0
  132. package/scripts/session-title-event.test.mjs +10 -18
  133. package/src/agent/local/Agent.ts +1 -55
  134. package/src/agent/local/services/AgentAssemblyService.ts +39 -3
  135. package/src/agent/local/services/AgentSessions.ts +48 -3
  136. package/src/agent/remote/RemoteAgent.ts +1 -54
  137. package/src/agent/remote/RemoteSession.ts +106 -136
  138. package/src/agent/remote/RemoteTransport.ts +30 -30
  139. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +52 -77
  140. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +30 -34
  141. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -2
  142. package/src/executor/types/SessionHistoryPaths.ts +1 -1
  143. package/src/executor/types/SessionRecords.ts +2 -0
  144. package/src/index.ts +36 -10
  145. package/src/rpc/Client.ts +58 -95
  146. package/src/session/Session.ts +128 -37
  147. package/src/session/browse/Browse.ts +51 -22
  148. package/src/session/recorder/JsonlSessionMessageStore.ts +246 -0
  149. package/src/session/recorder/SessionMessageCodec.ts +284 -0
  150. package/src/session/recorder/SessionRecorder.ts +871 -0
  151. package/src/session/recorder/SessionRecorderCompaction.ts +188 -0
  152. package/src/session/recorder/SessionRecorderHistoryStore.ts +276 -0
  153. package/src/session/runtime/SessionEventHub.ts +25 -12
  154. package/src/session/runtime/SessionPromptRuntime.ts +60 -43
  155. package/src/session/services/SessionStateService.ts +159 -86
  156. package/src/session/services/SessionTurnService.ts +91 -73
  157. package/src/session/services/SessionViewService.ts +25 -13
  158. package/src/session/storage/Paths.ts +2 -2
  159. package/src/session/storage/Persistence.ts +13 -0
  160. package/src/session/storage/RuntimeSessionPort.ts +8 -9
  161. package/src/types/agent/SessionActor.ts +31 -8
  162. package/src/types/rpc/RpcProtocol.ts +44 -67
  163. package/src/types/runtime/agent/AgentContext.ts +9 -7
  164. package/src/types/session/SessionApproval.ts +108 -0
  165. package/src/types/session/SessionMessage.ts +253 -0
  166. package/src/types/session/SessionMutation.ts +141 -0
  167. package/src/types/session/SessionOptions.ts +25 -0
  168. package/tsconfig.tsbuildinfo +1 -1
  169. package/bin/session/SessionEventMapper.d.ts +0 -32
  170. package/bin/session/SessionEventMapper.d.ts.map +0 -1
  171. package/bin/session/SessionEventMapper.js +0 -131
  172. package/bin/session/SessionEventMapper.js.map +0 -1
  173. package/bin/types/sdk/AgentSessionEvent.d.ts +0 -302
  174. package/bin/types/sdk/AgentSessionEvent.d.ts.map +0 -1
  175. package/bin/types/sdk/AgentSessionEvent.js +0 -9
  176. package/bin/types/sdk/AgentSessionEvent.js.map +0 -1
  177. package/bin/types/sdk/InternalUiChunkEvent.d.ts +0 -100
  178. package/bin/types/sdk/InternalUiChunkEvent.d.ts.map +0 -1
  179. package/bin/types/sdk/InternalUiChunkEvent.js +0 -9
  180. package/bin/types/sdk/InternalUiChunkEvent.js.map +0 -1
  181. package/scripts/session-history-archive.test.mjs +0 -188
  182. package/src/session/SessionEventMapper.ts +0 -148
  183. package/src/types/sdk/AgentSessionEvent.ts +0 -370
  184. package/src/types/sdk/InternalUiChunkEvent.ts +0 -108
@@ -15,18 +15,20 @@ import type {
15
15
  AgentArchiveSessionsResult,
16
16
  AgentCleanArchiveResult,
17
17
  AgentSessionForkInput,
18
- AgentSessionRecordsInput,
19
- AgentSessionRecordsPage,
20
18
  AgentSessionInfo,
21
19
  AgentSessionSummaryPage,
22
20
  AgentSessionSystemSnapshot,
23
21
  AgentSessionSetInput,
24
22
  } from "@/types/agent/SessionTypes.js";
23
+ import type {
24
+ ListSessionMessagesInput,
25
+ SessionMessagePage,
26
+ } from "@/types/session/SessionMessage.js";
25
27
  import type {
26
28
  RemoteAgentPluginActionInput,
27
29
  RemoteAgentPluginActionResult,
28
30
  } from "@/types/agent/RemoteAgentPluginAction.js";
29
- import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
31
+ import type { SessionMutation } from "@/types/session/SessionMutation.js";
30
32
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
31
33
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
32
34
  import type {
@@ -34,13 +36,12 @@ import type {
34
36
  TransportSubscription,
35
37
  } from "@/agent/remote/RemoteTransport.js";
36
38
  import type {
37
- ShellApprovalMode,
38
- ShellApprovalDecisionResult,
39
- ShellApprovalModeUpdateResult,
40
- ShellApprovalModeOption,
41
- ShellSessionApprovalModeView,
42
- ShellApprovalView,
43
- } from "@downcity/shell";
39
+ ResolveSessionApprovalInput,
40
+ SessionApproval,
41
+ SessionApprovalModeSnapshot,
42
+ SessionApprovalResult,
43
+ SetSessionApprovalModeInput,
44
+ } from "@/types/session/SessionApproval.js";
44
45
 
45
46
  type SdkEventsReadyFrame = {
46
47
  /** SDK HTTP events 连接内部 ready 标记。 */
@@ -168,7 +169,7 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
168
169
  async subscribe(params: {
169
170
  session_id: string;
170
171
  on_ready: () => void;
171
- on_event: (event: AgentSessionEvent) => void;
172
+ on_event: (event: SessionMutation) => void;
172
173
  on_close: (error?: unknown) => void;
173
174
  }): Promise<TransportSubscription> {
174
175
  const abort_controller = new AbortController();
@@ -213,32 +214,36 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
213
214
  };
214
215
  }
215
216
 
216
- async records(
217
+ async messages(
217
218
  session_id: string,
218
- input?: AgentSessionRecordsInput,
219
- ): Promise<AgentSessionRecordsPage> {
219
+ input?: ListSessionMessagesInput,
220
+ ): Promise<SessionMessagePage> {
220
221
  const query = new URLSearchParams();
221
222
  if (input?.limit !== undefined) query.set("limit", String(input.limit));
222
223
  if (input?.cursor) query.set("cursor", input.cursor);
223
- if (input?.archive_id) query.set("archive_id", input.archive_id);
224
- if (input?.order) query.set("order", input.order);
225
- if (input?.view) query.set("view", input.view);
224
+ if (input?.before_sequence !== undefined) {
225
+ query.set("before_sequence", String(input.before_sequence));
226
+ }
227
+ if (input?.include_internal) query.set("include_internal", "true");
228
+ if (input?.through_sequence !== undefined) {
229
+ query.set("through_sequence", String(input.through_sequence));
230
+ }
226
231
  const payload = await read_http_json<{
227
232
  success?: boolean;
228
233
  error?: string;
229
- records?: AgentSessionRecordsPage;
234
+ messages?: SessionMessagePage;
230
235
  }>(
231
- `${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/records${
236
+ `${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/messages${
232
237
  query.size > 0 ? `?${query.toString()}` : ""
233
238
  }`,
234
239
  {
235
240
  headers: this.headers(),
236
241
  },
237
242
  );
238
- if (!payload.success || !payload.records || !Array.isArray(payload.records.items)) {
239
- throw new Error(String(payload.error || "Remote session records failed"));
243
+ if (!payload.success || !payload.messages || !Array.isArray(payload.messages.items)) {
244
+ throw new Error(String(payload.error || "Remote session messages failed"));
240
245
  }
241
- return payload.records;
246
+ return payload.messages;
242
247
  }
243
248
 
244
249
  async system(session_id: string): Promise<AgentSessionSystemSnapshot> {
@@ -401,12 +406,12 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
401
406
  return payload;
402
407
  }
403
408
 
404
- async approvals(): Promise<ShellApprovalView[]> {
409
+ async approvals(session_id: string): Promise<SessionApproval[]> {
405
410
  const payload = await read_http_json<{
406
411
  success?: boolean;
407
412
  error?: string;
408
- approvals?: ShellApprovalView[];
409
- }>(`${this.base_url}/api/shell/approvals`, {
413
+ approvals?: SessionApproval[];
414
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approvals`, {
410
415
  headers: this.headers(),
411
416
  });
412
417
  if (!payload.success || !Array.isArray(payload.approvals)) {
@@ -415,28 +420,13 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
415
420
  return payload.approvals;
416
421
  }
417
422
 
418
- async approval_modes(): Promise<ShellApprovalModeOption[]> {
419
- const payload = await read_http_json<{
420
- success?: boolean;
421
- error?: string;
422
- modes?: ShellApprovalModeOption[];
423
- }>(`${this.base_url}/api/shell/approval-modes`, {
424
- headers: this.headers(),
425
- });
426
- if (!payload.success || !Array.isArray(payload.modes)) {
427
- throw new Error(String(payload.error || "Remote shell approval modes failed"));
428
- }
429
- return payload.modes;
430
- }
431
-
432
- async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
433
- const session_id = String(input.session_id || "").trim();
423
+ async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
434
424
  const payload = await read_http_json<{
435
425
  success?: boolean;
436
426
  error?: string;
437
427
  session_id?: string;
438
- mode?: ShellApprovalMode;
439
- }>(`${this.base_url}/api/shell/approval-mode?session_id=${encodeURIComponent(session_id)}`, {
428
+ mode?: SessionApprovalModeSnapshot["mode"];
429
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval-mode`, {
440
430
  headers: this.headers(),
441
431
  });
442
432
  if (!payload.success || !payload.session_id || !payload.mode) {
@@ -448,18 +438,19 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
448
438
  };
449
439
  }
450
440
 
451
- async set_approval_mode(input: {
452
- session_id: string;
453
- mode: ShellApprovalMode;
454
- }): Promise<ShellApprovalModeUpdateResult> {
455
- const payload = await read_http_json<ShellApprovalModeUpdateResult & {
441
+ async set_approval_mode(
442
+ session_id: string,
443
+ input: SetSessionApprovalModeInput,
444
+ ): Promise<SessionApprovalModeSnapshot> {
445
+ const payload = await read_http_json<SessionApprovalModeSnapshot & {
446
+ success?: boolean;
456
447
  error?: string;
457
- }>(`${this.base_url}/api/shell/approval-mode`, {
448
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval-mode`, {
458
449
  method: "POST",
459
450
  headers: this.headers({
460
451
  "Content-Type": "application/json",
461
452
  }),
462
- body: JSON.stringify(input),
453
+ body: JSON.stringify({ mode: input.mode }),
463
454
  });
464
455
  if (payload.success !== true) {
465
456
  throw new Error(String(payload.error || "Remote shell approval mode update failed"));
@@ -467,29 +458,21 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
467
458
  return payload;
468
459
  }
469
460
 
470
- async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
471
- return await this.run_shell_decision("approve", input.approval_id);
472
- }
473
-
474
- async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
475
- return await this.run_shell_decision("deny", input.approval_id);
476
- }
477
-
478
- private async run_shell_decision(
479
- action: "approve" | "deny",
480
- approval_id: string,
481
- ): Promise<ShellApprovalDecisionResult> {
482
- const payload = await read_http_json<ShellApprovalDecisionResult & {
461
+ async resolve_approval(
462
+ session_id: string,
463
+ input: ResolveSessionApprovalInput,
464
+ ): Promise<SessionApprovalResult> {
465
+ const payload = await read_http_json<SessionApprovalResult & {
483
466
  error?: string;
484
- }>(`${this.base_url}/api/shell/${action}`, {
467
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval`, {
485
468
  method: "POST",
486
469
  headers: this.headers({
487
470
  "Content-Type": "application/json",
488
471
  }),
489
- body: JSON.stringify({ approval_id }),
472
+ body: JSON.stringify(input),
490
473
  });
491
474
  if (typeof payload.success !== "boolean") {
492
- throw new Error(String(payload.error || `Remote shell ${action} failed`));
475
+ throw new Error(String(payload.error || "Remote session approval failed"));
493
476
  }
494
477
  return payload;
495
478
  }
@@ -523,7 +506,7 @@ async function consume_http_event_stream(params: {
523
506
  abort_controller: AbortController;
524
507
  on_ready: () => void;
525
508
  on_ready_error: (error: unknown) => void;
526
- on_event: (event: AgentSessionEvent) => void;
509
+ on_event: (event: SessionMutation) => void;
527
510
  }): Promise<unknown | undefined> {
528
511
  const decoder = new TextDecoder();
529
512
  const reader = params.body.getReader();
@@ -546,7 +529,7 @@ async function consume_http_event_stream(params: {
546
529
  ready_resolved = true;
547
530
  params.on_ready();
548
531
  } else {
549
- params.on_event(value as AgentSessionEvent);
532
+ params.on_event(value as SessionMutation);
550
533
  }
551
534
  }
552
535
  newline_index = buffered.indexOf("\n");
@@ -560,7 +543,7 @@ async function consume_http_event_stream(params: {
560
543
  ready_resolved = true;
561
544
  params.on_ready();
562
545
  } else {
563
- params.on_event(value as AgentSessionEvent);
546
+ params.on_event(value as SessionMutation);
564
547
  }
565
548
  }
566
549
 
@@ -570,10 +553,6 @@ async function consume_http_event_stream(params: {
570
553
  params.on_ready_error(error);
571
554
  throw error;
572
555
  }
573
- params.on_event({
574
- type: "error",
575
- message: "Remote session events connection closed",
576
- });
577
556
  }
578
557
  } catch (error) {
579
558
  close_error = error;
@@ -581,10 +560,6 @@ async function consume_http_event_stream(params: {
581
560
  if (!ready_resolved) {
582
561
  params.on_ready_error(error);
583
562
  }
584
- params.on_event({
585
- type: "error",
586
- message: error instanceof Error ? error.message : String(error),
587
- });
588
563
  }
589
564
  } finally {
590
565
  try {
@@ -15,18 +15,20 @@ import type {
15
15
  AgentArchiveSessionsResult,
16
16
  AgentCleanArchiveResult,
17
17
  AgentSessionForkInput,
18
- AgentSessionRecordsInput,
19
- AgentSessionRecordsPage,
20
18
  AgentSessionInfo,
21
19
  AgentSessionSummaryPage,
22
20
  AgentSessionSystemSnapshot,
23
21
  AgentSessionSetInput,
24
22
  } from "@/types/agent/SessionTypes.js";
23
+ import type {
24
+ ListSessionMessagesInput,
25
+ SessionMessagePage,
26
+ } from "@/types/session/SessionMessage.js";
25
27
  import type {
26
28
  RemoteAgentPluginActionInput,
27
29
  RemoteAgentPluginActionResult,
28
30
  } from "@/types/agent/RemoteAgentPluginAction.js";
29
- import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
31
+ import type { SessionMutation } from "@/types/session/SessionMutation.js";
30
32
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
31
33
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
32
34
  import { RpcClient, parse_rpc_url } from "@/rpc/Client.js";
@@ -35,13 +37,12 @@ import type {
35
37
  TransportSubscription,
36
38
  } from "@/agent/remote/RemoteTransport.js";
37
39
  import type {
38
- ShellApprovalMode,
39
- ShellApprovalDecisionResult,
40
- ShellApprovalModeUpdateResult,
41
- ShellApprovalModeOption,
42
- ShellSessionApprovalModeView,
43
- ShellApprovalView,
44
- } from "@downcity/shell";
40
+ ResolveSessionApprovalInput,
41
+ SessionApproval,
42
+ SessionApprovalModeSnapshot,
43
+ SessionApprovalResult,
44
+ SetSessionApprovalModeInput,
45
+ } from "@/types/session/SessionApproval.js";
45
46
 
46
47
  /**
47
48
  * 本机 RPC transport。
@@ -85,7 +86,7 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
85
86
  async subscribe(params: {
86
87
  session_id: string;
87
88
  on_ready: () => void;
88
- on_event: (event: AgentSessionEvent) => void;
89
+ on_event: (event: SessionMutation) => void;
89
90
  on_close: (error?: unknown) => void;
90
91
  }): Promise<TransportSubscription> {
91
92
  const subscription = await this.client.subscribe_session({
@@ -101,11 +102,11 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
101
102
  };
102
103
  }
103
104
 
104
- async records(
105
+ async messages(
105
106
  session_id: string,
106
- input?: AgentSessionRecordsInput,
107
- ): Promise<AgentSessionRecordsPage> {
108
- return await this.client.get_session_records({
107
+ input?: ListSessionMessagesInput,
108
+ ): Promise<SessionMessagePage> {
109
+ return await this.client.get_session_messages({
109
110
  session_id,
110
111
  input,
111
112
  });
@@ -159,31 +160,26 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
159
160
  });
160
161
  }
161
162
 
162
- async approvals(): Promise<ShellApprovalView[]> {
163
- return await this.client.list_shell_approvals();
164
- }
165
-
166
- async approval_modes(): Promise<ShellApprovalModeOption[]> {
167
- return await this.client.list_shell_approval_modes();
168
- }
169
-
170
- async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
171
- return await this.client.get_shell_approval_mode(input.session_id);
163
+ async approvals(session_id: string): Promise<SessionApproval[]> {
164
+ return await this.client.get_session_approvals(session_id);
172
165
  }
173
166
 
174
- async set_approval_mode(input: {
175
- session_id: string;
176
- mode: ShellApprovalMode;
177
- }): Promise<ShellApprovalModeUpdateResult> {
178
- return await this.client.set_shell_approval_mode(input);
167
+ async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
168
+ return await this.client.get_session_approval_mode(session_id);
179
169
  }
180
170
 
181
- async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
182
- return await this.client.approve_shell_approval(input.approval_id);
171
+ async set_approval_mode(
172
+ session_id: string,
173
+ input: SetSessionApprovalModeInput,
174
+ ): Promise<SessionApprovalModeSnapshot> {
175
+ return await this.client.set_session_approval_mode(session_id, input);
183
176
  }
184
177
 
185
- async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
186
- return await this.client.deny_shell_approval(input.approval_id);
178
+ async resolve_approval(
179
+ session_id: string,
180
+ input: ResolveSessionApprovalInput,
181
+ ): Promise<SessionApprovalResult> {
182
+ return await this.client.resolve_session_approval(session_id, input);
187
183
  }
188
184
 
189
185
  async close(): Promise<void> {
@@ -197,9 +197,9 @@ export class JsonlSessionHistoryStore implements SessionHistoryStore {
197
197
  private getInflightFilePath(): string {
198
198
  if (this.overrideInflightFilePath) return this.overrideInflightFilePath;
199
199
  if (this.overrideMessagesDirPath) {
200
- return path.join(this.overrideMessagesDirPath, "inflight.json");
200
+ return path.join(this.overrideMessagesDirPath, "assistant_message.json");
201
201
  }
202
- return path.join(this.getMessagesDirPath(), "inflight.json");
202
+ return path.join(this.getMessagesDirPath(), "assistant_message.json");
203
203
  }
204
204
 
205
205
  private getLockFilePath(): string {
@@ -32,7 +32,7 @@ export type SessionHistoryPathOverrides = {
32
32
  archiveDirPath?: string;
33
33
 
34
34
  /**
35
- * 运行中 assistant 快照路径(通常是 `.../messages/inflight.json`)。
35
+ * 运行中 assistant 快照路径(通常是 `.../messages/assistant_message.json`)。
36
36
  */
37
37
  inflightFilePath?: string;
38
38
  };
@@ -65,6 +65,8 @@ export type SessionMetadataV1 = {
65
65
  ts: number;
66
66
  /** 当前消息所属的 session ID。 */
67
67
  sessionId: string;
68
+ /** 当前消息所属 turn。 */
69
+ turnId?: string;
68
70
  /** 当前消息是普通消息还是摘要消息。 */
69
71
  kind?: SessionMessageKind;
70
72
  /** 当前消息来自入站、出站还是 compact。 */
package/src/index.ts CHANGED
@@ -27,9 +27,6 @@ export type {
27
27
  AgentListSessionsInput,
28
28
  AgentSessionConfigSnapshot,
29
29
  AgentSessionForkInput,
30
- AgentSessionRecordsInput,
31
- AgentSessionRecordsPage,
32
- AgentSessionRecordsView,
33
30
  AgentSessionInfo,
34
31
  AgentSessionSetInput,
35
32
  AgentSessionSummary,
@@ -38,8 +35,42 @@ export type {
38
35
  AgentSessionSystemBlockSource,
39
36
  AgentSessionSystemSessionInfo,
40
37
  AgentSessionSystemSnapshot,
41
- AgentSessionTimelineEvent,
42
38
  } from "./types/agent/SessionTypes.js";
39
+ export type {
40
+ ListSessionMessagesInput,
41
+ SessionActionMessage,
42
+ SessionAssistantMessage,
43
+ SessionAssistantMessagePart,
44
+ SessionAssistantToolPart,
45
+ SessionErrorMessage,
46
+ SessionMessage,
47
+ SessionMessagePage,
48
+ SessionUserMessage,
49
+ SessionUserMessagePart,
50
+ } from "./types/session/SessionMessage.js";
51
+ export {
52
+ is_session_mutation,
53
+ } from "./types/session/SessionMutation.js";
54
+ export type {
55
+ SessionDeltaMutation,
56
+ SessionMessageMutation,
57
+ SessionMutation,
58
+ SessionMutationReply,
59
+ SessionMutationSubscriber,
60
+ SessionMutationUnsubscribe,
61
+ SessionPartMutation,
62
+ SessionStateMutation,
63
+ SessionTurnMutation,
64
+ } from "./types/session/SessionMutation.js";
65
+ export type {
66
+ ResolveSessionApprovalInput,
67
+ SessionApproval,
68
+ SessionApprovalDecision,
69
+ SessionApprovalMode,
70
+ SessionApprovalModeSnapshot,
71
+ SessionApprovalResult,
72
+ SetSessionApprovalModeInput,
73
+ } from "./types/session/SessionApproval.js";
43
74
  export type {
44
75
  AgentOptions,
45
76
  AgentSessionConstructor,
@@ -56,18 +87,13 @@ export type {
56
87
  RemoteAgentPluginActionInput,
57
88
  RemoteAgentPluginActionResult,
58
89
  } from "./types/agent/RemoteAgentPluginAction.js";
59
- export type {
60
- AgentSessionEvent,
61
- AgentSessionSubscriber,
62
- AgentSessionUnsubscribe,
63
- } from "./types/sdk/AgentSessionEvent.js";
64
90
  export type {
65
91
  AgentSessionActionCallback,
66
92
  AgentSessionActionEvent,
67
93
  AgentSessionActionRecord,
68
94
  AgentSessionActionState,
69
95
  } from "./types/sdk/AgentSessionAction.js";
70
- export type { AgentSessionPromptInput, SessionUserMessagePart } from "./types/sdk/AgentSessionPrompt.js";
96
+ export type { AgentSessionPromptInput } from "./types/sdk/AgentSessionPrompt.js";
71
97
  export type { AgentSessionStopResult } from "./types/sdk/AgentSessionStop.js";
72
98
  export type {
73
99
  AgentSessionTurnHandle,