skybridge 0.0.0-dev.d9ee984 → 0.0.0-dev.db1ee0e

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 (190) hide show
  1. package/LICENSE +21 -674
  2. package/README.md +123 -1
  3. package/dist/src/server/devtoolsStaticServer.d.ts +15 -0
  4. package/dist/src/server/devtoolsStaticServer.js +38 -0
  5. package/dist/src/server/devtoolsStaticServer.js.map +1 -0
  6. package/dist/src/server/index.d.ts +5 -0
  7. package/dist/{server → src/server}/index.js +1 -1
  8. package/dist/src/server/index.js.map +1 -0
  9. package/dist/src/server/inferUtilityTypes.d.ts +64 -0
  10. package/dist/src/server/inferUtilityTypes.js +2 -0
  11. package/dist/src/server/inferUtilityTypes.js.map +1 -0
  12. package/dist/src/server/server.d.ts +73 -0
  13. package/dist/src/server/server.js +74 -0
  14. package/dist/src/server/server.js.map +1 -0
  15. package/dist/src/server/templateHelper.d.ts +15 -0
  16. package/dist/src/server/templateHelper.js +30 -0
  17. package/dist/src/server/templateHelper.js.map +1 -0
  18. package/dist/src/server/templates/development.hbs +12 -0
  19. package/dist/src/server/templates/production.hbs +6 -0
  20. package/dist/{server → src/server}/widgetsDevServer.d.ts +5 -2
  21. package/dist/{server → src/server}/widgetsDevServer.js +8 -5
  22. package/dist/src/server/widgetsDevServer.js.map +1 -0
  23. package/dist/src/test/utils.d.ts +135 -0
  24. package/dist/src/test/utils.js +242 -0
  25. package/dist/src/test/utils.js.map +1 -0
  26. package/dist/src/test/widget.test.d.ts +1 -0
  27. package/dist/src/test/widget.test.js +134 -0
  28. package/dist/src/test/widget.test.js.map +1 -0
  29. package/dist/src/web/bridges/index.d.ts +2 -0
  30. package/dist/src/web/bridges/index.js +3 -0
  31. package/dist/src/web/bridges/index.js.map +1 -0
  32. package/dist/src/web/bridges/use-apps-sdk-bridge.d.ts +2 -0
  33. package/dist/{web/use-openai-global.js → src/web/bridges/use-apps-sdk-bridge.js} +9 -5
  34. package/dist/src/web/bridges/use-apps-sdk-bridge.js.map +1 -0
  35. package/dist/src/web/bridges/use-mcp-app-bridge.d.ts +24 -0
  36. package/dist/src/web/bridges/use-mcp-app-bridge.js +123 -0
  37. package/dist/src/web/bridges/use-mcp-app-bridge.js.map +1 -0
  38. package/dist/src/web/bridges/use-mcp-app-bridge.test.d.ts +1 -0
  39. package/dist/src/web/bridges/use-mcp-app-bridge.test.js +64 -0
  40. package/dist/src/web/bridges/use-mcp-app-bridge.test.js.map +1 -0
  41. package/dist/src/web/create-store.d.ts +3 -0
  42. package/dist/src/web/create-store.js +25 -0
  43. package/dist/src/web/create-store.js.map +1 -0
  44. package/dist/src/web/create-store.test.d.ts +1 -0
  45. package/dist/src/web/create-store.test.js +70 -0
  46. package/dist/src/web/create-store.test.js.map +1 -0
  47. package/dist/src/web/data-llm.d.ts +14 -0
  48. package/dist/src/web/data-llm.js +68 -0
  49. package/dist/src/web/data-llm.js.map +1 -0
  50. package/dist/src/web/data-llm.test.d.ts +1 -0
  51. package/dist/src/web/data-llm.test.js +76 -0
  52. package/dist/src/web/data-llm.test.js.map +1 -0
  53. package/dist/src/web/generate-helpers.d.ts +115 -0
  54. package/dist/src/web/generate-helpers.js +111 -0
  55. package/dist/src/web/generate-helpers.js.map +1 -0
  56. package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
  57. package/dist/src/web/generate-helpers.test-d.js +206 -0
  58. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  59. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  60. package/dist/src/web/generate-helpers.test.js +17 -0
  61. package/dist/src/web/generate-helpers.test.js.map +1 -0
  62. package/dist/src/web/helpers/state.d.ts +7 -0
  63. package/dist/src/web/helpers/state.js +40 -0
  64. package/dist/src/web/helpers/state.js.map +1 -0
  65. package/dist/src/web/helpers/state.test.d.ts +1 -0
  66. package/dist/src/web/helpers/state.test.js +53 -0
  67. package/dist/src/web/helpers/state.test.js.map +1 -0
  68. package/dist/src/web/hooks/index.d.ts +12 -0
  69. package/dist/src/web/hooks/index.js +13 -0
  70. package/dist/src/web/hooks/index.js.map +1 -0
  71. package/dist/src/web/hooks/use-call-tool.d.ts +100 -0
  72. package/dist/src/web/hooks/use-call-tool.js +60 -0
  73. package/dist/src/web/hooks/use-call-tool.js.map +1 -0
  74. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  75. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  76. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  77. package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
  78. package/dist/src/web/hooks/use-call-tool.test.js +165 -0
  79. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
  80. package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
  81. package/dist/src/web/hooks/use-display-mode.js +7 -0
  82. package/dist/src/web/hooks/use-display-mode.js.map +1 -0
  83. package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
  84. package/dist/src/web/hooks/use-display-mode.test.js +40 -0
  85. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
  86. package/dist/src/web/hooks/use-files.d.ts +10 -0
  87. package/dist/src/web/hooks/use-files.js +7 -0
  88. package/dist/src/web/hooks/use-files.js.map +1 -0
  89. package/dist/src/web/hooks/use-files.test.d.ts +1 -0
  90. package/dist/src/web/hooks/use-files.test.js +29 -0
  91. package/dist/src/web/hooks/use-files.test.js.map +1 -0
  92. package/dist/src/web/hooks/use-locale.d.ts +1 -0
  93. package/dist/src/web/hooks/use-locale.js +5 -0
  94. package/dist/src/web/hooks/use-locale.js.map +1 -0
  95. package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
  96. package/dist/src/web/hooks/use-locale.test.js +21 -0
  97. package/dist/src/web/hooks/use-locale.test.js.map +1 -0
  98. package/dist/src/web/hooks/use-open-external.d.ts +1 -0
  99. package/dist/src/web/hooks/use-open-external.js +6 -0
  100. package/dist/src/web/hooks/use-open-external.js.map +1 -0
  101. package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
  102. package/dist/src/web/hooks/use-open-external.test.js +24 -0
  103. package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
  104. package/dist/src/web/hooks/use-openai-global.d.ts +3 -0
  105. package/dist/src/web/hooks/use-openai-global.js +6 -0
  106. package/dist/src/web/hooks/use-openai-global.js.map +1 -0
  107. package/dist/src/web/hooks/use-request-modal.d.ts +6 -0
  108. package/dist/src/web/hooks/use-request-modal.js +9 -0
  109. package/dist/src/web/hooks/use-request-modal.js.map +1 -0
  110. package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
  111. package/dist/src/web/hooks/use-request-modal.test.js +24 -0
  112. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
  113. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
  114. package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
  115. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
  116. package/dist/src/web/hooks/use-theme.d.ts +1 -0
  117. package/dist/src/web/hooks/use-theme.js +5 -0
  118. package/dist/src/web/hooks/use-theme.js.map +1 -0
  119. package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
  120. package/dist/src/web/hooks/use-theme.test.js +26 -0
  121. package/dist/src/web/hooks/use-theme.test.js.map +1 -0
  122. package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
  123. package/dist/src/web/hooks/use-tool-info.js +20 -0
  124. package/dist/src/web/hooks/use-tool-info.js.map +1 -0
  125. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  126. package/dist/src/web/hooks/use-tool-info.test-d.js +73 -0
  127. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  128. package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
  129. package/dist/src/web/hooks/use-tool-info.test.js +59 -0
  130. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
  131. package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
  132. package/dist/src/web/hooks/use-user-agent.js +5 -0
  133. package/dist/src/web/hooks/use-user-agent.js.map +1 -0
  134. package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
  135. package/dist/src/web/hooks/use-user-agent.test.js +31 -0
  136. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
  137. package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
  138. package/dist/src/web/hooks/use-widget-state.js +32 -0
  139. package/dist/src/web/hooks/use-widget-state.js.map +1 -0
  140. package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
  141. package/dist/src/web/hooks/use-widget-state.test.js +60 -0
  142. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
  143. package/dist/src/web/index.d.ts +8 -0
  144. package/dist/src/web/index.js +9 -0
  145. package/dist/src/web/index.js.map +1 -0
  146. package/dist/src/web/mount-widget.js +19 -0
  147. package/dist/src/web/mount-widget.js.map +1 -0
  148. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  149. package/dist/src/web/plugin/data-llm.test.js +81 -0
  150. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  151. package/dist/src/web/plugin/plugin.d.ts +2 -0
  152. package/dist/src/web/plugin/plugin.js +39 -0
  153. package/dist/src/web/plugin/plugin.js.map +1 -0
  154. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  155. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  156. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  157. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  158. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  159. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  160. package/dist/src/web/proxy.d.ts +1 -0
  161. package/dist/src/web/proxy.js +53 -0
  162. package/dist/src/web/proxy.js.map +1 -0
  163. package/dist/{web → src/web}/types.d.ts +56 -18
  164. package/dist/{web → src/web}/types.js +1 -0
  165. package/dist/src/web/types.js.map +1 -0
  166. package/dist/vitest.config.d.ts +2 -0
  167. package/dist/vitest.config.js +8 -0
  168. package/dist/vitest.config.js.map +1 -0
  169. package/package.json +36 -13
  170. package/dist/server/index.d.ts +0 -3
  171. package/dist/server/index.js.map +0 -1
  172. package/dist/server/middleware.d.ts +0 -3
  173. package/dist/server/middleware.js +0 -47
  174. package/dist/server/middleware.js.map +0 -1
  175. package/dist/server/server.d.ts +0 -12
  176. package/dist/server/server.js +0 -70
  177. package/dist/server/server.js.map +0 -1
  178. package/dist/server/widgetsDevServer.js.map +0 -1
  179. package/dist/web/index.d.ts +0 -4
  180. package/dist/web/index.js +0 -5
  181. package/dist/web/index.js.map +0 -1
  182. package/dist/web/mount-widget.js +0 -10
  183. package/dist/web/mount-widget.js.map +0 -1
  184. package/dist/web/types.js.map +0 -1
  185. package/dist/web/use-openai-global.d.ts +0 -2
  186. package/dist/web/use-openai-global.js.map +0 -1
  187. package/dist/web/use-tool-output.d.ts +0 -3
  188. package/dist/web/use-tool-output.js +0 -5
  189. package/dist/web/use-tool-output.js.map +0 -1
  190. /package/dist/{web → src/web}/mount-widget.d.ts +0 -0
package/README.md CHANGED
@@ -1,3 +1,125 @@
1
+ <div align="center">
2
+
3
+ <img alt="Skybridge" src="docs/static/img/github-banner.png" width="100%">
4
+
5
+ <br />
6
+
1
7
  # Skybridge
2
8
 
3
- Skybridge is a framework for building ChatGPT apps
9
+ **Build ChatGPT Apps. The Modern TypeScript Way.**
10
+
11
+ The fullstack TypeScript framework for ChatGPT Apps.<br />
12
+ **Type-safe. React-powered. Zero config.**
13
+
14
+ <br />
15
+
16
+ [![NPM Version](https://img.shields.io/npm/v/skybridge?color=e90060&style=for-the-badge)](https://www.npmjs.com/package/skybridge)
17
+ [![NPM Downloads](https://img.shields.io/npm/dm/skybridge?color=e90060&style=for-the-badge)](https://www.npmjs.com/package/skybridge)
18
+ [![GitHub License](https://img.shields.io/github/license/alpic-ai/skybridge?color=e90060&style=for-the-badge)](https://github.com/alpic-ai/skybridge/blob/main/LICENSE)
19
+
20
+ <br />
21
+
22
+ [Documentation](https://skybridge.tech) · [Quick Start](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) · [Examples](https://github.com/alpic-ai/apps-sdk-template)
23
+
24
+ </div>
25
+
26
+ <br />
27
+
28
+ ## ✨ Why Skybridge?
29
+
30
+ ChatGPT Apps let you embed **rich, interactive UIs** directly in conversations. But the raw SDK is low-level—no hooks, no type safety, no dev tools, and no HMR.
31
+
32
+ **Skybridge fixes that.**
33
+
34
+ | | |
35
+ |:--|:--|
36
+ | 👨‍💻 **Full Dev Environment** — HMR, debug traces, and local devtools. No more refresh loops. | ✅ **End-to-End Type Safety** — tRPC-style inference from server to widget. Autocomplete everywhere. |
37
+ | 🔄 **Widget-to-Model Sync** — Keep the model aware of UI state with `data-llm`. Dual surfaces, one source of truth. | ⚒️ **React Query-style Hooks** — `isPending`, `isError`, callbacks. State management you already know. |
38
+
39
+ <br />
40
+
41
+ ## 🚀 Get Started
42
+
43
+ **Create a new ChatGPT app:**
44
+
45
+ ```bash
46
+ gh repo create my-app --template alpic-ai/apps-sdk-template --clone
47
+ cd my-app && pnpm install
48
+ ```
49
+
50
+ **Or add to an existing project:**
51
+
52
+ ```bash
53
+ npm i skybridge
54
+ yarn add skybridge
55
+ pnpm add skybridge
56
+ bun add skybridge
57
+ deno add skybridge
58
+ ```
59
+
60
+ <div align="center">
61
+
62
+ **👉 [Read the Docs](https://skybridge.tech) 👈**
63
+
64
+ </div>
65
+
66
+ <br />
67
+
68
+ ## 📦 The Stack
69
+
70
+ - **`skybridge/server`** — Drop-in MCP SDK replacement with widget registration and type inference.
71
+ - **`skybridge/web`** — React hooks and components for ChatGPT's runtime.
72
+
73
+ ### Server
74
+
75
+ ```ts
76
+ import { McpServer } from "skybridge/server";
77
+
78
+ server.registerWidget("flights", {}, {
79
+ inputSchema: { destination: z.string() },
80
+ }, async ({ destination }) => {
81
+ const flights = await searchFlights(destination);
82
+ return { structuredContent: { flights } };
83
+ });
84
+ ```
85
+
86
+ ### Widget
87
+
88
+ ```tsx
89
+ import { useToolInfo } from "skybridge/web";
90
+
91
+ function FlightsWidget() {
92
+ const { output } = useToolInfo();
93
+
94
+ return output.structuredContent.flights.map(f =>
95
+ <FlightCard key={f.id} flight={f} />
96
+ );
97
+ }
98
+ ```
99
+
100
+ <br />
101
+
102
+ ## 🎯 Features at a Glance
103
+
104
+ - **Live Reload** — Vite HMR. See changes instantly without reinstalling.
105
+ - **Typed Hooks** — Full autocomplete for tools, inputs, outputs.
106
+ - **Widget → Tool Calls** — Trigger server actions from UI.
107
+ - **Dual Surface Sync** — Keep model aware of what users see with `data-llm`.
108
+ - **React Query-style API** — `isPending`, `isError`, callbacks.
109
+ - **MCP Compatible** — Extends the official SDK. Works with any MCP client.
110
+
111
+ <br />
112
+
113
+ <div align="center">
114
+
115
+ [![GitHub Discussions](https://img.shields.io/badge/Discussions-Ask%20Questions-blue?style=flat-square&logo=github)](https://github.com/alpic-ai/skybridge/discussions)
116
+ [![GitHub Issues](https://img.shields.io/badge/Issues-Report%20Bugs-red?style=flat-square&logo=github)](https://github.com/alpic-ai/skybridge/issues)
117
+ [![Discord](https://img.shields.io/badge/Discord-Chat-5865F2?style=flat-square&logo=discord&logoColor=white)](https://discord.com/invite/gNAazGueab)
118
+
119
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
120
+
121
+ <br />
122
+
123
+ **[MIT License](LICENSE)** · Made with ❤️ by **[Alpic](https://alpic.ai)**
124
+
125
+ </div>
@@ -0,0 +1,15 @@
1
+ import { type RequestHandler } from "express";
2
+ /**
3
+ * Serve the built devtools React app
4
+ * This router serves static files from the devtools's dist directory.
5
+ * It should be installed at the application root, like so:
6
+ *
7
+ * const app = express();
8
+ *
9
+ * if (env.NODE_ENV !== "production") {
10
+ * app.use(await devtoolsStaticServer(server));
11
+ * app.use(await widgetsDevServer());
12
+ * ^^^^^^^^ Make sure to install the devtoolsStaticServer before the widgetsDevServer
13
+ * }
14
+ */
15
+ export declare const devtoolsStaticServer: () => Promise<RequestHandler>;
@@ -0,0 +1,38 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import cors from "cors";
5
+ import express, {} from "express";
6
+ /**
7
+ * Serve the built devtools React app
8
+ * This router serves static files from the devtools's dist directory.
9
+ * It should be installed at the application root, like so:
10
+ *
11
+ * const app = express();
12
+ *
13
+ * if (env.NODE_ENV !== "production") {
14
+ * app.use(await devtoolsStaticServer(server));
15
+ * app.use(await widgetsDevServer());
16
+ * ^^^^^^^^ Make sure to install the devtoolsStaticServer before the widgetsDevServer
17
+ * }
18
+ */
19
+ export const devtoolsStaticServer = async () => {
20
+ const router = express.Router();
21
+ const currentDir = path.dirname(fileURLToPath(import.meta.url));
22
+ const devtoolsPath = path.join(currentDir, "..", "devtools");
23
+ router.use(cors());
24
+ router.use(express.static(devtoolsPath));
25
+ router.get("/", (_req, res, next) => {
26
+ 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
+ }
35
+ });
36
+ return router;
37
+ };
38
+ //# sourceMappingURL=devtoolsStaticServer.js.map
@@ -0,0 +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,CAAC,IAAI,EAAE,GAAG,EAAE,IAAI,EAAE,EAAE;QAClC,MAAM,aAAa,GAAG,IAAI,CAAC,IAAI,CAAC,YAAY,EAAE,YAAY,CAAC,CAAC;QAC5D,IAAI,CAAC;YACH,MAAM,SAAS,GAAG,YAAY,CAAC,aAAa,EAAE,OAAO,CAAC,CAAC;YACvD,GAAG,CAAC,SAAS,CAAC,cAAc,EAAE,WAAW,CAAC,CAAC;YAC3C,GAAG,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;QACtB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,IAAI,CAAC,KAAK,CAAC,CAAC;QACd,CAAC;IACH,CAAC,CAAC,CAAC;IAEH,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -0,0 +1,5 @@
1
+ export { devtoolsStaticServer } from "./devtoolsStaticServer.js";
2
+ export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
3
+ export type { McpServerTypes, ToolDef } from "./server.js";
4
+ export { McpServer } from "./server.js";
5
+ export { widgetsDevServer } from "./widgetsDevServer.js";
@@ -1,4 +1,4 @@
1
+ export { devtoolsStaticServer } from "./devtoolsStaticServer.js";
1
2
  export { McpServer } from "./server.js";
2
3
  export { widgetsDevServer } from "./widgetsDevServer.js";
3
- export { mcp } from "./middleware.js";
4
4
  //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAUjE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,64 @@
1
+ import type { McpServerTypes, ToolDef } from "./server.js";
2
+ /**
3
+ * Any tool registry shape (includes both widgets and regular tools).
4
+ * Used as a constraint for type parameters that accept tool registries.
5
+ */
6
+ export type AnyToolRegistry = Record<string, ToolDef>;
7
+ /**
8
+ * Extract the tool registry type from an McpServer instance.
9
+ * This includes both widgets (registered via widget()) and regular tools (registered via registerTool()).
10
+ *
11
+ * Uses the `$types` property pattern for cross-package type inference.
12
+ * This works across package boundaries because TypeScript uses structural typing
13
+ * on the shape of `$types`, rather than nominal typing on the McpServer class itself.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * type MyTools = InferTools<MyServer>;
18
+ * // { "search": ToolDef<...>, "calculate": ToolDef<...> }
19
+ * ```
20
+ */
21
+ export type InferTools<ServerType> = ServerType extends {
22
+ $types: McpServerTypes<infer W>;
23
+ } ? W : never;
24
+ type ExtractTool<ServerType, K extends ToolNames<ServerType>> = InferTools<ServerType>[K];
25
+ /**
26
+ * Get a union of all tool names from an McpServer instance.
27
+ * This includes both widgets and regular tools.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * type Names = ToolNames<MyServer>;
32
+ * // "search" | "calculate" | "details"
33
+ * ```
34
+ */
35
+ export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
36
+ /**
37
+ * Get the input type for a specific tool (widget or regular tool).
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * type SearchInput = ToolInput<MyServer, "search">;
42
+ * ```
43
+ */
44
+ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["input"];
45
+ /**
46
+ * Get the output type for a specific tool (widget or regular tool).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * type SearchOutput = ToolOutput<MyServer, "search">;
51
+ * ```
52
+ */
53
+ export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
+ /**
55
+ * Get the responseMetadata type for a specific tool (widget or regular tool).
56
+ * This is inferred from the `_meta` property of the tool callback's return value.
57
+ *
58
+ * @example
59
+ * ```ts
60
+ * type SearchMeta = ToolResponseMetadata<MyServer, "search">;
61
+ * ```
62
+ */
63
+ export type ToolResponseMetadata<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["responseMetadata"];
64
+ export {};
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inferUtilityTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
@@ -0,0 +1,73 @@
1
+ import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
3
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
4
+ import type { CallToolResult, Resource, ServerNotification, ServerRequest, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
5
+ export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
6
+ input: TInput;
7
+ output: TOutput;
8
+ responseMetadata: TResponseMetadata;
9
+ };
10
+ type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
11
+ type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
12
+ type Simplify<T> = {
13
+ [K in keyof T]: T[K];
14
+ };
15
+ type ExtractStructuredContent<T> = T extends {
16
+ structuredContent: infer SC;
17
+ } ? Simplify<SC> : never;
18
+ type ExtractMeta<T> = [Extract<T, {
19
+ _meta: unknown;
20
+ }>] extends [never] ? unknown : Extract<T, {
21
+ _meta: unknown;
22
+ }> extends {
23
+ _meta: infer M;
24
+ } ? Simplify<M> : unknown;
25
+ /**
26
+ * Type-level marker interface for cross-package type inference.
27
+ * This enables TypeScript to infer tool types across package boundaries
28
+ * using structural typing on the $types property, rather than relying on
29
+ * class generic inference which fails when McpServer comes from different
30
+ * package installations.
31
+ *
32
+ * Inspired by tRPC's _def pattern and Hono's type markers.
33
+ */
34
+ export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
35
+ readonly tools: TTools;
36
+ }
37
+ type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
38
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
39
+ } & {
40
+ [K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
41
+ }>;
42
+ type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
43
+ [K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
44
+ }>;
45
+ type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
46
+ title?: string;
47
+ description?: string;
48
+ inputSchema?: TInput;
49
+ outputSchema?: ZodRawShapeCompat | AnySchema;
50
+ annotations?: ToolAnnotations;
51
+ _meta?: Record<string, unknown>;
52
+ };
53
+ type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
54
+ content: CallToolResult["content"];
55
+ } = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
56
+ export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
57
+ readonly $types: McpServerTypes<TTools>;
58
+ registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
59
+ content: CallToolResult["content"];
60
+ }>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
61
+ inputSchema?: TInput;
62
+ outputSchema?: ZodRawShapeCompat | AnySchema;
63
+ }, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
64
+ registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
65
+ content: CallToolResult["content"];
66
+ }>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
67
+ registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
68
+ private registerWidgetResource;
69
+ private lookupDistFile;
70
+ private lookupDistFileWithIndexFallback;
71
+ private readManifest;
72
+ }
73
+ export {};
@@ -0,0 +1,74 @@
1
+ import { readFileSync } from "node:fs";
2
+ import path from "node:path";
3
+ import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
4
+ import { templateHelper } from "./templateHelper.js";
5
+ export class McpServer extends McpServerBase {
6
+ registerWidget(name, resourceConfig, toolConfig, toolCallback) {
7
+ const resourceMetadata = {
8
+ ...(resourceConfig._meta ?? {}),
9
+ };
10
+ if (toolConfig.description !== undefined) {
11
+ resourceMetadata["openai/widgetDescription"] = toolConfig.description;
12
+ }
13
+ const appsSdkResourceConfig = {
14
+ uri: `ui://widgets/apps-sdk/${name}.html`,
15
+ mimeType: "text/html+skybridge",
16
+ };
17
+ const extAppsResourceConfig = {
18
+ uri: `ui://widgets/ext-apps/${name}.html`,
19
+ mimeType: "text/html;profile=mcp-app",
20
+ };
21
+ [appsSdkResourceConfig, extAppsResourceConfig].forEach(({ uri, mimeType }) => {
22
+ this.registerWidgetResource({
23
+ name,
24
+ widgetUri: uri,
25
+ mimeType,
26
+ resourceConfig,
27
+ resourceMetadata,
28
+ });
29
+ });
30
+ const toolMeta = {
31
+ ...toolConfig._meta,
32
+ "openai/outputTemplate": appsSdkResourceConfig.uri,
33
+ // "ui/resourceUri": extAppsResourceConfig.uri,
34
+ };
35
+ this.registerTool(name, {
36
+ ...toolConfig,
37
+ _meta: toolMeta,
38
+ }, toolCallback);
39
+ return this;
40
+ }
41
+ registerTool(name, config, cb) {
42
+ super.registerTool(name, config, cb);
43
+ return this;
44
+ }
45
+ registerWidgetResource({ name, widgetUri, mimeType, resourceConfig, resourceMetadata, }) {
46
+ this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceMetadata }, async (uri, extra) => {
47
+ const serverUrl = process.env.NODE_ENV === "production"
48
+ ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
49
+ : `http://localhost:3000`;
50
+ const html = process.env.NODE_ENV === "production"
51
+ ? templateHelper.renderProduction({
52
+ serverUrl,
53
+ widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
54
+ styleFile: this.lookupDistFile("style.css"),
55
+ })
56
+ : templateHelper.renderDevelopment({ serverUrl, widgetName: name });
57
+ return { contents: [{ uri: uri.href, mimeType, text: html }] };
58
+ });
59
+ }
60
+ lookupDistFile(key) {
61
+ const manifest = this.readManifest();
62
+ return manifest[key]?.file;
63
+ }
64
+ lookupDistFileWithIndexFallback(basePath) {
65
+ const manifest = this.readManifest();
66
+ const flatFileKey = `${basePath}.tsx`;
67
+ const indexFileKey = `${basePath}/index.tsx`;
68
+ return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
69
+ }
70
+ readManifest() {
71
+ return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
72
+ }
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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"}
@@ -0,0 +1,15 @@
1
+ declare class TemplateHelper {
2
+ private templateCache;
3
+ private loadTemplate;
4
+ renderProduction(data: {
5
+ serverUrl: string;
6
+ widgetFile: string;
7
+ styleFile: string;
8
+ }): string;
9
+ renderDevelopment(data: {
10
+ serverUrl: string;
11
+ widgetName: string;
12
+ }): string;
13
+ }
14
+ export declare const templateHelper: TemplateHelper;
15
+ export {};
@@ -0,0 +1,30 @@
1
+ import { readFileSync } from "node:fs";
2
+ import { dirname, join } from "node:path";
3
+ import { fileURLToPath } from "node:url";
4
+ import Handlebars from "handlebars";
5
+ const __filename = fileURLToPath(import.meta.url);
6
+ const __dirname = dirname(__filename);
7
+ class TemplateHelper {
8
+ templateCache = new Map();
9
+ loadTemplate(templateName) {
10
+ const cached = this.templateCache.get(templateName);
11
+ if (cached) {
12
+ return cached;
13
+ }
14
+ const templatePath = join(__dirname, "templates", `${templateName}.hbs`);
15
+ const templateSource = readFileSync(templatePath, "utf-8");
16
+ const template = Handlebars.compile(templateSource);
17
+ this.templateCache.set(templateName, template);
18
+ return template;
19
+ }
20
+ renderProduction(data) {
21
+ const template = this.loadTemplate("production");
22
+ return template(data);
23
+ }
24
+ renderDevelopment(data) {
25
+ const template = this.loadTemplate("development");
26
+ return template(data);
27
+ }
28
+ }
29
+ export const templateHelper = new TemplateHelper();
30
+ //# sourceMappingURL=templateHelper.js.map
@@ -0,0 +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,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAA+C;QAC/D,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"}
@@ -0,0 +1,12 @@
1
+ <base href="{{serverUrl}}" />
2
+ <script type="module">
3
+ import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
4
+ injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
5
+ window.$RefreshSig$ = () => (type) => type;
6
+ window.__vite_plugin_react_preamble_installed__ = true;
7
+ </script>
8
+ <script type="module" src="{{serverUrl}}/@vite/client"></script>
9
+ <div id="root"></div>
10
+ <script type="module" id="dev-widget-entry">
11
+ import('{{serverUrl}}/src/widgets/{{widgetName}}');
12
+ </script>
@@ -0,0 +1,6 @@
1
+ <base href="{{serverUrl}}" />
2
+ <div id="root"></div>
3
+ <script type="module">
4
+ import('{{serverUrl}}/assets/{{widgetFile}}');
5
+ </script>
6
+ <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
@@ -1,9 +1,12 @@
1
1
  import { type RequestHandler } from "express";
2
2
  /**
3
- * Install Vite dev server when env is not production
3
+ * Install Vite dev server
4
4
  * This router MUST be installed at the application root, like so:
5
5
  *
6
6
  * const app = express();
7
- * app.use(await widgetsRouter());
7
+ *
8
+ * if (env.NODE_ENV !== "production") {
9
+ * app.use(await widgetsRouter());
10
+ * }
8
11
  */
9
12
  export declare const widgetsDevServer: () => Promise<RequestHandler>;
@@ -1,12 +1,15 @@
1
- import express, {} from "express";
2
- import cors from "cors";
3
1
  import path from "node:path";
2
+ import cors from "cors";
3
+ import express, {} from "express";
4
4
  /**
5
- * Install Vite dev server when env is not production
5
+ * Install Vite dev server
6
6
  * This router MUST be installed at the application root, like so:
7
7
  *
8
8
  * const app = express();
9
- * app.use(await widgetsRouter());
9
+ *
10
+ * if (env.NODE_ENV !== "production") {
11
+ * app.use(await widgetsRouter());
12
+ * }
10
13
  */
11
14
  export const widgetsDevServer = async () => {
12
15
  const router = express.Router();
@@ -14,7 +17,7 @@ export const widgetsDevServer = async () => {
14
17
  const workspaceRoot = searchForWorkspaceRoot(process.cwd());
15
18
  const webAppRoot = path.join(workspaceRoot, "web");
16
19
  const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
17
- // Remove build-specific options that don't apply to dev server
20
+ // biome-ignore lint/correctness/noUnusedVariables: Remove build-specific options that don't apply to dev server
18
21
  const { build, preview, ...devConfig } = configResult?.config || {};
19
22
  const vite = await createServer({
20
23
  ...devConfig,
@@ -0,0 +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,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