bambu-printer-mcp 1.1.90 → 1.1.92
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 +48 -3
- 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/flight-record.d.ts +155 -0
- package/dist/counterpart/flight-record.js +831 -0
- package/dist/counterpart/flight-tools.d.ts +213 -0
- package/dist/counterpart/flight-tools.js +232 -0
- package/dist/counterpart/fresh-frame.d.ts +16 -0
- package/dist/counterpart/fresh-frame.js +26 -0
- package/dist/counterpart/make-3mf.js +1 -4
- package/dist/counterpart/physical-evidence.d.ts +70 -0
- package/dist/counterpart/physical-evidence.js +103 -0
- package/dist/counterpart/print-geometry.d.ts +13 -0
- package/dist/counterpart/print-geometry.js +181 -0
- package/dist/counterpart/remote.js +2 -0
- package/dist/counterpart/schemas.d.ts +32 -0
- package/dist/counterpart/schemas.js +2 -0
- package/dist/counterpart/visual-evidence.d.ts +38 -0
- package/dist/counterpart/visual-evidence.js +155 -0
- package/dist/index.js +63 -24
- package/dist/printers/bambu.d.ts +15 -2
- package/dist/printers/bambu.js +64 -12
- 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/print-preview.d.ts +2 -0
- package/dist/safety/print-preview.js +1 -1
- package/dist/safety/printer-state.d.ts +4 -0
- package/dist/safety/printer-state.js +14 -1
- package/dist/slicer/3mf-xml.d.ts +7 -0
- package/dist/slicer/3mf-xml.js +61 -0
- package/dist/stl/stl-manipulator.js +5 -2
- package/dist/studio-print-options.d.ts +9 -0
- package/dist/studio-print-options.js +34 -2
- package/dist/tool-annotations.js +2 -0
- package/package.json +2 -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/flight-record.ts +984 -0
- package/src/counterpart/flight-tools.ts +282 -0
- package/src/counterpart/fresh-frame.ts +45 -0
- package/src/counterpart/make-3mf.ts +1 -5
- package/src/counterpart/physical-evidence.ts +185 -0
- package/src/counterpart/print-geometry.ts +192 -0
- package/src/counterpart/remote.ts +2 -0
- package/src/counterpart/schemas.ts +3 -0
- package/src/counterpart/visual-evidence.ts +212 -0
- package/src/index.ts +61 -21
- package/src/printers/bambu.ts +64 -10
- package/src/safety/limits.ts +8 -0
- package/src/safety/print-file.ts +2 -2
- package/src/safety/print-preview.ts +1 -1
- package/src/safety/printer-state.ts +13 -1
- package/src/slicer/3mf-xml.ts +52 -0
- package/src/stl/stl-manipulator.ts +4 -1
- package/src/studio-print-options.ts +33 -2
- package/src/tool-annotations.ts +2 -0
package/dist/index.js
CHANGED
|
@@ -1,4 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
+
import { physicalProblems } from "./counterpart/visual-evidence.js";
|
|
3
|
+
import { flightKey } from "./counterpart/flight-record.js";
|
|
4
|
+
import { FLIGHT_RECORD_PROPERTIES, FLIGHT_RECORD_DESCRIPTION, FLIGHT_RECORD_OUTPUT_SCHEMA, flightReadOptions, flightRecordResult, FLIGHT_ASSESS_PROPERTIES, FLIGHT_ASSESS_REQUIRED, FLIGHT_ASSESS_DESCRIPTION, PRINT_EVIDENCE_GUIDANCE, visualSubmission } from "./counterpart/flight-tools.js";
|
|
2
5
|
import { CAMERA_STREAM_TOOLS } from "./printers/camera-tools.js";
|
|
3
6
|
import { withAnnotations } from "./tool-annotations.js";
|
|
4
7
|
import { withRemote } from "./counterpart/remote.js";
|
|
@@ -42,7 +45,7 @@ import { resolveStudioPrintOptions, usedNozzleCount } from "./studio-print-optio
|
|
|
42
45
|
import { inspectPrintFile } from "./safety/print-file.js";
|
|
43
46
|
import { previewPrintFile } from "./safety/print-preview.js";
|
|
44
47
|
import { loadSafe3mfArchive } from "./safety/archive.js";
|
|
45
|
-
import { SERIAL_MODELS, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
48
|
+
import { SERIAL_MODELS, internalPrintingSupported, externalStorageState, validatePrinterState } from "./safety/printer-state.js";
|
|
46
49
|
import { isDualNozzleModel } from "./safety/limits.js";
|
|
47
50
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName } from "./safety/artifact.js";
|
|
48
51
|
import { detectProfilesRoot } from "./slicer/profile-flatten.js";
|
|
@@ -143,19 +146,26 @@ function withEmergencyMqttTimeout(send) {
|
|
|
143
146
|
return Promise.race([Promise.resolve().then(() => send(controller.signal)), timeout]).finally(() => clearTimeout(timer));
|
|
144
147
|
}
|
|
145
148
|
/**
|
|
146
|
-
* Whether
|
|
149
|
+
* Whether a native print stores its job on the SD card or USB stick
|
|
147
150
|
* (true) or internal storage (eMMC). An explicit try_emmc_print wins, then
|
|
148
151
|
* BAMBU_NATIVE_TRY_EMMC_PRINT read as the helper reads it; otherwise a ready
|
|
149
152
|
* card is used, as OrcaSlicer does, so the job can be reprinted from the
|
|
150
|
-
* printer and read over FTPS.
|
|
153
|
+
* printer and read over FTPS. X1C internal printing additionally requires
|
|
154
|
+
* the capability bit from fresh status, including at final dispatch.
|
|
151
155
|
*/
|
|
152
|
-
function nativeExternalStorage(tryEmmcPrint, raw) {
|
|
153
|
-
if (tryEmmcPrint !== undefined)
|
|
154
|
-
return !tryEmmcPrint;
|
|
156
|
+
function nativeExternalStorage(tryEmmcPrint, raw, model) {
|
|
155
157
|
const configured = process.env.BAMBU_NATIVE_TRY_EMMC_PRINT?.trim();
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
158
|
+
const external = tryEmmcPrint !== undefined ? !tryEmmcPrint
|
|
159
|
+
: configured ? !["1", "true", "TRUE", "yes"].includes(configured)
|
|
160
|
+
: externalStorageState(raw) === "normal";
|
|
161
|
+
if (!external)
|
|
162
|
+
assertNativeInternalStorage(model, raw);
|
|
163
|
+
return external;
|
|
164
|
+
}
|
|
165
|
+
function assertNativeInternalStorage(model, raw) {
|
|
166
|
+
if (model === "x1c" && !internalPrintingSupported(raw)) {
|
|
167
|
+
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.");
|
|
168
|
+
}
|
|
159
169
|
}
|
|
160
170
|
function requestedPrintNozzles(args) {
|
|
161
171
|
if (args.nozzle_diameters !== undefined && args.nozzle_diameter !== undefined) {
|
|
@@ -206,6 +216,11 @@ function callerPrintOptions(args) {
|
|
|
206
216
|
// the dual-nozzle H2 path. Keep it in this gate so pre-sliced multi-filament
|
|
207
217
|
// jobs take the correct branch instead of the legacy 5-slot mapping.
|
|
208
218
|
const H2_BAMBU_MODELS = new Set(["h2d", "h2dpro", "h2s", "h2c", "x2d"]);
|
|
219
|
+
// Models that may print and upload over connection_mode=bambu_native. X2D
|
|
220
|
+
// defaults to it. X1C opts in: firmware 01.12.00.00 was seen refusing every
|
|
221
|
+
// direct FTPS STOR with 553 while Bambu Studio's plug-in still printed.
|
|
222
|
+
const NATIVE_ROUTE_MODELS = new Set(["x2d", "x1c"]);
|
|
223
|
+
const NATIVE_ROUTE_RESTRICTION = "connection_mode=bambu_native is restricted to X2D and X1C.";
|
|
209
224
|
const VALID_BED_TYPES = ["textured_plate", "cool_plate", "engineering_plate", "hot_plate", "supertack_plate"];
|
|
210
225
|
const VALID_NOZZLE_TYPES = ["stainless_steel", "hardened_steel", "tungsten_carbide", "brass"];
|
|
211
226
|
/** The installed hotend material. Bambu machine presets assume the stock nozzle; the print gate compares this with the printer. */
|
|
@@ -1131,7 +1146,7 @@ class BambuPrinterMCPServer {
|
|
|
1131
1146
|
resources: {},
|
|
1132
1147
|
tools: {}
|
|
1133
1148
|
},
|
|
1134
|
-
instructions: SERVER_INSTRUCTIONS + (CAD_ENABLED ? " For headless dimensioned designs and parameter edits, read the cad_design prompt before using cad_run." : "")
|
|
1149
|
+
instructions: SERVER_INSTRUCTIONS + PRINT_EVIDENCE_GUIDANCE + (CAD_ENABLED ? " For headless dimensioned designs and parameter edits, read the cad_design prompt before using cad_run." : "")
|
|
1135
1150
|
});
|
|
1136
1151
|
this.bambu = new BambuImplementation(async (message) => {
|
|
1137
1152
|
try {
|
|
@@ -1427,7 +1442,7 @@ class BambuPrinterMCPServer {
|
|
|
1427
1442
|
const { threeMFPath, autoSliced } = await this.ensurePrintableThreeMFPath(args, printModel, printPreset, printBedType);
|
|
1428
1443
|
const { useAMS, finalAmsMapping, finalAmsSlots } = await this.resolveAmsPrintSettings(threeMFPath, args, host, bambuSerial, bambuToken, printModel, printNozzle);
|
|
1429
1444
|
if (native && args.use_ams !== false && !useAMS) {
|
|
1430
|
-
throw new Error("Native
|
|
1445
|
+
throw new Error("Native printing requires ams_mapping, ams_slots, auto_match_ams, or explicit use_ams: false for an external spool.");
|
|
1431
1446
|
}
|
|
1432
1447
|
const threeMfFilename = path.basename(threeMFPath);
|
|
1433
1448
|
const projectName = String(args?.project_name || args?.task_name || threeMfFilename.replace(/\.3mf$/i, ''));
|
|
@@ -1528,7 +1543,7 @@ class BambuPrinterMCPServer {
|
|
|
1528
1543
|
};
|
|
1529
1544
|
assertActive();
|
|
1530
1545
|
if (native) {
|
|
1531
|
-
const externalStorage = nativeExternalStorage(args?.try_emmc_print, confirmedStatus.raw);
|
|
1546
|
+
const externalStorage = nativeExternalStorage(args?.try_emmc_print, confirmedStatus.raw, printModel);
|
|
1532
1547
|
if (externalStorage && externalStorageState(confirmedStatus.raw) !== "normal") {
|
|
1533
1548
|
throw new Error("External storage was requested, but the printer reports no ready SD card or USB stick.");
|
|
1534
1549
|
}
|
|
@@ -1558,7 +1573,10 @@ class BambuPrinterMCPServer {
|
|
|
1558
1573
|
if (externalStorage && externalStorageState(dispatchStatus.raw) !== "normal") {
|
|
1559
1574
|
throw new Error("The printer's SD card or USB stick is no longer ready. Check it and start the print again.");
|
|
1560
1575
|
}
|
|
1576
|
+
if (!externalStorage)
|
|
1577
|
+
assertNativeInternalStorage(printModel, dispatchStatus.raw);
|
|
1561
1578
|
assertActive();
|
|
1579
|
+
this.bambu.recordFlightDispatch(devIp, devId, remoteFileName, requirements, resumeFile);
|
|
1562
1580
|
markPrintCommandSent();
|
|
1563
1581
|
} });
|
|
1564
1582
|
assertActive();
|
|
@@ -1577,6 +1595,7 @@ class BambuPrinterMCPServer {
|
|
|
1577
1595
|
},
|
|
1578
1596
|
assertDispatchAllowed: method => { if (method === bridgeMethod || method === cloudFallbackMethod) {
|
|
1579
1597
|
assertActive();
|
|
1598
|
+
this.bambu.recordFlightDispatch(devIp, devId, remoteFileName, requirements, resumeFile);
|
|
1580
1599
|
markPrintCommandSent();
|
|
1581
1600
|
} },
|
|
1582
1601
|
onDispatched: method => { if (method === bridgeMethod || method === cloudFallbackMethod)
|
|
@@ -1659,18 +1678,18 @@ class BambuPrinterMCPServer {
|
|
|
1659
1678
|
async print3mfViaBambuNative(args, host, bambuSerial, bambuToken, onUpdate, signal) {
|
|
1660
1679
|
assertBambuNativeAvailable();
|
|
1661
1680
|
const model = await this.resolveBambuModel(args.bambu_model);
|
|
1662
|
-
if (model
|
|
1663
|
-
throw new Error(
|
|
1681
|
+
if (!NATIVE_ROUTE_MODELS.has(model))
|
|
1682
|
+
throw new Error(NATIVE_ROUTE_RESTRICTION);
|
|
1664
1683
|
return this.print3mfViaBambuNetwork({ ...args, bambu_model: model, connection_type: "lan", bambu_network_method: "start_local_print" }, host, bambuSerial, bambuToken, { onUpdate, signal });
|
|
1665
1684
|
}
|
|
1666
1685
|
async uploadFileViaBambuNative(args, host, bambuSerial, bambuToken, onUpdate, signal) {
|
|
1667
1686
|
if (args.print)
|
|
1668
1687
|
throw new Error("Native upload never starts printing; use print_3mf.");
|
|
1669
1688
|
// Resolve and enforce the model first, as the print path does, so a
|
|
1670
|
-
//
|
|
1689
|
+
// request for another model is never told to install the native helper.
|
|
1671
1690
|
const model = await this.resolveBambuModel(args.bambu_model);
|
|
1672
|
-
if (model
|
|
1673
|
-
throw new Error(
|
|
1691
|
+
if (!NATIVE_ROUTE_MODELS.has(model))
|
|
1692
|
+
throw new Error(NATIVE_ROUTE_RESTRICTION);
|
|
1674
1693
|
assertBambuNativeAvailable();
|
|
1675
1694
|
const unsupported = ["use_ams", "ams_mapping", "ams_mapping2", "ams_mapping_info", "nozzle_mapping", "nozzles_info",
|
|
1676
1695
|
"bed_leveling", "flow_calibration", "vibration_calibration", "layer_inspect", "timelapse"];
|
|
@@ -2449,7 +2468,7 @@ class BambuPrinterMCPServer {
|
|
|
2449
2468
|
nozzle_mapping: { type: "string", description: "Raw JSON string for FULU PrintParams nozzle_mapping." },
|
|
2450
2469
|
nozzles_info: { type: "string", description: "Raw JSON string for FULU PrintParams nozzles_info." },
|
|
2451
2470
|
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." },
|
|
2452
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
2471
|
+
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." },
|
|
2453
2472
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
2454
2473
|
layer_inspect: { type: "boolean", description: "First-layer inspection where supported (default true, as Bambu Studio sends)." },
|
|
2455
2474
|
timelapse: { type: "boolean", description: "Enable timelapse recording in FULU PrintParams (default: false)." },
|
|
@@ -2531,7 +2550,7 @@ class BambuPrinterMCPServer {
|
|
|
2531
2550
|
connection_mode: {
|
|
2532
2551
|
type: "string",
|
|
2533
2552
|
enum: ["lan_mqtt_ftps", "bambu_native"],
|
|
2534
|
-
description: "Upload transport; bambu_native uses the installed Bambu networking plug-in for X2D and never starts printing."
|
|
2553
|
+
description: "Upload transport; bambu_native uses the installed Bambu networking plug-in for X2D or X1C and never starts printing."
|
|
2535
2554
|
},
|
|
2536
2555
|
bambu_model: {
|
|
2537
2556
|
type: "string",
|
|
@@ -2840,9 +2859,9 @@ class BambuPrinterMCPServer {
|
|
|
2840
2859
|
connection_mode: {
|
|
2841
2860
|
type: "string",
|
|
2842
2861
|
enum: ["lan_mqtt_ftps", "bambu_network", "bambu_native", "bambu_connect"],
|
|
2843
|
-
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."
|
|
2862
|
+
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."
|
|
2844
2863
|
},
|
|
2845
|
-
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." },
|
|
2864
|
+
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." },
|
|
2846
2865
|
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." },
|
|
2847
2866
|
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." },
|
|
2848
2867
|
dev_id: { type: "string", description: "Bambu device id for FULU BambuNetwork printing; defaults to BAMBU_DEV_ID or BAMBU_SERIAL." },
|
|
@@ -2892,7 +2911,7 @@ class BambuPrinterMCPServer {
|
|
|
2892
2911
|
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."
|
|
2893
2912
|
},
|
|
2894
2913
|
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." },
|
|
2895
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
2914
|
+
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." },
|
|
2896
2915
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
2897
2916
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
2898
2917
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
@@ -2928,7 +2947,7 @@ class BambuPrinterMCPServer {
|
|
|
2928
2947
|
description: "Bed plate type currently installed (default: textured_plate)"
|
|
2929
2948
|
},
|
|
2930
2949
|
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." },
|
|
2931
|
-
flow_calibration: { type: "boolean", description: "Flow calibration
|
|
2950
|
+
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." },
|
|
2932
2951
|
vibration_calibration: { type: "boolean", description: "Vibration calibration (default false, as Bambu Studio sends)." },
|
|
2933
2952
|
timelapse: { type: "boolean", description: "Enable timelapse recording (default: false)" },
|
|
2934
2953
|
slicer_profile: { type: "string", description: "Path to the slicer profile/config file for auto-slicing (optional)." },
|
|
@@ -3088,6 +3107,16 @@ class BambuPrinterMCPServer {
|
|
|
3088
3107
|
additionalProperties: false
|
|
3089
3108
|
}
|
|
3090
3109
|
},
|
|
3110
|
+
{
|
|
3111
|
+
name: "counterpart_print_record", description: FLIGHT_RECORD_DESCRIPTION,
|
|
3112
|
+
inputSchema: { type: "object", properties: { ...FLIGHT_RECORD_PROPERTIES, host: { type: "string", description: "Saved printer hostname or address; used only to select a local record." }, bambu_serial: { type: "string", description: "Saved Bambu printer serial; used only to select a local record." } }, additionalProperties: false },
|
|
3113
|
+
outputSchema: FLIGHT_RECORD_OUTPUT_SCHEMA
|
|
3114
|
+
},
|
|
3115
|
+
{
|
|
3116
|
+
name: "counterpart_print_assess", description: FLIGHT_ASSESS_DESCRIPTION,
|
|
3117
|
+
inputSchema: { type: "object", properties: { ...FLIGHT_ASSESS_PROPERTIES, host: { type: "string", description: "Saved printer hostname or address; used only to select a local record." }, bambu_serial: { type: "string", description: "Saved Bambu printer serial; used only to select a local record." } }, required: FLIGHT_ASSESS_REQUIRED, additionalProperties: false },
|
|
3118
|
+
outputSchema: FLIGHT_RECORD_OUTPUT_SCHEMA
|
|
3119
|
+
},
|
|
3091
3120
|
{
|
|
3092
3121
|
name: "counterpart_print_progress",
|
|
3093
3122
|
description: "Counterpart contract (counterpart/1): the printer's state, current job (name, task id, percent, time left, layers, stage words), temperatures, active filament and problems with Bambu's HMS messages and links. Read from the MQTT report this server keeps, so a held session asks the printer nothing; observedAt is when the printer sent it. An unreachable printer reports state offline. Read-only; not a safety check.",
|
|
@@ -3284,7 +3313,9 @@ class BambuPrinterMCPServer {
|
|
|
3284
3313
|
? linuxEmergency(() => nativeCommand(), signal => this.bambu.sendStopOverMqtt(host, bambuSerial, bambuToken, signal))
|
|
3285
3314
|
: nativeCommand;
|
|
3286
3315
|
}
|
|
3287
|
-
|
|
3316
|
+
// Native controls are X2D-only. Another model printed natively (X1C)
|
|
3317
|
+
// is stopped, paused and resumed over direct MQTT, as its default route is.
|
|
3318
|
+
if (route.mode === "bambu_native" && x2dTarget)
|
|
3288
3319
|
throw new Error(nativeUnavailableReason());
|
|
3289
3320
|
if (route.mode !== "bambu_network")
|
|
3290
3321
|
return undefined;
|
|
@@ -4377,11 +4408,19 @@ class BambuPrinterMCPServer {
|
|
|
4377
4408
|
choices: options.filter(option => option.available).map(option => option.id), options, savedTo };
|
|
4378
4409
|
break;
|
|
4379
4410
|
}
|
|
4411
|
+
case "counterpart_print_assess":
|
|
4412
|
+
return flightRecordResult(this.bambu.flightRecords.submitVisual(flightKey(host, bambuSerial), visualSubmission(args)));
|
|
4413
|
+
case "counterpart_print_record":
|
|
4414
|
+
return flightRecordResult(this.bambu.flightRecords.read(flightKey(host, bambuSerial), flightReadOptions(args)), args?.frame_format === "images");
|
|
4380
4415
|
case "counterpart_print_progress": {
|
|
4381
4416
|
const report = await this.bambu.readProgressReport(host, bambuSerial, bambuToken);
|
|
4417
|
+
if (report)
|
|
4418
|
+
void this.bambu.flightRecords.sample(flightKey(host, bambuSerial), after => this.bambu.cameraSnapshot(host, bambuSerial, bambuToken, { bambuModel: this.displayModel(args, bambuSerial), timeoutMs: 8000, capturedAfter: after })).catch(() => undefined);
|
|
4382
4419
|
result = report
|
|
4383
4420
|
? bambuProgress(report.raw, { receivedAt: report.receivedAt, serial: bambuSerial, model: this.displayModel(args, bambuSerial) })
|
|
4384
4421
|
: offlineProgress(Date.now());
|
|
4422
|
+
const physical = this.bambu.flightRecords.physicalForReport(flightKey(host, bambuSerial), report?.raw);
|
|
4423
|
+
result = { ...result, physical, problems: [...physicalProblems(physical, result.state === "finished"), ...result.problems] };
|
|
4385
4424
|
break;
|
|
4386
4425
|
}
|
|
4387
4426
|
case "counterpart_make_3mf":
|
package/dist/printers/bambu.d.ts
CHANGED
|
@@ -1,6 +1,13 @@
|
|
|
1
|
+
import { FlightRecords, type PrintGeometry } from "../counterpart/flight-record.js";
|
|
1
2
|
import { CameraStreams, type FrameOptions } from "./camera-stream.js";
|
|
2
3
|
import { inspectPrintFile, type PrintFileInspection } from "../safety/print-file.js";
|
|
3
4
|
import { type PrinterStateRequirements } from "../safety/printer-state.js";
|
|
5
|
+
/**
|
|
6
|
+
* X1C firmware 01.12.00.00 was seen refusing every FTPS STOR with
|
|
7
|
+
* "553 Could not create file." (card ready and writable, Developer Mode on)
|
|
8
|
+
* while Bambu Studio's networking plug-in still printed. Name that route.
|
|
9
|
+
*/
|
|
10
|
+
export declare function ftpsRefusalHint(error: unknown, model: string | undefined): string;
|
|
4
11
|
export declare function assertDirectPrintSupported(model: string | undefined, serial?: string): void;
|
|
5
12
|
interface BambuPrintOptionsInternal {
|
|
6
13
|
/** Bytes sent to the printer so far over FTPS, and the file's size (LAN route). */
|
|
@@ -42,6 +49,7 @@ export type ProgressReport = {
|
|
|
42
49
|
/** The inspected bytes and limits of a started job, for the resume prompt and byte check. */
|
|
43
50
|
export type CheckedFile = {
|
|
44
51
|
sha256: string;
|
|
52
|
+
expected?: PrintGeometry;
|
|
45
53
|
/** A project's printed plate: its number and the SHA-256 of its Metadata/plate_<index>.gcode. */
|
|
46
54
|
plate?: {
|
|
47
55
|
index: number;
|
|
@@ -71,6 +79,7 @@ export type PrintPreflight = {
|
|
|
71
79
|
export { cameraFrameParser } from "./camera-wire.js";
|
|
72
80
|
export declare class BambuImplementation {
|
|
73
81
|
private readonly confirm?;
|
|
82
|
+
readonly flightRecords: FlightRecords;
|
|
74
83
|
private printerStore;
|
|
75
84
|
readonly cameraStreams: CameraStreams;
|
|
76
85
|
/**
|
|
@@ -108,6 +117,8 @@ export declare class BambuImplementation {
|
|
|
108
117
|
* verified: a resume then re-reads it if it can and otherwise matches the
|
|
109
118
|
* unique name, as KAN-216 does for firmware that cannot download a file.
|
|
110
119
|
*/
|
|
120
|
+
/** At the existing send-authorization boundary: record evidence even if the reply/helper is lost. */
|
|
121
|
+
recordFlightDispatch(host: string, serial: string, remotePath: string, requirements: PrinterStateRequirements, file: CheckedFile): void;
|
|
111
122
|
recordCheckedJob(host: string, serial: string, remotePath: string, requirements: PrinterStateRequirements, file: CheckedFile, uploadedHere?: boolean): void;
|
|
112
123
|
/** Feed one merged report to the resume record (internal; the client store calls it for every report). */
|
|
113
124
|
observeReport(host: string, serial: string, raw: Record<string, any> | undefined): void;
|
|
@@ -206,7 +217,7 @@ export declare class BambuImplementation {
|
|
|
206
217
|
status: string;
|
|
207
218
|
uploaded: boolean;
|
|
208
219
|
printRequested: boolean;
|
|
209
|
-
dispatch: "
|
|
220
|
+
dispatch: "unconfirmed" | "started";
|
|
210
221
|
remotePath: string;
|
|
211
222
|
jobName: string;
|
|
212
223
|
message: string;
|
|
@@ -223,7 +234,7 @@ export declare class BambuImplementation {
|
|
|
223
234
|
status: string;
|
|
224
235
|
uploaded: boolean;
|
|
225
236
|
printRequested: boolean;
|
|
226
|
-
dispatch: "
|
|
237
|
+
dispatch: "unconfirmed" | "started";
|
|
227
238
|
remotePath: string;
|
|
228
239
|
jobName: string;
|
|
229
240
|
message: string;
|
|
@@ -276,6 +287,7 @@ export declare class BambuImplementation {
|
|
|
276
287
|
};
|
|
277
288
|
cameraSnapshot(host: string, _serial: string, token: string, options?: {
|
|
278
289
|
savePath?: string;
|
|
290
|
+
capturedAfter?: string;
|
|
279
291
|
timeoutMs?: number;
|
|
280
292
|
bambuModel?: string;
|
|
281
293
|
/**
|
|
@@ -297,6 +309,7 @@ export declare class BambuImplementation {
|
|
|
297
309
|
sizeBytes: number;
|
|
298
310
|
base64: string;
|
|
299
311
|
savedTo?: string;
|
|
312
|
+
capturedAt?: string;
|
|
300
313
|
width?: number;
|
|
301
314
|
height?: number;
|
|
302
315
|
note?: string;
|
package/dist/printers/bambu.js
CHANGED
|
@@ -1,3 +1,6 @@
|
|
|
1
|
+
import { snapshotFrame } from "../counterpart/fresh-frame.js";
|
|
2
|
+
import { FlightRecords, flightKey } from "../counterpart/flight-record.js";
|
|
3
|
+
import { geometryFromGcode, geometryFromFile } from "../counterpart/print-geometry.js";
|
|
1
4
|
import { PrinterRefusal, markPrintCommandSent } from "../refusal.js";
|
|
2
5
|
import { CameraStreams } from "./camera-stream.js";
|
|
3
6
|
import { openTcpCameraSource, openRtspCameraSource } from "./camera-sources.js";
|
|
@@ -17,7 +20,7 @@ import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, d
|
|
|
17
20
|
import { describeHmsKey, hiddenHmsKeys, hiddenHmsNotices, reportedHmsKey, unchippedNozzles, validatePrinterState, manualHeatingRequirements } from "../safety/printer-state.js";
|
|
18
21
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRemotePath, cancelPendingPrinterOperations } from "../safety/artifact.js";
|
|
19
22
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
20
|
-
import { resolveStudioPrintOptions, usedNozzleCount } from "../studio-print-options.js";
|
|
23
|
+
import { directPrintOptionReport, resolveStudioPrintOptions, usedNozzleCount } from "../studio-print-options.js";
|
|
21
24
|
import { Client as FTPClient } from "basic-ftp";
|
|
22
25
|
import { uploadBytes } from "./ftp-upload.js";
|
|
23
26
|
import * as mqtt from "mqtt";
|
|
@@ -140,6 +143,19 @@ const MODEL_ID_TO_NAME = {
|
|
|
140
143
|
C13: "X1E",
|
|
141
144
|
};
|
|
142
145
|
const H2_MODEL_NAMES = new Set(["h2", "h2c", "h2d", "h2dpro", "h2d pro", "h2s", "x2d"]);
|
|
146
|
+
/**
|
|
147
|
+
* X1C firmware 01.12.00.00 was seen refusing every FTPS STOR with
|
|
148
|
+
* "553 Could not create file." (card ready and writable, Developer Mode on)
|
|
149
|
+
* while Bambu Studio's networking plug-in still printed. Name that route.
|
|
150
|
+
*/
|
|
151
|
+
export function ftpsRefusalHint(error, model) {
|
|
152
|
+
const message = error instanceof Error ? error.message : String(error);
|
|
153
|
+
if (normalizeModel(model) !== "x1c" || (error?.code !== 553 && !/^553\b/.test(message)))
|
|
154
|
+
return "";
|
|
155
|
+
return ' X1C firmware 01.12.00.00 has been seen refusing every direct FTPS upload this way. ' +
|
|
156
|
+
'Retry with connection_mode: "bambu_native", which uploads through Bambu Studio\'s networking plug-in ' +
|
|
157
|
+
'(on macOS, first run npm run build:native in the package directory; on Linux, bambu-printer-mcp-native-setup).';
|
|
158
|
+
}
|
|
143
159
|
export function assertDirectPrintSupported(model, serial) {
|
|
144
160
|
if (model?.trim().toLowerCase() === "x2d" || serial?.trim().toUpperCase().startsWith("20P")) {
|
|
145
161
|
throw new Error("X2D direct printing is not supported through legacy MQTT/FTPS. Use the native eMMC route via print_3mf (macOS, or Linux with the native helper installed). " +
|
|
@@ -597,14 +613,22 @@ function reportsJob(raw, remotePath) {
|
|
|
597
613
|
export async function checkedFile(inspection, filePath) {
|
|
598
614
|
const used = inspection.usedFilamentPositions.map(position => inspection.materials[position]).filter(Boolean);
|
|
599
615
|
let plate;
|
|
616
|
+
let expected;
|
|
600
617
|
const plateNumber = /^Metadata\/plate_(\d+)\.gcode$/i.exec(inspection.plateInternalPath ?? "");
|
|
601
618
|
if (plateNumber && /\.3mf$/i.test(filePath)) {
|
|
602
619
|
const entry = (await readSafe3mfArchive(filePath)).zip.file(inspection.plateInternalPath);
|
|
603
|
-
if (entry)
|
|
604
|
-
|
|
620
|
+
if (entry) {
|
|
621
|
+
const bytes = await entry.async("nodebuffer");
|
|
622
|
+
plate = { index: Number(plateNumber[1]), sha256: createHash("sha256").update(bytes).digest("hex") };
|
|
623
|
+
if (bytes.length <= 64 * 1024 * 1024)
|
|
624
|
+
expected = geometryFromGcode(bytes.toString("utf8"));
|
|
625
|
+
}
|
|
626
|
+
}
|
|
627
|
+
else if (!/\.3mf$/i.test(filePath)) {
|
|
628
|
+
expected = await geometryFromFile(filePath);
|
|
605
629
|
}
|
|
606
630
|
return {
|
|
607
|
-
sha256: inspection.sha256, ...(plate ? { plate } : {}), model: inspection.model,
|
|
631
|
+
sha256: inspection.sha256, ...(plate ? { plate } : {}), ...(expected ? { expected } : {}), model: inspection.model,
|
|
608
632
|
maxNozzleTemperature: inspection.maxNozzleTemperature, maxBedTemperature: inspection.maxBedTemperature, maxChamberTemperature: inspection.maxChamberTemperature,
|
|
609
633
|
materials: [...new Set(used.length ? used : inspection.materials)],
|
|
610
634
|
};
|
|
@@ -632,6 +656,7 @@ export { cameraFrameParser } from "./camera-wire.js";
|
|
|
632
656
|
export class BambuImplementation {
|
|
633
657
|
constructor(confirm, options = {}) {
|
|
634
658
|
this.confirm = confirm;
|
|
659
|
+
this.flightRecords = new FlightRecords();
|
|
635
660
|
this.cameraStreams = new CameraStreams();
|
|
636
661
|
/** In-flight counterpart_print_progress reads, one per printer. */
|
|
637
662
|
this.progressReads = new Map();
|
|
@@ -708,16 +733,26 @@ export class BambuImplementation {
|
|
|
708
733
|
* verified: a resume then re-reads it if it can and otherwise matches the
|
|
709
734
|
* unique name, as KAN-216 does for firmware that cannot download a file.
|
|
710
735
|
*/
|
|
736
|
+
/** At the existing send-authorization boundary: record evidence even if the reply/helper is lost. */
|
|
737
|
+
recordFlightDispatch(host, serial, remotePath, requirements, file) {
|
|
738
|
+
this.flightRecords.begin(flightKey(host, serial), { sha256: file.sha256, jobName: remotePath, mapping: requirements.amsMapping, materials: file.materials, plate: file.plate, expected: file.expected });
|
|
739
|
+
}
|
|
711
740
|
recordCheckedJob(host, serial, remotePath, requirements, file, uploadedHere = true) {
|
|
712
741
|
if (!/^[a-f0-9]{64}$/.test(file?.sha256 ?? ""))
|
|
713
742
|
throw new Error("A started job needs the SHA-256 of its inspected bytes.");
|
|
714
743
|
this.checkedJobs.set(`${host}\n${serial}`, {
|
|
715
744
|
...structuredClone(file), remotePath, requirements: structuredClone(requirements), seenRunning: false, uploadedHere,
|
|
716
745
|
});
|
|
746
|
+
if (!this.flightRecords.accept(flightKey(host, serial), remotePath)) {
|
|
747
|
+
this.recordFlightDispatch(host, serial, remotePath, requirements, file);
|
|
748
|
+
this.flightRecords.accept(flightKey(host, serial), remotePath);
|
|
749
|
+
}
|
|
717
750
|
this.clearedErrors.delete(serial);
|
|
718
751
|
}
|
|
719
752
|
/** Feed one merged report to the resume record (internal; the client store calls it for every report). */
|
|
720
753
|
observeReport(host, serial, raw) {
|
|
754
|
+
if (raw)
|
|
755
|
+
this.flightRecords.observe(flightKey(host, serial), raw);
|
|
721
756
|
const key = `${host}\n${serial}`;
|
|
722
757
|
const checked = this.checkedJobs.get(key);
|
|
723
758
|
if (!checked || !raw || typeof raw.gcode_state !== "string")
|
|
@@ -967,12 +1002,13 @@ export class BambuImplementation {
|
|
|
967
1002
|
});
|
|
968
1003
|
const resumeFile = await checkedFile(inspection, options.filePath);
|
|
969
1004
|
// The options Bambu Studio's Send dialog would send; explicit ones win.
|
|
970
|
-
const
|
|
1005
|
+
const caller = {
|
|
971
1006
|
bedLeveling: options.bedLeveling, flowCalibration: options.flowCalibration,
|
|
972
1007
|
vibrationCalibration: options.vibrationCalibration, layerInspect: options.layerInspect,
|
|
973
1008
|
autoBedLeveling: options.autoBedLeveling, autoFlowCali: options.autoFlowCali,
|
|
974
1009
|
autoOffsetCali: options.autoOffsetCali, extruderCaliManualMode: options.extruderCaliManualMode,
|
|
975
|
-
}
|
|
1010
|
+
};
|
|
1011
|
+
const studio = resolveStudioPrintOptions(model, caller, { usedNozzles: usedNozzleCount(inspection) });
|
|
976
1012
|
const projectMetadata = await this.resolveProjectFileMetadata(options.filePath, options.plateIndex, inspection.plateInternalPath);
|
|
977
1013
|
// Send project_file command via bambu-node MQTT (bypasses bambu-js
|
|
978
1014
|
// hardcoded use_ams=true and missing ams_mapping support)
|
|
@@ -1093,7 +1129,7 @@ export class BambuImplementation {
|
|
|
1093
1129
|
}
|
|
1094
1130
|
catch (error) {
|
|
1095
1131
|
// Nothing has been sent to the printer but (part of) a file, so the print certainly did not start.
|
|
1096
|
-
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
|
|
1132
|
+
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)}`);
|
|
1097
1133
|
}
|
|
1098
1134
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1099
1135
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
@@ -1106,6 +1142,7 @@ export class BambuImplementation {
|
|
|
1106
1142
|
assertActive();
|
|
1107
1143
|
if (legacyContainer) {
|
|
1108
1144
|
const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
|
|
1145
|
+
this.recordFlightDispatch(host, serial, remoteProjectPath, requirements, resumeFile);
|
|
1109
1146
|
markPrintCommandSent();
|
|
1110
1147
|
try {
|
|
1111
1148
|
await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remoteProjectPath }));
|
|
@@ -1118,6 +1155,7 @@ export class BambuImplementation {
|
|
|
1118
1155
|
const dispatch = await watcher.settled();
|
|
1119
1156
|
return {
|
|
1120
1157
|
status: "success", dispatch, remoteProjectPath,
|
|
1158
|
+
calibration: directPrintOptionReport(caller, studio, {}),
|
|
1121
1159
|
message: dispatch === "started"
|
|
1122
1160
|
? `The printer accepted and started the checked gcode.3mf print: ${options.projectName}`
|
|
1123
1161
|
: `Uploaded the checked gcode.3mf and sent the print command for ${options.projectName}; the printer has not reported starting yet. ` +
|
|
@@ -1192,7 +1230,9 @@ export class BambuImplementation {
|
|
|
1192
1230
|
},
|
|
1193
1231
|
};
|
|
1194
1232
|
}
|
|
1233
|
+
const calibration = directPrintOptionReport(caller, studio, projectFileCmd.print);
|
|
1195
1234
|
const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
|
|
1235
|
+
this.recordFlightDispatch(host, serial, remoteProjectPath, requirements, resumeFile);
|
|
1196
1236
|
markPrintCommandSent();
|
|
1197
1237
|
try {
|
|
1198
1238
|
await printer.publish(projectFileCmd);
|
|
@@ -1206,6 +1246,7 @@ export class BambuImplementation {
|
|
|
1206
1246
|
const dispatch = await watcher.settled();
|
|
1207
1247
|
return {
|
|
1208
1248
|
status: "success",
|
|
1249
|
+
calibration,
|
|
1209
1250
|
dispatch,
|
|
1210
1251
|
message: dispatch === "started"
|
|
1211
1252
|
? `The printer accepted and started the checked 3MF print: ${options.projectName}`
|
|
@@ -1765,8 +1806,17 @@ export class BambuImplementation {
|
|
|
1765
1806
|
const destination = path.posix.join(path.posix.dirname(remotePath), uniquePrintName(remotePath));
|
|
1766
1807
|
if (upload)
|
|
1767
1808
|
await upload(snapshot, destination, assertActive);
|
|
1768
|
-
else
|
|
1769
|
-
|
|
1809
|
+
else {
|
|
1810
|
+
try {
|
|
1811
|
+
await this.ftpUpload(host, token, snapshot, `/${destination}`);
|
|
1812
|
+
}
|
|
1813
|
+
catch (error) {
|
|
1814
|
+
const hint = ftpsRefusalHint(error, model);
|
|
1815
|
+
if (hint && error instanceof Error)
|
|
1816
|
+
error.message += hint;
|
|
1817
|
+
throw error;
|
|
1818
|
+
}
|
|
1819
|
+
}
|
|
1770
1820
|
return { status: "success", uploaded: true, remotePath: destination, printRequested: false, inspected: printable };
|
|
1771
1821
|
}));
|
|
1772
1822
|
}
|
|
@@ -1799,6 +1849,7 @@ export class BambuImplementation {
|
|
|
1799
1849
|
const printer = await this.getPrinter(host, serial, token);
|
|
1800
1850
|
assertActive();
|
|
1801
1851
|
const watcher = this.watchDispatch(printer, host, serial, token, dispatchStatus, assertActive);
|
|
1852
|
+
this.recordFlightDispatch(host, serial, remotePath, requirements, resumeFile);
|
|
1802
1853
|
markPrintCommandSent();
|
|
1803
1854
|
try {
|
|
1804
1855
|
await invokeWithoutAck(printer, new GCodeFileCommand({ fileName: remotePath }));
|
|
@@ -1990,12 +2041,13 @@ export class BambuImplementation {
|
|
|
1990
2041
|
const timeoutMs = options.timeoutMs ?? 8000;
|
|
1991
2042
|
const stream = this.cameraStreams.get(JSON.stringify([host, _serial]));
|
|
1992
2043
|
if (stream && !stream.stopped) {
|
|
1993
|
-
const
|
|
1994
|
-
if (!
|
|
2044
|
+
const frame = await snapshotFrame(stream, timeoutMs, options.capturedAfter);
|
|
2045
|
+
if (frame.status !== "frame" || !frame.base64)
|
|
1995
2046
|
throw new Error("The active camera stream has not produced a live frame");
|
|
2047
|
+
const jpeg = Buffer.from(frame.base64, "base64");
|
|
1996
2048
|
if (options.savePath)
|
|
1997
2049
|
await (await import("node:fs/promises")).writeFile(options.savePath, jpeg);
|
|
1998
|
-
return { status: "success", format: "image/jpeg", sizeBytes: jpeg.length, base64: jpeg.toString("base64"), transport: stream.transport,
|
|
2050
|
+
return { status: "success", format: "image/jpeg", sizeBytes: jpeg.length, base64: jpeg.toString("base64"), transport: stream.transport, capturedAt: frame.capturedAt,
|
|
1999
2051
|
...(options.savePath ? { savedTo: options.savePath } : {}) };
|
|
2000
2052
|
}
|
|
2001
2053
|
const model = (options.bambuModel ?? "").toLowerCase();
|
package/dist/safety/limits.d.ts
CHANGED
|
@@ -27,6 +27,12 @@ export declare const MACHINE_LIMITS: Readonly<Record<string, {
|
|
|
27
27
|
* (VIRTUAL_TRAY_DEPUTY_ID). The single-nozzle H2S is deliberately absent. */
|
|
28
28
|
export declare const DUAL_NOZZLE_MODELS: ReadonlySet<string>;
|
|
29
29
|
export declare function isDualNozzleModel(model: unknown): boolean;
|
|
30
|
+
/** File models a printer accepts besides its own, keyed by the printer's observed model.
|
|
31
|
+
* A P1P with the enclosure upgrade kit still reports itself as a P1P, while its jobs are sliced with the P1S
|
|
32
|
+
* preset. Bambu Studio sends those jobs: resources/printers/C11.json (P1P) lists C12 (P1S) in compatible_machine.
|
|
33
|
+
* The two models have identical MACHINE_LIMITS, and the file is still checked against the printer's own limits. */
|
|
34
|
+
export declare const ACCEPTED_FILE_MODELS: Readonly<Record<string, ReadonlySet<string>>>;
|
|
35
|
+
export declare function fileModelFitsPrinter(fileModel: string, printerModel: string): boolean;
|
|
30
36
|
export declare function normalizeModel(value: unknown): string | undefined;
|
|
31
37
|
export declare function normalizeMaterial(value: unknown): string | undefined;
|
|
32
38
|
export declare function validateTemperature(component: 'nozzle' | 'bed' | 'chamber', value: unknown, model: string, materials?: string[]): number;
|
package/dist/safety/limits.js
CHANGED
|
@@ -39,6 +39,14 @@ export function isDualNozzleModel(model) {
|
|
|
39
39
|
const normalized = normalizeModel(model);
|
|
40
40
|
return normalized !== undefined && DUAL_NOZZLE_MODELS.has(normalized);
|
|
41
41
|
}
|
|
42
|
+
/** File models a printer accepts besides its own, keyed by the printer's observed model.
|
|
43
|
+
* A P1P with the enclosure upgrade kit still reports itself as a P1P, while its jobs are sliced with the P1S
|
|
44
|
+
* preset. Bambu Studio sends those jobs: resources/printers/C11.json (P1P) lists C12 (P1S) in compatible_machine.
|
|
45
|
+
* The two models have identical MACHINE_LIMITS, and the file is still checked against the printer's own limits. */
|
|
46
|
+
export const ACCEPTED_FILE_MODELS = { p1p: new Set(['p1s']) };
|
|
47
|
+
export function fileModelFitsPrinter(fileModel, printerModel) {
|
|
48
|
+
return fileModel === printerModel || ACCEPTED_FILE_MODELS[printerModel]?.has(fileModel) === true;
|
|
49
|
+
}
|
|
42
50
|
export function normalizeModel(value) {
|
|
43
51
|
if (typeof value !== 'string')
|
|
44
52
|
return undefined;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createHash } from 'node:crypto';
|
|
2
2
|
import { readBoundedPrintFile, loadSafe3mfArchive } from './archive.js';
|
|
3
3
|
import { projectFilaments } 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
|
const NUMBER = /^[+-]?(?:\d+(?:\.\d*)?|\.\d+)$/;
|
|
6
6
|
const fail = (message) => { throw new Error(`Print safety: ${message}`); };
|
|
7
7
|
function list(value) {
|
|
@@ -292,7 +292,7 @@ export async function inspectPrintFile(filePath, options) {
|
|
|
292
292
|
const metadata = [project, ...headers];
|
|
293
293
|
validateFffJob([...metadata, plate]);
|
|
294
294
|
const declaredModel = consistent(metadataValues(metadata, ['printer_model']), normalizeModel, 'printer model');
|
|
295
|
-
if (declaredModel
|
|
295
|
+
if (!fileModelFitsPrinter(declaredModel, model))
|
|
296
296
|
return fail(`file model ${declaredModel} contradicts requested model ${model}`);
|
|
297
297
|
const nozzleDiameters = consistent(metadataValues(metadata, ['nozzle_diameter']), value => {
|
|
298
298
|
const values = list(value);
|
|
@@ -31,6 +31,8 @@ export declare function extrusionSegments(gcode: string): {
|
|
|
31
31
|
segments: Segment[];
|
|
32
32
|
layers: number;
|
|
33
33
|
};
|
|
34
|
+
/** An arc's centre from I/J (offsets from the start) or R (radius; negative takes the longer way round). */
|
|
35
|
+
export declare function arcCentre(x: number, y: number, tx: number, ty: number, clockwise: boolean, i?: number, j?: number, r?: number): [number, number] | undefined;
|
|
34
36
|
/** The top and bed-side pictures of one plate's G-code. `colours` are the project's filament colours by slot. */
|
|
35
37
|
export declare function renderPrintPreview(gcode: string, colours?: unknown[]): PrintPreview | undefined;
|
|
36
38
|
/** The preview of one plate of a sliced .3mf or a .gcode file, or undefined when it has no extruding moves. */
|
|
@@ -198,7 +198,7 @@ function parameterWords(text) {
|
|
|
198
198
|
return words;
|
|
199
199
|
}
|
|
200
200
|
/** An arc's centre from I/J (offsets from the start) or R (radius; negative takes the longer way round). */
|
|
201
|
-
function arcCentre(x, y, tx, ty, clockwise, i, j, r) {
|
|
201
|
+
export function arcCentre(x, y, tx, ty, clockwise, i, j, r) {
|
|
202
202
|
if (i !== undefined || j !== undefined)
|
|
203
203
|
return [x + (i ?? 0), y + (j ?? 0)];
|
|
204
204
|
if (r === undefined || r === 0 || (tx === x && ty === y))
|
|
@@ -105,4 +105,8 @@ export type ExternalStorageState = "none" | "normal" | "abnormal" | "readonly";
|
|
|
105
105
|
* (DevStorage.cpp, DeviceManager.cpp parse_home_flag and parse_new_info).
|
|
106
106
|
*/
|
|
107
107
|
export declare function externalStorageState(raw: unknown): ExternalStorageState;
|
|
108
|
+
/** Studio DeviceManager.cpp at 926a7192574b: fun2 bit 0 advertises eMMC printing.
|
|
109
|
+
* Use only a fresh raw report at the caller. Reject malformed flags rather than
|
|
110
|
+
* stripping arbitrary characters as Studio's general-purpose parser does. */
|
|
111
|
+
export declare function internalPrintingSupported(raw: unknown): boolean;
|
|
108
112
|
export {};
|
|
@@ -364,7 +364,7 @@ function trayRange(value, label) {
|
|
|
364
364
|
/** Dual-nozzle printers report one virtual external slot per nozzle, numbered as Bambu
|
|
365
365
|
* Studio does (VIRTUAL_TRAY_MAIN_ID 255 = right/main nozzle, VIRTUAL_TRAY_DEPUTY_ID 254 =
|
|
366
366
|
* left/deputy nozzle), so the requested tray selects its slot. Single-nozzle printers keep
|
|
367
|
-
* requiring exactly one slot
|
|
367
|
+
* requiring exactly one external slot report, then the legacy vt_tray field. */
|
|
368
368
|
function externalTray(raw, trayIndex, model) {
|
|
369
369
|
const slots = raw.vir_slot;
|
|
370
370
|
const dualNozzle = isDualNozzleModel(model);
|
|
@@ -372,6 +372,10 @@ function externalTray(raw, trayIndex, model) {
|
|
|
372
372
|
const selected = slots.filter((slot) => Number(slot?.id) === trayIndex);
|
|
373
373
|
if (selected.length === 1 && (dualNozzle || slots.length === 1))
|
|
374
374
|
return selected[0];
|
|
375
|
+
// X1C firmware 01.12 reports its single external slot as id 255 (ams_id 255, slot 0) while
|
|
376
|
+
// tray_now is 254. One external slot on a single-nozzle printer is unambiguous.
|
|
377
|
+
if (!dualNozzle && slots.length === 1 && [254, 255].includes(Number(slots[0]?.id)) && [254, 255].includes(trayIndex))
|
|
378
|
+
return slots[0];
|
|
375
379
|
if (dualNozzle && selected.length === 0 && slots.length > 0)
|
|
376
380
|
throw new Error(`External spool ${trayIndex} is not in the fresh per-nozzle report; cannot verify the selected material.`);
|
|
377
381
|
if (slots.length > 0)
|
|
@@ -551,3 +555,12 @@ export function externalStorageState(raw) {
|
|
|
551
555
|
}
|
|
552
556
|
return state;
|
|
553
557
|
}
|
|
558
|
+
/** Studio DeviceManager.cpp at 926a7192574b: fun2 bit 0 advertises eMMC printing.
|
|
559
|
+
* Use only a fresh raw report at the caller. Reject malformed flags rather than
|
|
560
|
+
* stripping arbitrary characters as Studio's general-purpose parser does. */
|
|
561
|
+
export function internalPrintingSupported(raw) {
|
|
562
|
+
if (!object(raw) || typeof raw.fun2 !== "string")
|
|
563
|
+
return false;
|
|
564
|
+
const flags = raw.fun2.trim().replace(/^0x/i, "");
|
|
565
|
+
return /^[0-9a-f]+$/i.test(flags) && (parseInt(flags.slice(-1), 16) & 1) === 1;
|
|
566
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
/** Encode text for a quoted XML attribute, preserving whitespace through XML parsing. */
|
|
2
|
+
export declare function xmlAttribute(value: string): string;
|
|
3
|
+
/** Studio 02.08.02.61 bbs_3mf.cpp writes object opt_serialize values without XML escaping.
|
|
4
|
+
* Only repair its single-line key/value metadata form. Unexpected malformed XML fails closed. */
|
|
5
|
+
export declare function escapedModelSettings(xml: string): Promise<string>;
|
|
6
|
+
/** Normalize only a newly produced/restored slice, before caching or handing it to the client. */
|
|
7
|
+
export declare function normalize3mfMetadata(filePath: string): Promise<void>;
|