@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.
Files changed (153) hide show
  1. package/README.md +5 -11
  2. package/bin/cli/Index.js +10 -5
  3. package/bin/cli/Index.js.map +1 -1
  4. package/bin/cli/agent/AgentChat.js +1 -1
  5. package/bin/cli/agent/AgentChat.js.map +1 -1
  6. package/bin/cli/agent/AgentManager.js +3 -3
  7. package/bin/cli/agent/AgentManager.js.map +1 -1
  8. package/bin/cli/agent/Init.d.ts.map +1 -1
  9. package/bin/cli/agent/Init.js +14 -14
  10. package/bin/cli/agent/Init.js.map +1 -1
  11. package/bin/cli/agent/Restart.js +1 -1
  12. package/bin/cli/agent/Restart.js.map +1 -1
  13. package/bin/cli/agent/Run.d.ts.map +1 -1
  14. package/bin/cli/agent/Run.js +12 -19
  15. package/bin/cli/agent/Run.js.map +1 -1
  16. package/bin/cli/agent/Start.js +1 -1
  17. package/bin/cli/agent/Start.js.map +1 -1
  18. package/bin/cli/control-plane/ControlPlaneProcess.d.ts.map +1 -1
  19. package/bin/cli/control-plane/ControlPlaneProcess.js +2 -3
  20. package/bin/cli/control-plane/ControlPlaneProcess.js.map +1 -1
  21. package/bin/cli/model/ModelSupport.d.ts +1 -1
  22. package/bin/cli/model/ModelSupport.d.ts.map +1 -1
  23. package/bin/cli/model/ModelSupport.js +1 -1
  24. package/bin/cli/model/ModelSupport.js.map +1 -1
  25. package/bin/cli/shared/Chat.d.ts +1 -1
  26. package/bin/cli/shared/Chat.js +1 -1
  27. package/bin/cli/shared/ChatAuth.d.ts.map +1 -1
  28. package/bin/cli/shared/ChatAuth.js +5 -7
  29. package/bin/cli/shared/ChatAuth.js.map +1 -1
  30. package/bin/cli/shared/ChatManager.d.ts +1 -1
  31. package/bin/cli/shared/ChatManager.d.ts.map +1 -1
  32. package/bin/cli/shared/ChatManager.js +20 -21
  33. package/bin/cli/shared/ChatManager.js.map +1 -1
  34. package/bin/cli/shared/Config.js +1 -1
  35. package/bin/cli/shared/Config.js.map +1 -1
  36. package/bin/cli/shared/ManagedPluginActionCommands.d.ts +15 -0
  37. package/bin/cli/shared/ManagedPluginActionCommands.d.ts.map +1 -0
  38. package/bin/cli/shared/{PluginRuntimeActionCommands.js → ManagedPluginActionCommands.js} +13 -12
  39. package/bin/cli/shared/ManagedPluginActionCommands.js.map +1 -0
  40. package/bin/cli/shared/{PluginRuntimeRemote.d.ts → ManagedPluginRemote.d.ts} +6 -6
  41. package/bin/cli/shared/{PluginRuntimeRemote.d.ts.map → ManagedPluginRemote.d.ts.map} +1 -1
  42. package/bin/cli/shared/{PluginRuntimeRemote.js → ManagedPluginRemote.js} +14 -14
  43. package/bin/cli/shared/ManagedPluginRemote.js.map +1 -0
  44. package/bin/cli/shared/PluginScheduleCommand.d.ts +3 -2
  45. package/bin/cli/shared/PluginScheduleCommand.d.ts.map +1 -1
  46. package/bin/cli/shared/PluginScheduleCommand.js +12 -11
  47. package/bin/cli/shared/PluginScheduleCommand.js.map +1 -1
  48. package/bin/cli/shared/{PluginRuntimeSupport.d.ts → PluginTargetSupport.d.ts} +7 -7
  49. package/bin/cli/shared/PluginTargetSupport.d.ts.map +1 -0
  50. package/bin/cli/shared/{PluginRuntimeSupport.js → PluginTargetSupport.js} +7 -8
  51. package/bin/cli/shared/{PluginRuntimeSupport.js.map → PluginTargetSupport.js.map} +1 -1
  52. package/bin/cli/shared/Plugins.d.ts.map +1 -1
  53. package/bin/cli/shared/Plugins.js +30 -21
  54. package/bin/cli/shared/Plugins.js.map +1 -1
  55. package/bin/cli/shared/PortHints.js +1 -1
  56. package/bin/config/DowncitySchema.d.ts.map +1 -1
  57. package/bin/config/DowncitySchema.js +2 -8
  58. package/bin/config/DowncitySchema.js.map +1 -1
  59. package/bin/config/Paths.d.ts +2 -2
  60. package/bin/config/Paths.js +2 -2
  61. package/bin/control/AgentStatusApiRoutes.js +2 -2
  62. package/bin/control/AgentStatusApiRoutes.js.map +1 -1
  63. package/bin/control/ChannelAccountApiRoutes.d.ts.map +1 -1
  64. package/bin/control/ChannelAccountApiRoutes.js +6 -7
  65. package/bin/control/ChannelAccountApiRoutes.js.map +1 -1
  66. package/bin/control/ControlGateway.d.ts.map +1 -1
  67. package/bin/control/ControlGateway.js +3 -2
  68. package/bin/control/ControlGateway.js.map +1 -1
  69. package/bin/control/PluginApiRoutes.d.ts.map +1 -1
  70. package/bin/control/PluginApiRoutes.js +38 -30
  71. package/bin/control/PluginApiRoutes.js.map +1 -1
  72. package/bin/control/gateway/AgentActions.d.ts.map +1 -1
  73. package/bin/control/gateway/AgentActions.js +16 -11
  74. package/bin/control/gateway/AgentActions.js.map +1 -1
  75. package/bin/control/gateway/AgentCatalog.js +1 -1
  76. package/bin/control/gateway/AgentCatalog.js.map +1 -1
  77. package/bin/control/instant/InstantApiRoutes.d.ts +3 -3
  78. package/bin/control/instant/InstantApiRoutes.d.ts.map +1 -1
  79. package/bin/control/instant/InstantApiRoutes.js +5 -5
  80. package/bin/control/instant/InstantApiRoutes.js.map +1 -1
  81. package/bin/control/instant/{InstantSessionService.d.ts → InstantSessionRunner.d.ts} +7 -7
  82. package/bin/control/instant/InstantSessionRunner.d.ts.map +1 -0
  83. package/bin/control/instant/{InstantSessionService.js → InstantSessionRunner.js} +4 -4
  84. package/bin/control/instant/InstantSessionRunner.js.map +1 -0
  85. package/bin/http/auth/RoutePolicy.js +4 -4
  86. package/bin/http/auth/RoutePolicy.js.map +1 -1
  87. package/bin/model/runtime/CreateRuntimeModel.d.ts +2 -10
  88. package/bin/model/runtime/CreateRuntimeModel.d.ts.map +1 -1
  89. package/bin/model/runtime/CreateRuntimeModel.js +1 -16
  90. package/bin/model/runtime/CreateRuntimeModel.js.map +1 -1
  91. package/bin/model/runtime/ExecutionModelBinding.d.ts +46 -0
  92. package/bin/model/runtime/ExecutionModelBinding.d.ts.map +1 -0
  93. package/bin/model/runtime/ExecutionModelBinding.js +96 -0
  94. package/bin/model/runtime/ExecutionModelBinding.js.map +1 -0
  95. package/bin/process/daemon/Api.d.ts +2 -2
  96. package/bin/process/daemon/Api.js +1 -1
  97. package/bin/process/registry/AgentHostRuntime.d.ts +1 -9
  98. package/bin/process/registry/AgentHostRuntime.d.ts.map +1 -1
  99. package/bin/process/registry/AgentHostRuntime.js +2 -156
  100. package/bin/process/registry/AgentHostRuntime.js.map +1 -1
  101. package/package.json +3 -2
  102. package/src/cli/Index.ts +13 -5
  103. package/src/cli/agent/AgentChat.ts +1 -1
  104. package/src/cli/agent/AgentManager.ts +3 -3
  105. package/src/cli/agent/Init.ts +15 -14
  106. package/src/cli/agent/Restart.ts +1 -1
  107. package/src/cli/agent/Run.ts +12 -18
  108. package/src/cli/agent/Start.ts +1 -1
  109. package/src/cli/control-plane/ControlPlaneProcess.ts +2 -3
  110. package/src/cli/model/ModelSupport.ts +1 -1
  111. package/src/cli/shared/Chat.ts +1 -1
  112. package/src/cli/shared/ChatAuth.ts +10 -11
  113. package/src/cli/shared/ChatManager.ts +21 -22
  114. package/src/cli/shared/Config.ts +1 -1
  115. package/src/cli/shared/{PluginRuntimeActionCommands.ts → ManagedPluginActionCommands.ts} +18 -15
  116. package/src/cli/shared/{PluginRuntimeRemote.ts → ManagedPluginRemote.ts} +15 -15
  117. package/src/cli/shared/PluginScheduleCommand.ts +12 -11
  118. package/src/cli/shared/{PluginRuntimeSupport.ts → PluginTargetSupport.ts} +8 -9
  119. package/src/cli/shared/Plugins.ts +38 -28
  120. package/src/cli/shared/PortHints.ts +1 -1
  121. package/src/config/DowncitySchema.ts +2 -8
  122. package/src/config/Paths.ts +2 -2
  123. package/src/control/AgentStatusApiRoutes.ts +5 -5
  124. package/src/control/ChannelAccountApiRoutes.ts +6 -7
  125. package/src/control/ControlGateway.ts +3 -2
  126. package/src/control/PluginApiRoutes.ts +42 -32
  127. package/src/control/gateway/AgentActions.ts +16 -11
  128. package/src/control/gateway/AgentCatalog.ts +1 -1
  129. package/src/control/instant/InstantApiRoutes.ts +8 -8
  130. package/src/control/instant/{InstantSessionService.ts → InstantSessionRunner.ts} +7 -7
  131. package/src/http/auth/RoutePolicy.ts +4 -4
  132. package/src/model/runtime/CreateRuntimeModel.ts +1 -26
  133. package/src/model/runtime/ExecutionModelBinding.ts +120 -0
  134. package/src/process/daemon/Api.ts +2 -2
  135. package/src/process/registry/AgentHostRuntime.ts +2 -164
  136. package/tsconfig.json +2 -1
  137. package/bin/cli/shared/PluginRuntimeActionCommands.d.ts +0 -14
  138. package/bin/cli/shared/PluginRuntimeActionCommands.d.ts.map +0 -1
  139. package/bin/cli/shared/PluginRuntimeActionCommands.js.map +0 -1
  140. package/bin/cli/shared/PluginRuntimeRemote.js.map +0 -1
  141. package/bin/cli/shared/PluginRuntimeSupport.d.ts.map +0 -1
  142. package/bin/control/instant/InstantSessionService.d.ts.map +0 -1
  143. package/bin/control/instant/InstantSessionService.js.map +0 -1
  144. package/bin/platform/chatAuthorization/Store.d.ts +0 -31
  145. package/bin/platform/chatAuthorization/Store.d.ts.map +0 -1
  146. package/bin/platform/chatAuthorization/Store.js +0 -145
  147. package/bin/platform/chatAuthorization/Store.js.map +0 -1
  148. package/bin/process/registry/PluginRuntime.d.ts +0 -24
  149. package/bin/process/registry/PluginRuntime.d.ts.map +0 -1
  150. package/bin/process/registry/PluginRuntime.js +0 -31
  151. package/bin/process/registry/PluginRuntime.js.map +0 -1
  152. package/src/platform/chatAuthorization/Store.ts +0 -181
  153. 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":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAAE,MAAM,U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IAAI,KAAK,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,OAAO,IAAI,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;IAC7G,IAAI,CAAC,cAAc,EAAE,CAAC;QACpB,MAAM,IAAI,KAAK,CACb,gGAAgG,CACjG,CAAC;IACJ,CAAC;IACD,wBAAwB,CAAC,cAAc,CAAC,CAAC;AAC3C,CAAC;AAED,SAAS,yBAAyB,CAAC,WAAmB;IACpD,MAAM,YAAY,GAAG,mBAAmB,CAAC,WAAW,CAAC,CAAC;IACtD,OAAO,EAAE,CAAC,YAAY,CAAC,YAAY,CAAmB,CAAC;AACzD,CAAC"}
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里描述的是 CLI 与 agent daemon 之间的远程访问契约,不包含具体 HTTP 实现。
6
- * - service 等上层模块只依赖这些协议类型,不需要感知 city/daemon 的内部实现细节。
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`、`service command` 这类可能持续几十秒的请求,
39
+ * - 用于 `session execute`、`plugin command` 这类可能持续几十秒的请求,
40
40
  * 避免被默认短超时误判成“Agent server 未启动”。
41
41
  */
42
42
  timeoutMs?: number;
@@ -3,7 +3,7 @@
3
3
  *
4
4
  * 关键点(中文)
5
5
  * - 这里描述的是 CLI 与 agent daemon 之间的远程访问契约,不包含具体 HTTP 实现。
6
- * - service 等上层模块只依赖这些协议类型,不需要感知 city/daemon 的内部实现细节。
6
+ * - plugin runtime 等上层模块只依赖这些协议类型,不需要感知 city/daemon 的内部实现细节。
7
7
  * - 该文件属于 `main/city/daemon/*` 的协议边界,而不是通用 HTTP 类型目录。
8
8
  */
9
9
  export {};
@@ -1,4 +1,4 @@
1
- import type { AgentPathRuntime, AgentPlatformRuntime, AgentPluginConfigRuntime } from "@downcity/agent";
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,oBAAoB,EACpB,wBAAwB,EAIzB,MAAM,iBAAiB,CAAC;AAkEzB;;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;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,IAAI,oBAAoB,CAsFjE"}
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
- * - services / session / plugins 只消费这些对象,不再直接 import `main/*`。
7
- * - 当前由 city 在这里统一装配路径、plugin 配置持久化与平台能力三类宿主对象。
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,0BAA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AE,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.29",
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.32"
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 { registerAllPluginsForCli } from "@downcity/agent";
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 { registerAllRuntimePluginsForCli } from "./shared/PluginRuntimeActionCommands.js";
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
- // runtime plugin 命令统一注册(chat / task / memory / shell / future runtime plugins)
99
- registerAllRuntimePluginsForCli(program);
103
+ // agent 托管的 plugin 命令统一注册(chat / task / memory / shell / future managed plugins)
104
+ registerManagedPluginCommandsForCli(program, builtinPlugins);
100
105
  // 插件命令统一注册(skill / asr / tts / future plugins)
101
- registerAllPluginsForCli(program);
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/PluginRuntimeSupport.js";
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?.services?.chat?.channels || {};
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?.services?.chat?.channels || {};
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.services ??= {}).chat ??= {};
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) {
@@ -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 { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
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 platform = createAgentPlatformRuntime();
72
- const platformModelChoices = await listPlatformModelChoices(platform);
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: platformModelChoices,
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 (platformModelIds.length === 0) {
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: "services.chat.channels.feishu.channelAccountId",
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: "services.chat.channels.telegram.channelAccountId",
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: "services.chat.channels.qq.channelAccountId",
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 services.chat.channels.telegram.channelAccountId to an existing channel account",
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 services.chat.channels.feishu.channelAccountId to an existing channel account",
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 services.chat.channels.qq.channelAccountId to an existing channel account",
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');
@@ -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/PluginRuntimeSupport.js";
17
+ import { checkAgentPreflight } from "../shared/PluginTargetSupport.js";
18
18
  import { CliError } from "../shared/CliError.js";
19
19
 
20
20
  /**
@@ -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
- platform,
79
- useBuiltinRuntimePlugins: true,
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.getRuntime().logger,
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
- runtimePlugins: true,
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.getRuntime().logger;
117
+ const agentLogger = agent.getLogger();
124
118
 
125
119
  // 处理进程信号
126
- // 停机顺序(中文):runtime plugins -> API server -> flush logs。
120
+ // 停机顺序(中文):plugin runtimes -> API server -> flush logs。
127
121
  let isShuttingDown = false;
128
122
  const shutdown = async (signal: string) => {
129
123
  if (isShuttingDown) return;
@@ -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/PluginRuntimeSupport.js";
21
+ import { checkAgentPreflight } from "../shared/PluginTargetSupport.js";
22
22
  import { CliError } from "../shared/CliError.js";
23
23
 
24
24
  /**