@salesforce/platform-sdk 7.1.0 → 8.0.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/dist/index.js CHANGED
@@ -1,13 +1,19 @@
1
- import { buildServiceDescriptor as R, setHeader as S } from "@conduit-client/service-fetch-network/v1";
2
- import { resolvedPromiseLike as C } from "@conduit-client/utils";
3
- import { RetryPolicy as N, buildServiceDescriptor as U } from "@conduit-client/service-retry/v1";
4
- import { encodeCoreEnvelopeContentsRaw as q } from "o11y/collectors";
5
- import { SimpleCollector as W } from "o11y/simple_collector";
6
- import { registerInstrumentedApp as V } from "o11y/client";
7
- import { analyticsContextSchema as $, sessionSchema as B, pageViewSchema as K, errorContextSchema as j, interactionSchema as z, customEventSchema as J } from "o11y_schema/sf_mcpanalytics";
8
- var o = /* @__PURE__ */ ((s) => (s.WebApp = "WebApp", s.MicroFrontend = "Micro-Frontend", s.OpenAI = "OpenAI", s.SalesforceACC = "Salesforce-ACC", s.MCPApps = "MCP-Apps", s.Mosaic = "Mosaic", s))(o || {});
9
- const X = Y();
10
- function Y() {
1
+ import { buildServiceDescriptor as K, setHeader as _ } from "@conduit-client/service-fetch-network/v1";
2
+ import { resolvedPromiseLike as w, ok as I, err as D, stableJSONStringify as Z, DataNotFoundError as ee, UserVisibleError as te, deepFreeze as z } from "@conduit-client/utils";
3
+ import { print as R, parse as se } from "@conduit-client/onestore-graphql-parser/v1";
4
+ import { RetryPolicy as re, buildServiceDescriptor as ne } from "@conduit-client/service-retry/v1";
5
+ import { buildServiceDescriptor as ie } from "@conduit-client/service-cache/v1";
6
+ import { buildServiceDescriptor as oe } from "@conduit-client/service-cache-control/v1";
7
+ import { buildInMemoryCacheInclusionPolicyService as ae } from "@conduit-client/service-cache-inclusion-policy/v1";
8
+ import { buildServiceDescriptor as ce } from "@conduit-client/service-pubsub/v1";
9
+ import { HttpCacheControlCommand as le } from "@conduit-client/command-http-cache-control/v1";
10
+ import { encodeCoreEnvelopeContentsRaw as ue } from "o11y/collectors";
11
+ import { SimpleCollector as de } from "o11y/simple_collector";
12
+ import { registerInstrumentedApp as he } from "o11y/client";
13
+ import { analyticsContextSchema as fe, sessionSchema as pe, pageViewSchema as ge, errorContextSchema as me, interactionSchema as ye, customEventSchema as we } from "o11y_schema/sf_mcpanalytics";
14
+ var c = /* @__PURE__ */ ((s) => (s.WebApp = "WebApp", s.MicroFrontend = "Micro-Frontend", s.OpenAI = "OpenAI", s.SalesforceACC = "Salesforce-ACC", s.MCPApps = "MCP-Apps", s.Mosaic = "Mosaic", s))(c || {});
15
+ const be = ve();
16
+ function ve() {
11
17
  if (typeof window > "u")
12
18
  return "Mosaic";
13
19
  if (window.openai)
@@ -21,28 +27,28 @@ function Y() {
21
27
  const s = window;
22
28
  return s.$A || s.Aura ? "Salesforce-ACC" : "WebApp";
23
29
  }
24
- function T(s) {
25
- return s ?? X;
30
+ function C(s) {
31
+ return s ?? be;
26
32
  }
27
- function _(s) {
33
+ function A(s) {
28
34
  return typeof s == "object" && s !== null && "jsonrpc" in s && s.jsonrpc === "2.0";
29
35
  }
30
- function G(s) {
31
- return _(s) && "id" in s && typeof s.id == "number" && "result" in s;
36
+ function Ce(s) {
37
+ return A(s) && "id" in s && typeof s.id == "number" && "result" in s;
32
38
  }
33
- function x(s) {
34
- return _(s) && "id" in s && typeof s.id == "number" && "error" in s;
39
+ function B(s) {
40
+ return A(s) && "id" in s && typeof s.id == "number" && "error" in s;
35
41
  }
36
- function Q(s) {
37
- return G(s) || x(s);
42
+ function Se(s) {
43
+ return Ce(s) || B(s);
38
44
  }
39
- function Z(s) {
40
- return _(s) && "method" in s && typeof s.method == "string" && !("id" in s);
45
+ function Te(s) {
46
+ return A(s) && "method" in s && typeof s.method == "string" && !("id" in s);
41
47
  }
42
- function yt(s) {
43
- return _(s) && "id" in s && typeof s.id == "number" && "method" in s && typeof s.method == "string";
48
+ function Zt(s) {
49
+ return A(s) && "id" in s && typeof s.id == "number" && "method" in s && typeof s.method == "string";
44
50
  }
45
- class ee {
51
+ class _e {
46
52
  targetOrigin;
47
53
  /**
48
54
  * @param targetOrigin - origin passed as the second argument to
@@ -57,13 +63,13 @@ class ee {
57
63
  window.parent?.postMessage(e, this.targetOrigin);
58
64
  }
59
65
  onMessage(e) {
60
- const t = (n) => {
61
- e(n.data);
66
+ const t = (r) => {
67
+ e(r.data);
62
68
  };
63
69
  return window.addEventListener("message", t), () => window.removeEventListener("message", t);
64
70
  }
65
71
  }
66
- class te {
72
+ class Ee {
67
73
  nextRequestId = 1;
68
74
  pending = /* @__PURE__ */ new Map();
69
75
  notificationHandlers = /* @__PURE__ */ new Map();
@@ -75,7 +81,7 @@ class te {
75
81
  * `WindowPostMessageTransport`, which preserves the original
76
82
  * `window.parent.postMessage` behaviour.
77
83
  */
78
- constructor(e = new ee()) {
84
+ constructor(e = new _e()) {
79
85
  this.transport = e, this.transport.onMessage(this.onMessage);
80
86
  }
81
87
  /**
@@ -104,16 +110,16 @@ class te {
104
110
  * multiple protocols without cross-talk.
105
111
  */
106
112
  onMessage = (e) => {
107
- if (Q(e)) {
113
+ if (Se(e)) {
108
114
  const t = this.pending.get(e.id);
109
115
  if (!t)
110
116
  return;
111
- this.pending.delete(e.id), x(e) ? t.reject(new Error(e.error.message || "Request failed")) : t.resolve(e.result);
117
+ this.pending.delete(e.id), B(e) ? t.reject(new Error(e.error.message || "Request failed")) : t.resolve(e.result);
112
118
  return;
113
119
  }
114
- if (Z(e)) {
120
+ if (Te(e)) {
115
121
  const t = this.notificationHandlers.get(e.method);
116
- t && t.forEach((n) => n(e.params));
122
+ t && t.forEach((r) => r(e.params));
117
123
  }
118
124
  };
119
125
  /**
@@ -130,17 +136,17 @@ class te {
130
136
  * });
131
137
  */
132
138
  request(e, t) {
133
- const n = this.nextRequestId++, i = {
139
+ const r = this.nextRequestId++, n = {
134
140
  jsonrpc: "2.0",
135
- id: n,
141
+ id: r,
136
142
  method: e,
137
143
  params: t
138
144
  };
139
- return new Promise((r, a) => {
140
- this.pending.set(n, {
141
- resolve: r,
142
- reject: a
143
- }), this.transport.post(i);
145
+ return new Promise((i, o) => {
146
+ this.pending.set(r, {
147
+ resolve: i,
148
+ reject: o
149
+ }), this.transport.post(n);
144
150
  });
145
151
  }
146
152
  /**
@@ -167,21 +173,21 @@ class te {
167
173
  * });
168
174
  */
169
175
  sendNotification(e, t) {
170
- const n = {
176
+ const r = {
171
177
  jsonrpc: "2.0",
172
178
  method: e,
173
179
  params: t
174
180
  };
175
- this.transport.post(n);
181
+ this.transport.post(r);
176
182
  }
177
183
  }
178
- function se() {
184
+ function Ae() {
179
185
  }
180
- class Ct {
186
+ class es {
181
187
  #e;
182
188
  #s = /* @__PURE__ */ new Set();
183
- #i = !1;
184
189
  #n = !1;
190
+ #r = !1;
185
191
  /** Messages queued before `port.start()` has been called. Flushed on first subscribe. */
186
192
  #t = [];
187
193
  constructor(e) {
@@ -196,8 +202,8 @@ class Ct {
196
202
  * flushed on first subscription.
197
203
  */
198
204
  post(e) {
199
- if (!this.#n) {
200
- if (!this.#i) {
205
+ if (!this.#r) {
206
+ if (!this.#n) {
201
207
  this.#t.push(e);
202
208
  return;
203
209
  }
@@ -218,9 +224,9 @@ class Ct {
218
224
  * Returns an unsubscribe function. Calling it is idempotent.
219
225
  */
220
226
  onMessage(e) {
221
- if (this.#n)
222
- return se;
223
- this.#s.add(e), this.#i || this.#o();
227
+ if (this.#r)
228
+ return Ae;
229
+ this.#s.add(e), this.#n || this.#o();
224
230
  let t = !1;
225
231
  return () => {
226
232
  t || (t = !0, this.#s.delete(e));
@@ -235,10 +241,10 @@ class Ct {
235
241
  * - subsequent `onMessage` calls return a no-op unsubscribe
236
242
  */
237
243
  dispose() {
238
- if (!this.#n) {
239
- this.#n = !0;
244
+ if (!this.#r) {
245
+ this.#r = !0;
240
246
  try {
241
- this.#e.removeEventListener("message", this.#r);
247
+ this.#e.removeEventListener("message", this.#i);
242
248
  } catch {
243
249
  }
244
250
  this.#s.clear(), this.#t.length = 0;
@@ -249,7 +255,7 @@ class Ct {
249
255
  }
250
256
  }
251
257
  #o() {
252
- this.#i = !0, this.#e.addEventListener("message", this.#r);
258
+ this.#n = !0, this.#e.addEventListener("message", this.#i);
253
259
  try {
254
260
  this.#e.start();
255
261
  } catch {
@@ -264,17 +270,17 @@ class Ct {
264
270
  }
265
271
  }
266
272
  }
267
- #r = (e) => {
273
+ #i = (e) => {
268
274
  const t = [...this.#s];
269
- for (const n of t)
275
+ for (const r of t)
270
276
  try {
271
- n(e.data);
277
+ r(e.data);
272
278
  } catch {
273
279
  }
274
280
  };
275
281
  }
276
- const ne = 500, ie = "2026-01-26";
277
- class g extends te {
282
+ const ke = 500, Me = "2026-01-26";
283
+ class y extends Ee {
278
284
  static initPromise = null;
279
285
  hostCtx = {};
280
286
  _handshakeSucceeded = !1;
@@ -285,17 +291,17 @@ class g extends te {
285
291
  * calls reuse the same session and handshake result.
286
292
  */
287
293
  static async getInstance(e) {
288
- return g.initPromise || (g.initPromise = (async () => {
289
- const t = new g();
294
+ return y.initPromise || (y.initPromise = (async () => {
295
+ const t = new y();
290
296
  return await t.handshake(e), t;
291
- })()), g.initPromise;
297
+ })()), y.initPromise;
292
298
  }
293
299
  /**
294
300
  * Reset the singleton (for testing only).
295
301
  * @internal
296
302
  */
297
303
  static resetInstance() {
298
- g.initPromise = null;
304
+ y.initPromise = null;
299
305
  }
300
306
  /**
301
307
  * Perform the ui/initialize → hostContext → ui/notifications/initialized handshake.
@@ -305,20 +311,20 @@ class g extends te {
305
311
  * still render (graceful degradation for non-SEP-1865 hosts).
306
312
  */
307
313
  async handshake(e) {
308
- const t = e?.handshakeTimeoutMs ?? ne, n = e?.appInfo ?? { name: "mcp-app", version: "1.0.0" };
314
+ const t = e?.handshakeTimeoutMs ?? ke, r = e?.appInfo ?? { name: "mcp-app", version: "1.0.0" };
309
315
  try {
310
- const i = /* @__PURE__ */ Symbol("timeout"), r = await Promise.race([
316
+ const n = /* @__PURE__ */ Symbol("timeout"), i = await Promise.race([
311
317
  this.request("ui/initialize", {
312
- protocolVersion: ie,
313
- appInfo: n,
318
+ protocolVersion: Me,
319
+ appInfo: r,
314
320
  appCapabilities: {}
315
321
  }),
316
- new Promise((a) => setTimeout(() => a(i), t))
322
+ new Promise((o) => setTimeout(() => o(n), t))
317
323
  ]);
318
- r !== i && (this.hostCtx = r.hostContext ?? {}, this._handshakeSucceeded = !0, this.registerNotificationHandler("ui/notifications/host-context-changed", (a) => {
324
+ i !== n && (this.hostCtx = i.hostContext ?? {}, this._handshakeSucceeded = !0, this.registerNotificationHandler("ui/notifications/host-context-changed", (o) => {
319
325
  this.hostCtx = {
320
326
  ...this.hostCtx,
321
- ...a
327
+ ...o
322
328
  };
323
329
  }), this.sendNotification("ui/notifications/initialized"));
324
330
  } catch {
@@ -345,7 +351,7 @@ class g extends te {
345
351
  super.registerNotificationHandler(e, t);
346
352
  }
347
353
  }
348
- const re = {
354
+ const Ie = {
349
355
  callTool: !0,
350
356
  sendMessageToHost: !0,
351
357
  readResource: !0,
@@ -365,7 +371,7 @@ const re = {
365
371
  // TODO
366
372
  getTheme: !0,
367
373
  resize: !0
368
- }, oe = {
374
+ }, De = {
369
375
  callTool: !0,
370
376
  sendMessageToHost: !0,
371
377
  readResource: !1,
@@ -384,7 +390,7 @@ const re = {
384
390
  displayModal: !0,
385
391
  getTheme: !0,
386
392
  resize: !1
387
- }, ae = {
393
+ }, Pe = {
388
394
  callTool: !1,
389
395
  sendMessageToHost: !0,
390
396
  readResource: !1,
@@ -403,7 +409,7 @@ const re = {
403
409
  displayModal: !1,
404
410
  getTheme: !0,
405
411
  resize: !1
406
- }, ce = {
412
+ }, Le = {
407
413
  callTool: !1,
408
414
  sendMessageToHost: !1,
409
415
  readResource: !1,
@@ -423,28 +429,28 @@ const re = {
423
429
  getTheme: !1,
424
430
  resize: !1
425
431
  };
426
- function Tt(s) {
432
+ function ts(s) {
427
433
  switch (s) {
428
- case o.MCPApps:
429
- return { ...re };
430
- case o.OpenAI:
431
- return { ...oe };
432
- case o.SalesforceACC:
433
- return { ...ae };
434
- case o.Mosaic:
435
- case o.WebApp:
436
- case o.MicroFrontend:
434
+ case c.MCPApps:
435
+ return { ...Ie };
436
+ case c.OpenAI:
437
+ return { ...De };
438
+ case c.SalesforceACC:
439
+ return { ...Pe };
440
+ case c.Mosaic:
441
+ case c.WebApp:
442
+ case c.MicroFrontend:
437
443
  default:
438
- return { ...ce };
444
+ return { ...Le };
439
445
  }
440
446
  }
441
- const le = /* @__PURE__ */ new Set(["then", "catch", "finally"]);
442
- function A(s, e) {
447
+ const Re = /* @__PURE__ */ new Set(["then", "catch", "finally"]);
448
+ function k(s, e) {
443
449
  return new Proxy(s, {
444
- get(t, n, i) {
445
- if (typeof n == "symbol" || le.has(n)) {
446
- const r = Reflect.get(t, n, i);
447
- return typeof r == "function" ? r.bind(t) : r;
450
+ get(t, r, n) {
451
+ if (typeof r == "symbol" || Re.has(r)) {
452
+ const i = Reflect.get(t, r, n);
453
+ return typeof i == "function" ? i.bind(t) : i;
448
454
  }
449
455
  throw new TypeError(
450
456
  `\`${e}()\` returns a Promise — did you forget to await it?
@@ -453,7 +459,7 @@ Use \`const sdk = await ${e}();\` before accessing SDK methods.`
453
459
  }
454
460
  });
455
461
  }
456
- class ue {
462
+ class xe {
457
463
  constructor(e) {
458
464
  this.session = e;
459
465
  const t = e.getHostContext();
@@ -462,13 +468,13 @@ class ue {
462
468
  () => this.notifySubscribers()
463
469
  ), e.registerNotificationHandler(
464
470
  "ui/notifications/tool-result",
465
- (n) => this.handleToolResult(n)
471
+ (r) => this.handleToolResult(r)
466
472
  ), e.registerNotificationHandler(
467
473
  "ui/notifications/tool-input",
468
- (n) => this.handleToolInput(n)
474
+ (r) => this.handleToolInput(r)
469
475
  ), e.registerNotificationHandler(
470
476
  "ui/notifications/tool-cancelled",
471
- (n) => this.handleToolCancelled(n)
477
+ (r) => this.handleToolCancelled(r)
472
478
  );
473
479
  }
474
480
  globals = {};
@@ -480,8 +486,8 @@ class ue {
480
486
  */
481
487
  handleToolResult(e) {
482
488
  const t = e;
483
- let n = !1;
484
- t.content !== void 0 && (this.globals.toolOutput = t.content, n = !0), t.structuredContent !== void 0 && (this.globals.toolStructuredContent = t.structuredContent, n = !0), t._meta !== void 0 && (this.globals.toolResponseMetadata = t._meta, n = !0), n && this.notifySubscribers();
489
+ let r = !1;
490
+ t.content !== void 0 && (this.globals.toolOutput = t.content, r = !0), t.structuredContent !== void 0 && (this.globals.toolStructuredContent = t.structuredContent, r = !0), t._meta !== void 0 && (this.globals.toolResponseMetadata = t._meta, r = !0), r && this.notifySubscribers();
485
491
  }
486
492
  /**
487
493
  * Handle tool input notifications from the host
@@ -496,8 +502,8 @@ class ue {
496
502
  * @param params - Tool cancellation data from the host
497
503
  */
498
504
  handleToolCancelled(e) {
499
- const n = e.reason ?? "";
500
- this.canceledCallbacks.forEach((i) => i(n));
505
+ const r = e.reason ?? "";
506
+ this.canceledCallbacks.forEach((n) => n(r));
501
507
  }
502
508
  /**
503
509
  * Request display mode change from host
@@ -568,8 +574,8 @@ class ue {
568
574
  getHostContext() {
569
575
  const e = this.session.getHostContext(), t = {};
570
576
  if (e.theme !== void 0 && (t.theme = e.theme), e.displayMode !== void 0 && (t.displayMode = e.displayMode), e.containerDimensions !== void 0) {
571
- const n = e.containerDimensions.maxHeight ?? e.containerDimensions.height;
572
- n !== void 0 && (t.maxHeight = n);
577
+ const r = e.containerDimensions.maxHeight ?? e.containerDimensions.height;
578
+ r !== void 0 && (t.maxHeight = r);
573
579
  }
574
580
  return e.safeAreaInsets !== void 0 && (t.safeArea = e.safeAreaInsets), e.userAgent !== void 0 && (t.userAgent = e.userAgent), e.locale !== void 0 && (t.locale = e.locale), e.deviceCapabilities !== void 0 && (t.deviceCapabilities = e.deviceCapabilities), e.styles !== void 0 && (t.styles = e.styles), t;
575
581
  }
@@ -587,8 +593,8 @@ class ue {
587
593
  this.subscriptions.forEach((e) => e());
588
594
  }
589
595
  }
590
- const k = "openai:set_globals";
591
- class de {
596
+ const N = "openai:set_globals";
597
+ class Oe {
592
598
  sendMessageToHost(e) {
593
599
  return window.openai.sendFollowUpMessage({ prompt: e.content });
594
600
  }
@@ -623,12 +629,12 @@ class de {
623
629
  }
624
630
  subscribe(e) {
625
631
  const t = () => e();
626
- return window.addEventListener(k, t), () => {
627
- window.removeEventListener(k, t);
632
+ return window.addEventListener(N, t), () => {
633
+ window.removeEventListener(N, t);
628
634
  };
629
635
  }
630
636
  }
631
- class he {
637
+ class He {
632
638
  async sendMessageToHost(e) {
633
639
  throw console.warn("SalesforceACCChatSDK.sendMessageToHost: stub implementation", e), new Error("SalesforceACCChatSDK.sendMessageToHost not yet implemented");
634
640
  }
@@ -636,31 +642,31 @@ class he {
636
642
  return console.warn("SalesforceACCChatSDK.followUpActions: stub implementation"), [];
637
643
  }
638
644
  }
639
- let b = null, M = null;
640
- function fe(s) {
641
- return b || (b = pe(s).then((e) => (M = e, e))), b;
645
+ let S = null, x = null;
646
+ function qe(s) {
647
+ return S || (S = Ne(s).then((e) => (x = e, e))), S;
642
648
  }
643
- function bt() {
644
- return M;
649
+ function ss() {
650
+ return x;
645
651
  }
646
- function vt() {
647
- b = null, M = null;
652
+ function rs() {
653
+ S = null, x = null;
648
654
  }
649
- function pe(s) {
650
- return A(
655
+ function Ne(s) {
656
+ return k(
651
657
  (async () => {
652
- switch (T(s?.surface)) {
653
- case o.OpenAI:
654
- return new de();
655
- case o.WebApp:
656
- case o.Mosaic:
658
+ switch (C(s?.surface)) {
659
+ case c.OpenAI:
660
+ return new Oe();
661
+ case c.WebApp:
662
+ case c.Mosaic:
657
663
  return {};
658
- case o.SalesforceACC:
659
- return new he();
660
- case o.MicroFrontend:
661
- case o.MCPApps: {
662
- const t = await g.getInstance(s?.mcpApps);
663
- return t.handshakeSucceeded ? new ue(t) : {};
664
+ case c.SalesforceACC:
665
+ return new He();
666
+ case c.MicroFrontend:
667
+ case c.MCPApps: {
668
+ const t = await y.getInstance(s?.mcpApps);
669
+ return t.handshakeSucceeded ? new xe(t) : {};
664
670
  }
665
671
  default:
666
672
  return {};
@@ -669,7 +675,7 @@ function pe(s) {
669
675
  "createChatSDK"
670
676
  );
671
677
  }
672
- function ge(s) {
678
+ function Fe(s) {
673
679
  switch (s) {
674
680
  case "info":
675
681
  return "ℹ️";
@@ -683,26 +689,26 @@ function ge(s) {
683
689
  return "ℹ️";
684
690
  }
685
691
  }
686
- function I(s, e) {
687
- return `${ge(e)} ${s}`;
692
+ function P(s, e) {
693
+ return `${Fe(e)} ${s}`;
688
694
  }
689
- function D(s, e) {
695
+ function F(s, e) {
690
696
  const t = s.trim();
691
697
  if (t === "")
692
698
  return { success: !0, value: void 0 };
693
- const n = t.match(/^(\d+(?:\.\d+)?)(px)?$/);
694
- if (!n || !n[1])
699
+ const r = t.match(/^(\d+(?:\.\d+)?)(px)?$/);
700
+ if (!r || !r[1])
695
701
  return {
696
702
  success: !1,
697
703
  error: `Invalid ${e}: "${s}". Only pixel values are supported (e.g., "800px" or "800").`
698
704
  };
699
- const i = parseFloat(n[1]);
700
- return i < 0 || !isFinite(i) ? {
705
+ const n = parseFloat(r[1]);
706
+ return n < 0 || !isFinite(n) ? {
701
707
  success: !1,
702
708
  error: `Invalid ${e}: "${s}". Value must be a positive number.`
703
- } : { success: !0, value: i };
709
+ } : { success: !0, value: n };
704
710
  }
705
- class me {
711
+ class Ue {
706
712
  constructor(e) {
707
713
  this.session = e;
708
714
  }
@@ -712,13 +718,13 @@ class me {
712
718
  * @param level - The message severity level (defaults to "info")
713
719
  */
714
720
  async sendMessage(e, t = "info") {
715
- const n = I(e, t);
721
+ const r = P(e, t);
716
722
  await this.session.request("ui/message", {
717
723
  role: "user",
718
724
  content: [
719
725
  {
720
726
  type: "text",
721
- text: n
727
+ text: r
722
728
  }
723
729
  ]
724
730
  });
@@ -737,24 +743,24 @@ class me {
737
743
  return e ? { mode: e } : null;
738
744
  }
739
745
  async resize(e, t) {
740
- const n = D(e, "width");
746
+ const r = F(e, "width");
747
+ if (!r.success)
748
+ return Promise.reject(new Error(r.error));
749
+ const n = F(t, "height");
741
750
  if (!n.success)
742
751
  return Promise.reject(new Error(n.error));
743
- const i = D(t, "height");
744
- if (!i.success)
745
- return Promise.reject(new Error(i.error));
746
- const r = {};
747
- return n.value !== void 0 && (r.width = n.value), i.value !== void 0 && (r.height = i.value), this.session.sendNotification("ui/notifications/size-changed", r), Promise.resolve();
752
+ const i = {};
753
+ return r.value !== void 0 && (i.width = r.value), n.value !== void 0 && (i.height = n.value), this.session.sendNotification("ui/notifications/size-changed", i), Promise.resolve();
748
754
  }
749
755
  }
750
- class we {
756
+ class Ve {
751
757
  async displayAlert(e) {
752
- const t = e.level || "info", n = I(e.message, t);
753
- await window.openai.sendFollowUpMessage({ prompt: n });
758
+ const t = e.level || "info", r = P(e.message, t);
759
+ await window.openai.sendFollowUpMessage({ prompt: r });
754
760
  }
755
761
  async displayToast(e) {
756
- const t = e.level || "info", n = I(e.message, t);
757
- await window.openai.sendFollowUpMessage({ prompt: n });
762
+ const t = e.level || "info", r = P(e.message, t);
763
+ await window.openai.sendFollowUpMessage({ prompt: r });
758
764
  }
759
765
  async displayModal(e) {
760
766
  await window.openai.requestModal({
@@ -767,31 +773,31 @@ class we {
767
773
  return e ? { mode: e } : null;
768
774
  }
769
775
  }
770
- let v = null, E = null;
771
- function St(s) {
772
- return v || (v = ye(s).then((e) => (E = e, e))), v;
776
+ let T = null, O = null;
777
+ function ns(s) {
778
+ return T || (T = We(s).then((e) => (O = e, e))), T;
773
779
  }
774
- function _t() {
775
- return E;
780
+ function is() {
781
+ return O;
776
782
  }
777
- function At() {
778
- v = null, E = null;
783
+ function os() {
784
+ T = null, O = null;
779
785
  }
780
- function ye(s) {
781
- return A(
786
+ function We(s) {
787
+ return k(
782
788
  (async () => {
783
- switch (T(s?.surface)) {
784
- case o.OpenAI:
785
- return new we();
786
- case o.WebApp:
787
- case o.Mosaic:
789
+ switch (C(s?.surface)) {
790
+ case c.OpenAI:
791
+ return new Ve();
792
+ case c.WebApp:
793
+ case c.Mosaic:
788
794
  return {};
789
- case o.SalesforceACC:
795
+ case c.SalesforceACC:
790
796
  return {};
791
- case o.MicroFrontend:
792
- case o.MCPApps: {
793
- const t = await g.getInstance(s?.mcpApps);
794
- return t.handshakeSucceeded ? new me(t) : {};
797
+ case c.MicroFrontend:
798
+ case c.MCPApps: {
799
+ const t = await y.getInstance(s?.mcpApps);
800
+ return t.handshakeSucceeded ? new Ue(t) : {};
795
801
  }
796
802
  default:
797
803
  return {};
@@ -800,44 +806,155 @@ function ye(s) {
800
806
  "createViewSDK"
801
807
  );
802
808
  }
803
- function Ce(s) {
809
+ function $e(s) {
804
810
  return (e) => {
805
- const [t, n] = e;
811
+ const [t, r] = e;
806
812
  if (typeof t == "string" && !t.startsWith("http")) {
807
- const i = t.startsWith("/") ? t : `/${t}`;
808
- return C([`${s}${i}`, n]);
813
+ const n = t.startsWith("/") ? t : `/${t}`;
814
+ return w([`${s}${n}`, r]);
809
815
  }
810
- return C(e);
816
+ return w(e);
811
817
  };
812
818
  }
813
- function Te(s) {
814
- return (e) => C(S("Authorization", `Bearer ${s}`, e));
819
+ function Ke(s) {
820
+ return (e) => w(_("Authorization", `Bearer ${s}`, e));
815
821
  }
816
- function be(s, e) {
822
+ function ze(s, e) {
817
823
  const t = [];
818
- return s && t.push(Ce(s)), e && t.push(Te(e)), R({
824
+ return s && t.push($e(s)), e && t.push(Ke(e)), K({
819
825
  request: t
820
826
  }).service;
821
827
  }
822
- const ve = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0";
823
- function H(s = ve) {
828
+ const E = () => {
829
+ }, L = async () => {
830
+ };
831
+ function H(s) {
832
+ try {
833
+ return I(se(s));
834
+ } catch (e) {
835
+ return D(b(e));
836
+ }
837
+ }
838
+ function q(s, e) {
839
+ const t = s.definitions.filter(
840
+ (r) => r.kind === "OperationDefinition"
841
+ );
842
+ return t.length === 0 ? "unknown" : t.length === 1 ? e === void 0 || t[0].name?.value === e ? t[0].operation : "unknown" : e === void 0 ? "unknown" : t.find((r) => r.name?.value === e)?.operation ?? "unknown";
843
+ }
844
+ function b(s) {
845
+ if (s && typeof s == "object" && "data" in s) {
846
+ const e = s.data;
847
+ if (e && typeof e == "object" && "errors" in e && Array.isArray(e.errors))
848
+ return e.errors;
849
+ }
850
+ return s instanceof Error ? [{ message: s.message }] : typeof s == "string" ? [{ message: s }] : [{ message: "Unknown error" }];
851
+ }
852
+ async function j(s, { mutation: e, variables: t, operationName: r }) {
853
+ const n = H(e);
854
+ if (n.isErr()) return { data: void 0, errors: n.error };
855
+ const i = n.value, o = q(i, r);
856
+ if (o !== "mutation")
857
+ return {
858
+ data: void 0,
859
+ errors: [
860
+ {
861
+ message: `DataSDK.graphql.mutate() requires a GraphQL mutation, received ${o}.`
862
+ }
863
+ ]
864
+ };
865
+ try {
866
+ const a = await s({
867
+ query: R(i),
868
+ variables: t,
869
+ operationName: r
870
+ });
871
+ return {
872
+ data: a.data ?? void 0,
873
+ errors: a.errors
874
+ };
875
+ } catch (a) {
876
+ return { data: void 0, errors: b(a) };
877
+ }
878
+ }
879
+ function Q(s) {
880
+ function e(r, n, i) {
881
+ return s({
882
+ query: R(r),
883
+ variables: n,
884
+ operationName: i
885
+ }).then(
886
+ (o) => ({
887
+ data: o.data ?? void 0,
888
+ errors: o.errors
889
+ }),
890
+ (o) => ({ data: void 0, errors: b(o) })
891
+ );
892
+ }
893
+ async function t({
894
+ query: r,
895
+ variables: n,
896
+ operationName: i
897
+ }) {
898
+ const o = H(r);
899
+ if (o.isErr())
900
+ return {
901
+ data: void 0,
902
+ errors: o.error,
903
+ subscribe: () => E,
904
+ refresh: L
905
+ };
906
+ const a = o.value, u = q(a, i);
907
+ if (u !== "query")
908
+ return {
909
+ data: void 0,
910
+ errors: [
911
+ {
912
+ message: `DataSDK.graphql.query() requires a GraphQL query, received ${u}.`
913
+ }
914
+ ],
915
+ subscribe: () => E,
916
+ refresh: L
917
+ };
918
+ const l = /* @__PURE__ */ new Set(), f = n, p = await e(a, f, i);
919
+ return {
920
+ data: p.data,
921
+ errors: p.errors,
922
+ subscribe(d) {
923
+ return l.add(d), () => {
924
+ l.delete(d);
925
+ };
926
+ },
927
+ async refresh() {
928
+ const d = await e(a, f, i);
929
+ for (const h of l) h(d);
930
+ }
931
+ };
932
+ }
933
+ return {
934
+ query: t,
935
+ mutate: (r) => j(s, r)
936
+ };
937
+ }
938
+ const Be = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0";
939
+ function G(s = Be) {
824
940
  return `/services/data/v${s}`;
825
941
  }
826
- class Se {
942
+ class je {
827
943
  clientFetch;
828
944
  pathData;
945
+ graphql;
829
946
  constructor(e) {
830
- const t = _e(), n = Ae(e?.instanceUrl ?? t.instanceUrl), i = e?.accessToken ?? t.accessToken;
831
- this.pathData = H(e?.apiVersion ?? t.apiVersion), this.clientFetch = be(n || void 0, i);
947
+ const t = Qe(), r = Ge(e?.instanceUrl ?? t.instanceUrl), n = e?.accessToken ?? t.accessToken;
948
+ this.pathData = G(e?.apiVersion ?? t.apiVersion), this.clientFetch = ze(r || void 0, n), this.graphql = Q(this.executeRawGraphQL.bind(this));
832
949
  }
833
- async graphql({
950
+ async executeRawGraphQL({
834
951
  query: e,
835
952
  variables: t,
836
- operationName: n
953
+ operationName: r
837
954
  }) {
838
955
  return (await this.clientFetch(`${this.pathData}/graphql`, {
839
956
  method: "POST",
840
- body: JSON.stringify({ query: e, variables: t, operationName: n }),
957
+ body: JSON.stringify({ query: e, variables: t, operationName: r }),
841
958
  headers: {
842
959
  "Content-Type": "application/json",
843
960
  Accept: "application/json"
@@ -845,7 +962,7 @@ class Se {
845
962
  })).json();
846
963
  }
847
964
  }
848
- function _e() {
965
+ function Qe() {
849
966
  const s = globalThis.MOSAIC_ENV;
850
967
  return {
851
968
  instanceUrl: s?.instanceUrl,
@@ -853,58 +970,62 @@ function _e() {
853
970
  apiVersion: s?.apiVersion
854
971
  };
855
972
  }
856
- function Ae(s) {
973
+ function Ge(s) {
857
974
  if (!s || s === "/") return "";
858
975
  let e = s;
859
976
  return !e.startsWith("/") && !e.startsWith("http") && (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
860
977
  }
861
- const Ie = "graphqlQuery";
862
- class Me {
863
- async graphql({
978
+ const Je = "graphqlQuery";
979
+ class Xe {
980
+ graphql;
981
+ constructor() {
982
+ this.graphql = Q(this.executeRawGraphQL.bind(this));
983
+ }
984
+ async executeRawGraphQL({
864
985
  query: e,
865
986
  variables: t,
866
- operationName: n
987
+ operationName: r
867
988
  }) {
868
- return (await window.openai.callTool(Ie, {
989
+ return (await window.openai.callTool(Je, {
869
990
  query: e,
870
991
  ...t != null ? { variables: t } : {},
871
- ...n != null ? { operationName: n } : {}
992
+ ...r != null ? { operationName: r } : {}
872
993
  })).structuredContent;
873
994
  }
874
995
  }
875
- const Ee = "X-SFDC-Client-Name", ke = "X-SFDC-Client-Version", De = "@salesforce/platform-sdk", Pe = "7.1.0", Le = (s) => {
876
- let e = S(Ee, De, s);
877
- return e = S(ke, Pe, e), C(e);
878
- }, Re = "X-CSRF-Token";
879
- function xe(s, e = {}) {
880
- const { protectedUrls: t = [], alwaysProtectedUrls: n = [] } = e;
881
- return async (i) => {
882
- const [r, a] = i, c = new Request(r, a);
883
- if (P(n, c.url) || He(c.method) && P(t, c.url)) {
884
- const d = await s.getToken();
885
- i = S(Re, d, i);
996
+ const Ye = "X-SFDC-Client-Name", Ze = "X-SFDC-Client-Version", et = "@salesforce/platform-sdk", tt = "8.0.0", st = (s) => {
997
+ let e = _(Ye, et, s);
998
+ return e = _(Ze, tt, e), w(e);
999
+ }, rt = "X-CSRF-Token";
1000
+ function nt(s, e = {}) {
1001
+ const { protectedUrls: t = [], alwaysProtectedUrls: r = [] } = e;
1002
+ return async (n) => {
1003
+ const [i, o] = n, a = new Request(i, o);
1004
+ if (U(r, a.url) || it(a.method) && U(t, a.url)) {
1005
+ const l = await s.getToken();
1006
+ n = _(rt, l, n);
886
1007
  }
887
- return C(i);
1008
+ return w(n);
888
1009
  };
889
1010
  }
890
- function He(s) {
1011
+ function it(s) {
891
1012
  const e = s.toLowerCase();
892
1013
  return e === "post" || e === "put" || e === "patch" || e === "delete";
893
1014
  }
894
- function P(s, e) {
1015
+ function U(s, e) {
895
1016
  const t = new URL(e);
896
- return s.some((n) => t.pathname.includes(n));
1017
+ return s.some((r) => t.pathname.includes(r));
897
1018
  }
898
- function Oe(s, e = {}) {
899
- const t = xe(s, e);
900
- async function n(i) {
901
- const r = await t(i);
902
- return fetch(r[0], r[1]);
1019
+ function ot(s, e = {}) {
1020
+ const t = nt(s, e);
1021
+ async function r(n) {
1022
+ const i = await t(n);
1023
+ return fetch(i[0], i[1]);
903
1024
  }
904
- return (i, r) => r ? r.applyRetry(async () => n(i)) : n(i);
1025
+ return (n, i) => i ? i.applyRetry(async () => r(n)) : r(n);
905
1026
  }
906
- const Fe = [400, 401, 403];
907
- class Ne extends N {
1027
+ const at = [400, 401, 403];
1028
+ class ct extends re {
908
1029
  constructor(e) {
909
1030
  super(e), this.csrfTokenManager = e;
910
1031
  }
@@ -912,7 +1033,7 @@ class Ne extends N {
912
1033
  * Determines if a failed request should be retried due to CSRF token issues.
913
1034
  */
914
1035
  async shouldRetry(e, t) {
915
- return t.attempt >= 1 ? !1 : Fe.includes(e.status);
1036
+ return t.attempt >= 1 ? !1 : at.includes(e.status);
916
1037
  }
917
1038
  /**
918
1039
  * CSRF token refresh should happen immediately with no delay.
@@ -930,7 +1051,7 @@ class Ne extends N {
930
1051
  await this.csrfTokenManager.refreshToken();
931
1052
  }
932
1053
  }
933
- class Ue {
1054
+ class lt {
934
1055
  constructor(e, t) {
935
1056
  this.endpoint = e, this.cacheName = t, this.tokenPromise = this.obtainToken();
936
1057
  }
@@ -959,10 +1080,10 @@ class Ue {
959
1080
  * @returns Promise that resolves to the CSRF token string
960
1081
  */
961
1082
  async obtainToken() {
962
- let e = await this.withCache((i) => i.match(this.endpoint)), t = !1;
1083
+ let e = await this.withCache((n) => n.match(this.endpoint)), t = !1;
963
1084
  e || (e = await fetch(this.endpoint, { method: "get" }), t = !0);
964
- const n = (await e.clone().json()).csrfToken;
965
- return t && await this.withCache((i) => i.put(this.endpoint, e)), n;
1085
+ const r = (await e.clone().json()).csrfToken;
1086
+ return t && await this.withCache((n) => n.put(this.endpoint, e)), r;
966
1087
  }
967
1088
  /**
968
1089
  * Provides a safe way to interact with the Cache API with fallback for unsupported environments.
@@ -978,56 +1099,242 @@ class Ue {
978
1099
  return;
979
1100
  }
980
1101
  }
981
- const L = /* @__PURE__ */ new Map();
982
- function qe(s) {
983
- const { endpoint: e, cacheName: t, ...n } = s.csrf;
984
- let i = L.get(e);
985
- return i || (i = new Ue(e, t), L.set(e, i)), R(
1102
+ const V = /* @__PURE__ */ new Map();
1103
+ function ut(s) {
1104
+ const { endpoint: e, cacheName: t, ...r } = s.csrf;
1105
+ let n = V.get(e);
1106
+ return n || (n = new lt(e, t), V.set(e, n)), K(
986
1107
  {
987
- retry: Oe(i, n),
988
- request: [Le]
1108
+ retry: ot(n, r),
1109
+ request: [st]
989
1110
  },
990
- U(new Ne(i)).service
1111
+ ne(new ct(n)).service
991
1112
  ).service;
992
1113
  }
993
- function We() {
1114
+ function dt(s) {
1115
+ const e = ie().service, t = ae(e).service, r = oe(e, t).service, n = ce().service;
1116
+ return {
1117
+ cache: e,
1118
+ services: { cacheController: r, pubSub: n, fetch: s }
1119
+ };
1120
+ }
1121
+ function J() {
994
1122
  return {
995
1123
  "Content-Type": "application/json",
996
1124
  Accept: "application/json",
997
1125
  "X-Chatter-Entity-Encoding": "false"
998
1126
  };
999
1127
  }
1000
- const Ve = 1, $e = `@salesforce/platform-sdk_v${Ve}`, O = H(), Be = `${O}/ui-api`;
1001
- class Ke {
1128
+ const W = 300;
1129
+ function ht(s, e) {
1130
+ try {
1131
+ return JSON.parse(JSON.stringify(s));
1132
+ } catch (t) {
1133
+ const r = e || "(anonymous)", n = new TypeError(
1134
+ `HttpGraphQLResourceCacheControlCommand: variables for operation "${r}" must be JSON-serializable. ${t.message}`
1135
+ );
1136
+ throw n.cause = t, n;
1137
+ }
1138
+ }
1139
+ class ft extends le {
1140
+ constructor(e, t, r) {
1141
+ super(t), this.url = r, this.query = e.query, this.normalizedOperationName = e.operationName ?? "", this.normalizedVariables = ht(
1142
+ e.variables ?? {},
1143
+ this.normalizedOperationName
1144
+ );
1145
+ }
1146
+ query;
1147
+ normalizedVariables;
1148
+ normalizedOperationName;
1149
+ get fetchParams() {
1150
+ return [
1151
+ this.url,
1152
+ {
1153
+ method: "POST",
1154
+ headers: J(),
1155
+ body: JSON.stringify({
1156
+ query: this.query,
1157
+ variables: this.normalizedVariables,
1158
+ operationName: this.normalizedOperationName
1159
+ })
1160
+ }
1161
+ ];
1162
+ }
1163
+ buildKey() {
1164
+ return Z({
1165
+ query: this.query,
1166
+ variables: this.normalizedVariables,
1167
+ operationName: this.normalizedOperationName
1168
+ });
1169
+ }
1170
+ /**
1171
+ * Reads from the cache and returns the cache result or error
1172
+ *
1173
+ * In case of a missing or partial result, this should return either a DataNotFoundError or
1174
+ * DataIncompleteError, respectively, in the Error response
1175
+ *
1176
+ * Note that any subclass should JUST try to read the data from the cache here; it should
1177
+ * NOT try to take metadata (eg cache control semantics) into account while reading the
1178
+ * data. The CacheController is responsible for enforcing those semantics.
1179
+ *
1180
+ * @param cache source of cached data
1181
+ * @returns result or error from the cache
1182
+ */
1183
+ readFromCache(e) {
1184
+ const t = this.buildKey(), r = e.get(t)?.value;
1185
+ return r === void 0 ? w(D(new ee())) : w(I(r));
1186
+ }
1187
+ writeToCache(e, t) {
1188
+ if (t.isOk() && t.value.data != null && Object.keys(t.value.data).length > 0) {
1189
+ const r = Math.floor(Date.now() / 1e3);
1190
+ e.set(this.buildKey(), {
1191
+ value: t.value.data,
1192
+ metadata: {
1193
+ cacheControl: {
1194
+ type: "max-age",
1195
+ maxAge: W,
1196
+ generatedTime: r
1197
+ }
1198
+ }
1199
+ });
1200
+ }
1201
+ return w(void 0);
1202
+ }
1203
+ get cacheControlStrategyConfig() {
1204
+ return {
1205
+ type: "max-age",
1206
+ requestMaxAge: W,
1207
+ now: Math.floor(Date.now() / 1e3)
1208
+ };
1209
+ }
1210
+ responseHasErrors(e) {
1211
+ return e.errors && e.errors.length > 0;
1212
+ }
1213
+ processFetchReturnValue(e) {
1214
+ return this.responseHasErrors(e) ? D(new te(e)) : I(e);
1215
+ }
1216
+ }
1217
+ function pt(s) {
1218
+ return (e) => {
1219
+ if (e.isOk()) {
1220
+ const t = e.value;
1221
+ z(t), s({ data: t, errors: void 0 });
1222
+ } else
1223
+ s({ data: void 0, errors: b(e.error) });
1224
+ };
1225
+ }
1226
+ async function gt(s) {
1227
+ let e, t, r;
1228
+ try {
1229
+ const n = await s.execute();
1230
+ n.isOk() ? (e = n.value.data, z(e), r = (i) => n.value.subscribe(i)) : (t = b(n.error.failure), r = (i) => n.error.subscribe(i));
1231
+ } catch (n) {
1232
+ t = b(n);
1233
+ }
1234
+ return {
1235
+ data: e,
1236
+ errors: t,
1237
+ subscribe(n) {
1238
+ return r ? r(pt(n)) : E;
1239
+ },
1240
+ async refresh() {
1241
+ await s.refresh();
1242
+ }
1243
+ };
1244
+ }
1245
+ function M(s) {
1246
+ return {
1247
+ data: void 0,
1248
+ errors: s,
1249
+ subscribe: () => E,
1250
+ refresh: L
1251
+ };
1252
+ }
1253
+ function mt({
1254
+ bundle: s,
1255
+ url: e,
1256
+ executeRaw: t
1257
+ }) {
1258
+ const { services: r } = s;
1259
+ async function n({
1260
+ query: i,
1261
+ variables: o,
1262
+ operationName: a
1263
+ }) {
1264
+ const u = H(i);
1265
+ if (u.isErr()) return M(u.error);
1266
+ const l = u.value, f = q(l, a);
1267
+ if (f !== "query")
1268
+ return M([
1269
+ {
1270
+ message: `DataSDK.graphql.query() requires a GraphQL query, received ${f}.`
1271
+ }
1272
+ ]);
1273
+ let p;
1274
+ try {
1275
+ p = new ft(
1276
+ {
1277
+ query: R(l),
1278
+ variables: o,
1279
+ operationName: a
1280
+ },
1281
+ r,
1282
+ e
1283
+ );
1284
+ } catch (d) {
1285
+ return M(b(d));
1286
+ }
1287
+ return gt(p);
1288
+ }
1289
+ return {
1290
+ query: n,
1291
+ mutate: (i) => j(t, i)
1292
+ };
1293
+ }
1294
+ const yt = 1, wt = `@salesforce/platform-sdk-data_v${yt}`, X = G(), bt = `${X}/ui-api`, $ = `${X}/graphql`;
1295
+ class vt {
1002
1296
  baseUrl;
1003
1297
  clientFetch;
1004
1298
  onStatus;
1299
+ graphql;
1005
1300
  constructor(e) {
1006
- const t = je();
1007
- this.baseUrl = ze(e?.basePath ?? t.apiPath), this.onStatus = e?.onStatus ?? {}, this.clientFetch = qe({
1301
+ const t = Ct();
1302
+ this.baseUrl = St(e?.basePath ?? t.apiPath), this.onStatus = e?.onStatus ?? {}, this.clientFetch = ut({
1008
1303
  csrf: {
1009
- endpoint: `${this.baseUrl}${Be}/session/csrf`,
1010
- cacheName: $e,
1304
+ endpoint: `${this.baseUrl}${bt}/session/csrf`,
1305
+ cacheName: wt,
1011
1306
  protectedUrls: ["services/data/v", "services/apexrest"],
1012
1307
  alwaysProtectedUrls: ["services/apexrest"]
1013
1308
  }
1014
1309
  });
1310
+ const n = dt((i, o) => this.fetch(i, o));
1311
+ this.graphql = mt({
1312
+ bundle: n,
1313
+ url: $,
1314
+ executeRaw: this.executeRawGraphQL.bind(this)
1315
+ });
1015
1316
  }
1016
- async graphql({
1317
+ async fetch(e, t) {
1318
+ const r = this.applySalesforceBase(e), n = await this.clientFetch(r, t);
1319
+ return await this.onStatus[n.status]?.(), n;
1320
+ }
1321
+ /**
1322
+ * Raw GraphQL POST. Used internally by `graphql.mutate` (which has no
1323
+ * cache concern) and transitively by `graphql.query` on cache miss
1324
+ * (the OneStore cache command's fetch service is bound to this same
1325
+ * SDK's `fetch`, which in turn calls this method's caller patterns).
1326
+ */
1327
+ async executeRawGraphQL({
1017
1328
  query: e,
1018
1329
  variables: t,
1019
- operationName: n
1330
+ operationName: r
1020
1331
  }) {
1021
- return (await this.fetch(`${O}/graphql`, {
1332
+ return (await this.fetch($, {
1022
1333
  method: "POST",
1023
- body: JSON.stringify({ query: e, variables: t, operationName: n }),
1024
- headers: We()
1334
+ body: JSON.stringify({ query: e, variables: t, operationName: r }),
1335
+ headers: J()
1025
1336
  })).json();
1026
1337
  }
1027
- async fetch(e, t) {
1028
- const n = this.applySalesforceBase(e), i = await this.clientFetch(n, t);
1029
- return await this.onStatus[i.status]?.(), i;
1030
- }
1031
1338
  /**
1032
1339
  * If the url is relative, convert to it to an absolute Salesforce URL. This is due to the way Code
1033
1340
  * Builder deployments structure the url for Salesforce
@@ -1042,35 +1349,35 @@ class Ke {
1042
1349
  return e;
1043
1350
  }
1044
1351
  }
1045
- function je() {
1352
+ function Ct() {
1046
1353
  return {
1047
1354
  apiPath: globalThis.SFDC_ENV?.apiPath
1048
1355
  };
1049
1356
  }
1050
- function ze(s) {
1357
+ function St(s) {
1051
1358
  if (!s || s === "/") return "";
1052
1359
  let e = s;
1053
1360
  return e.startsWith("/") || (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
1054
1361
  }
1055
- function It(s, ...e) {
1362
+ function as(s, ...e) {
1056
1363
  let t = s[0] ?? "";
1057
- for (let n = 0; n < e.length; n += 1)
1058
- t += String(e[n]) + (s[n + 1] ?? "");
1364
+ for (let r = 0; r < e.length; r += 1)
1365
+ t += String(e[r]) + (s[r + 1] ?? "");
1059
1366
  return t;
1060
1367
  }
1061
- function Mt(s) {
1062
- return A(
1368
+ function cs(s) {
1369
+ return k(
1063
1370
  (async () => {
1064
- switch (T(s?.surface)) {
1065
- case o.OpenAI:
1066
- return new Me();
1067
- case o.WebApp:
1068
- case o.MicroFrontend:
1069
- return new Ke(s?.webapp);
1070
- case o.Mosaic:
1071
- return new Se(s?.mosaic);
1072
- case o.SalesforceACC:
1073
- case o.MCPApps:
1371
+ switch (C(s?.surface)) {
1372
+ case c.OpenAI:
1373
+ return new Xe();
1374
+ case c.WebApp:
1375
+ case c.MicroFrontend:
1376
+ return new vt(s?.webapp);
1377
+ case c.Mosaic:
1378
+ return new je(s?.mosaic);
1379
+ case c.SalesforceACC:
1380
+ case c.MCPApps:
1074
1381
  return {};
1075
1382
  default:
1076
1383
  return {};
@@ -1079,21 +1386,21 @@ function Mt(s) {
1079
1386
  "createDataSDK"
1080
1387
  );
1081
1388
  }
1082
- function Et(s) {
1083
- return A(
1389
+ function ls(s) {
1390
+ return k(
1084
1391
  (async () => {
1085
- switch (T(s?.surface)) {
1086
- case o.OpenAI:
1392
+ switch (C(s?.surface)) {
1393
+ case c.OpenAI:
1087
1394
  return {};
1088
- case o.WebApp:
1395
+ case c.WebApp:
1089
1396
  return {};
1090
- case o.MicroFrontend:
1397
+ case c.MicroFrontend:
1091
1398
  return {};
1092
- case o.SalesforceACC:
1399
+ case c.SalesforceACC:
1093
1400
  return {};
1094
- case o.MCPApps:
1401
+ case c.MCPApps:
1095
1402
  return {};
1096
- case o.Mosaic:
1403
+ case c.Mosaic:
1097
1404
  return {};
1098
1405
  default:
1099
1406
  return {};
@@ -1102,7 +1409,7 @@ function Et(s) {
1102
1409
  "createLightningSDK"
1103
1410
  );
1104
1411
  }
1105
- class Je {
1412
+ class Tt {
1106
1413
  buffer;
1107
1414
  constructor(e) {
1108
1415
  this.buffer = e;
@@ -1114,13 +1421,13 @@ class Je {
1114
1421
  return { ...e, _telemetry: t };
1115
1422
  }
1116
1423
  }
1117
- function Xe(s) {
1424
+ function _t(s) {
1118
1425
  let e = "";
1119
- for (let n = 0; n < s.length; n += 8192)
1120
- e += String.fromCharCode.apply(null, Array.from(s.subarray(n, n + 8192)));
1426
+ for (let r = 0; r < s.length; r += 8192)
1427
+ e += String.fromCharCode.apply(null, Array.from(s.subarray(r, r + 8192)));
1121
1428
  return btoa(e);
1122
1429
  }
1123
- class Ye {
1430
+ class Et {
1124
1431
  entries = [];
1125
1432
  totalBytes = 0;
1126
1433
  maxBufferSize;
@@ -1135,14 +1442,14 @@ class Ye {
1135
1442
  return this.entries.length === 0;
1136
1443
  }
1137
1444
  enqueue(e, t) {
1138
- const n = Xe(e), i = {
1139
- data: n,
1445
+ const r = _t(e), n = {
1446
+ data: r,
1140
1447
  traceId: t?.traceId,
1141
1448
  instanceId: t?.instanceId,
1142
1449
  componentRef: t?.componentRef,
1143
1450
  timestamp: Date.now()
1144
- }, r = n.length;
1145
- this.entries.push(i), this.totalBytes += r, this.totalBytes > this.maxBufferSize && this.evict();
1451
+ }, i = r.length;
1452
+ this.entries.push(n), this.totalBytes += i, this.totalBytes > this.maxBufferSize && this.evict();
1146
1453
  }
1147
1454
  drain() {
1148
1455
  const e = this.entries;
@@ -1157,7 +1464,7 @@ class Ye {
1157
1464
  e > 0 && this.onError?.({ reason: "buffer_overflow", droppedCount: e });
1158
1465
  }
1159
1466
  }
1160
- class Ge {
1467
+ class At {
1161
1468
  buffer;
1162
1469
  sdk;
1163
1470
  timerId = null;
@@ -1168,8 +1475,8 @@ class Ge {
1168
1475
  handlePageHide = () => {
1169
1476
  this.flush();
1170
1477
  };
1171
- constructor(e, t, n) {
1172
- this.buffer = e, this.sdk = t, this.timerId = setInterval(() => this.flush(), n), document.addEventListener("visibilitychange", this.handleVisibilityChange), window.addEventListener("pagehide", this.handlePageHide);
1478
+ constructor(e, t, r) {
1479
+ this.buffer = e, this.sdk = t, this.timerId = setInterval(() => this.flush(), r), document.addEventListener("visibilitychange", this.handleVisibilityChange), window.addEventListener("pagehide", this.handlePageHide);
1173
1480
  }
1174
1481
  flush() {
1175
1482
  if (this.buffer.isEmpty || !this.sdk.setWidgetState)
@@ -1181,37 +1488,37 @@ class Ge {
1181
1488
  this.disposed || (this.disposed = !0, this.timerId !== null && (clearInterval(this.timerId), this.timerId = null), document.removeEventListener("visibilitychange", this.handleVisibilityChange), window.removeEventListener("pagehide", this.handlePageHide), this.flush());
1182
1489
  }
1183
1490
  }
1184
- const Qe = 65536, Ze = 3e4;
1185
- function kt(s) {
1491
+ const kt = 65536, Mt = 3e4;
1492
+ function us(s) {
1186
1493
  const {
1187
1494
  sdk: e,
1188
1495
  flushOnAction: t = !0,
1189
- maxBufferSize: n = Qe,
1190
- flushInterval: i = Ze,
1191
- onError: r
1192
- } = s, a = new Ye({ maxBufferSize: n, onError: r }), c = new Je(a), h = new Ge(a, e, i);
1496
+ maxBufferSize: r = kt,
1497
+ flushInterval: n = Mt,
1498
+ onError: i
1499
+ } = s, o = new Et({ maxBufferSize: r, onError: i }), a = new Tt(o), u = new At(o, e, n);
1193
1500
  return {
1194
- enqueue(d, m) {
1195
- a.enqueue(d, m);
1501
+ enqueue(l, f) {
1502
+ o.enqueue(l, f);
1196
1503
  },
1197
- wrapAction(d) {
1198
- return t ? c.wrapAction(d) : d;
1504
+ wrapAction(l) {
1505
+ return t ? a.wrapAction(l) : l;
1199
1506
  },
1200
1507
  dispose() {
1201
- h.dispose();
1508
+ u.dispose();
1202
1509
  }
1203
1510
  };
1204
1511
  }
1205
- const et = 1e4, tt = 10, st = 10, nt = 250, it = 1e3;
1206
- function y(s, e) {
1512
+ const It = 1e4, Dt = 10, Pt = 10, Lt = 250, Rt = 1e3;
1513
+ function v(s, e) {
1207
1514
  if (s !== void 0 && (typeof s != "number" || !Number.isFinite(s) || s <= 0))
1208
1515
  throw new Error(`${e}, if defined, must be a finite number greater than 0`);
1209
1516
  }
1210
- function rt(s, e) {
1517
+ function xt(s, e) {
1211
1518
  if (typeof s != "function")
1212
1519
  throw new Error(`${e} must be a function`);
1213
1520
  }
1214
- class ot {
1521
+ class Ot {
1215
1522
  _collector;
1216
1523
  _onEnvelope;
1217
1524
  _onError;
@@ -1232,7 +1539,7 @@ class ot {
1232
1539
  _lastClickTriggeredAt = 0;
1233
1540
  _isDisposed = !1;
1234
1541
  constructor(e) {
1235
- rt(e?.onEnvelope, "options.onEnvelope"), y(e.uploadInterval, "options.uploadInterval"), y(e.messagesLimit, "options.messagesLimit"), y(e.metricsLimit, "options.metricsLimit"), y(e.maxUniqueSchemas, "options.maxUniqueSchemas"), y(e.clickUploadDelay, "options.clickUploadDelay"), y(e.clickTriggerCooldown, "options.clickTriggerCooldown"), this._onEnvelope = e.onEnvelope, this._onError = e.onError, this._messagesLimit = e.messagesLimit ?? tt, this._metricsLimit = e.metricsLimit ?? st, this._uploadInterval = e.uploadInterval ?? et, this._clickUploadDelay = e.clickUploadDelay ?? nt, this._clickTriggerCooldown = e.clickTriggerCooldown ?? it, this._enableClickTrigger = e.enableClickTrigger !== !1, this._enableVisibilityTrigger = e.enableVisibilityTrigger !== !1, this._collector = new W({
1542
+ xt(e?.onEnvelope, "options.onEnvelope"), v(e.uploadInterval, "options.uploadInterval"), v(e.messagesLimit, "options.messagesLimit"), v(e.metricsLimit, "options.metricsLimit"), v(e.maxUniqueSchemas, "options.maxUniqueSchemas"), v(e.clickUploadDelay, "options.clickUploadDelay"), v(e.clickTriggerCooldown, "options.clickTriggerCooldown"), this._onEnvelope = e.onEnvelope, this._onError = e.onError, this._messagesLimit = e.messagesLimit ?? Dt, this._metricsLimit = e.metricsLimit ?? Pt, this._uploadInterval = e.uploadInterval ?? It, this._clickUploadDelay = e.clickUploadDelay ?? Lt, this._clickTriggerCooldown = e.clickTriggerCooldown ?? Rt, this._enableClickTrigger = e.enableClickTrigger !== !1, this._enableVisibilityTrigger = e.enableVisibilityTrigger !== !1, this._collector = new de({
1236
1543
  environment: e.environment,
1237
1544
  maxUniqueSchemas: e.maxUniqueSchemas
1238
1545
  }), this._restartInterval(), this._attachWindowListeners();
@@ -1252,11 +1559,11 @@ class ot {
1252
1559
  getIsCollectDisabled() {
1253
1560
  return this._isDisposed;
1254
1561
  }
1255
- collect(e, t, n) {
1562
+ collect(e, t, r) {
1256
1563
  this._collector.collect(
1257
1564
  e,
1258
1565
  t,
1259
- n
1566
+ r
1260
1567
  ), this._shouldFlushForThreshold() && this.flush("threshold");
1261
1568
  }
1262
1569
  receiveMetricsExtractors(e) {
@@ -1312,62 +1619,62 @@ class ot {
1312
1619
  metricsCount: this.metricsCount,
1313
1620
  estimatedByteSize: this.estimatedByteSize,
1314
1621
  triggeredAt: Date.now()
1315
- }, n = this._collector.getRawContentsOfCoreEnvelope(), i = q(n);
1622
+ }, r = this._collector.getRawContentsOfCoreEnvelope(), n = ue(r);
1316
1623
  this._restartInterval();
1317
1624
  try {
1318
- await this._onEnvelope(i, t);
1319
- } catch (r) {
1320
- const a = {
1625
+ await this._onEnvelope(n, t);
1626
+ } catch (i) {
1627
+ const o = {
1321
1628
  ...t,
1322
- error: r
1629
+ error: i
1323
1630
  };
1324
- throw this._onError?.(a), r;
1631
+ throw this._onError?.(o), i;
1325
1632
  }
1326
1633
  }
1327
1634
  }
1328
- function at(s, e) {
1635
+ function Ht(s, e) {
1329
1636
  if (!s)
1330
1637
  throw new Error("instrumentedApp is required");
1331
- const t = new ot(e);
1638
+ const t = new Ot(e);
1332
1639
  return s.registerLogCollector(t), s.registerMetricsCollector(t), e.enableClickTrigger !== !1 && s.activateClickTracker?.(), t;
1333
1640
  }
1334
- function ct(s) {
1335
- const e = (n, i, r, a, c) => {
1336
- s.error(c ?? n);
1337
- }, t = (n) => {
1338
- s.error(n.reason);
1641
+ function qt(s) {
1642
+ const e = (r, n, i, o, a) => {
1643
+ s.error(a ?? r);
1644
+ }, t = (r) => {
1645
+ s.error(r.reason);
1339
1646
  };
1340
1647
  return window.addEventListener("error", e), window.addEventListener("unhandledrejection", t), () => {
1341
1648
  window.removeEventListener("error", e), window.removeEventListener("unhandledrejection", t);
1342
1649
  };
1343
1650
  }
1344
- function p(s, e) {
1651
+ function m(s, e) {
1345
1652
  return { surface: e };
1346
1653
  }
1347
- const lt = {
1654
+ const Nt = {
1348
1655
  callTool: {
1349
1656
  isAsync: !0,
1350
1657
  extractTags: (s, e) => ({ toolName: s[0]?.toolName ?? "unknown", surface: e })
1351
1658
  },
1352
1659
  setWidgetState: {
1353
1660
  isAsync: !1,
1354
- extractTags: p
1661
+ extractTags: m
1355
1662
  },
1356
1663
  getWidgetState: {
1357
1664
  isAsync: !1,
1358
- extractTags: p
1665
+ extractTags: m
1359
1666
  },
1360
1667
  sendMessageToHost: {
1361
1668
  isAsync: !0,
1362
- extractTags: p
1669
+ extractTags: m
1363
1670
  },
1364
1671
  openLink: {
1365
1672
  isAsync: !0,
1366
- extractTags: p
1673
+ extractTags: m
1367
1674
  },
1368
1675
  subscribe: {
1369
1676
  isAsync: !1,
1370
- extractTags: p,
1677
+ extractTags: m,
1371
1678
  wrapArgs: (s, e) => {
1372
1679
  const t = s[0];
1373
1680
  return [
@@ -1387,126 +1694,126 @@ const lt = {
1387
1694
  },
1388
1695
  accessToolOutput: {
1389
1696
  isAsync: !1,
1390
- extractTags: p
1697
+ extractTags: m
1391
1698
  },
1392
1699
  accessToolInput: {
1393
1700
  isAsync: !1,
1394
- extractTags: p
1701
+ extractTags: m
1395
1702
  },
1396
1703
  accessToolMetadata: {
1397
1704
  isAsync: !1,
1398
- extractTags: p
1705
+ extractTags: m
1399
1706
  }
1400
1707
  };
1401
- function ut(s, e, t) {
1708
+ function Ft(s, e, t) {
1402
1709
  return new Proxy(s, {
1403
- get(n, i, r) {
1404
- const a = Reflect.get(n, i, r), c = lt[i];
1405
- return !c || typeof a != "function" ? a : (...h) => {
1406
- const d = c.extractTags(h, t), m = c.wrapArgs ? c.wrapArgs(h, e) : h, w = `sdk.${String(i)}`;
1407
- return c.isAsync ? e.activityAsync(w, async () => {
1710
+ get(r, n, i) {
1711
+ const o = Reflect.get(r, n, i), a = Nt[n];
1712
+ return !a || typeof o != "function" ? o : (...u) => {
1713
+ const l = a.extractTags(u, t), f = a.wrapArgs ? a.wrapArgs(u, e) : u, p = `sdk.${String(n)}`;
1714
+ return a.isAsync ? e.activityAsync(p, async () => {
1408
1715
  try {
1409
- const f = await a.apply(
1410
- n,
1411
- m
1716
+ const d = await o.apply(
1717
+ r,
1718
+ f
1412
1719
  );
1413
- return e.incrementCounter(w, 1, !1, d), f;
1414
- } catch (f) {
1415
- throw e.incrementCounter(w, 1, !0, d), f;
1720
+ return e.incrementCounter(p, 1, !1, l), d;
1721
+ } catch (d) {
1722
+ throw e.incrementCounter(p, 1, !0, l), d;
1416
1723
  }
1417
- }) : (e.incrementCounter(w, 1, !1, d), a.apply(n, m));
1724
+ }) : (e.incrementCounter(p, 1, !1, l), o.apply(r, f));
1418
1725
  };
1419
1726
  }
1420
1727
  });
1421
1728
  }
1422
- async function Dt(s) {
1423
- const { appId: e, clientSessionId: t } = s, n = T(), i = Date.now(), r = s.sdk ?? await fe(), a = V("mcp-widget", {
1729
+ async function ds(s) {
1730
+ const { appId: e, clientSessionId: t } = s, r = C(), n = Date.now(), i = s.sdk ?? await qe(), o = he("mcp-widget", {
1424
1731
  appPayloadProvider: {
1425
1732
  getPayload: () => ({
1426
- schema: $,
1427
- payload: { appId: e, surface: n }
1733
+ schema: fe,
1734
+ payload: { appId: e, surface: r }
1428
1735
  })
1429
1736
  },
1430
1737
  clientSessionId: t
1431
- }), c = a, h = ut(r, c, n), d = ct(c);
1432
- let m;
1738
+ }), a = o, u = Ft(i, a, r), l = qt(a);
1739
+ let f;
1433
1740
  if (s.transport) {
1434
- m = at(a, {
1435
- onEnvelope: (u) => {
1436
- s.transport.enqueue(u);
1741
+ f = Ht(o, {
1742
+ onEnvelope: (g) => {
1743
+ s.transport.enqueue(g);
1437
1744
  }
1438
1745
  });
1439
- const l = h.callTool;
1440
- l && (h.callTool = (u) => {
1441
- const F = s.transport.wrapAction(u.params ?? {});
1442
- return l.call(h, {
1443
- ...u,
1444
- params: F
1746
+ const h = u.callTool;
1747
+ h && (u.callTool = (g) => {
1748
+ const Y = s.transport.wrapAction(g.params ?? {});
1749
+ return h.call(u, {
1750
+ ...g,
1751
+ params: Y
1445
1752
  });
1446
1753
  });
1447
1754
  }
1448
- let w, f = !1;
1755
+ let p, d = !1;
1449
1756
  return {
1450
- instrumentedSDK: h,
1451
- app: a,
1452
- trackEvent(l, u) {
1453
- f || c.log(J, {
1454
- eventName: l,
1455
- properties: u ? JSON.stringify(u) : ""
1757
+ instrumentedSDK: u,
1758
+ app: o,
1759
+ trackEvent(h, g) {
1760
+ d || a.log(we, {
1761
+ eventName: h,
1762
+ properties: g ? JSON.stringify(g) : ""
1456
1763
  });
1457
1764
  },
1458
- trackInteraction(l, u) {
1459
- f || c.log(z, {
1460
- elementId: l,
1461
- properties: u ? JSON.stringify(u) : ""
1765
+ trackInteraction(h, g) {
1766
+ d || a.log(ye, {
1767
+ elementId: h,
1768
+ properties: g ? JSON.stringify(g) : ""
1462
1769
  });
1463
1770
  },
1464
- trackError(l, u) {
1465
- f || c.error(l, j, {
1466
- properties: u ? JSON.stringify(u) : ""
1771
+ trackError(h, g) {
1772
+ d || a.error(h, me, {
1773
+ properties: g ? JSON.stringify(g) : ""
1467
1774
  });
1468
1775
  },
1469
- trackPageView(l) {
1470
- f || l !== w && (w = l, c.log(K, { componentRef: l }));
1776
+ trackPageView(h) {
1777
+ d || h !== p && (p = h, a.log(ge, { componentRef: h }));
1471
1778
  },
1472
1779
  dispose() {
1473
- if (f) return;
1474
- f = !0, d();
1475
- const l = Date.now() - i;
1476
- c.log(B, { durationMs: l }), m?.dispose();
1780
+ if (d) return;
1781
+ d = !0, l();
1782
+ const h = Date.now() - n;
1783
+ a.log(pe, { durationMs: h }), f?.dispose();
1477
1784
  }
1478
1785
  };
1479
1786
  }
1480
1787
  export {
1481
- te as JsonRpcClient,
1482
- ue as MCPAppsChatSDK,
1483
- me as MCPAppsViewSDK,
1484
- g as McpAppsSession,
1485
- Ct as MessageChannelTransport,
1486
- o as Surface,
1487
- ot as TelemetryUploader,
1488
- ee as WindowPostMessageTransport,
1489
- Dt as createAnalytics,
1490
- pe as createChatSDK,
1491
- Mt as createDataSDK,
1492
- Et as createLightningSDK,
1493
- kt as createTelemetryTransport,
1494
- ye as createViewSDK,
1495
- fe as getChatSDK,
1496
- bt as getChatSDKSync,
1497
- T as getSurface,
1498
- Tt as getSurfaceCapabilities,
1499
- St as getViewSDK,
1500
- _t as getViewSDKSync,
1501
- It as gql,
1502
- _ as isJsonRpcBase,
1503
- x as isJsonRpcErrorResponse,
1504
- Z as isJsonRpcNotification,
1505
- yt as isJsonRpcRequest,
1506
- Q as isJsonRpcResponse,
1507
- G as isJsonRpcSuccessResponse,
1508
- at as registerTelemetryUploader,
1509
- vt as resetChatSDK,
1510
- At as resetViewSDK,
1511
- A as wrapSDKPromise
1788
+ Ee as JsonRpcClient,
1789
+ xe as MCPAppsChatSDK,
1790
+ Ue as MCPAppsViewSDK,
1791
+ y as McpAppsSession,
1792
+ es as MessageChannelTransport,
1793
+ c as Surface,
1794
+ Ot as TelemetryUploader,
1795
+ _e as WindowPostMessageTransport,
1796
+ ds as createAnalytics,
1797
+ Ne as createChatSDK,
1798
+ cs as createDataSDK,
1799
+ ls as createLightningSDK,
1800
+ us as createTelemetryTransport,
1801
+ We as createViewSDK,
1802
+ qe as getChatSDK,
1803
+ ss as getChatSDKSync,
1804
+ C as getSurface,
1805
+ ts as getSurfaceCapabilities,
1806
+ ns as getViewSDK,
1807
+ is as getViewSDKSync,
1808
+ as as gql,
1809
+ A as isJsonRpcBase,
1810
+ B as isJsonRpcErrorResponse,
1811
+ Te as isJsonRpcNotification,
1812
+ Zt as isJsonRpcRequest,
1813
+ Se as isJsonRpcResponse,
1814
+ Ce as isJsonRpcSuccessResponse,
1815
+ Ht as registerTelemetryUploader,
1816
+ rs as resetChatSDK,
1817
+ os as resetViewSDK,
1818
+ k as wrapSDKPromise
1512
1819
  };