Skip to content

@sqlrooms/ai / AiSliceState

Type Alias: AiSliceState

AiSliceState = object

Properties

ai

ai: object

NameTypeDescription
initialize()?() => Promise<void>-
destroy()?() => Promise<void>-
configAiSliceConfig-
promptSuggestionsVisibleboolean-
draftPromptstringTransient composer prompt used before the first session is created.
apiKeyErrorsRecord<string, boolean>Tracks API key errors per provider (e.g., 401/403 responses)
toolsStoredToolSet-
toolRenderersToolRendererRegistry-
remoteClientToolNamesstring[]Executable local tools that await browser output with remote chat.
timeoutsAiTimeoutOptionsOpt-in timeout policy for chat runs and tool execution.
getProviderOptions?GetProviderOptions-
setConfig()(config) => void-
setPromptSuggestionsVisible()(visible) => void-
setDraftPrompt()(prompt) => voidUpdate the transient composer prompt used when no session is active.
setApiKeyError()(provider, hasError) => voidSet API key error flag for a provider
hasApiKeyError()() => booleanCheck if there's an API key error for the current provider
getAbortController()(sessionId) => AbortController | undefined-
setAbortController()(sessionId, controller) => void-
getSessionChat()(sessionId) => Chat<UIMessage> | undefinedReturn the ephemeral AI SDK chat for a session.
setToolCallSession()(toolCallId, sessionId) => voidMap toolCallId -> sessionId for long-running tool streams (e.g. agent tools)
getToolCallSession()(toolCallId) => string | undefined-
agentProgressRecord<string, AgentToolCall[]>Live progress for sub-agent tool calls, keyed by parent toolCallId
updateAgentProgress()(parentToolCallId, toolCalls) => void-
clearAgentProgress()(parentToolCallId) => void-
devtoolsAiDevtoolsStateDevtools-only agent snapshot state and controls.
pendingSubAgentApprovalsRecord<string, PendingSubAgentApproval>Pending approval requests from sub-agent tools with needsApproval
requestSubAgentApproval()(approval) => void-
resolveSubAgentApproval()(approvalId, approved) => void-
clearSubAgentApproval()(approvalId) => void-
writeAbortSnapshot()(toolCallId, snapshot) => voidTransient abort snapshots for nested agent progress propagation
readAbortSnapshot()(toolCallId) => AgentProgressSnapshot | undefined-
clearAbortSnapshots()() => void-
isSummarizingbooleanTrue while "summarize and continue" is in progress
setIsSummarizing()(value) => void-
toolTimingsRecord<string, ToolTimingEntry>Per-tool-call timing entries, keyed by toolCallId
setToolTiming()(toolCallId, entry) => void-
getToolTimings()() => Record<string, ToolTimingEntry>-
setPrompt()(sessionId, prompt) => void-
getPrompt()(sessionId) => string-
setIsRunning()(sessionId, isRunning) => void-
getIsRunning()(sessionId) => boolean-
addAnalysisResult()(message) => void-
sendPrompt()(prompt, options?) => Promise<string>-
startAnalysis()(sessionId, attachments?) => Promise<void>-
startAnalysisWhenReady()(sessionId, attachments?) => Promise<boolean>Compatibility entry point; session controllers are ready synchronously.
startNewSession()(name, prompt) => Promise<void>-
cancelAnalysis()(sessionId) => void-
setAiModel()(modelProvider, model) => void-
getSelectedModel()() => ModelSelectionResolve the model/provider that would be used right now: the current session's selection when a session exists, otherwise the default that a lazily created session would receive. Useful before any session exists, e.g. to know which provider a first-time API key belongs to.
hasResolvableModel()() => booleanWhether a model is resolvable by any configured path: a custom-model factory supplied to AiSliceOptions.getCustomModel, or — once a session exists — its provider/model pair being present in the @sqlrooms/ai-settings model list. With no session yet, the resolved default is assumed available. Only checks that a factory was configured; never calls it, since invoking it may have side effects and a factory returning undefined means "configured but not currently ready". Prefer this over re-deriving readiness from aiSettings.config, so UI and runtime agree on one source of truth.
requiresApiKey()() => booleanWhether the model resolution path in effect needs a browser-held API key. false only when a chatEndPoint is configured (the request is sent server-side), or when AiSliceOptions.getCustomModel is configured and currently returns a model, which carries its own credentials. A factory returning undefined still needs one: the transport then falls back to the built-in OpenAI-compatible client. Unlike AiSliceState.ai.hasResolvableModel this invokes the factory, so keep it cheap — it is called during render. The result is cached per selection and retired when the AI settings change.
createSession()(name?, modelProvider?, model?) => stringCreate a new chat session, make it the current session, and open it in a tab. When modelProvider/model are omitted the current selection (or configured defaults) are used.
forkSessionFromMessage()(args) => string | undefined-
getSessionForkOrigin()(sessionId) => AiSessionForkOrigin | undefined-
switchSession()(sessionId) => void-
resetCurrentSession()() => voidClear the current session selection (sets currentSessionId to undefined) without deleting any session, returning the UI to the start/new-chat state. A fresh session is created lazily on the next message.
renameSession()(sessionId, name) => void-
deleteSession()(sessionId) => void-
setOpenSessionTabs()(tabs) => void-
togglePinSession()(sessionId) => voidToggle the pinned state of a session. Pinning an unknown session id is a no-op; unpinning is always allowed (also used to drop stale ids).
isPinnedSession()(sessionId) => boolean
getCurrentSession()() => ChatSessionSchema | undefined-
getSessionRunContext()(sessionId) => AiRunContext | undefined-
setSessionRunContext()(sessionId, runContext) => void-
getSessionDraftContextItemIds()(sessionId) => string[] | undefined-
setSessionDraftContextItemIds()(sessionId, itemIds) => void-
setSessionUiMessages()(sessionId, uiMessages) => boolean-
persistTimedOutSession()(sessionId, uiMessages, timeoutMessage) => voidPersist a terminal timeout result and force the chat runtime to reload.
getAnalysisResults()() => AnalysisResultSchema[] | undefined-
deleteAnalysisResult()(sessionId, resultId) => void-
getAssistantMessageParts()(analysisResultId) => UIMessage["parts"]-
findToolRenderer()(toolName) => ToolRenderer | undefined-
getApiKeyFromSettings()(provider?, model?) => stringResolve the API key for the outbound provider. When provider/model are omitted the current session's provider (or the default) is used; callers targeting a specific provider (e.g. one-shot sendPrompt) must pass it so the key matches the endpoint the request is sent to.
getBaseUrlFromSettings()(provider?, model?) => string | undefinedResolve the base URL for the outbound provider. See AiSliceState.ai.getApiKeyFromSettings for the provider/model override semantics.
getMaxStepsFromSettings()() => number-
getFullInstructions()(sessionId?) => string-
getLocalChatTransport()(sessionId) => DefaultChatTransport<UIMessage>-
chatEndPointstringOptional remote endpoint to use for chat; if empty, local transport is used
chatHeadersRecord<string, string>-
getRemoteChatTransport()(sessionId, endpoint, headers?) => DefaultChatTransport<UIMessage>-
onChatFinish()(args) => void-
onChatError()(sessionId, error, messages?) => void-