@blockrun/franklin 3.30.1 → 3.32.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.
Files changed (43) hide show
  1. package/dist/agent/commands.js +72 -2
  2. package/dist/agent/compact.js +1 -1
  3. package/dist/agent/evaluator.js +1 -1
  4. package/dist/agent/llm.d.ts +1 -1
  5. package/dist/agent/llm.js +64 -19
  6. package/dist/agent/loop.js +23 -4
  7. package/dist/agent/optimize.js +10 -0
  8. package/dist/agent/permissions.js +17 -0
  9. package/dist/agent/tokens.js +23 -2
  10. package/dist/agent/turn-analyzer.js +1 -1
  11. package/dist/agent/types.d.ts +24 -0
  12. package/dist/agent/verification.js +1 -1
  13. package/dist/commands/predict.d.ts +10 -0
  14. package/dist/commands/predict.js +143 -0
  15. package/dist/commands/slack.js +1 -1
  16. package/dist/commands/social.js +1 -1
  17. package/dist/commands/start.js +24 -7
  18. package/dist/commands/telegram.js +1 -1
  19. package/dist/config.d.ts +1 -0
  20. package/dist/config.js +6 -0
  21. package/dist/index.js +12 -0
  22. package/dist/learnings/extractor.js +2 -2
  23. package/dist/market/client.d.ts +69 -0
  24. package/dist/market/client.js +230 -0
  25. package/dist/plugin-sdk/workflow.js +3 -3
  26. package/dist/pricing.js +27 -6
  27. package/dist/proxy/fallback.js +1 -1
  28. package/dist/proxy/server.js +6 -86
  29. package/dist/router/index.js +14 -13
  30. package/dist/router/vision.js +15 -3
  31. package/dist/serve/server.js +4 -1
  32. package/dist/tools/agent-talent.d.ts +15 -0
  33. package/dist/tools/agent-talent.js +116 -0
  34. package/dist/tools/defillama.js +6 -5
  35. package/dist/tools/index.d.ts +15 -0
  36. package/dist/tools/index.js +28 -0
  37. package/dist/tools/moa.js +3 -3
  38. package/dist/tools/prediction.js +11 -10
  39. package/dist/tools/subagent.js +1 -1
  40. package/dist/tools/trading.js +3 -2
  41. package/dist/ui/model-picker.d.ts +26 -1
  42. package/dist/ui/model-picker.js +107 -38
  43. package/package.json +2 -2
@@ -12,7 +12,7 @@ import { execSync } from 'node:child_process';
12
12
  import { BLOCKRUN_DIR, VERSION } from '../config.js';
13
13
  import { estimateHistoryTokens, getAnchoredTokenCount, getContextWindow, resetTokenAnchor } from './tokens.js';
14
14
  import { forceCompact } from './compact.js';
15
- import { getStatsSummary } from '../stats/tracker.js';
15
+ import { getStatsSummary, recordUsage } from '../stats/tracker.js';
16
16
  import { resolveModel } from '../ui/model-picker.js';
17
17
  import { listSessions, loadSessionHistory, } from '../session/storage.js';
18
18
  import { matchSkill } from '../skills/invoke.js';
@@ -236,6 +236,7 @@ const DIRECT_COMMANDS = {
236
236
  ` **Session:** /plan /ultraplan /execute /compact /retry /sessions /resume /session-search /context /tasks /history /transcript\n` +
237
237
  ` **Power:** /ultrathink [query] /ultraplan /noplan /moa [query] /dump\n` +
238
238
  ` **Info:** /model /auto /wallet /cost /tokens /learnings /brain /mcp /doctor /version /bug /help\n` +
239
+ ` **Market:** /market [keyword] · /market info <slug> · /market run <slug> <input>\n` +
239
240
  ` **UI:** /clear /exit\n` +
240
241
  skillsBlock +
241
242
  (ultrathinkOn ? `\n Ultrathink: ON\n` : '')
@@ -635,6 +636,75 @@ export async function handleSlashCommand(input, ctx) {
635
636
  emitDone(ctx);
636
637
  return { handled: true };
637
638
  }
639
+ // /market [keyword | info <slug> | run <slug> <input>] — browse + hire paid
640
+ // skills from the BlockRun agent marketplace (business.blockrun.ai). Browsing
641
+ // and search are free GETs; `run` pays ONE standard x402 from the wallet.
642
+ if (input === '/market' || input.startsWith('/market ')) {
643
+ const arg = input.slice('/market'.length).trim();
644
+ const { fetchCatalog, runMarketSkill, formatCatalogList, formatSkillCard, fmtUsd } = await import('../market/client.js');
645
+ // run <slug> <input> — the only paid path.
646
+ if (/^run(\s|$)/.test(arg)) {
647
+ const runMatch = arg.match(/^run\s+(\S+)\s+([\s\S]+)$/);
648
+ if (!runMatch) {
649
+ ctx.onEvent({ kind: 'text_delta', text: 'Usage: /market run <slug> <input>\n' });
650
+ emitDone(ctx);
651
+ return { handled: true };
652
+ }
653
+ const [, slug, skillInput] = runMatch;
654
+ ctx.onEvent({ kind: 'text_delta', text: `Hiring ${slug}…\n` });
655
+ const outcome = await runMarketSkill(slug, skillInput);
656
+ // Record the on-chain spend so the human /market run path is visible to
657
+ // the audit ledger, /cost, and the --max-spend accumulator (parity with
658
+ // the agent_talent tool path).
659
+ try {
660
+ recordUsage(`market:run:${slug}`, 0, 0, outcome.paidUsd, 0);
661
+ }
662
+ catch { /* best-effort */ }
663
+ if (!outcome.ok) {
664
+ ctx.onEvent({ kind: 'text_delta', text: `Could not run ${slug}: ${outcome.error}. No charge.\n` });
665
+ }
666
+ else {
667
+ const tx = outcome.txHash ? ` . tx ${outcome.txHash.slice(0, 12)}…` : '';
668
+ ctx.onEvent({ kind: 'text_delta', text: `Paid ${fmtUsd(outcome.paidUsd)}${tx}\n\n${outcome.result ?? ''}\n` });
669
+ }
670
+ emitDone(ctx);
671
+ return { handled: true };
672
+ }
673
+ // info <slug> — detail card.
674
+ if (/^info(\s|$)/.test(arg)) {
675
+ const slug = arg.slice('info'.length).trim();
676
+ if (!slug) {
677
+ ctx.onEvent({ kind: 'text_delta', text: 'Usage: /market info <slug>\n' });
678
+ emitDone(ctx);
679
+ return { handled: true };
680
+ }
681
+ try {
682
+ const skills = await fetchCatalog({ limit: 200 });
683
+ const skill = skills.find((s) => s.slug === slug);
684
+ ctx.onEvent({ kind: 'text_delta', text: skill ? formatSkillCard(skill) : `No skill "${slug}" in the marketplace.\n` });
685
+ }
686
+ catch (err) {
687
+ ctx.onEvent({ kind: 'text_delta', text: `Could not reach the marketplace: ${err.message}\n` });
688
+ }
689
+ emitDone(ctx);
690
+ return { handled: true };
691
+ }
692
+ // (no arg) browse the top skills, or <keyword> to search — both free.
693
+ try {
694
+ const TOP = 12;
695
+ const skills = await fetchCatalog({ limit: 200, query: arg || undefined });
696
+ const shown = arg ? skills : skills.slice(0, TOP);
697
+ const heading = arg
698
+ ? `Agent talents — ${shown.length} skill(s) matching "${arg}":`
699
+ : `Agent talents — top ${shown.length}${skills.length > TOP ? ` of ${skills.length}` : ''}:`;
700
+ ctx.onEvent({ kind: 'text_delta', text: formatCatalogList(shown, { heading }) });
701
+ }
702
+ catch (err) {
703
+ ctx.onEvent({ kind: 'text_delta', text: `Could not reach the marketplace: ${err.message}\n` });
704
+ }
705
+ emitDone(ctx);
706
+ return { handled: true };
707
+ }
638
708
  // /insights [--days N] — rich usage insights
639
709
  if (input === '/insights' || input.startsWith('/insights ')) {
640
710
  const daysMatch = input.match(/--days\s+(\d+)/);
@@ -1051,7 +1121,7 @@ export async function handleSlashCommand(input, ctx) {
1051
1121
  ...Object.keys(REWRITE_COMMANDS),
1052
1122
  ...ARG_COMMANDS.map(c => c.prefix.trim()),
1053
1123
  ...skillNames,
1054
- '/branch', '/resume', '/model', '/auto', '/wallet', '/cost', '/help', '/clear', '/retry', '/exit', '/session-search', '/ssearch', '/failures',
1124
+ '/branch', '/resume', '/model', '/auto', '/wallet', '/cost', '/help', '/clear', '/retry', '/exit', '/session-search', '/ssearch', '/failures', '/market',
1055
1125
  ];
1056
1126
  const cmd = input.split(/\s/)[0];
1057
1127
  const close = allCommands.filter(c => {
@@ -456,7 +456,7 @@ function formatCompactSummary(raw) {
456
456
  function pickCompactionModel(primaryModel) {
457
457
  // Free parent → free compaction (no silent charge)
458
458
  if (primaryModel.startsWith('nvidia/') || primaryModel === 'blockrun/free') {
459
- return 'nvidia/llama-4-maverick';
459
+ return 'nvidia/qwen3-next-80b-a3b-instruct';
460
460
  }
461
461
  // Use cheapest capable model for summarization to save cost
462
462
  // Tier down: opus/pro → sonnet, sonnet → haiku, everything else → flash (cheapest capable)
@@ -249,7 +249,7 @@ export function parseGroundingResponse(raw) {
249
249
  * choice so both quality gates have the same cost profile. Override via
250
250
  * `FRANKLIN_EVALUATOR_MODEL` to experiment with accuracy/cost trade-offs. */
251
251
  export function evaluatorModel() {
252
- return process.env.FRANKLIN_EVALUATOR_MODEL || 'nvidia/llama-4-maverick';
252
+ return process.env.FRANKLIN_EVALUATOR_MODEL || 'nvidia/qwen3-next-80b-a3b-instruct';
253
253
  }
254
254
  // ─── Run grounding check ─────────────────────────────────────────────────
255
255
  const MAX_EVAL_TOKENS = 512;
@@ -106,7 +106,7 @@ export declare function modelHasExtendedThinking(model: string): boolean;
106
106
  * direct unit testing — the happy path hits it only on stream error.
107
107
  */
108
108
  export declare function classifyToolCallFailure(toolName: string, rawInput: string, signal: AbortSignal | undefined, model: string): string;
109
- export declare function isRoleplayedJsonToolCallText(text: string): boolean;
109
+ export declare function isRoleplayedJsonToolCallText(text: string, knownToolNames?: ReadonlySet<string>): boolean;
110
110
  export declare class ModelClient {
111
111
  private apiUrl;
112
112
  private chain;
package/dist/agent/llm.js CHANGED
@@ -237,12 +237,16 @@ export function extractApiErrorMessage(errorBody) {
237
237
  */
238
238
  export function modelHasExtendedThinking(model) {
239
239
  const m = model.toLowerCase();
240
- // Excluded: Opus 4.7+ uses adaptive thinking; sending `thinking: enabled`
241
- // causes the API to 400.
240
+ // Excluded: Opus 4.7+, Sonnet 5, and Fable 5 use adaptive / always-on
241
+ // thinking; sending an explicit `thinking: enabled` causes the API to 400.
242
242
  if (m.includes('opus-4.8') || m.includes('opus-4-8'))
243
243
  return false;
244
244
  if (m.includes('opus-4.7') || m.includes('opus-4-7'))
245
245
  return false;
246
+ if (m.includes('fable-5') || m.includes('fable5'))
247
+ return false;
248
+ if (m.includes('sonnet-5') || m.includes('sonnet5'))
249
+ return false;
246
250
  return (m.includes('opus-4.6') || m.includes('opus-4-6') ||
247
251
  m.includes('opus-4.5') || m.includes('opus-4-5') ||
248
252
  m.includes('opus-4.1') || m.includes('opus-4-1') ||
@@ -276,22 +280,51 @@ export function classifyToolCallFailure(toolName, rawInput, signal, model) {
276
280
  `Preview: ${preview}${rawInput.length > 120 ? '…' : ''} — ` +
277
281
  `this is usually a model output bug; try \`/model <other>\` or retry.]`;
278
282
  }
279
- export function isRoleplayedJsonToolCallText(text) {
283
+ export function isRoleplayedJsonToolCallText(text, knownToolNames) {
280
284
  const trimmed = text.trim();
281
- if (!trimmed.startsWith('{') || !trimmed.endsWith('}'))
285
+ if (!trimmed)
282
286
  return false;
287
+ // Cheap pre-check: every shape we accept either starts with `{` or begins
288
+ // with a known XML wrapper. Avoid JSON.parse on long prose.
289
+ const looksJson = trimmed.startsWith('{') && trimmed.endsWith('}');
290
+ const looksXml = /^<tool_call(s)?>/i.test(trimmed);
291
+ if (!looksJson && !looksXml)
292
+ return false;
293
+ if (looksXml) {
294
+ // Match `<tool_call>{...}</tool_call>`, including the multi-call variant.
295
+ return /<tool_call(s)?>[\s\S]*?<\/tool_call(s)?>/i.test(trimmed);
296
+ }
283
297
  try {
284
298
  const parsed = JSON.parse(trimmed);
285
- return (parsed !== null &&
286
- typeof parsed === 'object' &&
287
- !Array.isArray(parsed) &&
288
- parsed.type === 'function' &&
289
- typeof parsed.name === 'string' &&
290
- ('parameters' in parsed || 'arguments' in parsed));
299
+ if (!parsed || typeof parsed !== 'object' || Array.isArray(parsed))
300
+ return false;
301
+ const obj = parsed;
302
+ // OpenAI envelope: assistant message that forgot to use the tool_calls
303
+ // channel and dumped the whole message JSON into the text stream.
304
+ if (Array.isArray(obj.tool_calls))
305
+ return true;
306
+ // Hermes/Claude roleplay envelope (`type: "function"` + name + arguments).
307
+ if (obj.type === 'function' &&
308
+ typeof obj.name === 'string' &&
309
+ ('parameters' in obj || 'arguments' in obj)) {
310
+ return true;
311
+ }
312
+ // Bare Hermes envelope (no `type`): what nvidia/llama-4-maverick,
313
+ // nvidia/qwen3-next, and similar small models emit. The matching
314
+ // `name` + `parameters|arguments` pair is enough for the scavenger — but
315
+ // only when `name` is a real registered tool. Otherwise ordinary JSON a
316
+ // user asked for (an object that happens to have a `name` and
317
+ // `parameters`/`arguments` field) would be suppressed from display and
318
+ // handed to the scavenger. When no tool set is supplied (e.g. unit tests),
319
+ // fall back to the permissive shape match.
320
+ if (typeof obj.name === 'string' && ('parameters' in obj || 'arguments' in obj)) {
321
+ return knownToolNames ? knownToolNames.has(obj.name) : true;
322
+ }
291
323
  }
292
324
  catch {
293
- return false;
325
+ // Fall through to false; not roleplayed tool-call JSON.
294
326
  }
327
+ return false;
295
328
  }
296
329
  /**
297
330
  * Apply Anthropic prompt caching, budgeted to Anthropic's hard limit of 4
@@ -422,10 +455,10 @@ export class ModelClient {
422
455
  // strings (now retired routing profiles) end up at the same place
423
456
  // without needing dedicated entries.
424
457
  const FALLBACKS = {
425
- 'blockrun/auto': 'nvidia/llama-4-maverick',
426
- 'blockrun/free': 'nvidia/llama-4-maverick',
458
+ 'blockrun/auto': 'nvidia/qwen3-next-80b-a3b-instruct',
459
+ 'blockrun/free': 'nvidia/qwen3-next-80b-a3b-instruct',
427
460
  };
428
- return FALLBACKS[model] || 'nvidia/llama-4-maverick';
461
+ return FALLBACKS[model] || 'nvidia/qwen3-next-80b-a3b-instruct';
429
462
  }
430
463
  /**
431
464
  * USDC actually charged for the most recent stream. 0 if no payment
@@ -767,6 +800,11 @@ export class ModelClient {
767
800
  let currentToolName = '';
768
801
  let currentToolInput = '';
769
802
  const textEmission = { mode: 'undecided' };
803
+ // Registered tool names for this request — used to distinguish a roleplayed
804
+ // bare tool-call envelope from ordinary JSON the user asked the model for.
805
+ const knownToolNames = new Set((request.tools ?? [])
806
+ .map((t) => t.name)
807
+ .filter((n) => typeof n === 'string'));
770
808
  const isNemotronProse = isNemotronProseModel(request.model);
771
809
  // Split inline <think>…</think> emitted by reasoning models (nemotron,
772
810
  // deepseek-r1, qwq, etc.) that use the text field instead of the native
@@ -796,9 +834,16 @@ export class ModelClient {
796
834
  const trimmed = currentText.trimStart();
797
835
  if (!trimmed)
798
836
  return;
799
- // Nemotron Omni leaks reasoning prose into the text channel without
800
- // <think> tags. Hold the buffer for end-of-stream stripping.
801
- textEmission.mode = isNemotronProse || trimmed.startsWith('{') ? 'hold' : 'stream';
837
+ // Hold the buffer when the model is roleplaying a tool call as text
838
+ // (free-tier llama/qwen/nemotron variants frequently do this) so
839
+ // the loop's scavenger can recover it instead of streaming junk
840
+ // to the user. Three shapes we recognize:
841
+ // 1. {…} roleplay JSON envelope
842
+ // 2. <tool_call>…</tool_call> XML
843
+ // 3. Nemotron Omni prose (handled separately below)
844
+ const looksLikeRoleplayJson = trimmed.startsWith('{');
845
+ const looksLikeRoleplayXml = /^<tool_call(s)?>/i.test(trimmed);
846
+ textEmission.mode = isNemotronProse || looksLikeRoleplayJson || looksLikeRoleplayXml ? 'hold' : 'stream';
802
847
  if (textEmission.mode === 'stream') {
803
848
  onStreamDelta?.({ type: 'text', text: currentText });
804
849
  }
@@ -948,7 +993,7 @@ export class ModelClient {
948
993
  }
949
994
  }
950
995
  if (currentText) {
951
- if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText)) {
996
+ if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText, knownToolNames)) {
952
997
  // A roleplayed JSON tool call. Do NOT stream it to the UI,
953
998
  // but DO keep it in `collected` so the loop's scavenge pass
954
999
  // (src/agent/repair/scavenge.ts) can turn it into a real
@@ -1044,7 +1089,7 @@ export class ModelClient {
1044
1089
  }
1045
1090
  }
1046
1091
  if (currentText) {
1047
- if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText)) {
1092
+ if (textEmission.mode === 'hold' && isRoleplayedJsonToolCallText(currentText, knownToolNames)) {
1048
1093
  // See the matching branch in content_block_stop: keep it for the
1049
1094
  // loop's scavenge pass instead of dropping it.
1050
1095
  collected.push({ type: 'text', text: currentText });
@@ -1285,6 +1285,22 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
1285
1285
  if (turnSkillHints) {
1286
1286
  callSystemPrompt = callSystemPrompt + '\n\n' + turnSkillHints;
1287
1287
  }
1288
+ // Force a final answer: withhold tools so the model must commit to text,
1289
+ // either on the last turn or once the tool-call budget is spent. Without
1290
+ // this, models that keep calling tools every turn hit maxTurns with no
1291
+ // answer (and waste the spend). Opt-in per config. Ordered last so a
1292
+ // forced turn intentionally rebuilds the prompt from the base (dropping
1293
+ // the skill hints above); normal turns keep them.
1294
+ const onFinalTurn = config.forceAnswerOnFinalTurn && loopCount === maxTurns;
1295
+ const toolBudgetSpent = config.maxToolCalls != null && turnToolCalls >= config.maxToolCalls;
1296
+ if ((onFinalTurn || toolBudgetSpent) && callToolDefs.length > 0) {
1297
+ callToolDefs = [];
1298
+ callSystemPrompt = systemPrompt + '\n\n' +
1299
+ (toolBudgetSpent
1300
+ ? `You have used your research budget (${config.maxToolCalls} tool calls) — no more tools are available.`
1301
+ : 'This is your FINAL turn — no more tools are available.') +
1302
+ ' Based on the research so far, output ONLY the final answer now, in the exact format requested.';
1303
+ }
1288
1304
  // ── Hallucination guard for weak models ──
1289
1305
  // Weak / free models (nemotron-ultra, GLM-4, qwen coder, free-profile
1290
1306
  // resolves) have been observed inventing tool names (e.g. MixtureOfAgents)
@@ -1398,9 +1414,12 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
1398
1414
  const hasTools = responseParts.some(p => p.type === 'tool_use');
1399
1415
  const hasThinking = responseParts.some(p => p.type === 'thinking');
1400
1416
  if (!hasText && !hasTools && !hasThinking) {
1401
- const EMPTY_FALLBACK_MODELS = ['nvidia/llama-4-maverick', 'nvidia/deepseek-v4-flash', 'zai/glm-5.2'];
1417
+ // Free-only recovery chain — a free/empty-response session must NEVER
1418
+ // fall back to a paid model (would silently charge the wallet). Both
1419
+ // entries are $0 nvidia models.
1420
+ const EMPTY_FALLBACK_MODELS = ['nvidia/qwen3-next-80b-a3b-instruct', 'nvidia/llama-4-maverick'];
1402
1421
  const nextModel = EMPTY_FALLBACK_MODELS.find(m => m !== config.model && !turnFailedModels.has(m));
1403
- if (nextModel && recoveryAttempts < 2) {
1422
+ if (nextModel && recoveryAttempts < 2 && !config.disableModelFallback) {
1404
1423
  recoveryAttempts++;
1405
1424
  turnFailedModels.add(config.model);
1406
1425
  const oldModel = config.model;
@@ -1445,7 +1464,7 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
1445
1464
  'anthropic/claude-sonnet-4.6',
1446
1465
  ];
1447
1466
  const nextModel = TOOL_USE_FALLBACK_MODELS.find(m => m !== config.model && !turnFailedModels.has(m));
1448
- if (nextModel && recoveryAttempts < 2) {
1467
+ if (nextModel && recoveryAttempts < 2 && !config.disableModelFallback) {
1449
1468
  recoveryAttempts++;
1450
1469
  turnFailedModels.add(config.model);
1451
1470
  const oldModel = config.model;
@@ -2061,7 +2080,7 @@ export async function interactiveSession(config, getUserInput, onEvent, onAbortR
2061
2080
  .filter(p => p.type === 'text' && typeof p.text === 'string')
2062
2081
  .map(p => p.text)
2063
2082
  .join('');
2064
- if (shouldCheckGrounding(lastUserInput || '', assistantText)) {
2083
+ if (!config.disableGroundingRetry && shouldCheckGrounding(lastUserInput || '', assistantText)) {
2065
2084
  const gResult = await checkGrounding(lastUserInput, history, assistantText, client, {
2066
2085
  abortSignal: abort.signal,
2067
2086
  });
@@ -25,16 +25,26 @@ const MODEL_MAX_OUTPUT = {
25
25
  // (anthropic/claude-opus-4.8 maxOutput: 128000). Bumping from 32k to
26
26
  // 128k unlocks the full headroom — runaway generations are gated
27
27
  // separately by CAPPED_MAX_TOKENS / ESCALATED_MAX_TOKENS budgets.
28
+ 'anthropic/claude-fable-5': 128_000,
28
29
  'anthropic/claude-opus-4.8': 128_000,
29
30
  'anthropic/claude-opus-4.7': 128_000,
30
31
  'anthropic/claude-opus-4.6': 32_000,
32
+ 'anthropic/claude-opus-4.5': 32_000,
33
+ 'anthropic/claude-sonnet-5': 128_000,
31
34
  'anthropic/claude-sonnet-4.6': 64_000,
35
+ 'anthropic/claude-sonnet-4.5': 64_000,
32
36
  'anthropic/claude-haiku-4.5-20251001': 16_384,
37
+ 'openai/gpt-5.6-sol': 128_000,
38
+ 'openai/gpt-5.6-terra': 128_000,
39
+ 'openai/gpt-5.6-luna': 128_000,
33
40
  'openai/gpt-5.5': 32_768,
34
41
  'openai/gpt-5.4': 32_768,
42
+ 'openai/gpt-5.4-mini': 128_000,
43
+ 'openai/gpt-5.4-nano': 32_768,
35
44
  'openai/gpt-5-mini': 16_384,
36
45
  'google/gemini-2.5-pro': 65_536,
37
46
  'google/gemini-2.5-flash': 65_536,
47
+ 'google/gemini-3.5-flash': 65_536,
38
48
  // DeepSeek V4 family — upstream max_output is 65K on V4 Flash + V4 Pro;
39
49
  // gateway re-aliased deepseek-chat/-reasoner to V4 Flash modes 2026-05-03.
40
50
  'deepseek/deepseek-chat': 65_536,
@@ -131,6 +131,16 @@ export class PermissionManager {
131
131
  }
132
132
  return { behavior: 'ask' };
133
133
  }
134
+ // agent_talent: browsing the marketplace is a free read (auto-allow);
135
+ // hiring (action="run") spends USDC from the wallet and has no refund, so
136
+ // it asks — same policy as the other paid, irreversible tools (VoiceCall,
137
+ // BuyPhoneNumber). describeAction spells out the spend in the prompt.
138
+ if (toolName === 'agent_talent') {
139
+ const action = typeof input.action === 'string' ? input.action.toLowerCase() : '';
140
+ return action === 'run'
141
+ ? { behavior: 'ask' }
142
+ : { behavior: 'allow', reason: 'free marketplace browse' };
143
+ }
134
144
  // Default: read-only tools are auto-allowed, others ask
135
145
  if (READ_ONLY_TOOLS.has(toolName)) {
136
146
  return { behavior: 'allow', reason: 'read-only default' };
@@ -325,6 +335,13 @@ export class PermissionManager {
325
335
  }
326
336
  case 'Agent':
327
337
  return `Launch sub-agent: ${input.description || input.prompt?.slice(0, 80) || 'task'}`;
338
+ case 'agent_talent': {
339
+ if ((input.action || '').toLowerCase() === 'run') {
340
+ const slug = input.slug || 'a skill';
341
+ return `Hire '${slug}' from the agent marketplace — pays from your wallet (USDC on Base, up to $5/hire), charged only on a successful run.`;
342
+ }
343
+ return 'Browse the agent marketplace (free).';
344
+ }
328
345
  default:
329
346
  return JSON.stringify(input).slice(0, 120);
330
347
  }
@@ -195,10 +195,16 @@ const MODEL_CONTEXT_WINDOWS = {
195
195
  // edge yet — sending more than 200k without it 413s. Keep 200k as the
196
196
  // safe Franklin baseline; bump to 1_000_000 in a separate commit once
197
197
  // a real >200k call has been verified end-to-end.
198
+ // Fable 5 / Sonnet 5 advertise 1M at the gateway; keep the 200k safe baseline
199
+ // (same rationale as Opus above) until a real >200k call is verified.
200
+ 'anthropic/claude-fable-5': 200_000,
198
201
  'anthropic/claude-opus-4.8': 200_000,
199
202
  'anthropic/claude-opus-4.7': 200_000,
200
203
  'anthropic/claude-opus-4.6': 200_000,
204
+ 'anthropic/claude-opus-4.5': 200_000,
205
+ 'anthropic/claude-sonnet-5': 200_000,
201
206
  'anthropic/claude-sonnet-4.6': 200_000,
207
+ 'anthropic/claude-sonnet-4.5': 200_000,
202
208
  'anthropic/claude-sonnet-4': 200_000,
203
209
  'anthropic/claude-haiku-4.5': 200_000,
204
210
  'anthropic/claude-haiku-4.5-20251001': 200_000,
@@ -206,9 +212,14 @@ const MODEL_CONTEXT_WINDOWS = {
206
212
  // gpt-5.5 advertises 1.05M context at the gateway, but Franklin keeps the
207
213
  // conservative 128k baseline matching every other gpt-5.x line — bump in
208
214
  // a separate change once a real >128k call has been verified end-to-end.
215
+ 'openai/gpt-5.6-sol': 128_000,
216
+ 'openai/gpt-5.6-terra': 128_000,
217
+ 'openai/gpt-5.6-luna': 128_000,
209
218
  'openai/gpt-5.5': 128_000,
210
219
  'openai/gpt-5.4': 128_000,
211
220
  'openai/gpt-5.4-pro': 128_000,
221
+ 'openai/gpt-5.4-mini': 128_000,
222
+ 'openai/gpt-5.4-nano': 128_000,
212
223
  'openai/gpt-5.3': 128_000,
213
224
  'openai/gpt-5.3-codex': 128_000,
214
225
  'openai/gpt-5.2': 128_000,
@@ -222,6 +233,8 @@ const MODEL_CONTEXT_WINDOWS = {
222
233
  'google/gemini-2.5-flash': 1_000_000,
223
234
  'google/gemini-2.5-flash-lite': 1_000_000,
224
235
  'google/gemini-3.1-pro': 1_000_000,
236
+ 'google/gemini-3.5-flash': 1_000_000,
237
+ 'google/gemini-3.1-flash-lite': 1_000_000,
225
238
  // DeepSeek (V4 family — gateway aliased deepseek-chat / -reasoner to V4
226
239
  // Flash on 2026-05-03; context bumped 128K → 1M for both, 65K out)
227
240
  'deepseek/deepseek-chat': 1_000_000,
@@ -239,9 +252,17 @@ const MODEL_CONTEXT_WINDOWS = {
239
252
  'moonshot/kimi-k2.5': 128_000,
240
253
  'minimax/minimax-m3': 1_000_000,
241
254
  'minimax/minimax-m2.7': 128_000,
242
- // NVIDIA-hosted free tier (2026-04-29 V4 Flash + Omni launch)
243
- 'nvidia/deepseek-v4-flash': 1_000_000,
255
+ // NVIDIA-hosted free tier (refreshed 2026-07-11 to match live /v1/models).
256
+ 'nvidia/qwen3-next-80b-a3b-instruct': 262_144, // current free default
257
+ 'nvidia/qwen3.5-122b-a10b': 131_072,
244
258
  'nvidia/nemotron-3-nano-omni-30b-a3b-reasoning': 256_000,
259
+ 'nvidia/mistral-nemotron': 131_072,
260
+ 'nvidia/step-3.7-flash': 131_072,
261
+ 'nvidia/seed-oss-36b': 131_072,
262
+ 'nvidia/nemotron-nano-9b-v2': 131_072,
263
+ 'nvidia/nemotron-nano-12b-v2-vl': 131_072,
264
+ 'nvidia/llama-4-maverick': 131_072,
265
+ 'nvidia/mistral-large-3-675b': 131_072,
245
266
  };
246
267
  /**
247
268
  * Get the context window size for a model, with a conservative default.
@@ -55,7 +55,7 @@ const CACHE_MAX_SIZE = 64;
55
55
  // emit a single-line JSON. Maverick (the classifier backbone since v3.8.23)
56
56
  // reliably produces plain-text structured output under tight max_tokens,
57
57
  // unlike thinking-first models that leave text empty.
58
- const ANALYZER_MODEL_DEFAULT = process.env.FRANKLIN_ANALYZER_MODEL || 'nvidia/llama-4-maverick';
58
+ const ANALYZER_MODEL_DEFAULT = process.env.FRANKLIN_ANALYZER_MODEL || 'nvidia/qwen3-next-80b-a3b-instruct';
59
59
  const ANALYZER_SYSTEM = `You analyze ONE user message for Franklin's routing + prefetch harness. Output ONE LINE of compact JSON — no explanation, no markdown, no code fences.
60
60
 
61
61
  ## Fields
@@ -187,6 +187,30 @@ export interface AgentConfig {
187
187
  maxSpendUsd?: number;
188
188
  /** Show user-visible harness prefetch status lines (interactive UX only). */
189
189
  showPrefetchStatus?: boolean;
190
+ /**
191
+ * On the final turn, withhold tools so the model must commit to a text answer
192
+ * instead of researching until cut off. For one-shot forecasting/extraction
193
+ * callers (e.g. `franklin predict`) where some models never stop calling tools
194
+ * and would otherwise hit maxTurns with no answer.
195
+ */
196
+ forceAnswerOnFinalTurn?: boolean;
197
+ /**
198
+ * Hard cap on total tool calls for the turn. Once reached, tools are withheld
199
+ * and the model is forced to answer from what it has. Bounds research/cost
200
+ * deterministically (a turn budget alone doesn't — a turn may have no tool).
201
+ */
202
+ maxToolCalls?: number;
203
+ /**
204
+ * Disable Franklin's automatic model-switching (empty-response / stalled-intent
205
+ * fallbacks). One-shot callers want a clean abstain from the requested model,
206
+ * not a silent switch to a different one.
207
+ */
208
+ disableModelFallback?: boolean;
209
+ /**
210
+ * Disable the post-response "ungrounded claims → force a tool-use retry" guard.
211
+ * It fights the forced-answer path and pollutes one-shot structured output.
212
+ */
213
+ disableGroundingRetry?: boolean;
190
214
  /** Mid-turn "research-bloat" compaction — summarizes history when a turn
191
215
  * racks up many tool calls + spend, to cut input-replay cost. Default on;
192
216
  * set false to disable (the desktop exposes this as a toggle). */
@@ -113,7 +113,7 @@ export async function runVerification(history, handlers, client, config) {
113
113
  ];
114
114
  config.onEvent?.({ kind: 'text_delta', text: '\n*Verifying...*\n' });
115
115
  // Use agent-tested free model for verification.
116
- const verificationModel = 'nvidia/llama-4-maverick';
116
+ const verificationModel = 'nvidia/qwen3-next-80b-a3b-instruct';
117
117
  try {
118
118
  // Simple single-turn verification call
119
119
  const response = await client.complete({
@@ -0,0 +1,10 @@
1
+ export interface PredictOptions {
2
+ model?: string;
3
+ question?: string;
4
+ maxTurns?: string;
5
+ maxToolCalls?: string;
6
+ maxSpend?: string;
7
+ json?: boolean;
8
+ debug?: boolean;
9
+ }
10
+ export declare function predictCommand(options: PredictOptions): Promise<void>;