@jingyi0605/codingns4dsh 0.2.0-beta.2 → 0.2.0-rc3
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.en.md +4 -4
- package/README.md +18 -7
- package/assets/provider-icons/antigravity.svg +39 -0
- package/assets/provider-icons/codebuddy.svg +37 -0
- package/assets/provider-icons/cursor-cli.svg +1 -0
- package/assets/provider-icons/kiro-cli.svg +11 -0
- package/assets/provider-icons/minimax-code.svg +4 -0
- package/assets/provider-icons/qoder-cn.svg +5 -0
- package/assets/provider-icons/qoder.svg +5 -0
- package/assets/provider-icons/workbuddy.svg +29 -0
- package/assets/provider-icons/zcode.svg +14 -0
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.d.ts.map +1 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js +78 -1
- package/data/build/dist/bootstrap/dsh-peer-host-preboot-shim.js.map +1 -1
- package/data/build/dist/client/account-bar.d.ts +2 -1
- package/data/build/dist/client/account-bar.d.ts.map +1 -1
- package/data/build/dist/client/account-bar.js +21 -16
- package/data/build/dist/client/account-bar.js.map +1 -1
- package/data/build/dist/client/bundle.js +8147 -2158
- package/data/build/dist/client/bundle.js.map +1 -1
- package/data/build/dist/client/cli-catalog.d.ts +1 -1
- package/data/build/dist/client/cli-catalog.d.ts.map +1 -1
- package/data/build/dist/client/cli-catalog.js +11 -5
- package/data/build/dist/client/cli-catalog.js.map +1 -1
- package/data/build/dist/client/cli-slots.d.ts.map +1 -1
- package/data/build/dist/client/cli-slots.js +127 -21
- package/data/build/dist/client/cli-slots.js.map +1 -1
- package/data/build/dist/client/debug/ui.d.ts +2 -1
- package/data/build/dist/client/debug/ui.d.ts.map +1 -1
- package/data/build/dist/client/debug/ui.js +41 -34
- package/data/build/dist/client/debug/ui.js.map +1 -1
- package/data/build/dist/client/delegate-command.d.ts +17 -0
- package/data/build/dist/client/delegate-command.d.ts.map +1 -0
- package/data/build/dist/client/delegate-command.js +597 -0
- package/data/build/dist/client/delegate-command.js.map +1 -0
- package/data/build/dist/client/delegate-plan.d.ts +40 -0
- package/data/build/dist/client/delegate-plan.d.ts.map +1 -0
- package/data/build/dist/client/delegate-plan.js +63 -0
- package/data/build/dist/client/delegate-plan.js.map +1 -0
- package/data/build/dist/client/delegate-ui-dom.d.ts +86 -0
- package/data/build/dist/client/delegate-ui-dom.d.ts.map +1 -0
- package/data/build/dist/client/delegate-ui-dom.js +647 -0
- package/data/build/dist/client/delegate-ui-dom.js.map +1 -0
- package/data/build/dist/client/external-tool-stream.d.ts.map +1 -1
- package/data/build/dist/client/external-tool-stream.js +44 -36
- package/data/build/dist/client/external-tool-stream.js.map +1 -1
- package/data/build/dist/client/features/cli-adapters.d.ts +7 -2
- package/data/build/dist/client/features/cli-adapters.d.ts.map +1 -1
- package/data/build/dist/client/features/cli-adapters.js +153 -95
- package/data/build/dist/client/features/cli-adapters.js.map +1 -1
- package/data/build/dist/client/features/debug.d.ts.map +1 -1
- package/data/build/dist/client/features/debug.js +5 -3
- package/data/build/dist/client/features/debug.js.map +1 -1
- package/data/build/dist/client/features/file-management.d.ts.map +1 -1
- package/data/build/dist/client/features/file-management.js +7 -4
- package/data/build/dist/client/features/file-management.js.map +1 -1
- package/data/build/dist/client/features/lan-access-panel.js +10 -10
- package/data/build/dist/client/features/lan-access-panel.js.map +1 -1
- package/data/build/dist/client/features/lan-access.d.ts.map +1 -1
- package/data/build/dist/client/features/lan-access.js +8 -3
- package/data/build/dist/client/features/lan-access.js.map +1 -1
- package/data/build/dist/client/features/login-protection-panel.d.ts.map +1 -1
- package/data/build/dist/client/features/login-protection-panel.js +9 -7
- package/data/build/dist/client/features/login-protection-panel.js.map +1 -1
- package/data/build/dist/client/features/login-protection.js +2 -2
- package/data/build/dist/client/features/login-protection.js.map +1 -1
- package/data/build/dist/client/features/mobile-access-panel.d.ts.map +1 -1
- package/data/build/dist/client/features/mobile-access-panel.js +8 -7
- package/data/build/dist/client/features/mobile-access-panel.js.map +1 -1
- package/data/build/dist/client/features/mobile-access.d.ts.map +1 -1
- package/data/build/dist/client/features/mobile-access.js +6 -2
- package/data/build/dist/client/features/mobile-access.js.map +1 -1
- package/data/build/dist/client/features/peer-host.d.ts +6 -4
- package/data/build/dist/client/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/client/features/peer-host.js +459 -27
- package/data/build/dist/client/features/peer-host.js.map +1 -1
- package/data/build/dist/client/features/reverse-proxy.js +2 -2
- package/data/build/dist/client/features/reverse-proxy.js.map +1 -1
- package/data/build/dist/client/features/terminal-enhancement.js +2 -2
- package/data/build/dist/client/features/terminal-enhancement.js.map +1 -1
- package/data/build/dist/client/features/workspace-session-enhancement-panel.js +1 -1
- package/data/build/dist/client/features/workspace-session-enhancement-panel.js.map +1 -1
- package/data/build/dist/client/features/workspace-session-enhancement.d.ts.map +1 -1
- package/data/build/dist/client/features/workspace-session-enhancement.js +8 -3
- package/data/build/dist/client/features/workspace-session-enhancement.js.map +1 -1
- package/data/build/dist/client/file-management-dom.d.ts +3 -0
- package/data/build/dist/client/file-management-dom.d.ts.map +1 -1
- package/data/build/dist/client/file-management-dom.js +41 -30
- package/data/build/dist/client/file-management-dom.js.map +1 -1
- package/data/build/dist/client/git-history-graph.d.ts +2 -2
- package/data/build/dist/client/git-history-graph.d.ts.map +1 -1
- package/data/build/dist/client/git-history-graph.js +2 -2
- package/data/build/dist/client/git-history-graph.js.map +1 -1
- package/data/build/dist/client/git-management.d.ts +2 -0
- package/data/build/dist/client/git-management.d.ts.map +1 -1
- package/data/build/dist/client/git-management.js +103 -75
- package/data/build/dist/client/git-management.js.map +1 -1
- package/data/build/dist/client/git-workspace-events.d.ts +7 -0
- package/data/build/dist/client/git-workspace-events.d.ts.map +1 -0
- package/data/build/dist/client/git-workspace-events.js +32 -0
- package/data/build/dist/client/git-workspace-events.js.map +1 -0
- package/data/build/dist/client/index.d.ts +2 -0
- package/data/build/dist/client/index.d.ts.map +1 -1
- package/data/build/dist/client/index.js +6 -5
- package/data/build/dist/client/index.js.map +1 -1
- package/data/build/dist/client/locale.d.ts +7 -0
- package/data/build/dist/client/locale.d.ts.map +1 -1
- package/data/build/dist/client/locale.js +140 -42
- package/data/build/dist/client/locale.js.map +1 -1
- package/data/build/dist/client/locales/debug.d.ts +9 -0
- package/data/build/dist/client/locales/debug.d.ts.map +1 -0
- package/data/build/dist/client/locales/debug.js +163 -0
- package/data/build/dist/client/locales/debug.js.map +1 -0
- package/data/build/dist/client/locales/fileWorkspace.d.ts +9 -0
- package/data/build/dist/client/locales/fileWorkspace.d.ts.map +1 -0
- package/data/build/dist/client/locales/fileWorkspace.js +139 -0
- package/data/build/dist/client/locales/fileWorkspace.js.map +1 -0
- package/data/build/dist/client/locales/git.d.ts +9 -0
- package/data/build/dist/client/locales/git.d.ts.map +1 -0
- package/data/build/dist/client/locales/git.js +223 -0
- package/data/build/dist/client/locales/git.js.map +1 -0
- package/data/build/dist/client/locales/panels.d.ts +9 -0
- package/data/build/dist/client/locales/panels.d.ts.map +1 -0
- package/data/build/dist/client/locales/panels.js +33 -0
- package/data/build/dist/client/locales/panels.js.map +1 -0
- package/data/build/dist/client/locales/peerHost.d.ts +9 -0
- package/data/build/dist/client/locales/peerHost.d.ts.map +1 -0
- package/data/build/dist/client/locales/peerHost.js +153 -0
- package/data/build/dist/client/locales/peerHost.js.map +1 -0
- package/data/build/dist/client/locales/peerHostWorkspace.d.ts +9 -0
- package/data/build/dist/client/locales/peerHostWorkspace.d.ts.map +1 -0
- package/data/build/dist/client/locales/peerHostWorkspace.js +69 -0
- package/data/build/dist/client/locales/peerHostWorkspace.js.map +1 -0
- package/data/build/dist/client/locales/terminalAuth.d.ts +9 -0
- package/data/build/dist/client/locales/terminalAuth.d.ts.map +1 -0
- package/data/build/dist/client/locales/terminalAuth.js +71 -0
- package/data/build/dist/client/locales/terminalAuth.js.map +1 -0
- package/data/build/dist/client/locales/usage.d.ts +9 -0
- package/data/build/dist/client/locales/usage.d.ts.map +1 -0
- package/data/build/dist/client/locales/usage.js +215 -0
- package/data/build/dist/client/locales/usage.js.map +1 -0
- package/data/build/dist/client/mobile-session-interaction.d.ts +44 -0
- package/data/build/dist/client/mobile-session-interaction.d.ts.map +1 -0
- package/data/build/dist/client/mobile-session-interaction.js +308 -0
- package/data/build/dist/client/mobile-session-interaction.js.map +1 -0
- package/data/build/dist/client/mobile-sidebar-gestures.d.ts +55 -7
- package/data/build/dist/client/mobile-sidebar-gestures.d.ts.map +1 -1
- package/data/build/dist/client/mobile-sidebar-gestures.js +339 -40
- package/data/build/dist/client/mobile-sidebar-gestures.js.map +1 -1
- package/data/build/dist/client/mobile-sidebar-rail-dom.d.ts +10 -2
- package/data/build/dist/client/mobile-sidebar-rail-dom.d.ts.map +1 -1
- package/data/build/dist/client/mobile-sidebar-rail-dom.js +14 -6
- package/data/build/dist/client/mobile-sidebar-rail-dom.js.map +1 -1
- package/data/build/dist/client/model-catalog-cache.d.ts +5 -0
- package/data/build/dist/client/model-catalog-cache.d.ts.map +1 -0
- package/data/build/dist/client/model-catalog-cache.js +58 -0
- package/data/build/dist/client/model-catalog-cache.js.map +1 -0
- package/data/build/dist/client/peer-host-aggregate-refresh.d.ts +7 -0
- package/data/build/dist/client/peer-host-aggregate-refresh.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-aggregate-refresh.js +13 -1
- package/data/build/dist/client/peer-host-aggregate-refresh.js.map +1 -1
- package/data/build/dist/client/peer-host-connection-button.d.ts +14 -1
- package/data/build/dist/client/peer-host-connection-button.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-connection-button.js +12 -4
- package/data/build/dist/client/peer-host-connection-button.js.map +1 -1
- package/data/build/dist/client/peer-host-management-panel.d.ts +3 -0
- package/data/build/dist/client/peer-host-management-panel.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-management-panel.js +83 -79
- package/data/build/dist/client/peer-host-management-panel.js.map +1 -1
- package/data/build/dist/client/peer-host-native-projection.d.ts +17 -1
- package/data/build/dist/client/peer-host-native-projection.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-native-projection.js +54 -8
- package/data/build/dist/client/peer-host-native-projection.js.map +1 -1
- package/data/build/dist/client/peer-host-native-store-projection.d.ts +6 -2
- package/data/build/dist/client/peer-host-native-store-projection.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-native-store-projection.js +308 -10
- package/data/build/dist/client/peer-host-native-store-projection.js.map +1 -1
- package/data/build/dist/client/peer-host-scoped-client.js +5 -5
- package/data/build/dist/client/peer-host-scoped-client.js.map +1 -1
- package/data/build/dist/client/peer-host-workspace-tab.d.ts +8 -0
- package/data/build/dist/client/peer-host-workspace-tab.d.ts.map +1 -1
- package/data/build/dist/client/peer-host-workspace-tab.js +48 -28
- package/data/build/dist/client/peer-host-workspace-tab.js.map +1 -1
- package/data/build/dist/client/provider-icon-assets.js +18 -0
- package/data/build/dist/client/provider-icon-assets.js.map +1 -1
- package/data/build/dist/client/provider-icons.d.ts +8 -2
- package/data/build/dist/client/provider-icons.d.ts.map +1 -1
- package/data/build/dist/client/provider-icons.js +28 -7
- package/data/build/dist/client/provider-icons.js.map +1 -1
- package/data/build/dist/client/pwa-install-prompt.d.ts +4 -1
- package/data/build/dist/client/pwa-install-prompt.d.ts.map +1 -1
- package/data/build/dist/client/pwa-install-prompt.js +8 -7
- package/data/build/dist/client/pwa-install-prompt.js.map +1 -1
- package/data/build/dist/client/quick-phrase-layout.d.ts +11 -0
- package/data/build/dist/client/quick-phrase-layout.d.ts.map +1 -1
- package/data/build/dist/client/quick-phrase-layout.js +20 -0
- package/data/build/dist/client/quick-phrase-layout.js.map +1 -1
- package/data/build/dist/client/quick-phrase-slot.d.ts.map +1 -1
- package/data/build/dist/client/quick-phrase-slot.js +20 -8
- package/data/build/dist/client/quick-phrase-slot.js.map +1 -1
- package/data/build/dist/client/remote-web-context.js +10 -6
- package/data/build/dist/client/remote-web-context.js.map +1 -1
- package/data/build/dist/client/service-tier.d.ts +54 -0
- package/data/build/dist/client/service-tier.d.ts.map +1 -0
- package/data/build/dist/client/service-tier.js +78 -0
- package/data/build/dist/client/service-tier.js.map +1 -0
- package/data/build/dist/client/session-changed-files-view.d.ts +8 -1
- package/data/build/dist/client/session-changed-files-view.d.ts.map +1 -1
- package/data/build/dist/client/session-changed-files-view.js +71 -28
- package/data/build/dist/client/session-changed-files-view.js.map +1 -1
- package/data/build/dist/client/settings-anchor.d.ts +9 -3
- package/data/build/dist/client/settings-anchor.d.ts.map +1 -1
- package/data/build/dist/client/settings-anchor.js +8 -2
- package/data/build/dist/client/settings-anchor.js.map +1 -1
- package/data/build/dist/client/settings-promo-styles.d.ts +28 -0
- package/data/build/dist/client/settings-promo-styles.d.ts.map +1 -0
- package/data/build/dist/client/settings-promo-styles.js +58 -0
- package/data/build/dist/client/settings-promo-styles.js.map +1 -0
- package/data/build/dist/client/settings-promo.d.ts +14 -0
- package/data/build/dist/client/settings-promo.d.ts.map +1 -0
- package/data/build/dist/client/settings-promo.js +68 -0
- package/data/build/dist/client/settings-promo.js.map +1 -0
- package/data/build/dist/client/settings-section.d.ts +2 -1
- package/data/build/dist/client/settings-section.d.ts.map +1 -1
- package/data/build/dist/client/settings-section.js +10 -7
- package/data/build/dist/client/settings-section.js.map +1 -1
- package/data/build/dist/client/subscription-slot.d.ts +4 -1
- package/data/build/dist/client/subscription-slot.d.ts.map +1 -1
- package/data/build/dist/client/subscription-slot.js +497 -56
- package/data/build/dist/client/subscription-slot.js.map +1 -1
- package/data/build/dist/client/terminal/model.d.ts +94 -4
- package/data/build/dist/client/terminal/model.d.ts.map +1 -1
- package/data/build/dist/client/terminal/model.js +392 -33
- package/data/build/dist/client/terminal/model.js.map +1 -1
- package/data/build/dist/client/terminal/recovery.d.ts +16 -1
- package/data/build/dist/client/terminal/recovery.d.ts.map +1 -1
- package/data/build/dist/client/terminal/recovery.js +101 -39
- package/data/build/dist/client/terminal/recovery.js.map +1 -1
- package/data/build/dist/client/terminal/styles.d.ts +10 -0
- package/data/build/dist/client/terminal/styles.d.ts.map +1 -1
- package/data/build/dist/client/terminal/styles.js +27 -3
- package/data/build/dist/client/terminal/styles.js.map +1 -1
- package/data/build/dist/client/terminal/ui.d.ts +3 -2
- package/data/build/dist/client/terminal/ui.d.ts.map +1 -1
- package/data/build/dist/client/terminal/ui.js +216 -103
- package/data/build/dist/client/terminal/ui.js.map +1 -1
- package/data/build/dist/client/terminal/xterm-view.d.ts +8 -1
- package/data/build/dist/client/terminal/xterm-view.d.ts.map +1 -1
- package/data/build/dist/client/terminal/xterm-view.js +394 -34
- package/data/build/dist/client/terminal/xterm-view.js.map +1 -1
- package/data/build/dist/client/workspace-session-archive-dom.d.ts +3 -0
- package/data/build/dist/client/workspace-session-archive-dom.d.ts.map +1 -1
- package/data/build/dist/client/workspace-session-archive-dom.js +131 -45
- package/data/build/dist/client/workspace-session-archive-dom.js.map +1 -1
- package/data/build/dist/client/workspace-session-logo-dom.d.ts +3 -0
- package/data/build/dist/client/workspace-session-logo-dom.d.ts.map +1 -1
- package/data/build/dist/client/workspace-session-logo-dom.js +3 -1
- package/data/build/dist/client/workspace-session-logo-dom.js.map +1 -1
- package/data/build/dist/client/workspace-session-visibility-dom.d.ts +3 -0
- package/data/build/dist/client/workspace-session-visibility-dom.d.ts.map +1 -1
- package/data/build/dist/client/workspace-session-visibility-dom.js +46 -17
- package/data/build/dist/client/workspace-session-visibility-dom.js.map +1 -1
- package/data/build/dist/dsh-capabilities/client/primitives-adapter.d.ts +10 -0
- package/data/build/dist/dsh-capabilities/client/primitives-adapter.d.ts.map +1 -1
- package/data/build/dist/dsh-capabilities/client/primitives-adapter.js +20 -0
- package/data/build/dist/dsh-capabilities/client/primitives-adapter.js.map +1 -1
- package/data/build/dist/host/browser-text.d.ts +30 -0
- package/data/build/dist/host/browser-text.d.ts.map +1 -0
- package/data/build/dist/host/browser-text.js +105 -0
- package/data/build/dist/host/browser-text.js.map +1 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts +58 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js +271 -0
- package/data/build/dist/host/cli-adapters/acp-cli-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.d.ts +30 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.js +210 -0
- package/data/build/dist/host/cli-adapters/antigravity-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/claude-driver.d.ts +28 -2
- package/data/build/dist/host/cli-adapters/claude-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/claude-driver.js +74 -4
- package/data/build/dist/host/cli-adapters/claude-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/claude-model-options.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/claude-model-options.js +22 -9
- package/data/build/dist/host/cli-adapters/claude-model-options.js.map +1 -1
- package/data/build/dist/host/cli-adapters/codebuddy-driver.d.ts +139 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.js +1721 -0
- package/data/build/dist/host/cli-adapters/codebuddy-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.d.ts +53 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.js +778 -0
- package/data/build/dist/host/cli-adapters/codebuddy-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts +22 -0
- package/data/build/dist/host/cli-adapters/codex-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/codex-driver.js +254 -7
- package/data/build/dist/host/cli-adapters/codex-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts +43 -3
- package/data/build/dist/host/cli-adapters/command-code-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-driver.js +681 -74
- package/data/build/dist/host/cli-adapters/command-code-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts +147 -0
- package/data/build/dist/host/cli-adapters/command-code-history.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/command-code-history.js +659 -0
- package/data/build/dist/host/cli-adapters/command-code-history.js.map +1 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.d.ts +12 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.js +20 -0
- package/data/build/dist/host/cli-adapters/cursor-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.d.ts +67 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.js +169 -0
- package/data/build/dist/host/cli-adapters/custom-upstream-classifier.js.map +1 -0
- package/data/build/dist/host/cli-adapters/delegate-dispatch.d.ts +48 -0
- package/data/build/dist/host/cli-adapters/delegate-dispatch.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/delegate-dispatch.js +111 -0
- package/data/build/dist/host/cli-adapters/delegate-dispatch.js.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.d.ts +19 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.js +49 -0
- package/data/build/dist/host/cli-adapters/delegation-authorization.js.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.d.ts +34 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js +121 -0
- package/data/build/dist/host/cli-adapters/delegation-mention-rewrite.js.map +1 -0
- package/data/build/dist/host/cli-adapters/desktop-app-runtime.d.ts +32 -0
- package/data/build/dist/host/cli-adapters/desktop-app-runtime.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/desktop-app-runtime.js +121 -0
- package/data/build/dist/host/cli-adapters/desktop-app-runtime.js.map +1 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts +6 -0
- package/data/build/dist/host/cli-adapters/driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/dsh-message-projector.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js +5 -4
- package/data/build/dist/host/cli-adapters/dsh-message-projector.js.map +1 -1
- package/data/build/dist/host/cli-adapters/dsh-virtual-providers.d.ts +16 -0
- package/data/build/dist/host/cli-adapters/dsh-virtual-providers.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/dsh-virtual-providers.js +73 -0
- package/data/build/dist/host/cli-adapters/dsh-virtual-providers.js.map +1 -0
- package/data/build/dist/host/cli-adapters/feature.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/feature.js +459 -26
- package/data/build/dist/host/cli-adapters/feature.js.map +1 -1
- package/data/build/dist/host/cli-adapters/gemini-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/gemini-driver.js +21 -5
- package/data/build/dist/host/cli-adapters/gemini-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/grok-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/grok-driver.js +24 -7
- package/data/build/dist/host/cli-adapters/grok-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts +22 -6
- package/data/build/dist/host/cli-adapters/json-rpc-process.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/json-rpc-process.js +118 -21
- package/data/build/dist/host/cli-adapters/json-rpc-process.js.map +1 -1
- package/data/build/dist/host/cli-adapters/kimi-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/kimi-driver.js +25 -4
- package/data/build/dist/host/cli-adapters/kimi-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/kiro-driver.d.ts +12 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.js +18 -0
- package/data/build/dist/host/cli-adapters/kiro-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.d.ts +11 -2
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.js +26 -6
- package/data/build/dist/host/cli-adapters/legacy-session-adapter.js.map +1 -1
- package/data/build/dist/host/cli-adapters/mcode-catalog.d.ts +23 -0
- package/data/build/dist/host/cli-adapters/mcode-catalog.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/mcode-catalog.js +120 -0
- package/data/build/dist/host/cli-adapters/mcode-catalog.js.map +1 -0
- package/data/build/dist/host/cli-adapters/mcode-driver.d.ts +56 -0
- package/data/build/dist/host/cli-adapters/mcode-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/mcode-driver.js +544 -0
- package/data/build/dist/host/cli-adapters/mcode-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts +35 -5
- package/data/build/dist/host/cli-adapters/model-catalog.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/model-catalog.js +213 -8
- package/data/build/dist/host/cli-adapters/model-catalog.js.map +1 -1
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.d.ts +81 -0
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.js +299 -0
- package/data/build/dist/host/cli-adapters/native-subagent-dispatch.js.map +1 -0
- package/data/build/dist/host/cli-adapters/native-subagent-holder.d.ts +4 -0
- package/data/build/dist/host/cli-adapters/native-subagent-holder.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/native-subagent-holder.js +4 -0
- package/data/build/dist/host/cli-adapters/native-subagent-holder.js.map +1 -0
- package/data/build/dist/host/cli-adapters/native-team-proxy.js +18 -15
- package/data/build/dist/host/cli-adapters/native-team-proxy.js.map +1 -1
- package/data/build/dist/host/cli-adapters/native-team-subagent.d.ts +57 -0
- package/data/build/dist/host/cli-adapters/native-team-subagent.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/native-team-subagent.js +126 -0
- package/data/build/dist/host/cli-adapters/native-team-subagent.js.map +1 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.d.ts +75 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.js +959 -0
- package/data/build/dist/host/cli-adapters/new-api-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/opencode-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/opencode-driver.js +22 -10
- package/data/build/dist/host/cli-adapters/opencode-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/pi-driver.js +24 -7
- package/data/build/dist/host/cli-adapters/pi-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts +41 -4
- package/data/build/dist/host/cli-adapters/provider-subscription.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/provider-subscription.js +254 -40
- package/data/build/dist/host/cli-adapters/provider-subscription.js.map +1 -1
- package/data/build/dist/host/cli-adapters/qoder-driver.d.ts +71 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.js +553 -0
- package/data/build/dist/host/cli-adapters/qoder-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.d.ts +31 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.js +178 -0
- package/data/build/dist/host/cli-adapters/qoder-subscription.js.map +1 -0
- package/data/build/dist/host/cli-adapters/registry-holder.d.ts +4 -0
- package/data/build/dist/host/cli-adapters/registry-holder.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/registry-holder.js +9 -0
- package/data/build/dist/host/cli-adapters/registry-holder.js.map +1 -0
- package/data/build/dist/host/cli-adapters/registry.d.ts +54 -2
- package/data/build/dist/host/cli-adapters/registry.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/registry.js +224 -18
- package/data/build/dist/host/cli-adapters/registry.js.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.d.ts +10 -1
- package/data/build/dist/host/cli-adapters/session-store.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/session-store.js +60 -6
- package/data/build/dist/host/cli-adapters/session-store.js.map +1 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts +16 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js +150 -26
- package/data/build/dist/host/cli-adapters/standard-stream-driver.js.map +1 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts +10 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.d.ts.map +1 -1
- package/data/build/dist/host/cli-adapters/stream-normalizer.js +23 -0
- package/data/build/dist/host/cli-adapters/stream-normalizer.js.map +1 -1
- package/data/build/dist/host/cli-adapters/subagent-tool.d.ts +5 -0
- package/data/build/dist/host/cli-adapters/subagent-tool.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/subagent-tool.js +112 -0
- package/data/build/dist/host/cli-adapters/subagent-tool.js.map +1 -0
- package/data/build/dist/host/cli-adapters/zcode-driver.d.ts +57 -0
- package/data/build/dist/host/cli-adapters/zcode-driver.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/zcode-driver.js +843 -0
- package/data/build/dist/host/cli-adapters/zcode-driver.js.map +1 -0
- package/data/build/dist/host/cli-adapters/zcode-subscription.d.ts +28 -0
- package/data/build/dist/host/cli-adapters/zcode-subscription.d.ts.map +1 -0
- package/data/build/dist/host/cli-adapters/zcode-subscription.js +212 -0
- package/data/build/dist/host/cli-adapters/zcode-subscription.js.map +1 -0
- package/data/build/dist/host/cli-bridge/bridge-holder.d.ts +27 -0
- package/data/build/dist/host/cli-bridge/bridge-holder.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/bridge-holder.js +51 -0
- package/data/build/dist/host/cli-bridge/bridge-holder.js.map +1 -0
- package/data/build/dist/host/cli-bridge/bridge-server.d.ts +39 -0
- package/data/build/dist/host/cli-bridge/bridge-server.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/bridge-server.js +140 -0
- package/data/build/dist/host/cli-bridge/bridge-server.js.map +1 -0
- package/data/build/dist/host/cli-bridge/command-code-mod.d.ts +29 -0
- package/data/build/dist/host/cli-bridge/command-code-mod.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/command-code-mod.js +91 -0
- package/data/build/dist/host/cli-bridge/command-code-mod.js.map +1 -0
- package/data/build/dist/host/cli-bridge/dispatch.d.ts +19 -0
- package/data/build/dist/host/cli-bridge/dispatch.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/dispatch.js +128 -0
- package/data/build/dist/host/cli-bridge/dispatch.js.map +1 -0
- package/data/build/dist/host/cli-bridge/injections.d.ts +28 -0
- package/data/build/dist/host/cli-bridge/injections.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/injections.js +131 -0
- package/data/build/dist/host/cli-bridge/injections.js.map +1 -0
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.d.ts +8 -0
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.d.ts.map +1 -0
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js +170 -0
- package/data/build/dist/host/cli-bridge/mcp-stdio-entry.js.map +1 -0
- package/data/build/dist/host/features/lan-access-dsh.d.ts.map +1 -1
- package/data/build/dist/host/features/lan-access-dsh.js +6 -2
- package/data/build/dist/host/features/lan-access-dsh.js.map +1 -1
- package/data/build/dist/host/features/peer-host.d.ts +21 -1
- package/data/build/dist/host/features/peer-host.d.ts.map +1 -1
- package/data/build/dist/host/features/peer-host.js +176 -31
- package/data/build/dist/host/features/peer-host.js.map +1 -1
- package/data/build/dist/host/features/types.d.ts +2 -0
- package/data/build/dist/host/features/types.d.ts.map +1 -1
- package/data/build/dist/host/index.d.ts +15 -1
- package/data/build/dist/host/index.d.ts.map +1 -1
- package/data/build/dist/host/index.js +48 -2
- package/data/build/dist/host/index.js.map +1 -1
- package/data/build/dist/host/lan-access-dsh.d.ts +7 -1
- package/data/build/dist/host/lan-access-dsh.d.ts.map +1 -1
- package/data/build/dist/host/lan-access-dsh.js +95 -19
- package/data/build/dist/host/lan-access-dsh.js.map +1 -1
- package/data/build/dist/host/login-attempt-guard.d.ts +55 -0
- package/data/build/dist/host/login-attempt-guard.d.ts.map +1 -0
- package/data/build/dist/host/login-attempt-guard.js +201 -0
- package/data/build/dist/host/login-attempt-guard.js.map +1 -0
- package/data/build/dist/host/modules/peer-host/host-api-proxy-service.d.ts +3 -0
- package/data/build/dist/host/modules/peer-host/host-api-proxy-service.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/host-api-proxy-service.js +2 -0
- package/data/build/dist/host/modules/peer-host/host-api-proxy-service.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-aggregate-service.d.ts +1 -0
- package/data/build/dist/host/modules/peer-host/peer-host-aggregate-service.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-aggregate-service.js +1 -0
- package/data/build/dist/host/modules/peer-host/peer-host-aggregate-service.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.d.ts +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js +9 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-protocol.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-transport.d.ts +8 -0
- package/data/build/dist/host/modules/peer-host/peer-host-native-transport.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-native-transport.js +9 -0
- package/data/build/dist/host/modules/peer-host/peer-host-native-transport.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-remote-summary-source.d.ts +7 -0
- package/data/build/dist/host/modules/peer-host/peer-host-remote-summary-source.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-remote-summary-source.js +31 -3
- package/data/build/dist/host/modules/peer-host/peer-host-remote-summary-source.js.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.d.ts +2 -0
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.d.ts.map +1 -1
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.js +26 -7
- package/data/build/dist/host/modules/peer-host/peer-host-virtual-registry.js.map +1 -1
- package/data/build/dist/host/modules/pwa/pwa-assets.d.ts +6 -4
- package/data/build/dist/host/modules/pwa/pwa-assets.d.ts.map +1 -1
- package/data/build/dist/host/modules/pwa/pwa-assets.js +11 -9
- package/data/build/dist/host/modules/pwa/pwa-assets.js.map +1 -1
- package/data/build/dist/host/modules/pwa/pwa-session-notifications.d.ts +3 -0
- package/data/build/dist/host/modules/pwa/pwa-session-notifications.d.ts.map +1 -1
- package/data/build/dist/host/modules/pwa/pwa-session-notifications.js +6 -4
- package/data/build/dist/host/modules/pwa/pwa-session-notifications.js.map +1 -1
- package/data/build/dist/host/native-session-bridge.d.ts.map +1 -1
- package/data/build/dist/host/native-session-bridge.js +106 -59
- package/data/build/dist/host/native-session-bridge.js.map +1 -1
- package/data/build/dist/host/rpc.js +8 -2
- package/data/build/dist/host/rpc.js.map +1 -1
- package/data/build/dist/host/settings.d.ts.map +1 -1
- package/data/build/dist/host/settings.js +14 -4
- package/data/build/dist/host/settings.js.map +1 -1
- package/data/build/dist/host/terminal/backends/local-pty-backend.d.ts.map +1 -1
- package/data/build/dist/host/terminal/backends/local-pty-backend.js +14 -0
- package/data/build/dist/host/terminal/backends/local-pty-backend.js.map +1 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts +40 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.d.ts.map +1 -1
- package/data/build/dist/host/terminal/backends/tmux-backend.js +291 -18
- package/data/build/dist/host/terminal/backends/tmux-backend.js.map +1 -1
- package/data/build/dist/host/terminal/runtime-adapter.d.ts +32 -0
- package/data/build/dist/host/terminal/runtime-adapter.d.ts.map +1 -1
- package/data/build/dist/host/terminal/runtime-adapter.js +8 -0
- package/data/build/dist/host/terminal/runtime-adapter.js.map +1 -1
- package/data/build/dist/host/terminal/runtime-manager.d.ts +3 -0
- package/data/build/dist/host/terminal/runtime-manager.d.ts.map +1 -1
- package/data/build/dist/host/terminal/runtime-manager.js +92 -4
- package/data/build/dist/host/terminal/runtime-manager.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-controller.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-controller.js +58 -6
- package/data/build/dist/host/terminal/terminal-controller.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-process-service.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-process-service.js +12 -2
- package/data/build/dist/host/terminal/terminal-process-service.js.map +1 -1
- package/data/build/dist/host/terminal/terminal-service.d.ts +41 -4
- package/data/build/dist/host/terminal/terminal-service.d.ts.map +1 -1
- package/data/build/dist/host/terminal/terminal-service.js +551 -61
- package/data/build/dist/host/terminal/terminal-service.js.map +1 -1
- package/data/build/dist/index.d.ts +2 -2
- package/data/build/dist/index.d.ts.map +1 -1
- package/data/build/dist/index.js +2 -2
- package/data/build/dist/index.js.map +1 -1
- package/data/build/dist/shared/contracts/cli-adapter.d.ts +69 -2
- package/data/build/dist/shared/contracts/cli-adapter.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.d.ts +63 -10
- package/data/build/dist/shared/contracts/config.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/config.js +57 -5
- package/data/build/dist/shared/contracts/config.js.map +1 -1
- package/data/build/dist/shared/contracts/peer-host.d.ts +2 -0
- package/data/build/dist/shared/contracts/peer-host.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/peer-host.js.map +1 -1
- package/data/build/dist/shared/contracts/subscription.d.ts +20 -1
- package/data/build/dist/shared/contracts/subscription.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/subscription.js.map +1 -1
- package/data/build/dist/shared/contracts/terminal.d.ts +8 -1
- package/data/build/dist/shared/contracts/terminal.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/version.d.ts +1 -1
- package/data/build/dist/shared/contracts/version.d.ts.map +1 -1
- package/data/build/dist/shared/contracts/version.js +1 -1
- package/data/build/dist/shared/contracts/version.js.map +1 -1
- package/data/build/dist/shared/debug.d.ts +8 -0
- package/data/build/dist/shared/debug.d.ts.map +1 -1
- package/data/build/dist/shared/debug.js +43 -7
- package/data/build/dist/shared/debug.js.map +1 -1
- package/data/build/dist/shared/delegation-carrier.d.ts +24 -0
- package/data/build/dist/shared/delegation-carrier.d.ts.map +1 -0
- package/data/build/dist/shared/delegation-carrier.js +111 -0
- package/data/build/dist/shared/delegation-carrier.js.map +1 -0
- package/data/build/dist/shared/index.d.ts +3 -3
- package/data/build/dist/shared/index.d.ts.map +1 -1
- package/data/build/dist/shared/index.js +2 -2
- package/data/build/dist/shared/index.js.map +1 -1
- package/data/build/dist/shared/terminal-input.d.ts +8 -0
- package/data/build/dist/shared/terminal-input.d.ts.map +1 -0
- package/data/build/dist/shared/terminal-input.js +10 -0
- package/data/build/dist/shared/terminal-input.js.map +1 -0
- package/data/build/dist/transport/debug.d.ts +7 -0
- package/data/build/dist/transport/debug.d.ts.map +1 -1
- package/data/build/dist/transport/debug.js +33 -5
- package/data/build/dist/transport/debug.js.map +1 -1
- package/data/build/dist/transport/index.d.ts +1 -1
- package/data/build/dist/transport/index.d.ts.map +1 -1
- package/data/build/dist/transport/index.js +1 -1
- package/data/build/dist/transport/index.js.map +1 -1
- package/data/build/dist/typert.host.js +1 -1
- package/data/build/dist/typert.host.js.map +1 -1
- package/package.json +3 -1
- package/profile/README.md +2 -2
- package/profile/package.json +2 -2
- package/profile/version.json +1 -1
- package/version.json +1 -1
|
@@ -0,0 +1,959 @@
|
|
|
1
|
+
import { createDecipheriv, createHash } from 'node:crypto';
|
|
2
|
+
import { existsSync, readFileSync } from 'node:fs';
|
|
3
|
+
import { homedir, userInfo } from 'node:os';
|
|
4
|
+
import { join } from 'node:path';
|
|
5
|
+
/**
|
|
6
|
+
* 从显式配置中解析某个 Agent 的 New-API 来源。
|
|
7
|
+
*
|
|
8
|
+
* providerId 优先用于兼容按提供商名称保存的旧配置;未找到时再读取
|
|
9
|
+
* adapterId。未传配置时返回空数组,来源发现由上层适配器负责。
|
|
10
|
+
*/
|
|
11
|
+
export function resolveNewApiSources(adapterId, providerId, configuredSources) {
|
|
12
|
+
if (configuredSources !== undefined) {
|
|
13
|
+
const configured = providerId !== undefined && configuredSources[providerId] !== undefined
|
|
14
|
+
? configuredSources[providerId]
|
|
15
|
+
: configuredSources[adapterId];
|
|
16
|
+
const sources = configured === undefined ? [] : Array.isArray(configured) ? [...configured] : [configured];
|
|
17
|
+
return sources.filter((source) => !isOfficialAgentBaseUrl(adapterId, source.baseUrl));
|
|
18
|
+
}
|
|
19
|
+
return discoverNewApiSources(adapterId, providerId).filter((source) => !isOfficialAgentBaseUrl(adapterId, source.baseUrl));
|
|
20
|
+
}
|
|
21
|
+
export function isOfficialAgentBaseUrl(_adapterId, value) {
|
|
22
|
+
try {
|
|
23
|
+
const host = new URL(value).hostname.toLowerCase();
|
|
24
|
+
// 官方地址不属于 New-API;这一规则对所有能声明自定义 Provider 的适配器生效。
|
|
25
|
+
// 参数保留在签名中,兼容旧配置解析调用,也避免把同一地址误判为第三方。
|
|
26
|
+
return host === 'api.openai.com'
|
|
27
|
+
|| host === 'api.anthropic.com'
|
|
28
|
+
|| host === 'api.x.ai'
|
|
29
|
+
|| host === 'api.xai.com'
|
|
30
|
+
|| host === 'www.codebuddy.ai'
|
|
31
|
+
|| host === 'copilot.tencent.com'
|
|
32
|
+
|| host === 'www.codebuddy.cn'
|
|
33
|
+
|| host === 'www.workbuddy.cn'
|
|
34
|
+
|| host === 'staging-codebuddy.tencent.com'
|
|
35
|
+
|| host === 'staging.copilot.tencent.com'
|
|
36
|
+
|| host === 'staging.codebuddy.cn';
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return false;
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** 从 Agent 自己的配置读取所有明确声明的自定义上游;不会改变 Sub2API 的来源解析。 */
|
|
43
|
+
function discoverNewApiSources(adapterId, providerId) {
|
|
44
|
+
const result = [];
|
|
45
|
+
const add = (source) => {
|
|
46
|
+
if (source === null || source.baseUrl.trim() === '' || source.apiKey.trim() === '')
|
|
47
|
+
return;
|
|
48
|
+
if (!result.some((item) => item.baseUrl === source.baseUrl && item.apiKey === source.apiKey))
|
|
49
|
+
result.push(source);
|
|
50
|
+
};
|
|
51
|
+
const home = homedir();
|
|
52
|
+
if (adapterId === 'codex')
|
|
53
|
+
add(readCodexSource());
|
|
54
|
+
if (adapterId === 'claude-code')
|
|
55
|
+
add(readClaudeSource());
|
|
56
|
+
if (adapterId === 'opencode') {
|
|
57
|
+
const paths = [
|
|
58
|
+
join(home, '.config', 'opencode', 'opencode.json'),
|
|
59
|
+
join(home, 'Library', 'Application Support', 'opencode', 'opencode.json'),
|
|
60
|
+
...(process.env.APPDATA === undefined ? [] : [join(process.env.APPDATA, 'opencode', 'opencode.json')]),
|
|
61
|
+
];
|
|
62
|
+
paths.flatMap((path) => readConfigSources(readJson(path), providerId)).forEach(add);
|
|
63
|
+
}
|
|
64
|
+
if (adapterId === 'grok') {
|
|
65
|
+
add(envSource('GROK_BASE_URL', 'GROK_API_KEY'));
|
|
66
|
+
add(envSource('XAI_BASE_URL', 'XAI_API_KEY'));
|
|
67
|
+
add(envSource('XAI_API_BASE_URL', 'XAI_API_KEY'));
|
|
68
|
+
readConfigSources(readJson(join(process.env.GROK_HOME ?? join(home, '.grok'), 'config.json')), providerId).forEach(add);
|
|
69
|
+
}
|
|
70
|
+
if (adapterId === 'command-code')
|
|
71
|
+
readCommandCodeSources(providerId).forEach(add);
|
|
72
|
+
if (adapterId === 'zcode')
|
|
73
|
+
readZcodeSources().forEach(add);
|
|
74
|
+
if (adapterId === 'codebuddy' || adapterId === 'workbuddy')
|
|
75
|
+
readCodeBuddySources(adapterId, providerId).forEach(add);
|
|
76
|
+
if (adapterId === 'dsh') {
|
|
77
|
+
if (providerId !== undefined && providerId.trim() !== '')
|
|
78
|
+
add(readNamedDshSource(providerId));
|
|
79
|
+
else {
|
|
80
|
+
add(envSource('DSH_BASE_URL', 'DSH_API_KEY'));
|
|
81
|
+
add(envSource('OPENAI_BASE_URL', 'OPENAI_API_KEY'));
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return result;
|
|
85
|
+
}
|
|
86
|
+
function readCodexSource() {
|
|
87
|
+
const home = process.env.CODEX_HOME ?? join(homedir(), '.codex');
|
|
88
|
+
const config = readText(join(home, 'config.toml')) ?? '';
|
|
89
|
+
const provider = tomlScalar(config, 'model_provider');
|
|
90
|
+
const section = provider === null ? '' : tomlSection(config, `model_providers.${provider}`);
|
|
91
|
+
const baseUrl = tomlScalar(section, 'base_url') ?? textValue(process.env.OPENAI_BASE_URL);
|
|
92
|
+
const envName = tomlScalar(section, 'api_key_env');
|
|
93
|
+
const apiKey = tomlScalar(section, 'experimental_bearer_token') ?? tomlScalar(section, 'api_key') ?? (envName === null ? null : textValue(process.env[envName])) ?? textValue(process.env.OPENAI_API_KEY);
|
|
94
|
+
return baseUrl === null || apiKey === null ? null : { baseUrl, apiKey };
|
|
95
|
+
}
|
|
96
|
+
function readClaudeSource() {
|
|
97
|
+
const home = process.env.CLAUDE_CONFIG_DIR ?? join(homedir(), '.claude');
|
|
98
|
+
const env = recordValue(readJson(join(home, 'settings.json'))?.env);
|
|
99
|
+
const baseUrl = textValue(process.env.ANTHROPIC_BASE_URL) ?? textValue(env?.ANTHROPIC_BASE_URL);
|
|
100
|
+
const apiKey = textValue(process.env.ANTHROPIC_AUTH_TOKEN) ?? textValue(process.env.ANTHROPIC_API_KEY) ?? textValue(env?.ANTHROPIC_AUTH_TOKEN) ?? textValue(env?.ANTHROPIC_API_KEY);
|
|
101
|
+
return baseUrl === null || apiKey === null ? null : { baseUrl, apiKey };
|
|
102
|
+
}
|
|
103
|
+
function readNamedDshSource(providerId) {
|
|
104
|
+
const prefix = providerId.replace(/[^a-z0-9]+/giu, '_').toUpperCase();
|
|
105
|
+
const env = envSource(`${prefix}_BASE_URL`, `${prefix}_API_KEY`);
|
|
106
|
+
if (env !== null)
|
|
107
|
+
return env;
|
|
108
|
+
const home = process.env.DSH_HOME ?? join(homedir(), '.dsh');
|
|
109
|
+
for (const path of [join(home, 'settings.yaml'), join(home, 'settings.yaml.imported')]) {
|
|
110
|
+
const source = readDshYamlSource(path, providerId);
|
|
111
|
+
if (source !== null)
|
|
112
|
+
return source;
|
|
113
|
+
}
|
|
114
|
+
return null;
|
|
115
|
+
}
|
|
116
|
+
function readDshYamlSource(path, providerId) {
|
|
117
|
+
const text = readText(path);
|
|
118
|
+
if (text === null)
|
|
119
|
+
return null;
|
|
120
|
+
const escaped = providerId.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
121
|
+
const start = text.search(new RegExp(`^ {4}${escaped}:\\s*$`, 'mu'));
|
|
122
|
+
if (start < 0)
|
|
123
|
+
return null;
|
|
124
|
+
const rest = text.slice(start);
|
|
125
|
+
const next = /^ {4}\S[^\n]*$/mu.exec(rest.slice(1));
|
|
126
|
+
const block = next === null ? rest : rest.slice(0, next.index + 1);
|
|
127
|
+
const baseUrl = yamlScalar(block.match(/^\s+baseURL:\s*(.+)$/mu)?.[1]);
|
|
128
|
+
const keyRef = yamlScalar(block.match(/^\s+apiKeyEnv:\s*(.+)$/mu)?.[1]);
|
|
129
|
+
const apiKey = keyRef === null ? null : textValue(process.env[keyRef]) ?? readDshCredential(keyRef);
|
|
130
|
+
return baseUrl === null || apiKey === null ? null : { baseUrl, apiKey };
|
|
131
|
+
}
|
|
132
|
+
function readZcodeSources() {
|
|
133
|
+
const paths = [process.env.ZCODE_PERSONAL_PROVIDER_CONFIG_FILE, process.env.ZCODE_BUILTIN_PROVIDER_CONFIG_FILE, join(homedir(), '.zcode', 'v2', 'provider_config.json')].filter((value) => typeof value === 'string' && value.trim() !== '');
|
|
134
|
+
const result = paths.flatMap((path) => {
|
|
135
|
+
const value = readJson(path);
|
|
136
|
+
return [...readConfigSources(value), ...readZcodeRuleSources(value)];
|
|
137
|
+
});
|
|
138
|
+
return result;
|
|
139
|
+
}
|
|
140
|
+
/** ZCode 的 Provider 规则和凭据分开保存;这里只拼出明确声明了 endpoint 的来源。 */
|
|
141
|
+
function readZcodeRuleSources(value) {
|
|
142
|
+
const config = recordValue(value?.config);
|
|
143
|
+
const rules = recordValue(config?.providerConfigRules)?.providerRules;
|
|
144
|
+
if (!Array.isArray(rules))
|
|
145
|
+
return [];
|
|
146
|
+
return rules.flatMap((item) => {
|
|
147
|
+
const rule = recordValue(item);
|
|
148
|
+
const providerId = textValue(rule?.providerId);
|
|
149
|
+
const ruleConfig = recordValue(rule?.config);
|
|
150
|
+
const baseUrl = textValue(ruleConfig?.baseURL ?? ruleConfig?.baseUrl ?? ruleConfig?.base_url ?? ruleConfig?.apiBaseUrl ?? ruleConfig?.api_base_url ?? ruleConfig?.endpoint ?? rule?.baseURL ?? rule?.baseUrl ?? rule?.endpoint);
|
|
151
|
+
const apiKey = textValue(ruleConfig?.apiKey ?? ruleConfig?.api_key ?? rule?.apiKey ?? rule?.api_key)
|
|
152
|
+
?? (providerId === null ? null : readZcodeProviderApiKey(providerId));
|
|
153
|
+
return baseUrl === null || apiKey === null ? [] : [{ baseUrl, apiKey }];
|
|
154
|
+
});
|
|
155
|
+
}
|
|
156
|
+
function readZcodeProviderApiKey(providerId) {
|
|
157
|
+
const path = process.env.ZCODE_CREDENTIALS_FILE ?? join(homedir(), '.zcode', 'v2', 'credentials.json');
|
|
158
|
+
const credentials = readJson(path);
|
|
159
|
+
if (credentials === null)
|
|
160
|
+
return null;
|
|
161
|
+
const prefix = `account-provider:coding-plan:${providerId}:account:`;
|
|
162
|
+
const key = Object.keys(credentials).find((candidate) => candidate.startsWith(prefix) && candidate.endsWith(':api-key'));
|
|
163
|
+
const value = key === undefined ? null : textValue(credentials[key]);
|
|
164
|
+
return value === null ? null : decryptZcodeCredential(value);
|
|
165
|
+
}
|
|
166
|
+
function decryptZcodeCredential(value) {
|
|
167
|
+
if (!value.startsWith('enc:v1:'))
|
|
168
|
+
return value;
|
|
169
|
+
const [ivRaw, authTagRaw, cipherRaw] = value.slice('enc:v1:'.length).split('.');
|
|
170
|
+
if (ivRaw === undefined || authTagRaw === undefined || cipherRaw === undefined)
|
|
171
|
+
return '';
|
|
172
|
+
try {
|
|
173
|
+
const iv = Buffer.from(ivRaw, 'base64url');
|
|
174
|
+
const authTag = Buffer.from(authTagRaw, 'base64url');
|
|
175
|
+
const cipherText = Buffer.from(cipherRaw, 'base64url');
|
|
176
|
+
if (iv.length !== 12 || authTag.length !== 16)
|
|
177
|
+
return '';
|
|
178
|
+
let username = 'unknown';
|
|
179
|
+
try {
|
|
180
|
+
username = userInfo().username;
|
|
181
|
+
}
|
|
182
|
+
catch { /* 沙箱环境可能无法读取用户名。 */ }
|
|
183
|
+
const secret = `zcode-credential-fallback:${process.platform}:${homedir()}:${username}`;
|
|
184
|
+
const decipher = createDecipheriv('aes-256-gcm', createHash('sha256').update(secret).digest(), iv);
|
|
185
|
+
decipher.setAuthTag(authTag);
|
|
186
|
+
return Buffer.concat([decipher.update(cipherText), decipher.final()]).toString('utf8').trim();
|
|
187
|
+
}
|
|
188
|
+
catch {
|
|
189
|
+
return '';
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
function readCommandCodeSources(providerId) {
|
|
193
|
+
const home = process.env.COMMANDCODE_HOME ?? join(homedir(), '.commandcode');
|
|
194
|
+
const providers = readJson(join(home, 'providers.json'));
|
|
195
|
+
const auth = readJson(join(home, 'auth.json'));
|
|
196
|
+
const providerMap = recordValue(providers?.provider) ?? recordValue(providers?.providers);
|
|
197
|
+
const selected = providerId === undefined || providerMap === null ? providerMap : recordValue(providerMap[providerId]);
|
|
198
|
+
const direct = readConfigSources(selected ?? providers, providerId);
|
|
199
|
+
const authSources = readConfigSources(auth, providerId);
|
|
200
|
+
return [...direct, ...authSources];
|
|
201
|
+
}
|
|
202
|
+
function readCodeBuddySources(adapterId, providerId) {
|
|
203
|
+
if (adapterId === 'codebuddy-cn')
|
|
204
|
+
adapterId = 'codebuddy';
|
|
205
|
+
// WorkBuddy 桌面应用的配置与认证根是 `.workbuddy`;旧的 `.workbuddy-ai`
|
|
206
|
+
// 目录不会包含桌面登录态,也不能作为 New-API 来源发现的默认目录。
|
|
207
|
+
const home = adapterId === 'workbuddy' ? join(homedir(), '.workbuddy') : join(homedir(), '.codebuddy');
|
|
208
|
+
const roots = adapterId === 'workbuddy'
|
|
209
|
+
? [process.env.WORKBUDDY_CONFIG_DIR ?? home]
|
|
210
|
+
: [process.env.CODEBUDDY_CONFIG_DIR, process.env.CODEBUDDY_CN_CONFIG_DIR, home, join(homedir(), '.codebuddy-cn')];
|
|
211
|
+
return [...new Set(roots.filter((root) => typeof root === 'string' && root.trim() !== ''))]
|
|
212
|
+
.flatMap((root) => ['config.json', 'settings.json', 'providers.json', 'auth.json']
|
|
213
|
+
.flatMap((name) => readConfigSources(readJson(join(root, name)), providerId)));
|
|
214
|
+
}
|
|
215
|
+
function readConfigSources(value, providerId) {
|
|
216
|
+
const result = [];
|
|
217
|
+
const root = providerId !== undefined && recordValue(value) !== null
|
|
218
|
+
? selectProviderNode(recordValue(value), providerId)
|
|
219
|
+
: value;
|
|
220
|
+
const walk = (node, depth) => {
|
|
221
|
+
if (depth > 8 || node === null || typeof node !== 'object')
|
|
222
|
+
return;
|
|
223
|
+
if (Array.isArray(node)) {
|
|
224
|
+
for (const child of node)
|
|
225
|
+
walk(child, depth + 1);
|
|
226
|
+
return;
|
|
227
|
+
}
|
|
228
|
+
const record = node;
|
|
229
|
+
const baseUrl = textValue(record.baseURL ?? record.baseUrl ?? record.base_url ?? record.apiBaseUrl ?? record.api_base_url ?? record.endpoint);
|
|
230
|
+
const key = textValue(record.apiKey ?? record.api_key ?? record.key) ?? (() => {
|
|
231
|
+
const envName = textValue(record.apiKeyEnv ?? record.api_key_env);
|
|
232
|
+
return envName === null ? null : textValue(process.env[envName]);
|
|
233
|
+
})();
|
|
234
|
+
if (baseUrl !== null && key !== null)
|
|
235
|
+
result.push({ baseUrl, apiKey: key });
|
|
236
|
+
for (const child of Object.values(record))
|
|
237
|
+
walk(child, depth + 1);
|
|
238
|
+
};
|
|
239
|
+
walk(root, 0);
|
|
240
|
+
return result;
|
|
241
|
+
}
|
|
242
|
+
function selectProviderNode(value, providerId) {
|
|
243
|
+
const direct = value[providerId];
|
|
244
|
+
if (direct !== undefined)
|
|
245
|
+
return direct;
|
|
246
|
+
for (const key of ['provider', 'providers', 'providerConfigRules', 'providerRules']) {
|
|
247
|
+
const raw = value[key];
|
|
248
|
+
const nested = recordValue(raw);
|
|
249
|
+
if (nested?.[providerId] !== undefined)
|
|
250
|
+
return nested[providerId];
|
|
251
|
+
if (Array.isArray(raw)) {
|
|
252
|
+
const match = raw.find((item) => {
|
|
253
|
+
const record = recordValue(item);
|
|
254
|
+
return textValue(record?.providerId ?? record?.id) === providerId;
|
|
255
|
+
});
|
|
256
|
+
if (match !== undefined)
|
|
257
|
+
return match;
|
|
258
|
+
}
|
|
259
|
+
}
|
|
260
|
+
return value;
|
|
261
|
+
}
|
|
262
|
+
function envSource(baseName, keyName) {
|
|
263
|
+
const baseUrl = textValue(process.env[baseName]);
|
|
264
|
+
const apiKey = textValue(process.env[keyName]);
|
|
265
|
+
return baseUrl === null || apiKey === null ? null : { baseUrl, apiKey };
|
|
266
|
+
}
|
|
267
|
+
function readText(path) {
|
|
268
|
+
if (!existsSync(path))
|
|
269
|
+
return null;
|
|
270
|
+
try {
|
|
271
|
+
return readFileSync(path, 'utf8');
|
|
272
|
+
}
|
|
273
|
+
catch {
|
|
274
|
+
return null;
|
|
275
|
+
}
|
|
276
|
+
}
|
|
277
|
+
function readDshCredential(name) {
|
|
278
|
+
const home = process.env.DSH_HOME ?? join(homedir(), '.dsh');
|
|
279
|
+
const paths = [join(home, '.credentials.yaml'), join(home, '.env'), join(process.cwd(), '.env')];
|
|
280
|
+
const yamlPattern = new RegExp(`^\\s*${name}\\s*:\\s*(?:"([^"]*)"|'([^']*)'|([^#\\s]+))`, 'mu');
|
|
281
|
+
const envPattern = new RegExp(`^\\s*${name}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^#\\s]+))`, 'mu');
|
|
282
|
+
for (const path of paths) {
|
|
283
|
+
const text = readText(path);
|
|
284
|
+
if (text === null)
|
|
285
|
+
continue;
|
|
286
|
+
const match = path.endsWith('.env') ? envPattern.exec(text) : yamlPattern.exec(text);
|
|
287
|
+
const value = match?.[1] ?? match?.[2] ?? match?.[3];
|
|
288
|
+
if (typeof value === 'string' && value.trim() !== '')
|
|
289
|
+
return value.trim();
|
|
290
|
+
}
|
|
291
|
+
return null;
|
|
292
|
+
}
|
|
293
|
+
function readJson(path) {
|
|
294
|
+
const text = readText(path);
|
|
295
|
+
if (text === null)
|
|
296
|
+
return null;
|
|
297
|
+
try {
|
|
298
|
+
return recordValue(JSON.parse(text));
|
|
299
|
+
}
|
|
300
|
+
catch {
|
|
301
|
+
return null;
|
|
302
|
+
}
|
|
303
|
+
}
|
|
304
|
+
function tomlSection(source, name) {
|
|
305
|
+
const escaped = name.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
306
|
+
const start = source.search(new RegExp(`^\\[${escaped}\\]\\s*$`, 'mu'));
|
|
307
|
+
if (start < 0)
|
|
308
|
+
return '';
|
|
309
|
+
const rest = source.slice(start);
|
|
310
|
+
const next = /^\[[^\n]+\]\s*$/mu.exec(rest.slice(1));
|
|
311
|
+
return next === null ? rest : rest.slice(0, next.index + 1);
|
|
312
|
+
}
|
|
313
|
+
function tomlScalar(source, key) {
|
|
314
|
+
const escaped = key.replace(/[.*+?^${}()|[\]\\]/gu, '\\$&');
|
|
315
|
+
const match = new RegExp(`^\\s*${escaped}\\s*=\\s*(?:"([^"]*)"|'([^']*)'|([^#\\s]+))`, 'mu').exec(source);
|
|
316
|
+
return textValue(match?.[1] ?? match?.[2] ?? match?.[3]);
|
|
317
|
+
}
|
|
318
|
+
function yamlScalar(value) {
|
|
319
|
+
if (value === undefined)
|
|
320
|
+
return null;
|
|
321
|
+
const normalized = value.trim().replace(/^(['"])(.*)\1$/u, '$2');
|
|
322
|
+
return normalized === '' ? null : normalized;
|
|
323
|
+
}
|
|
324
|
+
export class NewApiSubscriptionService {
|
|
325
|
+
timeoutMs;
|
|
326
|
+
request;
|
|
327
|
+
configuredSources;
|
|
328
|
+
constructor(options = {}) {
|
|
329
|
+
this.request = options.fetch ?? fetch;
|
|
330
|
+
this.timeoutMs = options.timeoutMs ?? 8_000;
|
|
331
|
+
this.configuredSources = options.sources;
|
|
332
|
+
}
|
|
333
|
+
hasSource(adapterId, providerId) {
|
|
334
|
+
return resolveNewApiSources(adapterId, providerId, this.configuredSources).length > 0;
|
|
335
|
+
}
|
|
336
|
+
/** 判断当前来源是否由调用方显式注入;用于避免把本机其它 Agent 配置混入分类探测。 */
|
|
337
|
+
hasConfiguredSource(adapterId, providerId) {
|
|
338
|
+
if (this.configuredSources === undefined)
|
|
339
|
+
return false;
|
|
340
|
+
return (providerId !== undefined && this.configuredSources[providerId] !== undefined)
|
|
341
|
+
|| this.configuredSources[adapterId] !== undefined;
|
|
342
|
+
}
|
|
343
|
+
resolveSources(adapterId, providerId) {
|
|
344
|
+
return resolveNewApiSources(adapterId, providerId, this.configuredSources);
|
|
345
|
+
}
|
|
346
|
+
async read(adapterId = 'dsh', providerId, source) {
|
|
347
|
+
const result = await this.readWithKind(adapterId, providerId, source);
|
|
348
|
+
return result?.usage ?? null;
|
|
349
|
+
}
|
|
350
|
+
async readWithKind(adapterId = 'dsh', providerId, source) {
|
|
351
|
+
const sources = source === undefined
|
|
352
|
+
? resolveNewApiSources(adapterId, providerId, this.configuredSources)
|
|
353
|
+
: [source];
|
|
354
|
+
for (const candidate of sources) {
|
|
355
|
+
const result = await this.readSourceWithKind(candidate);
|
|
356
|
+
if (result !== null)
|
|
357
|
+
return result;
|
|
358
|
+
}
|
|
359
|
+
return null;
|
|
360
|
+
}
|
|
361
|
+
async readSourceWithKind(source) {
|
|
362
|
+
const baseUrl = sanitizeUpstreamUrl(source.baseUrl);
|
|
363
|
+
const apiKey = source.apiKey.trim();
|
|
364
|
+
if (baseUrl === '' || apiKey === '')
|
|
365
|
+
return null;
|
|
366
|
+
const headers = {
|
|
367
|
+
Authorization: apiKey.startsWith('Bearer ') ? apiKey : `Bearer ${apiKey}`,
|
|
368
|
+
Accept: 'application/json',
|
|
369
|
+
};
|
|
370
|
+
const apiRoot = stripVersionSuffix(baseUrl);
|
|
371
|
+
const controller = new AbortController();
|
|
372
|
+
const timer = setTimeout(() => controller.abort(), this.timeoutMs);
|
|
373
|
+
try {
|
|
374
|
+
// New-API 官方路由通常注册为带斜杠的路径。先按统一协议请求无斜杠地址;
|
|
375
|
+
// 某些反向代理会把它返回 404/405,而不是自动重定向,此时再补一次斜杠。
|
|
376
|
+
// 认证失败不能重试成另一种结果,避免把失效 Key 误判为可用来源。
|
|
377
|
+
const tokenResponse = await this.requestJsonWithTrailingSlashFallback(`${apiRoot}/api/usage/token`, headers, controller.signal);
|
|
378
|
+
// 401/403 是凭据无效;不能把 billing 的错误响应误当成有效余额。
|
|
379
|
+
if (tokenResponse?.status === 401 || tokenResponse?.status === 403)
|
|
380
|
+
return null;
|
|
381
|
+
const tokenUsage = tokenResponse?.value ?? null;
|
|
382
|
+
// billing 是补充接口,即使 Token 主接口成功也要读取,用来补齐累计用量和到期时间。
|
|
383
|
+
// 两个补充请求共享同一超时并行执行,避免一个慢接口阻塞另一个可用结果。
|
|
384
|
+
const billingRoot = `${apiRoot}/v1`;
|
|
385
|
+
const [subscriptionResponse, usageResponse, logResponse, accountResponse, tokenListResponse, statusResponse] = await Promise.all([
|
|
386
|
+
this.requestJson(`${billingRoot}/dashboard/billing/subscription`, headers, controller.signal),
|
|
387
|
+
this.requestJson(`${billingRoot}/dashboard/billing/usage`, headers, controller.signal),
|
|
388
|
+
this.requestJson(`${apiRoot}/api/log/token`, headers, controller.signal),
|
|
389
|
+
// One-API 兼容部署可能不把余额放进 /api/usage/token,而是放在
|
|
390
|
+
// 用户摘要或令牌列表的 quota/used_quota/remain_quota 字段中。
|
|
391
|
+
this.requestJson(`${apiRoot}/api/user/self`, headers, controller.signal),
|
|
392
|
+
this.requestJsonWithTrailingSlashFallback(`${apiRoot}/api/token`, headers, controller.signal),
|
|
393
|
+
this.requestJson(`${apiRoot}/api/status`, headers, controller.signal),
|
|
394
|
+
]);
|
|
395
|
+
const tokenResult = tokenUsage === null ? null : normalizeNewApiUsage(tokenUsage, baseUrl);
|
|
396
|
+
const quotaInfo = readNewApiQuotaInfo(statusResponse?.value);
|
|
397
|
+
const accountResult = normalizeNewApiAccount(accountResponse?.value, baseUrl, tokenResult?.providerBalance?.unit ?? quotaInfo.unit, quotaInfo.quotaPerUnit) ?? normalizeNewApiAccount(tokenListResponse?.value, baseUrl, tokenResult?.providerBalance?.unit ?? quotaInfo.unit, quotaInfo.quotaPerUnit);
|
|
398
|
+
const billingResult = normalizeNewApiBilling(subscriptionResponse?.value ?? null, usageResponse?.value ?? null, baseUrl, Date.now(), tokenResult?.providerBalance?.used ?? null, tokenResult?.providerBalance?.unit ?? null);
|
|
399
|
+
const logSummary = summarizeNewApiLogs(logResponse?.value);
|
|
400
|
+
if (tokenResult !== null) {
|
|
401
|
+
const merged = mergeNewApiAccount(mergeNewApiUsage(tokenResult, billingResult), accountResult);
|
|
402
|
+
return { usage: enrichNewApiLogs(merged, logSummary), kind: 'new-api' };
|
|
403
|
+
}
|
|
404
|
+
if (accountResult !== null) {
|
|
405
|
+
const merged = mergeNewApiAccount(billingResult ?? accountResult, accountResult);
|
|
406
|
+
return { usage: enrichNewApiLogs(merged, logSummary), kind: 'new-api' };
|
|
407
|
+
}
|
|
408
|
+
if (billingResult !== null)
|
|
409
|
+
return { usage: enrichNewApiLogs(billingResult, logSummary), kind: 'new-api-billing-compatible' };
|
|
410
|
+
return null;
|
|
411
|
+
}
|
|
412
|
+
finally {
|
|
413
|
+
clearTimeout(timer);
|
|
414
|
+
}
|
|
415
|
+
}
|
|
416
|
+
async requestJson(url, headers, signal) {
|
|
417
|
+
try {
|
|
418
|
+
const response = await this.request(url, { headers, signal });
|
|
419
|
+
if (!response.ok)
|
|
420
|
+
return { status: response.status, value: null };
|
|
421
|
+
return { status: response.status, value: await response.json() };
|
|
422
|
+
}
|
|
423
|
+
catch {
|
|
424
|
+
return null;
|
|
425
|
+
}
|
|
426
|
+
}
|
|
427
|
+
async requestJsonWithTrailingSlashFallback(url, headers, signal) {
|
|
428
|
+
const first = await this.requestJson(url, headers, signal);
|
|
429
|
+
if (first === null || (first.status !== 404 && first.status !== 405))
|
|
430
|
+
return first;
|
|
431
|
+
return this.requestJson(`${url}/`, headers, signal);
|
|
432
|
+
}
|
|
433
|
+
}
|
|
434
|
+
/** 规范化 /api/usage/token/ 的响应。可独立用于 fixture 测试。 */
|
|
435
|
+
export function normalizeNewApiUsage(value, baseUrl, nowMs = Date.now()) {
|
|
436
|
+
const root = recordValue(value);
|
|
437
|
+
const data = recordValue(root?.data) ?? root;
|
|
438
|
+
if (data === null)
|
|
439
|
+
return null;
|
|
440
|
+
const object = textValue(data.object);
|
|
441
|
+
const tokenSignatureKeys = ['unlimited_quota', 'total_available', 'total_granted', 'total_used', 'model_limits', 'balance_source', 'is_active'];
|
|
442
|
+
const tokenSignatureCount = tokenSignatureKeys.filter((key) => data[key] !== undefined).length;
|
|
443
|
+
const hasTokenSignature = object === 'token_usage' || tokenSignatureCount >= 2;
|
|
444
|
+
// 读取器先做协议识别,再做字段归一化;不能因为普通 JSON 恰好带 remaining 就抢走 Sub2API。
|
|
445
|
+
if (object !== null && object !== 'token_usage')
|
|
446
|
+
return null;
|
|
447
|
+
if (!hasTokenSignature)
|
|
448
|
+
return null;
|
|
449
|
+
const unlimited = data.unlimited_quota === true;
|
|
450
|
+
const granted = numberValue(data.total_granted);
|
|
451
|
+
const used = numberValue(data.total_used);
|
|
452
|
+
// New-API 的无限额度常用 100000000 作为展示哨兵值,不能当作真实余额。
|
|
453
|
+
const rawRemaining = numberValue(data.remaining);
|
|
454
|
+
const rawAvailable = numberValue(data.total_available);
|
|
455
|
+
const isUnlimitedSentinel = (value) => value === 100000000;
|
|
456
|
+
// 无限额度时 total_available 通常是内部账务差值,可能为负数;只有
|
|
457
|
+
// 上游明确给出的非负 remaining 才能作为用户可见余额。
|
|
458
|
+
const remainingFromUpstream = unlimited
|
|
459
|
+
? rawRemaining !== null && rawRemaining >= 0 && !isUnlimitedSentinel(rawRemaining)
|
|
460
|
+
? rawRemaining
|
|
461
|
+
: null
|
|
462
|
+
: isUnlimitedSentinel(rawRemaining)
|
|
463
|
+
? null
|
|
464
|
+
: rawRemaining ?? (isUnlimitedSentinel(rawAvailable) ? null : rawAvailable);
|
|
465
|
+
const rawExpiresAt = numberValue(data.expires_at);
|
|
466
|
+
const permanent = rawExpiresAt !== null && rawExpiresAt <= 0;
|
|
467
|
+
const expiresAt = permanent ? null : unixSeconds(data.expires_at);
|
|
468
|
+
const active = typeof data.is_active === 'boolean' ? data.is_active : null;
|
|
469
|
+
const keyExpired = active !== null ? !active : permanent ? false : expiresAt === null ? null : expiresAt * 1_000 <= nowMs;
|
|
470
|
+
const total = unlimited ? null : granted ?? (used !== null && remainingFromUpstream !== null ? used + remainingFromUpstream : null);
|
|
471
|
+
const remaining = remainingFromUpstream ?? (total !== null && used !== null ? Math.max(0, total - used) : null);
|
|
472
|
+
if (!unlimited && used === null && remaining === null && total === null && expiresAt === null)
|
|
473
|
+
return null;
|
|
474
|
+
const unit = textValue(data.unit ?? data.quota_unit ?? data.quotaUnit);
|
|
475
|
+
const planName = textValue(data.plan_name ?? data.planName ?? data.name);
|
|
476
|
+
const providerBalance = {
|
|
477
|
+
upstreamUrl: sanitizeUpstreamUrl(baseUrl),
|
|
478
|
+
currency: null,
|
|
479
|
+
unit,
|
|
480
|
+
balance: remaining,
|
|
481
|
+
remaining,
|
|
482
|
+
used,
|
|
483
|
+
total,
|
|
484
|
+
requests: null,
|
|
485
|
+
inputTokens: null,
|
|
486
|
+
outputTokens: null,
|
|
487
|
+
planName,
|
|
488
|
+
expiresAt,
|
|
489
|
+
keyExpired,
|
|
490
|
+
details: [
|
|
491
|
+
{ label: '余额/剩余额度', value: remaining ?? '上游未提供' },
|
|
492
|
+
{ label: /token/i.test(unit ?? '') ? '累计 Token' : unit === null ? '上游原始额度' : '累计用量', value: used ?? '上游未提供' },
|
|
493
|
+
{ label: '今日 Token', value: '上游未提供' },
|
|
494
|
+
{ label: '今日费用', value: '上游未提供' },
|
|
495
|
+
{ label: '累计费用', value: '上游未提供' },
|
|
496
|
+
{ label: '按模型统计', value: '上游未提供' },
|
|
497
|
+
{ label: '模型限制', value: formatNewApiModelLimits(data.model_limits, data.model_limits_enabled) },
|
|
498
|
+
{ label: '按日统计', value: '上游未提供' },
|
|
499
|
+
{ label: '日订阅窗口', value: '上游未提供' },
|
|
500
|
+
{ label: '周订阅窗口', value: '上游未提供' },
|
|
501
|
+
{ label: '月订阅窗口', value: '上游未提供' },
|
|
502
|
+
{ label: '重置时间', value: '上游未提供' },
|
|
503
|
+
{ label: 'API Key 到期时间', value: permanent ? '永久有效' : expiresAt === null ? '上游未提供' : new Date(expiresAt * 1000).toISOString() },
|
|
504
|
+
{ label: 'API Key 是否过期', value: keyExpired === null ? '上游未提供' : keyExpired ? '已过期' : '有效' },
|
|
505
|
+
{ label: '无限额度', value: unlimited ? '是' : '否' },
|
|
506
|
+
],
|
|
507
|
+
};
|
|
508
|
+
return buildUsage(baseUrl, null, providerBalance, keyExpired === true ? 'expired' : null);
|
|
509
|
+
}
|
|
510
|
+
/** 规范化旧版 OpenAI billing subscription/usage 响应。 */
|
|
511
|
+
export function normalizeNewApiBilling(subscriptionValue, usageValue, baseUrl, nowMs = Date.now(), tokenRawUsed = null, tokenUnit = null) {
|
|
512
|
+
const subscriptionRoot = recordValue(subscriptionValue);
|
|
513
|
+
const subscription = recordValue(subscriptionRoot?.data) ?? subscriptionRoot;
|
|
514
|
+
if (subscription === null || textValue(subscription.object) !== 'billing_subscription')
|
|
515
|
+
return null;
|
|
516
|
+
const usageRoot = recordValue(usageValue);
|
|
517
|
+
const usage = recordValue(usageRoot?.data) ?? usageRoot;
|
|
518
|
+
const rawLimit = numberValue(subscription.hard_limit_usd ?? subscription.soft_limit_usd);
|
|
519
|
+
// New-API 无限额度会在 billing 中复用 100000000 展示哨兵值。
|
|
520
|
+
const limit = rawLimit === 100000000 ? null : rawLimit;
|
|
521
|
+
const rawUsed = usage === null ? null : numberValue(usage.total_usage);
|
|
522
|
+
// 真实 New-API 响应经常省略 unit/currency,字段名本身不能证明站点展示口径。
|
|
523
|
+
const hasUsdLimit = subscription.hard_limit_usd !== undefined || subscription.soft_limit_usd !== undefined;
|
|
524
|
+
const explicitUnit = textValue(subscription.unit ?? subscription.currency ?? usage?.unit ?? usage?.currency);
|
|
525
|
+
// 独立调用时没有 Token 原始配额可供交叉验证,保留兼容 OpenAI billing
|
|
526
|
+
// 的 USD 解释;读取器联动调用时若无法判定则保持单位未知。
|
|
527
|
+
const fallbackUnit = hasUsdLimit && (tokenRawUsed === null || tokenUnit !== null) ? 'USD' : null;
|
|
528
|
+
const unit = explicitUnit ?? inferNewApiBillingUnit(rawUsed, tokenRawUsed) ?? fallbackUnit;
|
|
529
|
+
const used = unit === null || rawUsed === null ? null : rawUsed / 100;
|
|
530
|
+
const remaining = unit !== null && limit !== null && used !== null ? Math.max(0, limit - used) : null;
|
|
531
|
+
const rawExpiresAt = numberValue(subscription.access_until);
|
|
532
|
+
const permanent = rawExpiresAt !== null && rawExpiresAt <= 0;
|
|
533
|
+
const expiresAt = permanent ? null : unixSeconds(subscription.access_until);
|
|
534
|
+
const keyExpired = permanent ? false : expiresAt === null ? null : expiresAt * 1_000 <= nowMs;
|
|
535
|
+
if (limit === null && used === null && expiresAt === null)
|
|
536
|
+
return null;
|
|
537
|
+
const providerBalance = {
|
|
538
|
+
upstreamUrl: sanitizeUpstreamUrl(baseUrl),
|
|
539
|
+
currency: unit,
|
|
540
|
+
unit,
|
|
541
|
+
balance: remaining,
|
|
542
|
+
remaining,
|
|
543
|
+
used,
|
|
544
|
+
total: unit === null ? null : limit,
|
|
545
|
+
requests: null,
|
|
546
|
+
inputTokens: null,
|
|
547
|
+
outputTokens: null,
|
|
548
|
+
planName: null,
|
|
549
|
+
expiresAt,
|
|
550
|
+
keyExpired,
|
|
551
|
+
details: [
|
|
552
|
+
{ label: '余额/剩余额度', value: remaining ?? '上游未提供' },
|
|
553
|
+
{ label: '余额上限', value: limit ?? '上游未提供' },
|
|
554
|
+
{ label: unit === null ? '上游原始用量' : /token/i.test(unit) ? '累计 Token' : '累计费用', value: used ?? rawUsed ?? '上游未提供' },
|
|
555
|
+
{ label: '上游单位', value: unit ?? '上游单位未明确' },
|
|
556
|
+
{ label: '今日 Token', value: '上游未提供' },
|
|
557
|
+
{ label: '累计 Token', value: '上游未提供' },
|
|
558
|
+
{ label: '按模型统计', value: '上游未提供' },
|
|
559
|
+
{ label: '按日统计', value: '上游未提供' },
|
|
560
|
+
{ label: '日订阅窗口', value: '上游未提供' },
|
|
561
|
+
{ label: '周订阅窗口', value: '上游未提供' },
|
|
562
|
+
{ label: '月订阅窗口', value: '上游未提供' },
|
|
563
|
+
{ label: '重置时间', value: '上游未提供' },
|
|
564
|
+
{ label: 'API Key 到期时间', value: permanent ? '永久有效' : expiresAt === null ? '上游未提供' : new Date(expiresAt * 1000).toISOString() },
|
|
565
|
+
{ label: 'API Key 是否过期', value: keyExpired === null ? '上游未提供' : keyExpired ? '已过期' : '有效' },
|
|
566
|
+
{ label: '无限额度', value: rawLimit === 100000000 ? '是' : '否' },
|
|
567
|
+
],
|
|
568
|
+
};
|
|
569
|
+
return buildUsage(baseUrl, null, providerBalance, keyExpired === true ? 'expired' : null);
|
|
570
|
+
}
|
|
571
|
+
/** 读取 One-API 兼容账户摘要中的 quota/used_quota/remain_quota。 */
|
|
572
|
+
function normalizeNewApiAccount(value, baseUrl, unit, quotaPerUnit) {
|
|
573
|
+
const root = recordValue(value);
|
|
574
|
+
const rawData = root?.data ?? value;
|
|
575
|
+
const candidate = Array.isArray(rawData) ? recordValue(rawData[0]) : recordValue(rawData);
|
|
576
|
+
if (candidate === null)
|
|
577
|
+
return null;
|
|
578
|
+
// One-API 的 `quota` 表示账户剩余额度,`used_quota` 表示累计已用额度;
|
|
579
|
+
// 只有显式的 `total_quota` 才是总额度,不能把 quota 当成总额再减一次。
|
|
580
|
+
const rawRemaining = numberValue(candidate.remain_quota ?? candidate.remaining ?? candidate.remainQuota ?? candidate.quota);
|
|
581
|
+
const rawUsed = numberValue(candidate.used_quota ?? candidate.usedQuota);
|
|
582
|
+
const rawTotal = numberValue(candidate.total_quota ?? candidate.totalQuota);
|
|
583
|
+
if (rawRemaining === null && rawUsed === null && rawTotal === null)
|
|
584
|
+
return null;
|
|
585
|
+
const convert = (value) => {
|
|
586
|
+
if (value === null)
|
|
587
|
+
return null;
|
|
588
|
+
if (unit?.trim().toUpperCase() === 'USD' && quotaPerUnit !== null && quotaPerUnit > 1)
|
|
589
|
+
return value / quotaPerUnit;
|
|
590
|
+
return value;
|
|
591
|
+
};
|
|
592
|
+
const remaining = convert(rawRemaining ?? (rawTotal !== null && rawUsed !== null ? Math.max(0, rawTotal - rawUsed) : null));
|
|
593
|
+
const used = convert(rawUsed);
|
|
594
|
+
const total = convert(rawTotal ?? (rawUsed !== null && rawRemaining !== null ? rawUsed + rawRemaining : null));
|
|
595
|
+
const providerBalance = {
|
|
596
|
+
upstreamUrl: sanitizeUpstreamUrl(baseUrl),
|
|
597
|
+
currency: unit,
|
|
598
|
+
unit,
|
|
599
|
+
balance: remaining,
|
|
600
|
+
remaining,
|
|
601
|
+
used,
|
|
602
|
+
total,
|
|
603
|
+
requests: numberValue(candidate.request_count ?? candidate.requestCount),
|
|
604
|
+
inputTokens: null,
|
|
605
|
+
outputTokens: null,
|
|
606
|
+
planName: textValue(candidate.group ?? candidate.group_name ?? candidate.groupName),
|
|
607
|
+
expiresAt: unixSeconds(candidate.expires_at ?? candidate.expire_time ?? candidate.expireTime),
|
|
608
|
+
keyExpired: typeof candidate.status === 'string' ? /expired|disabled|inactive/iu.test(candidate.status) : null,
|
|
609
|
+
details: [
|
|
610
|
+
{ label: '余额/剩余额度', value: remaining ?? '上游未提供' },
|
|
611
|
+
{ label: unit === null ? '上游原始额度' : '累计用量', value: used ?? '上游未提供' },
|
|
612
|
+
{ label: '余额来源', value: 'One-API quota' },
|
|
613
|
+
],
|
|
614
|
+
};
|
|
615
|
+
return buildUsage(baseUrl, null, providerBalance, providerBalance.keyExpired === true ? 'expired' : null);
|
|
616
|
+
}
|
|
617
|
+
function readNewApiQuotaInfo(value) {
|
|
618
|
+
const root = recordValue(value);
|
|
619
|
+
const data = recordValue(root?.data) ?? root;
|
|
620
|
+
if (data === null)
|
|
621
|
+
return { unit: null, quotaPerUnit: null };
|
|
622
|
+
const type = textValue(data.quota_display_type ?? data.quotaDisplayType ?? data.display_type ?? data.displayType);
|
|
623
|
+
const perUnit = numberValue(data.quota_per_unit ?? data.quotaPerUnit);
|
|
624
|
+
return { unit: type === null ? null : type.toUpperCase(), quotaPerUnit: perUnit };
|
|
625
|
+
}
|
|
626
|
+
function mergeNewApiAccount(usage, account) {
|
|
627
|
+
if (account?.providerBalance === undefined)
|
|
628
|
+
return usage;
|
|
629
|
+
const current = usage.providerBalance;
|
|
630
|
+
if (current === undefined)
|
|
631
|
+
return account;
|
|
632
|
+
const source = account.providerBalance;
|
|
633
|
+
const hasValue = (value) => value !== null && Number.isFinite(value);
|
|
634
|
+
const details = mergeProviderDetails(current.details, source.details);
|
|
635
|
+
return {
|
|
636
|
+
...usage,
|
|
637
|
+
providerBalance: {
|
|
638
|
+
...current,
|
|
639
|
+
currency: current.currency ?? source.currency,
|
|
640
|
+
unit: current.unit ?? source.unit,
|
|
641
|
+
balance: hasValue(current.remaining) ? current.balance : source.balance,
|
|
642
|
+
remaining: hasValue(current.remaining) ? current.remaining : source.remaining,
|
|
643
|
+
used: hasValue(current.used) ? current.used : source.used,
|
|
644
|
+
total: hasValue(current.total) ? current.total : source.total,
|
|
645
|
+
requests: current.requests ?? source.requests,
|
|
646
|
+
planName: current.planName ?? source.planName,
|
|
647
|
+
expiresAt: current.expiresAt ?? source.expiresAt ?? null,
|
|
648
|
+
keyExpired: current.keyExpired ?? source.keyExpired ?? null,
|
|
649
|
+
details,
|
|
650
|
+
},
|
|
651
|
+
};
|
|
652
|
+
}
|
|
653
|
+
/**
|
|
654
|
+
* New-API billing 没有返回 QuotaDisplayType。已同时拿到 Token 原始配额时,
|
|
655
|
+
* 用站点固定的 QuotaPerUnit=500000 交叉验证 USD/TOKENS;CNY 或未知口径
|
|
656
|
+
* 不强行猜测,交给界面显示“上游单位未明确”。
|
|
657
|
+
*/
|
|
658
|
+
function inferNewApiBillingUnit(rawUsed, tokenRawUsed) {
|
|
659
|
+
if (rawUsed === null || tokenRawUsed === null)
|
|
660
|
+
return null;
|
|
661
|
+
const displayUsed = rawUsed / 100;
|
|
662
|
+
const close = (left, right) => {
|
|
663
|
+
const tolerance = Math.max(1e-6, Math.abs(right) * 1e-9);
|
|
664
|
+
return Math.abs(left - right) <= tolerance;
|
|
665
|
+
};
|
|
666
|
+
if (close(displayUsed, tokenRawUsed))
|
|
667
|
+
return 'TOKENS';
|
|
668
|
+
if (close(displayUsed, tokenRawUsed / 500000))
|
|
669
|
+
return 'USD';
|
|
670
|
+
return null;
|
|
671
|
+
}
|
|
672
|
+
function mergeNewApiUsage(token, billing) {
|
|
673
|
+
const current = token.providerBalance;
|
|
674
|
+
if (billing?.providerBalance === undefined) {
|
|
675
|
+
if (current === undefined || current.unit !== null)
|
|
676
|
+
return token;
|
|
677
|
+
// billing 因 Key 过期/耗尽不可读时,Token 接口仍可能返回内部配额整数。
|
|
678
|
+
// 该整数没有单位,保留在明细中追溯,不能放到顶部余额或已用金额。
|
|
679
|
+
return {
|
|
680
|
+
...token,
|
|
681
|
+
providerBalance: {
|
|
682
|
+
...current,
|
|
683
|
+
balance: null,
|
|
684
|
+
remaining: null,
|
|
685
|
+
used: null,
|
|
686
|
+
total: null,
|
|
687
|
+
},
|
|
688
|
+
};
|
|
689
|
+
}
|
|
690
|
+
if (current === undefined)
|
|
691
|
+
return billing;
|
|
692
|
+
const tokenBalance = current;
|
|
693
|
+
const billingBalance = billing.providerBalance;
|
|
694
|
+
const { expiresAt: _tokenExpiresAt, keyExpired: _tokenKeyExpired, ...tokenBalanceBase } = tokenBalance;
|
|
695
|
+
// token 接口的 total_used/total_available 是 New-API 内部配额单位;只要 Token
|
|
696
|
+
// 没有声明单位,就不能把它混入顶部金额,统一以 billing 的可确认字段为准。
|
|
697
|
+
const preferBillingFinancials = tokenBalance.unit === null;
|
|
698
|
+
const merged = {
|
|
699
|
+
...tokenBalanceBase,
|
|
700
|
+
balance: preferBillingFinancials
|
|
701
|
+
? billingBalance.remaining ?? tokenBalance.remaining
|
|
702
|
+
: tokenBalance.remaining ?? billingBalance.remaining,
|
|
703
|
+
remaining: preferBillingFinancials
|
|
704
|
+
? billingBalance.remaining ?? tokenBalance.remaining
|
|
705
|
+
: tokenBalance.remaining ?? billingBalance.remaining,
|
|
706
|
+
used: preferBillingFinancials
|
|
707
|
+
? billingBalance.used ?? tokenBalance.used
|
|
708
|
+
: tokenBalance.used ?? billingBalance.used,
|
|
709
|
+
total: preferBillingFinancials
|
|
710
|
+
? billingBalance.total ?? tokenBalance.total
|
|
711
|
+
: tokenBalance.total ?? billingBalance.total,
|
|
712
|
+
currency: tokenBalance.currency ?? billingBalance.currency,
|
|
713
|
+
unit: tokenBalance.unit ?? billingBalance.unit,
|
|
714
|
+
expiresAt: tokenBalance.expiresAt ?? billingBalance.expiresAt ?? null,
|
|
715
|
+
keyExpired: tokenBalance.keyExpired ?? billingBalance.keyExpired ?? null,
|
|
716
|
+
details: mergeProviderDetails(tokenBalance.details, billingBalance.details),
|
|
717
|
+
};
|
|
718
|
+
return { ...token, planType: token.planType ?? billing.planType, providerBalance: merged };
|
|
719
|
+
}
|
|
720
|
+
function mergeProviderDetails(primary, supplement) {
|
|
721
|
+
const merged = new Map(primary.map((item) => [item.label, item]));
|
|
722
|
+
for (const item of supplement) {
|
|
723
|
+
const previous = merged.get(item.label);
|
|
724
|
+
if (previous === undefined
|
|
725
|
+
|| previous.value === '上游未提供'
|
|
726
|
+
|| previous.value === '上游单位未明确') {
|
|
727
|
+
merged.set(item.label, item);
|
|
728
|
+
}
|
|
729
|
+
}
|
|
730
|
+
return [...merged.values()];
|
|
731
|
+
}
|
|
732
|
+
/** 解析 `/api/log/token`,只统计消费日志;空日志不解释为零用量。 */
|
|
733
|
+
export function summarizeNewApiLogs(value, nowMs = Date.now()) {
|
|
734
|
+
const root = recordValue(value);
|
|
735
|
+
if (root?.success === false)
|
|
736
|
+
return null;
|
|
737
|
+
const logs = Array.isArray(value)
|
|
738
|
+
? value
|
|
739
|
+
: root !== null && Array.isArray(root.data) ? root.data : null;
|
|
740
|
+
if (logs === null)
|
|
741
|
+
return null;
|
|
742
|
+
// “今日”按 Host 所在时区计算,避免用户在 UTC+8 的站点看到 UTC 日期偏移。
|
|
743
|
+
const today = calendarDate(nowMs);
|
|
744
|
+
let count = 0;
|
|
745
|
+
let totalTokens = 0;
|
|
746
|
+
let todayTokens = 0;
|
|
747
|
+
let promptTokensTotal = 0;
|
|
748
|
+
let cacheCreationTokens = 0;
|
|
749
|
+
let cacheReadTokens = 0;
|
|
750
|
+
let totalQuota = 0;
|
|
751
|
+
let todayQuota = 0;
|
|
752
|
+
let hasQuota = false;
|
|
753
|
+
let hasTodayQuota = false;
|
|
754
|
+
const models = new Map();
|
|
755
|
+
const daily = new Map();
|
|
756
|
+
const groups = new Set();
|
|
757
|
+
for (const item of logs) {
|
|
758
|
+
const log = recordValue(item);
|
|
759
|
+
if (log === null)
|
|
760
|
+
continue;
|
|
761
|
+
const type = numberValue(log.type);
|
|
762
|
+
// 官方 LogTypeConsume=2。兼容站点有时省略 type,此时仍按消费日志解析。
|
|
763
|
+
if (type !== null && type !== 2)
|
|
764
|
+
continue;
|
|
765
|
+
const createdAt = unixSeconds(log.created_at ?? log.createdAt);
|
|
766
|
+
if (createdAt === null)
|
|
767
|
+
continue;
|
|
768
|
+
const model = textValue(log.model_name ?? log.modelName) ?? '未标注模型';
|
|
769
|
+
const group = textValue(log.group);
|
|
770
|
+
if (group !== null)
|
|
771
|
+
groups.add(group);
|
|
772
|
+
const promptTokens = nonNegativeLogNumber(log.prompt_tokens ?? log.promptTokens);
|
|
773
|
+
const completionTokens = nonNegativeLogNumber(log.completion_tokens ?? log.completionTokens);
|
|
774
|
+
const other = parseLogOther(log.other);
|
|
775
|
+
const creation = nonNegativeLogNumber(other?.cache_creation_tokens ?? other?.cache_creation_input_tokens ?? other?.cacheCreationTokens);
|
|
776
|
+
const read = nonNegativeLogNumber(other?.cache_read_tokens ?? other?.cache_read ?? other?.cache_tokens ?? other?.cacheReadTokens);
|
|
777
|
+
const tokens = promptTokens + completionTokens + creation + read;
|
|
778
|
+
const quota = numberValue(log.quota);
|
|
779
|
+
const date = calendarDate(createdAt * 1000);
|
|
780
|
+
count += 1;
|
|
781
|
+
totalTokens += tokens;
|
|
782
|
+
promptTokensTotal += promptTokens;
|
|
783
|
+
cacheCreationTokens += creation;
|
|
784
|
+
cacheReadTokens += read;
|
|
785
|
+
if (quota !== null) {
|
|
786
|
+
totalQuota += quota;
|
|
787
|
+
hasQuota = true;
|
|
788
|
+
}
|
|
789
|
+
const modelStat = models.get(model) ?? { requests: 0, tokens: 0, quota: 0, hasQuota: false };
|
|
790
|
+
modelStat.requests += 1;
|
|
791
|
+
modelStat.tokens += tokens;
|
|
792
|
+
if (quota !== null) {
|
|
793
|
+
modelStat.quota += quota;
|
|
794
|
+
modelStat.hasQuota = true;
|
|
795
|
+
}
|
|
796
|
+
models.set(model, modelStat);
|
|
797
|
+
const dayStat = daily.get(date) ?? { requests: 0, tokens: 0, quota: 0, hasQuota: false };
|
|
798
|
+
dayStat.requests += 1;
|
|
799
|
+
dayStat.tokens += tokens;
|
|
800
|
+
if (quota !== null) {
|
|
801
|
+
dayStat.quota += quota;
|
|
802
|
+
dayStat.hasQuota = true;
|
|
803
|
+
}
|
|
804
|
+
daily.set(date, dayStat);
|
|
805
|
+
if (date === today) {
|
|
806
|
+
todayTokens += tokens;
|
|
807
|
+
if (quota !== null) {
|
|
808
|
+
todayQuota += quota;
|
|
809
|
+
hasTodayQuota = true;
|
|
810
|
+
}
|
|
811
|
+
}
|
|
812
|
+
}
|
|
813
|
+
if (count === 0)
|
|
814
|
+
return null;
|
|
815
|
+
const cacheDenominator = promptTokensTotal + cacheReadTokens;
|
|
816
|
+
const cacheHitRate = cacheDenominator === 0 ? null : Number((cacheReadTokens / cacheDenominator * 100).toFixed(4));
|
|
817
|
+
return {
|
|
818
|
+
count,
|
|
819
|
+
totalTokens,
|
|
820
|
+
todayTokens,
|
|
821
|
+
cacheCreationTokens,
|
|
822
|
+
cacheReadTokens,
|
|
823
|
+
cacheHitRate,
|
|
824
|
+
totalQuota: hasQuota ? totalQuota : null,
|
|
825
|
+
todayQuota: hasTodayQuota ? todayQuota : null,
|
|
826
|
+
models: [...models.entries()]
|
|
827
|
+
.sort((left, right) => right[1].tokens - left[1].tokens)
|
|
828
|
+
.map(([name, stat]) => ({ name, requests: stat.requests, tokens: stat.tokens, quota: stat.hasQuota ? stat.quota : null })),
|
|
829
|
+
daily: [...daily.entries()]
|
|
830
|
+
.sort((left, right) => right[0].localeCompare(left[0]))
|
|
831
|
+
.map(([date, stat]) => ({ date, requests: stat.requests, tokens: stat.tokens, quota: stat.hasQuota ? stat.quota : null })),
|
|
832
|
+
groups: [...groups].sort(),
|
|
833
|
+
};
|
|
834
|
+
}
|
|
835
|
+
/** 将最近日志统计附加到统一 ProviderBalanceUsage,保留 billing 的完整累计金额。 */
|
|
836
|
+
function enrichNewApiLogs(usage, summary) {
|
|
837
|
+
if (summary === null || usage.providerBalance === undefined)
|
|
838
|
+
return usage;
|
|
839
|
+
const details = new Map(usage.providerBalance.details.map((item) => [item.label, item]));
|
|
840
|
+
const add = (label, value) => { details.set(label, { label, value }); };
|
|
841
|
+
add('最近日志统计范围', `最近 ${summary.count} 条消费日志(最多 1000 条)`);
|
|
842
|
+
add('今日 Token(最近日志)', summary.todayTokens);
|
|
843
|
+
add('累计 Token(最近日志)', summary.totalTokens);
|
|
844
|
+
add('今日费用', details.get('今日费用')?.value ?? '上游未提供');
|
|
845
|
+
add('累计费用', details.get('累计费用')?.value ?? '上游未提供');
|
|
846
|
+
add('今日内部额度(最近日志)', summary.todayQuota ?? '上游未提供');
|
|
847
|
+
add('累计内部额度(最近日志)', summary.totalQuota ?? '上游未提供');
|
|
848
|
+
add('缓存创建 Token(最近日志)', summary.cacheCreationTokens);
|
|
849
|
+
add('缓存读取 Token(最近日志)', summary.cacheReadTokens);
|
|
850
|
+
add('缓存命中率(最近日志)', summary.cacheHitRate === null ? '上游未提供' : `${summary.cacheHitRate}%`);
|
|
851
|
+
add('分组(最近日志)', summary.groups.length === 0 ? '上游未提供' : summary.groups.join('、'));
|
|
852
|
+
add('按模型统计(最近日志)', formatNewApiLogModels(summary.models));
|
|
853
|
+
add('按日统计(最近日志)', formatNewApiLogDaily(summary.daily));
|
|
854
|
+
return { ...usage, providerBalance: { ...usage.providerBalance, details: [...details.values()] } };
|
|
855
|
+
}
|
|
856
|
+
function formatNewApiLogModels(models) {
|
|
857
|
+
return models.length === 0 ? '上游未提供' : models.map((item) => `${item.name}: ${item.tokens} Token / ${item.requests} 次`).join(';');
|
|
858
|
+
}
|
|
859
|
+
function formatNewApiModelLimits(value, enabled) {
|
|
860
|
+
const limits = recordValue(value);
|
|
861
|
+
if (limits === null || Object.keys(limits).length === 0)
|
|
862
|
+
return '上游未提供';
|
|
863
|
+
const prefix = enabled === true ? '已启用:' : '未启用:';
|
|
864
|
+
return prefix + Object.entries(limits).map(([model, allowed]) => `${model}: ${allowed === true ? '允许' : '限制'}`).join('、');
|
|
865
|
+
}
|
|
866
|
+
function formatNewApiLogDaily(daily) {
|
|
867
|
+
return daily.length === 0 ? '上游未提供' : daily.map((item) => `${item.date}: ${item.tokens} Token / ${item.requests} 次`).join(';');
|
|
868
|
+
}
|
|
869
|
+
function parseLogOther(value) {
|
|
870
|
+
if (typeof value === 'string') {
|
|
871
|
+
try {
|
|
872
|
+
return recordValue(JSON.parse(value));
|
|
873
|
+
}
|
|
874
|
+
catch {
|
|
875
|
+
return null;
|
|
876
|
+
}
|
|
877
|
+
}
|
|
878
|
+
return recordValue(value);
|
|
879
|
+
}
|
|
880
|
+
function nonNegativeLogNumber(value) {
|
|
881
|
+
const parsed = numberValue(value);
|
|
882
|
+
return parsed === null ? 0 : Math.max(0, parsed);
|
|
883
|
+
}
|
|
884
|
+
function calendarDate(timestampMs) {
|
|
885
|
+
const date = new Date(timestampMs);
|
|
886
|
+
const pad = (value) => String(value).padStart(2, '0');
|
|
887
|
+
return `${date.getFullYear()}-${pad(date.getMonth() + 1)}-${pad(date.getDate())}`;
|
|
888
|
+
}
|
|
889
|
+
function buildUsage(baseUrl, primary, providerBalance, rateLimitReachedType) {
|
|
890
|
+
const sanitizedBaseUrl = sanitizeUpstreamUrl(baseUrl);
|
|
891
|
+
const provider = {
|
|
892
|
+
id: 'new-api',
|
|
893
|
+
displayName: 'New-API',
|
|
894
|
+
baseUrl: sanitizedBaseUrl,
|
|
895
|
+
capability: 'new-api',
|
|
896
|
+
// New-API 没有统一的第三方品牌 CDN;站点自身会在根路径提供 logo.png。
|
|
897
|
+
// 这里保留清洗后的上游地址,避免把 query、fragment 或凭据拼进图片地址。
|
|
898
|
+
logoUrl: buildNewApiLogoUrl(sanitizedBaseUrl),
|
|
899
|
+
};
|
|
900
|
+
return {
|
|
901
|
+
authenticated: true,
|
|
902
|
+
planType: null,
|
|
903
|
+
primary,
|
|
904
|
+
secondary: null,
|
|
905
|
+
monthly: null,
|
|
906
|
+
rateLimitReachedType,
|
|
907
|
+
resetCredits: null,
|
|
908
|
+
capturedAt: new Date().toISOString(),
|
|
909
|
+
provider,
|
|
910
|
+
providerBalance,
|
|
911
|
+
};
|
|
912
|
+
}
|
|
913
|
+
/** New-API 站点 Logo 的固定约定:上游根地址下的 /logo.png。 */
|
|
914
|
+
function buildNewApiLogoUrl(baseUrl) {
|
|
915
|
+
if (baseUrl === '')
|
|
916
|
+
return '';
|
|
917
|
+
try {
|
|
918
|
+
return new URL('/logo.png', baseUrl).toString();
|
|
919
|
+
}
|
|
920
|
+
catch {
|
|
921
|
+
return '';
|
|
922
|
+
}
|
|
923
|
+
}
|
|
924
|
+
function recordValue(value) {
|
|
925
|
+
return value !== null && typeof value === 'object' && !Array.isArray(value) ? value : null;
|
|
926
|
+
}
|
|
927
|
+
function textValue(value) {
|
|
928
|
+
return typeof value === 'string' && value.trim() !== '' ? value.trim() : null;
|
|
929
|
+
}
|
|
930
|
+
function numberValue(value) {
|
|
931
|
+
if (typeof value === 'number' && Number.isFinite(value))
|
|
932
|
+
return value;
|
|
933
|
+
if (typeof value === 'string' && value.trim() !== '') {
|
|
934
|
+
const parsed = Number(value);
|
|
935
|
+
return Number.isFinite(parsed) ? parsed : null;
|
|
936
|
+
}
|
|
937
|
+
return null;
|
|
938
|
+
}
|
|
939
|
+
function unixSeconds(value) {
|
|
940
|
+
const parsed = numberValue(value);
|
|
941
|
+
return parsed === null || parsed <= 0 ? null : Math.floor(parsed);
|
|
942
|
+
}
|
|
943
|
+
function stripVersionSuffix(value) {
|
|
944
|
+
return value.replace(/\/v1$/u, '');
|
|
945
|
+
}
|
|
946
|
+
function sanitizeUpstreamUrl(value) {
|
|
947
|
+
try {
|
|
948
|
+
const url = new URL(value.trim());
|
|
949
|
+
url.username = '';
|
|
950
|
+
url.password = '';
|
|
951
|
+
url.search = '';
|
|
952
|
+
url.hash = '';
|
|
953
|
+
return url.toString().replace(/\/$/u, '');
|
|
954
|
+
}
|
|
955
|
+
catch {
|
|
956
|
+
return '';
|
|
957
|
+
}
|
|
958
|
+
}
|
|
959
|
+
//# sourceMappingURL=new-api-subscription.js.map
|