@oxvo/ai-live-assist 7.4.50 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/AiLiveAssist.d.ts +76 -11
- package/cjs/AiLiveAssist.js +1771 -298
- package/cjs/client.d.ts +19 -0
- package/cjs/client.js +51 -0
- package/cjs/context.d.ts +23 -1
- package/cjs/context.js +713 -126
- package/cjs/control.d.ts +2 -0
- package/cjs/control.js +42 -3
- package/cjs/ctaOffer.d.ts +11 -0
- package/cjs/ctaOffer.js +185 -0
- package/cjs/dialogFocusScope.js +1 -1
- package/cjs/guideAdmission.d.ts +46 -0
- package/cjs/guideAdmission.js +397 -0
- package/cjs/guideHost.d.ts +47 -0
- package/cjs/guideHost.js +48 -0
- package/cjs/guideInstallation.d.ts +12 -0
- package/cjs/guideInstallation.js +60 -0
- package/cjs/guideInstaller.d.ts +4 -0
- package/cjs/guideInstaller.js +116 -0
- package/cjs/guideMount.d.ts +22 -0
- package/cjs/guideMount.js +84 -0
- package/cjs/guideRecording.d.ts +64 -0
- package/cjs/guideRecording.js +176 -0
- package/cjs/guideRecordingSession.d.ts +35 -0
- package/cjs/guideRecordingSession.js +167 -0
- package/cjs/guideSubjectStore.d.ts +32 -0
- package/cjs/guideSubjectStore.js +105 -0
- package/cjs/guideTypes.d.ts +117 -0
- package/cjs/guideTypes.js +15 -0
- package/cjs/index.d.ts +6 -0
- package/cjs/index.js +25 -11
- package/cjs/liveAudioProcessor.d.ts +92 -0
- package/cjs/liveAudioProcessor.js +269 -0
- package/cjs/liveAudioQueue.d.ts +40 -0
- package/cjs/liveAudioQueue.js +130 -0
- package/cjs/liveAudioWorklet.d.ts +1 -0
- package/cjs/liveAudioWorklet.js +63 -0
- package/cjs/liveBrowserDetector.d.ts +16 -0
- package/cjs/liveBrowserDetector.js +75 -0
- package/cjs/liveBrowserDetectorWorker.d.ts +1 -0
- package/cjs/liveBrowserDetectorWorker.js +72 -0
- package/cjs/liveControlChannel.d.ts +176 -0
- package/cjs/liveControlChannel.js +829 -0
- package/cjs/liveDuplexMedia.d.ts +204 -0
- package/cjs/liveDuplexMedia.js +740 -0
- package/cjs/liveGuideAdmission.d.ts +21 -0
- package/cjs/liveGuideAdmission.js +94 -0
- package/cjs/liveGuideWidget.d.ts +68 -0
- package/cjs/liveGuideWidget.js +451 -0
- package/cjs/liveSpeechAssets.d.ts +36 -0
- package/cjs/liveSpeechAssets.js +39 -0
- package/cjs/liveSpeechCaptureBridge.d.ts +32 -0
- package/cjs/liveSpeechCaptureBridge.js +140 -0
- package/cjs/liveSpeechDetector.d.ts +62 -0
- package/cjs/liveSpeechDetector.js +206 -0
- package/cjs/liveSpeechModel.d.ts +46 -0
- package/cjs/liveSpeechModel.js +105 -0
- package/cjs/liveSpeechResampler.d.ts +22 -0
- package/cjs/liveSpeechResampler.js +93 -0
- package/cjs/liveSpeechWorker.d.ts +56 -0
- package/cjs/liveSpeechWorker.js +143 -0
- package/cjs/locales/resources.js +568 -8
- package/cjs/media.d.ts +11 -0
- package/cjs/media.js +78 -9
- package/cjs/messages.js +22 -8
- package/cjs/pageAssistancePreference.d.ts +15 -3
- package/cjs/pageAssistancePreference.js +46 -7
- package/cjs/preview.d.ts +4 -1
- package/cjs/preview.js +42 -1
- package/cjs/recording.d.ts +12 -0
- package/cjs/recording.js +150 -0
- package/cjs/standalone.d.ts +6 -0
- package/cjs/standalone.js +12 -0
- package/cjs/types.d.ts +31 -5
- package/cjs/types.js +14 -0
- package/cjs/ui.d.ts +128 -4
- package/cjs/ui.js +1918 -276
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/cjs/voicePresenceUi.d.ts +52 -4
- package/cjs/voicePresenceUi.js +659 -57
- package/lib/AiLiveAssist.d.ts +76 -11
- package/lib/AiLiveAssist.js +1772 -299
- package/lib/client.d.ts +19 -0
- package/lib/client.js +51 -0
- package/lib/context.d.ts +23 -1
- package/lib/context.js +713 -126
- package/lib/control.d.ts +2 -0
- package/lib/control.js +42 -3
- package/lib/ctaOffer.d.ts +11 -0
- package/lib/ctaOffer.js +179 -0
- package/lib/dialogFocusScope.js +1 -1
- package/lib/guideAdmission.d.ts +46 -0
- package/lib/guideAdmission.js +392 -0
- package/lib/guideHost.d.ts +47 -0
- package/lib/guideHost.js +42 -0
- package/lib/guideInstallation.d.ts +12 -0
- package/lib/guideInstallation.js +56 -0
- package/lib/guideInstaller.d.ts +4 -0
- package/lib/guideInstaller.js +113 -0
- package/lib/guideMount.d.ts +22 -0
- package/lib/guideMount.js +77 -0
- package/lib/guideRecording.d.ts +64 -0
- package/lib/guideRecording.js +172 -0
- package/lib/guideRecordingSession.d.ts +35 -0
- package/lib/guideRecordingSession.js +163 -0
- package/lib/guideSubjectStore.d.ts +32 -0
- package/lib/guideSubjectStore.js +101 -0
- package/lib/guideTypes.d.ts +117 -0
- package/lib/guideTypes.js +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +21 -10
- package/lib/liveAudioProcessor.d.ts +92 -0
- package/lib/liveAudioProcessor.js +265 -0
- package/lib/liveAudioQueue.d.ts +40 -0
- package/lib/liveAudioQueue.js +126 -0
- package/lib/liveAudioWorklet.d.ts +1 -0
- package/lib/liveAudioWorklet.js +61 -0
- package/lib/liveBrowserDetector.d.ts +16 -0
- package/lib/liveBrowserDetector.js +71 -0
- package/lib/liveBrowserDetectorWorker.d.ts +1 -0
- package/lib/liveBrowserDetectorWorker.js +70 -0
- package/lib/liveControlChannel.d.ts +176 -0
- package/lib/liveControlChannel.js +825 -0
- package/lib/liveDuplexMedia.d.ts +204 -0
- package/lib/liveDuplexMedia.js +736 -0
- package/lib/liveGuideAdmission.d.ts +21 -0
- package/lib/liveGuideAdmission.js +90 -0
- package/lib/liveGuideWidget.d.ts +68 -0
- package/lib/liveGuideWidget.js +447 -0
- package/lib/liveSpeechAssets.d.ts +36 -0
- package/lib/liveSpeechAssets.js +35 -0
- package/lib/liveSpeechCaptureBridge.d.ts +32 -0
- package/lib/liveSpeechCaptureBridge.js +136 -0
- package/lib/liveSpeechDetector.d.ts +62 -0
- package/lib/liveSpeechDetector.js +202 -0
- package/lib/liveSpeechModel.d.ts +46 -0
- package/lib/liveSpeechModel.js +101 -0
- package/lib/liveSpeechResampler.d.ts +22 -0
- package/lib/liveSpeechResampler.js +89 -0
- package/lib/liveSpeechWorker.d.ts +56 -0
- package/lib/liveSpeechWorker.js +137 -0
- package/lib/locales/resources.js +568 -8
- package/lib/media.d.ts +11 -0
- package/lib/media.js +77 -8
- package/lib/messages.js +22 -8
- package/lib/pageAssistancePreference.d.ts +15 -3
- package/lib/pageAssistancePreference.js +46 -7
- package/lib/preview.d.ts +4 -1
- package/lib/preview.js +42 -1
- package/lib/recording.d.ts +12 -0
- package/lib/recording.js +146 -0
- package/lib/standalone.d.ts +6 -0
- package/lib/standalone.js +6 -0
- package/lib/types.d.ts +31 -5
- package/lib/types.js +14 -0
- package/lib/ui.d.ts +128 -4
- package/lib/ui.js +1919 -277
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/voicePresenceUi.d.ts +52 -4
- package/lib/voicePresenceUi.js +659 -57
- package/package.json +16 -1
|
@@ -0,0 +1,392 @@
|
|
|
1
|
+
import { RuntimeClientError, } from "./client.js";
|
|
2
|
+
import { GUIDE_SUBJECT_CREDENTIAL_PATTERN, GUIDE_UUID_PATTERN, guideLaunchRequestId, } from "./guideTypes.js";
|
|
3
|
+
import { VERSION } from "./version.js";
|
|
4
|
+
import { GuideRecordingSession, } from "./guideRecordingSession.js";
|
|
5
|
+
const invalid = () => new RuntimeClientError("PROTOCOL_INVALID", "The AI Guide runtime returned an invalid session identity.", false, null, 502);
|
|
6
|
+
const pending = () => new RuntimeClientError("GUIDE_LAUNCH_PENDING", "This AI Guide session is still being secured. Please try again.", true, 1000, 409);
|
|
7
|
+
export function validateGuideBootstrap(value, installKey) {
|
|
8
|
+
if (!value ||
|
|
9
|
+
value.schemaVersion !== 3 ||
|
|
10
|
+
value.installKey !== installKey ||
|
|
11
|
+
!Number.isSafeInteger(value.projectId) ||
|
|
12
|
+
(value.projectId ?? 0) <= 0 ||
|
|
13
|
+
typeof value.guideId !== "string" ||
|
|
14
|
+
!GUIDE_UUID_PATTERN.test(value.guideId) ||
|
|
15
|
+
value.protocol?.min !== 2 ||
|
|
16
|
+
value.protocol.max !== 2 ||
|
|
17
|
+
(value.experienceMode !== undefined &&
|
|
18
|
+
value.experienceMode !== "standard") ||
|
|
19
|
+
!Number.isSafeInteger(value.configRevision) ||
|
|
20
|
+
(value.configRevision ?? 0) <= 0 ||
|
|
21
|
+
typeof value.configChecksum !== "string" ||
|
|
22
|
+
!/^sha256:[0-9a-f]{64}$/.test(value.configChecksum))
|
|
23
|
+
throw invalid();
|
|
24
|
+
return value;
|
|
25
|
+
}
|
|
26
|
+
/** Server admission and local cancellation fences; no recorder or crypto substitute. */
|
|
27
|
+
export class GuideAdmission {
|
|
28
|
+
constructor(identity, store, runtime, bootstrap, recordingAdapter = null) {
|
|
29
|
+
this.identity = identity;
|
|
30
|
+
this.store = store;
|
|
31
|
+
this.runtime = runtime;
|
|
32
|
+
this.activeAdmission = null;
|
|
33
|
+
this.admissionRequestId = null;
|
|
34
|
+
this.activeLaunchRequestId = null;
|
|
35
|
+
this.recordingChoice = false;
|
|
36
|
+
this.recordingChoiceRevision = 0;
|
|
37
|
+
this.initialBootstrap = bootstrap;
|
|
38
|
+
this.currentBootstrap = bootstrap;
|
|
39
|
+
this.recording = recordingAdapter
|
|
40
|
+
? new GuideRecordingSession(identity, store, runtime, recordingAdapter)
|
|
41
|
+
: null;
|
|
42
|
+
this.activeLaunchRecord = store.readLaunch();
|
|
43
|
+
this.activeLaunchRequestId =
|
|
44
|
+
this.activeLaunchRecord?.intent.launchRequestId ?? null;
|
|
45
|
+
this.recordingChoice =
|
|
46
|
+
this.activeLaunchRecord?.recordingConsent ??
|
|
47
|
+
this.activeLaunchRecord?.intent.consent.scopes.includes("session_recording") ??
|
|
48
|
+
false;
|
|
49
|
+
}
|
|
50
|
+
subjectId() {
|
|
51
|
+
return this.store.readSubject()?.subjectId ?? null;
|
|
52
|
+
}
|
|
53
|
+
get recordingConfigured() {
|
|
54
|
+
return this.recording !== null;
|
|
55
|
+
}
|
|
56
|
+
get recordingAllowed() {
|
|
57
|
+
return (this.recordingConfigured &&
|
|
58
|
+
this.recordingChoice &&
|
|
59
|
+
this.currentBootstrap.replayRecordingEnabled === true);
|
|
60
|
+
}
|
|
61
|
+
setRecordingChoice(allowed) {
|
|
62
|
+
// Revocation takes effect before persistence or any network acknowledgement.
|
|
63
|
+
this.recordingChoice = false;
|
|
64
|
+
this.recordingChoiceRevision += 1;
|
|
65
|
+
if (!allowed)
|
|
66
|
+
this.recording?.applyConsent(false);
|
|
67
|
+
try {
|
|
68
|
+
const previous = this.store.readLaunch() ?? this.activeLaunchRecord;
|
|
69
|
+
if (previous) {
|
|
70
|
+
const record = { ...previous, recordingConsent: allowed };
|
|
71
|
+
this.activeLaunchRecord = record;
|
|
72
|
+
this.store.saveLaunch(record);
|
|
73
|
+
}
|
|
74
|
+
this.recordingChoice = allowed;
|
|
75
|
+
return true;
|
|
76
|
+
}
|
|
77
|
+
catch {
|
|
78
|
+
this.recording?.applyConsent(false);
|
|
79
|
+
return false;
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
syncRecording(result, scopes, tabId) {
|
|
83
|
+
this.recording?.bindSession(result.sessionId, tabId);
|
|
84
|
+
this.updateRecordingConsent(scopes);
|
|
85
|
+
}
|
|
86
|
+
updateRecordingConsent(scopes) {
|
|
87
|
+
this.recording?.applyConsent(this.recordingAllowed && scopes.includes("session_recording"));
|
|
88
|
+
}
|
|
89
|
+
destroy() {
|
|
90
|
+
this.recording?.destroy();
|
|
91
|
+
}
|
|
92
|
+
pendingIntent() {
|
|
93
|
+
return (this.store.readLaunch() ?? this.activeLaunchRecord)?.intent ?? null;
|
|
94
|
+
}
|
|
95
|
+
connectionScope() {
|
|
96
|
+
let subjectId = this.subjectId();
|
|
97
|
+
return {
|
|
98
|
+
kind: "guide_subject_v2",
|
|
99
|
+
assertCurrent: () => {
|
|
100
|
+
const current = this.subjectId();
|
|
101
|
+
if (subjectId !== null && current !== subjectId) {
|
|
102
|
+
throw new RuntimeClientError("GUIDE_SUBJECT_CHANGED", "The AI Guide session identity changed.", false, null, 409);
|
|
103
|
+
}
|
|
104
|
+
// Before first admission this is only a local cancellation scope. The
|
|
105
|
+
// signed server grant remains mandatory before any launch request.
|
|
106
|
+
if (subjectId === null && current !== null)
|
|
107
|
+
subjectId = current;
|
|
108
|
+
},
|
|
109
|
+
};
|
|
110
|
+
}
|
|
111
|
+
async bootstrap(path, locale, signal) {
|
|
112
|
+
const initial = this.initialBootstrap;
|
|
113
|
+
this.initialBootstrap = null;
|
|
114
|
+
const response = initial ??
|
|
115
|
+
(await this.runtime.bootstrapGuide(this.identity.installKey, path, locale, signal));
|
|
116
|
+
if (response.schemaVersion === 3 && response.available === false) {
|
|
117
|
+
this.recording?.applyConsent(false);
|
|
118
|
+
this.currentBootstrap = response;
|
|
119
|
+
return response;
|
|
120
|
+
}
|
|
121
|
+
const value = validateGuideBootstrap(response, this.identity.installKey);
|
|
122
|
+
if (value.projectId !== this.identity.projectId ||
|
|
123
|
+
value.guideId !== this.identity.guideId)
|
|
124
|
+
throw invalid();
|
|
125
|
+
this.currentBootstrap = value;
|
|
126
|
+
if (value.replayRecordingEnabled !== true)
|
|
127
|
+
this.recording?.applyConsent(false);
|
|
128
|
+
return value;
|
|
129
|
+
}
|
|
130
|
+
async launch(input, signal) {
|
|
131
|
+
const intent = this.intent(input);
|
|
132
|
+
const recordingChoiceRevision = this.recordingChoiceRevision;
|
|
133
|
+
let previous = this.store.readLaunch() ?? this.activeLaunchRecord;
|
|
134
|
+
if (previous && previous.intent.launchRequestId !== intent.launchRequestId &&
|
|
135
|
+
await this.retireTerminalLaunch(previous, input.tabId, signal)) {
|
|
136
|
+
previous = null;
|
|
137
|
+
}
|
|
138
|
+
if (previous) {
|
|
139
|
+
if (previous.intent.launchRequestId !== intent.launchRequestId) {
|
|
140
|
+
throw new RuntimeClientError("GUIDE_LAUNCH_PENDING", "Finish the previous AI Guide session before starting another.", true, null, 409);
|
|
141
|
+
}
|
|
142
|
+
const prior = previous.intent;
|
|
143
|
+
// The original semantic intent stays immutable. Navigation is authorized
|
|
144
|
+
// separately by resume2, not by mutating an already-issued grant.
|
|
145
|
+
if (JSON.stringify({ ...prior, path: intent.path }) !==
|
|
146
|
+
JSON.stringify(intent)) {
|
|
147
|
+
throw new RuntimeClientError("GUIDE_LAUNCH_CONFLICT", "The saved AI Guide launch does not match this request.", false, null, 409);
|
|
148
|
+
}
|
|
149
|
+
// Once admission was durably received, use readback rather than obtaining
|
|
150
|
+
// a new grant or redispatching potentially paid work after uncertainty.
|
|
151
|
+
return this.recover(intent.launchRequestId, input.tabId, input.path, signal);
|
|
152
|
+
}
|
|
153
|
+
if (!this.currentBootstrap.available ||
|
|
154
|
+
this.currentBootstrap.configRevision !== input.configRevision)
|
|
155
|
+
throw invalid();
|
|
156
|
+
const subject = this.store.readSubject();
|
|
157
|
+
this.admissionRequestId = intent.launchRequestId;
|
|
158
|
+
const admission = this.runtime.admitGuide(intent, subject?.credential, signal);
|
|
159
|
+
this.activeAdmission = admission;
|
|
160
|
+
let result;
|
|
161
|
+
try {
|
|
162
|
+
result = await admission;
|
|
163
|
+
this.validateAdmission(result, intent, subject);
|
|
164
|
+
const credential = subject?.credential ?? result.subjectCredential;
|
|
165
|
+
if (!credential)
|
|
166
|
+
throw invalid();
|
|
167
|
+
this.store.saveSubject({
|
|
168
|
+
v: 1,
|
|
169
|
+
origin: this.store.origin,
|
|
170
|
+
projectId: this.identity.projectId,
|
|
171
|
+
guideId: this.identity.guideId,
|
|
172
|
+
subjectId: result.subjectId,
|
|
173
|
+
subjectAuthorityRevision: result.subjectAuthorityRevision,
|
|
174
|
+
credential,
|
|
175
|
+
expiresAt: result.subjectCredentialExpiresAt,
|
|
176
|
+
});
|
|
177
|
+
const record = {
|
|
178
|
+
v: 1,
|
|
179
|
+
subjectId: result.subjectId,
|
|
180
|
+
intent,
|
|
181
|
+
recordingConsent: recordingChoiceRevision === this.recordingChoiceRevision
|
|
182
|
+
? intent.consent.scopes.includes("session_recording")
|
|
183
|
+
: this.recordingChoice,
|
|
184
|
+
};
|
|
185
|
+
this.store.saveLaunch(record);
|
|
186
|
+
this.activeLaunchRecord = record;
|
|
187
|
+
this.activeLaunchRequestId = intent.launchRequestId;
|
|
188
|
+
this.recordingChoice = record.recordingConsent === true;
|
|
189
|
+
if (!this.recordingChoice)
|
|
190
|
+
this.recording?.applyConsent(false);
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
if (this.activeAdmission === admission) {
|
|
194
|
+
this.activeAdmission = null;
|
|
195
|
+
this.admissionRequestId = null;
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
if (signal.aborted)
|
|
199
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
200
|
+
const launched = await this.runtime.launchGuide(intent, result.admissionGrant, signal);
|
|
201
|
+
this.validateLaunch(launched, intent.launchRequestId, result.subjectId);
|
|
202
|
+
return launched;
|
|
203
|
+
}
|
|
204
|
+
async endLaunch(idempotencyKey, tabId, signal) {
|
|
205
|
+
const launchRequestId = guideLaunchRequestId(idempotencyKey);
|
|
206
|
+
if (this.admissionRequestId === launchRequestId && this.activeAdmission) {
|
|
207
|
+
// Issuance is unpaid. Allow its caller to persist the newly received
|
|
208
|
+
// possession proof before looking up the already-issued ledger.
|
|
209
|
+
await this.activeAdmission.catch(() => undefined);
|
|
210
|
+
await Promise.resolve();
|
|
211
|
+
}
|
|
212
|
+
const record = this.store.readLaunch() ?? this.activeLaunchRecord;
|
|
213
|
+
if (!record)
|
|
214
|
+
return; // This client has not dispatched a paid launch.
|
|
215
|
+
if (record.intent.launchRequestId !== launchRequestId)
|
|
216
|
+
throw invalid();
|
|
217
|
+
const subject = this.requiredSubject(record.subjectId);
|
|
218
|
+
const result = await this.runtime.recoverGuideLaunch({
|
|
219
|
+
schemaVersion: 3,
|
|
220
|
+
installKey: this.identity.installKey,
|
|
221
|
+
subjectCredential: subject.credential,
|
|
222
|
+
launchRequestId,
|
|
223
|
+
tabId,
|
|
224
|
+
action: "end",
|
|
225
|
+
}, signal, true);
|
|
226
|
+
if (!result ||
|
|
227
|
+
result.schemaVersion !== 3 ||
|
|
228
|
+
result.launchRequestId !== launchRequestId ||
|
|
229
|
+
"launch" in result)
|
|
230
|
+
throw invalid();
|
|
231
|
+
if (result.status === "pending")
|
|
232
|
+
throw pending();
|
|
233
|
+
if (result.status !== "terminal")
|
|
234
|
+
throw invalid();
|
|
235
|
+
}
|
|
236
|
+
complete() {
|
|
237
|
+
this.recording?.endSession();
|
|
238
|
+
if (this.activeLaunchRequestId)
|
|
239
|
+
this.store.clearLaunch(this.activeLaunchRequestId);
|
|
240
|
+
this.activeLaunchRequestId = null;
|
|
241
|
+
this.activeLaunchRecord = null;
|
|
242
|
+
}
|
|
243
|
+
async retireTerminalLaunch(record, tabId, signal) {
|
|
244
|
+
if (record.intent.tabId !== tabId)
|
|
245
|
+
return false;
|
|
246
|
+
const launchRequestId = record.intent.launchRequestId;
|
|
247
|
+
const subject = this.requiredSubject(record.subjectId);
|
|
248
|
+
// Read back the exact previous launch with its possession proof. This path
|
|
249
|
+
// never ends an active conversation or allocates another paid session.
|
|
250
|
+
const result = await this.runtime.recoverGuideLaunch({
|
|
251
|
+
schemaVersion: 3,
|
|
252
|
+
installKey: this.identity.installKey,
|
|
253
|
+
subjectCredential: subject.credential,
|
|
254
|
+
launchRequestId,
|
|
255
|
+
tabId,
|
|
256
|
+
action: "resume",
|
|
257
|
+
}, signal);
|
|
258
|
+
if (signal.aborted)
|
|
259
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
260
|
+
if (!result || result.schemaVersion !== 3 || result.launchRequestId !== launchRequestId)
|
|
261
|
+
throw invalid();
|
|
262
|
+
if (result.status === "ready" || result.status === "pending")
|
|
263
|
+
return false;
|
|
264
|
+
if (result.status !== "terminal" || "launch" in result)
|
|
265
|
+
throw invalid();
|
|
266
|
+
const current = this.store.readLaunch() ?? this.activeLaunchRecord;
|
|
267
|
+
if (current?.intent.launchRequestId !== launchRequestId ||
|
|
268
|
+
current.subjectId !== record.subjectId || current.intent.tabId !== tabId ||
|
|
269
|
+
this.activeLaunchRequestId !== launchRequestId ||
|
|
270
|
+
this.requiredSubject(record.subjectId).credential !== subject.credential)
|
|
271
|
+
throw invalid();
|
|
272
|
+
this.complete();
|
|
273
|
+
return true;
|
|
274
|
+
}
|
|
275
|
+
async recover(launchRequestId, tabId, path, signal) {
|
|
276
|
+
const record = this.store.readLaunch() ?? this.activeLaunchRecord;
|
|
277
|
+
if (!record || record.intent.launchRequestId !== launchRequestId)
|
|
278
|
+
throw invalid();
|
|
279
|
+
const subject = this.requiredSubject(record.subjectId);
|
|
280
|
+
const result = await this.runtime.recoverGuideLaunch({
|
|
281
|
+
schemaVersion: 3,
|
|
282
|
+
installKey: this.identity.installKey,
|
|
283
|
+
subjectCredential: subject.credential,
|
|
284
|
+
launchRequestId,
|
|
285
|
+
tabId,
|
|
286
|
+
action: "resume",
|
|
287
|
+
}, signal);
|
|
288
|
+
if (!result ||
|
|
289
|
+
result.schemaVersion !== 3 ||
|
|
290
|
+
result.launchRequestId !== launchRequestId)
|
|
291
|
+
throw invalid();
|
|
292
|
+
if (result.status === "pending")
|
|
293
|
+
throw pending();
|
|
294
|
+
if (result.status === "terminal") {
|
|
295
|
+
throw new RuntimeClientError("SESSION_REVOKED", "This AI Guide session has ended.", false, null, 410);
|
|
296
|
+
}
|
|
297
|
+
if (result.status !== "ready")
|
|
298
|
+
throw invalid();
|
|
299
|
+
this.validateLaunch(result.launch, launchRequestId, subject.subjectId);
|
|
300
|
+
if (path === record.intent.path)
|
|
301
|
+
return result.launch;
|
|
302
|
+
// Recover authorizes the stored intent. A new page must additionally pass
|
|
303
|
+
// the existing path-bound resume contract before tools/media can connect.
|
|
304
|
+
const resumed = await this.runtime.resume(result.launch.sessionId, result.launch.resumeCredential, path, 2, signal);
|
|
305
|
+
if (resumed.schemaVersion !== 2 ||
|
|
306
|
+
resumed.protocolVersion !== 2 ||
|
|
307
|
+
resumed.sessionId !== result.launch.sessionId)
|
|
308
|
+
throw invalid();
|
|
309
|
+
return resumed;
|
|
310
|
+
}
|
|
311
|
+
requiredSubject(subjectId) {
|
|
312
|
+
const subject = this.store.readSubject();
|
|
313
|
+
if (!subject || subject.subjectId !== subjectId)
|
|
314
|
+
throw new RuntimeClientError("GUIDE_SUBJECT_REQUIRED", "The saved AI Guide session identity is unavailable.", false, null, 403);
|
|
315
|
+
return subject;
|
|
316
|
+
}
|
|
317
|
+
validateAdmission(result, intent, subject) {
|
|
318
|
+
if (!result ||
|
|
319
|
+
result.schemaVersion !== 3 ||
|
|
320
|
+
result.protocolVersion !== 2 ||
|
|
321
|
+
result.projectId !== this.identity.projectId ||
|
|
322
|
+
result.guideId !== this.identity.guideId ||
|
|
323
|
+
!GUIDE_UUID_PATTERN.test(result.subjectId) ||
|
|
324
|
+
(subject && result.subjectId !== subject.subjectId) ||
|
|
325
|
+
result.tabId !== intent.tabId ||
|
|
326
|
+
result.launchRequestId !== intent.launchRequestId ||
|
|
327
|
+
result.configRevision !== intent.configRevision ||
|
|
328
|
+
result.configChecksum !== this.currentBootstrap.configChecksum ||
|
|
329
|
+
!Number.isSafeInteger(result.subjectAuthorityRevision) ||
|
|
330
|
+
result.subjectAuthorityRevision < 0 ||
|
|
331
|
+
typeof result.admissionGrant !== "string" ||
|
|
332
|
+
result.admissionGrant.length < 32 ||
|
|
333
|
+
result.admissionGrant.length > 4096 ||
|
|
334
|
+
!Number.isFinite(Date.parse(result.expiresAt)) ||
|
|
335
|
+
!Number.isFinite(Date.parse(result.subjectCredentialExpiresAt)) ||
|
|
336
|
+
(!subject &&
|
|
337
|
+
(!result.subjectCredential ||
|
|
338
|
+
!GUIDE_SUBJECT_CREDENTIAL_PATTERN.test(result.subjectCredential))) ||
|
|
339
|
+
(subject &&
|
|
340
|
+
result.subjectCredential !== undefined &&
|
|
341
|
+
result.subjectCredential !== subject.credential))
|
|
342
|
+
throw invalid();
|
|
343
|
+
}
|
|
344
|
+
validateLaunch(result, launchRequestId, subjectId) {
|
|
345
|
+
if (!result ||
|
|
346
|
+
result.schemaVersion !== 3 ||
|
|
347
|
+
result.protocolVersion !== 2 ||
|
|
348
|
+
result.experienceMode !== "standard" ||
|
|
349
|
+
result.projectId !== this.identity.projectId ||
|
|
350
|
+
result.guideId !== this.identity.guideId ||
|
|
351
|
+
result.subjectId !== subjectId ||
|
|
352
|
+
result.launchRequestId !== launchRequestId ||
|
|
353
|
+
!GUIDE_UUID_PATTERN.test(result.sessionId))
|
|
354
|
+
throw invalid();
|
|
355
|
+
}
|
|
356
|
+
intent(input) {
|
|
357
|
+
if (input.protocolVersion !== 2 ||
|
|
358
|
+
input.experienceMode !== "standard" ||
|
|
359
|
+
input.fallbackIntent)
|
|
360
|
+
throw invalid();
|
|
361
|
+
return {
|
|
362
|
+
schemaVersion: 3,
|
|
363
|
+
protocolVersion: 2,
|
|
364
|
+
installKey: this.identity.installKey,
|
|
365
|
+
launchRequestId: guideLaunchRequestId(input.idempotencyKey),
|
|
366
|
+
clientVersion: VERSION,
|
|
367
|
+
configRevision: input.configRevision,
|
|
368
|
+
path: input.path,
|
|
369
|
+
tabId: input.tabId,
|
|
370
|
+
mode: input.mode,
|
|
371
|
+
experienceMode: "standard",
|
|
372
|
+
consent: {
|
|
373
|
+
disclosureChecksum: input.disclosureChecksum,
|
|
374
|
+
scopes: [...input.scopes],
|
|
375
|
+
locale: input.locale,
|
|
376
|
+
},
|
|
377
|
+
capabilitySummary: {
|
|
378
|
+
ctaOffer: true,
|
|
379
|
+
microphone: input.microphone,
|
|
380
|
+
webrtc: typeof RTCPeerConnection !== "undefined",
|
|
381
|
+
audioPlayback: typeof HTMLAudioElement !== "undefined",
|
|
382
|
+
webAudio: typeof AudioContext !== "undefined" ||
|
|
383
|
+
typeof window
|
|
384
|
+
.webkitAudioContext !== "undefined",
|
|
385
|
+
svgOverlay: typeof SVGElement !== "undefined",
|
|
386
|
+
visualViewport: typeof window.visualViewport !== "undefined",
|
|
387
|
+
reducedMotion: input.reducedMotion,
|
|
388
|
+
lowPower: input.lowPower,
|
|
389
|
+
},
|
|
390
|
+
};
|
|
391
|
+
}
|
|
392
|
+
}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import type { App } from "@oxvo/browser";
|
|
2
|
+
import type { PluginOptions } from "./types.js";
|
|
3
|
+
import type { GuideAdmission } from "./guideAdmission.js";
|
|
4
|
+
import type { GuideIdentity } from "./guideTypes.js";
|
|
5
|
+
export type { GuideIdentity } from "./guideTypes.js";
|
|
6
|
+
export type ReplayStartInfo = {
|
|
7
|
+
sessionID?: unknown;
|
|
8
|
+
assistToken?: unknown;
|
|
9
|
+
};
|
|
10
|
+
/** The real recorder surface used by the legacy, replay-required admission path. */
|
|
11
|
+
export type ReplayRecordingSource = {
|
|
12
|
+
getAssistSessionGrant?: () => {
|
|
13
|
+
sessionId?: unknown;
|
|
14
|
+
token?: unknown;
|
|
15
|
+
} | null;
|
|
16
|
+
getSessionMeta(): {
|
|
17
|
+
sessionID?: unknown;
|
|
18
|
+
} | null;
|
|
19
|
+
attachStartCallback(callback: (info: ReplayStartInfo) => void, useSafe?: boolean): void;
|
|
20
|
+
attachStopCallback(callback: () => void, useSafe?: boolean): void;
|
|
21
|
+
active(): boolean;
|
|
22
|
+
start(options: {
|
|
23
|
+
startNewSession: true;
|
|
24
|
+
}): Promise<unknown>;
|
|
25
|
+
stop(): void;
|
|
26
|
+
};
|
|
27
|
+
type BrowserServices = Readonly<{
|
|
28
|
+
runtimeUrl: string;
|
|
29
|
+
getTabId(): string | null | undefined;
|
|
30
|
+
getVisitorId(): unknown;
|
|
31
|
+
}>;
|
|
32
|
+
export type LegacyBrowserGuideHost = BrowserServices & Readonly<{
|
|
33
|
+
kind: "legacy_browser";
|
|
34
|
+
siteKey: string;
|
|
35
|
+
replay: ReplayRecordingSource;
|
|
36
|
+
}>;
|
|
37
|
+
/** Explicit Guide identity is preparation only until schema 3 admission is enabled. */
|
|
38
|
+
export type StandaloneGuideHost = BrowserServices & Readonly<{
|
|
39
|
+
kind: "guide";
|
|
40
|
+
identity: GuideIdentity;
|
|
41
|
+
admission?: GuideAdmission;
|
|
42
|
+
}>;
|
|
43
|
+
export type GuideHost = LegacyBrowserGuideHost | StandaloneGuideHost;
|
|
44
|
+
export declare function createLegacyBrowserHost(app: App, overrides?: Pick<PluginOptions, "siteKey" | "runtimeUrl">): LegacyBrowserGuideHost;
|
|
45
|
+
export declare function resolveGuideHost(input: App | GuideHost, overrides?: Pick<PluginOptions, "siteKey" | "runtimeUrl">): GuideHost;
|
|
46
|
+
export declare function guideStorageNamespace(host: GuideHost, siteKey: string, origin: string): string;
|
|
47
|
+
export declare function guideMountIdentity(host: GuideHost, siteKey: string, origin: string): string;
|
package/lib/guideHost.js
ADDED
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
export function createLegacyBrowserHost(app, overrides = {}) {
|
|
2
|
+
const endpoint = app.options.endpoint;
|
|
3
|
+
return {
|
|
4
|
+
kind: "legacy_browser",
|
|
5
|
+
siteKey: overrides.siteKey || app.getProjectKey(),
|
|
6
|
+
runtimeUrl: overrides.runtimeUrl ||
|
|
7
|
+
(endpoint
|
|
8
|
+
? new URL(endpoint, window.location.href).origin
|
|
9
|
+
: window.location.origin),
|
|
10
|
+
getTabId: () => app.session.getTabId(),
|
|
11
|
+
getVisitorId: () => app.getSessionMeta()?.userUUID,
|
|
12
|
+
replay: app,
|
|
13
|
+
};
|
|
14
|
+
}
|
|
15
|
+
export function resolveGuideHost(input, overrides = {}) {
|
|
16
|
+
return "kind" in input &&
|
|
17
|
+
(input.kind === "guide" || input.kind === "legacy_browser")
|
|
18
|
+
? input
|
|
19
|
+
: createLegacyBrowserHost(input, overrides);
|
|
20
|
+
}
|
|
21
|
+
export function guideStorageNamespace(host, siteKey, origin) {
|
|
22
|
+
if (host.kind === "legacy_browser")
|
|
23
|
+
return siteKey;
|
|
24
|
+
const { projectId, guideId, installKey } = host.identity;
|
|
25
|
+
const parsedOrigin = new URL(origin);
|
|
26
|
+
if (!Number.isSafeInteger(projectId) ||
|
|
27
|
+
projectId <= 0 ||
|
|
28
|
+
!/^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$/.test(guideId) ||
|
|
29
|
+
!/^gk_[0-9a-f]{32}$/.test(installKey) ||
|
|
30
|
+
!["http:", "https:"].includes(parsedOrigin.protocol) ||
|
|
31
|
+
parsedOrigin.origin !== origin ||
|
|
32
|
+
siteKey !== "") {
|
|
33
|
+
throw new Error("Invalid AI Guide installation identity.");
|
|
34
|
+
}
|
|
35
|
+
return `guide_v1_${encodeURIComponent(origin)}_${projectId}_${guideId}`;
|
|
36
|
+
}
|
|
37
|
+
export function guideMountIdentity(host, siteKey, origin) {
|
|
38
|
+
const namespace = guideStorageNamespace(host, siteKey, origin);
|
|
39
|
+
return host.kind === "legacy_browser"
|
|
40
|
+
? `legacy:${namespace}`
|
|
41
|
+
: `guide:${namespace}`;
|
|
42
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { type GuideIdentity } from "./guideTypes.js";
|
|
2
|
+
/** Non-authoritative locator: only finds stored credentials for recover-and-End. */
|
|
3
|
+
export declare class GuideInstallationLocator {
|
|
4
|
+
private readonly runtimeUrl;
|
|
5
|
+
private readonly installKey;
|
|
6
|
+
private readonly origin;
|
|
7
|
+
private readonly storage;
|
|
8
|
+
private readonly key;
|
|
9
|
+
constructor(runtimeUrl: string, installKey: string, origin: string, storage?: Storage);
|
|
10
|
+
read(): GuideIdentity | null;
|
|
11
|
+
save(identity: GuideIdentity): void;
|
|
12
|
+
}
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import { GUIDE_INSTALL_KEY_PATTERN, GUIDE_UUID_PATTERN, } from "./guideTypes.js";
|
|
2
|
+
/** Non-authoritative locator: only finds stored credentials for recover-and-End. */
|
|
3
|
+
export class GuideInstallationLocator {
|
|
4
|
+
constructor(runtimeUrl, installKey, origin, storage = localStorage) {
|
|
5
|
+
this.runtimeUrl = runtimeUrl;
|
|
6
|
+
this.installKey = installKey;
|
|
7
|
+
this.origin = origin;
|
|
8
|
+
this.storage = storage;
|
|
9
|
+
this.key = `__oxvo_ai_guide_installation_v1_${encodeURIComponent(origin)}_${encodeURIComponent(runtimeUrl)}_${installKey}`;
|
|
10
|
+
}
|
|
11
|
+
read() {
|
|
12
|
+
const text = this.storage.getItem(this.key);
|
|
13
|
+
if (text === null)
|
|
14
|
+
return null;
|
|
15
|
+
let value;
|
|
16
|
+
try {
|
|
17
|
+
if (text.length > 4096)
|
|
18
|
+
throw new Error();
|
|
19
|
+
value = JSON.parse(text);
|
|
20
|
+
if (!value || Array.isArray(value))
|
|
21
|
+
throw new Error();
|
|
22
|
+
}
|
|
23
|
+
catch {
|
|
24
|
+
throw new Error("The saved AI Guide installation is invalid.");
|
|
25
|
+
}
|
|
26
|
+
if (value.v !== 1 ||
|
|
27
|
+
value.runtimeUrl !== this.runtimeUrl ||
|
|
28
|
+
value.origin !== this.origin ||
|
|
29
|
+
value.installKey !== this.installKey ||
|
|
30
|
+
!GUIDE_INSTALL_KEY_PATTERN.test(this.installKey) ||
|
|
31
|
+
typeof value.projectId !== "number" ||
|
|
32
|
+
!Number.isSafeInteger(value.projectId) ||
|
|
33
|
+
value.projectId <= 0 ||
|
|
34
|
+
typeof value.guideId !== "string" ||
|
|
35
|
+
!GUIDE_UUID_PATTERN.test(value.guideId)) {
|
|
36
|
+
throw new Error("The saved AI Guide installation is invalid.");
|
|
37
|
+
}
|
|
38
|
+
return {
|
|
39
|
+
projectId: value.projectId,
|
|
40
|
+
guideId: value.guideId,
|
|
41
|
+
installKey: this.installKey,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
save(identity) {
|
|
45
|
+
const value = JSON.stringify({
|
|
46
|
+
v: 1,
|
|
47
|
+
runtimeUrl: this.runtimeUrl,
|
|
48
|
+
origin: this.origin,
|
|
49
|
+
...identity,
|
|
50
|
+
});
|
|
51
|
+
this.storage.setItem(this.key, value);
|
|
52
|
+
if (this.storage.getItem(this.key) !== value || !this.read()) {
|
|
53
|
+
throw new Error("AI Guide could not save its installation identity.");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { type AiGuideController, type StandaloneGuideOptions } from "./guideTypes.js";
|
|
2
|
+
import type { GuideRecordingFactory } from "./guideRecordingSession.js";
|
|
3
|
+
/** Install one Guide without importing, initializing or consulting a recorder. */
|
|
4
|
+
export declare function installGuide(options: StandaloneGuideOptions, recordingFactory?: GuideRecordingFactory): Promise<AiGuideController | undefined>;
|
|
@@ -0,0 +1,113 @@
|
|
|
1
|
+
import AiLiveAssist from "./AiLiveAssist.js";
|
|
2
|
+
import { RuntimeClient, RuntimeClientError } from "./client.js";
|
|
3
|
+
import { GuideAdmission, validateGuideBootstrap } from "./guideAdmission.js";
|
|
4
|
+
import { guideStorageNamespace, } from "./guideHost.js";
|
|
5
|
+
import { mountedGuide, PendingGuideMount } from "./guideMount.js";
|
|
6
|
+
import { GuideSubjectStore } from "./guideSubjectStore.js";
|
|
7
|
+
import { GuideInstallationLocator } from "./guideInstallation.js";
|
|
8
|
+
import { GUIDE_INSTALL_KEY_PATTERN, } from "./guideTypes.js";
|
|
9
|
+
import { VERSION } from "./version.js";
|
|
10
|
+
/** Install one Guide without importing, initializing or consulting a recorder. */
|
|
11
|
+
export function installGuide(options, recordingFactory) {
|
|
12
|
+
if (options.enabled === false)
|
|
13
|
+
return Promise.resolve(undefined);
|
|
14
|
+
const insideFrame = window.self !== window.top;
|
|
15
|
+
if (insideFrame && options.allowInFrame !== true)
|
|
16
|
+
return Promise.resolve(undefined);
|
|
17
|
+
try {
|
|
18
|
+
// location.origin alone is insufficient: a sandboxed HTTPS frame may have
|
|
19
|
+
// that URL while its actual security origin (and request Origin) is null.
|
|
20
|
+
// Never inherit parent identity or seek storage/DOM access outside this
|
|
21
|
+
// document. Server bootstrap/admission still authorizes the browser Origin.
|
|
22
|
+
if (!["http:", "https:"].includes(window.location.protocol) ||
|
|
23
|
+
window.origin === "null" ||
|
|
24
|
+
window.origin !== window.location.origin)
|
|
25
|
+
throw new Error("AI Guide requires its own non-opaque HTTP or HTTPS origin.");
|
|
26
|
+
if (!GUIDE_INSTALL_KEY_PATTERN.test(options.installKey))
|
|
27
|
+
throw new Error("Invalid AI Guide installation key.");
|
|
28
|
+
const runtime = new RuntimeClient(options.runtimeUrl, VERSION);
|
|
29
|
+
const installationIdentity = `installation:${runtime.baseUrl}:${options.installKey}`;
|
|
30
|
+
const existing = mountedGuide(document, installationIdentity);
|
|
31
|
+
if (existing)
|
|
32
|
+
return Promise.resolve(existing);
|
|
33
|
+
const mount = new PendingGuideMount(document, installationIdentity);
|
|
34
|
+
void (async () => {
|
|
35
|
+
const controller = new AbortController();
|
|
36
|
+
const timeout = setTimeout(() => controller.abort(), 15000);
|
|
37
|
+
try {
|
|
38
|
+
const bootstrap = await runtime.bootstrapGuide(options.installKey, window.location.pathname || "/", options.locale ||
|
|
39
|
+
navigator.language ||
|
|
40
|
+
document.documentElement.lang ||
|
|
41
|
+
"en", controller.signal);
|
|
42
|
+
const locator = new GuideInstallationLocator(runtime.baseUrl, options.installKey, window.location.origin);
|
|
43
|
+
const resolved = bootstrap.available
|
|
44
|
+
? validateGuideBootstrap(bootstrap, options.installKey)
|
|
45
|
+
: null;
|
|
46
|
+
const remembered = bootstrap.schemaVersion === 3 ? locator.read() : null;
|
|
47
|
+
if (resolved &&
|
|
48
|
+
remembered &&
|
|
49
|
+
(resolved.projectId !== remembered.projectId ||
|
|
50
|
+
resolved.guideId !== remembered.guideId)) {
|
|
51
|
+
throw new Error("The AI Guide installation identity changed.");
|
|
52
|
+
}
|
|
53
|
+
const identity = resolved
|
|
54
|
+
? Object.freeze({
|
|
55
|
+
projectId: resolved.projectId,
|
|
56
|
+
guideId: resolved.guideId,
|
|
57
|
+
installKey: options.installKey,
|
|
58
|
+
})
|
|
59
|
+
: remembered;
|
|
60
|
+
if (!identity)
|
|
61
|
+
throw new RuntimeClientError("GUIDE_UNAVAILABLE", "This AI Guide is currently unavailable.", false, null, 404);
|
|
62
|
+
if (resolved)
|
|
63
|
+
locator.save(identity);
|
|
64
|
+
const host = {
|
|
65
|
+
kind: "guide",
|
|
66
|
+
identity,
|
|
67
|
+
runtimeUrl: runtime.baseUrl,
|
|
68
|
+
getTabId: () => null,
|
|
69
|
+
getVisitorId: () => null,
|
|
70
|
+
};
|
|
71
|
+
const namespace = guideStorageNamespace(host, "", window.location.origin);
|
|
72
|
+
const store = new GuideSubjectStore(identity, window.location.origin, namespace);
|
|
73
|
+
if (!resolved && !store.readLaunch())
|
|
74
|
+
throw new RuntimeClientError("GUIDE_UNAVAILABLE", "This AI Guide is currently unavailable.", false, null, 404);
|
|
75
|
+
const admission = new GuideAdmission(identity, store, runtime, bootstrap, !insideFrame &&
|
|
76
|
+
resolved?.replayRecordingEnabled === true &&
|
|
77
|
+
recordingFactory
|
|
78
|
+
? recordingFactory(identity, runtime.baseUrl)
|
|
79
|
+
: null);
|
|
80
|
+
if (insideFrame &&
|
|
81
|
+
resolved?.replayRecordingEnabled === true &&
|
|
82
|
+
recordingFactory)
|
|
83
|
+
window.dispatchEvent(new CustomEvent("oxvo:ai-guide:recording-status", {
|
|
84
|
+
detail: { guideId: identity.guideId, status: "unavailable" },
|
|
85
|
+
}));
|
|
86
|
+
const tabKey = `__oxvo_ai_guide_tab_v1_${namespace}`;
|
|
87
|
+
const tabId = sessionStorage.getItem(tabKey) || `tab_${crypto.randomUUID()}`;
|
|
88
|
+
if (!/^[A-Za-z0-9_.:-]{1,128}$/.test(tabId))
|
|
89
|
+
throw new Error("The saved AI Guide tab identity is invalid.");
|
|
90
|
+
sessionStorage.setItem(tabKey, tabId);
|
|
91
|
+
if (sessionStorage.getItem(tabKey) !== tabId)
|
|
92
|
+
throw new Error("AI Guide could not securely save this tab identity.");
|
|
93
|
+
const instance = new AiLiveAssist({
|
|
94
|
+
...host,
|
|
95
|
+
admission,
|
|
96
|
+
getTabId: () => tabId,
|
|
97
|
+
getVisitorId: () => admission.subjectId(),
|
|
98
|
+
}, options, mount);
|
|
99
|
+
mount.resolve(instance);
|
|
100
|
+
}
|
|
101
|
+
finally {
|
|
102
|
+
clearTimeout(timeout);
|
|
103
|
+
}
|
|
104
|
+
})().catch((error) => {
|
|
105
|
+
mount.release();
|
|
106
|
+
mount.reject(error);
|
|
107
|
+
});
|
|
108
|
+
return mount.promise;
|
|
109
|
+
}
|
|
110
|
+
catch (error) {
|
|
111
|
+
return Promise.reject(error);
|
|
112
|
+
}
|
|
113
|
+
}
|