@downcity/agent 1.1.129 → 1.1.148
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/README.md +2 -2
- package/bin/agent/local/Agent.d.ts +40 -26
- package/bin/agent/local/Agent.d.ts.map +1 -1
- package/bin/agent/local/Agent.js +65 -41
- package/bin/agent/local/Agent.js.map +1 -1
- package/bin/agent/local/ProjectSetup.js +2 -2
- package/bin/agent/local/ProjectSetup.js.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.d.ts +2 -7
- package/bin/agent/local/services/AgentAssemblyService.d.ts.map +1 -1
- package/bin/agent/local/services/AgentAssemblyService.js +34 -22
- package/bin/agent/local/services/AgentAssemblyService.js.map +1 -1
- package/bin/agent/local/services/AgentBackgroundService.d.ts +55 -0
- package/bin/agent/local/services/AgentBackgroundService.d.ts.map +1 -0
- package/bin/agent/local/services/AgentBackgroundService.js +86 -0
- package/bin/agent/local/services/AgentBackgroundService.js.map +1 -0
- package/bin/agent/local/services/AgentSessionManager.d.ts +16 -7
- package/bin/agent/local/services/AgentSessionManager.d.ts.map +1 -1
- package/bin/agent/local/services/AgentSessionManager.js +83 -8
- package/bin/agent/local/services/AgentSessionManager.js.map +1 -1
- package/bin/agent/remote/RemoteAgent.d.ts +9 -13
- package/bin/agent/remote/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/remote/RemoteAgent.js +23 -24
- package/bin/agent/remote/RemoteAgent.js.map +1 -1
- package/bin/agent/remote/RemoteSession.d.ts +11 -4
- package/bin/agent/remote/RemoteSession.d.ts.map +1 -1
- package/bin/agent/remote/RemoteSession.js +15 -3
- package/bin/agent/remote/RemoteSession.js.map +1 -1
- package/bin/agent/remote/RemoteTransport.d.ts +9 -1
- package/bin/agent/remote/RemoteTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts +7 -3
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js +65 -2
- package/bin/agent/remote/transports/HttpRemoteAgentTransport.js.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts +5 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.d.ts.map +1 -1
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js +12 -0
- package/bin/agent/remote/transports/RpcRemoteAgentTransport.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +2 -2
- package/bin/config/AgentInitializer.js +2 -2
- package/bin/executor/Executor.d.ts +5 -0
- package/bin/executor/Executor.d.ts.map +1 -1
- package/bin/executor/Executor.js +34 -0
- package/bin/executor/Executor.js.map +1 -1
- package/bin/executor/composer/system/default/InitPrompts.d.ts +1 -1
- package/bin/executor/composer/system/default/InitPrompts.js +1 -1
- package/bin/executor/composer/system/default/SystemDomain.js +2 -2
- package/bin/executor/composer/system/default/SystemDomain.js.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.d.ts.map +1 -1
- package/bin/executor/core-engine/CoreEngineRunner.js +16 -0
- package/bin/executor/core-engine/CoreEngineRunner.js.map +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.d.ts +1 -1
- package/bin/executor/messages/ChatMessageMarkupTypes.js +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts +8 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +22 -0
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/types/SessionExecutor.d.ts +8 -0
- package/bin/executor/types/SessionExecutor.d.ts.map +1 -1
- package/bin/index.d.ts +4 -4
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +1 -2
- package/bin/index.js.map +1 -1
- package/bin/plugin/core/Activation.d.ts +0 -2
- package/bin/plugin/core/Activation.d.ts.map +1 -1
- package/bin/plugin/core/Activation.js +1 -1
- package/bin/plugin/core/Activation.js.map +1 -1
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginStateController.d.ts +0 -5
- package/bin/plugin/core/PluginStateController.d.ts.map +1 -1
- package/bin/plugin/core/PluginStateController.js +1 -5
- package/bin/plugin/core/PluginStateController.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/plugin/types/PluginApi.js +1 -1
- package/bin/rpc/Client.d.ts +17 -1
- package/bin/rpc/Client.d.ts.map +1 -1
- package/bin/rpc/Client.js +47 -0
- package/bin/rpc/Client.js.map +1 -1
- package/bin/session/Session.d.ts +5 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +7 -0
- package/bin/session/Session.js.map +1 -1
- package/bin/session/browse/Browse.d.ts +9 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +81 -3
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +3 -3
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +3 -3
- package/bin/session/index.js.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.d.ts +13 -0
- package/bin/session/runtime/SessionPromptRuntime.d.ts.map +1 -1
- package/bin/session/runtime/SessionPromptRuntime.js +82 -5
- package/bin/session/runtime/SessionPromptRuntime.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 +10 -1
- package/bin/session/services/SessionTurnService.js.map +1 -1
- package/bin/session/services/SessionViewService.d.ts.map +1 -1
- package/bin/session/services/SessionViewService.js +1 -7
- package/bin/session/services/SessionViewService.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +15 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +15 -1
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +24 -0
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +34 -0
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.d.ts +5 -0
- package/bin/session/storage/RuntimeSessionPort.d.ts.map +1 -1
- package/bin/session/storage/RuntimeSessionPort.js +4 -0
- package/bin/session/storage/RuntimeSessionPort.js.map +1 -1
- package/bin/types/agent/AgentOptions.d.ts +0 -63
- package/bin/types/agent/AgentOptions.d.ts.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +3 -2
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/agent/SessionActor.d.ts +13 -4
- package/bin/types/agent/SessionActor.d.ts.map +1 -1
- package/bin/types/agent/SessionTypes.d.ts +62 -0
- package/bin/types/agent/SessionTypes.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +1 -1
- package/bin/types/executor/SessionRunContext.d.ts +8 -0
- package/bin/types/executor/SessionRunContext.d.ts.map +1 -1
- package/bin/types/platform/Store.d.ts +2 -2
- package/bin/types/platform/Store.js +2 -2
- package/bin/types/rpc/RpcProtocol.d.ts +37 -5
- package/bin/types/rpc/RpcProtocol.d.ts.map +1 -1
- package/bin/types/rpc/RpcProtocol.js +1 -1
- package/bin/types/runtime/agent/AgentContext.d.ts +92 -43
- package/bin/types/runtime/agent/AgentContext.d.ts.map +1 -1
- package/bin/types/runtime/agent/AgentContext.js +97 -5
- package/bin/types/runtime/agent/AgentContext.js.map +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +8 -8
- package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
- package/bin/types/sdk/AgentSessionStop.d.ts +36 -0
- package/bin/types/sdk/AgentSessionStop.d.ts.map +1 -0
- package/bin/types/sdk/AgentSessionStop.js +9 -0
- package/bin/types/sdk/AgentSessionStop.js.map +1 -0
- package/package.json +3 -3
- package/scripts/city-model-tool-loop.test.mjs +2 -2
- package/scripts/session-prompt-runtime.test.mjs +59 -0
- package/src/agent/local/Agent.ts +66 -55
- package/src/agent/local/ProjectSetup.ts +2 -2
- package/src/agent/local/services/AgentAssemblyService.ts +41 -35
- package/src/agent/local/services/AgentBackgroundService.ts +116 -0
- package/src/agent/local/services/AgentSessionManager.ts +127 -13
- package/src/agent/remote/RemoteAgent.ts +25 -34
- package/src/agent/remote/RemoteSession.ts +21 -6
- package/src/agent/remote/RemoteTransport.ts +14 -0
- package/src/agent/remote/transports/HttpRemoteAgentTransport.ts +100 -2
- package/src/agent/remote/transports/RpcRemoteAgentTransport.ts +26 -0
- package/src/config/AgentInitializer.ts +2 -2
- package/src/executor/Executor.ts +33 -0
- package/src/executor/composer/system/default/InitPrompts.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +2 -2
- package/src/executor/core-engine/CoreEngineRunner.ts +21 -0
- package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +22 -0
- package/src/executor/types/SessionExecutor.ts +2 -1
- package/src/index.ts +8 -10
- package/src/plugin/core/Activation.ts +1 -3
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginStateController.ts +1 -10
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/rpc/Client.ts +61 -0
- package/src/session/Session.ts +9 -0
- package/src/session/browse/Browse.ts +103 -3
- package/src/session/index.ts +7 -0
- package/src/session/runtime/SessionPromptRuntime.ts +100 -5
- package/src/session/services/SessionTurnService.ts +13 -1
- package/src/session/services/SessionViewService.ts +1 -7
- package/src/session/storage/Metadata.ts +23 -1
- package/src/session/storage/Paths.ts +70 -0
- package/src/session/storage/RuntimeSessionPort.ts +9 -0
- package/src/types/agent/AgentOptions.ts +0 -69
- package/src/types/agent/AgentTypes.ts +6 -5
- package/src/types/agent/SessionActor.ts +21 -3
- package/src/types/agent/SessionTypes.ts +68 -0
- package/src/types/config/DowncityConfig.ts +1 -1
- package/src/types/executor/SessionRunContext.ts +9 -0
- package/src/types/platform/Store.ts +2 -2
- package/src/types/rpc/RpcProtocol.ts +46 -4
- package/src/types/runtime/agent/AgentContext.ts +132 -45
- package/src/types/runtime/platform/Platform.ts +8 -8
- package/src/types/runtime/platform/PlatformGateway.ts +2 -2
- package/src/types/sdk/AgentSessionStop.ts +39 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/agent/local/AgentRuntimeFactory.d.ts +0 -72
- package/bin/agent/local/AgentRuntimeFactory.d.ts.map +0 -1
- package/bin/agent/local/AgentRuntimeFactory.js +0 -73
- package/bin/agent/local/AgentRuntimeFactory.js.map +0 -1
- package/bin/agent/local/services/AgentLifecycleService.d.ts +0 -65
- package/bin/agent/local/services/AgentLifecycleService.d.ts.map +0 -1
- package/bin/agent/local/services/AgentLifecycleService.js +0 -140
- package/bin/agent/local/services/AgentLifecycleService.js.map +0 -1
- package/bin/rpc/Server.d.ts +0 -31
- package/bin/rpc/Server.d.ts.map +0 -1
- package/bin/rpc/Server.js +0 -106
- package/bin/rpc/Server.js.map +0 -1
- package/bin/rpc/server/InternalHandlers.d.ts +0 -21
- package/bin/rpc/server/InternalHandlers.d.ts.map +0 -1
- package/bin/rpc/server/InternalHandlers.js +0 -244
- package/bin/rpc/server/InternalHandlers.js.map +0 -1
- package/bin/rpc/server/RequestDispatcher.d.ts +0 -27
- package/bin/rpc/server/RequestDispatcher.d.ts.map +0 -1
- package/bin/rpc/server/RequestDispatcher.js +0 -38
- package/bin/rpc/server/RequestDispatcher.js.map +0 -1
- package/bin/rpc/server/SdkSessionHandlers.d.ts +0 -25
- package/bin/rpc/server/SdkSessionHandlers.d.ts.map +0 -1
- package/bin/rpc/server/SdkSessionHandlers.js +0 -86
- package/bin/rpc/server/SdkSessionHandlers.js.map +0 -1
- package/bin/rpc/server/ServerTypes.d.ts +0 -64
- package/bin/rpc/server/ServerTypes.d.ts.map +0 -1
- package/bin/rpc/server/ServerTypes.js +0 -9
- package/bin/rpc/server/ServerTypes.js.map +0 -1
- package/bin/types/runtime/agent/AgentRuntime.d.ts +0 -79
- package/bin/types/runtime/agent/AgentRuntime.d.ts.map +0 -1
- package/bin/types/runtime/agent/AgentRuntime.js +0 -13
- package/bin/types/runtime/agent/AgentRuntime.js.map +0 -1
- package/src/agent/local/AgentRuntimeFactory.ts +0 -152
- package/src/agent/local/services/AgentLifecycleService.ts +0 -198
- package/src/rpc/Server.ts +0 -143
- package/src/rpc/server/InternalHandlers.ts +0 -285
- package/src/rpc/server/RequestDispatcher.ts +0 -67
- package/src/rpc/server/SdkSessionHandlers.ts +0 -106
- package/src/rpc/server/ServerTypes.ts +0 -70
- package/src/types/runtime/agent/AgentRuntime.ts +0 -84
|
@@ -2,15 +2,14 @@
|
|
|
2
2
|
* AgentAssemblyService:本地 Agent 装配服务。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* - 统一装配 logger、config、env、
|
|
5
|
+
* - 统一装配 logger、config、env、context 与 plugin registry。
|
|
6
6
|
* - 该服务只负责一次性长期对象装配,不负责 session 缓存和生命周期启动。
|
|
7
7
|
* - session/lifecycle service 通过它暴露的长期对象协作,避免在 facade 中重复拼装。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { LanguageModel, Tool } from "ai";
|
|
11
11
|
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
12
|
-
import
|
|
13
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
12
|
+
import { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
14
13
|
import type { DowncityConfig } from "@/types/config/DowncityConfig.js";
|
|
15
14
|
import type { AgentPlugins } from "@/plugin/types/Plugin.js";
|
|
16
15
|
import type { AgentOptions } from "@/types/agent/AgentTypes.js";
|
|
@@ -25,9 +24,9 @@ import {
|
|
|
25
24
|
createAgentPluginRegistry,
|
|
26
25
|
} from "@/agent/local/AgentPluginFactory.js";
|
|
27
26
|
import {
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
} from "@/agent/local/
|
|
27
|
+
createAgentPathRuntime,
|
|
28
|
+
createAgentPluginConfigRuntime,
|
|
29
|
+
} from "@/agent/local/AgentRuntimeAssembly.js";
|
|
31
30
|
import {
|
|
32
31
|
plugin_tools,
|
|
33
32
|
setPluginToolRuntime,
|
|
@@ -114,11 +113,6 @@ export interface AgentAssemblyResult {
|
|
|
114
113
|
*/
|
|
115
114
|
plugins: AgentPlugins;
|
|
116
115
|
|
|
117
|
-
/**
|
|
118
|
-
* 当前 agent runtime。
|
|
119
|
-
*/
|
|
120
|
-
runtime: AgentRuntime;
|
|
121
|
-
|
|
122
116
|
/**
|
|
123
117
|
* 当前 agent context。
|
|
124
118
|
*/
|
|
@@ -165,46 +159,59 @@ export class AgentAssemblyService {
|
|
|
165
159
|
|
|
166
160
|
const logger = new Logger();
|
|
167
161
|
logger.bindProjectRoot(path);
|
|
162
|
+
// 关键点(中文)
|
|
163
|
+
// - 这里产出的 env 是 agent 全生命周期共享的 mutable 对象引用。
|
|
164
|
+
// - context / shell 都持有同一引用;后续 `agent.setEnv()` 会原地修改它。
|
|
168
165
|
const env = resolveAgentEnv(path, this.options.env);
|
|
169
166
|
const instruction = normalizeInstructionInput(this.options.instruction);
|
|
170
167
|
const config = this.load_config(id, path);
|
|
171
168
|
const plugin_instances = new Map<string, BasePlugin>();
|
|
172
169
|
|
|
173
|
-
const runtime = createAgentRuntime({
|
|
174
|
-
agent_id: id,
|
|
175
|
-
project_root: path,
|
|
176
|
-
logger,
|
|
177
|
-
config,
|
|
178
|
-
env,
|
|
179
|
-
systems: instruction,
|
|
180
|
-
plugin_instances,
|
|
181
|
-
get_session_port: this.get_session_port,
|
|
182
|
-
list_cached_sessions: this.list_cached_sessions,
|
|
183
|
-
});
|
|
184
|
-
|
|
185
170
|
this.register_plugins(plugin_instances, this.options.plugins || []);
|
|
186
171
|
|
|
187
|
-
|
|
172
|
+
// 关键点(中文)
|
|
173
|
+
// - plugin_registry 仍然延迟读取 agent_context(避免循环依赖)。
|
|
174
|
+
// - context 一构造完就赋值,registry 第一次读 get_context 时已经是非空。
|
|
175
|
+
let agent_context: AgentContext | undefined;
|
|
188
176
|
const plugin_registry = createAgentPluginRegistry({
|
|
189
177
|
plugins: [...plugin_instances.values()],
|
|
190
|
-
get_context: () =>
|
|
178
|
+
get_context: () => {
|
|
179
|
+
if (!agent_context) {
|
|
180
|
+
throw new Error("AgentContext is not assembled yet");
|
|
181
|
+
}
|
|
182
|
+
return agent_context;
|
|
183
|
+
},
|
|
191
184
|
});
|
|
192
185
|
const plugins = plugin_registry;
|
|
193
186
|
if (this.should_register_plugin_call_tool(plugin_instances)) {
|
|
194
187
|
tools.plugin_call = tools.plugin_call || plugin_tools.plugin_call;
|
|
195
188
|
}
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
189
|
+
const resolve_session_model = this.resolve_session_model;
|
|
190
|
+
const paths = createAgentPathRuntime(path, id);
|
|
191
|
+
const pluginConfig = createAgentPluginConfigRuntime(path);
|
|
192
|
+
agent_context = new AgentContext({
|
|
193
|
+
cwd: path,
|
|
194
|
+
rootPath: path,
|
|
199
195
|
logger,
|
|
200
196
|
config,
|
|
201
197
|
env,
|
|
202
198
|
systems: instruction,
|
|
203
|
-
|
|
199
|
+
paths,
|
|
200
|
+
pluginConfig,
|
|
201
|
+
pluginInstances: plugin_instances,
|
|
202
|
+
session: {
|
|
203
|
+
get: (session_id) => this.get_session_port(session_id),
|
|
204
|
+
listExecutingSessionIds: () =>
|
|
205
|
+
this.list_cached_sessions()
|
|
206
|
+
.filter((session) => session.isExecuting())
|
|
207
|
+
.map((session) => session.id),
|
|
208
|
+
getExecutingSessionCount: () =>
|
|
209
|
+
this.list_cached_sessions()
|
|
210
|
+
.filter((session) => session.isExecuting()).length,
|
|
211
|
+
resolveModel: async (session_id) =>
|
|
212
|
+
await resolve_session_model(session_id),
|
|
213
|
+
},
|
|
204
214
|
plugins,
|
|
205
|
-
get_session_port: this.get_session_port,
|
|
206
|
-
resolve_session_model: async (session_id) =>
|
|
207
|
-
await this.resolve_session_model(session_id),
|
|
208
215
|
});
|
|
209
216
|
const shell = this.options.shell;
|
|
210
217
|
if (shell) {
|
|
@@ -216,7 +223,7 @@ export class AgentAssemblyService {
|
|
|
216
223
|
emit_event: (event) => {
|
|
217
224
|
const session_id = String(event.session_id || "").trim();
|
|
218
225
|
if (!session_id) return;
|
|
219
|
-
|
|
226
|
+
agent_context!.session.get(session_id).publishEvent(event as unknown as AgentSessionEvent);
|
|
220
227
|
},
|
|
221
228
|
});
|
|
222
229
|
Object.assign(tools, shell.tools);
|
|
@@ -234,8 +241,7 @@ export class AgentAssemblyService {
|
|
|
234
241
|
plugin_instances,
|
|
235
242
|
plugin_registry,
|
|
236
243
|
plugins,
|
|
237
|
-
|
|
238
|
-
agent_context,
|
|
244
|
+
agent_context: agent_context!,
|
|
239
245
|
...(shell ? { shell } : {}),
|
|
240
246
|
};
|
|
241
247
|
}
|
|
@@ -0,0 +1,116 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* AgentBackgroundService:本地 Agent 后台能力生命周期服务。
|
|
3
|
+
*
|
|
4
|
+
* 关键点(中文)
|
|
5
|
+
* - 统一管理 plugins 与 ActionSchedule 的启动 / 停止。
|
|
6
|
+
* - 在 Agent 构造阶段自动启动后台能力,调用方通过 `await agent.ready()` 等待启动完成。
|
|
7
|
+
* - RPC / HTTP 等 transport 不再属于 Agent 内部职责,由 `@downcity/server` 等外部包按需挂载。
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
11
|
+
import type { Logger } from "@/utils/logger/Logger.js";
|
|
12
|
+
import type { ActionScheduleRuntimeHandle } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
13
|
+
import { startActionScheduleRuntime } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
14
|
+
import { startAllPlugins, stopAllPlugins } from "@/plugin/core/Manager.js";
|
|
15
|
+
import type { Shell } from "@downcity/shell";
|
|
16
|
+
|
|
17
|
+
type AgentBackgroundServiceOptions = {
|
|
18
|
+
/**
|
|
19
|
+
* 当前统一日志器。
|
|
20
|
+
*/
|
|
21
|
+
logger: Logger;
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* 当前 agent context。
|
|
25
|
+
*/
|
|
26
|
+
agent_context: AgentContext;
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* 读取当前 agent 挂载的 Shell。
|
|
30
|
+
*/
|
|
31
|
+
get_shell?: () => Shell | undefined;
|
|
32
|
+
};
|
|
33
|
+
|
|
34
|
+
/**
|
|
35
|
+
* 本地 Agent 后台能力生命周期服务。
|
|
36
|
+
*
|
|
37
|
+
* 关键点(中文)
|
|
38
|
+
* - 构造时自动触发 plugin lifecycle 与 ActionSchedule 启动。
|
|
39
|
+
* - 失败由 logger.error 记录,不抛错;调用方通过 `ready()` 等待启动完成。
|
|
40
|
+
*/
|
|
41
|
+
export class AgentBackgroundService {
|
|
42
|
+
private readonly logger: Logger;
|
|
43
|
+
private readonly agent_context: AgentContext;
|
|
44
|
+
private readonly get_shell: AgentBackgroundServiceOptions["get_shell"];
|
|
45
|
+
|
|
46
|
+
private plugins_started = false;
|
|
47
|
+
private action_schedule_runtime: ActionScheduleRuntimeHandle | null = null;
|
|
48
|
+
private ready_promise: Promise<void> | null = null;
|
|
49
|
+
|
|
50
|
+
constructor(options: AgentBackgroundServiceOptions) {
|
|
51
|
+
this.logger = options.logger;
|
|
52
|
+
this.agent_context = options.agent_context;
|
|
53
|
+
this.get_shell = options.get_shell;
|
|
54
|
+
// 关键点(中文):Agent 构造完成即触发后台启动,不再要求外部显式 `start()`。
|
|
55
|
+
this.ready_promise = this.boot();
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* 等待后台能力启动完成。
|
|
60
|
+
*/
|
|
61
|
+
async ready(): Promise<void> {
|
|
62
|
+
if (!this.ready_promise) return;
|
|
63
|
+
await this.ready_promise;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/**
|
|
67
|
+
* 释放当前 Agent 的后台能力。
|
|
68
|
+
*/
|
|
69
|
+
async dispose(): Promise<void> {
|
|
70
|
+
if (this.ready_promise) {
|
|
71
|
+
await this.ready_promise.catch(() => undefined);
|
|
72
|
+
this.ready_promise = null;
|
|
73
|
+
}
|
|
74
|
+
if (this.plugins_started) {
|
|
75
|
+
await this.stop_action_schedule_runtime();
|
|
76
|
+
await stopAllPlugins(this.agent_context);
|
|
77
|
+
this.plugins_started = false;
|
|
78
|
+
}
|
|
79
|
+
await this.get_shell?.()?.dispose();
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
private async boot(): Promise<void> {
|
|
83
|
+
await this.ensure_plugins_started();
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
private async ensure_plugins_started(): Promise<void> {
|
|
87
|
+
if (this.plugins_started) return;
|
|
88
|
+
const lifecycle = await startAllPlugins(this.agent_context);
|
|
89
|
+
this.plugins_started = true;
|
|
90
|
+
for (const item of lifecycle.results) {
|
|
91
|
+
if (!item.success) {
|
|
92
|
+
this.logger.error(
|
|
93
|
+
`Plugin start failed: ${item.plugin?.name || "unknown"} - ${item.error || "unknown error"}`,
|
|
94
|
+
);
|
|
95
|
+
}
|
|
96
|
+
}
|
|
97
|
+
await this.ensure_action_schedule_runtime_started();
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
private async ensure_action_schedule_runtime_started(): Promise<void> {
|
|
101
|
+
if (this.action_schedule_runtime) return;
|
|
102
|
+
try {
|
|
103
|
+
this.action_schedule_runtime = await startActionScheduleRuntime(
|
|
104
|
+
this.agent_context,
|
|
105
|
+
);
|
|
106
|
+
} catch (error) {
|
|
107
|
+
this.logger.error(`ActionSchedule start failed: ${String(error)}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
|
|
111
|
+
private async stop_action_schedule_runtime(): Promise<void> {
|
|
112
|
+
const runtime = this.action_schedule_runtime;
|
|
113
|
+
this.action_schedule_runtime = null;
|
|
114
|
+
runtime?.stop();
|
|
115
|
+
}
|
|
116
|
+
}
|
|
@@ -13,6 +13,11 @@ import type { Tool } from "ai";
|
|
|
13
13
|
import type { Logger } from "@/utils/logger/Logger.js";
|
|
14
14
|
import type {
|
|
15
15
|
AgentCreateSessionInput,
|
|
16
|
+
AgentArchiveSessionInput,
|
|
17
|
+
AgentArchiveSessionsInput,
|
|
18
|
+
AgentArchiveSessionResult,
|
|
19
|
+
AgentArchiveSessionsResult,
|
|
20
|
+
AgentCleanArchiveResult,
|
|
16
21
|
AgentListSessionsInput,
|
|
17
22
|
AgentManagedSession,
|
|
18
23
|
AgentModel,
|
|
@@ -24,16 +29,26 @@ import type {
|
|
|
24
29
|
} from "@/types/agent/AgentTypes.js";
|
|
25
30
|
import { Session } from "@/session/Session.js";
|
|
26
31
|
import {
|
|
32
|
+
getSdkAgentArchivedSessionDirPath,
|
|
33
|
+
getSdkAgentArchivedSessionsDirPath,
|
|
27
34
|
getSdkAgentSessionDirPath,
|
|
35
|
+
listArchivedAgentSessionSummaryPage,
|
|
28
36
|
listAgentSessionSummaryPage,
|
|
29
37
|
} from "@/session/index.js";
|
|
30
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
31
38
|
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
32
39
|
import type { SessionPort } from "@/types/runtime/agent/AgentContext.js";
|
|
33
40
|
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
34
41
|
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
35
42
|
import { createInstructionSystemBlocks } from "@/agent/local/AgentInstructions.js";
|
|
36
43
|
|
|
44
|
+
function decodeMaybe(input: string): string {
|
|
45
|
+
try {
|
|
46
|
+
return decodeURIComponent(input);
|
|
47
|
+
} catch {
|
|
48
|
+
return input;
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
37
52
|
type AgentSessionManagerOptions = {
|
|
38
53
|
/**
|
|
39
54
|
* 当前 agent 稳定标识。
|
|
@@ -55,13 +70,11 @@ type AgentSessionManagerOptions = {
|
|
|
55
70
|
*/
|
|
56
71
|
logger: Logger;
|
|
57
72
|
|
|
58
|
-
/**
|
|
59
|
-
* 当前 agent runtime。
|
|
60
|
-
*/
|
|
61
|
-
runtime: AgentRuntime;
|
|
62
|
-
|
|
63
73
|
/**
|
|
64
74
|
* 延迟读取当前 agent context。
|
|
75
|
+
*
|
|
76
|
+
* 关键点(中文)
|
|
77
|
+
* - 装配期通过 getter 拿到 context,避免循环引用。
|
|
65
78
|
*/
|
|
66
79
|
get_agent_context: () => AgentContext;
|
|
67
80
|
|
|
@@ -94,7 +107,6 @@ export class AgentSessionManager {
|
|
|
94
107
|
private readonly project_root: string;
|
|
95
108
|
private readonly tools: Record<string, Tool>;
|
|
96
109
|
private readonly logger: Logger;
|
|
97
|
-
private readonly runtime: AgentRuntime;
|
|
98
110
|
private readonly get_agent_context: AgentSessionManagerOptions["get_agent_context"];
|
|
99
111
|
private readonly get_instruction: AgentSessionManagerOptions["get_instruction"];
|
|
100
112
|
private readonly plugin_instances: Map<string, BasePlugin>;
|
|
@@ -109,16 +121,18 @@ export class AgentSessionManager {
|
|
|
109
121
|
this.project_root = options.project_root;
|
|
110
122
|
this.tools = options.tools;
|
|
111
123
|
this.logger = options.logger;
|
|
112
|
-
this.runtime = options.runtime;
|
|
113
124
|
this.get_agent_context = options.get_agent_context;
|
|
114
125
|
this.get_instruction = options.get_instruction;
|
|
115
126
|
this.plugin_instances = options.plugin_instances;
|
|
116
127
|
this.default_model = options.default_model;
|
|
117
128
|
this.SessionClass = options.SessionClass || Session;
|
|
118
129
|
this.session_collection = {
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
130
|
+
create_session: async (input) => await this.create_session(input),
|
|
131
|
+
get_session: async (session_id) => await this.get_session(session_id),
|
|
132
|
+
list_sessions: async (input) => await this.list_sessions(input),
|
|
133
|
+
archive_session: async (input) => await this.archive_session(input),
|
|
134
|
+
archive_sessions: async (input) => await this.archive_sessions(input),
|
|
135
|
+
clean_archive: async () => await this.clean_archive(),
|
|
122
136
|
};
|
|
123
137
|
}
|
|
124
138
|
|
|
@@ -180,7 +194,7 @@ export class AgentSessionManager {
|
|
|
180
194
|
async get_session(session_id: string): Promise<AgentSession> {
|
|
181
195
|
const resolved_session_id = String(session_id || "").trim();
|
|
182
196
|
if (!resolved_session_id) {
|
|
183
|
-
throw new Error("
|
|
197
|
+
throw new Error("get_session requires a non-empty sessionId");
|
|
184
198
|
}
|
|
185
199
|
const session_dir_path = getSdkAgentSessionDirPath(
|
|
186
200
|
this.project_root,
|
|
@@ -211,10 +225,110 @@ export class AgentSessionManager {
|
|
|
211
225
|
projectRoot: this.project_root,
|
|
212
226
|
agentId: this.agent_id,
|
|
213
227
|
input,
|
|
214
|
-
executingSessionIds: new Set(this.
|
|
228
|
+
executingSessionIds: new Set(this.get_agent_context().listExecutingSessionIds()),
|
|
215
229
|
});
|
|
216
230
|
}
|
|
217
231
|
|
|
232
|
+
/**
|
|
233
|
+
* 归档单个 session。
|
|
234
|
+
*/
|
|
235
|
+
async archive_session(
|
|
236
|
+
input: AgentArchiveSessionInput,
|
|
237
|
+
): Promise<AgentArchiveSessionResult> {
|
|
238
|
+
const session_id = String(input?.id || "").trim();
|
|
239
|
+
if (!session_id) {
|
|
240
|
+
throw new Error("archive_session requires a non-empty id");
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
const executing_session_ids = new Set(
|
|
244
|
+
this.get_agent_context().listExecutingSessionIds(),
|
|
245
|
+
);
|
|
246
|
+
if (executing_session_ids.has(session_id)) {
|
|
247
|
+
throw new Error(`Session "${session_id}" is currently executing`);
|
|
248
|
+
}
|
|
249
|
+
|
|
250
|
+
const source_path = getSdkAgentSessionDirPath(
|
|
251
|
+
this.project_root,
|
|
252
|
+
this.agent_id,
|
|
253
|
+
session_id,
|
|
254
|
+
);
|
|
255
|
+
if (!(await fs.pathExists(source_path))) {
|
|
256
|
+
throw new Error(`Session "${session_id}" not found`);
|
|
257
|
+
}
|
|
258
|
+
|
|
259
|
+
const target_path = getSdkAgentArchivedSessionDirPath(
|
|
260
|
+
this.project_root,
|
|
261
|
+
this.agent_id,
|
|
262
|
+
session_id,
|
|
263
|
+
);
|
|
264
|
+
if (await fs.pathExists(target_path)) {
|
|
265
|
+
throw new Error(`Archived session "${session_id}" already exists`);
|
|
266
|
+
}
|
|
267
|
+
|
|
268
|
+
await fs.ensureDir(getSdkAgentArchivedSessionsDirPath(
|
|
269
|
+
this.project_root,
|
|
270
|
+
this.agent_id,
|
|
271
|
+
));
|
|
272
|
+
await fs.move(source_path, target_path);
|
|
273
|
+
|
|
274
|
+
// 关键点(中文):归档后清理缓存,避免后续操作访问已移动目录。
|
|
275
|
+
this.sessions_by_id.delete(session_id);
|
|
276
|
+
this.configured_session_ids.delete(session_id);
|
|
277
|
+
|
|
278
|
+
return {
|
|
279
|
+
sessionId: session_id,
|
|
280
|
+
archivedAt: Date.now(),
|
|
281
|
+
};
|
|
282
|
+
}
|
|
283
|
+
|
|
284
|
+
/**
|
|
285
|
+
* 列出当前 agent 的已归档 session 摘要页。
|
|
286
|
+
*/
|
|
287
|
+
async archive_sessions(
|
|
288
|
+
input?: AgentArchiveSessionsInput,
|
|
289
|
+
): Promise<AgentArchiveSessionsResult> {
|
|
290
|
+
return await listArchivedAgentSessionSummaryPage({
|
|
291
|
+
projectRoot: this.project_root,
|
|
292
|
+
agentId: this.agent_id,
|
|
293
|
+
input,
|
|
294
|
+
});
|
|
295
|
+
}
|
|
296
|
+
|
|
297
|
+
/**
|
|
298
|
+
* 永久清空已归档 session。
|
|
299
|
+
*/
|
|
300
|
+
async clean_archive(): Promise<AgentCleanArchiveResult> {
|
|
301
|
+
const archived_root = getSdkAgentArchivedSessionsDirPath(
|
|
302
|
+
this.project_root,
|
|
303
|
+
this.agent_id,
|
|
304
|
+
);
|
|
305
|
+
if (!(await fs.pathExists(archived_root))) {
|
|
306
|
+
return {
|
|
307
|
+
removedSessionIds: [],
|
|
308
|
+
};
|
|
309
|
+
}
|
|
310
|
+
|
|
311
|
+
const entries = await fs.readdir(archived_root, { withFileTypes: true });
|
|
312
|
+
const removed_session_ids: string[] = [];
|
|
313
|
+
|
|
314
|
+
for (const entry of entries) {
|
|
315
|
+
if (!entry.isDirectory()) continue;
|
|
316
|
+
const session_id = decodeMaybe(entry.name);
|
|
317
|
+
if (!session_id) continue;
|
|
318
|
+
const session_path = getSdkAgentArchivedSessionDirPath(
|
|
319
|
+
this.project_root,
|
|
320
|
+
this.agent_id,
|
|
321
|
+
session_id,
|
|
322
|
+
);
|
|
323
|
+
await fs.remove(session_path);
|
|
324
|
+
removed_session_ids.push(session_id);
|
|
325
|
+
}
|
|
326
|
+
|
|
327
|
+
return {
|
|
328
|
+
removedSessionIds: removed_session_ids,
|
|
329
|
+
};
|
|
330
|
+
}
|
|
331
|
+
|
|
218
332
|
private get_or_create_session(input?: {
|
|
219
333
|
/**
|
|
220
334
|
* 可选指定 session id。
|
|
@@ -8,9 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type {
|
|
11
|
-
|
|
12
|
-
AgentListSessionsInput,
|
|
13
|
-
AgentSessionSummaryPage,
|
|
11
|
+
AgentSessionCollection,
|
|
14
12
|
RemoteAgentPluginActionInput,
|
|
15
13
|
RemoteAgentPluginActionResult,
|
|
16
14
|
RemoteAgentOptions,
|
|
@@ -42,37 +40,6 @@ export class RemoteAgent {
|
|
|
42
40
|
this.transport = create_remote_agent_transport(url, options.token);
|
|
43
41
|
}
|
|
44
42
|
|
|
45
|
-
/**
|
|
46
|
-
* 新建一个远程 session。
|
|
47
|
-
*/
|
|
48
|
-
async createSession(
|
|
49
|
-
input?: AgentCreateSessionInput,
|
|
50
|
-
): Promise<RemoteAgentSession> {
|
|
51
|
-
const info = await this.transport.create_session(input);
|
|
52
|
-
return new RemoteSession(this.transport, info.sessionId);
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 获取一个已存在的远程 session。
|
|
57
|
-
*/
|
|
58
|
-
async getSession(sessionId: string): Promise<RemoteAgentSession> {
|
|
59
|
-
const resolved_session_id = String(sessionId || "").trim();
|
|
60
|
-
if (!resolved_session_id) {
|
|
61
|
-
throw new Error("getSession requires a non-empty sessionId");
|
|
62
|
-
}
|
|
63
|
-
const info = await this.transport.get_info(resolved_session_id);
|
|
64
|
-
return new RemoteSession(this.transport, info.sessionId);
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
/**
|
|
68
|
-
* 列出远程 agent 的 session 摘要页。
|
|
69
|
-
*/
|
|
70
|
-
async listSessions(
|
|
71
|
-
input?: AgentListSessionsInput,
|
|
72
|
-
): Promise<AgentSessionSummaryPage> {
|
|
73
|
-
return await this.transport.list_sessions(input);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
43
|
/**
|
|
77
44
|
* 执行远程 Agent runtime 内的 plugin action。
|
|
78
45
|
*
|
|
@@ -153,4 +120,28 @@ export class RemoteAgent {
|
|
|
153
120
|
async close(): Promise<void> {
|
|
154
121
|
await this.transport.close?.();
|
|
155
122
|
}
|
|
123
|
+
|
|
124
|
+
/**
|
|
125
|
+
* 返回当前远程 session collection 入口。
|
|
126
|
+
*
|
|
127
|
+
* 关键点(中文)
|
|
128
|
+
* - `RemoteAgentTransport` 只负责协议传输,不直接等价于 `AgentSessionCollection`。
|
|
129
|
+
* - 这里把 transport 包装为 `AgentSessionCollection`,`create_session` / `get_session` 返回 `RemoteSession` 实例。
|
|
130
|
+
*/
|
|
131
|
+
session_collection(): AgentSessionCollection {
|
|
132
|
+
return {
|
|
133
|
+
create_session: async (input) => {
|
|
134
|
+
const info = await this.transport.create_session(input);
|
|
135
|
+
return new RemoteSession(this.transport, info);
|
|
136
|
+
},
|
|
137
|
+
get_session: async (session_id) => {
|
|
138
|
+
const info = await this.transport.get_info(session_id);
|
|
139
|
+
return new RemoteSession(this.transport, info);
|
|
140
|
+
},
|
|
141
|
+
list_sessions: async (input) => await this.transport.list_sessions(input),
|
|
142
|
+
archive_session: async (input) => await this.transport.archive_session(input),
|
|
143
|
+
archive_sessions: async (input) => await this.transport.archive_sessions(input),
|
|
144
|
+
clean_archive: async () => await this.transport.clean_archive(),
|
|
145
|
+
};
|
|
146
|
+
}
|
|
156
147
|
}
|
|
@@ -7,14 +7,16 @@
|
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import type {
|
|
10
|
+
AgentSession,
|
|
11
|
+
AgentSessionConfigSnapshot,
|
|
10
12
|
AgentSessionForkInput,
|
|
11
13
|
AgentSessionHistoryInput,
|
|
12
14
|
AgentSessionHistoryPage,
|
|
13
15
|
AgentSessionInfo,
|
|
14
16
|
AgentSessionSetInput,
|
|
15
17
|
AgentSessionSystemSnapshot,
|
|
16
|
-
RemoteAgentSession,
|
|
17
18
|
} from "@/types/agent/AgentTypes.js";
|
|
19
|
+
import type { AgentSessionStopResult } from "@/types/sdk/AgentSessionStop.js";
|
|
18
20
|
import type {
|
|
19
21
|
AgentSessionEvent,
|
|
20
22
|
AgentSessionSubscriber,
|
|
@@ -50,8 +52,10 @@ type RemoteTurnLifecycle = {
|
|
|
50
52
|
/**
|
|
51
53
|
* 远程 Session 客户端。
|
|
52
54
|
*/
|
|
53
|
-
export class RemoteSession implements
|
|
55
|
+
export class RemoteSession implements AgentSession {
|
|
54
56
|
readonly id: string;
|
|
57
|
+
readonly agentId: string;
|
|
58
|
+
readonly config: AgentSessionConfigSnapshot;
|
|
55
59
|
|
|
56
60
|
private readonly transport: RemoteSessionTransport;
|
|
57
61
|
private readonly event_hub = new SessionEventHub();
|
|
@@ -62,9 +66,12 @@ export class RemoteSession implements RemoteAgentSession {
|
|
|
62
66
|
private event_subscriber_count = 0;
|
|
63
67
|
private event_subscription: TransportSubscription | null = null;
|
|
64
68
|
|
|
65
|
-
constructor(transport: RemoteSessionTransport,
|
|
69
|
+
constructor(transport: RemoteSessionTransport, info: AgentSessionInfo) {
|
|
66
70
|
this.transport = transport;
|
|
67
|
-
this.id =
|
|
71
|
+
this.id = info.sessionId;
|
|
72
|
+
this.agentId = info.agentId;
|
|
73
|
+
// 远程 session 不暴露服务端模型实例,config 返回空快照。
|
|
74
|
+
this.config = {} as AgentSessionConfigSnapshot;
|
|
68
75
|
}
|
|
69
76
|
|
|
70
77
|
/**
|
|
@@ -98,6 +105,14 @@ export class RemoteSession implements RemoteAgentSession {
|
|
|
98
105
|
return create_turn_handle(lifecycle);
|
|
99
106
|
}
|
|
100
107
|
|
|
108
|
+
/**
|
|
109
|
+
* 停止当前远程 session turn,并取消未吸收队列。
|
|
110
|
+
*/
|
|
111
|
+
async stop(): Promise<AgentSessionStopResult> {
|
|
112
|
+
await this.ensure_event_pump();
|
|
113
|
+
return await this.transport.stop(this.id);
|
|
114
|
+
}
|
|
115
|
+
|
|
101
116
|
/**
|
|
102
117
|
* 订阅当前远程 session 的 future 事件。
|
|
103
118
|
*/
|
|
@@ -134,9 +149,9 @@ export class RemoteSession implements RemoteAgentSession {
|
|
|
134
149
|
/**
|
|
135
150
|
* 分叉远程 session。
|
|
136
151
|
*/
|
|
137
|
-
async fork(input?: AgentSessionForkInput | string): Promise<
|
|
152
|
+
async fork(input?: AgentSessionForkInput | string): Promise<AgentSession> {
|
|
138
153
|
const info = await this.transport.fork(this.id, input);
|
|
139
|
-
return new RemoteSession(this.transport, info
|
|
154
|
+
return new RemoteSession(this.transport, info);
|
|
140
155
|
}
|
|
141
156
|
|
|
142
157
|
private async ensure_event_pump(): Promise<void> {
|
|
@@ -9,12 +9,18 @@
|
|
|
9
9
|
import type {
|
|
10
10
|
AgentCreateSessionInput,
|
|
11
11
|
AgentListSessionsInput,
|
|
12
|
+
AgentArchiveSessionInput,
|
|
13
|
+
AgentArchiveSessionsInput,
|
|
14
|
+
AgentArchiveSessionResult,
|
|
15
|
+
AgentArchiveSessionsResult,
|
|
16
|
+
AgentCleanArchiveResult,
|
|
12
17
|
AgentSessionForkInput,
|
|
13
18
|
AgentSessionHistoryInput,
|
|
14
19
|
AgentSessionHistoryPage,
|
|
15
20
|
AgentSessionInfo,
|
|
16
21
|
AgentSessionSummaryPage,
|
|
17
22
|
AgentSessionSystemSnapshot,
|
|
23
|
+
AgentSessionStopResult,
|
|
18
24
|
RemoteAgentPluginActionInput,
|
|
19
25
|
RemoteAgentPluginActionResult,
|
|
20
26
|
} from "@/types/agent/AgentTypes.js";
|
|
@@ -48,6 +54,8 @@ export type RemoteSessionTransport = {
|
|
|
48
54
|
session_id: string,
|
|
49
55
|
input: AgentSessionPromptInput,
|
|
50
56
|
): Promise<{ id: string }>;
|
|
57
|
+
/** 停止当前 session turn,并取消未吸收队列。 */
|
|
58
|
+
stop(session_id: string): Promise<AgentSessionStopResult>;
|
|
51
59
|
/** 订阅 session 事件。 */
|
|
52
60
|
subscribe(params: {
|
|
53
61
|
session_id: string;
|
|
@@ -76,6 +84,12 @@ export type RemoteAgentTransport = RemoteSessionTransport & {
|
|
|
76
84
|
create_session(input?: AgentCreateSessionInput): Promise<AgentSessionInfo>;
|
|
77
85
|
/** 列出 sessions。 */
|
|
78
86
|
list_sessions(input?: AgentListSessionsInput): Promise<AgentSessionSummaryPage>;
|
|
87
|
+
/** 归档 session。 */
|
|
88
|
+
archive_session(input: AgentArchiveSessionInput): Promise<AgentArchiveSessionResult>;
|
|
89
|
+
/** 列出已归档 sessions。 */
|
|
90
|
+
archive_sessions(input?: AgentArchiveSessionsInput): Promise<AgentArchiveSessionsResult>;
|
|
91
|
+
/** 清空归档 sessions。 */
|
|
92
|
+
clean_archive(): Promise<AgentCleanArchiveResult>;
|
|
79
93
|
/** 执行远程 Agent runtime 内的 plugin action。 */
|
|
80
94
|
run_plugin_action(
|
|
81
95
|
input: RemoteAgentPluginActionInput,
|