@helpai/elements 1.10.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/docs/README.md +1 -0
- package/docs/analytics.md +27 -0
- package/docs/api-reference.md +54 -2
- package/docs/configuration.md +18 -0
- package/docs/events-and-hooks.md +13 -11
- package/docs/frameworks.md +4 -1
- package/docs/page-tools.md +194 -0
- package/elements-web-component.esm.js +39 -39
- package/elements-web-component.esm.js.map +4 -4
- package/elements.cjs.js +39 -39
- package/elements.cjs.js.map +4 -4
- package/elements.esm.js +39 -39
- package/elements.esm.js.map +4 -4
- package/elements.js +39 -39
- package/elements.js.map +4 -4
- package/index.d.ts +85 -3
- package/index.mjs +14 -14
- package/jsx-react.d.ts +2 -1
- package/jsx-svelte.d.ts +2 -1
- package/jsx-vue.d.ts +3 -2
- package/llms-full.txt +449 -147
- package/llms.txt +21 -18
- package/package.json +1 -1
- package/react.d.ts +101 -3
- package/react.mjs +31 -31
- package/style.css +1 -1
- package/web-component.d.ts +87 -3
- package/web-component.mjs +14 -14
package/llms.txt
CHANGED
|
@@ -1,37 +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.
|
|
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.
|
|
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
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.
|
|
13
15
|
- `theme: 'host'` (`theme="host"`) follows the site's own light/dark switch.
|
|
14
16
|
- Pin the exact version in production, as above; `latest` changes under you.
|
|
15
17
|
- It works when the launcher shows in the bottom corner and `HelpAI.ready()` (or `chat.ready`) resolves.
|
|
16
18
|
|
|
17
19
|
## Docs
|
|
18
20
|
|
|
19
|
-
- [Quickstart](https://cdn.help.ai/sdk/js/elements/1.
|
|
20
|
-
- [Installation](https://cdn.help.ai/sdk/js/elements/1.
|
|
21
|
-
- [Frameworks](https://cdn.help.ai/sdk/js/elements/1.
|
|
22
|
-
- [Configuration](https://cdn.help.ai/sdk/js/elements/1.
|
|
23
|
-
- [Option reference](https://cdn.help.ai/sdk/js/elements/1.
|
|
24
|
-
- [API reference](https://cdn.help.ai/sdk/js/elements/1.
|
|
25
|
-
- [Events and hooks](https://cdn.help.ai/sdk/js/elements/1.
|
|
26
|
-
- [
|
|
27
|
-
- [
|
|
28
|
-
- [
|
|
29
|
-
- [
|
|
30
|
-
- [
|
|
31
|
-
- [
|
|
32
|
-
- [
|
|
33
|
-
- [
|
|
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
|
|
34
37
|
|
|
35
38
|
## Optional
|
|
36
39
|
|
|
37
|
-
- [Every doc in one file](https://cdn.help.ai/sdk/js/elements/1.
|
|
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
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
|
/**
|
|
@@ -901,6 +901,36 @@ interface ResolvedTracking {
|
|
|
901
901
|
*/
|
|
902
902
|
/** A signed user token, or a function that returns a fresh one (see {@link ChatWidgetOptions.userToken}). */
|
|
903
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
|
+
}
|
|
904
934
|
interface ChatWidgetOptions {
|
|
905
935
|
/**
|
|
906
936
|
* Stable identifier for this widget instance. Use when mounting more
|
|
@@ -984,6 +1014,12 @@ interface ChatWidgetOptions {
|
|
|
984
1014
|
* sign-out. Sent only to the agent API, as `x-user-token`.
|
|
985
1015
|
*/
|
|
986
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[];
|
|
987
1023
|
onMessage?: (msg: {
|
|
988
1024
|
role: string;
|
|
989
1025
|
text: string;
|
|
@@ -1095,11 +1131,14 @@ interface ResolvedOptions {
|
|
|
1095
1131
|
/** Resolved storage adapter — defaults to `LocalStorageAdapter`. */
|
|
1096
1132
|
storage: ClientStorage;
|
|
1097
1133
|
userToken?: UserTokenSource;
|
|
1134
|
+
tools?: readonly ModelContextTool[];
|
|
1098
1135
|
onMessage?: ChatWidgetOptions['onMessage'];
|
|
1099
1136
|
onOpen?: ChatWidgetOptions['onOpen'];
|
|
1100
1137
|
onClose?: ChatWidgetOptions['onClose'];
|
|
1101
1138
|
onError?: ChatWidgetOptions['onError'];
|
|
1102
1139
|
}
|
|
1140
|
+
/** How a call this page ran (or found cut short) ended, for the `toolResult` event. */
|
|
1141
|
+
type PageToolCallStatus = 'completed' | 'failed' | 'interrupted';
|
|
1103
1142
|
/** A single image asset (logo, hero, icon). */
|
|
1104
1143
|
declare const assetSchema: z.ZodObject<{
|
|
1105
1144
|
url: z.ZodString;
|
|
@@ -3145,15 +3184,27 @@ interface EventMap {
|
|
|
3145
3184
|
values: Record<string, string>;
|
|
3146
3185
|
skipped: boolean;
|
|
3147
3186
|
};
|
|
3148
|
-
/**
|
|
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
|
+
*/
|
|
3149
3192
|
toolResult: {
|
|
3150
3193
|
toolCallId: string;
|
|
3194
|
+
name?: string;
|
|
3195
|
+
status?: PageToolCallStatus | 'declined' | 'stopped';
|
|
3196
|
+
durationMs?: number;
|
|
3151
3197
|
};
|
|
3152
3198
|
/** User approved / rejected a gated tool call (re-POST follows). */
|
|
3153
3199
|
toolDecision: {
|
|
3154
3200
|
toolCallId: string;
|
|
3155
3201
|
approved: boolean;
|
|
3156
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
|
+
};
|
|
3157
3208
|
/**
|
|
3158
3209
|
* User gave feedback on a rateable reply (AI or operator). `value` is `"up"` / `"down"`, or
|
|
3159
3210
|
* `null` when they cleared a prior choice. `messageId` is the backend message
|
|
@@ -3301,6 +3352,8 @@ interface AskOptions {
|
|
|
3301
3352
|
/** Send the text as the visitor's message instead of filling the composer with it. Default `false`. */
|
|
3302
3353
|
send?: boolean;
|
|
3303
3354
|
}
|
|
3355
|
+
/** Flat data about a host event: strings, numbers and booleans only. */
|
|
3356
|
+
type HostEventData = Record<string, string | number | boolean>;
|
|
3304
3357
|
/**
|
|
3305
3358
|
* Comprehensive logger for the widget runtime.
|
|
3306
3359
|
*
|
|
@@ -3407,6 +3460,35 @@ export interface ChatWidgetInstance {
|
|
|
3407
3460
|
* ```
|
|
3408
3461
|
*/
|
|
3409
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;
|
|
3410
3492
|
/**
|
|
3411
3493
|
* Subscribe to a lifecycle event. Returns an `off` function. See
|
|
3412
3494
|
* {@link EventMap} for the full set + payload shapes — currently
|
|
@@ -3566,10 +3648,26 @@ export interface HelpAIControls {
|
|
|
3566
3648
|
open: ChatWidgetInstance['open'];
|
|
3567
3649
|
close: ChatWidgetInstance['close'];
|
|
3568
3650
|
reset: ChatWidgetInstance['reset'];
|
|
3651
|
+
track: ChatWidgetInstance['track'];
|
|
3569
3652
|
}
|
|
3570
3653
|
/**
|
|
3571
3654
|
* The widget's state and commands, for any component in the app, wherever `<HelpAI />` sits. A command sent before
|
|
3572
3655
|
* the widget has mounted does nothing; `state.ready` turns true once it takes them.
|
|
3573
3656
|
*/
|
|
3574
3657
|
export declare function useHelpAI(widgetId?: string): HelpAIControls;
|
|
3575
|
-
|
|
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 };
|