skybridge 0.0.0-dev.d8535f2 → 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.
Files changed (60) hide show
  1. package/README.md +125 -0
  2. package/dist/src/server/index.d.ts +2 -0
  3. package/dist/src/server/inferUtilityTypes.d.ts +44 -0
  4. package/dist/src/server/inferUtilityTypes.js +2 -0
  5. package/dist/src/server/inferUtilityTypes.js.map +1 -0
  6. package/dist/src/server/server.d.ts +13 -7
  7. package/dist/src/server/server.js +5 -1
  8. package/dist/src/server/server.js.map +1 -1
  9. package/dist/src/test/utils.js +1 -1
  10. package/dist/src/test/utils.js.map +1 -1
  11. package/dist/src/web/hooks/index.d.ts +2 -1
  12. package/dist/src/web/hooks/index.js +2 -1
  13. package/dist/src/web/hooks/index.js.map +1 -1
  14. package/dist/src/web/hooks/use-call-tool.d.ts +30 -22
  15. package/dist/src/web/hooks/use-call-tool.js +28 -4
  16. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  17. package/dist/src/web/hooks/use-call-tool.test.js +99 -2
  18. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  19. package/dist/src/web/hooks/use-files.d.ts +10 -0
  20. package/dist/src/web/hooks/use-files.js +7 -0
  21. package/dist/src/web/hooks/use-files.js.map +1 -0
  22. package/dist/src/web/hooks/use-files.test.js +29 -0
  23. package/dist/src/web/hooks/use-files.test.js.map +1 -0
  24. package/dist/src/web/hooks/use-request-modal.d.ts +3 -2
  25. package/dist/src/web/hooks/use-request-modal.js.map +1 -1
  26. package/dist/src/web/hooks/use-tool-info.d.ts +19 -12
  27. package/dist/src/web/hooks/use-tool-info.js +3 -2
  28. package/dist/src/web/hooks/use-tool-info.js.map +1 -1
  29. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  30. package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
  31. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  32. package/dist/src/web/hooks/use-tool-info.test.js +30 -29
  33. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
  34. package/dist/src/web/hooks/use-widget-state.test.js +0 -1
  35. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -1
  36. package/dist/src/web/index.d.ts +1 -0
  37. package/dist/src/web/index.js +1 -0
  38. package/dist/src/web/index.js.map +1 -1
  39. package/dist/src/web/mount-widget.js +5 -0
  40. package/dist/src/web/mount-widget.js.map +1 -1
  41. package/dist/src/web/proxy.d.ts +1 -0
  42. package/dist/src/web/proxy.js +48 -0
  43. package/dist/src/web/proxy.js.map +1 -0
  44. package/dist/src/web/typed-hooks.d.ts +107 -0
  45. package/dist/src/web/typed-hooks.js +111 -0
  46. package/dist/src/web/typed-hooks.js.map +1 -0
  47. package/dist/src/web/typed-hooks.test-d.d.ts +1 -0
  48. package/dist/src/web/typed-hooks.test-d.js +72 -0
  49. package/dist/src/web/typed-hooks.test-d.js.map +1 -0
  50. package/dist/src/web/typed-hooks.test.d.ts +1 -0
  51. package/dist/src/web/typed-hooks.test.js +10 -0
  52. package/dist/src/web/typed-hooks.test.js.map +1 -0
  53. package/dist/src/web/types.d.ts +24 -16
  54. package/dist/src/web/types.js.map +1 -1
  55. package/dist/vitest.config.js +0 -1
  56. package/dist/vitest.config.js.map +1 -1
  57. package/package.json +1 -1
  58. package/dist/src/test/setup.js +0 -9
  59. package/dist/src/test/setup.js.map +0 -1
  60. /package/dist/src/{test/setup.d.ts → web/hooks/use-files.test.d.ts} +0 -0
package/README.md CHANGED
@@ -97,6 +97,84 @@ 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
180
  The `skybridge/web` package comes with a set of hooks to help you build your widgets :
@@ -104,7 +182,9 @@ The `skybridge/web` package comes with a set of hooks to help you build your wid
104
182
  - `useOpenAiGlobal`: A generic hook to get any global data from the OpenAI iFrame skybridge runtime (in `window.openai`).
105
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.
106
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).
107
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.
108
188
 
109
189
  _useOpenAiGlobal_
110
190
 
@@ -130,6 +210,51 @@ import { useToolResponseMetadata } from "skybridge/web";
130
210
  const toolResponseMetadata = useToolResponseMetadata();
131
211
  ```
132
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
+
133
258
  _useCallTool_ in synchronous mode
134
259
 
135
260
  ```ts
@@ -1,2 +1,4 @@
1
1
  export { McpServer } from "./server.js";
2
2
  export { widgetsDevServer } from "./widgetsDevServer.js";
3
+ export type { WidgetDef } from "./server.js";
4
+ export type { InferWidgets, AnyWidgetRegistry, WidgetNames, WidgetInput, WidgetOutput, } from "./inferUtilityTypes.js";
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=inferUtilityTypes.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
@@ -1,13 +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<McpServer["registerTool"]>[1], "inputSchema" | "outputSchema">;
6
- export declare class McpServer extends McpServerBase {
7
- widget<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(name: string, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
8
- inputSchema?: InputArgs;
9
- outputSchema?: OutputArgs;
10
- }, toolCallback: ToolCallback<InputArgs>): void;
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
+ }>;
11
17
  private lookupDistFile;
12
18
  }
13
19
  export {};
@@ -5,7 +5,9 @@ import path from "node:path";
5
5
  export class McpServer extends McpServerBase {
6
6
  widget(name, resourceConfig, toolConfig, toolCallback) {
7
7
  const uri = `ui://widgets/${name}.html`;
8
- const resourceMetadata = { ...(resourceConfig._meta ?? {}) };
8
+ const resourceMetadata = {
9
+ ...(resourceConfig._meta ?? {}),
10
+ };
9
11
  if (toolConfig.description !== undefined) {
10
12
  resourceMetadata["openai/widgetDescription"] = toolConfig.description;
11
13
  }
@@ -40,11 +42,13 @@ export class McpServer extends McpServerBase {
40
42
  const toolMeta = {
41
43
  ...toolConfig._meta,
42
44
  "openai/outputTemplate": uri,
45
+ "ui/resourceUri": uri,
43
46
  };
44
47
  this.registerTool(name, {
45
48
  ...toolConfig,
46
49
  _meta: toolMeta,
47
50
  }, toolCallback);
51
+ return this;
48
52
  }
49
53
  lookupDistFile(key) {
50
54
  const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
@@ -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;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AA4B7B,MAAM,OAAO,SAAU,SAAQ,aAAa;IAC1C,MAAM,CACJ,IAAY,EACZ,cAA+C,EAC/C,UAGC,EACD,YAAqC;QAErC,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,MAAM,gBAAgB,GAAiB,EAAE,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,EAAE,CAAC;QAC3E,IAAI,UAAU,CA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
2
+ import { McpServer } from "../server/server.js";
3
3
  /**
4
4
  * Creates a real McpServer instance for testing
5
5
  */
@@ -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,SAAS,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE5E;;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
+ {"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,8 +1,9 @@
1
1
  export { useCallTool } from "./use-call-tool.js";
2
2
  export { useDisplayMode } from "./use-display-mode.js";
3
+ export { useFiles } from "./use-files.js";
3
4
  export { useLocale } from "./use-locale.js";
4
- export { useOpenExternal } from "./use-open-external.js";
5
5
  export { useOpenAiGlobal } from "./use-openai-global.js";
6
+ export { useOpenExternal } from "./use-open-external.js";
6
7
  export { useRequestModal } from "./use-request-modal.js";
7
8
  export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
8
9
  export { useTheme } from "./use-theme.js";
@@ -1,8 +1,9 @@
1
1
  export { useCallTool } from "./use-call-tool.js";
2
2
  export { useDisplayMode } from "./use-display-mode.js";
3
+ export { useFiles } from "./use-files.js";
3
4
  export { useLocale } from "./use-locale.js";
4
- export { useOpenExternal } from "./use-open-external.js";
5
5
  export { useOpenAiGlobal } from "./use-openai-global.js";
6
+ export { useOpenExternal } from "./use-open-external.js";
6
7
  export { useRequestModal } from "./use-request-modal.js";
7
8
  export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
8
9
  export { useTheme } from "./use-theme.js";
@@ -1 +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,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"}
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"}
@@ -1,10 +1,17 @@
1
1
  import type { CallToolArgs, CallToolResponse } from "../types.js";
2
- export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string) => {
3
- callTool: (toolArgs: ToolArgs, sideEffects?: {
4
- onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
5
- onError?: (error: unknown, toolArgs: ToolArgs) => void;
6
- }) => void;
7
- callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
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>;
8
15
  status: "idle";
9
16
  isIdle: true;
10
17
  isPending: false;
@@ -13,11 +20,11 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
13
20
  data: undefined;
14
21
  error: undefined;
15
22
  } | {
16
- callTool: (toolArgs: ToolArgs, sideEffects?: {
17
- onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
18
- onError?: (error: unknown, toolArgs: ToolArgs) => void;
19
- }) => void;
20
- callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
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>;
21
28
  status: "pending";
22
29
  isIdle: false;
23
30
  isPending: true;
@@ -26,11 +33,11 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
26
33
  data: undefined;
27
34
  error: undefined;
28
35
  } | {
29
- callTool: (toolArgs: ToolArgs, sideEffects?: {
30
- onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
31
- onError?: (error: unknown, toolArgs: ToolArgs) => void;
32
- }) => void;
33
- callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
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>;
34
41
  status: "error";
35
42
  isIdle: false;
36
43
  isPending: false;
@@ -39,16 +46,17 @@ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolRes
39
46
  data: undefined;
40
47
  error: unknown;
41
48
  } | {
42
- callTool: (toolArgs: ToolArgs, sideEffects?: {
43
- onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
44
- onError?: (error: unknown, toolArgs: ToolArgs) => void;
45
- }) => void;
46
- callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
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>;
47
54
  status: "success";
48
55
  isIdle: false;
49
56
  isPending: false;
50
57
  isSuccess: true;
51
58
  isError: false;
52
- data: ToolResponse;
59
+ data: CallToolResponse & ToolResponse;
53
60
  error: undefined;
54
61
  };
62
+ export {};
@@ -1,7 +1,7 @@
1
1
  import { useState } from "react";
2
2
  export const useCallTool = (name) => {
3
3
  const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
4
- const callToolAsync = async (toolArgs) => {
4
+ const execute = async (toolArgs) => {
5
5
  setCallToolState({ status: "pending", data: undefined, error: undefined });
6
6
  try {
7
7
  const data = await window.openai.callTool(name, toolArgs);
@@ -13,19 +13,43 @@ export const useCallTool = (name) => {
13
13
  throw error;
14
14
  }
15
15
  };
16
- const callTool = (toolArgs, sideEffects) => {
17
- callToolAsync(toolArgs)
16
+ const callToolAsync = (async (toolArgs) => {
17
+ if (toolArgs === undefined) {
18
+ return execute(null);
19
+ }
20
+ return execute(toolArgs);
21
+ });
22
+ function callTool(firstArg, sideEffects) {
23
+ let toolArgs;
24
+ if (firstArg &&
25
+ typeof firstArg === "object" &&
26
+ ("onSuccess" in firstArg ||
27
+ "onError" in firstArg ||
28
+ "onSettled" in firstArg)) {
29
+ toolArgs = null; // no toolArgs provided
30
+ sideEffects = firstArg;
31
+ }
32
+ else {
33
+ toolArgs = (firstArg === undefined ? null : firstArg);
34
+ }
35
+ execute(toolArgs)
18
36
  .then((data) => {
19
37
  if (sideEffects?.onSuccess) {
20
38
  sideEffects.onSuccess(data, toolArgs);
21
39
  }
40
+ if (sideEffects?.onSettled) {
41
+ sideEffects.onSettled(data, undefined, toolArgs);
42
+ }
22
43
  })
23
44
  .catch((error) => {
24
45
  if (sideEffects?.onError) {
25
46
  sideEffects.onError(error, toolArgs);
26
47
  }
48
+ if (sideEffects?.onSettled) {
49
+ sideEffects.onSettled(undefined, error, toolArgs);
50
+ }
27
51
  });
28
- };
52
+ }
29
53
  const callToolState = {
30
54
  status,
31
55
  data,
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4BjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IACF,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,EAAE,KAAK,EAAE,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAK1D,EAAE,MAAM,EAAE,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;IAEzD,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;QACjD,gBAAgB,CAAC,EAAE,MAAM,EAAE,SAAS,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,SAAS,EAAE,CAAC,CAAC;QAC3E,IAAI,CAAC;YACH,MAAM,IAAI,GAAG,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GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
@@ -1,6 +1,6 @@
1
+ import { act, renderHook, waitFor } from "@testing-library/react";
2
+ import { afterEach, beforeEach, describe, expect, it, vi, expectTypeOf, } from "vitest";
1
3
  import { useCallTool } from "./use-call-tool.js";
2
- import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
3
- import { renderHook, act, waitFor } from "@testing-library/react";
4
4
  describe("useCallTool - onSuccess callback", () => {
5
5
  let OpenaiMock;
6
6
  beforeEach(() => {
@@ -62,5 +62,102 @@ describe("useCallTool - onSuccess callback", () => {
62
62
  expect(onError).toHaveBeenCalledWith(error, args);
63
63
  });
64
64
  });
65
+ it("should call onSettled callback with data and undefined error on successful execution", async () => {
66
+ const onSuccess = vi.fn();
67
+ const onError = vi.fn();
68
+ const onSettled = vi.fn();
69
+ OpenaiMock.callTool.mockResolvedValueOnce(data);
70
+ const { result } = renderHook(() => useCallTool(toolName));
71
+ act(() => {
72
+ result.current.callTool(args, {
73
+ onSuccess,
74
+ onError,
75
+ onSettled,
76
+ });
77
+ });
78
+ await waitFor(() => {
79
+ expect(onSuccess).toHaveBeenCalledWith(data, args);
80
+ expect(onSettled).toHaveBeenCalledWith(data, undefined, args);
81
+ expect(onError).not.toHaveBeenCalled();
82
+ });
83
+ });
84
+ it("should call onSettled callback with undefined data and error on failed execution", async () => {
85
+ const onSuccess = vi.fn();
86
+ const onError = vi.fn();
87
+ const onSettled = vi.fn();
88
+ OpenaiMock.callTool.mockRejectedValueOnce(error);
89
+ const { result } = renderHook(() => useCallTool(toolName));
90
+ act(() => {
91
+ result.current.callTool(args, {
92
+ onSuccess,
93
+ onError,
94
+ onSettled,
95
+ });
96
+ });
97
+ await waitFor(() => {
98
+ expect(onError).toHaveBeenCalledWith(error, args);
99
+ expect(onSettled).toHaveBeenCalledWith(undefined, error, args);
100
+ expect(onSuccess).not.toHaveBeenCalled();
101
+ });
102
+ });
103
+ });
104
+ describe("useCallTool - TypeScript typing", () => {
105
+ let OpenaiMock;
106
+ beforeEach(() => {
107
+ OpenaiMock = {
108
+ callTool: vi.fn(),
109
+ };
110
+ vi.stubGlobal("openai", OpenaiMock);
111
+ });
112
+ afterEach(() => {
113
+ vi.unstubAllGlobals();
114
+ vi.resetAllMocks();
115
+ });
116
+ it("should have correct return types when ToolArgs is null and ToolResponse is specified", () => {
117
+ const { result } = renderHook(() => useCallTool("test-tool"));
118
+ const data = {
119
+ content: [{ type: "text", text: "test" }],
120
+ structuredContent: { result: "test" },
121
+ isError: false,
122
+ result: "test",
123
+ meta: { id: 123 },
124
+ };
125
+ OpenaiMock.callTool.mockResolvedValueOnce(data);
126
+ act(() => {
127
+ result.current.callTool();
128
+ });
129
+ expect(OpenaiMock.callTool).toHaveBeenCalledWith("test-tool", null);
130
+ expectTypeOf(result.current.data);
131
+ });
132
+ it("should correctly type callToolAsync return value", async () => {
133
+ const { result } = renderHook(() => useCallTool("test-tool"));
134
+ const testArgs = { query: "test" };
135
+ const mockResponse = {
136
+ content: [{ type: "text", text: "answer" }],
137
+ structuredContent: { answer: "test answer" },
138
+ isError: false,
139
+ result: "answer",
140
+ meta: {},
141
+ };
142
+ OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
143
+ const promise = result.current.callToolAsync(testArgs);
144
+ expectTypeOf(promise);
145
+ const resolvedValue = await promise;
146
+ expect(resolvedValue).toEqual(mockResponse);
147
+ });
148
+ it("should correctly type callToolAsync when ToolArgs is null", async () => {
149
+ const { result } = renderHook(() => useCallTool("test-tool"));
150
+ const mockResponse = {
151
+ content: [{ type: "text", text: "data" }],
152
+ structuredContent: { data: "test data" },
153
+ isError: false,
154
+ result: "data",
155
+ };
156
+ OpenaiMock.callTool.mockResolvedValueOnce(mockResponse);
157
+ const promise = result.current.callToolAsync();
158
+ expectTypeOf(promise);
159
+ const resolvedValue = await promise;
160
+ expect(resolvedValue).toEqual(mockResponse);
161
+ });
65
162
  });
66
163
  //# sourceMappingURL=use-call-tool.test.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"use-call-tool.test.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-call-tool.test.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,UAAU,EAAE,GAAG,EAAE,OAAO,EAAE,MAAM,wBAAwB,CAAC;AAElE,QAAQ,CAAC,kCAAkC,EAAE,GAAG,EAAE;IAChD,IAAI,UAA8B,CAAC;IAEnC,UAAU,CAAC,GAAG,EAAE;QACd,UAAU,GAAG;YACX,QAAQ,EAAE,EAAE,CAAC,EAAE,EAAE;SAClB,CAAC;QACF,EAAE,CAAC,UAAU,CAAC,QAAQ,EAAE,UAAU,CAAC,CAAC;IACtC,CAAC,CAAC,CAAC;IAEH,SAAS,CAAC,GAAG,EAAE;QACb,EAAE,CAAC,gBAAgB,EAAE,CAAC;QACtB,EAAE,CAAC,aAAa,EAAE,CAAC;IACrB,CAAC,CAAC,CAAC;IAEH,MAAM,QAAQ,GAAG,WAAW,CAAC;IAC7B,MAAM,IAAI,GAAG,EAAE,KAAK,EAAE,YAAY,EAAE,CAAC;IACrC,MAAM,IAAI,GAAG;QACX,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAe,EAAE,IAAI,EAAE,aAAa,EAAE,CAAC;QACzD,iBAAiB,EAAE,EAAE,MAAM,EAAE,MAAM,EAAE;QACrC,OAAO,EAAE,KAAK;QACd,MAAM,EAAE,aAAa;QACrB,IAAI,EAAE,EAAE;KACT,CAAC;IACF,MAAM,KAAK,GAAG,IAAI,KAAK,CAAC,YAAY,CAAC,CAAC;IAEtC,EAAE,CAAC,2DAA2D,EAAE,KAAK,IAAI,EAAE;QACzE,MAAM,EAAE,MAAM,EAAE,GAAG,UAAU,CAAC,GA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EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;YACxC,OAAO,EAAE,KAAK;YACd,MAAM,EAAE,MAAM;SACf,CAAC;QAEF,UAAU,CAAC,QAAQ,CAAC,qBAAqB,CAAC,YAAY,CAAC,CAAC;QAExD,MAAM,OAAO,GAAG,MAAM,CAAC,OAAO,CAAC,aAAa,EAAE,CAAC;QAC/C,YAAY,CAA+B,OAAO,CAAC,CAAC;QAEpD,MAAM,aAAa,GAAG,MAAM,OAAO,CAAC;QACpC,MAAM,CAAC,aAAa,CAAC,CAAC,OAAO,CAAC,YAAY,CAAC,CAAC;IAC9C,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
@@ -0,0 +1,10 @@
1
+ export declare function useFiles(): {
2
+ upload: (file: File) => Promise<{
3
+ fileId: string;
4
+ }>;
5
+ download: (file: {
6
+ fileId: string;
7
+ }) => Promise<{
8
+ downloadUrl: string;
9
+ }>;
10
+ };
@@ -0,0 +1,7 @@
1
+ export function useFiles() {
2
+ return {
3
+ upload: window.openai.uploadFile,
4
+ download: window.openai.downloadFile,
5
+ };
6
+ }
7
+ //# sourceMappingURL=use-files.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-files.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-files.ts"],"names":[],"mappings":"AAAA,MAAM,UAAU,QAAQ;IACtB,OAAO;QACL,MAAM,EAAE,MAAM,CAAC,MAAM,CAAC,UAAU;QAChC,QAAQ,EAAE,MAAM,CAAC,MAAM,CAAC,YAAY;KACrC,CAAC;AACJ,CAAC"}