@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
@@ -1,8 +1,8 @@
1
1
  /**
2
- * AgentSessionManager:本地 Agent session 管理服务。
2
+ * AgentSessions:本地 Agent session 集合入口。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 统一管理 session 缓存、创建、恢复、默认配置注入与 session collection。
5
+ * - 统一管理 session 缓存、创建、恢复、默认配置注入与列表查询。
6
6
  * - 该服务只负责 session 生命周期与查询,不负责 plugin / RPC 启停。
7
7
  * - Session 对象创建细节集中在这里,避免 facade 和 lifecycle 重复依赖 Session 构造逻辑。
8
8
  */
@@ -22,7 +22,7 @@ import type {
22
22
  AgentManagedSession,
23
23
  AgentModel,
24
24
  AgentSession,
25
- AgentSessionCollection,
25
+ AgentSessions as AgentSessionsApi,
26
26
  AgentSessionConstructor,
27
27
  AgentSessionSummaryPage,
28
28
  AgentSessionSystemBlock,
@@ -48,7 +48,7 @@ function decodeMaybe(input: string): string {
48
48
  }
49
49
  }
50
50
 
51
- type AgentSessionManagerOptions = {
51
+ type AgentSessionsOptions = {
52
52
  /**
53
53
  * 当前 agent 稳定标识。
54
54
  */
@@ -106,22 +106,21 @@ type AgentSessionManagerOptions = {
106
106
  /**
107
107
  * 本地 Agent session 管理服务。
108
108
  */
109
- export class AgentSessionManager {
109
+ export class AgentSessions implements AgentSessionsApi<AgentSession> {
110
110
  private readonly agent_id: string;
111
111
  private readonly project_root: string;
112
112
  private readonly tools: Record<string, Tool>;
113
113
  private readonly logger: Logger;
114
- private readonly get_agent_context: AgentSessionManagerOptions["get_agent_context"];
115
- private readonly get_instruction: AgentSessionManagerOptions["get_instruction"];
114
+ private readonly get_agent_context: AgentSessionsOptions["get_agent_context"];
115
+ private readonly get_instruction: AgentSessionsOptions["get_instruction"];
116
116
  private readonly plugin_instances: Map<string, Plugin>;
117
- private readonly ensure_agent_ready: AgentSessionManagerOptions["ensure_agent_ready"];
117
+ private readonly ensure_agent_ready: AgentSessionsOptions["ensure_agent_ready"];
118
118
  private readonly default_model?: AgentModel;
119
119
  private readonly SessionClass: AgentSessionConstructor;
120
120
  private readonly sessions_by_id = new Map<string, AgentManagedSession>();
121
121
  private readonly configured_session_ids = new Set<string>();
122
- private readonly session_collection: AgentSessionCollection;
123
122
 
124
- constructor(options: AgentSessionManagerOptions) {
123
+ constructor(options: AgentSessionsOptions) {
125
124
  this.agent_id = options.agent_id;
126
125
  this.project_root = options.project_root;
127
126
  this.tools = options.tools;
@@ -132,14 +131,6 @@ export class AgentSessionManager {
132
131
  this.ensure_agent_ready = options.ensure_agent_ready;
133
132
  this.default_model = options.default_model;
134
133
  this.SessionClass = options.SessionClass || Session;
135
- this.session_collection = {
136
- create_session: async (input) => await this.create_session(input),
137
- get_session: async (session_id) => await this.get_session(session_id),
138
- list_sessions: async (input) => await this.list_sessions(input),
139
- archive_session: async (input) => await this.archive_session(input),
140
- archive_sessions: async (input) => await this.archive_sessions(input),
141
- clean_archive: async () => await this.clean_archive(),
142
- };
143
134
  }
144
135
 
145
136
  /**
@@ -149,13 +140,6 @@ export class AgentSessionManager {
149
140
  return [...this.sessions_by_id.values()];
150
141
  }
151
142
 
152
- /**
153
- * 返回对外暴露的 session collection。
154
- */
155
- get_session_collection(): AgentSessionCollection {
156
- return this.session_collection;
157
- }
158
-
159
143
  /**
160
144
  * 获取或创建一个 session runtime port。
161
145
  */
@@ -168,7 +152,7 @@ export class AgentSessionManager {
168
152
  /**
169
153
  * 新建一个 session。
170
154
  */
171
- async create_session(
155
+ async create(
172
156
  input?: AgentCreateSessionInput,
173
157
  ): Promise<AgentSession> {
174
158
  const explicit_session_id =
@@ -197,10 +181,10 @@ export class AgentSessionManager {
197
181
  /**
198
182
  * 获取一个已存在的 session。
199
183
  */
200
- async get_session(session_id: string): Promise<AgentSession> {
184
+ async get(session_id: string): Promise<AgentSession> {
201
185
  const resolved_session_id = String(session_id || "").trim();
202
186
  if (!resolved_session_id) {
203
- throw new Error("get_session requires a non-empty sessionId");
187
+ throw new Error("sessions.get requires a non-empty sessionId");
204
188
  }
205
189
  const session_dir_path = getSdkAgentSessionDirPath(
206
190
  this.project_root,
@@ -224,7 +208,7 @@ export class AgentSessionManager {
224
208
  /**
225
209
  * 列出当前 agent 的 session 摘要页。
226
210
  */
227
- async list_sessions(
211
+ async list(
228
212
  input?: AgentListSessionsInput,
229
213
  ): Promise<AgentSessionSummaryPage> {
230
214
  return await listAgentSessionSummaryPage({
@@ -238,12 +222,12 @@ export class AgentSessionManager {
238
222
  /**
239
223
  * 归档单个 session。
240
224
  */
241
- async archive_session(
225
+ async archive(
242
226
  input: AgentArchiveSessionInput,
243
227
  ): Promise<AgentArchiveSessionResult> {
244
228
  const session_id = String(input?.id || "").trim();
245
229
  if (!session_id) {
246
- throw new Error("archive_session requires a non-empty id");
230
+ throw new Error("sessions.archive requires a non-empty id");
247
231
  }
248
232
 
249
233
  const executing_session_ids = new Set(
@@ -290,7 +274,7 @@ export class AgentSessionManager {
290
274
  /**
291
275
  * 列出当前 agent 的已归档 session 摘要页。
292
276
  */
293
- async archive_sessions(
277
+ async archived(
294
278
  input?: AgentArchiveSessionsInput,
295
279
  ): Promise<AgentArchiveSessionsResult> {
296
280
  return await listArchivedAgentSessionSummaryPage({
@@ -8,7 +8,15 @@
8
8
  */
9
9
 
10
10
  import type {
11
- AgentSessionCollection,
11
+ AgentArchiveSessionInput,
12
+ AgentArchiveSessionsInput,
13
+ AgentArchiveSessionResult,
14
+ AgentArchiveSessionsResult,
15
+ AgentCleanArchiveResult,
16
+ AgentCreateSessionInput,
17
+ AgentListSessionsInput,
18
+ AgentSessionSummaryPage,
19
+ AgentSessions,
12
20
  RemoteAgentPluginActionInput,
13
21
  RemoteAgentPluginActionResult,
14
22
  RemoteAgentOptions,
@@ -30,6 +38,8 @@ import { create_remote_agent_transport } from "@/agent/remote/TransportFactory.j
30
38
  * RemoteAgent:远程 Agent 客户端。
31
39
  */
32
40
  export class RemoteAgent {
41
+ readonly sessions: AgentSessions<RemoteAgentSession>;
42
+
33
43
  private readonly transport: RemoteAgentTransport;
34
44
 
35
45
  constructor(options: RemoteAgentOptions) {
@@ -38,6 +48,7 @@ export class RemoteAgent {
38
48
  throw new Error("RemoteAgent requires a non-empty url");
39
49
  }
40
50
  this.transport = create_remote_agent_transport(url, options.token);
51
+ this.sessions = new RemoteAgentSessions(this.transport);
41
52
  }
42
53
 
43
54
  /**
@@ -121,27 +132,51 @@ export class RemoteAgent {
121
132
  await this.transport.close?.();
122
133
  }
123
134
 
124
- /**
125
- * 返回当前远程 session collection 入口。
126
- *
127
- * 关键点(中文)
128
- * - `RemoteAgentTransport` 只负责协议传输,不直接等价于 `AgentSessionCollection`。
129
- * - 这里把 transport 包装为 `AgentSessionCollection`,`create_session` / `get_session` 返回 `RemoteSession` 实例。
130
- */
131
- session_collection(): AgentSessionCollection {
132
- return {
133
- create_session: async (input) => {
134
- const info = await this.transport.create_session(input);
135
- return new RemoteSession(this.transport, info);
136
- },
137
- get_session: async (session_id) => {
138
- const info = await this.transport.get_info(session_id);
139
- return new RemoteSession(this.transport, info);
140
- },
141
- list_sessions: async (input) => await this.transport.list_sessions(input),
142
- archive_session: async (input) => await this.transport.archive_session(input),
143
- archive_sessions: async (input) => await this.transport.archive_sessions(input),
144
- clean_archive: async () => await this.transport.clean_archive(),
145
- };
135
+ }
136
+
137
+ /**
138
+ * 远程 Agent session 集合入口。
139
+ *
140
+ * 关键点(中文)
141
+ * - `RemoteAgentTransport` 只负责协议传输,不直接暴露为用户 SDK API。
142
+ * - 这里把远程传输包装成和本地 `agent.sessions` 一致的方法命名。
143
+ */
144
+ class RemoteAgentSessions implements AgentSessions<RemoteAgentSession> {
145
+ private readonly transport: RemoteAgentTransport;
146
+
147
+ constructor(transport: RemoteAgentTransport) {
148
+ this.transport = transport;
149
+ }
150
+
151
+ /** 新建一个远程 session。 */
152
+ async create(input?: AgentCreateSessionInput): Promise<RemoteAgentSession> {
153
+ const info = await this.transport.create_session(input);
154
+ return new RemoteSession(this.transport, info);
155
+ }
156
+
157
+ /** 获取一个远程 session。 */
158
+ async get(session_id: string): Promise<RemoteAgentSession> {
159
+ const info = await this.transport.get_info(session_id);
160
+ return new RemoteSession(this.transport, info);
161
+ }
162
+
163
+ /** 列出远程 session 摘要页。 */
164
+ async list(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage> {
165
+ return await this.transport.list_sessions(input);
166
+ }
167
+
168
+ /** 归档一个远程 session。 */
169
+ async archive(input: AgentArchiveSessionInput): Promise<AgentArchiveSessionResult> {
170
+ return await this.transport.archive_session(input);
171
+ }
172
+
173
+ /** 列出远程已归档 session。 */
174
+ async archived(input?: AgentArchiveSessionsInput): Promise<AgentArchiveSessionsResult> {
175
+ return await this.transport.archive_sessions(input);
176
+ }
177
+
178
+ /** 永久清空远程已归档 session。 */
179
+ async clean_archive(): Promise<AgentCleanArchiveResult> {
180
+ return await this.transport.clean_archive();
146
181
  }
147
182
  }
@@ -7,14 +7,14 @@
7
7
  */
8
8
 
9
9
  import type {
10
- AgentSession,
11
10
  AgentSessionConfigSnapshot,
12
11
  AgentSessionForkInput,
13
- AgentSessionHistoryInput,
14
- AgentSessionHistoryPage,
12
+ AgentSessionRecordsInput,
13
+ AgentSessionRecordsPage,
15
14
  AgentSessionInfo,
16
15
  AgentSessionSetInput,
17
16
  AgentSessionSystemSnapshot,
17
+ RemoteAgentSession,
18
18
  } from "@/types/agent/AgentTypes.js";
19
19
  import { isAgentSessionPromptInputEmpty } from "@/types/sdk/AgentSessionPrompt.js";
20
20
  import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
@@ -53,7 +53,7 @@ type RemoteTurnLifecycle = {
53
53
  /**
54
54
  * 远程 Session 客户端。
55
55
  */
56
- export class RemoteSession implements AgentSession {
56
+ export class RemoteSession implements RemoteAgentSession {
57
57
  readonly id: string;
58
58
  readonly agentId: string;
59
59
  readonly config: AgentSessionConfigSnapshot;
@@ -87,7 +87,7 @@ export class RemoteSession implements AgentSession {
87
87
  /**
88
88
  * 读取当前远程 session 详情。
89
89
  */
90
- async getInfo(): Promise<AgentSessionInfo> {
90
+ async get_info(): Promise<AgentSessionInfo> {
91
91
  return await this.transport.get_info(this.id);
92
92
  }
93
93
 
@@ -135,8 +135,8 @@ export class RemoteSession implements AgentSession {
135
135
  /**
136
136
  * 读取远程消息历史。
137
137
  */
138
- async history(input?: AgentSessionHistoryInput): Promise<AgentSessionHistoryPage> {
139
- return await this.transport.history(this.id, input);
138
+ async records(input?: AgentSessionRecordsInput): Promise<AgentSessionRecordsPage> {
139
+ return await this.transport.records(this.id, input);
140
140
  }
141
141
 
142
142
  /**
@@ -149,7 +149,7 @@ export class RemoteSession implements AgentSession {
149
149
  /**
150
150
  * 分叉远程 session。
151
151
  */
152
- async fork(input?: AgentSessionForkInput | string): Promise<AgentSession> {
152
+ async fork(input?: AgentSessionForkInput | string): Promise<RemoteAgentSession> {
153
153
  const info = await this.transport.fork(this.id, input);
154
154
  return new RemoteSession(this.transport, info);
155
155
  }
@@ -296,6 +296,8 @@ function extract_turn_id(event: AgentSessionEvent): string | null {
296
296
  case "assistant-step":
297
297
  case "turn-finish":
298
298
  return event.turnId;
299
+ case "action":
300
+ return event.metadata.turnId || null;
299
301
  default:
300
302
  return null;
301
303
  }
@@ -15,8 +15,8 @@ import type {
15
15
  AgentArchiveSessionsResult,
16
16
  AgentCleanArchiveResult,
17
17
  AgentSessionForkInput,
18
- AgentSessionHistoryInput,
19
- AgentSessionHistoryPage,
18
+ AgentSessionRecordsInput,
19
+ AgentSessionRecordsPage,
20
20
  AgentSessionInfo,
21
21
  AgentSessionSummaryPage,
22
22
  AgentSessionSystemSnapshot,
@@ -63,10 +63,10 @@ export type RemoteSessionTransport = {
63
63
  on_event: (event: AgentSessionEvent) => void;
64
64
  }): Promise<TransportSubscription>;
65
65
  /** 读取 history。 */
66
- history(
66
+ records(
67
67
  session_id: string,
68
- input?: AgentSessionHistoryInput,
69
- ): Promise<AgentSessionHistoryPage>;
68
+ input?: AgentSessionRecordsInput,
69
+ ): Promise<AgentSessionRecordsPage>;
70
70
  /** 读取 system snapshot。 */
71
71
  system(session_id: string): Promise<AgentSessionSystemSnapshot>;
72
72
  /** 分叉 session。 */
@@ -15,8 +15,8 @@ import type {
15
15
  AgentArchiveSessionsResult,
16
16
  AgentCleanArchiveResult,
17
17
  AgentSessionForkInput,
18
- AgentSessionHistoryInput,
19
- AgentSessionHistoryPage,
18
+ AgentSessionRecordsInput,
19
+ AgentSessionRecordsPage,
20
20
  AgentSessionInfo,
21
21
  AgentSessionSummaryPage,
22
22
  AgentSessionSystemSnapshot,
@@ -184,10 +184,10 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
184
184
  };
185
185
  }
186
186
 
187
- async history(
187
+ async records(
188
188
  session_id: string,
189
- input?: AgentSessionHistoryInput,
190
- ): Promise<AgentSessionHistoryPage> {
189
+ input?: AgentSessionRecordsInput,
190
+ ): Promise<AgentSessionRecordsPage> {
191
191
  const query = new URLSearchParams();
192
192
  if (input?.limit !== undefined) query.set("limit", String(input.limit));
193
193
  if (input?.cursor) query.set("cursor", input.cursor);
@@ -197,19 +197,19 @@ export class HttpRemoteAgentTransport implements RemoteAgentTransport {
197
197
  const payload = await read_http_json<{
198
198
  success?: boolean;
199
199
  error?: string;
200
- history?: AgentSessionHistoryPage;
200
+ records?: AgentSessionRecordsPage;
201
201
  }>(
202
- `${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/history${
202
+ `${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/records${
203
203
  query.size > 0 ? `?${query.toString()}` : ""
204
204
  }`,
205
205
  {
206
206
  headers: this.headers(),
207
207
  },
208
208
  );
209
- if (!payload.success || !payload.history || !Array.isArray(payload.history.items)) {
210
- throw new Error(String(payload.error || "Remote session history failed"));
209
+ if (!payload.success || !payload.records || !Array.isArray(payload.records.items)) {
210
+ throw new Error(String(payload.error || "Remote session records failed"));
211
211
  }
212
- return payload.history;
212
+ return payload.records;
213
213
  }
214
214
 
215
215
  async system(session_id: string): Promise<AgentSessionSystemSnapshot> {
@@ -15,8 +15,8 @@ import type {
15
15
  AgentArchiveSessionsResult,
16
16
  AgentCleanArchiveResult,
17
17
  AgentSessionForkInput,
18
- AgentSessionHistoryInput,
19
- AgentSessionHistoryPage,
18
+ AgentSessionRecordsInput,
19
+ AgentSessionRecordsPage,
20
20
  AgentSessionInfo,
21
21
  AgentSessionSummaryPage,
22
22
  AgentSessionSystemSnapshot,
@@ -89,11 +89,11 @@ export class RpcRemoteAgentTransport implements RemoteAgentTransport {
89
89
  };
90
90
  }
91
91
 
92
- async history(
92
+ async records(
93
93
  session_id: string,
94
- input?: AgentSessionHistoryInput,
95
- ): Promise<AgentSessionHistoryPage> {
96
- return await this.client.get_session_history({
94
+ input?: AgentSessionRecordsInput,
95
+ ): Promise<AgentSessionRecordsPage> {
96
+ return await this.client.get_session_records({
97
97
  session_id,
98
98
  input,
99
99
  });
@@ -25,10 +25,13 @@ import { ExecutorRecoveryPolicy } from "@executor/services/ExecutorRecoveryPolic
25
25
  import { generateId } from "@/utils/Id.js";
26
26
  import type { Logger } from "@/utils/logger/Logger.js";
27
27
  import type { JsonObject } from "@/types/common/Json.js";
28
- import type { SessionMessageV1 } from "@/executor/types/SessionMessages.js";
28
+ import type {
29
+ SessionActionRecordV1,
30
+ SessionRecordV1,
31
+ } from "@/executor/types/SessionRecords.js";
32
+ import { to_session_action_record } from "@/executor/types/SessionRecords.js";
29
33
  import type { SessionExecutor } from "@/executor/types/SessionExecutor.js";
30
34
  import type { SessionRunContext } from "@/types/executor/SessionRunContext.js";
31
- import type { AgentSessionOperationRecord } from "@/types/sdk/AgentSessionOperation.js";
32
35
  import type {
33
36
  SessionExecuteInput,
34
37
  SessionRunResult,
@@ -212,23 +215,23 @@ export class Executor implements SessionExecutor {
212
215
  /**
213
216
  * 追加一条 user 消息。
214
217
  */
215
- async appendUserMessage(params: {
216
- message?: SessionMessageV1 | null;
218
+ async append_user_message(params: {
219
+ message?: SessionRecordV1 | null;
217
220
  text?: string;
218
221
  extra?: JsonObject;
219
222
  }): Promise<void> {
220
- await this.historyWriter.appendUserMessage(params);
223
+ await this.historyWriter.append_user_message(params);
221
224
  }
222
225
 
223
226
  /**
224
227
  * 追加一条 assistant 消息。
225
228
  */
226
- async appendAssistantMessage(params: {
227
- message?: SessionMessageV1 | null;
229
+ async append_assistant_message(params: {
230
+ message?: SessionRecordV1 | null;
228
231
  fallbackText?: string;
229
232
  extra?: JsonObject;
230
233
  }): Promise<void> {
231
- await this.historyWriter.appendAssistantMessage(params);
234
+ await this.historyWriter.append_assistant_message(params);
232
235
  }
233
236
 
234
237
  /**
@@ -362,7 +365,7 @@ export class Executor implements SessionExecutor {
362
365
  const composed_context = await this.contextComposer.compose(run_context);
363
366
  const tools = this.bind_run_scope_to_tools(composed_context.tools, run_context);
364
367
  const system = await this.systemComposer.resolve(run_context);
365
- let compaction_operation_id = "";
368
+ let compaction_action_id = "";
366
369
 
367
370
  try {
368
371
  if (retry_count > 0) {
@@ -371,13 +374,13 @@ export class Executor implements SessionExecutor {
371
374
  });
372
375
  }
373
376
 
374
- const emit_compaction_operation = async (
375
- operation: AgentSessionOperationRecord,
377
+ const emit_compaction_action = async (
378
+ action: SessionActionRecordV1,
376
379
  ): Promise<void> => {
377
- if (operation.status === "started") {
378
- compaction_operation_id = operation.operationId;
380
+ if (action.state === "running") {
381
+ compaction_action_id = action.id;
379
382
  }
380
- await this.emitOperation(run_context, operation);
383
+ await this.emitAction(run_context, action);
381
384
  };
382
385
 
383
386
  await this.compactionComposer.run({
@@ -385,18 +388,22 @@ export class Executor implements SessionExecutor {
385
388
  model,
386
389
  system,
387
390
  retryCount: retry_count,
388
- onOperation: emit_compaction_operation,
391
+ onAction: emit_compaction_action,
389
392
  });
390
393
  } catch (error) {
391
- await this.emitOperation(run_context, {
392
- operationId:
393
- compaction_operation_id ||
394
+ await this.emitAction(run_context, {
395
+ type: "action",
396
+ id:
397
+ compaction_action_id ||
394
398
  `compacting:${this.sessionId}:failed:${Date.now()}:${generateId()}`,
395
- name: "compacting",
396
- status: "failed",
397
- label: "Session history compact failed",
398
- error: error instanceof Error ? error.message : String(error),
399
- visible: false,
399
+ title: "Session records compact failed",
400
+ description: error instanceof Error ? error.message : String(error),
401
+ state: "failed",
402
+ metadata: {
403
+ v: 1,
404
+ ts: Date.now(),
405
+ sessionId: this.sessionId,
406
+ },
400
407
  });
401
408
  // 压缩失败不阻断主流程,继续使用当前历史消息执行。
402
409
  }
@@ -492,8 +499,8 @@ export class Executor implements SessionExecutor {
492
499
  ...(typeof input?.onUiMessageChunkCallback === "function"
493
500
  ? { onUiMessageChunkCallback: input.onUiMessageChunkCallback }
494
501
  : {}),
495
- ...(typeof input?.onOperationCallback === "function"
496
- ? { onOperationCallback: input.onOperationCallback }
502
+ ...(typeof input?.onActionCallback === "function"
503
+ ? { onActionCallback: input.onActionCallback }
497
504
  : {}),
498
505
  ...(input?.abortSignal ? { abortSignal: input.abortSignal } : {}),
499
506
  injectedUserMessages: Array.isArray(input?.injectedUserMessages)
@@ -511,25 +518,28 @@ export class Executor implements SessionExecutor {
511
518
  }
512
519
 
513
520
  /**
514
- * 发布一次 session operation
521
+ * 发布一次 session action
515
522
  */
516
- private async emitOperation(
523
+ private async emitAction(
517
524
  run_context: SessionRunContext,
518
- operation: AgentSessionOperationRecord,
525
+ action: SessionActionRecordV1,
519
526
  ): Promise<void> {
520
- if (typeof run_context.onOperationCallback !== "function") return;
521
- const operation_id =
522
- String(operation.operationId || "").trim() ||
523
- `operation:${this.sessionId}:${Date.now()}:${generateId()}`;
524
- await run_context.onOperationCallback({
525
- type: "operation",
526
- sessionId: run_context.sessionId || this.sessionId,
527
- ...operation,
528
- operationId: operation_id,
529
- ...(run_context.turnId && !operation.turnId
530
- ? { turnId: run_context.turnId }
531
- : {}),
532
- });
527
+ if (typeof run_context.onActionCallback !== "function") return;
528
+ const action_id =
529
+ String(action.id || "").trim() ||
530
+ `action:${this.sessionId}:${Date.now()}:${generateId()}`;
531
+ const event = to_session_action_record({
532
+ ...action,
533
+ id: action_id,
534
+ metadata: {
535
+ ...action.metadata,
536
+ sessionId: run_context.sessionId || this.sessionId,
537
+ ...(run_context.turnId && !action.metadata.turnId
538
+ ? { turnId: run_context.turnId }
539
+ : {}),
540
+ },
541
+ }, run_context.sessionId || this.sessionId);
542
+ await run_context.onActionCallback(event);
533
543
  }
534
544
 
535
545
  /**
@@ -1,6 +1,6 @@
1
1
  import { AsyncLocalStorage } from "node:async_hooks";
2
2
  import type { FileUIPart } from "ai";
3
- import type { SessionUserMessageV1 } from "@/executor/types/SessionMessages.js";
3
+ import type { SessionUserMessageV1 } from "@/executor/types/SessionRecords.js";
4
4
  import type { SessionRunContext } from "@/types/executor/SessionRunContext.js";
5
5
 
6
6
  /**
@@ -8,7 +8,7 @@
8
8
 
9
9
  import type { LanguageModel, SystemModelMessage } from "ai";
10
10
  import type { SessionHistoryStore } from "@/executor/store/history/SessionHistoryStore.js";
11
- import type { AgentSessionOperationRecord } from "@/types/sdk/AgentSessionOperation.js";
11
+ import type { SessionActionRecordV1 } from "@/executor/types/SessionRecords.js";
12
12
 
13
13
  /**
14
14
  * compaction Composer 执行输入。
@@ -35,13 +35,13 @@ export type SessionCompactionInput = {
35
35
  retryCount: number;
36
36
 
37
37
  /**
38
- * 可选 operation 发布回调。
38
+ * 可选 action 发布回调。
39
39
  *
40
40
  * 说明(中文)
41
- * - 默认 compaction Composer 可在真正开始压缩时发布 `compacting`。
42
- * - 回调由上层 Session 负责转成订阅事件与 operation message
41
+ * - 默认 compaction Composer 可在真正开始压缩时发布 action。
42
+ * - 回调由上层 Session 负责转成订阅事件与 action record
43
43
  */
44
- onOperation?: (operation: AgentSessionOperationRecord) => Promise<void>;
44
+ onAction?: (action: SessionActionRecordV1) => Promise<void>;
45
45
  };
46
46
 
47
47
  /**
@@ -79,7 +79,7 @@ export class JsonlSessionCompactionComposer implements SessionCompactionComposer
79
79
  maxInputTokensApprox: policy.maxInputTokensApprox,
80
80
  archiveOnCompact: policy.archiveOnCompact,
81
81
  compactRatio: policy.compactRatio,
82
- ...(input.onOperation ? { onOperation: input.onOperation } : {}),
82
+ ...(input.onAction ? { onAction: input.onAction } : {}),
83
83
  });
84
84
  }
85
85