import { z } from "zod"; import { type ActionHandler, type ActionRegistry, type VerifiedAuthorization } from "@decionis/agent-safe-pipeline"; import { type HttpActionParameters, type HttpFactsParameters, type InterceptedRequest } from "./InterceptedRequest.js"; import type { Upstream, UpstreamResult } from "./Upstream.js"; /** The parameters an HTTP action carries; anything else the registry refuses before a grant is spent. */ export declare const HttpActionParametersSchema: z.ZodObject<{ method: z.ZodEnum<{ POST: "POST"; PUT: "PUT"; PATCH: "PATCH"; DELETE: "DELETE"; }>; path: z.ZodString; query: z.ZodRecord]>>; body: z.ZodOptional>>; policy_id: z.ZodOptional; policy_version: z.ZodOptional; }, z.core.$strict>; /** A facts-only HTTP action's parameters: the profile operation and its template, nothing more. */ export declare const HttpFactsParametersSchema: z.ZodObject<{ method: z.ZodEnum<{ POST: "POST"; PUT: "PUT"; PATCH: "PATCH"; DELETE: "DELETE"; }>; operation: z.ZodString; path_template: z.ZodString; }, z.core.$strict>; /** Either shape; a facts-only one is told apart by its `operation`. */ export type HttpParameters = HttpActionParameters | HttpFactsParameters; /** What the registry admits an HTTP action's parameters against: either shape, nothing else. */ export declare const HttpParametersSchema: z.ZodType; /** * The header a write carries the target version its intent bound in, as a * verifying hop sets it after checking an attestation: an upstream that takes * writes only through the gateway's credential, and honours it, refuses a * write whose target has moved since the decision. */ export declare const EXPECTED_STATE_VERSION_HEADER = "x-agent-safe-expected-state-version"; /** * Told when the upstream answered a forwarded write with a `2xx`, after the * point of no return and before the attempt is finalized, so what it does * rides on the finalization. It never throws. */ export type Landed = (authorization: VerifiedAuthorization) => Promise; /** * Asked after the grant is claimed and the bytes are checked, immediately * before the point of no return: a last check of the gateway's own (a * payment's cumulative limits) that refuses by throwing a * `PreDispatchRefusal`, so nothing is sent and the attempt is finalized as * not executed. */ export type BeforeDispatch = (authorization: VerifiedAuthorization) => Promise; /** What the handler leaves behind for the relay, whichever way the attempt ended. */ export interface ForwardOutcome { readonly response: UpstreamResult | null; /** Why the upstream's answer was not a commit, when it was not. */ readonly failure: "UPSTREAM_REFUSED" | "UPSTREAM_ERROR" | "TRANSPORT" | "RESPONSE_TOO_LARGE" | null; } interface Held { readonly request: InterceptedRequest; readonly extraHeaders: Readonly>; readonly landed: Landed | null; readonly before: BeforeDispatch | null; outcome: ForwardOutcome; } /** * The bytes and headers of each request in flight, keyed by intent id. The * intent carries the digest of the bytes and never the bytes, so the handler * looks them up here; nothing about a request outlives its run. */ export declare class RequestHolder { private readonly held; hold(intentId: string, request: InterceptedRequest, extraHeaders: Readonly>, landed?: Landed | null, before?: BeforeDispatch | null): void; /** @internal */ get(intentId: string): Held | undefined; /** The outcome the handler recorded, and the end of the hold. */ release(intentId: string): ForwardOutcome; } /** * The one handler every HTTP action runs through. It runs only behind a * claimed single-use grant, with the parameters the authority evaluated. * Before the point of no return it recomputes the digest of the bytes it is * about to send and refuses if they are not the bytes the intent bound; the * request forwarded is therefore the request authorized, and a payload that * changed between the two is a failure before dispatch, not an execution. * The upstream's status is the attempt's outcome: `2xx` and `3xx` commit, * `4xx` is the provider's own refusal, `5xx` and a lost connection are * unknown. A facts-only intent carries no path to compare: the held request * is bound by its keyed digest instead, which covers the same bytes. When * the intent bound its target's version, the write says so to the upstream, * and a `2xx` is handed to whoever held the request before the runner * finalizes the attempt. */ export declare function httpForwardHandler(upstream: Upstream, holder: RequestHolder, digestKey: Uint8Array): ActionHandler; /** Registers the one handler under every name the route table can produce, then seals. */ export declare function registerHttpActions(registry: ActionRegistry, actions: readonly string[], handler: ActionHandler): ActionRegistry; export {}; //# sourceMappingURL=ForwardHandler.d.ts.map