skybridge 0.0.0-dev.896f829 → 0.0.0-dev.897b09a
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.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/index.d.ts +1 -1
- package/dist/src/server/server.d.ts +4 -0
- package/dist/src/server/server.js +52 -28
- 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 +41 -2
- package/dist/src/server/templates/production.hbs +1 -0
- package/dist/src/server/widgetsDevServer.js +0 -1
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/widget.test.js +81 -16
- 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 +4 -1
- 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.d.ts +1 -1
- 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-d.js +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +28 -3
- 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 +25 -9
- package/dist/src/web/types.js.map +1 -1
- package/package.json +29 -29
- package/README.md +0 -123
- 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
|
@@ -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
|
export { devtoolsStaticServer } from "./devtoolsStaticServer.js";
|
|
2
2
|
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
3
|
-
export type { McpServerTypes, ToolDef } from "./server.js";
|
|
3
|
+
export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
|
|
4
4
|
export { McpServer } from "./server.js";
|
|
5
5
|
export { widgetsDevServer } from "./widgetsDevServer.js";
|
|
@@ -7,6 +7,7 @@ export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unk
|
|
|
7
7
|
output: TOutput;
|
|
8
8
|
responseMetadata: TResponseMetadata;
|
|
9
9
|
};
|
|
10
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
10
11
|
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
|
|
11
12
|
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
12
13
|
type Simplify<T> = {
|
|
@@ -65,6 +66,9 @@ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<n
|
|
|
65
66
|
content: CallToolResult["content"];
|
|
66
67
|
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
67
68
|
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
69
|
+
private registerWidgetResource;
|
|
68
70
|
private lookupDistFile;
|
|
71
|
+
private lookupDistFileWithIndexFallback;
|
|
72
|
+
private readManifest;
|
|
69
73
|
}
|
|
70
74
|
export {};
|
|
@@ -4,59 +4,83 @@ import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mc
|
|
|
4
4
|
import { templateHelper } from "./templateHelper.js";
|
|
5
5
|
export class McpServer extends McpServerBase {
|
|
6
6
|
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
7
|
-
const uri = `ui://widgets/${name}.html`;
|
|
8
7
|
const resourceMetadata = {
|
|
9
8
|
...(resourceConfig._meta ?? {}),
|
|
10
9
|
};
|
|
11
10
|
if (toolConfig.description !== undefined) {
|
|
12
11
|
resourceMetadata["openai/widgetDescription"] = toolConfig.description;
|
|
13
12
|
}
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
13
|
+
const appsSdkResourceConfig = {
|
|
14
|
+
hostType: "apps-sdk",
|
|
15
|
+
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
16
|
+
mimeType: "text/html+skybridge",
|
|
17
|
+
};
|
|
18
|
+
const extAppsResourceConfig = {
|
|
19
|
+
hostType: "mcp-app",
|
|
20
|
+
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
21
|
+
mimeType: "text/html;profile=mcp-app",
|
|
22
|
+
};
|
|
23
|
+
[appsSdkResourceConfig, extAppsResourceConfig].forEach(({ hostType, uri, mimeType }) => {
|
|
24
|
+
this.registerWidgetResource({
|
|
25
|
+
name,
|
|
26
|
+
hostType,
|
|
27
|
+
widgetUri: uri,
|
|
28
|
+
mimeType,
|
|
29
|
+
resourceConfig,
|
|
30
|
+
resourceMetadata,
|
|
31
|
+
});
|
|
32
|
+
});
|
|
33
|
+
const toolMeta = {
|
|
34
|
+
...toolConfig._meta,
|
|
35
|
+
"openai/outputTemplate": appsSdkResourceConfig.uri,
|
|
36
|
+
"ui/resourceUri": extAppsResourceConfig.uri,
|
|
37
|
+
};
|
|
38
|
+
this.registerTool(name, {
|
|
39
|
+
...toolConfig,
|
|
40
|
+
_meta: toolMeta,
|
|
41
|
+
}, toolCallback);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
registerTool(name, config, cb) {
|
|
45
|
+
super.registerTool(name, config, cb);
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
registerWidgetResource({ name, hostType, widgetUri, mimeType, resourceConfig, resourceMetadata, }) {
|
|
49
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceMetadata }, async (uri, extra) => {
|
|
18
50
|
const serverUrl = process.env.NODE_ENV === "production"
|
|
19
|
-
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
20
|
-
extra?.requestInfo?.headers?.host}`
|
|
51
|
+
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
|
|
21
52
|
: `http://localhost:3000`;
|
|
22
53
|
const html = process.env.NODE_ENV === "production"
|
|
23
54
|
? templateHelper.renderProduction({
|
|
55
|
+
hostType,
|
|
24
56
|
serverUrl,
|
|
25
|
-
widgetFile: this.
|
|
57
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
|
|
26
58
|
styleFile: this.lookupDistFile("style.css"),
|
|
27
59
|
})
|
|
28
60
|
: templateHelper.renderDevelopment({
|
|
61
|
+
hostType,
|
|
29
62
|
serverUrl,
|
|
30
63
|
widgetName: name,
|
|
31
64
|
});
|
|
32
65
|
return {
|
|
33
66
|
contents: [
|
|
34
|
-
{
|
|
35
|
-
uri,
|
|
36
|
-
mimeType: "text/html+skybridge",
|
|
37
|
-
text: html,
|
|
38
|
-
},
|
|
67
|
+
{ uri: uri.href, mimeType, text: html, _meta: resourceMetadata },
|
|
39
68
|
],
|
|
40
69
|
};
|
|
41
70
|
});
|
|
42
|
-
const toolMeta = {
|
|
43
|
-
...toolConfig._meta,
|
|
44
|
-
"openai/outputTemplate": uri,
|
|
45
|
-
"ui/resourceUri": uri,
|
|
46
|
-
};
|
|
47
|
-
this.registerTool(name, {
|
|
48
|
-
...toolConfig,
|
|
49
|
-
_meta: toolMeta,
|
|
50
|
-
}, toolCallback);
|
|
51
|
-
return this;
|
|
52
|
-
}
|
|
53
|
-
registerTool(name, config, cb) {
|
|
54
|
-
super.registerTool(name, config, cb);
|
|
55
|
-
return this;
|
|
56
71
|
}
|
|
57
72
|
lookupDistFile(key) {
|
|
58
|
-
const manifest =
|
|
73
|
+
const manifest = this.readManifest();
|
|
59
74
|
return manifest[key]?.file;
|
|
60
75
|
}
|
|
76
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
77
|
+
const manifest = this.readManifest();
|
|
78
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
79
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
80
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
81
|
+
}
|
|
82
|
+
readManifest() {
|
|
83
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
84
|
+
}
|
|
61
85
|
}
|
|
62
86
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAcjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAqIrD,MAAM,OAAO,SAEX,SAAQ,aAAa;IAGrB,cAAc,CAKZ,IAAW,EACX,cAA+C,EAC/C,UAGC,EACD,YAA0C;QAQ1C,MAAM,gBAAgB,GAAiB;YACrC,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC;SAChC,CAAC;QACF,IAAI,UAAU,CAAC,WAAW,KAAK,SAAS,EAAE,CAAC;YACzC,gBAAgB,CAAC,0BAA0B,CAAC,GAAG,UAAU,CAAC,WAAW,CAAC;QACxE,CAAC;QAED,MAAM,qBAAqB,GAAyB;YAClD,QAAQ,EAAE,UAAU;YACpB,GAAG,EAAE,yBAAyB,IAAI,OAAO;YACzC,QAAQ,EAAE,qBAAqB;SAChC,CAAC;QAEF,MAAM,qBAAqB,GAAyB;YAClD,QAAQ,EAAE,SA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AAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -1,12 +1,15 @@
|
|
|
1
|
+
import type { WidgetHostType } from "./server.js";
|
|
1
2
|
declare class TemplateHelper {
|
|
2
3
|
private templateCache;
|
|
3
4
|
private loadTemplate;
|
|
4
5
|
renderProduction(data: {
|
|
6
|
+
hostType: WidgetHostType;
|
|
5
7
|
serverUrl: string;
|
|
6
8
|
widgetFile: string;
|
|
7
9
|
styleFile: string;
|
|
8
10
|
}): string;
|
|
9
11
|
renderDevelopment(data: {
|
|
12
|
+
hostType: WidgetHostType;
|
|
10
13
|
serverUrl: string;
|
|
11
14
|
widgetName: string;
|
|
12
15
|
}): string;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,UAAU,MAAM,YAAY,CAAC;
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,IAKhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAIjB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -1,12 +1,51 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
2
3
|
<script type="module">
|
|
3
|
-
import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
|
|
4
|
+
import { injectIntoGlobalHook } from "{{serverUrl}}/assets/@react-refresh";
|
|
4
5
|
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
5
6
|
window.$RefreshSig$ = () => (type) => type;
|
|
6
7
|
window.__vite_plugin_react_preamble_installed__ = true;
|
|
7
8
|
</script>
|
|
8
9
|
<script type="module" src="{{serverUrl}}/@vite/client"></script>
|
|
10
|
+
<script type="module">
|
|
11
|
+
// Checks for browser support and shows error if local network access is denied
|
|
12
|
+
(async () => {
|
|
13
|
+
if (!navigator.permissions?.query) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
try {
|
|
18
|
+
const status = await navigator.permissions.query({ name: "local-network-access" });
|
|
19
|
+
if (status.state === "denied") {
|
|
20
|
+
const errorDiv = document.createElement("div");
|
|
21
|
+
errorDiv.style.cssText = "background: #fef2f2; border: 2px solid #ef4444; border-radius: 8px; padding: 16px; text-align: center; z-index: 10000; font-family: system-ui, sans-serif;";
|
|
22
|
+
|
|
23
|
+
const errorTitle = document.createElement("div");
|
|
24
|
+
errorTitle.style.cssText = "color: #ef4444; font-size: 18px; font-weight: 600; margin-bottom: 8px;";
|
|
25
|
+
errorTitle.textContent = "Error: Local network access permission is denied.";
|
|
26
|
+
|
|
27
|
+
const errorMessage = document.createElement("div");
|
|
28
|
+
errorMessage.style.cssText = "color: #ef4444; font-size: 14px;";
|
|
29
|
+
errorMessage.textContent = "Local network access is required for your widget to connect to the local dev server. Please enable it in your browser settings. ";
|
|
30
|
+
|
|
31
|
+
const link = document.createElement("a");
|
|
32
|
+
link.href = "https://developer.chrome.com/blog/local-network-access";
|
|
33
|
+
link.target = "_blank";
|
|
34
|
+
link.rel = "noopener noreferrer";
|
|
35
|
+
link.style.cssText = "color: #ef4444; text-decoration: underline;";
|
|
36
|
+
link.textContent = "Learn more";
|
|
37
|
+
errorMessage.appendChild(link);
|
|
38
|
+
|
|
39
|
+
errorDiv.appendChild(errorTitle);
|
|
40
|
+
errorDiv.appendChild(errorMessage);
|
|
41
|
+
document.body.appendChild(errorDiv);
|
|
42
|
+
}
|
|
43
|
+
} catch (e) {
|
|
44
|
+
// Permission API doesn't support local-network-access, ignore silently
|
|
45
|
+
}
|
|
46
|
+
})();
|
|
47
|
+
</script>
|
|
9
48
|
<div id="root"></div>
|
|
10
49
|
<script type="module" id="dev-widget-entry">
|
|
11
|
-
import('{{serverUrl}}/src/widgets/{{widgetName}}
|
|
50
|
+
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
12
51
|
</script>
|
|
@@ -17,7 +17,6 @@ export const widgetsDevServer = async () => {
|
|
|
17
17
|
const workspaceRoot = searchForWorkspaceRoot(process.cwd());
|
|
18
18
|
const webAppRoot = path.join(workspaceRoot, "web");
|
|
19
19
|
const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
|
|
20
|
-
// biome-ignore lint/correctness/noUnusedVariables: Remove build-specific options that don't apply to dev server
|
|
21
20
|
const { build, preview, ...devConfig } = configResult?.config || {};
|
|
22
21
|
const vite = await createServer({
|
|
23
22
|
...devConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;GASG;AACH,MAAM,CAAC,MAAM,gBAAgB,GAAG,KAAK,IAA6B,EAAE;IAClE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAEhC,MAAM,EAAE,YAAY,EAAE,sBAAsB,EAAE,kBAAkB,EAAE,GAChE,MAAM,MAAM,CAAC,MAAM,CAAC,CAAC;IACvB,MAAM,aAAa,GAAG,sBAAsB,CAAC,OAAO,CAAC,GAAG,EAAE,CAAC,CAAC;IAC5D,MAAM,UAAU,GAAG,IAAI,CAAC,IAAI,CAAC,aAAa,EAAE,KAAK,CAAC,CAAC;IAEnD,MAAM,YAAY,GAAG,MAAM,kBAAkB,CAC3C,EAAE,OAAO,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;QAChB,YAAY,EAAE;YACZ,OAAO,EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;SACvC;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
|
|
@@ -2,17 +2,15 @@ import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
|
2
2
|
import { createMockExtra, createMockMcpServer, resetTestEnv, setTestEnv, } from "./utils.js";
|
|
3
3
|
const mockManifest = {
|
|
4
4
|
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
5
|
+
"src/widgets/folder-widget/index.tsx": { file: "folder-widget.js" },
|
|
5
6
|
"style.css": { file: "style.css" },
|
|
6
7
|
};
|
|
7
|
-
vi.
|
|
8
|
-
|
|
8
|
+
const actual = vi.hoisted(() => require("node:fs"));
|
|
9
|
+
vi.mock("node:fs", () => {
|
|
9
10
|
const readFileSyncImpl = (path, ...args) => {
|
|
10
11
|
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
11
12
|
return JSON.stringify(mockManifest);
|
|
12
13
|
}
|
|
13
|
-
// Type assertion needed because readFileSync has overloads with different parameter types
|
|
14
|
-
// Using @ts-expect-error because the overloads are complex and we're forwarding args
|
|
15
|
-
// @ts-expect-error - readFileSync overloads require complex type handling
|
|
16
14
|
return actual.readFileSync(path, ...args);
|
|
17
15
|
};
|
|
18
16
|
const readFileSync = vi.fn(readFileSyncImpl);
|
|
@@ -42,26 +40,30 @@ describe("McpServer.registerWidget", () => {
|
|
|
42
40
|
const mockToolConfig = { description: "Test tool" };
|
|
43
41
|
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
44
42
|
// Get the resource callback function
|
|
45
|
-
const
|
|
43
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
46
44
|
.calls[0]?.[3];
|
|
47
|
-
expect(
|
|
45
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
48
46
|
const serverUrl = "http://localhost:3000";
|
|
49
47
|
const mockExtra = createMockExtra("__not_used__");
|
|
50
|
-
const result = await
|
|
48
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
|
|
51
49
|
expect(mockRegisterTool).toHaveBeenCalled();
|
|
52
50
|
expect(result).toEqual({
|
|
53
51
|
contents: [
|
|
54
52
|
{
|
|
55
|
-
uri: "ui://widgets/my-widget.html",
|
|
53
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
56
54
|
mimeType: "text/html+skybridge",
|
|
57
55
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
56
|
+
_meta: {
|
|
57
|
+
"openai/widgetDescription": "Test tool",
|
|
58
|
+
},
|
|
58
59
|
},
|
|
59
60
|
],
|
|
60
61
|
});
|
|
61
62
|
// Check development-specific content
|
|
62
|
-
expect(result.contents[0]?.text).toContain(`${serverUrl}/@react-refresh`);
|
|
63
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/@react-refresh`);
|
|
63
64
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/@vite/client`);
|
|
64
|
-
expect(result.contents[0]?.text).toContain(`${serverUrl}/src/widgets/my-widget
|
|
65
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/src/widgets/my-widget`);
|
|
66
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/src/widgets/my-widget.tsx`);
|
|
65
67
|
});
|
|
66
68
|
it("should generate correct HTML for production mode", async () => {
|
|
67
69
|
setTestEnv({ NODE_ENV: "production" });
|
|
@@ -70,26 +72,89 @@ describe("McpServer.registerWidget", () => {
|
|
|
70
72
|
const mockToolConfig = { description: "Test tool" };
|
|
71
73
|
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
72
74
|
// Get the resource callback function
|
|
73
|
-
const
|
|
75
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
74
76
|
.calls[0]?.[3];
|
|
75
|
-
expect(
|
|
77
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
76
78
|
const serverUrl = "https://myapp.com";
|
|
77
79
|
const mockExtra = createMockExtra(serverUrl);
|
|
78
|
-
const result = await
|
|
80
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
|
|
79
81
|
expect(result).toEqual({
|
|
80
82
|
contents: [
|
|
81
83
|
{
|
|
82
|
-
uri: "ui://widgets/my-widget.html",
|
|
84
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
83
85
|
mimeType: "text/html+skybridge",
|
|
84
86
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
87
|
+
_meta: {
|
|
88
|
+
"openai/widgetDescription": "Test tool",
|
|
89
|
+
},
|
|
85
90
|
},
|
|
86
91
|
],
|
|
87
92
|
});
|
|
88
93
|
// Check production-specific content
|
|
89
|
-
expect(result.contents[0]?.text).not.toContain(`${serverUrl}
|
|
94
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/assets/@react-refresh`);
|
|
90
95
|
expect(result.contents[0]?.text).not.toContain(`${serverUrl}@vite/client`);
|
|
91
96
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/my-widget.js`);
|
|
92
97
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/style.css`);
|
|
93
98
|
});
|
|
99
|
+
it("should resolve folder-based widgets (barrel files) in production mode", async () => {
|
|
100
|
+
setTestEnv({ NODE_ENV: "production" });
|
|
101
|
+
const mockToolCallback = vi.fn();
|
|
102
|
+
const mockRegisterResourceConfig = { description: "Folder widget" };
|
|
103
|
+
const mockToolConfig = { description: "Folder tool" };
|
|
104
|
+
server.registerWidget("folder-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
105
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
106
|
+
.calls[0]?.[3];
|
|
107
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
108
|
+
const serverUrl = "https://myapp.com";
|
|
109
|
+
const mockExtra = createMockExtra(serverUrl);
|
|
110
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/folder-widget.html"), mockExtra);
|
|
111
|
+
// Should resolve to folder-widget.js from the manifest entry "src/widgets/folder-widget/index.tsx"
|
|
112
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/folder-widget.js`);
|
|
113
|
+
});
|
|
114
|
+
it("should register resources with correct hostType for both apps-sdk and ext-apps formats", async () => {
|
|
115
|
+
const mockToolCallback = vi.fn();
|
|
116
|
+
const mockRegisterResourceConfig = {
|
|
117
|
+
description: "Test widget",
|
|
118
|
+
_meta: { "openai/widgetPrefersBorder": true },
|
|
119
|
+
};
|
|
120
|
+
const mockToolConfig = { description: "Test tool" };
|
|
121
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
122
|
+
expect(mockRegisterResource).toHaveBeenCalledTimes(2);
|
|
123
|
+
const appsSdkCallback = mockRegisterResource.mock
|
|
124
|
+
.calls[0]?.[3];
|
|
125
|
+
const appsSdkResult = await appsSdkCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), createMockExtra("__not_used__"));
|
|
126
|
+
expect(appsSdkResult).toEqual({
|
|
127
|
+
contents: [
|
|
128
|
+
{
|
|
129
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
130
|
+
mimeType: "text/html+skybridge",
|
|
131
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
132
|
+
_meta: {
|
|
133
|
+
"openai/widgetDescription": "Test tool",
|
|
134
|
+
"openai/widgetPrefersBorder": true,
|
|
135
|
+
},
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
});
|
|
139
|
+
expect(appsSdkResult.contents[0]?.text).toContain('window.skybridge = { hostType: "apps-sdk" }');
|
|
140
|
+
const extAppsResourceCallback = mockRegisterResource.mock
|
|
141
|
+
.calls[1]?.[3];
|
|
142
|
+
expect(extAppsResourceCallback).toBeDefined();
|
|
143
|
+
const extAppsResult = await extAppsResourceCallback(new URL("ui://widgets/ext-apps/my-widget.html"), createMockExtra("__not_used__"));
|
|
144
|
+
expect(extAppsResult).toEqual({
|
|
145
|
+
contents: [
|
|
146
|
+
{
|
|
147
|
+
uri: "ui://widgets/ext-apps/my-widget.html",
|
|
148
|
+
mimeType: "text/html;profile=mcp-app",
|
|
149
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
150
|
+
_meta: {
|
|
151
|
+
"openai/widgetDescription": "Test tool",
|
|
152
|
+
"openai/widgetPrefersBorder": true,
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
],
|
|
156
|
+
});
|
|
157
|
+
expect(extAppsResult.contents[0]?.text).toContain('window.skybridge = { hostType: "mcp-app" }');
|
|
158
|
+
});
|
|
94
159
|
});
|
|
95
160
|
//# sourceMappingURL=widget.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG;IACnB,2BAA2B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;IACrD,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;CACnC,CAAC;AAEF,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,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
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
|
+
openExternal(href: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
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
|
+
openExternal(href) {
|
|
30
|
+
window.openai.openExternal({ href });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# 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;IAEK,YAAY,CAAC,IAAY;QAC9B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
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
|
+
openExternal(href: string): void;
|
|
14
|
+
private initializeStores;
|
|
15
|
+
private createExternalStore;
|
|
16
|
+
}
|