mirror of
https://github.com/stablyai/orca.git
synced 2026-11-04 19:17:28 +00:00
Codex native chat shows the existing approval card for MCP tool-call approvals (form-mode elicitations with no fields) instead of auto-declining them; Deny sends Codex's user-cancel reply so the turn continues. Other elicitations and turn-less requests are still declined. Fixes #25045. Supersedes #25988, #25046. Co-authored-by: u-ichi <82369+u-ichi@users.noreply.github.com>
78 lines
2.9 KiB
TypeScript
78 lines
2.9 KiB
TypeScript
import type {
|
|
CodexAppServerConnection,
|
|
CodexAppServerServerRequest
|
|
} from './app-server/codex-app-server-connection-types'
|
|
import {
|
|
CODEX_COMMAND_APPROVAL_METHOD,
|
|
CODEX_FILE_CHANGE_APPROVAL_METHOD,
|
|
CODEX_MCP_ELICITATION_METHOD,
|
|
CODEX_USER_INPUT_METHOD,
|
|
type CodexPromptRegistry,
|
|
type CodexPendingPrompt
|
|
} from './codex-structured-prompt-replies'
|
|
|
|
export { CODEX_MCP_ELICITATION_METHOD }
|
|
export const CODEX_PERMISSIONS_APPROVAL_METHOD = 'item/permissions/requestApproval'
|
|
export const CODEX_DYNAMIC_TOOL_CALL_METHOD = 'item/tool/call'
|
|
export const CODEX_AUTH_TOKEN_REFRESH_METHOD = 'account/chatgptAuthTokens/refresh'
|
|
export const CODEX_ATTESTATION_METHOD = 'attestation/generate'
|
|
export const CODEX_LEGACY_APPLY_PATCH_APPROVAL_METHOD = 'applyPatchApproval'
|
|
export const CODEX_LEGACY_EXEC_APPROVAL_METHOD = 'execCommandApproval'
|
|
|
|
export type CodexServerRequestDisposition =
|
|
| { kind: 'prompt'; prompt: CodexPendingPrompt }
|
|
| { kind: 'responded'; method: string }
|
|
|
|
type ResponseConnection = Pick<CodexAppServerConnection, 'respond' | 'respondWithError'>
|
|
|
|
/** Every app-server request either becomes a durable prompt or receives a safe reply. */
|
|
export function disposeCodexServerRequest(
|
|
registry: CodexPromptRegistry,
|
|
connection: ResponseConnection,
|
|
request: CodexAppServerServerRequest
|
|
): CodexServerRequestDisposition {
|
|
const prompt = registry.register(request)
|
|
if (prompt) {
|
|
return { kind: 'prompt', prompt }
|
|
}
|
|
|
|
switch (request.method) {
|
|
case CODEX_COMMAND_APPROVAL_METHOD:
|
|
case CODEX_FILE_CHANGE_APPROVAL_METHOD:
|
|
case CODEX_USER_INPUT_METHOD:
|
|
connection.respondWithError(
|
|
request.id,
|
|
-32001,
|
|
`Orca could not model ${request.method} as a durable prompt`
|
|
)
|
|
break
|
|
case CODEX_MCP_ELICITATION_METHOD:
|
|
// Tool-call approvals become prompts above; Orca renders no other elicitation form.
|
|
connection.respond(request.id, { action: 'decline', content: null, _meta: null })
|
|
break
|
|
case CODEX_PERMISSIONS_APPROVAL_METHOD:
|
|
connection.respond(request.id, { permissions: {}, scope: 'turn', strictAutoReview: true })
|
|
break
|
|
case CODEX_DYNAMIC_TOOL_CALL_METHOD:
|
|
connection.respond(request.id, { contentItems: [], success: false })
|
|
break
|
|
case CODEX_LEGACY_APPLY_PATCH_APPROVAL_METHOD:
|
|
case CODEX_LEGACY_EXEC_APPROVAL_METHOD:
|
|
connection.respond(request.id, { decision: 'abort' })
|
|
break
|
|
case CODEX_AUTH_TOKEN_REFRESH_METHOD:
|
|
connection.respondWithError(request.id, -32001, 'Orca cannot refresh app-server auth tokens')
|
|
break
|
|
case CODEX_ATTESTATION_METHOD:
|
|
connection.respondWithError(request.id, -32001, 'Orca did not negotiate attestation')
|
|
break
|
|
default:
|
|
connection.respondWithError(
|
|
request.id,
|
|
-32000,
|
|
`Orca rejected unrecognized blocking request ${request.method}`
|
|
)
|
|
}
|
|
return { kind: 'responded', method: request.method }
|
|
}
|