import type { ContextAccessor } from "#context/key.js"; import { type ChannelDeliverySource } from "#channel/delivery-metadata.js"; import type { MessageStreamEvent } from "#protocol/message.js"; import type { UserContent } from "ai"; import type { CancelTurnResult, ClearSessionResult, CompactSessionResult, GetEventStreamOptions, ResetSessionResult, Runtime, SessionAuthContext, SessionCallback, SessionSendCommandResult, TurnPolicy, TurnCaller } from "#channel/types.js"; import type { SessionAuth } from "#context/keys.js"; import { type InputResponse, type StrictInputResponses } from "#shared/input.js"; import type { JsonObject } from "#shared/json.js"; /** Immutable-ID handle for one exact durable session. */ export interface Session { readonly id: string; /** * Sends a message to this exact session ID without creating or following a * replacement. Throws `SessionStrandedError` when the session's owner cannot * execute here; nothing is delivered. Call {@link reset} to end it. */ send(message: string | UserContent, options: SessionSendOptions): Promise; /** Answers pending input requests on this exact session ID. Throws `SessionStrandedError` like {@link send}. */ respond(inputResponses: StrictInputResponses, options: SessionRespondOptions): Promise; /** Requests cancellation of this exact session's active turn. */ cancel(options?: { turnId?: string; }): Promise; /** Queues compaction on this exact session ID. */ compact(): Promise; /** Queues a context clear on this exact session ID. */ clear(): Promise; /** Terminally retires this exact session ID. */ reset(options?: { reason?: string; }): Promise; /** * Opens the recorded stream. Following it throws `SessionStrandedError` * while its owner is stranded; `follow: false` reads recorded history up to * the current tail without inspecting or changing the session. */ getEventStream(options?: GetEventStreamOptions): Promise>; getStreamTailIndex(): Promise; } interface SessionDeliveryOptions { readonly auth: SessionAuthContext | null; /** Public callback destination for a delegated continuation turn. */ readonly callback?: SessionCallback; readonly context?: readonly string[]; readonly outputSchema?: JsonObject; } /** Options for sending a message through a fixed session handle. */ export type SessionSendOptions = SessionDeliveryOptions & { /** Initial workflow title for a prewarmed session. */ readonly title?: string; readonly turnPolicy?: TurnPolicy; }; /** Options for answering pending input requests through a fixed session handle. */ export type SessionRespondOptions = SessionDeliveryOptions; /** * Live handle to the current session, exposed on `ctx.session` to * `deliver` and event handlers. The framework hydrates the read-only * fields from the active context at step start. A write through * `continuation.alias()` selects a new current address and records it so the * runtime can add its hook to the session inbox at the next step boundary. * Previously claimed addresses remain active. */ export interface SessionHandle { readonly id: string; readonly auth: SessionAuth; readonly continuation?: { readonly token: string; alias(rawToken: string): void; }; } export declare function createSession(id: string, runtime: Runtime, metadata?: Partial & { readonly turnPolicy?: TurnPolicy; }): Session; /** Builds an I/O-free factory for fixed session-ID handles. */ export declare function createAttachSessionFn(runtime: Runtime, metadata?: Partial & { readonly turnPolicy?: TurnPolicy; }): (sessionId: string) => Session; /** * Builds a live {@link SessionHandle} backed by the active context * accessor. Read-only fields resolve through getters so they reflect * any updates made by other handlers within the same step (e.g. the * `deliver` hook seeding `AuthKey` before an event handler reads * `session.auth`). * * Used by {@link buildAdapterContext} to populate `ctx.session` on * every adapter handler invocation. */ export declare function buildSessionHandle(accessor: ContextAccessor): SessionHandle; /** @internal Converts validated public callback metadata into runtime turn routing. */ export declare function sessionCallbackToTurnCaller(callback: SessionCallback | undefined): TurnCaller | undefined; export {};