@oxvo/ai-live-assist 7.5.25 → 7.5.27
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/cjs/AiLiveAssist.d.ts +1 -1
- package/cjs/client.d.ts +7 -0
- package/cjs/client.js +12 -0
- package/cjs/commerce/cartSession.d.ts +6 -0
- package/cjs/commerce/cartSession.js +124 -21
- package/cjs/commerce/shopifyCart.d.ts +3 -1
- package/cjs/commerce/shopifyCart.js +24 -9
- package/cjs/guideMeasurement.d.ts +1 -1
- package/cjs/guideMeasurement.js +1 -1
- package/cjs/liveControlChannel.d.ts +3 -1
- package/cjs/liveControlChannel.js +4 -1
- package/cjs/liveGuideWidget.d.ts +20 -2
- package/cjs/liveGuideWidget.js +39 -8
- package/cjs/merchantPreview.d.ts +5 -0
- package/cjs/merchantPreview.js +148 -0
- package/cjs/merchantPreviewAdmission.d.ts +32 -0
- package/cjs/merchantPreviewAdmission.js +184 -0
- package/cjs/merchantPreviewOrigins.d.ts +6 -0
- package/cjs/merchantPreviewOrigins.js +24 -0
- package/cjs/merchantPreviewStorage.d.ts +9 -0
- package/cjs/merchantPreviewStorage.js +56 -0
- package/cjs/merchantPreviewTypes.d.ts +57 -0
- package/cjs/merchantPreviewTypes.js +2 -0
- package/cjs/standalone.d.ts +2 -0
- package/cjs/standalone.js +3 -1
- package/cjs/ui.d.ts +1 -0
- package/cjs/ui.js +8 -0
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/lib/AiLiveAssist.d.ts +1 -1
- package/lib/client.d.ts +7 -0
- package/lib/client.js +12 -0
- package/lib/commerce/cartSession.d.ts +6 -0
- package/lib/commerce/cartSession.js +124 -21
- package/lib/commerce/shopifyCart.d.ts +3 -1
- package/lib/commerce/shopifyCart.js +24 -9
- package/lib/guideMeasurement.d.ts +1 -1
- package/lib/guideMeasurement.js +1 -1
- package/lib/liveControlChannel.d.ts +3 -1
- package/lib/liveControlChannel.js +4 -1
- package/lib/liveGuideWidget.d.ts +20 -2
- package/lib/liveGuideWidget.js +39 -8
- package/lib/merchantPreview.d.ts +5 -0
- package/lib/merchantPreview.js +144 -0
- package/lib/merchantPreviewAdmission.d.ts +32 -0
- package/lib/merchantPreviewAdmission.js +179 -0
- package/lib/merchantPreviewOrigins.d.ts +6 -0
- package/lib/merchantPreviewOrigins.js +18 -0
- package/lib/merchantPreviewStorage.d.ts +9 -0
- package/lib/merchantPreviewStorage.js +50 -0
- package/lib/merchantPreviewTypes.d.ts +57 -0
- package/lib/merchantPreviewTypes.js +1 -0
- package/lib/standalone.d.ts +2 -0
- package/lib/standalone.js +1 -0
- package/lib/ui.d.ts +1 -0
- package/lib/ui.js +8 -0
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/package.json +1 -1
|
@@ -50,6 +50,9 @@ export declare class CartSession {
|
|
|
50
50
|
private readonly retiredRequests;
|
|
51
51
|
private recoveryOutcome;
|
|
52
52
|
private recoveryInFlight;
|
|
53
|
+
private recoveryGrant;
|
|
54
|
+
private recoveryBegin;
|
|
55
|
+
private pendingReport;
|
|
53
56
|
constructor(options: CartSessionOptions);
|
|
54
57
|
/** A catalog replaces the panel; install again after its visible receipt. */
|
|
55
58
|
refreshControls(): void;
|
|
@@ -73,7 +76,10 @@ export declare class CartSession {
|
|
|
73
76
|
private report;
|
|
74
77
|
private showRecovery;
|
|
75
78
|
private checkCart;
|
|
79
|
+
private recoveryHandle;
|
|
80
|
+
private beginRecovery;
|
|
76
81
|
private begin;
|
|
82
|
+
private awaitAdmission;
|
|
77
83
|
private ready;
|
|
78
84
|
private result;
|
|
79
85
|
private decline;
|
|
@@ -35,6 +35,11 @@ export class CartSession {
|
|
|
35
35
|
this.retiredRequests = new Set();
|
|
36
36
|
this.recoveryOutcome = null;
|
|
37
37
|
this.recoveryInFlight = null;
|
|
38
|
+
// At most one original grant, held only by this live instance. The public
|
|
39
|
+
// recovery ledger deliberately contains no mutation credentials.
|
|
40
|
+
this.recoveryGrant = null;
|
|
41
|
+
this.recoveryBegin = null;
|
|
42
|
+
this.pendingReport = null;
|
|
38
43
|
this.canAdd = (productRef, variantRef, quantity) => {
|
|
39
44
|
if (this.destroyed || this.pending || this.recoveryInFlight || !this.options.bootstrap.cartEnabled ||
|
|
40
45
|
!this.options.current() || this.hasUnresolved())
|
|
@@ -79,21 +84,40 @@ export class CartSession {
|
|
|
79
84
|
const stillCurrent = () => !this.destroyed && !this.pending && stable(this.options.current()) === stable(snapshot);
|
|
80
85
|
const work = async () => {
|
|
81
86
|
try {
|
|
82
|
-
|
|
83
|
-
const
|
|
84
|
-
const
|
|
85
|
-
const prepared =
|
|
87
|
+
let recoveryDeadline = null;
|
|
88
|
+
const executor = this.recoveryExecutor(() => stillCurrent() && (recoveryDeadline === null || Date.now() < recoveryDeadline));
|
|
89
|
+
const retained = executor.peekPending(this.recoveryScope(snapshot.sessionId));
|
|
90
|
+
const prepared = retained?.prepared;
|
|
91
|
+
let outcome = retained?.outcome;
|
|
92
|
+
if (!prepared || !outcome?.execution || !stillCurrent())
|
|
93
|
+
return;
|
|
94
|
+
const positive = outcome.receipt && (outcome.status === 'confirmed' || outcome.status === 'partial');
|
|
95
|
+
// Retained positive evidence may already be terminal on native: replay
|
|
96
|
+
// it unchanged before asking for any recovery admission or cart read.
|
|
97
|
+
let reported = positive ? await this.report(prepared, outcome, executor) : false;
|
|
98
|
+
if (!stillCurrent())
|
|
99
|
+
return;
|
|
100
|
+
if (!reported) {
|
|
101
|
+
const ready = await this.beginRecovery(snapshot, prepared, outcome.execution);
|
|
102
|
+
if (!ready || !stillCurrent() || Date.parse(ready.expiresAt) <= Date.now())
|
|
103
|
+
return;
|
|
104
|
+
recoveryDeadline = Date.parse(ready.expiresAt);
|
|
105
|
+
outcome = await executor.reconcile(prepared, outcome.execution.executionId, ready, { refreshObservation: !!positive });
|
|
106
|
+
reported = false;
|
|
107
|
+
}
|
|
108
|
+
if (!stillCurrent())
|
|
109
|
+
return;
|
|
86
110
|
if (outcome)
|
|
87
111
|
this.recoveryOutcome = outcome;
|
|
88
112
|
// Only an original public scope stored with the original executor
|
|
89
113
|
// record can report recovery. It confers no permission to POST.
|
|
90
|
-
if (
|
|
114
|
+
if (!reported && prepared && outcome && stillCurrent()) {
|
|
91
115
|
if (prepared.reportSessionId === snapshot.sessionId)
|
|
92
116
|
await this.report(prepared, outcome, executor);
|
|
93
117
|
}
|
|
94
118
|
if (prepared && outcome)
|
|
95
119
|
await refreshShopifyCartPresentation(prepared, outcome, { assertCurrent: stillCurrent }).catch(() => undefined);
|
|
96
|
-
if (
|
|
120
|
+
if (!stillCurrent())
|
|
97
121
|
return;
|
|
98
122
|
if (this.hasUnresolved())
|
|
99
123
|
this.showRecovery();
|
|
@@ -142,6 +166,9 @@ export class CartSession {
|
|
|
142
166
|
this.result(payload);
|
|
143
167
|
}
|
|
144
168
|
cut() {
|
|
169
|
+
this.recoveryGrant = null;
|
|
170
|
+
this.recoveryBegin?.resolve(null);
|
|
171
|
+
this.pendingReport?.resolve(false);
|
|
145
172
|
const pending = this.pending;
|
|
146
173
|
if (!pending)
|
|
147
174
|
return;
|
|
@@ -158,6 +185,7 @@ export class CartSession {
|
|
|
158
185
|
destroy() {
|
|
159
186
|
this.cut();
|
|
160
187
|
this.destroyed = true;
|
|
188
|
+
this.pendingReport?.resolve(false);
|
|
161
189
|
this.options.view()?.setCommerceCartActionHandler(null);
|
|
162
190
|
}
|
|
163
191
|
createPending(intentKind, requestId, snapshot, selection, quantity) {
|
|
@@ -254,6 +282,7 @@ export class CartSession {
|
|
|
254
282
|
pending.approved = true;
|
|
255
283
|
}
|
|
256
284
|
pending.grant = copy(grant);
|
|
285
|
+
this.recoveryGrant = { grant: copy(grant), snapshot: copy(pending.snapshot) };
|
|
257
286
|
pending.executing = true;
|
|
258
287
|
if (pending.timer)
|
|
259
288
|
clearTimeout(pending.timer);
|
|
@@ -298,8 +327,8 @@ export class CartSession {
|
|
|
298
327
|
await refreshShopifyCartPresentation(prepared, outcome, { assertCurrent: () => this.current(pending) }).catch(() => undefined);
|
|
299
328
|
this.finish(pending);
|
|
300
329
|
}
|
|
301
|
-
recoveryExecutor() {
|
|
302
|
-
return new ShopifyCartExecutor({ assertCurrent
|
|
330
|
+
recoveryExecutor(assertCurrent = () => !this.destroyed && this.options.current() !== null) {
|
|
331
|
+
return new ShopifyCartExecutor({ assertCurrent,
|
|
303
332
|
beginExecution: async () => { throw new Error('Cart recovery cannot admit a new write.'); } });
|
|
304
333
|
}
|
|
305
334
|
hasUnresolved() {
|
|
@@ -315,17 +344,37 @@ export class CartSession {
|
|
|
315
344
|
...(sessionId ? { sessionId } : {}) };
|
|
316
345
|
}
|
|
317
346
|
async report(prepared, outcome, executor) {
|
|
318
|
-
if (!prepared.reportScope || !prepared.reportSessionId || !outcome.execution ||
|
|
347
|
+
if (this.destroyed || !prepared.reportScope || !prepared.reportSessionId || !outcome.execution ||
|
|
319
348
|
prepared.reportScope.operationId !== prepared.operationId || prepared.guideId !== this.options.bootstrap.guideId ||
|
|
320
349
|
stable(prepared.store) !== stable(this.options.bootstrap.store))
|
|
321
|
-
return;
|
|
350
|
+
return false;
|
|
322
351
|
const transportSessionId = this.options.transportSessionId ? this.options.transportSessionId() :
|
|
323
352
|
this.options.current()?.sessionId ?? prepared.reportSessionId;
|
|
324
353
|
if (transportSessionId !== prepared.reportSessionId)
|
|
325
|
-
return;
|
|
354
|
+
return false;
|
|
326
355
|
const report = { ...scopeOf(prepared.reportScope), ...outcome.execution };
|
|
327
|
-
|
|
328
|
-
|
|
356
|
+
let resolve;
|
|
357
|
+
const response = new Promise(done => { resolve = done; });
|
|
358
|
+
const pending = { report, resolve };
|
|
359
|
+
this.pendingReport = pending;
|
|
360
|
+
try {
|
|
361
|
+
const [delivered, accepted] = await Promise.all([
|
|
362
|
+
this.send('commerce.cart.execution.result', report), this.boundedAccepted(response, 10000),
|
|
363
|
+
]);
|
|
364
|
+
const currentSessionId = this.options.transportSessionId ? this.options.transportSessionId() :
|
|
365
|
+
this.options.current()?.sessionId ?? prepared.reportSessionId;
|
|
366
|
+
if (!delivered || !accepted || this.destroyed || currentSessionId !== prepared.reportSessionId)
|
|
367
|
+
return false;
|
|
368
|
+
const acknowledged = executor.acknowledgeReport(this.recoveryScope(prepared.reportSessionId), report);
|
|
369
|
+
if (acknowledged && this.recoveryGrant?.grant.operationId === prepared.operationId)
|
|
370
|
+
this.recoveryGrant = null;
|
|
371
|
+
// Native acceptance and durable local acknowledgement are separate. A
|
|
372
|
+
// storage failure must retain local debt, not reopen a settled operation.
|
|
373
|
+
return true;
|
|
374
|
+
}
|
|
375
|
+
finally {
|
|
376
|
+
if (this.pendingReport === pending)
|
|
377
|
+
this.pendingReport = null;
|
|
329
378
|
}
|
|
330
379
|
}
|
|
331
380
|
showRecovery() {
|
|
@@ -340,10 +389,43 @@ export class CartSession {
|
|
|
340
389
|
? { ...retained.outcome, local: local.local } : retained.outcome;
|
|
341
390
|
}
|
|
342
391
|
const outcome = this.recoveryOutcome ?? failure('transport', true);
|
|
343
|
-
//
|
|
344
|
-
//
|
|
392
|
+
// Retain uncertain evidence without offering a no-op Check after the
|
|
393
|
+
// original instance/authority needed to reconcile it is gone.
|
|
345
394
|
const observed = outcome.receipt && (outcome.status === 'confirmed' || outcome.status === 'partial');
|
|
346
|
-
|
|
395
|
+
const current = this.options.current();
|
|
396
|
+
const prepared = retained?.prepared;
|
|
397
|
+
const canRecover = current && prepared && prepared.reportSessionId === current.sessionId &&
|
|
398
|
+
(observed && prepared.reportScope || this.recoveryHandle(current, prepared));
|
|
399
|
+
this.options.view()?.setCommerceCartStatus(observed ? outcome : { ...outcome, status: 'uncertain' }, this.cartUrl(), canRecover ? this.checkCart : undefined);
|
|
400
|
+
}
|
|
401
|
+
recoveryHandle(snapshot, prepared) {
|
|
402
|
+
const retained = this.recoveryGrant;
|
|
403
|
+
if (!retained || stable(retained.snapshot) !== stable(snapshot) || prepared.reportSessionId !== snapshot.sessionId ||
|
|
404
|
+
!prepared.reportScope || stable(prepared.reportScope) !== stable(scopeOf(retained.grant)) ||
|
|
405
|
+
prepared.operationId !== retained.grant.operationId)
|
|
406
|
+
return null;
|
|
407
|
+
return retained;
|
|
408
|
+
}
|
|
409
|
+
async beginRecovery(snapshot, prepared, execution) {
|
|
410
|
+
const retained = this.recoveryHandle(snapshot, prepared);
|
|
411
|
+
if (!retained)
|
|
412
|
+
return null;
|
|
413
|
+
let resolve;
|
|
414
|
+
const response = new Promise(done => { resolve = done; });
|
|
415
|
+
const begin = { messageId: null, executionId: execution.executionId, cartDigest: execution.cartDigest,
|
|
416
|
+
ready: null, resolve, operationId: prepared.operationId };
|
|
417
|
+
this.recoveryBegin = begin;
|
|
418
|
+
try {
|
|
419
|
+
return await this.awaitAdmission(begin, response, { schemaVersion: 1, operationId: prepared.operationId,
|
|
420
|
+
grant: retained.grant.grant, executionId: execution.executionId, cartDigest: execution.cartDigest });
|
|
421
|
+
}
|
|
422
|
+
catch {
|
|
423
|
+
return null;
|
|
424
|
+
}
|
|
425
|
+
finally {
|
|
426
|
+
if (this.recoveryBegin === begin)
|
|
427
|
+
this.recoveryBegin = null;
|
|
428
|
+
}
|
|
347
429
|
}
|
|
348
430
|
async begin(pending, executionId, cartDigest) {
|
|
349
431
|
if (!pending.grant || !this.current(pending))
|
|
@@ -352,19 +434,22 @@ export class CartSession {
|
|
|
352
434
|
const ready = new Promise(done => { resolve = done; });
|
|
353
435
|
pending.begin = { messageId: null, executionId, cartDigest, ready: null, resolve };
|
|
354
436
|
pending.started = true;
|
|
437
|
+
return this.awaitAdmission(pending.begin, ready, { schemaVersion: 1,
|
|
438
|
+
operationId: pending.grant.operationId, grant: pending.grant.grant, executionId, cartDigest });
|
|
439
|
+
}
|
|
440
|
+
async awaitAdmission(begin, ready, payload) {
|
|
355
441
|
let delivery;
|
|
356
442
|
try {
|
|
357
|
-
delivery = this.options.send('commerce.cart.execution.begin',
|
|
358
|
-
|
|
359
|
-
pending.begin.messageId = delivery.messageId;
|
|
443
|
+
delivery = this.options.send('commerce.cart.execution.begin', payload);
|
|
444
|
+
begin.messageId = delivery.messageId;
|
|
360
445
|
}
|
|
361
446
|
catch {
|
|
362
|
-
|
|
447
|
+
begin.resolve(null);
|
|
363
448
|
throw new Error('The cart admission could not be sent.');
|
|
364
449
|
}
|
|
365
450
|
// Admission can race expiry. A fresh already_started reply has its own
|
|
366
451
|
// short recovery window and can only lead to read-only reconciliation.
|
|
367
|
-
const timeout = setTimeout(() => resolve(null), 10000);
|
|
452
|
+
const timeout = setTimeout(() => begin.resolve(null), 10000);
|
|
368
453
|
try {
|
|
369
454
|
const [accepted, observed] = await Promise.all([this.boundedAccepted(delivery.accepted, 10000), ready]);
|
|
370
455
|
if (!accepted || !observed)
|
|
@@ -376,6 +461,16 @@ export class CartSession {
|
|
|
376
461
|
}
|
|
377
462
|
}
|
|
378
463
|
ready(payload) {
|
|
464
|
+
const recovery = this.recoveryBegin;
|
|
465
|
+
if (recovery?.messageId && !recovery.ready) {
|
|
466
|
+
const ready = parseCommerceCartExecutionReady(payload, { operationId: recovery.operationId,
|
|
467
|
+
requestMessageId: recovery.messageId, executionId: recovery.executionId, cartDigest: recovery.cartDigest });
|
|
468
|
+
if (ready?.state === 'already_started') {
|
|
469
|
+
recovery.ready = copy(ready);
|
|
470
|
+
recovery.resolve(ready);
|
|
471
|
+
}
|
|
472
|
+
return;
|
|
473
|
+
}
|
|
379
474
|
const pending = this.pending;
|
|
380
475
|
const begin = pending?.begin;
|
|
381
476
|
if (!pending?.grant || !begin?.messageId || begin.ready)
|
|
@@ -388,6 +483,14 @@ export class CartSession {
|
|
|
388
483
|
begin.resolve(ready);
|
|
389
484
|
}
|
|
390
485
|
result(payload) {
|
|
486
|
+
const waiting = this.pendingReport;
|
|
487
|
+
if (waiting) {
|
|
488
|
+
const result = parseCommerceCartResult(payload, { requestId: waiting.report.requestId,
|
|
489
|
+
operationId: waiting.report.operationId, executionId: waiting.report.executionId });
|
|
490
|
+
if (result)
|
|
491
|
+
waiting.resolve((result.status === 'observed' || result.status === 'partial') &&
|
|
492
|
+
stable(result.observation) === stable(waiting.report.observation));
|
|
493
|
+
}
|
|
391
494
|
const pending = this.pending;
|
|
392
495
|
if (!pending)
|
|
393
496
|
return;
|
|
@@ -114,7 +114,9 @@ export declare class ShopifyCartExecutor {
|
|
|
114
114
|
reconcilePending(scope: ShopifyCartRecoveryScope): Promise<ShopifyCartRecovery>;
|
|
115
115
|
execute(input: PreparedShopifyCartAddition, executionId: string): Promise<ShopifyCartOutcome>;
|
|
116
116
|
/** Read-only even after expiry/cut. recoveredReady must come from the trusted native ACK/ready path. */
|
|
117
|
-
reconcile(input: PreparedShopifyCartAddition, executionId: string, recoveredReady?: ShopifyCartExecutionReady
|
|
117
|
+
reconcile(input: PreparedShopifyCartAddition, executionId: string, recoveredReady?: ShopifyCartExecutionReady, options?: {
|
|
118
|
+
refreshObservation?: boolean;
|
|
119
|
+
}): Promise<ShopifyCartOutcome>;
|
|
118
120
|
/** Ajax change.js sets an absolute quantity and offers no conditional delta/CAS.
|
|
119
121
|
* A read then change can overwrite the shopper's concurrent edit even by line key.
|
|
120
122
|
* https://shopify.dev/docs/api/ajax/reference/cart#post-locale-cart-change-js
|
|
@@ -925,7 +925,7 @@ export class ShopifyCartExecutor {
|
|
|
925
925
|
return this.observe(prepared, evidence({ ...original, request: requestOutcome }));
|
|
926
926
|
}
|
|
927
927
|
/** Read-only even after expiry/cut. recoveredReady must come from the trusted native ACK/ready path. */
|
|
928
|
-
async reconcile(input, executionId, recoveredReady) {
|
|
928
|
+
async reconcile(input, executionId, recoveredReady, options = {}) {
|
|
929
929
|
let prepared;
|
|
930
930
|
try {
|
|
931
931
|
const text = JSON.stringify(input);
|
|
@@ -934,9 +934,11 @@ export class ShopifyCartExecutor {
|
|
|
934
934
|
prepared = JSON.parse(text);
|
|
935
935
|
if (!commerceUuid(executionId) || !validPrepared(prepared))
|
|
936
936
|
return result("unavailable", "invalid_request");
|
|
937
|
-
if (recoveredReady
|
|
938
|
-
(
|
|
939
|
-
|
|
937
|
+
if ((options.refreshObservation && (!recoveredReady || recoveredReady.executionId !== executionId ||
|
|
938
|
+
Date.parse(recoveredReady.expiresAt) <= Date.now())) ||
|
|
939
|
+
recoveredReady &&
|
|
940
|
+
(!validReady(recoveredReady) ||
|
|
941
|
+
recoveredReady.state !== "already_started"))
|
|
940
942
|
return result("uncertain", "grant_unavailable");
|
|
941
943
|
const digest = await sha(intent(prepared));
|
|
942
944
|
let started;
|
|
@@ -973,7 +975,9 @@ export class ShopifyCartExecutor {
|
|
|
973
975
|
/* Read-only recovery remains valid; unavailable storage still disables new effects. */
|
|
974
976
|
}
|
|
975
977
|
}
|
|
976
|
-
|
|
978
|
+
// Exact terminal report replay remains the default. Only a fresh,
|
|
979
|
+
// correlated already_started admission may request a new observation.
|
|
980
|
+
if (started?.resolved && started.prepared?.reportScope && !options.refreshObservation)
|
|
977
981
|
return retainedOutcome(prepared, started);
|
|
978
982
|
const execution = started
|
|
979
983
|
? evidence(started)
|
|
@@ -984,7 +988,7 @@ export class ShopifyCartExecutor {
|
|
|
984
988
|
request: null,
|
|
985
989
|
})
|
|
986
990
|
: null;
|
|
987
|
-
return this.observe(prepared, execution);
|
|
991
|
+
return this.observe(prepared, execution, options.refreshObservation === true);
|
|
988
992
|
}
|
|
989
993
|
catch {
|
|
990
994
|
return result("uncertain", "invalid_request");
|
|
@@ -1009,7 +1013,7 @@ export class ShopifyCartExecutor {
|
|
|
1009
1013
|
return false;
|
|
1010
1014
|
}
|
|
1011
1015
|
}
|
|
1012
|
-
async observe(prepared, execution) {
|
|
1016
|
+
async observe(prepared, execution, refreshUnacceptedObservation = false) {
|
|
1013
1017
|
const paths = route(prepared, false);
|
|
1014
1018
|
if (!paths)
|
|
1015
1019
|
return { ...result("uncertain", "context_changed"), execution };
|
|
@@ -1125,6 +1129,7 @@ export class ShopifyCartExecutor {
|
|
|
1125
1129
|
}
|
|
1126
1130
|
: null;
|
|
1127
1131
|
if (execution && observation && observation.quantity > 0) {
|
|
1132
|
+
let durablyRetained = false;
|
|
1128
1133
|
try {
|
|
1129
1134
|
const key = ledgerKey(prepared);
|
|
1130
1135
|
const entries = readLedger(key);
|
|
@@ -1134,7 +1139,10 @@ export class ShopifyCartExecutor {
|
|
|
1134
1139
|
cartDigest: execution.cartDigest,
|
|
1135
1140
|
intentDigest: intentDigest,
|
|
1136
1141
|
}));
|
|
1137
|
-
if (entry &&
|
|
1142
|
+
if (entry?.resolved && entry.prepared?.reportScope &&
|
|
1143
|
+
(!refreshUnacceptedObservation || entry.reportAccepted))
|
|
1144
|
+
return retainedOutcome(prepared, entry);
|
|
1145
|
+
if (entry && (!entry.resolved || (refreshUnacceptedObservation && !entry.reportAccepted))) {
|
|
1138
1146
|
entry.prepared ?? (entry.prepared = publicPrepared(prepared));
|
|
1139
1147
|
entry.request ?? (entry.request = execution.request);
|
|
1140
1148
|
entry.observation = observation;
|
|
@@ -1142,11 +1150,18 @@ export class ShopifyCartExecutor {
|
|
|
1142
1150
|
if (entry.initialCartEmpty === true)
|
|
1143
1151
|
entry.materializedCartDigest = cartDigest;
|
|
1144
1152
|
saveLedger(key, entries);
|
|
1153
|
+
durablyRetained = true;
|
|
1145
1154
|
}
|
|
1146
1155
|
}
|
|
1147
1156
|
catch {
|
|
1148
|
-
/*
|
|
1157
|
+
/* Retain the pending guard when storage cannot keep the observation. */
|
|
1149
1158
|
}
|
|
1159
|
+
// Every positive native report, including the first observation after
|
|
1160
|
+
// Add or an unknown result, must be replayable after native settles it.
|
|
1161
|
+
// Keep local cart truth but withhold undurable evidence from transport.
|
|
1162
|
+
if (prepared.reportScope && !durablyRetained)
|
|
1163
|
+
return { status, reason: "storage_unavailable", canUndo: false,
|
|
1164
|
+
receipt, execution: null, local: { itemCount: cart.itemCount } };
|
|
1150
1165
|
}
|
|
1151
1166
|
if (!execution) {
|
|
1152
1167
|
status = "uncertain";
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
|
|
2
|
-
export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.
|
|
2
|
+
export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.27";
|
|
3
3
|
export declare function isGuideMeasurementIntent(value: unknown): value is GuideMeasurementIntent;
|
|
4
4
|
/** The managed analytics owner supplies possession; this check grants no authority. */
|
|
5
5
|
export declare function currentGuideMeasurementBridge(value: unknown): value is GuideMeasurementBridge;
|
package/lib/guideMeasurement.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import { type MerchantPreviewRuntimePolicy } from './merchantPreviewOrigins.js';
|
|
1
2
|
import { type LiveDuplexMediaOptions, type LiveDuplexMediaDependencies } from './liveDuplexMedia.js';
|
|
2
3
|
import { type CommerceBootstrap, type CommerceContext, type CommerceCartSelection, type CommerceProduct, type CommerceContextClear, type LiveCommerceCatalog, type LiveCommerceDisplayed } from './commerce/contracts.js';
|
|
3
|
-
export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.
|
|
4
|
+
export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.27";
|
|
4
5
|
export declare const LIVE_CONTROL_CLIENT_CAPABILITIES: readonly ["live_duplex_v1", "live_local_wake_v1", "live_fragment_captions_v1"];
|
|
5
6
|
declare const phases: readonly ["voice_off", "local_listening", "wake_buffering", "starting", "active", "tentative_idle", "closing", "uncertain", "muted", "suspended", "budget_blocked", "ended"];
|
|
6
7
|
export type LiveControlState = {
|
|
@@ -41,6 +42,7 @@ export interface LiveControlChannelOptions {
|
|
|
41
42
|
tabId: string;
|
|
42
43
|
media: MediaOptions;
|
|
43
44
|
clock?: LiveControlClock;
|
|
45
|
+
previewRuntimePolicy?: MerchantPreviewRuntimePolicy;
|
|
44
46
|
createWebSocket?: (url: string, protocols: string[]) => WebSocket;
|
|
45
47
|
randomUUID?: () => string;
|
|
46
48
|
onState(state: LiveControlState): void;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { isPreviewRuntimeOrigin } from './merchantPreviewOrigins.js';
|
|
1
2
|
import { LiveDuplexMedia } from './liveDuplexMedia.js';
|
|
2
3
|
import { VERSION } from './version.js';
|
|
3
4
|
import { parseLiveCommerceCatalog, displayedCommerceProducts, isDisplayedCommerceProducts, commerceCartSelection, liveCommerceDisplayedReceipt } from './commerce/contracts.js';
|
|
@@ -91,7 +92,9 @@ export class LiveControlChannel {
|
|
|
91
92
|
if (!['https:', 'http:'].includes(trusted.protocol) || trusted.origin !== options.trustedRuntimeOrigin ||
|
|
92
93
|
trusted.username || trusted.password || target.username || target.password || target.search || target.hash || target.pathname !== path ||
|
|
93
94
|
target.protocol !== (trusted.protocol === 'https:' ? 'wss:' : 'ws:') || target.host !== trusted.host ||
|
|
94
|
-
(trusted.protocol === 'http:' && !
|
|
95
|
+
(trusted.protocol === 'http:' && !(options.previewRuntimePolicy
|
|
96
|
+
? isPreviewRuntimeOrigin(trusted, options.previewRuntimePolicy)
|
|
97
|
+
: ['localhost', '127.0.0.1', '[::1]'].includes(trusted.hostname))))
|
|
95
98
|
throw unavailable();
|
|
96
99
|
target.searchParams.set('session', String(value.sessionId));
|
|
97
100
|
this.url = target.href;
|
package/lib/liveGuideWidget.d.ts
CHANGED
|
@@ -2,19 +2,37 @@ import { WidgetView, type WidgetViewOptions } from './ui.js';
|
|
|
2
2
|
import type { AiGuideControllerState, AiGuideOpenInput, BootstrapConfig, PluginOptions } from './types.js';
|
|
3
3
|
import type { GuideAdmission } from './guideAdmission.js';
|
|
4
4
|
import { RuntimeClient } from './client.js';
|
|
5
|
+
import { type LiveGuideLaunchIntent } from './liveGuideAdmission.js';
|
|
6
|
+
import { type LiveControlChannelOptions, type LiveControlAuthorization } from './liveControlChannel.js';
|
|
7
|
+
export type LiveGuideStartIntent = Omit<LiveGuideLaunchIntent, 'installKey' | 'guideMeasurement'>;
|
|
8
|
+
export type LiveGuideSessionAdmission = {
|
|
9
|
+
readonly recoveryOnly?: boolean;
|
|
10
|
+
readonly endMessage?: string;
|
|
11
|
+
canStart?(): boolean;
|
|
12
|
+
hasPendingLaunch(): boolean;
|
|
13
|
+
pendingLaunchId(): string | null;
|
|
14
|
+
launch(intent: LiveGuideStartIntent, signal: AbortSignal): Promise<LiveControlAuthorization>;
|
|
15
|
+
end(signal?: AbortSignal, expectedLaunchRequestId?: string): Promise<void>;
|
|
16
|
+
};
|
|
5
17
|
type Options = {
|
|
6
18
|
bootstrap: BootstrapConfig;
|
|
7
|
-
admission: GuideAdmission;
|
|
8
19
|
runtime: RuntimeClient;
|
|
9
20
|
tabId: string;
|
|
10
21
|
locale: string;
|
|
22
|
+
previewRuntimePolicy?: LiveControlChannelOptions['previewRuntimePolicy'];
|
|
11
23
|
messages: PluginOptions['messages'];
|
|
12
24
|
viewOptions: WidgetViewOptions;
|
|
13
25
|
acquire(): boolean;
|
|
14
26
|
ownsActivity?(): boolean;
|
|
15
27
|
release(): void;
|
|
16
28
|
onState(): void;
|
|
17
|
-
}
|
|
29
|
+
} & ({
|
|
30
|
+
admission: GuideAdmission;
|
|
31
|
+
sessionAdmission?: never;
|
|
32
|
+
} | {
|
|
33
|
+
sessionAdmission: LiveGuideSessionAdmission;
|
|
34
|
+
admission?: never;
|
|
35
|
+
});
|
|
18
36
|
/** Actual widget protocol branch. Reuses WidgetView, visitor possession storage,
|
|
19
37
|
* local detector/media and authenticated runtime; never constructs a Realtime
|
|
20
38
|
* transport or grants model/provider authority on the browser's behalf. */
|
package/lib/liveGuideWidget.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { WidgetView } from './ui.js';
|
|
2
|
+
import { RuntimeClientError } from './client.js';
|
|
2
3
|
import { LiveGuideAdmission } from './liveGuideAdmission.js';
|
|
3
4
|
import { LiveControlChannel, LIVE_CONTROL_CLIENT_VERSION, LIVE_CONTROL_CLIENT_CAPABILITIES } from './liveControlChannel.js';
|
|
4
5
|
import { createLiveBrowserDetector, validateLiveBrowserAssets } from './liveBrowserDetector.js';
|
|
@@ -59,10 +60,21 @@ export class LiveGuideWidget {
|
|
|
59
60
|
JSON.stringify(config.liveCapabilities) !== JSON.stringify(LIVE_CONTROL_CLIENT_CAPABILITIES))
|
|
60
61
|
throw new Error('AI Guide Live is unavailable.');
|
|
61
62
|
validateLiveBrowserAssets(config.liveAssets);
|
|
62
|
-
|
|
63
|
+
if (options.sessionAdmission)
|
|
64
|
+
this.admission = options.sessionAdmission;
|
|
65
|
+
else {
|
|
66
|
+
const publicAdmission = options.admission;
|
|
67
|
+
const live = new LiveGuideAdmission(publicAdmission.identity, publicAdmission.store, options.runtime, publicAdmission);
|
|
68
|
+
this.admission = {
|
|
69
|
+
hasPendingLaunch: () => live.hasPendingLaunch(),
|
|
70
|
+
pendingLaunchId: () => live.pendingLaunchId(),
|
|
71
|
+
launch: (intent, signal) => live.launch({ ...intent, installKey: publicAdmission.identity.installKey }, signal),
|
|
72
|
+
end: (signal, expectedLaunchRequestId) => live.end(signal, expectedLaunchRequestId),
|
|
73
|
+
};
|
|
74
|
+
}
|
|
63
75
|
const callbacks = {
|
|
64
76
|
onStart: (mode, scopes, question) => this.start(mode, scopes, question),
|
|
65
|
-
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch(),
|
|
77
|
+
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch() && this.admission.canStart?.() !== false,
|
|
66
78
|
onEnd: () => { void this.end().catch(() => undefined); },
|
|
67
79
|
onMute: muted => { if (muted)
|
|
68
80
|
this.privacy('mute');
|
|
@@ -125,6 +137,10 @@ export class LiveGuideWidget {
|
|
|
125
137
|
void this.end().catch(() => undefined);
|
|
126
138
|
}
|
|
127
139
|
}
|
|
140
|
+
else if (this.admission.recoveryOnly) {
|
|
141
|
+
this.phase = 'ended';
|
|
142
|
+
this.view.showLaunchUnavailable(this.admission.endMessage ?? this.view.message('ended'));
|
|
143
|
+
}
|
|
128
144
|
// Capture runs before TabActivityLock releases cross-tab ownership.
|
|
129
145
|
window.addEventListener('pagehide', this.pagehide, true);
|
|
130
146
|
window.addEventListener('focus', this.refreshOwnership);
|
|
@@ -157,7 +173,7 @@ export class LiveGuideWidget {
|
|
|
157
173
|
companion: false, pendingQuestion: this.pendingQuestions.length > 0 };
|
|
158
174
|
}
|
|
159
175
|
start(mode, scopes, question) {
|
|
160
|
-
if (this.destroyed || this.starting || this.active || this.ending ||
|
|
176
|
+
if (this.destroyed || this.starting || this.active || this.ending || this.admission.canStart?.() === false ||
|
|
161
177
|
(question && (!question.trim() || question.length > 4000)) || !this.acquireLock())
|
|
162
178
|
return false;
|
|
163
179
|
// Recover abandoned intent only after acquiring the actual activity lock;
|
|
@@ -175,7 +191,7 @@ export class LiveGuideWidget {
|
|
|
175
191
|
this.operation = operation;
|
|
176
192
|
const timeout = setTimeout(() => operation.abort(), 20000);
|
|
177
193
|
const config = this.options.bootstrap;
|
|
178
|
-
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
194
|
+
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
179
195
|
launchRequestId: crypto.randomUUID(), clientVersion: LIVE_CONTROL_CLIENT_VERSION, liveCapabilities: LIVE_CONTROL_CLIENT_CAPABILITIES,
|
|
180
196
|
configRevision: config.configRevision, path: location.pathname, tabId: this.options.tabId, mode, experienceMode: 'standard',
|
|
181
197
|
consent: { disclosureChecksum: config.consent.disclosureChecksum, scopes: [...scopes], locale: this.options.locale },
|
|
@@ -195,6 +211,7 @@ export class LiveGuideWidget {
|
|
|
195
211
|
throw new Error('Cancelled.');
|
|
196
212
|
const audio = this.view.livePlaybackElement();
|
|
197
213
|
const channel = new LiveControlChannel({ authorization, trustedRuntimeOrigin: new URL(this.options.runtime.baseUrl).origin,
|
|
214
|
+
...(this.options.previewRuntimePolicy ? { previewRuntimePolicy: this.options.previewRuntimePolicy } : {}),
|
|
198
215
|
tabId: this.options.tabId, onState: state => this.onControlState(state),
|
|
199
216
|
onClose: reason => {
|
|
200
217
|
if (this.channel === channel && !this.ending && !this.destroyed) {
|
|
@@ -577,11 +594,25 @@ export class LiveGuideWidget {
|
|
|
577
594
|
this.ownedLaunchId = null;
|
|
578
595
|
this.phase = 'ended';
|
|
579
596
|
this.releaseLock();
|
|
580
|
-
if (!this.destroyed)
|
|
581
|
-
this.
|
|
597
|
+
if (!this.destroyed) {
|
|
598
|
+
if (this.admission.endMessage)
|
|
599
|
+
this.view.showLaunchUnavailable(this.admission.endMessage);
|
|
600
|
+
else
|
|
601
|
+
this.view.showResumeStopped();
|
|
602
|
+
}
|
|
603
|
+
this.options.onState();
|
|
604
|
+
}).catch(error => {
|
|
605
|
+
this.phase = 'error';
|
|
606
|
+
if (!this.destroyed) {
|
|
607
|
+
if (this.admission.recoveryOnly && error instanceof RuntimeClientError && error.code === 'MERCHANT_PREVIEW_END_UNRESOLVED') {
|
|
608
|
+
this.view.showLaunchUnavailable(error.message);
|
|
609
|
+
}
|
|
610
|
+
else
|
|
611
|
+
this.view.showError(this.view.message('error'), true);
|
|
612
|
+
}
|
|
582
613
|
this.options.onState();
|
|
583
|
-
|
|
584
|
-
|
|
614
|
+
throw error;
|
|
615
|
+
})
|
|
585
616
|
.finally(() => { if (this.ending === pending)
|
|
586
617
|
this.ending = null; });
|
|
587
618
|
this.ending = pending;
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import { type AiGuideController } from './guideTypes.js';
|
|
2
|
+
import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
3
|
+
export type { MerchantPreviewOptions } from './merchantPreviewTypes.js';
|
|
4
|
+
export declare function validateMerchantPreviewBootstrap(value: MerchantPreviewBootstrap, preview: MerchantPreviewOptions): MerchantPreviewBootstrap;
|
|
5
|
+
export declare function installMerchantGuidePreview(input: MerchantPreviewOptions): Promise<AiGuideController>;
|