@oxvo/ai-live-assist 7.5.20 → 7.5.22

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 (101) 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 +345 -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/context.js +17 -5
  26. package/cjs/control.d.ts +9 -1
  27. package/cjs/control.js +51 -1
  28. package/cjs/guideAdmission.d.ts +6 -2
  29. package/cjs/guideAdmission.js +39 -2
  30. package/cjs/guideInstaller.js +1 -1
  31. package/cjs/guideMeasurement.d.ts +7 -0
  32. package/cjs/guideMeasurement.js +59 -0
  33. package/cjs/guideSubjectStore.js +2 -0
  34. package/cjs/guideTypes.d.ts +19 -0
  35. package/cjs/liveControlChannel.d.ts +43 -1
  36. package/cjs/liveControlChannel.js +166 -14
  37. package/cjs/liveGuideAdmission.d.ts +3 -2
  38. package/cjs/liveGuideAdmission.js +14 -2
  39. package/cjs/liveGuideWidget.d.ts +18 -0
  40. package/cjs/liveGuideWidget.js +228 -23
  41. package/cjs/locales/resources.js +2240 -0
  42. package/cjs/messages.js +56 -0
  43. package/cjs/tabLock.d.ts +2 -0
  44. package/cjs/tabLock.js +11 -1
  45. package/cjs/types.d.ts +6 -2
  46. package/cjs/types.js +56 -0
  47. package/cjs/ui.d.ts +37 -0
  48. package/cjs/ui.js +259 -9
  49. package/cjs/version.d.ts +1 -1
  50. package/cjs/version.js +1 -1
  51. package/lib/AiLiveAssist.d.ts +8 -1
  52. package/lib/AiLiveAssist.js +113 -8
  53. package/lib/client.d.ts +5 -3
  54. package/lib/client.js +44 -5
  55. package/lib/commerce/cartContracts.d.ts +158 -0
  56. package/lib/commerce/cartContracts.js +221 -0
  57. package/lib/commerce/cartSession.d.ts +86 -0
  58. package/lib/commerce/cartSession.js +471 -0
  59. package/lib/commerce/contracts.d.ts +152 -0
  60. package/lib/commerce/contracts.js +300 -0
  61. package/lib/commerce/pageContext.d.ts +50 -0
  62. package/lib/commerce/pageContext.js +168 -0
  63. package/lib/commerce/productPanel.d.ts +65 -0
  64. package/lib/commerce/productPanel.js +657 -0
  65. package/lib/commerce/realtimeCommerce.d.ts +73 -0
  66. package/lib/commerce/realtimeCommerce.js +340 -0
  67. package/lib/commerce/shopifyCart.d.ts +130 -0
  68. package/lib/commerce/shopifyCart.js +1130 -0
  69. package/lib/commerce/shopifyCartPresentation.d.ts +12 -0
  70. package/lib/commerce/shopifyCartPresentation.js +376 -0
  71. package/lib/commerce/shoppingNotes.d.ts +61 -0
  72. package/lib/commerce/shoppingNotes.js +307 -0
  73. package/lib/commerce/shoppingNotesView.d.ts +46 -0
  74. package/lib/commerce/shoppingNotesView.js +265 -0
  75. package/lib/context.js +17 -5
  76. package/lib/control.d.ts +9 -1
  77. package/lib/control.js +51 -1
  78. package/lib/guideAdmission.d.ts +6 -2
  79. package/lib/guideAdmission.js +39 -2
  80. package/lib/guideInstaller.js +1 -1
  81. package/lib/guideMeasurement.d.ts +7 -0
  82. package/lib/guideMeasurement.js +53 -0
  83. package/lib/guideSubjectStore.js +2 -0
  84. package/lib/guideTypes.d.ts +19 -0
  85. package/lib/liveControlChannel.d.ts +43 -1
  86. package/lib/liveControlChannel.js +166 -14
  87. package/lib/liveGuideAdmission.d.ts +3 -2
  88. package/lib/liveGuideAdmission.js +14 -2
  89. package/lib/liveGuideWidget.d.ts +18 -0
  90. package/lib/liveGuideWidget.js +228 -23
  91. package/lib/locales/resources.js +2240 -0
  92. package/lib/messages.js +56 -0
  93. package/lib/tabLock.d.ts +2 -0
  94. package/lib/tabLock.js +11 -1
  95. package/lib/types.d.ts +6 -2
  96. package/lib/types.js +56 -0
  97. package/lib/ui.d.ts +37 -0
  98. package/lib/ui.js +259 -9
  99. package/lib/version.d.ts +1 -1
  100. package/lib/version.js +1 -1
  101. package/package.json +1 -1
@@ -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.20";
37
+ readonly version = "7.5.22";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
@@ -127,6 +127,9 @@ export default class AiLiveAssist {
127
127
  private channel;
128
128
  private media;
129
129
  private context;
130
+ private commerce;
131
+ private commerceReadyChannel;
132
+ private pendingCommerceGeneration;
130
133
  private presentation;
131
134
  private connectionAbort;
132
135
  private connectionGeneration;
@@ -448,6 +451,9 @@ export default class AiLiveAssist {
448
451
  private deliverContextNavigation;
449
452
  private commitAuthorizedRuntimePath;
450
453
  private waitForPendingContextNavigationAcknowledgements;
454
+ private commerceBootstrap;
455
+ private commerceCartEnabled;
456
+ private startRealtimeCommerce;
451
457
  private startContext;
452
458
  private startPresentation;
453
459
  private sendText;
@@ -767,6 +773,7 @@ export default class AiLiveAssist {
767
773
  private isVoicePresence;
768
774
  private lowPowerMode;
769
775
  private bindWindowLifecycle;
776
+ private handledPageHide;
770
777
  private onPageHide;
771
778
  private onPageShow;
772
779
  private onWindowFocus;
@@ -6,6 +6,8 @@ const guideMount_js_1 = require("./guideMount.js");
6
6
  const client_js_1 = require("./client.js");
7
7
  const control_js_1 = require("./control.js");
8
8
  const context_js_1 = require("./context.js");
9
+ const contracts_js_1 = require("./commerce/contracts.js");
10
+ const realtimeCommerce_js_1 = require("./commerce/realtimeCommerce.js");
9
11
  const media_js_1 = require("./media.js");
10
12
  const messengerLoader_js_1 = require("./messengerLoader.js");
11
13
  const pageAssistancePreference_js_1 = require("./pageAssistancePreference.js");
@@ -256,6 +258,7 @@ const CONSENT_SCOPES = new Set([
256
258
  "microphone",
257
259
  "page_context",
258
260
  "browser_control",
261
+ "commerce_cart",
259
262
  "visual_context",
260
263
  "handoff_context",
261
264
  "retained_transcript",
@@ -1423,6 +1426,9 @@ class AiLiveAssist {
1423
1426
  this.channel = null;
1424
1427
  this.media = null;
1425
1428
  this.context = null;
1429
+ this.commerce = null;
1430
+ this.commerceReadyChannel = null;
1431
+ this.pendingCommerceGeneration = null;
1426
1432
  this.presentation = null;
1427
1433
  this.connectionAbort = null;
1428
1434
  this.connectionGeneration = 0;
@@ -1595,7 +1601,11 @@ class AiLiveAssist {
1595
1601
  this.onMessengerReturnRequested = (event) => {
1596
1602
  this.handleMessengerReturnRequested(event);
1597
1603
  };
1604
+ this.handledPageHide = null;
1598
1605
  this.onPageHide = (event) => {
1606
+ if (this.handledPageHide === event)
1607
+ return;
1608
+ this.handledPageHide = event;
1599
1609
  const recoveryWasBusy = !event.persisted && (this.reconnecting || this.reconnectTimer !== null);
1600
1610
  const resumeAtHide = recoveryWasBusy ? this.readResume() : null;
1601
1611
  const ordinaryRecoveryPending = recoveryWasBusy &&
@@ -1791,6 +1801,12 @@ class AiLiveAssist {
1791
1801
  document.documentElement.lang ||
1792
1802
  "en");
1793
1803
  this.lock = new tabLock_js_1.TabActivityLock(this.storageNamespace, this.windowId, (active) => this.handleTabActivityChange(active), (requesterId, requestId) => this.handoffToFocusedTab(requesterId, requestId), (payload, authority, sourceOwnerId) => this.prepareFocusedTabHandoff(payload, authority, sourceOwnerId), {
1804
+ onBeforePageHideRelease: (event) => {
1805
+ if (this.liveWidget)
1806
+ void this.liveWidget.end().catch(() => undefined);
1807
+ else
1808
+ this.onPageHide(event);
1809
+ },
1794
1810
  onCommitting: (payload, authority) => this.commitStagedPendingLaunch(payload, authority),
1795
1811
  onCommitted: (payload, authority) => void this.commitFocusedTabHandoff(payload, authority),
1796
1812
  onRelinquished: (payload) => this.completeFocusedTabRelinquish(payload),
@@ -2044,6 +2060,8 @@ class AiLiveAssist {
2044
2060
  this.clearReconnectTimer();
2045
2061
  if (this.destroyed)
2046
2062
  return;
2063
+ this.commerce?.destroy();
2064
+ this.commerce = null;
2047
2065
  this.liveWidget?.destroy();
2048
2066
  this.liveWidget = null;
2049
2067
  const recoveringModeUpgrade = this.relinquishModeUpgradeForRecovery(true, true);
@@ -2177,7 +2195,8 @@ class AiLiveAssist {
2177
2195
  this.bootstrap = bootstrap;
2178
2196
  this.liveWidget = new liveGuideWidget_js_1.LiveGuideWidget({ bootstrap, admission: this.guideAdmission, runtime: this.runtime,
2179
2197
  tabId: this.tabId, locale: this.locale, messages: this.options.messages, viewOptions: this.widgetViewOptions,
2180
- acquire: () => this.lock.acquire(), release: () => this.lock.release(), onState: () => this.emitStateEvent() });
2198
+ acquire: () => this.lock.acquire(), release: () => this.lock.release(),
2199
+ ownsActivity: () => this.lock.ownsActivity(), onState: () => this.emitStateEvent() });
2181
2200
  this.view = this.liveWidget.view;
2182
2201
  this.lifecyclePhase = "ready";
2183
2202
  return;
@@ -7948,6 +7967,8 @@ class AiLiveAssist {
7948
7967
  let recoveryPath = null;
7949
7968
  const channel = new control_js_1.ControlChannel(result, this.tabId, version_js_1.VERSION, () => this.scheduleReconnect(true), this.readResume()?.clientSequence ?? 0, (sequence) => this.updateResumeSequence(sequence), () => this.handleControlSequenceGap(), {
7950
7969
  canRecover: () => {
7970
+ this.commerceReadyChannel = null;
7971
+ this.commerce?.suspend();
7951
7972
  const currentPath = path();
7952
7973
  if (!this.canRecoverControlTransport(channel, result, media) ||
7953
7974
  (recoveryPath !== null && recoveryPath !== currentPath))
@@ -7961,15 +7982,19 @@ class AiLiveAssist {
7961
7982
  channel.startHeartbeat(this.heartbeatSeconds);
7962
7983
  await this.replayPreFenceAuthorityEnvelopes(channel, fencingToken, assertCurrent);
7963
7984
  assertCurrent();
7985
+ this.startRealtimeCommerce(true);
7964
7986
  await this.context?.captureAndPublish();
7965
7987
  assertCurrent();
7966
7988
  this.flushPlaybackState();
7967
7989
  this.reapplyConservativePreFencePresence(channel, fencingToken);
7990
+ void this.flushPendingQuestion();
7968
7991
  },
7969
- });
7992
+ }, result.protocolVersion === 2 && this.commerceBootstrap() ? 1 : undefined, result.protocolVersion === 2 && this.commerceCartEnabled());
7970
7993
  const pauseHelloStateSignal = deferredSignal();
7971
7994
  (this.pauseHelloStateSignals ?? (this.pauseHelloStateSignals = new WeakMap())).set(channel, pauseHelloStateSignal);
7972
7995
  this.handoffContextPromptReceiptChannel = null;
7996
+ this.commerceReadyChannel = null;
7997
+ this.pendingCommerceGeneration = null;
7973
7998
  this.channel = channel;
7974
7999
  this.committedHandoffRecoveryChannel = null;
7975
8000
  this.committedHandoffRecoveryExpiresAt = 0;
@@ -8067,6 +8092,7 @@ class AiLiveAssist {
8067
8092
  // delivery is acknowledged so its fresh snapshot remains authoritative.
8068
8093
  assertCurrent();
8069
8094
  this.startContext(activeScopes);
8095
+ this.startRealtimeCommerce();
8070
8096
  assertCurrent();
8071
8097
  await this.replayPreFenceAuthorityEnvelopes(channel, fencingToken, assertCurrent);
8072
8098
  assertCurrent();
@@ -8319,6 +8345,38 @@ class AiLiveAssist {
8319
8345
  const outcomes = await Promise.all(pending.map((entry) => entry.outcome));
8320
8346
  return outcomes.every((outcome) => outcome.status === "ack");
8321
8347
  }
8348
+ commerceBootstrap() {
8349
+ return (0, contracts_js_1.parseCommerceBootstrap)(this.bootstrap?.commerce, this.bootstrap?.guideId, window.location.origin);
8350
+ }
8351
+ commerceCartEnabled(bootstrap = this.bootstrap) {
8352
+ return bootstrap?.capabilities?.commerceCart === true && (0, contracts_js_1.parseCommerceBootstrap)(bootstrap.commerce, bootstrap.guideId, window.location.origin)?.cartEnabled === true;
8353
+ }
8354
+ startRealtimeCommerce(preserveProvider = false) {
8355
+ const authority = this.commerceBootstrap();
8356
+ const sessionId = this.result?.sessionId;
8357
+ if (!authority || !sessionId || !(this.view instanceof ui_js_1.WidgetView) ||
8358
+ !this.channel?.hasFencedAuthority || this.channel.negotiatedCommerceVersion !== 1) {
8359
+ this.commerce?.suspend();
8360
+ return;
8361
+ }
8362
+ if (this.commerce?.sessionId !== sessionId) {
8363
+ this.commerce?.destroy();
8364
+ this.commerce = new realtimeCommerce_js_1.RealtimeCommerce(sessionId, authority, {
8365
+ channel: () => this.channel,
8366
+ view: () => this.view instanceof ui_js_1.WidgetView ? this.view : null,
8367
+ isCurrent: () => this.result?.sessionId === sessionId && !this.ended && !this.destroyed &&
8368
+ !this.terminalRequestPending && !this.messengerTransferred && !this.messengerTransferPending,
8369
+ sharePage: () => this.bootstrap?.capabilities?.pageContext === true && this.scopes.includes("page_context"),
8370
+ cartConsent: () => this.commerceCartEnabled() &&
8371
+ this.scopes.includes("ai_disclosure") && this.scopes.includes("commerce_cart"),
8372
+ submit: text => this.sendText(text),
8373
+ });
8374
+ }
8375
+ this.commerceReadyChannel = this.channel;
8376
+ const pending = this.pendingCommerceGeneration;
8377
+ this.pendingCommerceGeneration = null;
8378
+ this.commerce.activate(pending?.channel === this.channel ? pending.digest : undefined, preserveProvider);
8379
+ }
8322
8380
  startContext(scopes) {
8323
8381
  this.context?.stop();
8324
8382
  this.context = null;
@@ -8619,7 +8677,9 @@ class AiLiveAssist {
8619
8677
  this.terminalRequestPending ||
8620
8678
  this.ended ||
8621
8679
  !channel?.isOpen ||
8622
- channel.leaseToken < 1) {
8680
+ channel.leaseToken < 1 ||
8681
+ (channel.negotiatedCommerceVersion === 1 && this.commerceBootstrap() &&
8682
+ this.commerceReadyChannel !== channel)) {
8623
8683
  return;
8624
8684
  }
8625
8685
  const confirmationDecisionMessageId = pending.confirmationDecisionMessageId;
@@ -8643,7 +8703,9 @@ class AiLiveAssist {
8643
8703
  this.terminalRequestPending ||
8644
8704
  this.ended ||
8645
8705
  this.channel !== channel ||
8646
- !channel.isOpen) {
8706
+ !channel.isOpen ||
8707
+ (channel.negotiatedCommerceVersion === 1 && this.commerceBootstrap() &&
8708
+ this.commerceReadyChannel !== channel)) {
8647
8709
  return;
8648
8710
  }
8649
8711
  if (!pending.shown) {
@@ -8652,6 +8714,10 @@ class AiLiveAssist {
8652
8714
  this.rememberTranscript(pending.submissionId, "user", pending.text);
8653
8715
  (this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).add(pending.submissionId);
8654
8716
  }
8717
+ if (this.commerce?.beforeInput() === false) {
8718
+ this.scheduleReconnect(true);
8719
+ return;
8720
+ }
8655
8721
  let messageId;
8656
8722
  let sentSequence = 0;
8657
8723
  try {
@@ -9615,7 +9681,8 @@ class AiLiveAssist {
9615
9681
  !scopes.includes("text") ||
9616
9682
  typeof payload.browserControl !== "boolean" ||
9617
9683
  payload.browserControl !== scopes.includes("browser_control") ||
9618
- (scopes.includes("browser_control") && !scopes.includes("page_context"))) {
9684
+ (scopes.includes("browser_control") && !scopes.includes("page_context")) ||
9685
+ (scopes.includes("commerce_cart") && !this.commerceCartEnabled())) {
9619
9686
  return null;
9620
9687
  }
9621
9688
  return scopes;
@@ -9944,7 +10011,15 @@ class AiLiveAssist {
9944
10011
  // A delayed receipt cannot restore recording after the visitor opted out.
9945
10012
  if (this.guideAdmission && !this.guideAdmission.recordingAllowed)
9946
10013
  scopes = scopes.filter(scope => scope !== "session_recording");
10014
+ const sharedPage = this.scopes.includes("page_context");
10015
+ const cartConsent = this.scopes.includes("ai_disclosure") && this.scopes.includes("commerce_cart");
9947
10016
  this.scopes = [...scopes];
10017
+ const nextCartConsent = scopes.includes("ai_disclosure") && scopes.includes("commerce_cart");
10018
+ if (cartConsent !== nextCartConsent)
10019
+ this.commerce?.consentChanged(nextCartConsent);
10020
+ if (sharedPage !== scopes.includes("page_context")) {
10021
+ this.commerce?.permissionChanged(scopes.includes("page_context"));
10022
+ }
9948
10023
  if (this.guideAdmission && this.result) {
9949
10024
  this.guideAdmission.syncRecording(this.result, scopes, this.tabId);
9950
10025
  if (this.view instanceof ui_js_1.WidgetView)
@@ -10291,6 +10366,15 @@ class AiLiveAssist {
10291
10366
  this.invalidateCtaAuthority();
10292
10367
  }
10293
10368
  const fencedAuthorityAtIngress = this.channel?.hasFencedAuthority === true;
10369
+ if (message.type === "commerce.context.required" && this.channel?.negotiatedCommerceVersion === 1 &&
10370
+ this.commerceReadyChannel !== this.channel) {
10371
+ const digest = (0, realtimeCommerce_js_1.realtimeCommerceRequiredDigest)(message.payload);
10372
+ if (digest)
10373
+ this.pendingCommerceGeneration = { channel: this.channel, digest };
10374
+ }
10375
+ else {
10376
+ this.commerce?.observeIngress(message, fencedAuthorityAtIngress);
10377
+ }
10294
10378
  (this.fencedAuthorityAtIngressByEnvelope ?? (this.fencedAuthorityAtIngressByEnvelope = new WeakMap())).set(message, fencedAuthorityAtIngress);
10295
10379
  if (message.type === "handoff.state" &&
10296
10380
  message.payload.state === "prepared") {
@@ -10720,6 +10804,12 @@ class AiLiveAssist {
10720
10804
  return;
10721
10805
  const payload = message.payload;
10722
10806
  switch (message.type) {
10807
+ case "commerce.catalog":
10808
+ case "commerce.cart.confirmation":
10809
+ case "commerce.cart.grant":
10810
+ case "commerce.cart.result":
10811
+ this.commerce?.receive(message);
10812
+ return;
10723
10813
  case "cta.offer": {
10724
10814
  // CTA has its own ingress fence. Browser-action generations also move
10725
10815
  // on unchanged consent, which must not discard a queued native link.
@@ -13308,6 +13398,7 @@ class AiLiveAssist {
13308
13398
  void this.performPageAssistanceRevocation();
13309
13399
  }
13310
13400
  handleControlSequenceGap() {
13401
+ this.commerce?.suspend();
13311
13402
  // The socket is no longer authoritative, so revoke every executable
13312
13403
  // action immediately. A causal navigation/result envelope records an
13313
13404
  // action that already happened and remains bounded by its original grant;
@@ -15883,6 +15974,8 @@ class AiLiveAssist {
15883
15974
  });
15884
15975
  }
15885
15976
  quiesceLocalEffectsForTerminalRequest() {
15977
+ this.commerce?.destroy();
15978
+ this.commerce = null;
15886
15979
  this.clearCtaAuthority();
15887
15980
  this.queuedLaunchToken = null;
15888
15981
  this.launchGeneration += 1;
@@ -15949,6 +16042,9 @@ class AiLiveAssist {
15949
16042
  this.messengerOpenAckInFlight = null;
15950
16043
  }
15951
16044
  cleanupTransport(options = {}) {
16045
+ this.commerceReadyChannel = null;
16046
+ this.pendingCommerceGeneration = null;
16047
+ this.commerce?.suspend();
15952
16048
  this.voicePlaybackInterruptBarrier = null;
15953
16049
  this.voicePlaybackAdmissionAfterSequence = 0;
15954
16050
  this.invalidateVoicePlaybackRearm();
@@ -16054,6 +16150,12 @@ class AiLiveAssist {
16054
16150
  if (this.manualPushRequest && ["session.interrupt", "session.mode", "voice.turn_mode", "session.pause", "session.end", "experience.end"].includes(type)) {
16055
16151
  this.stopManualPushToTalk(false);
16056
16152
  }
16153
+ if (type === "session.pause")
16154
+ this.commerce?.pause();
16155
+ if (["session.end", "experience.end"].includes(type))
16156
+ this.commerce?.suspend();
16157
+ if (type === "session.interrupt")
16158
+ this.commerce?.cut();
16057
16159
  if (this.terminalRequestPending && type !== "experience.end")
16058
16160
  return null;
16059
16161
  if (!this.channel?.isOpen)
@@ -17583,9 +17685,8 @@ class AiLiveAssist {
17583
17685
  return connection?.saveData === true || connection?.effectiveType === "2g";
17584
17686
  }
17585
17687
  bindWindowLifecycle() {
17586
- // Run transport cleanup before TabActivityLock's own pagehide listener
17587
- // releases cross-tab authority. Pagehide targets Window, where capture
17588
- // listeners are invoked before the lock's non-capture listener.
17688
+ // The lock's explicit lifecycle hook captures owned cleanup before release;
17689
+ // this listener also cleans up inactive pages without relying on event order.
17589
17690
  window.addEventListener("pagehide", this.onPageHide, true);
17590
17691
  window.addEventListener("pageshow", this.onPageShow);
17591
17692
  window.addEventListener("online", this.onOnline);
@@ -17619,6 +17720,10 @@ class AiLiveAssist {
17619
17720
  return this.terminalRequestPending;
17620
17721
  }
17621
17722
  handleTabActivityChange(active) {
17723
+ if (this.liveWidget) {
17724
+ this.liveWidget.onTabActivityChange(active);
17725
+ return;
17726
+ }
17622
17727
  this.view?.showActiveElsewhere(false);
17623
17728
  if (!active ||
17624
17729
  this.terminalRequestPending ||
package/cjs/client.d.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  import type { AssistMode, AiGuideCompanionState, BootstrapConfig, ConsentScope, HandoffRecoveryResult, LaunchResult, ExperienceMode, MessengerConversationState } from "./types.js";
2
- import { type GuideAdmissionResult, type GuideLaunchIntent, type GuideLaunchRecoveryInput, type GuideLaunchRecoveryResult, type GuideLaunchResult, type GuideRecordingLinkInput, type GuideRecordingLinkResult } from "./guideTypes.js";
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
5
  export declare class RuntimeClientError extends Error {
@@ -96,7 +96,7 @@ export declare class RuntimeClient {
96
96
  admitLiveGuide(intent: LiveGuideLaunchIntent, subjectCredential: string | undefined, signal: AbortSignal): Promise<GuideAdmissionResult & {
97
97
  providerProtocol: "live";
98
98
  }>;
99
- launchLiveGuide(intent: LiveGuideLaunchIntent, admissionGrant: string, signal: AbortSignal): Promise<LiveControlAuthorization>;
99
+ launchLiveGuide(intent: LiveGuideLaunchIntent, admissionGrant: string, signal: AbortSignal, measurementBridge?: GuideMeasurementBridge): Promise<LiveControlAuthorization>;
100
100
  endLiveGuide(input: GuideLaunchRecoveryInput, signal?: AbortSignal): Promise<{
101
101
  schemaVersion: 3;
102
102
  protocolVersion: 2;
@@ -104,7 +104,7 @@ export declare class RuntimeClient {
104
104
  status: "end_requested";
105
105
  launchRequestId: string;
106
106
  }>;
107
- launchGuide(intent: GuideLaunchIntent, admissionGrant: string, signal: AbortSignal): Promise<GuideLaunchResult>;
107
+ launchGuide(intent: GuideLaunchIntent, admissionGrant: string, signal: AbortSignal, measurementBridge?: GuideMeasurementBridge): Promise<GuideLaunchResult>;
108
108
  recoverGuideLaunch(input: GuideLaunchRecoveryInput, signal?: AbortSignal, keepalive?: boolean): Promise<GuideLaunchRecoveryResult>;
109
109
  linkGuideRecording(sessionId: string, input: GuideRecordingLinkInput, signal: AbortSignal): Promise<GuideRecordingLinkResult>;
110
110
  resume(sessionId: string, credential: string, path: string, protocolVersion: 1 | 2, signal: AbortSignal): Promise<LaunchResult>;
@@ -127,7 +127,9 @@ export declare class RuntimeClient {
127
127
  private postEmpty;
128
128
  private parseCompanionState;
129
129
  private parseMessengerConversation;
130
+ private postGuideLaunch;
130
131
  private postJson;
132
+ private postRawJson;
131
133
  private parseJson;
132
134
  private throwResponse;
133
135
  }
package/cjs/client.js CHANGED
@@ -2,6 +2,7 @@
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.RuntimeClient = exports.idempotencyKey = exports.isValidAssistSessionGrant = exports.isValidReplaySessionId = exports.MAX_ASSIST_SESSION_GRANT_LENGTH = exports.RuntimeClientError = void 0;
4
4
  const guideTypes_js_1 = require("./guideTypes.js");
5
+ const guideMeasurement_js_1 = require("./guideMeasurement.js");
5
6
  class RuntimeClientError extends Error {
6
7
  constructor(code, message, retryable, retryAfterMs, status) {
7
8
  super(message);
@@ -189,14 +190,14 @@ class RuntimeClient {
189
190
  async admitLiveGuide(intent, subjectCredential, signal) {
190
191
  return this.postJson("/ai-live-assist/v1/public/live/admissions", { ...intent, ...(subjectCredential ? { subjectCredential } : {}) }, {}, signal);
191
192
  }
192
- async launchLiveGuide(intent, admissionGrant, signal) {
193
- return this.postJson("/ai-live-assist/v1/public/live/launch", { ...intent, admissionGrant }, { "Idempotency-Key": intent.launchRequestId }, signal);
193
+ async launchLiveGuide(intent, admissionGrant, signal, measurementBridge) {
194
+ return this.postGuideLaunch("/ai-live-assist/v1/public/live/launch", intent, admissionGrant, signal, measurementBridge);
194
195
  }
195
196
  async endLiveGuide(input, signal) {
196
197
  return this.postJson("/ai-live-assist/v1/public/live/launches/end", input, {}, signal, true);
197
198
  }
198
- async launchGuide(intent, admissionGrant, signal) {
199
- return this.postJson("/ai-live-assist/v1/public/launch", { ...intent, admissionGrant }, { "Idempotency-Key": intent.launchRequestId }, signal);
199
+ async launchGuide(intent, admissionGrant, signal, measurementBridge) {
200
+ return this.postGuideLaunch("/ai-live-assist/v1/public/launch", intent, admissionGrant, signal, measurementBridge);
200
201
  }
201
202
  async recoverGuideLaunch(input, signal, keepalive = false) {
202
203
  return this.postJson("/ai-live-assist/v1/public/launches/recover", input, {}, signal, keepalive);
@@ -462,7 +463,44 @@ class RuntimeClient {
462
463
  inboxId: candidate.inboxId,
463
464
  };
464
465
  }
466
+ async postGuideLaunch(path, intent, admissionGrant, signal, bridge) {
467
+ // Serialize once: possession signs these exact bytes, including the native grant.
468
+ const rawBody = JSON.stringify({ ...intent, admissionGrant });
469
+ const headers = { 'Idempotency-Key': intent.launchRequestId };
470
+ if (intent.guideMeasurement !== undefined) {
471
+ const unavailable = () => new RuntimeClientError('GUIDE_MEASUREMENT_UNAVAILABLE', 'AI Guide could not secure this conversation. Please try again.', true, null, 409);
472
+ const assignment = intent.guideMeasurement.assignment;
473
+ const current = () => !signal.aborted && intent.clientVersion === guideMeasurement_js_1.GUIDE_MEASUREMENT_CLIENT_VERSION &&
474
+ this.clientVersion === guideMeasurement_js_1.GUIDE_MEASUREMENT_CLIENT_VERSION && (0, guideMeasurement_js_1.currentGuideMeasurementBridge)(bridge) && bridge.assignment === assignment;
475
+ if (!current() || !bridge)
476
+ throw unavailable();
477
+ try {
478
+ const authorization = await bridge.authorizeLaunch(`${this.baseUrl}${path}`, rawBody, signal);
479
+ if (!current() || !authorization || typeof authorization.current !== 'function')
480
+ throw unavailable();
481
+ // The bridge supplies only the two possession headers, never arbitrary request authority.
482
+ const names = ['X-Oxvo-Analytics-Receipt', 'X-Oxvo-Analytics-Proof'];
483
+ if (!authorization.headers || Object.keys(authorization.headers).length !== names.length)
484
+ throw unavailable();
485
+ for (const name of names) {
486
+ const value = authorization.headers[name];
487
+ if (typeof value !== 'string' || value.length < 1 || value.length > 8192 || !/^[\x21-\x7e]+$/.test(value))
488
+ throw unavailable();
489
+ headers[name] = value;
490
+ }
491
+ if (!current() || authorization.current() !== true || signal.aborted)
492
+ throw unavailable();
493
+ }
494
+ catch {
495
+ throw unavailable();
496
+ }
497
+ }
498
+ return this.postRawJson(path, rawBody, headers, signal, false, false, intent.guideMeasurement !== undefined);
499
+ }
465
500
  async postJson(path, body, extraHeaders, signal, keepalive = false, requireNoContent = false) {
501
+ return this.postRawJson(path, JSON.stringify(body), extraHeaders, signal, keepalive, requireNoContent);
502
+ }
503
+ async postRawJson(path, rawBody, extraHeaders, signal, keepalive = false, requireNoContent = false, rejectRedirect = false) {
466
504
  const response = await fetch(`${this.baseUrl}${path}`, {
467
505
  method: "POST",
468
506
  mode: "cors",
@@ -475,7 +513,8 @@ class RuntimeClient {
475
513
  "X-Request-Id": requestId(),
476
514
  ...extraHeaders,
477
515
  },
478
- body: JSON.stringify(body),
516
+ body: rawBody,
517
+ ...(rejectRedirect ? { redirect: 'error' } : {}),
479
518
  ...(keepalive ? { keepalive: true } : {}),
480
519
  ...(signal ? { signal } : {}),
481
520
  });
@@ -0,0 +1,158 @@
1
+ import { type CommerceBootstrap, type CommerceContext, type CommerceMarket, type CommerceOption, type CommerceStore, type LiveCommerceDisplayed, type RealtimeCommerceDisplayed } from './contracts.js';
2
+ export declare const COMMERCE_CART_SMALL_MESSAGE_MAX_BYTES = 4096;
3
+ export declare const COMMERCE_CART_MESSAGE_MAX_BYTES = 12000;
4
+ export declare const COMMERCE_CART_CONFIRMATION_MAX_AGE_MS = 30000;
5
+ export declare const COMMERCE_CART_GRANT_MAX_AGE_MS = 8000;
6
+ export type CommerceCartProvider = {
7
+ kind: 'realtime';
8
+ generationDigest: string;
9
+ } | {
10
+ kind: 'live';
11
+ taskId: string;
12
+ inputEpoch: number;
13
+ };
14
+ export type CommerceCartScope = {
15
+ schemaVersion: 1;
16
+ requestId: string;
17
+ operationId: string;
18
+ proposalChecksum: string;
19
+ contextDigest: string;
20
+ contextRevision: number;
21
+ pageId: string;
22
+ provider: CommerceCartProvider;
23
+ };
24
+ export type CommerceCartItem = {
25
+ productRef: string;
26
+ variantRef: string;
27
+ shopifyVariantId: string;
28
+ title: string;
29
+ productUrl: string;
30
+ selectedOptions: CommerceOption[];
31
+ quantity: number;
32
+ unitPrice: {
33
+ amount: string;
34
+ currency: string;
35
+ };
36
+ quantityRule: {
37
+ minimum: number;
38
+ maximum: number | null;
39
+ increment: number;
40
+ };
41
+ requiresSellingPlan: false;
42
+ requiresComponents: false;
43
+ };
44
+ type CartRequestSelection = {
45
+ requestId: string;
46
+ productRef: string;
47
+ variantRef: string;
48
+ quantity: number;
49
+ selectionDigest: string;
50
+ };
51
+ export type CommerceCartRequest = (Omit<LiveCommerceDisplayed, 'products'> | Omit<RealtimeCommerceDisplayed, 'products'>) & CartRequestSelection;
52
+ export type CommerceCartConfirmation = CommerceCartScope & {
53
+ guideId: string;
54
+ store: CommerceStore;
55
+ market: CommerceMarket;
56
+ item: CommerceCartItem;
57
+ expiresAt: string;
58
+ };
59
+ export type CommerceCartConfirmationResult = {
60
+ schemaVersion: 1;
61
+ operationId: string;
62
+ proposalChecksum: string;
63
+ approved: boolean;
64
+ };
65
+ export type CommerceCartGrant = CommerceCartScope & {
66
+ grant: string;
67
+ action: 'add';
68
+ store: CommerceStore;
69
+ market: CommerceMarket;
70
+ item: CommerceCartItem;
71
+ operationMarker: string;
72
+ expiresAt: string;
73
+ };
74
+ export type CommerceCartExecutionBegin = {
75
+ schemaVersion: 1;
76
+ operationId: string;
77
+ grant: string;
78
+ executionId: string;
79
+ cartDigest: string;
80
+ };
81
+ export type CommerceCartExecutionReady = {
82
+ schemaVersion: 1;
83
+ operationId: string;
84
+ executionId: string;
85
+ cartDigest: string;
86
+ requestMessageId: string;
87
+ state: 'prepared' | 'already_started';
88
+ expiresAt: string;
89
+ };
90
+ export type CommerceCartRequestOutcome = {
91
+ outcome: 'response';
92
+ httpStatus: number;
93
+ } | {
94
+ outcome: 'timeout' | 'network_error' | 'aborted' | 'unknown';
95
+ };
96
+ export type CommerceCartObservation = {
97
+ source: 'browser_cart';
98
+ observedAt: string;
99
+ currency: string;
100
+ shopifyVariantId: string;
101
+ operationMarker: string;
102
+ quantity: number;
103
+ lineKeyDigest: string | null;
104
+ };
105
+ export type CommerceCartExecutionResult = CommerceCartScope & {
106
+ executionId: string;
107
+ cartDigest: string;
108
+ request: CommerceCartRequestOutcome;
109
+ observation: CommerceCartObservation | null;
110
+ };
111
+ export type CommerceCartRejectedCode = 'quote_unavailable' | 'quote_changed' | 'policy_denied' | 'unsupported_selection' | 'busy' | 'context_changed' | 'conflict';
112
+ export type CommerceCartResultCode = CommerceCartRejectedCode | 'expired' | 'declined' | 'unconfirmed' | 'observed' | 'partial';
113
+ type ResultBase = {
114
+ schemaVersion: 1;
115
+ requestId: string;
116
+ operationId: string | null;
117
+ executionId: string | null;
118
+ observation?: CommerceCartObservation;
119
+ };
120
+ export type CommerceCartResult = ResultBase & ({
121
+ status: 'rejected';
122
+ code: CommerceCartRejectedCode;
123
+ } | {
124
+ status: 'cancelled';
125
+ code: 'declined' | 'context_changed';
126
+ } | {
127
+ status: 'expired';
128
+ code: 'expired';
129
+ } | {
130
+ status: 'unconfirmed';
131
+ code: 'unconfirmed';
132
+ } | {
133
+ status: 'observed';
134
+ code: 'observed';
135
+ operationId: string;
136
+ executionId: string;
137
+ observation: CommerceCartObservation;
138
+ } | {
139
+ status: 'partial';
140
+ code: 'partial';
141
+ operationId: string;
142
+ executionId: string;
143
+ observation: CommerceCartObservation;
144
+ });
145
+ export type CommerceCartReadyExpectation = Partial<Pick<CommerceCartExecutionReady, 'operationId' | 'executionId' | 'cartDigest' | 'requestMessageId'>>;
146
+ export type CommerceCartResultExpectation = Partial<Pick<CommerceCartResult, 'requestId' | 'operationId' | 'executionId'>>;
147
+ /** A confirmation is a bounded quote, never permission to mutate the cart. */
148
+ export declare function parseCommerceCartConfirmation(value: unknown, bootstrap: CommerceBootstrap, context: CommerceContext | null, expected?: Partial<CommerceCartScope>, now?: number): CommerceCartConfirmation | null;
149
+ /** The session must additionally bind this grant to its approved quote and
150
+ * current control lease. operationMarker is an independent server-issued UUID. */
151
+ export declare function parseCommerceCartGrant(value: unknown, bootstrap: CommerceBootstrap, context: CommerceContext | null, expected?: Partial<CommerceCartScope>, now?: number): CommerceCartGrant | null;
152
+ /** already_started retains the original executionId/cartDigest exactly. The
153
+ * caller must correlate operation/requestMessageId and must never replay POST. */
154
+ export declare function parseCommerceCartExecutionReady(value: unknown, expected?: CommerceCartReadyExpectation, now?: number): CommerceCartExecutionReady | null;
155
+ /** observed/partial are correlated browser reports, not server-verified facts.
156
+ * observedAt remains the reported timestamp; no invented recency restriction. */
157
+ export declare function parseCommerceCartResult(value: unknown, expected?: CommerceCartResultExpectation, now?: number): CommerceCartResult | null;
158
+ export {};