The Open Framework for Building Agents
import { defineEval } from "eve/evals";
const MARKER = "authorized-response-oauth-e2e-R8N5";
const TOOL_NAME = "oauth-authorized-gate";
export default defineEval({
tags: ["real-model"],
description: "Approval response policy parks for fake OAuth, resumes, and settles.",
async test(t) {
const { session } = await t.send(`Call the \`${TOOL_NAME}\` tool with marker "${MARKER}".`);
const approval = session.requireInputRequest({ display: "confirmation", toolName: TOOL_NAME });
const approvalTurn = await session.startRespond([
{
optionId: "approve",
requestId: approval.requestId,
},
]);
const required = await approvalTurn.waitForEvent("authorization.required");
if (
required?.type !== "authorization.required" ||
required.data.authorization?.url === undefined
) {
throw new Error("Expected a fake OAuth authorization URL.");
}
const callbackUrl = new URL(required.data.authorization.url);
if (callbackUrl.origin !== new URL(t.target.url).origin) {
throw new Error("Fixture OAuth callback targeted an unexpected origin.");
}
// The responder's sign-in holds the turn, so this read stops there; the
// callback resumes the same turn.
const held = await approvalTurn.result();
held.event("approval.candidate", {
data: { outcome: "pending", requestId: approval.requestId },
count: 1,
});
held.event("authorization.required", { count: 1 });
held.event("turn.waiting", { data: { on: "input" } });
const resumedTurn = t.target.watchTurn(held.sessionId, {
startIndex: held.session.state.streamIndex,
});
const callback = await t.target.fetch(`${callbackUrl.pathname}${callbackUrl.search}`);
if (!callback.ok) {
throw new Error(
`Fixture OAuth callback failed (${String(callback.status)}): ${await callback.text()}`,
);
}
const resumed = await resumedTurn.result();
resumed.expectOk();
resumed.event("authorization.completed", {
data: { candidateId: required.data.candidateId, outcome: "authorized" },
count: 1,
});
resumed.event("approval.settled", {
data: { outcome: "approved", requestId: approval.requestId },
count: 1,
});
resumed.event("action.result", {
data: {
result: {
kind: "tool-result",
output: new RegExp(MARKER),
toolName: TOOL_NAME,
},
status: "completed",
},
count: 1,
});
t.succeeded();
},
});