skybridge 0.0.0-dev.e3e0986 → 0.0.0-dev.e667e59

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 (71) hide show
  1. package/README.md +62 -11
  2. package/dist/src/server/index.d.ts +2 -2
  3. package/dist/src/server/inferUtilityTypes.d.ts +36 -15
  4. package/dist/src/server/server.d.ts +38 -9
  5. package/dist/src/server/server.js +4 -0
  6. package/dist/src/server/server.js.map +1 -1
  7. package/dist/src/test/utils.d.ts +61 -0
  8. package/dist/src/test/utils.js +121 -0
  9. package/dist/src/test/utils.js.map +1 -1
  10. package/dist/src/web/data-llm.d.ts +13 -0
  11. package/dist/src/web/data-llm.js +67 -0
  12. package/dist/src/web/data-llm.js.map +1 -0
  13. package/dist/src/web/data-llm.test.js +76 -0
  14. package/dist/src/web/data-llm.test.js.map +1 -0
  15. package/dist/src/web/generate-helpers.d.ts +113 -0
  16. package/dist/src/web/generate-helpers.js +109 -0
  17. package/dist/src/web/generate-helpers.js.map +1 -0
  18. package/dist/src/web/generate-helpers.test-d.js +153 -0
  19. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  20. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  21. package/dist/src/web/generate-helpers.test.js +17 -0
  22. package/dist/src/web/generate-helpers.test.js.map +1 -0
  23. package/dist/src/web/hooks/index.d.ts +1 -3
  24. package/dist/src/web/hooks/index.js +1 -3
  25. package/dist/src/web/hooks/index.js.map +1 -1
  26. package/dist/src/web/hooks/use-call-tool.d.ts +57 -19
  27. package/dist/src/web/hooks/use-call-tool.js +7 -15
  28. package/dist/src/web/hooks/use-call-tool.js.map +1 -1
  29. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  30. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  31. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  32. package/dist/src/web/hooks/use-call-tool.test.js +17 -9
  33. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
  34. package/dist/src/web/hooks/use-tool-info.d.ts +1 -1
  35. package/dist/src/web/hooks/use-widget-state.js +30 -6
  36. package/dist/src/web/hooks/use-widget-state.js.map +1 -1
  37. package/dist/src/web/index.d.ts +3 -2
  38. package/dist/src/web/index.js +3 -2
  39. package/dist/src/web/index.js.map +1 -1
  40. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  41. package/dist/src/web/plugin/data-llm.test.js +81 -0
  42. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  43. package/dist/src/web/{plugin.js → plugin/plugin.js} +5 -0
  44. package/dist/src/web/plugin/plugin.js.map +1 -0
  45. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  46. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  47. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  48. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  49. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  50. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  51. package/dist/src/web/types.d.ts +14 -0
  52. package/dist/src/web/types.js +1 -0
  53. package/dist/src/web/types.js.map +1 -1
  54. package/package.json +4 -2
  55. package/dist/src/web/hooks/use-tool-output.d.ts +0 -4
  56. package/dist/src/web/hooks/use-tool-output.js +0 -9
  57. package/dist/src/web/hooks/use-tool-output.js.map +0 -1
  58. package/dist/src/web/hooks/use-tool-response-metadata.d.ts +0 -4
  59. package/dist/src/web/hooks/use-tool-response-metadata.js +0 -8
  60. package/dist/src/web/hooks/use-tool-response-metadata.js.map +0 -1
  61. package/dist/src/web/plugin.js.map +0 -1
  62. package/dist/src/web/typed-hooks.d.ts +0 -61
  63. package/dist/src/web/typed-hooks.js +0 -61
  64. package/dist/src/web/typed-hooks.js.map +0 -1
  65. package/dist/src/web/typed-hooks.test-d.js +0 -72
  66. package/dist/src/web/typed-hooks.test-d.js.map +0 -1
  67. package/dist/src/web/typed-hooks.test.js +0 -10
  68. package/dist/src/web/typed-hooks.test.js.map +0 -1
  69. /package/dist/src/web/{typed-hooks.test-d.d.ts → data-llm.test.d.ts} +0 -0
  70. /package/dist/src/web/{typed-hooks.test.d.ts → generate-helpers.test-d.d.ts} +0 -0
  71. /package/dist/src/web/{plugin.d.ts → plugin/plugin.d.ts} +0 -0
package/README.md CHANGED
@@ -101,6 +101,56 @@ export default defineConfig({
101
101
 
102
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
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
+
104
154
  _Server setup (server/src/index.ts)_
105
155
 
106
156
  ```ts
@@ -116,6 +166,7 @@ const server = new McpServer({ name: "my-app", version: "1.0" }, {})
116
166
  },
117
167
  outputSchema: {
118
168
  results: z.array(z.object({ id: z.string(), name: z.string() })),
169
+ totalCount: z.number(),
119
170
  },
120
171
  }, async ({ destination }) => {
121
172
  // Your tool logic here...
@@ -133,13 +184,13 @@ export type AppType = typeof server;
133
184
 
134
185
  _One-time setup (web/src/skybridge.ts)_
135
186
 
136
- Create typed hooks once and export them for use across your app:
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:
137
188
 
138
189
  ```ts
139
190
  import type { AppType } from "../server"; // type-only import
140
- import { createTypedHooks } from "skybridge/web";
191
+ import { generateHelpers } from "skybridge/web";
141
192
 
142
- export const { useCallTool, useToolInfo } = createTypedHooks<AppType>();
193
+ export const { useCallTool, useToolInfo } = generateHelpers<AppType>();
143
194
  ```
144
195
 
145
196
  _Usage in widgets (web/src/widgets/search.tsx)_
@@ -164,7 +215,7 @@ export function SearchWidget() {
164
215
  Search
165
216
  </button>
166
217
  {toolInfo.isSuccess && (
167
- <div>Found {toolInfo.output.totalCount} results</div>
218
+ <div>Found {toolInfo.output.structuredContent.totalCount} results</div>
168
219
  // ^ typed output
169
220
  )}
170
221
  </div>
@@ -181,7 +232,7 @@ The `skybridge/web` package comes with a set of hooks to help you build your wid
181
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.
182
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).
183
234
  - `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
184
- - `createTypedHooks`: A factory that creates typed versions of `useCallTool` and `useToolInfo` with full type inference from your server type.
235
+ - `generateHelpers`: A factory that creates typed versions of `useCallTool` and `useToolInfo` with full type inference from your server type.
185
236
 
186
237
  _useOpenAiGlobal_
187
238
 
@@ -219,17 +270,17 @@ const toolInfo = useToolInfo<{
219
270
  }>();
220
271
 
221
272
  // toolInfo.input is typed based on the input type
222
- // toolInfo.output is typed based on the output type (undefined when pending)
273
+ // toolInfo.output.structuredContent is typed based on the output type (undefined when pending)
223
274
  // toolInfo.status narrows correctly: "pending" | "success"
224
275
 
225
276
  if (toolInfo.isPending) {
226
- // toolInfo.output is undefined here
277
+ // toolInfo.output is undefined here (pending state)
227
278
  console.log(toolInfo.input.query);
228
279
  }
229
280
 
230
281
  if (toolInfo.isSuccess) {
231
- // toolInfo.output is typed here
232
- console.log(toolInfo.output.results);
282
+ // toolInfo.output.structuredContent is typed here
283
+ console.log(toolInfo.output.structuredContent.results);
233
284
  }
234
285
  ```
235
286
 
@@ -242,10 +293,10 @@ export function SearchWidget() {
242
293
  const toolInfo = useToolInfo<"search-voyage">();
243
294
  // ^ autocomplete for widget names
244
295
  // toolInfo.input is typed as { destination: string; departureDate?: string; ... }
245
- // toolInfo.output is typed as { results: Array<...>; totalCount: number; } | undefined
296
+ // toolInfo.output.structuredContent is typed as { results: Array<...>; totalCount: number; }
246
297
 
247
298
  if (toolInfo.isSuccess) {
248
- return <div>Found {toolInfo.output.totalCount} results</div>;
299
+ return <div>Found {toolInfo.output.structuredContent.totalCount} results</div>;
249
300
  }
250
301
 
251
302
  return <div>Searching for {toolInfo.input.destination}...</div>;
@@ -1,4 +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";
3
+ export type { ToolDef, McpServerTypes } from "./server.js";
4
+ export type { InferTools, AnyToolRegistry, ToolNames, ToolInput, ToolOutput, } from "./inferUtilityTypes.js";
@@ -1,33 +1,54 @@
1
- import type { McpServer, WidgetDef } from "./server.js";
2
- /** Any widget registry shape */
3
- export type AnyWidgetRegistry = Record<string, WidgetDef>;
1
+ import type { McpServerTypes, ToolDef } from "./server.js";
4
2
  /**
5
- * Extract the widget registry type from an McpServer instance.
3
+ * Any tool registry shape (includes both widgets and regular tools).
4
+ * Used as a constraint for type parameters that accept tool registries.
5
+ */
6
+ export type AnyToolRegistry = Record<string, ToolDef>;
7
+ /**
8
+ * Extract the tool registry type from an McpServer instance.
9
+ * This includes both widgets (registered via widget()) and regular tools (registered via registerTool()).
10
+ *
11
+ * Uses the `$types` property pattern for cross-package type inference.
12
+ * This works across package boundaries because TypeScript uses structural typing
13
+ * on the shape of `$types`, rather than nominal typing on the McpServer class itself.
14
+ *
15
+ * @example
16
+ * ```ts
17
+ * type MyTools = InferTools<MyServer>;
18
+ * // { "search": ToolDef<...>, "calculate": ToolDef<...> }
19
+ * ```
20
+ */
21
+ export type InferTools<ServerType> = ServerType extends {
22
+ $types: McpServerTypes<infer W>;
23
+ } ? W : never;
24
+ type ExtractTool<ServerType, K extends ToolNames<ServerType>> = InferTools<ServerType>[K];
25
+ /**
26
+ * Get a union of all tool names from an McpServer instance.
27
+ * This includes both widgets and regular tools.
6
28
  *
7
29
  * @example
8
30
  * ```ts
9
- * type MyWidgets = InferWidgets<MyServer>;
10
- * // { "search": WidgetDef<...>, "details": WidgetDef<...> }
31
+ * type Names = ToolNames<MyServer>;
32
+ * // "search" | "calculate" | "details"
11
33
  * ```
12
34
  */
13
- export type InferWidgets<T> = T extends McpServer<infer W extends AnyWidgetRegistry> ? W : T extends McpServer<any> ? never : "Error: T must be an McpServer instance";
14
- /** Get a union of all widget names from an McpServer instance */
15
- export type WidgetNames<T> = keyof InferWidgets<T> & string;
35
+ export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
16
36
  /**
17
- * Get the input type for a specific widget.
37
+ * Get the input type for a specific tool (widget or regular tool).
18
38
  *
19
39
  * @example
20
40
  * ```ts
21
- * type SearchInput = WidgetInput<MyServer, "search">;
41
+ * type SearchInput = ToolInput<MyServer, "search">;
22
42
  * ```
23
43
  */
24
- export type WidgetInput<T, K extends WidgetNames<T>> = InferWidgets<T> extends Record<string, WidgetDef> ? K extends keyof InferWidgets<T> ? InferWidgets<T>[K]["input"] : never : never;
44
+ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["input"];
25
45
  /**
26
- * Get the output type for a specific widget.
46
+ * Get the output type for a specific tool (widget or regular tool).
27
47
  *
28
48
  * @example
29
49
  * ```ts
30
- * type SearchOutput = WidgetOutput<MyServer, "search">;
50
+ * type SearchOutput = ToolOutput<MyServer, "search">;
31
51
  * ```
32
52
  */
33
- export type WidgetOutput<T, K extends WidgetNames<T>> = InferWidgets<T> extends Record<string, WidgetDef> ? K extends keyof InferWidgets<T> ? InferWidgets<T>[K]["output"] : never : never;
53
+ export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
+ export {};
@@ -1,19 +1,48 @@
1
- import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { Resource } from "@modelcontextprotocol/sdk/types.js";
1
+ import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
2
+ import type { Resource, ToolAnnotations, CallToolResult, ServerRequest, ServerNotification } from "@modelcontextprotocol/sdk/types.js";
3
+ import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
3
4
  import type { ZodRawShape, ZodObject, infer as Infer } from "zod";
4
- export type WidgetDef<TInput = unknown, TOutput = unknown> = {
5
+ export type ToolDef<TInput = unknown, TOutput = unknown> = {
5
6
  input: TInput;
6
7
  output: TOutput;
7
8
  };
8
9
  type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
9
10
  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 & {
11
+ type ExtractStructuredContent<T> = T extends {
12
+ structuredContent: infer SC;
13
+ } ? SC : never;
14
+ /**
15
+ * Type-level marker interface for cross-package type inference.
16
+ * This enables TypeScript to infer tool types across package boundaries
17
+ * using structural typing on the $types property, rather than relying on
18
+ * class generic inference which fails when McpServer comes from different
19
+ * package installations.
20
+ *
21
+ * Inspired by tRPC's _def pattern and Hono's type markers.
22
+ */
23
+ export interface McpServerTypes<TTools extends Record<string, ToolDef> = {}> {
24
+ readonly tools: TTools;
25
+ }
26
+ type AddTool<TTools, TName extends string, TInput extends ZodRawShape, TOutput> = McpServer<TTools & {
27
+ [K in TName]: ToolDef<Infer<ZodObject<TInput>>, TOutput>;
28
+ }>;
29
+ type ToolConfig<TInput extends ZodRawShape> = {
30
+ title?: string;
31
+ description?: string;
32
+ inputSchema?: TInput;
33
+ outputSchema?: ZodRawShape;
34
+ annotations?: ToolAnnotations;
35
+ _meta?: Record<string, unknown>;
36
+ };
37
+ type ToolHandler<TInput extends ZodRawShape, TReturn extends CallToolResult = CallToolResult> = (args: Infer<ZodObject<TInput>>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
38
+ export declare class McpServer<TTools extends Record<string, ToolDef> = {}> extends McpServerBase {
39
+ readonly $types: McpServerTypes<TTools>;
40
+ widget<TName extends string, TInput extends ZodRawShape, TReturn extends CallToolResult>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
12
41
  inputSchema?: TInput;
13
- outputSchema?: TOutput;
14
- }, toolCallback: ToolCallback<TInput>): McpServer<TWidgets & {
15
- [K in TName]: WidgetDef<Infer<ZodObject<TInput>>, Infer<ZodObject<TOutput>>>;
16
- }>;
42
+ outputSchema?: ZodRawShape;
43
+ }, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>>;
44
+ registerTool<TName extends string, InputArgs extends ZodRawShape, TReturn extends CallToolResult>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>>;
45
+ registerTool<InputArgs extends ZodRawShape>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
17
46
  private lookupDistFile;
18
47
  }
19
48
  export {};
@@ -50,6 +50,10 @@ export class McpServer extends McpServerBase {
50
50
  }, toolCallback);
51
51
  return this;
52
52
  }
53
+ registerTool(name, config, cb) {
54
+ super.registerTool(name, config, cb);
55
+ return this;
56
+ }
53
57
  lookupDistFile(key) {
54
58
  const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
55
59
  return manifest[key]?.file;
@@ -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;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,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC;SAChC,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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"}
@@ -8,6 +8,67 @@ export declare function createMockMcpServer(): {
8
8
  mockResource: MockInstance<McpServer["resource"]>;
9
9
  mockRegisterTool: MockInstance<McpServer["registerTool"]>;
10
10
  };
11
+ export declare function createTestServer(): McpServer<{
12
+ "search-voyage": import("../server/server.js").ToolDef<{
13
+ destination: string;
14
+ departureDate?: string | undefined;
15
+ maxPrice?: number | undefined;
16
+ }, {
17
+ results: {
18
+ id: string;
19
+ name: string;
20
+ price: number;
21
+ }[];
22
+ totalCount: number;
23
+ }>;
24
+ } & {
25
+ "get-trip-details": import("../server/server.js").ToolDef<{
26
+ tripId: string;
27
+ }, {
28
+ name: string;
29
+ description: string;
30
+ images: string[];
31
+ }>;
32
+ } & {
33
+ "no-input-widget": import("../server/server.js").ToolDef<{}, {}>;
34
+ } & {
35
+ "inferred-output-widget": import("../server/server.js").ToolDef<{
36
+ query: string;
37
+ }, {
38
+ inferredResults: {
39
+ id: string;
40
+ score: number;
41
+ }[];
42
+ inferredCount: number;
43
+ }>;
44
+ } & {
45
+ "calculate-price": import("../server/server.js").ToolDef<{
46
+ tripId: string;
47
+ passengers: number;
48
+ }, {
49
+ totalPrice: number;
50
+ currency: string;
51
+ }>;
52
+ } & {
53
+ "inferred-tool": import("../server/server.js").ToolDef<{
54
+ itemId: string;
55
+ }, {
56
+ itemDetails: {
57
+ name: string;
58
+ available: boolean;
59
+ };
60
+ fetchedAt: string;
61
+ }>;
62
+ }>;
63
+ export declare function createMinimalTestServer(): McpServer<{
64
+ "search-voyage": import("../server/server.js").ToolDef<{
65
+ destination: string;
66
+ }, {
67
+ results: {
68
+ id: string;
69
+ }[];
70
+ }>;
71
+ }>;
11
72
  /**
12
73
  * Mock extra parameter for resource callback
13
74
  */
@@ -1,5 +1,6 @@
1
1
  import { vi } from "vitest";
2
2
  import { McpServer } from "../server/server.js";
3
+ import { z } from "zod";
3
4
  /**
4
5
  * Creates a real McpServer instance for testing
5
6
  */
@@ -18,6 +19,126 @@ export function createMockMcpServer() {
18
19
  mockRegisterTool,
19
20
  };
20
21
  }
22
+ export function createTestServer() {
23
+ return new McpServer({ name: "test-app", version: "1.0.0" }, {})
24
+ .widget("search-voyage", {}, {
25
+ description: "Search for voyages",
26
+ inputSchema: {
27
+ destination: z.string(),
28
+ departureDate: z.string().optional(),
29
+ maxPrice: z.number().optional(),
30
+ },
31
+ outputSchema: {
32
+ results: z.array(z.object({
33
+ id: z.string(),
34
+ name: z.string(),
35
+ price: z.number(),
36
+ })),
37
+ totalCount: z.number(),
38
+ },
39
+ }, async ({ destination }) => {
40
+ return {
41
+ content: [{ type: "text", text: `Found trips to ${destination}` }],
42
+ structuredContent: {
43
+ results: [{ id: "1", name: "Trip", price: 1000 }],
44
+ totalCount: 1,
45
+ },
46
+ };
47
+ })
48
+ .widget("get-trip-details", {}, {
49
+ description: "Get trip details",
50
+ inputSchema: {
51
+ tripId: z.string(),
52
+ },
53
+ outputSchema: {
54
+ name: z.string(),
55
+ description: z.string(),
56
+ images: z.array(z.string()),
57
+ },
58
+ }, async ({ tripId }) => {
59
+ return {
60
+ content: [{ type: "text", text: `Details for ${tripId}` }],
61
+ structuredContent: {
62
+ name: "Trip",
63
+ description: "A great trip",
64
+ images: ["image1.jpg"],
65
+ },
66
+ };
67
+ })
68
+ .widget("no-input-widget", {}, {
69
+ description: "Widget with no input",
70
+ inputSchema: {},
71
+ outputSchema: {},
72
+ }, async () => {
73
+ return {
74
+ content: [{ type: "text", text: "No input needed" }],
75
+ structuredContent: {},
76
+ };
77
+ })
78
+ .widget("inferred-output-widget", {}, {
79
+ description: "Widget with output inferred from callback",
80
+ inputSchema: {
81
+ query: z.string(),
82
+ },
83
+ }, async ({ query }) => {
84
+ return {
85
+ content: [{ type: "text", text: `Query: ${query}` }],
86
+ structuredContent: {
87
+ inferredResults: [{ id: "inferred-1", score: 0.95 }],
88
+ inferredCount: 1,
89
+ },
90
+ };
91
+ })
92
+ .registerTool("calculate-price", {
93
+ description: "Calculate trip price",
94
+ inputSchema: {
95
+ tripId: z.string(),
96
+ passengers: z.number(),
97
+ },
98
+ outputSchema: {
99
+ totalPrice: z.number(),
100
+ currency: z.string(),
101
+ },
102
+ }, async ({ tripId, passengers }) => {
103
+ return {
104
+ content: [{ type: "text", text: `Price for ${tripId}` }],
105
+ structuredContent: {
106
+ totalPrice: 1000 * passengers,
107
+ currency: "USD",
108
+ },
109
+ };
110
+ })
111
+ .registerTool("inferred-tool", {
112
+ description: "Tool with output inferred from callback",
113
+ inputSchema: {
114
+ itemId: z.string(),
115
+ },
116
+ }, async ({ itemId }) => {
117
+ return {
118
+ content: [{ type: "text", text: `Item: ${itemId}` }],
119
+ structuredContent: {
120
+ itemDetails: { name: "Inferred Item", available: true },
121
+ fetchedAt: "2024-01-01",
122
+ },
123
+ };
124
+ });
125
+ }
126
+ export function createMinimalTestServer() {
127
+ return new McpServer({ name: "test-app", version: "1.0.0" }, {}).widget("search-voyage", {}, {
128
+ description: "Search for voyages",
129
+ inputSchema: {
130
+ destination: z.string(),
131
+ },
132
+ outputSchema: {
133
+ results: z.array(z.object({ id: z.string() })),
134
+ },
135
+ }, async ({ destination }) => {
136
+ return {
137
+ content: [{ type: "text", text: `Found trips to ${destination}` }],
138
+ structuredContent: { results: [{ id: "1" }] },
139
+ };
140
+ });
141
+ }
21
142
  /**
22
143
  * Mock extra parameter for resource callback
23
144
  */
@@ -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;AAEhD;;GAEG;AACH,MAAM,UAAU,mBAAmB;IAKjC,mCAAm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E,CACH,CAAC,MAAM,CACN,eAAe,EACf,EAAE,EACF;QACE,WAAW,EAAE,oBAAoB;QACjC,WAAW,EAAE;YACX,WAAW,EAAE,CAAC,CAAC,MAAM,EAAE;SACxB;QACD,YAAY,EAAE;YACZ,OAAO,EAAE,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,MAAM,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE,EAAE,CAAC,CAAC;SAC/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"}
@@ -0,0 +1,13 @@
1
+ import { type ReactNode } from "react";
2
+ export type DataLLMContent = string;
3
+ export interface DataLLMNode {
4
+ id: string;
5
+ parentId: string | null;
6
+ content: string | null;
7
+ }
8
+ interface DataLLMProps {
9
+ content: DataLLMContent | null | undefined;
10
+ children?: ReactNode;
11
+ }
12
+ export declare function DataLLM({ content, children }: DataLLMProps): import("react/jsx-runtime").JSX.Element;
13
+ export {};
@@ -0,0 +1,67 @@
1
+ import { jsx as _jsx } from "react/jsx-runtime";
2
+ import { createContext, useContext, useEffect, useId, } from "react";
3
+ const nodes = new Map();
4
+ function setNode(node) {
5
+ nodes.set(node.id, node);
6
+ onChange();
7
+ }
8
+ function removeNode(id) {
9
+ nodes.delete(id);
10
+ onChange();
11
+ }
12
+ function onChange() {
13
+ const description = getLLMDescriptionString();
14
+ window.openai.setWidgetState({
15
+ ...window.openai.widgetState,
16
+ __widget_context: description,
17
+ });
18
+ }
19
+ const ParentIdContext = createContext(null);
20
+ export function DataLLM({ content, children }) {
21
+ const parentId = useContext(ParentIdContext);
22
+ const id = useId();
23
+ useEffect(() => {
24
+ if (content) {
25
+ setNode({
26
+ id,
27
+ parentId,
28
+ content,
29
+ });
30
+ }
31
+ else {
32
+ removeNode(id);
33
+ }
34
+ return () => {
35
+ removeNode(id);
36
+ };
37
+ }, [id, parentId, content]);
38
+ return (_jsx(ParentIdContext.Provider, { value: id, children: children }));
39
+ }
40
+ function getLLMDescriptionString() {
41
+ const byParent = new Map();
42
+ for (const node of Array.from(nodes.values())) {
43
+ const key = node.parentId ?? null;
44
+ if (!byParent.has(key))
45
+ byParent.set(key, []);
46
+ byParent.get(key).push(node);
47
+ }
48
+ for (const list of byParent.values()) {
49
+ list.sort((a, b) => a.id.localeCompare(b.id));
50
+ }
51
+ const lines = [];
52
+ function traverseTree(parentId, depth) {
53
+ const children = byParent.get(parentId);
54
+ if (!children)
55
+ return;
56
+ for (const child of children) {
57
+ if (child.content && child.content.trim()) {
58
+ const indent = " ".repeat(depth);
59
+ lines.push(`${indent}- ${child.content.trim()}`);
60
+ }
61
+ traverseTree(child.id, depth + 1);
62
+ }
63
+ }
64
+ traverseTree(null, 0);
65
+ return lines.join("\n");
66
+ }
67
+ //# sourceMappingURL=data-llm.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"data-llm.js","sourceRoot":"","sources":["../../../src/web/data-llm.tsx"],"names":[],"mappings":";AAAA,OAAO,EACL,aAAa,EACb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