@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/lib/AiLiveAssist.js
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import { guideMountIdentity, guideStorageNamespace, resolveGuideHost, } from "./guideHost.js";
|
|
2
|
+
import { claimGuideMount } from "./guideMount.js";
|
|
1
3
|
import { RuntimeClient, RuntimeClientError, idempotencyKey, isValidAssistSessionGrant, isValidReplaySessionId, } from "./client.js";
|
|
2
4
|
import { ControlChannel, } from "./control.js";
|
|
3
5
|
import { PageContextCollector } from "./context.js";
|
|
@@ -6,9 +8,11 @@ import { loadMessengerWebWidget, normalizeMessengerWebWidgetDescriptor, } from "
|
|
|
6
8
|
import { MAX_PAGE_ASSISTANCE_RECOVERY_TTL_MS, PageAssistancePreferenceStore, PageAssistanceRecoveryStore, digestPageAssistanceVisitor, } from "./pageAssistancePreference.js";
|
|
7
9
|
import { PresentationPlane, parsePresentationIntent } from "./presentation.js";
|
|
8
10
|
import { TabActivityLock } from "./tabLock.js";
|
|
9
|
-
import { WidgetView } from "./ui.js";
|
|
11
|
+
import { WidgetView, } from "./ui.js";
|
|
10
12
|
import { VERSION } from "./version.js";
|
|
13
|
+
import { parseCtaOffer } from "./ctaOffer.js";
|
|
11
14
|
import { VoicePresenceView } from "./voicePresenceUi.js";
|
|
15
|
+
import { LiveGuideWidget } from "./liveGuideWidget.js";
|
|
12
16
|
class ModeUpgradeTerminalizedError extends Error {
|
|
13
17
|
constructor(state) {
|
|
14
18
|
super("The voice upgrade was safely ended.");
|
|
@@ -29,6 +33,19 @@ class ModeUpgradeConnectionDeadlineError extends RuntimeClientError {
|
|
|
29
33
|
this.name = "ModeUpgradeConnectionDeadlineError";
|
|
30
34
|
}
|
|
31
35
|
}
|
|
36
|
+
class InitialSessionStartupDeadlineError extends RuntimeClientError {
|
|
37
|
+
constructor() {
|
|
38
|
+
super("INTERNAL_UNAVAILABLE", "The secure AI Guide connection timed out.", true, 1000, 503);
|
|
39
|
+
this.name = "InitialSessionStartupDeadlineError";
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
class InitialVoiceMicrophoneUnavailableError extends Error {
|
|
43
|
+
constructor(cause) {
|
|
44
|
+
super("The microphone is unavailable.");
|
|
45
|
+
this.cause = cause;
|
|
46
|
+
this.name = "InitialVoiceMicrophoneUnavailableError";
|
|
47
|
+
}
|
|
48
|
+
}
|
|
32
49
|
class TerminalRequestTimeoutError extends RuntimeClientError {
|
|
33
50
|
constructor() {
|
|
34
51
|
super("INTERNAL_UNAVAILABLE", "The terminal request timed out.", true, null, 503);
|
|
@@ -41,6 +58,12 @@ class TerminalRequestDeferredError extends Error {
|
|
|
41
58
|
this.name = "TerminalRequestDeferredError";
|
|
42
59
|
}
|
|
43
60
|
}
|
|
61
|
+
class TerminalControlEndUnconfirmedError extends Error {
|
|
62
|
+
constructor() {
|
|
63
|
+
super("The realtime End request was sent but its authoritative result was not observed.");
|
|
64
|
+
this.name = "TerminalControlEndUnconfirmedError";
|
|
65
|
+
}
|
|
66
|
+
}
|
|
44
67
|
const TERMINAL_STATES = new Set(["ended", "failed", "revoked"]);
|
|
45
68
|
const ACTION_SCOPED_ERROR_CODES = new Set([
|
|
46
69
|
"CONFIRMATION_EXPIRED",
|
|
@@ -96,6 +119,9 @@ const MODE_UPGRADE_LIFECYCLE_TIMEOUT_MS = 15000;
|
|
|
96
119
|
const MODE_UPGRADE_CONNECTION_DEADLINE_MS = 30000;
|
|
97
120
|
const MODE_UPGRADE_PATH_GUARD_INTERVAL_MS = 50;
|
|
98
121
|
const NAVIGATION_CONSENT_RESET_TIMEOUT_MS = 15000;
|
|
122
|
+
const CONTEXT_NAVIGATION_ACK_TIMEOUT_MS = 5000;
|
|
123
|
+
const CONTEXT_NAVIGATION_LATE_ACK_TIMEOUT_MS = 10000;
|
|
124
|
+
const INITIAL_SESSION_STARTUP_TIMEOUT_MS = 15000;
|
|
99
125
|
const TERMINAL_REQUEST_TIMEOUT_MS = 7500;
|
|
100
126
|
const TERMINAL_REQUEST_RETRY_HORIZON_MS = 15 * 60 * 1000;
|
|
101
127
|
const TERMINAL_REQUEST_MAX_RETRY_MS = 30000;
|
|
@@ -122,6 +148,7 @@ const VALID_PRESENCE_STATES = new Set([
|
|
|
122
148
|
]);
|
|
123
149
|
const VALID_ASSISTANT_STATES = new Set(["ready", "listening", "thinking"]);
|
|
124
150
|
const PRE_FENCE_AUTHORITY_ENVELOPE_TYPES = new Set([
|
|
151
|
+
"cta.offer",
|
|
125
152
|
"page_assistance.request",
|
|
126
153
|
"page_assistance.updated",
|
|
127
154
|
"page_assistance.access_granted",
|
|
@@ -229,6 +256,7 @@ const CONSENT_SCOPES = new Set([
|
|
|
229
256
|
"visual_context",
|
|
230
257
|
"handoff_context",
|
|
231
258
|
"retained_transcript",
|
|
259
|
+
"session_recording",
|
|
232
260
|
"presentation_guidance",
|
|
233
261
|
]);
|
|
234
262
|
export const REPLAY_SESSION_READY_TIMEOUT_MS = 15000;
|
|
@@ -248,12 +276,12 @@ export class ReplaySessionReadiness {
|
|
|
248
276
|
this.destroyed = false;
|
|
249
277
|
this.recordingDisabled = false;
|
|
250
278
|
this.onStart = (startInfo) => {
|
|
251
|
-
if (this.destroyed)
|
|
279
|
+
if (this.destroyed || !this.app)
|
|
252
280
|
return;
|
|
253
281
|
if (this.recordingDisabled) {
|
|
254
282
|
window.setTimeout(() => {
|
|
255
283
|
if (!this.destroyed && this.recordingDisabled)
|
|
256
|
-
this.app
|
|
284
|
+
this.app?.stop();
|
|
257
285
|
}, 0);
|
|
258
286
|
return;
|
|
259
287
|
}
|
|
@@ -288,18 +316,18 @@ export class ReplaySessionReadiness {
|
|
|
288
316
|
this.stopHandler?.();
|
|
289
317
|
};
|
|
290
318
|
this.lineage = this.readCurrentLineage();
|
|
291
|
-
this.app
|
|
292
|
-
this.app
|
|
319
|
+
this.app?.attachStartCallback(this.onStart, true);
|
|
320
|
+
this.app?.attachStopCallback(this.onStop, true);
|
|
293
321
|
}
|
|
294
322
|
wait() {
|
|
295
323
|
if (this.destroyed) {
|
|
296
324
|
return Promise.reject(new RuntimeClientError("WIDGET_DESTROYED", "AI Guide is no longer available.", false, null, 410));
|
|
297
325
|
}
|
|
298
|
-
if (this.recordingDisabled) {
|
|
326
|
+
if (this.recordingDisabled || !this.app) {
|
|
299
327
|
return Promise.reject(this.recordingRequiredError());
|
|
300
328
|
}
|
|
301
329
|
const current = this.readCurrentLineage();
|
|
302
|
-
if (typeof this.app
|
|
330
|
+
if (typeof this.app?.getAssistSessionGrant === "function") {
|
|
303
331
|
this.lineage = current;
|
|
304
332
|
}
|
|
305
333
|
else if (current) {
|
|
@@ -334,7 +362,7 @@ export class ReplaySessionReadiness {
|
|
|
334
362
|
throw new RuntimeClientError("WIDGET_DESTROYED", "AI Guide is no longer available.", false, null, 410);
|
|
335
363
|
}
|
|
336
364
|
const current = this.readCurrentLineage();
|
|
337
|
-
const expected = typeof this.app
|
|
365
|
+
const expected = typeof this.app?.getAssistSessionGrant === "function"
|
|
338
366
|
? current
|
|
339
367
|
: this.lineage;
|
|
340
368
|
if (this.recordingDisabled ||
|
|
@@ -349,7 +377,7 @@ export class ReplaySessionReadiness {
|
|
|
349
377
|
this.stopHandler = handler;
|
|
350
378
|
}
|
|
351
379
|
startFreshSessionIfInactive() {
|
|
352
|
-
if (this.destroyed || this.recordingDisabled || this.startInFlight)
|
|
380
|
+
if (this.destroyed || this.recordingDisabled || this.startInFlight || !this.app)
|
|
353
381
|
return;
|
|
354
382
|
try {
|
|
355
383
|
if (this.app.active())
|
|
@@ -374,7 +402,7 @@ export class ReplaySessionReadiness {
|
|
|
374
402
|
this.recordingDisabled = true;
|
|
375
403
|
this.lineage = null;
|
|
376
404
|
this.rejectWaiter(this.recordingRequiredError());
|
|
377
|
-
this.app
|
|
405
|
+
this.app?.stop();
|
|
378
406
|
}
|
|
379
407
|
destroy() {
|
|
380
408
|
if (this.destroyed)
|
|
@@ -386,7 +414,7 @@ export class ReplaySessionReadiness {
|
|
|
386
414
|
}
|
|
387
415
|
readCurrentLineage() {
|
|
388
416
|
try {
|
|
389
|
-
const current = this.app
|
|
417
|
+
const current = this.app?.getAssistSessionGrant?.();
|
|
390
418
|
return replayLineage(current?.sessionId, current?.token, this.tabId);
|
|
391
419
|
}
|
|
392
420
|
catch {
|
|
@@ -797,6 +825,9 @@ const parseResumeRecord = (value) => {
|
|
|
797
825
|
const expiresAt = Date.parse(rawActionExecution.expiresAt ?? "");
|
|
798
826
|
const result = rawActionExecution.result;
|
|
799
827
|
const navigationPayload = rawActionExecution.navigationPayload;
|
|
828
|
+
const deferredNavigationPath = rawActionExecution.deferredNavigationPath === undefined
|
|
829
|
+
? null
|
|
830
|
+
: rawActionExecution.deferredNavigationPath;
|
|
800
831
|
const validResult = result === null ||
|
|
801
832
|
(typeof result === "object" &&
|
|
802
833
|
result !== null &&
|
|
@@ -829,21 +860,43 @@ const parseResumeRecord = (value) => {
|
|
|
829
860
|
navigationPayload.navigationType === "spa" &&
|
|
830
861
|
typeof navigationPayload.url === "string" &&
|
|
831
862
|
new URL(navigationPayload.url).origin === window.location.origin);
|
|
863
|
+
const validDeferredNavigation = deferredNavigationPath === null ||
|
|
864
|
+
(typeof deferredNavigationPath === "string" &&
|
|
865
|
+
deferredNavigationPath.length <= 2048 &&
|
|
866
|
+
/^\/(?!\/)[^?#]*$/u.test(deferredNavigationPath));
|
|
867
|
+
const deferredResultUrl = deferredNavigationPath !== null &&
|
|
868
|
+
result !== null &&
|
|
869
|
+
typeof result?.observed?.url === "string"
|
|
870
|
+
? new URL(result.observed.url)
|
|
871
|
+
: null;
|
|
872
|
+
const validDeferredResult = deferredNavigationPath === null ||
|
|
873
|
+
result === null ||
|
|
874
|
+
(result.status === "stale" &&
|
|
875
|
+
result.observed.targetState === "unknown" &&
|
|
876
|
+
deferredResultUrl?.origin === window.location.origin &&
|
|
877
|
+
deferredResultUrl.search === "" &&
|
|
878
|
+
deferredResultUrl.hash === "" &&
|
|
879
|
+
deferredResultUrl.pathname === deferredNavigationPath);
|
|
832
880
|
if (!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.actionId ?? "") ||
|
|
833
881
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.executionId ?? "") ||
|
|
834
882
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.beginMessageId ?? "") ||
|
|
835
883
|
!Number.isSafeInteger(rawActionExecution.beginClientSequence) ||
|
|
836
884
|
(rawActionExecution.beginClientSequence ?? 0) < 1 ||
|
|
837
885
|
!Number.isFinite(expiresAt) ||
|
|
838
|
-
expiresAt <= Date.now() ||
|
|
839
886
|
expiresAt > record.expiresAt ||
|
|
840
887
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.resultMessageId ?? "") ||
|
|
841
888
|
!PUBLIC_REQUEST_ID_PATTERN.test(rawActionExecution.navigationMessageId ?? "") ||
|
|
842
889
|
!validResult ||
|
|
843
|
-
!validNavigation
|
|
890
|
+
!validNavigation ||
|
|
891
|
+
!validDeferredNavigation ||
|
|
892
|
+
(deferredNavigationPath !== null && navigationPayload !== null) ||
|
|
893
|
+
!validDeferredResult) {
|
|
844
894
|
return null;
|
|
845
895
|
}
|
|
846
|
-
|
|
896
|
+
// A visitor can return from an external destination after the action's
|
|
897
|
+
// short deadline. Drop that action, not the valid same-tab session or
|
|
898
|
+
// its End authority. Resume still revalidates the session server-side.
|
|
899
|
+
actionExecution = expiresAt > Date.now() ? {
|
|
847
900
|
actionId: rawActionExecution.actionId,
|
|
848
901
|
executionId: rawActionExecution.executionId,
|
|
849
902
|
beginMessageId: rawActionExecution.beginMessageId,
|
|
@@ -853,7 +906,8 @@ const parseResumeRecord = (value) => {
|
|
|
853
906
|
navigationMessageId: rawActionExecution.navigationMessageId,
|
|
854
907
|
result: result ? { ...result, observed: { ...result.observed } } : null,
|
|
855
908
|
navigationPayload: navigationPayload ? { ...navigationPayload } : null,
|
|
856
|
-
|
|
909
|
+
...(deferredNavigationPath !== null ? { deferredNavigationPath } : {}),
|
|
910
|
+
} : null;
|
|
857
911
|
}
|
|
858
912
|
const rawPauseCommand = record.pauseCommand;
|
|
859
913
|
let pauseCommand = null;
|
|
@@ -1289,12 +1343,13 @@ const companionSwitchGrantExpiresSoon = (grant, nowMs = Date.now()) => {
|
|
|
1289
1343
|
}
|
|
1290
1344
|
};
|
|
1291
1345
|
export default class AiLiveAssist {
|
|
1292
|
-
constructor(app, options) {
|
|
1293
|
-
this.app = app;
|
|
1346
|
+
constructor(app, options, mountReservation) {
|
|
1294
1347
|
this.options = options;
|
|
1295
1348
|
this.version = VERSION;
|
|
1349
|
+
this.releaseMount = null;
|
|
1296
1350
|
this.bootstrap = null;
|
|
1297
1351
|
this.view = null;
|
|
1352
|
+
this.liveWidget = null;
|
|
1298
1353
|
this.messenger = null;
|
|
1299
1354
|
this.messengerListenersBound = false;
|
|
1300
1355
|
this.messengerReturnListenerBound = false;
|
|
@@ -1367,6 +1422,7 @@ export default class AiLiveAssist {
|
|
|
1367
1422
|
this.bootstrapAbort = null;
|
|
1368
1423
|
this.scopes = [];
|
|
1369
1424
|
this.mode = "text";
|
|
1425
|
+
this.pendingPlaybackState = null;
|
|
1370
1426
|
this.ended = false;
|
|
1371
1427
|
this.reconnecting = false;
|
|
1372
1428
|
this.resumeAttemptOwner = null;
|
|
@@ -1461,6 +1517,7 @@ export default class AiLiveAssist {
|
|
|
1461
1517
|
this.visitorActiveEligibilityRecheckController = null;
|
|
1462
1518
|
this.visitorActiveEligibilityRecheckKey = null;
|
|
1463
1519
|
this.launchGeneration = 0;
|
|
1520
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
1464
1521
|
this.queuedLaunchToken = null;
|
|
1465
1522
|
this.visitorLimitAbort = null;
|
|
1466
1523
|
this.lastLaunch = null;
|
|
@@ -1474,6 +1531,7 @@ export default class AiLiveAssist {
|
|
|
1474
1531
|
this.visualConsentGranted = false;
|
|
1475
1532
|
this.manualTurn = false;
|
|
1476
1533
|
this.pushActive = false;
|
|
1534
|
+
this.manualPushRequest = null;
|
|
1477
1535
|
this.pendingModeUpgrade = null;
|
|
1478
1536
|
this.pendingModeUpgradeConsentCompensation = null;
|
|
1479
1537
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -1486,6 +1544,25 @@ export default class AiLiveAssist {
|
|
|
1486
1544
|
this.preparedFocusedHandoff = null;
|
|
1487
1545
|
this.transcript = [];
|
|
1488
1546
|
this.renderedTranscriptIds = new Set();
|
|
1547
|
+
this.voicePlaybackInterruptionGeneration = 0;
|
|
1548
|
+
this.voicePlaybackAdmissionAfterSequence = 0;
|
|
1549
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
1550
|
+
this.voicePlaybackIngress = new WeakMap();
|
|
1551
|
+
this.voicePlaybackRearm = null;
|
|
1552
|
+
this.ctaOffer = null;
|
|
1553
|
+
this.ctaExpiryTimer = null;
|
|
1554
|
+
this.ctaResultRetryTimer = null;
|
|
1555
|
+
this.ctaSeenOffers = new Set();
|
|
1556
|
+
this.ctaAssistantTurns = new Set();
|
|
1557
|
+
this.ctaContentGeneration = 0;
|
|
1558
|
+
this.ctaContentAtIngress = new WeakMap();
|
|
1559
|
+
this.ctaTerminalOffers = new Set();
|
|
1560
|
+
this.ctaSessionId = null;
|
|
1561
|
+
this.ctaClicked = false;
|
|
1562
|
+
this.ctaAuthorityGeneration = 0;
|
|
1563
|
+
this.ctaAuthorityGenerationAtIngress = new WeakMap();
|
|
1564
|
+
this.ctaStoppedSessionId = null;
|
|
1565
|
+
this.ctaAnnouncedOffers = new Set();
|
|
1489
1566
|
this.transcriptRestoredFromCache = false;
|
|
1490
1567
|
this.agentDiscoveryLink = null;
|
|
1491
1568
|
this.onMessengerSupportState = (event) => {
|
|
@@ -1614,9 +1691,13 @@ export default class AiLiveAssist {
|
|
|
1614
1691
|
this.wakeTerminalRetry();
|
|
1615
1692
|
};
|
|
1616
1693
|
this.onVisitorControl = (event) => {
|
|
1694
|
+
// Only browser-authenticated visitor input may interrupt an approved page
|
|
1695
|
+
// action. Framer navigation uses untrusted synthetic pointer events to
|
|
1696
|
+
// release the exact approved link to its same-document router.
|
|
1697
|
+
if (!event.isTrusted)
|
|
1698
|
+
return;
|
|
1617
1699
|
if (!this.lock.ownsActivity()) {
|
|
1618
|
-
|
|
1619
|
-
this.requestFocusedHandoff();
|
|
1700
|
+
this.requestFocusedHandoff();
|
|
1620
1701
|
if (this.pendingAction)
|
|
1621
1702
|
return;
|
|
1622
1703
|
}
|
|
@@ -1645,56 +1726,85 @@ export default class AiLiveAssist {
|
|
|
1645
1726
|
this.pendingAction = false;
|
|
1646
1727
|
void this.updatePause(true);
|
|
1647
1728
|
};
|
|
1648
|
-
this.
|
|
1649
|
-
this.
|
|
1650
|
-
this.
|
|
1651
|
-
this.
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
this.
|
|
1655
|
-
this.
|
|
1656
|
-
this.
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
this.pageAssistanceTrackerIdentity =
|
|
1662
|
-
this.readPageAssistanceTrackerIdentity();
|
|
1663
|
-
const resume = this.readResume();
|
|
1664
|
-
this.tabId = resume?.tabId || app.session.getTabId() || randomId("tab");
|
|
1665
|
-
this.pageAssistanceBindingGeneration =
|
|
1666
|
-
resume?.pageAssistanceBindingGeneration ||
|
|
1667
|
-
randomId("page_assistance_binding");
|
|
1668
|
-
this.replayReadiness = new ReplaySessionReadiness(app, this.tabId);
|
|
1669
|
-
if (options.recordReplay === false) {
|
|
1670
|
-
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
1671
|
-
this.replayReadiness.disableRecording();
|
|
1672
|
-
}
|
|
1673
|
-
this.windowId = randomId("window");
|
|
1674
|
-
this.terminalOffline = navigator.onLine === false;
|
|
1675
|
-
this.locale =
|
|
1676
|
-
resume?.locale ??
|
|
1677
|
-
boundedLocale(options.locale ||
|
|
1678
|
-
navigator.language ||
|
|
1679
|
-
document.documentElement.lang ||
|
|
1680
|
-
"en");
|
|
1681
|
-
const endpoint = app.options.endpoint;
|
|
1682
|
-
const runtimeUrl = options.runtimeUrl ||
|
|
1683
|
-
(endpoint
|
|
1684
|
-
? new URL(endpoint, window.location.href).origin
|
|
1685
|
-
: window.location.origin);
|
|
1729
|
+
this.host = resolveGuideHost(app, options);
|
|
1730
|
+
this.guideAdmission = this.host.kind === "guide" ? this.host.admission ?? null : null;
|
|
1731
|
+
this.standaloneAdmissionPending = this.host.kind === "guide" && !this.guideAdmission;
|
|
1732
|
+
if (this.host.kind === "guide" && options.siteKey) {
|
|
1733
|
+
throw new Error("A standalone AI Guide cannot use a legacy project key.");
|
|
1734
|
+
}
|
|
1735
|
+
this.siteKey = this.host.kind === "legacy_browser" ? options.siteKey || this.host.siteKey : "";
|
|
1736
|
+
this.storageNamespace = guideStorageNamespace(this.host, this.siteKey, window.location.origin);
|
|
1737
|
+
this.widgetViewOptions =
|
|
1738
|
+
this.host.kind === "guide"
|
|
1739
|
+
? { storageNamespace: this.storageNamespace }
|
|
1740
|
+
: {};
|
|
1741
|
+
const runtimeUrl = options.runtimeUrl || this.host.runtimeUrl;
|
|
1686
1742
|
this.runtime = new RuntimeClient(runtimeUrl, VERSION);
|
|
1687
|
-
this.
|
|
1688
|
-
|
|
1689
|
-
|
|
1690
|
-
|
|
1691
|
-
|
|
1692
|
-
|
|
1693
|
-
|
|
1694
|
-
|
|
1695
|
-
|
|
1696
|
-
|
|
1697
|
-
|
|
1743
|
+
this.releaseMount =
|
|
1744
|
+
options.enabled === false
|
|
1745
|
+
? null
|
|
1746
|
+
: claimGuideMount(document, guideMountIdentity(this.host, this.siteKey, window.location.origin), this, mountReservation);
|
|
1747
|
+
try {
|
|
1748
|
+
this.storageKey = `__oxvo_ai_live_assist_resume_${this.storageNamespace}`;
|
|
1749
|
+
this.transcriptStorageKey = `__oxvo_ai_live_assist_transcript_${this.storageNamespace}`;
|
|
1750
|
+
this.transferAuthorityStorageKey = `__oxvo_ai_live_assist_transfer_authority_${this.storageNamespace}`;
|
|
1751
|
+
this.legacyStagedPendingLaunchStorageKey = `__oxvo_ai_live_assist_pending_launch_${this.storageNamespace}`;
|
|
1752
|
+
this.stagedPendingLaunchStorageKey = `__oxvo_ai_live_assist_pending_launch_v2_${this.storageNamespace}`;
|
|
1753
|
+
this.terminalEndStorageKey = `__oxvo_ai_live_assist_terminal_end_${this.storageNamespace}`;
|
|
1754
|
+
this.messengerReturnEndStorageKey = `__oxvo_ai_live_assist_handoff_terminal_${this.storageNamespace}`;
|
|
1755
|
+
this.legacyFreshAiReturnProvisionalStorageKey = `__oxvo_ai_live_assist_fresh_return_${this.storageNamespace}`;
|
|
1756
|
+
this.freshAiReturnProvisionalStorageKey = `__oxvo_ai_live_assist_fresh_return_v2_${this.storageNamespace}`;
|
|
1757
|
+
this.pageAssistanceTrackerIdentityStorageKey = `__oxvo_ai_live_assist_page_assistance_tracker_${this.storageNamespace}`;
|
|
1758
|
+
this.transcript = this.readTranscript();
|
|
1759
|
+
this.visitorIdentity = this.host.kind === "guide" ? "" : this.resolveVisitorId();
|
|
1760
|
+
this.pageAssistanceTrackerIdentity =
|
|
1761
|
+
this.readPageAssistanceTrackerIdentity();
|
|
1762
|
+
const resume = this.readResume();
|
|
1763
|
+
this.tabId = resume?.tabId || this.guideAdmission?.pendingIntent()?.tabId || this.host.getTabId() || randomId("tab");
|
|
1764
|
+
this.pageAssistanceBindingGeneration =
|
|
1765
|
+
resume?.pageAssistanceBindingGeneration ||
|
|
1766
|
+
randomId("page_assistance_binding");
|
|
1767
|
+
this.replayReadiness = new ReplaySessionReadiness(this.host.kind === "legacy_browser" ? this.host.replay : null, this.tabId);
|
|
1768
|
+
if (this.standaloneAdmissionPending) {
|
|
1769
|
+
// Never put explicit Guide identity through legacy replay admission.
|
|
1770
|
+
this.unavailableReason =
|
|
1771
|
+
"This AI Guide installation is not available yet.";
|
|
1772
|
+
}
|
|
1773
|
+
else if (this.host.kind === "legacy_browser" && options.recordReplay === false) {
|
|
1774
|
+
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
1775
|
+
this.replayReadiness.disableRecording();
|
|
1776
|
+
}
|
|
1777
|
+
this.windowId = randomId("window");
|
|
1778
|
+
this.terminalOffline = navigator.onLine === false;
|
|
1779
|
+
this.locale =
|
|
1780
|
+
resume?.locale ??
|
|
1781
|
+
boundedLocale(options.locale ||
|
|
1782
|
+
navigator.language ||
|
|
1783
|
+
document.documentElement.lang ||
|
|
1784
|
+
"en");
|
|
1785
|
+
this.lock = new TabActivityLock(this.storageNamespace, this.windowId, (active) => this.handleTabActivityChange(active), (requesterId, requestId) => this.handoffToFocusedTab(requesterId, requestId), (payload, authority, sourceOwnerId) => this.prepareFocusedTabHandoff(payload, authority, sourceOwnerId), {
|
|
1786
|
+
onCommitting: (payload, authority) => this.commitStagedPendingLaunch(payload, authority),
|
|
1787
|
+
onCommitted: (payload, authority) => void this.commitFocusedTabHandoff(payload, authority),
|
|
1788
|
+
onRelinquished: (payload) => this.completeFocusedTabRelinquish(payload),
|
|
1789
|
+
onFailed: (payload, authority) => this.recoverFailedFocusedTabHandoff(payload, authority),
|
|
1790
|
+
onStandby: (payload, authority) => this.acceptStandbyPayload(payload, authority),
|
|
1791
|
+
onRecovery: () => void this.recoverStandbySession(),
|
|
1792
|
+
});
|
|
1793
|
+
this.replayReadiness.setStopHandler(() => this.onReplayRecordingStopped());
|
|
1794
|
+
if (this.standaloneAdmissionPending) {
|
|
1795
|
+
// Schema 3 must own recovery too; do not arm the legacy lifecycle.
|
|
1796
|
+
this.lock.destroy();
|
|
1797
|
+
}
|
|
1798
|
+
else {
|
|
1799
|
+
this.bindWindowLifecycle();
|
|
1800
|
+
}
|
|
1801
|
+
void this.initialize();
|
|
1802
|
+
}
|
|
1803
|
+
catch (error) {
|
|
1804
|
+
this.releaseMount?.();
|
|
1805
|
+
this.releaseMount = null;
|
|
1806
|
+
throw error;
|
|
1807
|
+
}
|
|
1698
1808
|
}
|
|
1699
1809
|
recoveryBusy(record = this.readResume()) {
|
|
1700
1810
|
return (!this.ended &&
|
|
@@ -1704,6 +1814,8 @@ export default class AiLiveAssist {
|
|
|
1704
1814
|
Boolean(record || this.result || this.modeUpgradeTerminalResult));
|
|
1705
1815
|
}
|
|
1706
1816
|
open(input = {}) {
|
|
1817
|
+
if (this.liveWidget)
|
|
1818
|
+
return this.liveWidget.open(normalizeAiGuideOpenInput(input));
|
|
1707
1819
|
if (this.terminalRequestPending || this.recoveryBusy()) {
|
|
1708
1820
|
return this.getState();
|
|
1709
1821
|
}
|
|
@@ -1713,7 +1825,7 @@ export default class AiLiveAssist {
|
|
|
1713
1825
|
: normalized.mode;
|
|
1714
1826
|
const unavailable = this.publicModeUnavailable(requestedMode);
|
|
1715
1827
|
if (unavailable) {
|
|
1716
|
-
this.
|
|
1828
|
+
this.presentSessionError(unavailable, false, false);
|
|
1717
1829
|
this.state("unavailable");
|
|
1718
1830
|
throw new TypeError(unavailable);
|
|
1719
1831
|
}
|
|
@@ -1760,6 +1872,12 @@ export default class AiLiveAssist {
|
|
|
1760
1872
|
return this.getState();
|
|
1761
1873
|
}
|
|
1762
1874
|
close() {
|
|
1875
|
+
if (this.liveWidget) {
|
|
1876
|
+
this.liveWidget.close();
|
|
1877
|
+
return;
|
|
1878
|
+
}
|
|
1879
|
+
if (this.standaloneAdmissionPending)
|
|
1880
|
+
return;
|
|
1763
1881
|
if (this.recoveryBusy())
|
|
1764
1882
|
return;
|
|
1765
1883
|
this.clearPendingIntentBeforeAuthorization();
|
|
@@ -1772,6 +1890,8 @@ export default class AiLiveAssist {
|
|
|
1772
1890
|
this.emitStateEvent();
|
|
1773
1891
|
}
|
|
1774
1892
|
getState() {
|
|
1893
|
+
if (this.liveWidget)
|
|
1894
|
+
return this.liveWidget.getState();
|
|
1775
1895
|
const resume = this.readResume();
|
|
1776
1896
|
const recovering = this.recoveryBusy(resume);
|
|
1777
1897
|
const active = !this.ended &&
|
|
@@ -1796,6 +1916,10 @@ export default class AiLiveAssist {
|
|
|
1796
1916
|
};
|
|
1797
1917
|
}
|
|
1798
1918
|
end() {
|
|
1919
|
+
if (this.liveWidget)
|
|
1920
|
+
return this.liveWidget.end();
|
|
1921
|
+
if (this.standaloneAdmissionPending)
|
|
1922
|
+
return Promise.resolve();
|
|
1799
1923
|
return this.requestEnd(null);
|
|
1800
1924
|
}
|
|
1801
1925
|
endInBackground() {
|
|
@@ -1832,6 +1956,13 @@ export default class AiLiveAssist {
|
|
|
1832
1956
|
return Promise.resolve();
|
|
1833
1957
|
if (this.terminalRequestInFlight)
|
|
1834
1958
|
return this.terminalRequestInFlight;
|
|
1959
|
+
if (this.terminalRequestPending &&
|
|
1960
|
+
this.terminalEndIntent &&
|
|
1961
|
+
this.terminalEndIntent.retryUntil <= Date.now() &&
|
|
1962
|
+
!this.renewExpiredTerminalEndIntent()) {
|
|
1963
|
+
this.presentTerminalRetry();
|
|
1964
|
+
return Promise.reject(new TerminalRequestDeferredError());
|
|
1965
|
+
}
|
|
1835
1966
|
if (!this.terminalRequestPending) {
|
|
1836
1967
|
this.terminalHandoffReconciliationPending = Boolean(this.handoffRequestLifecycleOwner ||
|
|
1837
1968
|
this.messengerHandoffRequestInFlight ||
|
|
@@ -1855,7 +1986,7 @@ export default class AiLiveAssist {
|
|
|
1855
1986
|
(staged.state === "in_flight" &&
|
|
1856
1987
|
this.pendingLaunchMatches(staged.pendingLaunch, pendingLaunch)))
|
|
1857
1988
|
? { ...pendingLaunch, scopes: [...pendingLaunch.scopes] }
|
|
1858
|
-
:
|
|
1989
|
+
: this.savedGuidePendingLaunch();
|
|
1859
1990
|
const record = this.readResume();
|
|
1860
1991
|
const persistedIntent = this.readTerminalEndIntent();
|
|
1861
1992
|
const intent = record?.terminalEnd ??
|
|
@@ -1905,6 +2036,8 @@ export default class AiLiveAssist {
|
|
|
1905
2036
|
this.clearReconnectTimer();
|
|
1906
2037
|
if (this.destroyed)
|
|
1907
2038
|
return;
|
|
2039
|
+
this.liveWidget?.destroy();
|
|
2040
|
+
this.liveWidget = null;
|
|
1908
2041
|
const recoveringModeUpgrade = this.relinquishModeUpgradeForRecovery(true, true);
|
|
1909
2042
|
if (!recoveringModeUpgrade)
|
|
1910
2043
|
this.clearModeUpgradeAttempt(true);
|
|
@@ -1925,6 +2058,7 @@ export default class AiLiveAssist {
|
|
|
1925
2058
|
this.bootstrapAbort?.abort();
|
|
1926
2059
|
this.bootstrapAbort = null;
|
|
1927
2060
|
this.replayReadiness?.destroy();
|
|
2061
|
+
this.guideAdmission?.destroy();
|
|
1928
2062
|
this.clearPendingIntent();
|
|
1929
2063
|
this.discardPendingConfirmationDecisions();
|
|
1930
2064
|
window.removeEventListener("pagehide", this.onPageHide, true);
|
|
@@ -1954,10 +2088,18 @@ export default class AiLiveAssist {
|
|
|
1954
2088
|
if (controllerWindow.OxvoAiGuide === this) {
|
|
1955
2089
|
Reflect.deleteProperty(controllerWindow, "OxvoAiGuide");
|
|
1956
2090
|
}
|
|
2091
|
+
this.releaseMount?.();
|
|
2092
|
+
this.releaseMount = null;
|
|
1957
2093
|
}
|
|
1958
2094
|
async initialize() {
|
|
1959
2095
|
if (this.options.enabled === false || this.destroyed)
|
|
1960
2096
|
return;
|
|
2097
|
+
if (this.standaloneAdmissionPending) {
|
|
2098
|
+
this.initialized = true;
|
|
2099
|
+
this.state("unavailable");
|
|
2100
|
+
this.emitReadyEvent();
|
|
2101
|
+
return;
|
|
2102
|
+
}
|
|
1961
2103
|
// Terminal intent is authoritative over normal widget admission. Restore it
|
|
1962
2104
|
// before bootstrap so a rejected, unavailable, or incompatible bootstrap
|
|
1963
2105
|
// cannot revive the session or strand a credential-backed End request.
|
|
@@ -1982,12 +2124,12 @@ export default class AiLiveAssist {
|
|
|
1982
2124
|
this.bootstrapAbort = controller;
|
|
1983
2125
|
const timeout = setTimeout(() => controller.abort(), Math.max(1000, Math.min(15000, this.options.bootstrapTimeoutMs ?? 15000)));
|
|
1984
2126
|
try {
|
|
1985
|
-
const bootstrap = await this.
|
|
2127
|
+
const bootstrap = await this.requestBootstrap(controller.signal);
|
|
1986
2128
|
if (this.destroyed)
|
|
1987
2129
|
return;
|
|
1988
2130
|
this.locale = resolveAiGuideLocale(bootstrap.locale, this.locale);
|
|
1989
2131
|
this.syncAgentDiscovery(bootstrap.agentAccess?.discoveryUrl ?? null);
|
|
1990
|
-
if (bootstrap.replayRecordingEnabled === false) {
|
|
2132
|
+
if (!this.guideAdmission && bootstrap.replayRecordingEnabled === false) {
|
|
1991
2133
|
this.bootstrap = bootstrap;
|
|
1992
2134
|
this.unavailableReason = REPLAY_RECORDING_REQUIRED_MESSAGE;
|
|
1993
2135
|
this.replayReadiness.disableRecording();
|
|
@@ -2008,6 +2150,9 @@ export default class AiLiveAssist {
|
|
|
2008
2150
|
(!bootstrap.capabilities.voice ||
|
|
2009
2151
|
!bootstrap.capabilities.voicePresence ||
|
|
2010
2152
|
!bootstrap.appearance?.voicePresence?.enabled))) {
|
|
2153
|
+
if (this.guideAdmission && !bootstrap.available && this.guideAdmission.pendingIntent()) {
|
|
2154
|
+
this.endInBackground();
|
|
2155
|
+
}
|
|
2011
2156
|
return;
|
|
2012
2157
|
}
|
|
2013
2158
|
if (bootstrap.widgetVersion &&
|
|
@@ -2018,6 +2163,17 @@ export default class AiLiveAssist {
|
|
|
2018
2163
|
!versionAtLeast(VERSION, bootstrap.minimumClientVersion)) {
|
|
2019
2164
|
return;
|
|
2020
2165
|
}
|
|
2166
|
+
if (bootstrap.providerProtocol === "live") {
|
|
2167
|
+
if (!this.guideAdmission || bootstrap.schemaVersion !== 3 || voicePresence)
|
|
2168
|
+
return;
|
|
2169
|
+
this.bootstrap = bootstrap;
|
|
2170
|
+
this.liveWidget = new LiveGuideWidget({ bootstrap, admission: this.guideAdmission, runtime: this.runtime,
|
|
2171
|
+
tabId: this.tabId, locale: this.locale, messages: this.options.messages, viewOptions: this.widgetViewOptions,
|
|
2172
|
+
acquire: () => this.lock.acquire(), release: () => this.lock.release(), onState: () => this.emitStateEvent() });
|
|
2173
|
+
this.view = this.liveWidget.view;
|
|
2174
|
+
this.lifecyclePhase = "ready";
|
|
2175
|
+
return;
|
|
2176
|
+
}
|
|
2021
2177
|
let resume = this.readResume();
|
|
2022
2178
|
const sharedTerminalIntent = this.readTerminalEndIntent();
|
|
2023
2179
|
const terminalIntent = resume?.terminalEnd ??
|
|
@@ -2066,7 +2222,7 @@ export default class AiLiveAssist {
|
|
|
2066
2222
|
this.transcriptRestoredFromCache = false;
|
|
2067
2223
|
this.view = voicePresenceView
|
|
2068
2224
|
? new VoicePresenceView(effectiveBootstrap, this.options.messages ?? {}, callbacks, this.tabId, (fallback) => void this.activateFallback(fallback), this.options.visualTestMode === true)
|
|
2069
|
-
: new WidgetView(effectiveBootstrap, this.options.messages ?? {}, callbacks);
|
|
2225
|
+
: new WidgetView(effectiveBootstrap, this.options.messages ?? {}, callbacks, this.standardWidgetViewOptions(effectiveBootstrap));
|
|
2070
2226
|
this.syncCompanionView();
|
|
2071
2227
|
this.initializePageAssistancePreference(effectiveBootstrap);
|
|
2072
2228
|
this.startMessengerIntegration(effectiveBootstrap);
|
|
@@ -2164,7 +2320,7 @@ export default class AiLiveAssist {
|
|
|
2164
2320
|
}
|
|
2165
2321
|
catch (error) {
|
|
2166
2322
|
if (!(error instanceof DOMException && error.name === "AbortError")) {
|
|
2167
|
-
this.
|
|
2323
|
+
this.presentSessionError(this.publicError(error), this.retryable(error));
|
|
2168
2324
|
}
|
|
2169
2325
|
}
|
|
2170
2326
|
finally {
|
|
@@ -2266,6 +2422,53 @@ export default class AiLiveAssist {
|
|
|
2266
2422
|
if (index >= 0)
|
|
2267
2423
|
this.queuedQuestions.splice(index, 1);
|
|
2268
2424
|
}
|
|
2425
|
+
restoreAdmittedTextLaunch(question, launchIdempotencyKey, pendingLaunch) {
|
|
2426
|
+
if (!question)
|
|
2427
|
+
return false;
|
|
2428
|
+
const ownsQuestion = this.pendingQuestion === question ||
|
|
2429
|
+
this.queuedQuestions.includes(question);
|
|
2430
|
+
if (!ownsQuestion)
|
|
2431
|
+
return false;
|
|
2432
|
+
this.removePendingQuestion(question);
|
|
2433
|
+
this.acceptedRequestIds.delete(question.requestId);
|
|
2434
|
+
if (this.pendingOpenIntent?.launchIdempotencyKey === launchIdempotencyKey) {
|
|
2435
|
+
this.pendingOpenIntent = null;
|
|
2436
|
+
}
|
|
2437
|
+
if (pendingLaunch &&
|
|
2438
|
+
this.lastLaunch &&
|
|
2439
|
+
this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
2440
|
+
this.lastLaunch = null;
|
|
2441
|
+
const staged = this.readStagedPendingLaunch();
|
|
2442
|
+
if (staged &&
|
|
2443
|
+
this.pendingLaunchMatches(staged.pendingLaunch, pendingLaunch) &&
|
|
2444
|
+
(staged.authority.ownerId === this.windowId ||
|
|
2445
|
+
staged.claimAuthority?.ownerId === this.windowId)) {
|
|
2446
|
+
this.clearStagedPendingLaunch(staged.pendingLaunch, staged.authority);
|
|
2447
|
+
}
|
|
2448
|
+
}
|
|
2449
|
+
if (this.destroyed || this.ended || this.terminalRequestPending) {
|
|
2450
|
+
return true;
|
|
2451
|
+
}
|
|
2452
|
+
if (this.view instanceof WidgetView) {
|
|
2453
|
+
this.view.showStartRetry(question.text, this.view.message("error"), question.submissionId);
|
|
2454
|
+
}
|
|
2455
|
+
else {
|
|
2456
|
+
this.presentSessionError(this.view?.message("error"), false, false);
|
|
2457
|
+
}
|
|
2458
|
+
this.state("error");
|
|
2459
|
+
return true;
|
|
2460
|
+
}
|
|
2461
|
+
settlePreRuntimeLaunchFailure(question, launchIdempotencyKey, pendingLaunch, allowFocusedHandoff) {
|
|
2462
|
+
if (this.restoreAdmittedTextLaunch(question, launchIdempotencyKey, pendingLaunch)) {
|
|
2463
|
+
return;
|
|
2464
|
+
}
|
|
2465
|
+
if (this.destroyed || this.ended || this.terminalRequestPending)
|
|
2466
|
+
return;
|
|
2467
|
+
if (allowFocusedHandoff && this.requestFocusedHandoff())
|
|
2468
|
+
return;
|
|
2469
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), true, false);
|
|
2470
|
+
this.state("error");
|
|
2471
|
+
}
|
|
2269
2472
|
bindQuestionToSupersededConfirmation(question) {
|
|
2270
2473
|
const identity = question.supersededConfirmation;
|
|
2271
2474
|
if (!identity)
|
|
@@ -2279,6 +2482,15 @@ export default class AiLiveAssist {
|
|
|
2279
2482
|
performPendingOpen() {
|
|
2280
2483
|
const intent = this.pendingOpenIntent;
|
|
2281
2484
|
const view = this.view;
|
|
2485
|
+
if (intent && this.liveWidget && !this.destroyed) {
|
|
2486
|
+
const questions = [this.pendingQuestion, ...this.queuedQuestions].filter((question) => question !== null);
|
|
2487
|
+
this.liveWidget.open({ mode: intent.mode });
|
|
2488
|
+
for (const question of questions) {
|
|
2489
|
+
this.liveWidget.open({ mode: "text", question: question.text, requestId: question.requestId });
|
|
2490
|
+
}
|
|
2491
|
+
this.clearPendingIntent();
|
|
2492
|
+
return;
|
|
2493
|
+
}
|
|
2282
2494
|
if (!intent ||
|
|
2283
2495
|
!view ||
|
|
2284
2496
|
this.destroyed ||
|
|
@@ -3974,12 +4186,18 @@ export default class AiLiveAssist {
|
|
|
3974
4186
|
}
|
|
3975
4187
|
return scopes;
|
|
3976
4188
|
}
|
|
4189
|
+
standardWidgetViewOptions(bootstrap) {
|
|
4190
|
+
return {
|
|
4191
|
+
...this.widgetViewOptions,
|
|
4192
|
+
manualTurnsSupported: bootstrap.voice?.turnMode === "manual",
|
|
4193
|
+
};
|
|
4194
|
+
}
|
|
3977
4195
|
createMessengerReturnView(bootstrap) {
|
|
3978
4196
|
const callbacks = this.widgetCallbacks();
|
|
3979
4197
|
if ((bootstrap.experienceMode ?? "standard") === "voice_presence") {
|
|
3980
4198
|
return new VoicePresenceView(bootstrap, this.options.messages ?? {}, callbacks, this.tabId, (fallback) => void this.activateFallback(fallback), this.options.visualTestMode === true);
|
|
3981
4199
|
}
|
|
3982
|
-
return new WidgetView(bootstrap, this.options.messages ?? {}, callbacks);
|
|
4200
|
+
return new WidgetView(bootstrap, this.options.messages ?? {}, callbacks, this.standardWidgetViewOptions(bootstrap));
|
|
3983
4201
|
}
|
|
3984
4202
|
freshAiReturnProvisionalFor(conversationId) {
|
|
3985
4203
|
const provisional = this.readFreshAiReturnProvisional();
|
|
@@ -4038,10 +4256,10 @@ export default class AiLiveAssist {
|
|
|
4038
4256
|
quiesceProvisionalFreshAiReturn() {
|
|
4039
4257
|
this.launchGeneration += 1;
|
|
4040
4258
|
this.clearReconnectTimer();
|
|
4041
|
-
this.media?.endPushToTalk();
|
|
4259
|
+
this.media?.endPushToTalk?.();
|
|
4042
4260
|
this.media?.setMuted(true);
|
|
4043
4261
|
this.pushActive = false;
|
|
4044
|
-
this.view?.setPushActive(false);
|
|
4262
|
+
this.view?.setPushActive?.(false);
|
|
4045
4263
|
this.view?.setMuted(true);
|
|
4046
4264
|
this.view?.setPaused(true);
|
|
4047
4265
|
this.cleanupTransport();
|
|
@@ -4527,10 +4745,12 @@ export default class AiLiveAssist {
|
|
|
4527
4745
|
return true;
|
|
4528
4746
|
}
|
|
4529
4747
|
async refreshCompanionBootstrap() {
|
|
4748
|
+
if (this.guideAdmission)
|
|
4749
|
+
return false;
|
|
4530
4750
|
const controller = new AbortController();
|
|
4531
4751
|
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
4532
4752
|
try {
|
|
4533
|
-
const bootstrap = await this.
|
|
4753
|
+
const bootstrap = await this.requestBootstrap(controller.signal);
|
|
4534
4754
|
if (this.destroyed)
|
|
4535
4755
|
return false;
|
|
4536
4756
|
this.bootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
@@ -4677,7 +4897,7 @@ export default class AiLiveAssist {
|
|
|
4677
4897
|
this.media?.setMuted(true);
|
|
4678
4898
|
return true;
|
|
4679
4899
|
}
|
|
4680
|
-
async restoreAiAfterFailedSupportSwitch(mode, sessionId, previousMuted
|
|
4900
|
+
async restoreAiAfterFailedSupportSwitch(mode, sessionId, previousMuted) {
|
|
4681
4901
|
const restored = await this.requestCompanionSurface("ai", mode, idempotencyKey("companion_reconcile"), sessionId);
|
|
4682
4902
|
if (!restored) {
|
|
4683
4903
|
this.media?.endPushToTalk();
|
|
@@ -4696,10 +4916,13 @@ export default class AiLiveAssist {
|
|
|
4696
4916
|
this.view?.setPaused(false);
|
|
4697
4917
|
this.media?.setMuted(previousMuted);
|
|
4698
4918
|
this.view?.setMuted(previousMuted);
|
|
4699
|
-
|
|
4700
|
-
|
|
4701
|
-
|
|
4702
|
-
|
|
4919
|
+
// The provider-side push was cancelled before the surface transition.
|
|
4920
|
+
// Restoring the old local capture here would have no fresh push authority
|
|
4921
|
+
// and could transmit behind a still-running panel transition. Return to a
|
|
4922
|
+
// clean, ready manual-turn state and require a new visitor press instead.
|
|
4923
|
+
this.media?.endPushToTalk();
|
|
4924
|
+
this.pushActive = false;
|
|
4925
|
+
this.view?.setPushActive(false);
|
|
4703
4926
|
this.closeMessengerBeforeOpen();
|
|
4704
4927
|
await this.prepareMessengerIntegration();
|
|
4705
4928
|
return true;
|
|
@@ -4855,7 +5078,6 @@ export default class AiLiveAssist {
|
|
|
4855
5078
|
return;
|
|
4856
5079
|
}
|
|
4857
5080
|
const previousMuted = this.media?.isMuted ?? false;
|
|
4858
|
-
const previousPushActive = this.pushActive;
|
|
4859
5081
|
// Quiesce capture before the AI surface begins its hide/morph. The server
|
|
4860
5082
|
// has already paused the session, so no microphone track may remain live
|
|
4861
5083
|
// while Messenger visibility is being confirmed.
|
|
@@ -4867,7 +5089,7 @@ export default class AiLiveAssist {
|
|
|
4867
5089
|
this.view?.setPaused(true);
|
|
4868
5090
|
const suspended = await this.suspendAiSurfaceForMessenger(switchedCurrent);
|
|
4869
5091
|
if (!suspended || !switchedCurrent()) {
|
|
4870
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5092
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4871
5093
|
return;
|
|
4872
5094
|
}
|
|
4873
5095
|
const switchGuard = {
|
|
@@ -4889,12 +5111,12 @@ export default class AiLiveAssist {
|
|
|
4889
5111
|
}
|
|
4890
5112
|
}
|
|
4891
5113
|
if (!opened || !switchedCurrent()) {
|
|
4892
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5114
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4893
5115
|
return;
|
|
4894
5116
|
}
|
|
4895
5117
|
const returnActivated = await this.createMessengerReturnActivationPromise(messenger, displayId);
|
|
4896
5118
|
if (!returnActivated || !switchedCurrent()) {
|
|
4897
|
-
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted
|
|
5119
|
+
await this.restoreAiAfterFailedSupportSwitch(mode, result.sessionId, previousMuted);
|
|
4898
5120
|
return;
|
|
4899
5121
|
}
|
|
4900
5122
|
this.messenger = messenger;
|
|
@@ -6067,6 +6289,35 @@ export default class AiLiveAssist {
|
|
|
6067
6289
|
}
|
|
6068
6290
|
widgetCallbacks() {
|
|
6069
6291
|
return {
|
|
6292
|
+
onRecordingConsent: (allowed) => {
|
|
6293
|
+
if (!this.guideAdmission?.recordingConfigured)
|
|
6294
|
+
return;
|
|
6295
|
+
// Recording can outlive an AI conversation; its opt-out remains usable.
|
|
6296
|
+
if (!allowed)
|
|
6297
|
+
this.guideAdmission.setRecordingChoice(false);
|
|
6298
|
+
if (!this.result || this.ended || this.terminalRequestPending)
|
|
6299
|
+
return;
|
|
6300
|
+
if (allowed && !this.guideAdmission.setRecordingChoice(true)) {
|
|
6301
|
+
if (this.view instanceof WidgetView)
|
|
6302
|
+
this.view.setRecordingConsent(false);
|
|
6303
|
+
return;
|
|
6304
|
+
}
|
|
6305
|
+
const scopes = this.scopes.filter(scope => scope !== "session_recording");
|
|
6306
|
+
if (allowed)
|
|
6307
|
+
scopes.push("session_recording");
|
|
6308
|
+
// Revocation stops owned capture immediately; enabling waits for the
|
|
6309
|
+
// server's authoritative consent.updated acknowledgement.
|
|
6310
|
+
if (!allowed)
|
|
6311
|
+
this.guideAdmission.updateRecordingConsent(scopes);
|
|
6312
|
+
this.scopes = scopes;
|
|
6313
|
+
if (!allowed) {
|
|
6314
|
+
const record = this.readResume();
|
|
6315
|
+
if (record)
|
|
6316
|
+
this.storeResume({ ...record, scopes: [...scopes] });
|
|
6317
|
+
}
|
|
6318
|
+
this.send("consent.update", { scopes, locale: this.locale });
|
|
6319
|
+
},
|
|
6320
|
+
onCtaResult: (result) => this.resolveCtaOffer(result),
|
|
6070
6321
|
onStart: (mode, scopes, initialQuestion) => {
|
|
6071
6322
|
// Voice-presence has no separate restart control. Treat its explicit
|
|
6072
6323
|
// post-terminal Start as the same controller-owned new-session gate.
|
|
@@ -6078,6 +6329,7 @@ export default class AiLiveAssist {
|
|
|
6078
6329
|
this.recoveryBusy()) {
|
|
6079
6330
|
return false;
|
|
6080
6331
|
}
|
|
6332
|
+
let admittedQuestion = null;
|
|
6081
6333
|
if (initialQuestion) {
|
|
6082
6334
|
if (this.pendingQuestionCount() >= PUBLIC_QUESTION_QUEUE_CAPACITY) {
|
|
6083
6335
|
this.view?.setStatus(PUBLIC_QUESTION_BUSY_MESSAGE);
|
|
@@ -6091,6 +6343,16 @@ export default class AiLiveAssist {
|
|
|
6091
6343
|
this.acceptedRequestIds.delete(requestId);
|
|
6092
6344
|
return false;
|
|
6093
6345
|
}
|
|
6346
|
+
admittedQuestion = question;
|
|
6347
|
+
if (this.view instanceof WidgetView) {
|
|
6348
|
+
this.view.addCaption("user", question.text, true, {
|
|
6349
|
+
localQuestionId: question.submissionId,
|
|
6350
|
+
});
|
|
6351
|
+
}
|
|
6352
|
+
else {
|
|
6353
|
+
this.view?.addCaption("user", question.text, true);
|
|
6354
|
+
}
|
|
6355
|
+
question.shown = true;
|
|
6094
6356
|
}
|
|
6095
6357
|
const launchKey = this.pendingOpenIntent?.launchIdempotencyKey ??
|
|
6096
6358
|
idempotencyKey("launch");
|
|
@@ -6107,9 +6369,21 @@ export default class AiLiveAssist {
|
|
|
6107
6369
|
if (this.destroyed ||
|
|
6108
6370
|
this.ended ||
|
|
6109
6371
|
this.terminalRequestPending ||
|
|
6110
|
-
this.recoveryBusy())
|
|
6372
|
+
this.recoveryBusy()) {
|
|
6373
|
+
if (mode !== "text" ||
|
|
6374
|
+
!this.restoreAdmittedTextLaunch(admittedQuestion ?? undefined, launchKey)) {
|
|
6375
|
+
if (!this.destroyed &&
|
|
6376
|
+
!this.ended &&
|
|
6377
|
+
!this.terminalRequestPending) {
|
|
6378
|
+
this.presentSessionError(this.view?.message("error"), false, false);
|
|
6379
|
+
this.state("error");
|
|
6380
|
+
}
|
|
6381
|
+
}
|
|
6111
6382
|
return;
|
|
6112
|
-
|
|
6383
|
+
}
|
|
6384
|
+
void this.launch(mode, scopes, launchKey, {
|
|
6385
|
+
...(admittedQuestion ? { admittedQuestion } : {}),
|
|
6386
|
+
});
|
|
6113
6387
|
});
|
|
6114
6388
|
return true;
|
|
6115
6389
|
},
|
|
@@ -6159,9 +6433,9 @@ export default class AiLiveAssist {
|
|
|
6159
6433
|
onFeedback: (outcome) => void this.submitFeedback(outcome),
|
|
6160
6434
|
onRetry: () => void this.retry(),
|
|
6161
6435
|
onPlaybackState: (value) => {
|
|
6162
|
-
|
|
6163
|
-
|
|
6164
|
-
|
|
6436
|
+
this.media?.setAssistantPlaybackAudible(value.state === "playing" && value.audible);
|
|
6437
|
+
this.pendingPlaybackState = { ...value };
|
|
6438
|
+
this.flushPlaybackState();
|
|
6165
6439
|
},
|
|
6166
6440
|
onOpenChange: (open) => this.handleViewOpenChange(open),
|
|
6167
6441
|
};
|
|
@@ -6181,6 +6455,7 @@ export default class AiLiveAssist {
|
|
|
6181
6455
|
// fenced. Disconnect callbacks therefore cannot schedule a replacement
|
|
6182
6456
|
// session with the retiring credentials.
|
|
6183
6457
|
this.queuedLaunchToken = null;
|
|
6458
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
6184
6459
|
this.launchGeneration =
|
|
6185
6460
|
(Number.isSafeInteger(this.launchGeneration)
|
|
6186
6461
|
? this.launchGeneration
|
|
@@ -6220,6 +6495,7 @@ export default class AiLiveAssist {
|
|
|
6220
6495
|
this.visualConsentGranted = false;
|
|
6221
6496
|
this.manualTurn = false;
|
|
6222
6497
|
this.pushActive = false;
|
|
6498
|
+
this.pendingPlaybackState = null;
|
|
6223
6499
|
this.ended = false;
|
|
6224
6500
|
this.replayReadiness.startFreshSessionIfInactive?.();
|
|
6225
6501
|
this.state("ready");
|
|
@@ -6402,7 +6678,7 @@ export default class AiLiveAssist {
|
|
|
6402
6678
|
this.view?.destroy();
|
|
6403
6679
|
if (!isCurrent())
|
|
6404
6680
|
return;
|
|
6405
|
-
this.view = new WidgetView(fallbackBootstrap, this.options.messages ?? {}, this.widgetCallbacks());
|
|
6681
|
+
this.view = new WidgetView(fallbackBootstrap, this.options.messages ?? {}, this.widgetCallbacks(), this.standardWidgetViewOptions(fallbackBootstrap));
|
|
6406
6682
|
this.startMessengerIntegration(fallbackBootstrap);
|
|
6407
6683
|
if (isCurrent())
|
|
6408
6684
|
this.state("fallback_standard_offered");
|
|
@@ -6419,7 +6695,7 @@ export default class AiLiveAssist {
|
|
|
6419
6695
|
}
|
|
6420
6696
|
if (!offered.has("handoff_context")) {
|
|
6421
6697
|
if (isCurrent()) {
|
|
6422
|
-
this.
|
|
6698
|
+
this.presentSessionError(this.view?.message("humanUnavailable"), false, false);
|
|
6423
6699
|
}
|
|
6424
6700
|
return;
|
|
6425
6701
|
}
|
|
@@ -6446,6 +6722,7 @@ export default class AiLiveAssist {
|
|
|
6446
6722
|
this.ended ||
|
|
6447
6723
|
this.destroyed ||
|
|
6448
6724
|
this.recoveryBusy()) {
|
|
6725
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6449
6726
|
releaseMessengerReturnIfPreRuntime();
|
|
6450
6727
|
return;
|
|
6451
6728
|
}
|
|
@@ -6456,9 +6733,11 @@ export default class AiLiveAssist {
|
|
|
6456
6733
|
!this.destroyed;
|
|
6457
6734
|
const bootstrap = this.bootstrap;
|
|
6458
6735
|
if (!bootstrap?.configRevision || !bootstrap.consent || !this.view) {
|
|
6736
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6459
6737
|
releaseMessengerReturnIfPreRuntime();
|
|
6460
6738
|
return;
|
|
6461
6739
|
}
|
|
6740
|
+
const launchConsentProof = this.capturePendingLaunchConsentProof(bootstrap);
|
|
6462
6741
|
const retryIntent = options.pendingLaunch;
|
|
6463
6742
|
if (retryIntent &&
|
|
6464
6743
|
canonicalJson({ mode, scopes, idempotencyKey: launchIdempotencyKey }) !==
|
|
@@ -6467,6 +6746,7 @@ export default class AiLiveAssist {
|
|
|
6467
6746
|
scopes: retryIntent.scopes,
|
|
6468
6747
|
idempotencyKey: retryIntent.idempotencyKey,
|
|
6469
6748
|
})) {
|
|
6749
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey);
|
|
6470
6750
|
releaseMessengerReturnIfPreRuntime();
|
|
6471
6751
|
return;
|
|
6472
6752
|
}
|
|
@@ -6474,14 +6754,16 @@ export default class AiLiveAssist {
|
|
|
6474
6754
|
? bindPendingLaunchIntent(retryIntent, bootstrap)
|
|
6475
6755
|
: freshPendingLaunchIntent(mode, scopes, launchIdempotencyKey, bootstrap);
|
|
6476
6756
|
if (!durableLaunch) {
|
|
6477
|
-
this.
|
|
6757
|
+
if (!this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey)) {
|
|
6758
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
6759
|
+
}
|
|
6478
6760
|
releaseMessengerReturnIfPreRuntime();
|
|
6479
6761
|
return;
|
|
6480
6762
|
}
|
|
6481
6763
|
const { experienceMode, protocolVersion } = durableLaunch;
|
|
6482
6764
|
const voicePresence = experienceMode === "voice_presence";
|
|
6483
6765
|
if (voicePresence && mode !== "voice") {
|
|
6484
|
-
this.
|
|
6766
|
+
this.presentSessionError("Voice assist requires microphone access.", false, false);
|
|
6485
6767
|
releaseMessengerReturnIfPreRuntime();
|
|
6486
6768
|
return;
|
|
6487
6769
|
}
|
|
@@ -6507,7 +6789,7 @@ export default class AiLiveAssist {
|
|
|
6507
6789
|
this.state("reconnecting");
|
|
6508
6790
|
const handoffRequested = this.requestFocusedHandoff();
|
|
6509
6791
|
if (handoffRequested === false) {
|
|
6510
|
-
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration);
|
|
6792
|
+
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, false, launchConsentProof);
|
|
6511
6793
|
}
|
|
6512
6794
|
releaseMessengerReturnIfPreRuntime();
|
|
6513
6795
|
return;
|
|
@@ -6519,7 +6801,7 @@ export default class AiLiveAssist {
|
|
|
6519
6801
|
if (!this.lock.acquire()) {
|
|
6520
6802
|
this.view.showActiveElsewhere(false);
|
|
6521
6803
|
this.launchInFlight = false;
|
|
6522
|
-
this.
|
|
6804
|
+
this.settlePreRuntimeLaunchFailure(options.admittedQuestion, launchIdempotencyKey, durableLaunch, true);
|
|
6523
6805
|
releaseMessengerReturnIfPreRuntime();
|
|
6524
6806
|
return;
|
|
6525
6807
|
}
|
|
@@ -6538,12 +6820,14 @@ export default class AiLiveAssist {
|
|
|
6538
6820
|
this.state("requesting_access");
|
|
6539
6821
|
let runtimeSessionCreated = false;
|
|
6540
6822
|
let media = null;
|
|
6823
|
+
let startupDeadline = null;
|
|
6824
|
+
let startupDeadlineExceeded = false;
|
|
6541
6825
|
try {
|
|
6542
6826
|
this.replayReadiness.startFreshSessionIfInactive?.();
|
|
6543
|
-
const replay = await this.
|
|
6827
|
+
const replay = await this.sessionConnectionScope();
|
|
6544
6828
|
if (this.destroyed || this.ended)
|
|
6545
6829
|
return;
|
|
6546
|
-
this.
|
|
6830
|
+
this.assertSessionConnectionScope(replay);
|
|
6547
6831
|
const controller = new AbortController();
|
|
6548
6832
|
const connectionGeneration = this.beginConnectionAttempt(controller);
|
|
6549
6833
|
const assertConnectionCurrent = () => this.assertConnectionCurrent(controller, connectionGeneration, replay, options.messengerReturnAuthority, activeMode, launchIdempotencyKey);
|
|
@@ -6569,30 +6853,10 @@ export default class AiLiveAssist {
|
|
|
6569
6853
|
throw error;
|
|
6570
6854
|
}
|
|
6571
6855
|
assertConnectionCurrent();
|
|
6572
|
-
if (
|
|
6573
|
-
|
|
6574
|
-
!bootstrap.capabilities?.text ||
|
|
6575
|
-
options.messengerReturnAuthority !== undefined ||
|
|
6576
|
-
retryIntent !== undefined) {
|
|
6577
|
-
throw error;
|
|
6856
|
+
if (mode === "voice") {
|
|
6857
|
+
throw new InitialVoiceMicrophoneUnavailableError(error);
|
|
6578
6858
|
}
|
|
6579
|
-
|
|
6580
|
-
activeMode = "text";
|
|
6581
|
-
activeScopes = activeScopes.filter((scope) => scope !== "microphone");
|
|
6582
|
-
this.manualTurn = false;
|
|
6583
|
-
media = this.createMedia(() => {
|
|
6584
|
-
try {
|
|
6585
|
-
assertConnectionCurrent();
|
|
6586
|
-
return true;
|
|
6587
|
-
}
|
|
6588
|
-
catch {
|
|
6589
|
-
return false;
|
|
6590
|
-
}
|
|
6591
|
-
});
|
|
6592
|
-
this.media = media;
|
|
6593
|
-
if (options.startMuted === true)
|
|
6594
|
-
media.setMuted(true);
|
|
6595
|
-
this.view.setStatus(this.view.message("microphoneUnavailable"));
|
|
6859
|
+
throw error;
|
|
6596
6860
|
}
|
|
6597
6861
|
assertConnectionCurrent();
|
|
6598
6862
|
if (voicePresence)
|
|
@@ -6621,18 +6885,23 @@ export default class AiLiveAssist {
|
|
|
6621
6885
|
this.releaseMedia(media);
|
|
6622
6886
|
this.cleanupTransport();
|
|
6623
6887
|
this.lock.release();
|
|
6888
|
+
this.settlePreRuntimeLaunchFailure(options.admittedQuestion, launchIdempotencyKey, durableLaunch, false);
|
|
6624
6889
|
return;
|
|
6625
6890
|
}
|
|
6891
|
+
const startupDeadlineFailure = new Promise((_resolve, reject) => {
|
|
6892
|
+
startupDeadline = setTimeout(() => {
|
|
6893
|
+
startupDeadlineExceeded = true;
|
|
6894
|
+
controller.abort();
|
|
6895
|
+
reject(new InitialSessionStartupDeadlineError());
|
|
6896
|
+
}, INITIAL_SESSION_STARTUP_TIMEOUT_MS);
|
|
6897
|
+
});
|
|
6626
6898
|
const requestedLaunchPath = path();
|
|
6627
6899
|
runtimeLaunchStarted = true;
|
|
6628
|
-
const authorization = this.
|
|
6629
|
-
siteKey: this.siteKey,
|
|
6900
|
+
const authorization = this.requestLaunch({
|
|
6630
6901
|
configRevision: bootstrap.configRevision,
|
|
6631
6902
|
path: requestedLaunchPath,
|
|
6632
6903
|
tabId: this.tabId,
|
|
6633
6904
|
mode: activeMode,
|
|
6634
|
-
anonymousId: this.visitorId(),
|
|
6635
|
-
replay,
|
|
6636
6905
|
disclosureChecksum: bootstrap.consent.disclosureChecksum,
|
|
6637
6906
|
scopes: activeScopes,
|
|
6638
6907
|
locale: this.locale,
|
|
@@ -6646,12 +6915,12 @@ export default class AiLiveAssist {
|
|
|
6646
6915
|
: {}),
|
|
6647
6916
|
lowPower: this.lowPowerMode(),
|
|
6648
6917
|
idempotencyKey: launchIdempotencyKey,
|
|
6649
|
-
}, controller.signal);
|
|
6918
|
+
}, replay, controller.signal);
|
|
6650
6919
|
this.pendingSessionAuthorization = authorization;
|
|
6651
6920
|
this.pendingSessionAuthorizationController = controller;
|
|
6652
6921
|
let result;
|
|
6653
6922
|
try {
|
|
6654
|
-
result = await authorization;
|
|
6923
|
+
result = await Promise.race([authorization, startupDeadlineFailure]);
|
|
6655
6924
|
}
|
|
6656
6925
|
finally {
|
|
6657
6926
|
if (this.pendingSessionAuthorization === authorization) {
|
|
@@ -6661,7 +6930,7 @@ export default class AiLiveAssist {
|
|
|
6661
6930
|
}
|
|
6662
6931
|
}
|
|
6663
6932
|
}
|
|
6664
|
-
if (result
|
|
6933
|
+
if (!this.matchesLaunchSchema(result, protocolVersion) ||
|
|
6665
6934
|
result.protocolVersion !== protocolVersion ||
|
|
6666
6935
|
result.experienceMode !== experienceMode) {
|
|
6667
6936
|
throw new RuntimeClientError("PROTOCOL_INVALID", "The voice assist runtime returned an incompatible session.", false, null, 502);
|
|
@@ -6690,18 +6959,26 @@ export default class AiLiveAssist {
|
|
|
6690
6959
|
!this.acceptStagedPendingLaunch(durableLaunch, result))) {
|
|
6691
6960
|
throw new RuntimeClientError("RESUME_STORAGE_UNAVAILABLE", "The session could not be stored for recovery.", true, null, 503);
|
|
6692
6961
|
}
|
|
6693
|
-
await Promise.
|
|
6962
|
+
await Promise.race([
|
|
6694
6963
|
this.connectTransport(result, activeMode, activeScopes, false, controller, media, assertConnectionCurrent),
|
|
6695
|
-
|
|
6696
|
-
? Promise.resolve(false)
|
|
6697
|
-
: this.associateFreshCompanionSession(activeMode, result.sessionId),
|
|
6964
|
+
startupDeadlineFailure,
|
|
6698
6965
|
]);
|
|
6966
|
+
if (startupDeadline !== null) {
|
|
6967
|
+
clearTimeout(startupDeadline);
|
|
6968
|
+
startupDeadline = null;
|
|
6969
|
+
}
|
|
6970
|
+
if (options.associateCompanion !== false) {
|
|
6971
|
+
await this.associateFreshCompanionSession(activeMode, result.sessionId);
|
|
6972
|
+
}
|
|
6699
6973
|
if (options.startMuted === true && activeMode === "voice") {
|
|
6700
6974
|
media.setMuted(true);
|
|
6701
6975
|
this.view?.setMuted(true);
|
|
6702
6976
|
}
|
|
6703
6977
|
this.reconnectAttempts = 0;
|
|
6704
6978
|
this.visitorActiveEligibilityRecheckKey = null;
|
|
6979
|
+
if (this.initialLaunchDeadlineRetryKey === launchIdempotencyKey) {
|
|
6980
|
+
this.initialLaunchDeadlineRetryKey = null;
|
|
6981
|
+
}
|
|
6705
6982
|
this.lastLaunch = null;
|
|
6706
6983
|
}
|
|
6707
6984
|
catch (error) {
|
|
@@ -6715,11 +6992,60 @@ export default class AiLiveAssist {
|
|
|
6715
6992
|
this.lock.release();
|
|
6716
6993
|
if (!launchIsCurrent())
|
|
6717
6994
|
return;
|
|
6718
|
-
const
|
|
6995
|
+
const effectiveError = startupDeadlineExceeded
|
|
6996
|
+
? new InitialSessionStartupDeadlineError()
|
|
6997
|
+
: error;
|
|
6998
|
+
if (effectiveError instanceof InitialSessionStartupDeadlineError &&
|
|
6999
|
+
!runtimeSessionCreated &&
|
|
7000
|
+
options.messengerReturnAuthority === undefined &&
|
|
7001
|
+
this.initialLaunchDeadlineRetryKey !== launchIdempotencyKey) {
|
|
7002
|
+
const retryLaunch = durableLaunch;
|
|
7003
|
+
this.initialLaunchDeadlineRetryKey = launchIdempotencyKey;
|
|
7004
|
+
this.view?.showConnecting(true, retryLaunch.mode);
|
|
7005
|
+
this.state("reconnecting");
|
|
7006
|
+
queueMicrotask(() => {
|
|
7007
|
+
if (!launchIsCurrent() ||
|
|
7008
|
+
this.launchInFlight ||
|
|
7009
|
+
!this.lastLaunch ||
|
|
7010
|
+
!this.pendingLaunchMatches(this.lastLaunch, retryLaunch)) {
|
|
7011
|
+
return;
|
|
7012
|
+
}
|
|
7013
|
+
void this.launch(retryLaunch.mode, retryLaunch.scopes, retryLaunch.idempotencyKey, {
|
|
7014
|
+
...(options.startMuted === undefined
|
|
7015
|
+
? {}
|
|
7016
|
+
: { startMuted: options.startMuted }),
|
|
7017
|
+
...(options.associateCompanion === undefined
|
|
7018
|
+
? {}
|
|
7019
|
+
: { associateCompanion: options.associateCompanion }),
|
|
7020
|
+
...(options.admittedQuestion
|
|
7021
|
+
? { admittedQuestion: options.admittedQuestion }
|
|
7022
|
+
: {}),
|
|
7023
|
+
pendingLaunch: retryLaunch,
|
|
7024
|
+
});
|
|
7025
|
+
});
|
|
7026
|
+
return;
|
|
7027
|
+
}
|
|
7028
|
+
if (effectiveError instanceof InitialSessionStartupDeadlineError &&
|
|
7029
|
+
runtimeSessionCreated) {
|
|
7030
|
+
this.view?.showConnecting(true, activeMode);
|
|
7031
|
+
this.state("reconnecting");
|
|
7032
|
+
this.scheduleReconnect(true);
|
|
7033
|
+
return;
|
|
7034
|
+
}
|
|
7035
|
+
if (!runtimeLaunchStarted &&
|
|
7036
|
+
this.restoreAdmittedTextLaunch(options.admittedQuestion, launchIdempotencyKey, durableLaunch)) {
|
|
7037
|
+
return;
|
|
7038
|
+
}
|
|
7039
|
+
const limited = await this.applyVisitorLimitFailure(effectiveError, launchIsCurrent, launchConsentProof);
|
|
6719
7040
|
if (!launchIsCurrent())
|
|
6720
7041
|
return;
|
|
6721
7042
|
if (!limited) {
|
|
6722
|
-
|
|
7043
|
+
if (effectiveError instanceof InitialVoiceMicrophoneUnavailableError) {
|
|
7044
|
+
this.presentSessionError(this.view?.message("microphoneUnavailable"), false, false);
|
|
7045
|
+
}
|
|
7046
|
+
else {
|
|
7047
|
+
this.presentSessionError(this.publicError(effectiveError), this.retryable(effectiveError), runtimeSessionCreated);
|
|
7048
|
+
}
|
|
6723
7049
|
}
|
|
6724
7050
|
if (!launchIsCurrent())
|
|
6725
7051
|
return;
|
|
@@ -6730,33 +7056,81 @@ export default class AiLiveAssist {
|
|
|
6730
7056
|
this.state("error");
|
|
6731
7057
|
}
|
|
6732
7058
|
finally {
|
|
7059
|
+
if (startupDeadline !== null)
|
|
7060
|
+
clearTimeout(startupDeadline);
|
|
6733
7061
|
releaseMessengerReturnIfPreRuntime();
|
|
6734
7062
|
this.launchInFlight = false;
|
|
6735
7063
|
this.drainPendingFocusedHandoff();
|
|
6736
7064
|
}
|
|
6737
7065
|
}
|
|
6738
|
-
|
|
6739
|
-
if (!
|
|
6740
|
-
!(
|
|
6741
|
-
|
|
7066
|
+
capturePendingLaunchConsentProof(bootstrap) {
|
|
7067
|
+
if (!bootstrap?.consent ||
|
|
7068
|
+
!Number.isSafeInteger(bootstrap.configRevision) ||
|
|
7069
|
+
(bootstrap.configRevision ?? 0) <= 0) {
|
|
7070
|
+
return null;
|
|
7071
|
+
}
|
|
7072
|
+
return {
|
|
7073
|
+
configRevision: bootstrap.configRevision,
|
|
7074
|
+
consentSignature: canonicalJson(bootstrap.consent),
|
|
7075
|
+
};
|
|
7076
|
+
}
|
|
7077
|
+
pendingLaunchConsentProofMatches(proof, bootstrap) {
|
|
7078
|
+
const current = this.capturePendingLaunchConsentProof(bootstrap);
|
|
7079
|
+
return Boolean(proof &&
|
|
7080
|
+
current &&
|
|
7081
|
+
proof.configRevision === current.configRevision &&
|
|
7082
|
+
proof.consentSignature === current.consentSignature);
|
|
7083
|
+
}
|
|
7084
|
+
finishVisitorActiveConsentRefresh(pendingLaunch) {
|
|
7085
|
+
if (pendingLaunch &&
|
|
7086
|
+
this.lastLaunch &&
|
|
7087
|
+
!this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
7088
|
+
return;
|
|
7089
|
+
}
|
|
7090
|
+
this.visitorActiveTakeoverOnly = false;
|
|
7091
|
+
this.visitorActiveEligibilityRecheckKey = null;
|
|
7092
|
+
this.clearOwnedStagedPendingLaunch();
|
|
7093
|
+
this.lastLaunch = null;
|
|
7094
|
+
this.clearPendingIntent();
|
|
7095
|
+
this.view?.showActiveElsewhere(false);
|
|
7096
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
7097
|
+
this.state("error");
|
|
7098
|
+
}
|
|
7099
|
+
async applyVisitorLimitFailure(error, isCurrent, launchConsentProof = this.capturePendingLaunchConsentProof(this.bootstrap)) {
|
|
7100
|
+
const visitorActiveConflict = error instanceof RuntimeClientError &&
|
|
7101
|
+
error.code === "CONCURRENCY_LIMIT" &&
|
|
7102
|
+
error.status === 409;
|
|
7103
|
+
const visitorRateLimit = error instanceof RuntimeClientError &&
|
|
7104
|
+
error.code === "RATE_LIMITED" &&
|
|
7105
|
+
error.status === 429;
|
|
7106
|
+
if (!isCurrent() || (!visitorActiveConflict && !visitorRateLimit)) {
|
|
6742
7107
|
return false;
|
|
6743
7108
|
}
|
|
6744
7109
|
const controller = new AbortController();
|
|
6745
7110
|
this.visitorLimitAbort?.abort();
|
|
6746
7111
|
this.visitorLimitAbort = controller;
|
|
7112
|
+
const aborted = new Promise((resolve) => {
|
|
7113
|
+
controller.signal.addEventListener("abort", () => resolve(null), {
|
|
7114
|
+
once: true,
|
|
7115
|
+
});
|
|
7116
|
+
});
|
|
6747
7117
|
const timeout = setTimeout(() => controller.abort(), 5000);
|
|
6748
7118
|
try {
|
|
6749
|
-
const bootstrap = await
|
|
6750
|
-
|
|
7119
|
+
const bootstrap = await Promise.race([
|
|
7120
|
+
this.requestBootstrap(controller.signal),
|
|
7121
|
+
aborted,
|
|
7122
|
+
]);
|
|
7123
|
+
if (!bootstrap || !isCurrent() || controller.signal.aborted)
|
|
6751
7124
|
return false;
|
|
6752
7125
|
const effectiveBootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
6753
7126
|
if (!isCurrent() || controller.signal.aborted)
|
|
6754
7127
|
return false;
|
|
6755
|
-
this.bootstrap = effectiveBootstrap;
|
|
6756
7128
|
const status = bootstrap.visitorEligibility?.status;
|
|
6757
7129
|
if (status === "visitor_limited") {
|
|
7130
|
+
this.bootstrap = effectiveBootstrap;
|
|
6758
7131
|
if (!isCurrent() || controller.signal.aborted)
|
|
6759
7132
|
return false;
|
|
7133
|
+
this.clearPendingIntent();
|
|
6760
7134
|
if (bootstrap.appearance?.hideLauncherWhenVisitorLimited !== false) {
|
|
6761
7135
|
if (!isCurrent() || controller.signal.aborted)
|
|
6762
7136
|
return false;
|
|
@@ -6770,24 +7144,41 @@ export default class AiLiveAssist {
|
|
|
6770
7144
|
return true;
|
|
6771
7145
|
}
|
|
6772
7146
|
if (status === "cooldown_limited") {
|
|
7147
|
+
this.bootstrap = effectiveBootstrap;
|
|
6773
7148
|
if (!isCurrent() || controller.signal.aborted)
|
|
6774
7149
|
return false;
|
|
7150
|
+
this.clearPendingIntent();
|
|
6775
7151
|
this.view?.showLaunchUnavailable(this.view.message("visitorCooldown"));
|
|
6776
7152
|
return true;
|
|
6777
7153
|
}
|
|
6778
7154
|
if (status === "visitor_active") {
|
|
7155
|
+
if (!visitorActiveConflict)
|
|
7156
|
+
return false;
|
|
6779
7157
|
if (!isCurrent() || controller.signal.aborted)
|
|
6780
7158
|
return false;
|
|
7159
|
+
const pendingLaunch = this.lastLaunch;
|
|
7160
|
+
if (!pendingLaunch ||
|
|
7161
|
+
!this.pendingLaunchConsentProofMatches(launchConsentProof, effectiveBootstrap)) {
|
|
7162
|
+
this.finishVisitorActiveConsentRefresh(pendingLaunch);
|
|
7163
|
+
return true;
|
|
7164
|
+
}
|
|
7165
|
+
this.bootstrap = effectiveBootstrap;
|
|
6781
7166
|
const displayMode = this.lastLaunch?.mode ?? this.mode;
|
|
6782
7167
|
this.visitorActiveTakeoverOnly = true;
|
|
6783
7168
|
this.clearOwnedStagedPendingLaunch();
|
|
6784
7169
|
this.view?.showActiveElsewhere(false);
|
|
6785
7170
|
this.view?.showConnecting(true, displayMode);
|
|
6786
7171
|
this.state("reconnecting");
|
|
6787
|
-
const pendingLaunch = this.lastLaunch;
|
|
6788
7172
|
const handoffRequested = this.requestFocusedHandoff();
|
|
6789
7173
|
if (pendingLaunch && handoffRequested === false) {
|
|
6790
|
-
|
|
7174
|
+
const recheckGeneration = this.launchGeneration;
|
|
7175
|
+
setTimeout(() => {
|
|
7176
|
+
if (recheckGeneration !== this.launchGeneration ||
|
|
7177
|
+
this.launchInFlight) {
|
|
7178
|
+
return;
|
|
7179
|
+
}
|
|
7180
|
+
this.beginVisitorActiveEligibilityRecheck(pendingLaunch, recheckGeneration, false, launchConsentProof);
|
|
7181
|
+
}, 0);
|
|
6791
7182
|
}
|
|
6792
7183
|
return true;
|
|
6793
7184
|
}
|
|
@@ -6803,7 +7194,7 @@ export default class AiLiveAssist {
|
|
|
6803
7194
|
}
|
|
6804
7195
|
return false;
|
|
6805
7196
|
}
|
|
6806
|
-
beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, recoveredOwnership = false) {
|
|
7197
|
+
beginVisitorActiveEligibilityRecheck(pendingLaunch, launchGeneration, recoveredOwnership = false, launchConsentProof = this.capturePendingLaunchConsentProof(this.bootstrap)) {
|
|
6807
7198
|
if (!this.visitorActiveTakeoverOnly ||
|
|
6808
7199
|
this.terminalRequestPending ||
|
|
6809
7200
|
this.ended ||
|
|
@@ -6869,7 +7260,7 @@ export default class AiLiveAssist {
|
|
|
6869
7260
|
operation = (async () => {
|
|
6870
7261
|
try {
|
|
6871
7262
|
const bootstrap = await Promise.race([
|
|
6872
|
-
this.
|
|
7263
|
+
this.requestBootstrap(controller.signal),
|
|
6873
7264
|
aborted,
|
|
6874
7265
|
]);
|
|
6875
7266
|
if (!bootstrap) {
|
|
@@ -6896,21 +7287,36 @@ export default class AiLiveAssist {
|
|
|
6896
7287
|
await this.resume(recoveredRecord);
|
|
6897
7288
|
return;
|
|
6898
7289
|
}
|
|
6899
|
-
|
|
7290
|
+
const effectiveBootstrap = this.effectivePageAssistanceBootstrap(bootstrap);
|
|
6900
7291
|
const status = bootstrap.visitorEligibility?.status;
|
|
6901
7292
|
if (status === "eligible") {
|
|
7293
|
+
if (!this.pendingLaunchConsentProofMatches(launchConsentProof, effectiveBootstrap)) {
|
|
7294
|
+
if (recoveredOwnership && this.lock.ownsActivity()) {
|
|
7295
|
+
this.lock.release();
|
|
7296
|
+
}
|
|
7297
|
+
this.finishVisitorActiveConsentRefresh(pendingLaunch);
|
|
7298
|
+
return;
|
|
7299
|
+
}
|
|
7300
|
+
this.bootstrap = effectiveBootstrap;
|
|
6902
7301
|
this.visitorActiveTakeoverOnly = false;
|
|
6903
7302
|
this.lastLaunch = null;
|
|
6904
7303
|
this.view?.showActiveElsewhere(false);
|
|
6905
|
-
await this.launch(pendingLaunch.mode, pendingLaunch.scopes, pendingLaunch.idempotencyKey, {
|
|
7304
|
+
await this.launch(pendingLaunch.mode, pendingLaunch.scopes, pendingLaunch.idempotencyKey, {
|
|
7305
|
+
pendingLaunch,
|
|
7306
|
+
...(this.pendingQuestion
|
|
7307
|
+
? { admittedQuestion: this.pendingQuestion }
|
|
7308
|
+
: {}),
|
|
7309
|
+
});
|
|
6906
7310
|
return;
|
|
6907
7311
|
}
|
|
6908
7312
|
if (status === "visitor_limited") {
|
|
7313
|
+
this.bootstrap = effectiveBootstrap;
|
|
6909
7314
|
this.visitorActiveTakeoverOnly = false;
|
|
6910
7315
|
finish("visitorLimitReached");
|
|
6911
7316
|
return;
|
|
6912
7317
|
}
|
|
6913
7318
|
if (status === "cooldown_limited") {
|
|
7319
|
+
this.bootstrap = effectiveBootstrap;
|
|
6914
7320
|
this.visitorActiveTakeoverOnly = false;
|
|
6915
7321
|
finish("visitorCooldown");
|
|
6916
7322
|
return;
|
|
@@ -6938,9 +7344,18 @@ export default class AiLiveAssist {
|
|
|
6938
7344
|
!this.pendingLaunchMatches(this.lastLaunch, pendingLaunch)) {
|
|
6939
7345
|
return;
|
|
6940
7346
|
}
|
|
6941
|
-
this.lastLaunch = null;
|
|
6942
|
-
this.clearPendingIntent();
|
|
6943
7347
|
this.view?.showActiveElsewhere(false);
|
|
7348
|
+
if (messageKey === "visitorAlreadyActive") {
|
|
7349
|
+
// The explicit entry action has already staged the compact Voice/Text
|
|
7350
|
+
// surface. Keep that surface as a retryable, closable recovery card.
|
|
7351
|
+
// The generic unavailable presenter resets compact state while leaving
|
|
7352
|
+
// the open panel mounted, which produces an empty full-height shell.
|
|
7353
|
+
this.presentSessionError(this.view?.message(messageKey), true, false);
|
|
7354
|
+
this.state("error");
|
|
7355
|
+
return;
|
|
7356
|
+
}
|
|
7357
|
+
this.clearPendingIntent();
|
|
7358
|
+
this.lastLaunch = null;
|
|
6944
7359
|
this.view?.showLaunchUnavailable(this.view.message(messageKey));
|
|
6945
7360
|
this.state("ready");
|
|
6946
7361
|
}
|
|
@@ -7028,16 +7443,18 @@ export default class AiLiveAssist {
|
|
|
7028
7443
|
this.minimumPageAssistanceAuthorityEpoch = Math.max(this.minimumPageAssistanceAuthorityEpoch, this.activePageAssistanceAuthorityEpoch);
|
|
7029
7444
|
}
|
|
7030
7445
|
this.visualConsentGranted = record.visualConsentGranted;
|
|
7446
|
+
// A legacy override only keeps capture closed during recovery. It cannot
|
|
7447
|
+
// authorize manual controls; connectTransport restores the published mode.
|
|
7031
7448
|
this.manualTurn =
|
|
7032
7449
|
record.mode === "voice" &&
|
|
7033
7450
|
(record.manualTurn || this.bootstrap?.voice?.turnMode === "manual");
|
|
7034
7451
|
this.pushActive = false;
|
|
7035
7452
|
this.state("reconnecting");
|
|
7036
7453
|
try {
|
|
7037
|
-
const replay = await this.
|
|
7454
|
+
const replay = await this.sessionConnectionScope();
|
|
7038
7455
|
if (!resumeAttemptIsCurrent())
|
|
7039
7456
|
return;
|
|
7040
|
-
this.
|
|
7457
|
+
this.assertSessionConnectionScope(replay);
|
|
7041
7458
|
const controller = new AbortController();
|
|
7042
7459
|
const connectionGeneration = this.beginConnectionAttempt(controller);
|
|
7043
7460
|
if (modeUpgradeAttempt)
|
|
@@ -7148,6 +7565,9 @@ export default class AiLiveAssist {
|
|
|
7148
7565
|
else {
|
|
7149
7566
|
this.writeResume(...resumeArguments);
|
|
7150
7567
|
}
|
|
7568
|
+
if (!this.rebaseDeferredDocumentNavigationRecovery(requestedResumePath)) {
|
|
7569
|
+
throw new RuntimeClientError("RESUME_STORAGE_UNAVAILABLE", "The page-action recovery could not be stored safely.", true, null, 503);
|
|
7570
|
+
}
|
|
7151
7571
|
const media = preparedModeUpgradeMedia ??
|
|
7152
7572
|
this.createMedia(() => {
|
|
7153
7573
|
try {
|
|
@@ -7309,7 +7729,7 @@ export default class AiLiveAssist {
|
|
|
7309
7729
|
this.state("reconnecting");
|
|
7310
7730
|
}
|
|
7311
7731
|
else {
|
|
7312
|
-
this.
|
|
7732
|
+
this.presentSessionError(this.publicError(error), retryableFailure);
|
|
7313
7733
|
this.state("error");
|
|
7314
7734
|
}
|
|
7315
7735
|
}
|
|
@@ -7427,7 +7847,7 @@ export default class AiLiveAssist {
|
|
|
7427
7847
|
this.state("reconnecting");
|
|
7428
7848
|
}
|
|
7429
7849
|
else {
|
|
7430
|
-
this.
|
|
7850
|
+
this.presentSessionError(this.publicError(error), false);
|
|
7431
7851
|
this.state("error");
|
|
7432
7852
|
}
|
|
7433
7853
|
}
|
|
@@ -7557,6 +7977,7 @@ export default class AiLiveAssist {
|
|
|
7557
7977
|
const authorityOutcome = await channel.proveFencedAuthority();
|
|
7558
7978
|
this.requireControlReadiness(authorityOutcome, "The secure control authority could not be verified.");
|
|
7559
7979
|
assertCurrent();
|
|
7980
|
+
this.flushPlaybackState();
|
|
7560
7981
|
this.retryMessengerBindingTerminalAck();
|
|
7561
7982
|
this.retryMessengerTerminalAck();
|
|
7562
7983
|
this.preparePreFenceActionExecutionReadiness(channel, fencingToken, assertCurrent);
|
|
@@ -7586,19 +8007,24 @@ export default class AiLiveAssist {
|
|
|
7586
8007
|
}
|
|
7587
8008
|
assertCurrent();
|
|
7588
8009
|
channel.startHeartbeat(this.heartbeatSeconds);
|
|
8010
|
+
if (this.guideAdmission && !this.guideAdmission.recordingAllowed) {
|
|
8011
|
+
activeScopes = activeScopes.filter(scope => scope !== "session_recording");
|
|
8012
|
+
this.scopes = [...activeScopes];
|
|
8013
|
+
}
|
|
7589
8014
|
channel.send("consent.update", {
|
|
7590
8015
|
scopes: activeScopes,
|
|
7591
8016
|
locale: this.locale,
|
|
7592
8017
|
});
|
|
7593
8018
|
channel.send("media.state", {
|
|
7594
8019
|
microphone: mode === "voice" ? "active" : "unavailable",
|
|
7595
|
-
playback: mode
|
|
8020
|
+
playback: this.advertisedMediaPlaybackState(mode),
|
|
7596
8021
|
captions: true,
|
|
7597
8022
|
});
|
|
7598
8023
|
if (mode === "voice" &&
|
|
7599
8024
|
this.manualTurn &&
|
|
7600
8025
|
this.bootstrap?.voice?.turnMode !== "manual") {
|
|
7601
|
-
|
|
8026
|
+
await this.restoreConfiguredVoiceTurns(channel, controller.signal, assertCurrent);
|
|
8027
|
+
assertCurrent();
|
|
7602
8028
|
}
|
|
7603
8029
|
if (this.pendingNavigationActionResult) {
|
|
7604
8030
|
const terminalDeliveryConfirmed = await this.flushPendingNavigationActionResult();
|
|
@@ -7640,20 +8066,21 @@ export default class AiLiveAssist {
|
|
|
7640
8066
|
? null
|
|
7641
8067
|
: (result.assistant?.welcomeMessage ??
|
|
7642
8068
|
this.bootstrap?.appearance?.welcomeMessage);
|
|
7643
|
-
|
|
7644
|
-
if (
|
|
8069
|
+
const hasPendingTextQuestion = mode === "text" && this.pendingQuestion !== null;
|
|
8070
|
+
if (hasPendingTextQuestion &&
|
|
7645
8071
|
this.pendingQuestion &&
|
|
7646
8072
|
!this.pendingQuestion.shown) {
|
|
7647
8073
|
this.view?.addCaption("user", this.pendingQuestion.text, true);
|
|
7648
8074
|
this.pendingQuestion.shown = true;
|
|
8075
|
+
}
|
|
8076
|
+
if (hasPendingTextQuestion && this.pendingQuestion) {
|
|
7649
8077
|
this.rememberTranscript(this.pendingQuestion.submissionId, "user", this.pendingQuestion.text);
|
|
7650
8078
|
(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).add(this.pendingQuestion.submissionId);
|
|
7651
|
-
renderedPendingTextQuestion = true;
|
|
7652
8079
|
}
|
|
7653
8080
|
const visibleWelcome = resume ||
|
|
7654
|
-
|
|
8081
|
+
hasPendingTextQuestion ||
|
|
7655
8082
|
this.transcriptRestoredFromCache ||
|
|
7656
|
-
|
|
8083
|
+
mode === "voice"
|
|
7657
8084
|
? null
|
|
7658
8085
|
: welcomeMessage;
|
|
7659
8086
|
this.view?.showActive(visibleWelcome);
|
|
@@ -7680,8 +8107,60 @@ export default class AiLiveAssist {
|
|
|
7680
8107
|
void this.requestHumanHandoff("The visitor chose human support because voice assistance was unavailable.", undefined, undefined, isCurrent);
|
|
7681
8108
|
}
|
|
7682
8109
|
else {
|
|
7683
|
-
this.
|
|
8110
|
+
this.presentSessionError(this.view?.message("humanUnavailable"), false);
|
|
8111
|
+
}
|
|
8112
|
+
}
|
|
8113
|
+
}
|
|
8114
|
+
async restoreConfiguredVoiceTurns(channel, signal, assertCurrent) {
|
|
8115
|
+
assertCurrent();
|
|
8116
|
+
if (signal.aborted)
|
|
8117
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
8118
|
+
let unsubscribe = () => { };
|
|
8119
|
+
let timeout;
|
|
8120
|
+
let abort = () => { };
|
|
8121
|
+
let confirmApplied = () => { };
|
|
8122
|
+
const applied = new Promise(resolve => { confirmApplied = resolve; });
|
|
8123
|
+
const interrupted = new Promise((_, reject) => {
|
|
8124
|
+
abort = () => reject(new DOMException("The operation was aborted.", "AbortError"));
|
|
8125
|
+
signal.addEventListener("abort", abort, { once: true });
|
|
8126
|
+
timeout = setTimeout(() => reject(new Error("Automatic voice mode was not confirmed.")), 5000);
|
|
8127
|
+
unsubscribe = channel.subscribe((message, isCurrent) => {
|
|
8128
|
+
if (message.type !== "voice.turn_mode" || message.payload.mode !== "configured" || !isCurrent())
|
|
8129
|
+
return;
|
|
8130
|
+
try {
|
|
8131
|
+
assertCurrent();
|
|
8132
|
+
confirmApplied();
|
|
8133
|
+
}
|
|
8134
|
+
catch (error) {
|
|
8135
|
+
reject(error);
|
|
8136
|
+
}
|
|
8137
|
+
});
|
|
8138
|
+
});
|
|
8139
|
+
try {
|
|
8140
|
+
const id = channel.send("voice.turn_mode", { mode: "configured" });
|
|
8141
|
+
await Promise.race([
|
|
8142
|
+
interrupted,
|
|
8143
|
+
Promise.all([
|
|
8144
|
+
applied,
|
|
8145
|
+
channel.waitForOutcome(id).then(outcome => this.requireControlReadiness(outcome, "Automatic voice mode could not be restored.")),
|
|
8146
|
+
]),
|
|
8147
|
+
]);
|
|
8148
|
+
assertCurrent();
|
|
8149
|
+
if (signal.aborted || this.channel !== channel) {
|
|
8150
|
+
throw new DOMException("The operation was aborted.", "AbortError");
|
|
7684
8151
|
}
|
|
8152
|
+
// Apply only after both confirmations. An early or replayed server event
|
|
8153
|
+
// must not open capture while the legacy manual session is quarantined.
|
|
8154
|
+
this.manualTurn = false;
|
|
8155
|
+
this.pushActive = false;
|
|
8156
|
+
this.media?.setManualTurn(false);
|
|
8157
|
+
this.view?.setManualTurn(false);
|
|
8158
|
+
this.updateResumeManualTurn();
|
|
8159
|
+
}
|
|
8160
|
+
finally {
|
|
8161
|
+
unsubscribe();
|
|
8162
|
+
clearTimeout(timeout);
|
|
8163
|
+
signal.removeEventListener("abort", abort);
|
|
7685
8164
|
}
|
|
7686
8165
|
}
|
|
7687
8166
|
requireControlReadiness(outcome, unavailableMessage) {
|
|
@@ -7718,7 +8197,27 @@ export default class AiLiveAssist {
|
|
|
7718
8197
|
const pathname = this.contextNavigationPath(payload);
|
|
7719
8198
|
const sessionId = this.result?.sessionId ?? null;
|
|
7720
8199
|
const effectGeneration = this.sessionEffectGeneration;
|
|
7721
|
-
const rawOutcome =
|
|
8200
|
+
const rawOutcome = (async () => {
|
|
8201
|
+
const initial = await channel.waitForOutcome(messageId, CONTEXT_NAVIGATION_ACK_TIMEOUT_MS, clientSequence);
|
|
8202
|
+
if (initial.status !== "timeout" ||
|
|
8203
|
+
!pathname ||
|
|
8204
|
+
!sessionId ||
|
|
8205
|
+
effectGeneration !== this.sessionEffectGeneration ||
|
|
8206
|
+
this.channel !== channel ||
|
|
8207
|
+
this.result?.sessionId !== sessionId ||
|
|
8208
|
+
!channel.isOpen ||
|
|
8209
|
+
this.terminalRequestPending ||
|
|
8210
|
+
this.ended ||
|
|
8211
|
+
this.destroyed) {
|
|
8212
|
+
return initial;
|
|
8213
|
+
}
|
|
8214
|
+
// A same-document router can settle before the durable navigation frame
|
|
8215
|
+
// is acknowledged. Replay the exact outstanding frame (including its
|
|
8216
|
+
// sequence and timestamp) once, then observe that original identity for
|
|
8217
|
+
// one bounded grace period without disrupting healthy voice media.
|
|
8218
|
+
channel.retransmitOutstanding(messageId, clientSequence);
|
|
8219
|
+
return channel.waitForOutcome(messageId, CONTEXT_NAVIGATION_LATE_ACK_TIMEOUT_MS, clientSequence);
|
|
8220
|
+
})();
|
|
7722
8221
|
if (!pathname || !sessionId)
|
|
7723
8222
|
return rawOutcome;
|
|
7724
8223
|
const pending = {};
|
|
@@ -7779,18 +8278,17 @@ export default class AiLiveAssist {
|
|
|
7779
8278
|
return true;
|
|
7780
8279
|
}
|
|
7781
8280
|
async waitForPendingContextNavigationAcknowledgements() {
|
|
7782
|
-
|
|
7783
|
-
|
|
7784
|
-
|
|
7785
|
-
|
|
7786
|
-
|
|
7787
|
-
|
|
7788
|
-
|
|
7789
|
-
|
|
7790
|
-
|
|
7791
|
-
|
|
7792
|
-
|
|
7793
|
-
return false;
|
|
8281
|
+
// Each tracked outcome already has its own bounded 5s + 10s delivery
|
|
8282
|
+
// window. Snapshot this cohort so a navigation that starts later receives
|
|
8283
|
+
// its own complete window instead of inheriting an almost-expired outer
|
|
8284
|
+
// timer. Callers recheck the live set before activating voice.
|
|
8285
|
+
const pending = [
|
|
8286
|
+
...(this.pendingContextNavigationAcknowledgements ?? new Set()),
|
|
8287
|
+
];
|
|
8288
|
+
if (pending.length === 0)
|
|
8289
|
+
return true;
|
|
8290
|
+
const outcomes = await Promise.all(pending.map((entry) => entry.outcome));
|
|
8291
|
+
return outcomes.every((outcome) => outcome.status === "ack");
|
|
7794
8292
|
}
|
|
7795
8293
|
startContext(scopes) {
|
|
7796
8294
|
this.context?.stop();
|
|
@@ -7841,10 +8339,16 @@ export default class AiLiveAssist {
|
|
|
7841
8339
|
}
|
|
7842
8340
|
if (destination.origin !== window.location.origin ||
|
|
7843
8341
|
destination.search !== "" ||
|
|
7844
|
-
destination.hash !== ""
|
|
8342
|
+
destination.hash !== "" ||
|
|
8343
|
+
typeof pending.grant?.destinationPath !== "string" ||
|
|
8344
|
+
destination.pathname !== pending.grant.destinationPath) {
|
|
7845
8345
|
pending.causalNavigationObserved = false;
|
|
7846
8346
|
return;
|
|
7847
8347
|
}
|
|
8348
|
+
// The exact SPA destination is now observed, so the persisted state
|
|
8349
|
+
// becomes the causal navigation/result outbox rather than a
|
|
8350
|
+
// cross-document recovery marker.
|
|
8351
|
+
pending.deferredNavigationPath = null;
|
|
7848
8352
|
pending.navigationPayload = {
|
|
7849
8353
|
pageId,
|
|
7850
8354
|
revision,
|
|
@@ -7875,10 +8379,61 @@ export default class AiLiveAssist {
|
|
|
7875
8379
|
navigationType: "spa",
|
|
7876
8380
|
};
|
|
7877
8381
|
if (causalLegacy && legacy && cause) {
|
|
8382
|
+
if (legacy.result && !legacy.resultAcknowledged) {
|
|
8383
|
+
legacy.result = {
|
|
8384
|
+
...legacy.result,
|
|
8385
|
+
observed: {
|
|
8386
|
+
...legacy.result.observed,
|
|
8387
|
+
url,
|
|
8388
|
+
revision,
|
|
8389
|
+
},
|
|
8390
|
+
};
|
|
8391
|
+
}
|
|
7878
8392
|
return this.deliverLegacyCausalNavigation(legacy, payload, cause);
|
|
7879
8393
|
}
|
|
8394
|
+
if (causalPending && pending && !cause) {
|
|
8395
|
+
const retainedExactNavigation = pending.grant === null &&
|
|
8396
|
+
pending.causalNavigationObserved &&
|
|
8397
|
+
pending.navigationPayload?.url === url &&
|
|
8398
|
+
this.pendingNavigationPayloadMatchesGrant(pending);
|
|
8399
|
+
pending.result = this.unconfirmedActionExecutionResult(pending, revision, url);
|
|
8400
|
+
pending.deferredNavigationPath = null;
|
|
8401
|
+
if (!retainedExactNavigation) {
|
|
8402
|
+
pending.navigationPayload = null;
|
|
8403
|
+
pending.navigationAcknowledged = true;
|
|
8404
|
+
}
|
|
8405
|
+
pending.causalNavigationDeliveryAttempted = true;
|
|
8406
|
+
this.persistPendingActionExecution(pending);
|
|
8407
|
+
this.pendingAction = false;
|
|
8408
|
+
this.view?.showActionState("unconfirmed");
|
|
8409
|
+
this.resetActionGrantAuthority(true);
|
|
8410
|
+
const navigationAcknowledged = retainedExactNavigation
|
|
8411
|
+
? false
|
|
8412
|
+
: await this.deliverContextNavigation(payload);
|
|
8413
|
+
pending.causalNavigationDeliveryConfirmed =
|
|
8414
|
+
await this.flushPendingNavigationActionResult();
|
|
8415
|
+
if ((!navigationAcknowledged ||
|
|
8416
|
+
!pending.causalNavigationDeliveryConfirmed) &&
|
|
8417
|
+
!this.terminalRequestPending &&
|
|
8418
|
+
!this.ended &&
|
|
8419
|
+
!this.destroyed) {
|
|
8420
|
+
this.scheduleReconnect(true);
|
|
8421
|
+
}
|
|
8422
|
+
return false;
|
|
8423
|
+
}
|
|
7880
8424
|
this.resetActionGrantAuthority(causalPending);
|
|
7881
8425
|
if (causalPending && pending) {
|
|
8426
|
+
if (pending.result &&
|
|
8427
|
+
pending.resultDeliveryAttempted === false &&
|
|
8428
|
+
!pending.resultAcknowledged) {
|
|
8429
|
+
// A released link records its result before the router runs.
|
|
8430
|
+
// Bind that first delivery to the exact causal destination now
|
|
8431
|
+
// observed, then retain identical result bytes for every retry.
|
|
8432
|
+
pending.result = {
|
|
8433
|
+
...pending.result,
|
|
8434
|
+
observed: { ...pending.result.observed, url, revision },
|
|
8435
|
+
};
|
|
8436
|
+
}
|
|
7882
8437
|
this.sendPendingNavigationMessage(payload);
|
|
7883
8438
|
pending.causalNavigationDeliveryAttempted = true;
|
|
7884
8439
|
pending.causalNavigationDeliveryConfirmed =
|
|
@@ -7999,7 +8554,7 @@ export default class AiLiveAssist {
|
|
|
7999
8554
|
if (this.resolvePendingConfirmationReply(text))
|
|
8000
8555
|
return true;
|
|
8001
8556
|
if (this.destroyed || this.terminalRequestPending || this.ended) {
|
|
8002
|
-
this.
|
|
8557
|
+
this.presentSessionError(this.view?.message("ended"), false, false);
|
|
8003
8558
|
return false;
|
|
8004
8559
|
}
|
|
8005
8560
|
if (this.pendingQuestionCount() >= PUBLIC_QUESTION_QUEUE_CAPACITY) {
|
|
@@ -8127,15 +8682,19 @@ export default class AiLiveAssist {
|
|
|
8127
8682
|
}
|
|
8128
8683
|
}
|
|
8129
8684
|
}
|
|
8130
|
-
resolvePendingConfirmationReply(text) {
|
|
8685
|
+
resolvePendingConfirmationReply(text, nativeVoiceTurn) {
|
|
8131
8686
|
const pending = this.pendingConfirmation;
|
|
8132
8687
|
if (!pending)
|
|
8133
8688
|
return false;
|
|
8134
8689
|
const intent = confirmationReplyIntent(text);
|
|
8135
8690
|
if (!intent)
|
|
8136
8691
|
return false;
|
|
8137
|
-
|
|
8692
|
+
// Durable native voice turns already interrupt prior provider output. A
|
|
8693
|
+
// second session.interrupt here would discard the newly accepted input.
|
|
8694
|
+
if (this.mode === "voice" &&
|
|
8695
|
+
!this.hasAdmittedVoicePlaybackTurn(nativeVoiceTurn)) {
|
|
8138
8696
|
this.interrupt();
|
|
8697
|
+
}
|
|
8139
8698
|
const approved = intent === "approve";
|
|
8140
8699
|
if (this.view?.resolvePendingConfirmation(approved, pending)) {
|
|
8141
8700
|
// A visible prompt always invokes the identity-bound callback. If a
|
|
@@ -8147,15 +8706,17 @@ export default class AiLiveAssist {
|
|
|
8147
8706
|
}
|
|
8148
8707
|
return this.submitConfirmationDecision(pending, approved);
|
|
8149
8708
|
}
|
|
8150
|
-
cancelConfirmationForNewRequest(expected) {
|
|
8709
|
+
cancelConfirmationForNewRequest(expected, nativeVoiceTurn) {
|
|
8151
8710
|
const pending = this.pendingConfirmation;
|
|
8152
8711
|
if (!pending ||
|
|
8153
8712
|
pending.actionId !== expected.actionId ||
|
|
8154
8713
|
pending.proposalChecksum !== expected.proposalChecksum) {
|
|
8155
8714
|
return null;
|
|
8156
8715
|
}
|
|
8157
|
-
if (this.mode === "voice"
|
|
8716
|
+
if (this.mode === "voice" &&
|
|
8717
|
+
!this.hasAdmittedVoicePlaybackTurn(nativeVoiceTurn)) {
|
|
8158
8718
|
this.interrupt();
|
|
8719
|
+
}
|
|
8159
8720
|
if (this.view?.resolvePendingConfirmation(false, expected)) {
|
|
8160
8721
|
if (this.pendingConfirmation === pending) {
|
|
8161
8722
|
this.submitConfirmationDecision(pending, false);
|
|
@@ -8190,7 +8751,7 @@ export default class AiLiveAssist {
|
|
|
8190
8751
|
if (this.pendingConfirmationDecisions.length >=
|
|
8191
8752
|
CONFIRMATION_DECISION_QUEUE_CAPACITY) {
|
|
8192
8753
|
this.revokeActiveAction();
|
|
8193
|
-
this.
|
|
8754
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), true, true);
|
|
8194
8755
|
this.scheduleReconnect(true);
|
|
8195
8756
|
return false;
|
|
8196
8757
|
}
|
|
@@ -8293,7 +8854,7 @@ export default class AiLiveAssist {
|
|
|
8293
8854
|
return false;
|
|
8294
8855
|
const decision = this.pendingConfirmationDecisions[index];
|
|
8295
8856
|
if (payload.retryable === true) {
|
|
8296
|
-
this.
|
|
8857
|
+
this.presentSessionError(this.string(payload.message), true);
|
|
8297
8858
|
return true;
|
|
8298
8859
|
}
|
|
8299
8860
|
this.pendingConfirmationDecisions.splice(index, 1);
|
|
@@ -8331,7 +8892,7 @@ export default class AiLiveAssist {
|
|
|
8331
8892
|
if (!question)
|
|
8332
8893
|
return false;
|
|
8333
8894
|
if (payload.retryable === true) {
|
|
8334
|
-
this.
|
|
8895
|
+
this.presentSessionError(this.string(payload.message), true);
|
|
8335
8896
|
return true;
|
|
8336
8897
|
}
|
|
8337
8898
|
this.removePendingQuestion(question);
|
|
@@ -8635,14 +9196,14 @@ export default class AiLiveAssist {
|
|
|
8635
9196
|
: null;
|
|
8636
9197
|
if (identity && this.samePageAssistanceIdentity(identity, request)) {
|
|
8637
9198
|
this.invalidatePageAssistanceAuthority(false);
|
|
8638
|
-
this.
|
|
9199
|
+
this.presentSessionError(outcome.message, false);
|
|
8639
9200
|
}
|
|
8640
9201
|
}
|
|
8641
9202
|
});
|
|
8642
9203
|
}
|
|
8643
9204
|
pageAssistanceRecoveries() {
|
|
8644
9205
|
if (!this.pageAssistanceRecoveryStore) {
|
|
8645
|
-
this.pageAssistanceRecoveryStore = new PageAssistanceRecoveryStore(this.siteKey);
|
|
9206
|
+
this.pageAssistanceRecoveryStore = new PageAssistanceRecoveryStore(this.guideAdmission ? this.guideAdmission.identity : this.siteKey, { storageNamespace: this.storageNamespace });
|
|
8646
9207
|
}
|
|
8647
9208
|
return this.pageAssistanceRecoveryStore;
|
|
8648
9209
|
}
|
|
@@ -9343,7 +9904,15 @@ export default class AiLiveAssist {
|
|
|
9343
9904
|
this.commitAuthoritativeConsent(scopes);
|
|
9344
9905
|
}
|
|
9345
9906
|
commitAuthoritativeConsent(scopes) {
|
|
9907
|
+
// A delayed receipt cannot restore recording after the visitor opted out.
|
|
9908
|
+
if (this.guideAdmission && !this.guideAdmission.recordingAllowed)
|
|
9909
|
+
scopes = scopes.filter(scope => scope !== "session_recording");
|
|
9346
9910
|
this.scopes = [...scopes];
|
|
9911
|
+
if (this.guideAdmission && this.result) {
|
|
9912
|
+
this.guideAdmission.syncRecording(this.result, scopes, this.tabId);
|
|
9913
|
+
if (this.view instanceof WidgetView)
|
|
9914
|
+
this.view.setRecordingConsent(scopes.includes("session_recording"));
|
|
9915
|
+
}
|
|
9347
9916
|
this.visualConsentGranted = scopes.includes("visual_context");
|
|
9348
9917
|
const record = this.readResume();
|
|
9349
9918
|
if (record) {
|
|
@@ -9654,6 +10223,36 @@ export default class AiLiveAssist {
|
|
|
9654
10223
|
handleControlIngress(message, isCurrent = () => true) {
|
|
9655
10224
|
if (!isCurrent())
|
|
9656
10225
|
return;
|
|
10226
|
+
this.observeVoicePlaybackInterrupt(message);
|
|
10227
|
+
if (message.type === "assistant.interrupted" ||
|
|
10228
|
+
message.type === "provider.reconnecting" ||
|
|
10229
|
+
(message.type === "presence.state" &&
|
|
10230
|
+
message.payload.state === "reconnecting"))
|
|
10231
|
+
this.invalidateVoicePlaybackRearm();
|
|
10232
|
+
(this.voicePlaybackIngress ?? (this.voicePlaybackIngress = new WeakMap())).set(message, {
|
|
10233
|
+
generation: this.voicePlaybackInterruptionGeneration ?? 0,
|
|
10234
|
+
channel: this.channel,
|
|
10235
|
+
fencingToken: this.channel?.leaseToken ?? 0,
|
|
10236
|
+
});
|
|
10237
|
+
(this.ctaAuthorityGenerationAtIngress ?? (this.ctaAuthorityGenerationAtIngress = new WeakMap())).set(message, this.currentCtaAuthorityGeneration());
|
|
10238
|
+
if (message.type === "caption.segment" ||
|
|
10239
|
+
message.type === "assistant.caption") {
|
|
10240
|
+
(this.ctaContentAtIngress ?? (this.ctaContentAtIngress = new WeakMap())).set(message, {
|
|
10241
|
+
generation: this.ctaContentGeneration ?? 0,
|
|
10242
|
+
channel: this.channel,
|
|
10243
|
+
});
|
|
10244
|
+
}
|
|
10245
|
+
if (message.type === "provider.reconnecting")
|
|
10246
|
+
this.invalidateCtaAuthority();
|
|
10247
|
+
if (message.type === "session.state" &&
|
|
10248
|
+
["ending", "ended", "failed", "revoked"].includes(String(message.payload.state))) {
|
|
10249
|
+
this.ctaStoppedSessionId = message.sessionId;
|
|
10250
|
+
this.invalidateCtaAuthority();
|
|
10251
|
+
}
|
|
10252
|
+
if (message.type === "handoff.state" &&
|
|
10253
|
+
["prepared", "handoff_pending", "human_controlled"].includes(String(message.payload.state))) {
|
|
10254
|
+
this.invalidateCtaAuthority();
|
|
10255
|
+
}
|
|
9657
10256
|
const fencedAuthorityAtIngress = this.channel?.hasFencedAuthority === true;
|
|
9658
10257
|
(this.fencedAuthorityAtIngressByEnvelope ?? (this.fencedAuthorityAtIngressByEnvelope = new WeakMap())).set(message, fencedAuthorityAtIngress);
|
|
9659
10258
|
if (message.type === "handoff.state" &&
|
|
@@ -9729,8 +10328,16 @@ export default class AiLiveAssist {
|
|
|
9729
10328
|
!message.payload.scopes.includes("browser_control")) {
|
|
9730
10329
|
// Authority loss must preempt any older handler that is still awaiting
|
|
9731
10330
|
// context capture, fingerprinting, or visitor confirmation.
|
|
10331
|
+
// A routine unchanged text/voice consent refresh does not revoke a CTA:
|
|
10332
|
+
// its native visitor link does not require browser-control permission.
|
|
10333
|
+
const scopes = this.authoritativeConsentScopes(message.payload);
|
|
10334
|
+
const unchangedConsent = message.payload.source === "consent_update" &&
|
|
10335
|
+
scopes !== null &&
|
|
10336
|
+
!this.scopes.includes("browser_control") &&
|
|
10337
|
+
scopes.length === this.scopes.length &&
|
|
10338
|
+
scopes.every((scope) => this.scopes.includes(scope));
|
|
9732
10339
|
this.discardPendingConfirmationDecisions();
|
|
9733
|
-
this.revokeActiveActionAtIngress();
|
|
10340
|
+
this.revokeActiveActionAtIngress(unchangedConsent);
|
|
9734
10341
|
return;
|
|
9735
10342
|
}
|
|
9736
10343
|
if (message.type === "error") {
|
|
@@ -9802,7 +10409,9 @@ export default class AiLiveAssist {
|
|
|
9802
10409
|
this.finishFromServer(this.string(message.payload.reasonCode), message.sessionId);
|
|
9803
10410
|
}
|
|
9804
10411
|
}
|
|
9805
|
-
revokeActiveActionAtIngress() {
|
|
10412
|
+
revokeActiveActionAtIngress(preserveCta = false) {
|
|
10413
|
+
if (!preserveCta)
|
|
10414
|
+
this.invalidateCtaAuthority();
|
|
9806
10415
|
this.actionIngressRevocationGeneration =
|
|
9807
10416
|
(Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
9808
10417
|
? this.actionIngressRevocationGeneration
|
|
@@ -9895,6 +10504,7 @@ export default class AiLiveAssist {
|
|
|
9895
10504
|
return authorityEpoch;
|
|
9896
10505
|
}
|
|
9897
10506
|
revokeContextResyncActionAuthority(atIngress) {
|
|
10507
|
+
this.invalidateCtaAuthority();
|
|
9898
10508
|
if (atIngress) {
|
|
9899
10509
|
this.actionIngressRevocationGeneration =
|
|
9900
10510
|
(Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
@@ -9957,6 +10567,9 @@ export default class AiLiveAssist {
|
|
|
9957
10567
|
this.view.applyPresenceState(state, message.sequence, message.sessionId, this.context?.currentPageId ?? null, this.channel?.leaseToken ?? 0);
|
|
9958
10568
|
}
|
|
9959
10569
|
else if (this.view instanceof WidgetView && this.result) {
|
|
10570
|
+
if (state === "thinking") {
|
|
10571
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10572
|
+
}
|
|
9960
10573
|
if (state === "reconnecting") {
|
|
9961
10574
|
this.view.showConnecting(true, this.currentDisplayMode());
|
|
9962
10575
|
}
|
|
@@ -10012,7 +10625,10 @@ export default class AiLiveAssist {
|
|
|
10012
10625
|
const currentIngressGeneration = Number.isSafeInteger(this.actionIngressRevocationGeneration)
|
|
10013
10626
|
? this.actionIngressRevocationGeneration
|
|
10014
10627
|
: 0;
|
|
10015
|
-
|
|
10628
|
+
// A CTA is fenced by its own authority generation in the handler;
|
|
10629
|
+
// unchanged consent still advances the independent browser-action fence.
|
|
10630
|
+
if (message.type !== "cta.offer" &&
|
|
10631
|
+
ingressGeneration !== currentIngressGeneration)
|
|
10016
10632
|
continue;
|
|
10017
10633
|
await this.handleServerMessage(message, isCurrent, true);
|
|
10018
10634
|
}
|
|
@@ -10067,8 +10683,50 @@ export default class AiLiveAssist {
|
|
|
10067
10683
|
return;
|
|
10068
10684
|
const payload = message.payload;
|
|
10069
10685
|
switch (message.type) {
|
|
10070
|
-
case "
|
|
10071
|
-
|
|
10686
|
+
case "cta.offer": {
|
|
10687
|
+
// CTA has its own ingress fence. Browser-action generations also move
|
|
10688
|
+
// on unchanged consent, which must not discard a queued native link.
|
|
10689
|
+
const offer = parseCtaOffer(payload);
|
|
10690
|
+
if (message.sessionId !== this.result?.sessionId)
|
|
10691
|
+
return;
|
|
10692
|
+
if (this.ctaSessionId !== message.sessionId) {
|
|
10693
|
+
this.ctaSessionId = message.sessionId;
|
|
10694
|
+
this.ctaTerminalOffers = new Set();
|
|
10695
|
+
this.ctaAnnouncedOffers = new Set();
|
|
10696
|
+
this.ctaClicked = false;
|
|
10697
|
+
}
|
|
10698
|
+
if (!offer ||
|
|
10699
|
+
message.v !== 2 ||
|
|
10700
|
+
!this.ctaEnvelopeIsCurrent(message) ||
|
|
10701
|
+
this.ctaStoppedSessionId === message.sessionId ||
|
|
10702
|
+
(!replayingPreFenceAuthority &&
|
|
10703
|
+
!this.hadFencedAuthorityAtIngress(message)) ||
|
|
10704
|
+
!this.channel?.hasFencedAuthority ||
|
|
10705
|
+
this.bootstrap?.capabilities?.ctaOffer !== true ||
|
|
10706
|
+
offer.configRevision !== this.bootstrap.configRevision ||
|
|
10707
|
+
this.messengerTransferred ||
|
|
10708
|
+
this.messengerTransferPending ||
|
|
10709
|
+
this.ctaClicked ||
|
|
10710
|
+
this.ctaTerminalOffers.has(offer.offerId) ||
|
|
10711
|
+
this.ctaTerminalOffers.size >= 16 ||
|
|
10712
|
+
(this.ctaSeenOffers ?? (this.ctaSeenOffers = new Set())).has(offer.offerId) ||
|
|
10713
|
+
this.ctaSeenOffers.size >= 16)
|
|
10714
|
+
return;
|
|
10715
|
+
this.clearCurrentCtaOffer();
|
|
10716
|
+
this.ctaSeenOffers.add(offer.offerId);
|
|
10717
|
+
this.ctaOffer = offer;
|
|
10718
|
+
const generation = this.sessionEffectGeneration;
|
|
10719
|
+
this.ctaExpiryTimer = setTimeout(() => {
|
|
10720
|
+
if (this.ctaOffer === offer &&
|
|
10721
|
+
this.sessionEffectGeneration === generation) {
|
|
10722
|
+
this.clearCurrentCtaOffer();
|
|
10723
|
+
}
|
|
10724
|
+
}, Date.parse(offer.expiresAt) - Date.now());
|
|
10725
|
+
this.renderCurrentCtaOffer();
|
|
10726
|
+
return;
|
|
10727
|
+
}
|
|
10728
|
+
case "control.ready":
|
|
10729
|
+
this.handoffContextPromptReceiptChannel =
|
|
10072
10730
|
payload.handoffContextPromptReceipt === true &&
|
|
10073
10731
|
typeof payload.helloMessageId === "string" &&
|
|
10074
10732
|
payload.helloMessageId ===
|
|
@@ -10098,23 +10756,39 @@ export default class AiLiveAssist {
|
|
|
10098
10756
|
if (text) {
|
|
10099
10757
|
const final = payload.final === true;
|
|
10100
10758
|
if (this.isLocallyRenderedQuestionEcho(payload, speaker, final)) {
|
|
10759
|
+
if (speaker === "user" &&
|
|
10760
|
+
final &&
|
|
10761
|
+
!(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10762
|
+
this.renderedTranscriptIds.add(message.id);
|
|
10763
|
+
this.admitVoicePlaybackTurn(message);
|
|
10764
|
+
}
|
|
10101
10765
|
return;
|
|
10102
10766
|
}
|
|
10103
10767
|
if (final) {
|
|
10104
10768
|
if ((this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10769
|
+
if (speaker === "assistant" && this.ctaContentIsCurrent(message))
|
|
10770
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10105
10771
|
return;
|
|
10106
10772
|
}
|
|
10107
10773
|
this.rememberTranscript(message.id, speaker, text);
|
|
10108
10774
|
this.renderedTranscriptIds.add(message.id);
|
|
10775
|
+
if (speaker === "user")
|
|
10776
|
+
this.admitVoicePlaybackTurn(message);
|
|
10109
10777
|
}
|
|
10110
|
-
this.view?.addCaption(speaker, text, final
|
|
10778
|
+
this.view?.addCaption(speaker, text, final, {
|
|
10779
|
+
sourceTurnId: message.id,
|
|
10780
|
+
});
|
|
10781
|
+
if (speaker === "assistant" &&
|
|
10782
|
+
final &&
|
|
10783
|
+
this.ctaContentIsCurrent(message))
|
|
10784
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10111
10785
|
if (speaker === "user" && final) {
|
|
10112
10786
|
const pending = this.pendingConfirmation
|
|
10113
10787
|
? { ...this.pendingConfirmation }
|
|
10114
10788
|
: null;
|
|
10115
|
-
if (!this.resolvePendingConfirmationReply(text)) {
|
|
10789
|
+
if (!this.resolvePendingConfirmationReply(text, message)) {
|
|
10116
10790
|
if (pending)
|
|
10117
|
-
this.cancelConfirmationForNewRequest(pending);
|
|
10791
|
+
this.cancelConfirmationForNewRequest(pending, message);
|
|
10118
10792
|
}
|
|
10119
10793
|
}
|
|
10120
10794
|
}
|
|
@@ -10153,6 +10827,8 @@ export default class AiLiveAssist {
|
|
|
10153
10827
|
state === "ready") {
|
|
10154
10828
|
if (!this.hadFencedAuthorityAtIngress(message))
|
|
10155
10829
|
return;
|
|
10830
|
+
if (state === "thinking")
|
|
10831
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10156
10832
|
this.view?.setAssistantState(state);
|
|
10157
10833
|
}
|
|
10158
10834
|
return;
|
|
@@ -10166,38 +10842,67 @@ export default class AiLiveAssist {
|
|
|
10166
10842
|
? "assistant"
|
|
10167
10843
|
: "user";
|
|
10168
10844
|
const final = payload.final === true;
|
|
10169
|
-
if (this.isLocallyRenderedQuestionEcho(payload, role, final))
|
|
10845
|
+
if (this.isLocallyRenderedQuestionEcho(payload, role, final)) {
|
|
10846
|
+
if (role === "user" &&
|
|
10847
|
+
final &&
|
|
10848
|
+
!(this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10849
|
+
this.renderedTranscriptIds.add(message.id);
|
|
10850
|
+
this.admitVoicePlaybackTurn(message);
|
|
10851
|
+
}
|
|
10170
10852
|
return;
|
|
10853
|
+
}
|
|
10171
10854
|
if (final) {
|
|
10172
10855
|
if ((this.renderedTranscriptIds ?? (this.renderedTranscriptIds = new Set())).has(message.id)) {
|
|
10856
|
+
if (role === "assistant" && this.ctaContentIsCurrent(message))
|
|
10857
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10173
10858
|
return;
|
|
10174
10859
|
}
|
|
10175
10860
|
this.rememberTranscript(message.id, role, text);
|
|
10176
10861
|
this.renderedTranscriptIds.add(message.id);
|
|
10862
|
+
if (role === "user")
|
|
10863
|
+
this.admitVoicePlaybackTurn(message);
|
|
10177
10864
|
}
|
|
10178
|
-
this.view?.addCaption(role, text, final);
|
|
10865
|
+
this.view?.addCaption(role, text, final, { sourceTurnId: message.id });
|
|
10866
|
+
if (role === "assistant" && final && this.ctaContentIsCurrent(message))
|
|
10867
|
+
this.observeCtaAssistantTurn(message.id);
|
|
10179
10868
|
if (role === "user" && final) {
|
|
10180
10869
|
const pending = this.pendingConfirmation
|
|
10181
10870
|
? { ...this.pendingConfirmation }
|
|
10182
10871
|
: null;
|
|
10183
|
-
if (!this.resolvePendingConfirmationReply(text)) {
|
|
10872
|
+
if (!this.resolvePendingConfirmationReply(text, message)) {
|
|
10184
10873
|
if (pending)
|
|
10185
|
-
this.cancelConfirmationForNewRequest(pending);
|
|
10874
|
+
this.cancelConfirmationForNewRequest(pending, message);
|
|
10186
10875
|
}
|
|
10187
10876
|
}
|
|
10188
10877
|
if (role === "assistant" && message.v === 1) {
|
|
10878
|
+
this.resumeInterruptedVoicePlayback(message);
|
|
10189
10879
|
this.view?.setAssistantState("speaking");
|
|
10190
10880
|
}
|
|
10191
10881
|
return;
|
|
10192
10882
|
}
|
|
10193
|
-
case "assistant.interrupted":
|
|
10883
|
+
case "assistant.interrupted": {
|
|
10884
|
+
if (!this.voicePlaybackIngress?.has(message))
|
|
10885
|
+
this.invalidateVoicePlaybackRearm();
|
|
10194
10886
|
this.presentation?.clear("all");
|
|
10195
|
-
this.
|
|
10196
|
-
|
|
10197
|
-
|
|
10887
|
+
const request = this.currentManualPushRequest();
|
|
10888
|
+
const earlierStop = request !== null &&
|
|
10889
|
+
payload.controlFencingToken === request.fencingToken &&
|
|
10890
|
+
Number.isSafeInteger(payload.controlSequence) &&
|
|
10891
|
+
Number(payload.controlSequence) > 0 && Number(payload.controlSequence) < request.sequence;
|
|
10892
|
+
if (!earlierStop)
|
|
10893
|
+
this.stopManualPushToTalk(false);
|
|
10894
|
+
if (this.view instanceof WidgetView)
|
|
10895
|
+
this.view.interruptPlayback(earlierStop);
|
|
10896
|
+
else
|
|
10897
|
+
this.view?.interruptPlayback();
|
|
10198
10898
|
return;
|
|
10899
|
+
}
|
|
10199
10900
|
case "voice.turn_mode": {
|
|
10200
10901
|
const manual = payload.mode === "manual";
|
|
10902
|
+
if (manual && this.bootstrap?.voice?.turnMode !== "manual")
|
|
10903
|
+
return;
|
|
10904
|
+
if (!manual && this.manualTurn && this.bootstrap?.voice?.turnMode !== "manual")
|
|
10905
|
+
return;
|
|
10201
10906
|
this.manualTurn = manual;
|
|
10202
10907
|
this.pushActive = false;
|
|
10203
10908
|
this.media?.setManualTurn(manual);
|
|
@@ -10208,13 +10913,27 @@ export default class AiLiveAssist {
|
|
|
10208
10913
|
case "voice.push.ready":
|
|
10209
10914
|
if (!this.manualTurn)
|
|
10210
10915
|
return;
|
|
10916
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1) {
|
|
10917
|
+
const request = this.currentManualPushRequest();
|
|
10918
|
+
if (!request || request.state !== "pending" || request.id !== payload.requestId)
|
|
10919
|
+
return;
|
|
10920
|
+
request.state = "capturing";
|
|
10921
|
+
}
|
|
10922
|
+
if (this.media?.isMuted || this.view?.setPushActive(true) === false) {
|
|
10923
|
+
this.media?.endPushToTalk();
|
|
10924
|
+
this.pushActive = false;
|
|
10925
|
+
this.view?.setPushActive(false);
|
|
10926
|
+
this.send("session.interrupt", {});
|
|
10927
|
+
return;
|
|
10928
|
+
}
|
|
10211
10929
|
this.pushActive = true;
|
|
10212
10930
|
this.media?.beginPushToTalk();
|
|
10213
|
-
this.view?.setPushActive(true);
|
|
10214
10931
|
return;
|
|
10215
10932
|
case "voice.push.committed":
|
|
10216
|
-
this.
|
|
10217
|
-
|
|
10933
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1 &&
|
|
10934
|
+
this.currentManualPushRequest()?.id !== payload.requestId)
|
|
10935
|
+
return;
|
|
10936
|
+
this.stopManualPushToTalk(false);
|
|
10218
10937
|
return;
|
|
10219
10938
|
case "session.mode.upgrade_ready":
|
|
10220
10939
|
this.handleModeUpgradeReady(payload);
|
|
@@ -10377,6 +11096,8 @@ export default class AiLiveAssist {
|
|
|
10377
11096
|
this.view?.showActionState(payload.verified === true ? "verified" : "failed");
|
|
10378
11097
|
return;
|
|
10379
11098
|
case "action.revoked":
|
|
11099
|
+
if (!this.ctaAuthorityGenerationAtIngress?.has(message))
|
|
11100
|
+
this.invalidateCtaAuthority();
|
|
10380
11101
|
this.revokeActiveAction();
|
|
10381
11102
|
return;
|
|
10382
11103
|
case "context.resync_required":
|
|
@@ -10480,6 +11201,11 @@ export default class AiLiveAssist {
|
|
|
10480
11201
|
}
|
|
10481
11202
|
case "session.state": {
|
|
10482
11203
|
const state = this.string(payload.state);
|
|
11204
|
+
if (["ending", "ended", "failed", "revoked"].includes(state) &&
|
|
11205
|
+
!this.ctaAuthorityGenerationAtIngress?.has(message)) {
|
|
11206
|
+
this.ctaStoppedSessionId = message.sessionId;
|
|
11207
|
+
this.invalidateCtaAuthority();
|
|
11208
|
+
}
|
|
10483
11209
|
if (!this.hadFencedAuthorityAtIngress(message) &&
|
|
10484
11210
|
(state === "active_text" ||
|
|
10485
11211
|
state === "active_voice" ||
|
|
@@ -10526,6 +11252,8 @@ export default class AiLiveAssist {
|
|
|
10526
11252
|
return;
|
|
10527
11253
|
}
|
|
10528
11254
|
case "provider.reconnecting":
|
|
11255
|
+
if (!this.ctaAuthorityGenerationAtIngress?.has(message))
|
|
11256
|
+
this.invalidateCtaAuthority();
|
|
10529
11257
|
this.view?.showConnecting(true, this.currentDisplayMode());
|
|
10530
11258
|
this.state("reconnecting");
|
|
10531
11259
|
return;
|
|
@@ -10665,15 +11393,18 @@ export default class AiLiveAssist {
|
|
|
10665
11393
|
this.scheduleReconnect(true);
|
|
10666
11394
|
return;
|
|
10667
11395
|
}
|
|
10668
|
-
this.view?.showError(this.string(payload.message), retryable);
|
|
10669
11396
|
if (code === "SESSION_REVOKED") {
|
|
11397
|
+
this.presentSessionError(this.string(payload.message), retryable);
|
|
10670
11398
|
this.finishFromServer(code, message.sessionId);
|
|
10671
11399
|
return;
|
|
10672
11400
|
}
|
|
10673
|
-
//
|
|
10674
|
-
//
|
|
10675
|
-
|
|
11401
|
+
// A causal action result is settled by its exact waiter. Do not surface
|
|
11402
|
+
// that rejection as a session-wide error or tear down healthy media.
|
|
11403
|
+
// Other correlated frames can be fire-and-forget and still need their
|
|
11404
|
+
// server error surfaced.
|
|
11405
|
+
if (operation?.type === "action.result")
|
|
10676
11406
|
return;
|
|
11407
|
+
this.presentSessionError(this.string(payload.message), retryable);
|
|
10677
11408
|
return;
|
|
10678
11409
|
}
|
|
10679
11410
|
}
|
|
@@ -10722,6 +11453,12 @@ export default class AiLiveAssist {
|
|
|
10722
11453
|
return ["click", "type", "select", "submit"].includes(action);
|
|
10723
11454
|
}
|
|
10724
11455
|
pendingActionExecutionRecord(pending) {
|
|
11456
|
+
// An outgoing document has not observed the destination. Its in-memory
|
|
11457
|
+
// result is for a possible SPA transition only; pagehide/transport cleanup
|
|
11458
|
+
// must retain the result-less marker until navigation is actually rebound.
|
|
11459
|
+
const result = pending.deferredNavigationPath !== null && !pending.navigationAcknowledged
|
|
11460
|
+
? null
|
|
11461
|
+
: pending.result;
|
|
10725
11462
|
return {
|
|
10726
11463
|
actionId: pending.actionId,
|
|
10727
11464
|
executionId: pending.executionId,
|
|
@@ -10730,12 +11467,15 @@ export default class AiLiveAssist {
|
|
|
10730
11467
|
expiresAt: pending.expiresAt,
|
|
10731
11468
|
resultMessageId: pending.resultMessageId,
|
|
10732
11469
|
navigationMessageId: pending.navigationMessageId,
|
|
10733
|
-
result:
|
|
10734
|
-
? { ...
|
|
11470
|
+
result: result
|
|
11471
|
+
? { ...result, observed: { ...result.observed } }
|
|
10735
11472
|
: null,
|
|
10736
11473
|
navigationPayload: pending.navigationPayload
|
|
10737
11474
|
? { ...pending.navigationPayload }
|
|
10738
11475
|
: null,
|
|
11476
|
+
...(pending.deferredNavigationPath
|
|
11477
|
+
? { deferredNavigationPath: pending.deferredNavigationPath }
|
|
11478
|
+
: {}),
|
|
10739
11479
|
};
|
|
10740
11480
|
}
|
|
10741
11481
|
persistPendingActionExecution(pending) {
|
|
@@ -10769,7 +11509,7 @@ export default class AiLiveAssist {
|
|
|
10769
11509
|
expiresAt: stored.expiresAt,
|
|
10770
11510
|
ready: deferredSignal(),
|
|
10771
11511
|
readyState: null,
|
|
10772
|
-
mutationObserved: stored.result !== null,
|
|
11512
|
+
mutationObserved: stored.result !== null || stored.deferredNavigationPath !== undefined,
|
|
10773
11513
|
result: stored.result
|
|
10774
11514
|
? { ...stored.result, observed: { ...stored.result.observed } }
|
|
10775
11515
|
: null,
|
|
@@ -10781,8 +11521,12 @@ export default class AiLiveAssist {
|
|
|
10781
11521
|
navigationPayload: stored.navigationPayload
|
|
10782
11522
|
? { ...stored.navigationPayload }
|
|
10783
11523
|
: null,
|
|
11524
|
+
deferredNavigationPath: stored.deferredNavigationPath ?? null,
|
|
11525
|
+
// A restored result may already have reached the server without an ACK.
|
|
11526
|
+
resultDeliveryAttempted: true,
|
|
10784
11527
|
resultAcknowledged: false,
|
|
10785
|
-
navigationAcknowledged: stored.navigationPayload === null
|
|
11528
|
+
navigationAcknowledged: stored.navigationPayload === null &&
|
|
11529
|
+
stored.deferredNavigationPath === undefined,
|
|
10786
11530
|
};
|
|
10787
11531
|
this.pendingNavigationActionResult = pending;
|
|
10788
11532
|
return pending;
|
|
@@ -10813,6 +11557,69 @@ export default class AiLiveAssist {
|
|
|
10813
11557
|
},
|
|
10814
11558
|
};
|
|
10815
11559
|
}
|
|
11560
|
+
markDeferredNavigationUnconfirmed(pending, revision) {
|
|
11561
|
+
const result = this.unconfirmedActionExecutionResult(pending, revision);
|
|
11562
|
+
if (this.pendingNavigationActionResult !== pending)
|
|
11563
|
+
return result;
|
|
11564
|
+
pending.result = result;
|
|
11565
|
+
pending.deferredNavigationPath = null;
|
|
11566
|
+
if (!pending.navigationPayload)
|
|
11567
|
+
pending.navigationAcknowledged = true;
|
|
11568
|
+
this.persistPendingActionExecution(pending);
|
|
11569
|
+
return result;
|
|
11570
|
+
}
|
|
11571
|
+
deferredDocumentNavigationPath(pending, value) {
|
|
11572
|
+
const expectedPath = pending.grant?.destinationPath;
|
|
11573
|
+
if (!expectedPath)
|
|
11574
|
+
return null;
|
|
11575
|
+
try {
|
|
11576
|
+
const destination = new URL(value);
|
|
11577
|
+
return destination.origin === window.location.origin &&
|
|
11578
|
+
destination.username === "" &&
|
|
11579
|
+
destination.password === "" &&
|
|
11580
|
+
destination.search === "" &&
|
|
11581
|
+
destination.hash === "" &&
|
|
11582
|
+
destination.pathname === expectedPath
|
|
11583
|
+
? expectedPath
|
|
11584
|
+
: null;
|
|
11585
|
+
}
|
|
11586
|
+
catch {
|
|
11587
|
+
return null;
|
|
11588
|
+
}
|
|
11589
|
+
}
|
|
11590
|
+
prepareDeferredDocumentNavigationRecovery(pending, destinationUrl) {
|
|
11591
|
+
const deferredNavigationPath = this.deferredDocumentNavigationPath(pending, destinationUrl);
|
|
11592
|
+
if (!deferredNavigationPath)
|
|
11593
|
+
return false;
|
|
11594
|
+
const previousResult = pending.result;
|
|
11595
|
+
const previousNavigationAcknowledged = pending.navigationAcknowledged;
|
|
11596
|
+
pending.result = null;
|
|
11597
|
+
pending.deferredNavigationPath = deferredNavigationPath;
|
|
11598
|
+
pending.navigationAcknowledged = false;
|
|
11599
|
+
if (this.persistPendingActionExecution(pending))
|
|
11600
|
+
return true;
|
|
11601
|
+
pending.result = previousResult;
|
|
11602
|
+
pending.deferredNavigationPath = null;
|
|
11603
|
+
pending.navigationAcknowledged = previousNavigationAcknowledged;
|
|
11604
|
+
return false;
|
|
11605
|
+
}
|
|
11606
|
+
rebaseDeferredDocumentNavigationRecovery(pathname) {
|
|
11607
|
+
const pending = this.restorePendingActionExecution();
|
|
11608
|
+
const expectedPath = pending?.deferredNavigationPath ?? null;
|
|
11609
|
+
if (!pending || !expectedPath || pending.grant !== null)
|
|
11610
|
+
return true;
|
|
11611
|
+
const exactDestination = pathname === expectedPath &&
|
|
11612
|
+
path() === expectedPath &&
|
|
11613
|
+
window.location.search === "" &&
|
|
11614
|
+
window.location.hash === "";
|
|
11615
|
+
pending.result = this.unconfirmedActionExecutionResult(pending, 0, exactDestination
|
|
11616
|
+
? `${window.location.origin}${expectedPath}`
|
|
11617
|
+
: window.location.href);
|
|
11618
|
+
pending.navigationAcknowledged = true;
|
|
11619
|
+
if (!exactDestination)
|
|
11620
|
+
pending.deferredNavigationPath = null;
|
|
11621
|
+
return this.persistPendingActionExecution(pending);
|
|
11622
|
+
}
|
|
10816
11623
|
executionResultWithoutGrant(pending, result) {
|
|
10817
11624
|
return {
|
|
10818
11625
|
actionId: pending.actionId,
|
|
@@ -10866,14 +11673,19 @@ export default class AiLiveAssist {
|
|
|
10866
11673
|
const ready = { state, expiresAt };
|
|
10867
11674
|
pending.expiresAt = expiresAt;
|
|
10868
11675
|
pending.readyState = ready;
|
|
10869
|
-
if (state === "already_started" &&
|
|
11676
|
+
if (state === "already_started" &&
|
|
11677
|
+
pending.result === null &&
|
|
11678
|
+
(pending.deferredNavigationPath === null ||
|
|
11679
|
+
pending.navigationAcknowledged)) {
|
|
10870
11680
|
pending.result = this.unconfirmedActionExecutionResult(pending);
|
|
10871
11681
|
}
|
|
10872
11682
|
this.persistPendingActionExecution(pending);
|
|
10873
11683
|
pending.ready.resolve(ready);
|
|
10874
11684
|
if (scheduleFlush &&
|
|
10875
11685
|
state === "already_started" &&
|
|
10876
|
-
pending.grant === null
|
|
11686
|
+
pending.grant === null &&
|
|
11687
|
+
(pending.deferredNavigationPath === null ||
|
|
11688
|
+
pending.navigationAcknowledged)) {
|
|
10877
11689
|
queueMicrotask(() => void this.flushPendingNavigationActionResult());
|
|
10878
11690
|
}
|
|
10879
11691
|
return true;
|
|
@@ -10928,13 +11740,20 @@ export default class AiLiveAssist {
|
|
|
10928
11740
|
if (ready?.state === "already_started") {
|
|
10929
11741
|
pending.result ?? (pending.result = this.unconfirmedActionExecutionResult(pending));
|
|
10930
11742
|
this.persistPendingActionExecution(pending);
|
|
10931
|
-
await this.flushPendingNavigationActionResult();
|
|
11743
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
11744
|
+
if (!terminalDelivered &&
|
|
11745
|
+
!this.terminalRequestPending &&
|
|
11746
|
+
!this.ended &&
|
|
11747
|
+
!this.destroyed) {
|
|
11748
|
+
this.scheduleReconnect(true);
|
|
11749
|
+
}
|
|
10932
11750
|
return "pending";
|
|
10933
11751
|
}
|
|
10934
11752
|
}
|
|
10935
11753
|
pending.result ?? (pending.result = this.unconfirmedActionExecutionResult(pending));
|
|
10936
11754
|
this.persistPendingActionExecution(pending);
|
|
10937
|
-
|
|
11755
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
11756
|
+
if (!terminalDelivered &&
|
|
10938
11757
|
!this.terminalRequestPending &&
|
|
10939
11758
|
!this.ended &&
|
|
10940
11759
|
!this.destroyed) {
|
|
@@ -11075,7 +11894,9 @@ export default class AiLiveAssist {
|
|
|
11075
11894
|
if (this.result?.protocolVersion === 2 &&
|
|
11076
11895
|
this.actionRequiresExecutionTransition(grant.action)) {
|
|
11077
11896
|
if (this.pendingNavigationActionResult !== null) {
|
|
11078
|
-
|
|
11897
|
+
const result = this.blockedActionResult(grant, "Another page action is still awaiting secure verification.", context.currentRevision);
|
|
11898
|
+
this.send("action.result", result);
|
|
11899
|
+
return result;
|
|
11079
11900
|
}
|
|
11080
11901
|
pendingExecution = {
|
|
11081
11902
|
grant,
|
|
@@ -11094,6 +11915,8 @@ export default class AiLiveAssist {
|
|
|
11094
11915
|
resultMessageId: randomId("msg_action_result"),
|
|
11095
11916
|
navigationMessageId: randomId("msg_context_navigation"),
|
|
11096
11917
|
navigationPayload: null,
|
|
11918
|
+
deferredNavigationPath: null,
|
|
11919
|
+
resultDeliveryAttempted: false,
|
|
11097
11920
|
resultAcknowledged: false,
|
|
11098
11921
|
navigationAcknowledged: true,
|
|
11099
11922
|
};
|
|
@@ -11121,6 +11944,7 @@ export default class AiLiveAssist {
|
|
|
11121
11944
|
channel,
|
|
11122
11945
|
result: null,
|
|
11123
11946
|
causalNavigationObserved: false,
|
|
11947
|
+
resultAcknowledged: false,
|
|
11124
11948
|
deliveryCommitted: false,
|
|
11125
11949
|
}
|
|
11126
11950
|
: null;
|
|
@@ -11155,37 +11979,80 @@ export default class AiLiveAssist {
|
|
|
11155
11979
|
if (this.pendingNavigationActionResult !== pendingExecution) {
|
|
11156
11980
|
return deliveryResult;
|
|
11157
11981
|
}
|
|
11158
|
-
const
|
|
11159
|
-
? pendingExecution.causalNavigationDeliveryConfirmed
|
|
11160
|
-
: await this.flushPendingNavigationActionResult();
|
|
11161
|
-
if (deferredNavigation &&
|
|
11162
|
-
confirmed &&
|
|
11982
|
+
const deferredNavigationCanRelease = Boolean(deferredNavigation &&
|
|
11163
11983
|
authorityIsCurrent() &&
|
|
11164
11984
|
Date.parse(pendingExecution.expiresAt) > Date.now() &&
|
|
11165
|
-
|
|
11166
|
-
|
|
11985
|
+
this.prepareDeferredDocumentNavigationRecovery(pendingExecution, deferredNavigation));
|
|
11986
|
+
if (deferredNavigationCanRelease && deferredNavigation) {
|
|
11987
|
+
// Keep the verified result in memory so a same-document router can
|
|
11988
|
+
// deliver it with the causal navigation. The persisted copy remains
|
|
11989
|
+
// intentionally result-less until navigation settles, preserving the
|
|
11990
|
+
// cross-document recovery contract if this click unloads the page.
|
|
11991
|
+
pendingExecution.result = deliveryResult;
|
|
11992
|
+
try {
|
|
11993
|
+
if (await this.navigateTo(deferredNavigation)) {
|
|
11994
|
+
return deliveryResult;
|
|
11995
|
+
}
|
|
11996
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
11997
|
+
}
|
|
11998
|
+
catch {
|
|
11999
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
12000
|
+
}
|
|
12001
|
+
}
|
|
12002
|
+
else if (deferredNavigation) {
|
|
12003
|
+
deliveryResult = this.markDeferredNavigationUnconfirmed(pendingExecution, context.currentRevision);
|
|
12004
|
+
}
|
|
12005
|
+
if (!pendingExecution.causalNavigationDeliveryAttempted) {
|
|
12006
|
+
const terminalDelivered = await this.flushPendingNavigationActionResult();
|
|
12007
|
+
if (!terminalDelivered &&
|
|
12008
|
+
!this.terminalRequestPending &&
|
|
12009
|
+
!this.ended &&
|
|
12010
|
+
!this.destroyed) {
|
|
12011
|
+
this.scheduleReconnect(true);
|
|
12012
|
+
}
|
|
11167
12013
|
}
|
|
11168
12014
|
return deliveryResult;
|
|
11169
12015
|
}
|
|
11170
|
-
if (
|
|
12016
|
+
if (!deferredNavigation &&
|
|
12017
|
+
legacyExecution &&
|
|
12018
|
+
this.legacyActionExecution === legacyExecution) {
|
|
11171
12019
|
this.legacyActionExecution = null;
|
|
11172
12020
|
}
|
|
11173
12021
|
const messageId = authorityIsCurrent()
|
|
11174
12022
|
? this.send("action.result", result)
|
|
11175
12023
|
: null;
|
|
11176
|
-
if (!deferredNavigation
|
|
12024
|
+
if (!deferredNavigation)
|
|
11177
12025
|
return result;
|
|
12026
|
+
if (!messageId) {
|
|
12027
|
+
if (legacyExecution)
|
|
12028
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12029
|
+
return result;
|
|
12030
|
+
}
|
|
11178
12031
|
const outcome = await channel.waitForOutcome(messageId, 2500, channel.lastClientSequence);
|
|
11179
12032
|
if (outcome.status === "ack" &&
|
|
11180
12033
|
authorityIsCurrent() &&
|
|
11181
12034
|
Date.parse(grant.expiresAt) > Date.now() &&
|
|
11182
12035
|
new URL(deferredNavigation).origin === window.location.origin) {
|
|
11183
|
-
|
|
12036
|
+
if (legacyExecution)
|
|
12037
|
+
legacyExecution.resultAcknowledged = true;
|
|
12038
|
+
const navigationReleased = await this.navigateTo(deferredNavigation);
|
|
12039
|
+
if (!navigationReleased && legacyExecution) {
|
|
12040
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12041
|
+
}
|
|
12042
|
+
}
|
|
12043
|
+
else if (outcome.status === "ack" && legacyExecution) {
|
|
12044
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
11184
12045
|
}
|
|
11185
12046
|
else if (outcome.status === "explicit_error" &&
|
|
11186
12047
|
!outcome.retryable &&
|
|
11187
12048
|
authorityIsCurrent()) {
|
|
11188
|
-
this.
|
|
12049
|
+
const rejectedExecutionStillOwnsState = !legacyExecution || this.legacyActionExecution === legacyExecution;
|
|
12050
|
+
if (legacyExecution) {
|
|
12051
|
+
this.abandonLegacyCausalDelivery(legacyExecution);
|
|
12052
|
+
}
|
|
12053
|
+
if (rejectedExecutionStillOwnsState) {
|
|
12054
|
+
this.view?.showActionState("failed");
|
|
12055
|
+
}
|
|
11189
12056
|
}
|
|
11190
12057
|
else if (this.controlOutcomeNeedsRetry(outcome) && authorityIsCurrent()) {
|
|
11191
12058
|
this.scheduleReconnect(true);
|
|
@@ -11300,16 +12167,20 @@ export default class AiLiveAssist {
|
|
|
11300
12167
|
if (!navigationMessageId) {
|
|
11301
12168
|
return this.abandonLegacyCausalDelivery(execution);
|
|
11302
12169
|
}
|
|
11303
|
-
const resultMessageId =
|
|
12170
|
+
const resultMessageId = execution.resultAcknowledged
|
|
12171
|
+
? null
|
|
12172
|
+
: this.send("action.result", result);
|
|
11304
12173
|
const resultSequence = channel.lastClientSequence;
|
|
11305
|
-
if (!resultMessageId) {
|
|
12174
|
+
if (!execution.resultAcknowledged && !resultMessageId) {
|
|
11306
12175
|
return this.abandonLegacyCausalDelivery(execution);
|
|
11307
12176
|
}
|
|
11308
12177
|
execution.deliveryCommitted = true;
|
|
11309
12178
|
this.resetActionGrantAuthority();
|
|
11310
12179
|
const outcomes = await Promise.all([
|
|
11311
12180
|
this.trackContextNavigationAcknowledgement(channel, navigationMessageId, navigationSequence, payload),
|
|
11312
|
-
|
|
12181
|
+
...(resultMessageId
|
|
12182
|
+
? [channel.waitForOutcome(resultMessageId, 5000, resultSequence)]
|
|
12183
|
+
: []),
|
|
11313
12184
|
]);
|
|
11314
12185
|
if (outcomes.every((outcome) => outcome.status === "ack"))
|
|
11315
12186
|
return true;
|
|
@@ -11352,25 +12223,35 @@ export default class AiLiveAssist {
|
|
|
11352
12223
|
? this.trackContextNavigationAcknowledgement(channel, messageId, clientSequence, pending.navigationPayload)
|
|
11353
12224
|
: channel.waitForOutcome(messageId, 5000, clientSequence);
|
|
11354
12225
|
return delivery.then((outcome) => {
|
|
11355
|
-
|
|
11356
|
-
this.
|
|
11357
|
-
|
|
11358
|
-
if (
|
|
11359
|
-
|
|
11360
|
-
|
|
12226
|
+
const isCurrent = this.pendingNavigationActionResult === pending &&
|
|
12227
|
+
this.channel === channel;
|
|
12228
|
+
if (outcome.status === "ack") {
|
|
12229
|
+
if (kind === "result")
|
|
12230
|
+
pending.resultAcknowledged = true;
|
|
12231
|
+
else
|
|
12232
|
+
pending.navigationAcknowledged = true;
|
|
12233
|
+
if (isCurrent) {
|
|
12234
|
+
if (pending.resultAcknowledged && pending.navigationAcknowledged) {
|
|
12235
|
+
this.clearPendingActionExecution(pending);
|
|
12236
|
+
}
|
|
12237
|
+
}
|
|
12238
|
+
// Ingress-time revocation can retire the pending record before this
|
|
12239
|
+
// exact waiter settles. The correlated ACK still proves delivery and
|
|
12240
|
+
// must not reconnect a healthy transport or mutate a newer action.
|
|
12241
|
+
return true;
|
|
12242
|
+
}
|
|
12243
|
+
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
12244
|
+
if (isCurrent) {
|
|
11361
12245
|
this.clearPendingActionExecution(pending);
|
|
12246
|
+
this.pendingAction = false;
|
|
11362
12247
|
this.view?.showActionState("unconfirmed");
|
|
11363
12248
|
}
|
|
11364
|
-
|
|
12249
|
+
// A definitive operation-local result rejection terminalizes only this
|
|
12250
|
+
// action. It is not a transport failure, even if action.revoked already
|
|
12251
|
+
// cleared the local record or a newer channel has since been installed.
|
|
12252
|
+
return kind === "result";
|
|
11365
12253
|
}
|
|
11366
|
-
|
|
11367
|
-
pending.resultAcknowledged = true;
|
|
11368
|
-
else
|
|
11369
|
-
pending.navigationAcknowledged = true;
|
|
11370
|
-
if (pending.resultAcknowledged && pending.navigationAcknowledged) {
|
|
11371
|
-
this.clearPendingActionExecution(pending);
|
|
11372
|
-
}
|
|
11373
|
-
return true;
|
|
12254
|
+
return false;
|
|
11374
12255
|
});
|
|
11375
12256
|
}
|
|
11376
12257
|
pendingNavigationPayloadMatchesGrant(pending) {
|
|
@@ -11419,12 +12300,25 @@ export default class AiLiveAssist {
|
|
|
11419
12300
|
this.view?.showActionState("unconfirmed");
|
|
11420
12301
|
return true;
|
|
11421
12302
|
}
|
|
12303
|
+
if (pending.deferredNavigationPath !== null &&
|
|
12304
|
+
pending.navigationAcknowledged &&
|
|
12305
|
+
pending.readyState === null) {
|
|
12306
|
+
const ready = await this.waitForActionExecutionReady(pending);
|
|
12307
|
+
if (this.pendingNavigationActionResult !== pending)
|
|
12308
|
+
return true;
|
|
12309
|
+
if (ready?.state !== "already_started")
|
|
12310
|
+
return false;
|
|
12311
|
+
}
|
|
11422
12312
|
if (!pending.result) {
|
|
11423
12313
|
const ready = await this.waitForActionExecutionReady(pending);
|
|
11424
12314
|
if (this.pendingNavigationActionResult !== pending)
|
|
11425
12315
|
return true;
|
|
11426
12316
|
if (!ready)
|
|
11427
12317
|
return false;
|
|
12318
|
+
if (pending.deferredNavigationPath !== null &&
|
|
12319
|
+
!pending.navigationAcknowledged) {
|
|
12320
|
+
return false;
|
|
12321
|
+
}
|
|
11428
12322
|
pending.result = this.unconfirmedActionExecutionResult(pending);
|
|
11429
12323
|
this.persistPendingActionExecution(pending);
|
|
11430
12324
|
}
|
|
@@ -11455,6 +12349,7 @@ export default class AiLiveAssist {
|
|
|
11455
12349
|
}
|
|
11456
12350
|
}
|
|
11457
12351
|
if (!pending.resultAcknowledged) {
|
|
12352
|
+
pending.resultDeliveryAttempted = true;
|
|
11458
12353
|
const resultMessageId = this.send("action.result", pending.result, pending.resultMessageId);
|
|
11459
12354
|
if (resultMessageId) {
|
|
11460
12355
|
acknowledgements.push(this.observePendingNavigationAck(pending, "result", channel, resultMessageId, channel.lastClientSequence));
|
|
@@ -11478,8 +12373,11 @@ export default class AiLiveAssist {
|
|
|
11478
12373
|
},
|
|
11479
12374
|
};
|
|
11480
12375
|
}
|
|
11481
|
-
navigateTo(url) {
|
|
11482
|
-
|
|
12376
|
+
async navigateTo(url) {
|
|
12377
|
+
const context = this.context;
|
|
12378
|
+
if (!context)
|
|
12379
|
+
return false;
|
|
12380
|
+
return (await context.activateReleasedNavigation(url)) === "settled";
|
|
11483
12381
|
}
|
|
11484
12382
|
pruneCompletedActionGrants(now = Date.now()) {
|
|
11485
12383
|
for (const [key, entry] of this.completedActionGrants) {
|
|
@@ -11638,7 +12536,7 @@ export default class AiLiveAssist {
|
|
|
11638
12536
|
return;
|
|
11639
12537
|
}
|
|
11640
12538
|
if (outcome.status === "explicit_error") {
|
|
11641
|
-
this.
|
|
12539
|
+
this.presentSessionError(outcome.message, false);
|
|
11642
12540
|
}
|
|
11643
12541
|
}
|
|
11644
12542
|
parseGrant(payload, requireCurrentAuthority = true) {
|
|
@@ -11804,22 +12702,179 @@ export default class AiLiveAssist {
|
|
|
11804
12702
|
: this.mode === "voice"
|
|
11805
12703
|
? "active"
|
|
11806
12704
|
: "unavailable",
|
|
11807
|
-
playback: this.
|
|
12705
|
+
playback: this.advertisedMediaPlaybackState(),
|
|
11808
12706
|
captions: true,
|
|
11809
12707
|
});
|
|
11810
12708
|
}
|
|
12709
|
+
advertisedMediaPlaybackState(mode = this.mode) {
|
|
12710
|
+
// This is the visitor's explicit Voice authorization, not evidence that
|
|
12711
|
+
// remote audio is already audible. Protocol v2 reports actual playback
|
|
12712
|
+
// separately through playback.state before the UI can show Speaking.
|
|
12713
|
+
return mode === "voice" ? "active" : "paused";
|
|
12714
|
+
}
|
|
12715
|
+
flushPlaybackState() {
|
|
12716
|
+
const pending = this.pendingPlaybackState;
|
|
12717
|
+
const result = this.result;
|
|
12718
|
+
const channel = this.channel;
|
|
12719
|
+
if (!pending || !result)
|
|
12720
|
+
return;
|
|
12721
|
+
if (result.protocolVersion !== 2) {
|
|
12722
|
+
this.pendingPlaybackState = null;
|
|
12723
|
+
return;
|
|
12724
|
+
}
|
|
12725
|
+
if (!channel?.hasFencedAuthority)
|
|
12726
|
+
return;
|
|
12727
|
+
if (this.send("playback.state", pending) &&
|
|
12728
|
+
this.pendingPlaybackState === pending) {
|
|
12729
|
+
this.pendingPlaybackState = null;
|
|
12730
|
+
}
|
|
12731
|
+
}
|
|
11811
12732
|
interrupt() {
|
|
11812
12733
|
if (this.mode !== "voice")
|
|
11813
12734
|
return;
|
|
12735
|
+
const barrier = { operation: null };
|
|
12736
|
+
this.voicePlaybackInterruptBarrier = barrier;
|
|
12737
|
+
this.invalidateVoicePlaybackRearm();
|
|
12738
|
+
if (this.view instanceof WidgetView)
|
|
12739
|
+
this.view.interruptPlayback();
|
|
11814
12740
|
this.presentation?.clear("all");
|
|
11815
|
-
this.
|
|
12741
|
+
this.stopManualPushToTalk(false);
|
|
12742
|
+
const channel = this.channel;
|
|
12743
|
+
const sessionId = this.result?.sessionId;
|
|
12744
|
+
const messageId = this.send("session.interrupt", {});
|
|
12745
|
+
if (messageId &&
|
|
12746
|
+
channel &&
|
|
12747
|
+
sessionId &&
|
|
12748
|
+
this.channel === channel &&
|
|
12749
|
+
this.voicePlaybackInterruptBarrier === barrier &&
|
|
12750
|
+
Number.isSafeInteger(channel.lastClientSequence) &&
|
|
12751
|
+
channel.lastClientSequence > 0) {
|
|
12752
|
+
barrier.operation = {
|
|
12753
|
+
channel,
|
|
12754
|
+
fencingToken: channel.leaseToken,
|
|
12755
|
+
sessionId,
|
|
12756
|
+
messageId,
|
|
12757
|
+
clientSequence: channel.lastClientSequence,
|
|
12758
|
+
interruptedSequence: null,
|
|
12759
|
+
};
|
|
12760
|
+
}
|
|
12761
|
+
}
|
|
12762
|
+
observeVoicePlaybackInterrupt(message) {
|
|
12763
|
+
const operation = this.voicePlaybackInterruptBarrier?.operation;
|
|
12764
|
+
if (!operation ||
|
|
12765
|
+
this.channel !== operation.channel ||
|
|
12766
|
+
!this.channel.hasFencedAuthority ||
|
|
12767
|
+
this.channel.leaseToken !== operation.fencingToken ||
|
|
12768
|
+
this.result?.sessionId !== operation.sessionId ||
|
|
12769
|
+
message.sessionId !== operation.sessionId ||
|
|
12770
|
+
!Number.isSafeInteger(message.sequence) ||
|
|
12771
|
+
message.sequence <= 0)
|
|
12772
|
+
return;
|
|
12773
|
+
if (message.type === "assistant.interrupted") {
|
|
12774
|
+
operation.interruptedSequence = message.sequence;
|
|
12775
|
+
return;
|
|
12776
|
+
}
|
|
12777
|
+
if (message.type !== "ack" ||
|
|
12778
|
+
message.payload.messageId !== operation.messageId ||
|
|
12779
|
+
message.payload.sequence !== operation.clientSequence ||
|
|
12780
|
+
operation.interruptedSequence === null ||
|
|
12781
|
+
message.sequence <= operation.interruptedSequence)
|
|
12782
|
+
return;
|
|
12783
|
+
// This only opens admission. Frames queued before the exact Stop ACK
|
|
12784
|
+
// cannot count as a fresh visitor turn, and the ACK never resumes audio.
|
|
12785
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
12786
|
+
this.voicePlaybackAdmissionAfterSequence = message.sequence;
|
|
12787
|
+
this.invalidateVoicePlaybackRearm();
|
|
12788
|
+
}
|
|
12789
|
+
invalidateVoicePlaybackRearm() {
|
|
12790
|
+
this.voicePlaybackInterruptionGeneration =
|
|
12791
|
+
(this.voicePlaybackInterruptionGeneration ?? 0) + 1;
|
|
12792
|
+
this.voicePlaybackRearm = null;
|
|
12793
|
+
}
|
|
12794
|
+
currentVoicePlaybackIngress(message) {
|
|
12795
|
+
const ingress = this.voicePlaybackIngress?.get(message);
|
|
12796
|
+
if (!ingress ||
|
|
12797
|
+
this.voicePlaybackInterruptBarrier ||
|
|
12798
|
+
!(this.view instanceof WidgetView) ||
|
|
12799
|
+
this.mode !== "voice" ||
|
|
12800
|
+
this.lifecyclePhase !== "active_voice" ||
|
|
12801
|
+
this.ended ||
|
|
12802
|
+
this.destroyed ||
|
|
12803
|
+
this.terminalRequestPending ||
|
|
12804
|
+
!this.channel?.hasFencedAuthority ||
|
|
12805
|
+
!this.hadFencedAuthorityAtIngress(message) ||
|
|
12806
|
+
ingress.channel !== this.channel ||
|
|
12807
|
+
ingress.fencingToken !== this.channel.leaseToken ||
|
|
12808
|
+
ingress.generation !== this.voicePlaybackInterruptionGeneration ||
|
|
12809
|
+
message.sessionId !== this.result?.sessionId ||
|
|
12810
|
+
!Number.isSafeInteger(message.sequence) ||
|
|
12811
|
+
message.sequence <= 0)
|
|
12812
|
+
return null;
|
|
12813
|
+
return { ...ingress, channel: this.channel };
|
|
12814
|
+
}
|
|
12815
|
+
admitVoicePlaybackTurn(message) {
|
|
12816
|
+
const ingress = this.currentVoicePlaybackIngress(message);
|
|
12817
|
+
if (!ingress ||
|
|
12818
|
+
message.sequence <= (this.voicePlaybackAdmissionAfterSequence ?? 0))
|
|
12819
|
+
return;
|
|
12820
|
+
this.voicePlaybackRearm = {
|
|
12821
|
+
...ingress,
|
|
12822
|
+
sessionId: message.sessionId,
|
|
12823
|
+
visitorSequence: message.sequence,
|
|
12824
|
+
};
|
|
12825
|
+
}
|
|
12826
|
+
hasAdmittedVoicePlaybackTurn(message) {
|
|
12827
|
+
// The durable turn event namespace is shared by protocol v1 and v2. Keep
|
|
12828
|
+
// the legacy/no-ledger confirmation interruption behavior unchanged.
|
|
12829
|
+
if (!message ||
|
|
12830
|
+
!/^turn_visitor_[a-f0-9]{64}$/u.test(message.id) ||
|
|
12831
|
+
!this.currentVoicePlaybackIngress(message))
|
|
12832
|
+
return false;
|
|
12833
|
+
return (this.voicePlaybackRearm?.sessionId === message.sessionId &&
|
|
12834
|
+
this.voicePlaybackRearm.visitorSequence === message.sequence);
|
|
12835
|
+
}
|
|
12836
|
+
resumeInterruptedVoicePlayback(message) {
|
|
12837
|
+
const ingress = this.currentVoicePlaybackIngress(message), rearm = this.voicePlaybackRearm;
|
|
12838
|
+
if (!ingress ||
|
|
12839
|
+
!rearm ||
|
|
12840
|
+
!(this.view instanceof WidgetView) ||
|
|
12841
|
+
message.payload.cause !== undefined ||
|
|
12842
|
+
rearm.generation !== ingress.generation ||
|
|
12843
|
+
rearm.channel !== ingress.channel ||
|
|
12844
|
+
rearm.fencingToken !== ingress.fencingToken ||
|
|
12845
|
+
rearm.sessionId !== message.sessionId ||
|
|
12846
|
+
message.sequence <= rearm.visitorSequence)
|
|
12847
|
+
return;
|
|
12848
|
+
this.voicePlaybackRearm = null;
|
|
12849
|
+
this.view.resumeInterruptedPlayback();
|
|
12850
|
+
}
|
|
12851
|
+
stopManualPushToTalk(discardProviderBuffer) {
|
|
12852
|
+
const wasActive = this.pushActive || Boolean(this.manualPushRequest);
|
|
12853
|
+
this.manualPushRequest = null;
|
|
12854
|
+
this.media?.endPushToTalk?.();
|
|
11816
12855
|
this.pushActive = false;
|
|
11817
|
-
this.view?.setPushActive(false);
|
|
11818
|
-
|
|
12856
|
+
this.view?.setPushActive?.(false);
|
|
12857
|
+
if (discardProviderBuffer && wasActive) {
|
|
12858
|
+
this.send("session.interrupt", {});
|
|
12859
|
+
}
|
|
12860
|
+
}
|
|
12861
|
+
presentSessionError(message, retryable = false, sessionActive) {
|
|
12862
|
+
// An error surface hides every manual-turn control. Establish the matching
|
|
12863
|
+
// controller/media invariant first so no microphone capture can continue
|
|
12864
|
+
// invisibly behind the compact error card.
|
|
12865
|
+
this.stopManualPushToTalk(true);
|
|
12866
|
+
if (sessionActive === undefined) {
|
|
12867
|
+
this.view?.showError(message, retryable);
|
|
12868
|
+
}
|
|
12869
|
+
else {
|
|
12870
|
+
this.view?.showError(message, retryable, sessionActive);
|
|
12871
|
+
}
|
|
11819
12872
|
}
|
|
11820
12873
|
updateVoiceTurnMode(manual) {
|
|
11821
12874
|
if (this.mode !== "voice" || !this.channel?.isOpen)
|
|
11822
12875
|
return;
|
|
12876
|
+
if (manual && this.bootstrap?.voice?.turnMode !== "manual")
|
|
12877
|
+
return;
|
|
11823
12878
|
if (!manual && this.bootstrap?.voice?.turnMode === "manual")
|
|
11824
12879
|
return;
|
|
11825
12880
|
if (this.pushActive) {
|
|
@@ -11834,16 +12889,47 @@ export default class AiLiveAssist {
|
|
|
11834
12889
|
return;
|
|
11835
12890
|
}
|
|
11836
12891
|
if (active) {
|
|
12892
|
+
if (this.bootstrap?.voice?.manualPushReadiness === 1) {
|
|
12893
|
+
if (this.pushActive || this.currentManualPushRequest())
|
|
12894
|
+
return;
|
|
12895
|
+
const channel = this.channel, sessionId = this.result?.sessionId;
|
|
12896
|
+
if (!sessionId || !channel.hasFencedAuthority || !channel.leaseToken ||
|
|
12897
|
+
this.ended || this.destroyed || this.terminalRequestPending ||
|
|
12898
|
+
this.view?.setPushPending(true) === false)
|
|
12899
|
+
return;
|
|
12900
|
+
const id = randomId("voice_start");
|
|
12901
|
+
const request = {
|
|
12902
|
+
id, channel, sessionId, fencingToken: channel.leaseToken,
|
|
12903
|
+
effectGeneration: this.sessionEffectGeneration,
|
|
12904
|
+
sequence: channel.lastClientSequence + 1,
|
|
12905
|
+
state: "pending",
|
|
12906
|
+
};
|
|
12907
|
+
this.manualPushRequest = request;
|
|
12908
|
+
if (this.send("voice.push.start", { requestId: id }, id) !== id)
|
|
12909
|
+
this.stopManualPushToTalk(false);
|
|
12910
|
+
return;
|
|
12911
|
+
}
|
|
11837
12912
|
if (!this.pushActive)
|
|
11838
12913
|
this.send("voice.push.start", {});
|
|
11839
12914
|
return;
|
|
11840
12915
|
}
|
|
12916
|
+
const request = this.currentManualPushRequest();
|
|
12917
|
+
if (request?.state === "pending") {
|
|
12918
|
+
this.stopManualPushToTalk(true);
|
|
12919
|
+
return;
|
|
12920
|
+
}
|
|
11841
12921
|
if (!this.pushActive)
|
|
11842
12922
|
return;
|
|
11843
|
-
this.
|
|
11844
|
-
this.
|
|
11845
|
-
|
|
11846
|
-
|
|
12923
|
+
this.stopManualPushToTalk(false);
|
|
12924
|
+
this.send("voice.push.commit", request ? { requestId: request.id } : {});
|
|
12925
|
+
}
|
|
12926
|
+
currentManualPushRequest() {
|
|
12927
|
+
const request = this.manualPushRequest;
|
|
12928
|
+
return request && this.manualTurn && this.mode === "voice" &&
|
|
12929
|
+
this.lifecyclePhase === "active_voice" && !this.ended && !this.destroyed && !this.terminalRequestPending &&
|
|
12930
|
+
request.channel === this.channel && request.sessionId === this.result?.sessionId &&
|
|
12931
|
+
request.fencingToken === this.channel?.leaseToken && this.channel?.hasFencedAuthority &&
|
|
12932
|
+
request.effectGeneration === this.sessionEffectGeneration ? request : null;
|
|
11847
12933
|
}
|
|
11848
12934
|
pauseCommandKey(command) {
|
|
11849
12935
|
return `${command.operationId}\u0000${command.clientSequence}\u0000${command.fencingToken}`;
|
|
@@ -11992,6 +13078,10 @@ export default class AiLiveAssist {
|
|
|
11992
13078
|
(this.authoritativePauseStateByChannel ?? (this.authoritativePauseStateByChannel = new WeakMap())).set(channel, state);
|
|
11993
13079
|
}
|
|
11994
13080
|
if (state === "paused") {
|
|
13081
|
+
// A fenced server pause may arrive independently of the local pause
|
|
13082
|
+
// button (for example after outside-page interaction). Stop browser
|
|
13083
|
+
// capture without issuing another control command into a paused session.
|
|
13084
|
+
this.stopManualPushToTalk(false);
|
|
11995
13085
|
this.view?.setPaused(true);
|
|
11996
13086
|
if (this.lifecyclePhase !== "paused")
|
|
11997
13087
|
this.state("paused");
|
|
@@ -12064,6 +13154,17 @@ export default class AiLiveAssist {
|
|
|
12064
13154
|
async performPauseCommand(paused, rollbackState) {
|
|
12065
13155
|
if (this.terminalRequestPending || this.ended || this.destroyed)
|
|
12066
13156
|
return;
|
|
13157
|
+
if (paused) {
|
|
13158
|
+
// Controller-originated pauses bypass WidgetView's release callback.
|
|
13159
|
+
// Discard any in-flight manual turn before the first await so capture
|
|
13160
|
+
// cannot remain live behind a paused or transitioning surface.
|
|
13161
|
+
this.stopManualPushToTalk(true);
|
|
13162
|
+
// Make the pause intent visible synchronously. This also prevents an
|
|
13163
|
+
// already-queued voice.push.ready frame from reopening capture while
|
|
13164
|
+
// the authoritative pause command is in flight. Rollback below restores
|
|
13165
|
+
// the prior ready state if the pause is rejected.
|
|
13166
|
+
this.view?.setPaused(true);
|
|
13167
|
+
}
|
|
12067
13168
|
const commandGeneration = (Number.isSafeInteger(this.pauseCommandGeneration)
|
|
12068
13169
|
? this.pauseCommandGeneration
|
|
12069
13170
|
: 0) + 1;
|
|
@@ -12088,7 +13189,7 @@ export default class AiLiveAssist {
|
|
|
12088
13189
|
else
|
|
12089
13190
|
this.view?.setPaused(!paused);
|
|
12090
13191
|
if (message)
|
|
12091
|
-
this.
|
|
13192
|
+
this.presentSessionError(message, false);
|
|
12092
13193
|
};
|
|
12093
13194
|
if (!result || !channel || fencingToken <= 0) {
|
|
12094
13195
|
rollback();
|
|
@@ -12204,7 +13305,7 @@ export default class AiLiveAssist {
|
|
|
12204
13305
|
await this.flushPendingPageAssistanceRevocation();
|
|
12205
13306
|
}
|
|
12206
13307
|
pageAssistanceRevocationStorageKey() {
|
|
12207
|
-
return `${PAGE_ASSISTANCE_REVOCATION_STORAGE_PREFIX}${this.siteKey}`;
|
|
13308
|
+
return `${PAGE_ASSISTANCE_REVOCATION_STORAGE_PREFIX}${this.storageNamespace ?? this.siteKey}`;
|
|
12208
13309
|
}
|
|
12209
13310
|
rememberPendingPageAssistanceRevocation(saved) {
|
|
12210
13311
|
const existing = this.restorePendingPageAssistanceRevocation();
|
|
@@ -12341,7 +13442,7 @@ export default class AiLiveAssist {
|
|
|
12341
13442
|
return this.finalizePageAssistanceRevocation(pending);
|
|
12342
13443
|
}
|
|
12343
13444
|
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
12344
|
-
this.
|
|
13445
|
+
this.presentSessionError(outcome.message, false);
|
|
12345
13446
|
return false;
|
|
12346
13447
|
}
|
|
12347
13448
|
if (this.controlOutcomeNeedsRetry(outcome))
|
|
@@ -12414,7 +13515,7 @@ export default class AiLiveAssist {
|
|
|
12414
13515
|
updateCaptions(enabled) {
|
|
12415
13516
|
this.send("media.state", {
|
|
12416
13517
|
microphone: this.mode === "voice" ? "active" : "unavailable",
|
|
12417
|
-
playback: this.
|
|
13518
|
+
playback: this.advertisedMediaPlaybackState(),
|
|
12418
13519
|
captions: enabled,
|
|
12419
13520
|
});
|
|
12420
13521
|
}
|
|
@@ -12431,6 +13532,8 @@ export default class AiLiveAssist {
|
|
|
12431
13532
|
}
|
|
12432
13533
|
}
|
|
12433
13534
|
setModeTransitionPending(mode) {
|
|
13535
|
+
if (mode)
|
|
13536
|
+
this.clearCtaAuthority();
|
|
12434
13537
|
if (this.view instanceof WidgetView) {
|
|
12435
13538
|
this.view.setModeTransitionPending(mode);
|
|
12436
13539
|
}
|
|
@@ -12741,7 +13844,7 @@ export default class AiLiveAssist {
|
|
|
12741
13844
|
];
|
|
12742
13845
|
await this.waitForModeUpgradeConnectionDeadline(this.updateModeUpgradeConsent(attempt, requestedScopes), attempt);
|
|
12743
13846
|
this.assertModeUpgradeCurrent(attempt);
|
|
12744
|
-
|
|
13847
|
+
while ((this.pendingContextNavigationAcknowledgements?.size ?? 0) > 0) {
|
|
12745
13848
|
const navigationAcknowledged = await this.waitForModeUpgradeConnectionDeadline(this.waitForPendingContextNavigationAcknowledgements(), attempt);
|
|
12746
13849
|
this.assertModeUpgradeCurrent(attempt);
|
|
12747
13850
|
if (!navigationAcknowledged) {
|
|
@@ -12804,7 +13907,7 @@ export default class AiLiveAssist {
|
|
|
12804
13907
|
return;
|
|
12805
13908
|
}
|
|
12806
13909
|
this.clearModeUpgradeAttempt(false);
|
|
12807
|
-
this.
|
|
13910
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, true);
|
|
12808
13911
|
this.state("error");
|
|
12809
13912
|
return;
|
|
12810
13913
|
}
|
|
@@ -13036,7 +14139,7 @@ export default class AiLiveAssist {
|
|
|
13036
14139
|
return true;
|
|
13037
14140
|
}
|
|
13038
14141
|
if (outcome.status === "explicit_error" && !outcome.retryable) {
|
|
13039
|
-
this.
|
|
14142
|
+
this.presentSessionError(outcome.message, false);
|
|
13040
14143
|
queueMicrotask(() => this.endFailedModeUpgradeInBackground());
|
|
13041
14144
|
}
|
|
13042
14145
|
return false;
|
|
@@ -13329,7 +14432,7 @@ export default class AiLiveAssist {
|
|
|
13329
14432
|
this.scheduleReconnect(true);
|
|
13330
14433
|
}
|
|
13331
14434
|
else if (outcome.status === "explicit_error") {
|
|
13332
|
-
this.
|
|
14435
|
+
this.presentSessionError(outcome.message, outcome.retryable);
|
|
13333
14436
|
}
|
|
13334
14437
|
return;
|
|
13335
14438
|
}
|
|
@@ -13383,7 +14486,7 @@ export default class AiLiveAssist {
|
|
|
13383
14486
|
this.clearReconnectTimer();
|
|
13384
14487
|
if (this.messengerReturnRetryRemaining !== null) {
|
|
13385
14488
|
if (!this.lastLaunch || this.messengerReturnRetryRemaining <= 0) {
|
|
13386
|
-
this.
|
|
14489
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
13387
14490
|
return;
|
|
13388
14491
|
}
|
|
13389
14492
|
this.messengerReturnRetryRemaining -= 1;
|
|
@@ -13397,7 +14500,7 @@ export default class AiLiveAssist {
|
|
|
13397
14500
|
!this.ended &&
|
|
13398
14501
|
this.messengerReturnRetryRemaining === 0 &&
|
|
13399
14502
|
this.lastLaunch) {
|
|
13400
|
-
this.
|
|
14503
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false, false);
|
|
13401
14504
|
}
|
|
13402
14505
|
});
|
|
13403
14506
|
}
|
|
@@ -13407,10 +14510,21 @@ export default class AiLiveAssist {
|
|
|
13407
14510
|
return this.resume(resume);
|
|
13408
14511
|
}
|
|
13409
14512
|
if (this.lastLaunch) {
|
|
13410
|
-
|
|
14513
|
+
if (this.visitorActiveTakeoverOnly) {
|
|
14514
|
+
// A deliberate retry gets one fresh bounded eligibility check. The
|
|
14515
|
+
// key still prevents accidental automatic replay loops.
|
|
14516
|
+
this.visitorActiveEligibilityRecheckKey = null;
|
|
14517
|
+
}
|
|
14518
|
+
return this.launch(this.lastLaunch.mode, this.lastLaunch.scopes, this.lastLaunch.idempotencyKey, {
|
|
14519
|
+
pendingLaunch: this.lastLaunch,
|
|
14520
|
+
...(this.pendingQuestion
|
|
14521
|
+
? { admittedQuestion: this.pendingQuestion }
|
|
14522
|
+
: {}),
|
|
14523
|
+
});
|
|
13411
14524
|
}
|
|
13412
14525
|
}
|
|
13413
14526
|
scheduleReconnect(force = false) {
|
|
14527
|
+
this.clearCtaAuthority();
|
|
13414
14528
|
if (this.ended ||
|
|
13415
14529
|
this.destroyed ||
|
|
13416
14530
|
this.terminalRequestPending ||
|
|
@@ -13473,7 +14587,7 @@ export default class AiLiveAssist {
|
|
|
13473
14587
|
this.state("ready");
|
|
13474
14588
|
}
|
|
13475
14589
|
else {
|
|
13476
|
-
this.
|
|
14590
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false);
|
|
13477
14591
|
this.state("error");
|
|
13478
14592
|
}
|
|
13479
14593
|
return;
|
|
@@ -13495,7 +14609,7 @@ export default class AiLiveAssist {
|
|
|
13495
14609
|
this.state("reconnecting");
|
|
13496
14610
|
}
|
|
13497
14611
|
else {
|
|
13498
|
-
this.
|
|
14612
|
+
this.presentSessionError(this.view?.message("reconnectFailed"), false);
|
|
13499
14613
|
this.state("error");
|
|
13500
14614
|
}
|
|
13501
14615
|
return;
|
|
@@ -13791,12 +14905,82 @@ export default class AiLiveAssist {
|
|
|
13791
14905
|
beginConnectionAttempt(controller) {
|
|
13792
14906
|
this.connectionAbort?.abort();
|
|
13793
14907
|
this.connectionAbort = controller;
|
|
14908
|
+
// A media-element event from a failed attempt must never cross the next
|
|
14909
|
+
// connection fence. The new attempt will report its own observed state.
|
|
14910
|
+
this.pendingPlaybackState = null;
|
|
13794
14911
|
this.connectionGeneration =
|
|
13795
14912
|
(Number.isSafeInteger(this.connectionGeneration)
|
|
13796
14913
|
? this.connectionGeneration
|
|
13797
14914
|
: 0) + 1;
|
|
13798
14915
|
return this.connectionGeneration;
|
|
13799
14916
|
}
|
|
14917
|
+
savedGuidePendingLaunch() {
|
|
14918
|
+
const intent = this.guideAdmission?.pendingIntent();
|
|
14919
|
+
return intent ? {
|
|
14920
|
+
mode: intent.mode,
|
|
14921
|
+
scopes: [...intent.consent.scopes],
|
|
14922
|
+
idempotencyKey: `launch_${intent.launchRequestId}`,
|
|
14923
|
+
protocolVersion: 2,
|
|
14924
|
+
experienceMode: "standard",
|
|
14925
|
+
} : null;
|
|
14926
|
+
}
|
|
14927
|
+
async requestBootstrap(signal) {
|
|
14928
|
+
if (!this.guideAdmission) {
|
|
14929
|
+
return this.runtime.bootstrap(this.siteKey, path(), this.visitorId(), this.locale, signal);
|
|
14930
|
+
}
|
|
14931
|
+
const bootstrap = await this.guideAdmission.bootstrap(path(), this.locale, signal);
|
|
14932
|
+
// Replay-dependent Messenger continuity is unavailable until the server
|
|
14933
|
+
// validates a real optional recording link. Never borrow another recorder.
|
|
14934
|
+
const safe = { ...bootstrap };
|
|
14935
|
+
if (safe.consent) {
|
|
14936
|
+
safe.consent = { ...safe.consent,
|
|
14937
|
+
requiredScopes: safe.consent.requiredScopes.filter(scope => scope !== "session_recording"),
|
|
14938
|
+
optionalScopes: safe.consent.optionalScopes.filter(scope => scope !== "session_recording" || this.guideAdmission?.recordingConfigured === true),
|
|
14939
|
+
};
|
|
14940
|
+
}
|
|
14941
|
+
delete safe.companion;
|
|
14942
|
+
delete safe.messengerConversation;
|
|
14943
|
+
delete safe.humanHandoffRecovery;
|
|
14944
|
+
if (safe.capabilities)
|
|
14945
|
+
safe.capabilities = { ...safe.capabilities, handoff: false };
|
|
14946
|
+
if (safe.appearance) {
|
|
14947
|
+
safe.appearance = { ...safe.appearance };
|
|
14948
|
+
delete safe.appearance.messengerCompanion;
|
|
14949
|
+
}
|
|
14950
|
+
return safe;
|
|
14951
|
+
}
|
|
14952
|
+
sessionConnectionScope() {
|
|
14953
|
+
return this.guideAdmission
|
|
14954
|
+
? Promise.resolve(this.guideAdmission.connectionScope())
|
|
14955
|
+
: this.replayReadiness.wait();
|
|
14956
|
+
}
|
|
14957
|
+
assertSessionConnectionScope(scope) {
|
|
14958
|
+
if ("kind" in scope && scope.kind === "guide_subject_v2") {
|
|
14959
|
+
scope.assertCurrent();
|
|
14960
|
+
}
|
|
14961
|
+
else {
|
|
14962
|
+
this.replayReadiness.assertCurrent(scope);
|
|
14963
|
+
}
|
|
14964
|
+
}
|
|
14965
|
+
requestLaunch(input, scope, signal) {
|
|
14966
|
+
if (this.guideAdmission) {
|
|
14967
|
+
return this.guideAdmission.launch(input, signal).then((result) => {
|
|
14968
|
+
if (this.bootstrap)
|
|
14969
|
+
this.initializePageAssistancePreference(this.bootstrap);
|
|
14970
|
+
return result;
|
|
14971
|
+
});
|
|
14972
|
+
}
|
|
14973
|
+
return this.runtime.launch({
|
|
14974
|
+
...input,
|
|
14975
|
+
siteKey: this.siteKey,
|
|
14976
|
+
anonymousId: this.visitorId(),
|
|
14977
|
+
replay: scope,
|
|
14978
|
+
}, signal);
|
|
14979
|
+
}
|
|
14980
|
+
matchesLaunchSchema(result, protocolVersion) {
|
|
14981
|
+
return result.schemaVersion === protocolVersion ||
|
|
14982
|
+
(Boolean(this.guideAdmission) && protocolVersion === 2 && result.schemaVersion === 3);
|
|
14983
|
+
}
|
|
13800
14984
|
assertConnectionCurrent(controller, generation, replay, messengerReturnAuthority, mode, launchIdempotencyKey) {
|
|
13801
14985
|
if (controller.signal.aborted ||
|
|
13802
14986
|
this.destroyed ||
|
|
@@ -13808,7 +14992,7 @@ export default class AiLiveAssist {
|
|
|
13808
14992
|
generation !== this.connectionGeneration) {
|
|
13809
14993
|
throw new DOMException("The operation was aborted.", "AbortError");
|
|
13810
14994
|
}
|
|
13811
|
-
this.
|
|
14995
|
+
this.assertSessionConnectionScope(replay);
|
|
13812
14996
|
}
|
|
13813
14997
|
messengerReturnLaunchIsCurrent(authority, mode, launchIdempotencyKey) {
|
|
13814
14998
|
if (!this.messengerTransferred)
|
|
@@ -13922,6 +15106,7 @@ export default class AiLiveAssist {
|
|
|
13922
15106
|
});
|
|
13923
15107
|
}
|
|
13924
15108
|
invalidateConnectionAttempt() {
|
|
15109
|
+
this.pendingPlaybackState = null;
|
|
13925
15110
|
this.connectionGeneration =
|
|
13926
15111
|
(Number.isSafeInteger(this.connectionGeneration)
|
|
13927
15112
|
? this.connectionGeneration
|
|
@@ -14017,6 +15202,10 @@ export default class AiLiveAssist {
|
|
|
14017
15202
|
scopes: [...pending.scopes],
|
|
14018
15203
|
};
|
|
14019
15204
|
}
|
|
15205
|
+
const savedGuideLaunch = this.savedGuidePendingLaunch();
|
|
15206
|
+
if (savedGuideLaunch?.idempotencyKey === intent.launchIdempotencyKey) {
|
|
15207
|
+
this.terminalPendingLaunch = savedGuideLaunch;
|
|
15208
|
+
}
|
|
14020
15209
|
}
|
|
14021
15210
|
if (!this.destroyed) {
|
|
14022
15211
|
this.presentTerminalEnding();
|
|
@@ -14041,6 +15230,12 @@ export default class AiLiveAssist {
|
|
|
14041
15230
|
const request = this.completeRuntimeEnd().finally(() => {
|
|
14042
15231
|
if (this.terminalRequestInFlight === request) {
|
|
14043
15232
|
this.terminalRequestInFlight = null;
|
|
15233
|
+
const intent = this.terminalEndIntent;
|
|
15234
|
+
if (intent &&
|
|
15235
|
+
intent.retryUntil <= Date.now() &&
|
|
15236
|
+
this.terminalRequestPending) {
|
|
15237
|
+
this.presentTerminalRetry();
|
|
15238
|
+
}
|
|
14044
15239
|
}
|
|
14045
15240
|
});
|
|
14046
15241
|
this.terminalRequestInFlight = request;
|
|
@@ -14076,6 +15271,7 @@ export default class AiLiveAssist {
|
|
|
14076
15271
|
finishFromServer(reasonCode, sessionId) {
|
|
14077
15272
|
if (this.ended || this.terminalDeliveryRelinquished)
|
|
14078
15273
|
return;
|
|
15274
|
+
this.guideAdmission?.complete();
|
|
14079
15275
|
this.cancelMessengerTransferForTerminalPresentation();
|
|
14080
15276
|
const returnToTextEntry = this.modeUpgradeReturnToTextEntry || Boolean(this.pendingModeUpgrade);
|
|
14081
15277
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -14127,7 +15323,7 @@ export default class AiLiveAssist {
|
|
|
14127
15323
|
const expectedExperienceMode = sourceRecord?.experienceMode ??
|
|
14128
15324
|
pendingLaunch?.experienceMode ??
|
|
14129
15325
|
result.experienceMode;
|
|
14130
|
-
if (result
|
|
15326
|
+
if (!this.matchesLaunchSchema(result, expectedProtocolVersion) ||
|
|
14131
15327
|
result.protocolVersion !== expectedProtocolVersion ||
|
|
14132
15328
|
result.experienceMode !== expectedExperienceMode ||
|
|
14133
15329
|
(sourceRecord &&
|
|
@@ -14138,6 +15334,8 @@ export default class AiLiveAssist {
|
|
|
14138
15334
|
const currentIntent = this.terminalEndIntent;
|
|
14139
15335
|
if (!currentIntent)
|
|
14140
15336
|
return false;
|
|
15337
|
+
const previousResumeRecord = this.terminalResumeRecord;
|
|
15338
|
+
const previousStoredResume = this.readResume();
|
|
14141
15339
|
const authoritativeExpiry = result.resumeExpiresAt
|
|
14142
15340
|
? Date.parse(result.resumeExpiresAt)
|
|
14143
15341
|
: Date.now() + STORAGE_TTL_MS;
|
|
@@ -14146,16 +15344,39 @@ export default class AiLiveAssist {
|
|
|
14146
15344
|
sessionId: result.sessionId,
|
|
14147
15345
|
retryUntil: Math.min(currentIntent.retryUntil, authoritativeExpiry),
|
|
14148
15346
|
};
|
|
15347
|
+
const rollbackCapture = () => {
|
|
15348
|
+
this.terminalEndIntent = currentIntent;
|
|
15349
|
+
this.terminalResumeRecord = previousResumeRecord;
|
|
15350
|
+
if (canonicalJson(this.readTerminalEndIntent()) === canonicalJson(intent)) {
|
|
15351
|
+
this.persistTerminalEndIntent(currentIntent);
|
|
15352
|
+
const storedResume = this.readResume();
|
|
15353
|
+
if (previousStoredResume &&
|
|
15354
|
+
(!storedResume ||
|
|
15355
|
+
(storedResume.tabId === this.tabId &&
|
|
15356
|
+
storedResume.sessionId === result.sessionId &&
|
|
15357
|
+
storedResume.resumeCredential === result.resumeCredential &&
|
|
15358
|
+
canonicalJson(storedResume.terminalEnd) ===
|
|
15359
|
+
canonicalJson(intent)))) {
|
|
15360
|
+
this.storeResume(previousStoredResume, false);
|
|
15361
|
+
}
|
|
15362
|
+
}
|
|
15363
|
+
return false;
|
|
15364
|
+
};
|
|
14149
15365
|
this.terminalEndIntent = intent;
|
|
14150
|
-
this.persistTerminalEndIntent(intent)
|
|
15366
|
+
if (!this.persistTerminalEndIntent(intent))
|
|
15367
|
+
return rollbackCapture();
|
|
14151
15368
|
const resumedMode = result.mode ?? sourceRecord?.mode ?? this.mode;
|
|
14152
15369
|
const resumedScopes = sourceRecord?.scopes ?? this.scopes;
|
|
14153
15370
|
const stored = this.writeResume(result, resumedMode, resumedScopes, sourceRecord?.visualConsentGranted, sourceRecord?.clientSequence ?? 0, sourceRecord?.modeUpgrade ?? null, sourceRecord?.actionExecution ?? null, sourceRecord?.pauseCommand ?? null, intent);
|
|
14154
|
-
|
|
15371
|
+
if (!stored)
|
|
15372
|
+
return rollbackCapture();
|
|
14155
15373
|
const markedRecord = stored ? this.readResume() : null;
|
|
14156
|
-
if (markedRecord
|
|
14157
|
-
|
|
15374
|
+
if (!markedRecord ||
|
|
15375
|
+
canonicalJson(markedRecord.terminalEnd) !== canonicalJson(intent)) {
|
|
15376
|
+
return rollbackCapture();
|
|
14158
15377
|
}
|
|
15378
|
+
this.result = result;
|
|
15379
|
+
this.terminalResumeRecord = markedRecord;
|
|
14159
15380
|
return true;
|
|
14160
15381
|
}
|
|
14161
15382
|
retryRejectedTerminalAuthorizedResult(result) {
|
|
@@ -14200,6 +15421,13 @@ export default class AiLiveAssist {
|
|
|
14200
15421
|
}
|
|
14201
15422
|
if (this.result)
|
|
14202
15423
|
return this.finishRuntimeEndAttempt(this.result);
|
|
15424
|
+
// Read/end a standalone unknown outcome through its subject-authorized
|
|
15425
|
+
// ledger. A paid launch must never be replayed merely to discover it.
|
|
15426
|
+
if (this.guideAdmission && this.terminalPendingLaunch && !this.terminalResumeRecord) {
|
|
15427
|
+
const controller = new AbortController();
|
|
15428
|
+
const request = this.guideAdmission.endLaunch(this.terminalPendingLaunch.idempotencyKey, this.tabId, controller.signal);
|
|
15429
|
+
return this.settleRuntimeEndRequest(this.waitForTerminalRequestDeadline(request, controller), null);
|
|
15430
|
+
}
|
|
14203
15431
|
const terminalAuthorization = this.terminalSessionAuthorization;
|
|
14204
15432
|
if (terminalAuthorization) {
|
|
14205
15433
|
return this.waitForTerminalRequestDeadline(terminalAuthorization, this.terminalSessionAuthorizationController).then((authorized) => {
|
|
@@ -14311,14 +15539,17 @@ export default class AiLiveAssist {
|
|
|
14311
15539
|
? this.refreshTerminalResumeRecord(result.sessionId)
|
|
14312
15540
|
: null;
|
|
14313
15541
|
if (recoveryRecord) {
|
|
14314
|
-
// Once the live request loses its current revision
|
|
14315
|
-
// terminal recovery is the only authoritative delivery path
|
|
15542
|
+
// Once the live request loses its current revision, credential, or
|
|
15543
|
+
// lease, terminal recovery is the only authoritative delivery path
|
|
15544
|
+
// left.
|
|
14316
15545
|
// Re-sending the same direct request before every recovery probe
|
|
14317
15546
|
// creates duplicate pairs and cannot establish convergence.
|
|
14318
|
-
|
|
14319
|
-
|
|
14320
|
-
|
|
14321
|
-
|
|
15547
|
+
// Any failed direct dispatch is ambiguous: the provider may have
|
|
15548
|
+
// accepted it before the response or control acknowledgement was
|
|
15549
|
+
// lost. From this point forward, use only the idempotent
|
|
15550
|
+
// resume-credential recovery route and never race a second direct
|
|
15551
|
+
// terminal mutation.
|
|
15552
|
+
this.terminalRecoveryOnly = true;
|
|
14322
15553
|
return this.requestRecoveryRuntimeEnd(recoveryRecord).then(() => {
|
|
14323
15554
|
if (!this.ended)
|
|
14324
15555
|
this.finishConfirmedRuntimeEnd(result);
|
|
@@ -14350,6 +15581,7 @@ export default class AiLiveAssist {
|
|
|
14350
15581
|
finishConfirmedRuntimeEnd(result = null) {
|
|
14351
15582
|
if (this.terminalDeliveryRelinquished)
|
|
14352
15583
|
return;
|
|
15584
|
+
this.guideAdmission?.complete();
|
|
14353
15585
|
this.cancelMessengerTransferForTerminalPresentation();
|
|
14354
15586
|
const returnToTextEntry = this.modeUpgradeReturnToTextEntry || Boolean(this.pendingModeUpgrade);
|
|
14355
15587
|
this.modeUpgradeReturnToTextEntry = false;
|
|
@@ -14396,6 +15628,14 @@ export default class AiLiveAssist {
|
|
|
14396
15628
|
? view.message("handoffEnding")
|
|
14397
15629
|
: undefined);
|
|
14398
15630
|
}
|
|
15631
|
+
presentTerminalRetry() {
|
|
15632
|
+
if (this.destroyed || this.ended || this.terminalDeliveryRelinquished) {
|
|
15633
|
+
return;
|
|
15634
|
+
}
|
|
15635
|
+
this.cleanupTransport();
|
|
15636
|
+
this.view?.showEndRetry();
|
|
15637
|
+
this.state("error");
|
|
15638
|
+
}
|
|
14399
15639
|
retryTerminalEnd(error) {
|
|
14400
15640
|
if (this.ended)
|
|
14401
15641
|
return Promise.resolve();
|
|
@@ -14469,7 +15709,7 @@ export default class AiLiveAssist {
|
|
|
14469
15709
|
const current = this.bootstrap;
|
|
14470
15710
|
if (current?.configRevision && current.consent)
|
|
14471
15711
|
return current;
|
|
14472
|
-
const bootstrap = await this.
|
|
15712
|
+
const bootstrap = await this.requestBootstrap(signal);
|
|
14473
15713
|
if (!bootstrap.configRevision || !bootstrap.consent) {
|
|
14474
15714
|
throw new RuntimeClientError("INTERNAL_UNAVAILABLE", "Terminal launch recovery metadata is temporarily unavailable.", true, null, 503);
|
|
14475
15715
|
}
|
|
@@ -14520,7 +15760,7 @@ export default class AiLiveAssist {
|
|
|
14520
15760
|
!this.terminalRequestPending ||
|
|
14521
15761
|
this.terminalEndIntent?.operationId !== intent.operationId ||
|
|
14522
15762
|
intent.retryUntil > Date.now()) {
|
|
14523
|
-
return;
|
|
15763
|
+
return false;
|
|
14524
15764
|
}
|
|
14525
15765
|
this.terminalInitializationDeferred = false;
|
|
14526
15766
|
const clearsAssociatedStorage = this.clearExpiredTerminalRecoveryStorage(intent);
|
|
@@ -14547,6 +15787,7 @@ export default class AiLiveAssist {
|
|
|
14547
15787
|
}
|
|
14548
15788
|
void this.initialize();
|
|
14549
15789
|
});
|
|
15790
|
+
return true;
|
|
14550
15791
|
}
|
|
14551
15792
|
waitForTerminalRetry(error) {
|
|
14552
15793
|
this.terminalRetryAttempts += 1;
|
|
@@ -14586,6 +15827,7 @@ export default class AiLiveAssist {
|
|
|
14586
15827
|
});
|
|
14587
15828
|
}
|
|
14588
15829
|
quiesceLocalEffectsForTerminalRequest() {
|
|
15830
|
+
this.clearCtaAuthority();
|
|
14589
15831
|
this.queuedLaunchToken = null;
|
|
14590
15832
|
this.launchGeneration += 1;
|
|
14591
15833
|
this.visitorLimitAbort?.abort();
|
|
@@ -14651,6 +15893,10 @@ export default class AiLiveAssist {
|
|
|
14651
15893
|
this.messengerOpenAckInFlight = null;
|
|
14652
15894
|
}
|
|
14653
15895
|
cleanupTransport(options = {}) {
|
|
15896
|
+
this.voicePlaybackInterruptBarrier = null;
|
|
15897
|
+
this.voicePlaybackAdmissionAfterSequence = 0;
|
|
15898
|
+
this.invalidateVoicePlaybackRearm();
|
|
15899
|
+
this.clearCtaAuthority();
|
|
14654
15900
|
this.sessionEffectGeneration =
|
|
14655
15901
|
(Number.isSafeInteger(this.sessionEffectGeneration)
|
|
14656
15902
|
? this.sessionEffectGeneration
|
|
@@ -14718,10 +15964,10 @@ export default class AiLiveAssist {
|
|
|
14718
15964
|
}
|
|
14719
15965
|
let terminalOutcome;
|
|
14720
15966
|
try {
|
|
14721
|
-
terminalOutcome = controlChannel.waitForOutcome(terminalMessageId,
|
|
15967
|
+
terminalOutcome = controlChannel.waitForOutcome(terminalMessageId, 5000, terminalClientSequence);
|
|
14722
15968
|
}
|
|
14723
15969
|
catch {
|
|
14724
|
-
return
|
|
15970
|
+
return Promise.reject(new TerminalControlEndUnconfirmedError());
|
|
14725
15971
|
}
|
|
14726
15972
|
return terminalOutcome.then((outcome) => {
|
|
14727
15973
|
if (outcome.status !== "ack" ||
|
|
@@ -14729,9 +15975,9 @@ export default class AiLiveAssist {
|
|
|
14729
15975
|
outcome.sequence !== terminalClientSequence ||
|
|
14730
15976
|
this.channel !== controlChannel ||
|
|
14731
15977
|
controlChannel.leaseToken !== fencingToken) {
|
|
14732
|
-
|
|
15978
|
+
throw new TerminalControlEndUnconfirmedError();
|
|
14733
15979
|
}
|
|
14734
|
-
}, () =>
|
|
15980
|
+
}, () => Promise.reject(new TerminalControlEndUnconfirmedError()));
|
|
14735
15981
|
}
|
|
14736
15982
|
requestRecoveryRuntimeEnd(record) {
|
|
14737
15983
|
const controller = new AbortController();
|
|
@@ -14749,6 +15995,9 @@ export default class AiLiveAssist {
|
|
|
14749
15995
|
});
|
|
14750
15996
|
}
|
|
14751
15997
|
send(type, payload, stableMessageId) {
|
|
15998
|
+
if (this.manualPushRequest && ["session.interrupt", "session.mode", "voice.turn_mode", "session.pause", "session.end", "experience.end"].includes(type)) {
|
|
15999
|
+
this.stopManualPushToTalk(false);
|
|
16000
|
+
}
|
|
14752
16001
|
if (this.terminalRequestPending && type !== "experience.end")
|
|
14753
16002
|
return null;
|
|
14754
16003
|
if (!this.channel?.isOpen)
|
|
@@ -14801,19 +16050,21 @@ export default class AiLiveAssist {
|
|
|
14801
16050
|
return;
|
|
14802
16051
|
}
|
|
14803
16052
|
const ready = (async () => {
|
|
14804
|
-
const visitorDigest = await digestPageAssistanceVisitor(this.
|
|
16053
|
+
const visitorDigest = await digestPageAssistanceVisitor(this.visitorId());
|
|
14805
16054
|
if (!visitorDigest)
|
|
14806
16055
|
return null;
|
|
14807
16056
|
try {
|
|
14808
16057
|
return new PageAssistancePreferenceStore({
|
|
14809
16058
|
origin,
|
|
14810
|
-
|
|
16059
|
+
...(this.guideAdmission
|
|
16060
|
+
? { projectId: this.guideAdmission.identity.projectId, guideId: this.guideAdmission.identity.guideId }
|
|
16061
|
+
: { siteKey: this.siteKey }),
|
|
14811
16062
|
visitorDigest,
|
|
14812
16063
|
schemaVersion: 1,
|
|
14813
16064
|
configRevision: configRevision,
|
|
14814
16065
|
policyVersion: policyVersion,
|
|
14815
16066
|
capability: "browser_control",
|
|
14816
|
-
});
|
|
16067
|
+
}, { storageNamespace: this.storageNamespace });
|
|
14817
16068
|
}
|
|
14818
16069
|
catch {
|
|
14819
16070
|
return null;
|
|
@@ -14876,12 +16127,14 @@ export default class AiLiveAssist {
|
|
|
14876
16127
|
void this.flushPendingPageAssistanceRevocation();
|
|
14877
16128
|
}
|
|
14878
16129
|
visitorId() {
|
|
14879
|
-
return this.visitorIdentity;
|
|
16130
|
+
return this.guideAdmission ? this.guideAdmission.subjectId() ?? "" : this.visitorIdentity;
|
|
14880
16131
|
}
|
|
14881
16132
|
currentTrackerVisitorIdentity() {
|
|
16133
|
+
if (this.guideAdmission)
|
|
16134
|
+
return null;
|
|
14882
16135
|
try {
|
|
14883
|
-
const
|
|
14884
|
-
const trackerId = typeof
|
|
16136
|
+
const identity = this.host.getVisitorId();
|
|
16137
|
+
const trackerId = typeof identity === "string" ? identity : "";
|
|
14885
16138
|
return PUBLIC_REQUEST_ID_PATTERN.test(trackerId) ? trackerId : null;
|
|
14886
16139
|
}
|
|
14887
16140
|
catch {
|
|
@@ -14960,7 +16213,7 @@ export default class AiLiveAssist {
|
|
|
14960
16213
|
this.pageAssistanceTrackerRotationPending = false;
|
|
14961
16214
|
}
|
|
14962
16215
|
resolveVisitorId() {
|
|
14963
|
-
const key = `__oxvo_ai_live_assist_visitor_${this.siteKey}`;
|
|
16216
|
+
const key = `__oxvo_ai_live_assist_visitor_${this.storageNamespace ?? this.siteKey}`;
|
|
14964
16217
|
try {
|
|
14965
16218
|
const stored = localStorage.getItem(key) ?? "";
|
|
14966
16219
|
if (PUBLIC_REQUEST_ID_PATTERN.test(stored))
|
|
@@ -14979,6 +16232,138 @@ export default class AiLiveAssist {
|
|
|
14979
16232
|
return resolved;
|
|
14980
16233
|
}
|
|
14981
16234
|
}
|
|
16235
|
+
observeCtaAssistantTurn(id) {
|
|
16236
|
+
this.ctaAssistantTurns ?? (this.ctaAssistantTurns = new Set());
|
|
16237
|
+
this.ctaAssistantTurns.add(id);
|
|
16238
|
+
while (this.ctaAssistantTurns.size > 40) {
|
|
16239
|
+
this.ctaAssistantTurns.delete(this.ctaAssistantTurns.values().next().value);
|
|
16240
|
+
}
|
|
16241
|
+
this.renderCurrentCtaOffer();
|
|
16242
|
+
}
|
|
16243
|
+
renderCurrentCtaOffer() {
|
|
16244
|
+
const offer = this.ctaOffer;
|
|
16245
|
+
if (offer &&
|
|
16246
|
+
this.ctaAssistantTurns?.has(offer.sourceTurnId) &&
|
|
16247
|
+
offer.configRevision === this.bootstrap?.configRevision &&
|
|
16248
|
+
!this.terminalRequestPending &&
|
|
16249
|
+
!this.ended &&
|
|
16250
|
+
!this.destroyed &&
|
|
16251
|
+
!this.messengerTransferred &&
|
|
16252
|
+
!this.messengerTransferPending &&
|
|
16253
|
+
this.channel?.hasFencedAuthority &&
|
|
16254
|
+
Date.parse(offer.expiresAt) > Date.now()) {
|
|
16255
|
+
if (!this.view)
|
|
16256
|
+
return;
|
|
16257
|
+
this.ctaAnnouncedOffers ?? (this.ctaAnnouncedOffers = new Set());
|
|
16258
|
+
const announce = !this.ctaAnnouncedOffers.has(offer.offerId) &&
|
|
16259
|
+
this.ctaAnnouncedOffers.size < 16;
|
|
16260
|
+
if (announce)
|
|
16261
|
+
this.ctaAnnouncedOffers.add(offer.offerId);
|
|
16262
|
+
this.view.showCtaOffer(offer, { announce });
|
|
16263
|
+
}
|
|
16264
|
+
}
|
|
16265
|
+
resolveCtaOffer(result) {
|
|
16266
|
+
const offer = this.ctaOffer;
|
|
16267
|
+
const channel = this.channel;
|
|
16268
|
+
if (!offer ||
|
|
16269
|
+
result.offerId !== offer.offerId ||
|
|
16270
|
+
(this.ctaTerminalOffers ?? (this.ctaTerminalOffers = new Set())).has(offer.offerId) ||
|
|
16271
|
+
!channel?.hasFencedAuthority ||
|
|
16272
|
+
this.terminalRequestPending ||
|
|
16273
|
+
this.ended ||
|
|
16274
|
+
this.destroyed ||
|
|
16275
|
+
this.messengerTransferred ||
|
|
16276
|
+
this.messengerTransferPending ||
|
|
16277
|
+
offer.configRevision !== this.bootstrap?.configRevision ||
|
|
16278
|
+
Date.parse(offer.expiresAt) <= Date.now())
|
|
16279
|
+
return false;
|
|
16280
|
+
this.ctaTerminalOffers.add(offer.offerId);
|
|
16281
|
+
if (result.outcome === "clicked")
|
|
16282
|
+
this.ctaClicked = true;
|
|
16283
|
+
const generation = this.sessionEffectGeneration;
|
|
16284
|
+
const ctaGeneration = this.currentCtaAuthorityGeneration();
|
|
16285
|
+
const messageId = randomId("cta_result");
|
|
16286
|
+
let attempts = 0;
|
|
16287
|
+
const send = () => {
|
|
16288
|
+
if (generation !== this.sessionEffectGeneration ||
|
|
16289
|
+
ctaGeneration !== this.currentCtaAuthorityGeneration() ||
|
|
16290
|
+
this.channel !== channel ||
|
|
16291
|
+
this.terminalRequestPending ||
|
|
16292
|
+
this.ended ||
|
|
16293
|
+
this.destroyed ||
|
|
16294
|
+
!channel.hasFencedAuthority ||
|
|
16295
|
+
Date.parse(offer.expiresAt) <= Date.now())
|
|
16296
|
+
return;
|
|
16297
|
+
attempts += 1;
|
|
16298
|
+
void this.sendControlOutcome("cta.result", result, messageId, 2500)
|
|
16299
|
+
.then((outcome) => {
|
|
16300
|
+
if (generation !== this.sessionEffectGeneration ||
|
|
16301
|
+
ctaGeneration !== this.currentCtaAuthorityGeneration() ||
|
|
16302
|
+
this.channel !== channel)
|
|
16303
|
+
return;
|
|
16304
|
+
if (outcome?.status === "ack" ||
|
|
16305
|
+
outcome?.status === "explicit_error" ||
|
|
16306
|
+
attempts >= 3)
|
|
16307
|
+
return;
|
|
16308
|
+
this.ctaResultRetryTimer = setTimeout(send, 500);
|
|
16309
|
+
})
|
|
16310
|
+
.catch(() => undefined);
|
|
16311
|
+
};
|
|
16312
|
+
send();
|
|
16313
|
+
// Keep the anchor intact through native activation, independent of ACK delivery.
|
|
16314
|
+
queueMicrotask(() => {
|
|
16315
|
+
if (this.ctaOffer === offer)
|
|
16316
|
+
this.clearCurrentCtaOffer();
|
|
16317
|
+
});
|
|
16318
|
+
return true;
|
|
16319
|
+
}
|
|
16320
|
+
clearCurrentCtaOffer() {
|
|
16321
|
+
if (this.ctaExpiryTimer)
|
|
16322
|
+
clearTimeout(this.ctaExpiryTimer);
|
|
16323
|
+
this.ctaExpiryTimer = null;
|
|
16324
|
+
this.ctaOffer = null;
|
|
16325
|
+
this.view?.clearCtaOffer?.();
|
|
16326
|
+
}
|
|
16327
|
+
clearCtaAuthority() {
|
|
16328
|
+
this.clearCtaOfferAuthority();
|
|
16329
|
+
this.ctaContentGeneration = (this.ctaContentGeneration ?? 0) + 1;
|
|
16330
|
+
this.ctaAssistantTurns?.clear();
|
|
16331
|
+
}
|
|
16332
|
+
clearCtaOfferAuthority() {
|
|
16333
|
+
this.ctaAuthorityGeneration = this.currentCtaAuthorityGeneration() + 1;
|
|
16334
|
+
this.clearCurrentCtaOffer();
|
|
16335
|
+
if (this.ctaResultRetryTimer)
|
|
16336
|
+
clearTimeout(this.ctaResultRetryTimer);
|
|
16337
|
+
this.ctaResultRetryTimer = null;
|
|
16338
|
+
this.ctaSeenOffers?.clear();
|
|
16339
|
+
}
|
|
16340
|
+
ctaContentIsCurrent(message) {
|
|
16341
|
+
const captured = this.ctaContentAtIngress?.get(message);
|
|
16342
|
+
return (message.sessionId === this.result?.sessionId &&
|
|
16343
|
+
(!captured ||
|
|
16344
|
+
(captured.generation === (this.ctaContentGeneration ?? 0) &&
|
|
16345
|
+
captured.channel === this.channel)));
|
|
16346
|
+
}
|
|
16347
|
+
currentCtaAuthorityGeneration() {
|
|
16348
|
+
return Number.isSafeInteger(this.ctaAuthorityGeneration)
|
|
16349
|
+
? this.ctaAuthorityGeneration
|
|
16350
|
+
: 0;
|
|
16351
|
+
}
|
|
16352
|
+
ctaEnvelopeIsCurrent(message) {
|
|
16353
|
+
return ((this.ctaAuthorityGenerationAtIngress?.get(message) ??
|
|
16354
|
+
this.currentCtaAuthorityGeneration()) ===
|
|
16355
|
+
this.currentCtaAuthorityGeneration());
|
|
16356
|
+
}
|
|
16357
|
+
invalidateCtaAuthority() {
|
|
16358
|
+
if (this.ctaOffer && (this.ctaTerminalOffers ?? (this.ctaTerminalOffers = new Set())).size < 16) {
|
|
16359
|
+
this.ctaTerminalOffers.add(this.ctaOffer.offerId);
|
|
16360
|
+
}
|
|
16361
|
+
// Caption content is not permission: a navigation consent reset can follow
|
|
16362
|
+
// its replayed captions. Keep that bounded current-transport evidence, while
|
|
16363
|
+
// terminalizing this offer and fencing every older queued CTA. Transport or
|
|
16364
|
+
// session cleanup still clears the content generation in clearCtaAuthority.
|
|
16365
|
+
this.clearCtaOfferAuthority();
|
|
16366
|
+
}
|
|
14982
16367
|
readTranscript() {
|
|
14983
16368
|
try {
|
|
14984
16369
|
return parseTranscript(JSON.parse(sessionStorage.getItem(this.transcriptStorageKey) ?? "[]"));
|
|
@@ -15042,7 +16427,10 @@ export default class AiLiveAssist {
|
|
|
15042
16427
|
for (const entry of this.transcript) {
|
|
15043
16428
|
if (this.renderedTranscriptIds.has(entry.id))
|
|
15044
16429
|
continue;
|
|
15045
|
-
view.addCaption(entry.role, entry.text, true, {
|
|
16430
|
+
view.addCaption(entry.role, entry.text, true, {
|
|
16431
|
+
restored: true,
|
|
16432
|
+
sourceTurnId: entry.id,
|
|
16433
|
+
});
|
|
15046
16434
|
this.renderedTranscriptIds.add(entry.id);
|
|
15047
16435
|
}
|
|
15048
16436
|
}
|
|
@@ -15787,6 +17175,91 @@ export default class AiLiveAssist {
|
|
|
15787
17175
|
launchIdempotencyKey,
|
|
15788
17176
|
};
|
|
15789
17177
|
}
|
|
17178
|
+
renewExpiredTerminalEndIntent() {
|
|
17179
|
+
const intent = this.terminalEndIntent;
|
|
17180
|
+
const now = Date.now();
|
|
17181
|
+
if (!intent || intent.retryUntil > now)
|
|
17182
|
+
return true;
|
|
17183
|
+
const currentRecord = this.terminalResumeRecord;
|
|
17184
|
+
const retainedRecord = currentRecord?.terminalEnd?.operationId === intent.operationId &&
|
|
17185
|
+
currentRecord.sessionId === intent.sessionId
|
|
17186
|
+
? currentRecord
|
|
17187
|
+
: null;
|
|
17188
|
+
if (!retainedRecord ||
|
|
17189
|
+
!this.storedTerminalRetryAuthorityMatches(intent, retainedRecord)) {
|
|
17190
|
+
return false;
|
|
17191
|
+
}
|
|
17192
|
+
const retainedResult = [this.result, this.modeUpgradeTerminalResult].find((candidate) => candidate?.sessionId === intent.sessionId);
|
|
17193
|
+
const resultExpiry = retainedResult
|
|
17194
|
+
? Date.parse(retainedResult.resumeExpiresAt ?? retainedResult.expiresAt)
|
|
17195
|
+
: 0;
|
|
17196
|
+
const authorityExpiry = Math.max(retainedRecord?.expiresAt ?? 0, Number.isFinite(resultExpiry) ? resultExpiry : 0);
|
|
17197
|
+
const retryUntil = Math.min(now + TERMINAL_REQUEST_RETRY_HORIZON_MS, authorityExpiry);
|
|
17198
|
+
if (retryUntil <= now)
|
|
17199
|
+
return false;
|
|
17200
|
+
const renewed = {
|
|
17201
|
+
...intent,
|
|
17202
|
+
requestedAt: now,
|
|
17203
|
+
retryUntil,
|
|
17204
|
+
};
|
|
17205
|
+
const previousRetryAttempts = this.terminalRetryAttempts;
|
|
17206
|
+
this.terminalEndIntent = renewed;
|
|
17207
|
+
if (retainedResult) {
|
|
17208
|
+
if (!this.captureTerminalAuthorizedResult(retainedResult, retainedRecord)) {
|
|
17209
|
+
this.rollbackFailedTerminalEndRenewal(intent, retainedRecord, renewed, previousRetryAttempts);
|
|
17210
|
+
return false;
|
|
17211
|
+
}
|
|
17212
|
+
this.terminalRetryAttempts = 0;
|
|
17213
|
+
return true;
|
|
17214
|
+
}
|
|
17215
|
+
if (!this.storeTerminalResume(retainedRecord, renewed)) {
|
|
17216
|
+
this.rollbackFailedTerminalEndRenewal(intent, retainedRecord, renewed, previousRetryAttempts);
|
|
17217
|
+
return false;
|
|
17218
|
+
}
|
|
17219
|
+
this.terminalRetryAttempts = 0;
|
|
17220
|
+
return true;
|
|
17221
|
+
}
|
|
17222
|
+
rollbackFailedTerminalEndRenewal(previousIntent, previousRecord, attemptedIntent, previousRetryAttempts) {
|
|
17223
|
+
const persistedIntent = this.readTerminalEndIntent();
|
|
17224
|
+
if (persistedIntent?.operationId === attemptedIntent.operationId &&
|
|
17225
|
+
persistedIntent.sessionId === attemptedIntent.sessionId &&
|
|
17226
|
+
persistedIntent.requestedAt === attemptedIntent.requestedAt) {
|
|
17227
|
+
const persistedRecord = this.readResume();
|
|
17228
|
+
const failedResumeIsOwned = Boolean(!persistedRecord ||
|
|
17229
|
+
(persistedRecord.tabId === this.tabId &&
|
|
17230
|
+
persistedRecord.sessionId === previousRecord.sessionId &&
|
|
17231
|
+
persistedRecord.terminalEnd?.operationId ===
|
|
17232
|
+
attemptedIntent.operationId &&
|
|
17233
|
+
persistedRecord.terminalEnd.requestedAt ===
|
|
17234
|
+
attemptedIntent.requestedAt));
|
|
17235
|
+
if (this.persistTerminalEndIntent(previousIntent) &&
|
|
17236
|
+
failedResumeIsOwned) {
|
|
17237
|
+
this.storeResume(previousRecord, false);
|
|
17238
|
+
}
|
|
17239
|
+
}
|
|
17240
|
+
this.terminalEndIntent = previousIntent;
|
|
17241
|
+
this.terminalResumeRecord = previousRecord;
|
|
17242
|
+
this.terminalRetryAttempts = previousRetryAttempts;
|
|
17243
|
+
}
|
|
17244
|
+
storedTerminalRetryAuthorityMatches(intent, record) {
|
|
17245
|
+
try {
|
|
17246
|
+
const terminalSerialized = localStorage.getItem(this.terminalEndStorageKey);
|
|
17247
|
+
const resumeSerialized = sessionStorage.getItem(this.storageKey);
|
|
17248
|
+
if (!terminalSerialized || !resumeSerialized)
|
|
17249
|
+
return false;
|
|
17250
|
+
if (canonicalJson(JSON.parse(terminalSerialized)) !==
|
|
17251
|
+
canonicalJson(intent) ||
|
|
17252
|
+
canonicalJson(JSON.parse(resumeSerialized)) !== canonicalJson(record)) {
|
|
17253
|
+
return false;
|
|
17254
|
+
}
|
|
17255
|
+
return (localStorage.getItem(this.terminalEndStorageKey) ===
|
|
17256
|
+
terminalSerialized &&
|
|
17257
|
+
sessionStorage.getItem(this.storageKey) === resumeSerialized);
|
|
17258
|
+
}
|
|
17259
|
+
catch {
|
|
17260
|
+
return false;
|
|
17261
|
+
}
|
|
17262
|
+
}
|
|
15790
17263
|
terminalIntentMatchesAuthority(intent, record) {
|
|
15791
17264
|
const sessionId = this.result?.sessionId ??
|
|
15792
17265
|
this.modeUpgradeTerminalResult?.sessionId ??
|
|
@@ -16084,7 +17557,7 @@ export default class AiLiveAssist {
|
|
|
16084
17557
|
if (record?.terminalEnd?.operationId === intent.operationId ||
|
|
16085
17558
|
(intent.sessionId === null &&
|
|
16086
17559
|
intent.launchIdempotencyKey ===
|
|
16087
|
-
this.readStagedPendingLaunch()?.pendingLaunch.idempotencyKey)) {
|
|
17560
|
+
(this.savedGuidePendingLaunch()?.idempotencyKey ?? this.readStagedPendingLaunch()?.pendingLaunch.idempotencyKey))) {
|
|
16088
17561
|
return this.restoreTerminalEnd(intent, record?.terminalEnd?.operationId === intent.operationId ? record : null);
|
|
16089
17562
|
}
|
|
16090
17563
|
return this.terminalRequestPending;
|