@qlairoslabs/acp-client 0.4.3 → 0.6.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/CHANGELOG-metering.md +288 -0
- package/README.md +15 -5
- package/package.json +6 -3
- package/src/agent-session.ts +431 -17
- package/src/client.ts +179 -50
- package/src/controller.ts +41 -0
- package/src/degraded/pty-client.ts +22 -14
- package/src/degraded/pty-transport.ts +54 -19
- package/src/index.ts +156 -0
- package/src/launcher.ts +86 -0
- package/src/metering/catalog/build.ts +285 -0
- package/src/metering/catalog/index.ts +243 -0
- package/src/metering/catalog/live.ts +171 -0
- package/src/metering/catalog/models-dev.catalog.json +8797 -0
- package/src/metering/catalog/models-dev.meta.json +6 -0
- package/src/metering/categories.ts +129 -0
- package/src/metering/certification.ts +86 -0
- package/src/metering/context.ts +134 -0
- package/src/metering/delta.ts +108 -0
- package/src/metering/engine.ts +991 -0
- package/src/metering/money.ts +356 -0
- package/src/metering/opencode/channel.ts +389 -0
- package/src/metering/opencode/index.ts +159 -0
- package/src/metering/opencode/plugin.js +90 -0
- package/src/metering/opencode/profile.ts +159 -0
- package/src/metering/pricing.ts +285 -0
- package/src/metering/provider.ts +121 -0
- package/src/metering/rating.ts +349 -0
- package/src/metering/record.ts +274 -0
- package/src/metering/state.ts +421 -0
- package/src/metering/usage.ts +72 -0
- package/src/transport/acp-transport.ts +78 -41
- package/src/types.ts +28 -5
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
// The pinned models.dev catalog resolver — the library's DEFAULT pricing source.
|
|
2
|
+
// See 9-6-SPEC-metering.md §7.
|
|
3
|
+
//
|
|
4
|
+
// This is an offline deterministic default, not an always-current catalog and not a
|
|
5
|
+
// provider billing authority. It exists so a consumer gets reproducible rated costs
|
|
6
|
+
// without shipping their own price table, and so every record can name the exact upstream
|
|
7
|
+
// commit and artifact digest its prices came from.
|
|
8
|
+
//
|
|
9
|
+
// Regenerate with: bun run scripts/generate-pricing-catalog.ts
|
|
10
|
+
|
|
11
|
+
import { createHash } from "node:crypto";
|
|
12
|
+
import catalogJson from "./models-dev.catalog.json" with { type: "json" };
|
|
13
|
+
import metaJson from "./models-dev.meta.json" with { type: "json" };
|
|
14
|
+
import type {
|
|
15
|
+
CacheInputConvention,
|
|
16
|
+
CategoryApplicability,
|
|
17
|
+
PricingContext,
|
|
18
|
+
PricingPolicy,
|
|
19
|
+
PricingResolver,
|
|
20
|
+
PricingSchedule,
|
|
21
|
+
PricingSource,
|
|
22
|
+
TokenCategory,
|
|
23
|
+
} from "../pricing.ts";
|
|
24
|
+
import { validatePricingPolicy } from "../pricing.ts";
|
|
25
|
+
|
|
26
|
+
export interface CatalogModel {
|
|
27
|
+
readonly categoryApplicability: Readonly<Record<string, string>>;
|
|
28
|
+
readonly lastUpdated?: string;
|
|
29
|
+
readonly schedules: readonly PricingSchedule[];
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
export interface CatalogProvider {
|
|
33
|
+
readonly cacheInputConvention: CacheInputConvention;
|
|
34
|
+
readonly conventionEvidence: string;
|
|
35
|
+
readonly models: Readonly<Record<string, CatalogModel>>;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
interface Catalog {
|
|
39
|
+
readonly currency: string;
|
|
40
|
+
readonly perTokens: number;
|
|
41
|
+
readonly providers: Readonly<Record<string, CatalogProvider>>;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Validate the artifact's SHAPE, not just its bytes.
|
|
46
|
+
*
|
|
47
|
+
* The digest proves which bytes shipped; it says nothing about what shape they have. A
|
|
48
|
+
* generator change would otherwise surface as `undefined` deep in a pricing path rather
|
|
49
|
+
* than as a clear failure at load — the same "validate before trusting" argument already
|
|
50
|
+
* applied to restored consumer state.
|
|
51
|
+
*/
|
|
52
|
+
function assertCatalogShape(value: unknown): asserts value is Catalog {
|
|
53
|
+
const root = value as Record<string, unknown> | null;
|
|
54
|
+
if (typeof root !== "object" || root === null || typeof root.providers !== "object") {
|
|
55
|
+
throw new Error("pricing catalog artifact is not a catalog object");
|
|
56
|
+
}
|
|
57
|
+
for (const [providerId, provider] of Object.entries(
|
|
58
|
+
root.providers as Record<string, unknown>,
|
|
59
|
+
)) {
|
|
60
|
+
const entry = provider as Record<string, unknown> | null;
|
|
61
|
+
if (
|
|
62
|
+
typeof entry !== "object" ||
|
|
63
|
+
entry === null ||
|
|
64
|
+
typeof entry.cacheInputConvention !== "object" ||
|
|
65
|
+
typeof entry.conventionEvidence !== "string" ||
|
|
66
|
+
typeof entry.models !== "object"
|
|
67
|
+
) {
|
|
68
|
+
throw new Error(`pricing catalog provider ${providerId} is malformed`);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
assertCatalogShape(catalogJson);
|
|
74
|
+
const catalog = catalogJson as unknown as Catalog;
|
|
75
|
+
|
|
76
|
+
/** Identity of the shipped artifact, engraved into every policy it produces. */
|
|
77
|
+
export const MODELS_DEV_SOURCE: PricingSource = Object.freeze({
|
|
78
|
+
kind: "models.dev",
|
|
79
|
+
commit: metaJson.commit,
|
|
80
|
+
artifactSha256: metaJson.artifactSha256,
|
|
81
|
+
generatedAt: metaJson.generatedAt,
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
let integrityChecked = false;
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Verify the shipped catalog against the digest recorded beside it.
|
|
88
|
+
*
|
|
89
|
+
* The digest is what makes `artifactSha256` in a stored record meaningful: without this
|
|
90
|
+
* check the field would assert an identity nobody confirmed. Runs once, lazily — hashing
|
|
91
|
+
* ~76 KiB on first pricing call is cheaper than being wrong about which prices shipped.
|
|
92
|
+
*/
|
|
93
|
+
export function verifyCatalogIntegrity(): void {
|
|
94
|
+
if (integrityChecked) return;
|
|
95
|
+
// Must reproduce the generator's serialization exactly: 2-space indent, trailing newline.
|
|
96
|
+
const serialized = `${JSON.stringify(catalog, null, 2)}\n`;
|
|
97
|
+
const digest = createHash("sha256").update(serialized, "utf8").digest("hex");
|
|
98
|
+
if (digest !== metaJson.artifactSha256) {
|
|
99
|
+
throw new Error(
|
|
100
|
+
`pricing catalog digest mismatch: artifact hashes to ${digest} but its metadata ` +
|
|
101
|
+
`records ${metaJson.artifactSha256}. Regenerate with ` +
|
|
102
|
+
`scripts/generate-pricing-catalog.ts.`,
|
|
103
|
+
);
|
|
104
|
+
}
|
|
105
|
+
integrityChecked = true;
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/** One priceable model, with everything needed to display or re-derive its rates. */
|
|
109
|
+
export interface CatalogEntry {
|
|
110
|
+
readonly providerId: string;
|
|
111
|
+
readonly modelId: string;
|
|
112
|
+
/** ISO date the upstream entry last changed, when the source records it. */
|
|
113
|
+
readonly modelLastUpdated?: string;
|
|
114
|
+
readonly categoryApplicability: Readonly<Record<TokenCategory, CategoryApplicability>>;
|
|
115
|
+
readonly schedules: readonly PricingSchedule[];
|
|
116
|
+
}
|
|
117
|
+
|
|
118
|
+
export interface CatalogProviderInfo {
|
|
119
|
+
readonly providerId: string;
|
|
120
|
+
readonly cacheInputConvention: CacheInputConvention;
|
|
121
|
+
/** Why the library believes that convention — auditable, not folklore. */
|
|
122
|
+
readonly conventionEvidence: string;
|
|
123
|
+
readonly modelCount: number;
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* A readable view of a pricing catalog.
|
|
128
|
+
*
|
|
129
|
+
* The resolver answers "what does THIS model cost"; this answers "what can you price, and
|
|
130
|
+
* at what rates" — needed to build a price list, a model picker, or a markup table without
|
|
131
|
+
* reaching into the library's files.
|
|
132
|
+
*/
|
|
133
|
+
export interface PricingCatalog {
|
|
134
|
+
readonly source: PricingSource;
|
|
135
|
+
readonly providers: readonly CatalogProviderInfo[];
|
|
136
|
+
/** Every priceable model, or just one provider's. */
|
|
137
|
+
entries(providerId?: string): readonly CatalogEntry[];
|
|
138
|
+
get(providerId: string, modelId: string): CatalogEntry | null;
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* Wrap raw catalog providers in the readable view.
|
|
143
|
+
*
|
|
144
|
+
* Shared with the live resolver so both catalogs expose exactly the same surface.
|
|
145
|
+
*/
|
|
146
|
+
export function makeCatalog(
|
|
147
|
+
providers: Readonly<Record<string, CatalogProvider>>,
|
|
148
|
+
source: PricingSource,
|
|
149
|
+
): PricingCatalog {
|
|
150
|
+
const toEntry = (providerId: string, modelId: string, model: CatalogModel): CatalogEntry =>
|
|
151
|
+
Object.freeze({
|
|
152
|
+
providerId,
|
|
153
|
+
modelId,
|
|
154
|
+
...(model.lastUpdated ? { modelLastUpdated: model.lastUpdated } : {}),
|
|
155
|
+
categoryApplicability: model.categoryApplicability as Readonly<
|
|
156
|
+
Record<TokenCategory, CategoryApplicability>
|
|
157
|
+
>,
|
|
158
|
+
schedules: model.schedules,
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
return Object.freeze({
|
|
162
|
+
source,
|
|
163
|
+
providers: Object.freeze(
|
|
164
|
+
Object.entries(providers).map(([providerId, provider]) =>
|
|
165
|
+
Object.freeze({
|
|
166
|
+
providerId,
|
|
167
|
+
cacheInputConvention: provider.cacheInputConvention,
|
|
168
|
+
conventionEvidence: provider.conventionEvidence,
|
|
169
|
+
modelCount: Object.keys(provider.models).length,
|
|
170
|
+
}),
|
|
171
|
+
),
|
|
172
|
+
),
|
|
173
|
+
entries(providerId?: string) {
|
|
174
|
+
const wanted = providerId ? { [providerId]: providers[providerId] } : providers;
|
|
175
|
+
const out: CatalogEntry[] = [];
|
|
176
|
+
for (const [id, provider] of Object.entries(wanted)) {
|
|
177
|
+
if (!provider) continue;
|
|
178
|
+
for (const modelId of Object.keys(provider.models).sort()) {
|
|
179
|
+
out.push(toEntry(id, modelId, provider.models[modelId]!));
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
return Object.freeze(out);
|
|
183
|
+
},
|
|
184
|
+
get(providerId: string, modelId: string) {
|
|
185
|
+
const model = providers[providerId]?.models[modelId];
|
|
186
|
+
return model ? toEntry(providerId, modelId, model) : null;
|
|
187
|
+
},
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
|
|
191
|
+
/**
|
|
192
|
+
* The pinned catalog the library ships, as a readable view.
|
|
193
|
+
*
|
|
194
|
+
* Verifies the artifact digest first, so a listing cannot show prices the library would
|
|
195
|
+
* refuse to rate with.
|
|
196
|
+
*/
|
|
197
|
+
export function loadPinnedCatalog(): PricingCatalog {
|
|
198
|
+
verifyCatalogIntegrity();
|
|
199
|
+
return makeCatalog(catalog.providers, MODELS_DEV_SOURCE);
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
/** Providers this catalog can price, i.e. those with a documented counter convention. */
|
|
203
|
+
export function catalogProviderIds(): readonly string[] {
|
|
204
|
+
return Object.freeze(Object.keys(catalog.providers));
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
/**
|
|
208
|
+
* Build the default resolver.
|
|
209
|
+
*
|
|
210
|
+
* Returns null — never a guess — when the provider or model is not matched exactly. §7
|
|
211
|
+
* forbids inferring a provider from a bare model string: two providers can serve the same
|
|
212
|
+
* model id at different prices, so a fuzzy match would engrave a plausible wrong number
|
|
213
|
+
* rather than an honest "unavailable".
|
|
214
|
+
*/
|
|
215
|
+
export function createModelsDevResolver(): PricingResolver {
|
|
216
|
+
return (context: PricingContext): PricingPolicy | null => {
|
|
217
|
+
verifyCatalogIntegrity();
|
|
218
|
+
|
|
219
|
+
const { providerId, model } = context;
|
|
220
|
+
if (!providerId || !model) return null;
|
|
221
|
+
|
|
222
|
+
const provider = catalog.providers[providerId];
|
|
223
|
+
if (!provider) return null;
|
|
224
|
+
|
|
225
|
+
const entry = provider.models[model];
|
|
226
|
+
if (!entry) return null;
|
|
227
|
+
|
|
228
|
+
const policy: PricingPolicy = {
|
|
229
|
+
source: MODELS_DEV_SOURCE,
|
|
230
|
+
providerId,
|
|
231
|
+
modelId: model,
|
|
232
|
+
categoryApplicability: entry.categoryApplicability as Readonly<
|
|
233
|
+
Record<TokenCategory, CategoryApplicability>
|
|
234
|
+
>,
|
|
235
|
+
...(entry.lastUpdated ? { modelLastUpdated: entry.lastUpdated } : {}),
|
|
236
|
+
schedules: entry.schedules,
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
// A catalog entry that cannot satisfy the policy invariants is unavailable, not
|
|
240
|
+
// partially usable: half a schedule silently drops real cost from the total.
|
|
241
|
+
return validatePricingPolicy(policy).ok ? policy : null;
|
|
242
|
+
};
|
|
243
|
+
}
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
// An optional live models.dev pricing resolver. See 9-6-SPEC-metering.md §7.
|
|
2
|
+
//
|
|
3
|
+
// The DEFAULT is the pinned artifact, and that is the right default: models.dev publishes
|
|
4
|
+
// no versioning scheme and no update-frequency guarantee, so a live fetch means the price
|
|
5
|
+
// applied to an operation depends on when it ran. This exists for consumers who would
|
|
6
|
+
// rather have current prices than reproducible ones — a legitimate trade, but a trade.
|
|
7
|
+
//
|
|
8
|
+
// What makes it defensible is that a record still carries WHICH prices it used. Every
|
|
9
|
+
// policy this produces engraves the SHA-256 of the exact payload it was built from, so two
|
|
10
|
+
// records rated days apart are distinguishable, and an unexpected price change is
|
|
11
|
+
// detectable after the fact rather than invisible.
|
|
12
|
+
//
|
|
13
|
+
// It is never automatic. `MeteringConfig.pricing` must be set to it explicitly.
|
|
14
|
+
|
|
15
|
+
import { createHash } from "node:crypto";
|
|
16
|
+
import {
|
|
17
|
+
buildCatalog,
|
|
18
|
+
serializeCatalog,
|
|
19
|
+
type RawProvider,
|
|
20
|
+
} from "./build.ts";
|
|
21
|
+
import { makeCatalog, type CatalogProvider, type PricingCatalog } from "./index.ts";
|
|
22
|
+
import type {
|
|
23
|
+
CategoryApplicability,
|
|
24
|
+
PricingContext,
|
|
25
|
+
PricingPolicy,
|
|
26
|
+
PricingResolver,
|
|
27
|
+
PricingSchedule,
|
|
28
|
+
PricingSource,
|
|
29
|
+
TokenCategory,
|
|
30
|
+
} from "../pricing.ts";
|
|
31
|
+
import { validatePricingPolicy } from "../pricing.ts";
|
|
32
|
+
|
|
33
|
+
const CATALOG_URL = "https://models.dev/api.json";
|
|
34
|
+
/** Long enough that a busy session makes one request; short enough to be "live". */
|
|
35
|
+
const DEFAULT_TTL_MS = 15 * 60 * 1000;
|
|
36
|
+
|
|
37
|
+
export interface LiveCatalogOptions {
|
|
38
|
+
/** Milliseconds a fetched catalog is reused. Default 15 minutes. */
|
|
39
|
+
readonly ttlMs?: number;
|
|
40
|
+
/** Override the endpoint, e.g. for an internal mirror. */
|
|
41
|
+
readonly url?: string;
|
|
42
|
+
/**
|
|
43
|
+
* What to do when the fetch fails.
|
|
44
|
+
*
|
|
45
|
+
* `"unpriced"` (default) returns null, so best-effort metering records real tokens with
|
|
46
|
+
* no price rather than stalling. `"throw"` surfaces the failure, which a strict mode
|
|
47
|
+
* turns into a preflight rejection before any provider work is dispatched.
|
|
48
|
+
*/
|
|
49
|
+
readonly onFetchError?: "unpriced" | "throw";
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
interface CachedCatalog {
|
|
53
|
+
readonly providers: Readonly<Record<string, CatalogProvider>>;
|
|
54
|
+
readonly source: PricingSource;
|
|
55
|
+
readonly fetchedAt: number;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
interface CatalogModel {
|
|
59
|
+
readonly categoryApplicability: Readonly<Record<string, string>>;
|
|
60
|
+
readonly lastUpdated?: string;
|
|
61
|
+
readonly schedules: readonly PricingSchedule[];
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Build a resolver that fetches models.dev on demand.
|
|
66
|
+
*
|
|
67
|
+
* The transform is the one shared with the build script, so a live policy is identical to
|
|
68
|
+
* the pinned one for any model whose upstream prices have not changed.
|
|
69
|
+
*/
|
|
70
|
+
export function createLiveModelsDevResolver(options: LiveCatalogOptions = {}): PricingResolver {
|
|
71
|
+
const ttlMs = options.ttlMs ?? DEFAULT_TTL_MS;
|
|
72
|
+
const url = options.url ?? CATALOG_URL;
|
|
73
|
+
const onFetchError = options.onFetchError ?? "unpriced";
|
|
74
|
+
|
|
75
|
+
let cached: CachedCatalog | null = null;
|
|
76
|
+
// One in-flight request shared by concurrent operations: a queue of prompts starting
|
|
77
|
+
// together must not each fetch several hundred KiB.
|
|
78
|
+
let inFlight: Promise<CachedCatalog | null> | null = null;
|
|
79
|
+
|
|
80
|
+
async function load(): Promise<CachedCatalog | null> {
|
|
81
|
+
if (cached && Date.now() - cached.fetchedAt < ttlMs) return cached;
|
|
82
|
+
if (inFlight) return inFlight;
|
|
83
|
+
|
|
84
|
+
inFlight = (async () => {
|
|
85
|
+
try {
|
|
86
|
+
const response = await fetch(url);
|
|
87
|
+
if (!response.ok) throw new Error(`models.dev returned ${response.status}`);
|
|
88
|
+
const payload = await response.text();
|
|
89
|
+
const raw = JSON.parse(payload) as Record<string, RawProvider>;
|
|
90
|
+
const { catalog } = buildCatalog(raw);
|
|
91
|
+
|
|
92
|
+
// Digest the SERIALIZED catalog, not the raw payload: it is the thing that
|
|
93
|
+
// determines prices, and it matches how the pinned artifact is identified.
|
|
94
|
+
const artifactSha256 = createHash("sha256")
|
|
95
|
+
.update(serializeCatalog(catalog), "utf8")
|
|
96
|
+
.digest("hex");
|
|
97
|
+
|
|
98
|
+
cached = {
|
|
99
|
+
providers: catalog.providers as CachedCatalog["providers"],
|
|
100
|
+
// Not `kind: "models.dev"`: that shape promises an upstream commit, and a
|
|
101
|
+
// live fetch has verified none. The digest and the fetch time are what this run
|
|
102
|
+
// can honestly assert about the prices it used.
|
|
103
|
+
source: Object.freeze({
|
|
104
|
+
kind: "models.dev_live",
|
|
105
|
+
artifactSha256,
|
|
106
|
+
fetchedAt: Date.now(),
|
|
107
|
+
}),
|
|
108
|
+
fetchedAt: Date.now(),
|
|
109
|
+
};
|
|
110
|
+
return cached;
|
|
111
|
+
} catch (err) {
|
|
112
|
+
if (onFetchError === "throw") throw err;
|
|
113
|
+
return null;
|
|
114
|
+
} finally {
|
|
115
|
+
inFlight = null;
|
|
116
|
+
}
|
|
117
|
+
})();
|
|
118
|
+
|
|
119
|
+
return inFlight;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
return async (context: PricingContext): Promise<PricingPolicy | null> => {
|
|
123
|
+
const { providerId, model } = context;
|
|
124
|
+
if (!providerId || !model) return null;
|
|
125
|
+
|
|
126
|
+
const catalog = await load();
|
|
127
|
+
if (!catalog) return null;
|
|
128
|
+
|
|
129
|
+
const entry = catalog.providers[providerId]?.models[model];
|
|
130
|
+
if (!entry) return null;
|
|
131
|
+
|
|
132
|
+
const policy: PricingPolicy = {
|
|
133
|
+
source: catalog.source,
|
|
134
|
+
providerId,
|
|
135
|
+
modelId: model,
|
|
136
|
+
categoryApplicability: entry.categoryApplicability as Readonly<
|
|
137
|
+
Record<TokenCategory, CategoryApplicability>
|
|
138
|
+
>,
|
|
139
|
+
...(entry.lastUpdated ? { modelLastUpdated: entry.lastUpdated } : {}),
|
|
140
|
+
schedules: entry.schedules,
|
|
141
|
+
};
|
|
142
|
+
return validatePricingPolicy(policy).ok ? policy : null;
|
|
143
|
+
};
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/**
|
|
147
|
+
* Fetch models.dev and return it as a readable catalog.
|
|
148
|
+
*
|
|
149
|
+
* The counterpart to `loadPinnedCatalog()` for consumers who want the current price list
|
|
150
|
+
* rather than the shipped one — to render a model picker, build a markup table, or diff
|
|
151
|
+
* against the pinned artifact to see what upstream changed.
|
|
152
|
+
*
|
|
153
|
+
* Unlike the resolver this does not cache: it is a deliberate one-shot fetch, so a caller
|
|
154
|
+
* showing a price list decides its own refresh policy.
|
|
155
|
+
*/
|
|
156
|
+
export async function fetchLiveCatalog(
|
|
157
|
+
options: Pick<LiveCatalogOptions, "url"> = {},
|
|
158
|
+
): Promise<PricingCatalog> {
|
|
159
|
+
const response = await fetch(options.url ?? CATALOG_URL);
|
|
160
|
+
if (!response.ok) throw new Error(`models.dev returned ${response.status}`);
|
|
161
|
+
const raw = (await response.json()) as Record<string, RawProvider>;
|
|
162
|
+
const { catalog } = buildCatalog(raw);
|
|
163
|
+
const artifactSha256 = createHash("sha256")
|
|
164
|
+
.update(serializeCatalog(catalog), "utf8")
|
|
165
|
+
.digest("hex");
|
|
166
|
+
return makeCatalog(catalog.providers as Readonly<Record<string, CatalogProvider>>, {
|
|
167
|
+
kind: "models.dev_live",
|
|
168
|
+
artifactSha256,
|
|
169
|
+
fetchedAt: Date.now(),
|
|
170
|
+
});
|
|
171
|
+
}
|