skybridge 0.0.0-dev.f881c56 → 0.0.0-dev.fa642c4

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 (88) hide show
  1. package/dist/src/server/devtoolsStaticServer.d.ts +15 -0
  2. package/dist/src/server/devtoolsStaticServer.js +43 -0
  3. package/dist/src/server/devtoolsStaticServer.js.map +1 -0
  4. package/dist/src/server/index.d.ts +3 -2
  5. package/dist/src/server/index.js +1 -0
  6. package/dist/src/server/index.js.map +1 -1
  7. package/dist/src/server/inferUtilityTypes.d.ts +10 -0
  8. package/dist/src/server/server.d.ts +30 -16
  9. package/dist/src/server/server.js +4 -4
  10. package/dist/src/server/server.js.map +1 -1
  11. package/dist/src/server/templateHelper.js +5 -4
  12. package/dist/src/server/templateHelper.js.map +1 -1
  13. package/dist/src/server/templates/development.hbs +1 -1
  14. package/dist/src/server/widgetsDevServer.js +3 -3
  15. package/dist/src/server/widgetsDevServer.js.map +1 -1
  16. package/dist/src/test/utils.d.ts +44 -9
  17. package/dist/src/test/utils.js +66 -8
  18. package/dist/src/test/utils.js.map +1 -1
  19. package/dist/src/test/widget.test.js +26 -21
  20. package/dist/src/test/widget.test.js.map +1 -1
  21. package/dist/src/web/create-store.js +1 -1
  22. package/dist/src/web/create-store.js.map +1 -1
  23. package/dist/src/web/create-store.test.js +1 -1
  24. package/dist/src/web/create-store.test.js.map +1 -1
  25. package/dist/src/web/data-llm.js +2 -2
  26. package/dist/src/web/data-llm.js.map +1 -1
  27. package/dist/src/web/data-llm.test.js.map +1 -1
  28. package/dist/src/web/generate-helpers.d.ts +9 -7
  29. package/dist/src/web/generate-helpers.js +4 -2
  30. package/dist/src/web/generate-helpers.js.map +1 -1
  31. package/dist/src/web/generate-helpers.test-d.js +29 -2
  32. package/dist/src/web/generate-helpers.test-d.js.map +1 -1
  33. package/dist/src/web/generate-helpers.test.js +1 -1
  34. package/dist/src/web/generate-helpers.test.js.map +1 -1
  35. package/dist/src/web/helpers/state.js +1 -1
  36. package/dist/src/web/helpers/state.js.map +1 -1
  37. package/dist/src/web/helpers/state.test.js +2 -2
  38. package/dist/src/web/helpers/state.test.js.map +1 -1
  39. package/dist/src/web/hooks/index.d.ts +2 -2
  40. package/dist/src/web/hooks/index.js +1 -1
  41. package/dist/src/web/hooks/index.js.map +1 -1
  42. package/dist/src/web/hooks/use-call-tool.d.ts +1 -1
  43. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  44. package/dist/src/web/hooks/use-call-tool.test-d.js +1 -1
  45. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -1
  46. package/dist/src/web/hooks/use-call-tool.test.js +9 -15
  47. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  48. package/dist/src/web/hooks/use-display-mode.js.map +1 -1
  49. package/dist/src/web/hooks/use-display-mode.test.js +2 -2
  50. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -1
  51. package/dist/src/web/hooks/use-files.test.js +1 -1
  52. package/dist/src/web/hooks/use-files.test.js.map +1 -1
  53. package/dist/src/web/hooks/use-locale.js.map +1 -1
  54. package/dist/src/web/hooks/use-locale.test.js +2 -2
  55. package/dist/src/web/hooks/use-locale.test.js.map +1 -1
  56. package/dist/src/web/hooks/use-open-external.test.js +2 -2
  57. package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
  58. package/dist/src/web/hooks/use-openai-global.d.ts +2 -2
  59. package/dist/src/web/hooks/use-openai-global.js +7 -5
  60. package/dist/src/web/hooks/use-openai-global.js.map +1 -1
  61. package/dist/src/web/hooks/use-request-modal.test.js +2 -2
  62. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -1
  63. package/dist/src/web/hooks/use-theme.js.map +1 -1
  64. package/dist/src/web/hooks/use-theme.test.js +2 -2
  65. package/dist/src/web/hooks/use-theme.test.js.map +1 -1
  66. package/dist/src/web/hooks/use-tool-info.d.ts +1 -1
  67. package/dist/src/web/hooks/use-tool-info.js +4 -6
  68. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  69. package/dist/src/web/hooks/use-tool-info.test-d.js +0 -1
  70. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
  71. package/dist/src/web/hooks/use-tool-info.test.js +2 -2
  72. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  73. package/dist/src/web/hooks/use-user-agent.js.map +1 -1
  74. package/dist/src/web/hooks/use-user-agent.test.js +2 -2
  75. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -1
  76. package/dist/src/web/hooks/use-widget-state.js +2 -2
  77. package/dist/src/web/hooks/use-widget-state.js.map +1 -1
  78. package/dist/src/web/hooks/use-widget-state.test.js +2 -2
  79. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
  80. package/dist/src/web/index.d.ts +4 -4
  81. package/dist/src/web/index.js +4 -4
  82. package/dist/src/web/index.js.map +1 -1
  83. package/dist/src/web/proxy.js +1 -1
  84. package/dist/src/web/proxy.js.map +1 -1
  85. package/dist/src/web/types.d.ts +6 -6
  86. package/package.json +9 -8
  87. package/LICENSE +0 -674
  88. package/README.md +0 -415
package/README.md DELETED
@@ -1,415 +0,0 @@
1
- <div align="center">
2
-
3
- # Skybridge
4
-
5
- **Skybridge is the TypeScript framework for building ChatGPT apps**
6
-
7
- [![By Alpic](https://img.shields.io/badge/Made%20by%20Alpic-f6ffed?logo=alpic)](https://alpic.ai)
8
-
9
- ![NPM Downloads](https://img.shields.io/npm/dm/skybridge?color=e90060)
10
- ![NPM Version](https://img.shields.io/npm/v/skybridge?color=e90060)
11
- ![GitHub License](https://img.shields.io/github/license/alpic-ai/skybridge?color=e90060)
12
-
13
- </div>
14
-
15
- Skybridge comes with 2 packages:
16
-
17
- - `skybridge/server`: A drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development.
18
- - `skybridge/web`: A react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
19
-
20
- ## Quick start
21
-
22
- To get started in less than a minute, you can [create a new repository](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) using our [ChatGPT SDK template](https://github.com/alpic-ai/apps-sdk-template). This template includes a basic setup for both the server and the widgets.
23
-
24
- ## Installation
25
-
26
- ```bash
27
- pnpm add skybridge
28
- ```
29
-
30
- ## Concepts
31
-
32
- ### Widgets
33
-
34
- > A widget is a UI component that turns structured tool results into a human-friendly UI. Those are built using React components. They are rendered inside an iframe inline with the conversation on ChatGPT.
35
-
36
- Each widget in your app must have a unique name. The name is used to bridge the tool invocation result with the widget React component.
37
-
38
- For example, in order to register a new widget named `pokemon` on your ChatGPT app. You should have the following file structure and file contents:
39
-
40
- _Project structure_
41
-
42
- ```
43
- server/
44
- └── src/
45
- └── index.ts // Register the widget with McpServer.widget()
46
- web/
47
- └── src/
48
- └── widgets/
49
- └── pokemon.tsx // Use the same widget name as the file name
50
- ```
51
-
52
- _server/src/index.ts_
53
-
54
- ```ts
55
- import { McpServer } from "skybridge/server";
56
-
57
- const server = new McpServer();
58
-
59
- server.widget(
60
- "pokemon"
61
- // Remaining arguments...
62
- );
63
- ```
64
-
65
- _web/src/widgets/pokemon.tsx_
66
-
67
- ```ts
68
- import { mountWidget } from "skybridge/web";
69
-
70
- const Pokemon: React.FunctionComponent = () => {
71
- // Your React component code goes here...
72
- };
73
-
74
- mountWidget(<Pokemon />);
75
- ```
76
-
77
- ## Packages
78
-
79
- ### skybridge/server
80
-
81
- The `skybridge/server` package is a drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development. If you're already using the `@modelcontextprotocol/sdk`, you can simply replace your `McpServer` import with `skybridge/server` and you're good to go.
82
-
83
- ### skybridge/web
84
-
85
- The `skybridge/web` package is a react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
86
-
87
- **Vite plugin**
88
-
89
- The `skybridge/web` package comes with a Vite plugin that allows you to build your widgets as regular Vite apps.
90
-
91
- ```ts
92
- import { defineConfig } from "vite";
93
- import { skybridge } from "skybridge/web";
94
-
95
- export default defineConfig({
96
- plugins: [skybridge()],
97
- });
98
- ```
99
-
100
- **Typed Hooks**
101
-
102
- Skybridge provides fully typed hooks that give you autocomplete for tool names and type inference for inputs/outputs - similar to tRPC. This is opt-in and requires exporting your server type.
103
-
104
- > **Tip:** For the best TypeScript experience, use typed hooks throughout your application. They provide autocomplete, type safety, and better IDE support.
105
-
106
- > **Important:** For `generateHelpers` to work correctly, your MCP server must be defined using method chaining (e.g., `server.widget(...).widget(...).registerTool(...)`). This ensures TypeScript can properly infer the tool registry type from the chained calls.
107
-
108
- **Examples:**
109
-
110
- ✅ **Works** - Using method chaining:
111
-
112
- ```ts
113
- import { McpServer } from "skybridge/server";
114
- import { z } from "zod";
115
-
116
- const server = new McpServer({ name: "my-app", version: "1.0" }, {})
117
- .widget("search-voyage", {}, {
118
- inputSchema: { destination: z.string() },
119
- }, async ({ destination }) => {
120
- return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
121
- })
122
- .registerTool("calculate-price", {
123
- inputSchema: { tripId: z.string() },
124
- }, async ({ tripId }) => {
125
- return { content: [{ type: "text", text: `Price for ${tripId}` }] };
126
- });
127
-
128
- export type AppType = typeof server; // ✅ Type inference works correctly
129
- ```
130
-
131
- ❌ **Doesn't work** - Without method chaining:
132
-
133
- ```ts
134
- import { McpServer } from "skybridge/server";
135
- import { z } from "zod";
136
-
137
- const server = new McpServer({ name: "my-app", version: "1.0" }, {});
138
-
139
- server.widget("search-voyage", {}, {
140
- inputSchema: { destination: z.string() },
141
- }, async ({ destination }) => {
142
- return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
143
- });
144
-
145
- server.registerTool("calculate-price", {
146
- inputSchema: { tripId: z.string() },
147
- }, async ({ tripId }) => {
148
- return { content: [{ type: "text", text: `Price for ${tripId}` }] };
149
- });
150
-
151
- export type AppType = typeof server; // ❌ Type inference fails - tool registry is empty
152
- ```
153
-
154
- _Server setup (server/src/index.ts)_
155
-
156
- ```ts
157
- import { McpServer } from "skybridge/server";
158
- import { z } from "zod";
159
-
160
- const server = new McpServer({ name: "my-app", version: "1.0" }, {})
161
- .widget("search-voyage", {}, {
162
- description: "Search for trips",
163
- inputSchema: {
164
- destination: z.string(),
165
- departureDate: z.string().optional(),
166
- },
167
- outputSchema: {
168
- results: z.array(z.object({ id: z.string(), name: z.string() })),
169
- totalCount: z.number(),
170
- },
171
- }, async ({ destination }) => {
172
- // Your tool logic here...
173
- return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
174
- })
175
- .widget("get-details", {}, {
176
- inputSchema: { tripId: z.string() },
177
- }, async ({ tripId }) => {
178
- return { content: [{ type: "text", text: `Details for ${tripId}` }] };
179
- });
180
-
181
- // Export the server type for the client
182
- export type AppType = typeof server;
183
- ```
184
-
185
- _One-time setup (web/src/skybridge.ts)_
186
-
187
- Create typed hooks once and export them for use across your app. This file acts as a bridge between your server types and your widgets:
188
-
189
- ```ts
190
- import type { AppType } from "../server"; // type-only import
191
- import { generateHelpers } from "skybridge/web";
192
-
193
- export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
194
- ```
195
-
196
- _Usage in widgets (web/src/widgets/search.tsx)_
197
-
198
- ```tsx
199
- import { useCallTool, useToolInfo } from "../skybridge"; // import typed hooks
200
-
201
- export function SearchWidget() {
202
- const { callTool, data, isPending } = useCallTool("search-voyage");
203
- // ^ autocomplete for tool names
204
- const toolInfo = useToolInfo<"search-voyage">();
205
- // ^ autocomplete for widget names
206
-
207
- const handleSearch = () => {
208
- callTool({ destination: "Spain" });
209
- // ^ autocomplete for input fields
210
- };
211
-
212
- return (
213
- <div>
214
- <button onClick={handleSearch} disabled={isPending}>
215
- Search
216
- </button>
217
- {toolInfo.isSuccess && (
218
- <div>Found {toolInfo.output.structuredContent.totalCount} results</div>
219
- // ^ typed output
220
- )}
221
- </div>
222
- );
223
- }
224
- ```
225
-
226
- **Hooks**
227
-
228
- The `skybridge/web` package comes with a set of hooks to help you build your widgets :
229
-
230
- - `useOpenAiGlobal`: A generic hook to get any global data from the OpenAI iFrame skybridge runtime (in `window.openai`).
231
- - `useToolOutput`: A hook to get the initial tool `structuredContent` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
232
- - `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.
233
- - `useToolInfo`: A hook to get the tool input, output, and response metadata with type inference. Provides a discriminated union based on status (pending/success).
234
- - `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
235
- - `generateHelpers`: A factory that creates typed versions of `useCallTool` and `useToolInfo` with full type inference from your server type.
236
-
237
- _useOpenAiGlobal_
238
-
239
- ```ts
240
- import { useOpenAiGlobal } from "skybridge/web";
241
-
242
- const theme = useOpenAiGlobal("theme");
243
- ```
244
-
245
- _useToolOutput_
246
-
247
- ```ts
248
- import { useToolOutput } from "skybridge/web";
249
-
250
- const toolOutput = useToolOutput();
251
- ```
252
-
253
- _useToolResponseMetadata_
254
-
255
- ```ts
256
- import { useToolResponseMetadata } from "skybridge/web";
257
-
258
- const toolResponseMetadata = useToolResponseMetadata();
259
- ```
260
-
261
- _useToolInfo_
262
-
263
- ```ts
264
- import { useToolInfo } from "skybridge/web";
265
-
266
- const toolInfo = useToolInfo<{
267
- input: { query: string };
268
- output: { results: string[] };
269
- responseMetadata: { id: number };
270
- }>();
271
-
272
- // toolInfo.input is typed based on the input type
273
- // toolInfo.output.structuredContent is typed based on the output type (undefined when pending)
274
- // toolInfo.status narrows correctly: "pending" | "success"
275
-
276
- if (toolInfo.isPending) {
277
- // toolInfo.output is undefined here (pending state)
278
- console.log(toolInfo.input.query);
279
- }
280
-
281
- if (toolInfo.isSuccess) {
282
- // toolInfo.output.structuredContent is typed here
283
- console.log(toolInfo.output.structuredContent.results);
284
- }
285
- ```
286
-
287
- _useToolInfo_ with typed hooks (recommended)
288
-
289
- ```tsx
290
- import { useToolInfo } from "../skybridge"; // import typed hooks
291
-
292
- export function SearchWidget() {
293
- const toolInfo = useToolInfo<"search-voyage">();
294
- // ^ autocomplete for widget names
295
- // toolInfo.input is typed as { destination: string; departureDate?: string; ... }
296
- // toolInfo.output.structuredContent is typed as { results: Array<...>; totalCount: number; }
297
-
298
- if (toolInfo.isSuccess) {
299
- return <div>Found {toolInfo.output.structuredContent.totalCount} results</div>;
300
- }
301
-
302
- return <div>Searching for {toolInfo.input.destination}...</div>;
303
- }
304
- ```
305
-
306
- _useCallTool_ in synchronous mode
307
-
308
- ```ts
309
- import { useCallTool } from "skybridge/web";
310
-
311
- export const TestTool: React.FunctionComponent = () => {
312
- const { callTool, isPending } = useCallTool("myToolName");
313
-
314
- return (
315
- <div>
316
- <button
317
- disabled={isPending}
318
- onClick={() => {
319
- callTool({ input: "test input" }, {
320
- onSuccess: (data) => {
321
- alert("Tool returned: " + data);
322
- },
323
- });
324
- >
325
- Call Tool inside a widget
326
- </button>
327
- </div>
328
- );
329
- };
330
- ```
331
-
332
- _useCallTool_ in asynchronous mode
333
-
334
- ```ts
335
- import { useCallTool } from "skybridge/web";
336
-
337
- export const TestTool: React.FunctionComponent = () => {
338
- const { callToolAsync, isPending } = useCallTool("myToolName");
339
-
340
- return (
341
- <div>
342
- <button
343
- disabled={isPending}
344
- onClick={async () => {
345
- const data = await callToolAsync({ input: "test input" });
346
- alert("Tool returned: " + data);
347
- }}
348
- >
349
- Call Tool inside a widget
350
- </button>
351
- </div>
352
- );
353
- };
354
- ```
355
-
356
- **State Management**
357
-
358
- The `skybridge/web` package provides `createStore` for creating Zustand stores with automatic persistence to `window.openai.widgetState`. This is useful when you need more advanced state management than what `useWidgetState` provides.
359
-
360
- _createStore_
361
-
362
- ```ts
363
- import { createStore } from "skybridge/web";
364
-
365
- type CounterState = {
366
- count: number;
367
- increment: () => void;
368
- decrement: () => void;
369
- };
370
-
371
- const useCounterStore = createStore<CounterState>(
372
- (set) => ({
373
- count: 0,
374
- increment: () => set((state) => ({ count: state.count + 1 })),
375
- decrement: () => set((state) => ({ count: state.count - 1 })),
376
- }),
377
- { count: 0 } // Optional default state
378
- );
379
-
380
- // Use in your component
381
- function CounterWidget() {
382
- const { count, increment, decrement } = useCounterStore();
383
-
384
- return (
385
- <div>
386
- <p>Count: {count}</p>
387
- <button onClick={increment}>Increment</button>
388
- <button onClick={decrement}>Decrement</button>
389
- </div>
390
- );
391
- }
392
- ```
393
-
394
- The `createStore` function:
395
-
396
- - Automatically persists state to `window.openai.widgetState`
397
- - Syncs with external state changes from the host
398
- - Only serializes state data, not methods
399
-
400
- ## Migrate your existing MCP server to a ChatGPT app
401
-
402
- If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
403
-
404
- 1. Replace your `McpServer` import from `@modelcontextprotocol/sdk` with the same import from `skybridge/server`
405
- 2. Create a new vite project in a folder named `web` and install the `skybridge` package
406
- 3. Replace the `vite.config.ts` file with the following:
407
-
408
- ```ts
409
- import { defineConfig } from "vite";
410
- import { skybridge } from "skybridge/web";
411
-
412
- export default defineConfig({
413
- plugins: [skybridge()],
414
- });
415
- ```