skybridge 0.0.0-dev.bef3542 → 0.0.0-dev.befb8f5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -674
- package/README.md +74 -147
- package/dist/src/server/devtoolsStaticServer.d.ts +15 -0
- package/dist/src/server/devtoolsStaticServer.js +38 -0
- package/dist/src/server/devtoolsStaticServer.js.map +1 -0
- package/dist/src/server/index.d.ts +3 -0
- package/dist/src/server/index.js +1 -0
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/inferUtilityTypes.d.ts +64 -0
- package/dist/src/server/inferUtilityTypes.js +2 -0
- package/dist/src/server/inferUtilityTypes.js.map +1 -0
- package/dist/src/server/server.d.ts +61 -9
- package/dist/src/server/server.js +50 -34
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.js +5 -4
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +2 -2
- package/dist/src/server/widgetsDevServer.js +3 -3
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/utils.d.ts +97 -1
- package/dist/src/test/utils.js +182 -3
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +43 -21
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/create-store.d.ts +3 -0
- package/dist/src/web/create-store.js +25 -0
- package/dist/src/web/create-store.js.map +1 -0
- package/dist/src/web/create-store.test.d.ts +1 -0
- package/dist/src/web/create-store.test.js +70 -0
- package/dist/src/web/create-store.test.js.map +1 -0
- package/dist/src/web/data-llm.d.ts +14 -0
- package/dist/src/web/data-llm.js +68 -0
- package/dist/src/web/data-llm.js.map +1 -0
- package/dist/src/web/data-llm.test.d.ts +1 -0
- package/dist/src/web/data-llm.test.js +76 -0
- package/dist/src/web/data-llm.test.js.map +1 -0
- package/dist/src/web/generate-helpers.d.ts +115 -0
- package/dist/src/web/generate-helpers.js +111 -0
- package/dist/src/web/generate-helpers.js.map +1 -0
- package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/src/web/generate-helpers.test-d.js +180 -0
- package/dist/src/web/generate-helpers.test-d.js.map +1 -0
- package/dist/src/web/generate-helpers.test.d.ts +1 -0
- package/dist/src/web/generate-helpers.test.js +17 -0
- package/dist/src/web/generate-helpers.test.js.map +1 -0
- package/dist/src/web/helpers/state.d.ts +7 -0
- package/dist/src/web/helpers/state.js +40 -0
- package/dist/src/web/helpers/state.js.map +1 -0
- package/dist/src/web/helpers/state.test.d.ts +1 -0
- package/dist/src/web/helpers/state.test.js +53 -0
- package/dist/src/web/helpers/state.test.js.map +1 -0
- 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/use-call-tool.d.ts +58 -20
- package/dist/src/web/hooks/use-call-tool.js +7 -15
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +14 -12
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.test.js +2 -2
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
- package/dist/src/web/hooks/use-files.d.ts +10 -0
- package/dist/src/web/hooks/use-files.js +7 -0
- package/dist/src/web/hooks/use-files.js.map +1 -0
- package/dist/src/web/hooks/use-files.test.d.ts +1 -0
- package/dist/src/web/hooks/use-files.test.js +29 -0
- package/dist/src/web/hooks/use-files.test.js.map +1 -0
- package/dist/src/web/hooks/use-locale.js.map +1 -1
- package/dist/src/web/hooks/use-locale.test.js +2 -2
- package/dist/src/web/hooks/use-locale.test.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.test.js +2 -2
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +2 -2
- package/dist/src/web/hooks/use-openai-global.js +7 -5
- package/dist/src/web/hooks/use-openai-global.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +3 -2
- package/dist/src/web/hooks/use-request-modal.js.map +1 -1
- package/dist/src/web/hooks/use-request-modal.test.js +2 -2
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
- package/dist/src/web/hooks/use-theme.js.map +1 -1
- package/dist/src/web/hooks/use-theme.test.js +2 -2
- package/dist/src/web/hooks/use-theme.test.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +4 -4
- package/dist/src/web/hooks/use-tool-info.js +4 -6
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +2 -2
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user-agent.js.map +1 -1
- package/dist/src/web/hooks/use-user-agent.test.js +2 -2
- package/dist/src/web/hooks/use-user-agent.test.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.js +9 -7
- package/dist/src/web/hooks/use-widget-state.js.map +1 -1
- package/dist/src/web/hooks/use-widget-state.test.js +2 -2
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
- package/dist/src/web/index.d.ts +6 -3
- package/dist/src/web/index.js +6 -3
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/data-llm.test.js +81 -0
- package/dist/src/web/plugin/data-llm.test.js.map +1 -0
- package/dist/src/web/plugin/plugin.js +39 -0
- package/dist/src/web/plugin/plugin.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/src/web/plugin/transform-data-llm.js +93 -0
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
- package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/src/web/proxy.js +2 -2
- package/dist/src/web/proxy.js.map +1 -1
- package/dist/src/web/types.d.ts +42 -20
- package/dist/src/web/types.js +1 -0
- package/dist/src/web/types.js.map +1 -1
- package/package.json +14 -6
- package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-output.js +0 -9
- package/dist/src/web/hooks/use-tool-output.js.map +0 -1
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
- package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
- package/dist/src/web/plugin.js +0 -28
- package/dist/src/web/plugin.js.map +0 -1
- /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -1,198 +1,125 @@
|
|
|
1
1
|
<div align="center">
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
**Skybridge is the TypeScript framework for building ChatGPT apps**
|
|
6
|
-
|
|
7
|
-
[](https://alpic.ai)
|
|
3
|
+
<img alt="Skybridge" src="docs/static/img/github-banner.png" width="100%">
|
|
8
4
|
|
|
9
|
-
|
|
10
|
-

|
|
11
|
-

|
|
5
|
+
<br />
|
|
12
6
|
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
Skybridge comes with 2 packages:
|
|
7
|
+
# Skybridge
|
|
16
8
|
|
|
17
|
-
|
|
18
|
-
- `skybridge/web`: A react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
|
|
9
|
+
**Build ChatGPT Apps. The Modern TypeScript Way.**
|
|
19
10
|
|
|
20
|
-
|
|
11
|
+
The fullstack TypeScript framework for ChatGPT Apps.<br />
|
|
12
|
+
**Type-safe. React-powered. Zero config.**
|
|
21
13
|
|
|
22
|
-
|
|
14
|
+
<br />
|
|
23
15
|
|
|
24
|
-
|
|
16
|
+
[](https://www.npmjs.com/package/skybridge)
|
|
17
|
+
[](https://www.npmjs.com/package/skybridge)
|
|
18
|
+
[](https://github.com/alpic-ai/skybridge/blob/main/LICENSE)
|
|
25
19
|
|
|
26
|
-
|
|
27
|
-
pnpm add skybridge
|
|
28
|
-
```
|
|
20
|
+
<br />
|
|
29
21
|
|
|
30
|
-
|
|
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)
|
|
31
23
|
|
|
32
|
-
|
|
24
|
+
</div>
|
|
33
25
|
|
|
34
|
-
|
|
26
|
+
<br />
|
|
35
27
|
|
|
36
|
-
|
|
28
|
+
## ✨ Why Skybridge?
|
|
37
29
|
|
|
38
|
-
|
|
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.
|
|
39
31
|
|
|
40
|
-
|
|
32
|
+
**Skybridge fixes that.**
|
|
41
33
|
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
web/
|
|
47
|
-
└── src/
|
|
48
|
-
└── widgets/
|
|
49
|
-
└── pokemon.tsx // Use the same widget name as the file name
|
|
50
|
-
```
|
|
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. |
|
|
51
38
|
|
|
52
|
-
|
|
39
|
+
<br />
|
|
53
40
|
|
|
54
|
-
|
|
55
|
-
import { McpServer } from "skybridge/server";
|
|
41
|
+
## 🚀 Get Started
|
|
56
42
|
|
|
57
|
-
|
|
43
|
+
**Create a new ChatGPT app:**
|
|
58
44
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
);
|
|
45
|
+
```bash
|
|
46
|
+
gh repo create my-app --template alpic-ai/apps-sdk-template --clone
|
|
47
|
+
cd my-app && pnpm install
|
|
63
48
|
```
|
|
64
49
|
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
```ts
|
|
68
|
-
import { mountWidget } from "skybridge/web";
|
|
69
|
-
|
|
70
|
-
const Pokemon: React.FunctionComponent = () => {
|
|
71
|
-
// Your React component code goes here...
|
|
72
|
-
};
|
|
50
|
+
**Or add to an existing project:**
|
|
73
51
|
|
|
74
|
-
|
|
52
|
+
```bash
|
|
53
|
+
npm i skybridge
|
|
54
|
+
yarn add skybridge
|
|
55
|
+
pnpm add skybridge
|
|
56
|
+
bun add skybridge
|
|
57
|
+
deno add skybridge
|
|
75
58
|
```
|
|
76
59
|
|
|
77
|
-
|
|
60
|
+
<div align="center">
|
|
78
61
|
|
|
79
|
-
|
|
62
|
+
**👉 [Read the Docs](https://skybridge.tech) 👈**
|
|
80
63
|
|
|
81
|
-
|
|
64
|
+
</div>
|
|
82
65
|
|
|
83
|
-
|
|
66
|
+
<br />
|
|
84
67
|
|
|
85
|
-
|
|
68
|
+
## 📦 The Stack
|
|
86
69
|
|
|
87
|
-
|
|
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.
|
|
88
72
|
|
|
89
|
-
|
|
73
|
+
### Server
|
|
90
74
|
|
|
91
75
|
```ts
|
|
92
|
-
import {
|
|
93
|
-
import { skybridge } from "skybridge/web";
|
|
76
|
+
import { McpServer } from "skybridge/server";
|
|
94
77
|
|
|
95
|
-
|
|
96
|
-
|
|
78
|
+
server.registerWidget("flights", {}, {
|
|
79
|
+
inputSchema: { destination: z.string() },
|
|
80
|
+
}, async ({ destination }) => {
|
|
81
|
+
const flights = await searchFlights(destination);
|
|
82
|
+
return { structuredContent: { flights } };
|
|
97
83
|
});
|
|
98
84
|
```
|
|
99
85
|
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
The `skybridge/web` package comes with a set of hooks to help you build your widgets :
|
|
86
|
+
### Widget
|
|
103
87
|
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
- `useToolResponseMetadata`: A hook to get the initial tool `meta` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
|
|
107
|
-
- `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
|
|
88
|
+
```tsx
|
|
89
|
+
import { useToolInfo } from "skybridge/web";
|
|
108
90
|
|
|
109
|
-
|
|
91
|
+
function FlightsWidget() {
|
|
92
|
+
const { output } = useToolInfo();
|
|
110
93
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
```
|
|
116
|
-
|
|
117
|
-
_useToolOutput_
|
|
118
|
-
|
|
119
|
-
```ts
|
|
120
|
-
import { useToolOutput } from "skybridge/web";
|
|
121
|
-
|
|
122
|
-
const toolOutput = useToolOutput();
|
|
94
|
+
return output.structuredContent.flights.map(f =>
|
|
95
|
+
<FlightCard key={f.id} flight={f} />
|
|
96
|
+
);
|
|
97
|
+
}
|
|
123
98
|
```
|
|
124
99
|
|
|
125
|
-
|
|
100
|
+
<br />
|
|
126
101
|
|
|
127
|
-
|
|
128
|
-
import { useToolResponseMetadata } from "skybridge/web";
|
|
102
|
+
## 🎯 Features at a Glance
|
|
129
103
|
|
|
130
|
-
|
|
131
|
-
|
|
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.
|
|
132
110
|
|
|
133
|
-
|
|
111
|
+
<br />
|
|
134
112
|
|
|
135
|
-
|
|
136
|
-
import { useCallTool } from "skybridge/web";
|
|
137
|
-
|
|
138
|
-
export const TestTool: React.FunctionComponent = () => {
|
|
139
|
-
const { callTool, isPending } = useCallTool("myToolName");
|
|
140
|
-
|
|
141
|
-
return (
|
|
142
|
-
<div>
|
|
143
|
-
<button
|
|
144
|
-
disabled={isPending}
|
|
145
|
-
onClick={() => {
|
|
146
|
-
callTool({ input: "test input" }, {
|
|
147
|
-
onSuccess: (data) => {
|
|
148
|
-
alert("Tool returned: " + data);
|
|
149
|
-
},
|
|
150
|
-
});
|
|
151
|
-
>
|
|
152
|
-
Call Tool inside a widget
|
|
153
|
-
</button>
|
|
154
|
-
</div>
|
|
155
|
-
);
|
|
156
|
-
};
|
|
157
|
-
```
|
|
158
|
-
|
|
159
|
-
_useCallTool_ in asynchronous mode
|
|
160
|
-
|
|
161
|
-
```ts
|
|
162
|
-
import { useCallTool } from "skybridge/web";
|
|
163
|
-
|
|
164
|
-
export const TestTool: React.FunctionComponent = () => {
|
|
165
|
-
const { callToolAsync, isPending } = useCallTool("myToolName");
|
|
166
|
-
|
|
167
|
-
return (
|
|
168
|
-
<div>
|
|
169
|
-
<button
|
|
170
|
-
disabled={isPending}
|
|
171
|
-
onClick={async () => {
|
|
172
|
-
const data = await callToolAsync({ input: "test input" });
|
|
173
|
-
alert("Tool returned: " + data);
|
|
174
|
-
}}
|
|
175
|
-
>
|
|
176
|
-
Call Tool inside a widget
|
|
177
|
-
</button>
|
|
178
|
-
</div>
|
|
179
|
-
);
|
|
180
|
-
};
|
|
181
|
-
```
|
|
113
|
+
<div align="center">
|
|
182
114
|
|
|
183
|
-
|
|
115
|
+
[](https://github.com/alpic-ai/skybridge/discussions)
|
|
116
|
+
[](https://github.com/alpic-ai/skybridge/issues)
|
|
117
|
+
[](https://discord.com/invite/gNAazGueab)
|
|
184
118
|
|
|
185
|
-
|
|
119
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
|
|
186
120
|
|
|
187
|
-
|
|
188
|
-
2. Create a new vite project in a folder named `web` and install the `skybridge` package
|
|
189
|
-
3. Replace the `vite.config.ts` file with the following:
|
|
121
|
+
<br />
|
|
190
122
|
|
|
191
|
-
|
|
192
|
-
import { defineConfig } from "vite";
|
|
193
|
-
import { skybridge } from "skybridge/web";
|
|
123
|
+
**[MIT License](LICENSE)** · Made with ❤️ by **[Alpic](https://alpic.ai)**
|
|
194
124
|
|
|
195
|
-
|
|
196
|
-
plugins: [skybridge()],
|
|
197
|
-
});
|
|
198
|
-
```
|
|
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"}
|
|
@@ -1,2 +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";
|
|
1
4
|
export { McpServer } from "./server.js";
|
|
2
5
|
export { widgetsDevServer } from "./widgetsDevServer.js";
|
package/dist/src/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
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 @@
|
|
|
1
|
+
{"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1,13 +1,65 @@
|
|
|
1
|
-
import { McpServer as McpServerBase, type
|
|
2
|
-
import type {
|
|
3
|
-
import type {
|
|
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
|
+
};
|
|
4
10
|
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
|
|
5
|
-
type McpServerOriginalToolConfig = Omit<Parameters<
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
12
|
+
type ExtractStructuredContent<T> = T extends {
|
|
13
|
+
structuredContent: infer SC;
|
|
14
|
+
} ? SC : never;
|
|
15
|
+
type ExtractMeta<T> = Extract<T, {
|
|
16
|
+
_meta: unknown;
|
|
17
|
+
}> extends {
|
|
18
|
+
_meta: infer M;
|
|
19
|
+
} ? M : unknown;
|
|
20
|
+
/**
|
|
21
|
+
* Type-level marker interface for cross-package type inference.
|
|
22
|
+
* This enables TypeScript to infer tool types across package boundaries
|
|
23
|
+
* using structural typing on the $types property, rather than relying on
|
|
24
|
+
* class generic inference which fails when McpServer comes from different
|
|
25
|
+
* package installations.
|
|
26
|
+
*
|
|
27
|
+
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
28
|
+
*/
|
|
29
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
30
|
+
readonly tools: TTools;
|
|
31
|
+
}
|
|
32
|
+
type Simplify<T> = {
|
|
33
|
+
[K in keyof T]: T[K];
|
|
34
|
+
};
|
|
35
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
36
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
37
|
+
} & {
|
|
38
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
39
|
+
}>;
|
|
40
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
41
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
42
|
+
}>;
|
|
43
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
44
|
+
title?: string;
|
|
45
|
+
description?: string;
|
|
46
|
+
inputSchema?: TInput;
|
|
47
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
48
|
+
annotations?: ToolAnnotations;
|
|
49
|
+
_meta?: Record<string, unknown>;
|
|
50
|
+
};
|
|
51
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends CallToolResult = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
52
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
53
|
+
readonly $types: McpServerTypes<TTools>;
|
|
54
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends CallToolResult>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
55
|
+
inputSchema?: TInput;
|
|
56
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
57
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
58
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends CallToolResult>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
59
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
60
|
+
private registerWidgetResource;
|
|
11
61
|
private lookupDistFile;
|
|
62
|
+
private lookupDistFileWithIndexFallback;
|
|
63
|
+
private readManifest;
|
|
12
64
|
}
|
|
13
65
|
export {};
|
|
@@ -1,57 +1,73 @@
|
|
|
1
|
-
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { templateHelper } from "./templateHelper.js";
|
|
3
1
|
import { readFileSync } from "node:fs";
|
|
4
2
|
import path from "node:path";
|
|
3
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { templateHelper } from "./templateHelper.js";
|
|
5
5
|
export class McpServer extends McpServerBase {
|
|
6
|
-
|
|
7
|
-
const uri = `ui://widgets/${name}.html`;
|
|
6
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
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
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
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 appsSdkUri = `ui://widgets/apps-sdk/${name}.html`;
|
|
14
|
+
this.registerWidgetResource({
|
|
15
|
+
name,
|
|
16
|
+
uri: appsSdkUri,
|
|
17
|
+
mimeType: "text/html+skybridge",
|
|
18
|
+
resourceConfig,
|
|
19
|
+
resourceMetadata,
|
|
20
|
+
});
|
|
21
|
+
const extAppsUri = `ui://widgets/ext-apps/${name}.html`;
|
|
22
|
+
this.registerWidgetResource({
|
|
23
|
+
name,
|
|
24
|
+
uri: extAppsUri,
|
|
25
|
+
mimeType: "text/html;profile=mcp-app",
|
|
26
|
+
resourceConfig,
|
|
27
|
+
resourceMetadata,
|
|
41
28
|
});
|
|
42
29
|
const toolMeta = {
|
|
43
30
|
...toolConfig._meta,
|
|
44
|
-
"openai/outputTemplate":
|
|
45
|
-
"ui/resourceUri":
|
|
31
|
+
"openai/outputTemplate": appsSdkUri,
|
|
32
|
+
"ui/resourceUri": extAppsUri,
|
|
46
33
|
};
|
|
47
34
|
this.registerTool(name, {
|
|
48
35
|
...toolConfig,
|
|
49
36
|
_meta: toolMeta,
|
|
50
37
|
}, toolCallback);
|
|
38
|
+
return this;
|
|
39
|
+
}
|
|
40
|
+
registerTool(name, config, cb) {
|
|
41
|
+
super.registerTool(name, config, cb);
|
|
42
|
+
return this;
|
|
43
|
+
}
|
|
44
|
+
registerWidgetResource({ name, uri, mimeType, resourceConfig, resourceMetadata, }) {
|
|
45
|
+
this.registerResource(name, uri, { ...resourceConfig, _meta: resourceMetadata }, async (_uri, extra) => {
|
|
46
|
+
const serverUrl = process.env.NODE_ENV === "production"
|
|
47
|
+
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
|
|
48
|
+
: `http://localhost:3000`;
|
|
49
|
+
const html = process.env.NODE_ENV === "production"
|
|
50
|
+
? templateHelper.renderProduction({
|
|
51
|
+
serverUrl,
|
|
52
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}.tsx`),
|
|
53
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
54
|
+
})
|
|
55
|
+
: templateHelper.renderDevelopment({ serverUrl, widgetName: name });
|
|
56
|
+
return { contents: [{ uri, mimeType, text: html }] };
|
|
57
|
+
});
|
|
51
58
|
}
|
|
52
59
|
lookupDistFile(key) {
|
|
53
|
-
const manifest =
|
|
60
|
+
const manifest = this.readManifest();
|
|
54
61
|
return manifest[key]?.file;
|
|
55
62
|
}
|
|
63
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
64
|
+
const manifest = this.readManifest();
|
|
65
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
66
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
67
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
68
|
+
}
|
|
69
|
+
readManifest() {
|
|
70
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
71
|
+
}
|
|
56
72
|
}
|
|
57
73
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"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"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import Handlebars from "handlebars";
|
|
2
1
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import Handlebars from "handlebars";
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
class TemplateHelper {
|
|
8
8
|
templateCache = new Map();
|
|
9
9
|
loadTemplate(templateName) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const cached = this.templateCache.get(templateName);
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached;
|
|
12
13
|
}
|
|
13
14
|
const templatePath = join(__dirname, "templates", `${templateName}.hbs`);
|
|
14
15
|
const templateSource = readFileSync(templatePath, "utf-8");
|