@tangle-network/agent-runtime 0.70.0 → 0.71.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/agent.d.ts +4 -4
- package/dist/agent.js +5 -3
- package/dist/agent.js.map +1 -1
- package/dist/analyst-loop.d.ts +51 -0
- package/dist/analyst-loop.js +11 -0
- package/dist/analyst-loop.js.map +1 -0
- package/dist/{chunk-EDCVUZZC.js → chunk-4KGQHS7U.js} +2 -2
- package/dist/{chunk-QXWGSDAQ.js → chunk-5ISW5JUF.js} +287 -286
- package/dist/chunk-5ISW5JUF.js.map +1 -0
- package/dist/{chunk-ZNQVMMR5.js → chunk-74UAWZXE.js} +4 -4
- package/dist/{chunk-L5ZFBVT6.js → chunk-INXDNX2W.js} +2 -2
- package/dist/chunk-K3RM4MPM.js +214 -0
- package/dist/chunk-K3RM4MPM.js.map +1 -0
- package/dist/chunk-P5OKDSLB.js +580 -0
- package/dist/chunk-P5OKDSLB.js.map +1 -0
- package/dist/chunk-VLF5RHEQ.js +143 -0
- package/dist/chunk-VLF5RHEQ.js.map +1 -0
- package/dist/{chunk-G3RGMA7C.js → chunk-VMNEQHJR.js} +6 -1
- package/dist/chunk-VMNEQHJR.js.map +1 -0
- package/dist/{coordination-C7WxwHXq.d.ts → coordination-BPQmuwv8.d.ts} +280 -2
- package/dist/{delegates-DqAgo32T.d.ts → delegates-CsXJPZDH.d.ts} +48 -2
- package/dist/{improvement-adapter-BVuMragr.d.ts → improvement-adapter-CioiEE2z.d.ts} +1 -1
- package/dist/index.d.ts +9 -9
- package/dist/index.js +20 -17
- package/dist/index.js.map +1 -1
- package/dist/intelligence.d.ts +1 -1
- package/dist/intelligence.js +1 -1
- package/dist/{loop-runner-bin-B0NeLTRd.d.ts → loop-runner-bin-DLM_bVQO.d.ts} +4 -4
- package/dist/loop-runner-bin.d.ts +5 -5
- package/dist/loop-runner-bin.js +6 -4
- package/dist/loops.d.ts +121 -242
- package/dist/loops.js +10 -4
- package/dist/mcp/bin.js +8 -7
- package/dist/mcp/bin.js.map +1 -1
- package/dist/mcp/index.d.ts +7 -6
- package/dist/mcp/index.js +23 -12
- package/dist/mcp/index.js.map +1 -1
- package/dist/{openai-tools-DPx9Gzvn.d.ts → openai-tools-kdCS-T12.d.ts} +1 -1
- package/dist/platform.d.ts +255 -0
- package/dist/platform.js +229 -0
- package/dist/platform.js.map +1 -0
- package/dist/profiles.d.ts +1 -1
- package/dist/{types-DJu6TBGp.d.ts → types-BC3bZpH0.d.ts} +15 -1
- package/dist/{types-BYa2ZOAx.d.ts → types-CdnEAE3U.d.ts} +1 -1
- package/dist/{worktree-fanout-gNfl0Byj.d.ts → worktree-fanout-CK2ypmEm.d.ts} +3 -45
- package/package.json +11 -1
- package/dist/chunk-BYZCXQHF.js +0 -474
- package/dist/chunk-BYZCXQHF.js.map +0 -1
- package/dist/chunk-G3RGMA7C.js.map +0 -1
- package/dist/chunk-QXWGSDAQ.js.map +0 -1
- /package/dist/{chunk-EDCVUZZC.js.map → chunk-4KGQHS7U.js.map} +0 -0
- /package/dist/{chunk-ZNQVMMR5.js.map → chunk-74UAWZXE.js.map} +0 -0
- /package/dist/{chunk-L5ZFBVT6.js.map → chunk-INXDNX2W.js.map} +0 -0
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
import {
|
|
2
2
|
buildLoopSpanNodes
|
|
3
|
-
} from "./chunk-
|
|
3
|
+
} from "./chunk-VMNEQHJR.js";
|
|
4
|
+
import {
|
|
5
|
+
AgentEvalError,
|
|
6
|
+
AnalystError,
|
|
7
|
+
ConfigError,
|
|
8
|
+
NotFoundError,
|
|
9
|
+
PlannerError,
|
|
10
|
+
RuntimeRunStateError,
|
|
11
|
+
ValidationError,
|
|
12
|
+
extractLlmCallEvent
|
|
13
|
+
} from "./chunk-VLF5RHEQ.js";
|
|
4
14
|
import {
|
|
5
15
|
UI_LENSES
|
|
6
16
|
} from "./chunk-WIR4HOOJ.js";
|
|
@@ -679,61 +689,6 @@ function reportLoopUsage(cost, result, source = "loop") {
|
|
|
679
689
|
cost.observeTokens(result.tokenUsage);
|
|
680
690
|
}
|
|
681
691
|
|
|
682
|
-
// src/errors.ts
|
|
683
|
-
import { AgentEvalError } from "@tangle-network/agent-eval";
|
|
684
|
-
import {
|
|
685
|
-
AgentEvalError as AgentEvalError2,
|
|
686
|
-
ConfigError,
|
|
687
|
-
JudgeError,
|
|
688
|
-
NotFoundError,
|
|
689
|
-
ValidationError
|
|
690
|
-
} from "@tangle-network/agent-eval";
|
|
691
|
-
var SessionMismatchError = class extends AgentEvalError {
|
|
692
|
-
sessionBackend;
|
|
693
|
-
requestedBackend;
|
|
694
|
-
constructor(sessionBackend, requestedBackend, options) {
|
|
695
|
-
super(
|
|
696
|
-
"validation",
|
|
697
|
-
`Cannot resume ${sessionBackend} session with ${requestedBackend} backend`,
|
|
698
|
-
options
|
|
699
|
-
);
|
|
700
|
-
this.sessionBackend = sessionBackend;
|
|
701
|
-
this.requestedBackend = requestedBackend;
|
|
702
|
-
}
|
|
703
|
-
};
|
|
704
|
-
var BackendTransportError = class extends AgentEvalError {
|
|
705
|
-
backend;
|
|
706
|
-
status;
|
|
707
|
-
/**
|
|
708
|
-
* Truncated upstream response body (≤2 KiB) when available. Diagnostic
|
|
709
|
-
* only — surfaces in `backend_error.error.body` and `final.error.body`
|
|
710
|
-
* so operators can see "free_tier_limit", "invalid_api_key", etc. without
|
|
711
|
-
* cracking the log line open.
|
|
712
|
-
*/
|
|
713
|
-
body;
|
|
714
|
-
constructor(backend, message, options) {
|
|
715
|
-
super("config", message, options);
|
|
716
|
-
this.backend = backend;
|
|
717
|
-
this.status = options?.status;
|
|
718
|
-
this.body = options?.body;
|
|
719
|
-
}
|
|
720
|
-
};
|
|
721
|
-
var RuntimeRunStateError = class extends AgentEvalError {
|
|
722
|
-
constructor(message, options) {
|
|
723
|
-
super("validation", message, options);
|
|
724
|
-
}
|
|
725
|
-
};
|
|
726
|
-
var PlannerError = class extends AgentEvalError {
|
|
727
|
-
constructor(message, options) {
|
|
728
|
-
super("validation", message, options);
|
|
729
|
-
}
|
|
730
|
-
};
|
|
731
|
-
var AnalystError = class extends AgentEvalError {
|
|
732
|
-
constructor(message, options) {
|
|
733
|
-
super("validation", message, options);
|
|
734
|
-
}
|
|
735
|
-
};
|
|
736
|
-
|
|
737
692
|
// src/runtime-hooks.ts
|
|
738
693
|
function defineRuntimeHooks(hooks) {
|
|
739
694
|
return hooks;
|
|
@@ -962,79 +917,6 @@ async function resolveCapabilities(client) {
|
|
|
962
917
|
}
|
|
963
918
|
}
|
|
964
919
|
|
|
965
|
-
// src/runtime/sandbox-events.ts
|
|
966
|
-
function extractLlmCallEvent(event, agentRunName) {
|
|
967
|
-
if (!event || typeof event !== "object") return void 0;
|
|
968
|
-
const type = String(event.type ?? "");
|
|
969
|
-
const data = event.data && typeof event.data === "object" ? event.data : {};
|
|
970
|
-
if (type === "llm_call" || type === "cost.usage" || type === "usage") {
|
|
971
|
-
return buildLlmCall(data, agentRunName);
|
|
972
|
-
}
|
|
973
|
-
if (type === "message.completed" || type === "result" || type === "final") {
|
|
974
|
-
const usage = data.usage;
|
|
975
|
-
if (!usage || typeof usage !== "object") return void 0;
|
|
976
|
-
return buildLlmCall({ ...usage, model: data.model ?? usage.model }, agentRunName);
|
|
977
|
-
}
|
|
978
|
-
if (type === "done") {
|
|
979
|
-
const usage = data.tokenUsage;
|
|
980
|
-
if (!usage || typeof usage !== "object") return void 0;
|
|
981
|
-
const out = pickFiniteNumber(usage, ["outputTokens", "completion_tokens", "tokensOut"]);
|
|
982
|
-
const reasoning = pickFiniteNumber(usage, ["reasoningTokens"]);
|
|
983
|
-
const mergedOut = out !== void 0 || reasoning !== void 0 ? (out ?? 0) + (reasoning ?? 0) : void 0;
|
|
984
|
-
return buildLlmCall(
|
|
985
|
-
{
|
|
986
|
-
inputTokens: usage.inputTokens,
|
|
987
|
-
outputTokens: mergedOut,
|
|
988
|
-
totalCostUsd: data.totalCostUsd,
|
|
989
|
-
model: data.model ?? usage.model
|
|
990
|
-
},
|
|
991
|
-
agentRunName
|
|
992
|
-
);
|
|
993
|
-
}
|
|
994
|
-
return void 0;
|
|
995
|
-
}
|
|
996
|
-
function buildLlmCall(data, agentRunName) {
|
|
997
|
-
const tokensIn = pickFiniteNumber(data, ["tokensIn", "inputTokens", "prompt_tokens"]);
|
|
998
|
-
const tokensOut = pickFiniteNumber(data, ["tokensOut", "outputTokens", "completion_tokens"]);
|
|
999
|
-
const costUsd = pickFiniteNumber(data, ["costUsd", "totalCostUsd", "cost_usd", "cost"]);
|
|
1000
|
-
if (tokensIn === void 0 && tokensOut === void 0 && costUsd === void 0) {
|
|
1001
|
-
return void 0;
|
|
1002
|
-
}
|
|
1003
|
-
const model = typeof data.model === "string" && data.model.length > 0 ? data.model : agentRunName;
|
|
1004
|
-
const event = {
|
|
1005
|
-
type: "llm_call",
|
|
1006
|
-
model
|
|
1007
|
-
};
|
|
1008
|
-
if (tokensIn !== void 0) event.tokensIn = tokensIn;
|
|
1009
|
-
if (tokensOut !== void 0) event.tokensOut = tokensOut;
|
|
1010
|
-
if (costUsd !== void 0) event.costUsd = costUsd;
|
|
1011
|
-
return event;
|
|
1012
|
-
}
|
|
1013
|
-
function pickFiniteNumber(data, keys) {
|
|
1014
|
-
for (const key of keys) {
|
|
1015
|
-
const value = data[key];
|
|
1016
|
-
if (typeof value === "number" && Number.isFinite(value)) return value;
|
|
1017
|
-
}
|
|
1018
|
-
return void 0;
|
|
1019
|
-
}
|
|
1020
|
-
function mapSandboxEvent(event, opts = {}) {
|
|
1021
|
-
if (!event || typeof event !== "object") return void 0;
|
|
1022
|
-
const type = String(event.type ?? "");
|
|
1023
|
-
const data = event.data && typeof event.data === "object" ? event.data : {};
|
|
1024
|
-
if (type === "message.part.updated") {
|
|
1025
|
-
const part = data.part && typeof data.part === "object" ? data.part : {};
|
|
1026
|
-
const partType = String(part.type ?? "");
|
|
1027
|
-
const delta = typeof data.delta === "string" ? data.delta : void 0;
|
|
1028
|
-
const text = delta ?? (typeof part.text === "string" ? part.text : void 0);
|
|
1029
|
-
if (text === void 0) return void 0;
|
|
1030
|
-
if (partType === "text") return { type: "text_delta", text };
|
|
1031
|
-
if (partType === "reasoning" || partType === "thinking")
|
|
1032
|
-
return { type: "reasoning_delta", text };
|
|
1033
|
-
return void 0;
|
|
1034
|
-
}
|
|
1035
|
-
return extractLlmCallEvent(event, opts.agentRunName ?? "agent");
|
|
1036
|
-
}
|
|
1037
|
-
|
|
1038
920
|
// src/runtime/sandbox-lineage.ts
|
|
1039
921
|
var TEARDOWN_TIMEOUT_MS = 15e3;
|
|
1040
922
|
var DEFAULT_FORK_CONCURRENCY = 4;
|
|
@@ -4759,19 +4641,19 @@ function createSupervisor() {
|
|
|
4759
4641
|
...isNonEmptySpend(driverInference) ? { spentBreakdown: { driverInference, childWork } } : {}
|
|
4760
4642
|
};
|
|
4761
4643
|
}
|
|
4644
|
+
return noWinner();
|
|
4645
|
+
}
|
|
4646
|
+
return noWinner();
|
|
4647
|
+
async function noWinner() {
|
|
4648
|
+
const { childWork, driverInference } = await spentFromJournal(journal, opts.runId);
|
|
4762
4649
|
return {
|
|
4763
4650
|
kind: "no-winner",
|
|
4764
4651
|
reason: classifyNoWinner(controller, pool2, opts, breaker),
|
|
4765
4652
|
tree,
|
|
4766
|
-
downCount: breaker.downCount()
|
|
4653
|
+
downCount: breaker.downCount(),
|
|
4654
|
+
spentTotal: addSpend(childWork, driverInference)
|
|
4767
4655
|
};
|
|
4768
4656
|
}
|
|
4769
|
-
return {
|
|
4770
|
-
kind: "no-winner",
|
|
4771
|
-
reason: classifyNoWinner(controller, pool2, opts, breaker),
|
|
4772
|
-
tree,
|
|
4773
|
-
downCount: breaker.downCount()
|
|
4774
|
-
};
|
|
4775
4657
|
}
|
|
4776
4658
|
function attach(h) {
|
|
4777
4659
|
const control = rootControls.get(h);
|
|
@@ -7755,12 +7637,12 @@ function eventToSnapshot(event) {
|
|
|
7755
7637
|
// src/mcp/delegation-store.ts
|
|
7756
7638
|
import { mkdir, readFile, rename, writeFile } from "fs/promises";
|
|
7757
7639
|
import { dirname } from "path";
|
|
7758
|
-
var DelegationStateCorruptError = class extends
|
|
7640
|
+
var DelegationStateCorruptError = class extends AgentEvalError {
|
|
7759
7641
|
constructor(message, options) {
|
|
7760
7642
|
super("validation", message, options);
|
|
7761
7643
|
}
|
|
7762
7644
|
};
|
|
7763
|
-
var DelegationPersistenceError = class extends
|
|
7645
|
+
var DelegationPersistenceError = class extends AgentEvalError {
|
|
7764
7646
|
constructor(message, options) {
|
|
7765
7647
|
super("config", message, options);
|
|
7766
7648
|
}
|
|
@@ -8477,6 +8359,253 @@ function canonicalize(value) {
|
|
|
8477
8359
|
return out;
|
|
8478
8360
|
}
|
|
8479
8361
|
|
|
8362
|
+
// src/runtime/supervise/model-policy.ts
|
|
8363
|
+
function assertModelAllowed(model, allowed) {
|
|
8364
|
+
if (!allowed || model === void 0) return;
|
|
8365
|
+
if (!allowed.includes(model)) {
|
|
8366
|
+
throw new ConfigError(
|
|
8367
|
+
`model ${JSON.stringify(model)} is not in the allowed set ${JSON.stringify([...allowed])}`
|
|
8368
|
+
);
|
|
8369
|
+
}
|
|
8370
|
+
}
|
|
8371
|
+
|
|
8372
|
+
// src/runtime/supervise/run-context.ts
|
|
8373
|
+
function createInMemoryRunContext(opts = {}) {
|
|
8374
|
+
const base = createExecutorRegistry();
|
|
8375
|
+
return {
|
|
8376
|
+
journal: new InMemorySpawnJournal(),
|
|
8377
|
+
blobs: new InMemoryResultBlobStore(),
|
|
8378
|
+
executors: opts.withDriver ? withDriverExecutor(base) : base
|
|
8379
|
+
};
|
|
8380
|
+
}
|
|
8381
|
+
|
|
8382
|
+
// src/runtime/supervise/supervisor-agent.ts
|
|
8383
|
+
function supervisorAgent(profile, deps) {
|
|
8384
|
+
const name = profile.name ?? "supervisor";
|
|
8385
|
+
const systemPrompt = profile.systemPrompt ?? "";
|
|
8386
|
+
const harness = profile.harness ?? null;
|
|
8387
|
+
if (harness === null) {
|
|
8388
|
+
const brain = deps.brain ?? routerBrainFromProfile(profile, deps);
|
|
8389
|
+
return driverAgent({
|
|
8390
|
+
name,
|
|
8391
|
+
brain,
|
|
8392
|
+
blobs: deps.blobs,
|
|
8393
|
+
makeWorkerAgent: deps.makeWorkerAgent,
|
|
8394
|
+
perWorker: deps.perWorker,
|
|
8395
|
+
systemPrompt,
|
|
8396
|
+
...deps.extraTools ? { extraTools: deps.extraTools } : {},
|
|
8397
|
+
...deps.executeExtraTool ? { executeExtraTool: deps.executeExtraTool } : {},
|
|
8398
|
+
...deps.maxTurns !== void 0 ? { maxTurns: deps.maxTurns } : {}
|
|
8399
|
+
});
|
|
8400
|
+
}
|
|
8401
|
+
const driveHarness = deps.driveHarness;
|
|
8402
|
+
if (!driveHarness) {
|
|
8403
|
+
throw new ValidationError(
|
|
8404
|
+
`supervisorAgent: profile.harness="${harness}" needs deps.driveHarness (how to run the harness with the coordination MCP mounted)`
|
|
8405
|
+
);
|
|
8406
|
+
}
|
|
8407
|
+
return {
|
|
8408
|
+
name,
|
|
8409
|
+
async act(task, scope) {
|
|
8410
|
+
const mcp = await serveCoordinationMcp({
|
|
8411
|
+
scope,
|
|
8412
|
+
blobs: deps.blobs,
|
|
8413
|
+
makeWorkerAgent: deps.makeWorkerAgent,
|
|
8414
|
+
perWorker: deps.perWorker
|
|
8415
|
+
});
|
|
8416
|
+
try {
|
|
8417
|
+
await driveHarness({ profile, task, scope, coordinationMcpUrl: mcp.url });
|
|
8418
|
+
return await finalizeBestDelivered(mcp.settled(), deps.blobs);
|
|
8419
|
+
} finally {
|
|
8420
|
+
await mcp.close();
|
|
8421
|
+
}
|
|
8422
|
+
}
|
|
8423
|
+
};
|
|
8424
|
+
}
|
|
8425
|
+
function routerBrainFromProfile(profile, deps) {
|
|
8426
|
+
if (!deps.router) {
|
|
8427
|
+
throw new ValidationError(
|
|
8428
|
+
"supervisorAgent: a router-brained supervisor (harness null) needs deps.router (or deps.brain)"
|
|
8429
|
+
);
|
|
8430
|
+
}
|
|
8431
|
+
return routerBrain({ ...deps.router, model: profile.model ?? deps.router.model });
|
|
8432
|
+
}
|
|
8433
|
+
|
|
8434
|
+
// src/runtime/supervise/supervise.ts
|
|
8435
|
+
function workerFromBackend(backend, deliverable) {
|
|
8436
|
+
return (rawProfile) => {
|
|
8437
|
+
const p = rawProfile ?? {};
|
|
8438
|
+
const name = typeof p.name === "string" && p.name.length > 0 ? p.name : "worker";
|
|
8439
|
+
const spec = { profile: rawProfile, harness: null };
|
|
8440
|
+
const ctx = { signal: new AbortController().signal, seams: {} };
|
|
8441
|
+
const built = createExecutor(backend)(spec, ctx);
|
|
8442
|
+
const executor = deliverable ? gateOnDeliverable(built, deliverable) : built;
|
|
8443
|
+
return { name, act: async () => "", executorSpec: { ...spec, executor } };
|
|
8444
|
+
};
|
|
8445
|
+
}
|
|
8446
|
+
function defaultPerWorker(budget) {
|
|
8447
|
+
return {
|
|
8448
|
+
maxIterations: budget.maxIterations,
|
|
8449
|
+
maxTokens: Math.max(1, Math.floor(budget.maxTokens / 4))
|
|
8450
|
+
};
|
|
8451
|
+
}
|
|
8452
|
+
function supervise(profile, task, opts) {
|
|
8453
|
+
const backendModel = opts.backend?.model;
|
|
8454
|
+
assertModelAllowed(opts.router?.model, opts.allowedModels);
|
|
8455
|
+
assertModelAllowed(profile.model, opts.allowedModels);
|
|
8456
|
+
assertModelAllowed(
|
|
8457
|
+
typeof backendModel === "string" ? backendModel : void 0,
|
|
8458
|
+
opts.allowedModels
|
|
8459
|
+
);
|
|
8460
|
+
const ctx = createInMemoryRunContext({ withDriver: true });
|
|
8461
|
+
const blobs = opts.blobs ?? ctx.blobs;
|
|
8462
|
+
const perWorker = opts.perWorker ?? defaultPerWorker(opts.budget);
|
|
8463
|
+
let makeWorkerAgent = opts.makeWorkerAgent;
|
|
8464
|
+
if (!makeWorkerAgent) {
|
|
8465
|
+
if (!opts.backend) {
|
|
8466
|
+
throw new ValidationError(
|
|
8467
|
+
"supervise: provide opts.backend (where workers run) or opts.makeWorkerAgent"
|
|
8468
|
+
);
|
|
8469
|
+
}
|
|
8470
|
+
makeWorkerAgent = workerFromBackend(opts.backend, opts.deliverable);
|
|
8471
|
+
}
|
|
8472
|
+
const agent = supervisorAgent(profile, {
|
|
8473
|
+
blobs,
|
|
8474
|
+
makeWorkerAgent,
|
|
8475
|
+
perWorker,
|
|
8476
|
+
...opts.router ? { router: opts.router } : {},
|
|
8477
|
+
...opts.brain ? { brain: opts.brain } : {},
|
|
8478
|
+
...opts.driveHarness ? { driveHarness: opts.driveHarness } : {},
|
|
8479
|
+
...opts.extraTools ? { extraTools: opts.extraTools } : {},
|
|
8480
|
+
...opts.executeExtraTool ? { executeExtraTool: opts.executeExtraTool } : {},
|
|
8481
|
+
...opts.maxTurns !== void 0 ? { maxTurns: opts.maxTurns } : {}
|
|
8482
|
+
});
|
|
8483
|
+
return createSupervisor().run(agent, task, {
|
|
8484
|
+
budget: opts.budget,
|
|
8485
|
+
runId: opts.runId ?? "supervise",
|
|
8486
|
+
journal: ctx.journal,
|
|
8487
|
+
blobs,
|
|
8488
|
+
executors: ctx.executors,
|
|
8489
|
+
maxDepth: opts.maxDepth ?? 8,
|
|
8490
|
+
...opts.now ? { now: opts.now } : {}
|
|
8491
|
+
});
|
|
8492
|
+
}
|
|
8493
|
+
|
|
8494
|
+
// src/runtime/supervise/delegate.ts
|
|
8495
|
+
var defaultDelegateBudget = { maxIterations: 50, maxTokens: 2e5 };
|
|
8496
|
+
function authoringSupervisorProfile(model, override) {
|
|
8497
|
+
return {
|
|
8498
|
+
name: override?.name ?? "delegate-supervisor",
|
|
8499
|
+
harness: null,
|
|
8500
|
+
...model ? { model } : {},
|
|
8501
|
+
systemPrompt: override?.systemPrompt ?? supervisorInstructions()
|
|
8502
|
+
};
|
|
8503
|
+
}
|
|
8504
|
+
async function delegate(intent, opts = {}) {
|
|
8505
|
+
if (typeof intent !== "string" || intent.trim().length === 0) {
|
|
8506
|
+
throw new ConfigError("delegate: `intent` must be a non-empty string");
|
|
8507
|
+
}
|
|
8508
|
+
if (!opts.brain && !opts.router) {
|
|
8509
|
+
throw new ConfigError(
|
|
8510
|
+
"delegate: provide opts.router (the supervisor brain substrate) or opts.brain (tests)"
|
|
8511
|
+
);
|
|
8512
|
+
}
|
|
8513
|
+
const profile = authoringSupervisorProfile(opts.model, opts.supervisor);
|
|
8514
|
+
return supervise(profile, intent, {
|
|
8515
|
+
budget: opts.budget ?? defaultDelegateBudget,
|
|
8516
|
+
...opts.backend ? { backend: opts.backend } : {},
|
|
8517
|
+
...opts.deliverable ? { deliverable: opts.deliverable } : {},
|
|
8518
|
+
...opts.router ? { router: opts.router } : {},
|
|
8519
|
+
...opts.brain ? { brain: opts.brain } : {},
|
|
8520
|
+
...opts.allowedModels ? { allowedModels: opts.allowedModels } : {},
|
|
8521
|
+
...opts.runId ? { runId: opts.runId } : {}
|
|
8522
|
+
});
|
|
8523
|
+
}
|
|
8524
|
+
|
|
8525
|
+
// src/mcp/tools/delegate.ts
|
|
8526
|
+
var DELEGATE_TOOL_NAME = "delegate";
|
|
8527
|
+
var DELEGATE_DESCRIPTION = [
|
|
8528
|
+
"Delegate an INTENT to a supervisor that AUTHORS and drives whatever worker the intent needs.",
|
|
8529
|
+
"",
|
|
8530
|
+
'Use when: you want a task done but do not want to specify HOW. State the outcome \u2014 "fix the',
|
|
8531
|
+
'failing auth test", "research competitor pricing with citations", "refactor the parser for',
|
|
8532
|
+
'clarity" \u2014 and the supervisor decomposes it, writes a tailored worker profile per sub-task, runs',
|
|
8533
|
+
"the workers over a conserved compute budget, and settles only when a deployable check passes.",
|
|
8534
|
+
"",
|
|
8535
|
+
"There is no fixed worker type: this ONE verb replaces separate code / research delegation. The",
|
|
8536
|
+
"supervisor picks the worker shape from your intent.",
|
|
8537
|
+
"",
|
|
8538
|
+
"Returns synchronously with the delivered result AND the real cost of the whole delegation",
|
|
8539
|
+
"(spentTotal: iterations, input/output tokens, usd, ms) \u2014 so you always know what it spent. A run",
|
|
8540
|
+
'that produced no delivered worker returns status "no-winner" with the reason; it never fabricates',
|
|
8541
|
+
"a success."
|
|
8542
|
+
].join("\n");
|
|
8543
|
+
var DELEGATE_INPUT_SCHEMA = {
|
|
8544
|
+
type: "object",
|
|
8545
|
+
properties: {
|
|
8546
|
+
intent: {
|
|
8547
|
+
type: "string",
|
|
8548
|
+
description: "What you want accomplished, as an outcome. The supervisor authors the worker."
|
|
8549
|
+
},
|
|
8550
|
+
model: {
|
|
8551
|
+
type: "string",
|
|
8552
|
+
description: "Optional per-call override for the supervisor brain model."
|
|
8553
|
+
},
|
|
8554
|
+
runId: {
|
|
8555
|
+
type: "string",
|
|
8556
|
+
description: "Optional trace-correlation id for this delegation."
|
|
8557
|
+
}
|
|
8558
|
+
},
|
|
8559
|
+
required: ["intent"],
|
|
8560
|
+
additionalProperties: false
|
|
8561
|
+
};
|
|
8562
|
+
function validateDelegateArgs(raw) {
|
|
8563
|
+
if (raw === null || typeof raw !== "object") {
|
|
8564
|
+
throw new TypeError("delegate: arguments must be an object");
|
|
8565
|
+
}
|
|
8566
|
+
const value = raw;
|
|
8567
|
+
const intent = value.intent;
|
|
8568
|
+
if (typeof intent !== "string" || intent.trim().length === 0) {
|
|
8569
|
+
throw new TypeError("delegate: `intent` must be a non-empty string");
|
|
8570
|
+
}
|
|
8571
|
+
const args = { intent: intent.trim() };
|
|
8572
|
+
if (value.model !== void 0) {
|
|
8573
|
+
if (typeof value.model !== "string") throw new TypeError("delegate: `model` must be a string");
|
|
8574
|
+
args.model = value.model;
|
|
8575
|
+
}
|
|
8576
|
+
if (value.runId !== void 0) {
|
|
8577
|
+
if (typeof value.runId !== "string") throw new TypeError("delegate: `runId` must be a string");
|
|
8578
|
+
args.runId = value.runId;
|
|
8579
|
+
}
|
|
8580
|
+
return args;
|
|
8581
|
+
}
|
|
8582
|
+
function toDelegateResult(result) {
|
|
8583
|
+
if (result.kind === "no-winner") {
|
|
8584
|
+
return { status: "no-winner", reason: result.reason, spentTotal: result.spentTotal };
|
|
8585
|
+
}
|
|
8586
|
+
return {
|
|
8587
|
+
status: "winner",
|
|
8588
|
+
out: result.out,
|
|
8589
|
+
outRef: result.outRef,
|
|
8590
|
+
spentTotal: result.spentTotal
|
|
8591
|
+
};
|
|
8592
|
+
}
|
|
8593
|
+
function createDelegateHandler(options) {
|
|
8594
|
+
return async (raw) => {
|
|
8595
|
+
const args = validateDelegateArgs(raw);
|
|
8596
|
+
const opts = {
|
|
8597
|
+
backend: options.backend,
|
|
8598
|
+
router: options.router,
|
|
8599
|
+
model: args.model ?? options.model,
|
|
8600
|
+
...options.deliverable ? { deliverable: options.deliverable } : {},
|
|
8601
|
+
...options.allowedModels ? { allowedModels: options.allowedModels } : {},
|
|
8602
|
+
...args.runId ? { runId: args.runId } : {}
|
|
8603
|
+
};
|
|
8604
|
+
const result = await delegate(args.intent, opts);
|
|
8605
|
+
return toDelegateResult(result);
|
|
8606
|
+
};
|
|
8607
|
+
}
|
|
8608
|
+
|
|
8480
8609
|
// src/mcp/detached-turn.ts
|
|
8481
8610
|
var DEFAULT_TICK_INTERVAL_MS = 5e3;
|
|
8482
8611
|
function formatDetachedSessionRef(parts) {
|
|
@@ -9631,6 +9760,14 @@ function createMcpServer(options = {}) {
|
|
|
9631
9760
|
const serverName = options.serverName ?? DEFAULT_SERVER_NAME;
|
|
9632
9761
|
const serverVersion = options.serverVersion ?? DEFAULT_SERVER_VERSION;
|
|
9633
9762
|
const tools = /* @__PURE__ */ new Map();
|
|
9763
|
+
if (options.delegateSupervisor) {
|
|
9764
|
+
tools.set(DELEGATE_TOOL_NAME, {
|
|
9765
|
+
name: DELEGATE_TOOL_NAME,
|
|
9766
|
+
description: DELEGATE_DESCRIPTION,
|
|
9767
|
+
inputSchema: DELEGATE_INPUT_SCHEMA,
|
|
9768
|
+
handler: createDelegateHandler(options.delegateSupervisor)
|
|
9769
|
+
});
|
|
9770
|
+
}
|
|
9634
9771
|
if (options.coderDelegate) {
|
|
9635
9772
|
tools.set(DELEGATE_CODE_TOOL_NAME, {
|
|
9636
9773
|
name: DELEGATE_CODE_TOOL_NAME,
|
|
@@ -9928,16 +10065,6 @@ function watchTrace(source, opts = {}) {
|
|
|
9928
10065
|
});
|
|
9929
10066
|
}
|
|
9930
10067
|
|
|
9931
|
-
// src/runtime/supervise/model-policy.ts
|
|
9932
|
-
function assertModelAllowed(model, allowed) {
|
|
9933
|
-
if (!allowed || model === void 0) return;
|
|
9934
|
-
if (!allowed.includes(model)) {
|
|
9935
|
-
throw new ConfigError(
|
|
9936
|
-
`model ${JSON.stringify(model)} is not in the allowed set ${JSON.stringify([...allowed])}`
|
|
9937
|
-
);
|
|
9938
|
-
}
|
|
9939
|
-
}
|
|
9940
|
-
|
|
9941
10068
|
// src/runtime/supervise/patch-checks.ts
|
|
9942
10069
|
var DEFAULT_MAX_DIFF_LINES = 400;
|
|
9943
10070
|
var secretPathPattern = /(^|\/)(\.env(\.|$)|.*\.(pem|key|p12|pfx|keystore|wallet)|id_rsa|id_ed25519|secrets?\.json|credentials?\.json)$/i;
|
|
@@ -10048,128 +10175,6 @@ function signalPass(value, required) {
|
|
|
10048
10175
|
return !required;
|
|
10049
10176
|
}
|
|
10050
10177
|
|
|
10051
|
-
// src/runtime/supervise/run-context.ts
|
|
10052
|
-
function createInMemoryRunContext(opts = {}) {
|
|
10053
|
-
const base = createExecutorRegistry();
|
|
10054
|
-
return {
|
|
10055
|
-
journal: new InMemorySpawnJournal(),
|
|
10056
|
-
blobs: new InMemoryResultBlobStore(),
|
|
10057
|
-
executors: opts.withDriver ? withDriverExecutor(base) : base
|
|
10058
|
-
};
|
|
10059
|
-
}
|
|
10060
|
-
|
|
10061
|
-
// src/runtime/supervise/supervisor-agent.ts
|
|
10062
|
-
function supervisorAgent(profile, deps) {
|
|
10063
|
-
const name = profile.name ?? "supervisor";
|
|
10064
|
-
const systemPrompt = profile.systemPrompt ?? "";
|
|
10065
|
-
const harness = profile.harness ?? null;
|
|
10066
|
-
if (harness === null) {
|
|
10067
|
-
const brain = deps.brain ?? routerBrainFromProfile(profile, deps);
|
|
10068
|
-
return driverAgent({
|
|
10069
|
-
name,
|
|
10070
|
-
brain,
|
|
10071
|
-
blobs: deps.blobs,
|
|
10072
|
-
makeWorkerAgent: deps.makeWorkerAgent,
|
|
10073
|
-
perWorker: deps.perWorker,
|
|
10074
|
-
systemPrompt,
|
|
10075
|
-
...deps.extraTools ? { extraTools: deps.extraTools } : {},
|
|
10076
|
-
...deps.executeExtraTool ? { executeExtraTool: deps.executeExtraTool } : {},
|
|
10077
|
-
...deps.maxTurns !== void 0 ? { maxTurns: deps.maxTurns } : {}
|
|
10078
|
-
});
|
|
10079
|
-
}
|
|
10080
|
-
const driveHarness = deps.driveHarness;
|
|
10081
|
-
if (!driveHarness) {
|
|
10082
|
-
throw new ValidationError(
|
|
10083
|
-
`supervisorAgent: profile.harness="${harness}" needs deps.driveHarness (how to run the harness with the coordination MCP mounted)`
|
|
10084
|
-
);
|
|
10085
|
-
}
|
|
10086
|
-
return {
|
|
10087
|
-
name,
|
|
10088
|
-
async act(task, scope) {
|
|
10089
|
-
const mcp = await serveCoordinationMcp({
|
|
10090
|
-
scope,
|
|
10091
|
-
blobs: deps.blobs,
|
|
10092
|
-
makeWorkerAgent: deps.makeWorkerAgent,
|
|
10093
|
-
perWorker: deps.perWorker
|
|
10094
|
-
});
|
|
10095
|
-
try {
|
|
10096
|
-
await driveHarness({ profile, task, scope, coordinationMcpUrl: mcp.url });
|
|
10097
|
-
return await finalizeBestDelivered(mcp.settled(), deps.blobs);
|
|
10098
|
-
} finally {
|
|
10099
|
-
await mcp.close();
|
|
10100
|
-
}
|
|
10101
|
-
}
|
|
10102
|
-
};
|
|
10103
|
-
}
|
|
10104
|
-
function routerBrainFromProfile(profile, deps) {
|
|
10105
|
-
if (!deps.router) {
|
|
10106
|
-
throw new ValidationError(
|
|
10107
|
-
"supervisorAgent: a router-brained supervisor (harness null) needs deps.router (or deps.brain)"
|
|
10108
|
-
);
|
|
10109
|
-
}
|
|
10110
|
-
return routerBrain({ ...deps.router, model: profile.model ?? deps.router.model });
|
|
10111
|
-
}
|
|
10112
|
-
|
|
10113
|
-
// src/runtime/supervise/supervise.ts
|
|
10114
|
-
function workerFromBackend(backend, deliverable) {
|
|
10115
|
-
return (rawProfile) => {
|
|
10116
|
-
const p = rawProfile ?? {};
|
|
10117
|
-
const name = typeof p.name === "string" && p.name.length > 0 ? p.name : "worker";
|
|
10118
|
-
const spec = { profile: rawProfile, harness: null };
|
|
10119
|
-
const ctx = { signal: new AbortController().signal, seams: {} };
|
|
10120
|
-
const built = createExecutor(backend)(spec, ctx);
|
|
10121
|
-
const executor = deliverable ? gateOnDeliverable(built, deliverable) : built;
|
|
10122
|
-
return { name, act: async () => "", executorSpec: { ...spec, executor } };
|
|
10123
|
-
};
|
|
10124
|
-
}
|
|
10125
|
-
function defaultPerWorker(budget) {
|
|
10126
|
-
return {
|
|
10127
|
-
maxIterations: budget.maxIterations,
|
|
10128
|
-
maxTokens: Math.max(1, Math.floor(budget.maxTokens / 4))
|
|
10129
|
-
};
|
|
10130
|
-
}
|
|
10131
|
-
function supervise(profile, task, opts) {
|
|
10132
|
-
const backendModel = opts.backend?.model;
|
|
10133
|
-
assertModelAllowed(opts.router?.model, opts.allowedModels);
|
|
10134
|
-
assertModelAllowed(profile.model, opts.allowedModels);
|
|
10135
|
-
assertModelAllowed(
|
|
10136
|
-
typeof backendModel === "string" ? backendModel : void 0,
|
|
10137
|
-
opts.allowedModels
|
|
10138
|
-
);
|
|
10139
|
-
const ctx = createInMemoryRunContext({ withDriver: true });
|
|
10140
|
-
const blobs = opts.blobs ?? ctx.blobs;
|
|
10141
|
-
const perWorker = opts.perWorker ?? defaultPerWorker(opts.budget);
|
|
10142
|
-
let makeWorkerAgent = opts.makeWorkerAgent;
|
|
10143
|
-
if (!makeWorkerAgent) {
|
|
10144
|
-
if (!opts.backend) {
|
|
10145
|
-
throw new ValidationError(
|
|
10146
|
-
"supervise: provide opts.backend (where workers run) or opts.makeWorkerAgent"
|
|
10147
|
-
);
|
|
10148
|
-
}
|
|
10149
|
-
makeWorkerAgent = workerFromBackend(opts.backend, opts.deliverable);
|
|
10150
|
-
}
|
|
10151
|
-
const agent = supervisorAgent(profile, {
|
|
10152
|
-
blobs,
|
|
10153
|
-
makeWorkerAgent,
|
|
10154
|
-
perWorker,
|
|
10155
|
-
...opts.router ? { router: opts.router } : {},
|
|
10156
|
-
...opts.brain ? { brain: opts.brain } : {},
|
|
10157
|
-
...opts.driveHarness ? { driveHarness: opts.driveHarness } : {},
|
|
10158
|
-
...opts.extraTools ? { extraTools: opts.extraTools } : {},
|
|
10159
|
-
...opts.executeExtraTool ? { executeExtraTool: opts.executeExtraTool } : {},
|
|
10160
|
-
...opts.maxTurns !== void 0 ? { maxTurns: opts.maxTurns } : {}
|
|
10161
|
-
});
|
|
10162
|
-
return createSupervisor().run(agent, task, {
|
|
10163
|
-
budget: opts.budget,
|
|
10164
|
-
runId: opts.runId ?? "supervise",
|
|
10165
|
-
journal: ctx.journal,
|
|
10166
|
-
blobs,
|
|
10167
|
-
executors: ctx.executors,
|
|
10168
|
-
maxDepth: opts.maxDepth ?? 8,
|
|
10169
|
-
...opts.now ? { now: opts.now } : {}
|
|
10170
|
-
});
|
|
10171
|
-
}
|
|
10172
|
-
|
|
10173
10178
|
// src/runtime/supervise/trace-source.ts
|
|
10174
10179
|
function toToolSpan(input, runId, seq, at) {
|
|
10175
10180
|
const startedAt = typeof input.startedAt === "number" ? input.startedAt : at;
|
|
@@ -10693,19 +10698,8 @@ function tail(s) {
|
|
|
10693
10698
|
}
|
|
10694
10699
|
|
|
10695
10700
|
export {
|
|
10696
|
-
SessionMismatchError,
|
|
10697
|
-
BackendTransportError,
|
|
10698
|
-
RuntimeRunStateError,
|
|
10699
|
-
PlannerError,
|
|
10700
|
-
AgentEvalError2 as AgentEvalError,
|
|
10701
|
-
ConfigError,
|
|
10702
|
-
JudgeError,
|
|
10703
|
-
NotFoundError,
|
|
10704
|
-
ValidationError,
|
|
10705
10701
|
runLocalHarness,
|
|
10706
10702
|
assertModelAllowed,
|
|
10707
|
-
extractLlmCallEvent,
|
|
10708
|
-
mapSandboxEvent,
|
|
10709
10703
|
contentAddress,
|
|
10710
10704
|
InMemoryResultBlobStore,
|
|
10711
10705
|
InMemorySpawnJournal,
|
|
@@ -10819,6 +10813,17 @@ export {
|
|
|
10819
10813
|
composeLoopTraceEmitters,
|
|
10820
10814
|
DelegationTaskQueue,
|
|
10821
10815
|
hashIdempotencyInput,
|
|
10816
|
+
createInMemoryRunContext,
|
|
10817
|
+
supervisorAgent,
|
|
10818
|
+
workerFromBackend,
|
|
10819
|
+
supervise,
|
|
10820
|
+
defaultDelegateBudget,
|
|
10821
|
+
delegate,
|
|
10822
|
+
DELEGATE_TOOL_NAME,
|
|
10823
|
+
DELEGATE_DESCRIPTION,
|
|
10824
|
+
DELEGATE_INPUT_SCHEMA,
|
|
10825
|
+
validateDelegateArgs,
|
|
10826
|
+
createDelegateHandler,
|
|
10822
10827
|
formatDetachedSessionRef,
|
|
10823
10828
|
parseDetachedSessionRef,
|
|
10824
10829
|
detachedTurnEvents,
|
|
@@ -10861,10 +10866,6 @@ export {
|
|
|
10861
10866
|
watchTrace,
|
|
10862
10867
|
runCoderChecks,
|
|
10863
10868
|
patchDelivered,
|
|
10864
|
-
createInMemoryRunContext,
|
|
10865
|
-
supervisorAgent,
|
|
10866
|
-
workerFromBackend,
|
|
10867
|
-
supervise,
|
|
10868
10869
|
decodeToolPart,
|
|
10869
10870
|
createPushTraceSource,
|
|
10870
10871
|
sandboxSessionTraceSource,
|
|
@@ -10879,4 +10880,4 @@ export {
|
|
|
10879
10880
|
computeFindingId2 as computeFindingId,
|
|
10880
10881
|
makeFinding3 as makeFinding
|
|
10881
10882
|
};
|
|
10882
|
-
//# sourceMappingURL=chunk-
|
|
10883
|
+
//# sourceMappingURL=chunk-5ISW5JUF.js.map
|