@theokit/sdk 5.10.0 → 5.11.1
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 +82 -0
- package/dist/{agent-XTLAVVYC.js → agent-DFV52V6E.js} +8 -7
- package/dist/{agent-XTLAVVYC.js.map → agent-DFV52V6E.js.map} +1 -1
- package/dist/{agent-TLRURB7W.cjs → agent-OKP4LHG2.cjs} +9 -8
- package/dist/{agent-TLRURB7W.cjs.map → agent-OKP4LHG2.cjs.map} +1 -1
- package/dist/{chunk-CVEQ5366.cjs → chunk-35KBC4BX.cjs} +177 -119
- package/dist/chunk-35KBC4BX.cjs.map +1 -0
- package/dist/{chunk-FR6COQXZ.cjs → chunk-3JANYJYS.cjs} +3 -3
- package/dist/{chunk-FR6COQXZ.cjs.map → chunk-3JANYJYS.cjs.map} +1 -1
- package/dist/{chunk-523O5UYB.js → chunk-6G4IRQUD.js} +3 -3
- package/dist/{chunk-523O5UYB.js.map → chunk-6G4IRQUD.js.map} +1 -1
- package/dist/{chunk-EVH3OUMY.js → chunk-BBJ77S62.js} +190 -44
- package/dist/chunk-BBJ77S62.js.map +1 -0
- package/dist/{chunk-PCLRIQPX.cjs → chunk-EQ5NCH2Y.cjs} +4 -4
- package/dist/{chunk-PCLRIQPX.cjs.map → chunk-EQ5NCH2Y.cjs.map} +1 -1
- package/dist/{chunk-TE6XVTOA.js → chunk-JLIRFWUG.js} +47 -17
- package/dist/chunk-JLIRFWUG.js.map +1 -0
- package/dist/{chunk-YEHQ3SIC.cjs → chunk-JV7JA7BM.cjs} +5 -5
- package/dist/{chunk-YEHQ3SIC.cjs.map → chunk-JV7JA7BM.cjs.map} +1 -1
- package/dist/chunk-LZJXEPEQ.js +58 -0
- package/dist/chunk-LZJXEPEQ.js.map +1 -0
- package/dist/{chunk-RTE2DD4S.js → chunk-MHIBYKWA.js} +127 -69
- package/dist/chunk-MHIBYKWA.js.map +1 -0
- package/dist/{chunk-WPO3VCY4.cjs → chunk-N7KS3TIR.cjs} +47 -17
- package/dist/chunk-N7KS3TIR.cjs.map +1 -0
- package/dist/chunk-NWS2CS3Y.cjs +61 -0
- package/dist/chunk-NWS2CS3Y.cjs.map +1 -0
- package/dist/{chunk-QY3CIMUV.cjs → chunk-P5N3Q2NH.cjs} +210 -62
- package/dist/chunk-P5N3Q2NH.cjs.map +1 -0
- package/dist/{chunk-EXI7EHDN.js → chunk-Q34EBNYG.js} +3 -3
- package/dist/{chunk-EXI7EHDN.js.map → chunk-Q34EBNYG.js.map} +1 -1
- package/dist/{chunk-HI3W37FY.js → chunk-U27XHOEF.js} +3 -3
- package/dist/{chunk-HI3W37FY.js.map → chunk-U27XHOEF.js.map} +1 -1
- package/dist/{compact-session-PVAWTKKL.js → compact-session-4HAUP3HK.js} +4 -4
- package/dist/{compact-session-PVAWTKKL.js.map → compact-session-4HAUP3HK.js.map} +1 -1
- package/dist/{compact-session-4QHBBGEY.cjs → compact-session-Y56D3S57.cjs} +13 -13
- package/dist/{compact-session-4QHBBGEY.cjs.map → compact-session-Y56D3S57.cjs.map} +1 -1
- package/dist/cron.cjs +8 -7
- package/dist/cron.js +7 -6
- package/dist/eval.cjs +7 -6
- package/dist/eval.cjs.map +1 -1
- package/dist/eval.js +6 -5
- package/dist/eval.js.map +1 -1
- package/dist/index.cjs +40 -130
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +11 -106
- package/dist/index.js.map +1 -1
- package/dist/{inject-session-O24XGRR6.js → inject-session-LJX5JGV5.js} +3 -3
- package/dist/{inject-session-O24XGRR6.js.map → inject-session-LJX5JGV5.js.map} +1 -1
- package/dist/{inject-session-OMLFL2V3.cjs → inject-session-R73PRM7B.cjs} +4 -4
- package/dist/{inject-session-OMLFL2V3.cjs.map → inject-session-R73PRM7B.cjs.map} +1 -1
- package/dist/internal/budget/normalize-usage.d.ts +81 -0
- package/dist/internal/error-mappers/openai-compatible.d.ts +3 -1
- package/dist/internal/llm/anthropic-shared.d.ts +6 -0
- package/dist/internal/llm/openai.d.ts +3 -5
- package/dist/internal/llm/openrouter-system.d.ts +1 -0
- package/dist/internal/llm/types.d.ts +10 -5
- package/dist/internal/memory/adapters/index.cjs +3 -3
- package/dist/internal/memory/adapters/index.js +2 -2
- package/dist/models.cjs +5 -50
- package/dist/models.cjs.map +1 -1
- package/dist/models.js +3 -51
- package/dist/models.js.map +1 -1
- package/docs/error-codes.md +8 -4
- package/package.json +1 -1
- package/dist/chunk-CVEQ5366.cjs.map +0 -1
- package/dist/chunk-EVH3OUMY.js.map +0 -1
- package/dist/chunk-QY3CIMUV.cjs.map +0 -1
- package/dist/chunk-RTE2DD4S.js.map +0 -1
- package/dist/chunk-TE6XVTOA.js.map +0 -1
- package/dist/chunk-WPO3VCY4.cjs.map +0 -1
|
@@ -73,6 +73,13 @@ function mapOpenAICompatibleError(args) {
|
|
|
73
73
|
if (status === 429) {
|
|
74
74
|
return new chunkUNFBHV46_cjs.RateLimitError(message, { code: `${providerId}_rate_limit`, metadata });
|
|
75
75
|
}
|
|
76
|
+
if (status === 404 && code === "model_unavailable") {
|
|
77
|
+
const detailed = formatMessage(providerId, status, code, extractOpenAiErrorMessage(body));
|
|
78
|
+
return new chunkUNFBHV46_cjs.ConfigurationError(detailed, {
|
|
79
|
+
code: `${providerId}_model_unavailable`,
|
|
80
|
+
metadata
|
|
81
|
+
});
|
|
82
|
+
}
|
|
76
83
|
if (status === 400) {
|
|
77
84
|
return new chunkUNFBHV46_cjs.ConfigurationError(message, { code: `${providerId}_${code}`, metadata });
|
|
78
85
|
}
|
|
@@ -92,24 +99,47 @@ function extractOpenAiErrorCode(body) {
|
|
|
92
99
|
if (typeof err.type === "string") return err.type;
|
|
93
100
|
return void 0;
|
|
94
101
|
}
|
|
102
|
+
function extractOpenAiErrorMessage(body) {
|
|
103
|
+
if (body === null || typeof body !== "object") return void 0;
|
|
104
|
+
const err = body.error;
|
|
105
|
+
if (err === void 0 || err === null) return void 0;
|
|
106
|
+
return typeof err.message === "string" ? err.message : void 0;
|
|
107
|
+
}
|
|
108
|
+
var MISSING_MODEL_MESSAGE = /no endpoints found/i;
|
|
95
109
|
function mapOpenAiStatusToCode(status, body) {
|
|
96
|
-
const
|
|
97
|
-
if (
|
|
98
|
-
|
|
99
|
-
}
|
|
100
|
-
if (rawCode.includes("content_filter") || rawCode.includes("content_policy") || rawCode.includes("safety")) {
|
|
101
|
-
return "content_filtered";
|
|
102
|
-
}
|
|
103
|
-
if (rawCode.includes("model_not_found") || rawCode.includes("model_unavailable") || rawCode.includes("invalid_model")) {
|
|
104
|
-
return "model_unavailable";
|
|
105
|
-
}
|
|
106
|
-
if (rawCode.includes("insufficient_quota") || rawCode.includes("quota_exceeded")) {
|
|
107
|
-
return "quota_exceeded";
|
|
108
|
-
}
|
|
110
|
+
const fromBodyCode = classifyOpenAiBodyCode(extractOpenAiErrorCode(body)?.toLowerCase() ?? "");
|
|
111
|
+
if (fromBodyCode !== void 0) return fromBodyCode;
|
|
112
|
+
if (isMissingModel404(status, body)) return "model_unavailable";
|
|
109
113
|
return httpStatusToErrorCode(status);
|
|
110
114
|
}
|
|
111
|
-
function
|
|
112
|
-
return
|
|
115
|
+
function isMissingModel404(status, body) {
|
|
116
|
+
return status === 404 && MISSING_MODEL_MESSAGE.test(extractOpenAiErrorMessage(body) ?? "");
|
|
117
|
+
}
|
|
118
|
+
var BODY_CODE_RULES = [
|
|
119
|
+
{
|
|
120
|
+
fragments: ["context_length", "context_window", "too_many_tokens", "max_tokens"],
|
|
121
|
+
code: "context_too_long"
|
|
122
|
+
},
|
|
123
|
+
{ fragments: ["content_filter", "content_policy", "safety"], code: "content_filtered" },
|
|
124
|
+
{
|
|
125
|
+
fragments: ["model_not_found", "model_unavailable", "invalid_model"],
|
|
126
|
+
code: "model_unavailable"
|
|
127
|
+
},
|
|
128
|
+
// T3.7 — OpenRouter "Insufficient credits" / `insufficient_quota` in the BODY.
|
|
129
|
+
// The status-402 half of this rule moved to the shared ladder, where it now
|
|
130
|
+
// reaches all four mappers instead of this one; what stays here is the part
|
|
131
|
+
// that is genuinely a body dialect.
|
|
132
|
+
{ fragments: ["insufficient_quota", "quota_exceeded"], code: "quota_exceeded" }
|
|
133
|
+
];
|
|
134
|
+
function classifyOpenAiBodyCode(rawCode) {
|
|
135
|
+
const rule = BODY_CODE_RULES.find(
|
|
136
|
+
({ fragments }) => fragments.some((fragment) => rawCode.includes(fragment))
|
|
137
|
+
);
|
|
138
|
+
return rule?.code;
|
|
139
|
+
}
|
|
140
|
+
function formatMessage(providerId, status, code, detail) {
|
|
141
|
+
const base = `${providerId} API error: ${code} (HTTP ${status})`;
|
|
142
|
+
return detail === void 0 || detail === "" ? base : `${base}: ${detail}`;
|
|
113
143
|
}
|
|
114
144
|
|
|
115
145
|
exports.buildErrorMetadata = buildErrorMetadata;
|
|
@@ -117,5 +147,5 @@ exports.httpStatusToErrorCode = httpStatusToErrorCode;
|
|
|
117
147
|
exports.mapOpenAICompatibleError = mapOpenAICompatibleError;
|
|
118
148
|
exports.parseErrorBody = parseErrorBody;
|
|
119
149
|
exports.parseRetryAfter = parseRetryAfter;
|
|
120
|
-
//# sourceMappingURL=chunk-
|
|
121
|
-
//# sourceMappingURL=chunk-
|
|
150
|
+
//# sourceMappingURL=chunk-N7KS3TIR.cjs.map
|
|
151
|
+
//# sourceMappingURL=chunk-N7KS3TIR.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/internal/error-mappers/shared.ts","../src/internal/error-mappers/openai-compatible.ts"],"names":["redactSecrets","AuthenticationError","RateLimitError","ConfigurationError","NetworkError","UnknownAgentError"],"mappings":";;;;;;AAcA,IAAM,aAAA,GAAgB,IAAA;AAUf,SAAS,gBAAgB,OAAA,EAAkD;AAChF,EAAA,IAAI,OAAA,KAAY,QAAW,OAAO,MAAA;AAClC,EAAA,MAAM,GAAA,GAAM,OAAA,CAAQ,GAAA,CAAI,aAAa,CAAA;AACrC,EAAA,IAAI,GAAA,KAAQ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\nimport type { ErrorCode } from \"../../errors.js\";\n * Helpers shared between provider HTTP error mappers (ADR D67).\n *\n * Extracted to dedupe identical logic in `anthropic.ts` and\n * `openai-compatible.ts` — retry-after parsing, raw-body truncation,\n * and metadata assembly are dialect-agnostic.\n *\n * @internal\n */\n\nimport type { ErrorCode, ErrorMetadata } from \"../../errors.js\";\nimport { redactSecrets } from \"../security/index.js\";\n\nconst RAW_MAX_BYTES = 2048;\n\n/**\n * Parse the `Retry-After` header (RFC 7231) into seconds. Both forms are\n * supported: numeric-seconds (`Retry-After: 30`) and HTTP-date\n * (`Retry-After: Wed, 21 Oct 2025 07:28:00 GMT` → seconds until that instant,\n * clamped at 0 for a past date). Garbage / missing header → `undefined`.\n *\n * @internal\n */\nexport function parseRetryAfter(headers: Headers | undefined): number | undefined {\n if (headers === undefined) return undefined;\n const raw = headers.get(\"retry-after\");\n if (raw === null) return undefined;\n const n = Number(raw);\n if (Number.isFinite(n) && n >= 0) return Math.ceil(n);\n // HTTP-date form — seconds until the given instant (0 if already elapsed).\n const dateMs = Date.parse(raw);\n if (Number.isFinite(dateMs)) return Math.max(0, Math.ceil((dateMs - Date.now()) / 1000));\n return undefined;\n}\n\n/**\n * Truncate raw response body to ~2KB and redact known credential\n * patterns so it can ride inside `ErrorMetadata.raw` without\n * ballooning logs OR leaking tokens. Returns `undefined` for\n * null/undefined input.\n *\n * Post T1.1 (secret-redaction-discipline, ADR D68): every error metadata\n * goes through `redactSecrets` before exposure. Note the shape change —\n * pre-T1.1 the function preserved the original `body` shape when ≤2KB;\n * now it always returns a (possibly redacted) string, because redaction\n * coerces non-strings to JSON. Consumers who used to do `err.metadata.raw.foo`\n * must now `JSON.parse(err.metadata.raw)` first — but a workspace-wide\n * grep at T1.1 land time confirmed zero such callers.\n *\n * @internal\n */\nexport function truncateRaw(body: unknown): unknown {\n if (body === null || body === undefined) return undefined;\n const s = typeof body === \"string\" ? body : JSON.stringify(body);\n const truncated = s.length <= RAW_MAX_BYTES ? s : `${s.slice(0, RAW_MAX_BYTES)}…`;\n return redactSecrets(truncated);\n}\n\n/**\n * Build an `ErrorMetadata` object with all optional fields included\n * conditionally (no `undefined` keys in the output). Caller passes\n * dialect-specific fields (`provider`, `endpoint`, `code`); shared\n * fields (`statusCode`, `retryAfter`, `raw`) are derived here.\n *\n * @internal\n */\nexport function buildErrorMetadata(args: {\n provider: string;\n endpoint: string;\n code: ErrorCode;\n status: number;\n headers: Headers | undefined;\n body: unknown;\n}): ErrorMetadata {\n const retryAfter = parseRetryAfter(args.headers);\n const raw = truncateRaw(args.body);\n return {\n provider: args.provider,\n endpoint: args.endpoint,\n code: args.code,\n statusCode: args.status,\n ...(retryAfter !== undefined ? { retryAfter } : {}),\n ...(raw !== undefined ? { raw } : {}),\n };\n}\n\n/**\n * D314: extract the provider's request id (`x-request-id` is OpenAI/most;\n * `request-id` is Anthropic). Returns `undefined` when neither is present.\n *\n * @internal\n */\nexport function parseRequestId(headers: Headers | undefined): string | undefined {\n if (headers === undefined) return undefined;\n return headers.get(\"x-request-id\") ?? headers.get(\"request-id\") ?? undefined;\n}\n\n/**\n * The HTTP status ladder — ONE definition, shared by every provider mapper.\n *\n * This is RFC 9110 semantics, not a vendor contract: a 429 means the same thing\n * whether Anthropic, OpenAI, Bedrock or Vertex sent it. It lived in four copies\n * until 2026-09-01 and the copies had already drifted in two measurable ways,\n * which is what moved it here beside the other dialect-agnostic helpers ADR D67\n * extracted:\n *\n * 1. **402 reached one mapper of four.** T3.7 added `quota_exceeded` and wired\n * it into `openai-compatible.ts` only. A Bedrock, Vertex or Anthropic\n * endpoint answering 402 fell through every arm and came back `unknown` —\n * the canonical bucket existed and three of four mappers could not reach it.\n * 2. **The 5xx arm had two different upper bounds.** `anthropic` and\n * `openai-compatible` guarded `>= 500 && < 600`; `bedrock` and `vertex`\n * guarded `>= 500` with no ceiling, so a malformed or proxy-injected 6xx was\n * `server_error` in two mappers and `unknown` in the other two.\n *\n * Neither was a vendor difference. Both were copy-drift, and that is the DRY\n * test in its textbook form: one piece of knowledge, four places to change it.\n *\n * The ladder is deliberately the FALLBACK, never the whole classifier. Each\n * mapper keeps its own body-dialect rules — Anthropic's `context_too_long`,\n * Bedrock's AWS `__type` strings, Vertex's `google.rpc` status enum — because\n * those ARE per-vendor contracts. The shape is\n * `classifyVendorBody(body) ?? httpStatusToErrorCode(status)`.\n *\n * 404 is deliberately NOT mapped here. Three mappers treat it as `unknown` and\n * Bedrock treats it as `invalid_request` via its own `__type` rules; folding it\n * in would silently change three mappers to close a divergence nobody measured.\n *\n * @internal\n */\nexport type HttpStatusErrorCode = Extract<\n ErrorCode,\n | \"auth_failed\"\n | \"quota_exceeded\"\n | \"timeout\"\n | \"rate_limit\"\n | \"invalid_request\"\n | \"server_error\"\n | \"unknown\"\n>;\n\nexport function httpStatusToErrorCode(status: number): HttpStatusErrorCode {\n if (status === 401 || status === 403) return \"auth_failed\";\n if (status === 402) return \"quota_exceeded\";\n if (status === 408) return \"timeout\";\n if (status === 429) return \"rate_limit\";\n if (status === 400) return \"invalid_request\";\n if (status >= 500 && status < 600) return \"server_error\";\n return \"unknown\";\n}\n\n/**\n * Reads an error body that may arrive already parsed, as a JSON string, or as neither.\n *\n * This is TRANSPORT knowledge, not vendor knowledge: it describes how `fetch` surfaces a body, which\n * is the same whichever provider sent it. It lived twice, character-for-character, in bedrock.ts and\n * vertex.ts — identical once the return type name was substituted. They had not drifted, so the cost\n * was only latent: a fix to one would have missed the other silently.\n *\n * Unparseable input yields `{}` rather than throwing, because a mapper's job is to classify a\n * failure that already happened; failing to read the body is not a second failure to report.\n */\nexport function parseErrorBody<T>(body: unknown): T {\n if (body !== null && typeof body === \"object\") return body as T;\n if (typeof body === \"string\") {\n try {\n return JSON.parse(body) as T;\n } catch {\n return {} as T;\n }\n }\n return {} as T;\n}\n","/**\n * OpenAI-compatible HTTP error mapper (ADR D67).\n *\n * Translates OpenAI-shaped API error responses (covers OpenAI, OpenRouter,\n * DeepSeek, Together, Mistral, Voyage, DeepInfra, etc.) into typed\n * `TheokitAgentError` subclasses with full `ErrorMetadata`.\n *\n * Body inspection: looks at `body.error.code` / `body.error.type` to detect\n * `context_too_long`, `content_filtered`, `model_unavailable` semantics, and at\n * `body.error.message` for a 404 that says no endpoint serves the model\n * (OpenRouter's numeric-code body for a retired model id).\n * Falls back to status-based mapping when body doesn't expose `.error`\n * (e.g., HTML server error page, DeepInfra's `{message: \"...\"}` shape).\n *\n * Never throws — caller is already in an error path.\n *\n * @internal\n */\n\nimport {\n AuthenticationError,\n ConfigurationError,\n type ErrorCode,\n NetworkError,\n RateLimitError,\n type TheokitAgentError,\n UnknownAgentError,\n} from \"../../errors.js\";\nimport { buildErrorMetadata, httpStatusToErrorCode } from \"./shared.js\";\n\ninterface MapOpenAiErrorArgs {\n providerId: string;\n status: number;\n body: unknown;\n headers: Headers | undefined;\n endpoint: string;\n}\n\nexport function mapOpenAICompatibleError(args: MapOpenAiErrorArgs): TheokitAgentError {\n const { providerId, status, body, headers, endpoint } = args;\n const code = mapOpenAiStatusToCode(status, body);\n const message = formatMessage(providerId, status, code);\n const metadata = buildErrorMetadata({\n provider: providerId,\n endpoint,\n code,\n status,\n headers,\n body,\n });\n\n if (status === 401 || status === 403) {\n return new AuthenticationError(message, { code: `${providerId}_auth_failed`, metadata });\n }\n if (status === 429) {\n return new RateLimitError(message, { code: `${providerId}_rate_limit`, metadata });\n }\n if (status === 404 && code === \"model_unavailable\") {\n // The model id lives only in the provider's text, so this case carries it.\n const detailed = formatMessage(providerId, status, code, extractOpenAiErrorMessage(body));\n return new ConfigurationError(detailed, {\n code: `${providerId}_model_unavailable`,\n metadata,\n });\n }\n if (status === 400) {\n return new ConfigurationError(message, { code: `${providerId}_${code}`, metadata });\n }\n if (status === 408) {\n return new NetworkError(message, { code: `${providerId}_timeout`, metadata });\n }\n if (status >= 500 && status < 600) {\n return new NetworkError(message, { code: `${providerId}_server_error`, metadata });\n }\n return new UnknownAgentError(message, { code: `${providerId}_unknown`, metadata });\n}\n\nfunction extractOpenAiErrorCode(body: unknown): string | undefined {\n if (body === null || typeof body !== \"object\") return undefined;\n const err = (body as { error?: { code?: unknown; type?: unknown } }).error;\n if (err === undefined || err === null) return undefined;\n if (typeof err.code === \"string\") return err.code;\n if (typeof err.type === \"string\") return err.type;\n return undefined;\n}\n\nfunction extractOpenAiErrorMessage(body: unknown): string | undefined {\n if (body === null || typeof body !== \"object\") return undefined;\n const err = (body as { error?: { message?: unknown } }).error;\n if (err === undefined || err === null) return undefined;\n return typeof err.message === \"string\" ? err.message : undefined;\n}\n\n// OpenRouter answers a model it does not serve with HTTP 404 and a numeric `error.code`,\n// so only the message tells it apart from a 404 for a wrong path (measured 2026-10-20).\nconst MISSING_MODEL_MESSAGE = /no endpoints found/i;\n\nfunction mapOpenAiStatusToCode(status: number, body: unknown): ErrorCode {\n const fromBodyCode = classifyOpenAiBodyCode(extractOpenAiErrorCode(body)?.toLowerCase() ?? \"\");\n if (fromBodyCode !== undefined) return fromBodyCode;\n if (isMissingModel404(status, body)) return \"model_unavailable\";\n\n // Everything below the body dialect is RFC 9110 and lives once, in shared.ts.\n return httpStatusToErrorCode(status);\n}\n\nfunction isMissingModel404(status: number, body: unknown): boolean {\n return status === 404 && MISSING_MODEL_MESSAGE.test(extractOpenAiErrorMessage(body) ?? \"\");\n}\n\n// The body dialect, in precedence order: the first rule whose fragment appears in the\n// lowercased body code wins.\nconst BODY_CODE_RULES: ReadonlyArray<{ fragments: readonly string[]; code: ErrorCode }> = [\n {\n fragments: [\"context_length\", \"context_window\", \"too_many_tokens\", \"max_tokens\"],\n code: \"context_too_long\",\n },\n { fragments: [\"content_filter\", \"content_policy\", \"safety\"], code: \"content_filtered\" },\n {\n fragments: [\"model_not_found\", \"model_unavailable\", \"invalid_model\"],\n code: \"model_unavailable\",\n },\n // T3.7 — OpenRouter \"Insufficient credits\" / `insufficient_quota` in the BODY.\n // The status-402 half of this rule moved to the shared ladder, where it now\n // reaches all four mappers instead of this one; what stays here is the part\n // that is genuinely a body dialect.\n { fragments: [\"insufficient_quota\", \"quota_exceeded\"], code: \"quota_exceeded\" },\n];\n\nfunction classifyOpenAiBodyCode(rawCode: string): ErrorCode | undefined {\n const rule = BODY_CODE_RULES.find(({ fragments }) =>\n fragments.some((fragment) => rawCode.includes(fragment)),\n );\n return rule?.code;\n}\n\nfunction formatMessage(\n providerId: string,\n status: number,\n code: ErrorCode,\n detail?: string,\n): string {\n const base = `${providerId} API error: ${code} (HTTP ${status})`;\n return detail === undefined || detail === \"\" ? base : `${base}: ${detail}`;\n}\n"]}
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var chunkHU666T3Q_cjs = require('./chunk-HU666T3Q.cjs');
|
|
4
|
+
|
|
5
|
+
// src/internal/llm/model-capabilities.ts
|
|
6
|
+
var CONSERVATIVE_DEFAULTS = {
|
|
7
|
+
supportsVision: false,
|
|
8
|
+
supportsStructuredOutput: false,
|
|
9
|
+
supportsToolUse: false,
|
|
10
|
+
supportsCacheControl: false,
|
|
11
|
+
maxContextTokens: 4096,
|
|
12
|
+
maxOutputTokens: 4096
|
|
13
|
+
};
|
|
14
|
+
var ROUTING_PREFIXES = ["openrouter/", "vertex/", "bedrock/"];
|
|
15
|
+
function capsFromCatalog(m) {
|
|
16
|
+
return {
|
|
17
|
+
supportsVision: m.modalities?.input?.includes("image") ?? m.attachment ?? false,
|
|
18
|
+
supportsStructuredOutput: m.structured_output ?? false,
|
|
19
|
+
supportsToolUse: m.tool_call ?? false,
|
|
20
|
+
supportsCacheControl: m.cache_control ?? false,
|
|
21
|
+
maxContextTokens: m.limit?.context ?? CONSERVATIVE_DEFAULTS.maxContextTokens,
|
|
22
|
+
maxOutputTokens: m.limit?.output ?? CONSERVATIVE_DEFAULTS.maxOutputTokens
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
function resolveModelCapabilities(modelId) {
|
|
26
|
+
const bare = stripVariantSuffix(stripRoutingPrefix(modelId));
|
|
27
|
+
const fromIndex = chunkHU666T3Q_cjs.getCatalogModelInfo(bare);
|
|
28
|
+
if (fromIndex !== void 0) return capsFromCatalog(fromIndex);
|
|
29
|
+
const withVendor = inferVendorPrefix(bare);
|
|
30
|
+
if (withVendor !== bare) {
|
|
31
|
+
const vendored = chunkHU666T3Q_cjs.getCatalogModelInfo(withVendor);
|
|
32
|
+
if (vendored !== void 0) return capsFromCatalog(vendored);
|
|
33
|
+
}
|
|
34
|
+
return CONSERVATIVE_DEFAULTS;
|
|
35
|
+
}
|
|
36
|
+
function isAnthropicFamilyModel(modelId) {
|
|
37
|
+
if (modelId === void 0) return false;
|
|
38
|
+
return /^(anthropic\/|claude)/.test(stripRoutingPrefix(modelId));
|
|
39
|
+
}
|
|
40
|
+
function stripRoutingPrefix(modelId) {
|
|
41
|
+
for (const prefix of ROUTING_PREFIXES) {
|
|
42
|
+
if (modelId.startsWith(prefix)) return modelId.slice(prefix.length);
|
|
43
|
+
}
|
|
44
|
+
return modelId;
|
|
45
|
+
}
|
|
46
|
+
function stripVariantSuffix(modelId) {
|
|
47
|
+
const i = modelId.indexOf(":");
|
|
48
|
+
return i >= 0 ? modelId.slice(0, i) : modelId;
|
|
49
|
+
}
|
|
50
|
+
function inferVendorPrefix(bare) {
|
|
51
|
+
if (bare.startsWith("claude")) return `anthropic/${bare}`;
|
|
52
|
+
if (bare.startsWith("gpt-") || bare.startsWith("o1") || bare.startsWith("o3"))
|
|
53
|
+
return `openai/${bare}`;
|
|
54
|
+
if (bare.startsWith("gemini")) return `google/${bare}`;
|
|
55
|
+
return bare;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
exports.isAnthropicFamilyModel = isAnthropicFamilyModel;
|
|
59
|
+
exports.resolveModelCapabilities = resolveModelCapabilities;
|
|
60
|
+
//# sourceMappingURL=chunk-NWS2CS3Y.cjs.map
|
|
61
|
+
//# sourceMappingURL=chunk-NWS2CS3Y.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version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;AAC/C,IAAA,IAAI,QAAA,KAAa,MAAA,EAAW,OAAO,eAAA,CAAgB,QAAQ,CAAA;AAAA,EAC7D;AACA,EAAA,OAAO,qBAAA;AACT;AAUO,SAAS,uBAAuB,OAAA,EAAsC;AAC3E,EAAA,IAAI,OAAA,KAAY,QAAW,OAAO,KAAA;AAClC,EAAA,OAAO,uBAAA,CAAwB,IAAA,CAAK,kBAAA,CAAmB,OAAO,CAAC,CAAA;AACjE;AAEA,SAAS,mBAAmB,OAAA,EAAyB;AACnD,EAAA,KAAA,MAAW,UAAU,gBAAA,EAAkB;AACrC,IAAA,IAAI,OAAA,CAAQ,WAAW,MAAM,CAAA,SAAU,OAAA,CAAQ,KAAA,CAAM,OAAO,MAAM,CAAA;AAAA,EACpE;AACA,EAAA,OAAO,OAAA;AACT;AAOA,SAAS,mBAAmB,OAAA,EAAyB;AACnD,EAAA,MAAM,CAAA,GAAI,OAAA,CAAQ,OAAA,CAAQ,GAAG,CAAA;AAC7B,EAAA,OAAO,KAAK,CAAA,GAAI,OAAA,CAAQ,KAAA,CAAM,CAAA,EAAG,CAAC,CAAA,GAAI,OAAA;AACxC;AAGA,SAAS,kBAAkB,IAAA,EAAsB;AAC/C,EAAA,IAAI,KAAK,UAAA,CAAW,QAAQ,CAAA,EAAG,OAAO,aAAa,IAAI,CAAA,CAAA;AACvD,EAAA,IAAI,IAAA,CAAK,UAAA,CAAW,MAAM,CAAA,IAAK,IAAA,CAAK,WAAW,IAAI,CAAA,IAAK,IAAA,CAAK,UAAA,CAAW,IAAI,CAAA;AAC1E,IAAA,OAAO,UAAU,IAAI,CAAA,CAAA;AACvB,EAAA,IAAI,KAAK,UAAA,CAAW,QAAQ,CAAA,EAAG,OAAO,UAAU,IAAI,CAAA,CAAA;AACpD,EAAA,OAAO,IAAA;AACT","file":"chunk-NWS2CS3Y.cjs","sourcesContent":["/**\n * T3.10c — Model capability registry (DR3 #17).\n *\n * Typed per-model flags that let the SDK gate features at the boundary\n * (before hitting the provider) instead of letting opaque 400s surface.\n *\n * Resolution algorithm:\n * 1. Strip routing prefixes (openrouter/, vertex/, bedrock/) AND the\n * OpenRouter `:variant` suffix (:free/:nitro/…) to find the bare vendor id.\n * 2. Exact match in the `EXACT` catalog → return entry.\n * 3. Vendor inference (e.g., `claude-*` → `anthropic/claude-*`) → return entry.\n * 4. No match → conservative defaults (all false, minimum tokens).\n *\n * Module is internal, but `ModelCapabilities` + `resolveModelCapabilities` are\n * re-exported publicly via the `@theokit/sdk/models` subpath (see their @public tags).\n */\n\n/**\n * Per-model capability shape. Consumers use this to gate features at\n * the SDK boundary (before request construction, not after 400).\n *\n * @public\n */\nexport interface ModelCapabilities {\n supportsVision: boolean;\n supportsStructuredOutput: boolean;\n supportsToolUse: boolean;\n supportsCacheControl: boolean;\n maxContextTokens: number;\n maxOutputTokens: number;\n}\n\nconst CONSERVATIVE_DEFAULTS: ModelCapabilities = {\n supportsVision: false,\n supportsStructuredOutput: false,\n supportsToolUse: false,\n supportsCacheControl: false,\n maxContextTokens: 4096,\n maxOutputTokens: 4096,\n};\n\n/** Routing prefixes to strip to find the underlying vendor model. */\nconst ROUTING_PREFIXES = [\"openrouter/\", \"vertex/\", \"bedrock/\"] as const;\n\nimport { getCatalogModelInfo } from \"../providers/catalog-loader.js\";\nimport type { CatalogModel } from \"../providers/catalog-schema.js\";\n\n/** Map a catalog model block (models.dev shape) to the SDK's ModelCapabilities (M44 — catalog-backed). */\nfunction capsFromCatalog(m: CatalogModel): ModelCapabilities {\n return {\n supportsVision: m.modalities?.input?.includes(\"image\") ?? m.attachment ?? false,\n supportsStructuredOutput: m.structured_output ?? false,\n supportsToolUse: m.tool_call ?? false,\n supportsCacheControl: (m as { cache_control?: boolean }).cache_control ?? false,\n maxContextTokens: m.limit?.context ?? CONSERVATIVE_DEFAULTS.maxContextTokens,\n maxOutputTokens: m.limit?.output ?? CONSERVATIVE_DEFAULTS.maxOutputTokens,\n };\n}\n\n/**\n * Resolve per-model capability flags (vision/structured-output/tool-use/cache +\n * `maxContextTokens`/`maxOutputTokens`) for a model id. Pure, sync, offline (a\n * static catalog — no network). Strips routing prefixes (`openrouter/`/`vertex/`/\n * `bedrock/`) and OpenRouter `:variant` suffixes before lookup; unknown models get\n * conservative defaults. Public via `@theokit/sdk/models`.\n *\n * @public\n */\nexport function resolveModelCapabilities(modelId: string): ModelCapabilities {\n const bare = stripVariantSuffix(stripRoutingPrefix(modelId));\n // M44 — the catalog model-info index replaced the hand-curated EXACT map (single source of truth; the\n // vendored provider-catalog.json carries the migrated data — parity-tested against the old map snapshot).\n const fromIndex = getCatalogModelInfo(bare);\n if (fromIndex !== undefined) return capsFromCatalog(fromIndex);\n // Routing-prefixed models (vertex/claude-3-5-sonnet) strip to bare\n // model name without vendor. Try inferring the vendor from the name.\n const withVendor = inferVendorPrefix(bare);\n if (withVendor !== bare) {\n const vendored = getCatalogModelInfo(withVendor);\n if (vendored !== undefined) return capsFromCatalog(vendored);\n }\n return CONSERVATIVE_DEFAULTS;\n}\n\n/**\n * B-412 / B-475 — whether a model id names an Anthropic model the loop sends cacheable system\n * blocks to. Decided by the id, not by the catalog's `supportsCacheControl`, which is false for the\n * Anthropic ids measured on OpenRouter. After the same routing prefixes the capability lookup\n * strips (`openrouter/`, `vertex/`, `bedrock/`), the id must start with `anthropic/` or `claude`,\n * so Vertex Anthropic ids match and Bedrock ids (`anthropic.claude-…`) do not.\n * @internal\n */\nexport function isAnthropicFamilyModel(modelId: string | undefined): boolean {\n if (modelId === undefined) return false;\n return /^(anthropic\\/|claude)/.test(stripRoutingPrefix(modelId));\n}\n\nfunction stripRoutingPrefix(modelId: string): string {\n for (const prefix of ROUTING_PREFIXES) {\n if (modelId.startsWith(prefix)) return modelId.slice(prefix.length);\n }\n return modelId;\n}\n\n/**\n * Strip an OpenRouter variant suffix (`:free`/`:nitro`/`:floor`/`:beta`/…) so the\n * catalog lookup hits the underlying model. Model slugs contain no `:` except the\n * variant separator, so cutting at the first `:` is safe.\n */\nfunction stripVariantSuffix(modelId: string): string {\n const i = modelId.indexOf(\":\");\n return i >= 0 ? modelId.slice(0, i) : modelId;\n}\n\n/** Infer vendor prefix from bare model name for routing-prefixed lookups. */\nfunction inferVendorPrefix(bare: string): string {\n if (bare.startsWith(\"claude\")) return `anthropic/${bare}`;\n if (bare.startsWith(\"gpt-\") || bare.startsWith(\"o1\") || bare.startsWith(\"o3\"))\n return `openai/${bare}`;\n if (bare.startsWith(\"gemini\")) return `google/${bare}`;\n return bare;\n}\n"]}
|