@downcity/agent 1.1.199 → 1.1.202

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 (247) hide show
  1. package/bin/agent/local/Agent.d.ts +3 -7
  2. package/bin/agent/local/Agent.d.ts.map +1 -1
  3. package/bin/agent/local/Agent.js +14 -19
  4. package/bin/agent/local/Agent.js.map +1 -1
  5. package/bin/agent/local/services/{AgentSessionManager.d.ts → AgentSessions.d.ts} +12 -17
  6. package/bin/agent/local/services/AgentSessions.d.ts.map +1 -0
  7. package/bin/agent/local/services/{AgentSessionManager.js → AgentSessions.js} +11 -26
  8. package/bin/agent/local/services/AgentSessions.js.map +1 -0
  9. package/bin/agent/remote/RemoteAgent.d.ts +2 -9
  10. package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
  11. package/bin/agent/remote/RemoteAgent.js +40 -22
  12. package/bin/agent/remote/RemoteAgent.js.map +1 -1
  13. package/bin/agent/remote/RemoteSession.d.ts +5 -5
  14. package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
  15. package/bin/agent/remote/RemoteSession.js +5 -3
  16. package/bin/agent/remote/RemoteSession.js.map +1 -1
  17. package/bin/agent/remote/RemoteTransport.d.ts +2 -2
  18. package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +2 -2
  19. package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +5 -5
  20. package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +2 -2
  21. package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +2 -2
  22. package/bin/executor/Executor.d.ts +7 -7
  23. package/bin/executor/Executor.d.ts.map +1 -1
  24. package/bin/executor/Executor.js +41 -33
  25. package/bin/executor/Executor.js.map +1 -1
  26. package/bin/executor/SessionRunScope.d.ts +1 -1
  27. package/bin/executor/SessionRunScope.d.ts.map +1 -1
  28. package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +5 -5
  29. package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
  30. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +1 -1
  31. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
  32. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +4 -5
  33. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
  34. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +73 -40
  35. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
  36. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts +27 -0
  37. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts.map +1 -0
  38. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js +181 -0
  39. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js.map +1 -0
  40. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +45 -0
  41. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +1 -0
  42. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +144 -0
  43. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +1 -0
  44. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +3 -3
  45. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
  46. package/bin/executor/composer/context/SessionContextComposer.d.ts +3 -3
  47. package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
  48. package/bin/executor/composer/history/SessionHistoryComposer.d.ts +2 -2
  49. package/bin/executor/composer/history/SessionHistoryComposer.d.ts.map +1 -1
  50. package/bin/executor/composer/history/SessionHistoryWriter.d.ts +5 -5
  51. package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
  52. package/bin/executor/composer/history/SessionHistoryWriter.js +6 -6
  53. package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
  54. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +2 -2
  55. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +1 -1
  56. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js +5 -4
  57. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +1 -1
  58. package/bin/executor/core-engine/CoreEngineMessageState.d.ts +5 -5
  59. package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
  60. package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
  61. package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
  62. package/bin/executor/core-engine/CoreEngineSignals.d.ts +4 -4
  63. package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
  64. package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
  65. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +3 -3
  66. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
  67. package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
  68. package/bin/executor/messages/AssistantResultPersistence.d.ts +5 -5
  69. package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
  70. package/bin/executor/messages/AssistantResultPersistence.js +1 -1
  71. package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
  72. package/bin/executor/messages/SessionAttachmentMapper.d.ts +3 -3
  73. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
  74. package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
  75. package/bin/executor/messages/SessionMessageCodec.d.ts +4 -4
  76. package/bin/executor/messages/SessionMessageCodec.d.ts.map +1 -1
  77. package/bin/executor/messages/SessionMessageCodec.js +5 -5
  78. package/bin/executor/messages/SessionMessageCodec.js.map +1 -1
  79. package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
  80. package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
  81. package/bin/executor/messages/SessionMessageLog.js.map +1 -1
  82. package/bin/executor/messages/SessionStepEventMapper.d.ts +2 -2
  83. package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
  84. package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
  85. package/bin/executor/messages/UserVisibleText.d.ts +3 -3
  86. package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
  87. package/bin/executor/messages/UserVisibleText.js +3 -3
  88. package/bin/executor/messages/UserVisibleText.js.map +1 -1
  89. package/bin/executor/services/ExecutorInflightService.d.ts +2 -2
  90. package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
  91. package/bin/executor/services/ExecutorInflightService.js +11 -7
  92. package/bin/executor/services/ExecutorInflightService.js.map +1 -1
  93. package/bin/executor/store/history/SessionHistoryStore.d.ts +30 -27
  94. package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
  95. package/bin/executor/store/history/SessionHistoryStore.js +3 -3
  96. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +21 -20
  97. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
  98. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +114 -72
  99. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  100. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +1 -7
  101. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -1
  102. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +4 -6
  103. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -1
  104. package/bin/executor/tools/plugin/PluginToolSchemas.js +24 -10
  105. package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -1
  106. package/bin/executor/types/SessionRecords.d.ts +162 -0
  107. package/bin/executor/types/SessionRecords.d.ts.map +1 -0
  108. package/bin/executor/types/SessionRecords.js +52 -0
  109. package/bin/executor/types/SessionRecords.js.map +1 -0
  110. package/bin/executor/types/SessionRun.d.ts +3 -3
  111. package/bin/executor/types/SessionRun.d.ts.map +1 -1
  112. package/bin/index.d.ts +2 -2
  113. package/bin/index.d.ts.map +1 -1
  114. package/bin/index.js.map +1 -1
  115. package/bin/rpc/Client.d.ts +5 -5
  116. package/bin/rpc/Client.js +4 -4
  117. package/bin/session/Session.d.ts +6 -6
  118. package/bin/session/Session.d.ts.map +1 -1
  119. package/bin/session/Session.js +8 -8
  120. package/bin/session/Session.js.map +1 -1
  121. package/bin/session/SessionTitle.d.ts +2 -2
  122. package/bin/session/SessionTitle.d.ts.map +1 -1
  123. package/bin/session/SessionTitle.js +5 -0
  124. package/bin/session/SessionTitle.js.map +1 -1
  125. package/bin/session/browse/Browse.d.ts +12 -12
  126. package/bin/session/browse/Browse.d.ts.map +1 -1
  127. package/bin/session/browse/Browse.js +37 -34
  128. package/bin/session/browse/Browse.js.map +1 -1
  129. package/bin/session/index.d.ts +1 -1
  130. package/bin/session/index.js +1 -1
  131. package/bin/session/runtime/SessionPromptRuntime.d.ts +3 -3
  132. package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
  133. package/bin/session/services/SessionStateService.d.ts +11 -12
  134. package/bin/session/services/SessionStateService.d.ts.map +1 -1
  135. package/bin/session/services/SessionStateService.js +43 -69
  136. package/bin/session/services/SessionStateService.js.map +1 -1
  137. package/bin/session/services/SessionTurnService.js +3 -3
  138. package/bin/session/services/SessionTurnService.js.map +1 -1
  139. package/bin/session/services/SessionViewService.d.ts +4 -4
  140. package/bin/session/services/SessionViewService.d.ts.map +1 -1
  141. package/bin/session/services/SessionViewService.js +26 -36
  142. package/bin/session/services/SessionViewService.js.map +1 -1
  143. package/bin/session/storage/Persistence.d.ts +4 -4
  144. package/bin/session/storage/Persistence.d.ts.map +1 -1
  145. package/bin/session/storage/RuntimeSessionPort.d.ts +2 -2
  146. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  147. package/bin/session/storage/RuntimeSessionPort.js +4 -4
  148. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  149. package/bin/types/agent/AgentTypes.d.ts +2 -2
  150. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  151. package/bin/types/agent/SessionActor.d.ts +11 -11
  152. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  153. package/bin/types/agent/SessionTypes.d.ts +22 -22
  154. package/bin/types/agent/SessionTypes.d.ts.map +1 -1
  155. package/bin/types/executor/SessionRunContext.d.ts +7 -7
  156. package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
  157. package/bin/types/rpc/RpcProtocol.d.ts +6 -6
  158. package/bin/types/runtime/agent/AgentContext.d.ts +7 -7
  159. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  160. package/bin/types/sdk/AgentSessionAction.d.ts +26 -0
  161. package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -0
  162. package/bin/types/sdk/AgentSessionAction.js +10 -0
  163. package/bin/types/sdk/AgentSessionAction.js.map +1 -0
  164. package/bin/types/sdk/AgentSessionEvent.d.ts +2 -2
  165. package/bin/types/sdk/AgentSessionEvent.d.ts.map +1 -1
  166. package/bin/types/sdk/AgentSessionTurn.d.ts +2 -2
  167. package/bin/types/sdk/AgentSessionTurn.d.ts.map +1 -1
  168. package/package.json +3 -3
  169. package/scripts/agent-ready.test.mjs +1 -1
  170. package/scripts/city-model-tool-loop.test.mjs +36 -4
  171. package/scripts/plugin-tool-bridge.test.mjs +13 -0
  172. package/scripts/session-action-message.test.mjs +199 -0
  173. package/scripts/session-compaction-prompts.test.mjs +97 -0
  174. package/scripts/session-history-archive.test.mjs +8 -8
  175. package/scripts/session-history-inflight.test.mjs +10 -10
  176. package/scripts/session-list-title.test.mjs +9 -9
  177. package/scripts/session-title-event.test.mjs +12 -10
  178. package/src/agent/local/Agent.ts +16 -22
  179. package/src/agent/local/services/{AgentSessionManager.ts → AgentSessions.ts} +16 -32
  180. package/src/agent/remote/RemoteAgent.ts +58 -23
  181. package/src/agent/remote/RemoteSession.ts +10 -8
  182. package/src/agent/remote/RemoteTransport.ts +5 -5
  183. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +10 -10
  184. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -6
  185. package/src/executor/Executor.ts +51 -41
  186. package/src/executor/SessionRunScope.ts +1 -1
  187. package/src/executor/composer/compaction/SessionCompactionComposer.ts +5 -5
  188. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +1 -1
  189. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +91 -52
  190. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.ts +197 -0
  191. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +162 -0
  192. package/src/executor/composer/context/LocalSessionContextComposer.ts +5 -5
  193. package/src/executor/composer/context/SessionContextComposer.ts +5 -5
  194. package/src/executor/composer/history/SessionHistoryComposer.ts +2 -2
  195. package/src/executor/composer/history/SessionHistoryWriter.ts +10 -10
  196. package/src/executor/composer/history/jsonl/JsonlSessionHistoryComposer.ts +13 -10
  197. package/src/executor/core-engine/CoreEngineMessageState.ts +8 -8
  198. package/src/executor/core-engine/CoreEngineRunner.ts +7 -7
  199. package/src/executor/core-engine/CoreEngineSignals.ts +7 -7
  200. package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +5 -5
  201. package/src/executor/messages/AssistantResultPersistence.ts +8 -8
  202. package/src/executor/messages/SessionAttachmentMapper.ts +11 -11
  203. package/src/executor/messages/SessionMessageCodec.ts +10 -10
  204. package/src/executor/messages/SessionMessageLog.ts +3 -3
  205. package/src/executor/messages/SessionStepEventMapper.ts +5 -5
  206. package/src/executor/messages/UserVisibleText.ts +9 -9
  207. package/src/executor/services/ExecutorInflightService.ts +13 -9
  208. package/src/executor/store/history/SessionHistoryStore.ts +32 -28
  209. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +146 -95
  210. package/src/executor/tools/plugin/PluginToolSchemas.ts +24 -10
  211. package/src/executor/types/SessionRecords.ts +217 -0
  212. package/src/executor/types/SessionRun.ts +5 -5
  213. package/src/index.ts +9 -10
  214. package/src/rpc/Client.ts +9 -9
  215. package/src/session/Session.ts +10 -10
  216. package/src/session/SessionTitle.ts +7 -4
  217. package/src/session/browse/Browse.ts +66 -58
  218. package/src/session/index.ts +1 -1
  219. package/src/session/runtime/SessionPromptRuntime.ts +6 -6
  220. package/src/session/services/SessionStateService.ts +61 -86
  221. package/src/session/services/SessionTurnService.ts +7 -7
  222. package/src/session/services/SessionViewService.ts +35 -45
  223. package/src/session/storage/Persistence.ts +6 -6
  224. package/src/session/storage/RuntimeSessionPort.ts +6 -6
  225. package/src/types/agent/AgentTypes.ts +4 -4
  226. package/src/types/agent/SessionActor.ts +12 -12
  227. package/src/types/agent/SessionTypes.ts +22 -22
  228. package/src/types/executor/SessionRunContext.ts +12 -12
  229. package/src/types/rpc/RpcProtocol.ts +6 -6
  230. package/src/types/runtime/agent/AgentContext.ts +8 -8
  231. package/src/types/sdk/AgentSessionAction.ts +35 -0
  232. package/src/types/sdk/AgentSessionEvent.ts +2 -2
  233. package/src/types/sdk/AgentSessionTurn.ts +2 -2
  234. package/tsconfig.tsbuildinfo +1 -1
  235. package/bin/agent/local/services/AgentSessionManager.d.ts.map +0 -1
  236. package/bin/agent/local/services/AgentSessionManager.js.map +0 -1
  237. package/bin/executor/types/SessionMessages.d.ts +0 -118
  238. package/bin/executor/types/SessionMessages.d.ts.map +0 -1
  239. package/bin/executor/types/SessionMessages.js +0 -28
  240. package/bin/executor/types/SessionMessages.js.map +0 -1
  241. package/bin/types/sdk/AgentSessionOperation.d.ts +0 -99
  242. package/bin/types/sdk/AgentSessionOperation.d.ts.map +0 -1
  243. package/bin/types/sdk/AgentSessionOperation.js +0 -10
  244. package/bin/types/sdk/AgentSessionOperation.js.map +0 -1
  245. package/scripts/session-operation-message.test.mjs +0 -197
  246. package/src/executor/types/SessionMessages.ts +0 -148
  247. package/src/types/sdk/AgentSessionOperation.ts +0 -125
@@ -8,11 +8,11 @@
8
8
  */
9
9
 
10
10
  import { nanoid } from "nanoid";
11
- import type { SessionUserMessageV1 } from "@/executor/types/SessionMessages.js";
11
+ import type { SessionUserMessageV1 } from "@/executor/types/SessionRecords.js";
12
12
  import type {
13
- SessionMessageV1,
14
- SessionModelMessageV1,
15
- } from "@/executor/types/SessionMessages.js";
13
+ SessionRecordV1,
14
+ SessionMessageRecordV1,
15
+ } from "@/executor/types/SessionRecords.js";
16
16
  import type { AgentSessionEvent } from "@/types/sdk/AgentSessionEvent.js";
17
17
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
18
18
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
@@ -109,7 +109,7 @@ export interface SessionPromptRuntimeOptions {
109
109
  }) => Promise<{
110
110
  text: string;
111
111
  success: boolean;
112
- assistantMessage?: SessionModelMessageV1 | null;
112
+ assistantMessage?: SessionMessageRecordV1 | null;
113
113
  error?: string;
114
114
  }>;
115
115
 
@@ -349,7 +349,7 @@ export class SessionPromptRuntime {
349
349
  function buildPromptRuntimeErrorAssistantMessage(input: {
350
350
  sessionId: string;
351
351
  message: string;
352
- }): SessionModelMessageV1 {
352
+ }): SessionMessageRecordV1 {
353
353
  return {
354
354
  id: `a:${input.sessionId}:${Date.now()}:${nanoid(6)}`,
355
355
  role: "assistant",
@@ -30,16 +30,15 @@ import type {
30
30
  import type {
31
31
  AgentSessionEvent,
32
32
  } from "@/types/sdk/AgentSessionEvent.js";
33
- import type {
34
- AgentSessionOperationEvent,
35
- AgentSessionOperationRecord,
36
- } from "@/types/sdk/AgentSessionOperation.js";
37
33
  import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js";
38
34
  import type {
39
- SessionMessageV1,
40
- SessionModelMessageV1,
35
+ SessionActionRecordInputV1,
36
+ SessionActionRecordV1,
37
+ SessionRecordV1,
38
+ SessionMessageRecordV1,
41
39
  SessionUserMessageV1,
42
- } from "@/executor/types/SessionMessages.js";
40
+ } from "@/executor/types/SessionRecords.js";
41
+ import { to_session_action_record } from "@/executor/types/SessionRecords.js";
43
42
  import type { SessionLocalState } from "@/types/session/SessionLocalState.js";
44
43
  import { generateId } from "@/utils/Id.js";
45
44
 
@@ -87,17 +86,16 @@ type SessionStateServiceOptions = {
87
86
 
88
87
  type SessionSetOptions = {
89
88
  /**
90
- * 是否写入并发布 model-switching operation
89
+ * 是否写入并发布 model-switching action
91
90
  *
92
91
  * 说明(中文)
93
92
  * - 公开 `session.set()` 应保持默认开启。
94
93
  * - fork 内部复制模型配置时关闭,避免污染 forked session 历史。
95
94
  */
96
- emit_operation?: boolean;
95
+ emit_action?: boolean;
97
96
  };
98
97
 
99
- type EmitOperationInput = Omit<AgentSessionOperationRecord, "operationId"> &
100
- Partial<Pick<AgentSessionOperationRecord, "operationId">>;
98
+ type EmitActionInput = SessionActionRecordInputV1 | SessionActionRecordV1;
101
99
 
102
100
  /**
103
101
  * 本地 Session 状态与持久化服务。
@@ -223,23 +221,21 @@ export class SessionStateService {
223
221
  * 写入当前 session 配置。
224
222
  */
225
223
  async set(input: AgentSessionSetInput, options?: SessionSetOptions): Promise<void> {
226
- const should_emit_operation = options?.emit_operation !== false;
224
+ const should_emit_action = options?.emit_action !== false;
227
225
  const previous_model_label = this.state.sessionConfig.modelLabel;
228
226
  const next_model_label = input.model
229
227
  ? inferAgentModelLabel(input.model)
230
228
  : undefined;
231
- const operation_id = `model-switching:${this.session_id}:${Date.now()}:${generateId()}`;
232
-
233
- if (input.model && should_emit_operation) {
234
- await this.emit_operation_event({
235
- operationId: operation_id,
236
- name: "model-switching",
237
- status: "started",
238
- label: "Switching session model",
239
- result: {
240
- ...(previous_model_label ? { previousModelLabel: previous_model_label } : {}),
241
- ...(next_model_label ? { modelLabel: next_model_label } : {}),
242
- },
229
+ const action_id = `model-switching:${this.session_id}:${Date.now()}:${generateId()}`;
230
+
231
+ if (input.model && should_emit_action) {
232
+ await this.emit_action_event({
233
+ id: action_id,
234
+ title: "Switching session model",
235
+ description: next_model_label
236
+ ? `Switching to ${next_model_label}.`
237
+ : undefined,
238
+ state: "running",
243
239
  });
244
240
  }
245
241
 
@@ -256,30 +252,25 @@ export class SessionStateService {
256
252
  model: this.state.sessionConfig.model,
257
253
  });
258
254
  } catch (error) {
259
- if (input.model && should_emit_operation) {
260
- await this.emit_operation_event({
261
- operationId: operation_id,
262
- name: "model-switching",
263
- status: "failed",
264
- label: "Session model switch failed",
265
- error: error instanceof Error ? error.message : String(error),
255
+ if (input.model && should_emit_action) {
256
+ await this.emit_action_event({
257
+ id: action_id,
258
+ title: "Session model switch failed",
259
+ description: error instanceof Error ? error.message : String(error),
260
+ state: "failed",
266
261
  });
267
262
  }
268
263
  throw error;
269
264
  }
270
265
 
271
- if (input.model && should_emit_operation) {
272
- await this.emit_operation_event({
273
- operationId: operation_id,
274
- name: "model-switching",
275
- status: "finished",
276
- label: "Session model switched",
277
- result: {
278
- ...(previous_model_label ? { previousModelLabel: previous_model_label } : {}),
279
- ...(this.state.sessionConfig.modelLabel
280
- ? { modelLabel: this.state.sessionConfig.modelLabel }
281
- : {}),
282
- },
266
+ if (input.model && should_emit_action) {
267
+ await this.emit_action_event({
268
+ id: action_id,
269
+ title: "Session model switched",
270
+ description: this.state.sessionConfig.modelLabel
271
+ ? `Using ${this.state.sessionConfig.modelLabel}.`
272
+ : undefined,
273
+ state: "completed",
283
274
  });
284
275
  }
285
276
  }
@@ -288,10 +279,10 @@ export class SessionStateService {
288
279
  * 追加一条 user 消息并刷新标题与 metadata。
289
280
  */
290
281
  async append_user_message(params: {
291
- message?: SessionMessageV1 | null;
282
+ message?: SessionRecordV1 | null;
292
283
  text?: string;
293
284
  }): Promise<void> {
294
- await this.executor.appendUserMessage(params);
285
+ await this.executor.append_user_message(params);
295
286
  await this.ensure_title_from_history({ generate: true });
296
287
  await this.touch_metadata();
297
288
  }
@@ -300,10 +291,10 @@ export class SessionStateService {
300
291
  * 追加一条 assistant 消息并刷新 metadata。
301
292
  */
302
293
  async append_assistant_message(params: {
303
- message?: SessionMessageV1 | null;
294
+ message?: SessionRecordV1 | null;
304
295
  fallbackText?: string;
305
296
  }): Promise<void> {
306
- await this.executor.appendAssistantMessage(params);
297
+ await this.executor.append_assistant_message(params);
307
298
  await this.touch_metadata();
308
299
  }
309
300
 
@@ -328,7 +319,7 @@ export class SessionStateService {
328
319
  */
329
320
  generate?: boolean;
330
321
  }): Promise<void> {
331
- const messages = await this.history_store.list();
322
+ const messages = await this.history_store.list_records();
332
323
  const before_metadata = await readSessionMetadata({
333
324
  projectRoot: this.project_root,
334
325
  agentId: this.agent_id,
@@ -356,7 +347,7 @@ export class SessionStateService {
356
347
  * 持久化最终 assistant 结果。
357
348
  */
358
349
  async persist_assistant_result(
359
- assistant_message?: SessionModelMessageV1 | null,
350
+ assistant_message?: SessionMessageRecordV1 | null,
360
351
  ): Promise<void> {
361
352
  await persistSdkAssistantResult({
362
353
  projectRoot: this.project_root,
@@ -369,49 +360,33 @@ export class SessionStateService {
369
360
  }
370
361
 
371
362
  /**
372
- * 持久化一条 operation message
363
+ * 持久化一条 action record
373
364
  */
374
- async persist_operation_event(
375
- event: AgentSessionOperationEvent,
365
+ async persist_action_event(
366
+ event: SessionActionRecordV1,
376
367
  ): Promise<void> {
377
- if (event.status !== "finished" || event.visible === false) return;
378
- const message = this.history_store.operation({
379
- operation: {
380
- operationId: event.operationId,
381
- name: event.name,
382
- status: event.status,
383
- ...(event.turnId ? { turnId: event.turnId } : {}),
384
- ...(event.label ? { label: event.label } : {}),
385
- ...(event.reason ? { reason: event.reason } : {}),
386
- ...(typeof event.progress === "number" ? { progress: event.progress } : {}),
387
- ...(event.result !== undefined ? { result: event.result } : {}),
388
- ...(event.error ? { error: event.error } : {}),
389
- },
390
- metadata: {
391
- sessionId: this.session_id,
392
- },
393
- });
394
- await this.history_store.append(message);
368
+ const message = to_session_action_record(event, this.session_id);
369
+ await this.history_store.write_record(message);
395
370
  await this.touch_metadata();
396
371
  }
397
372
 
398
373
  /**
399
- * 写入并发布一条 operation
374
+ * 写入并发布一条 action
400
375
  */
401
- async emit_operation_event(input: EmitOperationInput): Promise<void> {
402
- const operation_id =
403
- String(input.operationId || "").trim() ||
404
- `${input.name}:${this.session_id}:${Date.now()}:${generateId()}`;
405
- const event: AgentSessionOperationEvent = {
406
- type: "operation",
407
- sessionId: this.session_id,
408
- ...input,
409
- operationId: operation_id,
410
- };
376
+ async emit_action_event(input: EmitActionInput): Promise<void> {
377
+ const event = to_session_action_record(
378
+ {
379
+ ...input,
380
+ id:
381
+ String(input.id || "").trim() ||
382
+ `action:${this.session_id}:${Date.now()}:${generateId()}`,
383
+ },
384
+ this.session_id,
385
+ );
411
386
  try {
412
- await this.persist_operation_event(event);
387
+ await this.persist_action_event(event);
413
388
  } catch {
414
- // operation 持久化失败不应阻断宿主操作。
389
+ // action 持久化失败不应阻断宿主操作。
415
390
  }
416
391
  this.publish_event(event);
417
392
  }
@@ -430,7 +405,7 @@ export class SessionStateService {
430
405
  sessionId: this.session_id,
431
406
  },
432
407
  }) as SessionUserMessageV1;
433
- await this.executor.appendUserMessage({
408
+ await this.executor.append_user_message({
434
409
  message,
435
410
  });
436
411
  await this.ensure_title_from_history({ generate: true });
@@ -455,7 +430,7 @@ export class SessionStateService {
455
430
  kind: "normal",
456
431
  },
457
432
  };
458
- await this.executor.appendUserMessage({
433
+ await this.executor.append_user_message({
459
434
  message,
460
435
  });
461
436
  await this.ensure_title_from_history({ generate: true });
@@ -474,7 +449,7 @@ export class SessionStateService {
474
449
  : [];
475
450
  if (normalized_messages.length <= 0) return;
476
451
  for (const message of normalized_messages) {
477
- await this.executor.appendUserMessage({
452
+ await this.executor.append_user_message({
478
453
  message,
479
454
  });
480
455
  }
@@ -19,10 +19,10 @@ import type { AgentSessionPromptInput } from "@/types/sdk/AgentSessionPrompt.js"
19
19
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
20
20
  import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
21
21
  import type {
22
- SessionMessageV1,
23
- SessionModelMessageV1,
22
+ SessionRecordV1,
23
+ SessionMessageRecordV1,
24
24
  SessionUserMessageV1,
25
- } from "@/executor/types/SessionMessages.js";
25
+ } from "@/executor/types/SessionRecords.js";
26
26
  import { mapAgentEventToSessionEvent, mapUiMessageChunkToAgentEvent } from "@/session/SessionEventMapper.js";
27
27
  import { SessionEventHub } from "@/session/runtime/SessionEventHub.js";
28
28
  import { SessionPromptRuntime } from "@/session/runtime/SessionPromptRuntime.js";
@@ -145,7 +145,7 @@ export class SessionTurnService {
145
145
  }): Promise<{
146
146
  text: string;
147
147
  success: boolean;
148
- assistantMessage?: SessionModelMessageV1 | null;
148
+ assistantMessage?: SessionMessageRecordV1 | null;
149
149
  error?: string;
150
150
  }> {
151
151
  const tool_name_by_call_id = new Map<string, string>();
@@ -199,11 +199,11 @@ export class SessionTurnService {
199
199
  this.publish_event(session_event);
200
200
  }
201
201
  },
202
- onOperationCallback: async (event) => {
202
+ onActionCallback: async (event) => {
203
203
  try {
204
- await this.state_service.persist_operation_event(event);
204
+ await this.state_service.persist_action_event(event);
205
205
  } catch {
206
- // operation 持久化失败不应阻断当前 turn。
206
+ // action 持久化失败不应阻断当前 turn。
207
207
  }
208
208
  this.publish_event(event);
209
209
  },
@@ -2,14 +2,14 @@
2
2
  * SessionViewService:本地 Session 查询与派生视图服务。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 统一管理 info/history/system/fork 这类读取型能力。
5
+ * - 统一管理 info/records/system/fork 这类读取型能力。
6
6
  * - 该服务只负责拼装查询结果,不负责编排 prompt turn。
7
7
  * - 需要写入持久化状态的地方仍委托给 SessionStateService。
8
8
  */
9
9
 
10
10
  import { nanoid } from "nanoid";
11
11
  import {
12
- buildSessionHistoryPage,
12
+ buildSessionRecordsPage,
13
13
  buildSessionInfo,
14
14
  getSdkAgentSessionArchiveFilePath,
15
15
  ensureSessionTitle,
@@ -21,14 +21,14 @@ import type { JsonlSessionHistoryStore } from "@/executor/store/history/jsonl/Js
21
21
  import type { SessionSystemComposer } from "@/executor/composer/system/SessionSystemComposer.js";
22
22
  import type {
23
23
  AgentSessionForkInput,
24
- AgentSessionHistoryInput,
25
- AgentSessionHistoryPage,
24
+ AgentSessionRecordsInput,
25
+ AgentSessionRecordsPage,
26
26
  AgentSessionInfo,
27
27
  AgentSession,
28
28
  AgentSessionSystemBlock,
29
29
  AgentSessionSystemSnapshot,
30
30
  } from "@/types/agent/AgentTypes.js";
31
- import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
31
+ import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
32
32
  import { SessionStateService } from "@/session/services/SessionStateService.js";
33
33
  import type { SessionRunContext } from "@/types/executor/SessionRunContext.js";
34
34
 
@@ -138,7 +138,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
138
138
  agentId: this.agent_id,
139
139
  sessionId: this.session_id,
140
140
  }),
141
- this.history_store.list(),
141
+ this.history_store.list_records(),
142
142
  ]);
143
143
  return await this.build_info({
144
144
  metadata,
@@ -155,7 +155,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
155
155
  /**
156
156
  * 当前 session 消息列表。
157
157
  */
158
- messages: SessionMessageV1[];
158
+ messages: SessionRecordV1[];
159
159
  }): Promise<AgentSessionInfo> {
160
160
  const metadata_with_title = input.metadata.title
161
161
  ? input.metadata
@@ -176,11 +176,11 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
176
176
  }
177
177
 
178
178
  /**
179
- * 读取当前 session 历史分页。
179
+ * 读取当前 session records 分页。
180
180
  */
181
- async history(
182
- input?: AgentSessionHistoryInput,
183
- ): Promise<AgentSessionHistoryPage> {
181
+ async records(
182
+ input?: AgentSessionRecordsInput,
183
+ ): Promise<AgentSessionRecordsPage> {
184
184
  const archive_id = String(input?.archive_id || "").trim();
185
185
  const [metadata, current_messages] = await Promise.all([
186
186
  readSessionMetadata({
@@ -188,7 +188,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
188
188
  agentId: this.agent_id,
189
189
  sessionId: this.session_id,
190
190
  }),
191
- this.history_store.list(),
191
+ this.history_store.list_records(),
192
192
  ]);
193
193
  const page_messages = archive_id
194
194
  ? await loadSessionArchiveMessagesFromPath(
@@ -204,7 +204,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
204
204
  metadata,
205
205
  messages: current_messages,
206
206
  });
207
- return buildSessionHistoryPage({
207
+ return buildSessionRecordsPage({
208
208
  session,
209
209
  messages: page_messages,
210
210
  input,
@@ -273,22 +273,18 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
273
273
  typeof input === "string"
274
274
  ? String(input || "").trim() || undefined
275
275
  : String(input?.messageId || "").trim() || undefined;
276
- const messages = await this.history_store.list();
276
+ const messages = await this.history_store.list_records();
277
277
  const fork_messages =
278
278
  !message_id
279
279
  ? messages
280
280
  : this.resolve_fork_messages(messages, message_id);
281
- const operation_id = `history-forking:${this.session_id}:${Date.now()}:${nanoid(8)}`;
281
+ const action_id = `history-forking:${this.session_id}:${Date.now()}:${nanoid(8)}`;
282
282
 
283
- await this.state_service.emit_operation_event({
284
- operationId: operation_id,
285
- name: "history-forking",
286
- status: "started",
287
- label: "Forking session history",
288
- result: {
289
- messageCount: fork_messages.length,
290
- ...(message_id ? { messageId: message_id } : {}),
291
- },
283
+ await this.state_service.emit_action_event({
284
+ id: action_id,
285
+ title: "Forking session records",
286
+ description: `Preparing ${String(fork_messages.length)} messages for the new session.`,
287
+ state: "running",
292
288
  });
293
289
 
294
290
  try {
@@ -302,38 +298,32 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
302
298
  {
303
299
  model: session_config.model,
304
300
  },
305
- { emit_operation: false },
301
+ { emit_action: false },
306
302
  );
307
303
  }
308
304
  await this.append_fork_messages(forked_bundle, fork_messages);
309
- await this.state_service.emit_operation_event({
310
- operationId: operation_id,
311
- name: "history-forking",
312
- status: "finished",
313
- label: "Session history forked",
314
- result: {
315
- forkedSessionId: String((forked as { id?: unknown }).id || ""),
316
- messageCount: fork_messages.length,
317
- ...(message_id ? { messageId: message_id } : {}),
318
- },
305
+ await this.state_service.emit_action_event({
306
+ id: action_id,
307
+ title: "Session records forked",
308
+ description: `Created ${String((forked as { id?: unknown }).id || "")} with ${String(fork_messages.length)} messages.`,
309
+ state: "completed",
319
310
  });
320
311
  return forked;
321
312
  } catch (error) {
322
- await this.state_service.emit_operation_event({
323
- operationId: operation_id,
324
- name: "history-forking",
325
- status: "failed",
326
- label: "Session history fork failed",
327
- error: error instanceof Error ? error.message : String(error),
313
+ await this.state_service.emit_action_event({
314
+ id: action_id,
315
+ title: "Session records fork failed",
316
+ description: error instanceof Error ? error.message : String(error),
317
+ state: "failed",
328
318
  });
329
319
  throw error;
330
320
  }
331
321
  }
332
322
 
333
323
  private resolve_fork_messages(
334
- messages: SessionMessageV1[],
324
+ messages: SessionRecordV1[],
335
325
  message_id: string,
336
- ): SessionMessageV1[] {
326
+ ): SessionRecordV1[] {
337
327
  const target_index = messages.findIndex(
338
328
  (message) => String(message.id || "").trim() === message_id,
339
329
  );
@@ -350,9 +340,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
350
340
  history_store: JsonlSessionHistoryStore;
351
341
  state_service: SessionStateService;
352
342
  },
353
- messages: SessionMessageV1[],
343
+ messages: SessionRecordV1[],
354
344
  ): Promise<void> {
355
- await forked_bundle.history_store.appendMany(messages);
345
+ await forked_bundle.history_store.write_records(messages);
356
346
  }
357
347
 
358
348
  private stringify_system_content(content: unknown): string {
@@ -9,9 +9,9 @@
9
9
  import { extractTextFromUiMessage } from "@/executor/messages/UIMessageTransformer.js";
10
10
  import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
11
11
  import type {
12
- SessionMessageV1,
13
- SessionModelMessageV1,
14
- } from "@/executor/types/SessionMessages.js";
12
+ SessionRecordV1,
13
+ SessionMessageRecordV1,
14
+ } from "@/executor/types/SessionRecords.js";
15
15
  import { persistAssistantResult } from "@/executor/messages/AssistantResultPersistence.js";
16
16
  import type { AgentSessionConfigSnapshot } from "@/types/agent/AgentTypes.js";
17
17
  import {
@@ -50,11 +50,11 @@ export interface PersistSdkAssistantResultParams
50
50
  * 追加 assistant 消息的底层执行编排器。
51
51
  */
52
52
  executor: {
53
- appendAssistantMessage(params: {
53
+ append_assistant_message(params: {
54
54
  /**
55
55
  * 已构造好的完整消息。
56
56
  */
57
- message?: SessionMessageV1 | null;
57
+ message?: SessionRecordV1 | null;
58
58
  /**
59
59
  * 兜底文本内容。
60
60
  */
@@ -68,7 +68,7 @@ export interface PersistSdkAssistantResultParams
68
68
  * - stop/abort 且没有 assistant 内容时允许为空。
69
69
  * - 为空时仅刷新 metadata,不写入伪造 assistant 正文。
70
70
  */
71
- assistantMessage?: SessionModelMessageV1 | null;
71
+ assistantMessage?: SessionMessageRecordV1 | null;
72
72
  }
73
73
 
74
74
  /**
@@ -58,11 +58,11 @@ export interface CreateRuntimeSessionPortParams {
58
58
  /**
59
59
  * 追加 user 消息到底层历史。
60
60
  */
61
- appendUserMessage: SessionPort["appendUserMessage"];
61
+ append_user_message: SessionPort["append_user_message"];
62
62
  /**
63
63
  * 追加 assistant 消息到底层历史。
64
64
  */
65
- appendAssistantMessage: SessionPort["appendAssistantMessage"];
65
+ append_assistant_message: SessionPort["append_assistant_message"];
66
66
  /**
67
67
  * 返回当前 session 是否正在执行。
68
68
  */
@@ -111,12 +111,12 @@ export function createRuntimeSessionPort(
111
111
  afterSessionUpdatedAsync: async () => {
112
112
  await params.afterSessionUpdatedAsync();
113
113
  },
114
- appendUserMessage: async (messageParams) => {
115
- await params.appendUserMessage(messageParams);
114
+ append_user_message: async (messageParams) => {
115
+ await params.append_user_message(messageParams);
116
116
  await params.touchMetadata();
117
117
  },
118
- appendAssistantMessage: async (messageParams) => {
119
- await params.appendAssistantMessage(messageParams);
118
+ append_assistant_message: async (messageParams) => {
119
+ await params.append_assistant_message(messageParams);
120
120
  await params.touchMetadata();
121
121
  },
122
122
  isExecuting: () => params.isExecuting(),
@@ -36,9 +36,9 @@ export type {
36
36
  AgentListSessionsInput,
37
37
  AgentSessionConfigSnapshot,
38
38
  AgentSessionForkInput,
39
- AgentSessionHistoryInput,
40
- AgentSessionHistoryPage,
41
- AgentSessionHistoryView,
39
+ AgentSessionRecordsInput,
40
+ AgentSessionRecordsPage,
41
+ AgentSessionRecordsView,
42
42
  AgentSessionInfo,
43
43
  AgentSessionSetInput,
44
44
  AgentSessionSummary,
@@ -53,6 +53,6 @@ export type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
53
53
  export type {
54
54
  AgentSession,
55
55
  AgentSessionActor,
56
- AgentSessionCollection,
56
+ AgentSessions,
57
57
  RemoteAgentSession,
58
58
  } from "@/types/agent/SessionActor.js";
@@ -16,8 +16,8 @@ import type {
16
16
  AgentListSessionsInput,
17
17
  AgentSessionConfigSnapshot,
18
18
  AgentSessionForkInput,
19
- AgentSessionHistoryInput,
20
- AgentSessionHistoryPage,
19
+ AgentSessionRecordsInput,
20
+ AgentSessionRecordsPage,
21
21
  AgentSessionInfo,
22
22
  AgentSessionSetInput,
23
23
  AgentSessionSummaryPage,
@@ -32,23 +32,23 @@ import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
32
32
  import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
33
33
 
34
34
  /**
35
- * SDK Session 集合绑定。
35
+ * SDK Session 集合入口。
36
36
  */
37
- export interface AgentSessionCollection {
37
+ export interface AgentSessions<TSession extends AgentSessionActor = AgentSession> {
38
38
  /** 新建一个 session。 */
39
- create_session(input?: AgentCreateSessionInput): Promise<AgentSession>;
39
+ create(input?: AgentCreateSessionInput): Promise<TSession>;
40
40
 
41
41
  /** 获取一个已存在的 session。 */
42
- get_session(sessionId: string): Promise<AgentSession>;
42
+ get(session_id: string): Promise<TSession>;
43
43
 
44
44
  /** 列出当前 agent 的 session 摘要页。 */
45
- list_sessions(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage>;
45
+ list(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage>;
46
46
 
47
47
  /** 归档单个 session。 */
48
- archive_session(input: AgentArchiveSessionInput): Promise<AgentArchiveSessionResult>;
48
+ archive(input: AgentArchiveSessionInput): Promise<AgentArchiveSessionResult>;
49
49
 
50
50
  /** 列出已归档的 session 摘要页。 */
51
- archive_sessions(input?: AgentArchiveSessionsInput): Promise<AgentArchiveSessionsResult>;
51
+ archived(input?: AgentArchiveSessionsInput): Promise<AgentArchiveSessionsResult>;
52
52
 
53
53
  /** 永久清空已归档 session。 */
54
54
  clean_archive(): Promise<AgentCleanArchiveResult>;
@@ -62,7 +62,7 @@ export interface AgentSessionActor {
62
62
  readonly id: string;
63
63
 
64
64
  /** 读取当前 session 详情。 */
65
- getInfo(): Promise<AgentSessionInfo>;
65
+ get_info(): Promise<AgentSessionInfo>;
66
66
 
67
67
  /** 追加一条新的 prompt。 */
68
68
  prompt(input: AgentSessionPromptInput): Promise<AgentSessionTurnHandle>;
@@ -73,8 +73,8 @@ export interface AgentSessionActor {
73
73
  /** 订阅当前 session 的未来事件。 */
74
74
  subscribe(subscriber: AgentSessionSubscriber): AgentSessionUnsubscribe;
75
75
 
76
- /** 读取当前 session 历史分页。 */
77
- history(input?: AgentSessionHistoryInput): Promise<AgentSessionHistoryPage>;
76
+ /** 读取当前 session records 分页。 */
77
+ records(input?: AgentSessionRecordsInput): Promise<AgentSessionRecordsPage>;
78
78
 
79
79
  /** 读取当前 session 生效的 system 快照。 */
80
80
  system(): Promise<AgentSessionSystemSnapshot>;