@liy/agent-runner 0.2.0 → 0.2.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/dist/bin/agent-runner.js +67 -1
- package/dist/bin/agent-runner.js.map +2 -2
- package/dist/index.js +67 -1
- package/dist/index.js.map +2 -2
- package/package.json +13 -13
package/dist/index.js
CHANGED
|
@@ -15682,6 +15682,7 @@ function buildPiRpcArgs(harness) {
|
|
|
15682
15682
|
model,
|
|
15683
15683
|
"--thinking",
|
|
15684
15684
|
thinking,
|
|
15685
|
+
"--no-session",
|
|
15685
15686
|
"--no-extensions",
|
|
15686
15687
|
"--no-prompt-templates",
|
|
15687
15688
|
"--no-themes",
|
|
@@ -15897,6 +15898,7 @@ async function runTaskAgentRunner(spec, options = {}) {
|
|
|
15897
15898
|
spec,
|
|
15898
15899
|
harness,
|
|
15899
15900
|
channel,
|
|
15901
|
+
...spec.timeouts?.taskMs !== void 0 ? { timeoutMs: spec.timeouts.taskMs } : {},
|
|
15900
15902
|
...options.env ? { env: options.env } : {}
|
|
15901
15903
|
});
|
|
15902
15904
|
sendTaskStatus(channel, {
|
|
@@ -16034,7 +16036,28 @@ async function runHarnessAndReadCompletion(input) {
|
|
|
16034
16036
|
...input.env ? { env: input.env } : {}
|
|
16035
16037
|
})
|
|
16036
16038
|
});
|
|
16037
|
-
const result = await
|
|
16039
|
+
const result = await waitForHarnessResult({
|
|
16040
|
+
run: activeRun,
|
|
16041
|
+
...input.timeoutMs !== void 0 ? { timeoutMs: input.timeoutMs } : {}
|
|
16042
|
+
});
|
|
16043
|
+
if (result === "timeout") {
|
|
16044
|
+
activeRun.cancel();
|
|
16045
|
+
await waitForHarnessCleanup(activeRun.result);
|
|
16046
|
+
const recovered = await readTaskCompletion(paths).catch(() => void 0);
|
|
16047
|
+
if (recovered) {
|
|
16048
|
+
await validateTaskArtifactFiles({
|
|
16049
|
+
paths,
|
|
16050
|
+
completion: recovered
|
|
16051
|
+
});
|
|
16052
|
+
return recovered;
|
|
16053
|
+
}
|
|
16054
|
+
const completion2 = createTimeoutCompletion(input.timeoutMs);
|
|
16055
|
+
await writeTaskCompletion({
|
|
16056
|
+
paths,
|
|
16057
|
+
completion: completion2
|
|
16058
|
+
});
|
|
16059
|
+
return completion2;
|
|
16060
|
+
}
|
|
16038
16061
|
if (cancelRequested) {
|
|
16039
16062
|
const completion2 = {
|
|
16040
16063
|
status: "cancelled",
|
|
@@ -16064,6 +16087,38 @@ async function runHarnessAndReadCompletion(input) {
|
|
|
16064
16087
|
}
|
|
16065
16088
|
return completion;
|
|
16066
16089
|
}
|
|
16090
|
+
async function waitForHarnessResult(input) {
|
|
16091
|
+
const timeoutMs = normalizeTimeoutMs(input.timeoutMs);
|
|
16092
|
+
if (timeoutMs === void 0) {
|
|
16093
|
+
return input.run.result;
|
|
16094
|
+
}
|
|
16095
|
+
let timer;
|
|
16096
|
+
try {
|
|
16097
|
+
return await Promise.race([
|
|
16098
|
+
input.run.result,
|
|
16099
|
+
new Promise((resolve) => {
|
|
16100
|
+
timer = setTimeout(() => resolve("timeout"), timeoutMs);
|
|
16101
|
+
})
|
|
16102
|
+
]);
|
|
16103
|
+
} finally {
|
|
16104
|
+
if (timer) {
|
|
16105
|
+
clearTimeout(timer);
|
|
16106
|
+
}
|
|
16107
|
+
}
|
|
16108
|
+
}
|
|
16109
|
+
async function waitForHarnessCleanup(result) {
|
|
16110
|
+
await Promise.race([
|
|
16111
|
+
result.catch(() => void 0),
|
|
16112
|
+
sleep(1e4)
|
|
16113
|
+
]);
|
|
16114
|
+
}
|
|
16115
|
+
function createTimeoutCompletion(timeoutMs) {
|
|
16116
|
+
return {
|
|
16117
|
+
status: "failed",
|
|
16118
|
+
summary: timeoutMs === void 0 ? "execute_task harness timed out" : `execute_task harness timed out after ${timeoutMs}ms`,
|
|
16119
|
+
artifactIds: []
|
|
16120
|
+
};
|
|
16121
|
+
}
|
|
16067
16122
|
function createMissingCompletionFailure(error48) {
|
|
16068
16123
|
const detail = error48 instanceof Error ? error48.message : String(error48);
|
|
16069
16124
|
return {
|
|
@@ -16085,6 +16140,9 @@ function validateRunnerSpec(spec) {
|
|
|
16085
16140
|
if (!spec.rpcUrl?.trim()) {
|
|
16086
16141
|
throw new Error("task spec rpcUrl is required");
|
|
16087
16142
|
}
|
|
16143
|
+
if (spec.timeouts?.taskMs !== void 0 && normalizeTimeoutMs(spec.timeouts.taskMs) === void 0) {
|
|
16144
|
+
throw new Error("task spec timeouts.taskMs must be a positive finite number");
|
|
16145
|
+
}
|
|
16088
16146
|
if (spec.agentRunner?.harness !== void 0 && typeof spec.agentRunner.harness !== "string") {
|
|
16089
16147
|
throw new Error("task spec agentRunner.harness must be a string");
|
|
16090
16148
|
}
|
|
@@ -16097,6 +16155,14 @@ function validateRunnerSpec(spec) {
|
|
|
16097
16155
|
}
|
|
16098
16156
|
assertNoForbiddenSpecKeys(spec);
|
|
16099
16157
|
}
|
|
16158
|
+
function normalizeTimeoutMs(value) {
|
|
16159
|
+
return typeof value === "number" && Number.isFinite(value) && value > 0 ? value : void 0;
|
|
16160
|
+
}
|
|
16161
|
+
function sleep(ms) {
|
|
16162
|
+
return new Promise((resolve) => {
|
|
16163
|
+
setTimeout(resolve, ms);
|
|
16164
|
+
});
|
|
16165
|
+
}
|
|
16100
16166
|
async function openControlChannel(url2) {
|
|
16101
16167
|
const WebSocketCtor = globalThis.WebSocket;
|
|
16102
16168
|
if (!WebSocketCtor) {
|