The Open Framework for Building Agents
import { defineEval } from "eve/evals";
import { NESTED_AUTHORIZATION } from "../agent/lib/remote-nested-script.js";
const AUTHORIZATION_CODE = "nested-release-code";
const AUTHORIZATION_NAME = "nested-release-authorization";
export default defineEval({
description:
"Alice completes a nested worker's authorization callback through the remote parent.",
timeoutMs: 120_000,
async test(t) {
const session = await t.session();
const live = await session.start(
`${NESTED_AUTHORIZATION}: Alice asks the remote agent to authorize her release checklist.`,
);
// The nested worker's sign-in holds the parent's turn, so the response stops there.
const held = await live.result();
const required = held.events.find((event) => event.type === "authorization.required");
if (required?.type !== "authorization.required" || required.data.webhookUrl === undefined) {
throw new Error("Nested authorization challenge has no callback URL.");
}
held.event("turn.waiting", { data: { on: "input" } });
held.event("authorization.required", {
data: { name: AUTHORIZATION_NAME, authorization: { userCode: AUTHORIZATION_CODE } },
});
const resumed = t.target.watchTurn(live.session.sessionId, {
startIndex: live.session.state?.streamIndex,
});
const callback = new URL(required.data.webhookUrl);
callback.searchParams.set("code", AUTHORIZATION_CODE);
const response = await t.target.fetch(`${callback.pathname}${callback.search}`);
if (!response.ok) throw new Error(`Nested authorization callback returned ${response.status}.`);
const turn = await resumed.result();
turn.expectOk();
turn.notEvent("turn.started");
turn.event("authorization.completed", {
data: { name: AUTHORIZATION_NAME, outcome: "authorized" },
});
if (!turn.message?.includes("PARENT-NESTED-COMPLETE: CHILD-NESTED-AUTHORIZATION-COMPLETE")) {
throw new Error("Nested authorization result did not reach the parent.");
}
t.noFailedActions();
},
});