/**
 * Gateway contract — the transport-agnostic CQRS dispatch shapes.
 *
 * Every operation flows through:
 *   GatewayRequest → Middleware → DomainHandler → GatewayResponse
 *
 * These shapes were promoted verbatim from `packages/cleo/src/dispatch/types.ts`
 * into `@cleocode/contracts/gateway` (R3-T2 · T11446 · SG-RUNTIME-UNIFICATION)
 * so that EVERY transport adapter — CLI, MCP, RPC, HTTP — shares one canonical,
 * zod-validated contract instead of the CLI owning a private copy. The CLI was
 * the only historical transport (`Source = 'cli'`); {@link GatewaySource} now
 * widens that to the four planned transports.
 *
 * Design: the zod schemas are the single source of truth (AC8 — runtime
 * validation at untrusted transport boundaries such as MCP/RPC/HTTP). The TS
 * types are derived via {@link https://zod.dev | z.infer}, so the static and
 * runtime contracts can never drift. The behavioral contracts that zod cannot
 * model (function types: {@link DomainHandler}, {@link Middleware},
 * {@link DispatchNext}) remain TS-only and reference the inferred data types.
 *
 * @epic T4820
 * @task T11446
 * @saga T11243
 */
import type { LAFSPage, MVILevel } from '@cleocode/lafs';
import { z } from 'zod';
import type { CanonicalDomain, Gateway, Tier } from './dispatch/identity.js';
import type { ProblemDetails } from './engine-result.js';
export { CANONICAL_DOMAINS } from './dispatch/identity.js';
export type { CanonicalDomain, Gateway, Tier };
/**
 * Frozen version of the gateway contract. Bump on any breaking change to the
 * request/response/error shapes; the freeze + spec are owned by R3-T8 (T11452).
 */
export declare const GATEWAY_CONTRACT_VERSION: "1.0.0";
/** The four canonical transports a gateway request can originate from. */
export declare const GATEWAY_SOURCES: readonly ["cli", "mcp", "rpc", "http"];
/** Where a gateway request originated. Widened from the historical CLI-only `'cli'`. */
export declare const gatewaySourceSchema: z.ZodEnum<{
    http: "http";
    cli: "cli";
    mcp: "mcp";
    rpc: "rpc";
}>;
/** Where a gateway request originated. */
export type GatewaySource = z.infer<typeof gatewaySourceSchema>;
/**
 * @deprecated Use {@link GatewaySource}. Retained as a structural alias so the
 * historical `import type { Source }` sites keep compiling unchanged.
 */
export type Source = GatewaySource;
/**
 * Canonical request shape produced by every transport adapter. The dispatcher
 * validates this against the OperationRegistry before passing it through the
 * middleware pipeline and into a {@link DomainHandler}.
 */
export declare const dispatchRequestSchema: z.ZodObject<{
    gateway: z.ZodCustom<Gateway, Gateway>;
    domain: z.ZodString;
    operation: z.ZodString;
    params: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    source: z.ZodEnum<{
        http: "http";
        cli: "cli";
        mcp: "mcp";
        rpc: "rpc";
    }>;
    requestId: z.ZodString;
    sessionId: z.ZodOptional<z.ZodString>;
    originSessionId: z.ZodOptional<z.ZodString>;
    executionSessionId: z.ZodOptional<z.ZodString>;
    _fields: z.ZodOptional<z.ZodArray<z.ZodString>>;
    _mvi: z.ZodOptional<z.ZodCustom<MVILevel, MVILevel>>;
}, z.core.$strip>;
/** {@inheritDoc dispatchRequestSchema} */
export type DispatchRequest = z.infer<typeof dispatchRequestSchema>;
/** Rate-limit metadata attached to every response. */
export declare const rateLimitMetaSchema: z.ZodObject<{
    limit: z.ZodNumber;
    remaining: z.ZodNumber;
    resetMs: z.ZodNumber;
    category: z.ZodString;
}, z.core.$strip>;
/** {@inheritDoc rateLimitMetaSchema} */
export type RateLimitMeta = z.infer<typeof rateLimitMetaSchema>;
/** Structured error shape (LAFS-compatible). */
export declare const dispatchErrorSchema: z.ZodObject<{
    code: z.ZodString;
    exitCode: z.ZodOptional<z.ZodNumber>;
    message: z.ZodString;
    details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
    fix: z.ZodOptional<z.ZodString>;
    alternatives: z.ZodOptional<z.ZodArray<z.ZodObject<{
        action: z.ZodString;
        command: z.ZodString;
    }, z.core.$strip>>>;
    problemDetails: z.ZodOptional<z.ZodCustom<ProblemDetails, ProblemDetails>>;
}, z.core.$strip>;
/** {@inheritDoc dispatchErrorSchema} */
export type DispatchError = z.infer<typeof dispatchErrorSchema>;
/**
 * Always-present metadata block on every {@link DispatchResponse}.
 *
 * The catch-all (`[key: string]: unknown`) makes this assignable to
 * `Record<string, unknown>` in covariant positions, eliminating the T9767
 * cast-chain anti-pattern at every responseMeta call site.
 *
 * @task T9767
 */
export declare const dispatchResponseMetaSchema: z.ZodObject<{
    gateway: z.ZodCustom<Gateway, Gateway>;
    domain: z.ZodString;
    operation: z.ZodString;
    timestamp: z.ZodString;
    duration_ms: z.ZodNumber;
    source: z.ZodEnum<{
        http: "http";
        cli: "cli";
        mcp: "mcp";
        rpc: "rpc";
    }>;
    requestId: z.ZodString;
    rateLimit: z.ZodOptional<z.ZodObject<{
        limit: z.ZodNumber;
        remaining: z.ZodNumber;
        resetMs: z.ZodNumber;
        category: z.ZodString;
    }, z.core.$strip>>;
    sessionId: z.ZodOptional<z.ZodString>;
    originSessionId: z.ZodOptional<z.ZodString>;
    executionSessionId: z.ZodOptional<z.ZodString>;
    version: z.ZodOptional<z.ZodString>;
}, z.core.$catchall<z.ZodUnknown>>;
/** {@inheritDoc dispatchResponseMetaSchema} */
export type DispatchResponseMeta = z.infer<typeof dispatchResponseMetaSchema>;
/**
 * Canonical response shape returned by the dispatcher. The CLI adapter
 * translates this into cliOutput() / cliError() + process.exit(); other
 * transports serialize it onto their wire.
 */
export declare const dispatchResponseSchema: z.ZodObject<{
    meta: z.ZodObject<{
        gateway: z.ZodCustom<Gateway, Gateway>;
        domain: z.ZodString;
        operation: z.ZodString;
        timestamp: z.ZodString;
        duration_ms: z.ZodNumber;
        source: z.ZodEnum<{
            http: "http";
            cli: "cli";
            mcp: "mcp";
            rpc: "rpc";
        }>;
        requestId: z.ZodString;
        rateLimit: z.ZodOptional<z.ZodObject<{
            limit: z.ZodNumber;
            remaining: z.ZodNumber;
            resetMs: z.ZodNumber;
            category: z.ZodString;
        }, z.core.$strip>>;
        sessionId: z.ZodOptional<z.ZodString>;
        originSessionId: z.ZodOptional<z.ZodString>;
        executionSessionId: z.ZodOptional<z.ZodString>;
        version: z.ZodOptional<z.ZodString>;
    }, z.core.$catchall<z.ZodUnknown>>;
    success: z.ZodBoolean;
    data: z.ZodOptional<z.ZodUnknown>;
    page: z.ZodOptional<z.ZodCustom<LAFSPage, LAFSPage>>;
    partial: z.ZodOptional<z.ZodBoolean>;
    error: z.ZodOptional<z.ZodObject<{
        code: z.ZodString;
        exitCode: z.ZodOptional<z.ZodNumber>;
        message: z.ZodString;
        details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
        fix: z.ZodOptional<z.ZodString>;
        alternatives: z.ZodOptional<z.ZodArray<z.ZodObject<{
            action: z.ZodString;
            command: z.ZodString;
        }, z.core.$strip>>>;
        problemDetails: z.ZodOptional<z.ZodCustom<ProblemDetails, ProblemDetails>>;
    }, z.core.$strip>>;
}, z.core.$strip>;
/** {@inheritDoc dispatchResponseSchema} */
export type DispatchResponse = z.infer<typeof dispatchResponseSchema>;
/**
 * A single frame emitted by a streaming gateway operation. Unary transports
 * (CLI) never see these; streaming transports (Studio SSE, RPC server-push)
 * emit a sequence terminated by a `done` or `error` event.
 */
export declare const gatewayStreamEventSchema: z.ZodObject<{
    kind: z.ZodEnum<{
        error: "error";
        done: "done";
        data: "data";
    }>;
    seq: z.ZodNumber;
    data: z.ZodOptional<z.ZodUnknown>;
    error: z.ZodOptional<z.ZodObject<{
        code: z.ZodString;
        exitCode: z.ZodOptional<z.ZodNumber>;
        message: z.ZodString;
        details: z.ZodOptional<z.ZodRecord<z.ZodString, z.ZodUnknown>>;
        fix: z.ZodOptional<z.ZodString>;
        alternatives: z.ZodOptional<z.ZodArray<z.ZodObject<{
            action: z.ZodString;
            command: z.ZodString;
        }, z.core.$strip>>>;
        problemDetails: z.ZodOptional<z.ZodCustom<ProblemDetails, ProblemDetails>>;
    }, z.core.$strip>>;
    requestId: z.ZodString;
}, z.core.$strip>;
/** {@inheritDoc gatewayStreamEventSchema} */
export type GatewayStreamEvent = z.infer<typeof gatewayStreamEventSchema>;
/**
 * Contract for domain handlers.
 *
 * Each canonical domain (tasks, session, memory, check, pipeline, orchestrate,
 * tools, admin, nexus, sticky, intelligence) implements this interface.
 */
export interface DomainHandler {
    /** Execute a read-only query operation. */
    query(operation: string, params?: Record<string, unknown>): Promise<DispatchResponse>;
    /** Execute a state-modifying mutation operation. */
    mutate(operation: string, params?: Record<string, unknown>): Promise<DispatchResponse>;
    /** Declared operations for introspection and validation. */
    getSupportedOperations(): {
        query: string[];
        mutate: string[];
    };
}
/** Async continuation that produces a {@link DispatchResponse}. */
export type DispatchNext = () => Promise<DispatchResponse>;
/**
 * Middleware function signature. Receives the request and a `next`
 * continuation; can short-circuit (e.g. rate-limit exceeded) or modify the
 * request/response.
 */
export type Middleware = (request: DispatchRequest, next: DispatchNext) => Promise<DispatchResponse>;
//# sourceMappingURL=gateway.d.ts.map