bambu-printer-mcp 1.1.89 → 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.
- package/README.md +49 -1
- package/dist/cad/contracts.d.ts +84 -0
- package/dist/cad/contracts.js +50 -5
- package/dist/cad/examples.d.ts +22 -0
- package/dist/cad/examples.js +81 -0
- package/dist/cad/process.js +3 -0
- package/dist/cad-engine.d.ts +25 -0
- package/dist/cad-engine.js +197 -27
- package/dist/counterpart/flight-record.d.ts +155 -0
- package/dist/counterpart/flight-record.js +831 -0
- package/dist/counterpart/flight-tools.d.ts +213 -0
- package/dist/counterpart/flight-tools.js +232 -0
- package/dist/counterpart/fresh-frame.d.ts +16 -0
- package/dist/counterpart/fresh-frame.js +26 -0
- package/dist/counterpart/make-3mf.js +1 -4
- package/dist/counterpart/physical-evidence.d.ts +70 -0
- package/dist/counterpart/physical-evidence.js +103 -0
- package/dist/counterpart/print-geometry.d.ts +13 -0
- package/dist/counterpart/print-geometry.js +181 -0
- package/dist/counterpart/remote.js +4 -0
- package/dist/counterpart/schemas.d.ts +32 -0
- package/dist/counterpart/schemas.js +2 -0
- package/dist/counterpart/visual-evidence.d.ts +38 -0
- package/dist/counterpart/visual-evidence.js +155 -0
- package/dist/design-guidance.d.ts +22 -1
- package/dist/design-guidance.js +35 -2
- package/dist/index.js +35 -3
- package/dist/printers/bambu.d.ts +9 -2
- package/dist/printers/bambu.js +32 -6
- package/dist/safety/print-preview.d.ts +2 -0
- package/dist/safety/print-preview.js +1 -1
- package/dist/slicer/3mf-xml.d.ts +7 -0
- package/dist/slicer/3mf-xml.js +61 -0
- package/dist/stl/stl-manipulator.js +5 -2
- package/dist/tool-annotations.js +4 -0
- package/package.json +2 -1
- package/src/cad/contracts.ts +54 -5
- package/src/cad/examples/bag_clip.py +86 -0
- package/src/cad/examples/bistable_clicker.py +81 -0
- package/src/cad/examples/cable_clip.py +55 -0
- package/src/cad/examples/chainmail.py +45 -0
- package/src/cad/examples/hinged_box.py +101 -0
- package/src/cad/examples/knurled_knob.py +50 -0
- package/src/cad/examples/loft_handle.py +52 -0
- package/src/cad/examples/phone_stand.py +92 -0
- package/src/cad/examples/swept_hook.py +69 -0
- package/src/cad/examples/threaded_jar.py +62 -0
- package/src/cad/examples/trigger_capo.py +95 -0
- package/src/cad/examples/wall_hook.py +65 -0
- package/src/cad/examples.ts +77 -0
- package/src/cad/geometry.py +122 -4
- package/src/cad/process.ts +3 -0
- package/src/cad/worker.py +4 -0
- package/src/cad-engine.ts +221 -52
- package/src/counterpart/flight-record.ts +984 -0
- package/src/counterpart/flight-tools.ts +282 -0
- package/src/counterpart/fresh-frame.ts +45 -0
- package/src/counterpart/make-3mf.ts +1 -5
- package/src/counterpart/physical-evidence.ts +185 -0
- package/src/counterpart/print-geometry.ts +192 -0
- package/src/counterpart/remote.ts +4 -0
- package/src/counterpart/schemas.ts +3 -0
- package/src/counterpart/visual-evidence.ts +212 -0
- package/src/design-guidance.ts +35 -2
- package/src/index.ts +38 -4
- package/src/printers/bambu.ts +34 -5
- package/src/safety/print-preview.ts +1 -1
- package/src/slicer/3mf-xml.ts +52 -0
- package/src/stl/stl-manipulator.ts +4 -1
- package/src/tool-annotations.ts +4 -0
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
import { PHYSICAL_EVIDENCE_SCHEMA } from "./physical-evidence.js";
|
|
2
|
+
import { validateVisualSubmission, VISIBILITIES } from "./visual-evidence.js";
|
|
3
|
+
import type { HeightMeasurement, ReadRecordOptions } from "./flight-record.js";
|
|
4
|
+
export const FLIGHT_RECORD_PROPERTIES = {
|
|
5
|
+
view: {
|
|
6
|
+
type: "string",
|
|
7
|
+
enum: ["record", "evidence"],
|
|
8
|
+
description:
|
|
9
|
+
"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.",
|
|
10
|
+
},
|
|
11
|
+
frame_format: {
|
|
12
|
+
type: "string",
|
|
13
|
+
enum: ["base64", "images"],
|
|
14
|
+
description:
|
|
15
|
+
"Return requested JPEGs once as structured base64 (default) or normal MCP image content for a vision worker.",
|
|
16
|
+
},
|
|
17
|
+
frame_ids: {
|
|
18
|
+
type: "array",
|
|
19
|
+
maxItems: 4,
|
|
20
|
+
items: { type: "string" },
|
|
21
|
+
description:
|
|
22
|
+
"At most four saved frame IDs to retrieve; defaults to the pending assessment and baseline candidates, or recent evidence.",
|
|
23
|
+
},
|
|
24
|
+
list_jobs: {
|
|
25
|
+
type: "boolean",
|
|
26
|
+
description:
|
|
27
|
+
"Include the retained job IDs, dispatch times, artifact hashes and outcomes for this printer, so an older job can be selected.",
|
|
28
|
+
},
|
|
29
|
+
job_id: {
|
|
30
|
+
type: "string",
|
|
31
|
+
description:
|
|
32
|
+
"Saved record UUID; omit for the latest dispatched job on this printer.",
|
|
33
|
+
},
|
|
34
|
+
include_frames: {
|
|
35
|
+
type: "boolean",
|
|
36
|
+
description:
|
|
37
|
+
"Include up to four saved JPEGs (512 KiB each). Reads disk only.",
|
|
38
|
+
},
|
|
39
|
+
measurements: {
|
|
40
|
+
type: "array",
|
|
41
|
+
maxItems: 4,
|
|
42
|
+
description:
|
|
43
|
+
"Optional calibrated client height measurements for saved frames; no image interpretation or printer control is performed.",
|
|
44
|
+
items: {
|
|
45
|
+
type: "object",
|
|
46
|
+
properties: {
|
|
47
|
+
frameId: {
|
|
48
|
+
type: "string",
|
|
49
|
+
description: "The saved frame UUID returned in this job record.",
|
|
50
|
+
},
|
|
51
|
+
visible: {
|
|
52
|
+
type: "boolean",
|
|
53
|
+
description:
|
|
54
|
+
"The expected printed region and its maximum height are visible, unoccluded and in view.",
|
|
55
|
+
},
|
|
56
|
+
observedHeightMm: {
|
|
57
|
+
type: "number",
|
|
58
|
+
minimum: 0,
|
|
59
|
+
description:
|
|
60
|
+
"Client-calibrated maximum deposited Z height of this plate in the visible expected object region; use the same region across frames.",
|
|
61
|
+
},
|
|
62
|
+
uncertaintyMm: {
|
|
63
|
+
type: "number",
|
|
64
|
+
minimum: 0,
|
|
65
|
+
description:
|
|
66
|
+
"Estimated plus/minus error of the calibrated physical height measurement, in millimetres.",
|
|
67
|
+
},
|
|
68
|
+
method: {
|
|
69
|
+
type: "string",
|
|
70
|
+
enum: ["calibrated-height"],
|
|
71
|
+
description:
|
|
72
|
+
"An explicit calibrated height measurement from the client, never a pixel-change guess.",
|
|
73
|
+
},
|
|
74
|
+
},
|
|
75
|
+
required: [
|
|
76
|
+
"frameId",
|
|
77
|
+
"visible",
|
|
78
|
+
"observedHeightMm",
|
|
79
|
+
"uncertaintyMm",
|
|
80
|
+
"method",
|
|
81
|
+
],
|
|
82
|
+
additionalProperties: false,
|
|
83
|
+
},
|
|
84
|
+
},
|
|
85
|
+
} as const;
|
|
86
|
+
export const FLIGHT_RECORD_DESCRIPTION =
|
|
87
|
+
"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.";
|
|
88
|
+
export const FLIGHT_RECORD_OUTPUT_SCHEMA = {
|
|
89
|
+
type: "object" as const,
|
|
90
|
+
properties: {
|
|
91
|
+
contract: { type: "string", const: "counterpart/1" },
|
|
92
|
+
status: { type: "string", enum: ["recorded", "unavailable"] },
|
|
93
|
+
record: { type: "object", additionalProperties: true },
|
|
94
|
+
jobs: {
|
|
95
|
+
type: "array",
|
|
96
|
+
maxItems: 10,
|
|
97
|
+
items: {
|
|
98
|
+
type: "object",
|
|
99
|
+
properties: {
|
|
100
|
+
id: { type: "string" },
|
|
101
|
+
dispatchedAt: { type: "string" },
|
|
102
|
+
sha256: { type: "string" },
|
|
103
|
+
outcome: { type: "string" },
|
|
104
|
+
},
|
|
105
|
+
required: ["id", "dispatchedAt", "sha256", "outcome"],
|
|
106
|
+
},
|
|
107
|
+
},
|
|
108
|
+
physical: PHYSICAL_EVIDENCE_SCHEMA,
|
|
109
|
+
},
|
|
110
|
+
required: ["contract", "status", "physical"],
|
|
111
|
+
};
|
|
112
|
+
export function flightReadOptions(
|
|
113
|
+
args: Record<string, unknown> = {},
|
|
114
|
+
): ReadRecordOptions {
|
|
115
|
+
if (
|
|
116
|
+
args.view !== undefined &&
|
|
117
|
+
!["record", "evidence"].includes(args.view as string)
|
|
118
|
+
)
|
|
119
|
+
throw Error("view must be record or evidence.");
|
|
120
|
+
if (
|
|
121
|
+
args.frame_format !== undefined &&
|
|
122
|
+
!["base64", "images"].includes(args.frame_format as string)
|
|
123
|
+
)
|
|
124
|
+
throw Error("frame_format must be base64 or images.");
|
|
125
|
+
if (
|
|
126
|
+
args.frame_ids !== undefined &&
|
|
127
|
+
(!Array.isArray(args.frame_ids) ||
|
|
128
|
+
args.frame_ids.length > 4 ||
|
|
129
|
+
args.frame_ids.some((v) => typeof v !== "string"))
|
|
130
|
+
)
|
|
131
|
+
throw Error("frame_ids must contain at most four saved frame IDs.");
|
|
132
|
+
if (args.list_jobs !== undefined && typeof args.list_jobs !== "boolean")
|
|
133
|
+
throw Error("list_jobs must be boolean.");
|
|
134
|
+
if (args.job_id !== undefined && typeof args.job_id !== "string")
|
|
135
|
+
throw Error("job_id must be a saved record UUID.");
|
|
136
|
+
if (
|
|
137
|
+
args.include_frames !== undefined &&
|
|
138
|
+
typeof args.include_frames !== "boolean"
|
|
139
|
+
)
|
|
140
|
+
throw Error("include_frames must be boolean.");
|
|
141
|
+
if (
|
|
142
|
+
args.measurements !== undefined &&
|
|
143
|
+
(!Array.isArray(args.measurements) || args.measurements.length > 4)
|
|
144
|
+
)
|
|
145
|
+
throw Error("measurements must contain at most four entries.");
|
|
146
|
+
const measurements = args.measurements as unknown[] | undefined;
|
|
147
|
+
if (
|
|
148
|
+
measurements?.some(
|
|
149
|
+
(v) =>
|
|
150
|
+
!v ||
|
|
151
|
+
typeof v !== "object" ||
|
|
152
|
+
typeof (v as any).frameId !== "string" ||
|
|
153
|
+
typeof (v as any).visible !== "boolean" ||
|
|
154
|
+
typeof (v as any).observedHeightMm !== "number" ||
|
|
155
|
+
typeof (v as any).uncertaintyMm !== "number" ||
|
|
156
|
+
typeof (v as any).method !== "string",
|
|
157
|
+
)
|
|
158
|
+
)
|
|
159
|
+
throw Error("Invalid frame measurement.");
|
|
160
|
+
return {
|
|
161
|
+
evidenceOnly:
|
|
162
|
+
args.view === "evidence" ||
|
|
163
|
+
(args.frame_format === "images" && args.view !== "record"),
|
|
164
|
+
frameIds: args.frame_ids as string[] | undefined,
|
|
165
|
+
jobId: args.job_id as string | undefined,
|
|
166
|
+
listJobs: args.list_jobs as boolean | undefined,
|
|
167
|
+
includeFrames:
|
|
168
|
+
args.frame_format === "images"
|
|
169
|
+
? true
|
|
170
|
+
: (args.include_frames as boolean | undefined),
|
|
171
|
+
measurements: measurements as HeightMeasurement[] | undefined,
|
|
172
|
+
};
|
|
173
|
+
}
|
|
174
|
+
|
|
175
|
+
/** Image bytes appear once: normal MCP images for vision, or structuredContent base64. */
|
|
176
|
+
export function flightRecordResult<
|
|
177
|
+
T extends {
|
|
178
|
+
contract: string;
|
|
179
|
+
record?: { frames: Array<{ base64?: string; imageContentIndex?: number }> };
|
|
180
|
+
},
|
|
181
|
+
>(view: T, asImages = false) {
|
|
182
|
+
const metadata = structuredClone(view);
|
|
183
|
+
const content: Array<
|
|
184
|
+
| { type: "text"; text: string }
|
|
185
|
+
| { type: "image"; data: string; mimeType: string }
|
|
186
|
+
> = [{ type: "text", text: "" }];
|
|
187
|
+
for (const frame of metadata.record?.frames ?? []) {
|
|
188
|
+
const bytes = frame.base64;
|
|
189
|
+
delete frame.base64;
|
|
190
|
+
if (asImages && bytes) {
|
|
191
|
+
frame.imageContentIndex = content.length;
|
|
192
|
+
content.push({ type: "image", data: bytes, mimeType: "image/jpeg" });
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
content[0] = { type: "text", text: JSON.stringify(metadata) };
|
|
196
|
+
return { content, structuredContent: asImages ? metadata : view };
|
|
197
|
+
}
|
|
198
|
+
export const PRINT_EVIDENCE_GUIDANCE =
|
|
199
|
+
" 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.";
|
|
200
|
+
export const FLIGHT_ASSESS_DESCRIPTION =
|
|
201
|
+
"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.";
|
|
202
|
+
export const FLIGHT_ASSESS_PROPERTIES = {
|
|
203
|
+
job_id: {
|
|
204
|
+
type: "string",
|
|
205
|
+
description: "Saved job UUID returned by counterpart_print_record.",
|
|
206
|
+
},
|
|
207
|
+
artifact_sha256: {
|
|
208
|
+
type: "string",
|
|
209
|
+
description: "Exact dispatch SHA-256 returned in this job record.",
|
|
210
|
+
},
|
|
211
|
+
frame_id: {
|
|
212
|
+
type: "string",
|
|
213
|
+
description: "Saved printing frame ID that the client visually assessed.",
|
|
214
|
+
},
|
|
215
|
+
image_sha256: {
|
|
216
|
+
type: "string",
|
|
217
|
+
description: "Saved JPEG SHA-256 for that exact frame.",
|
|
218
|
+
},
|
|
219
|
+
visibility: {
|
|
220
|
+
type: "string",
|
|
221
|
+
enum: [...VISIBILITIES],
|
|
222
|
+
description:
|
|
223
|
+
"Client visual judgement of illumination and occlusion in the expected deposition region.",
|
|
224
|
+
},
|
|
225
|
+
footprint_visible: {
|
|
226
|
+
type: "boolean",
|
|
227
|
+
description:
|
|
228
|
+
"The client can locate sufficient expected deposition footprint from the sliced geometry to judge whether material is present.",
|
|
229
|
+
},
|
|
230
|
+
deposition: {
|
|
231
|
+
type: "string",
|
|
232
|
+
enum: ["absent", "present", "unknown"],
|
|
233
|
+
description:
|
|
234
|
+
"Client visual observation in that footprint; absent means clearly empty, not merely an unchanged image.",
|
|
235
|
+
},
|
|
236
|
+
attempted: {
|
|
237
|
+
type: "boolean",
|
|
238
|
+
description:
|
|
239
|
+
"The client establishes this image follows attempted object deposition. False or uncertain stays unknown; counters alone do not establish physical success.",
|
|
240
|
+
},
|
|
241
|
+
reference_frame_id: {
|
|
242
|
+
type: "string",
|
|
243
|
+
description:
|
|
244
|
+
"Optional saved preparation-frame ID used as additional empty-bed context.",
|
|
245
|
+
},
|
|
246
|
+
reference_visibility: {
|
|
247
|
+
type: "string",
|
|
248
|
+
enum: [...VISIBILITIES],
|
|
249
|
+
description:
|
|
250
|
+
"Visibility of the expected footprint in the optional reference.",
|
|
251
|
+
},
|
|
252
|
+
reference_empty: {
|
|
253
|
+
type: "boolean",
|
|
254
|
+
description:
|
|
255
|
+
"True only if the client visually confirmed the reference footprint is empty.",
|
|
256
|
+
},
|
|
257
|
+
};
|
|
258
|
+
export const FLIGHT_ASSESS_REQUIRED = [
|
|
259
|
+
"job_id",
|
|
260
|
+
"artifact_sha256",
|
|
261
|
+
"frame_id",
|
|
262
|
+
"image_sha256",
|
|
263
|
+
"visibility",
|
|
264
|
+
"footprint_visible",
|
|
265
|
+
"deposition",
|
|
266
|
+
"attempted",
|
|
267
|
+
];
|
|
268
|
+
export function visualSubmission(args: Record<string, unknown> = {}) {
|
|
269
|
+
return validateVisualSubmission({
|
|
270
|
+
jobId: args.job_id as string,
|
|
271
|
+
artifactSha256: args.artifact_sha256 as string,
|
|
272
|
+
frameId: args.frame_id as string,
|
|
273
|
+
imageSha256: args.image_sha256 as string,
|
|
274
|
+
visibility: args.visibility as any,
|
|
275
|
+
footprintVisible: args.footprint_visible as boolean,
|
|
276
|
+
deposition: args.deposition as any,
|
|
277
|
+
attempted: args.attempted as boolean,
|
|
278
|
+
referenceFrameId: args.reference_frame_id as string | undefined,
|
|
279
|
+
referenceVisibility: args.reference_visibility as any,
|
|
280
|
+
referenceEmpty: args.reference_empty as boolean | undefined,
|
|
281
|
+
});
|
|
282
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 async function snapshotFrame(
|
|
16
|
+
source: FrameSource,
|
|
17
|
+
timeoutMs: number,
|
|
18
|
+
capturedAfter?: string,
|
|
19
|
+
): Promise<StreamFrame> {
|
|
20
|
+
const waitMs = Math.min(timeoutMs, 10000),
|
|
21
|
+
deadline = Date.now() + waitMs;
|
|
22
|
+
if (capturedAfter === undefined)
|
|
23
|
+
return source.frame({ waitMs, changedOnly: false });
|
|
24
|
+
const boundary = Date.parse(capturedAfter);
|
|
25
|
+
if (!Number.isFinite(boundary))
|
|
26
|
+
throw Error("Invalid camera acquisition boundary.");
|
|
27
|
+
const current = await source.frame({ waitMs: 0, changedOnly: false });
|
|
28
|
+
const matches = (frame: StreamFrame) =>
|
|
29
|
+
frame.status === "frame" &&
|
|
30
|
+
!!frame.base64 &&
|
|
31
|
+
frame.capturedAt !== undefined &&
|
|
32
|
+
Number.isFinite(Date.parse(frame.capturedAt)) &&
|
|
33
|
+
Date.parse(frame.capturedAt) >= boundary;
|
|
34
|
+
if (matches(current)) return current;
|
|
35
|
+
if (current.status !== "frame" && current.status !== "unchanged")
|
|
36
|
+
return current;
|
|
37
|
+
const fresh = await source.frame({
|
|
38
|
+
sinceSeq: current.seq,
|
|
39
|
+
waitMs: Math.max(0, deadline - Date.now()),
|
|
40
|
+
changedOnly: false,
|
|
41
|
+
});
|
|
42
|
+
return fresh.seq > current.seq && matches(fresh)
|
|
43
|
+
? fresh
|
|
44
|
+
: { status: "unavailable", seq: fresh.seq };
|
|
45
|
+
}
|
|
@@ -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).
|
|
@@ -85,11 +86,6 @@ async function readMesh(filePath: string, label: string): Promise<Mesh> {
|
|
|
85
86
|
}
|
|
86
87
|
}
|
|
87
88
|
|
|
88
|
-
function xmlAttribute(value: string): string {
|
|
89
|
-
return value.replace(/&/g, "&").replace(/"/g, """).replace(/</g, "<").replace(/>/g, ">")
|
|
90
|
-
.replace(/[\u0000-\u0008\u000b\u000c\u000e-\u001f]/g, "");
|
|
91
|
-
}
|
|
92
|
-
|
|
93
89
|
/** Shortest decimal that reads back as the same float32. */
|
|
94
90
|
const coordinate = (value: number) => String(Number(value.toPrecision(9)));
|
|
95
91
|
|
|
@@ -0,0 +1,185 @@
|
|
|
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 function frameMatchesReport(frame: EvidenceFrame): boolean {
|
|
18
|
+
const captured = Date.parse(frame.capturedAt),
|
|
19
|
+
report = Date.parse(frame.reportAt);
|
|
20
|
+
return (
|
|
21
|
+
Number.isFinite(captured) &&
|
|
22
|
+
Number.isFinite(report) &&
|
|
23
|
+
captured >= report &&
|
|
24
|
+
captured - report <= 15000
|
|
25
|
+
);
|
|
26
|
+
}
|
|
27
|
+
export interface HeightMeasurement {
|
|
28
|
+
frameId: string;
|
|
29
|
+
visible: boolean;
|
|
30
|
+
observedHeightMm: number;
|
|
31
|
+
uncertaintyMm: number;
|
|
32
|
+
method: string;
|
|
33
|
+
}
|
|
34
|
+
export interface PhysicalEvidence {
|
|
35
|
+
observedLayer?: number;
|
|
36
|
+
assessment?: {
|
|
37
|
+
required: boolean;
|
|
38
|
+
frameId: string;
|
|
39
|
+
referenceFrameIds: string[];
|
|
40
|
+
layer: number;
|
|
41
|
+
expectedHeightMm: number;
|
|
42
|
+
expectedFootprintMm: [number, number, number, number];
|
|
43
|
+
instruction: string;
|
|
44
|
+
};
|
|
45
|
+
status:
|
|
46
|
+
| "unknown"
|
|
47
|
+
| "consistent"
|
|
48
|
+
| "suspect_no_growth"
|
|
49
|
+
| "suspect_no_extrusion";
|
|
50
|
+
evidence: string[];
|
|
51
|
+
limitations: string[];
|
|
52
|
+
}
|
|
53
|
+
export function assessPhysical(
|
|
54
|
+
frames: EvidenceFrame[],
|
|
55
|
+
measurements: HeightMeasurement[] = [],
|
|
56
|
+
): PhysicalEvidence {
|
|
57
|
+
const limitations = [
|
|
58
|
+
"Firmware completion is separate from physical success.",
|
|
59
|
+
"Layer Z and extrusion bounds are commanded geometry, not measured deposited plastic.",
|
|
60
|
+
"Measurements are supplied by the client; this server does not interpret images.",
|
|
61
|
+
];
|
|
62
|
+
const unknown = (reason: string): PhysicalEvidence => ({
|
|
63
|
+
status: "unknown",
|
|
64
|
+
evidence: [],
|
|
65
|
+
limitations: [...limitations, reason],
|
|
66
|
+
});
|
|
67
|
+
if (measurements.length < 2 || measurements.length > 4)
|
|
68
|
+
return unknown(
|
|
69
|
+
"At least two usable calibrated frame measurements are required.",
|
|
70
|
+
);
|
|
71
|
+
const seen = new Set<string>();
|
|
72
|
+
const usable: Array<{
|
|
73
|
+
frame: EvidenceFrame;
|
|
74
|
+
measurement: HeightMeasurement;
|
|
75
|
+
}> = [];
|
|
76
|
+
for (const measurement of measurements) {
|
|
77
|
+
const frame = frames.find(
|
|
78
|
+
(f) =>
|
|
79
|
+
f.id === measurement.frameId &&
|
|
80
|
+
f.status === "captured" &&
|
|
81
|
+
f.role !== "baseline",
|
|
82
|
+
);
|
|
83
|
+
if (
|
|
84
|
+
!frame ||
|
|
85
|
+
seen.has(frame.id) ||
|
|
86
|
+
!measurement.visible ||
|
|
87
|
+
measurement.method !== "calibrated-height" ||
|
|
88
|
+
!Number.isFinite(measurement.observedHeightMm) ||
|
|
89
|
+
measurement.observedHeightMm < 0 ||
|
|
90
|
+
!Number.isFinite(measurement.uncertaintyMm) ||
|
|
91
|
+
measurement.uncertaintyMm < 0 ||
|
|
92
|
+
measurement.uncertaintyMm > Math.max(2, frame.expectedHeightMm * 0.05) ||
|
|
93
|
+
!frameMatchesReport(frame)
|
|
94
|
+
)
|
|
95
|
+
return unknown(
|
|
96
|
+
"A frame is unmatched, occluded/out of view, uncalibrated, too uncertain or too far from its report time.",
|
|
97
|
+
);
|
|
98
|
+
seen.add(frame.id);
|
|
99
|
+
usable.push({ frame, measurement });
|
|
100
|
+
}
|
|
101
|
+
usable.sort((a, b) => a.frame.layer - b.frame.layer);
|
|
102
|
+
const first = usable[0],
|
|
103
|
+
last = usable[usable.length - 1];
|
|
104
|
+
if (last.frame.expectedHeightMm - first.frame.expectedHeightMm < 5)
|
|
105
|
+
return unknown("Expected height changed too little to assess growth.");
|
|
106
|
+
if (
|
|
107
|
+
usable.some(
|
|
108
|
+
({ frame, measurement: m }) =>
|
|
109
|
+
m.observedHeightMm >
|
|
110
|
+
frame.expectedHeightMm + Math.max(2, 3 * m.uncertaintyMm),
|
|
111
|
+
) ||
|
|
112
|
+
usable.some(
|
|
113
|
+
(b, i) =>
|
|
114
|
+
i > 0 &&
|
|
115
|
+
usable[i - 1].measurement.observedHeightMm -
|
|
116
|
+
b.measurement.observedHeightMm >
|
|
117
|
+
usable[i - 1].measurement.uncertaintyMm +
|
|
118
|
+
b.measurement.uncertaintyMm +
|
|
119
|
+
1,
|
|
120
|
+
)
|
|
121
|
+
)
|
|
122
|
+
return unknown(
|
|
123
|
+
"Calibrated heights contradict the expected extent or decrease between frames.",
|
|
124
|
+
);
|
|
125
|
+
const evidence = usable.map(({ frame }) => frame.id);
|
|
126
|
+
const agrees = usable.every(
|
|
127
|
+
({ frame, measurement: m }) =>
|
|
128
|
+
Math.abs(m.observedHeightMm - frame.expectedHeightMm) <=
|
|
129
|
+
m.uncertaintyMm + 1,
|
|
130
|
+
);
|
|
131
|
+
if (agrees)
|
|
132
|
+
return {
|
|
133
|
+
status: "consistent",
|
|
134
|
+
evidence,
|
|
135
|
+
limitations: [
|
|
136
|
+
...limitations,
|
|
137
|
+
"Consistent height in these frames only; shape, strength and final completion are unverified.",
|
|
138
|
+
],
|
|
139
|
+
};
|
|
140
|
+
// Two later frames must show an unchanged short part; a healthy earlier frame must not hide that plateau.
|
|
141
|
+
for (let i = 1; i < usable.length; i++) {
|
|
142
|
+
const a = usable[i - 1],
|
|
143
|
+
b = usable[i];
|
|
144
|
+
if (
|
|
145
|
+
b.frame.expectedHeightMm - a.frame.expectedHeightMm >= 5 &&
|
|
146
|
+
Math.abs(
|
|
147
|
+
b.measurement.observedHeightMm - a.measurement.observedHeightMm,
|
|
148
|
+
) <=
|
|
149
|
+
a.measurement.uncertaintyMm + b.measurement.uncertaintyMm + 0.5 &&
|
|
150
|
+
b.measurement.observedHeightMm <
|
|
151
|
+
b.frame.expectedHeightMm - Math.max(2, 3 * b.measurement.uncertaintyMm)
|
|
152
|
+
)
|
|
153
|
+
return {
|
|
154
|
+
status: "suspect_no_growth",
|
|
155
|
+
evidence: [a.frame.id, b.frame.id],
|
|
156
|
+
limitations: [
|
|
157
|
+
...limitations,
|
|
158
|
+
"Visible measured height plateaued while expected Z increased; cause is unverified.",
|
|
159
|
+
],
|
|
160
|
+
};
|
|
161
|
+
}
|
|
162
|
+
return unknown(
|
|
163
|
+
"The measurements do not establish either consistent growth or a no-growth plateau.",
|
|
164
|
+
);
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
export const PHYSICAL_EVIDENCE_SCHEMA = {
|
|
168
|
+
type: "object",
|
|
169
|
+
properties: {
|
|
170
|
+
status: {
|
|
171
|
+
type: "string",
|
|
172
|
+
enum: [
|
|
173
|
+
"unknown",
|
|
174
|
+
"consistent",
|
|
175
|
+
"suspect_no_growth",
|
|
176
|
+
"suspect_no_extrusion",
|
|
177
|
+
],
|
|
178
|
+
},
|
|
179
|
+
observedLayer: { type: "integer", minimum: 1 },
|
|
180
|
+
assessment: { type: "object", additionalProperties: true },
|
|
181
|
+
evidence: { type: "array", items: { type: "string" } },
|
|
182
|
+
limitations: { type: "array", items: { type: "string" } },
|
|
183
|
+
},
|
|
184
|
+
required: ["status", "evidence", "limitations"],
|
|
185
|
+
};
|