Embed in your app's pages¶
Two ways, same result. Use the component when your page is built with a component framework and you want the assistant inline. Use the framed page to keep it isolated or to embed it in any other page.
As a framed page¶
Give us the origins that may embed the assistant (your page's origin goes in the host's allowedOrigins; any other page is refused by the browser). Then:
import { connectAssistantFrame } from "@farmoi/assistant-ui";
connectAssistantFrame(document.querySelector("#assistant"), {
assistantOrigin: "https://assistant.example.com",
getToken: () => currentUser.token,
hostFunctions: [
{ name: "open_task", description: "Show a task", mode: "read",
inputSchema: { type: "object", properties: { task_id: { type: "string" } }, required: ["task_id"] },
run: ({ task_id }) => openTask(task_id) },
],
});
with an element <iframe id="assistant" src="https://assistant.example.com/embed"></iframe> on the page. The token stays in memory and is sent only to the origin you name.
As a component¶
<Assistant baseUrl="https://assistant.example.com/proxy" token={token}
theme={{ accent: "#0b7a5b" }} hostFunctions={[...]} />
getToken replaces token when yours expires. baseUrl is the assistant's /proxy, which needs no further setup; to call the API directly, add your page's origin to the deployment's allowed origins.
Host functions¶
Functions your page runs. Give each an inputSchema; the page checks arguments against it before running. A function with mode: "write" asks the user to confirm first. One that takes longer than timeoutMs (30 s) is reported to the assistant as failed. Only the window that sent the message runs the function.
Look¶
| Option | What |
|---|---|
theme |
background, surface, text, muted, border, accent, accentText, danger, radius, fontFamily, fontSize |
colorScheme |
auto (default), light or dark |
branding |
name, logoUrl |
suggestions |
Up to four starter questions for an empty chat |
attachments, feedback |
false hides the file button or the rating prompt |
For a framed page, put the same objects in the host's configuration file. Pages with a strict style policy pass nonce.
Good to know¶
- Answers are formatted (markdown, code, tables). HTML from a model is never rendered; only http(s) and mail links stay; images are not loaded.
- Sources show as chips; opening one shows the cited passage with its page.
- Attachments upload straight to the storage bucket, which needs a CORS rule allowing
PUTfrom the origin the assistant runs on.