# useDocyrusAgentThreads URL: /docs/native/hooks/use-docyrus-agent-threads Lists, renames, deletes and loads the messages of Docyrus AI assistant chat threads. ## Installation ```bash pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-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`. [`useDocyrusAgentChat`](/docs/native/hooks/use-docyrus-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 { DocyrusAgentThreadsSidebar } from '@/components/docyrus-native/docyrus-agent'; import { useDocyrusAgentThreads } from '@/hooks/docyrus-native/use-docyrus-agent-threads'; const threads = useDocyrusAgentThreads({ 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 ### UseDocyrusAgentThreadsArgs | Option | Type | Default | Description | |--------|------|---------|-------------| | `client` | `DocyrusAgentThreadsClient \| 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 | ### UseDocyrusAgentThreadsResult | Field | Type | Description | |-------|------|-------------| | `threads` | `DocyrusAgentThread[]` | `{ 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 |