Cairn Widget — Public JS API (ATH-122)

The typed surface lives in clients/widget/src/api/every change there requires updating this document (CLAUDE.md).

Install

Snippet (Doc 04 §2.1):

<script>window.$cairn=[];CAIRN_WEBSITE_ID="ws_pub_…";</script>
<script src="https://{CAIRN_WIDGET_CDN_URL}/l.js" async></script>

{CAIRN_WIDGET_CDN_URL} is not a literal. The install snippet is ISSUED by GET /widget/install, which substitutes the configured CDN host — and returns snippet: null while that variable is unset, because a snippet pointing at a hostname nobody owns is worse than no snippet (PA-298). Copy what the API gives you, not what is written here.

npm — the programmatic equivalent; safe to call anywhere, the API is queue-backed until the bundle boots:

import { init } from '@cairn/widget'
const cairn = init({ websiteId: 'ws_pub_…' })

Reactimport { useCairn } from '@cairn/widget/react' Vueapp.use(CairnWidget, { websiteId }) from @cairn/widget/vue Angular — register CairnService from @cairn/widget/angular as a provider

(One package with subpath exports rather than four packages — same DX, a quarter of the release surface.)

Surface

Call Effect
Cairn.open() / close() / toggle() Launcher window control
Cairn.user.set({ email, name?, hmac? }) Identify the visitor. hmac = HMAC-SHA256(email, widget identity secret) signed by your backend verifies the identity (ATH-118); without it, verified identities cannot be claimed
Cairn.event.push(name) Record a custom event; feeds trigger rules (ATH-121)
Cairn.helpdesk.query(q?) Open help mode, optionally pre-searched (ATH-119)
Cairn.helpdesk.openArticle(slug) Open a public KB article in-widget
Cairn.walkthrough.start(guideId) Start the interactive walkthrough for a published guide (ATH-274, Doc 07 §2.1) — see Walkthroughs
Cairn.automation.run(guideId, params?) Start "do it for me": the assistant executes a published guide's steps on the current page, one at a time behind a consent HUD; optional params pre-fill non-sensitive step values for the user to confirm (PA-218/PA-221, Doc 07 §2.2) — see Do it for me
Cairn.on(event, handler) Subscribe; returns an unsubscribe function

Walkthroughs

Cairn.walkthrough.start(guideId) (ATH-274, Doc 07 §2.1) plays a published guide as an on-page spotlight walkthrough. guideId is the guide's ULID. Behavior:

Like every call, it is queue-backed: safe to invoke before the bundle boots.

Do it for me (execution)

Cairn.automation.run(guideId) (PA-218, Doc 07 §2.2) is the walkthrough's agent-driven sibling: instead of pointing at the next step and waiting for the user, the runtime executes the guide's steps on the current page — one at a time, each behind a floating consent HUD. It runs on the same engine as the walkthrough (selector resolution + player), so the same guides work in both. Behavior:

Proactive messages

The widget can speak first, from two sources that share one bubble above the launcher — clicking it opens the conversation.

No public API call is involved in either — this section documents behavior you will observe, not a surface you drive. Three properties are worth knowing:

campaign.shown and campaign.clicked analytics require Cairn.consent(true) like every other beacon; delivery itself does not.

Events

Event Payload
open / close
message:received { body } — an agent message arrived

Guarantees