@downcity/city 1.1.32 → 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 +10 -3
- 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.d.ts.map +1 -1
- package/bin/cli/agent/Init.js +17 -17
- 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 +44 -30
- 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.d.ts.map +1 -1
- package/bin/cli/control-plane/ControlPlaneProcess.js +7 -8
- 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/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/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 +2 -1
- package/bin/cli/shared/ManagedPluginActionCommands.d.ts.map +1 -1
- package/bin/cli/shared/ManagedPluginActionCommands.js +9 -7
- 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/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 +6 -6
- package/bin/cli/shared/PluginTargetSupport.d.ts.map +1 -1
- package/bin/cli/shared/PluginTargetSupport.js +23 -24
- 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 +22 -16
- 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/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 +4 -3
- 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/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 +2 -2
- package/bin/control/gateway/AgentActions.d.ts.map +1 -1
- package/bin/control/gateway/AgentActions.js +23 -18
- 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 +6 -6
- package/bin/model/runtime/CreateRuntimeModel.d.ts.map +1 -1
- package/bin/model/runtime/CreateRuntimeModel.js +44 -53
- 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/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/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/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 -2
- package/public/app.js +3 -3
- package/src/cli/Index.ts +13 -3
- 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 +22 -21
- package/src/cli/agent/Restart.ts +2 -2
- package/src/cli/agent/Run.ts +46 -30
- package/src/cli/agent/Start.ts +2 -2
- package/src/cli/agent/Stop.ts +2 -2
- package/src/cli/control-plane/ControlPlaneProcess.ts +7 -8
- 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/ChatAuth.ts +10 -11
- package/src/cli/shared/ChatManager.ts +2 -3
- 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 +15 -12
- package/src/cli/shared/ManagedPluginRemote.ts +4 -4
- package/src/cli/shared/PluginScheduleCommand.ts +11 -10
- package/src/cli/shared/PluginTargetSupport.ts +25 -26
- package/src/cli/shared/Plugins.ts +26 -20
- 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/ChannelAccountApiRoutes.ts +2 -3
- package/src/control/ControlGateway.ts +6 -5
- package/src/control/EnvApiRoutes.ts +7 -91
- package/src/control/PlatformApiRoutes.ts +6 -6
- package/src/control/PluginApiRoutes.ts +37 -27
- package/src/control/gateway/AgentActions.ts +26 -21
- 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 +51 -59
- package/src/model/runtime/ExecutionModelBinding.ts +120 -0
- 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/process/registry/AgentHostRuntime.ts +1 -163
- 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/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/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/platform/chatAuthorization/Store.ts +0 -181
- package/src/process/rpc/Client.ts +0 -113
- package/src/process/rpc/Paths.ts +0 -43
|
@@ -14,15 +14,12 @@ import { getPlatformStoreDbPath } from "@/process/registry/CityPaths.js";
|
|
|
14
14
|
import { ensurePlatformStoreSchema } from "./StoreSchema.js";
|
|
15
15
|
import type { PlatformStoreContext } from "./StoreShared.js";
|
|
16
16
|
import type {
|
|
17
|
-
StoredAgentEnvEntry,
|
|
18
17
|
StoredChannelAccount,
|
|
19
18
|
StoredEnvEntry,
|
|
20
|
-
StoredEnvScope,
|
|
21
19
|
StoredGlobalEnvEntry,
|
|
22
20
|
StoredModel,
|
|
23
21
|
StoredModelProvider,
|
|
24
22
|
StoredProviderMeta,
|
|
25
|
-
UpsertAgentEnvEntryInput,
|
|
26
23
|
UpsertChannelAccountInput,
|
|
27
24
|
UpsertEnvEntryInput,
|
|
28
25
|
UpsertGlobalEnvEntryInput,
|
|
@@ -55,23 +52,15 @@ import {
|
|
|
55
52
|
setSecureSettingJsonSync,
|
|
56
53
|
} from "./StoreSecureSettings.js";
|
|
57
54
|
import {
|
|
58
|
-
clearAgentEnvEntries,
|
|
59
55
|
clearGlobalEnvEntries,
|
|
60
|
-
getAgentEnvMap,
|
|
61
|
-
getAgentEnvMapSync,
|
|
62
56
|
getGlobalEnvMap,
|
|
63
57
|
getGlobalEnvMapSync,
|
|
64
|
-
listAgentEnvEntries,
|
|
65
|
-
listAgentEnvEntriesSync,
|
|
66
|
-
listAllAgentEnvEntries,
|
|
67
58
|
listEnvEntries,
|
|
68
59
|
listEnvEntriesSync,
|
|
69
60
|
listGlobalEnvEntries,
|
|
70
61
|
listGlobalEnvEntriesSync,
|
|
71
|
-
removeAgentEnvEntry,
|
|
72
62
|
removeEnvEntry,
|
|
73
63
|
removeGlobalEnvEntry,
|
|
74
|
-
upsertAgentEnvEntry,
|
|
75
64
|
upsertEnvEntry,
|
|
76
65
|
upsertGlobalEnvEntry,
|
|
77
66
|
} from "./StoreEnvRepository.js";
|
|
@@ -204,8 +193,6 @@ export class PlatformStore {
|
|
|
204
193
|
clearStoredModelsAndProviders(this.context);
|
|
205
194
|
this.sqlite.exec("DELETE FROM platform_secure_settings;");
|
|
206
195
|
this.sqlite.exec("DELETE FROM env_entries;");
|
|
207
|
-
this.sqlite.exec("DELETE FROM global_env;");
|
|
208
|
-
this.sqlite.exec("DELETE FROM agent_env;");
|
|
209
196
|
this.sqlite.exec("DELETE FROM channel_accounts;");
|
|
210
197
|
}
|
|
211
198
|
|
|
@@ -299,15 +286,15 @@ export class PlatformStore {
|
|
|
299
286
|
/**
|
|
300
287
|
* 查询 env 条目(同步)。
|
|
301
288
|
*/
|
|
302
|
-
listEnvEntriesSync(
|
|
303
|
-
return listEnvEntriesSync(this.context
|
|
289
|
+
listEnvEntriesSync(): StoredEnvEntry[] {
|
|
290
|
+
return listEnvEntriesSync(this.context);
|
|
304
291
|
}
|
|
305
292
|
|
|
306
293
|
/**
|
|
307
294
|
* 查询 env 条目(异步)。
|
|
308
295
|
*/
|
|
309
|
-
async listEnvEntries(
|
|
310
|
-
return await listEnvEntries(this.context
|
|
296
|
+
async listEnvEntries(): Promise<StoredEnvEntry[]> {
|
|
297
|
+
return await listEnvEntries(this.context);
|
|
311
298
|
}
|
|
312
299
|
|
|
313
300
|
/**
|
|
@@ -320,8 +307,8 @@ export class PlatformStore {
|
|
|
320
307
|
/**
|
|
321
308
|
* 删除单个 env 条目。
|
|
322
309
|
*/
|
|
323
|
-
removeEnvEntry(
|
|
324
|
-
removeEnvEntry(this.context,
|
|
310
|
+
removeEnvEntry(keyInput: string): void {
|
|
311
|
+
removeEnvEntry(this.context, keyInput);
|
|
325
312
|
}
|
|
326
313
|
|
|
327
314
|
/**
|
|
@@ -332,23 +319,23 @@ export class PlatformStore {
|
|
|
332
319
|
}
|
|
333
320
|
|
|
334
321
|
/**
|
|
335
|
-
*
|
|
322
|
+
* 读取环境变量映射(同步解密)。
|
|
336
323
|
*/
|
|
337
|
-
|
|
324
|
+
getEnvMapSync(): Record<string, string> {
|
|
338
325
|
return getGlobalEnvMapSync(this.context);
|
|
339
326
|
}
|
|
340
327
|
|
|
341
328
|
/**
|
|
342
|
-
*
|
|
329
|
+
* 列出环境变量(解密后)。
|
|
343
330
|
*/
|
|
344
331
|
async listGlobalEnvEntries(): Promise<StoredGlobalEnvEntry[]> {
|
|
345
332
|
return await listGlobalEnvEntries(this.context);
|
|
346
333
|
}
|
|
347
334
|
|
|
348
335
|
/**
|
|
349
|
-
*
|
|
336
|
+
* 读取环境变量映射(解密后)。
|
|
350
337
|
*/
|
|
351
|
-
async
|
|
338
|
+
async getEnvMap(): Promise<Record<string, string>> {
|
|
352
339
|
return await getGlobalEnvMap(this.context);
|
|
353
340
|
}
|
|
354
341
|
|
|
@@ -373,62 +360,6 @@ export class PlatformStore {
|
|
|
373
360
|
clearGlobalEnvEntries(this.context);
|
|
374
361
|
}
|
|
375
362
|
|
|
376
|
-
/**
|
|
377
|
-
* 列出指定 agent 的私有环境变量(同步解密)。
|
|
378
|
-
*/
|
|
379
|
-
listAgentEnvEntriesSync(agentIdInput: string): StoredAgentEnvEntry[] {
|
|
380
|
-
return listAgentEnvEntriesSync(this.context, agentIdInput);
|
|
381
|
-
}
|
|
382
|
-
|
|
383
|
-
/**
|
|
384
|
-
* 读取指定 agent 的私有环境变量映射(同步解密)。
|
|
385
|
-
*/
|
|
386
|
-
getAgentEnvMapSync(agentIdInput: string): Record<string, string> {
|
|
387
|
-
return getAgentEnvMapSync(this.context, agentIdInput);
|
|
388
|
-
}
|
|
389
|
-
|
|
390
|
-
/**
|
|
391
|
-
* 列出指定 agent 的私有环境变量(解密后)。
|
|
392
|
-
*/
|
|
393
|
-
async listAgentEnvEntries(agentIdInput: string): Promise<StoredAgentEnvEntry[]> {
|
|
394
|
-
return await listAgentEnvEntries(this.context, agentIdInput);
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
/**
|
|
398
|
-
* 列出全部 agent 私有环境变量(解密后)。
|
|
399
|
-
*/
|
|
400
|
-
async listAllAgentEnvEntries(): Promise<StoredAgentEnvEntry[]> {
|
|
401
|
-
return await listAllAgentEnvEntries(this.context);
|
|
402
|
-
}
|
|
403
|
-
|
|
404
|
-
/**
|
|
405
|
-
* 读取指定 agent 的私有环境变量映射(解密后)。
|
|
406
|
-
*/
|
|
407
|
-
async getAgentEnvMap(agentIdInput: string): Promise<Record<string, string>> {
|
|
408
|
-
return await getAgentEnvMap(this.context, agentIdInput);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
/**
|
|
412
|
-
* 新增或更新 agent 私有环境变量。
|
|
413
|
-
*/
|
|
414
|
-
async upsertAgentEnvEntry(input: UpsertAgentEnvEntryInput): Promise<void> {
|
|
415
|
-
await upsertAgentEnvEntry(this.context, input);
|
|
416
|
-
}
|
|
417
|
-
|
|
418
|
-
/**
|
|
419
|
-
* 删除指定 agent 的单个环境变量。
|
|
420
|
-
*/
|
|
421
|
-
removeAgentEnvEntry(agentIdInput: string, keyInput: string): void {
|
|
422
|
-
removeAgentEnvEntry(this.context, agentIdInput, keyInput);
|
|
423
|
-
}
|
|
424
|
-
|
|
425
|
-
/**
|
|
426
|
-
* 清空指定 agent 的私有环境变量。
|
|
427
|
-
*/
|
|
428
|
-
clearAgentEnvEntries(agentIdInput: string): void {
|
|
429
|
-
clearAgentEnvEntries(this.context, agentIdInput);
|
|
430
|
-
}
|
|
431
|
-
|
|
432
363
|
/**
|
|
433
364
|
* 列出 channel accounts(同步解密)。
|
|
434
365
|
*/
|
|
@@ -48,8 +48,8 @@ export const modelsTable = sqliteTable(
|
|
|
48
48
|
* 平台 Env 统一存储表。
|
|
49
49
|
*
|
|
50
50
|
* 关键点(中文)
|
|
51
|
-
* -
|
|
52
|
-
* - `
|
|
51
|
+
* - 当前只保留平台全局 env。
|
|
52
|
+
* - 仍使用 `scope + agent_id + key` 复合主键,其中运行时固定写入 `global + ''`。
|
|
53
53
|
* - value 采用密文存储,解密仅在运行时内存中进行。
|
|
54
54
|
*/
|
|
55
55
|
export const envEntriesTable = sqliteTable(
|
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
* 关键点
|
|
5
5
|
* - daemon(来自 `agent start` / `agent restart`)会拉起一个前台 `agent start`
|
|
6
6
|
* 进程(显式 `--foreground true`),这里负责拼装其 argv。
|
|
7
|
+
* - city 托管的 HTTP gateway 与 agent 本机 RPC 使用不同端口,避免职责混用。
|
|
7
8
|
*/
|
|
8
9
|
|
|
9
10
|
import type { StartOptions } from "@downcity/agent";
|
|
@@ -26,13 +27,35 @@ export const buildRunArgsFromOptions = async (
|
|
|
26
27
|
// 关键点(中文):host 未指定时统一落到 0.0.0.0,保持历史监听行为。
|
|
27
28
|
const host = String(options.host || "0.0.0.0").trim() || "0.0.0.0";
|
|
28
29
|
|
|
29
|
-
//
|
|
30
|
+
// 关键点(中文):外层 HTTP gateway 端口统一由 city 分配。
|
|
30
31
|
const port = await allocateAvailablePort({ host });
|
|
31
32
|
if (!Number.isFinite(port) || Number.isNaN(port) || port <= 0 || port > 65535) {
|
|
32
33
|
throw new Error(`Invalid allocated port: ${String(port)}`);
|
|
33
34
|
}
|
|
34
35
|
|
|
36
|
+
// 关键点(中文):本机 RPC 端口独立分配到另一段端口区间,避免和 HTTP gateway 冲突。
|
|
37
|
+
const rpc_port =
|
|
38
|
+
typeof options.rpcPort === "number" && Number.isInteger(options.rpcPort)
|
|
39
|
+
? options.rpcPort
|
|
40
|
+
: await allocateAvailablePort({
|
|
41
|
+
host: "127.0.0.1",
|
|
42
|
+
start: 15314,
|
|
43
|
+
end: 16399,
|
|
44
|
+
});
|
|
45
|
+
if (
|
|
46
|
+
!Number.isFinite(rpc_port) ||
|
|
47
|
+
Number.isNaN(rpc_port) ||
|
|
48
|
+
rpc_port <= 0 ||
|
|
49
|
+
rpc_port > 65535
|
|
50
|
+
) {
|
|
51
|
+
throw new Error(`Invalid allocated rpc port: ${String(rpc_port)}`);
|
|
52
|
+
}
|
|
53
|
+
if (rpc_port === port) {
|
|
54
|
+
throw new Error(`HTTP port and RPC port must be different: ${port}`);
|
|
55
|
+
}
|
|
56
|
+
|
|
35
57
|
args.push("--port", String(port));
|
|
58
|
+
args.push("--rpc-port", String(rpc_port));
|
|
36
59
|
args.push("--host", host);
|
|
37
60
|
|
|
38
61
|
return args;
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 关键点(中文)
|
|
5
5
|
* - 业务模块统一通过 daemon API 与运行时通信。
|
|
6
|
-
* -
|
|
6
|
+
* - HTTP gateway 与本机 RPC 的地址解析分开,避免端口语义混淆。
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
9
|
import fs from "fs-extra";
|
|
@@ -62,29 +62,27 @@ function pickArgValue(args: string[], key: string): string | undefined {
|
|
|
62
62
|
return next || undefined;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
|
|
66
|
-
* 解析 daemon endpoint。
|
|
67
|
-
*
|
|
68
|
-
* 优先级(中文)
|
|
69
|
-
* 1) 显式入参 `host/port`
|
|
70
|
-
* 2) 环境变量 `DC_SERVER_*` / `DC_CTX_SERVER_*`
|
|
71
|
-
* 3) daemon meta args(`downcity.daemon.json`)
|
|
72
|
-
* 4) 默认 `127.0.0.1:5314`
|
|
73
|
-
*/
|
|
74
|
-
export function resolveDaemonEndpoint(params: {
|
|
65
|
+
type ResolveDaemonEndpointParams = {
|
|
75
66
|
projectRoot: string;
|
|
76
67
|
host?: string;
|
|
77
68
|
port?: number;
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function resolveDaemonEndpointFromSources(params: {
|
|
72
|
+
projectRoot: string;
|
|
73
|
+
explicit_host?: string;
|
|
74
|
+
explicit_port?: number;
|
|
75
|
+
env_host_name: string;
|
|
76
|
+
env_port_name: string;
|
|
77
|
+
arg_port_name: string;
|
|
78
|
+
default_host: string;
|
|
79
|
+
default_port: number;
|
|
78
80
|
}): DaemonEndpoint {
|
|
79
|
-
const explicitHost = normalizeHost(params.
|
|
80
|
-
const explicitPort = parsePortLike(params.
|
|
81
|
+
const explicitHost = normalizeHost(params.explicit_host);
|
|
82
|
+
const explicitPort = parsePortLike(params.explicit_port);
|
|
81
83
|
|
|
82
|
-
const envHost =
|
|
83
|
-
|
|
84
|
-
normalizeHost(process.env.DC_CTX_SERVER_HOST);
|
|
85
|
-
const envPort =
|
|
86
|
-
parsePortLike(process.env.DC_SERVER_PORT) ||
|
|
87
|
-
parsePortLike(process.env.DC_CTX_SERVER_PORT);
|
|
84
|
+
const envHost = normalizeHost(process.env[params.env_host_name]);
|
|
85
|
+
const envPort = parsePortLike(process.env[params.env_port_name]);
|
|
88
86
|
|
|
89
87
|
let daemonArgHost: string | undefined;
|
|
90
88
|
let daemonArgPort: number | undefined;
|
|
@@ -96,14 +94,14 @@ export function resolveDaemonEndpoint(params: {
|
|
|
96
94
|
? raw.args.map((item) => String(item))
|
|
97
95
|
: [];
|
|
98
96
|
daemonArgHost = normalizeHost(pickArgValue(args, "--host"));
|
|
99
|
-
daemonArgPort = parsePortLike(pickArgValue(args,
|
|
97
|
+
daemonArgPort = parsePortLike(pickArgValue(args, params.arg_port_name));
|
|
100
98
|
}
|
|
101
99
|
} catch {
|
|
102
100
|
// ignore daemon meta errors, fallback to other sources
|
|
103
101
|
}
|
|
104
102
|
|
|
105
|
-
const host = explicitHost || envHost || daemonArgHost ||
|
|
106
|
-
const port = explicitPort || envPort || daemonArgPort ||
|
|
103
|
+
const host = explicitHost || envHost || daemonArgHost || params.default_host;
|
|
104
|
+
const port = explicitPort || envPort || daemonArgPort || params.default_port;
|
|
107
105
|
|
|
108
106
|
return {
|
|
109
107
|
host,
|
|
@@ -112,6 +110,56 @@ export function resolveDaemonEndpoint(params: {
|
|
|
112
110
|
};
|
|
113
111
|
}
|
|
114
112
|
|
|
113
|
+
/**
|
|
114
|
+
* 解析 daemon endpoint。
|
|
115
|
+
*
|
|
116
|
+
* 优先级(中文)
|
|
117
|
+
* 1) 显式入参 `host/port`
|
|
118
|
+
* 2) 环境变量 `DC_CITY_HOST/DC_CITY_PORT`
|
|
119
|
+
* 3) daemon meta args(`downcity.daemon.json`)
|
|
120
|
+
* 4) 默认 `127.0.0.1:5314`
|
|
121
|
+
*/
|
|
122
|
+
export function resolveDaemonEndpoint(params: {
|
|
123
|
+
projectRoot: string;
|
|
124
|
+
host?: string;
|
|
125
|
+
port?: number;
|
|
126
|
+
}): DaemonEndpoint {
|
|
127
|
+
return resolveDaemonEndpointFromSources({
|
|
128
|
+
projectRoot: params.projectRoot,
|
|
129
|
+
explicit_host: params.host,
|
|
130
|
+
explicit_port: params.port,
|
|
131
|
+
env_host_name: "DC_CITY_HOST",
|
|
132
|
+
env_port_name: "DC_CITY_PORT",
|
|
133
|
+
arg_port_name: "--port",
|
|
134
|
+
default_host: "127.0.0.1",
|
|
135
|
+
default_port: 5314,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
|
|
139
|
+
/**
|
|
140
|
+
* 解析 daemon 本机 RPC endpoint。
|
|
141
|
+
*
|
|
142
|
+
* 优先级(中文)
|
|
143
|
+
* 1) 显式入参 `host/port`
|
|
144
|
+
* 2) 环境变量 `DC_AGENT_RPC_HOST/DC_AGENT_RPC_PORT`
|
|
145
|
+
* 3) daemon meta args(`downcity.daemon.json`)
|
|
146
|
+
* 4) 默认 `127.0.0.1:15314`
|
|
147
|
+
*/
|
|
148
|
+
export function resolveDaemonRpcEndpoint(
|
|
149
|
+
params: ResolveDaemonEndpointParams,
|
|
150
|
+
): DaemonEndpoint {
|
|
151
|
+
return resolveDaemonEndpointFromSources({
|
|
152
|
+
projectRoot: params.projectRoot,
|
|
153
|
+
explicit_host: params.host,
|
|
154
|
+
explicit_port: params.port,
|
|
155
|
+
env_host_name: "DC_AGENT_RPC_HOST",
|
|
156
|
+
env_port_name: "DC_AGENT_RPC_PORT",
|
|
157
|
+
arg_port_name: "--rpc-port",
|
|
158
|
+
default_host: "127.0.0.1",
|
|
159
|
+
default_port: 15314,
|
|
160
|
+
});
|
|
161
|
+
}
|
|
162
|
+
|
|
115
163
|
/**
|
|
116
164
|
* 调用 daemon JSON API。
|
|
117
165
|
*
|
|
@@ -132,6 +180,12 @@ export async function callServer<T>(
|
|
|
132
180
|
const method = params.method || "GET";
|
|
133
181
|
const hasBody = params.body !== undefined && method !== "GET";
|
|
134
182
|
const headers: Record<string, string> = {};
|
|
183
|
+
const timeoutMs =
|
|
184
|
+
typeof params.timeoutMs === "number" &&
|
|
185
|
+
Number.isFinite(params.timeoutMs) &&
|
|
186
|
+
params.timeoutMs > 0
|
|
187
|
+
? Math.floor(params.timeoutMs)
|
|
188
|
+
: undefined;
|
|
135
189
|
const authHeaderValue = formatCliBearerHeaderValue(
|
|
136
190
|
resolveCliAuthToken({
|
|
137
191
|
explicitToken: params.authToken,
|
|
@@ -145,11 +199,19 @@ export async function callServer<T>(
|
|
|
145
199
|
}
|
|
146
200
|
|
|
147
201
|
try {
|
|
202
|
+
const abortController = timeoutMs ? new AbortController() : undefined;
|
|
203
|
+
const timeoutHandle = timeoutMs
|
|
204
|
+
? setTimeout(() => abortController?.abort(), timeoutMs)
|
|
205
|
+
: undefined;
|
|
148
206
|
const response = await fetch(url, {
|
|
149
207
|
method,
|
|
150
208
|
headers: Object.keys(headers).length > 0 ? headers : undefined,
|
|
151
209
|
body: hasBody ? JSON.stringify(params.body) : undefined,
|
|
210
|
+
signal: abortController?.signal,
|
|
152
211
|
});
|
|
212
|
+
if (timeoutHandle) {
|
|
213
|
+
clearTimeout(timeoutHandle);
|
|
214
|
+
}
|
|
153
215
|
|
|
154
216
|
let data: JsonValue | null = null;
|
|
155
217
|
try {
|
|
@@ -174,6 +236,12 @@ export async function callServer<T>(
|
|
|
174
236
|
data: data as T,
|
|
175
237
|
};
|
|
176
238
|
} catch (error) {
|
|
239
|
+
if (timeoutMs && error instanceof Error && error.name === "AbortError") {
|
|
240
|
+
return {
|
|
241
|
+
success: false,
|
|
242
|
+
error: `Failed to call ${url}: timeout after ${timeoutMs}ms`,
|
|
243
|
+
};
|
|
244
|
+
}
|
|
177
245
|
return {
|
|
178
246
|
success: false,
|
|
179
247
|
error: `Failed to call ${url}: ${String(error)}`,
|
|
@@ -28,6 +28,7 @@ import {
|
|
|
28
28
|
upsertManagedAgentEntry,
|
|
29
29
|
} from "@/process/registry/CityRegistry.js";
|
|
30
30
|
import { signalDetachedProcess } from "@/process/registry/ProcessSweep.js";
|
|
31
|
+
import { mergeProcessEnvWithPlatformGlobalEnv } from "@/env/ProcessEnv.js";
|
|
31
32
|
|
|
32
33
|
/**
|
|
33
34
|
* 异步睡眠工具。
|
|
@@ -239,7 +240,7 @@ export const startDaemonProcess = async (params: {
|
|
|
239
240
|
const logFd = fs.openSync(logPath, "a");
|
|
240
241
|
|
|
241
242
|
const childEnv: NodeJS.ProcessEnv = {
|
|
242
|
-
...process.env,
|
|
243
|
+
...mergeProcessEnvWithPlatformGlobalEnv(process.env),
|
|
243
244
|
DOWNCITY_DAEMON: "1",
|
|
244
245
|
};
|
|
245
246
|
|
|
@@ -4,7 +4,7 @@
|
|
|
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 {
|
|
10
10
|
getCacheDirPath,
|
|
@@ -21,76 +21,9 @@ import {
|
|
|
21
21
|
import { persistProjectPluginConfig } from "@downcity/agent";
|
|
22
22
|
import type {
|
|
23
23
|
AgentPathRuntime,
|
|
24
|
-
AgentPlatformRuntime,
|
|
25
24
|
AgentPluginConfigRuntime,
|
|
26
|
-
ChatChannelAccountListItem,
|
|
27
|
-
StoredChannelAccount,
|
|
28
|
-
StoredChannelAccountChannel,
|
|
29
25
|
} from "@downcity/agent";
|
|
30
26
|
import type { DowncityConfig } from "@downcity/agent";
|
|
31
|
-
import { PlatformStore } from "@/platform/store/index.js";
|
|
32
|
-
import {
|
|
33
|
-
isCityPluginEnabled,
|
|
34
|
-
setCityPluginEnabled,
|
|
35
|
-
} from "@/platform/PluginLifecycle.js";
|
|
36
|
-
import {
|
|
37
|
-
readChatAuthorizationConfigSync,
|
|
38
|
-
setChatAuthorizationUserRole,
|
|
39
|
-
writeChatAuthorizationConfig,
|
|
40
|
-
} from "@/platform/chatAuthorization/Store.js";
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 脱敏显示密钥。
|
|
44
|
-
*
|
|
45
|
-
* 关键点(中文)
|
|
46
|
-
* - channel account 列表只返回安全视图,避免在 CLI/UI 展示链路泄露明文。
|
|
47
|
-
* - 保持和现有 model provider 脱敏规则一致,减少用户心智负担。
|
|
48
|
-
*/
|
|
49
|
-
function maskSecret(value: string | undefined): string | undefined {
|
|
50
|
-
const raw = String(value || "").trim();
|
|
51
|
-
if (!raw) return undefined;
|
|
52
|
-
if (raw.length <= 8) return "***";
|
|
53
|
-
return `${raw.slice(0, 4)}***${raw.slice(-4)}`;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 将存储层 channel account 转成对外安全视图。
|
|
58
|
-
*/
|
|
59
|
-
function toChannelAccountListItem(
|
|
60
|
-
account: StoredChannelAccount,
|
|
61
|
-
): ChatChannelAccountListItem {
|
|
62
|
-
return {
|
|
63
|
-
id: account.id,
|
|
64
|
-
channel: account.channel,
|
|
65
|
-
name: account.name,
|
|
66
|
-
identity: account.identity,
|
|
67
|
-
owner: account.owner,
|
|
68
|
-
creator: account.creator,
|
|
69
|
-
domain: account.domain,
|
|
70
|
-
sandbox: account.sandbox === true,
|
|
71
|
-
hasBotToken: !!String(account.botToken || "").trim(),
|
|
72
|
-
hasAppId: !!String(account.appId || "").trim(),
|
|
73
|
-
hasAppSecret: !!String(account.appSecret || "").trim(),
|
|
74
|
-
botTokenMasked: maskSecret(account.botToken),
|
|
75
|
-
appIdMasked: maskSecret(account.appId),
|
|
76
|
-
appSecretMasked: maskSecret(account.appSecret),
|
|
77
|
-
createdAt: account.createdAt,
|
|
78
|
-
updatedAt: account.updatedAt,
|
|
79
|
-
};
|
|
80
|
-
}
|
|
81
|
-
|
|
82
|
-
/**
|
|
83
|
-
* 归一化并校验 channel account 渠道名。
|
|
84
|
-
*/
|
|
85
|
-
function normalizeChannelAccountChannel(
|
|
86
|
-
channelInput: string,
|
|
87
|
-
): StoredChannelAccountChannel {
|
|
88
|
-
const channel = String(channelInput || "").trim().toLowerCase();
|
|
89
|
-
if (channel === "telegram" || channel === "feishu" || channel === "qq") {
|
|
90
|
-
return channel;
|
|
91
|
-
}
|
|
92
|
-
throw new Error(`Unsupported channel account channel: ${channelInput}`);
|
|
93
|
-
}
|
|
94
27
|
|
|
95
28
|
/**
|
|
96
29
|
* 创建当前项目的路径能力集合。
|
|
@@ -134,98 +67,3 @@ export function createAgentPluginConfigRuntime(projectRoot: string): AgentPlugin
|
|
|
134
67
|
},
|
|
135
68
|
};
|
|
136
69
|
}
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 创建当前项目的平台能力集合。
|
|
140
|
-
*
|
|
141
|
-
* 关键点(中文)
|
|
142
|
-
* - 这里先暴露 agent 当前已经需要的最小平台读能力。
|
|
143
|
-
* - 具体平台数据仍由 city 自己管理,agent 只消费这一层接口。
|
|
144
|
-
*/
|
|
145
|
-
export function createAgentPlatformRuntime(): AgentPlatformRuntime {
|
|
146
|
-
return {
|
|
147
|
-
getGlobalEnv: () => {
|
|
148
|
-
const store = new PlatformStore();
|
|
149
|
-
try {
|
|
150
|
-
return store.getGlobalEnvMapSync();
|
|
151
|
-
} finally {
|
|
152
|
-
store.close();
|
|
153
|
-
}
|
|
154
|
-
},
|
|
155
|
-
getAgentEnv: (projectRoot) => {
|
|
156
|
-
const store = new PlatformStore();
|
|
157
|
-
try {
|
|
158
|
-
return store.getAgentEnvMapSync(projectRoot);
|
|
159
|
-
} finally {
|
|
160
|
-
store.close();
|
|
161
|
-
}
|
|
162
|
-
},
|
|
163
|
-
listModels: () => {
|
|
164
|
-
const store = new PlatformStore();
|
|
165
|
-
try {
|
|
166
|
-
return store.listModels();
|
|
167
|
-
} finally {
|
|
168
|
-
store.close();
|
|
169
|
-
}
|
|
170
|
-
},
|
|
171
|
-
listProviders: async () => {
|
|
172
|
-
const store = new PlatformStore();
|
|
173
|
-
try {
|
|
174
|
-
return await store.listProviders();
|
|
175
|
-
} finally {
|
|
176
|
-
store.close();
|
|
177
|
-
}
|
|
178
|
-
},
|
|
179
|
-
getModel: (modelId) => {
|
|
180
|
-
const store = new PlatformStore();
|
|
181
|
-
try {
|
|
182
|
-
return store.getModel(modelId);
|
|
183
|
-
} finally {
|
|
184
|
-
store.close();
|
|
185
|
-
}
|
|
186
|
-
},
|
|
187
|
-
getChannelAccount: (channelAccountId) => {
|
|
188
|
-
const store = new PlatformStore();
|
|
189
|
-
try {
|
|
190
|
-
return store.getChannelAccountSync(channelAccountId);
|
|
191
|
-
} finally {
|
|
192
|
-
store.close();
|
|
193
|
-
}
|
|
194
|
-
},
|
|
195
|
-
listChannelAccounts: async () => {
|
|
196
|
-
const store = new PlatformStore();
|
|
197
|
-
try {
|
|
198
|
-
const accounts = await store.listChannelAccounts();
|
|
199
|
-
return accounts.map(toChannelAccountListItem);
|
|
200
|
-
} finally {
|
|
201
|
-
store.close();
|
|
202
|
-
}
|
|
203
|
-
},
|
|
204
|
-
updateChannelAccount: async (input) => {
|
|
205
|
-
const store = new PlatformStore();
|
|
206
|
-
try {
|
|
207
|
-
await store.upsertChannelAccount({
|
|
208
|
-
...input,
|
|
209
|
-
channel: normalizeChannelAccountChannel(input.channel),
|
|
210
|
-
});
|
|
211
|
-
} finally {
|
|
212
|
-
store.close();
|
|
213
|
-
}
|
|
214
|
-
},
|
|
215
|
-
removeChannelAccount: async (channelAccountId) => {
|
|
216
|
-
const store = new PlatformStore();
|
|
217
|
-
try {
|
|
218
|
-
store.removeChannelAccount(channelAccountId);
|
|
219
|
-
} finally {
|
|
220
|
-
store.close();
|
|
221
|
-
}
|
|
222
|
-
},
|
|
223
|
-
readChatAuthorizationConfig: (projectRoot) => readChatAuthorizationConfigSync(projectRoot),
|
|
224
|
-
writeChatAuthorizationConfig,
|
|
225
|
-
setChatAuthorizationUserRole,
|
|
226
|
-
isPluginEnabled: (pluginName) => isCityPluginEnabled(pluginName),
|
|
227
|
-
setPluginEnabled: (pluginName, enabled) => {
|
|
228
|
-
setCityPluginEnabled(pluginName, enabled);
|
|
229
|
-
},
|
|
230
|
-
};
|
|
231
|
-
}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin 鉴权错误工具。
|
|
3
|
+
*
|
|
4
|
+
* 关键说明(中文)
|
|
5
|
+
* - 当 admin key 不正确或已失效时,SDK 会把请求失败包装成带 `status` 的 Error。
|
|
6
|
+
* - 这里统一把 401 转成可识别的 AdminAuthError,方便外层清理缓存 session 并提示重新输入。
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
/**
|
|
10
|
+
* admin key 无效时给用户展示的统一提示。
|
|
11
|
+
*/
|
|
12
|
+
export const ADMIN_AUTH_INVALID_MESSAGE =
|
|
13
|
+
"Current server admin key is incorrect or expired. Please set it again.";
|
|
14
|
+
|
|
15
|
+
interface HttpClientError extends Error {
|
|
16
|
+
/** HTTP 状态码 */
|
|
17
|
+
status?: number;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
/**
|
|
21
|
+
* 判断服务端是否缺少新接口。
|
|
22
|
+
*/
|
|
23
|
+
export function isAdminNotFoundError(error: unknown): boolean {
|
|
24
|
+
return (error as HttpClientError | undefined)?.status === 404;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* admin 鉴权失效错误。
|
|
29
|
+
*/
|
|
30
|
+
export class AdminAuthError extends Error {
|
|
31
|
+
constructor(message = ADMIN_AUTH_INVALID_MESSAGE) {
|
|
32
|
+
super(message);
|
|
33
|
+
this.name = "AdminAuthError";
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 判断当前错误是否是 admin 鉴权失效。
|
|
39
|
+
*/
|
|
40
|
+
export function isAdminAuthError(error: unknown): error is AdminAuthError {
|
|
41
|
+
return error instanceof AdminAuthError;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* 如果底层错误是 401,则提升为 AdminAuthError。
|
|
46
|
+
*/
|
|
47
|
+
export function rethrowAdminAuthError(error: unknown): void {
|
|
48
|
+
const status = (error as HttpClientError | undefined)?.status;
|
|
49
|
+
if (status === 401) {
|
|
50
|
+
throw new AdminAuthError();
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* 提取可展示的错误文本。
|
|
56
|
+
*/
|
|
57
|
+
export function adminErrorMessage(error: unknown): string {
|
|
58
|
+
if (error instanceof Error) {
|
|
59
|
+
return error.message;
|
|
60
|
+
}
|
|
61
|
+
return String(error);
|
|
62
|
+
}
|