/** * Make sure the client holds the agent credential required by the canonical * permission broker before a read goes out. * * ## Why this exists * * Permission, mode, and event reads require a noninteractive runtime * credential. This helper resolves only the process-local/injected credential * path and never starts user interaction or falls back to OAuth/DCR state. It * remains cheap to call for every read and preserves existing fail-open error * classification when no credential is available. */ import { OryAgentClient } from "./client.js"; import { ensureAgentIdentity } from "./agent-auth.js"; export interface EnsureReadCredentialOptions { /** Harness whose install credential to resolve. Defaults to `client.harness`. */ harness?: string; /** Inject the agent gate for tests. */ agentGate?: typeof ensureAgentIdentity; /** Injectable clock for the failed-attempt backoff (tests). */ now?: number; /** Abort network work when the caller's latency budget expires. */ signal?: AbortSignal; /** Retained for call-site compatibility; runtime resolution never uses DCR. */ allowRegistration?: boolean; } /** * How long a *failed* resolution suppresses another attempt on the same client. * * A success needs no backoff — the token is on the client and every later call * returns at the `present` check. A failure would otherwise be retried by each * read path of each gate (the mode probe and the tool check, at least), so one * unreachable token endpoint would mean several grant attempts per tool call. * Short enough that a long-lived in-process session still recovers on its own * once the endpoint comes back. */ export declare const READ_CREDENTIAL_RETRY_MS = 30000; /** Drop the failed-attempt backoff. Test-only (reassigns the WeakMap). */ export declare function resetReadCredentialBackoff(): void; export type ReadCredentialOutcome = /** Agent Security isn't connected; there is nothing to authenticate against. */ { kind: "not_connected"; } /** The agent credential was already in hand. */ | { kind: "present"; principal: "agent"; } /** The agent identity was resolved for this read. */ | { kind: "resolved"; } /** No agent credential could be resolved; the read will classify locally. */ | { kind: "unavailable"; reason?: string; }; /** * Resolve an Agent Security broker credential onto `client` if needed. * * Idempotent and cheap to call repeatedly: the first call in a process resolves, * the rest see the principal already populated and return immediately. */ export declare function ensureReadCredential(client: OryAgentClient, options?: EnsureReadCredentialOptions): Promise;