@hiv3d/bambu-types
Version:
TypeScript types and utilities for Bambu Lab 3D printers including error codes, commands, and API types
884 lines (880 loc) • 309 kB
JavaScript
import { z } from 'zod';
// src/bambu.ts
var PrinterModelNamesShort = /* @__PURE__ */ ((PrinterModelNamesShort2) => {
PrinterModelNamesShort2["X1C"] = "X1C";
PrinterModelNamesShort2["X1"] = "X1";
PrinterModelNamesShort2["X1E"] = "X1E";
PrinterModelNamesShort2["P1P"] = "P1P";
PrinterModelNamesShort2["P1S"] = "P1S";
PrinterModelNamesShort2["A1"] = "A1";
PrinterModelNamesShort2["A1M"] = "A1M";
PrinterModelNamesShort2["H2D"] = "H2D";
return PrinterModelNamesShort2;
})(PrinterModelNamesShort || {});
var PrinterModelIDs = /* @__PURE__ */ ((PrinterModelIDs2) => {
PrinterModelIDs2["X1C"] = "BL-P001";
PrinterModelIDs2["X1"] = "BL-P002";
PrinterModelIDs2["P1P"] = "C11";
PrinterModelIDs2["P1S"] = "C12";
PrinterModelIDs2["X1E"] = "C13";
PrinterModelIDs2["A1"] = "N2S";
PrinterModelIDs2["A1M"] = "N1";
PrinterModelIDs2["H2D"] = "O1D";
return PrinterModelIDs2;
})(PrinterModelIDs || {});
var PRINTER_MODEL_MAP = {
// Official model IDs from machine profiles
["BL-P001" /* X1C */]: "X1C",
// X1 Carbon
["BL-P002" /* X1 */]: "X1",
// X1
["C11" /* P1P */]: "P1P",
// P1P
["C12" /* P1S */]: "P1S",
// P1S
["C13" /* X1E */]: "X1E",
// X1E
["N2S" /* A1 */]: "A1",
// A1
["N1" /* A1M */]: "A1M",
// A1 Mini
["O1D" /* H2D */]: "H2D"
// H2D
};
var PRINTER_MODEL_LONG_NAME_MAP = {
// Full names (for project_settings.config)
["BL-P001" /* X1C */]: "Bambu Lab X1C",
["BL-P002" /* X1 */]: "Bambu Lab X1",
["C12" /* P1S */]: "Bambu Lab P1S",
["C11" /* P1P */]: "Bambu Lab P1P",
["N2S" /* A1 */]: "Bambu Lab A1",
["N1" /* A1M */]: "Bambu Lab A1 Mini",
["C13" /* X1E */]: "Bambu Lab X1C",
["O1D" /* H2D */]: "Bambu Lab H2D"
// H2D
};
var CONNECT_RETURN_CODE_DESC = {
0: "Connection successful",
1: "Connection refused - incorrect protocol version",
2: "Connection refused - invalid client identifier",
3: "Connection refused - server unavailable",
4: "Connection refused - bad username or password",
5: "Connection refused - not authorised"
};
var AMS_LETTER_MAP = {
"0": "A",
"1": "B",
"2": "C",
"3": "D"
};
// src/printerResponse.ts
var AMSControlAction = /* @__PURE__ */ ((AMSControlAction2) => {
AMSControlAction2["RESUME"] = "resume";
AMSControlAction2["RESET"] = "reset";
AMSControlAction2["PAUSE"] = "pause";
AMSControlAction2["DONE"] = "done";
return AMSControlAction2;
})(AMSControlAction || {});
function isPrintMessage(data) {
return !!data?.print && !!data?.print?.command && ["push_status", "resume", "gcode_line", "gcode_file", "project_file", "ams_filament_setting"].includes(
data.print.command
);
}
var PrintStage = /* @__PURE__ */ ((PrintStage2) => {
PrintStage2["PRINTING"] = "Printing";
PrintStage2["BED_LEVELING"] = "Auto bed leveling";
PrintStage2["HEATBED_PREHEATING"] = "Heatbed preheating";
PrintStage2["XY_MECH_MODE_SWEEP"] = "Sweeping XY mech mode";
PrintStage2["CHANGE_MATERIAL"] = "Changing filament";
PrintStage2["M400_PAUSE"] = "M400 pause";
PrintStage2["FILAMENT_RUNOUT_PAUSE"] = "Paused due to filament runout";
PrintStage2["HOTEND_HEATING"] = "Heating hotend";
PrintStage2["EXTRUDE_COMPENSATION_SCAN"] = "Calibrating extrusion";
PrintStage2["BED_SCAN"] = "Scanning bed surface";
PrintStage2["FIRST_LAYER_SCAN"] = "Inspecting first layer";
PrintStage2["BE_SURFACE_TYPT_IDENTIFICATION"] = "Identifying build plate type";
PrintStage2["SCANNER_EXTRINSIC_PARA_CALI"] = "Calibrating Micro Lidar";
PrintStage2["TOOLHEAD_HOMING"] = "Homing toolhead";
PrintStage2["NOZZLE_TIP_CLEANING"] = "Cleaning nozzle tip";
PrintStage2["EXTRUDER_TEMP_PROTECT_CALI"] = "Checking extruder temperature";
PrintStage2["USER_PAUSE"] = "Printing was paused by the user";
PrintStage2["TOOLHEAD_SHELL_OFF_PAUSE"] = "Pause of front cover falling";
PrintStage2["SCANNER_LASER_PARA_CALI"] = "Calibrating the micro lida";
PrintStage2["EXTRUDER_ABSOLUTE_FLOW_CALI"] = "Calibrating extrusion flow";
PrintStage2["HOTEND_TEMPERATURE_ERROR_PAUSE"] = "Paused due to nozzle temperature malfunction";
PrintStage2["HEATED_BED_TEMPERATURE_ERROR_PAUSE"] = "Paused due to heat bed temperature malfunction";
PrintStage2["FILAMENT_UNLOADING"] = "Filament unloading";
PrintStage2["SKIP_STEP_PAUSE"] = "Skip step pause";
PrintStage2["FILAMENT_LOADING"] = "Filament loading";
PrintStage2["MOTOR_NOISE_CALIBRATION"] = "Motor noise calibration";
PrintStage2["AMS_LOST_PAUSE"] = "Paused due to AMS lost";
PrintStage2["HEAT_BREAK_FAN_PAUSE"] = "Paused due to low speed of the heat break fan";
PrintStage2["CHAMBER_TEMPERATURE_CONTROL_ERROR_PAUSE"] = "Paused due to chamber temperature control error";
PrintStage2["CHAMBER_COOLING"] = "Cooling chamber";
PrintStage2["USER_INSERT_GCODE_PAUSE"] = "Paused by the Gcode inserted by user";
PrintStage2["MOTOR_NOISE_SHOWOFF"] = "Motor noise showoff";
PrintStage2["NOZZLE_FILAMENT_COVERED_DETECTED_PAUSE"] = "Nozzle filament covered detected pause";
PrintStage2["CUTTER_ERROR_PAUSE"] = "Cutter error pause";
PrintStage2["FIRST_LAYER_ERROR_PAUSE"] = "First layer error pause";
PrintStage2["NOZZLE_CLOG_PAUSE"] = "Nozzle clog pause";
return PrintStage2;
})(PrintStage || {});
var stageCurrToStage = {
0: "Printing" /* PRINTING */,
1: "Auto bed leveling" /* BED_LEVELING */,
2: "Heatbed preheating" /* HEATBED_PREHEATING */,
3: "Sweeping XY mech mode" /* XY_MECH_MODE_SWEEP */,
4: "Changing filament" /* CHANGE_MATERIAL */,
5: "M400 pause" /* M400_PAUSE */,
6: "Paused due to filament runout" /* FILAMENT_RUNOUT_PAUSE */,
7: "Heating hotend" /* HOTEND_HEATING */,
8: "Calibrating extrusion" /* EXTRUDE_COMPENSATION_SCAN */,
9: "Scanning bed surface" /* BED_SCAN */,
10: "Inspecting first layer" /* FIRST_LAYER_SCAN */,
11: "Identifying build plate type" /* BE_SURFACE_TYPT_IDENTIFICATION */,
12: "Calibrating Micro Lidar" /* SCANNER_EXTRINSIC_PARA_CALI */,
13: "Homing toolhead" /* TOOLHEAD_HOMING */,
14: "Cleaning nozzle tip" /* NOZZLE_TIP_CLEANING */,
15: "Checking extruder temperature" /* EXTRUDER_TEMP_PROTECT_CALI */,
16: "Printing was paused by the user" /* USER_PAUSE */,
17: "Pause of front cover falling" /* TOOLHEAD_SHELL_OFF_PAUSE */,
18: "Calibrating the micro lida" /* SCANNER_LASER_PARA_CALI */,
19: "Calibrating extrusion flow" /* EXTRUDER_ABSOLUTE_FLOW_CALI */,
20: "Paused due to nozzle temperature malfunction" /* HOTEND_TEMPERATURE_ERROR_PAUSE */,
21: "Paused due to heat bed temperature malfunction" /* HEATED_BED_TEMPERATURE_ERROR_PAUSE */,
22: "Filament unloading" /* FILAMENT_UNLOADING */,
23: "Skip step pause" /* SKIP_STEP_PAUSE */,
24: "Filament loading" /* FILAMENT_LOADING */,
25: "Motor noise calibration" /* MOTOR_NOISE_CALIBRATION */,
26: "Paused due to AMS lost" /* AMS_LOST_PAUSE */,
27: "Paused due to low speed of the heat break fan" /* HEAT_BREAK_FAN_PAUSE */,
28: "Paused due to chamber temperature control error" /* CHAMBER_TEMPERATURE_CONTROL_ERROR_PAUSE */,
29: "Cooling chamber" /* CHAMBER_COOLING */,
30: "Paused by the Gcode inserted by user" /* USER_INSERT_GCODE_PAUSE */,
31: "Motor noise showoff" /* MOTOR_NOISE_SHOWOFF */,
32: "Nozzle filament covered detected pause" /* NOZZLE_FILAMENT_COVERED_DETECTED_PAUSE */,
33: "Cutter error pause" /* CUTTER_ERROR_PAUSE */,
34: "First layer error pause" /* FIRST_LAYER_ERROR_PAUSE */,
35: "Nozzle clog pause" /* NOZZLE_CLOG_PAUSE */
};
var PrintStageDetails = {
["Printing" /* PRINTING */]: {
controllable: true,
critical: true,
description: "Actively printing the model"
},
["Auto bed leveling" /* BED_LEVELING */]: {
controllable: false,
critical: true,
description: "Performing automatic bed leveling calibration"
},
["Heatbed preheating" /* HEATBED_PREHEATING */]: {
controllable: false,
critical: true,
description: "Preheating the build plate to required temperature"
},
["Sweeping XY mech mode" /* XY_MECH_MODE_SWEEP */]: {
controllable: false,
critical: true,
description: "Calibrating XY mechanical movement"
},
["Changing filament" /* CHANGE_MATERIAL */]: {
controllable: true,
critical: false,
description: "Changing filament material"
},
["M400 pause" /* M400_PAUSE */]: {
controllable: false,
critical: false,
description: "Temporary pause for machine commands"
},
["Paused due to filament runout" /* FILAMENT_RUNOUT_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to filament running out"
},
["Heating hotend" /* HOTEND_HEATING */]: {
controllable: false,
critical: true,
description: "Heating nozzle to required temperature"
},
["Calibrating extrusion" /* EXTRUDE_COMPENSATION_SCAN */]: {
controllable: false,
critical: true,
description: "Calibrating extrusion compensation"
},
["Scanning bed surface" /* BED_SCAN */]: {
controllable: false,
critical: true,
description: "Scanning bed surface topology"
},
["Inspecting first layer" /* FIRST_LAYER_SCAN */]: {
controllable: false,
critical: true,
description: "Inspecting first layer quality"
},
["Identifying build plate type" /* BE_SURFACE_TYPT_IDENTIFICATION */]: {
controllable: false,
critical: true,
description: "Identifying build plate surface type"
},
["Calibrating Micro Lidar" /* SCANNER_EXTRINSIC_PARA_CALI */]: {
controllable: false,
critical: true,
description: "Calibrating Micro Lidar parameters"
},
["Homing toolhead" /* TOOLHEAD_HOMING */]: {
controllable: false,
critical: true,
description: "Moving toolhead to home position"
},
["Cleaning nozzle tip" /* NOZZLE_TIP_CLEANING */]: {
controllable: false,
critical: true,
description: "Cleaning nozzle tip"
},
["Checking extruder temperature" /* EXTRUDER_TEMP_PROTECT_CALI */]: {
controllable: false,
critical: true,
description: "Verifying extruder temperature protection"
},
["Printing was paused by the user" /* USER_PAUSE */]: {
controllable: true,
critical: false,
description: "Print manually paused by user"
},
["Pause of front cover falling" /* TOOLHEAD_SHELL_OFF_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to front cover falling"
},
["Calibrating the micro lida" /* SCANNER_LASER_PARA_CALI */]: {
controllable: false,
critical: true,
description: "Calibrating micro lidar laser parameters"
},
["Calibrating extrusion flow" /* EXTRUDER_ABSOLUTE_FLOW_CALI */]: {
controllable: false,
critical: true,
description: "Calibrating absolute extrusion flow"
},
["Paused due to nozzle temperature malfunction" /* HOTEND_TEMPERATURE_ERROR_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to nozzle temperature error"
},
["Paused due to heat bed temperature malfunction" /* HEATED_BED_TEMPERATURE_ERROR_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to bed temperature error"
},
["Filament unloading" /* FILAMENT_UNLOADING */]: {
controllable: true,
critical: false,
description: "Unloading filament from extruder"
},
["Skip step pause" /* SKIP_STEP_PAUSE */]: {
controllable: true,
critical: false,
description: "Print paused for step skipping"
},
["Filament loading" /* FILAMENT_LOADING */]: {
controllable: true,
critical: false,
description: "Loading filament into extruder"
},
["Motor noise calibration" /* MOTOR_NOISE_CALIBRATION */]: {
controllable: false,
critical: false,
description: "Calibrating motor noise reduction"
},
["Paused due to AMS lost" /* AMS_LOST_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to AMS communication loss"
},
["Paused due to low speed of the heat break fan" /* HEAT_BREAK_FAN_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to heat break fan issue"
},
["Paused due to chamber temperature control error" /* CHAMBER_TEMPERATURE_CONTROL_ERROR_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to chamber temperature error"
},
["Cooling chamber" /* CHAMBER_COOLING */]: {
controllable: false,
critical: true,
description: "Cooling print chamber"
},
["Paused by the Gcode inserted by user" /* USER_INSERT_GCODE_PAUSE */]: {
controllable: true,
critical: false,
description: "Print paused by user-inserted GCode"
},
["Motor noise showoff" /* MOTOR_NOISE_SHOWOFF */]: {
controllable: false,
critical: false,
description: "Demonstrating motor noise reduction"
},
["Nozzle filament covered detected pause" /* NOZZLE_FILAMENT_COVERED_DETECTED_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to filament covering nozzle"
},
["Cutter error pause" /* CUTTER_ERROR_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to filament cutter error"
},
["First layer error pause" /* FIRST_LAYER_ERROR_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to first layer error"
},
["Nozzle clog pause" /* NOZZLE_CLOG_PAUSE */]: {
controllable: true,
critical: true,
description: "Print paused due to nozzle clog"
}
};
var SpeedLevel = /* @__PURE__ */ ((SpeedLevel2) => {
SpeedLevel2["SILENT"] = "1";
SpeedLevel2["NORMAL"] = "2";
SpeedLevel2["SPORT"] = "3";
SpeedLevel2["LUDICROUS"] = "4";
return SpeedLevel2;
})(SpeedLevel || {});
var FilamentType = /* @__PURE__ */ ((FilamentType2) => {
FilamentType2["PLA"] = "PLA";
FilamentType2["ABS"] = "ABS";
FilamentType2["TPU"] = "TPU";
FilamentType2["PC"] = "PC";
FilamentType2["ASA"] = "ASA";
FilamentType2["PA_CF"] = "PA-CF";
FilamentType2["PA6_CF"] = "PA6-CF";
FilamentType2["PET_CF"] = "PET-CF";
FilamentType2["PETG"] = "PETG";
FilamentType2["PETG_CF"] = "PETG-CF";
FilamentType2["PLA_AERO"] = "PLA-AERO";
FilamentType2["PLA_CF"] = "PLA-CF";
FilamentType2["PPA_CF"] = "PPA-CF";
FilamentType2["PPA_GF"] = "PPA-GF";
FilamentType2["PA"] = "PA";
FilamentType2["HIPS"] = "HIPS";
FilamentType2["PPS"] = "PPS";
FilamentType2["PPS_CF"] = "PPS-CF";
FilamentType2["PVA"] = "PVA";
FilamentType2["PLA_S"] = "PLA-S";
FilamentType2["PA_S"] = "PLA-S";
return FilamentType2;
})(FilamentType || {});
var AmsRFIDStatus = /* @__PURE__ */ ((AmsRFIDStatus2) => {
AmsRFIDStatus2[AmsRFIDStatus2["IDLE"] = 0] = "IDLE";
AmsRFIDStatus2[AmsRFIDStatus2["READING"] = 1] = "READING";
AmsRFIDStatus2[AmsRFIDStatus2["GCODE_TRANS"] = 2] = "GCODE_TRANS";
AmsRFIDStatus2[AmsRFIDStatus2["GCODE_RUNNING"] = 3] = "GCODE_RUNNING";
AmsRFIDStatus2[AmsRFIDStatus2["ASSISTANT"] = 4] = "ASSISTANT";
AmsRFIDStatus2[AmsRFIDStatus2["SWITCH_FILAMENT"] = 5] = "SWITCH_FILAMENT";
AmsRFIDStatus2[AmsRFIDStatus2["HAS_FILAMENT"] = 6] = "HAS_FILAMENT";
return AmsRFIDStatus2;
})(AmsRFIDStatus || {});
var UpgradeStatusProgressState = /* @__PURE__ */ ((UpgradeStatusProgressState2) => {
UpgradeStatusProgressState2["DOWNLOADING"] = "DOWNLOADING";
UpgradeStatusProgressState2["UPGRADE_REQUEST"] = "UPGRADE_REQUEST";
UpgradeStatusProgressState2["PRE_FLASH_START"] = "PRE_FLASH_START";
UpgradeStatusProgressState2["PRE_FLASH_SUCCESS"] = "PRE_FLASH_SUCCESS";
return UpgradeStatusProgressState2;
})(UpgradeStatusProgressState || {});
var UpgradeStatusFinishState = /* @__PURE__ */ ((UpgradeStatusFinishState2) => {
UpgradeStatusFinishState2["UPGRADE_SUCCESS"] = "UPGRADE_SUCCESS";
UpgradeStatusFinishState2["DOWNLOAD_FAIL"] = "DOWNLOAD_FAIL";
UpgradeStatusFinishState2["FLASH_FAIL"] = "FLASH_FAIL";
UpgradeStatusFinishState2["PRE_FLASH_FAIL"] = "PRE_FLASH_FAIL";
UpgradeStatusFinishState2["UPGRADE_FAIL"] = "UPGRADE_FAIL";
return UpgradeStatusFinishState2;
})(UpgradeStatusFinishState || {});
var UpgradeErrorCode = /* @__PURE__ */ ((UpgradeErrorCode2) => {
UpgradeErrorCode2[UpgradeErrorCode2["UpgradeNoError"] = 0] = "UpgradeNoError";
UpgradeErrorCode2[UpgradeErrorCode2["UpgradeDownloadFailed"] = 1] = "UpgradeDownloadFailed";
UpgradeErrorCode2[UpgradeErrorCode2["UpgradeVerifyFailed"] = 2] = "UpgradeVerifyFailed";
UpgradeErrorCode2[UpgradeErrorCode2["UpgradeFlashFailed"] = 3] = "UpgradeFlashFailed";
UpgradeErrorCode2[UpgradeErrorCode2["UpgradePrinting"] = 4] = "UpgradePrinting";
return UpgradeErrorCode2;
})(UpgradeErrorCode || {});
var UpgradeDisplayState = /* @__PURE__ */ ((UpgradeDisplayState2) => {
UpgradeDisplayState2[UpgradeDisplayState2["UNAVAILABLE"] = 0] = "UNAVAILABLE";
UpgradeDisplayState2[UpgradeDisplayState2["IDLE"] = 1] = "IDLE";
UpgradeDisplayState2[UpgradeDisplayState2["UPGRADING"] = 2] = "UPGRADING";
UpgradeDisplayState2[UpgradeDisplayState2["UPGRADE_FINISHED"] = 3] = "UPGRADE_FINISHED";
return UpgradeDisplayState2;
})(UpgradeDisplayState || {});
var filamentConfigs = {
PLA: {
type: "filament",
name: "PLA",
inherits: "",
from: "",
filament_id: "PLA",
instantiation: "true",
filament_cost: ["20"],
filament_vendor: ["Generic"],
nozzle_temp_min: "190",
nozzle_temp_max: "230",
bed_temp: "60",
bed_temp_type: "normal"
},
ABS: {
type: "filament",
name: "ABS",
inherits: "",
from: "",
filament_id: "ABS",
instantiation: "true",
filament_cost: ["25"],
filament_vendor: ["Generic"],
nozzle_temp_min: "220",
nozzle_temp_max: "270",
bed_temp: "90",
bed_temp_type: "high"
}
};
function getFilamentConfig(id) {
return filamentConfigs[id] ?? null;
}
function getStageFromCurr(stageCurr) {
return stageCurrToStage[stageCurr];
}
function getStagesFromArray(stages) {
return stages.map((stage) => stageCurrToStage[stage]).filter((stage) => stage !== void 0);
}
function getEnrichedStages(currentStage, stageHistory) {
const currentPrintStage = stageCurrToStage[currentStage];
const historyStages = getStagesFromArray(stageHistory);
const currentIndex = historyStages.findIndex((stage) => stage === currentPrintStage);
const enrichedStages = historyStages.map((stage, index) => {
const stageDetails = PrintStageDetails[stage];
return {
stage,
description: stageDetails?.description || "Unknown stage",
controllable: stageDetails?.controllable || false,
critical: stageDetails?.critical || false,
// A stage is completed if it's before the current stage in history
// or if the current stage isn't in history and this is not the last stage
completed: currentIndex >= 0 ? index < currentIndex : index < historyStages.length - 1,
current: stage === currentPrintStage
};
});
if (currentPrintStage && !historyStages.includes(currentPrintStage)) {
const stageDetails = PrintStageDetails[currentPrintStage];
enrichedStages.push({
stage: currentPrintStage,
description: stageDetails?.description || "Unknown stage",
controllable: stageDetails?.controllable || false,
critical: stageDetails?.critical || false,
completed: false,
current: true
});
}
return enrichedStages;
}
function isPushAllCommand(data) {
return data.command === "push_status" && Object.keys(data).length >= 40;
}
var lightNodeSchema = z.enum(["chamber_light", "work_light"]);
var lightModeSchema = z.enum(["on", "off", "flashing"]);
var lightOptionsSchema = z.object({
onTime: z.number().optional(),
offTime: z.number().optional(),
loops: z.number().optional(),
interval: z.number().optional()
}).optional();
var fanTypeSchema = z.enum(["1", "2", "3"]).transform((val) => parseInt(val));
var fanSpeedSchema = z.number().min(0).max(100);
var speedLevelSchema = z.enum(["1", "2", "3", "4"]);
var tempPartSchema = z.enum(["bed", "nozzle", "chamber"]);
var temperatureSchema = z.number().min(0).max(300);
var stateSchema = z.enum(["pause", "resume", "stop"]);
var gcodesSchema = z.array(z.string());
z.nativeEnum(AMSControlAction);
var filamentSettingsSchema = z.object({
ams_id: z.number(),
tray_id: z.number(),
filament_id: z.string(),
setting_id: z.string(),
color: z.string(),
filament_type: z.string(),
nozzle_temp_min: z.number(),
nozzle_temp_max: z.number()
});
var loadFilamentSchema = z.object({
trayId: z.number(),
oldTemp: z.number().optional(),
newTemp: z.number().optional()
});
var unloadFilamentSchema = z.object({
oldTemp: z.number().optional(),
newTemp: z.number().optional()
});
var axisSchema = z.enum(["X", "Y", "Z", "E"]);
var axisControlSchema = z.object({
axis: axisSchema,
distance: z.number(),
unit: z.number().optional(),
speed: z.number().optional()
});
var cleanPrintErrorSchema = z.object({
subtaskId: z.string(),
printError: z.number()
});
var powerLossRecoverySchema = z.object({
action: z.enum(["resume", "stop"]),
subtaskId: z.string(),
printError: z.number()
});
var cameraOperationSchema = z.enum(["ipcam_record_set", "ipcam_timelapse", "ipcam_resolution_set"]);
var cameraSchema = z.object({
operation: cameraOperationSchema,
value: z.union([z.boolean(), z.string()])
});
var commandSchemas = {
updateLight: z.object({
light: lightNodeSchema,
mode: lightModeSchema,
loopOptions: lightOptionsSchema
}),
updateFan: z.object({
fan: fanTypeSchema,
speed: fanSpeedSchema
}),
updateSpeed: z.object({
speed: speedLevelSchema
}),
updateTemp: z.object({
part: tempPartSchema,
temperature: temperatureSchema
}),
updateState: z.object({
state: stateSchema
}),
gcode: z.object({
gcodes: gcodesSchema
}),
resume: z.object({
cleanPrintError: z.boolean().optional()
}),
ams_control: z.object({
param: z.any()
// This can be refined further based on AMSControlAction structure
}),
refreshPrinterState: z.object({}),
ams_filament_settings: filamentSettingsSchema,
loadFilament: loadFilamentSchema,
unloadFilament: unloadFilamentSchema,
axisControl: axisControlSchema,
autoLevel: z.object({}),
goHome: z.object({}),
cleanPrintError: cleanPrintErrorSchema,
powerLossRecovery: powerLossRecoverySchema,
camera: cameraSchema
};
function validateCommandParams(command, params) {
const schema = commandSchemas[command];
const result = schema.safeParse(params);
if (result.success) {
return { success: true, data: result.data };
} else {
return { success: false, error: result.error };
}
}
// src/commands.ts
var LightEffect = /* @__PURE__ */ ((LightEffect2) => {
LightEffect2["ON"] = "on";
LightEffect2["OFF"] = "off";
LightEffect2["FLASHING"] = "flashing";
return LightEffect2;
})(LightEffect || {});
var LightNode = /* @__PURE__ */ ((LightNode2) => {
LightNode2["CHAMBER"] = "chamber_light";
LightNode2["WORK"] = "work_light";
return LightNode2;
})(LightNode || {});
var CameraOperation = /* @__PURE__ */ ((CameraOperation2) => {
CameraOperation2["RECORD"] = "ipcam_record_set";
CameraOperation2["TIMELAPSE"] = "ipcam_timelapse";
CameraOperation2["RESOLUTION"] = "ipcam_resolution_set";
return CameraOperation2;
})(CameraOperation || {});
var FanType = /* @__PURE__ */ ((FanType2) => {
FanType2[FanType2["PART_COOLING"] = 1] = "PART_COOLING";
FanType2[FanType2["AUXILIARY"] = 2] = "AUXILIARY";
FanType2[FanType2["CHAMBER"] = 3] = "CHAMBER";
return FanType2;
})(FanType || {});
var VALID_COMMANDS = [
"updateLight",
"updateFan",
"updateSpeed",
"updateTemp",
"updateState",
"gcode",
"resume",
"ams_control",
"refreshPrinterState",
"ams_filament_settings",
"loadFilament",
"unloadFilament",
"axisControl",
"autoLevel",
"goHome",
"cleanPrintError",
"powerLossRecovery",
"camera",
"cleanPrintError"
];
var createCommand = (command, params) => ({
command,
params
});
var isValidCommand = (command) => VALID_COMMANDS.includes(command);
// src/errors.ts
var ERROR_CODES_JOB_FAILED = [
83902466,
83902467,
83902468,
83902469,
83902470,
83902471,
83902472,
83902473,
83902474,
83902475,
117456897,
83902476,
83902477,
83902478,
83902484,
83902485,
83902486,
83902509,
83902510,
83902511,
83902519,
83902520,
83902522,
83918867,
83935248,
83968052,
50348032,
50348033,
50348034,
50348045,
50364424,
50364430,
50364432
];
var LOCAL_CANCEL_CODE = 50348044;
var ALL_ERRORS = {
5324857: "Device login has expired, please try to bind again.",
50348032: "Printing stopped because homing Z axis failed.",
50348033: "The printer timed out waiting for the nozzle to cool down before homing.",
50348034: "Printing Stopped because Auto Bed Leveling failed.",
50348037: "The nozzle fan speed is abnormal.",
50348038: "The nozzle is clogged.",
50348040: "The AMS failed to change filament.",
50348041: "Homing XY axis failed.",
50348042: "Mechanical resonance frequency identification failed.",
50348043: "Internal communication exception.",
50348044: "Printing was cancelled.",
50348045: "Resume failed after power loss.",
50348046: "The motor self-check failed.",
50364416: 'Printing was paused for unknown reason. You can tap "Resume" to resume the print job.',
50364417: 'Printing was paused by the user. You can tap "Resume" to resume the print job.',
50364418: "First layer defects were detected by the Micro Lidar. Please check the quality of the printed model before continuing your print.",
50364419: "Spaghetti defects were detected by the AI Print Monitoring. Please check the quality of the printed model before continuing your print.",
50364420: "Filament ran out. Please load new filament.",
50364421: "Toolhead front cover fell off. Please remount the front cover and check to make sure your print is going okay.",
50364422: "The build plate marker was not detected. Please confirm the build plate is correctly positioned on the heatbed with all four corners aligned, and the maker is clear.",
50364423: "There was an unfinished print job when the printer lost power. If the model is still adhered to the build plate, you can try resuming the print job.",
50364424: "Printing Stopped because nozzle temperature problem.",
50364425: "Heatbed temperature malfunction.",
50364426: "A Filament pile-up was detected by the AI Print Monitoring. Please clean the filament from the waste chute.",
50364427: "The cutter is stuck. Please make sure the cutter handle is out.",
50364428: "Skipping step detected, auto-recover complete; please resume print and check if there are any layer shift problems.",
50364429: 'Some objects have fallen down, or the extruder is not extruding normally. If the defects are acceptable, click "Resume" button to resume the print job.',
50364430: "The print file is not available. Please check to see if the storage media has been removed.",
50364431: "The door seems to be open, so printing was paused.",
50364432: "Printing stopped because the hotend fan speed is abnormal.",
50364433: "Detected build plate is not the same as the Gcode file. Please adjust slicer settings or use the correct plate.",
50364435: 'Printing was paused by the user. You can select "Resume" to continue printing.',
50364436: 'The nozzle is covered with filaments, or the build plate is installed incorrectly. Please cancel this printing and clean the nozzle or adjust the build plate according to the actual status, or tap "Resume" button to resume the print job.',
50364437: 'The filament has run out, please load new filament in the "filament" page.',
50364438: 'The nozzle is clogged up with filaments. Please cancel this printing and clean the nozzle according to the actual status, or tap "Resume" button to resume the print job.',
50364439: 'Foreign objects detected on hotbed, Please check and clean the hotbed, Then tap "Resume" button to resume the print job.',
50364440: "Chamber temperature malfunction.",
50364441: "No build plate is placed.",
83902465: "Failed to connect to Bambu Cloud. Please check your network connection.",
83902466: "Unsupported print file path or name. Please resend the printing job.",
83902467: "Printing stopped because the printer was unable to parse the file. Please resend your print job.",
83902468: "The printer can't receive new print jobs while printing. Resend after the current print finishes.",
83902469: "Print jobs are not allowed to be sent while updating firmware.",
83902470: "There is not enough free storage space for the print job. Restoring to factory settings can release available space.",
83902471: "Print jobs are not allowed to be sent while force updating or when repair updating is required.",
83902472: "Starting printing failed. please power cycle the printer and resend the print job.",
83902473: "Print jobs are not allowed to be sent while updating logs.",
83902474: "The file name is not supported. Please rename and restart the printing job.",
83902475: "There was a problem downloading a file. Please check you network connection and resend the printing job.",
83902476: "Please insert a MicroSD card and restart the printing job.",
83902477: "Please run a self-test and restart the printing job.",
83902478: "Printing was cancelled.",
83902484: "Slicing for the print job failed. Please check your settings and restart the print job.",
83902485: "There is not enough free storage space for the print job. Please format or clean MicroSD card to release available space.",
83902486: "The MicroSD Card is write-protected. Please replace the MicroSD Card.",
83902487: "Binding failed. Please retry or restart the printer and retry.",
83902488: "Binding configuration information parsing failed, please try again.",
83902489: "The printer has already been bound. Please unbind it and try again.",
83902490: "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration and then try again.",
83902491: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83902492: "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service.",
83902493: "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83902494: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83902495: "Authorization timed out. Please make sure that your phone or PC has access to the internet, and ensure that the Bambu Studio/Bambu Handy APP is running in the foreground during the binding operation.",
83902496: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83902497: "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83902498: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83902499: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83902500: "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration before you try again.",
83902501: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83902502: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83902503: "Cloud access failed; this may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83902504: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83902505: "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service.",
83902506: "Failed to connect to the router, which may be caused by wireless interference or being too far away from the router. Please try again or move the printer closer to the router and try again.",
83902507: "Router connection failed due to incorrect password. Please check the password and try again.",
83902508: "Failed to obtain IP address, which may be caused by wireless interference resulting in data transmission failure or DHCP address pool of the router being full. Please move the printer closer to the router and try again. If the issue persists, please check router settings to see whether the IP addresses have been exhausted.",
83902509: "System exception.",
83902510: "The system does not support the file system currently used by the Micro SD card. Please replace the Micro SD card or format the current Micro SD card to FAT32.",
83902511: "The Micro SD card sector data is damaged. Please use the SD card repair tool to repair or format it. If it still cannot be identified, please replace the Micro SD card.",
83902519: "Your sliced file is not compatible with current printer model. This file can't be printed on this printer.",
83902520: "The nozzle diameter in sliced file is not consistent with the current nozzle setting. This file can't be printed.",
83902522: "The current temperature is too low. In order to protect you and your printer. Printing task, moving axis and other operations is disabled. Please move the printer to an environment above 10 celsius degree.",
83918867: "The print file is not available. Please check to see if the storage media has been removed.",
83918902: "Your sliced file is not consistent with the current printer model. Continue?",
83935248: "MicroSD Card read/write exception. please reinsert or replace MicroSD Card.",
83968023: "Binding failed. Please retry or restart the printer and retry.",
83968024: "Binding configuration information parsing failed, please try again.",
83968025: "The printer has already been bound. Please unbind it and try again.",
83968026: "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration and then try again.",
83968027: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83968028: "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service.",
83968029: "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83968030: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83968031: "Authorization timed out. Please make sure that your phone or PC has access to the internet, and ensure that the Bambu Studio/Bambu Handy APP is running in the foreground during the binding operation.",
83968032: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83968033: "Cloud access failed, which may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83968034: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83968035: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83968036: "Cloud access failed. Possible reasons include network instability caused by interference, inability to access the internet, or router firewall configuration restrictions. You can try moving the printer closer to the router or checking the router configuration before you try again.",
83968037: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83968038: "Cloud access rejected. If you have tried multiple times and are still failing, please contact customer service.",
83968039: "Cloud access failed; this may be caused by network instability due to interference. You can try moving the printer closer to the router before you try again.",
83968040: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.",
83968041: "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service.",
83968049: "Device discovery binding is in progress, and the QR code cannot be displayed on the screen. You can wait for the binding to finish or abort the device discovery binding process in the APP/Studio and retry scanning the QR code on the screen for binding.",
83968050: "QR code binding is in progress, so device discovery binding cannot be performed. You can scan the QR code on the screen for binding or exit the QR code display page on screen and try device discovery binding.",
83968051: "Your APP region is not matched with your printer, please download the APP in the corresponding region and register your account again.",
83968052: "The slicing progress has not been updated for a long time, and the printing task has exited. Please confirm the parameters and reinitiate printing.",
83968053: "The device is in the process of binding and cannot respond to new binding requests.",
83968056: "The regional settings do not match the printer, please check the printer's regional settings.",
117456897: "The AMS has been disabled for a print, but it still has filament loaded. Please unload the AMS filament , and switch to the spool holder filament for printing.",
117473281: 'Failed to cut the filament. Please check the cutter. After troubleshooting, click the "Retry" button.',
117473282: "The cutter is stuck. Please make sure the cutter handle is out.",
117473283: "Failed to pull out the filament from the extruder. This might be caused by clogged extruder or filament broken inside the extruder.",
117473284: "AMS failed to pull back filament. This could be due to a stuck spool or the end of the filament being stuck in the path.",
117473285: "The AMS failed to send out filament. You can clip the end of your filament flat, and reinsert. If this message persists, please check the PTFE tubes in AMS for any signs of wear and tear.",
117473286: "Unable to feed filament into the extruder. This could be due to entangled filament or a stuck spool. If not, please check if the AMS PTFE tube is connected.",
117473287: "Extruding filament failed. The extruder might be clogged.",
117473296: "The AMS assist motor is overloaded. This could be due to entangled filament or a stuck spool.",
117473297: "AMS filament ran out. Please insert a new filament into the same AMS slot.",
117473298: 'Failed to get AMS mapping table; please click "Retry" to continue.',
117473299: 'Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the "Retry" button.',
117522433: "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing.",
117538817: 'Failed to cut the filament. Please check the cutter. After troubleshooting, click the "Retry" button.',
117538818: 'The cutter is stuck. Please pull out the cutter handle and click the "Retry" button.',
117538819: "Failed to pull out the filament from the extruder. There may be an extruder clog or broken filament inside the extruder.",
117538820: "AMS failed to pull back filament. This could be due to a stuck spool or the end of the filament being stuck in the path.",
117538821: "The AMS failed to send filament. You canclip the end of your filament flat, and reinsert. If this message persists, please check the PTFE tubes in AMS for any signs of wear and tear.",
117538822: "Unable to feed filament into the extruder. This could be due to entangled filament or a stuck spool.",
117538823: 'Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the "Retry" button.',
117538832: "The AMS assist motor is overloaded. This could be due to entangled filament or a stuck spool.",
117538833: "AMS filament ran out. Please insert a new filament into the same AMS slot.",
117538834: 'Failed to get AMS mapping table; please click "Retry" to continue.',
117538835: 'Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the "Retry" button.',
117587969: "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing.",
117604353: 'Failed to cut the filament. Please check the cutter. After troubleshooting, click the "Retry" button.',
117604354: 'The cutter is stuck. Please pull out the cutter handle and click the "Retry" button.',
117604355: 'Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the "Retry" button.',
117604356: 'Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the "Retry" button.',
117604357: 'Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the "Retry" button.',
117604358: 'Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the "Retry" button.',
117604359: 'Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the "Retry" button.',
117604368: 'AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the "Retry" button.',
117604369: "AMS filament ran out. Please insert a new filament into the same AMS slot.",
117604370: 'Failed to get AMS mapping table; please click "Retry" to continue.',
117604371: 'Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the "Retry" button.',
117653505: "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing.",
117669889: 'Failed to cut the filament. Please check the cutter. After troubleshooting, click the "Retry" button.',
117669890: 'The cutter is stuck. Please pull out the cutter handle and click the "Retry" button.',
117669891: 'Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the "Retry" button.',
117669892: 'Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the "Retry" button.',
117669893: 'Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the "Retry" button.',
117669894: 'Failed to feed the filament into the toolhead. Please check whether the filament or the spool is stuck. After troubleshooting, click the "Retry" button.',
117669895: 'Failed to extrude the filament. Please check if the extruder clogged. After troubleshooting, click the "Retry" button.',
117669904: 'AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the "Retry" button.',
117669905: "AMS filament ran out. Please insert a new filament into the same AMS slot.",
117669906: 'Failed to get AMS mapping table; please click "Retry" to continue.',
117669907: 'Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the "Retry" button.',
134168577: "Filament is still loaded from the AMS after it has been disabled. Please unload the filament, load from the spool holder, and restart printing.",
134184961: 'Failed to cut the filament. Please check the cutter. After troubleshooting, click the "Retry" button.',
134184962: 'The cutter is stuck. Please pull out the cutter handle and click the "Retry" button.',
134184963: "Please pull out the filament on the spool holder. If this message persists, please check to see if there is filament broken in the extruder. (Connect PTFE tube if you are about to use AMS)",
134184964: 'Failed to pull back the filament from the toolhead to AMS. Please check whether the filament or the spool is stuck. After troubleshooting, click the "retry" button.',
134184965: 'Failed to feed the filament outside the AMS. Please clip the end of the filament flat and check to see if the spool is stuck. After troubleshooting, click the "Retry" button.',
134184966: "Please feed filament into the PTFE tube until it can not be pushed any farther.",
134184967: 'Please observe the nozzle. If the filament has been extruded, click "Done"; if it is not, please push the filament forward slightly and then click "Retry".',
134184976: 'AMS assist motor is overloaded. Please check if the spool or filament is stuck. After troubleshooting, click the "Retry" button.',
134184977: 'AMS filament ran out. Please put a new filament into AMS and click the "Retry" button.',
134184978: 'Failed to get AMS mapping table; please click "Retry" to continue.',
134184979: 'Timeout purging old filament: Please check if the filament is stuck or the extruder is clogged. After troubleshooting, click the "Retry" button.',
134201347: "Please pull out the filament on the spool holder. If this message persists, please check to see if there is filament broken in the extruder or PTFE Tube. (Connect PTFE tube if you are about to use AMS)",
134201350: "Please feed filament into the PTFE tube until it can not be pushed any farther.",
201359361: 'First layer defects were detected. If the defects are acceptable, click "Resume" button to resume the print job.',
201359362: "Spaghetti failure was detected.",
201359365: "Purged filament has piled up in the waste chute, which may cause a tool head collision.",
201359369: "Build plate localization marker was not found.",
201359370: "The detected build plate is not the same as in G-code.",
201375747: "Possible defects were detected in the first layer.",
201375748: "Possible spaghetti failure was detected.",
201375750: "Purged filament may have piled up in the waste chute.",
268484609: "High bed temperature may lead to filament clogging in the nozzle. Please ensure ventilation for the printer.",
268484610: "Printing CF material with stainless steel may cause nozzle damage.",
268484611: "Enabling traditional timelapse might lead to defects. Please enable it as needed?",
268550145: "Timelapse is not supported because Spiral vase is enabled in slicing presets.",
268550146: 'Timelapse is not supported because Print sequence is set to "By object".',
302006273: "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, and restart print job.",
302022657: "Cutting the filament failed. Please check to see if the cutter is stuck. Refer to the Assistant for solutions.",
302022658: 'The cutter is stuck. Please pull out the cutter handle and click the "Retry" button.',
302022659: 'Failed to pull out the filament from the extruder. Please check whether the extruder is clogged or whether the filament is broken inside the extruder. After troubleshooting, click the "Retry" button.',
302022660: 'Failed to pull back the filament from the toolhead. Please check whether the filament is stuck. After troubleshooting, click the "Retry" button.',
302022661: 'Failed to feed the filament. Please load the filament, then click the "Retry" button.',
302022662: 'Failed to feed the filament into the toolhead. Please check whether the filament is stuck. After troubleshooting, click the "Retry" button.',
302022663: "Failed to extrude the filament. This might be caused by clogged extruder or stuck filament. Refer to the Assistant for solutions.",
302022672: "Filament or spool may be stuck.",
302022673: "AMS filament ran out. Please insert a new filament into the same AMS slot.",
302022674: 'Failed to get AMS mapping table. Please click the "Retry" button to continue.',
302022675: 'Timeout while purging old filament. Please check if the filament is stuck or the extruder clogged. After troubleshooting, click the "Retry" button.',
302022676: "The filament location in the toolhead was not found. Refer to the Assistant for solutions.",
302022677: "Failed to pull out the filament from the toolhead. Please check if the filament is stuck, or the filament is broken inside the extruder or PTFE tube.",
302022678: 'The extruder is not extruding normally, please refer to the HMS. After trouble shooting. If the defects are acceptable, please click "Retry" button.',
302071809: "Filament is still loaded from the AMS when it has been disabled. Please unload AMS filament, load from spool holder, an