skybridge 0.0.0-dev.f1722d8 → 0.0.0-dev.f1c51a2
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/bin/run.js +9 -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/use-execute-steps.d.ts +10 -0
- package/dist/cli/use-execute-steps.js +31 -0
- package/dist/cli/use-execute-steps.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +44 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +7 -0
- package/dist/commands/dev.js +20 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +33 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/{src/server → server}/inferUtilityTypes.d.ts +10 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/server.d.ts +99 -0
- package/dist/server/server.js +138 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +3 -0
- package/dist/{src/server → server}/templateHelper.js +5 -4
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +66 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -0
- package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
- package/dist/{src/server → server}/widgetsDevServer.js +13 -5
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/{src/test → test}/utils.d.ts +54 -8
- package/dist/{src/test → test}/utils.js +86 -8
- package/dist/test/utils.js.map +1 -0
- package/dist/test/widget.test.js +255 -0
- package/dist/test/widget.test.js.map +1 -0
- package/dist/web/bridges/apps-sdk/adaptor.d.ts +14 -0
- package/dist/web/bridges/apps-sdk/adaptor.js +39 -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/{src/web → web/bridges/apps-sdk}/types.d.ts +28 -40
- package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -1
- 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 +19 -0
- package/dist/web/bridges/mcp-app/adaptor.js +145 -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 +255 -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.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 +74 -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/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.js +126 -0
- package/dist/web/create-store.test.js.map +1 -0
- package/dist/{src/web → web}/data-llm.d.ts +1 -0
- package/dist/{src/web → web}/data-llm.js +13 -8
- package/dist/web/data-llm.js.map +1 -0
- package/dist/web/data-llm.test.js +139 -0
- package/dist/web/data-llm.test.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.d.ts +11 -8
- package/dist/{src/web → web}/generate-helpers.js +5 -3
- package/dist/web/generate-helpers.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test-d.js +59 -3
- package/dist/web/generate-helpers.test-d.js.map +1 -0
- package/dist/{src/web → web}/generate-helpers.test.js +1 -1
- 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.js +53 -0
- package/dist/web/helpers/state.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/index.d.ts +3 -5
- package/dist/{src/web → web}/hooks/index.js +2 -4
- 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/{src/web → web}/hooks/use-call-tool.d.ts +3 -2
- package/dist/{src/web → web}/hooks/use-call-tool.js +12 -4
- package/dist/web/hooks/use-call-tool.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test-d.js +1 -1
- package/dist/web/hooks/use-call-tool.test-d.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-call-tool.test.js +35 -16
- package/dist/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.d.ts +1 -1
- package/dist/web/hooks/use-display-mode.js +9 -0
- package/dist/web/hooks/use-display-mode.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-display-mode.test.js +3 -2
- package/dist/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.d.ts +1 -1
- package/dist/web/hooks/use-files.js +7 -0
- package/dist/web/hooks/use-files.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-files.test.js +5 -5
- 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.js +96 -0
- package/dist/web/hooks/use-layout.test.js.map +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.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 +14 -0
- package/dist/web/hooks/use-request-modal.js.map +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.js +8 -0
- package/dist/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.d.ts +13 -2
- package/dist/web/hooks/use-tool-info.js +26 -0
- package/dist/web/hooks/use-tool-info.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-tool-info.test-d.js +40 -5
- package/dist/web/hooks/use-tool-info.test-d.js.map +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.js +94 -0
- package/dist/web/hooks/use-user.test.js.map +1 -0
- package/dist/web/hooks/use-widget-state.js +32 -0
- package/dist/web/hooks/use-widget-state.js.map +1 -0
- package/dist/{src/web → web}/hooks/use-widget-state.test.js +3 -2
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/{src/web → web}/index.d.ts +5 -4
- package/dist/{src/web → web}/index.js +5 -4
- package/dist/web/index.js.map +1 -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.map +1 -0
- package/dist/{src/web → web}/plugin/plugin.js +10 -4
- package/dist/web/plugin/plugin.js.map +1 -0
- package/dist/{src/web → web}/plugin/transform-data-llm.js +6 -3
- 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.map +1 -0
- package/dist/{src/web → web}/proxy.js +6 -1
- 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 +53 -32
- package/README.md +0 -371
- package/dist/src/server/index.d.ts +0 -4
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/inferUtilityTypes.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -48
- package/dist/src/server/server.js +0 -62
- package/dist/src/server/server.js.map +0 -1
- package/dist/src/server/templateHelper.js.map +0 -1
- package/dist/src/server/templates/development.hbs +0 -12
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -90
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/create-store.d.ts +0 -3
- package/dist/src/web/create-store.js +0 -103
- package/dist/src/web/create-store.js.map +0 -1
- package/dist/src/web/data-llm.js.map +0 -1
- package/dist/src/web/data-llm.test.js +0 -76
- package/dist/src/web/data-llm.test.js.map +0 -1
- package/dist/src/web/generate-helpers.js.map +0 -1
- package/dist/src/web/generate-helpers.test-d.js.map +0 -1
- package/dist/src/web/generate-helpers.test.js.map +0 -1
- package/dist/src/web/hooks/index.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-call-tool.test.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.js +0 -7
- package/dist/src/web/hooks/use-display-mode.js.map +0 -1
- package/dist/src/web/hooks/use-display-mode.test.js.map +0 -1
- package/dist/src/web/hooks/use-files.js +0 -7
- package/dist/src/web/hooks/use-files.js.map +0 -1
- package/dist/src/web/hooks/use-files.test.js.map +0 -1
- package/dist/src/web/hooks/use-locale.d.ts +0 -1
- package/dist/src/web/hooks/use-locale.js +0 -5
- package/dist/src/web/hooks/use-locale.js.map +0 -1
- package/dist/src/web/hooks/use-locale.test.js +0 -21
- package/dist/src/web/hooks/use-locale.test.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.js +0 -6
- package/dist/src/web/hooks/use-open-external.js.map +0 -1
- package/dist/src/web/hooks/use-open-external.test.js +0 -24
- package/dist/src/web/hooks/use-open-external.test.js.map +0 -1
- package/dist/src/web/hooks/use-openai-global.d.ts +0 -2
- package/dist/src/web/hooks/use-openai-global.js +0 -23
- package/dist/src/web/hooks/use-openai-global.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.d.ts +0 -6
- package/dist/src/web/hooks/use-request-modal.js +0 -9
- package/dist/src/web/hooks/use-request-modal.js.map +0 -1
- package/dist/src/web/hooks/use-request-modal.test.js +0 -24
- package/dist/src/web/hooks/use-request-modal.test.js.map +0 -1
- package/dist/src/web/hooks/use-send-follow-up-message.js +0 -11
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +0 -1
- package/dist/src/web/hooks/use-theme.d.ts +0 -1
- package/dist/src/web/hooks/use-theme.js +0 -5
- package/dist/src/web/hooks/use-theme.js.map +0 -1
- package/dist/src/web/hooks/use-theme.test.js +0 -26
- package/dist/src/web/hooks/use-theme.test.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.js +0 -22
- package/dist/src/web/hooks/use-tool-info.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test-d.js.map +0 -1
- package/dist/src/web/hooks/use-tool-info.test.js +0 -59
- package/dist/src/web/hooks/use-tool-info.test.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.d.ts +0 -1
- package/dist/src/web/hooks/use-user-agent.js +0 -5
- package/dist/src/web/hooks/use-user-agent.js.map +0 -1
- package/dist/src/web/hooks/use-user-agent.test.js +0 -31
- package/dist/src/web/hooks/use-user-agent.test.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.js +0 -54
- package/dist/src/web/hooks/use-widget-state.js.map +0 -1
- package/dist/src/web/hooks/use-widget-state.test.js.map +0 -1
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin/data-llm.test.js.map +0 -1
- package/dist/src/web/plugin/plugin.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.js.map +0 -1
- package/dist/src/web/plugin/transform-data-llm.test.js.map +0 -1
- package/dist/src/web/proxy.js.map +0 -1
- package/dist/src/web/types.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -8
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/server → server}/index.js +0 -0
- /package/dist/{src/server → server}/inferUtilityTypes.js +0 -0
- /package/dist/{src/test → test}/widget.test.d.ts +0 -0
- /package/dist/{src/web/data-llm.test.d.ts → web/bridges/mcp-app/use-mcp-app-context.test.d.ts} +0 -0
- /package/dist/{src/web/generate-helpers.test-d.d.ts → web/create-store.test.d.ts} +0 -0
- /package/dist/{src/web/plugin → web}/data-llm.test.d.ts +0 -0
- /package/dist/{src/web/generate-helpers.test.d.ts → web/generate-helpers.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test-d.d.ts → web/generate-helpers.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-call-tool.test.d.ts → web/helpers/state.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-display-mode.test.d.ts → web/hooks/use-call-tool.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-files.test.d.ts → web/hooks/use-call-tool.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-locale.test.d.ts → web/hooks/use-display-mode.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-open-external.test.d.ts → web/hooks/use-files.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-request-modal.test.d.ts → web/hooks/use-layout.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-open-external.d.ts +0 -0
- /package/dist/{src/web/hooks/use-theme.test.d.ts → web/hooks/use-open-external.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test-d.d.ts → web/hooks/use-request-modal.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-send-follow-up-message.d.ts +0 -0
- /package/dist/{src/web/hooks/use-tool-info.test.d.ts → web/hooks/use-tool-info.test-d.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-user-agent.test.d.ts → web/hooks/use-tool-info.test.d.ts} +0 -0
- /package/dist/{src/web/hooks/use-widget-state.test.d.ts → web/hooks/use-user.test.d.ts} +0 -0
- /package/dist/{src/web → web}/hooks/use-widget-state.d.ts +0 -0
- /package/dist/{src/web/plugin/transform-data-llm.test.d.ts → web/hooks/use-widget-state.test.d.ts} +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web}/mount-widget.js +0 -0
- /package/dist/{src/web → web}/plugin/data-llm.test.js +0 -0
- /package/dist/{src/web → web}/plugin/plugin.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.d.ts +0 -0
- /package/dist/{src/web → web}/plugin/transform-data-llm.test.js +0 -0
- /package/dist/{src/web → web}/proxy.d.ts +0 -0
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
<base href="{{serverUrl}}" />
|
|
2
|
+
<script type="module">window.skybridge = { hostType: "{{hostType}}" };</script>
|
|
3
|
+
<script type="module">
|
|
4
|
+
import { injectIntoGlobalHook } from "{{serverUrl}}/assets/@react-refresh";
|
|
5
|
+
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
6
|
+
window.$RefreshSig$ = () => (type) => type;
|
|
7
|
+
window.__vite_plugin_react_preamble_installed__ = true;
|
|
8
|
+
</script>
|
|
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>
|
|
63
|
+
<div id="root"></div>
|
|
64
|
+
<script type="module" id="dev-widget-entry">
|
|
65
|
+
import('{{serverUrl}}/src/widgets/{{widgetName}}');
|
|
66
|
+
</script>
|
|
@@ -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,6 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import cors from "cors";
|
|
1
|
+
import { existsSync } from "node:fs";
|
|
3
2
|
import path from "node:path";
|
|
3
|
+
import cors from "cors";
|
|
4
|
+
import express, {} from "express";
|
|
4
5
|
/**
|
|
5
6
|
* Install Vite dev server
|
|
6
7
|
* This router MUST be installed at the application root, like so:
|
|
@@ -14,10 +15,17 @@ import path from "node:path";
|
|
|
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
|
-
// 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,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
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,SAAS;QACZ,UAAU,EAAE,KAAK,EAAE,kFAAkF;QACrG,OAAO,EAAE,QAAQ;QACjB,MAAM,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,10 +5,10 @@ import { McpServer } from "../server/server.js";
|
|
|
5
5
|
*/
|
|
6
6
|
export declare function createMockMcpServer(): {
|
|
7
7
|
server: McpServer;
|
|
8
|
-
|
|
8
|
+
mockRegisterResource: MockInstance<McpServer["registerResource"]>;
|
|
9
9
|
mockRegisterTool: MockInstance<McpServer["registerTool"]>;
|
|
10
10
|
};
|
|
11
|
-
export declare function createTestServer(): McpServer<{
|
|
11
|
+
export declare function createTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
12
12
|
"search-voyage": import("../server/server.js").ToolDef<{
|
|
13
13
|
destination: string;
|
|
14
14
|
departureDate?: string | undefined;
|
|
@@ -20,7 +20,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
20
20
|
price: number;
|
|
21
21
|
}[];
|
|
22
22
|
totalCount: number;
|
|
23
|
-
}>;
|
|
23
|
+
}, unknown>;
|
|
24
24
|
} & {
|
|
25
25
|
"get-trip-details": import("../server/server.js").ToolDef<{
|
|
26
26
|
tripId: string;
|
|
@@ -28,9 +28,9 @@ export declare function createTestServer(): McpServer<{
|
|
|
28
28
|
name: string;
|
|
29
29
|
description: string;
|
|
30
30
|
images: string[];
|
|
31
|
-
}>;
|
|
31
|
+
}, unknown>;
|
|
32
32
|
} & {
|
|
33
|
-
"no-input-widget": import("../server/server.js").ToolDef<{}, {}>;
|
|
33
|
+
"no-input-widget": import("../server/server.js").ToolDef<{}, {}, unknown>;
|
|
34
34
|
} & {
|
|
35
35
|
"inferred-output-widget": import("../server/server.js").ToolDef<{
|
|
36
36
|
query: string;
|
|
@@ -40,7 +40,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
40
40
|
score: number;
|
|
41
41
|
}[];
|
|
42
42
|
inferredCount: number;
|
|
43
|
-
}>;
|
|
43
|
+
}, unknown>;
|
|
44
44
|
} & {
|
|
45
45
|
"calculate-price": import("../server/server.js").ToolDef<{
|
|
46
46
|
tripId: string;
|
|
@@ -48,7 +48,7 @@ export declare function createTestServer(): McpServer<{
|
|
|
48
48
|
}, {
|
|
49
49
|
totalPrice: number;
|
|
50
50
|
currency: string;
|
|
51
|
-
}>;
|
|
51
|
+
}, unknown>;
|
|
52
52
|
} & {
|
|
53
53
|
"inferred-tool": import("../server/server.js").ToolDef<{
|
|
54
54
|
itemId: string;
|
|
@@ -58,15 +58,61 @@ export declare function createTestServer(): McpServer<{
|
|
|
58
58
|
available: boolean;
|
|
59
59
|
};
|
|
60
60
|
fetchedAt: string;
|
|
61
|
+
}, unknown>;
|
|
62
|
+
} & {
|
|
63
|
+
"widget-with-metadata": import("../server/server.js").ToolDef<{
|
|
64
|
+
resourceId: string;
|
|
65
|
+
}, {
|
|
66
|
+
data: {
|
|
67
|
+
id: string;
|
|
68
|
+
loaded: boolean;
|
|
69
|
+
};
|
|
70
|
+
}, {
|
|
71
|
+
requestId: string;
|
|
72
|
+
timestamp: number;
|
|
73
|
+
cached: boolean;
|
|
74
|
+
}>;
|
|
75
|
+
} & {
|
|
76
|
+
"tool-with-metadata": import("../server/server.js").ToolDef<{
|
|
77
|
+
query: string;
|
|
78
|
+
}, {
|
|
79
|
+
results: string[];
|
|
80
|
+
}, {
|
|
81
|
+
executionTime: number;
|
|
82
|
+
source: string;
|
|
83
|
+
}>;
|
|
84
|
+
} & {
|
|
85
|
+
"widget-with-mixed-returns": import("../server/server.js").ToolDef<{
|
|
86
|
+
shouldSucceed: boolean;
|
|
87
|
+
}, {
|
|
88
|
+
error: string;
|
|
89
|
+
data?: undefined;
|
|
90
|
+
} | {
|
|
91
|
+
data: string;
|
|
92
|
+
error?: undefined;
|
|
93
|
+
}, {
|
|
94
|
+
processedAt: number;
|
|
95
|
+
region: string;
|
|
61
96
|
}>;
|
|
62
97
|
}>;
|
|
63
|
-
export declare function createMinimalTestServer(): McpServer<{
|
|
98
|
+
export declare function createMinimalTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
64
99
|
"search-voyage": import("../server/server.js").ToolDef<{
|
|
65
100
|
destination: string;
|
|
66
101
|
}, {
|
|
67
102
|
results: {
|
|
68
103
|
id: string;
|
|
69
104
|
}[];
|
|
105
|
+
}, unknown>;
|
|
106
|
+
}>;
|
|
107
|
+
export declare function createInterfaceTestServer(): McpServer<Record<never, import("../server/server.js").ToolDef<unknown, unknown, unknown>> & {
|
|
108
|
+
"interface-widget": import("../server/server.js").ToolDef<{
|
|
109
|
+
id: string;
|
|
110
|
+
}, {
|
|
111
|
+
itemName: string;
|
|
112
|
+
quantity: number;
|
|
113
|
+
}, {
|
|
114
|
+
processedBy: string;
|
|
115
|
+
version: number;
|
|
70
116
|
}>;
|
|
71
117
|
}>;
|
|
72
118
|
/**
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { vi } from "vitest";
|
|
2
|
+
import * as z from "zod";
|
|
2
3
|
import { McpServer } from "../server/server.js";
|
|
3
|
-
import { z } from "zod";
|
|
4
4
|
/**
|
|
5
5
|
* Creates a real McpServer instance for testing
|
|
6
6
|
*/
|
|
@@ -11,17 +11,17 @@ export function createMockMcpServer() {
|
|
|
11
11
|
version: "0.0.1",
|
|
12
12
|
}, { capabilities: {} });
|
|
13
13
|
// Mock the underlying methods to track calls
|
|
14
|
-
const
|
|
14
|
+
const mockRegisterResource = vi.spyOn(server, "registerResource");
|
|
15
15
|
const mockRegisterTool = vi.spyOn(server, "registerTool");
|
|
16
16
|
return {
|
|
17
17
|
server,
|
|
18
|
-
|
|
18
|
+
mockRegisterResource,
|
|
19
19
|
mockRegisterTool,
|
|
20
20
|
};
|
|
21
21
|
}
|
|
22
22
|
export function createTestServer() {
|
|
23
23
|
return new McpServer({ name: "test-app", version: "1.0.0" }, {})
|
|
24
|
-
.
|
|
24
|
+
.registerWidget("search-voyage", {}, {
|
|
25
25
|
description: "Search for voyages",
|
|
26
26
|
inputSchema: {
|
|
27
27
|
destination: z.string(),
|
|
@@ -45,7 +45,7 @@ export function createTestServer() {
|
|
|
45
45
|
},
|
|
46
46
|
};
|
|
47
47
|
})
|
|
48
|
-
.
|
|
48
|
+
.registerWidget("get-trip-details", {}, {
|
|
49
49
|
description: "Get trip details",
|
|
50
50
|
inputSchema: {
|
|
51
51
|
tripId: z.string(),
|
|
@@ -65,7 +65,7 @@ export function createTestServer() {
|
|
|
65
65
|
},
|
|
66
66
|
};
|
|
67
67
|
})
|
|
68
|
-
.
|
|
68
|
+
.registerWidget("no-input-widget", {}, {
|
|
69
69
|
description: "Widget with no input",
|
|
70
70
|
inputSchema: {},
|
|
71
71
|
outputSchema: {},
|
|
@@ -75,7 +75,7 @@ export function createTestServer() {
|
|
|
75
75
|
structuredContent: {},
|
|
76
76
|
};
|
|
77
77
|
})
|
|
78
|
-
.
|
|
78
|
+
.registerWidget("inferred-output-widget", {}, {
|
|
79
79
|
description: "Widget with output inferred from callback",
|
|
80
80
|
inputSchema: {
|
|
81
81
|
query: z.string(),
|
|
@@ -121,10 +121,68 @@ export function createTestServer() {
|
|
|
121
121
|
fetchedAt: "2024-01-01",
|
|
122
122
|
},
|
|
123
123
|
};
|
|
124
|
+
})
|
|
125
|
+
.registerWidget("widget-with-metadata", {}, {
|
|
126
|
+
description: "Widget that returns response metadata",
|
|
127
|
+
inputSchema: {
|
|
128
|
+
resourceId: z.string(),
|
|
129
|
+
},
|
|
130
|
+
}, async ({ resourceId }) => {
|
|
131
|
+
return {
|
|
132
|
+
content: [{ type: "text", text: `Resource: ${resourceId}` }],
|
|
133
|
+
structuredContent: {
|
|
134
|
+
data: { id: resourceId, loaded: true },
|
|
135
|
+
},
|
|
136
|
+
_meta: {
|
|
137
|
+
requestId: "req-123",
|
|
138
|
+
timestamp: 1704067200000,
|
|
139
|
+
cached: false,
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
})
|
|
143
|
+
.registerTool("tool-with-metadata", {
|
|
144
|
+
description: "Tool that returns response metadata",
|
|
145
|
+
inputSchema: {
|
|
146
|
+
query: z.string(),
|
|
147
|
+
},
|
|
148
|
+
}, async ({ query }) => {
|
|
149
|
+
return {
|
|
150
|
+
content: [{ type: "text", text: `Query: ${query}` }],
|
|
151
|
+
structuredContent: {
|
|
152
|
+
results: [query],
|
|
153
|
+
},
|
|
154
|
+
_meta: {
|
|
155
|
+
executionTime: 150,
|
|
156
|
+
source: "cache",
|
|
157
|
+
},
|
|
158
|
+
};
|
|
159
|
+
})
|
|
160
|
+
.registerWidget("widget-with-mixed-returns", {}, {
|
|
161
|
+
description: "Widget with mixed return paths (some with _meta, some without)",
|
|
162
|
+
inputSchema: {
|
|
163
|
+
shouldSucceed: z.boolean(),
|
|
164
|
+
},
|
|
165
|
+
}, async ({ shouldSucceed }) => {
|
|
166
|
+
if (!shouldSucceed) {
|
|
167
|
+
// Error path - no _meta
|
|
168
|
+
return {
|
|
169
|
+
content: [{ type: "text", text: "Error occurred" }],
|
|
170
|
+
structuredContent: { error: "Something went wrong" },
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
// Success path - has _meta
|
|
174
|
+
return {
|
|
175
|
+
content: [{ type: "text", text: "Success" }],
|
|
176
|
+
structuredContent: { data: "result" },
|
|
177
|
+
_meta: {
|
|
178
|
+
processedAt: 1704067200000,
|
|
179
|
+
region: "eu-west-1",
|
|
180
|
+
},
|
|
181
|
+
};
|
|
124
182
|
});
|
|
125
183
|
}
|
|
126
184
|
export function createMinimalTestServer() {
|
|
127
|
-
return new McpServer({ name: "test-app", version: "1.0.0" }, {}).
|
|
185
|
+
return new McpServer({ name: "test-app", version: "1.0.0" }, {}).registerWidget("search-voyage", {}, {
|
|
128
186
|
description: "Search for voyages",
|
|
129
187
|
inputSchema: {
|
|
130
188
|
destination: z.string(),
|
|
@@ -139,6 +197,26 @@ export function createMinimalTestServer() {
|
|
|
139
197
|
};
|
|
140
198
|
});
|
|
141
199
|
}
|
|
200
|
+
export function createInterfaceTestServer() {
|
|
201
|
+
return new McpServer({ name: "interface-test-app", version: "1.0.0" }, {}).registerWidget("interface-widget", {}, {
|
|
202
|
+
description: "Widget with interface-typed output",
|
|
203
|
+
inputSchema: {
|
|
204
|
+
id: z.string(),
|
|
205
|
+
},
|
|
206
|
+
}, async ({ id }) => {
|
|
207
|
+
return {
|
|
208
|
+
content: [{ type: "text", text: `Item ${id}` }],
|
|
209
|
+
structuredContent: {
|
|
210
|
+
itemName: "Test Item",
|
|
211
|
+
quantity: 42,
|
|
212
|
+
},
|
|
213
|
+
_meta: {
|
|
214
|
+
processedBy: "test",
|
|
215
|
+
version: 1,
|
|
216
|
+
},
|
|
217
|
+
};
|
|
218
|
+
});
|
|
219
|
+
}
|
|
142
220
|
/**
|
|
143
221
|
* Mock extra parameter for resource callback
|
|
144
222
|
*/
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../src/test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAqB,EAAE,EAAE,MAAM,QAAQ,CAAC;AAC/C,OAAO,KAAK,CAAC,MAAM,KAAK,CAAC;AACzB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAEhD;;GAEG;AACH,MAAM,UAAU,mBAAmB;IAKjC,mCAAmC;IACnC,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,kBAAkB;QACxB,OAA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,CACH,CAAC,cAAc,CAKd,kBAAkB,EAClB,EAAE,EACF;QACE,WAAW,EAAE,oCAAoC;QACjD,WAAW,EAAE;YACX,EAAE,EAAE,CAAC,CAAC,MAAM,EAAE;SACf;KACF,EACD,KAAK,EAAE,EAAE,EAAE,EAAE,EAAgC,EAAE;QAC7C,OAAO;YACL,OAAO,EAAE,CAAC,EAAE,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,QAAQ,EAAE,EAAE,EAAE,CAAC;YAC/C,iBAAiB,EAAE;gBACjB,QAAQ,EAAE,WAAW;gBACrB,QAAQ,EAAE,EAAE;aACb;YACD,KAAK,EAAE;gBACL,WAAW,EAAE,MAAM;gBACnB,OAAO,EAAE,CAAC;aACX;SACF,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO;QACL,WAAW,EAAE;YACX,OAAO,EAAE,EAAE,IAAI,EAAE;SAClB;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAA2B;IACpD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC9B,CAAC"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
2
|
+
import { createMockExtra, createMockMcpServer, resetTestEnv, setTestEnv, } from "./utils.js";
|
|
3
|
+
const mockManifest = {
|
|
4
|
+
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
5
|
+
"src/widgets/folder-widget/index.tsx": { file: "folder-widget.js" },
|
|
6
|
+
"style.css": { file: "style.css" },
|
|
7
|
+
};
|
|
8
|
+
const actual = vi.hoisted(() => require("node:fs"));
|
|
9
|
+
vi.mock("node:fs", () => {
|
|
10
|
+
const readFileSyncImpl = (path, ...args) => {
|
|
11
|
+
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
12
|
+
return JSON.stringify(mockManifest);
|
|
13
|
+
}
|
|
14
|
+
return actual.readFileSync(path, ...args);
|
|
15
|
+
};
|
|
16
|
+
const readFileSync = vi.fn(readFileSyncImpl);
|
|
17
|
+
return {
|
|
18
|
+
readFileSync,
|
|
19
|
+
default: {
|
|
20
|
+
readFileSync,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
24
|
+
describe("McpServer.registerWidget", () => {
|
|
25
|
+
let server;
|
|
26
|
+
let mockRegisterResource;
|
|
27
|
+
let mockRegisterTool;
|
|
28
|
+
beforeEach(() => {
|
|
29
|
+
({ server, mockRegisterResource, mockRegisterTool } =
|
|
30
|
+
createMockMcpServer());
|
|
31
|
+
});
|
|
32
|
+
afterEach(() => {
|
|
33
|
+
vi.clearAllMocks();
|
|
34
|
+
resetTestEnv();
|
|
35
|
+
});
|
|
36
|
+
it("should generate correct HTML for development mode", async () => {
|
|
37
|
+
setTestEnv({ NODE_ENV: "development" });
|
|
38
|
+
const mockToolCallback = vi.fn();
|
|
39
|
+
const mockRegisterResourceConfig = { description: "Test widget" };
|
|
40
|
+
const mockToolConfig = { description: "Test tool" };
|
|
41
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
42
|
+
// Get the resource callback function
|
|
43
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
44
|
+
.calls[0]?.[3];
|
|
45
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
46
|
+
const serverUrl = "http://localhost:3000";
|
|
47
|
+
const mockExtra = createMockExtra("__not_used__");
|
|
48
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
|
|
49
|
+
expect(mockRegisterTool).toHaveBeenCalled();
|
|
50
|
+
expect(result).toEqual({
|
|
51
|
+
contents: [
|
|
52
|
+
{
|
|
53
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
54
|
+
mimeType: "text/html+skybridge",
|
|
55
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
56
|
+
_meta: {
|
|
57
|
+
"openai/widgetCSP": {
|
|
58
|
+
resource_domains: [serverUrl],
|
|
59
|
+
connect_domains: ["ws://localhost:24678"],
|
|
60
|
+
},
|
|
61
|
+
"openai/widgetDomain": serverUrl,
|
|
62
|
+
"openai/widgetDescription": "Test tool",
|
|
63
|
+
},
|
|
64
|
+
},
|
|
65
|
+
],
|
|
66
|
+
});
|
|
67
|
+
// Check development-specific content
|
|
68
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/@react-refresh`);
|
|
69
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/@vite/client`);
|
|
70
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/src/widgets/my-widget`);
|
|
71
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/src/widgets/my-widget.tsx`);
|
|
72
|
+
});
|
|
73
|
+
it("should generate correct HTML for production mode", async () => {
|
|
74
|
+
setTestEnv({ NODE_ENV: "production" });
|
|
75
|
+
const mockToolCallback = vi.fn();
|
|
76
|
+
const mockRegisterResourceConfig = { description: "Test widget" };
|
|
77
|
+
const mockToolConfig = { description: "Test tool" };
|
|
78
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
79
|
+
// Get the resource callback function
|
|
80
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
81
|
+
.calls[0]?.[3];
|
|
82
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
83
|
+
const host = "myapp.com";
|
|
84
|
+
const serverUrl = `https://${host}`;
|
|
85
|
+
const mockExtra = createMockExtra(host);
|
|
86
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), mockExtra);
|
|
87
|
+
expect(result).toEqual({
|
|
88
|
+
contents: [
|
|
89
|
+
{
|
|
90
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
91
|
+
mimeType: "text/html+skybridge",
|
|
92
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
93
|
+
_meta: {
|
|
94
|
+
"openai/widgetCSP": {
|
|
95
|
+
resource_domains: [serverUrl],
|
|
96
|
+
connect_domains: [],
|
|
97
|
+
},
|
|
98
|
+
"openai/widgetDomain": serverUrl,
|
|
99
|
+
"openai/widgetDescription": "Test tool",
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
],
|
|
103
|
+
});
|
|
104
|
+
// Check production-specific content
|
|
105
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}/assets/@react-refresh`);
|
|
106
|
+
expect(result.contents[0]?.text).not.toContain(`${serverUrl}@vite/client`);
|
|
107
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/my-widget.js`);
|
|
108
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/style.css`);
|
|
109
|
+
});
|
|
110
|
+
it("should resolve folder-based widgets (barrel files) in production mode", async () => {
|
|
111
|
+
setTestEnv({ NODE_ENV: "production" });
|
|
112
|
+
const mockToolCallback = vi.fn();
|
|
113
|
+
const mockRegisterResourceConfig = { description: "Folder widget" };
|
|
114
|
+
const mockToolConfig = { description: "Folder tool" };
|
|
115
|
+
server.registerWidget("folder-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
116
|
+
const appsSdkResourceCallback = mockRegisterResource.mock
|
|
117
|
+
.calls[0]?.[3];
|
|
118
|
+
expect(appsSdkResourceCallback).toBeDefined();
|
|
119
|
+
const host = "myapp.com";
|
|
120
|
+
const serverUrl = `https://${host}`;
|
|
121
|
+
const mockExtra = createMockExtra(host);
|
|
122
|
+
const result = await appsSdkResourceCallback(new URL("ui://widgets/apps-sdk/folder-widget.html"), mockExtra);
|
|
123
|
+
// Should resolve to folder-widget.js from the manifest entry "src/widgets/folder-widget/index.tsx"
|
|
124
|
+
expect(result.contents[0]?.text).toContain(`${serverUrl}/assets/folder-widget.js`);
|
|
125
|
+
});
|
|
126
|
+
it("should register resources with correct hostType for both apps-sdk and ext-apps formats", async () => {
|
|
127
|
+
const mockToolCallback = vi.fn();
|
|
128
|
+
const mockRegisterResourceConfig = {
|
|
129
|
+
description: "Test widget",
|
|
130
|
+
_meta: { "openai/widgetPrefersBorder": true },
|
|
131
|
+
};
|
|
132
|
+
const mockToolConfig = { description: "Test tool" };
|
|
133
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
134
|
+
expect(mockRegisterResource).toHaveBeenCalledTimes(2);
|
|
135
|
+
const appsSdkCallback = mockRegisterResource.mock
|
|
136
|
+
.calls[0]?.[3];
|
|
137
|
+
const appsSdkResult = await appsSdkCallback(new URL("ui://widgets/apps-sdk/my-widget.html"), createMockExtra("__not_used__"));
|
|
138
|
+
expect(appsSdkResult).toEqual({
|
|
139
|
+
contents: [
|
|
140
|
+
{
|
|
141
|
+
uri: "ui://widgets/apps-sdk/my-widget.html",
|
|
142
|
+
mimeType: "text/html+skybridge",
|
|
143
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
144
|
+
_meta: {
|
|
145
|
+
"openai/widgetCSP": {
|
|
146
|
+
resource_domains: ["http://localhost:3000"],
|
|
147
|
+
connect_domains: ["ws://localhost:24678"],
|
|
148
|
+
},
|
|
149
|
+
"openai/widgetDomain": "http://localhost:3000",
|
|
150
|
+
"openai/widgetDescription": "Test tool",
|
|
151
|
+
"openai/widgetPrefersBorder": true,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
],
|
|
155
|
+
});
|
|
156
|
+
expect(appsSdkResult.contents[0]?.text).toContain('window.skybridge = { hostType: "apps-sdk" }');
|
|
157
|
+
const extAppsResourceCallback = mockRegisterResource.mock
|
|
158
|
+
.calls[1]?.[3];
|
|
159
|
+
expect(extAppsResourceCallback).toBeDefined();
|
|
160
|
+
const extAppsResult = await extAppsResourceCallback(new URL("ui://widgets/ext-apps/my-widget.html"), createMockExtra("__not_used__"));
|
|
161
|
+
expect(extAppsResult).toEqual({
|
|
162
|
+
contents: [
|
|
163
|
+
{
|
|
164
|
+
uri: "ui://widgets/ext-apps/my-widget.html",
|
|
165
|
+
mimeType: "text/html;profile=mcp-app",
|
|
166
|
+
text: expect.stringContaining('<div id="root"></div>'),
|
|
167
|
+
_meta: {
|
|
168
|
+
ui: {
|
|
169
|
+
csp: {
|
|
170
|
+
resourceDomains: ["http://localhost:3000"],
|
|
171
|
+
connectDomains: ["ws://localhost:24678"],
|
|
172
|
+
},
|
|
173
|
+
domain: "http://localhost:3000",
|
|
174
|
+
},
|
|
175
|
+
},
|
|
176
|
+
},
|
|
177
|
+
],
|
|
178
|
+
});
|
|
179
|
+
expect(extAppsResult.contents[0]?.text).toContain('window.skybridge = { hostType: "mcp-app" }');
|
|
180
|
+
});
|
|
181
|
+
it("should register tool with ui.resourceUri metadata (not deprecated ui/resourceUri)", async () => {
|
|
182
|
+
const mockToolCallback = vi.fn();
|
|
183
|
+
const mockRegisterResourceConfig = { description: "Test widget" };
|
|
184
|
+
const mockToolConfig = { description: "Test tool" };
|
|
185
|
+
server.registerWidget("my-widget", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
186
|
+
expect(mockRegisterTool).toHaveBeenCalledTimes(1);
|
|
187
|
+
const toolCallArgs = mockRegisterTool.mock.calls[0];
|
|
188
|
+
const toolConfig = toolCallArgs?.[1];
|
|
189
|
+
expect(toolConfig._meta).toHaveProperty("ui");
|
|
190
|
+
expect(toolConfig._meta?.ui).toEqual({
|
|
191
|
+
resourceUri: "ui://widgets/ext-apps/my-widget.html",
|
|
192
|
+
});
|
|
193
|
+
});
|
|
194
|
+
it("should apply meta overrides in correct priority: defaults < ui.* < direct openai/* keys", async () => {
|
|
195
|
+
const mockToolCallback = vi.fn();
|
|
196
|
+
const mockRegisterResourceConfig = {
|
|
197
|
+
description: "Test widget",
|
|
198
|
+
_meta: {
|
|
199
|
+
// ui.csp overrides (middle priority)
|
|
200
|
+
ui: {
|
|
201
|
+
csp: {
|
|
202
|
+
resourceDomains: ["https://from-ui-csp.com"],
|
|
203
|
+
connectDomains: ["https://from-ui-csp.com"],
|
|
204
|
+
},
|
|
205
|
+
domain: "https://from-ui-domain.com",
|
|
206
|
+
prefersBorder: false,
|
|
207
|
+
},
|
|
208
|
+
// Direct openai/* keys (highest priority) - should override ui.*
|
|
209
|
+
"openai/widgetDomain": "https://direct-override.com",
|
|
210
|
+
"openai/widgetPrefersBorder": true,
|
|
211
|
+
},
|
|
212
|
+
};
|
|
213
|
+
const mockToolConfig = { description: "Test tool" };
|
|
214
|
+
server.registerWidget("override-test", mockRegisterResourceConfig, mockToolConfig, mockToolCallback);
|
|
215
|
+
const appsSdkCallback = mockRegisterResource.mock
|
|
216
|
+
.calls[0]?.[3];
|
|
217
|
+
const result = await appsSdkCallback(new URL("ui://widgets/apps-sdk/override-test.html"), createMockExtra("__not_used__"));
|
|
218
|
+
const meta = result.contents[0]?._meta;
|
|
219
|
+
// CSP arrays are merged with union - all unique domains from defaults and user config are preserved
|
|
220
|
+
expect(meta["openai/widgetCSP"]).toEqual({
|
|
221
|
+
resource_domains: ["http://localhost:3000", "https://from-ui-csp.com"],
|
|
222
|
+
connect_domains: ["ws://localhost:24678", "https://from-ui-csp.com"],
|
|
223
|
+
frame_domains: undefined,
|
|
224
|
+
redirect_domains: undefined,
|
|
225
|
+
});
|
|
226
|
+
// Domain should be overridden by direct openai/* key (highest priority)
|
|
227
|
+
expect(meta["openai/widgetDomain"]).toBe("https://direct-override.com");
|
|
228
|
+
// PrefersBorder should be overridden by direct openai/* key (highest priority)
|
|
229
|
+
expect(meta["openai/widgetPrefersBorder"]).toBe(true);
|
|
230
|
+
// Description should be from defaults (toolConfig.description)
|
|
231
|
+
expect(meta["openai/widgetDescription"]).toBe("Test tool");
|
|
232
|
+
});
|
|
233
|
+
it("should register tool with ui.resourceUri metadata only", async () => {
|
|
234
|
+
const mockToolCallback = vi.fn();
|
|
235
|
+
server.registerWidget("my-widget", { description: "Test widget", hosts: ["mcp-app"] }, { description: "Test tool" }, mockToolCallback);
|
|
236
|
+
expect(mockRegisterTool).toHaveBeenCalledTimes(1);
|
|
237
|
+
const toolCallArgs = mockRegisterTool.mock.calls[0];
|
|
238
|
+
const toolConfig = toolCallArgs?.[1];
|
|
239
|
+
expect(toolConfig._meta).toHaveProperty("ui");
|
|
240
|
+
expect(toolConfig._meta?.ui).toEqual({
|
|
241
|
+
resourceUri: "ui://widgets/ext-apps/my-widget.html",
|
|
242
|
+
});
|
|
243
|
+
expect(toolConfig._meta?.["openai/outputTemplate"]).to.be.undefined;
|
|
244
|
+
});
|
|
245
|
+
it("should register tool with uopenai/outputTemplate metadata only", async () => {
|
|
246
|
+
const mockToolCallback = vi.fn();
|
|
247
|
+
server.registerWidget("my-widget", { description: "Test widget", hosts: ["apps-sdk"] }, { description: "Test tool" }, mockToolCallback);
|
|
248
|
+
expect(mockRegisterTool).toHaveBeenCalledTimes(1);
|
|
249
|
+
const toolCallArgs = mockRegisterTool.mock.calls[0];
|
|
250
|
+
const toolConfig = toolCallArgs?.[1];
|
|
251
|
+
expect(toolConfig._meta).not.toHaveProperty("ui");
|
|
252
|
+
expect(toolConfig._meta?.["openai/outputTemplate"]).to.eq("ui://widgets/apps-sdk/my-widget.html");
|
|
253
|
+
});
|
|
254
|
+
});
|
|
255
|
+
//# sourceMappingURL=widget.test.js.map
|