<script> tag, you call window.mindset.init() with your app UID and an authentication callback. The init function attaches runtime instances to every <mindset-agent> element on the page and watches for new ones added later.
Per-agent setup happens on the element itself, not here. This page covers the page-level API: the things you do once.
window.mindset.init(config)
Initialize the SDK. Call once after the bundle loads.
Signature:
mindset:agent-idle on each element to know it’s ready. Note that an agent configured with an icebreaker will fire that turn immediately after the first idle event. The sendWhenIdle pattern handles this so you don’t need to track which configuration applies.
InitConfig
When to call init
You can call init before or after <mindset-agent> elements are in the DOM. Both orders work:
- If you init first and then add elements (common when you mount agents from a JS framework like React or Vue), the SDK’s
MutationObserverpicks up elements as they’re added. - If you add elements first and then init (common with static HTML), the SDK finds existing elements and binds them.
setPageTools, setSituationalAwareness, sendMessage, thread CRUD, etc.) become callable after mindset.init() completes and the element fires mindset:agent-idle. See § When the element is ready to call.
Authentication
The SDK delegates auth to yourfetchAuthentication callback. The callback returns a token your app’s backend mints from sdkusersapi. The SDK exchanges that token for the credentials the runtime needs.
- Once when the SDK first needs a token
- Again whenever the token expires and needs refreshing
Token endpoint setup. Setting up the backend endpoint that mints SDK tokens (calling
sdkusersapi, configuring API keys, mapping users to Mindset AI identities) is a one-time piece of integration work covered in the existing Mindset AI auth docs.See the SDK 3 Authentication guide for the end-to-end flow, and the SDK Users API reference for the parameter-level detail.Anonymous agents
If your agent is configured to allow anonymous access in the Agent Management Studio, you can omitfetchAuthentication. The agent will run without identifying the user. Useful for public-facing demos and unauthenticated marketing pages.
For authenticated agents, the callback is required. Without it, the agent fires mindset:agent-error with code: 'agent_loading_failed' (or 'model_loading_failed') instead of reaching mindset:agent-idle. Listen for mindset:agent-error during integration testing so silent auth misconfigurations are caught early.
Auth state helpers
The SDK exposes Firebase-backed sign-in helpers for apps that use Mindset AI’s hosted authentication. These are page-level: you call them onwindow.mindset, not on a specific agent.
fetchAuthentication to mint tokens server-side, you don’t need these helpers.
Page-level utilities
What lives where
The boundary: anything that varies across agents lives on the element. Anything page-wide lives on
window.mindset.
Error handling
init rejects if:
appUidis missing or invalid- The bundle hasn’t finished loading (race condition, so use a
deferscript or callinitfromDOMContentLoaded)
mindset:agent-error with a code (e.g. model_loading_failed, agent_loading_failed) and a human-readable message. Listen on the element if you want to handle these: