skybridge 0.0.0-dev.896f829 → 0.0.0-dev.8a803c9

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.
Files changed (132) hide show
  1. package/dist/src/server/devtoolsStaticServer.d.ts +4 -0
  2. package/dist/src/server/devtoolsStaticServer.js +22 -12
  3. package/dist/src/server/devtoolsStaticServer.js.map +1 -1
  4. package/dist/src/server/index.d.ts +1 -1
  5. package/dist/src/server/server.d.ts +4 -0
  6. package/dist/src/server/server.js +51 -31
  7. package/dist/src/server/server.js.map +1 -1
  8. package/dist/src/server/templateHelper.d.ts +3 -0
  9. package/dist/src/server/templateHelper.js.map +1 -1
  10. package/dist/src/server/templates/development.hbs +2 -1
  11. package/dist/src/server/templates/production.hbs +1 -0
  12. package/dist/src/server/widgetsDevServer.js +0 -1
  13. package/dist/src/server/widgetsDevServer.js.map +1 -1
  14. package/dist/src/test/widget.test.js +60 -9
  15. package/dist/src/test/widget.test.js.map +1 -1
  16. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
  17. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -0
  18. package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
  19. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +16 -0
  20. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
  21. package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
  22. package/dist/src/web/bridges/apps-sdk-bridge.d.ts +10 -0
  23. package/dist/src/web/bridges/apps-sdk-bridge.js +46 -0
  24. package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -0
  25. package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
  26. package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
  27. package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
  28. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.d.ts +2 -0
  29. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js +7 -0
  30. package/dist/src/web/bridges/hooks/use-apps-sdk-bridge.js.map +1 -0
  31. package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -0
  32. package/dist/src/web/bridges/hooks/use-bridge.js +8 -0
  33. package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -0
  34. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +5 -0
  35. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +7 -0
  36. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -0
  37. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +41 -0
  38. package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -0
  39. package/dist/src/web/bridges/index.d.ts +4 -0
  40. package/dist/src/web/bridges/index.js +5 -0
  41. package/dist/src/web/bridges/index.js.map +1 -0
  42. package/dist/src/web/bridges/mcp-app-bridge.d.ts +38 -0
  43. package/dist/src/web/bridges/mcp-app-bridge.js +162 -0
  44. package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -0
  45. package/dist/src/web/bridges/types.d.ts +57 -0
  46. package/dist/src/web/bridges/types.js +2 -0
  47. package/dist/src/web/bridges/types.js.map +1 -0
  48. package/dist/src/web/data-llm.js +4 -2
  49. package/dist/src/web/data-llm.js.map +1 -1
  50. package/dist/src/web/generate-helpers.test-d.js +4 -1
  51. package/dist/src/web/generate-helpers.test-d.js.map +1 -1
  52. package/dist/src/web/hooks/index.d.ts +2 -3
  53. package/dist/src/web/hooks/index.js +2 -3
  54. package/dist/src/web/hooks/index.js.map +1 -1
  55. package/dist/src/web/hooks/test/utils.d.ts +10 -0
  56. package/dist/src/web/hooks/test/utils.js +40 -0
  57. package/dist/src/web/hooks/test/utils.js.map +1 -0
  58. package/dist/src/web/hooks/use-call-tool.js +12 -4
  59. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  60. package/dist/src/web/hooks/use-call-tool.test.js +26 -0
  61. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  62. package/dist/src/web/hooks/use-display-mode.d.ts +1 -1
  63. package/dist/src/web/hooks/use-display-mode.js +6 -3
  64. package/dist/src/web/hooks/use-display-mode.js.map +1 -1
  65. package/dist/src/web/hooks/use-display-mode.test.js +1 -0
  66. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
  67. package/dist/src/web/hooks/use-layout.d.ts +22 -0
  68. package/dist/src/web/hooks/use-layout.js +23 -0
  69. package/dist/src/web/hooks/use-layout.js.map +1 -0
  70. package/dist/src/web/hooks/use-layout.test.js +95 -0
  71. package/dist/src/web/hooks/use-layout.test.js.map +1 -0
  72. package/dist/src/web/hooks/use-open-external.js +5 -3
  73. package/dist/src/web/hooks/use-open-external.js.map +1 -1
  74. package/dist/src/web/hooks/use-open-external.test.js +41 -15
  75. package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
  76. package/dist/src/web/hooks/use-openai-global.d.ts +2 -1
  77. package/dist/src/web/hooks/use-openai-global.js +3 -22
  78. package/dist/src/web/hooks/use-openai-global.js.map +1 -1
  79. package/dist/src/web/hooks/use-request-modal.d.ts +6 -3
  80. package/dist/src/web/hooks/use-request-modal.js +6 -1
  81. package/dist/src/web/hooks/use-request-modal.js.map +1 -1
  82. package/dist/src/web/hooks/use-request-modal.test.js +35 -2
  83. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
  84. package/dist/src/web/hooks/use-send-follow-up-message.js +3 -6
  85. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
  86. package/dist/src/web/hooks/use-tool-info.d.ts +12 -1
  87. package/dist/src/web/hooks/use-tool-info.js +15 -9
  88. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  89. package/dist/src/web/hooks/use-tool-info.test-d.js +40 -4
  90. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
  91. package/dist/src/web/hooks/use-tool-info.test.js +117 -46
  92. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  93. package/dist/src/web/hooks/use-user.d.ts +18 -0
  94. package/dist/src/web/hooks/use-user.js +19 -0
  95. package/dist/src/web/hooks/use-user.js.map +1 -0
  96. package/dist/src/web/hooks/use-user.test.js +93 -0
  97. package/dist/src/web/hooks/use-user.test.js.map +1 -0
  98. package/dist/src/web/hooks/use-widget-state.js +2 -2
  99. package/dist/src/web/hooks/use-widget-state.js.map +1 -1
  100. package/dist/src/web/hooks/use-widget-state.test.js +1 -0
  101. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
  102. package/dist/src/web/index.d.ts +1 -0
  103. package/dist/src/web/index.js +1 -0
  104. package/dist/src/web/index.js.map +1 -1
  105. package/dist/src/web/plugin/plugin.js +10 -4
  106. package/dist/src/web/plugin/plugin.js.map +1 -1
  107. package/dist/src/web/plugin/transform-data-llm.js +6 -3
  108. package/dist/src/web/plugin/transform-data-llm.js.map +1 -1
  109. package/dist/src/web/proxy.js +5 -0
  110. package/dist/src/web/proxy.js.map +1 -1
  111. package/dist/src/web/types.d.ts +24 -8
  112. package/dist/src/web/types.js.map +1 -1
  113. package/package.json +19 -18
  114. package/README.md +0 -123
  115. package/dist/src/web/hooks/use-locale.d.ts +0 -1
  116. package/dist/src/web/hooks/use-locale.js +0 -5
  117. package/dist/src/web/hooks/use-locale.js.map +0 -1
  118. package/dist/src/web/hooks/use-locale.test.js +0 -21
  119. package/dist/src/web/hooks/use-locale.test.js.map +0 -1
  120. package/dist/src/web/hooks/use-theme.d.ts +0 -1
  121. package/dist/src/web/hooks/use-theme.js +0 -5
  122. package/dist/src/web/hooks/use-theme.js.map +0 -1
  123. package/dist/src/web/hooks/use-theme.test.js +0 -26
  124. package/dist/src/web/hooks/use-theme.test.js.map +0 -1
  125. package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
  126. package/dist/src/web/hooks/use-user-agent.js +0 -5
  127. package/dist/src/web/hooks/use-user-agent.js.map +0 -1
  128. package/dist/src/web/hooks/use-user-agent.test.js +0 -31
  129. package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
  130. /package/dist/src/web/{hooks/use-locale.test.d.ts → bridges/hooks/use-mcp-app-bridge.test.d.ts} +0 -0
  131. /package/dist/src/web/hooks/{use-theme.test.d.ts → use-layout.test.d.ts} +0 -0
  132. /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 { readFileSync } from "node:fs";
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
- const currentDir = path.dirname(fileURLToPath(import.meta.url));
22
- const devtoolsPath = path.join(currentDir, "..", "devtools");
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
- try {
28
- const indexHtml = readFileSync(indexHtmlPath, "utf-8");
29
- res.setHeader("Content-Type", "text/html");
30
- res.send(indexHtml);
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,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AAEvD;;;;;;;;;;;;GAYG;AACH,MAAM,CAAC,MAAM,oBAAoB,GAAG,KAAK,IAA6B,EAAE;IACtE,MAAM,MAAM,GAAG,OAAO,CAAC,MAAM,EAAE,CAAC;IAChC,MAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC;IAChE,MAAM,YAAY,GAAG,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,IAAI,EAAE,UAAU,CAAC,CAAC;IAE7D,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,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,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,45 +4,36 @@ 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
- this.registerResource(name, uri, {
15
- ...resourceConfig,
16
- _meta: resourceMetadata,
17
- }, async (_uri, extra) => {
18
- const serverUrl = process.env.NODE_ENV === "production"
19
- ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
20
- extra?.requestInfo?.headers?.host}`
21
- : `http://localhost:3000`;
22
- const html = process.env.NODE_ENV === "production"
23
- ? templateHelper.renderProduction({
24
- serverUrl,
25
- widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
26
- styleFile: this.lookupDistFile("style.css"),
27
- })
28
- : templateHelper.renderDevelopment({
29
- serverUrl,
30
- widgetName: name,
31
- });
32
- return {
33
- contents: [
34
- {
35
- uri,
36
- mimeType: "text/html+skybridge",
37
- text: html,
38
- },
39
- ],
40
- };
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
+ });
41
32
  });
42
33
  const toolMeta = {
43
34
  ...toolConfig._meta,
44
- "openai/outputTemplate": uri,
45
- "ui/resourceUri": uri,
35
+ "openai/outputTemplate": appsSdkResourceConfig.uri,
36
+ "ui/resourceUri": extAppsResourceConfig.uri,
46
37
  };
47
38
  this.registerTool(name, {
48
39
  ...toolConfig,
@@ -54,9 +45,38 @@ export class McpServer extends McpServerBase {
54
45
  super.registerTool(name, config, cb);
55
46
  return this;
56
47
  }
48
+ registerWidgetResource({ name, hostType, widgetUri, mimeType, resourceConfig, resourceMetadata, }) {
49
+ this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceMetadata }, async (uri, extra) => {
50
+ const serverUrl = process.env.NODE_ENV === "production"
51
+ ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
52
+ : `http://localhost:3000`;
53
+ const html = process.env.NODE_ENV === "production"
54
+ ? templateHelper.renderProduction({
55
+ hostType,
56
+ serverUrl,
57
+ widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
58
+ styleFile: this.lookupDistFile("style.css"),
59
+ })
60
+ : templateHelper.renderDevelopment({
61
+ hostType,
62
+ serverUrl,
63
+ widgetName: name,
64
+ });
65
+ return { contents: [{ uri: uri.href, mimeType, text: html }] };
66
+ });
67
+ }
57
68
  lookupDistFile(key) {
58
- const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
69
+ const manifest = this.readManifest();
59
70
  return manifest[key]?.file;
60
71
  }
72
+ lookupDistFileWithIndexFallback(basePath) {
73
+ const manifest = this.readManifest();
74
+ const flatFileKey = `${basePath}.tsx`;
75
+ const indexFileKey = `${basePath}/index.tsx`;
76
+ return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
77
+ }
78
+ readManifest() {
79
+ return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
80
+ }
61
81
  }
62
82
  //# 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;AA6HrD,MAAM,OAAO,SAEX,SAAQ,aAAa;IAGrB,cAAc,CAKZ,IAAW,EACX,cAA+C,EAC/C,UAGC,EACD,YAA0C;QAQ1C,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,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,IAAI,CAAC,gBAAgB,CACnB,IAAI,EACJ,GAAG,EACH;YACE,GAAG,cAAc;YACjB,KAAK,EAAE,gBAAgB;SACxB,EACD,KAAK,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE;YACpB,MAAM,S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BACT,UAAU,EAAE,IAAI,CAAC,+BAA+B,CAC9C,eAAe,IAAI,EAAE,CACtB;oBACD,SAAS,EAAE,IAAI,CAAC,cAAc,CAAC,WAAW,CAAC;iBAC5C,CAAC;gBACJ,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC;oBAC/B,QAAQ;oBACR,SAAS;oBACT,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;YAET,OAAO,EAAE,QAAQ,EAAE,CAAC,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,CAAC,EAAE,CAAC;QACjE,CAAC,CACF,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;IAEO,+BAA+B,CAAC,QAAgB;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAErC,MAAM,WAAW,GAAG,GAAG,QAAQ,MAAM,CAAC;QACtC,MAAM,YAAY,GAAG,GAAG,QAAQ,YAAY,CAAC;QAC7C,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IACrE,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CACf,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,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;AAEpC,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,IAIhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,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AKhB;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,4 +1,5 @@
1
1
  <base href="{{serverUrl}}" />
2
+ <script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
2
3
  <script type="module">
3
4
  import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
4
5
  injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
@@ -8,5 +9,5 @@
8
9
  <script type="module" src="{{serverUrl}}/@vite/client"></script>
9
10
  <div id="root"></div>
10
11
  <script type="module" id="dev-widget-entry">
11
- import('{{serverUrl}}/src/widgets/{{widgetName}}.tsx');
12
+ import('{{serverUrl}}/src/widgets/{{widgetName}}');
12
13
  </script>
@@ -1,4 +1,5 @@
1
1
  <base href="{{serverUrl}}" />
2
+ <script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
2
3
  <div id="root"></div>
3
4
  <script type="module">
4
5
  import('{{serverUrl}}/assets/{{widgetFile}}');
@@ -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":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AY,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,6 +2,7 @@ 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
8
  vi.mock("node:fs", async () => {
@@ -42,17 +43,17 @@ describe("McpServer.registerWidget", () => {
42
43
  const mockToolConfig = { description: "Test tool" };
43
44
  server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
44
45
  // Get the resource callback function
45
- const resourceCallback = mockRegisterResource.mock
46
+ const appsSdkResourceCallback = mockRegisterResource.mock
46
47
  .calls[0]?.[3];
47
- expect(resourceCallback).toBeDefined();
48
+ expect(appsSdkResourceCallback).toBeDefined();
48
49
  const serverUrl = "http://localhost:3000";
49
50
  const mockExtra = createMockExtra("__not_used__");
50
- const result = await resourceCallback(new URL("ui://widgets/my-widget.html"), mockExtra);
51
+ const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
51
52
  expect(mockRegisterTool).toHaveBeenCalled();
52
53
  expect(result).toEqual({
53
54
  contents: [
54
55
  {
55
- uri: "ui://widgets/my-widget.html",
56
+ uri: "ui://widgets/apps-sdk/my-widget.html",
56
57
  mimeType: "text/html+skybridge",
57
58
  text: expect.stringContaining('<div id="root"></div>'),
58
59
  },
@@ -61,7 +62,8 @@ describe("McpServer.registerWidget", () => {
61
62
  // Check development-specific content
62
63
  expect(result.contents[0]?.text).toContain(`${serverUrl}/@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.tsx`);
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,16 +72,16 @@ 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 resourceCallback = mockRegisterResource.mock
75
+ const appsSdkResourceCallback = mockRegisterResource.mock
74
76
  .calls[0]?.[3];
75
- expect(resourceCallback).toBeDefined();
77
+ expect(appsSdkResourceCallback).toBeDefined();
76
78
  const serverUrl = "https://myapp.com";
77
79
  const mockExtra = createMockExtra(serverUrl);
78
- const result = await resourceCallback(new URL("ui://widgets/my-widget.html"), mockExtra);
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>'),
85
87
  },
@@ -91,5 +93,54 @@ describe("McpServer.registerWidget", () => {
91
93
  expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/my-widget.js`);
92
94
  expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/style.css`);
93
95
  });
96
+ it("should resolve folder-based widgets (barrel files) in production mode", async () => {
97
+ setTestEnv({ NODE_ENV: "production" });
98
+ const mockToolCallback = vi.fn();
99
+ const mockRegisterResourceConfig = { description: "Folder widget" };
100
+ const mockToolConfig = { description: "Folder tool" };
101
+ server.registerWidget("folder-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
102
+ const appsSdkResourceCallback = mockRegisterResource.mock
103
+ .calls[0]?.[3];
104
+ expect(appsSdkResourceCallback).toBeDefined();
105
+ const serverUrl = "https://myapp.com";
106
+ const mockExtra = createMockExtra(serverUrl);
107
+ const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/folder-widget.html"), mockExtra);
108
+ // Should resolve to folder-widget.js from the manifest entry "src/widgets/folder-widget/index.tsx"
109
+ expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/folder-widget.js`);
110
+ });
111
+ it("should register resources with correct hostType for both apps-sdk and ext-apps formats", async () => {
112
+ const mockToolCallback = vi.fn();
113
+ const mockRegisterResourceConfig = { description: "Test widget" };
114
+ const mockToolConfig = { description: "Test tool" };
115
+ server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
116
+ expect(mockRegisterResource).toHaveBeenCalledTimes(2);
117
+ const appsSdkCallback = mockRegisterResource.mock
118
+ .calls[0]?.[3];
119
+ const appsSdkResult = await appsSdkCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), createMockExtra("__not_used__"));
120
+ expect(appsSdkResult).toEqual({
121
+ contents: [
122
+ {
123
+ uri: "ui://widgets/apps-sdk/my-widget.html",
124
+ mimeType: "text/html+skybridge",
125
+ text: expect.stringContaining('<div id="root"></div>'),
126
+ },
127
+ ],
128
+ });
129
+ expect(appsSdkResult.contents[0]?.text).toContain('window.skybridge = { hostType: "apps-sdk" }');
130
+ const extAppsResourceCallback = mockRegisterResource.mock
131
+ .calls[1]?.[3];
132
+ expect(extAppsResourceCallback).toBeDefined();
133
+ const extAppsResult = await extAppsResourceCallback(new URL("ui://widgets/ext-apps/my-widget.html"), createMockExtra("__not_used__"));
134
+ expect(extAppsResult).toEqual({
135
+ contents: [
136
+ {
137
+ uri: "ui://widgets/ext-apps/my-widget.html",
138
+ mimeType: "text/html;profile=mcp-app",
139
+ text: expect.stringContaining('<div id="root"></div>'),
140
+ },
141
+ ],
142
+ });
143
+ expect(extAppsResult.contents[0]?.text).toContain('window.skybridge = { hostType: "mcp-app" }');
144
+ });
94
145
  });
95
146
  //# 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,IAAI,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IAC5B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,YAAY,CAA2B,SAAS,CAAC,CAAC;IAC1E,MAAM,gBAAgB,GAAG,CACvB,IAA+C,EAC/C,GAAG,IAAe,EACsB,EAAE;QAC1C,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAEjC,CAAC;QACJ,CAAC;QACD,0FAA0F;QAC1F,qFAAqF;QACrF,0EAA0E;QAC1E,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC;IACF,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,gBAAgB,CAA+B,CAAC;IAE3E,OAAO;QACL,YAAY;QACZ,OAAO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,IAAI,CAAC,CAAC,SAAS,CAC/C,6CAA6C,CAC9C,CAAC;QAEF,MAAM,uBAAuB,GAAG,oBAAoB,CAAC,IAAI;aACtD,KAAK,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAKb,CAAC;QACH,MAAM,CAAC,uBAAuB,CAAC,CAAC,WAAW,EAAE,CAAC;QAE9C,MAAM,aAAa,GAAG,MAAM,uBAAuB,CACjD,IAAI,GAAG,CAAC,sCAAsC,CAAC,EAC/C,eAAe,CAAC,cAAc,CAG7B,CACF,CAAC;QAEF,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC;YAC5B,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,sCAAsC;oBAC3C,QAAQ,EAAE,2BAA2B;oBACrC,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;iBACvD;aACF;SACF,CAAC,CAAC;QACH,MAAM,CAAC,aAAa,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CAC/C,4CAA4C,CAC7C,CAAC;IACJ,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,13 @@
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
+ 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
+ }
@@ -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