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
package/dist/cad-engine.js
CHANGED
|
@@ -16,6 +16,11 @@ const PACKAGE_NAME = createRequire(import.meta.url)("../package.json")
|
|
|
16
16
|
export class CadEngine {
|
|
17
17
|
constructor(options) {
|
|
18
18
|
this.options = options;
|
|
19
|
+
/** How long a re-check waits for another CAD operation to let go of the engine (Counterpart reads status with 30 s). */
|
|
20
|
+
this.busyWaitMs = 25000;
|
|
21
|
+
/** Within this window a freed engine is re-checked here; later this call only waits for the other call's result, so
|
|
22
|
+
* a wait plus a ~17 s re-check cannot overrun the status deadline. */
|
|
23
|
+
this.busyRetryMs = 5000;
|
|
19
24
|
this.system = options.system ?? defaultCadSystem;
|
|
20
25
|
this.dataDir = path.resolve(options.dataDir ??
|
|
21
26
|
process.env.CAD_DATA_DIR ??
|
|
@@ -130,7 +135,7 @@ export class CadEngine {
|
|
|
130
135
|
if (args.install !== true)
|
|
131
136
|
return {
|
|
132
137
|
supported: ["darwin", "linux"].includes(this.system.platform),
|
|
133
|
-
...(await this.
|
|
138
|
+
...(await this.ensureReady(signal)),
|
|
134
139
|
};
|
|
135
140
|
if (!["darwin", "linux"].includes(this.system.platform))
|
|
136
141
|
throw new CadRefusal("cad-confinement-unavailable", `CAD confinement is unavailable on ${this.system.platform}.`);
|
|
@@ -168,29 +173,8 @@ export class CadEngine {
|
|
|
168
173
|
throw new CadRefusal("cad-uv-missing", "uv is not available on the MCP's PATH. Install uv, then run cad_setup again; no model was run.");
|
|
169
174
|
throw e;
|
|
170
175
|
}
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
const request = path.join(job, "request.json");
|
|
174
|
-
await fs.writeFile(request, JSON.stringify({ output: job, home: os.homedir() }), { mode: 0o600 });
|
|
175
|
-
const result = JSON.parse((await this.confined("smoke", request, job, [request], 180000, signal)).stdout);
|
|
176
|
-
if (result.build123d !== BUILD123D ||
|
|
177
|
-
!result.watertight ||
|
|
178
|
-
!result.manifold ||
|
|
179
|
-
!result.step_valid ||
|
|
180
|
-
result.solid_count !== 1)
|
|
181
|
-
throw new Error("CAD setup's confined STL/STEP round trip failed.");
|
|
182
|
-
const storage = {
|
|
183
|
-
installed_bytes: await measureEnvironment(this.dataDir),
|
|
184
|
-
measured_at: new Date().toISOString(),
|
|
185
|
-
};
|
|
186
|
-
await fs.writeFile(path.join(this.dataDir, "ready.json"), JSON.stringify({
|
|
187
|
-
build123d: BUILD123D,
|
|
188
|
-
platform: this.system.platform,
|
|
189
|
-
verifiedAt: new Date().toISOString(),
|
|
190
|
-
fingerprint: await this.fingerprint(),
|
|
191
|
-
dataDevice: (await fs.stat(this.dataDir)).dev,
|
|
192
|
-
storage,
|
|
193
|
-
}), { mode: 0o600 });
|
|
176
|
+
this.reverifyFailure = undefined;
|
|
177
|
+
await this.verify(opts, signal);
|
|
194
178
|
return {
|
|
195
179
|
supported: true,
|
|
196
180
|
...(await this.status()),
|
|
@@ -199,6 +183,181 @@ export class CadEngine {
|
|
|
199
183
|
};
|
|
200
184
|
}, "setup", signal);
|
|
201
185
|
}
|
|
186
|
+
/**
|
|
187
|
+
* The proof setup ends with: the runtime's imports, then the confined build, STL and STEP round trip, then the ready
|
|
188
|
+
* marker with the engine fingerprint and the runtime identity it proved. Shared by cad_setup and the automatic
|
|
189
|
+
* re-verification after an update that changed only the engine's sources.
|
|
190
|
+
*/
|
|
191
|
+
async verify(opts, signal, measured) {
|
|
192
|
+
// Setup proves the fresh install's imports outside confinement first; a re-check of an unchanged runtime relies on
|
|
193
|
+
// the confined round trip, which imports the same libraries.
|
|
194
|
+
if (measured === undefined) {
|
|
195
|
+
const python = path.join(this.dataDir, "runtime", "bin", "python");
|
|
196
|
+
await this.system.run(python, ["-I", "-B", path.join(ASSETS, "worker.py"), "imports"], { ...opts, timeoutMs: 120000 });
|
|
197
|
+
}
|
|
198
|
+
const job = await fs.mkdtemp(path.join(this.dataDir, "verify-"));
|
|
199
|
+
const request = path.join(job, "request.json");
|
|
200
|
+
await fs.writeFile(request, JSON.stringify({ output: job, home: os.homedir() }), { mode: 0o600 });
|
|
201
|
+
const result = JSON.parse((await this.confined("smoke", request, job, [request], 180000, signal)).stdout);
|
|
202
|
+
if (result.build123d !== BUILD123D ||
|
|
203
|
+
!result.watertight ||
|
|
204
|
+
!result.manifold ||
|
|
205
|
+
!result.step_valid ||
|
|
206
|
+
result.solid_count !== 1)
|
|
207
|
+
throw new Error("CAD setup's confined STL/STEP round trip failed.");
|
|
208
|
+
// A re-check of an unchanged runtime keeps the size setup measured instead of walking 1.4 GB again.
|
|
209
|
+
const storage = measured ?? {
|
|
210
|
+
installed_bytes: await measureEnvironment(this.dataDir),
|
|
211
|
+
measured_at: new Date().toISOString(),
|
|
212
|
+
};
|
|
213
|
+
await fs.writeFile(path.join(this.dataDir, "ready.json"), JSON.stringify({
|
|
214
|
+
build123d: BUILD123D,
|
|
215
|
+
platform: this.system.platform,
|
|
216
|
+
verifiedAt: new Date().toISOString(),
|
|
217
|
+
fingerprint: await this.fingerprint(),
|
|
218
|
+
runtime: await this.runtimeIdentity(),
|
|
219
|
+
dataDevice: (await fs.stat(this.dataDir)).dev,
|
|
220
|
+
storage,
|
|
221
|
+
}), { mode: 0o600 });
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
224
|
+
* Re-verifies without installing when only the engine's own sources changed since the last proof (#609): the
|
|
225
|
+
* marker matches this platform, build123d and data device, its engine fingerprint differs, and the installed
|
|
226
|
+
* runtime still matches requirements.lock exactly with the same interpreter. Anything else, including a changed
|
|
227
|
+
* lock, still needs cad_setup with install: true. A failed re-verification is reported, not retried, until the
|
|
228
|
+
* engine changes again or setup runs.
|
|
229
|
+
*/
|
|
230
|
+
async ensureReady(signal, deadline) {
|
|
231
|
+
const status = await this.status();
|
|
232
|
+
if (status.ready || !status.configured)
|
|
233
|
+
return status;
|
|
234
|
+
const fingerprint = await this.fingerprint();
|
|
235
|
+
if (!(await this.onlyEngineChanged(fingerprint)))
|
|
236
|
+
return status;
|
|
237
|
+
if (this.reverifyFailure?.fingerprint === fingerprint)
|
|
238
|
+
return { ...status, error: this.reverifyFailure.error };
|
|
239
|
+
const started = performance.now();
|
|
240
|
+
// A cad_run or cad_check_fit passes its own deadline: the re-check, its waiting included, stays inside timeout_ms.
|
|
241
|
+
const outOfTime = {
|
|
242
|
+
...status,
|
|
243
|
+
error: "The automatic re-check after this MCP's update did not finish within this call's timeout_ms; the next call runs it again.",
|
|
244
|
+
};
|
|
245
|
+
if (deadline !== undefined && deadline - started < 1)
|
|
246
|
+
return outOfTime;
|
|
247
|
+
const limit = deadline === undefined ? undefined : AbortSignal.timeout(Math.ceil(deadline - started));
|
|
248
|
+
const bounded = limit ? (signal ? AbortSignal.any([signal, limit]) : limit) : signal;
|
|
249
|
+
const recheck = () => this.exclusive(async () => {
|
|
250
|
+
if ((await this.status()).ready)
|
|
251
|
+
return;
|
|
252
|
+
const env = this.environment(this.dataDir);
|
|
253
|
+
await fs.mkdir(env.TMPDIR, { recursive: true });
|
|
254
|
+
const previous = await fs
|
|
255
|
+
.readFile(path.join(this.dataDir, "ready.json"), "utf8")
|
|
256
|
+
.then((text) => JSON.parse(text).storage, () => undefined);
|
|
257
|
+
await this.verify({ env, cwd: this.dataDir, signal: bounded, timeoutMs: 600000 }, bounded, previous ?? null);
|
|
258
|
+
}, "setup", bounded);
|
|
259
|
+
try {
|
|
260
|
+
// Another call may hold the engine, usually this same re-check from another process (Counterpart reading
|
|
261
|
+
// cad_status while the design worker's first cad_run starts): wait for it and try again, never call it a failure.
|
|
262
|
+
const waited = performance.now();
|
|
263
|
+
for (let attempt = true, until = Math.min(waited + this.busyWaitMs, deadline ?? Infinity);;) {
|
|
264
|
+
try {
|
|
265
|
+
if (attempt) {
|
|
266
|
+
await recheck();
|
|
267
|
+
break;
|
|
268
|
+
}
|
|
269
|
+
throw new CadRefusal("cad-setup-busy", "waiting for the other CAD operation's result");
|
|
270
|
+
}
|
|
271
|
+
catch (e) {
|
|
272
|
+
if (!(e instanceof CadRefusal && e.code === "cad-setup-busy"))
|
|
273
|
+
throw e;
|
|
274
|
+
signal?.throwIfAborted();
|
|
275
|
+
if (limit?.aborted)
|
|
276
|
+
return outOfTime;
|
|
277
|
+
if ((await this.status()).ready)
|
|
278
|
+
break;
|
|
279
|
+
attempt = performance.now() - waited < this.busyRetryMs;
|
|
280
|
+
if (performance.now() >= until)
|
|
281
|
+
return {
|
|
282
|
+
...(await this.status()),
|
|
283
|
+
error: "Another CAD operation is running; this MCP re-checks its unchanged runtime by itself when that finishes. Ask again shortly.",
|
|
284
|
+
};
|
|
285
|
+
await new Promise((resolve) => setTimeout(resolve, 500));
|
|
286
|
+
}
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
catch (e) {
|
|
290
|
+
signal?.throwIfAborted();
|
|
291
|
+
if (limit?.aborted)
|
|
292
|
+
return outOfTime; // ran out of this call's time: not a failed re-check, never cached
|
|
293
|
+
const reason = e instanceof Error ? e.message : String(e);
|
|
294
|
+
this.reverifyFailure = {
|
|
295
|
+
fingerprint,
|
|
296
|
+
error: `The automatic re-check after this MCP's update failed (${reason.slice(0, 300)}). Run cad_setup with install: true.`,
|
|
297
|
+
};
|
|
298
|
+
return { ...(await this.status()), error: this.reverifyFailure.error };
|
|
299
|
+
}
|
|
300
|
+
const after = await this.status();
|
|
301
|
+
return after.ready
|
|
302
|
+
? {
|
|
303
|
+
...after,
|
|
304
|
+
reverified: `Re-checked automatically after an update to the engine (${Math.round((performance.now() - started) / 1000)} s): the installed runtime was unchanged; confined import, build, STL and STEP round trip passed.`,
|
|
305
|
+
}
|
|
306
|
+
: after;
|
|
307
|
+
}
|
|
308
|
+
async onlyEngineChanged(fingerprint) {
|
|
309
|
+
try {
|
|
310
|
+
const marker = JSON.parse(await fs.readFile(path.join(this.dataDir, "ready.json"), "utf8"));
|
|
311
|
+
if (marker.build123d !== BUILD123D ||
|
|
312
|
+
marker.platform !== this.system.platform ||
|
|
313
|
+
marker.dataDevice !== (await fs.stat(this.dataDir)).dev ||
|
|
314
|
+
typeof marker.fingerprint !== "string" ||
|
|
315
|
+
marker.fingerprint === fingerprint)
|
|
316
|
+
return false;
|
|
317
|
+
const runtime = await this.runtimeIdentity();
|
|
318
|
+
if (!runtime.matchesLock)
|
|
319
|
+
return false;
|
|
320
|
+
// Markers from engines without the runtime record (bambu-printer-mcp 1.1.89, mcp-3D-printer-server 1.2.71 and
|
|
321
|
+
// earlier) qualify by the exact package match; the re-run proof decides the rest.
|
|
322
|
+
if (marker.runtime && (marker.runtime.interpreter !== runtime.interpreter || marker.runtime.lock_sha256 !== runtime.lock_sha256))
|
|
323
|
+
return false;
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
catch {
|
|
327
|
+
return false;
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
/** The interpreter the venv runs and whether its installed distributions are exactly requirements.lock's pins. */
|
|
331
|
+
async runtimeIdentity() {
|
|
332
|
+
const lock = await fs.readFile(path.join(ASSETS, "requirements.lock"), "utf8");
|
|
333
|
+
const runtime = path.join(this.dataDir, "runtime");
|
|
334
|
+
const cfg = await fs.readFile(path.join(runtime, "pyvenv.cfg"), "utf8").catch(() => "");
|
|
335
|
+
const field = (name) => cfg.match(new RegExp(`^${name}\\s*=\\s*(.+)$`, "m"))?.[1]?.trim() ?? "";
|
|
336
|
+
const interpreter = `${field("version_info") || field("version")} ${await fs.realpath(path.join(runtime, "bin", "python")).catch(() => "")}`;
|
|
337
|
+
const norm = (name) => name.toLowerCase().replace(/[-_.]+/g, "-");
|
|
338
|
+
const installed = new Map();
|
|
339
|
+
const lib = path.join(runtime, "lib");
|
|
340
|
+
for (const dir of await fs.readdir(lib).catch(() => [])) {
|
|
341
|
+
if (!/^python3\.\d+$/.test(dir))
|
|
342
|
+
continue;
|
|
343
|
+
for (const entry of await fs.readdir(path.join(lib, dir, "site-packages")).catch(() => [])) {
|
|
344
|
+
const m = entry.match(/^(.+)-([^-]+)\.dist-info$/);
|
|
345
|
+
if (m)
|
|
346
|
+
installed.set(norm(m[1]), m[2]);
|
|
347
|
+
}
|
|
348
|
+
}
|
|
349
|
+
let matchesLock = installed.size > 0;
|
|
350
|
+
for (const line of lock.split("\n")) {
|
|
351
|
+
const m = line.match(/^\s*([A-Za-z0-9][A-Za-z0-9._-]*)==([^\s;]+)\s*(;.*)?$/);
|
|
352
|
+
if (!m)
|
|
353
|
+
continue;
|
|
354
|
+
const have = installed.get(norm(m[1]));
|
|
355
|
+
// A pin behind an environment marker may not apply here: absent is fine, a different version is not.
|
|
356
|
+
if (have === undefined ? !m[3] : have !== m[2])
|
|
357
|
+
matchesLock = false;
|
|
358
|
+
}
|
|
359
|
+
return { interpreter, lock_sha256: createHash("sha256").update(lock).digest("hex"), matchesLock };
|
|
360
|
+
}
|
|
202
361
|
async fingerprint() {
|
|
203
362
|
const hash = createHash("sha256");
|
|
204
363
|
for (const file of [
|
|
@@ -346,10 +505,13 @@ export class CadEngine {
|
|
|
346
505
|
inputs[alias] = await this.inputFile(value, ext);
|
|
347
506
|
}
|
|
348
507
|
}
|
|
508
|
+
// Re-check before queueing, inside this run's deadline; a not-ready refusal still comes from inside the queue,
|
|
509
|
+
// after any queue timeout.
|
|
510
|
+
const before = await this.ensureReady(signal, deadline);
|
|
349
511
|
return this.exclusive(async (queueWaitMs) => {
|
|
350
512
|
const status = await this.status();
|
|
351
513
|
if (!status.ready)
|
|
352
|
-
throw new CadRefusal("cad-not-ready", status.error);
|
|
514
|
+
throw new CadRefusal("cad-not-ready", before.error ?? status.error);
|
|
353
515
|
const job = await fs.mkdtemp(path.join(root, `cad-${name}-`));
|
|
354
516
|
await fs.chmod(job, 0o700);
|
|
355
517
|
const script = path.join(job, `${name}.py`), parameters = path.join(job, `${name}.parameters.json`), request = path.join(job, ".cad-request.json");
|
|
@@ -484,10 +646,13 @@ export class CadEngine {
|
|
|
484
646
|
clearance < 0 ||
|
|
485
647
|
clearance > 100)
|
|
486
648
|
throw new Error("clearance_mm must be finite, between 0 and 100.");
|
|
649
|
+
// One deadline for the whole call: the automatic re-check and the fit share timeout_ms.
|
|
650
|
+
const deadline = performance.now() + milliseconds(args.timeout_ms);
|
|
651
|
+
const before = await this.ensureReady(signal, deadline);
|
|
487
652
|
return this.exclusive(async () => {
|
|
488
653
|
const status = await this.status();
|
|
489
654
|
if (!status.ready)
|
|
490
|
-
throw new CadRefusal("cad-not-ready", status.error);
|
|
655
|
+
throw new CadRefusal("cad-not-ready", before.error ?? status.error);
|
|
491
656
|
const job = await fs.mkdtemp(path.join(this.dataDir, "fit-"));
|
|
492
657
|
try {
|
|
493
658
|
await fs.copyFile(model, path.join(job, "model.stl"));
|
|
@@ -503,7 +668,12 @@ export class CadEngine {
|
|
|
503
668
|
request,
|
|
504
669
|
path.join(job, "model.stl"),
|
|
505
670
|
path.join(job, "reference.stl"),
|
|
506
|
-
],
|
|
671
|
+
], (() => {
|
|
672
|
+
const left = Math.floor(deadline - performance.now());
|
|
673
|
+
if (left <= 0)
|
|
674
|
+
throw new Error("CAD fit timed out.");
|
|
675
|
+
return left;
|
|
676
|
+
})(), signal)).stdout);
|
|
507
677
|
}
|
|
508
678
|
finally {
|
|
509
679
|
await fs.rm(job, { recursive: true, force: true });
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
import { type VisualSubmission, type VisualObservation } from "./visual-evidence.js";
|
|
2
|
+
import type { PrintGeometry } from "./print-geometry.js";
|
|
3
|
+
import { type EvidenceFrame, type HeightMeasurement } from "./physical-evidence.js";
|
|
4
|
+
export type { PrintGeometry, HeightMeasurement };
|
|
5
|
+
export declare const flightKey: (host: string, serial: string) => string;
|
|
6
|
+
/** An allowlist, not a recursive dump/redactor. Unknown fields and arbitrary strings never reach disk. */
|
|
7
|
+
export declare function flightSnapshot(raw: Record<string, any>): Record<string, unknown>;
|
|
8
|
+
export interface FlightDispatch {
|
|
9
|
+
sha256: string;
|
|
10
|
+
jobName: string;
|
|
11
|
+
mapping?: number[];
|
|
12
|
+
materials?: string[];
|
|
13
|
+
plate?: {
|
|
14
|
+
index: number;
|
|
15
|
+
sha256: string;
|
|
16
|
+
};
|
|
17
|
+
expected?: PrintGeometry;
|
|
18
|
+
}
|
|
19
|
+
interface StoredDispatch extends Omit<FlightDispatch, "jobName" | "expected"> {
|
|
20
|
+
jobHash: string;
|
|
21
|
+
outcome: "unconfirmed" | "accepted" | "observed-active";
|
|
22
|
+
acceptedAt?: string;
|
|
23
|
+
}
|
|
24
|
+
export interface FlightRecord {
|
|
25
|
+
version: 1;
|
|
26
|
+
seenActive: boolean;
|
|
27
|
+
owner?: {
|
|
28
|
+
pid: number;
|
|
29
|
+
token: string;
|
|
30
|
+
};
|
|
31
|
+
endedAt?: string;
|
|
32
|
+
execution?: Record<string, string>;
|
|
33
|
+
executionSuperseded?: boolean;
|
|
34
|
+
id: string;
|
|
35
|
+
printerKey: string;
|
|
36
|
+
dispatchedAt: string;
|
|
37
|
+
dispatch: StoredDispatch;
|
|
38
|
+
expected?: PrintGeometry;
|
|
39
|
+
reports: Array<{
|
|
40
|
+
seq: number;
|
|
41
|
+
at: string;
|
|
42
|
+
changes: Record<string, unknown>;
|
|
43
|
+
}>;
|
|
44
|
+
latest: Record<string, unknown>;
|
|
45
|
+
droppedReports: number;
|
|
46
|
+
nextSeq: number;
|
|
47
|
+
frames: EvidenceFrame[];
|
|
48
|
+
skippedCheckpoints: number[];
|
|
49
|
+
droppedFrames: number;
|
|
50
|
+
sampledCheckpoints?: number[];
|
|
51
|
+
visualObservations?: VisualObservation[];
|
|
52
|
+
omittedReports?: number;
|
|
53
|
+
omittedGeometryLayers?: number;
|
|
54
|
+
storage: "durable" | "volatile";
|
|
55
|
+
}
|
|
56
|
+
export interface ReadRecordOptions {
|
|
57
|
+
evidenceOnly?: boolean;
|
|
58
|
+
frameIds?: string[];
|
|
59
|
+
listJobs?: boolean;
|
|
60
|
+
jobId?: string;
|
|
61
|
+
includeFrames?: boolean;
|
|
62
|
+
measurements?: HeightMeasurement[];
|
|
63
|
+
}
|
|
64
|
+
export declare class FlightRecords {
|
|
65
|
+
private readonly dir;
|
|
66
|
+
private readonly now;
|
|
67
|
+
private readonly maxEvents;
|
|
68
|
+
private readonly maxJobs;
|
|
69
|
+
private readonly maxBytes;
|
|
70
|
+
private readonly maxCaptureMs;
|
|
71
|
+
private readonly cache;
|
|
72
|
+
private readonly pending;
|
|
73
|
+
private readonly recentReports;
|
|
74
|
+
private readonly superseded;
|
|
75
|
+
private warned;
|
|
76
|
+
private readonly ownerToken;
|
|
77
|
+
constructor(options?: {
|
|
78
|
+
dir?: string;
|
|
79
|
+
now?: () => number;
|
|
80
|
+
maxEvents?: number;
|
|
81
|
+
maxJobs?: number;
|
|
82
|
+
maxBytes?: number;
|
|
83
|
+
maxCaptureMs?: number;
|
|
84
|
+
});
|
|
85
|
+
begin(key: string, input: FlightDispatch): string;
|
|
86
|
+
accept(key: string, jobName: string): boolean;
|
|
87
|
+
observe(key: string, raw: Record<string, any>, at?: number): void;
|
|
88
|
+
/** Progress may expose saved evidence only for the job in this returned report. */
|
|
89
|
+
physicalForReport(key: string, raw: Record<string, any> | null | undefined): import("./physical-evidence.js").PhysicalEvidence;
|
|
90
|
+
read(key: string, options?: ReadRecordOptions): {
|
|
91
|
+
physical: import("./physical-evidence.js").PhysicalEvidence;
|
|
92
|
+
jobs?: {
|
|
93
|
+
id: string;
|
|
94
|
+
dispatchedAt: string;
|
|
95
|
+
sha256: string;
|
|
96
|
+
outcome: "accepted" | "unconfirmed" | "observed-active";
|
|
97
|
+
}[] | undefined;
|
|
98
|
+
contract: "counterpart/1";
|
|
99
|
+
status: "unavailable";
|
|
100
|
+
} | {
|
|
101
|
+
record: FlightRecord;
|
|
102
|
+
physical: import("./physical-evidence.js").PhysicalEvidence;
|
|
103
|
+
jobs?: {
|
|
104
|
+
id: string;
|
|
105
|
+
dispatchedAt: string;
|
|
106
|
+
sha256: string;
|
|
107
|
+
outcome: "accepted" | "unconfirmed" | "observed-active";
|
|
108
|
+
}[] | undefined;
|
|
109
|
+
contract: "counterpart/1";
|
|
110
|
+
status: "recorded";
|
|
111
|
+
};
|
|
112
|
+
/** Persist only the client's frame-bound visual observation, without printer I/O or journal ownership changes. */
|
|
113
|
+
submitVisual(key: string, input: VisualSubmission): {
|
|
114
|
+
physical: import("./physical-evidence.js").PhysicalEvidence;
|
|
115
|
+
jobs?: {
|
|
116
|
+
id: string;
|
|
117
|
+
dispatchedAt: string;
|
|
118
|
+
sha256: string;
|
|
119
|
+
outcome: "accepted" | "unconfirmed" | "observed-active";
|
|
120
|
+
}[] | undefined;
|
|
121
|
+
contract: "counterpart/1";
|
|
122
|
+
status: "unavailable";
|
|
123
|
+
} | {
|
|
124
|
+
record: FlightRecord;
|
|
125
|
+
physical: import("./physical-evidence.js").PhysicalEvidence;
|
|
126
|
+
jobs?: {
|
|
127
|
+
id: string;
|
|
128
|
+
dispatchedAt: string;
|
|
129
|
+
sha256: string;
|
|
130
|
+
outcome: "accepted" | "unconfirmed" | "observed-active";
|
|
131
|
+
}[] | undefined;
|
|
132
|
+
contract: "counterpart/1";
|
|
133
|
+
status: "recorded";
|
|
134
|
+
};
|
|
135
|
+
private visualFile;
|
|
136
|
+
private visuals;
|
|
137
|
+
private trimFrames;
|
|
138
|
+
/** Called only after existing reports/reads, never on a timer; a sample cannot block the print. */
|
|
139
|
+
sample(key: string, capture: (capturedAfter: string) => Promise<{
|
|
140
|
+
base64?: string;
|
|
141
|
+
capturedAt?: string;
|
|
142
|
+
}>): Promise<void>;
|
|
143
|
+
/** One process writes a dispatched job; fresh observations can take over after its process exits. */
|
|
144
|
+
private canWrite;
|
|
145
|
+
private jobSummaries;
|
|
146
|
+
private isSuperseded;
|
|
147
|
+
/** Monotonic one-byte sidecar: another observer cannot overwrite the live owner's journal. */
|
|
148
|
+
private invalidateExecution;
|
|
149
|
+
private file;
|
|
150
|
+
private frameFile;
|
|
151
|
+
private files;
|
|
152
|
+
private get;
|
|
153
|
+
private save;
|
|
154
|
+
private prune;
|
|
155
|
+
}
|