@agentproto/catalog-sync 0.7.4 → 0.8.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/index.mjs CHANGED
@@ -238,6 +238,56 @@ async function runGenerators(gens, opts) {
238
238
  }
239
239
  return { files, changed };
240
240
  }
241
+
242
+ // src/sources/openrouter-prompt-tiers.mjs
243
+ function round6(n) {
244
+ return Math.round(n * 1e6) / 1e6;
245
+ }
246
+ function per1m(tokenPrice) {
247
+ if (tokenPrice === void 0 || tokenPrice === null) return void 0;
248
+ const n = Number(tokenPrice);
249
+ return Number.isFinite(n) ? round6(n * 1e6) : void 0;
250
+ }
251
+ function promptLengthTiers(pricing) {
252
+ const overrides = pricing?.overrides;
253
+ if (!Array.isArray(overrides)) return void 0;
254
+ const byThreshold = /* @__PURE__ */ new Map();
255
+ for (const o of overrides) {
256
+ if (!o || typeof o !== "object") continue;
257
+ if (typeof o.min_prompt_tokens !== "number" || !(o.min_prompt_tokens > 0)) continue;
258
+ if (Object.keys(o).some((k) => k.startsWith("utc_"))) continue;
259
+ const inputPer1M = per1m(o.prompt);
260
+ const outputPer1M = per1m(o.completion);
261
+ if (inputPer1M === void 0 || outputPer1M === void 0) continue;
262
+ const tier = { aboveInputTokens: o.min_prompt_tokens, inputPer1M, outputPer1M };
263
+ const cacheRead = per1m(o.input_cache_read);
264
+ const cacheWrite = per1m(o.input_cache_write);
265
+ if (cacheRead !== void 0 && cacheRead > 0 && inputPer1M > 0) {
266
+ tier.cacheReadMultiplier = round6(cacheRead / inputPer1M);
267
+ }
268
+ if (cacheWrite !== void 0 && cacheWrite > 0 && inputPer1M > 0) {
269
+ tier.cacheWriteMultiplier = round6(cacheWrite / inputPer1M);
270
+ }
271
+ byThreshold.set(tier.aboveInputTokens, tier);
272
+ }
273
+ if (byThreshold.size === 0) return void 0;
274
+ return [...byThreshold.values()].sort((a, b) => a.aboveInputTokens - b.aboveInputTokens);
275
+ }
276
+ function serializeTiers(tiers) {
277
+ const items = tiers.map((t) => {
278
+ const fields = [
279
+ `aboveInputTokens: ${t.aboveInputTokens}`,
280
+ `inputPer1M: ${t.inputPer1M}`,
281
+ `outputPer1M: ${t.outputPer1M}`
282
+ ];
283
+ if (t.cacheReadMultiplier !== void 0) fields.push(`cacheReadMultiplier: ${t.cacheReadMultiplier}`);
284
+ if (t.cacheWriteMultiplier !== void 0) fields.push(`cacheWriteMultiplier: ${t.cacheWriteMultiplier}`);
285
+ return `{ ${fields.join(", ")} }`;
286
+ });
287
+ return `tiers: [${items.join(", ")}]`;
288
+ }
289
+
290
+ // src/generators/llm-openrouter.ts
241
291
  var OPENROUTER_MODELS_URL = "https://openrouter.ai/api/v1/models";
242
292
  var OUTPUT_PATH = "packages/model-catalog/src/llm/openrouter-routes.generated.ts";
243
293
  var PricingSchema = z.object({
@@ -254,18 +304,18 @@ var ModelSchema = z.object({
254
304
  var SnapshotSchema = z.object({
255
305
  data: z.array(ModelSchema)
256
306
  });
257
- function round6(n) {
307
+ function round62(n) {
258
308
  return Math.round(n * 1e6) / 1e6;
259
309
  }
260
- function per1m(tokenPrice) {
310
+ function per1m2(tokenPrice) {
261
311
  if (tokenPrice === void 0) return void 0;
262
312
  const n = Number(tokenPrice);
263
313
  if (!Number.isFinite(n)) return void 0;
264
- return round6(n * 1e6);
314
+ return round62(n * 1e6);
265
315
  }
266
316
  function fmt(n) {
267
317
  if (!Number.isFinite(n)) return "0";
268
- return `${round6(n)}`;
318
+ return `${round62(n)}`;
269
319
  }
270
320
  function vendorOf(id) {
271
321
  if (!id.includes("/")) return id;
@@ -282,6 +332,9 @@ function serializeEntry(e) {
282
332
  if (e.cacheWriteMultiplier !== void 0) {
283
333
  fields.push(`cacheWriteMultiplier: ${fmt(e.cacheWriteMultiplier)}`);
284
334
  }
335
+ if (e.tiers !== void 0) {
336
+ fields.push(serializeTiers(e.tiers));
337
+ }
285
338
  if (e.addedAt !== void 0) {
286
339
  fields.push(`addedAt: ${JSON.stringify(e.addedAt)}`);
287
340
  }
@@ -301,6 +354,7 @@ function serializeFile(entries) {
301
354
  "// Pricing carries provider USD (inputPer1M / outputPer1M) plus cache",
302
355
  "// multipliers (cacheReadMultiplier / cacheWriteMultiplier) derived from the",
303
356
  "// source's input_cache_read / input_cache_write per-token fields when present.",
357
+ "// tiers are the source's prompt-length price overrides (min_prompt_tokens).",
304
358
  "// addedAt is the ISO date this id was first seen by a sync run \u2014 backfilled",
305
359
  "// from the source's own `created` timestamp, then NEVER mutated; see",
306
360
  "// packages/catalog-sync/src/added-at.ts and the package README.",
@@ -333,8 +387,8 @@ async function generate(ctx) {
333
387
  for (const model of parsed.data) {
334
388
  const pricing = model.pricing;
335
389
  if (!pricing) continue;
336
- const inputPer1M = per1m(pricing.prompt);
337
- const outputPer1M = per1m(pricing.completion);
390
+ const inputPer1M = per1m2(pricing.prompt);
391
+ const outputPer1M = per1m2(pricing.completion);
338
392
  if (inputPer1M === void 0 || outputPer1M === void 0) continue;
339
393
  if (inputPer1M === 0 && outputPer1M === 0) continue;
340
394
  const entry = {
@@ -343,14 +397,16 @@ async function generate(ctx) {
343
397
  vendor: vendorOf(model.id),
344
398
  provider: "openrouter"
345
399
  };
346
- const cacheReadPer1M = per1m(pricing.input_cache_read);
347
- const cacheWritePer1M = per1m(pricing.input_cache_write);
400
+ const cacheReadPer1M = per1m2(pricing.input_cache_read);
401
+ const cacheWritePer1M = per1m2(pricing.input_cache_write);
348
402
  if (cacheReadPer1M !== void 0 && cacheReadPer1M > 0 && inputPer1M > 0) {
349
- entry.cacheReadMultiplier = round6(cacheReadPer1M / inputPer1M);
403
+ entry.cacheReadMultiplier = round62(cacheReadPer1M / inputPer1M);
350
404
  }
351
405
  if (cacheWritePer1M !== void 0 && cacheWritePer1M > 0 && inputPer1M > 0) {
352
- entry.cacheWriteMultiplier = round6(cacheWritePer1M / inputPer1M);
406
+ entry.cacheWriteMultiplier = round62(cacheWritePer1M / inputPer1M);
353
407
  }
408
+ const tiers = promptLengthTiers(pricing);
409
+ if (tiers) entry.tiers = tiers;
354
410
  entries[model.id] = entry;
355
411
  if (model.created !== void 0) createdAt[model.id] = isoDateFromUnixSeconds(model.created);
356
412
  }
@@ -386,17 +442,17 @@ var ModelSchema2 = z.object({
386
442
  var SnapshotSchema2 = z.object({
387
443
  data: z.array(ModelSchema2)
388
444
  });
389
- function round62(n) {
445
+ function round63(n) {
390
446
  return Math.round(n * 1e6) / 1e6;
391
447
  }
392
- function per1m2(tokenPrice) {
448
+ function per1m3(tokenPrice) {
393
449
  if (tokenPrice === void 0) return void 0;
394
450
  if (!Number.isFinite(tokenPrice)) return void 0;
395
- return round62(tokenPrice * 1e6);
451
+ return round63(tokenPrice * 1e6);
396
452
  }
397
453
  function fmt2(n) {
398
454
  if (!Number.isFinite(n)) return "0";
399
- return `${round62(n)}`;
455
+ return `${round63(n)}`;
400
456
  }
401
457
  function vendorOf2(id) {
402
458
  if (!id.includes("/")) return id;
@@ -460,8 +516,8 @@ async function generate2(ctx) {
460
516
  const entries = {};
461
517
  const createdAt = {};
462
518
  for (const model of parsed.data) {
463
- const inputPer1M = per1m2(model.input_price);
464
- const outputPer1M = per1m2(model.output_price);
519
+ const inputPer1M = per1m3(model.input_price);
520
+ const outputPer1M = per1m3(model.output_price);
465
521
  if (inputPer1M === void 0 || outputPer1M === void 0) continue;
466
522
  if (inputPer1M === 0 && outputPer1M === 0) continue;
467
523
  const entry = {
@@ -471,9 +527,9 @@ async function generate2(ctx) {
471
527
  provider: "requesty"
472
528
  };
473
529
  if (model.supports_caching === true && inputPer1M > 0) {
474
- const cachePer1M = per1m2(model.cached_price);
530
+ const cachePer1M = per1m3(model.cached_price);
475
531
  if (cachePer1M !== void 0) {
476
- entry.cacheReadMultiplier = round62(cachePer1M / inputPer1M);
532
+ entry.cacheReadMultiplier = round63(cachePer1M / inputPer1M);
477
533
  }
478
534
  }
479
535
  entries[model.id] = entry;
@@ -537,17 +593,17 @@ var ProviderSchema = z.object({
537
593
  models: z.record(z.string(), ModelSchema3).optional()
538
594
  }).passthrough();
539
595
  var SnapshotSchema3 = z.record(z.string(), ProviderSchema);
540
- function round63(n) {
596
+ function round64(n) {
541
597
  return Math.round(n * 1e6) / 1e6;
542
598
  }
543
599
  function fmt3(n) {
544
600
  if (!Number.isFinite(n)) return "0";
545
- return `${round63(n)}`;
601
+ return `${round64(n)}`;
546
602
  }
547
603
  function cacheMultiplier(cachePer1M, inputPer1M) {
548
604
  if (cachePer1M === void 0 || !Number.isFinite(cachePer1M)) return void 0;
549
605
  if (inputPer1M <= 0) return void 0;
550
- return round63(cachePer1M / inputPer1M);
606
+ return round64(cachePer1M / inputPer1M);
551
607
  }
552
608
  var VENDOR_BY_ID_PREFIX = [
553
609
  [/^claude-/, "anthropic"],
@@ -720,8 +776,8 @@ async function generateFor(endpoint, source, ctx) {
720
776
  if (!Number.isFinite(inputPer1M) || !Number.isFinite(outputPer1M)) continue;
721
777
  const key = routeKey(endpoint.providerKey, bareId);
722
778
  const entry = {
723
- inputPer1M: round63(inputPer1M),
724
- outputPer1M: round63(outputPer1M),
779
+ inputPer1M: round64(inputPer1M),
780
+ outputPer1M: round64(outputPer1M),
725
781
  vendor: vendorForOpencodeModelId(bareId),
726
782
  provider: endpoint.providerKey
727
783
  };