import {
  A as ChannelIngressEnvelope,
  B as isChannelMessageSurface,
  C as ChannelEmailIngressResult,
  D as ChannelInboundMessage,
  E as ChannelEventContextInput,
  F as ChannelMessageSurface,
  G as UserIdentityConflictError,
  H as ChannelIdentityInput,
  I as ChannelMessageSurfaceInput,
  J as UserIdentityStore,
  K as UserIdentitySqlValue,
  L as ChannelSurfaceArray,
  M as ChannelIngressEventInput,
  N as ChannelIngressResult,
  O as ChannelInboundMessageInput,
  P as matchesPath,
  Q as linkChannelIdentities,
  R as ChannelSurfaceObject,
  S as ChannelEmailIngress,
  T as ChannelEventContext,
  U as UserIdentity,
  V as ChannelIdentity,
  W as UserIdentityConflict,
  X as createUserIdentityStore,
  Y as UserIdentityStoreOptions,
  Z as identityKey,
  _ as ChannelActor,
  a as ChannelApprovalRequestOptions,
  b as ChannelApprovalResponseInput,
  c as ChannelDeliveryContext,
  d as ChannelRoute,
  f as ChannelRouteContext,
  g as OutboundResolver,
  h as DeliveryResult,
  i as ChannelApprovalRequest,
  j as ChannelIngressEvent,
  k as ChannelIngress,
  l as ChannelDeliveryOptions,
  m as DeliveryFailure,
  n as Channel,
  o as ChannelChunk,
  p as ChannelStreamOptions,
  q as UserIdentityStorage,
  r as ChannelApprovalLinks,
  s as ChannelChunkSource,
  t as Awaitable,
  u as ChannelMessage,
  v as ChannelActorInput,
  w as ChannelEmailInput,
  x as ChannelAttachment,
  y as ChannelApprovalResponse,
  z as ChannelSurfaceValue
} from "../channel-Bnm4S7T2.js";
import {
  a as ChannelRouteEvent,
  i as ChannelMessageEvent,
  n as ChannelHost,
  r as ChannelHostOptions,
  t as ChannelApprovalResponseEvent
} from "../index-BB0kqhIz.js";

//#region src/channels/fallback.d.ts
type FallbackSurface = ChannelMessageSurface<
  "fallback",
  {
    surfaces: readonly ChannelMessageSurface[];
  }
>;
/** A non-empty sequence of destinations ordered from preferred to final. */
type FallbackSurfaceOptions = readonly [
  ChannelMessageSurface,
  ...ChannelMessageSurface[]
];
/**
 * Build an inert fallback destination for a `ChannelHost` to resolve.
 *
 * The Host skips unavailable destinations, advances after confirmed failures,
 * and stops after a delivered or uncertain result to avoid duplicates.
 */
declare function fallback(surfaces: FallbackSurfaceOptions): FallbackSurface;
/** Build the ordinary Channel installed under the reserved fallback key. */
declare function fallbackChannel(resolve: OutboundResolver): Channel;
//#endregion
//#region src/channels/fanout.d.ts
type FanoutSurface = ChannelMessageSurface<
  "fanout",
  {
    surfaces: readonly ChannelMessageSurface[];
  }
>;
/** A non-empty set of destinations that must all receive each delivery. */
type FanoutSurfaceOptions = readonly [
  ChannelMessageSurface,
  ...ChannelMessageSurface[]
];
/** Build an inert fanout destination for a `ChannelHost` to resolve. */
declare function fanout(surfaces: FanoutSurfaceOptions): FanoutSurface;
/** Build the ordinary Channel installed under the reserved fanout key. */
declare function fanoutChannel(resolve: OutboundResolver): Channel;
//#endregion
//#region src/channels/routes.d.ts
/**
 * Common deterministic routing policies for normalized Channel events.
 *
 * Each one maps an event to a namespaced application route. Deciding whether
 * an event is relevant at all is application policy: write that in your own
 * `route` function and return `null` to ignore the event.
 */
declare const routes: {
  /**
   * Give every event its own application route. Useful to kick off a
   * new conversation for each ingress, and where you don't want subsequent
   * messages routed back to that same conversation.
   **/
  perEvent(
    event: ChannelIngressEvent
  ): string /** Send every event in the same thread to the same conversation */;
  perThread(event: ChannelIngressEvent): string;
  /**
   * Prefer the sender's own channel identity, then delegate to another route
   * policy. Without a fallback, an event carrying no identity is ignored.
   *
   * This groups events that carry the *same* identity. It never infers that
   * two different identities belong to one person: that is an explicit
   * application decision, exposed to routing through `byUser`.
   */
  byIdentity<TRaw>(
    fallback?: ChannelRoute<TRaw>
  ): ChannelRoute<TRaw> /** Prefer an explicitly linked user, then delegate to another route policy. */;
  byUser<TRaw>(fallback: ChannelRoute<TRaw>): ChannelRoute<TRaw>;
};
//#endregion
//#region src/channels/stream.d.ts
/** Why a consumption loop stopped reading. */
type StreamOutcome =
  | {
      interrupted: false;
    }
  | {
      interrupted: true;
      error: unknown;
    };
type ChunkConsumer<TChunk, TResult> = {
  onChunk(
    chunk: TChunk
  ): Awaitable<void> /** Runs exactly once, whether the stream closed or ended abnormally. */;
  onFinish(outcome: StreamOutcome): Awaitable<TResult>;
};
/**
 * Read a stream to completion, then finalize exactly once.
 *
 * `onFinish` runs whether the stream closed normally, errored because the
 * generation failed, or stopped because `onChunk` threw. A Channel that
 * finalizes here cannot lose a terminal provider call to an early ending.
 */
declare function consumeChunks<TChunk, TResult>(
  chunks: ReadableStream<TChunk>,
  consumer: ChunkConsumer<TChunk, TResult>
): Promise<TResult>;
//#endregion
export {
  Awaitable,
  Channel,
  ChannelActor,
  ChannelActorInput,
  ChannelApprovalLinks,
  ChannelApprovalRequest,
  ChannelApprovalRequestOptions,
  ChannelApprovalResponse,
  ChannelApprovalResponseEvent,
  ChannelApprovalResponseInput,
  ChannelAttachment,
  ChannelChunk,
  ChannelChunkSource,
  ChannelDeliveryContext,
  ChannelDeliveryOptions,
  ChannelEmailIngress,
  ChannelEmailIngressResult,
  ChannelEmailInput,
  ChannelEventContext,
  ChannelEventContextInput,
  ChannelHost,
  ChannelHostOptions,
  ChannelIdentity,
  ChannelIdentityInput,
  ChannelInboundMessage,
  ChannelInboundMessageInput,
  ChannelIngress,
  ChannelIngressEnvelope,
  ChannelIngressEvent,
  ChannelIngressEventInput,
  ChannelIngressResult,
  ChannelMessage,
  ChannelMessageEvent,
  ChannelMessageSurface,
  ChannelMessageSurfaceInput,
  ChannelRoute,
  ChannelRouteContext,
  ChannelRouteEvent,
  ChannelStreamOptions,
  ChannelSurfaceArray,
  ChannelSurfaceObject,
  ChannelSurfaceValue,
  type ChunkConsumer,
  DeliveryFailure,
  DeliveryResult,
  FallbackSurface,
  FallbackSurfaceOptions,
  FanoutSurface,
  FanoutSurfaceOptions,
  OutboundResolver,
  type StreamOutcome,
  UserIdentity,
  UserIdentityConflict,
  UserIdentityConflictError,
  UserIdentitySqlValue,
  UserIdentityStorage,
  UserIdentityStore,
  UserIdentityStoreOptions,
  consumeChunks,
  createUserIdentityStore,
  fallback,
  fallbackChannel,
  fanout,
  fanoutChannel,
  identityKey,
  isChannelMessageSurface,
  linkChannelIdentities,
  matchesPath,
  routes
};
//# sourceMappingURL=index.d.ts.map
