Hooks

useDocyrusAgentAttachments

Uploads chat attachments to a Docyrus agent thread (creating the thread on first use) and returns the storage paths for the chat request.

iOSAndroidExpo Go

Installation

pnpm dlx @docyrus/cli add @docyrus/rn-hooks-use-docyrus-agent-attachments
Required Packages(1 package)
pnpm add ai

Port of the web hook with one native change: the web hook fetches each file's blob: URL; on React Native FileUIPart.url is the local file:// / content:// URI returned by the picker, so the upload appends the RN FormData file shape { uri, name, type } instead. Thread state is controlled: pass the active threadId (null for a new chat) and capture the created id with onThreadCreated. useDocyrusAgentChat already embeds it.

Endpoints: POST /v1/apps/base/data-sources/thread/items (create thread, thread_type: 'assistant') and POST /v1/apps/base/data-sources/thread/items/{threadId}/files/upload (multipart file).

Usage

const [threadId, setThreadId] = useState<string | null>(null);
const { resolveFilePaths, ensureThread } = useDocyrusAgentAttachments({
  client, agentId: AGENT_ID, threadId, onThreadCreated: setThreadId
});

const onSendMessage = async ({ text, files }: AgentMessagePayload) => {
  await ensureThread(text);
  const { filePaths } = files?.length ? await resolveFilePaths(files, text) : { filePaths: [] };

  await sendMessage({ text }, { body: { files: filePaths, supportFiles: filePaths.length > 0 } });
};

API Reference

UseDocyrusAgentAttachmentsArgs

OptionTypeDefaultDescription
clientDocyrusAgentAttachmentsClient | null | undefined-Client with post(url, body)
agentIdstring-Tenant AI agent ID (required)
threadIdstring | null-Current thread; null → first call creates one (required)
onThreadCreated(threadId: string) => void-Fires when a new thread is created
projectIdstring | nullnullProject scope of new threads
deploymentIdstring | nullnullDeployment scope of new threads
senderNamestring'User'sender_name of new threads
threadSubject(messageText: string) => stringfirst 100 charsSubject of new threads

UseDocyrusAgentAttachmentsResult

FieldTypeDescription
resolveFilePaths(files: FileUIPart[], messageText: string) => Promise<{ filePaths: string[]; threadId: string | null }>Uploads every file, returns storage paths
ensureThread(messageText: string) => Promise<string | null>Returns the current thread id or creates one

On this page