skybridge 0.0.0-dev.3b1b0b4 → 0.0.0-dev.4eb7532

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 CHANGED
@@ -27,6 +27,53 @@ To get started in less than a minute, you can [create a new repository](https://
27
27
  pnpm add skybridge
28
28
  ```
29
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
+
30
77
  ## Packages
31
78
 
32
79
  ### skybridge/server
@@ -50,9 +97,30 @@ export default defineConfig({
50
97
  });
51
98
  ```
52
99
 
100
+ **Hooks**
101
+
102
+ The `skybridge/web` package comes with a set of hooks to help you build your widgets.
103
+
104
+ ```ts
105
+ import { useToolOutput } from "skybridge/web";
106
+
107
+ // Initial data returned by the tool invocation on structuredOutput
108
+ const toolOutput = useToolOutput();
109
+ ```
110
+
53
111
  ## Migrate your existing MCP server to a ChatGPT app
54
112
 
55
113
  If you're already using the `@modelcontextprotocol/sdk` to build a MCP server, you can migrate to a ChatGPT app by following these steps:
56
114
 
57
115
  1. Replace your `McpServer` import from `@modelcontextprotocol/sdk` with the same import from `skybridge/server`
58
- 2. Create a new node project named `web` and install the `skybridge` package
116
+ 2. Create a new vite project in a folder named `web` and install the `skybridge` package
117
+ 3. Replace the `vite.config.ts` file with the following:
118
+
119
+ ```ts
120
+ import { defineConfig } from "vite";
121
+ import { skybridge } from "skybridge/web";
122
+
123
+ export default defineConfig({
124
+ plugins: [skybridge()],
125
+ });
126
+ ```
@@ -0,0 +1,11 @@
1
+ <script type="module">
2
+ import { injectIntoGlobalHook } from "{{serverUrl}}/@react-refresh";
3
+ injectIntoGlobalHook(window); window.$RefreshReg$ = () => {};
4
+ window.$RefreshSig$ = () => (type) => type;
5
+ window.__vite_plugin_react_preamble_installed__ = true;
6
+ </script>
7
+ <script type="module" src="{{serverUrl}}/@vite/client"></script>
8
+ <div id="root"></div>
9
+ <script type="module">
10
+ import('{{serverUrl}}/src/widgets/{{widgetName}}.tsx');
11
+ </script>
@@ -0,0 +1,5 @@
1
+ <div id="root"></div>
2
+ <script type="module">
3
+ import('{{serverUrl}}/assets/{{widgetName}}.js');
4
+ </script>
5
+ <link rel="stylesheet" crossorigin href="{{serverUrl}}/assets/style.css" />
@@ -1,4 +1,6 @@
1
1
  export { useOpenAiGlobal } from "./use-openai-global.js";
2
2
  export { useToolOutput } from "./use-tool-output.js";
3
+ export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
3
4
  export * from "./types.js";
4
5
  export { mountWidget } from "./mount-widget.js";
6
+ export { skybridge } from "./plugin.js";
@@ -1,5 +1,7 @@
1
1
  export { useOpenAiGlobal } from "./use-openai-global.js";
2
2
  export { useToolOutput } from "./use-tool-output.js";
3
+ export { useToolResponseMetadata } from "./use-tool-response-metadata.js";
3
4
  export * from "./types.js";
4
5
  export { mountWidget } from "./mount-widget.js";
6
+ export { skybridge } from "./plugin.js";
5
7
  //# sourceMappingURL=index.js.map
@@ -1 +1 @@
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"}
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,OAAO,EAAE,uBAAuB,EAAE,MAAM,iCAAiC,CAAC;AAC1E,cAAc,YAAY,CAAC;AAC3B,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAC;AAChD,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC"}
@@ -0,0 +1,2 @@
1
+ import type { Plugin } from "vite";
2
+ export declare function skybridge(): Plugin;
@@ -0,0 +1,30 @@
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
+ build: {
16
+ minify: true,
17
+ cssCodeSplit: false,
18
+ rollupOptions: {
19
+ input,
20
+ output: {
21
+ entryFileNames: "[name].js",
22
+ assetFileNames: "[name][extname]",
23
+ },
24
+ },
25
+ },
26
+ };
27
+ },
28
+ };
29
+ }
30
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
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,KAAK,EAAE;oBACL,MAAM,EAAE,IAAI;oBACZ,YAAY,EAAE,KAAK;oBACnB,aAAa,EAAE;wBACb,KAAK;wBACL,MAAM,EAAE;4BACN,cAAc,EAAE,WAAW;4BAC3B,cAAc,EAAE,iBAAiB;yBAClC;qBACF;iBACF;aACF,CAAC;QACJ,CAAC;KACF,CAAC;AACJ,CAAC"}
@@ -38,12 +38,20 @@ export type OpenAiGlobals<ToolInput extends UnknownObject = UnknownObject, ToolO
38
38
  toolResponseMetadata: ToolResponseMetadata | null;
39
39
  widgetState: WidgetState | null;
40
40
  };
41
+ export type CallToolArgs = Record<string, unknown> | null;
41
42
  export type CallToolResponse = {
43
+ content: {
44
+ type: "text";
45
+ text: string;
46
+ }[];
47
+ structuredContent: Record<string, unknown>;
48
+ isError: boolean;
42
49
  result: string;
50
+ meta: Record<string, unknown>;
43
51
  };
44
52
  type API<WidgetState extends UnknownObject> = {
45
53
  /** Calls a tool on your MCP. Returns the full response. */
46
- callTool: (name: string, args: Record<string, unknown>) => Promise<CallToolResponse>;
54
+ callTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string, args: ToolArgs) => Promise<ToolResponse>;
47
55
  /** Triggers a followup turn in the ChatGPT conversation */
48
56
  sendFollowUpMessage: (args: {
49
57
  prompt: string;
@@ -1 +1 @@
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
+ {"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;AA2ED,sDAAsD;AACtD,MAAM,CAAC,MAAM,sBAAsB,GAAG,oBAAoB,CAAC;AAC3D,MAAM,OAAO,eAAgB,SAAQ,WAEnC;IACkB,IAAI,GAAG,sBAAsB,CAAC;CACjD"}
@@ -0,0 +1,39 @@
1
+ import type { CallToolArgs, CallToolResponse } from "./types.js";
2
+ export declare const useCallTool: <ToolArgs extends CallToolArgs = null, ToolResponse extends CallToolResponse = CallToolResponse>(name: string) => {
3
+ callTool: (toolArgs: ToolArgs) => void;
4
+ callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse | undefined>;
5
+ status: "idle";
6
+ response: undefined;
7
+ isIdle: true;
8
+ isPending: false;
9
+ isSuccess: false;
10
+ isError: false;
11
+ } | {
12
+ callTool: (toolArgs: ToolArgs) => void;
13
+ callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse | undefined>;
14
+ status: "pending";
15
+ response: undefined;
16
+ isIdle: false;
17
+ isPending: true;
18
+ isSuccess: false;
19
+ isError: false;
20
+ } | {
21
+ callTool: (toolArgs: ToolArgs) => void;
22
+ callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse | undefined>;
23
+ status: "error";
24
+ error: unknown;
25
+ response: undefined;
26
+ isIdle: false;
27
+ isPending: false;
28
+ isSuccess: false;
29
+ isError: true;
30
+ } | {
31
+ callTool: (toolArgs: ToolArgs) => void;
32
+ callToolAsync: (toolArgs: ToolArgs) => Promise<ToolResponse | undefined>;
33
+ status: "success";
34
+ response: ToolResponse;
35
+ isIdle: false;
36
+ isPending: false;
37
+ isSuccess: true;
38
+ isError: false;
39
+ };
@@ -0,0 +1,53 @@
1
+ import { useState } from "react";
2
+ export const useCallTool = (name) => {
3
+ const [callToolState, setCallToolState] = useState({
4
+ status: "idle",
5
+ response: undefined,
6
+ isIdle: true,
7
+ isPending: false,
8
+ isSuccess: false,
9
+ isError: false,
10
+ });
11
+ const callToolAsync = async (toolArgs) => {
12
+ setCallToolState({
13
+ status: "pending",
14
+ response: undefined,
15
+ isIdle: false,
16
+ isPending: true,
17
+ isSuccess: false,
18
+ isError: false,
19
+ });
20
+ try {
21
+ const response = await window.openai.callTool(name, toolArgs);
22
+ setCallToolState({
23
+ status: "success",
24
+ response,
25
+ isIdle: false,
26
+ isPending: false,
27
+ isSuccess: true,
28
+ isError: false,
29
+ });
30
+ return response;
31
+ }
32
+ catch (error) {
33
+ setCallToolState({
34
+ status: "error",
35
+ response: undefined,
36
+ error,
37
+ isIdle: false,
38
+ isPending: false,
39
+ isSuccess: false,
40
+ isError: true,
41
+ });
42
+ }
43
+ };
44
+ const callTool = (toolArgs) => {
45
+ void callToolAsync(toolArgs);
46
+ };
47
+ return {
48
+ ...callToolState,
49
+ callTool,
50
+ callToolAsync,
51
+ };
52
+ };
53
+ //# sourceMappingURL=use-call-tool.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-call-tool.js","sourceRoot":"","sources":["../../../src/web/use-call-tool.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AA4CjC,MAAM,CAAC,MAAM,WAAW,GAAG,CAIzB,IAAY,EACZ,EAAE;IACF,MAAM,CAAC,aAAa,EAAE,gBAAgB,CAAC,GAAG,QAAQ,CAEhD;QACA,MAAM,EAAE,MAAM;QACd,QAAQ,EAAE,SAAS;QACnB,MAAM,EAAE,IAAI;QACZ,SAAS,EAAE,KAAK;QAChB,SAAS,EAAE,KAAK;QAChB,OAAO,EAAE,KAAK;KACf,CAAC,CAAC;IAEH,MAAM,aAAa,GAAG,KAAK,EAAE,QAAkB,EAAE,EAAE;QACjD,gBAAgB,CAAC;YACf,MAAM,EAAE,SAAS;YACjB,QAAQ,EAAE,SAAS;YACnB,MAAM,EAAE,KAAK;YACb,SAAS,EAAE,IAAI;YACf,SAAS,EAAE,KAAK;YAChB,OAAO,EAAE,KAAK;SACf,CAAC,CAAC;QACH,IAAI,CAAC;YACH,MAAM,QAAQ,GAAG,MAAM,MAAM,CAAC,MAAM,CAAC,QAAQ,CAC3C,IAAI,EACJ,QAAQ,CACT,CAAC;YACF,gBAAgB,CAAC;gBACf,MAAM,EAAE,SAAS;gBACjB,QAAQ;gBACR,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,KAAK;gBAChB,SAAS,EAAE,IAAI;gBACf,OAAO,EAAE,KAAK;aACf,CAAC,CAAC;YAEH,OAAO,QAAQ,CAAC;QAClB,CAAC;QAAC,OAAO,KAAK,EAAE,CAAC;YACf,gBAAgB,CAAC;gBACf,MAAM,EAAE,OAAO;gBACf,QAAQ,EAAE,SAAS;gBACnB,KAAK;gBACL,MAAM,EAAE,KAAK;gBACb,SAAS,EAAE,KAAK;gBAChB,SAAS,EAAE,KAAK;gBAChB,OAAO,EAAE,IAAI;aACd,CAAC,CAAC;QACL,CAAC;IACH,CAAC,CAAC;IAEF,MAAM,QAAQ,GAAG,CAAC,QAAkB,EAAE,EAAE;QACtC,KAAK,aAAa,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC,CAAC;IAEF,OAAO;QACL,GAAG,aAAa;QAChB,QAAQ;QACR,aAAa;KACd,CAAC;AACJ,CAAC,CAAC"}
@@ -0,0 +1,3 @@
1
+ export declare function useToolResponseMetadata(): {
2
+ [x: string]: unknown;
3
+ } | null | undefined;
@@ -0,0 +1,5 @@
1
+ import { useOpenAiGlobal } from "./use-openai-global.js";
2
+ export function useToolResponseMetadata() {
3
+ return useOpenAiGlobal("toolResponseMetadata");
4
+ }
5
+ //# sourceMappingURL=use-tool-response-metadata.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"use-tool-response-metadata.js","sourceRoot":"","sources":["../../../src/web/use-tool-response-metadata.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAC;AAEzD,MAAM,UAAU,uBAAuB;IACrC,OAAO,eAAe,CAAC,sBAAsB,CAAC,CAAC;AACjD,CAAC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "skybridge",
3
- "version": "0.0.0-dev.3b1b0b4",
3
+ "version": "0.0.0-dev.4eb7532",
4
4
  "description": "Skybridge is a framework for building ChatGPT apps",
5
5
  "type": "module",
6
6
  "files": [
@@ -17,7 +17,8 @@
17
17
  }
18
18
  },
19
19
  "scripts": {
20
- "build": "tsc",
20
+ "build": "tsc && pnpm run build:templates",
21
+ "build:templates": "cp -r src/server/templates dist/src/server/",
21
22
  "test": "vitest run --silent"
22
23
  },
23
24
  "keywords": [
@@ -44,10 +45,10 @@
44
45
  "@total-typescript/tsconfig": "^1.0.4",
45
46
  "@types/cors": "^2.8.19",
46
47
  "@types/express": "^5.0.3",
48
+ "@types/jsdom": "^21.1.6",
47
49
  "@types/node": "^22.15.30",
48
50
  "@types/react": "^19.2.2",
49
51
  "@types/react-dom": "^19.2.2",
50
- "@types/jsdom": "^21.1.6",
51
52
  "@vitest/ui": "^2.1.8",
52
53
  "jsdom": "^25.0.1",
53
54
  "typescript": "^5.9.3",