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,213 @@
1
+ import type { ReadRecordOptions } from "./flight-record.js";
2
+ export declare const FLIGHT_RECORD_PROPERTIES: {
3
+ readonly view: {
4
+ readonly type: "string";
5
+ readonly enum: readonly ["record", "evidence"];
6
+ readonly description: "Full journal (default), or compact vision evidence with omission counts. Image format defaults to evidence view to avoid sending a large journal to the worker.";
7
+ };
8
+ readonly frame_format: {
9
+ readonly type: "string";
10
+ readonly enum: readonly ["base64", "images"];
11
+ readonly description: "Return requested JPEGs once as structured base64 (default) or normal MCP image content for a vision worker.";
12
+ };
13
+ readonly frame_ids: {
14
+ readonly type: "array";
15
+ readonly maxItems: 4;
16
+ readonly items: {
17
+ readonly type: "string";
18
+ };
19
+ readonly description: "At most four saved frame IDs to retrieve; defaults to the pending assessment and baseline candidates, or recent evidence.";
20
+ };
21
+ readonly list_jobs: {
22
+ readonly type: "boolean";
23
+ readonly description: "Include the retained job IDs, dispatch times, artifact hashes and outcomes for this printer, so an older job can be selected.";
24
+ };
25
+ readonly job_id: {
26
+ readonly type: "string";
27
+ readonly description: "Saved record UUID; omit for the latest dispatched job on this printer.";
28
+ };
29
+ readonly include_frames: {
30
+ readonly type: "boolean";
31
+ readonly description: "Include up to four saved JPEGs (512 KiB each). Reads disk only.";
32
+ };
33
+ readonly measurements: {
34
+ readonly type: "array";
35
+ readonly maxItems: 4;
36
+ readonly description: "Optional calibrated client height measurements for saved frames; no image interpretation or printer control is performed.";
37
+ readonly items: {
38
+ readonly type: "object";
39
+ readonly properties: {
40
+ readonly frameId: {
41
+ readonly type: "string";
42
+ readonly description: "The saved frame UUID returned in this job record.";
43
+ };
44
+ readonly visible: {
45
+ readonly type: "boolean";
46
+ readonly description: "The expected printed region and its maximum height are visible, unoccluded and in view.";
47
+ };
48
+ readonly observedHeightMm: {
49
+ readonly type: "number";
50
+ readonly minimum: 0;
51
+ readonly description: "Client-calibrated maximum deposited Z height of this plate in the visible expected object region; use the same region across frames.";
52
+ };
53
+ readonly uncertaintyMm: {
54
+ readonly type: "number";
55
+ readonly minimum: 0;
56
+ readonly description: "Estimated plus/minus error of the calibrated physical height measurement, in millimetres.";
57
+ };
58
+ readonly method: {
59
+ readonly type: "string";
60
+ readonly enum: readonly ["calibrated-height"];
61
+ readonly description: "An explicit calibrated height measurement from the client, never a pixel-change guess.";
62
+ };
63
+ };
64
+ readonly required: readonly ["frameId", "visible", "observedHeightMm", "uncertaintyMm", "method"];
65
+ readonly additionalProperties: false;
66
+ };
67
+ };
68
+ };
69
+ export declare const FLIGHT_RECORD_DESCRIPTION = "Counterpart contract (counterpart/1): read a bounded persistent per-job flight record from disk, including dispatched SHA-256, selected mapping, timestamped allowlisted printer-report changes, expected sliced layer geometry and sampled camera evidence. Survives restart. No printer connection, polling or controls. Firmware FINISH is separate from physical unknown/consistent/suspect_no_growth/suspect_no_extrusion. Inspect pending visual assessment requests with the client worker; clear empty-footprint observations can flag no extrusion without an empty-bed reference. Missing history is unavailable, never fetched from the printer.";
70
+ export declare const FLIGHT_RECORD_OUTPUT_SCHEMA: {
71
+ type: "object";
72
+ properties: {
73
+ contract: {
74
+ type: string;
75
+ const: string;
76
+ };
77
+ status: {
78
+ type: string;
79
+ enum: string[];
80
+ };
81
+ record: {
82
+ type: string;
83
+ additionalProperties: boolean;
84
+ };
85
+ jobs: {
86
+ type: string;
87
+ maxItems: number;
88
+ items: {
89
+ type: string;
90
+ properties: {
91
+ id: {
92
+ type: string;
93
+ };
94
+ dispatchedAt: {
95
+ type: string;
96
+ };
97
+ sha256: {
98
+ type: string;
99
+ };
100
+ outcome: {
101
+ type: string;
102
+ };
103
+ };
104
+ required: string[];
105
+ };
106
+ };
107
+ physical: {
108
+ type: string;
109
+ properties: {
110
+ status: {
111
+ type: string;
112
+ enum: string[];
113
+ };
114
+ observedLayer: {
115
+ type: string;
116
+ minimum: number;
117
+ };
118
+ assessment: {
119
+ type: string;
120
+ additionalProperties: boolean;
121
+ };
122
+ evidence: {
123
+ type: string;
124
+ items: {
125
+ type: string;
126
+ };
127
+ };
128
+ limitations: {
129
+ type: string;
130
+ items: {
131
+ type: string;
132
+ };
133
+ };
134
+ };
135
+ required: string[];
136
+ };
137
+ };
138
+ required: string[];
139
+ };
140
+ export declare function flightReadOptions(args?: Record<string, unknown>): ReadRecordOptions;
141
+ /** Image bytes appear once: normal MCP images for vision, or structuredContent base64. */
142
+ export declare function flightRecordResult<T extends {
143
+ contract: string;
144
+ record?: {
145
+ frames: Array<{
146
+ base64?: string;
147
+ imageContentIndex?: number;
148
+ }>;
149
+ };
150
+ }>(view: T, asImages?: boolean): {
151
+ content: ({
152
+ type: "text";
153
+ text: string;
154
+ } | {
155
+ type: "image";
156
+ data: string;
157
+ mimeType: string;
158
+ })[];
159
+ structuredContent: T;
160
+ };
161
+ export declare const PRINT_EVIDENCE_GUIDANCE = " When monitoring a print, firmware layer counters do not verify deposition. Follow physical.assessment requests at the first layer and later checkpoints: fetch counterpart_print_record with frame_format images, inspect the expected footprint with the client vision worker, then submit counterpart_print_assess. A clear empty footprint after attempted printing is suspect_no_extrusion; no baseline is required for that direct observation. Dark/occluded/unlocatable views are unknown. Never announce a first layer is down from counters alone. Do not stop or pause automatically.";
162
+ export declare const FLIGHT_ASSESS_DESCRIPTION = "Counterpart contract (counterpart/1): save a client vision worker observation against an exact saved job/artifact/frame hash. Local evidence only; no camera request, model call or printer controls. Clear visible empty expected footprint after attempted deposition reports suspect_no_extrusion, even without a usable baseline. Dark/occluded/unknown stays unknown; visible material does not verify success. Persists across restart; repeat observations are idempotent.";
163
+ export declare const FLIGHT_ASSESS_PROPERTIES: {
164
+ job_id: {
165
+ type: string;
166
+ description: string;
167
+ };
168
+ artifact_sha256: {
169
+ type: string;
170
+ description: string;
171
+ };
172
+ frame_id: {
173
+ type: string;
174
+ description: string;
175
+ };
176
+ image_sha256: {
177
+ type: string;
178
+ description: string;
179
+ };
180
+ visibility: {
181
+ type: string;
182
+ enum: ("dark" | "clear" | "unknown" | "occluded" | "out_of_view")[];
183
+ description: string;
184
+ };
185
+ footprint_visible: {
186
+ type: string;
187
+ description: string;
188
+ };
189
+ deposition: {
190
+ type: string;
191
+ enum: string[];
192
+ description: string;
193
+ };
194
+ attempted: {
195
+ type: string;
196
+ description: string;
197
+ };
198
+ reference_frame_id: {
199
+ type: string;
200
+ description: string;
201
+ };
202
+ reference_visibility: {
203
+ type: string;
204
+ enum: ("dark" | "clear" | "unknown" | "occluded" | "out_of_view")[];
205
+ description: string;
206
+ };
207
+ reference_empty: {
208
+ type: string;
209
+ description: string;
210
+ };
211
+ };
212
+ export declare const FLIGHT_ASSESS_REQUIRED: string[];
213
+ export declare function visualSubmission(args?: Record<string, unknown>): import("./visual-evidence.js").VisualSubmission;
@@ -0,0 +1,232 @@
1
+ import { PHYSICAL_EVIDENCE_SCHEMA } from "./physical-evidence.js";
2
+ import { validateVisualSubmission, VISIBILITIES } from "./visual-evidence.js";
3
+ export const FLIGHT_RECORD_PROPERTIES = {
4
+ view: {
5
+ type: "string",
6
+ enum: ["record", "evidence"],
7
+ description: "Full journal (default), or compact vision evidence with omission counts. Image format defaults to evidence view to avoid sending a large journal to the worker.",
8
+ },
9
+ frame_format: {
10
+ type: "string",
11
+ enum: ["base64", "images"],
12
+ description: "Return requested JPEGs once as structured base64 (default) or normal MCP image content for a vision worker.",
13
+ },
14
+ frame_ids: {
15
+ type: "array",
16
+ maxItems: 4,
17
+ items: { type: "string" },
18
+ description: "At most four saved frame IDs to retrieve; defaults to the pending assessment and baseline candidates, or recent evidence.",
19
+ },
20
+ list_jobs: {
21
+ type: "boolean",
22
+ description: "Include the retained job IDs, dispatch times, artifact hashes and outcomes for this printer, so an older job can be selected.",
23
+ },
24
+ job_id: {
25
+ type: "string",
26
+ description: "Saved record UUID; omit for the latest dispatched job on this printer.",
27
+ },
28
+ include_frames: {
29
+ type: "boolean",
30
+ description: "Include up to four saved JPEGs (512 KiB each). Reads disk only.",
31
+ },
32
+ measurements: {
33
+ type: "array",
34
+ maxItems: 4,
35
+ description: "Optional calibrated client height measurements for saved frames; no image interpretation or printer control is performed.",
36
+ items: {
37
+ type: "object",
38
+ properties: {
39
+ frameId: {
40
+ type: "string",
41
+ description: "The saved frame UUID returned in this job record.",
42
+ },
43
+ visible: {
44
+ type: "boolean",
45
+ description: "The expected printed region and its maximum height are visible, unoccluded and in view.",
46
+ },
47
+ observedHeightMm: {
48
+ type: "number",
49
+ minimum: 0,
50
+ description: "Client-calibrated maximum deposited Z height of this plate in the visible expected object region; use the same region across frames.",
51
+ },
52
+ uncertaintyMm: {
53
+ type: "number",
54
+ minimum: 0,
55
+ description: "Estimated plus/minus error of the calibrated physical height measurement, in millimetres.",
56
+ },
57
+ method: {
58
+ type: "string",
59
+ enum: ["calibrated-height"],
60
+ description: "An explicit calibrated height measurement from the client, never a pixel-change guess.",
61
+ },
62
+ },
63
+ required: [
64
+ "frameId",
65
+ "visible",
66
+ "observedHeightMm",
67
+ "uncertaintyMm",
68
+ "method",
69
+ ],
70
+ additionalProperties: false,
71
+ },
72
+ },
73
+ };
74
+ export const FLIGHT_RECORD_DESCRIPTION = "Counterpart contract (counterpart/1): read a bounded persistent per-job flight record from disk, including dispatched SHA-256, selected mapping, timestamped allowlisted printer-report changes, expected sliced layer geometry and sampled camera evidence. Survives restart. No printer connection, polling or controls. Firmware FINISH is separate from physical unknown/consistent/suspect_no_growth/suspect_no_extrusion. Inspect pending visual assessment requests with the client worker; clear empty-footprint observations can flag no extrusion without an empty-bed reference. Missing history is unavailable, never fetched from the printer.";
75
+ export const FLIGHT_RECORD_OUTPUT_SCHEMA = {
76
+ type: "object",
77
+ properties: {
78
+ contract: { type: "string", const: "counterpart/1" },
79
+ status: { type: "string", enum: ["recorded", "unavailable"] },
80
+ record: { type: "object", additionalProperties: true },
81
+ jobs: {
82
+ type: "array",
83
+ maxItems: 10,
84
+ items: {
85
+ type: "object",
86
+ properties: {
87
+ id: { type: "string" },
88
+ dispatchedAt: { type: "string" },
89
+ sha256: { type: "string" },
90
+ outcome: { type: "string" },
91
+ },
92
+ required: ["id", "dispatchedAt", "sha256", "outcome"],
93
+ },
94
+ },
95
+ physical: PHYSICAL_EVIDENCE_SCHEMA,
96
+ },
97
+ required: ["contract", "status", "physical"],
98
+ };
99
+ export function flightReadOptions(args = {}) {
100
+ if (args.view !== undefined &&
101
+ !["record", "evidence"].includes(args.view))
102
+ throw Error("view must be record or evidence.");
103
+ if (args.frame_format !== undefined &&
104
+ !["base64", "images"].includes(args.frame_format))
105
+ throw Error("frame_format must be base64 or images.");
106
+ if (args.frame_ids !== undefined &&
107
+ (!Array.isArray(args.frame_ids) ||
108
+ args.frame_ids.length > 4 ||
109
+ args.frame_ids.some((v) => typeof v !== "string")))
110
+ throw Error("frame_ids must contain at most four saved frame IDs.");
111
+ if (args.list_jobs !== undefined && typeof args.list_jobs !== "boolean")
112
+ throw Error("list_jobs must be boolean.");
113
+ if (args.job_id !== undefined && typeof args.job_id !== "string")
114
+ throw Error("job_id must be a saved record UUID.");
115
+ if (args.include_frames !== undefined &&
116
+ typeof args.include_frames !== "boolean")
117
+ throw Error("include_frames must be boolean.");
118
+ if (args.measurements !== undefined &&
119
+ (!Array.isArray(args.measurements) || args.measurements.length > 4))
120
+ throw Error("measurements must contain at most four entries.");
121
+ const measurements = args.measurements;
122
+ if (measurements?.some((v) => !v ||
123
+ typeof v !== "object" ||
124
+ typeof v.frameId !== "string" ||
125
+ typeof v.visible !== "boolean" ||
126
+ typeof v.observedHeightMm !== "number" ||
127
+ typeof v.uncertaintyMm !== "number" ||
128
+ typeof v.method !== "string"))
129
+ throw Error("Invalid frame measurement.");
130
+ return {
131
+ evidenceOnly: args.view === "evidence" ||
132
+ (args.frame_format === "images" && args.view !== "record"),
133
+ frameIds: args.frame_ids,
134
+ jobId: args.job_id,
135
+ listJobs: args.list_jobs,
136
+ includeFrames: args.frame_format === "images"
137
+ ? true
138
+ : args.include_frames,
139
+ measurements: measurements,
140
+ };
141
+ }
142
+ /** Image bytes appear once: normal MCP images for vision, or structuredContent base64. */
143
+ export function flightRecordResult(view, asImages = false) {
144
+ const metadata = structuredClone(view);
145
+ const content = [{ type: "text", text: "" }];
146
+ for (const frame of metadata.record?.frames ?? []) {
147
+ const bytes = frame.base64;
148
+ delete frame.base64;
149
+ if (asImages && bytes) {
150
+ frame.imageContentIndex = content.length;
151
+ content.push({ type: "image", data: bytes, mimeType: "image/jpeg" });
152
+ }
153
+ }
154
+ content[0] = { type: "text", text: JSON.stringify(metadata) };
155
+ return { content, structuredContent: asImages ? metadata : view };
156
+ }
157
+ export const PRINT_EVIDENCE_GUIDANCE = " When monitoring a print, firmware layer counters do not verify deposition. Follow physical.assessment requests at the first layer and later checkpoints: fetch counterpart_print_record with frame_format images, inspect the expected footprint with the client vision worker, then submit counterpart_print_assess. A clear empty footprint after attempted printing is suspect_no_extrusion; no baseline is required for that direct observation. Dark/occluded/unlocatable views are unknown. Never announce a first layer is down from counters alone. Do not stop or pause automatically.";
158
+ export const FLIGHT_ASSESS_DESCRIPTION = "Counterpart contract (counterpart/1): save a client vision worker observation against an exact saved job/artifact/frame hash. Local evidence only; no camera request, model call or printer controls. Clear visible empty expected footprint after attempted deposition reports suspect_no_extrusion, even without a usable baseline. Dark/occluded/unknown stays unknown; visible material does not verify success. Persists across restart; repeat observations are idempotent.";
159
+ export const FLIGHT_ASSESS_PROPERTIES = {
160
+ job_id: {
161
+ type: "string",
162
+ description: "Saved job UUID returned by counterpart_print_record.",
163
+ },
164
+ artifact_sha256: {
165
+ type: "string",
166
+ description: "Exact dispatch SHA-256 returned in this job record.",
167
+ },
168
+ frame_id: {
169
+ type: "string",
170
+ description: "Saved printing frame ID that the client visually assessed.",
171
+ },
172
+ image_sha256: {
173
+ type: "string",
174
+ description: "Saved JPEG SHA-256 for that exact frame.",
175
+ },
176
+ visibility: {
177
+ type: "string",
178
+ enum: [...VISIBILITIES],
179
+ description: "Client visual judgement of illumination and occlusion in the expected deposition region.",
180
+ },
181
+ footprint_visible: {
182
+ type: "boolean",
183
+ description: "The client can locate sufficient expected deposition footprint from the sliced geometry to judge whether material is present.",
184
+ },
185
+ deposition: {
186
+ type: "string",
187
+ enum: ["absent", "present", "unknown"],
188
+ description: "Client visual observation in that footprint; absent means clearly empty, not merely an unchanged image.",
189
+ },
190
+ attempted: {
191
+ type: "boolean",
192
+ description: "The client establishes this image follows attempted object deposition. False or uncertain stays unknown; counters alone do not establish physical success.",
193
+ },
194
+ reference_frame_id: {
195
+ type: "string",
196
+ description: "Optional saved preparation-frame ID used as additional empty-bed context.",
197
+ },
198
+ reference_visibility: {
199
+ type: "string",
200
+ enum: [...VISIBILITIES],
201
+ description: "Visibility of the expected footprint in the optional reference.",
202
+ },
203
+ reference_empty: {
204
+ type: "boolean",
205
+ description: "True only if the client visually confirmed the reference footprint is empty.",
206
+ },
207
+ };
208
+ export const FLIGHT_ASSESS_REQUIRED = [
209
+ "job_id",
210
+ "artifact_sha256",
211
+ "frame_id",
212
+ "image_sha256",
213
+ "visibility",
214
+ "footprint_visible",
215
+ "deposition",
216
+ "attempted",
217
+ ];
218
+ export function visualSubmission(args = {}) {
219
+ return validateVisualSubmission({
220
+ jobId: args.job_id,
221
+ artifactSha256: args.artifact_sha256,
222
+ frameId: args.frame_id,
223
+ imageSha256: args.image_sha256,
224
+ visibility: args.visibility,
225
+ footprintVisible: args.footprint_visible,
226
+ deposition: args.deposition,
227
+ attempted: args.attempted,
228
+ referenceFrameId: args.reference_frame_id,
229
+ referenceVisibility: args.reference_visibility,
230
+ referenceEmpty: args.reference_empty,
231
+ });
232
+ }
@@ -0,0 +1,16 @@
1
+ /** Reuse a stream, but never relabel a known pre-boundary cached image as a later layer. */
2
+ interface StreamFrame {
3
+ status: string;
4
+ seq: number;
5
+ capturedAt?: string;
6
+ base64?: string;
7
+ }
8
+ interface FrameSource {
9
+ frame(options: {
10
+ sinceSeq?: number;
11
+ waitMs?: number;
12
+ changedOnly?: boolean;
13
+ }): Promise<StreamFrame>;
14
+ }
15
+ export declare function snapshotFrame(source: FrameSource, timeoutMs: number, capturedAfter?: string): Promise<StreamFrame>;
16
+ export {};
@@ -0,0 +1,26 @@
1
+ export async function snapshotFrame(source, timeoutMs, capturedAfter) {
2
+ const waitMs = Math.min(timeoutMs, 10000), deadline = Date.now() + waitMs;
3
+ if (capturedAfter === undefined)
4
+ return source.frame({ waitMs, changedOnly: false });
5
+ const boundary = Date.parse(capturedAfter);
6
+ if (!Number.isFinite(boundary))
7
+ throw Error("Invalid camera acquisition boundary.");
8
+ const current = await source.frame({ waitMs: 0, changedOnly: false });
9
+ const matches = (frame) => frame.status === "frame" &&
10
+ !!frame.base64 &&
11
+ frame.capturedAt !== undefined &&
12
+ Number.isFinite(Date.parse(frame.capturedAt)) &&
13
+ Date.parse(frame.capturedAt) >= boundary;
14
+ if (matches(current))
15
+ return current;
16
+ if (current.status !== "frame" && current.status !== "unchanged")
17
+ return current;
18
+ const fresh = await source.frame({
19
+ sinceSeq: current.seq,
20
+ waitMs: Math.max(0, deadline - Date.now()),
21
+ changedOnly: false,
22
+ });
23
+ return fresh.seq > current.seq && matches(fresh)
24
+ ? fresh
25
+ : { status: "unavailable", seq: fresh.seq };
26
+ }
@@ -1,3 +1,4 @@
1
+ import { xmlAttribute } from "../slicer/3mf-xml.js";
1
2
  /**
2
3
  * counterpart_make_3mf: combine separately exported STL parts into one 3MF for
3
4
  * multi-colour printing (PRD §8.4/§8.5, M3b).
@@ -78,10 +79,6 @@ async function readMesh(filePath, label) {
78
79
  geometry?.dispose();
79
80
  }
80
81
  }
81
- function xmlAttribute(value) {
82
- return value.replace(/&/g, "&amp;").replace(/"/g, "&quot;").replace(/</g, "&lt;").replace(/>/g, "&gt;")
83
- .replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, "");
84
- }
85
82
  /** Shortest decimal that reads back as the same float32. */
86
83
  const coordinate = (value) => String(Number(value.toPrecision(9)));
87
84
  /** The model XML as buffers, so a large mesh never becomes one giant string. */
@@ -0,0 +1,70 @@
1
+ /** Pure assessment of explicit client measurements, not an embedded vision model or success gate. */
2
+ export interface EvidenceFrame {
3
+ role?: "baseline" | "first_layer" | "periodic" | "height";
4
+ stage?: string;
5
+ imageContentIndex?: number;
6
+ id: string;
7
+ capturedAt: string;
8
+ reportAt: string;
9
+ layer: number;
10
+ expectedHeightMm: number;
11
+ checkpoint: number;
12
+ status: "captured" | "unavailable";
13
+ reason?: string;
14
+ sha256?: string;
15
+ base64?: string;
16
+ }
17
+ export declare function frameMatchesReport(frame: EvidenceFrame): boolean;
18
+ export interface HeightMeasurement {
19
+ frameId: string;
20
+ visible: boolean;
21
+ observedHeightMm: number;
22
+ uncertaintyMm: number;
23
+ method: string;
24
+ }
25
+ export interface PhysicalEvidence {
26
+ observedLayer?: number;
27
+ assessment?: {
28
+ required: boolean;
29
+ frameId: string;
30
+ referenceFrameIds: string[];
31
+ layer: number;
32
+ expectedHeightMm: number;
33
+ expectedFootprintMm: [number, number, number, number];
34
+ instruction: string;
35
+ };
36
+ status: "unknown" | "consistent" | "suspect_no_growth" | "suspect_no_extrusion";
37
+ evidence: string[];
38
+ limitations: string[];
39
+ }
40
+ export declare function assessPhysical(frames: EvidenceFrame[], measurements?: HeightMeasurement[]): PhysicalEvidence;
41
+ export declare const PHYSICAL_EVIDENCE_SCHEMA: {
42
+ type: string;
43
+ properties: {
44
+ status: {
45
+ type: string;
46
+ enum: string[];
47
+ };
48
+ observedLayer: {
49
+ type: string;
50
+ minimum: number;
51
+ };
52
+ assessment: {
53
+ type: string;
54
+ additionalProperties: boolean;
55
+ };
56
+ evidence: {
57
+ type: string;
58
+ items: {
59
+ type: string;
60
+ };
61
+ };
62
+ limitations: {
63
+ type: string;
64
+ items: {
65
+ type: string;
66
+ };
67
+ };
68
+ };
69
+ required: string[];
70
+ };
@@ -0,0 +1,103 @@
1
+ export function frameMatchesReport(frame) {
2
+ const captured = Date.parse(frame.capturedAt), report = Date.parse(frame.reportAt);
3
+ return (Number.isFinite(captured) &&
4
+ Number.isFinite(report) &&
5
+ captured >= report &&
6
+ captured - report <= 15000);
7
+ }
8
+ export function assessPhysical(frames, measurements = []) {
9
+ const limitations = [
10
+ "Firmware completion is separate from physical success.",
11
+ "Layer Z and extrusion bounds are commanded geometry, not measured deposited plastic.",
12
+ "Measurements are supplied by the client; this server does not interpret images.",
13
+ ];
14
+ const unknown = (reason) => ({
15
+ status: "unknown",
16
+ evidence: [],
17
+ limitations: [...limitations, reason],
18
+ });
19
+ if (measurements.length < 2 || measurements.length > 4)
20
+ return unknown("At least two usable calibrated frame measurements are required.");
21
+ const seen = new Set();
22
+ const usable = [];
23
+ for (const measurement of measurements) {
24
+ const frame = frames.find((f) => f.id === measurement.frameId &&
25
+ f.status === "captured" &&
26
+ f.role !== "baseline");
27
+ if (!frame ||
28
+ seen.has(frame.id) ||
29
+ !measurement.visible ||
30
+ measurement.method !== "calibrated-height" ||
31
+ !Number.isFinite(measurement.observedHeightMm) ||
32
+ measurement.observedHeightMm < 0 ||
33
+ !Number.isFinite(measurement.uncertaintyMm) ||
34
+ measurement.uncertaintyMm < 0 ||
35
+ measurement.uncertaintyMm > Math.max(2, frame.expectedHeightMm * 0.05) ||
36
+ !frameMatchesReport(frame))
37
+ return unknown("A frame is unmatched, occluded/out of view, uncalibrated, too uncertain or too far from its report time.");
38
+ seen.add(frame.id);
39
+ usable.push({ frame, measurement });
40
+ }
41
+ usable.sort((a, b) => a.frame.layer - b.frame.layer);
42
+ const first = usable[0], last = usable[usable.length - 1];
43
+ if (last.frame.expectedHeightMm - first.frame.expectedHeightMm < 5)
44
+ return unknown("Expected height changed too little to assess growth.");
45
+ if (usable.some(({ frame, measurement: m }) => m.observedHeightMm >
46
+ frame.expectedHeightMm + Math.max(2, 3 * m.uncertaintyMm)) ||
47
+ usable.some((b, i) => i > 0 &&
48
+ usable[i - 1].measurement.observedHeightMm -
49
+ b.measurement.observedHeightMm >
50
+ usable[i - 1].measurement.uncertaintyMm +
51
+ b.measurement.uncertaintyMm +
52
+ 1))
53
+ return unknown("Calibrated heights contradict the expected extent or decrease between frames.");
54
+ const evidence = usable.map(({ frame }) => frame.id);
55
+ const agrees = usable.every(({ frame, measurement: m }) => Math.abs(m.observedHeightMm - frame.expectedHeightMm) <=
56
+ m.uncertaintyMm + 1);
57
+ if (agrees)
58
+ return {
59
+ status: "consistent",
60
+ evidence,
61
+ limitations: [
62
+ ...limitations,
63
+ "Consistent height in these frames only; shape, strength and final completion are unverified.",
64
+ ],
65
+ };
66
+ // Two later frames must show an unchanged short part; a healthy earlier frame must not hide that plateau.
67
+ for (let i = 1; i < usable.length; i++) {
68
+ const a = usable[i - 1], b = usable[i];
69
+ if (b.frame.expectedHeightMm - a.frame.expectedHeightMm >= 5 &&
70
+ Math.abs(b.measurement.observedHeightMm - a.measurement.observedHeightMm) <=
71
+ a.measurement.uncertaintyMm + b.measurement.uncertaintyMm + 0.5 &&
72
+ b.measurement.observedHeightMm <
73
+ b.frame.expectedHeightMm - Math.max(2, 3 * b.measurement.uncertaintyMm))
74
+ return {
75
+ status: "suspect_no_growth",
76
+ evidence: [a.frame.id, b.frame.id],
77
+ limitations: [
78
+ ...limitations,
79
+ "Visible measured height plateaued while expected Z increased; cause is unverified.",
80
+ ],
81
+ };
82
+ }
83
+ return unknown("The measurements do not establish either consistent growth or a no-growth plateau.");
84
+ }
85
+ export const PHYSICAL_EVIDENCE_SCHEMA = {
86
+ type: "object",
87
+ properties: {
88
+ status: {
89
+ type: "string",
90
+ enum: [
91
+ "unknown",
92
+ "consistent",
93
+ "suspect_no_growth",
94
+ "suspect_no_extrusion",
95
+ ],
96
+ },
97
+ observedLayer: { type: "integer", minimum: 1 },
98
+ assessment: { type: "object", additionalProperties: true },
99
+ evidence: { type: "array", items: { type: "string" } },
100
+ limitations: { type: "array", items: { type: "string" } },
101
+ },
102
+ required: ["status", "evidence", "limitations"],
103
+ };