skybridge 0.0.0-dev.ea1eaa2 → 0.0.0-dev.eac9740
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/README.md +196 -1
- 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 +1 -0
- package/dist/src/server/server.js +18 -10
- package/dist/src/server/server.js.map +1 -1
- package/dist/src/server/templateHelper.d.ts +9 -8
- package/dist/src/server/templateHelper.js +0 -8
- package/dist/src/server/templateHelper.js.map +1 -1
- package/dist/src/server/templates/development.hbs +12 -0
- package/dist/src/server/templates/production.hbs +6 -0
- package/dist/src/server/widgetsDevServer.d.ts +5 -2
- package/dist/src/server/widgetsDevServer.js +5 -2
- package/dist/src/server/widgetsDevServer.js.map +1 -1
- package/dist/src/test/widget.test.js +24 -6
- package/dist/src/test/widget.test.js.map +1 -1
- package/dist/src/web/hooks/index.d.ts +13 -0
- package/dist/src/web/hooks/index.js +14 -0
- package/dist/src/web/hooks/index.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.d.ts +58 -0
- package/dist/src/web/hooks/use-call-tool.js +50 -0
- package/dist/src/web/hooks/use-call-tool.js.map +1 -0
- package/dist/src/web/hooks/use-call-tool.test.d.ts +1 -0
- package/dist/src/web/hooks/use-call-tool.test.js +104 -0
- package/dist/src/web/hooks/use-call-tool.test.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.d.ts +4 -0
- package/dist/src/web/hooks/use-display-mode.js +7 -0
- package/dist/src/web/hooks/use-display-mode.js.map +1 -0
- package/dist/src/web/hooks/use-display-mode.test.d.ts +1 -0
- package/dist/src/web/hooks/use-display-mode.test.js +40 -0
- package/dist/src/web/hooks/use-display-mode.test.js.map +1 -0
- package/dist/src/web/hooks/use-locale.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.js +5 -0
- package/dist/src/web/hooks/use-locale.js.map +1 -0
- package/dist/src/web/hooks/use-locale.test.d.ts +1 -0
- package/dist/src/web/hooks/use-locale.test.js +21 -0
- package/dist/src/web/hooks/use-locale.test.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.js +6 -0
- package/dist/src/web/hooks/use-open-external.js.map +1 -0
- package/dist/src/web/hooks/use-open-external.test.d.ts +1 -0
- package/dist/src/web/hooks/use-open-external.test.js +24 -0
- package/dist/src/web/hooks/use-open-external.test.js.map +1 -0
- package/dist/src/web/{use-openai-global.d.ts → hooks/use-openai-global.d.ts} +1 -1
- package/dist/src/web/{use-openai-global.js → hooks/use-openai-global.js} +1 -1
- package/dist/src/web/hooks/use-openai-global.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.d.ts +5 -0
- package/dist/src/web/hooks/use-request-modal.js +9 -0
- package/dist/src/web/hooks/use-request-modal.js.map +1 -0
- package/dist/src/web/hooks/use-request-modal.test.d.ts +1 -0
- package/dist/src/web/hooks/use-request-modal.test.js +24 -0
- package/dist/src/web/hooks/use-request-modal.test.js.map +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.d.ts +1 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js +11 -0
- package/dist/src/web/hooks/use-send-follow-up-message.js.map +1 -0
- package/dist/src/web/hooks/use-theme.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.js +5 -0
- package/dist/src/web/hooks/use-theme.js.map +1 -0
- package/dist/src/web/hooks/use-theme.test.d.ts +1 -0
- package/dist/src/web/hooks/use-theme.test.js +26 -0
- package/dist/src/web/hooks/use-theme.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.d.ts +5 -0
- package/dist/src/web/hooks/use-tool-info.js +9 -0
- package/dist/src/web/hooks/use-tool-info.js.map +1 -0
- package/dist/src/web/hooks/use-tool-info.test.d.ts +1 -0
- package/dist/src/web/hooks/use-tool-info.test.js +38 -0
- package/dist/src/web/hooks/use-tool-info.test.js.map +1 -0
- package/dist/src/web/hooks/use-tool-output.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-output.js +9 -0
- package/dist/src/web/hooks/use-tool-output.js.map +1 -0
- package/dist/src/web/hooks/use-tool-response-metadata.d.ts +4 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js +8 -0
- package/dist/src/web/hooks/use-tool-response-metadata.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.js +5 -0
- package/dist/src/web/hooks/use-user-agent.js.map +1 -0
- package/dist/src/web/hooks/use-user-agent.test.d.ts +1 -0
- package/dist/src/web/hooks/use-user-agent.test.js +31 -0
- package/dist/src/web/hooks/use-user-agent.test.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.d.ts +4 -0
- package/dist/src/web/hooks/use-widget-state.js +30 -0
- package/dist/src/web/hooks/use-widget-state.js.map +1 -0
- package/dist/src/web/hooks/use-widget-state.test.d.ts +1 -0
- package/dist/src/web/hooks/use-widget-state.test.js +61 -0
- package/dist/src/web/hooks/use-widget-state.test.js.map +1 -0
- package/dist/src/web/index.d.ts +2 -2
- package/dist/src/web/index.js +2 -2
- package/dist/src/web/index.js.map +1 -1
- package/dist/src/web/mount-widget.js +7 -3
- package/dist/src/web/mount-widget.js.map +1 -1
- package/dist/src/web/plugin.d.ts +2 -0
- package/dist/src/web/plugin.js +28 -0
- package/dist/src/web/plugin.js.map +1 -0
- package/dist/src/web/types.d.ts +17 -2
- package/dist/src/web/types.js.map +1 -1
- package/package.json +16 -12
- package/dist/src/server/middleware.d.ts +0 -3
- package/dist/src/server/middleware.js +0 -47
- package/dist/src/server/middleware.js.map +0 -1
- package/dist/src/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/README.md
CHANGED
|
@@ -1,3 +1,198 @@
|
|
|
1
|
+
<div align="center">
|
|
2
|
+
|
|
1
3
|
# Skybridge
|
|
2
4
|
|
|
3
|
-
Skybridge is
|
|
5
|
+
**Skybridge is the TypeScript framework for building ChatGPT apps**
|
|
6
|
+
|
|
7
|
+
[](https://alpic.ai)
|
|
8
|
+
|
|
9
|
+

|
|
10
|
+

|
|
11
|
+

|
|
12
|
+
|
|
13
|
+
</div>
|
|
14
|
+
|
|
15
|
+
Skybridge comes with 2 packages:
|
|
16
|
+
|
|
17
|
+
- `skybridge/server`: A drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development.
|
|
18
|
+
- `skybridge/web`: A react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
|
|
19
|
+
|
|
20
|
+
## Quick start
|
|
21
|
+
|
|
22
|
+
To get started in less than a minute, you can [create a new repository](https://github.com/new?template_name=apps-sdk-template&template_owner=alpic-ai) using our [ChatGPT SDK template](https://github.com/alpic-ai/apps-sdk-template). This template includes a basic setup for both the server and the widgets.
|
|
23
|
+
|
|
24
|
+
## Installation
|
|
25
|
+
|
|
26
|
+
```bash
|
|
27
|
+
pnpm add skybridge
|
|
28
|
+
```
|
|
29
|
+
|
|
30
|
+
## Concepts
|
|
31
|
+
|
|
32
|
+
### Widgets
|
|
33
|
+
|
|
34
|
+
> A widget is a UI component that turns structured tool results into a human-friendly UI. Those are built using React components. They are rendered inside an iframe inline with the conversation on ChatGPT.
|
|
35
|
+
|
|
36
|
+
Each widget in your app must have a unique name. The name is used to bridge the tool invocation result with the widget React component.
|
|
37
|
+
|
|
38
|
+
For example, in order to register a new widget named `pokemon` on your ChatGPT app. You should have the following file structure and file contents:
|
|
39
|
+
|
|
40
|
+
_Project structure_
|
|
41
|
+
|
|
42
|
+
```
|
|
43
|
+
server/
|
|
44
|
+
└── src/
|
|
45
|
+
└── index.ts // Register the widget with McpServer.widget()
|
|
46
|
+
web/
|
|
47
|
+
└── src/
|
|
48
|
+
└── widgets/
|
|
49
|
+
└── pokemon.tsx // Use the same widget name as the file name
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
_server/src/index.ts_
|
|
53
|
+
|
|
54
|
+
```ts
|
|
55
|
+
import { McpServer } from "skybridge/server";
|
|
56
|
+
|
|
57
|
+
const server = new McpServer();
|
|
58
|
+
|
|
59
|
+
server.widget(
|
|
60
|
+
"pokemon"
|
|
61
|
+
// Remaining arguments...
|
|
62
|
+
);
|
|
63
|
+
```
|
|
64
|
+
|
|
65
|
+
_web/src/widgets/pokemon.tsx_
|
|
66
|
+
|
|
67
|
+
```ts
|
|
68
|
+
import { mountWidget } from "skybridge/web";
|
|
69
|
+
|
|
70
|
+
const Pokemon: React.FunctionComponent = () => {
|
|
71
|
+
// Your React component code goes here...
|
|
72
|
+
};
|
|
73
|
+
|
|
74
|
+
mountWidget(<Pokemon />);
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
## Packages
|
|
78
|
+
|
|
79
|
+
### skybridge/server
|
|
80
|
+
|
|
81
|
+
The `skybridge/server` package is a drop-in replacement of the `@modelcontextprotocol/sdk` official `McpServer` class with extra features for widget development. If you're already using the `@modelcontextprotocol/sdk`, you can simply replace your `McpServer` import with `skybridge/server` and you're good to go.
|
|
82
|
+
|
|
83
|
+
### skybridge/web
|
|
84
|
+
|
|
85
|
+
The `skybridge/web` package is a react library with hooks and components to build widgets on the underlying _OpenAI iFrame skybridge_ runtime.
|
|
86
|
+
|
|
87
|
+
**Vite plugin**
|
|
88
|
+
|
|
89
|
+
The `skybridge/web` package comes with a Vite plugin that allows you to build your widgets as regular Vite apps.
|
|
90
|
+
|
|
91
|
+
```ts
|
|
92
|
+
import { defineConfig } from "vite";
|
|
93
|
+
import { skybridge } from "skybridge/web";
|
|
94
|
+
|
|
95
|
+
export default defineConfig({
|
|
96
|
+
plugins: [skybridge()],
|
|
97
|
+
});
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
**Hooks**
|
|
101
|
+
|
|
102
|
+
The `skybridge/web` package comes with a set of hooks to help you build your widgets :
|
|
103
|
+
|
|
104
|
+
- `useOpenAiGlobal`: A generic hook to get any global data from the OpenAI iFrame skybridge runtime (in `window.openai`).
|
|
105
|
+
- `useToolOutput`: A hook to get the initial tool `structuredContent` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
|
|
106
|
+
- `useToolResponseMetadata`: A hook to get the initial tool `meta` returned when rendering the widget for the first time. The data inside this hook is not updated when the tool is called again.
|
|
107
|
+
- `useCallTool`: A @tanstack/react-query inspired hook to send make additional tool calls inside a widget.
|
|
108
|
+
|
|
109
|
+
_useOpenAiGlobal_
|
|
110
|
+
|
|
111
|
+
```ts
|
|
112
|
+
import { useOpenAiGlobal } from "skybridge/web";
|
|
113
|
+
|
|
114
|
+
const theme = useOpenAiGlobal("theme");
|
|
115
|
+
```
|
|
116
|
+
|
|
117
|
+
_useToolOutput_
|
|
118
|
+
|
|
119
|
+
```ts
|
|
120
|
+
import { useToolOutput } from "skybridge/web";
|
|
121
|
+
|
|
122
|
+
const toolOutput = useToolOutput();
|
|
123
|
+
```
|
|
124
|
+
|
|
125
|
+
_useToolResponseMetadata_
|
|
126
|
+
|
|
127
|
+
```ts
|
|
128
|
+
import { useToolResponseMetadata } from "skybridge/web";
|
|
129
|
+
|
|
130
|
+
const toolResponseMetadata = useToolResponseMetadata();
|
|
131
|
+
```
|
|
132
|
+
|
|
133
|
+
_useCallTool_ in synchronous mode
|
|
134
|
+
|
|
135
|
+
```ts
|
|
136
|
+
import { useCallTool } from "skybridge/web";
|
|
137
|
+
|
|
138
|
+
export const TestTool: React.FunctionComponent = () => {
|
|
139
|
+
const { callTool, isPending } = useCallTool("myToolName");
|
|
140
|
+
|
|
141
|
+
return (
|
|
142
|
+
<div>
|
|
143
|
+
<button
|
|
144
|
+
disabled={isPending}
|
|
145
|
+
onClick={() => {
|
|
146
|
+
callTool({ input: "test input" }, {
|
|
147
|
+
onSuccess: (data) => {
|
|
148
|
+
alert("Tool returned: " + data);
|
|
149
|
+
},
|
|
150
|
+
});
|
|
151
|
+
>
|
|
152
|
+
Call Tool inside a widget
|
|
153
|
+
</button>
|
|
154
|
+
</div>
|
|
155
|
+
);
|
|
156
|
+
};
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
_useCallTool_ in asynchronous mode
|
|
160
|
+
|
|
161
|
+
```ts
|
|
162
|
+
import { useCallTool } from "skybridge/web";
|
|
163
|
+
|
|
164
|
+
export const TestTool: React.FunctionComponent = () => {
|
|
165
|
+
const { callToolAsync, isPending } = useCallTool("myToolName");
|
|
166
|
+
|
|
167
|
+
return (
|
|
168
|
+
<div>
|
|
169
|
+
<button
|
|
170
|
+
disabled={isPending}
|
|
171
|
+
onClick={async () => {
|
|
172
|
+
const data = await callToolAsync({ input: "test input" });
|
|
173
|
+
alert("Tool returned: " + data);
|
|
174
|
+
}}
|
|
175
|
+
>
|
|
176
|
+
Call Tool inside a widget
|
|
177
|
+
</button>
|
|
178
|
+
</div>
|
|
179
|
+
);
|
|
180
|
+
};
|
|
181
|
+
```
|
|
182
|
+
|
|
183
|
+
## Migrate your existing MCP server to a ChatGPT app
|
|
184
|
+
|
|
185
|
+
If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
|
|
186
|
+
|
|
187
|
+
1. Replace your `McpServer` import from `@modelcontextprotocol/sdk` with the same import from `skybridge/server`
|
|
188
|
+
2. Create a new vite project in a folder named `web` and install the `skybridge` package
|
|
189
|
+
3. Replace the `vite.config.ts` file with the following:
|
|
190
|
+
|
|
191
|
+
```ts
|
|
192
|
+
import { defineConfig } from "vite";
|
|
193
|
+
import { skybridge } from "skybridge/web";
|
|
194
|
+
|
|
195
|
+
export default defineConfig({
|
|
196
|
+
plugins: [skybridge()],
|
|
197
|
+
});
|
|
198
|
+
```
|
package/dist/src/server/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
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
|
+
{"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,5 +1,7 @@
|
|
|
1
1
|
import { McpServer as McpServerBase, } from "@modelcontextprotocol/sdk/server/mcp.js";
|
|
2
2
|
import { templateHelper } from "./templateHelper.js";
|
|
3
|
+
import { readFileSync } from "node:fs";
|
|
4
|
+
import path from "node:path";
|
|
3
5
|
export class McpServer extends McpServerBase {
|
|
4
6
|
widget(name, resourceConfig, toolConfig, toolCallback) {
|
|
5
7
|
const uri = `ui://widgets/${name}.html`;
|
|
@@ -12,23 +14,25 @@ export class McpServer extends McpServerBase {
|
|
|
12
14
|
_meta: resourceMetadata,
|
|
13
15
|
}, async (_uri, extra) => {
|
|
14
16
|
const serverUrl = process.env.NODE_ENV === "production"
|
|
15
|
-
? `https://${extra?.requestInfo?.headers?.host
|
|
17
|
+
? `https://${extra?.requestInfo?.headers?.["x-forwarded-host"] ??
|
|
18
|
+
extra?.requestInfo?.headers?.host}`
|
|
16
19
|
: `http://localhost:3000`;
|
|
17
|
-
const templateData = {
|
|
18
|
-
serverUrl,
|
|
19
|
-
widgetName: name,
|
|
20
|
-
};
|
|
21
20
|
const html = process.env.NODE_ENV === "production"
|
|
22
|
-
? templateHelper.renderProduction(
|
|
23
|
-
|
|
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
|
+
});
|
|
24
30
|
return {
|
|
25
31
|
contents: [
|
|
26
32
|
{
|
|
27
33
|
uri,
|
|
28
34
|
mimeType: "text/html+skybridge",
|
|
29
|
-
text:
|
|
30
|
-
? html
|
|
31
|
-
: templateHelper.injectViteClient(html, templateData),
|
|
35
|
+
text: html,
|
|
32
36
|
},
|
|
33
37
|
],
|
|
34
38
|
};
|
|
@@ -42,5 +46,9 @@ export class McpServer extends McpServerBase {
|
|
|
42
46
|
_meta: toolMeta,
|
|
43
47
|
}, toolCallback);
|
|
44
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
|
+
}
|
|
45
53
|
}
|
|
46
54
|
//# sourceMappingURL=server.js.map
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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,OAAO,SAAU,SAAQ,aAAa;IAC1C,MAAM,CACJ,IAAY,EACZ,cAA+C,EAC/C,UAGC,EACD,YAAqC;QAErC,MAAM,GAAG,GAAG,gBAAgB,IAAI,OAAO,CAAC;QACxC,MAAM,gBAAgB,GAAiB,EAAE,GAAG,CAAC,cAAc,CAAC,KAAK,IAAI,EAAE,CAAC,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,YAAY,CACb,CAAC;IACJ,CAAC;IAEO,cAAc,CAAC,GAAW;QAChC,MAAM,QAAQ,GAAG,IAAI,CAAC,KAAK,CACzB,YAAY,CACV,IAAI,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,eAAe,CAAC,EACpE,OAAO,CACR,CACF,CAAC;QAEF,OAAO,QAAQ,CAAC,GAAG,CAAC,EAAE,IAAI,CAAC;IAC7B,CAAC;CACF"}
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
-
type TemplateData = {
|
|
2
|
-
serverUrl: string;
|
|
3
|
-
widgetName: string;
|
|
4
|
-
};
|
|
5
1
|
declare class TemplateHelper {
|
|
6
2
|
private templateCache;
|
|
7
3
|
private loadTemplate;
|
|
8
|
-
renderProduction(data:
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
4
|
+
renderProduction(data: {
|
|
5
|
+
serverUrl: string;
|
|
6
|
+
widgetFile: string;
|
|
7
|
+
styleFile: string;
|
|
8
|
+
}): string;
|
|
9
|
+
renderDevelopment(data: {
|
|
10
|
+
serverUrl: string;
|
|
11
|
+
widgetName: string;
|
|
12
|
+
}): string;
|
|
12
13
|
}
|
|
13
14
|
export declare const templateHelper: TemplateHelper;
|
|
14
15
|
export {};
|
|
@@ -24,14 +24,6 @@ class TemplateHelper {
|
|
|
24
24
|
const template = this.loadTemplate("development");
|
|
25
25
|
return template(data);
|
|
26
26
|
}
|
|
27
|
-
renderViteClient(data) {
|
|
28
|
-
const template = this.loadTemplate("vite-client");
|
|
29
|
-
return template(data);
|
|
30
|
-
}
|
|
31
|
-
injectViteClient(html, data) {
|
|
32
|
-
const viteClientScript = this.renderViteClient(data);
|
|
33
|
-
return viteClientScript + html;
|
|
34
|
-
}
|
|
35
27
|
}
|
|
36
28
|
export const templateHelper = new TemplateHelper();
|
|
37
29
|
//# sourceMappingURL=templateHelper.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC1C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAEzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AAOtC,MAAM,cAAc;IACV,aAAa,GAAG,IAAI,GAAG,EAAsC,CAAC;IAE9D,YAAY,CAAC,YAAoB;QACvC,IAAI,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAC,EAAE,CAAC;YACzC,OAAO,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,CAAE,CAAC;QAC/C,CAAC;QAED,MAAM,YAAY,GAAG,IAAI,CAAC,SAAS,EAAE,WAAW,EAAE,GAAG,YAAY,MAAM,CAAC,CAAC;QACzE,MAAM,cAAc,GAAG,YAAY,CAAC,YAAY,EAAE,OAAO,CAAC,CAAC;QAC3D,MAAM,QAAQ,GAAG,UAAU,CAAC,OAAO,CAAC,cAAc,CAAC,CAAC;QAEpD,IAAI,CAAC,aAAa,CAAC,GAAG,CAAC,YAAY,EAAE,QAAQ,CAAC,CAAC;QAC/C,OAAO,QAAQ,CAAC;IAClB,CAAC;IAED,gBAAgB,CAAC,
|
|
1
|
+
{"version":3,"file":"templateHelper.js","sourceRoot":"","sources":["../../../src/server/templateHelper.ts"],"names":[],"mappings":"AAAA,OAAO,UAAU,MAAM,YAAY,CAAC;AACpC,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;A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{{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,9 +1,12 @@
|
|
|
1
1
|
import { type RequestHandler } from "express";
|
|
2
2
|
/**
|
|
3
|
-
* Install Vite dev server
|
|
3
|
+
* Install Vite dev server
|
|
4
4
|
* This router MUST be installed at the application root, like so:
|
|
5
5
|
*
|
|
6
6
|
* const app = express();
|
|
7
|
-
*
|
|
7
|
+
*
|
|
8
|
+
* if (env.NODE_ENV !== "production") {
|
|
9
|
+
* app.use(await widgetsRouter());
|
|
10
|
+
* }
|
|
8
11
|
*/
|
|
9
12
|
export declare const widgetsDevServer: () => Promise<RequestHandler>;
|
|
@@ -2,11 +2,14 @@ import express, {} from "express";
|
|
|
2
2
|
import cors from "cors";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
/**
|
|
5
|
-
* Install Vite dev server
|
|
5
|
+
* Install Vite dev server
|
|
6
6
|
* This router MUST be installed at the application root, like so:
|
|
7
7
|
*
|
|
8
8
|
* const app = express();
|
|
9
|
-
*
|
|
9
|
+
*
|
|
10
|
+
* if (env.NODE_ENV !== "production") {
|
|
11
|
+
* app.use(await widgetsRouter());
|
|
12
|
+
* }
|
|
10
13
|
*/
|
|
11
14
|
export const widgetsDevServer = async () => {
|
|
12
15
|
const router = express.Router();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widgetsDevServer.js","sourceRoot":"","sources":["../../../src/server/widgetsDevServer.ts"],"names":[],"mappings":"AAAA,OAAO,OAAO,EAAE,EAAuB,MAAM,SAA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AAO,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"}
|
|
@@ -1,15 +1,33 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as fs from "node:fs";
|
|
2
|
+
import { afterEach, beforeEach, describe, expect, it, vi, } from "vitest";
|
|
2
3
|
import { McpServer } from "../server/server.js";
|
|
3
|
-
import { createMockMcpServer,
|
|
4
|
+
import { createMockExtra, createMockMcpServer, resetTestEnv, setTestEnv, } from "./utils.js";
|
|
5
|
+
const mockManifest = {
|
|
6
|
+
"src/widgets/my-widget.tsx": { file: "my-widget.js" },
|
|
7
|
+
"style.css": { file: "style.css" },
|
|
8
|
+
};
|
|
9
|
+
vi.mock("node:fs", async () => {
|
|
10
|
+
const actual = await vi.importActual("node:fs");
|
|
11
|
+
const readFileSync = vi.fn((path, ...args) => {
|
|
12
|
+
if (typeof path === "string" && path.includes("manifest.json")) {
|
|
13
|
+
return JSON.stringify(mockManifest);
|
|
14
|
+
}
|
|
15
|
+
return actual.readFileSync(path, ...args);
|
|
16
|
+
});
|
|
17
|
+
return {
|
|
18
|
+
readFileSync,
|
|
19
|
+
default: {
|
|
20
|
+
readFileSync,
|
|
21
|
+
},
|
|
22
|
+
};
|
|
23
|
+
});
|
|
4
24
|
describe("McpServer.widget", () => {
|
|
5
25
|
let server;
|
|
6
26
|
let mockResource;
|
|
7
27
|
let mockRegisterTool;
|
|
28
|
+
let readFileSyncSpy = null;
|
|
8
29
|
beforeEach(() => {
|
|
9
|
-
|
|
10
|
-
server = mock.server;
|
|
11
|
-
mockResource = mock.mockResource;
|
|
12
|
-
mockRegisterTool = mock.mockRegisterTool;
|
|
30
|
+
({ server, mockResource, mockRegisterTool } = createMockMcpServer());
|
|
13
31
|
});
|
|
14
32
|
afterEach(() => {
|
|
15
33
|
vi.clearAllMocks();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,QAAQ,EACR,
|
|
1
|
+
{"version":3,"file":"widget.test.js","sourceRoot":"","sources":["../../../src/test/widget.test.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,SAAS,CAAC;AAC9B,OAAO,EACL,SAAS,EACT,UAAU,EACV,QAAQ,EACR,MAAM,EACN,EAAE,EACF,EAAE,GAEH,MAAM,QAAQ,CAAC;AAChB,OAAO,EAAE,SAAS,EAAE,MAAM,qBAAqB,CAAC;AAChD,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,WAAW,EAAE,EAAE,IAAI,EAAE,WAAW,EAAE;CACnC,CAAC;AAEF,EAAE,CAAC,IAAI,CAAC,SAAS,EAAE,KAAK,IAAI,EAAE;IAC5B,MAAM,MAAM,GAAG,MAAM,EAAE,CAAC,YAAY,CAA2B,SAAS,CAAC,CAAC;IAC1E,MAAM,YAAY,GAAG,EAAE,CAAC,EAAE,CAAC,CAAC,IAAY,EAAE,GAAG,IAAW,EAAE,EAAE;QAC1D,IAAI,OAAO,IAAI,KAAK,QAAQ,IAAI,IAAI,CAAC,QAAQ,CAAC,eAAe,CAAC,EAAE,CAAC;YAC/D,OAAO,IAAI,CAAC,SAAS,CAAC,YAAY,CAAC,CAAC;QACtC,CAAC;QACD,OAAO,MAAM,CAAC,YAAY,CAAC,IAAI,EAAE,GAAG,IAAI,CAAC,CAAC;IAC5C,CAAC,CAAC,CAAC;IAEH,OAAO;QACL,YAAY;QACZ,OAAO,EAAE;YACP,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e,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"}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useLocale } from "./use-locale.js";
|
|
4
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
5
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useTheme } from "./use-theme.js";
|
|
9
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
10
|
+
export { useToolOutput } from "./use-tool-output.js";
|
|
11
|
+
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
12
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
13
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export { useCallTool } from "./use-call-tool.js";
|
|
2
|
+
export { useDisplayMode } from "./use-display-mode.js";
|
|
3
|
+
export { useLocale } from "./use-locale.js";
|
|
4
|
+
export { useOpenExternal } from "./use-open-external.js";
|
|
5
|
+
export { useOpenAiGlobal } from "./use-openai-global.js";
|
|
6
|
+
export { useRequestModal } from "./use-request-modal.js";
|
|
7
|
+
export { useSendFollowUpMessage } from "./use-send-follow-up-message.js";
|
|
8
|
+
export { useTheme } from "./use-theme.js";
|
|
9
|
+
export { useToolInfo } from "./use-tool-info.js";
|
|
10
|
+
export { useToolOutput } from "./use-tool-output.js";
|
|
11
|
+
export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
|
|
12
|
+
export { useUserAgent } from "./use-user-agent.js";
|
|
13
|
+
export { useWidgetState } from "./use-widget-state.js";
|
|
14
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../../../src/web/hooks/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC;AACvD,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAC5C,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AACzD,OAAO,EAAE,sBAAsB,EAAE,MAAM,iCAAiC,CAAC;AACzE,OAAO,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAC;AAC1C,OAAO,EAAE,WAAW,EAAE,MAAM,oBAAoB,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,sBAAsB,CAAC;AACrD,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,OAAO,EAAE,YAAY,EAAE,MAAM,qBAAqB,CAAC;AACnD,OAAO,EAAE,cAAc,EAAE,MAAM,uBAAuB,CAAC"}
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import type { CallToolArgs, CallToolResponse, CallToolResponseConstraint } from "../types.js";
|
|
2
|
+
export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponseConstraint = CallToolResponse>(name: string) => {
|
|
3
|
+
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
4
|
+
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
5
|
+
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
6
|
+
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
7
|
+
}) => void;
|
|
8
|
+
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
9
|
+
status: "idle";
|
|
10
|
+
isIdle: true;
|
|
11
|
+
isPending: false;
|
|
12
|
+
isSuccess: false;
|
|
13
|
+
isError: false;
|
|
14
|
+
data: undefined;
|
|
15
|
+
error: undefined;
|
|
16
|
+
} | {
|
|
17
|
+
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
18
|
+
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
19
|
+
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
20
|
+
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
21
|
+
}) => void;
|
|
22
|
+
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
23
|
+
status: "pending";
|
|
24
|
+
isIdle: false;
|
|
25
|
+
isPending: true;
|
|
26
|
+
isSuccess: false;
|
|
27
|
+
isError: false;
|
|
28
|
+
data: undefined;
|
|
29
|
+
error: undefined;
|
|
30
|
+
} | {
|
|
31
|
+
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
32
|
+
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
33
|
+
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
34
|
+
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
35
|
+
}) => void;
|
|
36
|
+
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
37
|
+
status: "error";
|
|
38
|
+
isIdle: false;
|
|
39
|
+
isPending: false;
|
|
40
|
+
isSuccess: false;
|
|
41
|
+
isError: true;
|
|
42
|
+
data: undefined;
|
|
43
|
+
error: unknown;
|
|
44
|
+
} | {
|
|
45
|
+
callTool: (toolArgs: ToolArgs, sideEffects?: {
|
|
46
|
+
onSuccess?: (data: ToolResponse, toolArgs: ToolArgs) => void;
|
|
47
|
+
onError?: (error: unknown, toolArgs: ToolArgs) => void;
|
|
48
|
+
onSettled?: (data: ToolResponse | undefined, error: unknown | undefined, toolArgs: ToolArgs) => void;
|
|
49
|
+
}) => void;
|
|
50
|
+
callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse>;
|
|
51
|
+
status: "success";
|
|
52
|
+
isIdle: false;
|
|
53
|
+
isPending: false;
|
|
54
|
+
isSuccess: true;
|
|
55
|
+
isError: false;
|
|
56
|
+
data: ToolResponse;
|
|
57
|
+
error: undefined;
|
|
58
|
+
};
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { useState } from "react";
|
|
2
|
+
export const useCallTool = (name) => {
|
|
3
|
+
const [{ status, data, error }, setCallToolState] = useState({ status: "idle", data: undefined, error: undefined });
|
|
4
|
+
const callToolAsync = async (toolArgs) => {
|
|
5
|
+
setCallToolState({ status: "pending", data: undefined, error: undefined });
|
|
6
|
+
try {
|
|
7
|
+
const data = await window.openai.callTool(name, toolArgs);
|
|
8
|
+
setCallToolState({ status: "success", data, error: undefined });
|
|
9
|
+
return data;
|
|
10
|
+
}
|
|
11
|
+
catch (error) {
|
|
12
|
+
setCallToolState({ status: "error", data: undefined, error });
|
|
13
|
+
throw error;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
const callTool = (toolArgs, sideEffects) => {
|
|
17
|
+
callToolAsync(toolArgs)
|
|
18
|
+
.then((data) => {
|
|
19
|
+
if (sideEffects?.onSuccess) {
|
|
20
|
+
sideEffects.onSuccess(data, toolArgs);
|
|
21
|
+
}
|
|
22
|
+
if (sideEffects?.onSettled) {
|
|
23
|
+
sideEffects.onSettled(data, undefined, toolArgs);
|
|
24
|
+
}
|
|
25
|
+
})
|
|
26
|
+
.catch((error) => {
|
|
27
|
+
if (sideEffects?.onError) {
|
|
28
|
+
sideEffects.onError(error, toolArgs);
|
|
29
|
+
}
|
|
30
|
+
if (sideEffects?.onSettled) {
|
|
31
|
+
sideEffects.onSettled(undefined, error, toolArgs);
|
|
32
|
+
}
|
|
33
|
+
});
|
|
34
|
+
};
|
|
35
|
+
const callToolState = {
|
|
36
|
+
status,
|
|
37
|
+
data,
|
|
38
|
+
error,
|
|
39
|
+
isIdle: status === "idle",
|
|
40
|
+
isPending: status === "pending",
|
|
41
|
+
isSuccess: status === "success",
|
|
42
|
+
isError: status === "error",
|
|
43
|
+
};
|
|
44
|
+
return {
|
|
45
|
+
...callToolState,
|
|
46
|
+
callTool,
|
|
47
|
+
callToolAsync,
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
//# sourceMappingURL=use-call-tool.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../../src/web/hooks/use-call-tool.ts"],"names":[],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