cascade-ai 0.50.0 → 0.51.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/dist/cli.cjs +788 -130
- package/dist/cli.cjs.map +1 -1
- package/dist/cli.js +788 -130
- package/dist/cli.js.map +1 -1
- package/dist/desktop-core.cjs +995 -344
- package/dist/index.cjs +774 -121
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +61 -0
- package/dist/index.d.ts +61 -0
- package/dist/index.js +774 -121
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -1845,7 +1845,7 @@ function reconcilePrice(model, live) {
|
|
|
1845
1845
|
}
|
|
1846
1846
|
|
|
1847
1847
|
// src/constants.ts
|
|
1848
|
-
var CASCADE_VERSION = "0.
|
|
1848
|
+
var CASCADE_VERSION = "0.51.0";
|
|
1849
1849
|
var CASCADE_CONFIG_DIR = ".cascade";
|
|
1850
1850
|
var CASCADE_MD_FILE = "CASCADE.md";
|
|
1851
1851
|
var CASCADE_IGNORE_FILE = ".cascadeignore";
|
|
@@ -2358,46 +2358,37 @@ var BaseProvider = class {
|
|
|
2358
2358
|
};
|
|
2359
2359
|
|
|
2360
2360
|
// src/providers/model-filter.ts
|
|
2361
|
-
var
|
|
2362
|
-
"embed",
|
|
2361
|
+
var MODALITY_PATTERNS = [
|
|
2362
|
+
["embedding", ["embed"]],
|
|
2363
2363
|
// text-embedding-3, nomic-embed, mxbai-embed, snowflake-arctic-embed
|
|
2364
|
-
"(?:^|[-_/])
|
|
2365
|
-
"text-to-speech",
|
|
2366
|
-
"
|
|
2367
|
-
|
|
2368
|
-
|
|
2369
|
-
|
|
2370
|
-
|
|
2371
|
-
|
|
2372
|
-
|
|
2373
|
-
|
|
2374
|
-
|
|
2375
|
-
|
|
2376
|
-
|
|
2377
|
-
"
|
|
2378
|
-
"
|
|
2379
|
-
"
|
|
2380
|
-
|
|
2381
|
-
|
|
2382
|
-
|
|
2383
|
-
|
|
2384
|
-
|
|
2385
|
-
|
|
2386
|
-
|
|
2387
|
-
|
|
2388
|
-
|
|
2389
|
-
"veo",
|
|
2390
|
-
"sora",
|
|
2391
|
-
"(?:^|[-_/])video(?:[-_/]|$)",
|
|
2392
|
-
// video
|
|
2393
|
-
"(?:^|[-_/])aqa(?:[-_/]|$)",
|
|
2394
|
-
// attributed QA
|
|
2395
|
-
"(?:^|[-_/])live(?:[-_/]|$)",
|
|
2396
|
-
// live-audio variants
|
|
2397
|
-
"(?:^|[-_/])(?:davinci|babbage)(?:[-_/]|$)"
|
|
2398
|
-
// legacy completion-only base models
|
|
2364
|
+
["transcription", ["whisper", "transcrib", "(?:^|[-_/])stt(?:[-_/]|$)"]],
|
|
2365
|
+
["speech", ["(?:^|[-_/])tts(?:[-_/]|$)", "text-to-speech", "speech"]],
|
|
2366
|
+
["video", ["veo", "sora", "(?:^|[-_/])video(?:[-_/]|$)"]],
|
|
2367
|
+
["image", [
|
|
2368
|
+
"dall[-]?e",
|
|
2369
|
+
"imagen",
|
|
2370
|
+
"image-generation",
|
|
2371
|
+
"gpt-image",
|
|
2372
|
+
"(?:^|[-_/])image(?:[-_/]|$)",
|
|
2373
|
+
"stable-diffusion",
|
|
2374
|
+
"sdxl",
|
|
2375
|
+
"flux"
|
|
2376
|
+
]],
|
|
2377
|
+
["moderation", ["moderation", "(?:^|[-_/])guard(?:[-_/]|$)"]],
|
|
2378
|
+
["rerank", ["rerank"]],
|
|
2379
|
+
["realtime", [
|
|
2380
|
+
"(?:^|[-_/])audio(?:[-_/]|$)",
|
|
2381
|
+
"native-audio",
|
|
2382
|
+
"realtime",
|
|
2383
|
+
"(?:^|[-_/])live(?:[-_/]|$)",
|
|
2384
|
+
// live-audio variants
|
|
2385
|
+
"(?:^|[-_/])aqa(?:[-_/]|$)"
|
|
2386
|
+
// attributed QA
|
|
2387
|
+
]],
|
|
2388
|
+
["legacy-completion", ["(?:^|[-_/])(?:davinci|babbage)(?:[-_/]|$)"]]
|
|
2399
2389
|
];
|
|
2400
|
-
|
|
2390
|
+
MODALITY_PATTERNS.map(([m, pats]) => [m, new RegExp(pats.join("|"), "i")]);
|
|
2391
|
+
var NON_CHAT = new RegExp(MODALITY_PATTERNS.flatMap(([, p]) => p).join("|"), "i");
|
|
2401
2392
|
function isChatModel(id, methods) {
|
|
2402
2393
|
if (methods && methods.length > 0) {
|
|
2403
2394
|
const canGenerate = methods.some((m) => /generatecontent|generatemessage|chat|completion/i.test(m));
|
|
@@ -2925,6 +2916,115 @@ var AzureOpenAIProvider = class extends OpenAIProvider {
|
|
|
2925
2916
|
}
|
|
2926
2917
|
}
|
|
2927
2918
|
};
|
|
2919
|
+
|
|
2920
|
+
// src/providers/gemini-schema.ts
|
|
2921
|
+
var ALLOWED_KEYS = /* @__PURE__ */ new Set([
|
|
2922
|
+
"type",
|
|
2923
|
+
"format",
|
|
2924
|
+
"title",
|
|
2925
|
+
"description",
|
|
2926
|
+
"nullable",
|
|
2927
|
+
"enum",
|
|
2928
|
+
"items",
|
|
2929
|
+
"properties",
|
|
2930
|
+
"required",
|
|
2931
|
+
"propertyOrdering",
|
|
2932
|
+
"minItems",
|
|
2933
|
+
"maxItems",
|
|
2934
|
+
"minProperties",
|
|
2935
|
+
"maxProperties",
|
|
2936
|
+
"minimum",
|
|
2937
|
+
"maximum",
|
|
2938
|
+
"minLength",
|
|
2939
|
+
"maxLength",
|
|
2940
|
+
"pattern",
|
|
2941
|
+
"example",
|
|
2942
|
+
"default",
|
|
2943
|
+
"anyOf"
|
|
2944
|
+
]);
|
|
2945
|
+
var ALLOWED_TYPES = /* @__PURE__ */ new Set(["string", "number", "integer", "boolean", "array", "object"]);
|
|
2946
|
+
function isPlainObject(v) {
|
|
2947
|
+
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
2948
|
+
}
|
|
2949
|
+
function normalizeType(value) {
|
|
2950
|
+
if (typeof value === "string") {
|
|
2951
|
+
return ALLOWED_TYPES.has(value) ? { type: value } : {};
|
|
2952
|
+
}
|
|
2953
|
+
if (Array.isArray(value)) {
|
|
2954
|
+
const types = value.filter((t) => typeof t === "string");
|
|
2955
|
+
const nullable = types.includes("null");
|
|
2956
|
+
const concrete = types.find((t) => t !== "null" && ALLOWED_TYPES.has(t));
|
|
2957
|
+
return {
|
|
2958
|
+
...concrete ? { type: concrete } : {},
|
|
2959
|
+
...nullable ? { nullable: true } : {}
|
|
2960
|
+
};
|
|
2961
|
+
}
|
|
2962
|
+
return {};
|
|
2963
|
+
}
|
|
2964
|
+
function normalizeEnum(value) {
|
|
2965
|
+
if (!Array.isArray(value) || value.length === 0) return void 0;
|
|
2966
|
+
return value.map((v) => typeof v === "string" ? v : JSON.stringify(v));
|
|
2967
|
+
}
|
|
2968
|
+
function sanitizeGeminiSchema(schema) {
|
|
2969
|
+
if (!isPlainObject(schema)) return void 0;
|
|
2970
|
+
const out = {};
|
|
2971
|
+
for (const [key, value] of Object.entries(schema)) {
|
|
2972
|
+
if (!ALLOWED_KEYS.has(key)) continue;
|
|
2973
|
+
switch (key) {
|
|
2974
|
+
case "type": {
|
|
2975
|
+
Object.assign(out, normalizeType(value));
|
|
2976
|
+
break;
|
|
2977
|
+
}
|
|
2978
|
+
case "enum": {
|
|
2979
|
+
const e = normalizeEnum(value);
|
|
2980
|
+
if (e) out["enum"] = e;
|
|
2981
|
+
break;
|
|
2982
|
+
}
|
|
2983
|
+
case "properties": {
|
|
2984
|
+
if (!isPlainObject(value)) break;
|
|
2985
|
+
const props = {};
|
|
2986
|
+
for (const [propName, propSchema] of Object.entries(value)) {
|
|
2987
|
+
const cleaned = sanitizeGeminiSchema(propSchema);
|
|
2988
|
+
props[propName] = cleaned && Object.keys(cleaned).length ? cleaned : { type: "string" };
|
|
2989
|
+
}
|
|
2990
|
+
out["properties"] = props;
|
|
2991
|
+
break;
|
|
2992
|
+
}
|
|
2993
|
+
case "items": {
|
|
2994
|
+
const cleaned = sanitizeGeminiSchema(value);
|
|
2995
|
+
if (cleaned) out["items"] = cleaned;
|
|
2996
|
+
break;
|
|
2997
|
+
}
|
|
2998
|
+
case "anyOf": {
|
|
2999
|
+
if (!Array.isArray(value)) break;
|
|
3000
|
+
const variants = value.map((v) => sanitizeGeminiSchema(v)).filter((v) => !!v && Object.keys(v).length > 0);
|
|
3001
|
+
if (variants.length) out["anyOf"] = variants;
|
|
3002
|
+
break;
|
|
3003
|
+
}
|
|
3004
|
+
case "required": {
|
|
3005
|
+
if (Array.isArray(value)) {
|
|
3006
|
+
out["required"] = value.filter((r) => typeof r === "string");
|
|
3007
|
+
}
|
|
3008
|
+
break;
|
|
3009
|
+
}
|
|
3010
|
+
default:
|
|
3011
|
+
out[key] = value;
|
|
3012
|
+
}
|
|
3013
|
+
}
|
|
3014
|
+
if (!out["type"] && out["properties"]) out["type"] = "object";
|
|
3015
|
+
if (!out["type"] && out["items"]) out["type"] = "array";
|
|
3016
|
+
return out;
|
|
3017
|
+
}
|
|
3018
|
+
function toGeminiParameters(inputSchema) {
|
|
3019
|
+
const cleaned = sanitizeGeminiSchema(inputSchema);
|
|
3020
|
+
if (!cleaned) return void 0;
|
|
3021
|
+
const props = cleaned["properties"];
|
|
3022
|
+
if (isPlainObject(props) && Object.keys(props).length === 0) return void 0;
|
|
3023
|
+
if (Object.keys(cleaned).length === 0) return void 0;
|
|
3024
|
+
return cleaned;
|
|
3025
|
+
}
|
|
3026
|
+
|
|
3027
|
+
// src/providers/gemini.ts
|
|
2928
3028
|
var GeminiProvider = class extends BaseProvider {
|
|
2929
3029
|
client;
|
|
2930
3030
|
constructor(config, model) {
|
|
@@ -3145,7 +3245,12 @@ var GeminiProvider = class extends BaseProvider {
|
|
|
3145
3245
|
return {
|
|
3146
3246
|
name: tool.name,
|
|
3147
3247
|
description: tool.description,
|
|
3148
|
-
parameters
|
|
3248
|
+
// Convert, never cast. Gemini's parameters field is an OpenAPI subset
|
|
3249
|
+
// that 400s on unknown keys, and MCP servers ship schemas carrying their
|
|
3250
|
+
// own extensions (GitHub's adds `x-mcp-header` to every header-bound
|
|
3251
|
+
// property). Casting sent those through verbatim and every request failed
|
|
3252
|
+
// before the model saw it. See providers/gemini-schema.ts.
|
|
3253
|
+
parameters: toGeminiParameters(tool.inputSchema)
|
|
3149
3254
|
};
|
|
3150
3255
|
}
|
|
3151
3256
|
};
|
|
@@ -3173,7 +3278,7 @@ async function nodeHttpFetch(input, init = {}, redirectCount = 0) {
|
|
|
3173
3278
|
headers["accept-encoding"] = "gzip, deflate, br";
|
|
3174
3279
|
}
|
|
3175
3280
|
const body = init.body == null ? void 0 : typeof init.body === "string" ? init.body : Buffer.from(init.body);
|
|
3176
|
-
return new Promise((
|
|
3281
|
+
return new Promise((resolve2, reject) => {
|
|
3177
3282
|
const req = lib.request(
|
|
3178
3283
|
{
|
|
3179
3284
|
hostname: u.hostname,
|
|
@@ -3190,7 +3295,7 @@ async function nodeHttpFetch(input, init = {}, redirectCount = 0) {
|
|
|
3190
3295
|
const nextUrl = new URL(location, u).href;
|
|
3191
3296
|
const downgrade = status === 303 || (status === 301 || status === 302) && method !== "GET" && method !== "HEAD";
|
|
3192
3297
|
const nextInit = downgrade ? { ...init, method: "GET", body: void 0 } : init;
|
|
3193
|
-
|
|
3298
|
+
resolve2(nodeHttpFetch(nextUrl, nextInit, redirectCount + 1));
|
|
3194
3299
|
return;
|
|
3195
3300
|
}
|
|
3196
3301
|
const encoding = (res.headers["content-encoding"] ?? "").toLowerCase();
|
|
@@ -3205,7 +3310,7 @@ async function nodeHttpFetch(input, init = {}, redirectCount = 0) {
|
|
|
3205
3310
|
if (Array.isArray(v)) respHeaders.set(k, v.join(", "));
|
|
3206
3311
|
else if (typeof v === "string") respHeaders.set(k, v);
|
|
3207
3312
|
}
|
|
3208
|
-
|
|
3313
|
+
resolve2(new Response(stream, {
|
|
3209
3314
|
status,
|
|
3210
3315
|
statusText: res.statusMessage ?? "",
|
|
3211
3316
|
headers: respHeaders
|
|
@@ -3850,7 +3955,7 @@ var TpmLimiter = class {
|
|
|
3850
3955
|
}
|
|
3851
3956
|
const deficit = want - bucket.available;
|
|
3852
3957
|
const waitMs = Math.max(50, Math.ceil(deficit / bucket.tokensPerMinute * 6e4));
|
|
3853
|
-
await new Promise((
|
|
3958
|
+
await new Promise((resolve2) => setTimeout(resolve2, waitMs));
|
|
3854
3959
|
}
|
|
3855
3960
|
}
|
|
3856
3961
|
/**
|
|
@@ -3913,14 +4018,14 @@ var LocalRequestQueue = class {
|
|
|
3913
4018
|
this.active++;
|
|
3914
4019
|
return this.makeRelease();
|
|
3915
4020
|
}
|
|
3916
|
-
return new Promise((
|
|
4021
|
+
return new Promise((resolve2, reject) => {
|
|
3917
4022
|
let settled = false;
|
|
3918
4023
|
let timer;
|
|
3919
4024
|
const resolver = (release) => {
|
|
3920
4025
|
if (settled) return;
|
|
3921
4026
|
settled = true;
|
|
3922
4027
|
if (timer !== void 0) clearTimeout(timer);
|
|
3923
|
-
|
|
4028
|
+
resolve2(release);
|
|
3924
4029
|
};
|
|
3925
4030
|
if (timeoutMs !== void 0 && timeoutMs > 0) {
|
|
3926
4031
|
timer = setTimeout(() => {
|
|
@@ -4551,6 +4656,7 @@ var CascadeRouter = class _CascadeRouter extends EventEmitter {
|
|
|
4551
4656
|
tpmLimiter;
|
|
4552
4657
|
localQueue;
|
|
4553
4658
|
taskAnalyzer;
|
|
4659
|
+
pendingFeedbackSource;
|
|
4554
4660
|
worldStateDB;
|
|
4555
4661
|
privacyPaths;
|
|
4556
4662
|
guidanceQueue;
|
|
@@ -5005,8 +5111,18 @@ var CascadeRouter = class _CascadeRouter extends EventEmitter {
|
|
|
5005
5111
|
return windows.length ? Math.min(...windows) : void 0;
|
|
5006
5112
|
}
|
|
5007
5113
|
/** Wire the Cascade Auto task analyzer used for per-subtask model routing. */
|
|
5114
|
+
/**
|
|
5115
|
+
* Feed per-model thumbs counts into Auto routing. Forwarded to the analyzer
|
|
5116
|
+
* because that is where the public benchmark score is combined; the prior
|
|
5117
|
+
* adjusts that number rather than sitting anywhere else in the pipeline.
|
|
5118
|
+
*/
|
|
5119
|
+
setFeedbackSource(source) {
|
|
5120
|
+
this.taskAnalyzer?.setFeedbackSource(source);
|
|
5121
|
+
this.pendingFeedbackSource = source;
|
|
5122
|
+
}
|
|
5008
5123
|
setTaskAnalyzer(analyzer) {
|
|
5009
5124
|
this.taskAnalyzer = analyzer;
|
|
5125
|
+
if (this.pendingFeedbackSource) analyzer.setFeedbackSource(this.pendingFeedbackSource);
|
|
5010
5126
|
}
|
|
5011
5127
|
setWorldStateDB(db) {
|
|
5012
5128
|
this.worldStateDB = db;
|
|
@@ -6100,8 +6216,11 @@ Now execute your subtask using this context where relevant.`
|
|
|
6100
6216
|
const result = await this.runAgentLoop(systemPrompt, this.tools);
|
|
6101
6217
|
output = result.output;
|
|
6102
6218
|
toolCalls = result.toolCalls;
|
|
6103
|
-
this.
|
|
6104
|
-
|
|
6219
|
+
const mustProduceArtifact = this.requiresArtifact();
|
|
6220
|
+
if (mustProduceArtifact) {
|
|
6221
|
+
this.sendStatusUpdate({ progressPct: 65, currentAction: "Verifying required artifacts", status: "IN_PROGRESS" });
|
|
6222
|
+
}
|
|
6223
|
+
const artifactCheck = mustProduceArtifact ? await this.verifyArtifacts(assignment) : { ok: true, issues: [] };
|
|
6105
6224
|
if (!artifactCheck.ok) {
|
|
6106
6225
|
correctionAttempts = 1;
|
|
6107
6226
|
issues.push(...artifactCheck.issues);
|
|
@@ -6381,11 +6500,11 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
|
|
|
6381
6500
|
if (!wasApproved) return `Tool ${tc.name} was denied by user.`;
|
|
6382
6501
|
} else {
|
|
6383
6502
|
const LEGACY_APPROVAL_TIMEOUT_MS = 6e5;
|
|
6384
|
-
const legacyDecision = await new Promise((
|
|
6503
|
+
const legacyDecision = await new Promise((resolve2) => {
|
|
6385
6504
|
const eventName = `tool:approval-response:${this.id}-${tc.id}`;
|
|
6386
6505
|
const timer = setTimeout(() => {
|
|
6387
6506
|
this.removeAllListeners(eventName);
|
|
6388
|
-
|
|
6507
|
+
resolve2({ approved: false });
|
|
6389
6508
|
}, LEGACY_APPROVAL_TIMEOUT_MS);
|
|
6390
6509
|
timer.unref?.();
|
|
6391
6510
|
this.emit("tool:approval-request", {
|
|
@@ -6398,7 +6517,7 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
|
|
|
6398
6517
|
});
|
|
6399
6518
|
this.once(eventName, (d) => {
|
|
6400
6519
|
clearTimeout(timer);
|
|
6401
|
-
|
|
6520
|
+
resolve2(d);
|
|
6402
6521
|
});
|
|
6403
6522
|
});
|
|
6404
6523
|
if (legacyDecision.always) this.sessionApprovals.set(tc.name, legacyDecision.approved);
|
|
@@ -6418,6 +6537,9 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
|
|
|
6418
6537
|
tierId: this.id,
|
|
6419
6538
|
sessionId: this.taskId,
|
|
6420
6539
|
requireApproval: false,
|
|
6540
|
+
// Media generation can run for a minute; without this a cancelled run
|
|
6541
|
+
// still pays for an image nobody will see.
|
|
6542
|
+
...this.signal ? { signal: this.signal } : {},
|
|
6421
6543
|
saveSnapshot: async (path26, content) => {
|
|
6422
6544
|
this.store?.addFileSnapshot(this.taskId, path26, content);
|
|
6423
6545
|
},
|
|
@@ -6465,7 +6587,8 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
|
|
|
6465
6587
|
const result = await this.toolRegistry.execute(altTool, tc.input, {
|
|
6466
6588
|
tierId: this.id,
|
|
6467
6589
|
sessionId: this.taskId,
|
|
6468
|
-
requireApproval: false
|
|
6590
|
+
requireApproval: false,
|
|
6591
|
+
...this.signal ? { signal: this.signal } : {}
|
|
6469
6592
|
});
|
|
6470
6593
|
const str = typeof result === "string" ? result : JSON.stringify(result);
|
|
6471
6594
|
if (!str.startsWith("Tool error:") && !str.startsWith("Error:")) {
|
|
@@ -6487,7 +6610,8 @@ HIERARCHY CONTEXT: ${this.hierarchyContext}` : "") + textToolSuffix,
|
|
|
6487
6610
|
const result = await this.toolRegistry.execute(newToolName, tc.input, {
|
|
6488
6611
|
tierId: this.id,
|
|
6489
6612
|
sessionId: this.taskId,
|
|
6490
|
-
requireApproval: false
|
|
6613
|
+
requireApproval: false,
|
|
6614
|
+
...this.signal ? { signal: this.signal } : {}
|
|
6491
6615
|
});
|
|
6492
6616
|
const str = typeof result === "string" ? result : JSON.stringify(result);
|
|
6493
6617
|
if (!str.startsWith("Tool error:")) return `[Synthesized ${newToolName}]: ${str}`;
|
|
@@ -6905,7 +7029,7 @@ var PeerBus = class extends EventEmitter {
|
|
|
6905
7029
|
this.outputs.set(subtaskId, entry);
|
|
6906
7030
|
this.emit("output:ready", entry);
|
|
6907
7031
|
const waiting = this.waiters.get(subtaskId) ?? [];
|
|
6908
|
-
for (const
|
|
7032
|
+
for (const resolve2 of waiting) resolve2(entry);
|
|
6909
7033
|
this.waiters.delete(subtaskId);
|
|
6910
7034
|
}
|
|
6911
7035
|
/**
|
|
@@ -6936,10 +7060,10 @@ var PeerBus = class extends EventEmitter {
|
|
|
6936
7060
|
waitFor(subtaskId, timeoutMs = 12e4) {
|
|
6937
7061
|
const existing = this.outputs.get(subtaskId);
|
|
6938
7062
|
if (existing && !this.retryPending.has(subtaskId)) return Promise.resolve(existing);
|
|
6939
|
-
return new Promise((
|
|
7063
|
+
return new Promise((resolve2, reject) => {
|
|
6940
7064
|
const resolver = (output) => {
|
|
6941
7065
|
clearTimeout(timer);
|
|
6942
|
-
|
|
7066
|
+
resolve2(output);
|
|
6943
7067
|
};
|
|
6944
7068
|
const timer = setTimeout(() => {
|
|
6945
7069
|
const waiting = this.waiters.get(subtaskId);
|
|
@@ -6993,10 +7117,10 @@ var PeerBus = class extends EventEmitter {
|
|
|
6993
7117
|
*/
|
|
6994
7118
|
collect(timeoutMs) {
|
|
6995
7119
|
const collected = [...this.broadcastLog];
|
|
6996
|
-
return new Promise((
|
|
7120
|
+
return new Promise((resolve2) => {
|
|
6997
7121
|
const timer = setTimeout(() => {
|
|
6998
7122
|
off();
|
|
6999
|
-
|
|
7123
|
+
resolve2(collected);
|
|
7000
7124
|
}, timeoutMs);
|
|
7001
7125
|
const handler = (msg) => {
|
|
7002
7126
|
collected.push({ fromId: msg.fromId, payload: msg.payload, timestamp: msg.timestamp });
|
|
@@ -7010,7 +7134,7 @@ var PeerBus = class extends EventEmitter {
|
|
|
7010
7134
|
const broadcasters = new Set(collected.map((m) => m.fromId));
|
|
7011
7135
|
if (broadcasters.size >= this.members.size) {
|
|
7012
7136
|
off();
|
|
7013
|
-
|
|
7137
|
+
resolve2(collected);
|
|
7014
7138
|
}
|
|
7015
7139
|
};
|
|
7016
7140
|
this.on("broadcast", checkComplete);
|
|
@@ -7028,7 +7152,7 @@ var PeerBus = class extends EventEmitter {
|
|
|
7028
7152
|
return;
|
|
7029
7153
|
}
|
|
7030
7154
|
this.emitCoordination(tierId, `\u23F3 waiting for ${filePath} (held by ${existing.holderId})`);
|
|
7031
|
-
return new Promise((
|
|
7155
|
+
return new Promise((resolve2, reject) => {
|
|
7032
7156
|
const timer = setTimeout(() => {
|
|
7033
7157
|
reject(new Error(`File lock timeout for ${filePath} (held by ${existing.holderId})`));
|
|
7034
7158
|
}, timeoutMs);
|
|
@@ -7036,7 +7160,7 @@ var PeerBus = class extends EventEmitter {
|
|
|
7036
7160
|
clearTimeout(timer);
|
|
7037
7161
|
this.fileLocks.set(filePath, { holderId: tierId, lockedAt: (/* @__PURE__ */ new Date()).toISOString(), waiters: [] });
|
|
7038
7162
|
this.emitCoordination(tierId, `\u{1F512} locked ${filePath}`);
|
|
7039
|
-
|
|
7163
|
+
resolve2();
|
|
7040
7164
|
});
|
|
7041
7165
|
});
|
|
7042
7166
|
}
|
|
@@ -7061,11 +7185,11 @@ var PeerBus = class extends EventEmitter {
|
|
|
7061
7185
|
*/
|
|
7062
7186
|
waitForFileRelease(filePath, timeoutMs = 3e4) {
|
|
7063
7187
|
if (!this.fileLocks.has(filePath)) return Promise.resolve();
|
|
7064
|
-
return new Promise((
|
|
7188
|
+
return new Promise((resolve2, reject) => {
|
|
7065
7189
|
const timer = setTimeout(() => reject(new Error(`Timeout waiting for file release: ${filePath}`)), timeoutMs);
|
|
7066
7190
|
this.once(`file:released:${filePath}`, () => {
|
|
7067
7191
|
clearTimeout(timer);
|
|
7068
|
-
|
|
7192
|
+
resolve2();
|
|
7069
7193
|
});
|
|
7070
7194
|
});
|
|
7071
7195
|
}
|
|
@@ -7131,13 +7255,13 @@ var PeerBus = class extends EventEmitter {
|
|
|
7131
7255
|
this.emit(`barrier:${barrierName}`);
|
|
7132
7256
|
return;
|
|
7133
7257
|
}
|
|
7134
|
-
return new Promise((
|
|
7258
|
+
return new Promise((resolve2, reject) => {
|
|
7135
7259
|
const timer = setTimeout(() => {
|
|
7136
7260
|
reject(new Error(`Barrier timeout: ${barrierName} (${bar.arrived.size}/${bar.total} arrived)`));
|
|
7137
7261
|
}, 12e4);
|
|
7138
7262
|
this.once(`barrier:${barrierName}`, () => {
|
|
7139
7263
|
clearTimeout(timer);
|
|
7140
|
-
|
|
7264
|
+
resolve2();
|
|
7141
7265
|
});
|
|
7142
7266
|
});
|
|
7143
7267
|
}
|
|
@@ -8682,6 +8806,174 @@ Reply with exactly one word: YES, NO, or UNSURE.
|
|
|
8682
8806
|
}
|
|
8683
8807
|
};
|
|
8684
8808
|
|
|
8809
|
+
// src/core/multimodal/registry.ts
|
|
8810
|
+
var CAPABILITIES = [
|
|
8811
|
+
// ── Image ──
|
|
8812
|
+
{
|
|
8813
|
+
modality: "image",
|
|
8814
|
+
provider: "openai",
|
|
8815
|
+
modelId: "dall-e-3",
|
|
8816
|
+
api: "openai-images"
|
|
8817
|
+
},
|
|
8818
|
+
{
|
|
8819
|
+
modality: "image",
|
|
8820
|
+
provider: "gemini",
|
|
8821
|
+
modelId: "gemini-3-pro-image",
|
|
8822
|
+
api: "gemini-predict"
|
|
8823
|
+
},
|
|
8824
|
+
// ── Speech (text → audio) ──
|
|
8825
|
+
{
|
|
8826
|
+
modality: "speech",
|
|
8827
|
+
provider: "openai",
|
|
8828
|
+
modelId: "tts-1",
|
|
8829
|
+
api: "openai-speech"
|
|
8830
|
+
},
|
|
8831
|
+
{
|
|
8832
|
+
// The only quality claim in this table that needs no leaderboard: OpenAI
|
|
8833
|
+
// ships these as the same voice at two fidelities and charges double for
|
|
8834
|
+
// this one. That is the vendor's own ordering, not an inference.
|
|
8835
|
+
modality: "speech",
|
|
8836
|
+
provider: "openai",
|
|
8837
|
+
modelId: "tts-1-hd",
|
|
8838
|
+
api: "openai-speech",
|
|
8839
|
+
quality: 70,
|
|
8840
|
+
qualityBasis: "OpenAI's own hd variant of tts-1, priced 2x"
|
|
8841
|
+
},
|
|
8842
|
+
// ── Transcription (audio → text) ──
|
|
8843
|
+
{
|
|
8844
|
+
modality: "transcription",
|
|
8845
|
+
provider: "openai",
|
|
8846
|
+
modelId: "whisper-1",
|
|
8847
|
+
api: "openai-transcriptions"
|
|
8848
|
+
},
|
|
8849
|
+
// ── Video ──
|
|
8850
|
+
{
|
|
8851
|
+
// Listed so `describe()` can tell the truth about what exists, and so the
|
|
8852
|
+
// planner is told video is out of reach rather than left to invent a tool.
|
|
8853
|
+
// Veo is a long-running operation: submit, poll, then fetch bytes from a
|
|
8854
|
+
// signed URL. That is a different execution shape from every other entry
|
|
8855
|
+
// here and is not wired up — claiming otherwise would produce a tool that
|
|
8856
|
+
// fails at call time instead of an honest "not yet".
|
|
8857
|
+
modality: "video",
|
|
8858
|
+
provider: "gemini",
|
|
8859
|
+
modelId: "veo-3.1-generate-001",
|
|
8860
|
+
api: "gemini-predict",
|
|
8861
|
+
unsupported: "Veo runs as a long-running operation (submit \u2192 poll \u2192 fetch). Not wired up yet."
|
|
8862
|
+
}
|
|
8863
|
+
];
|
|
8864
|
+
function capabilityCost(cap) {
|
|
8865
|
+
const match = findPricing(cap.modelId, cap.provider, {
|
|
8866
|
+
fallbackProviders: cap.provider === "gemini" ? ["vertex"] : []
|
|
8867
|
+
});
|
|
8868
|
+
const rate = match?.entry.rates?.[0];
|
|
8869
|
+
if (!rate) return null;
|
|
8870
|
+
const unitLabel = {
|
|
8871
|
+
per_image: "per image",
|
|
8872
|
+
per_second: "per second of video",
|
|
8873
|
+
per_character: "per character",
|
|
8874
|
+
per_audio_minute: "per audio minute"
|
|
8875
|
+
};
|
|
8876
|
+
const unit = unitLabel[rate.unit] ?? rate.unit;
|
|
8877
|
+
const amount = rate.amount;
|
|
8878
|
+
const shown = amount < 1e-3 ? amount.toExponential(2) : amount.toFixed(4);
|
|
8879
|
+
return { label: `$${shown} ${unit}`, amount, unit };
|
|
8880
|
+
}
|
|
8881
|
+
var MultimodalRegistry = class {
|
|
8882
|
+
/** Provider types the user has actually configured a key for. */
|
|
8883
|
+
available;
|
|
8884
|
+
constructor(availableProviders) {
|
|
8885
|
+
this.available = new Set(availableProviders);
|
|
8886
|
+
}
|
|
8887
|
+
/** Every capability whose provider is configured AND which Cascade can call. */
|
|
8888
|
+
usable(modality) {
|
|
8889
|
+
return CAPABILITIES.filter(
|
|
8890
|
+
(c) => !c.unsupported && this.available.has(c.provider) && (!modality || c.modality === modality)
|
|
8891
|
+
);
|
|
8892
|
+
}
|
|
8893
|
+
/** Modalities this account can actually generate right now. */
|
|
8894
|
+
availableModalities() {
|
|
8895
|
+
return [...new Set(this.usable().map((c) => c.modality))];
|
|
8896
|
+
}
|
|
8897
|
+
/**
|
|
8898
|
+
* Pick a model for a modality.
|
|
8899
|
+
*
|
|
8900
|
+
* Ranked models beat unranked ones, then higher quality, then lower unit
|
|
8901
|
+
* price. An explicit `preferModel` wins outright when it is usable — the user
|
|
8902
|
+
* naming a model is a stronger signal than any prior.
|
|
8903
|
+
*/
|
|
8904
|
+
select(modality, opts = {}) {
|
|
8905
|
+
const pool = this.usable(modality);
|
|
8906
|
+
if (!pool.length) return null;
|
|
8907
|
+
if (opts.preferModel) {
|
|
8908
|
+
const wanted = pool.find((c) => c.modelId === opts.preferModel);
|
|
8909
|
+
if (wanted) {
|
|
8910
|
+
return { capability: wanted, cost: capabilityCost(wanted), reason: `Requested explicitly: ${wanted.modelId}.` };
|
|
8911
|
+
}
|
|
8912
|
+
}
|
|
8913
|
+
const scored = pool.map((c) => ({ c, cost: capabilityCost(c) })).sort((a, b) => {
|
|
8914
|
+
const qa = a.c.quality ?? -1;
|
|
8915
|
+
const qb = b.c.quality ?? -1;
|
|
8916
|
+
if (qa !== qb) return qb - qa;
|
|
8917
|
+
const pa = a.cost?.amount ?? Number.POSITIVE_INFINITY;
|
|
8918
|
+
const pb = b.cost?.amount ?? Number.POSITIVE_INFINITY;
|
|
8919
|
+
return pa - pb;
|
|
8920
|
+
});
|
|
8921
|
+
const best = scored[0];
|
|
8922
|
+
const ranked = best.c.quality !== void 0;
|
|
8923
|
+
const reason = ranked ? `${best.c.modelId} (${best.c.provider}) \u2014 ranked highest for ${modality}: ${best.c.qualityBasis}.` + (best.cost ? ` ${best.cost.label}.` : "") : `${best.c.modelId} (${best.c.provider}) \u2014 cheapest usable ${modality} model` + (best.cost ? ` at ${best.cost.label}` : "") + ". No published quality ranking is applied for this modality, so this is a cost choice, not a quality one.";
|
|
8924
|
+
return { capability: best.c, cost: best.cost, reason };
|
|
8925
|
+
}
|
|
8926
|
+
/**
|
|
8927
|
+
* A plain-language account of what this account can and cannot generate —
|
|
8928
|
+
* including the things it cannot, and why. The planner sees this, so being
|
|
8929
|
+
* candid here is what stops it inventing a `generate_music` call.
|
|
8930
|
+
*/
|
|
8931
|
+
describe() {
|
|
8932
|
+
const lines = [];
|
|
8933
|
+
const usable = this.usable();
|
|
8934
|
+
if (usable.length) {
|
|
8935
|
+
lines.push("Generation models available on your configured providers:");
|
|
8936
|
+
for (const modality of ["image", "speech", "transcription", "video"]) {
|
|
8937
|
+
const forModality = usable.filter((c) => c.modality === modality);
|
|
8938
|
+
if (!forModality.length) continue;
|
|
8939
|
+
const shown = forModality.map((c) => {
|
|
8940
|
+
const cost = capabilityCost(c);
|
|
8941
|
+
return `${c.modelId}${cost ? ` (${cost.label})` : ""}`;
|
|
8942
|
+
});
|
|
8943
|
+
lines.push(` ${modality}: ${shown.join(", ")}`);
|
|
8944
|
+
}
|
|
8945
|
+
} else {
|
|
8946
|
+
lines.push("No generation models are available \u2014 none of your configured providers offers one.");
|
|
8947
|
+
}
|
|
8948
|
+
const blocked = CAPABILITIES.filter((c) => c.unsupported && this.available.has(c.provider));
|
|
8949
|
+
for (const c of blocked) {
|
|
8950
|
+
lines.push(` ${c.modality}: ${c.modelId} exists on your account but is not callable. ${c.unsupported}`);
|
|
8951
|
+
}
|
|
8952
|
+
lines.push(
|
|
8953
|
+
" music: no supported provider exposes a music-generation API, so Cascade cannot generate music."
|
|
8954
|
+
);
|
|
8955
|
+
return lines.join("\n");
|
|
8956
|
+
}
|
|
8957
|
+
};
|
|
8958
|
+
|
|
8959
|
+
// src/tools/base.ts
|
|
8960
|
+
var BaseTool = class {
|
|
8961
|
+
workspaceRoot = process.cwd();
|
|
8962
|
+
setWorkspaceRoot(root) {
|
|
8963
|
+
this.workspaceRoot = root;
|
|
8964
|
+
}
|
|
8965
|
+
isDangerous() {
|
|
8966
|
+
return false;
|
|
8967
|
+
}
|
|
8968
|
+
getDefinition() {
|
|
8969
|
+
return {
|
|
8970
|
+
name: this.name,
|
|
8971
|
+
description: this.description,
|
|
8972
|
+
inputSchema: this.inputSchema
|
|
8973
|
+
};
|
|
8974
|
+
}
|
|
8975
|
+
};
|
|
8976
|
+
|
|
8685
8977
|
// src/core/router/provider-errors.ts
|
|
8686
8978
|
var SYSTEMIC = /* @__PURE__ */ new Set([
|
|
8687
8979
|
"rate_limit",
|
|
@@ -8746,7 +9038,7 @@ function classifyProviderError(err) {
|
|
|
8746
9038
|
return { kind, systemic: isSystemicKind(kind), status, raw };
|
|
8747
9039
|
}
|
|
8748
9040
|
function describeProviderError(c, modelId) {
|
|
8749
|
-
const on = ` on ${modelId}` ;
|
|
9041
|
+
const on = modelId ? ` on ${modelId}` : "";
|
|
8750
9042
|
const detail = c.raw ? ` Provider said: ${c.raw}` : "";
|
|
8751
9043
|
switch (c.kind) {
|
|
8752
9044
|
case "rate_limit":
|
|
@@ -8768,6 +9060,295 @@ function describeProviderError(c, modelId) {
|
|
|
8768
9060
|
}
|
|
8769
9061
|
}
|
|
8770
9062
|
|
|
9063
|
+
// src/core/multimodal/generate.ts
|
|
9064
|
+
var DEFAULT_TIMEOUT_MS = 12e4;
|
|
9065
|
+
async function callProvider(fn, modelId) {
|
|
9066
|
+
try {
|
|
9067
|
+
return await fn();
|
|
9068
|
+
} catch (err) {
|
|
9069
|
+
const classified = classifyProviderError(err);
|
|
9070
|
+
throw new Error(describeProviderError(classified, modelId));
|
|
9071
|
+
}
|
|
9072
|
+
}
|
|
9073
|
+
async function postJson(url, body, headers, signal) {
|
|
9074
|
+
const ac = new AbortController();
|
|
9075
|
+
const timer = setTimeout(() => ac.abort(), DEFAULT_TIMEOUT_MS);
|
|
9076
|
+
const onAbort = () => ac.abort();
|
|
9077
|
+
signal?.addEventListener("abort", onAbort);
|
|
9078
|
+
try {
|
|
9079
|
+
const res = await fetch(url, {
|
|
9080
|
+
method: "POST",
|
|
9081
|
+
headers: { "Content-Type": "application/json", ...headers },
|
|
9082
|
+
body: JSON.stringify(body),
|
|
9083
|
+
signal: ac.signal
|
|
9084
|
+
});
|
|
9085
|
+
if (!res.ok) {
|
|
9086
|
+
const text = await res.text().catch(() => "");
|
|
9087
|
+
throw Object.assign(new Error(text || res.statusText), { status: res.status });
|
|
9088
|
+
}
|
|
9089
|
+
return res;
|
|
9090
|
+
} finally {
|
|
9091
|
+
clearTimeout(timer);
|
|
9092
|
+
signal?.removeEventListener("abort", onAbort);
|
|
9093
|
+
}
|
|
9094
|
+
}
|
|
9095
|
+
function baseUrlFor(cfg, fallback) {
|
|
9096
|
+
return (cfg.baseUrl ?? fallback).replace(/\/+$/, "");
|
|
9097
|
+
}
|
|
9098
|
+
function stamp(ext) {
|
|
9099
|
+
return `cascade-${Date.now()}.${ext}`;
|
|
9100
|
+
}
|
|
9101
|
+
async function generateImage(cap, cfg, req, signal) {
|
|
9102
|
+
return callProvider(async () => {
|
|
9103
|
+
if (cap.api === "openai-images") {
|
|
9104
|
+
const url = `${baseUrlFor(cfg, "https://api.openai.com/v1")}/images/generations`;
|
|
9105
|
+
const res = await postJson(url, {
|
|
9106
|
+
model: cap.modelId,
|
|
9107
|
+
prompt: req.prompt,
|
|
9108
|
+
size: req.size ?? "1024x1024",
|
|
9109
|
+
n: 1,
|
|
9110
|
+
// b64 rather than a URL: see the file header — provider URLs expire.
|
|
9111
|
+
response_format: "b64_json"
|
|
9112
|
+
}, { Authorization: `Bearer ${cfg.apiKey ?? ""}` }, signal);
|
|
9113
|
+
const body = await res.json();
|
|
9114
|
+
const first = body.data?.[0];
|
|
9115
|
+
if (!first?.b64_json) throw new Error("Image response contained no image data.");
|
|
9116
|
+
return {
|
|
9117
|
+
data: Buffer.from(first.b64_json, "base64"),
|
|
9118
|
+
mimeType: "image/png",
|
|
9119
|
+
filename: stamp("png"),
|
|
9120
|
+
modelId: cap.modelId,
|
|
9121
|
+
provider: cap.provider,
|
|
9122
|
+
...first.revised_prompt ? { revisedPrompt: first.revised_prompt } : {}
|
|
9123
|
+
};
|
|
9124
|
+
}
|
|
9125
|
+
if (cap.api === "gemini-predict") {
|
|
9126
|
+
const base = baseUrlFor(cfg, "https://generativelanguage.googleapis.com/v1beta");
|
|
9127
|
+
const url = `${base}/models/${encodeURIComponent(cap.modelId)}:predict`;
|
|
9128
|
+
const res = await postJson(url, {
|
|
9129
|
+
instances: [{ prompt: req.prompt }],
|
|
9130
|
+
parameters: { sampleCount: 1 }
|
|
9131
|
+
}, { "x-goog-api-key": cfg.apiKey ?? "" }, signal);
|
|
9132
|
+
const body = await res.json();
|
|
9133
|
+
const first = body.predictions?.[0];
|
|
9134
|
+
if (!first?.bytesBase64Encoded) throw new Error("Image response contained no image data.");
|
|
9135
|
+
const mimeType = first.mimeType ?? "image/png";
|
|
9136
|
+
return {
|
|
9137
|
+
data: Buffer.from(first.bytesBase64Encoded, "base64"),
|
|
9138
|
+
mimeType,
|
|
9139
|
+
filename: stamp(mimeType.includes("jpeg") ? "jpg" : "png"),
|
|
9140
|
+
modelId: cap.modelId,
|
|
9141
|
+
provider: cap.provider
|
|
9142
|
+
};
|
|
9143
|
+
}
|
|
9144
|
+
throw new Error(`${cap.modelId} is not an image generator.`);
|
|
9145
|
+
}, cap.modelId);
|
|
9146
|
+
}
|
|
9147
|
+
async function generateSpeech(cap, cfg, req, signal) {
|
|
9148
|
+
return callProvider(async () => {
|
|
9149
|
+
if (cap.api !== "openai-speech") throw new Error(`${cap.modelId} is not a speech model.`);
|
|
9150
|
+
const format = req.format ?? "mp3";
|
|
9151
|
+
const url = `${baseUrlFor(cfg, "https://api.openai.com/v1")}/audio/speech`;
|
|
9152
|
+
const res = await postJson(url, {
|
|
9153
|
+
model: cap.modelId,
|
|
9154
|
+
input: req.text,
|
|
9155
|
+
voice: req.voice ?? "alloy",
|
|
9156
|
+
response_format: format
|
|
9157
|
+
}, { Authorization: `Bearer ${cfg.apiKey ?? ""}` }, signal);
|
|
9158
|
+
const mime = {
|
|
9159
|
+
mp3: "audio/mpeg",
|
|
9160
|
+
opus: "audio/opus",
|
|
9161
|
+
aac: "audio/aac",
|
|
9162
|
+
flac: "audio/flac",
|
|
9163
|
+
wav: "audio/wav"
|
|
9164
|
+
};
|
|
9165
|
+
return {
|
|
9166
|
+
data: Buffer.from(await res.arrayBuffer()),
|
|
9167
|
+
mimeType: mime[format] ?? "application/octet-stream",
|
|
9168
|
+
filename: stamp(format),
|
|
9169
|
+
modelId: cap.modelId,
|
|
9170
|
+
provider: cap.provider
|
|
9171
|
+
};
|
|
9172
|
+
}, cap.modelId);
|
|
9173
|
+
}
|
|
9174
|
+
async function transcribeAudio(cap, cfg, req, signal) {
|
|
9175
|
+
return callProvider(async () => {
|
|
9176
|
+
if (cap.api !== "openai-transcriptions") throw new Error(`${cap.modelId} is not a transcription model.`);
|
|
9177
|
+
const url = `${baseUrlFor(cfg, "https://api.openai.com/v1")}/audio/transcriptions`;
|
|
9178
|
+
const form = new FormData();
|
|
9179
|
+
form.append("model", cap.modelId);
|
|
9180
|
+
if (req.language) form.append("language", req.language);
|
|
9181
|
+
form.append("file", new Blob([new Uint8Array(req.audio)]), req.filename);
|
|
9182
|
+
const ac = new AbortController();
|
|
9183
|
+
const timer = setTimeout(() => ac.abort(), DEFAULT_TIMEOUT_MS);
|
|
9184
|
+
const onAbort = () => ac.abort();
|
|
9185
|
+
signal?.addEventListener("abort", onAbort);
|
|
9186
|
+
try {
|
|
9187
|
+
const res = await fetch(url, {
|
|
9188
|
+
method: "POST",
|
|
9189
|
+
headers: { Authorization: `Bearer ${cfg.apiKey ?? ""}` },
|
|
9190
|
+
body: form,
|
|
9191
|
+
signal: ac.signal
|
|
9192
|
+
});
|
|
9193
|
+
if (!res.ok) {
|
|
9194
|
+
const text = await res.text().catch(() => "");
|
|
9195
|
+
throw Object.assign(new Error(text || res.statusText), { status: res.status });
|
|
9196
|
+
}
|
|
9197
|
+
const body = await res.json();
|
|
9198
|
+
return { text: body.text ?? "", modelId: cap.modelId };
|
|
9199
|
+
} finally {
|
|
9200
|
+
clearTimeout(timer);
|
|
9201
|
+
signal?.removeEventListener("abort", onAbort);
|
|
9202
|
+
}
|
|
9203
|
+
}, cap.modelId);
|
|
9204
|
+
}
|
|
9205
|
+
|
|
9206
|
+
// src/tools/generate-media.ts
|
|
9207
|
+
function resolve(deps, modality, preferModel) {
|
|
9208
|
+
const selected = deps.registry.select(modality, preferModel ? { preferModel } : {});
|
|
9209
|
+
if (!selected) {
|
|
9210
|
+
return { ok: false, error: `No ${modality} model is available on your configured providers.` };
|
|
9211
|
+
}
|
|
9212
|
+
const cfg = deps.lookupProvider(selected.capability.provider);
|
|
9213
|
+
if (!cfg) {
|
|
9214
|
+
return {
|
|
9215
|
+
ok: false,
|
|
9216
|
+
error: `${selected.capability.modelId} needs the ${selected.capability.provider} provider, which is not configured.`
|
|
9217
|
+
};
|
|
9218
|
+
}
|
|
9219
|
+
return { ok: true, selected, cfg };
|
|
9220
|
+
}
|
|
9221
|
+
var GenerateImageTool = class extends BaseTool {
|
|
9222
|
+
constructor(deps) {
|
|
9223
|
+
super();
|
|
9224
|
+
this.deps = deps;
|
|
9225
|
+
}
|
|
9226
|
+
deps;
|
|
9227
|
+
name = "generate_image";
|
|
9228
|
+
description = "Generate an image from a text description using the best available image model. Returns where the image was saved. Use when the user asks for a picture, illustration, diagram render, logo or any visual asset.";
|
|
9229
|
+
inputSchema = {
|
|
9230
|
+
type: "object",
|
|
9231
|
+
properties: {
|
|
9232
|
+
prompt: { type: "string", description: "What the image should show. Be specific about subject, style and composition." },
|
|
9233
|
+
size: { type: "string", description: 'Pixel size, e.g. "1024x1024" (default), "1792x1024", "1024x1792".' },
|
|
9234
|
+
model: { type: "string", description: "Optional: force a specific image model instead of the automatic choice." }
|
|
9235
|
+
},
|
|
9236
|
+
required: ["prompt"]
|
|
9237
|
+
};
|
|
9238
|
+
async execute(input, options) {
|
|
9239
|
+
const prompt = String(input["prompt"] ?? "").trim();
|
|
9240
|
+
if (!prompt) return 'Provide a "prompt" describing the image.';
|
|
9241
|
+
const r = resolve(this.deps, "image", input["model"] ? String(input["model"]) : void 0);
|
|
9242
|
+
if (!r.ok) return r.error;
|
|
9243
|
+
const size = input["size"] ? String(input["size"]) : void 0;
|
|
9244
|
+
const asset = await generateImage(
|
|
9245
|
+
r.selected.capability,
|
|
9246
|
+
r.cfg,
|
|
9247
|
+
{ prompt, ...size ? { size } : {} },
|
|
9248
|
+
options.signal
|
|
9249
|
+
);
|
|
9250
|
+
const location = await this.deps.sink(asset);
|
|
9251
|
+
return [
|
|
9252
|
+
`Image generated and saved to ${location}.`,
|
|
9253
|
+
`Model: ${asset.modelId} \u2014 ${r.selected.reason}`,
|
|
9254
|
+
// DALL·E rewrites the prompt before drawing; the model needs to know what
|
|
9255
|
+
// was actually rendered, not what it asked for, or its description of the
|
|
9256
|
+
// result will not match the image.
|
|
9257
|
+
asset.revisedPrompt ? `The provider rewrote the prompt to: ${asset.revisedPrompt}` : ""
|
|
9258
|
+
].filter(Boolean).join("\n");
|
|
9259
|
+
}
|
|
9260
|
+
};
|
|
9261
|
+
var GenerateSpeechTool = class extends BaseTool {
|
|
9262
|
+
constructor(deps) {
|
|
9263
|
+
super();
|
|
9264
|
+
this.deps = deps;
|
|
9265
|
+
}
|
|
9266
|
+
deps;
|
|
9267
|
+
name = "generate_speech";
|
|
9268
|
+
description = "Turn text into spoken audio using the best available text-to-speech model. Returns where the audio was saved. Use when the user asks for narration, a voiceover or an audio version of some text.";
|
|
9269
|
+
inputSchema = {
|
|
9270
|
+
type: "object",
|
|
9271
|
+
properties: {
|
|
9272
|
+
text: { type: "string", description: "The text to speak." },
|
|
9273
|
+
voice: { type: "string", description: "Voice id: alloy, echo, fable, onyx, nova, shimmer. Default alloy." },
|
|
9274
|
+
format: { type: "string", description: "Audio format: mp3 (default), opus, aac, flac, wav." },
|
|
9275
|
+
model: { type: "string", description: "Optional: force a specific speech model." }
|
|
9276
|
+
},
|
|
9277
|
+
required: ["text"]
|
|
9278
|
+
};
|
|
9279
|
+
async execute(input, options) {
|
|
9280
|
+
const text = String(input["text"] ?? "").trim();
|
|
9281
|
+
if (!text) return 'Provide "text" to speak.';
|
|
9282
|
+
const r = resolve(this.deps, "speech", input["model"] ? String(input["model"]) : void 0);
|
|
9283
|
+
if (!r.ok) return r.error;
|
|
9284
|
+
const fmt = String(input["format"] ?? "mp3");
|
|
9285
|
+
const allowed = ["mp3", "opus", "aac", "flac", "wav"];
|
|
9286
|
+
const format = allowed.includes(fmt) ? fmt : "mp3";
|
|
9287
|
+
const asset = await generateSpeech(
|
|
9288
|
+
r.selected.capability,
|
|
9289
|
+
r.cfg,
|
|
9290
|
+
{ text, voice: input["voice"] ? String(input["voice"]) : void 0, format },
|
|
9291
|
+
options.signal
|
|
9292
|
+
);
|
|
9293
|
+
const location = await this.deps.sink(asset);
|
|
9294
|
+
return `Speech generated and saved to ${location}.
|
|
9295
|
+
Model: ${asset.modelId} \u2014 ${r.selected.reason}`;
|
|
9296
|
+
}
|
|
9297
|
+
};
|
|
9298
|
+
var TranscribeAudioTool = class extends BaseTool {
|
|
9299
|
+
constructor(deps, readFile) {
|
|
9300
|
+
super();
|
|
9301
|
+
this.deps = deps;
|
|
9302
|
+
this.readFile = readFile;
|
|
9303
|
+
}
|
|
9304
|
+
deps;
|
|
9305
|
+
readFile;
|
|
9306
|
+
name = "transcribe_audio";
|
|
9307
|
+
description = "Transcribe a local audio file to text using the best available speech-to-text model. Use when the user supplies audio and wants its contents in writing.";
|
|
9308
|
+
inputSchema = {
|
|
9309
|
+
type: "object",
|
|
9310
|
+
properties: {
|
|
9311
|
+
path: { type: "string", description: "Path to the audio file to transcribe." },
|
|
9312
|
+
language: { type: "string", description: 'Optional ISO-639-1 language hint, e.g. "en", improves accuracy.' },
|
|
9313
|
+
model: { type: "string", description: "Optional: force a specific transcription model." }
|
|
9314
|
+
},
|
|
9315
|
+
required: ["path"]
|
|
9316
|
+
};
|
|
9317
|
+
async execute(input, options) {
|
|
9318
|
+
const filePath = String(input["path"] ?? "").trim();
|
|
9319
|
+
if (!filePath) return 'Provide a "path" to the audio file.';
|
|
9320
|
+
const r = resolve(this.deps, "transcription", input["model"] ? String(input["model"]) : void 0);
|
|
9321
|
+
if (!r.ok) return r.error;
|
|
9322
|
+
let audio;
|
|
9323
|
+
try {
|
|
9324
|
+
audio = await this.readFile(filePath);
|
|
9325
|
+
} catch {
|
|
9326
|
+
return `Could not read the audio file at ${filePath}.`;
|
|
9327
|
+
}
|
|
9328
|
+
const { text, modelId } = await transcribeAudio(
|
|
9329
|
+
r.selected.capability,
|
|
9330
|
+
r.cfg,
|
|
9331
|
+
{
|
|
9332
|
+
audio,
|
|
9333
|
+
filename: filePath.split(/[\\/]/).pop() || "audio",
|
|
9334
|
+
...input["language"] ? { language: String(input["language"]) } : {}
|
|
9335
|
+
},
|
|
9336
|
+
options.signal
|
|
9337
|
+
);
|
|
9338
|
+
return text ? `Transcript (${modelId}):
|
|
9339
|
+
|
|
9340
|
+
${text}` : `${modelId} returned an empty transcript \u2014 the file may be silent or in an unsupported format.`;
|
|
9341
|
+
}
|
|
9342
|
+
};
|
|
9343
|
+
function buildMediaTools(deps, readFile) {
|
|
9344
|
+
const tools = [];
|
|
9345
|
+
const modalities = new Set(deps.registry.availableModalities());
|
|
9346
|
+
if (modalities.has("image")) tools.push(new GenerateImageTool(deps));
|
|
9347
|
+
if (modalities.has("speech")) tools.push(new GenerateSpeechTool(deps));
|
|
9348
|
+
if (modalities.has("transcription") && readFile) tools.push(new TranscribeAudioTool(deps, readFile));
|
|
9349
|
+
return tools;
|
|
9350
|
+
}
|
|
9351
|
+
|
|
8771
9352
|
// src/core/run-breaker.ts
|
|
8772
9353
|
var DEFAULT_FAILURE_THRESHOLD = 3;
|
|
8773
9354
|
var RunBreaker = class {
|
|
@@ -8833,26 +9414,6 @@ var RunBreaker = class {
|
|
|
8833
9414
|
return out;
|
|
8834
9415
|
}
|
|
8835
9416
|
};
|
|
8836
|
-
|
|
8837
|
-
// src/tools/base.ts
|
|
8838
|
-
var BaseTool = class {
|
|
8839
|
-
workspaceRoot = process.cwd();
|
|
8840
|
-
setWorkspaceRoot(root) {
|
|
8841
|
-
this.workspaceRoot = root;
|
|
8842
|
-
}
|
|
8843
|
-
isDangerous() {
|
|
8844
|
-
return false;
|
|
8845
|
-
}
|
|
8846
|
-
getDefinition() {
|
|
8847
|
-
return {
|
|
8848
|
-
name: this.name,
|
|
8849
|
-
description: this.description,
|
|
8850
|
-
inputSchema: this.inputSchema
|
|
8851
|
-
};
|
|
8852
|
-
}
|
|
8853
|
-
};
|
|
8854
|
-
|
|
8855
|
-
// src/tools/shell.ts
|
|
8856
9417
|
var execAsync = promisify(exec);
|
|
8857
9418
|
var ShellTool = class extends BaseTool {
|
|
8858
9419
|
name = "shell";
|
|
@@ -9548,7 +10109,7 @@ var PDFCreateTool = class extends BaseTool {
|
|
|
9548
10109
|
if (!fs23.existsSync(dir)) {
|
|
9549
10110
|
fs23.mkdirSync(dir, { recursive: true });
|
|
9550
10111
|
}
|
|
9551
|
-
return new Promise((
|
|
10112
|
+
return new Promise((resolve2, reject) => {
|
|
9552
10113
|
try {
|
|
9553
10114
|
const doc = new PDFDocument({ margin: 50 });
|
|
9554
10115
|
const stream = fs23.createWriteStream(filePath);
|
|
@@ -9566,7 +10127,7 @@ var PDFCreateTool = class extends BaseTool {
|
|
|
9566
10127
|
});
|
|
9567
10128
|
doc.end();
|
|
9568
10129
|
stream.on("finish", () => {
|
|
9569
|
-
|
|
10130
|
+
resolve2(`Successfully created PDF at ${filePath} (${content.length} characters)`);
|
|
9570
10131
|
});
|
|
9571
10132
|
stream.on("error", (err) => {
|
|
9572
10133
|
reject(new Error(`Failed to write PDF: ${err.message}`));
|
|
@@ -9638,7 +10199,7 @@ var CodeInterpreterTool = class extends BaseTool {
|
|
|
9638
10199
|
const filePath = path24.join(tmpDir, fileName);
|
|
9639
10200
|
fs23.writeFileSync(filePath, code, "utf-8");
|
|
9640
10201
|
const execArgs = [filePath, ...args];
|
|
9641
|
-
return new Promise((
|
|
10202
|
+
return new Promise((resolve2) => {
|
|
9642
10203
|
const startMs = Date.now();
|
|
9643
10204
|
execFile(cmdPrefix, execArgs, { cwd: this.workspaceRoot, timeout: 3e4 }, (error, stdout, stderr) => {
|
|
9644
10205
|
const duration = Date.now() - startMs;
|
|
@@ -9652,17 +10213,17 @@ var CodeInterpreterTool = class extends BaseTool {
|
|
|
9652
10213
|
if (error) {
|
|
9653
10214
|
const timedOut = error.killed && duration >= 3e4;
|
|
9654
10215
|
if (timedOut) {
|
|
9655
|
-
|
|
10216
|
+
resolve2(`Execution timed out after 30s. Consider breaking the task into smaller pieces.
|
|
9656
10217
|
Partial stdout: ${stdout}
|
|
9657
10218
|
Stderr: ${stderr}`);
|
|
9658
10219
|
} else {
|
|
9659
|
-
|
|
10220
|
+
resolve2(`Execution failed (${duration}ms):
|
|
9660
10221
|
Error: ${error.message}
|
|
9661
10222
|
Stderr: ${stderr}
|
|
9662
10223
|
Stdout: ${stdout}`);
|
|
9663
10224
|
}
|
|
9664
10225
|
} else {
|
|
9665
|
-
|
|
10226
|
+
resolve2(`Execution successful (${duration}ms):
|
|
9666
10227
|
Stdout: ${stdout}
|
|
9667
10228
|
Stderr: ${stderr}`);
|
|
9668
10229
|
}
|
|
@@ -10316,7 +10877,7 @@ var ToolRegistry = class extends EventEmitter {
|
|
|
10316
10877
|
*/
|
|
10317
10878
|
waitForTool(toolName, timeoutMs = 6e4) {
|
|
10318
10879
|
if (this.tools.has(toolName)) return Promise.resolve();
|
|
10319
|
-
return new Promise((
|
|
10880
|
+
return new Promise((resolve2, reject) => {
|
|
10320
10881
|
const timer = setTimeout(() => {
|
|
10321
10882
|
this.off("tool:added", handler);
|
|
10322
10883
|
reject(new Error(`Timeout waiting for tool: ${toolName}`));
|
|
@@ -10325,7 +10886,7 @@ var ToolRegistry = class extends EventEmitter {
|
|
|
10325
10886
|
if (name === toolName) {
|
|
10326
10887
|
clearTimeout(timer);
|
|
10327
10888
|
this.off("tool:added", handler);
|
|
10328
|
-
|
|
10889
|
+
resolve2();
|
|
10329
10890
|
}
|
|
10330
10891
|
};
|
|
10331
10892
|
this.on("tool:added", handler);
|
|
@@ -11000,20 +11561,20 @@ var PermissionEscalator = class extends EventEmitter {
|
|
|
11000
11561
|
resolver(decision);
|
|
11001
11562
|
}
|
|
11002
11563
|
waitForUserDecision(req) {
|
|
11003
|
-
return new Promise((
|
|
11564
|
+
return new Promise((resolve2) => {
|
|
11004
11565
|
let timer;
|
|
11005
11566
|
const wrappedResolver = (decision) => {
|
|
11006
11567
|
if (timer) clearTimeout(timer);
|
|
11007
11568
|
if (decision.always) {
|
|
11008
11569
|
this.taskWideCache.set(req.toolName, decision.approved);
|
|
11009
11570
|
}
|
|
11010
|
-
|
|
11571
|
+
resolve2(decision);
|
|
11011
11572
|
};
|
|
11012
11573
|
this.pendingUserDecisions.set(req.id, wrappedResolver);
|
|
11013
11574
|
if (this.approvalTimeoutMs > 0 && Number.isFinite(this.approvalTimeoutMs)) {
|
|
11014
11575
|
timer = setTimeout(() => {
|
|
11015
11576
|
if (this.pendingUserDecisions.delete(req.id)) {
|
|
11016
|
-
|
|
11577
|
+
resolve2({
|
|
11017
11578
|
requestId: req.id,
|
|
11018
11579
|
approved: false,
|
|
11019
11580
|
decidedBy: "USER",
|
|
@@ -11180,6 +11741,14 @@ var BudgetConfigSchema = z.object({
|
|
|
11180
11741
|
maxTokensPerRun: z.number().int().positive().default(2e5),
|
|
11181
11742
|
/** Optional hard per-task cost ceiling (USD). Unset = only the token cap applies. */
|
|
11182
11743
|
maxCostPerRunUsd: z.number().positive().optional(),
|
|
11744
|
+
/**
|
|
11745
|
+
* Consecutive systemic failures against ONE model before the run stops
|
|
11746
|
+
* launching work that would fail the same way (dead key, wrong model id,
|
|
11747
|
+
* exhausted quota). Lower reacts sooner and wastes less; higher absorbs a
|
|
11748
|
+
* longer transient before giving up. Only failures that will certainly repeat
|
|
11749
|
+
* are counted — see core/run-breaker.ts.
|
|
11750
|
+
*/
|
|
11751
|
+
failureThreshold: z.number().int().min(1).max(20).default(3),
|
|
11183
11752
|
warnAtPct: z.number().default(80)
|
|
11184
11753
|
});
|
|
11185
11754
|
var WorkspaceConfigSchema = z.object({
|
|
@@ -11467,6 +12036,23 @@ var noopTelemetry = {
|
|
|
11467
12036
|
}
|
|
11468
12037
|
};
|
|
11469
12038
|
|
|
12039
|
+
// src/core/router/feedback-prior.ts
|
|
12040
|
+
var MAX_FEEDBACK_ADJUSTMENT = 0.05;
|
|
12041
|
+
var PRIOR_STRENGTH = 10;
|
|
12042
|
+
function feedbackAdjustment(counts) {
|
|
12043
|
+
const good = Math.max(0, Math.floor(counts.good));
|
|
12044
|
+
const bad = Math.max(0, Math.floor(counts.bad));
|
|
12045
|
+
const n = good + bad;
|
|
12046
|
+
if (n === 0) return 0;
|
|
12047
|
+
const half = PRIOR_STRENGTH / 2;
|
|
12048
|
+
const shrunk = (good + half) / (n + PRIOR_STRENGTH);
|
|
12049
|
+
return (shrunk - 0.5) * 2 * MAX_FEEDBACK_ADJUSTMENT;
|
|
12050
|
+
}
|
|
12051
|
+
function applyFeedback(score01, counts) {
|
|
12052
|
+
const adjusted = score01 + feedbackAdjustment(counts);
|
|
12053
|
+
return Math.max(0, Math.min(1, adjusted));
|
|
12054
|
+
}
|
|
12055
|
+
|
|
11470
12056
|
// src/core/router/task-analyzer.ts
|
|
11471
12057
|
var CODE_SIGNALS = [
|
|
11472
12058
|
/\b(?:function|class|interface|async|await|import|export|const|let|var|def|return|if|else|for|while|try|catch)\b/,
|
|
@@ -11541,6 +12127,8 @@ var TASK_TYPE_TAGS = {
|
|
|
11541
12127
|
};
|
|
11542
12128
|
var TaskAnalyzer = class {
|
|
11543
12129
|
tracker;
|
|
12130
|
+
/** Per-model thumbs counts, when the host collects them. */
|
|
12131
|
+
feedback;
|
|
11544
12132
|
bias;
|
|
11545
12133
|
lastProfile = null;
|
|
11546
12134
|
lastSelectedModels = /* @__PURE__ */ new Map();
|
|
@@ -11548,6 +12136,14 @@ var TaskAnalyzer = class {
|
|
|
11548
12136
|
this.tracker = tracker;
|
|
11549
12137
|
this.bias = bias;
|
|
11550
12138
|
}
|
|
12139
|
+
/**
|
|
12140
|
+
* Supply per-model rating counts. Optional by design: a host that collects no
|
|
12141
|
+
* feedback (the CLI, a fresh install) scores exactly as it did before, since
|
|
12142
|
+
* feedbackAdjustment returns 0 for an empty record.
|
|
12143
|
+
*/
|
|
12144
|
+
setFeedbackSource(source) {
|
|
12145
|
+
this.feedback = source;
|
|
12146
|
+
}
|
|
11551
12147
|
setTracker(tracker) {
|
|
11552
12148
|
this.tracker = tracker;
|
|
11553
12149
|
}
|
|
@@ -11631,7 +12227,10 @@ var TaskAnalyzer = class {
|
|
|
11631
12227
|
const perf = this.tracker?.performanceScore(model.id, profile.type) ?? 0.5;
|
|
11632
12228
|
const costEff = this.costEfficiency(model, profile.complexity);
|
|
11633
12229
|
const match = this.taskMatchScore(model, profile);
|
|
11634
|
-
const
|
|
12230
|
+
const rated = this.feedback?.(model.id);
|
|
12231
|
+
const publicScore = benchmarkScore01(model, profile.type);
|
|
12232
|
+
const adjusted = rated ? applyFeedback(publicScore, rated) : publicScore;
|
|
12233
|
+
const benchmark = 0.3 + 0.7 * adjusted;
|
|
11635
12234
|
switch (this.bias) {
|
|
11636
12235
|
case "quality":
|
|
11637
12236
|
return perf * match * benchmark ** 2 * (0.85 + 0.15 * costEff);
|
|
@@ -12033,10 +12632,10 @@ var DynamicTool = class extends BaseTool {
|
|
|
12033
12632
|
`;
|
|
12034
12633
|
const script = await isolate.compileScript(bootstrap);
|
|
12035
12634
|
const runPromise = script.run(context, { timeout: timeoutMs, promise: true }).then((v) => String(v ?? ""));
|
|
12036
|
-
const timeoutPromise = new Promise((
|
|
12635
|
+
const timeoutPromise = new Promise((resolve2) => {
|
|
12037
12636
|
const t = setTimeout(() => {
|
|
12038
12637
|
dispose();
|
|
12039
|
-
|
|
12638
|
+
resolve2(`Dynamic tool "${this.name}" timed out after ${timeoutMs}ms and was terminated.`);
|
|
12040
12639
|
}, timeoutMs + 500);
|
|
12041
12640
|
t.unref?.();
|
|
12042
12641
|
});
|
|
@@ -12054,7 +12653,7 @@ var DynamicTool = class extends BaseTool {
|
|
|
12054
12653
|
/** Spawn the worker, service its callTool/fetch bridge, enforce the kill timeout. */
|
|
12055
12654
|
runInWorker(input, callTool) {
|
|
12056
12655
|
const timeoutMs = Math.max(200, Number(process.env["CASCADE_DYNAMIC_TOOL_TIMEOUT_MS"]) || DYNAMIC_TOOL_TIMEOUT_MS);
|
|
12057
|
-
return new Promise((
|
|
12656
|
+
return new Promise((resolve2) => {
|
|
12058
12657
|
let settled = false;
|
|
12059
12658
|
const worker = new Worker(HARNESS_SRC, {
|
|
12060
12659
|
eval: true,
|
|
@@ -12066,7 +12665,7 @@ var DynamicTool = class extends BaseTool {
|
|
|
12066
12665
|
settled = true;
|
|
12067
12666
|
clearTimeout(timer);
|
|
12068
12667
|
void worker.terminate();
|
|
12069
|
-
|
|
12668
|
+
resolve2(value);
|
|
12070
12669
|
};
|
|
12071
12670
|
const timer = setTimeout(
|
|
12072
12671
|
() => finish(`Dynamic tool "${this.name}" timed out after ${timeoutMs}ms and was terminated.`),
|
|
@@ -13612,6 +14211,7 @@ ${prompt}`;
|
|
|
13612
14211
|
var Cascade = class _Cascade extends EventEmitter {
|
|
13613
14212
|
router;
|
|
13614
14213
|
toolRegistry;
|
|
14214
|
+
multimodal;
|
|
13615
14215
|
mcpClient;
|
|
13616
14216
|
codeIndex;
|
|
13617
14217
|
config;
|
|
@@ -13650,6 +14250,10 @@ var Cascade = class _Cascade extends EventEmitter {
|
|
|
13650
14250
|
}
|
|
13651
14251
|
});
|
|
13652
14252
|
this.toolRegistry = new ToolRegistry(this.config.tools, workspacePath);
|
|
14253
|
+
this.multimodal = new MultimodalRegistry(
|
|
14254
|
+
(this.config.providers ?? []).map((p) => p.type)
|
|
14255
|
+
);
|
|
14256
|
+
this.registerMediaTools(workspacePath);
|
|
13653
14257
|
this.telemetry = config.telemetry?.enabled ? new Telemetry(config.telemetry, config.telemetry.distinctId ?? "anonymous") : noopTelemetry;
|
|
13654
14258
|
this.worldStateDB = new WorldStateDB(this.workspacePath, this.config.workspace?.debugWorldState ?? false);
|
|
13655
14259
|
this.router.setWorldStateDB(this.worldStateDB);
|
|
@@ -13703,14 +14307,14 @@ var Cascade = class _Cascade extends EventEmitter {
|
|
|
13703
14307
|
if (this.listenerCount("mcp:approval-required") === 0) {
|
|
13704
14308
|
return false;
|
|
13705
14309
|
}
|
|
13706
|
-
return await new Promise((
|
|
13707
|
-
this.pendingMcpApprovals.set(server.name,
|
|
14310
|
+
return await new Promise((resolve2) => {
|
|
14311
|
+
this.pendingMcpApprovals.set(server.name, resolve2);
|
|
13708
14312
|
const timeout = setTimeout(() => {
|
|
13709
|
-
if (this.pendingMcpApprovals.delete(server.name))
|
|
14313
|
+
if (this.pendingMcpApprovals.delete(server.name)) resolve2(false);
|
|
13710
14314
|
}, 3e4);
|
|
13711
14315
|
const wrap = (approved) => {
|
|
13712
14316
|
clearTimeout(timeout);
|
|
13713
|
-
|
|
14317
|
+
resolve2(approved);
|
|
13714
14318
|
};
|
|
13715
14319
|
this.pendingMcpApprovals.set(server.name, wrap);
|
|
13716
14320
|
this.emit("mcp:approval-required", { server });
|
|
@@ -13784,17 +14388,17 @@ var Cascade = class _Cascade extends EventEmitter {
|
|
|
13784
14388
|
}
|
|
13785
14389
|
const t2Count = plan.sections.length;
|
|
13786
14390
|
const t3Count = plan.sections.reduce((sum, s) => sum + (s.t3Subtasks?.length ?? 0), 0);
|
|
13787
|
-
return await new Promise((
|
|
14391
|
+
return await new Promise((resolve2) => {
|
|
13788
14392
|
const timeout = setTimeout(() => {
|
|
13789
14393
|
if (this.pendingPlanApproval) {
|
|
13790
14394
|
this.pendingPlanApproval = void 0;
|
|
13791
|
-
|
|
14395
|
+
resolve2({ approved: true });
|
|
13792
14396
|
}
|
|
13793
14397
|
}, 12e4);
|
|
13794
14398
|
this.pendingPlanApproval = (decision) => {
|
|
13795
14399
|
clearTimeout(timeout);
|
|
13796
14400
|
this.pendingPlanApproval = void 0;
|
|
13797
|
-
|
|
14401
|
+
resolve2(decision);
|
|
13798
14402
|
};
|
|
13799
14403
|
this.emit("plan:approval-required", {
|
|
13800
14404
|
taskId,
|
|
@@ -13827,17 +14431,17 @@ var Cascade = class _Cascade extends EventEmitter {
|
|
|
13827
14431
|
}
|
|
13828
14432
|
async requestContextApproval(info) {
|
|
13829
14433
|
if (this.listenerCount("context:approval-required") === 0) return true;
|
|
13830
|
-
return await new Promise((
|
|
14434
|
+
return await new Promise((resolve2) => {
|
|
13831
14435
|
const timeout = setTimeout(() => {
|
|
13832
14436
|
if (this.pendingContextApproval) {
|
|
13833
14437
|
this.pendingContextApproval = void 0;
|
|
13834
|
-
|
|
14438
|
+
resolve2(true);
|
|
13835
14439
|
}
|
|
13836
14440
|
}, 12e4);
|
|
13837
14441
|
this.pendingContextApproval = (approved) => {
|
|
13838
14442
|
clearTimeout(timeout);
|
|
13839
14443
|
this.pendingContextApproval = void 0;
|
|
13840
|
-
|
|
14444
|
+
resolve2(approved);
|
|
13841
14445
|
};
|
|
13842
14446
|
this.emit("context:approval-required", info);
|
|
13843
14447
|
});
|
|
@@ -13917,6 +14521,55 @@ ${input}` }],
|
|
|
13917
14521
|
if (this.store) t1.setStore(this.store);
|
|
13918
14522
|
return t1.previewPlan(prompt);
|
|
13919
14523
|
}
|
|
14524
|
+
/**
|
|
14525
|
+
* Register image / speech / transcription tools for the modalities this
|
|
14526
|
+
* config can actually serve.
|
|
14527
|
+
*
|
|
14528
|
+
* The sink writes bytes into the workspace, because that is what a desktop or
|
|
14529
|
+
* CLI run wants and it keeps a generated asset indistinguishable from any
|
|
14530
|
+
* other file the run produced. A host with different storage (the cloud
|
|
14531
|
+
* server stores a file row) constructs the tools itself via buildMediaTools
|
|
14532
|
+
* with its own sink.
|
|
14533
|
+
*/
|
|
14534
|
+
registerMediaTools(workspacePath) {
|
|
14535
|
+
const allowlist = this.config.tools?.enabledTools;
|
|
14536
|
+
const permitted = (name) => !allowlist || allowlist.includes(name);
|
|
14537
|
+
const tools = buildMediaTools(
|
|
14538
|
+
{
|
|
14539
|
+
registry: this.multimodal,
|
|
14540
|
+
lookupProvider: (provider) => (this.config.providers ?? []).find((p) => p.type === provider),
|
|
14541
|
+
sink: async (asset) => {
|
|
14542
|
+
const fsp = await import('fs/promises');
|
|
14543
|
+
const nodePath = await import('path');
|
|
14544
|
+
const dir = nodePath.join(workspacePath, "generated");
|
|
14545
|
+
await fsp.mkdir(dir, { recursive: true });
|
|
14546
|
+
const dest = nodePath.join(dir, asset.filename);
|
|
14547
|
+
await fsp.writeFile(dest, asset.data);
|
|
14548
|
+
return nodePath.relative(workspacePath, dest);
|
|
14549
|
+
}
|
|
14550
|
+
},
|
|
14551
|
+
async (p) => {
|
|
14552
|
+
const fsp = await import('fs/promises');
|
|
14553
|
+
return fsp.readFile(p);
|
|
14554
|
+
}
|
|
14555
|
+
);
|
|
14556
|
+
for (const tool of tools) {
|
|
14557
|
+
if (!permitted(tool.name)) continue;
|
|
14558
|
+
tool.setWorkspaceRoot(workspacePath);
|
|
14559
|
+
this.toolRegistry.register(tool);
|
|
14560
|
+
}
|
|
14561
|
+
}
|
|
14562
|
+
/**
|
|
14563
|
+
* Supply per-model thumbs-up/down counts so Auto routing can weigh how models
|
|
14564
|
+
* have actually performed for this user, on top of public benchmarks.
|
|
14565
|
+
*
|
|
14566
|
+
* Optional everywhere: with no source, or an empty record, scoring is
|
|
14567
|
+
* byte-identical to before. The adjustment is capped and sample-size shrunk —
|
|
14568
|
+
* see core/router/feedback-prior.ts.
|
|
14569
|
+
*/
|
|
14570
|
+
setFeedbackSource(source) {
|
|
14571
|
+
this.router.setFeedbackSource(source);
|
|
14572
|
+
}
|
|
13920
14573
|
/** True when a task stopped at the budget cap and can be resumed via /continue. */
|
|
13921
14574
|
hasResumableRun() {
|
|
13922
14575
|
return this.lastInterruptedRun != null;
|
|
@@ -14406,7 +15059,7 @@ ${prompt}` : prompt;
|
|
|
14406
15059
|
if (toolCreator) toolCreator.setPermissionEscalator(escalator);
|
|
14407
15060
|
const rootPrompt = buildContextualPrompt(options.prompt, options.conversationHistory);
|
|
14408
15061
|
let finalOutput = "";
|
|
14409
|
-
const runBreaker = new RunBreaker();
|
|
15062
|
+
const runBreaker = new RunBreaker(this.config.budget?.failureThreshold);
|
|
14410
15063
|
let t2Results = [];
|
|
14411
15064
|
let runError = null;
|
|
14412
15065
|
let identityPrompt = "";
|
|
@@ -16579,12 +17232,12 @@ var DashboardServer = class {
|
|
|
16579
17232
|
console.warn("\u26A0 Dashboard auth is DISABLED while bound to a non-loopback interface \u2014 this allows unauthenticated remote task execution.");
|
|
16580
17233
|
}
|
|
16581
17234
|
}
|
|
16582
|
-
await new Promise((
|
|
17235
|
+
await new Promise((resolve2, reject) => {
|
|
16583
17236
|
const onError = (err) => reject(err);
|
|
16584
17237
|
this.httpServer.once("error", onError);
|
|
16585
17238
|
this.httpServer.listen(this.port, this.host, () => {
|
|
16586
17239
|
this.httpServer.off("error", onError);
|
|
16587
|
-
|
|
17240
|
+
resolve2();
|
|
16588
17241
|
});
|
|
16589
17242
|
});
|
|
16590
17243
|
try {
|
|
@@ -16608,8 +17261,8 @@ var DashboardServer = class {
|
|
|
16608
17261
|
} catch {
|
|
16609
17262
|
}
|
|
16610
17263
|
this.globalStore = null;
|
|
16611
|
-
await new Promise((
|
|
16612
|
-
this.httpServer.close((err) => err ? reject(err) :
|
|
17264
|
+
await new Promise((resolve2, reject) => {
|
|
17265
|
+
this.httpServer.close((err) => err ? reject(err) : resolve2());
|
|
16613
17266
|
});
|
|
16614
17267
|
}
|
|
16615
17268
|
getSocket() {
|
|
@@ -16806,8 +17459,8 @@ var DashboardServer = class {
|
|
|
16806
17459
|
* timeout denies it.
|
|
16807
17460
|
*/
|
|
16808
17461
|
makeApprovalCallback(sessionId) {
|
|
16809
|
-
return (request) => new Promise((
|
|
16810
|
-
this.pendingApprovals.set(request.id, { resolve, sessionId });
|
|
17462
|
+
return (request) => new Promise((resolve2) => {
|
|
17463
|
+
this.pendingApprovals.set(request.id, { resolve: resolve2, sessionId });
|
|
16811
17464
|
});
|
|
16812
17465
|
}
|
|
16813
17466
|
/**
|
|
@@ -18119,8 +18772,8 @@ var CloudClient = class _CloudClient {
|
|
|
18119
18772
|
}
|
|
18120
18773
|
};
|
|
18121
18774
|
function sleep(ms, signal) {
|
|
18122
|
-
return new Promise((
|
|
18123
|
-
const t = setTimeout(
|
|
18775
|
+
return new Promise((resolve2, reject) => {
|
|
18776
|
+
const t = setTimeout(resolve2, ms);
|
|
18124
18777
|
signal?.addEventListener("abort", () => {
|
|
18125
18778
|
clearTimeout(t);
|
|
18126
18779
|
reject(new Error("aborted"));
|