import type { SessionAuthContext } from "#channel/types.js"; import type { SessionParent, SessionTurn } from "#context/keys.js"; import type { ToolAuthOptions, ToolAuthProvider } from "#tools/auth.js"; import type { SessionContext } from "#context/session-context.js"; import type { TokenResult } from "#shared/connection-types.js"; type ApprovalToolInput = TInput extends object ? Readonly : TInput; /** * Context passed to an {@link ApprovalPolicy} function. * * Extends {@link SessionContext} so approval policies can make decisions from * the active session, current caller, and turn. */ export interface ApprovalContext> extends SessionContext { /** Cancels policy work when the active model generation is cancelled. */ readonly abortSignal: AbortSignal; readonly approvedTools: ReadonlySet; readonly callId: string; readonly toolInput?: ApprovalToolInput; readonly toolName: string; } /** Request-time approval decision returned by an {@link ApprovalPolicy}. */ export type ApprovalStatus = undefined | boolean | "not-applicable" | "approved" | "denied" | "user-approval" | { readonly type: "not-applicable"; readonly reason?: never; } | { readonly type: "approved"; readonly reason?: string; } | { readonly type: "denied"; readonly reason?: string; } | { readonly type: "user-approval"; readonly reason?: never; }; /** Request-time approval policy shared by authored tools and connections. */ export type ApprovalPolicy> = (ctx: ApprovalContext) => ApprovalStatus | Promise; /** Stable tool request passed to a response authorizer. */ export interface ApprovalRequest> { readonly callId: string; readonly requestId: string; /** * Who requested the tool call: the auth of the caller whose turn made it, * captured when the approval was requested. It stays the same while the * request is pending, however many people continue the session, and is * `null` when that caller was unauthenticated or anonymous. */ readonly principal: SessionAuthContext | null; readonly toolInput?: ApprovalToolInput; readonly toolName: string; } /** Read-only session identity and lineage available to a response authorizer. */ export interface ApprovalResponseSession { readonly id: string; readonly initiator: SessionAuthContext | null; readonly parent?: SessionParent; readonly turn: SessionTurn; } /** Narrow authorization capability available while validating a responder. */ export interface ApprovalResponseAuth { getToken(provider: ToolAuthProvider, options?: ToolAuthOptions): Promise; requireAuth(provider: ToolAuthProvider, options?: ToolAuthOptions): never; } /** Submitted response passed to an approval response policy. */ export interface ApprovalResponse { readonly decision: "approve" | "cancel"; /** * Who submitted the response: the authenticated principal, including its * `principalId`, `principalType`, `authenticator`, and `attributes`. */ readonly principal: SessionAuthContext; } /** Context passed to an approval response policy. */ export interface ApprovalResponseContext> { readonly auth: ApprovalResponseAuth; readonly request: ApprovalRequest; readonly response: ApprovalResponse; readonly session: ApprovalResponseSession; } /** * Response policy decision. Rejection keeps the shared request pending, so * another responder can still settle it. */ export type ApprovalResponseDecision = { readonly status: "allowed"; } | { readonly reason: string; readonly status: "rejected"; }; /** Decides whether an authenticated responder may approve or cancel one request. */ export type ApprovalResponsePolicy> = (ctx: ApprovalResponseContext) => ApprovalResponseDecision | Promise; /** Approval definition with request- and response-time policy. */ export interface ApprovalConfiguration> { readonly request: ApprovalPolicy; readonly response?: ApprovalResponsePolicy; } /** Shared approval definition used by authored tools and connections. */ export type Approval> = ApprovalPolicy | ApprovalConfiguration; /** Returns the request-time policy from either approval authoring shape. */ export declare function resolveApprovalPolicy(approval: Approval): ApprovalPolicy; export {};