@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
package/cjs/AiLiveAssist.d.ts
CHANGED
|
@@ -34,7 +34,7 @@ export declare const normalizeAiGuideOpenInput: (input?: AiGuideOpenInput) => Re
|
|
|
34
34
|
export declare const resolveAiGuideProtocolVersion: (bootstrap: Pick<BootstrapConfig, "experienceMode" | "minimumProtocolVersion" | "protocol">) => 1 | 2;
|
|
35
35
|
export default class AiLiveAssist {
|
|
36
36
|
private readonly options;
|
|
37
|
-
readonly version = "7.5.
|
|
37
|
+
readonly version = "7.5.27";
|
|
38
38
|
private readonly host;
|
|
39
39
|
private readonly guideAdmission;
|
|
40
40
|
private readonly standaloneAdmissionPending;
|
package/cjs/client.d.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type { AssistMode, AiGuideCompanionState, BootstrapConfig, ConsentScope,
|
|
|
2
2
|
import { type GuideAdmissionResult, type GuideLaunchIntent, type GuideLaunchRecoveryInput, type GuideLaunchRecoveryResult, type GuideLaunchResult, type GuideRecordingLinkInput, type GuideRecordingLinkResult, type GuideMeasurementBridge } from "./guideTypes.js";
|
|
3
3
|
import type { LiveControlAuthorization } from "./liveControlChannel.js";
|
|
4
4
|
import type { LiveGuideLaunchIntent } from "./liveGuideAdmission.js";
|
|
5
|
+
import type { MerchantPreviewBootstrapInput, MerchantPreviewBootstrap, MerchantPreviewLaunchIntent, MerchantPreviewAdmissionResult, MerchantPreviewEndInput, MerchantPreviewEndResult } from './merchantPreviewTypes.js';
|
|
5
6
|
export declare class RuntimeClientError extends Error {
|
|
6
7
|
readonly code: string;
|
|
7
8
|
readonly retryable: boolean;
|
|
@@ -104,6 +105,12 @@ export declare class RuntimeClient {
|
|
|
104
105
|
status: "end_requested";
|
|
105
106
|
launchRequestId: string;
|
|
106
107
|
}>;
|
|
108
|
+
bootstrapMerchantPreview(input: MerchantPreviewBootstrapInput, signal: AbortSignal): Promise<MerchantPreviewBootstrap>;
|
|
109
|
+
admitMerchantPreview(intent: MerchantPreviewLaunchIntent, previewGrant: string, subjectCredential: string | undefined, signal?: AbortSignal): Promise<MerchantPreviewAdmissionResult>;
|
|
110
|
+
launchMerchantPreview(intent: MerchantPreviewLaunchIntent, admissionGrant: string, signal: AbortSignal): Promise<LiveControlAuthorization & {
|
|
111
|
+
previewId: string;
|
|
112
|
+
}>;
|
|
113
|
+
endMerchantPreview(input: MerchantPreviewEndInput, signal?: AbortSignal): Promise<MerchantPreviewEndResult>;
|
|
107
114
|
launchGuide(intent: GuideLaunchIntent, admissionGrant: string, signal: AbortSignal, measurementBridge?: GuideMeasurementBridge): Promise<GuideLaunchResult>;
|
|
108
115
|
recoverGuideLaunch(input: GuideLaunchRecoveryInput, signal?: AbortSignal, keepalive?: boolean): Promise<GuideLaunchRecoveryResult>;
|
|
109
116
|
linkGuideRecording(sessionId: string, input: GuideRecordingLinkInput, signal: AbortSignal): Promise<GuideRecordingLinkResult>;
|
package/cjs/client.js
CHANGED
|
@@ -196,6 +196,18 @@ class RuntimeClient {
|
|
|
196
196
|
async endLiveGuide(input, signal) {
|
|
197
197
|
return this.postJson("/ai-live-assist/v1/public/live/launches/end", input, {}, signal, true);
|
|
198
198
|
}
|
|
199
|
+
async bootstrapMerchantPreview(input, signal) {
|
|
200
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/bootstrap', JSON.stringify(input), {}, signal, false, false, true);
|
|
201
|
+
}
|
|
202
|
+
async admitMerchantPreview(intent, previewGrant, subjectCredential, signal) {
|
|
203
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/admissions', JSON.stringify({ ...intent, previewGrant, ...(subjectCredential ? { subjectCredential } : {}) }), {}, signal, false, false, true);
|
|
204
|
+
}
|
|
205
|
+
async launchMerchantPreview(intent, admissionGrant, signal) {
|
|
206
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launch', JSON.stringify({ ...intent, admissionGrant }), { 'Idempotency-Key': intent.launchRequestId }, signal, false, false, true);
|
|
207
|
+
}
|
|
208
|
+
async endMerchantPreview(input, signal) {
|
|
209
|
+
return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launches/end', JSON.stringify(input), {}, signal, true, false, true);
|
|
210
|
+
}
|
|
199
211
|
async launchGuide(intent, admissionGrant, signal, measurementBridge) {
|
|
200
212
|
return this.postGuideLaunch("/ai-live-assist/v1/public/launch", intent, admissionGrant, signal, measurementBridge);
|
|
201
213
|
}
|
|
@@ -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;
|
|
@@ -38,6 +38,11 @@ class CartSession {
|
|
|
38
38
|
this.retiredRequests = new Set();
|
|
39
39
|
this.recoveryOutcome = null;
|
|
40
40
|
this.recoveryInFlight = null;
|
|
41
|
+
// At most one original grant, held only by this live instance. The public
|
|
42
|
+
// recovery ledger deliberately contains no mutation credentials.
|
|
43
|
+
this.recoveryGrant = null;
|
|
44
|
+
this.recoveryBegin = null;
|
|
45
|
+
this.pendingReport = null;
|
|
41
46
|
this.canAdd = (productRef, variantRef, quantity) => {
|
|
42
47
|
if (this.destroyed || this.pending || this.recoveryInFlight || !this.options.bootstrap.cartEnabled ||
|
|
43
48
|
!this.options.current() || this.hasUnresolved())
|
|
@@ -82,21 +87,40 @@ class CartSession {
|
|
|
82
87
|
const stillCurrent = () => !this.destroyed && !this.pending && stable(this.options.current()) === stable(snapshot);
|
|
83
88
|
const work = async () => {
|
|
84
89
|
try {
|
|
85
|
-
|
|
86
|
-
const
|
|
87
|
-
const
|
|
88
|
-
const prepared =
|
|
90
|
+
let recoveryDeadline = null;
|
|
91
|
+
const executor = this.recoveryExecutor(() => stillCurrent() && (recoveryDeadline === null || Date.now() < recoveryDeadline));
|
|
92
|
+
const retained = executor.peekPending(this.recoveryScope(snapshot.sessionId));
|
|
93
|
+
const prepared = retained?.prepared;
|
|
94
|
+
let outcome = retained?.outcome;
|
|
95
|
+
if (!prepared || !outcome?.execution || !stillCurrent())
|
|
96
|
+
return;
|
|
97
|
+
const positive = outcome.receipt && (outcome.status === 'confirmed' || outcome.status === 'partial');
|
|
98
|
+
// Retained positive evidence may already be terminal on native: replay
|
|
99
|
+
// it unchanged before asking for any recovery admission or cart read.
|
|
100
|
+
let reported = positive ? await this.report(prepared, outcome, executor) : false;
|
|
101
|
+
if (!stillCurrent())
|
|
102
|
+
return;
|
|
103
|
+
if (!reported) {
|
|
104
|
+
const ready = await this.beginRecovery(snapshot, prepared, outcome.execution);
|
|
105
|
+
if (!ready || !stillCurrent() || Date.parse(ready.expiresAt) <= Date.now())
|
|
106
|
+
return;
|
|
107
|
+
recoveryDeadline = Date.parse(ready.expiresAt);
|
|
108
|
+
outcome = await executor.reconcile(prepared, outcome.execution.executionId, ready, { refreshObservation: !!positive });
|
|
109
|
+
reported = false;
|
|
110
|
+
}
|
|
111
|
+
if (!stillCurrent())
|
|
112
|
+
return;
|
|
89
113
|
if (outcome)
|
|
90
114
|
this.recoveryOutcome = outcome;
|
|
91
115
|
// Only an original public scope stored with the original executor
|
|
92
116
|
// record can report recovery. It confers no permission to POST.
|
|
93
|
-
if (
|
|
117
|
+
if (!reported && prepared && outcome && stillCurrent()) {
|
|
94
118
|
if (prepared.reportSessionId === snapshot.sessionId)
|
|
95
119
|
await this.report(prepared, outcome, executor);
|
|
96
120
|
}
|
|
97
121
|
if (prepared && outcome)
|
|
98
122
|
await (0, shopifyCartPresentation_js_1.refreshShopifyCartPresentation)(prepared, outcome, { assertCurrent: stillCurrent }).catch(() => undefined);
|
|
99
|
-
if (
|
|
123
|
+
if (!stillCurrent())
|
|
100
124
|
return;
|
|
101
125
|
if (this.hasUnresolved())
|
|
102
126
|
this.showRecovery();
|
|
@@ -145,6 +169,9 @@ class CartSession {
|
|
|
145
169
|
this.result(payload);
|
|
146
170
|
}
|
|
147
171
|
cut() {
|
|
172
|
+
this.recoveryGrant = null;
|
|
173
|
+
this.recoveryBegin?.resolve(null);
|
|
174
|
+
this.pendingReport?.resolve(false);
|
|
148
175
|
const pending = this.pending;
|
|
149
176
|
if (!pending)
|
|
150
177
|
return;
|
|
@@ -161,6 +188,7 @@ class CartSession {
|
|
|
161
188
|
destroy() {
|
|
162
189
|
this.cut();
|
|
163
190
|
this.destroyed = true;
|
|
191
|
+
this.pendingReport?.resolve(false);
|
|
164
192
|
this.options.view()?.setCommerceCartActionHandler(null);
|
|
165
193
|
}
|
|
166
194
|
createPending(intentKind, requestId, snapshot, selection, quantity) {
|
|
@@ -257,6 +285,7 @@ class CartSession {
|
|
|
257
285
|
pending.approved = true;
|
|
258
286
|
}
|
|
259
287
|
pending.grant = copy(grant);
|
|
288
|
+
this.recoveryGrant = { grant: copy(grant), snapshot: copy(pending.snapshot) };
|
|
260
289
|
pending.executing = true;
|
|
261
290
|
if (pending.timer)
|
|
262
291
|
clearTimeout(pending.timer);
|
|
@@ -301,8 +330,8 @@ class CartSession {
|
|
|
301
330
|
await (0, shopifyCartPresentation_js_1.refreshShopifyCartPresentation)(prepared, outcome, { assertCurrent: () => this.current(pending) }).catch(() => undefined);
|
|
302
331
|
this.finish(pending);
|
|
303
332
|
}
|
|
304
|
-
recoveryExecutor() {
|
|
305
|
-
return new shopifyCart_js_1.ShopifyCartExecutor({ assertCurrent
|
|
333
|
+
recoveryExecutor(assertCurrent = () => !this.destroyed && this.options.current() !== null) {
|
|
334
|
+
return new shopifyCart_js_1.ShopifyCartExecutor({ assertCurrent,
|
|
306
335
|
beginExecution: async () => { throw new Error('Cart recovery cannot admit a new write.'); } });
|
|
307
336
|
}
|
|
308
337
|
hasUnresolved() {
|
|
@@ -318,17 +347,37 @@ class CartSession {
|
|
|
318
347
|
...(sessionId ? { sessionId } : {}) };
|
|
319
348
|
}
|
|
320
349
|
async report(prepared, outcome, executor) {
|
|
321
|
-
if (!prepared.reportScope || !prepared.reportSessionId || !outcome.execution ||
|
|
350
|
+
if (this.destroyed || !prepared.reportScope || !prepared.reportSessionId || !outcome.execution ||
|
|
322
351
|
prepared.reportScope.operationId !== prepared.operationId || prepared.guideId !== this.options.bootstrap.guideId ||
|
|
323
352
|
stable(prepared.store) !== stable(this.options.bootstrap.store))
|
|
324
|
-
return;
|
|
353
|
+
return false;
|
|
325
354
|
const transportSessionId = this.options.transportSessionId ? this.options.transportSessionId() :
|
|
326
355
|
this.options.current()?.sessionId ?? prepared.reportSessionId;
|
|
327
356
|
if (transportSessionId !== prepared.reportSessionId)
|
|
328
|
-
return;
|
|
357
|
+
return false;
|
|
329
358
|
const report = { ...scopeOf(prepared.reportScope), ...outcome.execution };
|
|
330
|
-
|
|
331
|
-
|
|
359
|
+
let resolve;
|
|
360
|
+
const response = new Promise(done => { resolve = done; });
|
|
361
|
+
const pending = { report, resolve };
|
|
362
|
+
this.pendingReport = pending;
|
|
363
|
+
try {
|
|
364
|
+
const [delivered, accepted] = await Promise.all([
|
|
365
|
+
this.send('commerce.cart.execution.result', report), this.boundedAccepted(response, 10000),
|
|
366
|
+
]);
|
|
367
|
+
const currentSessionId = this.options.transportSessionId ? this.options.transportSessionId() :
|
|
368
|
+
this.options.current()?.sessionId ?? prepared.reportSessionId;
|
|
369
|
+
if (!delivered || !accepted || this.destroyed || currentSessionId !== prepared.reportSessionId)
|
|
370
|
+
return false;
|
|
371
|
+
const acknowledged = executor.acknowledgeReport(this.recoveryScope(prepared.reportSessionId), report);
|
|
372
|
+
if (acknowledged && this.recoveryGrant?.grant.operationId === prepared.operationId)
|
|
373
|
+
this.recoveryGrant = null;
|
|
374
|
+
// Native acceptance and durable local acknowledgement are separate. A
|
|
375
|
+
// storage failure must retain local debt, not reopen a settled operation.
|
|
376
|
+
return true;
|
|
377
|
+
}
|
|
378
|
+
finally {
|
|
379
|
+
if (this.pendingReport === pending)
|
|
380
|
+
this.pendingReport = null;
|
|
332
381
|
}
|
|
333
382
|
}
|
|
334
383
|
showRecovery() {
|
|
@@ -343,10 +392,43 @@ class CartSession {
|
|
|
343
392
|
? { ...retained.outcome, local: local.local } : retained.outcome;
|
|
344
393
|
}
|
|
345
394
|
const outcome = this.recoveryOutcome ?? failure('transport', true);
|
|
346
|
-
//
|
|
347
|
-
//
|
|
395
|
+
// Retain uncertain evidence without offering a no-op Check after the
|
|
396
|
+
// original instance/authority needed to reconcile it is gone.
|
|
348
397
|
const observed = outcome.receipt && (outcome.status === 'confirmed' || outcome.status === 'partial');
|
|
349
|
-
|
|
398
|
+
const current = this.options.current();
|
|
399
|
+
const prepared = retained?.prepared;
|
|
400
|
+
const canRecover = current && prepared && prepared.reportSessionId === current.sessionId &&
|
|
401
|
+
(observed && prepared.reportScope || this.recoveryHandle(current, prepared));
|
|
402
|
+
this.options.view()?.setCommerceCartStatus(observed ? outcome : { ...outcome, status: 'uncertain' }, this.cartUrl(), canRecover ? this.checkCart : undefined);
|
|
403
|
+
}
|
|
404
|
+
recoveryHandle(snapshot, prepared) {
|
|
405
|
+
const retained = this.recoveryGrant;
|
|
406
|
+
if (!retained || stable(retained.snapshot) !== stable(snapshot) || prepared.reportSessionId !== snapshot.sessionId ||
|
|
407
|
+
!prepared.reportScope || stable(prepared.reportScope) !== stable(scopeOf(retained.grant)) ||
|
|
408
|
+
prepared.operationId !== retained.grant.operationId)
|
|
409
|
+
return null;
|
|
410
|
+
return retained;
|
|
411
|
+
}
|
|
412
|
+
async beginRecovery(snapshot, prepared, execution) {
|
|
413
|
+
const retained = this.recoveryHandle(snapshot, prepared);
|
|
414
|
+
if (!retained)
|
|
415
|
+
return null;
|
|
416
|
+
let resolve;
|
|
417
|
+
const response = new Promise(done => { resolve = done; });
|
|
418
|
+
const begin = { messageId: null, executionId: execution.executionId, cartDigest: execution.cartDigest,
|
|
419
|
+
ready: null, resolve, operationId: prepared.operationId };
|
|
420
|
+
this.recoveryBegin = begin;
|
|
421
|
+
try {
|
|
422
|
+
return await this.awaitAdmission(begin, response, { schemaVersion: 1, operationId: prepared.operationId,
|
|
423
|
+
grant: retained.grant.grant, executionId: execution.executionId, cartDigest: execution.cartDigest });
|
|
424
|
+
}
|
|
425
|
+
catch {
|
|
426
|
+
return null;
|
|
427
|
+
}
|
|
428
|
+
finally {
|
|
429
|
+
if (this.recoveryBegin === begin)
|
|
430
|
+
this.recoveryBegin = null;
|
|
431
|
+
}
|
|
350
432
|
}
|
|
351
433
|
async begin(pending, executionId, cartDigest) {
|
|
352
434
|
if (!pending.grant || !this.current(pending))
|
|
@@ -355,19 +437,22 @@ class CartSession {
|
|
|
355
437
|
const ready = new Promise(done => { resolve = done; });
|
|
356
438
|
pending.begin = { messageId: null, executionId, cartDigest, ready: null, resolve };
|
|
357
439
|
pending.started = true;
|
|
440
|
+
return this.awaitAdmission(pending.begin, ready, { schemaVersion: 1,
|
|
441
|
+
operationId: pending.grant.operationId, grant: pending.grant.grant, executionId, cartDigest });
|
|
442
|
+
}
|
|
443
|
+
async awaitAdmission(begin, ready, payload) {
|
|
358
444
|
let delivery;
|
|
359
445
|
try {
|
|
360
|
-
delivery = this.options.send('commerce.cart.execution.begin',
|
|
361
|
-
|
|
362
|
-
pending.begin.messageId = delivery.messageId;
|
|
446
|
+
delivery = this.options.send('commerce.cart.execution.begin', payload);
|
|
447
|
+
begin.messageId = delivery.messageId;
|
|
363
448
|
}
|
|
364
449
|
catch {
|
|
365
|
-
|
|
450
|
+
begin.resolve(null);
|
|
366
451
|
throw new Error('The cart admission could not be sent.');
|
|
367
452
|
}
|
|
368
453
|
// Admission can race expiry. A fresh already_started reply has its own
|
|
369
454
|
// short recovery window and can only lead to read-only reconciliation.
|
|
370
|
-
const timeout = setTimeout(() => resolve(null), 10000);
|
|
455
|
+
const timeout = setTimeout(() => begin.resolve(null), 10000);
|
|
371
456
|
try {
|
|
372
457
|
const [accepted, observed] = await Promise.all([this.boundedAccepted(delivery.accepted, 10000), ready]);
|
|
373
458
|
if (!accepted || !observed)
|
|
@@ -379,6 +464,16 @@ class CartSession {
|
|
|
379
464
|
}
|
|
380
465
|
}
|
|
381
466
|
ready(payload) {
|
|
467
|
+
const recovery = this.recoveryBegin;
|
|
468
|
+
if (recovery?.messageId && !recovery.ready) {
|
|
469
|
+
const ready = (0, cartContracts_js_1.parseCommerceCartExecutionReady)(payload, { operationId: recovery.operationId,
|
|
470
|
+
requestMessageId: recovery.messageId, executionId: recovery.executionId, cartDigest: recovery.cartDigest });
|
|
471
|
+
if (ready?.state === 'already_started') {
|
|
472
|
+
recovery.ready = copy(ready);
|
|
473
|
+
recovery.resolve(ready);
|
|
474
|
+
}
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
382
477
|
const pending = this.pending;
|
|
383
478
|
const begin = pending?.begin;
|
|
384
479
|
if (!pending?.grant || !begin?.messageId || begin.ready)
|
|
@@ -391,6 +486,14 @@ class CartSession {
|
|
|
391
486
|
begin.resolve(ready);
|
|
392
487
|
}
|
|
393
488
|
result(payload) {
|
|
489
|
+
const waiting = this.pendingReport;
|
|
490
|
+
if (waiting) {
|
|
491
|
+
const result = (0, cartContracts_js_1.parseCommerceCartResult)(payload, { requestId: waiting.report.requestId,
|
|
492
|
+
operationId: waiting.report.operationId, executionId: waiting.report.executionId });
|
|
493
|
+
if (result)
|
|
494
|
+
waiting.resolve((result.status === 'observed' || result.status === 'partial') &&
|
|
495
|
+
stable(result.observation) === stable(waiting.report.observation));
|
|
496
|
+
}
|
|
394
497
|
const pending = this.pending;
|
|
395
498
|
if (!pending)
|
|
396
499
|
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
|
|
@@ -929,7 +929,7 @@ class ShopifyCartExecutor {
|
|
|
929
929
|
return this.observe(prepared, evidence({ ...original, request: requestOutcome }));
|
|
930
930
|
}
|
|
931
931
|
/** Read-only even after expiry/cut. recoveredReady must come from the trusted native ACK/ready path. */
|
|
932
|
-
async reconcile(input, executionId, recoveredReady) {
|
|
932
|
+
async reconcile(input, executionId, recoveredReady, options = {}) {
|
|
933
933
|
let prepared;
|
|
934
934
|
try {
|
|
935
935
|
const text = JSON.stringify(input);
|
|
@@ -938,9 +938,11 @@ class ShopifyCartExecutor {
|
|
|
938
938
|
prepared = JSON.parse(text);
|
|
939
939
|
if (!(0, contracts_js_1.commerceUuid)(executionId) || !validPrepared(prepared))
|
|
940
940
|
return result("unavailable", "invalid_request");
|
|
941
|
-
if (recoveredReady
|
|
942
|
-
(
|
|
943
|
-
|
|
941
|
+
if ((options.refreshObservation && (!recoveredReady || recoveredReady.executionId !== executionId ||
|
|
942
|
+
Date.parse(recoveredReady.expiresAt) <= Date.now())) ||
|
|
943
|
+
recoveredReady &&
|
|
944
|
+
(!validReady(recoveredReady) ||
|
|
945
|
+
recoveredReady.state !== "already_started"))
|
|
944
946
|
return result("uncertain", "grant_unavailable");
|
|
945
947
|
const digest = await sha(intent(prepared));
|
|
946
948
|
let started;
|
|
@@ -977,7 +979,9 @@ class ShopifyCartExecutor {
|
|
|
977
979
|
/* Read-only recovery remains valid; unavailable storage still disables new effects. */
|
|
978
980
|
}
|
|
979
981
|
}
|
|
980
|
-
|
|
982
|
+
// Exact terminal report replay remains the default. Only a fresh,
|
|
983
|
+
// correlated already_started admission may request a new observation.
|
|
984
|
+
if (started?.resolved && started.prepared?.reportScope && !options.refreshObservation)
|
|
981
985
|
return retainedOutcome(prepared, started);
|
|
982
986
|
const execution = started
|
|
983
987
|
? evidence(started)
|
|
@@ -988,7 +992,7 @@ class ShopifyCartExecutor {
|
|
|
988
992
|
request: null,
|
|
989
993
|
})
|
|
990
994
|
: null;
|
|
991
|
-
return this.observe(prepared, execution);
|
|
995
|
+
return this.observe(prepared, execution, options.refreshObservation === true);
|
|
992
996
|
}
|
|
993
997
|
catch {
|
|
994
998
|
return result("uncertain", "invalid_request");
|
|
@@ -1013,7 +1017,7 @@ class ShopifyCartExecutor {
|
|
|
1013
1017
|
return false;
|
|
1014
1018
|
}
|
|
1015
1019
|
}
|
|
1016
|
-
async observe(prepared, execution) {
|
|
1020
|
+
async observe(prepared, execution, refreshUnacceptedObservation = false) {
|
|
1017
1021
|
const paths = route(prepared, false);
|
|
1018
1022
|
if (!paths)
|
|
1019
1023
|
return { ...result("uncertain", "context_changed"), execution };
|
|
@@ -1129,6 +1133,7 @@ class ShopifyCartExecutor {
|
|
|
1129
1133
|
}
|
|
1130
1134
|
: null;
|
|
1131
1135
|
if (execution && observation && observation.quantity > 0) {
|
|
1136
|
+
let durablyRetained = false;
|
|
1132
1137
|
try {
|
|
1133
1138
|
const key = ledgerKey(prepared);
|
|
1134
1139
|
const entries = readLedger(key);
|
|
@@ -1138,7 +1143,10 @@ class ShopifyCartExecutor {
|
|
|
1138
1143
|
cartDigest: execution.cartDigest,
|
|
1139
1144
|
intentDigest: intentDigest,
|
|
1140
1145
|
}));
|
|
1141
|
-
if (entry &&
|
|
1146
|
+
if (entry?.resolved && entry.prepared?.reportScope &&
|
|
1147
|
+
(!refreshUnacceptedObservation || entry.reportAccepted))
|
|
1148
|
+
return retainedOutcome(prepared, entry);
|
|
1149
|
+
if (entry && (!entry.resolved || (refreshUnacceptedObservation && !entry.reportAccepted))) {
|
|
1142
1150
|
entry.prepared ?? (entry.prepared = publicPrepared(prepared));
|
|
1143
1151
|
entry.request ?? (entry.request = execution.request);
|
|
1144
1152
|
entry.observation = observation;
|
|
@@ -1146,11 +1154,18 @@ class ShopifyCartExecutor {
|
|
|
1146
1154
|
if (entry.initialCartEmpty === true)
|
|
1147
1155
|
entry.materializedCartDigest = cartDigest;
|
|
1148
1156
|
saveLedger(key, entries);
|
|
1157
|
+
durablyRetained = true;
|
|
1149
1158
|
}
|
|
1150
1159
|
}
|
|
1151
1160
|
catch {
|
|
1152
|
-
/*
|
|
1161
|
+
/* Retain the pending guard when storage cannot keep the observation. */
|
|
1153
1162
|
}
|
|
1163
|
+
// Every positive native report, including the first observation after
|
|
1164
|
+
// Add or an unknown result, must be replayable after native settles it.
|
|
1165
|
+
// Keep local cart truth but withhold undurable evidence from transport.
|
|
1166
|
+
if (prepared.reportScope && !durablyRetained)
|
|
1167
|
+
return { status, reason: "storage_unavailable", canUndo: false,
|
|
1168
|
+
receipt, execution: null, local: { itemCount: cart.itemCount } };
|
|
1154
1169
|
}
|
|
1155
1170
|
if (!execution) {
|
|
1156
1171
|
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/cjs/guideMeasurement.js
CHANGED
|
@@ -4,7 +4,7 @@ exports.GUIDE_MEASUREMENT_CLIENT_VERSION = void 0;
|
|
|
4
4
|
exports.isGuideMeasurementIntent = isGuideMeasurementIntent;
|
|
5
5
|
exports.currentGuideMeasurementBridge = currentGuideMeasurementBridge;
|
|
6
6
|
exports.prepareGuideMeasurementBridge = prepareGuideMeasurementBridge;
|
|
7
|
-
exports.GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.
|
|
7
|
+
exports.GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.27';
|
|
8
8
|
function isGuideMeasurementIntent(value) {
|
|
9
9
|
if (!value || typeof value !== 'object' || Array.isArray(value))
|
|
10
10
|
return false;
|
|
@@ -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,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveControlChannel = exports.LIVE_CONTROL_CLIENT_CAPABILITIES = exports.LIVE_CONTROL_CLIENT_VERSION = void 0;
|
|
4
|
+
const merchantPreviewOrigins_js_1 = require("./merchantPreviewOrigins.js");
|
|
4
5
|
const liveDuplexMedia_js_1 = require("./liveDuplexMedia.js");
|
|
5
6
|
const version_js_1 = require("./version.js");
|
|
6
7
|
const contracts_js_1 = require("./commerce/contracts.js");
|
|
@@ -94,7 +95,9 @@ class LiveControlChannel {
|
|
|
94
95
|
if (!['https:', 'http:'].includes(trusted.protocol) || trusted.origin !== options.trustedRuntimeOrigin ||
|
|
95
96
|
trusted.username || trusted.password || target.username || target.password || target.search || target.hash || target.pathname !== path ||
|
|
96
97
|
target.protocol !== (trusted.protocol === 'https:' ? 'wss:' : 'ws:') || target.host !== trusted.host ||
|
|
97
|
-
(trusted.protocol === 'http:' && !
|
|
98
|
+
(trusted.protocol === 'http:' && !(options.previewRuntimePolicy
|
|
99
|
+
? (0, merchantPreviewOrigins_js_1.isPreviewRuntimeOrigin)(trusted, options.previewRuntimePolicy)
|
|
100
|
+
: ['localhost', '127.0.0.1', '[::1]'].includes(trusted.hostname))))
|
|
98
101
|
throw unavailable();
|
|
99
102
|
target.searchParams.set('session', String(value.sessionId));
|
|
100
103
|
this.url = target.href;
|
package/cjs/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/cjs/liveGuideWidget.js
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.LiveGuideWidget = void 0;
|
|
4
4
|
const ui_js_1 = require("./ui.js");
|
|
5
|
+
const client_js_1 = require("./client.js");
|
|
5
6
|
const liveGuideAdmission_js_1 = require("./liveGuideAdmission.js");
|
|
6
7
|
const liveControlChannel_js_1 = require("./liveControlChannel.js");
|
|
7
8
|
const liveBrowserDetector_js_1 = require("./liveBrowserDetector.js");
|
|
@@ -62,10 +63,21 @@ class LiveGuideWidget {
|
|
|
62
63
|
JSON.stringify(config.liveCapabilities) !== JSON.stringify(liveControlChannel_js_1.LIVE_CONTROL_CLIENT_CAPABILITIES))
|
|
63
64
|
throw new Error('AI Guide Live is unavailable.');
|
|
64
65
|
(0, liveBrowserDetector_js_1.validateLiveBrowserAssets)(config.liveAssets);
|
|
65
|
-
|
|
66
|
+
if (options.sessionAdmission)
|
|
67
|
+
this.admission = options.sessionAdmission;
|
|
68
|
+
else {
|
|
69
|
+
const publicAdmission = options.admission;
|
|
70
|
+
const live = new liveGuideAdmission_js_1.LiveGuideAdmission(publicAdmission.identity, publicAdmission.store, options.runtime, publicAdmission);
|
|
71
|
+
this.admission = {
|
|
72
|
+
hasPendingLaunch: () => live.hasPendingLaunch(),
|
|
73
|
+
pendingLaunchId: () => live.pendingLaunchId(),
|
|
74
|
+
launch: (intent, signal) => live.launch({ ...intent, installKey: publicAdmission.identity.installKey }, signal),
|
|
75
|
+
end: (signal, expectedLaunchRequestId) => live.end(signal, expectedLaunchRequestId),
|
|
76
|
+
};
|
|
77
|
+
}
|
|
66
78
|
const callbacks = {
|
|
67
79
|
onStart: (mode, scopes, question) => this.start(mode, scopes, question),
|
|
68
|
-
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch(),
|
|
80
|
+
onRestart: () => !this.active && !this.starting && !this.ending && !this.admission.hasPendingLaunch() && this.admission.canStart?.() !== false,
|
|
69
81
|
onEnd: () => { void this.end().catch(() => undefined); },
|
|
70
82
|
onMute: muted => { if (muted)
|
|
71
83
|
this.privacy('mute');
|
|
@@ -128,6 +140,10 @@ class LiveGuideWidget {
|
|
|
128
140
|
void this.end().catch(() => undefined);
|
|
129
141
|
}
|
|
130
142
|
}
|
|
143
|
+
else if (this.admission.recoveryOnly) {
|
|
144
|
+
this.phase = 'ended';
|
|
145
|
+
this.view.showLaunchUnavailable(this.admission.endMessage ?? this.view.message('ended'));
|
|
146
|
+
}
|
|
131
147
|
// Capture runs before TabActivityLock releases cross-tab ownership.
|
|
132
148
|
window.addEventListener('pagehide', this.pagehide, true);
|
|
133
149
|
window.addEventListener('focus', this.refreshOwnership);
|
|
@@ -160,7 +176,7 @@ class LiveGuideWidget {
|
|
|
160
176
|
companion: false, pendingQuestion: this.pendingQuestions.length > 0 };
|
|
161
177
|
}
|
|
162
178
|
start(mode, scopes, question) {
|
|
163
|
-
if (this.destroyed || this.starting || this.active || this.ending ||
|
|
179
|
+
if (this.destroyed || this.starting || this.active || this.ending || this.admission.canStart?.() === false ||
|
|
164
180
|
(question && (!question.trim() || question.length > 4000)) || !this.acquireLock())
|
|
165
181
|
return false;
|
|
166
182
|
// Recover abandoned intent only after acquiring the actual activity lock;
|
|
@@ -178,7 +194,7 @@ class LiveGuideWidget {
|
|
|
178
194
|
this.operation = operation;
|
|
179
195
|
const timeout = setTimeout(() => operation.abort(), 20000);
|
|
180
196
|
const config = this.options.bootstrap;
|
|
181
|
-
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
197
|
+
const intent = { schemaVersion: 3, protocolVersion: 2,
|
|
182
198
|
launchRequestId: crypto.randomUUID(), clientVersion: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_VERSION, liveCapabilities: liveControlChannel_js_1.LIVE_CONTROL_CLIENT_CAPABILITIES,
|
|
183
199
|
configRevision: config.configRevision, path: location.pathname, tabId: this.options.tabId, mode, experienceMode: 'standard',
|
|
184
200
|
consent: { disclosureChecksum: config.consent.disclosureChecksum, scopes: [...scopes], locale: this.options.locale },
|
|
@@ -198,6 +214,7 @@ class LiveGuideWidget {
|
|
|
198
214
|
throw new Error('Cancelled.');
|
|
199
215
|
const audio = this.view.livePlaybackElement();
|
|
200
216
|
const channel = new liveControlChannel_js_1.LiveControlChannel({ authorization, trustedRuntimeOrigin: new URL(this.options.runtime.baseUrl).origin,
|
|
217
|
+
...(this.options.previewRuntimePolicy ? { previewRuntimePolicy: this.options.previewRuntimePolicy } : {}),
|
|
201
218
|
tabId: this.options.tabId, onState: state => this.onControlState(state),
|
|
202
219
|
onClose: reason => {
|
|
203
220
|
if (this.channel === channel && !this.ending && !this.destroyed) {
|
|
@@ -580,11 +597,25 @@ class LiveGuideWidget {
|
|
|
580
597
|
this.ownedLaunchId = null;
|
|
581
598
|
this.phase = 'ended';
|
|
582
599
|
this.releaseLock();
|
|
583
|
-
if (!this.destroyed)
|
|
584
|
-
this.
|
|
600
|
+
if (!this.destroyed) {
|
|
601
|
+
if (this.admission.endMessage)
|
|
602
|
+
this.view.showLaunchUnavailable(this.admission.endMessage);
|
|
603
|
+
else
|
|
604
|
+
this.view.showResumeStopped();
|
|
605
|
+
}
|
|
606
|
+
this.options.onState();
|
|
607
|
+
}).catch(error => {
|
|
608
|
+
this.phase = 'error';
|
|
609
|
+
if (!this.destroyed) {
|
|
610
|
+
if (this.admission.recoveryOnly && error instanceof client_js_1.RuntimeClientError && error.code === 'MERCHANT_PREVIEW_END_UNRESOLVED') {
|
|
611
|
+
this.view.showLaunchUnavailable(error.message);
|
|
612
|
+
}
|
|
613
|
+
else
|
|
614
|
+
this.view.showError(this.view.message('error'), true);
|
|
615
|
+
}
|
|
585
616
|
this.options.onState();
|
|
586
|
-
|
|
587
|
-
|
|
617
|
+
throw error;
|
|
618
|
+
})
|
|
588
619
|
.finally(() => { if (this.ending === pending)
|
|
589
620
|
this.ending = null; });
|
|
590
621
|
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>;
|