dsh-keys-manager 0.4.3 → 0.4.5
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/CHANGELOG.md +15 -0
- package/README.md +12 -23
- package/README.zh-CN.md +9 -7
- package/lib/core.js +1 -0
- package/lib/core.js.map +1 -1
- package/lib/extra-capabilities.generated.d.ts +1 -1
- package/lib/extra-capabilities.generated.js +760 -250
- package/lib/extra-capabilities.generated.js.map +1 -1
- package/lib/index.js +1 -2
- package/lib/index.js.map +1 -1
- package/lib/omp-oauth/oauth.mjs +192 -38
- package/package.json +16 -16
package/lib/omp-oauth/oauth.mjs
CHANGED
|
@@ -90,11 +90,25 @@ var init_bun_global = __esm({
|
|
|
90
90
|
}
|
|
91
91
|
});
|
|
92
92
|
|
|
93
|
+
// node_modules/@oh-my-pi/pi-catalog/src/effort.ts
|
|
94
|
+
var init_effort = __esm({
|
|
95
|
+
"node_modules/@oh-my-pi/pi-catalog/src/effort.ts"() {
|
|
96
|
+
init_bun_global();
|
|
97
|
+
}
|
|
98
|
+
});
|
|
99
|
+
|
|
93
100
|
// scripts/omp-oauth/omp-shim/pi-utils.ts
|
|
94
|
-
|
|
101
|
+
function isRecord(value) {
|
|
102
|
+
return typeof value === "object" && value !== null && !Array.isArray(value);
|
|
103
|
+
}
|
|
104
|
+
var SEC, MIN, HOUR, DAY, $env, logger;
|
|
95
105
|
var init_pi_utils = __esm({
|
|
96
106
|
"scripts/omp-oauth/omp-shim/pi-utils.ts"() {
|
|
97
107
|
init_bun_global();
|
|
108
|
+
SEC = 1e3;
|
|
109
|
+
MIN = 60 * SEC;
|
|
110
|
+
HOUR = 60 * MIN;
|
|
111
|
+
DAY = 24 * HOUR;
|
|
98
112
|
$env = new Proxy(
|
|
99
113
|
{},
|
|
100
114
|
{
|
|
@@ -130,6 +144,7 @@ var ProviderHttpError, MAX_ANTHROPIC_ERROR_BODY_BYTES;
|
|
|
130
144
|
var init_classes = __esm({
|
|
131
145
|
"node_modules/@oh-my-pi/pi-ai/src/error/classes.ts"() {
|
|
132
146
|
init_bun_global();
|
|
147
|
+
init_pi_utils();
|
|
133
148
|
init_abort();
|
|
134
149
|
init_network_cause();
|
|
135
150
|
ProviderHttpError = class extends Error {
|
|
@@ -154,6 +169,7 @@ var init_rate_limit = __esm({
|
|
|
154
169
|
"node_modules/@oh-my-pi/pi-ai/src/error/rate-limit.ts"() {
|
|
155
170
|
init_bun_global();
|
|
156
171
|
init_pi_utils();
|
|
172
|
+
init_pi_utils();
|
|
157
173
|
QUOTA_EXHAUSTED_BACKOFF_MS = 30 * 60 * 1e3;
|
|
158
174
|
RATE_LIMIT_EXCEEDED_BACKOFF_MS = 30 * 1e3;
|
|
159
175
|
CONCURRENT_LIMIT_BACKOFF_MS = 5 * 1e3;
|
|
@@ -178,6 +194,7 @@ var Flag, KIND_MASK, RETRIABLE_KINDS, CONTEXT_OVERFLOW_EVIDENCE_PATTERNS, GENERI
|
|
|
178
194
|
var init_flags = __esm({
|
|
179
195
|
"node_modules/@oh-my-pi/pi-ai/src/error/flags.ts"() {
|
|
180
196
|
init_bun_global();
|
|
197
|
+
init_effort();
|
|
181
198
|
init_pi_utils();
|
|
182
199
|
init_aws();
|
|
183
200
|
init_classes();
|
|
@@ -216,10 +233,17 @@ var init_flags = __esm({
|
|
|
216
233
|
* status value, so no raw status id can set it.
|
|
217
234
|
*/
|
|
218
235
|
CacheControlUnsupported: 2048,
|
|
236
|
+
/**
|
|
237
|
+
* The transport already spent its own retry budget on this transient status
|
|
238
|
+
* (e.g. 503 backed off twice); every replay re-sends a request the provider
|
|
239
|
+
* may already have charged for, so no later layer retries it. A low bit like
|
|
240
|
+
* {@link Flag.CacheControlUnsupported}: 0x400 is 1024, above every HTTP status.
|
|
241
|
+
*/
|
|
242
|
+
RetriesExhausted: 1024,
|
|
219
243
|
/** HTTP 413 byte/media rejection — token compaction cannot shrink bytes or media budgets (#9235). */
|
|
220
244
|
PayloadRejected: 2147483648
|
|
221
245
|
};
|
|
222
|
-
KIND_MASK = Flag.ThinkingLoop | Flag.Transient | Flag.Timeout | Flag.UsageLimit | Flag.StaleResponsesItem | Flag.MalformedFunctionCall | Flag.ProviderFinishError | Flag.EmptyResponse | Flag.ContentBlocked | Flag.AccountPolicy | Flag.ContextOverflow | Flag.AuthFailed | Flag.PayloadRejected | Flag.SilentAbort | Flag.UserInterrupt | Flag.Abort | Flag.Grammar | Flag.FastModeUnsupported | Flag.CacheControlUnsupported | Flag.OAuthExpiry;
|
|
246
|
+
KIND_MASK = Flag.ThinkingLoop | Flag.Transient | Flag.Timeout | Flag.UsageLimit | Flag.StaleResponsesItem | Flag.MalformedFunctionCall | Flag.ProviderFinishError | Flag.EmptyResponse | Flag.ContentBlocked | Flag.AccountPolicy | Flag.ContextOverflow | Flag.AuthFailed | Flag.PayloadRejected | Flag.SilentAbort | Flag.UserInterrupt | Flag.Abort | Flag.Grammar | Flag.FastModeUnsupported | Flag.CacheControlUnsupported | Flag.RetriesExhausted | Flag.OAuthExpiry;
|
|
223
247
|
RETRIABLE_KINDS = Flag.Transient | Flag.UsageLimit | Flag.ThinkingLoop | Flag.StaleResponsesItem | Flag.ProviderFinishError | Flag.EmptyResponse;
|
|
224
248
|
CONTEXT_OVERFLOW_EVIDENCE_PATTERNS = [
|
|
225
249
|
/prompt is too long/i,
|
|
@@ -290,7 +314,8 @@ var init_flags = __esm({
|
|
|
290
314
|
[Flag.AuthFailed, "auth-failed"],
|
|
291
315
|
[Flag.SilentAbort, "silent-abort"],
|
|
292
316
|
[Flag.UserInterrupt, "user-interrupt"],
|
|
293
|
-
[Flag.Abort, "abort"]
|
|
317
|
+
[Flag.Abort, "abort"],
|
|
318
|
+
[Flag.RetriesExhausted, "retries-exhausted"]
|
|
294
319
|
];
|
|
295
320
|
}
|
|
296
321
|
});
|
|
@@ -329,15 +354,20 @@ var init_oauth = __esm({
|
|
|
329
354
|
kind;
|
|
330
355
|
provider;
|
|
331
356
|
status;
|
|
357
|
+
code;
|
|
358
|
+
/** See {@link OAuthErrorOptions.definitive}; `undefined` when the provider gave no verdict. */
|
|
359
|
+
definitive;
|
|
332
360
|
constructor(message, options = {}) {
|
|
333
361
|
super(message, options.cause === void 0 ? void 0 : { cause: options.cause });
|
|
334
362
|
this.name = "OAuthError";
|
|
335
363
|
this.kind = options.kind ?? "http";
|
|
336
364
|
this.provider = options.provider;
|
|
337
365
|
this.status = options.status;
|
|
366
|
+
this.code = options.code;
|
|
367
|
+
this.definitive = options.definitive;
|
|
338
368
|
attach(
|
|
339
369
|
this,
|
|
340
|
-
this.kind === "timeout" || this.kind === "polling" ? create(Flag.Transient) : create(Flag.AuthFailed)
|
|
370
|
+
options.definitive ? create(Flag.AuthFailed, Flag.OAuthExpiry) : this.kind === "timeout" || this.kind === "polling" ? create(Flag.Transient) : create(Flag.AuthFailed)
|
|
341
371
|
);
|
|
342
372
|
}
|
|
343
373
|
};
|
|
@@ -349,6 +379,7 @@ var init_auth_classify = __esm({
|
|
|
349
379
|
"node_modules/@oh-my-pi/pi-ai/src/error/auth-classify.ts"() {
|
|
350
380
|
init_bun_global();
|
|
351
381
|
init_pi_utils();
|
|
382
|
+
init_classes();
|
|
352
383
|
init_flags();
|
|
353
384
|
init_oauth();
|
|
354
385
|
init_rate_limit();
|
|
@@ -421,8 +452,11 @@ var init_finalize = __esm({
|
|
|
421
452
|
"node_modules/@oh-my-pi/pi-ai/src/error/finalize.ts"() {
|
|
422
453
|
init_bun_global();
|
|
423
454
|
init_abort();
|
|
455
|
+
init_http_inspector();
|
|
456
|
+
init_retry_after();
|
|
424
457
|
init_flags();
|
|
425
458
|
init_format();
|
|
459
|
+
init_rate_limit();
|
|
426
460
|
}
|
|
427
461
|
});
|
|
428
462
|
|
|
@@ -720,6 +754,7 @@ async function loginKilo(callbacks) {
|
|
|
720
754
|
|
|
721
755
|
// node_modules/@oh-my-pi/pi-ai/src/registry/engine/oauth-code.ts
|
|
722
756
|
init_bun_global();
|
|
757
|
+
init_pi_utils();
|
|
723
758
|
init_error();
|
|
724
759
|
|
|
725
760
|
// scripts/omp-oauth/overrides/api-key-validation.ts
|
|
@@ -731,9 +766,39 @@ async function validateApiKeyAgainstModelsEndpoint() {
|
|
|
731
766
|
// node_modules/@oh-my-pi/pi-ai/src/registry/oauth/callback-server.ts
|
|
732
767
|
init_bun_global();
|
|
733
768
|
init_pi_utils();
|
|
734
|
-
init_error();
|
|
735
769
|
import * as os from "node:os";
|
|
736
770
|
|
|
771
|
+
// node_modules/@oh-my-pi/pi-ai/src/auth-gateway/http.ts
|
|
772
|
+
init_bun_global();
|
|
773
|
+
import { timingSafeEqual as nodeTimingSafeEqual } from "node:crypto";
|
|
774
|
+
init_pi_utils();
|
|
775
|
+
|
|
776
|
+
// node_modules/@oh-my-pi/pi-ai/src/providers/anthropic-identity.ts
|
|
777
|
+
init_bun_global();
|
|
778
|
+
init_pi_utils();
|
|
779
|
+
|
|
780
|
+
// node_modules/@oh-my-pi/pi-ai/src/providers/claude-code-fingerprint.ts
|
|
781
|
+
init_bun_global();
|
|
782
|
+
|
|
783
|
+
// node_modules/@oh-my-pi/pi-ai/src/auth-gateway/http.ts
|
|
784
|
+
function timingSafeEqual(a, b) {
|
|
785
|
+
if (a.length === b.length && typeof nodeTimingSafeEqual === "function") {
|
|
786
|
+
return nodeTimingSafeEqual(a, b);
|
|
787
|
+
}
|
|
788
|
+
const len = Math.max(a.length, b.length);
|
|
789
|
+
let diff = a.length ^ b.length;
|
|
790
|
+
for (let i = 0; i < len; i++) {
|
|
791
|
+
const av = (i < a.length ? a[i] : 0) | 0;
|
|
792
|
+
const bv = (i < b.length ? b[i] : 0) | 0;
|
|
793
|
+
diff |= av ^ bv;
|
|
794
|
+
}
|
|
795
|
+
return diff === 0;
|
|
796
|
+
}
|
|
797
|
+
var TOKEN_ENCODER = new TextEncoder();
|
|
798
|
+
|
|
799
|
+
// node_modules/@oh-my-pi/pi-ai/src/registry/oauth/callback-server.ts
|
|
800
|
+
init_error();
|
|
801
|
+
|
|
737
802
|
// node_modules/@oh-my-pi/pi-ai/src/registry/oauth/native-scheme-callback.ts
|
|
738
803
|
init_bun_global();
|
|
739
804
|
|
|
@@ -790,7 +855,7 @@ async function createNativeSchemeCallbackReceiver(scheme, options = {}) {
|
|
|
790
855
|
}
|
|
791
856
|
|
|
792
857
|
// node_modules/@oh-my-pi/pi-ai/src/registry/oauth/oauth.html
|
|
793
|
-
var oauth_default = '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <meta name="color-scheme" content="dark light" />\n <title>omp \xB7 authentication</title>\n <style>\n :root {\n --bg: #000;\n --card: #0b0b0d;\n --ink-1: #f4f4f5;\n --ink-2: #b4b4bb;\n --ink-3: #7a7a83;\n --line-1: rgb(255 255 255 / 0.07);\n --line-2: rgb(255 255 255 / 0.12);\n --top-lit: rgb(255 255 255 / 0.22);\n --accent-a: #22d3ee;\n --accent-b: #f472b6;\n --accent-gradient: linear-gradient(135deg, var(--accent-a), var(--accent-b));\n --ok: #4ade80;\n --ok-soft: rgb(74 222 128 / 0.12);\n --bad: #f87171;\n --bad-soft: rgb(248 113 113 / 0.12);\n --pending: #a1a1aa;\n --pending-soft: rgb(161 161 170 / 0.12);\n --glow-a: rgb(34 211 238 / 0.1);\n --glow-b: rgb(244 114 182 / 0.08);\n --shadow: 0 30px 60px -20px rgb(0 0 0 / 0.8);\n --btn-bg: #f4f4f5;\n --btn-fg: #000;\n --r-control: 8px;\n --r-panel: 16px;\n --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;\n color-scheme: dark;\n }\n\n @media (prefers-color-scheme: light) {\n :root {\n --bg: #fafafa;\n --card: #fff;\n --ink-1: #111113;\n --ink-2: #4b4b52;\n --ink-3: #83838b;\n --line-1: rgb(0 0 0 / 0.08);\n --line-2: rgb(0 0 0 / 0.12);\n --top-lit: rgb(0 0 0 / 0.04);\n --accent-a: #0891b2;\n --accent-b: #db2777;\n --ok: #16a34a;\n --ok-soft: rgb(22 163 74 / 0.1);\n --bad: #dc2626;\n --bad-soft: rgb(220 38 38 / 0.1);\n --pending: #71717a;\n --pending-soft: rgb(113 113 122 / 0.1);\n --glow-a: rgb(8 145 178 / 0.08);\n --glow-b: rgb(219 39 119 / 0.06);\n --shadow: 0 20px 50px -24px rgb(0 0 0 / 0.18);\n --btn-bg: #111113;\n --btn-fg: #fff;\n color-scheme: light;\n }\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 1.5rem;\n font-family: var(--sans);\n background: var(--bg);\n color: var(--ink-1);\n -webkit-font-smoothing: antialiased;\n overflow-x: clip;\n }\n\n /* ambient glow */\n .glow {\n position: fixed;\n inset: 0;\n pointer-events: none;\n background:\n radial-gradient(ellipse 50vw 40vh at 38% 30%, var(--glow-a), transparent 70%),\n radial-gradient(ellipse 50vw 40vh at 64% 64%, var(--glow-b), transparent 70%);\n }\n\n .container {\n position: relative;\n width: 100%;\n max-width: 400px;\n padding: 2rem 2rem 1.75rem;\n background: var(--card);\n border: 1px solid var(--line-1);\n border-radius: var(--r-panel);\n box-shadow: var(--shadow);\n overflow: hidden;\n animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;\n }\n /* top-lit hairline */\n .container::before {\n content: "";\n position: absolute;\n top: 0;\n left: 12%;\n right: 12%;\n height: 1px;\n background: linear-gradient(90deg, transparent, var(--top-lit), transparent);\n }\n @keyframes rise {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n\n .brand {\n display: flex;\n align-items: center;\n gap: 0.6rem;\n margin-bottom: 1.75rem;\n }\n .omp-mark {\n flex: none;\n display: block;\n }\n .wordmark {\n font-size: 13px;\n font-weight: 600;\n letter-spacing: -0.01em;\n }\n .wordmark-sub {\n margin-left: auto;\n font-family: var(--mono);\n font-size: 12px;\n color: var(--ink-3);\n }\n\n .status {\n display: inline-flex;\n align-items: center;\n gap: 0.45rem;\n padding: 0.22rem 0.6rem 0.22rem 0.5rem;\n margin-bottom: 1rem;\n border-radius: 999px;\n font-size: 12px;\n font-weight: 500;\n color: var(--pending);\n background: var(--pending-soft);\n }\n .status-dot {\n width: 7px;\n height: 7px;\n border-radius: 50%;\n background: currentColor;\n }\n .status-word {\n display: none;\n }\n .container:not(.success):not(.error) .status-pending,\n .success .status-success,\n .error .status-error {\n display: inline;\n }\n .container:not(.success):not(.error) .status-dot {\n animation: pulse 1.4s ease-in-out infinite;\n }\n @keyframes pulse {\n 50% {\n opacity: 0.35;\n }\n }\n .success .status {\n color: var(--ok);\n background: var(--ok-soft);\n }\n .error .status {\n color: var(--bad);\n background: var(--bad-soft);\n }\n\n h1 {\n margin: 0 0 0.5rem;\n font-size: 1.35rem;\n font-weight: 600;\n letter-spacing: -0.02em;\n line-height: 1.25;\n text-wrap: balance;\n }\n p {\n margin: 0 0 1.5rem;\n font-size: 0.9rem;\n line-height: 1.6;\n color: var(--ink-2);\n }\n p:last-of-type:not(:has(+ .btn)) {\n margin-bottom: 0.25rem;\n }\n .error p {\n font-family: var(--mono);\n font-size: 0.8rem;\n padding: 0.6rem 0.75rem;\n border: 1px solid var(--line-1);\n border-radius: var(--r-control);\n overflow-wrap: anywhere;\n }\n\n .btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n padding: 0.6rem 1rem;\n font: inherit;\n font-size: 0.875rem;\n font-weight: 500;\n color: var(--btn-fg);\n background: var(--btn-bg);\n border: none;\n border-radius: var(--r-control);\n cursor: pointer;\n transition: opacity 0.15s;\n }\n .btn:hover {\n opacity: 0.86;\n }\n .btn:focus-visible {\n outline: 2px solid var(--accent-a);\n outline-offset: 2px;\n }\n .error .btn {\n color: var(--ink-1);\n background: transparent;\n border: 1px solid var(--line-2);\n }\n\n /* auto-close progress */\n .timer {\n position: absolute;\n left: 0;\n bottom: 0;\n height: 2px;\n width: 100%;\n background: var(--accent-gradient);\n transform-origin: left;\n transform: scaleX(0);\n }\n .countdown .timer {\n animation: countdown 3s linear forwards;\n }\n @keyframes countdown {\n from {\n transform: scaleX(1);\n }\n to {\n transform: scaleX(0);\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .container,\n .countdown .timer,\n .status-dot {\n animation: none !important;\n }\n }\n </style>\n </head>\n <body>\n <span aria-hidden="true" class="glow"></span>\n <div id="app" class="container">\n <div class="brand">\n <svg class="omp-mark" viewBox="0 0 64 64" width="24" height="24" aria-hidden="true">\n <defs>\n <linearGradient id="omp-mark-grad" x1="0" y1="0" x2="1" y2="1">\n <stop offset="0" stop-color="oklch(0.7 0.24 340)" />\n <stop offset=".5" stop-color="oklch(0.62 0.21 295)" />\n <stop offset="1" stop-color="oklch(0.81 0.14 200)" />\n </linearGradient>\n </defs>\n <path fill="url(#omp-mark-grad)" d="M10 14h44v9H43v33h-9V23h-9v22h-9V23H10z" />\n </svg>\n <span class="wordmark">omp</span>\n <span class="wordmark-sub">oauth</span>\n </div>\n\n <div class="status" role="status">\n <span aria-hidden="true" class="status-dot"></span>\n <span class="status-word status-pending">Waiting</span>\n <span class="status-word status-success">Connected</span>\n <span class="status-word status-error">Failed</span>\n </div>\n\n <h1 id="title">Authentication</h1>\n <p id="message"></p>\n <button onclick="window.close()" class="btn">Close window</button>\n <span aria-hidden="true" class="timer"></span>\n </div>\n\n <script id="server-state" type="application/json">\n __OAUTH_STATE__\n </script>\n\n <script>\n let serverState;\n try {\n serverState = JSON.parse(document.getElementById("server-state").textContent);\n } catch {\n const params = new URLSearchParams(window.location.search);\n serverState = {\n ok: params.get("ok") === "1",\n error: params.get("error") || "Authentication failed",\n };\n }\n\n const app = document.getElementById("app");\n const title = document.getElementById("title");\n const message = document.getElementById("message");\n\n if (serverState.ok) {\n const closeButton = document.querySelector(".btn");\n app.classList.add("success", "countdown");\n title.textContent = "Authentication successful";\n message.textContent = "You have successfully logged in.";\n window.close();\n setTimeout(() => {\n app.classList.remove("countdown");\n closeButton.remove();\n message.innerHTML = "You have successfully logged in.<br>Please close this tab manually.";\n }, 300);\n } else {\n app.classList.add("error");\n title.textContent = "Authentication failed";\n message.textContent = serverState.error || "An error occurred";\n }\n </script>\n </body>\n</html>\n';
|
|
858
|
+
var oauth_default = '<!doctype html>\n<html lang="en">\n <head>\n <meta charset="UTF-8" />\n <meta name="viewport" content="width=device-width, initial-scale=1.0" />\n <meta name="color-scheme" content="dark light" />\n <title>omp \xB7 authentication</title>\n <style>\n :root {\n --bg: #000;\n --card: #0b0b0d;\n --ink-1: #f4f4f5;\n --ink-2: #b4b4bb;\n --ink-3: #7a7a83;\n --line-1: rgb(255 255 255 / 0.07);\n --line-2: rgb(255 255 255 / 0.12);\n --top-lit: rgb(255 255 255 / 0.22);\n --accent-a: #22d3ee;\n --accent-b: #f472b6;\n --accent-gradient: linear-gradient(135deg, var(--accent-a), var(--accent-b));\n --ok: #4ade80;\n --ok-soft: rgb(74 222 128 / 0.12);\n --bad: #f87171;\n --bad-soft: rgb(248 113 113 / 0.12);\n --pending: #a1a1aa;\n --pending-soft: rgb(161 161 170 / 0.12);\n --glow-a: rgb(34 211 238 / 0.1);\n --glow-b: rgb(244 114 182 / 0.08);\n --shadow: 0 30px 60px -20px rgb(0 0 0 / 0.8);\n --btn-bg: #f4f4f5;\n --btn-fg: #000;\n --r-control: 8px;\n --r-panel: 16px;\n --sans: ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;\n --mono: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;\n color-scheme: dark;\n }\n\n @media (prefers-color-scheme: light) {\n :root {\n --bg: #fafafa;\n --card: #fff;\n --ink-1: #111113;\n --ink-2: #4b4b52;\n --ink-3: #83838b;\n --line-1: rgb(0 0 0 / 0.08);\n --line-2: rgb(0 0 0 / 0.12);\n --top-lit: rgb(0 0 0 / 0.04);\n --accent-a: #0891b2;\n --accent-b: #db2777;\n --ok: #16a34a;\n --ok-soft: rgb(22 163 74 / 0.1);\n --bad: #dc2626;\n --bad-soft: rgb(220 38 38 / 0.1);\n --pending: #71717a;\n --pending-soft: rgb(113 113 122 / 0.1);\n --glow-a: rgb(8 145 178 / 0.08);\n --glow-b: rgb(219 39 119 / 0.06);\n --shadow: 0 20px 50px -24px rgb(0 0 0 / 0.18);\n --btn-bg: #111113;\n --btn-fg: #fff;\n color-scheme: light;\n }\n }\n\n * {\n box-sizing: border-box;\n }\n\n body {\n margin: 0;\n min-height: 100vh;\n display: flex;\n align-items: center;\n justify-content: center;\n padding: 1.5rem;\n font-family: var(--sans);\n background: var(--bg);\n color: var(--ink-1);\n -webkit-font-smoothing: antialiased;\n overflow-x: clip;\n }\n\n /* ambient glow */\n .glow {\n position: fixed;\n inset: 0;\n pointer-events: none;\n background:\n radial-gradient(ellipse 50vw 40vh at 38% 30%, var(--glow-a), transparent 70%),\n radial-gradient(ellipse 50vw 40vh at 64% 64%, var(--glow-b), transparent 70%);\n }\n\n .container {\n position: relative;\n width: 100%;\n max-width: 400px;\n padding: 2rem 2rem 1.75rem;\n background: var(--card);\n border: 1px solid var(--line-1);\n border-radius: var(--r-panel);\n box-shadow: var(--shadow);\n overflow: hidden;\n animation: rise 0.5s cubic-bezier(0.16, 1, 0.3, 1) both;\n }\n /* top-lit hairline */\n .container::before {\n content: "";\n position: absolute;\n top: 0;\n left: 12%;\n right: 12%;\n height: 1px;\n background: linear-gradient(90deg, transparent, var(--top-lit), transparent);\n }\n @keyframes rise {\n from {\n opacity: 0;\n transform: translateY(8px);\n }\n }\n\n .brand {\n display: flex;\n align-items: center;\n gap: 0.6rem;\n margin-bottom: 1.75rem;\n }\n .omp-mark {\n flex: none;\n display: block;\n }\n .wordmark {\n font-size: 13px;\n font-weight: 600;\n letter-spacing: -0.01em;\n }\n .wordmark-sub {\n margin-left: auto;\n font-family: var(--mono);\n font-size: 12px;\n color: var(--ink-3);\n }\n\n .status {\n display: inline-flex;\n align-items: center;\n gap: 0.45rem;\n padding: 0.22rem 0.6rem 0.22rem 0.5rem;\n margin-bottom: 1rem;\n border-radius: 999px;\n font-size: 12px;\n font-weight: 500;\n color: var(--pending);\n background: var(--pending-soft);\n }\n .status-dot {\n width: 7px;\n height: 7px;\n border-radius: 50%;\n background: currentColor;\n }\n .status-word {\n display: none;\n }\n .container:not(.success):not(.error):not(.canceled) .status-pending,\n .success .status-success,\n .error .status-error,\n .canceled .status-canceled {\n display: inline;\n }\n .container:not(.success):not(.error):not(.canceled) .status-dot {\n animation: pulse 1.4s ease-in-out infinite;\n }\n @keyframes pulse {\n 50% {\n opacity: 0.35;\n }\n }\n .success .status {\n color: var(--ok);\n background: var(--ok-soft);\n }\n .error .status {\n color: var(--bad);\n background: var(--bad-soft);\n }\n\n h1 {\n margin: 0 0 0.5rem;\n font-size: 1.35rem;\n font-weight: 600;\n letter-spacing: -0.02em;\n line-height: 1.25;\n text-wrap: balance;\n }\n p {\n margin: 0 0 1.5rem;\n font-size: 0.9rem;\n line-height: 1.6;\n color: var(--ink-2);\n }\n p:last-of-type:not(:has(+ .btn)) {\n margin-bottom: 0.25rem;\n }\n .error p {\n font-family: var(--mono);\n font-size: 0.8rem;\n padding: 0.6rem 0.75rem;\n border: 1px solid var(--line-1);\n border-radius: var(--r-control);\n overflow-wrap: anywhere;\n }\n\n .btn {\n display: inline-flex;\n align-items: center;\n justify-content: center;\n width: 100%;\n padding: 0.6rem 1rem;\n font: inherit;\n font-size: 0.875rem;\n font-weight: 500;\n color: var(--btn-fg);\n background: var(--btn-bg);\n border: none;\n border-radius: var(--r-control);\n cursor: pointer;\n transition: opacity 0.15s;\n }\n .btn:hover {\n opacity: 0.86;\n }\n .btn:focus-visible {\n outline: 2px solid var(--accent-a);\n outline-offset: 2px;\n }\n .error .btn {\n color: var(--ink-1);\n background: transparent;\n border: 1px solid var(--line-2);\n }\n\n /* auto-close progress */\n .timer {\n position: absolute;\n left: 0;\n bottom: 0;\n height: 2px;\n width: 100%;\n background: var(--accent-gradient);\n transform-origin: left;\n transform: scaleX(0);\n }\n .countdown .timer {\n animation: countdown 3s linear forwards;\n }\n @keyframes countdown {\n from {\n transform: scaleX(1);\n }\n to {\n transform: scaleX(0);\n }\n }\n\n @media (prefers-reduced-motion: reduce) {\n .container,\n .countdown .timer,\n .status-dot {\n animation: none !important;\n }\n }\n </style>\n </head>\n <body>\n <span aria-hidden="true" class="glow"></span>\n <div id="app" class="container">\n <div class="brand">\n <svg class="omp-mark" viewBox="0 0 64 64" width="24" height="24" aria-hidden="true">\n <defs>\n <linearGradient id="omp-mark-grad" x1="0" y1="0" x2="1" y2="1">\n <stop offset="0" stop-color="oklch(0.7 0.24 340)" />\n <stop offset=".5" stop-color="oklch(0.62 0.21 295)" />\n <stop offset="1" stop-color="oklch(0.81 0.14 200)" />\n </linearGradient>\n </defs>\n <path fill="url(#omp-mark-grad)" d="M10 14h44v9H43v33h-9V23h-9v22h-9V23H10z" />\n </svg>\n <span class="wordmark">omp</span>\n <span class="wordmark-sub">oauth</span>\n </div>\n\n <div class="status" role="status">\n <span aria-hidden="true" class="status-dot"></span>\n <span class="status-word status-pending">Waiting</span>\n <span class="status-word status-success">Connected</span>\n <span class="status-word status-error">Failed</span>\n <span class="status-word status-canceled">Canceled</span>\n </div>\n\n <h1 id="title">Authentication</h1>\n <p id="message"></p>\n <button onclick="window.close()" class="btn">Close window</button>\n <span aria-hidden="true" class="timer"></span>\n </div>\n\n <script id="server-state" type="application/json">\n __OAUTH_STATE__\n </script>\n\n <script>\n let serverState;\n try {\n serverState = JSON.parse(document.getElementById("server-state").textContent);\n } catch {\n const params = new URLSearchParams(window.location.search);\n serverState = {\n ok: params.get("ok") === "1",\n error: params.get("error") || "Authentication failed",\n };\n }\n\n const app = document.getElementById("app");\n const title = document.getElementById("title");\n const message = document.getElementById("message");\n\n if (serverState.ok) {\n const closeButton = document.querySelector(".btn");\n app.classList.add("success", "countdown");\n title.textContent = "Authentication successful";\n message.textContent = "You have successfully logged in.";\n window.close();\n setTimeout(() => {\n app.classList.remove("countdown");\n closeButton.remove();\n message.innerHTML = "You have successfully logged in.<br>Please close this tab manually.";\n }, 300);\n } else if (serverState.canceled) {\n app.classList.add("canceled");\n title.textContent = "Sign-in canceled";\n message.textContent = serverState.error;\n } else {\n app.classList.add("error");\n title.textContent = "Authentication failed";\n message.textContent = serverState.error || "An error occurred";\n }\n </script>\n </body>\n</html>\n';
|
|
794
859
|
|
|
795
860
|
// node_modules/@oh-my-pi/pi-ai/src/registry/oauth/callback-server.ts
|
|
796
861
|
var DEFAULT_TIMEOUT = 3e5;
|
|
@@ -808,8 +873,17 @@ function isAddressInUse(error) {
|
|
|
808
873
|
function serializeCallbackState(state) {
|
|
809
874
|
return JSON.stringify(state).replaceAll("<", "\\u003c");
|
|
810
875
|
}
|
|
876
|
+
var STATE_ENCODER = new TextEncoder();
|
|
877
|
+
function stateMatches(state, expectedState) {
|
|
878
|
+
return timingSafeEqual(STATE_ENCODER.encode(state), STATE_ENCODER.encode(expectedState));
|
|
879
|
+
}
|
|
811
880
|
function ipv6LoopbackAvailable() {
|
|
812
|
-
|
|
881
|
+
let interfaces;
|
|
882
|
+
try {
|
|
883
|
+
interfaces = os.networkInterfaces();
|
|
884
|
+
} catch {
|
|
885
|
+
return false;
|
|
886
|
+
}
|
|
813
887
|
for (const name in interfaces) {
|
|
814
888
|
const addresses = interfaces[name];
|
|
815
889
|
if (!addresses) continue;
|
|
@@ -834,7 +908,7 @@ function parseNativeCallback(input, redirectUri, expectedState) {
|
|
|
834
908
|
});
|
|
835
909
|
}
|
|
836
910
|
const state = callback.searchParams.get("state") ?? "";
|
|
837
|
-
if (expectedState && state
|
|
911
|
+
if (expectedState && !stateMatches(state, expectedState)) {
|
|
838
912
|
throw new OAuthError("State mismatch - possible CSRF attack", { kind: "device-auth" });
|
|
839
913
|
}
|
|
840
914
|
const error = callback.searchParams.get("error");
|
|
@@ -856,6 +930,7 @@ var OAuthCallbackFlow = class {
|
|
|
856
930
|
callbackHostname;
|
|
857
931
|
redirectUri;
|
|
858
932
|
allowPortFallback;
|
|
933
|
+
timeoutMs;
|
|
859
934
|
#manualInputOnly;
|
|
860
935
|
#nativeScheme;
|
|
861
936
|
#callbackResolve;
|
|
@@ -875,6 +950,7 @@ var OAuthCallbackFlow = class {
|
|
|
875
950
|
this.callbackPath = callbackPath;
|
|
876
951
|
this.callbackHostname = DEFAULT_HOSTNAME;
|
|
877
952
|
this.allowPortFallback = true;
|
|
953
|
+
this.timeoutMs = DEFAULT_TIMEOUT;
|
|
878
954
|
this.#manualInputOnly = false;
|
|
879
955
|
this.#nativeScheme = false;
|
|
880
956
|
return;
|
|
@@ -884,6 +960,7 @@ var OAuthCallbackFlow = class {
|
|
|
884
960
|
this.callbackHostname = preferredPortOrOptions.callbackHostname ?? DEFAULT_HOSTNAME;
|
|
885
961
|
this.redirectUri = preferredPortOrOptions.redirectUri;
|
|
886
962
|
this.allowPortFallback = preferredPortOrOptions.allowPortFallback ?? true;
|
|
963
|
+
this.timeoutMs = preferredPortOrOptions.timeoutMs ?? DEFAULT_TIMEOUT;
|
|
887
964
|
this.#manualInputOnly = preferredPortOrOptions.manualInputOnly ?? false;
|
|
888
965
|
this.#nativeScheme = preferredPortOrOptions.nativeScheme ?? false;
|
|
889
966
|
}
|
|
@@ -941,7 +1018,7 @@ var OAuthCallbackFlow = class {
|
|
|
941
1018
|
this.ctrl.onAuth?.({ url: authUrl, launchUrl, instructions });
|
|
942
1019
|
this.#throwIfCancelled();
|
|
943
1020
|
this.ctrl.onProgress?.(
|
|
944
|
-
receiver || !this.#manualInputOnly ? "Waiting for browser
|
|
1021
|
+
receiver || !this.#manualInputOnly ? "Waiting for you to finish in the browser\u2026" : "Waiting for you to paste the address or code from your browser\u2026"
|
|
945
1022
|
);
|
|
946
1023
|
this.#throwIfCancelled();
|
|
947
1024
|
let callback;
|
|
@@ -954,7 +1031,7 @@ var OAuthCallbackFlow = class {
|
|
|
954
1031
|
this.#throwIfCancelled();
|
|
955
1032
|
receiverAbort.abort("OAuth callback received");
|
|
956
1033
|
await nativeCallback?.catch(() => void 0);
|
|
957
|
-
this.ctrl.onProgress?.("
|
|
1034
|
+
this.ctrl.onProgress?.("Finishing sign-in\u2026");
|
|
958
1035
|
this.#throwIfCancelled();
|
|
959
1036
|
return await this.exchangeToken(callback.code, state, redirectUri);
|
|
960
1037
|
} finally {
|
|
@@ -1169,11 +1246,13 @@ var OAuthCallbackFlow = class {
|
|
|
1169
1246
|
const error = url.searchParams.get("error") || "";
|
|
1170
1247
|
const errorDescription = url.searchParams.get("error_description") || error;
|
|
1171
1248
|
let resultState;
|
|
1249
|
+
const genuine = !expectedState || stateMatches(state, expectedState);
|
|
1250
|
+
const canceled = error === "access_denied" && genuine;
|
|
1172
1251
|
if (error) {
|
|
1173
|
-
resultState = { ok: false, error: `Authorization failed: ${errorDescription}` };
|
|
1252
|
+
resultState = canceled ? { ok: false, canceled: true, error: "Sign-in canceled. You can close this window." } : { ok: false, error: `Authorization failed: ${errorDescription}` };
|
|
1174
1253
|
} else if (!code) {
|
|
1175
1254
|
resultState = { ok: false, error: "Missing authorization code" };
|
|
1176
|
-
} else if (
|
|
1255
|
+
} else if (!genuine) {
|
|
1177
1256
|
resultState = { ok: false, error: "State mismatch - possible CSRF attack" };
|
|
1178
1257
|
} else {
|
|
1179
1258
|
resultState = { ok: true, code, state };
|
|
@@ -1183,17 +1262,17 @@ var OAuthCallbackFlow = class {
|
|
|
1183
1262
|
queueMicrotask(() => {
|
|
1184
1263
|
resolve?.({ code: resultState.code, state: resultState.state });
|
|
1185
1264
|
});
|
|
1186
|
-
} else if (error &&
|
|
1265
|
+
} else if (error && genuine) {
|
|
1187
1266
|
const reject = this.#callbackReject;
|
|
1188
|
-
const message =
|
|
1267
|
+
const message = `Authorization failed: ${errorDescription}`;
|
|
1189
1268
|
queueMicrotask(() => {
|
|
1190
|
-
reject?.(new OAuthError(message, { kind: "device-auth" }));
|
|
1269
|
+
reject?.(new OAuthError(message, { kind: "device-auth", code: error }));
|
|
1191
1270
|
});
|
|
1192
1271
|
}
|
|
1193
1272
|
return new Response(
|
|
1194
1273
|
oauth_default.replaceAll("__OAUTH_STATE__", () => serializeCallbackState(resultState)),
|
|
1195
1274
|
{
|
|
1196
|
-
status: resultState.ok ? 200 : 500,
|
|
1275
|
+
status: resultState.ok || canceled ? 200 : 500,
|
|
1197
1276
|
headers: { "Content-Type": "text/html" }
|
|
1198
1277
|
}
|
|
1199
1278
|
);
|
|
@@ -1202,7 +1281,7 @@ var OAuthCallbackFlow = class {
|
|
|
1202
1281
|
* Wait for OAuth callback or manual input (whichever comes first).
|
|
1203
1282
|
*/
|
|
1204
1283
|
#waitForCallback(expectedState, nativeCallback) {
|
|
1205
|
-
const timeoutSignal = AbortSignal.timeout(
|
|
1284
|
+
const timeoutSignal = AbortSignal.timeout(this.timeoutMs);
|
|
1206
1285
|
const settledSignal = new AbortController();
|
|
1207
1286
|
const signals = this.ctrl.signal ? [this.ctrl.signal, timeoutSignal, settledSignal.signal] : [timeoutSignal, settledSignal.signal];
|
|
1208
1287
|
const signal = AbortSignal.any(signals);
|
|
@@ -1230,8 +1309,14 @@ var OAuthCallbackFlow = class {
|
|
|
1230
1309
|
callbackPromise,
|
|
1231
1310
|
requestManualInput(signal).then((input) => {
|
|
1232
1311
|
const parsed = parseCallbackInput(input);
|
|
1312
|
+
if (parsed.error && (!expectedState || stateMatches(parsed.state ?? "", expectedState))) {
|
|
1313
|
+
throw new OAuthError(`Authorization failed: ${parsed.error}`, {
|
|
1314
|
+
kind: "device-auth",
|
|
1315
|
+
code: parsed.error
|
|
1316
|
+
});
|
|
1317
|
+
}
|
|
1233
1318
|
if (!parsed.code) return null;
|
|
1234
|
-
if (expectedState && parsed.state && parsed.state
|
|
1319
|
+
if (expectedState && parsed.state && !stateMatches(parsed.state, expectedState)) return null;
|
|
1235
1320
|
return { code: parsed.code, state: parsed.state ?? "" };
|
|
1236
1321
|
})
|
|
1237
1322
|
]);
|
|
@@ -1250,20 +1335,17 @@ var OAuthCallbackFlow = class {
|
|
|
1250
1335
|
function parseCallbackInput(input) {
|
|
1251
1336
|
const value = input.trim();
|
|
1252
1337
|
if (!value) return {};
|
|
1338
|
+
const fromParams = (params) => ({
|
|
1339
|
+
code: params.get("code") ?? void 0,
|
|
1340
|
+
state: params.get("state") ?? void 0,
|
|
1341
|
+
error: params.get("error") ?? void 0
|
|
1342
|
+
});
|
|
1253
1343
|
try {
|
|
1254
|
-
|
|
1255
|
-
return {
|
|
1256
|
-
code: url.searchParams.get("code") ?? void 0,
|
|
1257
|
-
state: url.searchParams.get("state") ?? void 0
|
|
1258
|
-
};
|
|
1344
|
+
return fromParams(new URL(value).searchParams);
|
|
1259
1345
|
} catch {
|
|
1260
1346
|
}
|
|
1261
|
-
if (value.includes("code=")) {
|
|
1262
|
-
|
|
1263
|
-
return {
|
|
1264
|
-
code: params.get("code") ?? void 0,
|
|
1265
|
-
state: params.get("state") ?? void 0
|
|
1266
|
-
};
|
|
1347
|
+
if (value.includes("code=") || value.includes("error=")) {
|
|
1348
|
+
return fromParams(new URLSearchParams(value.replace(/^[?#]/, "")));
|
|
1267
1349
|
}
|
|
1268
1350
|
const [code, state] = value.split("#", 2);
|
|
1269
1351
|
return { code, state };
|
|
@@ -1295,6 +1377,7 @@ var HOOKS = {
|
|
|
1295
1377
|
value: {},
|
|
1296
1378
|
login: {},
|
|
1297
1379
|
refresh: {},
|
|
1380
|
+
signOut: {},
|
|
1298
1381
|
afterExchange: {
|
|
1299
1382
|
"zai-mint-key": () => Promise.resolve().then(() => (init_zai(), zai_exports)).then((module) => module.zaiMintKeyHook)
|
|
1300
1383
|
}
|
|
@@ -1411,13 +1494,37 @@ function mapCredentials(map, body, provider, previous) {
|
|
|
1411
1494
|
refresh: readField(map.refresh, body, claims) ?? previous?.refresh ?? "",
|
|
1412
1495
|
expires
|
|
1413
1496
|
};
|
|
1414
|
-
const optional = [
|
|
1497
|
+
const optional = [
|
|
1498
|
+
"email",
|
|
1499
|
+
"accountId",
|
|
1500
|
+
"orgId",
|
|
1501
|
+
"orgName",
|
|
1502
|
+
"projectId",
|
|
1503
|
+
"apiEndpoint",
|
|
1504
|
+
"enterpriseUrl",
|
|
1505
|
+
"scope"
|
|
1506
|
+
];
|
|
1415
1507
|
for (const key of optional) {
|
|
1416
1508
|
const value = readField(map[key], body, claims);
|
|
1417
1509
|
if (value !== void 0) credentials[key] = value;
|
|
1418
1510
|
}
|
|
1511
|
+
const refreshSeconds = map.refreshExpiresIn === void 0 ? void 0 : jsonPath(body, map.refreshExpiresIn);
|
|
1512
|
+
if (typeof refreshSeconds === "number" && Number.isFinite(refreshSeconds)) {
|
|
1513
|
+
credentials.refreshExpires = Date.now() + refreshSeconds * 1e3;
|
|
1514
|
+
}
|
|
1419
1515
|
return credentials;
|
|
1420
1516
|
}
|
|
1517
|
+
function oauthRefusal(body) {
|
|
1518
|
+
if (!isRecord(body)) return {};
|
|
1519
|
+
const { error, error_description: description } = body;
|
|
1520
|
+
return {
|
|
1521
|
+
code: typeof error === "string" ? error : isRecord(error) && typeof error.type === "string" ? error.type : void 0,
|
|
1522
|
+
description: typeof description === "string" ? description : void 0
|
|
1523
|
+
};
|
|
1524
|
+
}
|
|
1525
|
+
function isDeadGrant(rule, status2, refusal) {
|
|
1526
|
+
return (status2 === 400 || status2 === 401) && refusal.code !== void 0 && rule.codes.includes(refusal.code) && (rule.exceptDescription === void 0 || refusal.description !== rule.exceptDescription);
|
|
1527
|
+
}
|
|
1421
1528
|
async function postTokenRequest(request, standardParams, vars, context, errorKind) {
|
|
1422
1529
|
const url = template(await resolveValue(request.url, context.signal), vars);
|
|
1423
1530
|
const params = {};
|
|
@@ -1427,20 +1534,32 @@ async function postTokenRequest(request, standardParams, vars, context, errorKin
|
|
|
1427
1534
|
if (value !== void 0) params[key] = value;
|
|
1428
1535
|
}
|
|
1429
1536
|
}
|
|
1430
|
-
|
|
1537
|
+
for (const key in request.params) {
|
|
1538
|
+
const value = request.params[key];
|
|
1539
|
+
params[key] = typeof value === "string" ? template(value, vars) : value;
|
|
1540
|
+
}
|
|
1431
1541
|
const headers = {
|
|
1432
1542
|
...context.headers,
|
|
1433
1543
|
...templateMap(request.headers, vars),
|
|
1434
1544
|
"Content-Type": request.body === "json" ? "application/json" : "application/x-www-form-urlencoded"
|
|
1435
1545
|
};
|
|
1546
|
+
let payload;
|
|
1547
|
+
if (request.body === "json") {
|
|
1548
|
+
payload = JSON.stringify(params);
|
|
1549
|
+
} else {
|
|
1550
|
+
const form = new URLSearchParams();
|
|
1551
|
+
for (const key in params) form.set(key, String(params[key]));
|
|
1552
|
+
payload = form.toString();
|
|
1553
|
+
}
|
|
1436
1554
|
const timeoutSignal = AbortSignal.timeout(request.timeoutMs ?? DEFAULT_REQUEST_TIMEOUT_MS);
|
|
1437
1555
|
const signal = context.signal ? AbortSignal.any([context.signal, timeoutSignal]) : timeoutSignal;
|
|
1556
|
+
const kept = context.deadGrant ? false : void 0;
|
|
1438
1557
|
let response;
|
|
1439
1558
|
try {
|
|
1440
1559
|
response = await context.fetch(url, {
|
|
1441
1560
|
method: "POST",
|
|
1442
1561
|
headers,
|
|
1443
|
-
body:
|
|
1562
|
+
body: payload,
|
|
1444
1563
|
signal
|
|
1445
1564
|
});
|
|
1446
1565
|
} catch (cause) {
|
|
@@ -1448,12 +1567,17 @@ async function postTokenRequest(request, standardParams, vars, context, errorKin
|
|
|
1448
1567
|
throw new LoginCancelledError(`OAuth login cancelled: ${String(context.signal.reason)}`);
|
|
1449
1568
|
}
|
|
1450
1569
|
if (timeoutSignal.aborted) {
|
|
1451
|
-
throw new OAuthError(`Timed out waiting for ${url}`, {
|
|
1570
|
+
throw new OAuthError(`Timed out waiting for ${url}`, {
|
|
1571
|
+
kind: "timeout",
|
|
1572
|
+
provider: context.provider,
|
|
1573
|
+
definitive: kept
|
|
1574
|
+
});
|
|
1452
1575
|
}
|
|
1453
1576
|
throw new OAuthError(`${context.provider} request to ${url} failed: ${describeError(cause)}`, {
|
|
1454
1577
|
kind: errorKind,
|
|
1455
1578
|
provider: context.provider,
|
|
1456
|
-
cause
|
|
1579
|
+
cause,
|
|
1580
|
+
definitive: kept
|
|
1457
1581
|
});
|
|
1458
1582
|
}
|
|
1459
1583
|
const text = await response.text();
|
|
@@ -1466,9 +1590,16 @@ async function postTokenRequest(request, standardParams, vars, context, errorKin
|
|
|
1466
1590
|
}
|
|
1467
1591
|
}
|
|
1468
1592
|
if (!response.ok && errorKind !== "device-auth") {
|
|
1593
|
+
const refusal = oauthRefusal(body);
|
|
1469
1594
|
throw new OAuthError(
|
|
1470
1595
|
`${context.provider} ${errorKind === "token-refresh" ? "token refresh" : "token exchange"} failed: ${response.status} ${text.slice(0, 500)}`,
|
|
1471
|
-
{
|
|
1596
|
+
{
|
|
1597
|
+
kind: errorKind,
|
|
1598
|
+
provider: context.provider,
|
|
1599
|
+
status: response.status,
|
|
1600
|
+
code: refusal.code,
|
|
1601
|
+
definitive: context.deadGrant ? isDeadGrant(context.deadGrant, response.status, refusal) : void 0
|
|
1602
|
+
}
|
|
1472
1603
|
);
|
|
1473
1604
|
}
|
|
1474
1605
|
return { body: body ?? text, response };
|
|
@@ -1511,12 +1642,29 @@ function throwIfCancelled(signal) {
|
|
|
1511
1642
|
function isLoopbackHost(hostname) {
|
|
1512
1643
|
return hostname === "localhost" || hostname === "127.0.0.1" || hostname === "[::1]";
|
|
1513
1644
|
}
|
|
1645
|
+
var BROKER_CALLBACK_PORT_ENV = "OMP_AUTH_BROKER_CALLBACK_PORT";
|
|
1646
|
+
function portFromEnv(name, provider, min) {
|
|
1647
|
+
const raw = name && $env[name]?.trim();
|
|
1648
|
+
if (!raw) return void 0;
|
|
1649
|
+
const port = /^\d+$/.test(raw) ? Number(raw) : Number.NaN;
|
|
1650
|
+
if (!(port >= min && port <= 65535)) {
|
|
1651
|
+
throw new OAuthError(`${name} must be a port number between ${min} and 65535, got: ${raw}`, {
|
|
1652
|
+
kind: "configuration",
|
|
1653
|
+
provider
|
|
1654
|
+
});
|
|
1655
|
+
}
|
|
1656
|
+
return port;
|
|
1657
|
+
}
|
|
1658
|
+
function resolveCallbackPort(callback, provider) {
|
|
1659
|
+
return portFromEnv(callback.portEnv, provider, 0) ?? callback.port;
|
|
1660
|
+
}
|
|
1514
1661
|
async function resolveCallbackOptions(callback, provider, signal) {
|
|
1662
|
+
const forwardedPort = callback.portEnv ? portFromEnv(BROKER_CALLBACK_PORT_ENV, provider, 1) : void 0;
|
|
1515
1663
|
const base = {
|
|
1516
|
-
preferredPort: callback
|
|
1664
|
+
preferredPort: forwardedPort ?? resolveCallbackPort(callback, provider),
|
|
1517
1665
|
callbackPath: callback.path,
|
|
1518
1666
|
callbackHostname: callback.hostname,
|
|
1519
|
-
allowPortFallback: callback.portFallback,
|
|
1667
|
+
allowPortFallback: forwardedPort === void 0 && callback.portFallback,
|
|
1520
1668
|
manualInputOnly: callback.manualOnly,
|
|
1521
1669
|
nativeScheme: callback.nativeScheme
|
|
1522
1670
|
};
|
|
@@ -1699,6 +1847,7 @@ var ZAI_CODING_PLAN_POLICY = {
|
|
|
1699
1847
|
"id": "zai-coding-plan",
|
|
1700
1848
|
"apiKeyFormat": "bearer",
|
|
1701
1849
|
"name": "Z.AI (GLM Coding Plan \xB7 Sign in)",
|
|
1850
|
+
"logo": "zai",
|
|
1702
1851
|
"login": {
|
|
1703
1852
|
"kind": "oauth-code",
|
|
1704
1853
|
"scopes": [],
|
|
@@ -1775,7 +1924,12 @@ var ZAI_CODING_PLAN_POLICY = {
|
|
|
1775
1924
|
"kind": "none"
|
|
1776
1925
|
},
|
|
1777
1926
|
"callbackPort": 0,
|
|
1778
|
-
"pasteCode": true
|
|
1927
|
+
"pasteCode": true,
|
|
1928
|
+
"loginGroup": {
|
|
1929
|
+
"title": "Z.AI",
|
|
1930
|
+
"label": "Z.AI / Zhipu (GLM Coding Plan)",
|
|
1931
|
+
"order": 2
|
|
1932
|
+
}
|
|
1779
1933
|
};
|
|
1780
1934
|
var ZAI_CODING_PLAN_RULE = ZAI_CODING_PLAN_POLICY.login;
|
|
1781
1935
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "dsh-keys-manager",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Multi-key management for DSH providers: sticky per-session round-robin, retry failover, cooldown recovery, and searchable extra providers.",
|
|
6
6
|
"repository": {
|
|
@@ -65,27 +65,27 @@
|
|
|
65
65
|
},
|
|
66
66
|
"peerDependencies": {
|
|
67
67
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
68
|
-
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.
|
|
69
|
-
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.
|
|
70
|
-
"@deepseek-ai/dsh-client-ui-plugin-manager": "^0.2.2-rc.
|
|
71
|
-
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.
|
|
72
|
-
"@deepseek-ai/dsh-client-ui-settings-models": "^0.2.2-rc.
|
|
73
|
-
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.
|
|
74
|
-
"@deepseek-ai/dsh-credentials": "^0.2.2-rc.
|
|
75
|
-
"@deepseek-ai/dsh-error": "^0.2.2-rc.
|
|
76
|
-
"@deepseek-ai/dsh-llm": "^0.2.2-rc.
|
|
77
|
-
"@deepseek-ai/dsh-settings": "^0.2.2-rc.
|
|
78
|
-
"@deepseek-ai/dsh-typert-registry": "^0.2.2-rc.
|
|
68
|
+
"@deepseek-ai/dsh-client-connection": "^0.2.2-rc.5",
|
|
69
|
+
"@deepseek-ai/dsh-client-locale": "^0.2.2-rc.5",
|
|
70
|
+
"@deepseek-ai/dsh-client-ui-plugin-manager": "^0.2.2-rc.5",
|
|
71
|
+
"@deepseek-ai/dsh-client-ui-settings": "^0.2.2-rc.5",
|
|
72
|
+
"@deepseek-ai/dsh-client-ui-settings-models": "^0.2.2-rc.5",
|
|
73
|
+
"@deepseek-ai/dsh-client-ui-slots": "^0.2.2-rc.5",
|
|
74
|
+
"@deepseek-ai/dsh-credentials": "^0.2.2-rc.5",
|
|
75
|
+
"@deepseek-ai/dsh-error": "^0.2.2-rc.5",
|
|
76
|
+
"@deepseek-ai/dsh-llm": "^0.2.2-rc.5",
|
|
77
|
+
"@deepseek-ai/dsh-settings": "^0.2.2-rc.5",
|
|
78
|
+
"@deepseek-ai/dsh-typert-registry": "^0.2.2-rc.5",
|
|
79
79
|
"react": "^18.2.0"
|
|
80
80
|
},
|
|
81
81
|
"dependencies": {
|
|
82
|
-
"dsh-llm-omp-transports": "^0.4.
|
|
82
|
+
"dsh-llm-omp-transports": "^0.4.5"
|
|
83
83
|
},
|
|
84
84
|
"devDependencies": {
|
|
85
85
|
"@deepseek-ai/cordis": "~4.1.0",
|
|
86
|
-
"@oh-my-pi/pi-ai": "
|
|
87
|
-
"@oh-my-pi/pi-catalog": "
|
|
88
|
-
"@oh-my-pi/pi-utils": "
|
|
86
|
+
"@oh-my-pi/pi-ai": "19.4.2",
|
|
87
|
+
"@oh-my-pi/pi-catalog": "19.4.2",
|
|
88
|
+
"@oh-my-pi/pi-utils": "19.4.2",
|
|
89
89
|
"@types/node": "^22.20.0",
|
|
90
90
|
"@types/react": "~18.3.31",
|
|
91
91
|
"esbuild": "^0.28.2",
|