@downcity/city 1.1.32 → 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/bin/cli/Index.js +8 -3
- package/bin/cli/Index.js.map +1 -1
- package/bin/cli/agent/Init.d.ts.map +1 -1
- package/bin/cli/agent/Init.js +8 -8
- package/bin/cli/agent/Init.js.map +1 -1
- package/bin/cli/agent/Run.d.ts.map +1 -1
- package/bin/cli/agent/Run.js +8 -14
- package/bin/cli/agent/Run.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/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.map +1 -1
- package/bin/cli/shared/ChatManager.js +2 -3
- package/bin/cli/shared/ChatManager.js.map +1 -1
- package/bin/cli/shared/ManagedPluginActionCommands.d.ts +2 -1
- package/bin/cli/shared/ManagedPluginActionCommands.d.ts.map +1 -1
- package/bin/cli/shared/ManagedPluginActionCommands.js +5 -4
- package/bin/cli/shared/ManagedPluginActionCommands.js.map +1 -1
- 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 +11 -10
- package/bin/cli/shared/PluginScheduleCommand.js.map +1 -1
- package/bin/cli/shared/PluginTargetSupport.d.ts +4 -4
- package/bin/cli/shared/PluginTargetSupport.d.ts.map +1 -1
- package/bin/cli/shared/PluginTargetSupport.js +4 -5
- package/bin/cli/shared/PluginTargetSupport.js.map +1 -1
- package/bin/cli/shared/Plugins.d.ts.map +1 -1
- package/bin/cli/shared/Plugins.js +12 -6
- package/bin/cli/shared/Plugins.js.map +1 -1
- package/bin/control/ChannelAccountApiRoutes.d.ts.map +1 -1
- package/bin/control/ChannelAccountApiRoutes.js +2 -3
- 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 +33 -25
- 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/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/registry/AgentHostRuntime.d.ts +1 -9
- package/bin/process/registry/AgentHostRuntime.d.ts.map +1 -1
- package/bin/process/registry/AgentHostRuntime.js +1 -155
- package/bin/process/registry/AgentHostRuntime.js.map +1 -1
- package/package.json +3 -2
- package/src/cli/Index.ts +11 -3
- package/src/cli/agent/Init.ts +9 -8
- package/src/cli/agent/Run.ts +8 -13
- package/src/cli/control-plane/ControlPlaneProcess.ts +2 -3
- package/src/cli/shared/ChatAuth.ts +10 -11
- package/src/cli/shared/ChatManager.ts +2 -3
- package/src/cli/shared/ManagedPluginActionCommands.ts +11 -8
- package/src/cli/shared/PluginScheduleCommand.ts +11 -10
- package/src/cli/shared/PluginTargetSupport.ts +6 -7
- package/src/cli/shared/Plugins.ts +16 -10
- package/src/control/ChannelAccountApiRoutes.ts +2 -3
- package/src/control/ControlGateway.ts +3 -2
- package/src/control/PluginApiRoutes.ts +37 -27
- package/src/control/gateway/AgentActions.ts +16 -11
- package/src/model/runtime/CreateRuntimeModel.ts +1 -26
- package/src/model/runtime/ExecutionModelBinding.ts +120 -0
- package/src/process/registry/AgentHostRuntime.ts +1 -163
- package/tsconfig.json +2 -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/src/platform/chatAuthorization/Store.ts +0 -181
|
@@ -4,61 +4,10 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - `main/agent/*` 负责创建这些宿主能力对象,再注入到 AgentRuntime。
|
|
6
6
|
* - plugin runtimes / session / plugins 只消费这些对象,不再直接 import `main/*`。
|
|
7
|
-
* - 当前由 city
|
|
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,7 +14,11 @@ 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
23
|
import { registerManagedPluginCommandsForCli } from "./shared/ManagedPluginActionCommands.js";
|
|
20
24
|
import { registerControlPlaneCommands } from "./control-plane/ControlPlaneCommand.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"))
|
|
@@ -96,9 +101,12 @@ registerChatCommand(program);
|
|
|
96
101
|
registerPluginsCommand(program);
|
|
97
102
|
|
|
98
103
|
// 受 agent 托管的 plugin 命令统一注册(chat / task / memory / shell / future managed plugins)
|
|
99
|
-
registerManagedPluginCommandsForCli(program);
|
|
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();
|
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[] = [];
|
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,23 +69,18 @@ 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
|
-
configureSession: async (session) => {
|
|
81
|
-
const model = await createRuntimeModel({
|
|
82
|
-
config: agent.getConfig(),
|
|
83
|
-
platform,
|
|
84
|
-
});
|
|
85
|
-
await session.set({
|
|
86
|
-
model,
|
|
87
|
-
});
|
|
88
|
-
},
|
|
82
|
+
plugins: createBuiltinPlugins(),
|
|
83
|
+
model,
|
|
89
84
|
});
|
|
90
85
|
|
|
91
86
|
const promptCatalog = new StaticPromptCatalog({
|
|
@@ -16,8 +16,7 @@ import {
|
|
|
16
16
|
readDaemonPid,
|
|
17
17
|
stopDaemonProcess,
|
|
18
18
|
} from "@/process/daemon/Manager.js";
|
|
19
|
-
import {
|
|
20
|
-
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
19
|
+
import { assertProjectExecutionModelReady } from "@/model/runtime/ExecutionModelBinding.js";
|
|
21
20
|
import { allocateAvailablePort } from "@/process/daemon/PortAllocator.js";
|
|
22
21
|
import {
|
|
23
22
|
ensureManagedAgentRegistry,
|
|
@@ -469,7 +468,7 @@ export async function prepareForegroundAgent(
|
|
|
469
468
|
|
|
470
469
|
injectAgentContext(cwd);
|
|
471
470
|
const projectRoot = resolve(String(cwd || "."));
|
|
472
|
-
|
|
471
|
+
assertProjectExecutionModelReady(projectRoot);
|
|
473
472
|
|
|
474
473
|
const shouldForeground = options.foreground === true;
|
|
475
474
|
if (!shouldForeground) {
|
|
@@ -11,18 +11,16 @@ import path from "node:path";
|
|
|
11
11
|
import prompts from "prompts";
|
|
12
12
|
import type { Command } from "commander";
|
|
13
13
|
import {
|
|
14
|
+
isChatAuthorizationChannel,
|
|
14
15
|
listChatAuthorizationRoles,
|
|
16
|
+
readChatAuthorizationConfigSync,
|
|
15
17
|
resolveAuthorizedUserRole,
|
|
16
|
-
|
|
17
|
-
import { emitCliBlock } from "./CliReporter.js";
|
|
18
|
-
import { parseBoolean } from "./IndexSupport.js";
|
|
19
|
-
import {
|
|
20
|
-
isChatAuthorizationChannel,
|
|
18
|
+
setChatAuthorizationUserRole,
|
|
21
19
|
type ChatAuthorizationChannel,
|
|
22
20
|
type ChatAuthorizationRole,
|
|
23
|
-
} from "@downcity/
|
|
24
|
-
import {
|
|
25
|
-
import {
|
|
21
|
+
} from "@downcity/plugins";
|
|
22
|
+
import { emitCliBlock } from "./CliReporter.js";
|
|
23
|
+
import { parseBoolean } from "./IndexSupport.js";
|
|
26
24
|
|
|
27
25
|
type ChatAuthSetOptions = {
|
|
28
26
|
/**
|
|
@@ -141,9 +139,10 @@ export async function runChatAuthSet(params: {
|
|
|
141
139
|
|
|
142
140
|
if (!nextRole) return;
|
|
143
141
|
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
142
|
+
await setChatAuthorizationUserRole({
|
|
143
|
+
context: {
|
|
144
|
+
rootPath: projectRoot,
|
|
145
|
+
},
|
|
147
146
|
channel: principal.channel,
|
|
148
147
|
userId: principal.userId,
|
|
149
148
|
roleId: nextRole.roleId,
|
|
@@ -12,7 +12,7 @@ import type { PromptObject } from "prompts";
|
|
|
12
12
|
import {
|
|
13
13
|
ChatChannelAccountManager,
|
|
14
14
|
type ChatChannelAccountListItem,
|
|
15
|
-
} from "@downcity/
|
|
15
|
+
} from "@downcity/plugins";
|
|
16
16
|
import { emitCliBlock, emitCliList } from "./CliReporter.js";
|
|
17
17
|
import { runManagedPluginControlCommand } from "./ManagedPluginRemote.js";
|
|
18
18
|
import type { StoredChannelAccountChannel } from "@downcity/agent";
|
|
@@ -21,12 +21,11 @@ import type {
|
|
|
21
21
|
ChatManagerRootAction,
|
|
22
22
|
} from "./ChatManagerTypes.js";
|
|
23
23
|
import { runInteractiveChatAuthSetFlow } from "./ChatAuth.js";
|
|
24
|
-
import { createAgentPlatformRuntime } from "@/process/registry/AgentHostRuntime.js";
|
|
25
24
|
|
|
26
25
|
const CHAT_CHANNELS: StoredChannelAccountChannel[] = ["telegram", "feishu", "qq"];
|
|
27
26
|
|
|
28
27
|
function createChannelAccountManager(): ChatChannelAccountManager {
|
|
29
|
-
return new ChatChannelAccountManager(
|
|
28
|
+
return new ChatChannelAccountManager();
|
|
30
29
|
}
|
|
31
30
|
|
|
32
31
|
function isInteractiveTerminal(): boolean {
|
|
@@ -11,12 +11,12 @@ import path from "node:path";
|
|
|
11
11
|
import type { Command } from "commander";
|
|
12
12
|
import {
|
|
13
13
|
callAgentTransport,
|
|
14
|
-
|
|
15
|
-
parseScheduledRunAtMsOrThrow,
|
|
14
|
+
parseActionScheduleRunAtMsOrThrow,
|
|
16
15
|
} from "@downcity/agent";
|
|
16
|
+
import { listPluginsWithLifecycle } from "@downcity/agent";
|
|
17
17
|
import type { BasePlugin, PluginAction } from "@downcity/agent";
|
|
18
18
|
import type { JsonObject, JsonValue } from "@downcity/agent";
|
|
19
|
-
import type {
|
|
19
|
+
import type { PluginActionScheduleInput } from "@downcity/agent";
|
|
20
20
|
import type { PluginCommandResponse } from "@downcity/agent";
|
|
21
21
|
import type { PluginCliBaseOptions } from "@downcity/agent";
|
|
22
22
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
@@ -160,8 +160,8 @@ function hasLongOption(command: Command, longFlag: string): boolean {
|
|
|
160
160
|
*/
|
|
161
161
|
function extractCommandScheduleInput(
|
|
162
162
|
options: Record<string, unknown>,
|
|
163
|
-
):
|
|
164
|
-
const runAtMs =
|
|
163
|
+
): PluginActionScheduleInput | undefined {
|
|
164
|
+
const runAtMs = parseActionScheduleRunAtMsOrThrow({
|
|
165
165
|
delay: options.delay as string | number | undefined,
|
|
166
166
|
time: options.time as string | number | undefined,
|
|
167
167
|
});
|
|
@@ -245,7 +245,7 @@ function registerPluginActionCommand(params: {
|
|
|
245
245
|
})();
|
|
246
246
|
const actionOptions = toPluginActionCommandOpts(allOptions);
|
|
247
247
|
const bridgeOptions = toPluginCliBridgeOptions(allOptions);
|
|
248
|
-
let schedule:
|
|
248
|
+
let schedule: PluginActionScheduleInput | undefined;
|
|
249
249
|
try {
|
|
250
250
|
schedule = extractCommandScheduleInput(allOptions);
|
|
251
251
|
} catch (error) {
|
|
@@ -395,8 +395,11 @@ function registerPluginLifecycleCommands(params: {
|
|
|
395
395
|
/**
|
|
396
396
|
* 注册所有受 agent 托管的 plugin actions CLI 命令。
|
|
397
397
|
*/
|
|
398
|
-
export function registerManagedPluginCommandsForCli(
|
|
399
|
-
|
|
398
|
+
export function registerManagedPluginCommandsForCli(
|
|
399
|
+
program: Command,
|
|
400
|
+
pluginsInput: BasePlugin[],
|
|
401
|
+
): void {
|
|
402
|
+
const plugins = listPluginsWithLifecycle(pluginsInput);
|
|
400
403
|
for (const plugin of plugins) {
|
|
401
404
|
for (const [actionName, action] of Object.entries(plugin.actions)) {
|
|
402
405
|
registerPluginActionCommand({
|
|
@@ -2,12 +2,13 @@
|
|
|
2
2
|
* `city plugin schedule` 命令。
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
|
-
* -
|
|
6
|
-
* -
|
|
5
|
+
* - 命令名保留 schedule,是用户侧“延迟执行任务”的操作语义。
|
|
6
|
+
* - 内部使用 Agent 的 ActionScheduleStore,不依赖独立 schedule plugin。
|
|
7
|
+
* - 这里同时承载 schedule 子命令注册与 ActionSchedule 本地存储读写流程。
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import type { Command } from "commander";
|
|
10
|
-
import {
|
|
11
|
+
import { ActionScheduleStore } from "@downcity/agent";
|
|
11
12
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
12
13
|
import type { PluginCliBaseOptions } from "@downcity/agent";
|
|
13
14
|
import {
|
|
@@ -57,7 +58,7 @@ export async function runPluginScheduleListCommand(params: {
|
|
|
57
58
|
const limit = params.limitRaw
|
|
58
59
|
? parsePositiveIntOption(params.limitRaw, "limit")
|
|
59
60
|
: 100;
|
|
60
|
-
const store = new
|
|
61
|
+
const store = new ActionScheduleStore(projectRoot);
|
|
61
62
|
try {
|
|
62
63
|
const jobs = store.listJobs({ status, limit });
|
|
63
64
|
printResult({
|
|
@@ -132,7 +133,7 @@ export async function runPluginScheduleInfoCommand(params: {
|
|
|
132
133
|
return;
|
|
133
134
|
}
|
|
134
135
|
|
|
135
|
-
const store = new
|
|
136
|
+
const store = new ActionScheduleStore(projectRoot);
|
|
136
137
|
try {
|
|
137
138
|
const job = store.getJobById(jobId);
|
|
138
139
|
if (!job) {
|
|
@@ -205,7 +206,7 @@ export async function runPluginScheduleCancelCommand(params: {
|
|
|
205
206
|
return;
|
|
206
207
|
}
|
|
207
208
|
|
|
208
|
-
const store = new
|
|
209
|
+
const store = new ActionScheduleStore(projectRoot);
|
|
209
210
|
try {
|
|
210
211
|
const current = store.getJobById(jobId);
|
|
211
212
|
if (!current) {
|
|
@@ -264,13 +265,13 @@ export async function runPluginScheduleCancelCommand(params: {
|
|
|
264
265
|
export function registerPluginScheduleCommands(plugin: Command): void {
|
|
265
266
|
const schedule = plugin
|
|
266
267
|
.command("schedule")
|
|
267
|
-
.description("
|
|
268
|
+
.description("查看和管理持久化延迟 action 任务")
|
|
268
269
|
.helpOption("--help", "display help for command");
|
|
269
270
|
|
|
270
271
|
addPluginScheduleOptions(
|
|
271
272
|
schedule
|
|
272
273
|
.command("list")
|
|
273
|
-
.description("列出当前 agent
|
|
274
|
+
.description("列出当前 agent 的延迟 action 任务")
|
|
274
275
|
.option("--status <status>", "状态过滤(pending|running|succeeded|failed|cancelled)")
|
|
275
276
|
.option("--limit <n>", "返回条数(默认 100)"),
|
|
276
277
|
).action(async (opts: PluginCliBaseOptions & { status?: string; limit?: string }) => {
|
|
@@ -284,7 +285,7 @@ export function registerPluginScheduleCommands(plugin: Command): void {
|
|
|
284
285
|
addPluginScheduleOptions(
|
|
285
286
|
schedule
|
|
286
287
|
.command("info <jobId>")
|
|
287
|
-
.description("
|
|
288
|
+
.description("查看单个延迟 action 任务详情"),
|
|
288
289
|
).action(async (jobId: string, opts: PluginCliBaseOptions) => {
|
|
289
290
|
await runPluginScheduleInfoCommand({
|
|
290
291
|
jobId,
|
|
@@ -295,7 +296,7 @@ export function registerPluginScheduleCommands(plugin: Command): void {
|
|
|
295
296
|
addPluginScheduleOptions(
|
|
296
297
|
schedule
|
|
297
298
|
.command("cancel <jobId>")
|
|
298
|
-
.description("
|
|
299
|
+
.description("取消一个尚未执行的延迟 action 任务"),
|
|
299
300
|
).action(async (jobId: string, opts: PluginCliBaseOptions) => {
|
|
300
301
|
await runPluginScheduleCancelCommand({
|
|
301
302
|
jobId,
|
|
@@ -13,14 +13,13 @@ import type { Command } from "commander";
|
|
|
13
13
|
import { getProfileMdPath, getDowncityJsonPath } from "@/config/Paths.js";
|
|
14
14
|
import { listManagedAgentEntries } from "@/process/registry/CityRegistry.js";
|
|
15
15
|
import { isCityRunning } from "@/process/registry/CityRuntime.js";
|
|
16
|
-
import { ensureRuntimeExecutionBindingReady } from "@downcity/agent";
|
|
17
16
|
import type { JsonValue } from "@downcity/agent";
|
|
18
17
|
import { parsePort, resolveAgentName } from "./IndexSupport.js";
|
|
19
18
|
import { CliError } from "./CliError.js";
|
|
20
|
-
import type {
|
|
19
|
+
import type { ActionScheduleJobStatus } from "@downcity/agent";
|
|
21
20
|
import type { PluginCliBaseOptions } from "@downcity/agent";
|
|
22
21
|
import { parseBoolean } from "./IndexSupport.js";
|
|
23
|
-
import {
|
|
22
|
+
import { assertProjectExecutionModelReady } from "@/model/runtime/ExecutionModelBinding.js";
|
|
24
23
|
|
|
25
24
|
export function isRegistryEntryRunning(
|
|
26
25
|
entry: { status?: "running" | "stopped" },
|
|
@@ -77,7 +76,7 @@ export async function checkAgentPreflight(
|
|
|
77
76
|
}
|
|
78
77
|
|
|
79
78
|
// 关键点(中文):提前校验 execution binding,避免"启动成功后秒退"。
|
|
80
|
-
|
|
79
|
+
assertProjectExecutionModelReady(projectRoot);
|
|
81
80
|
}
|
|
82
81
|
|
|
83
82
|
/**
|
|
@@ -96,7 +95,7 @@ export function parsePositiveIntOption(value: string, fieldName: string): number
|
|
|
96
95
|
*/
|
|
97
96
|
export function normalizeScheduledJobStatus(
|
|
98
97
|
value: string | undefined,
|
|
99
|
-
):
|
|
98
|
+
): ActionScheduleJobStatus | undefined {
|
|
100
99
|
const text = String(value || "").trim().toLowerCase();
|
|
101
100
|
if (!text) return undefined;
|
|
102
101
|
if (
|
|
@@ -206,7 +205,7 @@ export async function resolvePluginProjectRoot(options: PluginCliBaseOptions): P
|
|
|
206
205
|
}
|
|
207
206
|
|
|
208
207
|
/**
|
|
209
|
-
* 解析
|
|
208
|
+
* 解析 ActionSchedule 管理命令目标路径。
|
|
210
209
|
*/
|
|
211
210
|
export async function resolvePluginScheduleProjectRoot(options: PluginCliBaseOptions): Promise<{
|
|
212
211
|
projectRoot?: string;
|
|
@@ -266,7 +265,7 @@ export function addPluginTargetOptions(command: Command): Command {
|
|
|
266
265
|
}
|
|
267
266
|
|
|
268
267
|
/**
|
|
269
|
-
* 注入
|
|
268
|
+
* 注入 ActionSchedule 管理命令通用选项。
|
|
270
269
|
*/
|
|
271
270
|
export function addPluginScheduleOptions(command: Command): Command {
|
|
272
271
|
return command
|