Merge 0564482aba into 09be5d45d5
This commit is contained in:
commit
3aa93fc5b1
@ -423,17 +423,71 @@ export function createNodesTool(options?: {
|
|||||||
typeof params.needsScreenRecording === "boolean"
|
typeof params.needsScreenRecording === "boolean"
|
||||||
? params.needsScreenRecording
|
? params.needsScreenRecording
|
||||||
: undefined;
|
: undefined;
|
||||||
|
const runParams = {
|
||||||
|
command,
|
||||||
|
cwd,
|
||||||
|
env,
|
||||||
|
timeoutMs: commandTimeoutMs,
|
||||||
|
needsScreenRecording,
|
||||||
|
agentId,
|
||||||
|
sessionKey,
|
||||||
|
};
|
||||||
|
|
||||||
|
// First attempt without approval flags.
|
||||||
|
try {
|
||||||
|
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
|
||||||
|
nodeId,
|
||||||
|
command: "system.run",
|
||||||
|
params: runParams,
|
||||||
|
timeoutMs: invokeTimeoutMs,
|
||||||
|
idempotencyKey: crypto.randomUUID(),
|
||||||
|
})) as { payload?: unknown };
|
||||||
|
return jsonResult(raw?.payload ?? {});
|
||||||
|
} catch (firstErr) {
|
||||||
|
const msg = firstErr instanceof Error ? firstErr.message : String(firstErr);
|
||||||
|
if (!msg.includes("SYSTEM_RUN_DENIED: approval required")) {
|
||||||
|
throw firstErr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Node requires approval – create a pending approval request on
|
||||||
|
// the gateway and wait for the user to approve/deny via the UI.
|
||||||
|
const APPROVAL_TIMEOUT_MS = 120_000;
|
||||||
|
const cmdText = command.join(" ");
|
||||||
|
const approvalResult = (await callGatewayTool(
|
||||||
|
"exec.approval.request",
|
||||||
|
{ ...gatewayOpts, timeoutMs: APPROVAL_TIMEOUT_MS + 5_000 },
|
||||||
|
{
|
||||||
|
command: cmdText,
|
||||||
|
cwd,
|
||||||
|
host: "node",
|
||||||
|
agentId,
|
||||||
|
sessionKey,
|
||||||
|
timeoutMs: APPROVAL_TIMEOUT_MS,
|
||||||
|
},
|
||||||
|
)) as { decision?: string; id?: string } | null;
|
||||||
|
|
||||||
|
const decision =
|
||||||
|
approvalResult && typeof approvalResult === "object"
|
||||||
|
? (approvalResult.decision ?? null)
|
||||||
|
: null;
|
||||||
|
|
||||||
|
if (!decision || decision === "deny") {
|
||||||
|
throw new Error(
|
||||||
|
decision === "deny"
|
||||||
|
? "exec denied: user denied"
|
||||||
|
: "exec denied: approval timed out",
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Retry with the approval decision.
|
||||||
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
|
const raw = (await callGatewayTool("node.invoke", gatewayOpts, {
|
||||||
nodeId,
|
nodeId,
|
||||||
command: "system.run",
|
command: "system.run",
|
||||||
params: {
|
params: {
|
||||||
command,
|
...runParams,
|
||||||
cwd,
|
approved: true,
|
||||||
env,
|
approvalDecision: decision,
|
||||||
timeoutMs: commandTimeoutMs,
|
|
||||||
needsScreenRecording,
|
|
||||||
agentId,
|
|
||||||
sessionKey,
|
|
||||||
},
|
},
|
||||||
timeoutMs: invokeTimeoutMs,
|
timeoutMs: invokeTimeoutMs,
|
||||||
idempotencyKey: crypto.randomUUID(),
|
idempotencyKey: crypto.randomUUID(),
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user