@blockrun/franklin 3.42.1 → 3.43.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/README.md +7 -9
- package/dist/agent/commands.js +2 -2
- package/dist/agent/compact.js +6 -3
- package/dist/agent/context.js +1 -1
- package/dist/agent/evaluator.js +2 -1
- package/dist/agent/llm.js +4 -3
- package/dist/agent/loop.js +82 -14
- package/dist/agent/nemotron-prose-stripper.d.ts +26 -0
- package/dist/agent/nemotron-prose-stripper.js +39 -1
- package/dist/agent/tokens.js +22 -5
- package/dist/agent/turn-analyzer.js +18 -6
- package/dist/agent/verification.js +2 -1
- package/dist/brain/extract.js +2 -1
- package/dist/commands/slack.js +2 -1
- package/dist/commands/social.js +2 -1
- package/dist/commands/telegram.js +2 -1
- package/dist/free-models.constants.d.ts +28 -0
- package/dist/free-models.constants.js +33 -0
- package/dist/free-models.d.ts +320 -0
- package/dist/free-models.js +407 -0
- package/dist/gateway-models.js +15 -3
- package/dist/learnings/extractor.js +3 -2
- package/dist/plugin-sdk/workflow.js +5 -2
- package/dist/pricing.js +18 -9
- package/dist/proxy/fallback.d.ts +7 -0
- package/dist/proxy/fallback.js +14 -1
- package/dist/proxy/server.js +15 -2
- package/dist/router/index.d.ts +3 -1
- package/dist/router/index.js +140 -89
- package/dist/router/vision.js +35 -10
- package/dist/serve/server.js +1 -4
- package/dist/tools/moa.js +9 -3
- package/dist/tools/modal.d.ts +25 -0
- package/dist/tools/modal.js +87 -9
- package/dist/tools/subagent.js +6 -5
- package/dist/ui/model-picker.js +75 -74
- package/dist/wallet/reservation.d.ts +40 -3
- package/dist/wallet/reservation.js +91 -10
- package/package.json +3 -3
package/dist/router/index.js
CHANGED
|
@@ -18,6 +18,7 @@ import { detectCategory, mapCategoryToTier } from './categories.js';
|
|
|
18
18
|
import { selectModel } from './selector.js';
|
|
19
19
|
import { computeLocalElo, blendElo } from './local-elo.js';
|
|
20
20
|
import { isVisionModel, pickVisionSibling } from './vision.js';
|
|
21
|
+
import { FREE_DEFAULT_MODEL, QUARANTINED_FREE_MODELS, freeChain, freeVisionModel, } from '../free-models.js';
|
|
21
22
|
export { isVisionModel, messageNeedsVision, messagesNeedVision, pickVisionSibling } from './vision.js';
|
|
22
23
|
// ─── Learned Weights Loading ───
|
|
23
24
|
const WEIGHTS_FILE = path.join(BLOCKRUN_DIR, 'router-weights.json');
|
|
@@ -65,7 +66,7 @@ const SHARED_MODEL_PRICING = new Map(Object.entries(MODEL_PRICING).map(([model,
|
|
|
65
66
|
// route to, because the free pool answers for them with a substitute
|
|
66
67
|
// (the response's `model` field names a different model) and leaks
|
|
67
68
|
// thinking prose into content. Same "never promise a model the user
|
|
68
|
-
// doesn't get" rule the picker applies; see
|
|
69
|
+
// doesn't get" rule the picker applies; see src/free-models.ts.
|
|
69
70
|
// 3. Runtime observations — markModelUnavailable() is called by the agent
|
|
70
71
|
// loop when the gateway rejects a routed model id (400 "Unknown model",
|
|
71
72
|
// 404, 410 — see AgentErrorInfo.modelUnavailable). Process-scoped: the
|
|
@@ -80,10 +81,13 @@ const KNOWN_UNAVAILABLE_MODELS = [
|
|
|
80
81
|
// the core itself (d7bc10c), which is the steady state this list waits for.
|
|
81
82
|
];
|
|
82
83
|
const QUARANTINED_MODELS = [
|
|
83
|
-
// Catalogued free
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
84
|
+
// Catalogued free ids Franklin refuses to route to because the pool answers
|
|
85
|
+
// for them with a substitute, or the id itself misbehaves on the streaming
|
|
86
|
+
// path. The list and the per-id evidence live in src/free-models.ts so the
|
|
87
|
+
// picker, the router and the chains all quarantine the same set.
|
|
88
|
+
...QUARANTINED_FREE_MODELS,
|
|
89
|
+
// Substituted out of the catalog entirely on 2026-08-30; the core still used
|
|
90
|
+
// it as the free backstop rung of every Auto chain.
|
|
87
91
|
'nvidia/step-3.7-flash',
|
|
88
92
|
];
|
|
89
93
|
const observedUnavailable = new Set();
|
|
@@ -421,24 +425,47 @@ function classicRouteRequest(prompt, profile, needsVision = false) {
|
|
|
421
425
|
// - Exposed via async `routeRequestAsync(prompt, profile, classify?)`. Callers
|
|
422
426
|
// that can't be async (proxy, LLM-client bootstrap) keep using the sync
|
|
423
427
|
// `routeRequest`, which silently does keyword-only routing.
|
|
424
|
-
// The classifier
|
|
425
|
-
// tight max_tokens.
|
|
426
|
-
//
|
|
427
|
-
// into `content` (glm-4.7 and the qwen-thinking builds emit reasoning and
|
|
428
|
-
// leave text empty; nemotron-nano-9b-v2 opens with "Okay, let's see. The user
|
|
429
|
-
// wants to…" and never reaches a verdict inside the budget).
|
|
428
|
+
// The classifier used to require a free model that answers with ONE BARE WORD
|
|
429
|
+
// under a tight max_tokens. As of 2026-08-30 no free model can do that, and
|
|
430
|
+
// the requirement has been quietly unsatisfiable for longer than that:
|
|
430
431
|
//
|
|
431
|
-
//
|
|
432
|
-
//
|
|
433
|
-
//
|
|
434
|
-
//
|
|
435
|
-
//
|
|
432
|
+
// 2026-08-19: qwen3-next was EOL'd and its calls rode nemotron-3-super-120b,
|
|
433
|
+
// which leaks prose. Every classification failed the strict parse and fell
|
|
434
|
+
// through to keyword-only routing — silently, because that fallback is by
|
|
435
|
+
// design invisible.
|
|
436
|
+
// 2026-08-19: nemotron-3-nano-omni was promoted as the fix, on a probe that
|
|
437
|
+
// showed it returning "MEDIUM" and nothing else.
|
|
438
|
+
// 2026-08-30: re-probed on this exact prompt shape at max_tokens 8, omni now
|
|
439
|
+
// comes back from a nemotron-3-nano-30b substitute mid-sentence
|
|
440
|
+
// ("We need to classify request complexity. The request: ..."). So does
|
|
441
|
+
// every other free id, including the 550B default. The free pool reasons
|
|
442
|
+
// out loud now; there is no bare-word free model left to promote.
|
|
436
443
|
//
|
|
437
|
-
//
|
|
438
|
-
//
|
|
439
|
-
//
|
|
440
|
-
|
|
441
|
-
|
|
444
|
+
// So the classifier stops fighting the pool and reads it instead:
|
|
445
|
+
// - it defaults to FREE_DEFAULT_MODEL rather than its own pinned literal, so
|
|
446
|
+
// a pool rotation is one edit in free-models.ts, not two. (It is a static
|
|
447
|
+
// module-level pin, NOT a per-call resolveFreeModel() — a rotation that
|
|
448
|
+
// retires the default still needs a release.)
|
|
449
|
+
// - max_tokens is large enough for the verdict to actually ARRIVE after the
|
|
450
|
+
// model has finished thinking out loud (8 tokens never got there). Every
|
|
451
|
+
// free model is a reasoning model, and a tight budget truncates them
|
|
452
|
+
// mid-thought — the "chain-of-thought leak" this pool is blamed for is
|
|
453
|
+
// mostly just that. 1024 is cheap when the call bills at $0.
|
|
454
|
+
// - the parse takes the LAST tier word, not the first. A leaked trace
|
|
455
|
+
// restates the allowed set from the system prompt ("SIMPLE, MEDIUM, or
|
|
456
|
+
// COMPLEX") before reaching a verdict, so first-match reads the menu and
|
|
457
|
+
// last-match reads the answer.
|
|
458
|
+
//
|
|
459
|
+
// This costs nothing extra: the calls were already being made and already
|
|
460
|
+
// being paid for at $0. They were just being thrown away.
|
|
461
|
+
//
|
|
462
|
+
// Note this is not on the production hot path — Auto routing delegates to the
|
|
463
|
+
// shared Router core with no classifier round trip (see routeRequestAsync).
|
|
464
|
+
// Tests and third-party integrations that inject a classifier get a working
|
|
465
|
+
// one again.
|
|
466
|
+
const CLASSIFIER_MODEL = process.env.FRANKLIN_ROUTER_MODEL || FREE_DEFAULT_MODEL;
|
|
467
|
+
const CLASSIFIER_TIMEOUT_MS = 8_000;
|
|
468
|
+
const CLASSIFIER_MAX_TOKENS = 1_024;
|
|
442
469
|
const CLASSIFIER_SYSTEM = `You classify a user's message into ONE routing tier for a CLI agent. Reply with EXACTLY ONE WORD from the allowed set. No explanation, no punctuation, no quotes.
|
|
443
470
|
|
|
444
471
|
Tiers:
|
|
@@ -455,8 +482,29 @@ Answer format: a single word. SIMPLE or MEDIUM or COMPLEX or REASONING.`;
|
|
|
455
482
|
* the caller can fall back to keyword classification.
|
|
456
483
|
*/
|
|
457
484
|
function parseTierWord(reply) {
|
|
458
|
-
const
|
|
459
|
-
|
|
485
|
+
const text = reply.trim().toUpperCase();
|
|
486
|
+
if (!text)
|
|
487
|
+
return null;
|
|
488
|
+
const TIER = /\b(SIMPLE|MEDIUM|COMPLEX|REASONING)\b/g;
|
|
489
|
+
// Preferred: the reply is (or ends on) a bare tier word. A model that
|
|
490
|
+
// followed the instruction lands here.
|
|
491
|
+
const lastLine = text.split(/\n+/).filter(Boolean).pop() ?? '';
|
|
492
|
+
const bare = lastLine.match(/^[^A-Z]*\b(SIMPLE|MEDIUM|COMPLEX|REASONING)\b[^A-Z]*$/);
|
|
493
|
+
if (bare)
|
|
494
|
+
return bare[1];
|
|
495
|
+
// Otherwise take the last tier word ON THE LAST LINE, not on the whole blob.
|
|
496
|
+
// Whole-blob last-match was wrong in a way that costs money: CLASSIFIER_SYSTEM
|
|
497
|
+
// itself ends "SIMPLE or MEDIUM or COMPLEX or REASONING", so any reply that
|
|
498
|
+
// restates its instructions — the documented failure this parser exists to
|
|
499
|
+
// survive — matched REASONING, the most expensive tier. The classified text
|
|
500
|
+
// is also untrusted user content, so a prompt ending in the word REASONING
|
|
501
|
+
// could push its own tier up. Failing toward the cheap end is the safe
|
|
502
|
+
// direction; returning null (keyword routing) is safer still.
|
|
503
|
+
const onLastLine = lastLine.match(TIER);
|
|
504
|
+
if (onLastLine && onLastLine.length > 0) {
|
|
505
|
+
return onLastLine[onLastLine.length - 1];
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
460
508
|
}
|
|
461
509
|
/**
|
|
462
510
|
* Default LLM classifier — lazy-imports the ModelClient to avoid a hard
|
|
@@ -493,7 +541,7 @@ export async function llmClassifyRequest(prompt) {
|
|
|
493
541
|
system: CLASSIFIER_SYSTEM,
|
|
494
542
|
messages: [{ role: 'user', content: prompt.slice(0, 2000) }],
|
|
495
543
|
tools: [],
|
|
496
|
-
max_tokens:
|
|
544
|
+
max_tokens: CLASSIFIER_MAX_TOKENS,
|
|
497
545
|
}, ctrl.signal);
|
|
498
546
|
let text = '';
|
|
499
547
|
for (const part of result.content) {
|
|
@@ -561,15 +609,20 @@ export async function routeRequestAsync(prompt, profile = 'auto', classify, cont
|
|
|
561
609
|
*/
|
|
562
610
|
export function resolveTierToModel(tier, profile = 'auto', needsVision = false) {
|
|
563
611
|
// Free profile short-circuits — everything routes to a single free model.
|
|
564
|
-
//
|
|
565
|
-
//
|
|
566
|
-
//
|
|
612
|
+
//
|
|
613
|
+
// Vision turns go to the chain's free vision model when it has one. Where
|
|
614
|
+
// it doesn't, they get the TEXT model plus a `free-vision-unavailable`
|
|
615
|
+
// signal that callers surface — the free profile never falls back to a paid
|
|
616
|
+
// model. See freeVisionModel() for the per-chain measurements.
|
|
567
617
|
if (profile === 'free') {
|
|
618
|
+
const freeVision = needsVision ? freeVisionModel() : null;
|
|
568
619
|
return {
|
|
569
|
-
model:
|
|
620
|
+
model: freeVision ?? liveFreeChain()[0] ?? FREE_DEFAULT_MODEL,
|
|
570
621
|
tier: 'SIMPLE',
|
|
571
622
|
confidence: 1.0,
|
|
572
|
-
signals: needsVision
|
|
623
|
+
signals: needsVision
|
|
624
|
+
? ['free-profile', freeVision ? 'free-vision' : 'free-vision-unavailable']
|
|
625
|
+
: ['free-profile'],
|
|
573
626
|
savings: 1.0,
|
|
574
627
|
};
|
|
575
628
|
}
|
|
@@ -596,16 +649,19 @@ export function resolveTierToModel(tier, profile = 'auto', needsVision = false)
|
|
|
596
649
|
// ─── Main Router ───
|
|
597
650
|
export function routeRequest(prompt, profile = 'auto', context = false) {
|
|
598
651
|
const normalizedContext = normalizeRoutingContext(context);
|
|
599
|
-
// Free profile — always use free model
|
|
600
|
-
//
|
|
652
|
+
// Free profile — always use a free model. Vision turns go to the chain's
|
|
653
|
+
// free vision model where one exists (see resolveTierToModel).
|
|
601
654
|
if (profile === 'free') {
|
|
655
|
+
const freeVision = normalizedContext.needsVision ? freeVisionModel() : null;
|
|
602
656
|
return {
|
|
603
|
-
model:
|
|
657
|
+
model: freeVision ?? liveFreeChain()[0] ?? FREE_DEFAULT_MODEL,
|
|
604
658
|
tier: 'SIMPLE',
|
|
605
659
|
confidence: 1.0,
|
|
606
|
-
signals: normalizedContext.needsVision
|
|
660
|
+
signals: normalizedContext.needsVision
|
|
661
|
+
? ['free-profile', freeVision ? 'free-vision' : 'free-vision-unavailable']
|
|
662
|
+
: ['free-profile'],
|
|
607
663
|
savings: 1.0,
|
|
608
|
-
candidates:
|
|
664
|
+
candidates: freeModelsForCategory(),
|
|
609
665
|
};
|
|
610
666
|
}
|
|
611
667
|
// Emergency rollback for operators. This keeps the former Franklin rules
|
|
@@ -737,7 +793,7 @@ function computeSavings(model) {
|
|
|
737
793
|
*/
|
|
738
794
|
export function getFallbackChain(tier, profile = 'auto') {
|
|
739
795
|
if (profile === 'free')
|
|
740
|
-
return
|
|
796
|
+
return freeModelsForCategory();
|
|
741
797
|
const config = AUTO_TIERS[tier];
|
|
742
798
|
return [config.primary, ...config.fallback];
|
|
743
799
|
}
|
|
@@ -746,65 +802,60 @@ export function getFallbackChain(tier, profile = 'auto') {
|
|
|
746
802
|
// mid-turn (402 payment, rate-limit) and we need a zero-cost replacement
|
|
747
803
|
// to keep the user moving without waiting for funding.
|
|
748
804
|
//
|
|
749
|
-
// The
|
|
750
|
-
//
|
|
751
|
-
//
|
|
752
|
-
//
|
|
753
|
-
//
|
|
754
|
-
//
|
|
755
|
-
//
|
|
756
|
-
//
|
|
757
|
-
//
|
|
758
|
-
//
|
|
759
|
-
//
|
|
760
|
-
//
|
|
761
|
-
//
|
|
762
|
-
//
|
|
763
|
-
//
|
|
764
|
-
//
|
|
765
|
-
//
|
|
766
|
-
//
|
|
767
|
-
//
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
773
|
-
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
|
|
779
|
-
|
|
780
|
-
|
|
781
|
-
|
|
782
|
-
|
|
783
|
-
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
|
|
787
|
-
|
|
788
|
-
|
|
789
|
-
|
|
790
|
-
reasoning: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
791
|
-
chat: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
792
|
-
creative: ['nvidia/nemotron-nano-9b-v2', OMNI, 'nvidia/mistral-nemotron'],
|
|
793
|
-
};
|
|
794
|
-
const DEFAULT_FREE_CHAIN = [
|
|
795
|
-
'nvidia/nemotron-nano-9b-v2',
|
|
796
|
-
OMNI,
|
|
797
|
-
'nvidia/mistral-nemotron',
|
|
798
|
-
];
|
|
805
|
+
// The ids, the ordering and the evidence behind both live in
|
|
806
|
+
// src/free-models.ts — this file only maps categories onto that chain. The
|
|
807
|
+
// chain is deliberately short and identical across categories: the 2026-08-30
|
|
808
|
+
// probe established that the free pool collapses every NVIDIA id onto one
|
|
809
|
+
// backing model under load, so per-category NVIDIA rungs were three names for
|
|
810
|
+
// the same upstream — fake resilience that could never rescue a turn the
|
|
811
|
+
// first rung had already failed. The one real axis of resilience left is
|
|
812
|
+
// provider, which is why the last rung is poolside rather than NVIDIA.
|
|
813
|
+
//
|
|
814
|
+
// Rotation history (kept short on purpose — the per-id post-mortems moved to
|
|
815
|
+
// free-models.ts): glm-4.7 dropped 2026-06-07, deepseek-v4-flash 2026-07-11,
|
|
816
|
+
// llama-4-maverick 2026-07-14, qwen3-next 2026-08-12, and on 2026-08-30 the
|
|
817
|
+
// gateway rotated the entire pool at once.
|
|
818
|
+
// Every category shares one chain. The ids, the ordering and the evidence
|
|
819
|
+
// live in src/free-models.ts; freeChain() filters them against the live
|
|
820
|
+
// catalog for the CURRENT chain, because the Solana gateway lists only one of
|
|
821
|
+
// them and 400s on the rest. It is a function, not a constant, for that
|
|
822
|
+
// reason — a frozen array captured at module load would pin whichever answer
|
|
823
|
+
// was true before the catalog cache warmed.
|
|
824
|
+
function freeModelsForCategory() {
|
|
825
|
+
return liveFreeChain();
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* freeChain() filtered by the runtime kill-switch.
|
|
829
|
+
*
|
|
830
|
+
* freeChain lives in free-models.ts, which cannot import this module (the
|
|
831
|
+
* dependency runs the other way), so it knows nothing about the ids
|
|
832
|
+
* markModelUnavailable() has observed the gateway REJECT with 400 / 404 / 410.
|
|
833
|
+
* Without this filter a dead free rung was re-selected on every turn — the
|
|
834
|
+
* per-turn `alreadyFailed` set is cleared at the top of each turn, so the
|
|
835
|
+
* kill-switch had no effect on the free profile at all. Given this branch
|
|
836
|
+
* exists because the free pool rotates ids without notice, that is the exact
|
|
837
|
+
* failure mode it has to survive.
|
|
838
|
+
*/
|
|
839
|
+
function liveFreeChain(alreadyFailed = new Set()) {
|
|
840
|
+
const live = freeChain(alreadyFailed).filter(m => !isModelUnavailable(m));
|
|
841
|
+
// Every rung observed dead: fall back to the unfiltered chain rather than
|
|
842
|
+
// refusing to route. A stale kill-switch entry must not strand a free user
|
|
843
|
+
// with no model at all.
|
|
844
|
+
return live.length > 0 ? live : freeChain(alreadyFailed);
|
|
845
|
+
}
|
|
799
846
|
/**
|
|
800
847
|
* Pick the next free model to try given the question category and which
|
|
801
848
|
* free models have already failed this turn. Returns undefined when every
|
|
802
849
|
* candidate has been exhausted (caller should surface an error to user).
|
|
803
850
|
*/
|
|
804
|
-
export function pickFreeFallback(
|
|
805
|
-
|
|
806
|
-
|
|
807
|
-
|
|
851
|
+
export function pickFreeFallback(
|
|
852
|
+
/** @deprecated Ignored — the free chain no longer varies by category. */
|
|
853
|
+
category, alreadyFailed) {
|
|
854
|
+
// Category is accepted for API compatibility; the chain no longer varies by
|
|
855
|
+
// it (see freeModelsForCategory). Marked deprecated so a new caller doesn't
|
|
856
|
+
// assume passing one changes the answer.
|
|
857
|
+
void category;
|
|
858
|
+
return liveFreeChain(alreadyFailed)[0];
|
|
808
859
|
}
|
|
809
860
|
/**
|
|
810
861
|
* Parse routing profile from model string
|
package/dist/router/vision.js
CHANGED
|
@@ -18,6 +18,7 @@
|
|
|
18
18
|
* model — having no vision pathway — would hallucinate based on the
|
|
19
19
|
* `Image file: <path>` description string. Expensive AND wrong.
|
|
20
20
|
*/
|
|
21
|
+
import { freeVisionModel } from '../free-models.js';
|
|
21
22
|
const VISION_MODELS = new Set([
|
|
22
23
|
// Anthropic — native vision across the line
|
|
23
24
|
'anthropic/claude-fable-5',
|
|
@@ -81,21 +82,45 @@ const VISION_MODELS = new Set([
|
|
|
81
82
|
// Z.AI — GLM-5.3 Flash is the one GLM SKU the catalog tags as vision
|
|
82
83
|
// (2026-08-29 sync); GLM-5.3 / 5.2 / 5.1 are text + reasoning only.
|
|
83
84
|
'zai/glm-5.3-flash',
|
|
84
|
-
//
|
|
85
|
-
//
|
|
86
|
-
//
|
|
87
|
-
//
|
|
88
|
-
|
|
89
|
-
//
|
|
90
|
-
//
|
|
91
|
-
//
|
|
92
|
-
|
|
85
|
+
// ── The free vision model is NOT here, on purpose ──
|
|
86
|
+
// isVisionModel() consults freeVisionModel() instead of this static set,
|
|
87
|
+
// because that answer depends on gateway deploy state and an env override
|
|
88
|
+
// rather than on a fixed capability. See the note below and free-models.ts.
|
|
89
|
+
//
|
|
90
|
+
// ── Why no free vision id is listed (2026-08-31) ──
|
|
91
|
+
// Listing an id here is a promise isVisionModel() callers act on: the agent
|
|
92
|
+
// loop and the proxy both use it to decide whether an image can be sent at
|
|
93
|
+
// all. Neither free vision id earns that promise, for two DIFFERENT reasons:
|
|
94
|
+
//
|
|
95
|
+
// nemotron-3-nano-omni — the gateway now REFUSES image input for this
|
|
96
|
+
// id on /v1/messages with an explicit 400 and no
|
|
97
|
+
// charge ("served text-only on NVIDIA"). Before
|
|
98
|
+
// that it silently saw the image 6/10 and was
|
|
99
|
+
// substituted 7/10 on /chat/completions by a
|
|
100
|
+
// model with no vision at all. The loud refusal
|
|
101
|
+
// is the better failure and needs no guard here.
|
|
102
|
+
// llama-3.2-11b-vision — reads the image reliably as a bare call
|
|
103
|
+
// (30/30) but only 1/5 end-to-end through the
|
|
104
|
+
// agent loop, which is Franklin's own wiring
|
|
105
|
+
// problem, not the model's.
|
|
106
|
+
//
|
|
107
|
+
// Full measurement history and the acceptance bar for re-adding either:
|
|
108
|
+
// freeVisionModel() in src/free-models.ts.
|
|
109
|
+
//
|
|
110
|
+
// nvidia/nemotron-nano-12b-v2-vl held this slot until it left the catalog on
|
|
111
|
+
// 2026-08-30; Llama 4 Maverick before that (dropped 2026-07-14).
|
|
93
112
|
]);
|
|
94
113
|
/** Does this concrete gateway model accept image input? */
|
|
95
114
|
export function isVisionModel(modelId) {
|
|
96
115
|
if (!modelId)
|
|
97
116
|
return false;
|
|
98
|
-
|
|
117
|
+
if (VISION_MODELS.has(modelId))
|
|
118
|
+
return true;
|
|
119
|
+
// The free tier's vision model is resolved at runtime, not fixed: it depends
|
|
120
|
+
// on gateway deploy state and on FRANKLIN_FREE_VISION_MODEL. freeVisionModel()
|
|
121
|
+
// returns null when no free model can be trusted with an image, and this
|
|
122
|
+
// stays false there.
|
|
123
|
+
return modelId === freeVisionModel();
|
|
99
124
|
}
|
|
100
125
|
/** Lower-cased copy used for prefix family matching in pickVisionSibling. */
|
|
101
126
|
const VISION_MODELS_LIST = Array.from(VISION_MODELS);
|
package/dist/serve/server.js
CHANGED
|
@@ -37,10 +37,7 @@ import { setupAgentWallet, setupAgentSolanaWallet } from '@blockrun/llm';
|
|
|
37
37
|
import { retryFetchBalance } from '../commands/balance-retry.js';
|
|
38
38
|
import { AgentHost } from './agent-host.js';
|
|
39
39
|
import { bus } from '../events/bus.js';
|
|
40
|
-
|
|
41
|
-
// the STREAMING path (verified live 2026-08-12 — mistral-nemotron is DEGRADED
|
|
42
|
-
// at NVIDIA and 400s on stream; qwen3-next-80b-a3b-instruct hit NVIDIA's EOL).
|
|
43
|
-
const FREE_DEFAULT_MODEL = 'nvidia/nemotron-nano-9b-v2';
|
|
40
|
+
import { FREE_DEFAULT_MODEL } from '../free-models.js';
|
|
44
41
|
// Curated Base (chainId 8453) tokens for the wallet "holdings" view. Plain RPC
|
|
45
42
|
// can't enumerate every token an address holds (no on-chain "list all"), so we
|
|
46
43
|
// balanceOf a known set and show the non-zero ones. `stable` → USD ≈ amount.
|
package/dist/tools/moa.js
CHANGED
|
@@ -11,16 +11,22 @@
|
|
|
11
11
|
* Inspired by the Mixture-of-Agents architecture from Together.ai research.
|
|
12
12
|
*/
|
|
13
13
|
import { ModelClient } from '../agent/llm.js';
|
|
14
|
+
import { FREE_DEFAULT_MODEL, freeChain } from '../free-models.js';
|
|
14
15
|
// ─── Configuration ────────────────────────────────────────────────────────
|
|
15
16
|
/** Reference models — diverse, cheap/free models for parallel queries. */
|
|
16
17
|
const REFERENCE_MODELS = [
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
// Free voices come from the live chain rather than literals: a hardcoded
|
|
19
|
+
// second id (poolside/laguna-xs-2.1) is absent from some gateways and 400s
|
|
20
|
+
// there, turning the ensemble into one voice on exactly those chains.
|
|
21
|
+
// freeChain() also keeps the two voices on different PROVIDERS where the
|
|
22
|
+
// catalog allows it, which is the point — every NVIDIA free id can collapse
|
|
23
|
+
// onto one backing model under load (probed 2026-08-30).
|
|
24
|
+
...freeChain().slice(0, 2),
|
|
19
25
|
'google/gemini-2.5-flash', // Fast, cheap
|
|
20
26
|
'deepseek/deepseek-chat', // Cheap, good reasoning
|
|
21
27
|
];
|
|
22
28
|
/** Aggregator model — free by default. Users explicitly pass `aggregator` to upgrade. */
|
|
23
|
-
const AGGREGATOR_MODEL =
|
|
29
|
+
const AGGREGATOR_MODEL = FREE_DEFAULT_MODEL;
|
|
24
30
|
/** Max tokens per reference response. */
|
|
25
31
|
const REFERENCE_MAX_TOKENS = 4096;
|
|
26
32
|
/** Max tokens for aggregator. */
|
package/dist/tools/modal.d.ts
CHANGED
|
@@ -26,6 +26,7 @@
|
|
|
26
26
|
* the SessionSandboxTracker registry.
|
|
27
27
|
*/
|
|
28
28
|
import type { CapabilityHandler } from '../agent/types.js';
|
|
29
|
+
import { type ReservationToken } from '../wallet/reservation.js';
|
|
29
30
|
export interface SandboxRecord {
|
|
30
31
|
id: string;
|
|
31
32
|
gpu: string;
|
|
@@ -41,6 +42,30 @@ declare class SessionSandboxTracker {
|
|
|
41
42
|
drainIds(): string[];
|
|
42
43
|
}
|
|
43
44
|
export declare const sessionSandboxTracker: SessionSandboxTracker;
|
|
45
|
+
export declare function _setPaymentSignerForTests(fn: typeof signPayment | null): void;
|
|
46
|
+
declare function signPayment(response: Response, chain: 'base' | 'solana', endpoint: string, resourceDescription: string): Promise<Record<string, string> | null>;
|
|
47
|
+
/**
|
|
48
|
+
* Generic POST-with-x402-retry helper used by all four Modal endpoints. The
|
|
49
|
+
* first POST gets a 402 with payment requirements; we sign and retry once
|
|
50
|
+
* with the X-PAYMENT header. Returns the parsed JSON body and the raw
|
|
51
|
+
* Response (callers may need status code).
|
|
52
|
+
*
|
|
53
|
+
* `reservation` is the caller's wallet hold for this call. If the signed
|
|
54
|
+
* (paid) request has been dispatched and the call then aborts or times out
|
|
55
|
+
* before a response, or the response arrives but its body is cut off, the
|
|
56
|
+
* outcome is ambiguous — the gateway may already have settled the payment.
|
|
57
|
+
* The hold is marked ambiguous so the reservation layer keeps counting it
|
|
58
|
+
* (see reservation.ts) instead of the caller's `finally` releasing it as if
|
|
59
|
+
* nothing was spent. Failures that provably never left this machine (signal
|
|
60
|
+
* already aborted before dispatch, DNS / connection-refused) are NOT
|
|
61
|
+
* ambiguous and release normally.
|
|
62
|
+
*/
|
|
63
|
+
export declare function postWithPayment(endpoint: string, body: Record<string, unknown>, resourceDescription: string, abortSignal: AbortSignal, timeoutMs: number, reservation?: ReservationToken | null): Promise<{
|
|
64
|
+
ok: boolean;
|
|
65
|
+
status: number;
|
|
66
|
+
body: Record<string, unknown>;
|
|
67
|
+
raw: string;
|
|
68
|
+
}>;
|
|
44
69
|
export declare const modalCreateCapability: CapabilityHandler;
|
|
45
70
|
export declare const modalExecCapability: CapabilityHandler;
|
|
46
71
|
export declare const modalStatusCapability: CapabilityHandler;
|