import {
  N as ChannelIdentity,
  S as ChannelEmailInput,
  a as ChannelDeliveryOptions,
  k as ChannelIngressEvent,
  l as ChannelStreamOptions,
  n as Channel,
  o as ChannelMessage,
  p as DeliveryResult,
  r as ChannelChunkSource
} from "./channel-Bak_6zDP.js";
import {
  b as ChannelMessageSurface,
  p as Participant,
  s as GatewayOrigin
} from "./protocol-CukuI73M.js";
import { c as GatewayEvent } from "./conversations-FjHDRZyD.js";

//#region src/experimental/channels/gateway.d.ts
type ChannelRouteEvent = {
  channelKey: string;
  event: ChannelIngressEvent /** Who the Channel resolved the sender as; null when it refused them. */;
  participant: Participant | null /** The agent object the event reaches; null when it is ignored or refused. */;
  route:
    | string
    | null /** Stable identity derived only from the configured Channel and eventId. */;
  dispatchId: string;
};
/** The agent object a route names, as the gateway reaches it. */
type GatewayAgent = {
  /** Hand the agent an inbound event; Channels' `receive` serves it. */ receive(
    event: GatewayEvent,
    origin: GatewayOrigin
  ): Promise<unknown>;
  fetch(request: Request): Promise<Response>;
};
type ChannelGatewayOptions = {
  /**
   * The Channels this Worker serves. Each one that takes ingress says who
   * its senders are (`participant`) and which agent object they reach
   * (`route`).
   */
  channels: Record<string, Channel> /** The agent object a route names. */;
  agent(
    route: string
  ): GatewayAgent /** Observes every valid route outcome before it is sent to the agent. */;
  onRoute?(event: ChannelRouteEvent): void | Promise<void>;
};
/**
 * The Worker's entry point for Channels. Authenticates and normalizes
 * webhooks, resolves WebSocket upgrades, routes each to the agent object
 * its route names, and sends to surfaces.
 *
 * The gateway is the trust boundary. It alone decides who a sender is and
 * tells the agent, so an agent serving Channels must be reachable only
 * through it: an app that forwards an upgrade to the agent some other way
 * (another fetch handler, `routeAgentRequest`, RPC) lets the caller pick
 * its own participant and conversation.
 *
 * The agent object is the authorization boundary. Whoever a Channel routes
 * to an object may list, join, create, fork and reset every conversation in
 * it. To keep people apart, route them to different objects; by default
 * each participant gets an object of their own.
 */
declare class ChannelGateway {
  #private;
  constructor(options: ChannelGatewayOptions);
  /** Serve a request if it is for Channels, or return undefined. */
  fetch(request: Request): Promise<Response | undefined>;
  handleEmail(email: ChannelEmailInput): Promise<boolean>;
  /** Deliver through the configured Channel named by the surface. */
  deliver(
    surface: ChannelMessageSurface,
    message: ChannelMessage,
    options?: ChannelDeliveryOptions
  ): Promise<DeliveryResult>;
  /**
   * Deliver a progressively generated answer to the Channel
   * named by the surface.
   *
   * A Channel that can stream consumes the stream itself. A Channel that
   * cannot never learns it was a stream, because the Host collects the answer
   * and calls `deliver` once.
   */
  stream(
    surface: ChannelMessageSurface,
    chunks: ChannelChunkSource,
    options?: ChannelStreamOptions
  ): Promise<DeliveryResult>;
  /** Return the identity's configured Channel destination, when supported. */
  contactSurface(identity: ChannelIdentity): ChannelMessageSurface | null;
}
//#endregion
export {
  GatewayAgent as i,
  ChannelGatewayOptions as n,
  ChannelRouteEvent as r,
  ChannelGateway as t
};
//# sourceMappingURL=gateway-BFO6vRDn.d.ts.map
