Overview
Caylex provides two embeddable frontend components:<CaylexChatWidget />— a chat interface that connects to the Caylex Assistants API. It supports streaming responses, tool calls, saved sessions, connected-service visibility, a background-task approval Inbox, and optional agent-driven page navigation.<CaylexToolPermissionsWidget />— a permissions panel that lets end users control which tools are always allowed, require approval, or are disabled.
How Authentication Works
The widget uses a token-minting pattern:1
Mint a widget token on your backend
Your backend calls the Caylex API with a platform access token, navigator API key, and user email.
2
Send the token to your frontend
Caylex returns a short-lived JWT that encodes the navigator context and user identity without exposing raw credentials.
3
Render the widget
Your frontend passes the token to the widget component. The widget handles session creation, streaming responses, token refresh, tool call display, and errors.
Prerequisites
- A Caylex account
- A Platform Token from Administration → Access Tokens
- A Navigator API Key from your project’s navigator drawer → API Keys
- A User Email for the end user who will chat with the assistant
- Node.js 18+ for your backend token endpoint
- React 18+ if you use the React component package
Install Packages
If your app uses React, install the widget packages:react-markdown and remark-gfm.
The Caylex widget packages install the @caylex/shared package automatically.
For script-tag usage, you do not need to install NPM packages in your frontend. Load the hosted bundle from Caylex’s asset CDN:
Step 1: Mint A Widget Token
Your backend mints a token by calling the Caylex API.This endpoint was previously named
POST /widget/mint-token. It is now POST /widget/agent-session-init. The old path still works for backward compatibility, but we recommend using /widget/agent-session-init going forward.- Python
- TypeScript
token.py
token— the widget JWT to pass to the frontendexpires_at— ISO timestamp of when the token expires
Step 2: Embed The Chat Widget
Render the widget after your frontend receives a widget token.- React
- Script Tag
Full-Page Widget
Use this pattern when the assistant is a dedicated page in your app.AIAgentPage.tsx
Floating Popup Widget
Use this pattern when you want a chat bubble in the bottom-right corner that persists across pages. Render it in your root layout so it does not unmount during navigation.Layout.tsx
Background Task Approval Inbox
The chat widget can act as the human approval surface for background agent tasks. No additional widget prop is required. When your backend submits a task withapproval_mode: "human":
- The background worker runs independently until it reaches a tool configured as User Approval.
- The widget shows a notification on its session menu for the matching navigator and
user_email. - The Inbox tab lists pending background approvals. Opening one displays the persisted task transcript and the same approval card used by interactive chat.
- The composer stays disabled because the thread belongs to a background task.
- After a decision, the task resumes and the open transcript follows its progress. Any later approval card appears inline.
Only pending approvals appear in the Inbox. This keeps background work out of the regular Chat Sessions list and surfaces it only when user input is required.
Step 3: Enable Agent-Driven Page Navigation
If you want the assistant to navigate users to different pages in your app, pass anavigablePages site map and an onNavigate callback.
For simple apps, this site map can be static frontend data. For production SaaS apps, we recommend exposing it from your backend so you can return only the pages available to the current tenant and user.
Expose The Effective Site Map From Your Backend
Your backend should return aNavigablePage[] array. This endpoint can apply your existing tenant, feature flag, and user permission logic before sending pages to the browser.
navigation.ts
routes.ts
name— the page name the assistant sees and referencesdescription— optional guidance that helps the assistant know when to navigate thereurlTemplate— a base path with optional{param}placeholderstemplateParams— optional metadata for placeholders written directly inurlTemplatequeryParams— optional query filters appended to the resolved URL when the agent supplies a value
params field remains supported as a deprecated alias for
templateParams. Do not provide both fields on the same page.
Optional query parameters that the agent does not supply are omitted. Set
defaultValue when the host application requires a value even when the agent
does not provide one. An empty default intentionally preserves an empty query
key:
queryParams are rejected for pages using this contract.
The site map controls what the assistant can discover for navigation, but it is not a security boundary. Your app should still enforce normal authorization when a user visits a page.
Fetch And Pass Navigation To The Widget
- React
- Script Tag
get_page_info— looks up URL templates and parameter requirementsnavigate_page_ui— triggers youronNavigatecallback with the resolved URL
navigate_page_ui, Caylex resolves the URL template, the widget calls your callback with the resolved URL, and the assistant confirms the navigation in chat.
Step 4: Embed The Permissions Widget
The permissions widget lets users control which tools the assistant can access through the navigator instance. Each tool can be set to:- Always Allow — run without user confirmation
- User Approval — require confirmation before each use
- Disabled — block the tool
- React
- Script Tag
user_email because permissions are scoped to the navigator instance, not an individual user.
Token Refresh
Widget tokens are short-lived. To keep sessions alive without interruption, provide arefreshToken callback. The widget automatically calls this function when it receives a 401 response, obtains a fresh token, and retries the request.
- React
- Script Tag
/api/caylex/token endpoint should call the Caylex mint endpoint from your backend and return the new token.
Customization
Chat Widget Props
The current widget prop is still named
agentInstanceId for compatibility. It refers to the Caylex navigator instance.Permissions Widget Props
Widget Design Space
The Caylex platform includes a Widget Design Space where you can:- Enter your credentials and mint tokens interactively
- Customize colors, dimensions, and feature toggles with live preview
- Test the chat widget with your actual servers and tools
- Switch between chat and permissions widget modes
- Download backend and frontend code snippets for React, script tags, Python, and TypeScript
API Base URLs
The chat widget and permissions widget use different Caylex services:Updating Widgets
For React package usage, pull the latest widget versions with NPM:Security Model
- Platform token + navigator API key stay on your backend
- Widget JWT is short-lived and contains only encoded navigator context and user email
- No raw secrets in the browser — the widgets communicate using the JWT
- Playground keys are rejected — the mint endpoint blocks playground API keys to prevent misuse