bambu-printer-mcp 1.1.81 → 1.1.83
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 +40 -1
- package/dist/cad/contracts.d.ts +424 -0
- package/dist/cad/contracts.js +288 -0
- package/dist/cad/process.d.ts +32 -0
- package/dist/cad/process.js +151 -0
- package/dist/cad/refusal.d.ts +15 -0
- package/dist/cad/refusal.js +30 -0
- package/dist/cad/serial.d.ts +6 -0
- package/dist/cad/serial.js +114 -0
- package/dist/cad/storage.d.ts +34 -0
- package/dist/cad/storage.js +201 -0
- package/dist/cad-engine.d.ts +43 -0
- package/dist/cad-engine.js +546 -0
- package/dist/counterpart/info.js +2 -0
- package/dist/counterpart/remote.js +7 -0
- package/dist/counterpart/schemas.d.ts +33 -0
- package/dist/counterpart/schemas.js +1 -0
- package/dist/counterpart/setup.d.ts +10 -0
- package/dist/counterpart/setup.js +6 -2
- package/dist/design-guidance.js +2 -6
- package/dist/index.js +45 -4
- package/dist/tool-annotations.js +4 -0
- package/package.json +1 -1
- package/src/cad/contracts.ts +317 -0
- package/src/cad/geometry.py +157 -0
- package/src/cad/process.ts +216 -0
- package/src/cad/refusal.ts +34 -0
- package/src/cad/requirements.in +9 -0
- package/src/cad/requirements.lock +69 -0
- package/src/cad/serial.ts +126 -0
- package/src/cad/storage.ts +232 -0
- package/src/cad/worker.py +161 -0
- package/src/cad-engine.ts +794 -0
- package/src/counterpart/info.ts +2 -0
- package/src/counterpart/remote.ts +6 -0
- package/src/counterpart/schemas.ts +2 -0
- package/src/counterpart/setup.ts +12 -2
- package/src/design-guidance.ts +2 -0
- package/src/index.ts +40 -4
- package/src/tool-annotations.ts +4 -0
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
export declare const CAD_SIZE_ESTIMATE: {
|
|
2
|
+
expected_download_bytes: number;
|
|
3
|
+
expected_installed_bytes: number;
|
|
4
|
+
};
|
|
5
|
+
export interface CadStorage {
|
|
6
|
+
expected_download_bytes: number;
|
|
7
|
+
expected_installed_bytes: number;
|
|
8
|
+
installed_bytes: number | null;
|
|
9
|
+
measurement: "allocated-last-setup";
|
|
10
|
+
measured_at?: string;
|
|
11
|
+
}
|
|
12
|
+
export declare function storageInfo(marker: {
|
|
13
|
+
installed_bytes?: unknown;
|
|
14
|
+
measured_at?: unknown;
|
|
15
|
+
} | undefined, exists: boolean): CadStorage;
|
|
16
|
+
/** Allocated filesystem bytes, like du; no symlink traversal or double-counted hardlinks. */
|
|
17
|
+
export declare function measureEnvironment(data: string): Promise<number>;
|
|
18
|
+
/** Each immutable bundle contains exactly the declared files, retaining linked asset basenames. */
|
|
19
|
+
export declare function snapshotInputs(root: string, files: Record<string, string>, signal?: AbortSignal, index?: {
|
|
20
|
+
directory: string;
|
|
21
|
+
authorize: (directory: string) => Promise<string>;
|
|
22
|
+
}): Promise<{
|
|
23
|
+
inputs: Record<string, string>;
|
|
24
|
+
hashes: Record<string, string>;
|
|
25
|
+
directory: null;
|
|
26
|
+
added: number;
|
|
27
|
+
reused: number;
|
|
28
|
+
} | {
|
|
29
|
+
inputs: Record<string, string>;
|
|
30
|
+
hashes: Record<string, string>;
|
|
31
|
+
directory: string;
|
|
32
|
+
added: number;
|
|
33
|
+
reused: number;
|
|
34
|
+
}>;
|
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { createReadStream } from "node:fs";
|
|
3
|
+
import path from "node:path";
|
|
4
|
+
import { createHash, randomUUID } from "node:crypto";
|
|
5
|
+
// Budget estimates for the shipped pins, including managed Python and retained uv cache.
|
|
6
|
+
export const CAD_SIZE_ESTIMATE = {
|
|
7
|
+
expected_download_bytes: 350 * 1024 ** 2,
|
|
8
|
+
expected_installed_bytes: 1536 * 1024 ** 2,
|
|
9
|
+
};
|
|
10
|
+
export function storageInfo(marker, exists) {
|
|
11
|
+
return {
|
|
12
|
+
...CAD_SIZE_ESTIMATE,
|
|
13
|
+
installed_bytes: typeof marker?.installed_bytes === "number" &&
|
|
14
|
+
Number.isFinite(marker.installed_bytes) &&
|
|
15
|
+
marker.installed_bytes >= 0
|
|
16
|
+
? marker.installed_bytes
|
|
17
|
+
: exists
|
|
18
|
+
? null
|
|
19
|
+
: 0,
|
|
20
|
+
measurement: "allocated-last-setup",
|
|
21
|
+
...(typeof marker?.measured_at === "string"
|
|
22
|
+
? { measured_at: marker.measured_at }
|
|
23
|
+
: {}),
|
|
24
|
+
};
|
|
25
|
+
}
|
|
26
|
+
/** Allocated filesystem bytes, like du; no symlink traversal or double-counted hardlinks. */
|
|
27
|
+
export async function measureEnvironment(data) {
|
|
28
|
+
const seen = new Set();
|
|
29
|
+
let bytes = 0;
|
|
30
|
+
async function walk(file) {
|
|
31
|
+
const stat = await fs.lstat(file).catch((e) => {
|
|
32
|
+
if (e.code === "ENOENT")
|
|
33
|
+
return null;
|
|
34
|
+
throw e;
|
|
35
|
+
});
|
|
36
|
+
if (!stat)
|
|
37
|
+
return;
|
|
38
|
+
const key = `${stat.dev}:${stat.ino}`;
|
|
39
|
+
if (seen.has(key))
|
|
40
|
+
return;
|
|
41
|
+
seen.add(key);
|
|
42
|
+
bytes += stat.blocks * 512;
|
|
43
|
+
if (stat.isDirectory())
|
|
44
|
+
for (const name of await fs.readdir(file))
|
|
45
|
+
await walk(path.join(file, name));
|
|
46
|
+
}
|
|
47
|
+
for (const name of ["runtime", "python", "cache"])
|
|
48
|
+
await walk(path.join(data, name));
|
|
49
|
+
return bytes;
|
|
50
|
+
}
|
|
51
|
+
async function digest(file, signal) {
|
|
52
|
+
const hash = createHash("sha256");
|
|
53
|
+
let bytes = 0;
|
|
54
|
+
signal?.throwIfAborted();
|
|
55
|
+
const stream = createReadStream(file);
|
|
56
|
+
const abort = () => {
|
|
57
|
+
const error = new Error("CAD input snapshot cancelled.");
|
|
58
|
+
error.name = "AbortError";
|
|
59
|
+
stream.destroy(error);
|
|
60
|
+
};
|
|
61
|
+
signal?.addEventListener("abort", abort, { once: true });
|
|
62
|
+
try {
|
|
63
|
+
for await (const chunk of stream) {
|
|
64
|
+
signal?.throwIfAborted();
|
|
65
|
+
bytes += chunk.length;
|
|
66
|
+
if (bytes > 64 * 1024 ** 2)
|
|
67
|
+
throw new Error("CAD input exceeds 64 MiB.");
|
|
68
|
+
hash.update(chunk);
|
|
69
|
+
}
|
|
70
|
+
return { hash: hash.digest("hex"), bytes };
|
|
71
|
+
}
|
|
72
|
+
finally {
|
|
73
|
+
signal?.removeEventListener("abort", abort);
|
|
74
|
+
stream.destroy();
|
|
75
|
+
}
|
|
76
|
+
}
|
|
77
|
+
/** Each immutable bundle contains exactly the declared files, retaining linked asset basenames. */
|
|
78
|
+
export async function snapshotInputs(root, files, signal, index) {
|
|
79
|
+
const entries = [];
|
|
80
|
+
let bytes = 0;
|
|
81
|
+
const names = new Set();
|
|
82
|
+
for (const [alias, file] of Object.entries(files)) {
|
|
83
|
+
const name = path.basename(file);
|
|
84
|
+
if (names.has(name.toLowerCase()))
|
|
85
|
+
throw new Error("CAD input files must have distinct original filenames so linked mesh/texture assets remain unambiguous.");
|
|
86
|
+
names.add(name.toLowerCase());
|
|
87
|
+
const content = await digest(file, signal);
|
|
88
|
+
bytes += content.bytes;
|
|
89
|
+
if (bytes > 256 * 1024 ** 2)
|
|
90
|
+
throw new Error("CAD inputs exceed their 256 MiB total limit.");
|
|
91
|
+
entries.push({ alias, file, name, ...content });
|
|
92
|
+
}
|
|
93
|
+
const inputs = {}, hashes = {};
|
|
94
|
+
if (!entries.length)
|
|
95
|
+
return { inputs, hashes, directory: null, added: 0, reused: 0 };
|
|
96
|
+
const identity = entries
|
|
97
|
+
.map(({ name, hash, bytes }) => ({ name, hash, bytes }))
|
|
98
|
+
.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));
|
|
99
|
+
const id = createHash("sha256")
|
|
100
|
+
.update(JSON.stringify(identity))
|
|
101
|
+
.digest("hex");
|
|
102
|
+
const cache = path.join(root, ".cad-inputs"), directory = path.join(cache, id);
|
|
103
|
+
async function verify(directory) {
|
|
104
|
+
if (!(await fs.lstat(directory)).isDirectory())
|
|
105
|
+
throw new Error("CAD input bundle must be a directory, not a link.");
|
|
106
|
+
const found = await fs.readdir(directory);
|
|
107
|
+
if (found.length !== entries.length ||
|
|
108
|
+
found.some((n) => !entries.some((e) => e.name === n)))
|
|
109
|
+
throw new Error("CAD input bundle contains undeclared files.");
|
|
110
|
+
for (const entry of entries) {
|
|
111
|
+
const file = path.join(directory, entry.name);
|
|
112
|
+
if (!(await fs.lstat(file)).isFile())
|
|
113
|
+
throw new Error("CAD cached input is not a regular file.");
|
|
114
|
+
const actual = await digest(file, signal);
|
|
115
|
+
if (actual.hash !== entry.hash || actual.bytes !== entry.bytes)
|
|
116
|
+
throw new Error("CAD input cache failed its content hash check.");
|
|
117
|
+
}
|
|
118
|
+
}
|
|
119
|
+
const candidates = new Set(Object.values(files).map((file) => path.dirname(file)));
|
|
120
|
+
if (index) {
|
|
121
|
+
try {
|
|
122
|
+
const known = JSON.parse(await fs.readFile(path.join(index.directory, id + ".json"), "utf8"));
|
|
123
|
+
if (typeof known.directory === "string")
|
|
124
|
+
candidates.add(known.directory);
|
|
125
|
+
}
|
|
126
|
+
catch {
|
|
127
|
+
/* An absent/stale index is rebuilt from declared content. */
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
for (const candidate of candidates) {
|
|
131
|
+
if (path.basename(candidate) !== id ||
|
|
132
|
+
path.basename(path.dirname(candidate)) !== ".cad-inputs")
|
|
133
|
+
continue;
|
|
134
|
+
try {
|
|
135
|
+
if (index)
|
|
136
|
+
await index.authorize(candidate);
|
|
137
|
+
await verify(candidate);
|
|
138
|
+
for (const entry of entries) {
|
|
139
|
+
inputs[entry.alias] = path.join(candidate, entry.name);
|
|
140
|
+
hashes[entry.alias] = entry.hash;
|
|
141
|
+
}
|
|
142
|
+
return { inputs, hashes, directory: candidate, added: 0, reused: bytes };
|
|
143
|
+
}
|
|
144
|
+
catch {
|
|
145
|
+
/* Do not expose a stale, out-of-policy or incomplete bundle. */
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
await fs.mkdir(cache, { recursive: true, mode: 0o700 });
|
|
149
|
+
if ((await fs.lstat(cache)).isSymbolicLink())
|
|
150
|
+
throw new Error("CAD input cache must not be a symlink.");
|
|
151
|
+
let added = 0;
|
|
152
|
+
try {
|
|
153
|
+
await verify(directory);
|
|
154
|
+
}
|
|
155
|
+
catch (e) {
|
|
156
|
+
if (e.code !== "ENOENT")
|
|
157
|
+
throw e;
|
|
158
|
+
const stage = await fs.mkdtemp(path.join(cache, ".stage-"));
|
|
159
|
+
try {
|
|
160
|
+
for (const entry of entries) {
|
|
161
|
+
const file = path.join(stage, entry.name);
|
|
162
|
+
await fs.copyFile(entry.file, file);
|
|
163
|
+
const copied = await digest(file, signal);
|
|
164
|
+
if (copied.hash !== entry.hash || copied.bytes !== entry.bytes)
|
|
165
|
+
throw new Error("CAD input changed while snapshotting; no run was dispatched.");
|
|
166
|
+
await fs.chmod(file, 0o444);
|
|
167
|
+
}
|
|
168
|
+
try {
|
|
169
|
+
await fs.rename(stage, directory);
|
|
170
|
+
added = bytes;
|
|
171
|
+
}
|
|
172
|
+
catch (e) {
|
|
173
|
+
if (!["EEXIST", "ENOTEMPTY"].includes(e.code))
|
|
174
|
+
throw e;
|
|
175
|
+
await verify(directory);
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
finally {
|
|
179
|
+
await fs.rm(stage, { recursive: true, force: true });
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
if (index) {
|
|
183
|
+
await fs.mkdir(index.directory, { recursive: true, mode: 0o700 });
|
|
184
|
+
const temporary = path.join(index.directory, ".new-" + randomUUID());
|
|
185
|
+
try {
|
|
186
|
+
await fs.writeFile(temporary, JSON.stringify({ directory }), {
|
|
187
|
+
flag: "wx",
|
|
188
|
+
mode: 0o600,
|
|
189
|
+
});
|
|
190
|
+
await fs.rename(temporary, path.join(index.directory, id + ".json"));
|
|
191
|
+
}
|
|
192
|
+
finally {
|
|
193
|
+
await fs.unlink(temporary).catch(() => { });
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
for (const entry of entries) {
|
|
197
|
+
inputs[entry.alias] = path.join(directory, entry.name);
|
|
198
|
+
hashes[entry.alias] = entry.hash;
|
|
199
|
+
}
|
|
200
|
+
return { inputs, hashes, directory, added, reused: bytes - added };
|
|
201
|
+
}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { type CadStorage } from "./cad/storage.js";
|
|
2
|
+
import { type CadSystem } from "./cad/process.js";
|
|
3
|
+
export type CadArguments = Record<string, unknown>;
|
|
4
|
+
export interface CadOptions {
|
|
5
|
+
dataDir?: string;
|
|
6
|
+
outputRoots: string[];
|
|
7
|
+
system?: CadSystem;
|
|
8
|
+
}
|
|
9
|
+
export interface CadStatus {
|
|
10
|
+
configured: boolean;
|
|
11
|
+
ready: boolean;
|
|
12
|
+
python: string | null;
|
|
13
|
+
build123d: string;
|
|
14
|
+
platform: string;
|
|
15
|
+
storage: CadStorage;
|
|
16
|
+
error?: string;
|
|
17
|
+
}
|
|
18
|
+
export declare class CadEngine {
|
|
19
|
+
private readonly options;
|
|
20
|
+
private readonly system;
|
|
21
|
+
readonly dataDir: string;
|
|
22
|
+
constructor(options: CadOptions);
|
|
23
|
+
status(): Promise<CadStatus>;
|
|
24
|
+
failure(error: unknown, tool: string): Promise<{
|
|
25
|
+
storage: CadStorage;
|
|
26
|
+
status: "error";
|
|
27
|
+
code: "cad-uv-missing" | "cad-data-volume-refused" | "cad-setup-busy" | "cad-operation-busy" | "cad-queue-timeout" | "cad-not-ready" | "cad-confinement-unavailable" | "cad-disabled" | "cad-failed";
|
|
28
|
+
message: string;
|
|
29
|
+
tool: string;
|
|
30
|
+
retryable: boolean;
|
|
31
|
+
suggestion: string;
|
|
32
|
+
}>;
|
|
33
|
+
private allowedDirectory;
|
|
34
|
+
private environment;
|
|
35
|
+
private exclusive;
|
|
36
|
+
private confined;
|
|
37
|
+
setup(args: CadArguments, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
38
|
+
private fingerprint;
|
|
39
|
+
private requireSupportedStorage;
|
|
40
|
+
private inputFile;
|
|
41
|
+
run(args: CadArguments, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
42
|
+
checkFit(args: CadArguments, signal?: AbortSignal): Promise<Record<string, unknown>>;
|
|
43
|
+
}
|