@pancake-apps/web 0.0.0-snapshot-20260125200133
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/README.md +333 -0
- package/dist/adaptor-interface-BYbH9PpT.d.ts +370 -0
- package/dist/apps-sdk/index.d.ts +1 -0
- package/dist/apps-sdk/index.js +4 -0
- package/dist/apps-sdk/index.js.map +1 -0
- package/dist/chunk-5NYJ2IVD.js +406 -0
- package/dist/chunk-5NYJ2IVD.js.map +1 -0
- package/dist/chunk-7HJ5PKKT.js +146 -0
- package/dist/chunk-7HJ5PKKT.js.map +1 -0
- package/dist/chunk-PZ5AY32C.js +9 -0
- package/dist/chunk-PZ5AY32C.js.map +1 -0
- package/dist/chunk-TLBYYZHP.js +715 -0
- package/dist/chunk-TLBYYZHP.js.map +1 -0
- package/dist/chunk-YGGRUIUG.js +977 -0
- package/dist/chunk-YGGRUIUG.js.map +1 -0
- package/dist/chunk-ZYBPDIEG.js +674 -0
- package/dist/chunk-ZYBPDIEG.js.map +1 -0
- package/dist/core/index.d.ts +169 -0
- package/dist/core/index.js +195 -0
- package/dist/core/index.js.map +1 -0
- package/dist/index-BBfZZJWn.d.ts +671 -0
- package/dist/index-CpXDfXKD.d.ts +395 -0
- package/dist/index-DtukOUjY.d.ts +738 -0
- package/dist/index.d.ts +741 -0
- package/dist/index.js +685 -0
- package/dist/index.js.map +1 -0
- package/dist/mcp-apps/index.d.ts +2 -0
- package/dist/mcp-apps/index.js +4 -0
- package/dist/mcp-apps/index.js.map +1 -0
- package/dist/notify-size-changed-Ck2BGfUk.d.ts +270 -0
- package/dist/react/index.d.ts +3 -0
- package/dist/react/index.js +7 -0
- package/dist/react/index.js.map +1 -0
- package/dist/types-B_O3kZYh.d.ts +253 -0
- package/package.json +90 -0
|
@@ -0,0 +1,977 @@
|
|
|
1
|
+
import { __export } from './chunk-PZ5AY32C.js';
|
|
2
|
+
import { useSyncExternalStore } from 'react';
|
|
3
|
+
|
|
4
|
+
// src/mcp-apps/index.ts
|
|
5
|
+
var mcp_apps_exports = {};
|
|
6
|
+
__export(mcp_apps_exports, {
|
|
7
|
+
DEFAULT_CLIENT_INFO: () => DEFAULT_CLIENT_INFO,
|
|
8
|
+
ERROR_CODES: () => ERROR_CODES,
|
|
9
|
+
JsonRpcError: () => JsonRpcError,
|
|
10
|
+
MCP_METHODS: () => MCP_METHODS,
|
|
11
|
+
McpAppsBridge: () => McpAppsBridge,
|
|
12
|
+
McpAppsStore: () => McpAppsStore,
|
|
13
|
+
PROTOCOL_VERSION: () => PROTOCOL_VERSION,
|
|
14
|
+
callTool: () => callTool,
|
|
15
|
+
createErrorResponse: () => createErrorResponse,
|
|
16
|
+
createMcpStoreHook: () => createMcpStoreHook,
|
|
17
|
+
createMcpView: () => createMcpView,
|
|
18
|
+
createNotification: () => createNotification,
|
|
19
|
+
createRequest: () => createRequest,
|
|
20
|
+
createSuccessResponse: () => createSuccessResponse,
|
|
21
|
+
generateId: () => generateId,
|
|
22
|
+
getBridge: () => getBridge,
|
|
23
|
+
getStore: () => getStore,
|
|
24
|
+
initialize: () => initialize,
|
|
25
|
+
isErrorResponse: () => isErrorResponse,
|
|
26
|
+
isJsonRpcMessage: () => isJsonRpcMessage,
|
|
27
|
+
isNotification: () => isNotification,
|
|
28
|
+
isRequest: () => isRequest,
|
|
29
|
+
isResponse: () => isResponse,
|
|
30
|
+
log: () => log,
|
|
31
|
+
logDebug: () => logDebug,
|
|
32
|
+
logError: () => logError,
|
|
33
|
+
logInfo: () => logInfo,
|
|
34
|
+
logWarning: () => logWarning,
|
|
35
|
+
notifySizeChanged: () => notifySizeChanged,
|
|
36
|
+
onTeardown: () => onTeardown,
|
|
37
|
+
openLink: () => openLink,
|
|
38
|
+
readResource: () => readResource,
|
|
39
|
+
requestDisplayMode: () => requestDisplayMode,
|
|
40
|
+
sendMessage: () => sendMessage,
|
|
41
|
+
setupAutoSizeReporting: () => setupAutoSizeReporting,
|
|
42
|
+
updateModelContext: () => updateModelContext,
|
|
43
|
+
useAvailableDisplayModes: () => useAvailableDisplayModes,
|
|
44
|
+
useContainerDimensions: () => useContainerDimensions,
|
|
45
|
+
useDeviceCapabilities: () => useDeviceCapabilities,
|
|
46
|
+
useDisplayMode: () => useDisplayMode,
|
|
47
|
+
useHostCapabilities: () => useHostCapabilities,
|
|
48
|
+
useHostContext: () => useHostContext,
|
|
49
|
+
useIsInitialized: () => useIsInitialized,
|
|
50
|
+
useLocale: () => useLocale,
|
|
51
|
+
useMcpStore: () => useMcpStore,
|
|
52
|
+
usePlatform: () => usePlatform,
|
|
53
|
+
useSafeArea: () => useSafeArea,
|
|
54
|
+
useStyles: () => useStyles,
|
|
55
|
+
useTheme: () => useTheme,
|
|
56
|
+
useTimezone: () => useTimezone,
|
|
57
|
+
useToolInfo: () => useToolInfo,
|
|
58
|
+
useToolInput: () => useToolInput,
|
|
59
|
+
useToolResult: () => useToolResult
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
// src/mcp-apps/types.ts
|
|
63
|
+
var PROTOCOL_VERSION = "2025-11-21";
|
|
64
|
+
var DEFAULT_CLIENT_INFO = {
|
|
65
|
+
name: "pancake-mcp-apps",
|
|
66
|
+
version: "1.0.0"
|
|
67
|
+
};
|
|
68
|
+
var MCP_METHODS = {
|
|
69
|
+
// Guest -> Host Requests
|
|
70
|
+
INITIALIZE: "ui/initialize",
|
|
71
|
+
OPEN_LINK: "ui/open-link",
|
|
72
|
+
MESSAGE: "ui/message",
|
|
73
|
+
REQUEST_DISPLAY_MODE: "ui/request-display-mode",
|
|
74
|
+
UPDATE_MODEL_CONTEXT: "ui/update-model-context",
|
|
75
|
+
TOOLS_CALL: "tools/call",
|
|
76
|
+
RESOURCES_READ: "resources/read",
|
|
77
|
+
PING: "ping",
|
|
78
|
+
// Guest -> Host Notifications
|
|
79
|
+
INITIALIZED: "ui/notifications/initialized",
|
|
80
|
+
SIZE_CHANGED: "ui/notifications/size-changed",
|
|
81
|
+
LOG_MESSAGE: "notifications/message",
|
|
82
|
+
// Host -> Guest Notifications
|
|
83
|
+
TOOL_INPUT: "ui/notifications/tool-input",
|
|
84
|
+
TOOL_INPUT_PARTIAL: "ui/notifications/tool-input-partial",
|
|
85
|
+
TOOL_RESULT: "ui/notifications/tool-result",
|
|
86
|
+
TOOL_CANCELLED: "ui/notifications/tool-cancelled",
|
|
87
|
+
HOST_CONTEXT_CHANGED: "ui/notifications/host-context-changed",
|
|
88
|
+
RESOURCE_TEARDOWN: "ui/resource-teardown"
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
// src/mcp-apps/protocol.ts
|
|
92
|
+
function generateId() {
|
|
93
|
+
return crypto.randomUUID();
|
|
94
|
+
}
|
|
95
|
+
function createRequest(method, params, id = generateId()) {
|
|
96
|
+
const request = {
|
|
97
|
+
jsonrpc: "2.0",
|
|
98
|
+
id,
|
|
99
|
+
method
|
|
100
|
+
};
|
|
101
|
+
if (params !== void 0) {
|
|
102
|
+
request.params = params;
|
|
103
|
+
}
|
|
104
|
+
return request;
|
|
105
|
+
}
|
|
106
|
+
function createNotification(method, params) {
|
|
107
|
+
const notification = {
|
|
108
|
+
jsonrpc: "2.0",
|
|
109
|
+
method
|
|
110
|
+
};
|
|
111
|
+
if (params !== void 0) {
|
|
112
|
+
notification.params = params;
|
|
113
|
+
}
|
|
114
|
+
return notification;
|
|
115
|
+
}
|
|
116
|
+
function createSuccessResponse(id, result) {
|
|
117
|
+
return {
|
|
118
|
+
jsonrpc: "2.0",
|
|
119
|
+
id,
|
|
120
|
+
result
|
|
121
|
+
};
|
|
122
|
+
}
|
|
123
|
+
function createErrorResponse(id, code, message, data) {
|
|
124
|
+
return {
|
|
125
|
+
jsonrpc: "2.0",
|
|
126
|
+
id,
|
|
127
|
+
error: {
|
|
128
|
+
code,
|
|
129
|
+
message,
|
|
130
|
+
...data !== void 0 && { data }
|
|
131
|
+
}
|
|
132
|
+
};
|
|
133
|
+
}
|
|
134
|
+
function isJsonRpcMessage(data) {
|
|
135
|
+
if (typeof data !== "object" || data === null) return false;
|
|
136
|
+
return data.jsonrpc === "2.0";
|
|
137
|
+
}
|
|
138
|
+
function isRequest(message) {
|
|
139
|
+
return "id" in message && "method" in message && !("result" in message) && !("error" in message);
|
|
140
|
+
}
|
|
141
|
+
function isNotification(message) {
|
|
142
|
+
return "method" in message && !("id" in message);
|
|
143
|
+
}
|
|
144
|
+
function isResponse(message) {
|
|
145
|
+
return "id" in message && ("result" in message || "error" in message);
|
|
146
|
+
}
|
|
147
|
+
function isErrorResponse(response) {
|
|
148
|
+
return "error" in response;
|
|
149
|
+
}
|
|
150
|
+
var ERROR_CODES = {
|
|
151
|
+
PARSE_ERROR: -32700,
|
|
152
|
+
INVALID_REQUEST: -32600,
|
|
153
|
+
METHOD_NOT_FOUND: -32601,
|
|
154
|
+
INVALID_PARAMS: -32602,
|
|
155
|
+
INTERNAL_ERROR: -32603
|
|
156
|
+
};
|
|
157
|
+
var JsonRpcError = class _JsonRpcError extends Error {
|
|
158
|
+
code;
|
|
159
|
+
data;
|
|
160
|
+
constructor(code, message, data) {
|
|
161
|
+
super(message);
|
|
162
|
+
this.name = "JsonRpcError";
|
|
163
|
+
this.code = code;
|
|
164
|
+
this.data = data;
|
|
165
|
+
}
|
|
166
|
+
static fromResponse(response) {
|
|
167
|
+
return new _JsonRpcError(response.error.code, response.error.message, response.error.data);
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
|
|
171
|
+
// src/mcp-apps/bridge.ts
|
|
172
|
+
var DEFAULT_TIMEOUT = 3e4;
|
|
173
|
+
var McpAppsBridge = class _McpAppsBridge {
|
|
174
|
+
static instance = null;
|
|
175
|
+
pendingRequests = /* @__PURE__ */ new Map();
|
|
176
|
+
notificationHandlers = /* @__PURE__ */ new Map();
|
|
177
|
+
teardownHandlers = /* @__PURE__ */ new Set();
|
|
178
|
+
_isInitialized = false;
|
|
179
|
+
initializeResult = null;
|
|
180
|
+
resizeObserver = null;
|
|
181
|
+
/**
|
|
182
|
+
* Get the singleton bridge instance
|
|
183
|
+
*/
|
|
184
|
+
static getInstance() {
|
|
185
|
+
if (!_McpAppsBridge.instance) {
|
|
186
|
+
_McpAppsBridge.instance = new _McpAppsBridge();
|
|
187
|
+
}
|
|
188
|
+
return _McpAppsBridge.instance;
|
|
189
|
+
}
|
|
190
|
+
/**
|
|
191
|
+
* Reset the singleton (for testing)
|
|
192
|
+
*/
|
|
193
|
+
static reset() {
|
|
194
|
+
if (_McpAppsBridge.instance) {
|
|
195
|
+
_McpAppsBridge.instance.cleanup();
|
|
196
|
+
}
|
|
197
|
+
_McpAppsBridge.instance = null;
|
|
198
|
+
}
|
|
199
|
+
constructor() {
|
|
200
|
+
this.setupMessageListener();
|
|
201
|
+
}
|
|
202
|
+
/**
|
|
203
|
+
* Check if the bridge has been initialized
|
|
204
|
+
*/
|
|
205
|
+
get isInitialized() {
|
|
206
|
+
return this._isInitialized;
|
|
207
|
+
}
|
|
208
|
+
/**
|
|
209
|
+
* Get the initialization result (host context, capabilities, etc.)
|
|
210
|
+
*/
|
|
211
|
+
get initResult() {
|
|
212
|
+
return this.initializeResult;
|
|
213
|
+
}
|
|
214
|
+
// ============================================
|
|
215
|
+
// Message Handling
|
|
216
|
+
// ============================================
|
|
217
|
+
setupMessageListener() {
|
|
218
|
+
if (typeof window !== "undefined") {
|
|
219
|
+
window.addEventListener("message", this.handleMessage);
|
|
220
|
+
}
|
|
221
|
+
}
|
|
222
|
+
cleanup() {
|
|
223
|
+
if (typeof window !== "undefined") {
|
|
224
|
+
window.removeEventListener("message", this.handleMessage);
|
|
225
|
+
}
|
|
226
|
+
for (const [, pending] of this.pendingRequests) {
|
|
227
|
+
clearTimeout(pending.timeout);
|
|
228
|
+
pending.reject(new Error("Bridge was reset"));
|
|
229
|
+
}
|
|
230
|
+
this.pendingRequests.clear();
|
|
231
|
+
this.notificationHandlers.clear();
|
|
232
|
+
this.teardownHandlers.clear();
|
|
233
|
+
if (this.resizeObserver) {
|
|
234
|
+
this.resizeObserver.disconnect();
|
|
235
|
+
this.resizeObserver = null;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
handleMessage = (event) => {
|
|
239
|
+
const data = event.data;
|
|
240
|
+
if (!isJsonRpcMessage(data)) {
|
|
241
|
+
return;
|
|
242
|
+
}
|
|
243
|
+
if (isResponse(data)) {
|
|
244
|
+
const id = String(data.id);
|
|
245
|
+
const pending = this.pendingRequests.get(id);
|
|
246
|
+
if (pending) {
|
|
247
|
+
clearTimeout(pending.timeout);
|
|
248
|
+
this.pendingRequests.delete(id);
|
|
249
|
+
if (isErrorResponse(data)) {
|
|
250
|
+
pending.reject(JsonRpcError.fromResponse(data));
|
|
251
|
+
} else {
|
|
252
|
+
pending.resolve(data.result);
|
|
253
|
+
}
|
|
254
|
+
}
|
|
255
|
+
return;
|
|
256
|
+
}
|
|
257
|
+
if (isRequest(data)) {
|
|
258
|
+
this.handleHostRequest(data);
|
|
259
|
+
return;
|
|
260
|
+
}
|
|
261
|
+
if (isNotification(data)) {
|
|
262
|
+
this.handleNotification(data.method, data.params);
|
|
263
|
+
}
|
|
264
|
+
};
|
|
265
|
+
handleHostRequest(request) {
|
|
266
|
+
if (request.method === MCP_METHODS.RESOURCE_TEARDOWN) {
|
|
267
|
+
this.handleTeardown(request);
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
async handleTeardown(request) {
|
|
271
|
+
const params = request.params;
|
|
272
|
+
try {
|
|
273
|
+
await Promise.all(Array.from(this.teardownHandlers).map((handler) => handler(params)));
|
|
274
|
+
this.sendResponse(request.id, {});
|
|
275
|
+
} catch (error) {
|
|
276
|
+
this.sendErrorResponse(
|
|
277
|
+
request.id,
|
|
278
|
+
-32603,
|
|
279
|
+
error instanceof Error ? error.message : "Teardown failed"
|
|
280
|
+
);
|
|
281
|
+
}
|
|
282
|
+
}
|
|
283
|
+
handleNotification(method, params) {
|
|
284
|
+
const handlers = this.notificationHandlers.get(method);
|
|
285
|
+
if (handlers) {
|
|
286
|
+
handlers.forEach((handler) => handler(params));
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
// ============================================
|
|
290
|
+
// Sending Messages
|
|
291
|
+
// ============================================
|
|
292
|
+
send(message) {
|
|
293
|
+
if (typeof window !== "undefined") {
|
|
294
|
+
window.parent.postMessage(message, "*");
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
sendResponse(id, result) {
|
|
298
|
+
this.send({
|
|
299
|
+
jsonrpc: "2.0",
|
|
300
|
+
id,
|
|
301
|
+
result
|
|
302
|
+
});
|
|
303
|
+
}
|
|
304
|
+
sendErrorResponse(id, code, message) {
|
|
305
|
+
this.send({
|
|
306
|
+
jsonrpc: "2.0",
|
|
307
|
+
id,
|
|
308
|
+
error: { code, message }
|
|
309
|
+
});
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Send a request and wait for response
|
|
313
|
+
*/
|
|
314
|
+
async sendRequest(method, params, timeout = DEFAULT_TIMEOUT) {
|
|
315
|
+
const request = createRequest(method, params);
|
|
316
|
+
const id = String(request.id);
|
|
317
|
+
return new Promise((resolve, reject) => {
|
|
318
|
+
const timeoutId = setTimeout(() => {
|
|
319
|
+
this.pendingRequests.delete(id);
|
|
320
|
+
reject(new Error(`Request ${method} timed out after ${timeout}ms`));
|
|
321
|
+
}, timeout);
|
|
322
|
+
this.pendingRequests.set(id, {
|
|
323
|
+
resolve,
|
|
324
|
+
reject,
|
|
325
|
+
timeout: timeoutId
|
|
326
|
+
});
|
|
327
|
+
this.send(request);
|
|
328
|
+
});
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Send a notification (no response expected)
|
|
332
|
+
*/
|
|
333
|
+
sendNotification(method, params) {
|
|
334
|
+
this.send(createNotification(method, params));
|
|
335
|
+
}
|
|
336
|
+
// ============================================
|
|
337
|
+
// Subscription
|
|
338
|
+
// ============================================
|
|
339
|
+
/**
|
|
340
|
+
* Subscribe to notifications from the host
|
|
341
|
+
*/
|
|
342
|
+
onNotification(method, handler) {
|
|
343
|
+
if (!this.notificationHandlers.has(method)) {
|
|
344
|
+
this.notificationHandlers.set(method, /* @__PURE__ */ new Set());
|
|
345
|
+
}
|
|
346
|
+
this.notificationHandlers.get(method).add(handler);
|
|
347
|
+
return () => {
|
|
348
|
+
this.notificationHandlers.get(method)?.delete(handler);
|
|
349
|
+
};
|
|
350
|
+
}
|
|
351
|
+
/**
|
|
352
|
+
* Register a teardown handler
|
|
353
|
+
*/
|
|
354
|
+
onTeardown(handler) {
|
|
355
|
+
this.teardownHandlers.add(handler);
|
|
356
|
+
return () => {
|
|
357
|
+
this.teardownHandlers.delete(handler);
|
|
358
|
+
};
|
|
359
|
+
}
|
|
360
|
+
// ============================================
|
|
361
|
+
// Initialization
|
|
362
|
+
// ============================================
|
|
363
|
+
/**
|
|
364
|
+
* Initialize the connection with the host
|
|
365
|
+
*/
|
|
366
|
+
async initialize(options = {}) {
|
|
367
|
+
if (this._isInitialized && this.initializeResult) {
|
|
368
|
+
return this.initializeResult;
|
|
369
|
+
}
|
|
370
|
+
const result = await this.sendRequest(MCP_METHODS.INITIALIZE, {
|
|
371
|
+
protocolVersion: PROTOCOL_VERSION,
|
|
372
|
+
capabilities: options.capabilities ?? {},
|
|
373
|
+
clientInfo: options.clientInfo ?? DEFAULT_CLIENT_INFO
|
|
374
|
+
});
|
|
375
|
+
this.initializeResult = result;
|
|
376
|
+
this._isInitialized = true;
|
|
377
|
+
this.sendNotification(MCP_METHODS.INITIALIZED);
|
|
378
|
+
return result;
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Ensure the bridge is initialized before performing operations
|
|
382
|
+
*/
|
|
383
|
+
async ensureInitialized() {
|
|
384
|
+
if (!this._isInitialized) {
|
|
385
|
+
await this.initialize();
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
// ============================================
|
|
389
|
+
// Tool Operations
|
|
390
|
+
// ============================================
|
|
391
|
+
/**
|
|
392
|
+
* Call a server tool
|
|
393
|
+
*/
|
|
394
|
+
async callTool(name, args) {
|
|
395
|
+
await this.ensureInitialized();
|
|
396
|
+
return this.sendRequest(MCP_METHODS.TOOLS_CALL, {
|
|
397
|
+
name,
|
|
398
|
+
arguments: args
|
|
399
|
+
});
|
|
400
|
+
}
|
|
401
|
+
// ============================================
|
|
402
|
+
// Resource Operations
|
|
403
|
+
// ============================================
|
|
404
|
+
/**
|
|
405
|
+
* Read a resource by URI
|
|
406
|
+
*/
|
|
407
|
+
async readResource(uri) {
|
|
408
|
+
await this.ensureInitialized();
|
|
409
|
+
return this.sendRequest(MCP_METHODS.RESOURCES_READ, {
|
|
410
|
+
uri
|
|
411
|
+
});
|
|
412
|
+
}
|
|
413
|
+
// ============================================
|
|
414
|
+
// Message Operations
|
|
415
|
+
// ============================================
|
|
416
|
+
/**
|
|
417
|
+
* Send a message to the host's chat interface
|
|
418
|
+
*/
|
|
419
|
+
async sendMessage(text) {
|
|
420
|
+
await this.ensureInitialized();
|
|
421
|
+
await this.sendRequest(MCP_METHODS.MESSAGE, {
|
|
422
|
+
role: "user",
|
|
423
|
+
content: {
|
|
424
|
+
type: "text",
|
|
425
|
+
text
|
|
426
|
+
}
|
|
427
|
+
});
|
|
428
|
+
}
|
|
429
|
+
// ============================================
|
|
430
|
+
// Link Operations
|
|
431
|
+
// ============================================
|
|
432
|
+
/**
|
|
433
|
+
* Request the host to open a URL
|
|
434
|
+
*/
|
|
435
|
+
async openLink(url) {
|
|
436
|
+
await this.ensureInitialized();
|
|
437
|
+
await this.sendRequest(MCP_METHODS.OPEN_LINK, { url });
|
|
438
|
+
}
|
|
439
|
+
// ============================================
|
|
440
|
+
// Display Operations
|
|
441
|
+
// ============================================
|
|
442
|
+
/**
|
|
443
|
+
* Request a change in display mode
|
|
444
|
+
*/
|
|
445
|
+
async requestDisplayMode(mode) {
|
|
446
|
+
await this.ensureInitialized();
|
|
447
|
+
const result = await this.sendRequest(MCP_METHODS.REQUEST_DISPLAY_MODE, {
|
|
448
|
+
mode
|
|
449
|
+
});
|
|
450
|
+
return result.mode;
|
|
451
|
+
}
|
|
452
|
+
// ============================================
|
|
453
|
+
// Model Context Operations
|
|
454
|
+
// ============================================
|
|
455
|
+
/**
|
|
456
|
+
* Update the host's model context
|
|
457
|
+
*/
|
|
458
|
+
async updateModelContext(params) {
|
|
459
|
+
await this.ensureInitialized();
|
|
460
|
+
await this.sendRequest(MCP_METHODS.UPDATE_MODEL_CONTEXT, params);
|
|
461
|
+
}
|
|
462
|
+
// ============================================
|
|
463
|
+
// Size Reporting
|
|
464
|
+
// ============================================
|
|
465
|
+
/**
|
|
466
|
+
* Notify the host of size changes
|
|
467
|
+
*/
|
|
468
|
+
notifySizeChanged(width, height) {
|
|
469
|
+
this.sendNotification(MCP_METHODS.SIZE_CHANGED, { width, height });
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Setup automatic size reporting via ResizeObserver
|
|
473
|
+
*/
|
|
474
|
+
setupAutoSizeReporting(element = document.documentElement) {
|
|
475
|
+
if (this.resizeObserver) {
|
|
476
|
+
this.resizeObserver.disconnect();
|
|
477
|
+
}
|
|
478
|
+
this.resizeObserver = new ResizeObserver((entries) => {
|
|
479
|
+
const entry = entries[0];
|
|
480
|
+
if (!entry) return;
|
|
481
|
+
this.notifySizeChanged(entry.contentRect.width, entry.contentRect.height);
|
|
482
|
+
});
|
|
483
|
+
this.resizeObserver.observe(element);
|
|
484
|
+
return () => {
|
|
485
|
+
if (this.resizeObserver) {
|
|
486
|
+
this.resizeObserver.disconnect();
|
|
487
|
+
this.resizeObserver = null;
|
|
488
|
+
}
|
|
489
|
+
};
|
|
490
|
+
}
|
|
491
|
+
// ============================================
|
|
492
|
+
// Logging
|
|
493
|
+
// ============================================
|
|
494
|
+
/**
|
|
495
|
+
* Send a log message to the host
|
|
496
|
+
*/
|
|
497
|
+
log(level, data, logger) {
|
|
498
|
+
this.sendNotification(MCP_METHODS.LOG_MESSAGE, {
|
|
499
|
+
level,
|
|
500
|
+
data,
|
|
501
|
+
...logger && { logger }
|
|
502
|
+
});
|
|
503
|
+
}
|
|
504
|
+
// ============================================
|
|
505
|
+
// Health Check
|
|
506
|
+
// ============================================
|
|
507
|
+
/**
|
|
508
|
+
* Ping the host to check connection
|
|
509
|
+
*/
|
|
510
|
+
async ping() {
|
|
511
|
+
await this.sendRequest(MCP_METHODS.PING);
|
|
512
|
+
}
|
|
513
|
+
};
|
|
514
|
+
function getBridge() {
|
|
515
|
+
return McpAppsBridge.getInstance();
|
|
516
|
+
}
|
|
517
|
+
|
|
518
|
+
// src/mcp-apps/store.ts
|
|
519
|
+
var McpAppsStore = class _McpAppsStore {
|
|
520
|
+
static instance = null;
|
|
521
|
+
state = {
|
|
522
|
+
isInitialized: false,
|
|
523
|
+
hostContext: {},
|
|
524
|
+
hostCapabilities: void 0,
|
|
525
|
+
hostInfo: void 0,
|
|
526
|
+
toolInput: void 0,
|
|
527
|
+
toolResult: void 0,
|
|
528
|
+
toolInputPartial: void 0,
|
|
529
|
+
isCancelled: false,
|
|
530
|
+
cancelReason: void 0
|
|
531
|
+
};
|
|
532
|
+
subscribers = /* @__PURE__ */ new Map();
|
|
533
|
+
unsubscribers = [];
|
|
534
|
+
static getInstance() {
|
|
535
|
+
if (!_McpAppsStore.instance) {
|
|
536
|
+
_McpAppsStore.instance = new _McpAppsStore();
|
|
537
|
+
}
|
|
538
|
+
return _McpAppsStore.instance;
|
|
539
|
+
}
|
|
540
|
+
static reset() {
|
|
541
|
+
if (_McpAppsStore.instance) {
|
|
542
|
+
_McpAppsStore.instance.cleanup();
|
|
543
|
+
}
|
|
544
|
+
_McpAppsStore.instance = null;
|
|
545
|
+
}
|
|
546
|
+
constructor() {
|
|
547
|
+
this.setupNotificationHandlers();
|
|
548
|
+
}
|
|
549
|
+
cleanup() {
|
|
550
|
+
this.unsubscribers.forEach((unsub) => unsub());
|
|
551
|
+
this.unsubscribers = [];
|
|
552
|
+
this.subscribers.clear();
|
|
553
|
+
this.state = {
|
|
554
|
+
isInitialized: false,
|
|
555
|
+
hostContext: {},
|
|
556
|
+
hostCapabilities: void 0,
|
|
557
|
+
hostInfo: void 0,
|
|
558
|
+
toolInput: void 0,
|
|
559
|
+
toolResult: void 0,
|
|
560
|
+
toolInputPartial: void 0,
|
|
561
|
+
isCancelled: false,
|
|
562
|
+
cancelReason: void 0
|
|
563
|
+
};
|
|
564
|
+
}
|
|
565
|
+
setupNotificationHandlers() {
|
|
566
|
+
const bridge = getBridge();
|
|
567
|
+
this.unsubscribers.push(
|
|
568
|
+
bridge.onNotification(MCP_METHODS.TOOL_INPUT, (params) => {
|
|
569
|
+
const { arguments: args } = params;
|
|
570
|
+
this.updateState({ toolInput: args, toolInputPartial: void 0 });
|
|
571
|
+
})
|
|
572
|
+
);
|
|
573
|
+
this.unsubscribers.push(
|
|
574
|
+
bridge.onNotification(MCP_METHODS.TOOL_INPUT_PARTIAL, (params) => {
|
|
575
|
+
const { arguments: args } = params;
|
|
576
|
+
this.updateState({ toolInputPartial: args });
|
|
577
|
+
})
|
|
578
|
+
);
|
|
579
|
+
this.unsubscribers.push(
|
|
580
|
+
bridge.onNotification(MCP_METHODS.TOOL_RESULT, (params) => {
|
|
581
|
+
this.updateState({ toolResult: params });
|
|
582
|
+
})
|
|
583
|
+
);
|
|
584
|
+
this.unsubscribers.push(
|
|
585
|
+
bridge.onNotification(MCP_METHODS.TOOL_CANCELLED, (params) => {
|
|
586
|
+
const { reason } = params;
|
|
587
|
+
this.updateState({ isCancelled: true, cancelReason: reason });
|
|
588
|
+
})
|
|
589
|
+
);
|
|
590
|
+
this.unsubscribers.push(
|
|
591
|
+
bridge.onNotification(MCP_METHODS.HOST_CONTEXT_CHANGED, (params) => {
|
|
592
|
+
const changes = params;
|
|
593
|
+
this.updateState({
|
|
594
|
+
hostContext: { ...this.state.hostContext, ...changes }
|
|
595
|
+
});
|
|
596
|
+
})
|
|
597
|
+
);
|
|
598
|
+
}
|
|
599
|
+
/**
|
|
600
|
+
* Update store state and notify subscribers
|
|
601
|
+
*/
|
|
602
|
+
updateState(updates) {
|
|
603
|
+
const changedKeys = Object.keys(updates);
|
|
604
|
+
this.state = { ...this.state, ...updates };
|
|
605
|
+
for (const key of changedKeys) {
|
|
606
|
+
const keySubscribers = this.subscribers.get(key);
|
|
607
|
+
if (keySubscribers) {
|
|
608
|
+
keySubscribers.forEach((cb) => cb());
|
|
609
|
+
}
|
|
610
|
+
}
|
|
611
|
+
const wildcardSubscribers = this.subscribers.get("*");
|
|
612
|
+
if (wildcardSubscribers) {
|
|
613
|
+
wildcardSubscribers.forEach((cb) => cb());
|
|
614
|
+
}
|
|
615
|
+
}
|
|
616
|
+
/**
|
|
617
|
+
* Set initialization result from bridge
|
|
618
|
+
*/
|
|
619
|
+
setInitialized(hostContext, hostCapabilities, hostInfo) {
|
|
620
|
+
this.updateState({
|
|
621
|
+
isInitialized: true,
|
|
622
|
+
hostContext,
|
|
623
|
+
hostCapabilities,
|
|
624
|
+
hostInfo
|
|
625
|
+
});
|
|
626
|
+
}
|
|
627
|
+
/**
|
|
628
|
+
* Subscribe to changes for specific keys or all changes
|
|
629
|
+
*/
|
|
630
|
+
subscribe(keys, callback) {
|
|
631
|
+
const keyArray = keys === "*" ? ["*"] : Array.isArray(keys) ? keys : [keys];
|
|
632
|
+
for (const key of keyArray) {
|
|
633
|
+
if (!this.subscribers.has(key)) {
|
|
634
|
+
this.subscribers.set(key, /* @__PURE__ */ new Set());
|
|
635
|
+
}
|
|
636
|
+
this.subscribers.get(key).add(callback);
|
|
637
|
+
}
|
|
638
|
+
return () => {
|
|
639
|
+
for (const key of keyArray) {
|
|
640
|
+
this.subscribers.get(key)?.delete(callback);
|
|
641
|
+
}
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
/**
|
|
645
|
+
* Get current value of a state property
|
|
646
|
+
*/
|
|
647
|
+
getSnapshot(key) {
|
|
648
|
+
return this.state[key];
|
|
649
|
+
}
|
|
650
|
+
/**
|
|
651
|
+
* Get the full state snapshot
|
|
652
|
+
*/
|
|
653
|
+
getFullSnapshot() {
|
|
654
|
+
return this.state;
|
|
655
|
+
}
|
|
656
|
+
/**
|
|
657
|
+
* Get server snapshot (for SSR)
|
|
658
|
+
*/
|
|
659
|
+
getServerSnapshot(key) {
|
|
660
|
+
const defaults = {
|
|
661
|
+
isInitialized: false,
|
|
662
|
+
hostContext: {}
|
|
663
|
+
};
|
|
664
|
+
return defaults[key];
|
|
665
|
+
}
|
|
666
|
+
};
|
|
667
|
+
function getStore() {
|
|
668
|
+
return McpAppsStore.getInstance();
|
|
669
|
+
}
|
|
670
|
+
function createMcpStoreHook(key) {
|
|
671
|
+
return function useMcpStore2() {
|
|
672
|
+
const store = getStore();
|
|
673
|
+
return useSyncExternalStore(
|
|
674
|
+
(callback) => store.subscribe(key, callback),
|
|
675
|
+
() => store.getSnapshot(key),
|
|
676
|
+
() => store.getServerSnapshot(key)
|
|
677
|
+
);
|
|
678
|
+
};
|
|
679
|
+
}
|
|
680
|
+
function useMcpStore(key) {
|
|
681
|
+
const store = getStore();
|
|
682
|
+
return useSyncExternalStore(
|
|
683
|
+
(callback) => store.subscribe(key, callback),
|
|
684
|
+
() => store.getSnapshot(key),
|
|
685
|
+
() => store.getServerSnapshot(key)
|
|
686
|
+
);
|
|
687
|
+
}
|
|
688
|
+
|
|
689
|
+
// src/mcp-apps/hooks/use-theme.ts
|
|
690
|
+
function useTheme() {
|
|
691
|
+
const hostContext = useMcpStore("hostContext");
|
|
692
|
+
return hostContext.theme ?? "light";
|
|
693
|
+
}
|
|
694
|
+
|
|
695
|
+
// src/mcp-apps/hooks/use-locale.ts
|
|
696
|
+
function useLocale() {
|
|
697
|
+
const hostContext = useMcpStore("hostContext");
|
|
698
|
+
return hostContext.locale ?? "en-US";
|
|
699
|
+
}
|
|
700
|
+
|
|
701
|
+
// src/mcp-apps/hooks/use-timezone.ts
|
|
702
|
+
function useTimezone() {
|
|
703
|
+
const hostContext = useMcpStore("hostContext");
|
|
704
|
+
return hostContext.timeZone;
|
|
705
|
+
}
|
|
706
|
+
|
|
707
|
+
// src/mcp-apps/hooks/use-display-mode.ts
|
|
708
|
+
function useDisplayMode() {
|
|
709
|
+
const hostContext = useMcpStore("hostContext");
|
|
710
|
+
return hostContext.displayMode ?? "inline";
|
|
711
|
+
}
|
|
712
|
+
|
|
713
|
+
// src/mcp-apps/hooks/use-available-display-modes.ts
|
|
714
|
+
function useAvailableDisplayModes() {
|
|
715
|
+
const hostContext = useMcpStore("hostContext");
|
|
716
|
+
return hostContext.availableDisplayModes ?? ["inline"];
|
|
717
|
+
}
|
|
718
|
+
|
|
719
|
+
// src/mcp-apps/hooks/use-container-dimensions.ts
|
|
720
|
+
function useContainerDimensions() {
|
|
721
|
+
const hostContext = useMcpStore("hostContext");
|
|
722
|
+
return hostContext.containerDimensions;
|
|
723
|
+
}
|
|
724
|
+
|
|
725
|
+
// src/mcp-apps/hooks/use-safe-area.ts
|
|
726
|
+
var DEFAULT_SAFE_AREA = {
|
|
727
|
+
top: 0,
|
|
728
|
+
right: 0,
|
|
729
|
+
bottom: 0,
|
|
730
|
+
left: 0
|
|
731
|
+
};
|
|
732
|
+
function useSafeArea() {
|
|
733
|
+
const hostContext = useMcpStore("hostContext");
|
|
734
|
+
return hostContext.safeAreaInsets ?? DEFAULT_SAFE_AREA;
|
|
735
|
+
}
|
|
736
|
+
|
|
737
|
+
// src/mcp-apps/hooks/use-platform.ts
|
|
738
|
+
function usePlatform() {
|
|
739
|
+
const hostContext = useMcpStore("hostContext");
|
|
740
|
+
return hostContext.platform;
|
|
741
|
+
}
|
|
742
|
+
|
|
743
|
+
// src/mcp-apps/hooks/use-device-capabilities.ts
|
|
744
|
+
var DEFAULT_CAPABILITIES = {
|
|
745
|
+
touch: false,
|
|
746
|
+
hover: true
|
|
747
|
+
};
|
|
748
|
+
function useDeviceCapabilities() {
|
|
749
|
+
const hostContext = useMcpStore("hostContext");
|
|
750
|
+
return hostContext.deviceCapabilities ?? DEFAULT_CAPABILITIES;
|
|
751
|
+
}
|
|
752
|
+
|
|
753
|
+
// src/mcp-apps/hooks/use-styles.ts
|
|
754
|
+
function useStyles() {
|
|
755
|
+
const hostContext = useMcpStore("hostContext");
|
|
756
|
+
return hostContext.styles;
|
|
757
|
+
}
|
|
758
|
+
|
|
759
|
+
// src/mcp-apps/hooks/use-tool-info.ts
|
|
760
|
+
function useToolInfo() {
|
|
761
|
+
const hostContext = useMcpStore("hostContext");
|
|
762
|
+
return hostContext.toolInfo;
|
|
763
|
+
}
|
|
764
|
+
|
|
765
|
+
// src/mcp-apps/hooks/use-tool-input.ts
|
|
766
|
+
function useToolInput() {
|
|
767
|
+
return useMcpStore("toolInput");
|
|
768
|
+
}
|
|
769
|
+
|
|
770
|
+
// src/mcp-apps/hooks/use-tool-result.ts
|
|
771
|
+
function useToolResult() {
|
|
772
|
+
return useMcpStore("toolResult");
|
|
773
|
+
}
|
|
774
|
+
|
|
775
|
+
// src/mcp-apps/hooks/use-host-context.ts
|
|
776
|
+
function useHostContext() {
|
|
777
|
+
return useMcpStore("hostContext");
|
|
778
|
+
}
|
|
779
|
+
|
|
780
|
+
// src/mcp-apps/hooks/use-host-capabilities.ts
|
|
781
|
+
function useHostCapabilities() {
|
|
782
|
+
return useMcpStore("hostCapabilities");
|
|
783
|
+
}
|
|
784
|
+
|
|
785
|
+
// src/mcp-apps/hooks/use-is-initialized.ts
|
|
786
|
+
function useIsInitialized() {
|
|
787
|
+
return useMcpStore("isInitialized");
|
|
788
|
+
}
|
|
789
|
+
|
|
790
|
+
// src/mcp-apps/actions/initialize.ts
|
|
791
|
+
async function initialize(options) {
|
|
792
|
+
const bridge = getBridge();
|
|
793
|
+
const result = await bridge.initialize(options);
|
|
794
|
+
const store = getStore();
|
|
795
|
+
store.setInitialized(result.hostContext, result.hostCapabilities, result.hostInfo);
|
|
796
|
+
return result;
|
|
797
|
+
}
|
|
798
|
+
|
|
799
|
+
// src/mcp-apps/actions/call-tool.ts
|
|
800
|
+
async function callTool(name, args) {
|
|
801
|
+
const bridge = getBridge();
|
|
802
|
+
return bridge.callTool(name, args);
|
|
803
|
+
}
|
|
804
|
+
|
|
805
|
+
// src/mcp-apps/actions/read-resource.ts
|
|
806
|
+
async function readResource(uri) {
|
|
807
|
+
const bridge = getBridge();
|
|
808
|
+
return bridge.readResource(uri);
|
|
809
|
+
}
|
|
810
|
+
|
|
811
|
+
// src/mcp-apps/actions/send-message.ts
|
|
812
|
+
async function sendMessage(text) {
|
|
813
|
+
const bridge = getBridge();
|
|
814
|
+
return bridge.sendMessage(text);
|
|
815
|
+
}
|
|
816
|
+
|
|
817
|
+
// src/mcp-apps/actions/open-link.ts
|
|
818
|
+
async function openLink(url) {
|
|
819
|
+
const bridge = getBridge();
|
|
820
|
+
return bridge.openLink(url);
|
|
821
|
+
}
|
|
822
|
+
|
|
823
|
+
// src/mcp-apps/actions/request-display-mode.ts
|
|
824
|
+
async function requestDisplayMode(mode) {
|
|
825
|
+
const bridge = getBridge();
|
|
826
|
+
return bridge.requestDisplayMode(mode);
|
|
827
|
+
}
|
|
828
|
+
|
|
829
|
+
// src/mcp-apps/actions/update-model-context.ts
|
|
830
|
+
async function updateModelContext(params) {
|
|
831
|
+
const bridge = getBridge();
|
|
832
|
+
return bridge.updateModelContext(params);
|
|
833
|
+
}
|
|
834
|
+
|
|
835
|
+
// src/mcp-apps/actions/notify-size-changed.ts
|
|
836
|
+
function notifySizeChanged(width, height) {
|
|
837
|
+
const bridge = getBridge();
|
|
838
|
+
bridge.notifySizeChanged(width, height);
|
|
839
|
+
}
|
|
840
|
+
function setupAutoSizeReporting(element = document.documentElement) {
|
|
841
|
+
const bridge = getBridge();
|
|
842
|
+
return bridge.setupAutoSizeReporting(element);
|
|
843
|
+
}
|
|
844
|
+
|
|
845
|
+
// src/mcp-apps/actions/log.ts
|
|
846
|
+
function log(level, data, logger) {
|
|
847
|
+
const bridge = getBridge();
|
|
848
|
+
bridge.log(level, data, logger);
|
|
849
|
+
}
|
|
850
|
+
var logDebug = (data, logger) => log("debug", data, logger);
|
|
851
|
+
var logInfo = (data, logger) => log("info", data, logger);
|
|
852
|
+
var logWarning = (data, logger) => log("warning", data, logger);
|
|
853
|
+
var logError = (data, logger) => log("error", data, logger);
|
|
854
|
+
|
|
855
|
+
// src/mcp-apps/actions/on-teardown.ts
|
|
856
|
+
function onTeardown(handler) {
|
|
857
|
+
const bridge = getBridge();
|
|
858
|
+
return bridge.onTeardown(handler);
|
|
859
|
+
}
|
|
860
|
+
|
|
861
|
+
// src/mcp-apps/create-view.ts
|
|
862
|
+
var MCP_FONTS_STYLE_ID = "mcp-app-fonts";
|
|
863
|
+
function injectStyles(styles) {
|
|
864
|
+
if (!styles) return;
|
|
865
|
+
if (styles.variables) {
|
|
866
|
+
for (const [key, value] of Object.entries(styles.variables)) {
|
|
867
|
+
document.documentElement.style.setProperty(key, value);
|
|
868
|
+
}
|
|
869
|
+
}
|
|
870
|
+
if (styles.css?.fonts) {
|
|
871
|
+
let fontEl = document.getElementById(MCP_FONTS_STYLE_ID);
|
|
872
|
+
if (!fontEl) {
|
|
873
|
+
fontEl = document.createElement("style");
|
|
874
|
+
fontEl.id = MCP_FONTS_STYLE_ID;
|
|
875
|
+
document.head.appendChild(fontEl);
|
|
876
|
+
}
|
|
877
|
+
fontEl.textContent = styles.css.fonts;
|
|
878
|
+
}
|
|
879
|
+
}
|
|
880
|
+
function setupEnhancedSizeReporting(options = {}) {
|
|
881
|
+
const {
|
|
882
|
+
debounceMs = 100,
|
|
883
|
+
threshold = 2,
|
|
884
|
+
useMutationObserver = true,
|
|
885
|
+
element = document.body
|
|
886
|
+
} = options;
|
|
887
|
+
let lastSentHeight = 0;
|
|
888
|
+
let timeoutId = null;
|
|
889
|
+
const reportSize = () => {
|
|
890
|
+
const height = document.body.scrollHeight;
|
|
891
|
+
const width = document.documentElement.clientWidth;
|
|
892
|
+
if (Math.abs(height - lastSentHeight) > threshold) {
|
|
893
|
+
notifySizeChanged(width, height);
|
|
894
|
+
lastSentHeight = height;
|
|
895
|
+
}
|
|
896
|
+
};
|
|
897
|
+
const debouncedReport = () => {
|
|
898
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
899
|
+
timeoutId = setTimeout(reportSize, debounceMs);
|
|
900
|
+
};
|
|
901
|
+
const resizeObserver = new ResizeObserver(debouncedReport);
|
|
902
|
+
resizeObserver.observe(element);
|
|
903
|
+
let mutationObserver = null;
|
|
904
|
+
if (useMutationObserver) {
|
|
905
|
+
mutationObserver = new MutationObserver(debouncedReport);
|
|
906
|
+
mutationObserver.observe(document.body, {
|
|
907
|
+
childList: true,
|
|
908
|
+
subtree: true,
|
|
909
|
+
attributes: true
|
|
910
|
+
});
|
|
911
|
+
}
|
|
912
|
+
reportSize();
|
|
913
|
+
return () => {
|
|
914
|
+
if (timeoutId) clearTimeout(timeoutId);
|
|
915
|
+
resizeObserver.disconnect();
|
|
916
|
+
mutationObserver?.disconnect();
|
|
917
|
+
};
|
|
918
|
+
}
|
|
919
|
+
function computeChanges(prev, next) {
|
|
920
|
+
const changes = {};
|
|
921
|
+
for (const key of Object.keys(next)) {
|
|
922
|
+
if (prev[key] !== next[key]) {
|
|
923
|
+
changes[key] = next[key];
|
|
924
|
+
}
|
|
925
|
+
}
|
|
926
|
+
return changes;
|
|
927
|
+
}
|
|
928
|
+
async function createMcpView(options = {}) {
|
|
929
|
+
const {
|
|
930
|
+
clientInfo,
|
|
931
|
+
autoResize = true,
|
|
932
|
+
autoInjectStyles = false,
|
|
933
|
+
onReady,
|
|
934
|
+
onContextChange,
|
|
935
|
+
onTeardown: onTeardownCallback
|
|
936
|
+
} = options;
|
|
937
|
+
const cleanupFns = [];
|
|
938
|
+
const initResult = await initialize(clientInfo ? { clientInfo } : void 0);
|
|
939
|
+
const store = getStore();
|
|
940
|
+
if (autoInjectStyles) {
|
|
941
|
+
injectStyles(initResult.hostContext.styles);
|
|
942
|
+
}
|
|
943
|
+
if (autoResize) {
|
|
944
|
+
const resizeOptions = typeof autoResize === "object" ? autoResize : {};
|
|
945
|
+
const cleanup = setupEnhancedSizeReporting(resizeOptions);
|
|
946
|
+
cleanupFns.push(cleanup);
|
|
947
|
+
}
|
|
948
|
+
let previousContext = initResult.hostContext;
|
|
949
|
+
const unsubscribe = store.subscribe("hostContext", () => {
|
|
950
|
+
const newContext = store.getSnapshot("hostContext");
|
|
951
|
+
const changes = computeChanges(previousContext, newContext);
|
|
952
|
+
if (autoInjectStyles && changes.styles) {
|
|
953
|
+
injectStyles(newContext.styles);
|
|
954
|
+
}
|
|
955
|
+
onContextChange?.(newContext, changes);
|
|
956
|
+
previousContext = newContext;
|
|
957
|
+
});
|
|
958
|
+
cleanupFns.push(unsubscribe);
|
|
959
|
+
if (onTeardownCallback) {
|
|
960
|
+
const unregisterTeardown = onTeardown((params) => {
|
|
961
|
+
onTeardownCallback(params.reason);
|
|
962
|
+
});
|
|
963
|
+
cleanupFns.push(unregisterTeardown);
|
|
964
|
+
}
|
|
965
|
+
onReady?.(initResult.hostContext);
|
|
966
|
+
return {
|
|
967
|
+
getContext: () => store.getSnapshot("hostContext"),
|
|
968
|
+
notifySize: notifySizeChanged,
|
|
969
|
+
destroy: () => {
|
|
970
|
+
cleanupFns.forEach((fn) => fn());
|
|
971
|
+
}
|
|
972
|
+
};
|
|
973
|
+
}
|
|
974
|
+
|
|
975
|
+
export { DEFAULT_CLIENT_INFO, ERROR_CODES, JsonRpcError, MCP_METHODS, McpAppsBridge, McpAppsStore, PROTOCOL_VERSION, callTool, createErrorResponse, createMcpStoreHook, createMcpView, createNotification, createRequest, createSuccessResponse, generateId, getBridge, getStore, initialize, isErrorResponse, isJsonRpcMessage, isNotification, isRequest, isResponse, log, logDebug, logError, logInfo, logWarning, mcp_apps_exports, notifySizeChanged, onTeardown, openLink, readResource, requestDisplayMode, sendMessage, setupAutoSizeReporting, updateModelContext, useAvailableDisplayModes, useContainerDimensions, useDeviceCapabilities, useDisplayMode, useHostCapabilities, useHostContext, useIsInitialized, useLocale, useMcpStore, usePlatform, useSafeArea, useStyles, useTheme, useTimezone, useToolInfo, useToolInput, useToolResult };
|
|
976
|
+
//# sourceMappingURL=chunk-YGGRUIUG.js.map
|
|
977
|
+
//# sourceMappingURL=chunk-YGGRUIUG.js.map
|