import type { ReactNode } from 'react'; import type { AIMessage } from '../Conversation/types'; import { type AIUIAction } from './AIUIAction'; import type { AIUIComponent } from './AIUIComponent'; import { type AIUIDocument } from './AIUIDocument'; import { type AIUIRenderer } from './AIUIRenderer'; import { type AIUIClientTool, type AIUIClientToolDefinition } from './AIUITools'; export type { AIUIClientTool, AIUIClientToolDefinition } from './AIUITools'; export type AIUIHostOptions = { /** The renderer of each format the agent writes, the first one listed asked first. */ renderers: AIUIRenderer[]; /** * Sends what the person did to the agent, as their next message, such as * `session.responses.create(action.label, { uiAction: aiUIActionJSON(action) })`. */ send: (action: AIUIAction) => Promise | unknown; /** The app's views the agent can place. */ components?: AIUIComponent[]; /** Tells the app that an action could not be sent. It is logged by default. */ onError?: (error: unknown, action: AIUIAction) => void; /** * Tells the app that a reply's UI, or a part of it, failed to show: a reply's UI that throws * shows the reply's text instead, and one of the app's components that throws leaves only * itself out. It is logged by default. */ onRenderError?: (error: unknown, messageId: string) => void; /** * Opens a link from a reply's UI. By default, web and email links open and others don't: the * agent writes the links, so another could call someone or act in another app. */ open?: (url: URL) => void; /** * The app's tools a reply's UI can run, described to the agent's model. One that isn't * read-only runs only from something the person did, such as a tap. */ tools?: AIUIClientTool[]; }; /** Whether a link is one a reply's UI may open by default: a web or email link. */ export declare const isWebOrEmailLink: (url: URL) => boolean; /** * The generated UI of one conversation: the renderers of the formats the agent writes, the * app's components and tools, what each reply's UI was left in, and where what the person does * goes. Give it to `AIConversation` as `ui`; keep one per conversation, for as long as it shows. * The counterpart of `AIUIHost` in StreamChatAI. */ export declare class AIUIHost { readonly components: AIUIComponent[]; readonly renderers: AIUIRenderer[]; private readonly engines; private readonly failed; private lastSend; private readonly listeners; private readonly options; private readonly received; private readonly states; private readonly tools; private refreshing; private version; constructor(options: AIUIHostOptions); /** The names of the app's tools a reply's UI can run with `runTool`. */ get toolNames(): string[]; /** The app's tools a reply's UI can run, as the agent's model reads them. */ get toolDefinitions(): AIUIClientToolDefinition[]; /** The app's component the agent places by `name`. */ component(name: string): AIUIComponent | undefined; /** * Whether one of its renderers reads `document`. The one that does can still show nothing of * its own for a reply, which then shows its text, as `content` tells. */ canShow(document: AIUIDocument): boolean; /** * The view of a reply's document from the first renderer that reads its format and version, * or `null` when none shows anything of its own, so the reply shows its text. `AIUIView` puts * it on screen; `AIConversation` does it for every reply. */ content(document: AIUIDocument, messageId: string): ReactNode | null; /** * Gives its renderers the UI of the conversation's replies, oldest first, as each arrives or * changes, whether or not the reply is on screen, so a format whose later replies change an * earlier one's UI follows them all. It also tells them when a reply leaves the conversation, * or its UI does, such as when it is deleted. `AIConversation` does it: call it with the * conversation's messages when you show replies yourself with `AIUIView`. */ receive(messages: AIMessage[]): void; /** * Sends what the person did to the agent, after everything sent before it, so the agent gets * a reply's actions in the order they happened. Resolves to whether it was sent: one the * agent's backend would refuse, or that fails to send, goes to `onError`, resolves to * `false`, and does not hold up the ones after it. */ send(action: AIUIAction): Promise; /** * Whether a reply's UI failed to show (`fail`), so its text shows in its place. It stops being * failed as `fail` says: once the reply leaves the conversation, or, for a reply that failed * while it was written, once it is written. */ hasFailed(messageId: string): boolean; /** * Shows a reply's text in place of its UI, which failed to show, and tells the app. It lasts * while the reply is in the conversation, or, for a reply still being written, until it is * written. `AIConversation` and `AIUIView` do it. */ fail(messageId: string, error: unknown): void; /** * Tells the app that a part of a reply's UI failed to show, such as one of the app's * components that threw, while the rest of it still shows. `AIUIComponentView` calls it. */ reportRenderError(error: unknown, messageId: string): void; /** * Has the conversation show its replies again, because what one of them shows changed since * it was last asked: its renderer's runtime loaded, or a finished reply turned out to show * nothing of its own. Renderers call it; the conversation shows them again after the current * render, however many times it is called in it. */ refresh(): void; /** Calls `listener` each time the conversation should show its replies again. */ subscribe: (listener: () => void) => () => void; /** A number that changes each time the conversation should show its replies again. */ getVersion: () => number; /** * Runs one of the app's tools for a reply's UI, such as to load data on this device. One that * isn't read-only runs only when `userInitiated`, from something the person did, rather than * as the reply shows. Rejects with an `AIUIToolError` when the tool can't run, fails, or gives * what isn't JSON. */ runTool(name: string, args?: Record, { userInitiated }?: { userInitiated?: boolean; }): Promise; /** Opens a link from a reply's UI, as the host's `open` allows. */ open(url: URL | string): void; /** The state a reply's UI was left in, such as a form's values, kept while the host is. */ state(messageId: string): unknown; /** Keeps the state a reply's UI was left in. `undefined` forgets it. */ setState(messageId: string, state: unknown): void; /** * What the agent's backend needs to write UI this app shows: each format it reads, with what * its renderer adds, such as the model's instructions, the app's components, and its tools. * A renderer may load its format's packages to write them, so this resolves once they are * written. */ capabilities(): Promise<{ v: number; tools?: { inputSchema: Record; name: string; description?: string | undefined; annotations: { readOnlyHint: boolean; }; }[] | undefined; components: { description: string; events: { parameters?: import("./AIUIComponentDefinition").AIUIJSONSchema | undefined; description: string; name: string; }[]; name: string; parameters: import("./AIUIComponentDefinition").AIUIJSONSchema; }[]; renderers: { format: import("./AIUIDocument").AIUIFormat; }[]; }>; private engineOf; } //# sourceMappingURL=AIUIHost.d.ts.map