@oxvo/ai-live-assist 7.5.23 → 7.5.25

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.
@@ -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.23";
37
+ readonly version = "7.5.25";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
@@ -217,7 +217,9 @@ async function request(path, body, onResponse) {
217
217
  response.status > 599)
218
218
  throw new AjaxTransportError("network_error");
219
219
  onResponse?.(response.status);
220
- if (!/^application\/json(?:;|$)/iu.test(response.headers.get("content-type") ?? "") ||
220
+ if (
221
+ // Shopify's Ajax .js endpoints also serve JSON as text/javascript.
222
+ !/^(?:application\/json|text\/javascript)(?:;|$)/iu.test(response.headers.get("content-type") ?? "") ||
221
223
  Number(response.headers.get("content-length") ?? "0") > RESPONSE_BYTES ||
222
224
  response.redirected)
223
225
  throw new Error("transport");
@@ -296,6 +298,7 @@ function parseCart(value) {
296
298
  items,
297
299
  };
298
300
  }
301
+ const emptyCart = (cart) => cart.itemCount === 0 && cart.items.length === 0;
299
302
  async function readCart(root) {
300
303
  const response = await request(`${root}cart.js`);
301
304
  if (response.status !== 200)
@@ -475,6 +478,15 @@ function readLedger(key) {
475
478
  /^[0-9a-f]{64}$/u.test(entry.intentDigest) &&
476
479
  typeof entry.cartDigest === "string" &&
477
480
  /^[0-9a-f]{64}$/u.test(entry.cartDigest) &&
481
+ (entry.initialCartEmpty === undefined ||
482
+ typeof entry.initialCartEmpty === "boolean") &&
483
+ (entry.initialCartEmpty !== true || entry.prepared != null) &&
484
+ (entry.materializedCartDigest === undefined ||
485
+ (entry.initialCartEmpty === true &&
486
+ entry.resolved === true &&
487
+ entry.observation != null &&
488
+ typeof entry.materializedCartDigest === "string" &&
489
+ /^[0-9a-f]{64}$/u.test(entry.materializedCartDigest))) &&
478
490
  count(entry.expiresAt) &&
479
491
  (entry.request == null || validRequestOutcome(entry.request)) &&
480
492
  (entry.prepared == null ||
@@ -786,12 +798,14 @@ class ShopifyCartExecutor {
786
798
  BigInt(Number.MAX_SAFE_INTEGER))
787
799
  return result("unavailable", "invalid_request");
788
800
  let cartDigest;
801
+ let initialCartEmpty = false;
789
802
  let operationAlreadyVisible = false;
790
803
  try {
791
804
  const cart = await readCart(paths.root);
792
805
  if (cart.currency !== prepared.market.currency)
793
806
  return result("conflict", "cart_changed");
794
807
  cartDigest = await sha(cart.token);
808
+ initialCartEmpty = emptyCart(cart);
795
809
  operationAlreadyVisible = cart.items.some((line) => object(line.properties) &&
796
810
  line.properties[PROPERTY] === prepared.operationMarker);
797
811
  // An existing marker is reconciliation-only. Native must identify the original admission.
@@ -829,6 +843,7 @@ class ShopifyCartExecutor {
829
843
  executionId,
830
844
  intentDigest: digest,
831
845
  cartDigest,
846
+ initialCartEmpty,
832
847
  expiresAt: Date.parse(prepared.expiresAt),
833
848
  request: null,
834
849
  prepared: publicPrepared(prepared),
@@ -845,12 +860,16 @@ class ShopifyCartExecutor {
845
860
  if (Date.parse(claim.expiresAt) <= Date.now() ||
846
861
  Date.parse(prepared.expiresAt) <= Date.now())
847
862
  return abort("uncertain", "expired");
863
+ let cartChanged = false;
848
864
  try {
849
- // Product/native reads take time. Refuse a known cart switch; Ajax still has a cookie TOCTOU.
865
+ // An unmaterialized empty Shopify cart can receive a new opaque token on every GET.
866
+ // Both reads must still be empty. Nonempty carts retain strict token identity.
850
867
  const finalCart = await readCart(paths.root);
851
- if (finalCart.currency !== prepared.market.currency ||
852
- (await sha(finalCart.token)) !== cartDigest)
853
- return abort("conflict", "cart_changed");
868
+ cartChanged =
869
+ finalCart.currency !== prepared.market.currency ||
870
+ (initialCartEmpty
871
+ ? !emptyCart(finalCart)
872
+ : (await sha(finalCart.token)) !== cartDigest);
854
873
  operationAlreadyVisible || (operationAlreadyVisible = finalCart.items.some((line) => object(line.properties) &&
855
874
  line.properties[PROPERTY] === prepared.operationMarker));
856
875
  }
@@ -875,6 +894,8 @@ class ShopifyCartExecutor {
875
894
  : abort("conflict", "invalid_request");
876
895
  if (entries.some((entry) => pendingEntry(entry, prepared.reportSessionId)))
877
896
  return abort("uncertain", "previous_operation_unresolved");
897
+ if (cartChanged)
898
+ return abort("conflict", "cart_changed");
878
899
  if (operationAlreadyVisible)
879
900
  return abort("uncertain", "execution_unverified");
880
901
  saveStarted(key, entries, original);
@@ -1011,7 +1032,7 @@ class ShopifyCartExecutor {
1011
1032
  storeRef: prepared.store.storeRef,
1012
1033
  productRef: prepared.productRef,
1013
1034
  variantRef: prepared.variantRef,
1014
- cartDigest,
1035
+ cartDigest: execution?.cartDigest ?? cartDigest,
1015
1036
  lineDigest: line &&
1016
1037
  typeof line.key === "string" &&
1017
1038
  line.key.length > 0 &&
@@ -1026,7 +1047,26 @@ class ShopifyCartExecutor {
1026
1047
  let status = "uncertain";
1027
1048
  let reason = "not_observed";
1028
1049
  const expected = ajaxPrice(prepared.unitPrice.amount, prepared.unitPrice.currency);
1029
- if ((execution && execution.cartDigest !== cartDigest) ||
1050
+ const intentDigest = execution ? await sha(intent(prepared)) : null;
1051
+ let retained;
1052
+ if (execution && intentDigest) {
1053
+ try {
1054
+ retained = readLedger(ledgerKey(prepared)).find((entry) => sameStarted(entry, {
1055
+ ...execution,
1056
+ operationId: prepared.operationId,
1057
+ intentDigest,
1058
+ }));
1059
+ }
1060
+ catch {
1061
+ // Lost/corrupt storage cannot establish an empty start or relax token identity.
1062
+ }
1063
+ }
1064
+ const firstEmptyMaterialization = retained?.initialCartEmpty === true &&
1065
+ retained.materializedCartDigest === undefined &&
1066
+ !retained.resolved;
1067
+ const tokenMatches = !execution ||
1068
+ (retained?.materializedCartDigest ?? execution.cartDigest) === cartDigest;
1069
+ if ((!tokenMatches && !firstEmptyMaterialization) ||
1030
1070
  cart.currency !== prepared.market.currency) {
1031
1071
  status = "conflict";
1032
1072
  reason = "cart_changed";
@@ -1067,9 +1107,13 @@ class ShopifyCartExecutor {
1067
1107
  reason = "line_changed";
1068
1108
  }
1069
1109
  }
1070
- // Missing retained state cannot be replaced by today's token or a caller's
1071
- // new execution ID. Native recovery must provide the original bound values.
1072
- // Wire observations are facts about the original cart, never inferred from a mismatched line.
1110
+ else if (!tokenMatches && !emptyCart(cart)) {
1111
+ status = "conflict";
1112
+ reason = "cart_changed";
1113
+ }
1114
+ // Only a retained empty start permits the first materialized token, and only
1115
+ // the exact marked line above can bind it. Native execution/report identity never changes.
1116
+ // Missing retained state still requires the original native-bound token.
1073
1117
  const observation = execution &&
1074
1118
  (status === "confirmed" ||
1075
1119
  status === "partial" ||
@@ -1087,19 +1131,20 @@ class ShopifyCartExecutor {
1087
1131
  if (execution && observation && observation.quantity > 0) {
1088
1132
  try {
1089
1133
  const key = ledgerKey(prepared);
1090
- const digest = await sha(intent(prepared));
1091
1134
  const entries = readLedger(key);
1092
1135
  const entry = entries.find((candidate) => sameStarted(candidate, {
1093
1136
  operationId: prepared.operationId,
1094
1137
  executionId: execution.executionId,
1095
1138
  cartDigest: execution.cartDigest,
1096
- intentDigest: digest,
1139
+ intentDigest: intentDigest,
1097
1140
  }));
1098
1141
  if (entry && !entry.resolved) {
1099
1142
  entry.prepared ?? (entry.prepared = publicPrepared(prepared));
1100
1143
  entry.request ?? (entry.request = execution.request);
1101
1144
  entry.observation = observation;
1102
1145
  entry.resolved = true;
1146
+ if (entry.initialCartEmpty === true)
1147
+ entry.materializedCartDigest = cartDigest;
1103
1148
  saveLedger(key, entries);
1104
1149
  }
1105
1150
  }
@@ -1,5 +1,5 @@
1
1
  import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
2
- export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.23";
2
+ export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.25";
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;
@@ -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.23';
7
+ exports.GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.25';
8
8
  function isGuideMeasurementIntent(value) {
9
9
  if (!value || typeof value !== 'object' || Array.isArray(value))
10
10
  return false;
@@ -1,6 +1,6 @@
1
1
  import { type LiveDuplexMediaOptions, type LiveDuplexMediaDependencies } from './liveDuplexMedia.js';
2
2
  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.23";
3
+ export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.25";
4
4
  export declare const LIVE_CONTROL_CLIENT_CAPABILITIES: readonly ["live_duplex_v1", "live_local_wake_v1", "live_fragment_captions_v1"];
5
5
  declare const phases: readonly ["voice_off", "local_listening", "wake_buffering", "starting", "active", "tentative_idle", "closing", "uncertain", "muted", "suspended", "budget_blocked", "ended"];
6
6
  export type LiveControlState = {
package/cjs/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "7.5.23";
1
+ export declare const VERSION = "7.5.25";
package/cjs/version.js CHANGED
@@ -1,4 +1,4 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.VERSION = void 0;
4
- exports.VERSION = '7.5.23';
4
+ exports.VERSION = '7.5.25';
@@ -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.23";
37
+ readonly version = "7.5.25";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
@@ -213,7 +213,9 @@ async function request(path, body, onResponse) {
213
213
  response.status > 599)
214
214
  throw new AjaxTransportError("network_error");
215
215
  onResponse?.(response.status);
216
- if (!/^application\/json(?:;|$)/iu.test(response.headers.get("content-type") ?? "") ||
216
+ if (
217
+ // Shopify's Ajax .js endpoints also serve JSON as text/javascript.
218
+ !/^(?:application\/json|text\/javascript)(?:;|$)/iu.test(response.headers.get("content-type") ?? "") ||
217
219
  Number(response.headers.get("content-length") ?? "0") > RESPONSE_BYTES ||
218
220
  response.redirected)
219
221
  throw new Error("transport");
@@ -292,6 +294,7 @@ function parseCart(value) {
292
294
  items,
293
295
  };
294
296
  }
297
+ const emptyCart = (cart) => cart.itemCount === 0 && cart.items.length === 0;
295
298
  async function readCart(root) {
296
299
  const response = await request(`${root}cart.js`);
297
300
  if (response.status !== 200)
@@ -471,6 +474,15 @@ function readLedger(key) {
471
474
  /^[0-9a-f]{64}$/u.test(entry.intentDigest) &&
472
475
  typeof entry.cartDigest === "string" &&
473
476
  /^[0-9a-f]{64}$/u.test(entry.cartDigest) &&
477
+ (entry.initialCartEmpty === undefined ||
478
+ typeof entry.initialCartEmpty === "boolean") &&
479
+ (entry.initialCartEmpty !== true || entry.prepared != null) &&
480
+ (entry.materializedCartDigest === undefined ||
481
+ (entry.initialCartEmpty === true &&
482
+ entry.resolved === true &&
483
+ entry.observation != null &&
484
+ typeof entry.materializedCartDigest === "string" &&
485
+ /^[0-9a-f]{64}$/u.test(entry.materializedCartDigest))) &&
474
486
  count(entry.expiresAt) &&
475
487
  (entry.request == null || validRequestOutcome(entry.request)) &&
476
488
  (entry.prepared == null ||
@@ -782,12 +794,14 @@ export class ShopifyCartExecutor {
782
794
  BigInt(Number.MAX_SAFE_INTEGER))
783
795
  return result("unavailable", "invalid_request");
784
796
  let cartDigest;
797
+ let initialCartEmpty = false;
785
798
  let operationAlreadyVisible = false;
786
799
  try {
787
800
  const cart = await readCart(paths.root);
788
801
  if (cart.currency !== prepared.market.currency)
789
802
  return result("conflict", "cart_changed");
790
803
  cartDigest = await sha(cart.token);
804
+ initialCartEmpty = emptyCart(cart);
791
805
  operationAlreadyVisible = cart.items.some((line) => object(line.properties) &&
792
806
  line.properties[PROPERTY] === prepared.operationMarker);
793
807
  // An existing marker is reconciliation-only. Native must identify the original admission.
@@ -825,6 +839,7 @@ export class ShopifyCartExecutor {
825
839
  executionId,
826
840
  intentDigest: digest,
827
841
  cartDigest,
842
+ initialCartEmpty,
828
843
  expiresAt: Date.parse(prepared.expiresAt),
829
844
  request: null,
830
845
  prepared: publicPrepared(prepared),
@@ -841,12 +856,16 @@ export class ShopifyCartExecutor {
841
856
  if (Date.parse(claim.expiresAt) <= Date.now() ||
842
857
  Date.parse(prepared.expiresAt) <= Date.now())
843
858
  return abort("uncertain", "expired");
859
+ let cartChanged = false;
844
860
  try {
845
- // Product/native reads take time. Refuse a known cart switch; Ajax still has a cookie TOCTOU.
861
+ // An unmaterialized empty Shopify cart can receive a new opaque token on every GET.
862
+ // Both reads must still be empty. Nonempty carts retain strict token identity.
846
863
  const finalCart = await readCart(paths.root);
847
- if (finalCart.currency !== prepared.market.currency ||
848
- (await sha(finalCart.token)) !== cartDigest)
849
- return abort("conflict", "cart_changed");
864
+ cartChanged =
865
+ finalCart.currency !== prepared.market.currency ||
866
+ (initialCartEmpty
867
+ ? !emptyCart(finalCart)
868
+ : (await sha(finalCart.token)) !== cartDigest);
850
869
  operationAlreadyVisible || (operationAlreadyVisible = finalCart.items.some((line) => object(line.properties) &&
851
870
  line.properties[PROPERTY] === prepared.operationMarker));
852
871
  }
@@ -871,6 +890,8 @@ export class ShopifyCartExecutor {
871
890
  : abort("conflict", "invalid_request");
872
891
  if (entries.some((entry) => pendingEntry(entry, prepared.reportSessionId)))
873
892
  return abort("uncertain", "previous_operation_unresolved");
893
+ if (cartChanged)
894
+ return abort("conflict", "cart_changed");
874
895
  if (operationAlreadyVisible)
875
896
  return abort("uncertain", "execution_unverified");
876
897
  saveStarted(key, entries, original);
@@ -1007,7 +1028,7 @@ export class ShopifyCartExecutor {
1007
1028
  storeRef: prepared.store.storeRef,
1008
1029
  productRef: prepared.productRef,
1009
1030
  variantRef: prepared.variantRef,
1010
- cartDigest,
1031
+ cartDigest: execution?.cartDigest ?? cartDigest,
1011
1032
  lineDigest: line &&
1012
1033
  typeof line.key === "string" &&
1013
1034
  line.key.length > 0 &&
@@ -1022,7 +1043,26 @@ export class ShopifyCartExecutor {
1022
1043
  let status = "uncertain";
1023
1044
  let reason = "not_observed";
1024
1045
  const expected = ajaxPrice(prepared.unitPrice.amount, prepared.unitPrice.currency);
1025
- if ((execution && execution.cartDigest !== cartDigest) ||
1046
+ const intentDigest = execution ? await sha(intent(prepared)) : null;
1047
+ let retained;
1048
+ if (execution && intentDigest) {
1049
+ try {
1050
+ retained = readLedger(ledgerKey(prepared)).find((entry) => sameStarted(entry, {
1051
+ ...execution,
1052
+ operationId: prepared.operationId,
1053
+ intentDigest,
1054
+ }));
1055
+ }
1056
+ catch {
1057
+ // Lost/corrupt storage cannot establish an empty start or relax token identity.
1058
+ }
1059
+ }
1060
+ const firstEmptyMaterialization = retained?.initialCartEmpty === true &&
1061
+ retained.materializedCartDigest === undefined &&
1062
+ !retained.resolved;
1063
+ const tokenMatches = !execution ||
1064
+ (retained?.materializedCartDigest ?? execution.cartDigest) === cartDigest;
1065
+ if ((!tokenMatches && !firstEmptyMaterialization) ||
1026
1066
  cart.currency !== prepared.market.currency) {
1027
1067
  status = "conflict";
1028
1068
  reason = "cart_changed";
@@ -1063,9 +1103,13 @@ export class ShopifyCartExecutor {
1063
1103
  reason = "line_changed";
1064
1104
  }
1065
1105
  }
1066
- // Missing retained state cannot be replaced by today's token or a caller's
1067
- // new execution ID. Native recovery must provide the original bound values.
1068
- // Wire observations are facts about the original cart, never inferred from a mismatched line.
1106
+ else if (!tokenMatches && !emptyCart(cart)) {
1107
+ status = "conflict";
1108
+ reason = "cart_changed";
1109
+ }
1110
+ // Only a retained empty start permits the first materialized token, and only
1111
+ // the exact marked line above can bind it. Native execution/report identity never changes.
1112
+ // Missing retained state still requires the original native-bound token.
1069
1113
  const observation = execution &&
1070
1114
  (status === "confirmed" ||
1071
1115
  status === "partial" ||
@@ -1083,19 +1127,20 @@ export class ShopifyCartExecutor {
1083
1127
  if (execution && observation && observation.quantity > 0) {
1084
1128
  try {
1085
1129
  const key = ledgerKey(prepared);
1086
- const digest = await sha(intent(prepared));
1087
1130
  const entries = readLedger(key);
1088
1131
  const entry = entries.find((candidate) => sameStarted(candidate, {
1089
1132
  operationId: prepared.operationId,
1090
1133
  executionId: execution.executionId,
1091
1134
  cartDigest: execution.cartDigest,
1092
- intentDigest: digest,
1135
+ intentDigest: intentDigest,
1093
1136
  }));
1094
1137
  if (entry && !entry.resolved) {
1095
1138
  entry.prepared ?? (entry.prepared = publicPrepared(prepared));
1096
1139
  entry.request ?? (entry.request = execution.request);
1097
1140
  entry.observation = observation;
1098
1141
  entry.resolved = true;
1142
+ if (entry.initialCartEmpty === true)
1143
+ entry.materializedCartDigest = cartDigest;
1099
1144
  saveLedger(key, entries);
1100
1145
  }
1101
1146
  }
@@ -1,5 +1,5 @@
1
1
  import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
2
- export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.23";
2
+ export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.25";
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;
@@ -1,4 +1,4 @@
1
- export const GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.23';
1
+ export const GUIDE_MEASUREMENT_CLIENT_VERSION = '7.5.25';
2
2
  export function isGuideMeasurementIntent(value) {
3
3
  if (!value || typeof value !== 'object' || Array.isArray(value))
4
4
  return false;
@@ -1,6 +1,6 @@
1
1
  import { type LiveDuplexMediaOptions, type LiveDuplexMediaDependencies } from './liveDuplexMedia.js';
2
2
  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.23";
3
+ export declare const LIVE_CONTROL_CLIENT_VERSION = "7.5.25";
4
4
  export declare const LIVE_CONTROL_CLIENT_CAPABILITIES: readonly ["live_duplex_v1", "live_local_wake_v1", "live_fragment_captions_v1"];
5
5
  declare const phases: readonly ["voice_off", "local_listening", "wake_buffering", "starting", "active", "tentative_idle", "closing", "uncertain", "muted", "suspended", "budget_blocked", "ended"];
6
6
  export type LiveControlState = {
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "7.5.23";
1
+ export declare const VERSION = "7.5.25";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '7.5.23';
1
+ export const VERSION = '7.5.25';
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oxvo/ai-live-assist",
3
3
  "description": "Secure AI Guide browser plugin for OXVO Sessions.",
4
- "version": "7.5.23",
4
+ "version": "7.5.25",
5
5
  "keywords": [
6
6
  "ai-live-assist",
7
7
  "webrtc",