pi-auto-route 1.3.1 → 1.3.2
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.md +4 -0
- package/auto-route.ts +32 -11
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,9 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 1.3.2
|
|
4
|
+
|
|
5
|
+
- OpenCode Go subscribers now get `opencode/jev-1.13-free` classification out of the box without configuring the `opencode` Zen provider globally (which would otherwise expose pay-as-you-go chat models that fail with HTTP 402).
|
|
6
|
+
|
|
3
7
|
## 1.3.1
|
|
4
8
|
|
|
5
9
|
- npm version badge and package link in the README.
|
package/auto-route.ts
CHANGED
|
@@ -389,23 +389,41 @@ export async function classifyTier(
|
|
|
389
389
|
signal?: AbortSignal,
|
|
390
390
|
): Promise<TierDecision | undefined> {
|
|
391
391
|
try {
|
|
392
|
-
const
|
|
393
|
-
|
|
392
|
+
const available = (await ctx.modelRegistry.getAvailableOfType("classifier")) ?? [];
|
|
393
|
+
const candidates: Array<{ model: (typeof available)[number]; apiKey?: string }> =
|
|
394
|
+
available.map((model) => ({ model }));
|
|
395
|
+
// OpenCode's free classifier (opencode/jev-1.13-free) lives under the
|
|
396
|
+
// "opencode" provider in pi's catalog, yet accepts an "opencode-go" key
|
|
397
|
+
// at zero cost. Passing that key per request unlocks Jev for Go users
|
|
398
|
+
// without enabling "opencode" globally (which would flood /model with
|
|
399
|
+
// pay-as-you-go Zen chat models that fail with HTTP 402).
|
|
400
|
+
if (!candidates.some((c) => c.model.provider === "opencode")) {
|
|
401
|
+
const freeOc = (ctx.modelRegistry.getModelsOfType?.("classifier", "opencode") ?? []).filter(
|
|
402
|
+
(m) => m.cost?.input === 0,
|
|
403
|
+
);
|
|
404
|
+
if (freeOc.length > 0) {
|
|
405
|
+
const goKey = await ctx.modelRegistry.getApiKeyForProvider?.("opencode-go");
|
|
406
|
+
if (goKey) {
|
|
407
|
+
for (const model of freeOc) candidates.push({ model, apiKey: goKey });
|
|
408
|
+
}
|
|
409
|
+
}
|
|
410
|
+
}
|
|
411
|
+
if (candidates.length === 0) return undefined;
|
|
394
412
|
// Free classifiers first, then ascending input cost; unknown pricing
|
|
395
413
|
// ranks last. Array sort is stable, so the catalog order survives.
|
|
396
|
-
const
|
|
397
|
-
const freeA = a.cost?.input === 0;
|
|
398
|
-
const freeB = b.cost?.input === 0;
|
|
414
|
+
const picked = [...candidates].sort((a, b) => {
|
|
415
|
+
const freeA = a.model.cost?.input === 0;
|
|
416
|
+
const freeB = b.model.cost?.input === 0;
|
|
399
417
|
if (freeA !== freeB) return freeA ? -1 : 1;
|
|
400
418
|
return (
|
|
401
|
-
(a.cost?.input ?? Number.POSITIVE_INFINITY) -
|
|
402
|
-
(b.cost?.input ?? Number.POSITIVE_INFINITY)
|
|
419
|
+
(a.model.cost?.input ?? Number.POSITIVE_INFINITY) -
|
|
420
|
+
(b.model.cost?.input ?? Number.POSITIVE_INFINITY)
|
|
403
421
|
);
|
|
404
422
|
})[0];
|
|
405
|
-
if (!
|
|
423
|
+
if (!picked) return undefined;
|
|
406
424
|
const timeoutSignal = AbortSignal.timeout(4_000);
|
|
407
425
|
const result = await ctx.modelRegistry.classify(
|
|
408
|
-
model,
|
|
426
|
+
picked.model,
|
|
409
427
|
{
|
|
410
428
|
state: { prompt: text.slice(0, 16_000) },
|
|
411
429
|
questions: {
|
|
@@ -422,7 +440,10 @@ export async function classifyTier(
|
|
|
422
440
|
},
|
|
423
441
|
},
|
|
424
442
|
},
|
|
425
|
-
{
|
|
443
|
+
{
|
|
444
|
+
signal: signal ? AbortSignal.any([signal, timeoutSignal]) : timeoutSignal,
|
|
445
|
+
...(picked.apiKey ? { apiKey: picked.apiKey } : {}),
|
|
446
|
+
},
|
|
426
447
|
);
|
|
427
448
|
if (result.stopReason !== "stop") return undefined;
|
|
428
449
|
const answer = result.answers?.difficulty;
|
|
@@ -431,7 +452,7 @@ export async function classifyTier(
|
|
|
431
452
|
if (!decision) return undefined;
|
|
432
453
|
const probability = answer.probabilities[answer.choice] ?? answer.confidence ?? 0;
|
|
433
454
|
if (probability < 0.5) return undefined;
|
|
434
|
-
return { ...decision, via: modelKey(model) };
|
|
455
|
+
return { ...decision, via: modelKey(picked.model) };
|
|
435
456
|
} catch {
|
|
436
457
|
return undefined;
|
|
437
458
|
}
|
package/package.json
CHANGED