bambu-printer-mcp 1.1.90 → 1.1.91

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.
Files changed (42) hide show
  1. package/README.md +43 -0
  2. package/dist/counterpart/flight-record.d.ts +155 -0
  3. package/dist/counterpart/flight-record.js +831 -0
  4. package/dist/counterpart/flight-tools.d.ts +213 -0
  5. package/dist/counterpart/flight-tools.js +232 -0
  6. package/dist/counterpart/fresh-frame.d.ts +16 -0
  7. package/dist/counterpart/fresh-frame.js +26 -0
  8. package/dist/counterpart/make-3mf.js +1 -4
  9. package/dist/counterpart/physical-evidence.d.ts +70 -0
  10. package/dist/counterpart/physical-evidence.js +103 -0
  11. package/dist/counterpart/print-geometry.d.ts +13 -0
  12. package/dist/counterpart/print-geometry.js +181 -0
  13. package/dist/counterpart/remote.js +2 -0
  14. package/dist/counterpart/schemas.d.ts +32 -0
  15. package/dist/counterpart/schemas.js +2 -0
  16. package/dist/counterpart/visual-evidence.d.ts +38 -0
  17. package/dist/counterpart/visual-evidence.js +155 -0
  18. package/dist/index.js +24 -1
  19. package/dist/printers/bambu.d.ts +9 -2
  20. package/dist/printers/bambu.js +32 -6
  21. package/dist/safety/print-preview.d.ts +2 -0
  22. package/dist/safety/print-preview.js +1 -1
  23. package/dist/slicer/3mf-xml.d.ts +7 -0
  24. package/dist/slicer/3mf-xml.js +61 -0
  25. package/dist/stl/stl-manipulator.js +5 -2
  26. package/dist/tool-annotations.js +2 -0
  27. package/package.json +2 -1
  28. package/src/counterpart/flight-record.ts +984 -0
  29. package/src/counterpart/flight-tools.ts +282 -0
  30. package/src/counterpart/fresh-frame.ts +45 -0
  31. package/src/counterpart/make-3mf.ts +1 -5
  32. package/src/counterpart/physical-evidence.ts +185 -0
  33. package/src/counterpart/print-geometry.ts +192 -0
  34. package/src/counterpart/remote.ts +2 -0
  35. package/src/counterpart/schemas.ts +3 -0
  36. package/src/counterpart/visual-evidence.ts +212 -0
  37. package/src/index.ts +25 -2
  38. package/src/printers/bambu.ts +34 -5
  39. package/src/safety/print-preview.ts +1 -1
  40. package/src/slicer/3mf-xml.ts +52 -0
  41. package/src/stl/stl-manipulator.ts +4 -1
  42. package/src/tool-annotations.ts +2 -0
@@ -0,0 +1,52 @@
1
+ /** XML output boundary for 3MF metadata; no printer calls or geometry/G-code changes. */
2
+ import fs from "node:fs/promises";
3
+ import { randomUUID } from "node:crypto";
4
+ import { SaxesParser } from "saxes";
5
+ import { readSafe3mfArchive } from "../safety/archive.js";
6
+
7
+ /** Encode text for a quoted XML attribute, preserving whitespace through XML parsing. */
8
+ export function xmlAttribute(value: string): string {
9
+ const entities: Record<string,string> = {"&":"&amp;",'"':"&quot;","'":"&apos;","<":"&lt;",">":"&gt;","\t":"&#9;","\n":"&#10;","\r":"&#13;"};
10
+ return value.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, "").replace(/[&"'<>\t\r\n]/g, char=>entities[char]);
11
+ }
12
+ const parses = (xml:string) => {
13
+ try {
14
+ let root:string|undefined;
15
+ const parser=new SaxesParser();
16
+ parser.on("error",error=>{throw error;});
17
+ parser.on("opentag",node=>{root ??= node.name;});
18
+ parser.write(xml).close();
19
+ return root === "config";
20
+ } catch { return false; }
21
+ };
22
+
23
+ /** Studio 02.08.02.61 bbs_3mf.cpp writes object opt_serialize values without XML escaping.
24
+ * Only repair its single-line key/value metadata form. Unexpected malformed XML fails closed. */
25
+ export async function escapedModelSettings(xml:string):Promise<string> {
26
+ if (Buffer.byteLength(xml)>16*1024*1024) throw Error("3MF model settings exceed the 16 MiB XML limit.");
27
+ if (await parses(xml)) return xml;
28
+ const lines=xml.split(/(?<=\n)/);
29
+ for(let i=0;i<lines.length;i++) {
30
+ const match=/^([ \t]*<metadata\s+key="[\w.:-]+"\s+value=")(.*)("\s*\/>[ \t]*\r?\n?)$/.exec(lines[i]);
31
+ if (!match || await parses('<config>'+lines[i]+'</config>')) continue;
32
+ lines[i]=match[1]+xmlAttribute(match[2])+match[3];
33
+ }
34
+ const repaired=lines.join('');
35
+ if (!await parses(repaired)) throw Error("Slicer produced malformed Metadata/model_settings.config; no safe attribute repair is available.");
36
+ return repaired;
37
+ }
38
+
39
+ /** Normalize only a newly produced/restored slice, before caching or handing it to the client. */
40
+ export async function normalize3mfMetadata(filePath:string):Promise<void> {
41
+ const {zip}=await readSafe3mfArchive(filePath);
42
+ const entry=zip.file('Metadata/model_settings.config');
43
+ if(!entry) return;
44
+ const original=await entry.async('string'), repaired=await escapedModelSettings(original);
45
+ if (repaired===original) return;
46
+ zip.file(entry.name,repaired);
47
+ const staged=filePath+'.'+randomUUID()+'.xml-tmp';
48
+ try {
49
+ await fs.writeFile(staged,await zip.generateAsync({type:'nodebuffer',compression:'DEFLATE'}),{flag:'wx',mode:0o600});
50
+ await fs.rename(staged,filePath);
51
+ } finally { await fs.rm(staged,{force:true}).catch(()=>{}); }
52
+ }
@@ -1,3 +1,4 @@
1
+ import { normalize3mfMetadata } from "../slicer/3mf-xml.js";
1
2
  import { customGcodesWithPauses, layerTops, machinePauseGcode, pausedLayers, readPlateGcode, readProjectCustomGcodes } from "../slicer/layer-pauses.js";
2
3
  import * as THREE from 'three';
3
4
  import { STLLoader } from 'three/examples/jsm/loaders/STLLoader.js';
@@ -2134,12 +2135,14 @@ export class STLManipulator extends EventEmitter {
2134
2135
  if (typeof slicerResult?.return_code === "number" && slicerResult.return_code !== 0) {
2135
2136
  throw new SlicerRunError(`Slicer failed: the slicer exited with code 0, but its result.json reports return_code ${slicerResult.return_code}.`, slicerResult);
2136
2137
  }
2137
- if (cacheKey && !restored && fs.existsSync(outputFilePath)) await keepSlice(cacheKey, cacheRun!);
2138
2138
 
2139
2139
  if (!fs.existsSync(outputFilePath)) {
2140
2140
  throw new SlicerRunError(`Slicer finished but output file not found: ${outputFilePath}`, slicerResult);
2141
2141
  }
2142
2142
 
2143
+ if (/\.3mf$/i.test(outputFilePath)) await normalize3mfMetadata(outputFilePath);
2144
+ if (cacheKey && !restored) await keepSlice(cacheKey, cacheRun!);
2145
+
2143
2146
  if (progressCallback) progressCallback(100, "Slicing completed successfully");
2144
2147
 
2145
2148
  this.emit('operationComplete', {
@@ -46,6 +46,8 @@ export const TOOL_ANNOTATIONS: Record<string, ToolAnnotations> = {
46
46
  resolve_3mf_ams_slots: READ_OUTSIDE, // reads the live AMS inventory
47
47
  list_printer_files: READ_OUTSIDE,
48
48
  counterpart_print_progress: READ_OUTSIDE,
49
+ counterpart_print_record: READ_LOCAL,
50
+ counterpart_print_assess: hints(false,false,true,false),
49
51
  counterpart_discover_printers: READ_OUTSIDE, // listens for the printers' own SSDP announcements
50
52
  counterpart_propose_filaments: READ_OUTSIDE, // reads the live AMS inventory
51
53
  // connect: true starts the bridge agent, which writes its configuration and device identity and can replace certificates.