skybridge 0.0.0-dev.eb88644 → 0.0.0-dev.eb9ddab
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 +9 -5
- package/dist/cli/use-nodemon.d.ts +1 -0
- package/dist/cli/use-nodemon.js +10 -3
- package/dist/cli/use-nodemon.js.map +1 -1
- package/dist/commands/dev.d.ts +0 -1
- package/dist/commands/dev.js +1 -7
- package/dist/commands/dev.js.map +1 -1
- package/dist/server/express.d.ts +8 -2
- package/dist/server/express.js +24 -19
- package/dist/server/express.js.map +1 -1
- package/dist/server/express.test.js +189 -11
- package/dist/server/express.test.js.map +1 -1
- package/dist/server/index.d.ts +1 -0
- package/dist/server/index.js.map +1 -1
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +490 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +47 -2
- package/dist/server/server.js +114 -32
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +0 -1
- package/dist/server/templateHelper.js.map +1 -1
- package/dist/server/templates/development.hbs +0 -55
- package/dist/server/widgetsDevServer.d.ts +2 -1
- package/dist/server/widgetsDevServer.js +2 -8
- package/dist/server/widgetsDevServer.js.map +1 -1
- package/dist/test/widget.test.js +17 -15
- package/dist/test/widget.test.js.map +1 -1
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +3 -3
- package/dist/web/bridges/apps-sdk/adaptor.js +6 -2
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -1
- package/dist/web/bridges/apps-sdk/bridge.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.d.ts +1 -1
- package/dist/web/bridges/apps-sdk/index.js.map +1 -1
- package/dist/web/bridges/apps-sdk/types.d.ts +7 -5
- package/dist/web/bridges/apps-sdk/types.js.map +1 -1
- package/dist/web/bridges/mcp-app/adaptor.d.ts +5 -3
- package/dist/web/bridges/mcp-app/adaptor.js +29 -38
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -1
- package/dist/web/bridges/mcp-app/bridge.d.ts +13 -30
- package/dist/web/bridges/mcp-app/bridge.js +43 -201
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +5 -3
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +2 -2
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -1
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +1 -41
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -1
- package/dist/web/bridges/types.d.ts +4 -2
- package/dist/web/components/modal-provider.js +1 -3
- package/dist/web/components/modal-provider.js.map +1 -1
- package/dist/web/create-store.test.js +7 -2
- package/dist/web/create-store.test.js.map +1 -1
- package/dist/web/data-llm.test.js +2 -1
- package/dist/web/data-llm.test.js.map +1 -1
- package/dist/web/hooks/test/utils.js +4 -0
- package/dist/web/hooks/test/utils.js.map +1 -1
- package/dist/web/hooks/use-display-mode.d.ts +3 -3
- package/dist/web/hooks/use-display-mode.js.map +1 -1
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-layout.test.js +3 -3
- package/dist/web/hooks/use-layout.test.js.map +1 -1
- package/dist/web/hooks/use-open-external.test.js +15 -10
- package/dist/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/web/hooks/use-request-modal.test.js +5 -1
- package/dist/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/web/hooks/use-tool-info.test.js +1 -1
- package/dist/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/web/hooks/use-user.js +18 -2
- package/dist/web/hooks/use-user.js.map +1 -1
- package/dist/web/hooks/use-user.test.js +29 -1
- package/dist/web/hooks/use-user.test.js.map +1 -1
- package/dist/web/hooks/use-widget-state.test.js +2 -0
- package/dist/web/hooks/use-widget-state.test.js.map +1 -1
- package/package.json +14 -14
- package/tsconfig.base.json +3 -0
- package/dist/server/const.d.ts +0 -1
- package/dist/server/const.js +0 -2
- package/dist/server/const.js.map +0 -1
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { UnknownObject } from "../../types.js";
|
|
2
2
|
import type { CallToolArgs, CallToolResponse, FileMetadata, RequestModalOptions } from "../types.js";
|
|
3
3
|
type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
|
|
4
|
-
|
|
4
|
+
type RequestDisplayMode = Exclude<DisplayMode, "modal">;
|
|
5
|
+
export type AppsSdkWidgetState = {
|
|
5
6
|
modelContent: Record<string, unknown>;
|
|
7
|
+
privateContent: Record<string, unknown>;
|
|
6
8
|
imageIds?: string[];
|
|
7
9
|
};
|
|
8
10
|
export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
@@ -22,7 +24,7 @@ declare global {
|
|
|
22
24
|
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
23
25
|
}
|
|
24
26
|
}
|
|
25
|
-
export type AppsSdkContext<ToolInput extends UnknownObject = Record<never, unknown>, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WS extends
|
|
27
|
+
export type AppsSdkContext<ToolInput extends UnknownObject = Record<never, unknown>, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WS extends AppsSdkWidgetState = AppsSdkWidgetState> = {
|
|
26
28
|
theme: Theme;
|
|
27
29
|
userAgent: UserAgent;
|
|
28
30
|
locale: string;
|
|
@@ -37,7 +39,7 @@ export type AppsSdkContext<ToolInput extends UnknownObject = Record<never, unkno
|
|
|
37
39
|
toolResponseMetadata: ToolResponseMetadata | null;
|
|
38
40
|
widgetState: WS | null;
|
|
39
41
|
};
|
|
40
|
-
export type AppsSdkMethods<WS extends
|
|
42
|
+
export type AppsSdkMethods<WS extends AppsSdkWidgetState = AppsSdkWidgetState> = {
|
|
41
43
|
/** Calls a tool on your MCP. Returns the full response. */
|
|
42
44
|
callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
43
45
|
/** Triggers a followup turn in the ChatGPT conversation */
|
|
@@ -51,13 +53,13 @@ export type AppsSdkMethods<WS extends WidgetState = WidgetState> = {
|
|
|
51
53
|
}): void;
|
|
52
54
|
/** For transitioning an app from inline to fullscreen or pip */
|
|
53
55
|
requestDisplayMode: (args: {
|
|
54
|
-
mode:
|
|
56
|
+
mode: RequestDisplayMode;
|
|
55
57
|
}) => Promise<{
|
|
56
58
|
/**
|
|
57
59
|
* The granted display mode. The host may reject the request.
|
|
58
60
|
* For mobile, PiP is always coerced to fullscreen.
|
|
59
61
|
*/
|
|
60
|
-
mode:
|
|
62
|
+
mode: RequestDisplayMode;
|
|
61
63
|
}>;
|
|
62
64
|
/**
|
|
63
65
|
* Sets the widget state.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/types.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk/types.ts"],"names":[],"mappings":"AAiBA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA2FD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
import type { Adaptor, CallToolResponse, DisplayMode, HostContext, HostContextStore, OpenExternalOptions, RequestModalOptions, SetWidgetStateAction } from "../types.js";
|
|
1
|
+
import type { Adaptor, CallToolResponse, HostContext, HostContextStore, OpenExternalOptions, RequestDisplayMode, RequestModalOptions, SetWidgetStateAction } from "../types.js";
|
|
3
2
|
export declare class McpAppAdaptor implements Adaptor {
|
|
4
3
|
private static instance;
|
|
5
4
|
private stores;
|
|
@@ -12,7 +11,10 @@ export declare class McpAppAdaptor implements Adaptor {
|
|
|
12
11
|
static resetInstance(): void;
|
|
13
12
|
getHostContextStore<K extends keyof HostContext>(key: K): HostContextStore<K>;
|
|
14
13
|
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
15
|
-
requestDisplayMode: (mode:
|
|
14
|
+
requestDisplayMode: (mode: RequestDisplayMode) => Promise<{
|
|
15
|
+
[x: string]: unknown;
|
|
16
|
+
mode: "inline" | "fullscreen" | "pip";
|
|
17
|
+
}>;
|
|
16
18
|
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
17
19
|
openExternal(href: string, options?: OpenExternalOptions): void;
|
|
18
20
|
private initializeStores;
|
|
@@ -25,13 +25,10 @@ export class McpAppAdaptor {
|
|
|
25
25
|
return this.stores[key];
|
|
26
26
|
}
|
|
27
27
|
callTool = async (name, args) => {
|
|
28
|
-
const
|
|
29
|
-
const response = await
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
name,
|
|
33
|
-
arguments: args ?? undefined,
|
|
34
|
-
},
|
|
28
|
+
const app = await McpAppBridge.getInstance().getApp();
|
|
29
|
+
const response = await app.callServerTool({
|
|
30
|
+
name,
|
|
31
|
+
arguments: args ?? undefined,
|
|
35
32
|
});
|
|
36
33
|
const result = response.content
|
|
37
34
|
.filter((content) => content.type === "text")
|
|
@@ -45,39 +42,31 @@ export class McpAppAdaptor {
|
|
|
45
42
|
meta: response._meta ?? {},
|
|
46
43
|
};
|
|
47
44
|
};
|
|
48
|
-
requestDisplayMode = (mode) => {
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
return bridge.request({
|
|
52
|
-
method: "ui/request-display-mode",
|
|
53
|
-
params: { mode },
|
|
54
|
-
});
|
|
55
|
-
}
|
|
56
|
-
throw new Error("Modal display mode is not accessible in MCP App.");
|
|
45
|
+
requestDisplayMode = async (mode) => {
|
|
46
|
+
const app = await McpAppBridge.getInstance().getApp();
|
|
47
|
+
return app.requestDisplayMode({ mode });
|
|
57
48
|
};
|
|
58
49
|
sendFollowUpMessage = async (prompt) => {
|
|
59
|
-
const
|
|
60
|
-
await
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
},
|
|
69
|
-
],
|
|
70
|
-
},
|
|
50
|
+
const app = await McpAppBridge.getInstance().getApp();
|
|
51
|
+
await app.sendMessage({
|
|
52
|
+
role: "user",
|
|
53
|
+
content: [
|
|
54
|
+
{
|
|
55
|
+
type: "text",
|
|
56
|
+
text: prompt,
|
|
57
|
+
},
|
|
58
|
+
],
|
|
71
59
|
});
|
|
72
60
|
};
|
|
73
61
|
openExternal(href, options) {
|
|
74
62
|
if (options?.redirectUrl === false) {
|
|
75
63
|
console.warn("[skybridge] redirectUrl option is not supported by the MCP ui/open-link protocol and will be ignored.");
|
|
76
64
|
}
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
65
|
+
McpAppBridge.getInstance()
|
|
66
|
+
.getApp()
|
|
67
|
+
.then((app) => app.openLink({ url: href }))
|
|
68
|
+
.catch((err) => {
|
|
69
|
+
console.error("Failed to open external link:", err);
|
|
81
70
|
});
|
|
82
71
|
}
|
|
83
72
|
initializeStores() {
|
|
@@ -137,14 +126,16 @@ export class McpAppAdaptor {
|
|
|
137
126
|
this.widgetStateListeners.forEach((listener) => {
|
|
138
127
|
listener();
|
|
139
128
|
});
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
params: {
|
|
129
|
+
try {
|
|
130
|
+
const app = await McpAppBridge.getInstance().getApp();
|
|
131
|
+
await app.updateModelContext({
|
|
144
132
|
structuredContent: newState,
|
|
145
133
|
content: [{ type: "text", text: JSON.stringify(newState) }],
|
|
146
|
-
}
|
|
147
|
-
}
|
|
134
|
+
});
|
|
135
|
+
}
|
|
136
|
+
catch (error) {
|
|
137
|
+
console.error("Failed to update widget state in MCP App.", error);
|
|
138
|
+
}
|
|
148
139
|
};
|
|
149
140
|
/**
|
|
150
141
|
* @throws File upload is not supported in MCP App.
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"adaptor.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AAWrC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACM,YAAY,GAA+B,IAAI,CAAC;IAChD,oBAAoB,GAAG,IAAI,GAAG,EAAc,CAAC;IAE7C,UAAU,GAAwB;QACxC,IAAI,EAAE,QAAQ;KACf,CAAC;IACM,aAAa,GAAG,IAAI,GAAG,EAAc,CAAC;IAE9C;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,CAAC,gBAAgB,EAAE,CAAC;IACxC,CAAC;IAEM,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC5B,aAAa,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G,EAAE;gBAChB,MAAM,OAAO,GAAG,MAAM,CAAC,WAAW,CAChC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,EAAE,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CAAC,CAAC,CACvB,CAAC;gBACvB,MAAM,QAAQ,GAAG,eAAe,CAAC,OAAO,CAAC,CAAC;gBAE1C,IAAI,WAAW,KAAK,SAAS,IAAI,MAAM,CAAC,WAAW,EAAE,QAAQ,CAAC,EAAE,CAAC;oBAC/D,OAAO,WAAW,CAAC;gBACrB,CAAC;gBAED,WAAW,GAAG,QAAQ,CAAC;gBACvB,OAAO,QAAQ,CAAC;YAClB,CAAC;SACF,CAAC;IACJ,CAAC"}
|
|
@@ -1,43 +1,26 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
2
3
|
import type { Bridge, Subscribe } from "../types.js";
|
|
3
4
|
import type { McpAppContext, McpAppContextKey } from "./types.js";
|
|
4
|
-
|
|
5
|
-
export declare class McpAppBridge implements Bridge<McpUiHostContext> {
|
|
5
|
+
export declare class McpAppBridge implements Bridge<McpAppContext> {
|
|
6
6
|
private static instance;
|
|
7
7
|
context: McpAppContext;
|
|
8
8
|
private listeners;
|
|
9
|
-
private
|
|
10
|
-
private
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
private
|
|
15
|
-
|
|
16
|
-
static getInstance(options?: Partial<
|
|
9
|
+
private app;
|
|
10
|
+
private connectPromise;
|
|
11
|
+
constructor(options: {
|
|
12
|
+
appInfo: Implementation;
|
|
13
|
+
});
|
|
14
|
+
private connect;
|
|
15
|
+
getApp(): Promise<App>;
|
|
16
|
+
static getInstance(options?: Partial<{
|
|
17
|
+
appInfo: Implementation;
|
|
18
|
+
}>): McpAppBridge;
|
|
17
19
|
subscribe(key: McpAppContextKey): Subscribe;
|
|
18
20
|
subscribe(keys: readonly McpAppContextKey[]): Subscribe;
|
|
19
21
|
getSnapshot<K extends keyof McpAppContext>(key: K): McpAppContext[K];
|
|
20
22
|
cleanup: () => void;
|
|
21
23
|
static resetInstance(): void;
|
|
22
|
-
request<R extends {
|
|
23
|
-
method: string;
|
|
24
|
-
params?: unknown;
|
|
25
|
-
}, T>({ method, params, }: R): Promise<T>;
|
|
26
24
|
private emit;
|
|
27
25
|
private updateContext;
|
|
28
|
-
private init;
|
|
29
|
-
private handleMessage;
|
|
30
|
-
private handleResponse;
|
|
31
|
-
private handleNotification;
|
|
32
|
-
private handleRequest;
|
|
33
|
-
private connect;
|
|
34
|
-
private notify;
|
|
35
|
-
private sendSizeChanged;
|
|
36
|
-
/**
|
|
37
|
-
* Set up automatic size change notifications using ResizeObserver.
|
|
38
|
-
* Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
|
|
39
|
-
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
|
|
40
|
-
*/
|
|
41
|
-
private setupSizeChangedNotifications;
|
|
42
26
|
}
|
|
43
|
-
export {};
|
|
@@ -1,12 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
var JsonRpcErrorCode;
|
|
3
|
-
(function (JsonRpcErrorCode) {
|
|
4
|
-
JsonRpcErrorCode[JsonRpcErrorCode["ParseError"] = -32700] = "ParseError";
|
|
5
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InvalidRequest"] = -32600] = "InvalidRequest";
|
|
6
|
-
JsonRpcErrorCode[JsonRpcErrorCode["MethodNotFound"] = -32601] = "MethodNotFound";
|
|
7
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InvalidParams"] = -32602] = "InvalidParams";
|
|
8
|
-
JsonRpcErrorCode[JsonRpcErrorCode["InternalError"] = -32603] = "InternalError";
|
|
9
|
-
})(JsonRpcErrorCode || (JsonRpcErrorCode = {}));
|
|
1
|
+
import { App } from "@modelcontextprotocol/ext-apps";
|
|
10
2
|
export class McpAppBridge {
|
|
11
3
|
static instance = null;
|
|
12
4
|
context = {
|
|
@@ -15,34 +7,58 @@ export class McpAppBridge {
|
|
|
15
7
|
toolResult: null,
|
|
16
8
|
};
|
|
17
9
|
listeners = new Map();
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
constructor(options, requestTimeout = 10_000) {
|
|
25
|
-
this.requestTimeout = requestTimeout;
|
|
26
|
-
this.initialized = false;
|
|
27
|
-
this.appInitializationOptions = {
|
|
28
|
-
appInfo: options.appInfo,
|
|
29
|
-
appCapabilities: {},
|
|
30
|
-
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
10
|
+
app;
|
|
11
|
+
connectPromise;
|
|
12
|
+
constructor(options) {
|
|
13
|
+
this.app = new App(options.appInfo);
|
|
14
|
+
this.app.ontoolinput = (params) => {
|
|
15
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
31
16
|
};
|
|
32
|
-
this.
|
|
17
|
+
this.app.ontoolinputpartial = (params) => {
|
|
18
|
+
this.updateContext({ toolInput: params.arguments ?? {} });
|
|
19
|
+
};
|
|
20
|
+
this.app.ontoolresult = (params) => {
|
|
21
|
+
this.updateContext({ toolResult: params });
|
|
22
|
+
};
|
|
23
|
+
this.app.ontoolcancelled = (params) => {
|
|
24
|
+
this.updateContext({ toolCancelled: params });
|
|
25
|
+
};
|
|
26
|
+
this.app.onhostcontextchanged = (params) => {
|
|
27
|
+
this.updateContext(params);
|
|
28
|
+
};
|
|
29
|
+
this.connectPromise = this.connect();
|
|
30
|
+
}
|
|
31
|
+
async connect() {
|
|
32
|
+
try {
|
|
33
|
+
await this.app.connect();
|
|
34
|
+
const hostContext = this.app.getHostContext();
|
|
35
|
+
if (hostContext) {
|
|
36
|
+
this.updateContext(hostContext);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
catch (err) {
|
|
40
|
+
console.error(err);
|
|
41
|
+
}
|
|
33
42
|
}
|
|
34
|
-
|
|
43
|
+
async getApp() {
|
|
44
|
+
await this.connectPromise;
|
|
45
|
+
return this.app;
|
|
46
|
+
}
|
|
47
|
+
static getInstance(options) {
|
|
35
48
|
if (window.skybridge.hostType !== "mcp-app") {
|
|
36
49
|
throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
|
|
37
50
|
}
|
|
38
|
-
if (McpAppBridge.instance &&
|
|
39
|
-
console.warn("McpAppBridge.getInstance: options
|
|
51
|
+
if (McpAppBridge.instance && options) {
|
|
52
|
+
console.warn("McpAppBridge.getInstance: options ignored, instance already exists");
|
|
40
53
|
}
|
|
41
54
|
if (!McpAppBridge.instance) {
|
|
42
55
|
const defaultOptions = {
|
|
43
56
|
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
44
57
|
};
|
|
45
|
-
McpAppBridge.instance = new McpAppBridge({
|
|
58
|
+
McpAppBridge.instance = new McpAppBridge({
|
|
59
|
+
...defaultOptions,
|
|
60
|
+
...options,
|
|
61
|
+
});
|
|
46
62
|
}
|
|
47
63
|
return McpAppBridge.instance;
|
|
48
64
|
}
|
|
@@ -63,14 +79,7 @@ export class McpAppBridge {
|
|
|
63
79
|
return this.context[key];
|
|
64
80
|
}
|
|
65
81
|
cleanup = () => {
|
|
66
|
-
window.removeEventListener("message", this.handleMessage);
|
|
67
|
-
this.pendingRequests.forEach((request) => {
|
|
68
|
-
clearTimeout(request.timeout);
|
|
69
|
-
});
|
|
70
|
-
this.pendingRequests.clear();
|
|
71
82
|
this.listeners.clear();
|
|
72
|
-
this.cleanupSizeObserver?.();
|
|
73
|
-
this.cleanupSizeObserver = null;
|
|
74
83
|
};
|
|
75
84
|
static resetInstance() {
|
|
76
85
|
if (McpAppBridge.instance) {
|
|
@@ -78,20 +87,6 @@ export class McpAppBridge {
|
|
|
78
87
|
McpAppBridge.instance = null;
|
|
79
88
|
}
|
|
80
89
|
}
|
|
81
|
-
request({ method, params, }) {
|
|
82
|
-
const id = this.nextId++;
|
|
83
|
-
const { promise, resolve, reject } = Promise.withResolvers();
|
|
84
|
-
this.pendingRequests.set(id, {
|
|
85
|
-
resolve: resolve,
|
|
86
|
-
reject,
|
|
87
|
-
timeout: setTimeout(() => {
|
|
88
|
-
reject(new Error("Request timed out"));
|
|
89
|
-
this.pendingRequests.delete(id);
|
|
90
|
-
}, this.requestTimeout),
|
|
91
|
-
});
|
|
92
|
-
window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
|
|
93
|
-
return promise;
|
|
94
|
-
}
|
|
95
90
|
emit(key) {
|
|
96
91
|
this.listeners.get(key)?.forEach((listener) => {
|
|
97
92
|
listener();
|
|
@@ -103,158 +98,5 @@ export class McpAppBridge {
|
|
|
103
98
|
this.emit(key);
|
|
104
99
|
}
|
|
105
100
|
}
|
|
106
|
-
init() {
|
|
107
|
-
if (this.initialized) {
|
|
108
|
-
return;
|
|
109
|
-
}
|
|
110
|
-
this.initialized = true;
|
|
111
|
-
if (typeof window === "undefined" || window.parent === window) {
|
|
112
|
-
return;
|
|
113
|
-
}
|
|
114
|
-
window.addEventListener("message", this.handleMessage);
|
|
115
|
-
this.connect();
|
|
116
|
-
}
|
|
117
|
-
handleMessage = (event) => {
|
|
118
|
-
const data = event.data;
|
|
119
|
-
if (data.jsonrpc !== "2.0") {
|
|
120
|
-
return;
|
|
121
|
-
}
|
|
122
|
-
if ("id" in data) {
|
|
123
|
-
if ("method" in data) {
|
|
124
|
-
this.handleRequest(data);
|
|
125
|
-
return;
|
|
126
|
-
}
|
|
127
|
-
this.handleResponse(data);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
this.handleNotification(data);
|
|
131
|
-
};
|
|
132
|
-
handleResponse(response) {
|
|
133
|
-
const request = this.pendingRequests.get(response.id);
|
|
134
|
-
if (request) {
|
|
135
|
-
clearTimeout(request.timeout);
|
|
136
|
-
this.pendingRequests.delete(response.id);
|
|
137
|
-
if ("error" in response) {
|
|
138
|
-
request.reject(new Error(response.error.message));
|
|
139
|
-
return;
|
|
140
|
-
}
|
|
141
|
-
request.resolve(response.result);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
handleNotification = (notification) => {
|
|
145
|
-
switch (notification.method) {
|
|
146
|
-
case "ui/notifications/host-context-changed":
|
|
147
|
-
this.updateContext(notification.params);
|
|
148
|
-
return;
|
|
149
|
-
case "ui/notifications/tool-input-partial":
|
|
150
|
-
this.updateContext({
|
|
151
|
-
toolInput: notification.params.arguments ?? {},
|
|
152
|
-
});
|
|
153
|
-
return;
|
|
154
|
-
case "ui/notifications/tool-input":
|
|
155
|
-
this.updateContext({
|
|
156
|
-
toolInput: notification.params.arguments ?? {},
|
|
157
|
-
});
|
|
158
|
-
return;
|
|
159
|
-
case "ui/notifications/tool-result":
|
|
160
|
-
this.updateContext({
|
|
161
|
-
toolResult: notification.params,
|
|
162
|
-
});
|
|
163
|
-
return;
|
|
164
|
-
case "ui/notifications/tool-cancelled":
|
|
165
|
-
this.updateContext({
|
|
166
|
-
toolCancelled: notification.params,
|
|
167
|
-
});
|
|
168
|
-
return;
|
|
169
|
-
}
|
|
170
|
-
};
|
|
171
|
-
handleRequest = (request) => {
|
|
172
|
-
switch (request.method) {
|
|
173
|
-
case "ui/resource-teardown":
|
|
174
|
-
this.cleanup();
|
|
175
|
-
window.parent.postMessage({
|
|
176
|
-
jsonrpc: "2.0",
|
|
177
|
-
id: request.id,
|
|
178
|
-
result: {},
|
|
179
|
-
}, "*");
|
|
180
|
-
return;
|
|
181
|
-
default:
|
|
182
|
-
window.parent.postMessage({
|
|
183
|
-
jsonrpc: "2.0",
|
|
184
|
-
id: request.id,
|
|
185
|
-
error: {
|
|
186
|
-
code: JsonRpcErrorCode.MethodNotFound,
|
|
187
|
-
message: "Unsupported Request",
|
|
188
|
-
},
|
|
189
|
-
}, "*");
|
|
190
|
-
}
|
|
191
|
-
};
|
|
192
|
-
async connect() {
|
|
193
|
-
try {
|
|
194
|
-
const result = await this.request({
|
|
195
|
-
method: "ui/initialize",
|
|
196
|
-
params: this.appInitializationOptions,
|
|
197
|
-
});
|
|
198
|
-
this.updateContext(result.hostContext);
|
|
199
|
-
this.notify({ method: "ui/notifications/initialized" });
|
|
200
|
-
this.cleanupSizeObserver = this.setupSizeChangedNotifications();
|
|
201
|
-
}
|
|
202
|
-
catch (err) {
|
|
203
|
-
console.error(err);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
notify(notification) {
|
|
207
|
-
window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
|
|
208
|
-
}
|
|
209
|
-
sendSizeChanged(params) {
|
|
210
|
-
this.notify({ method: "ui/notifications/size-changed", params });
|
|
211
|
-
}
|
|
212
|
-
/**
|
|
213
|
-
* Set up automatic size change notifications using ResizeObserver.
|
|
214
|
-
* Based on @modelcontextprotocol/ext-apps App.setupSizeChangedNotifications
|
|
215
|
-
* @see https://github.com/modelcontextprotocol/ext-apps/blob/main/src/app.ts#L940-L989
|
|
216
|
-
*/
|
|
217
|
-
setupSizeChangedNotifications() {
|
|
218
|
-
let scheduled = false;
|
|
219
|
-
let lastWidth = 0;
|
|
220
|
-
let lastHeight = 0;
|
|
221
|
-
const sendBodySizeChanged = () => {
|
|
222
|
-
if (scheduled) {
|
|
223
|
-
return;
|
|
224
|
-
}
|
|
225
|
-
scheduled = true;
|
|
226
|
-
requestAnimationFrame(() => {
|
|
227
|
-
scheduled = false;
|
|
228
|
-
let width;
|
|
229
|
-
let height;
|
|
230
|
-
// In fullscreen mode, use viewport size since the widget should fill
|
|
231
|
-
// the entire available space provided by the host.
|
|
232
|
-
if (this.context.displayMode === "fullscreen") {
|
|
233
|
-
width = window.innerWidth;
|
|
234
|
-
height = window.innerHeight;
|
|
235
|
-
}
|
|
236
|
-
else {
|
|
237
|
-
// Use scrollWidth/scrollHeight to measure actual rendered content size.
|
|
238
|
-
// This works better than fit-content for viewport-based layouts (vw/vh)
|
|
239
|
-
// and fluid elements like maps that want to fill available space.
|
|
240
|
-
const body = document.body;
|
|
241
|
-
width = Math.ceil(body.scrollWidth);
|
|
242
|
-
height = Math.ceil(body.scrollHeight);
|
|
243
|
-
}
|
|
244
|
-
// Only send if size actually changed (prevents feedback loops from
|
|
245
|
-
// style changes)
|
|
246
|
-
if (width !== lastWidth || height !== lastHeight) {
|
|
247
|
-
lastWidth = width;
|
|
248
|
-
lastHeight = height;
|
|
249
|
-
this.sendSizeChanged({ width, height });
|
|
250
|
-
}
|
|
251
|
-
});
|
|
252
|
-
};
|
|
253
|
-
sendBodySizeChanged();
|
|
254
|
-
const resizeObserver = new ResizeObserver(sendBodySizeChanged);
|
|
255
|
-
resizeObserver.observe(document.documentElement);
|
|
256
|
-
resizeObserver.observe(document.body);
|
|
257
|
-
return () => resizeObserver.disconnect();
|
|
258
|
-
}
|
|
259
101
|
}
|
|
260
102
|
//# sourceMappingURL=bridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,MAAM,gCAAgC,CAAC;AAKrD,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAkB;QAC9B,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,IAAI,GAAG,EAAqC,CAAC;IACzD,GAAG,CAAM;IACT,cAAc,CAAgB;IAEtC,YAAY,OAAoC;QAC9C,IAAI,CAAC,GAAG,GAAG,IAAI,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC,CAAC;QAEpC,IAAI,CAAC,GAAG,CAAC,WAAW,GAAG,CAAC,MAAM,EAAE,EAAE;YAChC,IAAI,CAAC,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AAM,CAAC,QAAQ,CAAC,CAAC;gBAC5C,CAAC;YACH,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,CAAgC,GAAM;QACtD,OAAO,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,CAAC;IAC3B,CAAC;IAEM,OAAO,GAAG,GAAG,EAAE;QACpB,IAAI,CAAC,SAAS,CAAC,KAAK,EAAE,CAAC;IACzB,CAAC,CAAC;IAEK,MAAM,CAAC,aAAa;QACzB,IAAI,YAAY,CAAC,QAAQ,EAAE,CAAC;YAC1B,YAAY,CAAC,QAAQ,CAAC,OAAO,EAAE,CAAC;YAChC,YAAY,CAAC,QAAQ,GAAG,IAAI,CAAC;QAC/B,CAAC;IACH,CAAC;IAEO,IAAI,CAAC,GAAqB;QAChC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,GAAG,CAAC,EAAE,OAAO,CAAC,CAAC,QAAQ,EAAE,EAAE;YAC5C,QAAQ,EAAE,CAAC;QACb,CAAC,CAAC,CAAC;IACL,CAAC;IAEO,aAAa,CAAC,OAA+B;QACnD,IAAI,CAAC,OAAO,GAAG,EAAE,GAAG,IAAI,CAAC,OAAO,EAAE,GAAG,OAAO,EAAE,CAAC;QAC/C,KAAK,MAAM,GAAG,IAAI,MAAM,CAAC,IAAI,CAAC,OAAO,CAAC,EAAE,CAAC;YACvC,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;IACH,CAAC"}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { Implementation } from "@modelcontextprotocol/sdk/types.js";
|
|
2
2
|
import type { McpAppContext } from "./types.js";
|
|
3
|
-
type McpAppInitializationOptions =
|
|
4
|
-
|
|
3
|
+
type McpAppInitializationOptions = {
|
|
4
|
+
appInfo: Implementation;
|
|
5
|
+
};
|
|
6
|
+
export declare function useMcpAppContext<K extends keyof McpAppContext>(key: K, options?: Partial<McpAppInitializationOptions>): McpAppContext[K];
|
|
5
7
|
export {};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
2
|
import { McpAppBridge } from "./bridge.js";
|
|
3
|
-
export function useMcpAppContext(key, options
|
|
4
|
-
const bridge = McpAppBridge.getInstance(options
|
|
3
|
+
export function useMcpAppContext(key, options) {
|
|
4
|
+
const bridge = McpAppBridge.getInstance(options);
|
|
5
5
|
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
6
6
|
}
|
|
7
7
|
//# sourceMappingURL=use-mcp-app-context.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"use-mcp-app-context.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app/use-mcp-app-context.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C,MAAM,UAAU,gBAAgB,CAC9B,GAAM,EACN,OAA8C;IAE9C,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,CAAC,CAAC;IACjD,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
|