@springbrand/agent-runtime 0.1.2 → 0.1.3-alpha.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/package.json +1 -1
- package/src/pi/tool/core-host.ts +4 -0
- package/src/pi/tool/core.ts +28 -1
package/package.json
CHANGED
package/src/pi/tool/core-host.ts
CHANGED
|
@@ -14,6 +14,8 @@ import type { PiToolCandidate } from "./compiler";
|
|
|
14
14
|
|
|
15
15
|
// 本文件沿用 `../../index.ts` 入口定义的 Workspace、Port 和 Tool Candidate 术语。
|
|
16
16
|
|
|
17
|
+
const CODEMODE_SANDBOX_TIMEOUT_MS = 55_000;
|
|
18
|
+
|
|
17
19
|
/**
|
|
18
20
|
* 把宿主的 Worker Loader、出站网络和 Workspace 组装成 Pi 代码执行工具候选项。
|
|
19
21
|
*
|
|
@@ -32,6 +34,8 @@ export function workspaceCodeExecutionPiToolCandidate(options: {
|
|
|
32
34
|
executor: new DynamicWorkerExecutor({
|
|
33
35
|
loader: options.loader,
|
|
34
36
|
globalOutbound: options.outbound,
|
|
37
|
+
// 先于外层 60s 截止结束,给 Runtime RPC 结算和 Worker 释放留出时间。
|
|
38
|
+
timeout: CODEMODE_SANDBOX_TIMEOUT_MS,
|
|
35
39
|
}),
|
|
36
40
|
connectors: [
|
|
37
41
|
new StateConnector(
|
package/src/pi/tool/core.ts
CHANGED
|
@@ -205,6 +205,7 @@ const executeParameters = Type.Object({
|
|
|
205
205
|
"Plain JavaScript async function. TypeScript annotations are not supported.",
|
|
206
206
|
}),
|
|
207
207
|
});
|
|
208
|
+
const CODEMODE_EXECUTE_TIMEOUT_MS = 60_000;
|
|
208
209
|
|
|
209
210
|
/**
|
|
210
211
|
* 把 Cloudflare Codemode Runtime handle 包装为高风险 Pi 代码执行工具候选项。
|
|
@@ -235,7 +236,33 @@ export function codeExecutionPiToolCandidate(
|
|
|
235
236
|
// 必须通过 Runtime handle 而不是直接调用 executor,因为 Cloudflare Codemode 把重放、审批和执行日志放在持久化 Runtime 层。
|
|
236
237
|
async execute(_toolCallId, input, signal) {
|
|
237
238
|
signal?.throwIfAborted();
|
|
238
|
-
|
|
239
|
+
// ponytail: 外层截止只保证 Agent 继续;Codemode 支持 AbortSignal 或宿主 dispose 后再终止底层执行。
|
|
240
|
+
let timeout: ReturnType<typeof setTimeout> | undefined;
|
|
241
|
+
const deadline = new Promise<{
|
|
242
|
+
status: "error";
|
|
243
|
+
code: "timeout";
|
|
244
|
+
error: string;
|
|
245
|
+
retryable: false;
|
|
246
|
+
outcome: "unknown";
|
|
247
|
+
}>((resolve) => {
|
|
248
|
+
timeout = setTimeout(() => resolve({
|
|
249
|
+
status: "error",
|
|
250
|
+
code: "timeout",
|
|
251
|
+
error:
|
|
252
|
+
`Code Mode execute exceeded ${CODEMODE_EXECUTE_TIMEOUT_MS} ms; ` +
|
|
253
|
+
"use existing results and state the missing evidence.",
|
|
254
|
+
retryable: false,
|
|
255
|
+
outcome: "unknown",
|
|
256
|
+
}), CODEMODE_EXECUTE_TIMEOUT_MS);
|
|
257
|
+
});
|
|
258
|
+
try {
|
|
259
|
+
return result(await Promise.race([
|
|
260
|
+
runtime.execute(input),
|
|
261
|
+
deadline,
|
|
262
|
+
]));
|
|
263
|
+
} finally {
|
|
264
|
+
if (timeout !== undefined) clearTimeout(timeout);
|
|
265
|
+
}
|
|
239
266
|
},
|
|
240
267
|
};
|
|
241
268
|
return {
|