@downcity/agent 1.1.43 → 1.1.62
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 +11 -12
- package/bin/agent/Agent.d.ts +31 -16
- package/bin/agent/Agent.d.ts.map +1 -1
- package/bin/agent/Agent.js +47 -63
- package/bin/agent/Agent.js.map +1 -1
- package/bin/agent/RemoteAgent.d.ts +6 -6
- package/bin/agent/RemoteAgent.d.ts.map +1 -1
- package/bin/agent/RemoteAgent.js +377 -267
- package/bin/agent/RemoteAgent.js.map +1 -1
- package/bin/config/AgentInitializer.d.ts +5 -5
- package/bin/config/AgentInitializer.d.ts.map +1 -1
- package/bin/config/AgentInitializer.js +15 -13
- package/bin/config/AgentInitializer.js.map +1 -1
- package/bin/config/Config.d.ts +9 -30
- package/bin/config/Config.d.ts.map +1 -1
- package/bin/config/Config.js +23 -70
- package/bin/config/Config.js.map +1 -1
- package/bin/config/Defaults.d.ts.map +1 -1
- package/bin/config/Defaults.js +1 -9
- package/bin/config/Defaults.js.map +1 -1
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +4 -112
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/ExecutionBinding.d.ts +1 -16
- package/bin/config/ExecutionBinding.d.ts.map +1 -1
- package/bin/config/ExecutionBinding.js +2 -22
- package/bin/config/ExecutionBinding.js.map +1 -1
- package/bin/config/Paths.d.ts +4 -43
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +10 -30
- package/bin/config/Paths.js.map +1 -1
- package/bin/config/PlatformPaths.d.ts +0 -4
- package/bin/config/PlatformPaths.d.ts.map +1 -1
- package/bin/config/PlatformPaths.js +5 -1
- package/bin/config/PlatformPaths.js.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.d.ts.map +1 -1
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.js +0 -4
- package/bin/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.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 +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/core.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.d.ts.map +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js +1 -1
- package/bin/executor/composer/system/default/assets/init/PROFILE.md.js.map +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/plugin.prompt.js +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.d.ts +1 -1
- package/bin/executor/composer/system/default/assets/task.prompt.js +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 +1 -2
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.d.ts.map +1 -1
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js +17 -56
- package/bin/executor/store/history/jsonl/JsonlSessionHistoryStore.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js +1 -1
- package/bin/executor/tools/shell/ShellToolBridge.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolDefinition.d.ts +2 -2
- package/bin/executor/tools/shell/ShellToolFormatting.d.ts +1 -1
- package/bin/executor/tools/shell/ShellToolFormatting.js +9 -9
- package/bin/executor/tools/shell/ShellToolFormatting.js.map +1 -1
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts +7 -75
- package/bin/executor/tools/shell/ShellToolSchemas.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.d.ts +5 -24
- package/bin/executor/types/SessionHistoryMeta.d.ts.map +1 -1
- package/bin/executor/types/SessionHistoryMeta.js +1 -1
- package/bin/executor/types/SessionRun.d.ts +1 -1
- package/bin/index.d.ts +5 -6
- package/bin/index.d.ts.map +1 -1
- package/bin/index.js +6 -5
- package/bin/index.js.map +1 -1
- package/bin/model/CityModelAdapter.d.ts +23 -0
- package/bin/model/CityModelAdapter.d.ts.map +1 -0
- package/bin/model/CityModelAdapter.js +338 -0
- package/bin/model/CityModelAdapter.js.map +1 -0
- package/bin/plugin/core/PluginCommandRequest.d.ts +1 -1
- package/bin/plugin/core/PluginCommandRequest.js +1 -1
- package/bin/plugin/core/PluginLocalExecution.d.ts.map +1 -1
- package/bin/plugin/core/PluginLocalExecution.js +4 -8
- package/bin/plugin/core/PluginLocalExecution.js.map +1 -1
- package/bin/plugin/types/PluginApi.d.ts +1 -1
- package/bin/rpc/Client.d.ts +104 -0
- package/bin/rpc/Client.d.ts.map +1 -0
- package/bin/rpc/Client.js +300 -0
- package/bin/rpc/Client.js.map +1 -0
- package/bin/rpc/Server.d.ts +41 -0
- package/bin/rpc/Server.d.ts.map +1 -0
- package/bin/rpc/Server.js +164 -0
- package/bin/rpc/Server.js.map +1 -0
- package/bin/runtime/host/daemon/Api.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts +1 -1
- package/bin/runtime/host/daemon/Client.d.ts.map +1 -1
- package/bin/runtime/host/daemon/Client.js +30 -20
- package/bin/runtime/host/daemon/Client.js.map +1 -1
- package/bin/runtime/host/daemon/Paths.d.ts +1 -1
- package/bin/runtime/host/daemon/Paths.js +1 -1
- package/bin/runtime/host/daemon/ProjectSetup.js +2 -2
- package/bin/runtime/server/http/control/OverviewRoutes.js +1 -1
- package/bin/runtime/server/http/control/OverviewRoutes.js.map +1 -1
- package/bin/session/Session.d.ts +1 -0
- package/bin/session/Session.d.ts.map +1 -1
- package/bin/session/Session.js +32 -6
- package/bin/session/Session.js.map +1 -1
- package/bin/session/SessionTitle.d.ts +49 -0
- package/bin/session/SessionTitle.d.ts.map +1 -0
- package/bin/session/SessionTitle.js +130 -0
- package/bin/session/SessionTitle.js.map +1 -0
- package/bin/session/browse/Browse.d.ts +2 -1
- package/bin/session/browse/Browse.d.ts.map +1 -1
- package/bin/session/browse/Browse.js +18 -15
- package/bin/session/browse/Browse.js.map +1 -1
- package/bin/session/index.d.ts +3 -2
- package/bin/session/index.d.ts.map +1 -1
- package/bin/session/index.js +3 -2
- package/bin/session/index.js.map +1 -1
- package/bin/session/storage/Metadata.d.ts +4 -0
- package/bin/session/storage/Metadata.d.ts.map +1 -1
- package/bin/session/storage/Metadata.js +12 -25
- package/bin/session/storage/Metadata.js.map +1 -1
- package/bin/session/storage/Paths.d.ts +0 -4
- package/bin/session/storage/Paths.d.ts.map +1 -1
- package/bin/session/storage/Paths.js +0 -6
- package/bin/session/storage/Paths.js.map +1 -1
- package/bin/session/storage/Persistence.d.ts.map +1 -1
- package/bin/session/storage/Persistence.js +1 -4
- package/bin/session/storage/Persistence.js.map +1 -1
- package/bin/types/agent/AgentTypes.d.ts +32 -57
- package/bin/types/agent/AgentTypes.d.ts.map +1 -1
- package/bin/types/config/AgentProject.d.ts +7 -6
- package/bin/types/config/AgentProject.d.ts.map +1 -1
- package/bin/types/config/DowncityConfig.d.ts +11 -69
- package/bin/types/config/DowncityConfig.d.ts.map +1 -1
- package/bin/types/config/ExecutionBinding.d.ts +4 -4
- package/bin/types/config/ExecutionBinding.js +1 -1
- package/bin/types/config/LlmConfig.d.ts +1 -1
- package/bin/types/config/Start.d.ts +3 -0
- package/bin/types/config/Start.d.ts.map +1 -1
- package/bin/types/config/Start.js +2 -0
- package/bin/types/config/Start.js.map +1 -1
- package/bin/types/runtime/auth/AuthPermission.js +2 -2
- package/bin/types/runtime/auth/AuthPermission.js.map +1 -1
- package/bin/types/runtime/host/Store.d.ts +10 -227
- package/bin/types/runtime/host/Store.d.ts.map +1 -1
- package/bin/types/runtime/host/Store.js +7 -0
- package/bin/types/runtime/host/Store.js.map +1 -1
- package/bin/types/runtime/http/InlineInstant.d.ts +1 -1
- package/bin/types/runtime/platform/Platform.d.ts +7 -7
- package/bin/types/runtime/platform/Platform.d.ts.map +1 -1
- package/bin/types/runtime/platform/PlatformGateway.d.ts +2 -2
- package/bin/types/runtime/platform/PlatformGateway.d.ts.map +1 -1
- package/bin/utils/Time.d.ts +0 -1
- package/bin/utils/Time.d.ts.map +1 -1
- package/bin/utils/Time.js +0 -7
- package/bin/utils/Time.js.map +1 -1
- package/bin/utils/storage/index.d.ts +0 -1
- package/bin/utils/storage/index.d.ts.map +1 -1
- package/bin/utils/storage/index.js +0 -6
- package/bin/utils/storage/index.js.map +1 -1
- package/package.json +22 -23
- package/src/agent/Agent.ts +57 -73
- package/src/agent/RemoteAgent.ts +515 -345
- package/src/config/AgentInitializer.ts +15 -13
- package/src/config/Config.ts +28 -85
- package/src/config/Defaults.ts +1 -9
- package/src/config/DowncitySchema.ts +4 -114
- package/src/config/ExecutionBinding.ts +2 -24
- package/src/config/Paths.ts +10 -43
- package/src/config/PlatformPaths.ts +5 -1
- package/src/executor/composer/compaction/jsonl/JsonlSessionCompactionExecutor.ts +0 -4
- package/src/executor/composer/system/default/InitPrompts.ts +1 -1
- package/src/executor/composer/system/default/SystemDomain.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/core.prompt.ts.txt +1 -1
- package/src/executor/composer/system/default/assets/init/PROFILE.md.ts +1 -1
- package/src/executor/composer/system/default/assets/init/PROFILE.md.ts.txt +1 -2
- package/src/executor/composer/system/default/assets/plugin.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/plugin.prompt.ts.txt +18 -18
- package/src/executor/composer/system/default/assets/task.prompt.ts +1 -1
- package/src/executor/composer/system/default/assets/task.prompt.ts.txt +1 -1
- package/src/executor/messages/ChatMessageMarkupTypes.ts +1 -1
- package/src/executor/store/history/jsonl/JsonlSessionHistoryStore.ts +17 -57
- package/src/executor/tools/shell/ShellToolBridge.ts +1 -1
- package/src/executor/tools/shell/ShellToolFormatting.ts +9 -9
- package/src/executor/types/SessionHistoryMeta.ts +5 -25
- package/src/executor/types/SessionRun.ts +1 -1
- package/src/index.ts +12 -19
- package/src/model/CityModelAdapter.ts +384 -0
- package/src/plugin/core/PluginCommandRequest.ts +1 -1
- package/src/plugin/core/PluginLocalExecution.ts +4 -8
- package/src/plugin/types/PluginApi.ts +1 -1
- package/src/rpc/Client.ts +467 -0
- package/src/rpc/Server.ts +302 -0
- package/src/runtime/host/daemon/Api.ts +1 -1
- package/src/runtime/host/daemon/Client.ts +44 -22
- package/src/runtime/host/daemon/Paths.ts +1 -1
- package/src/runtime/host/daemon/ProjectSetup.ts +2 -2
- package/src/runtime/server/http/control/OverviewRoutes.ts +1 -1
- package/src/session/Session.ts +40 -6
- package/src/session/SessionTitle.ts +192 -0
- package/src/session/browse/Browse.ts +22 -13
- package/src/session/index.ts +5 -1
- package/src/session/storage/Metadata.ts +14 -29
- package/src/session/storage/Paths.ts +0 -10
- package/src/session/storage/Persistence.ts +1 -4
- package/src/types/agent/AgentTypes.ts +33 -62
- package/src/types/config/AgentProject.ts +7 -6
- package/src/types/config/DowncityConfig.ts +11 -70
- package/src/types/config/ExecutionBinding.ts +4 -4
- package/src/types/config/LlmConfig.ts +1 -1
- package/src/types/config/Start.ts +3 -0
- package/src/types/runtime/auth/AuthPermission.ts +2 -2
- package/src/types/runtime/host/Store.ts +10 -235
- package/src/types/runtime/http/InlineInstant.ts +1 -1
- package/src/types/runtime/platform/Platform.ts +7 -7
- package/src/types/runtime/platform/PlatformGateway.ts +2 -2
- package/src/utils/Time.ts +0 -6
- package/src/utils/storage/index.ts +0 -7
- package/tsconfig.json +1 -0
- package/tsconfig.tsbuildinfo +1 -1
- package/bin/config/ConfigEnvResolver.d.ts +0 -22
- package/bin/config/ConfigEnvResolver.d.ts.map +0 -1
- package/bin/config/ConfigEnvResolver.js +0 -41
- package/bin/config/ConfigEnvResolver.js.map +0 -1
- package/bin/runtime/server/rpc/Server.d.ts +0 -18
- package/bin/runtime/server/rpc/Server.d.ts.map +0 -1
- package/bin/runtime/server/rpc/Server.js +0 -315
- package/bin/runtime/server/rpc/Server.js.map +0 -1
- package/bin/runtime/transport/rpc/Client.d.ts +0 -13
- package/bin/runtime/transport/rpc/Client.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Client.js +0 -98
- package/bin/runtime/transport/rpc/Client.js.map +0 -1
- package/bin/runtime/transport/rpc/Paths.d.ts +0 -14
- package/bin/runtime/transport/rpc/Paths.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Paths.js +0 -42
- package/bin/runtime/transport/rpc/Paths.js.map +0 -1
- package/bin/runtime/transport/rpc/Transport.d.ts +0 -21
- package/bin/runtime/transport/rpc/Transport.d.ts.map +0 -1
- package/bin/runtime/transport/rpc/Transport.js +0 -30
- package/bin/runtime/transport/rpc/Transport.js.map +0 -1
- package/bin/types/common/ResolvedConfigValue.d.ts +0 -12
- package/bin/types/common/ResolvedConfigValue.d.ts.map +0 -1
- package/bin/types/common/ResolvedConfigValue.js +0 -2
- package/bin/types/common/ResolvedConfigValue.js.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.d.ts +0 -69
- package/bin/types/runtime/rpc/LocalRpc.d.ts.map +0 -1
- package/bin/types/runtime/rpc/LocalRpc.js +0 -9
- package/bin/types/runtime/rpc/LocalRpc.js.map +0 -1
- package/src/config/ConfigEnvResolver.ts +0 -52
- package/src/runtime/server/rpc/Server.ts +0 -408
- package/src/runtime/transport/rpc/Client.ts +0 -113
- package/src/runtime/transport/rpc/Paths.ts +0 -50
- package/src/runtime/transport/rpc/Transport.ts +0 -43
- package/src/types/common/ResolvedConfigValue.ts +0 -16
- package/src/types/runtime/rpc/LocalRpc.ts +0 -72
package/src/agent/Agent.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 职责说明(中文)
|
|
5
5
|
* - 对外暴露 `Agent` 这一唯一的本地实例类。
|
|
6
|
-
* - 统一承接单个 agent 实例的配置加载、plugin 装配、session 创建、
|
|
6
|
+
* - 统一承接单个 agent 实例的配置加载、plugin 装配、session 创建、RPC 启停。
|
|
7
7
|
* - 把原先独立的实例内核装配逻辑收敛到 `Agent` 内部,避免 facade 与 core 双层跳转。
|
|
8
8
|
*
|
|
9
9
|
* 边界说明(中文)
|
|
@@ -13,7 +13,7 @@
|
|
|
13
13
|
|
|
14
14
|
import fs from "fs-extra";
|
|
15
15
|
import { nanoid } from "nanoid";
|
|
16
|
-
import type {
|
|
16
|
+
import type { Tool } from "ai";
|
|
17
17
|
import type { BasePlugin } from "@/plugin/core/BasePlugin.js";
|
|
18
18
|
import type {
|
|
19
19
|
AgentContext,
|
|
@@ -35,13 +35,13 @@ import type {
|
|
|
35
35
|
AgentStartOptions,
|
|
36
36
|
AgentStartResult,
|
|
37
37
|
AgentStopResult,
|
|
38
|
-
AgentHttpBinding,
|
|
39
|
-
AgentHttpStartOptions,
|
|
40
38
|
AgentRpcBinding,
|
|
39
|
+
AgentRpcStartOptions,
|
|
41
40
|
AgentSessionCollection,
|
|
42
41
|
AgentSessionSummaryPage,
|
|
43
42
|
AgentSessionSystemBlock,
|
|
44
43
|
} from "@/types/agent/AgentTypes.js";
|
|
44
|
+
import type { AgentModel } from "@/model/CityModelAdapter.js";
|
|
45
45
|
import { Logger } from "@/utils/logger/Logger.js";
|
|
46
46
|
import { Session } from "@/session/Session.js";
|
|
47
47
|
import { DEFAULT_SHIP_PROMPTS } from "@executor/composer/system/default/SystemDomain.js";
|
|
@@ -53,7 +53,7 @@ import {
|
|
|
53
53
|
createAgentPathRuntime,
|
|
54
54
|
createAgentPluginConfigRuntime,
|
|
55
55
|
} from "@/runtime/host/AgentHostRuntime.js";
|
|
56
|
-
import { loadDowncityConfig } from "@/config/Config.js";
|
|
56
|
+
import { loadDowncityConfig, resolveAgentEnv } from "@/config/Config.js";
|
|
57
57
|
import { HookRegistry } from "@/plugin/core/HookRegistry.js";
|
|
58
58
|
import { PluginRegistry } from "@/plugin/core/PluginRegistry.js";
|
|
59
59
|
import { isPluginEnabled } from "@/plugin/core/Activation.js";
|
|
@@ -61,12 +61,11 @@ import { setShellToolRuntime } from "@executor/tools/shell/ShellToolDefinition.j
|
|
|
61
61
|
import { startAllPlugins, stopAllPlugins } from "@/plugin/core/Manager.js";
|
|
62
62
|
import type { ActionScheduleRuntimeHandle } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
63
63
|
import { startActionScheduleRuntime } from "@/plugin/core/ActionScheduleRuntime.js";
|
|
64
|
-
import {
|
|
65
|
-
import { startLocalRpcServer } from "@/runtime/server/rpc/Server.js";
|
|
64
|
+
import { startRpcServer } from "@/rpc/Server.js";
|
|
66
65
|
|
|
67
66
|
function createFallbackSdkConfig(agentId: string): DowncityConfig {
|
|
68
67
|
return {
|
|
69
|
-
|
|
68
|
+
id: agentId,
|
|
70
69
|
version: "0.0.0",
|
|
71
70
|
} as DowncityConfig;
|
|
72
71
|
}
|
|
@@ -126,7 +125,7 @@ export class Agent {
|
|
|
126
125
|
private readonly pluginRegistry: PluginRegistry;
|
|
127
126
|
private readonly config: DowncityConfig;
|
|
128
127
|
private readonly env: Record<string, string>;
|
|
129
|
-
private readonly defaultModel?:
|
|
128
|
+
private readonly defaultModel?: AgentModel;
|
|
130
129
|
private readonly pluginInstances: Map<string, BasePlugin>;
|
|
131
130
|
private readonly sessionCollection: AgentSessionCollection;
|
|
132
131
|
|
|
@@ -135,7 +134,6 @@ export class Agent {
|
|
|
135
134
|
private pluginsStarted = false;
|
|
136
135
|
private actionScheduleRuntime: ActionScheduleRuntimeHandle | null = null;
|
|
137
136
|
private startPromise: Promise<AgentStartResult> | null = null;
|
|
138
|
-
private httpBinding: AgentHttpBinding | null = null;
|
|
139
137
|
private rpcBinding: AgentRpcBinding | null = null;
|
|
140
138
|
|
|
141
139
|
constructor(options: AgentOptions) {
|
|
@@ -153,7 +151,7 @@ export class Agent {
|
|
|
153
151
|
|
|
154
152
|
this.logger = new Logger();
|
|
155
153
|
this.logger.bindProjectRoot(this.path);
|
|
156
|
-
this.env =
|
|
154
|
+
this.env = resolveAgentEnv(this.path, options.env);
|
|
157
155
|
this.instruction = normalizeInstructionInput(options.instruction);
|
|
158
156
|
this.defaultModel = options.model;
|
|
159
157
|
this.config = this.loadConfig();
|
|
@@ -246,7 +244,7 @@ export class Agent {
|
|
|
246
244
|
*
|
|
247
245
|
* 关键点(中文)
|
|
248
246
|
* - `start()` 是唯一公开的长期运行生命周期入口。
|
|
249
|
-
* - 多次并发调用会复用同一个启动 Promise,避免重复启动 plugins /
|
|
247
|
+
* - 多次并发调用会复用同一个启动 Promise,避免重复启动 plugins / rpc。
|
|
250
248
|
*/
|
|
251
249
|
async start(options?: AgentStartOptions): Promise<AgentStartResult> {
|
|
252
250
|
if (this.startPromise) {
|
|
@@ -259,17 +257,12 @@ export class Agent {
|
|
|
259
257
|
await this.ensurePluginsStarted();
|
|
260
258
|
}
|
|
261
259
|
|
|
262
|
-
const httpBinding =
|
|
263
|
-
options?.http === false || options?.http === undefined
|
|
264
|
-
? undefined
|
|
265
|
-
: await this.startHttp(options.http);
|
|
266
260
|
const rpcBinding =
|
|
267
|
-
options?.rpc ===
|
|
268
|
-
?
|
|
269
|
-
:
|
|
261
|
+
options?.rpc === false || options?.rpc === undefined
|
|
262
|
+
? undefined
|
|
263
|
+
: await this.startRpc(options.rpc);
|
|
270
264
|
|
|
271
265
|
return {
|
|
272
|
-
...(httpBinding ? { http: httpBinding } : {}),
|
|
273
266
|
...(rpcBinding ? { rpc: rpcBinding } : {}),
|
|
274
267
|
pluginsStarted: this.pluginsStarted,
|
|
275
268
|
};
|
|
@@ -286,13 +279,12 @@ export class Agent {
|
|
|
286
279
|
* 停止当前 agent 实例的长期运行能力。
|
|
287
280
|
*
|
|
288
281
|
* 关键点(中文)
|
|
289
|
-
* - 停止顺序保持为 plugins -> rpc
|
|
282
|
+
* - 停止顺序保持为 plugins -> rpc,与当前运行语义一致。
|
|
290
283
|
* - 停止后会清空 `startPromise`,允许后续再次 `start()`。
|
|
291
284
|
*/
|
|
292
285
|
async stop(): Promise<AgentStopResult> {
|
|
293
286
|
const pluginsStarted = this.pluginsStarted;
|
|
294
287
|
const rpcStarted = this.rpcBinding !== null;
|
|
295
|
-
const httpStarted = this.httpBinding !== null;
|
|
296
288
|
|
|
297
289
|
if (pluginsStarted) {
|
|
298
290
|
await this.stopActionScheduleRuntime();
|
|
@@ -304,14 +296,9 @@ export class Agent {
|
|
|
304
296
|
await this.stopRpc();
|
|
305
297
|
}
|
|
306
298
|
|
|
307
|
-
if (httpStarted) {
|
|
308
|
-
await this.stopHttp();
|
|
309
|
-
}
|
|
310
|
-
|
|
311
299
|
this.startPromise = null;
|
|
312
300
|
|
|
313
301
|
return {
|
|
314
|
-
httpStopped: httpStarted,
|
|
315
302
|
rpcStopped: rpcStarted,
|
|
316
303
|
pluginsStopped: pluginsStarted,
|
|
317
304
|
};
|
|
@@ -342,11 +329,42 @@ export class Agent {
|
|
|
342
329
|
return this.logger;
|
|
343
330
|
}
|
|
344
331
|
|
|
332
|
+
/**
|
|
333
|
+
* 返回当前 agent runtime。
|
|
334
|
+
*
|
|
335
|
+
* 关键点(中文)
|
|
336
|
+
* - 供宿主在 agent 外部装配 transport(例如 city HTTP gateway)时复用。
|
|
337
|
+
* - 不暴露启动语义,只暴露运行时访问口。
|
|
338
|
+
*/
|
|
339
|
+
getRuntime(): AgentRuntime {
|
|
340
|
+
return this.runtime;
|
|
341
|
+
}
|
|
342
|
+
|
|
343
|
+
/**
|
|
344
|
+
* 返回当前 agent context。
|
|
345
|
+
*
|
|
346
|
+
* 关键点(中文)
|
|
347
|
+
* - 供宿主装配 plugin/control 相关外层协议面。
|
|
348
|
+
*/
|
|
349
|
+
getContext(): AgentContext {
|
|
350
|
+
return this.agentContext;
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
/**
|
|
354
|
+
* 返回当前 session collection。
|
|
355
|
+
*
|
|
356
|
+
* 关键点(中文)
|
|
357
|
+
* - 供宿主在外层挂载 RemoteAgent transport 时复用。
|
|
358
|
+
*/
|
|
359
|
+
getSessionCollection(): AgentSessionCollection {
|
|
360
|
+
return this.sessionCollection;
|
|
361
|
+
}
|
|
362
|
+
|
|
345
363
|
/**
|
|
346
364
|
* 确保当前 plugins 已启动。
|
|
347
365
|
*
|
|
348
366
|
* 关键点(中文)
|
|
349
|
-
* - 这里只负责托管 plugin 的生命周期启动,不隐式启动
|
|
367
|
+
* - 这里只负责托管 plugin 的生命周期启动,不隐式启动 RPC 能力。
|
|
350
368
|
* - 启动失败的 plugin 会记录日志,但保留与原行为一致的整体启动流程。
|
|
351
369
|
*/
|
|
352
370
|
private async ensurePluginsStarted(): Promise<void> {
|
|
@@ -396,65 +414,35 @@ export class Agent {
|
|
|
396
414
|
}
|
|
397
415
|
|
|
398
416
|
/**
|
|
399
|
-
* 启动当前 agent
|
|
417
|
+
* 启动当前 agent 的本机 RPC server。
|
|
400
418
|
*/
|
|
401
|
-
private async
|
|
402
|
-
options?:
|
|
403
|
-
): Promise<
|
|
404
|
-
if (this.
|
|
405
|
-
return this.
|
|
419
|
+
private async startRpc(
|
|
420
|
+
options?: AgentRpcStartOptions,
|
|
421
|
+
): Promise<AgentRpcBinding> {
|
|
422
|
+
if (this.rpcBinding) {
|
|
423
|
+
return this.rpcBinding;
|
|
406
424
|
}
|
|
407
425
|
const host = String(options?.host || "127.0.0.1").trim() || "127.0.0.1";
|
|
408
426
|
const port =
|
|
409
427
|
typeof options?.port === "number" && Number.isInteger(options.port)
|
|
410
428
|
? options.port
|
|
411
429
|
: 15314;
|
|
412
|
-
const server = await
|
|
430
|
+
const server = await startRpcServer({
|
|
413
431
|
host,
|
|
414
432
|
port,
|
|
415
|
-
getAgentRuntime: () => this.runtime,
|
|
416
|
-
getAgentContext: () => this.agentContext,
|
|
417
433
|
sessionCollection: this.sessionCollection,
|
|
418
434
|
});
|
|
419
|
-
this.
|
|
420
|
-
|
|
435
|
+
this.rpcBinding = {
|
|
436
|
+
url: `rpc://${host}:${port}`,
|
|
421
437
|
host,
|
|
422
438
|
port,
|
|
423
439
|
server,
|
|
424
440
|
};
|
|
425
|
-
return this.httpBinding;
|
|
426
|
-
}
|
|
427
|
-
|
|
428
|
-
/**
|
|
429
|
-
* 停止当前 agent 的 HTTP server。
|
|
430
|
-
*/
|
|
431
|
-
private async stopHttp(): Promise<void> {
|
|
432
|
-
if (!this.httpBinding) return;
|
|
433
|
-
const current = this.httpBinding;
|
|
434
|
-
this.httpBinding = null;
|
|
435
|
-
await current.server.stop();
|
|
436
|
-
}
|
|
437
|
-
|
|
438
|
-
/**
|
|
439
|
-
* 启动当前 agent 的本地 RPC server。
|
|
440
|
-
*/
|
|
441
|
-
private async startRpc(): Promise<AgentRpcBinding> {
|
|
442
|
-
if (this.rpcBinding) {
|
|
443
|
-
return this.rpcBinding;
|
|
444
|
-
}
|
|
445
|
-
const server = await startLocalRpcServer({
|
|
446
|
-
context: this.agentContext,
|
|
447
|
-
runtime: this.runtime,
|
|
448
|
-
});
|
|
449
|
-
this.rpcBinding = {
|
|
450
|
-
endpoint: server.endpoint,
|
|
451
|
-
server,
|
|
452
|
-
};
|
|
453
441
|
return this.rpcBinding;
|
|
454
442
|
}
|
|
455
443
|
|
|
456
444
|
/**
|
|
457
|
-
* 停止当前 agent
|
|
445
|
+
* 停止当前 agent 的本机 RPC server。
|
|
458
446
|
*/
|
|
459
447
|
private async stopRpc(): Promise<void> {
|
|
460
448
|
if (!this.rpcBinding) return;
|
|
@@ -472,11 +460,7 @@ export class Agent {
|
|
|
472
460
|
*/
|
|
473
461
|
private loadConfig(): DowncityConfig {
|
|
474
462
|
try {
|
|
475
|
-
return loadDowncityConfig(this.path
|
|
476
|
-
projectEnv: this.env,
|
|
477
|
-
agentEnv: this.env,
|
|
478
|
-
globalEnv: {},
|
|
479
|
-
});
|
|
463
|
+
return loadDowncityConfig(this.path);
|
|
480
464
|
} catch {
|
|
481
465
|
return createFallbackSdkConfig(this.id);
|
|
482
466
|
}
|