@bytesbrains/cruise-worker 0.15.0 → 0.16.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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bytesbrains/cruise-worker",
3
- "version": "0.15.0",
3
+ "version": "0.16.0",
4
4
  "description": "The Cruise Worker, built and ready to deploy: one OpenAI-compatible endpoint in front of every model provider, with budgets that stop.",
5
5
  "license": "Apache-2.0",
6
6
  "type": "module",
package/worker/VERSION CHANGED
@@ -1 +1 @@
1
- 0.15.0+5410a035
1
+ 0.16.0+12e15204
package/worker/index.js CHANGED
@@ -8725,10 +8725,6 @@ function parseFrame(payload) {
8725
8725
  }
8726
8726
  __name(parseFrame, "parseFrame");
8727
8727
  var Translation = class {
8728
- constructor(model) {
8729
- this.model = model;
8730
- }
8731
- model;
8732
8728
  static {
8733
8729
  __name(this, "Translation");
8734
8730
  }
@@ -8740,6 +8736,10 @@ var Translation = class {
8740
8736
  usage = null;
8741
8737
  calledTool = false;
8742
8738
  done = false;
8739
+ model;
8740
+ constructor(model) {
8741
+ this.model = model;
8742
+ }
8743
8743
  start() {
8744
8744
  return [
8745
8745
  frame("message_start", {
@@ -11101,15 +11101,15 @@ var compressionRoutes = /* @__PURE__ */ __name(async ({ request, env, path, call
11101
11101
  if (typeof body?.enabled !== "boolean") {
11102
11102
  return errorResponse(400, "invalid_request_error", "'enabled' is required and must be true or false.", { headers: cors });
11103
11103
  }
11104
- const written2 = await setProjectCompression(
11104
+ const written = await setProjectCompression(
11105
11105
  env.DB,
11106
11106
  projectId,
11107
11107
  body.enabled,
11108
11108
  // The person, never the credential — the rule `tiers.ts` states.
11109
11109
  caller.identity.email ?? caller.identity.uid
11110
11110
  );
11111
- if (written2 === null) return noSuchProject(env.DB, caller.tenantId, projectId, cors);
11112
- return json({ project: projectId, compression: compressionView({ enabled: written2.enabled, modeInForce: compressModeOf(env) }) }, cors);
11111
+ if (written === null) return noSuchProject(env.DB, caller.tenantId, projectId, cors);
11112
+ return json({ project: projectId, compression: compressionView({ enabled: written.enabled, modeInForce: compressModeOf(env) }) }, cors);
11113
11113
  }, "compressionRoutes");
11114
11114
 
11115
11115
  // src/admin-fallbacks.ts
@@ -11387,18 +11387,244 @@ var keyRoutes = /* @__PURE__ */ __name(async ({ request, env, path, caller, cors
11387
11387
  return null;
11388
11388
  }, "keyRoutes");
11389
11389
 
11390
+ // src/lanes-warnings.ts
11391
+ var DEAR_FACTOR = 10;
11392
+ var JOB_IMPLIES = {
11393
+ "code-review": ["tools"],
11394
+ "agentic-coding": ["tools"],
11395
+ hunter: ["tools"],
11396
+ builder: ["tools"],
11397
+ "computer-use": ["tools", "vision"],
11398
+ "document-understanding": ["vision"],
11399
+ extraction: ["json_schema"],
11400
+ "rag-grounded-answers": ["json_schema"],
11401
+ "web-search": ["web_search"]
11402
+ };
11403
+ function worstCaseRate(price) {
11404
+ let input = price.input_micros_per_mtok;
11405
+ let output = price.output_micros_per_mtok;
11406
+ for (const v of price.variants) {
11407
+ input = Math.max(input, v.input_micros_per_mtok);
11408
+ output = Math.max(output, v.output_micros_per_mtok);
11409
+ }
11410
+ return input + output;
11411
+ }
11412
+ __name(worstCaseRate, "worstCaseRate");
11413
+ var perMillion = /* @__PURE__ */ __name((micros) => `$${(micros / 1e6).toFixed(2)}/M`, "perMillion");
11414
+ function laneWarnings(lane, members, routable, prices, reliability = /* @__PURE__ */ new Map(), billable = false) {
11415
+ const warnings = [];
11416
+ for (const id of lane.memberIds) {
11417
+ const r = reliability.get(id);
11418
+ if (unreliable(r)) {
11419
+ warnings.push({
11420
+ code: "unreliable_member",
11421
+ member: id,
11422
+ message: `'${id}' was refused by its provider on ${Math.round(r.failure_share * 100)}% of ${r.requests} requests in the last ${r.window_days} days (${r.rate_limited} rate-limited, ${r.upstream_errors} errored, ${r.refused} refused a lane's request); on this lane it will be tried after every member that was not, and a pinned request to it will fail that often.`
11423
+ });
11424
+ }
11425
+ }
11426
+ const present2 = lane.memberIds.map((id) => members.get(id)).filter((m) => m !== void 0);
11427
+ const serving = present2.filter(
11428
+ (m) => routable.has(m.id) && unmetRequirements(m, lane).length === 0 && !excludedByNamespace(m, lane)
11429
+ );
11430
+ const hosts = new Set(serving.map((m) => m.upstreamId));
11431
+ if (hosts.size === 1 && serving.length > 1) {
11432
+ warnings.push({
11433
+ code: "one_upstream",
11434
+ message: `Every member this lane can allocate to is on '${[...hosts][0]}'. A provider that rate-limits per organisation, or whose credential expires, refuses all of them at once \u2014 so the fallback chain has one point of failure whatever its depth. A member on another host is what makes falling over mean anything.`
11435
+ });
11436
+ }
11437
+ for (const id of lane.memberIds) {
11438
+ const member = members.get(id);
11439
+ if (member !== void 0 && routable.has(id)) {
11440
+ const unmet = unmetRequirements(member, lane);
11441
+ if (unmet.length > 0) {
11442
+ warnings.push({
11443
+ code: "unroutable_member",
11444
+ member: id,
11445
+ message: `'${id}' fails the lane's requirement${unmet.length > 1 ? "s" : ""} ${unmet.map((u) => `'${u}'`).join(", ")} and will not serve on it.`
11446
+ });
11447
+ } else if (excludedByNamespace(member, lane)) {
11448
+ warnings.push({
11449
+ code: "unroutable_member",
11450
+ member: id,
11451
+ message: `'${id}' no longer trains on the traffic it serves and will not serve on this contributor lane.`
11452
+ });
11453
+ }
11454
+ continue;
11455
+ }
11456
+ if (routable.has(id)) continue;
11457
+ const block = member === void 0 ? null : billingBlockOf(member, prices.has(id));
11458
+ const why = member === void 0 ? "is not in the routing table" : !member.enabled ? "is disabled" : member.measuredAt === null ? "has not been measured; it will not serve until the next conformance run" : verificationOf(member, /* @__PURE__ */ new Date()) === "stale" ? "has a stale measurement; it will not serve until measured again" : billable && block === "unpriced" ? "has no price in force; this tenant is billed, so it will not serve until one is" : billable && block === "usage_unreported" ? "does not report token usage; this tenant is billed, so it cannot serve" : "is not routable";
11459
+ warnings.push({ code: "unroutable_member", member: id, message: `'${id}' ${why}.` });
11460
+ }
11461
+ const priced = present2.map((m) => ({ id: m.id, rate: prices.get(m.id) })).filter((p) => p.rate !== void 0).map((p) => ({ id: p.id, worst: worstCaseRate(p.rate) }));
11462
+ if (priced.length > 1) {
11463
+ const cheapest = priced.reduce((a, b) => b.worst < a.worst ? b : a);
11464
+ if (cheapest.worst > 0) {
11465
+ for (const p of priced) {
11466
+ const factor = p.worst / cheapest.worst;
11467
+ if (factor >= DEAR_FACTOR) {
11468
+ warnings.push({
11469
+ code: "dear_member",
11470
+ member: p.id,
11471
+ message: `'${p.id}' is ${Math.round(factor)}\xD7 '${cheapest.id}' at worst case (${perMillion(p.worst)} against ${perMillion(cheapest.worst)}, input and output); ` + (lane.selection === "cheap" ? `it will serve only when every cheaper member is rejected by a gate.` : `under '${lane.selection}' selection it serves its share of requests, not only when every cheaper member is rejected.`)
11472
+ });
11473
+ }
11474
+ }
11475
+ }
11476
+ }
11477
+ const windows = present2.filter((m) => m.maxContext !== null).map((m) => ({ id: m.id, window: m.maxContext }));
11478
+ if (windows.length > 1) {
11479
+ const largest = Math.max(...windows.map((w) => w.window));
11480
+ const smallest = Math.min(...windows.map((w) => w.window));
11481
+ if (smallest < largest) {
11482
+ for (const w of windows.filter((w2) => w2.window === smallest)) {
11483
+ warnings.push({
11484
+ code: "narrow_member",
11485
+ member: w.id,
11486
+ message: `Including '${w.id}' caps the lane's context window at ${w.window.toLocaleString("en-US")} tokens; the largest member takes ${largest.toLocaleString("en-US")}.`
11487
+ });
11488
+ }
11489
+ }
11490
+ }
11491
+ const outputs = present2.filter((m) => m.maxOutput !== null).map((m) => ({ id: m.id, cap: m.maxOutput }));
11492
+ if (outputs.length > 1) {
11493
+ const largest = Math.max(...outputs.map((o) => o.cap));
11494
+ const smallest = Math.min(...outputs.map((o) => o.cap));
11495
+ if (smallest < largest) {
11496
+ for (const o of outputs.filter((o2) => o2.cap === smallest)) {
11497
+ warnings.push({
11498
+ code: "narrow_member",
11499
+ member: o.id,
11500
+ message: `Including '${o.id}' caps the lane's output at ${o.cap.toLocaleString("en-US")} tokens; the largest member allows ${largest.toLocaleString("en-US")}.`
11501
+ });
11502
+ }
11503
+ }
11504
+ }
11505
+ const implied = Object.hasOwn(JOB_IMPLIES, lane.job) ? JOB_IMPLIES[lane.job] : [];
11506
+ const routableMembers = present2.filter(
11507
+ (m) => routable.has(m.id) && unmetRequirements(m, lane).length === 0 && !excludedByNamespace(m, lane)
11508
+ );
11509
+ for (const capability of implied) {
11510
+ const cannot = routableMembers.filter((m) => {
11511
+ const flag2 = { tools: m.tools, vision: m.vision, json_schema: m.jsonSchema, web_search: m.webSearch }[capability];
11512
+ return flag2 === false;
11513
+ });
11514
+ if (cannot.length > 0) {
11515
+ const all = cannot.length === routableMembers.length;
11516
+ warnings.push({
11517
+ code: "job_capability",
11518
+ message: `A '${lane.job}' lane implies ${capability}, and ` + (all ? `none of its routable members supports it: ${cannot.map((m) => `'${m.id}'`).join(", ")}.` : `${cannot.map((m) => `'${m.id}'`).join(", ")} cannot; a request needing it will never be allocated there.`)
11519
+ });
11520
+ }
11521
+ }
11522
+ if (lane.selection === "graduated" && lane.weights.some((weight) => weight !== DEFAULT_WEIGHT)) {
11523
+ warnings.push({
11524
+ code: "weights_ignored",
11525
+ message: `This lane is 'graduated', which works each member's share out from its quality_rank (or allocator position when unranked), so the weights it stores are not read. They are kept, so switching back to 'weighted' restores them.`
11526
+ });
11527
+ }
11528
+ return warnings;
11529
+ }
11530
+ __name(laneWarnings, "laneWarnings");
11531
+
11532
+ // src/lanes-describe.ts
11533
+ async function describeLane(db, lane, billable, now) {
11534
+ const routable = await listRoutableModels(db, now);
11535
+ const prices = await pricesInForce(
11536
+ db,
11537
+ lane.memberIds,
11538
+ tokenlessOf(routable.filter((m) => lane.memberIds.includes(m.id)))
11539
+ );
11540
+ const listed = new Map(
11541
+ routable.filter((m) => !billable || billingBlockOf(m, prices.has(m.id)) === null).map((m) => [m.id, m])
11542
+ );
11543
+ const summary = summariseLane(lane, listed, prices);
11544
+ const members = /* @__PURE__ */ new Map();
11545
+ for (const id of lane.memberIds) {
11546
+ const member = listed.get(id) ?? await lookupModel(db, id);
11547
+ if (member !== null && member !== void 0) members.set(id, member);
11548
+ }
11549
+ return {
11550
+ id: lane.id,
11551
+ tenant: lane.tenantId,
11552
+ global: lane.tenantId === null,
11553
+ job: lane.job,
11554
+ description: lane.description,
11555
+ enabled: lane.enabled,
11556
+ archived_at: lane.archivedAt,
11557
+ members: lane.memberIds,
11558
+ weights: lane.weights,
11559
+ quality_ranks: lane.qualityRanks,
11560
+ selection: lane.selection,
11561
+ cache_ttl_seconds: lane.cacheTtlSeconds,
11562
+ cache_scope: lane.cacheScope,
11563
+ compress: lane.compress,
11564
+ max_chain: lane.maxChain,
11565
+ // What the lane's depth resolves to, so a reader never has to know the
11566
+ // platform constant to render "Platform default (3)" — the same courtesy
11567
+ // `selection_in_force` pays on `GET /admin/settings` (#288). Null above
11568
+ // is "nothing chosen"; this is what nothing-chosen means today, and it
11569
+ // moves when `MAX_CHAIN` does without anybody editing a lane.
11570
+ max_chain_in_force: lane.maxChain ?? MAX_CHAIN,
11571
+ router: lane.router,
11572
+ router_input: lane.routerInput,
11573
+ requires: lane.requires,
11574
+ created_by: lane.createdBy,
11575
+ created_at: lane.createdAt,
11576
+ updated_at: lane.updatedAt,
11577
+ // What the lane will actually do, said here rather than on the invoice
11578
+ // (#70). Never a refusal; computed from the same inputs as `catalog`.
11579
+ warnings: laneWarnings(lane, members, new Set(listed.keys()), prices, await reliabilityOf(db, lane.memberIds, now), billable),
11580
+ // Null when no member is routable: the lane exists and will list nothing
11581
+ // until conformance measures one of them.
11582
+ catalog: summary === null ? null : {
11583
+ routable_members: summary.members,
11584
+ modality: summary.modality,
11585
+ tools: summary.tools,
11586
+ parallel_tool_calls: summary.parallelToolCalls,
11587
+ tool_choice_forced: summary.toolChoiceForced,
11588
+ web_search: summary.webSearch,
11589
+ streaming: summary.streaming,
11590
+ json_schema: summary.jsonSchema,
11591
+ vision: summary.vision,
11592
+ // Omitted here while `/v1/models` reported it and the schema
11593
+ // declared it, so a client typing `Lane.catalog` got a field that
11594
+ // was permanently undefined on the control plane and present on the
11595
+ // data plane. The two describe the same lane and must not disagree
11596
+ // about which fields exist (#85).
11597
+ usage_reported: summary.usageReported,
11598
+ max_context: summary.maxContext,
11599
+ max_output: summary.maxOutput,
11600
+ output_limit: summary.outputLimit,
11601
+ any_member: anyMemberJson(summary.anyMember),
11602
+ data_retention: summary.dataRetention,
11603
+ pricing: summary.pricing
11604
+ }
11605
+ };
11606
+ }
11607
+ __name(describeLane, "describeLane");
11608
+ async function describeWritten(db, lane, tenantId, billable, now) {
11609
+ const described = await describeLane(db, lane, billable, now);
11610
+ if (lane.tenantId === null) return described;
11611
+ const warning = quotaWarning(await tierOf(db, tenantId), await lanesUsed(db, tenantId));
11612
+ return warning === null ? described : { ...described, warnings: [...described.warnings, warning] };
11613
+ }
11614
+ __name(describeWritten, "describeWritten");
11615
+
11390
11616
  // src/lanes-validate.ts
11391
11617
  var LaneWriteError = class extends Error {
11618
+ static {
11619
+ __name(this, "LaneWriteError");
11620
+ }
11621
+ status;
11622
+ code;
11392
11623
  constructor(status, message, code = null) {
11393
11624
  super(message);
11394
11625
  this.status = status;
11395
11626
  this.code = code;
11396
11627
  }
11397
- status;
11398
- code;
11399
- static {
11400
- __name(this, "LaneWriteError");
11401
- }
11402
11628
  };
11403
11629
  var JOBS = [
11404
11630
  "chat-assistant",
@@ -11621,14 +11847,16 @@ __name(validQualityRanks, "validQualityRanks");
11621
11847
 
11622
11848
  // src/tenant-settings.ts
11623
11849
  var SettingsError = class extends Error {
11850
+ static {
11851
+ __name(this, "SettingsError");
11852
+ }
11853
+ // Assigned, not a parameter property: `lane:create` reaches this file
11854
+ // under plain `node`, which refuses that syntax (see LaneWriteError).
11855
+ status;
11624
11856
  constructor(status, message) {
11625
11857
  super(message);
11626
11858
  this.status = status;
11627
11859
  }
11628
- status;
11629
- static {
11630
- __name(this, "SettingsError");
11631
- }
11632
11860
  };
11633
11861
  function selectionInForce(settings2) {
11634
11862
  return settings2.defaultSelection ?? DEFAULT_SELECTION;
@@ -11862,224 +12090,7 @@ async function disableLane(db, request) {
11862
12090
  }
11863
12091
  __name(disableLane, "disableLane");
11864
12092
 
11865
- // src/lanes-warnings.ts
11866
- var DEAR_FACTOR = 10;
11867
- var JOB_IMPLIES = {
11868
- "code-review": ["tools"],
11869
- "agentic-coding": ["tools"],
11870
- hunter: ["tools"],
11871
- builder: ["tools"],
11872
- "computer-use": ["tools", "vision"],
11873
- "document-understanding": ["vision"],
11874
- extraction: ["json_schema"],
11875
- "rag-grounded-answers": ["json_schema"],
11876
- "web-search": ["web_search"]
11877
- };
11878
- function worstCaseRate(price) {
11879
- let input = price.input_micros_per_mtok;
11880
- let output = price.output_micros_per_mtok;
11881
- for (const v of price.variants) {
11882
- input = Math.max(input, v.input_micros_per_mtok);
11883
- output = Math.max(output, v.output_micros_per_mtok);
11884
- }
11885
- return input + output;
11886
- }
11887
- __name(worstCaseRate, "worstCaseRate");
11888
- var perMillion = /* @__PURE__ */ __name((micros) => `$${(micros / 1e6).toFixed(2)}/M`, "perMillion");
11889
- function laneWarnings(lane, members, routable, prices, reliability = /* @__PURE__ */ new Map(), billable = false) {
11890
- const warnings = [];
11891
- for (const id of lane.memberIds) {
11892
- const r = reliability.get(id);
11893
- if (unreliable(r)) {
11894
- warnings.push({
11895
- code: "unreliable_member",
11896
- member: id,
11897
- message: `'${id}' was refused by its provider on ${Math.round(r.failure_share * 100)}% of ${r.requests} requests in the last ${r.window_days} days (${r.rate_limited} rate-limited, ${r.upstream_errors} errored, ${r.refused} refused a lane's request); on this lane it will be tried after every member that was not, and a pinned request to it will fail that often.`
11898
- });
11899
- }
11900
- }
11901
- const present2 = lane.memberIds.map((id) => members.get(id)).filter((m) => m !== void 0);
11902
- const serving = present2.filter(
11903
- (m) => routable.has(m.id) && unmetRequirements(m, lane).length === 0 && !excludedByNamespace(m, lane)
11904
- );
11905
- const hosts = new Set(serving.map((m) => m.upstreamId));
11906
- if (hosts.size === 1 && serving.length > 1) {
11907
- warnings.push({
11908
- code: "one_upstream",
11909
- message: `Every member this lane can allocate to is on '${[...hosts][0]}'. A provider that rate-limits per organisation, or whose credential expires, refuses all of them at once \u2014 so the fallback chain has one point of failure whatever its depth. A member on another host is what makes falling over mean anything.`
11910
- });
11911
- }
11912
- for (const id of lane.memberIds) {
11913
- const member = members.get(id);
11914
- if (member !== void 0 && routable.has(id)) {
11915
- const unmet = unmetRequirements(member, lane);
11916
- if (unmet.length > 0) {
11917
- warnings.push({
11918
- code: "unroutable_member",
11919
- member: id,
11920
- message: `'${id}' fails the lane's requirement${unmet.length > 1 ? "s" : ""} ${unmet.map((u) => `'${u}'`).join(", ")} and will not serve on it.`
11921
- });
11922
- } else if (excludedByNamespace(member, lane)) {
11923
- warnings.push({
11924
- code: "unroutable_member",
11925
- member: id,
11926
- message: `'${id}' no longer trains on the traffic it serves and will not serve on this contributor lane.`
11927
- });
11928
- }
11929
- continue;
11930
- }
11931
- if (routable.has(id)) continue;
11932
- const block = member === void 0 ? null : billingBlockOf(member, prices.has(id));
11933
- const why = member === void 0 ? "is not in the routing table" : !member.enabled ? "is disabled" : member.measuredAt === null ? "has not been measured; it will not serve until the next conformance run" : verificationOf(member, /* @__PURE__ */ new Date()) === "stale" ? "has a stale measurement; it will not serve until measured again" : billable && block === "unpriced" ? "has no price in force; this tenant is billed, so it will not serve until one is" : billable && block === "usage_unreported" ? "does not report token usage; this tenant is billed, so it cannot serve" : "is not routable";
11934
- warnings.push({ code: "unroutable_member", member: id, message: `'${id}' ${why}.` });
11935
- }
11936
- const priced = present2.map((m) => ({ id: m.id, rate: prices.get(m.id) })).filter((p) => p.rate !== void 0).map((p) => ({ id: p.id, worst: worstCaseRate(p.rate) }));
11937
- if (priced.length > 1) {
11938
- const cheapest = priced.reduce((a, b) => b.worst < a.worst ? b : a);
11939
- if (cheapest.worst > 0) {
11940
- for (const p of priced) {
11941
- const factor = p.worst / cheapest.worst;
11942
- if (factor >= DEAR_FACTOR) {
11943
- warnings.push({
11944
- code: "dear_member",
11945
- member: p.id,
11946
- message: `'${p.id}' is ${Math.round(factor)}\xD7 '${cheapest.id}' at worst case (${perMillion(p.worst)} against ${perMillion(cheapest.worst)}, input and output); ` + (lane.selection === "cheap" ? `it will serve only when every cheaper member is rejected by a gate.` : `under '${lane.selection}' selection it serves its share of requests, not only when every cheaper member is rejected.`)
11947
- });
11948
- }
11949
- }
11950
- }
11951
- }
11952
- const windows = present2.filter((m) => m.maxContext !== null).map((m) => ({ id: m.id, window: m.maxContext }));
11953
- if (windows.length > 1) {
11954
- const largest = Math.max(...windows.map((w) => w.window));
11955
- const smallest = Math.min(...windows.map((w) => w.window));
11956
- if (smallest < largest) {
11957
- for (const w of windows.filter((w2) => w2.window === smallest)) {
11958
- warnings.push({
11959
- code: "narrow_member",
11960
- member: w.id,
11961
- message: `Including '${w.id}' caps the lane's context window at ${w.window.toLocaleString("en-US")} tokens; the largest member takes ${largest.toLocaleString("en-US")}.`
11962
- });
11963
- }
11964
- }
11965
- }
11966
- const outputs = present2.filter((m) => m.maxOutput !== null).map((m) => ({ id: m.id, cap: m.maxOutput }));
11967
- if (outputs.length > 1) {
11968
- const largest = Math.max(...outputs.map((o) => o.cap));
11969
- const smallest = Math.min(...outputs.map((o) => o.cap));
11970
- if (smallest < largest) {
11971
- for (const o of outputs.filter((o2) => o2.cap === smallest)) {
11972
- warnings.push({
11973
- code: "narrow_member",
11974
- member: o.id,
11975
- message: `Including '${o.id}' caps the lane's output at ${o.cap.toLocaleString("en-US")} tokens; the largest member allows ${largest.toLocaleString("en-US")}.`
11976
- });
11977
- }
11978
- }
11979
- }
11980
- const implied = Object.hasOwn(JOB_IMPLIES, lane.job) ? JOB_IMPLIES[lane.job] : [];
11981
- const routableMembers = present2.filter(
11982
- (m) => routable.has(m.id) && unmetRequirements(m, lane).length === 0 && !excludedByNamespace(m, lane)
11983
- );
11984
- for (const capability of implied) {
11985
- const cannot = routableMembers.filter((m) => {
11986
- const flag2 = { tools: m.tools, vision: m.vision, json_schema: m.jsonSchema, web_search: m.webSearch }[capability];
11987
- return flag2 === false;
11988
- });
11989
- if (cannot.length > 0) {
11990
- const all = cannot.length === routableMembers.length;
11991
- warnings.push({
11992
- code: "job_capability",
11993
- message: `A '${lane.job}' lane implies ${capability}, and ` + (all ? `none of its routable members supports it: ${cannot.map((m) => `'${m.id}'`).join(", ")}.` : `${cannot.map((m) => `'${m.id}'`).join(", ")} cannot; a request needing it will never be allocated there.`)
11994
- });
11995
- }
11996
- }
11997
- if (lane.selection === "graduated" && lane.weights.some((weight) => weight !== DEFAULT_WEIGHT)) {
11998
- warnings.push({
11999
- code: "weights_ignored",
12000
- message: `This lane is 'graduated', which works each member's share out from its quality_rank (or allocator position when unranked), so the weights it stores are not read. They are kept, so switching back to 'weighted' restores them.`
12001
- });
12002
- }
12003
- return warnings;
12004
- }
12005
- __name(laneWarnings, "laneWarnings");
12006
-
12007
12093
  // src/admin-lanes.ts
12008
- async function describe(env, lane, caller, now) {
12009
- const routable = await listRoutableModels(env.DB, now);
12010
- const prices = await pricesInForce(
12011
- env.DB,
12012
- lane.memberIds,
12013
- tokenlessOf(routable.filter((m) => lane.memberIds.includes(m.id)))
12014
- );
12015
- const listed = new Map(
12016
- routable.filter((m) => !caller.billable || billingBlockOf(m, prices.has(m.id)) === null).map((m) => [m.id, m])
12017
- );
12018
- const summary = summariseLane(lane, listed, prices);
12019
- const members = /* @__PURE__ */ new Map();
12020
- for (const id of lane.memberIds) {
12021
- const member = listed.get(id) ?? await lookupModel(env.DB, id);
12022
- if (member !== null && member !== void 0) members.set(id, member);
12023
- }
12024
- return {
12025
- id: lane.id,
12026
- tenant: lane.tenantId,
12027
- global: lane.tenantId === null,
12028
- job: lane.job,
12029
- description: lane.description,
12030
- enabled: lane.enabled,
12031
- archived_at: lane.archivedAt,
12032
- members: lane.memberIds,
12033
- weights: lane.weights,
12034
- quality_ranks: lane.qualityRanks,
12035
- selection: lane.selection,
12036
- cache_ttl_seconds: lane.cacheTtlSeconds,
12037
- cache_scope: lane.cacheScope,
12038
- compress: lane.compress,
12039
- max_chain: lane.maxChain,
12040
- // What the lane's depth resolves to, so a reader never has to know the
12041
- // platform constant to render "Platform default (3)" — the same courtesy
12042
- // `selection_in_force` pays on `GET /admin/settings` (#288). Null above
12043
- // is "nothing chosen"; this is what nothing-chosen means today, and it
12044
- // moves when `MAX_CHAIN` does without anybody editing a lane.
12045
- max_chain_in_force: lane.maxChain ?? MAX_CHAIN,
12046
- router: lane.router,
12047
- router_input: lane.routerInput,
12048
- requires: lane.requires,
12049
- created_by: lane.createdBy,
12050
- created_at: lane.createdAt,
12051
- updated_at: lane.updatedAt,
12052
- // What the lane will actually do, said here rather than on the invoice
12053
- // (#70). Never a refusal; computed from the same inputs as `catalog`.
12054
- warnings: laneWarnings(lane, members, new Set(listed.keys()), prices, await reliabilityOf(env.DB, lane.memberIds, now), caller.billable),
12055
- // Null when no member is routable: the lane exists and will list nothing
12056
- // until conformance measures one of them.
12057
- catalog: summary === null ? null : {
12058
- routable_members: summary.members,
12059
- modality: summary.modality,
12060
- tools: summary.tools,
12061
- parallel_tool_calls: summary.parallelToolCalls,
12062
- tool_choice_forced: summary.toolChoiceForced,
12063
- web_search: summary.webSearch,
12064
- streaming: summary.streaming,
12065
- json_schema: summary.jsonSchema,
12066
- vision: summary.vision,
12067
- // Omitted here while `/v1/models` reported it and the schema
12068
- // declared it, so a client typing `Lane.catalog` got a field that
12069
- // was permanently undefined on the control plane and present on the
12070
- // data plane. The two describe the same lane and must not disagree
12071
- // about which fields exist (#85).
12072
- usage_reported: summary.usageReported,
12073
- max_context: summary.maxContext,
12074
- max_output: summary.maxOutput,
12075
- output_limit: summary.outputLimit,
12076
- any_member: anyMemberJson(summary.anyMember),
12077
- data_retention: summary.dataRetention,
12078
- pricing: summary.pricing
12079
- }
12080
- };
12081
- }
12082
- __name(describe, "describe");
12083
12094
  function refused2(error2, cors) {
12084
12095
  if (error2 instanceof LaneWriteError) {
12085
12096
  const type = error2.status === 403 ? "permission_error" : "invalid_request_error";
@@ -12091,20 +12102,13 @@ function refused2(error2, cors) {
12091
12102
  return null;
12092
12103
  }
12093
12104
  __name(refused2, "refused");
12094
- async function written(env, lane, caller, now) {
12095
- const described = await describe(env, lane, caller, now);
12096
- if (lane.tenantId === null) return described;
12097
- const warning = quotaWarning(await tierOf(env.DB, caller.tenantId), await lanesUsed(env.DB, caller.tenantId));
12098
- return warning === null ? described : { ...described, warnings: [...described.warnings, warning] };
12099
- }
12100
- __name(written, "written");
12101
12105
  var laneRoutes = /* @__PURE__ */ __name(async ({ request, env, url, path, caller, cors, now, mustWrite }) => {
12102
12106
  if (path === "/lanes" && request.method === "GET") {
12103
12107
  const lanes = await listLanes(env.DB, caller.tenantId, {
12104
12108
  includeDisabled: true,
12105
12109
  includeArchived: url.searchParams.get("archived") !== null
12106
12110
  });
12107
- return json({ lanes: await Promise.all(lanes.map((lane) => describe(env, lane, caller, now))) }, cors);
12111
+ return json({ lanes: await Promise.all(lanes.map((lane) => describeLane(env.DB, lane, caller.billable, now))) }, cors);
12108
12112
  }
12109
12113
  if (path === "/lanes" && request.method === "POST") {
12110
12114
  const refusal = mustWrite();
@@ -12137,7 +12141,7 @@ var laneRoutes = /* @__PURE__ */ __name(async ({ request, env, url, path, caller
12137
12141
  // Passed as sent, not coerced: `validCompress` refuses anything but a boolean.
12138
12142
  ...body.compress !== void 0 ? { compress: body.compress } : {}
12139
12143
  });
12140
- return json(await written(env, lane, caller, now), cors, 201);
12144
+ return json(await describeWritten(env.DB, lane, caller.tenantId, caller.billable, now), cors, 201);
12141
12145
  } catch (error2) {
12142
12146
  return refused2(error2, cors) ?? Promise.reject(error2);
12143
12147
  }
@@ -12191,7 +12195,7 @@ var laneRoutes = /* @__PURE__ */ __name(async ({ request, env, url, path, caller
12191
12195
  if (request.method === "GET") {
12192
12196
  const lane = await lookupLane(env.DB, id, caller.tenantId);
12193
12197
  if (lane === null) return errorResponse(404, "invalid_request_error", "No such lane.", { headers: cors });
12194
- return json(await describe(env, lane, caller, now), cors);
12198
+ return json(await describeLane(env.DB, lane, caller.billable, now), cors);
12195
12199
  }
12196
12200
  if (request.method === "PUT" || request.method === "DELETE") {
12197
12201
  const refusal = mustWrite();
@@ -12200,7 +12204,7 @@ var laneRoutes = /* @__PURE__ */ __name(async ({ request, env, url, path, caller
12200
12204
  const actor = caller.identity.email ?? caller.identity.uid;
12201
12205
  try {
12202
12206
  if (request.method === "DELETE") {
12203
- return json(await written(env, await disableLane(env.DB, { tenantId: caller.tenantId, actor, id, global: global2 }), caller, now), cors);
12207
+ return json(await describeWritten(env.DB, await disableLane(env.DB, { tenantId: caller.tenantId, actor, id, global: global2 }), caller.tenantId, caller.billable, now), cors);
12204
12208
  }
12205
12209
  const body = await request.json().catch(() => null);
12206
12210
  if (body === null) {
@@ -12232,7 +12236,7 @@ var laneRoutes = /* @__PURE__ */ __name(async ({ request, env, url, path, caller
12232
12236
  ...body.enabled !== void 0 ? { enabled: body.enabled === true } : {},
12233
12237
  ...body.archived !== void 0 ? { archived: body.archived === true } : {}
12234
12238
  });
12235
- return json(await written(env, lane, caller, now), cors);
12239
+ return json(await describeWritten(env.DB, lane, caller.tenantId, caller.billable, now), cors);
12236
12240
  } catch (error2) {
12237
12241
  return refused2(error2, cors) ?? Promise.reject(error2);
12238
12242
  }
@@ -12362,14 +12366,14 @@ var ledgerRoutes = /* @__PURE__ */ __name(async ({ request, env, path, url, call
12362
12366
 
12363
12367
  // src/project-sentry.ts
12364
12368
  var SentryDsnError = class extends Error {
12369
+ static {
12370
+ __name(this, "SentryDsnError");
12371
+ }
12372
+ status;
12365
12373
  constructor(status, message) {
12366
12374
  super(message);
12367
12375
  this.status = status;
12368
12376
  }
12369
- status;
12370
- static {
12371
- __name(this, "SentryDsnError");
12372
- }
12373
12377
  };
12374
12378
  var SHAPE = "a Sentry DSN: https://<public key>@<host>/<project id>, as Sentry \u2192 Project Settings \u2192 Client Keys shows it";
12375
12379
  function parseDsn(value) {
@@ -14199,16 +14203,17 @@ __name(paymentsEconomics, "paymentsEconomics");
14199
14203
 
14200
14204
  // src/tiers.ts
14201
14205
  var TierRefused = class extends Error {
14206
+ static {
14207
+ __name(this, "TierRefused");
14208
+ }
14209
+ code;
14210
+ /** Empty except on `tier_quota_exceeded`, where it names every limit that is over. */
14211
+ over;
14202
14212
  constructor(code, message, over = []) {
14203
14213
  super(message);
14214
+ this.name = "TierRefused";
14204
14215
  this.code = code;
14205
14216
  this.over = over;
14206
- this.name = "TierRefused";
14207
- }
14208
- code;
14209
- over;
14210
- static {
14211
- __name(this, "TierRefused");
14212
14217
  }
14213
14218
  };
14214
14219
  async function usageOf2(db, tenantId) {
@@ -14601,14 +14606,14 @@ __name(paymentsTenantsOfUid, "paymentsTenantsOfUid");
14601
14606
  // src/markups.ts
14602
14607
  var MARKUP_CEILING_BASIS_POINTS = 2e3;
14603
14608
  var MarkupRefused = class extends Error {
14609
+ static {
14610
+ __name(this, "MarkupRefused");
14611
+ }
14612
+ code;
14604
14613
  constructor(code, message) {
14605
14614
  super(message);
14606
- this.code = code;
14607
14615
  this.name = "MarkupRefused";
14608
- }
14609
- code;
14610
- static {
14611
- __name(this, "MarkupRefused");
14616
+ this.code = code;
14612
14617
  }
14613
14618
  };
14614
14619
  function earliestEffectiveFrom(now) {