@salesforce/sdk-chat 1.51.0 → 1.52.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/mcpapps.d.ts +35 -9
- package/dist/mcpapps.d.ts.map +1 -1
- package/dist/mcpapps.js +87 -62
- package/package.json +3 -3
package/dist/mcpapps.d.ts
CHANGED
|
@@ -3,29 +3,55 @@
|
|
|
3
3
|
* All rights reserved.
|
|
4
4
|
* For full license text, see the LICENSE.txt file
|
|
5
5
|
*/
|
|
6
|
-
import type { ChatSDK, ChatMessage, ResourceRequest, ToolCall, ToolState } from "@salesforce/sdk-core";
|
|
6
|
+
import type { ChatSDK, ChatMessage, ResourceRequest, ToolCall, ToolState, DisplayMode } from "@salesforce/sdk-core";
|
|
7
|
+
import { JsonRpcClient } from "@salesforce/sdk-core";
|
|
7
8
|
/**
|
|
8
9
|
* Chat SDK implementation for Webapp and MicroFrontend surfaces using MCP Apps protocol
|
|
9
10
|
* Supports: sendMessageToHost, callTool, readResource, accessToolInput, accessToolOutput,
|
|
10
|
-
* accessToolMetadata (stub), onToolCanceled
|
|
11
|
+
* accessToolMetadata (stub), onToolCanceled, subscribe
|
|
12
|
+
* Extends JsonRpcClient for JSON-RPC 2.0 notification support
|
|
11
13
|
*/
|
|
12
|
-
export declare class MCPAppsChatSDK implements ChatSDK {
|
|
13
|
-
private
|
|
14
|
-
private pending;
|
|
14
|
+
export declare class MCPAppsChatSDK extends JsonRpcClient implements ChatSDK {
|
|
15
|
+
private chatHostContext;
|
|
15
16
|
private globals;
|
|
16
17
|
private canceledCallbacks;
|
|
17
18
|
private subscriptions;
|
|
18
19
|
constructor();
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
20
|
+
/**
|
|
21
|
+
* Handle host context change notifications from the host
|
|
22
|
+
* @param params - Partial host context update from the host
|
|
23
|
+
*/
|
|
24
|
+
private handleHostContextChanged;
|
|
25
|
+
/**
|
|
26
|
+
* Handle tool result notifications from the host
|
|
27
|
+
* @param params - Tool result data from the host
|
|
28
|
+
*/
|
|
29
|
+
private handleToolResult;
|
|
30
|
+
/**
|
|
31
|
+
* Handle tool input notifications from the host
|
|
32
|
+
* @param params - Tool input data from the host
|
|
33
|
+
*/
|
|
34
|
+
private handleToolInput;
|
|
35
|
+
/**
|
|
36
|
+
* Handle tool cancelled notifications from the host
|
|
37
|
+
* @param params - Tool cancellation data from the host
|
|
38
|
+
*/
|
|
39
|
+
private handleToolCancelled;
|
|
40
|
+
/**
|
|
41
|
+
* Request display mode change from host
|
|
42
|
+
* @param mode - The requested display mode
|
|
43
|
+
* @returns Promise with the new display mode (confirmed by host)
|
|
44
|
+
*/
|
|
45
|
+
setDisplayMode(mode: DisplayMode): Promise<{
|
|
46
|
+
mode: DisplayMode;
|
|
47
|
+
}>;
|
|
22
48
|
sendMessageToHost(message: ChatMessage): Promise<void>;
|
|
23
49
|
callTool<T>(toolCall: ToolCall): Promise<T>;
|
|
24
50
|
readResource<T>(request: ResourceRequest): Promise<T>;
|
|
25
51
|
accessToolInput<T>(): ToolState<T> | null;
|
|
26
52
|
accessToolOutput<T>(): ToolState<T> | null;
|
|
27
53
|
accessToolMetadata<T>(): T | null;
|
|
28
|
-
onToolCanceled(callback: () => void): void;
|
|
54
|
+
onToolCanceled(callback: (reason: string) => void): () => void;
|
|
29
55
|
subscribe(callback: () => void): () => void;
|
|
30
56
|
}
|
|
31
57
|
//# sourceMappingURL=mcpapps.d.ts.map
|
package/dist/mcpapps.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"mcpapps.d.ts","sourceRoot":"","sources":["../src/mcpapps.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,OAAO,KAAK,EACX,OAAO,EACP,WAAW,EACX,eAAe,EACf,QAAQ,EACR,SAAS,EACT,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"mcpapps.d.ts","sourceRoot":"","sources":["../src/mcpapps.ts"],"names":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dist/mcpapps.js
CHANGED
|
@@ -1,79 +1,104 @@
|
|
|
1
|
+
import { JsonRpcClient } from "@salesforce/sdk-core";
|
|
1
2
|
/**
|
|
2
3
|
* Chat SDK implementation for Webapp and MicroFrontend surfaces using MCP Apps protocol
|
|
3
4
|
* Supports: sendMessageToHost, callTool, readResource, accessToolInput, accessToolOutput,
|
|
4
|
-
* accessToolMetadata (stub), onToolCanceled
|
|
5
|
+
* accessToolMetadata (stub), onToolCanceled, subscribe
|
|
6
|
+
* Extends JsonRpcClient for JSON-RPC 2.0 notification support
|
|
5
7
|
*/
|
|
6
|
-
export class MCPAppsChatSDK {
|
|
7
|
-
|
|
8
|
-
pending = new Map();
|
|
8
|
+
export class MCPAppsChatSDK extends JsonRpcClient {
|
|
9
|
+
chatHostContext = {};
|
|
9
10
|
globals = {};
|
|
10
|
-
canceledCallbacks =
|
|
11
|
+
canceledCallbacks = new Set();
|
|
11
12
|
subscriptions = new Set();
|
|
12
13
|
constructor() {
|
|
13
|
-
//
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
14
|
+
super(); // Sets up JSON-RPC message listener
|
|
15
|
+
// Register notification handler for display mode
|
|
16
|
+
this.registerNotificationHandler("ui/notifications/host-context-changed", (params) => this.handleHostContextChanged(params));
|
|
17
|
+
// Register notification handler for tool results
|
|
18
|
+
this.registerNotificationHandler("ui/notifications/tool-result", (params) => this.handleToolResult(params));
|
|
19
|
+
// Register notification handler for tool input
|
|
20
|
+
this.registerNotificationHandler("ui/notifications/tool-input", (params) => this.handleToolInput(params));
|
|
21
|
+
// Register notification handler for tool cancelled
|
|
22
|
+
this.registerNotificationHandler("ui/notifications/tool-cancelled", (params) => this.handleToolCancelled(params));
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
25
|
+
* Handle host context change notifications from the host
|
|
26
|
+
* @param params - Partial host context update from the host
|
|
27
|
+
*/
|
|
28
|
+
handleHostContextChanged(params) {
|
|
29
|
+
const contextUpdate = params;
|
|
30
|
+
if (contextUpdate.displayMode) {
|
|
31
|
+
// Update stored host context
|
|
32
|
+
this.chatHostContext = {
|
|
33
|
+
...this.chatHostContext,
|
|
34
|
+
displayMode: contextUpdate.displayMode,
|
|
35
|
+
};
|
|
18
36
|
}
|
|
19
37
|
}
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
if (renderData.toolOutput !== undefined) {
|
|
30
|
-
this.globals.toolOutput = renderData.toolOutput;
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
// Notify subscribers of data change
|
|
34
|
-
this.notifySubscribers();
|
|
38
|
+
/**
|
|
39
|
+
* Handle tool result notifications from the host
|
|
40
|
+
* @param params - Tool result data from the host
|
|
41
|
+
*/
|
|
42
|
+
handleToolResult(params) {
|
|
43
|
+
const toolResult = params;
|
|
44
|
+
if (toolResult.content !== undefined) {
|
|
45
|
+
// Store tool output from notification
|
|
46
|
+
this.globals.toolOutput = toolResult.content;
|
|
35
47
|
}
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
slot.resolve(response.payload?.response);
|
|
48
|
-
}
|
|
49
|
-
// Notify subscribers of data change
|
|
50
|
-
this.notifySubscribers();
|
|
51
|
-
}
|
|
48
|
+
}
|
|
49
|
+
/**
|
|
50
|
+
* Handle tool input notifications from the host
|
|
51
|
+
* @param params - Tool input data from the host
|
|
52
|
+
*/
|
|
53
|
+
handleToolInput(params) {
|
|
54
|
+
const toolInput = params;
|
|
55
|
+
// Only store non-empty arguments - treat empty object as "no input"
|
|
56
|
+
if (toolInput.arguments !== undefined && Object.keys(toolInput.arguments).length > 0) {
|
|
57
|
+
// Store tool input from notification
|
|
58
|
+
this.globals.toolInput = toolInput.arguments;
|
|
52
59
|
}
|
|
53
|
-
};
|
|
54
|
-
notifySubscribers() {
|
|
55
|
-
this.subscriptions.forEach((callback) => callback());
|
|
56
60
|
}
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
61
|
+
/**
|
|
62
|
+
* Handle tool cancelled notifications from the host
|
|
63
|
+
* @param params - Tool cancellation data from the host
|
|
64
|
+
*/
|
|
65
|
+
handleToolCancelled(params) {
|
|
66
|
+
const cancellation = params;
|
|
67
|
+
const reason = cancellation.reason ?? "";
|
|
68
|
+
// Notify all registered cancellation callbacks
|
|
69
|
+
this.canceledCallbacks.forEach((callback) => callback(reason));
|
|
70
|
+
}
|
|
71
|
+
/**
|
|
72
|
+
* Request display mode change from host
|
|
73
|
+
* @param mode - The requested display mode
|
|
74
|
+
* @returns Promise with the new display mode (confirmed by host)
|
|
75
|
+
*/
|
|
76
|
+
async setDisplayMode(mode) {
|
|
77
|
+
const response = await this.request("ui/request-display-mode", {
|
|
78
|
+
displayMode: mode,
|
|
63
79
|
});
|
|
80
|
+
return response;
|
|
64
81
|
}
|
|
65
82
|
async sendMessageToHost(message) {
|
|
66
|
-
await this.request("
|
|
83
|
+
await this.request("ui/message", {
|
|
84
|
+
role: "user",
|
|
85
|
+
content: {
|
|
86
|
+
type: "text",
|
|
87
|
+
text: message.content,
|
|
88
|
+
},
|
|
89
|
+
});
|
|
67
90
|
}
|
|
68
91
|
async callTool(toolCall) {
|
|
69
|
-
const result = await this.request("
|
|
70
|
-
|
|
71
|
-
|
|
92
|
+
const result = await this.request("tools/call", {
|
|
93
|
+
name: toolCall.toolName,
|
|
94
|
+
arguments: toolCall.params ?? {},
|
|
72
95
|
});
|
|
73
96
|
return result;
|
|
74
97
|
}
|
|
75
98
|
async readResource(request) {
|
|
76
|
-
const result = await this.request("
|
|
99
|
+
const result = await this.request("resources/read", {
|
|
100
|
+
uri: request.uri,
|
|
101
|
+
});
|
|
77
102
|
return result;
|
|
78
103
|
}
|
|
79
104
|
accessToolInput() {
|
|
@@ -89,15 +114,15 @@ export class MCPAppsChatSDK {
|
|
|
89
114
|
return { data: output };
|
|
90
115
|
}
|
|
91
116
|
accessToolMetadata() {
|
|
92
|
-
//
|
|
93
|
-
|
|
94
|
-
if (!metadata)
|
|
95
|
-
return null;
|
|
96
|
-
return metadata;
|
|
117
|
+
// Stub - to be implemented later
|
|
118
|
+
return null;
|
|
97
119
|
}
|
|
98
120
|
onToolCanceled(callback) {
|
|
99
|
-
|
|
100
|
-
|
|
121
|
+
this.canceledCallbacks.add(callback);
|
|
122
|
+
// Return unsubscribe function
|
|
123
|
+
return () => {
|
|
124
|
+
this.canceledCallbacks.delete(callback);
|
|
125
|
+
};
|
|
101
126
|
}
|
|
102
127
|
subscribe(callback) {
|
|
103
128
|
// Add callback to subscriptions set
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@salesforce/sdk-chat",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.52.0",
|
|
4
4
|
"license": "SEE LICENSE IN LICENSE.txt",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -26,7 +26,7 @@
|
|
|
26
26
|
"test:coverage": "vitest run --coverage"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@salesforce/sdk-core": "^1.
|
|
29
|
+
"@salesforce/sdk-core": "^1.52.0"
|
|
30
30
|
},
|
|
31
31
|
"devDependencies": {
|
|
32
32
|
"vitest": "^4.0.6"
|
|
@@ -34,5 +34,5 @@
|
|
|
34
34
|
"publishConfig": {
|
|
35
35
|
"access": "public"
|
|
36
36
|
},
|
|
37
|
-
"gitHead": "
|
|
37
|
+
"gitHead": "ca188815c4810100fe2029d791105091cd78067f"
|
|
38
38
|
}
|