@oxvo/ai-live-assist 7.5.20 → 7.5.21

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.
Files changed (99) hide show
  1. package/cjs/AiLiveAssist.d.ts +8 -1
  2. package/cjs/AiLiveAssist.js +113 -8
  3. package/cjs/client.d.ts +5 -3
  4. package/cjs/client.js +44 -5
  5. package/cjs/commerce/cartContracts.d.ts +158 -0
  6. package/cjs/commerce/cartContracts.js +228 -0
  7. package/cjs/commerce/cartSession.d.ts +86 -0
  8. package/cjs/commerce/cartSession.js +475 -0
  9. package/cjs/commerce/contracts.d.ts +152 -0
  10. package/cjs/commerce/contracts.js +322 -0
  11. package/cjs/commerce/pageContext.d.ts +50 -0
  12. package/cjs/commerce/pageContext.js +173 -0
  13. package/cjs/commerce/productPanel.d.ts +65 -0
  14. package/cjs/commerce/productPanel.js +662 -0
  15. package/cjs/commerce/realtimeCommerce.d.ts +73 -0
  16. package/cjs/commerce/realtimeCommerce.js +342 -0
  17. package/cjs/commerce/shopifyCart.d.ts +130 -0
  18. package/cjs/commerce/shopifyCart.js +1135 -0
  19. package/cjs/commerce/shopifyCartPresentation.d.ts +12 -0
  20. package/cjs/commerce/shopifyCartPresentation.js +379 -0
  21. package/cjs/commerce/shoppingNotes.d.ts +61 -0
  22. package/cjs/commerce/shoppingNotes.js +313 -0
  23. package/cjs/commerce/shoppingNotesView.d.ts +46 -0
  24. package/cjs/commerce/shoppingNotesView.js +269 -0
  25. package/cjs/control.d.ts +9 -1
  26. package/cjs/control.js +51 -1
  27. package/cjs/guideAdmission.d.ts +5 -2
  28. package/cjs/guideAdmission.js +21 -2
  29. package/cjs/guideInstaller.js +1 -1
  30. package/cjs/guideMeasurement.d.ts +5 -0
  31. package/cjs/guideMeasurement.js +29 -0
  32. package/cjs/guideSubjectStore.js +2 -0
  33. package/cjs/guideTypes.d.ts +18 -0
  34. package/cjs/liveControlChannel.d.ts +43 -1
  35. package/cjs/liveControlChannel.js +166 -14
  36. package/cjs/liveGuideAdmission.d.ts +3 -2
  37. package/cjs/liveGuideAdmission.js +10 -2
  38. package/cjs/liveGuideWidget.d.ts +18 -0
  39. package/cjs/liveGuideWidget.js +228 -23
  40. package/cjs/locales/resources.js +2240 -0
  41. package/cjs/messages.js +56 -0
  42. package/cjs/tabLock.d.ts +2 -0
  43. package/cjs/tabLock.js +11 -1
  44. package/cjs/types.d.ts +6 -2
  45. package/cjs/types.js +56 -0
  46. package/cjs/ui.d.ts +37 -0
  47. package/cjs/ui.js +259 -9
  48. package/cjs/version.d.ts +1 -1
  49. package/cjs/version.js +1 -1
  50. package/lib/AiLiveAssist.d.ts +8 -1
  51. package/lib/AiLiveAssist.js +113 -8
  52. package/lib/client.d.ts +5 -3
  53. package/lib/client.js +44 -5
  54. package/lib/commerce/cartContracts.d.ts +158 -0
  55. package/lib/commerce/cartContracts.js +221 -0
  56. package/lib/commerce/cartSession.d.ts +86 -0
  57. package/lib/commerce/cartSession.js +471 -0
  58. package/lib/commerce/contracts.d.ts +152 -0
  59. package/lib/commerce/contracts.js +300 -0
  60. package/lib/commerce/pageContext.d.ts +50 -0
  61. package/lib/commerce/pageContext.js +168 -0
  62. package/lib/commerce/productPanel.d.ts +65 -0
  63. package/lib/commerce/productPanel.js +657 -0
  64. package/lib/commerce/realtimeCommerce.d.ts +73 -0
  65. package/lib/commerce/realtimeCommerce.js +337 -0
  66. package/lib/commerce/shopifyCart.d.ts +130 -0
  67. package/lib/commerce/shopifyCart.js +1130 -0
  68. package/lib/commerce/shopifyCartPresentation.d.ts +12 -0
  69. package/lib/commerce/shopifyCartPresentation.js +376 -0
  70. package/lib/commerce/shoppingNotes.d.ts +61 -0
  71. package/lib/commerce/shoppingNotes.js +307 -0
  72. package/lib/commerce/shoppingNotesView.d.ts +46 -0
  73. package/lib/commerce/shoppingNotesView.js +265 -0
  74. package/lib/control.d.ts +9 -1
  75. package/lib/control.js +51 -1
  76. package/lib/guideAdmission.d.ts +5 -2
  77. package/lib/guideAdmission.js +21 -2
  78. package/lib/guideInstaller.js +1 -1
  79. package/lib/guideMeasurement.d.ts +5 -0
  80. package/lib/guideMeasurement.js +24 -0
  81. package/lib/guideSubjectStore.js +2 -0
  82. package/lib/guideTypes.d.ts +18 -0
  83. package/lib/liveControlChannel.d.ts +43 -1
  84. package/lib/liveControlChannel.js +166 -14
  85. package/lib/liveGuideAdmission.d.ts +3 -2
  86. package/lib/liveGuideAdmission.js +10 -2
  87. package/lib/liveGuideWidget.d.ts +18 -0
  88. package/lib/liveGuideWidget.js +228 -23
  89. package/lib/locales/resources.js +2240 -0
  90. package/lib/messages.js +56 -0
  91. package/lib/tabLock.d.ts +2 -0
  92. package/lib/tabLock.js +11 -1
  93. package/lib/types.d.ts +6 -2
  94. package/lib/types.js +56 -0
  95. package/lib/ui.d.ts +37 -0
  96. package/lib/ui.js +259 -9
  97. package/lib/version.d.ts +1 -1
  98. package/lib/version.js +1 -1
  99. package/package.json +1 -1
@@ -0,0 +1,307 @@
1
+ import { GUIDE_INSTALL_KEY_PATTERN } from "../guideTypes.js";
2
+ import { commerceUuid, isCommerceOptions, isCommerceStore, parseCommerceBootstrap, sameCommerceStore, } from "./contracts.js";
3
+ export const SHOPPING_NOTES_STORAGE_KEY = "__oxvo_guide_shopping_notes_v1";
4
+ export const SHOPPING_NOTES_MAX_BYTES = 4096;
5
+ export const SHOPPING_NOTES_TTL_MS = 30 * 60 * 1000;
6
+ export const SHOPPING_NOTES_QUESTION_MAX_LENGTH = 4000;
7
+ const scopeKeys = [
8
+ "origin",
9
+ "installKey",
10
+ "projectId",
11
+ "guideId",
12
+ "store",
13
+ ];
14
+ const storeKeys = ["provider", "storeRef", "origin", "policyRevision"];
15
+ const recordKeys = [
16
+ "schemaVersion",
17
+ "scope",
18
+ "savedAt",
19
+ "expiresAt",
20
+ "draft",
21
+ ];
22
+ const owns = (value, key) => Object.prototype.hasOwnProperty.call(value, key);
23
+ /** Do not invoke accessors/toJSON on inputs from a page or UI callback. */
24
+ function fields(value, required, optional = []) {
25
+ if (!value ||
26
+ typeof value !== "object" ||
27
+ Array.isArray(value) ||
28
+ (Object.getPrototypeOf(value) !== Object.prototype &&
29
+ Object.getPrototypeOf(value) !== null))
30
+ return false;
31
+ const keys = Reflect.ownKeys(value);
32
+ return (required.every((key) => owns(value, key)) &&
33
+ keys.every((key) => {
34
+ if (typeof key !== "string" ||
35
+ (!required.includes(key) && !optional.includes(key)))
36
+ return false;
37
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
38
+ return !!descriptor?.enumerable && "value" in descriptor;
39
+ }));
40
+ }
41
+ function plainArray(value, maximum) {
42
+ if (!Array.isArray(value) ||
43
+ value.length > maximum ||
44
+ Reflect.ownKeys(value).length !== value.length + 1)
45
+ return false;
46
+ return Array.from({ length: value.length }, (_, index) => Object.getOwnPropertyDescriptor(value, String(index))).every((descriptor) => !!descriptor?.enumerable && "value" in descriptor);
47
+ }
48
+ function validScope(value) {
49
+ return (fields(value, scopeKeys) &&
50
+ typeof value.origin === "string" &&
51
+ typeof value.installKey === "string" &&
52
+ GUIDE_INSTALL_KEY_PATTERN.test(value.installKey) &&
53
+ Number.isSafeInteger(value.projectId) &&
54
+ Number(value.projectId) > 0 &&
55
+ commerceUuid(value.guideId) &&
56
+ fields(value.store, storeKeys) &&
57
+ isCommerceStore(value.store) &&
58
+ value.store.origin === value.origin);
59
+ }
60
+ const sameScope = (left, right) => left.origin === right.origin &&
61
+ left.installKey === right.installKey &&
62
+ left.projectId === right.projectId &&
63
+ left.guideId === right.guideId &&
64
+ sameCommerceStore(left.store, right.store);
65
+ const copyScope = (scope) => ({
66
+ origin: scope.origin,
67
+ installKey: scope.installKey,
68
+ projectId: scope.projectId,
69
+ guideId: scope.guideId,
70
+ store: {
71
+ provider: scope.store.provider,
72
+ storeRef: scope.store.storeRef,
73
+ origin: scope.store.origin,
74
+ policyRevision: scope.store.policyRevision,
75
+ },
76
+ });
77
+ function ownData(value, key) {
78
+ const descriptor = Object.getOwnPropertyDescriptor(value, key);
79
+ return descriptor && "value" in descriptor ? descriptor.value : undefined;
80
+ }
81
+ /** Only validated current bootstrap identity supplies the scope; notes never supply it. */
82
+ export function createShoppingNotesScope(config, origin = location.origin) {
83
+ try {
84
+ if (!config ||
85
+ typeof config !== "object" ||
86
+ ownData(config, "schemaVersion") !== 3)
87
+ return null;
88
+ const commerce = ownData(config, "commerce");
89
+ if (!fields(commerce, [
90
+ "schemaVersion",
91
+ "enabled",
92
+ "guideId",
93
+ "store",
94
+ "cartEnabled",
95
+ ]) ||
96
+ !fields(commerce.store, storeKeys))
97
+ return null;
98
+ const scope = {
99
+ origin,
100
+ installKey: ownData(config, "installKey"),
101
+ projectId: ownData(config, "projectId"),
102
+ guideId: ownData(config, "guideId"),
103
+ store: commerce.store,
104
+ };
105
+ if (!validScope(scope) ||
106
+ !parseCommerceBootstrap(commerce, scope.guideId, origin))
107
+ return null;
108
+ return copyScope(scope);
109
+ }
110
+ catch {
111
+ return null;
112
+ }
113
+ }
114
+ const controls = /[\u0000-\u0008\u000b\u000c\u000e-\u001f\u007f]/u;
115
+ function reference(value, kind) {
116
+ if (typeof value !== "string")
117
+ return false;
118
+ const match = new RegExp(`^gid://shopify/${kind}/([1-9]\\d{0,19})$`, "u").exec(value);
119
+ return !!match?.[1] && BigInt(match[1]) <= 18446744073709551615n;
120
+ }
121
+ function validDraft(value) {
122
+ return (fields(value, ["needs", "products"]) &&
123
+ typeof value.needs === "string" &&
124
+ value.needs.length <= SHOPPING_NOTES_QUESTION_MAX_LENGTH &&
125
+ !controls.test(value.needs) &&
126
+ plainArray(value.products, 3) &&
127
+ value.products.every((product) => fields(product, ["productRef", "variantRef", "selectedOptions"], ["label"]) &&
128
+ reference(product.productRef, "Product") &&
129
+ (product.variantRef === null ||
130
+ reference(product.variantRef, "ProductVariant")) &&
131
+ plainArray(product.selectedOptions, 3) &&
132
+ product.selectedOptions.every((option) => fields(option, ["name", "value"])) &&
133
+ isCommerceOptions(product.selectedOptions) &&
134
+ (!owns(product, "label") ||
135
+ (typeof product.label === "string" &&
136
+ product.label.length > 0 &&
137
+ product.label.length <= 120 &&
138
+ product.label === product.label.trim() &&
139
+ !/[\u0000-\u001f\u007f]/u.test(product.label)))) &&
140
+ new Set(value.products.map((product) => `${product.productRef}\n${product.variantRef ?? ""}`)).size === value.products.length);
141
+ }
142
+ const empty = (draft) => !draft.needs.trim() && draft.products.length === 0;
143
+ function copyDraft(draft) {
144
+ return {
145
+ needs: draft.needs,
146
+ products: draft.products.map((product) => ({
147
+ productRef: product.productRef,
148
+ variantRef: product.variantRef,
149
+ selectedOptions: product.selectedOptions.map(({ name, value }) => ({
150
+ name,
151
+ value,
152
+ })),
153
+ ...(product.label === undefined ? {} : { label: product.label }),
154
+ })),
155
+ };
156
+ }
157
+ /** Builds the entire text for shopper review. No truncation, launch, text send or permission restoration. */
158
+ export function buildShoppingNotesQuestion(reviewedDraft) {
159
+ try {
160
+ if (fields(reviewedDraft, ["needs", "products"]) &&
161
+ typeof reviewedDraft.needs === "string" &&
162
+ reviewedDraft.needs.length > SHOPPING_NOTES_QUESTION_MAX_LENGTH)
163
+ return { ok: false, reason: "too_long" };
164
+ if (!validDraft(reviewedDraft))
165
+ return { ok: false, reason: "invalid" };
166
+ if (empty(reviewedDraft))
167
+ return { ok: false, reason: "empty" };
168
+ const products = reviewedDraft.products.map((product) => [
169
+ ...(product.label ? [product.label] : []),
170
+ product.productRef,
171
+ ...(product.variantRef ? [product.variantRef] : []),
172
+ ...product.selectedOptions.map((option) => `${option.name}: ${option.value}`),
173
+ ].join("\n"));
174
+ const initialQuestion = [
175
+ ...(reviewedDraft.needs ? [reviewedDraft.needs] : []),
176
+ ...products,
177
+ ].join("\n\n");
178
+ return initialQuestion.length <= SHOPPING_NOTES_QUESTION_MAX_LENGTH
179
+ ? { ok: true, initialQuestion }
180
+ : { ok: false, reason: "too_long" };
181
+ }
182
+ catch {
183
+ return { ok: false, reason: "invalid" };
184
+ }
185
+ }
186
+ const bytes = (value) => new TextEncoder().encode(value).byteLength;
187
+ function validRecord(value, now) {
188
+ return (fields(value, recordKeys) &&
189
+ value.schemaVersion === 1 &&
190
+ validScope(value.scope) &&
191
+ validDraft(value.draft) &&
192
+ !empty(value.draft) &&
193
+ Number.isSafeInteger(value.savedAt) &&
194
+ Number(value.savedAt) >= 0 &&
195
+ Number(value.savedAt) <= now &&
196
+ Number.isSafeInteger(value.expiresAt) &&
197
+ value.expiresAt === Number(value.savedAt) + SHOPPING_NOTES_TTL_MS &&
198
+ Number(value.expiresAt) > now);
199
+ }
200
+ /** Optional per-tab convenience. Constructing or reading this cannot start any Guide or restore authority. */
201
+ export class ShoppingNotesStore {
202
+ constructor(scope) {
203
+ try {
204
+ this.scope = validScope(scope) ? copyScope(scope) : null;
205
+ }
206
+ catch {
207
+ this.scope = null;
208
+ }
209
+ }
210
+ currentScope() {
211
+ return this.scope?.origin === location.origin ? this.scope : null;
212
+ }
213
+ read() {
214
+ try {
215
+ const scope = this.currentScope();
216
+ if (!scope)
217
+ return null;
218
+ const raw = sessionStorage.getItem(SHOPPING_NOTES_STORAGE_KEY);
219
+ if (raw === null || raw.length > SHOPPING_NOTES_MAX_BYTES)
220
+ return null;
221
+ let value;
222
+ try {
223
+ value = JSON.parse(raw);
224
+ }
225
+ catch {
226
+ return null;
227
+ }
228
+ // Another Guide's valid notes are not ours to remove. Unscopable records are ignored.
229
+ if (!value ||
230
+ typeof value !== "object" ||
231
+ !validScope(value.scope) ||
232
+ !sameScope(value.scope, scope))
233
+ return null;
234
+ if (bytes(raw) > SHOPPING_NOTES_MAX_BYTES ||
235
+ !validRecord(value, Date.now())) {
236
+ sessionStorage.removeItem(SHOPPING_NOTES_STORAGE_KEY);
237
+ return null;
238
+ }
239
+ return {
240
+ schemaVersion: 1,
241
+ scope: copyScope(value.scope),
242
+ savedAt: value.savedAt,
243
+ expiresAt: value.expiresAt,
244
+ draft: copyDraft(value.draft),
245
+ };
246
+ }
247
+ catch {
248
+ return null;
249
+ }
250
+ }
251
+ /** Called only by the explicit shopper Save control. Saving starts one new fixed expiry interval. */
252
+ save(draft) {
253
+ try {
254
+ const scope = this.currentScope();
255
+ if (!scope || !validDraft(draft))
256
+ return { ok: false, reason: "invalid" };
257
+ if (empty(draft))
258
+ return { ok: false, reason: "empty" };
259
+ const savedAt = Date.now();
260
+ const record = {
261
+ schemaVersion: 1,
262
+ scope: copyScope(scope),
263
+ savedAt,
264
+ expiresAt: savedAt + SHOPPING_NOTES_TTL_MS,
265
+ draft: copyDraft(draft),
266
+ };
267
+ const raw = JSON.stringify(record);
268
+ if (bytes(raw) > SHOPPING_NOTES_MAX_BYTES)
269
+ return { ok: false, reason: "too_large" };
270
+ sessionStorage.setItem(SHOPPING_NOTES_STORAGE_KEY, raw);
271
+ if (sessionStorage.getItem(SHOPPING_NOTES_STORAGE_KEY) !== raw)
272
+ return { ok: false, reason: "storage_unavailable" };
273
+ return { ok: true, record };
274
+ }
275
+ catch {
276
+ return { ok: false, reason: "storage_unavailable" };
277
+ }
278
+ }
279
+ /** Only our own scoped notes are removed; launch and unresolved-cart stores are never accessed. */
280
+ clear() {
281
+ try {
282
+ const scope = this.currentScope();
283
+ if (!scope)
284
+ return false;
285
+ const raw = sessionStorage.getItem(SHOPPING_NOTES_STORAGE_KEY);
286
+ if (raw === null || raw.length > SHOPPING_NOTES_MAX_BYTES)
287
+ return true;
288
+ let value;
289
+ try {
290
+ value = JSON.parse(raw);
291
+ }
292
+ catch {
293
+ return true;
294
+ }
295
+ if (!value ||
296
+ typeof value !== "object" ||
297
+ !validScope(value.scope) ||
298
+ !sameScope(value.scope, scope))
299
+ return true;
300
+ sessionStorage.removeItem(SHOPPING_NOTES_STORAGE_KEY);
301
+ return sessionStorage.getItem(SHOPPING_NOTES_STORAGE_KEY) === null;
302
+ }
303
+ catch {
304
+ return false;
305
+ }
306
+ }
307
+ }
@@ -0,0 +1,46 @@
1
+ import type { WidgetMessageKey } from "../types.js";
2
+ import type { DialogFocusScope } from "../dialogFocusScope.js";
3
+ import { type ShoppingNotesProduct, type ShoppingNotesScope } from "./shoppingNotes.js";
4
+ export declare const SHOPPING_NOTES_STYLES = "\n .shopping-notes-entry, .shopping-notes-dialog button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 10px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); font: inherit; cursor: pointer; pointer-events: auto; }\n .shopping-notes-entry { align-self: flex-end; margin-block-end: 8px; max-width: 100%; font: 400 13px/1.4 system-ui, sans-serif; }\n .shopping-notes-dialog { position: fixed; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto; z-index: 20; box-sizing: border-box; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; padding: 16px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 16px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); box-shadow: 0 8px 32px #0003; pointer-events: auto; font: 400 14px/1.45 system-ui, sans-serif; }\n .shopping-notes-dialog *, .shopping-notes-dialog *::before, .shopping-notes-dialog *::after { box-sizing: border-box; }\n .shopping-notes-dialog[hidden], .shopping-notes-dialog [hidden], .shopping-notes-entry[hidden] { display: none !important; }\n .shopping-notes-dialog h2 { margin: 0; font-size: 18px; }\n .shopping-notes-dialog p { margin-block: 10px; }\n .shopping-notes-dialog label { display: grid; gap: 6px; }\n .shopping-notes-dialog textarea { min-height: 100px; width: 100%; min-width: 0; padding: 10px; resize: vertical; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; color: inherit; background: var(--assist-surface-muted, var(--voice-surface)); font: inherit; }\n .shopping-notes-products { display: grid; gap: 8px; padding: 0; list-style: none; }\n .shopping-notes-products li { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; overflow-wrap: anywhere; }\n .shopping-notes-products small { color: var(--assist-muted, var(--voice-muted)); }\n .shopping-notes-actions { display: flex; flex-wrap: wrap; gap: 8px; }\n .shopping-notes-actions button { flex: 1 1 120px; }\n .shopping-notes-dialog button { white-space: normal; overflow-wrap: anywhere; }\n .shopping-notes-dialog button:disabled { opacity: .55; cursor: default; }\n .shopping-notes-dialog :is(button, textarea):focus-visible, .shopping-notes-entry:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }\n";
5
+ /** Explicit local editor. It never receives transcript, prices, or cart state. */
6
+ export declare class ShoppingNotesView {
7
+ readonly scope: ShoppingNotesScope;
8
+ private readonly message;
9
+ private readonly focus;
10
+ private readonly callbacks;
11
+ readonly element: HTMLElement;
12
+ private readonly needs;
13
+ private readonly products;
14
+ private readonly status;
15
+ private readonly startButton;
16
+ private readonly store;
17
+ private draft;
18
+ private expiresAt;
19
+ private destroyed;
20
+ private submitted;
21
+ private submittedQuestion;
22
+ private submittedCaption;
23
+ private failedLaunchDraft;
24
+ constructor(scope: ShoppingNotesScope, message: (key: WidgetMessageKey) => string, focus: DialogFocusScope, callbacks: {
25
+ active: () => boolean;
26
+ start: (question: string) => boolean;
27
+ changed: () => void;
28
+ fallbackFocus: () => HTMLElement | null;
29
+ });
30
+ hasSaved(): boolean;
31
+ markLaunchFailed(): void;
32
+ prepareLaunch(question?: string): void;
33
+ /** Internal retrieval references remain in the submitted text, not its UI echo. */
34
+ captionText(question: string): string;
35
+ open(product?: ShoppingNotesProduct): void;
36
+ /** Recover only our exact admitted draft after a failed asynchronous launch. */
37
+ retry(question: string, message: string): boolean;
38
+ private present;
39
+ close(restore?: boolean): void;
40
+ destroy(): void;
41
+ private save;
42
+ private clear;
43
+ private start;
44
+ private renderProducts;
45
+ private button;
46
+ }
@@ -0,0 +1,265 @@
1
+ import { ShoppingNotesStore, SHOPPING_NOTES_QUESTION_MAX_LENGTH, buildShoppingNotesQuestion, } from "./shoppingNotes.js";
2
+ export const SHOPPING_NOTES_STYLES = `
3
+ .shopping-notes-entry, .shopping-notes-dialog button { min-height: 44px; padding: 8px 12px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 10px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); font: inherit; cursor: pointer; pointer-events: auto; }
4
+ .shopping-notes-entry { align-self: flex-end; margin-block-end: 8px; max-width: 100%; font: 400 13px/1.4 system-ui, sans-serif; }
5
+ .shopping-notes-dialog { position: fixed; inset: auto max(12px, env(safe-area-inset-right)) max(12px, env(safe-area-inset-bottom)) auto; z-index: 20; box-sizing: border-box; width: min(420px, calc(100vw - 24px)); max-height: calc(100dvh - 24px); overflow: auto; overscroll-behavior: contain; padding: 16px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 16px; color: var(--assist-text, var(--voice-text)); background: var(--assist-surface, var(--voice-surface)); box-shadow: 0 8px 32px #0003; pointer-events: auto; font: 400 14px/1.45 system-ui, sans-serif; }
6
+ .shopping-notes-dialog *, .shopping-notes-dialog *::before, .shopping-notes-dialog *::after { box-sizing: border-box; }
7
+ .shopping-notes-dialog[hidden], .shopping-notes-dialog [hidden], .shopping-notes-entry[hidden] { display: none !important; }
8
+ .shopping-notes-dialog h2 { margin: 0; font-size: 18px; }
9
+ .shopping-notes-dialog p { margin-block: 10px; }
10
+ .shopping-notes-dialog label { display: grid; gap: 6px; }
11
+ .shopping-notes-dialog textarea { min-height: 100px; width: 100%; min-width: 0; padding: 10px; resize: vertical; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; color: inherit; background: var(--assist-surface-muted, var(--voice-surface)); font: inherit; }
12
+ .shopping-notes-products { display: grid; gap: 8px; padding: 0; list-style: none; }
13
+ .shopping-notes-products li { display: grid; gap: 4px; padding: 8px; border: 1px solid var(--assist-border, var(--voice-border)); border-radius: 8px; overflow-wrap: anywhere; }
14
+ .shopping-notes-products small { color: var(--assist-muted, var(--voice-muted)); }
15
+ .shopping-notes-actions { display: flex; flex-wrap: wrap; gap: 8px; }
16
+ .shopping-notes-actions button { flex: 1 1 120px; }
17
+ .shopping-notes-dialog button { white-space: normal; overflow-wrap: anywhere; }
18
+ .shopping-notes-dialog button:disabled { opacity: .55; cursor: default; }
19
+ .shopping-notes-dialog :is(button, textarea):focus-visible, .shopping-notes-entry:focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
20
+ `;
21
+ /** Explicit local editor. It never receives transcript, prices, or cart state. */
22
+ export class ShoppingNotesView {
23
+ constructor(scope, message, focus, callbacks) {
24
+ this.scope = scope;
25
+ this.message = message;
26
+ this.focus = focus;
27
+ this.callbacks = callbacks;
28
+ this.element = document.createElement("section");
29
+ this.needs = document.createElement("textarea");
30
+ this.products = document.createElement("ul");
31
+ this.status = document.createElement("p");
32
+ this.draft = { needs: "", products: [] };
33
+ this.expiresAt = null;
34
+ this.destroyed = false;
35
+ this.submitted = false;
36
+ this.submittedQuestion = null;
37
+ this.submittedCaption = null;
38
+ this.failedLaunchDraft = false;
39
+ this.store = new ShoppingNotesStore(scope);
40
+ this.element.className = "shopping-notes-dialog";
41
+ this.element.hidden = true;
42
+ this.element.setAttribute("role", "dialog");
43
+ this.element.setAttribute("aria-modal", "true");
44
+ this.element.setAttribute("aria-label", message("shoppingNotesTitle"));
45
+ const title = document.createElement("h2");
46
+ title.textContent = message("shoppingNotesTitle");
47
+ const description = document.createElement("p");
48
+ description.textContent = message("shoppingNotesDescription");
49
+ const label = document.createElement("label");
50
+ label.textContent = message("shoppingNotesNeeds");
51
+ this.needs.dataset.role = "shopping-notes-needs";
52
+ this.needs.addEventListener("input", () => {
53
+ this.draft.needs = this.needs.value;
54
+ this.status.textContent = "";
55
+ });
56
+ label.append(this.needs);
57
+ this.products.className = "shopping-notes-products";
58
+ this.status.setAttribute("role", "status");
59
+ this.status.setAttribute("aria-live", "polite");
60
+ this.status.dataset.role = "shopping-notes-status";
61
+ const actions = document.createElement("div");
62
+ actions.className = "shopping-notes-actions";
63
+ this.startButton = this.button("shoppingNotesStart", () => this.start());
64
+ actions.append(this.button("shoppingNotesSave", () => this.save()), this.button("shoppingNotesClear", () => this.clear()), this.startButton, this.button("close", () => this.close()));
65
+ this.element.append(title, description, label, this.products, this.status, actions);
66
+ }
67
+ hasSaved() {
68
+ return this.failedLaunchDraft || this.store.read() !== null;
69
+ }
70
+ markLaunchFailed() {
71
+ if (this.submittedQuestion !== null)
72
+ this.failedLaunchDraft = true;
73
+ }
74
+ prepareLaunch(question) {
75
+ if (question !== this.submittedQuestion) {
76
+ this.submittedQuestion = null;
77
+ this.submittedCaption = null;
78
+ }
79
+ }
80
+ /** Internal retrieval references remain in the submitted text, not its UI echo. */
81
+ captionText(question) {
82
+ return this.submittedCaption?.question === question ? this.submittedCaption.text : question;
83
+ }
84
+ open(product) {
85
+ if (this.destroyed)
86
+ return;
87
+ if (!this.failedLaunchDraft) {
88
+ const saved = this.store.read();
89
+ this.draft = saved?.draft ?? { needs: "", products: [] };
90
+ this.expiresAt = saved?.expiresAt ?? null;
91
+ }
92
+ this.submitted = false;
93
+ this.submittedQuestion = null;
94
+ this.status.textContent = this.failedLaunchDraft
95
+ ? this.message("shoppingNotesStartFailed")
96
+ : "";
97
+ if (product) {
98
+ const index = this.draft.products.findIndex((value) => value.productRef === product.productRef &&
99
+ value.variantRef === product.variantRef);
100
+ if (index >= 0)
101
+ this.draft.products[index] = product;
102
+ else if (this.draft.products.length < 3)
103
+ this.draft.products.push(product);
104
+ else
105
+ this.status.textContent = this.message("shoppingNotesTooMany");
106
+ }
107
+ this.needs.value = this.draft.needs;
108
+ this.renderProducts();
109
+ this.present();
110
+ }
111
+ /** Recover only our exact admitted draft after a failed asynchronous launch. */
112
+ retry(question, message) {
113
+ if (this.destroyed || question !== this.submittedQuestion)
114
+ return false;
115
+ this.failedLaunchDraft = true;
116
+ this.submitted = false;
117
+ this.needs.value = this.draft.needs;
118
+ this.renderProducts();
119
+ this.status.textContent = message;
120
+ this.present();
121
+ return true;
122
+ }
123
+ present() {
124
+ this.startButton.hidden = this.callbacks.active();
125
+ this.startButton.disabled = false;
126
+ this.element.hidden = false;
127
+ this.focus.present({
128
+ surface: this.element,
129
+ initialFocus: () => this.needs,
130
+ fallbackFocus: this.callbacks.fallbackFocus,
131
+ onEscape: () => this.close(),
132
+ });
133
+ }
134
+ close(restore = true) {
135
+ if (this.element.hidden)
136
+ return;
137
+ this.element.hidden = true;
138
+ this.focus.dismiss(this.element, { restore });
139
+ }
140
+ destroy() {
141
+ this.close(false);
142
+ this.destroyed = true;
143
+ this.element.remove();
144
+ }
145
+ save() {
146
+ if (this.destroyed || this.element.hidden)
147
+ return;
148
+ this.draft.needs = this.needs.value;
149
+ if (this.draft.needs.length > SHOPPING_NOTES_QUESTION_MAX_LENGTH) {
150
+ this.status.textContent = this.message("shoppingNotesTooLarge");
151
+ return;
152
+ }
153
+ const result = this.store.save(this.draft);
154
+ if (!result.ok) {
155
+ this.status.textContent = this.message(result.reason === "storage_unavailable"
156
+ ? "shoppingNotesStorageError"
157
+ : result.reason === "too_large"
158
+ ? "shoppingNotesTooLarge"
159
+ : result.reason === "empty"
160
+ ? "shoppingNotesEmpty"
161
+ : "shoppingNotesInvalid");
162
+ return;
163
+ }
164
+ this.draft = result.record.draft;
165
+ this.expiresAt = result.record.expiresAt;
166
+ this.failedLaunchDraft = false;
167
+ this.status.textContent = this.message("shoppingNotesSaved");
168
+ this.callbacks.changed();
169
+ }
170
+ clear() {
171
+ if (this.destroyed || this.element.hidden)
172
+ return;
173
+ if (!this.store.clear()) {
174
+ this.status.textContent = this.message("shoppingNotesStorageError");
175
+ return;
176
+ }
177
+ this.draft = { needs: "", products: [] };
178
+ this.expiresAt = null;
179
+ this.failedLaunchDraft = false;
180
+ this.submittedQuestion = null;
181
+ this.needs.value = "";
182
+ this.renderProducts();
183
+ this.status.textContent = this.message("shoppingNotesCleared");
184
+ this.callbacks.changed();
185
+ this.needs.focus();
186
+ }
187
+ start() {
188
+ if (this.destroyed ||
189
+ this.element.hidden ||
190
+ this.submitted ||
191
+ this.callbacks.active())
192
+ return;
193
+ if (this.expiresAt !== null && Date.now() >= this.expiresAt) {
194
+ this.status.textContent = this.message("shoppingNotesExpired");
195
+ return;
196
+ }
197
+ this.draft.needs = this.needs.value;
198
+ if (this.draft.needs.length > SHOPPING_NOTES_QUESTION_MAX_LENGTH) {
199
+ this.status.textContent = this.message("shoppingNotesTooLarge");
200
+ return;
201
+ }
202
+ const result = buildShoppingNotesQuestion(this.draft);
203
+ if (!result.ok) {
204
+ this.status.textContent = this.message(result.reason === "too_long"
205
+ ? "shoppingNotesTooLarge"
206
+ : result.reason === "empty"
207
+ ? "shoppingNotesEmpty"
208
+ : "shoppingNotesInvalid");
209
+ return;
210
+ }
211
+ this.submitted = true;
212
+ this.submittedQuestion = result.initialQuestion;
213
+ this.submittedCaption = {
214
+ question: result.initialQuestion,
215
+ text: [this.draft.needs, ...this.draft.products.map(product => [
216
+ product.label || this.message("shoppingNotesItem"),
217
+ ...product.selectedOptions.map(option => `${option.name}: ${option.value}`),
218
+ ].join("\n"))].filter(Boolean).join("\n\n"),
219
+ };
220
+ this.startButton.disabled = true;
221
+ if (!this.callbacks.start(result.initialQuestion)) {
222
+ this.failedLaunchDraft = true;
223
+ this.submitted = false;
224
+ this.startButton.disabled = false;
225
+ this.status.textContent = this.message("shoppingNotesStartFailed");
226
+ return;
227
+ }
228
+ this.failedLaunchDraft = false;
229
+ this.close(false);
230
+ }
231
+ renderProducts() {
232
+ this.products.replaceChildren();
233
+ for (const product of this.draft.products) {
234
+ const item = document.createElement("li");
235
+ const label = product.label || this.message("shoppingNotesItem");
236
+ const title = document.createElement("strong");
237
+ title.textContent = label;
238
+ const options = document.createElement("span");
239
+ options.textContent = product.selectedOptions
240
+ .map((value) => `${value.name}: ${value.value}`)
241
+ .join(" · ");
242
+ const remove = document.createElement("button");
243
+ remove.type = "button";
244
+ remove.textContent = this.message("shoppingNotesRemove")
245
+ .split("{product}")
246
+ .join(label);
247
+ remove.addEventListener("click", () => {
248
+ this.draft.products = this.draft.products.filter((value) => value !== product);
249
+ this.renderProducts();
250
+ this.status.textContent = "";
251
+ this.needs.focus();
252
+ });
253
+ item.append(title, options, remove);
254
+ this.products.append(item);
255
+ }
256
+ }
257
+ button(key, action) {
258
+ const button = document.createElement("button");
259
+ button.type = "button";
260
+ button.textContent = this.message(key);
261
+ button.dataset.role = key;
262
+ button.addEventListener("click", action);
263
+ return button;
264
+ }
265
+ }
package/lib/control.d.ts CHANGED
@@ -36,6 +36,8 @@ export declare class ControlChannel {
36
36
  private readonly onClientSequence;
37
37
  private readonly onUnsafeDisconnect;
38
38
  private readonly transportRecovery?;
39
+ private readonly commerceVersion?;
40
+ private readonly commerceCartEnabled;
39
41
  private socket;
40
42
  private clientSequence;
41
43
  private serverSequence;
@@ -59,10 +61,15 @@ export declare class ControlChannel {
59
61
  private pendingConnection;
60
62
  private helloOperation;
61
63
  private fencedAuthorityConfirmed;
64
+ private commerceNegotiated;
65
+ private cartNegotiated;
62
66
  private transportRecoveryAttempted;
63
67
  private recoveringTransport;
64
- constructor(result: RuntimeAuthorization, tabId: string, clientVersion: string, onDisconnect: () => void, initialClientSequence?: number, onClientSequence?: (sequence: number) => void, onUnsafeDisconnect?: () => void, transportRecovery?: TransportRecovery | undefined);
68
+ constructor(result: RuntimeAuthorization, tabId: string, clientVersion: string, onDisconnect: () => void, initialClientSequence?: number, onClientSequence?: (sequence: number) => void, onUnsafeDisconnect?: () => void, transportRecovery?: TransportRecovery | undefined, commerceVersion?: 1 | undefined, commerceCartEnabled?: boolean);
65
69
  get leaseToken(): number;
70
+ get sessionId(): string;
71
+ get negotiatedCommerceVersion(): 1 | undefined;
72
+ get commerceCartNegotiated(): boolean;
66
73
  get lastClientSequence(): number;
67
74
  get isOpen(): boolean;
68
75
  get connectionHelloOperation(): ReservedControlOperation | null;
@@ -83,6 +90,7 @@ export declare class ControlChannel {
83
90
  startHeartbeat(seconds: number): void;
84
91
  close(code?: number, reason?: string): void;
85
92
  private handleMessage;
93
+ private requireCommerceCartNegotiation;
86
94
  private recoverFromSequenceGap;
87
95
  private notifyUnsafeDisconnect;
88
96
  private recoverTransport;