@salesforce/sdk-chat 1.6.2
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/LICENSE.txt +82 -0
- package/dist/index.d.ts +94 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +24 -0
- package/dist/mcpapps.d.ts +28 -0
- package/dist/mcpapps.d.ts.map +1 -0
- package/dist/mcpapps.js +96 -0
- package/dist/openai.d.ts +21 -0
- package/dist/openai.d.ts.map +1 -0
- package/dist/openai.js +47 -0
- package/dist/salesforce-acc.d.ts +18 -0
- package/dist/salesforce-acc.d.ts.map +1 -0
- package/dist/salesforce-acc.js +19 -0
- package/package.json +34 -0
package/LICENSE.txt
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
Terms of Use
|
|
2
|
+
|
|
3
|
+
Copyright 2026 Salesforce, Inc. All rights reserved.
|
|
4
|
+
|
|
5
|
+
These Terms of Use govern the download, installation, and/or use of this
|
|
6
|
+
software provided by Salesforce, Inc. ("Salesforce") (the "Software"), were
|
|
7
|
+
last updated on April 15, 2025, and constitute a legally binding
|
|
8
|
+
agreement between you and Salesforce. If you do not agree to these Terms of
|
|
9
|
+
Use, do not install or use the Software.
|
|
10
|
+
|
|
11
|
+
Salesforce grants you a worldwide, non-exclusive, no-charge, royalty-free
|
|
12
|
+
copyright license to reproduce, prepare derivative works of, publicly
|
|
13
|
+
display, publicly perform, sublicense, and distribute the Software and
|
|
14
|
+
derivative works subject to these Terms. These Terms shall be included in
|
|
15
|
+
all copies or substantial portions of the Software.
|
|
16
|
+
|
|
17
|
+
Subject to the limited rights expressly granted hereunder, Salesforce
|
|
18
|
+
reserves all rights, title, and interest in and to all intellectual
|
|
19
|
+
property subsisting in the Software. No rights are granted to you hereunder
|
|
20
|
+
other than as expressly set forth herein. Users residing in countries on
|
|
21
|
+
the United States Office of Foreign Assets Control sanction list, or which
|
|
22
|
+
are otherwise subject to a US export embargo, may not use the Software.
|
|
23
|
+
|
|
24
|
+
Implementation of the Software may require development work, for which you
|
|
25
|
+
are responsible. The Software may contain bugs, errors and
|
|
26
|
+
incompatibilities and is made available on an AS IS basis without support,
|
|
27
|
+
updates, or service level commitments.
|
|
28
|
+
|
|
29
|
+
Salesforce reserves the right at any time to modify, suspend, or
|
|
30
|
+
discontinue, the Software (or any part thereof) with or without notice. You
|
|
31
|
+
agree that Salesforce shall not be liable to you or to any third party for
|
|
32
|
+
any modification, suspension, or discontinuance.
|
|
33
|
+
|
|
34
|
+
You agree to defend Salesforce against any claim, demand, suit or
|
|
35
|
+
proceeding made or brought against Salesforce by a third party arising out
|
|
36
|
+
of or accruing from (a) your use of the Software, and (b) any application
|
|
37
|
+
you develop with the Software that infringes any copyright, trademark,
|
|
38
|
+
trade secret, trade dress, patent, or other intellectual property right of
|
|
39
|
+
any person or defames any person or violates their rights of publicity or
|
|
40
|
+
privacy (each a "Claim Against Salesforce"), and will indemnify Salesforce
|
|
41
|
+
from any damages, attorney fees, and costs finally awarded against
|
|
42
|
+
Salesforce as a result of, or for any amounts paid by Salesforce under a
|
|
43
|
+
settlement approved by you in writing of, a Claim Against Salesforce,
|
|
44
|
+
provided Salesforce (x) promptly gives you written notice of the Claim
|
|
45
|
+
Against Salesforce, (y) gives you sole control of the defense and
|
|
46
|
+
settlement of the Claim Against Salesforce (except that you may not settle
|
|
47
|
+
any Claim Against Salesforce unless it unconditionally releases Salesforce
|
|
48
|
+
of all liability), and (z) gives you all reasonable assistance, at your
|
|
49
|
+
expense.
|
|
50
|
+
|
|
51
|
+
WITHOUT LIMITING THE GENERALITY OF THE FOREGOING, THE SOFTWARE IS NOT
|
|
52
|
+
SUPPORTED AND IS PROVIDED "AS IS," WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
53
|
+
IMPLIED. IN NO EVENT SHALL SALESFORCE HAVE ANY LIABILITY FOR ANY DAMAGES,
|
|
54
|
+
INCLUDING, BUT NOT LIMITED TO, DIRECT, INDIRECT, SPECIAL, INCIDENTAL,
|
|
55
|
+
PUNITIVE, OR CONSEQUENTIAL DAMAGES, OR DAMAGES BASED ON LOST PROFITS, DATA,
|
|
56
|
+
OR USE, IN CONNECTION WITH THE SOFTWARE, HOWEVER CAUSED AND WHETHER IN
|
|
57
|
+
CONTRACT, TORT, OR UNDER ANY OTHER THEORY OF LIABILITY, WHETHER OR NOT YOU
|
|
58
|
+
HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
|
|
59
|
+
|
|
60
|
+
These Terms of Use shall be governed exclusively by the internal laws of
|
|
61
|
+
the State of California, without regard to its conflicts of laws
|
|
62
|
+
rules. Each party hereby consents to the exclusive jurisdiction of the
|
|
63
|
+
state and federal courts located in San Francisco County, California to
|
|
64
|
+
adjudicate any dispute arising out of or relating to these Terms of Use and
|
|
65
|
+
the download, installation, and/or use of the Software. Except as expressly
|
|
66
|
+
stated herein, these Terms of Use constitute the entire agreement between
|
|
67
|
+
the parties, and supersede all prior and contemporaneous agreements,
|
|
68
|
+
proposals, or representations, written or oral, concerning their subject
|
|
69
|
+
matter. No modification, amendment, or waiver of any provision of these
|
|
70
|
+
Terms of Use shall be effective unless it is by an update to these Terms of
|
|
71
|
+
Use that Salesforce makes available, or is in writing and signed by the
|
|
72
|
+
party against whom the modification, amendment, or waiver is to be
|
|
73
|
+
asserted.
|
|
74
|
+
|
|
75
|
+
Data Privacy: Salesforce may collect, process, and store device,
|
|
76
|
+
system, and other information related to your use of the Software. This
|
|
77
|
+
information includes, but is not limited to, IP address, user metrics, and
|
|
78
|
+
other data ("Usage Data"). Salesforce may use Usage Data for analytics,
|
|
79
|
+
product development, and marketing purposes. You acknowledge that files
|
|
80
|
+
generated in conjunction with the Software may contain sensitive or
|
|
81
|
+
confidential data, and you are solely responsible for anonymizing and
|
|
82
|
+
protecting such data.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,94 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Message payload for chat stream
|
|
3
|
+
*/
|
|
4
|
+
export interface ChatMessage {
|
|
5
|
+
content: string;
|
|
6
|
+
metadata?: Record<string, unknown>;
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Tool execution payload
|
|
10
|
+
*/
|
|
11
|
+
export interface ToolCall {
|
|
12
|
+
toolName: string;
|
|
13
|
+
params?: Record<string, unknown>;
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* Resource read request
|
|
17
|
+
*/
|
|
18
|
+
export interface ResourceRequest {
|
|
19
|
+
uri: string;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Tool input/output state
|
|
23
|
+
*/
|
|
24
|
+
export interface ToolState<T = unknown> {
|
|
25
|
+
data: T;
|
|
26
|
+
timestamp?: number;
|
|
27
|
+
}
|
|
28
|
+
/**
|
|
29
|
+
* Chat SDK API with optional methods based on surface capabilities
|
|
30
|
+
*/
|
|
31
|
+
export interface ChatSDK {
|
|
32
|
+
/**
|
|
33
|
+
* Send a message to the host
|
|
34
|
+
*
|
|
35
|
+
* @param message - The message to send
|
|
36
|
+
*/
|
|
37
|
+
sendMessageToHost?: (message: ChatMessage) => Promise<void>;
|
|
38
|
+
/**
|
|
39
|
+
* Execute a tool on the MCP Server
|
|
40
|
+
*
|
|
41
|
+
* @param toolCall - The tool to call with parameters
|
|
42
|
+
*/
|
|
43
|
+
callTool?: <T>(toolCall: ToolCall) => Promise<T>;
|
|
44
|
+
/**
|
|
45
|
+
* Access the current tool input data
|
|
46
|
+
*
|
|
47
|
+
* @returns The tool input data or null if not available
|
|
48
|
+
*/
|
|
49
|
+
accessToolInput?: <T>() => ToolState<T> | null;
|
|
50
|
+
/**
|
|
51
|
+
* Set the tool output data
|
|
52
|
+
*
|
|
53
|
+
* @param state - The tool output state to set
|
|
54
|
+
*/
|
|
55
|
+
accessToolOutput?: <T>(state: ToolState<T>) => void;
|
|
56
|
+
/**
|
|
57
|
+
* Access metadata about the current tool
|
|
58
|
+
*
|
|
59
|
+
* @returns Tool metadata including schema, description, etc.
|
|
60
|
+
*/
|
|
61
|
+
accessToolMetadata?: <T>() => T | null;
|
|
62
|
+
/**
|
|
63
|
+
* Get the current widget state
|
|
64
|
+
*
|
|
65
|
+
* @returns The widget state or null if not available
|
|
66
|
+
*/
|
|
67
|
+
getWidgetState?: <T>() => T | null;
|
|
68
|
+
/**
|
|
69
|
+
* Set the widget state
|
|
70
|
+
*
|
|
71
|
+
* @param state - The widget state to persist
|
|
72
|
+
*/
|
|
73
|
+
setWidgetState?: <T>(state: T) => void;
|
|
74
|
+
/**
|
|
75
|
+
* Read resource content by URI
|
|
76
|
+
*
|
|
77
|
+
* @param request - The resource request with URI
|
|
78
|
+
*/
|
|
79
|
+
readResource?: <T>(request: ResourceRequest) => Promise<T>;
|
|
80
|
+
/**
|
|
81
|
+
* Register a callback for when tool execution is canceled
|
|
82
|
+
*
|
|
83
|
+
* @param callback - Function to call when tool is canceled
|
|
84
|
+
*/
|
|
85
|
+
onToolCanceled?: (callback: () => void) => void;
|
|
86
|
+
/**
|
|
87
|
+
* Get available follow-up actions
|
|
88
|
+
*
|
|
89
|
+
* @returns Array of available actions
|
|
90
|
+
*/
|
|
91
|
+
followUpActions?: <T>() => T[];
|
|
92
|
+
}
|
|
93
|
+
export declare const sdk: ChatSDK;
|
|
94
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAUA;;GAEG;AACH,MAAM,WAAW,WAAW;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACnC;AAED;;GAEG;AACH,MAAM,WAAW,QAAQ;IACxB,QAAQ,EAAE,MAAM,CAAC;IACjB,MAAM,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,CAAC;CACjC;AAED;;GAEG;AACH,MAAM,WAAW,eAAe;IAC/B,GAAG,EAAE,MAAM,CAAC;CACZ;AAED;;GAEG;AACH,MAAM,WAAW,SAAS,CAAC,CAAC,GAAG,OAAO;IACrC,IAAI,EAAE,CAAC,CAAC;IACR,SAAS,CAAC,EAAE,MAAM,CAAC;CACnB;AAED;;GAEG;AACH,MAAM,WAAW,OAAO;IACvB;;;;OAIG;IACH,iBAAiB,CAAC,EAAE,CAAC,OAAO,EAAE,WAAW,KAAK,OAAO,CAAC,IAAI,CAAC,CAAC;IAE5D;;;;OAIG;IACH,QAAQ,CAAC,EAAE,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAEjD;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI,CAAC;IAE/C;;;;OAIG;IACH,gBAAgB,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,KAAK,IAAI,CAAC;IAEpD;;;;OAIG;IACH,kBAAkB,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAEvC;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,GAAG,IAAI,CAAC;IAEnC;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,KAAK,IAAI,CAAC;IAEvC;;;;OAIG;IACH,YAAY,CAAC,EAAE,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,KAAK,OAAO,CAAC,CAAC,CAAC,CAAC;IAE3D;;;;OAIG;IACH,cAAc,CAAC,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,IAAI,CAAC;IAEhD;;;;OAIG;IACH,eAAe,CAAC,EAAE,CAAC,CAAC,OAAO,CAAC,EAAE,CAAC;CAC/B;AAiBD,eAAO,MAAM,GAAG,SAAe,CAAC"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,24 @@
|
|
|
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 } from "@salesforce/sdk-core";
|
|
7
|
+
import { MCPAppsChatSDK } from "./mcpapps.js";
|
|
8
|
+
import { OpenAIChatSDK } from "./openai.js";
|
|
9
|
+
import { SalesforceACCChatSDK } from "./salesforce-acc.js";
|
|
10
|
+
function initialize() {
|
|
11
|
+
const surface = getSurface();
|
|
12
|
+
switch (surface) {
|
|
13
|
+
case Surface.OpenAI:
|
|
14
|
+
return new OpenAIChatSDK();
|
|
15
|
+
case Surface.Webapp:
|
|
16
|
+
case Surface.MicroFrontend:
|
|
17
|
+
return new MCPAppsChatSDK();
|
|
18
|
+
case Surface.SalesforceACC:
|
|
19
|
+
return new SalesforceACCChatSDK();
|
|
20
|
+
default:
|
|
21
|
+
throw new Error(`ChatSDK not available in ${surface}`);
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
export const sdk = initialize();
|
|
@@ -0,0 +1,28 @@
|
|
|
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, ToolCall, ResourceRequest, ToolState } from "./index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Chat SDK implementation for Webapp and MicroFrontend surfaces using MCP Apps protocol
|
|
9
|
+
* Supports: sendMessageToHost, callTool, readResource, accessToolInput, accessToolOutput,
|
|
10
|
+
* accessToolMetadata (stub), onToolCanceled (stub)
|
|
11
|
+
*/
|
|
12
|
+
export declare class MCPAppsChatSDK implements ChatSDK {
|
|
13
|
+
private nextMessageId;
|
|
14
|
+
private pending;
|
|
15
|
+
private globals;
|
|
16
|
+
private canceledCallbacks;
|
|
17
|
+
constructor();
|
|
18
|
+
private onMessage;
|
|
19
|
+
private request;
|
|
20
|
+
sendMessageToHost(message: ChatMessage): Promise<void>;
|
|
21
|
+
callTool<T>(toolCall: ToolCall): Promise<T>;
|
|
22
|
+
readResource<T>(request: ResourceRequest): Promise<T>;
|
|
23
|
+
accessToolInput<T>(): ToolState<T> | null;
|
|
24
|
+
accessToolOutput<T>(state: ToolState<T>): void;
|
|
25
|
+
accessToolMetadata<T>(): T | null;
|
|
26
|
+
onToolCanceled(callback: () => void): void;
|
|
27
|
+
}
|
|
28
|
+
//# sourceMappingURL=mcpapps.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcpapps.d.ts","sourceRoot":"","sources":["../src/mcpapps.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,eAAe,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAqB7F;;;;GAIG;AACH,qBAAa,cAAe,YAAW,OAAO;IAC7C,OAAO,CAAC,aAAa,CAAK;IAC1B,OAAO,CAAC,OAAO,CAGX;IACJ,OAAO,CAAC,OAAO,CAIR;IACP,OAAO,CAAC,iBAAiB,CAAsB;;IAY/C,OAAO,CAAC,SAAS,CA+Bf;IAEF,OAAO,CAAC,OAAO;IAUT,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAItD,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IAQ3C,YAAY,CAAC,CAAC,EAAE,OAAO,EAAE,eAAe,GAAG,OAAO,CAAC,CAAC,CAAC;IAK3D,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAMzC,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAY9C,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI;IAOjC,cAAc,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;CAI1C"}
|
package/dist/mcpapps.js
ADDED
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat SDK implementation for Webapp and MicroFrontend surfaces using MCP Apps protocol
|
|
3
|
+
* Supports: sendMessageToHost, callTool, readResource, accessToolInput, accessToolOutput,
|
|
4
|
+
* accessToolMetadata (stub), onToolCanceled (stub)
|
|
5
|
+
*/
|
|
6
|
+
export class MCPAppsChatSDK {
|
|
7
|
+
nextMessageId = 1;
|
|
8
|
+
pending = new Map();
|
|
9
|
+
globals = {};
|
|
10
|
+
canceledCallbacks = [];
|
|
11
|
+
constructor() {
|
|
12
|
+
// Listen for messages from parent window
|
|
13
|
+
window.addEventListener("message", this.onMessage);
|
|
14
|
+
// Notify parent that iframe is ready
|
|
15
|
+
if (window.self !== window.top) {
|
|
16
|
+
window.parent?.postMessage({ type: "ui-lifecycle-iframe-ready" }, "*");
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
onMessage = (event) => {
|
|
20
|
+
const data = event.data || {};
|
|
21
|
+
// Handle render data with toolInput/toolOutput
|
|
22
|
+
if (data.type === "ui-lifecycle-iframe-render-data") {
|
|
23
|
+
const renderData = data.payload?.renderData;
|
|
24
|
+
if (renderData) {
|
|
25
|
+
if (renderData.toolInput !== undefined) {
|
|
26
|
+
this.globals.toolInput = renderData.toolInput;
|
|
27
|
+
}
|
|
28
|
+
if (renderData.toolOutput !== undefined) {
|
|
29
|
+
this.globals.toolOutput = renderData.toolOutput;
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
// Handle message responses
|
|
34
|
+
if (data.type === "ui-message-response" || data.type === "ui-message-received") {
|
|
35
|
+
const response = data;
|
|
36
|
+
const id = response.messageId;
|
|
37
|
+
const slot = id ? this.pending.get(id) : undefined;
|
|
38
|
+
if (slot && response.type === "ui-message-response") {
|
|
39
|
+
this.pending.delete(id);
|
|
40
|
+
if (response.payload?.error) {
|
|
41
|
+
slot.reject(new Error(response.payload.error));
|
|
42
|
+
}
|
|
43
|
+
else {
|
|
44
|
+
slot.resolve(response.payload?.response);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
};
|
|
49
|
+
request(type, payload) {
|
|
50
|
+
const id = String(this.nextMessageId++);
|
|
51
|
+
const message = { type, messageId: id, payload };
|
|
52
|
+
return new Promise((resolve, reject) => {
|
|
53
|
+
this.pending.set(id, { resolve, reject });
|
|
54
|
+
window.parent?.postMessage(message, "*");
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
async sendMessageToHost(message) {
|
|
58
|
+
await this.request("prompt", { prompt: message.content });
|
|
59
|
+
}
|
|
60
|
+
async callTool(toolCall) {
|
|
61
|
+
const result = await this.request("tool", {
|
|
62
|
+
toolName: toolCall.toolName,
|
|
63
|
+
params: toolCall.params ?? {},
|
|
64
|
+
});
|
|
65
|
+
return result;
|
|
66
|
+
}
|
|
67
|
+
async readResource(request) {
|
|
68
|
+
const result = await this.request("resource", { uri: request.uri });
|
|
69
|
+
return result;
|
|
70
|
+
}
|
|
71
|
+
accessToolInput() {
|
|
72
|
+
const input = this.globals.toolInput;
|
|
73
|
+
if (!input)
|
|
74
|
+
return null;
|
|
75
|
+
return { data: input };
|
|
76
|
+
}
|
|
77
|
+
accessToolOutput(state) {
|
|
78
|
+
this.globals.toolOutput = state.data;
|
|
79
|
+
// Notify parent of state change
|
|
80
|
+
window.parent?.postMessage({
|
|
81
|
+
type: "set-widget-state",
|
|
82
|
+
payload: state.data,
|
|
83
|
+
}, "*");
|
|
84
|
+
}
|
|
85
|
+
accessToolMetadata() {
|
|
86
|
+
// TODO: Implement once MCP Apps protocol specifies tool metadata format
|
|
87
|
+
const metadata = this.globals.toolMetadata;
|
|
88
|
+
if (!metadata)
|
|
89
|
+
return null;
|
|
90
|
+
return metadata;
|
|
91
|
+
}
|
|
92
|
+
onToolCanceled(callback) {
|
|
93
|
+
// TODO: Implement once MCP Apps protocol specifies cancellation event
|
|
94
|
+
this.canceledCallbacks.push(callback);
|
|
95
|
+
}
|
|
96
|
+
}
|
package/dist/openai.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
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, ToolCall, ToolState } from "./index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Chat SDK implementation for OpenAI surface
|
|
9
|
+
* Supports: sendMessageToHost, callTool, accessToolInput, accessToolOutput,
|
|
10
|
+
* accessToolMetadata, getWidgetState, setWidgetState
|
|
11
|
+
*/
|
|
12
|
+
export declare class OpenAIChatSDK implements ChatSDK {
|
|
13
|
+
sendMessageToHost(message: ChatMessage): Promise<void>;
|
|
14
|
+
callTool<T>(toolCall: ToolCall): Promise<T>;
|
|
15
|
+
accessToolInput<T>(): ToolState<T> | null;
|
|
16
|
+
accessToolOutput<T>(state: ToolState<T>): void;
|
|
17
|
+
accessToolMetadata<T>(): T | null;
|
|
18
|
+
getWidgetState<T>(): T | null;
|
|
19
|
+
setWidgetState<T>(state: T): void;
|
|
20
|
+
}
|
|
21
|
+
//# sourceMappingURL=openai.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"openai.d.ts","sourceRoot":"","sources":["../src/openai.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,YAAY,CAAC;AAE5E;;;;GAIG;AACH,qBAAa,aAAc,YAAW,OAAO;IAC5C,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAOtD,QAAQ,CAAC,CAAC,EAAE,QAAQ,EAAE,QAAQ,GAAG,OAAO,CAAC,CAAC,CAAC;IAO3C,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAMzC,gBAAgB,CAAC,CAAC,EAAE,KAAK,EAAE,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAM9C,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI;IAMjC,cAAc,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI;IAM7B,cAAc,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,GAAG,IAAI;CAKjC"}
|
package/dist/openai.js
ADDED
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Chat SDK implementation for OpenAI surface
|
|
3
|
+
* Supports: sendMessageToHost, callTool, accessToolInput, accessToolOutput,
|
|
4
|
+
* accessToolMetadata, getWidgetState, setWidgetState
|
|
5
|
+
*/
|
|
6
|
+
export class OpenAIChatSDK {
|
|
7
|
+
sendMessageToHost(message) {
|
|
8
|
+
if (window.openai?.sendFollowUpMessage) {
|
|
9
|
+
return window.openai.sendFollowUpMessage({ prompt: message.content });
|
|
10
|
+
}
|
|
11
|
+
throw new Error("window.openai.sendFollowUpMessage is not available");
|
|
12
|
+
}
|
|
13
|
+
callTool(toolCall) {
|
|
14
|
+
if (window.openai?.callTool) {
|
|
15
|
+
return window.openai.callTool(toolCall.toolName, toolCall.params ?? {});
|
|
16
|
+
}
|
|
17
|
+
throw new Error("window.openai.callTool is not available");
|
|
18
|
+
}
|
|
19
|
+
accessToolInput() {
|
|
20
|
+
const input = window.openai?.toolInput;
|
|
21
|
+
if (!input)
|
|
22
|
+
return null;
|
|
23
|
+
return { data: input };
|
|
24
|
+
}
|
|
25
|
+
accessToolOutput(state) {
|
|
26
|
+
if (window.openai) {
|
|
27
|
+
window.openai.toolOutput = state.data;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
accessToolMetadata() {
|
|
31
|
+
const metadata = window.openai?.toolResponseMetadata;
|
|
32
|
+
if (!metadata)
|
|
33
|
+
return null;
|
|
34
|
+
return metadata;
|
|
35
|
+
}
|
|
36
|
+
getWidgetState() {
|
|
37
|
+
const state = window.openai?.widgetState;
|
|
38
|
+
if (!state)
|
|
39
|
+
return null;
|
|
40
|
+
return state;
|
|
41
|
+
}
|
|
42
|
+
setWidgetState(state) {
|
|
43
|
+
if (window.openai?.setWidgetState) {
|
|
44
|
+
window.openai.setWidgetState(state);
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,18 @@
|
|
|
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 "./index.js";
|
|
7
|
+
/**
|
|
8
|
+
* Chat SDK implementation for Salesforce ACC surface
|
|
9
|
+
* Supports: sendMessageToHost, followUpActions
|
|
10
|
+
*
|
|
11
|
+
* NOTE: This is a stub implementation. Actual implementation depends on
|
|
12
|
+
* Salesforce ACC surface specification which is not yet available.
|
|
13
|
+
*/
|
|
14
|
+
export declare class SalesforceACCChatSDK implements ChatSDK {
|
|
15
|
+
sendMessageToHost(message: ChatMessage): Promise<void>;
|
|
16
|
+
followUpActions<T>(): T[];
|
|
17
|
+
}
|
|
18
|
+
//# sourceMappingURL=salesforce-acc.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"salesforce-acc.d.ts","sourceRoot":"","sources":["../src/salesforce-acc.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EAAE,OAAO,EAAE,WAAW,EAAE,MAAM,YAAY,CAAC;AAEvD;;;;;;GAMG;AACH,qBAAa,oBAAqB,YAAW,OAAO;IAC7C,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAM5D,eAAe,CAAC,CAAC,KAAK,CAAC,EAAE;CAKzB"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
}
|
package/package.json
ADDED
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@salesforce/sdk-chat",
|
|
3
|
+
"version": "1.6.2",
|
|
4
|
+
"type": "module",
|
|
5
|
+
"main": "./dist/index.js",
|
|
6
|
+
"module": "./dist/index.js",
|
|
7
|
+
"types": "./dist/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
"./package.json": "./package.json",
|
|
10
|
+
".": {
|
|
11
|
+
"types": "./dist/index.d.ts",
|
|
12
|
+
"import": "./dist/index.js",
|
|
13
|
+
"default": "./dist/index.js"
|
|
14
|
+
}
|
|
15
|
+
},
|
|
16
|
+
"files": [
|
|
17
|
+
"dist"
|
|
18
|
+
],
|
|
19
|
+
"scripts": {
|
|
20
|
+
"build": "tsc --build",
|
|
21
|
+
"clean": "rm -rf dist tsconfig.tsbuildinfo",
|
|
22
|
+
"dev": "tsc --build --watch",
|
|
23
|
+
"test": "vitest run",
|
|
24
|
+
"test:watch": "vitest",
|
|
25
|
+
"test:coverage": "vitest run --coverage"
|
|
26
|
+
},
|
|
27
|
+
"dependencies": {
|
|
28
|
+
"@salesforce/sdk-core": "^1.6.2"
|
|
29
|
+
},
|
|
30
|
+
"devDependencies": {
|
|
31
|
+
"vitest": "^4.0.6"
|
|
32
|
+
},
|
|
33
|
+
"gitHead": "3eb79262b3c2c37339863ab1b51e54bcb1ecf07f"
|
|
34
|
+
}
|