import { type DescService } from '@bufbuild/protobuf'; import type { ValueJson } from '@bufbuild/protobuf/wkt'; import { type ConnectRouterOptions, type ContextKey, type ServiceImpl } from '@connectrpc/connect'; import { ConfiguratorApi, ExecutorApi, SessionExecutorApi, StopExecutorApi } from '../api/index.js'; import type { SignalData } from '../genproto/mochabugapis/adapt/graph/v1/signal_data_pb.js'; import { type CronTriggerRequest, type ExchangeResultRequest, type StartExecutionRequest, type StopExecutionRequest } from '../genproto/mochabugapis/adapt/runtime/v1/executor_incoming_pb.js'; import type { ConfiguratorEnvironment, Environment, ExecutionContext, ExecutorEnvironment, HttpHeadersInit, HttpProtocol, HttpServerStream, HttpTunnel, HttpWebSocket, HttpWebTransport } from '@mochabug/adapt-builder/runtime'; export type RequestMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS'; export type RequestMethodOption = RequestMethod | readonly RequestMethod[] | '*'; export type Params = Readonly>; export interface RouteInfo { /** The registered path template that matched this request. */ readonly template: string; /** The actual URL pathname for this request. */ readonly path: string; /** Parameters extracted from the registered path template. */ readonly params: Params; /** Query parameters for the actual request URL. */ readonly query: URLSearchParams; } export type RouterApi = ExecutorApi | SessionExecutorApi | StopExecutorApi | ConfiguratorApi; /** Adapt API instance for the current Connect call. */ export declare const adaptApiContextKey: ContextKey; /** Runtime environment for the current Connect call. */ export declare const adaptEnvironmentContextKey: ContextKey; /** Runtime execution context for the current Connect call. */ export declare const adaptExecutionContextKey: ContextKey; /** Matched route information for the current Connect call. */ export declare const adaptRouteInfoContextKey: ContextKey; /** Original native HTTP stream for the current Connect call. */ export declare const adaptHttpStreamContextKey: ContextKey; export type HttpRouteHandler = (request: Request, api: Api, route: RouteInfo, ctx: Ctx, stream: HttpServerStream) => Response | Promise; export type WebSocketRouteHandler = (socket: HttpWebSocket, api: Api, route: RouteInfo, ctx: Ctx, stream: HttpServerStream) => void | Promise; export type WebTransportRouteHandler = (transport: HttpWebTransport, api: Api, route: RouteInfo, ctx: Ctx, stream: HttpServerStream) => void | Promise; /** The transport family selected by the router for a matched request. */ export type RouterRouteKind = 'http' | 'rpc' | 'websocket' | 'webtransport' | 'tunnel'; /** Request headers without mutating methods. */ export type ReadonlyHeaders = Omit; export interface RouterRequestMetadata { /** Negotiated HTTP version. */ readonly protocol: HttpProtocol; /** Uppercase request method. */ readonly method: string; /** Absolute request URL. */ readonly url: string; /** Request authority, including a non-default port when present. */ readonly authority: string; /** Normalized snapshot of the incoming headers. */ readonly headers: ReadonlyHeaders; /** Extended CONNECT or HTTP/1.1 Upgrade protocol, when requested. */ readonly requestedProtocol?: string; /** Aborts when the peer cancels the request. */ readonly signal: AbortSignal; } export interface RouterResponseMetadata { /** Headers applied when the matched response is committed. */ readonly headers: Headers; /** The HTTP status after downstream dispatch has committed a response. */ readonly status: number | undefined; } export interface RouterResponseMetadataWithTrailers extends RouterResponseMetadata { /** Trailers applied to ordinary HTTP and Connect RPC responses. */ readonly trailers: Headers; } interface RouterMiddlewareContextBase { readonly request: RouterRequestMetadata; readonly route: RouteInfo; readonly api: Api; readonly executionContext: Ctx; } export type RouterMiddlewareContext = Kind extends 'http' | 'rpc' ? RouterMiddlewareContextBase & { readonly kind: Kind; readonly response: RouterResponseMetadataWithTrailers; } : RouterMiddlewareContextBase & { readonly kind: Kind; readonly response: RouterResponseMetadata; }; export type RouterMiddleware = (exchange: RouterMiddlewareContext, next: () => Promise) => void | Response | Promise; export interface WebSocketRouteOptions { protocols?: readonly string[]; maxMessage?: number | bigint; compression?: false | 'permessage-deflate'; headers?: HttpHeadersInit; } export interface WebTransportRouteOptions { protocols?: readonly string[]; headers?: HttpHeadersInit; status?: number; } /** `null` matches classic CONNECT; `*` matches any present custom protocol. */ export type TunnelProtocol = string | null | '*'; export interface TunnelRouteOptions { /** Required protocol selector for this tunnel route. */ protocol: TunnelProtocol; /** Successful 2xx status returned when accepting. Defaults to 200. */ status?: number; /** Headers returned when accepting the tunnel. */ headers?: HttpHeadersInit; } export type TunnelRouteHandler = (tunnel: HttpTunnel, api: Api, route: RouteInfo, ctx: Ctx, stream: HttpServerStream) => void | Promise; /** A runtime-valid export with one own `http` handler property. */ export interface HttpRouterHandler { http(stream: HttpServerStream, env: Env, ctx: Ctx): void | Promise; } /** Middleware surface shared by fixed and plugin-defined HTTP routers. */ export interface RouterMiddlewareBuilder { /** * Register middleware for every matched route owned by this router. The * unified exchange represents ordinary HTTP, Connect RPC, WebSocket, * WebTransport, or tunnel routes when those route kinds are available. * * Middleware runs only after route matching and platform-token validation, * and before a body is read or a response/session is committed. Mutate * response metadata before calling `next()`. Then either call `next()` once * or return a `Response` to short-circuit the route. Metadata mutation after * `next()` throws. */ use(middleware: RouterMiddleware): this; } interface RouterBuilderBase extends RouterMiddlewareBuilder { addRoute(method: RequestMethodOption, path: string, handler: HttpRouteHandler): this; /** * Register decoded Connect-ES service implementations. Connect interceptors * remain the message-level extension point inside this HTTP middleware. */ addConnect(service: T, implementation: Partial>, options?: ConnectRouterOptions): this; addWebSocket(path: string, handler: WebSocketRouteHandler, options?: WebSocketRouteOptions): this; addWebTransport(path: string, handler: WebTransportRouteHandler, options?: WebTransportRouteOptions): this; /** Register a classic CONNECT or named extended-CONNECT tunnel. */ addTunnel(path: string, handler: TunnelRouteHandler, options: TunnelRouteOptions): this; /** * Require an Adapt bearer token. With no protected paths, every matched * route is protected; path lists match case-sensitive, complete path segments. * Authorization runs before user middleware and before accepting upgrades. */ useBearerAuthorization(protectedPaths?: readonly string[], unprotectedPaths?: readonly string[]): this; /** Advertise HTTP/3 over TLS on the request URL’s port (443 by default) for HTTP/1.1 and HTTP/2. */ useH3Upgrade(): this; } export interface RouterBuilder extends RouterBuilderBase { } export type StartHandler = (request: StartExecutionRequest, api: SessionExecutorApi, ctx: Ctx) => void | Promise; export type StopHandler = (request: StopExecutionRequest, api: StopExecutorApi, ctx: Ctx) => void | Promise; export interface ExchangeResultWrapper extends ExchangeResultRequest { getSignal(key: string): T; getSignalBinary(key: string): SignalData; } export type ExchangeHandler = (request: ExchangeResultWrapper, api: SessionExecutorApi, name: string, ctx: Ctx) => void | Promise; export type CronHandler = (request: CronTriggerRequest, api: SessionExecutorApi, ctx: Ctx) => void | Promise; /** * Closed configuration surface for the fully specified Internal Executor * protocol. The generated incoming service is registered by the toolkit. */ export interface IERouterBuilder extends RouterMiddlewareBuilder { onStart(handler: StartHandler): this; onStop(handler: StopHandler): this; onExchange(handler: ExchangeHandler): this; onCron(handler: CronHandler): this; } /** Join URL path fragments with POSIX-style `.` and `..` normalization. */ export declare function joinPaths(...paths: string[]): string; /** * Create a router for the plugin-defined External Executor HTTP surface. The * returned plain `{ http }` object can be exported directly as a runtime * handler. */ export declare function createEERouter(configure?: (router: RouterBuilder) => void): HttpRouterHandler; /** * Create a router for the fixed Internal Executor protocol. The toolkit * registers `ExecutorIncomingService` through Connect; callers configure only * middleware and its four optional lifecycle handlers. Each RPC acknowledges * the notification with an empty response when its callback is omitted. */ export declare function createIERouter(configure?: (router: IERouterBuilder) => void): HttpRouterHandler; /** * Create a router for the plugin-defined External Configurator HTTP surface. * The returned plain `{ http }` object can be exported directly as a runtime * handler. */ export declare function createECRouter(configure?: (router: RouterBuilder) => void): HttpRouterHandler; /** * Create the Internal Configurator HTTP handler. No incoming application * protocol is currently defined, so this factory intentionally has no * configuration callback. */ export declare function createICRouter(): HttpRouterHandler; export type { ConnectRouterOptions } from '@connectrpc/connect'; //# sourceMappingURL=index.d.ts.map