skybridge 0.0.0-dev.c63f165 → 0.0.0-dev.c6607c2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +21 -674
- package/README.md +147 -1
- package/bin/run.js +5 -0
- package/dist/cli/detect-port.d.ts +18 -0
- package/dist/cli/detect-port.js +61 -0
- package/dist/cli/detect-port.js.map +1 -0
- package/dist/cli/header.d.ts +4 -0
- package/dist/cli/header.js +6 -0
- package/dist/cli/header.js.map +1 -0
- package/dist/cli/run-command.d.ts +2 -0
- package/dist/cli/run-command.js +43 -0
- package/dist/cli/run-command.js.map +1 -0
- package/dist/cli/telemetry.d.ts +7 -0
- package/dist/cli/telemetry.js +123 -0
- package/dist/cli/telemetry.js.map +1 -0
- package/dist/cli/use-execute-steps.d.ts +11 -0
- package/dist/cli/use-execute-steps.js +36 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/cli/use-nodemon.d.ts +7 -0
- package/dist/cli/use-nodemon.js +76 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +8 -0
- package/dist/cli/use-typescript-check.js +59 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +46 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +9 -0
- package/dist/commands/dev.js +36 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +9 -0
- package/dist/commands/start.js +52 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +34 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/express.d.ts +15 -0
- package/dist/server/express.js +77 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.js +252 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +5 -0
- package/dist/{src/server/index.d.ts → server/index.js} +1 -1
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.d.ts +64 -0
- package/dist/server/inferUtilityTypes.js +2 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/middleware.d.ts +124 -0
- package/dist/server/middleware.js +93 -0
- package/dist/server/middleware.js.map +1 -0
- package/dist/server/middleware.test-d.d.ts +1 -0
- package/dist/server/middleware.test-d.js +75 -0
- package/dist/server/middleware.test-d.js.map +1 -0
- package/dist/server/middleware.test.d.ts +1 -0
- package/dist/server/middleware.test.js +490 -0
- package/dist/server/middleware.test.js.map +1 -0
- package/dist/server/server.d.ts +150 -0
- package/dist/server/server.js +288 -0
- package/dist/server/server.js.map +1 -0
- package/dist/server/templateHelper.d.ts +18 -0
- package/dist/{src/server → server}/templateHelper.js +5 -12
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +12 -0
- package/dist/server/templates/production.hbs +6 -0
- package/dist/server/widgetsDevServer.d.ts +13 -0
- package/dist/server/widgetsDevServer.js +57 -0
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +135 -0
- package/dist/test/utils.js +242 -0
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.d.ts +1 -0
- package/dist/test/widget.test.js +263 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +22 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +75 -0
- package/dist/web/bridges/apps-sdk/adaptor.js.map +1 -0
- package/dist/web/bridges/apps-sdk/bridge.d.ts +10 -0
- package/dist/web/bridges/apps-sdk/bridge.js +46 -0
- package/dist/web/bridges/apps-sdk/bridge.js.map +1 -0
- package/dist/web/bridges/apps-sdk/index.d.ts +5 -0
- package/dist/web/bridges/apps-sdk/index.js +5 -0
- package/dist/web/bridges/apps-sdk/index.js.map +1 -0
- package/dist/web/bridges/apps-sdk/types.d.ts +121 -0
- package/dist/web/bridges/apps-sdk/types.js.map +1 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.d.ts +2 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js +7 -0
- package/dist/web/bridges/apps-sdk/use-apps-sdk-context.js.map +1 -0
- package/dist/web/bridges/get-adaptor.d.ts +2 -0
- package/dist/web/bridges/get-adaptor.js +8 -0
- package/dist/web/bridges/get-adaptor.js.map +1 -0
- package/dist/web/bridges/index.d.ts +5 -0
- package/dist/web/bridges/index.js +6 -0
- package/dist/web/bridges/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/adaptor.d.ts +38 -0
- package/dist/web/bridges/mcp-app/adaptor.js +184 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +26 -0
- package/dist/web/bridges/mcp-app/bridge.js +102 -0
- package/dist/web/bridges/mcp-app/bridge.js.map +1 -0
- package/dist/web/bridges/mcp-app/index.d.ts +4 -0
- package/dist/web/bridges/mcp-app/index.js +4 -0
- package/dist/web/bridges/mcp-app/index.js.map +1 -0
- package/dist/web/bridges/mcp-app/types.d.ts +8 -0
- package/dist/web/bridges/mcp-app/types.js +2 -0
- package/dist/web/bridges/mcp-app/types.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.d.ts +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js +7 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.js.map +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.d.ts +1 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js +26 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +103 -0
- package/dist/web/bridges/types.js +2 -0
- package/dist/web/bridges/types.js.map +1 -0
- package/dist/web/bridges/use-host-context.d.ts +2 -0
- package/dist/web/bridges/use-host-context.js +8 -0
- package/dist/web/bridges/use-host-context.js.map +1 -0
- package/dist/web/components/modal-provider.d.ts +4 -0
- package/dist/web/components/modal-provider.js +45 -0
- package/dist/web/components/modal-provider.js.map +1 -0
- package/dist/web/create-store.d.ts +3 -0
- package/dist/web/create-store.js +24 -0
- package/dist/web/create-store.js.map +1 -0
- package/dist/web/create-store.test.d.ts +1 -0
- package/dist/web/create-store.test.js +131 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/web/data-llm.d.ts +14 -0
- package/dist/web/data-llm.js +72 -0
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.d.ts +1 -0
- package/dist/web/data-llm.test.js +142 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/web/generate-helpers.d.ts +116 -0
- package/dist/web/generate-helpers.js +111 -0
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/web/generate-helpers.test-d.d.ts +1 -0
- package/dist/web/generate-helpers.test-d.js +209 -0
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/web/generate-helpers.test.d.ts +1 -0
- package/dist/web/generate-helpers.test.js +17 -0
- package/dist/web/generate-helpers.test.js.map +1 -0
- package/dist/web/helpers/state.d.ts +7 -0
- package/dist/web/helpers/state.js +45 -0
- package/dist/web/helpers/state.js.map +1 -0
- package/dist/web/helpers/state.test.d.ts +1 -0
- package/dist/web/helpers/state.test.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/web/hooks/index.d.ts +11 -0
- package/dist/web/hooks/index.js +12 -0
- package/dist/web/hooks/index.js.map +1 -0
- package/dist/web/hooks/test/utils.d.ts +16 -0
- package/dist/web/hooks/test/utils.js +64 -0
- package/dist/web/hooks/test/utils.js.map +1 -0
- package/dist/web/hooks/use-call-tool.d.ts +101 -0
- package/dist/web/hooks/use-call-tool.js +68 -0
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test-d.d.ts +1 -0
- package/dist/web/hooks/use-call-tool.test-d.js +104 -0
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/web/hooks/use-call-tool.test.js +190 -0
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test-d.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test-d.js +8 -0
- package/dist/web/hooks/use-display-mode.test-d.js.map +1 -0
- package/dist/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/web/hooks/use-display-mode.test.js +41 -0
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/web/hooks/use-files.d.ts +6 -0
- package/dist/web/hooks/use-files.js +9 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/web/hooks/use-files.test.d.ts +1 -0
- package/dist/web/hooks/use-files.test.js +34 -0
- package/dist/web/hooks/use-files.test.js.map +1 -0
- package/dist/web/hooks/use-layout.d.ts +22 -0
- package/dist/web/hooks/use-layout.js +23 -0
- package/dist/web/hooks/use-layout.js.map +1 -0
- package/dist/web/hooks/use-layout.test.d.ts +1 -0
- package/dist/web/hooks/use-layout.test.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +1 -0
- package/dist/web/hooks/use-open-external.d.ts +3 -0
- package/dist/web/hooks/use-open-external.js +8 -0
- package/dist/web/hooks/use-open-external.js.map +1 -0
- package/dist/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/web/hooks/use-open-external.test.js +65 -0
- package/dist/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/web/hooks/use-request-modal.d.ts +9 -0
- package/dist/web/hooks/use-request-modal.js +16 -0
- package/dist/web/hooks/use-request-modal.js.map +1 -0
- package/dist/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/web/hooks/use-request-modal.test.js +61 -0
- package/dist/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/web/hooks/use-send-follow-up-message.d.ts +1 -0
- package/dist/web/hooks/use-send-follow-up-message.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.js +8 -0
- package/dist/web/hooks/use-set-open-in-app-url.js.map +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.d.ts +1 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js +43 -0
- package/dist/web/hooks/use-set-open-in-app-url.test.js.map +1 -0
- package/dist/web/hooks/use-tool-info.d.ts +36 -0
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test-d.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test-d.js +109 -0
- package/dist/web/hooks/use-tool-info.test-d.js.map +1 -0
- package/dist/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/web/hooks/use-tool-info.test.js +130 -0
- package/dist/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/web/hooks/use-user.d.ts +18 -0
- package/dist/web/hooks/use-user.js +35 -0
- package/dist/web/hooks/use-user.js.map +1 -0
- package/dist/web/hooks/use-user.test.d.ts +1 -0
- package/dist/web/hooks/use-user.test.js +122 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-widget-state.d.ts +4 -0
- package/dist/web/hooks/use-widget-state.js +32 -0
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/web/hooks/use-widget-state.test.js +64 -0
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/web/index.d.ts +8 -0
- package/dist/web/index.js +9 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-widget.js +27 -0
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js +81 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.d.ts +2 -0
- package/dist/web/plugin/plugin.js +54 -0
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.d.ts +12 -0
- package/dist/web/plugin/transform-data-llm.js +96 -0
- package/dist/web/plugin/transform-data-llm.js.map +1 -0
- package/dist/web/plugin/transform-data-llm.test.d.ts +1 -0
- package/dist/web/plugin/transform-data-llm.test.js +81 -0
- package/dist/web/plugin/transform-data-llm.test.js.map +1 -0
- package/dist/web/plugin/validate-widget.d.ts +5 -0
- package/dist/web/plugin/validate-widget.js +27 -0
- package/dist/web/plugin/validate-widget.js.map +1 -0
- package/dist/web/plugin/validate-widget.test.d.ts +1 -0
- package/dist/web/plugin/validate-widget.test.js +42 -0
- package/dist/web/plugin/validate-widget.test.js.map +1 -0
- package/dist/web/proxy.d.ts +1 -0
- package/dist/web/proxy.js +52 -0
- package/dist/web/proxy.js.map +1 -0
- package/dist/web/types.d.ts +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +71 -31
- package/tsconfig.base.json +31 -0
- package/dist/src/server/index.js +0 -4
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/middleware.d.ts +0 -3
- package/dist/src/server/middleware.js +0 -47
- package/dist/src/server/middleware.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -12
- package/dist/src/server/server.js +0 -47
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.d.ts +0 -14
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -4
- package/dist/src/server/templates/production.hbs +0 -5
- package/dist/src/server/templates/vite-client.hbs +0 -7
- package/dist/src/server/widgetsDevServer.d.ts +0 -9
- package/dist/src/server/widgetsDevServer.js +0 -36
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -28
- package/dist/src/test/utils.js +0 -43
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -72
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/index.d.ts +0 -4
- package/dist/src/web/index.js +0 -5
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js +0 -10
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/types.d.ts +0 -95
- package/dist/src/web/types.js.map +0 -1
- package/dist/src/web/use-openai-global.d.ts +0 -2
- package/dist/src/web/use-openai-global.js +0 -21
- package/dist/src/web/use-openai-global.js.map +0 -1
- package/dist/src/web/use-tool-output.d.ts +0 -3
- package/dist/src/web/use-tool-output.js +0 -5
- package/dist/src/web/use-tool-output.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -9
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/setup.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/test/widget.test.d.ts → server/express.test.d.ts} +0 -0
- /package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
|
@@ -0,0 +1,150 @@
|
|
|
1
|
+
import type { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
3
|
+
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
4
|
+
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
5
|
+
import type { CallToolResult, Resource, ServerNotification, ServerRequest, ServerResult, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import type { ErrorRequestHandler, RequestHandler } from "express";
|
|
7
|
+
import type { McpExtra, McpExtraFor, McpMethodString, McpMiddlewareFilter, McpMiddlewareFn, McpResultFor, McpTypedMiddlewareFn, McpWildcard } from "./middleware.js";
|
|
8
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
9
|
+
input: TInput;
|
|
10
|
+
output: TOutput;
|
|
11
|
+
responseMetadata: TResponseMetadata;
|
|
12
|
+
};
|
|
13
|
+
/**
|
|
14
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
15
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
16
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
17
|
+
*/
|
|
18
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
19
|
+
/**
|
|
20
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
21
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
22
|
+
*/
|
|
23
|
+
redirectDomains?: string[];
|
|
24
|
+
};
|
|
25
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
26
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
27
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
28
|
+
};
|
|
29
|
+
/** User-provided resource configuration with optional CSP override */
|
|
30
|
+
export type WidgetResourceMeta = {
|
|
31
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
32
|
+
} & Resource["_meta"];
|
|
33
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
34
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
35
|
+
_meta?: WidgetResourceMeta;
|
|
36
|
+
/** Restrict host types to a specific subset */
|
|
37
|
+
hosts?: WidgetHostType[];
|
|
38
|
+
};
|
|
39
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
40
|
+
type Simplify<T> = {
|
|
41
|
+
[K in keyof T]: T[K];
|
|
42
|
+
};
|
|
43
|
+
type ExtractStructuredContent<T> = T extends {
|
|
44
|
+
structuredContent: infer SC;
|
|
45
|
+
} ? Simplify<SC> : never;
|
|
46
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
47
|
+
_meta: unknown;
|
|
48
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
49
|
+
_meta: unknown;
|
|
50
|
+
}> extends {
|
|
51
|
+
_meta: infer M;
|
|
52
|
+
} ? Simplify<M> : unknown;
|
|
53
|
+
/**
|
|
54
|
+
* Type-level marker interface for cross-package type inference.
|
|
55
|
+
* This enables TypeScript to infer tool types across package boundaries
|
|
56
|
+
* using structural typing on the $types property, rather than relying on
|
|
57
|
+
* class generic inference which fails when McpServer comes from different
|
|
58
|
+
* package installations.
|
|
59
|
+
*
|
|
60
|
+
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
61
|
+
*/
|
|
62
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
63
|
+
readonly tools: TTools;
|
|
64
|
+
}
|
|
65
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
66
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
67
|
+
} & {
|
|
68
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
69
|
+
}>;
|
|
70
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
71
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
72
|
+
}>;
|
|
73
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
74
|
+
title?: string;
|
|
75
|
+
description?: string;
|
|
76
|
+
inputSchema?: TInput;
|
|
77
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
78
|
+
annotations?: ToolAnnotations;
|
|
79
|
+
_meta?: Record<string, unknown>;
|
|
80
|
+
};
|
|
81
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
82
|
+
content: CallToolResult["content"];
|
|
83
|
+
} = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
84
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
85
|
+
readonly $types: McpServerTypes<TTools>;
|
|
86
|
+
private express?;
|
|
87
|
+
private customMiddleware;
|
|
88
|
+
private customErrorMiddleware;
|
|
89
|
+
private mcpMiddlewareEntries;
|
|
90
|
+
private mcpMiddlewareApplied;
|
|
91
|
+
use(...handlers: RequestHandler[]): this;
|
|
92
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
93
|
+
useOnError(...handlers: ErrorRequestHandler[]): this;
|
|
94
|
+
useOnError(path: string, ...handlers: ErrorRequestHandler[]): this;
|
|
95
|
+
/**
|
|
96
|
+
* Register MCP protocol-level middleware (catch-all).
|
|
97
|
+
*/
|
|
98
|
+
mcpMiddleware(handler: McpMiddlewareFn): this;
|
|
99
|
+
/**
|
|
100
|
+
* Register MCP protocol-level middleware for all requests (`extra` is `McpExtra`).
|
|
101
|
+
*/
|
|
102
|
+
mcpMiddleware(filter: "request", handler: (request: {
|
|
103
|
+
method: string;
|
|
104
|
+
params: Record<string, unknown>;
|
|
105
|
+
}, extra: McpExtra, next: () => Promise<ServerResult>) => Promise<unknown> | unknown): this;
|
|
106
|
+
/**
|
|
107
|
+
* Register MCP protocol-level middleware for all notifications (`extra` is `undefined`).
|
|
108
|
+
*/
|
|
109
|
+
mcpMiddleware(filter: "notification", handler: (request: {
|
|
110
|
+
method: string;
|
|
111
|
+
params: Record<string, unknown>;
|
|
112
|
+
}, extra: undefined, next: () => Promise<undefined>) => Promise<unknown> | unknown): this;
|
|
113
|
+
/**
|
|
114
|
+
* Register MCP protocol-level middleware for an exact method.
|
|
115
|
+
* Narrows `params`, `extra`, and `next()` result based on the method string.
|
|
116
|
+
*/
|
|
117
|
+
mcpMiddleware<M extends McpMethodString>(filter: M, handler: McpTypedMiddlewareFn<M>): this;
|
|
118
|
+
/**
|
|
119
|
+
* Register MCP protocol-level middleware for a wildcard pattern (e.g. `"tools/*"`).
|
|
120
|
+
* `next()` returns the union of result types for matching methods.
|
|
121
|
+
*/
|
|
122
|
+
mcpMiddleware<W extends McpWildcard>(filter: W, handler: (request: {
|
|
123
|
+
method: string;
|
|
124
|
+
params: Record<string, unknown>;
|
|
125
|
+
}, extra: McpExtraFor<W>, next: () => Promise<McpResultFor<W>>) => Promise<unknown> | unknown): this;
|
|
126
|
+
/**
|
|
127
|
+
* Register MCP protocol-level middleware with a method filter.
|
|
128
|
+
* Filter can be an exact method (`"tools/call"`), wildcard (`"tools/*"`),
|
|
129
|
+
* category (`"request"` | `"notification"`), or an array of those.
|
|
130
|
+
*/
|
|
131
|
+
mcpMiddleware(filter: McpMiddlewareFilter, handler: McpMiddlewareFn): this;
|
|
132
|
+
private applyMcpMiddleware;
|
|
133
|
+
connect(transport: Parameters<typeof McpServerBase.prototype.connect>[0]): Promise<void>;
|
|
134
|
+
run(): Promise<void>;
|
|
135
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
|
|
136
|
+
content: CallToolResult["content"];
|
|
137
|
+
}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
138
|
+
inputSchema?: TInput;
|
|
139
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
140
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
141
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
142
|
+
content: CallToolResult["content"];
|
|
143
|
+
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
144
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
145
|
+
private registerWidgetResource;
|
|
146
|
+
private lookupDistFile;
|
|
147
|
+
private lookupDistFileWithIndexFallback;
|
|
148
|
+
private readManifest;
|
|
149
|
+
}
|
|
150
|
+
export {};
|
|
@@ -0,0 +1,288 @@
|
|
|
1
|
+
import crypto from "node:crypto";
|
|
2
|
+
import { readFileSync } from "node:fs";
|
|
3
|
+
import http from "node:http";
|
|
4
|
+
import path from "node:path";
|
|
5
|
+
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
6
|
+
import { mergeWith, union } from "es-toolkit";
|
|
7
|
+
import { createApp } from "./express.js";
|
|
8
|
+
import { buildMiddlewareChain, getHandlerMaps } from "./middleware.js";
|
|
9
|
+
import { templateHelper } from "./templateHelper.js";
|
|
10
|
+
const mergeWithUnion = (target, source) => {
|
|
11
|
+
return mergeWith(target, source, (targetVal, sourceVal) => {
|
|
12
|
+
if (Array.isArray(targetVal) && Array.isArray(sourceVal)) {
|
|
13
|
+
return union(targetVal, sourceVal);
|
|
14
|
+
}
|
|
15
|
+
});
|
|
16
|
+
};
|
|
17
|
+
export class McpServer extends McpServerBase {
|
|
18
|
+
express;
|
|
19
|
+
customMiddleware = [];
|
|
20
|
+
customErrorMiddleware = [];
|
|
21
|
+
mcpMiddlewareEntries = [];
|
|
22
|
+
mcpMiddlewareApplied = false;
|
|
23
|
+
use(pathOrHandler, ...handlers) {
|
|
24
|
+
if (typeof pathOrHandler === "string") {
|
|
25
|
+
this.customMiddleware.push({
|
|
26
|
+
path: pathOrHandler,
|
|
27
|
+
handlers,
|
|
28
|
+
});
|
|
29
|
+
}
|
|
30
|
+
else {
|
|
31
|
+
this.customMiddleware.push({
|
|
32
|
+
handlers: [pathOrHandler, ...handlers],
|
|
33
|
+
});
|
|
34
|
+
}
|
|
35
|
+
return this;
|
|
36
|
+
}
|
|
37
|
+
useOnError(pathOrHandler, ...handlers) {
|
|
38
|
+
if (typeof pathOrHandler === "string") {
|
|
39
|
+
this.customErrorMiddleware.push({ path: pathOrHandler, handlers });
|
|
40
|
+
}
|
|
41
|
+
else {
|
|
42
|
+
this.customErrorMiddleware.push({
|
|
43
|
+
handlers: [pathOrHandler, ...handlers],
|
|
44
|
+
});
|
|
45
|
+
}
|
|
46
|
+
return this;
|
|
47
|
+
}
|
|
48
|
+
mcpMiddleware(filterOrHandler,
|
|
49
|
+
// biome-ignore lint/suspicious/noExplicitAny: overloads narrow the handler type at call sites; implementation must accept all variants
|
|
50
|
+
maybeHandler) {
|
|
51
|
+
if (this.mcpMiddlewareApplied) {
|
|
52
|
+
throw new Error("Cannot register MCP middleware after run() or connect() has been called");
|
|
53
|
+
}
|
|
54
|
+
const handler = maybeHandler;
|
|
55
|
+
if (typeof filterOrHandler === "function") {
|
|
56
|
+
this.mcpMiddlewareEntries.push({
|
|
57
|
+
filter: null,
|
|
58
|
+
handler: filterOrHandler,
|
|
59
|
+
});
|
|
60
|
+
}
|
|
61
|
+
else if (handler) {
|
|
62
|
+
this.mcpMiddlewareEntries.push({
|
|
63
|
+
filter: filterOrHandler,
|
|
64
|
+
handler,
|
|
65
|
+
});
|
|
66
|
+
}
|
|
67
|
+
else {
|
|
68
|
+
throw new Error("mcpMiddleware requires a handler function when a filter is provided");
|
|
69
|
+
}
|
|
70
|
+
return this;
|
|
71
|
+
}
|
|
72
|
+
applyMcpMiddleware() {
|
|
73
|
+
if (this.mcpMiddlewareApplied) {
|
|
74
|
+
return;
|
|
75
|
+
}
|
|
76
|
+
this.mcpMiddlewareApplied = true;
|
|
77
|
+
if (this.mcpMiddlewareEntries.length === 0) {
|
|
78
|
+
return;
|
|
79
|
+
}
|
|
80
|
+
const { requestHandlers, notificationHandlers } = getHandlerMaps(this.server);
|
|
81
|
+
const entries = this.mcpMiddlewareEntries;
|
|
82
|
+
// Wrap existing handlers and proxy future .set() for lazy SDK registration
|
|
83
|
+
const instrumentMap = (map, isNotification) => {
|
|
84
|
+
for (const [method, handler] of map) {
|
|
85
|
+
map.set(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
86
|
+
}
|
|
87
|
+
const originalSet = map.set.bind(map);
|
|
88
|
+
map.set = (method, handler) => originalSet(method, buildMiddlewareChain(method, isNotification, handler, entries));
|
|
89
|
+
};
|
|
90
|
+
instrumentMap(requestHandlers, false);
|
|
91
|
+
instrumentMap(notificationHandlers, true);
|
|
92
|
+
}
|
|
93
|
+
async connect(transport) {
|
|
94
|
+
this.applyMcpMiddleware();
|
|
95
|
+
return super.connect(transport);
|
|
96
|
+
}
|
|
97
|
+
async run() {
|
|
98
|
+
this.applyMcpMiddleware();
|
|
99
|
+
const httpServer = http.createServer();
|
|
100
|
+
if (!this.express) {
|
|
101
|
+
this.express = await createApp({
|
|
102
|
+
mcpServer: this,
|
|
103
|
+
httpServer,
|
|
104
|
+
customMiddleware: this.customMiddleware,
|
|
105
|
+
errorMiddleware: this.customErrorMiddleware,
|
|
106
|
+
});
|
|
107
|
+
}
|
|
108
|
+
httpServer.on("request", this.express);
|
|
109
|
+
return new Promise((resolve, reject) => {
|
|
110
|
+
httpServer.on("error", (error) => {
|
|
111
|
+
console.error("Failed to start server:", error);
|
|
112
|
+
reject(error);
|
|
113
|
+
});
|
|
114
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
115
|
+
httpServer.listen(port, () => {
|
|
116
|
+
resolve();
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
121
|
+
const userMeta = resourceConfig._meta;
|
|
122
|
+
const toolMeta = {
|
|
123
|
+
...toolConfig._meta,
|
|
124
|
+
};
|
|
125
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("apps-sdk")) {
|
|
126
|
+
const widgetConfig = {
|
|
127
|
+
hostType: "apps-sdk",
|
|
128
|
+
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
129
|
+
mimeType: "text/html+skybridge",
|
|
130
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
131
|
+
const userUi = userMeta?.ui;
|
|
132
|
+
const userCsp = userUi?.csp;
|
|
133
|
+
const defaults = {
|
|
134
|
+
"openai/widgetCSP": {
|
|
135
|
+
resource_domains: resourceDomains,
|
|
136
|
+
connect_domains: connectDomains,
|
|
137
|
+
},
|
|
138
|
+
"openai/widgetDomain": domain,
|
|
139
|
+
"openai/widgetDescription": resourceConfig.description,
|
|
140
|
+
};
|
|
141
|
+
const fromUi = {
|
|
142
|
+
"openai/widgetCSP": {
|
|
143
|
+
resource_domains: userCsp?.resourceDomains,
|
|
144
|
+
connect_domains: userCsp?.connectDomains,
|
|
145
|
+
frame_domains: userCsp?.frameDomains,
|
|
146
|
+
redirect_domains: userCsp?.redirectDomains,
|
|
147
|
+
},
|
|
148
|
+
"openai/widgetDomain": userUi?.domain,
|
|
149
|
+
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
150
|
+
};
|
|
151
|
+
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
152
|
+
return mergeWithUnion(mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys), { "openai/widgetDomain": overrides.domain });
|
|
153
|
+
},
|
|
154
|
+
};
|
|
155
|
+
this.registerWidgetResource({
|
|
156
|
+
name,
|
|
157
|
+
widgetConfig,
|
|
158
|
+
resourceConfig,
|
|
159
|
+
});
|
|
160
|
+
toolMeta["openai/outputTemplate"] = widgetConfig.uri;
|
|
161
|
+
}
|
|
162
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("mcp-app")) {
|
|
163
|
+
const widgetConfig = {
|
|
164
|
+
hostType: "mcp-app",
|
|
165
|
+
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
166
|
+
mimeType: "text/html;profile=mcp-app",
|
|
167
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
168
|
+
const defaults = {
|
|
169
|
+
ui: {
|
|
170
|
+
csp: {
|
|
171
|
+
resourceDomains,
|
|
172
|
+
connectDomains,
|
|
173
|
+
},
|
|
174
|
+
domain,
|
|
175
|
+
},
|
|
176
|
+
};
|
|
177
|
+
return mergeWithUnion(defaults, {
|
|
178
|
+
ui: { ...userMeta?.ui, ...overrides },
|
|
179
|
+
});
|
|
180
|
+
},
|
|
181
|
+
};
|
|
182
|
+
this.registerWidgetResource({
|
|
183
|
+
name,
|
|
184
|
+
widgetConfig,
|
|
185
|
+
resourceConfig,
|
|
186
|
+
});
|
|
187
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
188
|
+
toolMeta["ui/resourceUri"] = widgetConfig.uri;
|
|
189
|
+
toolMeta.ui = { resourceUri: widgetConfig.uri };
|
|
190
|
+
}
|
|
191
|
+
this.registerTool(name, {
|
|
192
|
+
...toolConfig,
|
|
193
|
+
_meta: toolMeta,
|
|
194
|
+
}, toolCallback);
|
|
195
|
+
return this;
|
|
196
|
+
}
|
|
197
|
+
registerTool(name, config, cb) {
|
|
198
|
+
super.registerTool(name, config, cb);
|
|
199
|
+
return this;
|
|
200
|
+
}
|
|
201
|
+
registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
|
|
202
|
+
const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
|
|
203
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
|
|
204
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
205
|
+
const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
|
|
206
|
+
const headers = extra?.requestInfo?.headers || {};
|
|
207
|
+
const header = (key) => {
|
|
208
|
+
const val = headers[key];
|
|
209
|
+
return Array.isArray(val) ? val[0] : val;
|
|
210
|
+
};
|
|
211
|
+
let serverUrl;
|
|
212
|
+
const forwardedHost = header("x-forwarded-host");
|
|
213
|
+
const origin = header("origin");
|
|
214
|
+
const host = header("host");
|
|
215
|
+
if (forwardedHost) {
|
|
216
|
+
const proto = header("x-forwarded-proto") || "https";
|
|
217
|
+
serverUrl = `${proto}://${forwardedHost}`;
|
|
218
|
+
}
|
|
219
|
+
else if (origin) {
|
|
220
|
+
serverUrl = origin;
|
|
221
|
+
}
|
|
222
|
+
else if (host) {
|
|
223
|
+
const proto = ["127.0.0.1:", "localhost:"].some((p) => host.startsWith(p))
|
|
224
|
+
? "http"
|
|
225
|
+
: "https";
|
|
226
|
+
serverUrl = `${proto}://${host}`;
|
|
227
|
+
}
|
|
228
|
+
else {
|
|
229
|
+
const devPort = process.env.__PORT || "3000";
|
|
230
|
+
serverUrl = `http://localhost:${devPort}`;
|
|
231
|
+
}
|
|
232
|
+
const html = isProduction
|
|
233
|
+
? templateHelper.renderProduction({
|
|
234
|
+
hostType,
|
|
235
|
+
serverUrl,
|
|
236
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
|
|
237
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
238
|
+
})
|
|
239
|
+
: templateHelper.renderDevelopment({
|
|
240
|
+
hostType,
|
|
241
|
+
serverUrl,
|
|
242
|
+
widgetName: name,
|
|
243
|
+
});
|
|
244
|
+
const connectDomains = [serverUrl];
|
|
245
|
+
if (!isProduction) {
|
|
246
|
+
const wsUrl = new URL(serverUrl);
|
|
247
|
+
wsUrl.protocol = wsUrl.protocol === "https:" ? "wss:" : "ws:";
|
|
248
|
+
connectDomains.push(wsUrl.origin);
|
|
249
|
+
}
|
|
250
|
+
let contentMetaOverrides = {};
|
|
251
|
+
if (isClaude) {
|
|
252
|
+
const pathname = extra?.requestInfo?.url?.pathname ?? "";
|
|
253
|
+
const url = `${serverUrl}${pathname}`;
|
|
254
|
+
const hash = crypto
|
|
255
|
+
.createHash("sha256")
|
|
256
|
+
.update(url)
|
|
257
|
+
.digest("hex")
|
|
258
|
+
.slice(0, 32);
|
|
259
|
+
contentMetaOverrides = { domain: `${hash}.claudemcpcontent.com` };
|
|
260
|
+
}
|
|
261
|
+
const contentMeta = buildContentMeta({
|
|
262
|
+
resourceDomains: [serverUrl],
|
|
263
|
+
connectDomains,
|
|
264
|
+
domain: serverUrl,
|
|
265
|
+
baseUriDomains: [serverUrl],
|
|
266
|
+
}, contentMetaOverrides);
|
|
267
|
+
return {
|
|
268
|
+
contents: [
|
|
269
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
270
|
+
],
|
|
271
|
+
};
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
lookupDistFile(key) {
|
|
275
|
+
const manifest = this.readManifest();
|
|
276
|
+
return manifest[key]?.file;
|
|
277
|
+
}
|
|
278
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
279
|
+
const manifest = this.readManifest();
|
|
280
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
281
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
282
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
283
|
+
}
|
|
284
|
+
readManifest() {
|
|
285
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,MAAM,MAAM,aAAa,CAAC;AACjC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,WAAW,CAAC;AAK7B,OAAO,EACL,SAAS,IAAI,aAAa,GAG3B,MAAM,yCAAyC,CAAC;AAejD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AAYzC,OAAO,EAAE,oBAAoB,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC;AACvE,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,cAAc,GAAG,CACrB,MAAS,EACT,MAAS,EACF,EAAE;IACT,OAAO,SAAS,CAAC,MAAM,EAAE,MAAM,EAAE,CAAC,SAAS,EAAE,SAAS,EAAE,EAAE;QACxD,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,IAAI,KAAK,CAAC,OAAO,CAAC,SAAS,CAAC,EAAE,CAAC;YACzD,OAAO,KAAK,CAAC,SAAS,EAAE,SAAS,CAAC,CAAC;QACrC,CAAC;IACH,CAAC,CAAC,CAAC;AACL,CAAC,CAAC;AA0LF,MAAM,OAAO,SAEX,SAAQ,aAAa;IAEb,OAAO,CAAW;IAClB,gBAAgB,GAAuB,EAAE,CAAC;IAC1C,qBAAqB,GAA4B,EAAE,CAAC;IACpD,oBAAoB,GAAyB,EAAE,CAAC;IAChD,oBAAoB,G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Y,GAAG,GAAG,QAAQ,YAAY,CAAC;QAC7C,OAAO,QAAQ,CAAC,WAAW,CAAC,EAAE,IAAI,IAAI,QAAQ,CAAC,YAAY,CAAC,EAAE,IAAI,CAAC;IACrE,CAAC;IAEO,YAAY;QAClB,OAAO,IAAI,CAAC,KAAK,CACf,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;IACJ,CAAC;CACF"}
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { WidgetHostType } from "./server.js";
|
|
2
|
+
declare class TemplateHelper {
|
|
3
|
+
private templateCache;
|
|
4
|
+
private loadTemplate;
|
|
5
|
+
renderProduction(data: {
|
|
6
|
+
hostType: WidgetHostType;
|
|
7
|
+
serverUrl: string;
|
|
8
|
+
widgetFile: string;
|
|
9
|
+
styleFile: string;
|
|
10
|
+
}): string;
|
|
11
|
+
renderDevelopment(data: {
|
|
12
|
+
hostType: WidgetHostType;
|
|
13
|
+
serverUrl: string;
|
|
14
|
+
widgetName: string;
|
|
15
|
+
}): string;
|
|
16
|
+
}
|
|
17
|
+
export declare const templateHelper: TemplateHelper;
|
|
18
|
+
export {};
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
import Handlebars from "handlebars";
|
|
2
1
|
import { readFileSync } from "node:fs";
|
|
3
|
-
import {
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
4
3
|
import { fileURLToPath } from "node:url";
|
|
4
|
+
import Handlebars from "handlebars";
|
|
5
5
|
const __filename = fileURLToPath(import.meta.url);
|
|
6
6
|
const __dirname = dirname(__filename);
|
|
7
7
|
class TemplateHelper {
|
|
8
8
|
templateCache = new Map();
|
|
9
9
|
loadTemplate(templateName) {
|
|
10
|
-
|
|
11
|
-
|
|
10
|
+
const cached = this.templateCache.get(templateName);
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached;
|
|
12
13
|
}
|
|
13
14
|
const templatePath = join(__dirname, "templates", `${templateName}.hbs`);
|
|
14
15
|
const templateSource = readFileSync(templatePath, "utf-8");
|
|
@@ -24,14 +25,6 @@ class TemplateHelper {
|
|
|
24
25
|
const template = this.loadTemplate("development");
|
|
25
26
|
return template(data);
|
|
26
27
|
}
|
|
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
28
|
}
|
|
36
29
|
export const templateHelper = new TemplateHelper();
|
|
37
30
|
//# sourceMappingURL=templateHelper.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,UAAU,MAAM,YAAY,CAAC;AAGpC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAEtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,MAAM,MAAM,GAAG,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,CAAC;QACpD,IAAI,MAAM,EAAE,CAAC;YACX,OAAO,MAAM,CAAC;QAChB,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,IAKhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAIjB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,aAAa,CAAC,CAAC;QAClD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;CACF;AAED,MAAM,CAAC,MAAM,cAAc,GAAG,IAAI,cAAc,EAAE,CAAC"}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}", serverUrl: "{{serverUrl}}" };</script>
|
|
2
|
+
<script type="module">
|
|
3
|
+
import { injectIntoGlobalHook } from "{{serverUrl}}/assets/@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>
|
|
9
|
+
<div id="root"></div>
|
|
10
|
+
<script type="module" id="dev-widget-entry">
|
|
11
|
+
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
12
|
+
</script>
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}", serverUrl: "{{serverUrl}}" };</script>
|
|
2
|
+
<div id="root"></div>
|
|
3
|
+
<script type="module">
|
|
4
|
+
import('{{serverUrl}}/assets/{{widgetFile}}');
|
|
5
|
+
</script>
|
|
6
|
+
<link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/{{styleFile}}" />
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type http from "node:http";
|
|
2
|
+
import { type Router } from "express";
|
|
3
|
+
/**
|
|
4
|
+
* Install Vite dev server
|
|
5
|
+
* This router MUST be installed at the application root, like so:
|
|
6
|
+
*
|
|
7
|
+
* const app = express();
|
|
8
|
+
*
|
|
9
|
+
* if (env.NODE_ENV !== "production") {
|
|
10
|
+
* app.use(await widgetsRouter());
|
|
11
|
+
* }
|
|
12
|
+
*/
|
|
13
|
+
export declare const widgetsDevServer: (httpServer: http.Server) => Promise<Router>;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
2
|
+
import path from "node:path";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express, {} from "express";
|
|
5
|
+
import { assetBaseUrlTransformPlugin } from "./asset-base-url-transform-plugin.js";
|
|
6
|
+
/**
|
|
7
|
+
* Install Vite dev server
|
|
8
|
+
* This router MUST be installed at the application root, like so:
|
|
9
|
+
*
|
|
10
|
+
* const app = express();
|
|
11
|
+
*
|
|
12
|
+
* if (env.NODE_ENV !== "production") {
|
|
13
|
+
* app.use(await widgetsRouter());
|
|
14
|
+
* }
|
|
15
|
+
*/
|
|
16
|
+
export const widgetsDevServer = async (httpServer) => {
|
|
17
|
+
const router = express.Router();
|
|
18
|
+
const { createServer, searchForWorkspaceRoot, loadConfigFromFile } = await import("vite");
|
|
19
|
+
// Since 0.16.0, the template is a single package that does not rely on workspace.
|
|
20
|
+
// It means that, when starting the server, the working dir is the template root
|
|
21
|
+
// hence we don't need to walk up the tree to find the workspace, which does not exist anymore.
|
|
22
|
+
let webAppRoot = path.join(process.cwd(), "web");
|
|
23
|
+
// fallback to the old behavior for backward compatibility
|
|
24
|
+
const hasWebAppRoot = existsSync(webAppRoot);
|
|
25
|
+
if (!hasWebAppRoot) {
|
|
26
|
+
const workspaceRoot = searchForWorkspaceRoot(process.cwd());
|
|
27
|
+
webAppRoot = path.join(workspaceRoot, "web");
|
|
28
|
+
}
|
|
29
|
+
const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
|
|
30
|
+
const { build, preview, plugins: userPlugins = [], ...devConfig } = configResult?.config || {};
|
|
31
|
+
const vite = await createServer({
|
|
32
|
+
...devConfig,
|
|
33
|
+
configFile: false, // Keep this to prevent vite from trying to resolve path in the target config file
|
|
34
|
+
appType: "custom",
|
|
35
|
+
server: {
|
|
36
|
+
allowedHosts: true,
|
|
37
|
+
middlewareMode: true,
|
|
38
|
+
hmr: {
|
|
39
|
+
server: httpServer,
|
|
40
|
+
},
|
|
41
|
+
},
|
|
42
|
+
root: webAppRoot,
|
|
43
|
+
optimizeDeps: {
|
|
44
|
+
include: ["react", "react-dom/client"],
|
|
45
|
+
},
|
|
46
|
+
plugins: [
|
|
47
|
+
...userPlugins,
|
|
48
|
+
assetBaseUrlTransformPlugin({
|
|
49
|
+
devServerOrigin: `http://localhost:${process.env.__PORT ?? "3000"}`,
|
|
50
|
+
}),
|
|
51
|
+
],
|
|
52
|
+
});
|
|
53
|
+
router.use(cors());
|
|
54
|
+
router.use("/", vite.middlewares);
|
|
55
|
+
return router;
|
|
56
|
+
};
|
|
57
|
+
//# sourceMappingURL=widgetsDevServer.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AAErC,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,EAAe,MAAM,SAAS,CAAC;AAC/C,OAAO,EA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