@salesforce/metadata-core-sdk 1.7.0 → 1.9.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 (59) hide show
  1. package/README.md +61 -1
  2. package/dist/index.d.ts +6 -2
  3. package/dist/index.d.ts.map +1 -1
  4. package/dist/index.js +8 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.d.ts +34 -0
  7. package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.d.ts.map +1 -0
  8. package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.js +64 -0
  9. package/dist/sdk/hooks/vibe-edit/selection/selectionTelemetry.js.map +1 -0
  10. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.css +5 -0
  11. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.d.ts.map +1 -1
  12. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.js +39 -2
  13. package/dist/sdk/hooks/vibe-edit/ui/MarqueeSelection.js.map +1 -1
  14. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts +5 -0
  15. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.d.ts.map +1 -1
  16. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js +9 -7
  17. package/dist/sdk/hooks/vibe-edit/ui/VibeEditPanel.js.map +1 -1
  18. package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.css +460 -0
  19. package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.d.ts +71 -0
  20. package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.d.ts.map +1 -0
  21. package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.js +461 -0
  22. package/dist/sdk/hooks/vibe-edit/ui/composer/VibeEditComposer.js.map +1 -0
  23. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.d.ts +19 -0
  24. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.d.ts.map +1 -0
  25. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.js +23 -0
  26. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.js.map +1 -0
  27. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.test.d.ts +8 -0
  28. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.test.d.ts.map +1 -0
  29. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.test.js +33 -0
  30. package/dist/sdk/hooks/vibe-edit/ui/composer/composerPlacement.test.js.map +1 -0
  31. package/dist/sdk/hooks/vibe-edit/ui/composer/iconPaths.d.ts +12 -0
  32. package/dist/sdk/hooks/vibe-edit/ui/composer/iconPaths.d.ts.map +1 -0
  33. package/dist/sdk/hooks/vibe-edit/ui/composer/iconPaths.js +29 -0
  34. package/dist/sdk/hooks/vibe-edit/ui/composer/iconPaths.js.map +1 -0
  35. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.d.ts +10 -0
  36. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.d.ts.map +1 -1
  37. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js +279 -23
  38. package/dist/sdk/hooks/vibe-edit/ui/useVibeEdit.js.map +1 -1
  39. package/dist/sdk/utils/HostCommunicationUtils.d.ts +41 -1
  40. package/dist/sdk/utils/HostCommunicationUtils.d.ts.map +1 -1
  41. package/dist/sdk/utils/HostCommunicationUtils.js +115 -20
  42. package/dist/sdk/utils/HostCommunicationUtils.js.map +1 -1
  43. package/dist/sdk/utils/telemetry/telemetryBuffer.d.ts +54 -0
  44. package/dist/sdk/utils/telemetry/telemetryBuffer.d.ts.map +1 -0
  45. package/dist/sdk/utils/telemetry/telemetryBuffer.js +163 -0
  46. package/dist/sdk/utils/telemetry/telemetryBuffer.js.map +1 -0
  47. package/dist/sdk/utils/telemetry/telemetryEvents.d.ts +60 -0
  48. package/dist/sdk/utils/telemetry/telemetryEvents.d.ts.map +1 -0
  49. package/dist/sdk/utils/telemetry/telemetryEvents.js +243 -0
  50. package/dist/sdk/utils/telemetry/telemetryEvents.js.map +1 -0
  51. package/dist/sdk/utils/telemetry/telemetryRelay.d.ts +63 -0
  52. package/dist/sdk/utils/telemetry/telemetryRelay.d.ts.map +1 -0
  53. package/dist/sdk/utils/telemetry/telemetryRelay.js +64 -0
  54. package/dist/sdk/utils/telemetry/telemetryRelay.js.map +1 -0
  55. package/dist/sdk/webviewMessageTypes.d.ts +51 -7
  56. package/dist/sdk/webviewMessageTypes.d.ts.map +1 -1
  57. package/dist/sdk/webviewMessageTypes.js +10 -0
  58. package/dist/sdk/webviewMessageTypes.js.map +1 -1
  59. package/package.json +1 -1
@@ -4,9 +4,24 @@
4
4
  * Licensed under the BSD 3-Clause license.
5
5
  * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
6
  **/
7
- import { WebviewMessageType } from '../webviewMessageTypes.js';
7
+ import { WebviewMessageType, } from '../webviewMessageTypes.js';
8
8
  /** Single-flight guard: one in-flight getPluginData request at a time. */
9
9
  let inFlightPluginDataRequest = null;
10
+ /**
11
+ * True when the plugin iframe is running inside the VS Code extension host.
12
+ *
13
+ * The VS Code webview bootstrap installs `window.getHostApi` (its
14
+ * `acquireVsCodeApi()` wrapper) before plugin code loads; browser hosts (the web
15
+ * adapter, App Studio / Builder Central) never define it — they provide only
16
+ * `__ExtensionHostPostMessage`. The vibe-edit hook uses this to render the new
17
+ * composer UI ONLY in VS Code and keep the classic panel on the web — and,
18
+ * because the composer is lazily imported behind this gate, to keep it out of
19
+ * the web bundles entirely. SSR/eval-safe: false when there
20
+ * is no `window`.
21
+ */
22
+ export function isVsCodeHost() {
23
+ return typeof window !== 'undefined' && typeof window.getHostApi === 'function';
24
+ }
10
25
  /**
11
26
  * Browser hosts do not install an expected id, so correlation is intentionally
12
27
  * a no-op there. VS Code installs an immutable id in its page bootstrap.
@@ -15,22 +30,20 @@ function matchesExpectedRender(message) {
15
30
  const expectedRenderId = window.__ExtensionHostExpectedRenderId;
16
31
  return expectedRenderId === undefined || message.renderId === expectedRenderId;
17
32
  }
33
+ /** Logs a send failure unless the caller asked for a silent send. */
34
+ function logSendError(quiet, ...args) {
35
+ if (!quiet) {
36
+ // eslint-disable-next-line no-console
37
+ console.error(...args);
38
+ }
39
+ }
18
40
  /**
19
- * Send a message to the host via the platform-agnostic postMessage function.
20
- * Platform implementations provide window.__ExtensionHostPostMessage (e.g., VS Code via vscodeHostApiBootstrap).
21
- *
22
- * Fallback strategy:
23
- * 1. Try window.__ExtensionHostPostMessage (primary platform channel)
24
- * 2. If unavailable, try window.parent.postMessage (iframe fallback)
25
- * 3. If both fail, log error and return false
26
- *
27
- * @param message Message to send to host
28
- * @returns true if sent successfully, false if no communication channel available
41
+ * Channel logic shared by {@link sendToHost} (logs failures) and the telemetry
42
+ * sender (`quiet`, never logs). Behavior is identical apart from the logging.
29
43
  */
30
- export function sendToHost(message) {
44
+ function postToHost(message, quiet) {
31
45
  if (typeof window === 'undefined') {
32
- // eslint-disable-next-line no-console
33
- console.error('[sendToHost] Not in browser context');
46
+ logSendError(quiet, '[sendToHost] Not in browser context');
34
47
  return false;
35
48
  }
36
49
  // Primary: Try platform-provided __ExtensionHostPostMessage
@@ -40,8 +53,7 @@ export function sendToHost(message) {
40
53
  return true;
41
54
  }
42
55
  catch (error) {
43
- // eslint-disable-next-line no-console
44
- console.error('[sendToHost] Error sending via __ExtensionHostPostMessage:', error);
56
+ logSendError(quiet, '[sendToHost] Error sending via __ExtensionHostPostMessage:', error);
45
57
  // Fall through to try window.parent
46
58
  }
47
59
  }
@@ -55,14 +67,97 @@ export function sendToHost(message) {
55
67
  return true;
56
68
  }
57
69
  catch (error) {
58
- // eslint-disable-next-line no-console
59
- console.error('[sendToHost] Error sending via window.parent:', error);
70
+ logSendError(quiet, '[sendToHost] Error sending via window.parent:', error);
60
71
  }
61
72
  }
62
- // eslint-disable-next-line no-console
63
- console.error('[sendToHost] No host communication channel available');
73
+ logSendError(quiet, '[sendToHost] No host communication channel available');
64
74
  return false;
65
75
  }
76
+ /**
77
+ * Send a message to the host via the platform-agnostic postMessage function.
78
+ * Platform implementations provide window.__ExtensionHostPostMessage (e.g., VS Code via vscodeHostApiBootstrap).
79
+ *
80
+ * Fallback strategy:
81
+ * 1. Try window.__ExtensionHostPostMessage (primary platform channel)
82
+ * 2. If unavailable, try window.parent.postMessage (iframe fallback)
83
+ * 3. If both fail, log error and return false
84
+ *
85
+ * @param message Message to send to host
86
+ * @returns true if sent successfully, false if no communication channel available
87
+ */
88
+ export function sendToHost(message) {
89
+ return postToHost(message, false);
90
+ }
91
+ /**
92
+ * Send a TELEMETRY_EVENT to the host through the same channels as
93
+ * {@link sendToHost}, but silently: it never throws and never logs, because
94
+ * telemetry is fire-and-forget and the web e2e gate fails on console errors.
95
+ *
96
+ * Internal to core-sdk. Deliberately not re-exported from the package barrel;
97
+ * the shared vibe edit hook emits events, and hosts receive them through
98
+ * `relayTelemetryEvent`.
99
+ *
100
+ * @returns true if a channel accepted the message, false otherwise
101
+ */
102
+ export function sendTelemetryToHost(payload) {
103
+ try {
104
+ return postToHost({ type: WebviewMessageType.TELEMETRY_EVENT, payload }, true);
105
+ }
106
+ catch {
107
+ return false;
108
+ }
109
+ }
110
+ /**
111
+ * Submit an edit to the VS Code host and wait for its handoff acknowledgement.
112
+ * Browser hosts retain the existing send-only protocol and must not call this.
113
+ */
114
+ export function submitEditToHost(request) {
115
+ if (!isVsCodeHost() || typeof window.__ExtensionHostPostMessage !== 'function') {
116
+ return Promise.reject(new Error('vibe-edit: acknowledged submission is only available in VS Code'));
117
+ }
118
+ const requestId = globalThis.crypto?.randomUUID?.() ?? `${Date.now()}-${Math.random()}`;
119
+ return new Promise((resolve, reject) => {
120
+ const timeoutId = window.setTimeout(() => {
121
+ cleanup();
122
+ reject(new Error('vibe-edit: host acknowledgement timed out; the edit may still be pending'));
123
+ }, 120000);
124
+ const cleanup = () => {
125
+ clearTimeout(timeoutId);
126
+ window.removeEventListener('message', onMessage);
127
+ };
128
+ const onMessage = (event) => {
129
+ if (!isTrustedHostMessage(event)) {
130
+ return;
131
+ }
132
+ const message = event.data;
133
+ const payload = message.payload;
134
+ if (message.type !== WebviewMessageType.SUBMIT_EDIT_RESULT ||
135
+ !matchesExpectedRender(message) ||
136
+ payload?.requestId !== requestId) {
137
+ return;
138
+ }
139
+ cleanup();
140
+ if (payload.result.delivered) {
141
+ resolve(payload);
142
+ }
143
+ else {
144
+ reject(new Error(payload.result.detail ?? 'vibe-edit: host did not deliver the edit'));
145
+ }
146
+ };
147
+ window.addEventListener('message', onMessage);
148
+ try {
149
+ window.__ExtensionHostPostMessage({
150
+ type: WebviewMessageType.SUBMIT_EDIT,
151
+ payload: request,
152
+ requestId,
153
+ });
154
+ }
155
+ catch (error) {
156
+ cleanup();
157
+ reject(error);
158
+ }
159
+ });
160
+ }
66
161
  /**
67
162
  * Request plugin data from the host via message passing.
68
163
  * Platform-agnostic implementation using window.__ExtensionHostPostMessage.
@@ -1 +1 @@
1
- {"version":3,"file":"HostCommunicationUtils.js","sourceRoot":"","sources":["../../../src/sdk/utils/HostCommunicationUtils.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ,OAAO,EAAE,kBAAkB,EAAsC,MAAM,2BAA2B,CAAC;AAEnG,0EAA0E;AAC1E,IAAI,yBAAyB,GAA8C,IAAI,CAAC;AAchF;;;GAGG;AACH,SAAS,qBAAqB,CAAC,OAAuB;IACpD,MAAM,gBAAgB,GAAG,MAAM,CAAC,+BAA+B,CAAC;IAChE,OAAO,gBAAgB,KAAK,SAAS,IAAI,OAAO,CAAC,QAAQ,KAAK,gBAAgB,CAAC;AACjF,CAAC;AAED;;;;;;;;;;;GAWG;AACH,MAAM,UAAU,UAAU,CAAC,OAAuB;IAChD,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QAClC,sCAAsC;QACtC,OAAO,CAAC,KAAK,CAAC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MAAM,CAAC,MAAM,KAAK,MAAM,EAAE,CAAC;QAC7B,yEAAyE;QACzE,yEAAyE;QACzE,oEAAoE;QACpE,0EAA0E;QAC1E,uEAAuE;QACvE,sEAAsE;QACtE,MAAM,IAAI,GAAI,KAAK,CAAC,MAAqD,EAAE,WAAW,EAAE,IAAI,CAAC;QAC7F,IAAI,IAAI,KAAK,QAAQ,EAAE,CAAC;YACtB,OAAO,IAAI,CAAC;QACd,CAAC;IACH,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AACH,MAAM,UAAU,YAAY,CAAC,QAA4C;IACvE,MAAM,cAAc,GAAG,CAAC,KAAmB,EAAE,EAAE;QAC7C,IAAI,CAAC,oBAAoB,CAAC,KAAK,CAAC,EAAE,CAAC;YACjC,OAAO;QACT,CAAC;QACD,MAAM,OAAO,GAAG,KAAK,CAAC,IAAsB,CAAC;QAC7C,IAAI,OAAO,CAAC,IAAI,KAAK,kBAAkB,CAAC,kBAAkB,IAAI,qBAAqB,CAAC,OAAO,CAAC,EAAE,CAAC;YAC7F,MAAM,OAAO,GAAG,OAAO,CAAC,OAA6B,CAAC;YACtD,QAAQ,CAAC,OAAO,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,CAAC,gBAAgB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IAEnD,8BAA8B;IAC9B,OAAO,GAAG,EAAE;QACV,MAAM,CAAC,mBAAmB,CAAC,SAAS,EAAE,cAAc,CAAC,CAAC;IACxD,CAAC,CAAC;AACJ,CAAC"}
@@ -0,0 +1,54 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ import { type TelemetryEventName, type TelemetryEventPayload } from './telemetryEvents.js';
8
+ /** The slice of `window` / `document` the page-lifecycle flush needs. */
9
+ interface LifecycleTarget {
10
+ addEventListener(type: string, listener: () => void): void;
11
+ }
12
+ interface LifecycleDocument extends LifecycleTarget {
13
+ visibilityState?: string;
14
+ }
15
+ export declare class TelemetryBuffer {
16
+ private readonly send;
17
+ private readonly flushDelayMs;
18
+ private readonly buckets;
19
+ private lifecycleAttached;
20
+ private flushTimer;
21
+ /**
22
+ * @param send Delivers one validated-shape payload (never throws into the buffer).
23
+ * @param flushDelayMs When above 0, pending counts are flushed this long after
24
+ * the first `add`. 0 (the default) leaves flushing to the explicit triggers.
25
+ */
26
+ constructor(send: (payload: TelemetryEventPayload) => void, flushDelayMs?: number);
27
+ /**
28
+ * Add `n` to the bucket for (name, properties). Counts cap at
29
+ * `MAX_TELEMETRY_COUNT`, the largest value the host validator accepts.
30
+ */
31
+ add(name: TelemetryEventName, properties: Record<string, string>, n?: number): void;
32
+ /**
33
+ * Emit one message per non-zero bucket, then clear. With a `name`, only that
34
+ * event's buckets are flushed. A second flush with no new `add` sends nothing.
35
+ */
36
+ flush(name?: TelemetryEventName): void;
37
+ /** Send one event immediately, without aggregation (select-mode transitions, abandon). */
38
+ emitNow(name: TelemetryEventName, properties: Record<string, string>, measurements?: Record<string, number>): void;
39
+ /**
40
+ * Flush on `pagehide` and on `visibilitychange` to hidden. Idempotent per
41
+ * buffer, and a no-op where there is no `window` / `document`.
42
+ */
43
+ attachPageLifecycle(win?: LifecycleTarget, doc?: LifecycleDocument): void;
44
+ private scheduleFlush;
45
+ private cancelScheduledFlush;
46
+ private dispatch;
47
+ }
48
+ /**
49
+ * The shared buffer wired to the silent host sender. Created on first use, which
50
+ * is also when the page-lifecycle listeners are installed (once).
51
+ */
52
+ export declare function getTelemetryBuffer(): TelemetryBuffer;
53
+ export {};
54
+ //# sourceMappingURL=telemetryBuffer.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryBuffer.d.ts","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/tel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;AACH,wBAAgB,kBAAkB,IAAI,eAAe,CASpD"}
@@ -0,0 +1,163 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * Iframe-side telemetry buffer: aggregate counts in memory, then flush one
9
+ * TELEMETRY_EVENT per non-zero bucket.
10
+ *
11
+ * Counts are flushed on `pagehide`, on `visibilitychange` to hidden, when the
12
+ * vibe-edit hook asks for it (leaving select mode), and a short time after the
13
+ * first pending count. The timer matters because a host can replace the iframe
14
+ * and stamp the next render before the old page's `pagehide` flush arrives, and
15
+ * the host drops messages from a superseded render. React unmount cleanup is not
16
+ * relied on: a host removes the iframe without running it.
17
+ *
18
+ * Fire-and-forget: nothing here throws, logs, retries or blocks the UI.
19
+ */
20
+ import { sendTelemetryToHost } from '../HostCommunicationUtils.js';
21
+ import { MAX_TELEMETRY_COUNT, TELEMETRY_SCHEMA_VERSION, } from './telemetryEvents.js';
22
+ function bucketKey(name, properties) {
23
+ const parts = Object.keys(properties)
24
+ .sort()
25
+ .map((key) => `${key}=${properties[key]}`);
26
+ return `${name}|${parts.join('&')}`;
27
+ }
28
+ /** How long a count may sit in the default buffer before it is flushed on its own. */
29
+ const DEFAULT_FLUSH_DELAY_MS = 20000;
30
+ export class TelemetryBuffer {
31
+ /**
32
+ * @param send Delivers one validated-shape payload (never throws into the buffer).
33
+ * @param flushDelayMs When above 0, pending counts are flushed this long after
34
+ * the first `add`. 0 (the default) leaves flushing to the explicit triggers.
35
+ */
36
+ constructor(send, flushDelayMs = 0) {
37
+ this.send = send;
38
+ this.flushDelayMs = flushDelayMs;
39
+ this.buckets = new Map();
40
+ this.lifecycleAttached = false;
41
+ }
42
+ /**
43
+ * Add `n` to the bucket for (name, properties). Counts cap at
44
+ * `MAX_TELEMETRY_COUNT`, the largest value the host validator accepts.
45
+ */
46
+ add(name, properties, n = 1) {
47
+ const increment = Math.floor(n);
48
+ if (!Number.isFinite(increment) || increment <= 0) {
49
+ return;
50
+ }
51
+ this.scheduleFlush();
52
+ const key = bucketKey(name, properties);
53
+ const bucket = this.buckets.get(key);
54
+ if (bucket) {
55
+ bucket.count = Math.min(MAX_TELEMETRY_COUNT, bucket.count + increment);
56
+ }
57
+ else {
58
+ this.buckets.set(key, {
59
+ name,
60
+ properties: { ...properties },
61
+ count: Math.min(MAX_TELEMETRY_COUNT, increment),
62
+ });
63
+ }
64
+ }
65
+ /**
66
+ * Emit one message per non-zero bucket, then clear. With a `name`, only that
67
+ * event's buckets are flushed. A second flush with no new `add` sends nothing.
68
+ */
69
+ flush(name) {
70
+ if (name === undefined) {
71
+ this.cancelScheduledFlush();
72
+ }
73
+ const flushed = [];
74
+ for (const [key, bucket] of this.buckets) {
75
+ if (name === undefined || bucket.name === name) {
76
+ flushed.push(bucket);
77
+ this.buckets.delete(key);
78
+ }
79
+ }
80
+ for (const bucket of flushed) {
81
+ this.dispatch({
82
+ schemaVersion: TELEMETRY_SCHEMA_VERSION,
83
+ name: bucket.name,
84
+ properties: bucket.properties,
85
+ measurements: { count: bucket.count },
86
+ });
87
+ }
88
+ }
89
+ /** Send one event immediately, without aggregation (select-mode transitions, abandon). */
90
+ emitNow(name, properties, measurements = {}) {
91
+ this.dispatch({
92
+ schemaVersion: TELEMETRY_SCHEMA_VERSION,
93
+ name,
94
+ properties: { ...properties },
95
+ measurements: { ...measurements },
96
+ });
97
+ }
98
+ /**
99
+ * Flush on `pagehide` and on `visibilitychange` to hidden. Idempotent per
100
+ * buffer, and a no-op where there is no `window` / `document`.
101
+ */
102
+ attachPageLifecycle(win, doc) {
103
+ if (this.lifecycleAttached) {
104
+ return;
105
+ }
106
+ this.lifecycleAttached = true;
107
+ try {
108
+ win?.addEventListener('pagehide', () => this.flush());
109
+ doc?.addEventListener('visibilitychange', () => {
110
+ if (doc.visibilityState === 'hidden') {
111
+ this.flush();
112
+ }
113
+ });
114
+ }
115
+ catch {
116
+ // Telemetry must never break the page.
117
+ }
118
+ }
119
+ scheduleFlush() {
120
+ if (this.flushDelayMs <= 0 || this.flushTimer !== undefined) {
121
+ return;
122
+ }
123
+ try {
124
+ const timer = setTimeout(() => {
125
+ this.flushTimer = undefined;
126
+ this.flush();
127
+ }, this.flushDelayMs);
128
+ // Never keep a Node process (tests, SSR) alive for telemetry.
129
+ timer.unref?.();
130
+ this.flushTimer = timer;
131
+ }
132
+ catch {
133
+ // Telemetry must never break the page.
134
+ }
135
+ }
136
+ cancelScheduledFlush() {
137
+ if (this.flushTimer !== undefined) {
138
+ clearTimeout(this.flushTimer);
139
+ this.flushTimer = undefined;
140
+ }
141
+ }
142
+ dispatch(payload) {
143
+ try {
144
+ this.send(payload);
145
+ }
146
+ catch {
147
+ // Fire and forget.
148
+ }
149
+ }
150
+ }
151
+ let defaultBuffer;
152
+ /**
153
+ * The shared buffer wired to the silent host sender. Created on first use, which
154
+ * is also when the page-lifecycle listeners are installed (once).
155
+ */
156
+ export function getTelemetryBuffer() {
157
+ if (!defaultBuffer) {
158
+ defaultBuffer = new TelemetryBuffer(sendTelemetryToHost, DEFAULT_FLUSH_DELAY_MS);
159
+ defaultBuffer.attachPageLifecycle(typeof window === 'undefined' ? undefined : window, typeof document === 'undefined' ? undefined : document);
160
+ }
161
+ return defaultBuffer;
162
+ }
163
+ //# sourceMappingURL=telemetryBuffer.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryBuffer.js","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryBuffer.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;;;GAYG;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,8BAA8B,CAAC;AACnE,OAAO,EACL,mBAAmB,EACnB,wBAAwB,GAGzB,MAAM,sBAAsB,CAAC;AAgB9B,SAAS,SAAS,CAAC,IAAY,EAAE,UAAkC;IACjE,MAAM,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C,MAAM,CAAC;YACP,mBAAmB;QACrB,CAAC;IACH,CAAC;CACF;AAED,IAAI,aAA0C,CAAC;AAE/C;;;GAGG;AACH,MAAM,UAAU,kBAAkB;IAChC,IAAI,CAAC,aAAa,EAAE,CAAC;QACnB,aAAa,GAAG,IAAI,eAAe,CAAC,mBAAmB,EAAE,sBAAsB,CAAC,CAAC;QACjF,aAAa,CAAC,mBAAmB,CAC/B,OAAO,MAAM,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,MAAM,EAClD,OAAO,QAAQ,KAAK,WAAW,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC,CAAC,QAAQ,CACvD,CAAC;IACJ,CAAC;IACD,OAAO,aAAa,CAAC;AACvB,CAAC"}
@@ -0,0 +1,60 @@
1
+ /**
2
+ * Copyright (c) 2026, Salesforce, Inc.
3
+ * All rights reserved.
4
+ * Licensed under the BSD 3-Clause license.
5
+ * For full license text, see LICENSE.txt file in the repo root or https://opensource.org/licenses/BSD-3-Clause
6
+ **/
7
+ /**
8
+ * Schema and strict validator for the iframe -> host TELEMETRY_EVENT message.
9
+ *
10
+ * The payload mirrors `ITelemetry.sendEvent(name, properties, measurements)` so a
11
+ * host can forward a validated event without reshaping it. Every property value
12
+ * comes from a closed list and every measurement is a bounded integer, so a
13
+ * payload can never carry free-form text (prompt text, api names, paths, ids).
14
+ *
15
+ * Node-safe on purpose: no React, no CSS, no `window`. This module is exported
16
+ * from the React-free main barrel and is imported by hosts.
17
+ */
18
+ export declare const TELEMETRY_SCHEMA_VERSION = 1;
19
+ export declare const TELEMETRY_EVENT_NAMES: readonly ["vibeEdit.selectMode", "vibeEdit.selection", "vibeEdit.promptAbandoned"];
20
+ export type TelemetryEventName = (typeof TELEMETRY_EVENT_NAMES)[number];
21
+ export declare const SELECT_MODE_ACTIONS: readonly ["enter", "exit"];
22
+ export type SelectModeAction = (typeof SELECT_MODE_ACTIONS)[number];
23
+ export declare const SELECTION_ACTIONS: readonly ["add", "remove"];
24
+ export type SelectionAction = (typeof SELECTION_ACTIONS)[number];
25
+ /**
26
+ * `SelectableNode.type` values emitted by the first-party plugins, plus the
27
+ * `'other'` fallback. Anything outside this list is bucketed to `'other'` by
28
+ * `toElementTypeBucket` (iframe side) and by `parseTelemetryEvent` (host side),
29
+ * so a third-party plugin's custom type, or a type added after this host shipped,
30
+ * is counted but never named.
31
+ *
32
+ * Keep in step with the plugins repo: Flow emits its `FlowNodeKind`, Permission
33
+ * set emits its named-access section keys, Agent emits the types below. Every
34
+ * entry adds up to two buckets per flush (add and remove), so the default of
35
+ * `TelemetryRateLimiter` must stay above `2 * SELECTION_ELEMENT_TYPES.length`.
36
+ */
37
+ export declare const SELECTION_ELEMENT_TYPES: readonly ["agent", "start-agent", "subagent", "topic", "system-instructions", "reasoning", "reasoning-action", "action", "action-target", "action-input", "action-output", "messages", "description", "heading", "step", "detail", "start", "screen", "apexAction", "apexPluginCall", "emailAction", "externalCallout", "routeWork", "addScreenPop", "addSkillRequirement", "checkAvailability", "setScreenProperty", "assignment", "addPromptInstructions", "decision", "loop", "recordCreate", "recordLookup", "recordUpdate", "recordDelete", "recordRollback", "subflow", "wait", "collectionProcessor", "collectionSort", "transform", "customError", "stage", "interactiveStep", "managedContentStep", "permissionset", "objectPermission", "fieldPermission", "recordTypeVisibility", "tabSetting", "apexClassAccesses", "pageAccesses", "flowAccesses", "agentAccesses", "customPermissions", "customMetadataTypeAccesses", "customSettingAccesses", "externalDataSourceAccesses", "externalCredentialPrincipalAccesses", "servicePresenceStatusAccesses", "emailRoutingAddressAccesses", "genComputingSummaryDefAccesses", "userPermissions", "applicationVisibilities", "object", "field", "region", "block", "dataProvider", "other"];
38
+ export type SelectionElementType = (typeof SELECTION_ELEMENT_TYPES)[number];
39
+ export declare const BOOLEAN_STRINGS: readonly ["true", "false"];
40
+ /** Upper bound for every count measurement. */
41
+ export declare const MAX_TELEMETRY_COUNT = 10000;
42
+ export interface TelemetryEventPayload {
43
+ schemaVersion: typeof TELEMETRY_SCHEMA_VERSION;
44
+ name: TelemetryEventName;
45
+ properties: Record<string, string>;
46
+ measurements: Record<string, number>;
47
+ }
48
+ /**
49
+ * Strict host-side check of an iframe TELEMETRY_EVENT payload. Returns a fresh,
50
+ * validated copy, or null. Nothing is coerced except a string `elementType`
51
+ * outside the closed list, which becomes `'other'` (the schema's `fallbacks`), so
52
+ * the copy still only holds closed-list values. Any other deviation from the
53
+ * schema (unknown name, extra or missing key, out-of-list value, non-string
54
+ * value, non-integer or out-of-range measurement) is rejected. Never throws, even
55
+ * on hostile input (proxies, throwing getters).
56
+ */
57
+ export declare function parseTelemetryEvent(value: unknown): TelemetryEventPayload | null;
58
+ /** Emitter side: map any element type to a closed bucket (unknown -> 'other'). */
59
+ export declare function toElementTypeBucket(type: string): SelectionElementType;
60
+ //# sourceMappingURL=telemetryEvents.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"telemetryEvents.d.ts","sourceRoot":"","sources":["../../../../src/sdk/utils/telemetry/telemetryEvents.ts"],"names":[],"mappings":"AAAA;;;;;IAKI;AAEJ;;;;;;;;;;GAUG;AAEH,eAAO,MAAM,wBAAwB,IAAI,CAAC;AAE1C,eAAO,MAAM,qBAAqB,oFAIxB,CAAC;AACX,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,qBAAqB,CAAC,CAAC,MAAM,CAAC,CAAC;AAExE,eAAO,MAAM,mBAAmB,4BAA6B,CAAC;AAC9D,MAAM,MAAM,gBAAgB,GAAG,CAAC,OAAO,mBAAmB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEpE,eAAO,MAAM,iBAAiB,4BAA6B,CAAC;AAC5D,MAAM,MAAM,eAAe,GAAG,CAAC,OAAO,iBAAiB,CAAC,CAAC,MAAM,CAAC,CAAC;AAEjE;;;;;;;;;;;GAWG;AACH,eAAO,MAAM,uBAAuB,krCA6E1B,CAAC;AACX,MAAM,MAAM,oBAAoB,GAAG,CAAC,OAAO,uBAAuB,CAAC,C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