@downcity/agent 1.1.228 → 1.1.232
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.
- package/bin/agent/local/Agent.d.ts +6 -1
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +30 -3
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/AgentSessions.d.ts +23 -0
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessions.js +44 -0
- package/bin/agent/local/services/AgentSessions.js.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +0 -7
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/executor/Executor.d.ts +25 -0
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +36 -0
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +4 -0
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts +0 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +15 -11
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +11 -0
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +12 -8
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +3 -13
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolBridge.js +4 -2
- package/bin/executor/tools/plugin/PluginToolBridge.js.map +1 -1
- package/bin/index.d.ts +2 -1
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -1
- package/bin/index.js.map +1 -1
- package/bin/model/CityModelAdapter.d.ts +6 -0
- package/bin/model/CityModelAdapter.d.ts.map +1 -1
- package/bin/model/CityModelAdapter.js +13 -0
- package/bin/model/CityModelAdapter.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +22 -1
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +46 -4
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/session/Session.d.ts +11 -1
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +76 -11
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +0 -8
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +72 -57
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts +69 -16
- package/bin/session/recorder/JsonlSessionMessageStore.d.ts.map +1 -1
- package/bin/session/recorder/JsonlSessionMessageStore.js +283 -60
- package/bin/session/recorder/JsonlSessionMessageStore.js.map +1 -1
- package/bin/session/recorder/SessionRecorder.d.ts +20 -2
- package/bin/session/recorder/SessionRecorder.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorder.js +91 -46
- package/bin/session/recorder/SessionRecorder.js.map +1 -1
- package/bin/session/recorder/SessionRecorderCompaction.d.ts +3 -3
- package/bin/session/recorder/SessionRecorderCompaction.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorderCompaction.js +50 -62
- package/bin/session/recorder/SessionRecorderCompaction.js.map +1 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts +2 -2
- package/bin/session/recorder/SessionRecorderHistoryStore.d.ts.map +1 -1
- package/bin/session/recorder/SessionRecorderHistoryStore.js +31 -36
- package/bin/session/recorder/SessionRecorderHistoryStore.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +17 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +67 -8
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +15 -1
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +60 -39
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +5 -0
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +17 -3
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +1 -5
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +4 -34
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +3 -15
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +5 -21
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +2 -24
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +21 -0
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +25 -0
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +17 -5
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js +29 -6
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/session/SessionConfigMutation.d.ts +68 -0
- package/bin/types/session/SessionConfigMutation.d.ts.map +1 -0
- package/bin/types/session/SessionConfigMutation.js +10 -0
- package/bin/types/session/SessionConfigMutation.js.map +1 -0
- package/bin/types/session/SessionLocalState.d.ts +8 -0
- package/bin/types/session/SessionLocalState.d.ts.map +1 -1
- package/bin/types/session/SessionMessage.d.ts +16 -12
- package/bin/types/session/SessionMessage.d.ts.map +1 -1
- package/bin/types/session/SessionMutation.d.ts +1 -1
- package/bin/types/session/SessionMutation.js +1 -1
- package/bin/types/session/SessionOptions.d.ts +16 -0
- package/bin/types/session/SessionOptions.d.ts.map +1 -1
- package/bin/types/session/SessionSegment.d.ts +57 -0
- package/bin/types/session/SessionSegment.d.ts.map +1 -0
- package/bin/types/session/SessionSegment.js +8 -0
- package/bin/types/session/SessionSegment.js.map +1 -0
- package/package.json +3 -3
- package/scripts/city-model-tool-loop.test.mjs +32 -0
- package/scripts/session-action-message.test.mjs +59 -13
- package/scripts/session-compaction-context-window.test.mjs +95 -0
- package/scripts/session-config-turn-boundary.test.mjs +224 -0
- package/scripts/session-list-title.test.mjs +21 -3
- package/scripts/session-prompt-runtime.test.mjs +85 -0
- package/scripts/session-recorder.test.mjs +340 -11
- package/src/agent/local/Agent.ts +34 -3
- package/src/agent/local/services/AgentSessions.ts +61 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +0 -5
- package/src/executor/Executor.ts +62 -0
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +5 -0
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +16 -14
- package/src/executor/core-engine/CoreEngineRunner.ts +24 -8
- package/src/executor/store/history/SessionHistoryStore.ts +3 -14
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +1 -1
- package/src/executor/tools/plugin/PluginToolBridge.ts +4 -2
- package/src/index.ts +8 -0
- package/src/model/CityModelAdapter.ts +15 -0
- package/src/plugin/core/PluginRegistry.ts +72 -4
- package/src/session/Session.ts +89 -11
- package/src/session/browse/Browse.ts +73 -69
- package/src/session/recorder/JsonlSessionMessageStore.ts +378 -60
- package/src/session/recorder/SessionRecorder.ts +116 -49
- package/src/session/recorder/SessionRecorderCompaction.ts +55 -80
- package/src/session/recorder/SessionRecorderHistoryStore.ts +29 -49
- package/src/session/runtime/SessionPromptRuntime.ts +100 -9
- package/src/session/services/SessionStateService.ts +79 -44
- package/src/session/services/SessionTurnService.ts +19 -3
- package/src/session/services/SessionViewService.ts +4 -50
- package/src/session/storage/Paths.ts +5 -38
- package/src/types/agent/SessionTypes.ts +2 -24
- package/src/types/executor/SessionRunContext.ts +25 -0
- package/src/types/plugin/PluginRuntime.ts +27 -0
- package/src/types/runtime/agent/AgentContext.ts +32 -7
- package/src/types/session/SessionConfigMutation.ts +78 -0
- package/src/types/session/SessionLocalState.ts +9 -0
- package/src/types/session/SessionMessage.ts +16 -12
- package/src/types/session/SessionMutation.ts +1 -1
- package/src/types/session/SessionOptions.ts +21 -0
- package/src/types/session/SessionSegment.ts +62 -0
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -90,6 +90,8 @@ export interface AgentSessionConfigSnapshot {
|
|
|
90
90
|
modelLabel?: string;
|
|
91
91
|
/** 当前 session 绑定的稳定模型 ID。 */
|
|
92
92
|
modelId?: string;
|
|
93
|
+
/** 当前模型支持的总上下文窗口长度,单位为 token。 */
|
|
94
|
+
model_context_window?: number;
|
|
93
95
|
}
|
|
94
96
|
|
|
95
97
|
/**
|
|
@@ -305,14 +307,6 @@ export interface AgentSessionRecordsInput {
|
|
|
305
307
|
limit?: number;
|
|
306
308
|
/** 分页游标。 */
|
|
307
309
|
cursor?: string;
|
|
308
|
-
/**
|
|
309
|
-
* 要读取的 compact archive 层 ID。
|
|
310
|
-
*
|
|
311
|
-
* 说明(中文)
|
|
312
|
-
* - 省略时读取当前 `messages.jsonl`。
|
|
313
|
-
* - 传入时读取 `messages/archive/<archive_id>.json` 中保存的上一层历史。
|
|
314
|
-
*/
|
|
315
|
-
archive_id?: string;
|
|
316
310
|
/**
|
|
317
311
|
* 返回顺序。
|
|
318
312
|
*
|
|
@@ -359,22 +353,6 @@ export interface AgentSessionRecordsPage {
|
|
|
359
353
|
next_cursor?: string;
|
|
360
354
|
/** 是否仍有更多数据。 */
|
|
361
355
|
has_more: boolean;
|
|
362
|
-
/**
|
|
363
|
-
* 当前读取的 compact archive 层 ID。
|
|
364
|
-
*
|
|
365
|
-
* 说明(中文)
|
|
366
|
-
* - 省略表示当前页来自主历史 `messages.jsonl`。
|
|
367
|
-
* - 有值表示当前页来自指定 compact archive。
|
|
368
|
-
*/
|
|
369
|
-
archive_id?: string;
|
|
370
|
-
/**
|
|
371
|
-
* 当前层更早一次 compact 对应的 archive ID。
|
|
372
|
-
*
|
|
373
|
-
* 关键点(中文)
|
|
374
|
-
* - compact summary 不会出现在 `items` 中。
|
|
375
|
-
* - 若当前层包含 compact summary,则这里暴露其 archive ID,供调用方继续 `session.records({ archive_id })`。
|
|
376
|
-
*/
|
|
377
|
-
previous_archive_id?: string;
|
|
378
356
|
}
|
|
379
357
|
|
|
380
358
|
/**
|
|
@@ -18,6 +18,7 @@ import type {
|
|
|
18
18
|
} from "@/executor/types/SessionRun.js";
|
|
19
19
|
import type { SessionUserMessageV1 } from "@/executor/types/SessionRecords.js";
|
|
20
20
|
import type { FileUIPart } from "ai";
|
|
21
|
+
import type { AgentPluginExecutionRuntime } from "@/types/plugin/PluginRuntime.js";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* 单次 session run 的运行上下文。
|
|
@@ -55,6 +56,30 @@ export interface SessionRunContext {
|
|
|
55
56
|
*/
|
|
56
57
|
onStepCallback?: () => Promise<SessionUserMessageV1[]>;
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* 判断是否仍有等待并入下一模型 turn 的 steer prompt。
|
|
61
|
+
*
|
|
62
|
+
* 关键点(中文)
|
|
63
|
+
* - 只检查 prompt,不把单独的配置 mutation 当成继续调用模型的理由。
|
|
64
|
+
* - 真正的队列消费统一发生在 `onStepCallback`。
|
|
65
|
+
*/
|
|
66
|
+
hasPendingStepInput?: () => boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 当前模型 turn 实际使用的 Agent env。
|
|
70
|
+
*
|
|
71
|
+
* 关键点(中文)
|
|
72
|
+
* - 由 Session 配置队列在模型 turn 开始前更新。
|
|
73
|
+
* - tool/plugin 深层调用通过 run scope 读取,避免看到刚写入但尚未生效的 env。
|
|
74
|
+
*/
|
|
75
|
+
agentEnv?: Readonly<Record<string, string>>;
|
|
76
|
+
|
|
77
|
+
/** 当前模型 turn 已提交生效的 Agent instruction 文本。 */
|
|
78
|
+
agentSystems?: readonly string[];
|
|
79
|
+
|
|
80
|
+
/** 当前模型 turn 捕获的 Plugin 执行视图。 */
|
|
81
|
+
agentPlugins?: AgentPluginExecutionRuntime;
|
|
82
|
+
|
|
58
83
|
/**
|
|
59
84
|
* assistant step 完成回调。
|
|
60
85
|
*
|
|
@@ -142,6 +142,33 @@ export interface AgentPlugins {
|
|
|
142
142
|
pointName: string,
|
|
143
143
|
value: TInput,
|
|
144
144
|
): Promise<TOutput>;
|
|
145
|
+
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/**
|
|
149
|
+
* 单次模型 turn 可使用的 Plugin 能力视图。
|
|
150
|
+
*/
|
|
151
|
+
export interface AgentPluginExecutionRuntime {
|
|
152
|
+
/** 读取当前视图中的 plugin/action metadata。 */
|
|
153
|
+
read(params: {
|
|
154
|
+
/** Plugin 名称(可选)。 */
|
|
155
|
+
plugin?: string;
|
|
156
|
+
/** Action 名称(可选)。 */
|
|
157
|
+
action?: string;
|
|
158
|
+
}): PluginReadView | { plugins: PluginView[] };
|
|
159
|
+
|
|
160
|
+
/** 运行当前视图中捕获的 plugin action。 */
|
|
161
|
+
runAction(params: {
|
|
162
|
+
/** Plugin 名称。 */
|
|
163
|
+
plugin: string;
|
|
164
|
+
/** Action 名称。 */
|
|
165
|
+
action: string;
|
|
166
|
+
/** Action Payload(可选)。 */
|
|
167
|
+
payload?: JsonValue;
|
|
168
|
+
}): Promise<PluginActionResult<JsonValue>>;
|
|
169
|
+
|
|
170
|
+
/** 解析当前视图中捕获的 plugin system blocks。 */
|
|
171
|
+
systemBlocks(): Promise<AgentSessionSystemBlock[]>;
|
|
145
172
|
}
|
|
146
173
|
|
|
147
174
|
/**
|
|
@@ -34,6 +34,7 @@ import type {
|
|
|
34
34
|
} from "@/types/session/SessionMutation.js";
|
|
35
35
|
import type { SessionApprovalRuntimeEvent } from "@/types/session/SessionApproval.js";
|
|
36
36
|
import type { AgentSessionTurnHandle } from "@/types/sdk/AgentSessionTurn.js";
|
|
37
|
+
import { getSessionRunContext } from "@/executor/SessionRunScope.js";
|
|
37
38
|
|
|
38
39
|
/**
|
|
39
40
|
* 跨 plugin runtime 调用参数。
|
|
@@ -233,7 +234,7 @@ export interface AgentContextOptions {
|
|
|
233
234
|
*
|
|
234
235
|
* 关键点(中文)
|
|
235
236
|
* - 必须是 Agent 持有的同一个 mutable 引用,不要克隆后再传入。
|
|
236
|
-
* -
|
|
237
|
+
* - Session 模型 turn 内优先读取队列已经提交的 effective env。
|
|
237
238
|
*/
|
|
238
239
|
env: Record<string, string>;
|
|
239
240
|
/** 当前生效的 system 文本集合。 */
|
|
@@ -267,10 +268,10 @@ export class AgentContext {
|
|
|
267
268
|
readonly logger: Logger;
|
|
268
269
|
/** 当前运行时已解析配置。 */
|
|
269
270
|
readonly config: DowncityConfig;
|
|
270
|
-
/**
|
|
271
|
-
readonly
|
|
272
|
-
/**
|
|
273
|
-
readonly
|
|
271
|
+
/** 当前 Agent configured env 共享对象。 */
|
|
272
|
+
private readonly configured_env: Record<string, string>;
|
|
273
|
+
/** 当前 Agent configured system 文本。 */
|
|
274
|
+
private readonly configured_systems: string[];
|
|
274
275
|
/** 当前可见的路径能力集合。 */
|
|
275
276
|
readonly paths: AgentPathRuntime;
|
|
276
277
|
/** 当前可见的 plugin 配置持久化能力集合。 */
|
|
@@ -289,8 +290,8 @@ export class AgentContext {
|
|
|
289
290
|
this.rootPath = options.rootPath;
|
|
290
291
|
this.logger = options.logger;
|
|
291
292
|
this.config = options.config;
|
|
292
|
-
this.
|
|
293
|
-
this.
|
|
293
|
+
this.configured_env = options.env;
|
|
294
|
+
this.configured_systems = options.systems;
|
|
294
295
|
this.paths = options.paths;
|
|
295
296
|
this.pluginConfig = options.pluginConfig;
|
|
296
297
|
this.pluginInstances = options.pluginInstances;
|
|
@@ -301,6 +302,30 @@ export class AgentContext {
|
|
|
301
302
|
};
|
|
302
303
|
}
|
|
303
304
|
|
|
305
|
+
/**
|
|
306
|
+
* 读取当前调用链可见的 Agent env。
|
|
307
|
+
*
|
|
308
|
+
* 关键点(中文)
|
|
309
|
+
* - 模型 turn 内优先返回统一输入队列已经提交的 effective env。
|
|
310
|
+
* - Session 运行外返回 Agent 配置 API 最近一次成功写入的 configured env。
|
|
311
|
+
*/
|
|
312
|
+
get env(): Record<string, string> {
|
|
313
|
+
const effective_env = getSessionRunContext()?.agentEnv;
|
|
314
|
+
return effective_env
|
|
315
|
+
? { ...effective_env }
|
|
316
|
+
: this.configured_env;
|
|
317
|
+
}
|
|
318
|
+
|
|
319
|
+
/**
|
|
320
|
+
* 读取当前调用链可见的 Agent instruction。
|
|
321
|
+
*/
|
|
322
|
+
get systems(): string[] {
|
|
323
|
+
const effective_systems = getSessionRunContext()?.agentSystems;
|
|
324
|
+
return effective_systems
|
|
325
|
+
? [...effective_systems]
|
|
326
|
+
: this.configured_systems;
|
|
327
|
+
}
|
|
328
|
+
|
|
304
329
|
/**
|
|
305
330
|
* 读取指定 sessionId 对应的 session 端口。
|
|
306
331
|
*
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session 配置 Mutation 运行时类型。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 配置 API 负责把 configured state 修改成功后创建 mutation。
|
|
6
|
+
* - mutation 与 steer 共用 Session 输入队列,并在下一次模型 turn 开始前提交。
|
|
7
|
+
* - 这里只描述进程内提交协议,不属于持久化格式或公开 SDK 协议。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
|
|
11
|
+
import type { AgentPluginExecutionRuntime } from "@/types/plugin/PluginRuntime.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* 配置 Mutation 的归属作用域。
|
|
15
|
+
*/
|
|
16
|
+
export type SessionConfigMutationScope = "agent" | "session";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* 配置 Mutation 生效时的模型 turn 上下文。
|
|
20
|
+
*/
|
|
21
|
+
export interface SessionConfigMutationApplyContext {
|
|
22
|
+
/** 当前公开 Session turn 标识。 */
|
|
23
|
+
turn_id: string;
|
|
24
|
+
|
|
25
|
+
/** 当前 Session turn 内即将开始的模型 turn 序号。 */
|
|
26
|
+
model_turn_index: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/**
|
|
30
|
+
* 等待在下一次模型 turn 提交的配置 Mutation。
|
|
31
|
+
*/
|
|
32
|
+
export interface SessionRuntimeConfigMutation {
|
|
33
|
+
/** 当前配置修改的稳定唯一标识。 */
|
|
34
|
+
mutation_id: string;
|
|
35
|
+
|
|
36
|
+
/** 当前配置修改属于 Agent 还是 Session。 */
|
|
37
|
+
scope: SessionConfigMutationScope;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 把 configured state 提交为当前 Session 的 effective state。
|
|
41
|
+
*
|
|
42
|
+
* 关键点(中文)
|
|
43
|
+
* - 成功或失败的 action message 由具体配置实现负责写入。
|
|
44
|
+
* - 抛错只终止当前 mutation,不应让后续 mutation 静默丢失。
|
|
45
|
+
*/
|
|
46
|
+
apply(context: SessionConfigMutationApplyContext): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Agent configured state 广播给已有 Session 的配置修改。
|
|
51
|
+
*/
|
|
52
|
+
export type AgentSessionConfigMutation =
|
|
53
|
+
| {
|
|
54
|
+
/** 当前修改固定为 instruction。 */
|
|
55
|
+
type: "instruction";
|
|
56
|
+
/** 当前配置修改唯一标识。 */
|
|
57
|
+
mutation_id: string;
|
|
58
|
+
/** 下一模型 turn 使用的 instruction blocks。 */
|
|
59
|
+
instruction_blocks: AgentSessionSystemBlock[];
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
/** 当前修改固定为 env。 */
|
|
63
|
+
type: "env";
|
|
64
|
+
/** 当前配置修改唯一标识。 */
|
|
65
|
+
mutation_id: string;
|
|
66
|
+
/** 下一模型 turn 使用的完整 Agent env。 */
|
|
67
|
+
env: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
| {
|
|
70
|
+
/** 当前修改固定为 plugin registry。 */
|
|
71
|
+
type: "plugins";
|
|
72
|
+
/** 当前配置修改唯一标识。 */
|
|
73
|
+
mutation_id: string;
|
|
74
|
+
/** 当前 plugin 配置修改的用户可读标题。 */
|
|
75
|
+
title: string;
|
|
76
|
+
/** 下一模型 turn 使用的 Plugin 执行视图。 */
|
|
77
|
+
plugins: AgentPluginExecutionRuntime;
|
|
78
|
+
};
|
|
@@ -18,6 +18,15 @@ export interface SessionLocalState {
|
|
|
18
18
|
*/
|
|
19
19
|
sessionConfig: AgentSessionConfigSnapshot;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 当前模型 turn 实际使用的 Session 配置。
|
|
23
|
+
*
|
|
24
|
+
* 关键点(中文)
|
|
25
|
+
* - `sessionConfig` 是配置 API 最近一次成功写入的 configured state。
|
|
26
|
+
* - 该字段只在模型 turn 开始前由队列 mutation 更新。
|
|
27
|
+
*/
|
|
28
|
+
effective_session_config: AgentSessionConfigSnapshot;
|
|
29
|
+
|
|
21
30
|
/**
|
|
22
31
|
* 当前 session 创建时间(毫秒时间戳)。
|
|
23
32
|
*/
|
|
@@ -228,26 +228,30 @@ export type SessionMessage =
|
|
|
228
228
|
|
|
229
229
|
/** 读取 Session Message snapshot 的分页输入。 */
|
|
230
230
|
export interface ListSessionMessagesInput {
|
|
231
|
-
/**
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
231
|
+
/**
|
|
232
|
+
* 返回该 sequence 之前的最近一个完整历史 Segment。
|
|
233
|
+
*
|
|
234
|
+
* 必须是正整数;省略时直接返回 Active 中的全部 Message。
|
|
235
|
+
*/
|
|
236
236
|
before_sequence?: number;
|
|
237
237
|
/** 是否包含 internal Message。 */
|
|
238
238
|
include_internal?: boolean;
|
|
239
|
-
/** 只返回不大于该 sequence 的 Message。 */
|
|
240
|
-
through_sequence?: number;
|
|
241
239
|
}
|
|
242
240
|
|
|
243
241
|
/** Session Message snapshot 分页结果。 */
|
|
244
242
|
export interface SessionMessagePage {
|
|
245
|
-
/**
|
|
243
|
+
/** 当前 Active 或 Segment 中按 sequence 升序排列的 Message。 */
|
|
246
244
|
items: SessionMessage[];
|
|
247
|
-
/**
|
|
245
|
+
/** 当前 Session 已分配的真实 Message 总数。 */
|
|
248
246
|
total: number;
|
|
249
|
-
/**
|
|
250
|
-
|
|
251
|
-
/**
|
|
247
|
+
/** 当前结果来自 Active 还是已关闭 Segment。 */
|
|
248
|
+
source: "active" | "segment";
|
|
249
|
+
/** 当前结果覆盖的第一条真实 Message sequence。 */
|
|
250
|
+
start_sequence?: number;
|
|
251
|
+
/** 当前结果覆盖的最后一条真实 Message sequence。 */
|
|
252
|
+
end_sequence?: number;
|
|
253
|
+
/** 继续向前读取时应作为 before_sequence 传入的边界。 */
|
|
254
|
+
next_before_sequence?: number;
|
|
255
|
+
/** 当前结果之前是否仍有更早 Segment。 */
|
|
252
256
|
has_more: boolean;
|
|
253
257
|
}
|
|
@@ -11,6 +11,8 @@ import type { Tool } from "ai";
|
|
|
11
11
|
import type { AgentSession } from "@/types/agent/SessionActor.js";
|
|
12
12
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
13
13
|
import type { AgentSessionSystemBlock } from "@/types/agent/SessionTypes.js";
|
|
14
|
+
import type { AgentPluginExecutionRuntime } from "@/types/plugin/PluginRuntime.js";
|
|
15
|
+
import type { AgentSessionConfigMutation } from "@/types/session/SessionConfigMutation.js";
|
|
14
16
|
import type { SessionComposerOptions } from "@/types/session/SessionComposerOptions.js";
|
|
15
17
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
16
18
|
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
@@ -40,6 +42,13 @@ export interface AgentManagedSession extends AgentSession {
|
|
|
40
42
|
* 返回当前 session 是否正在执行。
|
|
41
43
|
*/
|
|
42
44
|
isExecuting(): boolean;
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* 把 Agent configured state 修改加入当前 Session 的统一输入队列。
|
|
48
|
+
*/
|
|
49
|
+
enqueue_agent_config(
|
|
50
|
+
mutation: AgentSessionConfigMutation,
|
|
51
|
+
): void;
|
|
43
52
|
}
|
|
44
53
|
|
|
45
54
|
/**
|
|
@@ -76,6 +85,18 @@ export interface SessionOptions {
|
|
|
76
85
|
*/
|
|
77
86
|
getInstructionSystemBlocks: () => AgentSessionSystemBlock[];
|
|
78
87
|
|
|
88
|
+
/**
|
|
89
|
+
* 读取当前 Agent configured env。
|
|
90
|
+
*
|
|
91
|
+
* 关键点(中文)
|
|
92
|
+
* - Session 创建时用它建立初始 effective env。
|
|
93
|
+
* - 后续 Agent env 修改通过 Session 配置 mutation 在模型 turn 边界提交。
|
|
94
|
+
*/
|
|
95
|
+
getAgentEnv: () => Record<string, string>;
|
|
96
|
+
|
|
97
|
+
/** 创建当前 Agent configured plugin 的模型 turn 执行视图。 */
|
|
98
|
+
get_agent_plugins: () => AgentPluginExecutionRuntime;
|
|
99
|
+
|
|
79
100
|
/**
|
|
80
101
|
* 读取当前 agent 显式注入的受托管 plugin system blocks。
|
|
81
102
|
*/
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session Message 物理分段类型。
|
|
3
|
+
*
|
|
4
|
+
* Segment 保存一段连续的原始 Message,并在文件末尾保存覆盖到该段末尾的累计 Summary。
|
|
5
|
+
* Summary 只服务模型上下文,不占用 Session Message sequence。
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { SessionMessage } from "@/types/session/SessionMessage.js";
|
|
9
|
+
|
|
10
|
+
/** 已关闭 Segment 的累计上下文摘要。 */
|
|
11
|
+
export interface SessionSegmentSummary {
|
|
12
|
+
/** 记录类型固定为 summary,用于和原始 Message 行区分。 */
|
|
13
|
+
record_type: "summary";
|
|
14
|
+
/** 当前 Summary 所属 Session 标识。 */
|
|
15
|
+
session_id: string;
|
|
16
|
+
/** 当前 Summary 的稳定唯一标识。 */
|
|
17
|
+
summary_id: string;
|
|
18
|
+
/** 当前 Summary 已覆盖到的最后一条真实 Message sequence。 */
|
|
19
|
+
through_sequence: number;
|
|
20
|
+
/** 供下一轮模型直接使用的累计摘要文本。 */
|
|
21
|
+
text: string;
|
|
22
|
+
/** 当前 Summary 创建时间戳(ms)。 */
|
|
23
|
+
created_at: number;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** 已关闭 Segment 的 sequence 范围与文件位置。 */
|
|
27
|
+
export interface SessionSegmentRange {
|
|
28
|
+
/** Segment 内第一条真实 Message sequence。 */
|
|
29
|
+
start_sequence: number;
|
|
30
|
+
/** Segment 内最后一条真实 Message sequence。 */
|
|
31
|
+
end_sequence: number;
|
|
32
|
+
/** Segment JSONL 文件的绝对路径。 */
|
|
33
|
+
file_path: string;
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
/** 从一个已关闭 Segment 读取出的完整数据。 */
|
|
37
|
+
export interface SessionSegmentSnapshot {
|
|
38
|
+
/** Segment 的 sequence 范围。 */
|
|
39
|
+
range: SessionSegmentRange;
|
|
40
|
+
/** Segment 中按 sequence 升序排列的原始 Message。 */
|
|
41
|
+
messages: SessionMessage[];
|
|
42
|
+
/** Segment 文件末尾的累计 Summary。 */
|
|
43
|
+
summary: SessionSegmentSummary;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** 当前模型上下文所需的最小 Session 快照。 */
|
|
47
|
+
export interface SessionContextSnapshot {
|
|
48
|
+
/** 最新已关闭 Segment 的累计 Summary;从未 Compact 时为空。 */
|
|
49
|
+
summary: SessionSegmentSummary | null;
|
|
50
|
+
/** Active 中上次 Compact 后产生的全部真实 Message。 */
|
|
51
|
+
messages: SessionMessage[];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/** Session 历史存储统计。 */
|
|
55
|
+
export interface SessionMessageStorageStats {
|
|
56
|
+
/** 当前 Session 已分配的真实 Message 总数。 */
|
|
57
|
+
message_count: number;
|
|
58
|
+
/** Active 与所有 Segment 文件占用的总字节数。 */
|
|
59
|
+
history_bytes: number;
|
|
60
|
+
/** 当前最新真实 Message;空 Session 时为空。 */
|
|
61
|
+
latest_message: SessionMessage | null;
|
|
62
|
+
}
|