@salesforce/platform-sdk 13.0.0-canary.1146.198.1.gaeab8f47 → 13.1.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/README.md CHANGED
@@ -164,8 +164,8 @@ analytics.trackProductUsage("hxlWidgetButton.clicked", {
164
164
 
165
165
  - The event is sent only when a PFT Id is set (via `pftId` or `setPftId`). PDP rejects events without one, so the call is a no-op otherwise.
166
166
  - `eventName` must be `<object>.<action>`: both parts in lower camelCase (`hxlWidget.rendered`, `hxlWidget.buttonClicked`). Other names are dropped with a `console.debug` note.
167
- - `once: true` sends a given `eventName` + `componentId` pair at most once for the life of the analytics instance. Use it for "rendered" and "interacted" counts.
168
- - Optional fields, all copied to the PDP row:
167
+ - `once: true` sends a given `eventName` + `componentId` pair at most once per PFT Id for the life of the analytics instance. Use it for "rendered" and "interacted" counts.
168
+ - Optional fields, copied to the PDP row when they are strings (other values are dropped):
169
169
  - `componentId`: the component that sent the event.
170
170
  - `channel`: the surface, for example `OpenAI` or `Slack`.
171
171
  - `subType`: a finer kind of event, for example `button`.
@@ -175,7 +175,7 @@ analytics.trackProductUsage("hxlWidgetButton.clicked", {
175
175
  - `productFeatureId` is filled in for you. Core fills in the org, user and session.
176
176
  - To group events by widget session in Huron, use `clientSessionId`. Core sets `sessionId` from the server session, which is `GuestSession` for calls made through an MCP server.
177
177
 
178
- Requires `o11y_schema` 264.146.0 or later.
178
+ The SDK bundles its own `sf.pdp.PdpEvent` descriptor, so consumers don't need to upgrade `o11y_schema`.
179
179
 
180
180
  ### Pages whose CSP blocks `'unsafe-eval'`
181
181
 
@@ -1,4 +1,4 @@
1
- import { P as e, c as s, v as c } from "../analytics-fNSDGQs-.js";
1
+ import { P as e, c as s, v as c } from "../analytics-CqPkAIdv.js";
2
2
  export {
3
3
  e as PFT_META_KEY,
4
4
  s as createAnalytics,
@@ -8,8 +8,9 @@
8
8
  *
9
9
  * @remarks
10
10
  * Rejection never throws. The function logs a debug message with
11
- * `console.debug` the first time it sees a given invalid name in a session.
12
- * It drops later occurrences of the same name without further logging.
11
+ * `console.debug` the first time it sees a given invalid name on the page,
12
+ * for up to 20 distinct names, and truncates long names. It drops later
13
+ * occurrences without further logging.
13
14
  *
14
15
  * @param name - The candidate event name, in any input shape, including non-strings.
15
16
  * @returns `true` when the name follows the `<object>.<action>` rule.
@@ -34,4 +35,12 @@ export declare function validatePdpEventName(name: unknown): name is string;
34
35
  * @returns `true` for a whole number from 0 to 2,147,483,647.
35
36
  */
36
37
  export declare function isEventVolume(value: unknown): value is number;
38
+ /**
39
+ * Logs a one-time `console.debug` when a caller passes an `eventVolume` that
40
+ * {@link isEventVolume} rejects, so the dropped count isn't silent.
41
+ *
42
+ * @remarks
43
+ * The value itself isn't printed, in case it holds customer data.
44
+ */
45
+ export declare function warnInvalidEventVolume(value: unknown): void;
37
46
  //# sourceMappingURL=pdp.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"pdp.d.ts","sourceRoot":"","sources":["../../src/analytics/pdp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAqCH;;;;;;;;;;;;;;;;;;GAkBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAYlE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D"}
1
+ {"version":3,"file":"pdp.d.ts","sourceRoot":"","sources":["../../src/analytics/pdp.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AA+CH;;;;;;;;;;;;;;;;;;;GAmBG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,OAAO,GAAG,IAAI,IAAI,MAAM,CAclE;AAED;;;;;;;;;GASG;AACH,wBAAgB,aAAa,CAAC,KAAK,EAAE,OAAO,GAAG,KAAK,IAAI,MAAM,CAE7D;AAED;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,KAAK,EAAE,OAAO,GAAG,IAAI,CAO3D"}
@@ -138,9 +138,10 @@ export interface ProductUsageOptions {
138
138
  * Sends the event at most once for the life of this Analytics instance.
139
139
  *
140
140
  * @remarks
141
- * The SDK keys repeats on `eventName` plus `componentId`. Use this option
142
- * for events such as `hxlWidget.rendered` that must count once per widget,
143
- * even when the widget re-renders.
141
+ * The SDK keys repeats on the current PFT Id, `eventName` and `componentId`,
142
+ * so a widget that switches PFT Id with `setPftId()` sends the event once
143
+ * for each PFT Id. Use this option for events such as `hxlWidget.rendered`
144
+ * that must count once per widget, even when the widget re-renders.
144
145
  *
145
146
  * @default false
146
147
  */
@@ -1 +1 @@
1
- {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../../src/analytics/types.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,cAAc,CAAC;AAEvD;;GAEG;AACH,MAAM,WAAW,MAAM;IACtB,SAAS,EAAE,MAAM,CAAC;IAClB,IAAI,EAAE,MAAM,CAAC;IACb,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACpC;AAED;;;GAGG;AACH,MAAM,WAAW,kBAAkB;IAClC,MAAM,EAAE,MAAM,CAAC;IACf,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;;GAGG;AACH,MAAM,WAAW,mBAAmB;IACnC,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;IAC/B,OAAO,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CAClC;AAED;;;;;;GAMG;AACH,MAAM,WAAW,eAAe;IAC/B,UAAU,CAAC,IAAI,CAAC,EAAE,mBAAmB,GAAG,kBAAkB,GAAG,SAAS,CA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AAC;IAC/B,wEAAwE;IACxE,OAAO,EAAE,MAAM,IAAI,CAAC;CACpB"}
@@ -0,0 +1,195 @@
1
+ import { registerInstrumentedApp as L } from "o11y/client";
2
+ import { g as M, S as z } from "./surface-DyglgPiz.js";
3
+ import { w as K } from "./sdk-promise-D0sy7OW1.js";
4
+ import { getChatSDK as O } from "./chat/index.js";
5
+ import { r as R } from "./TelemetryUploader-mZWIhtRG.js";
6
+ import { p as j } from "./pdp_event-DNU_h--P.js";
7
+ import { analyticsContextSchema as J, sessionSchema as W, pageViewSchema as Z, errorContextSchema as q, interactionSchema as U, customEventSchema as X } from "o11y_schema/sf_mcpanalytics";
8
+ function H(e) {
9
+ const n = (r, f, g, o, i) => {
10
+ e.error(i ?? r);
11
+ }, c = (r) => {
12
+ e.error(r.reason);
13
+ };
14
+ return window.addEventListener("error", n), window.addEventListener("unhandledrejection", c), () => {
15
+ window.removeEventListener("error", n), window.removeEventListener("unhandledrejection", c);
16
+ };
17
+ }
18
+ const w = /* @__PURE__ */ new Set(), Y = 20, T = 64;
19
+ let x = !1;
20
+ const B = /^[a-z][a-zA-Z0-9]*\.[a-z][a-zA-Z0-9]*$/;
21
+ function G(e) {
22
+ if (typeof e != "string") return !1;
23
+ if (B.test(e)) return !0;
24
+ if (!w.has(e) && w.size < Y) {
25
+ w.add(e);
26
+ const n = e.length > T ? `${e.slice(0, T)}…` : e;
27
+ console.debug(
28
+ `[platform-sdk:analytics] Ignoring invalid PDP event name "${n}". Expected "<object>.<action>", for example "hxlWidgetButton.clicked".`
29
+ );
30
+ }
31
+ return !1;
32
+ }
33
+ function Q(e) {
34
+ return Number.isInteger(e) && e >= 0 && e <= 2147483647;
35
+ }
36
+ function ee(e) {
37
+ x || (x = !0, console.debug(
38
+ `[platform-sdk:analytics] Ignoring invalid PDP eventVolume of type ${typeof e}. Expected a whole number from 0 to 2,147,483,647; the event counts once.`
39
+ ));
40
+ }
41
+ const te = "aJC", pe = "sfdc.pftId", _ = /* @__PURE__ */ new Set(), ne = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
42
+ function k(e) {
43
+ return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (N(e, "Expected a 15- or 18-character Salesforce ID"), !1) : ne.test(e) ? !0 : (N(e, `Expected a Product Feature Id (prefix "${te}", base62).`), !1);
44
+ }
45
+ function N(e, n) {
46
+ _.has(e) || (_.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${n}`));
47
+ }
48
+ function v(e) {
49
+ return {};
50
+ }
51
+ const re = {
52
+ callTool: {
53
+ isAsync: !0,
54
+ extractTags: (e) => ({ toolName: e[0]?.toolName ?? "unknown" })
55
+ },
56
+ setWidgetState: {
57
+ isAsync: !1,
58
+ extractTags: v
59
+ },
60
+ sendMessageToHost: {
61
+ isAsync: !0,
62
+ extractTags: v
63
+ },
64
+ openLink: {
65
+ isAsync: !0,
66
+ extractTags: v
67
+ },
68
+ readResource: {
69
+ isAsync: !0,
70
+ extractTags: (e) => {
71
+ const c = e[0]?.uri ?? "", r = c.indexOf("://");
72
+ return { scheme: r > 0 ? c.slice(0, r).toLowerCase() : "unknown" };
73
+ }
74
+ },
75
+ setDisplayMode: {
76
+ isAsync: !0,
77
+ extractTags: (e) => ({ mode: e[0] ?? "unknown" })
78
+ }
79
+ };
80
+ function oe(e, n, c) {
81
+ return new Proxy(e, {
82
+ get(r, f, g) {
83
+ const o = Reflect.get(r, f, g), i = re[f];
84
+ return !i || typeof o != "function" ? o : (...l) => {
85
+ const s = { ...c(), ...i.extractTags(l) }, d = `sdk.${String(f)}`;
86
+ return i.isAsync ? n.activityAsync(d, async () => {
87
+ try {
88
+ const p = await o.apply(r, l);
89
+ return n.incrementCounter(d, 1, !1, s), p;
90
+ } catch (p) {
91
+ throw n.incrementCounter(d, 1, !0, s), p;
92
+ }
93
+ }) : (n.incrementCounter(d, 1, !1, s), o.apply(r, l));
94
+ };
95
+ }
96
+ });
97
+ }
98
+ function ge(e) {
99
+ return K(se(e), "createAnalytics");
100
+ }
101
+ async function se(e) {
102
+ const { appId: n, clientSessionId: c } = e;
103
+ let r;
104
+ try {
105
+ r = await M();
106
+ } catch {
107
+ r = z.WebApp;
108
+ }
109
+ const f = Date.now(), g = e.sdk ?? await O();
110
+ let o = null;
111
+ e.pftId !== void 0 && k(e.pftId) && (o = e.pftId);
112
+ const i = () => o !== null ? { pftId: o } : {}, l = L("mcp-widget", {
113
+ appPayloadProvider: {
114
+ getPayload: () => ({
115
+ schema: J,
116
+ payload: {
117
+ appId: n,
118
+ surface: r,
119
+ ...i()
120
+ }
121
+ })
122
+ },
123
+ clientSessionId: c
124
+ }), s = l, d = oe(g, s, () => ({
125
+ surface: r,
126
+ ...i()
127
+ })), p = H(s);
128
+ let h;
129
+ e.transport && (h = R(l, {
130
+ onEnvelope: (t) => {
131
+ e.transport.enqueue(t);
132
+ },
133
+ useEvalFreeEncoder: e.useEvalFreeEncoder
134
+ }));
135
+ let P, u = !1;
136
+ const I = /* @__PURE__ */ new Set();
137
+ return {
138
+ instrumentedSDK: d,
139
+ app: l,
140
+ trackEvent(t, a) {
141
+ u || s.log(X, {
142
+ eventName: t,
143
+ properties: a ? JSON.stringify(a) : ""
144
+ });
145
+ },
146
+ trackInteraction(t, a) {
147
+ u || s.log(U, {
148
+ elementId: t,
149
+ properties: a ? JSON.stringify(a) : ""
150
+ });
151
+ },
152
+ trackError(t, a) {
153
+ u || s.error(t, q, {
154
+ properties: a ? JSON.stringify(a) : ""
155
+ });
156
+ },
157
+ trackPageView(t) {
158
+ u || t !== P && (P = t, s.log(Z, { componentRef: t }));
159
+ },
160
+ trackProductUsage(t, a) {
161
+ if (u || !G(t) || o === null) return;
162
+ const { componentId: A, contextName: C, contextValue: D, channel: V, subType: $, eventVolume: m, once: F } = a ?? {}, y = F ? `${o}\0${t}\0${A ?? ""}` : null;
163
+ if (y !== null && I.has(y)) return;
164
+ const E = {};
165
+ for (const [b, S] of Object.entries({
166
+ componentId: A,
167
+ contextName: C,
168
+ contextValue: D,
169
+ channel: V,
170
+ subType: $
171
+ }))
172
+ typeof S == "string" && (E[b] = S);
173
+ Q(m) ? E.eventVolume = m : m !== void 0 && ee(m), s.log(j, {
174
+ ...E,
175
+ eventName: t,
176
+ productFeatureId: o,
177
+ sessionId: l.getClientSessionId()
178
+ }), y !== null && I.add(y);
179
+ },
180
+ setPftId(t) {
181
+ u || k(t) && (o = t);
182
+ },
183
+ dispose() {
184
+ if (u) return;
185
+ u = !0, p();
186
+ const t = Date.now() - f;
187
+ s.log(W, { durationMs: t }), h?.dispose();
188
+ }
189
+ };
190
+ }
191
+ export {
192
+ pe as P,
193
+ ge as c,
194
+ k as v
195
+ };
@@ -484,7 +484,7 @@ function Xe(t) {
484
484
  const Ye = (t) => {
485
485
  const [e, r] = t, n = e instanceof Request && !r?.headers ? e.headers.has(w) : new Headers(r?.headers).has(w), s = Z(n);
486
486
  return s ? p(g(w, s, t)) : p(t);
487
- }, Ze = "X-SFDC-Client-Name", et = "X-SFDC-Client-Version", tt = "@salesforce/platform-sdk", rt = "13.0.0-canary.1146.198.1.gaeab8f47", nt = (t) => {
487
+ }, Ze = "X-SFDC-Client-Name", et = "X-SFDC-Client-Version", tt = "@salesforce/platform-sdk", rt = "13.1.0", nt = (t) => {
488
488
  let e = g(Ze, tt, t);
489
489
  return e = g(et, rt, e), p(e);
490
490
  }, st = "X-CSRF-Token";
package/dist/index.js CHANGED
@@ -8,7 +8,7 @@ import { createLightningSDK as E } from "./lightning/index.js";
8
8
  import { WebAppCurrentApp as I, getCurrentApp as U } from "./app/index.js";
9
9
  import { c as q } from "./transport-D9QstWle.js";
10
10
  import { T as F, r as L } from "./TelemetryUploader-mZWIhtRG.js";
11
- import { P as W, c as Y, v as j } from "./analytics-fNSDGQs-.js";
11
+ import { P as W, c as Y, v as j } from "./analytics-CqPkAIdv.js";
12
12
  export {
13
13
  n as MCPAppsChatSDK,
14
14
  d as MCPAppsViewSDK,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/platform-sdk",
3
- "version": "13.0.0-canary.1146.198.1.gaeab8f47",
3
+ "version": "13.1.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -148,7 +148,7 @@
148
148
  "@conduit-client/service-pubsub": "^3.19.6",
149
149
  "@conduit-client/service-retry": "^3.19.6",
150
150
  "@conduit-client/utils": "^3.19.6",
151
- "@salesforce/jsonrpc": "13.0.0-canary.1146.198.1.gaeab8f47",
151
+ "@salesforce/jsonrpc": "^13.1.0",
152
152
  "@salesforce/sf-embedding-bridge": "2.3.0-rc.3"
153
153
  },
154
154
  "peerDependencies": {
@@ -1,178 +0,0 @@
1
- import { registerInstrumentedApp as k } from "o11y/client";
2
- import { g as _, S as C } from "./surface-DyglgPiz.js";
3
- import { w as F } from "./sdk-promise-D0sy7OW1.js";
4
- import { getChatSDK as N } from "./chat/index.js";
5
- import { r as D } from "./TelemetryUploader-mZWIhtRG.js";
6
- import { p as $ } from "./pdp_event-DNU_h--P.js";
7
- import { analyticsContextSchema as L, sessionSchema as V, pageViewSchema as b, errorContextSchema as z, interactionSchema as K, customEventSchema as O } from "o11y_schema/sf_mcpanalytics";
8
- function J(e) {
9
- const n = (r, l, g, o, i) => {
10
- e.error(i ?? r);
11
- }, c = (r) => {
12
- e.error(r.reason);
13
- };
14
- return window.addEventListener("error", n), window.addEventListener("unhandledrejection", c), () => {
15
- window.removeEventListener("error", n), window.removeEventListener("unhandledrejection", c);
16
- };
17
- }
18
- const S = /* @__PURE__ */ new Set(), M = /^[a-z][a-zA-Z0-9]*\.[a-z][a-zA-Z0-9]*$/;
19
- function R(e) {
20
- return typeof e != "string" ? !1 : M.test(e) ? !0 : (S.has(e) || (S.add(e), console.debug(
21
- `[platform-sdk:analytics] Ignoring invalid PDP event name "${e}". Expected "<object>.<action>", for example "hxlWidgetButton.clicked".`
22
- )), !1);
23
- }
24
- function j(e) {
25
- return Number.isInteger(e) && e >= 0 && e <= 2147483647;
26
- }
27
- const Z = "aJC", re = "sfdc.pftId", v = /* @__PURE__ */ new Set(), q = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
28
- function A(e) {
29
- return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (T(e, "Expected a 15- or 18-character Salesforce ID"), !1) : q.test(e) ? !0 : (T(e, `Expected a Product Feature Id (prefix "${Z}", base62).`), !1);
30
- }
31
- function T(e, n) {
32
- v.has(e) || (v.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${n}`));
33
- }
34
- function m(e) {
35
- return {};
36
- }
37
- const U = {
38
- callTool: {
39
- isAsync: !0,
40
- extractTags: (e) => ({ toolName: e[0]?.toolName ?? "unknown" })
41
- },
42
- setWidgetState: {
43
- isAsync: !1,
44
- extractTags: m
45
- },
46
- sendMessageToHost: {
47
- isAsync: !0,
48
- extractTags: m
49
- },
50
- openLink: {
51
- isAsync: !0,
52
- extractTags: m
53
- },
54
- readResource: {
55
- isAsync: !0,
56
- extractTags: (e) => {
57
- const c = e[0]?.uri ?? "", r = c.indexOf("://");
58
- return { scheme: r > 0 ? c.slice(0, r).toLowerCase() : "unknown" };
59
- }
60
- },
61
- setDisplayMode: {
62
- isAsync: !0,
63
- extractTags: (e) => ({ mode: e[0] ?? "unknown" })
64
- }
65
- };
66
- function W(e, n, c) {
67
- return new Proxy(e, {
68
- get(r, l, g) {
69
- const o = Reflect.get(r, l, g), i = U[l];
70
- return !i || typeof o != "function" ? o : (...u) => {
71
- const s = { ...c(), ...i.extractTags(u) }, f = `sdk.${String(l)}`;
72
- return i.isAsync ? n.activityAsync(f, async () => {
73
- try {
74
- const p = await o.apply(r, u);
75
- return n.incrementCounter(f, 1, !1, s), p;
76
- } catch (p) {
77
- throw n.incrementCounter(f, 1, !0, s), p;
78
- }
79
- }) : (n.incrementCounter(f, 1, !1, s), o.apply(r, u));
80
- };
81
- }
82
- });
83
- }
84
- function ne(e) {
85
- return F(Y(e), "createAnalytics");
86
- }
87
- async function Y(e) {
88
- const { appId: n, clientSessionId: c } = e;
89
- let r;
90
- try {
91
- r = await _();
92
- } catch {
93
- r = C.WebApp;
94
- }
95
- const l = Date.now(), g = e.sdk ?? await N();
96
- let o = null;
97
- e.pftId !== void 0 && A(e.pftId) && (o = e.pftId);
98
- const i = () => o !== null ? { pftId: o } : {}, u = k("mcp-widget", {
99
- appPayloadProvider: {
100
- getPayload: () => ({
101
- schema: L,
102
- payload: {
103
- appId: n,
104
- surface: r,
105
- ...i()
106
- }
107
- })
108
- },
109
- clientSessionId: c
110
- }), s = u, f = W(g, s, () => ({
111
- surface: r,
112
- ...i()
113
- })), p = J(s);
114
- let y;
115
- e.transport && (y = D(u, {
116
- onEnvelope: (t) => {
117
- e.transport.enqueue(t);
118
- },
119
- useEvalFreeEncoder: e.useEvalFreeEncoder
120
- }));
121
- let w, d = !1;
122
- const E = /* @__PURE__ */ new Set();
123
- return {
124
- instrumentedSDK: f,
125
- app: u,
126
- trackEvent(t, a) {
127
- d || s.log(O, {
128
- eventName: t,
129
- properties: a ? JSON.stringify(a) : ""
130
- });
131
- },
132
- trackInteraction(t, a) {
133
- d || s.log(K, {
134
- elementId: t,
135
- properties: a ? JSON.stringify(a) : ""
136
- });
137
- },
138
- trackError(t, a) {
139
- d || s.error(t, z, {
140
- properties: a ? JSON.stringify(a) : ""
141
- });
142
- },
143
- trackPageView(t) {
144
- d || t !== w && (w = t, s.log(b, { componentRef: t }));
145
- },
146
- trackProductUsage(t, a) {
147
- if (d || o === null || !R(t)) return;
148
- const { once: x, eventVolume: P, ...I } = a ?? {};
149
- if (x) {
150
- const h = `${t}\0${I.componentId ?? ""}`;
151
- if (E.has(h)) return;
152
- E.add(h);
153
- }
154
- s.log($, {
155
- eventName: t,
156
- productFeatureId: o,
157
- sessionId: u.getClientSessionId(),
158
- ...I,
159
- // eventVolume is an int32 on the wire, and Core reads only integers.
160
- ...j(P) ? { eventVolume: P } : {}
161
- });
162
- },
163
- setPftId(t) {
164
- d || A(t) && (o = t);
165
- },
166
- dispose() {
167
- if (d) return;
168
- d = !0, p();
169
- const t = Date.now() - l;
170
- s.log(V, { durationMs: t }), y?.dispose();
171
- }
172
- };
173
- }
174
- export {
175
- re as P,
176
- ne as c,
177
- A as v
178
- };