@broberg/ai-sdk 0.11.0 → 0.12.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/chunk-HVZSYNZ5.js +141 -0
- package/dist/chunk-HVZSYNZ5.js.map +1 -0
- package/dist/index.d.ts +4 -71
- package/dist/index.js +11 -134
- package/dist/index.js.map +1 -1
- package/dist/registry.d.ts +69 -0
- package/dist/registry.js +11 -0
- package/dist/registry.js.map +1 -0
- package/package.json +5 -1
|
@@ -0,0 +1,141 @@
|
|
|
1
|
+
// src/availability/registry.ts
|
|
2
|
+
var SUSPENDED_FABLE_MYTHOS = "suspended \u2014 US export-control directive (2026-06-12)";
|
|
3
|
+
var DEFAULTS = [
|
|
4
|
+
// ── Anthropic ────────────────────────────────────────────────────────────
|
|
5
|
+
{ id: "claude-haiku-4-5", aliases: ["haiku", "fast"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
6
|
+
{ id: "claude-sonnet-4-6", aliases: ["sonnet", "smart"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
7
|
+
{ id: "claude-opus-4-8", aliases: ["opus", "powerful"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
8
|
+
{ id: "claude-fable-5", aliases: ["fable"], provider: "anthropic", available: false, status: "suspended", note: SUSPENDED_FABLE_MYTHOS, source: "default" },
|
|
9
|
+
{ id: "claude-mythos-5", aliases: ["mythos"], provider: "anthropic", available: false, status: "suspended", note: SUSPENDED_FABLE_MYTHOS, source: "default" },
|
|
10
|
+
// ── Gemini ───────────────────────────────────────────────────────────────
|
|
11
|
+
{ id: "gemini-2.5-flash", aliases: ["gemini-flash"], provider: "gemini", available: true, status: "available", source: "default" },
|
|
12
|
+
{ id: "gemini-2.5-flash-lite", aliases: ["gemini-flash-lite", "video"], provider: "gemini", available: true, status: "available", source: "default" },
|
|
13
|
+
// ── OpenAI ───────────────────────────────────────────────────────────────
|
|
14
|
+
{ id: "text-embedding-3-small", aliases: ["embedding"], provider: "openai", available: true, status: "available", source: "default" },
|
|
15
|
+
// ── Mistral (EU / GDPR) ──────────────────────────────────────────────────
|
|
16
|
+
{ id: "mistral-large-latest", aliases: ["mistral-large"], provider: "mistral", available: true, status: "available", source: "default" },
|
|
17
|
+
{ id: "mistral-small-latest", aliases: ["mistral-small"], provider: "mistral", available: true, status: "available", source: "default" }
|
|
18
|
+
];
|
|
19
|
+
var OVERLAY = /* @__PURE__ */ new Map();
|
|
20
|
+
var ALIAS_INDEX = /* @__PURE__ */ new Map();
|
|
21
|
+
function seed() {
|
|
22
|
+
OVERLAY = new Map(DEFAULTS.map((e) => [e.id, { ...e, aliases: [...e.aliases] }]));
|
|
23
|
+
ALIAS_INDEX = /* @__PURE__ */ new Map();
|
|
24
|
+
for (const e of DEFAULTS) for (const a of e.aliases) ALIAS_INDEX.set(a, e.id);
|
|
25
|
+
}
|
|
26
|
+
seed();
|
|
27
|
+
function resetRegistry() {
|
|
28
|
+
seed();
|
|
29
|
+
}
|
|
30
|
+
function canonicalId(requested) {
|
|
31
|
+
if (OVERLAY.has(requested)) return requested;
|
|
32
|
+
return ALIAS_INDEX.get(requested) ?? null;
|
|
33
|
+
}
|
|
34
|
+
function getEntry(requested) {
|
|
35
|
+
const id = canonicalId(requested);
|
|
36
|
+
return id ? OVERLAY.get(id) : void 0;
|
|
37
|
+
}
|
|
38
|
+
function allEntries(provider) {
|
|
39
|
+
const rows = [];
|
|
40
|
+
for (const e of OVERLAY.values()) {
|
|
41
|
+
if (provider && e.provider !== provider) continue;
|
|
42
|
+
rows.push({
|
|
43
|
+
id: e.id,
|
|
44
|
+
alias: e.aliases[0],
|
|
45
|
+
provider: e.provider,
|
|
46
|
+
available: e.available,
|
|
47
|
+
status: e.status,
|
|
48
|
+
note: e.note,
|
|
49
|
+
source: e.source
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
return rows;
|
|
53
|
+
}
|
|
54
|
+
function providerIds(provider) {
|
|
55
|
+
return [...OVERLAY.values()].filter((e) => e.provider === provider).map((e) => e.id);
|
|
56
|
+
}
|
|
57
|
+
function setAvailability(id, available, note) {
|
|
58
|
+
const e = OVERLAY.get(id);
|
|
59
|
+
if (!e) return;
|
|
60
|
+
e.available = available;
|
|
61
|
+
e.status = available ? "available" : "suspended";
|
|
62
|
+
e.source = "refresh";
|
|
63
|
+
if (note !== void 0) e.note = note;
|
|
64
|
+
else if (available) e.note = void 0;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// src/availability/types.ts
|
|
68
|
+
var ModelUnavailableError = class extends Error {
|
|
69
|
+
code = "model_unavailable";
|
|
70
|
+
requested;
|
|
71
|
+
provider;
|
|
72
|
+
note;
|
|
73
|
+
constructor(requested, note, provider) {
|
|
74
|
+
super(`model "${requested}" is unavailable${note ? ` (${note})` : ""}`);
|
|
75
|
+
this.name = "ModelUnavailableError";
|
|
76
|
+
this.requested = requested;
|
|
77
|
+
this.note = note;
|
|
78
|
+
this.provider = provider;
|
|
79
|
+
}
|
|
80
|
+
};
|
|
81
|
+
|
|
82
|
+
// src/availability/resolve.ts
|
|
83
|
+
function listModels(opts = {}) {
|
|
84
|
+
return allEntries(opts.provider);
|
|
85
|
+
}
|
|
86
|
+
function isAvailable(requested) {
|
|
87
|
+
const e = getEntry(requested);
|
|
88
|
+
return e ? e.available : true;
|
|
89
|
+
}
|
|
90
|
+
function resolveModel(requested, opts = {}) {
|
|
91
|
+
const id = canonicalId(requested) ?? requested;
|
|
92
|
+
const entry = getEntry(requested);
|
|
93
|
+
const provider = opts.provider ?? entry?.provider;
|
|
94
|
+
if (isAvailable(requested)) {
|
|
95
|
+
return {
|
|
96
|
+
ok: true,
|
|
97
|
+
model: id,
|
|
98
|
+
requested: id,
|
|
99
|
+
provider,
|
|
100
|
+
fellBack: false,
|
|
101
|
+
status: entry?.status ?? "unknown"
|
|
102
|
+
};
|
|
103
|
+
}
|
|
104
|
+
const chain = opts.fallback === void 0 ? [] : Array.isArray(opts.fallback) ? opts.fallback : [opts.fallback];
|
|
105
|
+
for (const fb of chain) {
|
|
106
|
+
if (isAvailable(fb)) {
|
|
107
|
+
const fbId = canonicalId(fb) ?? fb;
|
|
108
|
+
return {
|
|
109
|
+
ok: false,
|
|
110
|
+
model: fbId,
|
|
111
|
+
requested: id,
|
|
112
|
+
provider,
|
|
113
|
+
fellBack: true,
|
|
114
|
+
status: entry?.status ?? "suspended",
|
|
115
|
+
reason: entry?.note ?? `${id} is unavailable`
|
|
116
|
+
};
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
if (opts.throwIfUnavailable) {
|
|
120
|
+
throw new ModelUnavailableError(id, entry?.note, provider);
|
|
121
|
+
}
|
|
122
|
+
return {
|
|
123
|
+
ok: false,
|
|
124
|
+
model: id,
|
|
125
|
+
requested: id,
|
|
126
|
+
provider,
|
|
127
|
+
fellBack: false,
|
|
128
|
+
status: entry?.status ?? "suspended",
|
|
129
|
+
reason: entry?.note ?? `${id} is unavailable`
|
|
130
|
+
};
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
export {
|
|
134
|
+
resetRegistry,
|
|
135
|
+
providerIds,
|
|
136
|
+
setAvailability,
|
|
137
|
+
ModelUnavailableError,
|
|
138
|
+
listModels,
|
|
139
|
+
resolveModel
|
|
140
|
+
};
|
|
141
|
+
//# sourceMappingURL=chunk-HVZSYNZ5.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/availability/registry.ts","../src/availability/types.ts","../src/availability/resolve.ts"],"sourcesContent":["// F022 — the model-availability registry: the ONE source both resolveModel()\n// (spawn / call path) and listModels() (UI picker) read. A curated default seed\n// (works offline — the durable floor) plus a mutable overlay that\n// refreshAvailability() updates from the live provider list.\n//\n// Scope note: this is a LIVENESS view (is this id alive right now?), not the\n// rich capability/price inventory (that is F017 src/catalogue). We only track\n// ids we want to assert status on; anything not here is fail-open (treated\n// available) so we never block a model we simply do not track.\nimport type { AvailabilityStatus, AvailabilitySource, ModelStatus } from \"./types.js\";\n\n/** Internal registry row. `aliases[0]` surfaces as ModelStatus.alias. */\nexport interface RegistryEntry {\n id: string;\n aliases: string[];\n provider: string;\n available: boolean;\n status: AvailabilityStatus;\n note?: string;\n source: AvailabilitySource;\n}\n\nconst SUSPENDED_FABLE_MYTHOS = \"suspended — US export-control directive (2026-06-12)\";\n\n/** Curated defaults. Mirrors DEFAULT_TIER_MAP model ids (src/routing/tier-map.ts)\n * + the models documented in CLAUDE.md, plus the two ids Anthropic suspended\n * globally on 2026-06-12. Aliases are the tier / short names a caller or picker\n * may pass instead of the canonical id. */\nconst DEFAULTS: RegistryEntry[] = [\n // ── Anthropic ────────────────────────────────────────────────────────────\n { id: \"claude-haiku-4-5\", aliases: [\"haiku\", \"fast\"], provider: \"anthropic\", available: true, status: \"available\", source: \"default\" },\n { id: \"claude-sonnet-4-6\", aliases: [\"sonnet\", \"smart\"], provider: \"anthropic\", available: true, status: \"available\", source: \"default\" },\n { id: \"claude-opus-4-8\", aliases: [\"opus\", \"powerful\"], provider: \"anthropic\", available: true, status: \"available\", source: \"default\" },\n { id: \"claude-fable-5\", aliases: [\"fable\"], provider: \"anthropic\", available: false, status: \"suspended\", note: SUSPENDED_FABLE_MYTHOS, source: \"default\" },\n { id: \"claude-mythos-5\", aliases: [\"mythos\"], provider: \"anthropic\", available: false, status: \"suspended\", note: SUSPENDED_FABLE_MYTHOS, source: \"default\" },\n // ── Gemini ───────────────────────────────────────────────────────────────\n { id: \"gemini-2.5-flash\", aliases: [\"gemini-flash\"], provider: \"gemini\", available: true, status: \"available\", source: \"default\" },\n { id: \"gemini-2.5-flash-lite\", aliases: [\"gemini-flash-lite\", \"video\"], provider: \"gemini\", available: true, status: \"available\", source: \"default\" },\n // ── OpenAI ───────────────────────────────────────────────────────────────\n { id: \"text-embedding-3-small\", aliases: [\"embedding\"], provider: \"openai\", available: true, status: \"available\", source: \"default\" },\n // ── Mistral (EU / GDPR) ──────────────────────────────────────────────────\n { id: \"mistral-large-latest\", aliases: [\"mistral-large\"], provider: \"mistral\", available: true, status: \"available\", source: \"default\" },\n { id: \"mistral-small-latest\", aliases: [\"mistral-small\"], provider: \"mistral\", available: true, status: \"available\", source: \"default\" },\n];\n\n/** The live overlay, keyed by canonical id. Seeded from DEFAULTS (deep-copied so\n * resetting is clean). refreshAvailability() mutates this; resolve/listModels\n * read it synchronously. */\nlet OVERLAY = new Map<string, RegistryEntry>();\n/** alias → canonical id, rebuilt whenever the overlay is seeded. */\nlet ALIAS_INDEX = new Map<string, string>();\n\nfunction seed(): void {\n OVERLAY = new Map(DEFAULTS.map((e) => [e.id, { ...e, aliases: [...e.aliases] }]));\n ALIAS_INDEX = new Map();\n for (const e of DEFAULTS) for (const a of e.aliases) ALIAS_INDEX.set(a, e.id);\n}\nseed();\n\n/** Reset the overlay back to the curated defaults. For tests. */\nexport function resetRegistry(): void {\n seed();\n}\n\n/** Canonical id for a model id OR alias; null when we track neither. */\nexport function canonicalId(requested: string): string | null {\n if (OVERLAY.has(requested)) return requested;\n return ALIAS_INDEX.get(requested) ?? null;\n}\n\n/** The current entry for an id/alias, or undefined when untracked (fail-open). */\nexport function getEntry(requested: string): RegistryEntry | undefined {\n const id = canonicalId(requested);\n return id ? OVERLAY.get(id) : undefined;\n}\n\n/** All tracked entries (optionally provider-scoped), as a public ModelStatus[]. */\nexport function allEntries(provider?: string): ModelStatus[] {\n const rows: ModelStatus[] = [];\n for (const e of OVERLAY.values()) {\n if (provider && e.provider !== provider) continue;\n rows.push({\n id: e.id,\n alias: e.aliases[0],\n provider: e.provider,\n available: e.available,\n status: e.status,\n note: e.note,\n source: e.source,\n });\n }\n return rows;\n}\n\n/** Provider-scoped canonical ids (for refresh reconciliation). */\nexport function providerIds(provider: string): string[] {\n return [...OVERLAY.values()].filter((e) => e.provider === provider).map((e) => e.id);\n}\n\n/** Mark a tracked id available/suspended from a live refresh. No-op if untracked. */\nexport function setAvailability(id: string, available: boolean, note?: string): void {\n const e = OVERLAY.get(id);\n if (!e) return;\n e.available = available;\n e.status = available ? \"available\" : \"suspended\";\n e.source = \"refresh\";\n if (note !== undefined) e.note = note;\n else if (available) e.note = undefined;\n}\n","// F022 — Model Availability Harness. Public types for the availability layer:\n// the shared status read (ModelStatus), the resolve result, and the structured\n// error a caller can flag on. The registry is the one source both the spawn /\n// call path (resolveModel) and UI pickers (listModels) read.\n\nexport type AvailabilityStatus = \"available\" | \"suspended\" | \"unknown\";\n\n/** Where a model's current availability came from: the curated default seed,\n * or a live provider refresh (Anthropic GET /v1/models). */\nexport type AvailabilitySource = \"default\" | \"refresh\";\n\n/** One row of the shared status read — what a UI model-picker renders. */\nexport interface ModelStatus {\n /** Canonical provider model id, e.g. \"claude-fable-5\". */\n id: string;\n /** Short/tier alias, e.g. \"fable\" (the first registered alias). */\n alias?: string;\n /** \"anthropic\" | \"openai\" | \"gemini\" | \"mistral\" | … */\n provider: string;\n available: boolean;\n status: AvailabilityStatus;\n /** Friendly reason, e.g. \"suspended — US export-control directive (2026-06-12)\". */\n note?: string;\n source: AvailabilitySource;\n}\n\n/** Result of resolveModel — the spawn / call path consumes this synchronously. */\nexport interface ResolveResult {\n /** True when the requested model itself is available. */\n ok: boolean;\n /** The id to actually use: `requested` when ok, else the first available fallback. */\n model: string;\n /** What the caller asked for (id or alias, normalized to the canonical id). */\n requested: string;\n provider?: string;\n /** True when `model` differs from `requested` because we fell back. */\n fellBack: boolean;\n status: AvailabilityStatus;\n /** Why it degraded / why it is unavailable. */\n reason?: string;\n}\n\n/** Thrown by resolveModel when the requested model is unavailable, no usable\n * fallback exists, and the caller passed `throwIfUnavailable`. Callers flag on\n * `.code === \"model_unavailable\"`. */\nexport class ModelUnavailableError extends Error {\n readonly code = \"model_unavailable\";\n readonly requested: string;\n readonly provider?: string;\n readonly note?: string;\n constructor(requested: string, note?: string, provider?: string) {\n super(`model \"${requested}\" is unavailable${note ? ` (${note})` : \"\"}`);\n this.name = \"ModelUnavailableError\";\n this.requested = requested;\n this.note = note;\n this.provider = provider;\n }\n}\n","// F022 — the synchronous, zero-I/O resolve + status read. This is the spawn /\n// call hot path (buddy's launcher calls resolveModel per spawn, cardmem #4842):\n// it MUST never await and never touch the network. Freshness comes only from a\n// prior async refreshAvailability(); resolve just reads the in-memory registry.\nimport { allEntries, canonicalId, getEntry } from \"./registry.js\";\nimport { ModelUnavailableError } from \"./types.js\";\nimport type { ModelStatus, ResolveResult } from \"./types.js\";\n\nexport interface ResolveOptions {\n /** One id/alias or an ordered chain to try when `requested` is unavailable. */\n fallback?: string | string[];\n /** Scope hint (passed through to the result); does not gate lookup. */\n provider?: string;\n /** Throw ModelUnavailableError instead of returning ok:false when there is no\n * usable fallback. For callers that want to flag rather than degrade. */\n throwIfUnavailable?: boolean;\n}\n\n/** The shared status read — UI pickers grey out `available:false` rows. */\nexport function listModels(opts: { provider?: string } = {}): ModelStatus[] {\n return allEntries(opts.provider);\n}\n\n/** Is this id/alias currently usable? Untracked ids are fail-open (true). */\nfunction isAvailable(requested: string): boolean {\n const e = getEntry(requested);\n return e ? e.available : true; // fail-open on unknown\n}\n\n/**\n * Resolve a requested model (id or alias) to one that is actually usable.\n * Synchronous + offline by contract (cardmem #4842) — reads the registry only.\n *\n * - Available → pass through ({ ok:true, fellBack:false }).\n * - Unavailable + a fallback that IS available → swap ({ ok:false, fellBack:true }).\n * - Unavailable + no usable fallback → throw (throwIfUnavailable) or return ok:false.\n * - Unknown id → treated available (never block a model we do not track).\n */\nexport function resolveModel(requested: string, opts: ResolveOptions = {}): ResolveResult {\n const id = canonicalId(requested) ?? requested;\n const entry = getEntry(requested);\n const provider = opts.provider ?? entry?.provider;\n\n if (isAvailable(requested)) {\n return {\n ok: true,\n model: id,\n requested: id,\n provider,\n fellBack: false,\n status: entry?.status ?? \"unknown\",\n };\n }\n\n // Requested is suspended — walk the fallback chain for the first available one.\n const chain = opts.fallback === undefined ? [] : Array.isArray(opts.fallback) ? opts.fallback : [opts.fallback];\n for (const fb of chain) {\n if (isAvailable(fb)) {\n const fbId = canonicalId(fb) ?? fb;\n return {\n ok: false,\n model: fbId,\n requested: id,\n provider,\n fellBack: true,\n status: entry?.status ?? \"suspended\",\n reason: entry?.note ?? `${id} is unavailable`,\n };\n }\n }\n\n // No usable fallback.\n if (opts.throwIfUnavailable) {\n throw new ModelUnavailableError(id, entry?.note, provider);\n }\n return {\n ok: false,\n model: id,\n requested: id,\n provider,\n fellBack: false,\n status: entry?.status ?? \"suspended\",\n reason: entry?.note ?? `${id} is unavailable`,\n };\n}\n"],"mappings":";AAsBA,IAAM,yBAAyB;AAM/B,IAAM,WAA4B;AAAA;AAAA,EAEhC,EAAE,IAAI,oBAAoB,SAAS,CAAC,SAAS,MAAM,GAAG,UAAU,aAAa,WAAW,MAAM,QAAQ,aAAa,QAAQ,UAAU;AAAA,EACrI,EAAE,IAAI,qBAAqB,SAAS,CAAC,UAAU,OAAO,GAAG,UAAU,aAAa,WAAW,MAAM,QAAQ,aAAa,QAAQ,UAAU;AAAA,EACxI,EAAE,IAAI,mBAAmB,SAAS,CAAC,QAAQ,UAAU,GAAG,UAAU,aAAa,WAAW,MAAM,QAAQ,aAAa,QAAQ,UAAU;AAAA,EACvI,EAAE,IAAI,kBAAkB,SAAS,CAAC,OAAO,GAAG,UAAU,aAAa,WAAW,OAAO,QAAQ,aAAa,MAAM,wBAAwB,QAAQ,UAAU;AAAA,EAC1J,EAAE,IAAI,mBAAmB,SAAS,CAAC,QAAQ,GAAG,UAAU,aAAa,WAAW,OAAO,QAAQ,aAAa,MAAM,wBAAwB,QAAQ,UAAU;AAAA;AAAA,EAE5J,EAAE,IAAI,oBAAoB,SAAS,CAAC,cAAc,GAAG,UAAU,UAAU,WAAW,MAAM,QAAQ,aAAa,QAAQ,UAAU;AAAA,EACjI,EAAE,IAAI,yBAAyB,SAAS,CAAC,qBAAqB,OAAO,GAAG,UAAU,UAAU,WAAW,MAAM,QAAQ,aAAa,QAAQ,UAAU;AAAA;AAAA,EAEpJ,EAAE,IAAI,0BAA0B,SAAS,CAAC,WAAW,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Y,CAAC,IAAI,MAAM,QAAQ,KAAK,QAAQ,IAAI,KAAK,WAAW,CAAC,KAAK,QAAQ;AAC9G,aAAW,MAAM,OAAO;AACtB,QAAI,YAAY,EAAE,GAAG;AACnB,YAAM,OAAO,YAAY,EAAE,KAAK;AAChC,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,OAAO;AAAA,QACP,WAAW;AAAA,QACX;AAAA,QACA,UAAU;AAAA,QACV,QAAQ,OAAO,UAAU;AAAA,QACzB,QAAQ,OAAO,QAAQ,GAAG,EAAE;AAAA,MAC9B;AAAA,IACF;AAAA,EACF;AAGA,MAAI,KAAK,oBAAoB;AAC3B,UAAM,IAAI,sBAAsB,IAAI,OAAO,MAAM,QAAQ;AAAA,EAC3D;AACA,SAAO;AAAA,IACL,IAAI;AAAA,IACJ,OAAO;AAAA,IACP,WAAW;AAAA,IACX;AAAA,IACA,UAAU;AAAA,IACV,QAAQ,OAAO,UAAU;AAAA,IACzB,QAAQ,OAAO,QAAQ,GAAG,EAAE;AAAA,EAC9B;AACF;","names":[]}
|
package/dist/index.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { z } from 'zod';
|
|
2
|
+
export { AvailabilitySource, AvailabilityStatus, ModelStatus, ModelUnavailableError, ResolveOptions, ResolveResult, listModels, resolveModel } from './registry.js';
|
|
2
3
|
|
|
3
4
|
/** How a call reaches the model. `http` = provider REST API; `subprocess` = local
|
|
4
5
|
* `claude -p` CLI (Max plan, costUsd 0). */
|
|
@@ -1714,8 +1715,8 @@ declare const falStubAdapter: ProviderAdapter;
|
|
|
1714
1715
|
* wires the live adapters. */
|
|
1715
1716
|
declare const stubProviders: Record<string, ProviderAdapter>;
|
|
1716
1717
|
|
|
1717
|
-
declare const VERSION: "0.
|
|
1718
|
-
declare const SDK_TAG: "@broberg/ai-sdk@0.
|
|
1718
|
+
declare const VERSION: "0.12.0";
|
|
1719
|
+
declare const SDK_TAG: "@broberg/ai-sdk@0.12.0";
|
|
1719
1720
|
|
|
1720
1721
|
/** Built-in defaults. Every entry is overridable via AiConfig.defaults or a
|
|
1721
1722
|
* per-call override. Model IDs are current at scaffold time; callers pin their
|
|
@@ -1731,74 +1732,6 @@ declare const DEFAULT_TIER_MAP: Record<Tier, TierSpec>;
|
|
|
1731
1732
|
*/
|
|
1732
1733
|
declare function resolveTier(tier: Tier, override?: Partial<TierSpec>, configMap?: Partial<Record<Tier, TierSpec>>): TierSpec;
|
|
1733
1734
|
|
|
1734
|
-
type AvailabilityStatus = "available" | "suspended" | "unknown";
|
|
1735
|
-
/** Where a model's current availability came from: the curated default seed,
|
|
1736
|
-
* or a live provider refresh (Anthropic GET /v1/models). */
|
|
1737
|
-
type AvailabilitySource = "default" | "refresh";
|
|
1738
|
-
/** One row of the shared status read — what a UI model-picker renders. */
|
|
1739
|
-
interface ModelStatus {
|
|
1740
|
-
/** Canonical provider model id, e.g. "claude-fable-5". */
|
|
1741
|
-
id: string;
|
|
1742
|
-
/** Short/tier alias, e.g. "fable" (the first registered alias). */
|
|
1743
|
-
alias?: string;
|
|
1744
|
-
/** "anthropic" | "openai" | "gemini" | "mistral" | … */
|
|
1745
|
-
provider: string;
|
|
1746
|
-
available: boolean;
|
|
1747
|
-
status: AvailabilityStatus;
|
|
1748
|
-
/** Friendly reason, e.g. "suspended — US export-control directive (2026-06-12)". */
|
|
1749
|
-
note?: string;
|
|
1750
|
-
source: AvailabilitySource;
|
|
1751
|
-
}
|
|
1752
|
-
/** Result of resolveModel — the spawn / call path consumes this synchronously. */
|
|
1753
|
-
interface ResolveResult {
|
|
1754
|
-
/** True when the requested model itself is available. */
|
|
1755
|
-
ok: boolean;
|
|
1756
|
-
/** The id to actually use: `requested` when ok, else the first available fallback. */
|
|
1757
|
-
model: string;
|
|
1758
|
-
/** What the caller asked for (id or alias, normalized to the canonical id). */
|
|
1759
|
-
requested: string;
|
|
1760
|
-
provider?: string;
|
|
1761
|
-
/** True when `model` differs from `requested` because we fell back. */
|
|
1762
|
-
fellBack: boolean;
|
|
1763
|
-
status: AvailabilityStatus;
|
|
1764
|
-
/** Why it degraded / why it is unavailable. */
|
|
1765
|
-
reason?: string;
|
|
1766
|
-
}
|
|
1767
|
-
/** Thrown by resolveModel when the requested model is unavailable, no usable
|
|
1768
|
-
* fallback exists, and the caller passed `throwIfUnavailable`. Callers flag on
|
|
1769
|
-
* `.code === "model_unavailable"`. */
|
|
1770
|
-
declare class ModelUnavailableError extends Error {
|
|
1771
|
-
readonly code = "model_unavailable";
|
|
1772
|
-
readonly requested: string;
|
|
1773
|
-
readonly provider?: string;
|
|
1774
|
-
readonly note?: string;
|
|
1775
|
-
constructor(requested: string, note?: string, provider?: string);
|
|
1776
|
-
}
|
|
1777
|
-
|
|
1778
|
-
interface ResolveOptions {
|
|
1779
|
-
/** One id/alias or an ordered chain to try when `requested` is unavailable. */
|
|
1780
|
-
fallback?: string | string[];
|
|
1781
|
-
/** Scope hint (passed through to the result); does not gate lookup. */
|
|
1782
|
-
provider?: string;
|
|
1783
|
-
/** Throw ModelUnavailableError instead of returning ok:false when there is no
|
|
1784
|
-
* usable fallback. For callers that want to flag rather than degrade. */
|
|
1785
|
-
throwIfUnavailable?: boolean;
|
|
1786
|
-
}
|
|
1787
|
-
/** The shared status read — UI pickers grey out `available:false` rows. */
|
|
1788
|
-
declare function listModels(opts?: {
|
|
1789
|
-
provider?: string;
|
|
1790
|
-
}): ModelStatus[];
|
|
1791
|
-
/**
|
|
1792
|
-
* Resolve a requested model (id or alias) to one that is actually usable.
|
|
1793
|
-
* Synchronous + offline by contract (cardmem #4842) — reads the registry only.
|
|
1794
|
-
*
|
|
1795
|
-
* - Available → pass through ({ ok:true, fellBack:false }).
|
|
1796
|
-
* - Unavailable + a fallback that IS available → swap ({ ok:false, fellBack:true }).
|
|
1797
|
-
* - Unavailable + no usable fallback → throw (throwIfUnavailable) or return ok:false.
|
|
1798
|
-
* - Unknown id → treated available (never block a model we do not track).
|
|
1799
|
-
*/
|
|
1800
|
-
declare function resolveModel(requested: string, opts?: ResolveOptions): ResolveResult;
|
|
1801
|
-
|
|
1802
1735
|
interface RefreshOptions {
|
|
1803
1736
|
/** Only "anthropic" is wired in v1 (where the incident hit). */
|
|
1804
1737
|
provider?: "anthropic";
|
|
@@ -2006,4 +1939,4 @@ interface StreamTransportRequest extends TransportRequest {
|
|
|
2006
1939
|
*/
|
|
2007
1940
|
declare function streamTransport(req: StreamTransportRequest): AsyncIterable<string>;
|
|
2008
1941
|
|
|
2009
|
-
export { type AiClient, type AiConfig, type
|
|
1942
|
+
export { type AiClient, type AiConfig, type BatchJob, type BatchRequestItem, type BatchResultItem, type BudgetConfig, BudgetExceededError, BudgetGuard, type BudgetStore, type CallOptions, type Capability, type ChatInput, type ChatRequest, type ChatResult, type ChatStreamEvent, type ClassifyInput, type ClassifyResult, type ContentPart, type Contracts, type CostSink, type CostSummary, DEFAULT_TIER_MAP, type DesignInput, type DesignResult, type DialogueRequest, type DialogueTurn, type DiscordSinkConfig, ELEVENLABS_DANISH_VOICES, type EmbeddingInput, type EmbeddingRequest, type EmbeddingResult, type ExtractInput, type ExtractResult, type FalAdapterConfig, type HttpResponse, type ImageInput, type ImageRequest, type ImageResult, type LoraWeight, type Message, type MockupInput, type MockupResult, type ModerationInput, type ModerationItem, type ModerationRequest, type ModerationResult, type OcrInput, type OcrPage, type OcrRequest, type OcrResult, type OpenAICompatibleConfig, type PodcastInput, type PodcastResult, type PricingEntry, type ProviderAdapter, type RefreshOptions, type RefreshResult, type RerankInput, type RerankResult, type Role, SDK_TAG, type SqliteBudgetStoreConfig, type SqliteSinkConfig, StreamHttpError, type SubprocessResponse, type Tier, type TierSpec, type Tool, type ToolCall, type TrainStyleInput, type TrainStyleRequest, type TrainStyleResult, type TranscribeInput, type TranscribeRequest, type TranscribeResult, type TranslateInput, type TranslateResult, type Transport, type TransportRequest, type TransportResponse, type TtsInput, type TtsRequest, type UpmetricsSinkConfig, type Usage, VERSION, type VideoInput, type VisionInput, aiConfigSchema, anthropicAdapter, anthropicApiAdapter, anthropicSubprocessAdapter, chatInputSchema, computeCost, createAI, deepinfraAdapter, defaultProviders, discordSink, elevenlabsAdapter, embeddingInputSchema, falAdapter, falStubAdapter, freshUsage, fromProviderToolCall, geminiAdapter, getCostSummary, getPrice, httpTransport, imageInputSchema, makeContracts, makeOpenAICompatibleAdapter, messageSchema, mistralAdapter, multiSink, noopSink, openaiAdapter, openaiStubAdapter, openrouterAdapter, parseClaudeCliJson, parseJsonLoose, refreshAvailability, resetRefreshState, resetRegistry, resolveTier, resolveVoice, sqliteBudgetStore, sqliteSink, streamTransport, stubProviders, subprocessTransport, tierSpecSchema, toProviderTools, toolSchema, translateInputSchema, upmetricsSink, visionInputSchema };
|
package/dist/index.js
CHANGED
|
@@ -1,3 +1,12 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ModelUnavailableError,
|
|
3
|
+
listModels,
|
|
4
|
+
providerIds,
|
|
5
|
+
resetRegistry,
|
|
6
|
+
resolveModel,
|
|
7
|
+
setAvailability
|
|
8
|
+
} from "./chunk-HVZSYNZ5.js";
|
|
9
|
+
|
|
1
10
|
// src/routing/tier-map.ts
|
|
2
11
|
var DEFAULT_TIER_MAP = {
|
|
3
12
|
fast: { provider: "anthropic", model: "claude-haiku-4-5", transport: "http" },
|
|
@@ -14,138 +23,6 @@ function resolveTier(tier, override, configMap) {
|
|
|
14
23
|
return { ...base, ...override };
|
|
15
24
|
}
|
|
16
25
|
|
|
17
|
-
// src/availability/registry.ts
|
|
18
|
-
var SUSPENDED_FABLE_MYTHOS = "suspended \u2014 US export-control directive (2026-06-12)";
|
|
19
|
-
var DEFAULTS = [
|
|
20
|
-
// ── Anthropic ────────────────────────────────────────────────────────────
|
|
21
|
-
{ id: "claude-haiku-4-5", aliases: ["haiku", "fast"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
22
|
-
{ id: "claude-sonnet-4-6", aliases: ["sonnet", "smart"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
23
|
-
{ id: "claude-opus-4-8", aliases: ["opus", "powerful"], provider: "anthropic", available: true, status: "available", source: "default" },
|
|
24
|
-
{ id: "claude-fable-5", aliases: ["fable"], provider: "anthropic", available: false, status: "suspended", note: SUSPENDED_FABLE_MYTHOS, source: "default" },
|
|
25
|
-
{ id: "claude-mythos-5", aliases: ["mythos"], provider: "anthropic", available: false, status: "suspended", note: SUSPENDED_FABLE_MYTHOS, source: "default" },
|
|
26
|
-
// ── Gemini ───────────────────────────────────────────────────────────────
|
|
27
|
-
{ id: "gemini-2.5-flash", aliases: ["gemini-flash"], provider: "gemini", available: true, status: "available", source: "default" },
|
|
28
|
-
{ id: "gemini-2.5-flash-lite", aliases: ["gemini-flash-lite", "video"], provider: "gemini", available: true, status: "available", source: "default" },
|
|
29
|
-
// ── OpenAI ───────────────────────────────────────────────────────────────
|
|
30
|
-
{ id: "text-embedding-3-small", aliases: ["embedding"], provider: "openai", available: true, status: "available", source: "default" },
|
|
31
|
-
// ── Mistral (EU / GDPR) ──────────────────────────────────────────────────
|
|
32
|
-
{ id: "mistral-large-latest", aliases: ["mistral-large"], provider: "mistral", available: true, status: "available", source: "default" },
|
|
33
|
-
{ id: "mistral-small-latest", aliases: ["mistral-small"], provider: "mistral", available: true, status: "available", source: "default" }
|
|
34
|
-
];
|
|
35
|
-
var OVERLAY = /* @__PURE__ */ new Map();
|
|
36
|
-
var ALIAS_INDEX = /* @__PURE__ */ new Map();
|
|
37
|
-
function seed() {
|
|
38
|
-
OVERLAY = new Map(DEFAULTS.map((e) => [e.id, { ...e, aliases: [...e.aliases] }]));
|
|
39
|
-
ALIAS_INDEX = /* @__PURE__ */ new Map();
|
|
40
|
-
for (const e of DEFAULTS) for (const a of e.aliases) ALIAS_INDEX.set(a, e.id);
|
|
41
|
-
}
|
|
42
|
-
seed();
|
|
43
|
-
function resetRegistry() {
|
|
44
|
-
seed();
|
|
45
|
-
}
|
|
46
|
-
function canonicalId(requested) {
|
|
47
|
-
if (OVERLAY.has(requested)) return requested;
|
|
48
|
-
return ALIAS_INDEX.get(requested) ?? null;
|
|
49
|
-
}
|
|
50
|
-
function getEntry(requested) {
|
|
51
|
-
const id = canonicalId(requested);
|
|
52
|
-
return id ? OVERLAY.get(id) : void 0;
|
|
53
|
-
}
|
|
54
|
-
function allEntries(provider) {
|
|
55
|
-
const rows = [];
|
|
56
|
-
for (const e of OVERLAY.values()) {
|
|
57
|
-
if (provider && e.provider !== provider) continue;
|
|
58
|
-
rows.push({
|
|
59
|
-
id: e.id,
|
|
60
|
-
alias: e.aliases[0],
|
|
61
|
-
provider: e.provider,
|
|
62
|
-
available: e.available,
|
|
63
|
-
status: e.status,
|
|
64
|
-
note: e.note,
|
|
65
|
-
source: e.source
|
|
66
|
-
});
|
|
67
|
-
}
|
|
68
|
-
return rows;
|
|
69
|
-
}
|
|
70
|
-
function providerIds(provider) {
|
|
71
|
-
return [...OVERLAY.values()].filter((e) => e.provider === provider).map((e) => e.id);
|
|
72
|
-
}
|
|
73
|
-
function setAvailability(id, available, note) {
|
|
74
|
-
const e = OVERLAY.get(id);
|
|
75
|
-
if (!e) return;
|
|
76
|
-
e.available = available;
|
|
77
|
-
e.status = available ? "available" : "suspended";
|
|
78
|
-
e.source = "refresh";
|
|
79
|
-
if (note !== void 0) e.note = note;
|
|
80
|
-
else if (available) e.note = void 0;
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
// src/availability/types.ts
|
|
84
|
-
var ModelUnavailableError = class extends Error {
|
|
85
|
-
code = "model_unavailable";
|
|
86
|
-
requested;
|
|
87
|
-
provider;
|
|
88
|
-
note;
|
|
89
|
-
constructor(requested, note, provider) {
|
|
90
|
-
super(`model "${requested}" is unavailable${note ? ` (${note})` : ""}`);
|
|
91
|
-
this.name = "ModelUnavailableError";
|
|
92
|
-
this.requested = requested;
|
|
93
|
-
this.note = note;
|
|
94
|
-
this.provider = provider;
|
|
95
|
-
}
|
|
96
|
-
};
|
|
97
|
-
|
|
98
|
-
// src/availability/resolve.ts
|
|
99
|
-
function listModels(opts = {}) {
|
|
100
|
-
return allEntries(opts.provider);
|
|
101
|
-
}
|
|
102
|
-
function isAvailable(requested) {
|
|
103
|
-
const e = getEntry(requested);
|
|
104
|
-
return e ? e.available : true;
|
|
105
|
-
}
|
|
106
|
-
function resolveModel(requested, opts = {}) {
|
|
107
|
-
const id = canonicalId(requested) ?? requested;
|
|
108
|
-
const entry = getEntry(requested);
|
|
109
|
-
const provider = opts.provider ?? entry?.provider;
|
|
110
|
-
if (isAvailable(requested)) {
|
|
111
|
-
return {
|
|
112
|
-
ok: true,
|
|
113
|
-
model: id,
|
|
114
|
-
requested: id,
|
|
115
|
-
provider,
|
|
116
|
-
fellBack: false,
|
|
117
|
-
status: entry?.status ?? "unknown"
|
|
118
|
-
};
|
|
119
|
-
}
|
|
120
|
-
const chain = opts.fallback === void 0 ? [] : Array.isArray(opts.fallback) ? opts.fallback : [opts.fallback];
|
|
121
|
-
for (const fb of chain) {
|
|
122
|
-
if (isAvailable(fb)) {
|
|
123
|
-
const fbId = canonicalId(fb) ?? fb;
|
|
124
|
-
return {
|
|
125
|
-
ok: false,
|
|
126
|
-
model: fbId,
|
|
127
|
-
requested: id,
|
|
128
|
-
provider,
|
|
129
|
-
fellBack: true,
|
|
130
|
-
status: entry?.status ?? "suspended",
|
|
131
|
-
reason: entry?.note ?? `${id} is unavailable`
|
|
132
|
-
};
|
|
133
|
-
}
|
|
134
|
-
}
|
|
135
|
-
if (opts.throwIfUnavailable) {
|
|
136
|
-
throw new ModelUnavailableError(id, entry?.note, provider);
|
|
137
|
-
}
|
|
138
|
-
return {
|
|
139
|
-
ok: false,
|
|
140
|
-
model: id,
|
|
141
|
-
requested: id,
|
|
142
|
-
provider,
|
|
143
|
-
fellBack: false,
|
|
144
|
-
status: entry?.status ?? "suspended",
|
|
145
|
-
reason: entry?.note ?? `${id} is unavailable`
|
|
146
|
-
};
|
|
147
|
-
}
|
|
148
|
-
|
|
149
26
|
// src/transport/http.ts
|
|
150
27
|
async function httpTransport(req) {
|
|
151
28
|
if (!req.http) {
|
|
@@ -2612,8 +2489,8 @@ var stubProviders = {
|
|
|
2612
2489
|
};
|
|
2613
2490
|
|
|
2614
2491
|
// src/version.ts
|
|
2615
|
-
var VERSION = "0.
|
|
2616
|
-
var SDK_TAG = "@broberg/ai-sdk@0.
|
|
2492
|
+
var VERSION = "0.12.0";
|
|
2493
|
+
var SDK_TAG = "@broberg/ai-sdk@0.12.0";
|
|
2617
2494
|
|
|
2618
2495
|
// src/availability/refresh.ts
|
|
2619
2496
|
var NOT_REFRESHED = { refreshed: false, checked: 0, markedUnavailable: [] };
|