@providerkit/core 0.26.1 → 0.27.0
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/dist/auth/chatgpt-models.d.ts +21 -0
- package/dist/auth/chatgpt-models.d.ts.map +1 -0
- package/dist/auth/chatgpt-models.js +89 -0
- package/dist/auth/chatgpt-models.js.map +1 -0
- package/dist/auth/index.d.ts +1 -0
- package/dist/auth/index.d.ts.map +1 -1
- package/dist/auth/index.js +1 -0
- package/dist/auth/index.js.map +1 -1
- package/dist/auth/oauth.d.ts +1 -1
- package/dist/auth/oauth.d.ts.map +1 -1
- package/dist/auth/oauth.js.map +1 -1
- package/dist/decisions.js +1 -1
- package/dist/decisions.js.map +1 -1
- package/dist/errors.d.ts +3 -1
- package/dist/errors.d.ts.map +1 -1
- package/dist/errors.js +69 -28
- package/dist/errors.js.map +1 -1
- package/dist/providers/anthropic.js +1 -1
- package/dist/providers/anthropic.js.map +1 -1
- package/dist/providers/factory.d.ts +2 -0
- package/dist/providers/factory.d.ts.map +1 -1
- package/dist/providers/factory.js +5 -2
- package/dist/providers/factory.js.map +1 -1
- package/dist/providers/gemini.js +1 -1
- package/dist/providers/gemini.js.map +1 -1
- package/dist/providers/openai.js +1 -1
- package/dist/providers/openai.js.map +1 -1
- package/dist/providers/responses.d.ts.map +1 -1
- package/dist/providers/responses.js +3 -5
- package/dist/providers/responses.js.map +1 -1
- package/dist/rate-limit.d.ts.map +1 -1
- package/dist/rate-limit.js +29 -6
- package/dist/rate-limit.js.map +1 -1
- package/package.json +2 -2
- package/src/auth/chatgpt-models.ts +119 -0
- package/src/auth/index.ts +1 -0
- package/src/auth/oauth.ts +5 -1
- package/src/decisions.ts +1 -1
- package/src/errors.ts +76 -25
- package/src/providers/anthropic.ts +1 -1
- package/src/providers/factory.ts +5 -2
- package/src/providers/gemini.ts +1 -1
- package/src/providers/openai.ts +1 -1
- package/src/providers/responses.ts +6 -8
- package/src/rate-limit.ts +28 -6
package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Y,IAAI,IAAI,CAAC,YAAY,CAAC;IAC9D,MAAM,MAAM,GACV,IAAI,CAAC,SAAS,KAAK,SAAS,IAAI,IAAI,CAAC,SAAS,GAAG,CAAC,MAAM,CAAC,SAAS,IAAI,CAAC,CAAC;QACtE,CAAC,CAAC,IAAI,CAAC,MAAM;QACb,CAAC,CAAC,CAAC,MAAM,CAAC,MAAM,IAAI,IAAI,CAAC,MAAM,CAAC,CAAC;IACrC,OAAO;QACL,GAAG,CAAC,SAAS,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvC,GAAG,CAAC,YAAY,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;QACvD,GAAG,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;KAC9B,CAAC;AACJ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@providerkit/core",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.27.0",
|
|
4
4
|
"description": "The layer under your agent loop: one seam for every LLM provider, plus the failure handling you only learn in production.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -58,7 +58,7 @@
|
|
|
58
58
|
"check:presets": "bun run scripts/refresh-presets.ts",
|
|
59
59
|
"probe:model": "bun run scripts/probe-model.ts",
|
|
60
60
|
"sync:docs": "cp ../README.md ../LICENSE .",
|
|
61
|
-
"prepublishOnly": "bun run lint && bun run typecheck && bun run
|
|
61
|
+
"prepublishOnly": "bun run lint && bun run typecheck && bun run build && bun run sync:docs",
|
|
62
62
|
"release": "bun publish --access public",
|
|
63
63
|
"release:patch": "bun pm version patch && bun publish --access public",
|
|
64
64
|
"release:minor": "bun pm version minor && bun publish --access public",
|
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { classifyHttp, ProviderError } from "../errors.ts";
|
|
2
|
+
import { PROVIDER_PRESETS } from "../presets.ts";
|
|
3
|
+
import { isEffort, type Effort } from "../types.ts";
|
|
4
|
+
import { asRecord, authFetch, num, str, webUrl, type AuthHost, type Credential } from "./oauth.ts";
|
|
5
|
+
|
|
6
|
+
/** Models the signed-in ChatGPT account can choose in Codex. */
|
|
7
|
+
export interface ChatGPTModel {
|
|
8
|
+
id: string;
|
|
9
|
+
name?: string;
|
|
10
|
+
contextLength?: number;
|
|
11
|
+
/** Only levels this package can send, without guessing equivalent levels. */
|
|
12
|
+
reasoningEfforts?: Effort[];
|
|
13
|
+
priority?: number;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export interface ChatGPTModelsOptions extends Pick<AuthHost, "fetchImpl" | "timeoutMs"> {
|
|
17
|
+
/** The Codex API root. Defaults to the ChatGPT preset's base URL. */
|
|
18
|
+
baseUrl?: string;
|
|
19
|
+
/** The caller's version. Defaults to Codex's development version, `0.0.0`. */
|
|
20
|
+
clientVersion?: string;
|
|
21
|
+
signal?: AbortSignal;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
/** Fetch the account's live model list. Never probes completions or falls back to static ids. */
|
|
25
|
+
export async function listChatGPTModels(
|
|
26
|
+
credential: Pick<Credential, "accessToken" | "chatgptAccountId">,
|
|
27
|
+
options: ChatGPTModelsOptions = {},
|
|
28
|
+
): Promise<ChatGPTModel[]> {
|
|
29
|
+
const base = webUrl(options.baseUrl ?? PROVIDER_PRESETS.chatgpt.baseUrl);
|
|
30
|
+
if (!base) throw new TypeError("The ChatGPT model list needs an http(s) base URL.");
|
|
31
|
+
const url = new URL(base);
|
|
32
|
+
url.pathname = `${url.pathname.replace(/\/+$/, "")}/models`;
|
|
33
|
+
url.searchParams.set("client_version", options.clientVersion ?? "0.0.0");
|
|
34
|
+
const response = await authFetch(options, url.href, {
|
|
35
|
+
method: "GET",
|
|
36
|
+
redirect: "error",
|
|
37
|
+
signal: options.signal,
|
|
38
|
+
headers: {
|
|
39
|
+
Accept: "application/json",
|
|
40
|
+
Authorization: `Bearer ${credential.accessToken}`,
|
|
41
|
+
...(credential.chatgptAccountId ? { "ChatGPT-Account-Id": credential.chatgptAccountId } : {}),
|
|
42
|
+
},
|
|
43
|
+
});
|
|
44
|
+
const text = await response.text();
|
|
45
|
+
if (!response.ok) {
|
|
46
|
+
throw new ProviderError(
|
|
47
|
+
"chatgpt",
|
|
48
|
+
classifyHttp(response.status, text),
|
|
49
|
+
`ChatGPT refused the model list request (HTTP ${response.status}).`,
|
|
50
|
+
{ status: response.status, body: text.slice(0, 2_000) },
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
let payload: unknown;
|
|
54
|
+
try {
|
|
55
|
+
payload = JSON.parse(text);
|
|
56
|
+
} catch {
|
|
57
|
+
throw invalidCatalog();
|
|
58
|
+
}
|
|
59
|
+
const rows = asRecord(payload).models;
|
|
60
|
+
if (!Array.isArray(rows)) throw invalidCatalog();
|
|
61
|
+
const slugs = new Set<string>();
|
|
62
|
+
return rows
|
|
63
|
+
.map((row: unknown) => parseModel(row, slugs))
|
|
64
|
+
.filter((model) => model !== undefined)
|
|
65
|
+
.sort((a, b) => (a.priority ?? 0) - (b.priority ?? 0));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function parseModel(value: unknown, slugs: Set<string>): ChatGPTModel | undefined {
|
|
69
|
+
const row = asRecord(value);
|
|
70
|
+
const id = str(row.slug);
|
|
71
|
+
if (
|
|
72
|
+
!id?.trim() ||
|
|
73
|
+
(row.visibility !== "list" && row.visibility !== "hide" && row.visibility !== "none")
|
|
74
|
+
) {
|
|
75
|
+
throw invalidCatalog();
|
|
76
|
+
}
|
|
77
|
+
if (slugs.has(id)) throw invalidCatalog();
|
|
78
|
+
slugs.add(id);
|
|
79
|
+
const name = str(row.display_name);
|
|
80
|
+
const contextLength = num(row.context_window);
|
|
81
|
+
const priority = num(row.priority);
|
|
82
|
+
if (
|
|
83
|
+
(row.display_name !== undefined && !name?.trim()) ||
|
|
84
|
+
(row.context_window != null &&
|
|
85
|
+
(contextLength === undefined ||
|
|
86
|
+
!Number.isSafeInteger(contextLength) ||
|
|
87
|
+
contextLength <= 0)) ||
|
|
88
|
+
(row.priority !== undefined && (priority === undefined || !Number.isSafeInteger(priority)))
|
|
89
|
+
) {
|
|
90
|
+
throw invalidCatalog();
|
|
91
|
+
}
|
|
92
|
+
let reasoningEfforts: Effort[] | undefined;
|
|
93
|
+
if (row.supported_reasoning_levels !== undefined) {
|
|
94
|
+
if (!Array.isArray(row.supported_reasoning_levels)) throw invalidCatalog();
|
|
95
|
+
reasoningEfforts = row.supported_reasoning_levels.flatMap((level: unknown) => {
|
|
96
|
+
const effort = str(asRecord(level).effort);
|
|
97
|
+
if (!effort) throw invalidCatalog();
|
|
98
|
+
return isEffort(effort) ? [effort] : [];
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
// `supported_in_api` limits API keys, not ChatGPT subscription accounts.
|
|
102
|
+
if (row.visibility !== "list") return undefined;
|
|
103
|
+
return {
|
|
104
|
+
id,
|
|
105
|
+
...(name ? { name } : {}),
|
|
106
|
+
...(contextLength !== undefined ? { contextLength } : {}),
|
|
107
|
+
...(reasoningEfforts !== undefined ? { reasoningEfforts } : {}),
|
|
108
|
+
...(priority !== undefined ? { priority } : {}),
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function invalidCatalog(): ProviderError {
|
|
113
|
+
return new ProviderError(
|
|
114
|
+
"chatgpt",
|
|
115
|
+
"invalid",
|
|
116
|
+
"ChatGPT returned an invalid model list. Fetch the list again.",
|
|
117
|
+
{ code: "models_response_invalid" },
|
|
118
|
+
);
|
|
119
|
+
}
|
package/src/auth/index.ts
CHANGED
package/src/auth/oauth.ts
CHANGED
|
@@ -92,7 +92,11 @@ const AUTH_TIMEOUT_MS = 30_000;
|
|
|
92
92
|
* is sent. The timeout rejects with a `TimeoutError`, which is not a refusal,
|
|
93
93
|
* so `tokenSource` keeps the stored credential.
|
|
94
94
|
*/
|
|
95
|
-
export function authFetch(
|
|
95
|
+
export function authFetch(
|
|
96
|
+
host: Pick<AuthHost, "fetchImpl" | "timeoutMs">,
|
|
97
|
+
url: string,
|
|
98
|
+
init: RequestInit = {},
|
|
99
|
+
): Promise<Response> {
|
|
96
100
|
const deadline = AbortSignal.timeout(host.timeoutMs ?? AUTH_TIMEOUT_MS);
|
|
97
101
|
return (host.fetchImpl ?? fetch)(url, {
|
|
98
102
|
...init,
|
package/src/decisions.ts
CHANGED
|
@@ -547,7 +547,7 @@ export function createDecisionClient(config: DecisionConfig): DecisionClient {
|
|
|
547
547
|
// retried into hiding it.
|
|
548
548
|
const payload = record(json);
|
|
549
549
|
const error = payload?.error ?? payload?.errors;
|
|
550
|
-
if (error !== undefined) throw streamError(provider,
|
|
550
|
+
if (error !== undefined) throw streamError(provider, payload);
|
|
551
551
|
throw new ProviderError(provider, "unknown", `${provider}: the reply has no answers`, {
|
|
552
552
|
body: (JSON.stringify(json) ?? "").slice(0, 2_000),
|
|
553
553
|
});
|
package/src/errors.ts
CHANGED
|
@@ -10,7 +10,12 @@
|
|
|
10
10
|
// read before the status — status alone gives the wrong advice ("retry" for an
|
|
11
11
|
// empty balance, "check your key" for a plan that never included the API).
|
|
12
12
|
|
|
13
|
-
import {
|
|
13
|
+
import {
|
|
14
|
+
parseRateLimitReset,
|
|
15
|
+
parseRateLimitResponse,
|
|
16
|
+
parseUsageLimitBody,
|
|
17
|
+
type RateLimitWindow,
|
|
18
|
+
} from "./rate-limit.ts";
|
|
14
19
|
import type { FilePart } from "./types.ts";
|
|
15
20
|
|
|
16
21
|
/** What kind of failure this is, named by what actually fixes it. */
|
|
@@ -164,11 +169,12 @@ export class ProviderError extends Error {
|
|
|
164
169
|
const code = readString(err, "code") ?? readString(err, "type");
|
|
165
170
|
const message = messageOf(err);
|
|
166
171
|
const body = bodyTextOf(err);
|
|
172
|
+
const resetBody = providerBodyOf(err) ?? body;
|
|
167
173
|
return new ProviderError(provider, classify(err, status, body), message, {
|
|
168
174
|
status,
|
|
169
175
|
code,
|
|
170
|
-
retryAfterMs: parseRetryAfterMs(err,
|
|
171
|
-
...parseUsageLimitBody(
|
|
176
|
+
retryAfterMs: parseRetryAfterMs(err, resetBody),
|
|
177
|
+
...parseUsageLimitBody(resetBody),
|
|
172
178
|
body: body.slice(0, 2_000) || undefined,
|
|
173
179
|
cause: err,
|
|
174
180
|
});
|
|
@@ -218,13 +224,17 @@ export function messageOf(err: unknown): string {
|
|
|
218
224
|
*/
|
|
219
225
|
function bodyTextOf(err: unknown): string {
|
|
220
226
|
const message = messageOf(err);
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
227
|
+
const body = providerBodyOf(err);
|
|
228
|
+
return body === undefined ? message : `${message} ${body}`;
|
|
229
|
+
}
|
|
230
|
+
|
|
231
|
+
/** Kept as JSON for reset parsing; the searchable text above is not JSON. */
|
|
232
|
+
function providerBodyOf(err: unknown): string | undefined {
|
|
233
|
+
if (typeof err !== "object" || err === null || !("error" in err)) return undefined;
|
|
224
234
|
try {
|
|
225
|
-
return
|
|
235
|
+
return typeof err.error === "string" ? err.error : JSON.stringify(err.error);
|
|
226
236
|
} catch {
|
|
227
|
-
return
|
|
237
|
+
return undefined;
|
|
228
238
|
}
|
|
229
239
|
}
|
|
230
240
|
|
|
@@ -361,7 +371,7 @@ const CONTEXT_PATTERNS: readonly RegExp[] = [
|
|
|
361
371
|
// it, and its wording overlaps both other categories ("plan" appears in all
|
|
362
372
|
// three), so it is checked first.
|
|
363
373
|
const ENTITLEMENT_PATTERNS: readonly RegExp[] = [
|
|
364
|
-
/plan does(?:n't| not) (?:include|support)/i,
|
|
374
|
+
/plan does(?:n't| not) (?:yet )?(?:include|support)/i,
|
|
365
375
|
/not included (?:in|with) your .{0,40}plan/i,
|
|
366
376
|
/upgrade to [\w ]{1,30}(?:or higher|plan)/i,
|
|
367
377
|
/requires? (?:the |a |an )?[\w\s]{1,30}plan/i,
|
|
@@ -375,12 +385,22 @@ const ENTITLEMENT_PATTERNS: readonly RegExp[] = [
|
|
|
375
385
|
/usage not included/i,
|
|
376
386
|
];
|
|
377
387
|
|
|
388
|
+
const OPENCODE_FREE_LIMIT = /\bFreeUsageLimitError\b/i;
|
|
389
|
+
|
|
390
|
+
/** OpenCode's free allowance ran out, not a paid account's balance. */
|
|
391
|
+
export function isOpenCodeFreeLimit(body: string): boolean {
|
|
392
|
+
return OPENCODE_FREE_LIMIT.test(body);
|
|
393
|
+
}
|
|
394
|
+
|
|
378
395
|
// Balance or usage window used up. Chinese-market providers report it in
|
|
379
396
|
// Chinese, which is why the literal strings are here rather than a rule.
|
|
380
397
|
const QUOTA_PATTERNS: readonly RegExp[] = [
|
|
381
398
|
/insufficient[_\s]quota/i,
|
|
382
399
|
/exceeded your current quota/i,
|
|
383
400
|
/insufficient (?:balance|credits?)/i,
|
|
401
|
+
/insufficient (?:account )?funds/i,
|
|
402
|
+
/\bcredit limit exceeded\b/i,
|
|
403
|
+
/\baccount invoice is overdue\b/i,
|
|
384
404
|
/credit balance is too low/i,
|
|
385
405
|
/(?:no|any|out of) credits/i,
|
|
386
406
|
/(?:credits?|balance) depleted/i,
|
|
@@ -401,6 +421,14 @@ const QUOTA_PATTERNS: readonly RegExp[] = [
|
|
|
401
421
|
// The OpenAI-shape `type` field for billing failures, serialized into the
|
|
402
422
|
// scanned text — a quota signal with no prose wording at all (codex-router).
|
|
403
423
|
/billing_error/i,
|
|
424
|
+
// OpenCode's typed account caps can carry throttle prose or no prose at all.
|
|
425
|
+
// Their names survive both the HTTP and in-band error envelopes.
|
|
426
|
+
/\b(?:GoUsageLimitError|BudgetLimitError|CreditLimitExceeded)\b/i,
|
|
427
|
+
OPENCODE_FREE_LIMIT,
|
|
428
|
+
/\bbudget exceeded\b/i,
|
|
429
|
+
// Z.ai reports expired coding packages and spent weekly/monthly windows as 429.
|
|
430
|
+
/\bpackage has expired\b/i,
|
|
431
|
+
/\b(?:weekly|monthly) limit exhausted\b/i,
|
|
404
432
|
// Alibaba intl's English spelling of 欠费.
|
|
405
433
|
/\barrears?\b/i,
|
|
406
434
|
/余额不足/,
|
|
@@ -721,19 +749,34 @@ const STATUS_BY_TYPE: ReadonlyMap<string, number> = new Map([
|
|
|
721
749
|
* body does name keeps its own kind, which is what tells the caller to wait,
|
|
722
750
|
* rotate a key, or compact instead of retrying a failure that will repeat.
|
|
723
751
|
*/
|
|
724
|
-
export function streamError(provider: string,
|
|
752
|
+
export function streamError(provider: string, envelope: unknown): ProviderError {
|
|
753
|
+
// Only failure data is searchable or logged. A failed Responses object can
|
|
754
|
+
// echo instructions, tool definitions and output alongside its error.
|
|
755
|
+
const outer =
|
|
756
|
+
typeof envelope === "object" && envelope !== null ? (envelope as Record<string, unknown>) : {};
|
|
757
|
+
const error = outer.error ?? outer.errors ?? envelope;
|
|
725
758
|
const body = JSON.stringify(error ?? {}) ?? "";
|
|
726
759
|
const status = [
|
|
727
760
|
readNumber(error, "code"),
|
|
728
761
|
readNumber(error, "status"),
|
|
729
762
|
readNumber(error, "status_code"),
|
|
763
|
+
readNumber(envelope, "status_code"),
|
|
730
764
|
].find((value) => value !== undefined && value >= 400 && value < 600);
|
|
731
765
|
const code =
|
|
732
766
|
readString(error, "code") ?? readString(error, "status") ?? readString(error, "type");
|
|
733
767
|
const typeStatus =
|
|
734
768
|
STATUS_BY_TYPE.get(readString(error, "type") ?? "") ??
|
|
735
769
|
STATUS_BY_TYPE.get(readString(error, "code") ?? "");
|
|
736
|
-
|
|
770
|
+
// Keep type-derived 4xx precedence. Only a generic 5xx label without a real
|
|
771
|
+
// status may hide an account cap; OpenCode uses server_error for those.
|
|
772
|
+
const classified = classifyHttp(status ?? typeStatus, body);
|
|
773
|
+
const kind =
|
|
774
|
+
status === undefined &&
|
|
775
|
+
typeStatus !== undefined &&
|
|
776
|
+
typeStatus >= 500 &&
|
|
777
|
+
(matches(QUOTA_PATTERNS, body) || matches(ENTITLEMENT_PATTERNS, body))
|
|
778
|
+
? classifyHttp(undefined, body)
|
|
779
|
+
: classified;
|
|
737
780
|
return new ProviderError(
|
|
738
781
|
provider,
|
|
739
782
|
kind === "unknown" ? "overload" : kind,
|
|
@@ -741,27 +784,35 @@ export function streamError(provider: string, error: unknown): ProviderError {
|
|
|
741
784
|
{
|
|
742
785
|
...(status !== undefined ? { status } : {}),
|
|
743
786
|
...(code ? { code } : {}),
|
|
744
|
-
|
|
745
|
-
...readReset(error, body),
|
|
787
|
+
...readReset(envelope, error, body, kind),
|
|
746
788
|
body: body.slice(0, 2_000),
|
|
747
789
|
},
|
|
748
790
|
);
|
|
749
791
|
}
|
|
750
792
|
|
|
751
|
-
/**
|
|
752
|
-
*
|
|
753
|
-
|
|
754
|
-
function readReset(error: unknown, body: string) {
|
|
755
|
-
const raw =
|
|
756
|
-
typeof error === "object" && error !== null
|
|
757
|
-
? (error as { headers?: unknown }).headers
|
|
758
|
-
: undefined;
|
|
759
|
-
if (typeof raw !== "object" || raw === null) return parseUsageLimitBody(body);
|
|
793
|
+
/** Read reset metadata without copying echoed request data into diagnostics.
|
|
794
|
+
* Mirrored account windows describe only rate/quota failures, not a 503. */
|
|
795
|
+
function readReset(envelope: unknown, error: unknown, body: string, kind: ErrorKind) {
|
|
760
796
|
const headers = new Headers();
|
|
761
|
-
for (const [
|
|
762
|
-
if (typeof
|
|
797
|
+
for (const source of [error, envelope]) {
|
|
798
|
+
if (typeof source !== "object" || source === null || !("headers" in source)) continue;
|
|
799
|
+
const raw = source.headers;
|
|
800
|
+
if (typeof raw !== "object" || raw === null) continue;
|
|
801
|
+
for (const [name, value] of Object.entries(raw)) {
|
|
802
|
+
if (typeof value === "string" || typeof value === "number") headers.set(name, String(value));
|
|
803
|
+
}
|
|
763
804
|
}
|
|
764
|
-
|
|
805
|
+
if (kind !== "rate" && kind !== "quota") {
|
|
806
|
+
return {
|
|
807
|
+
retryAfterMs: parseRateLimitReset(headers).retryAfterMs ?? parseRetryAfterMs(error, body),
|
|
808
|
+
};
|
|
809
|
+
}
|
|
810
|
+
const metadata =
|
|
811
|
+
typeof envelope === "object" && envelope !== null && "metadata" in envelope
|
|
812
|
+
? envelope.metadata
|
|
813
|
+
: undefined;
|
|
814
|
+
const reset = parseRateLimitResponse(headers, JSON.stringify({ error, metadata }));
|
|
815
|
+
return { ...reset, retryAfterMs: reset.retryAfterMs ?? parseRetryAfterMs(error, body) };
|
|
765
816
|
}
|
|
766
817
|
|
|
767
818
|
/**
|
|
@@ -578,7 +578,7 @@ export function createAnthropicProvider(config: AnthropicConfig): Provider {
|
|
|
578
578
|
// most of the time, but a prompt found too long mid-stream arrives the
|
|
579
579
|
// same way, and retrying that one only fails it again more slowly.
|
|
580
580
|
case "error":
|
|
581
|
-
throw streamError(id, event
|
|
581
|
+
throw streamError(id, event);
|
|
582
582
|
|
|
583
583
|
case "message_start": {
|
|
584
584
|
const usage = event.message?.usage;
|
package/src/providers/factory.ts
CHANGED
|
@@ -259,6 +259,8 @@ function buildWireAdapter(
|
|
|
259
259
|
* the header on `fetch` (Chromium ignores it) and stamp it another way.
|
|
260
260
|
*/
|
|
261
261
|
export const OPENCODE_CLI_USER_AGENT = "opencode/latest/2.0.32/cli";
|
|
262
|
+
/** OpenCode's public credential for free models without an account. */
|
|
263
|
+
export const OPENCODE_PUBLIC_API_KEY = "public";
|
|
262
264
|
const BASE62 = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
|
263
265
|
|
|
264
266
|
/** Whether an OpenCode Zen model id belongs to the free shelf (`big-pickle` or `*-free`). */
|
|
@@ -376,7 +378,7 @@ function wrapOpenCodeZen(
|
|
|
376
378
|
merged.set("x-opencode-project", "global");
|
|
377
379
|
merged.set("x-opencode-client", "cli");
|
|
378
380
|
if (anonymous) {
|
|
379
|
-
merged.
|
|
381
|
+
merged.set("authorization", `Bearer ${OPENCODE_PUBLIC_API_KEY}`);
|
|
380
382
|
merged.delete("x-api-key");
|
|
381
383
|
merged.delete("x-goog-api-key");
|
|
382
384
|
}
|
|
@@ -416,7 +418,7 @@ function wrapOpenCodeZen(
|
|
|
416
418
|
}
|
|
417
419
|
};
|
|
418
420
|
|
|
419
|
-
const startAnonymous = free && !config.apiKey;
|
|
421
|
+
const startAnonymous = free && (!config.apiKey || config.apiKey === OPENCODE_PUBLIC_API_KEY);
|
|
420
422
|
let emitted = false;
|
|
421
423
|
try {
|
|
422
424
|
for await (const chunk of runAttempt(startAnonymous)) {
|
|
@@ -432,6 +434,7 @@ function wrapOpenCodeZen(
|
|
|
432
434
|
!startAnonymous &&
|
|
433
435
|
!emitted &&
|
|
434
436
|
err instanceof ProviderError &&
|
|
437
|
+
err.kind === "auth" &&
|
|
435
438
|
err.status === 401
|
|
436
439
|
) {
|
|
437
440
|
yield* runAttempt(true);
|
package/src/providers/gemini.ts
CHANGED
|
@@ -594,7 +594,7 @@ export function createGeminiProvider(config: GeminiConfig): Provider {
|
|
|
594
594
|
// `?alt=sse` commits to 200 the moment the headers go out, so a
|
|
595
595
|
// throttle or an overload landing after that arrives here as a
|
|
596
596
|
// google.rpc.Status in the body rather than as a status line.
|
|
597
|
-
if (chunk.error) throw streamError(id, chunk
|
|
597
|
+
if (chunk.error) throw streamError(id, chunk);
|
|
598
598
|
// A blocked PROMPT has no candidate to finish, so it reads as a cut
|
|
599
599
|
// stream — retried, into the same block. It is a content failure.
|
|
600
600
|
const blocked = chunk.promptFeedback?.blockReason;
|
package/src/providers/openai.ts
CHANGED
|
@@ -715,7 +715,7 @@ export function createOpenAIProvider(config: OpenAIConfig): Provider {
|
|
|
715
715
|
// line, and a frame carrying `error` carries no choices: unread, it
|
|
716
716
|
// falls through both branches below and the turn ends as a successful
|
|
717
717
|
// zero-token completion nobody retries.
|
|
718
|
-
if (chunk.error) throw streamError(id, chunk
|
|
718
|
+
if (chunk.error) throw streamError(id, chunk);
|
|
719
719
|
|
|
720
720
|
// A usage-only frame carries no choices — this shape sends it last.
|
|
721
721
|
if (chunk.usage) {
|
|
@@ -689,7 +689,7 @@ export function createResponsesProvider(config: ResponsesConfig): Provider {
|
|
|
689
689
|
// error failed, and one that states `incomplete` was cut. Read as
|
|
690
690
|
// a clean stop, either is a broken turn reported as a finished one.
|
|
691
691
|
if (response?.status === "failed" || response?.error) {
|
|
692
|
-
throw streamError(id, response.error
|
|
692
|
+
throw streamError(id, response.error ? response : { message: "response failed" });
|
|
693
693
|
}
|
|
694
694
|
// Any other status (`cancelled`, `queued`, one added later) says
|
|
695
695
|
// nothing about the answer being whole. Read as a clean stop, it
|
|
@@ -734,7 +734,10 @@ export function createResponsesProvider(config: ResponsesConfig): Provider {
|
|
|
734
734
|
// out: a terminal `response.failed`, or a bare error frame from a
|
|
735
735
|
// gateway in front of it.
|
|
736
736
|
case "response.failed":
|
|
737
|
-
throw streamError(
|
|
737
|
+
throw streamError(
|
|
738
|
+
id,
|
|
739
|
+
event.response?.error ? event.response : { message: "response failed" },
|
|
740
|
+
);
|
|
738
741
|
|
|
739
742
|
case "error":
|
|
740
743
|
case "response.error":
|
|
@@ -742,12 +745,7 @@ export function createResponsesProvider(config: ResponsesConfig): Provider {
|
|
|
742
745
|
// them a spent Codex window reads as an unnamed in-stream failure:
|
|
743
746
|
// floored to overload, then retried and walked across every backup
|
|
744
747
|
// on the same account wall.
|
|
745
|
-
throw streamError(
|
|
746
|
-
id,
|
|
747
|
-
event.error
|
|
748
|
-
? { ...event.error, status_code: event.status_code, headers: event.headers }
|
|
749
|
-
: { message: event.message, code: event.code },
|
|
750
|
-
);
|
|
748
|
+
throw streamError(id, event);
|
|
751
749
|
}
|
|
752
750
|
}
|
|
753
751
|
|
package/src/rate-limit.ts
CHANGED
|
@@ -315,6 +315,28 @@ export function parseUsageLimitBody(bodyText: string, now = Date.now()): RateLim
|
|
|
315
315
|
? (source as Record<string, unknown>)
|
|
316
316
|
: (body as Record<string, unknown>);
|
|
317
317
|
|
|
318
|
+
// OpenCode puts a budget's ISO reset in envelope metadata, or in Google's
|
|
319
|
+
// ErrorInfo details. It names the real horizon, not a short retry hint.
|
|
320
|
+
const envelopes: unknown[] = [
|
|
321
|
+
body,
|
|
322
|
+
error,
|
|
323
|
+
...(Array.isArray(error.details) ? error.details : []),
|
|
324
|
+
];
|
|
325
|
+
let metadataReset = -Infinity;
|
|
326
|
+
for (const envelope of envelopes) {
|
|
327
|
+
if (typeof envelope !== "object" || envelope === null || !("metadata" in envelope)) continue;
|
|
328
|
+
const metadata = envelope.metadata;
|
|
329
|
+
if (
|
|
330
|
+
typeof metadata !== "object" ||
|
|
331
|
+
metadata === null ||
|
|
332
|
+
!("resetsAt" in metadata) ||
|
|
333
|
+
typeof metadata.resetsAt !== "string"
|
|
334
|
+
)
|
|
335
|
+
continue;
|
|
336
|
+
const at = Date.parse(metadata.resetsAt);
|
|
337
|
+
if (Number.isFinite(at)) metadataReset = Math.max(metadataReset, at);
|
|
338
|
+
}
|
|
339
|
+
|
|
318
340
|
const inSeconds = jsonSeconds(error.resets_in_seconds);
|
|
319
341
|
const atSeconds = jsonSeconds(error.resets_at);
|
|
320
342
|
// The plain wait some gateways put in the error body instead of a header,
|
|
@@ -323,12 +345,12 @@ export function parseUsageLimitBody(bodyText: string, now = Date.now()): RateLim
|
|
|
323
345
|
jsonSeconds(error.retry_after) ??
|
|
324
346
|
jsonSeconds(error.retry_after_seconds) ??
|
|
325
347
|
jsonSeconds((body as Record<string, unknown>).retry_after_seconds);
|
|
326
|
-
|
|
327
|
-
if (
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
if (
|
|
331
|
-
return resetAfter(
|
|
348
|
+
let waitMs: number | undefined;
|
|
349
|
+
if (inSeconds !== undefined && inSeconds >= 0) waitMs = inSeconds * 1000;
|
|
350
|
+
else if (atSeconds !== undefined && atSeconds > 0) waitMs = Math.max(0, atSeconds * 1000 - now);
|
|
351
|
+
else if (afterSeconds !== undefined && afterSeconds >= 0) waitMs = afterSeconds * 1000;
|
|
352
|
+
if (waitMs !== undefined || Number.isFinite(metadataReset)) {
|
|
353
|
+
return resetAfter(Math.max(0, waitMs ?? 0, metadataReset - now), now);
|
|
332
354
|
}
|
|
333
355
|
}
|
|
334
356
|
|