@salesforce/sdk-chat 1.81.0 → 1.83.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.d.ts CHANGED
@@ -1,4 +1,4 @@
1
- import type { ChatSDK, SDKOptions, McpAppsSessionOptions } from "@salesforce/sdk-core";
1
+ import { ChatSDK, SDKOptions, McpAppsSessionOptions } from '@salesforce/sdk-core';
2
2
  /**
3
3
  * Options for creating a ChatSDK instance.
4
4
  */
@@ -16,6 +16,6 @@ export interface ChatSDKOptions extends SDKOptions {
16
16
  * @returns Promise resolving to an initialized ChatSDK instance
17
17
  */
18
18
  export declare function createChatSDK(options?: ChatSDKOptions): Promise<ChatSDK>;
19
- export { MCPAppsChatSDK } from "./mcpapps.js";
20
- export type { HostContext, ChatMessage, ChatSDK, DeviceCapabilities, DisplayMode, ResourceRequest, SafeAreaInsets, SDKOptions, ToolCall, ToolState, } from "@salesforce/sdk-core";
19
+ export { MCPAppsChatSDK } from './mcpapps';
20
+ export type { HostContext, ChatMessage, ChatSDK, DeviceCapabilities, DisplayMode, ResourceRequest, SafeAreaInsets, SDKOptions, ToolCall, ToolState, } from '@salesforce/sdk-core';
21
21
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKvF;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IACjD,iEAAiE;IACjE,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyB9E;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,cAAc,CAAC;AAE9C,YAAY,EACX,WAAW,EACX,WAAW,EACX,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,cAAc,EACd,UAAU,EACV,QAAQ,EACR,SAAS,GACT,MAAM,sBAAsB,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAMA,OAAO,KAAK,EAAE,OAAO,EAAE,UAAU,EAAE,qBAAqB,EAAE,MAAM,sBAAsB,CAAC;AAKvF;;GAEG;AACH,MAAM,WAAW,cAAe,SAAQ,UAAU;IACjD,iEAAiE;IACjE,OAAO,CAAC,EAAE,qBAAqB,CAAC;CAChC;AAED;;;;;;;;GAQG;AACH,wBAAsB,aAAa,CAAC,OAAO,CAAC,EAAE,cAAc,GAAG,OAAO,CAAC,OAAO,CAAC,CAyB9E;AAED,OAAO,EAAE,cAAc,EAAE,MAAM,WAAW,CAAC;AAE3C,YAAY,EACX,WAAW,EACX,WAAW,EACX,OAAO,EACP,kBAAkB,EAClB,WAAW,EACX,eAAe,EACf,cAAc,EACd,UAAU,EACV,QAAQ,EACR,SAAS,GACT,MAAM,sBAAsB,CAAC"}
package/dist/index.js CHANGED
@@ -1,45 +1,185 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import { getSurface, Surface, McpAppsSession } from "@salesforce/sdk-core";
7
- import { MCPAppsChatSDK } from "./mcpapps.js";
8
- import { OpenAIChatSDK } from "./openai.js";
9
- import { SalesforceACCChatSDK } from "./salesforce-acc.js";
10
- /**
11
- * Create and initialize a ChatSDK instance based on the detected surface
12
- *
13
- * For MCP Apps surfaces, this performs the SEP-1865 handshake (ui/initialize)
14
- * via the shared {@link McpAppsSession} singleton on the first call.
15
- *
16
- * @param options - Optional configuration including surface override
17
- * @returns Promise resolving to an initialized ChatSDK instance
18
- */
19
- export async function createChatSDK(options) {
20
- const surface = getSurface(options?.surface);
21
- switch (surface) {
22
- case Surface.OpenAI:
23
- return new OpenAIChatSDK();
24
- case Surface.WebApp:
25
- case Surface.MicroFrontend:
26
- return {};
27
- case Surface.SalesforceACC:
28
- return new SalesforceACCChatSDK();
29
- case Surface.MCPApps: {
30
- const session = await McpAppsSession.getInstance(options?.mcpApps);
31
- if (session.handshakeSucceeded) {
32
- return new MCPAppsChatSDK(session);
33
- }
34
- // Handshake timed out — not a real MCP Apps host.
35
- // Fall back to OpenAI if available, otherwise empty.
36
- if (window.openai) {
37
- return new OpenAIChatSDK();
38
- }
39
- return {};
1
+ import { getSurface as l, Surface as o, McpAppsSession as c } from "@salesforce/sdk-core";
2
+ class u {
3
+ constructor(e) {
4
+ this.session = e, e.registerNotificationHandler(
5
+ "ui/notifications/host-context-changed",
6
+ () => this.notifySubscribers()
7
+ ), e.registerNotificationHandler(
8
+ "ui/notifications/tool-result",
9
+ (t) => this.handleToolResult(t)
10
+ ), e.registerNotificationHandler(
11
+ "ui/notifications/tool-input",
12
+ (t) => this.handleToolInput(t)
13
+ ), e.registerNotificationHandler(
14
+ "ui/notifications/tool-cancelled",
15
+ (t) => this.handleToolCancelled(t)
16
+ );
17
+ }
18
+ globals = {};
19
+ canceledCallbacks = /* @__PURE__ */ new Set();
20
+ subscriptions = /* @__PURE__ */ new Set();
21
+ /**
22
+ * Handle tool result notifications from the host
23
+ * @param params - Tool result data from the host
24
+ */
25
+ handleToolResult(e) {
26
+ const t = e;
27
+ t.content !== void 0 && (this.globals.toolOutput = t.content, this.notifySubscribers());
28
+ }
29
+ /**
30
+ * Handle tool input notifications from the host
31
+ * @param params - Tool input data from the host
32
+ */
33
+ handleToolInput(e) {
34
+ const t = e;
35
+ t.arguments !== void 0 && Object.keys(t.arguments).length > 0 && (this.globals.toolInput = t.arguments, this.notifySubscribers());
36
+ }
37
+ /**
38
+ * Handle tool cancelled notifications from the host
39
+ * @param params - Tool cancellation data from the host
40
+ */
41
+ handleToolCancelled(e) {
42
+ const n = e.reason ?? "";
43
+ this.canceledCallbacks.forEach((r) => r(n));
44
+ }
45
+ /**
46
+ * Request display mode change from host
47
+ * @param mode - The requested display mode
48
+ * @returns Promise with the new display mode (confirmed by host)
49
+ */
50
+ async setDisplayMode(e) {
51
+ return await this.session.request("ui/request-display-mode", {
52
+ displayMode: e
53
+ });
54
+ }
55
+ async sendMessageToHost(e) {
56
+ await this.session.request("ui/message", {
57
+ role: "user",
58
+ content: [
59
+ {
60
+ type: "text",
61
+ text: e.content
40
62
  }
41
- default:
42
- return {};
63
+ ]
64
+ });
65
+ }
66
+ async callTool(e) {
67
+ return await this.session.request("tools/call", {
68
+ name: e.toolName,
69
+ arguments: e.params ?? {}
70
+ });
71
+ }
72
+ async readResource(e) {
73
+ return await this.session.request("resources/read", {
74
+ uri: e.uri
75
+ });
76
+ }
77
+ async openLink(e) {
78
+ await this.session.request("ui/open-link", { url: e });
79
+ }
80
+ accessToolInput() {
81
+ const e = this.globals.toolInput;
82
+ return e ? { data: e } : null;
83
+ }
84
+ accessToolOutput() {
85
+ const e = this.globals.toolOutput;
86
+ return e ? { data: e } : null;
87
+ }
88
+ accessToolMetadata() {
89
+ const e = this.session.getHostContext().toolInfo;
90
+ return e || null;
91
+ }
92
+ /**
93
+ * Get the current host context.
94
+ *
95
+ * Maps MCP Apps wire-format fields to the protocol-agnostic HostContext.
96
+ * Always returns an object (empty `{}` when no context has been received).
97
+ */
98
+ getHostContext() {
99
+ const e = this.session.getHostContext(), t = {};
100
+ if (e.theme !== void 0 && (t.theme = e.theme), e.displayMode !== void 0 && (t.displayMode = e.displayMode), e.containerDimensions !== void 0) {
101
+ const n = e.containerDimensions.maxHeight ?? e.containerDimensions.height;
102
+ n !== void 0 && (t.maxHeight = n);
43
103
  }
104
+ 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), t;
105
+ }
106
+ onToolCanceled(e) {
107
+ return this.canceledCallbacks.add(e), () => {
108
+ this.canceledCallbacks.delete(e);
109
+ };
110
+ }
111
+ subscribe(e) {
112
+ return this.subscriptions.add(e), () => {
113
+ this.subscriptions.delete(e);
114
+ };
115
+ }
116
+ notifySubscribers() {
117
+ this.subscriptions.forEach((e) => e());
118
+ }
44
119
  }
45
- export { MCPAppsChatSDK } from "./mcpapps.js";
120
+ const i = "openai:set_globals";
121
+ class a {
122
+ sendMessageToHost(e) {
123
+ return window.openai.sendFollowUpMessage({ prompt: e.content });
124
+ }
125
+ callTool(e) {
126
+ return window.openai.callTool(e.toolName, e.params ?? {});
127
+ }
128
+ accessToolInput() {
129
+ const e = window.openai.toolInput;
130
+ return e ? { data: e } : null;
131
+ }
132
+ accessToolOutput() {
133
+ const e = window.openai.toolOutput;
134
+ return e ? { data: e } : null;
135
+ }
136
+ accessToolMetadata() {
137
+ const e = window.openai.toolResponseMetadata;
138
+ return e || null;
139
+ }
140
+ getWidgetState() {
141
+ const e = window.openai.widgetState;
142
+ return e || null;
143
+ }
144
+ setWidgetState(e) {
145
+ window.openai.setWidgetState(e);
146
+ }
147
+ async setDisplayMode(e) {
148
+ return window.openai.requestDisplayMode({ mode: e });
149
+ }
150
+ subscribe(e) {
151
+ const t = () => e();
152
+ return window.addEventListener(i, t), () => {
153
+ window.removeEventListener(i, t);
154
+ };
155
+ }
156
+ }
157
+ class d {
158
+ async sendMessageToHost(e) {
159
+ throw console.warn("SalesforceACCChatSDK.sendMessageToHost: stub implementation", e), new Error("SalesforceACCChatSDK.sendMessageToHost not yet implemented");
160
+ }
161
+ followUpActions() {
162
+ return console.warn("SalesforceACCChatSDK.followUpActions: stub implementation"), [];
163
+ }
164
+ }
165
+ async function h(s) {
166
+ switch (l(s?.surface)) {
167
+ case o.OpenAI:
168
+ return new a();
169
+ case o.WebApp:
170
+ case o.MicroFrontend:
171
+ return {};
172
+ case o.SalesforceACC:
173
+ return new d();
174
+ case o.MCPApps: {
175
+ const t = await c.getInstance(s?.mcpApps);
176
+ return t.handshakeSucceeded ? new u(t) : window.openai ? new a() : {};
177
+ }
178
+ default:
179
+ return {};
180
+ }
181
+ }
182
+ export {
183
+ u as MCPAppsChatSDK,
184
+ h as createChatSDK
185
+ };
package/dist/mcpapps.d.ts CHANGED
@@ -1,10 +1,4 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import type { ChatSDK, HostContext, ChatMessage, ResourceRequest, ToolCall, ToolState, DisplayMode } from "@salesforce/sdk-core";
7
- import type { McpAppsSession } from "@salesforce/sdk-core";
1
+ import { ChatSDK, HostContext, ChatMessage, ResourceRequest, ToolCall, ToolState, DisplayMode, McpAppsSession } from '@salesforce/sdk-core';
8
2
  /**
9
3
  * Chat SDK implementation for MCP Apps surface using the shared McpAppsSession.
10
4
  *
package/dist/openai.d.ts CHANGED
@@ -1,9 +1,4 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import type { ChatSDK, ChatMessage, DisplayMode, ToolCall, ToolState } from "@salesforce/sdk-core";
1
+ import { ChatSDK, ChatMessage, DisplayMode, ToolCall, ToolState } from '@salesforce/sdk-core';
7
2
  /**
8
3
  * Event type emitted by OpenAI platform when global data changes
9
4
  */
@@ -1,9 +1,4 @@
1
- /**
2
- * Copyright (c) 2026, Salesforce, Inc.,
3
- * All rights reserved.
4
- * For full license text, see the LICENSE.txt file
5
- */
6
- import type { ChatSDK, ChatMessage } from "@salesforce/sdk-core";
1
+ import { ChatSDK, ChatMessage } from '@salesforce/sdk-core';
7
2
  /**
8
3
  * Chat SDK implementation for Salesforce ACC surface
9
4
  * Supports: sendMessageToHost, followUpActions
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sdk-chat",
3
- "version": "1.81.0",
3
+ "version": "1.83.0",
4
4
  "license": "SEE LICENSE IN LICENSE.txt",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",
@@ -18,17 +18,19 @@
18
18
  "dist"
19
19
  ],
20
20
  "scripts": {
21
- "build": "tsc --build",
22
- "clean": "rm -rf dist tsconfig.tsbuildinfo",
23
- "dev": "tsc --build --watch",
21
+ "build": "vite build",
22
+ "clean": "rm -rf dist",
23
+ "dev": "vite build --watch",
24
24
  "test": "vitest run",
25
25
  "test:watch": "vitest",
26
26
  "test:coverage": "vitest run --coverage"
27
27
  },
28
28
  "dependencies": {
29
- "@salesforce/sdk-core": "^1.81.0"
29
+ "@salesforce/sdk-core": "^1.83.0"
30
30
  },
31
31
  "devDependencies": {
32
+ "vite": "^7.3.1",
33
+ "vite-plugin-dts": "^4.5.4",
32
34
  "vitest": "^4.0.6"
33
35
  },
34
36
  "publishConfig": {
package/dist/mcpapps.js DELETED
@@ -1,165 +0,0 @@
1
- /**
2
- * Chat SDK implementation for MCP Apps surface using the shared McpAppsSession.
3
- *
4
- * Supports: sendMessageToHost, callTool, readResource, openLink, accessToolInput, accessToolOutput,
5
- * accessToolMetadata, onToolCanceled, subscribe
6
- *
7
- * Uses a shared {@link McpAppsSession} for JSON-RPC 2.0 transport instead of
8
- * owning its own postMessage listener, avoiding duplicate listeners and ID
9
- * counter collisions when used alongside MCPAppsViewSDK.
10
- */
11
- export class MCPAppsChatSDK {
12
- session;
13
- globals = {};
14
- canceledCallbacks = new Set();
15
- subscriptions = new Set();
16
- constructor(session) {
17
- this.session = session;
18
- // Register notification handlers on the shared session
19
- // Host context merging is handled by the session itself;
20
- // we only listen to notify subscribers of changes.
21
- session.registerNotificationHandler("ui/notifications/host-context-changed", () => this.notifySubscribers());
22
- session.registerNotificationHandler("ui/notifications/tool-result", (params) => this.handleToolResult(params));
23
- session.registerNotificationHandler("ui/notifications/tool-input", (params) => this.handleToolInput(params));
24
- session.registerNotificationHandler("ui/notifications/tool-cancelled", (params) => this.handleToolCancelled(params));
25
- }
26
- /**
27
- * Handle tool result notifications from the host
28
- * @param params - Tool result data from the host
29
- */
30
- handleToolResult(params) {
31
- const toolResult = params;
32
- if (toolResult.content !== undefined) {
33
- this.globals.toolOutput = toolResult.content;
34
- this.notifySubscribers();
35
- }
36
- }
37
- /**
38
- * Handle tool input notifications from the host
39
- * @param params - Tool input data from the host
40
- */
41
- handleToolInput(params) {
42
- const toolInput = params;
43
- // Only store non-empty arguments - treat empty object as "no input"
44
- if (toolInput.arguments !== undefined && Object.keys(toolInput.arguments).length > 0) {
45
- this.globals.toolInput = toolInput.arguments;
46
- this.notifySubscribers();
47
- }
48
- }
49
- /**
50
- * Handle tool cancelled notifications from the host
51
- * @param params - Tool cancellation data from the host
52
- */
53
- handleToolCancelled(params) {
54
- const cancellation = params;
55
- const reason = cancellation.reason ?? "";
56
- this.canceledCallbacks.forEach((callback) => callback(reason));
57
- }
58
- /**
59
- * Request display mode change from host
60
- * @param mode - The requested display mode
61
- * @returns Promise with the new display mode (confirmed by host)
62
- */
63
- async setDisplayMode(mode) {
64
- const response = await this.session.request("ui/request-display-mode", {
65
- displayMode: mode,
66
- });
67
- return response;
68
- }
69
- async sendMessageToHost(message) {
70
- await this.session.request("ui/message", {
71
- role: "user",
72
- content: [
73
- {
74
- type: "text",
75
- text: message.content,
76
- },
77
- ],
78
- });
79
- }
80
- async callTool(toolCall) {
81
- const result = await this.session.request("tools/call", {
82
- name: toolCall.toolName,
83
- arguments: toolCall.params ?? {},
84
- });
85
- return result;
86
- }
87
- async readResource(request) {
88
- const result = await this.session.request("resources/read", {
89
- uri: request.uri,
90
- });
91
- return result;
92
- }
93
- async openLink(url) {
94
- await this.session.request("ui/open-link", { url });
95
- }
96
- accessToolInput() {
97
- const input = this.globals.toolInput;
98
- if (!input)
99
- return null;
100
- return { data: input };
101
- }
102
- accessToolOutput() {
103
- const output = this.globals.toolOutput;
104
- if (!output)
105
- return null;
106
- return { data: output };
107
- }
108
- accessToolMetadata() {
109
- const toolInfo = this.session.getHostContext().toolInfo;
110
- if (!toolInfo)
111
- return null;
112
- return toolInfo;
113
- }
114
- /**
115
- * Get the current host context.
116
- *
117
- * Maps MCP Apps wire-format fields to the protocol-agnostic HostContext.
118
- * Always returns an object (empty `{}` when no context has been received).
119
- */
120
- getHostContext() {
121
- const mcp = this.session.getHostContext();
122
- const result = {};
123
- if (mcp.theme !== undefined) {
124
- result.theme = mcp.theme;
125
- }
126
- if (mcp.displayMode !== undefined) {
127
- result.displayMode = mcp.displayMode;
128
- }
129
- if (mcp.containerDimensions !== undefined) {
130
- const h = mcp.containerDimensions.maxHeight ?? mcp.containerDimensions.height;
131
- if (h !== undefined) {
132
- result.maxHeight = h;
133
- }
134
- }
135
- if (mcp.safeAreaInsets !== undefined) {
136
- result.safeArea = mcp.safeAreaInsets;
137
- }
138
- if (mcp.userAgent !== undefined) {
139
- result.userAgent = mcp.userAgent;
140
- }
141
- if (mcp.locale !== undefined) {
142
- result.locale = mcp.locale;
143
- }
144
- if (mcp.deviceCapabilities !== undefined) {
145
- result.deviceCapabilities = mcp.deviceCapabilities;
146
- }
147
- return result;
148
- }
149
- onToolCanceled(callback) {
150
- this.canceledCallbacks.add(callback);
151
- // Return unsubscribe function
152
- return () => {
153
- this.canceledCallbacks.delete(callback);
154
- };
155
- }
156
- subscribe(callback) {
157
- this.subscriptions.add(callback);
158
- return () => {
159
- this.subscriptions.delete(callback);
160
- };
161
- }
162
- notifySubscribers() {
163
- this.subscriptions.forEach((callback) => callback());
164
- }
165
- }
package/dist/openai.js DELETED
@@ -1,57 +0,0 @@
1
- /**
2
- * Event type emitted by OpenAI platform when global data changes
3
- */
4
- export const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
5
- /**
6
- * Chat SDK implementation for OpenAI surface
7
- * Supports: sendMessageToHost, callTool, accessToolInput, accessToolOutput,
8
- * accessToolMetadata, getWidgetState, setWidgetState, setDisplayMode, subscribe
9
- */
10
- export class OpenAIChatSDK {
11
- sendMessageToHost(message) {
12
- return window.openai.sendFollowUpMessage({ prompt: message.content });
13
- }
14
- callTool(toolCall) {
15
- return window.openai.callTool(toolCall.toolName, toolCall.params ?? {});
16
- }
17
- accessToolInput() {
18
- const input = window.openai.toolInput;
19
- if (!input)
20
- return null;
21
- return { data: input };
22
- }
23
- accessToolOutput() {
24
- const output = window.openai.toolOutput;
25
- if (!output)
26
- return null;
27
- return { data: output };
28
- }
29
- accessToolMetadata() {
30
- const metadata = window.openai.toolResponseMetadata;
31
- if (!metadata)
32
- return null;
33
- return metadata;
34
- }
35
- getWidgetState() {
36
- const state = window.openai.widgetState;
37
- if (!state)
38
- return null;
39
- return state;
40
- }
41
- setWidgetState(state) {
42
- window.openai.setWidgetState(state);
43
- }
44
- async setDisplayMode(mode) {
45
- return window.openai.requestDisplayMode({ mode });
46
- }
47
- subscribe(callback) {
48
- // OpenAI surface emits custom event when data changes
49
- const handler = () => callback();
50
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
51
- window.addEventListener(SET_GLOBALS_EVENT_TYPE, handler);
52
- return () => {
53
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
54
- window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handler);
55
- };
56
- }
57
- }
@@ -1,19 +0,0 @@
1
- /**
2
- * Chat SDK implementation for Salesforce ACC surface
3
- * Supports: sendMessageToHost, followUpActions
4
- *
5
- * NOTE: This is a stub implementation. Actual implementation depends on
6
- * Salesforce ACC surface specification which is not yet available.
7
- */
8
- export class SalesforceACCChatSDK {
9
- async sendMessageToHost(message) {
10
- // TODO: Implement based on Salesforce ACC surface specification
11
- console.warn("SalesforceACCChatSDK.sendMessageToHost: stub implementation", message);
12
- throw new Error("SalesforceACCChatSDK.sendMessageToHost not yet implemented");
13
- }
14
- followUpActions() {
15
- // TODO: Implement based on Salesforce ACC surface specification
16
- console.warn("SalesforceACCChatSDK.followUpActions: stub implementation");
17
- return [];
18
- }
19
- }