skybridge 0.9.3 → 0.9.5
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/README.md +10 -353
- package/dist/src/server/server.d.ts +1 -1
- package/dist/src/server/server.js +1 -1
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/test/utils.js +5 -5
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +3 -3
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +2 -2
- package/dist/src/web/types.d.ts +4 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -12,360 +12,17 @@
|
|
|
12
12
|
|
|
13
13
|
</div>
|
|
14
14
|
|
|
15
|
-
Skybridge comes with
|
|
15
|
+
Skybridge is a fullstack library. It comes with modular packages aiming at simplifying the development of ChatGPT apps:
|
|
16
16
|
|
|
17
|
-
-
|
|
18
|
-
-
|
|
17
|
+
- HMR server for development and build pipeline for production including end-to-end (tools-to-widget) type safety
|
|
18
|
+
- collection of React hooks for state management, async data fetching
|
|
19
|
+
- attribute for widget-to-context synchronization
|
|
19
20
|
|
|
20
|
-
|
|
21
|
+
### <a href="https://skybridge.tech">Read the docs →</b></a>
|
|
21
22
|
|
|
22
|
-
|
|
23
|
+
## Get Involved
|
|
23
24
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
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
|
-
## Migrate your existing MCP server to a ChatGPT app
|
|
357
|
-
|
|
358
|
-
If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
|
|
359
|
-
|
|
360
|
-
1. Replace your `McpServer` import from `@modelcontextprotocol/sdk` with the same import from `skybridge/server`
|
|
361
|
-
2. Create a new vite project in a folder named `web` and install the `skybridge` package
|
|
362
|
-
3. Replace the `vite.config.ts` file with the following:
|
|
363
|
-
|
|
364
|
-
```ts
|
|
365
|
-
import { defineConfig } from "vite";
|
|
366
|
-
import { skybridge } from "skybridge/web";
|
|
367
|
-
|
|
368
|
-
export default defineConfig({
|
|
369
|
-
plugins: [skybridge()],
|
|
370
|
-
});
|
|
371
|
-
```
|
|
25
|
+
We welcome issues and pull requests!</br>
|
|
26
|
+
Participate in [GitHub discussions](https://github.com/alpic-ai/skybridge/discussions)</br>
|
|
27
|
+
Chat with the community on [Discord](https://discord.com/invite/gNAazGueab)</br>
|
|
28
|
+
See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
|
|
@@ -37,7 +37,7 @@ type ToolConfig<TInput extends ZodRawShape> = {
|
|
|
37
37
|
type ToolHandler<TInput extends ZodRawShape, TReturn extends CallToolResult = CallToolResult> = (args: Infer<ZodObject<TInput>>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
38
38
|
export declare class McpServer<TTools extends Record<string, ToolDef> = {}> extends McpServerBase {
|
|
39
39
|
readonly $types: McpServerTypes<TTools>;
|
|
40
|
-
|
|
40
|
+
registerWidget<TName extends string, TInput extends ZodRawShape, TReturn extends CallToolResult>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
41
41
|
inputSchema?: TInput;
|
|
42
42
|
outputSchema?: ZodRawShape;
|
|
43
43
|
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>>;
|
|
@@ -3,7 +3,7 @@ import { templateHelper } from "./templateHelper.js";
|
|
|
3
3
|
import { readFileSync } from "node:fs";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
export class McpServer extends McpServerBase {
|
|
6
|
-
|
|
6
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
7
7
|
const uri = `ui://widgets/${name}.html`;
|
|
8
8
|
const resourceMetadata = {
|
|
9
9
|
...(resourceConfig._meta ?? {}),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAUjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAkG7B,MAAM,OAAO,SAEX,SAAQ,aAAa;IAGrB,
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,I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C,iBAAiB,CAAC;oBAC/B,SAAS;oBACT,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;YAET,OAAO;gBACL,QAAQ,EAAE;oBACR;wBACE,GAAG;wBACH,QAAQ,EAAE,qBAAqB;wBAC/B,IAAI,EAAE,IAAI;qBACX;iBACF;aACF,CAAC;QACJ,CAAC,CACF,CAAC;QAEF,MAAM,QAAQ,GAAa;YACzB,GAAG,UAAU,CAAC,KAAK;YACnB,uBAAuB,EAAE,GAAG;YAC5B,gBAAgB,EAAE,GAAG;SACtB,CAAC;QAEF,IAAI,CAAC,YAAY,CACf,IAAI,EACJ;YACE,GAAG,UAAU;YACb,KAAK,EAAE,QAAQ;SAChB,EACD,YAAY,CACb,CAAC;QAEF,OAAO,IAAyE,CAAC;IACnF,CAAC;IAkBQ,YAAY,CACnB,IAAY,EACZ,MAA6B,EAC7B,EAA2B;QAE3B,KAAK,CAAC,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,EAAE,CAAC,CAAC;QACrC,OAAO,IAAI,CAAC;IACd,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
package/dist/src/test/utils.js
CHANGED
|
@@ -21,7 +21,7 @@ export function createMockMcpServer() {
|
|
|
21
21
|
}
|
|
22
22
|
export function createTestServer() {
|
|
23
23
|
return new McpServer({ name: "test-app", version: "1.0.0" }, {})
|
|
24
|
-
.
|
|
24
|
+
.registerWidget("search-voyage", {}, {
|
|
25
25
|
description: "Search for voyages",
|
|
26
26
|
inputSchema: {
|
|
27
27
|
destination: z.string(),
|
|
@@ -45,7 +45,7 @@ export function createTestServer() {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
})
|
|
48
|
-
.
|
|
48
|
+
.registerWidget("get-trip-details", {}, {
|
|
49
49
|
description: "Get trip details",
|
|
50
50
|
inputSchema: {
|
|
51
51
|
tripId: z.string(),
|
|
@@ -65,7 +65,7 @@ export function createTestServer() {
|
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
67
|
})
|
|
68
|
-
.
|
|
68
|
+
.registerWidget("no-input-widget", {}, {
|
|
69
69
|
description: "Widget with no input",
|
|
70
70
|
inputSchema: {},
|
|
71
71
|
outputSchema: {},
|
|
@@ -75,7 +75,7 @@ export function createTestServer() {
|
|
|
75
75
|
structuredContent: {},
|
|
76
76
|
};
|
|
77
77
|
})
|
|
78
|
-
.
|
|
78
|
+
.registerWidget("inferred-output-widget", {}, {
|
|
79
79
|
description: "Widget with output inferred from callback",
|
|
80
80
|
inputSchema: {
|
|
81
81
|
query: z.string(),
|
|
@@ -124,7 +124,7 @@ export function createTestServer() {
|
|
|
124
124
|
});
|
|
125
125
|
}
|
|
126
126
|
export function createMinimalTestServer() {
|
|
127
|
-
return new McpServer({ name: "test-app", version: "1.0.0" }, {}).
|
|
127
|
+
return new McpServer({ name: "test-app", version: "1.0.0" }, {}).registerWidget("search-voyage", {}, {
|
|
128
128
|
description: "Search for voyages",
|
|
129
129
|
inputSchema: {
|
|
130
130
|
destination: z.string(),
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAqB,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EAAE,CAAC,EAAE,MAAM,KAAK,CAAC;AAExB;;GAEG;AACH,MAAM,UAAU,mBAAmB;IAKjC,mCAAmC;IACnC,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE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/C;KACF,EACD,KAAK,EAAE,EAAE,WAAW,EAAE,EAAE,EAAE;QACxB,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,WAAW,EAAE,EAAE,CAAC;YAClE,iBAAiB,EAAE,EAAE,OAAO,EAAE,CAAC,EAAE,EAAE,EAAE,GAAG,EAAE,CAAC,EAAE;SAC9C,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO;QACL,WAAW,EAAE;YACX,OAAO,EAAE,EAAE,IAAI,EAAE;SAClB;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAA2B;IACpD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC9B,CAAC"}
|
|
@@ -21,7 +21,7 @@ vi.mock("node:fs", async () => {
|
|
|
21
21
|
},
|
|
22
22
|
};
|
|
23
23
|
});
|
|
24
|
-
describe("McpServer.
|
|
24
|
+
describe("McpServer.registerWidget", () => {
|
|
25
25
|
let server;
|
|
26
26
|
let mockResource;
|
|
27
27
|
let mockRegisterTool;
|
|
@@ -38,7 +38,7 @@ describe("McpServer.widget", () => {
|
|
|
38
38
|
const mockToolCallback = vi.fn();
|
|
39
39
|
const mockResourceConfig = { description: "Test widget" };
|
|
40
40
|
const mockToolConfig = { description: "Test tool" };
|
|
41
|
-
server.
|
|
41
|
+
server.registerWidget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
|
|
42
42
|
// Get the resource callback function
|
|
43
43
|
const resourceCallback = mockResource.mock.calls[0]?.[3];
|
|
44
44
|
expect(resourceCallback).toBeDefined();
|
|
@@ -64,7 +64,7 @@ describe("McpServer.widget", () => {
|
|
|
64
64
|
const mockToolCallback = vi.fn();
|
|
65
65
|
const mockResourceConfig = { description: "Test widget" };
|
|
66
66
|
const mockToolConfig = { description: "Test tool" };
|
|
67
|
-
server.
|
|
67
|
+
server.registerWidget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
|
|
68
68
|
// Get the resource callback function
|
|
69
69
|
const resourceCallback = mockResource.mock.calls[0]?.[3];
|
|
70
70
|
expect(resourceCallback).toBeDefined();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,GAEH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,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,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,GAAG,IAAW,EAAE,EAAE;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,MAAM,CAAC,Y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,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,gBAAiB,CACpC,IAAI,GAAG,CAAC,6BAA6B,CAAC,EACtC,SAAS,CACV,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,6BAA6B;oBAClC,QAAQ,EAAE,qBAAqB;oBAC/B,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;iBACvD;aACF;SACF,CAAC,CAAC;QAEH,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAC5C,SAAS,GAAG,gBAAgB,CAC7B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC;QAC3E,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CACxC,SAAS,GAAG,sBAAsB,CACnC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,GAAG,mBAAmB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { type
|
|
2
|
-
export declare function useOpenAiGlobal<K extends keyof
|
|
1
|
+
import { type OpenAiProperties } from "../types.js";
|
|
2
|
+
export declare function useOpenAiGlobal<K extends keyof OpenAiProperties>(key: K): OpenAiProperties[K] | undefined;
|
package/dist/src/web/types.d.ts
CHANGED
|
@@ -28,13 +28,13 @@ export declare class ToolResponseEvent extends CustomEvent<{
|
|
|
28
28
|
}
|
|
29
29
|
declare global {
|
|
30
30
|
interface Window {
|
|
31
|
-
openai:
|
|
31
|
+
openai: OpenAiMethods<WidgetState> & OpenAiProperties;
|
|
32
32
|
}
|
|
33
33
|
interface WindowEventMap {
|
|
34
34
|
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export type
|
|
37
|
+
export type OpenAiProperties<ToolInput extends UnknownObject = {}, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
|
|
38
38
|
theme: Theme;
|
|
39
39
|
userAgent: UserAgent;
|
|
40
40
|
locale: string;
|
|
@@ -59,7 +59,7 @@ export type CallToolResponse = {
|
|
|
59
59
|
result: string;
|
|
60
60
|
meta: Record<string, unknown>;
|
|
61
61
|
};
|
|
62
|
-
type
|
|
62
|
+
export type OpenAiMethods<WidgetState extends UnknownObject = UnknownObject> = {
|
|
63
63
|
/** Calls a tool on your MCP. Returns the full response. */
|
|
64
64
|
callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
65
65
|
/** Triggers a followup turn in the ChatGPT conversation */
|
|
@@ -104,7 +104,7 @@ type API<WidgetState extends UnknownObject> = {
|
|
|
104
104
|
};
|
|
105
105
|
export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
106
106
|
export declare class SetGlobalsEvent extends CustomEvent<{
|
|
107
|
-
globals: Partial<
|
|
107
|
+
globals: Partial<OpenAiProperties>;
|
|
108
108
|
}> {
|
|
109
109
|
readonly type = "openai:set_globals";
|
|
110
110
|
}
|