# useKivaAgentThreads URL: /docs/native/hooks/use-kiva-agent-threads Lists, renames, deletes and loads the messages of Kiva AI assistant chat threads. ## Installation ```bash pnpm dlx @kivacore/ui-cli add @kivacore/rn-hooks-use-kiva-agent-threads ``` **Dependencies:** - [@tanstack/react-query](https://www.npmjs.com/package/@tanstack/react-query) - [ai](https://www.npmjs.com/package/ai) A 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`](/docs/native/hooks/use-kiva-agent-chat) 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 ```tsx 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 }); 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` | Invalidate the list | | `loadMessages` | `(threadId) => Promise` | Messages as `UIMessage[]` (from `body_json.parts`, else `body_text`) | | `isLoadingMessages` | `boolean` | `loadMessages` pending | | `renameThread` | `(threadId, subject) => Promise` | Rename | | `isRenaming` | `boolean` | Rename pending | | `deleteThread` | `(threadId) => Promise` | Delete | | `isDeleting` | `boolean` | Delete pending |