create-skybridge 0.0.0-dev.e0ed208 → 0.0.0-dev.e38035c

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.
Files changed (42) hide show
  1. package/LICENSE +21 -0
  2. package/dist/index.js +124 -18
  3. package/package.json +12 -13
  4. package/template/README.md +13 -2
  5. package/template/node_modules/.bin/mcp-inspector +21 -0
  6. package/template/node_modules/.bin/nodemon +21 -0
  7. package/template/node_modules/.bin/shx +21 -0
  8. package/template/node_modules/.bin/tsc +21 -0
  9. package/template/node_modules/.bin/tsserver +21 -0
  10. package/template/node_modules/.bin/tsx +21 -0
  11. package/template/node_modules/.bin/vite +21 -0
  12. package/template/nodemon.json +5 -0
  13. package/template/package.json +31 -10
  14. package/template/server/src/index.ts +6 -2
  15. package/template/server/src/server.ts +0 -5
  16. package/template/tsconfig.json +23 -0
  17. package/template/tsconfig.server.json +11 -0
  18. package/template/web/src/index.css +1 -0
  19. package/template/web/src/widgets/magic-8-ball.tsx +3 -1
  20. package/template/web/vite.config.ts +1 -1
  21. package/template-ecom/README.md +89 -0
  22. package/template-ecom/alpic.json +4 -0
  23. package/template-ecom/nodemon.json +5 -0
  24. package/template-ecom/package.json +40 -0
  25. package/template-ecom/server/src/index.ts +39 -0
  26. package/template-ecom/server/src/middleware.ts +54 -0
  27. package/template-ecom/server/src/server.ts +73 -0
  28. package/template-ecom/tsconfig.json +23 -0
  29. package/template-ecom/tsconfig.server.json +11 -0
  30. package/template-ecom/web/src/helpers.ts +4 -0
  31. package/template-ecom/web/src/index.css +194 -0
  32. package/template-ecom/web/src/widgets/ecom-carousel.tsx +181 -0
  33. package/template-ecom/web/vite.config.ts +15 -0
  34. package/template/_gitignore +0 -4
  35. package/template/pnpm-workspace.yaml +0 -7
  36. package/template/server/nodemon.json +0 -5
  37. package/template/server/package.json +0 -32
  38. package/template/server/tsconfig.json +0 -17
  39. package/template/web/package.json +0 -24
  40. package/template/web/tsconfig.app.json +0 -34
  41. package/template/web/tsconfig.json +0 -13
  42. package/template/web/tsconfig.node.json +0 -26
@@ -0,0 +1,89 @@
1
+ # Ecommerce Carousel Example
2
+
3
+ ## What This Example Showcases
4
+ This "Ecommerce Carousel" example demonstrates key Skybridge capabilities:
5
+ - **Interactive Widget Rendering**: A React-based widget that displays an interactive product carousel directly in ChatGPT
6
+ - **Tool Info Access**: Widgets access tool input, output, and metadata via `useToolInfo()` hook
7
+ - **Theme Support**: Adapts to light/dark mode using the `useLayout()` hook
8
+ - **Localization**: Translates UI based on user locale via `useUser()` hook
9
+ - **Persistent State**: Maintains cart state across re-renders using `useWidgetState()` hook
10
+ - **Modal Dialogs**: Opens checkout modal via `useRequestModal()` hook
11
+ - **External Links**: Opens external URL for checkout completion via `useOpenExternal()` hook
12
+ - **External API Integration**: Demonstrates fetching data from REST APIs
13
+ - **Hot Module Replacement**: Live reloading of widget components during development
14
+
15
+ This example serves as a comprehensive reference for building sophisticated, interactive widgets that leverage Skybridge's full feature set.
16
+
17
+ ## Getting Started
18
+
19
+ ### Prerequisites
20
+
21
+ - Node.js 22+
22
+ - HTTP tunnel such as [ngrok](https://ngrok.com/download)
23
+
24
+ ### Local Development
25
+
26
+ #### 1. Install
27
+
28
+ ```bash
29
+ npm install
30
+ # or
31
+ yarn install
32
+ # or
33
+ pnpm install
34
+ # or
35
+ bun install
36
+ ```
37
+
38
+ #### 2. Start your local server
39
+
40
+ Run the development server from the root directory:
41
+
42
+ ```bash
43
+ npm run dev
44
+ # or
45
+ yarn dev
46
+ # or
47
+ pnpm dev
48
+ # or
49
+ bun dev
50
+ ```
51
+
52
+ This command starts an Express server on port 3000. This server packages:
53
+
54
+ - an MCP endpoint on `/mcp` (the app backend)
55
+ - a React application on Vite HMR dev server (the UI elements to be displayed in ChatGPT)
56
+
57
+ #### 3. Connect to ChatGPT
58
+
59
+ - ChatGPT requires connectors to be publicly accessible. To expose your server on the Internet, run:
60
+ ```bash
61
+ ngrok http 3000
62
+ ```
63
+ - In ChatGPT, navigate to **Settings → Connectors → Create** and add the forwarding URL provided by ngrok suffixed with `/mcp` (e.g. `https://3785c5ddc4b6.ngrok-free.app/mcp`)
64
+
65
+ ### Create your first widget
66
+
67
+ #### 1. Add a new widget
68
+
69
+ - Register a widget in `server/server.ts` with a unique name (e.g., `my-widget`)
70
+ - Create a matching React component at `web/src/widgets/my-widget.tsx`. The file name must match the widget name exactly
71
+
72
+ #### 2. Edit widgets with Hot Module Replacement (HMR)
73
+
74
+ Edit and save components in `web/src/widgets/` — changes appear instantly in ChatGPT
75
+
76
+ #### 3. Edit server code
77
+
78
+ Modify files in `server/` and reload your ChatGPT connector in **Settings → Connectors → [Your connector] → Reload**
79
+
80
+ ## Deploy to Production
81
+
82
+ - Use [Alpic](https://alpic.ai/) to deploy your OpenAI App to production
83
+ - In ChatGPT, navigate to **Settings → Connectors → Create** and add your MCP server URL (e.g., `https://your-app-name.alpic.live`)
84
+
85
+ ## Resources
86
+
87
+ - [Apps SDK Documentation](https://developers.openai.com/apps-sdk)
88
+ - [Model Context Protocol Documentation](https://modelcontextprotocol.io/)
89
+ - [Alpic Documentation](https://docs.alpic.ai/)
@@ -0,0 +1,4 @@
1
+ {
2
+ "$schema": "https://assets.alpic.ai/alpic.json",
3
+ "buildOutputDir": "server/dist"
4
+ }
@@ -0,0 +1,5 @@
1
+ {
2
+ "watch": ["server/src"],
3
+ "ext": "ts,json",
4
+ "exec": "tsx server/src/index.ts"
5
+ }
@@ -0,0 +1,40 @@
1
+ {
2
+ "name": "ecom-carousel",
3
+ "version": "0.0.1",
4
+ "private": true,
5
+ "description": "An e-commerce carousel example",
6
+ "type": "module",
7
+ "scripts": {
8
+ "dev": "nodemon",
9
+ "build": "vite build -c web/vite.config.ts && shx rm -rf server/dist && tsc -p tsconfig.server.json && shx cp -r web/dist server/dist/assets",
10
+ "start": "node server/dist/index.js",
11
+ "inspector": "mcp-inspector http://localhost:3000/mcp",
12
+ "server:build": "tsc -p tsconfig.server.json",
13
+ "server:start": "node server/dist/index.js",
14
+ "web:build": "tsc -b web && vite build -c web/vite.config.ts",
15
+ "web:preview": "vite preview -c web/vite.config.ts"
16
+ },
17
+ "dependencies": {
18
+ "@modelcontextprotocol/sdk": "^1.25.1",
19
+ "express": "^5.2.1",
20
+ "react": "^19.2.3",
21
+ "react-dom": "^19.2.3",
22
+ "skybridge": ">=0.16.8 <1.0.0",
23
+ "vite": "^7.3.0",
24
+ "zod": "^4.3.5"
25
+ },
26
+ "devDependencies": {
27
+ "@modelcontextprotocol/inspector": "^0.18.0",
28
+ "@skybridge/devtools": "^0.16.2",
29
+ "@types/express": "^5.0.6",
30
+ "@types/node": "^22.19.3",
31
+ "@types/react": "^19.2.7",
32
+ "@types/react-dom": "^19.2.3",
33
+ "@vitejs/plugin-react": "^5.1.2",
34
+ "nodemon": "^3.1.11",
35
+ "shx": "^0.4.0",
36
+ "tsx": "^4.21.0",
37
+ "typescript": "^5.9.3"
38
+ },
39
+ "workspaces": []
40
+ }
@@ -0,0 +1,39 @@
1
+ import express, { type Express } from "express";
2
+ import { devtoolsStaticServer, widgetsDevServer } from "skybridge/server";
3
+ import type { ViteDevServer } from "vite";
4
+ import { mcp } from "./middleware.js";
5
+ import server from "./server.js";
6
+
7
+ const app = express() as Express & { vite: ViteDevServer };
8
+
9
+ app.use(express.json());
10
+
11
+ app.use(mcp(server));
12
+
13
+ const env = process.env.NODE_ENV || "development";
14
+
15
+ if (env !== "production") {
16
+ app.use(await devtoolsStaticServer());
17
+ app.use(await widgetsDevServer());
18
+ }
19
+
20
+ app.listen(3000, (error) => {
21
+ if (error) {
22
+ console.error("Failed to start server:", error);
23
+ process.exit(1);
24
+ }
25
+
26
+ console.log(`Server listening on port 3000 - ${env}`);
27
+ console.log(
28
+ "Make your local server accessible with 'ngrok http 3000' and connect to ChatGPT with URL https://xxxxxx.ngrok-free.app/mcp",
29
+ );
30
+
31
+ if (env !== "production") {
32
+ console.log("Devtools available at http://localhost:3000");
33
+ }
34
+ });
35
+
36
+ process.on("SIGINT", async () => {
37
+ console.log("Server shutdown complete");
38
+ process.exit(0);
39
+ });
@@ -0,0 +1,54 @@
1
+ import { StreamableHTTPServerTransport } from "@modelcontextprotocol/sdk/server/streamableHttp.js";
2
+ import type { NextFunction, Request, Response } from "express";
3
+
4
+ import type { McpServer } from "skybridge/server";
5
+
6
+ export const mcp =
7
+ (server: McpServer) =>
8
+ async (req: Request, res: Response, next: NextFunction) => {
9
+ // Only handle requests to the /mcp path
10
+ if (req.path !== "/mcp") {
11
+ return next();
12
+ }
13
+
14
+ if (req.method === "POST") {
15
+ try {
16
+ const transport = new StreamableHTTPServerTransport({
17
+ sessionIdGenerator: undefined,
18
+ });
19
+
20
+ res.on("close", () => {
21
+ transport.close();
22
+ });
23
+
24
+ await server.connect(transport);
25
+
26
+ await transport.handleRequest(req, res, req.body);
27
+ } catch (error) {
28
+ console.error("Error handling MCP request:", error);
29
+ if (!res.headersSent) {
30
+ res.status(500).json({
31
+ jsonrpc: "2.0",
32
+ error: {
33
+ code: -32603,
34
+ message: "Internal server error",
35
+ },
36
+ id: null,
37
+ });
38
+ }
39
+ }
40
+ } else if (req.method === "GET" || req.method === "DELETE") {
41
+ res.writeHead(405).end(
42
+ JSON.stringify({
43
+ jsonrpc: "2.0",
44
+ error: {
45
+ code: -32000,
46
+ message: "Method not allowed.",
47
+ },
48
+ id: null,
49
+ }),
50
+ );
51
+ } else {
52
+ next();
53
+ }
54
+ };
@@ -0,0 +1,73 @@
1
+ import { McpServer } from "skybridge/server";
2
+ import { z } from "zod";
3
+
4
+ interface Product {
5
+ id: number;
6
+ title: string;
7
+ price: number;
8
+ description: string;
9
+ category: string;
10
+ image: string;
11
+ rating: {
12
+ rate: number;
13
+ count: number;
14
+ };
15
+ }
16
+
17
+ const server = new McpServer(
18
+ {
19
+ name: "ecom-carousel-app",
20
+ version: "0.0.1",
21
+ },
22
+ { capabilities: {} },
23
+ ).registerWidget(
24
+ "ecom-carousel",
25
+ {
26
+ description: "E-commerce Product Carousel",
27
+ },
28
+ {
29
+ description: "Display a carousel of products from the store.",
30
+ inputSchema: {
31
+ category: z
32
+ .enum(["electronics", "jewelery", "men's clothing", "women's clothing"])
33
+ .optional()
34
+ .describe("Filter by product category"),
35
+ maxPrice: z.number().optional().describe("Maximum price filter"),
36
+ },
37
+ },
38
+ async ({ category, maxPrice }) => {
39
+ try {
40
+ const response = await fetch("https://fakestoreapi.com/products");
41
+ if (!response.ok) {
42
+ throw new Error(`API request failed: ${response.status}`);
43
+ }
44
+
45
+ const products: Product[] = await response.json();
46
+ const filtered: Product[] = [];
47
+
48
+ for (const product of products) {
49
+ if (category && product.category !== category) {
50
+ continue;
51
+ }
52
+ if (maxPrice !== undefined && product.price > maxPrice) {
53
+ continue;
54
+ }
55
+ filtered.push(product);
56
+ }
57
+
58
+ return {
59
+ structuredContent: { products: filtered },
60
+ content: [{ type: "text", text: JSON.stringify(filtered) }],
61
+ isError: false,
62
+ };
63
+ } catch (error) {
64
+ return {
65
+ content: [{ type: "text", text: `Error: ${error}` }],
66
+ isError: true,
67
+ };
68
+ }
69
+ },
70
+ );
71
+
72
+ export default server;
73
+ export type AppType = typeof server;
@@ -0,0 +1,23 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ESNext",
5
+ "moduleResolution": "bundler",
6
+ "lib": ["ES2022", "DOM", "DOM.Iterable"],
7
+ "jsx": "react-jsx",
8
+
9
+ "strict": true,
10
+ "skipLibCheck": true,
11
+ "esModuleInterop": true,
12
+ "forceConsistentCasingInFileNames": true,
13
+ "verbatimModuleSyntax": true,
14
+
15
+ "noUnusedLocals": true,
16
+ "noUnusedParameters": true,
17
+ "noFallthroughCasesInSwitch": true,
18
+
19
+ "noEmit": true
20
+ },
21
+ "include": ["server/src", "web/src", "web/vite.config.ts"],
22
+ "exclude": ["dist", "node_modules"]
23
+ }
@@ -0,0 +1,11 @@
1
+ {
2
+ "extends": "./tsconfig.json",
3
+ "compilerOptions": {
4
+ "noEmit": false,
5
+ "outDir": "server/dist",
6
+ "sourceMap": true,
7
+ "declaration": true
8
+ },
9
+ "include": ["server/src"],
10
+ "exclude": ["dist", "node_modules"]
11
+ }
@@ -0,0 +1,4 @@
1
+ import { generateHelpers } from "skybridge/web";
2
+ import type { AppType } from "../../server/src/server";
3
+
4
+ export const { useToolInfo } = generateHelpers<AppType>();
@@ -0,0 +1,194 @@
1
+ .light {
2
+ --bg: #fff;
3
+ --bg-alt: #f5f5f5;
4
+ --text: #333;
5
+ --text-muted: #666;
6
+ --shadow: rgba(0, 0, 0, 0.1);
7
+ }
8
+
9
+ .dark {
10
+ --bg: #2a2a2a;
11
+ --bg-alt: #333;
12
+ --text: #eee;
13
+ --text-muted: #aaa;
14
+ --shadow: rgba(0, 0, 0, 0.3);
15
+ }
16
+
17
+ .container,
18
+ .checkout {
19
+ --accent: mediumseagreen;
20
+ --accent-text: #fff;
21
+ display: flex;
22
+ flex-direction: column;
23
+ font-family: sans-serif;
24
+ }
25
+
26
+ .carousel {
27
+ display: flex;
28
+ gap: 1rem;
29
+ padding: 1rem;
30
+ overflow-x: auto;
31
+ scrollbar-width: none;
32
+ }
33
+
34
+ .product-wrapper {
35
+ flex: 0 0 150px;
36
+ max-width: 150px;
37
+ display: flex;
38
+ flex-direction: column;
39
+ gap: 0.5rem;
40
+ }
41
+
42
+ .product-card {
43
+ background: var(--bg);
44
+ border: none;
45
+ border-radius: 8px;
46
+ box-shadow: 0 2px 8px var(--shadow);
47
+ cursor: pointer;
48
+ padding: 0;
49
+ text-align: left;
50
+ }
51
+
52
+ .product-card.selected {
53
+ outline: 2px solid var(--accent);
54
+ }
55
+
56
+ .product-image {
57
+ width: 100%;
58
+ height: 100px;
59
+ object-fit: contain;
60
+ background: var(--bg-alt);
61
+ padding: 0.5rem;
62
+ box-sizing: border-box;
63
+ border-radius: 8px 8px 0 0;
64
+ }
65
+
66
+ .product-info {
67
+ padding: 0.5rem;
68
+ }
69
+
70
+ .product-title {
71
+ font-size: 0.75rem;
72
+ color: var(--text);
73
+ overflow: hidden;
74
+ text-overflow: ellipsis;
75
+ white-space: nowrap;
76
+ }
77
+
78
+ .product-price {
79
+ font-size: 0.875rem;
80
+ font-weight: bold;
81
+ color: var(--accent);
82
+ margin-top: 0.25rem;
83
+ }
84
+
85
+ .product-detail {
86
+ margin: 0 1rem 1rem;
87
+ padding: 1rem;
88
+ background: var(--bg);
89
+ border-radius: 8px;
90
+ box-shadow: 0 2px 8px var(--shadow);
91
+ }
92
+
93
+ .detail-title {
94
+ font-weight: bold;
95
+ color: var(--text);
96
+ margin-bottom: 0.5rem;
97
+ }
98
+
99
+ .detail-rating {
100
+ font-size: 0.875rem;
101
+ color: var(--text-muted);
102
+ margin-bottom: 0.5rem;
103
+ }
104
+
105
+ .detail-description {
106
+ font-size: 0.8rem;
107
+ color: var(--text-muted);
108
+ line-height: 1.4;
109
+ }
110
+
111
+ .message {
112
+ margin: 1rem;
113
+ padding: 1rem;
114
+ background: var(--bg);
115
+ border-radius: 8px;
116
+ box-shadow: 0 2px 8px var(--shadow);
117
+ color: var(--text-muted);
118
+ text-align: center;
119
+ }
120
+
121
+ .cart-indicator {
122
+ padding: 0.5rem 1rem;
123
+ align-self: flex-end;
124
+ color: var(--accent-text);
125
+ background: var(--accent);
126
+ border: none;
127
+ border-radius: 6px;
128
+ cursor: pointer;
129
+ font-weight: bold;
130
+ margin-right: 1rem;
131
+ }
132
+
133
+ .cart-indicator:disabled {
134
+ background: var(--bg-alt);
135
+ color: var(--text-muted);
136
+ cursor: default;
137
+ }
138
+
139
+ .cart-button {
140
+ padding: 0.5rem;
141
+ border: none;
142
+ border-radius: 6px;
143
+ cursor: pointer;
144
+ background: var(--accent);
145
+ color: var(--accent-text);
146
+ }
147
+
148
+ .cart-button.in-cart {
149
+ background: var(--bg-alt);
150
+ color: var(--text-muted);
151
+ }
152
+
153
+ .checkout {
154
+ gap: 1rem;
155
+ padding: 1.25rem;
156
+ }
157
+
158
+ .checkout-title {
159
+ font-weight: bold;
160
+ font-size: 1rem;
161
+ color: var(--text);
162
+ }
163
+
164
+ .checkout-items {
165
+ display: flex;
166
+ flex-direction: column;
167
+ gap: 0.5rem;
168
+ }
169
+
170
+ .checkout-item {
171
+ display: flex;
172
+ justify-content: space-between;
173
+ font-size: 0.875rem;
174
+ color: var(--text);
175
+ }
176
+
177
+ .checkout-total {
178
+ display: flex;
179
+ justify-content: space-between;
180
+ font-weight: bold;
181
+ color: var(--text);
182
+ border-top: 1px solid var(--bg-alt);
183
+ padding-top: 0.5rem;
184
+ }
185
+
186
+ .checkout-button {
187
+ padding: 0.75rem;
188
+ border: none;
189
+ border-radius: 6px;
190
+ cursor: pointer;
191
+ background: var(--accent);
192
+ color: var(--accent-text);
193
+ font-weight: bold;
194
+ }