useChatStore
useChatStore<T>(selector: (state: ChatStoreState) => T): T
The useChatStore()
hook makes it easy to create support chat interfaces. It provides API bindings, state management, function calling and abort handling capabilities.
Basic example
Hook API
The useChatStore()
hook is similar to the useStore()
hook of Zustand, wherein you pass a function that takes the state object and returns a specific value:
ChatStoreState
Prop | Type | Description |
---|---|---|
projectKey | string | The project key associated to the project. |
apiUrl | string | The base API URL. |
abort | () => void | Abort handler. |
threadId | string | The current thread id. |
setThreadId | (threadId: string) => void | Set a thread id. |
selectThread | (threadId?: string) => void | Select a thread. |
messages | ChatViewMessage[] | The messages in the current thread. |
setMessages | (messages: ChatViewMessage[]) => void | Set messages. |
setMessageByIndex | (index: number, next: Partial<ChatViewMessage>) => void | Set a message by index. |
setToolCallById | (toolCallId: string, next: Partial<ToolCall>) => void | Set a tool call by id. |
threadIdsByProjectKey | { [projectKey: string]: string[] } | Dictionary of threads by project id. |
messagesByThreadId | { [threadId: string]: ThreadData } | Dictionary of messages by thread id. |
toolCallsByToolCallId | { [tool_call_id: string]: ToolCall } | Dictionary of tool calls by id. |
submitChat | (messages: SubmitChatMessage[]) => void | Submit a list of new messages. |
submitToolCalls | (message: ChatViewMessage) => Promise<void> | Submit tool calls. |
options | MarkpromptOptions['chat'] | User configurable chat options. |
setOptions | (options: UserConfigurableOptions) => void | Set the chat options for this session. |
didAcceptDisclaimerByProjectKey | { [projectKey: string]: boolean } | Dictionary of disclaimer acceptance by project id. |
didAcceptDisclaimer | boolean | Acceptance state of the disclaimer. |
setDidAcceptDisclaimer | (accept: boolean) => void | Set the acceptance state of the disclaimer. |
regenerateLastAnswer | () => void | Trigger a regeneration of the last answer. |