bambu-printer-mcp 1.1.73 → 1.1.75
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -1
- package/dist/counterpart/model-plates.d.ts +7 -1
- package/dist/counterpart/model-plates.js +8 -6
- package/dist/counterpart/plate-filaments.d.ts +8 -1
- package/dist/counterpart/plate-filaments.js +25 -8
- package/dist/index.js +1 -1
- package/dist/printers/bambu.js +10 -3
- package/dist/printers/ftp-upload.d.ts +17 -0
- package/dist/printers/ftp-upload.js +23 -0
- package/dist/refusal.d.ts +2 -1
- package/dist/refusal.js +2 -1
- package/package.json +1 -1
- package/src/counterpart/model-plates.ts +15 -7
- package/src/counterpart/plate-filaments.ts +24 -8
- package/src/index.ts +1 -1
- package/src/printers/bambu.ts +9 -3
- package/src/printers/ftp-upload.ts +26 -0
- package/src/refusal.ts +2 -1
package/README.md
CHANGED
|
@@ -1086,7 +1086,7 @@ If the project does not match those assumptions, the tool fails fast with a stru
|
|
|
1086
1086
|
|
|
1087
1087
|
#### Counterpart tools (`counterpart/1`)
|
|
1088
1088
|
|
|
1089
|
-
[Counterpart](https://github.com/DMontgomery40/scan-to-make) (Scan to Make) reads printers through a small contract that this server and [mcp-3D-printer-server](https://github.com/DMontgomery40/mcp-3D-printer-server) share. Each tool declares an `outputSchema` and returns `structuredContent`, plus the same JSON as text for older clients. An error is returned as text only, because MCP clients check `structuredContent` against the schema even on errors. Other tools return an error's details in `structuredContent` (`status`, `retryable`, `suggestion`, `message`). When the printer refuses a print, the error also carries a stable `code
|
|
1089
|
+
[Counterpart](https://github.com/DMontgomery40/scan-to-make) (Scan to Make) reads printers through a small contract that this server and [mcp-3D-printer-server](https://github.com/DMontgomery40/mcp-3D-printer-server) share. Each tool declares an `outputSchema` and returns `structuredContent`, plus the same JSON as text for older clients. An error is returned as text only, because MCP clients check `structuredContent` against the schema even on errors. Other tools return an error's details in `structuredContent` (`status`, `retryable`, `suggestion`, `message`). When the printer refuses a print, the error also carries a stable `code`: `printer-command-rejected`, `printer-not-ready`, or `printer-upload-failed` when the file didn't reach the printer and no print command was sent, so a client can act on the code rather than the wording. `counterpart_printer_info` reports `capabilities.slicing` (`supports`, `copies`, `orient`), so a client can offer those choices without knowing the slicer. `counterpart_printer_info` and `counterpart_print_progress` take the usual optional `host`, `bambu_serial`, `bambu_token` and `bambu_model` (default `BAMBU_MODEL`) arguments.
|
|
1090
1090
|
|
|
1091
1091
|
- **`counterpart_printer_info`** returns `{contract, server: {name, version}, printer: {kind: "bambu", model, serial, host}, capabilities}`. `capabilities` lists progress, layers, the camera transport (`bambu-tcp` for A1/P1, `rtsp` for X1, P2S, H2 and X2D, `none` without a model), `cameraStream: true` for supported camera models, `filaments: "ams"`, pause, resume, cancel, `print3mf` and `gcode` (false on X2D). It sends nothing to the printer and never returns the access code.
|
|
1092
1092
|
- **`counterpart_print_route`** reads or changes how prints and Stop/Pause/Resume reach the printer: `{route, mode, type, choices, savedTo}`, where `route` is `lan` (the local network, in the configured `BAMBU_DEFAULT_CONNECTION_MODE`) or `cloud` (Bambu Cloud through the [FULU bridge](docs/FULU.md)). Pass `route` to change it; the next print and control use it at once, and it is written to the `.env` in the server's working directory when one exists (`savedTo`, otherwise `null`). It is not part of the shared contract: it has no `outputSchema`, and mcp-3D-printer-server has no Bambu Cloud route.
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { type PlateFilament } from "./plate-filaments.js";
|
|
1
|
+
import { type PaintLimits, type PlateFilament } from "./plate-filaments.js";
|
|
2
2
|
export interface ModelPlate {
|
|
3
3
|
/** Zero-based, as inspect_print_file's plate_index; slice_stl's slice_plate is index + 1. */
|
|
4
4
|
index: number;
|
|
@@ -21,6 +21,11 @@ export interface ModelPlate {
|
|
|
21
21
|
* Bambu Studio does for the objects on this plate (see plate-filaments.ts). Filaments of other plates never appear.
|
|
22
22
|
*/
|
|
23
23
|
filaments: PlateFilament[];
|
|
24
|
+
/**
|
|
25
|
+
* false when the plate's list may hold filaments it doesn't print: a part's mesh was too large to read its painting,
|
|
26
|
+
* so every declared filament is listed rather than risk leaving out one that prints. A client offers them all.
|
|
27
|
+
*/
|
|
28
|
+
filaments_complete: boolean;
|
|
24
29
|
/** The plate's own preview from the file (Metadata/plate_N.png), when asked for and present. */
|
|
25
30
|
thumbnail_png_base64?: string;
|
|
26
31
|
}
|
|
@@ -38,4 +43,5 @@ export interface ModelPlates {
|
|
|
38
43
|
}
|
|
39
44
|
export declare function listModelPlates(filePath: string, options?: {
|
|
40
45
|
thumbnails?: boolean;
|
|
46
|
+
paintLimits?: PaintLimits;
|
|
41
47
|
}): Promise<ModelPlates>;
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* is one plate. Only bounded metadata is read; nothing is extracted or run.
|
|
9
9
|
*/
|
|
10
10
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
11
|
-
import { plateFilaments } from "./plate-filaments.js";
|
|
11
|
+
import { PAINT_LIMITS, plateFilaments } from "./plate-filaments.js";
|
|
12
12
|
/** For the settings and plate files; the model file can be large and is only scanned. */
|
|
13
13
|
const MAX_METADATA_BYTES = 8 * 1024 * 1024;
|
|
14
14
|
const MAX_THUMBNAIL_BYTES = 2 * 1024 * 1024;
|
|
@@ -72,7 +72,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
72
72
|
const instanceId = Number(/<metadata\s+key="instance_id"\s+value="(\d+)"/.exec(instance[1])?.[1] ?? 0);
|
|
73
73
|
return objectId ? [{ objectId, instanceId }] : [];
|
|
74
74
|
}) });
|
|
75
|
-
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [],
|
|
75
|
+
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [], filaments_complete: true,
|
|
76
76
|
objects: [...match[1].matchAll(/<metadata\s+key="object_id"\s+value="(\d+)"/g)].flatMap(item => objects.get(item[1]) ? [objects.get(item[1])] : []) });
|
|
77
77
|
}
|
|
78
78
|
for (const name of Object.keys(zip.files)) {
|
|
@@ -82,7 +82,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
82
82
|
const number = Number(match[1]);
|
|
83
83
|
if (!valid(number))
|
|
84
84
|
continue;
|
|
85
|
-
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [] };
|
|
85
|
+
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true };
|
|
86
86
|
const layout = layouts.get(number) ?? { number, objectIds: [] };
|
|
87
87
|
layouts.set(number, layout);
|
|
88
88
|
if (match[2] === "gcode")
|
|
@@ -104,7 +104,7 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
104
104
|
result.plates = [...plates.values()].sort((a, b) => a.index - b.index);
|
|
105
105
|
// A standard single-build 3MF has no Bambu plate metadata: it is one plate.
|
|
106
106
|
if (!result.plates.length) {
|
|
107
|
-
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [] });
|
|
107
|
+
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true });
|
|
108
108
|
// Without plates every object is on the one plate.
|
|
109
109
|
layouts.set(1, { number: 1, objectIds: [...settings.matchAll(/<object\b[^>]*\bid="(\d+)"/g)].map(match => match[1]) });
|
|
110
110
|
}
|
|
@@ -119,9 +119,11 @@ export async function listModelPlates(filePath, options = {}) {
|
|
|
119
119
|
// A model file too large to read whole: its resources come first and its build items last (a plain 3MF).
|
|
120
120
|
const modelText = !modelBytes ? "" : modelBytes.length <= 64 * 1024 * 1024 ? modelBytes.toString("utf8")
|
|
121
121
|
: `${head}${modelBytes.subarray(-1024 * 1024).toString("utf8")}`;
|
|
122
|
-
const filaments = await plateFilaments(zip, settings, modelText, result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }));
|
|
123
|
-
for (const plate of result.plates)
|
|
122
|
+
const filaments = await plateFilaments(zip, settings, modelText, result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }), options.paintLimits ?? PAINT_LIMITS);
|
|
123
|
+
for (const plate of result.plates) {
|
|
124
124
|
plate.filaments = filaments.plates.get(plate.index + 1) ?? [];
|
|
125
|
+
plate.filaments_complete = !filaments.incomplete.has(plate.index + 1);
|
|
126
|
+
}
|
|
125
127
|
result.project_filaments = filaments.project;
|
|
126
128
|
if (options.thumbnails)
|
|
127
129
|
for (const plate of result.plates) {
|
|
@@ -56,6 +56,12 @@ export declare function readModelObjects(settings: string): ObjectEntry[];
|
|
|
56
56
|
* two bits, or, when both are set, 3 + the next nibble + 15 for every preceding 0b1111 nibble.
|
|
57
57
|
*/
|
|
58
58
|
export declare function paintedStates(paint: string): number[];
|
|
59
|
+
/** How much mesh text is read for painting: one file, and all of them together. */
|
|
60
|
+
export interface PaintLimits {
|
|
61
|
+
meshBytes: number;
|
|
62
|
+
totalBytes: number;
|
|
63
|
+
}
|
|
64
|
+
export declare const PAINT_LIMITS: PaintLimits;
|
|
59
65
|
export interface PlateLayout {
|
|
60
66
|
/** 1-based plate number. */
|
|
61
67
|
number: number;
|
|
@@ -73,8 +79,9 @@ export interface PlateLayout {
|
|
|
73
79
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
74
80
|
* 3D/3dmodel.model text.
|
|
75
81
|
*/
|
|
76
|
-
export declare function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[]): Promise<{
|
|
82
|
+
export declare function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[], limits?: PaintLimits): Promise<{
|
|
77
83
|
plates: Map<number, PlateFilament[]>;
|
|
84
|
+
incomplete: Set<number>;
|
|
78
85
|
project: PlateFilament[];
|
|
79
86
|
}>;
|
|
80
87
|
export {};
|
|
@@ -80,23 +80,30 @@ export function paintedStates(paint) {
|
|
|
80
80
|
}
|
|
81
81
|
return states;
|
|
82
82
|
}
|
|
83
|
+
export const PAINT_LIMITS = { meshBytes: MAX_MESH_BYTES, totalBytes: MAX_MESH_TOTAL };
|
|
83
84
|
/**
|
|
84
85
|
* Per component file and sub-object id, the painting of that mesh. Only files that contain painting are read in full.
|
|
86
|
+
* `unread` names the mesh files past the read limits: their painting is unknown, never taken as unpainted.
|
|
85
87
|
*/
|
|
86
|
-
async function readPainting(zip, paths) {
|
|
88
|
+
async function readPainting(zip, paths, limits) {
|
|
87
89
|
const result = new Map();
|
|
90
|
+
const unread = new Set();
|
|
88
91
|
let total = 0;
|
|
89
92
|
for (const path of paths) {
|
|
90
93
|
const file = zip.file(path);
|
|
91
94
|
if (!file)
|
|
92
95
|
continue;
|
|
93
|
-
// A mesh past the read budget is
|
|
96
|
+
// A mesh past the read budget is not read: its painting is unknown, and the listing says so.
|
|
94
97
|
const size = file._data?.uncompressedSize;
|
|
95
|
-
if (size !== undefined && (size >
|
|
98
|
+
if (size !== undefined && (size > limits.meshBytes || total + size > limits.totalBytes)) {
|
|
99
|
+
unread.add(path);
|
|
96
100
|
continue;
|
|
101
|
+
}
|
|
97
102
|
const bytes = await file.async("nodebuffer");
|
|
98
|
-
if (bytes.length >
|
|
103
|
+
if (bytes.length > limits.meshBytes || (total += bytes.length) > limits.totalBytes) {
|
|
104
|
+
unread.add(path);
|
|
99
105
|
continue;
|
|
106
|
+
}
|
|
100
107
|
if (!bytes.includes("paint_color=\""))
|
|
101
108
|
continue;
|
|
102
109
|
const text = bytes.toString("utf8");
|
|
@@ -118,7 +125,7 @@ async function readPainting(zip, paths) {
|
|
|
118
125
|
result.set(`${path}#${object[1]}`, paint);
|
|
119
126
|
}
|
|
120
127
|
}
|
|
121
|
-
return result;
|
|
128
|
+
return { painting: result, unread };
|
|
122
129
|
}
|
|
123
130
|
function projectFilaments(config) {
|
|
124
131
|
const list = (key) => Array.isArray(config[key]) ? config[key].map(String) : [];
|
|
@@ -135,7 +142,7 @@ function describe(index, project, name) {
|
|
|
135
142
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
136
143
|
* 3D/3dmodel.model text.
|
|
137
144
|
*/
|
|
138
|
-
export async function plateFilaments(zip, settings, model, plates) {
|
|
145
|
+
export async function plateFilaments(zip, settings, model, plates, limits = PAINT_LIMITS) {
|
|
139
146
|
const text = async (name) => {
|
|
140
147
|
const file = zip.file(name);
|
|
141
148
|
if (!file)
|
|
@@ -216,7 +223,9 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
216
223
|
for (const objectId of plate.objectIds)
|
|
217
224
|
for (const path of components.get(objectId)?.values() ?? [])
|
|
218
225
|
paintPaths.add(path);
|
|
219
|
-
const painting = await readPainting(zip, paintPaths);
|
|
226
|
+
const { painting, unread } = await readPainting(zip, paintPaths, limits);
|
|
227
|
+
// Plates with a part whose painting couldn't be read: they list every declared filament and say they're incomplete.
|
|
228
|
+
const incomplete = new Set();
|
|
220
229
|
const global = (key) => intOf(config[key]) ?? 0;
|
|
221
230
|
const FEATURES = ["wall_filament", "sparse_infill_filament", "solid_infill_filament"];
|
|
222
231
|
const result = new Map();
|
|
@@ -250,6 +259,14 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
250
259
|
const label = part.name || object.name;
|
|
251
260
|
const path = components.get(objectId)?.get(part.id);
|
|
252
261
|
const paint = path ? painting.get(`${path}#${part.id}`) : undefined;
|
|
262
|
+
// Its mesh is past the read limits: any declared filament may be painted on, so all of them are offered
|
|
263
|
+
// (a spare row, never a missing one), and the plate is marked incomplete.
|
|
264
|
+
// A sliced plate needs no painting: Studio's plate_N.json names its filaments, whatever another plate shares.
|
|
265
|
+
if (path && unread.has(path) && part.subtype === "normal_part" && !plate.slicedFilamentIds) {
|
|
266
|
+
incomplete.add(plate.number);
|
|
267
|
+
for (let index = 1; index <= declared; index++)
|
|
268
|
+
add(index, label);
|
|
269
|
+
}
|
|
253
270
|
for (const state of paint?.states ?? [])
|
|
254
271
|
if (part.subtype === "normal_part")
|
|
255
272
|
add(state, label);
|
|
@@ -321,5 +338,5 @@ export async function plateFilaments(zip, settings, model, plates) {
|
|
|
321
338
|
result.set(plate.number, [...used.entries()].sort((a, b) => a[0] - b[0]).map(([index, name]) => describe(index, project, name)));
|
|
322
339
|
}
|
|
323
340
|
// Every filament the project declares, used on a plate or not: slice_stl takes one profile per declared filament.
|
|
324
|
-
return { plates: result, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
341
|
+
return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
325
342
|
}
|
package/dist/index.js
CHANGED
|
@@ -2058,7 +2058,7 @@ class BambuPrinterMCPServer {
|
|
|
2058
2058
|
},
|
|
2059
2059
|
{
|
|
2060
2060
|
name: "list_3mf_plates",
|
|
2061
|
-
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2061
|
+
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. filaments_complete is false when a part's mesh was too large to read its painting: that plate then lists every declared filament, so offer them all rather than miss one that prints. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2062
2062
|
inputSchema: {
|
|
2063
2063
|
type: "object",
|
|
2064
2064
|
properties: {
|
package/dist/printers/bambu.js
CHANGED
|
@@ -10,7 +10,6 @@ import fs from "node:fs/promises";
|
|
|
10
10
|
import { createReadStream, readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import os from "node:os";
|
|
13
|
-
import { Readable } from "node:stream";
|
|
14
13
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
15
14
|
import { inspectPrintFile } from "../safety/print-file.js";
|
|
16
15
|
import { isDualNozzleModel, normalizeModel, validateTemperature } from "../safety/limits.js";
|
|
@@ -20,6 +19,7 @@ import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRem
|
|
|
20
19
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
21
20
|
import { resolveStudioPrintOptions, usedNozzleCount } from "../studio-print-options.js";
|
|
22
21
|
import { Client as FTPClient } from "basic-ftp";
|
|
22
|
+
import { uploadBytes } from "./ftp-upload.js";
|
|
23
23
|
import * as mqtt from "mqtt";
|
|
24
24
|
import { BambuClient, GCodeFileCommand, GCodeLineCommand, PushAllCommand, UpdateFanCommand, UpdateLightCommand, } from "bambu-node";
|
|
25
25
|
/**
|
|
@@ -1088,7 +1088,13 @@ export class BambuImplementation {
|
|
|
1088
1088
|
validatePrinterState(confirmedStatus, requirements);
|
|
1089
1089
|
this.assertPrintPreflight(confirmedStatus, preflight);
|
|
1090
1090
|
assertActive();
|
|
1091
|
-
|
|
1091
|
+
try {
|
|
1092
|
+
await this.ftpUpload(host, token, options.filePath, remoteUploadPath);
|
|
1093
|
+
}
|
|
1094
|
+
catch (error) {
|
|
1095
|
+
// 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.`);
|
|
1097
|
+
}
|
|
1092
1098
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1093
1099
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
1094
1100
|
if (legacyContainer)
|
|
@@ -2266,7 +2272,8 @@ export class BambuImplementation {
|
|
|
2266
2272
|
throw new Error(`Refusing to overwrite existing printer file ${absoluteRemote}. Choose a new filename.`);
|
|
2267
2273
|
}
|
|
2268
2274
|
const fileData = await fs.readFile(localPath);
|
|
2269
|
-
|
|
2275
|
+
// Small writes, so a multi-megabyte job on a slow SD card is not mistaken for a stall.
|
|
2276
|
+
await uploadBytes(client, fileData, absoluteRemote);
|
|
2270
2277
|
}
|
|
2271
2278
|
finally {
|
|
2272
2279
|
client.close();
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { Client as FTPClient } from "basic-ftp";
|
|
2
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
3
|
+
export declare const FTP_UPLOAD_CHUNK_BYTES: number;
|
|
4
|
+
/**
|
|
5
|
+
* Store bytes on the printer in small writes.
|
|
6
|
+
*
|
|
7
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
8
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
9
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
10
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
11
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
12
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
13
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
14
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
15
|
+
* inspected; nothing is re-read from disk.
|
|
16
|
+
*/
|
|
17
|
+
export declare function uploadBytes(client: FTPClient, bytes: Buffer, remotePath: string, chunkBytes?: number): Promise<void>;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
3
|
+
export const FTP_UPLOAD_CHUNK_BYTES = 64 * 1024;
|
|
4
|
+
function* chunks(bytes, size) {
|
|
5
|
+
for (let offset = 0; offset < bytes.length; offset += size)
|
|
6
|
+
yield bytes.subarray(offset, offset + size);
|
|
7
|
+
}
|
|
8
|
+
/**
|
|
9
|
+
* Store bytes on the printer in small writes.
|
|
10
|
+
*
|
|
11
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
12
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
13
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
14
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
15
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
16
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
17
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
18
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
19
|
+
* inspected; nothing is re-read from disk.
|
|
20
|
+
*/
|
|
21
|
+
export async function uploadBytes(client, bytes, remotePath, chunkBytes = FTP_UPLOAD_CHUNK_BYTES) {
|
|
22
|
+
await client.uploadFrom(Readable.from(chunks(bytes, chunkBytes)), remotePath);
|
|
23
|
+
}
|
package/dist/refusal.d.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export declare const REFUSAL_CODES: readonly ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export declare const REFUSAL_CODES: readonly ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"];
|
|
11
12
|
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
13
|
export declare class PrinterRefusal extends Error {
|
|
13
14
|
readonly code: RefusalCode;
|
package/dist/refusal.js
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"];
|
|
11
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"];
|
|
11
12
|
export class PrinterRefusal extends Error {
|
|
12
13
|
constructor(code, message) {
|
|
13
14
|
super(message);
|
package/package.json
CHANGED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* is one plate. Only bounded metadata is read; nothing is extracted or run.
|
|
9
9
|
*/
|
|
10
10
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
11
|
-
import { plateFilaments, type PlateFilament, type PlateLayout } from "./plate-filaments.js";
|
|
11
|
+
import { PAINT_LIMITS, plateFilaments, type PaintLimits, type PlateFilament, type PlateLayout } from "./plate-filaments.js";
|
|
12
12
|
|
|
13
13
|
export interface ModelPlate {
|
|
14
14
|
/** Zero-based, as inspect_print_file's plate_index; slice_stl's slice_plate is index + 1. */
|
|
@@ -29,6 +29,11 @@ export interface ModelPlate {
|
|
|
29
29
|
* Bambu Studio does for the objects on this plate (see plate-filaments.ts). Filaments of other plates never appear.
|
|
30
30
|
*/
|
|
31
31
|
filaments: PlateFilament[];
|
|
32
|
+
/**
|
|
33
|
+
* false when the plate's list may hold filaments it doesn't print: a part's mesh was too large to read its painting,
|
|
34
|
+
* so every declared filament is listed rather than risk leaving out one that prints. A client offers them all.
|
|
35
|
+
*/
|
|
36
|
+
filaments_complete: boolean;
|
|
32
37
|
/** The plate's own preview from the file (Metadata/plate_N.png), when asked for and present. */
|
|
33
38
|
thumbnail_png_base64?: string;
|
|
34
39
|
}
|
|
@@ -55,7 +60,7 @@ const words = (value: string) => value
|
|
|
55
60
|
.replace(/&(?:amp|lt|gt|quot|apos);/g, entity => ({ "&": "&", "<": "<", ">": ">", """: "\"", "'": "'" }[entity]!))
|
|
56
61
|
.replace(/[\u0000-\u001f\u007f]/g, " ").trim().slice(0, 256);
|
|
57
62
|
|
|
58
|
-
export async function listModelPlates(filePath: string, options: { thumbnails?: boolean } = {}): Promise<ModelPlates> {
|
|
63
|
+
export async function listModelPlates(filePath: string, options: { thumbnails?: boolean; paintLimits?: PaintLimits } = {}): Promise<ModelPlates> {
|
|
59
64
|
const { zip } = await readSafe3mfArchive(filePath);
|
|
60
65
|
const text = async (name: string) => {
|
|
61
66
|
const file = zip.file(name);
|
|
@@ -103,7 +108,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
103
108
|
const instanceId = Number(/<metadata\s+key="instance_id"\s+value="(\d+)"/.exec(instance[1])?.[1] ?? 0);
|
|
104
109
|
return objectId ? [{ objectId, instanceId }] : [];
|
|
105
110
|
}) });
|
|
106
|
-
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [],
|
|
111
|
+
plates.set(number, { index: number - 1, name: words(name?.[1] ?? "") || `Plate ${number}`, sliced: false, instances, filaments: [], filaments_complete: true,
|
|
107
112
|
objects: [...match[1].matchAll(/<metadata\s+key="object_id"\s+value="(\d+)"/g)].flatMap(item => objects.get(item[1]) ? [objects.get(item[1])!] : []) });
|
|
108
113
|
}
|
|
109
114
|
for (const name of Object.keys(zip.files)) {
|
|
@@ -111,7 +116,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
111
116
|
if (!match) continue;
|
|
112
117
|
const number = Number(match[1]);
|
|
113
118
|
if (!valid(number)) continue;
|
|
114
|
-
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [] };
|
|
119
|
+
const plate = plates.get(number) ?? { index: number - 1, name: `Plate ${number}`, objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true };
|
|
115
120
|
const layout = layouts.get(number) ?? { number, objectIds: [] };
|
|
116
121
|
layouts.set(number, layout);
|
|
117
122
|
if (match[2] === "gcode") plate.sliced = true;
|
|
@@ -129,7 +134,7 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
129
134
|
result.plates = [...plates.values()].sort((a, b) => a.index - b.index);
|
|
130
135
|
// A standard single-build 3MF has no Bambu plate metadata: it is one plate.
|
|
131
136
|
if (!result.plates.length) {
|
|
132
|
-
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [] });
|
|
137
|
+
result.plates.push({ index: 0, name: "Plate 1", objects: [], instances: [], sliced: false, filaments: [], filaments_complete: true });
|
|
133
138
|
// Without plates every object is on the one plate.
|
|
134
139
|
layouts.set(1, { number: 1, objectIds: [...settings.matchAll(/<object\b[^>]*\bid="(\d+)"/g)].map(match => match[1]) });
|
|
135
140
|
}
|
|
@@ -144,8 +149,11 @@ export async function listModelPlates(filePath: string, options: { thumbnails?:
|
|
|
144
149
|
const modelText = !modelBytes ? "" : modelBytes.length <= 64 * 1024 * 1024 ? modelBytes.toString("utf8")
|
|
145
150
|
: `${head}${modelBytes.subarray(-1024 * 1024).toString("utf8")}`;
|
|
146
151
|
const filaments = await plateFilaments(zip, settings, modelText,
|
|
147
|
-
result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }));
|
|
148
|
-
for (const plate of result.plates)
|
|
152
|
+
result.plates.map(plate => layouts.get(plate.index + 1) ?? { number: plate.index + 1, objectIds: [] }), options.paintLimits ?? PAINT_LIMITS);
|
|
153
|
+
for (const plate of result.plates) {
|
|
154
|
+
plate.filaments = filaments.plates.get(plate.index + 1) ?? [];
|
|
155
|
+
plate.filaments_complete = !filaments.incomplete.has(plate.index + 1);
|
|
156
|
+
}
|
|
149
157
|
result.project_filaments = filaments.project;
|
|
150
158
|
if (options.thumbnails) for (const plate of result.plates) {
|
|
151
159
|
const file = zip.file(`Metadata/plate_${plate.index + 1}.png`);
|
|
@@ -114,20 +114,26 @@ export function paintedStates(paint: string): number[] {
|
|
|
114
114
|
/** What a mesh's painting says: the painted filament states, and whether any facet keeps the volume's own filament. */
|
|
115
115
|
interface MeshPaint { states: Set<number>; ownFilament: boolean }
|
|
116
116
|
|
|
117
|
+
/** How much mesh text is read for painting: one file, and all of them together. */
|
|
118
|
+
export interface PaintLimits { meshBytes: number; totalBytes: number }
|
|
119
|
+
export const PAINT_LIMITS: PaintLimits = { meshBytes: MAX_MESH_BYTES, totalBytes: MAX_MESH_TOTAL };
|
|
120
|
+
|
|
117
121
|
/**
|
|
118
122
|
* Per component file and sub-object id, the painting of that mesh. Only files that contain painting are read in full.
|
|
123
|
+
* `unread` names the mesh files past the read limits: their painting is unknown, never taken as unpainted.
|
|
119
124
|
*/
|
|
120
|
-
async function readPainting(zip: JSZip, paths: Set<string
|
|
125
|
+
async function readPainting(zip: JSZip, paths: Set<string>, limits: PaintLimits): Promise<{ painting: Map<string, MeshPaint>; unread: Set<string> }> {
|
|
121
126
|
const result = new Map<string, MeshPaint>();
|
|
127
|
+
const unread = new Set<string>();
|
|
122
128
|
let total = 0;
|
|
123
129
|
for (const path of paths) {
|
|
124
130
|
const file = zip.file(path);
|
|
125
131
|
if (!file) continue;
|
|
126
|
-
// A mesh past the read budget is
|
|
132
|
+
// A mesh past the read budget is not read: its painting is unknown, and the listing says so.
|
|
127
133
|
const size = (file as unknown as { _data?: { uncompressedSize?: number } })._data?.uncompressedSize;
|
|
128
|
-
if (size !== undefined && (size >
|
|
134
|
+
if (size !== undefined && (size > limits.meshBytes || total + size > limits.totalBytes)) { unread.add(path); continue; }
|
|
129
135
|
const bytes = await file.async("nodebuffer");
|
|
130
|
-
if (bytes.length >
|
|
136
|
+
if (bytes.length > limits.meshBytes || (total += bytes.length) > limits.totalBytes) { unread.add(path); continue; }
|
|
131
137
|
if (!bytes.includes("paint_color=\"")) continue;
|
|
132
138
|
const text = bytes.toString("utf8");
|
|
133
139
|
for (const object of text.matchAll(/<object\b[^>]*\bid="(\d+)"[^>]*>([\s\S]*?)<\/object>/g)) {
|
|
@@ -143,7 +149,7 @@ async function readPainting(zip: JSZip, paths: Set<string>): Promise<Map<string,
|
|
|
143
149
|
result.set(`${path}#${object[1]}`, paint);
|
|
144
150
|
}
|
|
145
151
|
}
|
|
146
|
-
return result;
|
|
152
|
+
return { painting: result, unread };
|
|
147
153
|
}
|
|
148
154
|
|
|
149
155
|
interface ProjectFilaments { colours: string[]; materials: string[]; ids: string[]; config: Record<string, unknown> }
|
|
@@ -176,7 +182,8 @@ export interface PlateLayout {
|
|
|
176
182
|
* The filaments each plate prints with, keyed by plate number. `settings` is model_settings.config, `model` the root
|
|
177
183
|
* 3D/3dmodel.model text.
|
|
178
184
|
*/
|
|
179
|
-
export async function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[]
|
|
185
|
+
export async function plateFilaments(zip: JSZip, settings: string, model: string, plates: PlateLayout[], limits: PaintLimits = PAINT_LIMITS)
|
|
186
|
+
: Promise<{ plates: Map<number, PlateFilament[]>; incomplete: Set<number>; project: PlateFilament[] }> {
|
|
180
187
|
const text = async (name: string) => {
|
|
181
188
|
const file = zip.file(name);
|
|
182
189
|
if (!file) return "";
|
|
@@ -248,7 +255,9 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
248
255
|
const paintPaths = new Set<string>();
|
|
249
256
|
for (const plate of plates) if (!plate.slicedFilamentIds) for (const objectId of plate.objectIds)
|
|
250
257
|
for (const path of components.get(objectId)?.values() ?? []) paintPaths.add(path);
|
|
251
|
-
const painting = await readPainting(zip, paintPaths);
|
|
258
|
+
const { painting, unread } = await readPainting(zip, paintPaths, limits);
|
|
259
|
+
// Plates with a part whose painting couldn't be read: they list every declared filament and say they're incomplete.
|
|
260
|
+
const incomplete = new Set<number>();
|
|
252
261
|
|
|
253
262
|
const global = (key: string) => intOf(config[key]) ?? 0;
|
|
254
263
|
const FEATURES = ["wall_filament", "sparse_infill_filament", "solid_infill_filament"] as const;
|
|
@@ -279,6 +288,13 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
279
288
|
const label = part.name || object.name;
|
|
280
289
|
const path = components.get(objectId)?.get(part.id);
|
|
281
290
|
const paint = path ? painting.get(`${path}#${part.id}`) : undefined;
|
|
291
|
+
// Its mesh is past the read limits: any declared filament may be painted on, so all of them are offered
|
|
292
|
+
// (a spare row, never a missing one), and the plate is marked incomplete.
|
|
293
|
+
// A sliced plate needs no painting: Studio's plate_N.json names its filaments, whatever another plate shares.
|
|
294
|
+
if (path && unread.has(path) && part.subtype === "normal_part" && !plate.slicedFilamentIds) {
|
|
295
|
+
incomplete.add(plate.number);
|
|
296
|
+
for (let index = 1; index <= declared; index++) add(index, label);
|
|
297
|
+
}
|
|
282
298
|
for (const state of paint?.states ?? []) if (part.subtype === "normal_part") add(state, label);
|
|
283
299
|
// A modifier's own filament counts whatever its paint (Model.cpp:3384-3390).
|
|
284
300
|
if (part.subtype !== "normal_part" || !paint || paint.ownFilament) {
|
|
@@ -334,5 +350,5 @@ export async function plateFilaments(zip: JSZip, settings: string, model: string
|
|
|
334
350
|
result.set(plate.number, [...used.entries()].sort((a, b) => a[0] - b[0]).map(([index, name]) => describe(index, project, name)));
|
|
335
351
|
}
|
|
336
352
|
// Every filament the project declares, used on a plate or not: slice_stl takes one profile per declared filament.
|
|
337
|
-
return { plates: result, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
353
|
+
return { plates: result, incomplete, project: Array.from({ length: declared }, (_, i) => describe(i + 1, project)) };
|
|
338
354
|
}
|
package/src/index.ts
CHANGED
|
@@ -2569,7 +2569,7 @@ class BambuPrinterMCPServer {
|
|
|
2569
2569
|
},
|
|
2570
2570
|
{
|
|
2571
2571
|
name: "list_3mf_plates",
|
|
2572
|
-
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2572
|
+
description: "List a Bambu Studio or OrcaSlicer 3MF's plates as its designer laid them out, before slicing: plate_count, and for each plate its index (from 0; slice_stl's slice_plate is index + 1, inspect_print_file's plate_index is index), name, the objects on it, each object copy's identify_id (instances: the ids slice_stl's skip_objects takes) whether the file already holds its G-code (sliced), and filaments: the project filaments that plate prints with and only those (index from 1 = slice_stl's load_filaments/filament_colours position and print_3mf's ams_mapping position + 1; colour, material, filament_id, and the first part using it), from the slice when there is one, otherwise worked out as Bambu Studio does from the plate's parts, painting, support, layer ranges and tool changes. filaments_complete is false when a part's mesh was too large to read its painting: that plate then lists every declared filament, so offer them all rather than miss one that prints. project_filaments lists every filament the project declares, used or not (slice_stl takes one load_filaments profile per declared filament). A plain 3MF without plate metadata is one plate. include_thumbnails adds each plate's own preview from the file (thumbnail_png_base64). Read-only.",
|
|
2573
2573
|
inputSchema: {
|
|
2574
2574
|
type: "object",
|
|
2575
2575
|
properties: {
|
package/src/printers/bambu.ts
CHANGED
|
@@ -10,7 +10,6 @@ import fs from "node:fs/promises";
|
|
|
10
10
|
import { createReadStream, readFileSync, existsSync, mkdirSync, writeFileSync, renameSync, rmSync } from "node:fs";
|
|
11
11
|
import path from "node:path";
|
|
12
12
|
import os from "node:os";
|
|
13
|
-
import { Readable } from "node:stream";
|
|
14
13
|
import { readSafe3mfArchive } from "../safety/archive.js";
|
|
15
14
|
import { inspectPrintFile, type PrintFileInspection } from "../safety/print-file.js";
|
|
16
15
|
import { isDualNozzleModel, normalizeModel, validateTemperature } from "../safety/limits.js";
|
|
@@ -20,6 +19,7 @@ import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRem
|
|
|
20
19
|
import { RTSP_CAMERA_MODELS, TCP_CAMERA_MODELS } from "./camera-models.js";
|
|
21
20
|
import { resolveStudioPrintOptions, usedNozzleCount, type CallerPrintOptions } from "../studio-print-options.js";
|
|
22
21
|
import { Client as FTPClient } from "basic-ftp";
|
|
22
|
+
import { uploadBytes } from "./ftp-upload.js";
|
|
23
23
|
import * as mqtt from "mqtt";
|
|
24
24
|
import {
|
|
25
25
|
BambuClient,
|
|
@@ -1256,7 +1256,12 @@ export class BambuImplementation {
|
|
|
1256
1256
|
else validatePrinterState(confirmedStatus, requirements);
|
|
1257
1257
|
this.assertPrintPreflight(confirmedStatus, preflight);
|
|
1258
1258
|
assertActive();
|
|
1259
|
-
|
|
1259
|
+
try {
|
|
1260
|
+
await this.ftpUpload(host, token, options.filePath, remoteUploadPath);
|
|
1261
|
+
} catch (error) {
|
|
1262
|
+
// Nothing has been sent to the printer but (part of) a file, so the print certainly did not start.
|
|
1263
|
+
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.`);
|
|
1264
|
+
}
|
|
1260
1265
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1261
1266
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
1262
1267
|
if (legacyContainer) requirements = this.validateLoadedGcodeState(dispatchStatus, inspection);
|
|
@@ -2530,7 +2535,8 @@ export class BambuImplementation {
|
|
|
2530
2535
|
throw new Error(`Refusing to overwrite existing printer file ${absoluteRemote}. Choose a new filename.`);
|
|
2531
2536
|
}
|
|
2532
2537
|
const fileData = await fs.readFile(localPath);
|
|
2533
|
-
|
|
2538
|
+
// Small writes, so a multi-megabyte job on a slow SD card is not mistaken for a stall.
|
|
2539
|
+
await uploadBytes(client, fileData, absoluteRemote);
|
|
2534
2540
|
} finally {
|
|
2535
2541
|
client.close();
|
|
2536
2542
|
}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import { Readable } from "node:stream";
|
|
2
|
+
import type { Client as FTPClient } from "basic-ftp";
|
|
3
|
+
|
|
4
|
+
/** Bytes per write on the FTPS data socket; matches fs.createReadStream's default. */
|
|
5
|
+
export const FTP_UPLOAD_CHUNK_BYTES = 64 * 1024;
|
|
6
|
+
|
|
7
|
+
function* chunks(bytes: Buffer, size: number): Generator<Buffer> {
|
|
8
|
+
for (let offset = 0; offset < bytes.length; offset += size) yield bytes.subarray(offset, offset + size);
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Store bytes on the printer in small writes.
|
|
13
|
+
*
|
|
14
|
+
* basic-ftp's TransferWatchdog reports a stall ("Timeout (data socket)") when
|
|
15
|
+
* the data socket's bytesWritten stops changing while data is still queued.
|
|
16
|
+
* Readable.from(buffer) hands the whole file over as one write, which counts in
|
|
17
|
+
* bytesWritten at once; while the printer drains it at SD-card speed (a few
|
|
18
|
+
* hundred KB/s on a P1S) the count never moves, so a multi-megabyte job is
|
|
19
|
+
* declared stalled after the timeout although its bytes are still flowing.
|
|
20
|
+
* Small writes move the count as each one completes, so the watchdog only fires
|
|
21
|
+
* when the printer stops taking data. The bytes are the ones already read and
|
|
22
|
+
* inspected; nothing is re-read from disk.
|
|
23
|
+
*/
|
|
24
|
+
export async function uploadBytes(client: FTPClient, bytes: Buffer, remotePath: string, chunkBytes = FTP_UPLOAD_CHUNK_BYTES): Promise<void> {
|
|
25
|
+
await client.uploadFrom(Readable.from(chunks(bytes, chunkBytes)), remotePath);
|
|
26
|
+
}
|
package/src/refusal.ts
CHANGED
|
@@ -6,8 +6,9 @@
|
|
|
6
6
|
* - printer-command-rejected: the printer refused the print command itself (for Bambu, HMS 0500-0500-0001-0007,
|
|
7
7
|
* MQTT command verification); the file was uploaded and the command sent, but nothing is printing.
|
|
8
8
|
* - printer-not-ready: the printer isn't in a state that can start a print (busy, paused, failed, unknown).
|
|
9
|
+
* - printer-upload-failed: the print file didn't reach the printer, so no print command was sent.
|
|
9
10
|
*/
|
|
10
|
-
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready"] as const;
|
|
11
|
+
export const REFUSAL_CODES = ["printer-command-rejected", "printer-not-ready", "printer-upload-failed"] as const;
|
|
11
12
|
export type RefusalCode = (typeof REFUSAL_CODES)[number];
|
|
12
13
|
|
|
13
14
|
export class PrinterRefusal extends Error {
|