@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
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 本地/远程 transport 选择器。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 本地受信任调用默认优先使用 IPC。
|
|
6
|
-
* - 只有显式传入 `host/port` 时,才视为外部 HTTP 调用。
|
|
7
|
-
* - 当前返回结构与 `callServer()` 保持一致,方便命令层复用。
|
|
8
|
-
*/
|
|
9
|
-
import { callServer } from "../../../runtime/host/daemon/Client.js";
|
|
10
|
-
import { callLocalServer } from "./Client.js";
|
|
11
|
-
/**
|
|
12
|
-
* 判断是否应强制使用 HTTP transport。
|
|
13
|
-
*/
|
|
14
|
-
export function shouldUseHttpTransport(params) {
|
|
15
|
-
return Boolean((typeof params.host === "string" && params.host.trim()) ||
|
|
16
|
-
typeof params.port === "number");
|
|
17
|
-
}
|
|
18
|
-
/**
|
|
19
|
-
* 统一调用 agent transport。
|
|
20
|
-
*/
|
|
21
|
-
export async function callAgentTransport(params) {
|
|
22
|
-
if (shouldUseHttpTransport({
|
|
23
|
-
host: params.host,
|
|
24
|
-
port: params.port,
|
|
25
|
-
})) {
|
|
26
|
-
return await callServer(params);
|
|
27
|
-
}
|
|
28
|
-
return await callLocalServer(params);
|
|
29
|
-
}
|
|
30
|
-
//# sourceMappingURL=Transport.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Transport.js","sourceRoot":"","sources":["../../../../src/runtime/transport/rpc/Transport.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAMH,OAAO,EAAE,UAAU,EAAE,MAAM,iCAAiC,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,aAAa,CAAC;AAE9C;;GAEG;AACH,MAAM,UAAU,sBAAsB,CAAC,MAGtC;IACC,OAAO,OAAO,CACZ,CAAC,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,CAAC;QACvD,OAAO,MAAM,CAAC,IAAI,KAAK,QAAQ,CAChC,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,CAAC,KAAK,UAAU,kBAAkB,CACtC,MAA+B;IAE/B,IAAI,sBAAsB,CAAC;QACzB,IAAI,EAAE,MAAM,CAAC,IAAI;QACjB,IAAI,EAAE,MAAM,CAAC,IAAI;KAClB,CAAC,EAAE,CAAC;QACH,OAAO,MAAM,UAAU,CAAI,MAAM,CAAC,CAAC;IACrC,CAAC;IACD,OAAO,MAAM,eAAe,CAAI,MAAM,CAAC,CAAC;AAC1C,CAAC"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 配置值递归结构类型。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明(中文)
|
|
5
|
-
* - 描述 `downcity.json` 在“读取原始 JSON -> 解析环境变量占位符”阶段可接受的值结构。
|
|
6
|
-
* - 允许对象、数组、JSON 标量与 `undefined` 递归嵌套,供配置解析工具复用。
|
|
7
|
-
* - 该类型只服务配置装配阶段,不承诺运行时最终配置的严格业务语义。
|
|
8
|
-
*/
|
|
9
|
-
export type ResolvedConfigValue = string | number | boolean | null | undefined | {
|
|
10
|
-
[key: string]: ResolvedConfigValue;
|
|
11
|
-
} | ResolvedConfigValue[];
|
|
12
|
-
//# sourceMappingURL=ResolvedConfigValue.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ResolvedConfigValue.d.ts","sourceRoot":"","sources":["../../../src/types/common/ResolvedConfigValue.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,MAAM,MAAM,mBAAmB,GAC3B,MAAM,GACN,MAAM,GACN,OAAO,GACP,IAAI,GACJ,SAAS,GACT;IAAE,CAAC,GAAG,EAAE,MAAM,GAAG,mBAAmB,CAAA;CAAE,GACtC,mBAAmB,EAAE,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ResolvedConfigValue.js","sourceRoot":"","sources":["../../../src/types/common/ResolvedConfigValue.ts"],"names":[],"mappings":""}
|
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* LocalRpc:本地 IPC 调用协议类型。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 仅用于本机受信任进程之间的调用,不承担外部 HTTP 鉴权职责。
|
|
6
|
-
* - 当前协议采用“一连接一请求一响应”的 JSON 行格式,便于调试与逐步演进。
|
|
7
|
-
*/
|
|
8
|
-
import type { JsonValue } from "../../../types/common/Json.js";
|
|
9
|
-
import type { DaemonHttpMethod } from "../../../runtime/host/daemon/Api.js";
|
|
10
|
-
/**
|
|
11
|
-
* 单次本地 RPC 请求。
|
|
12
|
-
*/
|
|
13
|
-
export interface LocalRpcRequest {
|
|
14
|
-
/**
|
|
15
|
-
* 请求唯一标识。
|
|
16
|
-
*/
|
|
17
|
-
requestId: string;
|
|
18
|
-
/**
|
|
19
|
-
* 目标 API 路径。
|
|
20
|
-
*/
|
|
21
|
-
path: string;
|
|
22
|
-
/**
|
|
23
|
-
* 调用方法。
|
|
24
|
-
*/
|
|
25
|
-
method: DaemonHttpMethod;
|
|
26
|
-
/**
|
|
27
|
-
* 可选结构化请求体。
|
|
28
|
-
*/
|
|
29
|
-
body?: JsonValue;
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* 单次本地 RPC 响应。
|
|
33
|
-
*/
|
|
34
|
-
export interface LocalRpcResponse {
|
|
35
|
-
/**
|
|
36
|
-
* 对应请求标识。
|
|
37
|
-
*/
|
|
38
|
-
requestId: string;
|
|
39
|
-
/**
|
|
40
|
-
* HTTP 风格状态码。
|
|
41
|
-
*/
|
|
42
|
-
status: number;
|
|
43
|
-
/**
|
|
44
|
-
* 调用是否成功。
|
|
45
|
-
*/
|
|
46
|
-
success: boolean;
|
|
47
|
-
/**
|
|
48
|
-
* 成功时的数据。
|
|
49
|
-
*/
|
|
50
|
-
data?: JsonValue;
|
|
51
|
-
/**
|
|
52
|
-
* 失败时的错误信息。
|
|
53
|
-
*/
|
|
54
|
-
error?: string;
|
|
55
|
-
}
|
|
56
|
-
/**
|
|
57
|
-
* 本地 RPC server 句柄。
|
|
58
|
-
*/
|
|
59
|
-
export interface LocalRpcServerHandle {
|
|
60
|
-
/**
|
|
61
|
-
* 当前绑定的 socket/pipe 地址。
|
|
62
|
-
*/
|
|
63
|
-
endpoint: string;
|
|
64
|
-
/**
|
|
65
|
-
* 停止本地 RPC server。
|
|
66
|
-
*/
|
|
67
|
-
stop(): Promise<void>;
|
|
68
|
-
}
|
|
69
|
-
//# sourceMappingURL=LocalRpc.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalRpc.d.ts","sourceRoot":"","sources":["../../../../src/types/runtime/rpc/LocalRpc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,KAAK,EAAE,gBAAgB,EAAE,MAAM,8BAA8B,CAAC;AAErE;;GAEG;AACH,MAAM,WAAW,eAAe;IAC9B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,IAAI,EAAE,MAAM,CAAC;IACb;;OAEG;IACH,MAAM,EAAE,gBAAgB,CAAC;IACzB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;CAClB;AAED;;GAEG;AACH,MAAM,WAAW,gBAAgB;IAC/B;;OAEG;IACH,SAAS,EAAE,MAAM,CAAC;IAClB;;OAEG;IACH,MAAM,EAAE,MAAM,CAAC;IACf;;OAEG;IACH,OAAO,EAAE,OAAO,CAAC;IACjB;;OAEG;IACH,IAAI,CAAC,EAAE,SAAS,CAAC;IACjB;;OAEG;IACH,KAAK,CAAC,EAAE,MAAM,CAAC;CAChB;AAED;;GAEG;AACH,MAAM,WAAW,oBAAoB;IACnC;;OAEG;IACH,QAAQ,EAAE,MAAM,CAAC;IACjB;;OAEG;IACH,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CACvB"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"LocalRpc.js","sourceRoot":"","sources":["../../../../src/types/runtime/rpc/LocalRpc.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG"}
|
|
@@ -1,52 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Agent 配置域环境变量占位符解析模块。
|
|
3
|
-
*
|
|
4
|
-
* 职责说明(中文)
|
|
5
|
-
* - 负责把配置树中的 `${ENV_NAME}` 形式占位符替换为运行时可见的环境变量值。
|
|
6
|
-
* - 服务 `downcity.json` 等配置载体的解析流程,让配置读取相关逻辑集中留在 `config/` 语义域。
|
|
7
|
-
*
|
|
8
|
-
* 边界说明(中文)
|
|
9
|
-
* - 该模块只处理结构遍历与替换,不读取文件,也不决定环境变量来源优先级。
|
|
10
|
-
* - 这里只负责“如何替换”,不负责“缺失变量时是否报错”的业务策略。
|
|
11
|
-
*/
|
|
12
|
-
|
|
13
|
-
import type { JsonObject } from "@/types/common/Json.js";
|
|
14
|
-
import type { ResolvedConfigValue } from "@/types/common/ResolvedConfigValue.js";
|
|
15
|
-
|
|
16
|
-
/**
|
|
17
|
-
* 递归解析配置值中的环境变量占位符。
|
|
18
|
-
*
|
|
19
|
-
* 关键点(中文)
|
|
20
|
-
* - 仅替换“整个字符串就是 `${VAR}`”的场景,不处理字符串内插值拼接。
|
|
21
|
-
* - 数组与对象会递归遍历,保持原有结构不变。
|
|
22
|
-
* - 未命中的环境变量会返回 `undefined`,由调用方决定后续行为。
|
|
23
|
-
*/
|
|
24
|
-
export function resolveEnvPlaceholdersDeep(
|
|
25
|
-
value: ResolvedConfigValue,
|
|
26
|
-
resolveEnvVar: (name: string) => string | undefined,
|
|
27
|
-
): ResolvedConfigValue {
|
|
28
|
-
if (typeof value === "string") {
|
|
29
|
-
const match = value.match(/^\$\{([A-Z0-9_]+)\}$/);
|
|
30
|
-
if (!match) return value;
|
|
31
|
-
const envVar = match[1];
|
|
32
|
-
return resolveEnvVar(envVar);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
if (Array.isArray(value)) {
|
|
36
|
-
return value.map((item) => resolveEnvPlaceholdersDeep(item, resolveEnvVar));
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
if (value && typeof value === "object") {
|
|
40
|
-
const obj = value as JsonObject;
|
|
41
|
-
const out: { [key: string]: ResolvedConfigValue } = {};
|
|
42
|
-
for (const [key, child] of Object.entries(obj)) {
|
|
43
|
-
out[key] = resolveEnvPlaceholdersDeep(
|
|
44
|
-
child as ResolvedConfigValue,
|
|
45
|
-
resolveEnvVar,
|
|
46
|
-
);
|
|
47
|
-
}
|
|
48
|
-
return out;
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
return value;
|
|
52
|
-
}
|
|
@@ -1,408 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Local RPC server。
|
|
3
|
-
*
|
|
4
|
-
* 关键点(中文)
|
|
5
|
-
* - 只服务本地受信任进程,不暴露 HTTP 协议。
|
|
6
|
-
* - 这里承接本机 CLI 访问 agent runtime 的 IPC 路由,并与 HTTP 能力保持语义一致。
|
|
7
|
-
*/
|
|
8
|
-
|
|
9
|
-
import fs from "fs-extra";
|
|
10
|
-
import net, { type Server } from "node:net";
|
|
11
|
-
import path from "node:path";
|
|
12
|
-
import type { AgentRuntime } from "@/types/runtime/agent/AgentRuntime.js";
|
|
13
|
-
import type { AgentContext } from "@/types/runtime/agent/AgentContext.js";
|
|
14
|
-
import type { JsonValue } from "@/types/common/Json.js";
|
|
15
|
-
import type { LocalRpcRequest, LocalRpcResponse, LocalRpcServerHandle } from "@/types/runtime/rpc/LocalRpc.js";
|
|
16
|
-
import type { ControlSessionExecuteRequestBody } from "@/runtime/server/http/control/types/ControlSessionExecute.js";
|
|
17
|
-
import type {
|
|
18
|
-
PluginActionResponse,
|
|
19
|
-
PluginAvailabilityResponse,
|
|
20
|
-
PluginCatalogResponse,
|
|
21
|
-
} from "@/plugin/types/PluginApi.js";
|
|
22
|
-
import type {
|
|
23
|
-
PluginControlAction,
|
|
24
|
-
PluginCommandResponse,
|
|
25
|
-
PluginControlResponse,
|
|
26
|
-
PluginStateListResponse,
|
|
27
|
-
} from "@/plugin/types/Plugins.js";
|
|
28
|
-
import { listPluginStates, controlPluginState } from "@/plugin/core/PluginStateController.js";
|
|
29
|
-
import { runPluginCommand } from "@/plugin/core/PluginActionRunner.js";
|
|
30
|
-
import { parsePluginCommandRequestBody } from "@/plugin/core/PluginCommandRequest.js";
|
|
31
|
-
import { executeBySessionId } from "@/runtime/server/http/control/ExecuteBySession.js";
|
|
32
|
-
import { getLocalRpcEndpoint } from "@/runtime/transport/rpc/Paths.js";
|
|
33
|
-
|
|
34
|
-
async function isSocketEndpointActive(endpoint: string): Promise<boolean> {
|
|
35
|
-
return await new Promise<boolean>((resolve) => {
|
|
36
|
-
const socket = net.createConnection(endpoint);
|
|
37
|
-
let settled = false;
|
|
38
|
-
const finish = (value: boolean): void => {
|
|
39
|
-
if (settled) return;
|
|
40
|
-
settled = true;
|
|
41
|
-
socket.destroy();
|
|
42
|
-
resolve(value);
|
|
43
|
-
};
|
|
44
|
-
socket.setTimeout(200);
|
|
45
|
-
socket.on("connect", () => finish(true));
|
|
46
|
-
socket.on("timeout", () => finish(false));
|
|
47
|
-
socket.on("error", () => finish(false));
|
|
48
|
-
});
|
|
49
|
-
}
|
|
50
|
-
|
|
51
|
-
function isObjectRecord(value: unknown): value is Record<string, unknown> {
|
|
52
|
-
return Boolean(value && typeof value === "object" && !Array.isArray(value));
|
|
53
|
-
}
|
|
54
|
-
|
|
55
|
-
function createSuccessResponse(
|
|
56
|
-
requestId: string,
|
|
57
|
-
data: JsonValue,
|
|
58
|
-
status = 200,
|
|
59
|
-
): LocalRpcResponse {
|
|
60
|
-
return {
|
|
61
|
-
requestId,
|
|
62
|
-
status,
|
|
63
|
-
success: true,
|
|
64
|
-
data,
|
|
65
|
-
};
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
function createErrorResponse(
|
|
69
|
-
requestId: string,
|
|
70
|
-
status: number,
|
|
71
|
-
error: string,
|
|
72
|
-
): LocalRpcResponse {
|
|
73
|
-
return {
|
|
74
|
-
requestId,
|
|
75
|
-
status,
|
|
76
|
-
success: false,
|
|
77
|
-
error,
|
|
78
|
-
};
|
|
79
|
-
}
|
|
80
|
-
|
|
81
|
-
async function handlePluginControl(params: {
|
|
82
|
-
requestId: string;
|
|
83
|
-
body: JsonValue | undefined;
|
|
84
|
-
context: AgentContext;
|
|
85
|
-
}): Promise<LocalRpcResponse> {
|
|
86
|
-
const body = isObjectRecord(params.body) ? params.body : {};
|
|
87
|
-
const pluginName = String(body.pluginName || "").trim();
|
|
88
|
-
const action = String(body.action || "").trim() as PluginControlAction;
|
|
89
|
-
if (!pluginName || !action) {
|
|
90
|
-
return createErrorResponse(params.requestId, 400, "pluginName and action are required");
|
|
91
|
-
}
|
|
92
|
-
const result = await controlPluginState({
|
|
93
|
-
pluginName,
|
|
94
|
-
action,
|
|
95
|
-
context: params.context,
|
|
96
|
-
});
|
|
97
|
-
const payload: PluginControlResponse = {
|
|
98
|
-
success: result.success,
|
|
99
|
-
...(result.plugin ? { plugin: result.plugin } : {}),
|
|
100
|
-
...(result.error ? { error: result.error } : {}),
|
|
101
|
-
};
|
|
102
|
-
return createSuccessResponse(params.requestId, payload as unknown as JsonValue);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
|
-
async function handlePluginCommand(params: {
|
|
106
|
-
requestId: string;
|
|
107
|
-
body: JsonValue | undefined;
|
|
108
|
-
context: AgentContext;
|
|
109
|
-
}): Promise<LocalRpcResponse> {
|
|
110
|
-
let body;
|
|
111
|
-
try {
|
|
112
|
-
body = parsePluginCommandRequestBody(params.body);
|
|
113
|
-
} catch (error) {
|
|
114
|
-
return createErrorResponse(params.requestId, 400, String(error));
|
|
115
|
-
}
|
|
116
|
-
if (!body.pluginName || !body.command) {
|
|
117
|
-
return createErrorResponse(params.requestId, 400, "pluginName and command are required");
|
|
118
|
-
}
|
|
119
|
-
const result = await runPluginCommand({
|
|
120
|
-
pluginName: body.pluginName,
|
|
121
|
-
command: body.command,
|
|
122
|
-
payload: body.payload,
|
|
123
|
-
schedule: body.schedule,
|
|
124
|
-
context: params.context,
|
|
125
|
-
});
|
|
126
|
-
const payload: PluginCommandResponse = {
|
|
127
|
-
success: result.success,
|
|
128
|
-
...(result.plugin ? { plugin: result.plugin } : {}),
|
|
129
|
-
...(result.data !== undefined ? { data: result.data } : {}),
|
|
130
|
-
...(result.message ? { message: result.message } : {}),
|
|
131
|
-
...(result.success ? {} : { error: result.message || "plugin command failed" }),
|
|
132
|
-
};
|
|
133
|
-
return createSuccessResponse(params.requestId, payload as unknown as JsonValue);
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
async function handlePluginAvailability(params: {
|
|
137
|
-
requestId: string;
|
|
138
|
-
body: JsonValue | undefined;
|
|
139
|
-
context: AgentContext;
|
|
140
|
-
}): Promise<LocalRpcResponse> {
|
|
141
|
-
const body = isObjectRecord(params.body) ? params.body : {};
|
|
142
|
-
const pluginName = String(body.pluginName || "").trim();
|
|
143
|
-
if (!pluginName) {
|
|
144
|
-
return createErrorResponse(params.requestId, 400, "pluginName is required");
|
|
145
|
-
}
|
|
146
|
-
const availability = await params.context.plugins.availability(pluginName);
|
|
147
|
-
const payload: PluginAvailabilityResponse = {
|
|
148
|
-
success: true,
|
|
149
|
-
pluginName,
|
|
150
|
-
availability,
|
|
151
|
-
};
|
|
152
|
-
return createSuccessResponse(params.requestId, payload as unknown as JsonValue);
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
async function handlePluginAction(params: {
|
|
156
|
-
requestId: string;
|
|
157
|
-
body: JsonValue | undefined;
|
|
158
|
-
context: AgentContext;
|
|
159
|
-
}): Promise<LocalRpcResponse> {
|
|
160
|
-
const body = isObjectRecord(params.body) ? params.body : {};
|
|
161
|
-
const pluginName = String(body.pluginName || "").trim();
|
|
162
|
-
const actionName = String(body.actionName || "").trim();
|
|
163
|
-
if (!pluginName) {
|
|
164
|
-
return createErrorResponse(params.requestId, 400, "pluginName is required");
|
|
165
|
-
}
|
|
166
|
-
if (!actionName) {
|
|
167
|
-
return createErrorResponse(params.requestId, 400, "actionName is required");
|
|
168
|
-
}
|
|
169
|
-
const result = await params.context.plugins.runAction({
|
|
170
|
-
plugin: pluginName,
|
|
171
|
-
action: actionName,
|
|
172
|
-
payload: body.payload,
|
|
173
|
-
});
|
|
174
|
-
const payload: PluginActionResponse = {
|
|
175
|
-
success: result.success,
|
|
176
|
-
pluginName,
|
|
177
|
-
actionName,
|
|
178
|
-
...(result.data !== undefined ? { data: result.data } : {}),
|
|
179
|
-
...(result.message ? { message: result.message } : {}),
|
|
180
|
-
...(result.error ? { error: result.error } : {}),
|
|
181
|
-
};
|
|
182
|
-
return createSuccessResponse(
|
|
183
|
-
params.requestId,
|
|
184
|
-
payload as unknown as JsonValue,
|
|
185
|
-
result.success ? 200 : 400,
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
|
|
189
|
-
function matchControlSessionExecutePath(pathname: string): string | null {
|
|
190
|
-
const match = /^\/api\/control\/sessions\/([^/]+)\/execute$/.exec(
|
|
191
|
-
String(pathname || "").trim(),
|
|
192
|
-
);
|
|
193
|
-
if (!match) return null;
|
|
194
|
-
try {
|
|
195
|
-
return decodeURIComponent(match[1] || "").trim() || null;
|
|
196
|
-
} catch {
|
|
197
|
-
return null;
|
|
198
|
-
}
|
|
199
|
-
}
|
|
200
|
-
|
|
201
|
-
async function handleControlSessionExecute(params: {
|
|
202
|
-
requestId: string;
|
|
203
|
-
body: JsonValue | undefined;
|
|
204
|
-
context: AgentContext;
|
|
205
|
-
runtime?: AgentRuntime;
|
|
206
|
-
sessionId: string;
|
|
207
|
-
}): Promise<LocalRpcResponse> {
|
|
208
|
-
if (!params.runtime) {
|
|
209
|
-
return createErrorResponse(
|
|
210
|
-
params.requestId,
|
|
211
|
-
500,
|
|
212
|
-
"Local RPC control execute requires agent runtime",
|
|
213
|
-
);
|
|
214
|
-
}
|
|
215
|
-
const body = isObjectRecord(params.body) ? params.body : {};
|
|
216
|
-
const instructions = String(body.instructions || "").trim();
|
|
217
|
-
const attachments = Array.isArray(body.attachments)
|
|
218
|
-
? (body.attachments as ControlSessionExecuteRequestBody["attachments"])
|
|
219
|
-
: undefined;
|
|
220
|
-
if (!params.sessionId) {
|
|
221
|
-
return createErrorResponse(params.requestId, 400, "sessionId is required");
|
|
222
|
-
}
|
|
223
|
-
if (!instructions) {
|
|
224
|
-
return createErrorResponse(params.requestId, 400, "instructions are required");
|
|
225
|
-
}
|
|
226
|
-
try {
|
|
227
|
-
const result = await executeBySessionId({
|
|
228
|
-
agentState: params.runtime,
|
|
229
|
-
executionContext: params.context,
|
|
230
|
-
sessionId: params.sessionId,
|
|
231
|
-
instructions,
|
|
232
|
-
attachments,
|
|
233
|
-
});
|
|
234
|
-
return createSuccessResponse(
|
|
235
|
-
params.requestId,
|
|
236
|
-
{
|
|
237
|
-
success: true,
|
|
238
|
-
sessionId: params.sessionId,
|
|
239
|
-
result,
|
|
240
|
-
} as unknown as JsonValue,
|
|
241
|
-
);
|
|
242
|
-
} catch (error) {
|
|
243
|
-
return createErrorResponse(params.requestId, 500, String(error));
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
|
|
247
|
-
async function dispatchRequest(params: {
|
|
248
|
-
request: LocalRpcRequest;
|
|
249
|
-
context: AgentContext;
|
|
250
|
-
runtime?: AgentRuntime;
|
|
251
|
-
}): Promise<LocalRpcResponse> {
|
|
252
|
-
const { request } = params;
|
|
253
|
-
if (
|
|
254
|
-
request.method === "GET" &&
|
|
255
|
-
request.path === "/api/plugins/list"
|
|
256
|
-
) {
|
|
257
|
-
const payload: PluginStateListResponse = {
|
|
258
|
-
success: true,
|
|
259
|
-
plugins: listPluginStates({ context: params.context }),
|
|
260
|
-
};
|
|
261
|
-
return createSuccessResponse(request.requestId, payload as unknown as JsonValue);
|
|
262
|
-
}
|
|
263
|
-
if (
|
|
264
|
-
request.method === "POST" &&
|
|
265
|
-
request.path === "/api/plugins/control"
|
|
266
|
-
) {
|
|
267
|
-
return await handlePluginControl({
|
|
268
|
-
requestId: request.requestId,
|
|
269
|
-
body: request.body,
|
|
270
|
-
context: params.context,
|
|
271
|
-
});
|
|
272
|
-
}
|
|
273
|
-
if (
|
|
274
|
-
request.method === "POST" &&
|
|
275
|
-
request.path === "/api/plugins/command"
|
|
276
|
-
) {
|
|
277
|
-
return await handlePluginCommand({
|
|
278
|
-
requestId: request.requestId,
|
|
279
|
-
body: request.body,
|
|
280
|
-
context: params.context,
|
|
281
|
-
});
|
|
282
|
-
}
|
|
283
|
-
if (request.method === "GET" && request.path === "/api/plugins/catalog") {
|
|
284
|
-
const payload: PluginCatalogResponse = {
|
|
285
|
-
success: true,
|
|
286
|
-
plugins: params.context.plugins.list(),
|
|
287
|
-
};
|
|
288
|
-
return createSuccessResponse(request.requestId, payload as unknown as JsonValue);
|
|
289
|
-
}
|
|
290
|
-
if (request.method === "POST" && request.path === "/api/plugins/availability") {
|
|
291
|
-
return await handlePluginAvailability({
|
|
292
|
-
requestId: request.requestId,
|
|
293
|
-
body: request.body,
|
|
294
|
-
context: params.context,
|
|
295
|
-
});
|
|
296
|
-
}
|
|
297
|
-
if (request.method === "POST" && request.path === "/api/plugins/action") {
|
|
298
|
-
return await handlePluginAction({
|
|
299
|
-
requestId: request.requestId,
|
|
300
|
-
body: request.body,
|
|
301
|
-
context: params.context,
|
|
302
|
-
});
|
|
303
|
-
}
|
|
304
|
-
const controlSessionId =
|
|
305
|
-
request.method === "POST"
|
|
306
|
-
? matchControlSessionExecutePath(request.path)
|
|
307
|
-
: null;
|
|
308
|
-
if (controlSessionId) {
|
|
309
|
-
return await handleControlSessionExecute({
|
|
310
|
-
requestId: request.requestId,
|
|
311
|
-
body: request.body,
|
|
312
|
-
context: params.context,
|
|
313
|
-
runtime: params.runtime,
|
|
314
|
-
sessionId: controlSessionId,
|
|
315
|
-
});
|
|
316
|
-
}
|
|
317
|
-
return createErrorResponse(
|
|
318
|
-
request.requestId,
|
|
319
|
-
404,
|
|
320
|
-
`Unknown local RPC path: ${request.method} ${request.path}`,
|
|
321
|
-
);
|
|
322
|
-
}
|
|
323
|
-
|
|
324
|
-
async function ensureEndpointReady(endpoint: string): Promise<void> {
|
|
325
|
-
if (process.platform === "win32") return;
|
|
326
|
-
await fs.ensureDir(path.dirname(endpoint));
|
|
327
|
-
const exists = await fs.pathExists(endpoint);
|
|
328
|
-
if (!exists) return;
|
|
329
|
-
if (await isSocketEndpointActive(endpoint)) {
|
|
330
|
-
throw new Error(`Local RPC endpoint already in use: ${endpoint}`);
|
|
331
|
-
}
|
|
332
|
-
await fs.remove(endpoint);
|
|
333
|
-
}
|
|
334
|
-
|
|
335
|
-
function writeResponse(socket: net.Socket, response: LocalRpcResponse): void {
|
|
336
|
-
socket.end(`${JSON.stringify(response)}\n`);
|
|
337
|
-
}
|
|
338
|
-
|
|
339
|
-
function bindConnectionHandler(params: {
|
|
340
|
-
server: Server;
|
|
341
|
-
context: AgentContext;
|
|
342
|
-
runtime?: AgentRuntime;
|
|
343
|
-
}): void {
|
|
344
|
-
const { server, context, runtime } = params;
|
|
345
|
-
server.on("connection", (socket) => {
|
|
346
|
-
let buffered = "";
|
|
347
|
-
socket.setEncoding("utf8");
|
|
348
|
-
socket.on("data", async (chunk) => {
|
|
349
|
-
buffered += String(chunk || "");
|
|
350
|
-
const newlineIndex = buffered.indexOf("\n");
|
|
351
|
-
if (newlineIndex < 0) return;
|
|
352
|
-
const raw = buffered.slice(0, newlineIndex).trim();
|
|
353
|
-
if (!raw) {
|
|
354
|
-
writeResponse(socket, createErrorResponse("unknown", 400, "Empty local RPC payload"));
|
|
355
|
-
return;
|
|
356
|
-
}
|
|
357
|
-
try {
|
|
358
|
-
const request = JSON.parse(raw) as LocalRpcRequest;
|
|
359
|
-
const response = await dispatchRequest({
|
|
360
|
-
request,
|
|
361
|
-
context,
|
|
362
|
-
runtime,
|
|
363
|
-
});
|
|
364
|
-
writeResponse(socket, response);
|
|
365
|
-
} catch (error) {
|
|
366
|
-
writeResponse(
|
|
367
|
-
socket,
|
|
368
|
-
createErrorResponse("unknown", 400, `Invalid local RPC request: ${String(error)}`),
|
|
369
|
-
);
|
|
370
|
-
}
|
|
371
|
-
});
|
|
372
|
-
});
|
|
373
|
-
}
|
|
374
|
-
|
|
375
|
-
/**
|
|
376
|
-
* 启动本地 RPC server。
|
|
377
|
-
*/
|
|
378
|
-
export async function startLocalRpcServer(params: {
|
|
379
|
-
context: AgentContext;
|
|
380
|
-
runtime: AgentRuntime;
|
|
381
|
-
}): Promise<LocalRpcServerHandle> {
|
|
382
|
-
const endpoint = getLocalRpcEndpoint(params.context.rootPath);
|
|
383
|
-
await ensureEndpointReady(endpoint);
|
|
384
|
-
|
|
385
|
-
const server = net.createServer();
|
|
386
|
-
bindConnectionHandler({
|
|
387
|
-
server,
|
|
388
|
-
context: params.context,
|
|
389
|
-
runtime: params.runtime,
|
|
390
|
-
});
|
|
391
|
-
|
|
392
|
-
await new Promise<void>((resolve, reject) => {
|
|
393
|
-
server.once("error", reject);
|
|
394
|
-
server.listen(endpoint, () => resolve());
|
|
395
|
-
});
|
|
396
|
-
|
|
397
|
-
return {
|
|
398
|
-
endpoint,
|
|
399
|
-
async stop() {
|
|
400
|
-
await new Promise<void>((resolve) => {
|
|
401
|
-
server.close(() => resolve());
|
|
402
|
-
});
|
|
403
|
-
if (process.platform !== "win32") {
|
|
404
|
-
await fs.remove(endpoint);
|
|
405
|
-
}
|
|
406
|
-
},
|
|
407
|
-
};
|
|
408
|
-
}
|