Hooks
useKivaAgentThreads
Lists, renames, deletes and loads the messages of Kiva AI assistant chat threads.
iOSAndroidExpo Go
Installation
pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-kiva-agent-threadsRequired Packages(2 packages)
pnpm add @tanstack/react-query aiA verbatim port of the web hook. It manages the thread records (thread_type: 'assistant') of an agent and turns stored messages into AI SDK UIMessage[], ready for useChat().setMessages. useKivaAgentChat already embeds it.
Endpoints: GET /v1/apps/base/data-sources/thread/items (list), PATCH …/thread/items/{id} (rename), DELETE …/thread/items/{id} (delete), GET /v1/apps/base/data-sources/message/items (messages, max 200).
Usage
import { KivaAgentThreadsSidebar } from '@/components/kiva-native/kiva-agent';
import { useKivaAgentThreads } from '@/hooks/kiva-native/use-kiva-agent-threads';
const threads = useKivaAgentThreads({ client, agentId: AGENT_ID, userId: user?.id });
<KivaAgentThreadsSidebar
agent={agent}
threads={threads.threads}
isLoading={threads.isLoading}
onSelectThread={async thread => setMessages(await threads.loadMessages(thread.id))}
onRenameThread={(thread, subject) => threads.renameThread(thread.id, subject)}
onDeleteThread={thread => threads.deleteThread(thread.id)} />API Reference
UseKivaAgentThreadsArgs
| Option | Type | Default | Description |
|---|---|---|---|
client | KivaAgentThreadsClient | null | undefined | - | Client with get / post / patch / delete |
agentId | string | - | Tenant AI agent ID (required) |
userId | string | null | null | Only threads owned by / shared with this user |
projectId | string | null | null | Only threads of this project |
deploymentId | string | null | null | Filter by deployment instead of agent |
enabled | boolean | !!client | Toggle the list query |
UseKivaAgentThreadsResult
| Field | Type | Description |
|---|---|---|
threads | KivaAgentThread[] | { id, title, createdAt, updatedAt, bodyText?, createdBy?, createdByName?, projectId? }, newest first |
isLoading / error | boolean / Error | null | List query state |
refresh | () => Promise<void> | Invalidate the list |
loadMessages | (threadId) => Promise<UIMessage[]> | Messages as UIMessage[] (from body_json.parts, else body_text) |
isLoadingMessages | boolean | loadMessages pending |
renameThread | (threadId, subject) => Promise<boolean> | Rename |
isRenaming | boolean | Rename pending |
deleteThread | (threadId) => Promise<boolean> | Delete |
isDeleting | boolean | Delete pending |