skybridge 0.0.0-dev.cc48d14 → 0.0.0-dev.ccf1ae1
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/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +12 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +30 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +15 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +108 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +4 -2
- package/dist/src/web/bridges/apps-sdk-bridge.js +19 -14
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +1 -1
- package/dist/src/web/bridges/hooks/use-bridge.js +3 -56
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +3 -2
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +9 -26
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -1
- package/dist/src/web/bridges/index.d.ts +1 -1
- package/dist/src/web/bridges/index.js +1 -1
- package/dist/src/web/bridges/index.js.map +1 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +15 -6
- package/dist/src/web/bridges/mcp-app-bridge.js +58 -26
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -1
- package/dist/src/web/bridges/types.d.ts +40 -6
- package/dist/src/web/data-llm.js +4 -2
- package/dist/src/web/data-llm.js.map +1 -1
- package/dist/src/web/generate-helpers.test-d.js +4 -1
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/hooks/test/utils.d.ts +10 -0
- package/dist/src/web/hooks/test/utils.js +40 -0
- package/dist/src/web/hooks/test/utils.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.js +12 -4
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +26 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +3 -3
- package/dist/src/web/hooks/use-display-mode.js +3 -3
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-layout.test.js +87 -38
- package/dist/src/web/hooks/use-layout.test.js.map +1 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +3 -6
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +12 -1
- package/dist/src/web/hooks/use-tool-info.js +15 -9
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +40 -4
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +117 -47
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.js +2 -2
- package/dist/src/web/hooks/use-user.js.map +1 -1
- package/dist/src/web/hooks/use-user.test.js +83 -34
- package/dist/src/web/hooks/use-user.test.js.map +1 -1
- package/dist/src/web/plugin/transform-data-llm.js +6 -3
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/src/web/types.d.ts +2 -4
- package/dist/src/web/types.js.map +1 -1
- package/package.json +2 -1
- package/dist/src/web/bridges/apps-sdk-adapter.d.ts +0 -2
- package/dist/src/web/bridges/apps-sdk-adapter.js +0 -4
- package/dist/src/web/bridges/apps-sdk-adapter.js.map +0 -1
- package/dist/src/web/bridges/get-bridge-methods.d.ts +0 -2
- package/dist/src/web/bridges/get-bridge-methods.js +0 -8
- package/dist/src/web/bridges/get-bridge-methods.js.map +0 -1
- package/dist/src/web/bridges/mcp-app-adapter.d.ts +0 -2
- package/dist/src/web/bridges/mcp-app-adapter.js +0 -12
- package/dist/src/web/bridges/mcp-app-adapter.js.map +0 -1
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
|
|
2
|
+
export declare class AppsSdkAdaptor implements Adaptor {
|
|
3
|
+
private static instance;
|
|
4
|
+
static getInstance(): AppsSdkAdaptor;
|
|
5
|
+
static resetInstance(): void;
|
|
6
|
+
getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
|
|
7
|
+
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
8
|
+
requestDisplayMode: (mode: DisplayMode) => Promise<{
|
|
9
|
+
mode: DisplayMode;
|
|
10
|
+
}>;
|
|
11
|
+
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
12
|
+
}
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { AppsSdkBridge } from "../apps-sdk-bridge.js";
|
|
2
|
+
export class AppsSdkAdaptor {
|
|
3
|
+
static instance = null;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
if (!AppsSdkAdaptor.instance) {
|
|
6
|
+
AppsSdkAdaptor.instance = new AppsSdkAdaptor();
|
|
7
|
+
}
|
|
8
|
+
return AppsSdkAdaptor.instance;
|
|
9
|
+
}
|
|
10
|
+
static resetInstance() {
|
|
11
|
+
AppsSdkAdaptor.instance = null;
|
|
12
|
+
}
|
|
13
|
+
getExternalStore(key) {
|
|
14
|
+
const bridge = AppsSdkBridge.getInstance();
|
|
15
|
+
return {
|
|
16
|
+
subscribe: bridge.subscribe(key),
|
|
17
|
+
getSnapshot: () => bridge.getSnapshot(key),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
callTool = async (name, args) => {
|
|
21
|
+
return window.openai.callTool(name, args);
|
|
22
|
+
};
|
|
23
|
+
requestDisplayMode = (mode) => {
|
|
24
|
+
return window.openai.requestDisplayMode({ mode });
|
|
25
|
+
};
|
|
26
|
+
sendFollowUpMessage = (prompt) => {
|
|
27
|
+
return window.openai.sendFollowUpMessage({ prompt });
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
//# sourceMappingURL=apps-sdk-adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-sdk-adaptor.js","sourceRoot":"","sources":["../../../../../src/web/bridges/adaptors/apps-sdk-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAStD,MAAM,OAAO,cAAc;IACjB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAE/C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IACjC,CAAC;IAEM,gBAAgB,CACrB,GAAM;QAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;YAChC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SAC3C,CAAC;IACJ,CAAC;IAEM,QAAQ,GAAG,KAAK,EAIrB,IAAY,EACZ,IAAc,EACS,EAAE;QACzB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAyB,IAAI,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC,CAAC;IAEK,kBAAkB,GAAG,CAC1B,IAAiB,EACe,EAAE;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC;IAEK,mBAAmB,GAAG,CAAC,MAAc,EAAiB,EAAE;QAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC"}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import type { McpUiRequestDisplayModeResult } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
|
|
3
|
+
export declare class McpAppAdaptor implements Adaptor {
|
|
4
|
+
private static instance;
|
|
5
|
+
private stores;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): McpAppAdaptor;
|
|
8
|
+
static resetInstance(): void;
|
|
9
|
+
getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
|
|
10
|
+
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
11
|
+
requestDisplayMode: (mode: DisplayMode) => Promise<McpUiRequestDisplayModeResult>;
|
|
12
|
+
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
13
|
+
private initializeStores;
|
|
14
|
+
private createExternalStore;
|
|
15
|
+
}
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
import { dequal } from "dequal/lite";
|
|
2
|
+
import { McpAppBridge, } from "../mcp-app-bridge.js";
|
|
3
|
+
export class McpAppAdaptor {
|
|
4
|
+
static instance = null;
|
|
5
|
+
stores;
|
|
6
|
+
constructor() {
|
|
7
|
+
this.stores = this.initializeStores();
|
|
8
|
+
}
|
|
9
|
+
static getInstance() {
|
|
10
|
+
if (!McpAppAdaptor.instance) {
|
|
11
|
+
McpAppAdaptor.instance = new McpAppAdaptor();
|
|
12
|
+
}
|
|
13
|
+
return McpAppAdaptor.instance;
|
|
14
|
+
}
|
|
15
|
+
static resetInstance() {
|
|
16
|
+
McpAppAdaptor.instance = null;
|
|
17
|
+
}
|
|
18
|
+
getExternalStore(key) {
|
|
19
|
+
return this.stores[key];
|
|
20
|
+
}
|
|
21
|
+
callTool = async (name, args) => {
|
|
22
|
+
const bridge = McpAppBridge.getInstance();
|
|
23
|
+
const response = await bridge.request({
|
|
24
|
+
method: "tools/call",
|
|
25
|
+
params: {
|
|
26
|
+
name,
|
|
27
|
+
arguments: args ?? undefined,
|
|
28
|
+
},
|
|
29
|
+
});
|
|
30
|
+
const result = response.content
|
|
31
|
+
.filter((content) => content.type === "text")
|
|
32
|
+
.map(({ text }) => text)
|
|
33
|
+
.join("\n");
|
|
34
|
+
return {
|
|
35
|
+
content: response.content,
|
|
36
|
+
structuredContent: response.structuredContent ?? {},
|
|
37
|
+
isError: response.isError ?? false,
|
|
38
|
+
result,
|
|
39
|
+
meta: response._meta ?? {},
|
|
40
|
+
};
|
|
41
|
+
};
|
|
42
|
+
requestDisplayMode = (mode) => {
|
|
43
|
+
const bridge = McpAppBridge.getInstance();
|
|
44
|
+
if (mode !== "modal") {
|
|
45
|
+
return bridge.request({
|
|
46
|
+
method: "ui/request-display-mode",
|
|
47
|
+
params: { mode },
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
throw new Error("Modal display mode is not accessible in MCP App.");
|
|
51
|
+
};
|
|
52
|
+
sendFollowUpMessage = async (prompt) => {
|
|
53
|
+
const bridge = McpAppBridge.getInstance();
|
|
54
|
+
await bridge.request({
|
|
55
|
+
method: "ui/message",
|
|
56
|
+
params: {
|
|
57
|
+
role: "user",
|
|
58
|
+
content: [
|
|
59
|
+
{
|
|
60
|
+
type: "text",
|
|
61
|
+
text: prompt,
|
|
62
|
+
},
|
|
63
|
+
],
|
|
64
|
+
},
|
|
65
|
+
});
|
|
66
|
+
};
|
|
67
|
+
initializeStores() {
|
|
68
|
+
return {
|
|
69
|
+
theme: this.createExternalStore(["theme"], ({ theme }) => theme ?? "light"),
|
|
70
|
+
locale: this.createExternalStore(["locale"], ({ locale }) => locale ?? "en-US"),
|
|
71
|
+
safeArea: this.createExternalStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
72
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
73
|
+
})),
|
|
74
|
+
displayMode: this.createExternalStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
75
|
+
maxHeight: this.createExternalStore(["viewport"], ({ viewport }) => viewport?.maxHeight ?? window.innerHeight),
|
|
76
|
+
userAgent: this.createExternalStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
77
|
+
device: {
|
|
78
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
79
|
+
},
|
|
80
|
+
capabilities: {
|
|
81
|
+
hover: true,
|
|
82
|
+
touch: true,
|
|
83
|
+
...deviceCapabilities,
|
|
84
|
+
},
|
|
85
|
+
})),
|
|
86
|
+
toolInput: this.createExternalStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
87
|
+
toolOutput: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
88
|
+
toolResponseMetadata: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
89
|
+
};
|
|
90
|
+
}
|
|
91
|
+
createExternalStore(keys, computeSnapshot) {
|
|
92
|
+
const bridge = McpAppBridge.getInstance();
|
|
93
|
+
let cachedValue;
|
|
94
|
+
return {
|
|
95
|
+
subscribe: bridge.subscribe(keys),
|
|
96
|
+
getSnapshot: () => {
|
|
97
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
98
|
+
const newValue = computeSnapshot(context);
|
|
99
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
100
|
+
return cachedValue;
|
|
101
|
+
}
|
|
102
|
+
cachedValue = newValue;
|
|
103
|
+
return newValue;
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
//# sourceMappingURL=mcp-app-adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-app-adaptor.js","sourceRoot":"","sources":["../../../../../src/web/bridges/adaptors/mcp-app-adaptor.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EACL,YAAY,GAGb,MAAM,sBAAsB,CAAC;AAa9B,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAC7C,MAAM,CAEZ;IACF;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,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;IAChC,CAAC;IAEM,gBAAgB,CACrB,GAAM;QAEN,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC1B,CAAC;IAEM,QAAQ,GAAG,KAAK,EAIrB,IAAY,EACZ,IAAc,EACS,EAAE;QACzB,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,OAAO,CAAkC;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OpenAiProperties } from "../types.js";
|
|
2
|
-
|
|
2
|
+
import type { Bridge, Subscribe } from "./types.js";
|
|
3
|
+
export declare class AppsSdkBridge implements Bridge<OpenAiProperties> {
|
|
3
4
|
private static instance;
|
|
4
5
|
static getInstance(): AppsSdkBridge;
|
|
5
6
|
static resetInstance(): void;
|
|
6
|
-
subscribe
|
|
7
|
+
subscribe(key: keyof OpenAiProperties): Subscribe;
|
|
8
|
+
subscribe(keys: readonly (keyof OpenAiProperties)[]): Subscribe;
|
|
7
9
|
getSnapshot: <K extends keyof OpenAiProperties>(key: K) => (import("../types.js").OpenAiMethods<import("../types.js").UnknownObject> & OpenAiProperties<Record<never, unknown>, import("../types.js").UnknownObject, import("../types.js").UnknownObject, import("../types.js").UnknownObject>)[K];
|
|
8
10
|
}
|
|
@@ -16,21 +16,26 @@ export class AppsSdkBridge {
|
|
|
16
16
|
AppsSdkBridge.instance = null;
|
|
17
17
|
}
|
|
18
18
|
}
|
|
19
|
-
subscribe
|
|
20
|
-
const
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
19
|
+
subscribe(keyOrKeys) {
|
|
20
|
+
const keys = Array.isArray(keyOrKeys)
|
|
21
|
+
? keyOrKeys
|
|
22
|
+
: [keyOrKeys];
|
|
23
|
+
return (onChange) => {
|
|
24
|
+
const handleSetGlobal = (event) => {
|
|
25
|
+
const hasRelevantChange = keys.some((key) => event.detail.globals[key] !== undefined);
|
|
26
|
+
if (!hasRelevantChange) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
onChange();
|
|
30
|
+
};
|
|
31
|
+
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
32
|
+
passive: true,
|
|
33
|
+
});
|
|
34
|
+
return () => {
|
|
35
|
+
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
36
|
+
};
|
|
26
37
|
};
|
|
27
|
-
|
|
28
|
-
passive: true,
|
|
29
|
-
});
|
|
30
|
-
return () => {
|
|
31
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
32
|
-
};
|
|
33
|
-
};
|
|
38
|
+
}
|
|
34
39
|
getSnapshot = (key) => {
|
|
35
40
|
if (window.openai === undefined) {
|
|
36
41
|
throw new Error(`window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,aAAa,CAAC;
|
|
1
|
+
{"version":3,"file":"apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,sBAAsB,GAEvB,MAAM,aAAa,CAAC;AAGrB,MAAM,OAAO,aAAa;IAChB,MAAM,CAAC,QAAQ,GAAyB,IAAI,CAAC;IAE9C,MAAM,CAAC,WAAW;QACvB,IACE,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;YACxC,MAAM,CAAC,MAAM,KAAK,SAAS,EAC3B,CAAC;YACD,MAAM,IAAI,KAAK,CACb,0DAA0D,CAC3D,CAAC;QACJ,CAAC;QACD,IAAI,aAAa,CAAC,QAAQ,KAAK,IAAI,EAAE,CAAC;YACpC,aAAa,CAAC,QAAQ,GAAG,IAAI,aAAa,EAAE,CAAC;QAC/C,CAAC;QACD,OAAO,aAAa,CAAC,QAAQ,CAAC;IAChC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,IAAI,aAAa,CAAC,QAAQ,EAAE,CAAC;YAC3B,aAAa,CAAC,QAAQ,GAAG,IAAI,CAAC;QAChC,CAAC;IACH,CAAC;IAIM,SAAS,CACd,SAAuE;QAEvE,MAAM,IAAI,GAAwC,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC;YACxE,CAAC,CAAC,SAAS;YACX,CAAC,CAAC,CAAC,SAAS,CAAC,CAAC;QAChB,OAAO,CAAC,QAAoB,EAAE,EAAE;YAC9B,MAAM,eAAe,GAAG,CAAC,KAAsB,EAAE,EAAE;gBACjD,MAAM,iBAAiB,GAAG,IAAI,CAAC,IAAI,CACjC,CAAC,GAAG,EAAE,EAAE,CAAC,KAAK,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,KAAK,SAAS,CACjD,CAAC;gBACF,IAAI,CAAC,iBAAiB,EAAE,CAAC;oBACvB,OAAO;gBACT,CAAC;gBACD,QAAQ,EAAE,CAAC;YACb,CAAC,CAAC;YAEF,MAAM,CAAC,gBAAgB,CAAC,sBAAsB,EAAE,eAAe,EAAE;gBAC/D,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;YAEH,OAAO,GAAG,EAAE;gBACV,MAAM,CAAC,mBAAmB,CAAC,sBAAsB,EAAE,eAAe,CAAC,CAAC;YACtE,CAAC,CAAC;QACJ,CAAC,CAAC;IACJ,CAAC;IAEM,WAAW,GAAG,CAAmC,GAAM,EAAE,EAAE;QAChE,IAAI,MAAM,CAAC,MAAM,KAAK,SAAS,EAAE,CAAC;YAChC,MAAM,IAAI,KAAK,CACb,+EAA+E,GAAG,8CAA8C,CACjI,CAAC;QACJ,CAAC;QAED,OAAO,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC;IAC5B,CAAC,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { AppsSdkAdaptor } from "../adaptors/apps-sdk-adaptor.js";
|
|
2
|
+
import { McpAppAdaptor } from "../adaptors/mcp-app-adaptor.js";
|
|
3
|
+
export const useAdaptor = () => {
|
|
4
|
+
return window.skybridge.hostType === "apps-sdk"
|
|
5
|
+
? AppsSdkAdaptor.getInstance()
|
|
6
|
+
: McpAppAdaptor.getInstance();
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=use-adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-adaptor.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,iCAAiC,CAAC;AACjE,OAAO,EAAE,aAAa,EAAE,MAAM,gCAAgC,CAAC;AAG/D,MAAM,CAAC,MAAM,UAAU,GAAG,GAAY,EAAE;IACtC,OAAO,MAAM,CAAC,SAAS,CAAC,QAAQ,KAAK,UAAU;QAC7C,CAAC,CAAC,cAAc,CAAC,WAAW,EAAE;QAC9B,CAAC,CAAC,aAAa,CAAC,WAAW,EAAE,CAAC;AAClC,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { BridgeInterface } from "../types";
|
|
1
|
+
import type { BridgeInterface } from "../types.js";
|
|
2
2
|
export declare const useBridge: <K extends keyof BridgeInterface>(key: K) => BridgeInterface[K];
|
|
@@ -1,61 +1,8 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import {
|
|
3
|
-
import { McpAppBridge } from "../mcp-app-bridge";
|
|
4
|
-
const getDefaultValueFromMcpAppBridge = (key) => {
|
|
5
|
-
const DEFAULT_VALUES_FOR_MCP_APP_BRIDGE = {
|
|
6
|
-
theme: "light",
|
|
7
|
-
locale: "en-US",
|
|
8
|
-
displayMode: "inline",
|
|
9
|
-
safeArea: {
|
|
10
|
-
insets: {
|
|
11
|
-
top: 0,
|
|
12
|
-
right: 0,
|
|
13
|
-
bottom: 0,
|
|
14
|
-
left: 0,
|
|
15
|
-
},
|
|
16
|
-
},
|
|
17
|
-
maxHeight: window.innerHeight,
|
|
18
|
-
};
|
|
19
|
-
return DEFAULT_VALUES_FOR_MCP_APP_BRIDGE[key];
|
|
20
|
-
};
|
|
21
|
-
const getExternalStore = (key) => {
|
|
22
|
-
const defaultValue = getDefaultValueFromMcpAppBridge(key);
|
|
23
|
-
const hostType = window.skybridge.hostType;
|
|
24
|
-
if (hostType === "apps-sdk") {
|
|
25
|
-
const bridge = AppsSdkBridge.getInstance();
|
|
26
|
-
return {
|
|
27
|
-
subscribe: bridge.subscribe(key),
|
|
28
|
-
getSnapshot: () => bridge.getSnapshot(key),
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
const bridge = McpAppBridge.getInstance();
|
|
32
|
-
if (key === "safeArea") {
|
|
33
|
-
return {
|
|
34
|
-
subscribe: bridge.subscribe("safeAreaInsets"),
|
|
35
|
-
getSnapshot: () => {
|
|
36
|
-
const safeArea = bridge.getSnapshot("safeAreaInsets");
|
|
37
|
-
return safeArea
|
|
38
|
-
? { insets: safeArea }
|
|
39
|
-
: defaultValue;
|
|
40
|
-
},
|
|
41
|
-
};
|
|
42
|
-
}
|
|
43
|
-
if (key === "maxHeight") {
|
|
44
|
-
return {
|
|
45
|
-
subscribe: bridge.subscribe("viewport"),
|
|
46
|
-
getSnapshot: () => {
|
|
47
|
-
const viewport = bridge.getSnapshot("viewport");
|
|
48
|
-
return (viewport?.maxHeight ?? defaultValue);
|
|
49
|
-
},
|
|
50
|
-
};
|
|
51
|
-
}
|
|
52
|
-
return {
|
|
53
|
-
subscribe: bridge.subscribe(key),
|
|
54
|
-
getSnapshot: () => (bridge.getSnapshot(key) ?? defaultValue),
|
|
55
|
-
};
|
|
56
|
-
};
|
|
2
|
+
import { useAdaptor } from "./use-adaptor.js";
|
|
57
3
|
export const useBridge = (key) => {
|
|
58
|
-
const
|
|
4
|
+
const adaptor = useAdaptor();
|
|
5
|
+
const externalStore = adaptor.getExternalStore(key);
|
|
59
6
|
return useSyncExternalStore(externalStore.subscribe, externalStore.getSnapshot);
|
|
60
7
|
};
|
|
61
8
|
//# sourceMappingURL=use-bridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-bridge.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;
|
|
1
|
+
{"version":3,"file":"use-bridge.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAC;AAE9C,MAAM,CAAC,MAAM,SAAS,GAAG,CACvB,GAAM,EACc,EAAE;IACtB,MAAM,OAAO,GAAG,UAAU,EAAE,CAAC;IAC7B,MAAM,aAAa,GAAG,OAAO,CAAC,gBAAgB,CAAC,GAAG,CAAC,CAAC;IAEpD,OAAO,oBAAoB,CACzB,aAAa,CAAC,SAAS,EACvB,aAAa,CAAC,WAAW,CAC1B,CAAC;AACJ,CAAC,CAAC"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { type McpAppBridgeContext } from "../mcp-app-bridge.js";
|
|
2
3
|
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
3
|
-
export declare function useMcpAppBridge<K extends keyof
|
|
4
|
+
export declare function useMcpAppBridge<K extends keyof McpAppBridgeContext>(key: K, options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridgeContext[K];
|
|
4
5
|
export {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { McpAppBridge } from "../mcp-app-bridge";
|
|
2
|
+
import { McpAppBridge } from "../mcp-app-bridge.js";
|
|
3
3
|
export function useMcpAppBridge(key, options, requestTimeout) {
|
|
4
4
|
const bridge = McpAppBridge.getInstance(options, requestTimeout);
|
|
5
5
|
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-bridge.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-mcp-app-bridge.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"use-mcp-app-bridge.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-mcp-app-bridge.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAC7C,OAAO,EAAE,YAAY,EAA4B,MAAM,sBAAsB,CAAC;AAO9E,MAAM,UAAU,eAAe,CAC7B,GAAM,EACN,OAA8C,EAC9C,cAAuB;IAEvB,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,CAAC,OAAO,EAAE,cAAc,CAAC,CAAC;IACjE,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -1,41 +1,22 @@
|
|
|
1
1
|
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
2
|
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { getMcpAppHostPostMessageMock } from "../../hooks/test/utils.js";
|
|
3
4
|
import { McpAppBridge } from "../mcp-app-bridge.js";
|
|
4
5
|
import { useMcpAppBridge } from "./use-mcp-app-bridge.js";
|
|
5
6
|
describe("useMcpAppBridge", () => {
|
|
6
|
-
let mockPostMessage;
|
|
7
7
|
beforeEach(async () => {
|
|
8
|
-
mockPostMessage = vi.fn();
|
|
9
|
-
Object.defineProperty(window, "parent", {
|
|
10
|
-
value: { postMessage: mockPostMessage },
|
|
11
|
-
writable: true,
|
|
12
|
-
configurable: true,
|
|
13
|
-
});
|
|
14
8
|
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
15
9
|
McpAppBridge.resetInstance();
|
|
16
10
|
});
|
|
17
11
|
afterEach(() => {
|
|
12
|
+
vi.unstubAllGlobals();
|
|
18
13
|
vi.clearAllMocks();
|
|
19
14
|
});
|
|
20
|
-
it("should return the theme value from host context", async () => {
|
|
15
|
+
it("should return the theme value from host context and update on notification", async () => {
|
|
16
|
+
vi.stubGlobal("parent", {
|
|
17
|
+
postMessage: getMcpAppHostPostMessageMock({ theme: "light" }),
|
|
18
|
+
});
|
|
21
19
|
const { result } = renderHook(() => useMcpAppBridge("theme"));
|
|
22
|
-
const initCall = mockPostMessage.mock.calls.find((call) => call[0].method === "ui/initialize");
|
|
23
|
-
if (initCall) {
|
|
24
|
-
act(() => {
|
|
25
|
-
window.dispatchEvent(new MessageEvent("message", {
|
|
26
|
-
data: {
|
|
27
|
-
jsonrpc: "2.0",
|
|
28
|
-
id: initCall[0].id,
|
|
29
|
-
result: {
|
|
30
|
-
protocolVersion: "2025-06-18",
|
|
31
|
-
hostInfo: { name: "test-host", version: "1.0.0" },
|
|
32
|
-
hostCapabilities: {},
|
|
33
|
-
hostContext: { theme: "light" },
|
|
34
|
-
},
|
|
35
|
-
},
|
|
36
|
-
}));
|
|
37
|
-
});
|
|
38
|
-
}
|
|
39
20
|
await waitFor(() => {
|
|
40
21
|
expect(result.current).toBe("light");
|
|
41
22
|
});
|
|
@@ -45,8 +26,10 @@ describe("useMcpAppBridge", () => {
|
|
|
45
26
|
const consoleErrorSpy = vi
|
|
46
27
|
.spyOn(console, "error")
|
|
47
28
|
.mockImplementation(() => { });
|
|
29
|
+
const nonRespondingMock = vi.fn();
|
|
30
|
+
vi.stubGlobal("parent", { postMessage: nonRespondingMock });
|
|
48
31
|
renderHook(() => useMcpAppBridge("theme", undefined, 100));
|
|
49
|
-
expect(
|
|
32
|
+
expect(nonRespondingMock).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/initialize" }), "*");
|
|
50
33
|
await act(async () => {
|
|
51
34
|
await vi.advanceTimersByTimeAsync(100);
|
|
52
35
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"use-mcp-app-bridge.test.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-mcp-app-bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,
|
|
1
|
+
{"version":3,"file":"use-mcp-app-bridge.test.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-mcp-app-bridge.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,GAAG,EAAE,UAAU,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,EAAE,EAAE,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AACzE,OAAO,EAAE,4BAA4B,EAAE,MAAM,2BAA2B,CAAC;AACzE,OAAO,EAAE,YAAY,EAAE,MAAM,sBAAsB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,yBAAyB,CAAC;AAE1D,QAAQ,CAAC,iBAAiB,EAAE,GAAG,EAAE;IAC/B,UAAU,CAAC,KAAK,IAAI,EAAE;QACpB,EAAE,CAAC,UAAU,CAAC,WAAW,EAAE,EAAE,QAAQ,EAAE,SAAS,EAAE,CAAC,CAAC;QACpD,YAAY,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,EAAE,CAAC,4EAA4E,EAAE,KAA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AEF,eAAe,CAAC,WAAW,EAAE,CAAC;QAC9B,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useAdaptor } from "./hooks/use-adaptor.js";
|
|
2
2
|
export { useAppsSdkBridge } from "./hooks/use-apps-sdk-bridge.js";
|
|
3
3
|
export { useBridge } from "./hooks/use-bridge.js";
|
|
4
4
|
export { useMcpAppBridge } from "./hooks/use-mcp-app-bridge.js";
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { useAdaptor } from "./hooks/use-adaptor.js";
|
|
2
2
|
export { useAppsSdkBridge } from "./hooks/use-apps-sdk-bridge.js";
|
|
3
3
|
export { useBridge } from "./hooks/use-bridge.js";
|
|
4
4
|
export { useMcpAppBridge } from "./hooks/use-mcp-app-bridge.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,wBAAwB,CAAC;AACpD,OAAO,EAAE,gBAAgB,EAAE,MAAM,gCAAgC,CAAC;AAClE,OAAO,EAAE,SAAS,EAAE,MAAM,uBAAuB,CAAC;AAClD,OAAO,EAAE,eAAe,EAAE,MAAM,+BAA+B,CAAC"}
|
|
@@ -1,8 +1,16 @@
|
|
|
1
|
-
import type { McpUiHostContext, McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
|
|
1
|
+
import type { McpUiHostContext, McpUiInitializeRequest, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Bridge, Subscribe } from "./types.js";
|
|
2
3
|
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
3
|
-
export
|
|
4
|
+
export type McpToolState = {
|
|
5
|
+
toolInput: NonNullable<McpUiToolInputNotification["params"]["arguments"]> | null;
|
|
6
|
+
toolResult: McpUiToolResultNotification["params"] | null;
|
|
7
|
+
toolCancelled: McpUiToolCancelledNotification["params"] | null;
|
|
8
|
+
};
|
|
9
|
+
export type McpAppBridgeContext = McpUiHostContext & McpToolState;
|
|
10
|
+
export type McpAppBridgeKey = keyof McpAppBridgeContext;
|
|
11
|
+
export declare class McpAppBridge implements Bridge<McpUiHostContext> {
|
|
4
12
|
private static instance;
|
|
5
|
-
context:
|
|
13
|
+
context: McpAppBridgeContext;
|
|
6
14
|
private listeners;
|
|
7
15
|
private pendingRequests;
|
|
8
16
|
private nextId;
|
|
@@ -11,8 +19,9 @@ export declare class McpAppBridge {
|
|
|
11
19
|
private requestTimeout;
|
|
12
20
|
constructor(options: McpAppInitializationOptions, requestTimeout?: number);
|
|
13
21
|
static getInstance(options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridge;
|
|
14
|
-
subscribe
|
|
15
|
-
|
|
22
|
+
subscribe(key: McpAppBridgeKey): Subscribe;
|
|
23
|
+
subscribe(keys: readonly McpAppBridgeKey[]): Subscribe;
|
|
24
|
+
getSnapshot<K extends keyof McpAppBridgeContext>(key: K): McpAppBridgeContext[K];
|
|
16
25
|
cleanup: () => void;
|
|
17
26
|
static resetInstance(): void;
|
|
18
27
|
request<R extends {
|
|
@@ -20,7 +29,7 @@ export declare class McpAppBridge {
|
|
|
20
29
|
params?: unknown;
|
|
21
30
|
}, T>({ method, params, }: R): Promise<T>;
|
|
22
31
|
private emit;
|
|
23
|
-
private
|
|
32
|
+
private updateContext;
|
|
24
33
|
private init;
|
|
25
34
|
private handleMessage;
|
|
26
35
|
private connect;
|
|
@@ -1,7 +1,11 @@
|
|
|
1
1
|
const LATEST_PROTOCOL_VERSION = "2025-11-21";
|
|
2
2
|
export class McpAppBridge {
|
|
3
3
|
static instance = null;
|
|
4
|
-
context =
|
|
4
|
+
context = {
|
|
5
|
+
toolInput: null,
|
|
6
|
+
toolCancelled: null,
|
|
7
|
+
toolResult: null,
|
|
8
|
+
};
|
|
5
9
|
listeners = new Map();
|
|
6
10
|
pendingRequests = new Map();
|
|
7
11
|
nextId = 1;
|
|
@@ -32,14 +36,23 @@ export class McpAppBridge {
|
|
|
32
36
|
}
|
|
33
37
|
return McpAppBridge.instance;
|
|
34
38
|
}
|
|
35
|
-
subscribe
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
39
|
+
subscribe(keyOrKeys) {
|
|
40
|
+
const keys = Array.isArray(keyOrKeys) ? keyOrKeys : [keyOrKeys];
|
|
41
|
+
return (onChange) => {
|
|
42
|
+
for (const key of keys) {
|
|
43
|
+
this.listeners.set(key, new Set([...(this.listeners.get(key) || []), onChange]));
|
|
44
|
+
}
|
|
45
|
+
this.init();
|
|
46
|
+
return () => {
|
|
47
|
+
for (const key of keys) {
|
|
48
|
+
this.listeners.get(key)?.delete(onChange);
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
getSnapshot(key) {
|
|
54
|
+
return this.context[key];
|
|
55
|
+
}
|
|
43
56
|
cleanup = () => {
|
|
44
57
|
window.removeEventListener("message", this.handleMessage);
|
|
45
58
|
this.pendingRequests.forEach((request) => {
|
|
@@ -73,17 +86,16 @@ export class McpAppBridge {
|
|
|
73
86
|
listener();
|
|
74
87
|
});
|
|
75
88
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
return;
|
|
79
|
-
this.context = context;
|
|
89
|
+
updateContext(context) {
|
|
90
|
+
this.context = { ...this.context, ...context };
|
|
80
91
|
for (const key of Object.keys(context)) {
|
|
81
92
|
this.emit(key);
|
|
82
93
|
}
|
|
83
94
|
}
|
|
84
95
|
init() {
|
|
85
|
-
if (this.initialized)
|
|
96
|
+
if (this.initialized) {
|
|
86
97
|
return;
|
|
98
|
+
}
|
|
87
99
|
this.initialized = true;
|
|
88
100
|
if (typeof window === "undefined" || window.parent === window) {
|
|
89
101
|
return;
|
|
@@ -93,21 +105,41 @@ export class McpAppBridge {
|
|
|
93
105
|
}
|
|
94
106
|
handleMessage = (event) => {
|
|
95
107
|
const data = event.data;
|
|
96
|
-
if (data
|
|
108
|
+
if (data.jsonrpc !== "2.0") {
|
|
97
109
|
return;
|
|
98
|
-
|
|
99
|
-
if (
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
110
|
+
}
|
|
111
|
+
if ("id" in data) {
|
|
112
|
+
const request = this.pendingRequests.get(data.id);
|
|
113
|
+
if (request) {
|
|
114
|
+
clearTimeout(request.timeout);
|
|
115
|
+
this.pendingRequests.delete(data.id);
|
|
116
|
+
if ("error" in data) {
|
|
117
|
+
request.reject(new Error(data.error.message));
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
request.resolve(data.result);
|
|
105
121
|
}
|
|
106
|
-
request.resolve(data.result);
|
|
107
122
|
return;
|
|
108
123
|
}
|
|
109
|
-
|
|
110
|
-
|
|
124
|
+
switch (data.method) {
|
|
125
|
+
case "ui/notifications/host-context-changed":
|
|
126
|
+
this.updateContext(data.params);
|
|
127
|
+
return;
|
|
128
|
+
case "ui/notifications/tool-input":
|
|
129
|
+
this.updateContext({
|
|
130
|
+
toolInput: data.params.arguments ?? {},
|
|
131
|
+
});
|
|
132
|
+
return;
|
|
133
|
+
case "ui/notifications/tool-result":
|
|
134
|
+
this.updateContext({
|
|
135
|
+
toolResult: data.params,
|
|
136
|
+
});
|
|
137
|
+
return;
|
|
138
|
+
case "ui/notifications/tool-cancelled":
|
|
139
|
+
this.updateContext({
|
|
140
|
+
toolCancelled: data.params,
|
|
141
|
+
});
|
|
142
|
+
return;
|
|
111
143
|
}
|
|
112
144
|
};
|
|
113
145
|
async connect() {
|
|
@@ -116,7 +148,7 @@ export class McpAppBridge {
|
|
|
116
148
|
method: "ui/initialize",
|
|
117
149
|
params: this.appInitializationOptions,
|
|
118
150
|
});
|
|
119
|
-
this.
|
|
151
|
+
this.updateContext(result.hostContext);
|
|
120
152
|
this.notify({ method: "ui/notifications/initialized" });
|
|
121
153
|
}
|
|
122
154
|
catch (err) {
|