skybridge 0.0.0-dev.76a95bd → 0.0.0-dev.7753d55
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/LICENSE +21 -0
- package/dist/src/server/devtoolsStaticServer.d.ts +4 -0
- package/dist/src/server/devtoolsStaticServer.js +22 -12
- package/dist/src/server/devtoolsStaticServer.js.map +1 -1
- package/dist/src/server/templates/development.hbs +1 -1
- package/dist/src/server/templates/production.hbs +1 -1
- 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 +5 -9
- package/dist/src/web/bridges/apps-sdk-bridge.js +19 -17
- 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 +2 -8
- package/dist/src/web/bridges/hooks/use-bridge.js +4 -53
- 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 -0
- package/dist/src/web/bridges/index.js +1 -0
- package/dist/src/web/bridges/index.js.map +1 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +19 -11
- package/dist/src/web/bridges/mcp-app-bridge.js +58 -32
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -1
- package/dist/src/web/bridges/types.d.ts +54 -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-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 -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 +19 -8
- package/dist/src/web/types.js.map +1 -1
- package/package.json +16 -12
- package/dist/src/web/bridges/get-bridge.d.ts +0 -2
- package/dist/src/web/bridges/get-bridge.js +0 -8
- package/dist/src/web/bridges/get-bridge.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alpic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -2,6 +2,10 @@ import { type RequestHandler } from "express";
|
|
|
2
2
|
/**
|
|
3
3
|
* Serve the built devtools React app
|
|
4
4
|
* This router serves static files from the devtools's dist directory.
|
|
5
|
+
*
|
|
6
|
+
* **Note:** This requires `@skybridge/devtools` to be installed as a peer dependency.
|
|
7
|
+
* Install it with: `pnpm add -D @skybridge/devtools` (or `npm install -D @skybridge/devtools`)
|
|
8
|
+
*
|
|
5
9
|
* It should be installed at the application root, like so:
|
|
6
10
|
*
|
|
7
11
|
* const app = express();
|
|
@@ -1,11 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createRequire } from "node:module";
|
|
2
2
|
import path from "node:path";
|
|
3
|
-
import { fileURLToPath } from "node:url";
|
|
4
3
|
import cors from "cors";
|
|
5
4
|
import express, {} from "express";
|
|
5
|
+
const require = createRequire(import.meta.url);
|
|
6
6
|
/**
|
|
7
7
|
* Serve the built devtools React app
|
|
8
8
|
* This router serves static files from the devtools's dist directory.
|
|
9
|
+
*
|
|
10
|
+
* **Note:** This requires `@skybridge/devtools` to be installed as a peer dependency.
|
|
11
|
+
* Install it with: `pnpm add -D @skybridge/devtools` (or `npm install -D @skybridge/devtools`)
|
|
12
|
+
*
|
|
9
13
|
* It should be installed at the application root, like so:
|
|
10
14
|
*
|
|
11
15
|
* const app = express();
|
|
@@ -18,20 +22,26 @@ import express, {} from "express";
|
|
|
18
22
|
*/
|
|
19
23
|
export const devtoolsStaticServer = async () => {
|
|
20
24
|
const router = express.Router();
|
|
21
|
-
|
|
22
|
-
|
|
25
|
+
let devtoolsPath;
|
|
26
|
+
try {
|
|
27
|
+
const devtoolsPackagePath = require.resolve("@skybridge/devtools/package.json");
|
|
28
|
+
devtoolsPath = path.join(path.dirname(devtoolsPackagePath), "dist");
|
|
29
|
+
}
|
|
30
|
+
catch (error) {
|
|
31
|
+
throw new Error("@skybridge/devtools is not installed. Please install it as a dev dependency:\n" +
|
|
32
|
+
" pnpm add -D @skybridge/devtools\n" +
|
|
33
|
+
" or\n" +
|
|
34
|
+
" npm install -D @skybridge/devtools", { cause: error });
|
|
35
|
+
}
|
|
23
36
|
router.use(cors());
|
|
24
37
|
router.use(express.static(devtoolsPath));
|
|
25
38
|
router.get("/", (_req, res, next) => {
|
|
26
39
|
const indexHtmlPath = path.join(devtoolsPath, "index.html");
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
}
|
|
32
|
-
catch (error) {
|
|
33
|
-
next(error);
|
|
34
|
-
}
|
|
40
|
+
res.sendFile(indexHtmlPath, (error) => {
|
|
41
|
+
if (error) {
|
|
42
|
+
next(error);
|
|
43
|
+
}
|
|
44
|
+
});
|
|
35
45
|
});
|
|
36
46
|
return router;
|
|
37
47
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"devtoolsStaticServer.js","sourceRoot":"","sources":["../../../src/server/devtoolsStaticServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"devtoolsStaticServer.js","sourceRoot":"","sources":["../../../src/server/devtoolsStaticServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AAEvD,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAE/C;;;;;;;;;;;;;;;;GAgBG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,IAA6B,EAAE;IACtE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAChC,IAAI,YAAoB,CAAC;IACzB,IAAI,CAAC;QACH,MAAM,mBAAmB,GAAG,OAAO,CAAC,OAAO,CACzC,kCAAkC,CACnC,CAAC;QACF,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,mBAAmB,CAAC,EAAE,MAAM,CAAC,CAAC;IACtE,CAAC;IAAC,OAAO,KAAK,EAAE,CAAC;QACf,MAAM,IAAI,KAAK,CACb,gFAAgF;YAC9E,qCAAqC;YACrC,QAAQ;YACR,sCAAsC,EACxC,EAAE,KAAK,EAAE,KAAK,EAAE,CACjB,CAAC;IACJ,CAAC;IAED,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IAEnB,MAAM,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,CAAC,YAAY,CAAC,CAAC,CAAC;IAEzC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAClC,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC5D,GAAG,CAAC,QAAQ,CAAC,aAAa,EAAE,CAAC,KAAK,EAAE,EAAE;YACpC,IAAI,KAAK,EAAE,CAAC;gBACV,IAAI,CAAC,KAAK,CAAC,CAAC;YACd,CAAC;QACH,CAAC,CAAC,CAAC;IACL,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
-
<script>
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
3
3
|
<script type="module">
|
|
4
4
|
import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
|
|
5
5
|
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
-
<script>
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
3
3
|
<div id="root"></div>
|
|
4
4
|
<script type="module">
|
|
5
5
|
import('{{serverUrl}}/assets/{{widgetFile}}');
|
|
@@ -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;YACrE,MAAM,EAAE,YAAY;YACpB,MAAM,EAAE;gBACN,IAAI;gBACJ,SAAS,EAAE,IAAI,IAAI,SAAS;aAC7B;SACF,CAAC,CAAC;QAEH,MAAM,MAAM,GAAG,QAAQ,CAAC,OAAO;aAC5B,MAAM,CACL,CAAC,OAAO,E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rC;YACD,UAAU,EAAE,IAAI,CAAC,mBAAmB,CAClC,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,iBAAiB,IAAI,IAAI,CAC1D;YACD,oBAAoB,EAAE,IAAI,CAAC,mBAAmB,CAC5C,CAAC,YAAY,CAAC,EACd,CAAC,EAAE,UAAU,EAAE,EAAE,EAAE,CAAC,UAAU,EAAE,KAAK,IAAI,IAAI,CAC9C;SACF,CAAC;IACJ,CAAC;IAEO,mBAAmB,CACzB,IAAU,EACV,eAAkD;QAElD,MAAM,MAAM,GAAG,YAAY,CAAC,WAAW,EAAE,CAAC;QAC1C,IAAI,WAA0B,CAAC;QAE/B,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,IAAI,CAAC;YACjC,WAAW,EAAE,GAAG,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,14 +1,10 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
import type {
|
|
3
|
-
export declare class AppsSdkBridge implements
|
|
1
|
+
import { type OpenAiProperties } from "../types.js";
|
|
2
|
+
import type { Bridge, Subscribe } from "./types.js";
|
|
3
|
+
export declare class AppsSdkBridge implements Bridge<OpenAiProperties> {
|
|
4
4
|
private static instance;
|
|
5
5
|
static getInstance(): AppsSdkBridge;
|
|
6
6
|
static resetInstance(): void;
|
|
7
|
-
subscribe
|
|
7
|
+
subscribe(key: keyof OpenAiProperties): Subscribe;
|
|
8
|
+
subscribe(keys: readonly (keyof OpenAiProperties)[]): Subscribe;
|
|
8
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];
|
|
9
|
-
requestDisplayMode: ({ mode }: {
|
|
10
|
-
mode: DisplayMode;
|
|
11
|
-
}) => Promise<{
|
|
12
|
-
mode: DisplayMode;
|
|
13
|
-
}>;
|
|
14
10
|
}
|
|
@@ -16,29 +16,31 @@ 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.`);
|
|
37
42
|
}
|
|
38
43
|
return window.openai[key];
|
|
39
44
|
};
|
|
40
|
-
requestDisplayMode = ({ mode }) => {
|
|
41
|
-
return window.openai.requestDisplayMode({ mode });
|
|
42
|
-
};
|
|
43
45
|
}
|
|
44
46
|
//# sourceMappingURL=apps-sdk-bridge.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"apps-sdk-bridge.js","sourceRoot":"","sources":["../../../../src/web/bridges/apps-sdk-bridge.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
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,CA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
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,8 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export
|
|
3
|
-
safeArea: {
|
|
4
|
-
insets: NonNullable<McpUiHostContext["safeAreaInsets"]>;
|
|
5
|
-
};
|
|
6
|
-
maxHeight: NonNullable<NonNullable<McpUiHostContext["viewport"]>["maxHeight"]>;
|
|
7
|
-
};
|
|
8
|
-
export declare const useBridge: <K extends keyof BridgeInterface>(key: K, defaultValue?: BridgeInterface[K]) => BridgeInterface[K];
|
|
1
|
+
import type { BridgeInterface } from "../types.js";
|
|
2
|
+
export declare const useBridge: <K extends keyof BridgeInterface>(key: K) => BridgeInterface[K];
|
|
@@ -1,57 +1,8 @@
|
|
|
1
1
|
import { useSyncExternalStore } from "react";
|
|
2
|
-
import {
|
|
3
|
-
|
|
4
|
-
const
|
|
5
|
-
|
|
6
|
-
locale: "en-US",
|
|
7
|
-
displayMode: "inline",
|
|
8
|
-
safeArea: {
|
|
9
|
-
insets: {
|
|
10
|
-
top: 0,
|
|
11
|
-
right: 0,
|
|
12
|
-
bottom: 0,
|
|
13
|
-
left: 0,
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
maxHeight: window.innerHeight,
|
|
17
|
-
};
|
|
18
|
-
const getExternalStore = (key, defaultValue = DEFAULT_VALUE_FOR_MCP_APP_BRIDGE[key]) => {
|
|
19
|
-
const hostType = window.skybridge.hostType;
|
|
20
|
-
if (hostType === "apps-sdk") {
|
|
21
|
-
const bridge = AppsSdkBridge.getInstance();
|
|
22
|
-
return {
|
|
23
|
-
subscribe: bridge.subscribe(key),
|
|
24
|
-
getSnapshot: () => bridge.getSnapshot(key),
|
|
25
|
-
};
|
|
26
|
-
}
|
|
27
|
-
const bridge = McpAppBridge.getInstance();
|
|
28
|
-
if (key === "safeArea") {
|
|
29
|
-
return {
|
|
30
|
-
subscribe: bridge.subscribe("safeAreaInsets"),
|
|
31
|
-
getSnapshot: () => {
|
|
32
|
-
const safeArea = bridge.getSnapshot("safeAreaInsets");
|
|
33
|
-
return safeArea
|
|
34
|
-
? { insets: safeArea }
|
|
35
|
-
: defaultValue;
|
|
36
|
-
},
|
|
37
|
-
};
|
|
38
|
-
}
|
|
39
|
-
if (key === "maxHeight") {
|
|
40
|
-
return {
|
|
41
|
-
subscribe: bridge.subscribe("viewport"),
|
|
42
|
-
getSnapshot: () => {
|
|
43
|
-
const viewport = bridge.getSnapshot("viewport");
|
|
44
|
-
return (viewport?.maxHeight ?? defaultValue);
|
|
45
|
-
},
|
|
46
|
-
};
|
|
47
|
-
}
|
|
48
|
-
return {
|
|
49
|
-
subscribe: bridge.subscribe(key),
|
|
50
|
-
getSnapshot: () => (bridge.getSnapshot(key) ?? defaultValue),
|
|
51
|
-
};
|
|
52
|
-
};
|
|
53
|
-
export const useBridge = (key, defaultValue = DEFAULT_VALUE_FOR_MCP_APP_BRIDGE[key]) => {
|
|
54
|
-
const externalStore = getExternalStore(key, defaultValue);
|
|
2
|
+
import { useAdaptor } from "./use-adaptor.js";
|
|
3
|
+
export const useBridge = (key) => {
|
|
4
|
+
const adaptor = useAdaptor();
|
|
5
|
+
const externalStore = adaptor.getExternalStore(key);
|
|
55
6
|
return useSyncExternalStore(externalStore.subscribe, externalStore.getSnapshot);
|
|
56
7
|
};
|
|
57
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":"
|
|
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,EA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,CAAC,EACpD,GAAG,CACJ,CAAC;QAEF,MAAM,GAAG,CAAC,KAAK,IAAI,EAAE;YACnB,MAAM,EAAE,CAAC,wBAAwB,CAAC,GAAG,CAAC,CAAC;QACzC,CAAC,CAAC,CAAC;QAEH,MAAM,CAAC,eAAe,CAAC,CAAC,oBAAoB,CAC1C,IAAI,KAAK,CAAC,mBAAmB,CAAC,CAC/B,CAAC;QAEF,eAAe,CAAC,WAAW,EAAE,CAAC;QAC9B,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/bridges/index.tsx"],"names":[],"mappings":"AAAA,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
|
+
{"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"}
|