Skip to main content
Version: Next

Type Alias: LLMChatSession

LLMChatSession = object

Defined in: extensions/llm/tasks/llmChatSession.ts:103

Handle to an active LLM chat session.

Methods​

dispose()​

dispose(): void

Defined in: extensions/llm/tasks/llmChatSession.ts:119

Disposes native model weights, KV cache, and tokenizer runtime resources.

Returns​

void


getHistory()​

getHistory(): readonly ChatMessage[]

Defined in: extensions/llm/tasks/llmChatSession.ts:124

Returns a snapshot of the current message history in the session.

Returns​

readonly ChatMessage[]


getKVCacheState()​

getKVCacheState(): LLMKVCacheState

Defined in: extensions/llm/tasks/llmChatSession.ts:129

Returns current KV cache occupancy and total capacity statistics for the session runner.

Returns​

LLMKVCacheState


reset()​

reset(): void

Defined in: extensions/llm/tasks/llmChatSession.ts:114

Restores the initial messages and rewinds the KV cache position to zero. The next turn re-prefills those messages using the loaded model.

Returns​

void

Throws​

With code RESOURCE_BUSY if a turn is in progress.


sendMessage()​

sendMessage(message, onToken?, genConfig?): Promise<LLMChatTurnResult>

Defined in: extensions/llm/tasks/llmChatSession.ts:141

Sends a user message or chat turn to the model and generates a response.

Parameters​

message​

ChatMessageContent

Message string or interleaved media payload array.

onToken?​

(token) => void

Callback fired on the RN thread for each decoded token.

genConfig?​

LLMGenerationConfig

Generation options overriding session defaults.

Returns​

Promise<LLMChatTurnResult>

A promise resolving to the generated messages and turn stats.

Throws​

With code INVALID_ARGUMENT if the message is malformed, INVALID_STATE if the chat template is non-monotonic, or RESOURCE_BUSY if another turn is in progress.


stop()​

stop(): void

Defined in: extensions/llm/tasks/llmChatSession.ts:107

Stops active generation and discards the current turn after its tool calls finish.

Returns​

void