@hiv3d/bambu-types
Version:
TypeScript types and utilities for Bambu Lab 3D printers including error codes, commands, and API types
1,450 lines (1,444 loc) • 95.2 kB
TypeScript
import { z } from 'zod';
type StringNumber = `${number}`;
type StringBoolean = `${boolean}`;
type NumberRange<start extends number, end extends number, arr extends unknown[] = [], acc extends number = never> = arr["length"] extends end ? acc | start | end : NumberRange<start, end, [
...arr,
1
], arr[start] extends undefined ? acc : acc | arr["length"]>;
type StringNumberRange<F extends number, T extends number> = `${NumberRange<F, T>}`;
/**
* Valid AMS control actions
*/
declare enum AMSControlAction {
RESUME = "resume",
RESET = "reset",
PAUSE = "pause",
DONE = "done"
}
type State = "pause" | "resume" | "stop";
type PrintMessageCommands = "push_status" | "ams_control" | State | "gcode_line" | "gcode_file" | "project_file";
type PrintMessageCommand = {
command: PrintMessageCommands;
param?: string;
sequence_id: string;
};
interface PrintMessage {
print: PrintMessageCommand;
}
declare function isPrintMessage(data: any): data is PrintMessage;
type PrinterStatus = "FINISH" | "FAILED" | "RUNNING" | "IDLE" | "PAUSE" | "PREPARE" | "SLICING";
/**
* Every stage of a print.
* Extracted from https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp
*/
declare enum PrintStage {
"PRINTING" = "Printing",
"BED_LEVELING" = "Auto bed leveling",
"HEATBED_PREHEATING" = "Heatbed preheating",
"XY_MECH_MODE_SWEEP" = "Sweeping XY mech mode",
"CHANGE_MATERIAL" = "Changing filament",
"M400_PAUSE" = "M400 pause",
"FILAMENT_RUNOUT_PAUSE" = "Paused due to filament runout",
"HOTEND_HEATING" = "Heating hotend",
"EXTRUDE_COMPENSATION_SCAN" = "Calibrating extrusion",
"BED_SCAN" = "Scanning bed surface",
"FIRST_LAYER_SCAN" = "Inspecting first layer",
"BE_SURFACE_TYPT_IDENTIFICATION" = "Identifying build plate type",
"SCANNER_EXTRINSIC_PARA_CALI" = "Calibrating Micro Lidar",
"TOOLHEAD_HOMING" = "Homing toolhead",
"NOZZLE_TIP_CLEANING" = "Cleaning nozzle tip",
"EXTRUDER_TEMP_PROTECT_CALI" = "Checking extruder temperature",
"USER_PAUSE" = "Printing was paused by the user",
"TOOLHEAD_SHELL_OFF_PAUSE" = "Pause of front cover falling",
"SCANNER_LASER_PARA_CALI" = "Calibrating the micro lida",
"EXTRUDER_ABSOLUTE_FLOW_CALI" = "Calibrating extrusion flow",
"HOTEND_TEMPERATURE_ERROR_PAUSE" = "Paused due to nozzle temperature malfunction",
"HEATED_BED_TEMPERATURE_ERROR_PAUSE" = "Paused due to heat bed temperature malfunction",
"FILAMENT_UNLOADING" = "Filament unloading",
"SKIP_STEP_PAUSE" = "Skip step pause",
"FILAMENT_LOADING" = "Filament loading",
"MOTOR_NOISE_CALIBRATION" = "Motor noise calibration",
"AMS_LOST_PAUSE" = "Paused due to AMS lost",
"HEAT_BREAK_FAN_PAUSE" = "Paused due to low speed of the heat break fan",
"CHAMBER_TEMPERATURE_CONTROL_ERROR_PAUSE" = "Paused due to chamber temperature control error",
"CHAMBER_COOLING" = "Cooling chamber",
"USER_INSERT_GCODE_PAUSE" = "Paused by the Gcode inserted by user",
"MOTOR_NOISE_SHOWOFF" = "Motor noise showoff",
"NOZZLE_FILAMENT_COVERED_DETECTED_PAUSE" = "Nozzle filament covered detected pause",
"CUTTER_ERROR_PAUSE" = "Cutter error pause",
"FIRST_LAYER_ERROR_PAUSE" = "First layer error pause",
"NOZZLE_CLOG_PAUSE" = "Nozzle clog pause"
}
/**
* Maps numeric stage_curr values to PrintStage enum values
*/
declare const stageCurrToStage: Record<number, PrintStage>;
/**
* Detailed information about a print stage
*/
interface PrintStageInfo {
/** The current stage of printing */
stage: PrintStage;
/** Progress percentage within the current stage (0-100) */
progress: number;
/** Human-readable name of the stage */
name: string;
/** Detailed description of what's happening in this stage */
description: string;
/** Whether this stage can be controlled (paused/resumed/skipped) */
controllable: boolean;
/** Whether this stage is critical for print success */
critical: boolean;
/** Estimated time remaining in this stage (seconds) */
timeRemaining?: number;
}
declare const PrintStageDetails: Record<PrintStage, Partial<PrintStageInfo>>;
/**
* Speed levels of the printer.
*
* Extracted from https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.hpp#L73-L80
*/
declare enum SpeedLevel {
SILENT = "1",
NORMAL = "2",
SPORT = "3",
LUDICROUS = "4"
}
declare enum FilamentType {
PLA = "PLA",
ABS = "ABS",
TPU = "TPU",
PC = "PC",
ASA = "ASA",
PA_CF = "PA-CF",
PA6_CF = "PA6-CF",
PET_CF = "PET-CF",
PETG = "PETG",
PETG_CF = "PETG-CF",
PLA_AERO = "PLA-AERO",
PLA_CF = "PLA-CF",
PPA_CF = "PPA-CF",
PPA_GF = "PPA-GF",
PA = "PA",
HIPS = "HIPS",
PPS = "PPS",
PPS_CF = "PPS-CF",
PVA = "PVA",
PLA_S = "PLA-S",
PA_S = "PLA-S"
}
/**
* An AMS tray (filament slot) instance.
*/
interface AMSTray$1 {
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
bed_temp: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
bed_temp_type: string;
/**
* Unknown. Bambu Studio doesn't even check for it.
*
* Probably the temperature required for filament drying.
*/
drying_temp: string;
/**
* Probably the time required for filament drying.
*/
drying_time: string;
/**
* The ID of the tray.
*/
id: string;
/**
* The loaded filament's maximum nozzle temperature.
*/
nozzle_temp_max: StringNumber;
/**
* The loaded filament's minimum nozzle temperature.
*/
nozzle_temp_min: StringNumber;
/**
* The amount filament remaining in %, if enabled and an official Bambu filament is loaded.
*
* With non-official Bambu filament:
* - 0: Tracking is disabled.
* - -1: Tracking is enabled.
*/
remain: number;
/**
* The UID of the filament's NFC that was scanned.
*
* Uses:
* - Check if filament's manufacturer is Bambu Lab: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1090-L1101
*
* TODO: Extract when received from printer / provide helper function to do so.
*/
tag_uid: string;
/**
* The color of the filament loaded in HEX color code.
*/
tray_color: string;
/**
* The diameter of the spool loaded.
*/
tray_diameter: 1.75;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
tray_id_name: string;
/**
* The ID of the base config file for the filament.
*
* Uses:
* - Associate the filament loaded with it's complete brand name. Use the `getFilamentConfig` function for getting the config.
*
* Config files can be found here: https://github.com/bambulab/BambuStudio/tree/master/resources/profiles/BBL/filament
*/
tray_info_idx: string;
/**
* No use cases are known.
*/
tray_sub_brands: "";
/**
* The type of filament loaded into the tray (filament slot).
*/
tray_type: FilamentType;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
tray_uuid: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
tray_weight: string;
/**
* Information about the AI camera features (?)
*/
xcam_info: string;
}
/**
* An AMS instance.
*/
interface AMS {
humidity: string;
id: string;
temp: string;
tray: [
AMSTray$1 | undefined,
AMSTray$1 | undefined,
AMSTray$1 | undefined,
AMSTray$1 | undefined
];
}
/**
* External spool (tray). This has unused values due to being a copy of the AMS trays.
*/
interface ExternalTray extends AMSTray$1 {
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
cols: StringNumber[];
/**
* The ID of the tray.
*/
id: "254";
/**
* The loaded filament's "k" value (manually set in Bambu Studio).
*/
k: number;
/**
* The loaded filament's "n" value (manually set in Bambu Studio).
*/
n: number;
}
/**
* Status of the AMS' RFID reader.
*/
declare enum AmsRFIDStatus {
IDLE = 0,
READING = 1,
GCODE_TRANS = 2,
GCODE_RUNNING = 3,
ASSISTANT = 4,
SWITCH_FILAMENT = 5,
HAS_FILAMENT = 6
}
/**
* Bambu Lab's proprietary Health Management System (HMS).
*
* More info: https://wiki.bambulab.com/en/x1/troubleshooting/intro-hms
*
* All error codes: https://wiki.bambulab.com/en/hms/home
*/
interface HMS {
attr: number;
code: number;
}
/**
* Interior lighting related status instance.
*/
interface LightReport {
node: "chamber_light" | "work_light";
mode: "on" | "off" | "flashing";
}
/**
* The possible progress states of a firmware upgrade.
*
* Extracted from https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L3481-L3494
*/
declare enum UpgradeStatusProgressState {
DOWNLOADING = "DOWNLOADING",
UPGRADE_REQUEST = "UPGRADE_REQUEST",
PRE_FLASH_START = "PRE_FLASH_START",
PRE_FLASH_SUCCESS = "PRE_FLASH_SUCCESS"
}
/**
* The possible finish states of a firmware upgrade.
*
* Extracted from https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L3481-L3494
*/
declare enum UpgradeStatusFinishState {
UPGRADE_SUCCESS = "UPGRADE_SUCCESS",
DOWNLOAD_FAIL = "DOWNLOAD_FAIL",
FLASH_FAIL = "FLASH_FAIL",
PRE_FLASH_FAIL = "PRE_FLASH_FAIL",
UPGRADE_FAIL = "UPGRADE_FAIL"
}
/**
* Error codes thrown by the upgrade.
*/
declare enum UpgradeErrorCode {
UpgradeNoError = 0,
UpgradeDownloadFailed = 1,
UpgradeVerifyFailed = 2,
UpgradeFlashFailed = 3,
UpgradePrinting = 4
}
/**
* The possible states the printer's screen will display.
*/
declare enum UpgradeDisplayState {
UNAVAILABLE = 0,
IDLE = 1,
UPGRADING = 2,
UPGRADE_FINISHED = 3
}
/**
* Contains basic data about a filament, which is then extended by the final product.
*/
interface BaseFilamentConfig {
type: "filament";
name: string;
inherits: string;
from: string;
instantiation: StringBoolean;
fan_cooling_layer_time: [StringNumber];
filament_max_volumetric_speed: [StringNumber];
filament_density: [StringNumber];
filament_cost: [StringNumber];
cool_plate_temp: [StringNumber];
eng_plate_temp: [StringNumber];
hot_plate_temp: [StringNumber];
textured_plate_temp: [StringNumber];
cool_plate_temp_initial_layer: [StringNumber];
eng_plate_temp_initial_layer: [StringNumber];
hot_plate_temp_initial_layer: [StringNumber];
textured_plate_temp_initial_layer: [StringNumber];
nozzle_temperature_initial_layer: [StringNumber];
reduce_fan_stop_start_freq: [StringNumber];
fan_min_speed: [StringNumber];
overhang_fan_threshold: [StringNumber];
close_fan_the_first_x_layers: [StringNumber];
nozzle_temperature: [StringNumber];
temperature_vitrification: [StringNumber];
nozzle_temperature_range_low: [StringNumber];
nozzle_temperature_range_high: [StringNumber];
slow_down_min_speed: [StringNumber];
slow_down_layer_time: [StringNumber];
additional_cooling_fan_speed: [StringNumber];
filament_start_gcode: [string];
}
/**
* The config files ending with @base
*/
interface ExtendedFilamentConfig extends Partial<BaseFilamentConfig> {
type: "filament";
name: string;
inherits: string;
from: string;
filament_id: string;
setting_id: string;
}
/**
* The final filament config data. Contains the inherited and @base file data.
*/
interface FilamentConfig {
type: "filament";
name: string;
inherits: string;
from: string;
filament_id: string;
instantiation: StringBoolean;
filament_cost: [StringNumber];
filament_vendor: [string];
nozzle_temp_min: string;
nozzle_temp_max: string;
bed_temp: string;
bed_temp_type: string;
}
interface FilamentConfigs {
[key: string]: FilamentConfig;
}
declare const filamentConfigs: FilamentConfigs;
/**
* Reports all sensors and statuses of the printer.
*/
interface PushAllResponse extends PrintMessageCommand {
/**
* Status of all connected AMSes.
*/
ams: {
ams: [] | [AMS] | [AMS, AMS] | [AMS, AMS, AMS] | [AMS, AMS, AMS, AMS];
/**
* Unknown.
*
* Probably used for checking for new AMSes.
*/
ams_exist_bits: StringNumber;
/**
* Unknown.
*
* Could possibly be related to storing whether the filament's data has been read from the AMSes.
*/
insert_flag: boolean;
/**
* Exact definition is unknown, but it appears to be used for checking if all filaments have been read since startup or not.
*/
power_on_flag: boolean;
/**
* Unknown.
*
* Probably used for checking for new AMSes.
*/
tray_exist_bits: StringNumber;
/**
* Unknown.
*
* Probably used for checking for new AMSes.
*/
tray_is_bbl_bits: StringNumber;
/**
* Current tray selected by all AMSes.
* - 254: external spool (vt_tray)
* - otherwise: ((ams_id * 4) + tray_id) for current tray
*
* @example Ams 2 tray 2 would be: (1*4)+1 = 5.
*/
tray_now: StringNumber;
/**
* Unknown.
*
* Probably used for checking which filament slots (trays) have already been read.
*/
tray_read_done_bits: StringNumber;
/**
* Unknown.
*
* Probably used for signalling which filament slots (trays) are currently being read.
*/
tray_reading_bits: StringNumber;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
tray_tar: StringNumber;
/**
* Unknown.
*
* Could possibly be related to the AMS UI on the X1 series and in Bambu Studio.
*/
version: number;
};
/**
* The RFID reader status of the connected AMSes.
*/
ams_rfid_status: AmsRFIDStatus;
/**
* The AMS status.
*
* How to extract it: https://github.com/bambulab/BambuStudio/blob/f96b6cd433cf925e9759260925cd2142abf298ef/src/slic3r/GUI/DeviceManager.cpp#L736-L759
*
* TODO: Extract when received from printer / provide helper function to do so.
*/
ams_status: number;
/**
* The target temperature of the printing bed in Celsius.
*/
bed_target_temper: number;
/**
* The temperature of the printing bed in Celsius.
*/
bed_temper: number;
/**
* Speed of the auxiliary fan in %.
*/
big_fan1_speed: StringNumberRange<0, 100>;
/**
* Speed of the chamber fan in %.
*/
big_fan2_speed: StringNumberRange<0, 100>;
/**
* Interior chamber temperature.
*/
chamber_temper: number;
/**
* The interior chamber's target temperature.
*
* Exists on the X1 series but only used on the X1E.
*/
ctt: number;
/**
* `chamber_temper` doesn't make sense on P1 series (due to it not being enclosed
* by default) hence the `frame_temper` property.
*
* Even though `chamber_temper` exists, there is no physical sensor for it, but it is still included for some reason.
*
* The value of `chamber_temper` on the P1 series is a placeholder.
*/
frame_temper: number;
/**
* The command the response corresponds to.
*/
command: "push_status";
/**
* Speed of the part cooling fan in %.
*/
cooling_fan_speed: StringNumberRange<0, 100>;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
fail_reason: StringNumber;
/**
* Array of filament backup groups. Each number is a bitmap where each bit represents
* an AMS slot that can be used as backup for that filament group. Compatible slots
* (same filament type and color) are grouped together.
*
* For example, if slots 0 and 4 contain the same filament type and color,
* they would be in the same group with bitmap value 17 (binary: 0001 0001).
*/
filam_bak: number[];
/**
* Contains the current speed of all the fans
*
* How to extract it: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L3273-L3279
*
* TODO: Extract when received from printer / provide helper function to do so.
*/
fan_gear: number;
/**
* Something related to the firmware upgrades.
*/
force_upgrade: boolean;
/**
* Name of the GCode file that is currently printing.
*
* In most cases it's in the format "/plate_#.gcode", unless printing a
* gcode file directly (bbl.gcode, or calibration gcodes) instead of a 3mf.
*/
gcode_file: string;
/**
* % of GCode prepared (sliced?)
*/
gcode_file_prepare_percent: StringNumberRange<0, 100>;
/**
* Epoch time when the print started.
*/
gcode_start_time: StringNumber;
/**
* The current status of the printer.
*/
gcode_state: PrinterStatus;
/**
* Fan speed in %
*
* Heat break fan: The smaller fan on the hotend itself
*/
heatbreak_fan_speed: StringNumberRange<0, 100>;
/**
* Bambu Lab's proprietary Health Management System (HMS)
*
* More info: https://wiki.bambulab.com/en/x1/troubleshooting/intro-hms
*
* All error codes: https://wiki.bambulab.com/en/hms/home
*/
hms: HMS[];
/**
* This single property houses a lot of data regarding the printer.
* There's currently no documentation for it except Bambu Studio's source code:
*
* - Check if axes are homed: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1255-L1269
* - Check if printer is using 220V: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1346-L1351
* - Check if camera is currently recording: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1353
* - Check if AI camera detected filament entanglement: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1368
* - Check if motor noise cancellation has been calibrated: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1376-L1378
* - Check if the current machine is a P1P and has the enclosure enabled: https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1380-L1387
* - Check current SD card state (has a lot more info than the sdcard property): https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1389
* - Check if printer is using wired network (ethernet; X1E exclusive): https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1391
*/
home_flag: number;
hw_switch_state: number;
/**
* The printer's onboard camera.
*/
ipcam: {
/**
* The IP and path to the LAN liveview, otherwise disabled.
* @version X1 series exclusive
*/
liveview: string | "disable";
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
tukt_server: string;
/**
* 0: Doesn't have camera
* 1: Has camera
*/
ipcam_dev: StringNumberRange<0, 1>;
/**
* Whether recording while printing is enabled.
*/
ipcam_record: "enable" | "disable";
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
mode_bits: 3;
/**
* The camera's resolution
*
* The value is known to be very weird on the A1 series.
*/
resolution: "720p" | "1080p" | string;
/**
* Whether creating a timelapse while printing is enabled.
*/
timelapse: "enable" | "disable";
};
/**
* Current layer number while printing.
*/
layer_num: number;
/**
* Probably to differentiate between in-house prototypes and production machines.
*/
lifecycle: "product" | "engineer";
/**
* Internal light states
*/
lights_report: LightReport[];
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
maintain: number;
/**
* % of print done
*/
mc_percent: NumberRange<0, 100>;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*
* Perhaps the current GCode line while printing?
*/
mc_print_line_number: StringNumber;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
mc_print_error_code: "0" | StringNumber;
/**
* Something to do with signalling if calibration is done according to source code
*
* https://github.com/bambulab/BambuStudio/blob/master/src/slic3r/GUI/DeviceManager.cpp#L1331-L1342
*/
mc_print_stage: StringNumberRange<1, 3>;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
mc_print_sub_stage: number;
/**
* Remaining time from print.
*/
mc_remaining_time: number;
/**
* Probably to differentiate between in-house prototypes and production machines
*/
mess_production_state: "active" | "inactive";
/**
* - 0: Full (pushAll) message
* - 1: Partial (pushStatus) "difference" message (only changed properties are sent)
*
* @deprecated Unavailable on the X1 series in LAN mode.
*
* You can instead use isPushAllCommand or isPushStatusCommand from /responses or create a new PushAllCommand and PushStatus command from /commands and use their ownsResponse method for consistency.
*/
msg: NumberRange<0, 1>;
/**
* The target temperature of the nozzle in Celsius.
*/
nozzle_target_temper: number;
/**
* The temperature of the nozzle in Celsius.
*/
nozzle_temper: number;
/**
* Signals the status of some components of the printer and/or accessories.
*/
online: {
/**
* Unknown.
*/
ahb: boolean;
/**
* The RFID reader.
*/
rfid: boolean;
/**
* Unknown.
*/
version: number;
};
/**
* Unknown. Some error code standard which isn't defined in Bambu Studio.
*
* These codes can be cleared using `system.clean_print_error` command.
*/
print_error: number;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
print_gcode_action: number;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
print_real_action: number;
/**
* Where the print originates from.
*/
print_type: "cloud" | "system" | "local" | "idle";
/**
* Unknown. Something related to what's being printed.
*/
profile_id: StringNumber;
/**
* Unknown. Something related to what's being printed.
*/
project_id: StringNumber;
/**
* Unknown. Something related to a print queue. (?)
*/
queue_est: number;
/**
* Unknown. Something related to a print queue. (?)
*/
queue_number: number;
/**
* Unknown. Something related to a print queue. (?)
*/
queue_sts: number;
/**
* Unknown. Something related to a print queue. (?)
*/
queue_total: number;
/**
* Objects that have been skipped by the printer while printing,
*/
s_obj: unknown[];
/**
* Whether the SD card is inserted.
*/
sdcard: boolean;
/**
* Related to general MQTT commands on all Bambu Lab printers. Incremented by one each response/request.
*/
sequence_id: StringNumber;
/**
* The current speed level.
*/
spd_lvl: SpeedLevel;
/**
* The current speed level in %.
*/
spd_mag: NumberRange<50, 166>;
/**
* An x (unknown) amount of previous stages.
*/
stg: PrintStage[];
/**
* The current print stage.
*/
stg_cur: PrintStage;
/**
* Main purpose is unknown.
* - 0: printing from SD card
*/
subtask_id: StringNumber;
/**
* The name of the calibration gcode (without file extension), or the project file name (.3mf - with file extension)
*/
subtask_name: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
task_id: StringNumber;
/**
* Total layer number of the current job.
*/
total_layer_num: number;
/**
* Firmware upgrade status data of the printer.
*/
upgrade_state: {
/**
* Unknown.
*
* Some component's new version number.
*/
ahb_new_version_number: string;
/**
* The new version number of the AMS(es).
*/
ams_new_version_number: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
consistency_request: boolean;
/**
* What the display should say in the process.
*/
dis_state: UpgradeDisplayState;
/**
* Error codes thrown by the upgrade.
*/
err_code: UpgradeErrorCode;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*
* Probably has something to do with an update the user can't deny. (for ex.: security vulnerabilities)
*/
force_upgrade: boolean;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
message: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
module: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
new_ver_list: string;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
new_version_state: number;
/**
* Unknown. Bambu Studio appears to do nothing with it.
*/
ota_new_version_number: string;
/**
* The progress of the update in %.
*/
progress: StringNumberRange<0, 100>;
/**
* Incremented by one every time a new status is returned.
*/
sequence_id: number;
/**
* The progress / finish states of the upgrade.
*/
status: UpgradeStatusProgressState & UpgradeStatusFinishState;
};
/**
* Print file download status data.
*/
upload: {
/**
* Downloaded file size (?)
*/
file_size: number;
/**
* Total file size (?)
*/
finish_size: number;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
message: string;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
oss_url: string;
/**
* The progress of the file download in %.
*/
progress: StringNumberRange<0, 100>;
/**
* Incremented by one every time a new status is returned.
*/
sequence_id: StringNumber;
/**
* Download speed in unknown units.
*/
speed: number;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
status: "idle" | string;
/**
* Unknown. Bambu Studio doesn't even check for it.
*/
task_id: string;
/**
* Time remaining until download completes in unknown units.
*/
time_remaining: number;
/**
* Unknown. Bambu Studio doesn't even check for it.
*
* Probably some kind of error code.
*/
trouble_id: string;
};
/**
* External spool (tray). This has unused values due to being a copy of the AMS trays.
*/
vt_tray: ExternalTray;
/**
* The signal strength of the Wi-Fi signal which the printer is connected to in dBm.
*/
wifi_signal: `-${number}dBm`;
/**
* AI-related features of the printer's camera.
*/
xcam: {
/**
* Whether skipping parts setting is enabled.
*/
allow_skip_parts: boolean;
/**
* Whether the printer should detect the correct orientation and type of the buildplate.
*/
buildplate_marker_detector: boolean;
/**
* Whether the first layer inspection is enabled for the printer.
*/
first_layer_inspector: boolean;
/**
* Whether the printer is allowed to stop the print in the event it detects an abnormality.
*/
print_halt: boolean;
/**
* The sensitivity for the spaghetti detector, first layer inspection, etc.
*/
halt_print_sensitivity: "low" | "medium" | "high";
/**
* Whether print monitoring is enabled.
*/
printing_monitor: boolean;
/**
* Whether the spaghetti detector is enabled.
*/
spaghetti_detector: boolean;
};
/**
* AI-related features' status.
*/
xcam_status: StringNumber;
}
/**
* Retrieves the FilamentConfig object associated with the specified ID.
* @param id - The ID of the FilamentConfig to retrieve.
* @returns The FilamentConfig object if found, otherwise undefined.
*/
declare function getFilamentConfig(id: string): FilamentConfig | null;
/**
* Converts a numeric stage_curr value to its corresponding PrintStage enum value
* @param stageCurr - The numeric stage value (0-35)
* @returns The corresponding PrintStage enum value, or undefined if not found
*/
declare function getStageFromCurr(stageCurr: number): PrintStage | undefined;
/**
* Converts an array of numeric stage values to an array of PrintStage enum values
* @param stages - Array of numeric stage values (0-35)
* @returns Array of corresponding PrintStage enum values, filtering out any undefined stages
*/
declare function getStagesFromArray(stages: number[]): PrintStage[];
/**
* Represents a stage with its details and completion status
*/
interface EnrichedStageInfo extends Partial<PrintStageInfo> {
stage: PrintStage;
description: string;
completed: boolean;
current: boolean;
}
/**
* Creates an enriched array of stage information with completion status
* @param currentStage - The current stage number (stage_curr)
* @param stageHistory - Array of previous stage numbers (stg)
* @returns Array of stages with their details and completion status
*
* @example
* const stages = getEnrichedStages(4, [2, 13, 24, 4]);
* // Returns array of EnrichedStageInfo with:
* // - HEATBED_PREHEATING (completed)
* // - TOOLHEAD_HOMING (completed)
* // - FILAMENT_LOADING (completed)
* // - CHANGE_MATERIAL (current, not completed)
*/
declare function getEnrichedStages(currentStage: number, stageHistory: number[]): EnrichedStageInfo[];
declare function isPushAllCommand(data: PrintMessageCommand): data is PushAllResponse;
type BambuClientPrinterStatus = "FINISH" | "FAILED" | "RUNNING" | "IDLE" | "PAUSE" | "PREPARE" | "SLICING" | "OFFLINE";
declare enum PrinterModelNamesShort {
X1C = "X1C",
X1 = "X1",
X1E = "X1E",
P1P = "P1P",
P1S = "P1S",
A1 = "A1",
A1M = "A1M",
H2D = "H2D"
}
declare enum PrinterModelIDs {
X1C = "BL-P001",
X1 = "BL-P002",
P1P = "C11",
P1S = "C12",
X1E = "C13",
A1 = "N2S",
A1M = "N1",
H2D = "O1D"
}
/**
* Mapping of printer model IDs to their friendly model names
* This includes:
* - Official model IDs from machine profiles (BL-P001, C11, etc.)
* - Full names (from project_settings.config)
*/
declare const PRINTER_MODEL_MAP: Record<PrinterModelIDs, string>;
/**
* Mapping of printer model IDs to their full names
* This includes:
* - Official model IDs from machine profiles (BL-P001, C11, etc.)
* - Full names (from project_settings.config)
*/
declare const PRINTER_MODEL_LONG_NAME_MAP: Record<PrinterModelIDs, PrinterLongNames>;
declare const CONNECT_RETURN_CODE_DESC: {
0: string;
1: string;
2: string;
3: string;
4: string;
5: string;
};
type PrinterLongNames = "Bambu Lab X1C" | "Bambu Lab X1" | "Bambu Lab P1S" | "Bambu Lab P1P" | "Bambu Lab A1" | "Bambu Lab A1 Mini" | "Bambu Lab H2D";
type AMS_PREFIX = "A" | "B" | "C" | "D";
declare const AMS_LETTER_MAP: Record<string, AMS_PREFIX>;
declare const commandSchemas: {
updateLight: z.ZodObject<{
light: z.ZodEnum<["chamber_light", "work_light"]>;
mode: z.ZodEnum<["on", "off", "flashing"]>;
loopOptions: z.ZodOptional<z.ZodObject<{
onTime: z.ZodOptional<z.ZodNumber>;
offTime: z.ZodOptional<z.ZodNumber>;
loops: z.ZodOptional<z.ZodNumber>;
interval: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
onTime?: number | undefined;
offTime?: number | undefined;
loops?: number | undefined;
interval?: number | undefined;
}, {
onTime?: number | undefined;
offTime?: number | undefined;
loops?: number | undefined;
interval?: number | undefined;
}>>;
}, "strip", z.ZodTypeAny, {
light: "chamber_light" | "work_light";
mode: "on" | "off" | "flashing";
loopOptions?: {
onTime?: number | undefined;
offTime?: number | undefined;
loops?: number | undefined;
interval?: number | undefined;
} | undefined;
}, {
light: "chamber_light" | "work_light";
mode: "on" | "off" | "flashing";
loopOptions?: {
onTime?: number | undefined;
offTime?: number | undefined;
loops?: number | undefined;
interval?: number | undefined;
} | undefined;
}>;
updateFan: z.ZodObject<{
fan: z.ZodEffects<z.ZodEnum<["1", "2", "3"]>, number, "1" | "2" | "3">;
speed: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
speed: number;
fan: number;
}, {
speed: number;
fan: "1" | "2" | "3";
}>;
updateSpeed: z.ZodObject<{
speed: z.ZodEnum<["1", "2", "3", "4"]>;
}, "strip", z.ZodTypeAny, {
speed: "1" | "2" | "3" | "4";
}, {
speed: "1" | "2" | "3" | "4";
}>;
updateTemp: z.ZodObject<{
part: z.ZodEnum<["bed", "nozzle", "chamber"]>;
temperature: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
part: "bed" | "nozzle" | "chamber";
temperature: number;
}, {
part: "bed" | "nozzle" | "chamber";
temperature: number;
}>;
updateState: z.ZodObject<{
state: z.ZodEnum<["pause", "resume", "stop"]>;
}, "strip", z.ZodTypeAny, {
state: "resume" | "pause" | "stop";
}, {
state: "resume" | "pause" | "stop";
}>;
gcode: z.ZodObject<{
gcodes: z.ZodArray<z.ZodString, "many">;
}, "strip", z.ZodTypeAny, {
gcodes: string[];
}, {
gcodes: string[];
}>;
resume: z.ZodObject<{
cleanPrintError: z.ZodOptional<z.ZodBoolean>;
}, "strip", z.ZodTypeAny, {
cleanPrintError?: boolean | undefined;
}, {
cleanPrintError?: boolean | undefined;
}>;
ams_control: z.ZodObject<{
param: z.ZodAny;
}, "strip", z.ZodTypeAny, {
param?: any;
}, {
param?: any;
}>;
refreshPrinterState: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
ams_filament_settings: z.ZodObject<{
ams_id: z.ZodNumber;
tray_id: z.ZodNumber;
filament_id: z.ZodString;
setting_id: z.ZodString;
color: z.ZodString;
filament_type: z.ZodString;
nozzle_temp_min: z.ZodNumber;
nozzle_temp_max: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
ams_id: number;
tray_id: number;
filament_id: string;
setting_id: string;
color: string;
filament_type: string;
nozzle_temp_min: number;
nozzle_temp_max: number;
}, {
ams_id: number;
tray_id: number;
filament_id: string;
setting_id: string;
color: string;
filament_type: string;
nozzle_temp_min: number;
nozzle_temp_max: number;
}>;
loadFilament: z.ZodObject<{
trayId: z.ZodNumber;
oldTemp: z.ZodOptional<z.ZodNumber>;
newTemp: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
trayId: number;
oldTemp?: number | undefined;
newTemp?: number | undefined;
}, {
trayId: number;
oldTemp?: number | undefined;
newTemp?: number | undefined;
}>;
unloadFilament: z.ZodObject<{
oldTemp: z.ZodOptional<z.ZodNumber>;
newTemp: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
oldTemp?: number | undefined;
newTemp?: number | undefined;
}, {
oldTemp?: number | undefined;
newTemp?: number | undefined;
}>;
axisControl: z.ZodObject<{
axis: z.ZodEnum<["X", "Y", "Z", "E"]>;
distance: z.ZodNumber;
unit: z.ZodOptional<z.ZodNumber>;
speed: z.ZodOptional<z.ZodNumber>;
}, "strip", z.ZodTypeAny, {
axis: "X" | "Y" | "Z" | "E";
distance: number;
unit?: number | undefined;
speed?: number | undefined;
}, {
axis: "X" | "Y" | "Z" | "E";
distance: number;
unit?: number | undefined;
speed?: number | undefined;
}>;
autoLevel: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
goHome: z.ZodObject<{}, "strip", z.ZodTypeAny, {}, {}>;
cleanPrintError: z.ZodObject<{
subtaskId: z.ZodString;
printError: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
subtaskId: string;
printError: number;
}, {
subtaskId: string;
printError: number;
}>;
powerLossRecovery: z.ZodObject<{
action: z.ZodEnum<["resume", "stop"]>;
subtaskId: z.ZodString;
printError: z.ZodNumber;
}, "strip", z.ZodTypeAny, {
subtaskId: string;
printError: number;
action: "resume" | "stop";
}, {
subtaskId: string;
printError: number;
action: "resume" | "stop";
}>;
camera: z.ZodObject<{
operation: z.ZodEnum<["ipcam_record_set", "ipcam_timelapse", "ipcam_resolution_set"]>;
value: z.ZodUnion<[z.ZodBoolean, z.ZodString]>;
}, "strip", z.ZodTypeAny, {
value: string | boolean;
operation: "ipcam_record_set" | "ipcam_timelapse" | "ipcam_resolution_set";
}, {
value: string | boolean;
operation: "ipcam_record_set" | "ipcam_timelapse" | "ipcam_resolution_set";
}>;
};
type CommandSchemas = typeof commandSchemas;
declare function validateCommandParams<T extends keyof CommandSchemas>(command: T, params: unknown): {
success: true;
data: z.infer<CommandSchemas[T]>;
} | {
success: false;
error: z.ZodError;
};
type CommandCategory = "info" | "pushing" | "system" | "print";
declare enum LightEffect {
ON = "on",
OFF = "off",
FLASHING = "flashing"
}
declare enum LightNode {
CHAMBER = "chamber_light",
WORK = "work_light"
}
interface LightOptions {
onTime?: number;
offTime?: number;
loops?: number;
interval?: number;
}
declare enum CameraOperation {
RECORD = "ipcam_record_set",
TIMELAPSE = "ipcam_timelapse",
RESOLUTION = "ipcam_resolution_set"
}
declare enum FanType {
PART_COOLING = 1,
AUXILIARY = 2,
CHAMBER = 3
}
type Axis = "X" | "Y" | "Z" | "E";
declare const VALID_COMMANDS: readonly ["updateLight", "updateFan", "updateSpeed", "updateTemp", "updateState", "gcode", "resume", "ams_control", "refreshPrinterState", "ams_filament_settings", "loadFilament", "unloadFilament", "axisControl", "autoLevel", "goHome", "cleanPrintError", "powerLossRecovery", "camera", "cleanPrintError"];
type CommandType = (typeof VALID_COMMANDS)[number];
type CommandParams = {
updateLight: {
light: LightNode;
mode: LightEffect;
loopOptions?: LightOptions;
};
updateFan: {
fan: FanType;
speed: NumberRange<0, 100>;
};
updateSpeed: {
speed: SpeedLevel;
};
updateTemp: {
part: "bed" | "nozzle" | "chamber";
temperature: NumberRange<0, 300>;
};
updateState: {
state: "pause" | "resume" | "stop";
};
gcode: {
gcodes: string[];
};
resume: {
cleanPrintError?: boolean;
};
ams_control: {
param: AMSControlAction;
};
refreshPrinterState: Record<string, never>;
ams_filament_settings: {
ams_id: number;
tray_id: number;
filament_id: string;
setting_id: string;
color: string;
filament_type: string;
nozzle_temp_min: number;
nozzle_temp_max: number;
};
loadFilament: {
trayId: number;
oldTemp?: number;
newTemp?: number;
};
unloadFilament: {
oldTemp?: number;
newTemp?: number;
};
axisControl: {
axis: Axis;
distance: number;
unit?: number;
speed?: number;
};
autoLevel: Record<string, never>;
goHome: Record<string, never>;
cleanPrintError: {
subtaskId: string;
printError: number;
};
powerLossRecovery: {
action: "resume" | "stop";
subtaskId: string;
printError: number;
};
camera: {
operation: CameraOperation;
value: boolean | string;
};
};
interface CommandResponse {
sequence_id?: string;
status?: "success" | "error";
error?: string;
}
declare const createCommand: <T extends CommandType>(command: T, params: CommandParams[T]) => {
command: T;
params: CommandParams[T];
};
declare const isValidCommand: (command: string) => command is CommandType;
/**
* Error codes that indicate a job has failed
*/
declare const ERROR_CODES_JOB_FAILED: readonly [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];
/**
* Error code for local cancellation
*/
declare const LOCAL_CANCEL_CODE = 50348044;
/**
* Type for all possible Bambu Lab error codes
*/
type BambuErrorCode = keyof typeof ALL_ERRORS;
/**
* Complete mapping of Bambu Lab error codes to their descriptions
*/
declare const ALL_ERRORS: {
readonly 5324857: "Device login has expired, please try to bind again.";
readonly 50348032: "Printing stopped because homing Z axis failed.";
readonly 50348033: "The printer timed out waiting for the nozzle to cool down before homing.";
readonly 50348034: "Printing Stopped because Auto Bed Leveling failed.";
readonly 50348037: "The nozzle fan speed is abnormal.";
readonly 50348038: "The nozzle is clogged.";
readonly 50348040: "The AMS failed to change filament.";
readonly 50348041: "Homing XY axis failed.";
readonly 50348042: "Mechanical resonance frequency identification failed.";
readonly 50348043: "Internal communication exception.";
readonly 50348044: "Printing was cancelled.";
readonly 50348045: "Resume failed after power loss.";
readonly 50348046: "The motor self-check failed.";
readonly 50364416: "Printing was paused for unknown reason. You can tap \"Resume\" to resume the print job.";
readonly 50364417: "Printing was paused by the user. You can tap \"Resume\" to resume the print job.";
readonly 50364418: "First layer defects were detected by the Micro Lidar. Please check the quality of the printed model before continuing your print.";
readonly 50364419: "Spaghetti defects were detected by the AI Print Monitoring. Please check the quality of the printed model before continuing your print.";
readonly 50364420: "Filament ran out. Please load new filament.";
readonly 50364421: "Toolhead front cover fell off. Please remount the front cover and check to make sure your print is going okay.";
readonly 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.";
readonly 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.";
readonly 50364424: "Printing Stopped because nozzle temperature problem.";
readonly 50364425: "Heatbed temperature malfunction.";
readonly 50364426: "A Filament pile-up was detected by the AI Print Monitoring. Please clean the filament from the waste chute.";
readonly 50364427: "The cutter is stuck. Please make sure the cutter handle is out.";
readonly 50364428: "Skipping step detected, auto-recover complete; please resume print and check if there are any layer shift problems.";
readonly 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.";
readonly 50364430: "The print file is not available. Please check to see if the storage media has been removed.";
readonly 50364431: "The door seems to be open, so printing was paused.";
readonly 50364432: "Printing stopped because the hotend fan speed is abnormal.";
readonly 50364433: "Detected build plate is not the same as the Gcode file. Please adjust slicer settings or use the correct plate.";
readonly 50364435: "Printing was paused by the user. You can select \"Resume\" to continue printing.";
readonly 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.";
readonly 50364437: "The filament has run out, please load new filament in the \"filament\" page.";
readonly 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.";
readonly 50364439: "Foreign objects detected on hotbed, Please check and clean the hotbed, Then tap \"Resume\" button to resume the print job.";
readonly 50364440: "Chamber temperature malfunction.";
readonly 50364441: "No build plate is placed.";
readonly 83902465: "Failed to connect to Bambu Cloud. Please check your network connection.";
readonly 83902466: "Unsupported print file path or name. Please resend the printing job.";
readonly 83902467: "Printing stopped because the printer was unable to parse the file. Please resend your print job.";
readonly 83902468: "The printer can't receive new print jobs while printing. Resend after the current print finishes.";
readonly 83902469: "Print jobs are not allowed to be sent while updating firmware.";
readonly 83902470: "There is not enough free storage space for the print job. Restoring to factory settings can release available space.";
readonly 83902471: "Print jobs are not allowed to be sent while force updating or when repair updating is required.";
readonly 83902472: "Starting printing failed. please power cycle the printer and resend the print job.";
readonly 83902473: "Print jobs are not allowed to be sent while updating logs.";
readonly 83902474: "The file name is not supported. Please rename and restart the printing job.";
readonly 83902475: "There was a problem downloading a file. Please check you network connection and resend the printing job.";
readonly 83902476: "Please insert a MicroSD card and restart the printing job.";
readonly 83902477: "Please run a self-test and restart the printing job.";
readonly 83902478: "Printing was cancelled.";
readonly 83902484: "Slicing for the print job failed. Please check your settings and restart the print job.";
readonly 83902485: "There is not enough free storage space for the print job. Please format or clean MicroSD card to release available space.";
readonly 83902486: "The MicroSD Card is write-protected. Please replace the MicroSD Card.";
readonly 83902487: "Binding failed. Please retry or restart the printer and retry.";
readonly 83902488: "Binding configuration information parsing failed, please try again.";
readonly 83902489: "The printer has already been bound. Please unbind it and try again.";
readonly 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.";
readonly 83902491: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.";
readonly 83902492: "Cloud access is rejected. If you have tried multiple times and are still failing, please contact customer service.";
readonly 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.";
readonly 83902494: "Cloud response is invalid. If you have tried multiple times and are still failing, please contact customer service.";