skybridge 0.0.0-dev.f3e11a3 → 0.0.0-dev.f3fc72c
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 -0
- package/dist/src/server/index.d.ts +0 -1
- package/dist/src/server/index.js +0 -1
- package/dist/src/server/index.js.map +1 -1
- package/dist/src/server/server.d.ts +28 -1
- package/dist/src/server/server.js +53 -15
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templates/development.hbs +55 -2
- package/dist/src/server/templates/production.hbs +1 -1
- package/dist/src/server/widgetsDevServer.d.ts +2 -2
- package/dist/src/server/widgetsDevServer.js +11 -3
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/widget.test.js +103 -12
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.d.ts +13 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js +33 -0
- package/dist/src/web/bridges/adaptors/apps-sdk-adaptor.js.map +1 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.d.ts +16 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js +115 -0
- package/dist/src/web/bridges/adaptors/mcp-app-adaptor.js.map +1 -0
- package/dist/src/web/bridges/apps-sdk-bridge.d.ts +4 -2
- package/dist/src/web/bridges/apps-sdk-bridge.js +19 -14
- package/dist/src/web/bridges/apps-sdk-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-adaptor.d.ts +2 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js +8 -0
- package/dist/src/web/bridges/hooks/use-adaptor.js.map +1 -0
- package/dist/src/web/bridges/hooks/use-bridge.d.ts +2 -3
- package/dist/src/web/bridges/hooks/use-bridge.js +5 -24
- package/dist/src/web/bridges/hooks/use-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.d.ts +3 -2
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.js.map +1 -1
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js +9 -26
- package/dist/src/web/bridges/hooks/use-mcp-app-bridge.test.js.map +1 -1
- package/dist/src/web/bridges/index.d.ts +1 -0
- package/dist/src/web/bridges/index.js +1 -0
- package/dist/src/web/bridges/index.js.map +1 -1
- package/dist/src/web/bridges/mcp-app-bridge.d.ts +19 -7
- package/dist/src/web/bridges/mcp-app-bridge.js +58 -26
- package/dist/src/web/bridges/mcp-app-bridge.js.map +1 -1
- package/dist/src/web/bridges/types.d.ts +57 -0
- package/dist/src/web/bridges/types.js +2 -0
- package/dist/src/web/bridges/types.js.map +1 -0
- package/dist/src/web/data-llm.js +4 -2
- package/dist/src/web/data-llm.js.map +1 -1
- package/dist/src/web/generate-helpers.test-d.js +4 -1
- package/dist/src/web/generate-helpers.test-d.js.map +1 -1
- package/dist/src/web/hooks/test/utils.d.ts +10 -0
- package/dist/src/web/hooks/test/utils.js +40 -0
- package/dist/src/web/hooks/test/utils.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +1 -1
- package/dist/src/web/hooks/use-call-tool.js +12 -4
- package/dist/src/web/hooks/use-call-tool.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js +1 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-call-tool.test.js +28 -3
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -1
- package/dist/src/web/hooks/use-display-mode.d.ts +1 -1
- package/dist/src/web/hooks/use-display-mode.js +6 -3
- package/dist/src/web/hooks/use-display-mode.js.map +1 -1
- package/dist/src/web/hooks/use-layout.js +3 -3
- package/dist/src/web/hooks/use-layout.js.map +1 -1
- package/dist/src/web/hooks/use-layout.test.js +87 -38
- package/dist/src/web/hooks/use-layout.test.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.js +5 -3
- package/dist/src/web/hooks/use-open-external.js.map +1 -1
- package/dist/src/web/hooks/use-open-external.test.js +41 -15
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +3 -6
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.d.ts +12 -1
- package/dist/src/web/hooks/use-tool-info.js +15 -9
- package/dist/src/web/hooks/use-tool-info.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js +40 -4
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +1 -1
- package/dist/src/web/hooks/use-tool-info.test.js +117 -47
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -1
- package/dist/src/web/hooks/use-user.js +2 -2
- package/dist/src/web/hooks/use-user.js.map +1 -1
- package/dist/src/web/hooks/use-user.test.js +83 -34
- package/dist/src/web/hooks/use-user.test.js.map +1 -1
- package/dist/src/web/plugin/transform-data-llm.js +6 -3
- package/dist/src/web/plugin/transform-data-llm.js.map +1 -1
- package/dist/src/web/types.d.ts +3 -5
- package/dist/src/web/types.js.map +1 -1
- package/package.json +29 -26
- package/dist/src/server/devtoolsStaticServer.d.ts +0 -15
- package/dist/src/server/devtoolsStaticServer.js +0 -38
- package/dist/src/server/devtoolsStaticServer.js.map +0 -1
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Alpic
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
export { devtoolsStaticServer } from "./devtoolsStaticServer.js";
|
|
2
1
|
export type { AnyToolRegistry, InferTools, ToolInput, ToolNames, ToolOutput, ToolResponseMetadata, } from "./inferUtilityTypes.js";
|
|
3
2
|
export type { McpServerTypes, ToolDef, WidgetHostType } from "./server.js";
|
|
4
3
|
export { McpServer } from "./server.js";
|
package/dist/src/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AASA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { McpUiResourceMeta } from "@modelcontextprotocol/ext-apps";
|
|
1
2
|
import { McpServer as McpServerBase, type RegisteredTool } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
3
|
import type { AnySchema, SchemaOutput, ZodRawShapeCompat } from "@modelcontextprotocol/sdk/server/zod-compat.js";
|
|
3
4
|
import type { RequestHandlerExtra } from "@modelcontextprotocol/sdk/shared/protocol.js";
|
|
@@ -7,8 +8,34 @@ export type ToolDef<TInput = unknown, TOutput = unknown, TResponseMetadata = unk
|
|
|
7
8
|
output: TOutput;
|
|
8
9
|
responseMetadata: TResponseMetadata;
|
|
9
10
|
};
|
|
11
|
+
/**
|
|
12
|
+
* Extended MCP Apps CSP with upcoming fields from ext-apps PR #158
|
|
13
|
+
* and Skybridge-specific fields for OpenAI compatibility
|
|
14
|
+
* @see https://github.com/modelcontextprotocol/ext-apps/pull/158
|
|
15
|
+
*/
|
|
16
|
+
type ExtendedMcpUiResourceCsp = McpUiResourceMeta["csp"] & {
|
|
17
|
+
/** Origins allowed for nested iframe embeds */
|
|
18
|
+
frameDomains?: string[];
|
|
19
|
+
/** Origins permitted for the <base> tag URI directive */
|
|
20
|
+
baseUriDomains?: string[];
|
|
21
|
+
/**
|
|
22
|
+
* Origins that can receive openExternal redirects without safe-link modal (OpenAI-specific)
|
|
23
|
+
* @see https://developers.openai.com/apps-sdk/reference#component-resource-_meta-fields
|
|
24
|
+
*/
|
|
25
|
+
redirectDomains?: string[];
|
|
26
|
+
};
|
|
27
|
+
/** Extended MCP Apps resource metadata with upcoming CSP fields */
|
|
28
|
+
type ExtendedMcpUiResourceMeta = Omit<McpUiResourceMeta, "csp"> & {
|
|
29
|
+
csp?: ExtendedMcpUiResourceCsp;
|
|
30
|
+
};
|
|
31
|
+
/** User-provided resource configuration with optional CSP override */
|
|
32
|
+
export type WidgetResourceMeta = {
|
|
33
|
+
ui?: ExtendedMcpUiResourceMeta;
|
|
34
|
+
} & Resource["_meta"];
|
|
10
35
|
export type WidgetHostType = "apps-sdk" | "mcp-app";
|
|
11
|
-
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType"
|
|
36
|
+
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType" | "_meta"> & {
|
|
37
|
+
_meta?: WidgetResourceMeta;
|
|
38
|
+
};
|
|
12
39
|
type McpServerOriginalToolConfig = Omit<Parameters<typeof McpServerBase.prototype.registerTool<ZodRawShapeCompat, ZodRawShapeCompat>>[1], "inputSchema" | "outputSchema">;
|
|
13
40
|
type Simplify<T> = {
|
|
14
41
|
[K in keyof T]: T[K];
|
|
@@ -1,39 +1,70 @@
|
|
|
1
1
|
import { readFileSync } from "node:fs";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
4
|
+
import { toMerged } from "es-toolkit";
|
|
4
5
|
import { templateHelper } from "./templateHelper.js";
|
|
5
6
|
export class McpServer extends McpServerBase {
|
|
6
7
|
registerWidget(name, resourceConfig, toolConfig, toolCallback) {
|
|
7
|
-
const
|
|
8
|
-
...(resourceConfig._meta ?? {}),
|
|
9
|
-
};
|
|
10
|
-
if (toolConfig.description !== undefined) {
|
|
11
|
-
resourceMetadata["openai/widgetDescription"] = toolConfig.description;
|
|
12
|
-
}
|
|
8
|
+
const userMeta = resourceConfig._meta;
|
|
13
9
|
const appsSdkResourceConfig = {
|
|
14
10
|
hostType: "apps-sdk",
|
|
15
11
|
uri: `ui://widgets/apps-sdk/${name}.html`,
|
|
16
12
|
mimeType: "text/html+skybridge",
|
|
13
|
+
buildContentMeta: ({ serverUrl, wsServerUrl }) => {
|
|
14
|
+
const userUi = userMeta?.ui;
|
|
15
|
+
const defaults = {
|
|
16
|
+
"openai/widgetCSP": {
|
|
17
|
+
resource_domains: [serverUrl],
|
|
18
|
+
connect_domains: [serverUrl, wsServerUrl],
|
|
19
|
+
},
|
|
20
|
+
"openai/widgetDomain": serverUrl,
|
|
21
|
+
"openai/widgetDescription": toolConfig.description,
|
|
22
|
+
};
|
|
23
|
+
const userCsp = userUi?.csp;
|
|
24
|
+
const fromUi = {
|
|
25
|
+
"openai/widgetCSP": {
|
|
26
|
+
resource_domains: userCsp?.resourceDomains,
|
|
27
|
+
connect_domains: userCsp?.connectDomains,
|
|
28
|
+
frame_domains: userCsp?.frameDomains,
|
|
29
|
+
redirect_domains: userCsp?.redirectDomains,
|
|
30
|
+
},
|
|
31
|
+
"openai/widgetDomain": userUi?.domain,
|
|
32
|
+
"openai/widgetPrefersBorder": userUi?.prefersBorder,
|
|
33
|
+
};
|
|
34
|
+
const directOpenaiKeys = Object.fromEntries(Object.entries(userMeta ?? {}).filter(([key]) => key.startsWith("openai/")));
|
|
35
|
+
return toMerged(toMerged(defaults, fromUi), directOpenaiKeys);
|
|
36
|
+
},
|
|
17
37
|
};
|
|
18
38
|
const extAppsResourceConfig = {
|
|
19
39
|
hostType: "mcp-app",
|
|
20
40
|
uri: `ui://widgets/ext-apps/${name}.html`,
|
|
21
41
|
mimeType: "text/html;profile=mcp-app",
|
|
42
|
+
buildContentMeta: ({ serverUrl, wsServerUrl }) => {
|
|
43
|
+
const defaults = {
|
|
44
|
+
ui: {
|
|
45
|
+
csp: {
|
|
46
|
+
resourceDomains: [serverUrl],
|
|
47
|
+
connectDomains: [serverUrl, wsServerUrl],
|
|
48
|
+
},
|
|
49
|
+
domain: serverUrl,
|
|
50
|
+
},
|
|
51
|
+
};
|
|
52
|
+
return toMerged(defaults, { ui: userMeta?.ui });
|
|
53
|
+
},
|
|
22
54
|
};
|
|
23
|
-
[appsSdkResourceConfig, extAppsResourceConfig].forEach((
|
|
55
|
+
[appsSdkResourceConfig, extAppsResourceConfig].forEach((widgetConfig) => {
|
|
24
56
|
this.registerWidgetResource({
|
|
25
57
|
name,
|
|
26
|
-
|
|
27
|
-
widgetUri: uri,
|
|
28
|
-
mimeType,
|
|
58
|
+
widgetConfig,
|
|
29
59
|
resourceConfig,
|
|
30
|
-
resourceMetadata,
|
|
31
60
|
});
|
|
32
61
|
});
|
|
33
62
|
const toolMeta = {
|
|
34
63
|
...toolConfig._meta,
|
|
35
64
|
"openai/outputTemplate": appsSdkResourceConfig.uri,
|
|
36
|
-
|
|
65
|
+
ui: {
|
|
66
|
+
resourceUri: extAppsResourceConfig.uri,
|
|
67
|
+
},
|
|
37
68
|
};
|
|
38
69
|
this.registerTool(name, {
|
|
39
70
|
...toolConfig,
|
|
@@ -45,11 +76,13 @@ export class McpServer extends McpServerBase {
|
|
|
45
76
|
super.registerTool(name, config, cb);
|
|
46
77
|
return this;
|
|
47
78
|
}
|
|
48
|
-
registerWidgetResource({ name,
|
|
49
|
-
|
|
79
|
+
registerWidgetResource({ name, widgetConfig, resourceConfig, }) {
|
|
80
|
+
const { hostType, uri: widgetUri, mimeType, buildContentMeta, } = widgetConfig;
|
|
81
|
+
this.registerResource(name, widgetUri, { ...resourceConfig, _meta: resourceConfig._meta }, async (uri, extra) => {
|
|
50
82
|
const serverUrl = process.env.NODE_ENV === "production"
|
|
51
83
|
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ?? extra?.requestInfo?.headers?.host}`
|
|
52
84
|
: `http://localhost:3000`;
|
|
85
|
+
const wsServerUrl = serverUrl.replace(/^http/, "ws");
|
|
53
86
|
const html = process.env.NODE_ENV === "production"
|
|
54
87
|
? templateHelper.renderProduction({
|
|
55
88
|
hostType,
|
|
@@ -62,7 +95,12 @@ export class McpServer extends McpServerBase {
|
|
|
62
95
|
serverUrl,
|
|
63
96
|
widgetName: name,
|
|
64
97
|
});
|
|
65
|
-
|
|
98
|
+
const contentMeta = buildContentMeta({ serverUrl, wsServerUrl });
|
|
99
|
+
return {
|
|
100
|
+
contents: [
|
|
101
|
+
{ uri: uri.href, mimeType, text: html, _meta: contentMeta },
|
|
102
|
+
],
|
|
103
|
+
};
|
|
66
104
|
});
|
|
67
105
|
}
|
|
68
106
|
lookupDistFile(key) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;
|
|
1
|
+
{"version":3,"file":"server.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C,CAAC;gBACJ,CAAC,CAAC,cAAc,CAAC,iBAAiB,CAAC;oBAC/B,QAAQ;oBACR,SAAS;oBACT,UAAU,EAAE,IAAI;iBACjB,CAAC,CAAC;YAET,MAAM,WAAW,GAAG,gBAAgB,CAAC,EAAE,SAAS,EAAE,WAAW,EAAE,CAAC,CAAC;YAEjE,OAAO;gBACL,QAAQ,EAAE;oBACR,EAAE,GAAG,EAAE,GAAG,CAAC,IAAI,EAAE,QAAQ,EAAE,IAAI,EAAE,IAAI,EAAE,KAAK,EAAE,WAAW,EAAE;iBAC5D;aACF,CAAC;QACJ,CAAC,CACF,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QACrC,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;IAEO,+BAA+B,CAAC,QAAgB;QACtD,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,EAAE,CAAC;QAErC,MAAM,WAAW,GAAG,GAAG,QAAQ,MAAM,CAAC;QACtC,MAAM,YAAY,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"}
|
|
@@ -1,12 +1,65 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
-
<script>
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
3
3
|
<script type="module">
|
|
4
|
-
import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
|
|
4
|
+
import { injectIntoGlobalHook } from "{{serverUrl}}/assets/@react-refresh";
|
|
5
5
|
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
6
6
|
window.$RefreshSig$ = () => (type) => type;
|
|
7
7
|
window.__vite_plugin_react_preamble_installed__ = true;
|
|
8
8
|
</script>
|
|
9
9
|
<script type="module" src="{{serverUrl}}/@vite/client"></script>
|
|
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>
|
|
10
63
|
<div id="root"></div>
|
|
11
64
|
<script type="module" id="dev-widget-entry">
|
|
12
65
|
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
<base href="{{serverUrl}}" />
|
|
2
|
-
<script>
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
3
3
|
<div id="root"></div>
|
|
4
4
|
<script type="module">
|
|
5
5
|
import('{{serverUrl}}/assets/{{widgetFile}}');
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type
|
|
1
|
+
import { type Router } from "express";
|
|
2
2
|
/**
|
|
3
3
|
* Install Vite dev server
|
|
4
4
|
* This router MUST be installed at the application root, like so:
|
|
@@ -9,4 +9,4 @@ import { type RequestHandler } from "express";
|
|
|
9
9
|
* app.use(await widgetsRouter());
|
|
10
10
|
* }
|
|
11
11
|
*/
|
|
12
|
-
export declare const widgetsDevServer: () => Promise<
|
|
12
|
+
export declare const widgetsDevServer: () => Promise<Router>;
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
1
2
|
import path from "node:path";
|
|
2
3
|
import cors from "cors";
|
|
3
4
|
import express, {} from "express";
|
|
@@ -14,10 +15,17 @@ import express, {} from "express";
|
|
|
14
15
|
export const widgetsDevServer = async () => {
|
|
15
16
|
const router = express.Router();
|
|
16
17
|
const { createServer, searchForWorkspaceRoot, loadConfigFromFile } = await import("vite");
|
|
17
|
-
|
|
18
|
-
|
|
18
|
+
// Since 0.16.0, the template is a single package that does not rely on workspace.
|
|
19
|
+
// It means that, when starting the server, the working dir is the template root
|
|
20
|
+
// hence we don't need to walk up the tree to find the workspace, which does not exist anymore.
|
|
21
|
+
let webAppRoot = path.join(process.cwd(), "web");
|
|
22
|
+
// fallback to the old behavior for backward compatibility
|
|
23
|
+
const hasWebAppRoot = existsSync(webAppRoot);
|
|
24
|
+
if (!hasWebAppRoot) {
|
|
25
|
+
const workspaceRoot = searchForWorkspaceRoot(process.cwd());
|
|
26
|
+
webAppRoot = path.join(workspaceRoot, "web");
|
|
27
|
+
}
|
|
19
28
|
const configResult = await loadConfigFromFile({ command: "serve", mode: "development" }, path.join(webAppRoot, "vite.config.ts"), webAppRoot);
|
|
20
|
-
// biome-ignore lint/correctness/noUnusedVariables: Remove build-specific options that don't apply to dev server
|
|
21
29
|
const { build, preview, ...devConfig } = configResult?.config || {};
|
|
22
30
|
const vite = await createServer({
|
|
23
31
|
...devConfig,
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,IAAI,MAAM,WAAW,CAAC;AAC7B,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"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AM,EAAE;YACN,YAAY,EAAE,IAAI;YAClB,cAAc,EAAE,IAAI;SACrB;QACD,IAAI,EAAE,UAAU;QAChB,YAAY,EAAE;YACZ,OAAO,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"}
|
|
@@ -5,15 +5,12 @@ const mockManifest = {
|
|
|
5
5
|
"src/widgets/folder-widget/index.tsx": { file: "folder-widget.js" },
|
|
6
6
|
"style.css": { file: "style.css" },
|
|
7
7
|
};
|
|
8
|
-
vi.
|
|
9
|
-
|
|
8
|
+
const actual = vi.hoisted(() => require("node:fs"));
|
|
9
|
+
vi.mock("node:fs", () => {
|
|
10
10
|
const readFileSyncImpl = (path, ...args) => {
|
|
11
11
|
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
12
12
|
return JSON.stringify(mockManifest);
|
|
13
13
|
}
|
|
14
|
-
// Type assertion needed because readFileSync has overloads with different parameter types
|
|
15
|
-
// Using @ts-expect-error because the overloads are complex and we're forwarding args
|
|
16
|
-
// @ts-expect-error - readFileSync overloads require complex type handling
|
|
17
14
|
return actual.readFileSync(path, ...args);
|
|
18
15
|
};
|
|
19
16
|
const readFileSync = vi.fn(readFileSyncImpl);
|
|
@@ -56,11 +53,19 @@ describe("McpServer.registerWidget", () => {
|
|
|
56
53
|
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
57
54
|
mimeType: "text/html+skybridge",
|
|
58
55
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
56
|
+
_meta: {
|
|
57
|
+
"openai/widgetCSP": {
|
|
58
|
+
resource_domains: [serverUrl],
|
|
59
|
+
connect_domains: [serverUrl, "ws://localhost:3000"],
|
|
60
|
+
},
|
|
61
|
+
"openai/widgetDomain": serverUrl,
|
|
62
|
+
"openai/widgetDescription": "Test tool",
|
|
63
|
+
},
|
|
59
64
|
},
|
|
60
65
|
],
|
|
61
66
|
});
|
|
62
67
|
// Check development-specific content
|
|
63
|
-
expect(result.contents[0]?.text).toContain(`${serverUrl}/@react-refresh`);
|
|
68
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/@react-refresh`);
|
|
64
69
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/@vite/client`);
|
|
65
70
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/src/widgets/my-widget`);
|
|
66
71
|
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/src/widgets/my-widget.tsx`);
|
|
@@ -75,8 +80,9 @@ describe("McpServer.registerWidget", () => {
|
|
|
75
80
|
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
76
81
|
.calls[0]?.[3];
|
|
77
82
|
expect(appsSdkResourceCallback).toBeDefined();
|
|
78
|
-
const
|
|
79
|
-
const
|
|
83
|
+
const host = "myapp.com";
|
|
84
|
+
const serverUrl = `https://${host}`;
|
|
85
|
+
const mockExtra = createMockExtra(host);
|
|
80
86
|
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
|
|
81
87
|
expect(result).toEqual({
|
|
82
88
|
contents: [
|
|
@@ -84,11 +90,19 @@ describe("McpServer.registerWidget", () => {
|
|
|
84
90
|
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
85
91
|
mimeType: "text/html+skybridge",
|
|
86
92
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
93
|
+
_meta: {
|
|
94
|
+
"openai/widgetCSP": {
|
|
95
|
+
resource_domains: [serverUrl],
|
|
96
|
+
connect_domains: [serverUrl, `wss://${host}`],
|
|
97
|
+
},
|
|
98
|
+
"openai/widgetDomain": serverUrl,
|
|
99
|
+
"openai/widgetDescription": "Test tool",
|
|
100
|
+
},
|
|
87
101
|
},
|
|
88
102
|
],
|
|
89
103
|
});
|
|
90
104
|
// Check production-specific content
|
|
91
|
-
expect(result.contents[0]?.text).not.toContain(`${serverUrl}
|
|
105
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/assets/@react-refresh`);
|
|
92
106
|
expect(result.contents[0]?.text).not.toContain(`${serverUrl}@vite/client`);
|
|
93
107
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/my-widget.js`);
|
|
94
108
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/style.css`);
|
|
@@ -102,15 +116,19 @@ describe("McpServer.registerWidget", () => {
|
|
|
102
116
|
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
103
117
|
.calls[0]?.[3];
|
|
104
118
|
expect(appsSdkResourceCallback).toBeDefined();
|
|
105
|
-
const
|
|
106
|
-
const
|
|
119
|
+
const host = "myapp.com";
|
|
120
|
+
const serverUrl = `https://${host}`;
|
|
121
|
+
const mockExtra = createMockExtra(host);
|
|
107
122
|
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/folder-widget.html"), mockExtra);
|
|
108
123
|
// Should resolve to folder-widget.js from the manifest entry "src/widgets/folder-widget/index.tsx"
|
|
109
124
|
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/folder-widget.js`);
|
|
110
125
|
});
|
|
111
126
|
it("should register resources with correct hostType for both apps-sdk and ext-apps formats", async () => {
|
|
112
127
|
const mockToolCallback = vi.fn();
|
|
113
|
-
const mockRegisterResourceConfig = {
|
|
128
|
+
const mockRegisterResourceConfig = {
|
|
129
|
+
description: "Test widget",
|
|
130
|
+
_meta: { "openai/widgetPrefersBorder": true },
|
|
131
|
+
};
|
|
114
132
|
const mockToolConfig = { description: "Test tool" };
|
|
115
133
|
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
116
134
|
expect(mockRegisterResource).toHaveBeenCalledTimes(2);
|
|
@@ -123,6 +141,15 @@ describe("McpServer.registerWidget", () => {
|
|
|
123
141
|
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
124
142
|
mimeType: "text/html+skybridge",
|
|
125
143
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
144
|
+
_meta: {
|
|
145
|
+
"openai/widgetCSP": {
|
|
146
|
+
resource_domains: ["http://localhost:3000"],
|
|
147
|
+
connect_domains: ["http://localhost:3000", "ws://localhost:3000"],
|
|
148
|
+
},
|
|
149
|
+
"openai/widgetDomain": "http://localhost:3000",
|
|
150
|
+
"openai/widgetDescription": "Test tool",
|
|
151
|
+
"openai/widgetPrefersBorder": true,
|
|
152
|
+
},
|
|
126
153
|
},
|
|
127
154
|
],
|
|
128
155
|
});
|
|
@@ -137,10 +164,74 @@ describe("McpServer.registerWidget", () => {
|
|
|
137
164
|
uri: "ui://widgets/ext-apps/my-widget.html",
|
|
138
165
|
mimeType: "text/html;profile=mcp-app",
|
|
139
166
|
text: expect.stringContaining('<div id="root"></div>'),
|
|
167
|
+
_meta: {
|
|
168
|
+
ui: {
|
|
169
|
+
csp: {
|
|
170
|
+
resourceDomains: ["http://localhost:3000"],
|
|
171
|
+
connectDomains: [
|
|
172
|
+
"http://localhost:3000",
|
|
173
|
+
"ws://localhost:3000",
|
|
174
|
+
],
|
|
175
|
+
},
|
|
176
|
+
domain: "http://localhost:3000",
|
|
177
|
+
},
|
|
178
|
+
},
|
|
140
179
|
},
|
|
141
180
|
],
|
|
142
181
|
});
|
|
143
182
|
expect(extAppsResult.contents[0]?.text).toContain('window.skybridge = { hostType: "mcp-app" }');
|
|
144
183
|
});
|
|
184
|
+
it("should register tool with ui.resourceUri metadata (not deprecated ui/resourceUri)", async () => {
|
|
185
|
+
const mockToolCallback = vi.fn();
|
|
186
|
+
const mockRegisterResourceConfig = { description: "Test widget" };
|
|
187
|
+
const mockToolConfig = { description: "Test tool" };
|
|
188
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
189
|
+
expect(mockRegisterTool).toHaveBeenCalledTimes(1);
|
|
190
|
+
const toolCallArgs = mockRegisterTool.mock.calls[0];
|
|
191
|
+
const toolConfig = toolCallArgs?.[1];
|
|
192
|
+
expect(toolConfig._meta).toHaveProperty("ui");
|
|
193
|
+
expect(toolConfig._meta?.ui).toEqual({
|
|
194
|
+
resourceUri: "ui://widgets/ext-apps/my-widget.html",
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
it("should apply meta overrides in correct priority: defaults < ui.* < direct openai/* keys", async () => {
|
|
198
|
+
const mockToolCallback = vi.fn();
|
|
199
|
+
const mockRegisterResourceConfig = {
|
|
200
|
+
description: "Test widget",
|
|
201
|
+
_meta: {
|
|
202
|
+
// ui.csp overrides (middle priority)
|
|
203
|
+
ui: {
|
|
204
|
+
csp: {
|
|
205
|
+
resourceDomains: ["https://from-ui-csp.com"],
|
|
206
|
+
connectDomains: ["https://from-ui-csp.com"],
|
|
207
|
+
},
|
|
208
|
+
domain: "https://from-ui-domain.com",
|
|
209
|
+
prefersBorder: false,
|
|
210
|
+
},
|
|
211
|
+
// Direct openai/* keys (highest priority) - should override ui.*
|
|
212
|
+
"openai/widgetDomain": "https://direct-override.com",
|
|
213
|
+
"openai/widgetPrefersBorder": true,
|
|
214
|
+
},
|
|
215
|
+
};
|
|
216
|
+
const mockToolConfig = { description: "Test tool" };
|
|
217
|
+
server.registerWidget("override-test", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
218
|
+
const appsSdkCallback = mockRegisterResource.mock
|
|
219
|
+
.calls[0]?.[3];
|
|
220
|
+
const result = await appsSdkCallback(new URL("ui://widgets/apps-sdk/override-test.html"), createMockExtra("__not_used__"));
|
|
221
|
+
const meta = result.contents[0]?._meta;
|
|
222
|
+
// CSP arrays are merged by index - user value replaces at index 0, defaults remain at other indices
|
|
223
|
+
expect(meta["openai/widgetCSP"]).toEqual({
|
|
224
|
+
resource_domains: ["https://from-ui-csp.com"],
|
|
225
|
+
connect_domains: ["https://from-ui-csp.com", "ws://localhost:3000"],
|
|
226
|
+
frame_domains: undefined,
|
|
227
|
+
redirect_domains: undefined,
|
|
228
|
+
});
|
|
229
|
+
// Domain should be overridden by direct openai/* key (highest priority)
|
|
230
|
+
expect(meta["openai/widgetDomain"]).toBe("https://direct-override.com");
|
|
231
|
+
// PrefersBorder should be overridden by direct openai/* key (highest priority)
|
|
232
|
+
expect(meta["openai/widgetPrefersBorder"]).toBe(true);
|
|
233
|
+
// Description should be from defaults (toolConfig.description)
|
|
234
|
+
expect(meta["openai/widgetDescription"]).toBe("Test tool");
|
|
235
|
+
});
|
|
145
236
|
});
|
|
146
237
|
//# sourceMappingURL=widget.test.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG;IACnB,2BAA2B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;IACrD,qCAAqC,EAAE,EAAE,IAAI,EAAE,kBAAkB,EAAE;IACnE,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;CACnC,CAAC;AAEF,EAAE,CAAC,
|
|
1
|
+
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAKA,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EAEF,EAAE,GACH,MAAM,QAAQ,CAAC;AAEhB,OAAO,EACL,eAAe,EACf,mBAAmB,EACnB,YAAY,EACZ,UAAU,GACX,MAAM,YAAY,CAAC;AAEpB,MAAM,YAAY,GAAG;IACnB,2BAA2B,EAAE,EAAE,IAAI,EAAE,cAAc,EAAE;IACrD,qCAAqC,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AAM,CAAC,IAAI,CAAC,0BAA0B,CAAC,CAAC,CAAC,IAAI,CAAC,WAAW,CAAC,CAAC;IAC7D,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
|
|
2
|
+
export declare class AppsSdkAdaptor implements Adaptor {
|
|
3
|
+
private static instance;
|
|
4
|
+
static getInstance(): AppsSdkAdaptor;
|
|
5
|
+
static resetInstance(): void;
|
|
6
|
+
getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
|
|
7
|
+
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
8
|
+
requestDisplayMode: (mode: DisplayMode) => Promise<{
|
|
9
|
+
mode: DisplayMode;
|
|
10
|
+
}>;
|
|
11
|
+
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
12
|
+
openExternal(href: string): void;
|
|
13
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import { AppsSdkBridge } from "../apps-sdk-bridge.js";
|
|
2
|
+
export class AppsSdkAdaptor {
|
|
3
|
+
static instance = null;
|
|
4
|
+
static getInstance() {
|
|
5
|
+
if (!AppsSdkAdaptor.instance) {
|
|
6
|
+
AppsSdkAdaptor.instance = new AppsSdkAdaptor();
|
|
7
|
+
}
|
|
8
|
+
return AppsSdkAdaptor.instance;
|
|
9
|
+
}
|
|
10
|
+
static resetInstance() {
|
|
11
|
+
AppsSdkAdaptor.instance = null;
|
|
12
|
+
}
|
|
13
|
+
getExternalStore(key) {
|
|
14
|
+
const bridge = AppsSdkBridge.getInstance();
|
|
15
|
+
return {
|
|
16
|
+
subscribe: bridge.subscribe(key),
|
|
17
|
+
getSnapshot: () => bridge.getSnapshot(key),
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
callTool = async (name, args) => {
|
|
21
|
+
return window.openai.callTool(name, args);
|
|
22
|
+
};
|
|
23
|
+
requestDisplayMode = (mode) => {
|
|
24
|
+
return window.openai.requestDisplayMode({ mode });
|
|
25
|
+
};
|
|
26
|
+
sendFollowUpMessage = (prompt) => {
|
|
27
|
+
return window.openai.sendFollowUpMessage({ prompt });
|
|
28
|
+
};
|
|
29
|
+
openExternal(href) {
|
|
30
|
+
window.openai.openExternal({ href });
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=apps-sdk-adaptor.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"apps-sdk-adaptor.js","sourceRoot":"","sources":["../../../../../src/web/bridges/adaptors/apps-sdk-adaptor.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,MAAM,uBAAuB,CAAC;AAStD,MAAM,OAAO,cAAc;IACjB,MAAM,CAAC,QAAQ,GAA0B,IAAI,CAAC;IAE/C,MAAM,CAAC,WAAW;QACvB,IAAI,CAAC,cAAc,CAAC,QAAQ,EAAE,CAAC;YAC7B,cAAc,CAAC,QAAQ,GAAG,IAAI,cAAc,EAAE,CAAC;QACjD,CAAC;QACD,OAAO,cAAc,CAAC,QAAQ,CAAC;IACjC,CAAC;IAEM,MAAM,CAAC,aAAa;QACzB,cAAc,CAAC,QAAQ,GAAG,IAAI,CAAC;IACjC,CAAC;IAEM,gBAAgB,CACrB,GAAM;QAEN,MAAM,MAAM,GAAG,aAAa,CAAC,WAAW,EAAE,CAAC;QAC3C,OAAO;YACL,SAAS,EAAE,MAAM,CAAC,SAAS,CAAC,GAAG,CAAC;YAChC,WAAW,EAAE,GAAG,EAAE,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,CAAC;SAC3C,CAAC;IACJ,CAAC;IAEM,QAAQ,GAAG,KAAK,EAIrB,IAAY,EACZ,IAAc,EACS,EAAE;QACzB,OAAO,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAyB,IAAI,EAAE,IAAI,CAAC,CAAC;IACpE,CAAC,CAAC;IAEK,kBAAkB,GAAG,CAC1B,IAAiB,EACe,EAAE;QAClC,OAAO,MAAM,CAAC,MAAM,CAAC,kBAAkB,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACpD,CAAC,CAAC;IAEK,mBAAmB,GAAG,CAAC,MAAc,EAAiB,EAAE;QAC7D,OAAO,MAAM,CAAC,MAAM,CAAC,mBAAmB,CAAC,EAAE,MAAM,EAAE,CAAC,CAAC;IACvD,CAAC,CAAC;IAEK,YAAY,CAAC,IAAY;QAC9B,MAAM,CAAC,MAAM,CAAC,YAAY,CAAC,EAAE,IAAI,EAAE,CAAC,CAAC;IACvC,CAAC"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type { McpUiRequestDisplayModeResult } from "@modelcontextprotocol/ext-apps";
|
|
2
|
+
import type { Adaptor, BridgeInterface, CallToolResponse, DisplayMode, ExternalStore } from "../types.js";
|
|
3
|
+
export declare class McpAppAdaptor implements Adaptor {
|
|
4
|
+
private static instance;
|
|
5
|
+
private stores;
|
|
6
|
+
private constructor();
|
|
7
|
+
static getInstance(): McpAppAdaptor;
|
|
8
|
+
static resetInstance(): void;
|
|
9
|
+
getExternalStore<K extends keyof BridgeInterface>(key: K): ExternalStore<K>;
|
|
10
|
+
callTool: <ToolArgs extends Record<string, unknown> | null = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
|
|
11
|
+
requestDisplayMode: (mode: DisplayMode) => Promise<McpUiRequestDisplayModeResult>;
|
|
12
|
+
sendFollowUpMessage: (prompt: string) => Promise<void>;
|
|
13
|
+
openExternal(href: string): void;
|
|
14
|
+
private initializeStores;
|
|
15
|
+
private createExternalStore;
|
|
16
|
+
}
|