mirror of
https://github.com/getpaseo/paseo.git
synced 2026-12-03 21:56:41 +00:00
Compare commits
4
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
9f9fcd3aae | ||
|
|
f6600a003b | ||
|
|
4c56e94c3c | ||
|
|
bdb94d917e |
@@ -2537,6 +2537,135 @@ describe("Codex app-server provider", () => {
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("offers the persistence choices from a Codex MCP elicitation and returns the selected one", async () => {
|
||||
const appServer = createFakeCodexAppServer();
|
||||
const session = new CodexAppServerAgentSession(
|
||||
createConfig({ cwd: "/workspace/project" }),
|
||||
null,
|
||||
createTestLogger(),
|
||||
async () => appServer.child,
|
||||
);
|
||||
|
||||
await session.connect();
|
||||
const permissionRequested = waitForNextPermission(session);
|
||||
appServer.requestMcpElicitation({
|
||||
threadId: "thread-1",
|
||||
turnId: "turn-1",
|
||||
serverName: "computer-use",
|
||||
message: "Allow Computer Use to use Safari?",
|
||||
requestedSchema: { type: "object", properties: {} },
|
||||
_meta: { connector_id: "computer-use", persist: ["session", "always", "forever"] },
|
||||
});
|
||||
|
||||
const permission = await permissionRequested;
|
||||
expect(permission.request.actions).toEqual([
|
||||
{ id: "deny", label: "Deny", behavior: "deny", variant: "danger", intent: "dismiss" },
|
||||
{
|
||||
id: "mcp_persist_session",
|
||||
label: "Allow for this session",
|
||||
behavior: "allow",
|
||||
variant: "secondary",
|
||||
},
|
||||
{ id: "mcp_persist_always", label: "Always allow", behavior: "allow", variant: "secondary" },
|
||||
{ id: "allow_once", label: "Allow once", behavior: "allow", variant: "primary" },
|
||||
]);
|
||||
await session.respondToPermission(permission.request.id, {
|
||||
behavior: "allow",
|
||||
selectedActionId: "mcp_persist_always",
|
||||
});
|
||||
|
||||
await expect(appServer.waitForMcpElicitationDecision()).resolves.toEqual({
|
||||
action: "accept",
|
||||
content: {},
|
||||
_meta: { persist: "always" },
|
||||
});
|
||||
appServer.resolvesMcpElicitation();
|
||||
appServer.assertNoErrors();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("offers a single persistence choice from a Codex MCP elicitation", async () => {
|
||||
const appServer = createFakeCodexAppServer();
|
||||
const session = new CodexAppServerAgentSession(
|
||||
createConfig({ cwd: "/workspace/project" }),
|
||||
null,
|
||||
createTestLogger(),
|
||||
async () => appServer.child,
|
||||
);
|
||||
|
||||
await session.connect();
|
||||
const permissionRequested = waitForNextPermission(session);
|
||||
appServer.requestMcpElicitation({
|
||||
threadId: "thread-1",
|
||||
turnId: "turn-1",
|
||||
serverName: "computer-use",
|
||||
message: "Allow Computer Use to use Safari?",
|
||||
requestedSchema: { type: "object", properties: {} },
|
||||
_meta: { connector_id: "computer-use", persist: "session" },
|
||||
});
|
||||
|
||||
const permission = await permissionRequested;
|
||||
expect(permission.request.actions).toEqual([
|
||||
{ id: "deny", label: "Deny", behavior: "deny", variant: "danger", intent: "dismiss" },
|
||||
{
|
||||
id: "mcp_persist_session",
|
||||
label: "Allow for this session",
|
||||
behavior: "allow",
|
||||
variant: "secondary",
|
||||
},
|
||||
{ id: "allow_once", label: "Allow once", behavior: "allow", variant: "primary" },
|
||||
]);
|
||||
await session.respondToPermission(permission.request.id, {
|
||||
behavior: "allow",
|
||||
selectedActionId: "mcp_persist_session",
|
||||
});
|
||||
|
||||
await expect(appServer.waitForMcpElicitationDecision()).resolves.toEqual({
|
||||
action: "accept",
|
||||
content: {},
|
||||
_meta: { persist: "session" },
|
||||
});
|
||||
appServer.resolvesMcpElicitation();
|
||||
appServer.assertNoErrors();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("replies without persistence when the user allows a Codex MCP elicitation once", async () => {
|
||||
const appServer = createFakeCodexAppServer();
|
||||
const session = new CodexAppServerAgentSession(
|
||||
createConfig({ cwd: "/workspace/project" }),
|
||||
null,
|
||||
createTestLogger(),
|
||||
async () => appServer.child,
|
||||
);
|
||||
|
||||
await session.connect();
|
||||
const permissionRequested = waitForNextPermission(session);
|
||||
appServer.requestMcpElicitation({
|
||||
threadId: "thread-1",
|
||||
turnId: "turn-1",
|
||||
serverName: "computer-use",
|
||||
message: "Allow Computer Use to use Safari?",
|
||||
requestedSchema: { type: "object", properties: {} },
|
||||
_meta: { connector_id: "computer-use", persist: ["session", "always"] },
|
||||
});
|
||||
|
||||
const permission = await permissionRequested;
|
||||
await session.respondToPermission(permission.request.id, {
|
||||
behavior: "allow",
|
||||
selectedActionId: "allow_once",
|
||||
});
|
||||
|
||||
await expect(appServer.waitForMcpElicitationDecision()).resolves.toEqual({
|
||||
action: "accept",
|
||||
content: {},
|
||||
_meta: null,
|
||||
});
|
||||
appServer.resolvesMcpElicitation();
|
||||
appServer.assertNoErrors();
|
||||
await session.close();
|
||||
});
|
||||
|
||||
test("initializes Codex app-server without making Paseo the request originator", async () => {
|
||||
let initializeParams: unknown;
|
||||
const appServer = createFakeCodexAppServer({
|
||||
|
||||
@@ -716,6 +716,63 @@ function decodeEscapedChar(next: string): string {
|
||||
return next;
|
||||
}
|
||||
|
||||
type CodexMcpElicitationPersistOption = "session" | "always";
|
||||
|
||||
const CODEX_MCP_PERSIST_ACTIONS: ReadonlyArray<{
|
||||
option: CodexMcpElicitationPersistOption;
|
||||
id: string;
|
||||
label: string;
|
||||
}> = [
|
||||
{ option: "session", id: "mcp_persist_session", label: "Allow for this session" },
|
||||
{ option: "always", id: "mcp_persist_always", label: "Always allow" },
|
||||
];
|
||||
|
||||
// Codex offers persistence choices for an MCP approval through `_meta.persist`.
|
||||
// Keep only the choices Paseo can label; ignore unknown values.
|
||||
function readCodexMcpElicitationPersistOptions(meta: unknown): CodexMcpElicitationPersistOption[] {
|
||||
const persist = toObjectRecord(meta)?.persist;
|
||||
const offered = Array.isArray(persist) ? persist : [persist];
|
||||
return CODEX_MCP_PERSIST_ACTIONS.filter((action) => offered.includes(action.option)).map(
|
||||
(action) => action.option,
|
||||
);
|
||||
}
|
||||
|
||||
function buildCodexMcpElicitationActions(
|
||||
options: CodexMcpElicitationPersistOption[],
|
||||
): AgentPermissionAction[] {
|
||||
return [
|
||||
{ id: "deny", label: "Deny", behavior: "deny", variant: "danger", intent: "dismiss" },
|
||||
...CODEX_MCP_PERSIST_ACTIONS.filter((action) => options.includes(action.option)).map(
|
||||
(action): AgentPermissionAction => ({
|
||||
id: action.id,
|
||||
label: action.label,
|
||||
behavior: "allow",
|
||||
variant: "secondary",
|
||||
}),
|
||||
),
|
||||
{ id: "allow_once", label: "Allow once", behavior: "allow", variant: "primary" },
|
||||
];
|
||||
}
|
||||
|
||||
function resolveCodexMcpElicitationMeta({
|
||||
response,
|
||||
options,
|
||||
}: {
|
||||
response: AgentPermissionResponse;
|
||||
options: CodexMcpElicitationPersistOption[] | undefined;
|
||||
}): { persist: CodexMcpElicitationPersistOption } | null {
|
||||
if (response.behavior !== "allow" || !options) {
|
||||
return null;
|
||||
}
|
||||
const action = CODEX_MCP_PERSIST_ACTIONS.find(
|
||||
(candidate) => candidate.id === response.selectedActionId,
|
||||
);
|
||||
if (!action || !options.includes(action.option)) {
|
||||
return null;
|
||||
}
|
||||
return { persist: action.option };
|
||||
}
|
||||
|
||||
function resolvePermissionDecision(
|
||||
response: AgentPermissionResponse,
|
||||
): "accept" | "cancel" | "decline" {
|
||||
@@ -3808,6 +3865,7 @@ interface CodexPendingPermissionHandler {
|
||||
kind: "command" | "file" | "question" | "mcp_elicitation" | "plan";
|
||||
questions?: CodexQuestionPrompt[];
|
||||
plan?: { text: string; turnId: string | undefined };
|
||||
mcpPersistOptions?: CodexMcpElicitationPersistOption[];
|
||||
}
|
||||
|
||||
interface ConsumedRootCompaction {
|
||||
@@ -5343,7 +5401,10 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
pending.resolve({
|
||||
action: resolvePermissionDecision(response),
|
||||
content: response.behavior === "allow" ? {} : null,
|
||||
_meta: null,
|
||||
_meta: resolveCodexMcpElicitationMeta({
|
||||
response,
|
||||
options: pending.mcpPersistOptions,
|
||||
}),
|
||||
});
|
||||
return;
|
||||
}
|
||||
@@ -8185,6 +8246,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
requestedSchema: z.unknown().optional(),
|
||||
url: z.string().optional(),
|
||||
elicitationId: z.string().optional(),
|
||||
_meta: z.unknown().optional(),
|
||||
})
|
||||
.parse(params);
|
||||
if (parsed.mode === "url") {
|
||||
@@ -8194,6 +8256,7 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
if (Array.isArray(requiredFields) && requiredFields.length > 0) {
|
||||
return Promise.resolve({ action: "decline", content: null, _meta: null });
|
||||
}
|
||||
const persistOptions = readCodexMcpElicitationPersistOptions(parsed._meta);
|
||||
const requestId = `permission-${randomUUID()}`;
|
||||
const request: AgentPermissionRequest = {
|
||||
id: requestId,
|
||||
@@ -8213,12 +8276,19 @@ export class CodexAppServerAgentSession implements AgentSession {
|
||||
serverName: parsed.serverName,
|
||||
elicitationId: parsed.elicitationId ?? null,
|
||||
},
|
||||
...(persistOptions.length > 0
|
||||
? { actions: buildCodexMcpElicitationActions(persistOptions) }
|
||||
: {}),
|
||||
};
|
||||
this.pendingPermissions.set(requestId, request);
|
||||
this.mcpElicitationPermissionIds.set(serverRequestId, requestId);
|
||||
this.emitEvent({ type: "permission_requested", provider: CODEX_PROVIDER, request });
|
||||
return new Promise((resolve) => {
|
||||
this.pendingPermissionHandlers.set(requestId, { resolve, kind: "mcp_elicitation" });
|
||||
this.pendingPermissionHandlers.set(requestId, {
|
||||
resolve,
|
||||
kind: "mcp_elicitation",
|
||||
...(persistOptions.length > 0 ? { mcpPersistOptions: persistOptions } : {}),
|
||||
});
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -141,6 +141,7 @@ export interface FakeCodexAppServer {
|
||||
serverName: string;
|
||||
message: string;
|
||||
requestedSchema: Record<string, unknown>;
|
||||
_meta?: Record<string, unknown> | null;
|
||||
}): void;
|
||||
waitForMcpElicitationDecision(): Promise<unknown>;
|
||||
resolvesMcpElicitation(): void;
|
||||
@@ -679,7 +680,7 @@ export function createFakeCodexAppServer(
|
||||
params: {
|
||||
...params,
|
||||
mode: "openai/form",
|
||||
_meta: null,
|
||||
_meta: params._meta ?? null,
|
||||
},
|
||||
})}\n`,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user