@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
package/cjs/AiLiveAssist.js
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.resolveAiGuideProtocolVersion = exports.normalizeAiGuideOpenInput = exports.resolveAiGuideLocale = exports.confirmationReplyIntent = exports.ReplaySessionReadiness = exports.REPLAY_SESSION_READY_TIMEOUT_MS = void 0;
|
|
4
|
+
const guideHost_js_1 = require("./guideHost.js");
|
|
5
|
+
const guideMount_js_1 = require("./guideMount.js");
|
|
4
6
|
const client_js_1 = require("./client.js");
|
|
5
7
|
const control_js_1 = require("./control.js");
|
|
6
8
|
const context_js_1 = require("./context.js");
|
|
@@ -11,7 +13,9 @@ const presentation_js_1 = require("./presentation.js");
|
|
|
11
13
|
const tabLock_js_1 = require("./tabLock.js");
|
|
12
14
|
const ui_js_1 = require("./ui.js");
|
|
13
15
|
const version_js_1 = require("./version.js");
|
|
16
|
+
const ctaOffer_js_1 = require("./ctaOffer.js");
|
|
14
17
|
const voicePresenceUi_js_1 = require("./voicePresenceUi.js");
|
|
18
|
+
const liveGuideWidget_js_1 = require("./liveGuideWidget.js");
|
|
15
19
|
class ModeUpgradeTerminalizedError extends Error {
|
|
16
20
|
constructor(state) {
|
|
17
21
|
super("The voice upgrade was safely ended.");
|
|
@@ -32,6 +36,19 @@ class ModeUpgradeConnectionDeadlineError extends client_js_1.RuntimeClientError
|
|
|
32
36
|
this.name = "ModeUpgradeConnectionDeadlineError";
|
|
33
37
|
}
|
|
34
38
|
}
|
|
39
|
+
class InitialSessionStartupDeadlineError extends client_js_1.RuntimeClientError {
|
|
40
|
+
constructor() {
|
|
41
|
+
super("INTERNAL_UNAVAILABLE", "The secure AI Guide connection timed out.", true, 1000, 503);
|
|
42
|
+
this.name = "InitialSessionStartupDeadlineError";
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
class InitialVoiceMicrophoneUnavailableError extends Error {
|
|
46
|
+
constructor(cause) {
|
|
47
|
+
super("The microphone is unavailable.");
|
|
48
|
+
this.cause = cause;
|
|
49
|
+
this.name = "InitialVoiceMicrophoneUnavailableError";
|
|
50
|
+
}
|
|
51
|
+
}
|
|
35
52
|
class TerminalRequestTimeoutError extends client_js_1.RuntimeClientError {
|
|
36
53
|
constructor() {
|
|
37
54
|
super("INTERNAL_UNAVAILABLE", "The terminal request timed out.", true, null, 503);
|
|
@@ -44,6 +61,12 @@ class TerminalRequestDeferredError extends Error {
|
|
|
44
61
|
this.name = "TerminalRequestDeferredError";
|
|
45
62
|
}
|
|
46
63
|
}
|
|
64
|
+
class TerminalControlEndUnconfirmedError extends Error {
|
|
65
|
+
constructor() {
|
|
66
|
+
super("The realtime End request was sent but its authoritative result was not observed.");
|
|
67
|
+
this.name = "TerminalControlEndUnconfirmedError";
|
|
68
|
+
}
|
|
69
|
+
}
|
|
47
70
|
const TERMINAL_STATES = new Set(["ended", "failed", "revoked"]);
|
|
48
71
|
const ACTION_SCOPED_ERROR_CODES = new Set([
|
|
49
72
|
"CONFIRMATION_EXPIRED",
|
|
@@ -99,6 +122,9 @@ const MODE_UPGRADE_LIFECYCLE_TIMEOUT_MS = 15000;
|
|
|
99
122
|
const MODE_UPGRADE_CONNECTION_DEADLINE_MS = 30000;
|
|
100
123
|
const MODE_UPGRADE_PATH_GUARD_INTERVAL_MS = 50;
|
|
101
124
|
const NAVIGATION_CONSENT_RESET_TIMEOUT_MS = 15000;
|
|
125
|
+
const CONTEXT_NAVIGATION_ACK_TIMEOUT_MS = 5000;
|
|
126
|
+
const CONTEXT_NAVIGATION_LATE_ACK_TIMEOUT_MS = 10000;
|
|
127
|
+
const INITIAL_SESSION_STARTUP_TIMEOUT_MS = 15000;
|
|
102
128
|
const TERMINAL_REQUEST_TIMEOUT_MS = 7500;
|
|
103
129
|
const TERMINAL_REQUEST_RETRY_HORIZON_MS = 15 * 60 * 1000;
|
|
104
130
|
const TERMINAL_REQUEST_MAX_RETRY_MS = 30000;
|
|
@@ -125,6 +151,7 @@ const VALID_PRESENCE_STATES = new Set([
|
|
|
125
151
|
]);
|
|
126
152
|
const VALID_ASSISTANT_STATES = new Set(["ready", "listening", "thinking"]);
|
|
127
153
|
const PRE_FENCE_AUTHORITY_ENVELOPE_TYPES = new Set([
|
|
154
|
+
"cta.offer",
|
|
128
155
|
"page_assistance.request",
|
|
129
156
|
"page_assistance.updated",
|
|
130
157
|
"page_assistance.access_granted",
|
|
@@ -232,6 +259,7 @@ const CONSENT_SCOPES = new Set([
|
|
|
232
259
|
"visual_context",
|
|
233
260
|
"handoff_context",
|
|
234
261
|
"retained_transcript",
|
|
262
|
+
"session_recording",
|
|
235
263
|
"presentation_guidance",
|
|
236
264
|
]);
|
|
237
265
|
exports.REPLAY_SESSION_READY_TIMEOUT_MS = 15000;
|
|
@@ -251,12 +279,12 @@ class ReplaySessionReadiness {
|
|
|
251
279
|
this.destroyed = false;
|
|
252
280
|
this.recordingDisabled = false;
|
|
253
281
|
this.onStart = (startInfo) => {
|
|
254
|
-
if (this.destroyed)
|
|
282
|
+
if (this.destroyed || !this.app)
|
|
255
283
|
return;
|
|
256
284
|
if (this.recordingDisabled) {
|
|
257
285
|
window.setTimeout(() => {
|
|
258
286
|
if (!this.destroyed && this.recordingDisabled)
|
|
259
|
-
this.app
|
|
287
|
+
this.app?.stop();
|
|
260
288
|
}, 0);
|
|
261
289
|
return;
|
|
262
290
|
}
|
|
@@ -291,18 +319,18 @@ class ReplaySessionReadiness {
|
|
|
291
319
|
this.stopHandler?.();
|
|
292
320
|
};
|
|
293
321
|
this.lineage = this.readCurrentLineage();
|
|
294
|
-
this.app
|
|
295
|
-
this.app
|
|
322
|
+
this.app?.attachStartCallback(this.onStart, true);
|
|
323
|
+
this.app?.attachStopCallback(this.onStop, true);
|
|
296
324
|
}
|
|
297
325
|
wait() {
|
|
298
326
|
if (this.destroyed) {
|
|
299
327
|
return Promise.reject(new client_js_1.RuntimeClientError("WIDGET_DESTROYED", "AI Guide is no longer available.", false, null, 410));
|
|
300
328
|
}
|
|
301
|
-
if (this.recordingDisabled) {
|
|
329
|
+
if (this.recordingDisabled || !this.app) {
|
|
302
330
|
return Promise.reject(this.recordingRequiredError());
|
|
303
331
|
}
|
|
304
332
|
const current = this.readCurrentLineage();
|
|
305
|
-
if (typeof this.app
|
|
333
|
+
if (typeof this.app?.getAssistSessionGrant === "function") {
|
|
306
334
|
this.lineage = current;
|
|
307
335
|
}
|
|
308
336
|
else if (current) {
|
|
@@ -337,7 +365,7 @@ class ReplaySessionReadiness {
|
|
|
337
365
|
throw new client_js_1.RuntimeClientError("WIDGET_DESTROYED", "AI Guide is no longer available.", false, null, 410);
|
|
338
366
|
}
|
|
339
367
|
const current = this.readCurrentLineage();
|
|
340
|
-
const expected = typeof this.app
|
|
368
|
+
const expected = typeof this.app?.getAssistSessionGrant === "function"
|
|
341
369
|
? current
|
|
342
370
|
: this.lineage;
|
|
343
371
|
if (this.recordingDisabled ||
|
|
@@ -352,7 +380,7 @@ class ReplaySessionReadiness {
|
|
|
352
380
|
this.stopHandler = handler;
|
|
353
381
|
}
|
|
354
382
|
startFreshSessionIfInactive() {
|
|
355
|
-
if (this.destroyed || this.recordingDisabled || this.startInFlight)
|
|
383
|
+
if (this.destroyed || this.recordingDisabled || this.startInFlight || !this.app)
|
|
356
384
|
return;
|
|
357
385
|
try {
|
|
358
386
|
if (this.app.active())
|
|
@@ -377,7 +405,7 @@ class ReplaySessionReadiness {
|
|
|
377
405
|
this.recordingDisabled = true;
|
|
378
406
|
this.lineage = null;
|
|
379
407
|
this.rejectWaiter(this.recordingRequiredError());
|
|
380
|
-
this.app
|
|
408
|
+
this.app?.stop();
|
|
381
409
|
}
|
|
382
410
|
destroy() {
|
|
383
411
|
if (this.destroyed)
|
|
@@ -389,7 +417,7 @@ class ReplaySessionReadiness {
|
|
|
389
417
|
}
|
|
390
418
|
readCurrentLineage() {
|
|
391
419
|
try {
|
|
392
|
-
const current = this.app
|
|
420
|
+
const current = this.app?.getAssistSessionGrant?.();
|
|
393
421
|
return replayLineage(current?.sessionId, current?.token, this.tabId);
|
|
394
422
|
}
|
|
395
423
|
catch {
|
|
@@ -805,6 +833,9 @@ const parseResumeRecord = (value) => {
|
|
|
805
833
|
const expiresAt = Date.parse(rawActionExecution.expiresAt ?? "");
|
|
806
834
|
const result = rawActionExecution.result;
|
|
807
835
|
const navigationPayload = rawActionExecution.navigationPayload;
|
|
836
|
+
const deferredNavigationPath = rawActionExecution.deferredNavigationPath === undefined
|
|
837
|
+
? null
|
|
838
|
+
: rawActionExecution.deferredNavigationPath;
|
|
808
839
|
const validResult = result === null ||
|
|
809
840
|
(typeof result === "object" &&
|
|
810
841
|
result !== null &&
|
|
@@ -837,21 +868,43 @@ const parseResumeRecord = (value) => {
|
|
|
837
868
|
navigationPayload.navigationType === "spa" &&
|
|
838
869
|
typeof navigationPayload.url === "string" &&
|
|
839
870
|
new URL(navigationPayload.url).origin === window.location.origin);
|
|
871
|
+
const validDeferredNavigation = deferredNavigationPath === null ||
|
|
872
|
+
(typeof deferredNavigationPath === "string" &&
|
|
873
|
+
deferredNavigationPath.length <= 2048 &&
|
|
874
|
+
/^\/(?!\/)[^?#]*$/u.test(deferredNavigationPath));
|
|
875
|
+
const deferredResultUrl = deferredNavigationPath !== null &&
|
|
876
|
+
result !== null &&
|
|
877
|
+
typeof result?.observed?.url === "string"
|
|
878
|
+
? new URL(result.observed.url)
|
|
879
|
+
: null;
|
|
880
|
+
const validDeferredResult = deferredNavigationPath === null ||
|
|
881
|
+
result === null ||
|
|
882
|
+
(result.status === "stale" &&
|
|
883
|
+
result.observed.targetState === "unknown" &&
|
|
884
|
+
deferredResultUrl?.origin === window.location.origin &&
|
|
885
|
+
deferredResultUrl.search === "" &&
|
|
886
|
+
deferredResultUrl.hash === "" &&
|
|
887
|
+
deferredResultUrl.pathname === deferredNavigationPath);
|
|
840
888
|
if (!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.actionId ?? "") ||
|
|
841
889
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.executionId ?? "") ||
|
|
842
890
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.beginMessageId ?? "") ||
|
|
843
891
|
!Number.isSafeInteger(rawActionExecution.beginClientSequence) ||
|
|
844
892
|
(rawActionExecution.beginClientSequence ?? 0) < 1 ||
|
|
845
893
|
!Number.isFinite(expiresAt) ||
|
|
846
|
-
expiresAt <= Date.now() ||
|
|
847
894
|
expiresAt > record.expiresAt ||
|
|
848
895
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.resultMessageId ?? "") ||
|
|
849
896
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.navigationMessageId ?? "") ||
|
|
850
897
|
!validResult ||
|
|
851
|
-
!validNavigation
|
|
898
|
+
!validNavigation ||
|
|
899
|
+
!validDeferredNavigation ||
|
|
900
|
+
(deferredNavigationPath !== null && navigationPayload !== null) ||
|
|
901
|
+
!validDeferredResult) {
|
|
852
902
|
return null;
|
|
853
903
|
}
|
|
854
|
-
|
|
904
|
+
// A visitor can return from an external destination after the action's
|
|
905
|
+
// short deadline. Drop that action, not the valid same-tab session or
|
|
906
|
+
// its End authority. Resume still revalidates the session server-side.
|
|
907
|
+
actionExecution = expiresAt > Date.now() ? {
|
|
855
908
|
actionId: rawActionExecution.actionId,
|
|
856
909
|
executionId: rawActionExecution.executionId,
|
|
857
910
|
beginMessageId: rawActionExecution.beginMessageId,
|
|
@@ -861,7 +914,8 @@ const parseResumeRecord = (value) => {
|
|
|
861
914
|
navigationMessageId: rawActionExecution.navigationMessageId,
|
|
862
915
|
result: result ? { ...result, observed: { ...result.observed } } : null,
|
|
863
916
|
navigationPayload: navigationPayload ? { ...navigationPayload } : null,
|
|
864
|
-
|
|
917
|
+
...(deferredNavigationPath !== null ? { deferredNavigationPath } : {}),
|
|
918
|
+
} : null;
|
|
865
919
|
}
|
|
866
920
|
const rawPauseCommand = record.pauseCommand;
|
|
867
921
|
let pauseCommand = null;
|
|
@@ -1297,12 +1351,13 @@ const companionSwitchGrantExpiresSoon = (grant, nowMs = Date.now()) => {
|
|
|
1297
1351
|
}
|
|
1298
1352
|
};
|
|
1299
1353
|
class AiLiveAssist {
|
|
1300
|
-
constructor(app, options) {
|
|
1301
|
-
this.app = app;
|
|
1354
|
+
constructor(app, options, mountReservation) {
|
|
1302
1355
|
this.options = options;
|
|
1303
1356
|
this.version = version_js_1.VERSION;
|
|
1357
|
+
this.releaseMount = null;
|
|
1304
1358
|
this.bootstrap = null;
|
|
1305
1359
|
this.view = null;
|
|
1360
|
+
this.liveWidget = null;
|
|
1306
1361
|
this.messenger = null;
|
|
1307
1362
|
this.messengerListenersBound = false;
|
|
1308
1363
|
this.messengerReturnListenerBound = false;
|
|
@@ -1375,6 +1430,7 @@ class AiLiveAssist {
|
|
|
1375
1430
|
this.bootstrapAbort = null;
|
|
1376
1431
|
this.scopes = [];
|
|
1377
1432
|
this.mode = "text";
|
|
1433
|
+
this.pendingPlaybackState = null;
|
|
1378
1434
|
this.ended = false;
|
|
1379
1435
|
this.reconnecting = false;
|
|
1380
1436
|
this.resumeAttemptOwner = null;
|
|
@@ -1469,6 +1525,7 @@ class AiLiveAssist {
|
|
|
1469
1525
|
this.visitorActiveEligibilityRecheckController = null;
|
|
1470
1526
|
this.visitorActiveEligibilityRecheckKey = null;
|
|
1471
1527
|
this.launchGeneration = 0;
|
|
1528
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
1472
1529
|
this.queuedLaunchToken = null;
|
|
1473
1530
|
this.visitorLimitAbort = null;
|
|
1474
1531
|
this.lastLaunch = null;
|
|
@@ -1482,6 +1539,7 @@ class AiLiveAssist {
|
|
|
1482
1539
|
this.visualConsentGranted = false;
|
|
1483
1540
|
this.manualTurn = false;
|
|
1484
1541
|
this.pushActive = false;
|
|
1542
|
+
this.manualPushRequest = null;
|
|
1485
1543
|
this.pendingModeUpgrade = null;
|
|
1486
1544
|
this.pendingModeUpgradeConsentCompensation = null;
|
|
1487
1545
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -1494,6 +1552,25 @@ class AiLiveAssist {
|
|
|
1494
1552
|
this.preparedFocusedHandoff = null;
|
|
1495
1553
|
this.transcript = [];
|
|
1496
1554
|
this.renderedTranscriptIds = new Set();
|
|
1555
|
+
this.voicePlaybackInterruptionGeneration = 0;
|
|
1556
|
+
this.voicePlaybackAdmissionAfterSequence = 0;
|
|
1557
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
1558
|
+
this.voicePlaybackIngress = new WeakMap();
|
|
1559
|
+
this.voicePlaybackRearm = null;
|
|
1560
|
+
this.ctaOffer = null;
|
|
1561
|
+
this.ctaExpiryTimer = null;
|
|
1562
|
+
this.ctaResultRetryTimer = null;
|
|
1563
|
+
this.ctaSeenOffers = new Set();
|
|
1564
|
+
this.ctaAssistantTurns = new Set();
|
|
1565
|
+
this.ctaContentGeneration = 0;
|
|
1566
|
+
this.ctaContentAtIngress = new WeakMap();
|
|
1567
|
+
this.ctaTerminalOffers = new Set();
|
|
1568
|
+
this.ctaSessionId = null;
|
|
1569
|
+
this.ctaClicked = false;
|
|
1570
|
+
this.ctaAuthorityGeneration = 0;
|
|
1571
|
+
this.ctaAuthorityGenerationAtIngress = new WeakMap();
|
|
1572
|
+
this.ctaStoppedSessionId = null;
|
|
1573
|
+
this.ctaAnnouncedOffers = new Set();
|
|
1497
1574
|
this.transcriptRestoredFromCache = false;
|
|
1498
1575
|
this.agentDiscoveryLink = null;
|
|
1499
1576
|
this.onMessengerSupportState = (event) => {
|
|
@@ -1622,9 +1699,13 @@ class AiLiveAssist {
|
|
|
1622
1699
|
this.wakeTerminalRetry();
|
|
1623
1700
|
};
|
|
1624
1701
|
this.onVisitorControl = (event) => {
|
|
1702
|
+
// Only browser-authenticated visitor input may interrupt an approved page
|
|
1703
|
+
// action. Framer navigation uses untrusted synthetic pointer events to
|
|
1704
|
+
// release the exact approved link to its same-document router.
|
|
1705
|
+
if (!event.isTrusted)
|
|
1706
|
+
return;
|
|
1625
1707
|
if (!this.lock.ownsActivity()) {
|
|
1626
|
-
|
|
1627
|
-
this.requestFocusedHandoff();
|
|
1708
|
+
this.requestFocusedHandoff();
|
|
1628
1709
|
if (this.pendingAction)
|
|
1629
1710
|
return;
|
|
1630
1711
|
}
|
|
@@ -1653,56 +1734,85 @@ class AiLiveAssist {
|
|
|
1653
1734
|
this.pendingAction = false;
|
|
1654
1735
|
void this.updatePause(true);
|
|
1655
1736
|
};
|
|
1656
|
-
this.
|
|
1657
|
-
this.
|
|
1658
|
-
this.
|
|
1659
|
-
this.
|
|
1660
|
-
|
|
1661
|
-
|
|
1662
|
-
this.
|
|
1663
|
-
this.
|
|
1664
|
-
this.
|
|
1665
|
-
|
|
1666
|
-
|
|
1667
|
-
|
|
1668
|
-
|
|
1669
|
-
this.pageAssistanceTrackerIdentity =
|
|
1670
|
-
this.readPageAssistanceTrackerIdentity();
|
|
1671
|
-
const resume = this.readResume();
|
|
1672
|
-
this.tabId = resume?.tabId || app.session.getTabId() || randomId("tab");
|
|
1673
|
-
this.pageAssistanceBindingGeneration =
|
|
1674
|
-
resume?.pageAssistanceBindingGeneration ||
|
|
1675
|
-
randomId("page_assistance_binding");
|
|
1676
|
-
this.replayReadiness = new ReplaySessionReadiness(app, this.tabId);
|
|
1677
|
-
if (options.recordReplay === false) {
|
|
1678
|
-
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
1679
|
-
this.replayReadiness.disableRecording();
|
|
1680
|
-
}
|
|
1681
|
-
this.windowId = randomId("window");
|
|
1682
|
-
this.terminalOffline = navigator.onLine === false;
|
|
1683
|
-
this.locale =
|
|
1684
|
-
resume?.locale ??
|
|
1685
|
-
boundedLocale(options.locale ||
|
|
1686
|
-
navigator.language ||
|
|
1687
|
-
document.documentElement.lang ||
|
|
1688
|
-
"en");
|
|
1689
|
-
const endpoint = app.options.endpoint;
|
|
1690
|
-
const runtimeUrl = options.runtimeUrl ||
|
|
1691
|
-
(endpoint
|
|
1692
|
-
? new URL(endpoint, window.location.href).origin
|
|
1693
|
-
: window.location.origin);
|
|
1737
|
+
this.host = (0, guideHost_js_1.resolveGuideHost)(app, options);
|
|
1738
|
+
this.guideAdmission = this.host.kind === "guide" ? this.host.admission ?? null : null;
|
|
1739
|
+
this.standaloneAdmissionPending = this.host.kind === "guide" && !this.guideAdmission;
|
|
1740
|
+
if (this.host.kind === "guide" && options.siteKey) {
|
|
1741
|
+
throw new Error("A standalone AI Guide cannot use a legacy project key.");
|
|
1742
|
+
}
|
|
1743
|
+
this.siteKey = this.host.kind === "legacy_browser" ? options.siteKey || this.host.siteKey : "";
|
|
1744
|
+
this.storageNamespace = (0, guideHost_js_1.guideStorageNamespace)(this.host, this.siteKey, window.location.origin);
|
|
1745
|
+
this.widgetViewOptions =
|
|
1746
|
+
this.host.kind === "guide"
|
|
1747
|
+
? { storageNamespace: this.storageNamespace }
|
|
1748
|
+
: {};
|
|
1749
|
+
const runtimeUrl = options.runtimeUrl || this.host.runtimeUrl;
|
|
1694
1750
|
this.runtime = new client_js_1.RuntimeClient(runtimeUrl, version_js_1.VERSION);
|
|
1695
|
-
this.
|
|
1696
|
-
|
|
1697
|
-
|
|
1698
|
-
|
|
1699
|
-
|
|
1700
|
-
|
|
1701
|
-
|
|
1702
|
-
|
|
1703
|
-
|
|
1704
|
-
|
|
1705
|
-
|
|
1751
|
+
this.releaseMount =
|
|
1752
|
+
options.enabled === false
|
|
1753
|
+
? null
|
|
1754
|
+
: (0, guideMount_js_1.claimGuideMount)(document, (0, guideHost_js_1.guideMountIdentity)(this.host, this.siteKey, window.location.origin), this, mountReservation);
|
|
1755
|
+
try {
|
|
1756
|
+
this.storageKey = `__oxvo_ai_live_assist_resume_${this.storageNamespace}`;
|
|
1757
|
+
this.transcriptStorageKey = `__oxvo_ai_live_assist_transcript_${this.storageNamespace}`;
|
|
1758
|
+
this.transferAuthorityStorageKey = `__oxvo_ai_live_assist_transfer_authority_${this.storageNamespace}`;
|
|
1759
|
+
this.legacyStagedPendingLaunchStorageKey = `__oxvo_ai_live_assist_pending_launch_${this.storageNamespace}`;
|
|
1760
|
+
this.stagedPendingLaunchStorageKey = `__oxvo_ai_live_assist_pending_launch_v2_${this.storageNamespace}`;
|
|
1761
|
+
this.terminalEndStorageKey = `__oxvo_ai_live_assist_terminal_end_${this.storageNamespace}`;
|
|
1762
|
+
this.messengerReturnEndStorageKey = `__oxvo_ai_live_assist_handoff_terminal_${this.storageNamespace}`;
|
|
1763
|
+
this.legacyFreshAiReturnProvisionalStorageKey = `__oxvo_ai_live_assist_fresh_return_${this.storageNamespace}`;
|
|
1764
|
+
this.freshAiReturnProvisionalStorageKey = `__oxvo_ai_live_assist_fresh_return_v2_${this.storageNamespace}`;
|
|
1765
|
+
this.pageAssistanceTrackerIdentityStorageKey = `__oxvo_ai_live_assist_page_assistance_tracker_${this.storageNamespace}`;
|
|
1766
|
+
this.transcript = this.readTranscript();
|
|
1767
|
+
this.visitorIdentity = this.host.kind === "guide" ? "" : this.resolveVisitorId();
|
|
1768
|
+
this.pageAssistanceTrackerIdentity =
|
|
1769
|
+
this.readPageAssistanceTrackerIdentity();
|
|
1770
|
+
const resume = this.readResume();
|
|
1771
|
+
this.tabId = resume?.tabId || this.guideAdmission?.pendingIntent()?.tabId || this.host.getTabId() || randomId("tab");
|
|
1772
|
+
this.pageAssistanceBindingGeneration =
|
|
1773
|
+
resume?.pageAssistanceBindingGeneration ||
|
|
1774
|
+
randomId("page_assistance_binding");
|
|
1775
|
+
this.replayReadiness = new ReplaySessionReadiness(this.host.kind === "legacy_browser" ? this.host.replay : null, this.tabId);
|
|
1776
|
+
if (this.standaloneAdmissionPending) {
|
|
1777
|
+
// Never put explicit Guide identity through legacy replay admission.
|
|
1778
|
+
this.unavailableReason =
|
|
1779
|
+
"This AI Guide installation is not available yet.";
|
|
1780
|
+
}
|
|
1781
|
+
else if (this.host.kind === "legacy_browser" && options.recordReplay === false) {
|
|
1782
|
+
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
1783
|
+
this.replayReadiness.disableRecording();
|
|
1784
|
+
}
|
|
1785
|
+
this.windowId = randomId("window");
|
|
1786
|
+
this.terminalOffline = navigator.onLine === false;
|
|
1787
|
+
this.locale =
|
|
1788
|
+
resume?.locale ??
|
|
1789
|
+
boundedLocale(options.locale ||
|
|
1790
|
+
navigator.language ||
|
|
1791
|
+
document.documentElement.lang ||
|
|
1792
|
+
"en");
|
|
1793
|
+
this.lock = new tabLock_js_1.TabActivityLock(this.storageNamespace, this.windowId, (active) => this.handleTabActivityChange(active), (requesterId, requestId) => this.handoffToFocusedTab(requesterId, requestId), (payload, authority, sourceOwnerId) => this.prepareFocusedTabHandoff(payload, authority, sourceOwnerId), {
|
|
1794
|
+
onCommitting: (payload, authority) => this.commitStagedPendingLaunch(payload, authority),
|
|
1795
|
+
onCommitted: (payload, authority) => void this.commitFocusedTabHandoff(payload, authority),
|
|
1796
|
+
onRelinquished: (payload) => this.completeFocusedTabRelinquish(payload),
|
|
1797
|
+
onFailed: (payload, authority) => this.recoverFailedFocusedTabHandoff(payload, authority),
|
|
1798
|
+
onStandby: (payload, authority) => this.acceptStandbyPayload(payload, authority),
|
|
1799
|
+
onRecovery: () => void this.recoverStandbySession(),
|
|
1800
|
+
});
|
|
1801
|
+
this.replayReadiness.setStopHandler(() => this.onReplayRecordingStopped());
|
|
1802
|
+
if (this.standaloneAdmissionPending) {
|
|
1803
|
+
// Schema 3 must own recovery too; do not arm the legacy lifecycle.
|
|
1804
|
+
this.lock.destroy();
|
|
1805
|
+
}
|
|
1806
|
+
else {
|
|
1807
|
+
this.bindWindowLifecycle();
|
|
1808
|
+
}
|
|
1809
|
+
void this.initialize();
|
|
1810
|
+
}
|
|
1811
|
+
catch (error) {
|
|
1812
|
+
this.releaseMount?.();
|
|
1813
|
+
this.releaseMount = null;
|
|
1814
|
+
throw error;
|
|
1815
|
+
}
|
|
1706
1816
|
}
|
|
1707
1817
|
recoveryBusy(record = this.readResume()) {
|
|
1708
1818
|
return (!this.ended &&
|
|
@@ -1712,6 +1822,8 @@ class AiLiveAssist {
|
|
|
1712
1822
|
Boolean(record || this.result || this.modeUpgradeTerminalResult));
|
|
1713
1823
|
}
|
|
1714
1824
|
open(input = {}) {
|
|
1825
|
+
if (this.liveWidget)
|
|
1826
|
+
return this.liveWidget.open((0, exports.normalizeAiGuideOpenInput)(input));
|
|
1715
1827
|
if (this.terminalRequestPending || this.recoveryBusy()) {
|
|
1716
1828
|
return this.getState();
|
|
1717
1829
|
}
|
|
@@ -1721,7 +1833,7 @@ class AiLiveAssist {
|
|
|
1721
1833
|
: normalized.mode;
|
|
1722
1834
|
const unavailable = this.publicModeUnavailable(requestedMode);
|
|
1723
1835
|
if (unavailable) {
|
|
1724
|
-
this.
|
|
1836
|
+
this.presentSessionError(unavailable, false, false);
|
|
1725
1837
|
this.state("unavailable");
|
|
1726
1838
|
throw new TypeError(unavailable);
|
|
1727
1839
|
}
|
|
@@ -1768,6 +1880,12 @@ class AiLiveAssist {
|
|
|
1768
1880
|
return this.getState();
|
|
1769
1881
|
}
|
|
1770
1882
|
close() {
|
|
1883
|
+
if (this.liveWidget) {
|
|
1884
|
+
this.liveWidget.close();
|
|
1885
|
+
return;
|
|
1886
|
+
}
|
|
1887
|
+
if (this.standaloneAdmissionPending)
|
|
1888
|
+
return;
|
|
1771
1889
|
if (this.recoveryBusy())
|
|
1772
1890
|
return;
|
|
1773
1891
|
this.clearPendingIntentBeforeAuthorization();
|
|
@@ -1780,6 +1898,8 @@ class AiLiveAssist {
|
|
|
1780
1898
|
this.emitStateEvent();
|
|
1781
1899
|
}
|
|
1782
1900
|
getState() {
|
|
1901
|
+
if (this.liveWidget)
|
|
1902
|
+
return this.liveWidget.getState();
|
|
1783
1903
|
const resume = this.readResume();
|
|
1784
1904
|
const recovering = this.recoveryBusy(resume);
|
|
1785
1905
|
const active = !this.ended &&
|
|
@@ -1804,6 +1924,10 @@ class AiLiveAssist {
|
|
|
1804
1924
|
};
|
|
1805
1925
|
}
|
|
1806
1926
|
end() {
|
|
1927
|
+
if (this.liveWidget)
|
|
1928
|
+
return this.liveWidget.end();
|
|
1929
|
+
if (this.standaloneAdmissionPending)
|
|
1930
|
+
return Promise.resolve();
|
|
1807
1931
|
return this.requestEnd(null);
|
|
1808
1932
|
}
|
|
1809
1933
|
endInBackground() {
|
|
@@ -1840,6 +1964,13 @@ class AiLiveAssist {
|
|
|
1840
1964
|
return Promise.resolve();
|
|
1841
1965
|
if (this.terminalRequestInFlight)
|
|
1842
1966
|
return this.terminalRequestInFlight;
|
|
1967
|
+
if (this.terminalRequestPending &&
|
|
1968
|
+
this.terminalEndIntent &&
|
|
1969
|
+
this.terminalEndIntent.retryUntil <= Date.now() &&
|
|
1970
|
+
!this.renewExpiredTerminalEndIntent()) {
|
|
1971
|
+
this.presentTerminalRetry();
|
|
1972
|
+
return Promise.reject(new TerminalRequestDeferredError());
|
|
1973
|
+
}
|
|
1843
1974
|
if (!this.terminalRequestPending) {
|
|
1844
1975
|
this.terminalHandoffReconciliationPending = Boolean(this.handoffRequestLifecycleOwner ||
|
|
1845
1976
|
this.messengerHandoffRequestInFlight ||
|
|
@@ -1863,7 +1994,7 @@ class AiLiveAssist {
|
|
|
1863
1994
|
(staged.state === "in_flight" &&
|
|
1864
1995
|
this.pendingLaunchMatches(staged.pendingLaunch, pendingLaunch)))
|
|
1865
1996
|
? { ...pendingLaunch, scopes: [...pendingLaunch.scopes] }
|
|
1866
|
-
:
|
|
1997
|
+
: this.savedGuidePendingLaunch();
|
|
1867
1998
|
const record = this.readResume();
|
|
1868
1999
|
const persistedIntent = this.readTerminalEndIntent();
|
|
1869
2000
|
const intent = record?.terminalEnd ??
|
|
@@ -1913,6 +2044,8 @@ class AiLiveAssist {
|
|
|
1913
2044
|
this.clearReconnectTimer();
|
|
1914
2045
|
if (this.destroyed)
|
|
1915
2046
|
return;
|
|
2047
|
+
this.liveWidget?.destroy();
|
|
2048
|
+
this.liveWidget = null;
|
|
1916
2049
|
const recoveringModeUpgrade = this.relinquishModeUpgradeForRecovery(true, true);
|
|
1917
2050
|
if (!recoveringModeUpgrade)
|
|
1918
2051
|
this.clearModeUpgradeAttempt(true);
|
|
@@ -1933,6 +2066,7 @@ class AiLiveAssist {
|
|
|
1933
2066
|
this.bootstrapAbort?.abort();
|
|
1934
2067
|
this.bootstrapAbort = null;
|
|
1935
2068
|
this.replayReadiness?.destroy();
|
|
2069
|
+
this.guideAdmission?.destroy();
|
|
1936
2070
|
this.clearPendingIntent();
|
|
1937
2071
|
this.discardPendingConfirmationDecisions();
|
|
1938
2072
|
window.removeEventListener("pagehide", this.onPageHide, true);
|
|
@@ -1962,10 +2096,18 @@ class AiLiveAssist {
|
|
|
1962
2096
|
if (controllerWindow.OxvoAiGuide === this) {
|
|
1963
2097
|
Reflect.deleteProperty(controllerWindow, "OxvoAiGuide");
|
|
1964
2098
|
}
|
|
2099
|
+
this.releaseMount?.();
|
|
2100
|
+
this.releaseMount = null;
|
|
1965
2101
|
}
|
|
1966
2102
|
async initialize() {
|
|
1967
2103
|
if (this.options.enabled === false || this.destroyed)
|
|
1968
2104
|
return;
|
|
2105
|
+
if (this.standaloneAdmissionPending) {
|
|
2106
|
+
this.initialized = true;
|
|
2107
|
+
this.state("unavailable");
|
|
2108
|
+
this.emitReadyEvent();
|
|
2109
|
+
return;
|
|
2110
|
+
}
|
|
1969
2111
|
// Terminal intent is authoritative over normal widget admission. Restore it
|
|
1970
2112
|
// before bootstrap so a rejected, unavailable, or incompatible bootstrap
|
|
1971
2113
|
// cannot revive the session or strand a credential-backed End request.
|
|
@@ -1990,12 +2132,12 @@ class AiLiveAssist {
|
|
|
1990
2132
|
this.bootstrapAbort = controller;
|
|
1991
2133
|
const timeout = setTimeout(() => controller.abort(), Math.max(1000, Math.min(15000, this.options.bootstrapTimeoutMs ?? 15000)));
|
|
1992
2134
|
try {
|
|
1993
|
-
const bootstrap = await this.
|
|
2135
|
+
const bootstrap = await this.requestBootstrap(controller.signal);
|
|
1994
2136
|
if (this.destroyed)
|
|
1995
2137
|
return;
|
|
1996
2138
|
this.locale = (0, exports.resolveAiGuideLocale)(bootstrap.locale, this.locale);
|
|
1997
2139
|
this.syncAgentDiscovery(bootstrap.agentAccess?.discoveryUrl ?? null);
|
|
1998
|
-
if (bootstrap.replayRecordingEnabled === false) {
|
|
2140
|
+
if (!this.guideAdmission && bootstrap.replayRecordingEnabled === false) {
|
|
1999
2141
|
this.bootstrap = bootstrap;
|
|
2000
2142
|
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
2001
2143
|
this.replayReadiness.disableRecording();
|
|
@@ -2016,6 +2158,9 @@ class AiLiveAssist {
|
|
|
2016
2158
|
(!bootstrap.capabilities.voice ||
|
|
2017
2159
|
!bootstrap.capabilities.voicePresence ||
|
|
2018
2160
|
!bootstrap.appearance?.voicePresence?.enabled))) {
|
|
2161
|
+
if (this.guideAdmission && !bootstrap.available && this.guideAdmission.pendingIntent()) {
|
|
2162
|
+
this.endInBackground();
|
|
2163
|
+
}
|
|
2019
2164
|
return;
|
|
2020
2165
|
}
|
|
2021
2166
|
if (bootstrap.widgetVersion &&
|
|
@@ -2026,6 +2171,17 @@ class AiLiveAssist {
|
|
|
2026
2171
|
!versionAtLeast(version_js_1.VERSION, bootstrap.minimumClientVersion)) {
|
|
2027
2172
|
return;
|
|
2028
2173
|
}
|
|
2174
|
+
if (bootstrap.providerProtocol === "live") {
|
|
2175
|
+
if (!this.guideAdmission || bootstrap.schemaVersion !== 3 || voicePresence)
|
|
2176
|
+
return;
|
|
2177
|
+
this.bootstrap = bootstrap;
|
|
2178
|
+
this.liveWidget = new liveGuideWidget_js_1.LiveGuideWidget({ bootstrap, admission: this.guideAdmission, runtime: this.runtime,
|
|
2179
|
+
tabId: this.tabId, locale: this.locale, messages: this.options.messages, viewOptions: this.widgetViewOptions,
|
|
2180
|
+
acquire: () => this.lock.acquire(), release: () => this.lock.release(), onState: () => this.emitStateEvent() });
|
|
2181
|
+
this.view = this.liveWidget.view;
|
|
2182
|
+
this.lifecyclePhase = "ready";
|
|
2183
|
+
return;
|
|
2184
|
+
}
|
|
2029
2185
|
let resume = this.readResume();
|
|
2030
2186
|
const sharedTerminalIntent = this.readTerminalEndIntent();
|
|
2031
2187
|
const terminalIntent = resume?.terminalEnd ??
|
|
@@ -2074,7 +2230,7 @@ class AiLiveAssist {
|
|
|
2074
2230
|
this.transcriptRestoredFromCache = false;
|
|
2075
2231
|
this.view = voicePresenceView
|
|
2076
2232
|
? new voicePresenceUi_js_1.VoicePresenceView(effectiveBootstrap, this.options.messages ?? {}, callbacks, this.tabId, (fallback) => void this.activateFallback(fallback), this.options.visualTestMode === true)
|
|
2077
|
-
: new ui_js_1.WidgetView(effectiveBootstrap, this.options.messages ?? {}, callbacks);
|
|
2233
|
+
: new ui_js_1.WidgetView(effectiveBootstrap, this.options.messages ?? {}, callbacks, this.standardWidgetViewOptions(effectiveBootstrap));
|
|
2078
2234
|
this.syncCompanionView();
|
|
2079
2235
|
this.initializePageAssistancePreference(effectiveBootstrap);
|
|
2080
2236
|
this.startMessengerIntegration(effectiveBootstrap);
|
|
@@ -2172,7 +2328,7 @@ class AiLiveAssist {
|
|
|
2172
2328
|
}
|
|
2173
2329
|
catch (error) {
|
|
2174
2330
|
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
|
2175
|
-
this.
|
|
2331
|
+
this.presentSessionError(this.publicError(error), this.retryable(error));
|
|
2176
2332
|
}
|
|
2177
2333
|
}
|
|
2178
2334
|
finally {
|
|
@@ -2274,6 +2430,53 @@ class AiLiveAssist {
|
|
|
2274
2430
|
if (index >= 0)
|
|
2275
2431
|
this.queuedQuestions.splice(index, 1);
|
|
2276
2432
|
}
|
|
2433
|
+
restoreAdmittedTextLaunch(question, launchIdempotencyKey, pendingLaunch) {
|
|
2434
|
+
if (!question)
|
|
2435
|
+
return false;
|
|
2436
|
+
const ownsQuestion = this.pendingQuestion === question ||
|
|
2437
|
+
this.queuedQuestions.includes(question);
|
|
2438
|
+
if (!ownsQuestion)
|
|
2439
|
+
return false;
|
|
2440
|
+
this.removePendingQuestion(question);
|
|
2441
|
+
this.acceptedRequestIds.delete(question.requestId);
|
|
2442
|
+
if (this.pendingOpenIntent?.launchIdempotencyKey === launchIdempotencyKey) {
|
|
2443
|
+
this.pendingOpenIntent = null;
|
|
2444
|
+
}
|
|
2445
|
+
if (pendingLaunch &&
|
|
2446
|
+
this.lastLaunch &&
|
|
2447
|
+
this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
2448
|
+
this.lastLaunch = null;
|
|
2449
|
+
const staged = this.readStagedPendingLaunch();
|
|
2450
|
+
if (staged &&
|
|
2451
|
+
this.pendingLaunchMatches(staged.pendingLaunch, pendingLaunch) &&
|
|
2452
|
+
(staged.authority.ownerId === this.windowId ||
|
|
2453
|
+
staged.claimAuthority?.ownerId === this.windowId)) {
|
|
2454
|
+
this.clearStagedPendingLaunch(staged.pendingLaunch, staged.authority);
|
|
2455
|
+
}
|
|
2456
|
+
}
|
|
2457
|
+
if (this.destroyed || this.ended || this.terminalRequestPending) {
|
|
2458
|
+
return true;
|
|
2459
|
+
}
|
|
2460
|
+
if (this.view instanceof ui_js_1.WidgetView) {
|
|
2461
|
+
this.view.showStartRetry(question.text, this.view.message("error"), question.submissionId);
|
|
2462
|
+
}
|
|
2463
|
+
else {
|
|
2464
|
+
this.presentSessionError(this.view?.message("error"), false, false);
|
|
2465
|
+
}
|
|
2466
|
+
this.state("error");
|
|
2467
|
+
return true;
|
|
2468
|
+
}
|
|
2469
|
+
settlePreRuntimeLaunchFailure(question, launchIdempotencyKey, pendingLaunch, allowFocusedHandoff) {
|
|
2470
|
+
if (this.restoreAdmittedTextLaunch(question, launchIdempotencyKey, pendingLaunch)) {
|
|
2471
|
+
return;
|
|
2472
|
+
}
|
|
2473
|
+
if (this.destroyed || this.ended || this.terminalRequestPending)
|
|
2474
|
+
return;
|
|
2475
|
+
if (allowFocusedHandoff && this.requestFocusedHandoff())
|
|
2476
|
+
return;
|
|
2477
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), true, false);
|
|
2478
|
+
this.state("error");
|
|
2479
|
+
}
|
|
2277
2480
|
bindQuestionToSupersededConfirmation(question) {
|
|
2278
2481
|
const identity = question.supersededConfirmation;
|
|
2279
2482
|
if (!identity)
|
|
@@ -2287,6 +2490,15 @@ class AiLiveAssist {
|
|
|
2287
2490
|
performPendingOpen() {
|
|
2288
2491
|
const intent = this.pendingOpenIntent;
|
|
2289
2492
|
const view = this.view;
|
|
2493
|
+
if (intent && this.liveWidget && !this.destroyed) {
|
|
2494
|
+
const questions = [this.pendingQuestion, ...this.queuedQuestions].filter((question) => question !== null);
|
|
2495
|
+
this.liveWidget.open({ mode: intent.mode });
|
|
2496
|
+
for (const question of questions) {
|
|
2497
|
+
this.liveWidget.open({ mode: "text", question: question.text, requestId: question.requestId });
|
|
2498
|
+
}
|
|
2499
|
+
this.clearPendingIntent();
|
|
2500
|
+
return;
|
|
2501
|
+
}
|
|
2290
2502
|
if (!intent ||
|
|
2291
2503
|
!view ||
|
|
2292
2504
|
this.destroyed ||
|
|
@@ -3982,12 +4194,18 @@ class AiLiveAssist {
|
|
|
3982
4194
|
}
|
|
3983
4195
|
return scopes;
|
|
3984
4196
|
}
|
|
4197
|
+
standardWidgetViewOptions(bootstrap) {
|
|
4198
|
+
return {
|
|
4199
|
+
...this.widgetViewOptions,
|
|
4200
|
+
manualTurnsSupported: bootstrap.voice?.turnMode === "manual",
|
|
4201
|
+
};
|
|
4202
|
+
}
|
|
3985
4203
|
createMessengerReturnView(bootstrap) {
|
|
3986
4204
|
const callbacks = this.widgetCallbacks();
|
|
3987
4205
|
if ((bootstrap.experienceMode ?? "standard") === "voice_presence") {
|
|
3988
4206
|
return new voicePresenceUi_js_1.VoicePresenceView(bootstrap, this.options.messages ?? {}, callbacks, this.tabId, (fallback) => void this.activateFallback(fallback), this.options.visualTestMode === true);
|
|
3989
4207
|
}
|
|
3990
|
-
return new ui_js_1.WidgetView(bootstrap, this.options.messages ?? {}, callbacks);
|
|
4208
|
+
return new ui_js_1.WidgetView(bootstrap, this.options.messages ?? {}, callbacks, this.standardWidgetViewOptions(bootstrap));
|
|
3991
4209
|
}
|
|
3992
4210
|
freshAiReturnProvisionalFor(conversationId) {
|
|
3993
4211
|
const provisional = this.readFreshAiReturnProvisional();
|
|
@@ -4046,10 +4264,10 @@ class AiLiveAssist {
|
|
|
4046
4264
|
quiesceProvisionalFreshAiReturn() {
|
|
4047
4265
|
this.launchGeneration += 1;
|
|
4048
4266
|
this.clearReconnectTimer();
|
|
4049
|
-
this.media?.endPushToTalk();
|
|
4267
|
+
this.media?.endPushToTalk?.();
|
|
4050
4268
|
this.media?.setMuted(true);
|
|
4051
4269
|
this.pushActive = false;
|
|
4052
|
-
this.view?.setPushActive(false);
|
|
4270
|
+
this.view?.setPushActive?.(false);
|
|
4053
4271
|
this.view?.setMuted(true);
|
|
4054
4272
|
this.view?.setPaused(true);
|
|
4055
4273
|
this.cleanupTransport();
|
|
@@ -4535,10 +4753,12 @@ class AiLiveAssist {
|
|
|
4535
4753
|
return true;
|
|
4536
4754
|
}
|
|
4537
4755
|
async refreshCompanionBootstrap() {
|
|
4756
|
+
if (this.guideAdmission)
|
|
4757
|
+
return false;
|
|
4538
4758
|
const controller = new AbortController();
|
|
4539
4759
|
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
4540
4760
|
try {
|
|
4541
|
-
const bootstrap = await this.
|
|
4761
|
+
const bootstrap = await this.requestBootstrap(controller.signal);
|
|
4542
4762
|
if (this.destroyed)
|
|
4543
4763
|
return false;
|
|
4544
4764
|
this.bootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
@@ -4685,7 +4905,7 @@ class AiLiveAssist {
|
|
|
4685
4905
|
this.media?.setMuted(true);
|
|
4686
4906
|
return true;
|
|
4687
4907
|
}
|
|
4688
|
-
async restoreAiAfterFailedSupportSwitch(mode, sessionId, previousMuted
|
|
4908
|
+
async restoreAiAfterFailedSupportSwitch(mode, sessionId, previousMuted) {
|
|
4689
4909
|
const restored = await this.requestCompanionSurface("ai", mode, (0, client_js_1.idempotencyKey)("companion_reconcile"), sessionId);
|
|
4690
4910
|
if (!restored) {
|
|
4691
4911
|
this.media?.endPushToTalk();
|
|
@@ -4704,10 +4924,13 @@ class AiLiveAssist {
|
|
|
4704
4924
|
this.view?.setPaused(false);
|
|
4705
4925
|
this.media?.setMuted(previousMuted);
|
|
4706
4926
|
this.view?.setMuted(previousMuted);
|
|
4707
|
-
|
|
4708
|
-
|
|
4709
|
-
|
|
4710
|
-
|
|
4927
|
+
// The provider-side push was cancelled before the surface transition.
|
|
4928
|
+
// Restoring the old local capture here would have no fresh push authority
|
|
4929
|
+
// and could transmit behind a still-running panel transition. Return to a
|
|
4930
|
+
// clean, ready manual-turn state and require a new visitor press instead.
|
|
4931
|
+
this.media?.endPushToTalk();
|
|
4932
|
+
this.pushActive = false;
|
|
4933
|
+
this.view?.setPushActive(false);
|
|
4711
4934
|
this.closeMessengerBeforeOpen();
|
|
4712
4935
|
await this.prepareMessengerIntegration();
|
|
4713
4936
|
return true;
|
|
@@ -4863,7 +5086,6 @@ class AiLiveAssist {
|
|
|
4863
5086
|
return;
|
|
4864
5087
|
}
|
|
4865
5088
|
const previousMuted = this.media?.isMuted ?? false;
|
|
4866
|
-
const previousPushActive = this.pushActive;
|
|
4867
5089
|
// Quiesce capture before the AI surface begins its hide/morph. The server
|
|
4868
5090
|
// has already paused the session, so no microphone track may remain live
|
|
4869
5091
|
// while Messenger visibility is being confirmed.
|
|
@@ -4875,7 +5097,7 @@ class AiLiveAssist {
|
|
|
4875
5097
|
this.view?.setPaused(true);
|
|
4876
5098
|
const suspended = await this.suspendAiSurfaceForMessenger(switchedCurrent);
|
|
4877
5099
|
if (!suspended || !switchedCurrent()) {
|
|
4878
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5100
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4879
5101
|
return;
|
|
4880
5102
|
}
|
|
4881
5103
|
const switchGuard = {
|
|
@@ -4897,12 +5119,12 @@ class AiLiveAssist {
|
|
|
4897
5119
|
}
|
|
4898
5120
|
}
|
|
4899
5121
|
if (!opened || !switchedCurrent()) {
|
|
4900
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5122
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4901
5123
|
return;
|
|
4902
5124
|
}
|
|
4903
5125
|
const returnActivated = await this.createMessengerReturnActivationPromise(messenger, displayId);
|
|
4904
5126
|
if (!returnActivated || !switchedCurrent()) {
|
|
4905
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5127
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4906
5128
|
return;
|
|
4907
5129
|
}
|
|
4908
5130
|
this.messenger = messenger;
|
|
@@ -6075,6 +6297,35 @@ class AiLiveAssist {
|
|
|
6075
6297
|
}
|
|
6076
6298
|
widgetCallbacks() {
|
|
6077
6299
|
return {
|
|
6300
|
+
onRecordingConsent: (allowed) => {
|
|
6301
|
+
if (!this.guideAdmission?.recordingConfigured)
|
|
6302
|
+
return;
|
|
6303
|
+
// Recording can outlive an AI conversation; its opt-out remains usable.
|
|
6304
|
+
if (!allowed)
|
|
6305
|
+
this.guideAdmission.setRecordingChoice(false);
|
|
6306
|
+
if (!this.result || this.ended || this.terminalRequestPending)
|
|
6307
|
+
return;
|
|
6308
|
+
if (allowed && !this.guideAdmission.setRecordingChoice(true)) {
|
|
6309
|
+
if (this.view instanceof ui_js_1.WidgetView)
|
|
6310
|
+
this.view.setRecordingConsent(false);
|
|
6311
|
+
return;
|
|
6312
|
+
}
|
|
6313
|
+
const scopes = this.scopes.filter(scope => scope !== "session_recording");
|
|
6314
|
+
if (allowed)
|
|
6315
|
+
scopes.push("session_recording");
|
|
6316
|
+
// Revocation stops owned capture immediately; enabling waits for the
|
|
6317
|
+
// server's authoritative consent.updated acknowledgement.
|
|
6318
|
+
if (!allowed)
|
|
6319
|
+
this.guideAdmission.updateRecordingConsent(scopes);
|
|
6320
|
+
this.scopes = scopes;
|
|
6321
|
+
if (!allowed) {
|
|
6322
|
+
const record = this.readResume();
|
|
6323
|
+
if (record)
|
|
6324
|
+
this.storeResume({ ...record, scopes: [...scopes] });
|
|
6325
|
+
}
|
|
6326
|
+
this.send("consent.update", { scopes, locale: this.locale });
|
|
6327
|
+
},
|
|
6328
|
+
onCtaResult: (result) => this.resolveCtaOffer(result),
|
|
6078
6329
|
onStart: (mode, scopes, initialQuestion) => {
|
|
6079
6330
|
// Voice-presence has no separate restart control. Treat its explicit
|
|
6080
6331
|
// post-terminal Start as the same controller-owned new-session gate.
|
|
@@ -6086,6 +6337,7 @@ class AiLiveAssist {
|
|
|
6086
6337
|
this.recoveryBusy()) {
|
|
6087
6338
|
return false;
|
|
6088
6339
|
}
|
|
6340
|
+
let admittedQuestion = null;
|
|
6089
6341
|
if (initialQuestion) {
|
|
6090
6342
|
if (this.pendingQuestionCount() >= PUBLIC_QUESTION_QUEUE_CAPACITY) {
|
|
6091
6343
|
this.view?.setStatus(PUBLIC_QUESTION_BUSY_MESSAGE);
|
|
@@ -6099,6 +6351,16 @@ class AiLiveAssist {
|
|
|
6099
6351
|
this.acceptedRequestIds.delete(requestId);
|
|
6100
6352
|
return false;
|
|
6101
6353
|
}
|
|
6354
|
+
admittedQuestion = question;
|
|
6355
|
+
if (this.view instanceof ui_js_1.WidgetView) {
|
|
6356
|
+
this.view.addCaption("user", question.text, true, {
|
|
6357
|
+
localQuestionId: question.submissionId,
|
|
6358
|
+
});
|
|
6359
|
+
}
|
|
6360
|
+
else {
|
|
6361
|
+
this.view?.addCaption("user", question.text, true);
|
|
6362
|
+
}
|
|
6363
|
+
question.shown = true;
|
|
6102
6364
|
}
|
|
6103
6365
|
const launchKey = this.pendingOpenIntent?.launchIdempotencyKey ??
|
|
6104
6366
|
(0, client_js_1.idempotencyKey)("launch");
|
|
@@ -6115,9 +6377,21 @@ class AiLiveAssist {
|
|
|
6115
6377
|
if (this.destroyed ||
|
|
6116
6378
|
this.ended ||
|
|
6117
6379
|
this.terminalRequestPending ||
|
|
6118
|
-
this.recoveryBusy())
|
|
6380
|
+
this.recoveryBusy()) {
|
|
6381
|
+
if (mode !== "text" ||
|
|
6382
|
+
!this.restoreAdmittedTextLaunch(admittedQuestion ?? undefined, launchKey)) {
|
|
6383
|
+
if (!this.destroyed &&
|
|
6384
|
+
!this.ended &&
|
|
6385
|
+
!this.terminalRequestPending) {
|
|
6386
|
+
this.presentSessionError(this.view?.message("error"), false, false);
|
|
6387
|
+
this.state("error");
|
|
6388
|
+
}
|
|
6389
|
+
}
|
|
6119
6390
|
return;
|
|
6120
|
-
|
|
6391
|
+
}
|
|
6392
|
+
void this.launch(mode, scopes, launchKey, {
|
|
6393
|
+
...(admittedQuestion ? { admittedQuestion } : {}),
|
|
6394
|
+
});
|
|
6121
6395
|
});
|
|
6122
6396
|
return true;
|
|
6123
6397
|
},
|
|
@@ -6167,9 +6441,9 @@ class AiLiveAssist {
|
|
|
6167
6441
|
onFeedback: (outcome) => void this.submitFeedback(outcome),
|
|
6168
6442
|
onRetry: () => void this.retry(),
|
|
6169
6443
|
onPlaybackState: (value) => {
|
|
6170
|
-
|
|
6171
|
-
|
|
6172
|
-
|
|
6444
|
+
this.media?.setAssistantPlaybackAudible(value.state === "playing" && value.audible);
|
|
6445
|
+
this.pendingPlaybackState = { ...value };
|
|
6446
|
+
this.flushPlaybackState();
|
|
6173
6447
|
},
|
|
6174
6448
|
onOpenChange: (open) => this.handleViewOpenChange(open),
|
|
6175
6449
|
};
|
|
@@ -6189,6 +6463,7 @@ class AiLiveAssist {
|
|
|
6189
6463
|
// fenced. Disconnect callbacks therefore cannot schedule a replacement
|
|
6190
6464
|
// session with the retiring credentials.
|
|
6191
6465
|
this.queuedLaunchToken = null;
|
|
6466
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
6192
6467
|
this.launchGeneration =
|
|
6193
6468
|
(Number.isSafeInteger(this.launchGeneration)
|
|
6194
6469
|
? this.launchGeneration
|
|
@@ -6228,6 +6503,7 @@ class AiLiveAssist {
|
|
|
6228
6503
|
this.visualConsentGranted = false;
|
|
6229
6504
|
this.manualTurn = false;
|
|
6230
6505
|
this.pushActive = false;
|
|
6506
|
+
this.pendingPlaybackState = null;
|
|
6231
6507
|
this.ended = false;
|
|
6232
6508
|
this.replayReadiness.startFreshSessionIfInactive?.();
|
|
6233
6509
|
this.state("ready");
|
|
@@ -6410,7 +6686,7 @@ class AiLiveAssist {
|
|
|
6410
6686
|
this.view?.destroy();
|
|
6411
6687
|
if (!isCurrent())
|
|
6412
6688
|
return;
|
|
6413
|
-
this.view = new ui_js_1.WidgetView(fallbackBootstrap, this.options.messages ?? {}, this.widgetCallbacks());
|
|
6689
|
+
this.view = new ui_js_1.WidgetView(fallbackBootstrap, this.options.messages ?? {}, this.widgetCallbacks(), this.standardWidgetViewOptions(fallbackBootstrap));
|
|
6414
6690
|
this.startMessengerIntegration(fallbackBootstrap);
|
|
6415
6691
|
if (isCurrent())
|
|
6416
6692
|
this.state("fallback_standard_offered");
|
|
@@ -6427,7 +6703,7 @@ class AiLiveAssist {
|
|
|
6427
6703
|
}
|
|
6428
6704
|
if (!offered.has("handoff_context")) {
|
|
6429
6705
|
if (isCurrent()) {
|
|
6430
|
-
this.
|
|
6706
|
+
this.presentSessionError(this.view?.message("humanUnavailable"), false, false);
|
|
6431
6707
|
}
|
|
6432
6708
|
return;
|
|
6433
6709
|
}
|
|
@@ -6454,6 +6730,7 @@ class AiLiveAssist {
|
|
|
6454
6730
|
this.ended ||
|
|
6455
6731
|
this.destroyed ||
|
|
6456
6732
|
this.recoveryBusy()) {
|
|
6733
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6457
6734
|
releaseMessengerReturnIfPreRuntime();
|
|
6458
6735
|
return;
|
|
6459
6736
|
}
|
|
@@ -6464,9 +6741,11 @@ class AiLiveAssist {
|
|
|
6464
6741
|
!this.destroyed;
|
|
6465
6742
|
const bootstrap = this.bootstrap;
|
|
6466
6743
|
if (!bootstrap?.configRevision || !bootstrap.consent || !this.view) {
|
|
6744
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6467
6745
|
releaseMessengerReturnIfPreRuntime();
|
|
6468
6746
|
return;
|
|
6469
6747
|
}
|
|
6748
|
+
const launchConsentProof = this.capturePendingLaunchConsentProof(bootstrap);
|
|
6470
6749
|
const retryIntent = options.pendingLaunch;
|
|
6471
6750
|
if (retryIntent &&
|
|
6472
6751
|
canonicalJson({ mode, scopes, idempotencyKey: launchIdempotencyKey }) !==
|
|
@@ -6475,6 +6754,7 @@ class AiLiveAssist {
|
|
|
6475
6754
|
scopes: retryIntent.scopes,
|
|
6476
6755
|
idempotencyKey: retryIntent.idempotencyKey,
|
|
6477
6756
|
})) {
|
|
6757
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6478
6758
|
releaseMessengerReturnIfPreRuntime();
|
|
6479
6759
|
return;
|
|
6480
6760
|
}
|
|
@@ -6482,14 +6762,16 @@ class AiLiveAssist {
|
|
|
6482
6762
|
? bindPendingLaunchIntent(retryIntent, bootstrap)
|
|
6483
6763
|
: freshPendingLaunchIntent(mode, scopes, launchIdempotencyKey, bootstrap);
|
|
6484
6764
|
if (!durableLaunch) {
|
|
6485
|
-
this.
|
|
6765
|
+
if (!this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey)) {
|
|
6766
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
6767
|
+
}
|
|
6486
6768
|
releaseMessengerReturnIfPreRuntime();
|
|
6487
6769
|
return;
|
|
6488
6770
|
}
|
|
6489
6771
|
const { experienceMode, protocolVersion } = durableLaunch;
|
|
6490
6772
|
const voicePresence = experienceMode === "voice_presence";
|
|
6491
6773
|
if (voicePresence && mode !== "voice") {
|
|
6492
|
-
this.
|
|
6774
|
+
this.presentSessionError("Voice assist requires microphone access.", false, false);
|
|
6493
6775
|
releaseMessengerReturnIfPreRuntime();
|
|
6494
6776
|
return;
|
|
6495
6777
|
}
|
|
@@ -6515,7 +6797,7 @@ class AiLiveAssist {
|
|
|
6515
6797
|
this.state("reconnecting");
|
|
6516
6798
|
const handoffRequested = this.requestFocusedHandoff();
|
|
6517
6799
|
if (handoffRequested === false) {
|
|
6518
|
-
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration);
|
|
6800
|
+
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, false, launchConsentProof);
|
|
6519
6801
|
}
|
|
6520
6802
|
releaseMessengerReturnIfPreRuntime();
|
|
6521
6803
|
return;
|
|
@@ -6527,7 +6809,7 @@ class AiLiveAssist {
|
|
|
6527
6809
|
if (!this.lock.acquire()) {
|
|
6528
6810
|
this.view.showActiveElsewhere(false);
|
|
6529
6811
|
this.launchInFlight = false;
|
|
6530
|
-
this.
|
|
6812
|
+
this.settlePreRuntimeLaunchFailure(options.admittedQuestion, launchIdempotencyKey, durableLaunch, true);
|
|
6531
6813
|
releaseMessengerReturnIfPreRuntime();
|
|
6532
6814
|
return;
|
|
6533
6815
|
}
|
|
@@ -6546,12 +6828,14 @@ class AiLiveAssist {
|
|
|
6546
6828
|
this.state("requesting_access");
|
|
6547
6829
|
let runtimeSessionCreated = false;
|
|
6548
6830
|
let media = null;
|
|
6831
|
+
let startupDeadline = null;
|
|
6832
|
+
let startupDeadlineExceeded = false;
|
|
6549
6833
|
try {
|
|
6550
6834
|
this.replayReadiness.startFreshSessionIfInactive?.();
|
|
6551
|
-
const replay = await this.
|
|
6835
|
+
const replay = await this.sessionConnectionScope();
|
|
6552
6836
|
if (this.destroyed || this.ended)
|
|
6553
6837
|
return;
|
|
6554
|
-
this.
|
|
6838
|
+
this.assertSessionConnectionScope(replay);
|
|
6555
6839
|
const controller = new AbortController();
|
|
6556
6840
|
const connectionGeneration = this.beginConnectionAttempt(controller);
|
|
6557
6841
|
const assertConnectionCurrent = () => this.assertConnectionCurrent(controller, connectionGeneration, replay, options.messengerReturnAuthority, activeMode, launchIdempotencyKey);
|
|
@@ -6577,30 +6861,10 @@ class AiLiveAssist {
|
|
|
6577
6861
|
throw error;
|
|
6578
6862
|
}
|
|
6579
6863
|
assertConnectionCurrent();
|
|
6580
|
-
if (
|
|
6581
|
-
|
|
6582
|
-
!bootstrap.capabilities?.text ||
|
|
6583
|
-
options.messengerReturnAuthority !== undefined ||
|
|
6584
|
-
retryIntent !== undefined) {
|
|
6585
|
-
throw error;
|
|
6864
|
+
if (mode === "voice") {
|
|
6865
|
+
throw new InitialVoiceMicrophoneUnavailableError(error);
|
|
6586
6866
|
}
|
|
6587
|
-
|
|
6588
|
-
activeMode = "text";
|
|
6589
|
-
activeScopes = activeScopes.filter((scope) => scope !== "microphone");
|
|
6590
|
-
this.manualTurn = false;
|
|
6591
|
-
media = this.createMedia(() => {
|
|
6592
|
-
try {
|
|
6593
|
-
assertConnectionCurrent();
|
|
6594
|
-
return true;
|
|
6595
|
-
}
|
|
6596
|
-
catch {
|
|
6597
|
-
return false;
|
|
6598
|
-
}
|
|
6599
|
-
});
|
|
6600
|
-
this.media = media;
|
|
6601
|
-
if (options.startMuted === true)
|
|
6602
|
-
media.setMuted(true);
|
|
6603
|
-
this.view.setStatus(this.view.message("microphoneUnavailable"));
|
|
6867
|
+
throw error;
|
|
6604
6868
|
}
|
|
6605
6869
|
assertConnectionCurrent();
|
|
6606
6870
|
if (voicePresence)
|
|
@@ -6629,18 +6893,23 @@ class AiLiveAssist {
|
|
|
6629
6893
|
this.releaseMedia(media);
|
|
6630
6894
|
this.cleanupTransport();
|
|
6631
6895
|
this.lock.release();
|
|
6896
|
+
this.settlePreRuntimeLaunchFailure(options.admittedQuestion, launchIdempotencyKey, durableLaunch, false);
|
|
6632
6897
|
return;
|
|
6633
6898
|
}
|
|
6899
|
+
const startupDeadlineFailure = new Promise((_resolve, reject) => {
|
|
6900
|
+
startupDeadline = setTimeout(() => {
|
|
6901
|
+
startupDeadlineExceeded = true;
|
|
6902
|
+
controller.abort();
|
|
6903
|
+
reject(new InitialSessionStartupDeadlineError());
|
|
6904
|
+
}, INITIAL_SESSION_STARTUP_TIMEOUT_MS);
|
|
6905
|
+
});
|
|
6634
6906
|
const requestedLaunchPath = path();
|
|
6635
6907
|
runtimeLaunchStarted = true;
|
|
6636
|
-
const authorization = this.
|
|
6637
|
-
siteKey: this.siteKey,
|
|
6908
|
+
const authorization = this.requestLaunch({
|
|
6638
6909
|
configRevision: bootstrap.configRevision,
|
|
6639
6910
|
path: requestedLaunchPath,
|
|
6640
6911
|
tabId: this.tabId,
|
|
6641
6912
|
mode: activeMode,
|
|
6642
|
-
anonymousId: this.visitorId(),
|
|
6643
|
-
replay,
|
|
6644
6913
|
disclosureChecksum: bootstrap.consent.disclosureChecksum,
|
|
6645
6914
|
scopes: activeScopes,
|
|
6646
6915
|
locale: this.locale,
|
|
@@ -6654,12 +6923,12 @@ class AiLiveAssist {
|
|
|
6654
6923
|
: {}),
|
|
6655
6924
|
lowPower: this.lowPowerMode(),
|
|
6656
6925
|
idempotencyKey: launchIdempotencyKey,
|
|
6657
|
-
}, controller.signal);
|
|
6926
|
+
}, replay, controller.signal);
|
|
6658
6927
|
this.pendingSessionAuthorization = authorization;
|
|
6659
6928
|
this.pendingSessionAuthorizationController = controller;
|
|
6660
6929
|
let result;
|
|
6661
6930
|
try {
|
|
6662
|
-
result = await authorization;
|
|
6931
|
+
result = await Promise.race([authorization, startupDeadlineFailure]);
|
|
6663
6932
|
}
|
|
6664
6933
|
finally {
|
|
6665
6934
|
if (this.pendingSessionAuthorization === authorization) {
|
|
@@ -6669,7 +6938,7 @@ class AiLiveAssist {
|
|
|
6669
6938
|
}
|
|
6670
6939
|
}
|
|
6671
6940
|
}
|
|
6672
|
-
if (result
|
|
6941
|
+
if (!this.matchesLaunchSchema(result, protocolVersion) ||
|
|
6673
6942
|
result.protocolVersion !== protocolVersion ||
|
|
6674
6943
|
result.experienceMode !== experienceMode) {
|
|
6675
6944
|
throw new client_js_1.RuntimeClientError("PROTOCOL_INVALID", "The voice assist runtime returned an incompatible session.", false, null, 502);
|
|
@@ -6698,18 +6967,26 @@ class AiLiveAssist {
|
|
|
6698
6967
|
!this.acceptStagedPendingLaunch(durableLaunch, result))) {
|
|
6699
6968
|
throw new client_js_1.RuntimeClientError("RESUME_STORAGE_UNAVAILABLE", "The session could not be stored for recovery.", true, null, 503);
|
|
6700
6969
|
}
|
|
6701
|
-
await Promise.
|
|
6970
|
+
await Promise.race([
|
|
6702
6971
|
this.connectTransport(result, activeMode, activeScopes, false, controller, media, assertConnectionCurrent),
|
|
6703
|
-
|
|
6704
|
-
? Promise.resolve(false)
|
|
6705
|
-
: this.associateFreshCompanionSession(activeMode, result.sessionId),
|
|
6972
|
+
startupDeadlineFailure,
|
|
6706
6973
|
]);
|
|
6974
|
+
if (startupDeadline !== null) {
|
|
6975
|
+
clearTimeout(startupDeadline);
|
|
6976
|
+
startupDeadline = null;
|
|
6977
|
+
}
|
|
6978
|
+
if (options.associateCompanion !== false) {
|
|
6979
|
+
await this.associateFreshCompanionSession(activeMode, result.sessionId);
|
|
6980
|
+
}
|
|
6707
6981
|
if (options.startMuted === true && activeMode === "voice") {
|
|
6708
6982
|
media.setMuted(true);
|
|
6709
6983
|
this.view?.setMuted(true);
|
|
6710
6984
|
}
|
|
6711
6985
|
this.reconnectAttempts = 0;
|
|
6712
6986
|
this.visitorActiveEligibilityRecheckKey = null;
|
|
6987
|
+
if (this.initialLaunchDeadlineRetryKey === launchIdempotencyKey) {
|
|
6988
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
6989
|
+
}
|
|
6713
6990
|
this.lastLaunch = null;
|
|
6714
6991
|
}
|
|
6715
6992
|
catch (error) {
|
|
@@ -6723,11 +7000,60 @@ class AiLiveAssist {
|
|
|
6723
7000
|
this.lock.release();
|
|
6724
7001
|
if (!launchIsCurrent())
|
|
6725
7002
|
return;
|
|
6726
|
-
const
|
|
7003
|
+
const effectiveError = startupDeadlineExceeded
|
|
7004
|
+
? new InitialSessionStartupDeadlineError()
|
|
7005
|
+
: error;
|
|
7006
|
+
if (effectiveError instanceof InitialSessionStartupDeadlineError &&
|
|
7007
|
+
!runtimeSessionCreated &&
|
|
7008
|
+
options.messengerReturnAuthority === undefined &&
|
|
7009
|
+
this.initialLaunchDeadlineRetryKey !== launchIdempotencyKey) {
|
|
7010
|
+
const retryLaunch = durableLaunch;
|
|
7011
|
+
this.initialLaunchDeadlineRetryKey = launchIdempotencyKey;
|
|
7012
|
+
this.view?.showConnecting(true, retryLaunch.mode);
|
|
7013
|
+
this.state("reconnecting");
|
|
7014
|
+
queueMicrotask(() => {
|
|
7015
|
+
if (!launchIsCurrent() ||
|
|
7016
|
+
this.launchInFlight ||
|
|
7017
|
+
!this.lastLaunch ||
|
|
7018
|
+
!this.pendingLaunchMatches(this.lastLaunch, retryLaunch)) {
|
|
7019
|
+
return;
|
|
7020
|
+
}
|
|
7021
|
+
void this.launch(retryLaunch.mode, retryLaunch.scopes, retryLaunch.idempotencyKey, {
|
|
7022
|
+
...(options.startMuted === undefined
|
|
7023
|
+
? {}
|
|
7024
|
+
: { startMuted: options.startMuted }),
|
|
7025
|
+
...(options.associateCompanion === undefined
|
|
7026
|
+
? {}
|
|
7027
|
+
: { associateCompanion: options.associateCompanion }),
|
|
7028
|
+
...(options.admittedQuestion
|
|
7029
|
+
? { admittedQuestion: options.admittedQuestion }
|
|
7030
|
+
: {}),
|
|
7031
|
+
pendingLaunch: retryLaunch,
|
|
7032
|
+
});
|
|
7033
|
+
});
|
|
7034
|
+
return;
|
|
7035
|
+
}
|
|
7036
|
+
if (effectiveError instanceof InitialSessionStartupDeadlineError &&
|
|
7037
|
+
runtimeSessionCreated) {
|
|
7038
|
+
this.view?.showConnecting(true, activeMode);
|
|
7039
|
+
this.state("reconnecting");
|
|
7040
|
+
this.scheduleReconnect(true);
|
|
7041
|
+
return;
|
|
7042
|
+
}
|
|
7043
|
+
if (!runtimeLaunchStarted &&
|
|
7044
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey, durableLaunch)) {
|
|
7045
|
+
return;
|
|
7046
|
+
}
|
|
7047
|
+
const limited = await this.applyVisitorLimitFailure(effectiveError, launchIsCurrent, launchConsentProof);
|
|
6727
7048
|
if (!launchIsCurrent())
|
|
6728
7049
|
return;
|
|
6729
7050
|
if (!limited) {
|
|
6730
|
-
|
|
7051
|
+
if (effectiveError instanceof InitialVoiceMicrophoneUnavailableError) {
|
|
7052
|
+
this.presentSessionError(this.view?.message("microphoneUnavailable"), false, false);
|
|
7053
|
+
}
|
|
7054
|
+
else {
|
|
7055
|
+
this.presentSessionError(this.publicError(effectiveError), this.retryable(effectiveError), runtimeSessionCreated);
|
|
7056
|
+
}
|
|
6731
7057
|
}
|
|
6732
7058
|
if (!launchIsCurrent())
|
|
6733
7059
|
return;
|
|
@@ -6738,33 +7064,81 @@ class AiLiveAssist {
|
|
|
6738
7064
|
this.state("error");
|
|
6739
7065
|
}
|
|
6740
7066
|
finally {
|
|
7067
|
+
if (startupDeadline !== null)
|
|
7068
|
+
clearTimeout(startupDeadline);
|
|
6741
7069
|
releaseMessengerReturnIfPreRuntime();
|
|
6742
7070
|
this.launchInFlight = false;
|
|
6743
7071
|
this.drainPendingFocusedHandoff();
|
|
6744
7072
|
}
|
|
6745
7073
|
}
|
|
6746
|
-
|
|
6747
|
-
if (!
|
|
6748
|
-
!(
|
|
6749
|
-
|
|
7074
|
+
capturePendingLaunchConsentProof(bootstrap) {
|
|
7075
|
+
if (!bootstrap?.consent ||
|
|
7076
|
+
!Number.isSafeInteger(bootstrap.configRevision) ||
|
|
7077
|
+
(bootstrap.configRevision ?? 0) <= 0) {
|
|
7078
|
+
return null;
|
|
7079
|
+
}
|
|
7080
|
+
return {
|
|
7081
|
+
configRevision: bootstrap.configRevision,
|
|
7082
|
+
consentSignature: canonicalJson(bootstrap.consent),
|
|
7083
|
+
};
|
|
7084
|
+
}
|
|
7085
|
+
pendingLaunchConsentProofMatches(proof, bootstrap) {
|
|
7086
|
+
const current = this.capturePendingLaunchConsentProof(bootstrap);
|
|
7087
|
+
return Boolean(proof &&
|
|
7088
|
+
current &&
|
|
7089
|
+
proof.configRevision === current.configRevision &&
|
|
7090
|
+
proof.consentSignature === current.consentSignature);
|
|
7091
|
+
}
|
|
7092
|
+
finishVisitorActiveConsentRefresh(pendingLaunch) {
|
|
7093
|
+
if (pendingLaunch &&
|
|
7094
|
+
this.lastLaunch &&
|
|
7095
|
+
!this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
7096
|
+
return;
|
|
7097
|
+
}
|
|
7098
|
+
this.visitorActiveTakeoverOnly = false;
|
|
7099
|
+
this.visitorActiveEligibilityRecheckKey = null;
|
|
7100
|
+
this.clearOwnedStagedPendingLaunch();
|
|
7101
|
+
this.lastLaunch = null;
|
|
7102
|
+
this.clearPendingIntent();
|
|
7103
|
+
this.view?.showActiveElsewhere(false);
|
|
7104
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
7105
|
+
this.state("error");
|
|
7106
|
+
}
|
|
7107
|
+
async applyVisitorLimitFailure(error, isCurrent, launchConsentProof = this.capturePendingLaunchConsentProof(this.bootstrap)) {
|
|
7108
|
+
const visitorActiveConflict = error instanceof client_js_1.RuntimeClientError &&
|
|
7109
|
+
error.code === "CONCURRENCY_LIMIT" &&
|
|
7110
|
+
error.status === 409;
|
|
7111
|
+
const visitorRateLimit = error instanceof client_js_1.RuntimeClientError &&
|
|
7112
|
+
error.code === "RATE_LIMITED" &&
|
|
7113
|
+
error.status === 429;
|
|
7114
|
+
if (!isCurrent() || (!visitorActiveConflict && !visitorRateLimit)) {
|
|
6750
7115
|
return false;
|
|
6751
7116
|
}
|
|
6752
7117
|
const controller = new AbortController();
|
|
6753
7118
|
this.visitorLimitAbort?.abort();
|
|
6754
7119
|
this.visitorLimitAbort = controller;
|
|
7120
|
+
const aborted = new Promise((resolve) => {
|
|
7121
|
+
controller.signal.addEventListener("abort", () => resolve(null), {
|
|
7122
|
+
once: true,
|
|
7123
|
+
});
|
|
7124
|
+
});
|
|
6755
7125
|
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
6756
7126
|
try {
|
|
6757
|
-
const bootstrap = await
|
|
6758
|
-
|
|
7127
|
+
const bootstrap = await Promise.race([
|
|
7128
|
+
this.requestBootstrap(controller.signal),
|
|
7129
|
+
aborted,
|
|
7130
|
+
]);
|
|
7131
|
+
if (!bootstrap || !isCurrent() || controller.signal.aborted)
|
|
6759
7132
|
return false;
|
|
6760
7133
|
const effectiveBootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
6761
7134
|
if (!isCurrent() || controller.signal.aborted)
|
|
6762
7135
|
return false;
|
|
6763
|
-
this.bootstrap = effectiveBootstrap;
|
|
6764
7136
|
const status = bootstrap.visitorEligibility?.status;
|
|
6765
7137
|
if (status === "visitor_limited") {
|
|
7138
|
+
this.bootstrap = effectiveBootstrap;
|
|
6766
7139
|
if (!isCurrent() || controller.signal.aborted)
|
|
6767
7140
|
return false;
|
|
7141
|
+
this.clearPendingIntent();
|
|
6768
7142
|
if (bootstrap.appearance?.hideLauncherWhenVisitorLimited !== false) {
|
|
6769
7143
|
if (!isCurrent() || controller.signal.aborted)
|
|
6770
7144
|
return false;
|
|
@@ -6778,24 +7152,41 @@ class AiLiveAssist {
|
|
|
6778
7152
|
return true;
|
|
6779
7153
|
}
|
|
6780
7154
|
if (status === "cooldown_limited") {
|
|
7155
|
+
this.bootstrap = effectiveBootstrap;
|
|
6781
7156
|
if (!isCurrent() || controller.signal.aborted)
|
|
6782
7157
|
return false;
|
|
7158
|
+
this.clearPendingIntent();
|
|
6783
7159
|
this.view?.showLaunchUnavailable(this.view.message("visitorCooldown"));
|
|
6784
7160
|
return true;
|
|
6785
7161
|
}
|
|
6786
7162
|
if (status === "visitor_active") {
|
|
7163
|
+
if (!visitorActiveConflict)
|
|
7164
|
+
return false;
|
|
6787
7165
|
if (!isCurrent() || controller.signal.aborted)
|
|
6788
7166
|
return false;
|
|
7167
|
+
const pendingLaunch = this.lastLaunch;
|
|
7168
|
+
if (!pendingLaunch ||
|
|
7169
|
+
!this.pendingLaunchConsentProofMatches(launchConsentProof, effectiveBootstrap)) {
|
|
7170
|
+
this.finishVisitorActiveConsentRefresh(pendingLaunch);
|
|
7171
|
+
return true;
|
|
7172
|
+
}
|
|
7173
|
+
this.bootstrap = effectiveBootstrap;
|
|
6789
7174
|
const displayMode = this.lastLaunch?.mode ?? this.mode;
|
|
6790
7175
|
this.visitorActiveTakeoverOnly = true;
|
|
6791
7176
|
this.clearOwnedStagedPendingLaunch();
|
|
6792
7177
|
this.view?.showActiveElsewhere(false);
|
|
6793
7178
|
this.view?.showConnecting(true, displayMode);
|
|
6794
7179
|
this.state("reconnecting");
|
|
6795
|
-
const pendingLaunch = this.lastLaunch;
|
|
6796
7180
|
const handoffRequested = this.requestFocusedHandoff();
|
|
6797
7181
|
if (pendingLaunch && handoffRequested === false) {
|
|
6798
|
-
|
|
7182
|
+
const recheckGeneration = this.launchGeneration;
|
|
7183
|
+
setTimeout(() => {
|
|
7184
|
+
if (recheckGeneration !== this.launchGeneration ||
|
|
7185
|
+
this.launchInFlight) {
|
|
7186
|
+
return;
|
|
7187
|
+
}
|
|
7188
|
+
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, recheckGeneration, false, launchConsentProof);
|
|
7189
|
+
}, 0);
|
|
6799
7190
|
}
|
|
6800
7191
|
return true;
|
|
6801
7192
|
}
|
|
@@ -6811,7 +7202,7 @@ class AiLiveAssist {
|
|
|
6811
7202
|
}
|
|
6812
7203
|
return false;
|
|
6813
7204
|
}
|
|
6814
|
-
beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, recoveredOwnership = false) {
|
|
7205
|
+
beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, recoveredOwnership = false, launchConsentProof = this.capturePendingLaunchConsentProof(this.bootstrap)) {
|
|
6815
7206
|
if (!this.visitorActiveTakeoverOnly ||
|
|
6816
7207
|
this.terminalRequestPending ||
|
|
6817
7208
|
this.ended ||
|
|
@@ -6877,7 +7268,7 @@ class AiLiveAssist {
|
|
|
6877
7268
|
operation = (async () => {
|
|
6878
7269
|
try {
|
|
6879
7270
|
const bootstrap = await Promise.race([
|
|
6880
|
-
this.
|
|
7271
|
+
this.requestBootstrap(controller.signal),
|
|
6881
7272
|
aborted,
|
|
6882
7273
|
]);
|
|
6883
7274
|
if (!bootstrap) {
|
|
@@ -6904,21 +7295,36 @@ class AiLiveAssist {
|
|
|
6904
7295
|
await this.resume(recoveredRecord);
|
|
6905
7296
|
return;
|
|
6906
7297
|
}
|
|
6907
|
-
|
|
7298
|
+
const effectiveBootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
6908
7299
|
const status = bootstrap.visitorEligibility?.status;
|
|
6909
7300
|
if (status === "eligible") {
|
|
7301
|
+
if (!this.pendingLaunchConsentProofMatches(launchConsentProof, effectiveBootstrap)) {
|
|
7302
|
+
if (recoveredOwnership && this.lock.ownsActivity()) {
|
|
7303
|
+
this.lock.release();
|
|
7304
|
+
}
|
|
7305
|
+
this.finishVisitorActiveConsentRefresh(pendingLaunch);
|
|
7306
|
+
return;
|
|
7307
|
+
}
|
|
7308
|
+
this.bootstrap = effectiveBootstrap;
|
|
6910
7309
|
this.visitorActiveTakeoverOnly = false;
|
|
6911
7310
|
this.lastLaunch = null;
|
|
6912
7311
|
this.view?.showActiveElsewhere(false);
|
|
6913
|
-
await this.launch(pendingLaunch.mode, pendingLaunch.scopes, pendingLaunch.idempotencyKey, {
|
|
7312
|
+
await this.launch(pendingLaunch.mode, pendingLaunch.scopes, pendingLaunch.idempotencyKey, {
|
|
7313
|
+
pendingLaunch,
|
|
7314
|
+
...(this.pendingQuestion
|
|
7315
|
+
? { admittedQuestion: this.pendingQuestion }
|
|
7316
|
+
: {}),
|
|
7317
|
+
});
|
|
6914
7318
|
return;
|
|
6915
7319
|
}
|
|
6916
7320
|
if (status === "visitor_limited") {
|
|
7321
|
+
this.bootstrap = effectiveBootstrap;
|
|
6917
7322
|
this.visitorActiveTakeoverOnly = false;
|
|
6918
7323
|
finish("visitorLimitReached");
|
|
6919
7324
|
return;
|
|
6920
7325
|
}
|
|
6921
7326
|
if (status === "cooldown_limited") {
|
|
7327
|
+
this.bootstrap = effectiveBootstrap;
|
|
6922
7328
|
this.visitorActiveTakeoverOnly = false;
|
|
6923
7329
|
finish("visitorCooldown");
|
|
6924
7330
|
return;
|
|
@@ -6946,9 +7352,18 @@ class AiLiveAssist {
|
|
|
6946
7352
|
!this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
6947
7353
|
return;
|
|
6948
7354
|
}
|
|
6949
|
-
this.lastLaunch = null;
|
|
6950
|
-
this.clearPendingIntent();
|
|
6951
7355
|
this.view?.showActiveElsewhere(false);
|
|
7356
|
+
if (messageKey === "visitorAlreadyActive") {
|
|
7357
|
+
// The explicit entry action has already staged the compact Voice/Text
|
|
7358
|
+
// surface. Keep that surface as a retryable, closable recovery card.
|
|
7359
|
+
// The generic unavailable presenter resets compact state while leaving
|
|
7360
|
+
// the open panel mounted, which produces an empty full-height shell.
|
|
7361
|
+
this.presentSessionError(this.view?.message(messageKey), true, false);
|
|
7362
|
+
this.state("error");
|
|
7363
|
+
return;
|
|
7364
|
+
}
|
|
7365
|
+
this.clearPendingIntent();
|
|
7366
|
+
this.lastLaunch = null;
|
|
6952
7367
|
this.view?.showLaunchUnavailable(this.view.message(messageKey));
|
|
6953
7368
|
this.state("ready");
|
|
6954
7369
|
}
|
|
@@ -7036,16 +7451,18 @@ class AiLiveAssist {
|
|
|
7036
7451
|
this.minimumPageAssistanceAuthorityEpoch = Math.max(this.minimumPageAssistanceAuthorityEpoch, this.activePageAssistanceAuthorityEpoch);
|
|
7037
7452
|
}
|
|
7038
7453
|
this.visualConsentGranted = record.visualConsentGranted;
|
|
7454
|
+
// A legacy override only keeps capture closed during recovery. It cannot
|
|
7455
|
+
// authorize manual controls; connectTransport restores the published mode.
|
|
7039
7456
|
this.manualTurn =
|
|
7040
7457
|
record.mode === "voice" &&
|
|
7041
7458
|
(record.manualTurn || this.bootstrap?.voice?.turnMode === "manual");
|
|
7042
7459
|
this.pushActive = false;
|
|
7043
7460
|
this.state("reconnecting");
|
|
7044
7461
|
try {
|
|
7045
|
-
const replay = await this.
|
|
7462
|
+
const replay = await this.sessionConnectionScope();
|
|
7046
7463
|
if (!resumeAttemptIsCurrent())
|
|
7047
7464
|
return;
|
|
7048
|
-
this.
|
|
7465
|
+
this.assertSessionConnectionScope(replay);
|
|
7049
7466
|
const controller = new AbortController();
|
|
7050
7467
|
const connectionGeneration = this.beginConnectionAttempt(controller);
|
|
7051
7468
|
if (modeUpgradeAttempt)
|
|
@@ -7156,6 +7573,9 @@ class AiLiveAssist {
|
|
|
7156
7573
|
else {
|
|
7157
7574
|
this.writeResume(...resumeArguments);
|
|
7158
7575
|
}
|
|
7576
|
+
if (!this.rebaseDeferredDocumentNavigationRecovery(requestedResumePath)) {
|
|
7577
|
+
throw new client_js_1.RuntimeClientError("RESUME_STORAGE_UNAVAILABLE", "The page-action recovery could not be stored safely.", true, null, 503);
|
|
7578
|
+
}
|
|
7159
7579
|
const media = preparedModeUpgradeMedia ??
|
|
7160
7580
|
this.createMedia(() => {
|
|
7161
7581
|
try {
|
|
@@ -7317,7 +7737,7 @@ class AiLiveAssist {
|
|
|
7317
7737
|
this.state("reconnecting");
|
|
7318
7738
|
}
|
|
7319
7739
|
else {
|
|
7320
|
-
this.
|
|
7740
|
+
this.presentSessionError(this.publicError(error), retryableFailure);
|
|
7321
7741
|
this.state("error");
|
|
7322
7742
|
}
|
|
7323
7743
|
}
|
|
@@ -7435,7 +7855,7 @@ class AiLiveAssist {
|
|
|
7435
7855
|
this.state("reconnecting");
|
|
7436
7856
|
}
|
|
7437
7857
|
else {
|
|
7438
|
-
this.
|
|
7858
|
+
this.presentSessionError(this.publicError(error), false);
|
|
7439
7859
|
this.state("error");
|
|
7440
7860
|
}
|
|
7441
7861
|
}
|
|
@@ -7565,6 +7985,7 @@ class AiLiveAssist {
|
|
|
7565
7985
|
const authorityOutcome = await channel.proveFencedAuthority();
|
|
7566
7986
|
this.requireControlReadiness(authorityOutcome, "The secure control authority could not be verified.");
|
|
7567
7987
|
assertCurrent();
|
|
7988
|
+
this.flushPlaybackState();
|
|
7568
7989
|
this.retryMessengerBindingTerminalAck();
|
|
7569
7990
|
this.retryMessengerTerminalAck();
|
|
7570
7991
|
this.preparePreFenceActionExecutionReadiness(channel, fencingToken, assertCurrent);
|
|
@@ -7594,19 +8015,24 @@ class AiLiveAssist {
|
|
|
7594
8015
|
}
|
|
7595
8016
|
assertCurrent();
|
|
7596
8017
|
channel.startHeartbeat(this.heartbeatSeconds);
|
|
8018
|
+
if (this.guideAdmission && !this.guideAdmission.recordingAllowed) {
|
|
8019
|
+
activeScopes = activeScopes.filter(scope => scope !== "session_recording");
|
|
8020
|
+
this.scopes = [...activeScopes];
|
|
8021
|
+
}
|
|
7597
8022
|
channel.send("consent.update", {
|
|
7598
8023
|
scopes: activeScopes,
|
|
7599
8024
|
locale: this.locale,
|
|
7600
8025
|
});
|
|
7601
8026
|
channel.send("media.state", {
|
|
7602
8027
|
microphone: mode === "voice" ? "active" : "unavailable",
|
|
7603
|
-
playback: mode
|
|
8028
|
+
playback: this.advertisedMediaPlaybackState(mode),
|
|
7604
8029
|
captions: true,
|
|
7605
8030
|
});
|
|
7606
8031
|
if (mode === "voice" &&
|
|
7607
8032
|
this.manualTurn &&
|
|
7608
8033
|
this.bootstrap?.voice?.turnMode !== "manual") {
|
|
7609
|
-
|
|
8034
|
+
await this.restoreConfiguredVoiceTurns(channel, controller.signal, assertCurrent);
|
|
8035
|
+
assertCurrent();
|
|
7610
8036
|
}
|
|
7611
8037
|
if (this.pendingNavigationActionResult) {
|
|
7612
8038
|
const terminalDeliveryConfirmed = await this.flushPendingNavigationActionResult();
|
|
@@ -7648,20 +8074,21 @@ class AiLiveAssist {
|
|
|
7648
8074
|
? null
|
|
7649
8075
|
: (result.assistant?.welcomeMessage ??
|
|
7650
8076
|
this.bootstrap?.appearance?.welcomeMessage);
|
|
7651
|
-
|
|
7652
|
-
if (
|
|
8077
|
+
const hasPendingTextQuestion = mode === "text" && this.pendingQuestion !== null;
|
|
8078
|
+
if (hasPendingTextQuestion &&
|
|
7653
8079
|
this.pendingQuestion &&
|
|
7654
8080
|
!this.pendingQuestion.shown) {
|
|
7655
8081
|
this.view?.addCaption("user", this.pendingQuestion.text, true);
|
|
7656
8082
|
this.pendingQuestion.shown = true;
|
|
8083
|
+
}
|
|
8084
|
+
if (hasPendingTextQuestion && this.pendingQuestion) {
|
|
7657
8085
|
this.rememberTranscript(this.pendingQuestion.submissionId, "user", this.pendingQuestion.text);
|
|
7658
8086
|
(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).add(this.pendingQuestion.submissionId);
|
|
7659
|
-
renderedPendingTextQuestion = true;
|
|
7660
8087
|
}
|
|
7661
8088
|
const visibleWelcome = resume ||
|
|
7662
|
-
|
|
8089
|
+
hasPendingTextQuestion ||
|
|
7663
8090
|
this.transcriptRestoredFromCache ||
|
|
7664
|
-
|
|
8091
|
+
mode === "voice"
|
|
7665
8092
|
? null
|
|
7666
8093
|
: welcomeMessage;
|
|
7667
8094
|
this.view?.showActive(visibleWelcome);
|
|
@@ -7688,8 +8115,60 @@ class AiLiveAssist {
|
|
|
7688
8115
|
void this.requestHumanHandoff("The visitor chose human support because voice assistance was unavailable.", undefined, undefined, isCurrent);
|
|
7689
8116
|
}
|
|
7690
8117
|
else {
|
|
7691
|
-
this.
|
|
8118
|
+
this.presentSessionError(this.view?.message("humanUnavailable"), false);
|
|
8119
|
+
}
|
|
8120
|
+
}
|
|
8121
|
+
}
|
|
8122
|
+
async restoreConfiguredVoiceTurns(channel, signal, assertCurrent) {
|
|
8123
|
+
assertCurrent();
|
|
8124
|
+
if (signal.aborted)
|
|
8125
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
8126
|
+
let unsubscribe = () => { };
|
|
8127
|
+
let timeout;
|
|
8128
|
+
let abort = () => { };
|
|
8129
|
+
let confirmApplied = () => { };
|
|
8130
|
+
const applied = new Promise(resolve => { confirmApplied = resolve; });
|
|
8131
|
+
const interrupted = new Promise((_, reject) => {
|
|
8132
|
+
abort = () => reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
8133
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
8134
|
+
timeout = setTimeout(() => reject(new Error("Automatic voice mode was not confirmed.")), 5000);
|
|
8135
|
+
unsubscribe = channel.subscribe((message, isCurrent) => {
|
|
8136
|
+
if (message.type !== "voice.turn_mode" || message.payload.mode !== "configured" || !isCurrent())
|
|
8137
|
+
return;
|
|
8138
|
+
try {
|
|
8139
|
+
assertCurrent();
|
|
8140
|
+
confirmApplied();
|
|
8141
|
+
}
|
|
8142
|
+
catch (error) {
|
|
8143
|
+
reject(error);
|
|
8144
|
+
}
|
|
8145
|
+
});
|
|
8146
|
+
});
|
|
8147
|
+
try {
|
|
8148
|
+
const id = channel.send("voice.turn_mode", { mode: "configured" });
|
|
8149
|
+
await Promise.race([
|
|
8150
|
+
interrupted,
|
|
8151
|
+
Promise.all([
|
|
8152
|
+
applied,
|
|
8153
|
+
channel.waitForOutcome(id).then(outcome => this.requireControlReadiness(outcome, "Automatic voice mode could not be restored.")),
|
|
8154
|
+
]),
|
|
8155
|
+
]);
|
|
8156
|
+
assertCurrent();
|
|
8157
|
+
if (signal.aborted || this.channel !== channel) {
|
|
8158
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
7692
8159
|
}
|
|
8160
|
+
// Apply only after both confirmations. An early or replayed server event
|
|
8161
|
+
// must not open capture while the legacy manual session is quarantined.
|
|
8162
|
+
this.manualTurn = false;
|
|
8163
|
+
this.pushActive = false;
|
|
8164
|
+
this.media?.setManualTurn(false);
|
|
8165
|
+
this.view?.setManualTurn(false);
|
|
8166
|
+
this.updateResumeManualTurn();
|
|
8167
|
+
}
|
|
8168
|
+
finally {
|
|
8169
|
+
unsubscribe();
|
|
8170
|
+
clearTimeout(timeout);
|
|
8171
|
+
signal.removeEventListener("abort", abort);
|
|
7693
8172
|
}
|
|
7694
8173
|
}
|
|
7695
8174
|
requireControlReadiness(outcome, unavailableMessage) {
|
|
@@ -7726,7 +8205,27 @@ class AiLiveAssist {
|
|
|
7726
8205
|
const pathname = this.contextNavigationPath(payload);
|
|
7727
8206
|
const sessionId = this.result?.sessionId ?? null;
|
|
7728
8207
|
const effectGeneration = this.sessionEffectGeneration;
|
|
7729
|
-
const rawOutcome =
|
|
8208
|
+
const rawOutcome = (async () => {
|
|
8209
|
+
const initial = await channel.waitForOutcome(messageId, CONTEXT_NAVIGATION_ACK_TIMEOUT_MS, clientSequence);
|
|
8210
|
+
if (initial.status !== "timeout" ||
|
|
8211
|
+
!pathname ||
|
|
8212
|
+
!sessionId ||
|
|
8213
|
+
effectGeneration !== this.sessionEffectGeneration ||
|
|
8214
|
+
this.channel !== channel ||
|
|
8215
|
+
this.result?.sessionId !== sessionId ||
|
|
8216
|
+
!channel.isOpen ||
|
|
8217
|
+
this.terminalRequestPending ||
|
|
8218
|
+
this.ended ||
|
|
8219
|
+
this.destroyed) {
|
|
8220
|
+
return initial;
|
|
8221
|
+
}
|
|
8222
|
+
// A same-document router can settle before the durable navigation frame
|
|
8223
|
+
// is acknowledged. Replay the exact outstanding frame (including its
|
|
8224
|
+
// sequence and timestamp) once, then observe that original identity for
|
|
8225
|
+
// one bounded grace period without disrupting healthy voice media.
|
|
8226
|
+
channel.retransmitOutstanding(messageId, clientSequence);
|
|
8227
|
+
return channel.waitForOutcome(messageId, CONTEXT_NAVIGATION_LATE_ACK_TIMEOUT_MS, clientSequence);
|
|
8228
|
+
})();
|
|
7730
8229
|
if (!pathname || !sessionId)
|
|
7731
8230
|
return rawOutcome;
|
|
7732
8231
|
const pending = {};
|
|
@@ -7787,18 +8286,17 @@ class AiLiveAssist {
|
|
|
7787
8286
|
return true;
|
|
7788
8287
|
}
|
|
7789
8288
|
async waitForPendingContextNavigationAcknowledgements() {
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
|
|
7794
|
-
|
|
7795
|
-
|
|
7796
|
-
|
|
7797
|
-
|
|
7798
|
-
|
|
7799
|
-
|
|
7800
|
-
|
|
7801
|
-
return false;
|
|
8289
|
+
// Each tracked outcome already has its own bounded 5s + 10s delivery
|
|
8290
|
+
// window. Snapshot this cohort so a navigation that starts later receives
|
|
8291
|
+
// its own complete window instead of inheriting an almost-expired outer
|
|
8292
|
+
// timer. Callers recheck the live set before activating voice.
|
|
8293
|
+
const pending = [
|
|
8294
|
+
...(this.pendingContextNavigationAcknowledgements ?? new Set()),
|
|
8295
|
+
];
|
|
8296
|
+
if (pending.length === 0)
|
|
8297
|
+
return true;
|
|
8298
|
+
const outcomes = await Promise.all(pending.map((entry) => entry.outcome));
|
|
8299
|
+
return outcomes.every((outcome) => outcome.status === "ack");
|
|
7802
8300
|
}
|
|
7803
8301
|
startContext(scopes) {
|
|
7804
8302
|
this.context?.stop();
|
|
@@ -7849,10 +8347,16 @@ class AiLiveAssist {
|
|
|
7849
8347
|
}
|
|
7850
8348
|
if (destination.origin !== window.location.origin ||
|
|
7851
8349
|
destination.search !== "" ||
|
|
7852
|
-
destination.hash !== ""
|
|
8350
|
+
destination.hash !== "" ||
|
|
8351
|
+
typeof pending.grant?.destinationPath !== "string" ||
|
|
8352
|
+
destination.pathname !== pending.grant.destinationPath) {
|
|
7853
8353
|
pending.causalNavigationObserved = false;
|
|
7854
8354
|
return;
|
|
7855
8355
|
}
|
|
8356
|
+
// The exact SPA destination is now observed, so the persisted state
|
|
8357
|
+
// becomes the causal navigation/result outbox rather than a
|
|
8358
|
+
// cross-document recovery marker.
|
|
8359
|
+
pending.deferredNavigationPath = null;
|
|
7856
8360
|
pending.navigationPayload = {
|
|
7857
8361
|
pageId,
|
|
7858
8362
|
revision,
|
|
@@ -7883,10 +8387,61 @@ class AiLiveAssist {
|
|
|
7883
8387
|
navigationType: "spa",
|
|
7884
8388
|
};
|
|
7885
8389
|
if (causalLegacy && legacy && cause) {
|
|
8390
|
+
if (legacy.result && !legacy.resultAcknowledged) {
|
|
8391
|
+
legacy.result = {
|
|
8392
|
+
...legacy.result,
|
|
8393
|
+
observed: {
|
|
8394
|
+
...legacy.result.observed,
|
|
8395
|
+
url,
|
|
8396
|
+
revision,
|
|
8397
|
+
},
|
|
8398
|
+
};
|
|
8399
|
+
}
|
|
7886
8400
|
return this.deliverLegacyCausalNavigation(legacy, payload, cause);
|
|
7887
8401
|
}
|
|
8402
|
+
if (causalPending && pending && !cause) {
|
|
8403
|
+
const retainedExactNavigation = pending.grant === null &&
|
|
8404
|
+
pending.causalNavigationObserved &&
|
|
8405
|
+
pending.navigationPayload?.url === url &&
|
|
8406
|
+
this.pendingNavigationPayloadMatchesGrant(pending);
|
|
8407
|
+
pending.result = this.unconfirmedActionExecutionResult(pending, revision, url);
|
|
8408
|
+
pending.deferredNavigationPath = null;
|
|
8409
|
+
if (!retainedExactNavigation) {
|
|
8410
|
+
pending.navigationPayload = null;
|
|
8411
|
+
pending.navigationAcknowledged = true;
|
|
8412
|
+
}
|
|
8413
|
+
pending.causalNavigationDeliveryAttempted = true;
|
|
8414
|
+
this.persistPendingActionExecution(pending);
|
|
8415
|
+
this.pendingAction = false;
|
|
8416
|
+
this.view?.showActionState("unconfirmed");
|
|
8417
|
+
this.resetActionGrantAuthority(true);
|
|
8418
|
+
const navigationAcknowledged = retainedExactNavigation
|
|
8419
|
+
? false
|
|
8420
|
+
: await this.deliverContextNavigation(payload);
|
|
8421
|
+
pending.causalNavigationDeliveryConfirmed =
|
|
8422
|
+
await this.flushPendingNavigationActionResult();
|
|
8423
|
+
if ((!navigationAcknowledged ||
|
|
8424
|
+
!pending.causalNavigationDeliveryConfirmed) &&
|
|
8425
|
+
!this.terminalRequestPending &&
|
|
8426
|
+
!this.ended &&
|
|
8427
|
+
!this.destroyed) {
|
|
8428
|
+
this.scheduleReconnect(true);
|
|
8429
|
+
}
|
|
8430
|
+
return false;
|
|
8431
|
+
}
|
|
7888
8432
|
this.resetActionGrantAuthority(causalPending);
|
|
7889
8433
|
if (causalPending && pending) {
|
|
8434
|
+
if (pending.result &&
|
|
8435
|
+
pending.resultDeliveryAttempted === false &&
|
|
8436
|
+
!pending.resultAcknowledged) {
|
|
8437
|
+
// A released link records its result before the router runs.
|
|
8438
|
+
// Bind that first delivery to the exact causal destination now
|
|
8439
|
+
// observed, then retain identical result bytes for every retry.
|
|
8440
|
+
pending.result = {
|
|
8441
|
+
...pending.result,
|
|
8442
|
+
observed: { ...pending.result.observed, url, revision },
|
|
8443
|
+
};
|
|
8444
|
+
}
|
|
7890
8445
|
this.sendPendingNavigationMessage(payload);
|
|
7891
8446
|
pending.causalNavigationDeliveryAttempted = true;
|
|
7892
8447
|
pending.causalNavigationDeliveryConfirmed =
|
|
@@ -8007,7 +8562,7 @@ class AiLiveAssist {
|
|
|
8007
8562
|
if (this.resolvePendingConfirmationReply(text))
|
|
8008
8563
|
return true;
|
|
8009
8564
|
if (this.destroyed || this.terminalRequestPending || this.ended) {
|
|
8010
|
-
this.
|
|
8565
|
+
this.presentSessionError(this.view?.message("ended"), false, false);
|
|
8011
8566
|
return false;
|
|
8012
8567
|
}
|
|
8013
8568
|
if (this.pendingQuestionCount() >= PUBLIC_QUESTION_QUEUE_CAPACITY) {
|
|
@@ -8135,15 +8690,19 @@ class AiLiveAssist {
|
|
|
8135
8690
|
}
|
|
8136
8691
|
}
|
|
8137
8692
|
}
|
|
8138
|
-
resolvePendingConfirmationReply(text) {
|
|
8693
|
+
resolvePendingConfirmationReply(text, nativeVoiceTurn) {
|
|
8139
8694
|
const pending = this.pendingConfirmation;
|
|
8140
8695
|
if (!pending)
|
|
8141
8696
|
return false;
|
|
8142
8697
|
const intent = (0, exports.confirmationReplyIntent)(text);
|
|
8143
8698
|
if (!intent)
|
|
8144
8699
|
return false;
|
|
8145
|
-
|
|
8700
|
+
// Durable native voice turns already interrupt prior provider output. A
|
|
8701
|
+
// second session.interrupt here would discard the newly accepted input.
|
|
8702
|
+
if (this.mode === "voice" &&
|
|
8703
|
+
!this.hasAdmittedVoicePlaybackTurn(nativeVoiceTurn)) {
|
|
8146
8704
|
this.interrupt();
|
|
8705
|
+
}
|
|
8147
8706
|
const approved = intent === "approve";
|
|
8148
8707
|
if (this.view?.resolvePendingConfirmation(approved, pending)) {
|
|
8149
8708
|
// A visible prompt always invokes the identity-bound callback. If a
|
|
@@ -8155,15 +8714,17 @@ class AiLiveAssist {
|
|
|
8155
8714
|
}
|
|
8156
8715
|
return this.submitConfirmationDecision(pending, approved);
|
|
8157
8716
|
}
|
|
8158
|
-
cancelConfirmationForNewRequest(expected) {
|
|
8717
|
+
cancelConfirmationForNewRequest(expected, nativeVoiceTurn) {
|
|
8159
8718
|
const pending = this.pendingConfirmation;
|
|
8160
8719
|
if (!pending ||
|
|
8161
8720
|
pending.actionId !== expected.actionId ||
|
|
8162
8721
|
pending.proposalChecksum !== expected.proposalChecksum) {
|
|
8163
8722
|
return null;
|
|
8164
8723
|
}
|
|
8165
|
-
if (this.mode === "voice"
|
|
8724
|
+
if (this.mode === "voice" &&
|
|
8725
|
+
!this.hasAdmittedVoicePlaybackTurn(nativeVoiceTurn)) {
|
|
8166
8726
|
this.interrupt();
|
|
8727
|
+
}
|
|
8167
8728
|
if (this.view?.resolvePendingConfirmation(false, expected)) {
|
|
8168
8729
|
if (this.pendingConfirmation === pending) {
|
|
8169
8730
|
this.submitConfirmationDecision(pending, false);
|
|
@@ -8198,7 +8759,7 @@ class AiLiveAssist {
|
|
|
8198
8759
|
if (this.pendingConfirmationDecisions.length >=
|
|
8199
8760
|
CONFIRMATION_DECISION_QUEUE_CAPACITY) {
|
|
8200
8761
|
this.revokeActiveAction();
|
|
8201
|
-
this.
|
|
8762
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), true, true);
|
|
8202
8763
|
this.scheduleReconnect(true);
|
|
8203
8764
|
return false;
|
|
8204
8765
|
}
|
|
@@ -8301,7 +8862,7 @@ class AiLiveAssist {
|
|
|
8301
8862
|
return false;
|
|
8302
8863
|
const decision = this.pendingConfirmationDecisions[index];
|
|
8303
8864
|
if (payload.retryable === true) {
|
|
8304
|
-
this.
|
|
8865
|
+
this.presentSessionError(this.string(payload.message), true);
|
|
8305
8866
|
return true;
|
|
8306
8867
|
}
|
|
8307
8868
|
this.pendingConfirmationDecisions.splice(index, 1);
|
|
@@ -8339,7 +8900,7 @@ class AiLiveAssist {
|
|
|
8339
8900
|
if (!question)
|
|
8340
8901
|
return false;
|
|
8341
8902
|
if (payload.retryable === true) {
|
|
8342
|
-
this.
|
|
8903
|
+
this.presentSessionError(this.string(payload.message), true);
|
|
8343
8904
|
return true;
|
|
8344
8905
|
}
|
|
8345
8906
|
this.removePendingQuestion(question);
|
|
@@ -8643,14 +9204,14 @@ class AiLiveAssist {
|
|
|
8643
9204
|
: null;
|
|
8644
9205
|
if (identity && this.samePageAssistanceIdentity(identity, request)) {
|
|
8645
9206
|
this.invalidatePageAssistanceAuthority(false);
|
|
8646
|
-
this.
|
|
9207
|
+
this.presentSessionError(outcome.message, false);
|
|
8647
9208
|
}
|
|
8648
9209
|
}
|
|
8649
9210
|
});
|
|
8650
9211
|
}
|
|
8651
9212
|
pageAssistanceRecoveries() {
|
|
8652
9213
|
if (!this.pageAssistanceRecoveryStore) {
|
|
8653
|
-
this.pageAssistanceRecoveryStore = new pageAssistancePreference_js_1.PageAssistanceRecoveryStore(this.siteKey);
|
|
9214
|
+
this.pageAssistanceRecoveryStore = new pageAssistancePreference_js_1.PageAssistanceRecoveryStore(this.guideAdmission ? this.guideAdmission.identity : this.siteKey, { storageNamespace: this.storageNamespace });
|
|
8654
9215
|
}
|
|
8655
9216
|
return this.pageAssistanceRecoveryStore;
|
|
8656
9217
|
}
|
|
@@ -9351,7 +9912,15 @@ class AiLiveAssist {
|
|
|
9351
9912
|
this.commitAuthoritativeConsent(scopes);
|
|
9352
9913
|
}
|
|
9353
9914
|
commitAuthoritativeConsent(scopes) {
|
|
9915
|
+
// A delayed receipt cannot restore recording after the visitor opted out.
|
|
9916
|
+
if (this.guideAdmission && !this.guideAdmission.recordingAllowed)
|
|
9917
|
+
scopes = scopes.filter(scope => scope !== "session_recording");
|
|
9354
9918
|
this.scopes = [...scopes];
|
|
9919
|
+
if (this.guideAdmission && this.result) {
|
|
9920
|
+
this.guideAdmission.syncRecording(this.result, scopes, this.tabId);
|
|
9921
|
+
if (this.view instanceof ui_js_1.WidgetView)
|
|
9922
|
+
this.view.setRecordingConsent(scopes.includes("session_recording"));
|
|
9923
|
+
}
|
|
9355
9924
|
this.visualConsentGranted = scopes.includes("visual_context");
|
|
9356
9925
|
const record = this.readResume();
|
|
9357
9926
|
if (record) {
|
|
@@ -9662,6 +10231,36 @@ class AiLiveAssist {
|
|
|
9662
10231
|
handleControlIngress(message, isCurrent = () => true) {
|
|
9663
10232
|
if (!isCurrent())
|
|
9664
10233
|
return;
|
|
10234
|
+
this.observeVoicePlaybackInterrupt(message);
|
|
10235
|
+
if (message.type === "assistant.interrupted" ||
|
|
10236
|
+
message.type === "provider.reconnecting" ||
|
|
10237
|
+
(message.type === "presence.state" &&
|
|
10238
|
+
message.payload.state === "reconnecting"))
|
|
10239
|
+
this.invalidateVoicePlaybackRearm();
|
|
10240
|
+
(this.voicePlaybackIngress ?? (this.voicePlaybackIngress = new WeakMap())).set(message, {
|
|
10241
|
+
generation: this.voicePlaybackInterruptionGeneration ?? 0,
|
|
10242
|
+
channel: this.channel,
|
|
10243
|
+
fencingToken: this.channel?.leaseToken ?? 0,
|
|
10244
|
+
});
|
|
10245
|
+
(this.ctaAuthorityGenerationAtIngress ?? (this.ctaAuthorityGenerationAtIngress = new WeakMap())).set(message, this.currentCtaAuthorityGeneration());
|
|
10246
|
+
if (message.type === "caption.segment" ||
|
|
10247
|
+
message.type === "assistant.caption") {
|
|
10248
|
+
(this.ctaContentAtIngress ?? (this.ctaContentAtIngress = new WeakMap())).set(message, {
|
|
10249
|
+
generation: this.ctaContentGeneration ?? 0,
|
|
10250
|
+
channel: this.channel,
|
|
10251
|
+
});
|
|
10252
|
+
}
|
|
10253
|
+
if (message.type === "provider.reconnecting")
|
|
10254
|
+
this.invalidateCtaAuthority();
|
|
10255
|
+
if (message.type === "session.state" &&
|
|
10256
|
+
["ending", "ended", "failed", "revoked"].includes(String(message.payload.state))) {
|
|
10257
|
+
this.ctaStoppedSessionId = message.sessionId;
|
|
10258
|
+
this.invalidateCtaAuthority();
|
|
10259
|
+
}
|
|
10260
|
+
if (message.type === "handoff.state" &&
|
|
10261
|
+
["prepared", "handoff_pending", "human_controlled"].includes(String(message.payload.state))) {
|
|
10262
|
+
this.invalidateCtaAuthority();
|
|
10263
|
+
}
|
|
9665
10264
|
const fencedAuthorityAtIngress = this.channel?.hasFencedAuthority === true;
|
|
9666
10265
|
(this.fencedAuthorityAtIngressByEnvelope ?? (this.fencedAuthorityAtIngressByEnvelope = new WeakMap())).set(message, fencedAuthorityAtIngress);
|
|
9667
10266
|
if (message.type === "handoff.state" &&
|
|
@@ -9737,8 +10336,16 @@ class AiLiveAssist {
|
|
|
9737
10336
|
!message.payload.scopes.includes("browser_control")) {
|
|
9738
10337
|
// Authority loss must preempt any older handler that is still awaiting
|
|
9739
10338
|
// context capture, fingerprinting, or visitor confirmation.
|
|
10339
|
+
// A routine unchanged text/voice consent refresh does not revoke a CTA:
|
|
10340
|
+
// its native visitor link does not require browser-control permission.
|
|
10341
|
+
const scopes = this.authoritativeConsentScopes(message.payload);
|
|
10342
|
+
const unchangedConsent = message.payload.source === "consent_update" &&
|
|
10343
|
+
scopes !== null &&
|
|
10344
|
+
!this.scopes.includes("browser_control") &&
|
|
10345
|
+
scopes.length === this.scopes.length &&
|
|
10346
|
+
scopes.every((scope) => this.scopes.includes(scope));
|
|
9740
10347
|
this.discardPendingConfirmationDecisions();
|
|
9741
|
-
this.revokeActiveActionAtIngress();
|
|
10348
|
+
this.revokeActiveActionAtIngress(unchangedConsent);
|
|
9742
10349
|
return;
|
|
9743
10350
|
}
|
|
9744
10351
|
if (message.type === "error") {
|
|
@@ -9810,7 +10417,9 @@ class AiLiveAssist {
|
|
|
9810
10417
|
this.finishFromServer(this.string(message.payload.reasonCode), message.sessionId);
|
|
9811
10418
|
}
|
|
9812
10419
|
}
|
|
9813
|
-
revokeActiveActionAtIngress() {
|
|
10420
|
+
revokeActiveActionAtIngress(preserveCta = false) {
|
|
10421
|
+
if (!preserveCta)
|
|
10422
|
+
this.invalidateCtaAuthority();
|
|
9814
10423
|
this.actionIngressRevocationGeneration =
|
|
9815
10424
|
(Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
9816
10425
|
? this.actionIngressRevocationGeneration
|
|
@@ -9903,6 +10512,7 @@ class AiLiveAssist {
|
|
|
9903
10512
|
return authorityEpoch;
|
|
9904
10513
|
}
|
|
9905
10514
|
revokeContextResyncActionAuthority(atIngress) {
|
|
10515
|
+
this.invalidateCtaAuthority();
|
|
9906
10516
|
if (atIngress) {
|
|
9907
10517
|
this.actionIngressRevocationGeneration =
|
|
9908
10518
|
(Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
@@ -9965,6 +10575,9 @@ class AiLiveAssist {
|
|
|
9965
10575
|
this.view.applyPresenceState(state, message.sequence, message.sessionId, this.context?.currentPageId ?? null, this.channel?.leaseToken ?? 0);
|
|
9966
10576
|
}
|
|
9967
10577
|
else if (this.view instanceof ui_js_1.WidgetView && this.result) {
|
|
10578
|
+
if (state === "thinking") {
|
|
10579
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10580
|
+
}
|
|
9968
10581
|
if (state === "reconnecting") {
|
|
9969
10582
|
this.view.showConnecting(true, this.currentDisplayMode());
|
|
9970
10583
|
}
|
|
@@ -10020,7 +10633,10 @@ class AiLiveAssist {
|
|
|
10020
10633
|
const currentIngressGeneration = Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
10021
10634
|
? this.actionIngressRevocationGeneration
|
|
10022
10635
|
: 0;
|
|
10023
|
-
|
|
10636
|
+
// A CTA is fenced by its own authority generation in the handler;
|
|
10637
|
+
// unchanged consent still advances the independent browser-action fence.
|
|
10638
|
+
if (message.type !== "cta.offer" &&
|
|
10639
|
+
ingressGeneration !== currentIngressGeneration)
|
|
10024
10640
|
continue;
|
|
10025
10641
|
await this.handleServerMessage(message, isCurrent, true);
|
|
10026
10642
|
}
|
|
@@ -10075,8 +10691,50 @@ class AiLiveAssist {
|
|
|
10075
10691
|
return;
|
|
10076
10692
|
const payload = message.payload;
|
|
10077
10693
|
switch (message.type) {
|
|
10078
|
-
case "
|
|
10079
|
-
|
|
10694
|
+
case "cta.offer": {
|
|
10695
|
+
// CTA has its own ingress fence. Browser-action generations also move
|
|
10696
|
+
// on unchanged consent, which must not discard a queued native link.
|
|
10697
|
+
const offer = (0, ctaOffer_js_1.parseCtaOffer)(payload);
|
|
10698
|
+
if (message.sessionId !== this.result?.sessionId)
|
|
10699
|
+
return;
|
|
10700
|
+
if (this.ctaSessionId !== message.sessionId) {
|
|
10701
|
+
this.ctaSessionId = message.sessionId;
|
|
10702
|
+
this.ctaTerminalOffers = new Set();
|
|
10703
|
+
this.ctaAnnouncedOffers = new Set();
|
|
10704
|
+
this.ctaClicked = false;
|
|
10705
|
+
}
|
|
10706
|
+
if (!offer ||
|
|
10707
|
+
message.v !== 2 ||
|
|
10708
|
+
!this.ctaEnvelopeIsCurrent(message) ||
|
|
10709
|
+
this.ctaStoppedSessionId === message.sessionId ||
|
|
10710
|
+
(!replayingPreFenceAuthority &&
|
|
10711
|
+
!this.hadFencedAuthorityAtIngress(message)) ||
|
|
10712
|
+
!this.channel?.hasFencedAuthority ||
|
|
10713
|
+
this.bootstrap?.capabilities?.ctaOffer !== true ||
|
|
10714
|
+
offer.configRevision !== this.bootstrap.configRevision ||
|
|
10715
|
+
this.messengerTransferred ||
|
|
10716
|
+
this.messengerTransferPending ||
|
|
10717
|
+
this.ctaClicked ||
|
|
10718
|
+
this.ctaTerminalOffers.has(offer.offerId) ||
|
|
10719
|
+
this.ctaTerminalOffers.size >= 16 ||
|
|
10720
|
+
(this.ctaSeenOffers ?? (this.ctaSeenOffers = new Set())).has(offer.offerId) ||
|
|
10721
|
+
this.ctaSeenOffers.size >= 16)
|
|
10722
|
+
return;
|
|
10723
|
+
this.clearCurrentCtaOffer();
|
|
10724
|
+
this.ctaSeenOffers.add(offer.offerId);
|
|
10725
|
+
this.ctaOffer = offer;
|
|
10726
|
+
const generation = this.sessionEffectGeneration;
|
|
10727
|
+
this.ctaExpiryTimer = setTimeout(() => {
|
|
10728
|
+
if (this.ctaOffer === offer &&
|
|
10729
|
+
this.sessionEffectGeneration === generation) {
|
|
10730
|
+
this.clearCurrentCtaOffer();
|
|
10731
|
+
}
|
|
10732
|
+
}, Date.parse(offer.expiresAt) - Date.now());
|
|
10733
|
+
this.renderCurrentCtaOffer();
|
|
10734
|
+
return;
|
|
10735
|
+
}
|
|
10736
|
+
case "control.ready":
|
|
10737
|
+
this.handoffContextPromptReceiptChannel =
|
|
10080
10738
|
payload.handoffContextPromptReceipt === true &&
|
|
10081
10739
|
typeof payload.helloMessageId === "string" &&
|
|
10082
10740
|
payload.helloMessageId ===
|
|
@@ -10106,23 +10764,39 @@ class AiLiveAssist {
|
|
|
10106
10764
|
if (text) {
|
|
10107
10765
|
const final = payload.final === true;
|
|
10108
10766
|
if (this.isLocallyRenderedQuestionEcho(payload, speaker, final)) {
|
|
10767
|
+
if (speaker === "user" &&
|
|
10768
|
+
final &&
|
|
10769
|
+
!(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10770
|
+
this.renderedTranscriptIds.add(message.id);
|
|
10771
|
+
this.admitVoicePlaybackTurn(message);
|
|
10772
|
+
}
|
|
10109
10773
|
return;
|
|
10110
10774
|
}
|
|
10111
10775
|
if (final) {
|
|
10112
10776
|
if ((this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10777
|
+
if (speaker === "assistant" && this.ctaContentIsCurrent(message))
|
|
10778
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10113
10779
|
return;
|
|
10114
10780
|
}
|
|
10115
10781
|
this.rememberTranscript(message.id, speaker, text);
|
|
10116
10782
|
this.renderedTranscriptIds.add(message.id);
|
|
10783
|
+
if (speaker === "user")
|
|
10784
|
+
this.admitVoicePlaybackTurn(message);
|
|
10117
10785
|
}
|
|
10118
|
-
this.view?.addCaption(speaker, text, final
|
|
10786
|
+
this.view?.addCaption(speaker, text, final, {
|
|
10787
|
+
sourceTurnId: message.id,
|
|
10788
|
+
});
|
|
10789
|
+
if (speaker === "assistant" &&
|
|
10790
|
+
final &&
|
|
10791
|
+
this.ctaContentIsCurrent(message))
|
|
10792
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10119
10793
|
if (speaker === "user" && final) {
|
|
10120
10794
|
const pending = this.pendingConfirmation
|
|
10121
10795
|
? { ...this.pendingConfirmation }
|
|
10122
10796
|
: null;
|
|
10123
|
-
if (!this.resolvePendingConfirmationReply(text)) {
|
|
10797
|
+
if (!this.resolvePendingConfirmationReply(text, message)) {
|
|
10124
10798
|
if (pending)
|
|
10125
|
-
this.cancelConfirmationForNewRequest(pending);
|
|
10799
|
+
this.cancelConfirmationForNewRequest(pending, message);
|
|
10126
10800
|
}
|
|
10127
10801
|
}
|
|
10128
10802
|
}
|
|
@@ -10161,6 +10835,8 @@ class AiLiveAssist {
|
|
|
10161
10835
|
state === "ready") {
|
|
10162
10836
|
if (!this.hadFencedAuthorityAtIngress(message))
|
|
10163
10837
|
return;
|
|
10838
|
+
if (state === "thinking")
|
|
10839
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10164
10840
|
this.view?.setAssistantState(state);
|
|
10165
10841
|
}
|
|
10166
10842
|
return;
|
|
@@ -10174,38 +10850,67 @@ class AiLiveAssist {
|
|
|
10174
10850
|
? "assistant"
|
|
10175
10851
|
: "user";
|
|
10176
10852
|
const final = payload.final === true;
|
|
10177
|
-
if (this.isLocallyRenderedQuestionEcho(payload, role, final))
|
|
10853
|
+
if (this.isLocallyRenderedQuestionEcho(payload, role, final)) {
|
|
10854
|
+
if (role === "user" &&
|
|
10855
|
+
final &&
|
|
10856
|
+
!(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10857
|
+
this.renderedTranscriptIds.add(message.id);
|
|
10858
|
+
this.admitVoicePlaybackTurn(message);
|
|
10859
|
+
}
|
|
10178
10860
|
return;
|
|
10861
|
+
}
|
|
10179
10862
|
if (final) {
|
|
10180
10863
|
if ((this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10864
|
+
if (role === "assistant" && this.ctaContentIsCurrent(message))
|
|
10865
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10181
10866
|
return;
|
|
10182
10867
|
}
|
|
10183
10868
|
this.rememberTranscript(message.id, role, text);
|
|
10184
10869
|
this.renderedTranscriptIds.add(message.id);
|
|
10870
|
+
if (role === "user")
|
|
10871
|
+
this.admitVoicePlaybackTurn(message);
|
|
10185
10872
|
}
|
|
10186
|
-
this.view?.addCaption(role, text, final);
|
|
10873
|
+
this.view?.addCaption(role, text, final, { sourceTurnId: message.id });
|
|
10874
|
+
if (role === "assistant" && final && this.ctaContentIsCurrent(message))
|
|
10875
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10187
10876
|
if (role === "user" && final) {
|
|
10188
10877
|
const pending = this.pendingConfirmation
|
|
10189
10878
|
? { ...this.pendingConfirmation }
|
|
10190
10879
|
: null;
|
|
10191
|
-
if (!this.resolvePendingConfirmationReply(text)) {
|
|
10880
|
+
if (!this.resolvePendingConfirmationReply(text, message)) {
|
|
10192
10881
|
if (pending)
|
|
10193
|
-
this.cancelConfirmationForNewRequest(pending);
|
|
10882
|
+
this.cancelConfirmationForNewRequest(pending, message);
|
|
10194
10883
|
}
|
|
10195
10884
|
}
|
|
10196
10885
|
if (role === "assistant" && message.v === 1) {
|
|
10886
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10197
10887
|
this.view?.setAssistantState("speaking");
|
|
10198
10888
|
}
|
|
10199
10889
|
return;
|
|
10200
10890
|
}
|
|
10201
|
-
case "assistant.interrupted":
|
|
10891
|
+
case "assistant.interrupted": {
|
|
10892
|
+
if (!this.voicePlaybackIngress?.has(message))
|
|
10893
|
+
this.invalidateVoicePlaybackRearm();
|
|
10202
10894
|
this.presentation?.clear("all");
|
|
10203
|
-
this.
|
|
10204
|
-
|
|
10205
|
-
|
|
10895
|
+
const request = this.currentManualPushRequest();
|
|
10896
|
+
const earlierStop = request !== null &&
|
|
10897
|
+
payload.controlFencingToken === request.fencingToken &&
|
|
10898
|
+
Number.isSafeInteger(payload.controlSequence) &&
|
|
10899
|
+
Number(payload.controlSequence) > 0 && Number(payload.controlSequence) < request.sequence;
|
|
10900
|
+
if (!earlierStop)
|
|
10901
|
+
this.stopManualPushToTalk(false);
|
|
10902
|
+
if (this.view instanceof ui_js_1.WidgetView)
|
|
10903
|
+
this.view.interruptPlayback(earlierStop);
|
|
10904
|
+
else
|
|
10905
|
+
this.view?.interruptPlayback();
|
|
10206
10906
|
return;
|
|
10907
|
+
}
|
|
10207
10908
|
case "voice.turn_mode": {
|
|
10208
10909
|
const manual = payload.mode === "manual";
|
|
10910
|
+
if (manual && this.bootstrap?.voice?.turnMode !== "manual")
|
|
10911
|
+
return;
|
|
10912
|
+
if (!manual && this.manualTurn && this.bootstrap?.voice?.turnMode !== "manual")
|
|
10913
|
+
return;
|
|
10209
10914
|
this.manualTurn = manual;
|
|
10210
10915
|
this.pushActive = false;
|
|
10211
10916
|
this.media?.setManualTurn(manual);
|
|
@@ -10216,13 +10921,27 @@ class AiLiveAssist {
|
|
|
10216
10921
|
case "voice.push.ready":
|
|
10217
10922
|
if (!this.manualTurn)
|
|
10218
10923
|
return;
|
|
10924
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1) {
|
|
10925
|
+
const request = this.currentManualPushRequest();
|
|
10926
|
+
if (!request || request.state !== "pending" || request.id !== payload.requestId)
|
|
10927
|
+
return;
|
|
10928
|
+
request.state = "capturing";
|
|
10929
|
+
}
|
|
10930
|
+
if (this.media?.isMuted || this.view?.setPushActive(true) === false) {
|
|
10931
|
+
this.media?.endPushToTalk();
|
|
10932
|
+
this.pushActive = false;
|
|
10933
|
+
this.view?.setPushActive(false);
|
|
10934
|
+
this.send("session.interrupt", {});
|
|
10935
|
+
return;
|
|
10936
|
+
}
|
|
10219
10937
|
this.pushActive = true;
|
|
10220
10938
|
this.media?.beginPushToTalk();
|
|
10221
|
-
this.view?.setPushActive(true);
|
|
10222
10939
|
return;
|
|
10223
10940
|
case "voice.push.committed":
|
|
10224
|
-
this.
|
|
10225
|
-
|
|
10941
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1 &&
|
|
10942
|
+
this.currentManualPushRequest()?.id !== payload.requestId)
|
|
10943
|
+
return;
|
|
10944
|
+
this.stopManualPushToTalk(false);
|
|
10226
10945
|
return;
|
|
10227
10946
|
case "session.mode.upgrade_ready":
|
|
10228
10947
|
this.handleModeUpgradeReady(payload);
|
|
@@ -10385,6 +11104,8 @@ class AiLiveAssist {
|
|
|
10385
11104
|
this.view?.showActionState(payload.verified === true ? "verified" : "failed");
|
|
10386
11105
|
return;
|
|
10387
11106
|
case "action.revoked":
|
|
11107
|
+
if (!this.ctaAuthorityGenerationAtIngress?.has(message))
|
|
11108
|
+
this.invalidateCtaAuthority();
|
|
10388
11109
|
this.revokeActiveAction();
|
|
10389
11110
|
return;
|
|
10390
11111
|
case "context.resync_required":
|
|
@@ -10488,6 +11209,11 @@ class AiLiveAssist {
|
|
|
10488
11209
|
}
|
|
10489
11210
|
case "session.state": {
|
|
10490
11211
|
const state = this.string(payload.state);
|
|
11212
|
+
if (["ending", "ended", "failed", "revoked"].includes(state) &&
|
|
11213
|
+
!this.ctaAuthorityGenerationAtIngress?.has(message)) {
|
|
11214
|
+
this.ctaStoppedSessionId = message.sessionId;
|
|
11215
|
+
this.invalidateCtaAuthority();
|
|
11216
|
+
}
|
|
10491
11217
|
if (!this.hadFencedAuthorityAtIngress(message) &&
|
|
10492
11218
|
(state === "active_text" ||
|
|
10493
11219
|
state === "active_voice" ||
|
|
@@ -10534,6 +11260,8 @@ class AiLiveAssist {
|
|
|
10534
11260
|
return;
|
|
10535
11261
|
}
|
|
10536
11262
|
case "provider.reconnecting":
|
|
11263
|
+
if (!this.ctaAuthorityGenerationAtIngress?.has(message))
|
|
11264
|
+
this.invalidateCtaAuthority();
|
|
10537
11265
|
this.view?.showConnecting(true, this.currentDisplayMode());
|
|
10538
11266
|
this.state("reconnecting");
|
|
10539
11267
|
return;
|
|
@@ -10673,15 +11401,18 @@ class AiLiveAssist {
|
|
|
10673
11401
|
this.scheduleReconnect(true);
|
|
10674
11402
|
return;
|
|
10675
11403
|
}
|
|
10676
|
-
this.view?.showError(this.string(payload.message), retryable);
|
|
10677
11404
|
if (code === "SESSION_REVOKED") {
|
|
11405
|
+
this.presentSessionError(this.string(payload.message), retryable);
|
|
10678
11406
|
this.finishFromServer(code, message.sessionId);
|
|
10679
11407
|
return;
|
|
10680
11408
|
}
|
|
10681
|
-
//
|
|
10682
|
-
//
|
|
10683
|
-
|
|
11409
|
+
// A causal action result is settled by its exact waiter. Do not surface
|
|
11410
|
+
// that rejection as a session-wide error or tear down healthy media.
|
|
11411
|
+
// Other correlated frames can be fire-and-forget and still need their
|
|
11412
|
+
// server error surfaced.
|
|
11413
|
+
if (operation?.type === "action.result")
|
|
10684
11414
|
return;
|
|
11415
|
+
this.presentSessionError(this.string(payload.message), retryable);
|
|
10685
11416
|
return;
|
|
10686
11417
|
}
|
|
10687
11418
|
}
|
|
@@ -10730,6 +11461,12 @@ class AiLiveAssist {
|
|
|
10730
11461
|
return ["click", "type", "select", "submit"].includes(action);
|
|
10731
11462
|
}
|
|
10732
11463
|
pendingActionExecutionRecord(pending) {
|
|
11464
|
+
// An outgoing document has not observed the destination. Its in-memory
|
|
11465
|
+
// result is for a possible SPA transition only; pagehide/transport cleanup
|
|
11466
|
+
// must retain the result-less marker until navigation is actually rebound.
|
|
11467
|
+
const result = pending.deferredNavigationPath !== null && !pending.navigationAcknowledged
|
|
11468
|
+
? null
|
|
11469
|
+
: pending.result;
|
|
10733
11470
|
return {
|
|
10734
11471
|
actionId: pending.actionId,
|
|
10735
11472
|
executionId: pending.executionId,
|
|
@@ -10738,12 +11475,15 @@ class AiLiveAssist {
|
|
|
10738
11475
|
expiresAt: pending.expiresAt,
|
|
10739
11476
|
resultMessageId: pending.resultMessageId,
|
|
10740
11477
|
navigationMessageId: pending.navigationMessageId,
|
|
10741
|
-
result:
|
|
10742
|
-
? { ...
|
|
11478
|
+
result: result
|
|
11479
|
+
? { ...result, observed: { ...result.observed } }
|
|
10743
11480
|
: null,
|
|
10744
11481
|
navigationPayload: pending.navigationPayload
|
|
10745
11482
|
? { ...pending.navigationPayload }
|
|
10746
11483
|
: null,
|
|
11484
|
+
...(pending.deferredNavigationPath
|
|
11485
|
+
? { deferredNavigationPath: pending.deferredNavigationPath }
|
|
11486
|
+
: {}),
|
|
10747
11487
|
};
|
|
10748
11488
|
}
|
|
10749
11489
|
persistPendingActionExecution(pending) {
|
|
@@ -10777,7 +11517,7 @@ class AiLiveAssist {
|
|
|
10777
11517
|
expiresAt: stored.expiresAt,
|
|
10778
11518
|
ready: deferredSignal(),
|
|
10779
11519
|
readyState: null,
|
|
10780
|
-
mutationObserved: stored.result !== null,
|
|
11520
|
+
mutationObserved: stored.result !== null || stored.deferredNavigationPath !== undefined,
|
|
10781
11521
|
result: stored.result
|
|
10782
11522
|
? { ...stored.result, observed: { ...stored.result.observed } }
|
|
10783
11523
|
: null,
|
|
@@ -10789,8 +11529,12 @@ class AiLiveAssist {
|
|
|
10789
11529
|
navigationPayload: stored.navigationPayload
|
|
10790
11530
|
? { ...stored.navigationPayload }
|
|
10791
11531
|
: null,
|
|
11532
|
+
deferredNavigationPath: stored.deferredNavigationPath ?? null,
|
|
11533
|
+
// A restored result may already have reached the server without an ACK.
|
|
11534
|
+
resultDeliveryAttempted: true,
|
|
10792
11535
|
resultAcknowledged: false,
|
|
10793
|
-
navigationAcknowledged: stored.navigationPayload === null
|
|
11536
|
+
navigationAcknowledged: stored.navigationPayload === null &&
|
|
11537
|
+
stored.deferredNavigationPath === undefined,
|
|
10794
11538
|
};
|
|
10795
11539
|
this.pendingNavigationActionResult = pending;
|
|
10796
11540
|
return pending;
|
|
@@ -10821,6 +11565,69 @@ class AiLiveAssist {
|
|
|
10821
11565
|
},
|
|
10822
11566
|
};
|
|
10823
11567
|
}
|
|
11568
|
+
markDeferredNavigationUnconfirmed(pending, revision) {
|
|
11569
|
+
const result = this.unconfirmedActionExecutionResult(pending, revision);
|
|
11570
|
+
if (this.pendingNavigationActionResult !== pending)
|
|
11571
|
+
return result;
|
|
11572
|
+
pending.result = result;
|
|
11573
|
+
pending.deferredNavigationPath = null;
|
|
11574
|
+
if (!pending.navigationPayload)
|
|
11575
|
+
pending.navigationAcknowledged = true;
|
|
11576
|
+
this.persistPendingActionExecution(pending);
|
|
11577
|
+
return result;
|
|
11578
|
+
}
|
|
11579
|
+
deferredDocumentNavigationPath(pending, value) {
|
|
11580
|
+
const expectedPath = pending.grant?.destinationPath;
|
|
11581
|
+
if (!expectedPath)
|
|
11582
|
+
return null;
|
|
11583
|
+
try {
|
|
11584
|
+
const destination = new URL(value);
|
|
11585
|
+
return destination.origin === window.location.origin &&
|
|
11586
|
+
destination.username === "" &&
|
|
11587
|
+
destination.password === "" &&
|
|
11588
|
+
destination.search === "" &&
|
|
11589
|
+
destination.hash === "" &&
|
|
11590
|
+
destination.pathname === expectedPath
|
|
11591
|
+
? expectedPath
|
|
11592
|
+
: null;
|
|
11593
|
+
}
|
|
11594
|
+
catch {
|
|
11595
|
+
return null;
|
|
11596
|
+
}
|
|
11597
|
+
}
|
|
11598
|
+
prepareDeferredDocumentNavigationRecovery(pending, destinationUrl) {
|
|
11599
|
+
const deferredNavigationPath = this.deferredDocumentNavigationPath(pending, destinationUrl);
|
|
11600
|
+
if (!deferredNavigationPath)
|
|
11601
|
+
return false;
|
|
11602
|
+
const previousResult = pending.result;
|
|
11603
|
+
const previousNavigationAcknowledged = pending.navigationAcknowledged;
|
|
11604
|
+
pending.result = null;
|
|
11605
|
+
pending.deferredNavigationPath = deferredNavigationPath;
|
|
11606
|
+
pending.navigationAcknowledged = false;
|
|
11607
|
+
if (this.persistPendingActionExecution(pending))
|
|
11608
|
+
return true;
|
|
11609
|
+
pending.result = previousResult;
|
|
11610
|
+
pending.deferredNavigationPath = null;
|
|
11611
|
+
pending.navigationAcknowledged = previousNavigationAcknowledged;
|
|
11612
|
+
return false;
|
|
11613
|
+
}
|
|
11614
|
+
rebaseDeferredDocumentNavigationRecovery(pathname) {
|
|
11615
|
+
const pending = this.restorePendingActionExecution();
|
|
11616
|
+
const expectedPath = pending?.deferredNavigationPath ?? null;
|
|
11617
|
+
if (!pending || !expectedPath || pending.grant !== null)
|
|
11618
|
+
return true;
|
|
11619
|
+
const exactDestination = pathname === expectedPath &&
|
|
11620
|
+
path() === expectedPath &&
|
|
11621
|
+
window.location.search === "" &&
|
|
11622
|
+
window.location.hash === "";
|
|
11623
|
+
pending.result = this.unconfirmedActionExecutionResult(pending, 0, exactDestination
|
|
11624
|
+
? `${window.location.origin}${expectedPath}`
|
|
11625
|
+
: window.location.href);
|
|
11626
|
+
pending.navigationAcknowledged = true;
|
|
11627
|
+
if (!exactDestination)
|
|
11628
|
+
pending.deferredNavigationPath = null;
|
|
11629
|
+
return this.persistPendingActionExecution(pending);
|
|
11630
|
+
}
|
|
10824
11631
|
executionResultWithoutGrant(pending, result) {
|
|
10825
11632
|
return {
|
|
10826
11633
|
actionId: pending.actionId,
|
|
@@ -10874,14 +11681,19 @@ class AiLiveAssist {
|
|
|
10874
11681
|
const ready = { state, expiresAt };
|
|
10875
11682
|
pending.expiresAt = expiresAt;
|
|
10876
11683
|
pending.readyState = ready;
|
|
10877
|
-
if (state === "already_started" &&
|
|
11684
|
+
if (state === "already_started" &&
|
|
11685
|
+
pending.result === null &&
|
|
11686
|
+
(pending.deferredNavigationPath === null ||
|
|
11687
|
+
pending.navigationAcknowledged)) {
|
|
10878
11688
|
pending.result = this.unconfirmedActionExecutionResult(pending);
|
|
10879
11689
|
}
|
|
10880
11690
|
this.persistPendingActionExecution(pending);
|
|
10881
11691
|
pending.ready.resolve(ready);
|
|
10882
11692
|
if (scheduleFlush &&
|
|
10883
11693
|
state === "already_started" &&
|
|
10884
|
-
pending.grant === null
|
|
11694
|
+
pending.grant === null &&
|
|
11695
|
+
(pending.deferredNavigationPath === null ||
|
|
11696
|
+
pending.navigationAcknowledged)) {
|
|
10885
11697
|
queueMicrotask(() => void this.flushPendingNavigationActionResult());
|
|
10886
11698
|
}
|
|
10887
11699
|
return true;
|
|
@@ -10936,13 +11748,20 @@ class AiLiveAssist {
|
|
|
10936
11748
|
if (ready?.state === "already_started") {
|
|
10937
11749
|
pending.result ?? (pending.result = this.unconfirmedActionExecutionResult(pending));
|
|
10938
11750
|
this.persistPendingActionExecution(pending);
|
|
10939
|
-
await this.flushPendingNavigationActionResult();
|
|
11751
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
11752
|
+
if (!terminalDelivered &&
|
|
11753
|
+
!this.terminalRequestPending &&
|
|
11754
|
+
!this.ended &&
|
|
11755
|
+
!this.destroyed) {
|
|
11756
|
+
this.scheduleReconnect(true);
|
|
11757
|
+
}
|
|
10940
11758
|
return "pending";
|
|
10941
11759
|
}
|
|
10942
11760
|
}
|
|
10943
11761
|
pending.result ?? (pending.result = this.unconfirmedActionExecutionResult(pending));
|
|
10944
11762
|
this.persistPendingActionExecution(pending);
|
|
10945
|
-
|
|
11763
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
11764
|
+
if (!terminalDelivered &&
|
|
10946
11765
|
!this.terminalRequestPending &&
|
|
10947
11766
|
!this.ended &&
|
|
10948
11767
|
!this.destroyed) {
|
|
@@ -11083,7 +11902,9 @@ class AiLiveAssist {
|
|
|
11083
11902
|
if (this.result?.protocolVersion === 2 &&
|
|
11084
11903
|
this.actionRequiresExecutionTransition(grant.action)) {
|
|
11085
11904
|
if (this.pendingNavigationActionResult !== null) {
|
|
11086
|
-
|
|
11905
|
+
const result = this.blockedActionResult(grant, "Another page action is still awaiting secure verification.", context.currentRevision);
|
|
11906
|
+
this.send("action.result", result);
|
|
11907
|
+
return result;
|
|
11087
11908
|
}
|
|
11088
11909
|
pendingExecution = {
|
|
11089
11910
|
grant,
|
|
@@ -11102,6 +11923,8 @@ class AiLiveAssist {
|
|
|
11102
11923
|
resultMessageId: randomId("msg_action_result"),
|
|
11103
11924
|
navigationMessageId: randomId("msg_context_navigation"),
|
|
11104
11925
|
navigationPayload: null,
|
|
11926
|
+
deferredNavigationPath: null,
|
|
11927
|
+
resultDeliveryAttempted: false,
|
|
11105
11928
|
resultAcknowledged: false,
|
|
11106
11929
|
navigationAcknowledged: true,
|
|
11107
11930
|
};
|
|
@@ -11129,6 +11952,7 @@ class AiLiveAssist {
|
|
|
11129
11952
|
channel,
|
|
11130
11953
|
result: null,
|
|
11131
11954
|
causalNavigationObserved: false,
|
|
11955
|
+
resultAcknowledged: false,
|
|
11132
11956
|
deliveryCommitted: false,
|
|
11133
11957
|
}
|
|
11134
11958
|
: null;
|
|
@@ -11163,37 +11987,80 @@ class AiLiveAssist {
|
|
|
11163
11987
|
if (this.pendingNavigationActionResult !== pendingExecution) {
|
|
11164
11988
|
return deliveryResult;
|
|
11165
11989
|
}
|
|
11166
|
-
const
|
|
11167
|
-
? pendingExecution.causalNavigationDeliveryConfirmed
|
|
11168
|
-
: await this.flushPendingNavigationActionResult();
|
|
11169
|
-
if (deferredNavigation &&
|
|
11170
|
-
confirmed &&
|
|
11990
|
+
const deferredNavigationCanRelease = Boolean(deferredNavigation &&
|
|
11171
11991
|
authorityIsCurrent() &&
|
|
11172
11992
|
Date.parse(pendingExecution.expiresAt) > Date.now() &&
|
|
11173
|
-
|
|
11174
|
-
|
|
11993
|
+
this.prepareDeferredDocumentNavigationRecovery(pendingExecution, deferredNavigation));
|
|
11994
|
+
if (deferredNavigationCanRelease && deferredNavigation) {
|
|
11995
|
+
// Keep the verified result in memory so a same-document router can
|
|
11996
|
+
// deliver it with the causal navigation. The persisted copy remains
|
|
11997
|
+
// intentionally result-less until navigation settles, preserving the
|
|
11998
|
+
// cross-document recovery contract if this click unloads the page.
|
|
11999
|
+
pendingExecution.result = deliveryResult;
|
|
12000
|
+
try {
|
|
12001
|
+
if (await this.navigateTo(deferredNavigation)) {
|
|
12002
|
+
return deliveryResult;
|
|
12003
|
+
}
|
|
12004
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
12005
|
+
}
|
|
12006
|
+
catch {
|
|
12007
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
12008
|
+
}
|
|
12009
|
+
}
|
|
12010
|
+
else if (deferredNavigation) {
|
|
12011
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
12012
|
+
}
|
|
12013
|
+
if (!pendingExecution.causalNavigationDeliveryAttempted) {
|
|
12014
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
12015
|
+
if (!terminalDelivered &&
|
|
12016
|
+
!this.terminalRequestPending &&
|
|
12017
|
+
!this.ended &&
|
|
12018
|
+
!this.destroyed) {
|
|
12019
|
+
this.scheduleReconnect(true);
|
|
12020
|
+
}
|
|
11175
12021
|
}
|
|
11176
12022
|
return deliveryResult;
|
|
11177
12023
|
}
|
|
11178
|
-
if (
|
|
12024
|
+
if (!deferredNavigation &&
|
|
12025
|
+
legacyExecution &&
|
|
12026
|
+
this.legacyActionExecution === legacyExecution) {
|
|
11179
12027
|
this.legacyActionExecution = null;
|
|
11180
12028
|
}
|
|
11181
12029
|
const messageId = authorityIsCurrent()
|
|
11182
12030
|
? this.send("action.result", result)
|
|
11183
12031
|
: null;
|
|
11184
|
-
if (!deferredNavigation
|
|
12032
|
+
if (!deferredNavigation)
|
|
11185
12033
|
return result;
|
|
12034
|
+
if (!messageId) {
|
|
12035
|
+
if (legacyExecution)
|
|
12036
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12037
|
+
return result;
|
|
12038
|
+
}
|
|
11186
12039
|
const outcome = await channel.waitForOutcome(messageId, 2500, channel.lastClientSequence);
|
|
11187
12040
|
if (outcome.status === "ack" &&
|
|
11188
12041
|
authorityIsCurrent() &&
|
|
11189
12042
|
Date.parse(grant.expiresAt) > Date.now() &&
|
|
11190
12043
|
new URL(deferredNavigation).origin === window.location.origin) {
|
|
11191
|
-
|
|
12044
|
+
if (legacyExecution)
|
|
12045
|
+
legacyExecution.resultAcknowledged = true;
|
|
12046
|
+
const navigationReleased = await this.navigateTo(deferredNavigation);
|
|
12047
|
+
if (!navigationReleased && legacyExecution) {
|
|
12048
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12049
|
+
}
|
|
12050
|
+
}
|
|
12051
|
+
else if (outcome.status === "ack" && legacyExecution) {
|
|
12052
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
11192
12053
|
}
|
|
11193
12054
|
else if (outcome.status === "explicit_error" &&
|
|
11194
12055
|
!outcome.retryable &&
|
|
11195
12056
|
authorityIsCurrent()) {
|
|
11196
|
-
this.
|
|
12057
|
+
const rejectedExecutionStillOwnsState = !legacyExecution || this.legacyActionExecution === legacyExecution;
|
|
12058
|
+
if (legacyExecution) {
|
|
12059
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12060
|
+
}
|
|
12061
|
+
if (rejectedExecutionStillOwnsState) {
|
|
12062
|
+
this.view?.showActionState("failed");
|
|
12063
|
+
}
|
|
11197
12064
|
}
|
|
11198
12065
|
else if (this.controlOutcomeNeedsRetry(outcome) && authorityIsCurrent()) {
|
|
11199
12066
|
this.scheduleReconnect(true);
|
|
@@ -11308,16 +12175,20 @@ class AiLiveAssist {
|
|
|
11308
12175
|
if (!navigationMessageId) {
|
|
11309
12176
|
return this.abandonLegacyCausalDelivery(execution);
|
|
11310
12177
|
}
|
|
11311
|
-
const resultMessageId =
|
|
12178
|
+
const resultMessageId = execution.resultAcknowledged
|
|
12179
|
+
? null
|
|
12180
|
+
: this.send("action.result", result);
|
|
11312
12181
|
const resultSequence = channel.lastClientSequence;
|
|
11313
|
-
if (!resultMessageId) {
|
|
12182
|
+
if (!execution.resultAcknowledged && !resultMessageId) {
|
|
11314
12183
|
return this.abandonLegacyCausalDelivery(execution);
|
|
11315
12184
|
}
|
|
11316
12185
|
execution.deliveryCommitted = true;
|
|
11317
12186
|
this.resetActionGrantAuthority();
|
|
11318
12187
|
const outcomes = await Promise.all([
|
|
11319
12188
|
this.trackContextNavigationAcknowledgement(channel, navigationMessageId, navigationSequence, payload),
|
|
11320
|
-
|
|
12189
|
+
...(resultMessageId
|
|
12190
|
+
? [channel.waitForOutcome(resultMessageId, 5000, resultSequence)]
|
|
12191
|
+
: []),
|
|
11321
12192
|
]);
|
|
11322
12193
|
if (outcomes.every((outcome) => outcome.status === "ack"))
|
|
11323
12194
|
return true;
|
|
@@ -11360,25 +12231,35 @@ class AiLiveAssist {
|
|
|
11360
12231
|
? this.trackContextNavigationAcknowledgement(channel, messageId, clientSequence, pending.navigationPayload)
|
|
11361
12232
|
: channel.waitForOutcome(messageId, 5000, clientSequence);
|
|
11362
12233
|
return delivery.then((outcome) => {
|
|
11363
|
-
|
|
11364
|
-
this.
|
|
11365
|
-
|
|
11366
|
-
if (
|
|
11367
|
-
|
|
11368
|
-
|
|
12234
|
+
const isCurrent = this.pendingNavigationActionResult === pending &&
|
|
12235
|
+
this.channel === channel;
|
|
12236
|
+
if (outcome.status === "ack") {
|
|
12237
|
+
if (kind === "result")
|
|
12238
|
+
pending.resultAcknowledged = true;
|
|
12239
|
+
else
|
|
12240
|
+
pending.navigationAcknowledged = true;
|
|
12241
|
+
if (isCurrent) {
|
|
12242
|
+
if (pending.resultAcknowledged && pending.navigationAcknowledged) {
|
|
12243
|
+
this.clearPendingActionExecution(pending);
|
|
12244
|
+
}
|
|
12245
|
+
}
|
|
12246
|
+
// Ingress-time revocation can retire the pending record before this
|
|
12247
|
+
// exact waiter settles. The correlated ACK still proves delivery and
|
|
12248
|
+
// must not reconnect a healthy transport or mutate a newer action.
|
|
12249
|
+
return true;
|
|
12250
|
+
}
|
|
12251
|
+
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
12252
|
+
if (isCurrent) {
|
|
11369
12253
|
this.clearPendingActionExecution(pending);
|
|
12254
|
+
this.pendingAction = false;
|
|
11370
12255
|
this.view?.showActionState("unconfirmed");
|
|
11371
12256
|
}
|
|
11372
|
-
|
|
12257
|
+
// A definitive operation-local result rejection terminalizes only this
|
|
12258
|
+
// action. It is not a transport failure, even if action.revoked already
|
|
12259
|
+
// cleared the local record or a newer channel has since been installed.
|
|
12260
|
+
return kind === "result";
|
|
11373
12261
|
}
|
|
11374
|
-
|
|
11375
|
-
pending.resultAcknowledged = true;
|
|
11376
|
-
else
|
|
11377
|
-
pending.navigationAcknowledged = true;
|
|
11378
|
-
if (pending.resultAcknowledged && pending.navigationAcknowledged) {
|
|
11379
|
-
this.clearPendingActionExecution(pending);
|
|
11380
|
-
}
|
|
11381
|
-
return true;
|
|
12262
|
+
return false;
|
|
11382
12263
|
});
|
|
11383
12264
|
}
|
|
11384
12265
|
pendingNavigationPayloadMatchesGrant(pending) {
|
|
@@ -11427,12 +12308,25 @@ class AiLiveAssist {
|
|
|
11427
12308
|
this.view?.showActionState("unconfirmed");
|
|
11428
12309
|
return true;
|
|
11429
12310
|
}
|
|
12311
|
+
if (pending.deferredNavigationPath !== null &&
|
|
12312
|
+
pending.navigationAcknowledged &&
|
|
12313
|
+
pending.readyState === null) {
|
|
12314
|
+
const ready = await this.waitForActionExecutionReady(pending);
|
|
12315
|
+
if (this.pendingNavigationActionResult !== pending)
|
|
12316
|
+
return true;
|
|
12317
|
+
if (ready?.state !== "already_started")
|
|
12318
|
+
return false;
|
|
12319
|
+
}
|
|
11430
12320
|
if (!pending.result) {
|
|
11431
12321
|
const ready = await this.waitForActionExecutionReady(pending);
|
|
11432
12322
|
if (this.pendingNavigationActionResult !== pending)
|
|
11433
12323
|
return true;
|
|
11434
12324
|
if (!ready)
|
|
11435
12325
|
return false;
|
|
12326
|
+
if (pending.deferredNavigationPath !== null &&
|
|
12327
|
+
!pending.navigationAcknowledged) {
|
|
12328
|
+
return false;
|
|
12329
|
+
}
|
|
11436
12330
|
pending.result = this.unconfirmedActionExecutionResult(pending);
|
|
11437
12331
|
this.persistPendingActionExecution(pending);
|
|
11438
12332
|
}
|
|
@@ -11463,6 +12357,7 @@ class AiLiveAssist {
|
|
|
11463
12357
|
}
|
|
11464
12358
|
}
|
|
11465
12359
|
if (!pending.resultAcknowledged) {
|
|
12360
|
+
pending.resultDeliveryAttempted = true;
|
|
11466
12361
|
const resultMessageId = this.send("action.result", pending.result, pending.resultMessageId);
|
|
11467
12362
|
if (resultMessageId) {
|
|
11468
12363
|
acknowledgements.push(this.observePendingNavigationAck(pending, "result", channel, resultMessageId, channel.lastClientSequence));
|
|
@@ -11486,8 +12381,11 @@ class AiLiveAssist {
|
|
|
11486
12381
|
},
|
|
11487
12382
|
};
|
|
11488
12383
|
}
|
|
11489
|
-
navigateTo(url) {
|
|
11490
|
-
|
|
12384
|
+
async navigateTo(url) {
|
|
12385
|
+
const context = this.context;
|
|
12386
|
+
if (!context)
|
|
12387
|
+
return false;
|
|
12388
|
+
return (await context.activateReleasedNavigation(url)) === "settled";
|
|
11491
12389
|
}
|
|
11492
12390
|
pruneCompletedActionGrants(now = Date.now()) {
|
|
11493
12391
|
for (const [key, entry] of this.completedActionGrants) {
|
|
@@ -11646,7 +12544,7 @@ class AiLiveAssist {
|
|
|
11646
12544
|
return;
|
|
11647
12545
|
}
|
|
11648
12546
|
if (outcome.status === "explicit_error") {
|
|
11649
|
-
this.
|
|
12547
|
+
this.presentSessionError(outcome.message, false);
|
|
11650
12548
|
}
|
|
11651
12549
|
}
|
|
11652
12550
|
parseGrant(payload, requireCurrentAuthority = true) {
|
|
@@ -11812,22 +12710,179 @@ class AiLiveAssist {
|
|
|
11812
12710
|
: this.mode === "voice"
|
|
11813
12711
|
? "active"
|
|
11814
12712
|
: "unavailable",
|
|
11815
|
-
playback: this.
|
|
12713
|
+
playback: this.advertisedMediaPlaybackState(),
|
|
11816
12714
|
captions: true,
|
|
11817
12715
|
});
|
|
11818
12716
|
}
|
|
12717
|
+
advertisedMediaPlaybackState(mode = this.mode) {
|
|
12718
|
+
// This is the visitor's explicit Voice authorization, not evidence that
|
|
12719
|
+
// remote audio is already audible. Protocol v2 reports actual playback
|
|
12720
|
+
// separately through playback.state before the UI can show Speaking.
|
|
12721
|
+
return mode === "voice" ? "active" : "paused";
|
|
12722
|
+
}
|
|
12723
|
+
flushPlaybackState() {
|
|
12724
|
+
const pending = this.pendingPlaybackState;
|
|
12725
|
+
const result = this.result;
|
|
12726
|
+
const channel = this.channel;
|
|
12727
|
+
if (!pending || !result)
|
|
12728
|
+
return;
|
|
12729
|
+
if (result.protocolVersion !== 2) {
|
|
12730
|
+
this.pendingPlaybackState = null;
|
|
12731
|
+
return;
|
|
12732
|
+
}
|
|
12733
|
+
if (!channel?.hasFencedAuthority)
|
|
12734
|
+
return;
|
|
12735
|
+
if (this.send("playback.state", pending) &&
|
|
12736
|
+
this.pendingPlaybackState === pending) {
|
|
12737
|
+
this.pendingPlaybackState = null;
|
|
12738
|
+
}
|
|
12739
|
+
}
|
|
11819
12740
|
interrupt() {
|
|
11820
12741
|
if (this.mode !== "voice")
|
|
11821
12742
|
return;
|
|
12743
|
+
const barrier = { operation: null };
|
|
12744
|
+
this.voicePlaybackInterruptBarrier = barrier;
|
|
12745
|
+
this.invalidateVoicePlaybackRearm();
|
|
12746
|
+
if (this.view instanceof ui_js_1.WidgetView)
|
|
12747
|
+
this.view.interruptPlayback();
|
|
11822
12748
|
this.presentation?.clear("all");
|
|
11823
|
-
this.
|
|
12749
|
+
this.stopManualPushToTalk(false);
|
|
12750
|
+
const channel = this.channel;
|
|
12751
|
+
const sessionId = this.result?.sessionId;
|
|
12752
|
+
const messageId = this.send("session.interrupt", {});
|
|
12753
|
+
if (messageId &&
|
|
12754
|
+
channel &&
|
|
12755
|
+
sessionId &&
|
|
12756
|
+
this.channel === channel &&
|
|
12757
|
+
this.voicePlaybackInterruptBarrier === barrier &&
|
|
12758
|
+
Number.isSafeInteger(channel.lastClientSequence) &&
|
|
12759
|
+
channel.lastClientSequence > 0) {
|
|
12760
|
+
barrier.operation = {
|
|
12761
|
+
channel,
|
|
12762
|
+
fencingToken: channel.leaseToken,
|
|
12763
|
+
sessionId,
|
|
12764
|
+
messageId,
|
|
12765
|
+
clientSequence: channel.lastClientSequence,
|
|
12766
|
+
interruptedSequence: null,
|
|
12767
|
+
};
|
|
12768
|
+
}
|
|
12769
|
+
}
|
|
12770
|
+
observeVoicePlaybackInterrupt(message) {
|
|
12771
|
+
const operation = this.voicePlaybackInterruptBarrier?.operation;
|
|
12772
|
+
if (!operation ||
|
|
12773
|
+
this.channel !== operation.channel ||
|
|
12774
|
+
!this.channel.hasFencedAuthority ||
|
|
12775
|
+
this.channel.leaseToken !== operation.fencingToken ||
|
|
12776
|
+
this.result?.sessionId !== operation.sessionId ||
|
|
12777
|
+
message.sessionId !== operation.sessionId ||
|
|
12778
|
+
!Number.isSafeInteger(message.sequence) ||
|
|
12779
|
+
message.sequence <= 0)
|
|
12780
|
+
return;
|
|
12781
|
+
if (message.type === "assistant.interrupted") {
|
|
12782
|
+
operation.interruptedSequence = message.sequence;
|
|
12783
|
+
return;
|
|
12784
|
+
}
|
|
12785
|
+
if (message.type !== "ack" ||
|
|
12786
|
+
message.payload.messageId !== operation.messageId ||
|
|
12787
|
+
message.payload.sequence !== operation.clientSequence ||
|
|
12788
|
+
operation.interruptedSequence === null ||
|
|
12789
|
+
message.sequence <= operation.interruptedSequence)
|
|
12790
|
+
return;
|
|
12791
|
+
// This only opens admission. Frames queued before the exact Stop ACK
|
|
12792
|
+
// cannot count as a fresh visitor turn, and the ACK never resumes audio.
|
|
12793
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
12794
|
+
this.voicePlaybackAdmissionAfterSequence = message.sequence;
|
|
12795
|
+
this.invalidateVoicePlaybackRearm();
|
|
12796
|
+
}
|
|
12797
|
+
invalidateVoicePlaybackRearm() {
|
|
12798
|
+
this.voicePlaybackInterruptionGeneration =
|
|
12799
|
+
(this.voicePlaybackInterruptionGeneration ?? 0) + 1;
|
|
12800
|
+
this.voicePlaybackRearm = null;
|
|
12801
|
+
}
|
|
12802
|
+
currentVoicePlaybackIngress(message) {
|
|
12803
|
+
const ingress = this.voicePlaybackIngress?.get(message);
|
|
12804
|
+
if (!ingress ||
|
|
12805
|
+
this.voicePlaybackInterruptBarrier ||
|
|
12806
|
+
!(this.view instanceof ui_js_1.WidgetView) ||
|
|
12807
|
+
this.mode !== "voice" ||
|
|
12808
|
+
this.lifecyclePhase !== "active_voice" ||
|
|
12809
|
+
this.ended ||
|
|
12810
|
+
this.destroyed ||
|
|
12811
|
+
this.terminalRequestPending ||
|
|
12812
|
+
!this.channel?.hasFencedAuthority ||
|
|
12813
|
+
!this.hadFencedAuthorityAtIngress(message) ||
|
|
12814
|
+
ingress.channel !== this.channel ||
|
|
12815
|
+
ingress.fencingToken !== this.channel.leaseToken ||
|
|
12816
|
+
ingress.generation !== this.voicePlaybackInterruptionGeneration ||
|
|
12817
|
+
message.sessionId !== this.result?.sessionId ||
|
|
12818
|
+
!Number.isSafeInteger(message.sequence) ||
|
|
12819
|
+
message.sequence <= 0)
|
|
12820
|
+
return null;
|
|
12821
|
+
return { ...ingress, channel: this.channel };
|
|
12822
|
+
}
|
|
12823
|
+
admitVoicePlaybackTurn(message) {
|
|
12824
|
+
const ingress = this.currentVoicePlaybackIngress(message);
|
|
12825
|
+
if (!ingress ||
|
|
12826
|
+
message.sequence <= (this.voicePlaybackAdmissionAfterSequence ?? 0))
|
|
12827
|
+
return;
|
|
12828
|
+
this.voicePlaybackRearm = {
|
|
12829
|
+
...ingress,
|
|
12830
|
+
sessionId: message.sessionId,
|
|
12831
|
+
visitorSequence: message.sequence,
|
|
12832
|
+
};
|
|
12833
|
+
}
|
|
12834
|
+
hasAdmittedVoicePlaybackTurn(message) {
|
|
12835
|
+
// The durable turn event namespace is shared by protocol v1 and v2. Keep
|
|
12836
|
+
// the legacy/no-ledger confirmation interruption behavior unchanged.
|
|
12837
|
+
if (!message ||
|
|
12838
|
+
!/^turn_visitor_[a-f0-9]{64}$/u.test(message.id) ||
|
|
12839
|
+
!this.currentVoicePlaybackIngress(message))
|
|
12840
|
+
return false;
|
|
12841
|
+
return (this.voicePlaybackRearm?.sessionId === message.sessionId &&
|
|
12842
|
+
this.voicePlaybackRearm.visitorSequence === message.sequence);
|
|
12843
|
+
}
|
|
12844
|
+
resumeInterruptedVoicePlayback(message) {
|
|
12845
|
+
const ingress = this.currentVoicePlaybackIngress(message), rearm = this.voicePlaybackRearm;
|
|
12846
|
+
if (!ingress ||
|
|
12847
|
+
!rearm ||
|
|
12848
|
+
!(this.view instanceof ui_js_1.WidgetView) ||
|
|
12849
|
+
message.payload.cause !== undefined ||
|
|
12850
|
+
rearm.generation !== ingress.generation ||
|
|
12851
|
+
rearm.channel !== ingress.channel ||
|
|
12852
|
+
rearm.fencingToken !== ingress.fencingToken ||
|
|
12853
|
+
rearm.sessionId !== message.sessionId ||
|
|
12854
|
+
message.sequence <= rearm.visitorSequence)
|
|
12855
|
+
return;
|
|
12856
|
+
this.voicePlaybackRearm = null;
|
|
12857
|
+
this.view.resumeInterruptedPlayback();
|
|
12858
|
+
}
|
|
12859
|
+
stopManualPushToTalk(discardProviderBuffer) {
|
|
12860
|
+
const wasActive = this.pushActive || Boolean(this.manualPushRequest);
|
|
12861
|
+
this.manualPushRequest = null;
|
|
12862
|
+
this.media?.endPushToTalk?.();
|
|
11824
12863
|
this.pushActive = false;
|
|
11825
|
-
this.view?.setPushActive(false);
|
|
11826
|
-
|
|
12864
|
+
this.view?.setPushActive?.(false);
|
|
12865
|
+
if (discardProviderBuffer && wasActive) {
|
|
12866
|
+
this.send("session.interrupt", {});
|
|
12867
|
+
}
|
|
12868
|
+
}
|
|
12869
|
+
presentSessionError(message, retryable = false, sessionActive) {
|
|
12870
|
+
// An error surface hides every manual-turn control. Establish the matching
|
|
12871
|
+
// controller/media invariant first so no microphone capture can continue
|
|
12872
|
+
// invisibly behind the compact error card.
|
|
12873
|
+
this.stopManualPushToTalk(true);
|
|
12874
|
+
if (sessionActive === undefined) {
|
|
12875
|
+
this.view?.showError(message, retryable);
|
|
12876
|
+
}
|
|
12877
|
+
else {
|
|
12878
|
+
this.view?.showError(message, retryable, sessionActive);
|
|
12879
|
+
}
|
|
11827
12880
|
}
|
|
11828
12881
|
updateVoiceTurnMode(manual) {
|
|
11829
12882
|
if (this.mode !== "voice" || !this.channel?.isOpen)
|
|
11830
12883
|
return;
|
|
12884
|
+
if (manual && this.bootstrap?.voice?.turnMode !== "manual")
|
|
12885
|
+
return;
|
|
11831
12886
|
if (!manual && this.bootstrap?.voice?.turnMode === "manual")
|
|
11832
12887
|
return;
|
|
11833
12888
|
if (this.pushActive) {
|
|
@@ -11842,16 +12897,47 @@ class AiLiveAssist {
|
|
|
11842
12897
|
return;
|
|
11843
12898
|
}
|
|
11844
12899
|
if (active) {
|
|
12900
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1) {
|
|
12901
|
+
if (this.pushActive || this.currentManualPushRequest())
|
|
12902
|
+
return;
|
|
12903
|
+
const channel = this.channel, sessionId = this.result?.sessionId;
|
|
12904
|
+
if (!sessionId || !channel.hasFencedAuthority || !channel.leaseToken ||
|
|
12905
|
+
this.ended || this.destroyed || this.terminalRequestPending ||
|
|
12906
|
+
this.view?.setPushPending(true) === false)
|
|
12907
|
+
return;
|
|
12908
|
+
const id = randomId("voice_start");
|
|
12909
|
+
const request = {
|
|
12910
|
+
id, channel, sessionId, fencingToken: channel.leaseToken,
|
|
12911
|
+
effectGeneration: this.sessionEffectGeneration,
|
|
12912
|
+
sequence: channel.lastClientSequence + 1,
|
|
12913
|
+
state: "pending",
|
|
12914
|
+
};
|
|
12915
|
+
this.manualPushRequest = request;
|
|
12916
|
+
if (this.send("voice.push.start", { requestId: id }, id) !== id)
|
|
12917
|
+
this.stopManualPushToTalk(false);
|
|
12918
|
+
return;
|
|
12919
|
+
}
|
|
11845
12920
|
if (!this.pushActive)
|
|
11846
12921
|
this.send("voice.push.start", {});
|
|
11847
12922
|
return;
|
|
11848
12923
|
}
|
|
12924
|
+
const request = this.currentManualPushRequest();
|
|
12925
|
+
if (request?.state === "pending") {
|
|
12926
|
+
this.stopManualPushToTalk(true);
|
|
12927
|
+
return;
|
|
12928
|
+
}
|
|
11849
12929
|
if (!this.pushActive)
|
|
11850
12930
|
return;
|
|
11851
|
-
this.
|
|
11852
|
-
this.
|
|
11853
|
-
|
|
11854
|
-
|
|
12931
|
+
this.stopManualPushToTalk(false);
|
|
12932
|
+
this.send("voice.push.commit", request ? { requestId: request.id } : {});
|
|
12933
|
+
}
|
|
12934
|
+
currentManualPushRequest() {
|
|
12935
|
+
const request = this.manualPushRequest;
|
|
12936
|
+
return request && this.manualTurn && this.mode === "voice" &&
|
|
12937
|
+
this.lifecyclePhase === "active_voice" && !this.ended && !this.destroyed && !this.terminalRequestPending &&
|
|
12938
|
+
request.channel === this.channel && request.sessionId === this.result?.sessionId &&
|
|
12939
|
+
request.fencingToken === this.channel?.leaseToken && this.channel?.hasFencedAuthority &&
|
|
12940
|
+
request.effectGeneration === this.sessionEffectGeneration ? request : null;
|
|
11855
12941
|
}
|
|
11856
12942
|
pauseCommandKey(command) {
|
|
11857
12943
|
return `${command.operationId}\u0000${command.clientSequence}\u0000${command.fencingToken}`;
|
|
@@ -12000,6 +13086,10 @@ class AiLiveAssist {
|
|
|
12000
13086
|
(this.authoritativePauseStateByChannel ?? (this.authoritativePauseStateByChannel = new WeakMap())).set(channel, state);
|
|
12001
13087
|
}
|
|
12002
13088
|
if (state === "paused") {
|
|
13089
|
+
// A fenced server pause may arrive independently of the local pause
|
|
13090
|
+
// button (for example after outside-page interaction). Stop browser
|
|
13091
|
+
// capture without issuing another control command into a paused session.
|
|
13092
|
+
this.stopManualPushToTalk(false);
|
|
12003
13093
|
this.view?.setPaused(true);
|
|
12004
13094
|
if (this.lifecyclePhase !== "paused")
|
|
12005
13095
|
this.state("paused");
|
|
@@ -12072,6 +13162,17 @@ class AiLiveAssist {
|
|
|
12072
13162
|
async performPauseCommand(paused, rollbackState) {
|
|
12073
13163
|
if (this.terminalRequestPending || this.ended || this.destroyed)
|
|
12074
13164
|
return;
|
|
13165
|
+
if (paused) {
|
|
13166
|
+
// Controller-originated pauses bypass WidgetView's release callback.
|
|
13167
|
+
// Discard any in-flight manual turn before the first await so capture
|
|
13168
|
+
// cannot remain live behind a paused or transitioning surface.
|
|
13169
|
+
this.stopManualPushToTalk(true);
|
|
13170
|
+
// Make the pause intent visible synchronously. This also prevents an
|
|
13171
|
+
// already-queued voice.push.ready frame from reopening capture while
|
|
13172
|
+
// the authoritative pause command is in flight. Rollback below restores
|
|
13173
|
+
// the prior ready state if the pause is rejected.
|
|
13174
|
+
this.view?.setPaused(true);
|
|
13175
|
+
}
|
|
12075
13176
|
const commandGeneration = (Number.isSafeInteger(this.pauseCommandGeneration)
|
|
12076
13177
|
? this.pauseCommandGeneration
|
|
12077
13178
|
: 0) + 1;
|
|
@@ -12096,7 +13197,7 @@ class AiLiveAssist {
|
|
|
12096
13197
|
else
|
|
12097
13198
|
this.view?.setPaused(!paused);
|
|
12098
13199
|
if (message)
|
|
12099
|
-
this.
|
|
13200
|
+
this.presentSessionError(message, false);
|
|
12100
13201
|
};
|
|
12101
13202
|
if (!result || !channel || fencingToken <= 0) {
|
|
12102
13203
|
rollback();
|
|
@@ -12212,7 +13313,7 @@ class AiLiveAssist {
|
|
|
12212
13313
|
await this.flushPendingPageAssistanceRevocation();
|
|
12213
13314
|
}
|
|
12214
13315
|
pageAssistanceRevocationStorageKey() {
|
|
12215
|
-
return `${PAGE_ASSISTANCE_REVOCATION_STORAGE_PREFIX}${this.siteKey}`;
|
|
13316
|
+
return `${PAGE_ASSISTANCE_REVOCATION_STORAGE_PREFIX}${this.storageNamespace ?? this.siteKey}`;
|
|
12216
13317
|
}
|
|
12217
13318
|
rememberPendingPageAssistanceRevocation(saved) {
|
|
12218
13319
|
const existing = this.restorePendingPageAssistanceRevocation();
|
|
@@ -12349,7 +13450,7 @@ class AiLiveAssist {
|
|
|
12349
13450
|
return this.finalizePageAssistanceRevocation(pending);
|
|
12350
13451
|
}
|
|
12351
13452
|
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
12352
|
-
this.
|
|
13453
|
+
this.presentSessionError(outcome.message, false);
|
|
12353
13454
|
return false;
|
|
12354
13455
|
}
|
|
12355
13456
|
if (this.controlOutcomeNeedsRetry(outcome))
|
|
@@ -12422,7 +13523,7 @@ class AiLiveAssist {
|
|
|
12422
13523
|
updateCaptions(enabled) {
|
|
12423
13524
|
this.send("media.state", {
|
|
12424
13525
|
microphone: this.mode === "voice" ? "active" : "unavailable",
|
|
12425
|
-
playback: this.
|
|
13526
|
+
playback: this.advertisedMediaPlaybackState(),
|
|
12426
13527
|
captions: enabled,
|
|
12427
13528
|
});
|
|
12428
13529
|
}
|
|
@@ -12439,6 +13540,8 @@ class AiLiveAssist {
|
|
|
12439
13540
|
}
|
|
12440
13541
|
}
|
|
12441
13542
|
setModeTransitionPending(mode) {
|
|
13543
|
+
if (mode)
|
|
13544
|
+
this.clearCtaAuthority();
|
|
12442
13545
|
if (this.view instanceof ui_js_1.WidgetView) {
|
|
12443
13546
|
this.view.setModeTransitionPending(mode);
|
|
12444
13547
|
}
|
|
@@ -12749,7 +13852,7 @@ class AiLiveAssist {
|
|
|
12749
13852
|
];
|
|
12750
13853
|
await this.waitForModeUpgradeConnectionDeadline(this.updateModeUpgradeConsent(attempt, requestedScopes), attempt);
|
|
12751
13854
|
this.assertModeUpgradeCurrent(attempt);
|
|
12752
|
-
|
|
13855
|
+
while ((this.pendingContextNavigationAcknowledgements?.size ?? 0) > 0) {
|
|
12753
13856
|
const navigationAcknowledged = await this.waitForModeUpgradeConnectionDeadline(this.waitForPendingContextNavigationAcknowledgements(), attempt);
|
|
12754
13857
|
this.assertModeUpgradeCurrent(attempt);
|
|
12755
13858
|
if (!navigationAcknowledged) {
|
|
@@ -12812,7 +13915,7 @@ class AiLiveAssist {
|
|
|
12812
13915
|
return;
|
|
12813
13916
|
}
|
|
12814
13917
|
this.clearModeUpgradeAttempt(false);
|
|
12815
|
-
this.
|
|
13918
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, true);
|
|
12816
13919
|
this.state("error");
|
|
12817
13920
|
return;
|
|
12818
13921
|
}
|
|
@@ -13044,7 +14147,7 @@ class AiLiveAssist {
|
|
|
13044
14147
|
return true;
|
|
13045
14148
|
}
|
|
13046
14149
|
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
13047
|
-
this.
|
|
14150
|
+
this.presentSessionError(outcome.message, false);
|
|
13048
14151
|
queueMicrotask(() => this.endFailedModeUpgradeInBackground());
|
|
13049
14152
|
}
|
|
13050
14153
|
return false;
|
|
@@ -13337,7 +14440,7 @@ class AiLiveAssist {
|
|
|
13337
14440
|
this.scheduleReconnect(true);
|
|
13338
14441
|
}
|
|
13339
14442
|
else if (outcome.status === "explicit_error") {
|
|
13340
|
-
this.
|
|
14443
|
+
this.presentSessionError(outcome.message, outcome.retryable);
|
|
13341
14444
|
}
|
|
13342
14445
|
return;
|
|
13343
14446
|
}
|
|
@@ -13391,7 +14494,7 @@ class AiLiveAssist {
|
|
|
13391
14494
|
this.clearReconnectTimer();
|
|
13392
14495
|
if (this.messengerReturnRetryRemaining !== null) {
|
|
13393
14496
|
if (!this.lastLaunch || this.messengerReturnRetryRemaining <= 0) {
|
|
13394
|
-
this.
|
|
14497
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
13395
14498
|
return;
|
|
13396
14499
|
}
|
|
13397
14500
|
this.messengerReturnRetryRemaining -= 1;
|
|
@@ -13405,7 +14508,7 @@ class AiLiveAssist {
|
|
|
13405
14508
|
!this.ended &&
|
|
13406
14509
|
this.messengerReturnRetryRemaining === 0 &&
|
|
13407
14510
|
this.lastLaunch) {
|
|
13408
|
-
this.
|
|
14511
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
13409
14512
|
}
|
|
13410
14513
|
});
|
|
13411
14514
|
}
|
|
@@ -13415,10 +14518,21 @@ class AiLiveAssist {
|
|
|
13415
14518
|
return this.resume(resume);
|
|
13416
14519
|
}
|
|
13417
14520
|
if (this.lastLaunch) {
|
|
13418
|
-
|
|
14521
|
+
if (this.visitorActiveTakeoverOnly) {
|
|
14522
|
+
// A deliberate retry gets one fresh bounded eligibility check. The
|
|
14523
|
+
// key still prevents accidental automatic replay loops.
|
|
14524
|
+
this.visitorActiveEligibilityRecheckKey = null;
|
|
14525
|
+
}
|
|
14526
|
+
return this.launch(this.lastLaunch.mode, this.lastLaunch.scopes, this.lastLaunch.idempotencyKey, {
|
|
14527
|
+
pendingLaunch: this.lastLaunch,
|
|
14528
|
+
...(this.pendingQuestion
|
|
14529
|
+
? { admittedQuestion: this.pendingQuestion }
|
|
14530
|
+
: {}),
|
|
14531
|
+
});
|
|
13419
14532
|
}
|
|
13420
14533
|
}
|
|
13421
14534
|
scheduleReconnect(force = false) {
|
|
14535
|
+
this.clearCtaAuthority();
|
|
13422
14536
|
if (this.ended ||
|
|
13423
14537
|
this.destroyed ||
|
|
13424
14538
|
this.terminalRequestPending ||
|
|
@@ -13481,7 +14595,7 @@ class AiLiveAssist {
|
|
|
13481
14595
|
this.state("ready");
|
|
13482
14596
|
}
|
|
13483
14597
|
else {
|
|
13484
|
-
this.
|
|
14598
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false);
|
|
13485
14599
|
this.state("error");
|
|
13486
14600
|
}
|
|
13487
14601
|
return;
|
|
@@ -13503,7 +14617,7 @@ class AiLiveAssist {
|
|
|
13503
14617
|
this.state("reconnecting");
|
|
13504
14618
|
}
|
|
13505
14619
|
else {
|
|
13506
|
-
this.
|
|
14620
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false);
|
|
13507
14621
|
this.state("error");
|
|
13508
14622
|
}
|
|
13509
14623
|
return;
|
|
@@ -13799,12 +14913,82 @@ class AiLiveAssist {
|
|
|
13799
14913
|
beginConnectionAttempt(controller) {
|
|
13800
14914
|
this.connectionAbort?.abort();
|
|
13801
14915
|
this.connectionAbort = controller;
|
|
14916
|
+
// A media-element event from a failed attempt must never cross the next
|
|
14917
|
+
// connection fence. The new attempt will report its own observed state.
|
|
14918
|
+
this.pendingPlaybackState = null;
|
|
13802
14919
|
this.connectionGeneration =
|
|
13803
14920
|
(Number.isSafeInteger(this.connectionGeneration)
|
|
13804
14921
|
? this.connectionGeneration
|
|
13805
14922
|
: 0) + 1;
|
|
13806
14923
|
return this.connectionGeneration;
|
|
13807
14924
|
}
|
|
14925
|
+
savedGuidePendingLaunch() {
|
|
14926
|
+
const intent = this.guideAdmission?.pendingIntent();
|
|
14927
|
+
return intent ? {
|
|
14928
|
+
mode: intent.mode,
|
|
14929
|
+
scopes: [...intent.consent.scopes],
|
|
14930
|
+
idempotencyKey: `launch_${intent.launchRequestId}`,
|
|
14931
|
+
protocolVersion: 2,
|
|
14932
|
+
experienceMode: "standard",
|
|
14933
|
+
} : null;
|
|
14934
|
+
}
|
|
14935
|
+
async requestBootstrap(signal) {
|
|
14936
|
+
if (!this.guideAdmission) {
|
|
14937
|
+
return this.runtime.bootstrap(this.siteKey, path(), this.visitorId(), this.locale, signal);
|
|
14938
|
+
}
|
|
14939
|
+
const bootstrap = await this.guideAdmission.bootstrap(path(), this.locale, signal);
|
|
14940
|
+
// Replay-dependent Messenger continuity is unavailable until the server
|
|
14941
|
+
// validates a real optional recording link. Never borrow another recorder.
|
|
14942
|
+
const safe = { ...bootstrap };
|
|
14943
|
+
if (safe.consent) {
|
|
14944
|
+
safe.consent = { ...safe.consent,
|
|
14945
|
+
requiredScopes: safe.consent.requiredScopes.filter(scope => scope !== "session_recording"),
|
|
14946
|
+
optionalScopes: safe.consent.optionalScopes.filter(scope => scope !== "session_recording" || this.guideAdmission?.recordingConfigured === true),
|
|
14947
|
+
};
|
|
14948
|
+
}
|
|
14949
|
+
delete safe.companion;
|
|
14950
|
+
delete safe.messengerConversation;
|
|
14951
|
+
delete safe.humanHandoffRecovery;
|
|
14952
|
+
if (safe.capabilities)
|
|
14953
|
+
safe.capabilities = { ...safe.capabilities, handoff: false };
|
|
14954
|
+
if (safe.appearance) {
|
|
14955
|
+
safe.appearance = { ...safe.appearance };
|
|
14956
|
+
delete safe.appearance.messengerCompanion;
|
|
14957
|
+
}
|
|
14958
|
+
return safe;
|
|
14959
|
+
}
|
|
14960
|
+
sessionConnectionScope() {
|
|
14961
|
+
return this.guideAdmission
|
|
14962
|
+
? Promise.resolve(this.guideAdmission.connectionScope())
|
|
14963
|
+
: this.replayReadiness.wait();
|
|
14964
|
+
}
|
|
14965
|
+
assertSessionConnectionScope(scope) {
|
|
14966
|
+
if ("kind" in scope && scope.kind === "guide_subject_v2") {
|
|
14967
|
+
scope.assertCurrent();
|
|
14968
|
+
}
|
|
14969
|
+
else {
|
|
14970
|
+
this.replayReadiness.assertCurrent(scope);
|
|
14971
|
+
}
|
|
14972
|
+
}
|
|
14973
|
+
requestLaunch(input, scope, signal) {
|
|
14974
|
+
if (this.guideAdmission) {
|
|
14975
|
+
return this.guideAdmission.launch(input, signal).then((result) => {
|
|
14976
|
+
if (this.bootstrap)
|
|
14977
|
+
this.initializePageAssistancePreference(this.bootstrap);
|
|
14978
|
+
return result;
|
|
14979
|
+
});
|
|
14980
|
+
}
|
|
14981
|
+
return this.runtime.launch({
|
|
14982
|
+
...input,
|
|
14983
|
+
siteKey: this.siteKey,
|
|
14984
|
+
anonymousId: this.visitorId(),
|
|
14985
|
+
replay: scope,
|
|
14986
|
+
}, signal);
|
|
14987
|
+
}
|
|
14988
|
+
matchesLaunchSchema(result, protocolVersion) {
|
|
14989
|
+
return result.schemaVersion === protocolVersion ||
|
|
14990
|
+
(Boolean(this.guideAdmission) && protocolVersion === 2 && result.schemaVersion === 3);
|
|
14991
|
+
}
|
|
13808
14992
|
assertConnectionCurrent(controller, generation, replay, messengerReturnAuthority, mode, launchIdempotencyKey) {
|
|
13809
14993
|
if (controller.signal.aborted ||
|
|
13810
14994
|
this.destroyed ||
|
|
@@ -13816,7 +15000,7 @@ class AiLiveAssist {
|
|
|
13816
15000
|
generation !== this.connectionGeneration) {
|
|
13817
15001
|
throw new DOMException("The operation was aborted.", "AbortError");
|
|
13818
15002
|
}
|
|
13819
|
-
this.
|
|
15003
|
+
this.assertSessionConnectionScope(replay);
|
|
13820
15004
|
}
|
|
13821
15005
|
messengerReturnLaunchIsCurrent(authority, mode, launchIdempotencyKey) {
|
|
13822
15006
|
if (!this.messengerTransferred)
|
|
@@ -13930,6 +15114,7 @@ class AiLiveAssist {
|
|
|
13930
15114
|
});
|
|
13931
15115
|
}
|
|
13932
15116
|
invalidateConnectionAttempt() {
|
|
15117
|
+
this.pendingPlaybackState = null;
|
|
13933
15118
|
this.connectionGeneration =
|
|
13934
15119
|
(Number.isSafeInteger(this.connectionGeneration)
|
|
13935
15120
|
? this.connectionGeneration
|
|
@@ -14025,6 +15210,10 @@ class AiLiveAssist {
|
|
|
14025
15210
|
scopes: [...pending.scopes],
|
|
14026
15211
|
};
|
|
14027
15212
|
}
|
|
15213
|
+
const savedGuideLaunch = this.savedGuidePendingLaunch();
|
|
15214
|
+
if (savedGuideLaunch?.idempotencyKey === intent.launchIdempotencyKey) {
|
|
15215
|
+
this.terminalPendingLaunch = savedGuideLaunch;
|
|
15216
|
+
}
|
|
14028
15217
|
}
|
|
14029
15218
|
if (!this.destroyed) {
|
|
14030
15219
|
this.presentTerminalEnding();
|
|
@@ -14049,6 +15238,12 @@ class AiLiveAssist {
|
|
|
14049
15238
|
const request = this.completeRuntimeEnd().finally(() => {
|
|
14050
15239
|
if (this.terminalRequestInFlight === request) {
|
|
14051
15240
|
this.terminalRequestInFlight = null;
|
|
15241
|
+
const intent = this.terminalEndIntent;
|
|
15242
|
+
if (intent &&
|
|
15243
|
+
intent.retryUntil <= Date.now() &&
|
|
15244
|
+
this.terminalRequestPending) {
|
|
15245
|
+
this.presentTerminalRetry();
|
|
15246
|
+
}
|
|
14052
15247
|
}
|
|
14053
15248
|
});
|
|
14054
15249
|
this.terminalRequestInFlight = request;
|
|
@@ -14084,6 +15279,7 @@ class AiLiveAssist {
|
|
|
14084
15279
|
finishFromServer(reasonCode, sessionId) {
|
|
14085
15280
|
if (this.ended || this.terminalDeliveryRelinquished)
|
|
14086
15281
|
return;
|
|
15282
|
+
this.guideAdmission?.complete();
|
|
14087
15283
|
this.cancelMessengerTransferForTerminalPresentation();
|
|
14088
15284
|
const returnToTextEntry = this.modeUpgradeReturnToTextEntry || Boolean(this.pendingModeUpgrade);
|
|
14089
15285
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -14135,7 +15331,7 @@ class AiLiveAssist {
|
|
|
14135
15331
|
const expectedExperienceMode = sourceRecord?.experienceMode ??
|
|
14136
15332
|
pendingLaunch?.experienceMode ??
|
|
14137
15333
|
result.experienceMode;
|
|
14138
|
-
if (result
|
|
15334
|
+
if (!this.matchesLaunchSchema(result, expectedProtocolVersion) ||
|
|
14139
15335
|
result.protocolVersion !== expectedProtocolVersion ||
|
|
14140
15336
|
result.experienceMode !== expectedExperienceMode ||
|
|
14141
15337
|
(sourceRecord &&
|
|
@@ -14146,6 +15342,8 @@ class AiLiveAssist {
|
|
|
14146
15342
|
const currentIntent = this.terminalEndIntent;
|
|
14147
15343
|
if (!currentIntent)
|
|
14148
15344
|
return false;
|
|
15345
|
+
const previousResumeRecord = this.terminalResumeRecord;
|
|
15346
|
+
const previousStoredResume = this.readResume();
|
|
14149
15347
|
const authoritativeExpiry = result.resumeExpiresAt
|
|
14150
15348
|
? Date.parse(result.resumeExpiresAt)
|
|
14151
15349
|
: Date.now() + STORAGE_TTL_MS;
|
|
@@ -14154,16 +15352,39 @@ class AiLiveAssist {
|
|
|
14154
15352
|
sessionId: result.sessionId,
|
|
14155
15353
|
retryUntil: Math.min(currentIntent.retryUntil, authoritativeExpiry),
|
|
14156
15354
|
};
|
|
15355
|
+
const rollbackCapture = () => {
|
|
15356
|
+
this.terminalEndIntent = currentIntent;
|
|
15357
|
+
this.terminalResumeRecord = previousResumeRecord;
|
|
15358
|
+
if (canonicalJson(this.readTerminalEndIntent()) === canonicalJson(intent)) {
|
|
15359
|
+
this.persistTerminalEndIntent(currentIntent);
|
|
15360
|
+
const storedResume = this.readResume();
|
|
15361
|
+
if (previousStoredResume &&
|
|
15362
|
+
(!storedResume ||
|
|
15363
|
+
(storedResume.tabId === this.tabId &&
|
|
15364
|
+
storedResume.sessionId === result.sessionId &&
|
|
15365
|
+
storedResume.resumeCredential === result.resumeCredential &&
|
|
15366
|
+
canonicalJson(storedResume.terminalEnd) ===
|
|
15367
|
+
canonicalJson(intent)))) {
|
|
15368
|
+
this.storeResume(previousStoredResume, false);
|
|
15369
|
+
}
|
|
15370
|
+
}
|
|
15371
|
+
return false;
|
|
15372
|
+
};
|
|
14157
15373
|
this.terminalEndIntent = intent;
|
|
14158
|
-
this.persistTerminalEndIntent(intent)
|
|
15374
|
+
if (!this.persistTerminalEndIntent(intent))
|
|
15375
|
+
return rollbackCapture();
|
|
14159
15376
|
const resumedMode = result.mode ?? sourceRecord?.mode ?? this.mode;
|
|
14160
15377
|
const resumedScopes = sourceRecord?.scopes ?? this.scopes;
|
|
14161
15378
|
const stored = this.writeResume(result, resumedMode, resumedScopes, sourceRecord?.visualConsentGranted, sourceRecord?.clientSequence ?? 0, sourceRecord?.modeUpgrade ?? null, sourceRecord?.actionExecution ?? null, sourceRecord?.pauseCommand ?? null, intent);
|
|
14162
|
-
|
|
15379
|
+
if (!stored)
|
|
15380
|
+
return rollbackCapture();
|
|
14163
15381
|
const markedRecord = stored ? this.readResume() : null;
|
|
14164
|
-
if (markedRecord
|
|
14165
|
-
|
|
15382
|
+
if (!markedRecord ||
|
|
15383
|
+
canonicalJson(markedRecord.terminalEnd) !== canonicalJson(intent)) {
|
|
15384
|
+
return rollbackCapture();
|
|
14166
15385
|
}
|
|
15386
|
+
this.result = result;
|
|
15387
|
+
this.terminalResumeRecord = markedRecord;
|
|
14167
15388
|
return true;
|
|
14168
15389
|
}
|
|
14169
15390
|
retryRejectedTerminalAuthorizedResult(result) {
|
|
@@ -14208,6 +15429,13 @@ class AiLiveAssist {
|
|
|
14208
15429
|
}
|
|
14209
15430
|
if (this.result)
|
|
14210
15431
|
return this.finishRuntimeEndAttempt(this.result);
|
|
15432
|
+
// Read/end a standalone unknown outcome through its subject-authorized
|
|
15433
|
+
// ledger. A paid launch must never be replayed merely to discover it.
|
|
15434
|
+
if (this.guideAdmission && this.terminalPendingLaunch && !this.terminalResumeRecord) {
|
|
15435
|
+
const controller = new AbortController();
|
|
15436
|
+
const request = this.guideAdmission.endLaunch(this.terminalPendingLaunch.idempotencyKey, this.tabId, controller.signal);
|
|
15437
|
+
return this.settleRuntimeEndRequest(this.waitForTerminalRequestDeadline(request, controller), null);
|
|
15438
|
+
}
|
|
14211
15439
|
const terminalAuthorization = this.terminalSessionAuthorization;
|
|
14212
15440
|
if (terminalAuthorization) {
|
|
14213
15441
|
return this.waitForTerminalRequestDeadline(terminalAuthorization, this.terminalSessionAuthorizationController).then((authorized) => {
|
|
@@ -14319,14 +15547,17 @@ class AiLiveAssist {
|
|
|
14319
15547
|
? this.refreshTerminalResumeRecord(result.sessionId)
|
|
14320
15548
|
: null;
|
|
14321
15549
|
if (recoveryRecord) {
|
|
14322
|
-
// Once the live request loses its current revision
|
|
14323
|
-
// terminal recovery is the only authoritative delivery path
|
|
15550
|
+
// Once the live request loses its current revision, credential, or
|
|
15551
|
+
// lease, terminal recovery is the only authoritative delivery path
|
|
15552
|
+
// left.
|
|
14324
15553
|
// Re-sending the same direct request before every recovery probe
|
|
14325
15554
|
// creates duplicate pairs and cannot establish convergence.
|
|
14326
|
-
|
|
14327
|
-
|
|
14328
|
-
|
|
14329
|
-
|
|
15555
|
+
// Any failed direct dispatch is ambiguous: the provider may have
|
|
15556
|
+
// accepted it before the response or control acknowledgement was
|
|
15557
|
+
// lost. From this point forward, use only the idempotent
|
|
15558
|
+
// resume-credential recovery route and never race a second direct
|
|
15559
|
+
// terminal mutation.
|
|
15560
|
+
this.terminalRecoveryOnly = true;
|
|
14330
15561
|
return this.requestRecoveryRuntimeEnd(recoveryRecord).then(() => {
|
|
14331
15562
|
if (!this.ended)
|
|
14332
15563
|
this.finishConfirmedRuntimeEnd(result);
|
|
@@ -14358,6 +15589,7 @@ class AiLiveAssist {
|
|
|
14358
15589
|
finishConfirmedRuntimeEnd(result = null) {
|
|
14359
15590
|
if (this.terminalDeliveryRelinquished)
|
|
14360
15591
|
return;
|
|
15592
|
+
this.guideAdmission?.complete();
|
|
14361
15593
|
this.cancelMessengerTransferForTerminalPresentation();
|
|
14362
15594
|
const returnToTextEntry = this.modeUpgradeReturnToTextEntry || Boolean(this.pendingModeUpgrade);
|
|
14363
15595
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -14404,6 +15636,14 @@ class AiLiveAssist {
|
|
|
14404
15636
|
? view.message("handoffEnding")
|
|
14405
15637
|
: undefined);
|
|
14406
15638
|
}
|
|
15639
|
+
presentTerminalRetry() {
|
|
15640
|
+
if (this.destroyed || this.ended || this.terminalDeliveryRelinquished) {
|
|
15641
|
+
return;
|
|
15642
|
+
}
|
|
15643
|
+
this.cleanupTransport();
|
|
15644
|
+
this.view?.showEndRetry();
|
|
15645
|
+
this.state("error");
|
|
15646
|
+
}
|
|
14407
15647
|
retryTerminalEnd(error) {
|
|
14408
15648
|
if (this.ended)
|
|
14409
15649
|
return Promise.resolve();
|
|
@@ -14477,7 +15717,7 @@ class AiLiveAssist {
|
|
|
14477
15717
|
const current = this.bootstrap;
|
|
14478
15718
|
if (current?.configRevision && current.consent)
|
|
14479
15719
|
return current;
|
|
14480
|
-
const bootstrap = await this.
|
|
15720
|
+
const bootstrap = await this.requestBootstrap(signal);
|
|
14481
15721
|
if (!bootstrap.configRevision || !bootstrap.consent) {
|
|
14482
15722
|
throw new client_js_1.RuntimeClientError("INTERNAL_UNAVAILABLE", "Terminal launch recovery metadata is temporarily unavailable.", true, null, 503);
|
|
14483
15723
|
}
|
|
@@ -14528,7 +15768,7 @@ class AiLiveAssist {
|
|
|
14528
15768
|
!this.terminalRequestPending ||
|
|
14529
15769
|
this.terminalEndIntent?.operationId !== intent.operationId ||
|
|
14530
15770
|
intent.retryUntil > Date.now()) {
|
|
14531
|
-
return;
|
|
15771
|
+
return false;
|
|
14532
15772
|
}
|
|
14533
15773
|
this.terminalInitializationDeferred = false;
|
|
14534
15774
|
const clearsAssociatedStorage = this.clearExpiredTerminalRecoveryStorage(intent);
|
|
@@ -14555,6 +15795,7 @@ class AiLiveAssist {
|
|
|
14555
15795
|
}
|
|
14556
15796
|
void this.initialize();
|
|
14557
15797
|
});
|
|
15798
|
+
return true;
|
|
14558
15799
|
}
|
|
14559
15800
|
waitForTerminalRetry(error) {
|
|
14560
15801
|
this.terminalRetryAttempts += 1;
|
|
@@ -14594,6 +15835,7 @@ class AiLiveAssist {
|
|
|
14594
15835
|
});
|
|
14595
15836
|
}
|
|
14596
15837
|
quiesceLocalEffectsForTerminalRequest() {
|
|
15838
|
+
this.clearCtaAuthority();
|
|
14597
15839
|
this.queuedLaunchToken = null;
|
|
14598
15840
|
this.launchGeneration += 1;
|
|
14599
15841
|
this.visitorLimitAbort?.abort();
|
|
@@ -14659,6 +15901,10 @@ class AiLiveAssist {
|
|
|
14659
15901
|
this.messengerOpenAckInFlight = null;
|
|
14660
15902
|
}
|
|
14661
15903
|
cleanupTransport(options = {}) {
|
|
15904
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
15905
|
+
this.voicePlaybackAdmissionAfterSequence = 0;
|
|
15906
|
+
this.invalidateVoicePlaybackRearm();
|
|
15907
|
+
this.clearCtaAuthority();
|
|
14662
15908
|
this.sessionEffectGeneration =
|
|
14663
15909
|
(Number.isSafeInteger(this.sessionEffectGeneration)
|
|
14664
15910
|
? this.sessionEffectGeneration
|
|
@@ -14726,10 +15972,10 @@ class AiLiveAssist {
|
|
|
14726
15972
|
}
|
|
14727
15973
|
let terminalOutcome;
|
|
14728
15974
|
try {
|
|
14729
|
-
terminalOutcome = controlChannel.waitForOutcome(terminalMessageId,
|
|
15975
|
+
terminalOutcome = controlChannel.waitForOutcome(terminalMessageId, 5000, terminalClientSequence);
|
|
14730
15976
|
}
|
|
14731
15977
|
catch {
|
|
14732
|
-
return
|
|
15978
|
+
return Promise.reject(new TerminalControlEndUnconfirmedError());
|
|
14733
15979
|
}
|
|
14734
15980
|
return terminalOutcome.then((outcome) => {
|
|
14735
15981
|
if (outcome.status !== "ack" ||
|
|
@@ -14737,9 +15983,9 @@ class AiLiveAssist {
|
|
|
14737
15983
|
outcome.sequence !== terminalClientSequence ||
|
|
14738
15984
|
this.channel !== controlChannel ||
|
|
14739
15985
|
controlChannel.leaseToken !== fencingToken) {
|
|
14740
|
-
|
|
15986
|
+
throw new TerminalControlEndUnconfirmedError();
|
|
14741
15987
|
}
|
|
14742
|
-
}, () =>
|
|
15988
|
+
}, () => Promise.reject(new TerminalControlEndUnconfirmedError()));
|
|
14743
15989
|
}
|
|
14744
15990
|
requestRecoveryRuntimeEnd(record) {
|
|
14745
15991
|
const controller = new AbortController();
|
|
@@ -14757,6 +16003,9 @@ class AiLiveAssist {
|
|
|
14757
16003
|
});
|
|
14758
16004
|
}
|
|
14759
16005
|
send(type, payload, stableMessageId) {
|
|
16006
|
+
if (this.manualPushRequest && ["session.interrupt", "session.mode", "voice.turn_mode", "session.pause", "session.end", "experience.end"].includes(type)) {
|
|
16007
|
+
this.stopManualPushToTalk(false);
|
|
16008
|
+
}
|
|
14760
16009
|
if (this.terminalRequestPending && type !== "experience.end")
|
|
14761
16010
|
return null;
|
|
14762
16011
|
if (!this.channel?.isOpen)
|
|
@@ -14809,19 +16058,21 @@ class AiLiveAssist {
|
|
|
14809
16058
|
return;
|
|
14810
16059
|
}
|
|
14811
16060
|
const ready = (async () => {
|
|
14812
|
-
const visitorDigest = await (0, pageAssistancePreference_js_1.digestPageAssistanceVisitor)(this.
|
|
16061
|
+
const visitorDigest = await (0, pageAssistancePreference_js_1.digestPageAssistanceVisitor)(this.visitorId());
|
|
14813
16062
|
if (!visitorDigest)
|
|
14814
16063
|
return null;
|
|
14815
16064
|
try {
|
|
14816
16065
|
return new pageAssistancePreference_js_1.PageAssistancePreferenceStore({
|
|
14817
16066
|
origin,
|
|
14818
|
-
|
|
16067
|
+
...(this.guideAdmission
|
|
16068
|
+
? { projectId: this.guideAdmission.identity.projectId, guideId: this.guideAdmission.identity.guideId }
|
|
16069
|
+
: { siteKey: this.siteKey }),
|
|
14819
16070
|
visitorDigest,
|
|
14820
16071
|
schemaVersion: 1,
|
|
14821
16072
|
configRevision: configRevision,
|
|
14822
16073
|
policyVersion: policyVersion,
|
|
14823
16074
|
capability: "browser_control",
|
|
14824
|
-
});
|
|
16075
|
+
}, { storageNamespace: this.storageNamespace });
|
|
14825
16076
|
}
|
|
14826
16077
|
catch {
|
|
14827
16078
|
return null;
|
|
@@ -14884,12 +16135,14 @@ class AiLiveAssist {
|
|
|
14884
16135
|
void this.flushPendingPageAssistanceRevocation();
|
|
14885
16136
|
}
|
|
14886
16137
|
visitorId() {
|
|
14887
|
-
return this.visitorIdentity;
|
|
16138
|
+
return this.guideAdmission ? this.guideAdmission.subjectId() ?? "" : this.visitorIdentity;
|
|
14888
16139
|
}
|
|
14889
16140
|
currentTrackerVisitorIdentity() {
|
|
16141
|
+
if (this.guideAdmission)
|
|
16142
|
+
return null;
|
|
14890
16143
|
try {
|
|
14891
|
-
const
|
|
14892
|
-
const trackerId = typeof
|
|
16144
|
+
const identity = this.host.getVisitorId();
|
|
16145
|
+
const trackerId = typeof identity === "string" ? identity : "";
|
|
14893
16146
|
return PUBLIC_REQUEST_ID_PATTERN.test(trackerId) ? trackerId : null;
|
|
14894
16147
|
}
|
|
14895
16148
|
catch {
|
|
@@ -14968,7 +16221,7 @@ class AiLiveAssist {
|
|
|
14968
16221
|
this.pageAssistanceTrackerRotationPending = false;
|
|
14969
16222
|
}
|
|
14970
16223
|
resolveVisitorId() {
|
|
14971
|
-
const key = `__oxvo_ai_live_assist_visitor_${this.siteKey}`;
|
|
16224
|
+
const key = `__oxvo_ai_live_assist_visitor_${this.storageNamespace ?? this.siteKey}`;
|
|
14972
16225
|
try {
|
|
14973
16226
|
const stored = localStorage.getItem(key) ?? "";
|
|
14974
16227
|
if (PUBLIC_REQUEST_ID_PATTERN.test(stored))
|
|
@@ -14987,6 +16240,138 @@ class AiLiveAssist {
|
|
|
14987
16240
|
return resolved;
|
|
14988
16241
|
}
|
|
14989
16242
|
}
|
|
16243
|
+
observeCtaAssistantTurn(id) {
|
|
16244
|
+
this.ctaAssistantTurns ?? (this.ctaAssistantTurns = new Set());
|
|
16245
|
+
this.ctaAssistantTurns.add(id);
|
|
16246
|
+
while (this.ctaAssistantTurns.size > 40) {
|
|
16247
|
+
this.ctaAssistantTurns.delete(this.ctaAssistantTurns.values().next().value);
|
|
16248
|
+
}
|
|
16249
|
+
this.renderCurrentCtaOffer();
|
|
16250
|
+
}
|
|
16251
|
+
renderCurrentCtaOffer() {
|
|
16252
|
+
const offer = this.ctaOffer;
|
|
16253
|
+
if (offer &&
|
|
16254
|
+
this.ctaAssistantTurns?.has(offer.sourceTurnId) &&
|
|
16255
|
+
offer.configRevision === this.bootstrap?.configRevision &&
|
|
16256
|
+
!this.terminalRequestPending &&
|
|
16257
|
+
!this.ended &&
|
|
16258
|
+
!this.destroyed &&
|
|
16259
|
+
!this.messengerTransferred &&
|
|
16260
|
+
!this.messengerTransferPending &&
|
|
16261
|
+
this.channel?.hasFencedAuthority &&
|
|
16262
|
+
Date.parse(offer.expiresAt) > Date.now()) {
|
|
16263
|
+
if (!this.view)
|
|
16264
|
+
return;
|
|
16265
|
+
this.ctaAnnouncedOffers ?? (this.ctaAnnouncedOffers = new Set());
|
|
16266
|
+
const announce = !this.ctaAnnouncedOffers.has(offer.offerId) &&
|
|
16267
|
+
this.ctaAnnouncedOffers.size < 16;
|
|
16268
|
+
if (announce)
|
|
16269
|
+
this.ctaAnnouncedOffers.add(offer.offerId);
|
|
16270
|
+
this.view.showCtaOffer(offer, { announce });
|
|
16271
|
+
}
|
|
16272
|
+
}
|
|
16273
|
+
resolveCtaOffer(result) {
|
|
16274
|
+
const offer = this.ctaOffer;
|
|
16275
|
+
const channel = this.channel;
|
|
16276
|
+
if (!offer ||
|
|
16277
|
+
result.offerId !== offer.offerId ||
|
|
16278
|
+
(this.ctaTerminalOffers ?? (this.ctaTerminalOffers = new Set())).has(offer.offerId) ||
|
|
16279
|
+
!channel?.hasFencedAuthority ||
|
|
16280
|
+
this.terminalRequestPending ||
|
|
16281
|
+
this.ended ||
|
|
16282
|
+
this.destroyed ||
|
|
16283
|
+
this.messengerTransferred ||
|
|
16284
|
+
this.messengerTransferPending ||
|
|
16285
|
+
offer.configRevision !== this.bootstrap?.configRevision ||
|
|
16286
|
+
Date.parse(offer.expiresAt) <= Date.now())
|
|
16287
|
+
return false;
|
|
16288
|
+
this.ctaTerminalOffers.add(offer.offerId);
|
|
16289
|
+
if (result.outcome === "clicked")
|
|
16290
|
+
this.ctaClicked = true;
|
|
16291
|
+
const generation = this.sessionEffectGeneration;
|
|
16292
|
+
const ctaGeneration = this.currentCtaAuthorityGeneration();
|
|
16293
|
+
const messageId = randomId("cta_result");
|
|
16294
|
+
let attempts = 0;
|
|
16295
|
+
const send = () => {
|
|
16296
|
+
if (generation !== this.sessionEffectGeneration ||
|
|
16297
|
+
ctaGeneration !== this.currentCtaAuthorityGeneration() ||
|
|
16298
|
+
this.channel !== channel ||
|
|
16299
|
+
this.terminalRequestPending ||
|
|
16300
|
+
this.ended ||
|
|
16301
|
+
this.destroyed ||
|
|
16302
|
+
!channel.hasFencedAuthority ||
|
|
16303
|
+
Date.parse(offer.expiresAt) <= Date.now())
|
|
16304
|
+
return;
|
|
16305
|
+
attempts += 1;
|
|
16306
|
+
void this.sendControlOutcome("cta.result", result, messageId, 2500)
|
|
16307
|
+
.then((outcome) => {
|
|
16308
|
+
if (generation !== this.sessionEffectGeneration ||
|
|
16309
|
+
ctaGeneration !== this.currentCtaAuthorityGeneration() ||
|
|
16310
|
+
this.channel !== channel)
|
|
16311
|
+
return;
|
|
16312
|
+
if (outcome?.status === "ack" ||
|
|
16313
|
+
outcome?.status === "explicit_error" ||
|
|
16314
|
+
attempts >= 3)
|
|
16315
|
+
return;
|
|
16316
|
+
this.ctaResultRetryTimer = setTimeout(send, 500);
|
|
16317
|
+
})
|
|
16318
|
+
.catch(() => undefined);
|
|
16319
|
+
};
|
|
16320
|
+
send();
|
|
16321
|
+
// Keep the anchor intact through native activation, independent of ACK delivery.
|
|
16322
|
+
queueMicrotask(() => {
|
|
16323
|
+
if (this.ctaOffer === offer)
|
|
16324
|
+
this.clearCurrentCtaOffer();
|
|
16325
|
+
});
|
|
16326
|
+
return true;
|
|
16327
|
+
}
|
|
16328
|
+
clearCurrentCtaOffer() {
|
|
16329
|
+
if (this.ctaExpiryTimer)
|
|
16330
|
+
clearTimeout(this.ctaExpiryTimer);
|
|
16331
|
+
this.ctaExpiryTimer = null;
|
|
16332
|
+
this.ctaOffer = null;
|
|
16333
|
+
this.view?.clearCtaOffer?.();
|
|
16334
|
+
}
|
|
16335
|
+
clearCtaAuthority() {
|
|
16336
|
+
this.clearCtaOfferAuthority();
|
|
16337
|
+
this.ctaContentGeneration = (this.ctaContentGeneration ?? 0) + 1;
|
|
16338
|
+
this.ctaAssistantTurns?.clear();
|
|
16339
|
+
}
|
|
16340
|
+
clearCtaOfferAuthority() {
|
|
16341
|
+
this.ctaAuthorityGeneration = this.currentCtaAuthorityGeneration() + 1;
|
|
16342
|
+
this.clearCurrentCtaOffer();
|
|
16343
|
+
if (this.ctaResultRetryTimer)
|
|
16344
|
+
clearTimeout(this.ctaResultRetryTimer);
|
|
16345
|
+
this.ctaResultRetryTimer = null;
|
|
16346
|
+
this.ctaSeenOffers?.clear();
|
|
16347
|
+
}
|
|
16348
|
+
ctaContentIsCurrent(message) {
|
|
16349
|
+
const captured = this.ctaContentAtIngress?.get(message);
|
|
16350
|
+
return (message.sessionId === this.result?.sessionId &&
|
|
16351
|
+
(!captured ||
|
|
16352
|
+
(captured.generation === (this.ctaContentGeneration ?? 0) &&
|
|
16353
|
+
captured.channel === this.channel)));
|
|
16354
|
+
}
|
|
16355
|
+
currentCtaAuthorityGeneration() {
|
|
16356
|
+
return Number.isSafeInteger(this.ctaAuthorityGeneration)
|
|
16357
|
+
? this.ctaAuthorityGeneration
|
|
16358
|
+
: 0;
|
|
16359
|
+
}
|
|
16360
|
+
ctaEnvelopeIsCurrent(message) {
|
|
16361
|
+
return ((this.ctaAuthorityGenerationAtIngress?.get(message) ??
|
|
16362
|
+
this.currentCtaAuthorityGeneration()) ===
|
|
16363
|
+
this.currentCtaAuthorityGeneration());
|
|
16364
|
+
}
|
|
16365
|
+
invalidateCtaAuthority() {
|
|
16366
|
+
if (this.ctaOffer && (this.ctaTerminalOffers ?? (this.ctaTerminalOffers = new Set())).size < 16) {
|
|
16367
|
+
this.ctaTerminalOffers.add(this.ctaOffer.offerId);
|
|
16368
|
+
}
|
|
16369
|
+
// Caption content is not permission: a navigation consent reset can follow
|
|
16370
|
+
// its replayed captions. Keep that bounded current-transport evidence, while
|
|
16371
|
+
// terminalizing this offer and fencing every older queued CTA. Transport or
|
|
16372
|
+
// session cleanup still clears the content generation in clearCtaAuthority.
|
|
16373
|
+
this.clearCtaOfferAuthority();
|
|
16374
|
+
}
|
|
14990
16375
|
readTranscript() {
|
|
14991
16376
|
try {
|
|
14992
16377
|
return parseTranscript(JSON.parse(sessionStorage.getItem(this.transcriptStorageKey) ?? "[]"));
|
|
@@ -15050,7 +16435,10 @@ class AiLiveAssist {
|
|
|
15050
16435
|
for (const entry of this.transcript) {
|
|
15051
16436
|
if (this.renderedTranscriptIds.has(entry.id))
|
|
15052
16437
|
continue;
|
|
15053
|
-
view.addCaption(entry.role, entry.text, true, {
|
|
16438
|
+
view.addCaption(entry.role, entry.text, true, {
|
|
16439
|
+
restored: true,
|
|
16440
|
+
sourceTurnId: entry.id,
|
|
16441
|
+
});
|
|
15054
16442
|
this.renderedTranscriptIds.add(entry.id);
|
|
15055
16443
|
}
|
|
15056
16444
|
}
|
|
@@ -15795,6 +17183,91 @@ class AiLiveAssist {
|
|
|
15795
17183
|
launchIdempotencyKey,
|
|
15796
17184
|
};
|
|
15797
17185
|
}
|
|
17186
|
+
renewExpiredTerminalEndIntent() {
|
|
17187
|
+
const intent = this.terminalEndIntent;
|
|
17188
|
+
const now = Date.now();
|
|
17189
|
+
if (!intent || intent.retryUntil > now)
|
|
17190
|
+
return true;
|
|
17191
|
+
const currentRecord = this.terminalResumeRecord;
|
|
17192
|
+
const retainedRecord = currentRecord?.terminalEnd?.operationId === intent.operationId &&
|
|
17193
|
+
currentRecord.sessionId === intent.sessionId
|
|
17194
|
+
? currentRecord
|
|
17195
|
+
: null;
|
|
17196
|
+
if (!retainedRecord ||
|
|
17197
|
+
!this.storedTerminalRetryAuthorityMatches(intent, retainedRecord)) {
|
|
17198
|
+
return false;
|
|
17199
|
+
}
|
|
17200
|
+
const retainedResult = [this.result, this.modeUpgradeTerminalResult].find((candidate) => candidate?.sessionId === intent.sessionId);
|
|
17201
|
+
const resultExpiry = retainedResult
|
|
17202
|
+
? Date.parse(retainedResult.resumeExpiresAt ?? retainedResult.expiresAt)
|
|
17203
|
+
: 0;
|
|
17204
|
+
const authorityExpiry = Math.max(retainedRecord?.expiresAt ?? 0, Number.isFinite(resultExpiry) ? resultExpiry : 0);
|
|
17205
|
+
const retryUntil = Math.min(now + TERMINAL_REQUEST_RETRY_HORIZON_MS, authorityExpiry);
|
|
17206
|
+
if (retryUntil <= now)
|
|
17207
|
+
return false;
|
|
17208
|
+
const renewed = {
|
|
17209
|
+
...intent,
|
|
17210
|
+
requestedAt: now,
|
|
17211
|
+
retryUntil,
|
|
17212
|
+
};
|
|
17213
|
+
const previousRetryAttempts = this.terminalRetryAttempts;
|
|
17214
|
+
this.terminalEndIntent = renewed;
|
|
17215
|
+
if (retainedResult) {
|
|
17216
|
+
if (!this.captureTerminalAuthorizedResult(retainedResult, retainedRecord)) {
|
|
17217
|
+
this.rollbackFailedTerminalEndRenewal(intent, retainedRecord, renewed, previousRetryAttempts);
|
|
17218
|
+
return false;
|
|
17219
|
+
}
|
|
17220
|
+
this.terminalRetryAttempts = 0;
|
|
17221
|
+
return true;
|
|
17222
|
+
}
|
|
17223
|
+
if (!this.storeTerminalResume(retainedRecord, renewed)) {
|
|
17224
|
+
this.rollbackFailedTerminalEndRenewal(intent, retainedRecord, renewed, previousRetryAttempts);
|
|
17225
|
+
return false;
|
|
17226
|
+
}
|
|
17227
|
+
this.terminalRetryAttempts = 0;
|
|
17228
|
+
return true;
|
|
17229
|
+
}
|
|
17230
|
+
rollbackFailedTerminalEndRenewal(previousIntent, previousRecord, attemptedIntent, previousRetryAttempts) {
|
|
17231
|
+
const persistedIntent = this.readTerminalEndIntent();
|
|
17232
|
+
if (persistedIntent?.operationId === attemptedIntent.operationId &&
|
|
17233
|
+
persistedIntent.sessionId === attemptedIntent.sessionId &&
|
|
17234
|
+
persistedIntent.requestedAt === attemptedIntent.requestedAt) {
|
|
17235
|
+
const persistedRecord = this.readResume();
|
|
17236
|
+
const failedResumeIsOwned = Boolean(!persistedRecord ||
|
|
17237
|
+
(persistedRecord.tabId === this.tabId &&
|
|
17238
|
+
persistedRecord.sessionId === previousRecord.sessionId &&
|
|
17239
|
+
persistedRecord.terminalEnd?.operationId ===
|
|
17240
|
+
attemptedIntent.operationId &&
|
|
17241
|
+
persistedRecord.terminalEnd.requestedAt ===
|
|
17242
|
+
attemptedIntent.requestedAt));
|
|
17243
|
+
if (this.persistTerminalEndIntent(previousIntent) &&
|
|
17244
|
+
failedResumeIsOwned) {
|
|
17245
|
+
this.storeResume(previousRecord, false);
|
|
17246
|
+
}
|
|
17247
|
+
}
|
|
17248
|
+
this.terminalEndIntent = previousIntent;
|
|
17249
|
+
this.terminalResumeRecord = previousRecord;
|
|
17250
|
+
this.terminalRetryAttempts = previousRetryAttempts;
|
|
17251
|
+
}
|
|
17252
|
+
storedTerminalRetryAuthorityMatches(intent, record) {
|
|
17253
|
+
try {
|
|
17254
|
+
const terminalSerialized = localStorage.getItem(this.terminalEndStorageKey);
|
|
17255
|
+
const resumeSerialized = sessionStorage.getItem(this.storageKey);
|
|
17256
|
+
if (!terminalSerialized || !resumeSerialized)
|
|
17257
|
+
return false;
|
|
17258
|
+
if (canonicalJson(JSON.parse(terminalSerialized)) !==
|
|
17259
|
+
canonicalJson(intent) ||
|
|
17260
|
+
canonicalJson(JSON.parse(resumeSerialized)) !== canonicalJson(record)) {
|
|
17261
|
+
return false;
|
|
17262
|
+
}
|
|
17263
|
+
return (localStorage.getItem(this.terminalEndStorageKey) ===
|
|
17264
|
+
terminalSerialized &&
|
|
17265
|
+
sessionStorage.getItem(this.storageKey) === resumeSerialized);
|
|
17266
|
+
}
|
|
17267
|
+
catch {
|
|
17268
|
+
return false;
|
|
17269
|
+
}
|
|
17270
|
+
}
|
|
15798
17271
|
terminalIntentMatchesAuthority(intent, record) {
|
|
15799
17272
|
const sessionId = this.result?.sessionId ??
|
|
15800
17273
|
this.modeUpgradeTerminalResult?.sessionId ??
|
|
@@ -16092,7 +17565,7 @@ class AiLiveAssist {
|
|
|
16092
17565
|
if (record?.terminalEnd?.operationId === intent.operationId ||
|
|
16093
17566
|
(intent.sessionId === null &&
|
|
16094
17567
|
intent.launchIdempotencyKey ===
|
|
16095
|
-
this.readStagedPendingLaunch()?.pendingLaunch.idempotencyKey)) {
|
|
17568
|
+
(this.savedGuidePendingLaunch()?.idempotencyKey ?? this.readStagedPendingLaunch()?.pendingLaunch.idempotencyKey))) {
|
|
16096
17569
|
return this.restoreTerminalEnd(intent, record?.terminalEnd?.operationId === intent.operationId ? record : null);
|
|
16097
17570
|
}
|
|
16098
17571
|
return this.terminalRequestPending;
|