PAIPAI

useThread()

Thread handle without the chat transcript subscription.

useThread is the same ThreadController as useChat(), without messages / isRunning / activity. Use it for thread.commands and other handle APIs so the component does not re-render on every transcript change.

const { thread } = Assistant.useThread();
await thread.commands.rateResponse({ runId, rating: "up" });

Also on this binding: useClient, useAction.

Import

const { thread } = Assistant.useThread();

Signature

function useThread(): ThreadController<TContract>;
function useThreadState(): ThreadState<TContract>;
function useThreadSelector<TSelected>(
  selector: (state: ThreadState<TContract>) => TSelected,
): TSelected;

Returns

useThreadState() returns state only. useThreadSelector re-renders only when the selected slice changes.

useClient

function useClient(): AgentClient<TContract>;

Requires Pai.Provider. Does not require ThreadProvider.

A AgentClient<TContract>.

newThreadId(), thread(), threads.list(), files.upload / url / read.

useAction

function useAction<TAction extends PendingActionView<TContract>>(
  action: TAction,
): PendingActionController<TContract, TAction>;

Mount only when action is non-null so hook order stays stable. The action itself also has submit / cancel / fail.

action: TAction

isSubmitting: boolean

isCancelling: boolean

isFailing: boolean

isPending: boolean

error: Error | null

submit: (resume) => Promise<ActionResult<TContract>>

cancel: (input?: { reason?: string }) => Promise<ActionResult<TContract>>

fail: (error: unknown) => Promise<ActionResult<TContract>>

Learn more

On this page