@bitbybit-dev/create-app 1.3.2-rc.1 → 1.4.0-rc.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.
- package/README.md +47 -124
- package/dist/index.js +253 -21
- package/dist/index.js.map +1 -1
- package/dist/scaffold.d.ts +30 -0
- package/dist/scaffold.d.ts.map +1 -0
- package/dist/scaffold.js +107 -0
- package/dist/scaffold.js.map +1 -0
- package/package.json +4 -3
- package/src/index.test.ts +309 -8
- package/src/index.ts +285 -24
- package/src/scaffold.test.ts +177 -0
- package/src/scaffold.ts +99 -0
- package/templates/_agent/AGENTS.md +39 -0
- package/templates/_agent/CLAUDE.md +1 -0
- package/templates/_agent/_dot-cursor/mcp.json +5 -0
- package/templates/_agent/_dot-gitignore +7 -0
- package/templates/_agent/_dot-mcp.json +5 -0
- package/templates/_agent/_dot-vscode/mcp.json +5 -0
- package/templates/apps/drone-assembly/AGENTS.section.md +20 -0
- package/templates/apps/drone-assembly/README.md +35 -0
- package/templates/apps/drone-assembly/eslint.config.js +47 -0
- package/templates/apps/drone-assembly/index.html +17 -0
- package/templates/apps/drone-assembly/package.json +31 -0
- package/templates/apps/drone-assembly/public/favicon.ico +0 -0
- package/templates/apps/drone-assembly/public/logo.png +0 -0
- package/templates/apps/drone-assembly/scripts/smoke.ts +172 -0
- package/templates/apps/drone-assembly/src/assembly.ts +99 -0
- package/templates/apps/drone-assembly/src/exports.ts +10 -0
- package/templates/apps/drone-assembly/src/kernel.ts +14 -0
- package/templates/apps/drone-assembly/src/main.ts +298 -0
- package/templates/apps/drone-assembly/src/materials.ts +58 -0
- package/templates/apps/drone-assembly/src/model.ts +280 -0
- package/templates/apps/drone-assembly/src/parts.ts +343 -0
- package/templates/apps/drone-assembly/src/style.css +219 -0
- package/templates/apps/drone-assembly/src/ui.ts +180 -0
- package/templates/apps/drone-assembly/src/vite-env.d.ts +1 -0
- package/templates/apps/drone-assembly/tsconfig.json +29 -0
- package/templates/apps/laser-cut-box/AGENTS.section.md +17 -0
- package/templates/apps/laser-cut-box/README.md +34 -0
- package/templates/apps/laser-cut-box/eslint.config.js +47 -0
- package/templates/apps/laser-cut-box/index.html +17 -0
- package/templates/apps/laser-cut-box/package.json +30 -0
- package/templates/apps/laser-cut-box/public/favicon.ico +0 -0
- package/templates/apps/laser-cut-box/public/logo.png +0 -0
- package/templates/apps/laser-cut-box/scripts/smoke.ts +106 -0
- package/templates/apps/laser-cut-box/src/exports.ts +28 -0
- package/templates/apps/laser-cut-box/src/main.ts +176 -0
- package/templates/apps/laser-cut-box/src/model.ts +92 -0
- package/templates/apps/laser-cut-box/src/panels.ts +229 -0
- package/templates/apps/laser-cut-box/src/style.css +223 -0
- package/templates/apps/laser-cut-box/src/ui.ts +136 -0
- package/templates/apps/laser-cut-box/src/vite-env.d.ts +1 -0
- package/templates/apps/laser-cut-box/tsconfig.json +29 -0
- package/templates/apps/product-configurator/AGENTS.section.md +19 -0
- package/templates/apps/product-configurator/README.md +33 -0
- package/templates/apps/product-configurator/eslint.config.js +47 -0
- package/templates/apps/product-configurator/index.html +17 -0
- package/templates/apps/product-configurator/package.json +30 -0
- package/templates/apps/product-configurator/public/favicon.ico +0 -0
- package/templates/apps/product-configurator/public/logo.png +0 -0
- package/templates/apps/product-configurator/scripts/smoke.ts +69 -0
- package/templates/apps/product-configurator/src/catalog.ts +56 -0
- package/templates/apps/product-configurator/src/exports.ts +19 -0
- package/templates/apps/product-configurator/src/main.ts +134 -0
- package/templates/apps/product-configurator/src/model.ts +153 -0
- package/templates/apps/product-configurator/src/style.css +177 -0
- package/templates/apps/product-configurator/src/ui.ts +150 -0
- package/templates/apps/product-configurator/src/vite-env.d.ts +1 -0
- package/templates/apps/product-configurator/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/AGENTS.section.md +26 -0
- package/templates/apps/sheet-metal-unfold/README.md +41 -0
- package/templates/apps/sheet-metal-unfold/backend/_dot-env.example +5 -0
- package/templates/apps/sheet-metal-unfold/backend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/backend/package.json +28 -0
- package/templates/apps/sheet-metal-unfold/backend/scripts/smoke.ts +52 -0
- package/templates/apps/sheet-metal-unfold/backend/src/app.ts +65 -0
- package/templates/apps/sheet-metal-unfold/backend/src/cloud.ts +42 -0
- package/templates/apps/sheet-metal-unfold/backend/src/index.ts +13 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.build.json +9 -0
- package/templates/apps/sheet-metal-unfold/backend/tsconfig.json +27 -0
- package/templates/apps/sheet-metal-unfold/frontend/eslint.config.js +47 -0
- package/templates/apps/sheet-metal-unfold/frontend/index.html +17 -0
- package/templates/apps/sheet-metal-unfold/frontend/package.json +30 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/favicon.ico +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/public/logo.png +0 -0
- package/templates/apps/sheet-metal-unfold/frontend/scripts/smoke.ts +84 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/cloud-access.ts +37 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/exports.ts +10 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/flat.ts +71 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/main.ts +193 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/model.ts +166 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/style.css +291 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/ui.ts +150 -0
- package/templates/apps/sheet-metal-unfold/frontend/src/vite-env.d.ts +1 -0
- package/templates/apps/sheet-metal-unfold/frontend/tsconfig.json +29 -0
- package/templates/apps/sheet-metal-unfold/frontend/vite.config.ts +9 -0
- package/templates/apps/sheet-metal-unfold/package.json +18 -0
- package/templates/apps/step-to-gltf-cli/AGENTS.section.md +20 -0
- package/templates/apps/step-to-gltf-cli/README.md +34 -0
- package/templates/apps/step-to-gltf-cli/eslint.config.js +47 -0
- package/templates/apps/step-to-gltf-cli/package.json +26 -0
- package/templates/apps/step-to-gltf-cli/samples/bracket.step +2545 -0
- package/templates/apps/step-to-gltf-cli/scripts/smoke.ts +49 -0
- package/templates/apps/step-to-gltf-cli/src/cli.ts +106 -0
- package/templates/apps/step-to-gltf-cli/src/cloud.ts +34 -0
- package/templates/apps/step-to-gltf-cli/src/convert.ts +65 -0
- package/templates/apps/step-to-gltf-cli/src/kernel.ts +14 -0
- package/templates/apps/step-to-gltf-cli/tsconfig.json +27 -0
- package/templates/cloud/AGENTS.section.md +22 -0
- package/templates/cloud/backends/dotnet-rest/BitbybitClient.cs +22 -50
- package/templates/cloud/backends/dotnet-rest/Program.cs +1 -11
- package/templates/cloud/backends/dotnet-rest/dotnet-rest.csproj +4 -1
- package/templates/cloud/backends/hono-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-rest/package.json +11 -4
- package/templates/cloud/backends/hono-rest/src/bitbybit-client.ts +34 -45
- package/templates/cloud/backends/hono-rest/src/index.ts +1 -11
- package/templates/cloud/backends/hono-rest/tsconfig.json +19 -8
- package/templates/cloud/backends/hono-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/hono-sdk/package.json +12 -5
- package/templates/cloud/backends/hono-sdk/src/bitbybit-client.ts +6 -37
- package/templates/cloud/backends/hono-sdk/src/index.ts +1 -12
- package/templates/cloud/backends/hono-sdk/tsconfig.json +19 -8
- package/templates/cloud/backends/nodejs-rest/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-rest/package.json +12 -5
- package/templates/cloud/backends/nodejs-rest/src/bitbybit-client.ts +6 -35
- package/templates/cloud/backends/nodejs-rest/src/index.ts +6 -16
- package/templates/cloud/backends/nodejs-rest/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-rest/tsconfig.json +17 -7
- package/templates/cloud/backends/nodejs-sdk/eslint.config.js +47 -0
- package/templates/cloud/backends/nodejs-sdk/package.json +14 -7
- package/templates/cloud/backends/nodejs-sdk/src/bitbybit-client.ts +8 -33
- package/templates/cloud/backends/nodejs-sdk/src/index.ts +5 -16
- package/templates/cloud/backends/nodejs-sdk/tsconfig.build.json +9 -0
- package/templates/cloud/backends/nodejs-sdk/tsconfig.json +19 -9
- package/templates/cloud/frontend/eslint.config.js +50 -0
- package/templates/cloud/frontend/index.html +3 -1
- package/templates/cloud/frontend/package.json +13 -4
- package/templates/cloud/frontend/public/favicon.ico +0 -0
- package/templates/cloud/frontend/public/logo.png +0 -0
- package/templates/cloud/frontend/src/App.tsx +11 -9
- package/templates/cloud/frontend/src/api.ts +31 -0
- package/templates/cloud/frontend/src/components/ApiKeyWarning.tsx +28 -25
- package/templates/cloud/frontend/src/components/Header.tsx +4 -2
- package/templates/cloud/frontend/src/components/Tabs.tsx +4 -3
- package/templates/cloud/frontend/src/components/Viewer.tsx +57 -77
- package/templates/cloud/frontend/src/main.tsx +6 -1
- package/templates/cloud/frontend/src/panels/ModelsPanel.tsx +65 -73
- package/templates/cloud/frontend/src/panels/PipelinesPanel.tsx +82 -83
- package/templates/cloud/frontend/src/vite-env.d.ts +1 -0
- package/templates/cloud/frontend/tsconfig.json +19 -7
- package/templates/vite/babylonjs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/babylonjs/typescript/eslint.config.js +47 -0
- package/templates/vite/babylonjs/typescript/index.html +4 -2
- package/templates/vite/babylonjs/typescript/package.json +14 -4
- package/templates/vite/babylonjs/typescript/public/favicon.ico +0 -0
- package/templates/vite/babylonjs/typescript/public/logo.png +0 -0
- package/templates/vite/babylonjs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/babylonjs/typescript/src/main.ts +8 -17
- package/templates/vite/babylonjs/typescript/src/model.ts +24 -0
- package/templates/vite/babylonjs/typescript/tsconfig.json +16 -12
- package/templates/vite/playcanvas/typescript/AGENTS.section.md +13 -0
- package/templates/vite/playcanvas/typescript/eslint.config.js +47 -0
- package/templates/vite/playcanvas/typescript/index.html +4 -2
- package/templates/vite/playcanvas/typescript/package.json +14 -4
- package/templates/vite/playcanvas/typescript/public/favicon.ico +0 -0
- package/templates/vite/playcanvas/typescript/public/logo.png +0 -0
- package/templates/vite/playcanvas/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/playcanvas/typescript/src/main.ts +11 -22
- package/templates/vite/playcanvas/typescript/src/model.ts +24 -0
- package/templates/vite/playcanvas/typescript/tsconfig.json +16 -12
- package/templates/vite/threejs/typescript/AGENTS.section.md +13 -0
- package/templates/vite/threejs/typescript/eslint.config.js +47 -0
- package/templates/vite/threejs/typescript/index.html +4 -2
- package/templates/vite/threejs/typescript/package.json +16 -6
- package/templates/vite/threejs/typescript/public/favicon.ico +0 -0
- package/templates/vite/threejs/typescript/public/logo.png +0 -0
- package/templates/vite/threejs/typescript/scripts/smoke.ts +41 -0
- package/templates/vite/threejs/typescript/src/main.ts +11 -22
- package/templates/vite/threejs/typescript/src/model.ts +24 -0
- package/templates/vite/threejs/typescript/tsconfig.json +16 -12
- package/templates/vite/babylonjs/typescript/public/vite.svg +0 -1
- package/templates/vite/playcanvas/typescript/public/vite.svg +0 -1
- package/templates/vite/threejs/typescript/public/vite.svg +0 -1
- /package/templates/cloud/backends/dotnet-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/hono-sdk/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-rest/{_gitignore → _dot-gitignore} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{.env.example → _dot-env.example} +0 -0
- /package/templates/cloud/backends/nodejs-sdk/{_gitignore → _dot-gitignore} +0 -0
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { BitbybitClient } from "@bitbybit-dev/cad-cloud-sdk";
|
|
2
2
|
import { step } from "@bitbybit-dev/cad-cloud-sdk/pipeline";
|
|
3
3
|
|
|
4
|
-
const BITBYBIT_API_KEY = process.env
|
|
5
|
-
const BITBYBIT_API_URL = process.env
|
|
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
6
|
|
|
7
7
|
function getClient(): BitbybitClient {
|
|
8
8
|
return new BitbybitClient({
|
|
@@ -103,18 +103,13 @@ export async function getTaskResult(taskId: string): Promise<{ status: string; d
|
|
|
103
103
|
return { status: "completed", downloads };
|
|
104
104
|
}
|
|
105
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
106
|
export async function createInvalidCup(): Promise<never> {
|
|
112
107
|
const client = getClient();
|
|
113
108
|
|
|
114
109
|
await client.models.run("dragon-cup", {
|
|
115
110
|
params: {
|
|
116
|
-
height: 999,
|
|
117
|
-
radiusBottom: -5,
|
|
111
|
+
height: 999,
|
|
112
|
+
radiusBottom: -5,
|
|
118
113
|
},
|
|
119
114
|
outputs: {
|
|
120
115
|
formats: ["gltf"],
|
|
@@ -124,14 +119,6 @@ export async function createInvalidCup(): Promise<never> {
|
|
|
124
119
|
throw new Error("unreachable");
|
|
125
120
|
}
|
|
126
121
|
|
|
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
122
|
export async function runTranslateUnionFilletPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
136
123
|
const client = getClient();
|
|
137
124
|
|
|
@@ -146,10 +133,6 @@ export async function runTranslateUnionFilletPipeline(): Promise<{ taskId: strin
|
|
|
146
133
|
});
|
|
147
134
|
}
|
|
148
135
|
|
|
149
|
-
/**
|
|
150
|
-
* Map: Cylinders at Positions
|
|
151
|
-
* Parses an array of center positions, maps a cylinder at each, unions the result.
|
|
152
|
-
*/
|
|
153
136
|
export async function runMapCylindersPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
154
137
|
const client = getClient();
|
|
155
138
|
|
|
@@ -159,7 +142,7 @@ export async function runMapCylindersPipeline(): Promise<{ taskId: string; downl
|
|
|
159
142
|
{
|
|
160
143
|
type: "map",
|
|
161
144
|
items: "$ref:0",
|
|
162
|
-
steps: [step("occt.shapes.solid.createCylinder", { radius: 1, height: 5, center: "$item"
|
|
145
|
+
steps: [step("occt.shapes.solid.createCylinder", { radius: 1, height: 5, center: "$item" })],
|
|
163
146
|
},
|
|
164
147
|
step("occt.booleans.union", { shapes: "$ref:5" }),
|
|
165
148
|
],
|
|
@@ -167,10 +150,6 @@ export async function runMapCylindersPipeline(): Promise<{ taskId: string; downl
|
|
|
167
150
|
});
|
|
168
151
|
}
|
|
169
152
|
|
|
170
|
-
/**
|
|
171
|
-
* Map: Spheres at Different Radii
|
|
172
|
-
* Creates spheres of radii 1–5 at pre-computed positions, compounds the result.
|
|
173
|
-
*/
|
|
174
153
|
export async function runMapSpheresPipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
175
154
|
const client = getClient();
|
|
176
155
|
|
|
@@ -181,8 +160,8 @@ export async function runMapSpheresPipeline(): Promise<{ taskId: string; downloa
|
|
|
181
160
|
type: "map",
|
|
182
161
|
items: "$ref:0",
|
|
183
162
|
steps: [
|
|
184
|
-
step("math.twoNrOperation", { first: "$index"
|
|
185
|
-
step("occt.shapes.solid.createSphere", { radius: "$prev"
|
|
163
|
+
step("math.twoNrOperation", { first: "$index", second: 1, operation: "add" }),
|
|
164
|
+
step("occt.shapes.solid.createSphere", { radius: "$prev", center: "$item" }),
|
|
186
165
|
],
|
|
187
166
|
},
|
|
188
167
|
step("occt.shapes.compound.makeCompound", { shapes: "$ref:11" }),
|
|
@@ -191,17 +170,13 @@ export async function runMapSpheresPipeline(): Promise<{ taskId: string; downloa
|
|
|
191
170
|
});
|
|
192
171
|
}
|
|
193
172
|
|
|
194
|
-
/**
|
|
195
|
-
* Choice: Conditional Shape Size
|
|
196
|
-
* Parses a number, increments it, then picks a large box (> 5) or small sphere.
|
|
197
|
-
*/
|
|
198
173
|
export async function runChoicePipeline(): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
199
174
|
const client = getClient();
|
|
200
175
|
|
|
201
176
|
return client.cad.pipelineAndPoll({
|
|
202
177
|
steps: [
|
|
203
178
|
step("json.parse", { text: "10" }),
|
|
204
|
-
step("math.twoNrOperation", { first: "$ref:0"
|
|
179
|
+
step("math.twoNrOperation", { first: "$ref:0", second: 1, operation: "add" }),
|
|
205
180
|
{
|
|
206
181
|
type: "choice",
|
|
207
182
|
value: "$ref:1",
|
|
@@ -7,9 +7,8 @@ const upload = multer({ storage: multer.memoryStorage(), limits: { fileSize: 50
|
|
|
7
7
|
const app = express();
|
|
8
8
|
app.use(express.json());
|
|
9
9
|
|
|
10
|
-
// Check for missing API key and return a helpful error
|
|
11
10
|
app.use("/api", (_req, res, next) => {
|
|
12
|
-
if (!process.env
|
|
11
|
+
if (!process.env["BITBYBIT_API_KEY"]) {
|
|
13
12
|
res.status(503).json({
|
|
14
13
|
error: "BITBYBIT_API_KEY is not configured.",
|
|
15
14
|
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.",
|
|
@@ -19,7 +18,6 @@ app.use("/api", (_req, res, next) => {
|
|
|
19
18
|
next();
|
|
20
19
|
});
|
|
21
20
|
|
|
22
|
-
// Backend endpoint — calls bitbybit API with server-side API key
|
|
23
21
|
app.post("/api/generate", async (_req, res) => {
|
|
24
22
|
try {
|
|
25
23
|
const result = await createDragonCup();
|
|
@@ -34,7 +32,6 @@ app.post("/api/generate", async (_req, res) => {
|
|
|
34
32
|
}
|
|
35
33
|
});
|
|
36
34
|
|
|
37
|
-
// Batch generation — creates 3 dragon cup variations in parallel
|
|
38
35
|
app.post("/api/generate-batch", async (_req, res) => {
|
|
39
36
|
try {
|
|
40
37
|
const result = await createDragonCupBatch();
|
|
@@ -45,7 +42,6 @@ app.post("/api/generate-batch", async (_req, res) => {
|
|
|
45
42
|
}
|
|
46
43
|
});
|
|
47
44
|
|
|
48
|
-
// Validation demo — intentionally sends invalid params to show client-side validation
|
|
49
45
|
app.post("/api/validate-demo", async (_req, res) => {
|
|
50
46
|
try {
|
|
51
47
|
await createInvalidCup();
|
|
@@ -64,7 +60,6 @@ app.post("/api/validate-demo", async (_req, res) => {
|
|
|
64
60
|
}
|
|
65
61
|
});
|
|
66
62
|
|
|
67
|
-
// Fetch result for an existing task
|
|
68
63
|
app.get("/api/task/:id", async (req, res) => {
|
|
69
64
|
try {
|
|
70
65
|
const taskId = req.params.id;
|
|
@@ -76,7 +71,6 @@ app.get("/api/task/:id", async (req, res) => {
|
|
|
76
71
|
}
|
|
77
72
|
});
|
|
78
73
|
|
|
79
|
-
// Pipeline: translate → union → fillet
|
|
80
74
|
app.post("/api/pipeline/translate-union-fillet", async (_req, res) => {
|
|
81
75
|
try {
|
|
82
76
|
const result = await runTranslateUnionFilletPipeline();
|
|
@@ -87,7 +81,6 @@ app.post("/api/pipeline/translate-union-fillet", async (_req, res) => {
|
|
|
87
81
|
}
|
|
88
82
|
});
|
|
89
83
|
|
|
90
|
-
// Pipeline: map cylinders at positions
|
|
91
84
|
app.post("/api/pipeline/map-cylinders", async (_req, res) => {
|
|
92
85
|
try {
|
|
93
86
|
const result = await runMapCylindersPipeline();
|
|
@@ -98,7 +91,6 @@ app.post("/api/pipeline/map-cylinders", async (_req, res) => {
|
|
|
98
91
|
}
|
|
99
92
|
});
|
|
100
93
|
|
|
101
|
-
// Pipeline: map spheres at different radii
|
|
102
94
|
app.post("/api/pipeline/map-spheres", async (_req, res) => {
|
|
103
95
|
try {
|
|
104
96
|
const result = await runMapSpheresPipeline();
|
|
@@ -109,7 +101,6 @@ app.post("/api/pipeline/map-spheres", async (_req, res) => {
|
|
|
109
101
|
}
|
|
110
102
|
});
|
|
111
103
|
|
|
112
|
-
// Pipeline: choice conditional
|
|
113
104
|
app.post("/api/pipeline/choice", async (_req, res) => {
|
|
114
105
|
try {
|
|
115
106
|
const result = await runChoicePipeline();
|
|
@@ -120,7 +111,6 @@ app.post("/api/pipeline/choice", async (_req, res) => {
|
|
|
120
111
|
}
|
|
121
112
|
});
|
|
122
113
|
|
|
123
|
-
// Pipeline: file input (upload STEP → fillet)
|
|
124
114
|
app.post("/api/pipeline/file-input", upload.single("file"), async (req, res) => {
|
|
125
115
|
try {
|
|
126
116
|
const file = req.file;
|
|
@@ -135,10 +125,9 @@ app.post("/api/pipeline/file-input", upload.single("file"), async (req, res) =>
|
|
|
135
125
|
}
|
|
136
126
|
});
|
|
137
127
|
|
|
138
|
-
// Proxy download — streams a remote file through the backend to avoid CORS issues with GLTFLoader
|
|
139
128
|
app.get("/api/proxy-download", async (req, res) => {
|
|
140
|
-
const url = req.query
|
|
141
|
-
if (
|
|
129
|
+
const url = req.query["url"];
|
|
130
|
+
if (typeof url !== "string" || url.length === 0) { res.status(400).json({ error: "Missing url parameter" }); return; }
|
|
142
131
|
|
|
143
132
|
try {
|
|
144
133
|
const response = await fetch(url);
|
|
@@ -146,7 +135,7 @@ app.get("/api/proxy-download", async (req, res) => {
|
|
|
146
135
|
res.status(502).json({ error: `Upstream error: ${response.status}` });
|
|
147
136
|
return;
|
|
148
137
|
}
|
|
149
|
-
res.setHeader("Content-Type", response.headers.get("Content-Type")
|
|
138
|
+
res.setHeader("Content-Type", response.headers.get("Content-Type") ?? "model/gltf-binary");
|
|
150
139
|
const arrayBuffer = await response.arrayBuffer();
|
|
151
140
|
res.send(Buffer.from(arrayBuffer));
|
|
152
141
|
} catch (e: unknown) {
|
|
@@ -155,7 +144,7 @@ app.get("/api/proxy-download", async (req, res) => {
|
|
|
155
144
|
}
|
|
156
145
|
});
|
|
157
146
|
|
|
158
|
-
const PORT = parseInt(process.env
|
|
147
|
+
const PORT = parseInt(process.env["PORT"] ?? "3000", 10);
|
|
159
148
|
app.listen(PORT, () => {
|
|
160
149
|
console.log(`Server running at http://localhost:${PORT}`);
|
|
161
150
|
});
|
|
@@ -1,17 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
|
-
"module": "
|
|
5
|
-
"moduleResolution": "
|
|
6
|
-
"strict": true,
|
|
7
|
-
"skipLibCheck": true,
|
|
4
|
+
"module": "NodeNext",
|
|
5
|
+
"moduleResolution": "NodeNext",
|
|
8
6
|
"lib": ["ES2022"],
|
|
9
7
|
"types": ["node"],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
8
|
+
"noEmit": true,
|
|
9
|
+
"strict": true,
|
|
10
|
+
"noUncheckedIndexedAccess": true,
|
|
11
|
+
"exactOptionalPropertyTypes": true,
|
|
12
|
+
"noImplicitReturns": true,
|
|
13
|
+
"noImplicitOverride": true,
|
|
14
|
+
"noPropertyAccessFromIndexSignature": true,
|
|
15
|
+
"noFallthroughCasesInSwitch": true,
|
|
16
|
+
"noUnusedLocals": true,
|
|
17
|
+
"noUnusedParameters": true,
|
|
18
|
+
"useUnknownInCatchVariables": true,
|
|
19
|
+
"forceConsistentCasingInFileNames": true,
|
|
13
20
|
"isolatedModules": true,
|
|
14
|
-
"
|
|
21
|
+
"verbatimModuleSyntax": true,
|
|
22
|
+
"erasableSyntaxOnly": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true,
|
|
24
|
+
"skipLibCheck": true
|
|
15
25
|
},
|
|
16
|
-
"include": ["src
|
|
26
|
+
"include": ["src", "scripts"]
|
|
17
27
|
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import { defineConfig, globalIgnores } from "eslint/config";
|
|
2
|
+
import eslint from "@eslint/js";
|
|
3
|
+
import tseslint from "typescript-eslint";
|
|
4
|
+
import noComments from "eslint-plugin-no-comments";
|
|
5
|
+
import reactHooks from "eslint-plugin-react-hooks";
|
|
6
|
+
import reactRefresh from "eslint-plugin-react-refresh";
|
|
7
|
+
|
|
8
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
9
|
+
|
|
10
|
+
export default defineConfig([
|
|
11
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
12
|
+
{
|
|
13
|
+
files: ["**/*.{ts,tsx}"],
|
|
14
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked, reactHooks.configs.flat.recommended, reactRefresh.configs.vite],
|
|
15
|
+
plugins: { "no-comments": noComments },
|
|
16
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
17
|
+
rules: {
|
|
18
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
19
|
+
semi: ["error", "always"],
|
|
20
|
+
eqeqeq: ["error", "always"],
|
|
21
|
+
curly: ["error", "multi-line"],
|
|
22
|
+
"prefer-const": "error",
|
|
23
|
+
"no-var": "error",
|
|
24
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
25
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
26
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
27
|
+
"no-restricted-syntax": ["error", { selector: DOUBLE_ASSERTION, message: "A double assertion replaces a type instead of narrowing it: write a type predicate, constrain a generic to the union, or fix the type this is arguing with." }],
|
|
28
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
29
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
30
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
31
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
32
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
33
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
34
|
+
"@typescript-eslint/naming-convention": [
|
|
35
|
+
"error",
|
|
36
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE", "PascalCase"], leadingUnderscore: "allow" },
|
|
38
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
39
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
40
|
+
{ selector: "property", format: null },
|
|
41
|
+
{ selector: "method", format: ["camelCase"] },
|
|
42
|
+
{ selector: "import", format: null },
|
|
43
|
+
{ selector: "function", format: ["camelCase", "PascalCase"] },
|
|
44
|
+
],
|
|
45
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
46
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
47
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
48
|
+
},
|
|
49
|
+
},
|
|
50
|
+
]);
|
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
<meta charset="UTF-8" />
|
|
5
5
|
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
|
6
6
|
<title>Bitbybit CAD API Examples</title>
|
|
7
|
-
<link rel="icon" href="
|
|
7
|
+
<link rel="icon" href="/favicon.ico" sizes="48x48" />
|
|
8
|
+
<link rel="icon" type="image/png" href="/logo.png" sizes="150x150" />
|
|
9
|
+
<link rel="apple-touch-icon" href="/logo.png" />
|
|
8
10
|
</head>
|
|
9
11
|
<body>
|
|
10
12
|
<div id="root"></div>
|
|
@@ -1,12 +1,15 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitbybit-example-frontend",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0-rc.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "vite",
|
|
8
|
-
"build": "vite build",
|
|
9
|
-
"preview": "vite preview"
|
|
8
|
+
"build": "npm run typecheck && vite build",
|
|
9
|
+
"preview": "vite preview",
|
|
10
|
+
"smoke": "npm run typecheck && npm run lint",
|
|
11
|
+
"typecheck": "tsc --noEmit",
|
|
12
|
+
"lint": "eslint . --max-warnings 0"
|
|
10
13
|
},
|
|
11
14
|
"dependencies": {
|
|
12
15
|
"react": "^19.1.0",
|
|
@@ -14,11 +17,17 @@
|
|
|
14
17
|
"three": "0.186.0"
|
|
15
18
|
},
|
|
16
19
|
"devDependencies": {
|
|
20
|
+
"@eslint/js": "10.0.1",
|
|
17
21
|
"@types/react": "^19.1.0",
|
|
18
22
|
"@types/react-dom": "^19.1.0",
|
|
19
23
|
"@types/three": "0.186.0",
|
|
20
24
|
"@vitejs/plugin-react": "^4.4.0",
|
|
21
|
-
"
|
|
25
|
+
"eslint": "10.10.0",
|
|
26
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
27
|
+
"eslint-plugin-react-hooks": "7.1.1",
|
|
28
|
+
"eslint-plugin-react-refresh": "0.5.7",
|
|
29
|
+
"typescript": "5.9.3",
|
|
30
|
+
"typescript-eslint": "8.70.0",
|
|
22
31
|
"vite": "^6.3.0"
|
|
23
32
|
}
|
|
24
33
|
}
|
|
Binary file
|
|
Binary file
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useState } from "react";
|
|
1
|
+
import { useCallback, useState, type ReactElement } from "react";
|
|
2
2
|
import { Header } from "./components/Header";
|
|
3
3
|
import { Tabs } from "./components/Tabs";
|
|
4
4
|
import { ModelsPanel } from "./panels/ModelsPanel";
|
|
@@ -8,34 +8,36 @@ import { ApiKeyWarning } from "./components/ApiKeyWarning";
|
|
|
8
8
|
|
|
9
9
|
export type TabId = "models" | "pipelines";
|
|
10
10
|
|
|
11
|
-
export function App() {
|
|
11
|
+
export function App(): ReactElement {
|
|
12
12
|
const initialTab = new URLSearchParams(window.location.search).has("pipeline-task") ? "pipelines" : "models";
|
|
13
13
|
const [activeTab, setActiveTab] = useState<TabId>(initialTab);
|
|
14
14
|
const [viewerUrl, setViewerUrl] = useState<string | null>(null);
|
|
15
15
|
const [viewerUrls, setViewerUrls] = useState<string[] | null>(null);
|
|
16
16
|
|
|
17
|
-
const loadModel = (url: string) => {
|
|
17
|
+
const loadModel = useCallback((url: string): void => {
|
|
18
18
|
setViewerUrls(null);
|
|
19
19
|
setViewerUrl(url);
|
|
20
|
-
};
|
|
20
|
+
}, []);
|
|
21
21
|
|
|
22
|
-
const loadModels = (urls: string[]) => {
|
|
22
|
+
const loadModels = useCallback((urls: string[]): void => {
|
|
23
23
|
setViewerUrl(null);
|
|
24
24
|
setViewerUrls(urls);
|
|
25
|
-
};
|
|
25
|
+
}, []);
|
|
26
26
|
|
|
27
|
-
const clearViewer = () => {
|
|
27
|
+
const clearViewer = (): void => {
|
|
28
28
|
setViewerUrl(null);
|
|
29
29
|
setViewerUrls(null);
|
|
30
30
|
};
|
|
31
31
|
|
|
32
|
+
const modelLoaded = viewerUrl !== null || viewerUrls !== null;
|
|
33
|
+
|
|
32
34
|
return (
|
|
33
35
|
<>
|
|
34
36
|
<Header />
|
|
35
37
|
<ApiKeyWarning />
|
|
36
38
|
<Tabs activeTab={activeTab} onTabChange={(tab) => { clearViewer(); setActiveTab(tab); }} />
|
|
37
|
-
<ModelsPanel active={activeTab === "models"} modelLoaded={
|
|
38
|
-
<PipelinesPanel active={activeTab === "pipelines"} modelLoaded={
|
|
39
|
+
<ModelsPanel active={activeTab === "models"} modelLoaded={modelLoaded} onLoadModel={loadModel} onLoadModels={loadModels} />
|
|
40
|
+
<PipelinesPanel active={activeTab === "pipelines"} modelLoaded={modelLoaded} onLoadModel={loadModel} />
|
|
39
41
|
<Viewer url={viewerUrl} urls={viewerUrls} />
|
|
40
42
|
</>
|
|
41
43
|
);
|
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export interface Download {
|
|
2
|
+
format: string;
|
|
3
|
+
downloadUrl: string;
|
|
4
|
+
filename: string;
|
|
5
|
+
}
|
|
6
|
+
|
|
7
|
+
export async function readJson(response: Response): Promise<Record<string, unknown>> {
|
|
8
|
+
const data: unknown = await response.json();
|
|
9
|
+
return data !== null && typeof data === "object" ? (data as Record<string, unknown>) : {};
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export function stringOf(record: Record<string, unknown>, key: string): string | undefined {
|
|
13
|
+
const value = record[key];
|
|
14
|
+
return typeof value === "string" ? value : undefined;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export function isDownload(value: unknown): value is Download {
|
|
18
|
+
return typeof value === "object" && value !== null
|
|
19
|
+
&& "format" in value && typeof value.format === "string"
|
|
20
|
+
&& "downloadUrl" in value && typeof value.downloadUrl === "string"
|
|
21
|
+
&& "filename" in value && typeof value.filename === "string";
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export function downloadsOf(value: unknown): Download[] {
|
|
25
|
+
return Array.isArray(value) ? value.filter(isDownload) : [];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
export function glbUrlOf(downloads: Download[]): string | undefined {
|
|
29
|
+
const glb = downloads.find((download) => download.format === "glb" || download.format === "gltf") ?? downloads[0];
|
|
30
|
+
return glb?.downloadUrl;
|
|
31
|
+
}
|
|
@@ -1,40 +1,43 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useState, type ReactElement } from "react";
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
3
|
+
const CAD_CLOUD_URL = "https://bitbybit.dev/cad-cloud";
|
|
4
|
+
const STUDIO_KEYS_URL = "https://studio.bitbybit.dev/keys/billing";
|
|
5
|
+
|
|
6
|
+
export function ApiKeyWarning(): ReactElement | null {
|
|
7
|
+
const [state, setState] = useState<"ok" | "no-key" | "no-backend">("ok");
|
|
5
8
|
|
|
6
9
|
useEffect(() => {
|
|
7
|
-
// Probe the backend to check if the API key is configured
|
|
8
10
|
fetch("/api/generate", { method: "POST" })
|
|
9
|
-
.then(
|
|
10
|
-
|
|
11
|
-
if (res.status ===
|
|
12
|
-
setVisible(true);
|
|
13
|
-
}
|
|
11
|
+
.then((res) => {
|
|
12
|
+
if (res.status === 503) setState("no-key");
|
|
13
|
+
else if (res.status === 502 || res.status === 504) setState("no-backend");
|
|
14
14
|
})
|
|
15
|
-
.catch(() => {
|
|
16
|
-
// Backend not reachable — show generic warning
|
|
17
|
-
setVisible(true);
|
|
18
|
-
});
|
|
15
|
+
.catch(() => { setState("no-backend"); });
|
|
19
16
|
}, []);
|
|
20
17
|
|
|
21
|
-
if (
|
|
18
|
+
if (state === "ok") return null;
|
|
22
19
|
|
|
23
20
|
return (
|
|
24
21
|
<div className="api-key-warning">
|
|
25
22
|
<div className="api-key-warning-icon">⚠️</div>
|
|
26
23
|
<div className="api-key-warning-content">
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
24
|
+
{state === "no-backend" ? (
|
|
25
|
+
<>
|
|
26
|
+
<strong>Backend not reachable</strong>
|
|
27
|
+
<p>Start it in a second terminal: <code>cd backend</code> then <code>npm run dev</code> (or <code>dotnet run</code>). The frontend proxies <code>/api</code> to it.</p>
|
|
28
|
+
</>
|
|
29
|
+
) : (
|
|
30
|
+
<>
|
|
31
|
+
<strong>This app needs CAD Cloud</strong>
|
|
32
|
+
<p>
|
|
33
|
+
Everything it renders is computed on{" "}
|
|
34
|
+
<a href={CAD_CLOUD_URL} target="_blank" rel="noopener noreferrer">CAD Cloud</a>, and the backend has no API key yet.
|
|
35
|
+
Any plan includes one: create it in{" "}
|
|
36
|
+
<a href={STUDIO_KEYS_URL} target="_blank" rel="noopener noreferrer">Bitbybit Studio</a>, put it in the backend's secret file
|
|
37
|
+
(see the README) and restart the backend. The key stays on the server; this page never sees it.
|
|
38
|
+
</p>
|
|
39
|
+
</>
|
|
40
|
+
)}
|
|
38
41
|
</div>
|
|
39
42
|
</div>
|
|
40
43
|
);
|
|
@@ -1,7 +1,9 @@
|
|
|
1
|
-
|
|
1
|
+
import type { ReactElement } from "react";
|
|
2
|
+
|
|
3
|
+
export function Header(): ReactElement {
|
|
2
4
|
return (
|
|
3
5
|
<header className="header">
|
|
4
|
-
<img src="
|
|
6
|
+
<img src="/logo.png" alt="bitbybit.dev" />
|
|
5
7
|
<h1>Bitbybit CAD Cloud API</h1>
|
|
6
8
|
</header>
|
|
7
9
|
);
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { ReactElement } from "react";
|
|
1
2
|
import type { TabId } from "../App";
|
|
2
3
|
|
|
3
4
|
interface TabsProps {
|
|
@@ -5,18 +6,18 @@ interface TabsProps {
|
|
|
5
6
|
onTabChange: (tab: TabId) => void;
|
|
6
7
|
}
|
|
7
8
|
|
|
8
|
-
export function Tabs({ activeTab, onTabChange }: TabsProps) {
|
|
9
|
+
export function Tabs({ activeTab, onTabChange }: TabsProps): ReactElement {
|
|
9
10
|
return (
|
|
10
11
|
<nav className="tabs">
|
|
11
12
|
<button
|
|
12
13
|
className={`tab ${activeTab === "models" ? "active" : ""}`}
|
|
13
|
-
onClick={() => onTabChange("models")}
|
|
14
|
+
onClick={() => { onTabChange("models"); }}
|
|
14
15
|
>
|
|
15
16
|
Models
|
|
16
17
|
</button>
|
|
17
18
|
<button
|
|
18
19
|
className={`tab ${activeTab === "pipelines" ? "active" : ""}`}
|
|
19
|
-
onClick={() => onTabChange("pipelines")}
|
|
20
|
+
onClick={() => { onTabChange("pipelines"); }}
|
|
20
21
|
>
|
|
21
22
|
Pipelines
|
|
22
23
|
</button>
|