@helpai/elements 1.9.0 → 1.11.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/llms.txt CHANGED
@@ -1,36 +1,40 @@
1
1
  # Help AI Elements
2
2
 
3
- > Help AI's AI chat widget for any website: an AI agent that answers visitors from the customer's own help content, can hand the chat to a person, and shows Help articles and News. Install it with one script tag, the `<web-ai-chat>` element, the npm API or the React kit. These docs match @helpai/elements@1.9.0.
3
+ > Help AI's AI chat widget for any website: an AI agent that answers visitors from the customer's own help content, can hand the chat to a person, and shows Help articles and News. Install it with one script tag, the `<web-ai-chat>` element, the npm API or the React kit. These docs match @helpai/elements@1.11.0.
4
4
 
5
5
  What a coding agent needs to install it right the first time:
6
6
 
7
7
  - Two values come from the deployment's Install page in the Help AI dashboard: the public key (`agent_pk_…`) and the AI agent deployment id (a UUID). Both belong in browser code. The deployment's secret key never does.
8
- - Plain HTML, WordPress or any CMS: `<script src="https://cdn.help.ai/sdk/js/elements/1.9.0/elements.js" data-public-key="agent_pk_…" data-ai-agent-deployment-id="…" defer></script>`.
8
+ - Plain HTML, WordPress or any CMS: `<script src="https://cdn.help.ai/sdk/js/elements/1.11.0/elements.js" data-public-key="agent_pk_…" data-ai-agent-deployment-id="…" defer></script>`.
9
9
  - React, Next.js, Remix: install `@helpai/elements` and render `<HelpAI publicKey="…" aiAgentDeploymentId="…" />` from `@helpai/elements/react` once, in the root layout. `useHelpAI()` in any component returns `{ state, ask, open, close, reset }`. It is server-render safe; import everything from `@helpai/elements/react`.
10
10
  - Vue, Svelte, Angular and other bundlers: `import '@helpai/elements/web-component'`, then `<web-ai-chat public-key="…" ai-agent-deployment-id="…"></web-ai-chat>`. JSX typings: `@helpai/elements/jsx/react`, `/jsx/vue`, `/jsx/svelte`.
11
11
  - Site buttons need no JavaScript: `data-helpai-ask="Which plan fits a team of 10?"` puts the question in the chat, `data-helpai-open="help"` opens a tab (`home`, `chats`, `help`, `news`). In code, `ask(text)` fills the composer and sends only with `{ send: true }`.
12
+ - Logged-in users: your server signs a JWT with the deployment's secret key (HS256; `sub` = your user id, `exp`; optional `name`, `email`), and the widget gets a function that fetches it: `userToken` at init, `login(fn)` after sign-in, `reset()` at sign-out. Their chats then follow them to any device. Never sign tokens in the browser.
13
+ - Your page's own events: `chat.track('plan_viewed', { plan: 'pro' })` sends an analytics hit and lets the agent see the visitor's last 10 events with their next message.
14
+ - Page tools: `chat.registerTool({ name, description, inputSchema?, annotations?: { consequentialHint }, execute })` (WebMCP shape; `HelpAI('registerTool', tool)` from the script tag, `useHelpAITool(tool)` in React, or a `<form toolname tooldescription>`) lets the agent act on the page (open a form, read the cart). `execute(input, { signal })` runs once in the browser and returns JSON for the agent; abort the registration's `signal` when a route leaves.
12
15
  - `theme: 'host'` (`theme="host"`) follows the site's own light/dark switch.
13
16
  - Pin the exact version in production, as above; `latest` changes under you.
14
17
  - It works when the launcher shows in the bottom corner and `HelpAI.ready()` (or `chat.ready`) resolves.
15
18
 
16
19
  ## Docs
17
20
 
18
- - [Quickstart](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/quickstart.md): credentials, the install paths and a first check, in five minutes
19
- - [Installation](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/installation.md): every install path in depth: script tag, async loader, npm, web component, CDN URLs and version pinning
20
- - [Frameworks](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/frameworks.md): the React kit (`<HelpAI />`, `useHelpAI()`), Next.js, Remix, Vue, Nuxt, Svelte, Astro, Angular, WordPress, Shopify, Webflow
21
- - [Configuration](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/configuration.md): every option by group, with examples
22
- - [Option reference](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/options.md): the table of every option, generated from the schemas; authoritative
23
- - [API reference](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/api-reference.md): exports, instance methods (`ask`, `open`, `state`, `ready`, `reset`, …), the global API, no-script triggers, deep links, JSX typings
24
- - [Events and hooks](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/events-and-hooks.md): every event and its payload, `on()` and `hook()`
25
- - [Theming](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/theming.md): colors, shapes, fonts, launcher styles, `theme: "host"` and `::part()` styling
26
- - [Recipes](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/recipes.md): copy-paste solutions for common integrations
27
- - [Analytics](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/analytics.md): sending widget activity to Google Analytics, Segment, PostHog and other trackers
28
- - [Security and privacy](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/security-privacy.md): isolation, CSP, what the widget stores and sends
29
- - [Browser support](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/browser-support.md): supported browsers and fallbacks
30
- - [Troubleshooting](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/troubleshooting.md): an install that does not show, connect or answer
31
- - [FAQ](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/faq.md): short answers to common questions
32
- - [Overview](https://cdn.help.ai/sdk/js/elements/1.9.0/docs/README.md): the whole SDK on one page
21
+ - [Quickstart](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/quickstart.md): credentials, the install paths and a first check, in five minutes
22
+ - [Installation](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/installation.md): every install path in depth: script tag, async loader, npm, web component, CDN URLs and version pinning
23
+ - [Frameworks](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/frameworks.md): the React kit (`<HelpAI />`, `useHelpAI()`), Next.js, Remix, Vue, Nuxt, Svelte, Astro, Angular, WordPress, Shopify, Webflow
24
+ - [Configuration](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/configuration.md): every option by group, with examples
25
+ - [Option reference](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/options.md): the table of every option, generated from the schemas; authoritative
26
+ - [API reference](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/api-reference.md): exports, instance methods (`ask`, `open`, `state`, `ready`, `reset`, …), the global API, no-script triggers, deep links, JSX typings
27
+ - [Events and hooks](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/events-and-hooks.md): every event and its payload, `on()` and `hook()`
28
+ - [Page tools](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/page-tools.md): WebMCP-shaped tools the AI agent calls on your page (`registerTool`, `tools`, `useHelpAITool`, `<form toolname>`), run once in the browser
29
+ - [Theming](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/theming.md): colors, shapes, fonts, launcher styles, `theme: "host"` and `::part()` styling
30
+ - [Recipes](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/recipes.md): copy-paste solutions for common integrations
31
+ - [Analytics](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/analytics.md): sending widget activity to Google Analytics, Segment, PostHog and other trackers
32
+ - [Security and privacy](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/security-privacy.md): isolation, CSP, what the widget stores and sends
33
+ - [Browser support](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/browser-support.md): supported browsers and fallbacks
34
+ - [Troubleshooting](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/troubleshooting.md): an install that does not show, connect or answer
35
+ - [FAQ](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/faq.md): short answers to common questions
36
+ - [Overview](https://cdn.help.ai/sdk/js/elements/1.11.0/docs/README.md): the whole SDK on one page
33
37
 
34
38
  ## Optional
35
39
 
36
- - [Every doc in one file](https://cdn.help.ai/sdk/js/elements/1.9.0/llms-full.txt): the docs above, concatenated
40
+ - [Every doc in one file](https://cdn.help.ai/sdk/js/elements/1.11.0/llms-full.txt): the docs above, concatenated
package/package.json CHANGED
@@ -117,5 +117,5 @@
117
117
  ],
118
118
  "type": "module",
119
119
  "types": "./index.d.ts",
120
- "version": "1.9.0"
120
+ "version": "1.11.0"
121
121
  }
package/react.d.ts CHANGED
@@ -39,7 +39,7 @@ interface ClientStorage {
39
39
  * populated {@link Strings} map. UI components then read `strings.send` as a
40
40
  * normal property access — no per-render lookup, no per-render allocation.
41
41
  */
42
- type StringKey = 'launcherOpen' | 'launcherLabel' | 'panelTitle' | 'composerPlaceholder' | 'send' | 'stop' | 'queueMessage' | 'removeQueuedMessage' | 'compactingContext' | 'attach' | 'micStart' | 'micStop' | 'micUnsupported' | 'expand' | 'collapse' | 'fullscreen' | 'exitFullscreen' | 'popOut' | 'resizeHandle' | 'scrollToBottom' | 'close' | 'moreActions' | 'soundOn' | 'soundOff' | 'language' | 'theme' | 'themeAuto' | 'themeLight' | 'themeDark' | 'textSize' | 'textSizeSmall' | 'textSizeNormal' | 'textSizeLarge' | 'history' | 'historyTitle' | 'historyEmpty' | 'historyLoading' | 'historyBack' | 'historyContinue' | 'loadMoreConversations' | 'conversationLoading' | 'loadPreviousMessages' | 'conversationClosed' | 'startNewConversation' | 'talkToOperator' | 'connectingOperator' | 'noOperatorAvailable' | 'chattingWithOperator' | 'cancelOperatorRequest' | 'dateToday' | 'dateYesterday' | 'dateLastWeek' | 'dateOlder' | 'newConversation' | 'dropZone' | 'attachmentTooLarge' | 'attachmentTooMany' | 'attachmentMimeRejected' | 'errorRetry' | 'errorGeneric' | 'errorRateLimited' | 'loading' | 'visualPreparing' | 'visualError' | 'visualPartial' | 'thinking' | 'thoughts' | 'toolResult' | 'sources' | 'feedbackUp' | 'feedbackDown' | 'feedbackThanks' | 'copy' | 'copied' | 'collapseSidebar' | 'expandSidebar' | 'formSubmit' | 'formSkip' | 'formSubmitted' | 'formSkipped' | 'formFillOut' | 'formRequired' | 'formInvalidEmail' | 'formInvalidTel' | 'formInvalidUrl' | 'formInvalidNumber' | 'formTooShort' | 'formTooLong' | 'formNumberTooSmall' | 'formNumberTooLarge' | 'formPatternMismatch' | 'formChooseAtLeast' | 'formChooseAtMost' | 'formOther' | 'formOtherPlaceholder' | 'inputRequired' | 'inputBadge' | 'inputAnswered' | 'inputSkipped' | 'inputSubmit' | 'inputSubmitHint' | 'inputSkip' | 'showOptions' | 'hideOptions' | 'qtypeText' | 'qtypeEmail' | 'qtypePhone' | 'qtypeNumber' | 'qtypeDate' | 'qtypeChooseOne' | 'qtypeChooseAny' | 'qtypeBoolean' | 'confirmYes' | 'confirmNo' | 'approve' | 'reject' | 'approvalPrompt' | 'approvalBody' | 'approvalYourResponse' | 'approvalEditHint' | 'approvalSubmitting' | 'edit' | 'toolParameters' | 'statusAwaiting' | 'statusResponded' | 'statusCompleted' | 'statusDenied' | 'statusError' | 'statusRunning' | 'statusSuperseded' | 'tabHome' | 'tabConversations' | 'tabHelp' | 'tabNews' | 'modulesEmpty' | 'moduleBack' | 'contentLoading' | 'contentHelpful' | 'homeGreeting' | 'homeGreetingNamed' | 'homeGreetingLead' | 'homeSearchPlaceholder' | 'homeAskPlaceholder' | 'homeWhatsNew' | 'homeContentTitle' | 'homeStatus' | 'helpTitle' | 'helpSearchPlaceholder' | 'helpEmpty' | 'helpLoading' | 'helpSearchEmpty' | 'helpShowMore' | 'newsTitle' | 'newsEmpty' | 'newsLoading' | 'newsBack' | 'newsPublishedAt' | 'newsShowMore' | 'newsUnseen';
42
+ type StringKey = 'launcherOpen' | 'launcherLabel' | 'panelTitle' | 'composerPlaceholder' | 'send' | 'stop' | 'queueMessage' | 'removeQueuedMessage' | 'compactingContext' | 'attach' | 'micStart' | 'micStop' | 'micUnsupported' | 'expand' | 'collapse' | 'fullscreen' | 'exitFullscreen' | 'popOut' | 'resizeHandle' | 'scrollToBottom' | 'close' | 'moreActions' | 'soundOn' | 'soundOff' | 'language' | 'theme' | 'themeAuto' | 'themeLight' | 'themeDark' | 'textSize' | 'textSizeSmall' | 'textSizeNormal' | 'textSizeLarge' | 'history' | 'historyTitle' | 'historyEmpty' | 'historyLoading' | 'historyBack' | 'historyContinue' | 'loadMoreConversations' | 'conversationLoading' | 'loadPreviousMessages' | 'conversationClosed' | 'startNewConversation' | 'talkToOperator' | 'connectingOperator' | 'noOperatorAvailable' | 'chattingWithOperator' | 'cancelOperatorRequest' | 'dateToday' | 'dateYesterday' | 'dateLastWeek' | 'dateOlder' | 'newConversation' | 'dropZone' | 'attachmentTooLarge' | 'attachmentTooMany' | 'attachmentMimeRejected' | 'errorRetry' | 'errorGeneric' | 'errorRateLimited' | 'loading' | 'visualPreparing' | 'visualError' | 'visualPartial' | 'thinking' | 'thoughts' | 'toolResult' | 'sources' | 'feedbackUp' | 'feedbackDown' | 'feedbackThanks' | 'copy' | 'copied' | 'collapseSidebar' | 'expandSidebar' | 'formSubmit' | 'formSkip' | 'formSubmitted' | 'formSkipped' | 'formFillOut' | 'formRequired' | 'formInvalidEmail' | 'formInvalidTel' | 'formInvalidUrl' | 'formInvalidNumber' | 'formTooShort' | 'formTooLong' | 'formNumberTooSmall' | 'formNumberTooLarge' | 'formPatternMismatch' | 'formChooseAtLeast' | 'formChooseAtMost' | 'formOther' | 'formOtherPlaceholder' | 'inputRequired' | 'inputBadge' | 'inputAnswered' | 'inputSkipped' | 'inputSubmit' | 'inputSubmitHint' | 'inputSkip' | 'showOptions' | 'hideOptions' | 'qtypeText' | 'qtypeEmail' | 'qtypePhone' | 'qtypeNumber' | 'qtypeDate' | 'qtypeChooseOne' | 'qtypeChooseAny' | 'qtypeBoolean' | 'confirmYes' | 'confirmNo' | 'approve' | 'reject' | 'approvalPrompt' | 'approvalBody' | 'approvalYourResponse' | 'approvalEditHint' | 'approvalSubmitting' | 'edit' | 'toolParameters' | 'statusAwaiting' | 'statusResponded' | 'statusCompleted' | 'statusDenied' | 'statusError' | 'statusRunning' | 'statusSuperseded' | 'statusIncomplete' | 'tabHome' | 'tabConversations' | 'tabHelp' | 'tabNews' | 'modulesEmpty' | 'moduleBack' | 'contentLoading' | 'contentHelpful' | 'homeGreeting' | 'homeGreetingNamed' | 'homeGreetingLead' | 'homeSearchPlaceholder' | 'homeAskPlaceholder' | 'homeWhatsNew' | 'homeContentTitle' | 'homeStatus' | 'helpTitle' | 'helpSearchPlaceholder' | 'helpEmpty' | 'helpLoading' | 'helpSearchEmpty' | 'helpShowMore' | 'newsTitle' | 'newsEmpty' | 'newsLoading' | 'newsBack' | 'newsPublishedAt' | 'newsShowMore' | 'newsUnseen';
43
43
  /** A partial map for one locale — what overrides look like on the wire. */
44
44
  type LocaleStrings = Partial<Record<StringKey, string>>;
45
45
  /**
@@ -899,6 +899,38 @@ interface ResolvedTracking {
899
899
  * alongside at the top level — they're function / DOM types that can't be
900
900
  * serialised on the wire.
901
901
  */
902
+ /** A signed user token, or a function that returns a fresh one (see {@link ChatWidgetOptions.userToken}). */
903
+ type UserTokenSource = string | (() => string | Promise<string>);
904
+ /** WebMCP `ToolAnnotations`: hints about what a tool does. */
905
+ interface ToolAnnotations {
906
+ /** It only reads; it changes nothing. */
907
+ readOnlyHint?: boolean;
908
+ /** Its result holds content the site doesn't vouch for, such as reviews. */
909
+ untrustedContentHint?: boolean;
910
+ /** A significant or irreversible action (booking, paying, deleting): the visitor approves each call first. */
911
+ consequentialHint?: boolean;
912
+ /** Built for developers, not visitors. */
913
+ debugging?: boolean;
914
+ }
915
+ /**
916
+ * A tool the AI agent can use on your page, in the WebMCP `ModelContextTool` shape: the same object works with
917
+ * `document.modelContext.registerTool()`. The agent sees `name`, `description` and `inputSchema`; `execute` runs here,
918
+ * in the visitor's browser, and what it returns goes back to the agent.
919
+ */
920
+ interface ModelContextTool<TInput = unknown> {
921
+ /** Letters, digits, `_` and `-` (58 at most; others become `_`). A name registered again replaces the earlier tool. */
922
+ name: string;
923
+ title?: string;
924
+ /** When the agent should use it and what it does (1024 characters at most). */
925
+ description: string;
926
+ /** JSON Schema of the input (`type: "object"`); none means the tool takes no input. */
927
+ inputSchema?: Record<string, unknown>;
928
+ annotations?: ToolAnnotations;
929
+ /** Runs the tool: return a JSON value (or a promise of one) for the agent; throw to report a failure. `signal` aborts when the visitor moves on first. */
930
+ execute(input: TInput, options: {
931
+ signal: AbortSignal;
932
+ }): unknown;
933
+ }
902
934
  interface ChatWidgetOptions {
903
935
  /**
904
936
  * Stable identifier for this widget instance. Use when mounting more
@@ -974,6 +1006,20 @@ interface ChatWidgetOptions {
974
1006
  * interface (`get` / `set` / `remove` / `clear`).
975
1007
  */
976
1008
  storage?: ClientStorage;
1009
+ /**
1010
+ * Proves who the logged-in visitor is: a JWT your server signs (HS256) with the deployment's secret key, carrying
1011
+ * `sub` (your user id) and `exp`, optionally `name` and `email`. A function is called when a token is first
1012
+ * needed and again when the server rejects the current one as expired, so return a fresh token from it. Their
1013
+ * conversations then follow them to any device; `chat.login(token)` sets it after sign-in, `chat.reset()` on
1014
+ * sign-out. Sent only to the agent API, as `x-user-token`.
1015
+ */
1016
+ userToken?: UserTokenSource;
1017
+ /**
1018
+ * Tools the AI agent can use on your page (open a booking form, read the cart, jump to a section), WebMCP
1019
+ * `ModelContextTool`s. Sent with each message as definitions only; the agent's call runs `execute` here, in the
1020
+ * visitor's browser. `registerTool()` adds one from anywhere, for example a single-page app's route.
1021
+ */
1022
+ tools?: readonly ModelContextTool[];
977
1023
  onMessage?: (msg: {
978
1024
  role: string;
979
1025
  text: string;
@@ -1084,11 +1130,15 @@ interface ResolvedOptions {
1084
1130
  tracking: ResolvedTracking;
1085
1131
  /** Resolved storage adapter — defaults to `LocalStorageAdapter`. */
1086
1132
  storage: ClientStorage;
1133
+ userToken?: UserTokenSource;
1134
+ tools?: readonly ModelContextTool[];
1087
1135
  onMessage?: ChatWidgetOptions['onMessage'];
1088
1136
  onOpen?: ChatWidgetOptions['onOpen'];
1089
1137
  onClose?: ChatWidgetOptions['onClose'];
1090
1138
  onError?: ChatWidgetOptions['onError'];
1091
1139
  }
1140
+ /** How a call this page ran (or found cut short) ended, for the `toolResult` event. */
1141
+ type PageToolCallStatus = 'completed' | 'failed' | 'interrupted';
1092
1142
  /** A single image asset (logo, hero, icon). */
1093
1143
  declare const assetSchema: z.ZodObject<{
1094
1144
  url: z.ZodString;
@@ -3134,15 +3184,27 @@ interface EventMap {
3134
3184
  values: Record<string, string>;
3135
3185
  skipped: boolean;
3136
3186
  };
3137
- /** User answered an ask-questions tool request (re-POST follows). */
3187
+ /**
3188
+ * A tool call settled on the page: the visitor answered an ask-questions request (`toolCallId` only), or a page
3189
+ * tool's call ended — `completed`, `failed`, `declined` or `stopped` by the visitor, or `interrupted` by a reload —
3190
+ * after `durationMs`. Never its input or result.
3191
+ */
3138
3192
  toolResult: {
3139
3193
  toolCallId: string;
3194
+ name?: string;
3195
+ status?: PageToolCallStatus | 'declined' | 'stopped';
3196
+ durationMs?: number;
3140
3197
  };
3141
3198
  /** User approved / rejected a gated tool call (re-POST follows). */
3142
3199
  toolDecision: {
3143
3200
  toolCallId: string;
3144
3201
  approved: boolean;
3145
3202
  };
3203
+ /** Your page reported its own event with `track(name, data)`: sent to analytics, and to the agent with the next message. */
3204
+ hostEvent: {
3205
+ name: string;
3206
+ data?: Record<string, string | number | boolean>;
3207
+ };
3146
3208
  /**
3147
3209
  * User gave feedback on a rateable reply (AI or operator). `value` is `"up"` / `"down"`, or
3148
3210
  * `null` when they cleared a prior choice. `messageId` is the backend message
@@ -3290,6 +3352,8 @@ interface AskOptions {
3290
3352
  /** Send the text as the visitor's message instead of filling the composer with it. Default `false`. */
3291
3353
  send?: boolean;
3292
3354
  }
3355
+ /** Flat data about a host event: strings, numbers and booleans only. */
3356
+ type HostEventData = Record<string, string | number | boolean>;
3293
3357
  /**
3294
3358
  * Comprehensive logger for the widget runtime.
3295
3359
  *
@@ -3384,6 +3448,47 @@ export interface ChatWidgetInstance {
3384
3448
  * Listeners added with `on()` stay.
3385
3449
  */
3386
3450
  reset: () => void;
3451
+ /**
3452
+ * Sign the visitor in as your logged-in user, after they log in to your site: `userToken` is a JWT your server
3453
+ * signs with the deployment's secret key (`sub`, `exp`; optional `name`, `email`), or a function that returns a
3454
+ * fresh one. The widget reconnects as that user: their earlier chats on this browser move to them, and their
3455
+ * conversations follow them to any device. Call `reset()` when they log out.
3456
+ *
3457
+ * @example
3458
+ * ```ts
3459
+ * chat.login(async () => (await fetch('/api/help-ai-token')).text());
3460
+ * ```
3461
+ */
3462
+ login: (userToken: UserTokenSource) => void;
3463
+ /**
3464
+ * Report something the visitor did on your site, outside the chat. Sends a `hostEvent` hit to analytics (not when
3465
+ * tracking is off), and the agent reads your last 10 events with the visitor's next message. `name` is 1–64
3466
+ * characters; `data` is flat (strings, numbers, booleans), 256 characters of JSON at most.
3467
+ *
3468
+ * @example
3469
+ * ```ts
3470
+ * chat.track('plan_viewed', { plan: 'pro' });
3471
+ * ```
3472
+ */
3473
+ track: (name: string, data?: HostEventData) => void;
3474
+ /**
3475
+ * Add a tool the agent can use on this page, in the WebMCP tool shape — for every widget on the page, not only this
3476
+ * one. The latest registration of a name wins; aborting `options.signal` removes it. `annotations.consequentialHint`
3477
+ * asks the visitor before each call. See `docs/sdk/page-tools.md`.
3478
+ *
3479
+ * @example
3480
+ * ```ts
3481
+ * chat.registerTool({
3482
+ * name: 'open_booking',
3483
+ * description: 'Open the booking form for a meeting type.',
3484
+ * inputSchema: { type: 'object', properties: { meetingType: { type: 'string', enum: ['sales', 'support'] } }, required: ['meetingType'] },
3485
+ * execute: ({ meetingType }) => booking.open(meetingType),
3486
+ * });
3487
+ * ```
3488
+ */
3489
+ registerTool: (tool: ModelContextTool, options?: {
3490
+ signal?: AbortSignal;
3491
+ }) => void;
3387
3492
  /**
3388
3493
  * Subscribe to a lifecycle event. Returns an `off` function. See
3389
3494
  * {@link EventMap} for the full set + payload shapes — currently
@@ -3543,10 +3648,26 @@ export interface HelpAIControls {
3543
3648
  open: ChatWidgetInstance['open'];
3544
3649
  close: ChatWidgetInstance['close'];
3545
3650
  reset: ChatWidgetInstance['reset'];
3651
+ track: ChatWidgetInstance['track'];
3546
3652
  }
3547
3653
  /**
3548
3654
  * The widget's state and commands, for any component in the app, wherever `<HelpAI />` sits. A command sent before
3549
3655
  * the widget has mounted does nothing; `state.ready` turns true once it takes them.
3550
3656
  */
3551
3657
  export declare function useHelpAI(widgetId?: string): HelpAIControls;
3552
- export type { AskOptions, Asset, BlocksConfig, ChatWidgetOptions, ConnectionConfig, ConnectionConfigPartial, EventMap, EventName, HandshakeResponse, HookListener, Link, LogEntry, LogLevel, OpenTarget, ResolvedOptions, ServerConfig, SiteConfig, WidgetConfig, WidgetConfigPartial, WidgetSettings, WidgetSettingsPartial, WidgetState };
3658
+ /**
3659
+ * Give the agent a tool on this page while the component is mounted (WebMCP `registerTool`): every widget on the
3660
+ * page can use it. A change to its definition registers it again; `execute` always runs the latest render's function.
3661
+ *
3662
+ * @example
3663
+ * ```tsx
3664
+ * useHelpAITool({
3665
+ * name: 'add_to_cart',
3666
+ * description: 'Add a product to the visitor\'s cart.',
3667
+ * inputSchema: { type: 'object', properties: { sku: { type: 'string' } }, required: ['sku'] },
3668
+ * execute: ({ sku }) => cart.add(sku),
3669
+ * });
3670
+ * ```
3671
+ */
3672
+ export declare function useHelpAITool<TInput>(tool: ModelContextTool<TInput>): void;
3673
+ export type { AskOptions, Asset, BlocksConfig, ChatWidgetOptions, ConnectionConfig, ConnectionConfigPartial, EventMap, EventName, HandshakeResponse, HookListener, HostEventData, Link, LogEntry, LogLevel, ModelContextTool, OpenTarget, ResolvedOptions, ServerConfig, SiteConfig, ToolAnnotations, UserTokenSource, WidgetConfig, WidgetConfigPartial, WidgetSettings, WidgetSettingsPartial, WidgetState };