@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
|
@@ -0,0 +1,135 @@
|
|
|
1
|
+
import { encodeCoreEnvelopeContentsRaw as a } from "o11y/collectors";
|
|
2
|
+
import { SimpleCollector as h } from "o11y/simple_collector";
|
|
3
|
+
const c = 1e4, d = 10, u = 10, _ = 250, m = 1e3;
|
|
4
|
+
function s(i, e) {
|
|
5
|
+
if (i !== void 0 && (typeof i != "number" || !Number.isFinite(i) || i <= 0))
|
|
6
|
+
throw new Error(`${e}, if defined, must be a finite number greater than 0`);
|
|
7
|
+
}
|
|
8
|
+
function g(i, e) {
|
|
9
|
+
if (typeof i != "function")
|
|
10
|
+
throw new Error(`${e} must be a function`);
|
|
11
|
+
}
|
|
12
|
+
class f {
|
|
13
|
+
_collector;
|
|
14
|
+
_onEnvelope;
|
|
15
|
+
_onError;
|
|
16
|
+
_enableClickTrigger;
|
|
17
|
+
_enableVisibilityTrigger;
|
|
18
|
+
_messagesLimit;
|
|
19
|
+
_metricsLimit;
|
|
20
|
+
_uploadInterval;
|
|
21
|
+
_clickUploadDelay;
|
|
22
|
+
_clickTriggerCooldown;
|
|
23
|
+
_boundClickListener = this._handleClick.bind(this);
|
|
24
|
+
_boundVisibilityChangeListener = this._handleVisibilityChange.bind(this);
|
|
25
|
+
_boundPageHideListener = this._handlePageHide.bind(this);
|
|
26
|
+
_intervalHandle;
|
|
27
|
+
_clickTimeoutHandle;
|
|
28
|
+
_flushPromise;
|
|
29
|
+
_pendingFlushReason;
|
|
30
|
+
_lastClickTriggeredAt = 0;
|
|
31
|
+
_isDisposed = !1;
|
|
32
|
+
constructor(e) {
|
|
33
|
+
g(e?.onEnvelope, "options.onEnvelope"), s(e.uploadInterval, "options.uploadInterval"), s(e.messagesLimit, "options.messagesLimit"), s(e.metricsLimit, "options.metricsLimit"), s(e.maxUniqueSchemas, "options.maxUniqueSchemas"), s(e.clickUploadDelay, "options.clickUploadDelay"), s(e.clickTriggerCooldown, "options.clickTriggerCooldown"), this._onEnvelope = e.onEnvelope, this._onError = e.onError, this._messagesLimit = e.messagesLimit ?? d, this._metricsLimit = e.metricsLimit ?? u, this._uploadInterval = e.uploadInterval ?? c, this._clickUploadDelay = e.clickUploadDelay ?? _, this._clickTriggerCooldown = e.clickTriggerCooldown ?? m, this._enableClickTrigger = e.enableClickTrigger !== !1, this._enableVisibilityTrigger = e.enableVisibilityTrigger !== !1, this._collector = new h({
|
|
34
|
+
environment: e.environment,
|
|
35
|
+
maxUniqueSchemas: e.maxUniqueSchemas
|
|
36
|
+
}), this._restartInterval(), this._attachWindowListeners();
|
|
37
|
+
}
|
|
38
|
+
get hasData() {
|
|
39
|
+
return this._collector.hasData;
|
|
40
|
+
}
|
|
41
|
+
get estimatedByteSize() {
|
|
42
|
+
return this._collector.estimatedByteSize;
|
|
43
|
+
}
|
|
44
|
+
get messagesCount() {
|
|
45
|
+
return this._collector.messagesCount;
|
|
46
|
+
}
|
|
47
|
+
get metricsCount() {
|
|
48
|
+
return this._collector.metricsCount;
|
|
49
|
+
}
|
|
50
|
+
getIsCollectDisabled() {
|
|
51
|
+
return this._isDisposed;
|
|
52
|
+
}
|
|
53
|
+
collect(e, t, r) {
|
|
54
|
+
this._collector.collect(
|
|
55
|
+
e,
|
|
56
|
+
t,
|
|
57
|
+
r
|
|
58
|
+
), this._shouldFlushForThreshold() && this.flush("threshold");
|
|
59
|
+
}
|
|
60
|
+
receiveMetricsExtractors(e) {
|
|
61
|
+
this._collector.receiveMetricsExtractors(
|
|
62
|
+
e
|
|
63
|
+
);
|
|
64
|
+
}
|
|
65
|
+
async flush(e = "manual") {
|
|
66
|
+
return this._flushPromise ? (this._pendingFlushReason = this._pendingFlushReason ?? e, this._flushPromise) : (this._flushPromise = this._flushInternal(e).then(() => {
|
|
67
|
+
const t = this._pendingFlushReason;
|
|
68
|
+
this._pendingFlushReason = void 0, t && this.hasData && !this._isDisposed && this.flush(t);
|
|
69
|
+
}).finally(() => {
|
|
70
|
+
this._flushPromise = void 0;
|
|
71
|
+
}), this._flushPromise);
|
|
72
|
+
}
|
|
73
|
+
async dispose(e) {
|
|
74
|
+
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");
|
|
75
|
+
}
|
|
76
|
+
_attachWindowListeners() {
|
|
77
|
+
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));
|
|
78
|
+
}
|
|
79
|
+
_detachWindowListeners() {
|
|
80
|
+
typeof document == "object" && (document.removeEventListener("click", this._boundClickListener, !0), document.removeEventListener("visibilitychange", this._boundVisibilityChangeListener, !0)), typeof window == "object" && window.removeEventListener("pagehide", this._boundPageHideListener, !0);
|
|
81
|
+
}
|
|
82
|
+
_handleClick() {
|
|
83
|
+
!this.hasData || this._isDisposed || Date.now() - this._lastClickTriggeredAt < this._clickTriggerCooldown || (this._clickTimeoutHandle !== void 0 && clearTimeout(this._clickTimeoutHandle), this._clickTimeoutHandle = setTimeout(() => {
|
|
84
|
+
this._clickTimeoutHandle = void 0, !(!this.hasData || this._isDisposed) && (this._lastClickTriggeredAt = Date.now(), this.flush("click"));
|
|
85
|
+
}, this._clickUploadDelay));
|
|
86
|
+
}
|
|
87
|
+
_handleVisibilityChange() {
|
|
88
|
+
typeof document != "object" || document.visibilityState !== "hidden" || !this.hasData || this.flush("visibilitychange");
|
|
89
|
+
}
|
|
90
|
+
_handlePageHide() {
|
|
91
|
+
this.hasData && this.flush("pagehide");
|
|
92
|
+
}
|
|
93
|
+
_restartInterval() {
|
|
94
|
+
this._stopInterval(), this._intervalHandle = setInterval(() => {
|
|
95
|
+
this.hasData && !this._isDisposed && this.flush("interval");
|
|
96
|
+
}, this._uploadInterval);
|
|
97
|
+
}
|
|
98
|
+
_stopInterval() {
|
|
99
|
+
this._intervalHandle !== void 0 && (clearInterval(this._intervalHandle), this._intervalHandle = void 0);
|
|
100
|
+
}
|
|
101
|
+
_shouldFlushForThreshold() {
|
|
102
|
+
return this.messagesCount >= this._messagesLimit || this.metricsCount >= this._metricsLimit;
|
|
103
|
+
}
|
|
104
|
+
async _flushInternal(e) {
|
|
105
|
+
if (!this.hasData)
|
|
106
|
+
return;
|
|
107
|
+
const t = {
|
|
108
|
+
reason: e,
|
|
109
|
+
messagesCount: this.messagesCount,
|
|
110
|
+
metricsCount: this.metricsCount,
|
|
111
|
+
estimatedByteSize: this.estimatedByteSize,
|
|
112
|
+
triggeredAt: Date.now()
|
|
113
|
+
}, r = this._collector.getRawContentsOfCoreEnvelope(), o = a(r);
|
|
114
|
+
this._restartInterval();
|
|
115
|
+
try {
|
|
116
|
+
await this._onEnvelope(o, t);
|
|
117
|
+
} catch (n) {
|
|
118
|
+
const l = {
|
|
119
|
+
...t,
|
|
120
|
+
error: n
|
|
121
|
+
};
|
|
122
|
+
throw this._onError?.(l), n;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
function b(i, e) {
|
|
127
|
+
if (!i)
|
|
128
|
+
throw new Error("instrumentedApp is required");
|
|
129
|
+
const t = new f(e);
|
|
130
|
+
return i.registerLogCollector(t), i.registerMetricsCollector(t), e.enableClickTrigger !== !1 && i.activateClickTracker?.(), t;
|
|
131
|
+
}
|
|
132
|
+
export {
|
|
133
|
+
f as T,
|
|
134
|
+
b as r
|
|
135
|
+
};
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
import { registerInstrumentedApp as x } from "o11y/client";
|
|
2
|
+
import { g as I } from "./sdk-promise-7SpSqah5.js";
|
|
3
|
+
import { getChatSDK as h } from "./chat/index.js";
|
|
4
|
+
import { r as E } from "./TelemetryUploader-DKkdppe9.js";
|
|
5
|
+
import { analyticsContextSchema as P, sessionSchema as S, pageViewSchema as v, errorContextSchema as k, interactionSchema as C, customEventSchema as _ } from "o11y_schema/sf_mcpanalytics";
|
|
6
|
+
function b(e) {
|
|
7
|
+
const t = (o, d, y, c, s) => {
|
|
8
|
+
e.error(s ?? o);
|
|
9
|
+
}, n = (o) => {
|
|
10
|
+
e.error(o.reason);
|
|
11
|
+
};
|
|
12
|
+
return window.addEventListener("error", t), window.addEventListener("unhandledrejection", n), () => {
|
|
13
|
+
window.removeEventListener("error", t), window.removeEventListener("unhandledrejection", n);
|
|
14
|
+
};
|
|
15
|
+
}
|
|
16
|
+
const D = "aJC", R = "sfdc.pftId", w = /* @__PURE__ */ new Set(), F = /^aJC[0-9A-Za-z]{12}(?:[0-9A-Za-z]{3})?$/;
|
|
17
|
+
function T(e) {
|
|
18
|
+
return typeof e != "string" || e.length === 0 ? !1 : e.length !== 15 && e.length !== 18 ? (A(e, "Expected a 15- or 18-character Salesforce ID"), !1) : F.test(e) ? !0 : (A(e, `Expected a Product Feature Id (prefix "${D}", base62).`), !1);
|
|
19
|
+
}
|
|
20
|
+
function A(e, t) {
|
|
21
|
+
w.has(e) || (w.add(e), console.debug(`[platform-sdk:analytics] Ignoring invalid PFT Id "${e}". ${t}`));
|
|
22
|
+
}
|
|
23
|
+
function u(e, t) {
|
|
24
|
+
return { surface: t };
|
|
25
|
+
}
|
|
26
|
+
const L = {
|
|
27
|
+
callTool: {
|
|
28
|
+
isAsync: !0,
|
|
29
|
+
extractTags: (e, t) => ({ toolName: e[0]?.toolName ?? "unknown", surface: t })
|
|
30
|
+
},
|
|
31
|
+
setWidgetState: {
|
|
32
|
+
isAsync: !1,
|
|
33
|
+
extractTags: u
|
|
34
|
+
},
|
|
35
|
+
getWidgetState: {
|
|
36
|
+
isAsync: !1,
|
|
37
|
+
extractTags: u
|
|
38
|
+
},
|
|
39
|
+
sendMessageToHost: {
|
|
40
|
+
isAsync: !0,
|
|
41
|
+
extractTags: u
|
|
42
|
+
},
|
|
43
|
+
openLink: {
|
|
44
|
+
isAsync: !0,
|
|
45
|
+
extractTags: u
|
|
46
|
+
},
|
|
47
|
+
subscribe: {
|
|
48
|
+
isAsync: !1,
|
|
49
|
+
extractTags: u,
|
|
50
|
+
wrapArgs: (e, t) => {
|
|
51
|
+
const n = e[0];
|
|
52
|
+
return [
|
|
53
|
+
() => {
|
|
54
|
+
t.activity("sdk.subscribe_callback", () => n());
|
|
55
|
+
}
|
|
56
|
+
];
|
|
57
|
+
}
|
|
58
|
+
},
|
|
59
|
+
readResource: {
|
|
60
|
+
isAsync: !0,
|
|
61
|
+
extractTags: (e, t) => ({ uri: e[0]?.uri ?? "unknown", surface: t })
|
|
62
|
+
},
|
|
63
|
+
setDisplayMode: {
|
|
64
|
+
isAsync: !0,
|
|
65
|
+
extractTags: (e, t) => ({ mode: e[0] ?? "unknown", surface: t })
|
|
66
|
+
},
|
|
67
|
+
accessToolOutput: {
|
|
68
|
+
isAsync: !1,
|
|
69
|
+
extractTags: u
|
|
70
|
+
},
|
|
71
|
+
accessToolInput: {
|
|
72
|
+
isAsync: !1,
|
|
73
|
+
extractTags: u
|
|
74
|
+
},
|
|
75
|
+
accessToolMetadata: {
|
|
76
|
+
isAsync: !1,
|
|
77
|
+
extractTags: u
|
|
78
|
+
}
|
|
79
|
+
};
|
|
80
|
+
function N(e, t, n) {
|
|
81
|
+
return new Proxy(e, {
|
|
82
|
+
get(o, d, y) {
|
|
83
|
+
const c = Reflect.get(o, d, y), s = L[d];
|
|
84
|
+
return !s || typeof c != "function" ? c : (...a) => {
|
|
85
|
+
const p = s.extractTags(a, n), m = s.wrapArgs ? s.wrapArgs(a, t) : a, l = `sdk.${String(d)}`;
|
|
86
|
+
return s.isAsync ? t.activityAsync(l, async () => {
|
|
87
|
+
try {
|
|
88
|
+
const g = await c.apply(
|
|
89
|
+
o,
|
|
90
|
+
m
|
|
91
|
+
);
|
|
92
|
+
return t.incrementCounter(l, 1, !1, p), g;
|
|
93
|
+
} catch (g) {
|
|
94
|
+
throw t.incrementCounter(l, 1, !0, p), g;
|
|
95
|
+
}
|
|
96
|
+
}) : (t.incrementCounter(l, 1, !1, p), c.apply(o, m));
|
|
97
|
+
};
|
|
98
|
+
}
|
|
99
|
+
});
|
|
100
|
+
}
|
|
101
|
+
async function j(e) {
|
|
102
|
+
const { appId: t, clientSessionId: n } = e, o = I(), d = Date.now(), y = e.sdk ?? await h();
|
|
103
|
+
let c = null;
|
|
104
|
+
e.pftId !== void 0 && T(e.pftId) && (c = e.pftId);
|
|
105
|
+
const s = x("mcp-widget", {
|
|
106
|
+
appPayloadProvider: {
|
|
107
|
+
getPayload: () => ({
|
|
108
|
+
schema: P,
|
|
109
|
+
payload: {
|
|
110
|
+
appId: t,
|
|
111
|
+
surface: o,
|
|
112
|
+
...c !== null ? { pftId: c } : {}
|
|
113
|
+
}
|
|
114
|
+
})
|
|
115
|
+
},
|
|
116
|
+
clientSessionId: n
|
|
117
|
+
}), a = s, p = N(y, a, o), m = b(a);
|
|
118
|
+
let l;
|
|
119
|
+
e.transport && (l = E(s, {
|
|
120
|
+
onEnvelope: (r) => {
|
|
121
|
+
e.transport.enqueue(r);
|
|
122
|
+
}
|
|
123
|
+
}));
|
|
124
|
+
let g, f = !1;
|
|
125
|
+
return {
|
|
126
|
+
instrumentedSDK: p,
|
|
127
|
+
app: s,
|
|
128
|
+
trackEvent(r, i) {
|
|
129
|
+
f || a.log(_, {
|
|
130
|
+
eventName: r,
|
|
131
|
+
properties: i ? JSON.stringify(i) : ""
|
|
132
|
+
});
|
|
133
|
+
},
|
|
134
|
+
trackInteraction(r, i) {
|
|
135
|
+
f || a.log(C, {
|
|
136
|
+
elementId: r,
|
|
137
|
+
properties: i ? JSON.stringify(i) : ""
|
|
138
|
+
});
|
|
139
|
+
},
|
|
140
|
+
trackError(r, i) {
|
|
141
|
+
f || a.error(r, k, {
|
|
142
|
+
properties: i ? JSON.stringify(i) : ""
|
|
143
|
+
});
|
|
144
|
+
},
|
|
145
|
+
trackPageView(r) {
|
|
146
|
+
f || r !== g && (g = r, a.log(v, { componentRef: r }));
|
|
147
|
+
},
|
|
148
|
+
setPftId(r) {
|
|
149
|
+
f || T(r) && (c = r);
|
|
150
|
+
},
|
|
151
|
+
dispose() {
|
|
152
|
+
if (f) return;
|
|
153
|
+
f = !0, m();
|
|
154
|
+
const r = Date.now() - d;
|
|
155
|
+
a.log(S, { durationMs: r }), l?.dispose();
|
|
156
|
+
}
|
|
157
|
+
};
|
|
158
|
+
}
|
|
159
|
+
export {
|
|
160
|
+
R as P,
|
|
161
|
+
j as c,
|
|
162
|
+
T as v
|
|
163
|
+
};
|
|
@@ -0,0 +1,227 @@
|
|
|
1
|
+
import { w as u, g as c, S as n } from "../sdk-promise-7SpSqah5.js";
|
|
2
|
+
import { M as d } from "../mcpapps-session-BOT5CvWa.js";
|
|
3
|
+
class p {
|
|
4
|
+
constructor(t) {
|
|
5
|
+
this.session = t;
|
|
6
|
+
const e = t.getHostContext();
|
|
7
|
+
e.toolOutput !== void 0 && (this.globals.toolOutput = e.toolOutput), e.toolStructuredContent !== void 0 && (this.globals.toolStructuredContent = e.toolStructuredContent), e.toolInput !== void 0 && (this.globals.toolInput = e.toolInput), e.toolResponseMetadata !== void 0 && (this.globals.toolResponseMetadata = e.toolResponseMetadata), e.widgetState !== void 0 && (this.globals.widgetState = e.widgetState), t.registerNotificationHandler(
|
|
8
|
+
"ui/notifications/host-context-changed",
|
|
9
|
+
() => this.notifySubscribers()
|
|
10
|
+
), t.registerNotificationHandler(
|
|
11
|
+
"ui/notifications/tool-result",
|
|
12
|
+
(o) => this.handleToolResult(o)
|
|
13
|
+
), t.registerNotificationHandler(
|
|
14
|
+
"ui/notifications/tool-input",
|
|
15
|
+
(o) => this.handleToolInput(o)
|
|
16
|
+
), t.registerNotificationHandler(
|
|
17
|
+
"ui/notifications/tool-cancelled",
|
|
18
|
+
(o) => this.handleToolCancelled(o)
|
|
19
|
+
);
|
|
20
|
+
}
|
|
21
|
+
globals = {};
|
|
22
|
+
canceledCallbacks = /* @__PURE__ */ new Set();
|
|
23
|
+
subscriptions = /* @__PURE__ */ new Set();
|
|
24
|
+
/**
|
|
25
|
+
* Handle tool result notifications from the host
|
|
26
|
+
* @param params - Tool result data from the host
|
|
27
|
+
*/
|
|
28
|
+
handleToolResult(t) {
|
|
29
|
+
const e = t;
|
|
30
|
+
let o = !1;
|
|
31
|
+
e.content !== void 0 && (this.globals.toolOutput = e.content, o = !0), e.structuredContent !== void 0 && (this.globals.toolStructuredContent = e.structuredContent, o = !0), e._meta !== void 0 && (this.globals.toolResponseMetadata = e._meta, o = !0), o && this.notifySubscribers();
|
|
32
|
+
}
|
|
33
|
+
/**
|
|
34
|
+
* Handle tool input notifications from the host
|
|
35
|
+
* @param params - Tool input data from the host
|
|
36
|
+
*/
|
|
37
|
+
handleToolInput(t) {
|
|
38
|
+
const e = t;
|
|
39
|
+
e.arguments !== void 0 && Object.keys(e.arguments).length > 0 && (this.globals.toolInput = e.arguments, this.notifySubscribers());
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Handle tool cancelled notifications from the host
|
|
43
|
+
* @param params - Tool cancellation data from the host
|
|
44
|
+
*/
|
|
45
|
+
handleToolCancelled(t) {
|
|
46
|
+
const o = t.reason ?? "";
|
|
47
|
+
this.canceledCallbacks.forEach((l) => l(o));
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Request display mode change from host
|
|
51
|
+
* @param mode - The requested display mode
|
|
52
|
+
* @returns Promise with the new display mode (confirmed by host)
|
|
53
|
+
*/
|
|
54
|
+
async setDisplayMode(t) {
|
|
55
|
+
return await this.session.request("ui/request-display-mode", {
|
|
56
|
+
displayMode: t
|
|
57
|
+
});
|
|
58
|
+
}
|
|
59
|
+
async sendMessageToHost(t) {
|
|
60
|
+
await this.session.request("ui/message", {
|
|
61
|
+
role: "user",
|
|
62
|
+
content: [
|
|
63
|
+
{
|
|
64
|
+
type: "text",
|
|
65
|
+
text: t.content
|
|
66
|
+
}
|
|
67
|
+
]
|
|
68
|
+
});
|
|
69
|
+
}
|
|
70
|
+
async callTool(t) {
|
|
71
|
+
return await this.session.request("tools/call", {
|
|
72
|
+
name: t.toolName,
|
|
73
|
+
arguments: t.params ?? {}
|
|
74
|
+
});
|
|
75
|
+
}
|
|
76
|
+
async readResource(t) {
|
|
77
|
+
return await this.session.request("resources/read", {
|
|
78
|
+
uri: t.uri
|
|
79
|
+
});
|
|
80
|
+
}
|
|
81
|
+
async openLink(t) {
|
|
82
|
+
await this.session.request("ui/open-link", { url: t });
|
|
83
|
+
}
|
|
84
|
+
accessToolInput() {
|
|
85
|
+
const t = this.globals.toolInput;
|
|
86
|
+
return t ? { data: t } : null;
|
|
87
|
+
}
|
|
88
|
+
accessToolOutput() {
|
|
89
|
+
const t = this.globals.toolStructuredContent;
|
|
90
|
+
if (t)
|
|
91
|
+
return { data: t };
|
|
92
|
+
const e = this.globals.toolOutput;
|
|
93
|
+
return e ? { data: e } : null;
|
|
94
|
+
}
|
|
95
|
+
accessToolMetadata() {
|
|
96
|
+
if (this.globals.toolResponseMetadata)
|
|
97
|
+
return this.globals.toolResponseMetadata;
|
|
98
|
+
const t = this.session.getHostContext().toolInfo;
|
|
99
|
+
return t || null;
|
|
100
|
+
}
|
|
101
|
+
getWidgetState() {
|
|
102
|
+
const t = this.globals.widgetState;
|
|
103
|
+
return t || null;
|
|
104
|
+
}
|
|
105
|
+
setWidgetState(t, e) {
|
|
106
|
+
this.globals.widgetState = t;
|
|
107
|
+
const o = { state: t };
|
|
108
|
+
e?.content !== void 0 && (o.content = e.content), e?.structuredContent !== void 0 && (o.structuredContent = e.structuredContent), this.session.request("ui/update-model-context", o).catch(() => {
|
|
109
|
+
}), this.notifySubscribers();
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Get the current host context.
|
|
113
|
+
*
|
|
114
|
+
* Maps MCP Apps wire-format fields to the protocol-agnostic HostContext.
|
|
115
|
+
* Always returns an object (empty `{}` when no context has been received).
|
|
116
|
+
*/
|
|
117
|
+
getHostContext() {
|
|
118
|
+
const t = this.session.getHostContext(), e = {};
|
|
119
|
+
if (t.theme !== void 0 && (e.theme = t.theme), t.displayMode !== void 0 && (e.displayMode = t.displayMode), t.containerDimensions !== void 0) {
|
|
120
|
+
const o = t.containerDimensions.maxHeight ?? t.containerDimensions.height;
|
|
121
|
+
o !== void 0 && (e.maxHeight = o);
|
|
122
|
+
}
|
|
123
|
+
return t.safeAreaInsets !== void 0 && (e.safeArea = t.safeAreaInsets), t.userAgent !== void 0 && (e.userAgent = t.userAgent), t.locale !== void 0 && (e.locale = t.locale), t.deviceCapabilities !== void 0 && (e.deviceCapabilities = t.deviceCapabilities), t.styles !== void 0 && (e.styles = t.styles), e;
|
|
124
|
+
}
|
|
125
|
+
onToolCanceled(t) {
|
|
126
|
+
return this.canceledCallbacks.add(t), () => {
|
|
127
|
+
this.canceledCallbacks.delete(t);
|
|
128
|
+
};
|
|
129
|
+
}
|
|
130
|
+
subscribe(t) {
|
|
131
|
+
return this.subscriptions.add(t), () => {
|
|
132
|
+
this.subscriptions.delete(t);
|
|
133
|
+
};
|
|
134
|
+
}
|
|
135
|
+
notifySubscribers() {
|
|
136
|
+
this.subscriptions.forEach((t) => t());
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
const r = "openai:set_globals";
|
|
140
|
+
class f {
|
|
141
|
+
sendMessageToHost(t) {
|
|
142
|
+
return window.openai.sendFollowUpMessage({ prompt: t.content });
|
|
143
|
+
}
|
|
144
|
+
callTool(t) {
|
|
145
|
+
return window.openai.callTool(t.toolName, t.params ?? {});
|
|
146
|
+
}
|
|
147
|
+
accessToolInput() {
|
|
148
|
+
const t = window.openai.toolInput;
|
|
149
|
+
return t ? { data: t } : null;
|
|
150
|
+
}
|
|
151
|
+
accessToolOutput() {
|
|
152
|
+
const t = window.openai.toolOutput;
|
|
153
|
+
return t ? { data: t } : null;
|
|
154
|
+
}
|
|
155
|
+
accessToolMetadata() {
|
|
156
|
+
const t = window.openai.toolResponseMetadata;
|
|
157
|
+
return t || null;
|
|
158
|
+
}
|
|
159
|
+
getWidgetState() {
|
|
160
|
+
const t = window.openai.widgetState;
|
|
161
|
+
return t || null;
|
|
162
|
+
}
|
|
163
|
+
setWidgetState(t, e) {
|
|
164
|
+
window.openai.setWidgetState(t);
|
|
165
|
+
}
|
|
166
|
+
async openLink(t) {
|
|
167
|
+
const e = window.openai;
|
|
168
|
+
typeof e?.openExternal == "function" ? await e.openExternal({ href: t }) : window.open(t, "_blank", "noopener,noreferrer");
|
|
169
|
+
}
|
|
170
|
+
async setDisplayMode(t) {
|
|
171
|
+
return window.openai.requestDisplayMode({ mode: t });
|
|
172
|
+
}
|
|
173
|
+
subscribe(t) {
|
|
174
|
+
const e = () => t();
|
|
175
|
+
return window.addEventListener(r, e), () => {
|
|
176
|
+
window.removeEventListener(r, e);
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
class h {
|
|
181
|
+
async sendMessageToHost(t) {
|
|
182
|
+
throw console.warn("SalesforceACCChatSDK.sendMessageToHost: stub implementation", t), new Error("SalesforceACCChatSDK.sendMessageToHost not yet implemented");
|
|
183
|
+
}
|
|
184
|
+
followUpActions() {
|
|
185
|
+
return console.warn("SalesforceACCChatSDK.followUpActions: stub implementation"), [];
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
let a = null, i = null;
|
|
189
|
+
function b(s) {
|
|
190
|
+
return a || (a = g(s).then((t) => (i = t, t))), a;
|
|
191
|
+
}
|
|
192
|
+
function C() {
|
|
193
|
+
return i;
|
|
194
|
+
}
|
|
195
|
+
function m() {
|
|
196
|
+
a = null, i = null;
|
|
197
|
+
}
|
|
198
|
+
function g(s) {
|
|
199
|
+
return u(
|
|
200
|
+
(async () => {
|
|
201
|
+
switch (c(s?.surface)) {
|
|
202
|
+
case n.OpenAI:
|
|
203
|
+
return new f();
|
|
204
|
+
case n.WebApp:
|
|
205
|
+
case n.Mosaic:
|
|
206
|
+
return {};
|
|
207
|
+
case n.SalesforceACC:
|
|
208
|
+
return new h();
|
|
209
|
+
case n.MicroFrontend:
|
|
210
|
+
case n.MCPApps: {
|
|
211
|
+
const e = await d.getInstance(s?.mcpApps);
|
|
212
|
+
return e.handshakeSucceeded ? new p(e) : {};
|
|
213
|
+
}
|
|
214
|
+
default:
|
|
215
|
+
return {};
|
|
216
|
+
}
|
|
217
|
+
})(),
|
|
218
|
+
"createChatSDK"
|
|
219
|
+
);
|
|
220
|
+
}
|
|
221
|
+
export {
|
|
222
|
+
p as MCPAppsChatSDK,
|
|
223
|
+
g as createChatSDK,
|
|
224
|
+
b as getChatSDK,
|
|
225
|
+
C as getChatSDKSync,
|
|
226
|
+
m as resetChatSDK
|
|
227
|
+
};
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { S as e } from "../sdk-promise-7SpSqah5.js";
|
|
2
|
+
import { g as i, w as f } from "../sdk-promise-7SpSqah5.js";
|
|
3
|
+
import { M as p } from "../mcpapps-session-BOT5CvWa.js";
|
|
4
|
+
const s = {
|
|
5
|
+
callTool: !0,
|
|
6
|
+
sendMessageToHost: !0,
|
|
7
|
+
readResource: !0,
|
|
8
|
+
openLink: !0,
|
|
9
|
+
accessToolInput: !0,
|
|
10
|
+
accessToolOutput: !0,
|
|
11
|
+
accessToolMetadata: !0,
|
|
12
|
+
getWidgetState: !0,
|
|
13
|
+
setWidgetState: !0,
|
|
14
|
+
setWidgetStateModelContext: !0,
|
|
15
|
+
onToolCanceled: !0,
|
|
16
|
+
setDisplayMode: !0,
|
|
17
|
+
getHostContext: !0,
|
|
18
|
+
subscribe: !0,
|
|
19
|
+
displayAlert: !0,
|
|
20
|
+
displayToast: !0,
|
|
21
|
+
displayModal: !1,
|
|
22
|
+
// TODO
|
|
23
|
+
getTheme: !0,
|
|
24
|
+
resize: !0
|
|
25
|
+
}, a = {
|
|
26
|
+
callTool: !0,
|
|
27
|
+
sendMessageToHost: !0,
|
|
28
|
+
readResource: !1,
|
|
29
|
+
openLink: !0,
|
|
30
|
+
accessToolInput: !0,
|
|
31
|
+
accessToolOutput: !0,
|
|
32
|
+
accessToolMetadata: !0,
|
|
33
|
+
getWidgetState: !0,
|
|
34
|
+
setWidgetState: !0,
|
|
35
|
+
setWidgetStateModelContext: !1,
|
|
36
|
+
onToolCanceled: !1,
|
|
37
|
+
setDisplayMode: !0,
|
|
38
|
+
getHostContext: !1,
|
|
39
|
+
subscribe: !0,
|
|
40
|
+
displayAlert: !0,
|
|
41
|
+
displayToast: !0,
|
|
42
|
+
displayModal: !0,
|
|
43
|
+
getTheme: !0,
|
|
44
|
+
resize: !1
|
|
45
|
+
}, o = {
|
|
46
|
+
callTool: !1,
|
|
47
|
+
sendMessageToHost: !0,
|
|
48
|
+
readResource: !1,
|
|
49
|
+
openLink: !0,
|
|
50
|
+
accessToolInput: !1,
|
|
51
|
+
accessToolOutput: !1,
|
|
52
|
+
accessToolMetadata: !1,
|
|
53
|
+
getWidgetState: !1,
|
|
54
|
+
setWidgetState: !1,
|
|
55
|
+
setWidgetStateModelContext: !1,
|
|
56
|
+
onToolCanceled: !1,
|
|
57
|
+
setDisplayMode: !1,
|
|
58
|
+
getHostContext: !1,
|
|
59
|
+
subscribe: !0,
|
|
60
|
+
displayAlert: !0,
|
|
61
|
+
displayToast: !0,
|
|
62
|
+
displayModal: !1,
|
|
63
|
+
getTheme: !0,
|
|
64
|
+
resize: !1
|
|
65
|
+
}, l = {
|
|
66
|
+
callTool: !1,
|
|
67
|
+
sendMessageToHost: !1,
|
|
68
|
+
readResource: !1,
|
|
69
|
+
openLink: !1,
|
|
70
|
+
accessToolInput: !1,
|
|
71
|
+
accessToolOutput: !1,
|
|
72
|
+
accessToolMetadata: !1,
|
|
73
|
+
getWidgetState: !1,
|
|
74
|
+
setWidgetState: !1,
|
|
75
|
+
setWidgetStateModelContext: !1,
|
|
76
|
+
onToolCanceled: !1,
|
|
77
|
+
setDisplayMode: !1,
|
|
78
|
+
getHostContext: !1,
|
|
79
|
+
subscribe: !1,
|
|
80
|
+
displayAlert: !1,
|
|
81
|
+
displayToast: !1,
|
|
82
|
+
displayModal: !1,
|
|
83
|
+
getTheme: !1,
|
|
84
|
+
resize: !1
|
|
85
|
+
};
|
|
86
|
+
function u(t) {
|
|
87
|
+
switch (t) {
|
|
88
|
+
case e.MCPApps:
|
|
89
|
+
return { ...s };
|
|
90
|
+
case e.OpenAI:
|
|
91
|
+
return { ...a };
|
|
92
|
+
case e.SalesforceACC:
|
|
93
|
+
return { ...o };
|
|
94
|
+
case e.Mosaic:
|
|
95
|
+
case e.WebApp:
|
|
96
|
+
case e.MicroFrontend:
|
|
97
|
+
default:
|
|
98
|
+
return { ...l };
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
export {
|
|
102
|
+
p as McpAppsSession,
|
|
103
|
+
e as Surface,
|
|
104
|
+
i as getSurface,
|
|
105
|
+
u as getSurfaceCapabilities,
|
|
106
|
+
f as wrapSDKPromise
|
|
107
|
+
};
|