@downcity/agent 1.1.12 → 1.1.13

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 (117) hide show
  1. package/bin/index.d.ts +2 -2
  2. package/bin/index.d.ts.map +1 -1
  3. package/bin/index.js +2 -2
  4. package/bin/index.js.map +1 -1
  5. package/bin/runtime/AgentRuntime.d.ts +2 -2
  6. package/bin/runtime/AgentRuntime.d.ts.map +1 -1
  7. package/bin/runtime/AgentRuntime.js +7 -12
  8. package/bin/runtime/AgentRuntime.js.map +1 -1
  9. package/bin/runtime/AgentRuntimeTypes.d.ts +3 -3
  10. package/bin/runtime/AgentRuntimeTypes.d.ts.map +1 -1
  11. package/bin/sdk/Agent.d.ts +2 -2
  12. package/bin/sdk/Agent.d.ts.map +1 -1
  13. package/bin/sdk/Agent.js +2 -2
  14. package/bin/sdk/Agent.js.map +1 -1
  15. package/bin/sdk/Session.d.ts +6 -6
  16. package/bin/sdk/Session.d.ts.map +1 -1
  17. package/bin/sdk/Session.js +41 -53
  18. package/bin/sdk/Session.js.map +1 -1
  19. package/bin/sdk/SessionMetadata.d.ts +3 -3
  20. package/bin/sdk/SessionMetadata.d.ts.map +1 -1
  21. package/bin/sdk/SessionMetadata.js +5 -5
  22. package/bin/sdk/SessionMetadata.js.map +1 -1
  23. package/bin/sdk/SessionPersistence.d.ts +6 -6
  24. package/bin/sdk/SessionPersistence.d.ts.map +1 -1
  25. package/bin/sdk/SessionPersistence.js +7 -7
  26. package/bin/sdk/SessionPersistence.js.map +1 -1
  27. package/bin/sdk/SessionServicePort.d.ts +5 -5
  28. package/bin/sdk/SessionServicePort.d.ts.map +1 -1
  29. package/bin/sdk/SessionServicePort.js +9 -9
  30. package/bin/sdk/SessionServicePort.js.map +1 -1
  31. package/bin/sdk/{SdkSessionSystemComposer.d.ts → SessionSystemBuilder.d.ts} +7 -7
  32. package/bin/sdk/SessionSystemBuilder.d.ts.map +1 -0
  33. package/bin/sdk/{SdkSessionSystemComposer.js → SessionSystemBuilder.js} +14 -14
  34. package/bin/sdk/SessionSystemBuilder.js.map +1 -0
  35. package/bin/service/builtins/chat/runtime/ChatSession.d.ts +27 -8
  36. package/bin/service/builtins/chat/runtime/ChatSession.d.ts.map +1 -1
  37. package/bin/service/builtins/chat/runtime/ChatSession.js +9 -4
  38. package/bin/service/builtins/chat/runtime/ChatSession.js.map +1 -1
  39. package/bin/service/builtins/task/runtime/Runner.d.ts +1 -1
  40. package/bin/service/builtins/task/runtime/Runner.js +1 -1
  41. package/bin/service/builtins/task/runtime/TaskRunnerSession.d.ts +2 -2
  42. package/bin/service/builtins/task/runtime/TaskRunnerSession.js +4 -4
  43. package/bin/service/builtins/task/runtime/TaskRunnerSession.js.map +1 -1
  44. package/bin/service/builtins/task/runtime/TaskRunnerTypes.d.ts +1 -1
  45. package/bin/session/{Session.d.ts → Executor.d.ts} +54 -17
  46. package/bin/session/Executor.d.ts.map +1 -0
  47. package/bin/session/{Session.js → Executor.js} +60 -23
  48. package/bin/session/Executor.js.map +1 -0
  49. package/bin/session/composer/SessionComposer.d.ts +1 -1
  50. package/bin/session/composer/SessionComposer.js +1 -1
  51. package/bin/session/composer/compaction/SessionCompactionComposer.d.ts +2 -2
  52. package/bin/session/composer/execution/LocalSessionExecutionComposer.d.ts +1 -1
  53. package/bin/session/composer/execution/LocalSessionExecutionComposer.js +1 -1
  54. package/bin/session/composer/execution/SessionExecutionComposer.d.ts +1 -1
  55. package/bin/session/composer/history/SessionHistoryComposer.d.ts +1 -1
  56. package/bin/session/composer/system/SessionSystemComposer.d.ts +1 -1
  57. package/bin/session/composer/system/SessionSystemComposer.js +1 -1
  58. package/bin/session/executors/local/{LocalSessionCore.d.ts → Runner.d.ts} +10 -10
  59. package/bin/session/executors/local/Runner.d.ts.map +1 -0
  60. package/bin/session/executors/local/{LocalSessionCore.js → Runner.js} +11 -11
  61. package/bin/session/executors/local/Runner.js.map +1 -0
  62. package/bin/session/executors/local/SessionExecutionError.d.ts +1 -1
  63. package/bin/session/executors/local/SessionExecutionError.js +1 -1
  64. package/bin/session/executors/local/SessionLoopDecision.d.ts +3 -3
  65. package/bin/session/executors/local/SessionLoopDecision.js +3 -3
  66. package/bin/session/executors/local/SessionModelMessageState.d.ts +2 -2
  67. package/bin/session/executors/local/SessionModelMessageState.js +2 -2
  68. package/bin/session/executors/local/SessionSignals.d.ts +3 -3
  69. package/bin/session/executors/local/SessionSignals.js +3 -3
  70. package/bin/session/executors/local/SessionToolLoopRunner.d.ts +1 -1
  71. package/bin/session/executors/local/SessionToolLoopRunner.js +2 -2
  72. package/bin/session/executors/local/SessionToolLoopRunner.js.map +1 -1
  73. package/bin/session/types/SessionLoop.d.ts +1 -1
  74. package/bin/session/types/SessionLoop.js +1 -1
  75. package/bin/session/types/SessionRun.d.ts +2 -2
  76. package/bin/session/types/SessionRun.js +1 -1
  77. package/package.json +1 -1
  78. package/src/index.ts +2 -2
  79. package/src/runtime/AgentRuntime.ts +7 -17
  80. package/src/runtime/AgentRuntimeTypes.ts +3 -3
  81. package/src/sdk/Agent.ts +5 -5
  82. package/src/sdk/Session.ts +52 -66
  83. package/src/sdk/SessionMetadata.ts +5 -5
  84. package/src/sdk/SessionPersistence.ts +13 -13
  85. package/src/sdk/SessionServicePort.ts +13 -13
  86. package/src/sdk/{SdkSessionSystemComposer.ts → SessionSystemBuilder.ts} +24 -24
  87. package/src/service/builtins/chat/runtime/ChatSession.ts +37 -13
  88. package/src/service/builtins/task/runtime/Runner.ts +1 -1
  89. package/src/service/builtins/task/runtime/TaskRunnerSession.ts +4 -4
  90. package/src/service/builtins/task/runtime/TaskRunnerTypes.ts +1 -1
  91. package/src/session/{Session.ts → Executor.ts} +96 -26
  92. package/src/session/composer/SessionComposer.ts +1 -1
  93. package/src/session/composer/compaction/SessionCompactionComposer.ts +2 -2
  94. package/src/session/composer/execution/LocalSessionExecutionComposer.ts +1 -1
  95. package/src/session/composer/execution/SessionExecutionComposer.ts +1 -1
  96. package/src/session/composer/history/SessionHistoryComposer.ts +1 -1
  97. package/src/session/composer/system/SessionSystemComposer.ts +1 -1
  98. package/src/session/executors/local/{LocalSessionCore.ts → Runner.ts} +13 -13
  99. package/src/session/executors/local/SessionExecutionError.ts +1 -1
  100. package/src/session/executors/local/SessionLoopDecision.ts +3 -3
  101. package/src/session/executors/local/SessionModelMessageState.ts +2 -2
  102. package/src/session/executors/local/SessionSignals.ts +3 -3
  103. package/src/session/executors/local/SessionToolLoopRunner.ts +2 -2
  104. package/src/session/types/SessionLoop.ts +1 -1
  105. package/src/session/types/SessionRun.ts +2 -2
  106. package/tsconfig.tsbuildinfo +1 -1
  107. package/bin/sdk/SdkSessionSystemComposer.d.ts.map +0 -1
  108. package/bin/sdk/SdkSessionSystemComposer.js.map +0 -1
  109. package/bin/session/Session.d.ts.map +0 -1
  110. package/bin/session/Session.js.map +0 -1
  111. package/bin/session/executors/local/LocalSessionCore.d.ts.map +0 -1
  112. package/bin/session/executors/local/LocalSessionCore.js.map +0 -1
  113. package/bin/session/executors/local/LocalSessionExecutor.d.ts +0 -61
  114. package/bin/session/executors/local/LocalSessionExecutor.d.ts.map +0 -1
  115. package/bin/session/executors/local/LocalSessionExecutor.js +0 -36
  116. package/bin/session/executors/local/LocalSessionExecutor.js.map +0 -1
  117. package/src/session/executors/local/LocalSessionExecutor.ts +0 -89
@@ -1,5 +1,5 @@
1
1
  /**
2
- * ChatSession:chat 专用 Session 实现。
2
+ * ChatSession:chat 专用 Executor 实现。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - ChatSession 在实例化时持有自己的 execution composer 实例。
@@ -7,10 +7,13 @@
7
7
  * - 外层仍只调用标准 `run(...)`;chat 语义由 ChatSession 内部收敛。
8
8
  */
9
9
 
10
- import { Session } from "@session/Session.js";
10
+ import type { LanguageModel, Tool } from "ai";
11
+ import { Executor } from "@session/Executor.js";
11
12
  import type { SessionHistoryComposer } from "@session/composer/history/SessionHistoryComposer.js";
13
+ import type { SessionCompactionComposer } from "@session/composer/compaction/SessionCompactionComposer.js";
14
+ import type { SessionSystemComposer } from "@session/composer/system/SessionSystemComposer.js";
12
15
  import type { ChatSessionExecutionComposer } from "@/service/builtins/chat/runtime/ChatSessionExecutionComposer.js";
13
- import type { SessionExecutor } from "@/session/types/SessionExecutor.js";
16
+ import type { Logger } from "@/utils/logger/Logger.js";
14
17
  import type { SessionAssistantStepCallback } from "@/session/types/SessionRun.js";
15
18
  import type { SessionRunResult } from "@/session/types/SessionRun.js";
16
19
  import type { ChatSessionTurnState } from "@/service/builtins/chat/runtime/ChatSessionTypes.js";
@@ -27,17 +30,34 @@ type ChatSessionOptions = {
27
30
  historyComposer: SessionHistoryComposer;
28
31
 
29
32
  /**
30
- * 当前 session 绑定的 chat execution composer。
33
+ * 读取当前 session 使用的模型实例。
31
34
  */
32
- executionComposer: ChatSessionExecutionComposer;
35
+ getModel: () => LanguageModel | undefined;
36
+
37
+ /**
38
+ * 统一日志器。
39
+ */
40
+ logger: Logger;
41
+
42
+ /**
43
+ * 当前 session 对应的 compaction Composer。
44
+ */
45
+ compactionComposer: SessionCompactionComposer;
33
46
 
34
47
  /**
35
- * 创建当前 session 的执行器。
48
+ * 当前 session 对应的 system Composer。
36
49
  */
37
- createExecutor: (
38
- historyComposer: SessionHistoryComposer,
39
- executionComposer: ChatSessionExecutionComposer,
40
- ) => SessionExecutor;
50
+ systemComposer: SessionSystemComposer;
51
+
52
+ /**
53
+ * 获取当前可用工具集合。
54
+ */
55
+ getTools: () => Record<string, Tool>;
56
+
57
+ /**
58
+ * 当前 session 绑定的 chat execution composer。
59
+ */
60
+ executionComposer: ChatSessionExecutionComposer;
41
61
 
42
62
  /**
43
63
  * session 更新后的异步回调。
@@ -48,7 +68,7 @@ type ChatSessionOptions = {
48
68
  /**
49
69
  * Chat 专用 Session。
50
70
  */
51
- export class ChatSession extends Session {
71
+ export class ChatSession extends Executor {
52
72
  /**
53
73
  * ChatSession 持有的 composer 实例。
54
74
  */
@@ -61,8 +81,12 @@ export class ChatSession extends Session {
61
81
  super({
62
82
  sessionId: options.sessionId,
63
83
  historyComposer: options.historyComposer,
64
- createExecutor: (historyComposer) =>
65
- options.createExecutor(historyComposer, executionComposer),
84
+ getModel: options.getModel,
85
+ logger: options.logger,
86
+ compactionComposer: options.compactionComposer,
87
+ systemComposer: options.systemComposer,
88
+ getTools: options.getTools,
89
+ executionComposer,
66
90
  ...(options.runAfterSessionUpdated
67
91
  ? { runAfterSessionUpdated: options.runAfterSessionUpdated }
68
92
  : {}),
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 职责(中文)
5
5
  * - 创建 run 目录(timestamp)。
6
- * - 以“干净历史”调用当前 runtime 的 LocalSessionCore(逻辑与正常 chat 一致)。
6
+ * - 以“干净历史”调用当前 runtime 的 Runner(逻辑与正常 chat 一致)。
7
7
  * - 协调 script / agent 两类执行主链。
8
8
  * - 把最终产物写入 run 目录的具体格式委托给 `TaskRunArtifacts.ts`。
9
9
  */
@@ -2,7 +2,7 @@
2
2
  * TaskRunnerSession:task runner 的 session 装配模块。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 负责构建 task 专用 LocalSessionCore / JsonlSessionHistoryComposer 运行时。
5
+ * - 负责构建 task 专用 Runner / JsonlSessionHistoryComposer 运行时。
6
6
  * - 负责把每轮 user/assistant 消息写入 run 目录对应的 messages.jsonl。
7
7
  * - 这些能力与任务编排逻辑解耦后,Runner 主流程会更聚焦于状态流转。
8
8
  * - 当前只有 api 执行模式。
@@ -12,7 +12,7 @@ import path from "node:path";
12
12
  import type { AgentContext } from "@/runtime/AgentContextTypes.js";
13
13
  import type { SessionRunResult } from "@/session/types/SessionRun.js";
14
14
  import type { TaskSessionRuntimePort } from "@/service/builtins/task/runtime/TaskRunnerTypes.js";
15
- import { LocalSessionCore } from "@session/executors/local/LocalSessionCore.js";
15
+ import { Runner } from "@session/executors/local/Runner.js";
16
16
  import { drainDeferredPersistedUserMessages } from "@session/SessionRunScope.js";
17
17
  import { JsonlSessionHistoryComposer } from "@session/composer/history/jsonl/JsonlSessionHistoryComposer.js";
18
18
  import { JsonlSessionCompactionComposer } from "@session/composer/compaction/jsonl/JsonlSessionCompactionComposer.js";
@@ -54,7 +54,7 @@ export async function appendTaskRoundUserMessage(params: {
54
54
  * 构建 task 专用 Session 运行时(独立于普通 Session 实例缓存)。
55
55
  *
56
56
  * 关键点(中文)
57
- * - 使用 LocalSessionCore 执行,模型来自 context.session.model(agent 级模型)。
57
+ * - 使用 Runner 执行,模型来自 context.session.model(agent 级模型)。
58
58
  */
59
59
  export function createTaskSessionRuntimePort(params: {
60
60
  context: AgentContext;
@@ -132,7 +132,7 @@ export function createTaskSessionRuntimePort(params: {
132
132
  sessionId: key,
133
133
  getTools: () => shellTools,
134
134
  });
135
- const created = new LocalSessionCore({
135
+ const created = new Runner({
136
136
  model: context.session.model,
137
137
  logger: context.logger,
138
138
  historyComposer,
@@ -170,7 +170,7 @@ export type ScriptExecutionResult = {
170
170
  * task 运行专用的 session runtime 端口。
171
171
  *
172
172
  * 关键点(中文)
173
- * - task runner 不直接依赖具体 `LocalSessionExecutor` 实现。
173
+ * - task runner 不直接依赖具体 SDK `Session` 实现。
174
174
  * - 这里暴露的是 task 场景最小可用端口:执行器 + history Composer。
175
175
  */
176
176
  export type TaskSessionRuntimePort = {
@@ -1,23 +1,31 @@
1
1
  /**
2
- * Session:单个会话实例。
2
+ * Executor:单个 session 的执行编排器。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 一个 Session 只对应一个固定的 `sessionId`。
6
- * - 对外直接暴露 `run / appendUserMessage / appendAssistantMessage / getExecutor / getHistoryComposer`。
7
- * - 运行态(如 executing)直接收在实例内部,不再拆 `Facade / Runner / ExecutionRegistry`。
5
+ * - SDK 对外对象叫 `Session`,这里是内部执行层。
6
+ * - 一个 Executor 只对应一个固定的 `sessionId`。
7
+ * - 负责 history 写入、run scope、executing 状态与本地 Runner 的懒创建。
8
8
  */
9
9
 
10
+ import type { LanguageModel, Tool } from "ai";
10
11
  import { SessionHistoryWriter } from "@session/composer/history/SessionHistoryWriter.js";
11
12
  import type { SessionHistoryComposer } from "@session/composer/history/SessionHistoryComposer.js";
12
13
  import { withSessionRunScope } from "@session/SessionRunScope.js";
13
14
  import type { SessionRunScope } from "@session/SessionRunScope.js";
14
15
  import { buildSessionStepEventMessages } from "@session/messages/SessionStepEventMapper.js";
16
+ import { JsonlSessionCompactionComposer } from "@session/composer/compaction/jsonl/JsonlSessionCompactionComposer.js";
17
+ import { LocalSessionExecutionComposer } from "@session/composer/execution/LocalSessionExecutionComposer.js";
18
+ import type { SessionCompactionComposer } from "@session/composer/compaction/SessionCompactionComposer.js";
19
+ import type { SessionExecutionComposer } from "@session/composer/execution/SessionExecutionComposer.js";
20
+ import type { SessionSystemComposer } from "@session/composer/system/SessionSystemComposer.js";
21
+ import { Runner } from "@session/executors/local/Runner.js";
22
+ import type { Logger } from "@/utils/logger/Logger.js";
15
23
  import type { JsonObject } from "@/types/common/Json.js";
16
24
  import type { SessionMessageV1 } from "@/session/types/SessionMessages.js";
17
25
  import type { SessionExecutor } from "@/session/types/SessionExecutor.js";
18
26
  import type { SessionRunResult } from "@/session/types/SessionRun.js";
19
27
 
20
- type SessionOptions = {
28
+ type ExecutorOptions = {
21
29
  /**
22
30
  * 当前会话 ID。
23
31
  */
@@ -29,9 +37,34 @@ type SessionOptions = {
29
37
  historyComposer: SessionHistoryComposer;
30
38
 
31
39
  /**
32
- * 创建当前 session 对应的执行器。
40
+ * 读取当前 session 使用的模型实例。
33
41
  */
34
- createExecutor: (historyComposer: SessionHistoryComposer) => SessionExecutor;
42
+ getModel: () => LanguageModel | undefined;
43
+
44
+ /**
45
+ * 统一日志器。
46
+ */
47
+ logger: Logger;
48
+
49
+ /**
50
+ * 当前 session 对应的 compaction Composer。
51
+ */
52
+ compactionComposer?: SessionCompactionComposer;
53
+
54
+ /**
55
+ * 当前 session 对应的 system Composer。
56
+ */
57
+ systemComposer: SessionSystemComposer;
58
+
59
+ /**
60
+ * 获取当前可用工具集合。
61
+ */
62
+ getTools: () => Record<string, Tool>;
63
+
64
+ /**
65
+ * 可选自定义 execution Composer。
66
+ */
67
+ executionComposer?: SessionExecutionComposer;
35
68
 
36
69
  /**
37
70
  * session 更新后的异步回调。
@@ -40,30 +73,41 @@ type SessionOptions = {
40
73
  };
41
74
 
42
75
  /**
43
- * Session 单实例实现。
76
+ * Executor 单实例实现。
44
77
  */
45
- export class Session {
78
+ export class Executor implements SessionExecutor {
46
79
  /**
47
80
  * 当前 session 标识。
48
81
  */
49
82
  readonly sessionId: string;
50
83
 
51
84
  private readonly historyComposer: SessionHistoryComposer;
52
- private readonly createExecutor: SessionOptions["createExecutor"];
85
+ private readonly getModel: ExecutorOptions["getModel"];
86
+ private readonly logger: Logger;
87
+ private readonly compactionComposer: SessionCompactionComposer;
88
+ private readonly systemComposer: SessionSystemComposer;
89
+ private readonly getTools: ExecutorOptions["getTools"];
90
+ private readonly runnerExecutionComposer?: SessionExecutionComposer;
53
91
  private readonly historyWriter: SessionHistoryWriter;
54
92
 
55
- private executor: SessionExecutor | null = null;
93
+ private runner: Runner | null = null;
56
94
  private executing = false;
57
95
 
58
- constructor(options: SessionOptions) {
96
+ constructor(options: ExecutorOptions) {
59
97
  const sessionId = String(options.sessionId || "").trim();
60
98
  if (!sessionId) {
61
- throw new Error("Session requires a non-empty sessionId");
99
+ throw new Error("Executor requires a non-empty sessionId");
62
100
  }
63
101
 
64
102
  this.sessionId = sessionId;
65
103
  this.historyComposer = options.historyComposer;
66
- this.createExecutor = options.createExecutor;
104
+ this.getModel = options.getModel;
105
+ this.logger = options.logger;
106
+ this.compactionComposer =
107
+ options.compactionComposer || new JsonlSessionCompactionComposer();
108
+ this.systemComposer = options.systemComposer;
109
+ this.getTools = options.getTools;
110
+ this.runnerExecutionComposer = options.executionComposer;
67
111
  this.historyWriter = new SessionHistoryWriter({
68
112
  sessionId,
69
113
  getHistoryComposer: () => this.getHistoryComposer(),
@@ -86,26 +130,52 @@ export class Session {
86
130
  }
87
131
 
88
132
  /**
89
- * 获取当前 session 的执行器。
133
+ * 获取当前 session 的执行端口。
134
+ *
135
+ * 关键点(中文)
136
+ * - 兼容 runtime/service 端口语义:Executor 自己就是执行端口。
90
137
  */
91
138
  getExecutor(): SessionExecutor {
92
- if (this.executor) return this.executor;
93
- const created = this.createExecutor(this.getHistoryComposer());
94
- this.executor = created;
139
+ return this;
140
+ }
141
+
142
+ /**
143
+ * 获取或创建当前本地 Runner。
144
+ */
145
+ private getRunner(): Runner {
146
+ if (this.runner) return this.runner;
147
+ const model = this.getModel();
148
+ if (!model) {
149
+ throw new Error(
150
+ `Executor for session "${this.sessionId}" requires a configured model`,
151
+ );
152
+ }
153
+ const created = new Runner({
154
+ model,
155
+ logger: this.logger,
156
+ historyComposer: this.getHistoryComposer(),
157
+ compactionComposer: this.compactionComposer,
158
+ systemComposer: this.systemComposer,
159
+ executionComposer:
160
+ this.runnerExecutionComposer ||
161
+ new LocalSessionExecutionComposer({
162
+ sessionId: this.sessionId,
163
+ getTools: this.getTools,
164
+ }),
165
+ });
166
+ this.runner = created;
95
167
  return created;
96
168
  }
97
169
 
98
170
  /**
99
- * 清理当前 session 的执行器缓存。
171
+ * 清理当前 session 的 Runner 缓存。
100
172
  *
101
173
  * 关键点(中文)
102
- * - 这里只清 executor,不清 history Composer。
103
- * - history 是事实源,不应随着 executor 一起丢失。
174
+ * - 这里只清 Runner,不清 history Composer。
175
+ * - history 是事实源,不应随着 Runner 一起丢失。
104
176
  */
105
177
  clearExecutor(): void {
106
- const current = this.executor;
107
- this.executor = null;
108
-
178
+ this.runner = null;
109
179
  }
110
180
 
111
181
  /**
@@ -153,7 +223,7 @@ export class Session {
153
223
  if (this.executing) {
154
224
  // 关键点(中文):同一个 Session 实例只允许一个活跃 run,
155
225
  // 否则 step 回调、scope 与执行器状态都会互相污染。
156
- throw new Error("Session.run does not support concurrent execution");
226
+ throw new Error("Executor.run does not support concurrent execution");
157
227
  }
158
228
  const query = String(params.query || "").trim();
159
229
  const sessionRunScope: Omit<SessionRunScope, "sessionId"> = {
@@ -206,7 +276,7 @@ export class Session {
206
276
  ...sessionRunScope,
207
277
  onAssistantStepCallback: wrappedOnAssistantStepCallback,
208
278
  },
209
- () => this.getExecutor().run({ query }),
279
+ () => this.getRunner().run({ query }),
210
280
  );
211
281
  if (persistedAssistantStepCount <= 0) return result;
212
282
 
@@ -15,7 +15,7 @@ export abstract class SessionComposer {
15
15
  * 可选初始化钩子。
16
16
  *
17
17
  * 关键点(中文)
18
- * - LocalSessionExecutor 启动时可统一调用。
18
+ * - Executor / Runner 启动时可统一调用。
19
19
  * - 无需初始化的 Composer 可不实现。
20
20
  */
21
21
  async init(): Promise<void> {
@@ -30,7 +30,7 @@ export type SessionCompactionInput = {
30
30
  system: SystemModelMessage[];
31
31
 
32
32
  /**
33
- * 当前重试次数(由 LocalSessionCore 递增)。
33
+ * 当前重试次数(由 Runner 递增)。
34
34
  */
35
35
  retryCount: number;
36
36
  };
@@ -57,7 +57,7 @@ export abstract class SessionCompactionComposer extends SessionComposer {
57
57
  *
58
58
  * 关键点(中文)
59
59
  * - 由 compaction Composer 实现侧维护错误识别策略。
60
- * - LocalSessionCore 不感知具体错误文案,只按该布尔结果决定是否重试。
60
+ * - Runner 不感知具体错误文案,只按该布尔结果决定是否重试。
61
61
  */
62
62
  abstract shouldCompactOnError(error: unknown): boolean;
63
63
 
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 统一组装 tools。
6
- * - step 边界回调从 SessionRunScope 读取,LocalSessionCore 不直接管理来源。
6
+ * - step 边界回调从 SessionRunScope 读取,Runner 不直接管理来源。
7
7
  */
8
8
 
9
9
  import type { ModelMessage } from "ai";
@@ -65,7 +65,7 @@ export abstract class SessionExecutionComposer extends SessionComposer {
65
65
  * 构造 fallback assistant 消息。
66
66
  *
67
67
  * 关键点(中文)
68
- * - fallback 消息构造由 execution Composer 内部实现,LocalSessionCore 不直接依赖 history Composer。
68
+ * - fallback 消息构造由 execution Composer 内部实现,Runner 不直接依赖 history Composer。
69
69
  */
70
70
  abstract buildFallbackAssistantMessage(text: string): SessionMessageV1;
71
71
  }
@@ -39,7 +39,7 @@ export type SessionHistoryPrepareInput = {
39
39
  model: LanguageModel;
40
40
 
41
41
  /**
42
- * 当前重试次数(由 LocalSessionCore 递增)。
42
+ * 当前重试次数(由 Runner 递增)。
43
43
  */
44
44
  retryCount: number;
45
45
  };
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 专职负责“会话上下文 -> system messages”解析。
6
- * - 与 tools / step 编排解耦,避免 LocalSessionCore 过载。
6
+ * - 与 tools / step 编排解耦,避免 Runner 过载。
7
7
  */
8
8
 
9
9
  import type { SystemModelMessage } from "ai";
@@ -1,5 +1,5 @@
1
1
  /**
2
- * LocalSessionCore:本地 Session 执行内核。
2
+ * Runner:本地 Session 执行内核。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这个类只做“流程编排”,不承载业务策略。
@@ -33,9 +33,9 @@ import { SessionToolLoopRunner } from "@session/executors/local/SessionToolLoopR
33
33
  const MAX_COMPACTION_RETRY_ATTEMPTS = 3;
34
34
 
35
35
  /**
36
- * LocalSessionCore 构造参数。
36
+ * Runner 构造参数。
37
37
  */
38
- type LocalSessionCoreOptions = {
38
+ type RunnerOptions = {
39
39
  /** 当前模型实例。 */
40
40
  model: LanguageModel;
41
41
 
@@ -57,9 +57,9 @@ type LocalSessionCoreOptions = {
57
57
  };
58
58
 
59
59
  /**
60
- * LocalSessionCore 主类。
60
+ * Runner 主类。
61
61
  */
62
- export class LocalSessionCore {
62
+ export class Runner {
63
63
  /** 模型实例:用于真正执行 streamText。 */
64
64
  private readonly model: LanguageModel;
65
65
 
@@ -78,7 +78,7 @@ export class LocalSessionCore {
78
78
  /** system 解析器:用于解析 system messages。 */
79
79
  private readonly systemComposer: SessionSystemComposer;
80
80
 
81
- /** 运行互斥锁:防止同一个 LocalSessionCore 实例并发 run。 */
81
+ /** 运行互斥锁:防止同一个 Runner 实例并发 run。 */
82
82
  private isRunning = false;
83
83
 
84
84
  /** context-length 重试计数。 */
@@ -87,7 +87,7 @@ export class LocalSessionCore {
87
87
  /**
88
88
  * 构造函数。
89
89
  */
90
- constructor(options: LocalSessionCoreOptions) {
90
+ constructor(options: RunnerOptions) {
91
91
  // 注入模型。
92
92
  this.model = options.model;
93
93
 
@@ -109,7 +109,7 @@ export class LocalSessionCore {
109
109
  }
110
110
 
111
111
  /**
112
- * 执行一次 LocalSessionCore run。
112
+ * 执行一次 Runner run。
113
113
  *
114
114
  * 关键点(中文)
115
115
  * - 这里只做入口控制,不直接做模型调用。
@@ -118,7 +118,7 @@ export class LocalSessionCore {
118
118
  async run(input: SessionRunInput): Promise<SessionRunResult> {
119
119
  // 如果当前实例已经在运行,则直接拒绝并发调用。
120
120
  if (this.isRunning) {
121
- throw new Error("LocalSessionCore.run does not support concurrent execution");
121
+ throw new Error("Runner.run does not support concurrent execution");
122
122
  }
123
123
 
124
124
  // 标记运行中。
@@ -140,7 +140,7 @@ export class LocalSessionCore {
140
140
  }
141
141
 
142
142
  /**
143
- * 执行一次 LocalSessionCore run(带可压缩错误重试)。
143
+ * 执行一次 Runner run(带可压缩错误重试)。
144
144
  *
145
145
  * 关键点(中文)
146
146
  * - 正常:准备输入 -> 执行。
@@ -159,7 +159,7 @@ export class LocalSessionCore {
159
159
  // 执行组装好的运行输入。
160
160
  return await this.executePreparedRun(prepared);
161
161
  } catch (error) {
162
- // 是否应压缩重试由 compaction Composer 决策,LocalSessionCore 只消费布尔结果。
162
+ // 是否应压缩重试由 compaction Composer 决策,Runner 只消费布尔结果。
163
163
  if (this.compactionComposer.shouldCompactOnError(error)) {
164
164
  // 记录压缩重试日志,便于观测问题频率。
165
165
  await this.logger.log("info", "[agent] compacting", {
@@ -187,7 +187,7 @@ export class LocalSessionCore {
187
187
  const errorMsg = String(error);
188
188
 
189
189
  // 记录错误日志。
190
- await this.logger.log("error", "LocalSessionCore execution failed", {
190
+ await this.logger.log("error", "Runner execution failed", {
191
191
  error: errorMsg,
192
192
  });
193
193
 
@@ -213,7 +213,7 @@ export class LocalSessionCore {
213
213
  private async prepareExecuteInput(query: string): Promise<SessionExecuteInput> {
214
214
  // 基础安全检查:historyComposer 必须携带 sessionId。
215
215
  if (!String(this.historyComposer.sessionId || "").trim()) {
216
- throw new Error("LocalSessionCore.run requires historyComposer.sessionId");
216
+ throw new Error("Runner.run requires historyComposer.sessionId");
217
217
  }
218
218
 
219
219
  // 让 execution Composer 组装运行上下文(例如 tools 与 request 作用域)。
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - AI SDK 的最终错误有时只是兜底包装,底层 provider 错误会先从 stream `onError` 暴露。
6
- * - LocalSessionCore 只需要消费这里输出的日志字段与最终错误文本。
6
+ * - Runner 只需要消费这里输出的日志字段与最终错误文本。
7
7
  */
8
8
 
9
9
  import type { JsonObject } from "@/types/common/Json.js";
@@ -1,8 +1,8 @@
1
1
  /**
2
- * SessionLoopDecision:LocalSessionCore 执行循环的纯决策模块。
2
+ * SessionLoopDecision:Runner 执行循环的纯决策模块。
3
3
  *
4
4
  * 关键点(中文)
5
- * - 把 “是否继续下一轮” 的分支优先级从 LocalSessionCore 主流程中拆出。
5
+ * - 把 “是否继续下一轮” 的分支优先级从 Runner 主流程中拆出。
6
6
  * - 保持纯函数,不依赖模型、持久化或 logger,便于直接测试。
7
7
  */
8
8
 
@@ -13,7 +13,7 @@ import type {
13
13
  } from "@/session/types/SessionLoop.js";
14
14
 
15
15
  /**
16
- * 评估当前 step 完成后,LocalSessionCore 是否应继续下一轮。
16
+ * 评估当前 step 完成后,Runner 是否应继续下一轮。
17
17
  *
18
18
  * 优先级(中文)
19
19
  * 1. 不完整响应恢复
@@ -2,7 +2,7 @@
2
2
  * Session 模型消息运行态。
3
3
  *
4
4
  * 关键点(中文)
5
- * - LocalSessionCore 同时维护 session 语义消息与模型消息。
5
+ * - Runner 同时维护 session 语义消息与模型消息。
6
6
  * - 新增 user 消息可优先做增量转换,失败时再回退为全量重算。
7
7
  * - assistant UI 消息只需要进入 session 语义基线;模型侧使用 SDK 返回的 response messages。
8
8
  */
@@ -15,7 +15,7 @@ import {
15
15
  } from "@session/messages/SessionMessageCodec.js";
16
16
 
17
17
  /**
18
- * LocalSessionCore 单轮执行期间的消息基线。
18
+ * Runner 单轮执行期间的消息基线。
19
19
  */
20
20
  export class SessionModelMessageState {
21
21
  /**
@@ -1,10 +1,10 @@
1
1
  /**
2
- * SessionLoopSignals:LocalSessionCore 执行循环的信号判断与调试摘要工具。
2
+ * SessionLoopSignals:Runner 执行循环的信号判断与调试摘要工具。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里只放“如何判断继续执行 / 如何输出调试摘要”的纯函数。
6
- * - 不放 LocalSessionCore 主流程,避免执行内核被大量辅助细节淹没。
7
- * - 目标是让 LocalSessionCore 保持“只看主链路就能理解”的结构。
6
+ * - 不放 Runner 主流程,避免执行内核被大量辅助细节淹没。
7
+ * - 目标是让 Runner 保持“只看主链路就能理解”的结构。
8
8
  */
9
9
 
10
10
  import {
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里只负责已准备好的 `SessionExecuteInput` 如何进入 `streamText` 循环。
6
- * - LocalSessionCore 保留入口、重试与输入准备职责,本模块负责 step 循环、续写、恢复和最终日志。
6
+ * - Runner 保留入口、重试与输入准备职责,本模块负责 step 循环、续写、恢复和最终日志。
7
7
  * - 运行过程中同时维护 UI assistant 消息、模型消息基线和 step 统计。
8
8
  */
9
9
 
@@ -334,7 +334,7 @@ export class SessionToolLoopRunner {
334
334
  streamError: lastObservedStreamError,
335
335
  });
336
336
 
337
- await this.logger.log("error", "LocalSessionCore execution failed", {
337
+ await this.logger.log("error", "Runner execution failed", {
338
338
  error: errorMsg,
339
339
  });
340
340
 
@@ -1,5 +1,5 @@
1
1
  /**
2
- * LocalSessionCore tool-loop 决策相关类型。
2
+ * Runner tool-loop 决策相关类型。
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里只描述“是否继续下一轮”的纯决策输入/输出。
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - `SessionRunInput` 表示上层会话入口输入(例如 context query)。
6
- * - `SessionExecuteInput` 表示 LocalSessionCore 通过 Composer 装配后的中间运行态。
6
+ * - `SessionExecuteInput` 表示 Runner 通过 Composer 装配后的中间运行态。
7
7
  * - 输出仅暴露 assistantMessage(UIMessage)。
8
8
  */
9
9
 
@@ -107,7 +107,7 @@ export interface SessionRunInput {
107
107
  }
108
108
 
109
109
  /**
110
- * LocalSessionCore 通过 Composer 装配后的中间运行态。
110
+ * Runner 通过 Composer 装配后的中间运行态。
111
111
  */
112
112
  export interface SessionExecuteInput {
113
113
  /**