@oxvo/ai-live-assist 7.5.22 → 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.22";
37
+ readonly version = "7.5.25";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
@@ -242,6 +242,9 @@ class RealtimeCommerce {
242
242
  }
243
243
  },
244
244
  onDisplayed: (resultSetId, products) => {
245
+ // The empty-state UI is visible, but the protocol acknowledges product cards only.
246
+ if (products.length === 0)
247
+ return;
245
248
  this.context.refresh();
246
249
  if (!isCurrent() || resultSetId !== event.catalog.resultSetId ||
247
250
  !(0, contracts_js_1.isDisplayedCommerceProducts)(event.catalog, products))
@@ -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
  }
package/cjs/context.js CHANGED
@@ -1,10 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.PageContextCollector = exports.actionTargetFingerprint = void 0;
4
+ const textRedaction_generated_js_1 = require("./privacy/textRedaction.generated.js");
4
5
  const visualContext_js_1 = require("./visualContext.js");
5
6
  const MAX_TARGETS = 256;
6
7
  const MAX_TEXT_ITEMS = 256;
7
8
  const MAX_TOTAL_TEXT = 24000;
9
+ const MAX_RAW_TEXT_NODE = 96000;
8
10
  const MAX_OPTIONS = 100;
9
11
  const MAX_SELECTED_TEXT = 2000;
10
12
  const SELECTION_RETENTION_MS = 120000;
@@ -1257,22 +1259,60 @@ class PageContextCollector {
1257
1259
  const textElement = semanticTextElement && isRendered(semanticTextElement)
1258
1260
  ? semanticTextElement
1259
1261
  : node.nodeType === Node.TEXT_NODE ? parent : null;
1260
- const text = normalize(semanticTextElement?.getAttribute('aria-label') ??
1261
- (node.nodeType === Node.TEXT_NODE ? node.textContent ?? '' : ''), 500);
1262
+ const rawText = semanticTextElement?.getAttribute('aria-label') ??
1263
+ (node.nodeType === Node.TEXT_NODE ? node.textContent ?? '' : '');
1264
+ const normalizedText = normalize(rawText.slice(0, MAX_RAW_TEXT_NODE), MAX_RAW_TEXT_NODE);
1265
+ const text = normalizedText.slice(0, 500);
1262
1266
  if (parent &&
1263
1267
  textElement &&
1264
- text &&
1268
+ (text || rawText.length > MAX_RAW_TEXT_NODE) &&
1265
1269
  !parent.closest(PRIVATE_SELECTOR) &&
1266
1270
  !parent.closest('script,style,noscript,template,svg') &&
1267
1271
  !parent.closest('input,select,textarea,option') &&
1268
1272
  (!semanticTextElement || !capturedSemanticText.has(semanticTextElement)) &&
1269
- !belongsToInteractiveControl(textElement, text) &&
1273
+ !belongsToInteractiveControl(textElement, normalizedText) &&
1270
1274
  isRendered(textElement) &&
1271
1275
  sensitivityFor(textElement, nameFor(textElement)) === 'none') {
1272
1276
  const textId = this.textIds.get(node) ?? id('text');
1273
1277
  this.textIds.set(node, textId);
1274
- visibleText.push({ id: textId, text, provenance: 'page' });
1275
- totalText += text.length;
1278
+ // Fail closed on unusually large nodes instead of redacting a partial
1279
+ // credential or adding an unbounded full-node redaction pass.
1280
+ if (rawText.length > MAX_RAW_TEXT_NODE) {
1281
+ truncated = true;
1282
+ node = walker.nextNode();
1283
+ continue;
1284
+ }
1285
+ // Normalize the whole bounded node before the native text policy so
1286
+ // whitespace-separated credentials cannot evade redaction at a cut.
1287
+ const safeText = (0, textRedaction_generated_js_1.redactText)(normalizedText, MAX_TOTAL_TEXT + 1);
1288
+ let offset = 0;
1289
+ let chunkIndex = 0;
1290
+ while (offset < safeText.length && visibleText.length < MAX_TEXT_ITEMS && totalText < MAX_TOTAL_TEXT) {
1291
+ let end = Math.min(offset + 500, offset + MAX_TOTAL_TEXT - totalText, safeText.length);
1292
+ // Prefer sentence/word boundaries without reserving more payload.
1293
+ if (end < safeText.length) {
1294
+ const window = safeText.slice(offset, end);
1295
+ const sentences = Array.from(window.matchAll(/[.!?] (?=\S)/g));
1296
+ const sentenceEnd = sentences[sentences.length - 1]?.index;
1297
+ const wordEnd = window.lastIndexOf(' ');
1298
+ if (sentenceEnd !== undefined && sentenceEnd >= 249)
1299
+ end = offset + sentenceEnd + 2;
1300
+ else if (wordEnd > 0)
1301
+ end = offset + wordEnd + 1;
1302
+ }
1303
+ // A hard token/budget boundary must not split a UTF-16 pair.
1304
+ if (end < safeText.length && /[\uD800-\uDBFF]/.test(safeText[end - 1]))
1305
+ end -= 1;
1306
+ if (end === offset)
1307
+ break;
1308
+ const chunk = safeText.slice(offset, end);
1309
+ visibleText.push({ id: chunkIndex === 0 ? textId : `${textId}.${chunkIndex}`, text: chunk, provenance: 'page' });
1310
+ totalText += chunk.length;
1311
+ offset = end;
1312
+ chunkIndex += 1;
1313
+ }
1314
+ if (offset < safeText.length)
1315
+ truncated = true;
1276
1316
  if (semanticTextElement)
1277
1317
  capturedSemanticText.add(semanticTextElement);
1278
1318
  }
@@ -1,5 +1,5 @@
1
1
  import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
2
- export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.22";
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.22';
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.22";
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 = {
@@ -221,6 +221,9 @@ class LiveControlChannel {
221
221
  return true;
222
222
  }
223
223
  acknowledgeCommerceCatalog(value) {
224
+ // The empty-state UI is visible, but the protocol acknowledges product cards only.
225
+ if (value.products.length === 0)
226
+ return false;
224
227
  const current = this.commerceCatalog;
225
228
  const commerce = this.options.commerce;
226
229
  if (!this.commerceNegotiated || !current || !commerce || !this.commerceTask || !(0, contracts_js_1.parseLiveCommerceCatalog)(current, commerce.bootstrap, commerce.currentContext(), this.commerceTask, this.clock.wallNow(), { cartNegotiated: this.commerceCartNegotiated }) ||
@@ -428,7 +431,7 @@ class LiveControlChannel {
428
431
  stack.pop();
429
432
  else if (data.slice((match.index ?? 0) + match[0].length).trimStart().startsWith(':')) {
430
433
  const key = JSON.parse(match[0]);
431
- const keys = stack.at(-1);
434
+ const keys = stack[stack.length - 1];
432
435
  if (!keys || keys.has(key))
433
436
  throw unavailable();
434
437
  keys.add(key);
@@ -0,0 +1 @@
1
+ export declare const redactText: (value: string, maximum?: number) => string;
@@ -0,0 +1,29 @@
1
+ "use strict";
2
+ // Generated from ai-live-assist/src/security/textRedaction.ts. Do not edit.
3
+ // Source SHA256: 23840bc803a386b537b4104c4e8d92c7faa7ec0643efff8284bc825d7731e257
4
+ Object.defineProperty(exports, "__esModule", { value: true });
5
+ exports.redactText = void 0;
6
+ const secretValuePatterns = [
7
+ // Compact signed JWTs remain credentials even without a Bearer prefix or a
8
+ // secret-looking field name (for example guideMeasurement.assignment).
9
+ /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?![A-Za-z0-9_-])/g,
10
+ /\b(?:assignment[_ -]?credential|analytics[_ -]?(?:receipt|proof))["']?\s*[:=]\s*["']?[^\s,;"']{2,}["']?/gi,
11
+ /\b(?:password|passphrase|secret|token|api[_ -]?key|authorization|cookie|otp|one[- ]time(?: code)?|verification code|cvv|cvc|card number|routing number|iban|private[_ -]?key)\s*[:=]\s*["']?[^\s,;"']{2,}["']?/gi,
12
+ /\b(?:sk|rk|pk)-[A-Za-z0-9_-]{16,}\b/g,
13
+ /\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*\b/gi,
14
+ /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
15
+ /\b(?:\d[ -]*?){13,19}\b/g,
16
+ ];
17
+ const redactText = (value, maximum = 2000) => {
18
+ let redacted = value;
19
+ for (const pattern of secretValuePatterns)
20
+ redacted = redacted.replace(pattern, '[REDACTED]');
21
+ let safe = '';
22
+ for (let index = 0; index < redacted.length; index += 1) {
23
+ const character = redacted[index] ?? '';
24
+ const code = redacted.charCodeAt(index);
25
+ safe += code < 32 && ![9, 10, 13].includes(code) ? ' ' : character;
26
+ }
27
+ return safe.trim().slice(0, maximum);
28
+ };
29
+ exports.redactText = redactText;
package/cjs/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "7.5.22";
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.22';
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.22";
37
+ readonly version = "7.5.25";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
@@ -238,6 +238,9 @@ export class RealtimeCommerce {
238
238
  }
239
239
  },
240
240
  onDisplayed: (resultSetId, products) => {
241
+ // The empty-state UI is visible, but the protocol acknowledges product cards only.
242
+ if (products.length === 0)
243
+ return;
241
244
  this.context.refresh();
242
245
  if (!isCurrent() || resultSetId !== event.catalog.resultSetId ||
243
246
  !isDisplayedCommerceProducts(event.catalog, products))
@@ -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
  }
package/lib/context.js CHANGED
@@ -1,7 +1,9 @@
1
+ import { redactText } from './privacy/textRedaction.generated.js';
1
2
  import { renderSanitizedLayout } from './visualContext.js';
2
3
  const MAX_TARGETS = 256;
3
4
  const MAX_TEXT_ITEMS = 256;
4
5
  const MAX_TOTAL_TEXT = 24000;
6
+ const MAX_RAW_TEXT_NODE = 96000;
5
7
  const MAX_OPTIONS = 100;
6
8
  const MAX_SELECTED_TEXT = 2000;
7
9
  const SELECTION_RETENTION_MS = 120000;
@@ -1253,22 +1255,60 @@ export class PageContextCollector {
1253
1255
  const textElement = semanticTextElement && isRendered(semanticTextElement)
1254
1256
  ? semanticTextElement
1255
1257
  : node.nodeType === Node.TEXT_NODE ? parent : null;
1256
- const text = normalize(semanticTextElement?.getAttribute('aria-label') ??
1257
- (node.nodeType === Node.TEXT_NODE ? node.textContent ?? '' : ''), 500);
1258
+ const rawText = semanticTextElement?.getAttribute('aria-label') ??
1259
+ (node.nodeType === Node.TEXT_NODE ? node.textContent ?? '' : '');
1260
+ const normalizedText = normalize(rawText.slice(0, MAX_RAW_TEXT_NODE), MAX_RAW_TEXT_NODE);
1261
+ const text = normalizedText.slice(0, 500);
1258
1262
  if (parent &&
1259
1263
  textElement &&
1260
- text &&
1264
+ (text || rawText.length > MAX_RAW_TEXT_NODE) &&
1261
1265
  !parent.closest(PRIVATE_SELECTOR) &&
1262
1266
  !parent.closest('script,style,noscript,template,svg') &&
1263
1267
  !parent.closest('input,select,textarea,option') &&
1264
1268
  (!semanticTextElement || !capturedSemanticText.has(semanticTextElement)) &&
1265
- !belongsToInteractiveControl(textElement, text) &&
1269
+ !belongsToInteractiveControl(textElement, normalizedText) &&
1266
1270
  isRendered(textElement) &&
1267
1271
  sensitivityFor(textElement, nameFor(textElement)) === 'none') {
1268
1272
  const textId = this.textIds.get(node) ?? id('text');
1269
1273
  this.textIds.set(node, textId);
1270
- visibleText.push({ id: textId, text, provenance: 'page' });
1271
- totalText += text.length;
1274
+ // Fail closed on unusually large nodes instead of redacting a partial
1275
+ // credential or adding an unbounded full-node redaction pass.
1276
+ if (rawText.length > MAX_RAW_TEXT_NODE) {
1277
+ truncated = true;
1278
+ node = walker.nextNode();
1279
+ continue;
1280
+ }
1281
+ // Normalize the whole bounded node before the native text policy so
1282
+ // whitespace-separated credentials cannot evade redaction at a cut.
1283
+ const safeText = redactText(normalizedText, MAX_TOTAL_TEXT + 1);
1284
+ let offset = 0;
1285
+ let chunkIndex = 0;
1286
+ while (offset < safeText.length && visibleText.length < MAX_TEXT_ITEMS && totalText < MAX_TOTAL_TEXT) {
1287
+ let end = Math.min(offset + 500, offset + MAX_TOTAL_TEXT - totalText, safeText.length);
1288
+ // Prefer sentence/word boundaries without reserving more payload.
1289
+ if (end < safeText.length) {
1290
+ const window = safeText.slice(offset, end);
1291
+ const sentences = Array.from(window.matchAll(/[.!?] (?=\S)/g));
1292
+ const sentenceEnd = sentences[sentences.length - 1]?.index;
1293
+ const wordEnd = window.lastIndexOf(' ');
1294
+ if (sentenceEnd !== undefined && sentenceEnd >= 249)
1295
+ end = offset + sentenceEnd + 2;
1296
+ else if (wordEnd > 0)
1297
+ end = offset + wordEnd + 1;
1298
+ }
1299
+ // A hard token/budget boundary must not split a UTF-16 pair.
1300
+ if (end < safeText.length && /[\uD800-\uDBFF]/.test(safeText[end - 1]))
1301
+ end -= 1;
1302
+ if (end === offset)
1303
+ break;
1304
+ const chunk = safeText.slice(offset, end);
1305
+ visibleText.push({ id: chunkIndex === 0 ? textId : `${textId}.${chunkIndex}`, text: chunk, provenance: 'page' });
1306
+ totalText += chunk.length;
1307
+ offset = end;
1308
+ chunkIndex += 1;
1309
+ }
1310
+ if (offset < safeText.length)
1311
+ truncated = true;
1272
1312
  if (semanticTextElement)
1273
1313
  capturedSemanticText.add(semanticTextElement);
1274
1314
  }
@@ -1,5 +1,5 @@
1
1
  import type { GuideMeasurementBridge, GuideMeasurementIntent } from './guideTypes.js';
2
- export declare const GUIDE_MEASUREMENT_CLIENT_VERSION = "7.5.22";
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.22';
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.22";
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 = {
@@ -218,6 +218,9 @@ export class LiveControlChannel {
218
218
  return true;
219
219
  }
220
220
  acknowledgeCommerceCatalog(value) {
221
+ // The empty-state UI is visible, but the protocol acknowledges product cards only.
222
+ if (value.products.length === 0)
223
+ return false;
221
224
  const current = this.commerceCatalog;
222
225
  const commerce = this.options.commerce;
223
226
  if (!this.commerceNegotiated || !current || !commerce || !this.commerceTask || !parseLiveCommerceCatalog(current, commerce.bootstrap, commerce.currentContext(), this.commerceTask, this.clock.wallNow(), { cartNegotiated: this.commerceCartNegotiated }) ||
@@ -425,7 +428,7 @@ export class LiveControlChannel {
425
428
  stack.pop();
426
429
  else if (data.slice((match.index ?? 0) + match[0].length).trimStart().startsWith(':')) {
427
430
  const key = JSON.parse(match[0]);
428
- const keys = stack.at(-1);
431
+ const keys = stack[stack.length - 1];
429
432
  if (!keys || keys.has(key))
430
433
  throw unavailable();
431
434
  keys.add(key);
@@ -0,0 +1 @@
1
+ export declare const redactText: (value: string, maximum?: number) => string;
@@ -0,0 +1,25 @@
1
+ // Generated from ai-live-assist/src/security/textRedaction.ts. Do not edit.
2
+ // Source SHA256: 23840bc803a386b537b4104c4e8d92c7faa7ec0643efff8284bc825d7731e257
3
+ const secretValuePatterns = [
4
+ // Compact signed JWTs remain credentials even without a Bearer prefix or a
5
+ // secret-looking field name (for example guideMeasurement.assignment).
6
+ /\beyJ[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+\.[A-Za-z0-9_-]+(?![A-Za-z0-9_-])/g,
7
+ /\b(?:assignment[_ -]?credential|analytics[_ -]?(?:receipt|proof))["']?\s*[:=]\s*["']?[^\s,;"']{2,}["']?/gi,
8
+ /\b(?:password|passphrase|secret|token|api[_ -]?key|authorization|cookie|otp|one[- ]time(?: code)?|verification code|cvv|cvc|card number|routing number|iban|private[_ -]?key)\s*[:=]\s*["']?[^\s,;"']{2,}["']?/gi,
9
+ /\b(?:sk|rk|pk)-[A-Za-z0-9_-]{16,}\b/g,
10
+ /\bBearer\s+[A-Za-z0-9._~+/-]{12,}=*\b/gi,
11
+ /\b(?:AKIA|ASIA)[A-Z0-9]{16}\b/g,
12
+ /\b(?:\d[ -]*?){13,19}\b/g,
13
+ ];
14
+ export const redactText = (value, maximum = 2000) => {
15
+ let redacted = value;
16
+ for (const pattern of secretValuePatterns)
17
+ redacted = redacted.replace(pattern, '[REDACTED]');
18
+ let safe = '';
19
+ for (let index = 0; index < redacted.length; index += 1) {
20
+ const character = redacted[index] ?? '';
21
+ const code = redacted.charCodeAt(index);
22
+ safe += code < 32 && ![9, 10, 13].includes(code) ? ' ' : character;
23
+ }
24
+ return safe.trim().slice(0, maximum);
25
+ };
package/lib/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "7.5.22";
1
+ export declare const VERSION = "7.5.25";
package/lib/version.js CHANGED
@@ -1 +1 @@
1
- export const VERSION = '7.5.22';
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.22",
4
+ "version": "7.5.25",
5
5
  "keywords": [
6
6
  "ai-live-assist",
7
7
  "webrtc",
@@ -44,12 +44,13 @@
44
44
  "access": "public"
45
45
  },
46
46
  "scripts": {
47
- "build": "node scripts/generateLocales.mjs && rm -rf lib cjs && tsc --project tsconfig.json && tsc --project tsconfig-cjs.json && printf '{ \"type\": \"commonjs\" }\\n' > cjs/package.json",
47
+ "build": "node scripts/generateTextRedaction.mjs --check && node scripts/generateLocales.mjs && rm -rf lib cjs && tsc --project tsconfig.json && tsc --project tsconfig-cjs.json && printf '{ \"type\": \"commonjs\" }\\n' > cjs/package.json",
48
48
  "locales:generate": "node scripts/generateLocales.mjs",
49
49
  "lint": "eslint src --ext .ts --max-warnings=0",
50
- "test": "jest --coverage=false --runInBand",
51
- "test:ci": "jest --coverage=true --runInBand",
52
- "prepublishOnly": "bun run test && bun run build"
50
+ "test": "node scripts/generateTextRedaction.mjs --check && jest --coverage=false --runInBand",
51
+ "test:ci": "node scripts/generateTextRedaction.mjs --check && jest --coverage=true --runInBand",
52
+ "prepublishOnly": "bun run test && bun run build",
53
+ "text-redaction:generate": "node scripts/generateTextRedaction.mjs"
53
54
  },
54
55
  "peerDependencies": {
55
56
  "@oxvo/browser": ">=7.4.50"