@downcity/agent 1.1.200 → 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 (228) 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 +5 -5
  23. package/bin/executor/Executor.d.ts.map +1 -1
  24. package/bin/executor/Executor.js +22 -13
  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 +3 -3
  29. package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
  30. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +4 -5
  31. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
  32. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +56 -16
  33. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
  34. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts +27 -0
  35. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts.map +1 -0
  36. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js +181 -0
  37. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js.map +1 -0
  38. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +45 -0
  39. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +1 -0
  40. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +144 -0
  41. package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +1 -0
  42. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +3 -3
  43. package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
  44. package/bin/executor/composer/context/SessionContextComposer.d.ts +3 -3
  45. package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
  46. package/bin/executor/composer/history/SessionHistoryComposer.d.ts +2 -2
  47. package/bin/executor/composer/history/SessionHistoryComposer.d.ts.map +1 -1
  48. package/bin/executor/composer/history/SessionHistoryWriter.d.ts +5 -5
  49. package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
  50. package/bin/executor/composer/history/SessionHistoryWriter.js +6 -6
  51. package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
  52. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +2 -2
  53. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +1 -1
  54. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js +5 -5
  55. package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +1 -1
  56. package/bin/executor/core-engine/CoreEngineMessageState.d.ts +5 -5
  57. package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
  58. package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
  59. package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
  60. package/bin/executor/core-engine/CoreEngineSignals.d.ts +4 -4
  61. package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
  62. package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
  63. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +3 -3
  64. package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
  65. package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
  66. package/bin/executor/messages/AssistantResultPersistence.d.ts +5 -5
  67. package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
  68. package/bin/executor/messages/AssistantResultPersistence.js +1 -1
  69. package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
  70. package/bin/executor/messages/SessionAttachmentMapper.d.ts +3 -3
  71. package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
  72. package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
  73. package/bin/executor/messages/SessionMessageCodec.d.ts +4 -4
  74. package/bin/executor/messages/SessionMessageCodec.d.ts.map +1 -1
  75. package/bin/executor/messages/SessionMessageCodec.js +5 -5
  76. package/bin/executor/messages/SessionMessageCodec.js.map +1 -1
  77. package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
  78. package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
  79. package/bin/executor/messages/SessionMessageLog.js.map +1 -1
  80. package/bin/executor/messages/SessionStepEventMapper.d.ts +2 -2
  81. package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
  82. package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
  83. package/bin/executor/messages/UserVisibleText.d.ts +3 -3
  84. package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
  85. package/bin/executor/messages/UserVisibleText.js +3 -3
  86. package/bin/executor/messages/UserVisibleText.js.map +1 -1
  87. package/bin/executor/services/ExecutorInflightService.d.ts +2 -2
  88. package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
  89. package/bin/executor/services/ExecutorInflightService.js +4 -4
  90. package/bin/executor/services/ExecutorInflightService.js.map +1 -1
  91. package/bin/executor/store/history/SessionHistoryStore.d.ts +24 -21
  92. package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
  93. package/bin/executor/store/history/SessionHistoryStore.js +3 -3
  94. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +18 -19
  95. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
  96. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +33 -36
  97. package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
  98. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +1 -7
  99. package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -1
  100. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +4 -6
  101. package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -1
  102. package/bin/executor/tools/plugin/PluginToolSchemas.js +24 -10
  103. package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -1
  104. package/bin/executor/types/{SessionMessages.d.ts → SessionRecords.d.ts} +53 -28
  105. package/bin/executor/types/SessionRecords.d.ts.map +1 -0
  106. package/bin/executor/types/SessionRecords.js +52 -0
  107. package/bin/executor/types/SessionRecords.js.map +1 -0
  108. package/bin/executor/types/SessionRun.d.ts +3 -3
  109. package/bin/executor/types/SessionRun.d.ts.map +1 -1
  110. package/bin/index.d.ts +1 -1
  111. package/bin/index.d.ts.map +1 -1
  112. package/bin/rpc/Client.d.ts +5 -5
  113. package/bin/rpc/Client.js +4 -4
  114. package/bin/session/Session.d.ts +6 -6
  115. package/bin/session/Session.d.ts.map +1 -1
  116. package/bin/session/Session.js +8 -8
  117. package/bin/session/Session.js.map +1 -1
  118. package/bin/session/SessionTitle.d.ts +2 -2
  119. package/bin/session/SessionTitle.d.ts.map +1 -1
  120. package/bin/session/SessionTitle.js +3 -3
  121. package/bin/session/SessionTitle.js.map +1 -1
  122. package/bin/session/browse/Browse.d.ts +12 -12
  123. package/bin/session/browse/Browse.d.ts.map +1 -1
  124. package/bin/session/browse/Browse.js +9 -9
  125. package/bin/session/browse/Browse.js.map +1 -1
  126. package/bin/session/index.d.ts +1 -1
  127. package/bin/session/index.js +1 -1
  128. package/bin/session/runtime/SessionPromptRuntime.d.ts +3 -3
  129. package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
  130. package/bin/session/services/SessionStateService.d.ts +7 -8
  131. package/bin/session/services/SessionStateService.d.ts.map +1 -1
  132. package/bin/session/services/SessionStateService.js +15 -31
  133. package/bin/session/services/SessionStateService.js.map +1 -1
  134. package/bin/session/services/SessionViewService.d.ts +4 -4
  135. package/bin/session/services/SessionViewService.js +12 -12
  136. package/bin/session/services/SessionViewService.js.map +1 -1
  137. package/bin/session/storage/Persistence.d.ts +4 -4
  138. package/bin/session/storage/Persistence.d.ts.map +1 -1
  139. package/bin/session/storage/RuntimeSessionPort.d.ts +2 -2
  140. package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
  141. package/bin/session/storage/RuntimeSessionPort.js +4 -4
  142. package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
  143. package/bin/types/agent/AgentTypes.d.ts +2 -2
  144. package/bin/types/agent/AgentTypes.d.ts.map +1 -1
  145. package/bin/types/agent/SessionActor.d.ts +11 -11
  146. package/bin/types/agent/SessionActor.d.ts.map +1 -1
  147. package/bin/types/agent/SessionTypes.d.ts +12 -12
  148. package/bin/types/agent/SessionTypes.d.ts.map +1 -1
  149. package/bin/types/executor/SessionRunContext.d.ts +2 -2
  150. package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
  151. package/bin/types/rpc/RpcProtocol.d.ts +6 -6
  152. package/bin/types/runtime/agent/AgentContext.d.ts +7 -7
  153. package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
  154. package/bin/types/sdk/AgentSessionAction.d.ts +8 -49
  155. package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -1
  156. package/bin/types/sdk/AgentSessionAction.js +4 -4
  157. package/bin/types/sdk/AgentSessionTurn.d.ts +2 -2
  158. package/bin/types/sdk/AgentSessionTurn.d.ts.map +1 -1
  159. package/package.json +3 -3
  160. package/scripts/agent-ready.test.mjs +1 -1
  161. package/scripts/city-model-tool-loop.test.mjs +36 -4
  162. package/scripts/plugin-tool-bridge.test.mjs +13 -0
  163. package/scripts/session-action-message.test.mjs +25 -25
  164. package/scripts/session-compaction-prompts.test.mjs +97 -0
  165. package/scripts/session-history-archive.test.mjs +8 -8
  166. package/scripts/session-history-inflight.test.mjs +10 -10
  167. package/scripts/session-list-title.test.mjs +9 -9
  168. package/scripts/session-title-event.test.mjs +12 -10
  169. package/src/agent/local/Agent.ts +16 -22
  170. package/src/agent/local/services/{AgentSessionManager.ts → AgentSessions.ts} +16 -32
  171. package/src/agent/remote/RemoteAgent.ts +58 -23
  172. package/src/agent/remote/RemoteSession.ts +10 -8
  173. package/src/agent/remote/RemoteTransport.ts +5 -5
  174. package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +10 -10
  175. package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -6
  176. package/src/executor/Executor.ts +30 -19
  177. package/src/executor/SessionRunScope.ts +1 -1
  178. package/src/executor/composer/compaction/SessionCompactionComposer.ts +3 -3
  179. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +73 -29
  180. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.ts +197 -0
  181. package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +162 -0
  182. package/src/executor/composer/context/LocalSessionContextComposer.ts +5 -5
  183. package/src/executor/composer/context/SessionContextComposer.ts +5 -5
  184. package/src/executor/composer/history/SessionHistoryComposer.ts +2 -2
  185. package/src/executor/composer/history/SessionHistoryWriter.ts +10 -10
  186. package/src/executor/composer/history/jsonl/JsonlSessionHistoryComposer.ts +13 -13
  187. package/src/executor/core-engine/CoreEngineMessageState.ts +8 -8
  188. package/src/executor/core-engine/CoreEngineRunner.ts +7 -7
  189. package/src/executor/core-engine/CoreEngineSignals.ts +7 -7
  190. package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +5 -5
  191. package/src/executor/messages/AssistantResultPersistence.ts +8 -8
  192. package/src/executor/messages/SessionAttachmentMapper.ts +11 -11
  193. package/src/executor/messages/SessionMessageCodec.ts +10 -10
  194. package/src/executor/messages/SessionMessageLog.ts +3 -3
  195. package/src/executor/messages/SessionStepEventMapper.ts +5 -5
  196. package/src/executor/messages/UserVisibleText.ts +9 -9
  197. package/src/executor/services/ExecutorInflightService.ts +7 -7
  198. package/src/executor/store/history/SessionHistoryStore.ts +26 -23
  199. package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +58 -62
  200. package/src/executor/tools/plugin/PluginToolSchemas.ts +24 -10
  201. package/src/executor/types/{SessionMessages.ts → SessionRecords.ts} +71 -40
  202. package/src/executor/types/SessionRun.ts +5 -5
  203. package/src/index.ts +4 -4
  204. package/src/rpc/Client.ts +9 -9
  205. package/src/session/Session.ts +10 -10
  206. package/src/session/SessionTitle.ts +7 -7
  207. package/src/session/browse/Browse.ts +38 -38
  208. package/src/session/index.ts +1 -1
  209. package/src/session/runtime/SessionPromptRuntime.ts +6 -6
  210. package/src/session/services/SessionStateService.ts +29 -44
  211. package/src/session/services/SessionTurnService.ts +4 -4
  212. package/src/session/services/SessionViewService.ts +21 -21
  213. package/src/session/storage/Persistence.ts +6 -6
  214. package/src/session/storage/RuntimeSessionPort.ts +6 -6
  215. package/src/types/agent/AgentTypes.ts +4 -4
  216. package/src/types/agent/SessionActor.ts +12 -12
  217. package/src/types/agent/SessionTypes.ts +12 -12
  218. package/src/types/executor/SessionRunContext.ts +2 -2
  219. package/src/types/rpc/RpcProtocol.ts +6 -6
  220. package/src/types/runtime/agent/AgentContext.ts +8 -8
  221. package/src/types/sdk/AgentSessionAction.ts +12 -56
  222. package/src/types/sdk/AgentSessionTurn.ts +2 -2
  223. package/tsconfig.tsbuildinfo +1 -1
  224. package/bin/agent/local/services/AgentSessionManager.d.ts.map +0 -1
  225. package/bin/agent/local/services/AgentSessionManager.js.map +0 -1
  226. package/bin/executor/types/SessionMessages.d.ts.map +0 -1
  227. package/bin/executor/types/SessionMessages.js +0 -46
  228. package/bin/executor/types/SessionMessages.js.map +0 -1
@@ -15,8 +15,8 @@ import type {
15
15
  AgentSession,
16
16
  AgentSessionConfigSnapshot,
17
17
  AgentSessionForkInput,
18
- AgentSessionHistoryInput,
19
- AgentSessionHistoryPage,
18
+ AgentSessionRecordsInput,
19
+ AgentSessionRecordsPage,
20
20
  AgentSessionInfo,
21
21
  AgentSessionSetInput,
22
22
  AgentSessionSystemBlock,
@@ -207,7 +207,7 @@ export class Session implements AgentSession {
207
207
  /**
208
208
  * 追加一条 user 文本消息。
209
209
  */
210
- async appendUserMessage(input: {
210
+ async append_user_message(input: {
211
211
  text: string;
212
212
  }): Promise<void> {
213
213
  await this.stateService.append_user_message({
@@ -218,7 +218,7 @@ export class Session implements AgentSession {
218
218
  /**
219
219
  * 追加一条 assistant 文本消息。
220
220
  */
221
- async appendAssistantMessage(input: {
221
+ async append_assistant_message(input: {
222
222
  text: string;
223
223
  }): Promise<void> {
224
224
  await this.stateService.append_assistant_message({
@@ -229,15 +229,15 @@ export class Session implements AgentSession {
229
229
  /**
230
230
  * 读取当前 session 详情。
231
231
  */
232
- async getInfo(): Promise<AgentSessionInfo> {
232
+ async get_info(): Promise<AgentSessionInfo> {
233
233
  return await this.viewService.get_info();
234
234
  }
235
235
 
236
236
  /**
237
- * 读取当前 session 历史分页。
237
+ * 读取当前 session records 分页。
238
238
  */
239
- async history(input?: AgentSessionHistoryInput): Promise<AgentSessionHistoryPage> {
240
- return await this.viewService.history(input);
239
+ async records(input?: AgentSessionRecordsInput): Promise<AgentSessionRecordsPage> {
240
+ return await this.viewService.records(input);
241
241
  }
242
242
 
243
243
  /**
@@ -288,10 +288,10 @@ export class Session implements AgentSession {
288
288
  afterSessionUpdatedAsync: async () => {
289
289
  await this.executor.afterSessionUpdatedAsync();
290
290
  },
291
- appendUserMessage: async (message_params) => {
291
+ append_user_message: async (message_params) => {
292
292
  await this.stateService.append_user_message(message_params);
293
293
  },
294
- appendAssistantMessage: async (message_params) => {
294
+ append_assistant_message: async (message_params) => {
295
295
  await this.stateService.append_assistant_message(message_params);
296
296
  },
297
297
  isExecuting: () => this.isExecuting(),
@@ -9,8 +9,8 @@
9
9
 
10
10
  import { generateText, type LanguageModel } from "ai";
11
11
  import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
12
- import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
13
- import { isSessionModelMessage } from "@/executor/types/SessionMessages.js";
12
+ import type { SessionRecordV1 } from "@/executor/types/SessionRecords.js";
13
+ import { is_session_message_record } from "@/executor/types/SessionRecords.js";
14
14
  import {
15
15
  normalizeSessionTitle,
16
16
  readSessionMetadata,
@@ -41,7 +41,7 @@ export interface EnsureSessionTitleParams {
41
41
  /**
42
42
  * 当前 session 已落盘消息。
43
43
  */
44
- messages: SessionMessageV1[];
44
+ messages: SessionRecordV1[];
45
45
 
46
46
  /**
47
47
  * 可选模型实例;传入时会尝试生成更短标题。
@@ -61,8 +61,8 @@ function truncateTitle(input: string, maxChars: number): string {
61
61
  return title.slice(0, maxChars).trimEnd();
62
62
  }
63
63
 
64
- function extractTextFromMessage(message: SessionMessageV1): string {
65
- if (!isSessionModelMessage(message)) return "";
64
+ function extractTextFromMessage(message: SessionRecordV1): string {
65
+ if (!is_session_message_record(message)) return "";
66
66
  if (!Array.isArray(message.parts)) return "";
67
67
  const texts: string[] = [];
68
68
  for (const part of message.parts) {
@@ -76,9 +76,9 @@ function extractTextFromMessage(message: SessionMessageV1): string {
76
76
  return texts.join("\n").trim();
77
77
  }
78
78
 
79
- function resolveFirstUserText(messages: SessionMessageV1[]): string {
79
+ function resolveFirstUserText(messages: SessionRecordV1[]): string {
80
80
  for (const message of messages) {
81
- if (!isSessionModelMessage(message)) continue;
81
+ if (!is_session_message_record(message)) continue;
82
82
  if (message.role !== "user") continue;
83
83
  const text = extractTextFromMessage(message);
84
84
  if (text) return text;
@@ -17,24 +17,24 @@ import {
17
17
  } from "ai";
18
18
  import type {
19
19
  AgentListSessionsInput,
20
- AgentSessionHistoryInput,
21
- AgentSessionHistoryPage,
22
- AgentSessionHistoryView,
20
+ AgentSessionRecordsInput,
21
+ AgentSessionRecordsPage,
22
+ AgentSessionRecordsView,
23
23
  AgentSessionInfo,
24
24
  AgentSessionSummary,
25
25
  AgentSessionSummaryPage,
26
26
  AgentSessionTimelineEvent,
27
27
  } from "@/types/agent/AgentTypes.js";
28
28
  import type {
29
- SessionActionMessageV1,
30
- SessionMessageV1,
29
+ SessionActionRecordV1,
30
+ SessionRecordV1,
31
31
  SessionMetadataV1,
32
- SessionModelMessageV1,
33
- } from "@/executor/types/SessionMessages.js";
32
+ SessionMessageRecordV1,
33
+ } from "@/executor/types/SessionRecords.js";
34
34
  import {
35
- isSessionActionMessage,
36
- isSessionModelMessage,
37
- } from "@/executor/types/SessionMessages.js";
35
+ is_session_action_record,
36
+ is_session_message_record,
37
+ } from "@/executor/types/SessionRecords.js";
38
38
  import type { SessionHistoryMetaV1 } from "@/executor/types/SessionHistoryMeta.js";
39
39
  import { pickLastSuccessfulChatSendText } from "@/executor/messages/UserVisibleText.js";
40
40
  import { getSdkAgentSessionMessagesPath } from "@/session/storage/Paths.js";
@@ -81,7 +81,7 @@ type SessionBrowseBaseInput = {
81
81
  /**
82
82
  * 当前 session 已读取到的完整消息。
83
83
  */
84
- messages: SessionMessageV1[];
84
+ messages: SessionRecordV1[];
85
85
 
86
86
  /**
87
87
  * 当前 session 是否正在执行。
@@ -177,7 +177,7 @@ function extractMessageText(parts: unknown): string {
177
177
  return texts.join("\n").trim();
178
178
  }
179
179
 
180
- function extractAssistantToolSummary(message: SessionModelMessageV1): string {
180
+ function extractAssistantToolSummary(message: SessionMessageRecordV1): string {
181
181
  if (!Array.isArray(message.parts)) return "";
182
182
  const toolNames = new Set<string>();
183
183
  for (const part of message.parts as AnyUiPart[]) {
@@ -193,13 +193,13 @@ function extractAssistantToolSummary(message: SessionModelMessageV1): string {
193
193
  /**
194
194
  * 解析单条 session 消息的用户可见预览文本。
195
195
  */
196
- export function resolveSessionMessagePreview(message: SessionMessageV1): string {
197
- if (isSessionActionMessage(message)) {
196
+ export function resolveSessionMessagePreview(message: SessionRecordV1): string {
197
+ if (is_session_action_record(message)) {
198
198
  return message.description
199
199
  ? `${message.title}\n${message.description}`
200
200
  : message.title;
201
201
  }
202
- if (!isSessionModelMessage(message)) return "";
202
+ if (!is_session_message_record(message)) return "";
203
203
  const plainText = extractMessageText(message.parts);
204
204
  if (plainText) return plainText;
205
205
  if (message.role !== "assistant") return "";
@@ -237,7 +237,7 @@ function extractToolResultOutput(part: ToolPartCompatShape): unknown {
237
237
  }
238
238
 
239
239
  function toTimelineEvent(params: {
240
- message: SessionModelMessageV1;
240
+ message: SessionMessageRecordV1;
241
241
  role: AgentSessionTimelineEvent["role"];
242
242
  text: string;
243
243
  sequence: number;
@@ -256,7 +256,7 @@ function toTimelineEvent(params: {
256
256
  }
257
257
 
258
258
  function toActionTimelineEvent(
259
- message: SessionActionMessageV1,
259
+ message: SessionActionRecordV1,
260
260
  ): AgentSessionTimelineEvent {
261
261
  const metadata = message.metadata || null;
262
262
  return {
@@ -274,13 +274,13 @@ function toActionTimelineEvent(
274
274
  * 把单条 session message 展平成时间线事件。
275
275
  */
276
276
  export function toSessionTimelineEvents(
277
- message: SessionMessageV1,
277
+ message: SessionRecordV1,
278
278
  ): AgentSessionTimelineEvent[] {
279
- if (isSessionActionMessage(message)) {
279
+ if (is_session_action_record(message)) {
280
280
  return [toActionTimelineEvent(message)];
281
281
  }
282
282
 
283
- if (!isSessionModelMessage(message)) return [];
283
+ if (!is_session_message_record(message)) return [];
284
284
  if (message.role !== "assistant") {
285
285
  return [
286
286
  toTimelineEvent({
@@ -366,14 +366,14 @@ export function toSessionTimelineEvents(
366
366
  */
367
367
  export async function loadSessionMessagesFromPath(
368
368
  filePath: string,
369
- ): Promise<SessionMessageV1[]> {
370
- const messages: SessionMessageV1[] = [];
369
+ ): Promise<SessionRecordV1[]> {
370
+ const messages: SessionRecordV1[] = [];
371
371
  if (await fs.pathExists(filePath)) {
372
372
  const raw = await fs.readFile(filePath, "utf-8");
373
373
  const lines = raw.split("\n").filter(Boolean);
374
374
  for (const line of lines) {
375
375
  try {
376
- const parsed = JSON.parse(line) as SessionMessageV1;
376
+ const parsed = JSON.parse(line) as SessionRecordV1;
377
377
  if (!parsed || typeof parsed !== "object") continue;
378
378
  const candidate = parsed as { type?: unknown; role?: unknown };
379
379
  if (
@@ -393,9 +393,9 @@ export async function loadSessionMessagesFromPath(
393
393
  const inflight_path = filePath.replace(/messages\.jsonl$/, "inflight.json");
394
394
  if (await fs.pathExists(inflight_path)) {
395
395
  try {
396
- const parsed = (await fs.readJson(inflight_path)) as SessionMessageV1;
396
+ const parsed = (await fs.readJson(inflight_path)) as SessionRecordV1;
397
397
  if (
398
- isSessionModelMessage(parsed) &&
398
+ is_session_message_record(parsed) &&
399
399
  parsed.role === "assistant" &&
400
400
  Array.isArray(parsed.parts)
401
401
  ) {
@@ -418,11 +418,11 @@ export async function loadSessionMessagesFromPath(
418
418
  */
419
419
  export async function loadSessionArchiveMessagesFromPath(
420
420
  filePath: string,
421
- ): Promise<SessionMessageV1[]> {
421
+ ): Promise<SessionRecordV1[]> {
422
422
  try {
423
423
  const raw = (await fs.readJson(filePath)) as SessionArchiveFileV1 | null;
424
424
  const items = Array.isArray(raw?.messages) ? raw.messages : [];
425
- return items.filter((item): item is SessionMessageV1 => {
425
+ return items.filter((item): item is SessionRecordV1 => {
426
426
  if (!item || typeof item !== "object") return false;
427
427
  const candidate = item as { type?: unknown; role?: unknown; parts?: unknown };
428
428
  return (
@@ -439,13 +439,13 @@ export async function loadSessionArchiveMessagesFromPath(
439
439
  }
440
440
  }
441
441
 
442
- function isCompactSummaryMessage(message: SessionMessageV1): boolean {
443
- if (!isSessionModelMessage(message)) return false;
442
+ function isCompactSummaryMessage(message: SessionRecordV1): boolean {
443
+ if (!is_session_message_record(message)) return false;
444
444
  const metadata = (message.metadata || null) as SessionMetadataV1 | null;
445
445
  return metadata?.source === "compact" || metadata?.kind === "summary";
446
446
  }
447
447
 
448
- function resolvePreviousArchiveId(messages: SessionMessageV1[]): string | undefined {
448
+ function resolvePreviousArchiveId(messages: SessionRecordV1[]): string | undefined {
449
449
  for (const message of messages) {
450
450
  if (!isCompactSummaryMessage(message)) continue;
451
451
  const metadata = (message.metadata || null) as SessionMetadataV1 | null;
@@ -456,8 +456,8 @@ function resolvePreviousArchiveId(messages: SessionMessageV1[]): string | undefi
456
456
  }
457
457
 
458
458
  function filterUserVisibleHistoryMessages(
459
- messages: SessionMessageV1[],
460
- ): SessionMessageV1[] {
459
+ messages: SessionRecordV1[],
460
+ ): SessionRecordV1[] {
461
461
  return messages.filter((message) => !isCompactSummaryMessage(message));
462
462
  }
463
463
 
@@ -500,14 +500,14 @@ export function buildSessionInfo(
500
500
  }
501
501
 
502
502
  /**
503
- * 基于完整消息列表构建 session history 分页结果。
503
+ * 基于完整消息列表构建 session records 分页结果。
504
504
  */
505
- export function buildSessionHistoryPage(params: {
505
+ export function buildSessionRecordsPage(params: {
506
506
  session: AgentSessionInfo;
507
- messages: SessionMessageV1[];
508
- input?: AgentSessionHistoryInput;
509
- }): AgentSessionHistoryPage {
510
- const view: AgentSessionHistoryView = params.input?.view || "message";
507
+ messages: SessionRecordV1[];
508
+ input?: AgentSessionRecordsInput;
509
+ }): AgentSessionRecordsPage {
510
+ const view: AgentSessionRecordsView = params.input?.view || "message";
511
511
  const order = params.input?.order || "asc";
512
512
  const limit = normalizeLimit(params.input?.limit, 50, 500);
513
513
  const cursor = normalizeCursor(params.input?.cursor);
@@ -46,7 +46,7 @@ export {
46
46
  createRuntimeSessionPort,
47
47
  } from "./storage/RuntimeSessionPort.js";
48
48
  export {
49
- buildSessionHistoryPage,
49
+ buildSessionRecordsPage,
50
50
  buildSessionInfo,
51
51
  listArchivedAgentSessionSummaryPage,
52
52
  listAgentSessionSummaryPage,
@@ -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
- AgentSessionActionEvent,
35
- AgentSessionActionRecord,
36
- } from "@/types/sdk/AgentSessionAction.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
 
@@ -96,8 +95,7 @@ type SessionSetOptions = {
96
95
  emit_action?: boolean;
97
96
  };
98
97
 
99
- type EmitActionInput = Omit<AgentSessionActionRecord, "id"> &
100
- Partial<Pick<AgentSessionActionRecord, "id">>;
98
+ type EmitActionInput = SessionActionRecordInputV1 | SessionActionRecordV1;
101
99
 
102
100
  /**
103
101
  * 本地 Session 状态与持久化服务。
@@ -281,10 +279,10 @@ export class SessionStateService {
281
279
  * 追加一条 user 消息并刷新标题与 metadata。
282
280
  */
283
281
  async append_user_message(params: {
284
- message?: SessionMessageV1 | null;
282
+ message?: SessionRecordV1 | null;
285
283
  text?: string;
286
284
  }): Promise<void> {
287
- await this.executor.appendUserMessage(params);
285
+ await this.executor.append_user_message(params);
288
286
  await this.ensure_title_from_history({ generate: true });
289
287
  await this.touch_metadata();
290
288
  }
@@ -293,10 +291,10 @@ export class SessionStateService {
293
291
  * 追加一条 assistant 消息并刷新 metadata。
294
292
  */
295
293
  async append_assistant_message(params: {
296
- message?: SessionMessageV1 | null;
294
+ message?: SessionRecordV1 | null;
297
295
  fallbackText?: string;
298
296
  }): Promise<void> {
299
- await this.executor.appendAssistantMessage(params);
297
+ await this.executor.append_assistant_message(params);
300
298
  await this.touch_metadata();
301
299
  }
302
300
 
@@ -321,7 +319,7 @@ export class SessionStateService {
321
319
  */
322
320
  generate?: boolean;
323
321
  }): Promise<void> {
324
- const messages = await this.history_store.list();
322
+ const messages = await this.history_store.list_records();
325
323
  const before_metadata = await readSessionMetadata({
326
324
  projectRoot: this.project_root,
327
325
  agentId: this.agent_id,
@@ -349,7 +347,7 @@ export class SessionStateService {
349
347
  * 持久化最终 assistant 结果。
350
348
  */
351
349
  async persist_assistant_result(
352
- assistant_message?: SessionModelMessageV1 | null,
350
+ assistant_message?: SessionMessageRecordV1 | null,
353
351
  ): Promise<void> {
354
352
  await persistSdkAssistantResult({
355
353
  projectRoot: this.project_root,
@@ -362,24 +360,13 @@ export class SessionStateService {
362
360
  }
363
361
 
364
362
  /**
365
- * 持久化一条 action message
363
+ * 持久化一条 action record
366
364
  */
367
365
  async persist_action_event(
368
- event: AgentSessionActionEvent,
366
+ event: SessionActionRecordV1,
369
367
  ): Promise<void> {
370
- const message = this.history_store.action({
371
- action: {
372
- id: event.id,
373
- title: event.title,
374
- state: event.state,
375
- ...(event.description ? { description: event.description } : {}),
376
- ...(event.turnId ? { turnId: event.turnId } : {}),
377
- },
378
- metadata: {
379
- sessionId: this.session_id,
380
- },
381
- });
382
- 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);
383
370
  await this.touch_metadata();
384
371
  }
385
372
 
@@ -387,17 +374,15 @@ export class SessionStateService {
387
374
  * 写入并发布一条 action。
388
375
  */
389
376
  async emit_action_event(input: EmitActionInput): Promise<void> {
390
- if (input.visible === false) return;
391
- const action_id =
392
- String(input.id || "").trim() ||
393
- `action:${this.session_id}:${Date.now()}:${generateId()}`;
394
- const { visible: _visible, ...public_input } = input;
395
- const event: AgentSessionActionEvent = {
396
- type: "action",
397
- sessionId: this.session_id,
398
- ...public_input,
399
- id: action_id,
400
- };
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
+ );
401
386
  try {
402
387
  await this.persist_action_event(event);
403
388
  } catch {
@@ -420,7 +405,7 @@ export class SessionStateService {
420
405
  sessionId: this.session_id,
421
406
  },
422
407
  }) as SessionUserMessageV1;
423
- await this.executor.appendUserMessage({
408
+ await this.executor.append_user_message({
424
409
  message,
425
410
  });
426
411
  await this.ensure_title_from_history({ generate: true });
@@ -445,7 +430,7 @@ export class SessionStateService {
445
430
  kind: "normal",
446
431
  },
447
432
  };
448
- await this.executor.appendUserMessage({
433
+ await this.executor.append_user_message({
449
434
  message,
450
435
  });
451
436
  await this.ensure_title_from_history({ generate: true });
@@ -464,7 +449,7 @@ export class SessionStateService {
464
449
  : [];
465
450
  if (normalized_messages.length <= 0) return;
466
451
  for (const message of normalized_messages) {
467
- await this.executor.appendUserMessage({
452
+ await this.executor.append_user_message({
468
453
  message,
469
454
  });
470
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>();
@@ -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,7 +273,7 @@ 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
@@ -282,7 +282,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
282
282
 
283
283
  await this.state_service.emit_action_event({
284
284
  id: action_id,
285
- title: "Forking session history",
285
+ title: "Forking session records",
286
286
  description: `Preparing ${String(fork_messages.length)} messages for the new session.`,
287
287
  state: "running",
288
288
  });
@@ -304,7 +304,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
304
304
  await this.append_fork_messages(forked_bundle, fork_messages);
305
305
  await this.state_service.emit_action_event({
306
306
  id: action_id,
307
- title: "Session history forked",
307
+ title: "Session records forked",
308
308
  description: `Created ${String((forked as { id?: unknown }).id || "")} with ${String(fork_messages.length)} messages.`,
309
309
  state: "completed",
310
310
  });
@@ -312,7 +312,7 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
312
312
  } catch (error) {
313
313
  await this.state_service.emit_action_event({
314
314
  id: action_id,
315
- title: "Session history fork failed",
315
+ title: "Session records fork failed",
316
316
  description: error instanceof Error ? error.message : String(error),
317
317
  state: "failed",
318
318
  });
@@ -321,9 +321,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
321
321
  }
322
322
 
323
323
  private resolve_fork_messages(
324
- messages: SessionMessageV1[],
324
+ messages: SessionRecordV1[],
325
325
  message_id: string,
326
- ): SessionMessageV1[] {
326
+ ): SessionRecordV1[] {
327
327
  const target_index = messages.findIndex(
328
328
  (message) => String(message.id || "").trim() === message_id,
329
329
  );
@@ -340,9 +340,9 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
340
340
  history_store: JsonlSessionHistoryStore;
341
341
  state_service: SessionStateService;
342
342
  },
343
- messages: SessionMessageV1[],
343
+ messages: SessionRecordV1[],
344
344
  ): Promise<void> {
345
- await forked_bundle.history_store.appendMany(messages);
345
+ await forked_bundle.history_store.write_records(messages);
346
346
  }
347
347
 
348
348
  private stringify_system_content(content: unknown): string {