@oxvo/ai-live-assist 7.5.25 → 7.5.27

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (59) hide show
  1. package/cjs/AiLiveAssist.d.ts +1 -1
  2. package/cjs/client.d.ts +7 -0
  3. package/cjs/client.js +12 -0
  4. package/cjs/commerce/cartSession.d.ts +6 -0
  5. package/cjs/commerce/cartSession.js +124 -21
  6. package/cjs/commerce/shopifyCart.d.ts +3 -1
  7. package/cjs/commerce/shopifyCart.js +24 -9
  8. package/cjs/guideMeasurement.d.ts +1 -1
  9. package/cjs/guideMeasurement.js +1 -1
  10. package/cjs/liveControlChannel.d.ts +3 -1
  11. package/cjs/liveControlChannel.js +4 -1
  12. package/cjs/liveGuideWidget.d.ts +20 -2
  13. package/cjs/liveGuideWidget.js +39 -8
  14. package/cjs/merchantPreview.d.ts +5 -0
  15. package/cjs/merchantPreview.js +148 -0
  16. package/cjs/merchantPreviewAdmission.d.ts +32 -0
  17. package/cjs/merchantPreviewAdmission.js +184 -0
  18. package/cjs/merchantPreviewOrigins.d.ts +6 -0
  19. package/cjs/merchantPreviewOrigins.js +24 -0
  20. package/cjs/merchantPreviewStorage.d.ts +9 -0
  21. package/cjs/merchantPreviewStorage.js +56 -0
  22. package/cjs/merchantPreviewTypes.d.ts +57 -0
  23. package/cjs/merchantPreviewTypes.js +2 -0
  24. package/cjs/standalone.d.ts +2 -0
  25. package/cjs/standalone.js +3 -1
  26. package/cjs/ui.d.ts +1 -0
  27. package/cjs/ui.js +8 -0
  28. package/cjs/version.d.ts +1 -1
  29. package/cjs/version.js +1 -1
  30. package/lib/AiLiveAssist.d.ts +1 -1
  31. package/lib/client.d.ts +7 -0
  32. package/lib/client.js +12 -0
  33. package/lib/commerce/cartSession.d.ts +6 -0
  34. package/lib/commerce/cartSession.js +124 -21
  35. package/lib/commerce/shopifyCart.d.ts +3 -1
  36. package/lib/commerce/shopifyCart.js +24 -9
  37. package/lib/guideMeasurement.d.ts +1 -1
  38. package/lib/guideMeasurement.js +1 -1
  39. package/lib/liveControlChannel.d.ts +3 -1
  40. package/lib/liveControlChannel.js +4 -1
  41. package/lib/liveGuideWidget.d.ts +20 -2
  42. package/lib/liveGuideWidget.js +39 -8
  43. package/lib/merchantPreview.d.ts +5 -0
  44. package/lib/merchantPreview.js +144 -0
  45. package/lib/merchantPreviewAdmission.d.ts +32 -0
  46. package/lib/merchantPreviewAdmission.js +179 -0
  47. package/lib/merchantPreviewOrigins.d.ts +6 -0
  48. package/lib/merchantPreviewOrigins.js +18 -0
  49. package/lib/merchantPreviewStorage.d.ts +9 -0
  50. package/lib/merchantPreviewStorage.js +50 -0
  51. package/lib/merchantPreviewTypes.d.ts +57 -0
  52. package/lib/merchantPreviewTypes.js +1 -0
  53. package/lib/standalone.d.ts +2 -0
  54. package/lib/standalone.js +1 -0
  55. package/lib/ui.d.ts +1 -0
  56. package/lib/ui.js +8 -0
  57. package/lib/version.d.ts +1 -1
  58. package/lib/version.js +1 -1
  59. package/package.json +1 -1
@@ -0,0 +1,148 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.validateMerchantPreviewBootstrap = validateMerchantPreviewBootstrap;
4
+ exports.installMerchantGuidePreview = installMerchantGuidePreview;
5
+ const client_js_1 = require("./client.js");
6
+ const merchantPreviewOrigins_js_1 = require("./merchantPreviewOrigins.js");
7
+ const guideAdmission_js_1 = require("./guideAdmission.js");
8
+ const guideTypes_js_1 = require("./guideTypes.js");
9
+ const guideMount_js_1 = require("./guideMount.js");
10
+ const liveGuideWidget_js_1 = require("./liveGuideWidget.js");
11
+ const merchantPreviewAdmission_js_1 = require("./merchantPreviewAdmission.js");
12
+ const merchantPreviewStorage_js_1 = require("./merchantPreviewStorage.js");
13
+ const tabLock_js_1 = require("./tabLock.js");
14
+ const version_js_1 = require("./version.js");
15
+ const invalid = () => new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_INVALID', 'This preview could not be opened. Open it again from OXVO.', false, null, 409);
16
+ const positive = (value) => Number.isSafeInteger(value) && value > 0;
17
+ const timestamp = (value) => typeof value === 'string' ? Date.parse(value) : NaN;
18
+ function captureOptions(input) {
19
+ if (!input || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(input.previewId) || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(input.guideId) ||
20
+ !positive(input.projectId) || !positive(input.configurationVersionId) || !positive(input.configurationRevision) ||
21
+ !/^[a-f0-9]{64}$/.test(input.configurationChecksum) || input.targetOrigin !== location.origin ||
22
+ input.targetPath !== location.pathname || !/^\/(?!\/)[^\x00-\x20\\?#]*$/.test(input.targetPath) || input.targetPath.length > 2048 ||
23
+ input.widgetVersion !== version_js_1.VERSION || typeof input.previewGrant !== 'string' ||
24
+ input.previewGrant.length > 4096 || !/^[\x21-\x7e]*$/.test(input.previewGrant) ||
25
+ !Number.isFinite(timestamp(input.launchExpiresAt)) ||
26
+ !Number.isFinite(timestamp(input.expiresAt)) || timestamp(input.expiresAt) < timestamp(input.launchExpiresAt))
27
+ throw invalid();
28
+ if (input.developmentConsoleOrigin !== undefined && !(0, merchantPreviewOrigins_js_1.isLocalConsoleOrigin)(input.developmentConsoleOrigin))
29
+ throw invalid();
30
+ const runtime = new URL(input.runtimeUrl);
31
+ if (runtime.username || runtime.password || runtime.search || runtime.hash || runtime.pathname !== '/' ||
32
+ !(0, merchantPreviewOrigins_js_1.isPreviewRuntimeOrigin)(runtime, input))
33
+ throw invalid();
34
+ return { previewId: input.previewId, projectId: input.projectId, guideId: input.guideId,
35
+ configurationVersionId: input.configurationVersionId, configurationRevision: input.configurationRevision,
36
+ configurationChecksum: input.configurationChecksum, targetOrigin: input.targetOrigin, targetPath: input.targetPath,
37
+ launchExpiresAt: input.launchExpiresAt, expiresAt: input.expiresAt, runtimeUrl: runtime.href,
38
+ widgetVersion: input.widgetVersion, previewGrant: input.previewGrant,
39
+ ...(input.developmentConsoleOrigin ? { developmentConsoleOrigin: input.developmentConsoleOrigin } : {}),
40
+ ...(typeof input.onState === 'function' ? { onState: input.onState } : {}),
41
+ ...(typeof input.onError === 'function' ? { onError: input.onError } : {}) };
42
+ }
43
+ function validateMerchantPreviewBootstrap(value, preview) {
44
+ const config = (0, guideAdmission_js_1.validateGuideBootstrap)(value, value?.installKey);
45
+ const metadata = value?.merchantPreview;
46
+ if (!guideTypes_js_1.GUIDE_INSTALL_KEY_PATTERN.test(config.installKey) || config.projectId !== preview.projectId || config.guideId !== preview.guideId ||
47
+ config.configRevision !== preview.configurationRevision || config.configChecksum !== `sha256:${preview.configurationChecksum}` ||
48
+ value.providerProtocol !== 'live' || value.widgetVersion !== preview.widgetVersion || value.experienceMode !== 'standard' ||
49
+ value.capabilities?.guideMeasurementV1 === true || value.replayRecordingEnabled === true ||
50
+ !metadata || metadata.previewId !== preview.previewId || metadata.configurationVersionId !== preview.configurationVersionId ||
51
+ metadata.targetOrigin !== preview.targetOrigin || metadata.targetPath !== preview.targetPath ||
52
+ timestamp(metadata.expiresAt) !== timestamp(preview.expiresAt))
53
+ throw invalid();
54
+ return value;
55
+ }
56
+ function installMerchantGuidePreview(input) {
57
+ try {
58
+ if (window.self !== window.top || window.location.origin === 'null')
59
+ throw invalid();
60
+ const preview = captureOptions(input);
61
+ const recovery = (0, merchantPreviewStorage_js_1.readMerchantPreviewRecovery)(preview, sessionStorage);
62
+ if (!recovery && (!preview.previewGrant || timestamp(preview.launchExpiresAt) <= Date.now()))
63
+ throw invalid();
64
+ const namespace = (0, merchantPreviewAdmission_js_1.merchantPreviewNamespace)(preview.targetOrigin, preview.previewId);
65
+ const mountIdentity = `merchant-preview:${namespace}`;
66
+ const current = (0, guideMount_js_1.mountedGuide)(document, mountIdentity);
67
+ if (current)
68
+ return Promise.resolve(current);
69
+ const mount = new guideMount_js_1.PendingGuideMount(document, mountIdentity);
70
+ void (async () => {
71
+ let lock;
72
+ let widget;
73
+ let admission;
74
+ const operation = new AbortController();
75
+ const timeout = window.setTimeout(() => operation.abort(), 15000);
76
+ try {
77
+ const runtime = new client_js_1.RuntimeClient(preview.runtimeUrl, version_js_1.VERSION);
78
+ const locale = (navigator.language || 'en').slice(0, 32);
79
+ const bootstrap = validateMerchantPreviewBootstrap(recovery ?? await runtime.bootstrapMerchantPreview({ schemaVersion: 1,
80
+ previewId: preview.previewId, previewGrant: preview.previewGrant, path: preview.targetPath, requestedLocale: locale }, operation.signal), preview);
81
+ if (operation.signal.aborted || location.origin !== preview.targetOrigin || location.pathname !== preview.targetPath)
82
+ throw invalid();
83
+ admission = new merchantPreviewAdmission_js_1.MerchantPreviewAdmission(preview, bootstrap, runtime, sessionStorage, recovery !== null);
84
+ const ownerId = `preview:${crypto.randomUUID()}`;
85
+ const tabKey = `__oxvo_ai_guide_preview_tab_${namespace}`;
86
+ let tabId = sessionStorage.getItem(tabKey);
87
+ if (!tabId || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(tabId)) {
88
+ tabId = `preview:${crypto.randomUUID()}`;
89
+ sessionStorage.setItem(tabKey, tabId);
90
+ if (sessionStorage.getItem(tabKey) !== tabId)
91
+ throw invalid();
92
+ }
93
+ const reportState = () => {
94
+ if (!widget)
95
+ return;
96
+ const state = widget.getState();
97
+ try {
98
+ preview.onState?.(state);
99
+ }
100
+ catch { /* A host observer cannot interrupt session cleanup. */ }
101
+ window.dispatchEvent(new CustomEvent('oxvo-ai-guide:state', { detail: state }));
102
+ };
103
+ lock = new tabLock_js_1.TabActivityLock(namespace, ownerId, active => widget?.onTabActivityChange(active), undefined, undefined, {
104
+ onBeforePageHideRelease: () => { void widget?.end().catch(() => undefined); },
105
+ });
106
+ const activity = lock;
107
+ widget = new liveGuideWidget_js_1.LiveGuideWidget({ bootstrap, sessionAdmission: admission, runtime, tabId, locale, messages: {},
108
+ previewRuntimePolicy: preview.developmentConsoleOrigin ? { developmentConsoleOrigin: preview.developmentConsoleOrigin } : {},
109
+ viewOptions: { storageNamespace: namespace, initialPanelView: 'expanded',
110
+ contextNotice: recovery ? 'Finishing your previous preview. If it cannot finish here, check its status in the original Console tab or wait for it to expire.'
111
+ : `Saved draft · Revision ${preview.configurationRevision}. This preview uses OXVO Credits.` },
112
+ acquire: () => activity.acquire(), ownsActivity: () => activity.ownsActivity(), release: () => activity.release(), onState: reportState });
113
+ const live = widget;
114
+ const session = admission;
115
+ let destroyed = false;
116
+ const controller = {
117
+ version: version_js_1.VERSION,
118
+ open: value => live.open(value), close: () => live.close(), getState: () => live.getState(), end: () => live.end(),
119
+ destroy: () => {
120
+ if (destroyed)
121
+ return;
122
+ destroyed = true;
123
+ const ended = live.end();
124
+ live.destroy();
125
+ void ended.catch(() => undefined).finally(() => { session.destroy(); activity.destroy(); mount.release(); });
126
+ },
127
+ };
128
+ mount.promote(document, mountIdentity, controller);
129
+ mount.resolve(controller);
130
+ reportState();
131
+ }
132
+ catch (error) {
133
+ widget?.destroy();
134
+ admission?.destroy();
135
+ lock?.destroy();
136
+ mount.release();
137
+ mount.reject(error);
138
+ }
139
+ finally {
140
+ window.clearTimeout(timeout);
141
+ }
142
+ })();
143
+ return mount.promise;
144
+ }
145
+ catch (error) {
146
+ return Promise.reject(error);
147
+ }
148
+ }
@@ -0,0 +1,32 @@
1
+ import { RuntimeClient } from './client.js';
2
+ import type { LiveControlAuthorization } from './liveControlChannel.js';
3
+ import type { LiveGuideSessionAdmission, LiveGuideStartIntent } from './liveGuideWidget.js';
4
+ import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
5
+ export { merchantPreviewNamespace } from './merchantPreviewStorage.js';
6
+ export declare class MerchantPreviewAdmission implements LiveGuideSessionAdmission {
7
+ private readonly preview;
8
+ private readonly bootstrap;
9
+ private readonly runtime;
10
+ private readonly storage;
11
+ readonly recoveryOnly: boolean;
12
+ readonly endMessage = "Preview ended. Return to Console to open another preview.";
13
+ private readonly store;
14
+ private readonly originalKey;
15
+ private admission;
16
+ private admitting;
17
+ private ending;
18
+ private grant;
19
+ constructor(preview: MerchantPreviewOptions, bootstrap: MerchantPreviewBootstrap, runtime: RuntimeClient, storage?: Storage, recoveryOnly?: boolean);
20
+ canStart(): boolean;
21
+ hasPendingLaunch(): boolean;
22
+ pendingLaunchId(): string | null;
23
+ destroy(): void;
24
+ launch(input: LiveGuideStartIntent, signal: AbortSignal): Promise<LiveControlAuthorization>;
25
+ private reportError;
26
+ private start;
27
+ end(signal?: AbortSignal, expectedLaunchRequestId?: string): Promise<void>;
28
+ private finish;
29
+ private admit;
30
+ private original;
31
+ private writeOriginal;
32
+ }
@@ -0,0 +1,184 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.MerchantPreviewAdmission = exports.merchantPreviewNamespace = void 0;
4
+ const client_js_1 = require("./client.js");
5
+ const guideSubjectStore_js_1 = require("./guideSubjectStore.js");
6
+ const guideTypes_js_1 = require("./guideTypes.js");
7
+ const merchantPreviewStorage_js_1 = require("./merchantPreviewStorage.js");
8
+ var merchantPreviewStorage_js_2 = require("./merchantPreviewStorage.js");
9
+ Object.defineProperty(exports, "merchantPreviewNamespace", { enumerable: true, get: function () { return merchantPreviewStorage_js_2.merchantPreviewNamespace; } });
10
+ const unavailable = () => new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_UNAVAILABLE', 'This preview is no longer available. Open a new preview from OXVO.', false, null, 409);
11
+ class MerchantPreviewAdmission {
12
+ constructor(preview, bootstrap, runtime, storage = sessionStorage, recoveryOnly = false) {
13
+ this.preview = preview;
14
+ this.bootstrap = bootstrap;
15
+ this.runtime = runtime;
16
+ this.storage = storage;
17
+ this.recoveryOnly = recoveryOnly;
18
+ this.endMessage = 'Preview ended. Return to Console to open another preview.';
19
+ this.admission = null;
20
+ this.admitting = null;
21
+ this.ending = null;
22
+ const namespace = (0, merchantPreviewStorage_js_1.merchantPreviewNamespace)(preview.targetOrigin, preview.previewId);
23
+ this.store = new guideSubjectStore_js_1.GuideSubjectStore(bootstrap, preview.targetOrigin, namespace, storage);
24
+ this.originalKey = (0, merchantPreviewStorage_js_1.merchantPreviewStorageKeys)(preview).original;
25
+ this.grant = recoveryOnly ? '' : preview.previewGrant;
26
+ }
27
+ canStart() { return !this.recoveryOnly && !this.original() && Date.now() < Date.parse(this.preview.launchExpiresAt); }
28
+ hasPendingLaunch() { const original = this.original(); return original !== null && !original.completed; }
29
+ pendingLaunchId() { const original = this.original(); return original && !original.completed ? original.intent.launchRequestId : null; }
30
+ destroy() { this.grant = ''; }
31
+ async launch(input, signal) {
32
+ try {
33
+ return await this.start(input, signal);
34
+ }
35
+ catch (error) {
36
+ this.reportError(error);
37
+ throw error;
38
+ }
39
+ }
40
+ reportError(error) {
41
+ const code = error instanceof client_js_1.RuntimeClientError && /^[A-Z][A-Z0-9_]{0,63}$/.test(error.code)
42
+ ? error.code : 'MERCHANT_PREVIEW_UNAVAILABLE';
43
+ try {
44
+ this.preview.onError?.(code);
45
+ }
46
+ catch { /* Feedback cannot interrupt original-session cleanup. */ }
47
+ }
48
+ async start(input, signal) {
49
+ if (signal.aborted || !this.canStart() || location.origin !== this.preview.targetOrigin ||
50
+ location.pathname !== this.preview.targetPath || input.path !== this.preview.targetPath ||
51
+ input.configRevision !== this.preview.configurationRevision)
52
+ throw unavailable();
53
+ const intent = {
54
+ schemaVersion: 3, protocolVersion: 2, installKey: this.bootstrap.installKey,
55
+ previewId: this.preview.previewId, launchRequestId: input.launchRequestId,
56
+ clientVersion: input.clientVersion, liveCapabilities: [...input.liveCapabilities],
57
+ configRevision: input.configRevision, path: input.path, tabId: input.tabId, mode: input.mode,
58
+ experienceMode: 'standard', consent: { ...input.consent, scopes: [...input.consent.scopes] },
59
+ capabilitySummary: { ...input.capabilitySummary },
60
+ };
61
+ (0, merchantPreviewStorage_js_1.saveMerchantPreviewRecovery)(this.preview, this.bootstrap, this.storage);
62
+ this.writeOriginal({ v: 1, previewId: this.preview.previewId, intent, completed: false });
63
+ const admission = await this.admit(intent, signal);
64
+ if (signal.aborted || this.original()?.completed)
65
+ throw unavailable();
66
+ const result = await this.runtime.launchMerchantPreview(intent, admission.admissionGrant, signal);
67
+ if (result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
68
+ result.guideId !== this.preview.guideId || result.subjectId !== admission.subjectId ||
69
+ result.launchRequestId !== intent.launchRequestId)
70
+ throw unavailable();
71
+ // The existing control protocol validates its exact envelope, without preview metadata.
72
+ const authorization = { ...result };
73
+ delete authorization.previewId;
74
+ return authorization;
75
+ }
76
+ end(signal, expectedLaunchRequestId) {
77
+ if (this.ending)
78
+ return this.ending;
79
+ const original = this.original();
80
+ if (!original || original.completed || (expectedLaunchRequestId !== undefined &&
81
+ original.intent.launchRequestId !== expectedLaunchRequestId))
82
+ return Promise.resolve();
83
+ const operation = this.finish(original, signal).catch(error => { this.reportError(error); throw error; })
84
+ .finally(() => { if (this.ending === operation)
85
+ this.ending = null; });
86
+ this.ending = operation;
87
+ return operation;
88
+ }
89
+ async finish(original, signal) {
90
+ if (this.admitting)
91
+ await this.admitting.catch(() => undefined);
92
+ let subject = this.store.readSubject();
93
+ if (!subject) {
94
+ // An ambiguous admission can be recovered only with its original intent and in-memory grant.
95
+ if (!this.grant)
96
+ throw new client_js_1.RuntimeClientError('MERCHANT_PREVIEW_END_UNRESOLVED', 'The previous preview could not be confirmed. Return to the original Console tab to check its status or wait for it to expire.', false, null, 409);
97
+ await this.admit(original.intent, signal);
98
+ subject = this.store.readSubject();
99
+ }
100
+ if (!subject || this.original()?.intent.launchRequestId !== original.intent.launchRequestId)
101
+ throw unavailable();
102
+ const result = await this.runtime.endMerchantPreview({ schemaVersion: 3, previewId: this.preview.previewId,
103
+ installKey: this.bootstrap.installKey, subjectCredential: subject.credential,
104
+ launchRequestId: original.intent.launchRequestId, tabId: original.intent.tabId, action: 'end' }, signal);
105
+ if (!result || Object.keys(result).length !== 6 || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
106
+ result.providerProtocol !== 'live' || result.status !== 'end_requested' || result.previewId !== this.preview.previewId ||
107
+ result.launchRequestId !== original.intent.launchRequestId)
108
+ throw unavailable();
109
+ this.writeOriginal({ ...original, completed: true });
110
+ this.store.clearLaunch(original.intent.launchRequestId);
111
+ this.admission = null;
112
+ this.grant = '';
113
+ }
114
+ async admit(intent, signal) {
115
+ if (this.admission)
116
+ return this.admission;
117
+ if (this.admitting)
118
+ return this.admitting;
119
+ if (!this.grant)
120
+ throw unavailable();
121
+ const subject = this.store.readSubject();
122
+ const operation = this.runtime.admitMerchantPreview(intent, this.grant, subject?.credential, signal).then(result => {
123
+ const required = ['schemaVersion', 'protocolVersion', 'providerProtocol', 'previewId', 'projectId', 'guideId', 'subjectId',
124
+ 'subjectAuthorityRevision', 'tabId', 'launchRequestId', 'configRevision', 'configChecksum', 'admissionGrant',
125
+ 'expiresAt', 'subjectCredentialExpiresAt'];
126
+ if (!result || Object.keys(result).some(key => ![...required, 'subjectCredential'].includes(key)) ||
127
+ required.some(key => !(key in result)) || result.schemaVersion !== 3 || result.protocolVersion !== 2 ||
128
+ result.providerProtocol !== 'live' || result.previewId !== this.preview.previewId || result.projectId !== this.preview.projectId ||
129
+ result.guideId !== this.preview.guideId || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(result.subjectId) ||
130
+ result.tabId !== intent.tabId || result.launchRequestId !== intent.launchRequestId ||
131
+ result.configRevision !== this.preview.configurationRevision || result.configChecksum !== this.bootstrap.configChecksum ||
132
+ !Number.isSafeInteger(result.subjectAuthorityRevision) || result.subjectAuthorityRevision < 0 ||
133
+ typeof result.admissionGrant !== 'string' || result.admissionGrant.length < 1 || result.admissionGrant.length > 4096 ||
134
+ !Number.isFinite(Date.parse(result.expiresAt)) || Date.parse(result.expiresAt) <= Date.now() ||
135
+ !Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) || Date.parse(result.subjectCredentialExpiresAt) <= Date.now() ||
136
+ (subject && (result.subjectId !== subject.subjectId || result.subjectAuthorityRevision !== subject.subjectAuthorityRevision)))
137
+ throw unavailable();
138
+ const credential = subject?.credential ?? result.subjectCredential;
139
+ if (!credential || !guideTypes_js_1.GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(credential))
140
+ throw unavailable();
141
+ this.store.saveSubject({ v: 1, origin: this.preview.targetOrigin, projectId: this.preview.projectId, guideId: this.preview.guideId,
142
+ subjectId: result.subjectId, subjectAuthorityRevision: result.subjectAuthorityRevision, credential, expiresAt: result.subjectCredentialExpiresAt });
143
+ this.store.saveLaunch({ v: 1, subjectId: result.subjectId, intent, recordingConsent: false });
144
+ this.admission = result;
145
+ return result;
146
+ }).finally(() => { if (this.admitting === operation)
147
+ this.admitting = null; });
148
+ this.admitting = operation;
149
+ return operation;
150
+ }
151
+ original() {
152
+ const raw = this.storage.getItem(this.originalKey);
153
+ if (raw === null)
154
+ return null;
155
+ if (raw.length > 16384)
156
+ throw unavailable();
157
+ let value;
158
+ try {
159
+ value = JSON.parse(raw);
160
+ }
161
+ catch {
162
+ throw unavailable();
163
+ }
164
+ const intent = value?.intent;
165
+ if (value?.v !== 1 || value.previewId !== this.preview.previewId || typeof value.completed !== 'boolean' ||
166
+ !intent || intent.schemaVersion !== 3 || intent.protocolVersion !== 2 || intent.previewId !== this.preview.previewId ||
167
+ intent.installKey !== this.bootstrap.installKey || intent.configRevision !== this.preview.configurationRevision ||
168
+ intent.path !== this.preview.targetPath || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(intent.launchRequestId) ||
169
+ typeof intent.tabId !== 'string' || !/^[A-Za-z0-9_.:/-]{1,128}$/.test(intent.tabId) ||
170
+ !['text', 'voice'].includes(intent.mode) || intent.experienceMode !== 'standard' ||
171
+ 'guideMeasurement' in intent || 'previewGrant' in intent || 'admissionGrant' in intent)
172
+ throw unavailable();
173
+ return value;
174
+ }
175
+ writeOriginal(value) {
176
+ const raw = JSON.stringify(value);
177
+ if (raw.length > 16384)
178
+ throw unavailable();
179
+ this.storage.setItem(this.originalKey, raw);
180
+ if (this.storage.getItem(this.originalKey) !== raw)
181
+ throw unavailable();
182
+ }
183
+ }
184
+ exports.MerchantPreviewAdmission = MerchantPreviewAdmission;
@@ -0,0 +1,6 @@
1
+ export type MerchantPreviewRuntimePolicy = {
2
+ developmentConsoleOrigin?: string;
3
+ };
4
+ export declare const isLoopbackHostname: (hostname: string) => boolean;
5
+ export declare function isLocalConsoleOrigin(value: string): boolean;
6
+ export declare function isPreviewRuntimeOrigin(url: URL, policy?: MerchantPreviewRuntimePolicy): boolean;
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isLoopbackHostname = void 0;
4
+ exports.isLocalConsoleOrigin = isLocalConsoleOrigin;
5
+ exports.isPreviewRuntimeOrigin = isPreviewRuntimeOrigin;
6
+ const isLoopbackHostname = (hostname) => hostname === 'localhost' ||
7
+ hostname.endsWith('.localhost') || /^127(?:\.\d{1,3}){3}$/.test(hostname) || hostname === '[::1]';
8
+ exports.isLoopbackHostname = isLoopbackHostname;
9
+ function isLocalConsoleOrigin(value) {
10
+ try {
11
+ const url = new URL(value);
12
+ return value === url.origin && ['http:', 'https:'].includes(url.protocol) &&
13
+ !url.username && !url.password && (0, exports.isLoopbackHostname)(url.hostname);
14
+ }
15
+ catch {
16
+ return false;
17
+ }
18
+ }
19
+ // The dev alias is accepted only for a preview whose installed loader pinned a local Console.
20
+ function isPreviewRuntimeOrigin(url, policy = {}) {
21
+ return url.protocol === 'https:' || (url.protocol === 'http:' && ((0, exports.isLoopbackHostname)(url.hostname) ||
22
+ (url.hostname === 'oxvosessions.local' && typeof policy.developmentConsoleOrigin === 'string' &&
23
+ isLocalConsoleOrigin(policy.developmentConsoleOrigin))));
24
+ }
@@ -0,0 +1,9 @@
1
+ import type { MerchantPreviewBootstrap, MerchantPreviewOptions } from './merchantPreviewTypes.js';
2
+ export declare function merchantPreviewNamespace(origin: string, previewId: string): string;
3
+ export declare function merchantPreviewStorageKeys(preview: Pick<MerchantPreviewOptions, 'targetOrigin' | 'previewId'>): {
4
+ namespace: string;
5
+ original: string;
6
+ recovery: string;
7
+ };
8
+ export declare function saveMerchantPreviewRecovery(preview: MerchantPreviewOptions, bootstrap: MerchantPreviewBootstrap, storage: Storage): void;
9
+ export declare function readMerchantPreviewRecovery(preview: MerchantPreviewOptions, storage: Storage): MerchantPreviewBootstrap | null;
@@ -0,0 +1,56 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.merchantPreviewNamespace = merchantPreviewNamespace;
4
+ exports.merchantPreviewStorageKeys = merchantPreviewStorageKeys;
5
+ exports.saveMerchantPreviewRecovery = saveMerchantPreviewRecovery;
6
+ exports.readMerchantPreviewRecovery = readMerchantPreviewRecovery;
7
+ const guideTypes_js_1 = require("./guideTypes.js");
8
+ const invalid = () => new Error('The previous preview could not be recovered. Return to the original Console tab to check its status or wait for it to expire.');
9
+ const PREVIEW_FIELDS = ['previewId', 'projectId', 'guideId', 'configurationVersionId', 'configurationRevision',
10
+ 'configurationChecksum', 'targetOrigin', 'targetPath', 'launchExpiresAt', 'expiresAt', 'runtimeUrl', 'widgetVersion'];
11
+ const BOOTSTRAP_FIELDS = ['schemaVersion', 'projectId', 'guideId', 'installKey', 'protocol', 'available', 'configRevision',
12
+ 'configChecksum', 'providerProtocol', 'providerModel', 'liveCapabilities', 'liveAssets', 'widgetVersion',
13
+ 'experienceMode', 'replayRecordingEnabled', 'capabilities', 'consent', 'cache', 'merchantPreview'];
14
+ const APPEARANCE_FIELDS = ['brandName', 'launcherLabel', 'accent', 'position', 'panelWidth', 'glassEffect',
15
+ 'hideLauncherWhenVisitorLimited', 'theme', 'welcomeMessage', 'compactEntryEnabled'];
16
+ function merchantPreviewNamespace(origin, previewId) {
17
+ if (new URL(origin).origin !== origin || !guideTypes_js_1.GUIDE_UUID_PATTERN.test(previewId))
18
+ throw invalid();
19
+ return `merchant_preview_v1_${encodeURIComponent(origin)}_${previewId}`;
20
+ }
21
+ function merchantPreviewStorageKeys(preview) {
22
+ const namespace = merchantPreviewNamespace(preview.targetOrigin, preview.previewId);
23
+ return { namespace, original: `__oxvo_ai_guide_preview_launch_${namespace}`, recovery: `__oxvo_ai_guide_preview_recovery_${namespace}` };
24
+ }
25
+ const pick = (value, fields) => Object.fromEntries(fields.filter(key => key in value)
26
+ .map(key => [key, value[key]]));
27
+ function saveMerchantPreviewRecovery(preview, bootstrap, storage) {
28
+ const presentation = { ...pick(bootstrap, BOOTSTRAP_FIELDS),
29
+ ...(bootstrap.appearance ? { appearance: pick(bootstrap.appearance, APPEARANCE_FIELDS) } : {}) };
30
+ const raw = JSON.stringify({ v: 1, preview: pick(preview, PREVIEW_FIELDS), bootstrap: presentation });
31
+ if (raw.length > 65536 || /"(?:previewGrant|admissionGrant|controlCredential|subjectCredential)"\s*:/.test(raw))
32
+ throw invalid();
33
+ const key = merchantPreviewStorageKeys(preview).recovery;
34
+ storage.setItem(key, raw);
35
+ if (storage.getItem(key) !== raw)
36
+ throw invalid();
37
+ }
38
+ function readMerchantPreviewRecovery(preview, storage) {
39
+ const keys = merchantPreviewStorageKeys(preview);
40
+ if (storage.getItem(keys.original) === null)
41
+ return null;
42
+ const raw = storage.getItem(keys.recovery);
43
+ if (!raw || raw.length > 65536)
44
+ throw invalid();
45
+ let value;
46
+ try {
47
+ value = JSON.parse(raw);
48
+ }
49
+ catch {
50
+ throw invalid();
51
+ }
52
+ if (value?.v !== 1 || !value.preview || !value.bootstrap ||
53
+ JSON.stringify(value.preview) !== JSON.stringify(pick(preview, PREVIEW_FIELDS)))
54
+ throw invalid();
55
+ return value.bootstrap;
56
+ }
@@ -0,0 +1,57 @@
1
+ import type { GuideAdmissionResult, GuideBootstrapConfig, GuideLaunchRecoveryInput } from './guideTypes.js';
2
+ import type { LiveGuideLaunchIntent } from './liveGuideAdmission.js';
3
+ import type { AiGuideControllerState } from './types.js';
4
+ export type MerchantPreviewOptions = {
5
+ previewId: string;
6
+ projectId: number;
7
+ guideId: string;
8
+ configurationVersionId: number;
9
+ configurationRevision: number;
10
+ configurationChecksum: string;
11
+ targetOrigin: string;
12
+ targetPath: string;
13
+ launchExpiresAt: string;
14
+ expiresAt: string;
15
+ runtimeUrl: string;
16
+ widgetVersion: string;
17
+ previewGrant: string;
18
+ developmentConsoleOrigin?: string;
19
+ onState?(state: AiGuideControllerState): void;
20
+ onError?(code: string): void;
21
+ };
22
+ export type MerchantPreviewBootstrapInput = {
23
+ schemaVersion: 1;
24
+ previewId: string;
25
+ previewGrant: string;
26
+ path: string;
27
+ requestedLocale?: string;
28
+ };
29
+ export type MerchantPreviewBootstrap = GuideBootstrapConfig & {
30
+ providerProtocol: 'live';
31
+ merchantPreview: {
32
+ previewId: string;
33
+ configurationVersionId: number;
34
+ targetOrigin: string;
35
+ targetPath: string;
36
+ expiresAt: string;
37
+ };
38
+ };
39
+ export type MerchantPreviewLaunchIntent = Omit<LiveGuideLaunchIntent, 'guideMeasurement'> & {
40
+ previewId: string;
41
+ };
42
+ export type MerchantPreviewAdmissionResult = GuideAdmissionResult & {
43
+ providerProtocol: 'live';
44
+ previewId: string;
45
+ };
46
+ export type MerchantPreviewEndInput = GuideLaunchRecoveryInput & {
47
+ previewId: string;
48
+ action: 'end';
49
+ };
50
+ export type MerchantPreviewEndResult = {
51
+ schemaVersion: 3;
52
+ protocolVersion: 2;
53
+ providerProtocol: 'live';
54
+ status: 'end_requested';
55
+ launchRequestId: string;
56
+ previewId: string;
57
+ };
@@ -0,0 +1,2 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
@@ -4,3 +4,5 @@ export { createGuideRecordingNetworkCapture, observeGuideRecording, } from "./gu
4
4
  export type { GuideRecordingObserver, GuideRecordingSource, GuideRecordingLink, } from "./guideRecording.js";
5
5
  /** Install a Guide without importing, initializing or consulting a recorder. */
6
6
  export declare function installAiGuide(options: StandaloneGuideOptions): Promise<AiGuideController | undefined>;
7
+ export { installMerchantGuidePreview } from './merchantPreview.js';
8
+ export type { MerchantPreviewOptions } from './merchantPreviewTypes.js';
package/cjs/standalone.js CHANGED
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.observeGuideRecording = exports.createGuideRecordingNetworkCapture = void 0;
3
+ exports.installMerchantGuidePreview = exports.observeGuideRecording = exports.createGuideRecordingNetworkCapture = void 0;
4
4
  exports.installAiGuide = installAiGuide;
5
5
  const guideInstaller_js_1 = require("./guideInstaller.js");
6
6
  var guideRecording_js_1 = require("./guideRecording.js");
@@ -10,3 +10,5 @@ Object.defineProperty(exports, "observeGuideRecording", { enumerable: true, get:
10
10
  function installAiGuide(options) {
11
11
  return (0, guideInstaller_js_1.installGuide)(options);
12
12
  }
13
+ var merchantPreview_js_1 = require("./merchantPreview.js");
14
+ Object.defineProperty(exports, "installMerchantGuidePreview", { enumerable: true, get: function () { return merchantPreview_js_1.installMerchantGuidePreview; } });
package/cjs/ui.d.ts CHANGED
@@ -60,6 +60,7 @@ export type WidgetCallbacks = {
60
60
  onOpenChange?: (open: boolean) => void;
61
61
  };
62
62
  export type WidgetViewOptions = {
63
+ contextNotice?: string;
63
64
  persistentState?: boolean;
64
65
  storageNamespace?: string;
65
66
  initialPanelView?: "compact" | "expanded";
package/cjs/ui.js CHANGED
@@ -4868,6 +4868,14 @@ class WidgetView {
4868
4868
  this.shadow.append(this.build());
4869
4869
  document.documentElement.append(this.host);
4870
4870
  this.panel = this.require(".panel");
4871
+ if (options.contextNotice) {
4872
+ const notice = document.createElement("p");
4873
+ notice.dataset.role = "context-notice";
4874
+ notice.textContent = options.contextNotice.slice(0, 240);
4875
+ notice.style.cssText = "margin:0;padding:4px 0;font-size:12px;line-height:1.4;color:var(--assist-muted)";
4876
+ this.require(".header .identity").append(notice);
4877
+ this.require('[data-role="intro-entry"]').prepend(notice.cloneNode(true));
4878
+ }
4871
4879
  this.body = this.require(".body");
4872
4880
  this.status = this.require('[data-role="status"]');
4873
4881
  this.duration = this.require('[data-role="duration"]');
package/cjs/version.d.ts CHANGED
@@ -1 +1 @@
1
- export declare const VERSION = "7.5.25";
1
+ export declare const VERSION = "7.5.27";
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.25';
4
+ exports.VERSION = '7.5.27';
@@ -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.25";
37
+ readonly version = "7.5.27";
38
38
  private readonly host;
39
39
  private readonly guideAdmission;
40
40
  private readonly standaloneAdmissionPending;
package/lib/client.d.ts CHANGED
@@ -2,6 +2,7 @@ import type { AssistMode, AiGuideCompanionState, BootstrapConfig, ConsentScope,
2
2
  import { type GuideAdmissionResult, type GuideLaunchIntent, type GuideLaunchRecoveryInput, type GuideLaunchRecoveryResult, type GuideLaunchResult, type GuideRecordingLinkInput, type GuideRecordingLinkResult, type GuideMeasurementBridge } from "./guideTypes.js";
3
3
  import type { LiveControlAuthorization } from "./liveControlChannel.js";
4
4
  import type { LiveGuideLaunchIntent } from "./liveGuideAdmission.js";
5
+ import type { MerchantPreviewBootstrapInput, MerchantPreviewBootstrap, MerchantPreviewLaunchIntent, MerchantPreviewAdmissionResult, MerchantPreviewEndInput, MerchantPreviewEndResult } from './merchantPreviewTypes.js';
5
6
  export declare class RuntimeClientError extends Error {
6
7
  readonly code: string;
7
8
  readonly retryable: boolean;
@@ -104,6 +105,12 @@ export declare class RuntimeClient {
104
105
  status: "end_requested";
105
106
  launchRequestId: string;
106
107
  }>;
108
+ bootstrapMerchantPreview(input: MerchantPreviewBootstrapInput, signal: AbortSignal): Promise<MerchantPreviewBootstrap>;
109
+ admitMerchantPreview(intent: MerchantPreviewLaunchIntent, previewGrant: string, subjectCredential: string | undefined, signal?: AbortSignal): Promise<MerchantPreviewAdmissionResult>;
110
+ launchMerchantPreview(intent: MerchantPreviewLaunchIntent, admissionGrant: string, signal: AbortSignal): Promise<LiveControlAuthorization & {
111
+ previewId: string;
112
+ }>;
113
+ endMerchantPreview(input: MerchantPreviewEndInput, signal?: AbortSignal): Promise<MerchantPreviewEndResult>;
107
114
  launchGuide(intent: GuideLaunchIntent, admissionGrant: string, signal: AbortSignal, measurementBridge?: GuideMeasurementBridge): Promise<GuideLaunchResult>;
108
115
  recoverGuideLaunch(input: GuideLaunchRecoveryInput, signal?: AbortSignal, keepalive?: boolean): Promise<GuideLaunchRecoveryResult>;
109
116
  linkGuideRecording(sessionId: string, input: GuideRecordingLinkInput, signal: AbortSignal): Promise<GuideRecordingLinkResult>;
package/lib/client.js CHANGED
@@ -189,6 +189,18 @@ export class RuntimeClient {
189
189
  async endLiveGuide(input, signal) {
190
190
  return this.postJson("/ai-live-assist/v1/public/live/launches/end", input, {}, signal, true);
191
191
  }
192
+ async bootstrapMerchantPreview(input, signal) {
193
+ return this.postRawJson('/ai-live-assist/v1/merchant-previews/bootstrap', JSON.stringify(input), {}, signal, false, false, true);
194
+ }
195
+ async admitMerchantPreview(intent, previewGrant, subjectCredential, signal) {
196
+ return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/admissions', JSON.stringify({ ...intent, previewGrant, ...(subjectCredential ? { subjectCredential } : {}) }), {}, signal, false, false, true);
197
+ }
198
+ async launchMerchantPreview(intent, admissionGrant, signal) {
199
+ return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launch', JSON.stringify({ ...intent, admissionGrant }), { 'Idempotency-Key': intent.launchRequestId }, signal, false, false, true);
200
+ }
201
+ async endMerchantPreview(input, signal) {
202
+ return this.postRawJson('/ai-live-assist/v1/merchant-previews/live/launches/end', JSON.stringify(input), {}, signal, true, false, true);
203
+ }
192
204
  async launchGuide(intent, admissionGrant, signal, measurementBridge) {
193
205
  return this.postGuideLaunch("/ai-live-assist/v1/public/launch", intent, admissionGrant, signal, measurementBridge);
194
206
  }