bambu-printer-mcp 1.1.91 → 1.1.93
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/CONTRIBUTORS.md +2 -0
- package/README.md +8 -4
- package/dist/bambu-native.js +1 -1
- package/dist/cad/contracts.js +16 -7
- package/dist/cad/examples.d.ts +2 -1
- package/dist/cad/examples.js +13 -10
- package/dist/cad/serial.d.ts +1 -1
- package/dist/cad/serial.js +4 -6
- package/dist/cad-engine.js +17 -12
- package/dist/counterpart/info.d.ts +2 -0
- package/dist/counterpart/info.js +6 -1
- package/dist/counterpart/remote.js +1 -0
- package/dist/counterpart/schemas.d.ts +5 -0
- package/dist/counterpart/schemas.js +1 -0
- package/dist/counterpart/self-check.d.ts +79 -0
- package/dist/counterpart/self-check.js +163 -0
- package/dist/index.js +50 -24
- package/dist/printers/bambu.d.ts +6 -0
- package/dist/printers/bambu.js +59 -25
- package/dist/printers/report-merge.d.ts +12 -0
- package/dist/printers/report-merge.js +46 -0
- package/dist/safety/limits.d.ts +6 -0
- package/dist/safety/limits.js +8 -0
- package/dist/safety/print-file.js +2 -2
- package/dist/safety/printer-state.d.ts +4 -0
- package/dist/safety/printer-state.js +14 -1
- package/dist/stl/stl-manipulator.js +79 -20
- package/dist/studio-print-options.d.ts +9 -0
- package/dist/studio-print-options.js +34 -2
- package/dist/tool-annotations.js +1 -0
- package/package.json +6 -1
- package/src/bambu-native.ts +1 -1
- package/src/cad/contracts.ts +17 -7
- package/src/cad/examples/bag_clip.py +1 -0
- package/src/cad/examples/bistable_clicker.py +1 -0
- package/src/cad/examples/broom_grip.py +61 -0
- package/src/cad/examples/cable_clip.py +1 -0
- package/src/cad/examples/chainmail.py +1 -0
- package/src/cad/examples/desk_clamp_hook.py +91 -0
- package/src/cad/examples/desk_edge_cable_holder.py +55 -0
- package/src/cad/examples/drawer_divider.py +56 -0
- package/src/cad/examples/hinged_box.py +1 -0
- package/src/cad/examples/knurled_knob.py +1 -0
- package/src/cad/examples/loft_handle.py +1 -0
- package/src/cad/examples/organizer_tray.py +41 -0
- package/src/cad/examples/phone_stand.py +1 -0
- package/src/cad/examples/plant_pot.py +53 -0
- package/src/cad/examples/shelf_bracket.py +53 -0
- package/src/cad/examples/swept_hook.py +1 -0
- package/src/cad/examples/threaded_jar.py +1 -0
- package/src/cad/examples/trigger_capo.py +1 -0
- package/src/cad/examples/wall_hook.py +1 -0
- package/src/cad/examples.ts +13 -10
- package/src/cad/geometry.py +6 -0
- package/src/cad/serial.ts +4 -6
- package/src/cad-engine.ts +9 -3
- package/src/counterpart/info.ts +7 -1
- package/src/counterpart/remote.ts +1 -0
- package/src/counterpart/schemas.ts +3 -1
- package/src/counterpart/self-check.ts +164 -0
- package/src/index.ts +48 -20
- package/src/printers/bambu.ts +57 -24
- package/src/printers/report-merge.ts +48 -0
- package/src/safety/limits.ts +8 -0
- package/src/safety/print-file.ts +2 -2
- package/src/safety/printer-state.ts +13 -1
- package/src/stl/stl-manipulator.ts +75 -14
- package/src/studio-print-options.ts +33 -2
- package/src/tool-annotations.ts +1 -0
|
@@ -40,6 +40,7 @@ export const REMOTE_SCOPES: Readonly<Record<string, RemoteScope>> = {
|
|
|
40
40
|
inspect_print_file: "read",
|
|
41
41
|
blender_mcp_status: "read",
|
|
42
42
|
counterpart_printer_info: "read",
|
|
43
|
+
counterpart_self_check: "read",
|
|
43
44
|
counterpart_print_progress: "read",
|
|
44
45
|
counterpart_print_record: "read",
|
|
45
46
|
counterpart_print_assess: "control", // local evidence mutation, never a printer command
|
|
@@ -28,7 +28,8 @@ export type PrintProgress = {
|
|
|
28
28
|
export type PrinterInfo = {
|
|
29
29
|
contract: typeof COUNTERPART_CONTRACT;
|
|
30
30
|
server: { name: string; version: string };
|
|
31
|
-
|
|
31
|
+
/** displayName: the model with its maker ("Bambu Lab P1S"), shown as given; absent when the model is unknown. */
|
|
32
|
+
printer: { kind: typeof PRINTER_KINDS[number]; model?: string; displayName?: string; serial?: string; host: string; name?: string };
|
|
32
33
|
capabilities: {
|
|
33
34
|
cad?: {contract: string; status: string; setup: string; run: string; checkFit: string; prompt: string};
|
|
34
35
|
progress: boolean; layers: boolean;
|
|
@@ -61,6 +62,7 @@ export const PRINTER_INFO_OUTPUT_SCHEMA = {
|
|
|
61
62
|
properties: {
|
|
62
63
|
kind: { type: "string", enum: [...PRINTER_KINDS] },
|
|
63
64
|
model: { type: "string" },
|
|
65
|
+
displayName: { type: "string" },
|
|
64
66
|
serial: { type: "string" },
|
|
65
67
|
host: { type: "string" },
|
|
66
68
|
name: { type: "string" },
|
|
@@ -0,0 +1,164 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* counterpart_self_check (counterpart/1): whether this install's own runtime dependencies and the bundled bambu-node
|
|
3
|
+
* patch loaded, so a client that updated the server can tell a broken install from a working one. Local only: it
|
|
4
|
+
* loads modules from this server's own install and sends nothing to a printer.
|
|
5
|
+
*/
|
|
6
|
+
import fs from "node:fs";
|
|
7
|
+
import { createRequire } from "node:module";
|
|
8
|
+
import path from "node:path";
|
|
9
|
+
import { fileURLToPath } from "node:url";
|
|
10
|
+
import { COUNTERPART_CONTRACT } from "./schemas.js";
|
|
11
|
+
|
|
12
|
+
/** optional: an optional dependency, whose failure does not make ok false (mcp-3D-printer-server has one; this server none). */
|
|
13
|
+
export type SelfCheck = { name: string; ok: boolean; optional?: boolean; version?: string; message?: string };
|
|
14
|
+
export type SelfCheckResult = {
|
|
15
|
+
contract: typeof COUNTERPART_CONTRACT;
|
|
16
|
+
server: { name: string; version: string };
|
|
17
|
+
ok: boolean;
|
|
18
|
+
checks: SelfCheck[];
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const SELF_CHECK_OUTPUT_SCHEMA = {
|
|
22
|
+
type: "object" as const,
|
|
23
|
+
properties: {
|
|
24
|
+
contract: { type: "string", const: COUNTERPART_CONTRACT },
|
|
25
|
+
server: { type: "object", properties: { name: { type: "string" }, version: { type: "string" } }, required: ["name", "version"] },
|
|
26
|
+
ok: { type: "boolean", description: "Every check passed, optional dependencies aside." },
|
|
27
|
+
checks: {
|
|
28
|
+
type: "array",
|
|
29
|
+
items: {
|
|
30
|
+
type: "object",
|
|
31
|
+
properties: { name: { type: "string" }, ok: { type: "boolean" }, optional: { type: "boolean" }, version: { type: "string" }, message: { type: "string" } },
|
|
32
|
+
required: ["name", "ok"],
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
},
|
|
36
|
+
required: ["contract", "server", "ok", "checks"],
|
|
37
|
+
};
|
|
38
|
+
|
|
39
|
+
const PACKAGE_JSON = new URL("../../package.json", import.meta.url);
|
|
40
|
+
/** The module each dependency is loaded through, where its package root is not importable on its own. */
|
|
41
|
+
const ENTRIES: Record<string, string> = {
|
|
42
|
+
"@modelcontextprotocol/sdk": "@modelcontextprotocol/sdk/server/index.js",
|
|
43
|
+
// Only its patch parser runs, at install (scripts/install-patches.mjs); its root is the CLI.
|
|
44
|
+
"patch-package": "patch-package/dist/patch/parse.js",
|
|
45
|
+
};
|
|
46
|
+
|
|
47
|
+
/** The version in the package.json of name that contains file, from this install. */
|
|
48
|
+
function installedVersion(file: string, name: string): string | undefined {
|
|
49
|
+
for (let dir = path.dirname(file); dir !== path.dirname(dir); dir = path.dirname(dir)) {
|
|
50
|
+
const manifest = path.join(dir, "package.json");
|
|
51
|
+
if (!fs.existsSync(manifest)) continue;
|
|
52
|
+
try {
|
|
53
|
+
const parsed = JSON.parse(fs.readFileSync(manifest, "utf8"));
|
|
54
|
+
if (parsed?.name === name) return typeof parsed.version === "string" ? parsed.version : undefined;
|
|
55
|
+
} catch { /* a malformed manifest is not this package's */ }
|
|
56
|
+
}
|
|
57
|
+
return undefined;
|
|
58
|
+
}
|
|
59
|
+
|
|
60
|
+
/** The file specifier resolves to from this module (import.meta.resolve needs Node.js 18.19 or 20.6; older ones require). */
|
|
61
|
+
function resolveFromHere(specifier: string): string {
|
|
62
|
+
return typeof import.meta.resolve === "function"
|
|
63
|
+
? fileURLToPath(import.meta.resolve(specifier))
|
|
64
|
+
: createRequire(import.meta.url).resolve(specifier);
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
const message = (error: unknown) => error instanceof Error ? error.message : String(error);
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* Whether version meets declared, for the forms package.json uses: x.y.z exactly, ^x.y.z (the leftmost non-zero
|
|
71
|
+
* part stays) or ~x.y.z (the minor stays). Other forms are not judged (undefined).
|
|
72
|
+
*/
|
|
73
|
+
export function meetsDeclared(version: string, declared: string): boolean | undefined {
|
|
74
|
+
const want = /^([~^]?)(\d+)\.(\d+)\.(\d+)$/.exec(declared.trim());
|
|
75
|
+
const have = /^(\d+)\.(\d+)\.(\d+)(-)?/.exec(version);
|
|
76
|
+
if (!want || !have) return undefined;
|
|
77
|
+
// A prerelease (3.22.21-beta.1) meets none of these forms.
|
|
78
|
+
if (have[4]) return false;
|
|
79
|
+
const [w0, w1, w2] = want.slice(2).map(Number), [h0, h1, h2] = have.slice(1, 4).map(Number);
|
|
80
|
+
const order = h0 - w0 || h1 - w1 || h2 - w2;
|
|
81
|
+
if (want[1] === "") return order === 0;
|
|
82
|
+
if (order < 0) return false;
|
|
83
|
+
if (want[1] === "~") return h0 === w0 && h1 === w1;
|
|
84
|
+
return w0 > 0 ? h0 === w0 : w1 > 0 ? h0 === 0 && h1 === w1 : h0 === 0 && h1 === 0 && h2 === w2;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
/** Why the installed version does not meet package.json's, or undefined when it does. A form not judged is a failure. */
|
|
88
|
+
export function versionProblem(name: string, version: string | undefined, declared: string): string | undefined {
|
|
89
|
+
const meets = meetsDeclared(version ?? "", declared);
|
|
90
|
+
if (meets === true) return undefined;
|
|
91
|
+
if (meets === undefined && version !== undefined) return `This check cannot judge ${name}'s declared version "${declared}"; ${version} is installed.`;
|
|
92
|
+
return `This server needs ${name} ${declared}; ${version ?? "an unknown version"} is installed.`;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
/** One dependency: it resolves from this install, loads, and its installed version meets package.json's. */
|
|
96
|
+
async function dependencyCheck(name: string, declared: string): Promise<SelfCheck> {
|
|
97
|
+
const specifier = ENTRIES[name] ?? name;
|
|
98
|
+
try {
|
|
99
|
+
const file = resolveFromHere(specifier);
|
|
100
|
+
const version = installedVersion(file, name);
|
|
101
|
+
await import(specifier);
|
|
102
|
+
const problem = versionProblem(name, version, declared);
|
|
103
|
+
if (problem) return { name, ok: false, ...(version ? { version } : {}), message: problem };
|
|
104
|
+
return { name, ok: true, ...(version ? { version } : {}) };
|
|
105
|
+
} catch (error) {
|
|
106
|
+
return { name, ok: false, message: `${name} did not load: ${message(error)}` };
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** Every hunk of the bundled patch is in the installed bambu-node: a read-only reverse dry run, as postinstall checks. */
|
|
111
|
+
function patchApplied(version: string): void {
|
|
112
|
+
const require = createRequire(import.meta.url);
|
|
113
|
+
const root = fs.realpathSync(path.dirname(require.resolve("bambu-node/package.json")));
|
|
114
|
+
const { parsePatchFile } = require("patch-package/dist/patch/parse.js");
|
|
115
|
+
const { executeEffects } = require("patch-package/dist/patch/apply.js");
|
|
116
|
+
const { reversePatch } = require("patch-package/dist/patch/reverse.js");
|
|
117
|
+
const patch = fs.readFileSync(new URL(`../../patches/bambu-node+${version}.patch`, import.meta.url), "utf8");
|
|
118
|
+
const effects = parsePatchFile(patch).map((effect: { type: string; path: string }) => {
|
|
119
|
+
if (effect.type !== "patch" || !effect.path.startsWith("node_modules/bambu-node/")) throw new Error("the bundled patch has an unexpected target");
|
|
120
|
+
return { ...effect, path: effect.path.slice("node_modules/bambu-node/".length) };
|
|
121
|
+
});
|
|
122
|
+
try {
|
|
123
|
+
executeEffects(reversePatch(effects), { cwd: root, dryRun: true, bestEffort: false });
|
|
124
|
+
} catch {
|
|
125
|
+
throw new Error(`the installed bambu-node ${version} is missing part of this server's patch`);
|
|
126
|
+
}
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* The bundled patch (patches/bambu-node+<version>.patch) is in the installed bambu-node, and the loaded module
|
|
131
|
+
* behaves patched: it adds the H2-series and later printers to model detection, so an unpatched bambu-node throws
|
|
132
|
+
* "Printer model not supported!" on an H2D's version report. The report is read in memory, without a connection.
|
|
133
|
+
*/
|
|
134
|
+
async function bambuNodePatchCheck(version: string | undefined): Promise<SelfCheck> {
|
|
135
|
+
const name = "bambu-node patch";
|
|
136
|
+
try {
|
|
137
|
+
if (!version) throw new Error("package.json names no bambu-node version");
|
|
138
|
+
patchApplied(version);
|
|
139
|
+
const { BambuClient } = await import("bambu-node");
|
|
140
|
+
const serial = "094SELFCHECK";
|
|
141
|
+
const client = new BambuClient({ host: "127.0.0.1", serialNumber: serial, accessToken: "self-check" });
|
|
142
|
+
await (client as any).onMessage(JSON.stringify({ info: { command: "get_version", module: [{ name: "ota", sn: serial }] } }), `device/${serial}/report`);
|
|
143
|
+
const model = (client as any).data?.model;
|
|
144
|
+
return model === "H2D" ? { name, ok: true } : { name, ok: false, message: `bambu-node read an H2D as ${String(model)}; reinstall this server so its patch is applied.` };
|
|
145
|
+
} catch (error) {
|
|
146
|
+
return { name, ok: false, message: `bambu-node is not patched: ${message(error)}. Reinstall this server so its patch is applied.` };
|
|
147
|
+
}
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
export async function selfCheck(server: { name: string; version: string }): Promise<SelfCheckResult> {
|
|
151
|
+
let dependencies: Record<string, string> = {};
|
|
152
|
+
const checks: SelfCheck[] = [];
|
|
153
|
+
try {
|
|
154
|
+
const manifest = JSON.parse(fs.readFileSync(PACKAGE_JSON, "utf8"));
|
|
155
|
+
dependencies = manifest.dependencies ?? {};
|
|
156
|
+
if (manifest.version !== server.version) checks.push({ name: "package", ok: false, version: String(manifest.version), message: `The running server is ${server.version}, but its install is ${manifest.version}; restart it.` });
|
|
157
|
+
else checks.push({ name: "package", ok: true, version: server.version });
|
|
158
|
+
} catch (error) {
|
|
159
|
+
checks.push({ name: "package", ok: false, message: `Could not read this server's package.json: ${message(error)}` });
|
|
160
|
+
}
|
|
161
|
+
checks.push(...await Promise.all(Object.entries(dependencies).map(([name, declared]) => dependencyCheck(name, declared))));
|
|
162
|
+
checks.push(await bambuNodePatchCheck(dependencies["bambu-node"]));
|
|
163
|
+
return { contract: COUNTERPART_CONTRACT, server, ok: checks.every(check => check.ok || check.optional), checks };
|
|
164
|
+
}
|
package/src/index.ts
CHANGED
|
@@ -76,7 +76,7 @@ import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } f
|
|
|
76
76
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
77
77
|
import { previewPrintFile } from "./safety/print-preview.js";
|
|
78
78
|
import { loadSafe3mfArchive } from "./safety/archive.js";
|
|
79
|
-
import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
79
|
+
import { SERIAL_MODELS, internalPrintingSupported, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
80
80
|
import { isDualNozzleModel } from "./safety/limits.js";
|
|
81
81
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName } from "./safety/artifact.js";
|
|
82
82
|
import { detectProfilesRoot } from "./slicer/profile-flatten.js";
|
|
@@ -88,6 +88,7 @@ import { DESIGN_PROMPTS, FDM_CAPABILITY_GUIDANCE, FDM_CAPABILITY_RESOURCE, FDM_C
|
|
|
88
88
|
import { bambuProgress, offlineProgress } from "./counterpart/progress.js";
|
|
89
89
|
import { makeCounterpart3mf } from "./counterpart/make-3mf.js";
|
|
90
90
|
import { MAKE_3MF_OUTPUT_SCHEMA, PRINT_PROGRESS_OUTPUT_SCHEMA, PRINTER_INFO_OUTPUT_SCHEMA } from "./counterpart/schemas.js";
|
|
91
|
+
import { SELF_CHECK_OUTPUT_SCHEMA, selfCheck } from "./counterpart/self-check.js";
|
|
91
92
|
import { parseProcessOverrides } from "./slicer/process-overrides.js";
|
|
92
93
|
import { PRINT_QUALITY_PROPERTIES, withPrintQuality } from "./slicer/print-quality.js";
|
|
93
94
|
import { PrinterRefusal, withPrintDispatch, markPrintCommandSent, printOutcome } from "./refusal.js";
|
|
@@ -161,7 +162,7 @@ const SERVER_INFO = {
|
|
|
161
162
|
/** Tools that declare an outputSchema: they always return structuredContent, and errors carry none. */
|
|
162
163
|
const OUTPUT_SCHEMA_TOOLS = new Set([
|
|
163
164
|
"cad_status", "cad_setup", "cad_run", "cad_check_fit", "cad_examples",
|
|
164
|
-
"counterpart_printer_info", "counterpart_print_progress", "counterpart_make_3mf",
|
|
165
|
+
"counterpart_printer_info", "counterpart_self_check", "counterpart_print_progress", "counterpart_make_3mf",
|
|
165
166
|
"counterpart_discover_printers", "counterpart_setup_fields", "counterpart_propose_filaments",
|
|
166
167
|
"fusion_mcp_status", "fusion_mcp_new_design", "fusion_mcp_export",
|
|
167
168
|
"camera_stream_start", "camera_frame", "camera_stream_stop",
|
|
@@ -184,17 +185,26 @@ function withEmergencyMqttTimeout<T>(send: (signal: AbortSignal) => Promise<T>):
|
|
|
184
185
|
}
|
|
185
186
|
|
|
186
187
|
/**
|
|
187
|
-
* Whether
|
|
188
|
+
* Whether a native print stores its job on the SD card or USB stick
|
|
188
189
|
* (true) or internal storage (eMMC). An explicit try_emmc_print wins, then
|
|
189
190
|
* BAMBU_NATIVE_TRY_EMMC_PRINT read as the helper reads it; otherwise a ready
|
|
190
191
|
* card is used, as OrcaSlicer does, so the job can be reprinted from the
|
|
191
|
-
* printer and read over FTPS.
|
|
192
|
+
* printer and read over FTPS. X1C internal printing additionally requires
|
|
193
|
+
* the capability bit from fresh status, including at final dispatch.
|
|
192
194
|
*/
|
|
193
|
-
function nativeExternalStorage(tryEmmcPrint: boolean | undefined, raw: unknown): boolean {
|
|
194
|
-
if (tryEmmcPrint !== undefined) return !tryEmmcPrint;
|
|
195
|
+
function nativeExternalStorage(tryEmmcPrint: boolean | undefined, raw: unknown, model: string): boolean {
|
|
195
196
|
const configured = process.env.BAMBU_NATIVE_TRY_EMMC_PRINT?.trim();
|
|
196
|
-
|
|
197
|
-
|
|
197
|
+
const external = tryEmmcPrint !== undefined ? !tryEmmcPrint
|
|
198
|
+
: configured ? !["1", "true", "TRUE", "yes"].includes(configured)
|
|
199
|
+
: externalStorageState(raw) === "normal";
|
|
200
|
+
if (!external) assertNativeInternalStorage(model, raw);
|
|
201
|
+
return external;
|
|
202
|
+
}
|
|
203
|
+
|
|
204
|
+
function assertNativeInternalStorage(model: string, raw: unknown): void {
|
|
205
|
+
if (model === "x1c" && !internalPrintingSupported(raw)) {
|
|
206
|
+
throw new Error("X1C internal printing is not advertised in the fresh status. Use a ready SD card or USB stick; unsupported internal storage requests are refused.");
|
|
207
|
+
}
|
|
198
208
|
}
|
|
199
209
|
|
|
200
210
|
function requestedPrintNozzles(args: Record<string, any>): number[] | undefined {
|
|
@@ -248,6 +258,11 @@ type BambuModel = typeof VALID_BAMBU_MODELS[number];
|
|
|
248
258
|
// the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
|
|
249
259
|
// jobs take the correct branch instead of the legacy 5-slot mapping.
|
|
250
260
|
const H2_BAMBU_MODELS = new Set<string>(["h2d", "h2dpro", "h2s", "h2c", "x2d"]);
|
|
261
|
+
// Models that may print and upload over connection_mode=bambu_native. X2D
|
|
262
|
+
// defaults to it. X1C opts in: firmware 01.12.00.00 was seen refusing every
|
|
263
|
+
// direct FTPS STOR with 553 while Bambu Studio's plug-in still printed.
|
|
264
|
+
const NATIVE_ROUTE_MODELS = new Set<string>(["x2d", "x1c"]);
|
|
265
|
+
const NATIVE_ROUTE_RESTRICTION = "connection_mode=bambu_native is restricted to X2D and X1C.";
|
|
251
266
|
|
|
252
267
|
const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"] as const;
|
|
253
268
|
const VALID_NOZZLE_TYPES = ["stainless_steel", "hardened_steel", "tungsten_carbide", "brass"] as const;
|
|
@@ -1829,7 +1844,7 @@ class BambuPrinterMCPServer {
|
|
|
1829
1844
|
printNozzle
|
|
1830
1845
|
);
|
|
1831
1846
|
if (native && args.use_ams !== false && !useAMS) {
|
|
1832
|
-
throw new Error("Native
|
|
1847
|
+
throw new Error("Native printing requires ams_mapping, ams_slots, auto_match_ams, or explicit use_ams: false for an external spool.");
|
|
1833
1848
|
}
|
|
1834
1849
|
const threeMfFilename = path.basename(threeMFPath);
|
|
1835
1850
|
const projectName = String(args?.project_name || args?.task_name || threeMfFilename.replace(/\.3mf$/i, ''));
|
|
@@ -1931,7 +1946,7 @@ class BambuPrinterMCPServer {
|
|
|
1931
1946
|
|
|
1932
1947
|
assertActive();
|
|
1933
1948
|
if (native) {
|
|
1934
|
-
const externalStorage = nativeExternalStorage(args?.try_emmc_print, confirmedStatus.raw);
|
|
1949
|
+
const externalStorage = nativeExternalStorage(args?.try_emmc_print, confirmedStatus.raw, printModel);
|
|
1935
1950
|
if (externalStorage && externalStorageState(confirmedStatus.raw) !== "normal") {
|
|
1936
1951
|
throw new Error("External storage was requested, but the printer reports no ready SD card or USB stick.");
|
|
1937
1952
|
}
|
|
@@ -1961,6 +1976,7 @@ class BambuPrinterMCPServer {
|
|
|
1961
1976
|
if (externalStorage && externalStorageState(dispatchStatus.raw) !== "normal") {
|
|
1962
1977
|
throw new Error("The printer's SD card or USB stick is no longer ready. Check it and start the print again.");
|
|
1963
1978
|
}
|
|
1979
|
+
if (!externalStorage) assertNativeInternalStorage(printModel, dispatchStatus.raw);
|
|
1964
1980
|
assertActive();
|
|
1965
1981
|
this.bambu.recordFlightDispatch(devIp,devId,remoteFileName,requirements,resumeFile);
|
|
1966
1982
|
markPrintCommandSent();
|
|
@@ -2085,7 +2101,7 @@ class BambuPrinterMCPServer {
|
|
|
2085
2101
|
): Promise<Record<string, unknown>> {
|
|
2086
2102
|
assertBambuNativeAvailable();
|
|
2087
2103
|
const model = await this.resolveBambuModel(args.bambu_model);
|
|
2088
|
-
if (model
|
|
2104
|
+
if (!NATIVE_ROUTE_MODELS.has(model)) throw new Error(NATIVE_ROUTE_RESTRICTION);
|
|
2089
2105
|
return this.print3mfViaBambuNetwork(
|
|
2090
2106
|
{ ...args, bambu_model: model, connection_type: "lan", bambu_network_method: "start_local_print" },
|
|
2091
2107
|
host, bambuSerial, bambuToken, { onUpdate, signal }
|
|
@@ -2098,9 +2114,9 @@ class BambuPrinterMCPServer {
|
|
|
2098
2114
|
): Promise<Record<string, unknown>> {
|
|
2099
2115
|
if (args.print) throw new Error("Native upload never starts printing; use print_3mf.");
|
|
2100
2116
|
// Resolve and enforce the model first, as the print path does, so a
|
|
2101
|
-
//
|
|
2117
|
+
// request for another model is never told to install the native helper.
|
|
2102
2118
|
const model = await this.resolveBambuModel(args.bambu_model);
|
|
2103
|
-
if (model
|
|
2119
|
+
if (!NATIVE_ROUTE_MODELS.has(model)) throw new Error(NATIVE_ROUTE_RESTRICTION);
|
|
2104
2120
|
assertBambuNativeAvailable();
|
|
2105
2121
|
const unsupported = ["use_ams", "ams_mapping", "ams_mapping2", "ams_mapping_info", "nozzle_mapping", "nozzles_info",
|
|
2106
2122
|
"bed_leveling", "flow_calibration", "vibration_calibration", "layer_inspect", "timelapse"];
|
|
@@ -2962,7 +2978,7 @@ class BambuPrinterMCPServer {
|
|
|
2962
2978
|
nozzle_mapping: { type: "string", description: "Raw JSON string for FULU PrintParams nozzle_mapping." },
|
|
2963
2979
|
nozzles_info: { type: "string", description: "Raw JSON string for FULU PrintParams nozzles_info." },
|
|
2964
2980
|
bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
|
|
2965
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
2981
|
+
flow_calibration: { type: "boolean", description: "Flow calibration task boolean. Omission resolves Studio settings (auto on P1/P1S); direct MQTT sends false for auto but does not transmit the integer auto mode. The result calibration report distinguishes resolved and transmitted options." },
|
|
2966
2982
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
2967
2983
|
layer_inspect: { type: "boolean", description: "First-layer inspection where supported (default true, as Bambu Studio sends)." },
|
|
2968
2984
|
timelapse: { type: "boolean", description: "Enable timelapse recording in FULU PrintParams (default: false)." },
|
|
@@ -3044,7 +3060,7 @@ class BambuPrinterMCPServer {
|
|
|
3044
3060
|
connection_mode: {
|
|
3045
3061
|
type: "string",
|
|
3046
3062
|
enum: ["lan_mqtt_ftps", "bambu_native"],
|
|
3047
|
-
description: "Upload transport; bambu_native uses the installed Bambu networking plug-in for X2D and never starts printing."
|
|
3063
|
+
description: "Upload transport; bambu_native uses the installed Bambu networking plug-in for X2D or X1C and never starts printing."
|
|
3048
3064
|
},
|
|
3049
3065
|
bambu_model: {
|
|
3050
3066
|
type: "string",
|
|
@@ -3353,9 +3369,9 @@ class BambuPrinterMCPServer {
|
|
|
3353
3369
|
connection_mode: {
|
|
3354
3370
|
type: "string",
|
|
3355
3371
|
enum: ["lan_mqtt_ftps", "bambu_network", "bambu_native", "bambu_connect"],
|
|
3356
|
-
description: "Print path: bambu_connect hands a printable file to the signed-in Bambu Connect app for cloud-mode review; X2D otherwise defaults to bambu_native (Bambu Studio's installed local networking plug-in, storing the job on a ready SD card or USB stick, otherwise internal eMMC); lan_mqtt_ftps is the legacy direct MQTT/FTPS path; bambu_network uses the FULU bridge."
|
|
3372
|
+
description: "Print path: bambu_connect hands a printable file to the signed-in Bambu Connect app for cloud-mode review; X2D otherwise defaults to bambu_native (Bambu Studio's installed local networking plug-in, storing the job on a ready SD card or USB stick, otherwise internal eMMC); X1C may opt in to bambu_native, for example when its firmware refuses FTPS uploads with 553; lan_mqtt_ftps is the legacy direct MQTT/FTPS path; bambu_network uses the FULU bridge."
|
|
3357
3373
|
},
|
|
3358
|
-
try_emmc_print: { type: "boolean", description: "X2D native printing: true stores the job on internal storage (eMMC), false on the SD card or USB stick (refused unless the printer reports one ready). Omit to use the card when ready, else eMMC; BAMBU_NATIVE_TRY_EMMC_PRINT sets a server default." },
|
|
3374
|
+
try_emmc_print: { type: "boolean", description: "X2D native printing: true stores the job on internal storage (eMMC), false on the SD card or USB stick (refused unless the printer reports one ready). Omit to use the card when ready, else eMMC; X1C requires fresh advertised internal-printing support before using eMMC. BAMBU_NATIVE_TRY_EMMC_PRINT sets a server default." },
|
|
3359
3375
|
connection_type: { type: "string", enum: ["cloud", "lan"], description: "BambuNetwork connection type when connection_mode is bambu_network; cloud uses restored internet printing, lan uses local bridge printing." },
|
|
3360
3376
|
bambu_network_method: { type: "string", enum: BAMBU_NETWORK_PRINT_METHODS, description: "FULU print method when connection_mode is bambu_network; defaults to start_local_print for lan, and for cloud to Bambu Studio's order: start_local_print_with_record, then start_print if that fails." },
|
|
3361
3377
|
dev_id: { type: "string", description: "Bambu device id for FULU BambuNetwork printing; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
@@ -3405,7 +3421,7 @@ class BambuPrinterMCPServer {
|
|
|
3405
3421
|
description: "When true, match the sliced 3MF's tray_info_idx requirements against live AMS inventory and use the resulting ams_slots. Ignored when ams_mapping or ams_slots is provided."
|
|
3406
3422
|
},
|
|
3407
3423
|
bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
|
|
3408
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
3424
|
+
flow_calibration: { type: "boolean", description: "Flow calibration task boolean. Omission resolves Studio settings (auto on P1/P1S); direct MQTT sends false for auto but does not transmit the integer auto mode. The result calibration report distinguishes resolved and transmitted options." },
|
|
3409
3425
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
3410
3426
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
3411
3427
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
@@ -3441,7 +3457,7 @@ class BambuPrinterMCPServer {
|
|
|
3441
3457
|
description: "Bed plate type currently installed (default: textured_plate)"
|
|
3442
3458
|
},
|
|
3443
3459
|
bed_leveling: { type: "boolean", description: "Auto bed leveling on or off. Omit to send what Bambu Studio's Send dialog would: the choice saved in BambuStudio.conf for this printer, else Studio's default." },
|
|
3444
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
3460
|
+
flow_calibration: { type: "boolean", description: "Flow calibration task boolean. Omission resolves Studio settings (auto on P1/P1S); direct MQTT sends false for auto but does not transmit the integer auto mode. The result calibration report distinguishes resolved and transmitted options." },
|
|
3445
3461
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
3446
3462
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
3447
3463
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
@@ -3552,6 +3568,12 @@ class BambuPrinterMCPServer {
|
|
|
3552
3568
|
},
|
|
3553
3569
|
outputSchema: PRINTER_INFO_OUTPUT_SCHEMA
|
|
3554
3570
|
},
|
|
3571
|
+
{
|
|
3572
|
+
name: "counterpart_self_check",
|
|
3573
|
+
description: "Counterpart contract (counterpart/1): whether this install's own runtime dependencies and its bundled bambu-node patch loaded, each with its installed version. Run it after an update; ok is false when a check failed, with a message saying which. Sends nothing to the printer.",
|
|
3574
|
+
inputSchema: { type: "object", properties: {} },
|
|
3575
|
+
outputSchema: SELF_CHECK_OUTPUT_SCHEMA
|
|
3576
|
+
},
|
|
3555
3577
|
{
|
|
3556
3578
|
name: "counterpart_discover_printers",
|
|
3557
3579
|
description: "Counterpart contract (counterpart/1): Bambu printers on the local network, from their own SSDP announcements (UDP 2021), with serial, model (as bambu_model names it), name and firmware. Listens for duration_ms (default 4000). network is \"unavailable\" when another app holds the port. Never connects to or authenticates with a printer.",
|
|
@@ -3816,7 +3838,9 @@ class BambuPrinterMCPServer {
|
|
|
3816
3838
|
? linuxEmergency(() => nativeCommand(), signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
3817
3839
|
: nativeCommand;
|
|
3818
3840
|
}
|
|
3819
|
-
|
|
3841
|
+
// Native controls are X2D-only. Another model printed natively (X1C)
|
|
3842
|
+
// is stopped, paused and resumed over direct MQTT, as its default route is.
|
|
3843
|
+
if (route.mode === "bambu_native" && x2dTarget) throw new Error(nativeUnavailableReason()!);
|
|
3820
3844
|
if (route.mode !== "bambu_network") return undefined;
|
|
3821
3845
|
return (assertActive?: () => void, beforeDispatch?: () => Promise<void>) => {
|
|
3822
3846
|
const options = { assertDispatchAllowed: () => { extra.signal.throwIfAborted(); assertActive?.(); } };
|
|
@@ -5081,6 +5105,10 @@ class BambuPrinterMCPServer {
|
|
|
5081
5105
|
break;
|
|
5082
5106
|
}
|
|
5083
5107
|
|
|
5108
|
+
case "counterpart_self_check":
|
|
5109
|
+
result = await selfCheck(SERVER_INFO);
|
|
5110
|
+
break;
|
|
5111
|
+
|
|
5084
5112
|
case "counterpart_printer_info":
|
|
5085
5113
|
result = bambuPrinterInfo({ server: SERVER_INFO, host, serial: bambuSerial, model: this.displayModel(args, bambuSerial), slicerType: normalizeSlicerType(DEFAULT_SLICER_TYPE) });
|
|
5086
5114
|
break;
|
package/src/printers/bambu.ts
CHANGED
|
@@ -20,9 +20,10 @@ import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, d
|
|
|
20
20
|
import { describeHmsKey, hiddenHmsKeys, hiddenHmsNotices, reportedHmsKey, unchippedNozzles, validatePrinterState, manualHeatingRequirements, type PrinterStateRequirements } from "../safety/printer-state.js";
|
|
21
21
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRemotePath, cancelPendingPrinterOperations } from "../safety/artifact.js";
|
|
22
22
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
23
|
-
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "../studio-print-options.js";
|
|
23
|
+
import { directPrintOptionReport, resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "../studio-print-options.js";
|
|
24
24
|
import { Client as FTPClient } from "basic-ftp";
|
|
25
25
|
import { uploadBytes } from "./ftp-upload.js";
|
|
26
|
+
import { mergeBambuReport } from "./report-merge.js";
|
|
26
27
|
import * as mqtt from "mqtt";
|
|
27
28
|
import {
|
|
28
29
|
BambuClient,
|
|
@@ -157,6 +158,19 @@ const MODEL_ID_TO_NAME: Record<string, string> = {
|
|
|
157
158
|
|
|
158
159
|
const H2_MODEL_NAMES = new Set(["h2", "h2c", "h2d", "h2dpro", "h2d pro", "h2s", "x2d"]);
|
|
159
160
|
|
|
161
|
+
/**
|
|
162
|
+
* X1C firmware 01.12.00.00 was seen refusing every FTPS STOR with
|
|
163
|
+
* "553 Could not create file." (card ready and writable, Developer Mode on)
|
|
164
|
+
* while Bambu Studio's networking plug-in still printed. Name that route.
|
|
165
|
+
*/
|
|
166
|
+
export function ftpsRefusalHint(error: unknown, model: string | undefined): string {
|
|
167
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
168
|
+
if (normalizeModel(model) !== "x1c" || ((error as { code?: unknown })?.code !== 553 && !/^553\b/.test(message))) return "";
|
|
169
|
+
return ' X1C firmware 01.12.00.00 has been seen refusing every direct FTPS upload this way. ' +
|
|
170
|
+
'Retry with connection_mode: "bambu_native", which uploads through Bambu Studio\'s networking plug-in ' +
|
|
171
|
+
'(on macOS, first run npm run build:native in the package directory; on Linux, bambu-printer-mcp-native-setup).';
|
|
172
|
+
}
|
|
173
|
+
|
|
160
174
|
export function assertDirectPrintSupported(model: string | undefined, serial?: string): void {
|
|
161
175
|
if (model?.trim().toLowerCase() === "x2d" || serial?.trim().toUpperCase().startsWith("20P")) {
|
|
162
176
|
throw new Error(
|
|
@@ -412,12 +426,35 @@ class BambuClientStore {
|
|
|
412
426
|
return;
|
|
413
427
|
}
|
|
414
428
|
|
|
415
|
-
|
|
416
|
-
this.reportSnapshots.set(key, { ...previous, ...update });
|
|
429
|
+
this.reportSnapshots.set(key, mergeBambuReport(this.reportSnapshots.get(key), update));
|
|
417
430
|
this.reportTimes.set(key, Date.now());
|
|
418
431
|
this.resolveInitialReport(key);
|
|
419
432
|
}
|
|
420
433
|
|
|
434
|
+
/** Merges the printer's reports into its snapshot as they arrive (tests feed a client without a connection). */
|
|
435
|
+
private watchReports(printer: BambuClient, host: string, serial: string, key: string): void {
|
|
436
|
+
printer.on("rawMessage", (_topic, payload) => {
|
|
437
|
+
try {
|
|
438
|
+
const parsed = JSON.parse(payload.toString());
|
|
439
|
+
const printMessage = parsed?.print;
|
|
440
|
+
if (printMessage && typeof printMessage === "object") {
|
|
441
|
+
this.updateReportSnapshot(key, printMessage);
|
|
442
|
+
this.reportObserved(host, serial, key);
|
|
443
|
+
}
|
|
444
|
+
} catch {
|
|
445
|
+
// Ignore unrelated payloads.
|
|
446
|
+
}
|
|
447
|
+
});
|
|
448
|
+
|
|
449
|
+
// bambu-node passes its whole merged report and then what changed. Only the change is merged here, so a field the
|
|
450
|
+
// printer has not sent again (the previous job's layer) is not copied back over this merge's own reset.
|
|
451
|
+
printer.on("printer:dataUpdate", (_data, changed) => {
|
|
452
|
+
if (!changed || typeof changed !== "object") return;
|
|
453
|
+
this.updateReportSnapshot(key, changed);
|
|
454
|
+
this.reportObserved(host, serial, key);
|
|
455
|
+
});
|
|
456
|
+
}
|
|
457
|
+
|
|
421
458
|
private reportObserved(host: string, serial: string, key: string): void {
|
|
422
459
|
const report = this.reportSnapshots.get(key);
|
|
423
460
|
if (!report || !this.onReport) return;
|
|
@@ -515,23 +552,7 @@ class BambuClientStore {
|
|
|
515
552
|
});
|
|
516
553
|
this.ensureInitialReportPromise(key);
|
|
517
554
|
|
|
518
|
-
|
|
519
|
-
try {
|
|
520
|
-
const parsed = JSON.parse(payload.toString());
|
|
521
|
-
const printMessage = parsed?.print;
|
|
522
|
-
if (printMessage && typeof printMessage === "object") {
|
|
523
|
-
this.updateReportSnapshot(key, printMessage);
|
|
524
|
-
this.reportObserved(host, serial, key);
|
|
525
|
-
}
|
|
526
|
-
} catch {
|
|
527
|
-
// Ignore unrelated payloads.
|
|
528
|
-
}
|
|
529
|
-
});
|
|
530
|
-
|
|
531
|
-
printer.on("printer:dataUpdate", (data) => {
|
|
532
|
-
this.updateReportSnapshot(key, data);
|
|
533
|
-
this.reportObserved(host, serial, key);
|
|
534
|
-
});
|
|
555
|
+
this.watchReports(printer, host, serial, key);
|
|
535
556
|
|
|
536
557
|
printer.on("client:connect", () => {
|
|
537
558
|
this.printers.set(key, printer);
|
|
@@ -1142,12 +1163,13 @@ export class BambuImplementation {
|
|
|
1142
1163
|
});
|
|
1143
1164
|
const resumeFile = await checkedFile(inspection, options.filePath);
|
|
1144
1165
|
// The options Bambu Studio's Send dialog would send; explicit ones win.
|
|
1145
|
-
const
|
|
1166
|
+
const caller: CallerPrintOptions = {
|
|
1146
1167
|
bedLeveling: options.bedLeveling, flowCalibration: options.flowCalibration,
|
|
1147
1168
|
vibrationCalibration: options.vibrationCalibration, layerInspect: options.layerInspect,
|
|
1148
1169
|
autoBedLeveling: options.autoBedLeveling, autoFlowCali: options.autoFlowCali,
|
|
1149
1170
|
autoOffsetCali: options.autoOffsetCali, extruderCaliManualMode: options.extruderCaliManualMode,
|
|
1150
|
-
}
|
|
1171
|
+
};
|
|
1172
|
+
const studio = resolveStudioPrintOptions(model, caller, { usedNozzles: usedNozzleCount(inspection) });
|
|
1151
1173
|
const projectMetadata = await this.resolveProjectFileMetadata(
|
|
1152
1174
|
options.filePath,
|
|
1153
1175
|
options.plateIndex,
|
|
@@ -1285,7 +1307,7 @@ export class BambuImplementation {
|
|
|
1285
1307
|
await this.ftpUpload(host, token, options.filePath, remoteUploadPath, options.onUploadProgress);
|
|
1286
1308
|
} catch (error) {
|
|
1287
1309
|
// Nothing has been sent to the printer but (part of) a file, so the print certainly did not start.
|
|
1288
|
-
throw new PrinterRefusal("printer-upload-failed", `The print file did not reach the printer (${error instanceof Error ? error.message : String(error)}). No print was started
|
|
1310
|
+
throw new PrinterRefusal("printer-upload-failed", `The print file did not reach the printer (${error instanceof Error ? error.message : String(error)}). No print was started.${ftpsRefusalHint(error, model)}`);
|
|
1289
1311
|
}
|
|
1290
1312
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1291
1313
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
@@ -1303,6 +1325,7 @@ export class BambuImplementation {
|
|
|
1303
1325
|
const dispatch = await watcher.settled();
|
|
1304
1326
|
return {
|
|
1305
1327
|
status: "success", dispatch, remoteProjectPath,
|
|
1328
|
+
calibration: directPrintOptionReport(caller, studio, {}),
|
|
1306
1329
|
message: dispatch === "started"
|
|
1307
1330
|
? `The printer accepted and started the checked gcode.3mf print: ${options.projectName}`
|
|
1308
1331
|
: `Uploaded the checked gcode.3mf and sent the print command for ${options.projectName}; the printer has not reported starting yet. ` +
|
|
@@ -1378,6 +1401,7 @@ export class BambuImplementation {
|
|
|
1378
1401
|
};
|
|
1379
1402
|
}
|
|
1380
1403
|
|
|
1404
|
+
const calibration = directPrintOptionReport(caller, studio, projectFileCmd.print);
|
|
1381
1405
|
const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
|
|
1382
1406
|
this.recordFlightDispatch(host,serial,remoteProjectPath,requirements,resumeFile);
|
|
1383
1407
|
markPrintCommandSent();
|
|
@@ -1388,6 +1412,7 @@ export class BambuImplementation {
|
|
|
1388
1412
|
|
|
1389
1413
|
return {
|
|
1390
1414
|
status: "success",
|
|
1415
|
+
calibration,
|
|
1391
1416
|
dispatch,
|
|
1392
1417
|
message: dispatch === "started"
|
|
1393
1418
|
? `The printer accepted and started the checked 3MF print: ${options.projectName}`
|
|
@@ -2007,7 +2032,15 @@ export class BambuImplementation {
|
|
|
2007
2032
|
assertActive();
|
|
2008
2033
|
const destination = path.posix.join(path.posix.dirname(remotePath), uniquePrintName(remotePath));
|
|
2009
2034
|
if (upload) await upload(snapshot, destination, assertActive);
|
|
2010
|
-
else
|
|
2035
|
+
else {
|
|
2036
|
+
try {
|
|
2037
|
+
await this.ftpUpload(host, token, snapshot, `/${destination}`);
|
|
2038
|
+
} catch (error) {
|
|
2039
|
+
const hint = ftpsRefusalHint(error, model);
|
|
2040
|
+
if (hint && error instanceof Error) error.message += hint;
|
|
2041
|
+
throw error;
|
|
2042
|
+
}
|
|
2043
|
+
}
|
|
2011
2044
|
return { status: "success", uploaded: true, remotePath: destination, printRequested: false, inspected: printable };
|
|
2012
2045
|
}));
|
|
2013
2046
|
}
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Merging Bambu MQTT reports. P1/A1 printers push only what changed, so a merged report keeps every field until the
|
|
3
|
+
* printer sends it again. A new job's first pushes can carry its name and layer count before its layer number, and the
|
|
4
|
+
* previous job's last layer then read against the new total ("315/150"). Until the new job reports its own progress,
|
|
5
|
+
* its report has none.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Fields that name the job a report describes. The layer count is not one: a running job's count can be revised, and a
|
|
10
|
+
* different job differs in its name, file or task id.
|
|
11
|
+
*/
|
|
12
|
+
const JOB_FIELDS = ["subtask_name", "gcode_file", "task_id"] as const;
|
|
13
|
+
/** A new job prepares (PREPARE, SLICING) after any end; RUNNING straight after FAILED is that job resuming. */
|
|
14
|
+
const PREPARING = new Set(["PREPARE", "SLICING"]);
|
|
15
|
+
const DONE = new Set(["FINISH", "IDLE"]);
|
|
16
|
+
|
|
17
|
+
/** The previous job's progress, left out of a new job's report until the printer reports the new job's own. */
|
|
18
|
+
const JOB_PROGRESS = ["layer_num", "mc_percent", "mc_remaining_time"] as const;
|
|
19
|
+
|
|
20
|
+
/** A job field's value, or undefined for a placeholder: empty, or 0 (LAN prints report task_id "0"). */
|
|
21
|
+
function named(value: unknown): string | undefined {
|
|
22
|
+
const text = value === undefined || value === null ? "" : String(value).trim();
|
|
23
|
+
return text === "" || text === "0" ? undefined : text;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/** True when update describes a different job than the report merged before it. */
|
|
27
|
+
export function startsNewJob(previous: Record<string, any> | undefined, update: Record<string, any>): boolean {
|
|
28
|
+
if (!previous) return false;
|
|
29
|
+
for (const field of JOB_FIELDS) {
|
|
30
|
+
const before = named(previous[field]), after = named(update[field]);
|
|
31
|
+
if (before !== undefined && after !== undefined && before !== after) return true;
|
|
32
|
+
}
|
|
33
|
+
const before = String(previous.gcode_state), after = String(update.gcode_state);
|
|
34
|
+
return (DONE.has(before) || before === "FAILED") && PREPARING.has(after) || DONE.has(before) && after === "RUNNING";
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** The previous job's progress fields to leave out when update starts a new job without reporting them. */
|
|
38
|
+
export function newJobResets(previous: Record<string, any> | undefined, update: Record<string, any>): string[] {
|
|
39
|
+
if (!startsNewJob(previous, update)) return [];
|
|
40
|
+
return JOB_PROGRESS.filter(field => update[field] === undefined && previous?.[field] !== undefined);
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** previous merged with update, without the previous job's progress when update starts a new one (newJobResets). */
|
|
44
|
+
export function mergeBambuReport(previous: Record<string, any> | undefined, update: Record<string, any>): Record<string, any> {
|
|
45
|
+
const merged: Record<string, any> = { ...previous, ...update };
|
|
46
|
+
for (const field of newJobResets(previous, update)) delete merged[field];
|
|
47
|
+
return merged;
|
|
48
|
+
}
|
package/src/safety/limits.ts
CHANGED
|
@@ -40,6 +40,14 @@ export function isDualNozzleModel(model: unknown): boolean {
|
|
|
40
40
|
const normalized = normalizeModel(model);
|
|
41
41
|
return normalized !== undefined && DUAL_NOZZLE_MODELS.has(normalized);
|
|
42
42
|
}
|
|
43
|
+
/** File models a printer accepts besides its own, keyed by the printer's observed model.
|
|
44
|
+
* A P1P with the enclosure upgrade kit still reports itself as a P1P, while its jobs are sliced with the P1S
|
|
45
|
+
* preset. Bambu Studio sends those jobs: resources/printers/C11.json (P1P) lists C12 (P1S) in compatible_machine.
|
|
46
|
+
* The two models have identical MACHINE_LIMITS, and the file is still checked against the printer's own limits. */
|
|
47
|
+
export const ACCEPTED_FILE_MODELS: Readonly<Record<string, ReadonlySet<string>>> = {p1p: new Set(['p1s'])};
|
|
48
|
+
export function fileModelFitsPrinter(fileModel: string, printerModel: string): boolean {
|
|
49
|
+
return fileModel === printerModel || ACCEPTED_FILE_MODELS[printerModel]?.has(fileModel) === true;
|
|
50
|
+
}
|
|
43
51
|
export function normalizeModel(value: unknown): string | undefined {
|
|
44
52
|
if (typeof value !== 'string') return undefined;
|
|
45
53
|
let model = value.trim().toLowerCase().replace(/^bambu\s*(?:lab\s*)?/, '').replace(/[\s_-]/g, '');
|
package/src/safety/print-file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readBoundedPrintFile, loadSafe3mfArchive } from './archive.js';
|
|
3
3
|
import { projectFilaments, type ProjectFilament } from "../ams-mapping.js";
|
|
4
|
-
import { MACHINE_LIMITS, isDualNozzleModel, normalizeMaterial, normalizeModel, validateStartupPurgeTemperature, validateTemperature } from './limits.js';
|
|
4
|
+
import { MACHINE_LIMITS, fileModelFitsPrinter, isDualNozzleModel, normalizeMaterial, normalizeModel, validateStartupPurgeTemperature, validateTemperature } from './limits.js';
|
|
5
5
|
|
|
6
6
|
export interface PrintFileInspection {
|
|
7
7
|
model: string;
|
|
@@ -240,7 +240,7 @@ export async function inspectPrintFile(filePath: string, options: {model:string;
|
|
|
240
240
|
const metadata:Metadata[]=[project,...headers];
|
|
241
241
|
validateFffJob([...metadata,plate]);
|
|
242
242
|
const declaredModel=consistent(metadataValues(metadata,['printer_model']),normalizeModel,'printer model');
|
|
243
|
-
if(declaredModel
|
|
243
|
+
if(!fileModelFitsPrinter(declaredModel,model)) return fail(`file model ${declaredModel} contradicts requested model ${model}`);
|
|
244
244
|
const nozzleDiameters=consistent(metadataValues(metadata,['nozzle_diameter']),value=>{
|
|
245
245
|
const values=list(value);return values.length && values.every(v=>NUMBER.test(v) && [0.2,0.4,0.6,0.8].includes(Number(v)))?values.map(Number):undefined;
|
|
246
246
|
},'nozzle diameter');
|