@oxvo/ai-live-assist 7.4.50 → 7.5.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (163) hide show
  1. package/cjs/AiLiveAssist.d.ts +76 -11
  2. package/cjs/AiLiveAssist.js +1771 -298
  3. package/cjs/client.d.ts +19 -0
  4. package/cjs/client.js +51 -0
  5. package/cjs/context.d.ts +23 -1
  6. package/cjs/context.js +713 -126
  7. package/cjs/control.d.ts +2 -0
  8. package/cjs/control.js +42 -3
  9. package/cjs/ctaOffer.d.ts +11 -0
  10. package/cjs/ctaOffer.js +185 -0
  11. package/cjs/dialogFocusScope.js +1 -1
  12. package/cjs/guideAdmission.d.ts +46 -0
  13. package/cjs/guideAdmission.js +397 -0
  14. package/cjs/guideHost.d.ts +47 -0
  15. package/cjs/guideHost.js +48 -0
  16. package/cjs/guideInstallation.d.ts +12 -0
  17. package/cjs/guideInstallation.js +60 -0
  18. package/cjs/guideInstaller.d.ts +4 -0
  19. package/cjs/guideInstaller.js +116 -0
  20. package/cjs/guideMount.d.ts +22 -0
  21. package/cjs/guideMount.js +84 -0
  22. package/cjs/guideRecording.d.ts +64 -0
  23. package/cjs/guideRecording.js +176 -0
  24. package/cjs/guideRecordingSession.d.ts +35 -0
  25. package/cjs/guideRecordingSession.js +167 -0
  26. package/cjs/guideSubjectStore.d.ts +32 -0
  27. package/cjs/guideSubjectStore.js +105 -0
  28. package/cjs/guideTypes.d.ts +117 -0
  29. package/cjs/guideTypes.js +15 -0
  30. package/cjs/index.d.ts +6 -0
  31. package/cjs/index.js +25 -11
  32. package/cjs/liveAudioProcessor.d.ts +92 -0
  33. package/cjs/liveAudioProcessor.js +269 -0
  34. package/cjs/liveAudioQueue.d.ts +40 -0
  35. package/cjs/liveAudioQueue.js +130 -0
  36. package/cjs/liveAudioWorklet.d.ts +1 -0
  37. package/cjs/liveAudioWorklet.js +63 -0
  38. package/cjs/liveBrowserDetector.d.ts +16 -0
  39. package/cjs/liveBrowserDetector.js +75 -0
  40. package/cjs/liveBrowserDetectorWorker.d.ts +1 -0
  41. package/cjs/liveBrowserDetectorWorker.js +72 -0
  42. package/cjs/liveControlChannel.d.ts +176 -0
  43. package/cjs/liveControlChannel.js +829 -0
  44. package/cjs/liveDuplexMedia.d.ts +204 -0
  45. package/cjs/liveDuplexMedia.js +740 -0
  46. package/cjs/liveGuideAdmission.d.ts +21 -0
  47. package/cjs/liveGuideAdmission.js +94 -0
  48. package/cjs/liveGuideWidget.d.ts +68 -0
  49. package/cjs/liveGuideWidget.js +451 -0
  50. package/cjs/liveSpeechAssets.d.ts +36 -0
  51. package/cjs/liveSpeechAssets.js +39 -0
  52. package/cjs/liveSpeechCaptureBridge.d.ts +32 -0
  53. package/cjs/liveSpeechCaptureBridge.js +140 -0
  54. package/cjs/liveSpeechDetector.d.ts +62 -0
  55. package/cjs/liveSpeechDetector.js +206 -0
  56. package/cjs/liveSpeechModel.d.ts +46 -0
  57. package/cjs/liveSpeechModel.js +105 -0
  58. package/cjs/liveSpeechResampler.d.ts +22 -0
  59. package/cjs/liveSpeechResampler.js +93 -0
  60. package/cjs/liveSpeechWorker.d.ts +56 -0
  61. package/cjs/liveSpeechWorker.js +143 -0
  62. package/cjs/locales/resources.js +568 -8
  63. package/cjs/media.d.ts +11 -0
  64. package/cjs/media.js +78 -9
  65. package/cjs/messages.js +22 -8
  66. package/cjs/pageAssistancePreference.d.ts +15 -3
  67. package/cjs/pageAssistancePreference.js +46 -7
  68. package/cjs/preview.d.ts +4 -1
  69. package/cjs/preview.js +42 -1
  70. package/cjs/recording.d.ts +12 -0
  71. package/cjs/recording.js +150 -0
  72. package/cjs/standalone.d.ts +6 -0
  73. package/cjs/standalone.js +12 -0
  74. package/cjs/types.d.ts +31 -5
  75. package/cjs/types.js +14 -0
  76. package/cjs/ui.d.ts +128 -4
  77. package/cjs/ui.js +1918 -276
  78. package/cjs/version.d.ts +1 -1
  79. package/cjs/version.js +1 -1
  80. package/cjs/voicePresenceUi.d.ts +52 -4
  81. package/cjs/voicePresenceUi.js +659 -57
  82. package/lib/AiLiveAssist.d.ts +76 -11
  83. package/lib/AiLiveAssist.js +1772 -299
  84. package/lib/client.d.ts +19 -0
  85. package/lib/client.js +51 -0
  86. package/lib/context.d.ts +23 -1
  87. package/lib/context.js +713 -126
  88. package/lib/control.d.ts +2 -0
  89. package/lib/control.js +42 -3
  90. package/lib/ctaOffer.d.ts +11 -0
  91. package/lib/ctaOffer.js +179 -0
  92. package/lib/dialogFocusScope.js +1 -1
  93. package/lib/guideAdmission.d.ts +46 -0
  94. package/lib/guideAdmission.js +392 -0
  95. package/lib/guideHost.d.ts +47 -0
  96. package/lib/guideHost.js +42 -0
  97. package/lib/guideInstallation.d.ts +12 -0
  98. package/lib/guideInstallation.js +56 -0
  99. package/lib/guideInstaller.d.ts +4 -0
  100. package/lib/guideInstaller.js +113 -0
  101. package/lib/guideMount.d.ts +22 -0
  102. package/lib/guideMount.js +77 -0
  103. package/lib/guideRecording.d.ts +64 -0
  104. package/lib/guideRecording.js +172 -0
  105. package/lib/guideRecordingSession.d.ts +35 -0
  106. package/lib/guideRecordingSession.js +163 -0
  107. package/lib/guideSubjectStore.d.ts +32 -0
  108. package/lib/guideSubjectStore.js +101 -0
  109. package/lib/guideTypes.d.ts +117 -0
  110. package/lib/guideTypes.js +11 -0
  111. package/lib/index.d.ts +6 -0
  112. package/lib/index.js +21 -10
  113. package/lib/liveAudioProcessor.d.ts +92 -0
  114. package/lib/liveAudioProcessor.js +265 -0
  115. package/lib/liveAudioQueue.d.ts +40 -0
  116. package/lib/liveAudioQueue.js +126 -0
  117. package/lib/liveAudioWorklet.d.ts +1 -0
  118. package/lib/liveAudioWorklet.js +61 -0
  119. package/lib/liveBrowserDetector.d.ts +16 -0
  120. package/lib/liveBrowserDetector.js +71 -0
  121. package/lib/liveBrowserDetectorWorker.d.ts +1 -0
  122. package/lib/liveBrowserDetectorWorker.js +70 -0
  123. package/lib/liveControlChannel.d.ts +176 -0
  124. package/lib/liveControlChannel.js +825 -0
  125. package/lib/liveDuplexMedia.d.ts +204 -0
  126. package/lib/liveDuplexMedia.js +736 -0
  127. package/lib/liveGuideAdmission.d.ts +21 -0
  128. package/lib/liveGuideAdmission.js +90 -0
  129. package/lib/liveGuideWidget.d.ts +68 -0
  130. package/lib/liveGuideWidget.js +447 -0
  131. package/lib/liveSpeechAssets.d.ts +36 -0
  132. package/lib/liveSpeechAssets.js +35 -0
  133. package/lib/liveSpeechCaptureBridge.d.ts +32 -0
  134. package/lib/liveSpeechCaptureBridge.js +136 -0
  135. package/lib/liveSpeechDetector.d.ts +62 -0
  136. package/lib/liveSpeechDetector.js +202 -0
  137. package/lib/liveSpeechModel.d.ts +46 -0
  138. package/lib/liveSpeechModel.js +101 -0
  139. package/lib/liveSpeechResampler.d.ts +22 -0
  140. package/lib/liveSpeechResampler.js +89 -0
  141. package/lib/liveSpeechWorker.d.ts +56 -0
  142. package/lib/liveSpeechWorker.js +137 -0
  143. package/lib/locales/resources.js +568 -8
  144. package/lib/media.d.ts +11 -0
  145. package/lib/media.js +77 -8
  146. package/lib/messages.js +22 -8
  147. package/lib/pageAssistancePreference.d.ts +15 -3
  148. package/lib/pageAssistancePreference.js +46 -7
  149. package/lib/preview.d.ts +4 -1
  150. package/lib/preview.js +42 -1
  151. package/lib/recording.d.ts +12 -0
  152. package/lib/recording.js +146 -0
  153. package/lib/standalone.d.ts +6 -0
  154. package/lib/standalone.js +6 -0
  155. package/lib/types.d.ts +31 -5
  156. package/lib/types.js +14 -0
  157. package/lib/ui.d.ts +128 -4
  158. package/lib/ui.js +1919 -277
  159. package/lib/version.d.ts +1 -1
  160. package/lib/version.js +1 -1
  161. package/lib/voicePresenceUi.d.ts +52 -4
  162. package/lib/voicePresenceUi.js +659 -57
  163. package/package.json +16 -1
@@ -0,0 +1,116 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.installGuide = installGuide;
4
+ const AiLiveAssist_js_1 = require("./AiLiveAssist.js");
5
+ const client_js_1 = require("./client.js");
6
+ const guideAdmission_js_1 = require("./guideAdmission.js");
7
+ const guideHost_js_1 = require("./guideHost.js");
8
+ const guideMount_js_1 = require("./guideMount.js");
9
+ const guideSubjectStore_js_1 = require("./guideSubjectStore.js");
10
+ const guideInstallation_js_1 = require("./guideInstallation.js");
11
+ const guideTypes_js_1 = require("./guideTypes.js");
12
+ const version_js_1 = require("./version.js");
13
+ /** Install one Guide without importing, initializing or consulting a recorder. */
14
+ function installGuide(options, recordingFactory) {
15
+ if (options.enabled === false)
16
+ return Promise.resolve(undefined);
17
+ const insideFrame = window.self !== window.top;
18
+ if (insideFrame && options.allowInFrame !== true)
19
+ return Promise.resolve(undefined);
20
+ try {
21
+ // location.origin alone is insufficient: a sandboxed HTTPS frame may have
22
+ // that URL while its actual security origin (and request Origin) is null.
23
+ // Never inherit parent identity or seek storage/DOM access outside this
24
+ // document. Server bootstrap/admission still authorizes the browser Origin.
25
+ if (!["http:", "https:"].includes(window.location.protocol) ||
26
+ window.origin === "null" ||
27
+ window.origin !== window.location.origin)
28
+ throw new Error("AI Guide requires its own non-opaque HTTP or HTTPS origin.");
29
+ if (!guideTypes_js_1.GUIDE_INSTALL_KEY_PATTERN.test(options.installKey))
30
+ throw new Error("Invalid AI Guide installation key.");
31
+ const runtime = new client_js_1.RuntimeClient(options.runtimeUrl, version_js_1.VERSION);
32
+ const installationIdentity = `installation:${runtime.baseUrl}:${options.installKey}`;
33
+ const existing = (0, guideMount_js_1.mountedGuide)(document, installationIdentity);
34
+ if (existing)
35
+ return Promise.resolve(existing);
36
+ const mount = new guideMount_js_1.PendingGuideMount(document, installationIdentity);
37
+ void (async () => {
38
+ const controller = new AbortController();
39
+ const timeout = setTimeout(() => controller.abort(), 15000);
40
+ try {
41
+ const bootstrap = await runtime.bootstrapGuide(options.installKey, window.location.pathname || "/", options.locale ||
42
+ navigator.language ||
43
+ document.documentElement.lang ||
44
+ "en", controller.signal);
45
+ const locator = new guideInstallation_js_1.GuideInstallationLocator(runtime.baseUrl, options.installKey, window.location.origin);
46
+ const resolved = bootstrap.available
47
+ ? (0, guideAdmission_js_1.validateGuideBootstrap)(bootstrap, options.installKey)
48
+ : null;
49
+ const remembered = bootstrap.schemaVersion === 3 ? locator.read() : null;
50
+ if (resolved &&
51
+ remembered &&
52
+ (resolved.projectId !== remembered.projectId ||
53
+ resolved.guideId !== remembered.guideId)) {
54
+ throw new Error("The AI Guide installation identity changed.");
55
+ }
56
+ const identity = resolved
57
+ ? Object.freeze({
58
+ projectId: resolved.projectId,
59
+ guideId: resolved.guideId,
60
+ installKey: options.installKey,
61
+ })
62
+ : remembered;
63
+ if (!identity)
64
+ throw new client_js_1.RuntimeClientError("GUIDE_UNAVAILABLE", "This AI Guide is currently unavailable.", false, null, 404);
65
+ if (resolved)
66
+ locator.save(identity);
67
+ const host = {
68
+ kind: "guide",
69
+ identity,
70
+ runtimeUrl: runtime.baseUrl,
71
+ getTabId: () => null,
72
+ getVisitorId: () => null,
73
+ };
74
+ const namespace = (0, guideHost_js_1.guideStorageNamespace)(host, "", window.location.origin);
75
+ const store = new guideSubjectStore_js_1.GuideSubjectStore(identity, window.location.origin, namespace);
76
+ if (!resolved && !store.readLaunch())
77
+ throw new client_js_1.RuntimeClientError("GUIDE_UNAVAILABLE", "This AI Guide is currently unavailable.", false, null, 404);
78
+ const admission = new guideAdmission_js_1.GuideAdmission(identity, store, runtime, bootstrap, !insideFrame &&
79
+ resolved?.replayRecordingEnabled === true &&
80
+ recordingFactory
81
+ ? recordingFactory(identity, runtime.baseUrl)
82
+ : null);
83
+ if (insideFrame &&
84
+ resolved?.replayRecordingEnabled === true &&
85
+ recordingFactory)
86
+ window.dispatchEvent(new CustomEvent("oxvo:ai-guide:recording-status", {
87
+ detail: { guideId: identity.guideId, status: "unavailable" },
88
+ }));
89
+ const tabKey = `__oxvo_ai_guide_tab_v1_${namespace}`;
90
+ const tabId = sessionStorage.getItem(tabKey) || `tab_${crypto.randomUUID()}`;
91
+ if (!/^[A-Za-z0-9_.:-]{1,128}$/.test(tabId))
92
+ throw new Error("The saved AI Guide tab identity is invalid.");
93
+ sessionStorage.setItem(tabKey, tabId);
94
+ if (sessionStorage.getItem(tabKey) !== tabId)
95
+ throw new Error("AI Guide could not securely save this tab identity.");
96
+ const instance = new AiLiveAssist_js_1.default({
97
+ ...host,
98
+ admission,
99
+ getTabId: () => tabId,
100
+ getVisitorId: () => admission.subjectId(),
101
+ }, options, mount);
102
+ mount.resolve(instance);
103
+ }
104
+ finally {
105
+ clearTimeout(timeout);
106
+ }
107
+ })().catch((error) => {
108
+ mount.release();
109
+ mount.reject(error);
110
+ });
111
+ return mount.promise;
112
+ }
113
+ catch (error) {
114
+ return Promise.reject(error);
115
+ }
116
+ }
@@ -0,0 +1,22 @@
1
+ export type GuideMountReservation = {
2
+ promote(document: Document, identity: string, instance: unknown): () => void;
3
+ };
4
+ export declare class GuideMountConflictError extends Error {
5
+ constructor();
6
+ }
7
+ export declare function mountedGuide<T>(document: Document, identity: string): T | undefined;
8
+ export declare function claimGuideMount(document: Document, identity: string, instance: unknown, pending?: GuideMountReservation): () => void;
9
+ /** Owns one asynchronous installation until canonical bootstrap identity is known. */
10
+ export declare class PendingGuideMount<T> {
11
+ private readonly document;
12
+ readonly promise: Promise<T>;
13
+ private readonly claim;
14
+ private resolvePromise;
15
+ private rejectPromise;
16
+ private promoted;
17
+ constructor(document: Document, identity: string);
18
+ promote(document: Document, identity: string, instance: unknown): () => void;
19
+ resolve(instance: T): void;
20
+ reject(error: unknown): void;
21
+ release(): void;
22
+ }
@@ -0,0 +1,84 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.PendingGuideMount = exports.GuideMountConflictError = void 0;
4
+ exports.mountedGuide = mountedGuide;
5
+ exports.claimGuideMount = claimGuideMount;
6
+ // A document-owned registry also coordinates different copies/versions of the SDK
7
+ // before asynchronous bootstrap has created the visible widget root.
8
+ const MOUNT_KEY = Symbol.for("oxvo.ai-guide.document-mount.v1");
9
+ class GuideMountConflictError extends Error {
10
+ constructor() {
11
+ super("An AI Guide is already mounted on this page.");
12
+ this.name = "GuideMountConflictError";
13
+ }
14
+ }
15
+ exports.GuideMountConflictError = GuideMountConflictError;
16
+ function mountedGuide(document, identity) {
17
+ const mounted = document[MOUNT_KEY];
18
+ if (!mounted)
19
+ return undefined;
20
+ if (mounted.identity !== identity &&
21
+ mounted.installationIdentity !== identity)
22
+ throw new GuideMountConflictError();
23
+ return mounted.instance;
24
+ }
25
+ function claimGuideMount(document, identity, instance, pending) {
26
+ if (pending)
27
+ return pending.promote(document, identity, instance);
28
+ const owner = document;
29
+ if (owner[MOUNT_KEY] ||
30
+ document.querySelector("[data-oxvo-ai-live-assist-root]")) {
31
+ throw new GuideMountConflictError();
32
+ }
33
+ const claim = { identity, instance };
34
+ Object.defineProperty(owner, MOUNT_KEY, { value: claim, configurable: true });
35
+ return () => {
36
+ if (owner[MOUNT_KEY] === claim)
37
+ Reflect.deleteProperty(owner, MOUNT_KEY);
38
+ };
39
+ }
40
+ /** Owns one asynchronous installation until canonical bootstrap identity is known. */
41
+ class PendingGuideMount {
42
+ constructor(document, identity) {
43
+ this.document = document;
44
+ this.promoted = false;
45
+ const owner = document;
46
+ if (owner[MOUNT_KEY] ||
47
+ document.querySelector("[data-oxvo-ai-live-assist-root]"))
48
+ throw new GuideMountConflictError();
49
+ this.promise = new Promise((resolve, reject) => {
50
+ this.resolvePromise = resolve;
51
+ this.rejectPromise = reject;
52
+ });
53
+ this.claim = {
54
+ identity,
55
+ installationIdentity: identity,
56
+ instance: this.promise,
57
+ };
58
+ Object.defineProperty(owner, MOUNT_KEY, {
59
+ value: this.claim,
60
+ configurable: true,
61
+ });
62
+ }
63
+ promote(document, identity, instance) {
64
+ if (document !== this.document ||
65
+ document[MOUNT_KEY] !== this.claim ||
66
+ this.promoted)
67
+ throw new GuideMountConflictError();
68
+ this.promoted = true;
69
+ this.claim.identity = identity;
70
+ this.claim.instance = instance;
71
+ return () => this.release();
72
+ }
73
+ resolve(instance) {
74
+ this.resolvePromise(instance);
75
+ }
76
+ reject(error) {
77
+ this.rejectPromise(error);
78
+ }
79
+ release() {
80
+ if (this.document[MOUNT_KEY] === this.claim)
81
+ Reflect.deleteProperty(this.document, MOUNT_KEY);
82
+ }
83
+ }
84
+ exports.PendingGuideMount = PendingGuideMount;
@@ -0,0 +1,64 @@
1
+ /** Browser-free structural subset of the real recorder App. No lifecycle ownership. */
2
+ export type GuideRecordingSource = {
3
+ active(): boolean;
4
+ getSessionMeta(): {
5
+ sessionID?: unknown;
6
+ projectID?: unknown;
7
+ } | null;
8
+ getAssistSessionGrant(): {
9
+ sessionId?: unknown;
10
+ token?: unknown;
11
+ } | null;
12
+ session: {
13
+ getTabId(): unknown;
14
+ };
15
+ attachStartCallback(callback: () => void, useSafe?: boolean): void;
16
+ attachStopCallback(callback: () => void, useSafe?: boolean): void;
17
+ };
18
+ /** A real replay grant candidate, not proof of a server-validated Guide recording link. */
19
+ export type GuideRecordingLink = Readonly<{
20
+ sessionId: string;
21
+ token: string;
22
+ tabId: string;
23
+ }>;
24
+ export type GuideRecordingObserver = Readonly<{
25
+ getCurrentLink(): GuideRecordingLink | null;
26
+ /** Immediately supplies the current candidate, then changed lifecycle snapshots. */
27
+ subscribeLinkChange(listener: (link: GuideRecordingLink | null) => void): () => void;
28
+ dispose(): void;
29
+ }>;
30
+ /** Observe only an explicitly supplied recorder; never discover, start or stop one. */
31
+ export declare function observeGuideRecording(source: GuideRecordingSource, input: {
32
+ projectId: number;
33
+ }): GuideRecordingObserver;
34
+ /** Structural match for Browser's actual networkCapture.sanitizer data API. */
35
+ export type GuideRecordingNetworkData = {
36
+ readonly status: number;
37
+ readonly method: string;
38
+ url: string;
39
+ request: {
40
+ body: string | null;
41
+ headers: Record<string, string>;
42
+ };
43
+ response: {
44
+ body: unknown;
45
+ headers: Record<string, string>;
46
+ };
47
+ };
48
+ export type GuideRecordingNetworkSanitizer = (data: GuideRecordingNetworkData) => GuideRecordingNetworkData | null;
49
+ type NetworkCaptureOptions = {
50
+ sanitizer?: GuideRecordingNetworkSanitizer;
51
+ };
52
+ /**
53
+ * Supply this result as networkCapture BEFORE constructing a Guide-owned Browser.
54
+ * Browser captures the sanitizer in its constructor. This cannot retrofit an
55
+ * external recorder, and it does not initialize or enable recording/analytics.
56
+ */
57
+ export declare function createGuideRecordingNetworkCapture<T extends object = NetworkCaptureOptions>(input: {
58
+ runtimeUrl: string;
59
+ pageUrl: string;
60
+ networkCapture?: T & NetworkCaptureOptions;
61
+ }): T & {
62
+ sanitizer: GuideRecordingNetworkSanitizer;
63
+ };
64
+ export {};
@@ -0,0 +1,176 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.observeGuideRecording = observeGuideRecording;
4
+ exports.createGuideRecordingNetworkCapture = createGuideRecordingNetworkCapture;
5
+ const recordingHubs = new WeakMap();
6
+ const MAX_REPLAY_SESSION_ID = 9223372036854775807n;
7
+ function replaySessionId(value) {
8
+ const text = typeof value === "string"
9
+ ? value
10
+ : typeof value === "number" && Number.isSafeInteger(value)
11
+ ? String(value)
12
+ : "";
13
+ return /^[1-9][0-9]{0,18}$/.test(text) &&
14
+ BigInt(text) <= MAX_REPLAY_SESSION_ID
15
+ ? text
16
+ : null;
17
+ }
18
+ function currentLink(source, projectId) {
19
+ try {
20
+ if (!source.active())
21
+ return null;
22
+ const metadata = source.getSessionMeta();
23
+ if (metadata?.projectID !== projectId &&
24
+ metadata?.projectID !== String(projectId)) {
25
+ return null;
26
+ }
27
+ const sessionId = replaySessionId(metadata.sessionID);
28
+ if (!sessionId)
29
+ return null;
30
+ const grant = source.getAssistSessionGrant();
31
+ if (replaySessionId(grant?.sessionId) !== sessionId ||
32
+ typeof grant?.token !== "string" ||
33
+ grant.token.length < 1 ||
34
+ grant.token.length > 4096 ||
35
+ /\s/.test(grant.token)) {
36
+ return null;
37
+ }
38
+ const tabId = source.session.getTabId();
39
+ if (typeof tabId !== "string" || !/^[A-Za-z0-9_.:-]{8,128}$/.test(tabId)) {
40
+ return null;
41
+ }
42
+ return Object.freeze({ sessionId, token: grant.token, tabId });
43
+ }
44
+ catch {
45
+ // Recorder failures must not produce a fabricated link or disclose a grant.
46
+ return null;
47
+ }
48
+ }
49
+ function recordingHub(source) {
50
+ const existing = recordingHubs.get(source);
51
+ if (existing)
52
+ return existing;
53
+ const hub = { listeners: new Set() };
54
+ let refreshPending = false;
55
+ const scheduleRefresh = () => {
56
+ if (refreshPending || hub.listeners.size === 0)
57
+ return;
58
+ refreshPending = true;
59
+ // App invokes callbacks before flipping its activity state. Its API has no
60
+ // detach operation, so share one inert-when-unused callback pair per source.
61
+ void Promise.resolve().then(() => {
62
+ refreshPending = false;
63
+ for (const refresh of [...hub.listeners]) {
64
+ if (hub.listeners.has(refresh))
65
+ refresh();
66
+ }
67
+ });
68
+ };
69
+ source.attachStartCallback(scheduleRefresh);
70
+ source.attachStopCallback(scheduleRefresh);
71
+ recordingHubs.set(source, hub);
72
+ return hub;
73
+ }
74
+ function sameLink(left, right) {
75
+ return (left?.sessionId === right?.sessionId &&
76
+ left?.token === right?.token &&
77
+ left?.tabId === right?.tabId);
78
+ }
79
+ /** Observe only an explicitly supplied recorder; never discover, start or stop one. */
80
+ function observeGuideRecording(source, input) {
81
+ const { projectId } = input;
82
+ if (!Number.isSafeInteger(projectId) || projectId <= 0) {
83
+ throw new Error("Invalid AI Guide recording workspace.");
84
+ }
85
+ let disposed = false;
86
+ const subscriptions = new Set();
87
+ const getCurrentLink = () => disposed ? null : currentLink(source, projectId);
88
+ return Object.freeze({
89
+ getCurrentLink,
90
+ subscribeLinkChange(listener) {
91
+ if (disposed)
92
+ return () => undefined;
93
+ const hub = recordingHub(source);
94
+ let previous = getCurrentLink();
95
+ const notify = (link) => {
96
+ try {
97
+ listener(link);
98
+ }
99
+ catch {
100
+ // Do not leak credentials through recorder debug/error callbacks.
101
+ }
102
+ };
103
+ const refresh = () => {
104
+ const next = getCurrentLink();
105
+ if (sameLink(previous, next))
106
+ return;
107
+ previous = next;
108
+ notify(next);
109
+ };
110
+ const unsubscribe = () => {
111
+ hub.listeners.delete(refresh);
112
+ subscriptions.delete(unsubscribe);
113
+ previous = null;
114
+ };
115
+ subscriptions.add(unsubscribe);
116
+ hub.listeners.add(refresh);
117
+ notify(previous);
118
+ return unsubscribe;
119
+ },
120
+ dispose() {
121
+ disposed = true;
122
+ for (const unsubscribe of subscriptions)
123
+ unsubscribe();
124
+ },
125
+ });
126
+ }
127
+ /**
128
+ * Supply this result as networkCapture BEFORE constructing a Guide-owned Browser.
129
+ * Browser captures the sanitizer in its constructor. This cannot retrofit an
130
+ * external recorder, and it does not initialize or enable recording/analytics.
131
+ */
132
+ function createGuideRecordingNetworkCapture(input) {
133
+ let page;
134
+ let runtime;
135
+ try {
136
+ page = new URL(input.pageUrl);
137
+ runtime = new URL(input.runtimeUrl, page);
138
+ if (!["http:", "https:"].includes(page.protocol) ||
139
+ !["http:", "https:"].includes(runtime.protocol) ||
140
+ runtime.username ||
141
+ runtime.password ||
142
+ runtime.search ||
143
+ runtime.hash) {
144
+ throw new Error();
145
+ }
146
+ }
147
+ catch {
148
+ throw new Error("Invalid AI Guide recording privacy configuration.");
149
+ }
150
+ const excluded = (value) => {
151
+ try {
152
+ const url = new URL(value, page);
153
+ const path = decodeURIComponent(url.pathname);
154
+ // The namespace guard also protects runtime-returned URLs on another
155
+ // allowed host. Do not rely on recorder ingest-origin filtering.
156
+ return (!["http:", "https:"].includes(url.protocol) ||
157
+ /(?:^|\/)ai-live-assist(?:\/|$)/i.test(path));
158
+ }
159
+ catch {
160
+ return true;
161
+ }
162
+ };
163
+ const existing = input.networkCapture?.sanitizer;
164
+ const sanitizer = (data) => {
165
+ if (excluded(data.url))
166
+ return null;
167
+ try {
168
+ const sanitized = existing ? existing(data) : data;
169
+ return sanitized && !excluded(sanitized.url) ? sanitized : null;
170
+ }
171
+ catch {
172
+ return null;
173
+ }
174
+ };
175
+ return { ...input.networkCapture, sanitizer };
176
+ }
@@ -0,0 +1,35 @@
1
+ import type { RuntimeClient } from "./client.js";
2
+ import type { GuideIdentity } from "./guideTypes.js";
3
+ import type { GuideSubjectStore } from "./guideSubjectStore.js";
4
+ import type { GuideRecordingObserver } from "./guideRecording.js";
5
+ export type GuideRecordingStatus = "off" | "starting" | "recording" | "linked" | "unavailable";
6
+ export type GuideRecordingAdapter = {
7
+ start(): Promise<GuideRecordingObserver>;
8
+ stop(): void;
9
+ dispose(): void;
10
+ report(status: GuideRecordingStatus): void;
11
+ };
12
+ export type GuideRecordingFactory = (identity: GuideIdentity, runtimeUrl: string) => GuideRecordingAdapter;
13
+ /** Optional recording has its own lifecycle and never supplies Guide admission. */
14
+ export declare class GuideRecordingSession {
15
+ private readonly identity;
16
+ private readonly store;
17
+ private readonly runtime;
18
+ private readonly adapter;
19
+ private observer;
20
+ private unsubscribe;
21
+ private starting;
22
+ private consented;
23
+ private destroyed;
24
+ private session;
25
+ private linkController;
26
+ private lastAttempt;
27
+ private generation;
28
+ constructor(identity: GuideIdentity, store: GuideSubjectStore, runtime: RuntimeClient, adapter: GuideRecordingAdapter);
29
+ applyConsent(consented: boolean): void;
30
+ bindSession(sessionId: string, tabId: string): void;
31
+ endSession(): void;
32
+ destroy(): void;
33
+ private start;
34
+ private link;
35
+ }
@@ -0,0 +1,167 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.GuideRecordingSession = void 0;
4
+ /** Optional recording has its own lifecycle and never supplies Guide admission. */
5
+ class GuideRecordingSession {
6
+ constructor(identity, store, runtime, adapter) {
7
+ this.identity = identity;
8
+ this.store = store;
9
+ this.runtime = runtime;
10
+ this.adapter = adapter;
11
+ this.observer = null;
12
+ this.unsubscribe = null;
13
+ this.starting = null;
14
+ this.consented = false;
15
+ this.destroyed = false;
16
+ this.session = null;
17
+ this.linkController = null;
18
+ this.lastAttempt = null;
19
+ this.generation = 0;
20
+ }
21
+ applyConsent(consented) {
22
+ if (this.destroyed || consented === this.consented)
23
+ return;
24
+ this.consented = consented;
25
+ this.generation += 1;
26
+ if (!consented) {
27
+ this.linkController?.abort();
28
+ this.linkController = null;
29
+ this.lastAttempt = null;
30
+ this.unsubscribe?.();
31
+ this.unsubscribe = null;
32
+ this.observer?.dispose();
33
+ this.observer = null;
34
+ this.adapter.stop();
35
+ this.adapter.report("off");
36
+ return;
37
+ }
38
+ this.start();
39
+ }
40
+ bindSession(sessionId, tabId) {
41
+ if (this.destroyed)
42
+ return;
43
+ if (this.session?.sessionId !== sessionId ||
44
+ this.session?.tabId !== tabId) {
45
+ this.linkController?.abort();
46
+ this.linkController = null;
47
+ this.lastAttempt = null;
48
+ }
49
+ this.session = { sessionId, tabId };
50
+ this.link(this.observer?.getCurrentLink() ?? null);
51
+ }
52
+ endSession() {
53
+ this.session = null;
54
+ this.lastAttempt = null;
55
+ this.linkController?.abort();
56
+ this.linkController = null;
57
+ // AI End is not revocation of independent browsing-recording consent.
58
+ }
59
+ destroy() {
60
+ this.destroyed = true;
61
+ this.generation += 1;
62
+ this.endSession();
63
+ this.unsubscribe?.();
64
+ this.unsubscribe = null;
65
+ this.observer?.dispose();
66
+ this.observer = null;
67
+ this.adapter.dispose();
68
+ }
69
+ start() {
70
+ if (this.starting || !this.consented || this.destroyed)
71
+ return;
72
+ const generation = this.generation;
73
+ this.adapter.report("starting");
74
+ const starting = this.adapter
75
+ .start()
76
+ .then((observer) => {
77
+ if (this.destroyed ||
78
+ !this.consented ||
79
+ generation !== this.generation) {
80
+ observer.dispose();
81
+ this.adapter.stop();
82
+ return;
83
+ }
84
+ this.observer = observer;
85
+ this.adapter.report("recording");
86
+ this.unsubscribe = observer.subscribeLinkChange((link) => this.link(link));
87
+ })
88
+ .catch(() => {
89
+ if (!this.destroyed && this.consented && generation === this.generation)
90
+ this.adapter.report("unavailable");
91
+ })
92
+ .finally(() => {
93
+ if (this.starting === starting)
94
+ this.starting = null;
95
+ // A new explicit grant can arrive while a revoked startup settles.
96
+ // Retry only that newer choice, never an unchanged failed start.
97
+ if (generation !== this.generation && this.consented && !this.destroyed)
98
+ this.start();
99
+ });
100
+ this.starting = starting;
101
+ }
102
+ link(link) {
103
+ const session = this.session;
104
+ if (!link || !session || !this.consented || this.destroyed)
105
+ return;
106
+ const previous = this.lastAttempt;
107
+ if (previous?.sessionId === session.sessionId &&
108
+ previous.replaySessionId === link.sessionId &&
109
+ previous.grant === link.token)
110
+ return;
111
+ let credential;
112
+ try {
113
+ credential = this.store.readSubject()?.credential;
114
+ }
115
+ catch {
116
+ /* fail closed below */
117
+ }
118
+ if (!credential) {
119
+ this.adapter.report("unavailable");
120
+ return;
121
+ }
122
+ this.linkController?.abort();
123
+ const controller = new AbortController();
124
+ this.linkController = controller;
125
+ this.lastAttempt = {
126
+ sessionId: session.sessionId,
127
+ replaySessionId: link.sessionId,
128
+ grant: link.token,
129
+ };
130
+ const timeout = setTimeout(() => controller.abort(), 10000);
131
+ void this.runtime
132
+ .linkGuideRecording(session.sessionId, {
133
+ schemaVersion: 3,
134
+ installKey: this.identity.installKey,
135
+ subjectCredential: credential,
136
+ tabId: session.tabId,
137
+ replaySessionId: link.sessionId,
138
+ replayGrant: link.token,
139
+ }, controller.signal)
140
+ .then((result) => {
141
+ if (controller.signal.aborted ||
142
+ this.linkController !== controller ||
143
+ !this.consented ||
144
+ this.destroyed)
145
+ return;
146
+ if (!result ||
147
+ result.schemaVersion !== 3 ||
148
+ result.linked !== true ||
149
+ result.sessionId !== session.sessionId ||
150
+ result.replaySessionId !== link.sessionId)
151
+ throw new Error("Invalid recording link.");
152
+ this.adapter.report("linked");
153
+ })
154
+ .catch(() => {
155
+ if (!this.destroyed &&
156
+ this.consented &&
157
+ this.linkController === controller)
158
+ this.adapter.report("unavailable");
159
+ })
160
+ .finally(() => {
161
+ clearTimeout(timeout);
162
+ if (this.linkController === controller)
163
+ this.linkController = null;
164
+ });
165
+ }
166
+ }
167
+ exports.GuideRecordingSession = GuideRecordingSession;