@adonis-agora/agent
Version:
Governed, durable-backed AI agent (chat + tool-calling + governance) for AdonisJS — part of the Agora ecosystem.
68 lines • 3.44 kB
TypeScript
import { type ReactNode } from 'react';
import type { UiCapabilities } from '../../genui/index.js';
import type { AgentBackend, AttachmentUploadStrategy } from './backend.js';
import { type GenuiProviderValue } from './genui/generative-ui.js';
import type { HttpErrorListener } from './http-error.js';
export interface AgentProviderProps {
/** Advertise exact supported component versions; omission keeps legacy support, [] is text only. */
uiCapabilities?: UiCapabilities;
/**
* A backend of your own — see {@link AgentBackend}. Omitted → an {@link AgentClient} over this
* library's REST routes, built from the connection props below (which are ignored when a backend
* is given). Must be stable across renders.
*/
backend?: AgentBackend;
/** The server's origin, e.g. `https://api.example.com`. Default `''` (same origin). */
baseUrl?: string;
/** `AgentModule`'s `path`, global prefix included (`'api/agent'`). Default `'agent'`. */
path?: string;
/** Static headers on every request. */
headers?: Record<string, string>;
/**
* Read at every request — a short-lived bearer token, or a CSRF header read from a cookie
* (`{ 'X-XSRF-TOKEN': readCookie('XSRF-TOKEN') }`).
*/
getHeaders?: () => Record<string, string> | Promise<Record<string, string>>;
/** `'include'` when the API is on another origin and authenticates by cookie. */
credentials?: RequestCredentials;
/** Injectable for tests / non-browser runtimes. */
fetch?: typeof fetch;
/**
* Every error answer of the built-in client (an `AgentHttpError`, or a `MediaUploadError` from
* `mediaAttachments()`), right before it is thrown — for app-wide reactions such as "401 → sign
* in again". Read at call time, so it may change between renders.
*/
onHttpError?: HttpErrorListener;
/** Attachment uploads of the built-in client. */
attachments?: {
/** e.g. `mediaAttachments()` from `@adonis-agora/agent/react/media`. */
upload?: AttachmentUploadStrategy;
};
/**
* Set generative UI up here — the same settings `<GenuiProvider>` takes (registry, catalog,
* resolver, fallback, …). Every message then draws pushed components with them.
*/
genui?: GenuiProviderValue;
children?: ReactNode;
}
/**
* The agent connection, once, at the app root. Every hook below it — `useAgentChat`, `useThreads`,
* `useModels`, `useAgents`, `useQuota`, `useToolCatalog`, `useMessageFeedback`, `useAttachments` —
* talks to it unless handed a `backend` of its own.
*
* ```tsx
* <AgentProvider baseUrl="https://api.example.com" credentials="include">
* <App />
* </AgentProvider>
* ```
*
* Without a provider every hook shares one same-origin client on `/agent`.
*/
export declare function AgentProvider({ backend, uiCapabilities, baseUrl, path, headers, getHeaders, credentials, fetch, onHttpError, attachments, genui, children, }: AgentProviderProps): import("react").JSX.Element;
/**
* The backend a hook talks to: `own` when given, else the enclosing {@link AgentProvider}'s, else a
* shared same-origin client on `/agent`. For your own hooks over the same connection.
*/
export declare function useAgentBackend<B extends AgentBackend = AgentBackend>(own?: B): B;
export declare function useAgentUiCapabilities(): UiCapabilities | undefined;
//# sourceMappingURL=provider.d.ts.map