@downcity/agent 1.1.228 → 1.1.236
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/RemoteSession.d.ts +2 -0
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +4 -0
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +2 -0
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +1 -0
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +11 -7
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +1 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +3 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/executor/Executor.d.ts +43 -0
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +127 -7
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts +10 -0
- package/bin/executor/composer/compaction/SessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts +0 -10
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js +4 -34
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts +1 -3
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +7 -59
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts +38 -0
- package/bin/executor/core-engine/CoreEngineContextCompaction.d.ts.map +1 -0
- package/bin/executor/core-engine/CoreEngineContextCompaction.js +392 -0
- package/bin/executor/core-engine/CoreEngineContextCompaction.js.map +1 -0
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts +15 -0
- package/bin/executor/core-engine/CoreEngineMessageState.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineMessageState.js +20 -0
- package/bin/executor/core-engine/CoreEngineMessageState.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts +15 -0
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +150 -35
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/store/history/SessionHistoryStore.d.ts +7 -23
- package/bin/executor/store/history/SessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +2 -4
- 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/executor/types/SessionRun.d.ts +8 -0
- package/bin/executor/types/SessionRun.d.ts.map +1 -1
- package/bin/index.d.ts +3 -2
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +2 -2
- 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/PluginLocalExecution.js +3 -3
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/core/PluginRegistry.d.ts +41 -2
- package/bin/plugin/core/PluginRegistry.d.ts.map +1 -1
- package/bin/plugin/core/PluginRegistry.js +145 -6
- package/bin/plugin/core/PluginRegistry.js.map +1 -1
- package/bin/rpc/Client.d.ts +4 -0
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +11 -0
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +15 -1
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +83 -11
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionSystemBuilder.d.ts.map +1 -1
- package/bin/session/SessionSystemBuilder.js +3 -1
- package/bin/session/SessionSystemBuilder.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 +118 -88
- 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 +21 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +65 -8
- package/bin/session/runtime/SessionPromptRuntime.js.map +1 -1
- package/bin/session/services/SessionStateService.d.ts +19 -1
- package/bin/session/services/SessionStateService.d.ts.map +1 -1
- package/bin/session/services/SessionStateService.js +70 -40
- package/bin/session/services/SessionStateService.js.map +1 -1
- package/bin/session/services/SessionTurnService.d.ts +15 -0
- package/bin/session/services/SessionTurnService.d.ts.map +1 -1
- package/bin/session/services/SessionTurnService.js +104 -7
- 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/SessionActor.d.ts +8 -0
- package/bin/types/agent/SessionActor.d.ts.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 +29 -0
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/plugin/PluginRuntime.d.ts +59 -2
- package/bin/types/plugin/PluginRuntime.d.ts.map +1 -1
- package/bin/types/plugin/PluginState.d.ts +10 -0
- package/bin/types/plugin/PluginState.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.d.ts +10 -0
- package/bin/types/rpc/RpcProtocol.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/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/SessionQueueCommand.d.ts +68 -0
- package/bin/types/session/SessionQueueCommand.d.ts.map +1 -0
- package/bin/types/session/SessionQueueCommand.js +10 -0
- package/bin/types/session/SessionQueueCommand.js.map +1 -0
- 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/bin/utils/logger/Logger.d.ts +7 -9
- package/bin/utils/logger/Logger.d.ts.map +1 -1
- package/bin/utils/logger/Logger.js +11 -9
- package/bin/utils/logger/Logger.js.map +1 -1
- package/package.json +3 -3
- package/scripts/city-model-tool-loop.test.mjs +32 -0
- package/scripts/core-engine-context-compaction.test.mjs +411 -0
- package/scripts/logger-isolation.test.mjs +55 -0
- package/scripts/multi-agent-plugin-isolation.test.mjs +289 -0
- package/scripts/plugin-tool-bridge.test.mjs +52 -0
- package/scripts/remote-session-reconnect.test.mjs +18 -0
- package/scripts/session-action-message.test.mjs +59 -13
- package/scripts/session-compaction-context-window.test.mjs +96 -0
- package/scripts/session-config-turn-boundary.test.mjs +278 -0
- package/scripts/session-list-title.test.mjs +21 -3
- package/scripts/session-prompt-runtime.test.mjs +93 -0
- package/scripts/session-recorder.test.mjs +335 -15
- package/src/agent/local/Agent.ts +34 -3
- package/src/agent/local/services/AgentSessions.ts +61 -0
- package/src/agent/remote/RemoteSession.ts +5 -0
- package/src/agent/remote/RemoteTransport.ts +2 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +15 -5
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +4 -0
- package/src/executor/Executor.ts +161 -7
- package/src/executor/composer/compaction/SessionCompactionComposer.ts +12 -0
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionComposer.ts +4 -55
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +8 -66
- package/src/executor/core-engine/CoreEngineContextCompaction.ts +477 -0
- package/src/executor/core-engine/CoreEngineMessageState.ts +29 -0
- package/src/executor/core-engine/CoreEngineRunner.ts +211 -43
- package/src/executor/store/history/SessionHistoryStore.ts +7 -26
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +2 -4
- package/src/executor/tools/plugin/PluginToolBridge.ts +4 -2
- package/src/executor/types/SessionRun.ts +9 -0
- package/src/index.ts +9 -1
- package/src/model/CityModelAdapter.ts +15 -0
- package/src/plugin/core/PluginLocalExecution.ts +3 -3
- package/src/plugin/core/PluginRegistry.ts +187 -6
- package/src/rpc/Client.ts +12 -0
- package/src/session/Session.ts +97 -11
- package/src/session/SessionSystemBuilder.ts +4 -1
- 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 +131 -108
- package/src/session/recorder/SessionRecorderHistoryStore.ts +29 -49
- package/src/session/runtime/SessionPromptRuntime.ts +86 -10
- package/src/session/services/SessionStateService.ts +89 -45
- package/src/session/services/SessionTurnService.ts +112 -7
- package/src/session/services/SessionViewService.ts +4 -50
- package/src/session/storage/Paths.ts +5 -38
- package/src/types/agent/SessionActor.ts +9 -0
- package/src/types/agent/SessionTypes.ts +2 -24
- package/src/types/executor/SessionRunContext.ts +34 -0
- package/src/types/plugin/PluginRuntime.ts +63 -2
- package/src/types/plugin/PluginState.ts +10 -0
- package/src/types/rpc/RpcProtocol.ts +11 -0
- package/src/types/runtime/agent/AgentContext.ts +32 -7
- 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/SessionQueueCommand.ts +78 -0
- package/src/types/session/SessionSegment.ts +62 -0
- package/src/utils/logger/Logger.ts +10 -10
- package/tsconfig.tsbuildinfo +1 -1
|
@@ -8,12 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import { nanoid } from "nanoid";
|
|
11
|
-
import {
|
|
12
|
-
buildSessionRecordsPage,
|
|
13
|
-
buildSessionInfo,
|
|
14
|
-
loadSessionArchiveMessagesFromPath,
|
|
15
|
-
} from "@/session/browse/Browse.js";
|
|
16
|
-
import { getSdkAgentSessionArchiveFilePath } from "@/session/storage/Paths.js";
|
|
11
|
+
import { buildSessionInfo } from "@/session/browse/Browse.js";
|
|
17
12
|
import { ensureSessionTitle } from "@/session/SessionTitle.js";
|
|
18
13
|
import { readSessionMetadata } from "@/session/storage/Metadata.js";
|
|
19
14
|
import { buildSessionSystemBlocks } from "@/session/SessionSystemBuilder.js";
|
|
@@ -21,8 +16,6 @@ import type { SessionHistoryStore } from "@/executor/store/history/SessionHistor
|
|
|
21
16
|
import type { SessionSystemComposer } from "@/executor/composer/system/SessionSystemComposer.js";
|
|
22
17
|
import type {
|
|
23
18
|
AgentSessionForkInput,
|
|
24
|
-
AgentSessionRecordsInput,
|
|
25
|
-
AgentSessionRecordsPage,
|
|
26
19
|
AgentSessionInfo,
|
|
27
20
|
AgentSessionSystemBlock,
|
|
28
21
|
AgentSessionSystemSnapshot,
|
|
@@ -192,42 +185,6 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
192
185
|
});
|
|
193
186
|
}
|
|
194
187
|
|
|
195
|
-
/**
|
|
196
|
-
* 读取当前 session records 分页。
|
|
197
|
-
*/
|
|
198
|
-
async records(
|
|
199
|
-
input?: AgentSessionRecordsInput,
|
|
200
|
-
): Promise<AgentSessionRecordsPage> {
|
|
201
|
-
const archive_id = String(input?.archive_id || "").trim();
|
|
202
|
-
const [metadata, current_messages] = await Promise.all([
|
|
203
|
-
readSessionMetadata({
|
|
204
|
-
projectRoot: this.project_root,
|
|
205
|
-
agentId: this.agent_id,
|
|
206
|
-
sessionId: this.session_id,
|
|
207
|
-
}),
|
|
208
|
-
this.history_store.list_records(),
|
|
209
|
-
]);
|
|
210
|
-
const page_messages = archive_id
|
|
211
|
-
? await loadSessionArchiveMessagesFromPath(
|
|
212
|
-
getSdkAgentSessionArchiveFilePath(
|
|
213
|
-
this.project_root,
|
|
214
|
-
this.agent_id,
|
|
215
|
-
this.session_id,
|
|
216
|
-
archive_id,
|
|
217
|
-
),
|
|
218
|
-
)
|
|
219
|
-
: current_messages;
|
|
220
|
-
const session = await this.build_info({
|
|
221
|
-
metadata,
|
|
222
|
-
messages: current_messages,
|
|
223
|
-
});
|
|
224
|
-
return buildSessionRecordsPage({
|
|
225
|
-
session,
|
|
226
|
-
messages: page_messages,
|
|
227
|
-
input,
|
|
228
|
-
});
|
|
229
|
-
}
|
|
230
|
-
|
|
231
188
|
/**
|
|
232
189
|
* 读取当前 session 生效的 system 快照。
|
|
233
190
|
*/
|
|
@@ -290,14 +247,11 @@ export class SessionViewService<TSession extends Pick<AgentSession, "set">> {
|
|
|
290
247
|
typeof input === "string"
|
|
291
248
|
? String(input || "").trim() || undefined
|
|
292
249
|
: String(input?.messageId || "").trim() || undefined;
|
|
293
|
-
const
|
|
294
|
-
limit: 500,
|
|
295
|
-
include_internal: true,
|
|
296
|
-
});
|
|
250
|
+
const messages = await this.recorder.list_history_messages();
|
|
297
251
|
const fork_messages =
|
|
298
252
|
!message_id
|
|
299
|
-
?
|
|
300
|
-
: this.resolve_fork_messages(
|
|
253
|
+
? messages
|
|
254
|
+
: this.resolve_fork_messages(messages, message_id);
|
|
301
255
|
const action_id = `history-forking:${this.session_id}:${Date.now()}:${nanoid(8)}`;
|
|
302
256
|
|
|
303
257
|
await this.state_service.emit_action_event({
|
|
@@ -88,7 +88,7 @@ export function getSdkAgentArchivedSessionMessagesDirPath(
|
|
|
88
88
|
}
|
|
89
89
|
|
|
90
90
|
/**
|
|
91
|
-
* 单个已归档 session
|
|
91
|
+
* 单个已归档 session 的 Active JSONL 文件路径。
|
|
92
92
|
*/
|
|
93
93
|
export function getSdkAgentArchivedSessionMessagesPath(
|
|
94
94
|
projectRoot: string,
|
|
@@ -97,7 +97,7 @@ export function getSdkAgentArchivedSessionMessagesPath(
|
|
|
97
97
|
): string {
|
|
98
98
|
return path.join(
|
|
99
99
|
getSdkAgentArchivedSessionMessagesDirPath(projectRoot, agentId, sessionId),
|
|
100
|
-
"
|
|
100
|
+
"active.jsonl",
|
|
101
101
|
);
|
|
102
102
|
}
|
|
103
103
|
|
|
@@ -144,7 +144,7 @@ export function getSdkAgentSessionMessagesDirPath(
|
|
|
144
144
|
}
|
|
145
145
|
|
|
146
146
|
/**
|
|
147
|
-
* 单个 session
|
|
147
|
+
* 单个 session 的 Active JSONL 文件路径。
|
|
148
148
|
*/
|
|
149
149
|
export function getSdkAgentSessionMessagesPath(
|
|
150
150
|
projectRoot: string,
|
|
@@ -153,7 +153,7 @@ export function getSdkAgentSessionMessagesPath(
|
|
|
153
153
|
): string {
|
|
154
154
|
return path.join(
|
|
155
155
|
getSdkAgentSessionMessagesDirPath(projectRoot, agentId, sessionId),
|
|
156
|
-
"
|
|
156
|
+
"active.jsonl",
|
|
157
157
|
);
|
|
158
158
|
}
|
|
159
159
|
|
|
@@ -171,46 +171,13 @@ export function getSdkAgentSessionMetaPath(
|
|
|
171
171
|
);
|
|
172
172
|
}
|
|
173
173
|
|
|
174
|
-
/**
|
|
175
|
-
* 单个 session 的 archive 目录路径。
|
|
176
|
-
*/
|
|
177
|
-
export function getSdkAgentSessionArchiveDirPath(
|
|
178
|
-
projectRoot: string,
|
|
179
|
-
agentId: string,
|
|
180
|
-
sessionId: string,
|
|
181
|
-
): string {
|
|
182
|
-
return path.join(
|
|
183
|
-
getSdkAgentSessionMessagesDirPath(projectRoot, agentId, sessionId),
|
|
184
|
-
"archive",
|
|
185
|
-
);
|
|
186
|
-
}
|
|
187
|
-
|
|
188
|
-
/**
|
|
189
|
-
* 单个 session 的 compact archive JSON 文件路径。
|
|
190
|
-
*
|
|
191
|
-
* 关键点(中文)
|
|
192
|
-
* - `archiveId` 来自 compact summary metadata,不由调用方拼接扩展名。
|
|
193
|
-
* - 这里统一 encode,避免 archiveId 中的特殊字符影响文件路径。
|
|
194
|
-
*/
|
|
195
|
-
export function getSdkAgentSessionArchiveFilePath(
|
|
196
|
-
projectRoot: string,
|
|
197
|
-
agentId: string,
|
|
198
|
-
sessionId: string,
|
|
199
|
-
archiveId: string,
|
|
200
|
-
): string {
|
|
201
|
-
return path.join(
|
|
202
|
-
getSdkAgentSessionArchiveDirPath(projectRoot, agentId, sessionId),
|
|
203
|
-
`${encodeURIComponent(String(archiveId || "").trim())}.json`,
|
|
204
|
-
);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
174
|
/**
|
|
208
175
|
* 单个 session 的 inflight assistant 路径。
|
|
209
176
|
*
|
|
210
177
|
* 关键点(中文)
|
|
211
178
|
* - 运行中的 assistant 只保留一份增量快照。
|
|
212
179
|
* - step / tool 过程会持续重写这个文件,避免中途中断后过程完全丢失。
|
|
213
|
-
* - 完成后再把最终 assistant 合并进 `
|
|
180
|
+
* - 完成后再把最终 assistant 合并进 `active.jsonl`,并清理该文件。
|
|
214
181
|
*/
|
|
215
182
|
export function getSdkAgentSessionAssistantMessagePath(
|
|
216
183
|
projectRoot: string,
|
|
@@ -79,6 +79,15 @@ export interface AgentSessionActor {
|
|
|
79
79
|
/** 停止当前 turn,并取消尚未被吸收的排队 prompt。 */
|
|
80
80
|
stop(): Promise<AgentSessionStopResult>;
|
|
81
81
|
|
|
82
|
+
/**
|
|
83
|
+
* 把一次显式历史压缩加入当前 Session 的有序输入队列。
|
|
84
|
+
*
|
|
85
|
+
* 关键点(中文)
|
|
86
|
+
* - 返回表示 command 已成功入队,不表示压缩已经执行完成。
|
|
87
|
+
* - 实际结果通过 Session action message 对外观测。
|
|
88
|
+
*/
|
|
89
|
+
compact(): Promise<void>;
|
|
90
|
+
|
|
82
91
|
/** 订阅当前 session 的未来事件。 */
|
|
83
92
|
subscribe(
|
|
84
93
|
subscriber: SessionMutationSubscriber,
|
|
@@ -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 { AgentPluginExecutionLease } from "@/types/plugin/PluginRuntime.js";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* 单次 session run 的运行上下文。
|
|
@@ -55,6 +56,39 @@ export interface SessionRunContext {
|
|
|
55
56
|
*/
|
|
56
57
|
onStepCallback?: () => Promise<SessionUserMessageV1[]>;
|
|
57
58
|
|
|
59
|
+
/**
|
|
60
|
+
* 判断是否仍有等待并入下一 Session step 的 steer prompt。
|
|
61
|
+
*
|
|
62
|
+
* 关键点(中文)
|
|
63
|
+
* - 只检查 prompt,不把单独的 command 当成继续调用模型的理由。
|
|
64
|
+
* - 真正的队列消费统一发生在 `onStepCallback`。
|
|
65
|
+
*/
|
|
66
|
+
hasPendingStepInput?: () => boolean;
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* 消费一次 canonical history 重载请求。
|
|
70
|
+
*
|
|
71
|
+
* 关键点(中文)
|
|
72
|
+
* - QueueCommand 重写持久化历史后返回 true。
|
|
73
|
+
* - CoreEngine 必须在下一次 provider 调用前重新读取 records,并且每次请求只能消费一次。
|
|
74
|
+
*/
|
|
75
|
+
consume_history_reload?: () => boolean;
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* 当前 Session step 实际使用的 Agent env。
|
|
79
|
+
*
|
|
80
|
+
* 关键点(中文)
|
|
81
|
+
* - 由 Session 统一输入队列在 step 检查点更新。
|
|
82
|
+
* - tool/plugin 深层调用通过 run scope 读取,避免看到刚写入但尚未生效的 env。
|
|
83
|
+
*/
|
|
84
|
+
agentEnv?: Readonly<Record<string, string>>;
|
|
85
|
+
|
|
86
|
+
/** 当前 Session step 已提交生效的 Agent instruction 文本。 */
|
|
87
|
+
agentSystems?: readonly string[];
|
|
88
|
+
|
|
89
|
+
/** 当前 Session step 持有的 Plugin 执行 lease。 */
|
|
90
|
+
agentPlugins?: AgentPluginExecutionLease;
|
|
91
|
+
|
|
58
92
|
/**
|
|
59
93
|
* assistant step 完成回调。
|
|
60
94
|
*
|
|
@@ -95,11 +95,17 @@ export interface PluginAvailability {
|
|
|
95
95
|
export interface AgentPlugins {
|
|
96
96
|
/** 注册或替换一个 plugin。 */
|
|
97
97
|
register(plugin: Plugin): Promise<PluginSnapshot>;
|
|
98
|
-
/**
|
|
98
|
+
/**
|
|
99
|
+
* 从 configured registry 卸载一个 plugin。
|
|
100
|
+
*
|
|
101
|
+
* 关键点(中文)
|
|
102
|
+
* - 返回值表示 configured registry 是否发生删除。
|
|
103
|
+
* - 活跃 Session step 仍可使用已捕获的 execution lease,lifecycle.stop 在 lease 释放后执行。
|
|
104
|
+
*/
|
|
99
105
|
unregister(pluginName: string): Promise<boolean>;
|
|
100
106
|
/** 启动全部已挂载 plugin lifecycle。 */
|
|
101
107
|
startAll(): Promise<PluginSnapshot[]>;
|
|
102
|
-
/** 卸载全部 plugin
|
|
108
|
+
/** 卸载全部 plugin,并等待所有 execution lease 释放后的 lifecycle.stop 完成。 */
|
|
103
109
|
unregisterAll(): Promise<void>;
|
|
104
110
|
/** 判断 plugin 是否已注册。 */
|
|
105
111
|
has(pluginName: string): boolean;
|
|
@@ -142,6 +148,61 @@ export interface AgentPlugins {
|
|
|
142
148
|
pointName: string,
|
|
143
149
|
value: TInput,
|
|
144
150
|
): Promise<TOutput>;
|
|
151
|
+
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Plugin execution view 的只读调用能力。
|
|
156
|
+
*/
|
|
157
|
+
export interface AgentPluginExecutionView {
|
|
158
|
+
/** 读取当前视图中的 plugin/action metadata。 */
|
|
159
|
+
read(params: {
|
|
160
|
+
/** Plugin 名称(可选)。 */
|
|
161
|
+
plugin?: string;
|
|
162
|
+
/** Action 名称(可选)。 */
|
|
163
|
+
action?: string;
|
|
164
|
+
}): PluginReadView | { plugins: PluginView[] };
|
|
165
|
+
|
|
166
|
+
/** 运行当前视图中捕获的 plugin action。 */
|
|
167
|
+
runAction(params: {
|
|
168
|
+
/** Plugin 名称。 */
|
|
169
|
+
plugin: string;
|
|
170
|
+
/** Action 名称。 */
|
|
171
|
+
action: string;
|
|
172
|
+
/** Action Payload(可选)。 */
|
|
173
|
+
payload?: JsonValue;
|
|
174
|
+
}): Promise<PluginActionResult<JsonValue>>;
|
|
175
|
+
|
|
176
|
+
/** 解析当前视图中捕获的 plugin system blocks。 */
|
|
177
|
+
systemBlocks(): Promise<AgentSessionSystemBlock[]>;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
/**
|
|
181
|
+
* 单次 Session step 持有的 Plugin 执行 lease。
|
|
182
|
+
*/
|
|
183
|
+
export interface AgentPluginExecutionLease extends AgentPluginExecutionView {
|
|
184
|
+
/**
|
|
185
|
+
* 释放当前 step 对捕获 Plugin lifecycle 的占用。
|
|
186
|
+
*
|
|
187
|
+
* 关键点(中文)
|
|
188
|
+
* - 必须幂等,重复释放不会重复停止 lifecycle。
|
|
189
|
+
* - 若 Plugin 已从 configured registry 移除,最后一个 lease 释放时完成延迟 stop。
|
|
190
|
+
*/
|
|
191
|
+
release(): Promise<void>;
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
/**
|
|
195
|
+
* Session effective 配置持有的 Plugin 执行 runtime。
|
|
196
|
+
*/
|
|
197
|
+
export interface AgentPluginExecutionRuntime extends AgentPluginExecutionView {
|
|
198
|
+
/**
|
|
199
|
+
* 为当前 Session step 获取独立的 Plugin 执行 lease。
|
|
200
|
+
*
|
|
201
|
+
* 关键点(中文)
|
|
202
|
+
* - lease 只捕获创建 runtime 时存在的 Plugin records。
|
|
203
|
+
* - 已退休或 lifecycle 未就绪的 Plugin 不会进入新 lease。
|
|
204
|
+
*/
|
|
205
|
+
acquire(): AgentPluginExecutionLease;
|
|
145
206
|
}
|
|
146
207
|
|
|
147
208
|
/**
|
|
@@ -32,6 +32,16 @@ export interface PluginRuntimeRecord {
|
|
|
32
32
|
chain: Promise<void>;
|
|
33
33
|
/** lifecycle.start 是否已经执行成功。 */
|
|
34
34
|
lifecycle_started: boolean;
|
|
35
|
+
/** 当前正在使用该 Plugin 的 Session step lease 数量。 */
|
|
36
|
+
active_execution_leases: number;
|
|
37
|
+
/** 当前 Plugin 是否已从 configured registry 移除并等待释放。 */
|
|
38
|
+
retired: boolean;
|
|
39
|
+
/** 当前 Plugin 的延迟 lifecycle.stop 是否已经开始。 */
|
|
40
|
+
retirement_started: boolean;
|
|
41
|
+
/** 当前 Plugin 完成延迟 lifecycle.stop 后兑现的 Promise。 */
|
|
42
|
+
retirement_promise?: Promise<void>;
|
|
43
|
+
/** 兑现当前 Plugin retirement Promise 的内部回调。 */
|
|
44
|
+
resolve_retirement?: () => void;
|
|
35
45
|
}
|
|
36
46
|
|
|
37
47
|
/**
|
|
@@ -126,6 +126,17 @@ export type RpcRequest =
|
|
|
126
126
|
sessionId: string;
|
|
127
127
|
};
|
|
128
128
|
}
|
|
129
|
+
| {
|
|
130
|
+
/** 请求 id,用于匹配响应。 */
|
|
131
|
+
id: string;
|
|
132
|
+
/** 把显式历史压缩加入 Session 的有序输入队列。 */
|
|
133
|
+
method: "sdk.sessions.compact";
|
|
134
|
+
/** 目标 Session 参数。 */
|
|
135
|
+
params: {
|
|
136
|
+
/** 目标 session id。 */
|
|
137
|
+
sessionId: string;
|
|
138
|
+
};
|
|
139
|
+
}
|
|
129
140
|
| {
|
|
130
141
|
/** 请求 id,用于匹配响应。 */
|
|
131
142
|
id: string;
|
|
@@ -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 step 内优先读取队列已经提交的 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
|
+
* - Session step 内优先返回统一输入队列已经提交的 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
|
*
|
|
@@ -18,6 +18,15 @@ export interface SessionLocalState {
|
|
|
18
18
|
*/
|
|
19
19
|
sessionConfig: AgentSessionConfigSnapshot;
|
|
20
20
|
|
|
21
|
+
/**
|
|
22
|
+
* 当前 Session step 实际使用的 Session 配置。
|
|
23
|
+
*
|
|
24
|
+
* 关键点(中文)
|
|
25
|
+
* - `sessionConfig` 是配置 API 最近一次成功写入的 configured state。
|
|
26
|
+
* - 该字段只在 Session step 检查点由队列 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 { AgentSessionCommand } from "@/types/session/SessionQueueCommand.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 command 加入当前 Session 的统一输入队列。
|
|
48
|
+
*/
|
|
49
|
+
enqueue_agent_command(
|
|
50
|
+
command: AgentSessionCommand,
|
|
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 command 在 step 检查点执行。
|
|
94
|
+
*/
|
|
95
|
+
getAgentEnv: () => Record<string, string>;
|
|
96
|
+
|
|
97
|
+
/** 创建当前 Agent configured plugin 的 Session step 执行视图。 */
|
|
98
|
+
get_agent_plugins: () => AgentPluginExecutionRuntime;
|
|
99
|
+
|
|
79
100
|
/**
|
|
80
101
|
* 读取当前 agent 显式注入的受托管 plugin system blocks。
|
|
81
102
|
*/
|
|
@@ -0,0 +1,78 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Session queue command 运行时类型。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 配置 API 负责把 configured state 修改成功后创建 command。
|
|
6
|
+
* - command 与 steer 共用 Session 输入队列,并在下一次 Session step 检查点执行。
|
|
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
|
+
* Session queue command 的归属作用域。
|
|
15
|
+
*/
|
|
16
|
+
export type SessionQueueCommandScope = "agent" | "session";
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* Session queue command 执行时的 step 上下文。
|
|
20
|
+
*/
|
|
21
|
+
export interface SessionQueueCommandContext {
|
|
22
|
+
/** 当前公开 Session turn 标识。 */
|
|
23
|
+
turn_id: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* 等待在 Session step 检查点执行的 command。
|
|
28
|
+
*/
|
|
29
|
+
export interface SessionQueueCommand {
|
|
30
|
+
/** 当前队列项固定为 command。 */
|
|
31
|
+
type: "command";
|
|
32
|
+
|
|
33
|
+
/** 当前 command 的稳定唯一标识。 */
|
|
34
|
+
command_id: string;
|
|
35
|
+
|
|
36
|
+
/** 当前配置修改属于 Agent 还是 Session。 */
|
|
37
|
+
scope: SessionQueueCommandScope;
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* 把 configured state 提交为当前 Session 的 effective state。
|
|
41
|
+
*
|
|
42
|
+
* 关键点(中文)
|
|
43
|
+
* - effective state 提交失败时可以抛错,但不能让后续 command 静默丢失。
|
|
44
|
+
* - action message 是提交后的观测记录,写入失败不能回滚已经生效的配置。
|
|
45
|
+
*/
|
|
46
|
+
execute(context: SessionQueueCommandContext): Promise<void>;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* Agent configured state 广播给已有 Session 的 command。
|
|
51
|
+
*/
|
|
52
|
+
export type AgentSessionCommand =
|
|
53
|
+
| {
|
|
54
|
+
/** 当前修改固定为 instruction。 */
|
|
55
|
+
type: "instruction";
|
|
56
|
+
/** 当前 command 唯一标识。 */
|
|
57
|
+
command_id: string;
|
|
58
|
+
/** 下一 Session step 使用的 instruction blocks。 */
|
|
59
|
+
instruction_blocks: AgentSessionSystemBlock[];
|
|
60
|
+
}
|
|
61
|
+
| {
|
|
62
|
+
/** 当前修改固定为 env。 */
|
|
63
|
+
type: "env";
|
|
64
|
+
/** 当前 command 唯一标识。 */
|
|
65
|
+
command_id: string;
|
|
66
|
+
/** 下一 Session step 使用的完整 Agent env。 */
|
|
67
|
+
env: Record<string, string>;
|
|
68
|
+
}
|
|
69
|
+
| {
|
|
70
|
+
/** 当前修改固定为 plugin registry。 */
|
|
71
|
+
type: "plugins";
|
|
72
|
+
/** 当前 command 唯一标识。 */
|
|
73
|
+
command_id: string;
|
|
74
|
+
/** 当前 plugin 配置修改的用户可读标题。 */
|
|
75
|
+
title: string;
|
|
76
|
+
/** 下一 Session step 使用的 Plugin 执行视图。 */
|
|
77
|
+
plugins: AgentPluginExecutionRuntime;
|
|
78
|
+
};
|