import { ContextProjection, ModeProjection } from "../../types/hub.mjs"; import { SessionSelectionAnswer } from "./sessionSelectionApi.mjs"; import { PoApprovalPrompt, ToolResultView } from "@agimon-ai/po-core/web"; import { SessionLifecycle, TranscriptImageRef } from "@agimon-ai/po-core/sessionProtocol"; //#region src/web/lib/sessionModel.d.ts export type EntryKind = 'user' | 'assistant' | 'tool' | 'notice'; export interface UserImage { /** Base64 bytes. Absent from an image a transcript sent by reference, until its saved entry is read. */ data?: string; mimeType: string; /** Where the saved entry keeps the bytes of an image sent by reference. */ ref?: TranscriptImageRef['ref']; } /** Who sent an input, as the host stamped it on the input's envelope. */ export interface InputSender { kind: 'human' | 'agent' | 'system'; id?: string; name: string; } export interface UserEntry { kind: 'user'; id: string; text: string; images?: UserImage[]; /** Present only when the host recorded who sent it; a typed prompt here has none. */ sender?: InputSender; /** A steer the server holds in its inbox; its journal entry replaces it once the agent places it. */ pending?: true; } export interface AssistantEntry { kind: 'assistant'; id: string; text: string; thinking: string; streaming: boolean; /** Provider model, used with the message timestamp to reconcile repeated starts. */ model?: string; /** * The persona active when this message was written. * * Stamped at creation rather than read from current state, so a profile * switch leaves earlier messages showing who actually wrote them. Replay * reproduces it because the identity entry is folded in journal order. */ identity?: ProfileIdentity; } /** Display name and avatar of the persona a message was written under. */ export interface ProfileIdentity { profile: string; name?: string; icon?: string; } export interface ToolEntry { kind: 'tool'; id: string; toolCallId: string; name: string; /** The call arguments as the frame carried them, for a plugin's own renderer. */ args: Record; argSummary: string; /** The newest result, partial while running; null before the tool produced any. */ result: ToolResultView | null; output: string; isError: boolean; running: boolean; } export interface NoticeEntry { kind: 'notice'; id: string; text: string; tone: 'info' | 'error'; } /** A message another agent sent this session over the team intercom, named for a person to read. */ export interface IntercomEntry { kind: 'intercom'; id: string; /** `send` is a plain message; `ask` wants an answer; `reply` and `no_reply` close an earlier ask. */ intent: 'send' | 'ask' | 'reply' | 'no_reply'; /** The sender's first name when it has an identity (`faris-c-6` is Faris), else its member name. */ name: string; /** The seed that keeps the sender's avatar colour fixed. */ seed: string; /** The agent definition behind a named sender, empty when the name already is it. */ role: string; text: string; } export interface SettledEntry { kind: 'settled'; id: string; tools: number; /** Canonical journal members verified by the runtime, absent in legacy history. */ entryIds?: readonly string[]; } export interface QueuedEntry { kind: 'queued'; id: string; text: string; delivery?: 'steer' | 'followUp' | 'nextRun'; scheduling?: 'automatic' | 'held'; disposition?: 'pending' | 'handoff'; images?: UserImage[]; } export type TimelineEntry = (UserEntry | AssistantEntry | ToolEntry | NoticeEntry | IntercomEntry | SettledEntry | QueuedEntry) & { timestamp?: number; /** Runtime-verified agent run, never inferred from transcript position. */ turnId?: string; /** Canonical journal identity, retained when a local or tool card id differs. */ sourceEntryId?: string; /** Other canonical records represented by this card, such as its tool result. */ sourceEntryIds?: readonly string[]; }; export interface SessionStats { cost: number; totalTokens: number; contextPercent: number | null; contextTokens: number | null; contextWindow: number | null; } export interface AgentInfo { model: string; /** The provider Pi resolved the model under; set_model needs both halves. */ provider: string; thinkingLevel: string; sessionId: string; sessionName: string; messageCount: number; isStreaming: boolean; } export interface CommandInfo { name: string; description: string; source?: string; } /** One model the session can switch to, as get_available_models lists it. */ export interface ModelChoice { provider: string; id: string; name: string; reasoning: boolean; } export type DialogMethod = 'select' | 'confirm' | 'input' | 'editor'; export interface DialogRequest { id: string; method: DialogMethod; title: string; message: string; options: string[]; /** A second line per option, parallel to `options`, when the request supplies any. */ descriptions?: string[]; /** An image `data:` URL per option, parallel to `options`; empty where an option has none. */ icons?: string[]; placeholder: string; prefill: string; approval?: PoApprovalPrompt; } export interface EditorTextRequest { append?: boolean; id: string; text: string; } export interface SessionState { entries: TimelineEntry[]; hasNewerHistory: boolean; /** Running tool frames kept outside the protocol-owned transcript so prompt plugins can claim their dialogs. */ activeTools: ToolEntry[]; /** * Footer status entries keyed as the publishing extension named them, raw so * the colour survives. A key that is absent means the package is not in this * composition; a key holding an empty string means it is loaded but off. */ statuses: Record; /** Widget keys the session has announced, the only signal some modes give. */ widgets: string[]; streaming: boolean; settled: boolean; /** Latest authoritative server execution and retained-input snapshot. */ lifecycle: SessionLifecycle | null; stats: SessionStats | null; /** * Cost the assistant message now streaming has run up, on top of `stats`. * * Pi answers `get_session_stats` once per message at best, so without this * the cost chip sits still for the length of a turn. Zero whenever no * message is streaming or the provider has not reported yet. */ liveCost: number; agent: AgentInfo | null; commands: CommandInfo[]; /** Models the session offered, empty until the picker asks. */ models: ModelChoice[]; /** Thinking levels the current model accepts, empty until the picker asks. */ fastMode: boolean; /** True while the session's local agent is blocked from starting turns. */ agentLocked: boolean; thinkingLevels: string[]; dialog: DialogRequest | null; /** Latest fire-and-forget editor replacement requested by a session extension. */ editorTextRequest: EditorTextRequest | null; /** The runtime's mode catalog as last journaled, or null before it reports. */ modes: ModeProjection | null; /** What the session is composed of, as last journaled, or null before it reports. */ context: ContextProjection | null; /** * The persona most recently journaled, used to stamp assistant messages as * they are created. Not a projection: folding it forward in journal order is * what keeps a pre-switch message attributed to the persona that wrote it. */ profileIdentity: ProfileIdentity | null; /** Tool calls seen since the current run began, reported when it settles. */ toolsThisRun: number; /** * Journal entry ids already folded into the timeline. The hub re-reads the * journal on every attach, so a reconnect replays entries this page already * has; folding by id is what keeps a restored transcript from doubling. */ restoredIds: string[]; /** * Prompts this page put on screen before the journal recorded them, newest * last. The cockpit shows your message the moment you send it, but the * journal is what carries every message, including the ones an extension * sends on your behalf. Matching a journal message against this list is what * lets both appear exactly once. */ pendingUserEntries: { id: string; text: string; images?: UserImage[]; }[]; /** * Prompts an authoritative transcript already folded into the entry this page * rendered, newest last. * * A prompt reaches the timeline from two directions, Pi's protocol snapshot * and the session journal, and whichever lands first consumes the pending * record. Without this the second arrival has nothing to match and appends a * second copy of the message, which is what a reader sees when transcript * ownership returns to the journal mid-session. */ reconciledUserEntries: { id: string; text: string; images?: UserImage[]; }[]; /** Stable local ids for optimistic prompts after Pi publishes their canonical transcript entries. */ protocolUserEntryIds: Record; /** Verified journal ownership retained even when its protocol item has not arrived yet. */ transcriptTurnIds: Record; nextId: number; /** In-flight steers from the server lifecycle, newest last, ids `steer:`. */ pendingSteers: readonly UserEntry[]; /** Submission ids whose journal entry already landed, so an older lifecycle frame cannot bring them back. */ placedSteers: readonly string[]; } export declare const initialSessionState: SessionState; type Frame = Record; /** Joins the text blocks of a Pi content array, ignoring non-text parts. */ export declare function textFromContent(content: unknown): string; export declare function isSupportedImageMimeType(mimeType: string): boolean; /** Keeps only image blocks the cockpit can safely render as data URLs, inline or sent by reference. */ export declare function imagesFromContent(content: unknown): UserImage[]; /** A one-line description of a tool call, good enough for a card header. */ export declare function summariseArgs(args: unknown): string; /** Provider error payloads can include credentials, so only render a fixed failure explanation. */ export declare function assistantFailureText(message: unknown): string; export declare function selectionStatuses(selection: { preset: string; domains: string[]; profile?: string | null; }): Record; export declare function applySelectionAnswer(state: SessionState, answer: SessionSelectionAnswer): SessionState; /** * Folds an older window of transcript above what the page already holds. * * The reducer is append-only by design: it builds the timeline as the session * produces it. Paging backwards is the one case that runs the other way, so * the window is reduced on its own and the result is prepended, rather than * teaching every case in the reducer about a second direction. * * Entry ids are positional, so a window reduced from scratch would collide * with the live entries. Prefixing by page keeps every key unique and stable * across re-renders, which is what a virtualised list needs to keep its * measurements. */ export declare function prependHistory(state: SessionState, frames: readonly Frame[], page: number): SessionState; export interface ReduceSessionOptions { /** * The protocol supplies the transcript, so this reducer must not build one. * * Both would otherwise write the same timeline from different sources: the * snapshot replaces it wholesale while these frames append to it, and the * result flickers between the two. The frames still reach here for * everything else they carry, which is why this is a filter rather than a * missing subscription. */ transcriptFromProtocol?: boolean; } export declare function reduceSession(state: SessionState, frame: Frame, options?: ReduceSessionOptions): SessionState; /** Records the prompt locally, because Pi does not echo it back as an event. */ export declare function appendUserPrompt(state: SessionState, text: string, images?: UserImage[]): SessionState; /** A follow-up waits for the current run, so it is marked rather than shown as sent. */ export declare function appendQueued(state: SessionState, text: string, images?: UserImage[]): SessionState; /** Uses server IDs as-is: equal text or a snapshot revision is not an item identity. */ export declare function replaceQueuedEntries(state: SessionState, queue: readonly QueuedEntry[]): SessionState; /** Removes queued rows and their reconciliation records after Pi clears the queue. */ export declare function clearQueuedEntries(state: SessionState): SessionState; /** Removes one queued row and the optimistic reconciliation record tied to it. */ export declare function removeQueuedEntry(state: SessionState, id: string): SessionState; export declare function clearDialog(state: SessionState): SessionState; //#endregion export {}; //# sourceMappingURL=sessionModel.d.mts.map