@saar-ai/web-widget 0.8.0 → 0.9.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/dist/chunks/{chat-e1afSRBr.js → chat-DAgqVvIS.js} +150 -23
- package/dist/chunks/{host-widget-Ce-l1xu1.js → host-widget-CTK7C95y.js} +186 -11
- package/dist/chunks/{telemetry-CBblNC6C.js → telemetry-DQUulENJ.js} +15 -0
- package/dist/dock/dock.d.ts +41 -8
- package/dist/dock/dock.d.ts.map +1 -1
- package/dist/host-routes.d.ts +187 -0
- package/dist/host-routes.d.ts.map +1 -0
- package/dist/host-widget.d.ts +18 -1
- package/dist/host-widget.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/mount.d.ts +10 -1
- package/dist/mount.d.ts.map +1 -1
- package/dist/next/index.js +1 -1
- package/dist/use-chat-session.d.ts +54 -32
- package/dist/use-chat-session.d.ts.map +1 -1
- package/dist/use-voice-session.d.ts +11 -8
- package/dist/use-voice-session.d.ts.map +1 -1
- package/package.json +2 -2
|
@@ -177,6 +177,37 @@ var WidgetNavigateFailedReportSchema = object({
|
|
|
177
177
|
target: NavigateTargetSchema.optional()
|
|
178
178
|
}).strict();
|
|
179
179
|
//#endregion
|
|
180
|
+
//#region ../widget-protocol/dist/currency.js
|
|
181
|
+
/**
|
|
182
|
+
* The ISO 4217 currency-code schema every currency field on this wire
|
|
183
|
+
* shares — three LETTERS, case preserved, never a bare length check.
|
|
184
|
+
*
|
|
185
|
+
* ## Why the charset is the control, not the length
|
|
186
|
+
*
|
|
187
|
+
* `z.string().length(3)` and this schema admit the same LENGTH, but
|
|
188
|
+
* `"\n- "` is three characters and only one of the schemas below refuses
|
|
189
|
+
* it. A currency value that reaches a model as prose — `chat.ts`'s cards,
|
|
190
|
+
* `@wesence/agent-core`'s `renderShopperCartForModel` — sits on the same
|
|
191
|
+
* line as a price, and a newline there forges a line boundary in a block
|
|
192
|
+
* whose entire legibility rests on one line per item. The titles beside it
|
|
193
|
+
* have always been trimmed/bounded for exactly this reason; a currency code
|
|
194
|
+
* was left at `length(3)` because three characters "looks safe," which is
|
|
195
|
+
* precisely the assumption this regex refuses to make.
|
|
196
|
+
*
|
|
197
|
+
* ## Why this lives in its own module, not just `chat.ts`
|
|
198
|
+
*
|
|
199
|
+
* This schema used to be declared privately inside `chat.ts` and never
|
|
200
|
+
* exported. `catalog.ts` and `curation.ts` — this same package — each grew
|
|
201
|
+
* their own `z.string().length(3)` instead of importing it, and
|
|
202
|
+
* `@wesence/agent-core`'s `shopper-cart.ts` grew a fourth copy of the regex
|
|
203
|
+
* itself rather than importing this one. An unexported validator gets
|
|
204
|
+
* re-invented at every call site that needs it, and re-invention is exactly
|
|
205
|
+
* how two of those four copies lost the hardening. This module is the one
|
|
206
|
+
* place `CURRENCY_CODE` is declared; every schema on both legs of a widget
|
|
207
|
+
* conversation imports it from here rather than restating it.
|
|
208
|
+
*/
|
|
209
|
+
var CURRENCY_CODE = string().regex(/^[A-Za-z]{3}$/, "must be a three-letter ISO 4217 currency code");
|
|
210
|
+
//#endregion
|
|
180
211
|
//#region ../widget-protocol/dist/chat.js
|
|
181
212
|
/**
|
|
182
213
|
* The webchat SSE wire contract, and the sidecar `widgetEvent` a tool result
|
|
@@ -242,14 +273,6 @@ var CARD_TEXT_MAX = 500;
|
|
|
242
273
|
/** Bound for an id-shaped field (product/variant/curation ids). */
|
|
243
274
|
var ID_MAX = 200;
|
|
244
275
|
/**
|
|
245
|
-
* An ISO 4217 currency code, as a schema — three LETTERS, case preserved.
|
|
246
|
-
*
|
|
247
|
-
* Shared by every currency field on this wire so none of them can drift back
|
|
248
|
-
* to a bare `length(3)`. See {@link WidgetChatCardSchema}'s `currency` for the
|
|
249
|
-
* prompt-injection reason the charset matters and not just the length.
|
|
250
|
-
*/
|
|
251
|
-
var CURRENCY_CODE = string().regex(/^[A-Za-z]{3}$/, "must be a three-letter ISO 4217 currency code");
|
|
252
|
-
/**
|
|
253
276
|
* One product/curation card. `priceMinor` is the ISO 4217 minor-unit integer
|
|
254
277
|
* (cents, paise, …) — never a float — and `currency` is the ISO 4217 code, so
|
|
255
278
|
* the widget formats price itself rather than trusting a pre-formatted
|
|
@@ -309,14 +332,113 @@ var WidgetChatTextDeltaEventSchema = object({
|
|
|
309
332
|
type: literal("text-delta"),
|
|
310
333
|
delta: string()
|
|
311
334
|
});
|
|
312
|
-
/**
|
|
335
|
+
/**
|
|
336
|
+
* Max cards in one event — a chat bubble, not a catalog page.
|
|
337
|
+
*
|
|
338
|
+
* Exported so `build_curation` (`apps/api/src/catalog/tools/build-curation.tool.ts`)
|
|
339
|
+
* can cap what it renders BEFORE persisting, rather than building an
|
|
340
|
+
* oversized array and finding out only when this schema (or
|
|
341
|
+
* {@link buildWidgetChatCardsEvent}'s own cap, for replay) refuses it. A
|
|
342
|
+
* second, hand-typed `20` here would be exactly the kind of drift this
|
|
343
|
+
* package exists to prevent.
|
|
344
|
+
*/
|
|
313
345
|
var MAX_CARDS_PER_EVENT = 20;
|
|
314
346
|
var WidgetChatCardsEventSchema = object({
|
|
315
347
|
type: literal("cards"),
|
|
316
348
|
/** Correlates this render back to whichever tool call produced it, when the tool supplies one. */
|
|
317
349
|
curationId: string().min(1).max(ID_MAX).optional(),
|
|
318
|
-
items: array(WidgetChatCardSchema).min(1).max(
|
|
350
|
+
items: array(WidgetChatCardSchema).min(1).max(20)
|
|
319
351
|
});
|
|
352
|
+
/**
|
|
353
|
+
* The optional {@link WidgetChatCard} fields a validation failure may drop
|
|
354
|
+
* WITHOUT losing the card — a card missing its image or its PDP handle is
|
|
355
|
+
* still a usable recommendation. `title`/`currency`/`priceMinor`/`productId`/
|
|
356
|
+
* `available` stay OUT of this list on purpose: there is no honest way to
|
|
357
|
+
* show a product with no price, or a price with no currency, so a failure in
|
|
358
|
+
* one of those drops the whole card instead (see {@link buildWidgetChatCard}).
|
|
359
|
+
*/
|
|
360
|
+
var DROPPABLE_CARD_FIELDS = [
|
|
361
|
+
"variantId",
|
|
362
|
+
"platformVariantId",
|
|
363
|
+
"imageUrl",
|
|
364
|
+
"handle",
|
|
365
|
+
"reason"
|
|
366
|
+
];
|
|
367
|
+
/**
|
|
368
|
+
* Generic "try the whole candidate; if every refusal is on a DROPPABLE field,
|
|
369
|
+
* drop just those and retry once" parser — no card-specific knowledge at all.
|
|
370
|
+
*
|
|
371
|
+
* Exported so `apps/api`'s `act-destinations.ts` `buildActEvent`
|
|
372
|
+
* (`apply_filter`/`spotlight`/`navigate`'s events) can DELEGATE to this
|
|
373
|
+
* instead of keeping its own copy of the identical safeParse/prune/retry
|
|
374
|
+
* algorithm. The dependency has to run this direction — this package cannot
|
|
375
|
+
* import from `apps/api`, which depends on it — so this generic form lives
|
|
376
|
+
* here and `buildActEvent` becomes a thin wrapper around it. One
|
|
377
|
+
* implementation, called from both sides, rather than two that can drift on
|
|
378
|
+
* the next edit to either.
|
|
379
|
+
*/
|
|
380
|
+
function buildWithDroppableFields(schema, candidate, droppable = []) {
|
|
381
|
+
const first = schema.safeParse(candidate);
|
|
382
|
+
if (first.success) return first.data;
|
|
383
|
+
const offending = new Set(first.error.issues.map((issue) => String(issue.path[0] ?? "")));
|
|
384
|
+
const pruned = { ...candidate };
|
|
385
|
+
let droppedAny = false;
|
|
386
|
+
for (const key of droppable) {
|
|
387
|
+
if (!offending.has(key)) continue;
|
|
388
|
+
delete pruned[key];
|
|
389
|
+
droppedAny = true;
|
|
390
|
+
}
|
|
391
|
+
if (!droppedAny) return null;
|
|
392
|
+
const second = schema.safeParse(pruned);
|
|
393
|
+
return second.success ? second.data : null;
|
|
394
|
+
}
|
|
395
|
+
/**
|
|
396
|
+
* Build ONE validated {@link WidgetChatCard} from a raw candidate record, or
|
|
397
|
+
* `null` when it cannot be rendered as a card at all.
|
|
398
|
+
*
|
|
399
|
+
* Tries the candidate whole first; if every refusal is on a
|
|
400
|
+
* {@link DROPPABLE_CARD_FIELDS} field, drops JUST those fields and retries
|
|
401
|
+
* once. A REQUIRED field failing has no fallback, so this returns `null` and
|
|
402
|
+
* the caller drops the whole candidate.
|
|
403
|
+
*
|
|
404
|
+
* ## Why this lives here, callable by both the live and the replay leg
|
|
405
|
+
*
|
|
406
|
+
* `build_curation` (`apps/api/src/catalog/tools/build-curation.tool.ts`, the
|
|
407
|
+
* live SSE leg) and {@link buildWidgetChatCardsEvent} (the replay leg, for a
|
|
408
|
+
* resumed session) each turn catalogue data into cards, and a catalogue row
|
|
409
|
+
* with one malformed optional field — an image URL on an underscore host, an
|
|
410
|
+
* IP-address image host, a unicode handle — is exactly as malformed whichever
|
|
411
|
+
* leg reads it. Before this function existed, only the live leg had this
|
|
412
|
+
* drop-the-field-not-the-card contract (via `apps/api`'s own `buildActEvent`);
|
|
413
|
+
* replay did a single `safeParse` with no retry and dropped the WHOLE card
|
|
414
|
+
* for a field the live leg could shrug off. A shopper who reloaded
|
|
415
|
+
* mid-conversation saw fewer cards than the turn had actually streamed. Both
|
|
416
|
+
* legs now call this one function, so the SAME product produces the SAME
|
|
417
|
+
* card — field dropped, not card dropped — regardless of which leg built it.
|
|
418
|
+
*
|
|
419
|
+
* ## An empty/whitespace-only string on a DROPPABLE field is normalized to
|
|
420
|
+
* absent, BEFORE either leg's candidate ever reaches {@link WidgetChatCardSchema}
|
|
421
|
+
*
|
|
422
|
+
* Live and replay build their OWN candidate record from different source
|
|
423
|
+
* shapes and, independently, made different choices about what "no reason"
|
|
424
|
+
* looks like: one omits an empty `reason` (a truthiness check), the other
|
|
425
|
+
* keeps it as `reason: ''` (a not-null check) — and {@link WidgetChatCardSchema}'s
|
|
426
|
+
* `reason` has no `.min(1)`, so `''` parses cleanly on either side, meaning
|
|
427
|
+
* neither call site's own guard was ever exercised by the schema and the two
|
|
428
|
+
* legs rendered DIFFERENT cards for the identical row (one with no `reason`
|
|
429
|
+
* key, one with `reason: ''`). Normalizing here — in the ONE function both
|
|
430
|
+
* legs call, rather than requiring every call site to independently agree on
|
|
431
|
+
* a null convention — is what actually closes that gap, for `reason` and for
|
|
432
|
+
* any other droppable string field a future caller adds the same way.
|
|
433
|
+
*/
|
|
434
|
+
function buildWidgetChatCard(candidate) {
|
|
435
|
+
const normalized = { ...candidate };
|
|
436
|
+
for (const key of DROPPABLE_CARD_FIELDS) {
|
|
437
|
+
const value = normalized[key];
|
|
438
|
+
if (typeof value === "string" && value.trim() === "") delete normalized[key];
|
|
439
|
+
}
|
|
440
|
+
return buildWithDroppableFields(WidgetChatCardSchema, normalized, DROPPABLE_CARD_FIELDS);
|
|
441
|
+
}
|
|
320
442
|
var WidgetChatEscalatedEventSchema = object({ type: literal("escalated") });
|
|
321
443
|
/**
|
|
322
444
|
* A real Shopify checkout handoff — `checkout_handoff` (the concierge tool)
|
|
@@ -549,15 +671,20 @@ function extractWidgetToolEvent(output) {
|
|
|
549
671
|
/**
|
|
550
672
|
* Rebuild the `cards` event a curation was streamed as, for replay.
|
|
551
673
|
*
|
|
552
|
-
* **Per-item
|
|
553
|
-
* live: between the turn that curated a product and the
|
|
554
|
-
* it, the product can lose its price (a variant
|
|
555
|
-
* the scheme allowlist refuses, or have its
|
|
556
|
-
* {@link WidgetChatCardSchema}'s slug regex
|
|
557
|
-
* whole array at once would make ONE such row
|
|
558
|
-
* that turn; parsing per item drops only the
|
|
559
|
-
*
|
|
560
|
-
*
|
|
674
|
+
* **Per-item {@link buildWidgetChatCard}, not one parse of the whole array.**
|
|
675
|
+
* A catalogue is live: between the turn that curated a product and the
|
|
676
|
+
* reload that replays it, the product can lose its price (a variant
|
|
677
|
+
* deleted), gain an image URL the scheme allowlist refuses, or have its
|
|
678
|
+
* handle rewritten into something {@link WidgetChatCardSchema}'s slug regex
|
|
679
|
+
* will not accept. Parsing the whole array at once would make ONE such row
|
|
680
|
+
* cost the shopper every card in that turn; parsing per item drops only the
|
|
681
|
+
* row that no longer renders — and, for a droppable field, drops only the
|
|
682
|
+
* FIELD, via {@link buildWidgetChatCard}, the exact "degrade, never
|
|
683
|
+
* fabricate" contract the live leg (`build_curation`) applies to the same
|
|
684
|
+
* data. Before this called the shared builder, a per-item `safeParse` with no
|
|
685
|
+
* retry meant a droppable field's failure still cost the whole card here —
|
|
686
|
+
* so a product with, say, an image URL on an underscore host rendered on
|
|
687
|
+
* reload with one card fewer than the live turn had actually streamed.
|
|
561
688
|
*
|
|
562
689
|
* **Filter first, then cap.** The `MAX_CARDS_PER_EVENT` cap used to be taken
|
|
563
690
|
* as `items.slice(0, MAX)` BEFORE the drops below, so twenty rows that no
|
|
@@ -577,7 +704,7 @@ function buildWidgetChatCardsEvent(curationId, items) {
|
|
|
577
704
|
for (const item of items) {
|
|
578
705
|
if (item.priceMinor === null || item.currency === null) continue;
|
|
579
706
|
if (item.available !== true) continue;
|
|
580
|
-
const
|
|
707
|
+
const card = buildWidgetChatCard({
|
|
581
708
|
productId: item.productId,
|
|
582
709
|
...item.variantId !== null ? { variantId: item.variantId } : {},
|
|
583
710
|
...item.platformVariantId !== null ? { platformVariantId: item.platformVariantId } : {},
|
|
@@ -589,13 +716,13 @@ function buildWidgetChatCardsEvent(curationId, items) {
|
|
|
589
716
|
available: true,
|
|
590
717
|
...item.reason !== null ? { reason: item.reason } : {}
|
|
591
718
|
});
|
|
592
|
-
if (
|
|
719
|
+
if (card !== null) cards.push(card);
|
|
593
720
|
}
|
|
594
721
|
if (cards.length === 0) return null;
|
|
595
722
|
return {
|
|
596
723
|
type: "cards",
|
|
597
724
|
curationId,
|
|
598
|
-
items: cards.slice(0,
|
|
725
|
+
items: cards.slice(0, 20)
|
|
599
726
|
};
|
|
600
727
|
}
|
|
601
728
|
/**
|
|
@@ -774,4 +901,4 @@ function parseWidgetChatCart(value) {
|
|
|
774
901
|
return parsed.success ? parsed.data : null;
|
|
775
902
|
}
|
|
776
903
|
//#endregion
|
|
777
|
-
export { MAX_CART_LINES, WidgetCartAddFailedReportSchema, WidgetCartAddReportSchema, WidgetChatAddToCartEventSchema, WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCartLineSchema, WidgetChatCartSchema, WidgetChatCartSourceSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatReportSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetToolEventSchema, buildWidgetChatCardsEvent, extractWidgetToolEvent, parseWidgetChatCart, parseWidgetChatReport };
|
|
904
|
+
export { DROPPABLE_CARD_FIELDS, MAX_CARDS_PER_EVENT, MAX_CART_LINES, WidgetCartAddFailedReportSchema, WidgetCartAddReportSchema, WidgetChatAddToCartEventSchema, WidgetChatCardSchema, WidgetChatCardsEventSchema, WidgetChatCartLineSchema, WidgetChatCartSchema, WidgetChatCartSourceSchema, WidgetChatCheckoutEventSchema, WidgetChatDoneEventSchema, WidgetChatErrorEventSchema, WidgetChatEscalatedEventSchema, WidgetChatReportSchema, WidgetChatSseEventSchema, WidgetChatTextDeltaEventSchema, WidgetToolEventSchema, buildWidgetChatCard, buildWidgetChatCardsEvent, buildWithDroppableFields, extractWidgetToolEvent, parseWidgetChatCart, parseWidgetChatReport };
|
|
@@ -7013,7 +7013,7 @@ function speakerFor(role) {
|
|
|
7013
7013
|
return role === "user" ? "caller" : "agent";
|
|
7014
7014
|
}
|
|
7015
7015
|
function useChatSession(options) {
|
|
7016
|
-
const { embedKey, attribution, apiBase = DEFAULT_API_BASE, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, idlePollIntervalMs = DEFAULT_IDLE_POLL_INTERVAL_MS, socketUrl, socketPath = DEFAULT_SOCKET_PATH, collector } = options;
|
|
7016
|
+
const { embedKey, attribution, apiBase = DEFAULT_API_BASE, pollIntervalMs = DEFAULT_POLL_INTERVAL_MS, idlePollIntervalMs = DEFAULT_IDLE_POLL_INTERVAL_MS, socketUrl, socketPath = DEFAULT_SOCKET_PATH, collector, hostRoutes } = options;
|
|
7017
7017
|
const fetchImpl = options.fetchImpl ?? fetch;
|
|
7018
7018
|
const socketFactory = options.socketImpl;
|
|
7019
7019
|
const now = useMemo(() => options.now ?? (() => Date.now()), []);
|
|
@@ -7445,7 +7445,8 @@ function useChatSession(options) {
|
|
|
7445
7445
|
embedKey,
|
|
7446
7446
|
attribution,
|
|
7447
7447
|
...stored.visitorId ? { visitorId: stored.visitorId } : {},
|
|
7448
|
-
...stored.visitorProof ? { visitorProof: stored.visitorProof } : {}
|
|
7448
|
+
...stored.visitorProof ? { visitorProof: stored.visitorProof } : {},
|
|
7449
|
+
...hostRoutes !== void 0 ? { hostRoutes } : {}
|
|
7449
7450
|
})
|
|
7450
7451
|
});
|
|
7451
7452
|
if (!res.ok) throw new Error(`Session boot failed (${res.status}).`);
|
|
@@ -7537,6 +7538,7 @@ function useChatSession(options) {
|
|
|
7537
7538
|
collector,
|
|
7538
7539
|
embedKey,
|
|
7539
7540
|
fetchImpl,
|
|
7541
|
+
hostRoutes,
|
|
7540
7542
|
now,
|
|
7541
7543
|
poll,
|
|
7542
7544
|
scheduleRefresh
|
|
@@ -8468,7 +8470,7 @@ async function streamReply(args) {
|
|
|
8468
8470
|
* cache makes a second `start()` after `stop()` free).
|
|
8469
8471
|
*/
|
|
8470
8472
|
async function loadVoiceProtocol() {
|
|
8471
|
-
const [telemetry, chat] = await Promise.all([import("./telemetry-
|
|
8473
|
+
const [telemetry, chat] = await Promise.all([import("./telemetry-DQUulENJ.js"), import("./chat-DAgqVvIS.js")]);
|
|
8472
8474
|
return {
|
|
8473
8475
|
decodeTelemetry: telemetry.decodeTelemetry,
|
|
8474
8476
|
encodeCallerText: telemetry.encodeCallerText,
|
|
@@ -8979,7 +8981,7 @@ function useVoiceSession(options = {}) {
|
|
|
8979
8981
|
if (!message) return;
|
|
8980
8982
|
if (message.type === "turn.latency") {
|
|
8981
8983
|
setTurns((t) => [...t.filter((x) => x.turnId !== message.turnId), message].slice(-20));
|
|
8982
|
-
record("turn_latency", `${message.overallMs ?? "—"}ms overall`);
|
|
8984
|
+
record("turn_latency", `${message.overallMs ?? "—"}ms overall` + (typeof message.firstActMs === "number" ? `, act ${message.firstActMs}ms` : ""));
|
|
8983
8985
|
return;
|
|
8984
8986
|
}
|
|
8985
8987
|
if (message.type === "turn.cost") {
|
|
@@ -9588,6 +9590,117 @@ var PageContextTracker = class {
|
|
|
9588
9590
|
}
|
|
9589
9591
|
};
|
|
9590
9592
|
//#endregion
|
|
9593
|
+
//#region src/host-routes.ts
|
|
9594
|
+
/**
|
|
9595
|
+
* What to declare to the server on session boot, or `undefined` when this host
|
|
9596
|
+
* declares nothing (⇒ the field is omitted, and the server keeps its Shopify
|
|
9597
|
+
* assumption).
|
|
9598
|
+
*
|
|
9599
|
+
* `'url'` is never declared. That target exists so a model can name a
|
|
9600
|
+
* storefront path directly, and a host with a scheme of its own has no closed
|
|
9601
|
+
* route list the server could check such a path against — so on a declaring
|
|
9602
|
+
* host it is refused outright rather than allowed to become the one hole every
|
|
9603
|
+
* other narrowing here would leave.
|
|
9604
|
+
*
|
|
9605
|
+
* @param routes the resolvers, from {@link hostRouteResolvers}
|
|
9606
|
+
*/
|
|
9607
|
+
function hostRouteTargets(routes) {
|
|
9608
|
+
if (!routes) return void 0;
|
|
9609
|
+
return [
|
|
9610
|
+
...routes.product ? ["product"] : [],
|
|
9611
|
+
...routes.collection ? ["collection"] : [],
|
|
9612
|
+
...routes.search ? ["search"] : [],
|
|
9613
|
+
...routes.cart ? ["cart"] : []
|
|
9614
|
+
];
|
|
9615
|
+
}
|
|
9616
|
+
/** `/collections/rugs?filter.p.vendor=X#top` split into the three parts a rewrite needs. */
|
|
9617
|
+
function splitPath(path) {
|
|
9618
|
+
const withoutFragment = path.split("#")[0] ?? path;
|
|
9619
|
+
const split = withoutFragment.indexOf("?");
|
|
9620
|
+
return split === -1 ? {
|
|
9621
|
+
route: withoutFragment,
|
|
9622
|
+
query: ""
|
|
9623
|
+
} : {
|
|
9624
|
+
route: withoutFragment.slice(0, split),
|
|
9625
|
+
query: withoutFragment.slice(split + 1)
|
|
9626
|
+
};
|
|
9627
|
+
}
|
|
9628
|
+
/**
|
|
9629
|
+
* The handle in `/products/<handle>` or `/collections/<handle>`, or
|
|
9630
|
+
* `undefined`. Tolerates a trailing slash; rejects a deeper path, which is not
|
|
9631
|
+
* a route the server emits.
|
|
9632
|
+
*
|
|
9633
|
+
* The decode is GUARDED because it can genuinely throw and this module must
|
|
9634
|
+
* not: the server builds `/products/<handle>` from the merchant's own
|
|
9635
|
+
* catalogue handle without encoding it, and `SameOriginPathSchema` permits a
|
|
9636
|
+
* bare `%`, so a product handled `50%-off-rug` reaches here and
|
|
9637
|
+
* `decodeURIComponent` raises `URIError: URI malformed`. Nothing between this
|
|
9638
|
+
* and the act queue catches — the drain is `try`/`finally` with no `catch` —
|
|
9639
|
+
* so an unguarded throw would abandon every act still queued in that batch AND
|
|
9640
|
+
* skip the `navigate_failed` report, which is the one failure with no
|
|
9641
|
+
* correction path. `undefined` instead means "this is not a shape I can
|
|
9642
|
+
* rewrite", which the caller turns into a refusal the model can read.
|
|
9643
|
+
*/
|
|
9644
|
+
function handleAfter(route, prefix) {
|
|
9645
|
+
if (!route.startsWith(prefix)) return void 0;
|
|
9646
|
+
const rest = route.slice(prefix.length).replace(/\/$/, "");
|
|
9647
|
+
if (rest === "" || rest.includes("/")) return void 0;
|
|
9648
|
+
try {
|
|
9649
|
+
return decodeURIComponent(rest);
|
|
9650
|
+
} catch {
|
|
9651
|
+
return;
|
|
9652
|
+
}
|
|
9653
|
+
}
|
|
9654
|
+
/**
|
|
9655
|
+
* Rewrite a server-resolved destination into the path THIS host serves.
|
|
9656
|
+
*
|
|
9657
|
+
* Three answers, and the difference between the last two is the whole point:
|
|
9658
|
+
*
|
|
9659
|
+
* - the path itself — this host declared nothing, so the server's Shopify
|
|
9660
|
+
* spelling is the right one and nothing is rewritten;
|
|
9661
|
+
* - a rewritten path — the host declared this target and the destination
|
|
9662
|
+
* matched its shape;
|
|
9663
|
+
* - `null` — this host cannot serve the destination, so NOTHING should
|
|
9664
|
+
* happen. The caller reports a failed navigate rather than assigning a URL
|
|
9665
|
+
* the host will 404 (or, on the console, bounce to a login page).
|
|
9666
|
+
*
|
|
9667
|
+
* `null` for a declared target whose path does not match the expected shape is
|
|
9668
|
+
* deliberate rather than a fallthrough to the raw path: a `product` target
|
|
9669
|
+
* carrying something that is not `/products/<handle>` is a destination this
|
|
9670
|
+
* function does not understand, and passing an un-rewritten Shopify path to a
|
|
9671
|
+
* host that just told us it has no Shopify routes is precisely the defect.
|
|
9672
|
+
*
|
|
9673
|
+
* @param url the server-resolved, root-relative destination
|
|
9674
|
+
* @param target which kind of destination the server said it was
|
|
9675
|
+
* @param routes this host's declared scheme, or `undefined`
|
|
9676
|
+
*/
|
|
9677
|
+
function resolveHostRoutePath(url, target, routes) {
|
|
9678
|
+
if (!routes) return url;
|
|
9679
|
+
if (target === void 0 || target === "url") return null;
|
|
9680
|
+
if (target === "cart") return routes.cart ?? null;
|
|
9681
|
+
const { route, query } = splitPath(url);
|
|
9682
|
+
if (target === "search") {
|
|
9683
|
+
if (!routes.search) return null;
|
|
9684
|
+
let q;
|
|
9685
|
+
try {
|
|
9686
|
+
q = new URLSearchParams(query).get("q");
|
|
9687
|
+
} catch {
|
|
9688
|
+
q = null;
|
|
9689
|
+
}
|
|
9690
|
+
return q ? routes.search(q) : null;
|
|
9691
|
+
}
|
|
9692
|
+
const build = target === "product" ? routes.product : routes.collection;
|
|
9693
|
+
if (!build) return null;
|
|
9694
|
+
const handle = handleAfter(route, target === "product" ? "/products/" : "/collections/");
|
|
9695
|
+
if (handle === void 0) return null;
|
|
9696
|
+
const built = build(handle);
|
|
9697
|
+
if (query === "") return built;
|
|
9698
|
+
const hash = built.indexOf("#");
|
|
9699
|
+
const base = hash === -1 ? built : built.slice(0, hash);
|
|
9700
|
+
const fragment = hash === -1 ? "" : built.slice(hash);
|
|
9701
|
+
return `${base}${base.includes("?") ? "&" : "?"}${query}${fragment}`;
|
|
9702
|
+
}
|
|
9703
|
+
//#endregion
|
|
9591
9704
|
//#region src/turn-order.ts
|
|
9592
9705
|
/**
|
|
9593
9706
|
* The widget's arrival clock. One instance per mounted widget (`useRef`), fed
|
|
@@ -9716,6 +9829,21 @@ var TurnOrderClock = class {
|
|
|
9716
9829
|
*/
|
|
9717
9830
|
var NAVIGATE_BEAT_MS = 300;
|
|
9718
9831
|
/**
|
|
9832
|
+
* How often `performAct` re-checks whether the typed turn has landed.
|
|
9833
|
+
*
|
|
9834
|
+
* Short enough that it disappears inside the 300 ms beat that follows it.
|
|
9835
|
+
*/
|
|
9836
|
+
var ACT_HOLD_POLL_MS = 50;
|
|
9837
|
+
/**
|
|
9838
|
+
* The longest a page-moving act waits for a typed turn to finish streaming.
|
|
9839
|
+
*
|
|
9840
|
+
* A bound rather than a hope, for the same reason `ScheduledWidgetEventQueue`
|
|
9841
|
+
* caps what it holds: a stream that never settles — a dropped socket with no
|
|
9842
|
+
* error, a tab backgrounded mid-turn — must not strand a navigation the shopper
|
|
9843
|
+
* asked for. A late page change is recoverable; one that never comes is not.
|
|
9844
|
+
*/
|
|
9845
|
+
var ACT_HOLD_MAX_MS = 15e3;
|
|
9846
|
+
/**
|
|
9719
9847
|
* Is this widget event one the concierge wants PERFORMED on the host page?
|
|
9720
9848
|
*
|
|
9721
9849
|
* Hand-written rather than imported from `@saar-ai/widget-protocol`'s
|
|
@@ -10051,7 +10179,7 @@ function deriveCallPhase(voice) {
|
|
|
10051
10179
|
* about offering voice here costs a byte until a caller actually presses
|
|
10052
10180
|
* the microphone.
|
|
10053
10181
|
*/
|
|
10054
|
-
function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages = defaultWidgetMessages, locale = "en", productHref, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady }) {
|
|
10182
|
+
function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages = defaultWidgetMessages, locale = "en", productHref, hostRoutes, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady }) {
|
|
10055
10183
|
/**
|
|
10056
10184
|
* Maps the tenant's semantic config fields onto the widget's historical
|
|
10057
10185
|
* CSS custom properties — this is the "one becomes the other" site
|
|
@@ -10080,12 +10208,14 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10080
10208
|
brandSecondary,
|
|
10081
10209
|
brandAccent
|
|
10082
10210
|
]);
|
|
10211
|
+
const hostRouteDeclaration = useMemo(() => hostRouteTargets(hostRoutes), [hostRoutes]);
|
|
10083
10212
|
const session = useChatSession({
|
|
10084
10213
|
embedKey,
|
|
10085
10214
|
...apiBase !== void 0 ? { apiBase } : {},
|
|
10086
10215
|
...socketUrl !== void 0 ? { socketUrl } : {},
|
|
10087
10216
|
...socketPath !== void 0 ? { socketPath } : {},
|
|
10088
|
-
...collector ? { collector } : {}
|
|
10217
|
+
...collector ? { collector } : {},
|
|
10218
|
+
...hostRouteDeclaration ? { hostRoutes: hostRouteDeclaration } : {}
|
|
10089
10219
|
});
|
|
10090
10220
|
const chatToken = session.chatToken;
|
|
10091
10221
|
const canReachVoiceToken = apiBase !== void 0 && chatToken !== void 0;
|
|
@@ -10536,9 +10666,22 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10536
10666
|
*/
|
|
10537
10667
|
const inCallRef = useRef(inCall);
|
|
10538
10668
|
const actLiveRef = useRef(true);
|
|
10669
|
+
/**
|
|
10670
|
+
* Is a typed turn still streaming in?
|
|
10671
|
+
*
|
|
10672
|
+
* The typed leg's answer to the realtime tier's "is the agent still
|
|
10673
|
+
* speaking" — see `performAct`. A ref rather than a dependency because
|
|
10674
|
+
* `performAct` is read out of a ref by the drain loop and must see the
|
|
10675
|
+
* CURRENT value at the moment it runs, not the one captured when the act
|
|
10676
|
+
* was queued.
|
|
10677
|
+
*/
|
|
10678
|
+
const streamingRef = useRef(false);
|
|
10539
10679
|
useEffect(() => {
|
|
10540
10680
|
inCallRef.current = inCall;
|
|
10541
10681
|
}, [inCall]);
|
|
10682
|
+
useEffect(() => {
|
|
10683
|
+
streamingRef.current = session.status === "streaming";
|
|
10684
|
+
}, [session.status]);
|
|
10542
10685
|
useEffect(() => () => {
|
|
10543
10686
|
actLiveRef.current = false;
|
|
10544
10687
|
actQueueRef.current = [];
|
|
@@ -10644,7 +10787,16 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10644
10787
|
reportFailedNavigate(target);
|
|
10645
10788
|
return;
|
|
10646
10789
|
}
|
|
10647
|
-
const
|
|
10790
|
+
const routed = resolveHostRoutePath(url, target, hostRoutes);
|
|
10791
|
+
if (routed === null) {
|
|
10792
|
+
reportFailedNavigate(target);
|
|
10793
|
+
return;
|
|
10794
|
+
}
|
|
10795
|
+
const path = hostRoutes ? routed : withStorefrontLocale(storefrontLocalePrefix(bridgePath()), routed);
|
|
10796
|
+
if (!isSameOriginPath(path)) {
|
|
10797
|
+
reportFailedNavigate(target);
|
|
10798
|
+
return;
|
|
10799
|
+
}
|
|
10648
10800
|
if (!actLiveRef.current) return;
|
|
10649
10801
|
if (voiceEnabled) await notifyNavigating().catch(() => false);
|
|
10650
10802
|
if (!actLiveRef.current) return;
|
|
@@ -10656,6 +10808,7 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10656
10808
|
}, [
|
|
10657
10809
|
bridge,
|
|
10658
10810
|
bridgePath,
|
|
10811
|
+
hostRoutes,
|
|
10659
10812
|
voiceEnabled,
|
|
10660
10813
|
notifyNavigating,
|
|
10661
10814
|
reportFailedNavigate
|
|
@@ -10663,9 +10816,30 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10663
10816
|
/**
|
|
10664
10817
|
* Perform ONE act event. Never throws — every branch is a host-facing call.
|
|
10665
10818
|
*/
|
|
10819
|
+
/**
|
|
10820
|
+
* Block until the typed turn carrying this act has finished streaming.
|
|
10821
|
+
*
|
|
10822
|
+
* Polled rather than promised: the only signal is `session.status`, which is
|
|
10823
|
+
* React state, and a resolver registry keyed off it would be more machinery
|
|
10824
|
+
* than a 50 ms tick in a path that already waits 300 ms afterwards.
|
|
10825
|
+
*
|
|
10826
|
+
* BOUNDED, and the bound is the point. A stream that never settles — a socket
|
|
10827
|
+
* the network dropped without an error, a tab backgrounded mid-turn — must
|
|
10828
|
+
* not strand a navigation the shopper asked for forever; after
|
|
10829
|
+
* {@link ACT_HOLD_MAX_MS} the act goes anyway, because a late page change is
|
|
10830
|
+
* recoverable and a page change that never happens is not. It also stops at
|
|
10831
|
+
* unmount, so nothing assigns `location` after the widget is gone.
|
|
10832
|
+
*/
|
|
10833
|
+
const waitForTypedTurnToLand = useCallback(async () => {
|
|
10834
|
+
const deadline = Date.now() + ACT_HOLD_MAX_MS;
|
|
10835
|
+
while (streamingRef.current && actLiveRef.current && Date.now() < deadline) await new Promise((resolve) => setTimeout(resolve, ACT_HOLD_POLL_MS));
|
|
10836
|
+
}, []);
|
|
10666
10837
|
const performAct = useCallback(async (event) => {
|
|
10667
10838
|
if (event.type !== "spotlight") {
|
|
10668
|
-
if (!inCallRef.current)
|
|
10839
|
+
if (!inCallRef.current) {
|
|
10840
|
+
await waitForTypedTurnToLand();
|
|
10841
|
+
await new Promise((resolve) => setTimeout(resolve, NAVIGATE_BEAT_MS));
|
|
10842
|
+
}
|
|
10669
10843
|
if (!actLiveRef.current) return;
|
|
10670
10844
|
}
|
|
10671
10845
|
if (event.type === "navigate") {
|
|
@@ -10675,8 +10849,8 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10675
10849
|
if (event.type === "filter") {
|
|
10676
10850
|
if (event.collectionUrl !== void 0 && !isSameOriginPath(event.collectionUrl)) return;
|
|
10677
10851
|
const prefix = storefrontLocalePrefix(bridgePath());
|
|
10678
|
-
const collectionUrl = event.collectionUrl
|
|
10679
|
-
if (!(collectionUrl !== void 0 && !isSamePagePath(collectionUrl, bridgePath())) && bridge?.applyFilter) try {
|
|
10852
|
+
const collectionUrl = event.collectionUrl;
|
|
10853
|
+
if (!(collectionUrl !== void 0 && !isSamePagePath(withStorefrontLocale(prefix, collectionUrl), bridgePath())) && bridge?.applyFilter) try {
|
|
10680
10854
|
if (await bridge.applyFilter(event.filters) !== false) return;
|
|
10681
10855
|
} catch {}
|
|
10682
10856
|
if (collectionUrl !== void 0) await performNavigate(withStorefrontFacets(collectionUrl, event.filters), "collection");
|
|
@@ -10697,7 +10871,8 @@ function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, sit
|
|
|
10697
10871
|
bridgePath,
|
|
10698
10872
|
siteProfile,
|
|
10699
10873
|
performNavigate,
|
|
10700
|
-
reportFailedSpotlight
|
|
10874
|
+
reportFailedSpotlight,
|
|
10875
|
+
waitForTypedTurnToLand
|
|
10701
10876
|
]);
|
|
10702
10877
|
/**
|
|
10703
10878
|
* The acts the concierge asked for, from both legs, performed exactly once
|
|
@@ -173,6 +173,21 @@ var TurnLatencyPayloadSchema = object({
|
|
|
173
173
|
/** Caller stopped speaking → first audio they hear. The felt latency. */
|
|
174
174
|
overallMs: number().nullable(),
|
|
175
175
|
/**
|
|
176
|
+
* Caller stopped speaking → the first ACT that reached their screen: a card
|
|
177
|
+
* ringed, a page opened, a grid narrowed.
|
|
178
|
+
*
|
|
179
|
+
* Not a stage and not part of the sum — an eager act tool runs while the
|
|
180
|
+
* model is still dictating the rest of its sentence, so this can land before
|
|
181
|
+
* `overallMs` and that is the concierge acting while it talks. Above
|
|
182
|
+
* `overallMs` it is a navigation waiting for the clause to finish, which is
|
|
183
|
+
* equally correct. `null` is a turn that only spoke.
|
|
184
|
+
*
|
|
185
|
+
* OPTIONAL, and read defensively: a widget bundle older than this field is
|
|
186
|
+
* the ordinary case for the life of a storefront tab, and a worker older than
|
|
187
|
+
* it simply does not send one.
|
|
188
|
+
*/
|
|
189
|
+
firstActMs: number().nullable().optional(),
|
|
190
|
+
/**
|
|
176
191
|
* The turn tier began generating before the turn was confirmed, so most of
|
|
177
192
|
* `agentMs` hid under `eotMs` and the stages will not sum to `overallMs`.
|
|
178
193
|
*/
|
package/dist/dock/dock.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { type CSSProperties, type ReactNode } from 'react';
|
|
2
|
+
import type { CallerInterruptReason } from '@saar-ai/widget-protocol/telemetry';
|
|
3
|
+
import type { WidgetCopyField } from '@saar-ai/widget-protocol/copy-limits';
|
|
2
4
|
import { type WidgetImageAspect } from '../card-aspect.js';
|
|
3
5
|
import { type WidgetMessages } from '../messages.js';
|
|
4
6
|
import { type WidgetColorConfig, type WidgetTypeConfig } from '../theme/derive.js';
|
|
@@ -77,13 +79,32 @@ export interface DockLayoutView {
|
|
|
77
79
|
*/
|
|
78
80
|
readonly draggable?: boolean;
|
|
79
81
|
}
|
|
80
|
-
/**
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
82
|
+
/**
|
|
83
|
+
* The tenant's `copy[locale]` (§9.1), as the dock reads it.
|
|
84
|
+
*
|
|
85
|
+
* Field NAMES are derived from `@saar-ai/widget-protocol/copy-limits`'s
|
|
86
|
+
* `WidgetCopyField` here — this package's own four hand-typed lists collapse
|
|
87
|
+
* to one. `apps/api`'s `widgetCopySchema` (`apps/api/src/widget/dto/
|
|
88
|
+
* widget-config.type.ts`) and `apps/web`'s console
|
|
89
|
+
* (`components/widget-config/model.ts`'s `WidgetCopyDraft`) do NOT key off
|
|
90
|
+
* `WidgetCopyField` — corrected from an earlier version of this comment,
|
|
91
|
+
* which claimed they did: both are still their own hand-typed
|
|
92
|
+
* `z.object({greeting, placeholder, offlineMessage, minimisedLabel})`/
|
|
93
|
+
* interface, verified by reading each file directly. (`apps/api`'s
|
|
94
|
+
* `widget-config.types.ts` DOES re-export `WidgetCopyField` from this same
|
|
95
|
+
* package, at a different file from `widgetCopySchema` — that's what misled
|
|
96
|
+
* the earlier version of this comment.) A fifth and sixth copy of the same
|
|
97
|
+
* four names, left as they are: this package cannot import `widgetCopySchema`
|
|
98
|
+
* itself (a private `apps/api` zod schema; packages never depend on apps),
|
|
99
|
+
* so it uses `WidgetCopyField` — the zod-free, dependency-free piece of that
|
|
100
|
+
* contract that already lives in a package for exactly this reason (see that
|
|
101
|
+
* module's own doc comment) — as the closest canonical source it CAN reach,
|
|
102
|
+
* not as evidence the other two sites are derived from anything.
|
|
103
|
+
* All four stay optional here, unlike the console's `WidgetCopyDraft` (whose
|
|
104
|
+
* `''` empty-string default is form state, not wire shape) — an unauthored
|
|
105
|
+
* field is simply absent on this side.
|
|
106
|
+
*/
|
|
107
|
+
export type DockCopyView = Readonly<Partial<Record<WidgetCopyField, string>>>;
|
|
87
108
|
/** The voice leg, as the dock drives it. Absent ⇒ no microphone is ever drawn. */
|
|
88
109
|
export interface DockVoiceProps {
|
|
89
110
|
/** The tenant published voice AND this is not an embedded webview (§8.4). */
|
|
@@ -125,8 +146,20 @@ export interface DockVoiceProps {
|
|
|
125
146
|
* The names are `@saar-ai/widget-protocol/telemetry`'s
|
|
126
147
|
* `CALLER_INTERRUPT_REASONS`, which is what reaches the worker and what an
|
|
127
148
|
* operator's console reads back; they are not this component's to invent.
|
|
149
|
+
*
|
|
150
|
+
* `Exclude<CallerInterruptReason, 'keyboard'>`, not the full three-value
|
|
151
|
+
* type, and deliberately: the dock itself only ever calls this for its own
|
|
152
|
+
* two native gestures, the duck (`'look'`, above) and the interrupt
|
|
153
|
+
* control/row tap (`'tap'`, `onControl`'s `'interrupt'` case below).
|
|
154
|
+
* `'keyboard'` — "switched to text mid-reply" — would have to be fired from
|
|
155
|
+
* wherever a typed turn is actually SUBMITTED, which is outside this
|
|
156
|
+
* component (`onSubmit`, wired up by whatever renders the dock); nothing in
|
|
157
|
+
* this package calls it today. Narrowing here keeps the callback's declared
|
|
158
|
+
* surface honest about what THIS component emits — widening back to the
|
|
159
|
+
* full union is one edit away, the same day something upstream of
|
|
160
|
+
* `onSubmit` actually wires a keyboard interrupt through it.
|
|
128
161
|
*/
|
|
129
|
-
readonly onInterrupt?: (reason:
|
|
162
|
+
readonly onInterrupt?: (reason: Exclude<CallerInterruptReason, 'keyboard'>) => void;
|
|
130
163
|
/**
|
|
131
164
|
* §5.1 — the duck is over: the shopper spoke, or tapped the microphone.
|
|
132
165
|
* Never a timer.
|
package/dist/dock/dock.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dock.d.ts","sourceRoot":"","sources":["../../src/dock/dock.tsx"],"names":[],"mappings":"AAEA,OAAO,EASL,KAAK,aAAa,EAClB,KAAK,SAAS,EAEf,MAAM,OAAO,CAAC;AAEf,OAAO,EAAwC,KAAK,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAQjG,OAAO,EAAwC,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAGL,KAAK,iBAAiB,EACtB,KAAK,gBAAgB,EACtB,MAAM,oBAAoB,CAAC;AAC5B,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,wBAAwB,CAAC;AACxD,OAAO,EAYL,KAAK,YAAY,EACjB,KAAK,YAAY,EACjB,KAAK,SAAS,EACf,MAAM,eAAe,CAAC;AACvB,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAYhD,OAAO,EAAW,KAAK,gBAAgB,EAAsB,MAAM,eAAe,CAAC;AAWnF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,WAAW,iBAAiB;IAChC,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;IACtB,QAAQ,C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,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,0FAA0F;IAC1F,QAAQ,CAAC,WAAW,CAAC,EAAE,iBAAiB,CAAC;IAEzC,4EAA4E;IAC5E,QAAQ,CAAC,YAAY,CAAC,EAAE,MAAM,CAAC;IAC/B,QAAQ,CAAC,gBAAgB,CAAC,EAAE;QAAE,KAAK,EAAE,MAAM,CAAC;QAAC,GAAG,EAAE,MAAM,CAAA;KAAE,CAAC;IAC3D,QAAQ,CAAC,YAAY,CAAC,EAAE,UAAU,GAAG,KAAK,GAAG,IAAI,CAAC;IAClD,QAAQ,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,YAAY,CAAA;KAAE,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B;AAUD,qEAAqE;AACrE,eAAO,MAAM,qBAAqB,IAAI,CAAC;AACvC,eAAO,MAAM,0BAA0B,4BAA4B,CAAC;AAEpE,wBAAgB,IAAI,CAAC,KAAK,EAAE,SAAS,+BA89CpC;AAuMD,OAAO,EAAE,WAAW,EAAE,CAAC"}
|
|
@@ -0,0 +1,187 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HOST ROUTES — the merchant's own URL scheme, and the two things the widget
|
|
3
|
+
* does with it.
|
|
4
|
+
*
|
|
5
|
+
* ## The defect
|
|
6
|
+
*
|
|
7
|
+
* `navigate` (`apps/api/src/catalog/tools/navigate.tool.ts`) resolves every
|
|
8
|
+
* destination against the catalogue and spells the result the way a SHOPIFY
|
|
9
|
+
* storefront spells it: `/products/<handle>`, `/collections/<handle>`,
|
|
10
|
+
* `/search?q=`, `/cart`. That is right for the only production bridge and
|
|
11
|
+
* wrong for any host with a scheme of its own. The console's own demo store is
|
|
12
|
+
* the worked example: "take me to the rugs collection" produced
|
|
13
|
+
* `/collections/carpets`, the widget applied it on the console's origin, no
|
|
14
|
+
* such route exists there, and the console's auth gate turned the navigation
|
|
15
|
+
* into `/login?next=/`. Every collection navigation ejected the shopper.
|
|
16
|
+
*
|
|
17
|
+
* ## Two halves, and both are needed
|
|
18
|
+
*
|
|
19
|
+
* 1. **Rewrite** — {@link resolveHostRoutePath} turns the canonical path the
|
|
20
|
+
* server resolved into the path THIS host serves, using the templates the
|
|
21
|
+
* embed declared (`data-collection-url-template` and friends). A host that
|
|
22
|
+
* declared nothing is untouched, which is what keeps every Shopify
|
|
23
|
+
* storefront byte-identical.
|
|
24
|
+
* 2. **Declare** — {@link hostRouteTargets} turns the same templates into the
|
|
25
|
+
* capability list the widget sends on session boot, so the server can
|
|
26
|
+
* REFUSE a target this host cannot serve instead of emitting a path that
|
|
27
|
+
* ends in a 404. Without this half the concierge still says "taking you to
|
|
28
|
+
* the cushions" and then nothing happens; without the first half the
|
|
29
|
+
* declaration would be a promise the widget could not keep.
|
|
30
|
+
*
|
|
31
|
+
* The two are derived from ONE object for exactly that reason — a host that
|
|
32
|
+
* declares `collection` and cannot build a collection path, or builds one it
|
|
33
|
+
* never declared, is the bug this module's shape makes unrepresentable.
|
|
34
|
+
*
|
|
35
|
+
* ## Root-relative only, for NAVIGATION
|
|
36
|
+
*
|
|
37
|
+
* `buildProductHref` (`./cdn/core.ts`) accepts an absolute `https://` template
|
|
38
|
+
* because a product CARD may legitimately link to another origin. A navigation
|
|
39
|
+
* may not: `@saar-ai/widget-protocol`'s `SameOriginPathSchema` makes every
|
|
40
|
+
* server-resolved destination structurally same-origin, and a host template
|
|
41
|
+
* that re-opened that door would undo it at the last step. So
|
|
42
|
+
* {@link hostRouteResolvers} builds navigation hrefs with
|
|
43
|
+
* `allowAbsoluteHttps: false`, and a host whose product template is absolute
|
|
44
|
+
* simply does not declare `product` — its cards still link out, and the
|
|
45
|
+
* concierge declines to drive.
|
|
46
|
+
*/
|
|
47
|
+
/**
|
|
48
|
+
* Backslash, every ASCII C0 control (0x00–0x1F — which includes tab, LF and
|
|
49
|
+
* CR), and space (0x20), as one ascending range plus the backslash.
|
|
50
|
+
*
|
|
51
|
+
* Both bypasses this closes are properties of the WHATWG URL parser rather
|
|
52
|
+
* than of any check below it, which is why they are rejected on the raw
|
|
53
|
+
* template before any prefix test runs:
|
|
54
|
+
*
|
|
55
|
+
* - **backslash** — the spec treats `\` exactly like `/` when scanning a
|
|
56
|
+
* special scheme's authority, so `/\evil.com/{handle}` starts with `/`,
|
|
57
|
+
* fails a `startsWith('//')` test, and parses identically to
|
|
58
|
+
* `//evil.com/{handle}`.
|
|
59
|
+
* - **tab/newline/CR** — the same spec STRIPS every ASCII tab and newline
|
|
60
|
+
* before parsing at all, so `/<TAB>/evil.com/{handle}` also starts with
|
|
61
|
+
* `/`, contains no backslash, and becomes protocol-relative once the
|
|
62
|
+
* browser is done with it. A raw space goes for the same class of reason.
|
|
63
|
+
*
|
|
64
|
+
* `eslint-disable-next-line no-control-regex` — the control range is the
|
|
65
|
+
* entire point of this pattern, not an accidental literal.
|
|
66
|
+
*/
|
|
67
|
+
export declare const UNSAFE_TEMPLATE_CHARS: RegExp;
|
|
68
|
+
/**
|
|
69
|
+
* Turn a merchant-declared URL template into a one-argument href builder, or
|
|
70
|
+
* `undefined` when the template is not safe to use. Never throws — a malformed
|
|
71
|
+
* or hostile template degrades to "this host declares no such route" rather
|
|
72
|
+
* than reaching a `location.assign` unvalidated.
|
|
73
|
+
*
|
|
74
|
+
* Four rules, all required:
|
|
75
|
+
*
|
|
76
|
+
* - **carries the literal placeholder.** A template with nothing to
|
|
77
|
+
* substitute is not a per-entity template at all (probably a typo'd
|
|
78
|
+
* attribute), and building hrefs that all point at the same URL is worse
|
|
79
|
+
* than building none.
|
|
80
|
+
* - **contains none of {@link UNSAFE_TEMPLATE_CHARS}**, ahead of the prefix
|
|
81
|
+
* check so a hostile template never reaches it.
|
|
82
|
+
* - **starts with `/` and is not protocol-relative** — or, when
|
|
83
|
+
* `allowAbsoluteHttps`, with `https://`. This is the one thing standing
|
|
84
|
+
* between a merchant-configured attribute and a URL a shopper's browser
|
|
85
|
+
* will follow: `javascript:` executes script, `data:` can spoof a page, and
|
|
86
|
+
* a bare `//evil.com/{handle}` silently sends the shopper to another
|
|
87
|
+
* origin.
|
|
88
|
+
* - **the substituted value is `encodeURIComponent`-ed**, so a handle or a
|
|
89
|
+
* search query containing `/`, `?`, `#` or `&` cannot smuggle extra path
|
|
90
|
+
* segments or query parameters into the built href.
|
|
91
|
+
*
|
|
92
|
+
* @param template the merchant's template, verbatim from the embed attribute
|
|
93
|
+
* @param placeholder the literal token to substitute (`{handle}`, `{query}`)
|
|
94
|
+
* @param allowAbsoluteHttps whether an `https://…` template is acceptable —
|
|
95
|
+
* true for a card link, false for a navigation (see the module doc comment)
|
|
96
|
+
*/
|
|
97
|
+
export declare function buildTemplateHref(template: string, placeholder: string, allowAbsoluteHttps: boolean): ((value: string) => string) | undefined;
|
|
98
|
+
/**
|
|
99
|
+
* The scheme half of {@link buildTemplateHref}'s rules, on its own — for the
|
|
100
|
+
* one declared route that substitutes nothing (the cart page). Exported so
|
|
101
|
+
* "is this merchant-supplied path safe to send a browser to" has exactly one
|
|
102
|
+
* spelling, rather than a second, subtly different copy for the placeholder-
|
|
103
|
+
* less case.
|
|
104
|
+
*
|
|
105
|
+
* @param template the merchant-supplied template or path
|
|
106
|
+
* @param allowAbsoluteHttps whether an `https://…` value is acceptable
|
|
107
|
+
*/
|
|
108
|
+
export declare function isSafeHrefTemplate(template: string, allowAbsoluteHttps: boolean): boolean;
|
|
109
|
+
/**
|
|
110
|
+
* The merchant's declared URL scheme, as builders. Every member optional: a
|
|
111
|
+
* host declares what it has, and an absent member is a target the concierge
|
|
112
|
+
* will be told it cannot reach.
|
|
113
|
+
*/
|
|
114
|
+
export interface HostRouteResolvers {
|
|
115
|
+
/** `/shop/p/{handle}` → a builder taking a product handle. */
|
|
116
|
+
readonly product?: (handle: string) => string;
|
|
117
|
+
/** `/shop/c/{handle}` → a builder taking a collection handle. */
|
|
118
|
+
readonly collection?: (handle: string) => string;
|
|
119
|
+
/** `/shop/search?query={query}` → a builder taking the shopper's own text. */
|
|
120
|
+
readonly search?: (query: string) => string;
|
|
121
|
+
/** The host's cart PAGE, as a root-relative path. A cart drawer is not a page and must not be declared. */
|
|
122
|
+
readonly cart?: string;
|
|
123
|
+
}
|
|
124
|
+
/** The embed's raw declaration — every field exactly as it came off the `<script>` tag, unvalidated. */
|
|
125
|
+
export interface HostRouteTemplates {
|
|
126
|
+
readonly product?: string | null;
|
|
127
|
+
readonly collection?: string | null;
|
|
128
|
+
readonly search?: string | null;
|
|
129
|
+
readonly cart?: string | null;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Build the resolvers from the raw embed attributes, or `undefined` when this
|
|
133
|
+
* host is not declaring a scheme at all.
|
|
134
|
+
*
|
|
135
|
+
* **What counts as declaring is deliberately narrow**: any of `collection`,
|
|
136
|
+
* `search` or `cart`. `product` alone does NOT, because
|
|
137
|
+
* `data-product-url-template` predates this feature by many releases and means
|
|
138
|
+
* "link my cards" — a merchant who set only that one has said nothing about
|
|
139
|
+
* navigation, and reading it as a narrowing would silently stop their
|
|
140
|
+
* concierge from navigating anywhere. The demo store sets a collection
|
|
141
|
+
* template, so it declares; a Shopify storefront sets none of the three, so it
|
|
142
|
+
* does not, and nothing about it changes.
|
|
143
|
+
*
|
|
144
|
+
* @param templates the raw attribute values
|
|
145
|
+
*/
|
|
146
|
+
export declare function hostRouteResolvers(templates: HostRouteTemplates): HostRouteResolvers | undefined;
|
|
147
|
+
/** The navigation targets, in the vocabulary `@saar-ai/widget-protocol`'s `HostRoutes` uses. Spelt as literals, so `ui`/`core` never pull the zod-backed protocol module in for a string. */
|
|
148
|
+
export type HostRouteTarget = 'product' | 'collection' | 'search' | 'cart' | 'url';
|
|
149
|
+
/**
|
|
150
|
+
* What to declare to the server on session boot, or `undefined` when this host
|
|
151
|
+
* declares nothing (⇒ the field is omitted, and the server keeps its Shopify
|
|
152
|
+
* assumption).
|
|
153
|
+
*
|
|
154
|
+
* `'url'` is never declared. That target exists so a model can name a
|
|
155
|
+
* storefront path directly, and a host with a scheme of its own has no closed
|
|
156
|
+
* route list the server could check such a path against — so on a declaring
|
|
157
|
+
* host it is refused outright rather than allowed to become the one hole every
|
|
158
|
+
* other narrowing here would leave.
|
|
159
|
+
*
|
|
160
|
+
* @param routes the resolvers, from {@link hostRouteResolvers}
|
|
161
|
+
*/
|
|
162
|
+
export declare function hostRouteTargets(routes: HostRouteResolvers | undefined): readonly HostRouteTarget[] | undefined;
|
|
163
|
+
/**
|
|
164
|
+
* Rewrite a server-resolved destination into the path THIS host serves.
|
|
165
|
+
*
|
|
166
|
+
* Three answers, and the difference between the last two is the whole point:
|
|
167
|
+
*
|
|
168
|
+
* - the path itself — this host declared nothing, so the server's Shopify
|
|
169
|
+
* spelling is the right one and nothing is rewritten;
|
|
170
|
+
* - a rewritten path — the host declared this target and the destination
|
|
171
|
+
* matched its shape;
|
|
172
|
+
* - `null` — this host cannot serve the destination, so NOTHING should
|
|
173
|
+
* happen. The caller reports a failed navigate rather than assigning a URL
|
|
174
|
+
* the host will 404 (or, on the console, bounce to a login page).
|
|
175
|
+
*
|
|
176
|
+
* `null` for a declared target whose path does not match the expected shape is
|
|
177
|
+
* deliberate rather than a fallthrough to the raw path: a `product` target
|
|
178
|
+
* carrying something that is not `/products/<handle>` is a destination this
|
|
179
|
+
* function does not understand, and passing an un-rewritten Shopify path to a
|
|
180
|
+
* host that just told us it has no Shopify routes is precisely the defect.
|
|
181
|
+
*
|
|
182
|
+
* @param url the server-resolved, root-relative destination
|
|
183
|
+
* @param target which kind of destination the server said it was
|
|
184
|
+
* @param routes this host's declared scheme, or `undefined`
|
|
185
|
+
*/
|
|
186
|
+
export declare function resolveHostRoutePath(url: string, target: HostRouteTarget | undefined, routes: HostRouteResolvers | undefined): string | null;
|
|
187
|
+
//# sourceMappingURL=host-routes.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"host-routes.d.ts","sourceRoot":"","sources":["../src/host-routes.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA6CG;AAEH;;;;;;;;;;;;;;;;;;;GAmBG;AAEH,eAAO,MAAM,qBAAqB,QAAkB,CAAC;AAErD;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4BG;AACH,wBAAgB,iBAAiB,CAC/B,QAAQ,EAAE,MAAM,EAChB,WAAW,EAAE,MAAM,EACnB,kBAAkB,EAAE,OAAO,GAC1B,CAAC,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC,GAAG,SAAS,CAIzC;AAED;;;;;;;;;GASG;AACH,wBAAgB,kBAAkB,CAAC,QAAQ,EAAE,MAAM,EAAE,kBAAkB,EAAE,OAAO,GAAG,OAAO,CAIzF;AAED;;;;GAIG;AACH,MAAM,WAAW,kBAAkB;IACjC,8DAA8D;IAC9D,QAAQ,CAAC,OAAO,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IAC9C,iEAAiE;IACjE,QAAQ,CAAC,UAAU,CAAC,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,MAAM,CAAC;IACjD,8EAA8E;IAC9E,QAAQ,CAAC,MAAM,CAAC,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,MAAM,CAAC;IAC5C,2GAA2G;IAC3G,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,CAAC;CACxB;AAED,wGAAwG;AACxG,MAAM,WAAW,kBAAkB;IACjC,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACjC,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IACpC,QAAQ,CAAC,MAAM,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;IAChC,QAAQ,CAAC,IAAI,CAAC,EAAE,MAAM,GAAG,IAAI,CAAC;CAC/B;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,kBAAkB,CAAC,SAAS,EAAE,kBAAkB,GAAG,kBAAkB,GAAG,SAAS,CAuBhG;AAED,6LAA6L;AAC7L,MAAM,MAAM,eAAe,GAAG,SAAS,GAAG,YAAY,GAAG,QAAQ,GAAG,MAAM,GAAG,KAAK,CAAC;AAEnF;;;;;;;;;;;;GAYG;AACH,wBAAgB,gBAAgB,CAC9B,MAAM,EAAE,kBAAkB,GAAG,SAAS,GACrC,SAAS,eAAe,EAAE,GAAG,SAAS,CAQxC;AAsCD;;;;;;;;;;;;;;;;;;;;;;GAsBG;AACH,wBAAgB,oBAAoB,CAClC,GAAG,EAAE,MAAM,EACX,MAAM,EAAE,eAAe,GAAG,SAAS,EACnC,MAAM,EAAE,kBAAkB,GAAG,SAAS,GACrC,MAAM,GAAG,IAAI,CAsCf"}
|
package/dist/host-widget.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { CartSnapshot, HostBridge, SiteProfile } from '@saar-ai/widget-bridge';
|
|
2
2
|
import type { VisitorEventCollector } from '@saar-ai/widget-bridge';
|
|
3
3
|
import type { WidgetChatCart } from '@saar-ai/widget-protocol/chat';
|
|
4
|
+
import { type HostRouteResolvers } from './host-routes.js';
|
|
4
5
|
import { type ChatCardItem, type ChatCheckoutHandoff } from './use-chat-session.js';
|
|
5
6
|
import { type VoiceSession } from './use-voice-session.js';
|
|
6
7
|
import type { WidgetCartLine } from './widget-cart-summary.js';
|
|
@@ -301,6 +302,22 @@ export interface ConciergeWidgetProps {
|
|
|
301
302
|
readonly locale?: string;
|
|
302
303
|
/** Builds a product card's PDP href from its handle — also feeds the `addToCart` degraded path, see `resolveAddToCartHandler`. */
|
|
303
304
|
readonly productHref?: (handle: string) => string;
|
|
305
|
+
/**
|
|
306
|
+
* This host's OWN navigation scheme — see `./host-routes.ts` for the defect
|
|
307
|
+
* it exists for (a demo storefront whose every collection navigation bounced
|
|
308
|
+
* the shopper to a login page).
|
|
309
|
+
*
|
|
310
|
+
* Two things follow from it, and both have to, which is why it is one prop
|
|
311
|
+
* rather than two: the concierge's destinations are REWRITTEN into this
|
|
312
|
+
* host's paths before the bridge is asked to navigate, and the same set is
|
|
313
|
+
* DECLARED to the api on session boot so a target this host cannot serve is
|
|
314
|
+
* refused before an event is ever produced.
|
|
315
|
+
*
|
|
316
|
+
* Absent — the default, and every host that predates this — means "spell
|
|
317
|
+
* destinations the way a Shopify storefront spells them", which is exactly
|
|
318
|
+
* what the widget did before.
|
|
319
|
+
*/
|
|
320
|
+
readonly hostRoutes?: HostRouteResolvers;
|
|
304
321
|
/** Builds a truncated curation's "See all N" href. */
|
|
305
322
|
readonly curationHref?: (curationId: string) => string;
|
|
306
323
|
/**
|
|
@@ -447,5 +464,5 @@ export interface ConciergeWidgetProps {
|
|
|
447
464
|
* about offering voice here costs a byte until a caller actually presses
|
|
448
465
|
* the microphone.
|
|
449
466
|
*/
|
|
450
|
-
export declare function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages, locale, productHref, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, }: ConciergeWidgetProps): import("react").JSX.Element;
|
|
467
|
+
export declare function ConciergeWidget({ embedKey, apiBase, socketUrl, socketPath, bridge, siteProfile, collector, messages, locale, productHref, hostRoutes, curationHref, brandPrimary, brandSecondary, brandAccent, avatar, attribution, color, type, identity, layout, copy, bottomOffset, showPrice, cardImageAspect, voiceAvailable, direction, proactive, initialDraft, initialSelection, initialFocus, initialMinimised, insets, hold, audio, onReady, }: ConciergeWidgetProps): import("react").JSX.Element;
|
|
451
468
|
//# sourceMappingURL=host-widget.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"host-widget.d.ts","sourceRoot":"","sources":["../src/host-widget.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,YAAY,EACZ,UAAU,EAEV,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAYhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAIpE,OAAO,KAAK,EAAE,cAAc,EAAoB,MAAM,+BAA+B,CAAC;AAOtF,OAAO,EAGL,KAAK,YAAY,EACjB,KAAK,mBAAmB,EACzB,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EAGL,KAAK,YAAY,EAClB,MAAM,wBAAwB,CAAC;AAEhC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAC/D,OAAO,KAAK,EAAE,kBAAkB,EAAE,iBAAiB,EAAE,MAAM,mBAAmB,CAAC;AAC/E,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,oBAAoB,CAAC;AACzD,OAAO,KAAK,EAAE,YAAY,EAAE,cAAc,EAAkB,MAAM,gBAAgB,CAAC;AAEnF,OAAO,KAAK,EAAE,iBAAiB,EAAE,gBAAgB,EAAE,MAAM,mBAAmB,CAAC;AAC7E,OAAO,EAAyB,KAAK,cAAc,EAAE,MAAM,eAAe,CAAC;AAE3E,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"host-widget.d.ts","sourceRoot":"","sources":["../src/host-widget.tsx"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAEV,YAAY,EACZ,UAAU,EAEV,WAAW,EAEZ,MAAM,wBAAwB,CAAC;AAYhC,OAAO,KAAK,EAAE,qBAAqB,EAAE,MAAM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AAC,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,UAAU,EAAE,MAAM,CAAA;KAAE,CAAC;IACrD,yEAAyE;IACzE,QAAQ,CAAC,IAAI,CAAC,EAAE;QAAE,MAAM,EAAE,MAAM,CAAC;QAAC,UAAU,CAAC,EAAE,MAAM,CAAA;KAAE,CAAC;IACxD,0DAA0D;IAC1D,QAAQ,CAAC,KAAK,CAAC,EAAE;QAAE,OAAO,EAAE,YAAY,CAAA;KAAE,CAAC;IAC3C;;;;OAIG;IACH,QAAQ,CAAC,OAAO,CAAC,EAAE,MAAM,IAAI,CAAC;CAC/B;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,wBAAgB,eAAe,CAAC,EAC9B,QAAQ,EACR,OAAO,EACP,SAAS,EACT,UAAU,EACV,MAAM,EACN,WAAW,EACX,SAAS,EACT,QAAgC,EAChC,MAAa,EACb,WAAW,EACX,UAAU,EACV,YAAY,EACZ,YAAY,EACZ,cAAc,EACd,WAAW,EACX,MAAM,EACN,WAAW,EACX,KAAK,EACL,IAAI,EACJ,QAAQ,EACR,MAAM,EACN,IAAI,EACJ,YAAY,EACZ,SAAS,EACT,eAAe,EACf,cAAc,EACd,SAAS,EACT,SAAS,EACT,YAAY,EACZ,gBAAgB,EAChB,YAAY,EACZ,gBAAgB,EAChB,MAAM,EACN,IAAI,EACJ,KAAK,EACL,OAAO,GACR,EAAE,oBAAoB,+BA22DtB"}
|
package/dist/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { $ as RADII, A as latencyBetween, At as linearToSrgb, B as CONTROL, Bt as srgbToLinear, C as parseBlocks, Ct as themeToCss, D as SESSION_EVENTS, Dt as hexToOklab, E as SseFrameParser, Et as formatHex, F as idleDockInput, Ft as oklchToHex, G as DOCK_ALIGN_STORAGE_KEY, Gt as widgetMessagesFromCopy, H as DESKTOP_BREAKPOINT, Ht as defaultWidgetMessages, I as latestExchangeStart, It as oklchToOklab, J as MARK, K as DOCK_MINIMISED_STORAGE_KEY, L as formatMoney, Lt as parseHex, M as DOCK_STATES, Mt as oklabToHex, N as deriveDockState, Nt as oklabToLinearRgb, O as SessionLog, Ot as hexToOklch, P as exchangeCount, Pt as oklabToOklch, Q as PROACTIVE_NUDGE_MS, R as ACTIVITY_W, Rt as relativeLuminance, S as WidgetMarkdown, St as deriveTheme, T as botStateFor, Tt as contrastRatio, U as DESKTOP_GUTTER, Ut as formatMessage, V as DESKTOP_BOTTOM, Vt as withAlpha, W as DESKTOP_WIDTHS, Wt as resolveWidgetMessages, X as PILL_H, Y as MOBILE_MARGIN, Z as PILL_MARK, _ as readsAsCartViewIntent, _t as writeStored, a as mergeAddedCartLine, at as SHEET_TOP_CLEARANCE, b as WidgetCartSummary, bt as SYSTEM_FONT_STACK, c as toChatCart, ct as bottomLen, d as useVoiceSession, dt as pillAnchor, et as ROW_H, f as isSameOriginPath, ft as readStored, g as basketIntentFromTurns, gt as snapAlign, h as VoiceWidget, ht as sheetMaxHeightLen, i as deriveCallPhase, it as SHEET_PEEK_MAX, j as Dock, jt as mixToward, k as formatMs, kt as linearRgbToOklab, l as ROOM_EVENTS, lt as geometryVars, mt as rowWidthLen, n as MAX_REPORTED_CART_LINES, nt as SHEET_EXPANDED_VH, o as resolveAddToCartHandler, ot as SHORT_VIEWPORT, p as useChatSession, pt as readStoredAlign, q as DRAG_TAP_SLOP_PX, r as cartLinesFromSnapshot, rt as SHEET_GAP, s as resolveCheckoutUrl, st as Z_INDEX, t as ConciergeWidget, tt as SHEET_EXPANDED_DESKTOP_MAX, u as createWidgetVoiceTokenFetcher, ut as persistAlign, v as readsAsCheckoutIntent, vt as CARD_RADIUS_MAX_PX, w as IDLE_SNAPSHOT, wt as themeToInlineStyle, x as WidgetCardList, xt as WIDGET_THEME_TOKENS, y as textDirectionFor, yt as SHEET_RADIUS_MAX_PX, z as BOTTOM_FLOOR, zt as rotateHue } from "./chunks/host-widget-
|
|
1
|
+
import { $ as RADII, A as latencyBetween, At as linearToSrgb, B as CONTROL, Bt as srgbToLinear, C as parseBlocks, Ct as themeToCss, D as SESSION_EVENTS, Dt as hexToOklab, E as SseFrameParser, Et as formatHex, F as idleDockInput, Ft as oklchToHex, G as DOCK_ALIGN_STORAGE_KEY, Gt as widgetMessagesFromCopy, H as DESKTOP_BREAKPOINT, Ht as defaultWidgetMessages, I as latestExchangeStart, It as oklchToOklab, J as MARK, K as DOCK_MINIMISED_STORAGE_KEY, L as formatMoney, Lt as parseHex, M as DOCK_STATES, Mt as oklabToHex, N as deriveDockState, Nt as oklabToLinearRgb, O as SessionLog, Ot as hexToOklch, P as exchangeCount, Pt as oklabToOklch, Q as PROACTIVE_NUDGE_MS, R as ACTIVITY_W, Rt as relativeLuminance, S as WidgetMarkdown, St as deriveTheme, T as botStateFor, Tt as contrastRatio, U as DESKTOP_GUTTER, Ut as formatMessage, V as DESKTOP_BOTTOM, Vt as withAlpha, W as DESKTOP_WIDTHS, Wt as resolveWidgetMessages, X as PILL_H, Y as MOBILE_MARGIN, Z as PILL_MARK, _ as readsAsCartViewIntent, _t as writeStored, a as mergeAddedCartLine, at as SHEET_TOP_CLEARANCE, b as WidgetCartSummary, bt as SYSTEM_FONT_STACK, c as toChatCart, ct as bottomLen, d as useVoiceSession, dt as pillAnchor, et as ROW_H, f as isSameOriginPath, ft as readStored, g as basketIntentFromTurns, gt as snapAlign, h as VoiceWidget, ht as sheetMaxHeightLen, i as deriveCallPhase, it as SHEET_PEEK_MAX, j as Dock, jt as mixToward, k as formatMs, kt as linearRgbToOklab, l as ROOM_EVENTS, lt as geometryVars, mt as rowWidthLen, n as MAX_REPORTED_CART_LINES, nt as SHEET_EXPANDED_VH, o as resolveAddToCartHandler, ot as SHORT_VIEWPORT, p as useChatSession, pt as readStoredAlign, q as DRAG_TAP_SLOP_PX, r as cartLinesFromSnapshot, rt as SHEET_GAP, s as resolveCheckoutUrl, st as Z_INDEX, t as ConciergeWidget, tt as SHEET_EXPANDED_DESKTOP_MAX, u as createWidgetVoiceTokenFetcher, ut as persistAlign, v as readsAsCheckoutIntent, vt as CARD_RADIUS_MAX_PX, w as IDLE_SNAPSHOT, wt as themeToInlineStyle, x as WidgetCardList, xt as WIDGET_THEME_TOKENS, y as textDirectionFor, yt as SHEET_RADIUS_MAX_PX, z as BOTTOM_FLOOR, zt as rotateHue } from "./chunks/host-widget-CTK7C95y.js";
|
|
2
2
|
import { jsx, jsxs } from "react/jsx-runtime";
|
|
3
3
|
import { Component, createElement, useEffect, useId, useRef, useState } from "react";
|
|
4
4
|
import { createRoot } from "react-dom/client";
|
package/dist/mount.d.ts
CHANGED
|
@@ -1,6 +1,15 @@
|
|
|
1
1
|
import { type ConciergeWidgetProps } from './host-widget.js';
|
|
2
2
|
export interface MountedWidget {
|
|
3
|
-
/**
|
|
3
|
+
/**
|
|
4
|
+
* Unmounts the React tree and detaches nothing else — the shadow root stays
|
|
5
|
+
* on `host` (removing it is the caller's own DOM to own).
|
|
6
|
+
*
|
|
7
|
+
* CALL IT. Removing `host` from the document is NOT equivalent: detaching
|
|
8
|
+
* leaves the tree mounted, so `useChatSession`'s refresh timer, its polling
|
|
9
|
+
* loop, its desk socket and every listener the dock attached keep running
|
|
10
|
+
* for the life of the page. A host that mounts and removes the widget across
|
|
11
|
+
* route changes accumulates one live widget per route.
|
|
12
|
+
*/
|
|
4
13
|
unmount(): void;
|
|
5
14
|
}
|
|
6
15
|
/**
|
package/dist/mount.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,MAAM,WAAW,aAAa;IAC5B
|
|
1
|
+
{"version":3,"file":"mount.d.ts","sourceRoot":"","sources":["../src/mount.ts"],"names":[],"mappings":"AAIA,OAAO,EAAmB,KAAK,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAG9E,MAAM,WAAW,aAAa;IAC5B;;;;;;;;;OASG;IACH,OAAO,IAAI,IAAI,CAAC;CACjB;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,wBAAgB,oBAAoB,CAClC,IAAI,EAAE,WAAW,EACjB,KAAK,EAAE,oBAAoB,GAC1B,aAAa,CAqCf;AAED;;;;;GAKG;AACH,wBAAgB,qBAAqB,CAAC,MAAM,EAAE,UAAU,GAAG,IAAI,CAiB9D"}
|
package/dist/next/index.js
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { m as detectPage, t as ConciergeWidget } from "../chunks/host-widget-
|
|
1
|
+
import { m as detectPage, t as ConciergeWidget } from "../chunks/host-widget-CTK7C95y.js";
|
|
2
2
|
import { useCallback, useEffect, useMemo, useRef } from "react";
|
|
3
3
|
import { usePathname, useRouter } from "next/navigation";
|
|
4
4
|
//#region src/next/use-next-bridge.ts
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { PageContext, VisitorEventCollector } from '@saar-ai/widget-bridge';
|
|
2
|
-
import type { WidgetChatCart, WidgetChatReport } from '@saar-ai/widget-protocol/chat';
|
|
2
|
+
import type { WidgetChatCard, WidgetChatCart, WidgetChatReport } from '@saar-ai/widget-protocol/chat';
|
|
3
3
|
import type { WidgetActEvent } from '@saar-ai/widget-protocol/act';
|
|
4
4
|
/**
|
|
5
5
|
* Is `value` a root-relative, same-origin storefront path?
|
|
@@ -128,37 +128,42 @@ export type ChatStatus = 'idle' | 'streaming' | 'escalated' | 'error';
|
|
|
128
128
|
* or the handshake was refused); poll restores to its normal cadence.
|
|
129
129
|
*/
|
|
130
130
|
export type ChatConnectionState = 'idle' | 'connecting' | 'connected' | 'disconnected';
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
131
|
+
/**
|
|
132
|
+
* The UI's own name for one product/curation card, as it renders it.
|
|
133
|
+
*
|
|
134
|
+
* An ALIAS of `@saar-ai/widget-protocol/chat`'s `WidgetChatCard` — the wire
|
|
135
|
+
* shape the server already validated before this ever reaches the widget —
|
|
136
|
+
* not a hand-maintained retyping. The two used to drift silently: a field
|
|
137
|
+
* added to the wire schema (`WidgetChatCardSchema`) would type-check here
|
|
138
|
+
* with no error, and the card renderer would just never see it. `variantId`
|
|
139
|
+
* is the INTERNAL catalog UUID (`curation_items.variant_id`) — never a
|
|
140
|
+
* platform id; see `platformVariantId` for what `addToCart` actually needs.
|
|
141
|
+
*
|
|
142
|
+
* `platformVariantId` is the PLATFORM-NATIVE variant id (e.g. Shopify's
|
|
143
|
+
* numeric `/cart/add.js` id, extracted server-side from the variant's
|
|
144
|
+
* provider GID via `apps/api/src/catalog/checkout-permalink.ts`'s
|
|
145
|
+
* `parseShopifyVariantNumericId` — the SAME parser the checkout permalink
|
|
146
|
+
* uses, never a client-side string-slice of `variantId`).
|
|
147
|
+
* `resolveAddToCartHandler` (`host-widget.tsx`) calls `bridge.addToCart` with
|
|
148
|
+
* THIS field, never `variantId` — adversarial-review finding #2: the
|
|
149
|
+
* internal UUID is meaningless to `ShopifyBridge`'s `POST /cart/add.js`,
|
|
150
|
+
* which needs Shopify's own numeric id. Absent whenever the underlying
|
|
151
|
+
* variant's external id isn't a recognised platform GID (§5.3's "degrade,
|
|
152
|
+
* never fabricate" — never guessed from `variantId`) — in that case the
|
|
153
|
+
* widget offers no add-to-cart action for this card and falls back to a PDP
|
|
154
|
+
* navigation instead, same as a card with no `handle` at all falling back to
|
|
155
|
+
* nothing.
|
|
156
|
+
*
|
|
157
|
+
* `Readonly<...>`, not the bare alias — `WidgetChatCard` is `z.infer<...>`
|
|
158
|
+
* and carries no `readonly` modifiers (zod does not emit them), but the
|
|
159
|
+
* interface this replaced marked every field `readonly` and callers hold
|
|
160
|
+
* `ChatCardItem[]` buffers (`host-widget.tsx`'s pending-cart-add and
|
|
161
|
+
* cards-by-turn maps) that were never meant to be mutated in place. Dropping
|
|
162
|
+
* that annotation silently was caught by adversarial review, not intended —
|
|
163
|
+
* `Readonly<WidgetChatCard>` restores it while staying a real alias: any
|
|
164
|
+
* field the wire schema adds still flows through with no edit here.
|
|
165
|
+
*/
|
|
166
|
+
export type ChatCardItem = Readonly<WidgetChatCard>;
|
|
162
167
|
export interface ChatCards {
|
|
163
168
|
readonly curationId?: string;
|
|
164
169
|
readonly items: readonly ChatCardItem[];
|
|
@@ -298,6 +303,23 @@ export interface UseChatSessionOptions {
|
|
|
298
303
|
* this option is purely additive.
|
|
299
304
|
*/
|
|
300
305
|
readonly collector?: VisitorEventCollector;
|
|
306
|
+
/**
|
|
307
|
+
* Which navigation targets THIS host page can actually resolve, sent once on
|
|
308
|
+
* `POST /widget/session` — see `./host-routes.ts` for the defect and
|
|
309
|
+
* `@saar-ai/widget-protocol`'s `host-routes.ts` for the wire contract.
|
|
310
|
+
*
|
|
311
|
+
* Absent ⇒ the field is omitted from the boot body entirely and the server
|
|
312
|
+
* keeps its storefront assumption, which is what every host did before this
|
|
313
|
+
* existed. An EMPTY array is a real declaration ("I can serve none of
|
|
314
|
+
* these") and is sent as one.
|
|
315
|
+
*
|
|
316
|
+
* Re-sent on a RECOVERY boot as well as a mount boot, unlike the tenant
|
|
317
|
+
* config this hook deliberately does not re-apply: a recovery mints a new
|
|
318
|
+
* session row server-side, and a capability omitted from that boot would
|
|
319
|
+
* leave the new session assuming a Shopify storefront on a host that is not
|
|
320
|
+
* one — the original bug, arriving thirty minutes in.
|
|
321
|
+
*/
|
|
322
|
+
readonly hostRoutes?: readonly ('product' | 'collection' | 'search' | 'cart' | 'url')[];
|
|
301
323
|
/**
|
|
302
324
|
* Overridable for tests; defaults to `Date.now`.
|
|
303
325
|
*
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-chat-session.d.ts","sourceRoot":"","sources":["../src/use-chat-session.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAQjF,OAAO,KAAK,
|
|
1
|
+
{"version":3,"file":"use-chat-session.d.ts","sourceRoot":"","sources":["../src/use-chat-session.ts"],"names":[],"mappings":"AAKA,OAAO,KAAK,EAAE,WAAW,EAAE,qBAAqB,EAAE,MAAM,wBAAwB,CAAC;AAQjF,OAAO,KAAK,EACV,cAAc,EACd,cAAc,EACd,gBAAgB,EACjB,MAAM,+BAA+B,CAAC;AAOvC,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,8BAA8B,CAAC;AAenE;;;;;;;;GAQG;AACH,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAEhE;AAUD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwGG;AAEH,MAAM,MAAM,UAAU,GAAG,MAAM,GAAG,WAAW,GAAG,WAAW,GAAG,OAAO,CAAC;AAEtE;;;;;;;;;GASG;AACH,MAAM,MAAM,mBAAmB,GAAG,MAAM,GAAG,YAAY,GAAG,WAAW,GAAG,cAAc,CAAC;AAEvF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAkCG;AACH,MAAM,MAAM,YAAY,GAAG,QAAQ,CAAC,cAAc,CAAC,CAAC;AAEpD,MAAM,WAAW,SAAS;IACxB,QAAQ,CAAC,UAAU,CAAC,EAAE,MAAM,CAAC;IAC7B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CAAC,mBAAmB,GAAG,IAAI,CAAC,CAAC;IACzC;;;;;;;;;OASG;IACH,QAAQ,CAAC,cAAc,EAAE,CAAC,IAAI,EAAE,IAAI,EAAE,OAAO,CAAC,EAAE,MAAM,KAAK,OAAO,CAAC,OAAO,CAAC,CAAC;IAC5E;;;;;;;;;;;;;;;;;;;;;;OAsBG;IACH,QAAQ,CAAC,kBAAkB,EAAE,MAAM,IAAI,CAAC;CACzC;AAgVD,wBAAgB,cAAc,CAAC,OAAO,EAAE,qBAAqB,GAAG,oBAAoB,CA2xDnF"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { BotState } from './bot-state.js';
|
|
2
|
-
import type { SessionConfigPayload, TranscriptPayload, TurnCostPayload, TurnLatencyPayload } from '@saar-ai/widget-protocol/telemetry';
|
|
2
|
+
import type { CallerInterruptReason, SessionConfigPayload, TranscriptPayload, TurnCostPayload, TurnLatencyPayload } from '@saar-ai/widget-protocol/telemetry';
|
|
3
3
|
import type { SessionTuning } from '@saar-ai/widget-protocol/tuning';
|
|
4
4
|
import type { WidgetToolEvent } from '@saar-ai/widget-protocol/chat';
|
|
5
5
|
import { type SessionLogEntry } from './session-log.js';
|
|
@@ -187,13 +187,17 @@ export type VoiceProtocol = Awaited<ReturnType<typeof loadVoiceProtocol>>;
|
|
|
187
187
|
/**
|
|
188
188
|
* Why the shopper cut the agent off, when they did it without speaking.
|
|
189
189
|
*
|
|
190
|
-
*
|
|
191
|
-
* `
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
* text mid-reply.
|
|
190
|
+
* Re-exported (not retyped) from `@saar-ai/widget-protocol/telemetry`'s
|
|
191
|
+
* `CallerInterruptReason` — the type derived from `CALLER_INTERRUPT_REASONS`,
|
|
192
|
+
* the same names `apps/voice`'s `handleCallerControl` records on the turn:
|
|
193
|
+
* `'look'` is §5.1's duck (the shopper turned to the page), `'tap'` the
|
|
194
|
+
* explicit interrupt control, `'keyboard'` a switch to text mid-reply. A
|
|
195
|
+
* TYPE-only import — this file already imports payload types from the same
|
|
196
|
+
* subpath above — so a fourth reason added to the wire enum reaches this
|
|
197
|
+
* hook's `interrupt()` signature with no edit here, rather than silently
|
|
198
|
+
* type-checking against a stale three-value union.
|
|
195
199
|
*/
|
|
196
|
-
export type CallerInterruptReason
|
|
200
|
+
export type { CallerInterruptReason };
|
|
197
201
|
/**
|
|
198
202
|
* `RoomEvent` values, as literals.
|
|
199
203
|
*
|
|
@@ -420,5 +424,4 @@ export interface WidgetVoiceTokenFetcherOptions {
|
|
|
420
424
|
*/
|
|
421
425
|
export declare function createWidgetVoiceTokenFetcher(options: WidgetVoiceTokenFetcherOptions): (tuning: SessionTuning) => Promise<CallerSession>;
|
|
422
426
|
export declare function useVoiceSession(options?: UseVoiceSessionOptions): VoiceSession;
|
|
423
|
-
export {};
|
|
424
427
|
//# sourceMappingURL=use-voice-session.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-voice-session.d.ts","sourceRoot":"","sources":["../src/use-voice-session.ts"],"names":[],"mappings":"AAIA,OAAO,KAAK,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC/C,OAAO,KAAK,EACV,oBAAoB,EACpB,iBAAiB,EACjB,eAAe,EACf,kBAAkB,EACnB,MAAM,oCAAoC,CAAC;AAC5C,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,iCAAiC,CAAC;AACrE,OAAO,KAAK,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC;AAErE,OAAO,EAAqC,KAAK,eAAe,EAAE,MAAM,kBAAkB,CAAC;AAC3F,OAAO,EAGL,KAAK,UAAU,EACf,KAAK,oBAAoB,EAC1B,MAAM,0BAA0B,CAAC;AAElC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmEG;AAEH,MAAM,WAAW,aAAa;IAC5B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACr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AC;CACnC;AAqGD;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,wBAAgB,6BAA6B,CAC3C,OAAO,EAAE,8BAA8B,GACtC,CAAC,MAAM,EAAE,aAAa,KAAK,OAAO,CAAC,aAAa,CAAC,CAyBnD;AA4ED,wBAAgB,eAAe,CAAC,OAAO,GAAE,sBAA2B,GAAG,YAAY,CA0gBlF"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@saar-ai/web-widget",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.9.0",
|
|
4
4
|
"saar:distribution": "publishable",
|
|
5
5
|
"description": "The concierge widget's React UI — ConciergeShell chrome plus the full end-user conversation (VoiceWidget, useChatSession, useVoiceSession) — de-Nexted for the merchant-site embed (docs/WIDGET_EMBED_PLAN.md §4 Phase 3). Publishes PUBLICLY to npmjs (docs/WIDGET_EMBED_PLAN.md §5.1) — every workspace and third-party runtime dependency is bundled into dist/ at build time, so \"dependencies\" is empty. React and react-dom are peer dependencies only; next is an optional peer, needed only by the ./next subpath (Phase 5).",
|
|
6
6
|
"type": "module",
|
|
@@ -71,7 +71,7 @@
|
|
|
71
71
|
"vite": "8.0.16",
|
|
72
72
|
"vitest": "4.1.10",
|
|
73
73
|
"@saar-ai/widget-bridge": "0.6.0",
|
|
74
|
-
"@saar-ai/widget-protocol": "0.
|
|
74
|
+
"@saar-ai/widget-protocol": "0.7.0",
|
|
75
75
|
"@wesence/branding": "0.0.1",
|
|
76
76
|
"@wesence/vitest-presets": "0.0.1"
|
|
77
77
|
},
|