skybridge 0.0.0-dev.fc2b7e8 → 0.0.0-dev.fc31237
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/server/devtoolsStaticServer.js +4 -9
- package/dist/src/server/devtoolsStaticServer.js.map +1 -1
- package/dist/src/server/index.d.ts +1 -1
- package/dist/src/server/server.d.ts +21 -9
- package/dist/src/server/server.js +51 -31
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +3 -0
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +2 -1
- package/dist/src/server/templates/production.hbs +1 -0
- package/dist/src/server/widgetsDevServer.js +14 -3
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/utils.d.ts +11 -0
- package/dist/src/test/utils.js +20 -0
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +60 -9
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -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 +16 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +10 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js +46 -0
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -0
- 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-apps-sdk-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-bridge.js +8 -0
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +5 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +7 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +41 -0
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -0
- package/dist/src/web/bridges/index.d.ts +4 -0
- package/dist/src/web/bridges/index.js +5 -0
- package/dist/src/web/bridges/index.js.map +1 -0
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +38 -0
- package/dist/src/web/bridges/mcp-app-bridge.js +162 -0
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -0
- package/dist/src/web/bridges/types.d.ts +57 -0
- package/dist/src/web/bridges/types.js +2 -0
- package/dist/src/web/bridges/types.js.map +1 -0
- 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 +31 -2
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +2 -3
- package/dist/src/web/hooks/index.js +2 -3
- package/dist/src/web/hooks/index.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 +1 -1
- package/dist/src/web/hooks/use-display-mode.js +6 -3
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/src/web/hooks/use-layout.d.ts +22 -0
- package/dist/src/web/hooks/use-layout.js +23 -0
- package/dist/src/web/hooks/use-layout.js.map +1 -0
- package/dist/src/web/hooks/use-layout.test.js +95 -0
- package/dist/src/web/hooks/use-layout.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.js +5 -3
- package/dist/src/web/hooks/use-open-external.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.test.js +41 -15
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +2 -1
- package/dist/src/web/hooks/use-openai-global.js +3 -22
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +6 -3
- package/dist/src/web/hooks/use-request-modal.js +6 -1
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.test.js +35 -2
- package/dist/src/web/hooks/use-request-modal.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 -46
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.d.ts +18 -0
- package/dist/src/web/hooks/use-user.js +19 -0
- package/dist/src/web/hooks/use-user.js.map +1 -0
- package/dist/src/web/hooks/use-user.test.js +93 -0
- package/dist/src/web/hooks/use-user.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.js +2 -2
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/index.d.ts +1 -0
- package/dist/src/web/index.js +1 -0
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin/plugin.js +10 -4
- package/dist/src/web/plugin/plugin.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/proxy.js +5 -0
- package/dist/src/web/proxy.js.map +1 -1
- package/dist/src/web/types.d.ts +24 -8
- package/dist/src/web/types.js.map +1 -1
- package/package.json +18 -12
- package/LICENSE +0 -21
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- /package/dist/src/web/{hooks/use-locale.test.d.ts → bridges/hooks/use-mcp-app-bridge.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-theme.test.d.ts → use-layout.test.d.ts} +0 -0
- /package/dist/src/web/hooks/{use-user-agent.test.d.ts → use-user.test.d.ts} +0 -0
|
@@ -0,0 +1,115 @@
|
|
|
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
|
+
openExternal(href) {
|
|
68
|
+
const bridge = McpAppBridge.getInstance();
|
|
69
|
+
bridge.request({
|
|
70
|
+
method: "ui/open-link",
|
|
71
|
+
params: { url: href },
|
|
72
|
+
});
|
|
73
|
+
}
|
|
74
|
+
initializeStores() {
|
|
75
|
+
return {
|
|
76
|
+
theme: this.createExternalStore(["theme"], ({ theme }) => theme ?? "light"),
|
|
77
|
+
locale: this.createExternalStore(["locale"], ({ locale }) => locale ?? "en-US"),
|
|
78
|
+
safeArea: this.createExternalStore(["safeAreaInsets"], ({ safeAreaInsets }) => ({
|
|
79
|
+
insets: safeAreaInsets ?? { top: 0, right: 0, bottom: 0, left: 0 },
|
|
80
|
+
})),
|
|
81
|
+
displayMode: this.createExternalStore(["displayMode"], ({ displayMode }) => displayMode ?? "inline"),
|
|
82
|
+
maxHeight: this.createExternalStore(["viewport"], ({ viewport }) => viewport?.maxHeight ?? window.innerHeight),
|
|
83
|
+
userAgent: this.createExternalStore(["platform", "deviceCapabilities"], ({ platform, deviceCapabilities }) => ({
|
|
84
|
+
device: {
|
|
85
|
+
type: platform === "web" ? "desktop" : (platform ?? "unknown"),
|
|
86
|
+
},
|
|
87
|
+
capabilities: {
|
|
88
|
+
hover: true,
|
|
89
|
+
touch: true,
|
|
90
|
+
...deviceCapabilities,
|
|
91
|
+
},
|
|
92
|
+
})),
|
|
93
|
+
toolInput: this.createExternalStore(["toolInput"], ({ toolInput }) => toolInput ?? null),
|
|
94
|
+
toolOutput: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?.structuredContent ?? null),
|
|
95
|
+
toolResponseMetadata: this.createExternalStore(["toolResult"], ({ toolResult }) => toolResult?._meta ?? null),
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
createExternalStore(keys, computeSnapshot) {
|
|
99
|
+
const bridge = McpAppBridge.getInstance();
|
|
100
|
+
let cachedValue;
|
|
101
|
+
return {
|
|
102
|
+
subscribe: bridge.subscribe(keys),
|
|
103
|
+
getSnapshot: () => {
|
|
104
|
+
const context = Object.fromEntries(keys.map((k) => [k, bridge.getSnapshot(k)]));
|
|
105
|
+
const newValue = computeSnapshot(context);
|
|
106
|
+
if (cachedValue !== undefined && dequal(cachedValue, newValue)) {
|
|
107
|
+
return cachedValue;
|
|
108
|
+
}
|
|
109
|
+
cachedValue = newValue;
|
|
110
|
+
return newValue;
|
|
111
|
+
},
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
//# 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":"AAYA,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;IACh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AAO,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"}
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { type OpenAiProperties } from "../types.js";
|
|
2
|
+
import type { Bridge, Subscribe } from "./types.js";
|
|
3
|
+
export declare class AppsSdkBridge implements Bridge<OpenAiProperties> {
|
|
4
|
+
private static instance;
|
|
5
|
+
static getInstance(): AppsSdkBridge;
|
|
6
|
+
static resetInstance(): void;
|
|
7
|
+
subscribe(key: keyof OpenAiProperties): Subscribe;
|
|
8
|
+
subscribe(keys: readonly (keyof OpenAiProperties)[]): Subscribe;
|
|
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];
|
|
10
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
import { SET_GLOBALS_EVENT_TYPE, } from "../types.js";
|
|
2
|
+
export class AppsSdkBridge {
|
|
3
|
+
static instance = null;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
if (window.skybridge.hostType !== "apps-sdk" ||
|
|
6
|
+
window.openai === undefined) {
|
|
7
|
+
throw new Error("Apps SDK Bridge can only be used in the apps-sdk runtime");
|
|
8
|
+
}
|
|
9
|
+
if (AppsSdkBridge.instance === null) {
|
|
10
|
+
AppsSdkBridge.instance = new AppsSdkBridge();
|
|
11
|
+
}
|
|
12
|
+
return AppsSdkBridge.instance;
|
|
13
|
+
}
|
|
14
|
+
static resetInstance() {
|
|
15
|
+
if (AppsSdkBridge.instance) {
|
|
16
|
+
AppsSdkBridge.instance = null;
|
|
17
|
+
}
|
|
18
|
+
}
|
|
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
|
+
};
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
getSnapshot = (key) => {
|
|
40
|
+
if (window.openai === undefined) {
|
|
41
|
+
throw new Error(`window.openai is not available. Make sure you're calling the hook requiring ${key} within the OpenAI iFrame skybridge runtime.`);
|
|
42
|
+
}
|
|
43
|
+
return window.openai[key];
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=apps-sdk-bridge.js.map
|
|
@@ -0,0 +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;AAGrB,MAAM,OAAO,aAAa;IAChB,MAAM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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"}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { AppsSdkBridge } from "../apps-sdk-bridge.js";
|
|
3
|
+
export function useAppsSdkBridge(key) {
|
|
4
|
+
const bridge = AppsSdkBridge.getInstance();
|
|
5
|
+
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=use-apps-sdk-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../../src/web/bridges/hooks/use-apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,OAAO,CAAC;AAE7C,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAEtD,MAAM,UAAU,gBAAgB,CAC9B,GAAM;IAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;IAC3C,OAAO,oBAAoB,CAAC,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,GAAG,EAAE,CACtD,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC,CACxB,CAAC;AACJ,CAAC"}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { useAdaptor } from "./use-adaptor.js";
|
|
3
|
+
export const useBridge = (key) => {
|
|
4
|
+
const adaptor = useAdaptor();
|
|
5
|
+
const externalStore = adaptor.getExternalStore(key);
|
|
6
|
+
return useSyncExternalStore(externalStore.subscribe, externalStore.getSnapshot);
|
|
7
|
+
};
|
|
8
|
+
//# sourceMappingURL=use-bridge.js.map
|
|
@@ -0,0 +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;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"}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import type { McpUiInitializeRequest } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { type McpAppBridgeContext } from "../mcp-app-bridge.js";
|
|
3
|
+
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
4
|
+
export declare function useMcpAppBridge<K extends keyof McpAppBridgeContext>(key: K, options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridgeContext[K];
|
|
5
|
+
export {};
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { useSyncExternalStore } from "react";
|
|
2
|
+
import { McpAppBridge } from "../mcp-app-bridge.js";
|
|
3
|
+
export function useMcpAppBridge(key, options, requestTimeout) {
|
|
4
|
+
const bridge = McpAppBridge.getInstance(options, requestTimeout);
|
|
5
|
+
return useSyncExternalStore(bridge.subscribe(key), () => bridge.getSnapshot(key));
|
|
6
|
+
}
|
|
7
|
+
//# sourceMappingURL=use-mcp-app-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { act, renderHook, waitFor } from "@testing-library/react";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
+
import { getMcpAppHostPostMessageMock } from "../../hooks/test/utils.js";
|
|
4
|
+
import { McpAppBridge } from "../mcp-app-bridge.js";
|
|
5
|
+
import { useMcpAppBridge } from "./use-mcp-app-bridge.js";
|
|
6
|
+
describe("useMcpAppBridge", () => {
|
|
7
|
+
beforeEach(async () => {
|
|
8
|
+
vi.stubGlobal("skybridge", { hostType: "mcp-app" });
|
|
9
|
+
McpAppBridge.resetInstance();
|
|
10
|
+
});
|
|
11
|
+
afterEach(() => {
|
|
12
|
+
vi.unstubAllGlobals();
|
|
13
|
+
vi.clearAllMocks();
|
|
14
|
+
});
|
|
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
|
+
});
|
|
19
|
+
const { result } = renderHook(() => useMcpAppBridge("theme"));
|
|
20
|
+
await waitFor(() => {
|
|
21
|
+
expect(result.current).toBe("light");
|
|
22
|
+
});
|
|
23
|
+
});
|
|
24
|
+
it("should reject the request after timeout", async () => {
|
|
25
|
+
vi.useFakeTimers();
|
|
26
|
+
const consoleErrorSpy = vi
|
|
27
|
+
.spyOn(console, "error")
|
|
28
|
+
.mockImplementation(() => { });
|
|
29
|
+
const nonRespondingMock = vi.fn();
|
|
30
|
+
vi.stubGlobal("parent", { postMessage: nonRespondingMock });
|
|
31
|
+
renderHook(() => useMcpAppBridge("theme", undefined, 100));
|
|
32
|
+
expect(nonRespondingMock).toHaveBeenCalledWith(expect.objectContaining({ method: "ui/initialize" }), "*");
|
|
33
|
+
await act(async () => {
|
|
34
|
+
await vi.advanceTimersByTimeAsync(100);
|
|
35
|
+
});
|
|
36
|
+
expect(consoleErrorSpy).toHaveBeenCalledWith(new Error("Request timed out"));
|
|
37
|
+
consoleErrorSpy.mockRestore();
|
|
38
|
+
vi.useRealTimers();
|
|
39
|
+
});
|
|
40
|
+
});
|
|
41
|
+
//# sourceMappingURL=use-mcp-app-bridge.test.js.map
|
|
@@ -0,0 +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,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,KAAK,IAAI,EAAE;QAC1F,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE;YACtB,WAAW,EAAE,4BAA4B,CAAC,EAAE,KAAK,EAAE,OAAO,EAAE,CAAC;SAC9D,CAAC,CAAC;QACH,M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1
|
+
export { useAdaptor } from "./hooks/use-adaptor.js";
|
|
2
|
+
export { useAppsSdkBridge } from "./hooks/use-apps-sdk-bridge.js";
|
|
3
|
+
export { useBridge } from "./hooks/use-bridge.js";
|
|
4
|
+
export { useMcpAppBridge } from "./hooks/use-mcp-app-bridge.js";
|
|
5
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type { McpUiHostContext, McpUiInitializeRequest, McpUiToolCancelledNotification, McpUiToolInputNotification, McpUiToolResultNotification } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Bridge, Subscribe } from "./types.js";
|
|
3
|
+
type McpAppInitializationOptions = Pick<McpUiInitializeRequest["params"], "appInfo">;
|
|
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> {
|
|
12
|
+
private static instance;
|
|
13
|
+
context: McpAppBridgeContext;
|
|
14
|
+
private listeners;
|
|
15
|
+
private pendingRequests;
|
|
16
|
+
private nextId;
|
|
17
|
+
private initialized;
|
|
18
|
+
private appInitializationOptions;
|
|
19
|
+
private requestTimeout;
|
|
20
|
+
constructor(options: McpAppInitializationOptions, requestTimeout?: number);
|
|
21
|
+
static getInstance(options?: Partial<McpAppInitializationOptions>, requestTimeout?: number): McpAppBridge;
|
|
22
|
+
subscribe(key: McpAppBridgeKey): Subscribe;
|
|
23
|
+
subscribe(keys: readonly McpAppBridgeKey[]): Subscribe;
|
|
24
|
+
getSnapshot<K extends keyof McpAppBridgeContext>(key: K): McpAppBridgeContext[K];
|
|
25
|
+
cleanup: () => void;
|
|
26
|
+
static resetInstance(): void;
|
|
27
|
+
request<R extends {
|
|
28
|
+
method: string;
|
|
29
|
+
params?: unknown;
|
|
30
|
+
}, T>({ method, params, }: R): Promise<T>;
|
|
31
|
+
private emit;
|
|
32
|
+
private updateContext;
|
|
33
|
+
private init;
|
|
34
|
+
private handleMessage;
|
|
35
|
+
private connect;
|
|
36
|
+
private notify;
|
|
37
|
+
}
|
|
38
|
+
export {};
|
|
@@ -0,0 +1,162 @@
|
|
|
1
|
+
const LATEST_PROTOCOL_VERSION = "2025-11-21";
|
|
2
|
+
export class McpAppBridge {
|
|
3
|
+
static instance = null;
|
|
4
|
+
context = {
|
|
5
|
+
toolInput: null,
|
|
6
|
+
toolCancelled: null,
|
|
7
|
+
toolResult: null,
|
|
8
|
+
};
|
|
9
|
+
listeners = new Map();
|
|
10
|
+
pendingRequests = new Map();
|
|
11
|
+
nextId = 1;
|
|
12
|
+
initialized;
|
|
13
|
+
appInitializationOptions;
|
|
14
|
+
requestTimeout;
|
|
15
|
+
constructor(options, requestTimeout = 10_000) {
|
|
16
|
+
this.requestTimeout = requestTimeout;
|
|
17
|
+
this.initialized = false;
|
|
18
|
+
this.appInitializationOptions = {
|
|
19
|
+
appInfo: options.appInfo,
|
|
20
|
+
appCapabilities: {},
|
|
21
|
+
protocolVersion: LATEST_PROTOCOL_VERSION,
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
static getInstance(options, requestTimeout) {
|
|
25
|
+
if (window.skybridge.hostType !== "mcp-app") {
|
|
26
|
+
throw new Error("MCP App Bridge can only be used in the mcp-app runtime");
|
|
27
|
+
}
|
|
28
|
+
if (McpAppBridge.instance && (options || requestTimeout)) {
|
|
29
|
+
console.warn("McpAppBridge.getInstance: options and requestTimeout ignored, instance already exists");
|
|
30
|
+
}
|
|
31
|
+
if (!McpAppBridge.instance) {
|
|
32
|
+
const defaultOptions = {
|
|
33
|
+
appInfo: { name: "skybridge-app", version: "0.0.1" },
|
|
34
|
+
};
|
|
35
|
+
McpAppBridge.instance = new McpAppBridge({ ...defaultOptions, ...options }, requestTimeout);
|
|
36
|
+
}
|
|
37
|
+
return McpAppBridge.instance;
|
|
38
|
+
}
|
|
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
|
+
}
|
|
56
|
+
cleanup = () => {
|
|
57
|
+
window.removeEventListener("message", this.handleMessage);
|
|
58
|
+
this.pendingRequests.forEach((request) => {
|
|
59
|
+
clearTimeout(request.timeout);
|
|
60
|
+
});
|
|
61
|
+
this.pendingRequests.clear();
|
|
62
|
+
this.listeners.clear();
|
|
63
|
+
};
|
|
64
|
+
static resetInstance() {
|
|
65
|
+
if (McpAppBridge.instance) {
|
|
66
|
+
McpAppBridge.instance.cleanup();
|
|
67
|
+
McpAppBridge.instance = null;
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
request({ method, params, }) {
|
|
71
|
+
const id = this.nextId++;
|
|
72
|
+
const { promise, resolve, reject } = Promise.withResolvers();
|
|
73
|
+
this.pendingRequests.set(id, {
|
|
74
|
+
resolve: resolve,
|
|
75
|
+
reject,
|
|
76
|
+
timeout: setTimeout(() => {
|
|
77
|
+
reject(new Error("Request timed out"));
|
|
78
|
+
this.pendingRequests.delete(id);
|
|
79
|
+
}, this.requestTimeout),
|
|
80
|
+
});
|
|
81
|
+
window.parent.postMessage({ jsonrpc: "2.0", id, method, params }, "*");
|
|
82
|
+
return promise;
|
|
83
|
+
}
|
|
84
|
+
emit(key) {
|
|
85
|
+
this.listeners.get(key)?.forEach((listener) => {
|
|
86
|
+
listener();
|
|
87
|
+
});
|
|
88
|
+
}
|
|
89
|
+
updateContext(context) {
|
|
90
|
+
this.context = { ...this.context, ...context };
|
|
91
|
+
for (const key of Object.keys(context)) {
|
|
92
|
+
this.emit(key);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
init() {
|
|
96
|
+
if (this.initialized) {
|
|
97
|
+
return;
|
|
98
|
+
}
|
|
99
|
+
this.initialized = true;
|
|
100
|
+
if (typeof window === "undefined" || window.parent === window) {
|
|
101
|
+
return;
|
|
102
|
+
}
|
|
103
|
+
window.addEventListener("message", this.handleMessage);
|
|
104
|
+
this.connect();
|
|
105
|
+
}
|
|
106
|
+
handleMessage = (event) => {
|
|
107
|
+
const data = event.data;
|
|
108
|
+
if (data.jsonrpc !== "2.0") {
|
|
109
|
+
return;
|
|
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);
|
|
121
|
+
}
|
|
122
|
+
return;
|
|
123
|
+
}
|
|
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;
|
|
143
|
+
}
|
|
144
|
+
};
|
|
145
|
+
async connect() {
|
|
146
|
+
try {
|
|
147
|
+
const result = await this.request({
|
|
148
|
+
method: "ui/initialize",
|
|
149
|
+
params: this.appInitializationOptions,
|
|
150
|
+
});
|
|
151
|
+
this.updateContext(result.hostContext);
|
|
152
|
+
this.notify({ method: "ui/notifications/initialized" });
|
|
153
|
+
}
|
|
154
|
+
catch (err) {
|
|
155
|
+
console.error(err);
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
notify(notification) {
|
|
159
|
+
window.parent.postMessage({ jsonrpc: "2.0", ...notification }, "*");
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
//# sourceMappingURL=mcp-app-bridge.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mcp-app-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/mcp-app-bridge.ts"],"names":[],"mappings":"AAmCA,MAAM,uBAAuB,GAAG,YAAY,CAAC;AAqB7C,MAAM,OAAO,YAAY;IACf,MAAM,CAAC,QAAQ,GAAwB,IAAI,CAAC;IAC7C,OAAO,GAAwB;QACpC,SAAS,EAAE,IAAI;QACf,aAAa,EAAE,IAAI;QACnB,UAAU,EAAE,IAAI;KACjB,CAAC;IACM,SAAS,GAAG,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AI,CAAC,aAAa,CAAC;oBACjB,UAAU,EAAE,IAAI,CAAC,MAAM;iBACxB,CAAC,CAAC;gBACH,OAAO;YACT,KAAK,iCAAiC;gBACpC,IAAI,CAAC,aAAa,CAAC;oBACjB,aAAa,EAAE,IAAI,CAAC,MAAM;iBAC3B,CAAC,CAAC;gBACH,OAAO;QACX,CAAC;IACH,CAAC,CAAC;IAEM,KAAK,CAAC,OAAO;QACnB,IAAI,CAAC;YACH,MAAM,MAAM,GAAG,MAAM,IAAI,CAAC,OAAO,CAG/B;gBACA,MAAM,EAAE,eAAe;gBACvB,MAAM,EAAE,IAAI,CAAC,wBAAwB;aACtC,CAAC,CAAC;YAEH,IAAI,CAAC,aAAa,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;YACvC,IAAI,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,8BAA8B,EAAE,CAAC,CAAC;QAC1D,CAAC;QAAC,OAAO,GAAG,EAAE,CAAC;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACrB,CAAC;IACH,CAAC;IAEO,MAAM,CAAC,YAA0C;QACvD,MAAM,CAAC,MAAM,CAAC,WAAW,CAAC,EAAE,OAAO,EAAE,KAAK,EAAE,GAAG,YAAY,EAAE,EAAE,GAAG,CAAC,CAAC;IACtE,CAAC"}
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import type { CallToolResult } from "@modelcontextprotocol/sdk/types.js";
|
|
2
|
+
import type { useSyncExternalStore } from "react";
|
|
3
|
+
export type CallToolArgs = Record<string, unknown> | null;
|
|
4
|
+
export type CallToolResponse = {
|
|
5
|
+
content: CallToolResult["content"];
|
|
6
|
+
structuredContent: NonNullable<CallToolResult["structuredContent"]>;
|
|
7
|
+
isError: NonNullable<CallToolResult["isError"]>;
|
|
8
|
+
result: string;
|
|
9
|
+
meta: NonNullable<CallToolResult["_meta"]>;
|
|
10
|
+
};
|
|
11
|
+
export type DisplayMode = "pip" | "inline" | "fullscreen" | "modal";
|
|
12
|
+
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
13
|
+
export interface BridgeInterface {
|
|
14
|
+
theme: "light" | "dark";
|
|
15
|
+
locale: string;
|
|
16
|
+
displayMode: DisplayMode;
|
|
17
|
+
safeArea: {
|
|
18
|
+
insets: {
|
|
19
|
+
top: number;
|
|
20
|
+
right: number;
|
|
21
|
+
bottom: number;
|
|
22
|
+
left: number;
|
|
23
|
+
};
|
|
24
|
+
};
|
|
25
|
+
maxHeight: number;
|
|
26
|
+
userAgent: {
|
|
27
|
+
device: {
|
|
28
|
+
type: DeviceType;
|
|
29
|
+
};
|
|
30
|
+
capabilities: {
|
|
31
|
+
hover: boolean;
|
|
32
|
+
touch: boolean;
|
|
33
|
+
};
|
|
34
|
+
};
|
|
35
|
+
toolInput: Record<string, unknown> | null;
|
|
36
|
+
toolOutput: Record<string, unknown> | null;
|
|
37
|
+
toolResponseMetadata: Record<string, unknown> | null;
|
|
38
|
+
}
|
|
39
|
+
export type Subscribe = Parameters<typeof useSyncExternalStore>[0];
|
|
40
|
+
export interface Bridge<Context> {
|
|
41
|
+
subscribe(key: keyof Context): Subscribe;
|
|
42
|
+
subscribe(keys: readonly (keyof Context)[]): Subscribe;
|
|
43
|
+
getSnapshot<K extends keyof Context>(key: K): Context[K] | undefined;
|
|
44
|
+
}
|
|
45
|
+
export type ExternalStore<K extends keyof BridgeInterface> = {
|
|
46
|
+
subscribe: Subscribe;
|
|
47
|
+
getSnapshot: () => BridgeInterface[K];
|
|
48
|
+
};
|
|
49
|
+
export interface Adaptor {
|
|
50
|
+
getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
|
|
51
|
+
callTool<ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs): Promise<ToolResponse>;
|
|
52
|
+
requestDisplayMode(mode: DisplayMode): Promise<{
|
|
53
|
+
mode: DisplayMode;
|
|
54
|
+
}>;
|
|
55
|
+
sendFollowUpMessage(prompt: string): Promise<void>;
|
|
56
|
+
openExternal(href: string): void;
|
|
57
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../../src/web/bridges/types.ts"],"names":[],"mappings":""}
|
package/dist/src/web/data-llm.js
CHANGED
|
@@ -42,8 +42,9 @@ function getLLMDescriptionString() {
|
|
|
42
42
|
const byParent = new Map();
|
|
43
43
|
for (const node of Array.from(nodes.values())) {
|
|
44
44
|
const key = node.parentId ?? null;
|
|
45
|
-
if (!byParent.has(key))
|
|
45
|
+
if (!byParent.has(key)) {
|
|
46
46
|
byParent.set(key, []);
|
|
47
|
+
}
|
|
47
48
|
byParent.get(key)?.push(node);
|
|
48
49
|
}
|
|
49
50
|
for (const list of byParent.values()) {
|
|
@@ -52,8 +53,9 @@ function getLLMDescriptionString() {
|
|
|
52
53
|
const lines = [];
|
|
53
54
|
function traverseTree(parentId, depth) {
|
|
54
55
|
const children = byParent.get(parentId);
|
|
55
|
-
if (!children)
|
|
56
|
+
if (!children) {
|
|
56
57
|
return;
|
|
58
|
+
}
|
|
57
59
|
for (const child of children) {
|
|
58
60
|
if (child.content?.trim()) {
|
|
59
61
|
const indent = " ".repeat(depth);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../../src/web/data-llm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EAEb,UAAU,EACV,SAAS,EACT,KAAK,GACN,MAAM,OAAO,CAAC;AAUf,MAAM,CAAC,MAAM,kBAAkB,GAAG,kBAA2B,CAAC;AAE9D,MAAM,KAAK,GAAG,IAAI,GAAG,EAAuB,CAAC;AAE7C,SAAS,OAAO,CAAC,IAAiB;IAChC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,EAAE,IAAI,CAAC,CAAC;IACzB,QAAQ,EAAE,CAAC;AACb,CAAC;AAED,SAAS,UAAU,CAAC,EAAU;IAC5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