@oxvo/ai-live-assist 7.4.50 → 7.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/cjs/AiLiveAssist.d.ts +76 -11
- package/cjs/AiLiveAssist.js +1771 -298
- package/cjs/client.d.ts +19 -0
- package/cjs/client.js +51 -0
- package/cjs/context.d.ts +23 -1
- package/cjs/context.js +713 -126
- package/cjs/control.d.ts +2 -0
- package/cjs/control.js +42 -3
- package/cjs/ctaOffer.d.ts +11 -0
- package/cjs/ctaOffer.js +185 -0
- package/cjs/dialogFocusScope.js +1 -1
- package/cjs/guideAdmission.d.ts +46 -0
- package/cjs/guideAdmission.js +397 -0
- package/cjs/guideHost.d.ts +47 -0
- package/cjs/guideHost.js +48 -0
- package/cjs/guideInstallation.d.ts +12 -0
- package/cjs/guideInstallation.js +60 -0
- package/cjs/guideInstaller.d.ts +4 -0
- package/cjs/guideInstaller.js +116 -0
- package/cjs/guideMount.d.ts +22 -0
- package/cjs/guideMount.js +84 -0
- package/cjs/guideRecording.d.ts +64 -0
- package/cjs/guideRecording.js +176 -0
- package/cjs/guideRecordingSession.d.ts +35 -0
- package/cjs/guideRecordingSession.js +167 -0
- package/cjs/guideSubjectStore.d.ts +32 -0
- package/cjs/guideSubjectStore.js +105 -0
- package/cjs/guideTypes.d.ts +117 -0
- package/cjs/guideTypes.js +15 -0
- package/cjs/index.d.ts +6 -0
- package/cjs/index.js +25 -11
- package/cjs/liveAudioProcessor.d.ts +92 -0
- package/cjs/liveAudioProcessor.js +269 -0
- package/cjs/liveAudioQueue.d.ts +40 -0
- package/cjs/liveAudioQueue.js +130 -0
- package/cjs/liveAudioWorklet.d.ts +1 -0
- package/cjs/liveAudioWorklet.js +63 -0
- package/cjs/liveBrowserDetector.d.ts +16 -0
- package/cjs/liveBrowserDetector.js +75 -0
- package/cjs/liveBrowserDetectorWorker.d.ts +1 -0
- package/cjs/liveBrowserDetectorWorker.js +72 -0
- package/cjs/liveControlChannel.d.ts +176 -0
- package/cjs/liveControlChannel.js +829 -0
- package/cjs/liveDuplexMedia.d.ts +204 -0
- package/cjs/liveDuplexMedia.js +740 -0
- package/cjs/liveGuideAdmission.d.ts +21 -0
- package/cjs/liveGuideAdmission.js +94 -0
- package/cjs/liveGuideWidget.d.ts +68 -0
- package/cjs/liveGuideWidget.js +451 -0
- package/cjs/liveSpeechAssets.d.ts +36 -0
- package/cjs/liveSpeechAssets.js +39 -0
- package/cjs/liveSpeechCaptureBridge.d.ts +32 -0
- package/cjs/liveSpeechCaptureBridge.js +140 -0
- package/cjs/liveSpeechDetector.d.ts +62 -0
- package/cjs/liveSpeechDetector.js +206 -0
- package/cjs/liveSpeechModel.d.ts +46 -0
- package/cjs/liveSpeechModel.js +105 -0
- package/cjs/liveSpeechResampler.d.ts +22 -0
- package/cjs/liveSpeechResampler.js +93 -0
- package/cjs/liveSpeechWorker.d.ts +56 -0
- package/cjs/liveSpeechWorker.js +143 -0
- package/cjs/locales/resources.js +568 -8
- package/cjs/media.d.ts +11 -0
- package/cjs/media.js +78 -9
- package/cjs/messages.js +22 -8
- package/cjs/pageAssistancePreference.d.ts +15 -3
- package/cjs/pageAssistancePreference.js +46 -7
- package/cjs/preview.d.ts +4 -1
- package/cjs/preview.js +42 -1
- package/cjs/recording.d.ts +12 -0
- package/cjs/recording.js +150 -0
- package/cjs/standalone.d.ts +6 -0
- package/cjs/standalone.js +12 -0
- package/cjs/types.d.ts +31 -5
- package/cjs/types.js +14 -0
- package/cjs/ui.d.ts +128 -4
- package/cjs/ui.js +1918 -276
- package/cjs/version.d.ts +1 -1
- package/cjs/version.js +1 -1
- package/cjs/voicePresenceUi.d.ts +52 -4
- package/cjs/voicePresenceUi.js +659 -57
- package/lib/AiLiveAssist.d.ts +76 -11
- package/lib/AiLiveAssist.js +1772 -299
- package/lib/client.d.ts +19 -0
- package/lib/client.js +51 -0
- package/lib/context.d.ts +23 -1
- package/lib/context.js +713 -126
- package/lib/control.d.ts +2 -0
- package/lib/control.js +42 -3
- package/lib/ctaOffer.d.ts +11 -0
- package/lib/ctaOffer.js +179 -0
- package/lib/dialogFocusScope.js +1 -1
- package/lib/guideAdmission.d.ts +46 -0
- package/lib/guideAdmission.js +392 -0
- package/lib/guideHost.d.ts +47 -0
- package/lib/guideHost.js +42 -0
- package/lib/guideInstallation.d.ts +12 -0
- package/lib/guideInstallation.js +56 -0
- package/lib/guideInstaller.d.ts +4 -0
- package/lib/guideInstaller.js +113 -0
- package/lib/guideMount.d.ts +22 -0
- package/lib/guideMount.js +77 -0
- package/lib/guideRecording.d.ts +64 -0
- package/lib/guideRecording.js +172 -0
- package/lib/guideRecordingSession.d.ts +35 -0
- package/lib/guideRecordingSession.js +163 -0
- package/lib/guideSubjectStore.d.ts +32 -0
- package/lib/guideSubjectStore.js +101 -0
- package/lib/guideTypes.d.ts +117 -0
- package/lib/guideTypes.js +11 -0
- package/lib/index.d.ts +6 -0
- package/lib/index.js +21 -10
- package/lib/liveAudioProcessor.d.ts +92 -0
- package/lib/liveAudioProcessor.js +265 -0
- package/lib/liveAudioQueue.d.ts +40 -0
- package/lib/liveAudioQueue.js +126 -0
- package/lib/liveAudioWorklet.d.ts +1 -0
- package/lib/liveAudioWorklet.js +61 -0
- package/lib/liveBrowserDetector.d.ts +16 -0
- package/lib/liveBrowserDetector.js +71 -0
- package/lib/liveBrowserDetectorWorker.d.ts +1 -0
- package/lib/liveBrowserDetectorWorker.js +70 -0
- package/lib/liveControlChannel.d.ts +176 -0
- package/lib/liveControlChannel.js +825 -0
- package/lib/liveDuplexMedia.d.ts +204 -0
- package/lib/liveDuplexMedia.js +736 -0
- package/lib/liveGuideAdmission.d.ts +21 -0
- package/lib/liveGuideAdmission.js +90 -0
- package/lib/liveGuideWidget.d.ts +68 -0
- package/lib/liveGuideWidget.js +447 -0
- package/lib/liveSpeechAssets.d.ts +36 -0
- package/lib/liveSpeechAssets.js +35 -0
- package/lib/liveSpeechCaptureBridge.d.ts +32 -0
- package/lib/liveSpeechCaptureBridge.js +136 -0
- package/lib/liveSpeechDetector.d.ts +62 -0
- package/lib/liveSpeechDetector.js +202 -0
- package/lib/liveSpeechModel.d.ts +46 -0
- package/lib/liveSpeechModel.js +101 -0
- package/lib/liveSpeechResampler.d.ts +22 -0
- package/lib/liveSpeechResampler.js +89 -0
- package/lib/liveSpeechWorker.d.ts +56 -0
- package/lib/liveSpeechWorker.js +137 -0
- package/lib/locales/resources.js +568 -8
- package/lib/media.d.ts +11 -0
- package/lib/media.js +77 -8
- package/lib/messages.js +22 -8
- package/lib/pageAssistancePreference.d.ts +15 -3
- package/lib/pageAssistancePreference.js +46 -7
- package/lib/preview.d.ts +4 -1
- package/lib/preview.js +42 -1
- package/lib/recording.d.ts +12 -0
- package/lib/recording.js +146 -0
- package/lib/standalone.d.ts +6 -0
- package/lib/standalone.js +6 -0
- package/lib/types.d.ts +31 -5
- package/lib/types.js +14 -0
- package/lib/ui.d.ts +128 -4
- package/lib/ui.js +1919 -277
- package/lib/version.d.ts +1 -1
- package/lib/version.js +1 -1
- package/lib/voicePresenceUi.d.ts +52 -4
- package/lib/voicePresenceUi.js +659 -57
- package/package.json +16 -1
package/cjs/control.d.ts
CHANGED
|
@@ -45,6 +45,7 @@ export declare class ControlChannel {
|
|
|
45
45
|
private pendingOutcomes;
|
|
46
46
|
private recentOutcomes;
|
|
47
47
|
private outboundOperations;
|
|
48
|
+
private outstandingControlFrames;
|
|
48
49
|
private latestOutboundSequence;
|
|
49
50
|
private unsettledStatefulOperations;
|
|
50
51
|
private socketGeneration;
|
|
@@ -66,6 +67,7 @@ export declare class ControlChannel {
|
|
|
66
67
|
send(type: string, payload: Record<string, unknown>, stableMessageId?: string): string;
|
|
67
68
|
reserveOperationIdentity(type: string, stableMessageId?: string): ReservedControlOperation;
|
|
68
69
|
sendReserved(operation: ReservedControlOperation, payload: Record<string, unknown>): string;
|
|
70
|
+
retransmitOutstanding(messageId: string, expectedSequence: number): boolean;
|
|
69
71
|
outboundOperation(messageId: string, sequence?: number): ControlOutboundOperation | null;
|
|
70
72
|
waitForOutcome(messageId: string, timeoutMs?: number, expectedSequence?: number): Promise<ControlDeliveryOutcome>;
|
|
71
73
|
waitForAck(messageId: string, timeoutMs?: number): Promise<boolean>;
|
package/cjs/control.js
CHANGED
|
@@ -11,6 +11,7 @@ const MAX_PENDING_STATEFUL_OPERATIONS = 64;
|
|
|
11
11
|
const MAX_SETTLED_OPERATION_HISTORY = 100;
|
|
12
12
|
const CLIENT_MESSAGE_ID_PATTERN = /^[A-Za-z0-9_.:-]{8,128}$/;
|
|
13
13
|
const STATEFUL_CONTROL_TYPES = new Set([
|
|
14
|
+
"cta.result",
|
|
14
15
|
"text.message",
|
|
15
16
|
"confirmation.result",
|
|
16
17
|
"consent.update",
|
|
@@ -57,6 +58,7 @@ class ControlChannel {
|
|
|
57
58
|
this.pendingOutcomes = new Map();
|
|
58
59
|
this.recentOutcomes = new Map();
|
|
59
60
|
this.outboundOperations = new Map();
|
|
61
|
+
this.outstandingControlFrames = new Map();
|
|
60
62
|
this.latestOutboundSequence = new Map();
|
|
61
63
|
this.unsettledStatefulOperations = new Set();
|
|
62
64
|
this.socketGeneration = 0;
|
|
@@ -150,6 +152,7 @@ class ControlChannel {
|
|
|
150
152
|
protocolMin: 1,
|
|
151
153
|
protocolMax: this.result.protocolVersion,
|
|
152
154
|
clientVersion: this.clientVersion,
|
|
155
|
+
ctaOffer: true,
|
|
153
156
|
resume,
|
|
154
157
|
});
|
|
155
158
|
this.helloOperation = {
|
|
@@ -238,7 +241,9 @@ class ControlChannel {
|
|
|
238
241
|
};
|
|
239
242
|
}
|
|
240
243
|
sendReserved(operation, payload) {
|
|
241
|
-
|
|
244
|
+
const socket = this.socket;
|
|
245
|
+
const socketGeneration = this.socketGeneration;
|
|
246
|
+
if (!socket || socket.readyState !== WebSocket.OPEN) {
|
|
242
247
|
throw new Error("The AI Guide control channel is not connected.");
|
|
243
248
|
}
|
|
244
249
|
if (!CLIENT_MESSAGE_ID_PATTERN.test(operation.messageId) ||
|
|
@@ -253,7 +258,7 @@ class ControlChannel {
|
|
|
253
258
|
this.unsettledStatefulOperations.size >= MAX_PENDING_STATEFUL_OPERATIONS) {
|
|
254
259
|
throw new Error("Too many AI Guide control operations are pending.");
|
|
255
260
|
}
|
|
256
|
-
|
|
261
|
+
const encoded = JSON.stringify({
|
|
257
262
|
v: this.result.protocolVersion,
|
|
258
263
|
id: operation.messageId,
|
|
259
264
|
type: operation.type,
|
|
@@ -263,16 +268,47 @@ class ControlChannel {
|
|
|
263
268
|
fencingToken: this.fencingToken,
|
|
264
269
|
sentAt: new Date().toISOString(),
|
|
265
270
|
payload,
|
|
266
|
-
})
|
|
271
|
+
});
|
|
272
|
+
socket.send(encoded);
|
|
267
273
|
const key = outcomeKey(operation.messageId, operation.sequence);
|
|
268
274
|
this.outboundOperations.set(key, operation);
|
|
269
275
|
this.latestOutboundSequence.set(operation.messageId, operation.sequence);
|
|
270
276
|
if (STATEFUL_CONTROL_TYPES.has(operation.type)) {
|
|
271
277
|
this.unsettledStatefulOperations.add(key);
|
|
278
|
+
this.outstandingControlFrames.set(key, {
|
|
279
|
+
encoded,
|
|
280
|
+
socketGeneration,
|
|
281
|
+
});
|
|
272
282
|
}
|
|
273
283
|
this.pruneSettledOperationHistory();
|
|
274
284
|
return operation.messageId;
|
|
275
285
|
}
|
|
286
|
+
retransmitOutstanding(messageId, expectedSequence) {
|
|
287
|
+
const socket = this.socket;
|
|
288
|
+
if (!socket ||
|
|
289
|
+
socket.readyState !== WebSocket.OPEN ||
|
|
290
|
+
!CLIENT_MESSAGE_ID_PATTERN.test(messageId) ||
|
|
291
|
+
!Number.isSafeInteger(expectedSequence) ||
|
|
292
|
+
expectedSequence < 1) {
|
|
293
|
+
return false;
|
|
294
|
+
}
|
|
295
|
+
const key = outcomeKey(messageId, expectedSequence);
|
|
296
|
+
const frame = this.outstandingControlFrames.get(key);
|
|
297
|
+
if (!frame ||
|
|
298
|
+
frame.socketGeneration !== this.socketGeneration ||
|
|
299
|
+
!this.unsettledStatefulOperations.has(key) ||
|
|
300
|
+
this.latestOutboundSequence.get(messageId) !== expectedSequence ||
|
|
301
|
+
this.recentOutcomes.has(key)) {
|
|
302
|
+
return false;
|
|
303
|
+
}
|
|
304
|
+
try {
|
|
305
|
+
socket.send(frame.encoded);
|
|
306
|
+
return true;
|
|
307
|
+
}
|
|
308
|
+
catch {
|
|
309
|
+
return false;
|
|
310
|
+
}
|
|
311
|
+
}
|
|
276
312
|
outboundOperation(messageId, sequence = this.latestOutboundSequence.get(messageId) ?? 0) {
|
|
277
313
|
return this.outboundOperations.get(outcomeKey(messageId, sequence)) ?? null;
|
|
278
314
|
}
|
|
@@ -655,6 +691,7 @@ class ControlChannel {
|
|
|
655
691
|
settleOutcome(outcome) {
|
|
656
692
|
const key = outcomeKey(outcome.messageId, outcome.sequence);
|
|
657
693
|
this.unsettledStatefulOperations.delete(key);
|
|
694
|
+
this.outstandingControlFrames.delete(key);
|
|
658
695
|
this.recentOutcomes.set(key, outcome);
|
|
659
696
|
if (this.recentOutcomes.size > 100) {
|
|
660
697
|
const oldest = this.recentOutcomes.keys().next().value;
|
|
@@ -689,6 +726,7 @@ class ControlChannel {
|
|
|
689
726
|
value.settle(outcome);
|
|
690
727
|
}
|
|
691
728
|
this.unsettledStatefulOperations.clear();
|
|
729
|
+
this.outstandingControlFrames.clear();
|
|
692
730
|
}
|
|
693
731
|
pruneSettledOperationHistory() {
|
|
694
732
|
const maximum = this.unsettledStatefulOperations.size + MAX_SETTLED_OPERATION_HISTORY;
|
|
@@ -698,6 +736,7 @@ class ControlChannel {
|
|
|
698
736
|
return;
|
|
699
737
|
const retired = this.outboundOperations.get(candidate);
|
|
700
738
|
this.outboundOperations.delete(candidate);
|
|
739
|
+
this.outstandingControlFrames.delete(candidate);
|
|
701
740
|
if (retired &&
|
|
702
741
|
this.latestOutboundSequence.get(retired.messageId) === retired.sequence) {
|
|
703
742
|
this.latestOutboundSequence.delete(retired.messageId);
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { CtaOffer, CtaResult, WidgetMessageKey } from "./types.js";
|
|
2
|
+
export declare const safeCtaUrl: (input: unknown) => string | null;
|
|
3
|
+
export declare const parseCtaOffer: (input: unknown, now?: number) => CtaOffer | null;
|
|
4
|
+
export declare const CTA_OFFER_STYLES = "\n .cta-offer { box-sizing: border-box; display: flex; flex: none; align-items: center; gap: 8px; padding: 8px; margin-block: 8px; border: 1px solid var(--assist-border, var(--voice-border, #c7cbd2)); border-radius: 14px; background: var(--assist-surface, var(--voice-surface, #fff)); color: var(--assist-text, var(--voice-text, #17212b)); font: 500 14px/1.4 system-ui, sans-serif; pointer-events: auto; }\n .cta-offer-link { display: flex; flex: 1; flex-direction: column; justify-content: center; min-width: 0; min-height: 44px; padding: 4px 8px; color: inherit; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }\n .cta-offer-hostname { font-size: 11px; font-weight: 400; text-decoration: none; }\n .cta-offer-dismiss { flex: none; min-width: 44px; min-height: 44px; border: 0; border-radius: 8px; color: inherit; background: transparent; font: inherit; font-size: 22px; cursor: pointer; }\n .cta-offer :is(a, button):focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }\n .cta-offer :is(a, button):hover { background: var(--assist-surface-muted, #f3f4f6); }\n .cta-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }\n .cta-action-slot:empty { display: none; }\n .panel > .cta-action-slot { position: absolute; inset-block-end: calc(100% + 12px); inset-inline-end: 0; width: min(320px, calc(100vw - 40px)); max-height: min(220px, 40dvh); overflow: auto; }\n .panel:not(.open) > .cta-action-slot { display: none; }\n .panel[data-anchor=\"left\"] > .cta-action-slot { inset-inline-start: 0; inset-inline-end: auto; }\n .panel[data-anchor=\"center\"] > .cta-action-slot { inset-inline-start: 50%; inset-inline-end: auto; translate: -50% 0; }\n .panel > .cta-action-slot:not(:empty) ~ .compact-captions { margin-block-end: 100px; }\n .orb-wrap > .cta-action-slot { position: absolute; inset-block-end: calc(100% + 80px + var(--voice-subtitle-height, 0px)); inset-inline-end: 0; width: min(300px, calc(100vw - 40px)); max-height: min(220px, 40dvh); overflow: auto; }\n :host([data-position=\"bottom_left\"]) .orb-wrap > .cta-action-slot { inset-inline-start: 0; inset-inline-end: auto; }\n @media (forced-colors: active) { .cta-offer { background: Canvas; color: CanvasText; border-color: CanvasText; } .cta-offer-link { color: LinkText; } .cta-offer :is(a,button):focus-visible { outline-color: Highlight; } }\n @media (prefers-reduced-motion: reduce), (prefers-reduced-transparency: reduce) { .cta-offer { animation: none; transition: none; backdrop-filter: none; background: var(--assist-surface, #fff); } }\n";
|
|
5
|
+
export declare class CtaOfferCard {
|
|
6
|
+
readonly offer: CtaOffer;
|
|
7
|
+
readonly element: HTMLDivElement;
|
|
8
|
+
private terminal;
|
|
9
|
+
constructor(offer: CtaOffer, messages: Record<WidgetMessageKey, string>, onResult: (result: CtaResult) => boolean, focusAfterDismiss: () => void, announce?: boolean);
|
|
10
|
+
destroy(): void;
|
|
11
|
+
}
|
package/cjs/ctaOffer.js
ADDED
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.CtaOfferCard = exports.CTA_OFFER_STYLES = exports.parseCtaOffer = exports.safeCtaUrl = void 0;
|
|
4
|
+
const OPAQUE_ID = /^[A-Za-z0-9_.:-]{8,128}$/;
|
|
5
|
+
const UNSAFE_TEXT = /[\u0000-\u001f\u007f-\u009f\u2028\u2029\u202a-\u202e\u2066-\u2069]/u;
|
|
6
|
+
const OFFER_KEYS = [
|
|
7
|
+
"configRevision",
|
|
8
|
+
"expiresAt",
|
|
9
|
+
"label",
|
|
10
|
+
"offerId",
|
|
11
|
+
"openBehavior",
|
|
12
|
+
"sourceTurnId",
|
|
13
|
+
"url",
|
|
14
|
+
];
|
|
15
|
+
const safeCtaUrl = (input) => {
|
|
16
|
+
if (typeof input !== "string" ||
|
|
17
|
+
Array.from(input).length > 2048 ||
|
|
18
|
+
/[\s\\]/u.test(input) ||
|
|
19
|
+
UNSAFE_TEXT.test(input))
|
|
20
|
+
return null;
|
|
21
|
+
const authority = /^https:\/\/([^/?#]+)/iu.exec(input)?.[1];
|
|
22
|
+
if (!authority ||
|
|
23
|
+
authority.includes("@") ||
|
|
24
|
+
authority.includes("%") ||
|
|
25
|
+
authority.endsWith(":"))
|
|
26
|
+
return null;
|
|
27
|
+
try {
|
|
28
|
+
const url = new URL(input);
|
|
29
|
+
if (url.protocol !== "https:" ||
|
|
30
|
+
!url.hostname ||
|
|
31
|
+
url.username ||
|
|
32
|
+
url.password ||
|
|
33
|
+
input.includes("#") ||
|
|
34
|
+
(url.port && Number(url.port) < 1))
|
|
35
|
+
return null;
|
|
36
|
+
return input;
|
|
37
|
+
}
|
|
38
|
+
catch {
|
|
39
|
+
return null;
|
|
40
|
+
}
|
|
41
|
+
};
|
|
42
|
+
exports.safeCtaUrl = safeCtaUrl;
|
|
43
|
+
const parseCtaOffer = (input, now = Date.now()) => {
|
|
44
|
+
if (!input || typeof input !== "object" || Array.isArray(input))
|
|
45
|
+
return null;
|
|
46
|
+
const value = input;
|
|
47
|
+
if (Object.keys(value).sort().join("|") !== OFFER_KEYS.join("|"))
|
|
48
|
+
return null;
|
|
49
|
+
const { offerId, sourceTurnId, label, openBehavior, configRevision, expiresAt, } = value;
|
|
50
|
+
const url = (0, exports.safeCtaUrl)(value.url);
|
|
51
|
+
if (typeof offerId !== "string" ||
|
|
52
|
+
!OPAQUE_ID.test(offerId) ||
|
|
53
|
+
typeof sourceTurnId !== "string" ||
|
|
54
|
+
!OPAQUE_ID.test(sourceTurnId) ||
|
|
55
|
+
typeof label !== "string" ||
|
|
56
|
+
label !== label.trim() ||
|
|
57
|
+
label !== label.normalize("NFC") ||
|
|
58
|
+
Array.from(label).length < 1 ||
|
|
59
|
+
Array.from(label).length > 80 ||
|
|
60
|
+
UNSAFE_TEXT.test(label) ||
|
|
61
|
+
!url ||
|
|
62
|
+
(openBehavior !== "same_tab" && openBehavior !== "new_tab") ||
|
|
63
|
+
!Number.isSafeInteger(configRevision) ||
|
|
64
|
+
configRevision < 1 ||
|
|
65
|
+
typeof expiresAt !== "string" ||
|
|
66
|
+
!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}:\d{2}(?:\.\d{1,3})?(?:Z|[+-]\d{2}:\d{2})$/u.test(expiresAt))
|
|
67
|
+
return null;
|
|
68
|
+
const expiry = Date.parse(expiresAt);
|
|
69
|
+
if (!Number.isFinite(expiry) || expiry <= now || expiry > now + 300000)
|
|
70
|
+
return null;
|
|
71
|
+
return {
|
|
72
|
+
offerId,
|
|
73
|
+
sourceTurnId,
|
|
74
|
+
label,
|
|
75
|
+
url,
|
|
76
|
+
openBehavior,
|
|
77
|
+
configRevision: configRevision,
|
|
78
|
+
expiresAt,
|
|
79
|
+
};
|
|
80
|
+
};
|
|
81
|
+
exports.parseCtaOffer = parseCtaOffer;
|
|
82
|
+
exports.CTA_OFFER_STYLES = `
|
|
83
|
+
.cta-offer { box-sizing: border-box; display: flex; flex: none; align-items: center; gap: 8px; padding: 8px; margin-block: 8px; border: 1px solid var(--assist-border, var(--voice-border, #c7cbd2)); border-radius: 14px; background: var(--assist-surface, var(--voice-surface, #fff)); color: var(--assist-text, var(--voice-text, #17212b)); font: 500 14px/1.4 system-ui, sans-serif; pointer-events: auto; }
|
|
84
|
+
.cta-offer-link { display: flex; flex: 1; flex-direction: column; justify-content: center; min-width: 0; min-height: 44px; padding: 4px 8px; color: inherit; text-decoration: underline; text-underline-offset: 3px; overflow-wrap: anywhere; }
|
|
85
|
+
.cta-offer-hostname { font-size: 11px; font-weight: 400; text-decoration: none; }
|
|
86
|
+
.cta-offer-dismiss { flex: none; min-width: 44px; min-height: 44px; border: 0; border-radius: 8px; color: inherit; background: transparent; font: inherit; font-size: 22px; cursor: pointer; }
|
|
87
|
+
.cta-offer :is(a, button):focus-visible { outline: 2px solid currentColor; outline-offset: 2px; }
|
|
88
|
+
.cta-offer :is(a, button):hover { background: var(--assist-surface-muted, #f3f4f6); }
|
|
89
|
+
.cta-sr-only { position: absolute; width: 1px; height: 1px; padding: 0; overflow: hidden; clip-path: inset(50%); white-space: nowrap; }
|
|
90
|
+
.cta-action-slot:empty { display: none; }
|
|
91
|
+
.panel > .cta-action-slot { position: absolute; inset-block-end: calc(100% + 12px); inset-inline-end: 0; width: min(320px, calc(100vw - 40px)); max-height: min(220px, 40dvh); overflow: auto; }
|
|
92
|
+
.panel:not(.open) > .cta-action-slot { display: none; }
|
|
93
|
+
.panel[data-anchor="left"] > .cta-action-slot { inset-inline-start: 0; inset-inline-end: auto; }
|
|
94
|
+
.panel[data-anchor="center"] > .cta-action-slot { inset-inline-start: 50%; inset-inline-end: auto; translate: -50% 0; }
|
|
95
|
+
.panel > .cta-action-slot:not(:empty) ~ .compact-captions { margin-block-end: 100px; }
|
|
96
|
+
.orb-wrap > .cta-action-slot { position: absolute; inset-block-end: calc(100% + 80px + var(--voice-subtitle-height, 0px)); inset-inline-end: 0; width: min(300px, calc(100vw - 40px)); max-height: min(220px, 40dvh); overflow: auto; }
|
|
97
|
+
:host([data-position="bottom_left"]) .orb-wrap > .cta-action-slot { inset-inline-start: 0; inset-inline-end: auto; }
|
|
98
|
+
@media (forced-colors: active) { .cta-offer { background: Canvas; color: CanvasText; border-color: CanvasText; } .cta-offer-link { color: LinkText; } .cta-offer :is(a,button):focus-visible { outline-color: Highlight; } }
|
|
99
|
+
@media (prefers-reduced-motion: reduce), (prefers-reduced-transparency: reduce) { .cta-offer { animation: none; transition: none; backdrop-filter: none; background: var(--assist-surface, #fff); } }
|
|
100
|
+
`;
|
|
101
|
+
class CtaOfferCard {
|
|
102
|
+
constructor(offer, messages, onResult, focusAfterDismiss, announce = true) {
|
|
103
|
+
this.offer = offer;
|
|
104
|
+
this.element = document.createElement("div");
|
|
105
|
+
this.terminal = false;
|
|
106
|
+
this.element.className = "cta-offer";
|
|
107
|
+
this.element.dataset.offerId = offer.offerId;
|
|
108
|
+
this.element.dataset.sourceTurnId = offer.sourceTurnId;
|
|
109
|
+
this.element.setAttribute("role", "group");
|
|
110
|
+
this.element.setAttribute("aria-label", offer.label);
|
|
111
|
+
this.element.setAttribute("aria-live", "off");
|
|
112
|
+
const link = document.createElement("a");
|
|
113
|
+
link.className = "cta-offer-link";
|
|
114
|
+
link.href = offer.url;
|
|
115
|
+
link.target = offer.openBehavior === "new_tab" ? "_blank" : "_self";
|
|
116
|
+
if (offer.openBehavior === "new_tab")
|
|
117
|
+
link.rel = "noopener noreferrer";
|
|
118
|
+
const label = document.createElement("span");
|
|
119
|
+
label.textContent = offer.label;
|
|
120
|
+
link.append(label);
|
|
121
|
+
if (new URL(offer.url).origin !== window.location.origin) {
|
|
122
|
+
const hostname = document.createElement("span");
|
|
123
|
+
hostname.className = "cta-offer-hostname";
|
|
124
|
+
hostname.textContent = new URL(offer.url).hostname;
|
|
125
|
+
link.append(hostname);
|
|
126
|
+
}
|
|
127
|
+
if (offer.openBehavior === "new_tab") {
|
|
128
|
+
const hint = document.createElement("span");
|
|
129
|
+
hint.className = "cta-sr-only";
|
|
130
|
+
hint.textContent = messages.ctaNewTab;
|
|
131
|
+
link.append(hint);
|
|
132
|
+
}
|
|
133
|
+
const dismiss = document.createElement("button");
|
|
134
|
+
dismiss.type = "button";
|
|
135
|
+
dismiss.className = "cta-offer-dismiss";
|
|
136
|
+
dismiss.setAttribute("aria-label", messages.ctaDismiss);
|
|
137
|
+
dismiss.textContent = "×";
|
|
138
|
+
const settle = (outcome, event) => {
|
|
139
|
+
if (this.terminal || Date.parse(offer.expiresAt) <= Date.now()) {
|
|
140
|
+
event.preventDefault();
|
|
141
|
+
return;
|
|
142
|
+
}
|
|
143
|
+
this.terminal = true;
|
|
144
|
+
const restoreFocus = outcome === "dismissed" &&
|
|
145
|
+
dismiss.getRootNode() instanceof ShadowRoot &&
|
|
146
|
+
dismiss.getRootNode().activeElement === dismiss;
|
|
147
|
+
let accepted = false;
|
|
148
|
+
try {
|
|
149
|
+
accepted = onResult({ offerId: offer.offerId, outcome });
|
|
150
|
+
}
|
|
151
|
+
catch {
|
|
152
|
+
/* fail closed */
|
|
153
|
+
}
|
|
154
|
+
if (!accepted)
|
|
155
|
+
event.preventDefault();
|
|
156
|
+
if (outcome === "dismissed") {
|
|
157
|
+
this.destroy();
|
|
158
|
+
if (restoreFocus)
|
|
159
|
+
focusAfterDismiss();
|
|
160
|
+
}
|
|
161
|
+
else {
|
|
162
|
+
// Native link activation stays in the visitor gesture; no ACK is awaited.
|
|
163
|
+
queueMicrotask(() => this.destroy());
|
|
164
|
+
}
|
|
165
|
+
};
|
|
166
|
+
link.addEventListener("click", (event) => settle("clicked", event));
|
|
167
|
+
link.addEventListener("auxclick", (event) => {
|
|
168
|
+
if (event.button === 1)
|
|
169
|
+
settle("clicked", event);
|
|
170
|
+
});
|
|
171
|
+
dismiss.addEventListener("click", (event) => settle("dismissed", event));
|
|
172
|
+
const announcement = document.createElement("span");
|
|
173
|
+
announcement.className = "cta-sr-only";
|
|
174
|
+
if (announce) {
|
|
175
|
+
announcement.setAttribute("aria-live", "polite");
|
|
176
|
+
announcement.textContent = messages.ctaAvailable;
|
|
177
|
+
}
|
|
178
|
+
this.element.append(link, dismiss, announcement);
|
|
179
|
+
}
|
|
180
|
+
destroy() {
|
|
181
|
+
this.terminal = true;
|
|
182
|
+
this.element.remove();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
exports.CtaOfferCard = CtaOfferCard;
|
package/cjs/dialogFocusScope.js
CHANGED
|
@@ -85,7 +85,7 @@ class DialogFocusScope {
|
|
|
85
85
|
...presentation.surface.querySelectorAll(focusableSelector),
|
|
86
86
|
].filter(isVisibleFocusTarget);
|
|
87
87
|
const first = focusable[0];
|
|
88
|
-
const last = focusable.
|
|
88
|
+
const last = focusable[focusable.length - 1];
|
|
89
89
|
if (!first || !last)
|
|
90
90
|
return;
|
|
91
91
|
const active = this.root.activeElement;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { RuntimeClient, type LaunchInput } from "./client.js";
|
|
2
|
+
import { GuideSubjectStore } from "./guideSubjectStore.js";
|
|
3
|
+
import { type GuideBootstrapConfig, type GuideIdentity, type GuideLaunchIntent } from "./guideTypes.js";
|
|
4
|
+
import type { BootstrapConfig, LaunchResult, ConsentScope } from "./types.js";
|
|
5
|
+
import { type GuideRecordingAdapter } from "./guideRecordingSession.js";
|
|
6
|
+
export type GuideConnectionScope = {
|
|
7
|
+
kind: "guide_subject_v2";
|
|
8
|
+
assertCurrent(): void;
|
|
9
|
+
};
|
|
10
|
+
export type GuideLaunchInput = Omit<LaunchInput, "siteKey" | "anonymousId" | "replay">;
|
|
11
|
+
export declare function validateGuideBootstrap(value: BootstrapConfig, installKey: string): GuideBootstrapConfig;
|
|
12
|
+
/** Server admission and local cancellation fences; no recorder or crypto substitute. */
|
|
13
|
+
export declare class GuideAdmission {
|
|
14
|
+
readonly identity: GuideIdentity;
|
|
15
|
+
readonly store: GuideSubjectStore;
|
|
16
|
+
private readonly runtime;
|
|
17
|
+
private initialBootstrap;
|
|
18
|
+
private currentBootstrap;
|
|
19
|
+
private activeAdmission;
|
|
20
|
+
private admissionRequestId;
|
|
21
|
+
private activeLaunchRequestId;
|
|
22
|
+
private activeLaunchRecord;
|
|
23
|
+
private readonly recording;
|
|
24
|
+
private recordingChoice;
|
|
25
|
+
private recordingChoiceRevision;
|
|
26
|
+
constructor(identity: GuideIdentity, store: GuideSubjectStore, runtime: RuntimeClient, bootstrap: BootstrapConfig, recordingAdapter?: GuideRecordingAdapter | null);
|
|
27
|
+
subjectId(): string | null;
|
|
28
|
+
get recordingConfigured(): boolean;
|
|
29
|
+
get recordingAllowed(): boolean;
|
|
30
|
+
setRecordingChoice(allowed: boolean): boolean;
|
|
31
|
+
syncRecording(result: LaunchResult, scopes: ConsentScope[], tabId: string): void;
|
|
32
|
+
updateRecordingConsent(scopes: ConsentScope[]): void;
|
|
33
|
+
destroy(): void;
|
|
34
|
+
pendingIntent(): GuideLaunchIntent | null;
|
|
35
|
+
connectionScope(): GuideConnectionScope;
|
|
36
|
+
bootstrap(path: string, locale: string, signal: AbortSignal): Promise<BootstrapConfig>;
|
|
37
|
+
launch(input: GuideLaunchInput, signal: AbortSignal): Promise<LaunchResult>;
|
|
38
|
+
endLaunch(idempotencyKey: string, tabId: string, signal?: AbortSignal): Promise<void>;
|
|
39
|
+
complete(): void;
|
|
40
|
+
private retireTerminalLaunch;
|
|
41
|
+
private recover;
|
|
42
|
+
private requiredSubject;
|
|
43
|
+
private validateAdmission;
|
|
44
|
+
private validateLaunch;
|
|
45
|
+
private intent;
|
|
46
|
+
}
|