skybridge 0.0.0-dev.feb36b5 → 0.0.0-dev.ff3ca79
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 +95 -76
- package/bin/run.js +5 -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 +61 -0
- package/dist/cli/use-nodemon.js.map +1 -0
- package/dist/cli/use-typescript-check.d.ts +8 -0
- package/dist/cli/use-typescript-check.js +59 -0
- package/dist/cli/use-typescript-check.js.map +1 -0
- package/dist/commands/build.d.ts +9 -0
- package/dist/commands/build.js +46 -0
- package/dist/commands/build.js.map +1 -0
- package/dist/commands/dev.d.ts +9 -0
- package/dist/commands/dev.js +31 -0
- package/dist/commands/dev.js.map +1 -0
- package/dist/commands/start.d.ts +7 -0
- package/dist/commands/start.js +28 -0
- package/dist/commands/start.js.map +1 -0
- package/dist/commands/telemetry/disable.d.ts +5 -0
- package/dist/commands/telemetry/disable.js +14 -0
- package/dist/commands/telemetry/disable.js.map +1 -0
- package/dist/commands/telemetry/enable.d.ts +5 -0
- package/dist/commands/telemetry/enable.js +14 -0
- package/dist/commands/telemetry/enable.js.map +1 -0
- package/dist/commands/telemetry/status.d.ts +5 -0
- package/dist/commands/telemetry/status.js +14 -0
- package/dist/commands/telemetry/status.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.d.ts +11 -0
- package/dist/server/asset-base-url-transform-plugin.js +34 -0
- package/dist/server/asset-base-url-transform-plugin.js.map +1 -0
- package/dist/server/asset-base-url-transform-plugin.test.js +56 -0
- package/dist/server/asset-base-url-transform-plugin.test.js.map +1 -0
- package/dist/server/express.d.ts +5 -0
- package/dist/server/express.js +63 -0
- package/dist/server/express.js.map +1 -0
- package/dist/server/index.d.ts +4 -0
- package/dist/server/index.js.map +1 -0
- package/dist/server/inferUtilityTypes.d.ts +64 -0
- package/dist/server/inferUtilityTypes.js +2 -0
- package/dist/server/inferUtilityTypes.js.map +1 -0
- package/dist/server/server.d.ts +109 -0
- package/dist/server/server.js +201 -0
- package/dist/server/server.js.map +1 -0
- package/dist/{src/server → server}/templateHelper.d.ts +4 -0
- package/dist/{src/server → server}/templateHelper.js +5 -4
- package/dist/server/templateHelper.js.map +1 -0
- package/dist/server/templates/development.hbs +67 -0
- package/dist/{src/server → server}/templates/production.hbs +1 -1
- package/dist/{src/server → server}/widgetsDevServer.d.ts +2 -2
- package/dist/server/widgetsDevServer.js +57 -0
- package/dist/server/widgetsDevServer.js.map +1 -0
- package/dist/test/utils.d.ts +355 -0
- package/dist/test/utils.js +242 -0
- package/dist/test/utils.js.map +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 +64 -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 +115 -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 +188 -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.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 +139 -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 +30 -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 +49 -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 +61 -0
- package/dist/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/web/index.d.ts +8 -0
- package/dist/web/index.js +9 -0
- package/dist/web/index.js.map +1 -0
- package/dist/web/mount-widget.js +27 -0
- package/dist/web/mount-widget.js.map +1 -0
- package/dist/web/plugin/data-llm.test.d.ts +1 -0
- package/dist/web/plugin/data-llm.test.js +81 -0
- package/dist/web/plugin/data-llm.test.js.map +1 -0
- package/dist/web/plugin/plugin.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 +16 -0
- package/dist/web/types.js +2 -0
- package/dist/web/types.js.map +1 -0
- package/package.json +66 -27
- package/dist/src/server/index.d.ts +0 -2
- package/dist/src/server/index.js.map +0 -1
- package/dist/src/server/server.d.ts +0 -13
- package/dist/src/server/server.js +0 -54
- 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 +0 -39
- package/dist/src/server/widgetsDevServer.js.map +0 -1
- package/dist/src/test/setup.js +0 -9
- package/dist/src/test/setup.js.map +0 -1
- package/dist/src/test/utils.d.ts +0 -28
- package/dist/src/test/utils.js +0 -43
- package/dist/src/test/utils.js.map +0 -1
- package/dist/src/test/widget.test.js +0 -76
- package/dist/src/test/widget.test.js.map +0 -1
- package/dist/src/web/index.d.ts +0 -5
- package/dist/src/web/index.js +0 -6
- package/dist/src/web/index.js.map +0 -1
- package/dist/src/web/mount-widget.js +0 -14
- package/dist/src/web/mount-widget.js.map +0 -1
- package/dist/src/web/plugin.js +0 -28
- package/dist/src/web/plugin.js.map +0 -1
- package/dist/src/web/types.d.ts +0 -95
- package/dist/src/web/types.js.map +0 -1
- package/dist/src/web/use-openai-global.d.ts +0 -2
- package/dist/src/web/use-openai-global.js +0 -21
- package/dist/src/web/use-openai-global.js.map +0 -1
- package/dist/src/web/use-tool-output.d.ts +0 -3
- package/dist/src/web/use-tool-output.js +0 -5
- package/dist/src/web/use-tool-output.js.map +0 -1
- package/dist/vitest.config.d.ts +0 -2
- package/dist/vitest.config.js +0 -9
- package/dist/vitest.config.js.map +0 -1
- /package/dist/{src/test/setup.d.ts → server/asset-base-url-transform-plugin.test.d.ts} +0 -0
- /package/dist/{src/server → server}/index.js +0 -0
- /package/dist/{src/test → test}/widget.test.d.ts +0 -0
- /package/dist/{src/web → web/bridges/apps-sdk}/types.js +0 -0
- /package/dist/{src/web → web}/mount-widget.d.ts +0 -0
- /package/dist/{src/web → web/plugin}/plugin.d.ts +0 -0
package/package.json
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "skybridge",
|
|
3
|
-
"version": "0.0.0-dev.
|
|
4
|
-
"description": "Skybridge is a framework for building ChatGPT
|
|
3
|
+
"version": "0.0.0-dev.ff3ca79",
|
|
4
|
+
"description": "Skybridge is a framework for building ChatGPT and MCP Apps",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "https://github.com/alpic-ai/skybridge.git"
|
|
8
|
+
},
|
|
5
9
|
"type": "module",
|
|
6
10
|
"files": [
|
|
7
|
-
"dist"
|
|
11
|
+
"dist",
|
|
12
|
+
"README.md"
|
|
8
13
|
],
|
|
9
14
|
"exports": {
|
|
10
15
|
"./server": {
|
|
11
|
-
"types": "./dist/
|
|
12
|
-
"default": "./dist/
|
|
16
|
+
"types": "./dist/server/index.d.ts",
|
|
17
|
+
"default": "./dist/server/index.js"
|
|
13
18
|
},
|
|
14
19
|
"./web": {
|
|
15
|
-
"types": "./dist/
|
|
16
|
-
"default": "./dist/
|
|
20
|
+
"types": "./dist/web/index.d.ts",
|
|
21
|
+
"default": "./dist/web/index.js"
|
|
17
22
|
}
|
|
18
23
|
},
|
|
19
|
-
"scripts": {
|
|
20
|
-
"build": "tsc && pnpm run build:templates",
|
|
21
|
-
"build:templates": "cp -r src/server/templates dist/src/server/",
|
|
22
|
-
"test": "vitest run --silent"
|
|
23
|
-
},
|
|
24
24
|
"keywords": [
|
|
25
25
|
"chatgpt",
|
|
26
26
|
"app",
|
|
@@ -30,29 +30,68 @@
|
|
|
30
30
|
"author": "Frédéric Barthelet",
|
|
31
31
|
"license": "ISC",
|
|
32
32
|
"peerDependencies": {
|
|
33
|
+
"@modelcontextprotocol/sdk": ">=1.0.0",
|
|
34
|
+
"@skybridge/devtools": ">=0.26.1",
|
|
35
|
+
"nodemon": ">=3.0.0",
|
|
33
36
|
"react": ">=18.0.0",
|
|
34
37
|
"react-dom": ">=18.0.0"
|
|
35
38
|
},
|
|
36
39
|
"dependencies": {
|
|
37
|
-
"@
|
|
38
|
-
"
|
|
39
|
-
"
|
|
40
|
+
"@babel/core": "^7.29.0",
|
|
41
|
+
"@oclif/core": "^4.8.0",
|
|
42
|
+
"ci-info": "^4.4.0",
|
|
43
|
+
"cors": "^2.8.6",
|
|
44
|
+
"dequal": "^2.0.3",
|
|
45
|
+
"es-toolkit": "^1.44.0",
|
|
46
|
+
"express": "^5.2.1",
|
|
40
47
|
"handlebars": "^4.7.8",
|
|
41
|
-
"
|
|
42
|
-
"
|
|
48
|
+
"ink": "^6.6.0",
|
|
49
|
+
"posthog-node": "^5.24.14",
|
|
50
|
+
"superjson": "^2.2.6",
|
|
51
|
+
"vite": "^7.3.1",
|
|
52
|
+
"zustand": "^5.0.11"
|
|
43
53
|
},
|
|
44
54
|
"devDependencies": {
|
|
55
|
+
"@modelcontextprotocol/ext-apps": "^1.0.1",
|
|
56
|
+
"@modelcontextprotocol/sdk": "^1.26.0",
|
|
57
|
+
"@testing-library/dom": "^10.4.1",
|
|
58
|
+
"@testing-library/react": "^16.3.2",
|
|
45
59
|
"@total-typescript/tsconfig": "^1.0.4",
|
|
60
|
+
"@types/babel__core": "^7.20.5",
|
|
46
61
|
"@types/cors": "^2.8.19",
|
|
47
|
-
"@types/express": "^5.0.
|
|
48
|
-
"@types/jsdom": "^
|
|
49
|
-
"@types/node": "^
|
|
50
|
-
"@types/react": "^19.2.
|
|
51
|
-
"@types/react-dom": "^19.2.
|
|
52
|
-
"@vitest/ui": "^
|
|
53
|
-
"jsdom": "^
|
|
62
|
+
"@types/express": "^5.0.6",
|
|
63
|
+
"@types/jsdom": "^27.0.0",
|
|
64
|
+
"@types/node": "^24.10.12",
|
|
65
|
+
"@types/react": "^19.2.13",
|
|
66
|
+
"@types/react-dom": "^19.2.3",
|
|
67
|
+
"@vitest/ui": "^4.0.18",
|
|
68
|
+
"jsdom": "^28.0.0",
|
|
69
|
+
"shx": "^0.4.0",
|
|
70
|
+
"ts-node": "^10.9.2",
|
|
54
71
|
"typescript": "^5.9.3",
|
|
55
|
-
"vitest": "^
|
|
72
|
+
"vitest": "^4.0.18",
|
|
73
|
+
"zod": "^4.3.6"
|
|
74
|
+
},
|
|
75
|
+
"bin": {
|
|
76
|
+
"sb": "./bin/run.js",
|
|
77
|
+
"skybridge": "./bin/run.js"
|
|
56
78
|
},
|
|
57
|
-
"
|
|
58
|
-
|
|
79
|
+
"oclif": {
|
|
80
|
+
"bin": "skybridge",
|
|
81
|
+
"commands": "./dist/commands",
|
|
82
|
+
"dirname": "skybridge",
|
|
83
|
+
"topicSeparator": " ",
|
|
84
|
+
"hooks": {
|
|
85
|
+
"finally": "./dist/cli/telemetry"
|
|
86
|
+
}
|
|
87
|
+
},
|
|
88
|
+
"scripts": {
|
|
89
|
+
"build": "shx rm -rf dist && tsc && pnpm run build:templates",
|
|
90
|
+
"build:templates": "cp -r src/server/templates dist/server/",
|
|
91
|
+
"format": "biome check --write --error-on-warnings",
|
|
92
|
+
"test": "pnpm run test:unit && pnpm run test:type && pnpm run test:format",
|
|
93
|
+
"test:unit": "vitest run",
|
|
94
|
+
"test:type": "tsc --noEmit",
|
|
95
|
+
"test:format": "biome ci"
|
|
96
|
+
}
|
|
97
|
+
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/server/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACxC,OAAO,EAAE,gBAAgB,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import { McpServer as McpServerBase, type ToolCallback } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import type { Resource } from "@modelcontextprotocol/sdk/types.js";
|
|
3
|
-
import type { ZodRawShape } from "zod";
|
|
4
|
-
type McpServerOriginalResourceConfig = Omit<Resource, "uri" | "name" | "mimeType">;
|
|
5
|
-
type McpServerOriginalToolConfig = Omit<Parameters<McpServer["registerTool"]>[1], "inputSchema" | "outputSchema">;
|
|
6
|
-
export declare class McpServer extends McpServerBase {
|
|
7
|
-
widget<InputArgs extends ZodRawShape, OutputArgs extends ZodRawShape>(name: string, resourceConfig: McpServerOriginalResourceConfig, toolConfig: McpServerOriginalToolConfig & {
|
|
8
|
-
inputSchema?: InputArgs;
|
|
9
|
-
outputSchema?: OutputArgs;
|
|
10
|
-
}, toolCallback: ToolCallback<InputArgs>): void;
|
|
11
|
-
private lookupDistFile;
|
|
12
|
-
}
|
|
13
|
-
export {};
|
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
|
-
import { templateHelper } from "./templateHelper.js";
|
|
3
|
-
import { readFileSync } from "node:fs";
|
|
4
|
-
import path from "node:path";
|
|
5
|
-
export class McpServer extends McpServerBase {
|
|
6
|
-
widget(name, resourceConfig, toolConfig, toolCallback) {
|
|
7
|
-
const uri = `ui://widgets/${name}.html`;
|
|
8
|
-
const resourceMetadata = { ...(resourceConfig._meta ?? {}) };
|
|
9
|
-
if (toolConfig.description !== undefined) {
|
|
10
|
-
resourceMetadata["openai/widgetDescription"] = toolConfig.description;
|
|
11
|
-
}
|
|
12
|
-
this.resource(name, uri, {
|
|
13
|
-
...resourceConfig,
|
|
14
|
-
_meta: resourceMetadata,
|
|
15
|
-
}, async (_uri, extra) => {
|
|
16
|
-
const serverUrl = process.env.NODE_ENV === "production"
|
|
17
|
-
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
18
|
-
extra?.requestInfo?.headers?.host}`
|
|
19
|
-
: `http://localhost:3000`;
|
|
20
|
-
const html = process.env.NODE_ENV === "production"
|
|
21
|
-
? templateHelper.renderProduction({
|
|
22
|
-
serverUrl,
|
|
23
|
-
widgetFile: this.lookupDistFile(`src/widgets/${name}.tsx`),
|
|
24
|
-
styleFile: this.lookupDistFile("style.css"),
|
|
25
|
-
})
|
|
26
|
-
: templateHelper.renderDevelopment({
|
|
27
|
-
serverUrl,
|
|
28
|
-
widgetName: name,
|
|
29
|
-
});
|
|
30
|
-
return {
|
|
31
|
-
contents: [
|
|
32
|
-
{
|
|
33
|
-
uri,
|
|
34
|
-
mimeType: "text/html+skybridge",
|
|
35
|
-
text: html,
|
|
36
|
-
},
|
|
37
|
-
],
|
|
38
|
-
};
|
|
39
|
-
});
|
|
40
|
-
const toolMeta = {
|
|
41
|
-
...toolConfig._meta,
|
|
42
|
-
"openai/outputTemplate": uri,
|
|
43
|
-
};
|
|
44
|
-
this.registerTool(name, {
|
|
45
|
-
...toolConfig,
|
|
46
|
-
_meta: toolMeta,
|
|
47
|
-
}, toolCallback);
|
|
48
|
-
}
|
|
49
|
-
lookupDistFile(key) {
|
|
50
|
-
const manifest = JSON.parse(readFileSync(path.join(process.cwd(), "dist", "assets", ".vite", "manifest.json"), "utf-8"));
|
|
51
|
-
return manifest[key]?.file;
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
//# sourceMappingURL=server.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"server.js","sourceRoot":"","sources":["../../../src/server/server.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,SAAS,IAAI,aAAa,GAE3B,MAAM,yCAAyC,CAAC;AAGjD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,IAAI,MAAM,WAAW,CAAC;AA4B7B,MAAM,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,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,IAIhB;QACC,MAAM,QAAQ,GAAG,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,CAAC;QACjD,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC;IACxB,CAAC;IAED,iBAAiB,CAAC,IAA+C;QAC/D,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"}
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
<base href="{{serverUrl}}" />
|
|
2
|
-
<script type="module">
|
|
3
|
-
import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
|
|
4
|
-
injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
|
|
5
|
-
window.$RefreshSig$ = () => (type) => type;
|
|
6
|
-
window.__vite_plugin_react_preamble_installed__ = true;
|
|
7
|
-
</script>
|
|
8
|
-
<script type="module" src="{{serverUrl}}/@vite/client"></script>
|
|
9
|
-
<div id="root"></div>
|
|
10
|
-
<script type="module">
|
|
11
|
-
import('{{serverUrl}}/src/widgets/{{widgetName}}.tsx');
|
|
12
|
-
</script>
|
|
@@ -1,39 +0,0 @@
|
|
|
1
|
-
import express, {} from "express";
|
|
2
|
-
import cors from "cors";
|
|
3
|
-
import path from "node:path";
|
|
4
|
-
/**
|
|
5
|
-
* Install Vite dev server
|
|
6
|
-
* This router MUST be installed at the application root, like so:
|
|
7
|
-
*
|
|
8
|
-
* const app = express();
|
|
9
|
-
*
|
|
10
|
-
* if (env.NODE_ENV !== "production") {
|
|
11
|
-
* app.use(await widgetsRouter());
|
|
12
|
-
* }
|
|
13
|
-
*/
|
|
14
|
-
export const widgetsDevServer = async () => {
|
|
15
|
-
const router = express.Router();
|
|
16
|
-
const { createServer, searchForWorkspaceRoot, loadConfigFromFile } = await import("vite");
|
|
17
|
-
const workspaceRoot = searchForWorkspaceRoot(process.cwd());
|
|
18
|
-
const webAppRoot = path.join(workspaceRoot, "web");
|
|
19
|
-
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
|
-
const { build, preview, ...devConfig } = configResult?.config || {};
|
|
22
|
-
const vite = await createServer({
|
|
23
|
-
...devConfig,
|
|
24
|
-
configFile: false, // Keep this to prevent vite from trying to resolve path in the target config file
|
|
25
|
-
appType: "custom",
|
|
26
|
-
server: {
|
|
27
|
-
allowedHosts: true,
|
|
28
|
-
middlewareMode: true,
|
|
29
|
-
},
|
|
30
|
-
root: webAppRoot,
|
|
31
|
-
optimizeDeps: {
|
|
32
|
-
include: ["react", "react-dom/client"],
|
|
33
|
-
},
|
|
34
|
-
});
|
|
35
|
-
router.use(cors());
|
|
36
|
-
router.use("/", vite.middlewares);
|
|
37
|
-
return router;
|
|
38
|
-
};
|
|
39
|
-
//# sourceMappingURL=widgetsDevServer.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAuB,MAAM,SAAS,CAAC;AACvD,OAAO,IAAI,MAAM,MAAM,CAAC;AACxB,OAAO,IAAI,MAAM,WAAW,CAAC;AAE7B;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"setup.js","sourceRoot":"","sources":["../../../src/test/setup.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAE,MAAM,QAAQ,CAAC;AAE5B,+CAA+C;AAC/C,MAAM,CAAC,OAAO,GAAG;IACf,GAAG,OAAO;IACV,KAAK,EAAE,EAAE,CAAC,EAAE,EAAE;IACd,IAAI,EAAE,EAAE,CAAC,EAAE,EAAE;IACb,GAAG,EAAE,EAAE,CAAC,EAAE,EAAE;CACb,CAAC"}
|
package/dist/src/test/utils.d.ts
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
import { type MockInstance } from "vitest";
|
|
2
|
-
import { McpServer } from "../server/server.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a real McpServer instance for testing
|
|
5
|
-
*/
|
|
6
|
-
export declare function createMockMcpServer(): {
|
|
7
|
-
server: McpServer;
|
|
8
|
-
mockResource: MockInstance<McpServer["resource"]>;
|
|
9
|
-
mockRegisterTool: MockInstance<McpServer["registerTool"]>;
|
|
10
|
-
};
|
|
11
|
-
/**
|
|
12
|
-
* Mock extra parameter for resource callback
|
|
13
|
-
*/
|
|
14
|
-
export declare function createMockExtra(host: string): {
|
|
15
|
-
requestInfo: {
|
|
16
|
-
headers: {
|
|
17
|
-
host: string;
|
|
18
|
-
};
|
|
19
|
-
};
|
|
20
|
-
};
|
|
21
|
-
/**
|
|
22
|
-
* Sets up environment variables for testing
|
|
23
|
-
*/
|
|
24
|
-
export declare function setTestEnv(env: Record<string, string>): void;
|
|
25
|
-
/**
|
|
26
|
-
* Resets environment variables
|
|
27
|
-
*/
|
|
28
|
-
export declare function resetTestEnv(): void;
|
package/dist/src/test/utils.js
DELETED
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
import { vi } from "vitest";
|
|
2
|
-
import { McpServer, McpServer as McpServerBase } from "../server/server.js";
|
|
3
|
-
/**
|
|
4
|
-
* Creates a real McpServer instance for testing
|
|
5
|
-
*/
|
|
6
|
-
export function createMockMcpServer() {
|
|
7
|
-
// Create a real McpServer instance
|
|
8
|
-
const server = new McpServer({
|
|
9
|
-
name: "alpic-openai-app",
|
|
10
|
-
version: "0.0.1",
|
|
11
|
-
}, { capabilities: {} });
|
|
12
|
-
// Mock the underlying methods to track calls
|
|
13
|
-
const mockResource = vi.spyOn(server, "resource");
|
|
14
|
-
const mockRegisterTool = vi.spyOn(server, "registerTool");
|
|
15
|
-
return {
|
|
16
|
-
server,
|
|
17
|
-
mockResource,
|
|
18
|
-
mockRegisterTool,
|
|
19
|
-
};
|
|
20
|
-
}
|
|
21
|
-
/**
|
|
22
|
-
* Mock extra parameter for resource callback
|
|
23
|
-
*/
|
|
24
|
-
export function createMockExtra(host) {
|
|
25
|
-
return {
|
|
26
|
-
requestInfo: {
|
|
27
|
-
headers: { host },
|
|
28
|
-
},
|
|
29
|
-
};
|
|
30
|
-
}
|
|
31
|
-
/**
|
|
32
|
-
* Sets up environment variables for testing
|
|
33
|
-
*/
|
|
34
|
-
export function setTestEnv(env) {
|
|
35
|
-
Object.assign(process.env, env);
|
|
36
|
-
}
|
|
37
|
-
/**
|
|
38
|
-
* Resets environment variables
|
|
39
|
-
*/
|
|
40
|
-
export function resetTestEnv() {
|
|
41
|
-
delete process.env.NODE_ENV;
|
|
42
|
-
}
|
|
43
|
-
//# sourceMappingURL=utils.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"utils.js","sourceRoot":"","sources":["../../../src/test/utils.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,EAAE,EAAqB,MAAM,QAAQ,CAAC;AAC/C,OAAO,EAAE,SAAS,EAAE,SAAS,IAAI,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAE5E;;GAEG;AACH,MAAM,UAAU,mBAAmB;IAKjC,mCAAmC;IACnC,MAAM,MAAM,GAAG,IAAI,SAAS,CAC1B;QACE,IAAI,EAAE,kBAAkB;QACxB,OAAO,EAAE,OAAO;KACjB,EACD,EAAE,YAAY,EAAE,EAAE,EAAE,CACrB,CAAC;IAEF,6CAA6C;IAC7C,MAAM,YAAY,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,UAAU,CAAC,CAAC;IAClD,MAAM,gBAAgB,GAAG,EAAE,CAAC,KAAK,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAE1D,OAAO;QACL,MAAM;QACN,YAAY;QACZ,gBAAgB;KACjB,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,IAAY;IAC1C,OAAO;QACL,WAAW,EAAE;YACX,OAAO,EAAE,EAAE,IAAI,EAAE;SAClB;KACF,CAAC;AACJ,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,UAAU,CAAC,GAA2B;IACpD,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,GAAG,EAAE,GAAG,CAAC,CAAC;AAClC,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,YAAY;IAC1B,OAAO,OAAO,CAAC,GAAG,CAAC,QAAQ,CAAC;AAC9B,CAAC"}
|
|
@@ -1,76 +0,0 @@
|
|
|
1
|
-
import { describe, it, expect, vi, beforeEach, afterEach, } from "vitest";
|
|
2
|
-
import * as fs from "node:fs";
|
|
3
|
-
import { McpServer } from "../server/server.js";
|
|
4
|
-
import { createMockMcpServer, createMockExtra, setTestEnv, resetTestEnv, } from "./utils.js";
|
|
5
|
-
describe("McpServer.widget", () => {
|
|
6
|
-
let server;
|
|
7
|
-
let mockResource;
|
|
8
|
-
let mockRegisterTool;
|
|
9
|
-
beforeEach(() => {
|
|
10
|
-
({ server, mockResource, mockRegisterTool } = createMockMcpServer());
|
|
11
|
-
});
|
|
12
|
-
afterEach(() => {
|
|
13
|
-
vi.clearAllMocks();
|
|
14
|
-
resetTestEnv();
|
|
15
|
-
});
|
|
16
|
-
it("should generate correct HTML for development mode", async () => {
|
|
17
|
-
setTestEnv({ NODE_ENV: "development" });
|
|
18
|
-
const mockToolCallback = vi.fn();
|
|
19
|
-
const mockResourceConfig = { description: "Test widget" };
|
|
20
|
-
const mockToolConfig = { description: "Test tool" };
|
|
21
|
-
server.widget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
|
|
22
|
-
// Get the resource callback function
|
|
23
|
-
const resourceCallback = mockResource.mock.calls[0]?.[3];
|
|
24
|
-
expect(resourceCallback).toBeDefined();
|
|
25
|
-
const serverUrl = "http://localhost:3000";
|
|
26
|
-
const mockExtra = createMockExtra("__not_used__");
|
|
27
|
-
const result = await resourceCallback(new URL("ui://widgets/my-widget.html"), mockExtra);
|
|
28
|
-
expect(result).toEqual({
|
|
29
|
-
contents: [
|
|
30
|
-
{
|
|
31
|
-
uri: "ui://widgets/my-widget.html",
|
|
32
|
-
mimeType: "text/html+skybridge",
|
|
33
|
-
text: expect.stringContaining('<div id="root"></div>'),
|
|
34
|
-
},
|
|
35
|
-
],
|
|
36
|
-
});
|
|
37
|
-
// Check development-specific content
|
|
38
|
-
expect(result.contents[0]?.text).toContain(serverUrl + "/@react-refresh");
|
|
39
|
-
expect(result.contents[0]?.text).toContain(serverUrl + "/@vite/client");
|
|
40
|
-
expect(result.contents[0]?.text).toContain(serverUrl + "/src/widgets/my-widget.tsx");
|
|
41
|
-
});
|
|
42
|
-
it("should generate correct HTML for production mode", async () => {
|
|
43
|
-
setTestEnv({ NODE_ENV: "production" });
|
|
44
|
-
// Mock the manifest.json file that's read in production mode
|
|
45
|
-
const mockManifest = {
|
|
46
|
-
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
47
|
-
"style.css": { file: "style.css" },
|
|
48
|
-
};
|
|
49
|
-
vi.spyOn(fs, "readFileSync").mockReturnValue(JSON.stringify(mockManifest));
|
|
50
|
-
const mockToolCallback = vi.fn();
|
|
51
|
-
const mockResourceConfig = { description: "Test widget" };
|
|
52
|
-
const mockToolConfig = { description: "Test tool" };
|
|
53
|
-
server.widget("my-widget", mockResourceConfig, mockToolConfig, mockToolCallback);
|
|
54
|
-
// Get the resource callback function
|
|
55
|
-
const resourceCallback = mockResource.mock.calls[0]?.[3];
|
|
56
|
-
expect(resourceCallback).toBeDefined();
|
|
57
|
-
const serverUrl = "https://myapp.com";
|
|
58
|
-
const mockExtra = createMockExtra(serverUrl);
|
|
59
|
-
const result = await resourceCallback(new URL("ui://widgets/my-widget.html"), mockExtra);
|
|
60
|
-
expect(result).toEqual({
|
|
61
|
-
contents: [
|
|
62
|
-
{
|
|
63
|
-
uri: "ui://widgets/my-widget.html",
|
|
64
|
-
mimeType: "text/html+skybridge",
|
|
65
|
-
text: expect.stringContaining('<div id="root"></div>'),
|
|
66
|
-
},
|
|
67
|
-
],
|
|
68
|
-
});
|
|
69
|
-
// Check production-specific content
|
|
70
|
-
expect(result.contents[0]?.text).not.toContain(serverUrl + "@react-refresh");
|
|
71
|
-
expect(result.contents[0]?.text).not.toContain(serverUrl + "@vite/client");
|
|
72
|
-
expect(result.contents[0]?.text).toContain(serverUrl + "/assets/my-widget.js");
|
|
73
|
-
expect(result.contents[0]?.text).toContain(serverUrl + "/assets/style.css");
|
|
74
|
-
});
|
|
75
|
-
});
|
|
76
|
-
//# sourceMappingURL=widget.test.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,EAAE,EACF,MAAM,EACN,EAAE,EACF,UAAU,EACV,SAAS,GAEV,MAAM,QAAQ,CAAC;AAChB,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,UAAU,EACV,YAAY,GACb,MAAM,YAAY,CAAC;AAEpB,QAAQ,CAAC,kBAAkB,EAAE,GAAG,EAAE;IAChC,IAAI,MAAiB,CAAC;IACtB,IAAI,YAAiD,CAAC;IACtD,IAAI,gBAAyD,CAAC;IAE9D,UAAU,CAAC,GAAG,EAA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,CAAC;QACtC,MAAM,SAAS,GAAG,eAAe,CAAC,SAAS,CAAC,CAAC;QAC7C,MAAM,MAAM,GAAG,MAAM,gBAAiB,CACpC,IAAI,GAAG,CAAC,6BAA6B,CAAC,EACtC,SAAS,CACV,CAAC;QAEF,MAAM,CAAC,MAAM,CAAC,CAAC,OAAO,CAAC;YACrB,QAAQ,EAAE;gBACR;oBACE,GAAG,EAAE,6BAA6B;oBAClC,QAAQ,EAAE,qBAAqB;oBAC/B,IAAI,EAAE,MAAM,CAAC,gBAAgB,CAAC,uBAAuB,CAAC;iBACvD;aACF;SACF,CAAC,CAAC;QAEH,oCAAoC;QACpC,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAC5C,SAAS,GAAG,gBAAgB,CAC7B,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,GAAG,CAAC,SAAS,CAAC,SAAS,GAAG,cAAc,CAAC,CAAC;QAC3E,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CACxC,SAAS,GAAG,sBAAsB,CACnC,CAAC;QACF,MAAM,CAAC,MAAM,CAAC,QAAQ,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,CAAC,SAAS,CAAC,SAAS,GAAG,mBAAmB,CAAC,CAAC;IAC9E,CAAC,CAAC,CAAC;AACL,CAAC,CAAC,CAAC"}
|
package/dist/src/web/index.d.ts
DELETED
package/dist/src/web/index.js
DELETED
|
@@ -1,6 +0,0 @@
|
|
|
1
|
-
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
2
|
-
export { useToolOutput } from "./use-tool-output.js";
|
|
3
|
-
export * from "./types.js";
|
|
4
|
-
export { mountWidget } from "./mount-widget.js";
|
|
5
|
-
export { skybridge } from "./plugin.js";
|
|
6
|
-
//# sourceMappingURL=index.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../src/web/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import { createElement, StrictMode } from "react";
|
|
2
|
-
import { createRoot } from "react-dom/client";
|
|
3
|
-
let rootInstance = null;
|
|
4
|
-
export const mountWidget = (component) => {
|
|
5
|
-
const rootElement = document.getElementById("root");
|
|
6
|
-
if (!rootElement) {
|
|
7
|
-
throw new Error("Root element not found");
|
|
8
|
-
}
|
|
9
|
-
if (!rootInstance) {
|
|
10
|
-
rootInstance = createRoot(rootElement);
|
|
11
|
-
}
|
|
12
|
-
rootInstance.render(createElement(StrictMode, null, component));
|
|
13
|
-
};
|
|
14
|
-
//# sourceMappingURL=mount-widget.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"mount-widget.js","sourceRoot":"","sources":["../../../src/web/mount-widget.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,aAAa,EAAE,UAAU,EAAE,MAAM,OAAO,CAAC;AAClD,OAAO,EAAE,UAAU,EAAa,MAAM,kBAAkB,CAAC;AAEzD,IAAI,YAAY,GAAgB,IAAI,CAAC;AAErC,MAAM,CAAC,MAAM,WAAW,GAAG,CAAC,SAA0B,EAAE,EAAE;IACxD,MAAM,WAAW,GAAG,QAAQ,CAAC,cAAc,CAAC,MAAM,CAAC,CAAC;IACpD,IAAI,CAAC,WAAW,EAAE,CAAC;QACjB,MAAM,IAAI,KAAK,CAAC,wBAAwB,CAAC,CAAC;IAC5C,CAAC;IAED,IAAI,CAAC,YAAY,EAAE,CAAC;QAClB,YAAY,GAAG,UAAU,CAAC,WAAW,CAAC,CAAC;IACzC,CAAC;IAED,YAAY,CAAC,MAAM,CAAC,aAAa,CAAC,UAAU,EAAE,IAAI,EAAE,SAAS,CAAC,CAAC,CAAC;AAClE,CAAC,CAAC"}
|
package/dist/src/web/plugin.js
DELETED
|
@@ -1,28 +0,0 @@
|
|
|
1
|
-
export function skybridge() {
|
|
2
|
-
return {
|
|
3
|
-
name: "skybridge",
|
|
4
|
-
async config(config) {
|
|
5
|
-
// Dynamic imports to ensure Node modules are only loaded in Node.js context
|
|
6
|
-
const { globSync } = await import("node:fs");
|
|
7
|
-
const { resolve } = await import("node:path");
|
|
8
|
-
const projectRoot = config.root || process.cwd();
|
|
9
|
-
const widgetsPattern = resolve(projectRoot, "src/widgets/*.{js,ts,jsx,tsx,html}");
|
|
10
|
-
const input = Object.fromEntries(globSync(widgetsPattern).map((file) => [
|
|
11
|
-
file.match(/src\/widgets\/(.+)\.tsx$/)?.[1],
|
|
12
|
-
file,
|
|
13
|
-
]));
|
|
14
|
-
return {
|
|
15
|
-
base: "/assets",
|
|
16
|
-
build: {
|
|
17
|
-
manifest: true,
|
|
18
|
-
minify: true,
|
|
19
|
-
cssCodeSplit: false,
|
|
20
|
-
rollupOptions: {
|
|
21
|
-
input,
|
|
22
|
-
},
|
|
23
|
-
},
|
|
24
|
-
};
|
|
25
|
-
},
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
//# sourceMappingURL=plugin.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sourceRoot":"","sources":["../../../src/web/plugin.ts"],"names":[],"mappings":"AAEA,MAAM,UAAU,SAAS;IACvB,OAAO;QACL,IAAI,EAAE,WAAW;QAEjB,KAAK,CAAC,MAAM,CAAC,MAAM;YACjB,4EAA4E;YAC5E,MAAM,EAAE,QAAQ,EAAE,GAAG,MAAM,MAAM,CAAC,SAAS,CAAC,CAAC;YAC7C,MAAM,EAAE,OAAO,EAAE,GAAG,MAAM,MAAM,CAAC,WAAW,CAAC,CAAC;YAE9C,MAAM,WAAW,GAAG,MAAM,CAAC,IAAI,IAAI,OAAO,CAAC,GAAG,EAAE,CAAC;YACjD,MAAM,cAAc,GAAG,OAAO,CAC5B,WAAW,EACX,oCAAoC,CACrC,CAAC;YAEF,MAAM,KAAK,GAAG,MAAM,CAAC,WAAW,CAC9B,QAAQ,CAAC,cAAc,CAAC,CAAC,GAAG,CAAC,CAAC,IAAI,EAAE,EAAE,CAAC;gBACrC,IAAI,CAAC,KAAK,CAAC,0BAA0B,CAAC,EAAE,CAAC,CAAC,CAAC;gBAC3C,IAAI;aACL,CAAC,CACH,CAAC;YAEF,OAAO;gBACL,IAAI,EAAE,SAAS;gBACf,KAAK,EAAE;oBACL,QAAQ,EAAE,IAAI;oBACd,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;qBACN;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/dist/src/web/types.d.ts
DELETED
|
@@ -1,95 +0,0 @@
|
|
|
1
|
-
type UnknownObject = Record<string, unknown>;
|
|
2
|
-
export type WidgetState = UnknownObject;
|
|
3
|
-
export type SetWidgetState = (state: WidgetState) => Promise<void>;
|
|
4
|
-
export type SendFollowUpMessage = (args: {
|
|
5
|
-
prompt: string;
|
|
6
|
-
}) => Promise<void>;
|
|
7
|
-
export type RequestDisplayMode = (args: {
|
|
8
|
-
mode: DisplayMode;
|
|
9
|
-
}) => Promise<{
|
|
10
|
-
mode: DisplayMode;
|
|
11
|
-
}>;
|
|
12
|
-
export declare const TOOL_RESPONSE_EVENT_TYPE = "openai:tool_response";
|
|
13
|
-
export declare class ToolResponseEvent extends CustomEvent<{
|
|
14
|
-
tool: {
|
|
15
|
-
name: string;
|
|
16
|
-
args: UnknownObject;
|
|
17
|
-
};
|
|
18
|
-
}> {
|
|
19
|
-
readonly type = "openai:tool_response";
|
|
20
|
-
}
|
|
21
|
-
declare global {
|
|
22
|
-
interface Window {
|
|
23
|
-
openai: API<WidgetState> & OpenAiGlobals;
|
|
24
|
-
}
|
|
25
|
-
interface WindowEventMap {
|
|
26
|
-
[SET_GLOBALS_EVENT_TYPE]: SetGlobalsEvent;
|
|
27
|
-
}
|
|
28
|
-
}
|
|
29
|
-
export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolOutput extends UnknownObject = UnknownObject, ToolResponseMetadata extends UnknownObject = UnknownObject, WidgetState extends UnknownObject = UnknownObject> = {
|
|
30
|
-
theme: Theme;
|
|
31
|
-
userAgent: UserAgent;
|
|
32
|
-
locale: string;
|
|
33
|
-
maxHeight: number;
|
|
34
|
-
displayMode: DisplayMode;
|
|
35
|
-
safeArea: SafeArea;
|
|
36
|
-
toolInput: ToolInput;
|
|
37
|
-
toolOutput: ToolOutput | null;
|
|
38
|
-
toolResponseMetadata: ToolResponseMetadata | null;
|
|
39
|
-
widgetState: WidgetState | null;
|
|
40
|
-
};
|
|
41
|
-
export type CallToolResponse = {
|
|
42
|
-
result: string;
|
|
43
|
-
};
|
|
44
|
-
type API<WidgetState extends UnknownObject> = {
|
|
45
|
-
/** Calls a tool on your MCP. Returns the full response. */
|
|
46
|
-
callTool: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
47
|
-
/** Triggers a followup turn in the ChatGPT conversation */
|
|
48
|
-
sendFollowUpMessage: (args: {
|
|
49
|
-
prompt: string;
|
|
50
|
-
}) => Promise<void>;
|
|
51
|
-
/** Opens an external link, redirects web page or mobile app */
|
|
52
|
-
openExternal(payload: {
|
|
53
|
-
href: string;
|
|
54
|
-
}): void;
|
|
55
|
-
/** For transitioning an app from inline to fullscreen or pip */
|
|
56
|
-
requestDisplayMode: (args: {
|
|
57
|
-
mode: DisplayMode;
|
|
58
|
-
}) => Promise<{
|
|
59
|
-
/**
|
|
60
|
-
* The granted display mode. The host may reject the request.
|
|
61
|
-
* For mobile, PiP is always coerced to fullscreen.
|
|
62
|
-
*/
|
|
63
|
-
mode: DisplayMode;
|
|
64
|
-
}>;
|
|
65
|
-
setWidgetState: (state: WidgetState) => Promise<void>;
|
|
66
|
-
};
|
|
67
|
-
export declare const SET_GLOBALS_EVENT_TYPE = "openai:set_globals";
|
|
68
|
-
export declare class SetGlobalsEvent extends CustomEvent<{
|
|
69
|
-
globals: Partial<OpenAiGlobals>;
|
|
70
|
-
}> {
|
|
71
|
-
readonly type = "openai:set_globals";
|
|
72
|
-
}
|
|
73
|
-
export type CallTool = (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
|
|
74
|
-
export type DisplayMode = "pip" | "inline" | "fullscreen";
|
|
75
|
-
export type Theme = "light" | "dark";
|
|
76
|
-
export type SafeAreaInsets = {
|
|
77
|
-
top: number;
|
|
78
|
-
bottom: number;
|
|
79
|
-
left: number;
|
|
80
|
-
right: number;
|
|
81
|
-
};
|
|
82
|
-
export type SafeArea = {
|
|
83
|
-
insets: SafeAreaInsets;
|
|
84
|
-
};
|
|
85
|
-
export type DeviceType = "mobile" | "tablet" | "desktop" | "unknown";
|
|
86
|
-
export type UserAgent = {
|
|
87
|
-
device: {
|
|
88
|
-
type: DeviceType;
|
|
89
|
-
};
|
|
90
|
-
capabilities: {
|
|
91
|
-
hover: boolean;
|
|
92
|
-
touch: boolean;
|
|
93
|
-
};
|
|
94
|
-
};
|
|
95
|
-
export {};
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"types.js","sourceRoot":"","sources":["../../../src/web/types.ts"],"names":[],"mappings":"AAYA,MAAM,CAAC,MAAM,wBAAwB,GAAG,sBAAsB,CAAC;AAC/D,MAAM,OAAO,iBAAkB,SAAQ,WAErC;IACkB,IAAI,GAAG,wBAAwB,CAAC;CACnD;AA+DD,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { useSyncExternalStore } from "react";
|
|
2
|
-
import { SET_GLOBALS_EVENT_TYPE, SetGlobalsEvent } from "./types.js";
|
|
3
|
-
export function useOpenAiGlobal(key) {
|
|
4
|
-
return useSyncExternalStore((onChange) => {
|
|
5
|
-
const handleSetGlobal = (event) => {
|
|
6
|
-
const value = event.detail.globals[key];
|
|
7
|
-
if (value === undefined) {
|
|
8
|
-
return;
|
|
9
|
-
}
|
|
10
|
-
console.dir(event.detail.globals, { depth: Infinity });
|
|
11
|
-
onChange();
|
|
12
|
-
};
|
|
13
|
-
window.addEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal, {
|
|
14
|
-
passive: true,
|
|
15
|
-
});
|
|
16
|
-
return () => {
|
|
17
|
-
window.removeEventListener(SET_GLOBALS_EVENT_TYPE, handleSetGlobal);
|
|
18
|
-
};
|
|
19
|
-
}, () => window.openai?.[key]);
|
|
20
|
-
}
|
|
21
|
-
//# sourceMappingURL=use-openai-global.js.map
|