/** * Shared building blocks for the two direct-turn entry points (streaming * webchat realtime and one-shot CLI). Both flows do the same hydrate → maybe-slash * → run-embedded-turn → after-turn dance; this module captures that core so * the entry points only manage their I/O specifics (event sink, voice STT, * TTS, transcript persistence). */ import type { AgentMessage } from '@earendil-works/pi-agent-core'; import type { ImageContent } from '@earendil-works/pi-ai'; import type { CommandHandler } from '../messaging/command-handler.js'; import type { CommandStreamEvent } from '../../chat-commands/types.js'; import type { SessionStore } from '../../session/index.js'; import type { Config } from '../../config/schema.js'; import type { AgentInstanceGateway } from '../agent-instance-gateway.js'; import type { ModelManager } from '../models/index.js'; import type { EmbeddedStreamEvent } from '../embedded/types.js'; export interface HydratePerTurnStateDeps { hydrateSessionWorkspaceFromStore: (sessionKey: string) => Promise; hydrateSessionModelFromStore: (sessionKey: string) => Promise; applyResolvedThinkingLevel: (sessionKey: string, thinking?: string | null) => Promise; } /** Workspace + model + thinking level — common prep before any direct turn. */ export declare function hydratePerTurnState(deps: HydratePerTurnStateDeps, sessionKey: string, thinking?: string): Promise; export interface SlashCommandTask { /** True if the input parsed as a registered slash command (handled or not). */ matched: boolean; /** Aggregated user-visible reply text (assistant view). */ aggregatedText: string; /** The parsed command name when matched. */ command?: string; /** Structured command result metadata for webchat and other rich clients. */ metadata?: Record; } export interface TryRunSlashCommandDeps { commandHandler: Pick; log: { warn: (obj: Record, msg: string) => void; }; } /** * Detect a slash command and, if registered, execute it and aggregate the reply * text. Errors thrown inside the command surface as `aggregatedText` so callers * can persist the receipt or stream it as a token. */ export declare function tryRunSlashCommand(deps: TryRunSlashCommandDeps, ctx: { sessionKey: string; channel: string; chatId: string; senderId?: string; isGroup?: boolean; inboundMetadata?: Record; }, content: string, options?: { skipResetCommands?: boolean; emitEvent?: (event: CommandStreamEvent) => void | Promise; }): Promise; export interface RunDirectAgentTurnDeps { sessionStore: SessionStore; agentManager: AgentInstanceGateway; modelManager: ModelManager; config: Config | undefined; } export interface RunDirectAgentTurnInput { sessionKey: string; runId?: string; userMessage: AgentMessage; abortSignal?: AbortSignal; deadlineAtMs?: number; sourceImages?: ImageContent[]; onEvent?: (event: EmbeddedStreamEvent) => void; } export interface RunDirectAgentTurnResult { ok: boolean; errorMessage?: string; lastAssistantText?: string; } /** * Convert a user message into an embedded turn, including the standard memory * prefetch + background-review nudge wiring used by every direct entry point. */ export declare function runDirectAgentTurn(deps: RunDirectAgentTurnDeps, input: RunDirectAgentTurnInput): Promise;