@downcity/city 1.1.39 → 1.1.47
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 +4 -9
- package/bin/cli/Index.js +2 -0
- package/bin/cli/Index.js.map +1 -1
- package/bin/cli/agent/AgentChat.d.ts +2 -1
- package/bin/cli/agent/AgentChat.d.ts.map +1 -1
- package/bin/cli/agent/AgentChat.js +93 -214
- package/bin/cli/agent/AgentChat.js.map +1 -1
- package/bin/cli/agent/AgentChatTypes.d.ts +8 -12
- package/bin/cli/agent/AgentChatTypes.d.ts.map +1 -1
- package/bin/cli/agent/AgentHistory.js +2 -2
- package/bin/cli/agent/AgentHistory.js.map +1 -1
- package/bin/cli/agent/AgentManager.d.ts.map +1 -1
- package/bin/cli/agent/AgentManager.js +26 -27
- package/bin/cli/agent/AgentManager.js.map +1 -1
- package/bin/cli/agent/AgentManagerTypes.d.ts +2 -2
- package/bin/cli/agent/AgentManagerTypes.d.ts.map +1 -1
- package/bin/cli/agent/AgentReset.js +4 -4
- package/bin/cli/agent/AgentReset.js.map +1 -1
- package/bin/cli/agent/AgentSelection.js +6 -6
- package/bin/cli/agent/AgentSelection.js.map +1 -1
- package/bin/cli/agent/AgentSelectionTypes.d.ts +1 -1
- package/bin/cli/agent/AgentSelectionTypes.d.ts.map +1 -1
- package/bin/cli/agent/Init.js +10 -10
- package/bin/cli/agent/Init.js.map +1 -1
- package/bin/cli/agent/Restart.js +2 -2
- package/bin/cli/agent/Restart.js.map +1 -1
- package/bin/cli/agent/Run.d.ts +1 -1
- package/bin/cli/agent/Run.d.ts.map +1 -1
- package/bin/cli/agent/Run.js +37 -17
- package/bin/cli/agent/Run.js.map +1 -1
- package/bin/cli/agent/Start.js +2 -2
- package/bin/cli/agent/Start.js.map +1 -1
- package/bin/cli/agent/Stop.js +2 -2
- package/bin/cli/agent/Stop.js.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.js +5 -5
- package/bin/cli/control-plane/ControlPlaneProcess.js.map +1 -1
- package/bin/cli/model/ModelCreateCommand.js +1 -1
- package/bin/cli/model/ModelCreateCommand.js.map +1 -1
- package/bin/cli/model/ModelManageCommand.d.ts.map +1 -1
- package/bin/cli/model/ModelManageCommand.js +5 -3
- package/bin/cli/model/ModelManageCommand.js.map +1 -1
- package/bin/cli/model/ModelManager.js +3 -3
- package/bin/cli/model/ModelManager.js.map +1 -1
- package/bin/cli/model/ModelSupport.d.ts +0 -1
- package/bin/cli/model/ModelSupport.d.ts.map +1 -1
- package/bin/cli/model/ModelSupport.js +2 -11
- package/bin/cli/model/ModelSupport.js.map +1 -1
- package/bin/cli/shared/CliReporterTypes.d.ts +1 -1
- package/bin/cli/shared/Config.js +2 -2
- package/bin/cli/shared/Config.js.map +1 -1
- package/bin/cli/shared/Env.d.ts +1 -1
- package/bin/cli/shared/Env.d.ts.map +1 -1
- package/bin/cli/shared/Env.js +18 -149
- package/bin/cli/shared/Env.js.map +1 -1
- package/bin/cli/shared/IndexAgentCommand.d.ts.map +1 -1
- package/bin/cli/shared/IndexAgentCommand.js +3 -3
- package/bin/cli/shared/IndexAgentCommand.js.map +1 -1
- package/bin/cli/shared/IndexSupport.d.ts +3 -3
- package/bin/cli/shared/IndexSupport.d.ts.map +1 -1
- package/bin/cli/shared/IndexSupport.js +14 -8
- package/bin/cli/shared/IndexSupport.js.map +1 -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/ManagedPluginRemote.d.ts.map +1 -1
- package/bin/cli/shared/ManagedPluginRemote.js +4 -4
- package/bin/cli/shared/ManagedPluginRemote.js.map +1 -1
- package/bin/cli/shared/PluginTargetSupport.d.ts +2 -2
- package/bin/cli/shared/PluginTargetSupport.d.ts.map +1 -1
- package/bin/cli/shared/PluginTargetSupport.js +19 -19
- package/bin/cli/shared/PluginTargetSupport.js.map +1 -1
- package/bin/cli/shared/Plugins.js +10 -10
- package/bin/cli/shared/Plugins.js.map +1 -1
- package/bin/cli/shared/PublicHostEnv.d.ts +1 -1
- package/bin/cli/shared/PublicHostEnv.js +2 -2
- package/bin/cli/shared/PublicHostEnv.js.map +1 -1
- package/bin/cli/shared/Terminal.d.ts +13 -0
- package/bin/cli/shared/Terminal.d.ts.map +1 -0
- package/bin/cli/shared/Terminal.js +22 -0
- package/bin/cli/shared/Terminal.js.map +1 -0
- package/bin/config/DowncitySchema.d.ts.map +1 -1
- package/bin/config/DowncitySchema.js +3 -111
- package/bin/config/DowncitySchema.js.map +1 -1
- package/bin/config/Paths.d.ts +0 -56
- package/bin/config/Paths.d.ts.map +1 -1
- package/bin/config/Paths.js +9 -51
- package/bin/config/Paths.js.map +1 -1
- package/bin/control/ControlGateway.js +1 -1
- package/bin/control/ControlGateway.js.map +1 -1
- package/bin/control/EnvApiRoutes.d.ts +1 -1
- package/bin/control/EnvApiRoutes.d.ts.map +1 -1
- package/bin/control/EnvApiRoutes.js +7 -79
- package/bin/control/EnvApiRoutes.js.map +1 -1
- package/bin/control/PlatformApiRoutes.d.ts +2 -2
- package/bin/control/PlatformApiRoutes.d.ts.map +1 -1
- package/bin/control/PlatformApiRoutes.js +2 -2
- package/bin/control/PlatformApiRoutes.js.map +1 -1
- package/bin/control/gateway/AgentActions.d.ts +2 -2
- package/bin/control/gateway/AgentActions.d.ts.map +1 -1
- package/bin/control/gateway/AgentActions.js +7 -7
- package/bin/control/gateway/AgentActions.js.map +1 -1
- package/bin/control/gateway/AgentCatalog.d.ts +3 -6
- package/bin/control/gateway/AgentCatalog.d.ts.map +1 -1
- package/bin/control/gateway/AgentCatalog.js +16 -18
- package/bin/control/gateway/AgentCatalog.js.map +1 -1
- package/bin/control/instant/InstantSessionRunner.d.ts.map +1 -1
- package/bin/control/instant/InstantSessionRunner.js +3 -1
- package/bin/control/instant/InstantSessionRunner.js.map +1 -1
- package/bin/env/ProcessEnv.d.ts +24 -0
- package/bin/env/ProcessEnv.d.ts.map +1 -0
- package/bin/env/ProcessEnv.js +41 -0
- package/bin/env/ProcessEnv.js.map +1 -0
- package/bin/http/auth/AuthEnv.d.ts +1 -1
- package/bin/http/auth/AuthEnv.js +1 -1
- package/bin/model/runtime/CreateRuntimeModel.d.ts +8 -0
- package/bin/model/runtime/CreateRuntimeModel.d.ts.map +1 -1
- package/bin/model/runtime/CreateRuntimeModel.js +43 -37
- package/bin/model/runtime/CreateRuntimeModel.js.map +1 -1
- package/bin/model/service/ModelPoolService.d.ts +1 -1
- package/bin/model/service/ModelPoolService.d.ts.map +1 -1
- package/bin/model/service/ModelPoolService.js +8 -6
- package/bin/model/service/ModelPoolService.js.map +1 -1
- package/bin/platform/store/StoreEnvRepository.d.ts +5 -49
- package/bin/platform/store/StoreEnvRepository.d.ts.map +1 -1
- package/bin/platform/store/StoreEnvRepository.js +31 -178
- package/bin/platform/store/StoreEnvRepository.js.map +1 -1
- package/bin/platform/store/StoreSchema.js +3 -44
- package/bin/platform/store/StoreSchema.js.map +1 -1
- package/bin/platform/store/index.d.ts +9 -45
- package/bin/platform/store/index.d.ts.map +1 -1
- package/bin/platform/store/index.js +12 -62
- package/bin/platform/store/index.js.map +1 -1
- package/bin/platform/store/schema.d.ts +2 -2
- package/bin/platform/store/schema.js +2 -2
- package/bin/process/daemon/Api.d.ts +1 -1
- package/bin/process/daemon/CliArgs.d.ts +1 -0
- package/bin/process/daemon/CliArgs.d.ts.map +1 -1
- package/bin/process/daemon/CliArgs.js +20 -1
- package/bin/process/daemon/CliArgs.js.map +1 -1
- package/bin/process/daemon/Client.d.ts +18 -2
- package/bin/process/daemon/Client.d.ts.map +1 -1
- package/bin/process/daemon/Client.js +70 -20
- package/bin/process/daemon/Client.js.map +1 -1
- package/bin/process/daemon/Manager.d.ts.map +1 -1
- package/bin/process/daemon/Manager.js +2 -1
- package/bin/process/daemon/Manager.js.map +1 -1
- package/bin/terminal/admin/auth-error.d.ts +34 -0
- package/bin/terminal/admin/auth-error.d.ts.map +1 -0
- package/bin/terminal/admin/auth-error.js +51 -0
- package/bin/terminal/admin/auth-error.js.map +1 -0
- package/bin/terminal/admin/commands/accounts.d.ts +6 -0
- package/bin/terminal/admin/commands/accounts.d.ts.map +1 -0
- package/bin/terminal/admin/commands/accounts.js +44 -0
- package/bin/terminal/admin/commands/accounts.js.map +1 -0
- package/bin/terminal/admin/commands/balance.d.ts +6 -0
- package/bin/terminal/admin/commands/balance.d.ts.map +1 -0
- package/bin/terminal/admin/commands/balance.js +153 -0
- package/bin/terminal/admin/commands/balance.js.map +1 -0
- package/bin/terminal/admin/commands/config.d.ts +10 -0
- package/bin/terminal/admin/commands/config.d.ts.map +1 -0
- package/bin/terminal/admin/commands/config.js +11 -0
- package/bin/terminal/admin/commands/config.js.map +1 -0
- package/bin/terminal/admin/commands/custom.d.ts +6 -0
- package/bin/terminal/admin/commands/custom.d.ts.map +1 -0
- package/bin/terminal/admin/commands/custom.js +47 -0
- package/bin/terminal/admin/commands/custom.js.map +1 -0
- package/bin/terminal/admin/commands/instruction.d.ts +9 -0
- package/bin/terminal/admin/commands/instruction.d.ts.map +1 -0
- package/bin/terminal/admin/commands/instruction.js +10 -0
- package/bin/terminal/admin/commands/instruction.js.map +1 -0
- package/bin/terminal/admin/commands/models.d.ts +14 -0
- package/bin/terminal/admin/commands/models.d.ts.map +1 -0
- package/bin/terminal/admin/commands/models.js +61 -0
- package/bin/terminal/admin/commands/models.js.map +1 -0
- package/bin/terminal/admin/commands/payment.d.ts +6 -0
- package/bin/terminal/admin/commands/payment.d.ts.map +1 -0
- package/bin/terminal/admin/commands/payment.js +59 -0
- package/bin/terminal/admin/commands/payment.js.map +1 -0
- package/bin/terminal/admin/commands/products.d.ts +6 -0
- package/bin/terminal/admin/commands/products.d.ts.map +1 -0
- package/bin/terminal/admin/commands/products.js +80 -0
- package/bin/terminal/admin/commands/products.js.map +1 -0
- package/bin/terminal/admin/commands/service-env.d.ts +11 -0
- package/bin/terminal/admin/commands/service-env.d.ts.map +1 -0
- package/bin/terminal/admin/commands/service-env.js +248 -0
- package/bin/terminal/admin/commands/service-env.js.map +1 -0
- package/bin/terminal/admin/commands/usage.d.ts +6 -0
- package/bin/terminal/admin/commands/usage.d.ts.map +1 -0
- package/bin/terminal/admin/commands/usage.js +44 -0
- package/bin/terminal/admin/commands/usage.js.map +1 -0
- package/bin/terminal/admin/loop.d.ts +6 -0
- package/bin/terminal/admin/loop.d.ts.map +1 -0
- package/bin/terminal/admin/loop.js +70 -0
- package/bin/terminal/admin/loop.js.map +1 -0
- package/bin/terminal/agent/pi-agent.d.ts +15 -0
- package/bin/terminal/agent/pi-agent.d.ts.map +1 -0
- package/bin/terminal/agent/pi-agent.js +136 -0
- package/bin/terminal/agent/pi-agent.js.map +1 -0
- package/bin/terminal/app.d.ts +13 -0
- package/bin/terminal/app.d.ts.map +1 -0
- package/bin/terminal/app.js +123 -0
- package/bin/terminal/app.js.map +1 -0
- package/bin/terminal/auth/admin.d.ts +8 -0
- package/bin/terminal/auth/admin.d.ts.map +1 -0
- package/bin/terminal/auth/admin.js +18 -0
- package/bin/terminal/auth/admin.js.map +1 -0
- package/bin/terminal/auth/mode-select.d.ts +11 -0
- package/bin/terminal/auth/mode-select.d.ts.map +1 -0
- package/bin/terminal/auth/mode-select.js +33 -0
- package/bin/terminal/auth/mode-select.js.map +1 -0
- package/bin/terminal/auth/server-switch.d.ts +22 -0
- package/bin/terminal/auth/server-switch.d.ts.map +1 -0
- package/bin/terminal/auth/server-switch.js +241 -0
- package/bin/terminal/auth/server-switch.js.map +1 -0
- package/bin/terminal/auth/user.d.ts +19 -0
- package/bin/terminal/auth/user.d.ts.map +1 -0
- package/bin/terminal/auth/user.js +261 -0
- package/bin/terminal/auth/user.js.map +1 -0
- package/bin/terminal/core/browser.d.ts +12 -0
- package/bin/terminal/core/browser.d.ts.map +1 -0
- package/bin/terminal/core/browser.js +29 -0
- package/bin/terminal/core/browser.js.map +1 -0
- package/bin/terminal/core/env.d.ts +15 -0
- package/bin/terminal/core/env.d.ts.map +1 -0
- package/bin/terminal/core/env.js +67 -0
- package/bin/terminal/core/env.js.map +1 -0
- package/bin/terminal/core/session.d.ts +97 -0
- package/bin/terminal/core/session.d.ts.map +1 -0
- package/bin/terminal/core/session.js +342 -0
- package/bin/terminal/core/session.js.map +1 -0
- package/bin/terminal/core/stripe.d.ts +26 -0
- package/bin/terminal/core/stripe.d.ts.map +1 -0
- package/bin/terminal/core/stripe.js +22 -0
- package/bin/terminal/core/stripe.js.map +1 -0
- package/bin/terminal/core/ui.d.ts +29 -0
- package/bin/terminal/core/ui.d.ts.map +1 -0
- package/bin/terminal/core/ui.js +60 -0
- package/bin/terminal/core/ui.js.map +1 -0
- package/bin/terminal/core/update.d.ts +20 -0
- package/bin/terminal/core/update.d.ts.map +1 -0
- package/bin/terminal/core/update.js +193 -0
- package/bin/terminal/core/update.js.map +1 -0
- package/bin/terminal/user/balance.d.ts +31 -0
- package/bin/terminal/user/balance.d.ts.map +1 -0
- package/bin/terminal/user/balance.js +131 -0
- package/bin/terminal/user/balance.js.map +1 -0
- package/bin/terminal/user/chat.d.ts +12 -0
- package/bin/terminal/user/chat.d.ts.map +1 -0
- package/bin/terminal/user/chat.js +70 -0
- package/bin/terminal/user/chat.js.map +1 -0
- package/bin/terminal/user/loop.d.ts +13 -0
- package/bin/terminal/user/loop.d.ts.map +1 -0
- package/bin/terminal/user/loop.js +93 -0
- package/bin/terminal/user/loop.js.map +1 -0
- package/bin/terminal/user/models.d.ts +10 -0
- package/bin/terminal/user/models.d.ts.map +1 -0
- package/bin/terminal/user/models.js +39 -0
- package/bin/terminal/user/models.js.map +1 -0
- package/bin/utils/storage.d.ts +0 -1
- package/bin/utils/storage.d.ts.map +1 -1
- package/bin/utils/storage.js +0 -6
- package/bin/utils/storage.js.map +1 -1
- package/package.json +7 -3
- package/public/app.js +3 -3
- package/src/cli/Index.ts +2 -0
- package/src/cli/agent/AgentChat.ts +113 -289
- package/src/cli/agent/AgentChatTypes.ts +8 -12
- package/src/cli/agent/AgentHistory.ts +2 -2
- package/src/cli/agent/AgentManager.ts +27 -28
- package/src/cli/agent/AgentManagerTypes.ts +2 -2
- package/src/cli/agent/AgentReset.ts +4 -4
- package/src/cli/agent/AgentSelection.ts +6 -6
- package/src/cli/agent/AgentSelectionTypes.ts +1 -1
- package/src/cli/agent/Init.ts +13 -13
- package/src/cli/agent/Restart.ts +2 -2
- package/src/cli/agent/Run.ts +38 -17
- package/src/cli/agent/Start.ts +2 -2
- package/src/cli/agent/Stop.ts +2 -2
- package/src/cli/control-plane/ControlPlaneProcess.ts +5 -5
- package/src/cli/model/ModelCreateCommand.ts +1 -1
- package/src/cli/model/ModelManageCommand.ts +5 -3
- package/src/cli/model/ModelManager.ts +3 -3
- package/src/cli/model/ModelSupport.ts +2 -10
- package/src/cli/shared/CliReporterTypes.ts +1 -1
- package/src/cli/shared/Config.ts +2 -2
- package/src/cli/shared/Env.ts +22 -230
- package/src/cli/shared/IndexAgentCommand.ts +3 -4
- package/src/cli/shared/IndexSupport.ts +16 -10
- package/src/cli/shared/ManagedPluginActionCommands.ts +4 -4
- package/src/cli/shared/ManagedPluginRemote.ts +4 -4
- package/src/cli/shared/PluginTargetSupport.ts +19 -19
- package/src/cli/shared/Plugins.ts +10 -10
- package/src/cli/shared/PublicHostEnv.ts +2 -2
- package/src/cli/shared/Terminal.ts +24 -0
- package/src/config/DowncitySchema.ts +3 -113
- package/src/config/Paths.ts +9 -90
- package/src/control/ControlGateway.ts +3 -3
- package/src/control/EnvApiRoutes.ts +7 -91
- package/src/control/PlatformApiRoutes.ts +6 -6
- package/src/control/gateway/AgentActions.ts +10 -10
- package/src/control/gateway/AgentCatalog.ts +17 -21
- package/src/control/instant/InstantSessionRunner.ts +3 -1
- package/src/env/ProcessEnv.ts +43 -0
- package/src/http/auth/AuthEnv.ts +1 -1
- package/src/model/runtime/CreateRuntimeModel.ts +54 -37
- package/src/model/service/ModelPoolService.ts +13 -11
- package/src/platform/store/StoreEnvRepository.ts +31 -234
- package/src/platform/store/StoreSchema.ts +3 -49
- package/src/platform/store/index.ts +11 -80
- package/src/platform/store/schema.ts +2 -2
- package/src/process/daemon/Api.ts +1 -1
- package/src/process/daemon/CliArgs.ts +24 -1
- package/src/process/daemon/Client.ts +90 -22
- package/src/process/daemon/Manager.ts +2 -1
- package/src/terminal/admin/auth-error.ts +62 -0
- package/src/terminal/admin/commands/accounts.ts +44 -0
- package/src/terminal/admin/commands/balance.ts +160 -0
- package/src/terminal/admin/commands/config.ts +13 -0
- package/src/terminal/admin/commands/custom.ts +46 -0
- package/src/terminal/admin/commands/instruction.ts +12 -0
- package/src/terminal/admin/commands/models.ts +64 -0
- package/src/terminal/admin/commands/payment.ts +94 -0
- package/src/terminal/admin/commands/products.ts +72 -0
- package/src/terminal/admin/commands/service-env.ts +256 -0
- package/src/terminal/admin/commands/usage.ts +44 -0
- package/src/terminal/admin/loop.ts +69 -0
- package/src/terminal/agent/pi-agent.ts +180 -0
- package/src/terminal/app.ts +120 -0
- package/src/terminal/auth/admin.ts +21 -0
- package/src/terminal/auth/mode-select.ts +38 -0
- package/src/terminal/auth/server-switch.ts +275 -0
- package/src/terminal/auth/user.ts +351 -0
- package/src/terminal/core/browser.ts +31 -0
- package/src/terminal/core/env.ts +71 -0
- package/src/terminal/core/session.ts +450 -0
- package/src/terminal/core/stripe.ts +37 -0
- package/src/terminal/core/ui.ts +84 -0
- package/src/terminal/core/update.ts +230 -0
- package/src/terminal/user/balance.ts +215 -0
- package/src/terminal/user/chat.ts +80 -0
- package/src/terminal/user/loop.ts +112 -0
- package/src/terminal/user/models.ts +43 -0
- package/src/utils/storage.ts +0 -7
- package/bin/process/rpc/Client.d.ts +0 -13
- package/bin/process/rpc/Client.d.ts.map +0 -1
- package/bin/process/rpc/Client.js +0 -98
- package/bin/process/rpc/Client.js.map +0 -1
- package/bin/process/rpc/Paths.d.ts +0 -14
- package/bin/process/rpc/Paths.d.ts.map +0 -1
- package/bin/process/rpc/Paths.js +0 -36
- package/bin/process/rpc/Paths.js.map +0 -1
- package/src/process/rpc/Client.ts +0 -113
- package/src/process/rpc/Paths.ts +0 -43
|
@@ -11,6 +11,7 @@ import { generateText } from "ai";
|
|
|
11
11
|
import type { LlmProviderType } from "@downcity/agent";
|
|
12
12
|
import { createRuntimeModel } from "@/model/runtime/CreateRuntimeModel.js";
|
|
13
13
|
import { ModelPoolService } from "@/model/service/ModelPoolService.js";
|
|
14
|
+
import { mergeProcessEnvWithPlatformGlobalEnv } from "@/env/ProcessEnv.js";
|
|
14
15
|
import {
|
|
15
16
|
discoverProviderModels,
|
|
16
17
|
} from "./ModelSupport.js";
|
|
@@ -45,7 +46,7 @@ function registerAddCommands(model: Command): void {
|
|
|
45
46
|
.description("新增 provider")
|
|
46
47
|
.requiredOption("--type <type>", "provider 类型")
|
|
47
48
|
.option("--base-url <baseUrl>", "provider baseUrl")
|
|
48
|
-
.requiredOption("--api-key <apiKey>", "provider apiKey
|
|
49
|
+
.requiredOption("--api-key <apiKey>", "provider apiKey")
|
|
49
50
|
.option("--json [enabled]", "以 JSON 输出", parseBooleanOption, true)
|
|
50
51
|
.helpOption("--help", "display help for command")
|
|
51
52
|
.action(async (
|
|
@@ -247,7 +248,7 @@ function registerUpdateCommands(model: Command): void {
|
|
|
247
248
|
.description("更新 provider")
|
|
248
249
|
.option("--type <type>", "provider 类型")
|
|
249
250
|
.option("--base-url <baseUrl>", "provider baseUrl")
|
|
250
|
-
.option("--api-key <apiKey>", "provider apiKey
|
|
251
|
+
.option("--api-key <apiKey>", "provider apiKey")
|
|
251
252
|
.option("--clear-base-url", "清空 baseUrl", false)
|
|
252
253
|
.option("--clear-api-key", "清空 apiKey", false)
|
|
253
254
|
.option("--json [enabled]", "以 JSON 输出", parseBooleanOption, true)
|
|
@@ -497,10 +498,11 @@ function registerTestCommands(model: Command): void {
|
|
|
497
498
|
if (!id) throw new Error("modelId cannot be empty");
|
|
498
499
|
const runtimeModel = await createRuntimeModel({
|
|
499
500
|
config: {
|
|
500
|
-
|
|
501
|
+
id: "console_model_test",
|
|
501
502
|
version: "1.0.0",
|
|
502
503
|
execution: { type: "api", modelId: id },
|
|
503
504
|
},
|
|
505
|
+
env: mergeProcessEnvWithPlatformGlobalEnv(process.env),
|
|
504
506
|
});
|
|
505
507
|
const prompt = String(options.prompt || "").trim() || "Reply with exactly: OK";
|
|
506
508
|
const result = await generateText({
|
|
@@ -55,10 +55,10 @@ function parseOptionalPositiveIntegerInput(input: string): number | undefined {
|
|
|
55
55
|
|
|
56
56
|
function formatManagerAgentReference(reference: {
|
|
57
57
|
projectRoot: string;
|
|
58
|
-
|
|
58
|
+
agentId?: string;
|
|
59
59
|
}): string {
|
|
60
|
-
const
|
|
61
|
-
if (
|
|
60
|
+
const agentId = String(reference.agentId || "").trim();
|
|
61
|
+
if (agentId) return `${agentId} (${reference.projectRoot})`;
|
|
62
62
|
return reference.projectRoot;
|
|
63
63
|
}
|
|
64
64
|
|
|
@@ -34,14 +34,6 @@ export type ProviderDiscoveryResult = {
|
|
|
34
34
|
error?: string;
|
|
35
35
|
};
|
|
36
36
|
|
|
37
|
-
export function resolveEnvPlaceholder(value: string | undefined): string | undefined {
|
|
38
|
-
const raw = String(value || "").trim();
|
|
39
|
-
if (!raw) return undefined;
|
|
40
|
-
const matched = raw.match(/^\$\{([A-Z0-9_]+)\}$/);
|
|
41
|
-
if (!matched) return raw;
|
|
42
|
-
return process.env[matched[1]];
|
|
43
|
-
}
|
|
44
|
-
|
|
45
37
|
export function resolveProviderDefaultBaseUrl(
|
|
46
38
|
providerType: LlmProviderType,
|
|
47
39
|
): string | undefined {
|
|
@@ -88,14 +80,14 @@ export async function discoverProviderModels(params: {
|
|
|
88
80
|
const providerId = String(params.providerId || "").trim();
|
|
89
81
|
const providerType = params.providerType;
|
|
90
82
|
const baseUrl = normalizeBaseUrl(params.baseUrl) || resolveProviderDefaultBaseUrl(providerType);
|
|
91
|
-
const apiKey =
|
|
83
|
+
const apiKey = String(params.apiKey || "").trim() || undefined;
|
|
92
84
|
if (!apiKey) {
|
|
93
85
|
return {
|
|
94
86
|
providerId,
|
|
95
87
|
providerType,
|
|
96
88
|
ok: false,
|
|
97
89
|
models: [],
|
|
98
|
-
error: "Missing apiKey
|
|
90
|
+
error: "Missing apiKey",
|
|
99
91
|
};
|
|
100
92
|
}
|
|
101
93
|
|
package/src/cli/shared/Config.ts
CHANGED
|
@@ -59,8 +59,8 @@ function readDowncityConfigByPath(
|
|
|
59
59
|
throw new Error("Invalid downcity.json: expected object");
|
|
60
60
|
}
|
|
61
61
|
const candidate = raw as Partial<DowncityConfig>;
|
|
62
|
-
if (typeof candidate.
|
|
63
|
-
throw new Error("Invalid downcity.json: missing required fields
|
|
62
|
+
if (typeof candidate.id !== "string" || typeof candidate.version !== "string") {
|
|
63
|
+
throw new Error("Invalid downcity.json: missing required fields id/version");
|
|
64
64
|
}
|
|
65
65
|
return { downcityJsonPath, config: candidate as DowncityConfig };
|
|
66
66
|
}
|
package/src/cli/shared/Env.ts
CHANGED
|
@@ -4,37 +4,16 @@
|
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - `env` 是平台 Env 的资源命令,支持 list/set/delete。
|
|
6
6
|
* - 默认不输出任何 secret value;只在显式 set 时写入值。
|
|
7
|
-
* -
|
|
7
|
+
* - 当前只保留平台全局 env,不再区分 agent 私有层。
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
10
|
import type { Command } from "commander";
|
|
11
11
|
import { PlatformStore } from "@/platform/store/index.js";
|
|
12
|
-
import type { StoredEnvEntry
|
|
12
|
+
import type { StoredEnvEntry } from "@downcity/agent";
|
|
13
13
|
import { emitCliBlock, emitCliList } from "./CliReporter.js";
|
|
14
14
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
15
15
|
import { parseBoolean } from "./IndexSupport.js";
|
|
16
16
|
|
|
17
|
-
/**
|
|
18
|
-
* env 子命令的 scope 类型。
|
|
19
|
-
*/
|
|
20
|
-
type KeysScope = StoredEnvScope | "all";
|
|
21
|
-
|
|
22
|
-
/**
|
|
23
|
-
* 规范化 env scope。
|
|
24
|
-
*/
|
|
25
|
-
function normalizeKeysScope(value: string | undefined, options?: {
|
|
26
|
-
/**
|
|
27
|
-
* 是否允许 `all`。
|
|
28
|
-
*/
|
|
29
|
-
allowAll?: boolean;
|
|
30
|
-
}): KeysScope {
|
|
31
|
-
const normalized = String(value || "").trim().toLowerCase();
|
|
32
|
-
if (!normalized || normalized === "global") return "global";
|
|
33
|
-
if (normalized === "agent") return "agent";
|
|
34
|
-
if (options?.allowAll === true && normalized === "all") return "all";
|
|
35
|
-
throw new Error(`Unsupported scope: ${value}`);
|
|
36
|
-
}
|
|
37
|
-
|
|
38
17
|
/**
|
|
39
18
|
* 规范化 env key。
|
|
40
19
|
*/
|
|
@@ -46,17 +25,6 @@ function normalizeEnvKey(value: string): string {
|
|
|
46
25
|
return key;
|
|
47
26
|
}
|
|
48
27
|
|
|
49
|
-
/**
|
|
50
|
-
* 规范化非空文本。
|
|
51
|
-
*/
|
|
52
|
-
function normalizeRequiredText(value: string | undefined, fieldName: string): string {
|
|
53
|
-
const normalized = String(value || "").trim();
|
|
54
|
-
if (!normalized) {
|
|
55
|
-
throw new Error(`${fieldName} is required`);
|
|
56
|
-
}
|
|
57
|
-
return normalized;
|
|
58
|
-
}
|
|
59
|
-
|
|
60
28
|
/**
|
|
61
29
|
* 把 env value 格式化成 `.env` 可解析的值。
|
|
62
30
|
*
|
|
@@ -93,13 +61,13 @@ function formatDotenvEntries(entries: StoredEnvEntry[]): string {
|
|
|
93
61
|
* 判断当前命令是否处在 agent shell 执行上下文。
|
|
94
62
|
*
|
|
95
63
|
* 关键点(中文)
|
|
96
|
-
* - agent shell 会注入 `DC_AGENT_PATH/
|
|
64
|
+
* - agent shell 会注入 `DC_AGENT_PATH/DC_AGENT_ID`,用于嵌套 city CLI 定位当前 agent。
|
|
97
65
|
* - `env copy` 会导出 secret 明文,不能允许 agent 自己调用。
|
|
98
66
|
*/
|
|
99
67
|
function isAgentShellExecution(): boolean {
|
|
100
68
|
return Boolean(
|
|
101
69
|
String(process.env.DC_AGENT_PATH || "").trim() ||
|
|
102
|
-
String(process.env.
|
|
70
|
+
String(process.env.DC_AGENT_ID || "").trim(),
|
|
103
71
|
);
|
|
104
72
|
}
|
|
105
73
|
|
|
@@ -111,66 +79,10 @@ function assertEnvCopyAllowedFromLocalCli(): void {
|
|
|
111
79
|
throw new Error("city env copy can only be run from the local CLI, not from an agent shell.");
|
|
112
80
|
}
|
|
113
81
|
|
|
114
|
-
|
|
115
|
-
* 解析命令输入最终使用的 env scope。
|
|
116
|
-
*/
|
|
117
|
-
function resolveKeysCommandScope(params: {
|
|
118
|
-
/**
|
|
119
|
-
* 命令行 `--scope` 原始值。
|
|
120
|
-
*/
|
|
121
|
-
scope?: string;
|
|
122
|
-
/**
|
|
123
|
-
* 命令行 `--agent` 原始值。
|
|
124
|
-
*/
|
|
125
|
-
agentId?: string;
|
|
126
|
-
/**
|
|
127
|
-
* 当前命令是否允许 `all`。
|
|
128
|
-
*/
|
|
129
|
-
allowAll?: boolean;
|
|
130
|
-
}): {
|
|
131
|
-
/**
|
|
132
|
-
* 最终 env scope。
|
|
133
|
-
*/
|
|
134
|
-
scope: KeysScope;
|
|
135
|
-
/**
|
|
136
|
-
* 规范化后的 agentId。
|
|
137
|
-
*/
|
|
138
|
-
agentId?: string;
|
|
139
|
-
} {
|
|
140
|
-
const agentId = String(params.agentId || "").trim();
|
|
141
|
-
if (agentId) {
|
|
142
|
-
return {
|
|
143
|
-
scope: "agent",
|
|
144
|
-
agentId,
|
|
145
|
-
};
|
|
146
|
-
}
|
|
147
|
-
|
|
148
|
-
return {
|
|
149
|
-
scope: normalizeKeysScope(params.scope, {
|
|
150
|
-
allowAll: params.allowAll === true,
|
|
151
|
-
}),
|
|
152
|
-
};
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
/**
|
|
156
|
-
* 读取指定范围的 env 条目。
|
|
157
|
-
*/
|
|
158
|
-
async function listKeysEntries(params: {
|
|
159
|
-
/**
|
|
160
|
-
* scope 过滤。
|
|
161
|
-
*/
|
|
162
|
-
scope: KeysScope;
|
|
163
|
-
/**
|
|
164
|
-
* agent 过滤。
|
|
165
|
-
*/
|
|
166
|
-
agentId?: string;
|
|
167
|
-
}): Promise<StoredEnvEntry[]> {
|
|
82
|
+
async function listKeysEntries(): Promise<StoredEnvEntry[]> {
|
|
168
83
|
const store = new PlatformStore();
|
|
169
84
|
try {
|
|
170
|
-
|
|
171
|
-
return await store.listEnvEntries();
|
|
172
|
-
}
|
|
173
|
-
return await store.listEnvEntries(params.scope, params.agentId);
|
|
85
|
+
return await store.listEnvEntries();
|
|
174
86
|
} finally {
|
|
175
87
|
store.close();
|
|
176
88
|
}
|
|
@@ -180,23 +92,12 @@ async function listKeysEntries(params: {
|
|
|
180
92
|
* 输出 env 列表。
|
|
181
93
|
*/
|
|
182
94
|
async function emitKeysList(params: {
|
|
183
|
-
/**
|
|
184
|
-
* scope 过滤。
|
|
185
|
-
*/
|
|
186
|
-
scope: KeysScope;
|
|
187
|
-
/**
|
|
188
|
-
* agent 过滤。
|
|
189
|
-
*/
|
|
190
|
-
agentId?: string;
|
|
191
95
|
/**
|
|
192
96
|
* 是否以 JSON 输出。
|
|
193
97
|
*/
|
|
194
98
|
asJson?: boolean;
|
|
195
99
|
}): Promise<void> {
|
|
196
|
-
const entries = await listKeysEntries(
|
|
197
|
-
scope: params.scope,
|
|
198
|
-
agentId: params.agentId,
|
|
199
|
-
});
|
|
100
|
+
const entries = await listKeysEntries();
|
|
200
101
|
|
|
201
102
|
if (params.asJson === true) {
|
|
202
103
|
printResult({
|
|
@@ -204,14 +105,11 @@ async function emitKeysList(params: {
|
|
|
204
105
|
success: true,
|
|
205
106
|
title: "env list",
|
|
206
107
|
payload: {
|
|
207
|
-
scope: params.scope,
|
|
208
|
-
agentId: params.agentId,
|
|
209
108
|
count: entries.length,
|
|
210
109
|
keys: entries.map((item) => ({
|
|
211
110
|
key: item.key,
|
|
212
111
|
description: item.description || "",
|
|
213
112
|
scope: item.scope,
|
|
214
|
-
...(item.agentId ? { agentId: item.agentId } : {}),
|
|
215
113
|
createdAt: item.createdAt,
|
|
216
114
|
updatedAt: item.updatedAt,
|
|
217
115
|
})),
|
|
@@ -240,16 +138,8 @@ async function emitKeysList(params: {
|
|
|
240
138
|
facts: [
|
|
241
139
|
{
|
|
242
140
|
label: "Scope",
|
|
243
|
-
value:
|
|
141
|
+
value: "global",
|
|
244
142
|
},
|
|
245
|
-
...(item.agentId
|
|
246
|
-
? [
|
|
247
|
-
{
|
|
248
|
-
label: "Agent",
|
|
249
|
-
value: item.agentId,
|
|
250
|
-
},
|
|
251
|
-
]
|
|
252
|
-
: []),
|
|
253
143
|
...(item.description
|
|
254
144
|
? [
|
|
255
145
|
{
|
|
@@ -266,20 +156,8 @@ async function emitKeysList(params: {
|
|
|
266
156
|
/**
|
|
267
157
|
* 输出 dotenv 格式的 env 内容。
|
|
268
158
|
*/
|
|
269
|
-
async function emitDotenvCopy(
|
|
270
|
-
|
|
271
|
-
* scope 过滤。
|
|
272
|
-
*/
|
|
273
|
-
scope: KeysScope;
|
|
274
|
-
/**
|
|
275
|
-
* agent 过滤。
|
|
276
|
-
*/
|
|
277
|
-
agentId?: string;
|
|
278
|
-
}): Promise<void> {
|
|
279
|
-
const entries = await listKeysEntries({
|
|
280
|
-
scope: params.scope,
|
|
281
|
-
agentId: params.agentId,
|
|
282
|
-
});
|
|
159
|
+
async function emitDotenvCopy(): Promise<void> {
|
|
160
|
+
const entries = await listKeysEntries();
|
|
283
161
|
process.stdout.write(formatDotenvEntries(entries));
|
|
284
162
|
}
|
|
285
163
|
|
|
@@ -287,14 +165,6 @@ async function emitDotenvCopy(params: {
|
|
|
287
165
|
* 写入单个 env 条目。
|
|
288
166
|
*/
|
|
289
167
|
async function setKeyEntry(params: {
|
|
290
|
-
/**
|
|
291
|
-
* scope。
|
|
292
|
-
*/
|
|
293
|
-
scope: StoredEnvScope;
|
|
294
|
-
/**
|
|
295
|
-
* agentId。
|
|
296
|
-
*/
|
|
297
|
-
agentId?: string;
|
|
298
168
|
/**
|
|
299
169
|
* env key。
|
|
300
170
|
*/
|
|
@@ -315,8 +185,7 @@ async function setKeyEntry(params: {
|
|
|
315
185
|
const store = new PlatformStore();
|
|
316
186
|
try {
|
|
317
187
|
await store.upsertEnvEntry({
|
|
318
|
-
scope:
|
|
319
|
-
agentId: params.agentId,
|
|
188
|
+
scope: "global",
|
|
320
189
|
key: params.key,
|
|
321
190
|
value: params.value,
|
|
322
191
|
description: String(params.description || "").trim(),
|
|
@@ -332,8 +201,7 @@ async function setKeyEntry(params: {
|
|
|
332
201
|
title: "env set",
|
|
333
202
|
payload: {
|
|
334
203
|
action: "set",
|
|
335
|
-
scope:
|
|
336
|
-
agentId: params.agentId,
|
|
204
|
+
scope: "global",
|
|
337
205
|
key: params.key,
|
|
338
206
|
},
|
|
339
207
|
});
|
|
@@ -347,16 +215,8 @@ async function setKeyEntry(params: {
|
|
|
347
215
|
facts: [
|
|
348
216
|
{
|
|
349
217
|
label: "Scope",
|
|
350
|
-
value:
|
|
218
|
+
value: "global",
|
|
351
219
|
},
|
|
352
|
-
...(params.agentId
|
|
353
|
-
? [
|
|
354
|
-
{
|
|
355
|
-
label: "Agent",
|
|
356
|
-
value: params.agentId,
|
|
357
|
-
},
|
|
358
|
-
]
|
|
359
|
-
: []),
|
|
360
220
|
...(params.description
|
|
361
221
|
? [
|
|
362
222
|
{
|
|
@@ -373,14 +233,6 @@ async function setKeyEntry(params: {
|
|
|
373
233
|
* 删除单个 env 条目。
|
|
374
234
|
*/
|
|
375
235
|
function deleteKeyEntry(params: {
|
|
376
|
-
/**
|
|
377
|
-
* scope。
|
|
378
|
-
*/
|
|
379
|
-
scope: StoredEnvScope;
|
|
380
|
-
/**
|
|
381
|
-
* agentId。
|
|
382
|
-
*/
|
|
383
|
-
agentId?: string;
|
|
384
236
|
/**
|
|
385
237
|
* env key。
|
|
386
238
|
*/
|
|
@@ -392,11 +244,7 @@ function deleteKeyEntry(params: {
|
|
|
392
244
|
}): void {
|
|
393
245
|
const store = new PlatformStore();
|
|
394
246
|
try {
|
|
395
|
-
store.removeEnvEntry(
|
|
396
|
-
scope: params.scope,
|
|
397
|
-
agentId: params.agentId,
|
|
398
|
-
key: params.key,
|
|
399
|
-
});
|
|
247
|
+
store.removeEnvEntry(params.key);
|
|
400
248
|
} finally {
|
|
401
249
|
store.close();
|
|
402
250
|
}
|
|
@@ -408,8 +256,7 @@ function deleteKeyEntry(params: {
|
|
|
408
256
|
title: "env delete",
|
|
409
257
|
payload: {
|
|
410
258
|
action: "delete",
|
|
411
|
-
scope:
|
|
412
|
-
agentId: params.agentId,
|
|
259
|
+
scope: "global",
|
|
413
260
|
key: params.key,
|
|
414
261
|
},
|
|
415
262
|
});
|
|
@@ -423,16 +270,8 @@ function deleteKeyEntry(params: {
|
|
|
423
270
|
facts: [
|
|
424
271
|
{
|
|
425
272
|
label: "Scope",
|
|
426
|
-
value:
|
|
273
|
+
value: "global",
|
|
427
274
|
},
|
|
428
|
-
...(params.agentId
|
|
429
|
-
? [
|
|
430
|
-
{
|
|
431
|
-
label: "Agent",
|
|
432
|
-
value: params.agentId,
|
|
433
|
-
},
|
|
434
|
-
]
|
|
435
|
-
: []),
|
|
436
275
|
],
|
|
437
276
|
});
|
|
438
277
|
}
|
|
@@ -449,19 +288,10 @@ export function registerEnvCommand(program: Command): void {
|
|
|
449
288
|
env
|
|
450
289
|
.command("list")
|
|
451
290
|
.description("列出平台 Env 中已配置的 key")
|
|
452
|
-
.option("--scope <scope>", "按作用域过滤:global|agent|all", "global")
|
|
453
|
-
.option("--agent <agentId>", "仅列出指定 agent 的私有 env(会隐式使用 --scope agent)")
|
|
454
291
|
.option("--json [enabled]", "以 JSON 输出", parseBoolean)
|
|
455
292
|
.helpOption("--help", "display help for command")
|
|
456
|
-
.action(async (options: {
|
|
457
|
-
const resolved = resolveKeysCommandScope({
|
|
458
|
-
scope: options.scope,
|
|
459
|
-
agentId: options.agent,
|
|
460
|
-
allowAll: true,
|
|
461
|
-
});
|
|
293
|
+
.action(async (options: { json?: boolean }) => {
|
|
462
294
|
await emitKeysList({
|
|
463
|
-
scope: resolved.scope,
|
|
464
|
-
agentId: resolved.agentId,
|
|
465
295
|
asJson: options.json === true,
|
|
466
296
|
});
|
|
467
297
|
});
|
|
@@ -469,28 +299,15 @@ export function registerEnvCommand(program: Command): void {
|
|
|
469
299
|
env
|
|
470
300
|
.command("set <key> <value>")
|
|
471
301
|
.description("新增或更新平台 Env 中的 key")
|
|
472
|
-
.option("--scope <scope>", "写入作用域:global|agent", "global")
|
|
473
|
-
.option("--agent <agentId>", "指定 agent 私有 env(会隐式使用 --scope agent)")
|
|
474
302
|
.option("-d, --description <description>", "设置 key 描述")
|
|
475
303
|
.option("--json [enabled]", "以 JSON 输出", parseBoolean)
|
|
476
304
|
.helpOption("--help", "display help for command")
|
|
477
305
|
.action(async (
|
|
478
306
|
keyInput: string,
|
|
479
307
|
valueInput: string,
|
|
480
|
-
options: {
|
|
308
|
+
options: { description?: string; json?: boolean },
|
|
481
309
|
) => {
|
|
482
|
-
const resolved = resolveKeysCommandScope({
|
|
483
|
-
scope: options.scope,
|
|
484
|
-
agentId: options.agent,
|
|
485
|
-
allowAll: false,
|
|
486
|
-
});
|
|
487
|
-
if (resolved.scope === "all") {
|
|
488
|
-
throw new Error("env set does not support scope=all");
|
|
489
|
-
}
|
|
490
|
-
|
|
491
310
|
await setKeyEntry({
|
|
492
|
-
scope: resolved.scope,
|
|
493
|
-
agentId: resolved.agentId,
|
|
494
311
|
key: normalizeEnvKey(keyInput),
|
|
495
312
|
value: String(valueInput ?? ""),
|
|
496
313
|
description: String(options.description || "").trim(),
|
|
@@ -501,54 +318,29 @@ export function registerEnvCommand(program: Command): void {
|
|
|
501
318
|
env
|
|
502
319
|
.command("copy")
|
|
503
320
|
.description("按 .env 文件格式输出平台 Env 的明文值")
|
|
504
|
-
.option("--scope <scope>", "按作用域复制:global|agent|all", "global")
|
|
505
|
-
.option("--agent <agentId>", "复制指定 agent 的私有 env(会隐式使用 --scope agent)")
|
|
506
321
|
.helpOption("--help", "display help for command")
|
|
507
|
-
.action(async (
|
|
322
|
+
.action(async () => {
|
|
508
323
|
assertEnvCopyAllowedFromLocalCli();
|
|
509
|
-
|
|
510
|
-
scope: options.scope,
|
|
511
|
-
agentId: options.agent,
|
|
512
|
-
allowAll: true,
|
|
513
|
-
});
|
|
514
|
-
await emitDotenvCopy({
|
|
515
|
-
scope: resolved.scope,
|
|
516
|
-
agentId: resolved.agentId,
|
|
517
|
-
});
|
|
324
|
+
await emitDotenvCopy();
|
|
518
325
|
});
|
|
519
326
|
|
|
520
327
|
env
|
|
521
328
|
.command("delete <key>")
|
|
522
329
|
.description("删除平台 Env 中的 key")
|
|
523
|
-
.option("--scope <scope>", "删除作用域:global|agent", "global")
|
|
524
|
-
.option("--agent <agentId>", "指定 agent 私有 env(会隐式使用 --scope agent)")
|
|
525
330
|
.option("--json [enabled]", "以 JSON 输出", parseBoolean)
|
|
526
331
|
.helpOption("--help", "display help for command")
|
|
527
332
|
.action(async (
|
|
528
333
|
keyInput: string,
|
|
529
|
-
options: {
|
|
334
|
+
options: { json?: boolean },
|
|
530
335
|
) => {
|
|
531
|
-
const resolved = resolveKeysCommandScope({
|
|
532
|
-
scope: options.scope,
|
|
533
|
-
agentId: options.agent,
|
|
534
|
-
allowAll: false,
|
|
535
|
-
});
|
|
536
|
-
if (resolved.scope === "all") {
|
|
537
|
-
throw new Error("env delete does not support scope=all");
|
|
538
|
-
}
|
|
539
|
-
|
|
540
336
|
deleteKeyEntry({
|
|
541
|
-
scope: resolved.scope,
|
|
542
|
-
agentId: resolved.agentId,
|
|
543
337
|
key: normalizeEnvKey(keyInput),
|
|
544
338
|
asJson: options.json === true,
|
|
545
339
|
});
|
|
546
340
|
});
|
|
547
341
|
|
|
548
342
|
env.action(async () => {
|
|
549
|
-
await emitKeysList({
|
|
550
|
-
scope: "global",
|
|
551
|
-
});
|
|
343
|
+
await emitKeysList({});
|
|
552
344
|
});
|
|
553
345
|
|
|
554
346
|
env.showHelpAfterError();
|
|
@@ -97,6 +97,7 @@ export function registerAgentCommands(
|
|
|
97
97
|
.command("start [path]")
|
|
98
98
|
.description("启动 Agent 进程(后台/前台)")
|
|
99
99
|
.addOption(new context.hiddenPortOption("--port <port>").argParser(parsePort).hideHelp())
|
|
100
|
+
.addOption(new context.hiddenPortOption("--rpc-port <port>").argParser(parsePort).hideHelp())
|
|
100
101
|
.option("-h, --host <host>", "服务主机(默认 0.0.0.0)")
|
|
101
102
|
.option("--foreground [enabled]", "前台启动(仅当前终端)", parseBoolean)
|
|
102
103
|
.helpOption("--help", "display help for command")
|
|
@@ -119,12 +120,11 @@ export function registerAgentCommands(
|
|
|
119
120
|
agent
|
|
120
121
|
.command("chat")
|
|
121
122
|
.description("在终端中与指定 Agent 对话(交互式或一次性)")
|
|
122
|
-
.option("-t, --to <
|
|
123
|
+
.option("-t, --to <id>", "目标 agent id(省略时交互选择)")
|
|
123
124
|
.option("-m, --message <text>", "一次性发送一轮消息并退出")
|
|
124
125
|
.option("--json [enabled]", "一次性模式下以 JSON 输出", parseBoolean)
|
|
125
|
-
.option("--host <host>", "
|
|
126
|
+
.option("--host <host>", "RPC host(覆盖自动解析)")
|
|
126
127
|
.addOption(new context.hiddenPortOption("--port <port>").argParser(parsePort).hideHelp())
|
|
127
|
-
.option("--token <token>", "覆盖 Bearer Token(仅远程 HTTP 调用需要)")
|
|
128
128
|
.helpOption("--help", "display help for command")
|
|
129
129
|
.action(createVersionBanner(
|
|
130
130
|
context.version,
|
|
@@ -135,7 +135,6 @@ export function registerAgentCommands(
|
|
|
135
135
|
json?: boolean;
|
|
136
136
|
host?: string;
|
|
137
137
|
port?: number;
|
|
138
|
-
token?: string;
|
|
139
138
|
},
|
|
140
139
|
) => {
|
|
141
140
|
await chatCommand(options);
|
|
@@ -103,18 +103,24 @@ export const sleep = async (ms: number): Promise<void> =>
|
|
|
103
103
|
new Promise((resolve) => setTimeout(resolve, ms));
|
|
104
104
|
|
|
105
105
|
/**
|
|
106
|
-
* 从项目根目录推断 agent
|
|
106
|
+
* 从项目根目录推断 agent id。
|
|
107
107
|
*/
|
|
108
|
-
export function
|
|
109
|
-
const fallback = basename(projectRoot)
|
|
108
|
+
export function resolveAgentId(projectRoot: string): string {
|
|
109
|
+
const fallback = basename(projectRoot)
|
|
110
|
+
.trim()
|
|
111
|
+
.toLowerCase()
|
|
112
|
+
.replace(/[^a-z0-9]+/g, "_")
|
|
113
|
+
.replace(/^_+|_+$/g, "")
|
|
114
|
+
.replace(/_{2,}/g, "_")
|
|
115
|
+
.trim() || basename(projectRoot);
|
|
110
116
|
const shipJsonPath = join(projectRoot, "downcity.json");
|
|
111
117
|
if (!existsSync(shipJsonPath)) return fallback;
|
|
112
118
|
|
|
113
119
|
try {
|
|
114
120
|
const raw = readFileSync(shipJsonPath, "utf-8");
|
|
115
|
-
const parsed = JSON.parse(raw) as {
|
|
116
|
-
if (typeof parsed.
|
|
117
|
-
return parsed.
|
|
121
|
+
const parsed = JSON.parse(raw) as { id?: unknown };
|
|
122
|
+
if (typeof parsed.id === "string" && parsed.id.trim()) {
|
|
123
|
+
return parsed.id.trim();
|
|
118
124
|
}
|
|
119
125
|
} catch {
|
|
120
126
|
// ignore parse errors and fallback to dirname
|
|
@@ -128,11 +134,11 @@ export function resolveAgentName(projectRoot: string): string {
|
|
|
128
134
|
*/
|
|
129
135
|
export function injectAgentContext(pathInput: string = "."): {
|
|
130
136
|
projectRoot: string;
|
|
131
|
-
|
|
137
|
+
agentId: string;
|
|
132
138
|
} {
|
|
133
139
|
const projectRoot = resolve(String(pathInput || "."));
|
|
134
|
-
const
|
|
140
|
+
const agentId = resolveAgentId(projectRoot);
|
|
135
141
|
process.env.DC_AGENT_PATH = projectRoot;
|
|
136
|
-
process.env.
|
|
137
|
-
return { projectRoot,
|
|
142
|
+
process.env.DC_AGENT_ID = agentId;
|
|
143
|
+
return { projectRoot, agentId };
|
|
138
144
|
}
|
|
@@ -10,7 +10,6 @@
|
|
|
10
10
|
import path from "node:path";
|
|
11
11
|
import type { Command } from "commander";
|
|
12
12
|
import {
|
|
13
|
-
callAgentTransport,
|
|
14
13
|
parseActionScheduleRunAtMsOrThrow,
|
|
15
14
|
} from "@downcity/agent";
|
|
16
15
|
import { listPluginsWithLifecycle } from "@downcity/agent";
|
|
@@ -19,6 +18,7 @@ import type { JsonObject, JsonValue } from "@downcity/agent";
|
|
|
19
18
|
import type { PluginActionScheduleInput } from "@downcity/agent";
|
|
20
19
|
import type { PluginCommandResponse } from "@downcity/agent";
|
|
21
20
|
import type { PluginCliBaseOptions } from "@downcity/agent";
|
|
21
|
+
import { callServer } from "@/process/daemon/Client.js";
|
|
22
22
|
import { printResult } from "@/utils/cli/CliOutput.js";
|
|
23
23
|
import { parseBoolean, parsePort } from "./IndexSupport.js";
|
|
24
24
|
import { runManagedPluginControlCommand } from "./ManagedPluginRemote.js";
|
|
@@ -207,7 +207,7 @@ function registerPluginActionCommand(params: {
|
|
|
207
207
|
.option("--path <path>", "项目根目录(默认当前目录)", ".")
|
|
208
208
|
.option("--host <host>", "Server host(覆盖自动解析)")
|
|
209
209
|
.option("--port <port>", "Server port(覆盖自动解析)", parsePort)
|
|
210
|
-
.option("--token <token>", "覆盖 Bearer Token
|
|
210
|
+
.option("--token <token>", "覆盖 Bearer Token(按 HTTP daemon 调用时可选)")
|
|
211
211
|
.option("--json [enabled]", "以 JSON 输出", parseBoolean, true);
|
|
212
212
|
|
|
213
213
|
commandSpec.configure?.(actionCommand);
|
|
@@ -278,7 +278,7 @@ function registerPluginActionCommand(params: {
|
|
|
278
278
|
return;
|
|
279
279
|
}
|
|
280
280
|
|
|
281
|
-
const remote = await
|
|
281
|
+
const remote = await callServer<PluginCommandResponse>({
|
|
282
282
|
projectRoot: resolveProjectRoot(bridgeOptions.path),
|
|
283
283
|
path: "/api/plugins/command",
|
|
284
284
|
method: "POST",
|
|
@@ -330,7 +330,7 @@ function attachPluginLifecycleOptions(command: Command): Command {
|
|
|
330
330
|
.option("--path <path>", "项目根目录(默认当前目录)", ".")
|
|
331
331
|
.option("--host <host>", "Server host(覆盖自动解析)")
|
|
332
332
|
.option("--port <port>", "Server port(覆盖自动解析)", parsePort)
|
|
333
|
-
.option("--token <token>", "覆盖 Bearer Token
|
|
333
|
+
.option("--token <token>", "覆盖 Bearer Token(按 HTTP daemon 调用时可选)")
|
|
334
334
|
.option("--json [enabled]", "以 JSON 输出", parseBoolean, true);
|
|
335
335
|
}
|
|
336
336
|
|