bambu-printer-mcp 1.1.72 → 1.1.74
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/ams-mapping.d.ts +6 -0
- package/dist/ams-mapping.js +9 -0
- package/dist/counterpart/model-plates.d.ts +12 -0
- package/dist/counterpart/model-plates.js +29 -5
- package/dist/counterpart/plate-filaments.d.ts +80 -0
- package/dist/counterpart/plate-filaments.js +325 -0
- package/dist/index.js +5 -4
- package/dist/printers/bambu.js +14 -5
- 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/ams-mapping.ts +10 -0
- package/src/counterpart/model-plates.ts +40 -5
- package/src/counterpart/plate-filaments.ts +338 -0
- package/src/index.ts +5 -4
- package/src/printers/bambu.ts +13 -5
- package/src/printers/ftp-upload.ts +26 -0
- package/src/refusal.ts +2 -1
package/src/printers/bambu.ts
CHANGED
|
@@ -10,16 +10,16 @@ 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";
|
|
17
|
-
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, describeAmsTrayRange } from "../ams-mapping.js";
|
|
16
|
+
import { bridgeAmsMapping2Entry, bridgeAmsMappingValue, externalTrayForNozzle, describeAmsTrayRange, studioAmsMapping } from "../ams-mapping.js";
|
|
18
17
|
import { describeHmsKey, hiddenHmsKeys, hiddenHmsNotices, reportedHmsKey, unchippedNozzles, validatePrinterState, manualHeatingRequirements, type PrinterStateRequirements } from "../safety/printer-state.js";
|
|
19
18
|
import { withPrinterOperation, withPrintSnapshot, uniquePrintName, normalizedRemotePath, cancelPendingPrinterOperations } from "../safety/artifact.js";
|
|
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,
|
|
@@ -1175,7 +1175,9 @@ export class BambuImplementation {
|
|
|
1175
1175
|
let baseMapping: number[];
|
|
1176
1176
|
if (options.amsMapping && options.amsMapping.length > 0) {
|
|
1177
1177
|
for (const v of options.amsMapping) validateTrayValue(v, "ams_mapping");
|
|
1178
|
-
|
|
1178
|
+
// Bambu Studio sends a tray only for the filaments the plate prints and -1 for every other project filament
|
|
1179
|
+
// (SelectMachineDialog::get_ams_mapping_result, SelectMachine.cpp:1463-1500): so does this route.
|
|
1180
|
+
baseMapping = studioAmsMapping(options.amsMapping, inspection.usedFilamentPositions);
|
|
1179
1181
|
} else if (options.amsSlots && options.amsSlots.length > 0) {
|
|
1180
1182
|
for (const v of options.amsSlots) validateTrayValue(v, "amsSlots");
|
|
1181
1183
|
const positions = projectMetadata.usedFilamentPositions;
|
|
@@ -1254,7 +1256,12 @@ export class BambuImplementation {
|
|
|
1254
1256
|
else validatePrinterState(confirmedStatus, requirements);
|
|
1255
1257
|
this.assertPrintPreflight(confirmedStatus, preflight);
|
|
1256
1258
|
assertActive();
|
|
1257
|
-
|
|
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
|
+
}
|
|
1258
1265
|
// Uploads can be long. Recheck current state before the command is dispatched.
|
|
1259
1266
|
const dispatchStatus = await this.getSafetyStatus(host, serial, token);
|
|
1260
1267
|
if (legacyContainer) requirements = this.validateLoadedGcodeState(dispatchStatus, inspection);
|
|
@@ -2528,7 +2535,8 @@ export class BambuImplementation {
|
|
|
2528
2535
|
throw new Error(`Refusing to overwrite existing printer file ${absoluteRemote}. Choose a new filename.`);
|
|
2529
2536
|
}
|
|
2530
2537
|
const fileData = await fs.readFile(localPath);
|
|
2531
|
-
|
|
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);
|
|
2532
2540
|
} finally {
|
|
2533
2541
|
client.close();
|
|
2534
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 {
|