@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.
- package/bin/agent/local/Agent.d.ts +3 -7
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +14 -19
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/services/{AgentSessionManager.d.ts → AgentSessions.d.ts} +12 -17
- package/bin/agent/local/services/AgentSessions.d.ts.map +1 -0
- package/bin/agent/local/services/{AgentSessionManager.js → AgentSessions.js} +11 -26
- package/bin/agent/local/services/AgentSessions.js.map +1 -0
- package/bin/agent/remote/RemoteAgent.d.ts +2 -9
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +40 -22
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +5 -5
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +5 -3
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +2 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +2 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +5 -5
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +2 -2
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +2 -2
- package/bin/executor/Executor.d.ts +7 -7
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +41 -33
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/SessionRunScope.d.ts +1 -1
- package/bin/executor/SessionRunScope.d.ts.map +1 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +5 -5
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +4 -5
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +73 -40
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts +27 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.d.ts.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js +181 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.js.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts +45 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.d.ts.map +1 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js +144 -0
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.js.map +1 -0
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts +3 -3
- package/bin/executor/composer/context/LocalSessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/context/SessionContextComposer.d.ts +3 -3
- package/bin/executor/composer/context/SessionContextComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts +2 -2
- package/bin/executor/composer/history/SessionHistoryComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts +5 -5
- package/bin/executor/composer/history/SessionHistoryWriter.d.ts.map +1 -1
- package/bin/executor/composer/history/SessionHistoryWriter.js +6 -6
- package/bin/executor/composer/history/SessionHistoryWriter.js.map +1 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts +2 -2
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.d.ts.map +1 -1
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js +5 -4
- package/bin/executor/composer/history/jsonl/JsonlSessionHistoryComposer.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +5 -5
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.d.ts +4 -4
- package/bin/executor/core-engine/CoreEngineSignals.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineSignals.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts +3 -3
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineUiStreamCollector.js.map +1 -1
- package/bin/executor/messages/AssistantResultPersistence.d.ts +5 -5
- package/bin/executor/messages/AssistantResultPersistence.d.ts.map +1 -1
- package/bin/executor/messages/AssistantResultPersistence.js +1 -1
- package/bin/executor/messages/AssistantResultPersistence.js.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.d.ts +3 -3
- package/bin/executor/messages/SessionAttachmentMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionAttachmentMapper.js.map +1 -1
- package/bin/executor/messages/SessionMessageCodec.d.ts +4 -4
- package/bin/executor/messages/SessionMessageCodec.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageCodec.js +5 -5
- package/bin/executor/messages/SessionMessageCodec.js.map +1 -1
- package/bin/executor/messages/SessionMessageLog.d.ts +3 -3
- package/bin/executor/messages/SessionMessageLog.d.ts.map +1 -1
- package/bin/executor/messages/SessionMessageLog.js.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.d.ts +2 -2
- package/bin/executor/messages/SessionStepEventMapper.d.ts.map +1 -1
- package/bin/executor/messages/SessionStepEventMapper.js.map +1 -1
- package/bin/executor/messages/UserVisibleText.d.ts +3 -3
- package/bin/executor/messages/UserVisibleText.d.ts.map +1 -1
- package/bin/executor/messages/UserVisibleText.js +3 -3
- package/bin/executor/messages/UserVisibleText.js.map +1 -1
- package/bin/executor/services/ExecutorInflightService.d.ts +2 -2
- package/bin/executor/services/ExecutorInflightService.d.ts.map +1 -1
- package/bin/executor/services/ExecutorInflightService.js +11 -7
- package/bin/executor/services/ExecutorInflightService.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +30 -27
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.js +3 -3
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +21 -20
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +114 -72
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts +1 -7
- package/bin/executor/tools/plugin/PluginToolDefinition.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts +4 -6
- package/bin/executor/tools/plugin/PluginToolSchemas.d.ts.map +1 -1
- package/bin/executor/tools/plugin/PluginToolSchemas.js +24 -10
- package/bin/executor/tools/plugin/PluginToolSchemas.js.map +1 -1
- package/bin/executor/types/SessionRecords.d.ts +162 -0
- package/bin/executor/types/SessionRecords.d.ts.map +1 -0
- package/bin/executor/types/SessionRecords.js +52 -0
- package/bin/executor/types/SessionRecords.js.map +1 -0
- package/bin/executor/types/SessionRun.d.ts +3 -3
- package/bin/executor/types/SessionRun.d.ts.map +1 -1
- package/bin/index.d.ts +2 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js.map +1 -1
- package/bin/rpc/Client.d.ts +5 -5
- package/bin/rpc/Client.js +4 -4
- package/bin/session/Session.d.ts +6 -6
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +8 -8
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +2 -2
- package/bin/session/SessionTitle.d.ts.map +1 -1
- package/bin/session/SessionTitle.js +5 -0
- package/bin/session/SessionTitle.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +12 -12
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +37 -34
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +1 -1
- package/bin/session/index.js +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +3 -3
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +11 -12
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +43 -69
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.js +3 -3
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts +4 -4
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +26 -36
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts +4 -4
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +2 -2
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +4 -4
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +2 -2
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +11 -11
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +22 -22
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +7 -7
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +6 -6
- package/bin/types/runtime/agent/AgentContext.d.ts +7 -7
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionAction.d.ts +26 -0
- package/bin/types/sdk/AgentSessionAction.d.ts.map +1 -0
- package/bin/types/sdk/AgentSessionAction.js +10 -0
- package/bin/types/sdk/AgentSessionAction.js.map +1 -0
- package/bin/types/sdk/AgentSessionEvent.d.ts +2 -2
- package/bin/types/sdk/AgentSessionEvent.d.ts.map +1 -1
- package/bin/types/sdk/AgentSessionTurn.d.ts +2 -2
- package/bin/types/sdk/AgentSessionTurn.d.ts.map +1 -1
- package/package.json +3 -3
- package/scripts/agent-ready.test.mjs +1 -1
- package/scripts/city-model-tool-loop.test.mjs +36 -4
- package/scripts/plugin-tool-bridge.test.mjs +13 -0
- package/scripts/session-action-message.test.mjs +199 -0
- package/scripts/session-compaction-prompts.test.mjs +97 -0
- package/scripts/session-history-archive.test.mjs +8 -8
- package/scripts/session-history-inflight.test.mjs +10 -10
- package/scripts/session-list-title.test.mjs +9 -9
- package/scripts/session-title-event.test.mjs +12 -10
- package/src/agent/local/Agent.ts +16 -22
- package/src/agent/local/services/{AgentSessionManager.ts → AgentSessions.ts} +16 -32
- package/src/agent/remote/RemoteAgent.ts +58 -23
- package/src/agent/remote/RemoteSession.ts +10 -8
- package/src/agent/remote/RemoteTransport.ts +5 -5
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +10 -10
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +6 -6
- package/src/executor/Executor.ts +51 -41
- package/src/executor/SessionRunScope.ts +1 -1
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +5 -5
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +1 -1
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +91 -52
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionFileOperations.ts +197 -0
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionPrompts.ts +162 -0
- package/src/executor/composer/context/LocalSessionContextComposer.ts +5 -5
- package/src/executor/composer/context/SessionContextComposer.ts +5 -5
- package/src/executor/composer/history/SessionHistoryComposer.ts +2 -2
- package/src/executor/composer/history/SessionHistoryWriter.ts +10 -10
- package/src/executor/composer/history/jsonl/JsonlSessionHistoryComposer.ts +13 -10
- package/src/executor/core-engine/CoreEngineMessageState.ts +8 -8
- package/src/executor/core-engine/CoreEngineRunner.ts +7 -7
- package/src/executor/core-engine/CoreEngineSignals.ts +7 -7
- package/src/executor/core-engine/CoreEngineUiStreamCollector.ts +5 -5
- package/src/executor/messages/AssistantResultPersistence.ts +8 -8
- package/src/executor/messages/SessionAttachmentMapper.ts +11 -11
- package/src/executor/messages/SessionMessageCodec.ts +10 -10
- package/src/executor/messages/SessionMessageLog.ts +3 -3
- package/src/executor/messages/SessionStepEventMapper.ts +5 -5
- package/src/executor/messages/UserVisibleText.ts +9 -9
- package/src/executor/services/ExecutorInflightService.ts +13 -9
- package/src/executor/store/history/SessionHistoryStore.ts +32 -28
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +146 -95
- package/src/executor/tools/plugin/PluginToolSchemas.ts +24 -10
- package/src/executor/types/SessionRecords.ts +217 -0
- package/src/executor/types/SessionRun.ts +5 -5
- package/src/index.ts +9 -10
- package/src/rpc/Client.ts +9 -9
- package/src/session/Session.ts +10 -10
- package/src/session/SessionTitle.ts +7 -4
- package/src/session/browse/Browse.ts +66 -58
- package/src/session/index.ts +1 -1
- package/src/session/runtime/SessionPromptRuntime.ts +6 -6
- package/src/session/services/SessionStateService.ts +61 -86
- package/src/session/services/SessionTurnService.ts +7 -7
- package/src/session/services/SessionViewService.ts +35 -45
- package/src/session/storage/Persistence.ts +6 -6
- package/src/session/storage/RuntimeSessionPort.ts +6 -6
- package/src/types/agent/AgentTypes.ts +4 -4
- package/src/types/agent/SessionActor.ts +12 -12
- package/src/types/agent/SessionTypes.ts +22 -22
- package/src/types/executor/SessionRunContext.ts +12 -12
- package/src/types/rpc/RpcProtocol.ts +6 -6
- package/src/types/runtime/agent/AgentContext.ts +8 -8
- package/src/types/sdk/AgentSessionAction.ts +35 -0
- package/src/types/sdk/AgentSessionEvent.ts +2 -2
- package/src/types/sdk/AgentSessionTurn.ts +2 -2
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +0 -1
- package/bin/agent/local/services/AgentSessionManager.js.map +0 -1
- package/bin/executor/types/SessionMessages.d.ts +0 -118
- package/bin/executor/types/SessionMessages.d.ts.map +0 -1
- package/bin/executor/types/SessionMessages.js +0 -28
- package/bin/executor/types/SessionMessages.js.map +0 -1
- package/bin/types/sdk/AgentSessionOperation.d.ts +0 -99
- package/bin/types/sdk/AgentSessionOperation.d.ts.map +0 -1
- package/bin/types/sdk/AgentSessionOperation.js +0 -10
- package/bin/types/sdk/AgentSessionOperation.js.map +0 -1
- package/scripts/session-operation-message.test.mjs +0 -197
- package/src/executor/types/SessionMessages.ts +0 -148
- package/src/types/sdk/AgentSessionOperation.ts +0 -125
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
2
|
+
* AgentSessions:本地 Agent session 集合入口。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 统一管理 session
|
|
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
|
-
|
|
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
|
|
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
|
|
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:
|
|
115
|
-
private readonly 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:
|
|
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:
|
|
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
|
|
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
|
|
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("
|
|
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
|
|
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
|
|
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("
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
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
|
-
|
|
14
|
-
|
|
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
|
|
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
|
|
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
|
|
139
|
-
return await this.transport.
|
|
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<
|
|
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
|
-
|
|
19
|
-
|
|
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
|
-
|
|
66
|
+
records(
|
|
67
67
|
session_id: string,
|
|
68
|
-
input?:
|
|
69
|
-
): Promise<
|
|
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
|
-
|
|
19
|
-
|
|
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
|
|
187
|
+
async records(
|
|
188
188
|
session_id: string,
|
|
189
|
-
input?:
|
|
190
|
-
): Promise<
|
|
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
|
-
|
|
200
|
+
records?: AgentSessionRecordsPage;
|
|
201
201
|
}>(
|
|
202
|
-
`${this.base_url}/api/sdk/sessions/${encodeURIComponent(session_id)}/
|
|
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.
|
|
210
|
-
throw new Error(String(payload.error || "Remote session
|
|
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.
|
|
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
|
-
|
|
19
|
-
|
|
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
|
|
92
|
+
async records(
|
|
93
93
|
session_id: string,
|
|
94
|
-
input?:
|
|
95
|
-
): Promise<
|
|
96
|
-
return await this.client.
|
|
94
|
+
input?: AgentSessionRecordsInput,
|
|
95
|
+
): Promise<AgentSessionRecordsPage> {
|
|
96
|
+
return await this.client.get_session_records({
|
|
97
97
|
session_id,
|
|
98
98
|
input,
|
|
99
99
|
});
|
package/src/executor/Executor.ts
CHANGED
|
@@ -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 {
|
|
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
|
|
216
|
-
message?:
|
|
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.
|
|
223
|
+
await this.historyWriter.append_user_message(params);
|
|
221
224
|
}
|
|
222
225
|
|
|
223
226
|
/**
|
|
224
227
|
* 追加一条 assistant 消息。
|
|
225
228
|
*/
|
|
226
|
-
async
|
|
227
|
-
message?:
|
|
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.
|
|
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
|
|
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
|
|
375
|
-
|
|
377
|
+
const emit_compaction_action = async (
|
|
378
|
+
action: SessionActionRecordV1,
|
|
376
379
|
): Promise<void> => {
|
|
377
|
-
if (
|
|
378
|
-
|
|
380
|
+
if (action.state === "running") {
|
|
381
|
+
compaction_action_id = action.id;
|
|
379
382
|
}
|
|
380
|
-
await this.
|
|
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
|
-
|
|
391
|
+
onAction: emit_compaction_action,
|
|
389
392
|
});
|
|
390
393
|
} catch (error) {
|
|
391
|
-
await this.
|
|
392
|
-
|
|
393
|
-
|
|
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
|
-
|
|
396
|
-
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
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?.
|
|
496
|
-
? {
|
|
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
|
|
521
|
+
* 发布一次 session action。
|
|
515
522
|
*/
|
|
516
|
-
private async
|
|
523
|
+
private async emitAction(
|
|
517
524
|
run_context: SessionRunContext,
|
|
518
|
-
|
|
525
|
+
action: SessionActionRecordV1,
|
|
519
526
|
): Promise<void> {
|
|
520
|
-
if (typeof run_context.
|
|
521
|
-
const
|
|
522
|
-
String(
|
|
523
|
-
`
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
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/
|
|
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 {
|
|
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
|
-
* 可选
|
|
38
|
+
* 可选 action 发布回调。
|
|
39
39
|
*
|
|
40
40
|
* 说明(中文)
|
|
41
|
-
* - 默认 compaction Composer 可在真正开始压缩时发布
|
|
42
|
-
* - 回调由上层 Session 负责转成订阅事件与
|
|
41
|
+
* - 默认 compaction Composer 可在真正开始压缩时发布 action。
|
|
42
|
+
* - 回调由上层 Session 负责转成订阅事件与 action record。
|
|
43
43
|
*/
|
|
44
|
-
|
|
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.
|
|
82
|
+
...(input.onAction ? { onAction: input.onAction } : {}),
|
|
83
83
|
});
|
|
84
84
|
}
|
|
85
85
|
|