skybridge 0.0.0-dev.66b8f6b → 0.0.0-dev.66ea4ea
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 +143 -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 +6 -0
- package/dist/cli/use-nodemon.js +69 -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 +10 -0
- package/dist/commands/dev.js +42 -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.d.ts +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/const.d.ts +1 -0
- package/dist/server/const.js +2 -0
- package/dist/server/const.js.map +1 -0
- package/dist/server/express.d.ts +9 -0
- package/dist/server/express.js +72 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/express.test.d.ts +1 -0
- package/dist/server/express.test.js +74 -0
- package/dist/server/express.test.js.map +1 -0
- package/dist/server/index.d.ts +2 -1
- package/dist/server/index.js +0 -1
- package/dist/server/index.js.map +1 -1
- 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/server.d.ts +103 -10
- package/dist/server/server.js +191 -57
- package/dist/server/server.js.map +1 -1
- package/dist/server/templateHelper.d.ts +19 -0
- package/dist/server/templateHelper.js +30 -0
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +67 -0
- package/dist/server/templates/production.hbs +6 -0
- package/dist/server/widgetsDevServer.d.ts +7 -4
- package/dist/server/widgetsDevServer.js +35 -8
- package/dist/server/widgetsDevServer.js.map +1 -1
- 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 +261 -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 +71 -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 +118 -0
- package/dist/web/bridges/apps-sdk/types.js +10 -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 +36 -0
- package/dist/web/bridges/mcp-app/adaptor.js +190 -0
- package/dist/web/bridges/mcp-app/adaptor.js.map +1 -0
- package/dist/web/bridges/mcp-app/bridge.d.ts +43 -0
- package/dist/web/bridges/mcp-app/bridge.js +260 -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 +5 -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 +66 -0
- package/dist/web/bridges/mcp-app/use-mcp-app-context.test.js.map +1 -0
- package/dist/web/bridges/types.d.ts +98 -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 +47 -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 +126 -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 +141 -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 +60 -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.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 +1 -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 +50 -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 +57 -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 +19 -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 +94 -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 +62 -0
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/web/index.d.ts +7 -3
- package/dist/web/index.js +7 -3
- package/dist/web/index.js.map +1 -1
- package/dist/web/mount-widget.js +20 -3
- package/dist/web/mount-widget.js.map +1 -1
- 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 +46 -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/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 +13 -92
- package/dist/web/types.js +1 -9
- package/dist/web/types.js.map +1 -1
- package/package.json +69 -20
- package/tsconfig.base.json +28 -0
- package/dist/server/middleware.d.ts +0 -3
- package/dist/server/middleware.js +0 -47
- package/dist/server/middleware.js.map +0 -1
- package/dist/web/use-openai-global.d.ts +0 -2
- package/dist/web/use-openai-global.js +0 -21
- package/dist/web/use-openai-global.js.map +0 -1
- package/dist/web/use-tool-output.d.ts +0 -3
- package/dist/web/use-tool-output.js +0 -5
- package/dist/web/use-tool-output.js.map +0 -1
|
@@ -0,0 +1,64 @@
|
|
|
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
|
+
/**
|
|
55
|
+
* Get the responseMetadata type for a specific tool (widget or regular tool).
|
|
56
|
+
* This is inferred from the `_meta` property of the tool callback's return value.
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* type SearchMeta = ToolResponseMetadata<MyServer, "search">;
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
export type ToolResponseMetadata<ServerType, ToolName extends ToolNames<ServerType>> = ExtractTool<ServerType, ToolName>["responseMetadata"];
|
|
64
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"inferUtilityTypes.js","sourceRoot":"","sources":["../../src/server/inferUtilityTypes.ts"],"names":[],"mappings":""}
|
package/dist/server/server.d.ts
CHANGED
|
@@ -1,12 +1,105 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import type
|
|
3
|
-
import type {
|
|
4
|
-
type
|
|
5
|
-
type
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
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, ToolAnnotations } from "@modelcontextprotocol/sdk/types.js";
|
|
6
|
+
import type { RequestHandler } from "express";
|
|
7
|
+
export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unknown> = {
|
|
8
|
+
input: TInput;
|
|
9
|
+
output: TOutput;
|
|
10
|
+
responseMetadata: TResponseMetadata;
|
|
11
|
+
};
|
|
12
|
+
/**
|
|
13
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
14
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
15
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
16
|
+
*/
|
|
17
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
18
|
+
/**
|
|
19
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
20
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
21
|
+
*/
|
|
22
|
+
redirectDomains?: string[];
|
|
23
|
+
};
|
|
24
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
25
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
26
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
27
|
+
};
|
|
28
|
+
/** User-provided resource configuration with optional CSP override */
|
|
29
|
+
export type WidgetResourceMeta = {
|
|
30
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
31
|
+
} & Resource["_meta"];
|
|
32
|
+
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
33
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
34
|
+
_meta?: WidgetResourceMeta;
|
|
35
|
+
/** Restrict host types to a specific subset */
|
|
36
|
+
hosts?: WidgetHostType[];
|
|
37
|
+
};
|
|
38
|
+
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
39
|
+
type Simplify<T> = {
|
|
40
|
+
[K in keyof T]: T[K];
|
|
41
|
+
};
|
|
42
|
+
type ExtractStructuredContent<T> = T extends {
|
|
43
|
+
structuredContent: infer SC;
|
|
44
|
+
} ? Simplify<SC> : never;
|
|
45
|
+
type ExtractMeta<T> = [Extract<T, {
|
|
46
|
+
_meta: unknown;
|
|
47
|
+
}>] extends [never] ? unknown : Extract<T, {
|
|
48
|
+
_meta: unknown;
|
|
49
|
+
}> extends {
|
|
50
|
+
_meta: infer M;
|
|
51
|
+
} ? Simplify<M> : unknown;
|
|
52
|
+
/**
|
|
53
|
+
* Type-level marker interface for cross-package type inference.
|
|
54
|
+
* This enables TypeScript to infer tool types across package boundaries
|
|
55
|
+
* using structural typing on the $types property, rather than relying on
|
|
56
|
+
* class generic inference which fails when McpServer comes from different
|
|
57
|
+
* package installations.
|
|
58
|
+
*
|
|
59
|
+
* Inspired by tRPC's _def pattern and Hono's type markers.
|
|
60
|
+
*/
|
|
61
|
+
export interface McpServerTypes<TTools extends Record<string, ToolDef>> {
|
|
62
|
+
readonly tools: TTools;
|
|
63
|
+
}
|
|
64
|
+
type ShapeOutput<Shape extends ZodRawShapeCompat> = Simplify<{
|
|
65
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? never : K]: SchemaOutput<Shape[K]>;
|
|
66
|
+
} & {
|
|
67
|
+
[K in keyof Shape as undefined extends SchemaOutput<Shape[K]> ? K : never]?: SchemaOutput<Shape[K]>;
|
|
68
|
+
}>;
|
|
69
|
+
type AddTool<TTools, TName extends string, TInput extends ZodRawShapeCompat, TOutput, TResponseMetadata = unknown> = McpServer<TTools & {
|
|
70
|
+
[K in TName]: ToolDef<ShapeOutput<TInput>, TOutput, TResponseMetadata>;
|
|
71
|
+
}>;
|
|
72
|
+
type ToolConfig<TInput extends ZodRawShapeCompat | AnySchema> = {
|
|
73
|
+
title?: string;
|
|
74
|
+
description?: string;
|
|
75
|
+
inputSchema?: TInput;
|
|
76
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
77
|
+
annotations?: ToolAnnotations;
|
|
78
|
+
_meta?: Record<string, unknown>;
|
|
79
|
+
};
|
|
80
|
+
type ToolHandler<TInput extends ZodRawShapeCompat, TReturn extends {
|
|
81
|
+
content: CallToolResult["content"];
|
|
82
|
+
} = CallToolResult> = (args: ShapeOutput<TInput>, extra: RequestHandlerExtra<ServerRequest, ServerNotification>) => TReturn | Promise<TReturn>;
|
|
83
|
+
export declare class McpServer<TTools extends Record<string, ToolDef> = Record<never, ToolDef>> extends McpServerBase {
|
|
84
|
+
readonly $types: McpServerTypes<TTools>;
|
|
85
|
+
private express?;
|
|
86
|
+
private customMiddleware;
|
|
87
|
+
use(...handlers: RequestHandler[]): this;
|
|
88
|
+
use(path: string, ...handlers: RequestHandler[]): this;
|
|
89
|
+
run(): Promise<void>;
|
|
90
|
+
registerWidget<TName extends string, TInput extends ZodRawShapeCompat, TReturn extends {
|
|
91
|
+
content: CallToolResult["content"];
|
|
92
|
+
}>(name: TName, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
93
|
+
inputSchema?: TInput;
|
|
94
|
+
outputSchema?: ZodRawShapeCompat | AnySchema;
|
|
95
|
+
}, toolCallback: ToolHandler<TInput, TReturn>): AddTool<TTools, TName, TInput, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
96
|
+
registerTool<TName extends string, InputArgs extends ZodRawShapeCompat, TReturn extends {
|
|
97
|
+
content: CallToolResult["content"];
|
|
98
|
+
}>(name: TName, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs, TReturn>): AddTool<TTools, TName, InputArgs, ExtractStructuredContent<TReturn>, ExtractMeta<TReturn>>;
|
|
99
|
+
registerTool<InputArgs extends ZodRawShapeCompat>(name: string, config: ToolConfig<InputArgs>, cb: ToolHandler<InputArgs>): RegisteredTool;
|
|
100
|
+
private registerWidgetResource;
|
|
101
|
+
private lookupDistFile;
|
|
102
|
+
private lookupDistFileWithIndexFallback;
|
|
103
|
+
private readManifest;
|
|
11
104
|
}
|
|
12
105
|
export {};
|
package/dist/server/server.js
CHANGED
|
@@ -1,70 +1,204 @@
|
|
|
1
|
-
import
|
|
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 { DEFAULT_HMR_PORT } from "./const.js";
|
|
8
|
+
import { createServer } from "./express.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
|
+
};
|
|
2
17
|
export class McpServer extends McpServerBase {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
if (
|
|
7
|
-
|
|
18
|
+
express;
|
|
19
|
+
customMiddleware = [];
|
|
20
|
+
use(pathOrHandler, ...handlers) {
|
|
21
|
+
if (typeof pathOrHandler === "string") {
|
|
22
|
+
this.customMiddleware.push({
|
|
23
|
+
path: pathOrHandler,
|
|
24
|
+
handlers,
|
|
25
|
+
});
|
|
8
26
|
}
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
<link rel="stylesheet" crossorigin href="${serverUrl}/assets/style.css">
|
|
35
|
-
`;
|
|
36
|
-
}
|
|
37
|
-
catch (error) {
|
|
38
|
-
console.error("Failed to load production assets:", error);
|
|
39
|
-
return "";
|
|
40
|
-
}
|
|
41
|
-
}
|
|
42
|
-
return `
|
|
43
|
-
<div id="root"></div>
|
|
44
|
-
<script type="module">
|
|
45
|
-
import('${serverUrl}/src/widgets/${name}.tsx');
|
|
46
|
-
</script>
|
|
47
|
-
`;
|
|
48
|
-
};
|
|
49
|
-
const html = buildHtml();
|
|
50
|
-
return {
|
|
51
|
-
contents: [
|
|
52
|
-
{
|
|
53
|
-
uri,
|
|
54
|
-
mimeType: "text/html+skybridge",
|
|
55
|
-
text: process.env.NODE_ENV === "production" ? html : injectViteClient(html),
|
|
56
|
-
},
|
|
57
|
-
],
|
|
58
|
-
};
|
|
27
|
+
else {
|
|
28
|
+
this.customMiddleware.push({
|
|
29
|
+
handlers: [pathOrHandler, ...handlers],
|
|
30
|
+
});
|
|
31
|
+
}
|
|
32
|
+
return this;
|
|
33
|
+
}
|
|
34
|
+
async run() {
|
|
35
|
+
if (!this.express) {
|
|
36
|
+
this.express = await createServer({
|
|
37
|
+
server: this,
|
|
38
|
+
customMiddleware: this.customMiddleware,
|
|
39
|
+
});
|
|
40
|
+
}
|
|
41
|
+
const express = this.express;
|
|
42
|
+
return new Promise((resolve, reject) => {
|
|
43
|
+
const server = http.createServer(express);
|
|
44
|
+
server.on("error", (error) => {
|
|
45
|
+
console.error("Failed to start server:", error);
|
|
46
|
+
reject(error);
|
|
47
|
+
});
|
|
48
|
+
const port = parseInt(process.env.__PORT ?? "3000", 10);
|
|
49
|
+
server.listen(port, () => {
|
|
50
|
+
resolve();
|
|
51
|
+
});
|
|
59
52
|
});
|
|
53
|
+
}
|
|
54
|
+
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
55
|
+
const userMeta = resourceConfig._meta;
|
|
60
56
|
const toolMeta = {
|
|
61
57
|
...toolConfig._meta,
|
|
62
|
-
"openai/outputTemplate": uri,
|
|
63
58
|
};
|
|
59
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("apps-sdk")) {
|
|
60
|
+
const widgetConfig = {
|
|
61
|
+
hostType: "apps-sdk",
|
|
62
|
+
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
63
|
+
mimeType: "text/html+skybridge",
|
|
64
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
65
|
+
const userUi = userMeta?.ui;
|
|
66
|
+
const userCsp = userUi?.csp;
|
|
67
|
+
const defaults = {
|
|
68
|
+
"openai/widgetCSP": {
|
|
69
|
+
resource_domains: resourceDomains,
|
|
70
|
+
connect_domains: connectDomains,
|
|
71
|
+
},
|
|
72
|
+
"openai/widgetDomain": domain,
|
|
73
|
+
"openai/widgetDescription": resourceConfig.description,
|
|
74
|
+
};
|
|
75
|
+
const fromUi = {
|
|
76
|
+
"openai/widgetCSP": {
|
|
77
|
+
resource_domains: userCsp?.resourceDomains,
|
|
78
|
+
connect_domains: userCsp?.connectDomains,
|
|
79
|
+
frame_domains: userCsp?.frameDomains,
|
|
80
|
+
redirect_domains: userCsp?.redirectDomains,
|
|
81
|
+
},
|
|
82
|
+
"openai/widgetDomain": userUi?.domain,
|
|
83
|
+
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
84
|
+
};
|
|
85
|
+
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
86
|
+
return mergeWithUnion(mergeWithUnion(mergeWithUnion(defaults, fromUi), directOpenaiKeys), { "openai/widgetDomain": overrides.domain });
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
this.registerWidgetResource({
|
|
90
|
+
name,
|
|
91
|
+
widgetConfig,
|
|
92
|
+
resourceConfig,
|
|
93
|
+
});
|
|
94
|
+
toolMeta["openai/outputTemplate"] = widgetConfig.uri;
|
|
95
|
+
}
|
|
96
|
+
if (!resourceConfig.hosts || resourceConfig.hosts.includes("mcp-app")) {
|
|
97
|
+
const widgetConfig = {
|
|
98
|
+
hostType: "mcp-app",
|
|
99
|
+
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
100
|
+
mimeType: "text/html;profile=mcp-app",
|
|
101
|
+
buildContentMeta: ({ resourceDomains, connectDomains, domain }, overrides) => {
|
|
102
|
+
const defaults = {
|
|
103
|
+
ui: {
|
|
104
|
+
csp: {
|
|
105
|
+
resourceDomains,
|
|
106
|
+
connectDomains,
|
|
107
|
+
},
|
|
108
|
+
domain,
|
|
109
|
+
},
|
|
110
|
+
};
|
|
111
|
+
return mergeWithUnion(defaults, {
|
|
112
|
+
ui: { ...userMeta?.ui, ...overrides },
|
|
113
|
+
});
|
|
114
|
+
},
|
|
115
|
+
};
|
|
116
|
+
this.registerWidgetResource({
|
|
117
|
+
name,
|
|
118
|
+
widgetConfig,
|
|
119
|
+
resourceConfig,
|
|
120
|
+
});
|
|
121
|
+
// @ts-expect-error - For backwards compatibility with Claude current implementation of the specs
|
|
122
|
+
toolMeta["ui/resourceUri"] = widgetConfig.uri;
|
|
123
|
+
toolMeta.ui = { resourceUri: widgetConfig.uri };
|
|
124
|
+
}
|
|
64
125
|
this.registerTool(name, {
|
|
65
126
|
...toolConfig,
|
|
66
127
|
_meta: toolMeta,
|
|
67
128
|
}, toolCallback);
|
|
129
|
+
return this;
|
|
130
|
+
}
|
|
131
|
+
registerTool(name, config, cb) {
|
|
132
|
+
super.registerTool(name, config, cb);
|
|
133
|
+
return this;
|
|
134
|
+
}
|
|
135
|
+
registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
|
|
136
|
+
const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
|
|
137
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
|
|
138
|
+
const isProduction = process.env.NODE_ENV === "production";
|
|
139
|
+
const useForwardedHost = process.env.SKYBRIDGE_USE_FORWARDED_HOST === "true";
|
|
140
|
+
const isClaude = extra?.requestInfo?.headers?.["user-agent"] === "Claude-User";
|
|
141
|
+
const hostFromHeaders = extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
142
|
+
extra?.requestInfo?.headers?.host;
|
|
143
|
+
const useExternalHost = isProduction || useForwardedHost || isClaude;
|
|
144
|
+
const devPort = process.env.__PORT || "3000";
|
|
145
|
+
const serverUrl = useExternalHost
|
|
146
|
+
? `https://${hostFromHeaders}`
|
|
147
|
+
: `http://localhost:${devPort}`;
|
|
148
|
+
const html = isProduction
|
|
149
|
+
? templateHelper.renderProduction({
|
|
150
|
+
hostType,
|
|
151
|
+
serverUrl,
|
|
152
|
+
widgetFile: this.lookupDistFileWithIndexFallback(`src/widgets/${name}`),
|
|
153
|
+
styleFile: this.lookupDistFile("style.css"),
|
|
154
|
+
})
|
|
155
|
+
: templateHelper.renderDevelopment({
|
|
156
|
+
hostType,
|
|
157
|
+
serverUrl,
|
|
158
|
+
useLocalNetworkAccess: !useExternalHost,
|
|
159
|
+
widgetName: name,
|
|
160
|
+
});
|
|
161
|
+
const connectDomains = [serverUrl];
|
|
162
|
+
if (!isProduction) {
|
|
163
|
+
const hmrPort = process.env.__SKYBRIDGE_HMR_PORT ?? DEFAULT_HMR_PORT;
|
|
164
|
+
const VITE_HMR_WEBSOCKET_DEFAULT_URL = `ws://localhost:${hmrPort}`;
|
|
165
|
+
connectDomains.push(VITE_HMR_WEBSOCKET_DEFAULT_URL);
|
|
166
|
+
}
|
|
167
|
+
const contentMetaOverrides = isClaude
|
|
168
|
+
? {
|
|
169
|
+
domain: `${crypto
|
|
170
|
+
.createHash("sha256")
|
|
171
|
+
.update(extra.requestInfo?.url?.href ||
|
|
172
|
+
`https://${hostFromHeaders}/mcp`)
|
|
173
|
+
.digest("hex")
|
|
174
|
+
.slice(0, 32)}.claudemcpcontent.com`,
|
|
175
|
+
}
|
|
176
|
+
: {};
|
|
177
|
+
const contentMeta = buildContentMeta({
|
|
178
|
+
resourceDomains: [serverUrl],
|
|
179
|
+
connectDomains,
|
|
180
|
+
domain: serverUrl,
|
|
181
|
+
baseUriDomains: [serverUrl],
|
|
182
|
+
}, contentMetaOverrides);
|
|
183
|
+
return {
|
|
184
|
+
contents: [
|
|
185
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
186
|
+
],
|
|
187
|
+
};
|
|
188
|
+
});
|
|
189
|
+
}
|
|
190
|
+
lookupDistFile(key) {
|
|
191
|
+
const manifest = this.readManifest();
|
|
192
|
+
return manifest[key]?.file;
|
|
193
|
+
}
|
|
194
|
+
lookupDistFileWithIndexFallback(basePath) {
|
|
195
|
+
const manifest = this.readManifest();
|
|
196
|
+
const flatFileKey = `${basePath}.tsx`;
|
|
197
|
+
const indexFileKey = `${basePath}/index.tsx`;
|
|
198
|
+
return manifest[flatFileKey]?.file ?? manifest[indexFileKey]?.file;
|
|
199
|
+
}
|
|
200
|
+
readManifest() {
|
|
201
|
+
return JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
68
202
|
}
|
|
69
203
|
}
|
|
70
204
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,IAAI,aAAa,
|
|
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;AAcjD,OAAO,EAAE,SAAS,EAAE,KAAK,EAAE,MAAM,YAAY,CAAC;AAE9C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,cAAc,CAAC;AAC5C,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AAErD,MAAM,cAAc,GAAG,CACrB,MAAS,EACT,MAAS,E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J,CAAC;CACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
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
|
+
useLocalNetworkAccess: boolean;
|
|
15
|
+
widgetName: string;
|
|
16
|
+
}): string;
|
|
17
|
+
}
|
|
18
|
+
export declare const templateHelper: TemplateHelper;
|
|
19
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { readFileSync } from "node:fs";
|
|
2
|
+
import { dirname, join } from "node:path";
|
|
3
|
+
import { fileURLToPath } from "node:url";
|
|
4
|
+
import Handlebars from "handlebars";
|
|
5
|
+
const __filename = fileURLToPath(import.meta.url);
|
|
6
|
+
const __dirname = dirname(__filename);
|
|
7
|
+
class TemplateHelper {
|
|
8
|
+
templateCache = new Map();
|
|
9
|
+
loadTemplate(templateName) {
|
|
10
|
+
const cached = this.templateCache.get(templateName);
|
|
11
|
+
if (cached) {
|
|
12
|
+
return cached;
|
|
13
|
+
}
|
|
14
|
+
const templatePath = join(__dirname, "templates", `${templateName}.hbs`);
|
|
15
|
+
const templateSource = readFileSync(templatePath, "utf-8");
|
|
16
|
+
const template = Handlebars.compile(templateSource);
|
|
17
|
+
this.templateCache.set(templateName, template);
|
|
18
|
+
return template;
|
|
19
|
+
}
|
|
20
|
+
renderProduction(data) {
|
|
21
|
+
const template = this.loadTemplate("production");
|
|
22
|
+
return template(data);
|
|
23
|
+
}
|
|
24
|
+
renderDevelopment(data) {
|
|
25
|
+
const template = this.loadTemplate("development");
|
|
26
|
+
return template(data);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
export const templateHelper = new TemplateHelper();
|
|
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,IAKjB;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,67 @@
|
|
|
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
|
+
{{#if useLocalNetworkAccess}}
|
|
10
|
+
<script type="module">
|
|
11
|
+
// Checks for browser support and shows error if local network access is denied
|
|
12
|
+
(async () => {
|
|
13
|
+
if (!navigator.permissions?.query) {
|
|
14
|
+
return;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
// Skip for non-http(s) protocols (file://, custom protocols in Electron, etc.)
|
|
18
|
+
const protocol = window.location.protocol;
|
|
19
|
+
const isNonHttpProtocol = protocol !== 'http:' && protocol !== 'https:'
|
|
20
|
+
if (isNonHttpProtocol) {
|
|
21
|
+
return;
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
const host = window.location.hostname;
|
|
25
|
+
const isLoopback = host === 'localhost'
|
|
26
|
+
|| /^127\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})$/.test(host)
|
|
27
|
+
|| host === '::1';
|
|
28
|
+
if (isLoopback) {
|
|
29
|
+
return;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
try {
|
|
33
|
+
const status = await navigator.permissions.query({ name: "local-network-access" });
|
|
34
|
+
if (status.state === "denied") {
|
|
35
|
+
const errorDiv = document.createElement("div");
|
|
36
|
+
errorDiv.style.cssText = "background: #fef2f2; border: 2px solid #ef4444; border-radius: 8px; padding: 16px; text-align: center; z-index: 10000; font-family: system-ui, sans-serif;";
|
|
37
|
+
|
|
38
|
+
const errorTitle = document.createElement("div");
|
|
39
|
+
errorTitle.style.cssText = "color: #ef4444; font-size: 18px; font-weight: 600; margin-bottom: 8px;";
|
|
40
|
+
errorTitle.textContent = "Error: Local network access permission is denied.";
|
|
41
|
+
|
|
42
|
+
const errorMessage = document.createElement("div");
|
|
43
|
+
errorMessage.style.cssText = "color: #ef4444; font-size: 14px;";
|
|
44
|
+
errorMessage.textContent = "Local network access is required for your widget to connect to the local dev server. Please enable it in your browser settings. ";
|
|
45
|
+
|
|
46
|
+
const link = document.createElement("a");
|
|
47
|
+
link.href = "https://developer.chrome.com/blog/local-network-access";
|
|
48
|
+
link.target = "_blank";
|
|
49
|
+
link.rel = "noopener noreferrer";
|
|
50
|
+
link.style.cssText = "color: #ef4444; text-decoration: underline;";
|
|
51
|
+
link.textContent = "Learn more";
|
|
52
|
+
errorMessage.appendChild(link);
|
|
53
|
+
|
|
54
|
+
errorDiv.appendChild(errorTitle);
|
|
55
|
+
errorDiv.appendChild(errorMessage);
|
|
56
|
+
document.body.appendChild(errorDiv);
|
|
57
|
+
}
|
|
58
|
+
} catch (e) {
|
|
59
|
+
// Permission API doesn't support local-network-access, ignore silently
|
|
60
|
+
}
|
|
61
|
+
})();
|
|
62
|
+
</script>
|
|
63
|
+
{{/if}}
|
|
64
|
+
<div id="root"></div>
|
|
65
|
+
<script type="module" id="dev-widget-entry">
|
|
66
|
+
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
67
|
+
</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}}" />
|
|
@@ -1,9 +1,12 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Router } from "express";
|
|
2
2
|
/**
|
|
3
|
-
* Install Vite dev server
|
|
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
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* if (env.NODE_ENV !== "production") {
|
|
9
|
+
* app.use(await widgetsRouter());
|
|
10
|
+
* }
|
|
8
11
|
*/
|
|
9
|
-
export declare const widgetsDevServer: () => Promise<
|
|
12
|
+
export declare const widgetsDevServer: () => Promise<Router>;
|