@bitbybit-dev/create-app 1.3.2 → 1.4.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
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
|
|
6
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
10
|
+
{
|
|
11
|
+
files: ["**/*.ts"],
|
|
12
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
|
|
13
|
+
plugins: { "no-comments": noComments },
|
|
14
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
15
|
+
rules: {
|
|
16
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
17
|
+
semi: ["error", "always"],
|
|
18
|
+
eqeqeq: ["error", "always"],
|
|
19
|
+
curly: ["error", "multi-line"],
|
|
20
|
+
"prefer-const": "error",
|
|
21
|
+
"no-var": "error",
|
|
22
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
23
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
24
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
25
|
+
"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." }],
|
|
26
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
28
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
29
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
30
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
31
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
32
|
+
"@typescript-eslint/naming-convention": [
|
|
33
|
+
"error",
|
|
34
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
35
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
|
|
36
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
38
|
+
{ selector: "property", format: null },
|
|
39
|
+
{ selector: "method", format: ["camelCase"] },
|
|
40
|
+
{ selector: "import", format: null },
|
|
41
|
+
],
|
|
42
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
43
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
44
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitbybit-api-hono-rest-threejs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "wrangler dev",
|
|
8
8
|
"deploy": "wrangler deploy",
|
|
9
|
-
"deploy:staging": "wrangler deploy --env staging"
|
|
9
|
+
"deploy:staging": "wrangler deploy --env staging",
|
|
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
|
"hono": "^4.7.0"
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
18
|
"@cloudflare/workers-types": "^5.20260903.1",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
19
|
+
"@eslint/js": "10.0.1",
|
|
20
|
+
"eslint": "10.10.0",
|
|
21
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
22
|
+
"typescript": "5.9.3",
|
|
23
|
+
"typescript-eslint": "8.70.0",
|
|
24
|
+
"wrangler": "^4.129.0"
|
|
18
25
|
}
|
|
19
26
|
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import type { Env } from "./types";
|
|
2
2
|
|
|
3
3
|
const POLL_INTERVAL_MS = 2_000;
|
|
4
|
-
const
|
|
4
|
+
const POLL_TIMEOUT_MS = 4 * 60 * 1000;
|
|
5
|
+
const MAX_POLL_ATTEMPTS = POLL_TIMEOUT_MS / POLL_INTERVAL_MS;
|
|
5
6
|
|
|
6
7
|
interface TaskResponse {
|
|
7
8
|
ok: boolean;
|
|
@@ -39,24 +40,39 @@ interface ResultResponse {
|
|
|
39
40
|
error?: { code: string; message: string };
|
|
40
41
|
}
|
|
41
42
|
|
|
43
|
+
interface Download {
|
|
44
|
+
format: string;
|
|
45
|
+
downloadUrl: string;
|
|
46
|
+
filename: string;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
interface DownloadsResponse {
|
|
50
|
+
ok: boolean;
|
|
51
|
+
data?: { downloads: Download[] };
|
|
52
|
+
error?: { code: string; message: string };
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
interface UploadResponse {
|
|
56
|
+
ok: boolean;
|
|
57
|
+
data?: { fileId: string; uploadUrl: string };
|
|
58
|
+
error?: { code: string; message: string };
|
|
59
|
+
}
|
|
60
|
+
|
|
42
61
|
async function apiRequest(env: Env, method: string, path: string, body?: unknown): Promise<Response> {
|
|
43
62
|
const url = `${env.BITBYBIT_API_URL}${path}`;
|
|
44
63
|
const headers: Record<string, string> = {
|
|
45
64
|
"x-api-key": env.BITBYBIT_API_KEY,
|
|
46
65
|
};
|
|
47
|
-
|
|
66
|
+
const init: RequestInit = { method, headers };
|
|
67
|
+
if (body !== undefined) {
|
|
48
68
|
headers["Content-Type"] = "application/json";
|
|
69
|
+
init.body = JSON.stringify(body);
|
|
49
70
|
}
|
|
50
71
|
|
|
51
|
-
return fetch(url,
|
|
52
|
-
method,
|
|
53
|
-
headers,
|
|
54
|
-
body: body ? JSON.stringify(body) : undefined,
|
|
55
|
-
});
|
|
72
|
+
return fetch(url, init);
|
|
56
73
|
}
|
|
57
74
|
|
|
58
75
|
export async function createDragonCup(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
59
|
-
// 1. Create dragon cup model — returns 202 with taskId
|
|
60
76
|
const createRes = await apiRequest(env, "POST", "/api/v1/models/dragon-cup", {
|
|
61
77
|
params: {
|
|
62
78
|
height: 8,
|
|
@@ -83,7 +99,7 @@ export async function createDragonCup(env: Env): Promise<{ taskId: string; downl
|
|
|
83
99
|
throw new Error(`Failed to create dragon cup: ${createRes.status} ${err}`);
|
|
84
100
|
}
|
|
85
101
|
|
|
86
|
-
const createData
|
|
102
|
+
const createData = await createRes.json<TaskResponse>();
|
|
87
103
|
if (!createData.ok || !createData.data?.taskId) {
|
|
88
104
|
throw new Error(`API error: ${createData.error?.message ?? "unknown"}`);
|
|
89
105
|
}
|
|
@@ -140,21 +156,19 @@ export async function createDragonCupBatch(
|
|
|
140
156
|
throw new Error(`Failed to create batch: ${createRes.status} ${err}`);
|
|
141
157
|
}
|
|
142
158
|
|
|
143
|
-
const createData
|
|
159
|
+
const createData = await createRes.json<CompoundTaskResponse>();
|
|
144
160
|
if (!createData.ok || !createData.data?.taskId) {
|
|
145
161
|
throw new Error(`API error: ${createData.error?.message ?? "unknown"}`);
|
|
146
162
|
}
|
|
147
163
|
|
|
148
164
|
const { taskId, subTasks } = createData.data;
|
|
149
165
|
|
|
150
|
-
// Poll compound task until all sub-tasks complete
|
|
151
166
|
await pollUntilDone(env, taskId);
|
|
152
167
|
|
|
153
|
-
// Fetch each sub-task result
|
|
154
168
|
const downloadUrls: string[] = [];
|
|
155
169
|
for (const sub of subTasks) {
|
|
156
170
|
const resultRes = await apiRequest(env, "GET", `/api/v1/tasks/${sub.taskId}/result/glb`);
|
|
157
|
-
const resultData
|
|
171
|
+
const resultData = await resultRes.json<ResultResponse>();
|
|
158
172
|
if (!resultData.ok || !resultData.data?.downloadUrl) {
|
|
159
173
|
throw new Error(`Sub-task ${sub.index} result error: ${resultData.error?.message ?? "no download URL"}`);
|
|
160
174
|
}
|
|
@@ -166,7 +180,7 @@ export async function createDragonCupBatch(
|
|
|
166
180
|
|
|
167
181
|
export async function getTaskResult(env: Env, taskId: string): Promise<{ status: string; downloads?: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
168
182
|
const statusRes = await apiRequest(env, "GET", `/api/v1/tasks/${taskId}`);
|
|
169
|
-
const statusData
|
|
183
|
+
const statusData = await statusRes.json<TaskResponse>();
|
|
170
184
|
|
|
171
185
|
if (!statusData.ok || !statusData.data) {
|
|
172
186
|
throw new Error(`Task error: ${statusData.error?.message ?? "unknown"}`);
|
|
@@ -183,7 +197,7 @@ export async function getTaskResult(env: Env, taskId: string): Promise<{ status:
|
|
|
183
197
|
}
|
|
184
198
|
|
|
185
199
|
const resultRes = await apiRequest(env, "GET", `/api/v1/tasks/${taskId}/results`);
|
|
186
|
-
const resultData = await resultRes.json()
|
|
200
|
+
const resultData = await resultRes.json<DownloadsResponse>();
|
|
187
201
|
|
|
188
202
|
if (!resultData.ok || !resultData.data?.downloads) {
|
|
189
203
|
throw new Error(`Result error: ${resultData.error?.message ?? "no downloads"}`);
|
|
@@ -197,7 +211,7 @@ async function pollUntilDone(env: Env, taskId: string): Promise<void> {
|
|
|
197
211
|
await sleep(POLL_INTERVAL_MS);
|
|
198
212
|
|
|
199
213
|
const statusRes = await apiRequest(env, "GET", `/api/v1/tasks/${taskId}`);
|
|
200
|
-
const statusData
|
|
214
|
+
const statusData = await statusRes.json<TaskResponse>();
|
|
201
215
|
|
|
202
216
|
if (!statusData.ok || !statusData.data) {
|
|
203
217
|
throw new Error(`Task poll error: ${statusData.error?.message ?? "unknown"}`);
|
|
@@ -215,11 +229,11 @@ async function pollUntilDone(env: Env, taskId: string): Promise<void> {
|
|
|
215
229
|
throw new Error("Polling timed out");
|
|
216
230
|
}
|
|
217
231
|
|
|
218
|
-
async function pollAndGetResult(env: Env, taskId: string): Promise<
|
|
232
|
+
async function pollAndGetResult(env: Env, taskId: string): Promise<Download[]> {
|
|
219
233
|
await pollUntilDone(env, taskId);
|
|
220
234
|
|
|
221
235
|
const resultRes = await apiRequest(env, "GET", `/api/v1/tasks/${taskId}/results`);
|
|
222
|
-
const resultData = await resultRes.json()
|
|
236
|
+
const resultData = await resultRes.json<DownloadsResponse>();
|
|
223
237
|
|
|
224
238
|
if (!resultData.ok || !resultData.data?.downloads) {
|
|
225
239
|
throw new Error(`Result error: ${resultData.error?.message ?? "no downloads"}`);
|
|
@@ -228,10 +242,6 @@ async function pollAndGetResult(env: Env, taskId: string): Promise<{ format: str
|
|
|
228
242
|
return resultData.data.downloads;
|
|
229
243
|
}
|
|
230
244
|
|
|
231
|
-
// ---------------------------------------------------------------------------
|
|
232
|
-
// Pipeline examples
|
|
233
|
-
// ---------------------------------------------------------------------------
|
|
234
|
-
|
|
235
245
|
async function submitPipeline(env: Env, body: unknown): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
236
246
|
const createRes = await apiRequest(env, "POST", "/api/v1/cad/pipeline", body);
|
|
237
247
|
if (!createRes.ok && createRes.status !== 202) {
|
|
@@ -239,7 +249,7 @@ async function submitPipeline(env: Env, body: unknown): Promise<{ taskId: string
|
|
|
239
249
|
throw new Error(`Pipeline failed: ${createRes.status} ${err}`);
|
|
240
250
|
}
|
|
241
251
|
|
|
242
|
-
const createData
|
|
252
|
+
const createData = await createRes.json<TaskResponse>();
|
|
243
253
|
if (!createData.ok || !createData.data?.taskId) {
|
|
244
254
|
throw new Error(`API error: ${createData.error?.message ?? "unknown"}`);
|
|
245
255
|
}
|
|
@@ -249,9 +259,6 @@ async function submitPipeline(env: Env, body: unknown): Promise<{ taskId: string
|
|
|
249
259
|
return { taskId, downloads };
|
|
250
260
|
}
|
|
251
261
|
|
|
252
|
-
/**
|
|
253
|
-
* Translate, Union + Fillet: createBox → translate → union → fillet
|
|
254
|
-
*/
|
|
255
262
|
export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
256
263
|
return submitPipeline(env, {
|
|
257
264
|
steps: [
|
|
@@ -264,9 +271,6 @@ export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskI
|
|
|
264
271
|
});
|
|
265
272
|
}
|
|
266
273
|
|
|
267
|
-
/**
|
|
268
|
-
* Map: Cylinders at Positions
|
|
269
|
-
*/
|
|
270
274
|
export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
271
275
|
return submitPipeline(env, {
|
|
272
276
|
steps: [
|
|
@@ -282,9 +286,6 @@ export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: strin
|
|
|
282
286
|
});
|
|
283
287
|
}
|
|
284
288
|
|
|
285
|
-
/**
|
|
286
|
-
* Map: Spheres at Different Radii
|
|
287
|
-
*/
|
|
288
289
|
export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
289
290
|
return submitPipeline(env, {
|
|
290
291
|
steps: [
|
|
@@ -303,9 +304,6 @@ export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string;
|
|
|
303
304
|
});
|
|
304
305
|
}
|
|
305
306
|
|
|
306
|
-
/**
|
|
307
|
-
* Choice: Conditional Shape Size
|
|
308
|
-
*/
|
|
309
307
|
export async function runChoicePipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
310
308
|
return submitPipeline(env, {
|
|
311
309
|
steps: [
|
|
@@ -324,9 +322,6 @@ export async function runChoicePipeline(env: Env): Promise<{ taskId: string; dow
|
|
|
324
322
|
});
|
|
325
323
|
}
|
|
326
324
|
|
|
327
|
-
/**
|
|
328
|
-
* File-input pipeline: upload a STEP file, fillet all edges, export.
|
|
329
|
-
*/
|
|
330
325
|
export async function runFileInputPipeline(env: Env, fileId: string): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
331
326
|
return submitPipeline(env, {
|
|
332
327
|
steps: [
|
|
@@ -338,11 +333,7 @@ export async function runFileInputPipeline(env: Env, fileId: string): Promise<{
|
|
|
338
333
|
});
|
|
339
334
|
}
|
|
340
335
|
|
|
341
|
-
/**
|
|
342
|
-
* Upload a file to the Bitbybit API, returns a fileId for use in pipelines.
|
|
343
|
-
*/
|
|
344
336
|
export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: string): Promise<string> {
|
|
345
|
-
// 1. Request a pre-signed upload URL
|
|
346
337
|
const uploadRes = await apiRequest(env, "POST", "/api/v1/files/upload", {
|
|
347
338
|
filename,
|
|
348
339
|
contentType: "application/octet-stream",
|
|
@@ -354,14 +345,13 @@ export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: st
|
|
|
354
345
|
throw new Error(`File upload request failed: ${uploadRes.status} ${err}`);
|
|
355
346
|
}
|
|
356
347
|
|
|
357
|
-
const uploadData = await uploadRes.json()
|
|
348
|
+
const uploadData = await uploadRes.json<UploadResponse>();
|
|
358
349
|
if (!uploadData.ok || !uploadData.data?.uploadUrl) {
|
|
359
350
|
throw new Error(`Upload error: ${uploadData.error?.message ?? "no uploadUrl"}`);
|
|
360
351
|
}
|
|
361
352
|
|
|
362
353
|
const { fileId, uploadUrl } = uploadData.data;
|
|
363
354
|
|
|
364
|
-
// 2. PUT raw bytes to the pre-signed URL
|
|
365
355
|
const putRes = await fetch(uploadUrl, {
|
|
366
356
|
method: "PUT",
|
|
367
357
|
headers: { "Content-Type": "application/octet-stream" },
|
|
@@ -372,7 +362,6 @@ export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: st
|
|
|
372
362
|
throw new Error(`PUT to upload URL failed: ${putRes.status} ${putRes.statusText}`);
|
|
373
363
|
}
|
|
374
364
|
|
|
375
|
-
// 3. Confirm the upload
|
|
376
365
|
const confirmRes = await apiRequest(env, "POST", `/api/v1/files/${encodeURIComponent(fileId)}/confirm`);
|
|
377
366
|
if (!confirmRes.ok) {
|
|
378
367
|
const err = await confirmRes.text();
|
|
@@ -4,7 +4,6 @@ import { createDragonCup, createDragonCupBatch, getTaskResult, runTranslateUnion
|
|
|
4
4
|
|
|
5
5
|
const app = new Hono<{ Bindings: Env }>();
|
|
6
6
|
|
|
7
|
-
// Check for missing API key and return a helpful error
|
|
8
7
|
app.use("/api/*", async (c, next) => {
|
|
9
8
|
if (!c.env.BITBYBIT_API_KEY) {
|
|
10
9
|
return c.json({
|
|
@@ -12,10 +11,9 @@ app.use("/api/*", async (c, next) => {
|
|
|
12
11
|
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.",
|
|
13
12
|
}, 503);
|
|
14
13
|
}
|
|
15
|
-
|
|
14
|
+
return next();
|
|
16
15
|
});
|
|
17
16
|
|
|
18
|
-
// Backend endpoint — calls bitbybit API with server-side API key
|
|
19
17
|
app.post("/api/generate", async (c) => {
|
|
20
18
|
try {
|
|
21
19
|
const result = await createDragonCup(c.env);
|
|
@@ -26,7 +24,6 @@ app.post("/api/generate", async (c) => {
|
|
|
26
24
|
}
|
|
27
25
|
});
|
|
28
26
|
|
|
29
|
-
// Batch generation — creates 3 dragon cup variations in parallel
|
|
30
27
|
app.post("/api/generate-batch", async (c) => {
|
|
31
28
|
try {
|
|
32
29
|
const result = await createDragonCupBatch(c.env);
|
|
@@ -37,7 +34,6 @@ app.post("/api/generate-batch", async (c) => {
|
|
|
37
34
|
}
|
|
38
35
|
});
|
|
39
36
|
|
|
40
|
-
// Fetch result for an existing task
|
|
41
37
|
app.get("/api/task/:id", async (c) => {
|
|
42
38
|
try {
|
|
43
39
|
const taskId = c.req.param("id");
|
|
@@ -49,7 +45,6 @@ app.get("/api/task/:id", async (c) => {
|
|
|
49
45
|
}
|
|
50
46
|
});
|
|
51
47
|
|
|
52
|
-
// Pipeline: translate → union → fillet
|
|
53
48
|
app.post("/api/pipeline/translate-union-fillet", async (c) => {
|
|
54
49
|
try {
|
|
55
50
|
const result = await runTranslateUnionFilletPipeline(c.env);
|
|
@@ -60,7 +55,6 @@ app.post("/api/pipeline/translate-union-fillet", async (c) => {
|
|
|
60
55
|
}
|
|
61
56
|
});
|
|
62
57
|
|
|
63
|
-
// Pipeline: map cylinders at positions
|
|
64
58
|
app.post("/api/pipeline/map-cylinders", async (c) => {
|
|
65
59
|
try {
|
|
66
60
|
const result = await runMapCylindersPipeline(c.env);
|
|
@@ -71,7 +65,6 @@ app.post("/api/pipeline/map-cylinders", async (c) => {
|
|
|
71
65
|
}
|
|
72
66
|
});
|
|
73
67
|
|
|
74
|
-
// Pipeline: map spheres at different radii
|
|
75
68
|
app.post("/api/pipeline/map-spheres", async (c) => {
|
|
76
69
|
try {
|
|
77
70
|
const result = await runMapSpheresPipeline(c.env);
|
|
@@ -82,7 +75,6 @@ app.post("/api/pipeline/map-spheres", async (c) => {
|
|
|
82
75
|
}
|
|
83
76
|
});
|
|
84
77
|
|
|
85
|
-
// Pipeline: choice conditional
|
|
86
78
|
app.post("/api/pipeline/choice", async (c) => {
|
|
87
79
|
try {
|
|
88
80
|
const result = await runChoicePipeline(c.env);
|
|
@@ -93,7 +85,6 @@ app.post("/api/pipeline/choice", async (c) => {
|
|
|
93
85
|
}
|
|
94
86
|
});
|
|
95
87
|
|
|
96
|
-
// Pipeline: file input (upload STEP → fillet)
|
|
97
88
|
app.post("/api/pipeline/file-input", async (c) => {
|
|
98
89
|
try {
|
|
99
90
|
const formData = await c.req.formData();
|
|
@@ -110,7 +101,6 @@ app.post("/api/pipeline/file-input", async (c) => {
|
|
|
110
101
|
}
|
|
111
102
|
});
|
|
112
103
|
|
|
113
|
-
// Proxy download — fetches a remote file through the backend to avoid CORS issues with GLTFLoader
|
|
114
104
|
app.get("/api/proxy-download", async (c) => {
|
|
115
105
|
const url = c.req.query("url");
|
|
116
106
|
if (!url) return c.json({ error: "Missing url parameter" }, 400);
|
|
@@ -1,16 +1,27 @@
|
|
|
1
1
|
{
|
|
2
2
|
"compilerOptions": {
|
|
3
3
|
"target": "ES2022",
|
|
4
|
-
"module": "
|
|
4
|
+
"module": "ESNext",
|
|
5
5
|
"moduleResolution": "bundler",
|
|
6
|
-
"strict": true,
|
|
7
|
-
"skipLibCheck": true,
|
|
8
6
|
"lib": ["ES2022"],
|
|
9
7
|
"types": ["@cloudflare/workers-types"],
|
|
10
|
-
"
|
|
11
|
-
"
|
|
12
|
-
"
|
|
13
|
-
"
|
|
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,
|
|
20
|
+
"isolatedModules": true,
|
|
21
|
+
"verbatimModuleSyntax": true,
|
|
22
|
+
"erasableSyntaxOnly": true,
|
|
23
|
+
"noUncheckedSideEffectImports": true,
|
|
24
|
+
"skipLibCheck": true
|
|
14
25
|
},
|
|
15
|
-
"include": ["src
|
|
26
|
+
"include": ["src"]
|
|
16
27
|
}
|
|
@@ -0,0 +1,47 @@
|
|
|
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
|
+
|
|
6
|
+
const DOUBLE_ASSERTION = ":matches(TSAsExpression, TSTypeAssertion) > :matches(TSAsExpression, TSTypeAssertion).expression[typeAnnotation.type=/^TS(Unknown|Any)Keyword$/]";
|
|
7
|
+
|
|
8
|
+
export default defineConfig([
|
|
9
|
+
globalIgnores(["dist/", "node_modules/", "**/*.d.ts"]),
|
|
10
|
+
{
|
|
11
|
+
files: ["**/*.ts"],
|
|
12
|
+
extends: [eslint.configs.recommended, tseslint.configs.strictTypeChecked, tseslint.configs.stylisticTypeChecked],
|
|
13
|
+
plugins: { "no-comments": noComments },
|
|
14
|
+
languageOptions: { parserOptions: { projectService: true, tsconfigRootDir: import.meta.dirname } },
|
|
15
|
+
rules: {
|
|
16
|
+
quotes: ["error", "double", { avoidEscape: true, allowTemplateLiterals: true }],
|
|
17
|
+
semi: ["error", "always"],
|
|
18
|
+
eqeqeq: ["error", "always"],
|
|
19
|
+
curly: ["error", "multi-line"],
|
|
20
|
+
"prefer-const": "error",
|
|
21
|
+
"no-var": "error",
|
|
22
|
+
"max-lines": ["error", { max: 600, skipBlankLines: true, skipComments: true }],
|
|
23
|
+
"no-warning-comments": ["error", { terms: ["todo", "fixme", "hack"], location: "anywhere" }],
|
|
24
|
+
"no-comments/disallowComments": ["error", { allow: ["global", "eslint", "/ <reference"] }],
|
|
25
|
+
"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." }],
|
|
26
|
+
"@typescript-eslint/no-unused-vars": ["error", { argsIgnorePattern: "^_", varsIgnorePattern: "^_", caughtErrorsIgnorePattern: "^_", ignoreRestSiblings: true }],
|
|
27
|
+
"@typescript-eslint/no-explicit-any": "error",
|
|
28
|
+
"@typescript-eslint/no-non-null-assertion": "error",
|
|
29
|
+
"@typescript-eslint/explicit-function-return-type": ["error", { allowExpressions: true, allowTypedFunctionExpressions: true, allowHigherOrderFunctions: true, allowDirectConstAssertionInArrowFunctions: true }],
|
|
30
|
+
"@typescript-eslint/consistent-type-imports": ["error", { prefer: "type-imports", fixStyle: "separate-type-imports", disallowTypeAnnotations: false }],
|
|
31
|
+
"@typescript-eslint/restrict-template-expressions": ["error", { allowNumber: true, allowBoolean: true, allowNullish: false, allowRegExp: false }],
|
|
32
|
+
"@typescript-eslint/naming-convention": [
|
|
33
|
+
"error",
|
|
34
|
+
{ selector: "default", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
35
|
+
{ selector: "variable", format: ["camelCase", "UPPER_CASE"], leadingUnderscore: "allow" },
|
|
36
|
+
{ selector: "parameter", format: ["camelCase"], leadingUnderscore: "allow" },
|
|
37
|
+
{ selector: "typeLike", format: ["PascalCase"] },
|
|
38
|
+
{ selector: "property", format: null },
|
|
39
|
+
{ selector: "method", format: ["camelCase"] },
|
|
40
|
+
{ selector: "import", format: null },
|
|
41
|
+
],
|
|
42
|
+
"@typescript-eslint/only-throw-error": "error",
|
|
43
|
+
"@typescript-eslint/unbound-method": ["error", { ignoreStatic: true }],
|
|
44
|
+
"@typescript-eslint/non-nullable-type-assertion-style": "off",
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
]);
|
|
@@ -1,19 +1,26 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "bitbybit-api-hono-sdk-threejs",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.4.0",
|
|
4
4
|
"private": true,
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
7
7
|
"dev": "wrangler dev",
|
|
8
|
-
"deploy": "wrangler deploy"
|
|
8
|
+
"deploy": "wrangler deploy",
|
|
9
|
+
"smoke": "npm run typecheck && npm run lint",
|
|
10
|
+
"typecheck": "tsc --noEmit",
|
|
11
|
+
"lint": "eslint . --max-warnings 0"
|
|
9
12
|
},
|
|
10
13
|
"dependencies": {
|
|
11
14
|
"hono": "^4.7.0",
|
|
12
|
-
"@bitbybit-dev/cad-cloud-sdk": "1.
|
|
15
|
+
"@bitbybit-dev/cad-cloud-sdk": "1.4.0"
|
|
13
16
|
},
|
|
14
17
|
"devDependencies": {
|
|
15
18
|
"@cloudflare/workers-types": "^5.20260903.1",
|
|
16
|
-
"
|
|
17
|
-
"
|
|
19
|
+
"@eslint/js": "10.0.1",
|
|
20
|
+
"eslint": "10.10.0",
|
|
21
|
+
"eslint-plugin-no-comments": "1.2.1",
|
|
22
|
+
"typescript": "5.9.3",
|
|
23
|
+
"typescript-eslint": "8.70.0",
|
|
24
|
+
"wrangler": "^4.129.0"
|
|
18
25
|
}
|
|
19
26
|
}
|
|
@@ -101,18 +101,13 @@ export async function getTaskResult(env: Env, taskId: string): Promise<{ status:
|
|
|
101
101
|
return { status: "completed", downloads };
|
|
102
102
|
}
|
|
103
103
|
|
|
104
|
-
/**
|
|
105
|
-
* Intentionally invalid request — height exceeds the 50cm maximum.
|
|
106
|
-
* The SDK validates against JSON Schema before sending, so this throws
|
|
107
|
-
* a BitbybitValidationError without ever hitting the network.
|
|
108
|
-
*/
|
|
109
104
|
export async function createInvalidCup(env: Env): Promise<never> {
|
|
110
105
|
const client = getClient(env);
|
|
111
106
|
|
|
112
107
|
await client.models.run("dragon-cup", {
|
|
113
108
|
params: {
|
|
114
|
-
height: 999,
|
|
115
|
-
radiusBottom: -5,
|
|
109
|
+
height: 999,
|
|
110
|
+
radiusBottom: -5,
|
|
116
111
|
},
|
|
117
112
|
outputs: {
|
|
118
113
|
formats: ["gltf"],
|
|
@@ -122,14 +117,6 @@ export async function createInvalidCup(env: Env): Promise<never> {
|
|
|
122
117
|
throw new Error("unreachable");
|
|
123
118
|
}
|
|
124
119
|
|
|
125
|
-
// ---------------------------------------------------------------------------
|
|
126
|
-
// Pipeline examples (using typed step() helper)
|
|
127
|
-
// ---------------------------------------------------------------------------
|
|
128
|
-
|
|
129
|
-
/**
|
|
130
|
-
* Translate, Union + Fillet: createBox → translate → union → fillet
|
|
131
|
-
* Creates a box, translates a copy, unions both, fillets the result.
|
|
132
|
-
*/
|
|
133
120
|
export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
134
121
|
const client = getClient(env);
|
|
135
122
|
|
|
@@ -144,10 +131,6 @@ export async function runTranslateUnionFilletPipeline(env: Env): Promise<{ taskI
|
|
|
144
131
|
});
|
|
145
132
|
}
|
|
146
133
|
|
|
147
|
-
/**
|
|
148
|
-
* Map: Cylinders at Positions
|
|
149
|
-
* Parses an array of center positions, maps a cylinder at each, unions the result.
|
|
150
|
-
*/
|
|
151
134
|
export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
152
135
|
const client = getClient(env);
|
|
153
136
|
|
|
@@ -157,7 +140,7 @@ export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: strin
|
|
|
157
140
|
{
|
|
158
141
|
type: "map",
|
|
159
142
|
items: "$ref:0",
|
|
160
|
-
steps: [step("occt.shapes.solid.createCylinder", { radius: 1, height: 5, center: "$item"
|
|
143
|
+
steps: [step("occt.shapes.solid.createCylinder", { radius: 1, height: 5, center: "$item" })],
|
|
161
144
|
},
|
|
162
145
|
step("occt.booleans.union", { shapes: "$ref:5" }),
|
|
163
146
|
],
|
|
@@ -165,10 +148,6 @@ export async function runMapCylindersPipeline(env: Env): Promise<{ taskId: strin
|
|
|
165
148
|
});
|
|
166
149
|
}
|
|
167
150
|
|
|
168
|
-
/**
|
|
169
|
-
* Map: Spheres at Different Radii
|
|
170
|
-
* Creates spheres of radii 1–5 at pre-computed positions, compounds the result.
|
|
171
|
-
*/
|
|
172
151
|
export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
173
152
|
const client = getClient(env);
|
|
174
153
|
|
|
@@ -179,8 +158,8 @@ export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string;
|
|
|
179
158
|
type: "map",
|
|
180
159
|
items: "$ref:0",
|
|
181
160
|
steps: [
|
|
182
|
-
step("math.twoNrOperation", { first: "$index"
|
|
183
|
-
step("occt.shapes.solid.createSphere", { radius: "$prev"
|
|
161
|
+
step("math.twoNrOperation", { first: "$index", second: 1, operation: "add" }),
|
|
162
|
+
step("occt.shapes.solid.createSphere", { radius: "$prev", center: "$item" }),
|
|
184
163
|
],
|
|
185
164
|
},
|
|
186
165
|
step("occt.shapes.compound.makeCompound", { shapes: "$ref:11" }),
|
|
@@ -189,17 +168,13 @@ export async function runMapSpheresPipeline(env: Env): Promise<{ taskId: string;
|
|
|
189
168
|
});
|
|
190
169
|
}
|
|
191
170
|
|
|
192
|
-
/**
|
|
193
|
-
* Choice: Conditional Shape Size
|
|
194
|
-
* Parses a number, increments it, then picks a large box (> 5) or small sphere.
|
|
195
|
-
*/
|
|
196
171
|
export async function runChoicePipeline(env: Env): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
197
172
|
const client = getClient(env);
|
|
198
173
|
|
|
199
174
|
return client.cad.pipelineAndPoll({
|
|
200
175
|
steps: [
|
|
201
176
|
step("json.parse", { text: "10" }),
|
|
202
|
-
step("math.twoNrOperation", { first: "$ref:0"
|
|
177
|
+
step("math.twoNrOperation", { first: "$ref:0", second: 1, operation: "add" }),
|
|
203
178
|
{
|
|
204
179
|
type: "choice",
|
|
205
180
|
value: "$ref:1",
|
|
@@ -213,9 +188,6 @@ export async function runChoicePipeline(env: Env): Promise<{ taskId: string; dow
|
|
|
213
188
|
});
|
|
214
189
|
}
|
|
215
190
|
|
|
216
|
-
/**
|
|
217
|
-
* File-input pipeline: import an uploaded STEP file, fillet all edges, export.
|
|
218
|
-
*/
|
|
219
191
|
export async function runFileInputPipeline(env: Env, fileId: string): Promise<{ taskId: string; downloads: { format: string; downloadUrl: string; filename: string }[] }> {
|
|
220
192
|
const client = getClient(env);
|
|
221
193
|
|
|
@@ -229,9 +201,6 @@ export async function runFileInputPipeline(env: Env, fileId: string): Promise<{
|
|
|
229
201
|
});
|
|
230
202
|
}
|
|
231
203
|
|
|
232
|
-
/**
|
|
233
|
-
* Upload a file via the SDK and get a fileId for use in pipelines.
|
|
234
|
-
*/
|
|
235
204
|
export async function uploadFile(env: Env, fileBuffer: ArrayBuffer, filename: string): Promise<string> {
|
|
236
205
|
const client = getClient(env);
|
|
237
206
|
const result = await client.files.uploadBytes(filename, fileBuffer);
|