bambu-printer-mcp 1.1.93 → 1.1.95
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 +6 -3
- package/dist/3mf_parser.js +3 -2
- package/dist/cad/contracts.d.ts +10 -0
- package/dist/cad/contracts.js +41 -1
- package/dist/cad-engine.d.ts +5 -0
- package/dist/cad-engine.js +74 -3
- package/dist/counterpart/diagnostics.d.ts +163 -0
- package/dist/counterpart/diagnostics.js +816 -0
- package/dist/counterpart/flight-tools.d.ts +2 -2
- package/dist/counterpart/info.js +1 -0
- package/dist/counterpart/make-3mf.d.ts +10 -0
- package/dist/counterpart/make-3mf.js +472 -65
- package/dist/counterpart/model-plates.d.ts +8 -1
- package/dist/counterpart/model-plates.js +9 -4
- package/dist/counterpart/plate-filaments.d.ts +19 -0
- package/dist/counterpart/plate-filaments.js +72 -10
- package/dist/counterpart/remote.js +1 -0
- package/dist/counterpart/schemas.d.ts +8 -2
- package/dist/counterpart/schemas.js +1 -0
- package/dist/index.js +100 -2
- package/dist/tool-annotations.js +1 -0
- package/package.json +2 -2
- package/src/3mf_parser.ts +3 -2
- package/src/cad/contracts.ts +46 -1
- package/src/cad/examples/desk_clamp_hook.py +32 -0
- package/src/cad/examples/desk_edge_cable_holder.py +24 -0
- package/src/cad/examples/phone_stand.py +26 -0
- package/src/cad/geometry.py +52 -2
- package/src/cad/project3mf.py +426 -0
- package/src/cad/purpose.py +492 -0
- package/src/cad/worker.py +17 -2
- package/src/cad-engine.ts +73 -3
- package/src/counterpart/diagnostics.ts +775 -0
- package/src/counterpart/info.ts +1 -0
- package/src/counterpart/make-3mf.ts +446 -61
- package/src/counterpart/model-plates.ts +17 -5
- package/src/counterpart/plate-filaments.ts +75 -7
- package/src/counterpart/remote.ts +1 -0
- package/src/counterpart/schemas.ts +3 -0
- package/src/index.ts +83 -2
- package/src/tool-annotations.ts +1 -0
package/src/cad-engine.ts
CHANGED
|
@@ -6,6 +6,8 @@ import { createHash, randomUUID } from "node:crypto";
|
|
|
6
6
|
import { createRequire } from "node:module";
|
|
7
7
|
import { performance } from "node:perf_hooks";
|
|
8
8
|
import { CadRefusal, cadFailure } from "./cad/refusal.js";
|
|
9
|
+
import { writeCadProject3mf } from "./counterpart/make-3mf.js";
|
|
10
|
+
import { listModelPlates } from "./counterpart/model-plates.js";
|
|
9
11
|
import { withCadLock } from "./cad/serial.js";
|
|
10
12
|
import {
|
|
11
13
|
measureEnvironment,
|
|
@@ -490,6 +492,8 @@ export class CadEngine {
|
|
|
490
492
|
"worker.py",
|
|
491
493
|
"geometry.py",
|
|
492
494
|
"scan_touchup.py",
|
|
495
|
+
"project3mf.py",
|
|
496
|
+
"purpose.py",
|
|
493
497
|
"process.ts",
|
|
494
498
|
"storage.ts",
|
|
495
499
|
"serial.ts",
|
|
@@ -576,6 +580,7 @@ export class CadEngine {
|
|
|
576
580
|
"inputs",
|
|
577
581
|
"mode",
|
|
578
582
|
"final",
|
|
583
|
+
"role",
|
|
579
584
|
]);
|
|
580
585
|
const root = await this.allowedDirectory(args.output_dir);
|
|
581
586
|
const name = plainName(args.name);
|
|
@@ -583,6 +588,11 @@ export class CadEngine {
|
|
|
583
588
|
deadline = started + timeout;
|
|
584
589
|
if (args.final !== undefined && typeof args.final !== "boolean")
|
|
585
590
|
throw new Error("final must be a boolean.");
|
|
591
|
+
// What the run is for, on every receipt: the design itself, or a check part or reference export that must
|
|
592
|
+
// never become the person's model (scan-to-make #790 keeps the last valid run as a draft). Absent is design.
|
|
593
|
+
if (args.role !== undefined && args.role !== "design" && args.role !== "check")
|
|
594
|
+
throw new Error('role must be "design" or "check".');
|
|
595
|
+
const role = args.role === "check" ? "check" : "design";
|
|
586
596
|
if (root.split(path.sep).includes(".cad-inputs"))
|
|
587
597
|
throw new Error(
|
|
588
598
|
"output_dir cannot be inside the reserved CAD input cache.",
|
|
@@ -709,9 +719,12 @@ export class CadEngine {
|
|
|
709
719
|
JSON.stringify({ ...(previous as object), ...overrides }),
|
|
710
720
|
{ mode: 0o600 },
|
|
711
721
|
);
|
|
722
|
+
// Not final until the engine has found it ready: an interrupted run never reads as selected.
|
|
712
723
|
await atomicJson(resultManifest, {
|
|
713
724
|
status: "pending",
|
|
714
|
-
final:
|
|
725
|
+
final: false,
|
|
726
|
+
...(args.final === true ? { final_requested: true } : {}),
|
|
727
|
+
role,
|
|
715
728
|
lineage_id: lineage,
|
|
716
729
|
});
|
|
717
730
|
try {
|
|
@@ -732,6 +745,7 @@ export class CadEngine {
|
|
|
732
745
|
script,
|
|
733
746
|
parameters,
|
|
734
747
|
mode,
|
|
748
|
+
role,
|
|
735
749
|
inputs: snapshots,
|
|
736
750
|
};
|
|
737
751
|
await fs.writeFile(request, JSON.stringify(base), { mode: 0o600 });
|
|
@@ -803,14 +817,43 @@ export class CadEngine {
|
|
|
803
817
|
).stdout,
|
|
804
818
|
);
|
|
805
819
|
const printed = built.stdout.trim();
|
|
820
|
+
const project = await this.project3mf(job, name, snapshots);
|
|
821
|
+
// final is the designer's selection, and it no longer stands on its own word (scan-to-make #608): a solid
|
|
822
|
+
// design is selected only when the engine found it ready, its purpose evaluated on the design as used.
|
|
823
|
+
const blocked: string[] = Array.isArray(checked.purpose?.blocked) ? checked.purpose.blocked : [];
|
|
824
|
+
const refused: string[] | undefined =
|
|
825
|
+
args.final === true && role === "check"
|
|
826
|
+
? ['A check run is never the design: run the design itself with role "design" to mark it final.']
|
|
827
|
+
: args.final === true && checked.ready === false
|
|
828
|
+
? (Array.isArray(checked.purpose?.blocked) && checked.purpose.blocked.length ? checked.purpose.blocked : ["the engine did not find this design ready"])
|
|
829
|
+
: undefined;
|
|
806
830
|
const result = {
|
|
807
831
|
...checked,
|
|
832
|
+
...project,
|
|
808
833
|
// Beside the image paths, where the next step is decided.
|
|
809
|
-
next:
|
|
834
|
+
next: refused
|
|
835
|
+
? `Not selected as final, so it is not yet the model. To make it final: ${refused.slice(0, 3).join(" ")}${refused.length > 3 ? ` (and ${refused.length - 3} more in final_refused)` : ""} Then run again with final: true. Read renders.perspective and renders.use first.`
|
|
836
|
+
: "Read renders.perspective before the next cad_run or any other change: say what it shows is wrong against what you are making (the bought product you named, or the object in the photos), then fix that." +
|
|
837
|
+
(checked.purpose && checked.ready === false && Array.isArray(checked.purpose.blocked)
|
|
838
|
+
? ` Not ready yet, so final: true would be refused. To make it ready: ${checked.purpose.blocked.slice(0, 3).join(" ")}`
|
|
839
|
+
: ""),
|
|
810
840
|
// The script's own print() output: its words, not a measurement by this engine.
|
|
811
841
|
...(printed ? { printed: printed.length > 4000 ? printed.slice(0, 4000) + "\n[cut at 4000 characters; build.log has the rest]" : printed } : {}),
|
|
812
842
|
status: "completed",
|
|
813
|
-
final: args.final === true,
|
|
843
|
+
final: args.final === true && !refused,
|
|
844
|
+
...(refused ? { final_requested: true, final_refused: refused } : {}),
|
|
845
|
+
role,
|
|
846
|
+
// Why a valid run is not the final model, in plain sentences, for a client that keeps it as a draft.
|
|
847
|
+
...(checked.valid === true && !(args.final === true && !refused)
|
|
848
|
+
? {
|
|
849
|
+
draft_reasons:
|
|
850
|
+
role === "check"
|
|
851
|
+
? ["This is a check part or reference export, not the design."]
|
|
852
|
+
: args.final === true
|
|
853
|
+
? ["It isn't ready, so the engine didn't mark it final.", ...refused!]
|
|
854
|
+
: ["The designer didn't mark this run final.", ...(checked.ready === false ? blocked : [])],
|
|
855
|
+
}
|
|
856
|
+
: {}),
|
|
814
857
|
completed_at: new Date().toISOString(),
|
|
815
858
|
lineage_id: lineage,
|
|
816
859
|
result_manifest: resultManifest,
|
|
@@ -839,6 +882,7 @@ export class CadEngine {
|
|
|
839
882
|
status: "failed",
|
|
840
883
|
final: false,
|
|
841
884
|
final_requested: args.final === true,
|
|
885
|
+
role,
|
|
842
886
|
lineage_id: lineage,
|
|
843
887
|
message: e instanceof Error ? e.message : String(e),
|
|
844
888
|
script,
|
|
@@ -854,6 +898,32 @@ export class CadEngine {
|
|
|
854
898
|
deadline,
|
|
855
899
|
);
|
|
856
900
|
}
|
|
901
|
+
/**
|
|
902
|
+
* When build() returned project_3mf(), write <name>.3mf from the sandbox's manifest and part STLs (this trusted
|
|
903
|
+
* process writes it; the sandbox only meshed the parts) and read it back as list_3mf_plates does.
|
|
904
|
+
*/
|
|
905
|
+
private async project3mf(job: string, name: string, inputs: Record<string, string>): Promise<Record<string, unknown>> {
|
|
906
|
+
const manifestPath = path.join(job, `${name}.project.json`);
|
|
907
|
+
const st = await fs.lstat(manifestPath).catch(() => undefined);
|
|
908
|
+
if (!st) return {};
|
|
909
|
+
if (!st.isFile() || st.size > 1024 * 1024) throw new Error("The design's 3MF project manifest is unsafe or too large.");
|
|
910
|
+
const partsDir = path.join(job, `${name}.parts`);
|
|
911
|
+
const dir = await fs.lstat(partsDir).catch(() => undefined);
|
|
912
|
+
if (!dir?.isDirectory()) throw new Error("The design's 3MF project parts are missing.");
|
|
913
|
+
const out = path.join(job, `${name}.3mf`);
|
|
914
|
+
const written = await writeCadProject3mf(JSON.parse(await fs.readFile(manifestPath, "utf8")), partsDir, inputs, out);
|
|
915
|
+
const listed = await listModelPlates(out);
|
|
916
|
+
return {
|
|
917
|
+
three_mf: out,
|
|
918
|
+
three_mf_project: {
|
|
919
|
+
base: written.base,
|
|
920
|
+
changes: written.changed,
|
|
921
|
+
plate_count: listed.plate_count,
|
|
922
|
+
plates: listed.plates.map(plate => ({ index: plate.index, name: plate.name, build_items: plate.build_items, parts: plate.parts, filaments: plate.filaments })),
|
|
923
|
+
project_filaments: listed.project_filaments,
|
|
924
|
+
},
|
|
925
|
+
};
|
|
926
|
+
}
|
|
857
927
|
async checkFit(
|
|
858
928
|
args: CadArguments,
|
|
859
929
|
signal?: AbortSignal,
|