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