@helpai/elements 0.25.0 → 0.27.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/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- export { A as Asset, B as BlocksConfig, C as ConnectionConfig, a as ConnectionConfigPartial, L as Link, S as ServerConfig, b as SiteConfig, c as StartConversationResponse, W as WidgetConfig, d as WidgetConfigPartial, e as WidgetSettings, f as WidgetSettingsPartial } from './deployment-B0uvvJYK.js';
1
+ export { A as Asset, B as BlocksConfig, C as ConnectionConfig, a as ConnectionConfigPartial, H as HandshakeResponse, L as Link, S as ServerConfig, b as SiteConfig, W as WidgetConfig, c as WidgetConfigPartial, d as WidgetSettings, e as WidgetSettingsPartial } from './deployment-CcW_mx_i.js';
2
2
  import 'zod';
3
3
 
4
4
  /**
@@ -113,73 +113,11 @@ interface UserPrefs {
113
113
  textSize?: "small" | "normal" | "large";
114
114
  }
115
115
 
116
- /**
117
- * A human-in-the-loop approval decision on a tool call. Mirrors AI SDK v6's
118
- * `ToolUIPart.approval`: `id` correlates the request ↔ response; `approved`
119
- * is filled once the user decides; `reason` is an optional note.
120
- */
121
- interface ToolApproval {
122
- id: string;
123
- approved?: boolean;
124
- reason?: string;
125
- }
126
- /**
127
- * Lifecycle of a tool part. `input` — args streaming. `awaiting` —
128
- * server-executed tool waiting on output. `awaiting-input` — the ask-input
129
- * tool waiting on the user's inline-form answer. `awaiting-approval` — a gated
130
- * action waiting on approve/reject. `output` — resolved. `error` — failed.
131
- */
132
- type ToolState = "input" | "awaiting" | "awaiting-input" | "awaiting-approval" | "output" | "error";
133
-
134
116
  /** A tool reference on the wire: `{ code, config }`. `config` is opaque. */
135
117
  interface ToolRef {
136
118
  code: string;
137
119
  config?: Record<string, unknown>;
138
120
  }
139
- interface WireMessage {
140
- id: string;
141
- role: "user" | "assistant" | "system";
142
- parts: WirePart[];
143
- /**
144
- * ISO-8601 timestamp the message was created (a serialized Mongo ISODate,
145
- * e.g. `2026-06-10T07:50:55.816Z`) — every wire date uses this format.
146
- * Optional so older backends still parse; when present, the widget shows
147
- * the real send time (and groups messages by day) on reload instead of
148
- * falling back to "now". Parse with {@link parseWireDate}.
149
- */
150
- createdAt?: string;
151
- }
152
- type WirePart = {
153
- type: "text";
154
- text: string;
155
- } | {
156
- type: "file";
157
- /** Canonical URL. May be a custom scheme (e.g. `library-id://<id>`). */
158
- url: string;
159
- mediaType: string;
160
- /** Original filename as uploaded. */
161
- filename?: string;
162
- /** Opaque id from the upload response — lets the backend dedupe + cache. */
163
- fileId?: string;
164
- /** Size in bytes. */
165
- fileSize?: number;
166
- } | {
167
- /**
168
- * A tool call on the wire. Carries the resolved result up to the backend
169
- * on a HITL re-POST: the ask-input answer rides in `output`, an approval
170
- * decision in `approval`. Sent up only for parts the user has acted on
171
- * (state `output`/`error`/`awaiting-approval` with a decision); in-flight
172
- * tool parts are not re-serialized. Aligns with AI SDK v6 tool parts.
173
- */
174
- type: "tool";
175
- toolCallId: string;
176
- toolName: string;
177
- state: ToolState;
178
- input?: unknown;
179
- output?: unknown;
180
- errorText?: string;
181
- approval?: ToolApproval;
182
- };
183
121
  /** One-shot bot persona shown in the panel header. */
184
122
  interface ConversationAgent {
185
123
  name: string;
@@ -208,8 +146,12 @@ interface ConversationWelcome {
208
146
  suggestions?: ConversationSuggestion[];
209
147
  }
210
148
  /**
211
- * Response from `POST /ai/agent/start-conversation`. Every field is optional so the
212
- * backend can opt into surfaces incrementally.
149
+ * Response from `POST /pai/handshake` the widget's one mount-time
150
+ * round-trip. Deliberately LIGHT: identity + deployment surface only
151
+ * (config, agent persona, welcome, page-mode site/blocks, userPrefs).
152
+ * The conversation THREAD is a separate, lazily-fetched read
153
+ * (`GET /conversation`) that only runs once the widget is activated
154
+ * (opened) — a closed launcher costs the page exactly one request.
213
155
  *
214
156
  * The `userPrefs` field (when present) is the server's authoritative
215
157
  * copy of per-visitor preferences — the client should adopt it and update
@@ -217,14 +159,13 @@ interface ConversationWelcome {
217
159
  * widget in French when they open it on their laptop (assuming the same
218
160
  * `visitorId`, e.g. via authenticated conversation — out of scope for v1).
219
161
  */
220
- interface StartConversationResponse {
162
+ interface HandshakeResponse {
221
163
  /**
222
164
  * Public runtime conversation id. The widget mints this UUIDv7 and the backend
223
165
  * validates that it belongs to the public deployment + visitor.
224
166
  */
225
167
  conversationId: string;
226
168
  visitorId?: string;
227
- canContinue?: boolean;
228
169
  /** Bot persona in the panel header (name, avatar, status). */
229
170
  agent?: ConversationAgent;
230
171
  /** Initial assistant messages + quick-reply chips. */
@@ -240,7 +181,6 @@ interface StartConversationResponse {
240
181
  site?: Record<string, unknown>;
241
182
  /** Page-mode sidebar blocks (navigation, link cards). Backend ships it whenever the deployment renders the page-shell sidebar. */
242
183
  blocks?: Record<string, unknown>;
243
- messages?: WireMessage[];
244
184
  /**
245
185
  * Server's authoritative copy of the visitor's preferences. When present,
246
186
  * client adopts it (overrides local cache) and re-applies it to the UI
@@ -292,7 +232,7 @@ type Position = "bottom-right" | "bottom-left" | "top-right" | "top-left";
292
232
  * `"12px"` horizontal — restore the legacy full-edge
293
233
  * slab with `size: { width: "100vw", height: "100vh", inset: "0" }`.
294
234
  *
295
- * Page mode reads `site` and `blocks` from the start-conversation response.
235
+ * Page mode reads `site` and `blocks` from the handshake response.
296
236
  */
297
237
  type Mode = "floating" | "inline" | "standalone" | "page" | "modal" | "drawer";
298
238
  /** End-user text-size preference — scales the whole type ramp. */
@@ -961,9 +901,9 @@ interface PageContext {
961
901
  * like a CDN presign service).
962
902
  */
963
903
  interface Endpoints {
964
- /** File upload endpoint. Default: `'/ai/agent/upload-file'`. */
904
+ /** File upload endpoint. Default: `'/pai/upload-file'`. */
965
905
  upload?: string;
966
- /** Voice transcription endpoint. Default: `'/ai/agent/transcribe-audio'`. */
906
+ /** Voice transcription endpoint. Default: `'/pai/transcribe-audio'`. */
967
907
  transcribe?: string;
968
908
  /**
969
909
  * Form submission endpoint. Default: `'/submit-form'`. When any form
@@ -993,13 +933,14 @@ interface Endpoints {
993
933
  /** Section: anonymous owner-facing usage tracking. */
994
934
  interface TrackingOptions {
995
935
  /**
996
- * Master switch. Default `false` — tracking stays off until the
997
- * deployment (or the embedding page) explicitly turns it on.
936
+ * Master switch. Default `true` — the widget always fires; the data
937
+ * module gates ingestion per deployment server-side. Set `false`
938
+ * (deployment config or init) to silence the client entirely.
998
939
  */
999
940
  enabled?: boolean;
1000
941
  /**
1001
- * Pixel collector URL. Default: `${dataBaseUrl}/elements/px.gif`
1002
- * (e.g. `https://help.ai/api/data/elements/px.gif`).
942
+ * Pixel collector URL. Default: `${dataBaseUrl}/pai/elements-px.gif`
943
+ * (e.g. `https://help.ai/api/data/pai/elements-px.gif`).
1003
944
  */
1004
945
  endpoint?: string;
1005
946
  /**
@@ -1010,7 +951,7 @@ interface TrackingOptions {
1010
951
  /**
1011
952
  * Anti-forgery token, echoed as `tk=` on every hit. **Server-issued,
1012
953
  * never set by hand** — the backend mints it in the
1013
- * `/start-conversation` response (HMAC over `pk`/`vid`/expiry with a
954
+ * `/handshake` response (HMAC over `pk`/`vid`/expiry with a
1014
955
  * server-side secret; see `docs/api/tracking-collector.md`) and the
1015
956
  * collector verifies it statelessly. Opaque to the client.
1016
957
  */
@@ -1027,7 +968,7 @@ interface ResolvedTracking {
1027
968
  /**
1028
969
  * The three composing roots: raw input ({@link ChatWidgetOptions}),
1029
970
  * post-normalisation runtime shape ({@link ResolvedOptions}), and the
1030
- * subset the server can push back via `/start-conversation` ({@link
971
+ * subset the server can push back via `/handshake` ({@link
1031
972
  * ServerConfig}).
1032
973
  *
1033
974
  * Internal modules always depend on `ResolvedOptions`. The raw shape
@@ -1066,14 +1007,26 @@ interface ChatWidgetOptions {
1066
1007
  aiAgentDeploymentId?: string;
1067
1008
  /**
1068
1009
  * MAIN site origin (no trailing slash, e.g. `https://help.ai`). The API
1069
- * modules derive from it: the agent API lives at `${baseUrl}/api/agent`,
1070
- * the data API at `${baseUrl}/api/data`. Defaults to the brand's origin.
1010
+ * modules derive from it the production edge mounts the agent API at
1011
+ * `${baseUrl}/api/agent` and the data API at `${baseUrl}/api/data`.
1012
+ * Defaults to the brand's origin.
1071
1013
  */
1072
1014
  baseUrl?: string;
1015
+ /**
1016
+ * Agent-API base (no trailing slash) — set it when the
1017
+ * `module-help-ai-agent-api` service is reached DIRECTLY (a standalone
1018
+ * local module, e.g. `http://localhost:3087`) instead of through the
1019
+ * edge. Routes attach as-is (`${agentBaseUrl}/pai/handshake`).
1020
+ * Precedence: this option > derived from the main origin
1021
+ * (`${baseUrl}/api/agent`). Not server-pushable — the handshake already
1022
+ * travelled over it.
1023
+ */
1024
+ agentBaseUrl?: string;
1073
1025
  /**
1074
1026
  * Data-API base (no trailing slash) — the `module-help-ai-data-api`
1075
1027
  * service serving content, form definitions, and form submissions at
1076
1028
  * root-level paths (`/content`, `/forms`, `/activity`, `/submit-form`).
1029
+ * Set it for a standalone local module (e.g. `http://localhost:3106`).
1077
1030
  * Precedence: this option > server-pushed `config.dataBaseUrl` > derived
1078
1031
  * from the main origin (`${baseUrl}/api/data`, e.g.
1079
1032
  * `https://help.ai/api/data`).
@@ -1133,6 +1086,8 @@ interface ResolvedOptions {
1133
1086
  publicKey?: string;
1134
1087
  aiAgentDeploymentId?: string;
1135
1088
  baseUrl: string;
1089
+ /** Resolved agent-API base — see {@link ChatWidgetOptions.agentBaseUrl}. */
1090
+ agentBaseUrl: string;
1136
1091
  /** Resolved data-API base — see {@link ChatWidgetOptions.dataBaseUrl}. */
1137
1092
  dataBaseUrl: string;
1138
1093
  userContext?: UserContext;
@@ -1221,7 +1176,7 @@ interface ResolvedOptions {
1221
1176
  onError?: ChatWidgetOptions["onError"];
1222
1177
  }
1223
1178
  /**
1224
- * Shape of the server-pushed `widget` object in `StartConversationResponse`.
1179
+ * Shape of the server-pushed `widget` object in `HandshakeResponse`.
1225
1180
  *
1226
1181
  * Matches a subset of {@link ChatWidgetOptions} — anything the server can
1227
1182
  * reasonably dictate (UI, behaviour, routing). Callbacks (`onMessage` etc.)
@@ -1395,18 +1350,18 @@ interface EventMap {
1395
1350
  /** An unhandled error occurred somewhere in the transport or UI. */
1396
1351
  error: unknown;
1397
1352
  /** Connect bootstrap succeeded. Payload is the typed server response. */
1398
- conversationStarted: StartConversationResponse;
1353
+ handshake: HandshakeResponse;
1399
1354
  /**
1400
1355
  * Server rebound the `visitorId` — e.g. the client-minted id
1401
1356
  * conflicted with an existing record, was expired, or otherwise
1402
1357
  * rejected, and the server returned a fresh one in the
1403
- * `/start-conversation` response. The widget has already adopted the new
1358
+ * `/handshake` response. The widget has already adopted the new
1404
1359
  * id and persisted it; this event is informational so host pages
1405
1360
  * can re-link analytics / external systems that pinned the
1406
1361
  * previous value.
1407
1362
  *
1408
1363
  * `reason` is the server's explanation, when provided
1409
- * (`rebind.visitorId` in the start-conversation response). Common values:
1364
+ * (`rebind.visitorId` in the handshake response). Common values:
1410
1365
  * `"conflict"` / `"expired"` / `"invalid"`. May be `undefined` if
1411
1366
  * the server didn't include a `rebind` block.
1412
1367
  */
@@ -1535,7 +1490,7 @@ interface ChatWidgetInstance {
1535
1490
  expand: () => void;
1536
1491
  /**
1537
1492
  * Open the widget in a new browser tab at `behavior.popOutUrl`
1538
- * (mount option / start-conversation-pushable), or the brand's
1493
+ * (mount option / handshake-pushable), or the brand's
1539
1494
  * `BRAND.standaloneUrl` build-time default. Carries the active
1540
1495
  * `chat` + `widgetId` as query params. No-ops when the resolved
1541
1496
  * URL is empty.
@@ -1551,7 +1506,7 @@ interface ChatWidgetInstance {
1551
1506
  * Subscribe to a lifecycle event. Returns an `off` function. See
1552
1507
  * {@link EventMap} for the full set + payload shapes — currently
1553
1508
  * `open | close | message | error | expand | fullscreen | popOut |
1554
- * conversationStarted | localeChange`.
1509
+ * handshake | localeChange`.
1555
1510
  */
1556
1511
  on: <E extends EventName>(name: E, fn: (payload: EventMap[E]) => void) => () => void;
1557
1512
  /**
@@ -1572,7 +1527,7 @@ interface ChatWidgetInstance {
1572
1527
  * ```
1573
1528
  */
1574
1529
  setUserContext: (userContext: UserContext) => void;
1575
- /** Clear the end-user context (e.g. on logout) and re-start-conversation anonymously. */
1530
+ /** Clear the end-user context (e.g. on logout) and re-handshake anonymously. */
1576
1531
  clearUserContext: () => void;
1577
1532
  /**
1578
1533
  * Set / merge the host-asserted page/visit context (`area`, `url`, `path`,
@@ -1586,7 +1541,7 @@ interface ChatWidgetInstance {
1586
1541
  * ```
1587
1542
  */
1588
1543
  setPageContext: (pageContext: PageContext) => void;
1589
- /** Clear the page/visit context and re-start-conversation. */
1544
+ /** Clear the page/visit context and re-handshake. */
1590
1545
  clearPageContext: () => void;
1591
1546
  /**
1592
1547
  * Set the runtime log level. Accepts `"off"` / `"error"` / `"warn"` /