eve
Version:
Filesystem-first framework for durable backend AI agents that run anywhere.
90 lines (89 loc) • 5.3 kB
TypeScript
export { defineChannel, GET, POST, PUT, PATCH, DELETE, WS, type Channel, type ChannelDefinition, type ChannelSessionOps, type ChannelEvents, type InferChannelMetadata, type Session, type SessionHandle, type RouteDefinition, type RouteHandlerArgs, type SendFn, type SendOptions, type SendPayload, type GetSessionFn, type HttpRouteDefinition, type WebSocketMessage, type WebSocketPeer, type WebSocketRouteDefinition, type WebSocketRouteHandler, type WebSocketRouteHooks, type WebSocketUpgradeRequest, type WebSocketUpgradeResult, } from "#public/definitions/defineChannel.js";
export { createWebSocketUpgradeServer, type WebSocketUpgradeServerBridge, } from "#channel/websocket-upgrade-server.js";
import type { Channel } from "#public/definitions/defineChannel.js";
/**
* Base channel metadata shape used by framework channel kinds.
*/
export type InstrumentationChannelMetadata = Readonly<Record<string, unknown>>;
/**
* Channel metadata projections keyed by channel kind.
*
* Built-in channel packages ship declaration-merged entries (e.g. Slack
* ships `"channel:slack"`). The eve compiler generates entries for
* authored channels at build time.
*/
export interface ChannelMetadataMap {
readonly http: InstrumentationChannelMetadata;
readonly schedule: InstrumentationChannelMetadata;
readonly subagent: InstrumentationChannelMetadata;
readonly unknown: InstrumentationChannelMetadata;
readonly "channel:slack": import("#public/channels/slack/slackChannel.js").SlackInstrumentationMetadata;
readonly "channel:discord": import("#public/channels/discord/index.js").DiscordInstrumentationMetadata;
readonly "channel:twilio": import("#public/channels/twilio/twilioChannel.js").TwilioInstrumentationMetadata;
readonly "channel:teams": import("#public/channels/teams/index.js").TeamsInstrumentationMetadata;
readonly "channel:telegram": import("#public/channels/telegram/index.js").TelegramInstrumentationMetadata;
readonly "channel:linear": import("#public/channels/linear/index.js").LinearInstrumentationMetadata;
}
/**
* Union of all known channel kind discriminators (the keys of
* {@link ChannelMetadataMap}): the framework kinds `"http"`, `"schedule"`,
* `"subagent"`, and `"unknown"`, plus a `"channel:<slug>"` entry for each
* built-in and compiler-generated authored channel.
*/
export type InstrumentationChannelKind = keyof ChannelMetadataMap;
/**
* Channel values keyed by path-derived channel kind.
*
* Entries are generated by the eve compiler for authored channels.
* Built-in channel entries are declared inline above.
* Used by {@link isChannel} to resolve a channel value to its kind string.
*/
export interface ChannelReferenceMap {
readonly "channel:slack": import("#public/channels/slack/slackChannel.js").SlackChannel;
readonly "channel:discord": import("#public/channels/discord/discordChannel.js").DiscordChannel;
readonly "channel:twilio": import("#public/channels/twilio/twilioChannel.js").TwilioChannel;
readonly "channel:teams": import("#public/channels/teams/teamsChannel.js").TeamsChannel;
readonly "channel:telegram": import("#public/channels/telegram/telegramChannel.js").TelegramChannel;
readonly "channel:linear": import("#public/channels/linear/linearChannel.js").LinearChannel;
}
/**
* One arm of {@link InstrumentationChannel}: a channel of kind `K` paired with
* its matching {@link ChannelMetadataMap} metadata projection.
*/
export interface InstrumentationChannelForKind<K extends InstrumentationChannelKind> {
readonly kind: K;
readonly metadata: ChannelMetadataMap[K];
}
/**
* Discriminated union over every {@link InstrumentationChannelKind}, each arm
* carrying its `kind` string and matching `metadata`. This is the channel shape
* instrumentation callbacks receive as `input.channel`; narrow it with
* {@link isChannel}.
*/
export type InstrumentationChannel = {
readonly [K in InstrumentationChannelKind]: InstrumentationChannelForKind<K>;
}[InstrumentationChannelKind];
type ChannelReferenceKind<TChannel> = {
readonly [K in keyof ChannelReferenceMap]: [TChannel] extends [ChannelReferenceMap[K]] ? [ChannelReferenceMap[K]] extends [TChannel] ? K : never : never;
}[keyof ChannelReferenceMap];
/**
* The {@link InstrumentationChannel} arm matching the app-owned channel value
* `TChannel`, resolved through its compiler-derived `channel:<slug>` identity in
* {@link ChannelReferenceMap}. Used as the narrowed type produced by
* {@link isChannel}.
*/
export type InstrumentationChannelForChannel<TChannel> = Extract<InstrumentationChannel, {
readonly kind: Extract<ChannelReferenceKind<TChannel>, InstrumentationChannelKind>;
}>;
/**
* Narrows a channel by comparing it to an app-owned channel value imported
* from `agent/channels/*`.
*
* Works with both instrumentation resolver inputs (`input.channel`) and
* dynamic resolver inputs (`ctx.channel`). The comparison uses the
* compiler's path-derived `channel:<slug>` identity. Metadata narrows to
* the channel's declared `ChannelMetadataMap` entry on success.
*/
export declare function isChannel<TChannel extends Channel<any, any, any>>(channel: InstrumentationChannel | {
readonly kind?: string;
}, target: TChannel): channel is InstrumentationChannelForChannel<TChannel>;