@bizzywork/routing 0.4.2 → 0.4.4

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.
@@ -24,7 +24,7 @@ async function readStdin() {
24
24
  for await (const chunk of process.stdin) text += String(chunk);
25
25
  return text;
26
26
  }
27
- var { run } = await import("./main-FBJOREHY.js");
27
+ var { run } = await import("./main-TRXFLPTZ.js");
28
28
  var { plainUi } = await import("./ui-PEKFVWX7.js");
29
29
  var { clackUi, showError } = await import("./clack-ui-KG2I32T5.js");
30
30
  var interactive = Boolean(process.stdin.isTTY && process.stdout.isTTY);
@@ -35,7 +35,7 @@ try {
35
35
  home: homedir(),
36
36
  execPath: process.execPath,
37
37
  bundleDir: dirname(fileURLToPath(import.meta.url)),
38
- version: true ? "0.4.2" : "dev",
38
+ version: true ? "0.4.4" : "dev",
39
39
  platform: process.platform,
40
40
  uid: process.getuid?.(),
41
41
  interactive,
@@ -18,6 +18,7 @@ import {
18
18
  candidatesFor,
19
19
  isTransient,
20
20
  modelId,
21
+ fallbackFrom,
21
22
  realModel,
22
23
  routingWindow,
23
24
  turnOf,
@@ -73,6 +74,13 @@ function loadConfig(): Config {
73
74
  }
74
75
 
75
76
  const config = loadConfig();
77
+ // The last real @default, kept in the routing data dir so a reinstall doesn't lose it: `/model bizzy/auto` overwrites
78
+ // omp's own setting, and omp keeps no record of what it was.
79
+ const REMEMBERED = join(
80
+ config.server?.cwd ?? dirname(fileURLToPath(import.meta.url)),
81
+ "omp-default",
82
+ );
83
+ let remembered: string | undefined;
76
84
  // One routing server per machine, however many sessions and subagents load this module.
77
85
  let keepingServer = false;
78
86
 
@@ -192,8 +200,28 @@ export default function (pi: ExtensionAPI) {
192
200
  });
193
201
  };
194
202
 
195
- /** The model sent on when routing is off or refused. */
196
- const fallbackOf = (c: ExtensionContext) => realModel(c.models.resolve("@default"));
203
+ /** The model sent on when routing is off or refused: `@default`, or once `/model bizzy/auto` has made that this
204
+ * extension, the `@default` it last saw, or failing that the first real model. */
205
+ const fallbackOf = (c: ExtensionContext) => {
206
+ const set = realModel(c.models.resolve("@default"));
207
+ if (set) {
208
+ if (remembered !== modelId(set)) {
209
+ remembered = modelId(set);
210
+ try {
211
+ writeFileSync(REMEMBERED, remembered);
212
+ } catch {
213
+ // Unwritable: remembered for this process only.
214
+ }
215
+ }
216
+ return set;
217
+ }
218
+ try {
219
+ remembered ??= readFileSync(REMEMBERED, "utf8").trim();
220
+ } catch {
221
+ // Never saved.
222
+ }
223
+ return fallbackFrom(remembered ? c.models.resolve(remembered) : undefined, c.models.list());
224
+ };
197
225
  const candidates = (c: ExtensionContext) => candidatesFor(c.models.list(), fallbackOf(c));
198
226
 
199
227
  // The server keeps the list in memory, so it is sent on every poll: a restarted server has it again within one.
@@ -117,6 +117,14 @@ export function turnOf(messages: readonly OmpMessage[]) {
117
117
  export const realModel = <M extends { provider: string }>(model: M | undefined) =>
118
118
  model && model.provider !== OWN_PROVIDER ? model : undefined;
119
119
 
120
+ /** The model to send on when routing is off: `preferred` if it is a real model, else the first real one in omp's list. */
121
+ export function fallbackFrom<M extends { provider: string }>(
122
+ preferred: M | undefined,
123
+ models: readonly M[],
124
+ ): M | undefined {
125
+ return realModel(preferred) ?? models.find((model) => realModel(model));
126
+ }
127
+
120
128
  /**
121
129
  * The models routing may serve: every real one, except those with a known context window or output limit below
122
130
  * `floor`'s (the `@default` model), so omp's budgets for `bizzy/auto` hold on whatever it serves.
@@ -76747,6 +76747,8 @@ __export(src_exports, {
76747
76747
  getBest: () => getBest,
76748
76748
  getPromoted: () => getPromoted,
76749
76749
  has: () => has,
76750
+ isApproved: () => isApproved,
76751
+ isSubscription: () => isSubscription,
76750
76752
  isTrialDue: () => isTrialDue,
76751
76753
  jevGradeProfile: () => jevGradeProfile,
76752
76754
  jevProfile: () => jevProfile,
@@ -76786,6 +76788,40 @@ __export(src_exports, {
76786
76788
  wilsonLowerBound: () => wilsonLowerBound
76787
76789
  });
76788
76790
 
76791
+ // bizzy-routing/decision/src/approved.ts
76792
+ var subscriptionProviders = /* @__PURE__ */ new Set(["anthropic", "openai", "openai-codex"]);
76793
+ var anthropicModels = [
76794
+ "anthropic/claude-fable-5.2",
76795
+ "anthropic/claude-haiku-5.5",
76796
+ "anthropic/claude-opus-5.5",
76797
+ "anthropic/claude-sonnet-5.5"
76798
+ ];
76799
+ var openAiModels = [
76800
+ "openai/gpt-6-astra",
76801
+ "openai/gpt-6-luna",
76802
+ "openai/gpt-6.1-sol",
76803
+ "openai/gpt-6.1-terra",
76804
+ "openai/gpt-6.2-astra",
76805
+ "openai/gpt-6.2-sol"
76806
+ ];
76807
+ var openRouterModels = [
76808
+ "deepseek/deepseek-v4.1-flash-1017",
76809
+ "deepseek/deepseek-v4.1-flash",
76810
+ "deepseek/deepseek-v4-flash-0731",
76811
+ "z-ai/glm-5.3-flash",
76812
+ "z-ai/glm-5.3",
76813
+ "minimax/minimax-m3.1-flash",
76814
+ "tencent/hy4-flash",
76815
+ "moonshotai/kimi-k3.1-pro",
76816
+ "nvidia/nemotron-3-ultra-550b-a55b",
76817
+ "nvidia/nemotron-3.5-super-vl",
76818
+ "meta/muse-spark-1.3-contributor",
76819
+ "xiaomi/mimo-v2.6-flash"
76820
+ ];
76821
+ var approved = /* @__PURE__ */ new Set([...anthropicModels, ...openAiModels, ...openRouterModels]);
76822
+ var isSubscription = (provider) => subscriptionProviders.has(provider);
76823
+ var isApproved = (catalogId) => catalogId !== null && approved.has(catalogId);
76824
+
76789
76825
  // bizzy-routing/decision/src/profiles.ts
76790
76826
  var jevProfile = {
76791
76827
  name: "jev",
@@ -77341,7 +77377,10 @@ var judgeGradeStrategy = function* (input2) {
77341
77377
  const state = validateRoutingState(input2.state);
77342
77378
  const base = cascade(input2, [pin, trial, registry2, history, coldStart]);
77343
77379
  if (input2.pin) return { kind: "done", decision: base, state };
77344
- const ranked = [...permittedCandidates(input2)].sort((a, b) => a.costPer1k - b.costPer1k);
77380
+ const priors = input2.priors ?? {};
77381
+ const ranked = [...permittedCandidates(input2)].sort(
77382
+ (a, b) => Number(!(a.id in priors)) - Number(!(b.id in priors)) || a.costPer1k - b.costPer1k
77383
+ );
77345
77384
  if (!ranked.length) return { kind: "done", decision: base, state };
77346
77385
  const questions2 = ranked.map((_, i) => ({
77347
77386
  id: gradeQuestionId(i + 1),
@@ -81341,13 +81380,16 @@ async function routeInput(envelope, options) {
81341
81380
  const id2 = catalog && catalogIdOf(candidate.id, catalog, { provider: candidate.provider, aliases });
81342
81381
  return id2 ? listed.get(id2) : void 0;
81343
81382
  };
81344
- const candidates = envelope.candidates.map((candidate) => {
81383
+ const approved2 = envelope.candidates.filter(
81384
+ (candidate) => options.approved?.(rowOf(candidate)?.id ?? null) ?? true
81385
+ );
81386
+ const candidates = approved2.map((candidate) => {
81345
81387
  const model = rowOf(candidate);
81346
81388
  return model ? { ...candidate, costPer1k: (model.inputPer1k + model.outputPer1k) / 2 } : candidate;
81347
81389
  });
81348
81390
  const { priors: benchmarks, priorIndex } = poolPriors(
81349
81391
  Object.fromEntries(
81350
- envelope.candidates.flatMap((candidate) => {
81392
+ approved2.flatMap((candidate) => {
81351
81393
  const model = rowOf(candidate);
81352
81394
  return model ? [[candidate.id, model]] : [];
81353
81395
  })
@@ -81373,8 +81415,8 @@ async function routeInput(envelope, options) {
81373
81415
  function profileFor({ envelope, material }) {
81374
81416
  if (material.policy === "none") return cascadeProfile;
81375
81417
  if (envelope.profile === "cascade") return cascadeProfile;
81376
- if (envelope.profile === "jev-grade") return jevGradeProfile;
81377
- return jevProfile;
81418
+ if (envelope.profile === "jev") return jevProfile;
81419
+ return jevGradeProfile;
81378
81420
  }
81379
81421
  var routeNotices = {
81380
81422
  absent: "no OpenRouter key: routing with Bizzy's own rules",
@@ -81463,6 +81505,7 @@ function createHostedRoute(options) {
81463
81505
  state: envelope.state,
81464
81506
  ...envelope.profile ? { profile: envelope.profile } : {},
81465
81507
  ...envelope.newUserTurn ? { newUserTurn: true } : {},
81508
+ ...envelope.allowOpenRouter ? { allowOpenRouter: true } : {},
81466
81509
  ...shared ? { context: "summary", summary: shared } : {}
81467
81510
  };
81468
81511
  const text = await post(
@@ -81569,12 +81612,24 @@ async function matchModels(available, server, provider) {
81569
81612
  const rows2 = new Map(catalog?.models.map((model) => [model.id, model]));
81570
81613
  const matched = {};
81571
81614
  const unmatched = [];
81572
- const unlisted = [];
81573
- for (const model of new Set(available)) {
81574
- const row = catalog && rows2.get(catalogIdOf(model, catalog, { ...provider ? { provider } : {}, aliases }) ?? "");
81575
- if (row?.toolUse) matched[model] = row;
81576
- else unmatched.push(model);
81577
- if (!row) unlisted.push(model);
81615
+ const reached = /* @__PURE__ */ new Set();
81616
+ const byPreference = [...new Set(available)].sort(
81617
+ (a, b) => Number(!isSubscription(providerOf(a, provider))) - Number(!isSubscription(providerOf(b, provider)))
81618
+ );
81619
+ for (const model of byPreference) {
81620
+ const catalogId = catalog ? catalogIdOf(model.replace(/^openai-codex\//, "openai/"), catalog, {
81621
+ ...provider ? { provider } : {},
81622
+ aliases
81623
+ }) : null;
81624
+ if (server.approved && !server.approved(catalogId)) continue;
81625
+ const row = catalogId ? rows2.get(catalogId) : void 0;
81626
+ if (!row?.toolUse) {
81627
+ unmatched.push(model);
81628
+ continue;
81629
+ }
81630
+ if (reached.has(row.id)) continue;
81631
+ reached.add(row.id);
81632
+ matched[model] = row;
81578
81633
  }
81579
81634
  const candidate = (model, costPer1k) => ({
81580
81635
  id: model,
@@ -81599,8 +81654,8 @@ async function matchModels(available, server, provider) {
81599
81654
  candidates: Object.keys(matched),
81600
81655
  unmatched,
81601
81656
  picks: efficient && capable ? { efficient: efficient.model.id, capable: capable.model.id } : null,
81602
- // A model whose row has no tool use stays out; one with no row at all can still earn a score.
81603
- pool: [...candidates, ...unlisted.map((model) => candidate(model, 0))]
81657
+ // Only models with a catalog row that takes tools: a model with no price or score can't be compared, so it's never routed.
81658
+ pool: candidates
81604
81659
  };
81605
81660
  }
81606
81661
  function parseHarnessComplete(raw) {
@@ -81728,6 +81783,8 @@ function createHarnessRouter(options, server) {
81728
81783
  mode: "auto",
81729
81784
  state: current.state,
81730
81785
  newUserTurn: true,
81786
+ // The harness's OpenRouter models are ones its user signed in to; the approved list has already narrowed them.
81787
+ allowOpenRouter: true,
81731
81788
  ...options.profile ? { profile: options.profile } : {}
81732
81789
  };
81733
81790
  const material = body.prompt ? { policy: "summary", summary: body.prompt } : { policy: "none" };
@@ -83088,7 +83145,8 @@ async function openServerState(dataDir, env, log) {
83088
83145
  trialWindow: new SqliteTrialWindowStore(database),
83089
83146
  // The same key fetches the daily catalog that prices callers' candidates and scores them.
83090
83147
  catalog: bundled ? async () => bundled : () => loadCatalog({ cwd: dataDir, apiKey: env.OPENROUTER_API_KEY }),
83091
- aliases: () => loadAliases(dataDir)
83148
+ aliases: () => loadAliases(dataDir),
83149
+ approved: isApproved
83092
83150
  }
83093
83151
  };
83094
83152
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@bizzywork/routing",
3
- "version": "0.4.2",
3
+ "version": "0.4.4",
4
4
  "type": "module",
5
5
  "description": "Bizzy Auto routing for Claude Code, oh-my-pi and Codex: npx @bizzywork/routing install <harness>.",
6
6
  "license": "SEE LICENSE IN LICENSE",