@salesforce/sdk-chat 1.65.0 → 1.66.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
@@ -17,5 +17,5 @@ export interface ChatSDKOptions extends SDKOptions {
17
17
  */
18
18
  export declare function createChatSDK(options?: ChatSDKOptions): Promise<ChatSDK>;
19
19
  export { MCPAppsChatSDK } from "./mcpapps.js";
20
- export type { ChatMessage, ChatSDK, DisplayMode, ResourceRequest, SDKOptions, ToolCall, ToolState, } from "@salesforce/sdk-core";
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,OAAO,EACP,WAAW,EACX,eAAe,EACf,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,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"}
package/dist/mcpapps.d.ts CHANGED
@@ -3,7 +3,7 @@
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, DisplayMode } from "@salesforce/sdk-core";
6
+ import type { ChatSDK, HostContext, ChatMessage, ResourceRequest, ToolCall, ToolState, DisplayMode } from "@salesforce/sdk-core";
7
7
  import type { McpAppsSession } from "@salesforce/sdk-core";
8
8
  /**
9
9
  * Chat SDK implementation for MCP Apps surface using the shared McpAppsSession.
@@ -17,16 +17,10 @@ import type { McpAppsSession } from "@salesforce/sdk-core";
17
17
  */
18
18
  export declare class MCPAppsChatSDK implements ChatSDK {
19
19
  private session;
20
- private chatHostContext;
21
20
  private globals;
22
21
  private canceledCallbacks;
23
22
  private subscriptions;
24
23
  constructor(session: McpAppsSession);
25
- /**
26
- * Handle host context change notifications from the host
27
- * @param params - Partial host context update from the host
28
- */
29
- private handleHostContextChanged;
30
24
  /**
31
25
  * Handle tool result notifications from the host
32
26
  * @param params - Tool result data from the host
@@ -56,6 +50,13 @@ export declare class MCPAppsChatSDK implements ChatSDK {
56
50
  accessToolInput<T>(): ToolState<T> | null;
57
51
  accessToolOutput<T>(): ToolState<T> | null;
58
52
  accessToolMetadata<T>(): T | null;
53
+ /**
54
+ * Get the current host context.
55
+ *
56
+ * Maps MCP Apps wire-format fields to the protocol-agnostic HostContext.
57
+ * Always returns an object (empty `{}` when no context has been received).
58
+ */
59
+ getHostContext(): HostContext;
59
60
  onToolCanceled(callback: (reason: string) => void): () => void;
60
61
  subscribe(callback: () => void): () => void;
61
62
  private notifySubscribers;
@@ -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,WAAW,EACX,MAAM,sBAAsB,CAAC;AAC9B,OAAO,KAAK,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAC;AAa3D;;;;;;;;;GASG;AACH,qBAAa,cAAe,YAAW,OAAO;IASjC,OAAO,CAAC,OAAO;IAR3B,OAAO,CAAC,eAAe,CAAuB;IAC9C,OAAO,CAAC,OAAO,CAGR;IACP,OAAO,CAAC,iBAAiB,CAAuC;IAChE,OAAO,CAAC,aAAa,CAAyB;gBAE1B,OAAO,EAAE,cAAc;IAmB3C;;;OAGG;IACH,OAAO,CAAC,wBAAwB;IAehC;;;OAGG;IACH,OAAO,CAAC,gBAAgB;IASxB;;;OAGG;IACH,OAAO,CAAC,eAAe;IAUvB;;;OAGG;IACH,OAAO,CAAC,mBAAmB;IAO3B;;;;OAIG;IACG,cAAc,CAAC,IAAI,EAAE,WAAW,GAAG,OAAO,CAAC;QAAE,IAAI,EAAE,WAAW,CAAA;KAAE,CAAC;IAOjE,iBAAiB,CAAC,OAAO,EAAE,WAAW,GAAG,OAAO,CAAC,IAAI,CAAC;IAYtD,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;IAO3D,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GA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CAAC,CAAC,CAAC;IAO3D,eAAe,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAMzC,gBAAgB,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,GAAG,IAAI;IAM1C,kBAAkB,CAAC,CAAC,KAAK,CAAC,GAAG,IAAI;IAMjC;;;;;OAKG;IACH,cAAc,IAAI,WAAW;IAgC7B,cAAc,CAAC,QAAQ,EAAE,CAAC,MAAM,EAAE,MAAM,KAAK,IAAI,GAAG,MAAM,IAAI;IAS9D,SAAS,CAAC,QAAQ,EAAE,MAAM,IAAI,GAAG,MAAM,IAAI;IAQ3C,OAAO,CAAC,iBAAiB;CAGzB"}
package/dist/mcpapps.js CHANGED
@@ -10,32 +10,19 @@
10
10
  */
11
11
  export class MCPAppsChatSDK {
12
12
  session;
13
- chatHostContext = {};
14
13
  globals = {};
15
14
  canceledCallbacks = new Set();
16
15
  subscriptions = new Set();
17
16
  constructor(session) {
18
17
  this.session = session;
19
18
  // Register notification handlers on the shared session
20
- session.registerNotificationHandler("ui/notifications/host-context-changed", (params) => this.handleHostContextChanged(params));
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());
21
22
  session.registerNotificationHandler("ui/notifications/tool-result", (params) => this.handleToolResult(params));
22
23
  session.registerNotificationHandler("ui/notifications/tool-input", (params) => this.handleToolInput(params));
23
24
  session.registerNotificationHandler("ui/notifications/tool-cancelled", (params) => this.handleToolCancelled(params));
24
25
  }
25
- /**
26
- * Handle host context change notifications from the host
27
- * @param params - Partial host context update from the host
28
- */
29
- handleHostContextChanged(params) {
30
- const contextUpdate = params;
31
- if (contextUpdate.displayMode) {
32
- this.chatHostContext = {
33
- ...this.chatHostContext,
34
- displayMode: contextUpdate.displayMode,
35
- };
36
- }
37
- this.notifySubscribers();
38
- }
39
26
  /**
40
27
  * Handle tool result notifications from the host
41
28
  * @param params - Tool result data from the host
@@ -121,6 +108,41 @@ export class MCPAppsChatSDK {
121
108
  return null;
122
109
  return toolInfo;
123
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 mcp = this.session.getHostContext();
119
+ const result = {};
120
+ if (mcp.theme !== undefined) {
121
+ result.theme = mcp.theme;
122
+ }
123
+ if (mcp.displayMode !== undefined) {
124
+ result.displayMode = mcp.displayMode;
125
+ }
126
+ if (mcp.containerDimensions !== undefined) {
127
+ const h = mcp.containerDimensions.maxHeight ?? mcp.containerDimensions.height;
128
+ if (h !== undefined) {
129
+ result.maxHeight = h;
130
+ }
131
+ }
132
+ if (mcp.safeAreaInsets !== undefined) {
133
+ result.safeArea = mcp.safeAreaInsets;
134
+ }
135
+ if (mcp.userAgent !== undefined) {
136
+ result.userAgent = mcp.userAgent;
137
+ }
138
+ if (mcp.locale !== undefined) {
139
+ result.locale = mcp.locale;
140
+ }
141
+ if (mcp.deviceCapabilities !== undefined) {
142
+ result.deviceCapabilities = mcp.deviceCapabilities;
143
+ }
144
+ return result;
145
+ }
124
146
  onToolCanceled(callback) {
125
147
  this.canceledCallbacks.add(callback);
126
148
  // Return unsubscribe function
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salesforce/sdk-chat",
3
- "version": "1.65.0",
3
+ "version": "1.66.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.65.0"
29
+ "@salesforce/sdk-core": "^1.66.0"
30
30
  },
31
31
  "devDependencies": {
32
32
  "vitest": "^4.0.6"