cascade-ai 0.66.0 → 0.66.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/dist/cli.js CHANGED
@@ -1757,7 +1757,7 @@ var CASCADE_VERSION, CASCADE_CONFIG_FILE, CASCADE_DB_FILE, CASCADE_DASHBOARD_SEC
1757
1757
  var init_constants = __esm({
1758
1758
  "src/constants.ts"() {
1759
1759
  init_pricing();
1760
- CASCADE_VERSION = "0.66.0";
1760
+ CASCADE_VERSION = "0.66.2";
1761
1761
  CASCADE_CONFIG_FILE = ".cascade/config.json";
1762
1762
  CASCADE_DB_FILE = ".cascade/memory.db";
1763
1763
  CASCADE_DASHBOARD_SECRET_FILE = ".cascade/dashboard-secret";
@@ -9049,7 +9049,15 @@ var KNOWN_TOOLS = [
9049
9049
  "glob",
9050
9050
  "grep",
9051
9051
  "web_fetch",
9052
- "generate_image"
9052
+ // Every media tool buildMediaTools can register, not just the image one.
9053
+ // Omitting three of the four meant a run whose ONLY tools were media ones
9054
+ // (a video-generation subtask on an account with no file/web tools) counted
9055
+ // as "no tools registered" and dropped all tool guidance — the worker was
9056
+ // then told nothing about using tools at all, and wrote the video as prose.
9057
+ "generate_image",
9058
+ "generate_video",
9059
+ "generate_speech",
9060
+ "transcribe_audio"
9053
9061
  ];
9054
9062
  var PROVIDER_BACKED_TOOLS = /* @__PURE__ */ new Set([
9055
9063
  "generate_image",
@@ -9078,6 +9086,15 @@ function buildWorkerRules(has) {
9078
9086
  // reference straight to caption text — telling the model to call
9079
9087
  // generate_image for THOSE just pays for an image nobody ever sees.
9080
9088
  has("generate_image") && '- When a slide deck (PowerPoint) or Word document deliverable calls for a decorative image or illustration, you MUST call the "generate_image" tool and then reference its result using Markdown image syntax: ![description](location), where "location" is exactly the string the tool reported back. NEVER write a text placeholder or a bracketed description such as [image: a cat] in its place. Do NOT use "generate_image" for a chart, graph, or diagram that must show exact data (numbers, axes, labels) \u2014 an image model cannot guarantee those values are correct, so render that data as a Markdown table instead. For any OTHER deliverable format (PDF, plain text, code, etc.) do NOT call "generate_image" \u2014 those cannot embed the result, so describe the visual in words instead.',
9089
+ // The video counterpart of the image rule above, and the fix for the
9090
+ // reported "it writes scripts forever and never makes the video" run. The
9091
+ // failure mode is identical — the model narrates the deliverable instead of
9092
+ // producing it — but the stakes are not: a video subtask that ends in prose
9093
+ // has burned the whole pre-production plan for nothing. Unlike the image
9094
+ // rule this is NOT scoped to a document format, because the clip itself is
9095
+ // the deliverable rather than an illustration inside one, and the reference
9096
+ // syntax is a plain link: Markdown image syntax does not embed a video.
9097
+ has("generate_video") && '- When the subtask deliverable is a video, you MUST call the "generate_video" tool \u2014 that call IS the deliverable, and the subtask is not done until it has returned. NEVER deliver the video as prose, a script, a storyboard, or a bracketed placeholder such as [video: a cat skating], and NEVER claim a video exists unless the tool reported a location for it. Call it exactly ONCE: it is billed per second of output and renders for minutes, so a second call charges the user again. Then report the location string the tool returned VERBATIM as your result, referencing it as [description](location) if it goes inside a document. If the tool reports a failure or a timeout, report that failure verbatim and stop \u2014 do NOT call it again, and do NOT substitute a written description of a video that was never made.',
9081
9098
  has("run_code") && '- Use the "run_code" tool for any file types (Excel, Zip, csv, etc.) or complex processing not covered by other tools. Always cleanup after code execution.',
9082
9099
  "- If you are not making meaningful progress, stop and escalate rather than looping or padding the response.",
9083
9100
  has("peer_message") && '- Use the "peer_message" tool to communicate with other T3 workers if your tasks have dependencies or shared state. You can send updates or wait for signals.',
@@ -9620,6 +9637,12 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
9620
9637
  if (isTaggedSystemic || isProviderBacked && classifyProviderError(err).systemic) {
9621
9638
  throw new CriticalToolError(errMsg, tc.name);
9622
9639
  }
9640
+ if (isProviderBacked) {
9641
+ throw new CriticalToolError(
9642
+ `${tc.name} failed and was not retried \u2014 media generation is billed per attempt, so Cascade stops on the first failure instead of paying for a second. Reason: ${errMsg}`,
9643
+ tc.name
9644
+ );
9645
+ }
9623
9646
  return await this.adaptiveFallback(tc, `Tool error: ${errMsg}`);
9624
9647
  }
9625
9648
  }
@@ -9629,6 +9652,14 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
9629
9652
  * 1. Find a semantically similar registered tool and retry with same input
9630
9653
  * 2. Synthesize a new tool via ToolCreator (if available) and run it
9631
9654
  * 3. Return the original error so the agent loop can decide what to do next
9655
+ *
9656
+ * Scoped to CHEAP, task-scoped failures — the class of problem it was built
9657
+ * for is a wrong or missing tool name, where a name-similar sibling plausibly
9658
+ * does the same job for the same (near-zero) cost. PROVIDER_BACKED_TOOLS never
9659
+ * reach it: their siblings are keyword-similar but semantically different
9660
+ * (generate_image is not a stand-in for generate_video), and every attempt —
9661
+ * theirs, or a synthesized replacement's — is separately billed. See the
9662
+ * fast-fail branch in executeTool().
9632
9663
  */
9633
9664
  async adaptiveFallback(tc, originalError) {
9634
9665
  const altTool = this.findAlternativeTool(tc.name);
@@ -10381,15 +10412,245 @@ _(incomplete: ${t2Result.issues.join("; ")})_`;
10381
10412
  return output;
10382
10413
  }
10383
10414
 
10415
+ // src/core/multimodal/registry.ts
10416
+ init_pricing();
10417
+ var CAPABILITIES = [
10418
+ // ── Image ──
10419
+ {
10420
+ modality: "image",
10421
+ provider: "openai",
10422
+ modelId: "dall-e-3",
10423
+ api: "openai-images"
10424
+ },
10425
+ {
10426
+ // Was `imagen-4.0-generate-001` on `:predict`, which now 404s for new keys
10427
+ // ("no longer available to new users") — Imagen's :predict API is deprecated
10428
+ // and shuts down 2026-08-17. Google's own migration path is this model on
10429
+ // the ordinary generateContent endpoint, so the fix was never another Imagen
10430
+ // id: the whole request/response SHAPE changes, which is why `api` moved to
10431
+ // 'gemini-generate-content' rather than just the modelId moving.
10432
+ // https://ai.google.dev/gemini-api/docs/imagen
10433
+ modality: "image",
10434
+ provider: "gemini",
10435
+ modelId: "gemini-2.5-flash-image",
10436
+ api: "gemini-generate-content"
10437
+ },
10438
+ // ── Speech (text → audio) ──
10439
+ {
10440
+ modality: "speech",
10441
+ provider: "openai",
10442
+ modelId: "tts-1",
10443
+ api: "openai-speech"
10444
+ },
10445
+ {
10446
+ // The only quality claim in this table that needs no leaderboard: OpenAI
10447
+ // ships these as the same voice at two fidelities and charges double for
10448
+ // this one. That is the vendor's own ordering, not an inference.
10449
+ modality: "speech",
10450
+ provider: "openai",
10451
+ modelId: "tts-1-hd",
10452
+ api: "openai-speech",
10453
+ quality: 70,
10454
+ qualityBasis: "OpenAI's own hd variant of tts-1, priced 2x"
10455
+ },
10456
+ // ── Transcription (audio → text) ──
10457
+ {
10458
+ modality: "transcription",
10459
+ provider: "openai",
10460
+ modelId: "whisper-1",
10461
+ api: "openai-transcriptions"
10462
+ },
10463
+ // ── Video ──
10464
+ {
10465
+ // Long-running: submit returns an operation name, the video lands minutes
10466
+ // later, and the bytes come from a short-lived signed URL. generate.ts owns
10467
+ // that polling loop; the registry only records the shape via `api`.
10468
+ //
10469
+ // `veo-3.1-generate-001` (no "-preview") is VERTEX AI's id for this model,
10470
+ // not the Gemini Developer API's — this file calls
10471
+ // generativelanguage.googleapis.com (see generate.ts), which 404s on it:
10472
+ // "models/veo-3.1-generate-001 is not found for API version v1beta". On the
10473
+ // Gemini API specifically, Veo 3.1 is still preview-only, so the correct id
10474
+ // there is `veo-3.1-generate-preview`.
10475
+ // https://ai.google.dev/gemini-api/docs/veo
10476
+ modality: "video",
10477
+ provider: "gemini",
10478
+ modelId: "veo-3.1-generate-preview",
10479
+ api: "gemini-predict-lro"
10480
+ }
10481
+ ];
10482
+ function capabilityCost(cap) {
10483
+ const match = findPricing(cap.modelId, cap.provider, {
10484
+ fallbackProviders: cap.provider === "gemini" ? ["vertex"] : []
10485
+ });
10486
+ const rate = match?.entry.rates?.[0];
10487
+ if (!rate) return null;
10488
+ const unitLabel = {
10489
+ per_image: "per image",
10490
+ per_second: "per second of video",
10491
+ per_character: "per character",
10492
+ per_audio_minute: "per audio minute"
10493
+ };
10494
+ const unit = unitLabel[rate.unit] ?? rate.unit;
10495
+ const amount = rate.amount;
10496
+ const shown = amount < 1e-3 ? amount.toExponential(2) : amount.toFixed(4);
10497
+ return { label: `$${shown} ${unit}`, amount, unit };
10498
+ }
10499
+ function explainChoice(c, cost, modality, isBest) {
10500
+ const priced = cost ? ` ${cost.label}.` : "";
10501
+ if (c.quality !== void 0) {
10502
+ return isBest ? `${c.modelId} (${c.provider}) \u2014 ranked highest for ${modality}: ${c.qualityBasis}.${priced}` : `${c.modelId} (${c.provider}) \u2014 ranked alternative for ${modality}: ${c.qualityBasis}.${priced}`;
10503
+ }
10504
+ const noRanking = ". No published quality ranking is applied for this modality, so this is a cost choice, not a quality one.";
10505
+ return isBest ? `${c.modelId} (${c.provider}) \u2014 cheapest usable ${modality} model` + (cost ? ` at ${cost.label}` : "") + noRanking : `${c.modelId} (${c.provider}) \u2014 alternative usable ${modality} model` + (cost ? ` at ${cost.label}` : "") + noRanking;
10506
+ }
10507
+ var MultimodalRegistry = class {
10508
+ /** Provider types the user has actually configured a key for. */
10509
+ available;
10510
+ constructor(availableProviders) {
10511
+ this.available = new Set(availableProviders);
10512
+ }
10513
+ /** Every capability whose provider is configured AND which Cascade can call. */
10514
+ usable(modality) {
10515
+ return CAPABILITIES.filter(
10516
+ (c) => !c.unsupported && this.available.has(c.provider) && (!modality || c.modality === modality)
10517
+ );
10518
+ }
10519
+ /** Modalities this account can actually generate right now. */
10520
+ availableModalities() {
10521
+ return [...new Set(this.usable().map((c) => c.modality))];
10522
+ }
10523
+ /**
10524
+ * Every usable capability for a modality, best first.
10525
+ *
10526
+ * Ranked models beat unranked ones, then higher quality, then lower unit
10527
+ * price. An explicit `preferModel` is moved to the head when it is usable —
10528
+ * the user naming a model is a stronger signal than any prior.
10529
+ *
10530
+ * `select()` is just the head of this list. The TAIL is the point: a systemic
10531
+ * provider failure (dead key, 404, exhausted quota) is scoped to one
10532
+ * provider+model, so "this model cannot draw" is not the same fact as "this
10533
+ * account cannot draw". A caller holding the ordered alternatives can try the
10534
+ * next provider instead of aborting the whole run — see generate-media.ts.
10535
+ */
10536
+ rank(modality, opts = {}) {
10537
+ const scored = this.usable(modality).map((c) => ({ c, cost: capabilityCost(c) })).sort((a, b) => {
10538
+ const qa = a.c.quality ?? -1;
10539
+ const qb = b.c.quality ?? -1;
10540
+ if (qa !== qb) return qb - qa;
10541
+ const pa = a.cost?.amount ?? Number.POSITIVE_INFINITY;
10542
+ const pb = b.cost?.amount ?? Number.POSITIVE_INFINITY;
10543
+ return pa - pb;
10544
+ });
10545
+ const results = scored.map(({ c, cost }, i) => ({
10546
+ capability: c,
10547
+ cost,
10548
+ reason: explainChoice(c, cost, modality, i === 0)
10549
+ }));
10550
+ if (opts.preferModel) {
10551
+ const i = results.findIndex((r) => r.capability.modelId === opts.preferModel);
10552
+ if (i > -1) {
10553
+ const [wanted] = results.splice(i, 1);
10554
+ results.unshift({ ...wanted, reason: `Requested explicitly: ${wanted.capability.modelId}.` });
10555
+ }
10556
+ }
10557
+ return results;
10558
+ }
10559
+ /**
10560
+ * Pick a model for a modality — the best usable one, or null if there is none.
10561
+ */
10562
+ select(modality, opts = {}) {
10563
+ return this.rank(modality, opts)[0] ?? null;
10564
+ }
10565
+ /**
10566
+ * A plain-language account of what this account can and cannot generate —
10567
+ * including the things it cannot, and why.
10568
+ *
10569
+ * This is the USER-facing inventory (model ids and unit prices), keyed on
10570
+ * which providers are configured. It is deliberately NOT what the planner
10571
+ * reads: see `describeGenerationForPlanner()` below for that, and the note
10572
+ * there for why the two cannot be the same string.
10573
+ */
10574
+ describe() {
10575
+ const lines = [];
10576
+ const usable = this.usable();
10577
+ if (usable.length) {
10578
+ lines.push("Generation models available on your configured providers:");
10579
+ for (const modality of ["image", "speech", "transcription", "video"]) {
10580
+ const forModality = usable.filter((c) => c.modality === modality);
10581
+ if (!forModality.length) continue;
10582
+ const shown = forModality.map((c) => {
10583
+ const cost = capabilityCost(c);
10584
+ return `${c.modelId}${cost ? ` (${cost.label})` : ""}`;
10585
+ });
10586
+ lines.push(` ${modality}: ${shown.join(", ")}`);
10587
+ }
10588
+ } else {
10589
+ lines.push("No generation models are available \u2014 none of your configured providers offers one.");
10590
+ }
10591
+ const blocked = CAPABILITIES.filter((c) => c.unsupported && this.available.has(c.provider));
10592
+ for (const c of blocked) {
10593
+ lines.push(` ${c.modality}: ${c.modelId} exists on your account but is not callable. ${c.unsupported}`);
10594
+ }
10595
+ lines.push(
10596
+ " music: no supported provider exposes a music-generation API, so Cascade cannot generate music."
10597
+ );
10598
+ return lines.join("\n");
10599
+ }
10600
+ };
10601
+ var PLANNER_FACTS = [
10602
+ { tool: "generate_image", modality: "image", shape: "one call returns one finished image" },
10603
+ { tool: "generate_speech", modality: "speech", shape: "one call returns one finished audio file" },
10604
+ {
10605
+ tool: "generate_video",
10606
+ modality: "video",
10607
+ shape: "one call returns one finished clip, after rendering for 1-3 minutes (Cascade stops waiting at 8)"
10608
+ },
10609
+ {
10610
+ tool: "transcribe_audio",
10611
+ modality: "transcription",
10612
+ shape: "one call returns the transcript of one audio file"
10613
+ }
10614
+ ];
10615
+ function plannerPriceNote(modality) {
10616
+ const costs = CAPABILITIES.filter((c) => c.modality === modality && !c.unsupported).map((c) => capabilityCost(c)).filter((c) => c !== null);
10617
+ if (!costs.length) return "";
10618
+ const labels = new Set(costs.map((c) => c.label));
10619
+ if (labels.size === 1) return ` Billed ${costs[0].label}.`;
10620
+ const units = new Set(costs.map((c) => c.unit));
10621
+ return units.size === 1 ? ` Billed ${[...units][0]}.` : "";
10622
+ }
10623
+ function describeGenerationForPlanner(has) {
10624
+ const present = PLANNER_FACTS.filter((f) => has(f.tool));
10625
+ if (!present.length) return "";
10626
+ const lines = ["MEDIA GENERATION \u2014 the only generation tools this run can call:"];
10627
+ for (const f of present) {
10628
+ lines.push(`- "${f.tool}" (${f.modality}): ${f.shape}.${plannerPriceNote(f.modality)}`);
10629
+ }
10630
+ lines.push(
10631
+ "Each one is a single ATOMIC tool call, made by ONE T3 worker, that produces the finished file. It is never a multi-step pipeline, and no worker can satisfy it by describing the result in words.",
10632
+ "No other modality has a tool here \u2014 never plan a step that generates music, 3D or anything not listed above."
10633
+ );
10634
+ if (has("generate_video")) {
10635
+ lines.push(
10636
+ 'VIDEO PLANS MUST END IN THE TOOL CALL. Creative pre-production \u2014 a script, a shot list, direction notes \u2014 is expected and worth planning, but it is NOT the video. Any plan that involves video MUST contain exactly ONE subtask whose deliverable is the "generate_video" call itself; it MUST be the last subtask on that path (dependsOn the pre-production ones), and nothing after it may be required to produce the clip. Never end a video plan on a script, a storyboard or a review step. Never split one clip across several "generate_video" subtasks, and never plan a render \u2192 critique \u2192 re-render loop: every render is billed again and takes minutes.'
10637
+ );
10638
+ }
10639
+ return lines.join("\n");
10640
+ }
10641
+
10384
10642
  // src/core/tiers/t2-manager.ts
10385
- function buildT2SystemPrompt(hasPeerMessage) {
10643
+ function buildT2SystemPrompt(has) {
10644
+ const generation = describeGenerationForPlanner(has);
10386
10645
  return [
10387
10646
  "You are a T2 Manager agent in the Cascade AI system.",
10388
10647
  "Your role is to analyze a section of a task and decompose it into 2-5 discrete subtasks for T3 Workers.",
10389
10648
  'If subtasks have dependencies, you can specify "executionMode": "sequential" for the section.',
10390
- hasPeerMessage && 'Provide "peerT3Ids" to subtasks so they can coordinate using the peer_message tool.',
10391
- "Return ONLY valid JSON matching the T3 subtask array schema \u2014 no other text."
10392
- ].filter((l) => l !== false).join("\n");
10649
+ has("peer_message") && 'Provide "peerT3Ids" to subtasks so they can coordinate using the peer_message tool.',
10650
+ "Return ONLY valid JSON matching the T3 subtask array schema \u2014 no other text.",
10651
+ generation && `
10652
+ ${generation}`
10653
+ ].filter((l) => l !== false && l !== "").join("\n");
10393
10654
  }
10394
10655
  var T2Manager = class extends BaseTier {
10395
10656
  router;
@@ -10686,7 +10947,7 @@ Return ONLY the JSON array.`;
10686
10947
  const messages = [{ role: "user", content: prompt }];
10687
10948
  const result = await this.router.generate("T2", {
10688
10949
  messages,
10689
- systemPrompt: this.systemPromptOverride + buildT2SystemPrompt(this.toolRegistry.hasTool("peer_message")) + (this.hierarchyContext ? `
10950
+ systemPrompt: this.systemPromptOverride + buildT2SystemPrompt((name) => this.toolRegistry.hasTool(name)) + (this.hierarchyContext ? `
10690
10951
 
10691
10952
  HIERARCHY CONTEXT: ${this.hierarchyContext}` : ""),
10692
10953
  maxTokens: 2e3,
@@ -11239,6 +11500,7 @@ function isStrongKeywordOverlap(a = [], b = []) {
11239
11500
  }
11240
11501
  function buildT1SystemPrompt(has) {
11241
11502
  const canWriteArtifacts = has("file_write") || has("file_edit") || has("run_code") || has("pdf_create");
11503
+ const generation = describeGenerationForPlanner(has);
11242
11504
  const rules = [
11243
11505
  "- Simple \u2192 1 T3, Moderate \u2192 2-3 T2s, Complex \u2192 3-5 T2s, Highly Complex \u2192 5+ T2s",
11244
11506
  "- Return ONLY valid JSON \u2014 no other text",
@@ -11273,7 +11535,9 @@ DEPENDENCY GUIDANCE:
11273
11535
  QUALITY RULES:
11274
11536
  - Each section must have a clear, testable "expectedOutput" so T2 knows when it is done.
11275
11537
  - Do NOT create trivial sections that only move files or print summaries \u2014 fold those into adjacent sections.
11276
- - If the plan would naturally produce fewer than 2 independent sections, prefer Moderate routing (single T2).`;
11538
+ - If the plan would naturally produce fewer than 2 independent sections, prefer Moderate routing (single T2).${generation ? `
11539
+
11540
+ ${generation}` : ""}`;
11277
11541
  }
11278
11542
  var T1Administrator = class extends BaseTier {
11279
11543
  router;
@@ -11971,189 +12235,6 @@ Reply with exactly one word: YES, NO, or UNSURE.
11971
12235
  // src/core/cascade.ts
11972
12236
  init_cost();
11973
12237
 
11974
- // src/core/multimodal/registry.ts
11975
- init_pricing();
11976
- var CAPABILITIES = [
11977
- // ── Image ──
11978
- {
11979
- modality: "image",
11980
- provider: "openai",
11981
- modelId: "dall-e-3",
11982
- api: "openai-images"
11983
- },
11984
- {
11985
- // Was `imagen-4.0-generate-001` on `:predict`, which now 404s for new keys
11986
- // ("no longer available to new users") — Imagen's :predict API is deprecated
11987
- // and shuts down 2026-08-17. Google's own migration path is this model on
11988
- // the ordinary generateContent endpoint, so the fix was never another Imagen
11989
- // id: the whole request/response SHAPE changes, which is why `api` moved to
11990
- // 'gemini-generate-content' rather than just the modelId moving.
11991
- // https://ai.google.dev/gemini-api/docs/imagen
11992
- modality: "image",
11993
- provider: "gemini",
11994
- modelId: "gemini-2.5-flash-image",
11995
- api: "gemini-generate-content"
11996
- },
11997
- // ── Speech (text → audio) ──
11998
- {
11999
- modality: "speech",
12000
- provider: "openai",
12001
- modelId: "tts-1",
12002
- api: "openai-speech"
12003
- },
12004
- {
12005
- // The only quality claim in this table that needs no leaderboard: OpenAI
12006
- // ships these as the same voice at two fidelities and charges double for
12007
- // this one. That is the vendor's own ordering, not an inference.
12008
- modality: "speech",
12009
- provider: "openai",
12010
- modelId: "tts-1-hd",
12011
- api: "openai-speech",
12012
- quality: 70,
12013
- qualityBasis: "OpenAI's own hd variant of tts-1, priced 2x"
12014
- },
12015
- // ── Transcription (audio → text) ──
12016
- {
12017
- modality: "transcription",
12018
- provider: "openai",
12019
- modelId: "whisper-1",
12020
- api: "openai-transcriptions"
12021
- },
12022
- // ── Video ──
12023
- {
12024
- // Long-running: submit returns an operation name, the video lands minutes
12025
- // later, and the bytes come from a short-lived signed URL. generate.ts owns
12026
- // that polling loop; the registry only records the shape via `api`.
12027
- //
12028
- // `veo-3.1-generate-001` (no "-preview") is VERTEX AI's id for this model,
12029
- // not the Gemini Developer API's — this file calls
12030
- // generativelanguage.googleapis.com (see generate.ts), which 404s on it:
12031
- // "models/veo-3.1-generate-001 is not found for API version v1beta". On the
12032
- // Gemini API specifically, Veo 3.1 is still preview-only, so the correct id
12033
- // there is `veo-3.1-generate-preview`.
12034
- // https://ai.google.dev/gemini-api/docs/veo
12035
- modality: "video",
12036
- provider: "gemini",
12037
- modelId: "veo-3.1-generate-preview",
12038
- api: "gemini-predict-lro"
12039
- }
12040
- ];
12041
- function capabilityCost(cap) {
12042
- const match = findPricing(cap.modelId, cap.provider, {
12043
- fallbackProviders: cap.provider === "gemini" ? ["vertex"] : []
12044
- });
12045
- const rate = match?.entry.rates?.[0];
12046
- if (!rate) return null;
12047
- const unitLabel = {
12048
- per_image: "per image",
12049
- per_second: "per second of video",
12050
- per_character: "per character",
12051
- per_audio_minute: "per audio minute"
12052
- };
12053
- const unit = unitLabel[rate.unit] ?? rate.unit;
12054
- const amount = rate.amount;
12055
- const shown = amount < 1e-3 ? amount.toExponential(2) : amount.toFixed(4);
12056
- return { label: `$${shown} ${unit}`, amount, unit };
12057
- }
12058
- function explainChoice(c, cost, modality, isBest) {
12059
- const priced = cost ? ` ${cost.label}.` : "";
12060
- if (c.quality !== void 0) {
12061
- return isBest ? `${c.modelId} (${c.provider}) \u2014 ranked highest for ${modality}: ${c.qualityBasis}.${priced}` : `${c.modelId} (${c.provider}) \u2014 ranked alternative for ${modality}: ${c.qualityBasis}.${priced}`;
12062
- }
12063
- const noRanking = ". No published quality ranking is applied for this modality, so this is a cost choice, not a quality one.";
12064
- return isBest ? `${c.modelId} (${c.provider}) \u2014 cheapest usable ${modality} model` + (cost ? ` at ${cost.label}` : "") + noRanking : `${c.modelId} (${c.provider}) \u2014 alternative usable ${modality} model` + (cost ? ` at ${cost.label}` : "") + noRanking;
12065
- }
12066
- var MultimodalRegistry = class {
12067
- /** Provider types the user has actually configured a key for. */
12068
- available;
12069
- constructor(availableProviders) {
12070
- this.available = new Set(availableProviders);
12071
- }
12072
- /** Every capability whose provider is configured AND which Cascade can call. */
12073
- usable(modality) {
12074
- return CAPABILITIES.filter(
12075
- (c) => !c.unsupported && this.available.has(c.provider) && (!modality || c.modality === modality)
12076
- );
12077
- }
12078
- /** Modalities this account can actually generate right now. */
12079
- availableModalities() {
12080
- return [...new Set(this.usable().map((c) => c.modality))];
12081
- }
12082
- /**
12083
- * Every usable capability for a modality, best first.
12084
- *
12085
- * Ranked models beat unranked ones, then higher quality, then lower unit
12086
- * price. An explicit `preferModel` is moved to the head when it is usable —
12087
- * the user naming a model is a stronger signal than any prior.
12088
- *
12089
- * `select()` is just the head of this list. The TAIL is the point: a systemic
12090
- * provider failure (dead key, 404, exhausted quota) is scoped to one
12091
- * provider+model, so "this model cannot draw" is not the same fact as "this
12092
- * account cannot draw". A caller holding the ordered alternatives can try the
12093
- * next provider instead of aborting the whole run — see generate-media.ts.
12094
- */
12095
- rank(modality, opts = {}) {
12096
- const scored = this.usable(modality).map((c) => ({ c, cost: capabilityCost(c) })).sort((a, b) => {
12097
- const qa = a.c.quality ?? -1;
12098
- const qb = b.c.quality ?? -1;
12099
- if (qa !== qb) return qb - qa;
12100
- const pa = a.cost?.amount ?? Number.POSITIVE_INFINITY;
12101
- const pb = b.cost?.amount ?? Number.POSITIVE_INFINITY;
12102
- return pa - pb;
12103
- });
12104
- const results = scored.map(({ c, cost }, i) => ({
12105
- capability: c,
12106
- cost,
12107
- reason: explainChoice(c, cost, modality, i === 0)
12108
- }));
12109
- if (opts.preferModel) {
12110
- const i = results.findIndex((r) => r.capability.modelId === opts.preferModel);
12111
- if (i > -1) {
12112
- const [wanted] = results.splice(i, 1);
12113
- results.unshift({ ...wanted, reason: `Requested explicitly: ${wanted.capability.modelId}.` });
12114
- }
12115
- }
12116
- return results;
12117
- }
12118
- /**
12119
- * Pick a model for a modality — the best usable one, or null if there is none.
12120
- */
12121
- select(modality, opts = {}) {
12122
- return this.rank(modality, opts)[0] ?? null;
12123
- }
12124
- /**
12125
- * A plain-language account of what this account can and cannot generate —
12126
- * including the things it cannot, and why. The planner sees this, so being
12127
- * candid here is what stops it inventing a `generate_music` call.
12128
- */
12129
- describe() {
12130
- const lines = [];
12131
- const usable = this.usable();
12132
- if (usable.length) {
12133
- lines.push("Generation models available on your configured providers:");
12134
- for (const modality of ["image", "speech", "transcription", "video"]) {
12135
- const forModality = usable.filter((c) => c.modality === modality);
12136
- if (!forModality.length) continue;
12137
- const shown = forModality.map((c) => {
12138
- const cost = capabilityCost(c);
12139
- return `${c.modelId}${cost ? ` (${cost.label})` : ""}`;
12140
- });
12141
- lines.push(` ${modality}: ${shown.join(", ")}`);
12142
- }
12143
- } else {
12144
- lines.push("No generation models are available \u2014 none of your configured providers offers one.");
12145
- }
12146
- const blocked = CAPABILITIES.filter((c) => c.unsupported && this.available.has(c.provider));
12147
- for (const c of blocked) {
12148
- lines.push(` ${c.modality}: ${c.modelId} exists on your account but is not callable. ${c.unsupported}`);
12149
- }
12150
- lines.push(
12151
- " music: no supported provider exposes a music-generation API, so Cascade cannot generate music."
12152
- );
12153
- return lines.join("\n");
12154
- }
12155
- };
12156
-
12157
12238
  // src/tools/base.ts
12158
12239
  var BaseTool = class {
12159
12240
  workspaceRoot = process.cwd();
@@ -12174,10 +12255,17 @@ var BaseTool = class {
12174
12255
 
12175
12256
  // src/core/multimodal/generate.ts
12176
12257
  var DEFAULT_TIMEOUT_MS = 12e4;
12258
+ var GenerationGaveUpError = class extends Error {
12259
+ constructor(message) {
12260
+ super(message);
12261
+ this.name = "GenerationGaveUpError";
12262
+ }
12263
+ };
12177
12264
  async function callProvider(fn, modelId) {
12178
12265
  try {
12179
12266
  return await fn();
12180
12267
  } catch (err) {
12268
+ if (err instanceof GenerationGaveUpError) throw err;
12181
12269
  const classified = classifyProviderError(err);
12182
12270
  throw new Error(describeProviderError(classified, modelId));
12183
12271
  }
@@ -12375,8 +12463,8 @@ async function generateVideo(cap, cfg, req, signal, onProgress) {
12375
12463
  onProgress?.("Still rendering\u2026");
12376
12464
  }
12377
12465
  if (!operation.done) {
12378
- throw new Error(
12379
- `Video was still rendering after ${Math.round(VIDEO_TIMEOUT_MS / 6e4)} minutes. It may still complete on the provider side, but Cascade stopped waiting.`
12466
+ throw new GenerationGaveUpError(
12467
+ `${cap.modelId} timed out after ${Math.round(VIDEO_TIMEOUT_MS / 6e4)} minutes \u2014 no video was produced. Cascade stopped waiting; the render may still finish on the provider side, but nothing was saved. Try again with a shorter clip or a simpler prompt.`
12380
12468
  );
12381
12469
  }
12382
12470
  if (operation.error?.message) throw new Error(operation.error.message);