React hooks
Headless React hooks for auth, progress, chat, approvals, and entities.
@lunnoa/client/react ships headless React hooks for Pattern B portals. There are no UI components: you render with your own design system. All hooks (except auth bootstrap) need a surrounding LunnoaAuthProvider.
These examples assume a Pattern B app from the Authentication guide.
Peers
| Package | Required when |
|---|---|
react ≥ 18 | Any @lunnoa/client/react import |
@ai-sdk/react | Only for useAgentChat (pairs with the ai dependency already on @lunnoa/client) |
npm install @lunnoa/client react
npm install @ai-sdk/react # only if you use useAgentChatAuth (provider)
See Authentication for LunnoaAuthProvider, useLunnoaAuth, useLunnoaClient, and useAccessToken.
Execution progress
useExecutionProgress(executionId | null) subscribes via executions.watchProgress, keeps the latest snapshot, and aborts on unmount or id change.
Needs input
useNeedsInput(executionOrProgress) derives the waiting NEEDS_INPUT step and optional pendingInput field schema, then exposes submitInput(values).
Null or non-waiting sources return waiting: false without throwing.
Agent chat
useAgentChat(agentId, taskId?) is a thin wrapper around AI SDK useChat + DefaultChatTransport, pointed at:
${baseUrl}/api/agents/${agentId}/tasks/${taskId}/stream-message
with a Bearer token from the auth provider. If taskId is omitted, the hook generates one with crypto.randomUUID() and keeps it for the hook lifetime.
For lower-level streaming without React, use lunnoa.agentChat.streamMessage from the Agent chat guide.
Approvals inbox
useApprovalsInbox(options?) loads approvals.inbox() for the current user. Polling is off by default; pass pollIntervalMs: 15_000 for a live inbox.
After decide, the hook refreshes the inbox.
Entity list
useEntityList({ objectTypeSlug, ...listOptions }) wraps entities.list with page state and light filter helpers.
Options match ListEntitiesOptions from the core SDK. setSearch / setState reset to page 1.
Related
- Authentication: provider and session helpers
- Execution progress:
getProgress/watchProgress - Agent chat: SSE protocol details
- Approvals: inbox and decide
- Entities: list filters and expansion