@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
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Payment 管理命令。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AdminClient } from "@downcity/conduit";
|
|
6
|
+
import { select, isCancel } from "@clack/prompts";
|
|
7
|
+
import { buildStripeEndpoints } from "../../core/stripe.js";
|
|
8
|
+
import { show, showError } from "../../core/ui.js";
|
|
9
|
+
import { adminErrorMessage, rethrowAdminAuthError } from "../auth-error.js";
|
|
10
|
+
|
|
11
|
+
interface StripePaymentListItem {
|
|
12
|
+
/** 支付记录 ID */
|
|
13
|
+
payment_id: string;
|
|
14
|
+
/** 充值单 ID */
|
|
15
|
+
topup_id: string;
|
|
16
|
+
/** 用户 ID */
|
|
17
|
+
user_id: string;
|
|
18
|
+
/** 充值金额 */
|
|
19
|
+
amount: number;
|
|
20
|
+
/** 结算币种 */
|
|
21
|
+
currency: string;
|
|
22
|
+
/** 当前状态 */
|
|
23
|
+
status: string;
|
|
24
|
+
/** 更新时间 */
|
|
25
|
+
updated_at: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface StripeEventListItem {
|
|
29
|
+
/** 事件 ID */
|
|
30
|
+
event_id: string;
|
|
31
|
+
/** 事件类型 */
|
|
32
|
+
type: string;
|
|
33
|
+
/** 同步状态 */
|
|
34
|
+
sync_status: string;
|
|
35
|
+
/** 同步错误 */
|
|
36
|
+
sync_error: string;
|
|
37
|
+
/** 创建时间 */
|
|
38
|
+
created_at: string;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
export async function managePayment(a: AdminClient, baseUrl: string): Promise<void> {
|
|
42
|
+
const svc = a.service("payment.stripe");
|
|
43
|
+
const endpoints = buildStripeEndpoints(baseUrl);
|
|
44
|
+
while (true) {
|
|
45
|
+
const act = await select({
|
|
46
|
+
message: "Payment",
|
|
47
|
+
options: [
|
|
48
|
+
{ label: "Show webhook setup", value: "webhook", hint: endpoints.webhook_url },
|
|
49
|
+
{ label: "List payments", value: "payments" },
|
|
50
|
+
{ label: "List webhook events", value: "events" },
|
|
51
|
+
{ label: "Back", value: "back" },
|
|
52
|
+
],
|
|
53
|
+
});
|
|
54
|
+
if (!act || isCancel(act) || act === "back") return;
|
|
55
|
+
|
|
56
|
+
try {
|
|
57
|
+
if (act === "webhook") {
|
|
58
|
+
show([
|
|
59
|
+
`Server URL: ${endpoints.base_url}`,
|
|
60
|
+
`Stripe webhook endpoint: ${endpoints.webhook_url}`,
|
|
61
|
+
"Recommended Stripe events:",
|
|
62
|
+
"- checkout.session.completed",
|
|
63
|
+
"- checkout.session.expired",
|
|
64
|
+
"- payment_intent.payment_failed",
|
|
65
|
+
"After creating the endpoint in Stripe Dashboard, copy its Signing secret into STRIPE_WEBHOOK_SECRET.",
|
|
66
|
+
].join("\n"));
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
if (act === "payments") {
|
|
71
|
+
const result = await svc.get<{ items: StripePaymentListItem[] }>("payments");
|
|
72
|
+
console.log(`\n${result.items.length} payments:\n`);
|
|
73
|
+
for (const item of result.items) {
|
|
74
|
+
console.log(
|
|
75
|
+
` ${item.updated_at.slice(0, 19)} ${item.user_id.padEnd(20)} ${String(item.amount).padStart(6)} ${item.currency.padEnd(6)} [${item.status}] ${item.payment_id}`,
|
|
76
|
+
);
|
|
77
|
+
}
|
|
78
|
+
console.log("");
|
|
79
|
+
continue;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const result = await svc.get<{ items: StripeEventListItem[] }>("events");
|
|
83
|
+
console.log(`\n${result.items.length} webhook events:\n`);
|
|
84
|
+
for (const item of result.items) {
|
|
85
|
+
const error = item.sync_error ? ` ${item.sync_error}` : "";
|
|
86
|
+
console.log(` ${item.created_at.slice(0, 19)} ${item.type.padEnd(32)} [${item.sync_status}] ${item.event_id}${error}`);
|
|
87
|
+
}
|
|
88
|
+
console.log("");
|
|
89
|
+
} catch (e) {
|
|
90
|
+
rethrowAdminAuthError(e);
|
|
91
|
+
showError(adminErrorMessage(e));
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Products 管理命令。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AdminClient } from "@downcity/conduit";
|
|
6
|
+
import { select, isCancel } from "@clack/prompts";
|
|
7
|
+
import { askText, showError, showSuccess } from "../../core/ui.js";
|
|
8
|
+
import { adminErrorMessage, rethrowAdminAuthError } from "../auth-error.js";
|
|
9
|
+
|
|
10
|
+
export async function manageProducts(a: AdminClient): Promise<void> {
|
|
11
|
+
while (true) {
|
|
12
|
+
const act = await select({
|
|
13
|
+
message: "Products",
|
|
14
|
+
options: [
|
|
15
|
+
{ label: "List all", value: "list" },
|
|
16
|
+
{ label: "Create", value: "create" },
|
|
17
|
+
{ label: "Pause", value: "pause" },
|
|
18
|
+
{ label: "Activate", value: "activate" },
|
|
19
|
+
{ label: "Remove", value: "remove" },
|
|
20
|
+
{ label: "Issue token", value: "token" },
|
|
21
|
+
{ label: "Back", value: "back" },
|
|
22
|
+
],
|
|
23
|
+
});
|
|
24
|
+
if (!act || isCancel(act) || act === "back") return;
|
|
25
|
+
|
|
26
|
+
try {
|
|
27
|
+
if (act === "list") {
|
|
28
|
+
const items = await a.products.list();
|
|
29
|
+
console.log(`\n${items.length} products:\n`);
|
|
30
|
+
for (const p of items) {
|
|
31
|
+
console.log(` ${p.product_id.padEnd(24)} ${p.name.padEnd(20)} [${p.status}]`);
|
|
32
|
+
}
|
|
33
|
+
console.log("");
|
|
34
|
+
} else if (act === "create") {
|
|
35
|
+
const n = await askText("product name");
|
|
36
|
+
if (!n) continue;
|
|
37
|
+
const productId = await askText("product_id (optional)");
|
|
38
|
+
const p = await a.products.create(
|
|
39
|
+
productId
|
|
40
|
+
? { name: n, product_id: productId }
|
|
41
|
+
: { name: n },
|
|
42
|
+
);
|
|
43
|
+
showSuccess(`created: ${p.product_id}`);
|
|
44
|
+
} else if (act === "pause") {
|
|
45
|
+
const id = await askText("product_id");
|
|
46
|
+
if (!id) continue;
|
|
47
|
+
await a.products.pause(id);
|
|
48
|
+
showSuccess(`paused: ${id}`);
|
|
49
|
+
} else if (act === "activate") {
|
|
50
|
+
const id = await askText("product_id");
|
|
51
|
+
if (!id) continue;
|
|
52
|
+
await a.products.activate(id);
|
|
53
|
+
showSuccess(`activated: ${id}`);
|
|
54
|
+
} else if (act === "remove") {
|
|
55
|
+
const id = await askText("product_id");
|
|
56
|
+
if (!id) continue;
|
|
57
|
+
await a.products.remove(id);
|
|
58
|
+
showSuccess(`removed: ${id}`);
|
|
59
|
+
} else if (act === "token") {
|
|
60
|
+
const pid = await askText("product_id");
|
|
61
|
+
if (!pid) continue;
|
|
62
|
+
const uid = await askText("user_id");
|
|
63
|
+
if (!uid) continue;
|
|
64
|
+
const t = await a.products.tokens.apply({ product_id: pid, user_id: uid });
|
|
65
|
+
showSuccess(`token: ${t.user_token.slice(0, 20)}...`);
|
|
66
|
+
}
|
|
67
|
+
} catch (e) {
|
|
68
|
+
rethrowAdminAuthError(e);
|
|
69
|
+
showError(adminErrorMessage(e));
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
}
|
|
@@ -0,0 +1,256 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Env 管理命令。
|
|
3
|
+
*
|
|
4
|
+
* 三种模式:
|
|
5
|
+
* - Init:遍历所有 service 的 env 需求,逐一交互式配置
|
|
6
|
+
* - 按 Service 查看:选择一个 service,查看/配置其 env
|
|
7
|
+
* - 直接管理:list / upsert / remove 裸 key-value
|
|
8
|
+
*/
|
|
9
|
+
|
|
10
|
+
import { AdminClient } from "@downcity/conduit";
|
|
11
|
+
import { select, isCancel } from "@clack/prompts";
|
|
12
|
+
import { askText, show, showError, showSuccess } from "../../core/ui.js";
|
|
13
|
+
import { adminErrorMessage, isAdminNotFoundError, rethrowAdminAuthError } from "../auth-error.js";
|
|
14
|
+
|
|
15
|
+
interface EnvRequirement {
|
|
16
|
+
/** 环境变量 key */
|
|
17
|
+
key: string;
|
|
18
|
+
/** 给管理员展示的说明文本 */
|
|
19
|
+
description: string;
|
|
20
|
+
/** 当前是否必须配置 */
|
|
21
|
+
required: boolean;
|
|
22
|
+
/** 当前 InfraRuntime 是否已配置该 key */
|
|
23
|
+
configured: boolean;
|
|
24
|
+
/** 当前值的安全预览 */
|
|
25
|
+
value_preview?: string;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
interface ServiceEnv {
|
|
29
|
+
/** 逻辑分组 ID */
|
|
30
|
+
id: string;
|
|
31
|
+
/** 分组展示名称 */
|
|
32
|
+
name: string;
|
|
33
|
+
/** 当前分组包含的 env 需求列表 */
|
|
34
|
+
env: EnvRequirement[];
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
export async function manageEnv(a: AdminClient): Promise<void> {
|
|
38
|
+
while (true) {
|
|
39
|
+
const services = await fetchEnvScopes(a);
|
|
40
|
+
|
|
41
|
+
const choices: { label: string; value: string; hint?: string }[] = [
|
|
42
|
+
{ label: "Init (walk through all)", value: "__init__", hint: "Configure all missing env keys in sequence" },
|
|
43
|
+
{ label: "List all", value: "__list__", hint: "Show all configured env variables" },
|
|
44
|
+
{ label: "Upsert", value: "__upsert__", hint: "Add or update a key=value" },
|
|
45
|
+
{ label: "Update", value: "__update__", hint: "Update an existing key" },
|
|
46
|
+
{ label: "Remove", value: "__remove__", hint: "Delete a key" },
|
|
47
|
+
];
|
|
48
|
+
|
|
49
|
+
if (services) {
|
|
50
|
+
for (const s of services) {
|
|
51
|
+
const configured = s.env.filter((item) => item.configured).length;
|
|
52
|
+
choices.push({
|
|
53
|
+
label: ` ${s.name} (${configured}/${s.env.length} configured)`,
|
|
54
|
+
value: s.id,
|
|
55
|
+
hint: s.env.map((e) => `${e.key}${e.configured ? "✓" : ""}`).join(", "),
|
|
56
|
+
});
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
choices.push({ label: "Back", value: "back", hint: "Return to admin menu" });
|
|
61
|
+
|
|
62
|
+
const svcId = await select({ message: "Env", options: choices });
|
|
63
|
+
if (!svcId || isCancel(svcId) || svcId === "back") return;
|
|
64
|
+
|
|
65
|
+
if (svcId === "__init__" && services) { await initAllEnv(a, services); continue; }
|
|
66
|
+
if (svcId === "__list__") { await listAllEnv(a); continue; }
|
|
67
|
+
if (svcId === "__upsert__") { await upsertEnv(a); continue; }
|
|
68
|
+
if (svcId === "__update__") { await updateEnv(a); continue; }
|
|
69
|
+
if (svcId === "__remove__") { await removeEnv(a); continue; }
|
|
70
|
+
|
|
71
|
+
if (services) {
|
|
72
|
+
const svc = services.find((s) => s.id === svcId);
|
|
73
|
+
if (svc) await configureServiceEnv(a, svc);
|
|
74
|
+
}
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// ============================================================
|
|
79
|
+
// Init 模式
|
|
80
|
+
// ============================================================
|
|
81
|
+
|
|
82
|
+
async function initAllEnv(a: AdminClient, services: ServiceEnv[]): Promise<void> {
|
|
83
|
+
const configuredKeys = new Set(
|
|
84
|
+
services.flatMap((svc) => svc.env.filter((item) => item.configured).map((item) => item.key)),
|
|
85
|
+
);
|
|
86
|
+
let changed = false;
|
|
87
|
+
|
|
88
|
+
for (const svc of services) {
|
|
89
|
+
show(`\n── ${svc.name} ──────────────────────────────`);
|
|
90
|
+
for (const req of svc.env) {
|
|
91
|
+
if (configuredKeys.has(req.key)) { show(` ${req.key} ✓ (already set)`); continue; }
|
|
92
|
+
|
|
93
|
+
const label = req.required
|
|
94
|
+
? `${req.key} (${req.description})`
|
|
95
|
+
: `${req.key} (${req.description}, optional — enter to skip)`;
|
|
96
|
+
|
|
97
|
+
const value = await askText(label);
|
|
98
|
+
if (!value) { if (req.required) show(` ${req.key} ✗ skipped (required)`); continue; }
|
|
99
|
+
|
|
100
|
+
try {
|
|
101
|
+
await a.env.upsert({ key: req.key, value });
|
|
102
|
+
configuredKeys.add(req.key);
|
|
103
|
+
showSuccess(` ${req.key}`);
|
|
104
|
+
changed = true;
|
|
105
|
+
} catch (e) {
|
|
106
|
+
rethrowAdminAuthError(e);
|
|
107
|
+
showError(` ${req.key}: ${adminErrorMessage(e)}`);
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
if (changed) showSuccess("\nEnv init complete.");
|
|
113
|
+
else show("\nAll env keys are already configured.");
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
// ============================================================
|
|
117
|
+
// 直接管理模式
|
|
118
|
+
// ============================================================
|
|
119
|
+
|
|
120
|
+
async function listAllEnv(a: AdminClient): Promise<void> {
|
|
121
|
+
try {
|
|
122
|
+
const items = await a.env.list();
|
|
123
|
+
if (items.length === 0) { show("No env variables configured."); return; }
|
|
124
|
+
console.log(`\n${items.length} env:\n`);
|
|
125
|
+
for (const e of items) {
|
|
126
|
+
console.log(` ${e.key.padEnd(35)} ${maskValue(e.value, 40)}`);
|
|
127
|
+
}
|
|
128
|
+
console.log("");
|
|
129
|
+
} catch (e) {
|
|
130
|
+
rethrowAdminAuthError(e);
|
|
131
|
+
showError(adminErrorMessage(e));
|
|
132
|
+
}
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
async function upsertEnv(a: AdminClient): Promise<void> {
|
|
136
|
+
const key = await askText("key");
|
|
137
|
+
if (!key) return;
|
|
138
|
+
const value = await askText("value");
|
|
139
|
+
if (!value) return;
|
|
140
|
+
try {
|
|
141
|
+
await a.env.upsert({ key, value });
|
|
142
|
+
showSuccess(`upserted: ${key}`);
|
|
143
|
+
} catch (e) {
|
|
144
|
+
rethrowAdminAuthError(e);
|
|
145
|
+
showError(adminErrorMessage(e));
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
|
|
149
|
+
async function updateEnv(a: AdminClient): Promise<void> {
|
|
150
|
+
const items = await fetchCurrentEnv(a);
|
|
151
|
+
if (items.length === 0) { show("No env variables to update."); return; }
|
|
152
|
+
|
|
153
|
+
const choices = items.map((e) => ({
|
|
154
|
+
label: e.key, value: e.key, hint: `current: ${maskValue(e.value, 20)}`,
|
|
155
|
+
}));
|
|
156
|
+
choices.push({ label: "Cancel", value: "__cancel__", hint: "Return without changes" });
|
|
157
|
+
|
|
158
|
+
const key = await select({ message: "Select key to update", options: choices });
|
|
159
|
+
if (!key || isCancel(key) || key === "__cancel__") return;
|
|
160
|
+
|
|
161
|
+
const current = items.find((e) => e.key === key)!;
|
|
162
|
+
const value = await askText(`New value (current: ${maskValue(current.value, 16)})`);
|
|
163
|
+
if (!value) return;
|
|
164
|
+
|
|
165
|
+
try {
|
|
166
|
+
await a.env.upsert({ key: key as string, value });
|
|
167
|
+
showSuccess(`updated: ${key}`);
|
|
168
|
+
} catch (e) {
|
|
169
|
+
rethrowAdminAuthError(e);
|
|
170
|
+
showError(adminErrorMessage(e));
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
async function removeEnv(a: AdminClient): Promise<void> {
|
|
175
|
+
const key = await askText("key");
|
|
176
|
+
if (!key) return;
|
|
177
|
+
try {
|
|
178
|
+
await a.env.remove(key);
|
|
179
|
+
showSuccess(`removed: ${key}`);
|
|
180
|
+
} catch (e) {
|
|
181
|
+
rethrowAdminAuthError(e);
|
|
182
|
+
showError(adminErrorMessage(e));
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
// ============================================================
|
|
187
|
+
// 按 Service 查看
|
|
188
|
+
// ============================================================
|
|
189
|
+
|
|
190
|
+
async function configureServiceEnv(a: AdminClient, svc: ServiceEnv): Promise<void> {
|
|
191
|
+
while (true) {
|
|
192
|
+
const scopes = await fetchEnvScopes(a);
|
|
193
|
+
const currentScope = scopes?.find((item) => item.id === svc.id) ?? svc;
|
|
194
|
+
|
|
195
|
+
const choices = currentScope.env.map((req) => {
|
|
196
|
+
const status = req.configured
|
|
197
|
+
? `✓ configured${req.value_preview ? ` (${req.value_preview})` : ""}`
|
|
198
|
+
: (req.required ? "✗ MISSING" : "○ unset");
|
|
199
|
+
return { label: req.key, value: req.key, hint: `${req.description} [${status}]` };
|
|
200
|
+
});
|
|
201
|
+
choices.push({ label: "Back", value: "back", hint: "Return to env menu" });
|
|
202
|
+
|
|
203
|
+
const key = await select({ message: `${svc.name} — configure`, options: choices });
|
|
204
|
+
if (!key || isCancel(key) || key === "back") return;
|
|
205
|
+
|
|
206
|
+
const req = currentScope.env.find((e) => e.key === key)!;
|
|
207
|
+
const hint = req.configured
|
|
208
|
+
? `(current: ${req.value_preview ?? "configured"}, enter a new value to replace it)`
|
|
209
|
+
: "";
|
|
210
|
+
const value = await askText(`${req.description} ${hint}`);
|
|
211
|
+
if (!value) continue;
|
|
212
|
+
|
|
213
|
+
try {
|
|
214
|
+
if (value) { await a.env.upsert({ key: req.key, value }); showSuccess(`set ${req.key}`); }
|
|
215
|
+
} catch (e) {
|
|
216
|
+
rethrowAdminAuthError(e);
|
|
217
|
+
showError(adminErrorMessage(e));
|
|
218
|
+
}
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
|
|
222
|
+
// ============================================================
|
|
223
|
+
// 工具
|
|
224
|
+
// ============================================================
|
|
225
|
+
|
|
226
|
+
async function fetchEnvScopes(a: AdminClient): Promise<ServiceEnv[] | undefined> {
|
|
227
|
+
try {
|
|
228
|
+
const scopes = await a.env.catalog();
|
|
229
|
+
if (scopes.length === 0) {
|
|
230
|
+
show("No services or AI models with env requirements found.");
|
|
231
|
+
return undefined;
|
|
232
|
+
}
|
|
233
|
+
return scopes;
|
|
234
|
+
} catch (e) {
|
|
235
|
+
rethrowAdminAuthError(e);
|
|
236
|
+
if (isAdminNotFoundError(e)) {
|
|
237
|
+
showError("Connected InfraRuntime is too old and does not expose /v1/env/catalog yet. Deploy the latest worker/server first.")
|
|
238
|
+
return undefined;
|
|
239
|
+
}
|
|
240
|
+
showError(`Failed to fetch env catalog: ${adminErrorMessage(e)}`);
|
|
241
|
+
return undefined;
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
async function fetchCurrentEnv(a: AdminClient): Promise<{ key: string; value: string }[]> {
|
|
246
|
+
try {
|
|
247
|
+
return await a.env.list();
|
|
248
|
+
} catch (e) {
|
|
249
|
+
rethrowAdminAuthError(e);
|
|
250
|
+
return [];
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
function maskValue(v: string, n: number): string {
|
|
255
|
+
return v.length <= n ? v : v.slice(0, n) + "...";
|
|
256
|
+
}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin Usage 管理命令。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AdminClient } from "@downcity/conduit";
|
|
6
|
+
import { select, isCancel } from "@clack/prompts";
|
|
7
|
+
import { showError } from "../../core/ui.js";
|
|
8
|
+
import { adminErrorMessage, rethrowAdminAuthError } from "../auth-error.js";
|
|
9
|
+
|
|
10
|
+
export async function manageUsage(a: AdminClient): Promise<void> {
|
|
11
|
+
const svc = a.service("usage");
|
|
12
|
+
while (true) {
|
|
13
|
+
const act = await select({
|
|
14
|
+
message: "Usage",
|
|
15
|
+
options: [
|
|
16
|
+
{ label: "List events", value: "events" },
|
|
17
|
+
{ label: "Summary", value: "summary" },
|
|
18
|
+
{ label: "Back", value: "back" },
|
|
19
|
+
],
|
|
20
|
+
});
|
|
21
|
+
if (!act || isCancel(act) || act === "back") return;
|
|
22
|
+
|
|
23
|
+
try {
|
|
24
|
+
if (act === "events") {
|
|
25
|
+
const b = await svc.get<{ items: { product_id: string; service: string; status: string; created_at: string }[] }>("events");
|
|
26
|
+
console.log(`\n${b.items.length} events:\n`);
|
|
27
|
+
for (const e of b.items.slice(-20)) {
|
|
28
|
+
console.log(` ${e.created_at.slice(0, 19)} ${e.product_id.padEnd(22)} ${e.service.padEnd(15)} [${e.status}]`);
|
|
29
|
+
}
|
|
30
|
+
console.log("");
|
|
31
|
+
} else {
|
|
32
|
+
const b = await svc.get<{ items: { product_id: string; service: string; status: string; count: number }[] }>("summary");
|
|
33
|
+
console.log(`\nSummary:\n`);
|
|
34
|
+
for (const s of b.items) {
|
|
35
|
+
console.log(` ${s.product_id.padEnd(22)} ${s.service.padEnd(15)} ${String(s.count).padStart(5)} [${s.status}]`);
|
|
36
|
+
}
|
|
37
|
+
console.log("");
|
|
38
|
+
}
|
|
39
|
+
} catch (e) {
|
|
40
|
+
rethrowAdminAuthError(e);
|
|
41
|
+
showError(adminErrorMessage(e));
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Admin 命令循环。返回 "logout" | "quit" | "switch_identity"。
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
import { AdminClient } from "@downcity/conduit";
|
|
6
|
+
import { select, isCancel } from "@clack/prompts";
|
|
7
|
+
import { type AdminSession } from "../core/session.js";
|
|
8
|
+
import { showError, showSuccess } from "../core/ui.js";
|
|
9
|
+
import { adminErrorMessage, isAdminAuthError } from "./auth-error.js";
|
|
10
|
+
import { manageEnv } from "./commands/service-env.js";
|
|
11
|
+
import { manageProducts } from "./commands/products.js";
|
|
12
|
+
import { manageAccounts } from "./commands/accounts.js";
|
|
13
|
+
import { manageBalance } from "./commands/balance.js";
|
|
14
|
+
import { manageUsage } from "./commands/usage.js";
|
|
15
|
+
import { managePayment } from "./commands/payment.js";
|
|
16
|
+
import { manageCustom } from "./commands/custom.js";
|
|
17
|
+
import { manageModels } from "./commands/models.js";
|
|
18
|
+
import { manageInstruction } from "./commands/instruction.js";
|
|
19
|
+
|
|
20
|
+
const commands: Record<string, (a: AdminClient, baseUrl: string) => Promise<void>> = {
|
|
21
|
+
env: manageEnv,
|
|
22
|
+
instruction: manageInstruction,
|
|
23
|
+
models: manageModels,
|
|
24
|
+
products: manageProducts,
|
|
25
|
+
accounts: manageAccounts,
|
|
26
|
+
balance: manageBalance,
|
|
27
|
+
usage: manageUsage,
|
|
28
|
+
payment: managePayment,
|
|
29
|
+
custom: manageCustom,
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
export async function adminLoop(session: AdminSession): Promise<"logout" | "quit" | "switch_identity"> {
|
|
33
|
+
const admin = new AdminClient({ base_url: session.base_url, admin_secret_key: session.admin_token });
|
|
34
|
+
|
|
35
|
+
while (true) {
|
|
36
|
+
const svc = await select({
|
|
37
|
+
message: "Manage Service",
|
|
38
|
+
options: [
|
|
39
|
+
{ label: "Env", value: "env", hint: "View & configure environment variables" },
|
|
40
|
+
{ label: "Infra Instruction", value: "instruction", hint: "Read aggregated base/service/service guidance" },
|
|
41
|
+
{ label: "Models", value: "models", hint: "Read model readiness and missing env" },
|
|
42
|
+
{ label: "Products", value: "products" },
|
|
43
|
+
{ label: "Accounts", value: "accounts" },
|
|
44
|
+
{ label: "Balance", value: "balance" },
|
|
45
|
+
{ label: "Usage", value: "usage" },
|
|
46
|
+
{ label: "Payment (Stripe)", value: "payment" },
|
|
47
|
+
{ label: "Custom service...", value: "custom" },
|
|
48
|
+
{ label: "Switch to User", value: "switch" },
|
|
49
|
+
{ label: "Logout", value: "logout" },
|
|
50
|
+
{ label: "Quit", value: "quit" },
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
if (!svc || isCancel(svc)) return "quit";
|
|
54
|
+
|
|
55
|
+
if (svc === "quit") return "quit";
|
|
56
|
+
if (svc === "logout") { showSuccess("left admin mode"); return "logout"; }
|
|
57
|
+
if (svc === "switch") return "switch_identity";
|
|
58
|
+
|
|
59
|
+
try {
|
|
60
|
+
await commands[svc]?.(admin, session.base_url);
|
|
61
|
+
} catch (e) {
|
|
62
|
+
if (isAdminAuthError(e)) {
|
|
63
|
+
showError(adminErrorMessage(e));
|
|
64
|
+
return "logout";
|
|
65
|
+
}
|
|
66
|
+
showError(adminErrorMessage(e));
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|