@ixo/oracles-client-sdk

Reference for the React client of a QiForge oracle: the OraclesProvider wrapper, the useChat hook, browser tools, AG-UI actions, events, the auth lifecycle and errors.

@ixo/oracles-client-sdk is the official React client for a QiForge oracle. This page is the reference for its provider, hooks, browser tools and events. The SDK wraps:

  • The streaming chat endpoint over SSE.
  • The WebSocket event channel (tool calls, render components, browser tools, AG-UI actions).
  • UCAN auth: signing invocations (authentication) and delegations (downstream authorization).
  • Browser-side tools and AG-UI actions (so the agent can act on the user's tab / UI).

If you're building a Portal-like web UI for your oracle, use this. If you're building a non-React client (CLI, mobile app), implement the HTTP/WS protocol directly. The API reference is API endpoints.

Install

pnpm add @ixo/oracles-client-sdk

react >= 18 and zod ^3 are peer dependencies.

OraclesProvider (required wrapper)

Every hook calls useOraclesContext(), which throws useOraclesContext must be used within a OraclesProvider if there's no provider above it. Wrap your app once. The provider holds the wallet, signs transactions, and turns your createDelegation / createInvocation callbacks into the cached auth artifacts the hooks attach to requests.

import { OraclesProvider } from '@ixo/oracles-client-sdk';

function Root({ children }) {
  return (
    <OraclesProvider
      initialWallet={{
        address: 'ixo1...',
        did: 'did:ixo:ixo1...',
        matrix: { accessToken: 'syt_...', homeServer: 'https://matrix.ixo.world' },
      }}
      transactSignX={async (messages, memo) => {
        // sign + broadcast the chain tx with your wallet; return the result
        return undefined;
      }}
      createDelegation={async (oracleDid) => {
        // sign a user→oracle UCAN delegation (downstream authorization)
        return { serialized: '<base64-car>', expiresAt: Date.now() + 60 * 60 * 1000 };
      }}
      createInvocation={async (oracleDid) => {
        // sign a short-lived UCAN invocation (primary authentication)
        return { serialized: '<base64-car>', expiresAt: Date.now() + 15 * 60 * 1000 };
      }}
    >
      {children}
    </OraclesProvider>
  );
}
initialWallet{ address, did, matrix: { accessToken, homeServer } }required
transactSignX(messages, memo?) => Promise<unknown>required
createDelegation(oracleDid: string) => Promise<{ serialized: string; expiresAt: number }>required
createInvocation(oracleDid: string) => Promise<{ serialized: string; expiresAt: number }>

useChat

The primary hook. Provides the message thread, the send function, and live streaming state.

import { useChat, useOracleSessions, renderMessageContent } from '@ixo/oracles-client-sdk';

function Chat({ oracleDid }: { oracleDid: string }) {
  const { sessions, createSession } = useOracleSessions(oracleDid);
  const sessionId = sessions?.[0]?.sessionId ?? '';

  const { messages, sendMessage, isSending, status } = useChat({
    oracleDid,
    sessionId,
    onPaymentRequiredError: (claimIds) => {
      // the oracle needs payment before answering — surface a paywall
      console.log('Payment required:', claimIds);
    },
  });

  return (
    <div>
      <button onClick={() => createSession()}>New chat</button>
      {messages.map((m) => (
        <div key={m.id} className={m.type}>{renderMessageContent(m.content)}</div>
      ))}
      <form onSubmit={(e) => { e.preventDefault(); sendMessage(e.currentTarget.message.value); }}>
        <input name="message" />
        <button type="submit" disabled={isSending}>
          {status === 'streaming' ? 'Streaming…' : 'Send'}
        </button>
      </form>
    </div>
  );
}

Options (IChatOptions):

oracleDidstringrequired
sessionIdstringrequired
onPaymentRequiredError(claimIds: string[]) => voidrequired
browserToolsRecord<string, { toolName, description, schema, fn }>
uiComponentsUIComponents
overrides{ baseUrl?, wsUrl? }
streamingMode'batched' | 'immediate'

Returned values:

FieldTypeNotes
messagesIMessage[]Thread history, including in-flight streamed content.
sendMessage(message: string, metadata?, attachments?) => Promise<void>Submit a user message. Rejects with a RequestError when the oracle refuses it (see Errors).
abortStream() => Promise<void>Abort the in-flight response.
status'submitted' | 'streaming' | 'ready' | 'error'Current chat state.
isSendingbooleantrue while submitting or streaming.
isLoadingbooleanInitial history fetch in flight.
error / sendMessageErrorError | undefinedLoad error / send error.
refetchMessages() => Promise<…>Re-pull the thread from the server.
isRealTimeConnectedbooleanWebSocket connection status.
isConfigReadybooleanThe oracle's config has resolved.

There is no isStreaming or events field. Use status / isSending for streaming state.

Browser tools

Browser tools let the agent call DOM/UI actions on the user's tab. Pass them as the browserTools option to useChat, a map keyed by tool name. The SDK advertises them to the agent, forwards each call to your fn, and returns the result over the WebSocket.

import { useChat } from '@ixo/oracles-client-sdk';
import { z } from 'zod';

const browserTools = {
  open_portal_route: {
    toolName: 'open_portal_route',
    description: 'Navigate to a route inside the Portal.',
    schema: z.object({ route: z.string() }),
    fn: async ({ route }: { route: string }) => {
      router.push(route);
      return { ok: true };
    },
  },
};

const { messages, sendMessage } = useChat({
  oracleDid,
  sessionId,
  onPaymentRequiredError: () => {},
  browserTools,
});

There is no registerBrowserTools export. Browser tools are the browserTools option above.

AG-UI actions

useAgAction registers an agent-invokable action with an optional render. The provider tracks registered actions; useChat advertises them and renders their output inline.

import { useAgAction } from '@ixo/oracles-client-sdk';
import { z } from 'zod';

useAgAction({
  name: 'create_data_table',
  description: 'Render a data table from structured rows.',
  parameters: z.object({
    title: z.string().optional(),
    columns: z.array(z.any()),
    data: z.array(z.any()),
  }),
  handler: async ({ data }) => ({ ok: true, rowCount: data.length }),
  render: ({ status, args }) =>
    status === 'done' && args ? <DataTable {...args} /> : null,
});

Events

Streamed and WebSocket events are surfaced as the typed AnyEvent union and rendered through renderMessageContent / your uiComponents map. The event eventName values match the wire names:

eventNameWhat it carries
tool_callA tool invocation (and its result).
render_componentA structured UI component the agent wants displayed.
browser_tool_callA call to one of your browserTools.

The full server/client WebSocket event catalog is in API endpoints → WebSocket.

Other exports

ExportPurpose
useOracleSessions(oracleDid)Create, list, and delete chat sessions.
useOraclesConfig(oracleDid)The oracle's resolved public config (API URL, model, price).
useContractOracle()Pay to contract (subscribe to) an oracle.
useMemoryEngine(oracleDid)Invite the Memory Engine's Matrix bot into the user's oracle room (power level 50, so it can log its ixo.memory.* events there) and list or invite room members. It does not read or write memories; the oracle's memory plugin does that.
useGetOpenIdToken() / getOpenIdToken()Mint a Matrix OpenID token for the user.
renderMessageContent(content)Turn stored message content into React nodes.
OraclesProvider, useOraclesContextThe provider + its context accessor.
@ixo/oracles-client-sdk/live-agent → useLiveAgentEncrypted voice/video live-agent calls (separate entry point).

Auth lifecycle

The provider owns auth. From your createDelegation / createInvocation callbacks it:

  • Caches the signed delegation and invocation per (userDid, oracleDid).
  • Attaches Authorization: Bearer <invocation> + X-Auth-Type: ucan (primary) and x-ucan-delegation (downstream / fallback) to every request.
  • Passes the same artifacts on the WebSocket handshake (auth.invocation / auth.ucanDelegation).

When a stored delegation is missing or expired, the oracle nudges the user to re-authorize; your app calls createDelegation again to mint a fresh one (the client-sdk POSTs it to /delegation).

When the oracle refuses a request for its credentials (a 401, or a 403 other than VFS_AUTH_FAILED, without refused: true in the error body), the SDK renews them and repeats the request: first a fresh invocation, then, only if the request is refused again, a fresh delegation and a fresh invocation. Minting a delegation can ask the user for their PIN or passkey. A turn refused by a plugin is not a credential refusal and is never renewed. See Errors.

Errors

A failed request rejects with a RequestError: sendMessage from useChat, and authedRequest from useOraclesContext(). The class is not exported from the package, so read its fields on the caught error.

FieldTypeMeaning
statusnumberThe HTTP status.
codestringThe oracle's machine-readable reason, when it sends one.
messagestringThe oracle's message.
requestIdstringThe request id, when the oracle sends one.
retryablebooleanWhether repeating the same request can succeed, when the oracle says.
refusedbooleantrue when one of the oracle's plugins refused the turn, for example because the user is out of credits. Never a credential problem, whatever status is.
detailsRecord<string, unknown>The refusal's details, when sent. The runtime documents retryAfterSeconds and action: { label, url }.
outstandingClaimsstring[]Claims that must be paid before the oracle answers.

From @ixo/oracles-client-sdk 1.10.0, an answer with refused: true is surfaced at once, whatever its status (for example 402 insufficient_credits, 503 credits_check_unavailable, or a 403 with a plugin's own code). Nothing is renewed and nothing is repeated, so the user is not asked for their PIN. Show message, and the action as a button or link when there is one, instead of asking the user to sign in again:

try {
  await sendMessage(text);
} catch (error) {
  const e = error as {
    refused?: boolean;
    message: string;
    details?: { action?: { label: string; url: string }; retryAfterSeconds?: number };
  };
  if (e.refused) {
    showNotice(e.message, e.details?.action); // your UI
    return;
  }
  throw error;
}

Choose how to present a refusal by its code, not by status alone: a 503 can mean "try again shortly" and a 403 can come from a plugin. What the oracle sends for each refusal is in How a refusal reaches the person.