dsh-cliworker-now 0.0.0-stage → 0.7.6
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/LICENSE +21 -0
- package/README.en.md +344 -0
- package/README.md +346 -2
- package/cordis.patch.yml +3 -0
- package/lib/account-models.mjs +259 -0
- package/lib/client.js +21542 -0
- package/lib/client.js.map +1 -0
- package/lib/grok-catalog.mjs +145 -0
- package/lib/hermes-native-entry.py +61 -0
- package/lib/index.js +12409 -0
- package/lib/index.js.map +1 -0
- package/lib/native-launch.mjs +179 -0
- package/lib/own-account-lease.mjs +105 -0
- package/lib/pi-installation.mjs +63 -0
- package/lib/pi-login.mjs +80 -0
- package/lib/pi-native-catalog.mjs +417 -0
- package/lib/pi-omp-bridge.mjs +602 -0
- package/lib/pi-omp-environment.mjs +15 -0
- package/lib/pi-omp-refresh.mjs +324 -0
- package/lib/private-launch.mjs +19 -0
- package/lib/terminal-bridge.mjs +18 -0
- package/lib/typert.host.d.ts +3 -0
- package/lib/typert.host.js +1358 -0
- package/lib/typert.remote-client.d.ts +70 -0
- package/lib/typert.remote-client.d.ts.map +1 -0
- package/lib/typert.remote-client.js +1190 -0
- package/lib/types/client/account-terminal-css.d.ts +1 -0
- package/lib/types/client/account-terminal-css.js +3 -0
- package/lib/types/client/account-terminal-css.js.map +1 -0
- package/lib/types/client/account-terminal.d.ts +13 -0
- package/lib/types/client/account-terminal.js +296 -0
- package/lib/types/client/account-terminal.js.map +1 -0
- package/lib/types/client/assets/antigravity.png +0 -0
- package/lib/types/client/assets/claude-code.png +0 -0
- package/lib/types/client/assets/cliworker-now-logo.png +0 -0
- package/lib/types/client/assets/codex.png +0 -0
- package/lib/types/client/assets/grok.png +0 -0
- package/lib/types/client/assets/hermes.png +0 -0
- package/lib/types/client/assets/kimi-dark.png +0 -0
- package/lib/types/client/assets/kimi-light.png +0 -0
- package/lib/types/client/assets/mimo-code.png +0 -0
- package/lib/types/client/assets/omp.png +0 -0
- package/lib/types/client/assets/opencode.png +0 -0
- package/lib/types/client/assets/pi.png +0 -0
- package/lib/types/client/assets/zcode.png +0 -0
- package/lib/types/client/composer-keymap.d.ts +18 -0
- package/lib/types/client/composer-keymap.js +49 -0
- package/lib/types/client/composer-keymap.js.map +1 -0
- package/lib/types/client/conversation-timeline.d.ts +6 -0
- package/lib/types/client/conversation-timeline.js +65 -0
- package/lib/types/client/conversation-timeline.js.map +1 -0
- package/lib/types/client/copy-text.d.ts +5 -0
- package/lib/types/client/copy-text.js +45 -0
- package/lib/types/client/copy-text.js.map +1 -0
- package/lib/types/client/icons.d.ts +21 -0
- package/lib/types/client/icons.js +68 -0
- package/lib/types/client/icons.js.map +1 -0
- package/lib/types/client/index.d.ts +3 -0
- package/lib/types/client/index.js +124 -0
- package/lib/types/client/index.js.map +1 -0
- package/lib/types/client/management-styles.d.ts +1 -0
- package/lib/types/client/management-styles.js +17 -0
- package/lib/types/client/management-styles.js.map +1 -0
- package/lib/types/client/name-copy.d.ts +5 -0
- package/lib/types/client/name-copy.js +107 -0
- package/lib/types/client/name-copy.js.map +1 -0
- package/lib/types/client/native-job-overlay.d.ts +11 -0
- package/lib/types/client/native-job-overlay.js +129 -0
- package/lib/types/client/native-job-overlay.js.map +1 -0
- package/lib/types/client/operation-error.d.ts +2 -0
- package/lib/types/client/operation-error.js +12 -0
- package/lib/types/client/operation-error.js.map +1 -0
- package/lib/types/client/panel.d.ts +8 -0
- package/lib/types/client/panel.js +310 -0
- package/lib/types/client/panel.js.map +1 -0
- package/lib/types/client/rename-copy-styles.d.ts +1 -0
- package/lib/types/client/rename-copy-styles.js +21 -0
- package/lib/types/client/rename-copy-styles.js.map +1 -0
- package/lib/types/client/rename-worker.d.ts +9 -0
- package/lib/types/client/rename-worker.js +53 -0
- package/lib/types/client/rename-worker.js.map +1 -0
- package/lib/types/client/role-presets.d.ts +6 -0
- package/lib/types/client/role-presets.js +111 -0
- package/lib/types/client/role-presets.js.map +1 -0
- package/lib/types/client/settings-dialog.d.ts +13 -0
- package/lib/types/client/settings-dialog.js +415 -0
- package/lib/types/client/settings-dialog.js.map +1 -0
- package/lib/types/client/stat-popover.d.ts +10 -0
- package/lib/types/client/stat-popover.js +32 -0
- package/lib/types/client/stat-popover.js.map +1 -0
- package/lib/types/client/styles.d.ts +9 -0
- package/lib/types/client/styles.js +221 -0
- package/lib/types/client/styles.js.map +1 -0
- package/lib/types/client/telemetry.d.ts +11 -0
- package/lib/types/client/telemetry.js +24 -0
- package/lib/types/client/telemetry.js.map +1 -0
- package/lib/types/client/worker-card.d.ts +10 -0
- package/lib/types/client/worker-card.js +75 -0
- package/lib/types/client/worker-card.js.map +1 -0
- package/lib/types/client/worker-model-menu.d.ts +9 -0
- package/lib/types/client/worker-model-menu.js +136 -0
- package/lib/types/client/worker-model-menu.js.map +1 -0
- package/lib/types/client/workers.d.ts +21 -0
- package/lib/types/client/workers.js +59 -0
- package/lib/types/client/workers.js.map +1 -0
- package/lib/types/host/account-identity.d.ts +16 -0
- package/lib/types/host/account-identity.js +126 -0
- package/lib/types/host/account-identity.js.map +1 -0
- package/lib/types/host/account-login.d.ts +10 -0
- package/lib/types/host/account-login.js +126 -0
- package/lib/types/host/account-login.js.map +1 -0
- package/lib/types/host/account-models.d.mts +19 -0
- package/lib/types/host/account-models.mjs +259 -0
- package/lib/types/host/accounts.d.ts +41 -0
- package/lib/types/host/accounts.js +838 -0
- package/lib/types/host/accounts.js.map +1 -0
- package/lib/types/host/adapters.d.ts +24 -0
- package/lib/types/host/adapters.js +331 -0
- package/lib/types/host/adapters.js.map +1 -0
- package/lib/types/host/agy-context.d.ts +8 -0
- package/lib/types/host/agy-context.js +122 -0
- package/lib/types/host/agy-context.js.map +1 -0
- package/lib/types/host/agy-models.d.ts +4 -0
- package/lib/types/host/agy-models.js +37 -0
- package/lib/types/host/agy-models.js.map +1 -0
- package/lib/types/host/authorized-catalog.d.ts +14 -0
- package/lib/types/host/authorized-catalog.js +26 -0
- package/lib/types/host/authorized-catalog.js.map +1 -0
- package/lib/types/host/bridge-protocol.d.ts +15 -0
- package/lib/types/host/bridge-protocol.js +80 -0
- package/lib/types/host/bridge-protocol.js.map +1 -0
- package/lib/types/host/cli-account-binding.d.ts +32 -0
- package/lib/types/host/cli-account-binding.js +502 -0
- package/lib/types/host/cli-account-binding.js.map +1 -0
- package/lib/types/host/cli-protocol.d.ts +27 -0
- package/lib/types/host/cli-protocol.js +212 -0
- package/lib/types/host/cli-protocol.js.map +1 -0
- package/lib/types/host/codex-account.d.ts +8 -0
- package/lib/types/host/codex-account.js +143 -0
- package/lib/types/host/codex-account.js.map +1 -0
- package/lib/types/host/codex-models.d.ts +6 -0
- package/lib/types/host/codex-models.js +165 -0
- package/lib/types/host/codex-models.js.map +1 -0
- package/lib/types/host/extended-adapters.d.ts +43 -0
- package/lib/types/host/extended-adapters.js +205 -0
- package/lib/types/host/extended-adapters.js.map +1 -0
- package/lib/types/host/first-party-account-context.d.ts +26 -0
- package/lib/types/host/first-party-account-context.js +55 -0
- package/lib/types/host/first-party-account-context.js.map +1 -0
- package/lib/types/host/first-party-models.d.ts +28 -0
- package/lib/types/host/first-party-models.js +370 -0
- package/lib/types/host/first-party-models.js.map +1 -0
- package/lib/types/host/grok-adapter.d.ts +44 -0
- package/lib/types/host/grok-adapter.js +293 -0
- package/lib/types/host/grok-adapter.js.map +1 -0
- package/lib/types/host/grok-models.d.ts +47 -0
- package/lib/types/host/grok-models.js +320 -0
- package/lib/types/host/grok-models.js.map +1 -0
- package/lib/types/host/harness-opencode-accounts.d.ts +17 -0
- package/lib/types/host/harness-opencode-accounts.js +80 -0
- package/lib/types/host/harness-opencode-accounts.js.map +1 -0
- package/lib/types/host/hermes-account-context.d.ts +8 -0
- package/lib/types/host/hermes-account-context.js +99 -0
- package/lib/types/host/hermes-account-context.js.map +1 -0
- package/lib/types/host/hermes-accounts.d.ts +19 -0
- package/lib/types/host/hermes-accounts.js +342 -0
- package/lib/types/host/hermes-accounts.js.map +1 -0
- package/lib/types/host/hermes-adapter.d.ts +90 -0
- package/lib/types/host/hermes-adapter.js +446 -0
- package/lib/types/host/hermes-adapter.js.map +1 -0
- package/lib/types/host/hermes-env.d.ts +4 -0
- package/lib/types/host/hermes-env.js +22 -0
- package/lib/types/host/hermes-env.js.map +1 -0
- package/lib/types/host/hermes-installation.d.ts +10 -0
- package/lib/types/host/hermes-installation.js +162 -0
- package/lib/types/host/hermes-installation.js.map +1 -0
- package/lib/types/host/hermes-models.d.ts +26 -0
- package/lib/types/host/hermes-models.js +328 -0
- package/lib/types/host/hermes-models.js.map +1 -0
- package/lib/types/host/hermes-native-entry.py +61 -0
- package/lib/types/host/hermes-nous.d.ts +49 -0
- package/lib/types/host/hermes-nous.js +343 -0
- package/lib/types/host/hermes-nous.js.map +1 -0
- package/lib/types/host/hermes-suppression.d.ts +7 -0
- package/lib/types/host/hermes-suppression.js +69 -0
- package/lib/types/host/hermes-suppression.js.map +1 -0
- package/lib/types/host/index.d.ts +138 -0
- package/lib/types/host/index.js +932 -0
- package/lib/types/host/index.js.map +1 -0
- package/lib/types/host/kimi-accounts.d.ts +15 -0
- package/lib/types/host/kimi-accounts.js +218 -0
- package/lib/types/host/kimi-accounts.js.map +1 -0
- package/lib/types/host/managed-agent.d.ts +4 -0
- package/lib/types/host/managed-agent.js +127 -0
- package/lib/types/host/managed-agent.js.map +1 -0
- package/lib/types/host/mimo-configuration.d.ts +22 -0
- package/lib/types/host/mimo-configuration.js +258 -0
- package/lib/types/host/mimo-configuration.js.map +1 -0
- package/lib/types/host/native-launch.d.mts +2 -0
- package/lib/types/host/native-launch.mjs +179 -0
- package/lib/types/host/native-process.d.ts +3 -0
- package/lib/types/host/native-process.js +26 -0
- package/lib/types/host/native-process.js.map +1 -0
- package/lib/types/host/opencode-adapter.d.ts +94 -0
- package/lib/types/host/opencode-adapter.js +507 -0
- package/lib/types/host/opencode-adapter.js.map +1 -0
- package/lib/types/host/opencode-native.d.ts +27 -0
- package/lib/types/host/opencode-native.js +403 -0
- package/lib/types/host/opencode-native.js.map +1 -0
- package/lib/types/host/own-account-lease.d.mts +5 -0
- package/lib/types/host/own-account-lease.mjs +105 -0
- package/lib/types/host/pi-installation.d.mts +7 -0
- package/lib/types/host/pi-installation.mjs +63 -0
- package/lib/types/host/pi-omp-accounts.d.ts +28 -0
- package/lib/types/host/pi-omp-accounts.js +175 -0
- package/lib/types/host/pi-omp-accounts.js.map +1 -0
- package/lib/types/host/pi-omp-adapter.d.ts +32 -0
- package/lib/types/host/pi-omp-adapter.js +176 -0
- package/lib/types/host/pi-omp-adapter.js.map +1 -0
- package/lib/types/host/pi-omp-environment.d.mts +1 -0
- package/lib/types/host/pi-omp-environment.mjs +15 -0
- package/lib/types/host/pi-omp-identity.d.ts +2 -0
- package/lib/types/host/pi-omp-identity.js +142 -0
- package/lib/types/host/pi-omp-identity.js.map +1 -0
- package/lib/types/host/pi-omp-logout.d.ts +3 -0
- package/lib/types/host/pi-omp-logout.js +152 -0
- package/lib/types/host/pi-omp-logout.js.map +1 -0
- package/lib/types/host/pi-omp-native.d.ts +71 -0
- package/lib/types/host/pi-omp-native.js +753 -0
- package/lib/types/host/pi-omp-native.js.map +1 -0
- package/lib/types/host/pi-omp-refresh.d.mts +7 -0
- package/lib/types/host/pi-omp-refresh.mjs +324 -0
- package/lib/types/host/process.d.ts +43 -0
- package/lib/types/host/process.js +134 -0
- package/lib/types/host/process.js.map +1 -0
- package/lib/types/host/protocol.d.ts +23 -0
- package/lib/types/host/protocol.js +112 -0
- package/lib/types/host/protocol.js.map +1 -0
- package/lib/types/host/roles.d.ts +34 -0
- package/lib/types/host/roles.js +80 -0
- package/lib/types/host/roles.js.map +1 -0
- package/lib/types/host/routing.d.ts +31 -0
- package/lib/types/host/routing.js +225 -0
- package/lib/types/host/routing.js.map +1 -0
- package/lib/types/host/runtime.d.ts +60 -0
- package/lib/types/host/runtime.js +586 -0
- package/lib/types/host/runtime.js.map +1 -0
- package/lib/types/host/storage.d.ts +48 -0
- package/lib/types/host/storage.js +449 -0
- package/lib/types/host/storage.js.map +1 -0
- package/lib/types/host/telemetry.d.ts +17 -0
- package/lib/types/host/telemetry.js +158 -0
- package/lib/types/host/telemetry.js.map +1 -0
- package/lib/types/host/zcode-account-models.d.ts +16 -0
- package/lib/types/host/zcode-account-models.js +114 -0
- package/lib/types/host/zcode-account-models.js.map +1 -0
- package/lib/types/host/zcode-adapter.d.ts +93 -0
- package/lib/types/host/zcode-adapter.js +804 -0
- package/lib/types/host/zcode-adapter.js.map +1 -0
- package/lib/types/host/zcode-grok-accounts.d.ts +28 -0
- package/lib/types/host/zcode-grok-accounts.js +359 -0
- package/lib/types/host/zcode-grok-accounts.js.map +1 -0
- package/lib/types/shared/accounts.d.ts +43 -0
- package/lib/types/shared/accounts.js +2 -0
- package/lib/types/shared/accounts.js.map +1 -0
- package/lib/types/shared/builtin-presets.d.ts +2 -0
- package/lib/types/shared/builtin-presets.js +231 -0
- package/lib/types/shared/builtin-presets.js.map +1 -0
- package/lib/types/shared/cli-settings.d.ts +5 -0
- package/lib/types/shared/cli-settings.js +2 -0
- package/lib/types/shared/cli-settings.js.map +1 -0
- package/lib/types/shared/model-presentation.d.ts +10 -0
- package/lib/types/shared/model-presentation.js +95 -0
- package/lib/types/shared/model-presentation.js.map +1 -0
- package/lib/types/shared/models.d.ts +7 -0
- package/lib/types/shared/models.js +35 -0
- package/lib/types/shared/models.js.map +1 -0
- package/lib/types/shared/telemetry.d.ts +18 -0
- package/lib/types/shared/telemetry.js +16 -0
- package/lib/types/shared/telemetry.js.map +1 -0
- package/lib/types/shared/types.d.ts +127 -0
- package/lib/types/shared/types.js +147 -0
- package/lib/types/shared/types.js.map +1 -0
- package/lib/zcode-resume.mjs +423 -0
- package/package.json +109 -4
|
@@ -0,0 +1,259 @@
|
|
|
1
|
+
// Read-only account metadata. Never refresh OAuth, submit prompts, or return
|
|
2
|
+
// credentials, account IDs, headers, endpoint URLs, or raw exception messages.
|
|
3
|
+
const unknown = () => ({ state: 'unknown', source: 'unknown', models: [] })
|
|
4
|
+
const denied = () => ({ state: 'denied', source: 'unknown', models: [] })
|
|
5
|
+
const validId = (id) => typeof id === 'string' && !!id && id.length <= 1024 && !/[\s\x00-\x1f]/.test(id)
|
|
6
|
+
const object = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
7
|
+
const unavailable = (model) =>
|
|
8
|
+
model.supported_in_api === false ||
|
|
9
|
+
model.allowed === false ||
|
|
10
|
+
model.available === false ||
|
|
11
|
+
model.entitled === false ||
|
|
12
|
+
model.enabled === false ||
|
|
13
|
+
model.disabled === true ||
|
|
14
|
+
model.upgrade_required === true ||
|
|
15
|
+
model.visibility === 'hidden' ||
|
|
16
|
+
model.visibility === 'none'
|
|
17
|
+
const numericRate = (value) =>
|
|
18
|
+
typeof value === 'number'
|
|
19
|
+
? value
|
|
20
|
+
: typeof value === 'string' &&
|
|
21
|
+
value.trim() &&
|
|
22
|
+
/^(?:\d+(?:\.\d*)?|\.\d+)(?:[eE][+-]?\d+)?$/.test(value.trim())
|
|
23
|
+
? Number(value)
|
|
24
|
+
: NaN
|
|
25
|
+
const costFor = (model, oauth) => {
|
|
26
|
+
if (oauth) return 'unknown'
|
|
27
|
+
const rates = model.pricing
|
|
28
|
+
if (object(rates)) {
|
|
29
|
+
const input = numericRate(Object.hasOwn(rates, 'input') ? rates.input : rates.prompt),
|
|
30
|
+
output = numericRate(Object.hasOwn(rates, 'output') ? rates.output : rates.completion)
|
|
31
|
+
if (Number.isFinite(input) && Number.isFinite(output) && input >= 0 && output >= 0) {
|
|
32
|
+
const additional = Object.entries(rates)
|
|
33
|
+
.filter(([key]) => !['input', 'output', 'prompt', 'completion', 'free'].includes(key))
|
|
34
|
+
.map(([, value]) => numericRate(value))
|
|
35
|
+
if (input > 0 || output > 0 || additional.some((value) => value > 0)) return 'paid'
|
|
36
|
+
if (additional.some((value) => !Number.isFinite(value) || value < 0)) return 'unknown'
|
|
37
|
+
return 'free'
|
|
38
|
+
}
|
|
39
|
+
// Explicit invalid rates cannot be overridden by a contradictory free flag.
|
|
40
|
+
if ('input' in rates || 'prompt' in rates || 'output' in rates || 'completion' in rates) return 'unknown'
|
|
41
|
+
}
|
|
42
|
+
return model.free === true || model.is_free === true || model.pricing?.free === true ? 'free' : 'unknown'
|
|
43
|
+
}
|
|
44
|
+
function entries(payload) {
|
|
45
|
+
if (Array.isArray(payload)) return payload
|
|
46
|
+
if (!object(payload)) return undefined
|
|
47
|
+
return Array.isArray(payload.models)
|
|
48
|
+
? payload.models
|
|
49
|
+
: Array.isArray(payload.data)
|
|
50
|
+
? payload.data
|
|
51
|
+
: undefined
|
|
52
|
+
}
|
|
53
|
+
function normalize(payload, oauth, token) {
|
|
54
|
+
const list = entries(payload)
|
|
55
|
+
if (!list) return undefined
|
|
56
|
+
const result = new Map()
|
|
57
|
+
for (const model of list) {
|
|
58
|
+
if (!object(model) || unavailable(model)) continue
|
|
59
|
+
const id = model.slug ?? model.id
|
|
60
|
+
if (
|
|
61
|
+
!validId(id) ||
|
|
62
|
+
id === token ||
|
|
63
|
+
(token.length >= 12 && id.includes(token)) ||
|
|
64
|
+
(oauth && model.supported_in_api !== true)
|
|
65
|
+
)
|
|
66
|
+
continue
|
|
67
|
+
const name = model.display_name ?? model.name
|
|
68
|
+
result.set(id, {
|
|
69
|
+
id,
|
|
70
|
+
...(typeof name === 'string' &&
|
|
71
|
+
name.trim() &&
|
|
72
|
+
name.length <= 4096 &&
|
|
73
|
+
name !== token &&
|
|
74
|
+
!(token.length >= 12 && name.includes(token))
|
|
75
|
+
? { name }
|
|
76
|
+
: {}),
|
|
77
|
+
cost: costFor(model, oauth),
|
|
78
|
+
})
|
|
79
|
+
}
|
|
80
|
+
return [...result.values()]
|
|
81
|
+
}
|
|
82
|
+
function metadataBase(input, codex) {
|
|
83
|
+
const url = new URL(codex ? 'https://chatgpt.com/backend-api' : input.baseUrl)
|
|
84
|
+
if (!['https:', 'http:'].includes(url.protocol) || url.username || url.password || url.search || url.hash)
|
|
85
|
+
throw new Error('Unsafe metadata endpoint')
|
|
86
|
+
const base = url.toString().replace(/\/+$/, '')
|
|
87
|
+
return input.apiType === 'anthropic-messages' && !/\/v1$/.test(url.pathname.replace(/\/+$/, ''))
|
|
88
|
+
? `${base}/v1`
|
|
89
|
+
: base
|
|
90
|
+
}
|
|
91
|
+
async function readResponse(response) {
|
|
92
|
+
if (!response.body) return undefined
|
|
93
|
+
const reader = response.body.getReader()
|
|
94
|
+
let length = 0
|
|
95
|
+
const chunks = []
|
|
96
|
+
try {
|
|
97
|
+
while (true) {
|
|
98
|
+
const { done, value } = await reader.read()
|
|
99
|
+
if (done) break
|
|
100
|
+
length += value.length
|
|
101
|
+
if (length > 2 * 1024 * 1024) {
|
|
102
|
+
await reader.cancel()
|
|
103
|
+
return undefined
|
|
104
|
+
}
|
|
105
|
+
chunks.push(value)
|
|
106
|
+
}
|
|
107
|
+
const bytes = new Uint8Array(length)
|
|
108
|
+
let offset = 0
|
|
109
|
+
for (const chunk of chunks) {
|
|
110
|
+
bytes.set(chunk, offset)
|
|
111
|
+
offset += chunk.length
|
|
112
|
+
}
|
|
113
|
+
return JSON.parse(new TextDecoder('utf-8', { fatal: true }).decode(bytes))
|
|
114
|
+
} finally {
|
|
115
|
+
reader.releaseLock()
|
|
116
|
+
}
|
|
117
|
+
}
|
|
118
|
+
/** Exact current-account model scope, or a narrowly declared API fallback. */
|
|
119
|
+
export async function probeAccountModels(input, options = {}) {
|
|
120
|
+
const credential = input.credential
|
|
121
|
+
if (!credential || !['api', 'oauth'].includes(credential.type)) return unknown()
|
|
122
|
+
const oauth = credential.type === 'oauth'
|
|
123
|
+
const token = oauth ? credential.access : credential.key
|
|
124
|
+
if (typeof token !== 'string' || !token.trim() || token.trimStart().startsWith('!')) return unknown()
|
|
125
|
+
// Near-expiry credentials cannot reliably finish the query. Do not renew them.
|
|
126
|
+
if (oauth && (typeof credential.expires !== 'number' || credential.expires <= Date.now() + 30000))
|
|
127
|
+
return denied()
|
|
128
|
+
const codex = oauth && ['openai', 'openai-codex'].includes(input.provider)
|
|
129
|
+
// xAI/other subscription catalogs do not expose a verified per-account scope
|
|
130
|
+
// contract here. Do not turn an OAuth login into their whole public catalog.
|
|
131
|
+
if (oauth && !codex) return unknown()
|
|
132
|
+
const parent = options.signal
|
|
133
|
+
if (parent?.aborted) return unknown()
|
|
134
|
+
const controller = new AbortController()
|
|
135
|
+
const signal = parent ? AbortSignal.any([parent, controller.signal]) : controller.signal
|
|
136
|
+
const timer = setTimeout(() => controller.abort(), Math.max(50, Math.min(options.timeoutMs ?? 8000, 10000)))
|
|
137
|
+
try {
|
|
138
|
+
if (codex && input.baseUrl && input.baseUrl.replace(/\/+$/, '') !== 'https://chatgpt.com/backend-api')
|
|
139
|
+
return unknown()
|
|
140
|
+
const base = metadataBase(input, codex)
|
|
141
|
+
const headers = { accept: 'application/json', Authorization: `Bearer ${token}` }
|
|
142
|
+
if (input.apiType === 'anthropic-messages' && !oauth) {
|
|
143
|
+
// ZCode's native Anthropic factory sends both headers. Other callers keep
|
|
144
|
+
// the ordinary x-api-key contract unless they explicitly mirror that route.
|
|
145
|
+
if (input.anthropicAuth !== 'api-key-and-bearer') delete headers.Authorization
|
|
146
|
+
headers['x-api-key'] = token
|
|
147
|
+
headers['anthropic-version'] = '2023-06-01'
|
|
148
|
+
}
|
|
149
|
+
if (codex) {
|
|
150
|
+
let accountId = credential.accountId
|
|
151
|
+
if (!accountId) {
|
|
152
|
+
try {
|
|
153
|
+
accountId = JSON.parse(Buffer.from(token.split('.')[1] ?? '', 'base64url').toString('utf8'))?.[
|
|
154
|
+
'https://api.openai.com/auth'
|
|
155
|
+
]?.chatgpt_account_id
|
|
156
|
+
} catch {}
|
|
157
|
+
}
|
|
158
|
+
if (typeof accountId === 'string' && accountId) headers['chatgpt-account-id'] = accountId
|
|
159
|
+
headers['OpenAI-Beta'] = 'responses=experimental'
|
|
160
|
+
headers.originator = 'pi'
|
|
161
|
+
headers.version = '0.144.1'
|
|
162
|
+
}
|
|
163
|
+
const fetcher = options.fetch ?? globalThis.fetch
|
|
164
|
+
const request = async (path) => {
|
|
165
|
+
const target = `${base}${path}${codex && path !== '/wham/usage' ? '?client_version=0.144.1' : ''}`
|
|
166
|
+
const response = await fetcher(target, { method: 'GET', headers, signal, redirect: 'error' })
|
|
167
|
+
if (!response.ok) {
|
|
168
|
+
await response.body?.cancel()
|
|
169
|
+
return { status: response.status, payload: undefined }
|
|
170
|
+
}
|
|
171
|
+
return { status: response.status, payload: await readResponse(response) }
|
|
172
|
+
}
|
|
173
|
+
let modelResponse
|
|
174
|
+
for (const path of codex
|
|
175
|
+
? ['/codex/models', '/models']
|
|
176
|
+
: [
|
|
177
|
+
input.provider === 'openrouter' || new URL(base).hostname === 'openrouter.ai'
|
|
178
|
+
? '/models/user'
|
|
179
|
+
: '/models',
|
|
180
|
+
]) {
|
|
181
|
+
modelResponse = await request(path)
|
|
182
|
+
if (modelResponse.status === 401 || modelResponse.status === 403) return denied()
|
|
183
|
+
if (modelResponse.status >= 200 && modelResponse.status < 300) break
|
|
184
|
+
if (![404, 405].includes(modelResponse.status)) return unknown()
|
|
185
|
+
}
|
|
186
|
+
if (modelResponse?.status >= 200 && modelResponse.status < 300) {
|
|
187
|
+
const envelope = modelResponse.payload
|
|
188
|
+
if (envelope?.allowed === false || envelope?.authenticated === false) return denied()
|
|
189
|
+
if (envelope?.success === false || envelope?.error) {
|
|
190
|
+
const code = envelope?.error?.code
|
|
191
|
+
return ['invalid_api_key', 'authentication_failed', 'unauthorized', 'forbidden', 401, 403].includes(
|
|
192
|
+
code,
|
|
193
|
+
)
|
|
194
|
+
? denied()
|
|
195
|
+
: unknown()
|
|
196
|
+
}
|
|
197
|
+
const models = normalize(envelope, oauth, token)
|
|
198
|
+
if (models === undefined) return unknown()
|
|
199
|
+
if (codex) {
|
|
200
|
+
const usage = await request('/wham/usage')
|
|
201
|
+
const rate = usage.payload?.rate_limit
|
|
202
|
+
if (
|
|
203
|
+
usage.status === 401 ||
|
|
204
|
+
usage.status === 403 ||
|
|
205
|
+
rate?.allowed === false ||
|
|
206
|
+
rate?.limit_reached === true
|
|
207
|
+
)
|
|
208
|
+
return denied()
|
|
209
|
+
// A catalog/menu is not evidence that the account has an executable quota.
|
|
210
|
+
if (usage.status !== 200 || rate?.allowed !== true || rate?.limit_reached !== false) return unknown()
|
|
211
|
+
const plan =
|
|
212
|
+
typeof usage.payload?.plan_type === 'string'
|
|
213
|
+
? usage.payload.plan_type
|
|
214
|
+
.trim()
|
|
215
|
+
.toLowerCase()
|
|
216
|
+
.replace(/^chatgpt_/, '')
|
|
217
|
+
: ''
|
|
218
|
+
const cost =
|
|
219
|
+
plan === 'free'
|
|
220
|
+
? 'free'
|
|
221
|
+
: ['plus', 'pro', 'team', 'business', 'enterprise', 'edu', 'pro_lite', 'prolite'].includes(plan)
|
|
222
|
+
? 'paid'
|
|
223
|
+
: 'unknown'
|
|
224
|
+
for (const model of models) model.cost = cost
|
|
225
|
+
}
|
|
226
|
+
if (
|
|
227
|
+
!oauth &&
|
|
228
|
+
([
|
|
229
|
+
'zai-coding-cn',
|
|
230
|
+
'cliworker-zai-cn',
|
|
231
|
+
'zhipu-coding-plan',
|
|
232
|
+
'zhipuai-coding-plan',
|
|
233
|
+
'kimi-coding',
|
|
234
|
+
].includes(input.provider) ||
|
|
235
|
+
/open\.bigmodel\.cn\/api\/coding\//.test(base))
|
|
236
|
+
) {
|
|
237
|
+
for (const model of models) if (model.cost === 'free') model.cost = 'unknown'
|
|
238
|
+
}
|
|
239
|
+
return { state: 'supported', source: 'account-models', models }
|
|
240
|
+
}
|
|
241
|
+
if (!oauth && [404, 405].includes(modelResponse?.status)) {
|
|
242
|
+
// Declaring a custom model is not an account entitlement proof.
|
|
243
|
+
const verified = [...new Set(input.verifiedModelIds ?? [])].filter(
|
|
244
|
+
(id) => validId(id) && id !== token && !(token.length >= 12 && id.includes(token)),
|
|
245
|
+
)
|
|
246
|
+
if (verified.length)
|
|
247
|
+
return {
|
|
248
|
+
state: 'supported',
|
|
249
|
+
source: 'verified-route',
|
|
250
|
+
models: verified.map((id) => ({ id, cost: 'unknown' })),
|
|
251
|
+
}
|
|
252
|
+
}
|
|
253
|
+
return unknown()
|
|
254
|
+
} catch {
|
|
255
|
+
return unknown()
|
|
256
|
+
} finally {
|
|
257
|
+
clearTimeout(timer)
|
|
258
|
+
}
|
|
259
|
+
}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type ProcessBackend, type RuntimeConfig } from './process.ts';
|
|
2
|
+
import { type CliId } from '../shared/types.ts';
|
|
3
|
+
import type { AccountAction, AccountFrame, AccountSource, AccountStatus } from '../shared/accounts.ts';
|
|
4
|
+
import { type AccountIdentitySource } from './account-identity.ts';
|
|
5
|
+
/** User-only auth processes. Only allowlisted identity metadata leaves the Host. */
|
|
6
|
+
export declare class AccountManager {
|
|
7
|
+
private backend;
|
|
8
|
+
private config;
|
|
9
|
+
private identity;
|
|
10
|
+
private readonly sessions;
|
|
11
|
+
private readonly reserved;
|
|
12
|
+
private readonly unsafeQueries;
|
|
13
|
+
private readonly statusQueries;
|
|
14
|
+
private readonly pending;
|
|
15
|
+
private readonly parents;
|
|
16
|
+
private readonly parentClosings;
|
|
17
|
+
private readonly controller;
|
|
18
|
+
private closing?;
|
|
19
|
+
constructor(backend: ProcessBackend, config: RuntimeConfig, identity?: AccountIdentitySource);
|
|
20
|
+
isBusy(cli: CliId): boolean;
|
|
21
|
+
status(cli: CliId, cwd: string, signal: AbortSignal): Promise<AccountStatus>;
|
|
22
|
+
private readStatus;
|
|
23
|
+
private hasCustomExecutable;
|
|
24
|
+
start(parent: string, cli: CliId, action: AccountAction, cwd: string, signal: AbortSignal, source?: AccountSource): Promise<{
|
|
25
|
+
id: string;
|
|
26
|
+
instruction: string;
|
|
27
|
+
}>;
|
|
28
|
+
private startSession;
|
|
29
|
+
private readTerminal;
|
|
30
|
+
private emit;
|
|
31
|
+
private owned;
|
|
32
|
+
watch(parent: string, id: string, signal: AbortSignal): AsyncIterable<AccountFrame>;
|
|
33
|
+
write(parent: string, id: string, data: string): Promise<void>;
|
|
34
|
+
resize(parent: string, id: string, cols: number, rows: number): Promise<void>;
|
|
35
|
+
stop(parent: string, id: string): Promise<void>;
|
|
36
|
+
/** Close one Agent lifetime, including startup; a later Agent with the same ID gets a fresh scope. */
|
|
37
|
+
closeParent(parent: string): Promise<void>;
|
|
38
|
+
private finish;
|
|
39
|
+
private track;
|
|
40
|
+
close(): Promise<void>;
|
|
41
|
+
}
|