@bitbybit-dev/create-app 1.0.0-rc.1 → 1.0.0

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 (51) hide show
  1. package/README.md +19 -5
  2. package/dist/index.js +478 -32
  3. package/dist/index.js.map +1 -1
  4. package/package.json +1 -1
  5. package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +371 -0
  6. package/templates/cloud/backends/dotnet-rest/Program.cs +147 -0
  7. package/templates/cloud/backends/dotnet-rest/Properties/launchSettings.json +14 -0
  8. package/templates/cloud/backends/dotnet-rest/appsettings.json +13 -0
  9. package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +10 -0
  10. package/templates/cloud/backends/hono-rest/package.json +19 -0
  11. package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +387 -0
  12. package/templates/cloud/backends/hono-rest/src/index.ts +128 -0
  13. package/templates/cloud/backends/hono-rest/src/types.ts +4 -0
  14. package/templates/cloud/backends/hono-rest/tsconfig.json +16 -0
  15. package/templates/cloud/backends/hono-rest/wrangler.jsonc +11 -0
  16. package/templates/cloud/backends/hono-sdk/package.json +19 -0
  17. package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +239 -0
  18. package/templates/cloud/backends/hono-sdk/src/index.ts +155 -0
  19. package/templates/cloud/backends/hono-sdk/src/types.ts +4 -0
  20. package/templates/cloud/backends/hono-sdk/tsconfig.json +16 -0
  21. package/templates/cloud/backends/hono-sdk/wrangler.jsonc +11 -0
  22. package/templates/cloud/backends/nodejs-rest/.env.example +3 -0
  23. package/templates/cloud/backends/nodejs-rest/package.json +22 -0
  24. package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +387 -0
  25. package/templates/cloud/backends/nodejs-rest/src/index.ts +143 -0
  26. package/templates/cloud/backends/nodejs-rest/src/types.ts +4 -0
  27. package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -0
  28. package/templates/cloud/backends/nodejs-sdk/.env.example +3 -0
  29. package/templates/cloud/backends/nodejs-sdk/package.json +23 -0
  30. package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +235 -0
  31. package/templates/cloud/backends/nodejs-sdk/src/index.ts +161 -0
  32. package/templates/cloud/backends/nodejs-sdk/tsconfig.json +17 -0
  33. package/templates/cloud/frontend/index.html +13 -0
  34. package/templates/cloud/frontend/package.json +24 -0
  35. package/templates/cloud/frontend/src/App.tsx +42 -0
  36. package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +41 -0
  37. package/templates/cloud/frontend/src/components/Header.tsx +8 -0
  38. package/templates/cloud/frontend/src/components/Tabs.tsx +25 -0
  39. package/templates/cloud/frontend/src/components/Viewer.tsx +155 -0
  40. package/templates/cloud/frontend/src/main.tsx +10 -0
  41. package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +134 -0
  42. package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +213 -0
  43. package/templates/cloud/frontend/src/styles.css +320 -0
  44. package/templates/cloud/frontend/tsconfig.json +17 -0
  45. package/templates/cloud/frontend/vite.config.ts +15 -0
  46. package/templates/vite/babylonjs/typescript/index.html +1 -1
  47. package/templates/vite/babylonjs/typescript/package.json +1 -1
  48. package/templates/vite/playcanvas/typescript/index.html +1 -1
  49. package/templates/vite/playcanvas/typescript/package.json +2 -2
  50. package/templates/vite/threejs/typescript/index.html +1 -1
  51. package/templates/vite/threejs/typescript/package.json +2 -2
@@ -0,0 +1,235 @@
1
+ import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";
2
+ import { step } from "@bitbybit-dev/cad-cloud-sdk/pipeline";
3
+
4
+ const BITBYBIT_API_KEY = process.env.BITBYBIT_API_KEY ?? "";
5
+ const BITBYBIT_API_URL = process.env.BITBYBIT_API_URL ?? "https://api.bitbybit.dev";
6
+
7
+ function getClient(): BitbybitClient {
8
+ return new BitbybitClient({
9
+ apiKey: BITBYBIT_API_KEY,
10
+ baseUrl: BITBYBIT_API_URL,
11
+ });
12
+ }
13
+
14
+ export async function createDragonCup(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
15
+ const client = getClient();
16
+
17
+ return client.models.run("dragon-cup", {
18
+ params: {
19
+ height: 8,
20
+ radiusBottom: 4,
21
+ radiusTopOffset: 2,
22
+ radiusMidOffset: 2,
23
+ rotationTopAngle: 20,
24
+ rotationMidAngle: 20,
25
+ nrSkinCellsVertical: 5,
26
+ nrSkinCellsHorizontal: 10,
27
+ thickness: 0.6,
28
+ bottomThickness: 1,
29
+ scale: 1,
30
+ origin: [0, 0, 0],
31
+ direction: [0, 1, 0],
32
+ },
33
+ outputs: {
34
+ formats: ["gltf"],
35
+ },
36
+ });
37
+ }
38
+
39
+ export async function createDragonCupBatch(): Promise<{
40
+ taskId: string;
41
+ subTasks: { taskId: string; index: number; downloads: { format: string; downloadUrl: string; filename: string }[] }[];
42
+ }> {
43
+ const client = getClient();
44
+
45
+ const result = await client.models.batchRun("dragon-cup", {
46
+ items: [
47
+ {
48
+ params: {
49
+ height: 4, radiusBottom: 4, radiusTopOffset: 2, radiusMidOffset: 2,
50
+ rotationTopAngle: 20, rotationMidAngle: 20,
51
+ nrSkinCellsVertical: 2, nrSkinCellsHorizontal: 6,
52
+ nrSkinCellDivisionsTop: 2, nrSkinCellDivisionsBottom: 3,
53
+ skinCellOuterHeight: 1, skinCellInnerHeight: 0.3,
54
+ skinCellBottomHeight: 1, skinCellTopHeight: 1,
55
+ thickness: 2,
56
+ },
57
+ },
58
+ {
59
+ params: {
60
+ height: 7, radiusBottom: 4, radiusTopOffset: 2, radiusMidOffset: 2,
61
+ rotationTopAngle: 20, rotationMidAngle: 20,
62
+ nrSkinCellsVertical: 1, nrSkinCellsHorizontal: 12,
63
+ nrSkinCellDivisionsTop: 1, nrSkinCellDivisionsBottom: 1,
64
+ skinCellOuterHeight: 2, skinCellInnerHeight: 1,
65
+ skinCellBottomHeight: 1, skinCellTopHeight: 1,
66
+ thickness: 0.5,
67
+ },
68
+ },
69
+ {
70
+ params: {
71
+ height: 9, radiusBottom: 2, radiusTopOffset: 1, radiusMidOffset: 1,
72
+ rotationTopAngle: -30, rotationMidAngle: -30,
73
+ nrSkinCellsVertical: 1, nrSkinCellsHorizontal: 5,
74
+ nrSkinCellDivisionsTop: 1, nrSkinCellDivisionsBottom: 1,
75
+ skinCellOuterHeight: 4, skinCellInnerHeight: -0.3,
76
+ skinCellBottomHeight: 0.5, skinCellTopHeight: 0.3,
77
+ thickness: 0.5,
78
+ },
79
+ },
80
+ ],
81
+ outputs: {
82
+ formats: ["gltf"],
83
+ },
84
+ });
85
+
86
+ return { taskId: result.taskId, subTasks: [...result.subTasks] };
87
+ }
88
+
89
+ export async function getTaskResult(taskId: string): Promise<{ status: string; downloads?: { format: string; downloadUrl: string; filename: string }[] }> {
90
+ const client = getClient();
91
+
92
+ const task = await client.tasks.get(taskId);
93
+
94
+ if (task.status === "failed" || task.status === "cancelled" || task.status === "expired") {
95
+ throw new Error(`Task ${task.status}: ${task.error ?? "no details"}`);
96
+ }
97
+
98
+ if (task.status !== "completed") {
99
+ return { status: task.status };
100
+ }
101
+
102
+ const downloads = await client.tasks.getResults(taskId);
103
+ return { status: "completed", downloads };
104
+ }
105
+
106
+ /**
107
+ * Intentionally invalid request — height exceeds the 50cm maximum.
108
+ * The SDK validates against JSON Schema before sending, so this throws
109
+ * a BitbybitValidationError without ever hitting the network.
110
+ */
111
+ export async function createInvalidCup(): Promise<never> {
112
+ const client = getClient();
113
+
114
+ await client.models.run("dragon-cup", {
115
+ params: {
116
+ height: 999, // max is 50
117
+ radiusBottom: -5, // must be > 0
118
+ },
119
+ outputs: {
120
+ formats: ["gltf"],
121
+ },
122
+ });
123
+
124
+ throw new Error("unreachable");
125
+ }
126
+
127
+ // ---------------------------------------------------------------------------
128
+ // Pipeline examples (using typed step() helper)
129
+ // ---------------------------------------------------------------------------
130
+
131
+ /**
132
+ * Translate, Union + Fillet: createBox → translate → union → fillet
133
+ * Creates a box, translates a copy, unions both, fillets the result.
134
+ */
135
+ export async function runTranslateUnionFilletPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
136
+ const client = getClient();
137
+
138
+ return client.cad.pipelineAndPoll({
139
+ steps: [
140
+ step("occt.shapes.solid.createBox", { width: 8, length: 6, height: 4, center: [0, 0, 0] }),
141
+ step("occt.transforms.translate", { shape: "$ref:0", translation: [4, 2, 3] }),
142
+ step("occt.booleans.union", { shapes: ["$ref:0", "$ref:1"] }),
143
+ step("occt.fillets.filletEdges", { shape: "$ref:2", radius: 0.5 }),
144
+ ],
145
+ outputs: { formats: ["stpz", "gltf"] },
146
+ });
147
+ }
148
+
149
+ /**
150
+ * Map: Cylinders at Positions
151
+ * Parses an array of center positions, maps a cylinder at each, unions the result.
152
+ */
153
+ export async function runMapCylindersPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
154
+ const client = getClient();
155
+
156
+ return client.cad.pipelineAndPoll({
157
+ steps: [
158
+ step("json.parse", { text: "[[0,0,0],[1.5,0,0],[3,0,0],[4.5,0,0]]" }),
159
+ {
160
+ type: "map",
161
+ items: "$ref:0",
162
+ steps: [step("occt.shapes.solid.createCylinder", { radius: 1, height: 5, center: "$item" as never })],
163
+ },
164
+ step("occt.booleans.union", { shapes: "$ref:5" }),
165
+ ],
166
+ outputs: { formats: ["stpz", "gltf"] },
167
+ });
168
+ }
169
+
170
+ /**
171
+ * Map: Spheres at Different Radii
172
+ * Creates spheres of radii 1–5 at pre-computed positions, compounds the result.
173
+ */
174
+ export async function runMapSpheresPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
175
+ const client = getClient();
176
+
177
+ return client.cad.pipelineAndPoll({
178
+ steps: [
179
+ step("json.parse", { text: "[[0,0,0],[4,0,0],[10,0,0],[18,0,0],[28,0,0]]" }),
180
+ {
181
+ type: "map",
182
+ items: "$ref:0",
183
+ steps: [
184
+ step("math.twoNrOperation", { first: "$index" as never, second: 1, operation: "add" }),
185
+ step("occt.shapes.solid.createSphere", { radius: "$prev" as never, center: "$item" as never }),
186
+ ],
187
+ },
188
+ step("occt.shapes.compound.makeCompound", { shapes: "$ref:11" }),
189
+ ],
190
+ outputs: { formats: ["stpz", "gltf"] },
191
+ });
192
+ }
193
+
194
+ /**
195
+ * Choice: Conditional Shape Size
196
+ * Parses a number, increments it, then picks a large box (> 5) or small sphere.
197
+ */
198
+ export async function runChoicePipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
199
+ const client = getClient();
200
+
201
+ return client.cad.pipelineAndPoll({
202
+ steps: [
203
+ step("json.parse", { text: "10" }),
204
+ step("math.twoNrOperation", { first: "$ref:0" as never, second: 1, operation: "add" }),
205
+ {
206
+ type: "choice",
207
+ value: "$ref:1",
208
+ operator: "gt",
209
+ compareTo: 5,
210
+ then: [step("occt.shapes.solid.createBox", { width: 10, length: 10, height: 10, center: [0, 0, 0] })],
211
+ else: [step("occt.shapes.solid.createSphere", { radius: 2, center: [0, 0, 0] })],
212
+ },
213
+ ],
214
+ outputs: { formats: ["stpz", "gltf"] },
215
+ });
216
+ }
217
+
218
+ export async function runFileInputPipeline(fileId: string): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
219
+ const client = getClient();
220
+
221
+ return client.cad.pipelineAndPoll({
222
+ steps: [
223
+ step("occt.io.loadSTEPorIGES", { filetext: "$file:0", fileName: "shape.step", adjustZtoY: true }),
224
+ step("occt.fillets.filletEdges", { shape: "$ref:0", radius: 0.1 }),
225
+ ],
226
+ inputFiles: [{ fileId, role: "input" }],
227
+ outputs: { formats: ["stpz", "gltf"], meshPrecision: 0.001 },
228
+ });
229
+ }
230
+
231
+ export async function uploadFile(fileBuffer: ArrayBuffer, filename: string): Promise<string> {
232
+ const client = getClient();
233
+ const result = await client.files.uploadBytes(filename, fileBuffer);
234
+ return result.fileId;
235
+ }
@@ -0,0 +1,161 @@
1
+ import express from "express";
2
+ import multer from "multer";
3
+ import { BitbybitValidationError } from "@bitbybit-dev/cad-cloud-sdk";
4
+ import { createDragonCup, createDragonCupBatch, createInvalidCup, getTaskResult, runTranslateUnionFilletPipeline, runMapCylindersPipeline, runMapSpheresPipeline, runChoicePipeline, runFileInputPipeline, uploadFile } from "./bitbybit-client.js";
5
+
6
+ const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 50 * 1024 * 1024 } });
7
+ const app = express();
8
+ app.use(express.json());
9
+
10
+ // Check for missing API key and return a helpful error
11
+ app.use("/api", (_req, res, next) => {
12
+ if (!process.env.BITBYBIT_API_KEY) {
13
+ res.status(503).json({
14
+ error: "BITBYBIT_API_KEY is not configured.",
15
+ help: "You need a Bitbybit API key to use this service. Create an account on https://bitbybit.dev and purchase an API key plan at https://bitbybit.dev/auth/pick-plan?api-keys=true to get access to managed CAD cloud servers.",
16
+ });
17
+ return;
18
+ }
19
+ next();
20
+ });
21
+
22
+ // Backend endpoint — calls bitbybit API with server-side API key
23
+ app.post("/api/generate", async (_req, res) => {
24
+ try {
25
+ const result = await createDragonCup();
26
+ res.json(result);
27
+ } catch (e: unknown) {
28
+ if (e instanceof BitbybitValidationError) {
29
+ res.status(400).json({ error: e.message, validationErrors: e.errors });
30
+ return;
31
+ }
32
+ const message = e instanceof Error ? e.message : "Unknown error";
33
+ res.status(500).json({ error: message });
34
+ }
35
+ });
36
+
37
+ // Batch generation — creates 3 dragon cup variations in parallel
38
+ app.post("/api/generate-batch", async (_req, res) => {
39
+ try {
40
+ const result = await createDragonCupBatch();
41
+ res.json(result);
42
+ } catch (e: unknown) {
43
+ const message = e instanceof Error ? e.message : "Unknown error";
44
+ res.status(500).json({ error: message });
45
+ }
46
+ });
47
+
48
+ // Validation demo — intentionally sends invalid params to show client-side validation
49
+ app.post("/api/validate-demo", async (_req, res) => {
50
+ try {
51
+ await createInvalidCup();
52
+ res.status(500).json({ error: "Should not reach here" });
53
+ } catch (e: unknown) {
54
+ if (e instanceof BitbybitValidationError) {
55
+ res.status(400).json({
56
+ caught: "BitbybitValidationError",
57
+ message: e.message,
58
+ errors: e.errors,
59
+ });
60
+ return;
61
+ }
62
+ const message = e instanceof Error ? e.message : "Unknown error";
63
+ res.status(500).json({ error: message });
64
+ }
65
+ });
66
+
67
+ // Fetch result for an existing task
68
+ app.get("/api/task/:id", async (req, res) => {
69
+ try {
70
+ const taskId = req.params.id;
71
+ const result = await getTaskResult(taskId);
72
+ res.json(result);
73
+ } catch (e: unknown) {
74
+ const message = e instanceof Error ? e.message : "Unknown error";
75
+ res.status(500).json({ error: message });
76
+ }
77
+ });
78
+
79
+ // Pipeline: translate → union → fillet
80
+ app.post("/api/pipeline/translate-union-fillet", async (_req, res) => {
81
+ try {
82
+ const result = await runTranslateUnionFilletPipeline();
83
+ res.json(result);
84
+ } catch (e: unknown) {
85
+ const message = e instanceof Error ? e.message : "Unknown error";
86
+ res.status(500).json({ error: message });
87
+ }
88
+ });
89
+
90
+ // Pipeline: map cylinders at positions
91
+ app.post("/api/pipeline/map-cylinders", async (_req, res) => {
92
+ try {
93
+ const result = await runMapCylindersPipeline();
94
+ res.json(result);
95
+ } catch (e: unknown) {
96
+ const message = e instanceof Error ? e.message : "Unknown error";
97
+ res.status(500).json({ error: message });
98
+ }
99
+ });
100
+
101
+ // Pipeline: map spheres at different radii
102
+ app.post("/api/pipeline/map-spheres", async (_req, res) => {
103
+ try {
104
+ const result = await runMapSpheresPipeline();
105
+ res.json(result);
106
+ } catch (e: unknown) {
107
+ const message = e instanceof Error ? e.message : "Unknown error";
108
+ res.status(500).json({ error: message });
109
+ }
110
+ });
111
+
112
+ // Pipeline: choice conditional
113
+ app.post("/api/pipeline/choice", async (_req, res) => {
114
+ try {
115
+ const result = await runChoicePipeline();
116
+ res.json(result);
117
+ } catch (e: unknown) {
118
+ const message = e instanceof Error ? e.message : "Unknown error";
119
+ res.status(500).json({ error: message });
120
+ }
121
+ });
122
+
123
+ // Pipeline: file input (upload STEP → fillet)
124
+ app.post("/api/pipeline/file-input", upload.single("file"), async (req, res) => {
125
+ try {
126
+ const file = req.file;
127
+ if (!file) { res.status(400).json({ error: "No file uploaded" }); return; }
128
+
129
+ const fileId = await uploadFile(file.buffer.buffer as ArrayBuffer, file.originalname);
130
+ const result = await runFileInputPipeline(fileId);
131
+ res.json(result);
132
+ } catch (e: unknown) {
133
+ const message = e instanceof Error ? e.message : "Unknown error";
134
+ res.status(500).json({ error: message });
135
+ }
136
+ });
137
+
138
+ // Proxy download — streams a remote file through the backend to avoid CORS issues with GLTFLoader
139
+ app.get("/api/proxy-download", async (req, res) => {
140
+ const url = req.query.url as string | undefined;
141
+ if (!url) { res.status(400).json({ error: "Missing url parameter" }); return; }
142
+
143
+ try {
144
+ const response = await fetch(url);
145
+ if (!response.ok || !response.body) {
146
+ res.status(502).json({ error: `Upstream error: ${response.status}` });
147
+ return;
148
+ }
149
+ res.setHeader("Content-Type", response.headers.get("Content-Type") || "model/gltf-binary");
150
+ const arrayBuffer = await response.arrayBuffer();
151
+ res.send(Buffer.from(arrayBuffer));
152
+ } catch (e: unknown) {
153
+ const message = e instanceof Error ? e.message : "Unknown error";
154
+ res.status(500).json({ error: message });
155
+ }
156
+ });
157
+
158
+ const PORT = parseInt(process.env.PORT ?? "3000", 10);
159
+ app.listen(PORT, () => {
160
+ console.log(`Server running at http://localhost:${PORT}`);
161
+ });
@@ -0,0 +1,17 @@
1
+ {
2
+ "compilerOptions": {
3
+ "target": "ES2022",
4
+ "module": "ES2022",
5
+ "moduleResolution": "bundler",
6
+ "strict": true,
7
+ "skipLibCheck": true,
8
+ "lib": ["ES2022"],
9
+ "types": ["node"],
10
+ "outDir": "dist",
11
+ "rootDir": "src",
12
+ "resolveJsonModule": true,
13
+ "isolatedModules": true,
14
+ "esModuleInterop": true
15
+ },
16
+ "include": ["src/**/*.ts"]
17
+ }
@@ -0,0 +1,13 @@
1
+ <!DOCTYPE html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Bitbybit CAD API Examples</title>
7
+ <link rel="icon" href="https://bitbybit.dev/favicon.png" />
8
+ </head>
9
+ <body>
10
+ <div id="root"></div>
11
+ <script type="module" src="/src/main.tsx"></script>
12
+ </body>
13
+ </html>
@@ -0,0 +1,24 @@
1
+ {
2
+ "name": "bitbybit-example-frontend",
3
+ "version": "1.0.0",
4
+ "private": true,
5
+ "type": "module",
6
+ "scripts": {
7
+ "dev": "vite",
8
+ "build": "vite build",
9
+ "preview": "vite preview"
10
+ },
11
+ "dependencies": {
12
+ "react": "^19.1.0",
13
+ "react-dom": "^19.1.0",
14
+ "three": "0.184.0"
15
+ },
16
+ "devDependencies": {
17
+ "@types/react": "^19.1.0",
18
+ "@types/react-dom": "^19.1.0",
19
+ "@types/three": "0.184.0",
20
+ "@vitejs/plugin-react": "^4.4.0",
21
+ "typescript": "^5.8.0",
22
+ "vite": "^6.3.0"
23
+ }
24
+ }
@@ -0,0 +1,42 @@
1
+ import { useState } from "react";
2
+ import { Header } from "./components/Header";
3
+ import { Tabs } from "./components/Tabs";
4
+ import { ModelsPanel } from "./panels/ModelsPanel";
5
+ import { PipelinesPanel } from "./panels/PipelinesPanel";
6
+ import { Viewer } from "./components/Viewer";
7
+ import { ApiKeyWarning } from "./components/ApiKeyWarning";
8
+
9
+ export type TabId = "models" | "pipelines";
10
+
11
+ export function App() {
12
+ const initialTab = new URLSearchParams(window.location.search).has("pipeline-task") ? "pipelines" : "models";
13
+ const [activeTab, setActiveTab] = useState<TabId>(initialTab);
14
+ const [viewerUrl, setViewerUrl] = useState<string | null>(null);
15
+ const [viewerUrls, setViewerUrls] = useState<string[] | null>(null);
16
+
17
+ const loadModel = (url: string) => {
18
+ setViewerUrls(null);
19
+ setViewerUrl(url);
20
+ };
21
+
22
+ const loadModels = (urls: string[]) => {
23
+ setViewerUrl(null);
24
+ setViewerUrls(urls);
25
+ };
26
+
27
+ const clearViewer = () => {
28
+ setViewerUrl(null);
29
+ setViewerUrls(null);
30
+ };
31
+
32
+ return (
33
+ <>
34
+ <Header />
35
+ <ApiKeyWarning />
36
+ <Tabs activeTab={activeTab} onTabChange={(tab) => { clearViewer(); setActiveTab(tab); }} />
37
+ <ModelsPanel active={activeTab === "models"} modelLoaded={!!(viewerUrl || viewerUrls)} onLoadModel={loadModel} onLoadModels={loadModels} />
38
+ <PipelinesPanel active={activeTab === "pipelines"} modelLoaded={!!(viewerUrl || viewerUrls)} onLoadModel={loadModel} />
39
+ <Viewer url={viewerUrl} urls={viewerUrls} />
40
+ </>
41
+ );
42
+ }
@@ -0,0 +1,41 @@
1
+ import { useEffect, useState } from "react";
2
+
3
+ export function ApiKeyWarning() {
4
+ const [visible, setVisible] = useState(false);
5
+
6
+ useEffect(() => {
7
+ // Probe the backend to check if the API key is configured
8
+ fetch("/api/generate", { method: "POST" })
9
+ .then(async (res) => {
10
+ // 503 = API key not configured, 502/504 = backend not reachable
11
+ if (res.status === 503 || res.status === 502 || res.status === 504) {
12
+ setVisible(true);
13
+ }
14
+ })
15
+ .catch(() => {
16
+ // Backend not reachable — show generic warning
17
+ setVisible(true);
18
+ });
19
+ }, []);
20
+
21
+ if (!visible) return null;
22
+
23
+ return (
24
+ <div className="api-key-warning">
25
+ <div className="api-key-warning-icon">⚠️</div>
26
+ <div className="api-key-warning-content">
27
+ <strong>API Key Not Configured</strong>
28
+ <p>
29
+ You need a Bitbybit API key to use this application.
30
+ Create an account on{" "}
31
+ <a href="https://bitbybit.dev" target="_blank" rel="noopener noreferrer">bitbybit.dev</a>{" "}
32
+ and purchase an API key plan at{" "}
33
+ <a href="https://bitbybit.dev/auth/pick-plan?api-keys=true" target="_blank" rel="noopener noreferrer">
34
+ bitbybit.dev/auth/pick-plan
35
+ </a>{" "}
36
+ to get access to managed CAD cloud servers.
37
+ </p>
38
+ </div>
39
+ </div>
40
+ );
41
+ }
@@ -0,0 +1,8 @@
1
+ export function Header() {
2
+ return (
3
+ <header className="header">
4
+ <img src="https://bitbybit.dev/favicon.png" alt="Bitbybit" />
5
+ <h1>Bitbybit CAD Cloud API</h1>
6
+ </header>
7
+ );
8
+ }
@@ -0,0 +1,25 @@
1
+ import type { TabId } from "../App";
2
+
3
+ interface TabsProps {
4
+ activeTab: TabId;
5
+ onTabChange: (tab: TabId) => void;
6
+ }
7
+
8
+ export function Tabs({ activeTab, onTabChange }: TabsProps) {
9
+ return (
10
+ <nav className="tabs">
11
+ <button
12
+ className={`tab ${activeTab === "models" ? "active" : ""}`}
13
+ onClick={() => onTabChange("models")}
14
+ >
15
+ Models
16
+ </button>
17
+ <button
18
+ className={`tab ${activeTab === "pipelines" ? "active" : ""}`}
19
+ onClick={() => onTabChange("pipelines")}
20
+ >
21
+ Pipelines
22
+ </button>
23
+ </nav>
24
+ );
25
+ }