@downcity/agent 1.1.222 → 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 (166) 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 +42 -0
  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 +24 -45
  17. package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
  18. package/bin/agent/remote/RemoteSession.js +74 -121
  19. package/bin/agent/remote/RemoteSession.js.map +1 -1
  20. package/bin/agent/remote/RemoteTransport.d.ts +11 -27
  21. package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
  22. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +7 -21
  23. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
  24. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +11 -47
  25. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
  26. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +7 -20
  27. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
  28. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +8 -17
  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/index.d.ts +3 -3
  34. package/bin/index.d.ts.map +1 -1
  35. package/bin/index.js +1 -1
  36. package/bin/index.js.map +1 -1
  37. package/bin/rpc/Client.d.ts +7 -36
  38. package/bin/rpc/Client.d.ts.map +1 -1
  39. package/bin/rpc/Client.js +28 -78
  40. package/bin/rpc/Client.js.map +1 -1
  41. package/bin/session/Session.d.ts +16 -8
  42. package/bin/session/Session.d.ts.map +1 -1
  43. package/bin/session/Session.js +66 -21
  44. package/bin/session/Session.js.map +1 -1
  45. package/bin/session/browse/Browse.d.ts.map +1 -1
  46. package/bin/session/browse/Browse.js +49 -18
  47. package/bin/session/browse/Browse.js.map +1 -1
  48. package/bin/session/recorder/JsonlSessionMessageStore.d.ts +30 -24
  49. package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -1
  50. package/bin/session/recorder/JsonlSessionMessageStore.js +163 -59
  51. package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -1
  52. package/bin/session/recorder/SessionMessageCodec.d.ts.map +1 -1
  53. package/bin/session/recorder/SessionMessageCodec.js +6 -1
  54. package/bin/session/recorder/SessionMessageCodec.js.map +1 -1
  55. package/bin/session/recorder/SessionRecorder.d.ts +20 -11
  56. package/bin/session/recorder/SessionRecorder.d.ts.map +1 -1
  57. package/bin/session/recorder/SessionRecorder.js +148 -103
  58. package/bin/session/recorder/SessionRecorder.js.map +1 -1
  59. package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -1
  60. package/bin/session/recorder/SessionRecorderCompaction.js +1 -0
  61. package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -1
  62. package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +5 -5
  63. package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -1
  64. package/bin/session/recorder/SessionRecorderHistoryStore.js +5 -5
  65. package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -1
  66. package/bin/session/runtime/SessionEventHub.d.ts +12 -5
  67. package/bin/session/runtime/SessionEventHub.d.ts.map +1 -1
  68. package/bin/session/runtime/SessionEventHub.js +11 -6
  69. package/bin/session/runtime/SessionEventHub.js.map +1 -1
  70. package/bin/session/runtime/SessionPromptRuntime.d.ts +2 -2
  71. package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
  72. package/bin/session/runtime/SessionPromptRuntime.js +35 -17
  73. package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
  74. package/bin/session/services/SessionStateService.d.ts +2 -2
  75. package/bin/session/services/SessionStateService.d.ts.map +1 -1
  76. package/bin/session/services/SessionStateService.js +6 -2
  77. package/bin/session/services/SessionStateService.js.map +1 -1
  78. package/bin/session/services/SessionTurnService.d.ts +2 -7
  79. package/bin/session/services/SessionTurnService.d.ts.map +1 -1
  80. package/bin/session/services/SessionTurnService.js +2 -8
  81. package/bin/session/services/SessionTurnService.js.map +1 -1
  82. package/bin/session/storage/Paths.d.ts +1 -1
  83. package/bin/session/storage/Paths.d.ts.map +1 -1
  84. package/bin/session/storage/Paths.js +2 -2
  85. package/bin/session/storage/Paths.js.map +1 -1
  86. package/bin/session/storage/RuntimeSessionPort.d.ts +3 -4
  87. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  88. package/bin/session/storage/RuntimeSessionPort.js +2 -2
  89. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  90. package/bin/types/agent/SessionActor.d.ts +11 -7
  91. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  92. package/bin/types/rpc/RpcProtocol.d.ts +35 -62
  93. package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
  94. package/bin/types/runtime/agent/AgentContext.d.ts +4 -4
  95. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  96. package/bin/types/runtime/agent/AgentContext.js.map +1 -1
  97. package/bin/types/session/SessionApproval.d.ts +97 -0
  98. package/bin/types/session/SessionApproval.d.ts.map +1 -0
  99. package/bin/types/session/SessionApproval.js +7 -0
  100. package/bin/types/session/SessionApproval.js.map +1 -0
  101. package/bin/types/session/SessionMessage.d.ts +10 -4
  102. package/bin/types/session/SessionMessage.d.ts.map +1 -1
  103. package/bin/types/session/SessionMutation.d.ts +116 -0
  104. package/bin/types/session/SessionMutation.d.ts.map +1 -0
  105. package/bin/types/session/SessionMutation.js +19 -0
  106. package/bin/types/session/SessionMutation.js.map +1 -0
  107. package/bin/types/session/SessionOptions.d.ts +9 -0
  108. package/bin/types/session/SessionOptions.d.ts.map +1 -1
  109. package/package.json +3 -3
  110. package/scripts/remote-session-reconnect.test.mjs +7 -3
  111. package/scripts/session-history-inflight.test.mjs +2 -2
  112. package/scripts/session-prompt-runtime.test.mjs +3 -3
  113. package/scripts/session-recorder.test.mjs +100 -146
  114. package/src/agent/local/Agent.ts +1 -55
  115. package/src/agent/local/services/AgentAssemblyService.ts +39 -3
  116. package/src/agent/local/services/AgentSessions.ts +47 -0
  117. package/src/agent/remote/RemoteAgent.ts +1 -54
  118. package/src/agent/remote/RemoteSession.ts +105 -163
  119. package/src/agent/remote/RemoteTransport.ts +23 -34
  120. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +33 -90
  121. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +22 -39
  122. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -2
  123. package/src/executor/types/SessionHistoryPaths.ts +1 -1
  124. package/src/index.ts +20 -12
  125. package/src/rpc/Client.ts +48 -106
  126. package/src/session/Session.ts +91 -34
  127. package/src/session/browse/Browse.ts +51 -22
  128. package/src/session/recorder/JsonlSessionMessageStore.ts +170 -86
  129. package/src/session/recorder/SessionMessageCodec.ts +6 -1
  130. package/src/session/recorder/SessionRecorder.ts +183 -124
  131. package/src/session/recorder/SessionRecorderCompaction.ts +1 -0
  132. package/src/session/recorder/SessionRecorderHistoryStore.ts +5 -5
  133. package/src/session/runtime/SessionEventHub.ts +25 -12
  134. package/src/session/runtime/SessionPromptRuntime.ts +37 -19
  135. package/src/session/services/SessionStateService.ts +8 -6
  136. package/src/session/services/SessionTurnService.ts +3 -14
  137. package/src/session/storage/Paths.ts +2 -2
  138. package/src/session/storage/RuntimeSessionPort.ts +8 -11
  139. package/src/types/agent/SessionActor.ts +23 -20
  140. package/src/types/rpc/RpcProtocol.ts +34 -71
  141. package/src/types/runtime/agent/AgentContext.ts +7 -11
  142. package/src/types/session/SessionApproval.ts +108 -0
  143. package/src/types/session/SessionMessage.ts +10 -4
  144. package/src/types/session/SessionMutation.ts +141 -0
  145. package/src/types/session/SessionOptions.ts +25 -0
  146. package/tsconfig.tsbuildinfo +1 -1
  147. package/bin/session/recorder/SessionMessageReducer.d.ts +0 -12
  148. package/bin/session/recorder/SessionMessageReducer.d.ts.map +0 -1
  149. package/bin/session/recorder/SessionMessageReducer.js +0 -109
  150. package/bin/session/recorder/SessionMessageReducer.js.map +0 -1
  151. package/bin/session/runtime/SessionMessageEventHub.d.ts +0 -15
  152. package/bin/session/runtime/SessionMessageEventHub.d.ts.map +0 -1
  153. package/bin/session/runtime/SessionMessageEventHub.js +0 -28
  154. package/bin/session/runtime/SessionMessageEventHub.js.map +0 -1
  155. package/bin/types/sdk/AgentSessionEvent.d.ts +0 -303
  156. package/bin/types/sdk/AgentSessionEvent.d.ts.map +0 -1
  157. package/bin/types/sdk/AgentSessionEvent.js +0 -9
  158. package/bin/types/sdk/AgentSessionEvent.js.map +0 -1
  159. package/bin/types/session/SessionMessageMutation.d.ts +0 -92
  160. package/bin/types/session/SessionMessageMutation.d.ts.map +0 -1
  161. package/bin/types/session/SessionMessageMutation.js +0 -21
  162. package/bin/types/session/SessionMessageMutation.js.map +0 -1
  163. package/src/session/recorder/SessionMessageReducer.ts +0 -155
  164. package/src/session/runtime/SessionMessageEventHub.ts +0 -35
  165. package/src/types/sdk/AgentSessionEvent.ts +0 -372
  166. package/src/types/session/SessionMessageMutation.ts +0 -121
@@ -24,15 +24,11 @@ import type {
24
24
  ListSessionMessagesInput,
25
25
  SessionMessagePage,
26
26
  } from "@/types/session/SessionMessage.js";
27
- import type {
28
- ListSessionMessageChangesInput,
29
- SessionMessageMutationPage,
30
- } from "@/types/session/SessionMessageMutation.js";
31
27
  import type {
32
28
  RemoteAgentPluginActionInput,
33
29
  RemoteAgentPluginActionResult,
34
30
  } from "@/types/agent/RemoteAgentPluginAction.js";
35
- import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
31
+ import type { SessionMutation } from "@/types/session/SessionMutation.js";
36
32
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
37
33
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
38
34
  import type {
@@ -40,13 +36,12 @@ import type {
40
36
  TransportSubscription,
41
37
  } from "@/agent/remote/RemoteTransport.js";
42
38
  import type {
43
- ShellApprovalMode,
44
- ShellApprovalDecisionResult,
45
- ShellApprovalModeUpdateResult,
46
- ShellApprovalModeOption,
47
- ShellSessionApprovalModeView,
48
- ShellApprovalView,
49
- } from "@downcity/shell";
39
+ ResolveSessionApprovalInput,
40
+ SessionApproval,
41
+ SessionApprovalModeSnapshot,
42
+ SessionApprovalResult,
43
+ SetSessionApprovalModeInput,
44
+ } from "@/types/session/SessionApproval.js";
50
45
 
51
46
  type SdkEventsReadyFrame = {
52
47
  /** SDK HTTP events 连接内部 ready 标记。 */
@@ -174,7 +169,7 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
174
169
  async subscribe(params: {
175
170
  session_id: string;
176
171
  on_ready: () => void;
177
- on_event: (event: AgentSessionEvent) => void;
172
+ on_event: (event: SessionMutation) => void;
178
173
  on_close: (error?: unknown) => void;
179
174
  }): Promise<TransportSubscription> {
180
175
  const abort_controller = new AbortController();
@@ -251,28 +246,6 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
251
246
  return payload.messages;
252
247
  }
253
248
 
254
- async message_changes(
255
- session_id: string,
256
- input: ListSessionMessageChangesInput,
257
- ): Promise<SessionMessageMutationPage> {
258
- const query = new URLSearchParams({
259
- after_commit_sequence: String(input.after_commit_sequence),
260
- });
261
- if (input.limit !== undefined) query.set("limit", String(input.limit));
262
- const payload = await read_http_json<{
263
- success?: boolean;
264
- error?: string;
265
- changes?: SessionMessageMutationPage;
266
- }>(
267
- `${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/message-changes?${query.toString()}`,
268
- { headers: this.headers() },
269
- );
270
- if (!payload.success || !payload.changes) {
271
- throw new Error(String(payload.error || "Remote session message changes failed"));
272
- }
273
- return payload.changes;
274
- }
275
-
276
249
  async system(session_id: string): Promise<AgentSessionSystemSnapshot> {
277
250
  const payload = await read_http_json<{
278
251
  success?: boolean;
@@ -433,12 +406,12 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
433
406
  return payload;
434
407
  }
435
408
 
436
- async approvals(): Promise<ShellApprovalView[]> {
409
+ async approvals(session_id: string): Promise<SessionApproval[]> {
437
410
  const payload = await read_http_json<{
438
411
  success?: boolean;
439
412
  error?: string;
440
- approvals?: ShellApprovalView[];
441
- }>(`${this.base_url}/api/shell/approvals`, {
413
+ approvals?: SessionApproval[];
414
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approvals`, {
442
415
  headers: this.headers(),
443
416
  });
444
417
  if (!payload.success || !Array.isArray(payload.approvals)) {
@@ -447,28 +420,13 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
447
420
  return payload.approvals;
448
421
  }
449
422
 
450
- async approval_modes(): Promise<ShellApprovalModeOption[]> {
451
- const payload = await read_http_json<{
452
- success?: boolean;
453
- error?: string;
454
- modes?: ShellApprovalModeOption[];
455
- }>(`${this.base_url}/api/shell/approval-modes`, {
456
- headers: this.headers(),
457
- });
458
- if (!payload.success || !Array.isArray(payload.modes)) {
459
- throw new Error(String(payload.error || "Remote shell approval modes failed"));
460
- }
461
- return payload.modes;
462
- }
463
-
464
- async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
465
- const session_id = String(input.session_id || "").trim();
423
+ async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
466
424
  const payload = await read_http_json<{
467
425
  success?: boolean;
468
426
  error?: string;
469
427
  session_id?: string;
470
- mode?: ShellApprovalMode;
471
- }>(`${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`, {
472
430
  headers: this.headers(),
473
431
  });
474
432
  if (!payload.success || !payload.session_id || !payload.mode) {
@@ -480,18 +438,19 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
480
438
  };
481
439
  }
482
440
 
483
- async set_approval_mode(input: {
484
- session_id: string;
485
- mode: ShellApprovalMode;
486
- }): Promise<ShellApprovalModeUpdateResult> {
487
- 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;
488
447
  error?: string;
489
- }>(`${this.base_url}/api/shell/approval-mode`, {
448
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval-mode`, {
490
449
  method: "POST",
491
450
  headers: this.headers({
492
451
  "Content-Type": "application/json",
493
452
  }),
494
- body: JSON.stringify(input),
453
+ body: JSON.stringify({ mode: input.mode }),
495
454
  });
496
455
  if (payload.success !== true) {
497
456
  throw new Error(String(payload.error || "Remote shell approval mode update failed"));
@@ -499,29 +458,21 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
499
458
  return payload;
500
459
  }
501
460
 
502
- async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
503
- return await this.run_shell_decision("approve", input.approval_id);
504
- }
505
-
506
- async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
507
- return await this.run_shell_decision("deny", input.approval_id);
508
- }
509
-
510
- private async run_shell_decision(
511
- action: "approve" | "deny",
512
- approval_id: string,
513
- ): Promise<ShellApprovalDecisionResult> {
514
- 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 & {
515
466
  error?: string;
516
- }>(`${this.base_url}/api/shell/${action}`, {
467
+ }>(`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/approval`, {
517
468
  method: "POST",
518
469
  headers: this.headers({
519
470
  "Content-Type": "application/json",
520
471
  }),
521
- body: JSON.stringify({ approval_id }),
472
+ body: JSON.stringify(input),
522
473
  });
523
474
  if (typeof payload.success !== "boolean") {
524
- throw new Error(String(payload.error || `Remote shell ${action} failed`));
475
+ throw new Error(String(payload.error || "Remote session approval failed"));
525
476
  }
526
477
  return payload;
527
478
  }
@@ -555,7 +506,7 @@ async function consume_http_event_stream(params: {
555
506
  abort_controller: AbortController;
556
507
  on_ready: () => void;
557
508
  on_ready_error: (error: unknown) => void;
558
- on_event: (event: AgentSessionEvent) => void;
509
+ on_event: (event: SessionMutation) => void;
559
510
  }): Promise<unknown | undefined> {
560
511
  const decoder = new TextDecoder();
561
512
  const reader = params.body.getReader();
@@ -578,7 +529,7 @@ async function consume_http_event_stream(params: {
578
529
  ready_resolved = true;
579
530
  params.on_ready();
580
531
  } else {
581
- params.on_event(value as AgentSessionEvent);
532
+ params.on_event(value as SessionMutation);
582
533
  }
583
534
  }
584
535
  newline_index = buffered.indexOf("\n");
@@ -592,7 +543,7 @@ async function consume_http_event_stream(params: {
592
543
  ready_resolved = true;
593
544
  params.on_ready();
594
545
  } else {
595
- params.on_event(value as AgentSessionEvent);
546
+ params.on_event(value as SessionMutation);
596
547
  }
597
548
  }
598
549
 
@@ -602,10 +553,6 @@ async function consume_http_event_stream(params: {
602
553
  params.on_ready_error(error);
603
554
  throw error;
604
555
  }
605
- params.on_event({
606
- type: "error",
607
- message: "Remote session events connection closed",
608
- });
609
556
  }
610
557
  } catch (error) {
611
558
  close_error = error;
@@ -613,10 +560,6 @@ async function consume_http_event_stream(params: {
613
560
  if (!ready_resolved) {
614
561
  params.on_ready_error(error);
615
562
  }
616
- params.on_event({
617
- type: "error",
618
- message: error instanceof Error ? error.message : String(error),
619
- });
620
563
  }
621
564
  } finally {
622
565
  try {
@@ -24,15 +24,11 @@ import type {
24
24
  ListSessionMessagesInput,
25
25
  SessionMessagePage,
26
26
  } from "@/types/session/SessionMessage.js";
27
- import type {
28
- ListSessionMessageChangesInput,
29
- SessionMessageMutationPage,
30
- } from "@/types/session/SessionMessageMutation.js";
31
27
  import type {
32
28
  RemoteAgentPluginActionInput,
33
29
  RemoteAgentPluginActionResult,
34
30
  } from "@/types/agent/RemoteAgentPluginAction.js";
35
- import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
31
+ import type { SessionMutation } from "@/types/session/SessionMutation.js";
36
32
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
37
33
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
38
34
  import { RpcClient, parse_rpc_url } from "@/rpc/Client.js";
@@ -41,13 +37,12 @@ import type {
41
37
  TransportSubscription,
42
38
  } from "@/agent/remote/RemoteTransport.js";
43
39
  import type {
44
- ShellApprovalMode,
45
- ShellApprovalDecisionResult,
46
- ShellApprovalModeUpdateResult,
47
- ShellApprovalModeOption,
48
- ShellSessionApprovalModeView,
49
- ShellApprovalView,
50
- } from "@downcity/shell";
40
+ ResolveSessionApprovalInput,
41
+ SessionApproval,
42
+ SessionApprovalModeSnapshot,
43
+ SessionApprovalResult,
44
+ SetSessionApprovalModeInput,
45
+ } from "@/types/session/SessionApproval.js";
51
46
 
52
47
  /**
53
48
  * 本机 RPC transport。
@@ -91,7 +86,7 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
91
86
  async subscribe(params: {
92
87
  session_id: string;
93
88
  on_ready: () => void;
94
- on_event: (event: AgentSessionEvent) => void;
89
+ on_event: (event: SessionMutation) => void;
95
90
  on_close: (error?: unknown) => void;
96
91
  }): Promise<TransportSubscription> {
97
92
  const subscription = await this.client.subscribe_session({
@@ -117,13 +112,6 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
117
112
  });
118
113
  }
119
114
 
120
- async message_changes(
121
- session_id: string,
122
- input: ListSessionMessageChangesInput,
123
- ): Promise<SessionMessageMutationPage> {
124
- return await this.client.get_session_message_changes({ session_id, input });
125
- }
126
-
127
115
  async system(session_id: string): Promise<AgentSessionSystemSnapshot> {
128
116
  return await this.client.get_session_system(session_id);
129
117
  }
@@ -172,31 +160,26 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
172
160
  });
173
161
  }
174
162
 
175
- async approvals(): Promise<ShellApprovalView[]> {
176
- return await this.client.list_shell_approvals();
177
- }
178
-
179
- async approval_modes(): Promise<ShellApprovalModeOption[]> {
180
- return await this.client.list_shell_approval_modes();
163
+ async approvals(session_id: string): Promise<SessionApproval[]> {
164
+ return await this.client.get_session_approvals(session_id);
181
165
  }
182
166
 
183
- async approval_mode(input: { session_id: string }): Promise<ShellSessionApprovalModeView> {
184
- return await this.client.get_shell_approval_mode(input.session_id);
167
+ async approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
168
+ return await this.client.get_session_approval_mode(session_id);
185
169
  }
186
170
 
187
- async set_approval_mode(input: {
188
- session_id: string;
189
- mode: ShellApprovalMode;
190
- }): Promise<ShellApprovalModeUpdateResult> {
191
- return await this.client.set_shell_approval_mode(input);
192
- }
193
-
194
- async approve(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
195
- 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);
196
176
  }
197
177
 
198
- async deny(input: { approval_id: string }): Promise<ShellApprovalDecisionResult> {
199
- 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);
200
183
  }
201
184
 
202
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
  };
package/src/index.ts CHANGED
@@ -49,15 +49,28 @@ export type {
49
49
  SessionUserMessagePart,
50
50
  } from "./types/session/SessionMessage.js";
51
51
  export {
52
- is_session_message_mutation,
53
- } from "./types/session/SessionMessageMutation.js";
52
+ is_session_mutation,
53
+ } from "./types/session/SessionMutation.js";
54
54
  export type {
55
- ListSessionMessageChangesInput,
55
+ SessionDeltaMutation,
56
56
  SessionMessageMutation,
57
- SessionMessageMutationPage,
58
- SessionMessageMutationSubscriber,
59
- SessionMessageMutationUnsubscribe,
60
- } from "./types/session/SessionMessageMutation.js";
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";
61
74
  export type {
62
75
  AgentOptions,
63
76
  AgentSessionConstructor,
@@ -74,11 +87,6 @@ export type {
74
87
  RemoteAgentPluginActionInput,
75
88
  RemoteAgentPluginActionResult,
76
89
  } from "./types/agent/RemoteAgentPluginAction.js";
77
- export type {
78
- AgentSessionEvent,
79
- AgentSessionSubscriber,
80
- AgentSessionUnsubscribe,
81
- } from "./types/sdk/AgentSessionEvent.js";
82
90
  export type {
83
91
  AgentSessionActionCallback,
84
92
  AgentSessionActionEvent,
package/src/rpc/Client.ts CHANGED
@@ -25,10 +25,6 @@ import type {
25
25
  ListSessionMessagesInput,
26
26
  SessionMessagePage,
27
27
  } from "@/types/session/SessionMessage.js";
28
- import type {
29
- ListSessionMessageChangesInput,
30
- SessionMessageMutationPage,
31
- } from "@/types/session/SessionMessageMutation.js";
32
28
  import type { JsonValue } from "@/types/common/Json.js";
33
29
  import type { JsonObject } from "@/types/common/Json.js";
34
30
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
@@ -42,7 +38,14 @@ import type {
42
38
  PluginControlResult,
43
39
  PluginSnapshot,
44
40
  } from "@/types/plugin/PluginState.js";
45
- import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
41
+ import type { SessionMutation } from "@/types/session/SessionMutation.js";
42
+ import type {
43
+ ResolveSessionApprovalInput,
44
+ SessionApproval,
45
+ SessionApprovalModeSnapshot,
46
+ SessionApprovalResult,
47
+ SetSessionApprovalModeInput,
48
+ } from "@/types/session/SessionApproval.js";
46
49
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
47
50
  import type {
48
51
  RpcClientEndpoint,
@@ -51,14 +54,6 @@ import type {
51
54
  RpcSessionSubscription,
52
55
  RpcSystemPromptPayload,
53
56
  } from "@/types/rpc/RpcProtocol.js";
54
- import type {
55
- ShellApprovalMode,
56
- ShellApprovalDecisionResult,
57
- ShellApprovalModeUpdateResult,
58
- ShellApprovalModeOption,
59
- ShellSessionApprovalModeView,
60
- ShellApprovalView,
61
- } from "@downcity/shell";
62
57
 
63
58
  export type {
64
59
  RpcClientEndpoint,
@@ -73,7 +68,7 @@ type PendingRequest = {
73
68
 
74
69
  type RpcSubscription = {
75
70
  on_ready: () => void;
76
- on_event: (event: AgentSessionEvent) => void;
71
+ on_event: (event: SessionMutation) => void;
77
72
  /** 底层 RPC 连接结束后的通知。 */
78
73
  on_close: (error?: unknown) => void;
79
74
  };
@@ -239,21 +234,6 @@ export class RpcClient {
239
234
  return data.messages;
240
235
  }
241
236
 
242
- /** 读取指定 cursor 后的 Session Message Mutation。 */
243
- async get_session_message_changes(params: {
244
- session_id: string;
245
- input: ListSessionMessageChangesInput;
246
- }): Promise<SessionMessageMutationPage> {
247
- const data = await this.request<{ changes: SessionMessageMutationPage }>({
248
- method: "sdk.sessions.message_changes",
249
- params: {
250
- sessionId: params.session_id,
251
- input: params.input,
252
- },
253
- });
254
- return data.changes;
255
- }
256
-
257
237
  /**
258
238
  * 读取 system snapshot。
259
239
  */
@@ -267,6 +247,44 @@ export class RpcClient {
267
247
  return data.system;
268
248
  }
269
249
 
250
+ async get_session_approvals(session_id: string): Promise<SessionApproval[]> {
251
+ const data = await this.request<{ approvals: SessionApproval[] }>({
252
+ method: "sdk.sessions.approvals",
253
+ params: { sessionId: session_id },
254
+ });
255
+ return data.approvals;
256
+ }
257
+
258
+ async get_session_approval_mode(session_id: string): Promise<SessionApprovalModeSnapshot> {
259
+ const data = await this.request<{ approval_mode: SessionApprovalModeSnapshot }>({
260
+ method: "sdk.sessions.approvalMode",
261
+ params: { sessionId: session_id },
262
+ });
263
+ return data.approval_mode;
264
+ }
265
+
266
+ async set_session_approval_mode(
267
+ session_id: string,
268
+ input: SetSessionApprovalModeInput,
269
+ ): Promise<SessionApprovalModeSnapshot> {
270
+ const data = await this.request<{ approval_mode: SessionApprovalModeSnapshot }>({
271
+ method: "sdk.sessions.setApprovalMode",
272
+ params: { sessionId: session_id, input },
273
+ });
274
+ return data.approval_mode;
275
+ }
276
+
277
+ async resolve_session_approval(
278
+ session_id: string,
279
+ input: ResolveSessionApprovalInput,
280
+ ): Promise<SessionApprovalResult> {
281
+ const data = await this.request<{ result: SessionApprovalResult }>({
282
+ method: "sdk.sessions.resolveApproval",
283
+ params: { sessionId: session_id, input },
284
+ });
285
+ return data.result;
286
+ }
287
+
270
288
  /**
271
289
  * 分叉 session。
272
290
  */
@@ -290,7 +308,7 @@ export class RpcClient {
290
308
  async subscribe_session(params: {
291
309
  session_id: string;
292
310
  on_ready: () => void;
293
- on_event: (event: AgentSessionEvent) => void;
311
+ on_event: (event: SessionMutation) => void;
294
312
  on_close: (error?: unknown) => void;
295
313
  }): Promise<RpcSessionSubscription> {
296
314
  const data = await this.request<{ subscriptionId: string }>({
@@ -471,78 +489,6 @@ export class RpcClient {
471
489
  });
472
490
  }
473
491
 
474
- /**
475
- * 列出 shell approvals。
476
- */
477
- async list_shell_approvals(): Promise<ShellApprovalView[]> {
478
- const data = await this.request<{ approvals: ShellApprovalView[] }>({
479
- method: "internal.shell.approvals",
480
- });
481
- return Array.isArray(data.approvals) ? data.approvals : [];
482
- }
483
-
484
- /**
485
- * 列出 shell approval 模式。
486
- */
487
- async list_shell_approval_modes(): Promise<ShellApprovalModeOption[]> {
488
- const data = await this.request<{ modes: ShellApprovalModeOption[] }>({
489
- method: "internal.shell.approvalModes",
490
- });
491
- return Array.isArray(data.modes) ? data.modes : [];
492
- }
493
-
494
- /**
495
- * 读取 shell approval 模式。
496
- */
497
- async get_shell_approval_mode(session_id: string): Promise<ShellSessionApprovalModeView> {
498
- return await this.request<ShellSessionApprovalModeView>({
499
- method: "internal.shell.approvalMode",
500
- params: {
501
- sessionId: session_id,
502
- },
503
- });
504
- }
505
-
506
- /**
507
- * 设置 shell approval 模式。
508
- */
509
- async set_shell_approval_mode(input: {
510
- session_id: string;
511
- mode: ShellApprovalMode;
512
- }): Promise<ShellApprovalModeUpdateResult> {
513
- return await this.request<ShellApprovalModeUpdateResult>({
514
- method: "internal.shell.setApprovalMode",
515
- params: {
516
- sessionId: input.session_id,
517
- mode: input.mode,
518
- },
519
- });
520
- }
521
-
522
- /**
523
- * 批准 shell approval。
524
- */
525
- async approve_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
526
- return await this.request<ShellApprovalDecisionResult>({
527
- method: "internal.shell.approve",
528
- params: {
529
- approvalId: approval_id,
530
- },
531
- });
532
- }
533
-
534
- /**
535
- * 拒绝 shell approval。
536
- */
537
- async deny_shell_approval(approval_id: string): Promise<ShellApprovalDecisionResult> {
538
- return await this.request<ShellApprovalDecisionResult>({
539
- method: "internal.shell.deny",
540
- params: {
541
- approvalId: approval_id,
542
- },
543
- });
544
- }
545
-
546
492
  /**
547
493
  * 关闭底层连接。
548
494
  */
@@ -690,10 +636,6 @@ export class RpcClient {
690
636
 
691
637
  private fail_all_subscriptions(message: string): void {
692
638
  for (const subscription of this.subscriptions.values()) {
693
- subscription.on_event({
694
- type: "error",
695
- message,
696
- });
697
639
  subscription.on_close(new Error(message));
698
640
  }
699
641
  this.subscriptions.clear();