@salesforce/platform-sdk 9.15.0 → 9.16.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/TelemetryUploader-DKkdppe9.js +135 -0
- package/dist/analytics/index.js +6 -0
- package/dist/analytics-496rdIN5.js +163 -0
- package/dist/chat/index.js +227 -0
- package/dist/core/index.js +107 -0
- package/dist/data/index.js +628 -0
- package/dist/index.js +34 -1766
- package/dist/lightning/index.js +27 -0
- package/dist/mcpapps-session-BOT5CvWa.js +241 -0
- package/dist/sdk-promise-7SpSqah5.js +39 -0
- package/dist/telemetry/index.js +7 -0
- package/dist/transport-D8xgRy7y.js +95 -0
- package/dist/view/index.js +140 -0
- package/package.json +64 -4
package/dist/index.js
CHANGED
|
@@ -1,1768 +1,36 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import {
|
|
6
|
-
import {
|
|
7
|
-
import {
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import {
|
|
11
|
-
import { SimpleCollector as be } from "o11y/simple_collector";
|
|
12
|
-
import { registerInstrumentedApp as ve } from "o11y/client";
|
|
13
|
-
import { analyticsContextSchema as Ce, sessionSchema as Se, pageViewSchema as Te, errorContextSchema as _e, interactionSchema as Ee, customEventSchema as Ie } from "o11y_schema/sf_mcpanalytics";
|
|
14
|
-
var a = /* @__PURE__ */ ((s) => (s.WebApp = "WebApp", s.MicroFrontend = "Micro-Frontend", s.OpenAI = "OpenAI", s.SalesforceACC = "Salesforce-ACC", s.MCPApps = "MCP-Apps", s.Mosaic = "Mosaic", s))(a || {});
|
|
15
|
-
const Ae = Me();
|
|
16
|
-
function Me() {
|
|
17
|
-
if (typeof window > "u")
|
|
18
|
-
return "Mosaic";
|
|
19
|
-
if (window.openai)
|
|
20
|
-
return "OpenAI";
|
|
21
|
-
try {
|
|
22
|
-
if (window.self !== window.top)
|
|
23
|
-
return "Micro-Frontend";
|
|
24
|
-
} catch {
|
|
25
|
-
return "Micro-Frontend";
|
|
26
|
-
}
|
|
27
|
-
const s = window;
|
|
28
|
-
return s.$A || s.Aura ? "Salesforce-ACC" : "WebApp";
|
|
29
|
-
}
|
|
30
|
-
function S(s) {
|
|
31
|
-
return s ?? Ae;
|
|
32
|
-
}
|
|
33
|
-
function X(s) {
|
|
34
|
-
return typeof s == "object" && s !== null && !Array.isArray(s);
|
|
35
|
-
}
|
|
36
|
-
function Y(s) {
|
|
37
|
-
return typeof s.id == "number" && Number.isInteger(s.id) && s.id >= 0;
|
|
38
|
-
}
|
|
39
|
-
function H(s) {
|
|
40
|
-
return X(s) && s.jsonrpc === "2.0";
|
|
41
|
-
}
|
|
42
|
-
function ke(s) {
|
|
43
|
-
if (!H(s)) return !1;
|
|
44
|
-
const e = s;
|
|
45
|
-
return !("id" in e) && typeof e.method == "string";
|
|
46
|
-
}
|
|
47
|
-
function De(s) {
|
|
48
|
-
if (!H(s)) return !1;
|
|
49
|
-
const e = s;
|
|
50
|
-
return Y(e) && "result" in e && !("error" in e) && !("method" in e);
|
|
51
|
-
}
|
|
52
|
-
function Z(s) {
|
|
53
|
-
if (!H(s)) return !1;
|
|
54
|
-
const e = s;
|
|
55
|
-
if (!Y(e) || "result" in e || "method" in e) return !1;
|
|
56
|
-
const t = e.error;
|
|
57
|
-
return X(t) && typeof t.code == "number";
|
|
58
|
-
}
|
|
59
|
-
function Pe(s) {
|
|
60
|
-
return De(s) || Z(s);
|
|
61
|
-
}
|
|
62
|
-
class Le {
|
|
63
|
-
nextRequestId = 1;
|
|
64
|
-
pending = /* @__PURE__ */ new Map();
|
|
65
|
-
notificationHandlers = /* @__PURE__ */ new Map();
|
|
66
|
-
transport;
|
|
67
|
-
/**
|
|
68
|
-
* Construct a JSON-RPC client bound to the given transport.
|
|
69
|
-
*
|
|
70
|
-
* @param transport - the transport to use.
|
|
71
|
-
*/
|
|
72
|
-
constructor(e) {
|
|
73
|
-
this.transport = e, this.transport.onMessage(this.onMessage);
|
|
74
|
-
}
|
|
75
|
-
/**
|
|
76
|
-
* Register a handler for a specific JSON-RPC notification method.
|
|
77
|
-
*
|
|
78
|
-
* Subclasses can register handlers to process specific notification
|
|
79
|
-
* types. When a notification with the registered method is received,
|
|
80
|
-
* the handler will be invoked with the notification params.
|
|
81
|
-
*
|
|
82
|
-
* @param method - The notification method to handle (e.g.
|
|
83
|
-
* "ui/notifications/host-context-changed")
|
|
84
|
-
* @param handler - Callback function to process the notification params
|
|
85
|
-
*
|
|
86
|
-
* @example
|
|
87
|
-
* this.registerNotificationHandler("ui/notifications/host-context-changed", (params) => {
|
|
88
|
-
* this.handleHostContextChanged(params);
|
|
89
|
-
* });
|
|
90
|
-
*/
|
|
91
|
-
registerNotificationHandler(e, t) {
|
|
92
|
-
this.notificationHandlers.has(e) || this.notificationHandlers.set(e, /* @__PURE__ */ new Set()), this.notificationHandlers.get(e).add(t);
|
|
93
|
-
}
|
|
94
|
-
/**
|
|
95
|
-
* Handle inbound JSON-RPC messages from the transport.
|
|
96
|
-
*
|
|
97
|
-
* Processes both responses (for requests) and notifications.
|
|
98
|
-
* Non-JSON-RPC payloads are silently ignored so that a shared transport
|
|
99
|
-
* can be used for multiple protocols without cross-talk.
|
|
100
|
-
*/
|
|
101
|
-
onMessage = (e) => {
|
|
102
|
-
if (Pe(e)) {
|
|
103
|
-
const t = this.pending.get(e.id);
|
|
104
|
-
if (!t)
|
|
105
|
-
return;
|
|
106
|
-
this.pending.delete(e.id), Z(e) ? t.reject(new Error(e.error.message || "Request failed")) : t.resolve(e.result);
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
if (ke(e)) {
|
|
110
|
-
const t = this.notificationHandlers.get(e.method);
|
|
111
|
-
t && t.forEach((r) => r(e.params));
|
|
112
|
-
}
|
|
113
|
-
};
|
|
114
|
-
/**
|
|
115
|
-
* Send a JSON-RPC request to the peer.
|
|
116
|
-
*
|
|
117
|
-
* @param method - The JSON-RPC method name
|
|
118
|
-
* @param params - The method parameters
|
|
119
|
-
* @returns Promise that resolves with the result or rejects with error
|
|
120
|
-
*
|
|
121
|
-
* @example
|
|
122
|
-
* const result = await this.request("ui/message", {
|
|
123
|
-
* role: "user",
|
|
124
|
-
* content: { type: "text", text: "Hello" }
|
|
125
|
-
* });
|
|
126
|
-
*/
|
|
127
|
-
request(e, t) {
|
|
128
|
-
const r = this.nextRequestId++, n = {
|
|
129
|
-
jsonrpc: "2.0",
|
|
130
|
-
id: r,
|
|
131
|
-
method: e,
|
|
132
|
-
params: t
|
|
133
|
-
};
|
|
134
|
-
return new Promise((i, o) => {
|
|
135
|
-
this.pending.set(r, {
|
|
136
|
-
resolve: i,
|
|
137
|
-
reject: o
|
|
138
|
-
}), this.transport.post(n);
|
|
139
|
-
});
|
|
140
|
-
}
|
|
141
|
-
/**
|
|
142
|
-
* Send a JSON-RPC notification to the peer.
|
|
143
|
-
*
|
|
144
|
-
* Notifications are one-way messages that do not expect a response.
|
|
145
|
-
* Use notifications for:
|
|
146
|
-
* - Informing the host of state changes
|
|
147
|
-
* - Fire-and-forget operations
|
|
148
|
-
* - Events that don't require confirmation
|
|
149
|
-
*
|
|
150
|
-
* Use request() instead when you need:
|
|
151
|
-
* - A response from the host
|
|
152
|
-
* - Confirmation of success/failure
|
|
153
|
-
* - Return values from the operation
|
|
154
|
-
*
|
|
155
|
-
* @param method - The JSON-RPC method name
|
|
156
|
-
* @param params - Optional method parameters
|
|
157
|
-
*
|
|
158
|
-
* @example
|
|
159
|
-
* this.sendNotification("ui/notifications/size-changed", {
|
|
160
|
-
* width: 800,
|
|
161
|
-
* height: 600
|
|
162
|
-
* });
|
|
163
|
-
*/
|
|
164
|
-
sendNotification(e, t) {
|
|
165
|
-
const r = {
|
|
166
|
-
jsonrpc: "2.0",
|
|
167
|
-
method: e,
|
|
168
|
-
params: t
|
|
169
|
-
};
|
|
170
|
-
this.transport.post(r);
|
|
171
|
-
}
|
|
172
|
-
}
|
|
173
|
-
class xe {
|
|
174
|
-
targetOrigin;
|
|
175
|
-
/**
|
|
176
|
-
* @param targetOrigin - origin passed as the second argument to
|
|
177
|
-
* `window.parent.postMessage`.
|
|
178
|
-
*/
|
|
179
|
-
constructor(e) {
|
|
180
|
-
this.targetOrigin = e;
|
|
181
|
-
}
|
|
182
|
-
post(e) {
|
|
183
|
-
window.parent?.postMessage(e, this.targetOrigin);
|
|
184
|
-
}
|
|
185
|
-
onMessage(e) {
|
|
186
|
-
const t = (r) => {
|
|
187
|
-
e(r.data);
|
|
188
|
-
};
|
|
189
|
-
return window.addEventListener("message", t), () => window.removeEventListener("message", t);
|
|
190
|
-
}
|
|
191
|
-
}
|
|
192
|
-
const Oe = 500, He = "2026-01-26";
|
|
193
|
-
class w extends Le {
|
|
194
|
-
static initPromise = null;
|
|
195
|
-
hostCtx = {};
|
|
196
|
-
_handshakeSucceeded = !1;
|
|
197
|
-
/**
|
|
198
|
-
* Get or create the shared session singleton.
|
|
199
|
-
*
|
|
200
|
-
* The first call performs the SEP-1865 handshake. Concurrent and subsequent
|
|
201
|
-
* calls reuse the same session and handshake result.
|
|
202
|
-
*
|
|
203
|
-
* @param options - Optional configuration. `targetOrigin` defaults to `"*"`
|
|
204
|
-
* when omitted; pin to the concrete MCP host origin whenever known.
|
|
205
|
-
*/
|
|
206
|
-
static async getInstance(e) {
|
|
207
|
-
if (!w.initPromise) {
|
|
208
|
-
const t = e?.targetOrigin ?? "*";
|
|
209
|
-
w.initPromise = (async () => {
|
|
210
|
-
const r = new w(new xe(t));
|
|
211
|
-
return await r.handshake(e), r;
|
|
212
|
-
})();
|
|
213
|
-
}
|
|
214
|
-
return w.initPromise;
|
|
215
|
-
}
|
|
216
|
-
/**
|
|
217
|
-
* Reset the singleton (for testing only).
|
|
218
|
-
* @internal
|
|
219
|
-
*/
|
|
220
|
-
static resetInstance() {
|
|
221
|
-
w.initPromise = null;
|
|
222
|
-
}
|
|
223
|
-
/**
|
|
224
|
-
* Perform the ui/initialize → hostContext → ui/notifications/initialized handshake.
|
|
225
|
-
*
|
|
226
|
-
* On success, stores the host context and sends the initialized notification.
|
|
227
|
-
* On timeout or error, falls back to an empty host context so the app can
|
|
228
|
-
* still render (graceful degradation for non-SEP-1865 hosts).
|
|
229
|
-
*/
|
|
230
|
-
async handshake(e) {
|
|
231
|
-
const t = e?.handshakeTimeoutMs ?? Oe, r = e?.appInfo ?? { name: "mcp-app", version: "1.0.0" };
|
|
232
|
-
try {
|
|
233
|
-
const n = /* @__PURE__ */ Symbol("timeout"), i = await Promise.race([
|
|
234
|
-
this.request("ui/initialize", {
|
|
235
|
-
protocolVersion: He,
|
|
236
|
-
appInfo: r,
|
|
237
|
-
appCapabilities: {}
|
|
238
|
-
}),
|
|
239
|
-
new Promise((o) => setTimeout(() => o(n), t))
|
|
240
|
-
]);
|
|
241
|
-
i !== n && (this.hostCtx = i.hostContext ?? {}, this._handshakeSucceeded = !0, this.registerNotificationHandler("ui/notifications/host-context-changed", (o) => {
|
|
242
|
-
this.hostCtx = {
|
|
243
|
-
...this.hostCtx,
|
|
244
|
-
...o
|
|
245
|
-
};
|
|
246
|
-
}), this.sendNotification("ui/notifications/initialized"));
|
|
247
|
-
} catch {
|
|
248
|
-
}
|
|
249
|
-
}
|
|
250
|
-
/** Returns the current host context (handshake + notification updates). */
|
|
251
|
-
getHostContext() {
|
|
252
|
-
return this.hostCtx;
|
|
253
|
-
}
|
|
254
|
-
/** Whether the ui/initialize handshake completed successfully (not timed out). */
|
|
255
|
-
get handshakeSucceeded() {
|
|
256
|
-
return this._handshakeSucceeded;
|
|
257
|
-
}
|
|
258
|
-
// ── Public wrappers ──────────────────────────────────────────────────
|
|
259
|
-
// Widen access from protected to public so SDK classes can use the
|
|
260
|
-
// shared transport without extending JsonRpcClient themselves.
|
|
261
|
-
request(e, t) {
|
|
262
|
-
return super.request(e, t);
|
|
263
|
-
}
|
|
264
|
-
sendNotification(e, t) {
|
|
265
|
-
super.sendNotification(e, t);
|
|
266
|
-
}
|
|
267
|
-
registerNotificationHandler(e, t) {
|
|
268
|
-
super.registerNotificationHandler(e, t);
|
|
269
|
-
}
|
|
270
|
-
}
|
|
271
|
-
const Re = {
|
|
272
|
-
callTool: !0,
|
|
273
|
-
sendMessageToHost: !0,
|
|
274
|
-
readResource: !0,
|
|
275
|
-
openLink: !0,
|
|
276
|
-
accessToolInput: !0,
|
|
277
|
-
accessToolOutput: !0,
|
|
278
|
-
accessToolMetadata: !0,
|
|
279
|
-
getWidgetState: !0,
|
|
280
|
-
setWidgetState: !0,
|
|
281
|
-
setWidgetStateModelContext: !0,
|
|
282
|
-
onToolCanceled: !0,
|
|
283
|
-
setDisplayMode: !0,
|
|
284
|
-
getHostContext: !0,
|
|
285
|
-
subscribe: !0,
|
|
286
|
-
displayAlert: !0,
|
|
287
|
-
displayToast: !0,
|
|
288
|
-
displayModal: !1,
|
|
289
|
-
// TODO
|
|
290
|
-
getTheme: !0,
|
|
291
|
-
resize: !0
|
|
292
|
-
}, qe = {
|
|
293
|
-
callTool: !0,
|
|
294
|
-
sendMessageToHost: !0,
|
|
295
|
-
readResource: !1,
|
|
296
|
-
openLink: !0,
|
|
297
|
-
accessToolInput: !0,
|
|
298
|
-
accessToolOutput: !0,
|
|
299
|
-
accessToolMetadata: !0,
|
|
300
|
-
getWidgetState: !0,
|
|
301
|
-
setWidgetState: !0,
|
|
302
|
-
setWidgetStateModelContext: !1,
|
|
303
|
-
onToolCanceled: !1,
|
|
304
|
-
setDisplayMode: !0,
|
|
305
|
-
getHostContext: !1,
|
|
306
|
-
subscribe: !0,
|
|
307
|
-
displayAlert: !0,
|
|
308
|
-
displayToast: !0,
|
|
309
|
-
displayModal: !0,
|
|
310
|
-
getTheme: !0,
|
|
311
|
-
resize: !1
|
|
312
|
-
}, Ne = {
|
|
313
|
-
callTool: !1,
|
|
314
|
-
sendMessageToHost: !0,
|
|
315
|
-
readResource: !1,
|
|
316
|
-
openLink: !0,
|
|
317
|
-
accessToolInput: !1,
|
|
318
|
-
accessToolOutput: !1,
|
|
319
|
-
accessToolMetadata: !1,
|
|
320
|
-
getWidgetState: !1,
|
|
321
|
-
setWidgetState: !1,
|
|
322
|
-
setWidgetStateModelContext: !1,
|
|
323
|
-
onToolCanceled: !1,
|
|
324
|
-
setDisplayMode: !1,
|
|
325
|
-
getHostContext: !1,
|
|
326
|
-
subscribe: !0,
|
|
327
|
-
displayAlert: !0,
|
|
328
|
-
displayToast: !0,
|
|
329
|
-
displayModal: !1,
|
|
330
|
-
getTheme: !0,
|
|
331
|
-
resize: !1
|
|
332
|
-
}, Fe = {
|
|
333
|
-
callTool: !1,
|
|
334
|
-
sendMessageToHost: !1,
|
|
335
|
-
readResource: !1,
|
|
336
|
-
openLink: !1,
|
|
337
|
-
accessToolInput: !1,
|
|
338
|
-
accessToolOutput: !1,
|
|
339
|
-
accessToolMetadata: !1,
|
|
340
|
-
getWidgetState: !1,
|
|
341
|
-
setWidgetState: !1,
|
|
342
|
-
setWidgetStateModelContext: !1,
|
|
343
|
-
onToolCanceled: !1,
|
|
344
|
-
setDisplayMode: !1,
|
|
345
|
-
getHostContext: !1,
|
|
346
|
-
subscribe: !1,
|
|
347
|
-
displayAlert: !1,
|
|
348
|
-
displayToast: !1,
|
|
349
|
-
displayModal: !1,
|
|
350
|
-
getTheme: !1,
|
|
351
|
-
resize: !1
|
|
352
|
-
};
|
|
353
|
-
function ds(s) {
|
|
354
|
-
switch (s) {
|
|
355
|
-
case a.MCPApps:
|
|
356
|
-
return { ...Re };
|
|
357
|
-
case a.OpenAI:
|
|
358
|
-
return { ...qe };
|
|
359
|
-
case a.SalesforceACC:
|
|
360
|
-
return { ...Ne };
|
|
361
|
-
case a.Mosaic:
|
|
362
|
-
case a.WebApp:
|
|
363
|
-
case a.MicroFrontend:
|
|
364
|
-
default:
|
|
365
|
-
return { ...Fe };
|
|
366
|
-
}
|
|
367
|
-
}
|
|
368
|
-
const Ue = /* @__PURE__ */ new Set(["then", "catch", "finally"]);
|
|
369
|
-
function M(s, e) {
|
|
370
|
-
return new Proxy(s, {
|
|
371
|
-
get(t, r, n) {
|
|
372
|
-
if (typeof r == "symbol" || Ue.has(r)) {
|
|
373
|
-
const i = Reflect.get(t, r, n);
|
|
374
|
-
return typeof i == "function" ? i.bind(t) : i;
|
|
375
|
-
}
|
|
376
|
-
throw new TypeError(
|
|
377
|
-
`\`${e}()\` returns a Promise — did you forget to await it?
|
|
378
|
-
Use \`const sdk = await ${e}();\` before accessing SDK methods.`
|
|
379
|
-
);
|
|
380
|
-
}
|
|
381
|
-
});
|
|
382
|
-
}
|
|
383
|
-
class Ve {
|
|
384
|
-
constructor(e) {
|
|
385
|
-
this.session = e;
|
|
386
|
-
const t = e.getHostContext();
|
|
387
|
-
t.toolOutput !== void 0 && (this.globals.toolOutput = t.toolOutput), t.toolStructuredContent !== void 0 && (this.globals.toolStructuredContent = t.toolStructuredContent), t.toolInput !== void 0 && (this.globals.toolInput = t.toolInput), t.toolResponseMetadata !== void 0 && (this.globals.toolResponseMetadata = t.toolResponseMetadata), t.widgetState !== void 0 && (this.globals.widgetState = t.widgetState), e.registerNotificationHandler(
|
|
388
|
-
"ui/notifications/host-context-changed",
|
|
389
|
-
() => this.notifySubscribers()
|
|
390
|
-
), e.registerNotificationHandler(
|
|
391
|
-
"ui/notifications/tool-result",
|
|
392
|
-
(r) => this.handleToolResult(r)
|
|
393
|
-
), e.registerNotificationHandler(
|
|
394
|
-
"ui/notifications/tool-input",
|
|
395
|
-
(r) => this.handleToolInput(r)
|
|
396
|
-
), e.registerNotificationHandler(
|
|
397
|
-
"ui/notifications/tool-cancelled",
|
|
398
|
-
(r) => this.handleToolCancelled(r)
|
|
399
|
-
);
|
|
400
|
-
}
|
|
401
|
-
globals = {};
|
|
402
|
-
canceledCallbacks = /* @__PURE__ */ new Set();
|
|
403
|
-
subscriptions = /* @__PURE__ */ new Set();
|
|
404
|
-
/**
|
|
405
|
-
* Handle tool result notifications from the host
|
|
406
|
-
* @param params - Tool result data from the host
|
|
407
|
-
*/
|
|
408
|
-
handleToolResult(e) {
|
|
409
|
-
const t = e;
|
|
410
|
-
let r = !1;
|
|
411
|
-
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();
|
|
412
|
-
}
|
|
413
|
-
/**
|
|
414
|
-
* Handle tool input notifications from the host
|
|
415
|
-
* @param params - Tool input data from the host
|
|
416
|
-
*/
|
|
417
|
-
handleToolInput(e) {
|
|
418
|
-
const t = e;
|
|
419
|
-
t.arguments !== void 0 && Object.keys(t.arguments).length > 0 && (this.globals.toolInput = t.arguments, this.notifySubscribers());
|
|
420
|
-
}
|
|
421
|
-
/**
|
|
422
|
-
* Handle tool cancelled notifications from the host
|
|
423
|
-
* @param params - Tool cancellation data from the host
|
|
424
|
-
*/
|
|
425
|
-
handleToolCancelled(e) {
|
|
426
|
-
const r = e.reason ?? "";
|
|
427
|
-
this.canceledCallbacks.forEach((n) => n(r));
|
|
428
|
-
}
|
|
429
|
-
/**
|
|
430
|
-
* Request display mode change from host
|
|
431
|
-
* @param mode - The requested display mode
|
|
432
|
-
* @returns Promise with the new display mode (confirmed by host)
|
|
433
|
-
*/
|
|
434
|
-
async setDisplayMode(e) {
|
|
435
|
-
return await this.session.request("ui/request-display-mode", {
|
|
436
|
-
displayMode: e
|
|
437
|
-
});
|
|
438
|
-
}
|
|
439
|
-
async sendMessageToHost(e) {
|
|
440
|
-
await this.session.request("ui/message", {
|
|
441
|
-
role: "user",
|
|
442
|
-
content: [
|
|
443
|
-
{
|
|
444
|
-
type: "text",
|
|
445
|
-
text: e.content
|
|
446
|
-
}
|
|
447
|
-
]
|
|
448
|
-
});
|
|
449
|
-
}
|
|
450
|
-
async callTool(e) {
|
|
451
|
-
return await this.session.request("tools/call", {
|
|
452
|
-
name: e.toolName,
|
|
453
|
-
arguments: e.params ?? {}
|
|
454
|
-
});
|
|
455
|
-
}
|
|
456
|
-
async readResource(e) {
|
|
457
|
-
return await this.session.request("resources/read", {
|
|
458
|
-
uri: e.uri
|
|
459
|
-
});
|
|
460
|
-
}
|
|
461
|
-
async openLink(e) {
|
|
462
|
-
await this.session.request("ui/open-link", { url: e });
|
|
463
|
-
}
|
|
464
|
-
accessToolInput() {
|
|
465
|
-
const e = this.globals.toolInput;
|
|
466
|
-
return e ? { data: e } : null;
|
|
467
|
-
}
|
|
468
|
-
accessToolOutput() {
|
|
469
|
-
const e = this.globals.toolStructuredContent;
|
|
470
|
-
if (e)
|
|
471
|
-
return { data: e };
|
|
472
|
-
const t = this.globals.toolOutput;
|
|
473
|
-
return t ? { data: t } : null;
|
|
474
|
-
}
|
|
475
|
-
accessToolMetadata() {
|
|
476
|
-
if (this.globals.toolResponseMetadata)
|
|
477
|
-
return this.globals.toolResponseMetadata;
|
|
478
|
-
const e = this.session.getHostContext().toolInfo;
|
|
479
|
-
return e || null;
|
|
480
|
-
}
|
|
481
|
-
getWidgetState() {
|
|
482
|
-
const e = this.globals.widgetState;
|
|
483
|
-
return e || null;
|
|
484
|
-
}
|
|
485
|
-
setWidgetState(e, t) {
|
|
486
|
-
this.globals.widgetState = e;
|
|
487
|
-
const r = { state: e };
|
|
488
|
-
t?.content !== void 0 && (r.content = t.content), t?.structuredContent !== void 0 && (r.structuredContent = t.structuredContent), this.session.request("ui/update-model-context", r).catch(() => {
|
|
489
|
-
}), this.notifySubscribers();
|
|
490
|
-
}
|
|
491
|
-
/**
|
|
492
|
-
* Get the current host context.
|
|
493
|
-
*
|
|
494
|
-
* Maps MCP Apps wire-format fields to the protocol-agnostic HostContext.
|
|
495
|
-
* Always returns an object (empty `{}` when no context has been received).
|
|
496
|
-
*/
|
|
497
|
-
getHostContext() {
|
|
498
|
-
const e = this.session.getHostContext(), t = {};
|
|
499
|
-
if (e.theme !== void 0 && (t.theme = e.theme), e.displayMode !== void 0 && (t.displayMode = e.displayMode), e.containerDimensions !== void 0) {
|
|
500
|
-
const r = e.containerDimensions.maxHeight ?? e.containerDimensions.height;
|
|
501
|
-
r !== void 0 && (t.maxHeight = r);
|
|
502
|
-
}
|
|
503
|
-
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;
|
|
504
|
-
}
|
|
505
|
-
onToolCanceled(e) {
|
|
506
|
-
return this.canceledCallbacks.add(e), () => {
|
|
507
|
-
this.canceledCallbacks.delete(e);
|
|
508
|
-
};
|
|
509
|
-
}
|
|
510
|
-
subscribe(e) {
|
|
511
|
-
return this.subscriptions.add(e), () => {
|
|
512
|
-
this.subscriptions.delete(e);
|
|
513
|
-
};
|
|
514
|
-
}
|
|
515
|
-
notifySubscribers() {
|
|
516
|
-
this.subscriptions.forEach((e) => e());
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
const U = "openai:set_globals";
|
|
520
|
-
class $e {
|
|
521
|
-
sendMessageToHost(e) {
|
|
522
|
-
return window.openai.sendFollowUpMessage({ prompt: e.content });
|
|
523
|
-
}
|
|
524
|
-
callTool(e) {
|
|
525
|
-
return window.openai.callTool(e.toolName, e.params ?? {});
|
|
526
|
-
}
|
|
527
|
-
accessToolInput() {
|
|
528
|
-
const e = window.openai.toolInput;
|
|
529
|
-
return e ? { data: e } : null;
|
|
530
|
-
}
|
|
531
|
-
accessToolOutput() {
|
|
532
|
-
const e = window.openai.toolOutput;
|
|
533
|
-
return e ? { data: e } : null;
|
|
534
|
-
}
|
|
535
|
-
accessToolMetadata() {
|
|
536
|
-
const e = window.openai.toolResponseMetadata;
|
|
537
|
-
return e || null;
|
|
538
|
-
}
|
|
539
|
-
getWidgetState() {
|
|
540
|
-
const e = window.openai.widgetState;
|
|
541
|
-
return e || null;
|
|
542
|
-
}
|
|
543
|
-
setWidgetState(e, t) {
|
|
544
|
-
window.openai.setWidgetState(e);
|
|
545
|
-
}
|
|
546
|
-
async openLink(e) {
|
|
547
|
-
const t = window.openai;
|
|
548
|
-
typeof t?.openExternal == "function" ? await t.openExternal({ href: e }) : window.open(e, "_blank", "noopener,noreferrer");
|
|
549
|
-
}
|
|
550
|
-
async setDisplayMode(e) {
|
|
551
|
-
return window.openai.requestDisplayMode({ mode: e });
|
|
552
|
-
}
|
|
553
|
-
subscribe(e) {
|
|
554
|
-
const t = () => e();
|
|
555
|
-
return window.addEventListener(U, t), () => {
|
|
556
|
-
window.removeEventListener(U, t);
|
|
557
|
-
};
|
|
558
|
-
}
|
|
559
|
-
}
|
|
560
|
-
class We {
|
|
561
|
-
async sendMessageToHost(e) {
|
|
562
|
-
throw console.warn("SalesforceACCChatSDK.sendMessageToHost: stub implementation", e), new Error("SalesforceACCChatSDK.sendMessageToHost not yet implemented");
|
|
563
|
-
}
|
|
564
|
-
followUpActions() {
|
|
565
|
-
return console.warn("SalesforceACCChatSDK.followUpActions: stub implementation"), [];
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
let T = null, R = null;
|
|
569
|
-
function Ke(s) {
|
|
570
|
-
return T || (T = ze(s).then((e) => (R = e, e))), T;
|
|
571
|
-
}
|
|
572
|
-
function hs() {
|
|
573
|
-
return R;
|
|
574
|
-
}
|
|
575
|
-
function fs() {
|
|
576
|
-
T = null, R = null;
|
|
577
|
-
}
|
|
578
|
-
function ze(s) {
|
|
579
|
-
return M(
|
|
580
|
-
(async () => {
|
|
581
|
-
switch (S(s?.surface)) {
|
|
582
|
-
case a.OpenAI:
|
|
583
|
-
return new $e();
|
|
584
|
-
case a.WebApp:
|
|
585
|
-
case a.Mosaic:
|
|
586
|
-
return {};
|
|
587
|
-
case a.SalesforceACC:
|
|
588
|
-
return new We();
|
|
589
|
-
case a.MicroFrontend:
|
|
590
|
-
case a.MCPApps: {
|
|
591
|
-
const t = await w.getInstance(s?.mcpApps);
|
|
592
|
-
return t.handshakeSucceeded ? new Ve(t) : {};
|
|
593
|
-
}
|
|
594
|
-
default:
|
|
595
|
-
return {};
|
|
596
|
-
}
|
|
597
|
-
})(),
|
|
598
|
-
"createChatSDK"
|
|
599
|
-
);
|
|
600
|
-
}
|
|
601
|
-
function Be(s) {
|
|
602
|
-
switch (s) {
|
|
603
|
-
case "info":
|
|
604
|
-
return "ℹ️";
|
|
605
|
-
case "success":
|
|
606
|
-
return "✅";
|
|
607
|
-
case "warning":
|
|
608
|
-
return "⚠️";
|
|
609
|
-
case "error":
|
|
610
|
-
return "❌";
|
|
611
|
-
default:
|
|
612
|
-
return "ℹ️";
|
|
613
|
-
}
|
|
614
|
-
}
|
|
615
|
-
function L(s, e) {
|
|
616
|
-
return `${Be(e)} ${s}`;
|
|
617
|
-
}
|
|
618
|
-
function V(s, e) {
|
|
619
|
-
const t = s.trim();
|
|
620
|
-
if (t === "")
|
|
621
|
-
return { success: !0, value: void 0 };
|
|
622
|
-
const r = t.match(/^(\d+(?:\.\d+)?)(px)?$/);
|
|
623
|
-
if (!r || !r[1])
|
|
624
|
-
return {
|
|
625
|
-
success: !1,
|
|
626
|
-
error: `Invalid ${e}: "${s}". Only pixel values are supported (e.g., "800px" or "800").`
|
|
627
|
-
};
|
|
628
|
-
const n = parseFloat(r[1]);
|
|
629
|
-
return n < 0 || !isFinite(n) ? {
|
|
630
|
-
success: !1,
|
|
631
|
-
error: `Invalid ${e}: "${s}". Value must be a positive number.`
|
|
632
|
-
} : { success: !0, value: n };
|
|
633
|
-
}
|
|
634
|
-
class je {
|
|
635
|
-
constructor(e) {
|
|
636
|
-
this.session = e;
|
|
637
|
-
}
|
|
638
|
-
/**
|
|
639
|
-
* Send a formatted message to the host via ui/message
|
|
640
|
-
* @param message - The message text
|
|
641
|
-
* @param level - The message severity level (defaults to "info")
|
|
642
|
-
*/
|
|
643
|
-
async sendMessage(e, t = "info") {
|
|
644
|
-
const r = L(e, t);
|
|
645
|
-
await this.session.request("ui/message", {
|
|
646
|
-
role: "user",
|
|
647
|
-
content: [
|
|
648
|
-
{
|
|
649
|
-
type: "text",
|
|
650
|
-
text: r
|
|
651
|
-
}
|
|
652
|
-
]
|
|
653
|
-
});
|
|
654
|
-
}
|
|
655
|
-
async displayAlert(e) {
|
|
656
|
-
await this.sendMessage(e.message, e.level);
|
|
657
|
-
}
|
|
658
|
-
async displayToast(e) {
|
|
659
|
-
await this.sendMessage(e.message, e.level);
|
|
660
|
-
}
|
|
661
|
-
async displayModal(e) {
|
|
662
|
-
return Promise.resolve();
|
|
663
|
-
}
|
|
664
|
-
getTheme() {
|
|
665
|
-
const e = this.session.getHostContext().theme;
|
|
666
|
-
return e ? { mode: e } : null;
|
|
667
|
-
}
|
|
668
|
-
async resize(e, t) {
|
|
669
|
-
const r = V(e, "width");
|
|
670
|
-
if (!r.success)
|
|
671
|
-
return Promise.reject(new Error(r.error));
|
|
672
|
-
const n = V(t, "height");
|
|
673
|
-
if (!n.success)
|
|
674
|
-
return Promise.reject(new Error(n.error));
|
|
675
|
-
const i = {};
|
|
676
|
-
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();
|
|
677
|
-
}
|
|
678
|
-
}
|
|
679
|
-
class Qe {
|
|
680
|
-
async displayAlert(e) {
|
|
681
|
-
const t = e.level || "info", r = L(e.message, t);
|
|
682
|
-
await window.openai.sendFollowUpMessage({ prompt: r });
|
|
683
|
-
}
|
|
684
|
-
async displayToast(e) {
|
|
685
|
-
const t = e.level || "info", r = L(e.message, t);
|
|
686
|
-
await window.openai.sendFollowUpMessage({ prompt: r });
|
|
687
|
-
}
|
|
688
|
-
async displayModal(e) {
|
|
689
|
-
await window.openai.requestModal({
|
|
690
|
-
template: e.componentReference,
|
|
691
|
-
params: e.params
|
|
692
|
-
});
|
|
693
|
-
}
|
|
694
|
-
getTheme() {
|
|
695
|
-
const e = window.openai.theme;
|
|
696
|
-
return e ? { mode: e } : null;
|
|
697
|
-
}
|
|
698
|
-
}
|
|
699
|
-
let _ = null, q = null;
|
|
700
|
-
function ps(s) {
|
|
701
|
-
return _ || (_ = Ge(s).then((e) => (q = e, e))), _;
|
|
702
|
-
}
|
|
703
|
-
function gs() {
|
|
704
|
-
return q;
|
|
705
|
-
}
|
|
706
|
-
function ms() {
|
|
707
|
-
_ = null, q = null;
|
|
708
|
-
}
|
|
709
|
-
function Ge(s) {
|
|
710
|
-
return M(
|
|
711
|
-
(async () => {
|
|
712
|
-
switch (S(s?.surface)) {
|
|
713
|
-
case a.OpenAI:
|
|
714
|
-
return new Qe();
|
|
715
|
-
case a.WebApp:
|
|
716
|
-
case a.Mosaic:
|
|
717
|
-
return {};
|
|
718
|
-
case a.SalesforceACC:
|
|
719
|
-
return {};
|
|
720
|
-
case a.MicroFrontend:
|
|
721
|
-
case a.MCPApps: {
|
|
722
|
-
const t = await w.getInstance(s?.mcpApps);
|
|
723
|
-
return t.handshakeSucceeded ? new je(t) : {};
|
|
724
|
-
}
|
|
725
|
-
default:
|
|
726
|
-
return {};
|
|
727
|
-
}
|
|
728
|
-
})(),
|
|
729
|
-
"createViewSDK"
|
|
730
|
-
);
|
|
731
|
-
}
|
|
732
|
-
function Je(s) {
|
|
733
|
-
return (e) => {
|
|
734
|
-
const [t, r] = e;
|
|
735
|
-
if (typeof t == "string" && !t.startsWith("http")) {
|
|
736
|
-
const n = t.startsWith("/") ? t : `/${t}`;
|
|
737
|
-
return b([`${s}${n}`, r]);
|
|
738
|
-
}
|
|
739
|
-
return b(e);
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
function Xe(s) {
|
|
743
|
-
return (e) => b(E("Authorization", `Bearer ${s}`, e));
|
|
744
|
-
}
|
|
745
|
-
function Ye(s, e) {
|
|
746
|
-
const t = [];
|
|
747
|
-
return s && t.push(Je(s)), e && t.push(Xe(e)), J({
|
|
748
|
-
request: t
|
|
749
|
-
}).service;
|
|
750
|
-
}
|
|
751
|
-
const A = () => {
|
|
752
|
-
}, x = async () => {
|
|
753
|
-
};
|
|
754
|
-
function N(s) {
|
|
755
|
-
try {
|
|
756
|
-
return D(ue(s));
|
|
757
|
-
} catch (e) {
|
|
758
|
-
return P(v(e));
|
|
759
|
-
}
|
|
760
|
-
}
|
|
761
|
-
function F(s, e) {
|
|
762
|
-
const t = s.definitions.filter(
|
|
763
|
-
(r) => r.kind === "OperationDefinition"
|
|
764
|
-
);
|
|
765
|
-
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";
|
|
766
|
-
}
|
|
767
|
-
function v(s) {
|
|
768
|
-
if (s && typeof s == "object" && "data" in s) {
|
|
769
|
-
const e = s.data;
|
|
770
|
-
if (e && typeof e == "object" && "errors" in e && Array.isArray(e.errors))
|
|
771
|
-
return e.errors;
|
|
772
|
-
}
|
|
773
|
-
return s instanceof Error ? [{ message: s.message }] : typeof s == "string" ? [{ message: s }] : [{ message: "Unknown error" }];
|
|
774
|
-
}
|
|
775
|
-
async function ee(s, { mutation: e, variables: t, operationName: r }) {
|
|
776
|
-
const n = N(e);
|
|
777
|
-
if (n.isErr()) return { data: void 0, errors: n.error };
|
|
778
|
-
const i = n.value, o = F(i, r);
|
|
779
|
-
if (o !== "mutation")
|
|
780
|
-
return {
|
|
781
|
-
data: void 0,
|
|
782
|
-
errors: [
|
|
783
|
-
{
|
|
784
|
-
message: `DataSDK.graphql.mutate() requires a GraphQL mutation, received ${o}.`
|
|
785
|
-
}
|
|
786
|
-
]
|
|
787
|
-
};
|
|
788
|
-
try {
|
|
789
|
-
const c = await s({
|
|
790
|
-
query: O(i),
|
|
791
|
-
variables: t,
|
|
792
|
-
operationName: r
|
|
793
|
-
});
|
|
794
|
-
return {
|
|
795
|
-
data: c.data ?? void 0,
|
|
796
|
-
errors: c.errors
|
|
797
|
-
};
|
|
798
|
-
} catch (c) {
|
|
799
|
-
return { data: void 0, errors: v(c) };
|
|
800
|
-
}
|
|
801
|
-
}
|
|
802
|
-
function te(s) {
|
|
803
|
-
function e(r, n, i) {
|
|
804
|
-
return s({
|
|
805
|
-
query: O(r),
|
|
806
|
-
variables: n,
|
|
807
|
-
operationName: i
|
|
808
|
-
}).then(
|
|
809
|
-
(o) => ({
|
|
810
|
-
data: o.data ?? void 0,
|
|
811
|
-
errors: o.errors
|
|
812
|
-
}),
|
|
813
|
-
(o) => ({ data: void 0, errors: v(o) })
|
|
814
|
-
);
|
|
815
|
-
}
|
|
816
|
-
async function t({
|
|
817
|
-
query: r,
|
|
818
|
-
variables: n,
|
|
819
|
-
operationName: i
|
|
820
|
-
}) {
|
|
821
|
-
const o = N(r);
|
|
822
|
-
if (o.isErr())
|
|
823
|
-
return {
|
|
824
|
-
data: void 0,
|
|
825
|
-
errors: o.error,
|
|
826
|
-
subscribe: () => A,
|
|
827
|
-
refresh: x
|
|
828
|
-
};
|
|
829
|
-
const c = o.value, l = F(c, i);
|
|
830
|
-
if (l !== "query")
|
|
831
|
-
return {
|
|
832
|
-
data: void 0,
|
|
833
|
-
errors: [
|
|
834
|
-
{
|
|
835
|
-
message: `DataSDK.graphql.query() requires a GraphQL query, received ${l}.`
|
|
836
|
-
}
|
|
837
|
-
],
|
|
838
|
-
subscribe: () => A,
|
|
839
|
-
refresh: x
|
|
840
|
-
};
|
|
841
|
-
const d = /* @__PURE__ */ new Set(), g = n, f = await e(c, g, i);
|
|
842
|
-
return {
|
|
843
|
-
data: f.data,
|
|
844
|
-
errors: f.errors,
|
|
845
|
-
subscribe(h) {
|
|
846
|
-
return d.add(h), () => {
|
|
847
|
-
d.delete(h);
|
|
848
|
-
};
|
|
849
|
-
},
|
|
850
|
-
async refresh() {
|
|
851
|
-
const h = await e(c, g, i);
|
|
852
|
-
for (const p of d) p(h);
|
|
853
|
-
}
|
|
854
|
-
};
|
|
855
|
-
}
|
|
856
|
-
return {
|
|
857
|
-
query: t,
|
|
858
|
-
mutate: (r) => ee(s, r)
|
|
859
|
-
};
|
|
860
|
-
}
|
|
861
|
-
const Ze = typeof __SF_API_VERSION__ < "u" ? __SF_API_VERSION__ : "65.0";
|
|
862
|
-
function se(s = Ze) {
|
|
863
|
-
return `/services/data/v${s}`;
|
|
864
|
-
}
|
|
865
|
-
class et {
|
|
866
|
-
clientFetch;
|
|
867
|
-
pathData;
|
|
868
|
-
graphql;
|
|
869
|
-
constructor(e) {
|
|
870
|
-
const t = tt(), r = st(e?.instanceUrl ?? t.instanceUrl), n = e?.accessToken ?? t.accessToken;
|
|
871
|
-
this.pathData = se(e?.apiVersion ?? t.apiVersion), this.clientFetch = Ye(r || void 0, n), this.graphql = te(this.executeRawGraphQL.bind(this));
|
|
872
|
-
}
|
|
873
|
-
async executeRawGraphQL({
|
|
874
|
-
query: e,
|
|
875
|
-
variables: t,
|
|
876
|
-
operationName: r
|
|
877
|
-
}) {
|
|
878
|
-
return (await this.clientFetch(`${this.pathData}/graphql`, {
|
|
879
|
-
method: "POST",
|
|
880
|
-
body: JSON.stringify({ query: e, variables: t, operationName: r }),
|
|
881
|
-
headers: {
|
|
882
|
-
"Content-Type": "application/json",
|
|
883
|
-
Accept: "application/json"
|
|
884
|
-
}
|
|
885
|
-
})).json();
|
|
886
|
-
}
|
|
887
|
-
}
|
|
888
|
-
function tt() {
|
|
889
|
-
const s = globalThis.MOSAIC_ENV;
|
|
890
|
-
return {
|
|
891
|
-
instanceUrl: s?.instanceUrl,
|
|
892
|
-
accessToken: s?.accessToken,
|
|
893
|
-
apiVersion: s?.apiVersion
|
|
894
|
-
};
|
|
895
|
-
}
|
|
896
|
-
function st(s) {
|
|
897
|
-
if (!s || s === "/") return "";
|
|
898
|
-
let e = s;
|
|
899
|
-
return !e.startsWith("/") && !e.startsWith("http") && (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
|
|
900
|
-
}
|
|
901
|
-
const rt = "graphqlQuery";
|
|
902
|
-
class nt {
|
|
903
|
-
graphql;
|
|
904
|
-
constructor() {
|
|
905
|
-
this.graphql = te(this.executeRawGraphQL.bind(this));
|
|
906
|
-
}
|
|
907
|
-
async executeRawGraphQL({
|
|
908
|
-
query: e,
|
|
909
|
-
variables: t,
|
|
910
|
-
operationName: r
|
|
911
|
-
}) {
|
|
912
|
-
return (await window.openai.callTool(rt, {
|
|
913
|
-
query: e,
|
|
914
|
-
...t != null ? { variables: t } : {},
|
|
915
|
-
...r != null ? { operationName: r } : {}
|
|
916
|
-
})).structuredContent;
|
|
917
|
-
}
|
|
918
|
-
}
|
|
919
|
-
const it = "X-SFDC-Client-Name", ot = "X-SFDC-Client-Version", at = "@salesforce/platform-sdk", ct = "9.15.0", lt = (s) => {
|
|
920
|
-
let e = E(it, at, s);
|
|
921
|
-
return e = E(ot, ct, e), b(e);
|
|
922
|
-
}, ut = "X-CSRF-Token";
|
|
923
|
-
function dt(s, e = {}) {
|
|
924
|
-
const { protectedUrls: t = [], alwaysProtectedUrls: r = [] } = e;
|
|
925
|
-
return async (n) => {
|
|
926
|
-
const [i, o] = n, c = new Request(i, o);
|
|
927
|
-
if ($(r, c.url) || ht(c.method) && $(t, c.url)) {
|
|
928
|
-
const d = await s.getToken();
|
|
929
|
-
n = E(ut, d, n);
|
|
930
|
-
}
|
|
931
|
-
return b(n);
|
|
932
|
-
};
|
|
933
|
-
}
|
|
934
|
-
function ht(s) {
|
|
935
|
-
const e = s.toLowerCase();
|
|
936
|
-
return e === "post" || e === "put" || e === "patch" || e === "delete";
|
|
937
|
-
}
|
|
938
|
-
function $(s, e) {
|
|
939
|
-
const t = new URL(e);
|
|
940
|
-
return s.some((r) => t.pathname.includes(r));
|
|
941
|
-
}
|
|
942
|
-
function ft(s, e = {}) {
|
|
943
|
-
const t = dt(s, e);
|
|
944
|
-
async function r(n) {
|
|
945
|
-
const i = await t(n);
|
|
946
|
-
return fetch(i[0], i[1]);
|
|
947
|
-
}
|
|
948
|
-
return (n, i) => i ? i.applyRetry(async () => r(n)) : r(n);
|
|
949
|
-
}
|
|
950
|
-
const pt = [400, 401, 403];
|
|
951
|
-
class gt extends de {
|
|
952
|
-
constructor(e) {
|
|
953
|
-
super(e), this.csrfTokenManager = e;
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Determines if a failed request should be retried due to CSRF token issues.
|
|
957
|
-
*/
|
|
958
|
-
async shouldRetry(e, t) {
|
|
959
|
-
return t.attempt >= 1 ? !1 : pt.includes(e.status);
|
|
960
|
-
}
|
|
961
|
-
/**
|
|
962
|
-
* CSRF token refresh should happen immediately with no delay.
|
|
963
|
-
*/
|
|
964
|
-
async calculateDelay(e, t) {
|
|
965
|
-
return 0;
|
|
966
|
-
}
|
|
967
|
-
/**
|
|
968
|
-
* Called by retry service before each retry attempt.
|
|
969
|
-
*
|
|
970
|
-
* @param _result - The failed response that triggered the retry (unused, already validated)
|
|
971
|
-
* @param _context - Current retry context (unused but part of interface)
|
|
972
|
-
*/
|
|
973
|
-
async prepareRetry(e, t) {
|
|
974
|
-
await this.csrfTokenManager.refreshToken();
|
|
975
|
-
}
|
|
976
|
-
}
|
|
977
|
-
class mt {
|
|
978
|
-
constructor(e, t) {
|
|
979
|
-
this.endpoint = e, this.cacheName = t, this.tokenPromise = this.obtainToken();
|
|
980
|
-
}
|
|
981
|
-
tokenPromise;
|
|
982
|
-
refreshPromise;
|
|
983
|
-
/**
|
|
984
|
-
* Returns the current token value as a Promise.
|
|
985
|
-
* Lazy-loads the token on first call (from cache or by fetching).
|
|
986
|
-
*/
|
|
987
|
-
async getToken() {
|
|
988
|
-
return this.tokenPromise;
|
|
989
|
-
}
|
|
990
|
-
/**
|
|
991
|
-
* Obtains and returns a new token value as a promise.
|
|
992
|
-
* This will clear the cached token and fetch a fresh one.
|
|
993
|
-
* If a refresh is already in progress, all callers share the same in-flight promise.
|
|
994
|
-
*/
|
|
995
|
-
refreshToken() {
|
|
996
|
-
return this.refreshPromise || (this.refreshPromise = this.withCache((e) => e.delete(this.endpoint)).then(() => (this.tokenPromise = this.obtainToken(), this.tokenPromise)).finally(() => {
|
|
997
|
-
this.refreshPromise = void 0;
|
|
998
|
-
})), this.refreshPromise;
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Obtains a CSRF token, using cache when available or fetching a new one.
|
|
1002
|
-
*
|
|
1003
|
-
* @returns Promise that resolves to the CSRF token string
|
|
1004
|
-
*/
|
|
1005
|
-
async obtainToken() {
|
|
1006
|
-
let e = await this.withCache((n) => n.match(this.endpoint)), t = !1;
|
|
1007
|
-
e || (e = await fetch(this.endpoint, { method: "get" }), t = !0);
|
|
1008
|
-
const r = (await e.clone().json()).csrfToken;
|
|
1009
|
-
return t && await this.withCache((n) => n.put(this.endpoint, e)), r;
|
|
1010
|
-
}
|
|
1011
|
-
/**
|
|
1012
|
-
* Provides a safe way to interact with the Cache API with fallback for unsupported environments.
|
|
1013
|
-
*
|
|
1014
|
-
* @param callback - Function that receives the cache instance and returns a promise
|
|
1015
|
-
* @returns The result of the callback, or undefined if caches API is not available
|
|
1016
|
-
*/
|
|
1017
|
-
async withCache(e) {
|
|
1018
|
-
if (this.cacheName && caches) {
|
|
1019
|
-
const t = await caches.open(this.cacheName);
|
|
1020
|
-
return e(t);
|
|
1021
|
-
} else
|
|
1022
|
-
return;
|
|
1023
|
-
}
|
|
1024
|
-
}
|
|
1025
|
-
const W = /* @__PURE__ */ new Map();
|
|
1026
|
-
function yt(s) {
|
|
1027
|
-
const { endpoint: e, cacheName: t, ...r } = s.csrf;
|
|
1028
|
-
let n = W.get(e);
|
|
1029
|
-
return n || (n = new mt(e, t), W.set(e, n)), J(
|
|
1030
|
-
{
|
|
1031
|
-
retry: ft(n, r),
|
|
1032
|
-
request: [lt]
|
|
1033
|
-
},
|
|
1034
|
-
he(new gt(n)).service
|
|
1035
|
-
).service;
|
|
1036
|
-
}
|
|
1037
|
-
const K = /* @__PURE__ */ new Map();
|
|
1038
|
-
function wt(s) {
|
|
1039
|
-
let e = K.get(s);
|
|
1040
|
-
if (!e) {
|
|
1041
|
-
const t = fe().service, r = ge(t).service, n = pe(t, r).service, i = me().service;
|
|
1042
|
-
e = { cache: t, cacheController: n, pubSub: i }, K.set(s, e);
|
|
1043
|
-
}
|
|
1044
|
-
return e;
|
|
1045
|
-
}
|
|
1046
|
-
function bt(s, e) {
|
|
1047
|
-
const t = wt(s);
|
|
1048
|
-
return {
|
|
1049
|
-
shared: t,
|
|
1050
|
-
services: {
|
|
1051
|
-
cacheController: t.cacheController,
|
|
1052
|
-
pubSub: t.pubSub,
|
|
1053
|
-
fetch: e
|
|
1054
|
-
}
|
|
1055
|
-
};
|
|
1056
|
-
}
|
|
1057
|
-
function re() {
|
|
1058
|
-
return {
|
|
1059
|
-
"Content-Type": "application/json",
|
|
1060
|
-
Accept: "application/json",
|
|
1061
|
-
"X-Chatter-Entity-Encoding": "false"
|
|
1062
|
-
};
|
|
1063
|
-
}
|
|
1064
|
-
const z = 300;
|
|
1065
|
-
function vt(s, e) {
|
|
1066
|
-
try {
|
|
1067
|
-
return JSON.parse(JSON.stringify(s));
|
|
1068
|
-
} catch (t) {
|
|
1069
|
-
const r = e || "(anonymous)", n = new TypeError(
|
|
1070
|
-
`HttpGraphQLResourceCacheControlCommand: variables for operation "${r}" must be JSON-serializable. ${t.message}`
|
|
1071
|
-
);
|
|
1072
|
-
throw n.cause = t, n;
|
|
1073
|
-
}
|
|
1074
|
-
}
|
|
1075
|
-
function Ct(s) {
|
|
1076
|
-
if (typeof s == "object" && s.type === "max-age") {
|
|
1077
|
-
const e = s.maxAge;
|
|
1078
|
-
return Number.isFinite(e) && e >= 0 ? e : z;
|
|
1079
|
-
}
|
|
1080
|
-
return z;
|
|
1081
|
-
}
|
|
1082
|
-
class St extends ye {
|
|
1083
|
-
constructor(e, t, r) {
|
|
1084
|
-
super(t), this.url = r, this.query = e.query, this.normalizedOperationName = e.operationName ?? "", this.normalizedVariables = vt(
|
|
1085
|
-
e.variables ?? {},
|
|
1086
|
-
this.normalizedOperationName
|
|
1087
|
-
), this.cacheControl = e.cacheControl, this.resolvedMaxAge = Ct(e.cacheControl);
|
|
1088
|
-
}
|
|
1089
|
-
query;
|
|
1090
|
-
normalizedVariables;
|
|
1091
|
-
normalizedOperationName;
|
|
1092
|
-
cacheControl;
|
|
1093
|
-
resolvedMaxAge;
|
|
1094
|
-
get fetchParams() {
|
|
1095
|
-
return [
|
|
1096
|
-
this.url,
|
|
1097
|
-
{
|
|
1098
|
-
method: "POST",
|
|
1099
|
-
headers: re(),
|
|
1100
|
-
body: JSON.stringify({
|
|
1101
|
-
query: this.query,
|
|
1102
|
-
variables: this.normalizedVariables,
|
|
1103
|
-
operationName: this.normalizedOperationName
|
|
1104
|
-
})
|
|
1105
|
-
}
|
|
1106
|
-
];
|
|
1107
|
-
}
|
|
1108
|
-
buildKey() {
|
|
1109
|
-
return oe({
|
|
1110
|
-
query: this.query,
|
|
1111
|
-
variables: this.normalizedVariables,
|
|
1112
|
-
operationName: this.normalizedOperationName
|
|
1113
|
-
});
|
|
1114
|
-
}
|
|
1115
|
-
/**
|
|
1116
|
-
* Reads from the cache and returns the cache result or error
|
|
1117
|
-
*
|
|
1118
|
-
* In case of a missing or partial result, this should return either a DataNotFoundError or
|
|
1119
|
-
* DataIncompleteError, respectively, in the Error response
|
|
1120
|
-
*
|
|
1121
|
-
* Note that any subclass should JUST try to read the data from the cache here; it should
|
|
1122
|
-
* NOT try to take metadata (eg cache control semantics) into account while reading the
|
|
1123
|
-
* data. The CacheController is responsible for enforcing those semantics.
|
|
1124
|
-
*
|
|
1125
|
-
* @param cache source of cached data
|
|
1126
|
-
* @returns result or error from the cache
|
|
1127
|
-
*/
|
|
1128
|
-
readFromCache(e) {
|
|
1129
|
-
const t = this.buildKey(), r = e.get(t)?.value;
|
|
1130
|
-
return r === void 0 ? b(P(new ae())) : b(D(r));
|
|
1131
|
-
}
|
|
1132
|
-
writeToCache(e, t) {
|
|
1133
|
-
if (t.isOk() && t.value.data != null && Object.keys(t.value.data).length > 0) {
|
|
1134
|
-
const r = Math.floor(Date.now() / 1e3);
|
|
1135
|
-
e.set(this.buildKey(), {
|
|
1136
|
-
value: t.value.data,
|
|
1137
|
-
metadata: {
|
|
1138
|
-
cacheControl: {
|
|
1139
|
-
type: "max-age",
|
|
1140
|
-
maxAge: this.resolvedMaxAge,
|
|
1141
|
-
generatedTime: r
|
|
1142
|
-
}
|
|
1143
|
-
}
|
|
1144
|
-
});
|
|
1145
|
-
}
|
|
1146
|
-
return b(void 0);
|
|
1147
|
-
}
|
|
1148
|
-
get cacheControlStrategyConfig() {
|
|
1149
|
-
const e = Math.floor(Date.now() / 1e3);
|
|
1150
|
-
return this.cacheControl === "no-cache" ? { type: "no-cache", now: e } : this.cacheControl === "only-if-cached" ? { type: "only-if-cached", now: e } : {
|
|
1151
|
-
type: "max-age",
|
|
1152
|
-
requestMaxAge: this.resolvedMaxAge,
|
|
1153
|
-
now: e
|
|
1154
|
-
};
|
|
1155
|
-
}
|
|
1156
|
-
responseHasErrors(e) {
|
|
1157
|
-
return e.errors && e.errors.length > 0;
|
|
1158
|
-
}
|
|
1159
|
-
processFetchReturnValue(e) {
|
|
1160
|
-
return this.responseHasErrors(e) ? P(new ce(e)) : D(e);
|
|
1161
|
-
}
|
|
1162
|
-
}
|
|
1163
|
-
function ne(s) {
|
|
1164
|
-
if (le(s) && s.data && typeof s.data == "object") {
|
|
1165
|
-
const e = s.data;
|
|
1166
|
-
if (e.data != null)
|
|
1167
|
-
return e.data;
|
|
1168
|
-
}
|
|
1169
|
-
}
|
|
1170
|
-
function Tt(s) {
|
|
1171
|
-
return (e) => {
|
|
1172
|
-
if (e.isOk()) {
|
|
1173
|
-
const t = e.value;
|
|
1174
|
-
I(t), s({ data: t, errors: void 0 });
|
|
1175
|
-
} else {
|
|
1176
|
-
const t = ne(e.error);
|
|
1177
|
-
t && I(t), s({ data: t, errors: v(e.error) });
|
|
1178
|
-
}
|
|
1179
|
-
};
|
|
1180
|
-
}
|
|
1181
|
-
async function _t(s) {
|
|
1182
|
-
let e, t, r;
|
|
1183
|
-
try {
|
|
1184
|
-
const n = await s.execute();
|
|
1185
|
-
n.isOk() ? (e = n.value.data, I(e), r = (i) => n.value.subscribe(i)) : (e = ne(n.error.failure), e && I(e), t = v(n.error.failure), r = (i) => n.error.subscribe(i));
|
|
1186
|
-
} catch (n) {
|
|
1187
|
-
t = v(n);
|
|
1188
|
-
}
|
|
1189
|
-
return {
|
|
1190
|
-
data: e,
|
|
1191
|
-
errors: t,
|
|
1192
|
-
subscribe(n) {
|
|
1193
|
-
return r ? r(Tt(n)) : A;
|
|
1194
|
-
},
|
|
1195
|
-
async refresh() {
|
|
1196
|
-
await s.refresh();
|
|
1197
|
-
}
|
|
1198
|
-
};
|
|
1199
|
-
}
|
|
1200
|
-
function k(s) {
|
|
1201
|
-
return {
|
|
1202
|
-
data: void 0,
|
|
1203
|
-
errors: s,
|
|
1204
|
-
subscribe: () => A,
|
|
1205
|
-
refresh: x
|
|
1206
|
-
};
|
|
1207
|
-
}
|
|
1208
|
-
function Et({
|
|
1209
|
-
bundle: s,
|
|
1210
|
-
url: e,
|
|
1211
|
-
executeRaw: t
|
|
1212
|
-
}) {
|
|
1213
|
-
const { services: r } = s;
|
|
1214
|
-
async function n({
|
|
1215
|
-
query: i,
|
|
1216
|
-
variables: o,
|
|
1217
|
-
operationName: c,
|
|
1218
|
-
cacheControl: l
|
|
1219
|
-
}) {
|
|
1220
|
-
const d = N(i);
|
|
1221
|
-
if (d.isErr()) return k(d.error);
|
|
1222
|
-
const g = d.value, f = F(g, c);
|
|
1223
|
-
if (f !== "query")
|
|
1224
|
-
return k([
|
|
1225
|
-
{
|
|
1226
|
-
message: `DataSDK.graphql.query() requires a GraphQL query, received ${f}.`
|
|
1227
|
-
}
|
|
1228
|
-
]);
|
|
1229
|
-
let h;
|
|
1230
|
-
try {
|
|
1231
|
-
h = new St(
|
|
1232
|
-
{
|
|
1233
|
-
query: O(g),
|
|
1234
|
-
variables: o,
|
|
1235
|
-
operationName: c,
|
|
1236
|
-
cacheControl: l
|
|
1237
|
-
},
|
|
1238
|
-
r,
|
|
1239
|
-
e
|
|
1240
|
-
);
|
|
1241
|
-
} catch (p) {
|
|
1242
|
-
return k(v(p));
|
|
1243
|
-
}
|
|
1244
|
-
return _t(h);
|
|
1245
|
-
}
|
|
1246
|
-
return {
|
|
1247
|
-
query: n,
|
|
1248
|
-
mutate: (i) => ee(t, i)
|
|
1249
|
-
};
|
|
1250
|
-
}
|
|
1251
|
-
const It = 1, At = `@salesforce/platform-sdk-data_v${It}`, ie = se(), Mt = `${ie}/ui-api`, B = `${ie}/graphql`;
|
|
1252
|
-
class kt {
|
|
1253
|
-
baseUrl;
|
|
1254
|
-
clientFetch;
|
|
1255
|
-
onStatus;
|
|
1256
|
-
graphql;
|
|
1257
|
-
constructor(e) {
|
|
1258
|
-
const t = Dt();
|
|
1259
|
-
this.baseUrl = Pt(e?.basePath ?? t.apiPath), this.onStatus = e?.onStatus ?? {}, this.clientFetch = yt({
|
|
1260
|
-
csrf: {
|
|
1261
|
-
endpoint: `${this.baseUrl}${Mt}/session/csrf`,
|
|
1262
|
-
cacheName: At,
|
|
1263
|
-
protectedUrls: ["services/data/v", "services/apexrest"],
|
|
1264
|
-
alwaysProtectedUrls: ["services/apexrest"]
|
|
1265
|
-
}
|
|
1266
|
-
});
|
|
1267
|
-
const r = (i, o) => this.fetch(i, o), n = bt(this.baseUrl, r);
|
|
1268
|
-
this.graphql = Et({
|
|
1269
|
-
bundle: n,
|
|
1270
|
-
url: B,
|
|
1271
|
-
executeRaw: this.executeRawGraphQL.bind(this)
|
|
1272
|
-
});
|
|
1273
|
-
}
|
|
1274
|
-
async fetch(e, t) {
|
|
1275
|
-
const r = this.applySalesforceBase(e), n = await this.clientFetch(r, t);
|
|
1276
|
-
return await this.onStatus[n.status]?.(), n;
|
|
1277
|
-
}
|
|
1278
|
-
/**
|
|
1279
|
-
* Raw GraphQL POST. Used internally by `graphql.mutate` (which has no
|
|
1280
|
-
* cache concern) and transitively by `graphql.query` on cache miss
|
|
1281
|
-
* (the OneStore cache command's fetch service is bound to this same
|
|
1282
|
-
* SDK's `fetch`, which in turn calls this method's caller patterns).
|
|
1283
|
-
*/
|
|
1284
|
-
async executeRawGraphQL({
|
|
1285
|
-
query: e,
|
|
1286
|
-
variables: t,
|
|
1287
|
-
operationName: r
|
|
1288
|
-
}) {
|
|
1289
|
-
return (await this.fetch(B, {
|
|
1290
|
-
method: "POST",
|
|
1291
|
-
body: JSON.stringify({ query: e, variables: t, operationName: r }),
|
|
1292
|
-
headers: re()
|
|
1293
|
-
})).json();
|
|
1294
|
-
}
|
|
1295
|
-
/**
|
|
1296
|
-
* If the url is relative, convert to it to an absolute Salesforce URL. This is due to the way Code
|
|
1297
|
-
* Builder deployments structure the url for Salesforce
|
|
1298
|
-
*/
|
|
1299
|
-
applySalesforceBase(e) {
|
|
1300
|
-
if (typeof e == "string") {
|
|
1301
|
-
if (e.startsWith("http"))
|
|
1302
|
-
return e;
|
|
1303
|
-
const t = e.startsWith("/") ? e : `/${e}`;
|
|
1304
|
-
return `${this.baseUrl}${t}`;
|
|
1305
|
-
}
|
|
1306
|
-
return e;
|
|
1307
|
-
}
|
|
1308
|
-
}
|
|
1309
|
-
function Dt() {
|
|
1310
|
-
return {
|
|
1311
|
-
apiPath: globalThis.SFDC_ENV?.apiPath
|
|
1312
|
-
};
|
|
1313
|
-
}
|
|
1314
|
-
function Pt(s) {
|
|
1315
|
-
if (!s || s === "/") return "";
|
|
1316
|
-
let e = s;
|
|
1317
|
-
return e.startsWith("/") || (e = `/${e}`), e.endsWith("/") && (e = e.slice(0, -1)), e;
|
|
1318
|
-
}
|
|
1319
|
-
function ys(s, ...e) {
|
|
1320
|
-
let t = s[0] ?? "";
|
|
1321
|
-
for (let r = 0; r < e.length; r += 1)
|
|
1322
|
-
t += String(e[r]) + (s[r + 1] ?? "");
|
|
1323
|
-
return t;
|
|
1324
|
-
}
|
|
1325
|
-
function ws(s) {
|
|
1326
|
-
return M(
|
|
1327
|
-
(async () => {
|
|
1328
|
-
switch (S(s?.surface)) {
|
|
1329
|
-
case a.OpenAI:
|
|
1330
|
-
return new nt();
|
|
1331
|
-
case a.WebApp:
|
|
1332
|
-
case a.MicroFrontend:
|
|
1333
|
-
return new kt(s?.webapp);
|
|
1334
|
-
case a.Mosaic:
|
|
1335
|
-
return new et(s?.mosaic);
|
|
1336
|
-
case a.SalesforceACC:
|
|
1337
|
-
case a.MCPApps:
|
|
1338
|
-
return {};
|
|
1339
|
-
default:
|
|
1340
|
-
return {};
|
|
1341
|
-
}
|
|
1342
|
-
})(),
|
|
1343
|
-
"createDataSDK"
|
|
1344
|
-
);
|
|
1345
|
-
}
|
|
1346
|
-
function bs(s) {
|
|
1347
|
-
return M(
|
|
1348
|
-
(async () => {
|
|
1349
|
-
switch (S(s?.surface)) {
|
|
1350
|
-
case a.OpenAI:
|
|
1351
|
-
return {};
|
|
1352
|
-
case a.WebApp:
|
|
1353
|
-
return {};
|
|
1354
|
-
case a.MicroFrontend:
|
|
1355
|
-
return {};
|
|
1356
|
-
case a.SalesforceACC:
|
|
1357
|
-
return {};
|
|
1358
|
-
case a.MCPApps:
|
|
1359
|
-
return {};
|
|
1360
|
-
case a.Mosaic:
|
|
1361
|
-
return {};
|
|
1362
|
-
default:
|
|
1363
|
-
return {};
|
|
1364
|
-
}
|
|
1365
|
-
})(),
|
|
1366
|
-
"createLightningSDK"
|
|
1367
|
-
);
|
|
1368
|
-
}
|
|
1369
|
-
function Lt(s) {
|
|
1370
|
-
let e = "";
|
|
1371
|
-
for (let r = 0; r < s.length; r += 8192)
|
|
1372
|
-
e += String.fromCharCode.apply(null, Array.from(s.subarray(r, r + 8192)));
|
|
1373
|
-
return btoa(e);
|
|
1374
|
-
}
|
|
1375
|
-
class xt {
|
|
1376
|
-
entries = [];
|
|
1377
|
-
totalBytes = 0;
|
|
1378
|
-
maxBufferSize;
|
|
1379
|
-
onError;
|
|
1380
|
-
constructor(e) {
|
|
1381
|
-
this.maxBufferSize = e.maxBufferSize, this.onError = e.onError;
|
|
1382
|
-
}
|
|
1383
|
-
get size() {
|
|
1384
|
-
return this.totalBytes;
|
|
1385
|
-
}
|
|
1386
|
-
get isEmpty() {
|
|
1387
|
-
return this.entries.length === 0;
|
|
1388
|
-
}
|
|
1389
|
-
enqueue(e, t) {
|
|
1390
|
-
const r = Lt(e), n = {
|
|
1391
|
-
data: r,
|
|
1392
|
-
traceId: t?.traceId,
|
|
1393
|
-
instanceId: t?.instanceId,
|
|
1394
|
-
componentRef: t?.componentRef,
|
|
1395
|
-
timestamp: Date.now()
|
|
1396
|
-
}, i = r.length;
|
|
1397
|
-
this.entries.push(n), this.totalBytes += i, this.totalBytes > this.maxBufferSize && this.evict();
|
|
1398
|
-
}
|
|
1399
|
-
drain() {
|
|
1400
|
-
const e = this.entries;
|
|
1401
|
-
return this.entries = [], this.totalBytes = 0, e;
|
|
1402
|
-
}
|
|
1403
|
-
evict() {
|
|
1404
|
-
let e = 0;
|
|
1405
|
-
for (; this.totalBytes > this.maxBufferSize && this.entries.length > 1; ) {
|
|
1406
|
-
const t = this.entries.shift();
|
|
1407
|
-
this.totalBytes -= t.data.length, e++;
|
|
1408
|
-
}
|
|
1409
|
-
e > 0 && this.onError?.({ reason: "buffer_overflow", droppedCount: e });
|
|
1410
|
-
}
|
|
1411
|
-
}
|
|
1412
|
-
const Ot = "telemetry/upload";
|
|
1413
|
-
class Ht {
|
|
1414
|
-
buffer;
|
|
1415
|
-
sdk;
|
|
1416
|
-
onError;
|
|
1417
|
-
timerId = null;
|
|
1418
|
-
disposed = !1;
|
|
1419
|
-
handleVisibilityChange = () => {
|
|
1420
|
-
document.visibilityState === "hidden" && this.flush();
|
|
1421
|
-
};
|
|
1422
|
-
handlePageHide = () => {
|
|
1423
|
-
this.flush();
|
|
1424
|
-
};
|
|
1425
|
-
constructor(e, t, r) {
|
|
1426
|
-
this.buffer = e, this.sdk = t, this.onError = r.onError, this.timerId = setInterval(() => this.flush(), r.flushInterval), document.addEventListener("visibilitychange", this.handleVisibilityChange), window.addEventListener("pagehide", this.handlePageHide);
|
|
1427
|
-
}
|
|
1428
|
-
flush() {
|
|
1429
|
-
if (this.buffer.isEmpty || !this.sdk.callTool)
|
|
1430
|
-
return;
|
|
1431
|
-
const t = this.buffer.drain().map(Rt);
|
|
1432
|
-
this.sdk.callTool({ toolName: Ot, params: { inputs: [{ envelopes: t }] } }).catch((r) => {
|
|
1433
|
-
this.onError?.({ reason: "tool_call_failed", error: r });
|
|
1434
|
-
});
|
|
1435
|
-
}
|
|
1436
|
-
dispose() {
|
|
1437
|
-
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());
|
|
1438
|
-
}
|
|
1439
|
-
}
|
|
1440
|
-
function Rt(s) {
|
|
1441
|
-
const e = { base64Env: s.data };
|
|
1442
|
-
return s.traceId !== void 0 && (e.traceId = s.traceId), e;
|
|
1443
|
-
}
|
|
1444
|
-
const qt = 65536, Nt = 3e4;
|
|
1445
|
-
function vs(s) {
|
|
1446
|
-
const {
|
|
1447
|
-
sdk: e,
|
|
1448
|
-
maxBufferSize: t = qt,
|
|
1449
|
-
flushInterval: r = Nt,
|
|
1450
|
-
onError: n
|
|
1451
|
-
} = s, i = new xt({ maxBufferSize: t, onError: n }), o = new Ht(i, e, { flushInterval: r, onError: n });
|
|
1452
|
-
return {
|
|
1453
|
-
enqueue(c, l) {
|
|
1454
|
-
i.enqueue(c, l);
|
|
1455
|
-
},
|
|
1456
|
-
dispose() {
|
|
1457
|
-
o.dispose();
|
|
1458
|
-
}
|
|
1459
|
-
};
|
|
1460
|
-
}
|
|
1461
|
-
const Ft = 1e4, Ut = 10, Vt = 10, $t = 250, Wt = 1e3;
|
|
1462
|
-
function C(s, e) {
|
|
1463
|
-
if (s !== void 0 && (typeof s != "number" || !Number.isFinite(s) || s <= 0))
|
|
1464
|
-
throw new Error(`${e}, if defined, must be a finite number greater than 0`);
|
|
1465
|
-
}
|
|
1466
|
-
function Kt(s, e) {
|
|
1467
|
-
if (typeof s != "function")
|
|
1468
|
-
throw new Error(`${e} must be a function`);
|
|
1469
|
-
}
|
|
1470
|
-
class zt {
|
|
1471
|
-
_collector;
|
|
1472
|
-
_onEnvelope;
|
|
1473
|
-
_onError;
|
|
1474
|
-
_enableClickTrigger;
|
|
1475
|
-
_enableVisibilityTrigger;
|
|
1476
|
-
_messagesLimit;
|
|
1477
|
-
_metricsLimit;
|
|
1478
|
-
_uploadInterval;
|
|
1479
|
-
_clickUploadDelay;
|
|
1480
|
-
_clickTriggerCooldown;
|
|
1481
|
-
_boundClickListener = this._handleClick.bind(this);
|
|
1482
|
-
_boundVisibilityChangeListener = this._handleVisibilityChange.bind(this);
|
|
1483
|
-
_boundPageHideListener = this._handlePageHide.bind(this);
|
|
1484
|
-
_intervalHandle;
|
|
1485
|
-
_clickTimeoutHandle;
|
|
1486
|
-
_flushPromise;
|
|
1487
|
-
_pendingFlushReason;
|
|
1488
|
-
_lastClickTriggeredAt = 0;
|
|
1489
|
-
_isDisposed = !1;
|
|
1490
|
-
constructor(e) {
|
|
1491
|
-
Kt(e?.onEnvelope, "options.onEnvelope"), C(e.uploadInterval, "options.uploadInterval"), C(e.messagesLimit, "options.messagesLimit"), C(e.metricsLimit, "options.metricsLimit"), C(e.maxUniqueSchemas, "options.maxUniqueSchemas"), C(e.clickUploadDelay, "options.clickUploadDelay"), C(e.clickTriggerCooldown, "options.clickTriggerCooldown"), this._onEnvelope = e.onEnvelope, this._onError = e.onError, this._messagesLimit = e.messagesLimit ?? Ut, this._metricsLimit = e.metricsLimit ?? Vt, this._uploadInterval = e.uploadInterval ?? Ft, this._clickUploadDelay = e.clickUploadDelay ?? $t, this._clickTriggerCooldown = e.clickTriggerCooldown ?? Wt, this._enableClickTrigger = e.enableClickTrigger !== !1, this._enableVisibilityTrigger = e.enableVisibilityTrigger !== !1, this._collector = new be({
|
|
1492
|
-
environment: e.environment,
|
|
1493
|
-
maxUniqueSchemas: e.maxUniqueSchemas
|
|
1494
|
-
}), this._restartInterval(), this._attachWindowListeners();
|
|
1495
|
-
}
|
|
1496
|
-
get hasData() {
|
|
1497
|
-
return this._collector.hasData;
|
|
1498
|
-
}
|
|
1499
|
-
get estimatedByteSize() {
|
|
1500
|
-
return this._collector.estimatedByteSize;
|
|
1501
|
-
}
|
|
1502
|
-
get messagesCount() {
|
|
1503
|
-
return this._collector.messagesCount;
|
|
1504
|
-
}
|
|
1505
|
-
get metricsCount() {
|
|
1506
|
-
return this._collector.metricsCount;
|
|
1507
|
-
}
|
|
1508
|
-
getIsCollectDisabled() {
|
|
1509
|
-
return this._isDisposed;
|
|
1510
|
-
}
|
|
1511
|
-
collect(e, t, r) {
|
|
1512
|
-
this._collector.collect(
|
|
1513
|
-
e,
|
|
1514
|
-
t,
|
|
1515
|
-
r
|
|
1516
|
-
), this._shouldFlushForThreshold() && this.flush("threshold");
|
|
1517
|
-
}
|
|
1518
|
-
receiveMetricsExtractors(e) {
|
|
1519
|
-
this._collector.receiveMetricsExtractors(
|
|
1520
|
-
e
|
|
1521
|
-
);
|
|
1522
|
-
}
|
|
1523
|
-
async flush(e = "manual") {
|
|
1524
|
-
return this._flushPromise ? (this._pendingFlushReason = this._pendingFlushReason ?? e, this._flushPromise) : (this._flushPromise = this._flushInternal(e).then(() => {
|
|
1525
|
-
const t = this._pendingFlushReason;
|
|
1526
|
-
this._pendingFlushReason = void 0, t && this.hasData && !this._isDisposed && this.flush(t);
|
|
1527
|
-
}).finally(() => {
|
|
1528
|
-
this._flushPromise = void 0;
|
|
1529
|
-
}), this._flushPromise);
|
|
1530
|
-
}
|
|
1531
|
-
async dispose(e) {
|
|
1532
|
-
this._isDisposed = !0, this._detachWindowListeners(), this._stopInterval(), this._clickTimeoutHandle !== void 0 && (clearTimeout(this._clickTimeoutHandle), this._clickTimeoutHandle = void 0), e?.flush !== !1 && this.hasData && await this.flush("dispose");
|
|
1533
|
-
}
|
|
1534
|
-
_attachWindowListeners() {
|
|
1535
|
-
typeof document == "object" && this._enableClickTrigger && document.addEventListener("click", this._boundClickListener, !0), typeof window == "object" && this._enableVisibilityTrigger && (document.addEventListener("visibilitychange", this._boundVisibilityChangeListener, !0), window.addEventListener("pagehide", this._boundPageHideListener, !0));
|
|
1536
|
-
}
|
|
1537
|
-
_detachWindowListeners() {
|
|
1538
|
-
typeof document == "object" && (document.removeEventListener("click", this._boundClickListener, !0), document.removeEventListener("visibilitychange", this._boundVisibilityChangeListener, !0)), typeof window == "object" && window.removeEventListener("pagehide", this._boundPageHideListener, !0);
|
|
1539
|
-
}
|
|
1540
|
-
_handleClick() {
|
|
1541
|
-
!this.hasData || this._isDisposed || Date.now() - this._lastClickTriggeredAt < this._clickTriggerCooldown || (this._clickTimeoutHandle !== void 0 && clearTimeout(this._clickTimeoutHandle), this._clickTimeoutHandle = setTimeout(() => {
|
|
1542
|
-
this._clickTimeoutHandle = void 0, !(!this.hasData || this._isDisposed) && (this._lastClickTriggeredAt = Date.now(), this.flush("click"));
|
|
1543
|
-
}, this._clickUploadDelay));
|
|
1544
|
-
}
|
|
1545
|
-
_handleVisibilityChange() {
|
|
1546
|
-
typeof document != "object" || document.visibilityState !== "hidden" || !this.hasData || this.flush("visibilitychange");
|
|
1547
|
-
}
|
|
1548
|
-
_handlePageHide() {
|
|
1549
|
-
this.hasData && this.flush("pagehide");
|
|
1550
|
-
}
|
|
1551
|
-
_restartInterval() {
|
|
1552
|
-
this._stopInterval(), this._intervalHandle = setInterval(() => {
|
|
1553
|
-
this.hasData && !this._isDisposed && this.flush("interval");
|
|
1554
|
-
}, this._uploadInterval);
|
|
1555
|
-
}
|
|
1556
|
-
_stopInterval() {
|
|
1557
|
-
this._intervalHandle !== void 0 && (clearInterval(this._intervalHandle), this._intervalHandle = void 0);
|
|
1558
|
-
}
|
|
1559
|
-
_shouldFlushForThreshold() {
|
|
1560
|
-
return this.messagesCount >= this._messagesLimit || this.metricsCount >= this._metricsLimit;
|
|
1561
|
-
}
|
|
1562
|
-
async _flushInternal(e) {
|
|
1563
|
-
if (!this.hasData)
|
|
1564
|
-
return;
|
|
1565
|
-
const t = {
|
|
1566
|
-
reason: e,
|
|
1567
|
-
messagesCount: this.messagesCount,
|
|
1568
|
-
metricsCount: this.metricsCount,
|
|
1569
|
-
estimatedByteSize: this.estimatedByteSize,
|
|
1570
|
-
triggeredAt: Date.now()
|
|
1571
|
-
}, r = this._collector.getRawContentsOfCoreEnvelope(), n = we(r);
|
|
1572
|
-
this._restartInterval();
|
|
1573
|
-
try {
|
|
1574
|
-
await this._onEnvelope(n, t);
|
|
1575
|
-
} catch (i) {
|
|
1576
|
-
const o = {
|
|
1577
|
-
...t,
|
|
1578
|
-
error: i
|
|
1579
|
-
};
|
|
1580
|
-
throw this._onError?.(o), i;
|
|
1581
|
-
}
|
|
1582
|
-
}
|
|
1583
|
-
}
|
|
1584
|
-
function Bt(s, e) {
|
|
1585
|
-
if (!s)
|
|
1586
|
-
throw new Error("instrumentedApp is required");
|
|
1587
|
-
const t = new zt(e);
|
|
1588
|
-
return s.registerLogCollector(t), s.registerMetricsCollector(t), e.enableClickTrigger !== !1 && s.activateClickTracker?.(), t;
|
|
1589
|
-
}
|
|
1590
|
-
function jt(s) {
|
|
1591
|
-
const e = (r, n, i, o, c) => {
|
|
1592
|
-
s.error(c ?? r);
|
|
1593
|
-
}, t = (r) => {
|
|
1594
|
-
s.error(r.reason);
|
|
1595
|
-
};
|
|
1596
|
-
return window.addEventListener("error", e), window.addEventListener("unhandledrejection", t), () => {
|
|
1597
|
-
window.removeEventListener("error", e), window.removeEventListener("unhandledrejection", t);
|
|
1598
|
-
};
|
|
1599
|
-
}
|
|
1600
|
-
const Qt = "aJC", Cs = "sfdc.pftId", j = /* @__PURE__ */ new Set(), Gt = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
|
|
1601
|
-
function Q(s) {
|
|
1602
|
-
return typeof s != "string" || s.length === 0 ? !1 : s.length !== 15 && s.length !== 18 ? (G(s, "Expected a 15- or 18-character Salesforce ID"), !1) : Gt.test(s) ? !0 : (G(s, `Expected a Product Feature Id (prefix "${Qt}", base62).`), !1);
|
|
1603
|
-
}
|
|
1604
|
-
function G(s, e) {
|
|
1605
|
-
j.has(s) || (j.add(s), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${s}". ${e}`));
|
|
1606
|
-
}
|
|
1607
|
-
function y(s, e) {
|
|
1608
|
-
return { surface: e };
|
|
1609
|
-
}
|
|
1610
|
-
const Jt = {
|
|
1611
|
-
callTool: {
|
|
1612
|
-
isAsync: !0,
|
|
1613
|
-
extractTags: (s, e) => ({ toolName: s[0]?.toolName ?? "unknown", surface: e })
|
|
1614
|
-
},
|
|
1615
|
-
setWidgetState: {
|
|
1616
|
-
isAsync: !1,
|
|
1617
|
-
extractTags: y
|
|
1618
|
-
},
|
|
1619
|
-
getWidgetState: {
|
|
1620
|
-
isAsync: !1,
|
|
1621
|
-
extractTags: y
|
|
1622
|
-
},
|
|
1623
|
-
sendMessageToHost: {
|
|
1624
|
-
isAsync: !0,
|
|
1625
|
-
extractTags: y
|
|
1626
|
-
},
|
|
1627
|
-
openLink: {
|
|
1628
|
-
isAsync: !0,
|
|
1629
|
-
extractTags: y
|
|
1630
|
-
},
|
|
1631
|
-
subscribe: {
|
|
1632
|
-
isAsync: !1,
|
|
1633
|
-
extractTags: y,
|
|
1634
|
-
wrapArgs: (s, e) => {
|
|
1635
|
-
const t = s[0];
|
|
1636
|
-
return [
|
|
1637
|
-
() => {
|
|
1638
|
-
e.activity("sdk.subscribe_callback", () => t());
|
|
1639
|
-
}
|
|
1640
|
-
];
|
|
1641
|
-
}
|
|
1642
|
-
},
|
|
1643
|
-
readResource: {
|
|
1644
|
-
isAsync: !0,
|
|
1645
|
-
extractTags: (s, e) => ({ uri: s[0]?.uri ?? "unknown", surface: e })
|
|
1646
|
-
},
|
|
1647
|
-
setDisplayMode: {
|
|
1648
|
-
isAsync: !0,
|
|
1649
|
-
extractTags: (s, e) => ({ mode: s[0] ?? "unknown", surface: e })
|
|
1650
|
-
},
|
|
1651
|
-
accessToolOutput: {
|
|
1652
|
-
isAsync: !1,
|
|
1653
|
-
extractTags: y
|
|
1654
|
-
},
|
|
1655
|
-
accessToolInput: {
|
|
1656
|
-
isAsync: !1,
|
|
1657
|
-
extractTags: y
|
|
1658
|
-
},
|
|
1659
|
-
accessToolMetadata: {
|
|
1660
|
-
isAsync: !1,
|
|
1661
|
-
extractTags: y
|
|
1662
|
-
}
|
|
1663
|
-
};
|
|
1664
|
-
function Xt(s, e, t) {
|
|
1665
|
-
return new Proxy(s, {
|
|
1666
|
-
get(r, n, i) {
|
|
1667
|
-
const o = Reflect.get(r, n, i), c = Jt[n];
|
|
1668
|
-
return !c || typeof o != "function" ? o : (...l) => {
|
|
1669
|
-
const d = c.extractTags(l, t), g = c.wrapArgs ? c.wrapArgs(l, e) : l, f = `sdk.${String(n)}`;
|
|
1670
|
-
return c.isAsync ? e.activityAsync(f, async () => {
|
|
1671
|
-
try {
|
|
1672
|
-
const h = await o.apply(
|
|
1673
|
-
r,
|
|
1674
|
-
g
|
|
1675
|
-
);
|
|
1676
|
-
return e.incrementCounter(f, 1, !1, d), h;
|
|
1677
|
-
} catch (h) {
|
|
1678
|
-
throw e.incrementCounter(f, 1, !0, d), h;
|
|
1679
|
-
}
|
|
1680
|
-
}) : (e.incrementCounter(f, 1, !1, d), o.apply(r, g));
|
|
1681
|
-
};
|
|
1682
|
-
}
|
|
1683
|
-
});
|
|
1684
|
-
}
|
|
1685
|
-
async function Ss(s) {
|
|
1686
|
-
const { appId: e, clientSessionId: t } = s, r = S(), n = Date.now(), i = s.sdk ?? await Ke();
|
|
1687
|
-
let o = null;
|
|
1688
|
-
s.pftId !== void 0 && Q(s.pftId) && (o = s.pftId);
|
|
1689
|
-
const c = ve("mcp-widget", {
|
|
1690
|
-
appPayloadProvider: {
|
|
1691
|
-
getPayload: () => ({
|
|
1692
|
-
schema: Ce,
|
|
1693
|
-
payload: {
|
|
1694
|
-
appId: e,
|
|
1695
|
-
surface: r,
|
|
1696
|
-
...o !== null ? { pftId: o } : {}
|
|
1697
|
-
}
|
|
1698
|
-
})
|
|
1699
|
-
},
|
|
1700
|
-
clientSessionId: t
|
|
1701
|
-
}), l = c, d = Xt(i, l, r), g = jt(l);
|
|
1702
|
-
let f;
|
|
1703
|
-
s.transport && (f = Bt(c, {
|
|
1704
|
-
onEnvelope: (u) => {
|
|
1705
|
-
s.transport.enqueue(u);
|
|
1706
|
-
}
|
|
1707
|
-
}));
|
|
1708
|
-
let h, p = !1;
|
|
1709
|
-
return {
|
|
1710
|
-
instrumentedSDK: d,
|
|
1711
|
-
app: c,
|
|
1712
|
-
trackEvent(u, m) {
|
|
1713
|
-
p || l.log(Ie, {
|
|
1714
|
-
eventName: u,
|
|
1715
|
-
properties: m ? JSON.stringify(m) : ""
|
|
1716
|
-
});
|
|
1717
|
-
},
|
|
1718
|
-
trackInteraction(u, m) {
|
|
1719
|
-
p || l.log(Ee, {
|
|
1720
|
-
elementId: u,
|
|
1721
|
-
properties: m ? JSON.stringify(m) : ""
|
|
1722
|
-
});
|
|
1723
|
-
},
|
|
1724
|
-
trackError(u, m) {
|
|
1725
|
-
p || l.error(u, _e, {
|
|
1726
|
-
properties: m ? JSON.stringify(m) : ""
|
|
1727
|
-
});
|
|
1728
|
-
},
|
|
1729
|
-
trackPageView(u) {
|
|
1730
|
-
p || u !== h && (h = u, l.log(Te, { componentRef: u }));
|
|
1731
|
-
},
|
|
1732
|
-
setPftId(u) {
|
|
1733
|
-
p || Q(u) && (o = u);
|
|
1734
|
-
},
|
|
1735
|
-
dispose() {
|
|
1736
|
-
if (p) return;
|
|
1737
|
-
p = !0, g();
|
|
1738
|
-
const u = Date.now() - n;
|
|
1739
|
-
l.log(Se, { durationMs: u }), f?.dispose();
|
|
1740
|
-
}
|
|
1741
|
-
};
|
|
1742
|
-
}
|
|
1
|
+
import { S as t, g as a, w as o } from "./sdk-promise-7SpSqah5.js";
|
|
2
|
+
import { M as s } from "./mcpapps-session-BOT5CvWa.js";
|
|
3
|
+
import { getSurfaceCapabilities as c } from "./core/index.js";
|
|
4
|
+
import { MCPAppsChatSDK as f, createChatSDK as m, getChatSDK as D, getChatSDKSync as K, resetChatSDK as g } from "./chat/index.js";
|
|
5
|
+
import { MCPAppsViewSDK as l, createViewSDK as C, getViewSDK as n, getViewSDKSync as w, resetViewSDK as T } from "./view/index.js";
|
|
6
|
+
import { createDataSDK as y, gql as P } from "./data/index.js";
|
|
7
|
+
import { createLightningSDK as M } from "./lightning/index.js";
|
|
8
|
+
import { c as d } from "./transport-D8xgRy7y.js";
|
|
9
|
+
import { T as v, r as E } from "./TelemetryUploader-DKkdppe9.js";
|
|
10
|
+
import { P as _, c as b, v as q } from "./analytics-496rdIN5.js";
|
|
1743
11
|
export {
|
|
1744
|
-
|
|
1745
|
-
|
|
1746
|
-
|
|
1747
|
-
|
|
1748
|
-
|
|
1749
|
-
|
|
1750
|
-
|
|
1751
|
-
|
|
1752
|
-
|
|
1753
|
-
|
|
1754
|
-
|
|
1755
|
-
|
|
1756
|
-
|
|
1757
|
-
|
|
1758
|
-
|
|
1759
|
-
|
|
1760
|
-
|
|
1761
|
-
|
|
1762
|
-
|
|
1763
|
-
|
|
1764
|
-
|
|
1765
|
-
|
|
1766
|
-
|
|
1767
|
-
|
|
12
|
+
f as MCPAppsChatSDK,
|
|
13
|
+
l as MCPAppsViewSDK,
|
|
14
|
+
s as McpAppsSession,
|
|
15
|
+
_ as PFT_META_KEY,
|
|
16
|
+
t as Surface,
|
|
17
|
+
v as TelemetryUploader,
|
|
18
|
+
b as createAnalytics,
|
|
19
|
+
m as createChatSDK,
|
|
20
|
+
y as createDataSDK,
|
|
21
|
+
M as createLightningSDK,
|
|
22
|
+
d as createTelemetryTransport,
|
|
23
|
+
C as createViewSDK,
|
|
24
|
+
D as getChatSDK,
|
|
25
|
+
K as getChatSDKSync,
|
|
26
|
+
a as getSurface,
|
|
27
|
+
c as getSurfaceCapabilities,
|
|
28
|
+
n as getViewSDK,
|
|
29
|
+
w as getViewSDKSync,
|
|
30
|
+
P as gql,
|
|
31
|
+
E as registerTelemetryUploader,
|
|
32
|
+
g as resetChatSDK,
|
|
33
|
+
T as resetViewSDK,
|
|
34
|
+
q as validatePftId,
|
|
35
|
+
o as wrapSDKPromise
|
|
1768
36
|
};
|