dsh-cliworker-now 0.7.6 → 0.7.7
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 +29 -9
- package/README.md +31 -9
- package/lib/account-models.mjs +16 -13
- package/lib/client.js +658 -61
- package/lib/client.js.map +1 -1
- package/lib/grok-catalog.mjs +2 -2
- package/lib/hermes-native-entry.py +48 -13
- package/lib/hermes-nous-refresh.py +331 -0
- package/lib/index.js +3724 -1589
- package/lib/index.js.map +1 -1
- package/lib/native-launch.mjs +62 -7
- package/lib/native-spawn.mjs +32 -0
- package/lib/pi-installation.mjs +27 -3
- package/lib/pi-native-catalog.mjs +2 -2
- package/lib/pi-omp-bridge.mjs +2 -2
- package/lib/private-launch.mjs +6 -2
- package/lib/terminal-bridge.mjs +2 -2
- package/lib/typert.host.js +83 -11
- package/lib/typert.remote-client.d.ts +2 -0
- package/lib/typert.remote-client.d.ts.map +1 -1
- package/lib/typert.remote-client.js +77 -11
- package/lib/types/client/account-query-queue.d.ts +16 -0
- package/lib/types/client/account-query-queue.js +61 -0
- package/lib/types/client/account-query-queue.js.map +1 -0
- package/lib/types/client/account-terminal.d.ts +6 -2
- package/lib/types/client/account-terminal.js +260 -31
- package/lib/types/client/account-terminal.js.map +1 -1
- package/lib/types/client/settings-dialog.js +65 -38
- package/lib/types/client/settings-dialog.js.map +1 -1
- package/lib/types/client/zcode-login-link-provider.d.ts +9 -0
- package/lib/types/client/zcode-login-link-provider.js +105 -0
- package/lib/types/client/zcode-login-link-provider.js.map +1 -0
- package/lib/types/client/zcode-login-link.d.ts +16 -0
- package/lib/types/client/zcode-login-link.js +194 -0
- package/lib/types/client/zcode-login-link.js.map +1 -0
- package/lib/types/host/account-models.d.mts +3 -1
- package/lib/types/host/account-models.mjs +16 -13
- package/lib/types/host/accounts.d.ts +3 -2
- package/lib/types/host/accounts.js +129 -22
- package/lib/types/host/accounts.js.map +1 -1
- package/lib/types/host/adapters.d.ts +1 -1
- package/lib/types/host/adapters.js +60 -11
- package/lib/types/host/adapters.js.map +1 -1
- package/lib/types/host/agy-models.d.ts +2 -1
- package/lib/types/host/agy-models.js +6 -6
- package/lib/types/host/agy-models.js.map +1 -1
- package/lib/types/host/agy-windows-account.d.ts +14 -0
- package/lib/types/host/agy-windows-account.js +104 -0
- package/lib/types/host/agy-windows-account.js.map +1 -0
- package/lib/types/host/authorized-catalog.js +13 -4
- package/lib/types/host/authorized-catalog.js.map +1 -1
- package/lib/types/host/claude-native-oauth.d.ts +17 -0
- package/lib/types/host/claude-native-oauth.js +272 -0
- package/lib/types/host/claude-native-oauth.js.map +1 -0
- package/lib/types/host/claude-own-route.d.ts +33 -0
- package/lib/types/host/claude-own-route.js +250 -0
- package/lib/types/host/claude-own-route.js.map +1 -0
- package/lib/types/host/cli-account-binding.d.ts +2 -1
- package/lib/types/host/cli-account-binding.js +59 -21
- package/lib/types/host/cli-account-binding.js.map +1 -1
- package/lib/types/host/codex-models.js +4 -0
- package/lib/types/host/codex-models.js.map +1 -1
- package/lib/types/host/extended-adapters.d.ts +3 -2
- package/lib/types/host/extended-adapters.js +9 -7
- package/lib/types/host/extended-adapters.js.map +1 -1
- package/lib/types/host/first-party-models.d.ts +1 -0
- package/lib/types/host/first-party-models.js +136 -47
- package/lib/types/host/first-party-models.js.map +1 -1
- package/lib/types/host/hermes-accounts.js +15 -1
- package/lib/types/host/hermes-accounts.js.map +1 -1
- package/lib/types/host/hermes-adapter.d.ts +3 -0
- package/lib/types/host/hermes-adapter.js +13 -4
- package/lib/types/host/hermes-adapter.js.map +1 -1
- package/lib/types/host/hermes-installation.js +54 -35
- package/lib/types/host/hermes-installation.js.map +1 -1
- package/lib/types/host/hermes-native-entry.py +48 -13
- package/lib/types/host/hermes-nous-refresh.py +331 -0
- package/lib/types/host/hermes-nous.d.ts +5 -1
- package/lib/types/host/hermes-nous.js +5 -5
- package/lib/types/host/hermes-nous.js.map +1 -1
- package/lib/types/host/hermes-renewal.d.ts +27 -0
- package/lib/types/host/hermes-renewal.js +292 -0
- package/lib/types/host/hermes-renewal.js.map +1 -0
- package/lib/types/host/hermes-windows-installation.d.ts +5 -0
- package/lib/types/host/hermes-windows-installation.js +91 -0
- package/lib/types/host/hermes-windows-installation.js.map +1 -0
- package/lib/types/host/index.d.ts +2 -0
- package/lib/types/host/index.js +17 -2
- package/lib/types/host/index.js.map +1 -1
- package/lib/types/host/kimi-accounts.d.ts +2 -0
- package/lib/types/host/kimi-accounts.js +4 -2
- package/lib/types/host/kimi-accounts.js.map +1 -1
- package/lib/types/host/kimi-oauth-models.d.ts +14 -0
- package/lib/types/host/kimi-oauth-models.js +246 -0
- package/lib/types/host/kimi-oauth-models.js.map +1 -0
- package/lib/types/host/mimo-metadata-cache.d.ts +22 -0
- package/lib/types/host/mimo-metadata-cache.js +121 -0
- package/lib/types/host/mimo-metadata-cache.js.map +1 -0
- package/lib/types/host/native-capability-cache.d.ts +11 -0
- package/lib/types/host/native-capability-cache.js +94 -0
- package/lib/types/host/native-capability-cache.js.map +1 -0
- package/lib/types/host/native-launch.mjs +62 -7
- package/lib/types/host/native-process.d.ts +3 -1
- package/lib/types/host/native-process.js +18 -3
- package/lib/types/host/native-process.js.map +1 -1
- package/lib/types/host/native-spawn.mjs +32 -0
- package/lib/types/host/pi-installation.d.mts +1 -1
- package/lib/types/host/pi-installation.mjs +27 -3
- package/lib/types/host/pi-omp-adapter.js +15 -1
- package/lib/types/host/pi-omp-adapter.js.map +1 -1
- package/lib/types/host/private-launch.mjs +23 -0
- package/lib/types/host/routing.js +25 -2
- package/lib/types/host/routing.js.map +1 -1
- package/lib/types/host/runtime.js +17 -5
- package/lib/types/host/runtime.js.map +1 -1
- package/lib/types/host/windows-account-bootstrap.ps1 +44 -0
- package/lib/types/host/windows-account-launch.mjs +47 -0
- package/lib/types/host/windows-account-owner.ps1 +137 -0
- package/lib/types/host/windows-account-stdio.mjs +19 -0
- package/lib/types/host/windows-account-terminal.d.ts +17 -0
- package/lib/types/host/windows-account-terminal.js +208 -0
- package/lib/types/host/windows-account-terminal.js.map +1 -0
- package/lib/types/host/windows-agy-account.ps1 +81 -0
- package/lib/types/host/windows-cli-installation.d.ts +31 -0
- package/lib/types/host/windows-cli-installation.js +157 -0
- package/lib/types/host/windows-cli-installation.js.map +1 -0
- package/lib/types/host/windows-hidden-launch.mjs +49 -0
- package/lib/types/host/windows-hidden-process.d.ts +12 -0
- package/lib/types/host/windows-hidden-process.js +116 -0
- package/lib/types/host/windows-hidden-process.js.map +1 -0
- package/lib/types/host/zcode-adapter.js +5 -1
- package/lib/types/host/zcode-adapter.js.map +1 -1
- package/lib/types/host/zcode-grok-accounts.d.ts +3 -1
- package/lib/types/host/zcode-grok-accounts.js +60 -11
- package/lib/types/host/zcode-grok-accounts.js.map +1 -1
- package/lib/types/shared/accounts.d.ts +4 -0
- package/lib/windows-account-bootstrap.ps1 +44 -0
- package/lib/windows-account-launch.mjs +47 -0
- package/lib/windows-account-owner.ps1 +137 -0
- package/lib/windows-account-stdio.mjs +19 -0
- package/lib/windows-agy-account.ps1 +81 -0
- package/lib/windows-hidden-launch.mjs +49 -0
- package/lib/zcode-resume.mjs +2 -2
- package/package.json +1 -1
|
@@ -0,0 +1,194 @@
|
|
|
1
|
+
const nativePrompt = 'Open this URL to sign in:';
|
|
2
|
+
const maxLineLength = 8_192;
|
|
3
|
+
// Fixed endpoints observed from the official CLI's provider-specific device
|
|
4
|
+
// flows. Preserve the server-returned URL; never construct or rewrite one.
|
|
5
|
+
const nativeEndpoints = {
|
|
6
|
+
zai: {
|
|
7
|
+
prefix: /^https:\/\/chat\.z\.ai(?::443)?\/api\/oauth\/authorize\?/,
|
|
8
|
+
origin: 'https://chat.z.ai',
|
|
9
|
+
path: '/api/oauth/authorize',
|
|
10
|
+
parameters: ['client_id', 'redirect_uri', 'state', 'response_type'],
|
|
11
|
+
},
|
|
12
|
+
bigmodel: {
|
|
13
|
+
prefix: /^https:\/\/bigmodel\.cn(?::443)?\/login\?/,
|
|
14
|
+
origin: 'https://bigmodel.cn',
|
|
15
|
+
path: '/login',
|
|
16
|
+
parameters: ['appId', 'redirect', 'state'],
|
|
17
|
+
},
|
|
18
|
+
};
|
|
19
|
+
/** Validate only the observed native authorization endpoint; return the original bytes. */
|
|
20
|
+
function nativeLoginUrl(line, provider) {
|
|
21
|
+
// Older callers retain their Z.AI-only contract. Unknown providers never
|
|
22
|
+
// broaden navigation to either region or a caller-supplied destination.
|
|
23
|
+
const selected = provider === undefined ? 'zai' : provider;
|
|
24
|
+
if (selected !== 'zai' && selected !== 'bigmodel')
|
|
25
|
+
return undefined;
|
|
26
|
+
const endpoint = nativeEndpoints[selected];
|
|
27
|
+
if (line.length > maxLineLength || !endpoint.prefix.test(line) || /[\s\p{C}<>"'\\#]/u.test(line))
|
|
28
|
+
return undefined;
|
|
29
|
+
try {
|
|
30
|
+
const url = new URL(line);
|
|
31
|
+
if (url.protocol !== 'https:' ||
|
|
32
|
+
url.origin !== endpoint.origin ||
|
|
33
|
+
url.pathname !== endpoint.path ||
|
|
34
|
+
url.username ||
|
|
35
|
+
url.password ||
|
|
36
|
+
url.hash ||
|
|
37
|
+
(url.port && url.port !== '443'))
|
|
38
|
+
return undefined;
|
|
39
|
+
for (const parameter of endpoint.parameters) {
|
|
40
|
+
const values = url.searchParams.getAll(parameter);
|
|
41
|
+
if (values.length !== 1 || !values[0]?.trim())
|
|
42
|
+
return undefined;
|
|
43
|
+
}
|
|
44
|
+
return line;
|
|
45
|
+
}
|
|
46
|
+
catch {
|
|
47
|
+
return undefined;
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
/**
|
|
51
|
+
* The caller must enable this only for a ZCode login session and pass the selected
|
|
52
|
+
* provider so one region cannot open the other region's URL. URLs stay in memory.
|
|
53
|
+
* Accept a single complete line immediately after the fixed native --no-browser
|
|
54
|
+
* prompt. SGR/cursor visibility do not affect text. The observed ConPTY blank
|
|
55
|
+
* screen initialization is accepted only before any prompt/URL text; arbitrary
|
|
56
|
+
* cursor edits do not become trusted text. OSC payloads are never stored.
|
|
57
|
+
*/
|
|
58
|
+
export function createZcodeLoginLinkParser(provider) {
|
|
59
|
+
let mode = 'text';
|
|
60
|
+
let line = '';
|
|
61
|
+
let invalidLine = false;
|
|
62
|
+
let carriageReturn = false;
|
|
63
|
+
let csiParameters = true;
|
|
64
|
+
let csiLength = 0;
|
|
65
|
+
let csiSequence = '';
|
|
66
|
+
let oscCommand = '';
|
|
67
|
+
let oscCommandComplete = false;
|
|
68
|
+
let oscInitialization = false;
|
|
69
|
+
let awaitingUrl = false;
|
|
70
|
+
let previousUrl;
|
|
71
|
+
const reset = () => {
|
|
72
|
+
mode = 'text';
|
|
73
|
+
line = '';
|
|
74
|
+
invalidLine = false;
|
|
75
|
+
carriageReturn = false;
|
|
76
|
+
csiParameters = true;
|
|
77
|
+
csiLength = 0;
|
|
78
|
+
csiSequence = '';
|
|
79
|
+
oscCommand = '';
|
|
80
|
+
oscCommandComplete = false;
|
|
81
|
+
oscInitialization = false;
|
|
82
|
+
awaitingUrl = false;
|
|
83
|
+
previousUrl = undefined;
|
|
84
|
+
};
|
|
85
|
+
const finishLine = () => {
|
|
86
|
+
const complete = invalidLine ? '' : line.trim();
|
|
87
|
+
line = '';
|
|
88
|
+
invalidLine = false;
|
|
89
|
+
carriageReturn = false;
|
|
90
|
+
if (complete === nativePrompt) {
|
|
91
|
+
awaitingUrl = true;
|
|
92
|
+
return undefined;
|
|
93
|
+
}
|
|
94
|
+
const candidate = awaitingUrl ? nativeLoginUrl(complete, provider) : undefined;
|
|
95
|
+
awaitingUrl = false;
|
|
96
|
+
if (!candidate || candidate === previousUrl)
|
|
97
|
+
return undefined;
|
|
98
|
+
previousUrl = candidate;
|
|
99
|
+
return candidate;
|
|
100
|
+
};
|
|
101
|
+
return {
|
|
102
|
+
reset,
|
|
103
|
+
write(chunk) {
|
|
104
|
+
let result;
|
|
105
|
+
for (const character of chunk) {
|
|
106
|
+
if (mode === 'osc' || mode === 'osc-escape') {
|
|
107
|
+
if (character === '\x07' || (mode === 'osc-escape' && character === '\\')) {
|
|
108
|
+
// Only startup OSC 0/2 title metadata is inert here. In particular,
|
|
109
|
+
// OSC 8 hyperlink targets never supply or decorate a login link.
|
|
110
|
+
if (!oscInitialization || !oscCommandComplete || !['0', '2'].includes(oscCommand))
|
|
111
|
+
invalidLine = true;
|
|
112
|
+
mode = 'text';
|
|
113
|
+
}
|
|
114
|
+
else {
|
|
115
|
+
if (!oscCommandComplete) {
|
|
116
|
+
if (character === ';')
|
|
117
|
+
oscCommandComplete = true;
|
|
118
|
+
else if (oscCommand.length < 2)
|
|
119
|
+
oscCommand += character;
|
|
120
|
+
else
|
|
121
|
+
oscInitialization = false;
|
|
122
|
+
}
|
|
123
|
+
mode = character === '\x1b' ? 'osc-escape' : 'osc';
|
|
124
|
+
}
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
if (mode === 'escape') {
|
|
128
|
+
if (character === '[') {
|
|
129
|
+
mode = 'csi';
|
|
130
|
+
csiParameters = true;
|
|
131
|
+
csiLength = 0;
|
|
132
|
+
csiSequence = '';
|
|
133
|
+
continue;
|
|
134
|
+
}
|
|
135
|
+
if (character === ']') {
|
|
136
|
+
oscInitialization = !line && !awaitingUrl && !invalidLine;
|
|
137
|
+
oscCommand = '';
|
|
138
|
+
oscCommandComplete = false;
|
|
139
|
+
mode = 'osc';
|
|
140
|
+
}
|
|
141
|
+
else {
|
|
142
|
+
invalidLine = true;
|
|
143
|
+
mode = 'text';
|
|
144
|
+
}
|
|
145
|
+
if (character !== '\n')
|
|
146
|
+
continue;
|
|
147
|
+
}
|
|
148
|
+
else if (mode === 'csi') {
|
|
149
|
+
csiLength++;
|
|
150
|
+
if (character >= '@' && character <= '~') {
|
|
151
|
+
const sequence = csiSequence + character;
|
|
152
|
+
const decoration = character === 'm' && csiParameters;
|
|
153
|
+
const visibility = /^\?25[hl]$/.test(sequence);
|
|
154
|
+
const initialization = !line && !awaitingUrl && !invalidLine && /^(?:2J|0?K|(?:1;1)?H)$/.test(sequence);
|
|
155
|
+
if (csiLength > 64 || (!decoration && !visibility && !initialization))
|
|
156
|
+
invalidLine = true;
|
|
157
|
+
mode = 'text';
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
csiParameters &&= /^[0-9;:]$/.test(character);
|
|
161
|
+
if (csiLength <= 64)
|
|
162
|
+
csiSequence += character;
|
|
163
|
+
if (character !== '\n')
|
|
164
|
+
continue;
|
|
165
|
+
invalidLine = true;
|
|
166
|
+
mode = 'text';
|
|
167
|
+
}
|
|
168
|
+
if (character === '\n') {
|
|
169
|
+
const found = finishLine();
|
|
170
|
+
if (found)
|
|
171
|
+
result = found;
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (carriageReturn)
|
|
175
|
+
invalidLine = true;
|
|
176
|
+
carriageReturn = character === '\r';
|
|
177
|
+
if (carriageReturn)
|
|
178
|
+
continue;
|
|
179
|
+
if (character === '\x1b') {
|
|
180
|
+
mode = 'escape';
|
|
181
|
+
continue;
|
|
182
|
+
}
|
|
183
|
+
if (/[\p{C}]/u.test(character))
|
|
184
|
+
invalidLine = true;
|
|
185
|
+
if (line.length + character.length > maxLineLength)
|
|
186
|
+
invalidLine = true;
|
|
187
|
+
if (!invalidLine)
|
|
188
|
+
line += character;
|
|
189
|
+
}
|
|
190
|
+
return result;
|
|
191
|
+
},
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
//# sourceMappingURL=zcode-login-link.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"zcode-login-link.js","sourceRoot":"","sources":["../../../src/client/zcode-login-link.ts"],"names":[],"mappings":"AAEA,MAAM,YAAY,GAAG,2BAA2B,CAAA;AAChD,MAAM,aAAa,GAAG,KAAK,CAAA;AAC3B,4EAA4E;AAC5E,2EAA2E;AAC3E,MAAM,eAAe,GAAG;IACtB,GAAG,EAAE;QACH,MAAM,EAAE,0DAA0D;QAClE,MAAM,EAAE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"}
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
export interface AccountModelScope {
|
|
2
2
|
state: 'supported' | 'denied' | 'unknown'
|
|
3
3
|
source: 'account-models' | 'configured-custom' | 'verified-route' | 'unknown'
|
|
4
|
+
/** Safe metadata classification; absent when the server did not establish a specific cause. */
|
|
5
|
+
denialReason?: 'authentication' | 'quota'
|
|
4
6
|
models: { id: string; name?: string; cost: 'free' | 'paid' | 'unknown' }[]
|
|
5
7
|
}
|
|
6
8
|
export interface AccountModelInput {
|
|
@@ -9,7 +11,7 @@ export interface AccountModelInput {
|
|
|
9
11
|
baseUrl?: string
|
|
10
12
|
apiType?: string
|
|
11
13
|
/** Mirror a native route that explicitly sends both Anthropic auth headers. */
|
|
12
|
-
anthropicAuth?: 'api-key-and-bearer'
|
|
14
|
+
anthropicAuth?: 'api-key-and-bearer' | 'bearer'
|
|
13
15
|
customModelIds?: string[]
|
|
14
16
|
verifiedModelIds?: string[]
|
|
15
17
|
}
|
|
@@ -1,7 +1,12 @@
|
|
|
1
1
|
// Read-only account metadata. Never refresh OAuth, submit prompts, or return
|
|
2
2
|
// credentials, account IDs, headers, endpoint URLs, or raw exception messages.
|
|
3
3
|
const unknown = () => ({ state: 'unknown', source: 'unknown', models: [] })
|
|
4
|
-
const denied = () => ({
|
|
4
|
+
const denied = (denialReason) => ({
|
|
5
|
+
state: 'denied',
|
|
6
|
+
source: 'unknown',
|
|
7
|
+
models: [],
|
|
8
|
+
...(denialReason ? { denialReason } : {}),
|
|
9
|
+
})
|
|
5
10
|
const validId = (id) => typeof id === 'string' && !!id && id.length <= 1024 && !/[\s\x00-\x1f]/.test(id)
|
|
6
11
|
const object = (value) => value && typeof value === 'object' && !Array.isArray(value)
|
|
7
12
|
const unavailable = (model) =>
|
|
@@ -124,7 +129,7 @@ export async function probeAccountModels(input, options = {}) {
|
|
|
124
129
|
if (typeof token !== 'string' || !token.trim() || token.trimStart().startsWith('!')) return unknown()
|
|
125
130
|
// Near-expiry credentials cannot reliably finish the query. Do not renew them.
|
|
126
131
|
if (oauth && (typeof credential.expires !== 'number' || credential.expires <= Date.now() + 30000))
|
|
127
|
-
return denied()
|
|
132
|
+
return denied('authentication')
|
|
128
133
|
const codex = oauth && ['openai', 'openai-codex'].includes(input.provider)
|
|
129
134
|
// xAI/other subscription catalogs do not expose a verified per-account scope
|
|
130
135
|
// contract here. Do not turn an OAuth login into their whole public catalog.
|
|
@@ -142,8 +147,8 @@ export async function probeAccountModels(input, options = {}) {
|
|
|
142
147
|
if (input.apiType === 'anthropic-messages' && !oauth) {
|
|
143
148
|
// ZCode's native Anthropic factory sends both headers. Other callers keep
|
|
144
149
|
// the ordinary x-api-key contract unless they explicitly mirror that route.
|
|
145
|
-
if (
|
|
146
|
-
headers['x-api-key'] = token
|
|
150
|
+
if (!['api-key-and-bearer', 'bearer'].includes(input.anthropicAuth)) delete headers.Authorization
|
|
151
|
+
if (input.anthropicAuth !== 'bearer') headers['x-api-key'] = token
|
|
147
152
|
headers['anthropic-version'] = '2023-06-01'
|
|
148
153
|
}
|
|
149
154
|
if (codex) {
|
|
@@ -179,7 +184,7 @@ export async function probeAccountModels(input, options = {}) {
|
|
|
179
184
|
: '/models',
|
|
180
185
|
]) {
|
|
181
186
|
modelResponse = await request(path)
|
|
182
|
-
if (modelResponse.status === 401 || modelResponse.status === 403) return denied()
|
|
187
|
+
if (modelResponse.status === 401 || modelResponse.status === 403) return denied('authentication')
|
|
183
188
|
if (modelResponse.status >= 200 && modelResponse.status < 300) break
|
|
184
189
|
if (![404, 405].includes(modelResponse.status)) return unknown()
|
|
185
190
|
}
|
|
@@ -191,7 +196,7 @@ export async function probeAccountModels(input, options = {}) {
|
|
|
191
196
|
return ['invalid_api_key', 'authentication_failed', 'unauthorized', 'forbidden', 401, 403].includes(
|
|
192
197
|
code,
|
|
193
198
|
)
|
|
194
|
-
? denied()
|
|
199
|
+
? denied('authentication')
|
|
195
200
|
: unknown()
|
|
196
201
|
}
|
|
197
202
|
const models = normalize(envelope, oauth, token)
|
|
@@ -199,13 +204,11 @@ export async function probeAccountModels(input, options = {}) {
|
|
|
199
204
|
if (codex) {
|
|
200
205
|
const usage = await request('/wham/usage')
|
|
201
206
|
const rate = usage.payload?.rate_limit
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
)
|
|
208
|
-
return denied()
|
|
207
|
+
if (usage.status === 401 || usage.status === 403) return denied('authentication')
|
|
208
|
+
// Only the authenticated usage response establishes exhausted quota.
|
|
209
|
+
// Keep an unclassified denial distinct from expiry/401/403 and network failure.
|
|
210
|
+
if (usage.status === 200 && rate?.limit_reached === true) return denied('quota')
|
|
211
|
+
if (rate?.allowed === false || rate?.limit_reached === true) return denied()
|
|
209
212
|
// A catalog/menu is not evidence that the account has an executable quota.
|
|
210
213
|
if (usage.status !== 200 || rate?.allowed !== true || rate?.limit_reached !== false) return unknown()
|
|
211
214
|
const plan =
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { type ProcessBackend, type RuntimeConfig } from './process.ts';
|
|
2
2
|
import { type CliId } from '../shared/types.ts';
|
|
3
|
-
import type { AccountAction, AccountFrame, AccountSource, AccountStatus } from '../shared/accounts.ts';
|
|
3
|
+
import type { AccountAction, AccountFrame, AccountSource, AccountStatus, ZCodeLoginProvider } from '../shared/accounts.ts';
|
|
4
4
|
import { type AccountIdentitySource } from './account-identity.ts';
|
|
5
5
|
/** User-only auth processes. Only allowlisted identity metadata leaves the Host. */
|
|
6
6
|
export declare class AccountManager {
|
|
@@ -10,6 +10,7 @@ export declare class AccountManager {
|
|
|
10
10
|
private readonly sessions;
|
|
11
11
|
private readonly reserved;
|
|
12
12
|
private readonly unsafeQueries;
|
|
13
|
+
private readonly unsafeTerminals;
|
|
13
14
|
private readonly statusQueries;
|
|
14
15
|
private readonly pending;
|
|
15
16
|
private readonly parents;
|
|
@@ -21,7 +22,7 @@ export declare class AccountManager {
|
|
|
21
22
|
status(cli: CliId, cwd: string, signal: AbortSignal): Promise<AccountStatus>;
|
|
22
23
|
private readStatus;
|
|
23
24
|
private hasCustomExecutable;
|
|
24
|
-
start(parent: string, cli: CliId, action: AccountAction, cwd: string, signal: AbortSignal, source?: AccountSource): Promise<{
|
|
25
|
+
start(parent: string, cli: CliId, action: AccountAction, cwd: string, signal: AbortSignal, source?: AccountSource, provider?: ZCodeLoginProvider): Promise<{
|
|
25
26
|
id: string;
|
|
26
27
|
instruction: string;
|
|
27
28
|
}>;
|