@downcity/city 1.1.29 → 1.1.39
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 +5 -11
- package/bin/cli/Index.js +10 -5
- package/bin/cli/Index.js.map +1 -1
- package/bin/cli/agent/AgentChat.js +1 -1
- package/bin/cli/agent/AgentChat.js.map +1 -1
- package/bin/cli/agent/AgentManager.js +3 -3
- package/bin/cli/agent/AgentManager.js.map +1 -1
- package/bin/cli/agent/Init.d.ts.map +1 -1
- package/bin/cli/agent/Init.js +14 -14
- package/bin/cli/agent/Init.js.map +1 -1
- package/bin/cli/agent/Restart.js +1 -1
- package/bin/cli/agent/Restart.js.map +1 -1
- package/bin/cli/agent/Run.d.ts.map +1 -1
- package/bin/cli/agent/Run.js +12 -19
- package/bin/cli/agent/Run.js.map +1 -1
- package/bin/cli/agent/Start.js +1 -1
- package/bin/cli/agent/Start.js.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.d.ts.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.js +2 -3
- package/bin/cli/control-plane/ControlPlaneProcess.js.map +1 -1
- package/bin/cli/model/ModelSupport.d.ts +1 -1
- package/bin/cli/model/ModelSupport.d.ts.map +1 -1
- package/bin/cli/model/ModelSupport.js +1 -1
- package/bin/cli/model/ModelSupport.js.map +1 -1
- package/bin/cli/shared/Chat.d.ts +1 -1
- package/bin/cli/shared/Chat.js +1 -1
- package/bin/cli/shared/ChatAuth.d.ts.map +1 -1
- package/bin/cli/shared/ChatAuth.js +5 -7
- package/bin/cli/shared/ChatAuth.js.map +1 -1
- package/bin/cli/shared/ChatManager.d.ts +1 -1
- package/bin/cli/shared/ChatManager.d.ts.map +1 -1
- package/bin/cli/shared/ChatManager.js +20 -21
- package/bin/cli/shared/ChatManager.js.map +1 -1
- package/bin/cli/shared/Config.js +1 -1
- package/bin/cli/shared/Config.js.map +1 -1
- package/bin/cli/shared/ManagedPluginActionCommands.d.ts +15 -0
- package/bin/cli/shared/ManagedPluginActionCommands.d.ts.map +1 -0
- package/bin/cli/shared/{PluginRuntimeActionCommands.js → ManagedPluginActionCommands.js} +13 -12
- package/bin/cli/shared/ManagedPluginActionCommands.js.map +1 -0
- package/bin/cli/shared/{PluginRuntimeRemote.d.ts → ManagedPluginRemote.d.ts} +6 -6
- package/bin/cli/shared/{PluginRuntimeRemote.d.ts.map → ManagedPluginRemote.d.ts.map} +1 -1
- package/bin/cli/shared/{PluginRuntimeRemote.js → ManagedPluginRemote.js} +14 -14
- package/bin/cli/shared/ManagedPluginRemote.js.map +1 -0
- package/bin/cli/shared/PluginScheduleCommand.d.ts +3 -2
- package/bin/cli/shared/PluginScheduleCommand.d.ts.map +1 -1
- package/bin/cli/shared/PluginScheduleCommand.js +12 -11
- package/bin/cli/shared/PluginScheduleCommand.js.map +1 -1
- package/bin/cli/shared/{PluginRuntimeSupport.d.ts → PluginTargetSupport.d.ts} +7 -7
- package/bin/cli/shared/PluginTargetSupport.d.ts.map +1 -0
- package/bin/cli/shared/{PluginRuntimeSupport.js → PluginTargetSupport.js} +7 -8
- package/bin/cli/shared/{PluginRuntimeSupport.js.map → PluginTargetSupport.js.map} +1 -1
- package/bin/cli/shared/Plugins.d.ts.map +1 -1
- package/bin/cli/shared/Plugins.js +30 -21
- package/bin/cli/shared/Plugins.js.map +1 -1
- package/bin/cli/shared/PortHints.js +1 -1
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +2 -8
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/Paths.d.ts +2 -2
- package/bin/config/Paths.js +2 -2
- package/bin/control/AgentStatusApiRoutes.js +2 -2
- package/bin/control/AgentStatusApiRoutes.js.map +1 -1
- package/bin/control/ChannelAccountApiRoutes.d.ts.map +1 -1
- package/bin/control/ChannelAccountApiRoutes.js +6 -7
- package/bin/control/ChannelAccountApiRoutes.js.map +1 -1
- package/bin/control/ControlGateway.d.ts.map +1 -1
- package/bin/control/ControlGateway.js +3 -2
- package/bin/control/ControlGateway.js.map +1 -1
- package/bin/control/PluginApiRoutes.d.ts.map +1 -1
- package/bin/control/PluginApiRoutes.js +38 -30
- package/bin/control/PluginApiRoutes.js.map +1 -1
- package/bin/control/gateway/AgentActions.d.ts.map +1 -1
- package/bin/control/gateway/AgentActions.js +16 -11
- package/bin/control/gateway/AgentActions.js.map +1 -1
- package/bin/control/gateway/AgentCatalog.js +1 -1
- package/bin/control/gateway/AgentCatalog.js.map +1 -1
- package/bin/control/instant/InstantApiRoutes.d.ts +3 -3
- package/bin/control/instant/InstantApiRoutes.d.ts.map +1 -1
- package/bin/control/instant/InstantApiRoutes.js +5 -5
- package/bin/control/instant/InstantApiRoutes.js.map +1 -1
- package/bin/control/instant/{InstantSessionService.d.ts → InstantSessionRunner.d.ts} +7 -7
- package/bin/control/instant/InstantSessionRunner.d.ts.map +1 -0
- package/bin/control/instant/{InstantSessionService.js → InstantSessionRunner.js} +4 -4
- package/bin/control/instant/InstantSessionRunner.js.map +1 -0
- package/bin/http/auth/RoutePolicy.js +4 -4
- package/bin/http/auth/RoutePolicy.js.map +1 -1
- package/bin/model/runtime/CreateRuntimeModel.d.ts +2 -10
- package/bin/model/runtime/CreateRuntimeModel.d.ts.map +1 -1
- package/bin/model/runtime/CreateRuntimeModel.js +1 -16
- package/bin/model/runtime/CreateRuntimeModel.js.map +1 -1
- package/bin/model/runtime/ExecutionModelBinding.d.ts +46 -0
- package/bin/model/runtime/ExecutionModelBinding.d.ts.map +1 -0
- package/bin/model/runtime/ExecutionModelBinding.js +96 -0
- package/bin/model/runtime/ExecutionModelBinding.js.map +1 -0
- package/bin/process/daemon/Api.d.ts +2 -2
- package/bin/process/daemon/Api.js +1 -1
- package/bin/process/registry/AgentHostRuntime.d.ts +1 -9
- package/bin/process/registry/AgentHostRuntime.d.ts.map +1 -1
- package/bin/process/registry/AgentHostRuntime.js +2 -156
- package/bin/process/registry/AgentHostRuntime.js.map +1 -1
- package/package.json +3 -2
- package/src/cli/Index.ts +13 -5
- package/src/cli/agent/AgentChat.ts +1 -1
- package/src/cli/agent/AgentManager.ts +3 -3
- package/src/cli/agent/Init.ts +15 -14
- package/src/cli/agent/Restart.ts +1 -1
- package/src/cli/agent/Run.ts +12 -18
- package/src/cli/agent/Start.ts +1 -1
- package/src/cli/control-plane/ControlPlaneProcess.ts +2 -3
- package/src/cli/model/ModelSupport.ts +1 -1
- package/src/cli/shared/Chat.ts +1 -1
- package/src/cli/shared/ChatAuth.ts +10 -11
- package/src/cli/shared/ChatManager.ts +21 -22
- package/src/cli/shared/Config.ts +1 -1
- package/src/cli/shared/{PluginRuntimeActionCommands.ts → ManagedPluginActionCommands.ts} +18 -15
- package/src/cli/shared/{PluginRuntimeRemote.ts → ManagedPluginRemote.ts} +15 -15
- package/src/cli/shared/PluginScheduleCommand.ts +12 -11
- package/src/cli/shared/{PluginRuntimeSupport.ts → PluginTargetSupport.ts} +8 -9
- package/src/cli/shared/Plugins.ts +38 -28
- package/src/cli/shared/PortHints.ts +1 -1
- package/src/config/DowncitySchema.ts +2 -8
- package/src/config/Paths.ts +2 -2
- package/src/control/AgentStatusApiRoutes.ts +5 -5
- package/src/control/ChannelAccountApiRoutes.ts +6 -7
- package/src/control/ControlGateway.ts +3 -2
- package/src/control/PluginApiRoutes.ts +42 -32
- package/src/control/gateway/AgentActions.ts +16 -11
- package/src/control/gateway/AgentCatalog.ts +1 -1
- package/src/control/instant/InstantApiRoutes.ts +8 -8
- package/src/control/instant/{InstantSessionService.ts → InstantSessionRunner.ts} +7 -7
- package/src/http/auth/RoutePolicy.ts +4 -4
- package/src/model/runtime/CreateRuntimeModel.ts +1 -26
- package/src/model/runtime/ExecutionModelBinding.ts +120 -0
- package/src/process/daemon/Api.ts +2 -2
- package/src/process/registry/AgentHostRuntime.ts +2 -164
- package/tsconfig.json +2 -1
- package/bin/cli/shared/PluginRuntimeActionCommands.d.ts +0 -14
- package/bin/cli/shared/PluginRuntimeActionCommands.d.ts.map +0 -1
- package/bin/cli/shared/PluginRuntimeActionCommands.js.map +0 -1
- package/bin/cli/shared/PluginRuntimeRemote.js.map +0 -1
- package/bin/cli/shared/PluginRuntimeSupport.d.ts.map +0 -1
- package/bin/control/instant/InstantSessionService.d.ts.map +0 -1
- package/bin/control/instant/InstantSessionService.js.map +0 -1
- package/bin/platform/chatAuthorization/Store.d.ts +0 -31
- package/bin/platform/chatAuthorization/Store.d.ts.map +0 -1
- package/bin/platform/chatAuthorization/Store.js +0 -145
- package/bin/platform/chatAuthorization/Store.js.map +0 -1
- package/bin/process/registry/PluginRuntime.d.ts +0 -24
- package/bin/process/registry/PluginRuntime.d.ts.map +0 -1
- package/bin/process/registry/PluginRuntime.js +0 -31
- package/bin/process/registry/PluginRuntime.js.map +0 -1
- package/src/platform/chatAuthorization/Store.ts +0 -181
- package/src/process/registry/PluginRuntime.ts +0 -42
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionModelBinding.d.ts","sourceRoot":"","sources":["../../../src/model/runtime/ExecutionModelBinding.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAQH;;GAEG;AACH,MAAM,WAAW,mBAAmB;IAClC;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;IACd;;OAEG;IACH,KAAK,EAAE,MAAM,CAAC;CACf;AAED;;;;;;GAMG;AACH,wBAAsB,wBAAwB,IAAI,OAAO,CAAC,mBAAmB,EAAE,CAAC,CAY/E;AAsBD;;;;;;GAMG;AACH,wBAAgB,wBAAwB,CAAC,OAAO,EAAE,MAAM,GAAG,IAAI,CAkB9D;AAED;;;;;;GAMG;AACH,wBAAgB,gCAAgC,CAAC,WAAW,EAAE,MAAM,GAAG,IAAI,CAU1E"}
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ExecutionModelBinding:city 宿主侧执行模型绑定辅助。
|
|
3
|
+
*
|
|
4
|
+
* 职责说明(中文)
|
|
5
|
+
* - 统一承接平台模型池读取、模型候选列表构建与项目 execution.modelId 校验。
|
|
6
|
+
* - 保证 `Agent` 只接收最终 `LanguageModel`,不再承担模型池查询职责。
|
|
7
|
+
* - 让 CLI、control gateway、前台启动等宿主入口复用同一套模型绑定规则。
|
|
8
|
+
*/
|
|
9
|
+
import fs from "fs-extra";
|
|
10
|
+
import { assertProjectExecutionTarget } from "@downcity/agent";
|
|
11
|
+
import { getDowncityJsonPath } from "../../config/Paths.js";
|
|
12
|
+
import { PlatformStore } from "../../platform/store/index.js";
|
|
13
|
+
/**
|
|
14
|
+
* 读取平台模型候选列表。
|
|
15
|
+
*
|
|
16
|
+
* 关键点(中文)
|
|
17
|
+
* - 输出结果面向 CLI/Console 的模型选择界面。
|
|
18
|
+
* - provider 信息会拼到标题中,便于区分同名模型。
|
|
19
|
+
*/
|
|
20
|
+
export async function listPlatformModelChoices() {
|
|
21
|
+
const store = new PlatformStore();
|
|
22
|
+
try {
|
|
23
|
+
const models = store.listModels();
|
|
24
|
+
const providers = await store.listProviders();
|
|
25
|
+
const providerMap = new Map(providers.map((item) => [item.id, item]));
|
|
26
|
+
return models
|
|
27
|
+
.map((item) => buildPlatformModelChoice(item.id, item.providerId, providerMap))
|
|
28
|
+
.filter((item) => item !== null);
|
|
29
|
+
}
|
|
30
|
+
finally {
|
|
31
|
+
store.close();
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
function buildPlatformModelChoice(modelId, providerId, providerMap) {
|
|
35
|
+
const id = String(modelId || "").trim();
|
|
36
|
+
if (!id)
|
|
37
|
+
return null;
|
|
38
|
+
const normalizedProviderId = String(providerId || "").trim();
|
|
39
|
+
const providerType = String(providerMap.get(normalizedProviderId)?.type || "").trim();
|
|
40
|
+
const providerLabel = normalizedProviderId
|
|
41
|
+
? providerType
|
|
42
|
+
? `${normalizedProviderId} (${providerType})`
|
|
43
|
+
: normalizedProviderId
|
|
44
|
+
: "-";
|
|
45
|
+
return {
|
|
46
|
+
title: `${id} · ${providerLabel}`,
|
|
47
|
+
value: id,
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* 断言指定平台模型可用于 agent execution。
|
|
52
|
+
*
|
|
53
|
+
* 关键点(中文)
|
|
54
|
+
* - 当前只校验“存在且未暂停”。
|
|
55
|
+
* - 供应商连通性与 API Key 可用性仍交给真正创建模型实例时再校验。
|
|
56
|
+
*/
|
|
57
|
+
export function assertPlatformModelReady(modelId) {
|
|
58
|
+
const normalizedModelId = String(modelId || "").trim();
|
|
59
|
+
if (!normalizedModelId) {
|
|
60
|
+
throw new Error("execution.modelId is required");
|
|
61
|
+
}
|
|
62
|
+
const store = new PlatformStore();
|
|
63
|
+
try {
|
|
64
|
+
const model = store.getModel(normalizedModelId);
|
|
65
|
+
if (!model) {
|
|
66
|
+
throw new Error(`Model not found in platform model pool: ${normalizedModelId}`);
|
|
67
|
+
}
|
|
68
|
+
if (model.isPaused === true) {
|
|
69
|
+
throw new Error(`Model is paused: ${normalizedModelId}`);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
store.close();
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
/**
|
|
77
|
+
* 断言项目 execution 绑定已声明且目标模型可用。
|
|
78
|
+
*
|
|
79
|
+
* 关键点(中文)
|
|
80
|
+
* - 这里是 city 启动/控制面入口的宿主前置校验。
|
|
81
|
+
* - 失败时抛出稳定错误,交由 CLI 或 HTTP 层决定如何展示。
|
|
82
|
+
*/
|
|
83
|
+
export function assertProjectExecutionModelReady(projectRoot) {
|
|
84
|
+
const config = readProjectDowncityConfig(projectRoot);
|
|
85
|
+
assertProjectExecutionTarget(config);
|
|
86
|
+
const primaryModelId = String(config.execution?.type === "api" ? config.execution.modelId || "" : "").trim();
|
|
87
|
+
if (!primaryModelId) {
|
|
88
|
+
throw new Error('Invalid downcity.json: "execution" is required and must be { "type": "api", "modelId": "..." }');
|
|
89
|
+
}
|
|
90
|
+
assertPlatformModelReady(primaryModelId);
|
|
91
|
+
}
|
|
92
|
+
function readProjectDowncityConfig(projectRoot) {
|
|
93
|
+
const shipJsonPath = getDowncityJsonPath(projectRoot);
|
|
94
|
+
return fs.readJsonSync(shipJsonPath);
|
|
95
|
+
}
|
|
96
|
+
//# sourceMappingURL=ExecutionModelBinding.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ExecutionModelBinding.js","sourceRoot":"","sources":["../../../src/model/runtime/ExecutionModelBinding.ts"],"names":[],"mappings":"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"}
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 这里描述的是 CLI 与 agent daemon 之间的远程访问契约,不包含具体 HTTP 实现。
|
|
6
|
-
* -
|
|
6
|
+
* - plugin runtime 等上层模块只依赖这些协议类型,不需要感知 city/daemon 的内部实现细节。
|
|
7
7
|
* - 该文件属于 `main/city/daemon/*` 的协议边界,而不是通用 HTTP 类型目录。
|
|
8
8
|
*/
|
|
9
9
|
import type { JsonValue } from "@downcity/agent";
|
|
@@ -36,7 +36,7 @@ export type DaemonJsonApiCallParams = {
|
|
|
36
36
|
*
|
|
37
37
|
* 说明(中文)
|
|
38
38
|
* - 仅本地 IPC transport 当前会消费该参数。
|
|
39
|
-
* - 用于 `session execute`、`
|
|
39
|
+
* - 用于 `session execute`、`plugin command` 这类可能持续几十秒的请求,
|
|
40
40
|
* 避免被默认短超时误判成“Agent server 未启动”。
|
|
41
41
|
*/
|
|
42
42
|
timeoutMs?: number;
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { AgentPathRuntime,
|
|
1
|
+
import type { AgentPathRuntime, AgentPluginConfigRuntime } from "@downcity/agent";
|
|
2
2
|
/**
|
|
3
3
|
* 创建当前项目的路径能力集合。
|
|
4
4
|
*/
|
|
@@ -7,12 +7,4 @@ export declare function createAgentPathRuntime(projectRoot: string, agentIdInput
|
|
|
7
7
|
* 创建 plugin 配置持久化能力集合。
|
|
8
8
|
*/
|
|
9
9
|
export declare function createAgentPluginConfigRuntime(projectRoot: string): AgentPluginConfigRuntime;
|
|
10
|
-
/**
|
|
11
|
-
* 创建当前项目的平台能力集合。
|
|
12
|
-
*
|
|
13
|
-
* 关键点(中文)
|
|
14
|
-
* - 这里先暴露 agent 当前已经需要的最小平台读能力。
|
|
15
|
-
* - 具体平台数据仍由 city 自己管理,agent 只消费这一层接口。
|
|
16
|
-
*/
|
|
17
|
-
export declare function createAgentPlatformRuntime(): AgentPlatformRuntime;
|
|
18
10
|
//# sourceMappingURL=AgentHostRuntime.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentHostRuntime.d.ts","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,gBAAgB,EAChB,
|
|
1
|
+
{"version":3,"file":"AgentHostRuntime.d.ts","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAqBA,OAAO,KAAK,EACV,gBAAgB,EAChB,wBAAwB,EACzB,MAAM,iBAAiB,CAAC;AAGzB;;GAEG;AACH,wBAAgB,sBAAsB,CACpC,WAAW,EAAE,MAAM,EACnB,YAAY,EAAE,MAAM,GACnB,gBAAgB,CAkBlB;AAED;;GAEG;AACH,wBAAgB,8BAA8B,CAAC,WAAW,EAAE,MAAM,GAAG,wBAAwB,CAY5F"}
|
|
@@ -3,62 +3,11 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - `main/agent/*` 负责创建这些宿主能力对象,再注入到 AgentRuntime。
|
|
6
|
-
* -
|
|
7
|
-
* - 当前由 city
|
|
6
|
+
* - plugin runtimes / session / plugins 只消费这些对象,不再直接 import `main/*`。
|
|
7
|
+
* - 当前由 city 在这里统一装配路径与 plugin 配置持久化两类宿主对象。
|
|
8
8
|
*/
|
|
9
9
|
import { getCacheDirPath, getDowncityChannelDirPath, getDowncityChannelMetaPath, getDowncityChatHistoryPath, getDowncityDirPath, getDowncityMemoryDailyDirPath, getDowncityMemoryDailyPath, getDowncityMemoryLongTermPath, getDowncitySessionDirPath, getDowncitySessionRootDirPath, } from "../../config/Paths.js";
|
|
10
10
|
import { persistProjectPluginConfig } from "@downcity/agent";
|
|
11
|
-
import { PlatformStore } from "../../platform/store/index.js";
|
|
12
|
-
import { isCityPluginEnabled, setCityPluginEnabled, } from "../../platform/PluginLifecycle.js";
|
|
13
|
-
import { readChatAuthorizationConfigSync, setChatAuthorizationUserRole, writeChatAuthorizationConfig, } from "../../platform/chatAuthorization/Store.js";
|
|
14
|
-
/**
|
|
15
|
-
* 脱敏显示密钥。
|
|
16
|
-
*
|
|
17
|
-
* 关键点(中文)
|
|
18
|
-
* - channel account 列表只返回安全视图,避免在 CLI/UI 展示链路泄露明文。
|
|
19
|
-
* - 保持和现有 model provider 脱敏规则一致,减少用户心智负担。
|
|
20
|
-
*/
|
|
21
|
-
function maskSecret(value) {
|
|
22
|
-
const raw = String(value || "").trim();
|
|
23
|
-
if (!raw)
|
|
24
|
-
return undefined;
|
|
25
|
-
if (raw.length <= 8)
|
|
26
|
-
return "***";
|
|
27
|
-
return `${raw.slice(0, 4)}***${raw.slice(-4)}`;
|
|
28
|
-
}
|
|
29
|
-
/**
|
|
30
|
-
* 将存储层 channel account 转成对外安全视图。
|
|
31
|
-
*/
|
|
32
|
-
function toChannelAccountListItem(account) {
|
|
33
|
-
return {
|
|
34
|
-
id: account.id,
|
|
35
|
-
channel: account.channel,
|
|
36
|
-
name: account.name,
|
|
37
|
-
identity: account.identity,
|
|
38
|
-
owner: account.owner,
|
|
39
|
-
creator: account.creator,
|
|
40
|
-
domain: account.domain,
|
|
41
|
-
sandbox: account.sandbox === true,
|
|
42
|
-
hasBotToken: !!String(account.botToken || "").trim(),
|
|
43
|
-
hasAppId: !!String(account.appId || "").trim(),
|
|
44
|
-
hasAppSecret: !!String(account.appSecret || "").trim(),
|
|
45
|
-
botTokenMasked: maskSecret(account.botToken),
|
|
46
|
-
appIdMasked: maskSecret(account.appId),
|
|
47
|
-
appSecretMasked: maskSecret(account.appSecret),
|
|
48
|
-
createdAt: account.createdAt,
|
|
49
|
-
updatedAt: account.updatedAt,
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
/**
|
|
53
|
-
* 归一化并校验 channel account 渠道名。
|
|
54
|
-
*/
|
|
55
|
-
function normalizeChannelAccountChannel(channelInput) {
|
|
56
|
-
const channel = String(channelInput || "").trim().toLowerCase();
|
|
57
|
-
if (channel === "telegram" || channel === "feishu" || channel === "qq") {
|
|
58
|
-
return channel;
|
|
59
|
-
}
|
|
60
|
-
throw new Error(`Unsupported channel account channel: ${channelInput}`);
|
|
61
|
-
}
|
|
62
11
|
/**
|
|
63
12
|
* 创建当前项目的路径能力集合。
|
|
64
13
|
*/
|
|
@@ -96,107 +45,4 @@ export function createAgentPluginConfigRuntime(projectRoot) {
|
|
|
96
45
|
},
|
|
97
46
|
};
|
|
98
47
|
}
|
|
99
|
-
/**
|
|
100
|
-
* 创建当前项目的平台能力集合。
|
|
101
|
-
*
|
|
102
|
-
* 关键点(中文)
|
|
103
|
-
* - 这里先暴露 agent 当前已经需要的最小平台读能力。
|
|
104
|
-
* - 具体平台数据仍由 city 自己管理,agent 只消费这一层接口。
|
|
105
|
-
*/
|
|
106
|
-
export function createAgentPlatformRuntime() {
|
|
107
|
-
return {
|
|
108
|
-
getGlobalEnv: () => {
|
|
109
|
-
const store = new PlatformStore();
|
|
110
|
-
try {
|
|
111
|
-
return store.getGlobalEnvMapSync();
|
|
112
|
-
}
|
|
113
|
-
finally {
|
|
114
|
-
store.close();
|
|
115
|
-
}
|
|
116
|
-
},
|
|
117
|
-
getAgentEnv: (projectRoot) => {
|
|
118
|
-
const store = new PlatformStore();
|
|
119
|
-
try {
|
|
120
|
-
return store.getAgentEnvMapSync(projectRoot);
|
|
121
|
-
}
|
|
122
|
-
finally {
|
|
123
|
-
store.close();
|
|
124
|
-
}
|
|
125
|
-
},
|
|
126
|
-
listModels: () => {
|
|
127
|
-
const store = new PlatformStore();
|
|
128
|
-
try {
|
|
129
|
-
return store.listModels();
|
|
130
|
-
}
|
|
131
|
-
finally {
|
|
132
|
-
store.close();
|
|
133
|
-
}
|
|
134
|
-
},
|
|
135
|
-
listProviders: async () => {
|
|
136
|
-
const store = new PlatformStore();
|
|
137
|
-
try {
|
|
138
|
-
return await store.listProviders();
|
|
139
|
-
}
|
|
140
|
-
finally {
|
|
141
|
-
store.close();
|
|
142
|
-
}
|
|
143
|
-
},
|
|
144
|
-
getModel: (modelId) => {
|
|
145
|
-
const store = new PlatformStore();
|
|
146
|
-
try {
|
|
147
|
-
return store.getModel(modelId);
|
|
148
|
-
}
|
|
149
|
-
finally {
|
|
150
|
-
store.close();
|
|
151
|
-
}
|
|
152
|
-
},
|
|
153
|
-
getChannelAccount: (channelAccountId) => {
|
|
154
|
-
const store = new PlatformStore();
|
|
155
|
-
try {
|
|
156
|
-
return store.getChannelAccountSync(channelAccountId);
|
|
157
|
-
}
|
|
158
|
-
finally {
|
|
159
|
-
store.close();
|
|
160
|
-
}
|
|
161
|
-
},
|
|
162
|
-
listChannelAccounts: async () => {
|
|
163
|
-
const store = new PlatformStore();
|
|
164
|
-
try {
|
|
165
|
-
const accounts = await store.listChannelAccounts();
|
|
166
|
-
return accounts.map(toChannelAccountListItem);
|
|
167
|
-
}
|
|
168
|
-
finally {
|
|
169
|
-
store.close();
|
|
170
|
-
}
|
|
171
|
-
},
|
|
172
|
-
updateChannelAccount: async (input) => {
|
|
173
|
-
const store = new PlatformStore();
|
|
174
|
-
try {
|
|
175
|
-
await store.upsertChannelAccount({
|
|
176
|
-
...input,
|
|
177
|
-
channel: normalizeChannelAccountChannel(input.channel),
|
|
178
|
-
});
|
|
179
|
-
}
|
|
180
|
-
finally {
|
|
181
|
-
store.close();
|
|
182
|
-
}
|
|
183
|
-
},
|
|
184
|
-
removeChannelAccount: async (channelAccountId) => {
|
|
185
|
-
const store = new PlatformStore();
|
|
186
|
-
try {
|
|
187
|
-
store.removeChannelAccount(channelAccountId);
|
|
188
|
-
}
|
|
189
|
-
finally {
|
|
190
|
-
store.close();
|
|
191
|
-
}
|
|
192
|
-
},
|
|
193
|
-
readChatAuthorizationConfig: (projectRoot) => readChatAuthorizationConfigSync(projectRoot),
|
|
194
|
-
writeChatAuthorizationConfig,
|
|
195
|
-
setChatAuthorizationUserRole,
|
|
196
|
-
isPluginEnabled: (pluginName) => isCityPluginEnabled(pluginName),
|
|
197
|
-
setPluginEnabled: (pluginName, enabled) => {
|
|
198
|
-
setCityPluginEnabled(pluginName, enabled);
|
|
199
|
-
},
|
|
200
|
-
};
|
|
201
|
-
}
|
|
202
48
|
//# sourceMappingURL=AgentHostRuntime.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"AgentHostRuntime.js","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EAClB,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;
|
|
1
|
+
{"version":3,"file":"AgentHostRuntime.js","sourceRoot":"","sources":["../../../src/process/registry/AgentHostRuntime.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AACH,OAAO,EACL,eAAe,EACf,yBAAyB,EACzB,0BAA0B,EAC1B,0BAA0B,EAC1B,kBAAkB,EAClB,6BAA6B,EAC7B,0BAA0B,EAC1B,6BAA6B,EAC7B,yBAAyB,EACzB,6BAA6B,GAC9B,MAAM,mBAAmB,CAAC;AAC3B,OAAO,EAAE,0BAA0B,EAAE,MAAM,iBAAiB,CAAC;AAO7D;;GAEG;AACH,MAAM,UAAU,sBAAsB,CACpC,WAAmB,EACnB,YAAoB;IAEpB,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,MAAM,OAAO,GAAG,MAAM,CAAC,YAAY,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO;QACL,WAAW,EAAE,QAAQ;QACrB,OAAO;QACP,kBAAkB,EAAE,GAAG,EAAE,CAAC,kBAAkB,CAAC,QAAQ,CAAC;QACtD,eAAe,EAAE,GAAG,EAAE,CAAC,eAAe,CAAC,QAAQ,CAAC;QAChD,yBAAyB,EAAE,GAAG,EAAE,CAAC,yBAAyB,CAAC,QAAQ,CAAC;QACpE,0BAA0B,EAAE,GAAG,EAAE,CAAC,0BAA0B,CAAC,QAAQ,CAAC;QACtE,0BAA0B,EAAE,CAAC,SAAS,EAAE,EAAE,CAAC,0BAA0B,CAAC,QAAQ,EAAE,SAAS,CAAC;QAC1F,6BAA6B,EAAE,GAAG,EAAE,CAAC,6BAA6B,CAAC,QAAQ,CAAC;QAC5E,6BAA6B,EAAE,GAAG,EAAE,CAAC,6BAA6B,CAAC,QAAQ,CAAC;QAC5E,0BAA0B,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,0BAA0B,CAAC,QAAQ,EAAE,IAAI,CAAC;QAChF,6BAA6B,EAAE,GAAG,EAAE,CAAC,6BAA6B,CAAC,QAAQ,EAAE,OAAO,CAAC;QACrF,yBAAyB,EAAE,CAAC,SAAS,EAAE,EAAE,CACvC,yBAAyB,CAAC,QAAQ,EAAE,OAAO,EAAE,SAAS,CAAC;KACtC,CAAC;AACxB,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,8BAA8B,CAAC,WAAmB;IAChE,MAAM,QAAQ,GAAG,MAAM,CAAC,WAAW,IAAI,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAClD,OAAO;QACL,KAAK,CAAC,qBAAqB,CAAC,OAA8C;YACxE,OAAO,0BAA0B,CAAC;gBAChC,WAAW,EAAE,QAAQ;gBACrB,QAAQ,EAAE;oBACR,GAAG,CAAC,OAAO,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,OAAO,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;iBAC9C;aACF,CAAC,CAAC;QACL,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@downcity/city",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.39",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Downcity City 平台 — CLI、daemon 管理、Console 网关、能力平台",
|
|
6
6
|
"bin": {
|
|
@@ -36,7 +36,8 @@
|
|
|
36
36
|
"prompts": "^2.4.0",
|
|
37
37
|
"ws": "^8.19.0",
|
|
38
38
|
"zod": "^3.24.0",
|
|
39
|
-
"@downcity/agent": "^1.1.
|
|
39
|
+
"@downcity/agent": "^1.1.43",
|
|
40
|
+
"@downcity/plugins": "^1.0.4"
|
|
40
41
|
},
|
|
41
42
|
"devDependencies": {
|
|
42
43
|
"@types/better-sqlite3": "^7.6.13",
|
package/src/cli/Index.ts
CHANGED
|
@@ -14,9 +14,13 @@ import { basename, dirname, join } from "path";
|
|
|
14
14
|
import { createRequire } from "module";
|
|
15
15
|
import { fileURLToPath } from "url";
|
|
16
16
|
import { Command, Option } from "commander";
|
|
17
|
-
import {
|
|
17
|
+
import {
|
|
18
|
+
listPluginsWithoutLifecycle,
|
|
19
|
+
registerPluginActionCommandsForCli,
|
|
20
|
+
} from "@downcity/agent";
|
|
21
|
+
import { createBuiltinPlugins } from "@downcity/plugins";
|
|
18
22
|
import { registerPluginsCommand } from "./shared/Plugins.js";
|
|
19
|
-
import {
|
|
23
|
+
import { registerManagedPluginCommandsForCli } from "./shared/ManagedPluginActionCommands.js";
|
|
20
24
|
import { registerControlPlaneCommands } from "./control-plane/ControlPlaneCommand.js";
|
|
21
25
|
import { registerAgentCommands } from "./shared/IndexAgentCommand.js";
|
|
22
26
|
import { registerEnvCommand } from "./shared/Env.js";
|
|
@@ -67,6 +71,7 @@ const installedAgentVersion = resolveInstalledAgentVersion();
|
|
|
67
71
|
|
|
68
72
|
const program = new Command();
|
|
69
73
|
const argv = process.argv.slice(2);
|
|
74
|
+
const builtinPlugins = createBuiltinPlugins();
|
|
70
75
|
|
|
71
76
|
program
|
|
72
77
|
.name(basename(process.argv[1] || "downcity"))
|
|
@@ -95,10 +100,13 @@ registerChatCommand(program);
|
|
|
95
100
|
|
|
96
101
|
registerPluginsCommand(program);
|
|
97
102
|
|
|
98
|
-
//
|
|
99
|
-
|
|
103
|
+
// 受 agent 托管的 plugin 命令统一注册(chat / task / memory / shell / future managed plugins)
|
|
104
|
+
registerManagedPluginCommandsForCli(program, builtinPlugins);
|
|
100
105
|
// 插件命令统一注册(skill / asr / tts / future plugins)
|
|
101
|
-
|
|
106
|
+
registerPluginActionCommandsForCli({
|
|
107
|
+
program,
|
|
108
|
+
plugins: listPluginsWithoutLifecycle(builtinPlugins),
|
|
109
|
+
});
|
|
102
110
|
|
|
103
111
|
program.showHelpAfterError();
|
|
104
112
|
program.showSuggestionAfterError();
|
|
@@ -16,7 +16,7 @@ import { printResult } from "@/utils/cli/CliOutput.js";
|
|
|
16
16
|
import {
|
|
17
17
|
resolveProjectRootByAgentName,
|
|
18
18
|
validateAgentProjectRoot,
|
|
19
|
-
} from "../shared/
|
|
19
|
+
} from "../shared/PluginTargetSupport.js";
|
|
20
20
|
import { listRegisteredAgentsForCli } from "./AgentSelection.js";
|
|
21
21
|
import {
|
|
22
22
|
formatCliBearerHeaderValue,
|
|
@@ -81,7 +81,7 @@ function readAgentModelId(config: DowncityConfig | null): string {
|
|
|
81
81
|
|
|
82
82
|
function readAgentChannelSummaries(config: DowncityConfig | null): string[] {
|
|
83
83
|
const accountsById = loadChannelAccountMap();
|
|
84
|
-
const channels = config?.
|
|
84
|
+
const channels = config?.plugins?.chat?.channels || {};
|
|
85
85
|
const summaries: string[] = [];
|
|
86
86
|
for (const channel of CHAT_CHANNELS) {
|
|
87
87
|
const channelConfig = channels[channel];
|
|
@@ -101,7 +101,7 @@ function readAgentChannelSummaries(config: DowncityConfig | null): string[] {
|
|
|
101
101
|
|
|
102
102
|
function findDanglingChannelAccounts(config: DowncityConfig | null): DanglingChannelAccount[] {
|
|
103
103
|
const accountsById = loadChannelAccountMap();
|
|
104
|
-
const channels = config?.
|
|
104
|
+
const channels = config?.plugins?.chat?.channels || {};
|
|
105
105
|
const dangling: DanglingChannelAccount[] = [];
|
|
106
106
|
for (const channel of CHAT_CHANNELS) {
|
|
107
107
|
const accountId = String(channels[channel]?.channelAccountId || "").trim();
|
|
@@ -453,7 +453,7 @@ async function connectAgentChannels(
|
|
|
453
453
|
): Promise<AgentManagerAgentSummary> {
|
|
454
454
|
const shipJsonPath = getDowncityJsonPath(agent.projectRoot);
|
|
455
455
|
const raw = fs.readJsonSync(shipJsonPath) as DowncityConfig;
|
|
456
|
-
const chatConfig = (raw.
|
|
456
|
+
const chatConfig = (((raw.plugins ??= {}) as NonNullable<DowncityConfig["plugins"]>).chat ??= {});
|
|
457
457
|
const channelConfigs = chatConfig.channels ??= {};
|
|
458
458
|
const dangling = findDanglingChannelAccounts(raw);
|
|
459
459
|
if (dangling.length > 0) {
|
package/src/cli/agent/Init.ts
CHANGED
|
@@ -18,14 +18,16 @@ import fg from "fast-glob";
|
|
|
18
18
|
import { getProfileMdPath, getDowncityJsonPath, getSoulMdPath } from "@/config/Paths.js";
|
|
19
19
|
import {
|
|
20
20
|
initializeAgentProject,
|
|
21
|
-
listPlatformModelChoices,
|
|
22
21
|
normalizeDefaultAgentName,
|
|
23
22
|
} from "@downcity/agent";
|
|
24
23
|
import type { AgentProjectChannel } from "@downcity/agent";
|
|
25
24
|
import type { ExecutionBindingConfig } from "@downcity/agent";
|
|
26
25
|
import { emitCliBlock, emitCliList } from "../shared/CliReporter.js";
|
|
27
26
|
import { CliError } from "../shared/CliError.js";
|
|
28
|
-
import {
|
|
27
|
+
import {
|
|
28
|
+
assertPlatformModelReady,
|
|
29
|
+
listPlatformModelChoices,
|
|
30
|
+
} from "@/model/runtime/ExecutionModelBinding.js";
|
|
29
31
|
|
|
30
32
|
type InitPromptResponse = {
|
|
31
33
|
name?: string;
|
|
@@ -68,9 +70,8 @@ export async function initCommand(
|
|
|
68
70
|
const existingProfileMd = fs.existsSync(getProfileMdPath(projectRoot));
|
|
69
71
|
const existingSoulMd = fs.existsSync(getSoulMdPath(projectRoot));
|
|
70
72
|
const existingShipJson = fs.existsSync(getDowncityJsonPath(projectRoot));
|
|
71
|
-
const
|
|
72
|
-
const
|
|
73
|
-
const platformModelIds = platformModelChoices.map((item) => item.value);
|
|
73
|
+
const modelChoices = await listPlatformModelChoices();
|
|
74
|
+
const modelChoiceIds = modelChoices.map((item) => item.value);
|
|
74
75
|
|
|
75
76
|
// 关键点(中文):已存在的 PROFILE.md 永远不覆盖,只在 downcity.json 已存在时询问覆盖。
|
|
76
77
|
if (existingShipJson) {
|
|
@@ -107,7 +108,7 @@ export async function initCommand(
|
|
|
107
108
|
type: "select",
|
|
108
109
|
name: "primaryModelId",
|
|
109
110
|
message: "Select primary model (from platform model pool)",
|
|
110
|
-
choices:
|
|
111
|
+
choices: modelChoices,
|
|
111
112
|
initial: 0,
|
|
112
113
|
},
|
|
113
114
|
{
|
|
@@ -128,7 +129,7 @@ export async function initCommand(
|
|
|
128
129
|
String(response.name || "").trim() || defaultAgentName;
|
|
129
130
|
const primaryModelId =
|
|
130
131
|
String(response.primaryModelId || "").trim() || "default";
|
|
131
|
-
if (
|
|
132
|
+
if (modelChoiceIds.length === 0) {
|
|
132
133
|
throw new CliError({
|
|
133
134
|
title: "Platform model pool is empty",
|
|
134
135
|
note: "Please configure at least one model first.",
|
|
@@ -139,6 +140,7 @@ export async function initCommand(
|
|
|
139
140
|
type: "api",
|
|
140
141
|
modelId: primaryModelId,
|
|
141
142
|
};
|
|
143
|
+
assertPlatformModelReady(primaryModelId);
|
|
142
144
|
const selectedChannels = Array.isArray(response.channels)
|
|
143
145
|
? (response.channels as AgentProjectChannel[])
|
|
144
146
|
: [];
|
|
@@ -150,7 +152,6 @@ export async function initCommand(
|
|
|
150
152
|
channels: selectedChannels,
|
|
151
153
|
forceOverwriteShipJson: allowOverwrite,
|
|
152
154
|
},
|
|
153
|
-
platform,
|
|
154
155
|
);
|
|
155
156
|
|
|
156
157
|
const createdItems: string[] = [];
|
|
@@ -208,7 +209,7 @@ export async function initCommand(
|
|
|
208
209
|
facts: [
|
|
209
210
|
{
|
|
210
211
|
label: "Bind",
|
|
211
|
-
value: "
|
|
212
|
+
value: "plugins.chat.channels.feishu.channelAccountId",
|
|
212
213
|
},
|
|
213
214
|
{
|
|
214
215
|
label: "Manage",
|
|
@@ -223,7 +224,7 @@ export async function initCommand(
|
|
|
223
224
|
facts: [
|
|
224
225
|
{
|
|
225
226
|
label: "Bind",
|
|
226
|
-
value: "
|
|
227
|
+
value: "plugins.chat.channels.telegram.channelAccountId",
|
|
227
228
|
},
|
|
228
229
|
{
|
|
229
230
|
label: "Manage",
|
|
@@ -238,7 +239,7 @@ export async function initCommand(
|
|
|
238
239
|
facts: [
|
|
239
240
|
{
|
|
240
241
|
label: "Bind",
|
|
241
|
-
value: "
|
|
242
|
+
value: "plugins.chat.channels.qq.channelAccountId",
|
|
242
243
|
},
|
|
243
244
|
{
|
|
244
245
|
label: "Manage",
|
|
@@ -267,17 +268,17 @@ export async function initCommand(
|
|
|
267
268
|
|
|
268
269
|
if (selectedChannels.includes("telegram")) {
|
|
269
270
|
nextSteps.push(
|
|
270
|
-
"Bind
|
|
271
|
+
"Bind plugins.chat.channels.telegram.channelAccountId to an existing channel account",
|
|
271
272
|
);
|
|
272
273
|
}
|
|
273
274
|
if (selectedChannels.includes("feishu")) {
|
|
274
275
|
nextSteps.push(
|
|
275
|
-
"Bind
|
|
276
|
+
"Bind plugins.chat.channels.feishu.channelAccountId to an existing channel account",
|
|
276
277
|
);
|
|
277
278
|
}
|
|
278
279
|
if (selectedChannels.includes("qq")) {
|
|
279
280
|
nextSteps.push(
|
|
280
|
-
"Bind
|
|
281
|
+
"Bind plugins.chat.channels.qq.channelAccountId to an existing channel account",
|
|
281
282
|
);
|
|
282
283
|
}
|
|
283
284
|
nextSteps.push('Run "city agent start" to start the agent');
|
package/src/cli/agent/Restart.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { startDaemonProcess, stopDaemonProcess } from "@/process/daemon/Manager.
|
|
|
14
14
|
import type { StartOptions } from "@downcity/agent";
|
|
15
15
|
import { emitCliBlock } from "../shared/CliReporter.js";
|
|
16
16
|
import { resolveAgentName } from "../shared/IndexSupport.js";
|
|
17
|
-
import { checkAgentPreflight } from "../shared/
|
|
17
|
+
import { checkAgentPreflight } from "../shared/PluginTargetSupport.js";
|
|
18
18
|
import { CliError } from "../shared/CliError.js";
|
|
19
19
|
|
|
20
20
|
/**
|
package/src/cli/agent/Run.ts
CHANGED
|
@@ -13,13 +13,14 @@
|
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
import {
|
|
15
15
|
Agent,
|
|
16
|
+
loadDowncityConfig,
|
|
16
17
|
loadStaticSystemPrompts,
|
|
17
18
|
shellTools,
|
|
18
19
|
StaticPromptCatalog,
|
|
19
20
|
} from "@downcity/agent";
|
|
21
|
+
import { createBuiltinPlugins } from "@downcity/plugins";
|
|
20
22
|
import type { StartOptions } from "@downcity/agent";
|
|
21
23
|
import { CliError } from "../shared/CliError.js";
|
|
22
|
-
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
23
24
|
import { createRuntimeModel } from "@/model/runtime/CreateRuntimeModel.js";
|
|
24
25
|
import { resolveAgentName } from "../shared/IndexSupport.js";
|
|
25
26
|
|
|
@@ -38,7 +39,6 @@ export async function runCommand(
|
|
|
38
39
|
options: StartOptions,
|
|
39
40
|
): Promise<void> {
|
|
40
41
|
const projectRoot = path.resolve(cwd);
|
|
41
|
-
const platform = createAgentPlatformRuntime();
|
|
42
42
|
// 端口解析(中文):允许 number / string;空值返回 undefined 以便走配置回退链。
|
|
43
43
|
const parsePort = (
|
|
44
44
|
value: string | number | undefined,
|
|
@@ -69,29 +69,23 @@ export async function runCommand(
|
|
|
69
69
|
const host = (options.host ?? "0.0.0.0").trim();
|
|
70
70
|
const agentName = resolveAgentName(projectRoot);
|
|
71
71
|
let currentSystems = loadStaticSystemPrompts(projectRoot);
|
|
72
|
+
const config = loadDowncityConfig(projectRoot);
|
|
73
|
+
const model = await createRuntimeModel({
|
|
74
|
+
config,
|
|
75
|
+
});
|
|
72
76
|
|
|
73
77
|
const agent = new Agent({
|
|
74
78
|
id: agentName,
|
|
75
79
|
path: projectRoot,
|
|
76
80
|
instruction: currentSystems,
|
|
77
81
|
tools: shellTools,
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
useBuiltinPlugins: true,
|
|
81
|
-
configureSession: async (session) => {
|
|
82
|
-
const model = await createRuntimeModel({
|
|
83
|
-
config: agent.getRuntime().config,
|
|
84
|
-
platform,
|
|
85
|
-
});
|
|
86
|
-
await session.set({
|
|
87
|
-
model,
|
|
88
|
-
});
|
|
89
|
-
},
|
|
82
|
+
plugins: createBuiltinPlugins(),
|
|
83
|
+
model,
|
|
90
84
|
});
|
|
91
85
|
|
|
92
86
|
const promptCatalog = new StaticPromptCatalog({
|
|
93
87
|
rootPath: projectRoot,
|
|
94
|
-
logger: agent.
|
|
88
|
+
logger: agent.getLogger(),
|
|
95
89
|
getCurrentSystems: () => currentSystems,
|
|
96
90
|
applySystems: (nextSystems) => {
|
|
97
91
|
currentSystems = nextSystems;
|
|
@@ -111,7 +105,7 @@ export async function runCommand(
|
|
|
111
105
|
host,
|
|
112
106
|
},
|
|
113
107
|
rpc: true,
|
|
114
|
-
|
|
108
|
+
plugins: true,
|
|
115
109
|
});
|
|
116
110
|
|
|
117
111
|
const server = startResult.http?.server;
|
|
@@ -120,10 +114,10 @@ export async function runCommand(
|
|
|
120
114
|
throw new Error("Agent start did not return expected HTTP/RPC bindings");
|
|
121
115
|
}
|
|
122
116
|
|
|
123
|
-
const agentLogger = agent.
|
|
117
|
+
const agentLogger = agent.getLogger();
|
|
124
118
|
|
|
125
119
|
// 处理进程信号
|
|
126
|
-
// 停机顺序(中文):
|
|
120
|
+
// 停机顺序(中文):plugin runtimes -> API server -> flush logs。
|
|
127
121
|
let isShuttingDown = false;
|
|
128
122
|
const shutdown = async (signal: string) => {
|
|
129
123
|
if (isShuttingDown) return;
|
package/src/cli/agent/Start.ts
CHANGED
|
@@ -18,7 +18,7 @@ import { buildRunArgsFromOptions } from "@/process/daemon/CliArgs.js";
|
|
|
18
18
|
import type { StartOptions } from "@downcity/agent";
|
|
19
19
|
import { emitCliBlock } from "../shared/CliReporter.js";
|
|
20
20
|
import { resolveAgentName } from "../shared/IndexSupport.js";
|
|
21
|
-
import { checkAgentPreflight } from "../shared/
|
|
21
|
+
import { checkAgentPreflight } from "../shared/PluginTargetSupport.js";
|
|
22
22
|
import { CliError } from "../shared/CliError.js";
|
|
23
23
|
|
|
24
24
|
/**
|