opencode-anyrouter-auth 0.0.0-stage → 0.1.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/DESIGN.md +245 -0
- package/LICENSE +21 -0
- package/README.md +224 -2
- package/UPSTREAM.md +96 -0
- package/generic.mjs +156 -0
- package/icon.png +0 -0
- package/index.mjs +52 -0
- package/lib/accounts.mjs +200 -0
- package/lib/catalog.mjs +138 -0
- package/lib/headers.mjs +65 -0
- package/lib/model-metadata.mjs +140 -0
- package/lib/model-registry.mjs +61 -0
- package/lib/protocols.mjs +129 -0
- package/lib/provider.mjs +501 -0
- package/lib/responses-filter.mjs +710 -0
- package/lib/site-client.mjs +585 -0
- package/lib/sse-delivery.mjs +140 -0
- package/package.json +48 -4
|
@@ -0,0 +1,140 @@
|
|
|
1
|
+
const object = value => value && typeof value === "object" && !Array.isArray(value) ? value : {};
|
|
2
|
+
const positive = value => Number.isSafeInteger(value) && value > 0;
|
|
3
|
+
const effortValue = value => typeof value === "string" && /^[a-z][a-z0-9_-]{0,31}$/.test(value);
|
|
4
|
+
const modalities = ["text", "image", "audio", "video", "pdf"];
|
|
5
|
+
const origins = {
|
|
6
|
+
openai: /^(?:gpt-|chatgpt-|codex-|o\d(?:-|$))/i,
|
|
7
|
+
anthropic: /^claude-/i, google: /^gemini-/i, deepseek: /^deepseek-/i,
|
|
8
|
+
xai: /^grok-/i, mistral: /^(?:mistral|magistral|codestral|devstral|pixtral|ministral)[-\d]/i,
|
|
9
|
+
moonshotai: /^(?:kimi-|moonshot-)/i, minimax: /^minimax[-/]/i,
|
|
10
|
+
zai: /^glm-/i, alibaba: /^qwen[-\d]/i
|
|
11
|
+
};
|
|
12
|
+
|
|
13
|
+
function first(sources, read, valid = value => value !== undefined) {
|
|
14
|
+
for (const source of sources) {
|
|
15
|
+
const value = read(source);
|
|
16
|
+
if (valid(value)) return value;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
function limits(source) {
|
|
21
|
+
const values = {
|
|
22
|
+
context: [source.limit?.context, source.context_length, source.context_window],
|
|
23
|
+
input: [source.limit?.input, source.max_input_tokens, source.inputTokenLimit],
|
|
24
|
+
output: [source.limit?.output, source.max_output_tokens, source.max_tokens, source.outputTokenLimit]
|
|
25
|
+
};
|
|
26
|
+
return Object.fromEntries(Object.entries(values).map(([key, list]) => [key, list.find(positive)]));
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
function controls(source) {
|
|
30
|
+
if (!Array.isArray(source.reasoning_options)) return undefined;
|
|
31
|
+
const options = source.reasoning_options.flatMap(option => {
|
|
32
|
+
if (!option || !["effort", "toggle", "budget_tokens"].includes(option.type)) return [];
|
|
33
|
+
if (option.type !== "effort") return [{ ...option }];
|
|
34
|
+
if (!Array.isArray(option.values)) return [];
|
|
35
|
+
const values = [...new Set(option.values.filter(effortValue))];
|
|
36
|
+
return values.length || option.values.length === 0 ? [{ type: "effort", values }] : [];
|
|
37
|
+
});
|
|
38
|
+
return options.length || source.reasoning_options.length === 0 ? options : undefined;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function capabilities(source) {
|
|
42
|
+
const cap = object(source.capabilities), result = { input: {}, output: {} };
|
|
43
|
+
for (const [key, alias] of Object.entries({ reasoning: "reasoning", toolcall: "tool_call", temperature: "temperature", attachment: "attachment" })) {
|
|
44
|
+
const value = first([cap[key], source[alias]], value => value, value => typeof value === "boolean");
|
|
45
|
+
if (value !== undefined) result[key] = value;
|
|
46
|
+
}
|
|
47
|
+
if (result.reasoning === undefined && controls(source)?.length) result.reasoning = true;
|
|
48
|
+
if (result.reasoning === undefined && Object.values(object(source.variants)).some(variant =>
|
|
49
|
+
variant?.disabled !== true && effortValue(variant?.reasoningEffort))) result.reasoning = true;
|
|
50
|
+
const interleaved = cap.interleaved ?? source.interleaved;
|
|
51
|
+
if (typeof interleaved === "boolean" || typeof interleaved?.field === "string") result.interleaved = interleaved;
|
|
52
|
+
for (const direction of ["input", "output"]) {
|
|
53
|
+
const listed = source.modalities?.[direction];
|
|
54
|
+
for (const name of modalities) {
|
|
55
|
+
const value = cap[direction]?.[name];
|
|
56
|
+
if (typeof value === "boolean") result[direction][name] = value;
|
|
57
|
+
else if (Array.isArray(listed)) result[direction][name] = listed.includes(name);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
return result;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
function consensus(members) {
|
|
64
|
+
if (members.length < 2) return {};
|
|
65
|
+
const same = values => values[0] !== undefined && values.every(value => JSON.stringify(value) === JSON.stringify(values[0])) ? values[0] : undefined;
|
|
66
|
+
const caps = members.map(capabilities), limit = {}, cap = { input: {}, output: {} };
|
|
67
|
+
for (const key of ["context", "input", "output"]) limit[key] = same(members.map(model => limits(model)[key]));
|
|
68
|
+
for (const key of ["reasoning", "toolcall", "temperature", "attachment", "interleaved"]) cap[key] = same(caps.map(model => model[key]));
|
|
69
|
+
for (const direction of ["input", "output"]) for (const name of modalities) cap[direction][name] = same(caps.map(model => model[direction][name]));
|
|
70
|
+
return { limit, capabilities: cap, reasoning_options: same(members.map(controls)) };
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
function registrySources(id, providerId, registry, declarations) {
|
|
74
|
+
let corresponding = object(registry[providerId]?.models?.[id]);
|
|
75
|
+
const declaredOwner = first(declarations, model => [model.manufacturer, model.owned_by]
|
|
76
|
+
.filter(value => typeof value === "string").map(value => value.toLowerCase()).find(value => Object.hasOwn(origins, value)));
|
|
77
|
+
const prefix = id.split("/")[0].toLowerCase();
|
|
78
|
+
const owner = Object.hasOwn(origins, declaredOwner) ? declaredOwner : Object.hasOwn(origins, prefix) ? prefix :
|
|
79
|
+
Object.keys(origins).find(name => origins[name].test(id.replace(/^models\//i, "")));
|
|
80
|
+
if (!owner) return [corresponding];
|
|
81
|
+
const canonical = id.replace(new RegExp(`^(?:${owner}/|models/)`, "i"), "");
|
|
82
|
+
if (!Object.keys(corresponding).length) corresponding = object(registry[providerId]?.models?.[canonical]);
|
|
83
|
+
const models = object(registry[owner]?.models);
|
|
84
|
+
const exact = object(models[canonical]);
|
|
85
|
+
// Dated aliases require agreement among known versions of the complete
|
|
86
|
+
// base model. A single current alias is not evidence about every snapshot.
|
|
87
|
+
const undated = value => value.replace(/-\d{4}-?\d{2}-?\d{2}$/, "");
|
|
88
|
+
const stem = undated(canonical);
|
|
89
|
+
const snapshot = stem !== canonical ? consensus(Object.entries(models).filter(([name]) => undated(name) === stem).map(([, model]) => model)) : {};
|
|
90
|
+
const family = first([...declarations, corresponding, exact, snapshot], model => model.family, value => typeof value === "string" && value.length > 0);
|
|
91
|
+
const related = family ? Object.values(models).filter(model => model?.family === family) : [];
|
|
92
|
+
return [corresponding, exact, snapshot, consensus(related)];
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
export function resolveModelMetadata({ id, providerId, registry = {}, user = {}, row = {}, pricing = {}, base = {} }) {
|
|
96
|
+
const declared = [user, row, pricing].map(object);
|
|
97
|
+
const owned = [...declared, object(base)];
|
|
98
|
+
const sources = [...declared, ...registrySources(id, providerId, object(registry), declared), object(base)];
|
|
99
|
+
const limitSources = sources.map(limits);
|
|
100
|
+
const limit = {
|
|
101
|
+
context: first(limitSources, value => value.context, positive) ?? 0,
|
|
102
|
+
output: first(limitSources, value => value.output, positive) ?? 0,
|
|
103
|
+
// Magpie serves a plugin model's input cap as the window agents are
|
|
104
|
+
// told (and Codex is exported), so a maker's spec inherited from the
|
|
105
|
+
// registry must not pose as one: only the user's, the site's or the
|
|
106
|
+
// host's own word sets input.
|
|
107
|
+
input: first(owned.map(limits), value => value.input, positive) ?? 0
|
|
108
|
+
};
|
|
109
|
+
// Do not publish inherited sub-limits that cannot fit a provider's smaller
|
|
110
|
+
// context. Unknown (0) is safer than silently conflating input with context.
|
|
111
|
+
for (const key of ["input", "output"]) if (limit.context && limit[key] > limit.context) {
|
|
112
|
+
if (limitSources.findIndex(source => positive(source[key])) < limitSources.findIndex(source => positive(source.context))) limit.context = 0;
|
|
113
|
+
else limit[key] = 0;
|
|
114
|
+
}
|
|
115
|
+
const capSources = sources.map(capabilities), cap = { input: {}, output: {} };
|
|
116
|
+
for (const key of ["reasoning", "toolcall", "temperature", "attachment", "interleaved"]) {
|
|
117
|
+
const value = first(capSources, source => source[key]);
|
|
118
|
+
if (value !== undefined) cap[key] = value;
|
|
119
|
+
}
|
|
120
|
+
for (const direction of ["input", "output"]) for (const name of modalities) {
|
|
121
|
+
const value = first(capSources, source => source[direction][name]);
|
|
122
|
+
if (value !== undefined) cap[direction][name] = value;
|
|
123
|
+
}
|
|
124
|
+
const reasoningOptions = first(sources, controls);
|
|
125
|
+
const efforts = [...new Set((reasoningOptions ?? []).filter(option => option.type === "effort").flatMap(option => option.values))];
|
|
126
|
+
const variants = {};
|
|
127
|
+
if (reasoningOptions !== undefined) for (const effort of efforts) variants[effort] = { reasoningEffort: effort };
|
|
128
|
+
else Object.assign(variants, first(sources, source => Object.keys(object(source.variants)).length ? source.variants : undefined) ?? {});
|
|
129
|
+
for (const [name, value] of Object.entries(object(user.variants))) {
|
|
130
|
+
if (["__proto__", "constructor", "prototype"].includes(name)) continue;
|
|
131
|
+
if (value === false || value?.disabled === true) delete variants[name];
|
|
132
|
+
else if (value && typeof value === "object") variants[name] = { ...variants[name], ...value };
|
|
133
|
+
}
|
|
134
|
+
for (const [name, value] of Object.entries(variants)) if (value === false || value?.disabled === true) delete variants[name];
|
|
135
|
+
cap.reasoning ??= Boolean(reasoningOptions?.length || Object.keys(variants).length);
|
|
136
|
+
return {
|
|
137
|
+
limit, capabilities: cap, variants: cap.reasoning ? variants : {},
|
|
138
|
+
...(reasoningOptions !== undefined ? { reasoning_options: reasoningOptions } : {})
|
|
139
|
+
};
|
|
140
|
+
}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { open } from "node:fs/promises";
|
|
2
|
+
import { homedir } from "node:os";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { readBoundedText } from "./site-client.mjs";
|
|
5
|
+
|
|
6
|
+
export const REGISTRY_URL = "https://models.dev/api.json";
|
|
7
|
+
const MAX_BYTES = 32 * 1024 * 1024;
|
|
8
|
+
const valid = value => value && typeof value === "object" && !Array.isArray(value) &&
|
|
9
|
+
Object.values(value).some(provider => provider?.models && typeof provider.models === "object" && !Array.isArray(provider.models));
|
|
10
|
+
|
|
11
|
+
export function registryCachePaths(env = process.env, home = homedir()) {
|
|
12
|
+
const roots = [env.XDG_CACHE_HOME || join(home, ".cache"), env.LOCALAPPDATA].filter(Boolean);
|
|
13
|
+
return [...new Set(roots)].flatMap(root => ["magpie", "opencode"].map(app => join(root, app, "models.json")));
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
async function readCache(path) {
|
|
17
|
+
const file = await open(path, "r");
|
|
18
|
+
try {
|
|
19
|
+
const stat = await file.stat();
|
|
20
|
+
if (!stat.isFile() || stat.size > MAX_BYTES) return undefined;
|
|
21
|
+
const chunks = [];
|
|
22
|
+
let size = 0;
|
|
23
|
+
for await (const chunk of file.createReadStream({ autoClose: false })) {
|
|
24
|
+
size += chunk.byteLength;
|
|
25
|
+
if (size > MAX_BYTES) return undefined;
|
|
26
|
+
chunks.push(chunk);
|
|
27
|
+
}
|
|
28
|
+
const value = JSON.parse(Buffer.concat(chunks).toString("utf8"));
|
|
29
|
+
if (valid(value)) return value;
|
|
30
|
+
} finally { await file.close(); }
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
// This is capability data, not an account catalog. Read the host's raw cache
|
|
34
|
+
// (its normalized model objects lose reasoning_options), never rewrite it.
|
|
35
|
+
export function createModelRegistry({ paths = registryCachePaths(), fetchImpl = (...args) => fetch(...args), now = Date.now,
|
|
36
|
+
ttlMs = 300000, timeoutMs = 5000 } = {}) {
|
|
37
|
+
let cached = {}, expires = 0, pending;
|
|
38
|
+
return async () => {
|
|
39
|
+
if (now() < expires) return cached;
|
|
40
|
+
if (pending) return pending;
|
|
41
|
+
pending = (async () => {
|
|
42
|
+
try {
|
|
43
|
+
for (const path of paths) {
|
|
44
|
+
try {
|
|
45
|
+
const value = await readCache(path);
|
|
46
|
+
if (value) { cached = value; return cached; }
|
|
47
|
+
} catch {}
|
|
48
|
+
}
|
|
49
|
+
const response = await fetchImpl(REGISTRY_URL, {
|
|
50
|
+
headers: { accept: "application/json" }, redirect: "error", signal: AbortSignal.timeout(timeoutMs)
|
|
51
|
+
});
|
|
52
|
+
if (!response.ok) { await response.body?.cancel(); return cached; }
|
|
53
|
+
const value = JSON.parse(await readBoundedText(response, MAX_BYTES));
|
|
54
|
+
if (valid(value)) cached = value;
|
|
55
|
+
} catch {}
|
|
56
|
+
return cached;
|
|
57
|
+
})();
|
|
58
|
+
try { return await pending; }
|
|
59
|
+
finally { expires = now() + ttlMs; pending = undefined; }
|
|
60
|
+
};
|
|
61
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
export function protocolOfURL(value) {
|
|
2
|
+
const path = new URL(value instanceof Request ? value.url : String(value)).pathname;
|
|
3
|
+
if (/\/responses\/?$/.test(path)) return "responses";
|
|
4
|
+
if (/\/chat\/completions\/?$/.test(path)) return "chat";
|
|
5
|
+
if (/\/messages\/?$/.test(path)) return "anthropic";
|
|
6
|
+
if (/\/models\/[^/]+:(?:streamGenerateContent|generateContent)$/.test(path)) return "gemini";
|
|
7
|
+
return null;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
export function errorOf(value) {
|
|
11
|
+
const error = value?.error ?? value?.response?.error;
|
|
12
|
+
if (error && typeof error === "object" && !Array.isArray(error)) return error;
|
|
13
|
+
if (value?.type === "response.failed") return {};
|
|
14
|
+
if (value?.type === "error" && typeof value.message === "string") return value;
|
|
15
|
+
return null;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function incomplete(message) {
|
|
19
|
+
return Object.assign(new Error(message), { code: "stream_incomplete", status: 502 });
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function frameData(frame) {
|
|
23
|
+
const lines = frame.replace(/^\uFEFF/, "").split(/\r\n|\n|\r/);
|
|
24
|
+
const data = lines.filter(line => line === "data" || line.startsWith("data:"))
|
|
25
|
+
.map(line => line.slice(5).replace(/^ /, "")).join("\n");
|
|
26
|
+
const event = lines.find(line => line.startsWith("event:"))?.slice(6).trim();
|
|
27
|
+
return { event, data };
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
export function createSseInspector(protocol, request = {}) {
|
|
31
|
+
const choices = new Map();
|
|
32
|
+
const wanted = protocol === "gemini" ? request.generationConfig?.candidateCount : request.n;
|
|
33
|
+
const count = Number.isInteger(wanted) && wanted > 0 ? wanted : 1;
|
|
34
|
+
let blocked = false;
|
|
35
|
+
|
|
36
|
+
function allFinished() {
|
|
37
|
+
return choices.size >= count && [...choices.values()].every(Boolean);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
function accept(frame) {
|
|
41
|
+
const { event, data } = frameData(frame);
|
|
42
|
+
if (!data.trim()) return null;
|
|
43
|
+
if (data.trim() === "[DONE]") {
|
|
44
|
+
if (protocol !== "chat") return null;
|
|
45
|
+
if (!allFinished()) throw incomplete("Chat SSE ended without terminal results for all requested choices.");
|
|
46
|
+
return { kind: "complete" };
|
|
47
|
+
}
|
|
48
|
+
let value;
|
|
49
|
+
try { value = JSON.parse(data); } catch { throw incomplete("The upstream sent malformed SSE JSON."); }
|
|
50
|
+
if (!value || typeof value !== "object" || Array.isArray(value)) throw incomplete("The upstream sent an invalid SSE value.");
|
|
51
|
+
const type = event || value.type;
|
|
52
|
+
const normalized = type === "error" || type === "response.failed" ? { ...value, type } : value;
|
|
53
|
+
if (errorOf(normalized) !== null) return { kind: "error", value: normalized };
|
|
54
|
+
if (protocol === "responses") {
|
|
55
|
+
if (type === "response.completed" || type === "response.incomplete") return { kind: type };
|
|
56
|
+
} else if (protocol === "anthropic") {
|
|
57
|
+
if (type === "message_stop") return { kind: "complete" };
|
|
58
|
+
} else if (protocol === "chat") {
|
|
59
|
+
for (const choice of value.choices ?? []) {
|
|
60
|
+
if (!Number.isInteger(choice?.index) || choice.index < 0) throw incomplete("The upstream sent a Chat choice without a valid index.");
|
|
61
|
+
const finished = typeof choice.finish_reason === "string" && choice.finish_reason.length > 0;
|
|
62
|
+
choices.set(choice.index, Boolean(choices.get(choice.index)) || finished);
|
|
63
|
+
}
|
|
64
|
+
} else if (protocol === "gemini") {
|
|
65
|
+
if (value.promptFeedback?.blockReason && !(value.candidates?.length)) blocked = true;
|
|
66
|
+
for (const [position, candidate] of (value.candidates ?? []).entries()) {
|
|
67
|
+
const index = candidate.index ?? position;
|
|
68
|
+
if (!Number.isInteger(index) || index < 0) throw incomplete("The upstream sent a Gemini candidate without a valid index.");
|
|
69
|
+
const finished = typeof candidate.finishReason === "string" && candidate.finishReason.length > 0;
|
|
70
|
+
choices.set(index, Boolean(choices.get(index)) || finished);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
return {
|
|
77
|
+
accept,
|
|
78
|
+
finish() {
|
|
79
|
+
// Gemini has no DONE sentinel: consume its usage trailers and require both
|
|
80
|
+
// protocol completion and a normally terminated transport.
|
|
81
|
+
if (protocol === "gemini" && (blocked || allFinished())) return { kind: "complete" };
|
|
82
|
+
throw incomplete(`The upstream ${protocol} stream ended before a valid terminal result.`);
|
|
83
|
+
}
|
|
84
|
+
};
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
export function protocolRetryClass(value, protocol) {
|
|
88
|
+
if (protocol === "responses") return null;
|
|
89
|
+
const error = errorOf(value) || value;
|
|
90
|
+
const code = error?.type || error?.status || error?.code;
|
|
91
|
+
if (["overloaded_error", "api_error", "server_error", "upstream_error", "UNAVAILABLE", "INTERNAL"].includes(code)) {
|
|
92
|
+
return "availability";
|
|
93
|
+
}
|
|
94
|
+
// A Gemini RESOURCE_EXHAUSTED error can mean exhausted daily/billing quota.
|
|
95
|
+
// Only an explicit per-minute/second limit is a local rate retry.
|
|
96
|
+
if (protocol === "gemini" && code === "RESOURCE_EXHAUSTED" &&
|
|
97
|
+
/per[ _-]?(?:minute|second)|requests?\s*\/\s*(?:min|sec)/i.test(error.message || "")) return "rateLimit";
|
|
98
|
+
return null;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
export function failureStatus(error) {
|
|
102
|
+
const codes = [error?.type, error?.status, error?.code].filter(value => typeof value === "string");
|
|
103
|
+
if (codes.some(code => /^(authentication_error|invalid_api_key|unauthorized|UNAUTHENTICATED)$/.test(code))) return 401;
|
|
104
|
+
if (codes.some(code => /^(permission_error|permission_denied|forbidden|PERMISSION_DENIED)$/.test(code))) return 403;
|
|
105
|
+
if (codes.some(code => /^(rate_limit_error|rate_limit_exceeded|insufficient_quota|RESOURCE_EXHAUSTED)$/.test(code))) return 429;
|
|
106
|
+
if (codes.some(code => /^(invalid_request_error|INVALID_ARGUMENT)$/.test(code)) && error?.code !== "invalid_encrypted_content") return 400;
|
|
107
|
+
return 502;
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
export function errorRoutingHeaders(value, original) {
|
|
111
|
+
const headers = new Headers(original);
|
|
112
|
+
const error = errorOf(value) || value;
|
|
113
|
+
if (!headers.has("x-magpie-sign-in") && error?.code !== "invalid_api_key" &&
|
|
114
|
+
/unauthorized client detected/i.test(error?.message || "")) headers.set("x-magpie-sign-in", "kept");
|
|
115
|
+
return headers;
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export function errorEnvelope(error, status, protocol) {
|
|
119
|
+
const message = error.message || "The upstream request could not be completed.";
|
|
120
|
+
if (protocol === "anthropic") {
|
|
121
|
+
const type = ({ 400: "invalid_request_error", 401: "authentication_error", 403: "permission_error", 429: "rate_limit_error" })[status] || "api_error";
|
|
122
|
+
return { type: "error", error: { ...error, type, message } };
|
|
123
|
+
}
|
|
124
|
+
if (protocol === "gemini") {
|
|
125
|
+
const name = ({ 400: "INVALID_ARGUMENT", 401: "UNAUTHENTICATED", 403: "PERMISSION_DENIED", 413: "INVALID_ARGUMENT", 429: "RESOURCE_EXHAUSTED" })[status] || "UNAVAILABLE";
|
|
126
|
+
return { error: { code: status, status: typeof error.status === "string" ? error.status : name, message, ...(Array.isArray(error.details) ? { details: error.details } : {}) } };
|
|
127
|
+
}
|
|
128
|
+
return { error: { ...error, message, type: error.type || "invalid_request_error", code: error.code || "local_filter_error" } };
|
|
129
|
+
}
|