skybridge 0.0.0-dev.d798b8b → 0.0.0-dev.d8b52a9
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 +199 -2
- package/dist/src/server/index.d.ts +2 -0
- package/dist/src/server/inferUtilityTypes.d.ts +44 -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 +14 -7
- package/dist/src/server/server.js +20 -7
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +9 -8
- package/dist/src/server/templateHelper.js +0 -8
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +1 -0
- package/dist/src/server/templates/production.hbs +3 -2
- package/dist/src/test/utils.js +1 -1
- package/dist/src/test/utils.js.map +1 -1
- package/dist/src/test/widget.test.js +23 -2
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +14 -0
- package/dist/src/web/hooks/index.js +15 -0
- package/dist/src/web/hooks/index.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +62 -0
- package/dist/src/web/hooks/use-call-tool.js +68 -0
- package/dist/src/web/hooks/use-call-tool.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +163 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/src/web/hooks/use-display-mode.js +7 -0
- package/dist/src/web/hooks/use-display-mode.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js +40 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
- 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.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.js +5 -0
- package/dist/src/web/hooks/use-locale.js.map +1 -0
- package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.test.js +21 -0
- package/dist/src/web/hooks/use-locale.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.js +6 -0
- package/dist/src/web/hooks/use-open-external.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.test.js +24 -0
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
- package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +4 -2
- package/dist/src/web/hooks/use-openai-global.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.d.ts +6 -0
- package/dist/src/web/hooks/use-request-modal.js +9 -0
- package/dist/src/web/hooks/use-request-modal.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/src/web/hooks/use-request-modal.test.js +24 -0
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/src/web/hooks/use-theme.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.js +5 -0
- package/dist/src/web/hooks/use-theme.js.map +1 -0
- package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.test.js +26 -0
- package/dist/src/web/hooks/use-theme.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
- package/dist/src/web/hooks/use-tool-info.js +22 -0
- package/dist/src/web/hooks/use-tool-info.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +59 -0
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-output.js +9 -0
- package/dist/src/web/hooks/use-tool-output.js.map +1 -0
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.js +5 -0
- package/dist/src/web/hooks/use-user-agent.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.test.js +31 -0
- package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
- package/dist/src/web/hooks/use-widget-state.js +30 -0
- package/dist/src/web/hooks/use-widget-state.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js +60 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/src/web/index.d.ts +2 -4
- package/dist/src/web/index.js +2 -4
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/mount-widget.js +5 -0
- package/dist/src/web/mount-widget.js.map +1 -1
- package/dist/src/web/plugin.js +2 -4
- package/dist/src/web/plugin.js.map +1 -1
- package/dist/src/web/proxy.d.ts +1 -0
- package/dist/src/web/proxy.js +48 -0
- package/dist/src/web/proxy.js.map +1 -0
- package/dist/src/web/typed-hooks.d.ts +107 -0
- package/dist/src/web/typed-hooks.js +111 -0
- package/dist/src/web/typed-hooks.js.map +1 -0
- package/dist/src/web/typed-hooks.test-d.d.ts +1 -0
- package/dist/src/web/typed-hooks.test-d.js +72 -0
- package/dist/src/web/typed-hooks.test-d.js.map +1 -0
- package/dist/src/web/typed-hooks.test.d.ts +1 -0
- package/dist/src/web/typed-hooks.test.js +10 -0
- package/dist/src/web/typed-hooks.test.js.map +1 -0
- package/dist/src/web/types.d.ts +30 -14
- package/dist/src/web/types.js.map +1 -1
- package/dist/vitest.config.js +0 -1
- package/dist/vitest.config.js.map +1 -1
- package/package.json +7 -2
- package/dist/src/test/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- package/dist/src/web/use-call-tool.d.ts +0 -54
- package/dist/src/web/use-call-tool.js +0 -67
- package/dist/src/web/use-call-tool.js.map +0 -1
- package/dist/src/web/use-call-tool.test.js +0 -66
- package/dist/src/web/use-call-tool.test.js.map +0 -1
- package/dist/src/web/use-openai-global.js.map +0 -1
- package/dist/src/web/use-tool-output.d.ts +0 -3
- package/dist/src/web/use-tool-output.js +0 -5
- package/dist/src/web/use-tool-output.js.map +0 -1
- package/dist/src/web/use-tool-response-metadata.d.ts +0 -3
- package/dist/src/web/use-tool-response-metadata.js +0 -5
- package/dist/src/web/use-tool-response-metadata.js.map +0 -1
- /package/dist/src/web/{use-call-tool.test.d.ts → hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/src/{test/setup.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
package/README.md
CHANGED
|
@@ -97,17 +97,214 @@ export default defineConfig({
|
|
|
97
97
|
});
|
|
98
98
|
```
|
|
99
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
|
+
_Server setup (server/src/index.ts)_
|
|
107
|
+
|
|
108
|
+
```ts
|
|
109
|
+
import { McpServer } from "skybridge/server";
|
|
110
|
+
import { z } from "zod";
|
|
111
|
+
|
|
112
|
+
const server = new McpServer({ name: "my-app", version: "1.0" }, {})
|
|
113
|
+
.widget("search-voyage", {}, {
|
|
114
|
+
description: "Search for trips",
|
|
115
|
+
inputSchema: {
|
|
116
|
+
destination: z.string(),
|
|
117
|
+
departureDate: z.string().optional(),
|
|
118
|
+
},
|
|
119
|
+
outputSchema: {
|
|
120
|
+
results: z.array(z.object({ id: z.string(), name: z.string() })),
|
|
121
|
+
totalCount: z.number(),
|
|
122
|
+
},
|
|
123
|
+
}, async ({ destination }) => {
|
|
124
|
+
// Your tool logic here...
|
|
125
|
+
return { content: [{ type: "text", text: `Found trips to ${destination}` }] };
|
|
126
|
+
})
|
|
127
|
+
.widget("get-details", {}, {
|
|
128
|
+
inputSchema: { tripId: z.string() },
|
|
129
|
+
}, async ({ tripId }) => {
|
|
130
|
+
return { content: [{ type: "text", text: `Details for ${tripId}` }] };
|
|
131
|
+
});
|
|
132
|
+
|
|
133
|
+
// Export the server type for the client
|
|
134
|
+
export type AppType = typeof server;
|
|
135
|
+
```
|
|
136
|
+
|
|
137
|
+
_One-time setup (web/src/skybridge.ts)_
|
|
138
|
+
|
|
139
|
+
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:
|
|
140
|
+
|
|
141
|
+
```ts
|
|
142
|
+
import type { AppType } from "../server"; // type-only import
|
|
143
|
+
import { createTypedHooks } from "skybridge/web";
|
|
144
|
+
|
|
145
|
+
export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
|
|
146
|
+
```
|
|
147
|
+
|
|
148
|
+
_Usage in widgets (web/src/widgets/search.tsx)_
|
|
149
|
+
|
|
150
|
+
```tsx
|
|
151
|
+
import { useCallTool, useToolInfo } from "../skybridge"; // import typed hooks
|
|
152
|
+
|
|
153
|
+
export function SearchWidget() {
|
|
154
|
+
const { callTool, data, isPending } = useCallTool("search-voyage");
|
|
155
|
+
// ^ autocomplete for tool names
|
|
156
|
+
const toolInfo = useToolInfo<"search-voyage">();
|
|
157
|
+
// ^ autocomplete for widget names
|
|
158
|
+
|
|
159
|
+
const handleSearch = () => {
|
|
160
|
+
callTool({ destination: "Spain" });
|
|
161
|
+
// ^ autocomplete for input fields
|
|
162
|
+
};
|
|
163
|
+
|
|
164
|
+
return (
|
|
165
|
+
<div>
|
|
166
|
+
<button onClick={handleSearch} disabled={isPending}>
|
|
167
|
+
Search
|
|
168
|
+
</button>
|
|
169
|
+
{toolInfo.isSuccess && (
|
|
170
|
+
<div>Found {toolInfo.output.totalCount} results</div>
|
|
171
|
+
// ^ typed output
|
|
172
|
+
)}
|
|
173
|
+
</div>
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
```
|
|
177
|
+
|
|
100
178
|
**Hooks**
|
|
101
179
|
|
|
102
|
-
The `skybridge/web` package comes with a set of hooks to help you build your widgets
|
|
180
|
+
The `skybridge/web` package comes with a set of hooks to help you build your widgets :
|
|
181
|
+
|
|
182
|
+
- `useOpenAiGlobal`: A generic hook to get any global data from the OpenAI iFrame skybridge runtime (in `window.openai`).
|
|
183
|
+
- `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.
|
|
184
|
+
- `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.
|
|
185
|
+
- `useToolInfo`: A hook to get the tool input, output, and response metadata with type inference. Provides a discriminated union based on status (pending/success).
|
|
186
|
+
- `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
|
|
187
|
+
- `createTypedHooks`: A factory that creates typed versions of `useCallTool` and `useToolInfo` with full type inference from your server type.
|
|
188
|
+
|
|
189
|
+
_useOpenAiGlobal_
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { useOpenAiGlobal } from "skybridge/web";
|
|
193
|
+
|
|
194
|
+
const theme = useOpenAiGlobal("theme");
|
|
195
|
+
```
|
|
196
|
+
|
|
197
|
+
_useToolOutput_
|
|
103
198
|
|
|
104
199
|
```ts
|
|
105
200
|
import { useToolOutput } from "skybridge/web";
|
|
106
201
|
|
|
107
|
-
// Initial data returned by the tool invocation on structuredOutput
|
|
108
202
|
const toolOutput = useToolOutput();
|
|
109
203
|
```
|
|
110
204
|
|
|
205
|
+
_useToolResponseMetadata_
|
|
206
|
+
|
|
207
|
+
```ts
|
|
208
|
+
import { useToolResponseMetadata } from "skybridge/web";
|
|
209
|
+
|
|
210
|
+
const toolResponseMetadata = useToolResponseMetadata();
|
|
211
|
+
```
|
|
212
|
+
|
|
213
|
+
_useToolInfo_
|
|
214
|
+
|
|
215
|
+
```ts
|
|
216
|
+
import { useToolInfo } from "skybridge/web";
|
|
217
|
+
|
|
218
|
+
const toolInfo = useToolInfo<{
|
|
219
|
+
input: { query: string };
|
|
220
|
+
output: { results: string[] };
|
|
221
|
+
responseMetadata: { id: number };
|
|
222
|
+
}>();
|
|
223
|
+
|
|
224
|
+
// toolInfo.input is typed based on the input type
|
|
225
|
+
// toolInfo.output is typed based on the output type (undefined when pending)
|
|
226
|
+
// toolInfo.status narrows correctly: "pending" | "success"
|
|
227
|
+
|
|
228
|
+
if (toolInfo.isPending) {
|
|
229
|
+
// toolInfo.output is undefined here
|
|
230
|
+
console.log(toolInfo.input.query);
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (toolInfo.isSuccess) {
|
|
234
|
+
// toolInfo.output is typed here
|
|
235
|
+
console.log(toolInfo.output.results);
|
|
236
|
+
}
|
|
237
|
+
```
|
|
238
|
+
|
|
239
|
+
_useToolInfo_ with typed hooks (recommended)
|
|
240
|
+
|
|
241
|
+
```tsx
|
|
242
|
+
import { useToolInfo } from "../skybridge"; // import typed hooks
|
|
243
|
+
|
|
244
|
+
export function SearchWidget() {
|
|
245
|
+
const toolInfo = useToolInfo<"search-voyage">();
|
|
246
|
+
// ^ autocomplete for widget names
|
|
247
|
+
// toolInfo.input is typed as { destination: string; departureDate?: string; ... }
|
|
248
|
+
// toolInfo.output is typed as { results: Array<...>; totalCount: number; } | undefined
|
|
249
|
+
|
|
250
|
+
if (toolInfo.isSuccess) {
|
|
251
|
+
return <div>Found {toolInfo.output.totalCount} results</div>;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
return <div>Searching for {toolInfo.input.destination}...</div>;
|
|
255
|
+
}
|
|
256
|
+
```
|
|
257
|
+
|
|
258
|
+
_useCallTool_ in synchronous mode
|
|
259
|
+
|
|
260
|
+
```ts
|
|
261
|
+
import { useCallTool } from "skybridge/web";
|
|
262
|
+
|
|
263
|
+
export const TestTool: React.FunctionComponent = () => {
|
|
264
|
+
const { callTool, isPending } = useCallTool("myToolName");
|
|
265
|
+
|
|
266
|
+
return (
|
|
267
|
+
<div>
|
|
268
|
+
<button
|
|
269
|
+
disabled={isPending}
|
|
270
|
+
onClick={() => {
|
|
271
|
+
callTool({ input: "test input" }, {
|
|
272
|
+
onSuccess: (data) => {
|
|
273
|
+
alert("Tool returned: " + data);
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
>
|
|
277
|
+
Call Tool inside a widget
|
|
278
|
+
</button>
|
|
279
|
+
</div>
|
|
280
|
+
);
|
|
281
|
+
};
|
|
282
|
+
```
|
|
283
|
+
|
|
284
|
+
_useCallTool_ in asynchronous mode
|
|
285
|
+
|
|
286
|
+
```ts
|
|
287
|
+
import { useCallTool } from "skybridge/web";
|
|
288
|
+
|
|
289
|
+
export const TestTool: React.FunctionComponent = () => {
|
|
290
|
+
const { callToolAsync, isPending } = useCallTool("myToolName");
|
|
291
|
+
|
|
292
|
+
return (
|
|
293
|
+
<div>
|
|
294
|
+
<button
|
|
295
|
+
disabled={isPending}
|
|
296
|
+
onClick={async () => {
|
|
297
|
+
const data = await callToolAsync({ input: "test input" });
|
|
298
|
+
alert("Tool returned: " + data);
|
|
299
|
+
}}
|
|
300
|
+
>
|
|
301
|
+
Call Tool inside a widget
|
|
302
|
+
</button>
|
|
303
|
+
</div>
|
|
304
|
+
);
|
|
305
|
+
};
|
|
306
|
+
```
|
|
307
|
+
|
|
111
308
|
## Migrate your existing MCP server to a ChatGPT app
|
|
112
309
|
|
|
113
310
|
If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
import type { McpServer, WidgetDef } from "./server.js";
|
|
2
|
+
/**
|
|
3
|
+
* Any widget registry shape.
|
|
4
|
+
* Used as a constraint for type parameters that accept widget registries.
|
|
5
|
+
*/
|
|
6
|
+
export type AnyWidgetRegistry = Record<string, WidgetDef>;
|
|
7
|
+
/**
|
|
8
|
+
* Extract the widget registry type from an McpServer instance.
|
|
9
|
+
*
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* type MyWidgets = InferWidgets<MyServer>;
|
|
13
|
+
* // { "search": WidgetDef<...>, "details": WidgetDef<...> }
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
export type InferWidgets<T> = T extends McpServer<infer W extends AnyWidgetRegistry> ? W : T extends McpServer<any> ? never : never;
|
|
17
|
+
/**
|
|
18
|
+
* Get a union of all widget names from an McpServer instance.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```ts
|
|
22
|
+
* type Names = WidgetNames<MyServer>;
|
|
23
|
+
* // "search" | "details" | "profile"
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
export type WidgetNames<T> = keyof InferWidgets<T> & string;
|
|
27
|
+
/**
|
|
28
|
+
* Get the input type for a specific widget.
|
|
29
|
+
*
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* type SearchInput = WidgetInput<MyServer, "search">;
|
|
33
|
+
* ```
|
|
34
|
+
*/
|
|
35
|
+
export type WidgetInput<T, K extends WidgetNames<T>> = InferWidgets<T>[K]["input"];
|
|
36
|
+
/**
|
|
37
|
+
* Get the output type for a specific widget.
|
|
38
|
+
*
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* type SearchOutput = WidgetOutput<MyServer, "search">;
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
export type WidgetOutput<T, K extends WidgetNames<T>> = InferWidgets<T>[K]["output"];
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import type { Resource } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
import type { ZodRawShape } from "zod";
|
|
3
|
+
import type { ZodRawShape, ZodObject, infer as Infer } from "zod";
|
|
4
|
+
export type WidgetDef<TInput = unknown, TOutput = unknown> = {
|
|
5
|
+
input: TInput;
|
|
6
|
+
output: TOutput;
|
|
7
|
+
};
|
|
4
8
|
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
|
|
5
|
-
type McpServerOriginalToolConfig = Omit<Parameters<
|
|
6
|
-
export declare class McpServer extends McpServerBase {
|
|
7
|
-
widget<
|
|
8
|
-
inputSchema?:
|
|
9
|
-
outputSchema?:
|
|
10
|
-
}, toolCallback: ToolCallback<
|
|
9
|
+
type McpServerOriginalToolConfig = Omit<Parameters<McpServerBase["registerTool"]>[1], "inputSchema" | "outputSchema">;
|
|
10
|
+
export declare class McpServer<TWidgets extends Record<string, WidgetDef> = {}> extends McpServerBase {
|
|
11
|
+
widget<TName extends string, TInput extends ZodRawShape, TOutput extends ZodRawShape = {}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
12
|
+
inputSchema?: TInput;
|
|
13
|
+
outputSchema?: TOutput;
|
|
14
|
+
}, toolCallback: ToolCallback<TInput>): McpServer<TWidgets & {
|
|
15
|
+
[K in TName]: WidgetDef<Infer<ZodObject<TInput>>, Infer<ZodObject<TOutput>>>;
|
|
16
|
+
}>;
|
|
17
|
+
private lookupDistFile;
|
|
11
18
|
}
|
|
12
19
|
export {};
|
|
@@ -1,9 +1,13 @@
|
|
|
1
1
|
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { templateHelper } from "./templateHelper.js";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
export class McpServer extends McpServerBase {
|
|
4
6
|
widget(name, resourceConfig, toolConfig, toolCallback) {
|
|
5
7
|
const uri = `ui://widgets/${name}.html`;
|
|
6
|
-
const resourceMetadata = {
|
|
8
|
+
const resourceMetadata = {
|
|
9
|
+
...(resourceConfig._meta ?? {}),
|
|
10
|
+
};
|
|
7
11
|
if (toolConfig.description !== undefined) {
|
|
8
12
|
resourceMetadata["openai/widgetDescription"] = toolConfig.description;
|
|
9
13
|
}
|
|
@@ -15,13 +19,16 @@ export class McpServer extends McpServerBase {
|
|
|
15
19
|
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
16
20
|
extra?.requestInfo?.headers?.host}`
|
|
17
21
|
: `http://localhost:3000`;
|
|
18
|
-
const templateData = {
|
|
19
|
-
serverUrl,
|
|
20
|
-
widgetName: name,
|
|
21
|
-
};
|
|
22
22
|
const html = process.env.NODE_ENV === "production"
|
|
23
|
-
? templateHelper.renderProduction(
|
|
24
|
-
|
|
23
|
+
? templateHelper.renderProduction({
|
|
24
|
+
serverUrl,
|
|
25
|
+
widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
|
|
26
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
27
|
+
})
|
|
28
|
+
: templateHelper.renderDevelopment({
|
|
29
|
+
serverUrl,
|
|
30
|
+
widgetName: name,
|
|
31
|
+
});
|
|
25
32
|
return {
|
|
26
33
|
contents: [
|
|
27
34
|
{
|
|
@@ -35,11 +42,17 @@ export class McpServer extends McpServerBase {
|
|
|
35
42
|
const toolMeta = {
|
|
36
43
|
...toolConfig._meta,
|
|
37
44
|
"openai/outputTemplate": uri,
|
|
45
|
+
"ui/resourceUri": uri,
|
|
38
46
|
};
|
|
39
47
|
this.registerTool(name, {
|
|
40
48
|
...toolConfig,
|
|
41
49
|
_meta: toolMeta,
|
|
42
50
|
}, toolCallback);
|
|
51
|
+
return this;
|
|
52
|
+
}
|
|
53
|
+
lookupDistFile(key) {
|
|
54
|
+
const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
55
|
+
return manifest[key]?.file;
|
|
43
56
|
}
|
|
44
57
|
}
|
|
45
58
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAuD7B,MAAM,OAAO,SAEX,SAAQ,aAAa;IACrB,MAAM,CAKJ,IAAW,EACX,cAA+C,EAC/C,UAGC,EACD,YAAkC;QASlC,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,MAAM,gBAAgB,GAAiB;YACrC,GAAG,CAAC,c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I,EACJ;YACE,GAAG,UAAU;YACb,KAAK,EAAE,QAAQ;SAChB,EACD,YAAY,CACb,CAAC;QAEF,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"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
type TemplateData = {
|
|
2
|
-
serverUrl: string;
|
|
3
|
-
widgetName: string;
|
|
4
|
-
};
|
|
5
1
|
declare class TemplateHelper {
|
|
6
2
|
private templateCache;
|
|
7
3
|
private loadTemplate;
|
|
8
|
-
renderProduction(data:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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;
|
|
12
13
|
}
|
|
13
14
|
export declare const templateHelper: TemplateHelper;
|
|
14
15
|
export {};
|
|
@@ -24,14 +24,6 @@ class TemplateHelper {
|
|
|
24
24
|
const template = this.loadTemplate("development");
|
|
25
25
|
return template(data);
|
|
26
26
|
}
|
|
27
|
-
renderViteClient(data) {
|
|
28
|
-
const template = this.loadTemplate("vite-client");
|
|
29
|
-
return template(data);
|
|
30
|
-
}
|
|
31
|
-
injectViteClient(html, data) {
|
|
32
|
-
const viteClientScript = this.renderViteClient(data);
|
|
33
|
-
return viteClientScript + html;
|
|
34
|
-
}
|
|
35
27
|
}
|
|
36
28
|
export const templateHelper = new TemplateHelper();
|
|
37
29
|
//# sourceMappingURL=templateHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAOtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC;QAC/C,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,
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAA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
|
1
|
+
<base href="{{serverUrl}}" />
|
|
1
2
|
<div id="root"></div>
|
|
2
3
|
<script type="module">
|
|
3
|
-
import('{{serverUrl}}/assets/{{
|
|
4
|
+
import('{{serverUrl}}/assets/{{widgetFile}}');
|
|
4
5
|
</script>
|
|
5
|
-
<link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/
|
|
6
|
+
<link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
|
package/dist/src/test/utils.js
CHANGED
|
@@ -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,
|
|
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;AAEhD;;GAEG;AACH,MAAM,UAAU,mBAAmB;IAKjC,mCAAmC;IACnC,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,OAAO;KACjB,EACD,EAAE,YAAY,EAAE,EAAE,EAAE,CACrB,CAAC;IAEF,6CAA6C;IAC7C,MAAM,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAE1D,OAAO;QACL,MAAM;QACN,YAAY;QACZ,gBAAgB;KACjB,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"}
|
|
@@ -1,10 +1,31 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
2
3
|
import { McpServer } from "../server/server.js";
|
|
3
|
-
import { createMockMcpServer,
|
|
4
|
+
import { createMockExtra, createMockMcpServer, resetTestEnv, setTestEnv, } from "./utils.js";
|
|
5
|
+
const mockManifest = {
|
|
6
|
+
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
7
|
+
"style.css": { file: "style.css" },
|
|
8
|
+
};
|
|
9
|
+
vi.mock("node:fs", async () => {
|
|
10
|
+
const actual = await vi.importActual("node:fs");
|
|
11
|
+
const readFileSync = vi.fn((path, ...args) => {
|
|
12
|
+
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
13
|
+
return JSON.stringify(mockManifest);
|
|
14
|
+
}
|
|
15
|
+
return actual.readFileSync(path, ...args);
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
readFileSync,
|
|
19
|
+
default: {
|
|
20
|
+
readFileSync,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
4
24
|
describe("McpServer.widget", () => {
|
|
5
25
|
let server;
|
|
6
26
|
let mockResource;
|
|
7
27
|
let mockRegisterTool;
|
|
28
|
+
let readFileSyncSpy = null;
|
|
8
29
|
beforeEach(() => {
|
|
9
30
|
({ server, mockResource, mockRegisterTool } = createMockMcpServer());
|
|
10
31
|
});
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,
|
|
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,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,YAAY;QACZ,OAAO,EAAE;YACP,YAAY;SACb;KACF,CAAC;AACJ,CAAC,CAAC,CAAC;AAEH,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,MAAiB,CAAC;IACtB,IAAI,YAA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,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"}
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useFiles } from "./use-files.js";
|
|
4
|
+
export { useLocale } from "./use-locale.js";
|
|
5
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
8
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
9
|
+
export { useTheme } from "./use-theme.js";
|
|
10
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
11
|
+
export { useToolOutput } from "./use-tool-output.js";
|
|
12
|
+
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
13
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
14
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useFiles } from "./use-files.js";
|
|
4
|
+
export { useLocale } from "./use-locale.js";
|
|
5
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
7
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
8
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
9
|
+
export { useTheme } from "./use-theme.js";
|
|
10
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
11
|
+
export { useToolOutput } from "./use-tool-output.js";
|
|
12
|
+
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
13
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
14
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
15
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import type { CallToolArgs, CallToolResponse } from "../types.js";
|
|
2
|
+
type SideEffects<ToolArgs, ToolResponse> = {
|
|
3
|
+
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
4
|
+
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
5
|
+
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
6
|
+
};
|
|
7
|
+
type CallToolAsyncFn<ToolArgs, ToolResponse> = ToolArgs extends null ? () => Promise<ToolResponse> : (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
8
|
+
type ToolResponseSignature = Pick<CallToolResponse, "structuredContent" | "meta">;
|
|
9
|
+
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends Partial<ToolResponseSignature> = {}>(name: string) => {
|
|
10
|
+
callTool: {
|
|
11
|
+
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
12
|
+
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
13
|
+
};
|
|
14
|
+
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
15
|
+
status: "idle";
|
|
16
|
+
isIdle: true;
|
|
17
|
+
isPending: false;
|
|
18
|
+
isSuccess: false;
|
|
19
|
+
isError: false;
|
|
20
|
+
data: undefined;
|
|
21
|
+
error: undefined;
|
|
22
|
+
} | {
|
|
23
|
+
callTool: {
|
|
24
|
+
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
25
|
+
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
26
|
+
};
|
|
27
|
+
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
28
|
+
status: "pending";
|
|
29
|
+
isIdle: false;
|
|
30
|
+
isPending: true;
|
|
31
|
+
isSuccess: false;
|
|
32
|
+
isError: false;
|
|
33
|
+
data: undefined;
|
|
34
|
+
error: undefined;
|
|
35
|
+
} | {
|
|
36
|
+
callTool: {
|
|
37
|
+
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
38
|
+
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
39
|
+
};
|
|
40
|
+
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
41
|
+
status: "error";
|
|
42
|
+
isIdle: false;
|
|
43
|
+
isPending: false;
|
|
44
|
+
isSuccess: false;
|
|
45
|
+
isError: true;
|
|
46
|
+
data: undefined;
|
|
47
|
+
error: unknown;
|
|
48
|
+
} | {
|
|
49
|
+
callTool: {
|
|
50
|
+
(sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
51
|
+
(toolArgs: ToolArgs, sideEffects?: SideEffects<ToolArgs, CallToolResponse & ToolResponse>): void;
|
|
52
|
+
};
|
|
53
|
+
callToolAsync: CallToolAsyncFn<ToolArgs, CallToolResponse & ToolResponse>;
|
|
54
|
+
status: "success";
|
|
55
|
+
isIdle: false;
|
|
56
|
+
isPending: false;
|
|
57
|
+
isSuccess: true;
|
|
58
|
+
isError: false;
|
|
59
|
+
data: CallToolResponse & ToolResponse;
|
|
60
|
+
error: undefined;
|
|
61
|
+
};
|
|
62
|
+
export {};
|