skybridge 0.0.0-dev.b33fb3f → 0.0.0-dev.b5f503d

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 (149) hide show
  1. package/README.md +26 -1
  2. package/dist/src/server/index.d.ts +2 -1
  3. package/dist/src/server/index.js +0 -1
  4. package/dist/src/server/index.js.map +1 -1
  5. package/dist/src/server/inferUtilityTypes.d.ts +54 -0
  6. package/dist/src/server/inferUtilityTypes.js +2 -0
  7. package/dist/src/server/inferUtilityTypes.js.map +1 -0
  8. package/dist/src/server/server.d.ts +45 -9
  9. package/dist/src/server/server.js +28 -12
  10. package/dist/src/server/server.js.map +1 -1
  11. package/dist/src/server/templateHelper.d.ts +9 -8
  12. package/dist/src/server/templateHelper.js +0 -8
  13. package/dist/src/server/templateHelper.js.map +1 -1
  14. package/dist/src/server/templates/development.hbs +8 -0
  15. package/dist/src/server/templates/production.hbs +3 -2
  16. package/dist/src/server/widgetsDevServer.d.ts +5 -2
  17. package/dist/src/server/widgetsDevServer.js +5 -2
  18. package/dist/src/server/widgetsDevServer.js.map +1 -1
  19. package/dist/src/test/utils.d.ts +61 -0
  20. package/dist/src/test/utils.js +122 -1
  21. package/dist/src/test/utils.js.map +1 -1
  22. package/dist/src/test/widget.test.js +27 -9
  23. package/dist/src/test/widget.test.js.map +1 -1
  24. package/dist/src/web/data-llm.d.ts +13 -0
  25. package/dist/src/web/data-llm.js +67 -0
  26. package/dist/src/web/data-llm.js.map +1 -0
  27. package/dist/src/web/data-llm.test.js +76 -0
  28. package/dist/src/web/data-llm.test.js.map +1 -0
  29. package/dist/src/web/generate-helpers.d.ts +113 -0
  30. package/dist/src/web/generate-helpers.js +109 -0
  31. package/dist/src/web/generate-helpers.js.map +1 -0
  32. package/dist/src/web/generate-helpers.test-d.d.ts +1 -0
  33. package/dist/src/web/generate-helpers.test-d.js +153 -0
  34. package/dist/src/web/generate-helpers.test-d.js.map +1 -0
  35. package/dist/src/web/generate-helpers.test.d.ts +1 -0
  36. package/dist/src/web/generate-helpers.test.js +17 -0
  37. package/dist/src/web/generate-helpers.test.js.map +1 -0
  38. package/dist/src/web/hooks/index.d.ts +12 -0
  39. package/dist/src/web/hooks/index.js +13 -0
  40. package/dist/src/web/hooks/index.js.map +1 -0
  41. package/dist/src/web/hooks/use-call-tool.d.ts +100 -0
  42. package/dist/src/web/hooks/use-call-tool.js +60 -0
  43. package/dist/src/web/hooks/use-call-tool.js.map +1 -0
  44. package/dist/src/web/hooks/use-call-tool.test-d.d.ts +1 -0
  45. package/dist/src/web/hooks/use-call-tool.test-d.js +104 -0
  46. package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -0
  47. package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
  48. package/dist/src/web/hooks/use-call-tool.test.js +171 -0
  49. package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
  50. package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
  51. package/dist/src/web/hooks/use-display-mode.js +7 -0
  52. package/dist/src/web/hooks/use-display-mode.js.map +1 -0
  53. package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
  54. package/dist/src/web/hooks/use-display-mode.test.js +40 -0
  55. package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
  56. package/dist/src/web/hooks/use-files.d.ts +10 -0
  57. package/dist/src/web/hooks/use-files.js +7 -0
  58. package/dist/src/web/hooks/use-files.js.map +1 -0
  59. package/dist/src/web/hooks/use-files.test.d.ts +1 -0
  60. package/dist/src/web/hooks/use-files.test.js +29 -0
  61. package/dist/src/web/hooks/use-files.test.js.map +1 -0
  62. package/dist/src/web/hooks/use-locale.d.ts +1 -0
  63. package/dist/src/web/hooks/use-locale.js +5 -0
  64. package/dist/src/web/hooks/use-locale.js.map +1 -0
  65. package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
  66. package/dist/src/web/hooks/use-locale.test.js +21 -0
  67. package/dist/src/web/hooks/use-locale.test.js.map +1 -0
  68. package/dist/src/web/hooks/use-open-external.d.ts +1 -0
  69. package/dist/src/web/hooks/use-open-external.js +6 -0
  70. package/dist/src/web/hooks/use-open-external.js.map +1 -0
  71. package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
  72. package/dist/src/web/hooks/use-open-external.test.js +24 -0
  73. package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
  74. package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
  75. package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +4 -2
  76. package/dist/src/web/hooks/use-openai-global.js.map +1 -0
  77. package/dist/src/web/hooks/use-request-modal.d.ts +6 -0
  78. package/dist/src/web/hooks/use-request-modal.js +9 -0
  79. package/dist/src/web/hooks/use-request-modal.js.map +1 -0
  80. package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
  81. package/dist/src/web/hooks/use-request-modal.test.js +24 -0
  82. package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
  83. package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
  84. package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
  85. package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
  86. package/dist/src/web/hooks/use-theme.d.ts +1 -0
  87. package/dist/src/web/hooks/use-theme.js +5 -0
  88. package/dist/src/web/hooks/use-theme.js.map +1 -0
  89. package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
  90. package/dist/src/web/hooks/use-theme.test.js +26 -0
  91. package/dist/src/web/hooks/use-theme.test.js.map +1 -0
  92. package/dist/src/web/hooks/use-tool-info.d.ts +25 -0
  93. package/dist/src/web/hooks/use-tool-info.js +22 -0
  94. package/dist/src/web/hooks/use-tool-info.js.map +1 -0
  95. package/dist/src/web/hooks/use-tool-info.test-d.d.ts +1 -0
  96. package/dist/src/web/hooks/use-tool-info.test-d.js +74 -0
  97. package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -0
  98. package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
  99. package/dist/src/web/hooks/use-tool-info.test.js +59 -0
  100. package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
  101. package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
  102. package/dist/src/web/hooks/use-user-agent.js +5 -0
  103. package/dist/src/web/hooks/use-user-agent.js.map +1 -0
  104. package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
  105. package/dist/src/web/hooks/use-user-agent.test.js +31 -0
  106. package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
  107. package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
  108. package/dist/src/web/hooks/use-widget-state.js +54 -0
  109. package/dist/src/web/hooks/use-widget-state.js.map +1 -0
  110. package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
  111. package/dist/src/web/hooks/use-widget-state.test.js +60 -0
  112. package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
  113. package/dist/src/web/index.d.ts +4 -2
  114. package/dist/src/web/index.js +4 -2
  115. package/dist/src/web/index.js.map +1 -1
  116. package/dist/src/web/mount-widget.js +12 -3
  117. package/dist/src/web/mount-widget.js.map +1 -1
  118. package/dist/src/web/plugin/data-llm.test.d.ts +1 -0
  119. package/dist/src/web/plugin/data-llm.test.js +81 -0
  120. package/dist/src/web/plugin/data-llm.test.js.map +1 -0
  121. package/dist/src/web/plugin/plugin.d.ts +2 -0
  122. package/dist/src/web/plugin/plugin.js +33 -0
  123. package/dist/src/web/plugin/plugin.js.map +1 -0
  124. package/dist/src/web/plugin/transform-data-llm.d.ts +12 -0
  125. package/dist/src/web/plugin/transform-data-llm.js +93 -0
  126. package/dist/src/web/plugin/transform-data-llm.js.map +1 -0
  127. package/dist/src/web/plugin/transform-data-llm.test.d.ts +1 -0
  128. package/dist/src/web/plugin/transform-data-llm.test.js +81 -0
  129. package/dist/src/web/plugin/transform-data-llm.test.js.map +1 -0
  130. package/dist/src/web/proxy.d.ts +1 -0
  131. package/dist/src/web/proxy.js +48 -0
  132. package/dist/src/web/proxy.js.map +1 -0
  133. package/dist/src/web/types.d.ts +53 -15
  134. package/dist/src/web/types.js +1 -0
  135. package/dist/src/web/types.js.map +1 -1
  136. package/dist/vitest.config.js +0 -1
  137. package/dist/vitest.config.js.map +1 -1
  138. package/package.json +13 -6
  139. package/dist/src/server/middleware.d.ts +0 -3
  140. package/dist/src/server/middleware.js +0 -47
  141. package/dist/src/server/middleware.js.map +0 -1
  142. package/dist/src/server/templates/vite-client.hbs +0 -7
  143. package/dist/src/test/setup.js +0 -9
  144. package/dist/src/test/setup.js.map +0 -1
  145. package/dist/src/web/use-openai-global.js.map +0 -1
  146. package/dist/src/web/use-tool-output.d.ts +0 -3
  147. package/dist/src/web/use-tool-output.js +0 -5
  148. package/dist/src/web/use-tool-output.js.map +0 -1
  149. /package/dist/src/{test/setup.d.ts → web/data-llm.test.d.ts} +0 -0
package/README.md CHANGED
@@ -1,3 +1,28 @@
1
+ <div align="center">
2
+
1
3
  # Skybridge
2
4
 
3
- Skybridge is a framework for building ChatGPT apps
5
+ **Skybridge is the TypeScript framework for building ChatGPT apps**
6
+
7
+ [![By Alpic](https://img.shields.io/badge/Made%20by%20Alpic-f6ffed?logo=alpic)](https://alpic.ai)
8
+
9
+ ![NPM Downloads](https://img.shields.io/npm/dm/skybridge?color=e90060)
10
+ ![NPM Version](https://img.shields.io/npm/v/skybridge?color=e90060)
11
+ ![GitHub License](https://img.shields.io/github/license/alpic-ai/skybridge?color=e90060)
12
+
13
+ </div>
14
+
15
+ Skybridge is a fullstack library. It comes with modular packages aiming at simplifying the development of ChatGPT apps:
16
+
17
+ - HMR server for development and build pipeline for production including end-to-end (tools-to-widget) type safety
18
+ - collection of React hooks for state management, async data fetching
19
+ - attribute for widget-to-context synchronization
20
+
21
+ ### <a href="https://skybridge.tech">Read the docs →</b></a>
22
+
23
+ ## Get Involved
24
+
25
+ We welcome issues and pull requests!
26
+ Participate in [GitHub discussions](https://github.com/alpic-ai/skybridge/discussions)
27
+ Chat with the community on [Discord](https://discord.com/invite/gNAazGueab)
28
+ See [CONTRIBUTING.md](CONTRIBUTING.md) for setup instructions
@@ -1,3 +1,4 @@
1
1
  export { McpServer } from "./server.js";
2
2
  export { widgetsDevServer } from "./widgetsDevServer.js";
3
- export { mcp } from "./middleware.js";
3
+ export type { ToolDef, McpServerTypes } from "./server.js";
4
+ export type { InferTools, AnyToolRegistry, ToolNames, ToolInput, ToolOutput, } from "./inferUtilityTypes.js";
@@ -1,4 +1,3 @@
1
1
  export { McpServer } from "./server.js";
2
2
  export { widgetsDevServer } from "./widgetsDevServer.js";
3
- export { mcp } from "./middleware.js";
4
3
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC;AACzD,OAAO,EAAE,GAAG,EAAE,MAAM,iBAAiB,CAAC"}
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
@@ -0,0 +1,54 @@
1
+ import type { McpServerTypes, ToolDef } from "./server.js";
2
+ /**
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.
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * type Names = ToolNames<MyServer>;
32
+ * // "search" | "calculate" | "details"
33
+ * ```
34
+ */
35
+ export type ToolNames<ServerType> = keyof InferTools<ServerType> & string;
36
+ /**
37
+ * Get the input type for a specific tool (widget or regular tool).
38
+ *
39
+ * @example
40
+ * ```ts
41
+ * type SearchInput = ToolInput<MyServer, "search">;
42
+ * ```
43
+ */
44
+ export type ToolInput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["input"];
45
+ /**
46
+ * Get the output type for a specific tool (widget or regular tool).
47
+ *
48
+ * @example
49
+ * ```ts
50
+ * type SearchOutput = ToolOutput<MyServer, "search">;
51
+ * ```
52
+ */
53
+ export type ToolOutput<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["output"];
54
+ export {};
@@ -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,12 +1,48 @@
1
- import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
2
- import type { Resource } from "@modelcontextprotocol/sdk/types.js";
3
- import type { ZodRawShape } from "zod";
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";
4
+ import type { ZodRawShape, ZodObject, infer as Infer } from "zod";
5
+ export type ToolDef<TInput = unknown, TOutput = unknown> = {
6
+ input: TInput;
7
+ output: TOutput;
8
+ };
4
9
  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;
10
+ type McpServerOriginalToolConfig = Omit<Parameters<McpServerBase["registerTool"]>[1], "inputSchema" | "outputSchema">;
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
+ registerWidget<TName extends string, TInput extends ZodRawShape, TReturn extends CallToolResult>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
41
+ inputSchema?: TInput;
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;
46
+ private lookupDistFile;
11
47
  }
12
48
  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
- widget(name, resourceConfig, toolConfig, toolCallback) {
6
+ registerWidget(name, resourceConfig, toolConfig, toolCallback) {
5
7
  const uri = `ui://widgets/${name}.html`;
6
- const resourceMetadata = { ...(resourceConfig._meta ?? {}) };
8
+ const resourceMetadata = {
9
+ ...(resourceConfig._meta ?? {}),
10
+ };
7
11
  if (toolConfig.description !== undefined) {
8
12
  resourceMetadata["openai/widgetDescription"] = toolConfig.description;
9
13
  }
@@ -12,23 +16,25 @@ export class McpServer extends McpServerBase {
12
16
  _meta: resourceMetadata,
13
17
  }, async (_uri, extra) => {
14
18
  const serverUrl = process.env.NODE_ENV === "production"
15
- ? `https://${extra?.requestInfo?.headers?.host}`
19
+ ? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
20
+ extra?.requestInfo?.headers?.host}`
16
21
  : `http://localhost:3000`;
17
- const templateData = {
18
- serverUrl,
19
- widgetName: name,
20
- };
21
22
  const html = process.env.NODE_ENV === "production"
22
- ? templateHelper.renderProduction(templateData)
23
- : templateHelper.renderDevelopment(templateData);
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
+ });
24
32
  return {
25
33
  contents: [
26
34
  {
27
35
  uri,
28
36
  mimeType: "text/html+skybridge",
29
- text: process.env.NODE_ENV === "production"
30
- ? html
31
- : templateHelper.injectViteClient(html, templateData),
37
+ text: html,
32
38
  },
33
39
  ],
34
40
  };
@@ -36,11 +42,21 @@ export class McpServer extends McpServerBase {
36
42
  const toolMeta = {
37
43
  ...toolConfig._meta,
38
44
  "openai/outputTemplate": uri,
45
+ "ui/resourceUri": uri,
39
46
  };
40
47
  this.registerTool(name, {
41
48
  ...toolConfig,
42
49
  _meta: toolMeta,
43
50
  }, toolCallback);
51
+ return this;
52
+ }
53
+ registerTool(name, config, cb) {
54
+ super.registerTool(name, config, cb);
55
+ return this;
56
+ }
57
+ lookupDistFile(key) {
58
+ const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
59
+ return manifest[key]?.file;
44
60
  }
45
61
  }
46
62
  //# 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;AA4BrD,MAAM,OAAO,SAAU,SAAQ,aAAa;IA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@ -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: TemplateData): string;
9
- renderDevelopment(data: TemplateData): string;
10
- renderViteClient(data: TemplateData): string;
11
- injectViteClient(html: string, data: TemplateData): string;
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,Y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,3 +1,11 @@
1
+ <base href="{{serverUrl}}" />
2
+ <script type="module">
3
+ import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
4
+ injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
5
+ window.$RefreshSig$ = () => (type) => type;
6
+ window.__vite_plugin_react_preamble_installed__ = true;
7
+ </script>
8
+ <script type="module" src="{{serverUrl}}/@vite/client"></script>
1
9
  <div id="root"></div>
2
10
  <script type="module">
3
11
  import('{{serverUrl}}/src/widgets/{{widgetName}}.tsx');
@@ -1,5 +1,6 @@
1
+ <base href="{{serverUrl}}" />
1
2
  <div id="root"></div>
2
3
  <script type="module">
3
- import('{{serverUrl}}/assets/{{widgetName}}.js');
4
+ import('{{serverUrl}}/assets/{{widgetFile}}');
4
5
  </script>
5
- <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/style.css" />
6
+ <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
@@ -1,9 +1,12 @@
1
1
  import { type RequestHandler } from "express";
2
2
  /**
3
- * Install Vite dev server when env is not production
3
+ * Install Vite dev server
4
4
  * This router MUST be installed at the application root, like so:
5
5
  *
6
6
  * const app = express();
7
- * app.use(await widgetsRouter());
7
+ *
8
+ * if (env.NODE_ENV !== "production") {
9
+ * app.use(await widgetsRouter());
10
+ * }
8
11
  */
9
12
  export declare const widgetsDevServer: () => Promise<RequestHandler>;
@@ -2,11 +2,14 @@ import express, {} from "express";
2
2
  import cors from "cors";
3
3
  import path from "node:path";
4
4
  /**
5
- * Install Vite dev server when env is not production
5
+ * Install Vite dev server
6
6
  * This router MUST be installed at the application root, like so:
7
7
  *
8
8
  * const app = express();
9
- * app.use(await widgetsRouter());
9
+ *
10
+ * if (env.NODE_ENV !== "production") {
11
+ * app.use(await widgetsRouter());
12
+ * }
10
13
  */
11
14
  export const widgetsDevServer = async () => {
12
15
  const router = express.Router();
@@ -1 +1 @@
1
- {"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../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EAAE,CAAC,OAAO,EAAE,kBAAkB,CAAC;SACvC;KACF,CAAC,CAAC;IAEH,MAAM,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC,CAAC;IACnB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,IAAI,CAAC,WAAW,CAAC,CAAC;IAElC,OAAO,MAAM,CAAC;AAChB,CAAC,CAAC"}
@@ -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
- import { McpServer, McpServer as McpServerBase } from "../server/server.js";
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
+ .registerWidget("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
+ .registerWidget("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
+ .registerWidget("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
+ .registerWidget("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" }, {}).registerWidget("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,M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CAAC,CACF,CAAC;AACN,CAAC;AAED,MAAM,UAAU,uBAAuB;IACrC,OAAO,IAAI,SAAS,CAClB,EAAE,IAAI,EAAE,UAAU,EAAE,OAAO,EAAE,OAAO,EAAE,EACtC,EAAE,CACH,CAAC,cAAc,CACd,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"}
@@ -1,15 +1,33 @@
1
- import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
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, createMockExtra, setTestEnv, resetTestEnv, } from "./utils.js";
4
- describe("McpServer.widget", () => {
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
+ });
24
+ describe("McpServer.registerWidget", () => {
5
25
  let server;
6
26
  let mockResource;
7
27
  let mockRegisterTool;
28
+ let readFileSyncSpy = null;
8
29
  beforeEach(() => {
9
- const mock = createMockMcpServer();
10
- server = mock.server;
11
- mockResource = mock.mockResource;
12
- mockRegisterTool = mock.mockRegisterTool;
30
+ ({ server, mockResource, mockRegisterTool } = createMockMcpServer());
13
31
  });
14
32
  afterEach(() => {
15
33
  vi.clearAllMocks();
@@ -20,7 +38,7 @@ describe("McpServer.widget", () => {
20
38
  const mockToolCallback = vi.fn();
21
39
  const mockResourceConfig = { description: "Test widget" };
22
40
  const mockToolConfig = { description: "Test tool" };
23
- server.widget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
41
+ server.registerWidget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
24
42
  // Get the resource callback function
25
43
  const resourceCallback = mockResource.mock.calls[0]?.[3];
26
44
  expect(resourceCallback).toBeDefined();
@@ -46,7 +64,7 @@ describe("McpServer.widget", () => {
46
64
  const mockToolCallback = vi.fn();
47
65
  const mockResourceConfig = { description: "Test widget" };
48
66
  const mockToolConfig = { description: "Test tool" };
49
- server.widget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
67
+ server.registerWidget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
50
68
  // Get the resource callback function
51
69
  const resourceCallback = mockResource.mock.calls[0]?.[3];
52
70
  expect(resourceCallback).toBeDefined();