@tangle-network/agent-eval 0.126.0 → 0.126.1
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/CHANGELOG.md +14 -0
- package/dist/analyst/index.js +3 -3
- package/dist/benchmarks/index.js +3 -3
- package/dist/campaign/index.d.ts +4 -5
- package/dist/campaign/index.js +3 -3
- package/dist/{chunk-4B7ZZHPX.js → chunk-KE2VWPZX.js} +3 -3
- package/dist/{chunk-CM4OILD2.js → chunk-LUNF2SEL.js} +4 -6
- package/dist/{chunk-CM4OILD2.js.map → chunk-LUNF2SEL.js.map} +1 -1
- package/dist/{chunk-KO2PZOGP.js → chunk-NGUYT5CI.js} +3 -3
- package/dist/{chunk-NTOV7RU5.js → chunk-VMUENW6F.js} +177 -55
- package/dist/chunk-VMUENW6F.js.map +1 -0
- package/dist/{chunk-UI4YMIN2.js → chunk-WGXIEX7P.js} +12 -1
- package/dist/chunk-WGXIEX7P.js.map +1 -0
- package/dist/contract/index.d.ts +4 -5
- package/dist/contract/index.js +3 -3
- package/dist/index.js +5 -5
- package/dist/openapi.json +1 -1
- package/docs/campaign-proposers.md +3 -3
- package/package.json +1 -1
- package/dist/chunk-NTOV7RU5.js.map +0 -1
- package/dist/chunk-UI4YMIN2.js.map +0 -1
- /package/dist/{chunk-4B7ZZHPX.js.map → chunk-KE2VWPZX.js.map} +0 -0
- /package/dist/{chunk-KO2PZOGP.js.map → chunk-NGUYT5CI.js.map} +0 -0
|
@@ -7,7 +7,7 @@ import {
|
|
|
7
7
|
pairHoldout,
|
|
8
8
|
recoverTruncatedJson,
|
|
9
9
|
surfaceContentHash
|
|
10
|
-
} from "./chunk-
|
|
10
|
+
} from "./chunk-VMUENW6F.js";
|
|
11
11
|
import {
|
|
12
12
|
SearchLedgerConflictError,
|
|
13
13
|
SearchLedgerError,
|
|
@@ -22,7 +22,7 @@ import {
|
|
|
22
22
|
} from "./chunk-UCLVDLCH.js";
|
|
23
23
|
import {
|
|
24
24
|
Mutex
|
|
25
|
-
} from "./chunk-
|
|
25
|
+
} from "./chunk-WGXIEX7P.js";
|
|
26
26
|
import {
|
|
27
27
|
eProcess,
|
|
28
28
|
mcnemar,
|
|
@@ -4634,4 +4634,4 @@ export {
|
|
|
4634
4634
|
verifyCodeSurface,
|
|
4635
4635
|
resolveWorktreePath
|
|
4636
4636
|
};
|
|
4637
|
-
//# sourceMappingURL=chunk-
|
|
4637
|
+
//# sourceMappingURL=chunk-NGUYT5CI.js.map
|
|
@@ -16,8 +16,9 @@ import {
|
|
|
16
16
|
} from "./chunk-UCLVDLCH.js";
|
|
17
17
|
import {
|
|
18
18
|
clamp01,
|
|
19
|
+
combineAbortSignals,
|
|
19
20
|
mapConcurrent
|
|
20
|
-
} from "./chunk-
|
|
21
|
+
} from "./chunk-WGXIEX7P.js";
|
|
21
22
|
import {
|
|
22
23
|
detectRewardHacking
|
|
23
24
|
} from "./chunk-ARU2PZFM.js";
|
|
@@ -1696,7 +1697,6 @@ ${describe(winnerSurface)}`;
|
|
|
1696
1697
|
}
|
|
1697
1698
|
|
|
1698
1699
|
// src/campaign/presets/compare-optimization-methods.ts
|
|
1699
|
-
import { randomUUID } from "crypto";
|
|
1700
1700
|
async function compareOptimizationMethods(opts) {
|
|
1701
1701
|
assertOptimizationMethods(opts.methods);
|
|
1702
1702
|
assertComparisonPartitions(opts);
|
|
@@ -1711,20 +1711,22 @@ async function compareOptimizationMethods(opts) {
|
|
|
1711
1711
|
assertComparisonControls(opts, seed, resamples, confidence);
|
|
1712
1712
|
const storage = opts.storage ?? fsCampaignStorage();
|
|
1713
1713
|
const resolvedRunDir = resolveRunDir(opts.runDir, opts.repo);
|
|
1714
|
-
const
|
|
1715
|
-
const
|
|
1714
|
+
const baselineSurface = structuredClone(opts.baselineSurface);
|
|
1715
|
+
const costLedger = opts.costLedger ?? createRunCostLedger({
|
|
1716
1716
|
storage,
|
|
1717
|
-
runDir: `${resolvedRunDir}/
|
|
1717
|
+
runDir: `${resolvedRunDir}/cost`,
|
|
1718
1718
|
costCeilingUsd: opts.costCeiling
|
|
1719
1719
|
});
|
|
1720
|
-
const scoreOnTest = async (surface, tag) => {
|
|
1720
|
+
const scoreOnTest = async (surface, tag, costPhase) => {
|
|
1721
|
+
const measuredSurface = structuredClone(surface);
|
|
1721
1722
|
const campaign = await runCampaign({
|
|
1722
1723
|
...opts,
|
|
1723
1724
|
storage,
|
|
1724
|
-
costLedger
|
|
1725
|
-
costPhase
|
|
1725
|
+
costLedger,
|
|
1726
|
+
costPhase,
|
|
1726
1727
|
scenarios: opts.testScenarios.map((scenario) => structuredClone(scenario)),
|
|
1727
|
-
dispatch: (scenario, ctx) => opts.dispatchWithSurface(
|
|
1728
|
+
dispatch: (scenario, ctx) => opts.dispatchWithSurface(structuredClone(measuredSurface), scenario, ctx),
|
|
1729
|
+
dispatchRef: finalDispatchRef(opts, measuredSurface),
|
|
1728
1730
|
runDir: `${resolvedRunDir}/${tag}`
|
|
1729
1731
|
});
|
|
1730
1732
|
const byScenario = {};
|
|
@@ -1745,22 +1747,40 @@ async function compareOptimizationMethods(opts) {
|
|
|
1745
1747
|
}
|
|
1746
1748
|
return scenarioIds.map((id) => byScenario[id]);
|
|
1747
1749
|
};
|
|
1750
|
+
const optimizationOwner = new AbortController();
|
|
1748
1751
|
const optimized = await mapConcurrent(opts.methods, optimizationConcurrency, async (method) => {
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1752
|
+
try {
|
|
1753
|
+
const out = await method.optimize(
|
|
1754
|
+
createOptimizationMethodInput(
|
|
1755
|
+
opts,
|
|
1756
|
+
method.name,
|
|
1757
|
+
resolvedRunDir,
|
|
1758
|
+
seed,
|
|
1759
|
+
baselineSurface,
|
|
1760
|
+
costLedger,
|
|
1761
|
+
optimizationOwner.signal
|
|
1762
|
+
)
|
|
1763
|
+
);
|
|
1764
|
+
assertOptimizationResult(method.name, out);
|
|
1765
|
+
const winnerSurface = structuredClone(out.winnerSurface);
|
|
1766
|
+
return {
|
|
1767
|
+
name: method.name,
|
|
1768
|
+
winnerSurface,
|
|
1769
|
+
cost: out.cost,
|
|
1770
|
+
durationMs: out.durationMs,
|
|
1771
|
+
provenance: out.provenance
|
|
1772
|
+
};
|
|
1773
|
+
} catch (error) {
|
|
1774
|
+
if (!optimizationOwner.signal.aborted) optimizationOwner.abort(error);
|
|
1775
|
+
throw error;
|
|
1776
|
+
}
|
|
1761
1777
|
});
|
|
1762
|
-
const
|
|
1763
|
-
const
|
|
1778
|
+
const testCostPhase = finalCostPhase(opts, baselineSurface, optimized, seed);
|
|
1779
|
+
const baselineArr = align(
|
|
1780
|
+
await scoreOnTest(baselineSurface, "test/baseline", testCostPhase),
|
|
1781
|
+
"baseline"
|
|
1782
|
+
);
|
|
1783
|
+
const testScoresBySurface = /* @__PURE__ */ new Map([[surfaceContentHash(baselineSurface), baselineArr]]);
|
|
1764
1784
|
const winners = [];
|
|
1765
1785
|
for (const winner of optimized) {
|
|
1766
1786
|
const surfaceKey = surfaceContentHash(winner.winnerSurface);
|
|
@@ -1768,7 +1788,8 @@ async function compareOptimizationMethods(opts) {
|
|
|
1768
1788
|
if (!arr) {
|
|
1769
1789
|
const byScenario = await scoreOnTest(
|
|
1770
1790
|
winner.winnerSurface,
|
|
1771
|
-
`test/methods/${slug(winner.name)}
|
|
1791
|
+
`test/methods/${slug(winner.name)}`,
|
|
1792
|
+
testCostPhase
|
|
1772
1793
|
);
|
|
1773
1794
|
arr = align(byScenario, `method "${winner.name}"`);
|
|
1774
1795
|
testScoresBySurface.set(surfaceKey, arr);
|
|
@@ -1798,7 +1819,7 @@ async function compareOptimizationMethods(opts) {
|
|
|
1798
1819
|
winnerComposite: w.arr[index],
|
|
1799
1820
|
lift: w.arr[index] - baselineArr[index]
|
|
1800
1821
|
})),
|
|
1801
|
-
winnerSurface: w.winnerSurface,
|
|
1822
|
+
winnerSurface: structuredClone(w.winnerSurface),
|
|
1802
1823
|
rank: 0
|
|
1803
1824
|
};
|
|
1804
1825
|
if (w.durationMs !== void 0) score.durationMs = w.durationMs;
|
|
@@ -1843,7 +1864,7 @@ async function compareOptimizationMethods(opts) {
|
|
|
1843
1864
|
const optimizationCost = combineCosts(
|
|
1844
1865
|
scores.map((score) => ({ label: `method '${score.name}'`, cost: score.optimizationCost }))
|
|
1845
1866
|
);
|
|
1846
|
-
const testCost = costFromLedgerSummary(
|
|
1867
|
+
const testCost = costFromLedgerSummary(costLedger.summary({ phase: testCostPhase }));
|
|
1847
1868
|
const totalCost = combineCosts([
|
|
1848
1869
|
{ label: "optimization", cost: optimizationCost },
|
|
1849
1870
|
{ label: "final test", cost: testCost }
|
|
@@ -1961,12 +1982,22 @@ function assertOptimizationProvenance(methodName, value) {
|
|
|
1961
1982
|
}
|
|
1962
1983
|
}
|
|
1963
1984
|
function assertComparisonControls(opts, seed, resamples, confidence) {
|
|
1985
|
+
if (opts.optimizationRunOptions && "costCeiling" in opts.optimizationRunOptions) {
|
|
1986
|
+
throw new Error(
|
|
1987
|
+
"compareOptimizationMethods: optimizationRunOptions.costCeiling is not supported; costCeiling covers optimization and final scoring"
|
|
1988
|
+
);
|
|
1989
|
+
}
|
|
1964
1990
|
if (!opts.judges || opts.judges.length === 0) {
|
|
1965
1991
|
throw new Error("compareOptimizationMethods: at least one judge is required");
|
|
1966
1992
|
}
|
|
1967
1993
|
if (typeof opts.dispatchWithSurface !== "function") {
|
|
1968
1994
|
throw new Error("compareOptimizationMethods: dispatchWithSurface must be a function");
|
|
1969
1995
|
}
|
|
1996
|
+
if (opts.dispatchRef !== void 0 && (typeof opts.dispatchRef !== "string" || opts.dispatchRef.trim().length === 0 || opts.dispatchRef.trim() !== opts.dispatchRef)) {
|
|
1997
|
+
throw new Error(
|
|
1998
|
+
"compareOptimizationMethods: dispatchRef must be trimmed and non-empty when provided"
|
|
1999
|
+
);
|
|
2000
|
+
}
|
|
1970
2001
|
try {
|
|
1971
2002
|
surfaceContentHash(opts.baselineSurface);
|
|
1972
2003
|
} catch (cause) {
|
|
@@ -2112,9 +2143,8 @@ function minimumBootstrapResamples(confidence, comparisonCount) {
|
|
|
2112
2143
|
const exact = 2 * comparisonCount / (1 - confidence);
|
|
2113
2144
|
return Math.ceil(exact - Number.EPSILON * Math.max(1, exact) * 32);
|
|
2114
2145
|
}
|
|
2115
|
-
function createOptimizationMethodInput(opts, methodName, resolvedRunDir, seed) {
|
|
2146
|
+
function createOptimizationMethodInput(opts, methodName, resolvedRunDir, seed, baselineSurface, costLedger, optimizationSignal) {
|
|
2116
2147
|
const methodRunDir = `${resolvedRunDir}/optimization/${slug(methodName)}`;
|
|
2117
|
-
const storage = opts.storage ?? fsCampaignStorage();
|
|
2118
2148
|
const cloneScenarios = (scenarios) => Object.freeze(scenarios.map((scenario) => structuredClone(scenario)));
|
|
2119
2149
|
const judges = opts.judges.map(
|
|
2120
2150
|
(judge) => Object.freeze({
|
|
@@ -2124,21 +2154,53 @@ function createOptimizationMethodInput(opts, methodName, resolvedRunDir, seed) {
|
|
|
2124
2154
|
)
|
|
2125
2155
|
})
|
|
2126
2156
|
);
|
|
2157
|
+
const signal = combineAbortSignals(
|
|
2158
|
+
opts.signal,
|
|
2159
|
+
opts.optimizationRunOptions?.signal,
|
|
2160
|
+
optimizationSignal
|
|
2161
|
+
);
|
|
2127
2162
|
return Object.freeze({
|
|
2128
|
-
baselineSurface: structuredClone(
|
|
2163
|
+
baselineSurface: structuredClone(baselineSurface),
|
|
2129
2164
|
trainScenarios: cloneScenarios(opts.trainScenarios),
|
|
2130
2165
|
selectionScenarios: cloneScenarios(opts.selectionScenarios),
|
|
2131
2166
|
dispatchWithSurface: opts.dispatchWithSurface,
|
|
2132
2167
|
judges: Object.freeze(judges),
|
|
2133
2168
|
runDir: methodRunDir,
|
|
2134
2169
|
seed,
|
|
2135
|
-
runOptions: Object.freeze({
|
|
2136
|
-
|
|
2137
|
-
|
|
2138
|
-
|
|
2139
|
-
|
|
2140
|
-
|
|
2170
|
+
runOptions: Object.freeze({
|
|
2171
|
+
...opts.optimizationRunOptions ?? {},
|
|
2172
|
+
...signal ? { signal } : {}
|
|
2173
|
+
}),
|
|
2174
|
+
costLedger
|
|
2175
|
+
});
|
|
2176
|
+
}
|
|
2177
|
+
function finalCostPhase(opts, baselineSurface, winners, seed) {
|
|
2178
|
+
const identity = contentHash({
|
|
2179
|
+
baseline: surfaceContentHash(baselineSurface),
|
|
2180
|
+
winners: winners.map((winner) => ({
|
|
2181
|
+
name: winner.name,
|
|
2182
|
+
surface: surfaceContentHash(winner.winnerSurface)
|
|
2183
|
+
})),
|
|
2184
|
+
testScenarios: opts.testScenarios,
|
|
2185
|
+
judges: opts.judges.map((judge) => ({
|
|
2186
|
+
name: judge.name,
|
|
2187
|
+
dimensions: judge.dimensions,
|
|
2188
|
+
version: judge.judgeVersion ?? contentHash({
|
|
2189
|
+
score: judge.score.toString(),
|
|
2190
|
+
appliesTo: judge.appliesTo?.toString() ?? null
|
|
2191
|
+
})
|
|
2192
|
+
})),
|
|
2193
|
+
dispatch: callerDispatchRef(opts),
|
|
2194
|
+
seed,
|
|
2195
|
+
reps: opts.reps ?? 1
|
|
2141
2196
|
});
|
|
2197
|
+
return `compareOptimizationMethods.test:${identity}`;
|
|
2198
|
+
}
|
|
2199
|
+
function finalDispatchRef(opts, surface) {
|
|
2200
|
+
return `compareOptimizationMethods:${callerDispatchRef(opts)}:${surfaceContentHash(surface)}`;
|
|
2201
|
+
}
|
|
2202
|
+
function callerDispatchRef(opts) {
|
|
2203
|
+
return (opts.dispatchRef ?? opts.dispatchWithSurface.name) || "anonymous";
|
|
2142
2204
|
}
|
|
2143
2205
|
function costFromLedgerSummary(summary) {
|
|
2144
2206
|
const cost = {
|
|
@@ -2384,6 +2446,7 @@ function sendJson(response, status, body) {
|
|
|
2384
2446
|
var MAX_CALLBACK_BODY_BYTES = 1e6;
|
|
2385
2447
|
async function startExternalOptimizerCallback(args) {
|
|
2386
2448
|
assertCallbackConfig(args);
|
|
2449
|
+
args.signal?.throwIfAborted();
|
|
2387
2450
|
let evaluations = 0;
|
|
2388
2451
|
let accepting = true;
|
|
2389
2452
|
let closePromise;
|
|
@@ -2397,6 +2460,7 @@ async function startExternalOptimizerCallback(args) {
|
|
|
2397
2460
|
const controller = new AbortController();
|
|
2398
2461
|
const abortRequest = () => {
|
|
2399
2462
|
request.destroy();
|
|
2463
|
+
response.destroy();
|
|
2400
2464
|
};
|
|
2401
2465
|
activeControllers.add(controller);
|
|
2402
2466
|
controller.signal.addEventListener("abort", abortRequest, { once: true });
|
|
@@ -2419,16 +2483,23 @@ async function startExternalOptimizerCallback(args) {
|
|
|
2419
2483
|
void handler.catch(() => void 0);
|
|
2420
2484
|
});
|
|
2421
2485
|
const port = await listenLocal(server);
|
|
2486
|
+
const close = () => {
|
|
2487
|
+
closePromise ??= closeCallbackServer();
|
|
2488
|
+
return closePromise;
|
|
2489
|
+
};
|
|
2490
|
+
const onAbort = () => {
|
|
2491
|
+
void close().catch(() => void 0);
|
|
2492
|
+
};
|
|
2493
|
+
args.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2494
|
+
if (args.signal?.aborted) onAbort();
|
|
2422
2495
|
return {
|
|
2423
2496
|
url: `http://127.0.0.1:${port}/evaluate`,
|
|
2424
2497
|
token: args.token,
|
|
2425
2498
|
evaluations: () => evaluations,
|
|
2426
|
-
close
|
|
2427
|
-
closePromise ??= closeCallbackServer();
|
|
2428
|
-
return closePromise;
|
|
2429
|
-
}
|
|
2499
|
+
close
|
|
2430
2500
|
};
|
|
2431
2501
|
async function closeCallbackServer() {
|
|
2502
|
+
args.signal?.removeEventListener("abort", onAbort);
|
|
2432
2503
|
accepting = false;
|
|
2433
2504
|
const closingServer = closeServer(server);
|
|
2434
2505
|
server.closeIdleConnections?.();
|
|
@@ -2525,6 +2596,7 @@ import { createServer as createServer2 } from "http";
|
|
|
2525
2596
|
var MODEL_PROXY_PATHS = /* @__PURE__ */ new Set(["/v1/chat/completions", "/v1/responses"]);
|
|
2526
2597
|
async function startExternalOptimizerModelProxy(args) {
|
|
2527
2598
|
assertModelProxyConfig(args);
|
|
2599
|
+
args.signal?.throwIfAborted();
|
|
2528
2600
|
const token = randomLocalToken();
|
|
2529
2601
|
const fetchImpl = args.fetchImpl ?? fetch;
|
|
2530
2602
|
let requestCount = 0;
|
|
@@ -2544,6 +2616,7 @@ async function startExternalOptimizerModelProxy(args) {
|
|
|
2544
2616
|
const controller = new AbortController();
|
|
2545
2617
|
const abortRequest = () => {
|
|
2546
2618
|
request.destroy();
|
|
2619
|
+
response.destroy();
|
|
2547
2620
|
};
|
|
2548
2621
|
activeControllers.add(controller);
|
|
2549
2622
|
controller.signal.addEventListener("abort", abortRequest, { once: true });
|
|
@@ -2583,17 +2656,24 @@ async function startExternalOptimizerModelProxy(args) {
|
|
|
2583
2656
|
void handler.catch(() => void 0);
|
|
2584
2657
|
});
|
|
2585
2658
|
const port = await listenLocal(server);
|
|
2659
|
+
const close = () => {
|
|
2660
|
+
closePromise ??= closeModelProxy();
|
|
2661
|
+
return closePromise;
|
|
2662
|
+
};
|
|
2663
|
+
const onAbort = () => {
|
|
2664
|
+
void close().catch(() => void 0);
|
|
2665
|
+
};
|
|
2666
|
+
args.signal?.addEventListener("abort", onAbort, { once: true });
|
|
2667
|
+
if (args.signal?.aborted) onAbort();
|
|
2586
2668
|
return {
|
|
2587
2669
|
baseUrl: `http://127.0.0.1:${port}/v1`,
|
|
2588
2670
|
apiKey: token,
|
|
2589
2671
|
requestAttempts: () => requestCount,
|
|
2590
2672
|
successfulCompletions: () => successfulCompletionCount,
|
|
2591
|
-
close
|
|
2592
|
-
closePromise ??= closeModelProxy();
|
|
2593
|
-
return closePromise;
|
|
2594
|
-
}
|
|
2673
|
+
close
|
|
2595
2674
|
};
|
|
2596
2675
|
async function closeModelProxy() {
|
|
2676
|
+
args.signal?.removeEventListener("abort", onAbort);
|
|
2597
2677
|
accepting = false;
|
|
2598
2678
|
const closingServer = closeServer(server);
|
|
2599
2679
|
server.closeIdleConnections?.();
|
|
@@ -3041,6 +3121,7 @@ async function runExternalOptimizerProcess(args) {
|
|
|
3041
3121
|
`${args.label} requires POSIX process-group cleanup; run the optimizer through WSL or Linux`
|
|
3042
3122
|
);
|
|
3043
3123
|
}
|
|
3124
|
+
throwIfAborted(args.signal, args.label);
|
|
3044
3125
|
const dir = await mkdtemp(join2(tmpdir2(), args.tempPrefix));
|
|
3045
3126
|
const inputPath = join2(dir, "input.json");
|
|
3046
3127
|
const outputPath = join2(dir, "output.json");
|
|
@@ -3074,11 +3155,14 @@ async function runExternalOptimizerProcess(args) {
|
|
|
3074
3155
|
args: commandArgs,
|
|
3075
3156
|
cwd: dir,
|
|
3076
3157
|
env: args.runner?.env,
|
|
3077
|
-
timeoutMs: args.timeoutMs
|
|
3158
|
+
timeoutMs: args.timeoutMs,
|
|
3159
|
+
signal: args.signal
|
|
3078
3160
|
});
|
|
3161
|
+
throwIfAborted(args.signal, args.label);
|
|
3079
3162
|
const raw = JSON.parse(
|
|
3080
3163
|
await readBoundedTextFile(outputPath, MAX_PROCESS_RESULT_BYTES, `${args.label} output`)
|
|
3081
3164
|
);
|
|
3165
|
+
throwIfAborted(args.signal, args.label);
|
|
3082
3166
|
if (!isRecord(raw)) throw new Error(`${args.label} output must be a JSON object`);
|
|
3083
3167
|
return raw;
|
|
3084
3168
|
},
|
|
@@ -3106,6 +3190,7 @@ async function readBoundedTextFile(path, maxBytes, label) {
|
|
|
3106
3190
|
}
|
|
3107
3191
|
}
|
|
3108
3192
|
function runProcess(args) {
|
|
3193
|
+
throwIfAborted(args.signal, args.label);
|
|
3109
3194
|
return new Promise((resolvePromise, reject) => {
|
|
3110
3195
|
const child = spawn(args.command, args.args, {
|
|
3111
3196
|
cwd: args.cwd,
|
|
@@ -3118,10 +3203,12 @@ function runProcess(args) {
|
|
|
3118
3203
|
const stderr = createProcessOutputCapture();
|
|
3119
3204
|
let settled = false;
|
|
3120
3205
|
let timeout;
|
|
3206
|
+
const onAbort = () => finish(abortReason(args.signal, args.label));
|
|
3121
3207
|
const finish = (error) => {
|
|
3122
3208
|
if (settled) return;
|
|
3123
3209
|
settled = true;
|
|
3124
3210
|
if (timeout) clearTimeout(timeout);
|
|
3211
|
+
args.signal?.removeEventListener("abort", onAbort);
|
|
3125
3212
|
void terminateProcessTree(child).then(
|
|
3126
3213
|
() => {
|
|
3127
3214
|
if (error) reject(error);
|
|
@@ -3149,6 +3236,8 @@ function runProcess(args) {
|
|
|
3149
3236
|
timeout = setTimeout(() => {
|
|
3150
3237
|
finish(new Error(`${args.label} exceeded ${args.timeoutMs}ms`));
|
|
3151
3238
|
}, args.timeoutMs);
|
|
3239
|
+
args.signal?.addEventListener("abort", onAbort, { once: true });
|
|
3240
|
+
if (args.signal?.aborted) onAbort();
|
|
3152
3241
|
child.stdout.on("data", (chunk) => {
|
|
3153
3242
|
appendProcessOutput(stdout, chunk);
|
|
3154
3243
|
});
|
|
@@ -3171,6 +3260,12 @@ function runProcess(args) {
|
|
|
3171
3260
|
});
|
|
3172
3261
|
});
|
|
3173
3262
|
}
|
|
3263
|
+
function throwIfAborted(signal, label) {
|
|
3264
|
+
if (signal?.aborted) throw abortReason(signal, label);
|
|
3265
|
+
}
|
|
3266
|
+
function abortReason(signal, label) {
|
|
3267
|
+
return signal.reason instanceof Error ? signal.reason : new Error(`${label} aborted`, { cause: signal.reason });
|
|
3268
|
+
}
|
|
3174
3269
|
function safeProcessEnvironment() {
|
|
3175
3270
|
const allowed = [
|
|
3176
3271
|
"PATH",
|
|
@@ -4912,7 +5007,8 @@ async function inspectExternalOptimizerRuntime(args) {
|
|
|
4912
5007
|
engineModules: [...args.engineModules ?? []]
|
|
4913
5008
|
},
|
|
4914
5009
|
...args.runner ? { runner: args.runner } : {},
|
|
4915
|
-
timeoutMs: args.timeoutMs
|
|
5010
|
+
timeoutMs: args.timeoutMs,
|
|
5011
|
+
...args.signal ? { signal: args.signal } : {}
|
|
4916
5012
|
});
|
|
4917
5013
|
assertExternalOptimizerRuntimeIdentity(result.runtime, args.package, args.label);
|
|
4918
5014
|
return result.runtime;
|
|
@@ -5311,6 +5407,8 @@ function gepaOptimizationMethod(config) {
|
|
|
5311
5407
|
return {
|
|
5312
5408
|
name,
|
|
5313
5409
|
async optimize(input) {
|
|
5410
|
+
const signal = input.runOptions.signal;
|
|
5411
|
+
signal?.throwIfAborted();
|
|
5314
5412
|
if (typeof input.baselineSurface !== "string" && input.baselineSurface.kind !== "components") {
|
|
5315
5413
|
throw new Error(`${name}: GEPA bridge supports text and component surfaces`);
|
|
5316
5414
|
}
|
|
@@ -5337,7 +5435,8 @@ function gepaOptimizationMethod(config) {
|
|
|
5337
5435
|
module: "agent_eval_rpc.gepa_bridge",
|
|
5338
5436
|
engineModules: config.engineModules,
|
|
5339
5437
|
...bridgeRunner ? { runner: bridgeRunner } : {},
|
|
5340
|
-
timeoutMs: config.timeoutMs ?? GEPA_DEFAULT_TIMEOUT_MS
|
|
5438
|
+
timeoutMs: config.timeoutMs ?? GEPA_DEFAULT_TIMEOUT_MS,
|
|
5439
|
+
...signal ? { signal } : {}
|
|
5341
5440
|
});
|
|
5342
5441
|
const seedCandidate = encodeExternalTextCandidate(input.baselineSurface);
|
|
5343
5442
|
const trainSet = input.trainScenarios.map(
|
|
@@ -5408,7 +5507,8 @@ function gepaOptimizationMethod(config) {
|
|
|
5408
5507
|
token: randomBytes3(32).toString("hex"),
|
|
5409
5508
|
maxEvaluations: evaluationLimit,
|
|
5410
5509
|
acceptEvaluation: () => runBudget.acceptEvaluation(),
|
|
5411
|
-
evaluate
|
|
5510
|
+
evaluate,
|
|
5511
|
+
...signal ? { signal } : {}
|
|
5412
5512
|
});
|
|
5413
5513
|
const runnerEnv = bridgeRunner?.env ?? {};
|
|
5414
5514
|
let modelProxy;
|
|
@@ -5438,7 +5538,8 @@ function gepaOptimizationMethod(config) {
|
|
|
5438
5538
|
initialUsage: {
|
|
5439
5539
|
requests: priorOptimizerUsage.totalCalls,
|
|
5440
5540
|
costUsd: priorOptimizerUsage.totalCostUsd
|
|
5441
|
-
}
|
|
5541
|
+
},
|
|
5542
|
+
...signal ? { signal } : {}
|
|
5442
5543
|
});
|
|
5443
5544
|
}
|
|
5444
5545
|
const outputDir2 = `${runDir}/external`;
|
|
@@ -5481,12 +5582,14 @@ function gepaOptimizationMethod(config) {
|
|
|
5481
5582
|
...bridgeRunner,
|
|
5482
5583
|
env: removeCredentialEnvironment(runnerEnv)
|
|
5483
5584
|
} : bridgeRunner,
|
|
5484
|
-
timeoutMs: config.timeoutMs ?? GEPA_DEFAULT_TIMEOUT_MS
|
|
5585
|
+
timeoutMs: config.timeoutMs ?? GEPA_DEFAULT_TIMEOUT_MS,
|
|
5586
|
+
...signal ? { signal } : {}
|
|
5485
5587
|
});
|
|
5486
5588
|
return { result: result2, outputDir: outputDir2 };
|
|
5487
5589
|
},
|
|
5488
5590
|
cleanup: closeResources
|
|
5489
5591
|
});
|
|
5592
|
+
signal?.throwIfAborted();
|
|
5490
5593
|
assertGepaBridgeOutput(
|
|
5491
5594
|
result,
|
|
5492
5595
|
name,
|
|
@@ -6840,6 +6943,8 @@ function skillOptOptimizationMethod(config) {
|
|
|
6840
6943
|
return {
|
|
6841
6944
|
name,
|
|
6842
6945
|
async optimize(input) {
|
|
6946
|
+
const signal = input.runOptions.signal;
|
|
6947
|
+
signal?.throwIfAborted();
|
|
6843
6948
|
if (typeof input.baselineSurface !== "string") {
|
|
6844
6949
|
throw new Error(`${name}: SkillOpt requires a string baselineSurface`);
|
|
6845
6950
|
}
|
|
@@ -6861,7 +6966,8 @@ function skillOptOptimizationMethod(config) {
|
|
|
6861
6966
|
package: "skillopt",
|
|
6862
6967
|
module: "agent_eval_rpc.skillopt_bridge",
|
|
6863
6968
|
...bridgeRunner ? { runner: bridgeRunner } : {},
|
|
6864
|
-
timeoutMs: config.timeoutMs ?? SKILLOPT_DEFAULT_TIMEOUT_MS
|
|
6969
|
+
timeoutMs: config.timeoutMs ?? SKILLOPT_DEFAULT_TIMEOUT_MS,
|
|
6970
|
+
...signal ? { signal } : {}
|
|
6865
6971
|
});
|
|
6866
6972
|
const trainSet = input.trainScenarios.map(
|
|
6867
6973
|
(scenario) => describeExternalScenario(scenario, "SkillOpt", maxEvidenceChars, config.describeScenario)
|
|
@@ -6927,7 +7033,8 @@ function skillOptOptimizationMethod(config) {
|
|
|
6927
7033
|
token: randomBytes4(32).toString("hex"),
|
|
6928
7034
|
maxEvaluations: config.maxEvaluations,
|
|
6929
7035
|
acceptEvaluation: () => runBudget.acceptEvaluation(),
|
|
6930
|
-
evaluate
|
|
7036
|
+
evaluate,
|
|
7037
|
+
...signal ? { signal } : {}
|
|
6931
7038
|
});
|
|
6932
7039
|
const runnerEnv = bridgeRunner?.env ?? {};
|
|
6933
7040
|
let activeModelProxy;
|
|
@@ -6956,7 +7063,8 @@ function skillOptOptimizationMethod(config) {
|
|
|
6956
7063
|
initialUsage: {
|
|
6957
7064
|
requests: priorOptimizerUsage.totalCalls,
|
|
6958
7065
|
costUsd: priorOptimizerUsage.totalCostUsd
|
|
6959
|
-
}
|
|
7066
|
+
},
|
|
7067
|
+
...signal ? { signal } : {}
|
|
6960
7068
|
});
|
|
6961
7069
|
activeModelProxy = modelProxy2;
|
|
6962
7070
|
const outputDir2 = `${runDir}/external`;
|
|
@@ -6998,15 +7106,29 @@ function skillOptOptimizationMethod(config) {
|
|
|
6998
7106
|
OPTIMIZER_OPENAI_COMPATIBLE_BASE_URL: modelProxy2.baseUrl,
|
|
6999
7107
|
OPTIMIZER_OPENAI_COMPATIBLE_API_KEY: modelProxy2.apiKey,
|
|
7000
7108
|
TARGET_OPENAI_COMPATIBLE_BASE_URL: modelProxy2.baseUrl,
|
|
7001
|
-
TARGET_OPENAI_COMPATIBLE_API_KEY: modelProxy2.apiKey
|
|
7109
|
+
TARGET_OPENAI_COMPATIBLE_API_KEY: modelProxy2.apiKey,
|
|
7110
|
+
OPENAI_COMPATIBLE_MODEL: config.optimizer.model,
|
|
7111
|
+
OPENAI_COMPATIBLE_MAX_TOKENS: String(
|
|
7112
|
+
config.optimizer.budget.maxOutputTokensPerRequest
|
|
7113
|
+
),
|
|
7114
|
+
OPTIMIZER_OPENAI_COMPATIBLE_MODEL: config.optimizer.model,
|
|
7115
|
+
OPTIMIZER_OPENAI_COMPATIBLE_MAX_TOKENS: String(
|
|
7116
|
+
config.optimizer.budget.maxOutputTokensPerRequest
|
|
7117
|
+
),
|
|
7118
|
+
TARGET_OPENAI_COMPATIBLE_MODEL: config.optimizer.model,
|
|
7119
|
+
TARGET_OPENAI_COMPATIBLE_MAX_TOKENS: String(
|
|
7120
|
+
config.optimizer.budget.maxOutputTokensPerRequest
|
|
7121
|
+
)
|
|
7002
7122
|
}
|
|
7003
7123
|
},
|
|
7004
|
-
timeoutMs: config.timeoutMs ?? SKILLOPT_DEFAULT_TIMEOUT_MS
|
|
7124
|
+
timeoutMs: config.timeoutMs ?? SKILLOPT_DEFAULT_TIMEOUT_MS,
|
|
7125
|
+
...signal ? { signal } : {}
|
|
7005
7126
|
});
|
|
7006
7127
|
return { result: result2, outputDir: outputDir2, modelProxy: modelProxy2 };
|
|
7007
7128
|
},
|
|
7008
7129
|
cleanup: closeResources
|
|
7009
7130
|
});
|
|
7131
|
+
signal?.throwIfAborted();
|
|
7010
7132
|
assertSkillOptBridgeOutput(result, name, maxCandidateChars, config.maxEvaluations);
|
|
7011
7133
|
assertExternalOptimizerRunBinding({
|
|
7012
7134
|
label: name,
|
|
@@ -7149,4 +7271,4 @@ export {
|
|
|
7149
7271
|
emitLoopProvenance,
|
|
7150
7272
|
skillOptOptimizationMethod
|
|
7151
7273
|
};
|
|
7152
|
-
//# sourceMappingURL=chunk-
|
|
7274
|
+
//# sourceMappingURL=chunk-VMUENW6F.js.map
|