@floless/app 0.128.1 → 0.129.0

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.
@@ -78,7 +78,7 @@ var require_queue = __commonJS({
78
78
  var _running = 0;
79
79
  var errorHandler = null;
80
80
  var self = {
81
- push,
81
+ push: push2,
82
82
  drain: noop,
83
83
  saturated: noop,
84
84
  pause,
@@ -150,7 +150,7 @@ var require_queue = __commonJS({
150
150
  function idle() {
151
151
  return _running === 0 && self.length() === 0;
152
152
  }
153
- function push(value, done) {
153
+ function push2(value, done) {
154
154
  var current = cache2.get();
155
155
  current.context = context;
156
156
  current.release = release;
@@ -289,11 +289,11 @@ var require_queue = __commonJS({
289
289
  var queue2 = fastqueue(context, asyncWrapper, _concurrency);
290
290
  var pushCb = queue2.push;
291
291
  var unshiftCb = queue2.unshift;
292
- queue2.push = push;
292
+ queue2.push = push2;
293
293
  queue2.unshift = unshift;
294
294
  queue2.drained = drained;
295
295
  return queue2;
296
- function push(value) {
296
+ function push2(value) {
297
297
  var p = new Promise(function(resolve20, reject) {
298
298
  pushCb(value, function(err2, result) {
299
299
  if (err2) {
@@ -32061,7 +32061,7 @@ var require_parse_url = __commonJS({
32061
32061
  var require_form_data = __commonJS({
32062
32062
  "node_modules/light-my-request/lib/form-data.js"(exports2, module2) {
32063
32063
  "use strict";
32064
- var { randomUUID: randomUUID32 } = require("node:crypto");
32064
+ var { randomUUID: randomUUID33 } = require("node:crypto");
32065
32065
  var { Readable: Readable3 } = require("node:stream");
32066
32066
  var textEncoder;
32067
32067
  function isFormDataLike(payload) {
@@ -32069,7 +32069,7 @@ var require_form_data = __commonJS({
32069
32069
  }
32070
32070
  function formDataToStream(formdata) {
32071
32071
  textEncoder = textEncoder ?? new TextEncoder();
32072
- const boundary = `----formdata-${randomUUID32()}`;
32072
+ const boundary = `----formdata-${randomUUID33()}`;
32073
32073
  const prefix = `--${boundary}\r
32074
32074
  Content-Disposition: form-data`;
32075
32075
  const escape2 = (str4) => str4.replace(/\n/g, "%0A").replace(/\r/g, "%0D").replace(/"/g, "%22");
@@ -53340,6 +53340,120 @@ function startTriggerWithLease(id, args, lease) {
53340
53340
  }
53341
53341
  };
53342
53342
  }
53343
+ var PROGRESS_POLL_MS = 100;
53344
+ function toProgressRecord(e, fallbackRunId) {
53345
+ const data = e.data;
53346
+ if (!data || typeof data !== "object" || Array.isArray(data)) return null;
53347
+ const d = data;
53348
+ if (typeof d.phase !== "string" || !d.phase) return null;
53349
+ const evRunId = e.run_id;
53350
+ const runId = typeof evRunId === "string" && RUN_ID.test(evRunId) ? evRunId : fallbackRunId;
53351
+ if (!runId) return null;
53352
+ const num4 = (v) => typeof v === "number" && Number.isFinite(v) ? v : void 0;
53353
+ const art = d.artifact;
53354
+ const artifact = art && typeof art === "object" && !Array.isArray(art) && typeof art.id === "string" ? {
53355
+ id: art.id,
53356
+ mediaType: typeof art.mediaType === "string" ? art.mediaType : void 0,
53357
+ bytes: num4(art.bytes),
53358
+ items: num4(art.items),
53359
+ seq: num4(art.seq)
53360
+ } : void 0;
53361
+ return {
53362
+ runId,
53363
+ node: typeof e.node === "string" ? e.node : null,
53364
+ phase: d.phase,
53365
+ seq: num4(d.seq),
53366
+ done: num4(d.done),
53367
+ total: num4(d.total),
53368
+ message: typeof d.message === "string" ? d.message : void 0,
53369
+ ...artifact ? { artifact } : {}
53370
+ };
53371
+ }
53372
+ function watchRunProgress(id, onProgress) {
53373
+ let tracePath = null;
53374
+ let runId = null;
53375
+ let stdoutBuf = "";
53376
+ let offset = 0;
53377
+ let stopped = false;
53378
+ const drain = () => {
53379
+ if (!tracePath || stopped) return;
53380
+ let size;
53381
+ try {
53382
+ size = (0, import_node_fs9.statSync)(tracePath).size;
53383
+ } catch {
53384
+ return;
53385
+ }
53386
+ if (size < offset) offset = 0;
53387
+ if (size <= offset) return;
53388
+ let text4;
53389
+ let fd2 = -1;
53390
+ try {
53391
+ fd2 = (0, import_node_fs9.openSync)(tracePath, "r");
53392
+ const buf = Buffer.alloc(size - offset);
53393
+ const read2 = (0, import_node_fs9.readSync)(fd2, buf, 0, buf.length, offset);
53394
+ const nl = buf.lastIndexOf(10, read2 - 1);
53395
+ if (nl < 0) return;
53396
+ text4 = buf.subarray(0, nl + 1).toString("utf8");
53397
+ offset += nl + 1;
53398
+ } catch {
53399
+ return;
53400
+ } finally {
53401
+ if (fd2 >= 0) {
53402
+ try {
53403
+ (0, import_node_fs9.closeSync)(fd2);
53404
+ } catch {
53405
+ }
53406
+ }
53407
+ }
53408
+ for (const line of text4.split(/\r?\n/)) {
53409
+ if (!line.trim()) continue;
53410
+ let ev;
53411
+ try {
53412
+ ev = JSON.parse(line);
53413
+ } catch {
53414
+ continue;
53415
+ }
53416
+ if (ev.kind !== "node-progress") continue;
53417
+ const rec = toProgressRecord(ev, runId);
53418
+ if (!rec) continue;
53419
+ try {
53420
+ onProgress(rec);
53421
+ } catch {
53422
+ }
53423
+ }
53424
+ };
53425
+ const tick2 = () => {
53426
+ try {
53427
+ drain();
53428
+ } catch {
53429
+ clearInterval(poll);
53430
+ stopped = true;
53431
+ }
53432
+ };
53433
+ const poll = setInterval(tick2, PROGRESS_POLL_MS);
53434
+ return {
53435
+ attach(child) {
53436
+ child.stdout?.on("data", (d) => {
53437
+ if (tracePath || stopped) return;
53438
+ stdoutBuf = (stdoutBuf + d.toString()).slice(0, OUTPUT_CAP_BYTES);
53439
+ const h = parseRunHandle(stdoutBuf);
53440
+ if (h) {
53441
+ runId = h.runId;
53442
+ tracePath = traceLogPath(id, h.instance, h.runId);
53443
+ }
53444
+ });
53445
+ },
53446
+ stop() {
53447
+ if (stopped) return;
53448
+ clearInterval(poll);
53449
+ try {
53450
+ drain();
53451
+ } catch {
53452
+ }
53453
+ stopped = true;
53454
+ }
53455
+ };
53456
+ }
53343
53457
  var APP_ID2 = /^[a-z0-9][a-z0-9._-]*$/i;
53344
53458
  function assertId(id) {
53345
53459
  if (!APP_ID2.test(id)) throw new AwareError(`invalid app id: ${JSON.stringify(id)}`);
@@ -53984,11 +54098,13 @@ var awareImpl = {
53984
54098
  runChain = new Promise((r) => release = r);
53985
54099
  await prev.catch(() => {
53986
54100
  });
54101
+ const progress = opts.onProgress ? watchRunProgress(id, opts.onProgress) : null;
53987
54102
  try {
53988
54103
  if (ticket.cancelled) throw new AwareError("Run cancelled", { cancelled: true });
53989
54104
  const { code, stdout, stderr } = await runRaw(args, (child) => {
53990
54105
  ticket.child = child;
53991
54106
  activeRun = ticket;
54107
+ progress?.attach(child);
53992
54108
  }, opts.env, opts.timeoutMs);
53993
54109
  if (ticket.cancelled) {
53994
54110
  throw new AwareError("Run cancelled", { cancelled: true });
@@ -53999,6 +54115,7 @@ var awareImpl = {
53999
54115
  const traceText = tracePath && (0, import_node_fs9.existsSync)(tracePath) ? (0, import_node_fs9.readFileSync)(tracePath, "utf8") : null;
54000
54116
  return { runId, tracePath, traceText, output: stdout.trim() };
54001
54117
  } finally {
54118
+ progress?.stop();
54002
54119
  if (activeRun === ticket) activeRun = null;
54003
54120
  ticket.child = null;
54004
54121
  release();
@@ -54011,18 +54128,23 @@ var awareImpl = {
54011
54128
  */
54012
54129
  async readRunArtifact(app, id, runId, opts = {}) {
54013
54130
  const ticket = opts.ticket;
54131
+ if (ticket && opts.signal) {
54132
+ throw new AwareError("readRunArtifact takes a ticket or a signal, never both \u2014 see the collision above");
54133
+ }
54014
54134
  if (ticket?.cancelled) throw new AwareError("Run cancelled", { cancelled: true });
54135
+ if (opts.signal?.aborted) throw new AwareError("artifact transfer aborted", { cancelled: true });
54015
54136
  const dir = (0, import_node_fs9.mkdtempSync)((0, import_node_path7.join)(artifactTempParent(), "run-"));
54016
54137
  const output = (0, import_node_path7.join)(dir, "artifact.json");
54017
54138
  try {
54018
- const { code, stdout, stderr } = await runRaw(
54139
+ const { code, stdout, stderr } = await runRawWithEnv(
54019
54140
  appArtifactArgv(app, id, runId, output),
54141
+ void 0,
54142
+ 3e5,
54020
54143
  (child) => {
54021
54144
  if (!ticket) return;
54022
54145
  ticket.child = child;
54023
54146
  },
54024
- void 0,
54025
- 3e5
54147
+ opts.signal
54026
54148
  );
54027
54149
  if (ticket?.cancelled) throw new AwareError("Run cancelled", { cancelled: true });
54028
54150
  if (code !== 0) {
@@ -54858,7 +54980,7 @@ function appVersion() {
54858
54980
  return resolveVersion({
54859
54981
  isSea: isSea2(),
54860
54982
  sqVersionXml: readSqVersionXml(),
54861
- define: true ? "0.128.1" : void 0,
54983
+ define: true ? "0.129.0" : void 0,
54862
54984
  pkgVersion: readPkgVersion()
54863
54985
  });
54864
54986
  }
@@ -54874,7 +54996,7 @@ function resolveChannel(s) {
54874
54996
  function appChannel() {
54875
54997
  return resolveChannel({
54876
54998
  isSea: isSea2(),
54877
- define: true ? "0.128.1" : void 0,
54999
+ define: true ? "0.129.0" : void 0,
54878
55000
  // argv[1] is the entry the runtime actually loaded (…/dist/floless-server.cjs), which is what
54879
55001
  // carries the npx cache prefix. Absent under the SEA exe, which never reaches the npx branch.
54880
55002
  modulePath: process.argv[1]
@@ -59462,7 +59584,7 @@ function bearingFaces(x, uOnN, vOnN, requestedSide) {
59462
59584
  }
59463
59585
 
59464
59586
  // index.ts
59465
- var import_node_crypto40 = require("node:crypto");
59587
+ var import_node_crypto41 = require("node:crypto");
59466
59588
 
59467
59589
  // ifc-guid.ts
59468
59590
  var import_node_crypto13 = require("node:crypto");
@@ -60911,7 +61033,6 @@ var TYPE_SET = {
60911
61033
  "knowledge-adjust": true,
60912
61034
  "knowledge-consult": true
60913
61035
  };
60914
- var REQUEST_TYPES = Object.keys(TYPE_SET);
60915
61036
  function isRequestType(t) {
60916
61037
  return typeof t === "string" && Object.prototype.hasOwnProperty.call(TYPE_SET, t);
60917
61038
  }
@@ -70856,7 +70977,7 @@ function registerSteelPrepassRoute(app, deps) {
70856
70977
  }
70857
70978
 
70858
70979
  // reference-routes.ts
70859
- var import_node_crypto28 = require("node:crypto");
70980
+ var import_node_crypto29 = require("node:crypto");
70860
70981
 
70861
70982
  // reference-import.ts
70862
70983
  var import_node_fs42 = require("node:fs");
@@ -71111,6 +71232,91 @@ function toReferenceObjects(raw) {
71111
71232
  selected: toSelection(raw.selected)
71112
71233
  };
71113
71234
  }
71235
+ var PREVIEW_BATCH_SIZE = 500;
71236
+ var PREVIEW_MAX_OBJECTS = WARN_OBJECTS;
71237
+ function toPreviewObjects(raw) {
71238
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return [];
71239
+ const doc = raw;
71240
+ if (!Array.isArray(doc.objects)) return [];
71241
+ const alreadyZUp = doc.frame === FILE_Z_UP;
71242
+ if (!alreadyZUp && doc.frame !== void 0 && doc.frame !== FILE_Y_UP) return [];
71243
+ return doc.objects.filter(renderable).map((o) => ({
71244
+ positions: alreadyZUp ? o.positions : yUpToZUp(o.positions),
71245
+ indices: o.indices
71246
+ }));
71247
+ }
71248
+ var SEGMENT_CONCURRENCY = 2;
71249
+ function createSegmentPump(companionId, sink) {
71250
+ const controller = new AbortController();
71251
+ const seen = /* @__PURE__ */ new Set();
71252
+ let painted = 0;
71253
+ let active2 = 0;
71254
+ let stopped = false;
71255
+ const queue2 = [];
71256
+ const stop = (reason) => {
71257
+ if (stopped) return;
71258
+ stopped = true;
71259
+ queue2.length = 0;
71260
+ controller.abort();
71261
+ try {
71262
+ sink.onStop(reason);
71263
+ } catch {
71264
+ }
71265
+ };
71266
+ const pump = () => {
71267
+ while (!stopped && active2 < SEGMENT_CONCURRENCY && queue2.length) {
71268
+ const job = queue2.shift();
71269
+ active2++;
71270
+ void (async () => {
71271
+ try {
71272
+ const text4 = await aware.readRunArtifact(companionId, job.id, job.runId, { signal: controller.signal });
71273
+ if (stopped) return;
71274
+ const objects = toPreviewObjects(JSON.parse(text4));
71275
+ if (!objects.length) return;
71276
+ if (painted + objects.length > PREVIEW_MAX_OBJECTS) {
71277
+ stop("cap");
71278
+ return;
71279
+ }
71280
+ painted += objects.length;
71281
+ sink.onBatch(objects, { seq: job.seq, painted });
71282
+ } catch (e) {
71283
+ if (!stopped) {
71284
+ console.warn(
71285
+ "[reference] preview segment failed; preview abandoned",
71286
+ { seq: job.seq, artifact: job.id, runId: job.runId, painted, error: e instanceof Error ? e.message : String(e) }
71287
+ );
71288
+ stop("error");
71289
+ }
71290
+ } finally {
71291
+ active2--;
71292
+ pump();
71293
+ }
71294
+ })();
71295
+ }
71296
+ };
71297
+ try {
71298
+ sink.onAbortable?.(() => stop("aborted"));
71299
+ } catch {
71300
+ }
71301
+ return {
71302
+ onRecord(rec) {
71303
+ if (stopped) return;
71304
+ if (rec.phase === "progress-suppressed") {
71305
+ stop("suppressed");
71306
+ return;
71307
+ }
71308
+ if (rec.phase !== "batch") return;
71309
+ const seq = rec.artifact?.seq ?? rec.seq;
71310
+ if (!rec.artifact?.id || typeof seq !== "number" || seen.has(seq)) return;
71311
+ seen.add(seq);
71312
+ queue2.push({ seq, id: rec.artifact.id, runId: rec.runId });
71313
+ pump();
71314
+ },
71315
+ abort(reason) {
71316
+ stop(reason);
71317
+ }
71318
+ };
71319
+ }
71114
71320
  var REFERENCE_DIR = "references";
71115
71321
  var SAFE_NAME = /[^A-Za-z0-9._-]+/g;
71116
71322
  function projectRelativeReferencePath(fileName, taken = /* @__PURE__ */ new Set()) {
@@ -71128,7 +71334,10 @@ function projectRelativeReferencePath(fileName, taken = /* @__PURE__ */ new Set(
71128
71334
  return candidate;
71129
71335
  }
71130
71336
  var readerChain2 = Promise.resolve();
71131
- function writeReaderApp2(companionId, command, ifcPath, filter) {
71337
+ function wantsSegments(command, filter) {
71338
+ return command === "read-model" && !emittedFilter(filter);
71339
+ }
71340
+ function writeReaderApp2(companionId, command, ifcPath, filter, progressive = false) {
71132
71341
  const dir = appPath(companionId);
71133
71342
  (0, import_node_fs42.mkdirSync)(dir, { recursive: true });
71134
71343
  const flo = (0, import_node_path39.join)(dir, `${companionId}.flo`);
@@ -71169,6 +71378,7 @@ function writeReaderApp2(companionId, command, ifcPath, filter) {
71169
71378
  const emit = emittedFilter(filter);
71170
71379
  if (emit?.storeys) lines.push(` storeys: ${JSON.stringify(emit.storeys)}`);
71171
71380
  if (emit?.ifcTypes) lines.push(` ifc-types: ${JSON.stringify(emit.ifcTypes)}`);
71381
+ if (progressive && wantsSegments(command, filter)) lines.push(` batch-size: ${PREVIEW_BATCH_SIZE}`);
71172
71382
  }
71173
71383
  lines.push("");
71174
71384
  (0, import_node_fs42.writeFileSync)(flo, lines.join("\n"));
@@ -71206,8 +71416,9 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71206
71416
  readerChain2 = new Promise((r) => release = r);
71207
71417
  await prev.catch(() => {
71208
71418
  });
71419
+ const pump = opts.preview && wantsSegments(command, opts.filter) ? createSegmentPump(companionId, opts.preview) : null;
71209
71420
  try {
71210
- const flo = writeReaderApp2(companionId, command, ifcPath, opts.filter);
71421
+ const flo = writeReaderApp2(companionId, command, ifcPath, opts.filter, !!pump);
71211
71422
  try {
71212
71423
  await aware.compile(flo);
71213
71424
  } catch (e) {
@@ -71218,7 +71429,12 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71218
71429
  try {
71219
71430
  ({ traceText, runId } = await aware.run(companionId, {
71220
71431
  ticket: opts.ticket,
71221
- timeoutMs: readerRunTimeout(command)
71432
+ timeoutMs: readerRunTimeout(command),
71433
+ // Records arrive on a 100 ms poll of the trace WHILE this await is still pending. Nothing here
71434
+ // waits on the pump: `aware.run` resolves when the reader exits, and the pump is aborted
71435
+ // immediately below rather than drained, so preview work can never make the authoritative
71436
+ // response slower than it is today.
71437
+ ...pump ? { onProgress: (rec) => pump.onRecord(rec) } : {}
71222
71438
  }));
71223
71439
  } catch (e) {
71224
71440
  const reason = e instanceof AwareError ? String(e.detail?.stderr ?? "").trim() : "";
@@ -71246,6 +71462,7 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71246
71462
  }
71247
71463
  return artifact;
71248
71464
  } finally {
71465
+ pump?.abort("aborted");
71249
71466
  release();
71250
71467
  }
71251
71468
  }
@@ -71275,8 +71492,126 @@ async function readReferenceModel(companionId, ifcPath, opts = {}) {
71275
71492
  return read2;
71276
71493
  }
71277
71494
 
71278
- // reference-store.ts
71495
+ // reference-progress.ts
71279
71496
  var import_node_crypto27 = require("node:crypto");
71497
+ var MAX_BUFFER_BYTES = 8 * 1024 * 1024;
71498
+ var SESSION_TTL_MS = 10 * 6e4;
71499
+ var UNCLAIMED_TTL_MS = 2 * 6e4;
71500
+ var SWEEP_MS = 3e4;
71501
+ var sessions = /* @__PURE__ */ new Map();
71502
+ function createProgressSession(appId, project) {
71503
+ const id = (0, import_node_crypto27.randomUUID)();
71504
+ sessions.set(id, {
71505
+ id,
71506
+ appId,
71507
+ project,
71508
+ createdAt: Date.now(),
71509
+ seq: 0,
71510
+ buffered: [],
71511
+ bytes: 0,
71512
+ droppedBefore: 0,
71513
+ subscriber: null,
71514
+ terminal: false,
71515
+ onDead: null
71516
+ });
71517
+ return id;
71518
+ }
71519
+ function claimProgressSession(id, appId, project, onDead) {
71520
+ if (!id) return null;
71521
+ const s = sessions.get(id);
71522
+ if (!s || s.terminal || s.onDead || s.appId !== appId || s.project !== project) return null;
71523
+ s.onDead = onDead;
71524
+ return id;
71525
+ }
71526
+ function frameOf(seq, event) {
71527
+ return `id: ${seq}
71528
+ data: ${JSON.stringify(event)}
71529
+
71530
+ `;
71531
+ }
71532
+ function push(s, seq, frame) {
71533
+ if (!s.subscriber) return false;
71534
+ try {
71535
+ s.subscriber.raw.write(frame);
71536
+ return true;
71537
+ } catch {
71538
+ endSubscriber(s);
71539
+ return false;
71540
+ }
71541
+ }
71542
+ function publishProgress(id, event) {
71543
+ const s = sessions.get(id);
71544
+ if (!s || s.terminal) return;
71545
+ const seq = ++s.seq;
71546
+ const frame = frameOf(seq, event);
71547
+ push(s, seq, frame);
71548
+ s.buffered.push({ seq, frame });
71549
+ s.bytes += frame.length;
71550
+ while (s.bytes > MAX_BUFFER_BYTES && s.buffered.length > 1) {
71551
+ const dropped = s.buffered.shift();
71552
+ s.bytes -= dropped.frame.length;
71553
+ s.droppedBefore = dropped.seq;
71554
+ }
71555
+ }
71556
+ function subscribeProgress(id, reply, afterSeq, owner2) {
71557
+ const s = sessions.get(id);
71558
+ if (!s || s.appId !== owner2.appId || s.project !== owner2.project) return false;
71559
+ if (s.subscriber && s.subscriber !== reply) endSubscriber(s);
71560
+ s.subscriber = reply;
71561
+ reply.raw.on("close", () => {
71562
+ if (s.subscriber !== reply) return;
71563
+ s.subscriber = null;
71564
+ if (!s.onDead) closeProgressSession(id, "unsubscribed");
71565
+ });
71566
+ if (afterSeq > 0 && afterSeq < s.droppedBefore) {
71567
+ closeProgressSession(id, "gap");
71568
+ return true;
71569
+ }
71570
+ for (const b of s.buffered) {
71571
+ if (b.seq > afterSeq) push(s, b.seq, b.frame);
71572
+ }
71573
+ if (s.terminal) endSubscriber(s);
71574
+ return true;
71575
+ }
71576
+ function endSubscriber(s) {
71577
+ const sub = s.subscriber;
71578
+ s.subscriber = null;
71579
+ if (!sub) return;
71580
+ try {
71581
+ sub.raw.end();
71582
+ } catch {
71583
+ }
71584
+ }
71585
+ function closeProgressSession(id, reason) {
71586
+ const s = sessions.get(id);
71587
+ if (!s || s.terminal) return;
71588
+ s.terminal = true;
71589
+ const seq = ++s.seq;
71590
+ push(s, seq, frameOf(seq, { type: "stopped", reason }));
71591
+ s.buffered = [];
71592
+ s.bytes = 0;
71593
+ endSubscriber(s);
71594
+ sessions.delete(id);
71595
+ const dead = s.onDead;
71596
+ s.onDead = null;
71597
+ if (dead && reason !== "done" && reason !== "aborted") {
71598
+ try {
71599
+ dead();
71600
+ } catch {
71601
+ }
71602
+ }
71603
+ }
71604
+ var sweep = setInterval(() => {
71605
+ const now = Date.now();
71606
+ for (const [id, s] of [...sessions]) {
71607
+ const ttl = s.onDead ? SESSION_TTL_MS : UNCLAIMED_TTL_MS;
71608
+ if (now - s.createdAt > ttl) closeProgressSession(id, "expired");
71609
+ }
71610
+ }, SWEEP_MS);
71611
+ sweep.unref?.();
71612
+
71613
+ // reference-store.ts
71614
+ var import_node_crypto28 = require("node:crypto");
71280
71615
  var import_node_fs43 = require("node:fs");
71281
71616
  var import_promises4 = require("node:stream/promises");
71282
71617
  var import_node_path40 = require("node:path");
@@ -71312,7 +71647,7 @@ function safeId2(refId2) {
71312
71647
  return s;
71313
71648
  }
71314
71649
  async function hashFile(path) {
71315
- const h = (0, import_node_crypto27.createHash)("sha256");
71650
+ const h = (0, import_node_crypto28.createHash)("sha256");
71316
71651
  await (0, import_promises4.pipeline)((0, import_node_fs43.createReadStream)(path), h);
71317
71652
  return h.digest("hex");
71318
71653
  }
@@ -71506,7 +71841,62 @@ function importRefusal(e) {
71506
71841
  }
71507
71842
  return null;
71508
71843
  }
71844
+ function previewFor(sessionId, appId, project) {
71845
+ let abortPump = null;
71846
+ const id = claimProgressSession(sessionId, appId, project, () => {
71847
+ abortPump?.();
71848
+ });
71849
+ if (!id) return null;
71850
+ return {
71851
+ id,
71852
+ sink: {
71853
+ onAbortable(abort) {
71854
+ abortPump = abort;
71855
+ },
71856
+ onBatch(objects, meta) {
71857
+ publishProgress(id, { type: "batch", objects, painted: meta.painted });
71858
+ },
71859
+ // TERMINAL, AND IMMEDIATE. A client told nothing would keep a progress indicator spinning until
71860
+ // the HTTP result finally landed — which for a suppressed channel or a crossed cap is the whole
71861
+ // remaining duration of the read, i.e. exactly the wait this feature exists to remove.
71862
+ onStop(reason) {
71863
+ closeProgressSession(id, reason);
71864
+ }
71865
+ }
71866
+ };
71867
+ }
71509
71868
  function registerReferenceRoutes(app, deps) {
71869
+ app.post(
71870
+ "/api/steel/:appId/reference/progress",
71871
+ async (req, reply) => {
71872
+ const g = gate2(deps, req.params.appId, req.query.project);
71873
+ if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71874
+ return { ok: true, sessionId: createProgressSession(g.appId, g.project) };
71875
+ }
71876
+ );
71877
+ app.get(
71878
+ "/api/steel/:appId/reference/progress/:sessionId",
71879
+ async (req, reply) => {
71880
+ const g = gate2(deps, req.params.appId, req.query.project);
71881
+ if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71882
+ const header = req.headers["last-event-id"];
71883
+ const raw = (Array.isArray(header) ? header[0] : header) ?? req.query.afterSeq ?? "0";
71884
+ const afterSeq = Number.isFinite(Number(raw)) && Number(raw) >= 0 ? Math.floor(Number(raw)) : 0;
71885
+ reply.raw.writeHead(200, {
71886
+ "Content-Type": "text/event-stream",
71887
+ "Cache-Control": "no-cache, no-transform",
71888
+ Connection: "keep-alive",
71889
+ "X-Accel-Buffering": "no"
71890
+ });
71891
+ if (!subscribeProgress(req.params.sessionId, reply, afterSeq, { appId: g.appId, project: g.project })) {
71892
+ reply.raw.write(`data: ${JSON.stringify({ type: "stopped", reason: "unknown" })}
71893
+
71894
+ `);
71895
+ reply.raw.end();
71896
+ }
71897
+ return reply;
71898
+ }
71899
+ );
71510
71900
  app.post(
71511
71901
  "/api/steel/:appId/reference/probe",
71512
71902
  { bodyLimit: REFERENCE_BODY_LIMIT },
@@ -71559,7 +71949,7 @@ function registerReferenceRoutes(app, deps) {
71559
71949
  const scope = runScope(deps, reply, { detachOnDisconnect: true });
71560
71950
  const g = gate2(deps, req.params.appId, req.query.project);
71561
71951
  if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71562
- const { sha, name, placement } = req.body ?? {};
71952
+ const { sha, name, placement, progressId: sessionId } = req.body ?? {};
71563
71953
  if (!sha) return reply.status(400).send({ ok: false, error: "probe the file first \u2014 its sha is required" });
71564
71954
  const asked = req.body?.filter;
71565
71955
  const names = (v) => Array.isArray(v) ? v.filter((s) => typeof s === "string" && !!s.trim()) : [];
@@ -71576,7 +71966,7 @@ function registerReferenceRoutes(app, deps) {
71576
71966
  return reply.status(404).send({ ok: false, error: "the uploaded IFC is no longer available \u2014 drop the file again" });
71577
71967
  }
71578
71968
  const displayName = String(name || "model.ifc");
71579
- const id = (0, import_node_crypto28.randomUUID)();
71969
+ const id = (0, import_node_crypto29.randomUUID)();
71580
71970
  let rel;
71581
71971
  try {
71582
71972
  rel = await withLifecycleLock("project", g.project, () => {
@@ -71593,6 +71983,7 @@ function registerReferenceRoutes(app, deps) {
71593
71983
  throw e;
71594
71984
  }
71595
71985
  let committed = false;
71986
+ let preview2 = null;
71596
71987
  const rollback = () => {
71597
71988
  if (committed) return;
71598
71989
  try {
@@ -71615,7 +72006,12 @@ function registerReferenceRoutes(app, deps) {
71615
72006
  error: tooMany(`"${displayName}" would load about ${estimate.toLocaleString("en-US")} objects`, probe)
71616
72007
  });
71617
72008
  }
71618
- const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket(), filter });
72009
+ preview2 = previewFor(sessionId, g.appId, g.project);
72010
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, {
72011
+ ticket: scope.ticket(),
72012
+ filter,
72013
+ ...preview2 ? { preview: preview2.sink } : {}
72014
+ });
71619
72015
  if (scope.gone()) throw new ReferenceImportError("cancelled");
71620
72016
  const missed = unmatchedNames(geometry.selected);
71621
72017
  if (!geometry.objects.length && hasUnmatched(geometry.selected)) {
@@ -71675,6 +72071,7 @@ function registerReferenceRoutes(app, deps) {
71675
72071
  app.log.error({ appId: g.appId, err: e instanceof Error ? e.message : e }, "reference insert failed");
71676
72072
  return reply.status(500).send({ ok: false, error: "could not load that reference model" });
71677
72073
  } finally {
72074
+ if (preview2) closeProgressSession(preview2.id, "done");
71678
72075
  scope.finish();
71679
72076
  }
71680
72077
  }
@@ -71712,8 +72109,14 @@ function registerReferenceRoutes(app, deps) {
71712
72109
  const stored2 = entry2.filter;
71713
72110
  const hit = rebuild ? null : cachedGeometry(g.project, entry2.id, sourceHash, stored2);
71714
72111
  if (hit) return { ok: true, cached: true, objects: hit.objects, dropped: hit.dropped, colorsAvailable: hit.colorsAvailable ?? null, colorsDropped: hit.colorsDropped ?? 0, propertySetsAvailable: hit.propertySetsAvailable ?? null, spanMm: spanOf(hit.objects) };
72112
+ let preview2 = null;
71715
72113
  try {
71716
- const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket(), filter: stored2 });
72114
+ preview2 = previewFor(req.query.progressId, g.appId, g.project);
72115
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, {
72116
+ ticket: scope.ticket(),
72117
+ filter: stored2,
72118
+ ...preview2 ? { preview: preview2.sink } : {}
72119
+ });
71717
72120
  const missed = unmatchedNames(geometry.selected);
71718
72121
  if (!geometry.objects.length && hasUnmatched(geometry.selected)) {
71719
72122
  return reply.status(409).send({
@@ -71748,6 +72151,7 @@ function registerReferenceRoutes(app, deps) {
71748
72151
  app.log.error({ appId: g.appId, id: entry2.id, err: e instanceof Error ? e.message : e }, "reference rebuild failed");
71749
72152
  return reply.status(500).send({ ok: false, error: `could not re-read "${entry2.name}"` });
71750
72153
  } finally {
72154
+ if (preview2) closeProgressSession(preview2.id, "done");
71751
72155
  scope.finish();
71752
72156
  }
71753
72157
  }
@@ -76261,7 +76665,7 @@ function buildApprovalReview(input) {
76261
76665
  }
76262
76666
 
76263
76667
  // working-revision-manifest.ts
76264
- var import_node_crypto29 = require("node:crypto");
76668
+ var import_node_crypto30 = require("node:crypto");
76265
76669
  var import_node_fs46 = require("node:fs");
76266
76670
  var import_node_path43 = require("node:path");
76267
76671
  var pathOf = (projectId) => (0, import_node_path43.join)(projectDir(projectId), ".floless-working-revision-state-v1.json");
@@ -76291,7 +76695,7 @@ function ensureWorkingRevisionManifest(input) {
76291
76695
  schema: 1,
76292
76696
  projectUuid: assertProject(input.project),
76293
76697
  publicationIdentity: input.publicationIdentity,
76294
- revisionId: (0, import_node_crypto29.randomUUID)(),
76698
+ revisionId: (0, import_node_crypto30.randomUUID)(),
76295
76699
  epoch: 0,
76296
76700
  source: { kind: "working" },
76297
76701
  workingBase: input.workingBase,
@@ -76312,7 +76716,7 @@ function advanceWorkingRevisionManifest(input) {
76312
76716
  if (current.publicationIdentity !== input.publicationIdentity) throw new Error("working revision belongs to another app publication");
76313
76717
  const body = {
76314
76718
  ...bodyOf(current),
76315
- revisionId: (0, import_node_crypto29.randomUUID)(),
76719
+ revisionId: (0, import_node_crypto30.randomUUID)(),
76316
76720
  epoch: current.epoch + 1,
76317
76721
  source: input.source,
76318
76722
  workingBase: input.workingBase,
@@ -76570,7 +76974,7 @@ function projectApprovalCandidateAccepted(appId, projectId, candidate) {
76570
76974
  }
76571
76975
 
76572
76976
  // project-checkpoints-store.ts
76573
- var import_node_crypto30 = require("node:crypto");
76977
+ var import_node_crypto31 = require("node:crypto");
76574
76978
  var import_node_fs47 = require("node:fs");
76575
76979
  var import_node_path44 = require("node:path");
76576
76980
  var HASH_RE3 = /^[0-9a-f]{64}$/;
@@ -76614,7 +77018,7 @@ function requireIdentity(project) {
76614
77018
  function appendEvent(projectId, event) {
76615
77019
  (0, import_node_fs47.mkdirSync)(root5(projectId), { recursive: true });
76616
77020
  const log2 = readEvents(projectId);
76617
- const row = { ...event, eventId: (0, import_node_crypto30.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
77021
+ const row = { ...event, eventId: (0, import_node_crypto31.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
76618
77022
  log2.events.push(row);
76619
77023
  writeJsonAtomic(eventsPath(projectId), log2);
76620
77024
  return row;
@@ -76674,7 +77078,7 @@ function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
76674
77078
  }
76675
77079
 
76676
77080
  // export-source.ts
76677
- var import_node_crypto31 = require("node:crypto");
77081
+ var import_node_crypto32 = require("node:crypto");
76678
77082
  var import_node_fs48 = require("node:fs");
76679
77083
  var import_node_os26 = require("node:os");
76680
77084
  var import_node_path45 = require("node:path");
@@ -76761,7 +77165,7 @@ function captureExportSource(projectId, selector = { kind: "latest-approved" },
76761
77165
  }
76762
77166
  const contentHash = hashOf(contract);
76763
77167
  const capturedAt = (/* @__PURE__ */ new Date()).toISOString();
76764
- const handleId = (0, import_node_crypto31.randomUUID)();
77168
+ const handleId = (0, import_node_crypto32.randomUUID)();
76765
77169
  const shortHash = contentHash.slice(0, 8);
76766
77170
  const filenameLabel = kind === "approved" ? `v${approvedVersion}` : kind === "working" ? `Working-DRAFT-${shortHash}` : `Checkpoint-${sourceRef.slice(0, 8)}-DRAFT-${shortHash}`;
76767
77171
  const body = {
@@ -76803,7 +77207,7 @@ function cloneExportHandle(handleId, copies) {
76803
77207
  const created = [];
76804
77208
  try {
76805
77209
  for (let index = 0; index < copies; index++) {
76806
- const value = index === 0 ? original : stored({ ...withoutChecksum(original), handleId: (0, import_node_crypto31.randomUUID)(), resultRefs: [] });
77210
+ const value = index === 0 ? original : stored({ ...withoutChecksum(original), handleId: (0, import_node_crypto32.randomUUID)(), resultRefs: [] });
76807
77211
  if (index > 0) {
76808
77212
  writeJsonAtomic(handlePath(value.handleId), value);
76809
77213
  created.push(value.handleId);
@@ -76874,7 +77278,7 @@ function collectExpiredExportHandles(now = Date.now()) {
76874
77278
  }
76875
77279
 
76876
77280
  // file-publication.ts
76877
- var import_node_crypto32 = require("node:crypto");
77281
+ var import_node_crypto33 = require("node:crypto");
76878
77282
  var import_node_fs49 = require("node:fs");
76879
77283
  var import_node_path46 = require("node:path");
76880
77284
  var FilePublicationError = class extends Error {
@@ -76889,7 +77293,7 @@ var FilePublicationError = class extends Error {
76889
77293
  };
76890
77294
  var proofOfBytes = (bytes) => ({
76891
77295
  bytes: bytes.byteLength,
76892
- sha256: (0, import_node_crypto32.createHash)("sha256").update(bytes).digest("hex")
77296
+ sha256: (0, import_node_crypto33.createHash)("sha256").update(bytes).digest("hex")
76893
77297
  });
76894
77298
  function readFileProof2(path) {
76895
77299
  try {
@@ -76905,7 +77309,7 @@ function fileProofEquals2(a, b) {
76905
77309
  function durableCanonicalJson(path, value) {
76906
77310
  const dir = (0, import_node_path46.dirname)(path);
76907
77311
  (0, import_node_fs49.mkdirSync)(dir, { recursive: true });
76908
- const temp = (0, import_node_path46.join)(dir, `.${(0, import_node_path46.basename)(path)}.${process.pid}.${(0, import_node_crypto32.randomUUID)()}.tmp`);
77312
+ const temp = (0, import_node_path46.join)(dir, `.${(0, import_node_path46.basename)(path)}.${process.pid}.${(0, import_node_crypto33.randomUUID)()}.tmp`);
76909
77313
  try {
76910
77314
  (0, import_node_fs49.writeFileSync)(temp, `${canonicalJson(value)}
76911
77315
  `, { encoding: "utf8", flag: "wx" });
@@ -76952,7 +77356,7 @@ function assertSameVolume(a, b) {
76952
77356
  }
76953
77357
  function uniqueArtifact(dir, label2, livePath) {
76954
77358
  (0, import_node_fs49.mkdirSync)(dir, { recursive: true });
76955
- return (0, import_node_path46.join)(dir, `.floless-${label2}-${(0, import_node_crypto32.randomUUID)()}-${(0, import_node_path46.basename)(livePath)}`);
77359
+ return (0, import_node_path46.join)(dir, `.floless-${label2}-${(0, import_node_crypto33.randomUUID)()}-${(0, import_node_path46.basename)(livePath)}`);
76956
77360
  }
76957
77361
  function publishFileExclusive(input) {
76958
77362
  const { livePath, stagedPath, expectedLive, artifactDir } = input;
@@ -77051,7 +77455,7 @@ function withAppSourceLock(appId, label2, fn, options = {}) {
77051
77455
  }
77052
77456
 
77053
77457
  // app-publication-manifest.ts
77054
- var import_node_crypto33 = require("node:crypto");
77458
+ var import_node_crypto34 = require("node:crypto");
77055
77459
  var import_node_fs51 = require("node:fs");
77056
77460
  var import_yaml7 = __toESM(require_dist6(), 1);
77057
77461
  var APP_PUBLICATION_MANIFEST_SCHEMA = 1;
@@ -77123,7 +77527,7 @@ function bootstrapAppPublicationManifest(input) {
77123
77527
  const observed2 = observeAppPublication(input.sourcePath, input.lockPath);
77124
77528
  const rebound = {
77125
77529
  schema: APP_PUBLICATION_MANIFEST_SCHEMA,
77126
- publicationId: (0, import_node_crypto33.randomUUID)(),
77530
+ publicationId: (0, import_node_crypto34.randomUUID)(),
77127
77531
  appId: input.appId,
77128
77532
  generation: 0,
77129
77533
  state: observed2.coherent ? "ready-clean" : "ready-dirty",
@@ -77144,7 +77548,7 @@ function bootstrapAppPublicationManifest(input) {
77144
77548
  const observed = observeAppPublication(input.sourcePath, input.lockPath);
77145
77549
  const manifest = {
77146
77550
  schema: APP_PUBLICATION_MANIFEST_SCHEMA,
77147
- publicationId: (0, import_node_crypto33.randomUUID)(),
77551
+ publicationId: (0, import_node_crypto34.randomUUID)(),
77148
77552
  appId: input.appId,
77149
77553
  generation: 0,
77150
77554
  state: observed.coherent ? "ready-clean" : "ready-dirty",
@@ -77292,7 +77696,7 @@ function withAppPublicationWhileProjectLocked(input) {
77292
77696
  }
77293
77697
 
77294
77698
  // approval-app-publication.ts
77295
- var import_node_crypto34 = require("node:crypto");
77699
+ var import_node_crypto35 = require("node:crypto");
77296
77700
  var import_node_fs52 = require("node:fs");
77297
77701
  var import_node_path49 = require("node:path");
77298
77702
  var JOURNAL = ".floless-approval-publication-journal-v1.json";
@@ -77336,7 +77740,7 @@ function readApprovalPublicationJournal(sourcePath2) {
77336
77740
  }
77337
77741
  async function stageApprovalPublication(input) {
77338
77742
  const appRoot = (0, import_node_path49.dirname)(input.sourcePath);
77339
- const id = (0, import_node_crypto34.randomUUID)();
77743
+ const id = (0, import_node_crypto35.randomUUID)();
77340
77744
  const stageDir = (0, import_node_path49.join)(stagingRoot2(input.sourcePath), `${input.appId}-${id}`);
77341
77745
  const stagedAppRoot = (0, import_node_path49.join)(stageDir, "app");
77342
77746
  let stagedSourcePath = "";
@@ -79334,7 +79738,7 @@ async function teklaVersionToBake() {
79334
79738
  }
79335
79739
 
79336
79740
  // export-companion.ts
79337
- var import_node_crypto35 = require("node:crypto");
79741
+ var import_node_crypto36 = require("node:crypto");
79338
79742
  var import_node_fs57 = require("node:fs");
79339
79743
  var import_node_path52 = require("node:path");
79340
79744
  var PREFIX2 = "floless-export-tmp-";
@@ -79365,7 +79769,7 @@ function removeScratch(path, appsRoot) {
79365
79769
  }
79366
79770
  function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
79367
79771
  const safeOwner = ownerId.replace(/[^a-z0-9._-]/gi, "-").slice(0, 80) || "app";
79368
- const token2 = (0, import_node_crypto35.randomUUID)();
79772
+ const token2 = (0, import_node_crypto36.randomUUID)();
79369
79773
  const id = `${PREFIX2}${safeOwner}-${sink}-${token2}`;
79370
79774
  const root6 = (0, import_node_path52.resolve)(appsRoot);
79371
79775
  const path = (0, import_node_path52.resolve)(root6, id);
@@ -80405,7 +80809,7 @@ var defaultDeps = {
80405
80809
  onChange: (id, snapshot) => broadcast({ type: "trigger-session-changed", id, snapshot }),
80406
80810
  onReport: (id, workflow, report) => broadcast({ type: "trigger-report", id, workflow, nodeId: report.nodeId, html: report.html })
80407
80811
  };
80408
- var sessions = /* @__PURE__ */ new Map();
80812
+ var sessions2 = /* @__PURE__ */ new Map();
80409
80813
  var sessionOperations = /* @__PURE__ */ new Map();
80410
80814
  function serializeSession(id, operation) {
80411
80815
  const prior = sessionOperations.get(id) ?? Promise.resolve();
@@ -80424,7 +80828,7 @@ function isLive(s) {
80424
80828
  return s.handle !== null && s.snapshot.state === "listening";
80425
80829
  }
80426
80830
  function hostWatcherActive(exceptId) {
80427
- for (const [id, s] of sessions) {
80831
+ for (const [id, s] of sessions2) {
80428
80832
  if (id !== exceptId && s.spec.hostBacked && isLive(s)) return true;
80429
80833
  }
80430
80834
  return false;
@@ -80444,15 +80848,15 @@ async function startSessionUnlocked(spec, deps) {
80444
80848
  if (spec.hostBacked && hostWatcherActive(spec.id)) {
80445
80849
  return { ok: false, reason: "another host watcher is live \u2014 stop it first (one live model = one watcher)" };
80446
80850
  }
80447
- const prior = sessions.get(spec.id);
80851
+ const prior = sessions2.get(spec.id);
80448
80852
  if (prior?.handle) await prior.handle.stop();
80449
80853
  const session = {
80450
80854
  spec,
80451
80855
  handle: null,
80452
80856
  snapshot: { state: "listening", firedCount: 0, lastEvent: null, error: null }
80453
80857
  };
80454
- sessions.set(spec.id, session);
80455
- const current = () => sessions.get(spec.id) === session;
80858
+ sessions2.set(spec.id, session);
80859
+ const current = () => sessions2.get(spec.id) === session;
80456
80860
  const emit = () => {
80457
80861
  if (current()) deps.onChange(spec.id, session.snapshot);
80458
80862
  };
@@ -80496,7 +80900,7 @@ async function stopSession(id) {
80496
80900
  await serializeSession(id, () => stopSessionUnlocked(id));
80497
80901
  }
80498
80902
  async function stopSessionUnlocked(id) {
80499
- const s = sessions.get(id);
80903
+ const s = sessions2.get(id);
80500
80904
  if (!s) return;
80501
80905
  const handle = s.handle;
80502
80906
  s.handle = null;
@@ -80505,14 +80909,14 @@ async function stopSessionUnlocked(id) {
80505
80909
  if (handle) await handle.stop();
80506
80910
  }
80507
80911
  function getSnapshot(id) {
80508
- return sessions.get(id)?.snapshot ?? null;
80912
+ return sessions2.get(id)?.snapshot ?? null;
80509
80913
  }
80510
80914
  async function stopAllSessions() {
80511
80915
  while (sessionOperations.size > 0) {
80512
80916
  await Promise.allSettled([...sessionOperations.values()]);
80513
80917
  }
80514
- await Promise.all([...sessions.keys()].map((id) => stopSession(id)));
80515
- sessions.clear();
80918
+ await Promise.all([...sessions2.keys()].map((id) => stopSession(id)));
80919
+ sessions2.clear();
80516
80920
  }
80517
80921
 
80518
80922
  // routines.ts
@@ -81843,7 +82247,7 @@ function unregisterAutostart() {
81843
82247
 
81844
82248
  // updater.ts
81845
82249
  var import_node_child_process11 = require("node:child_process");
81846
- var import_node_crypto36 = require("node:crypto");
82250
+ var import_node_crypto37 = require("node:crypto");
81847
82251
  var import_node_fs66 = require("node:fs");
81848
82252
  var import_node_stream3 = require("node:stream");
81849
82253
  var import_promises5 = require("node:stream/promises");
@@ -82000,7 +82404,7 @@ async function checkForUpdate() {
82000
82404
  return { supported: true, currentVersion: cur, updateAvailable: true, targetVersion: latest.Version, asset: latest };
82001
82405
  }
82002
82406
  async function sha1OfFile(path) {
82003
- const hash3 = (0, import_node_crypto36.createHash)("sha1");
82407
+ const hash3 = (0, import_node_crypto37.createHash)("sha1");
82004
82408
  await (0, import_promises5.pipeline)((0, import_node_fs66.createReadStream)(path), hash3);
82005
82409
  return hash3.digest("hex").toUpperCase();
82006
82410
  }
@@ -82684,7 +83088,7 @@ if (entry === "launch.mjs") {
82684
83088
 
82685
83089
  // aware-update.ts
82686
83090
  var import_promises6 = require("node:fs/promises");
82687
- var import_node_crypto37 = require("node:crypto");
83091
+ var import_node_crypto38 = require("node:crypto");
82688
83092
  var import_node_path62 = require("node:path");
82689
83093
  var REGISTRY_LATEST = "https://registry.npmjs.org/@aware-aeco/cli/latest";
82690
83094
  var FEED_TIMEOUT_MS2 = 15e3;
@@ -82824,7 +83228,7 @@ function validateMarker(value) {
82824
83228
  function createMaintenanceMarkerStore(markerPath2, options = {}) {
82825
83229
  const io = options.io ?? nodeMarkerIo;
82826
83230
  const maxBytes = Math.min(options.maxBytes ?? MARKER_MAX_BYTES, MARKER_MAX_BYTES);
82827
- const randomId = options.randomId ?? import_node_crypto37.randomUUID;
83231
+ const randomId = options.randomId ?? import_node_crypto38.randomUUID;
82828
83232
  const directory = (0, import_node_path62.dirname)(markerPath2);
82829
83233
  return {
82830
83234
  async read() {
@@ -82882,7 +83286,7 @@ function validatePending(value) {
82882
83286
  }
82883
83287
  function createBridgePendingStore(pendingPath, options = {}) {
82884
83288
  const io = options.io ?? nodeMarkerIo;
82885
- const randomId = options.randomId ?? import_node_crypto37.randomUUID;
83289
+ const randomId = options.randomId ?? import_node_crypto38.randomUUID;
82886
83290
  const directory = (0, import_node_path62.dirname)(pendingPath);
82887
83291
  return {
82888
83292
  async read() {
@@ -84008,12 +84412,12 @@ function registerDebugNodeRoute(app, deps) {
84008
84412
  var import_node_child_process14 = require("node:child_process");
84009
84413
  var import_node_child_process15 = require("node:child_process");
84010
84414
  var import_node_fs71 = require("node:fs");
84011
- var import_node_crypto39 = require("node:crypto");
84415
+ var import_node_crypto40 = require("node:crypto");
84012
84416
  var import_node_os36 = require("node:os");
84013
84417
  var import_node_path67 = require("node:path");
84014
84418
 
84015
84419
  // run-file-relay.ts
84016
- var import_node_crypto38 = require("node:crypto");
84420
+ var import_node_crypto39 = require("node:crypto");
84017
84421
  var import_node_fs68 = require("node:fs");
84018
84422
  var import_node_path64 = require("node:path");
84019
84423
  var import_yaml11 = __toESM(require_dist6(), 1);
@@ -84052,7 +84456,7 @@ function createRunFileRelay(options) {
84052
84456
  }
84053
84457
  const parsedCandidate = parseWorkflow(candidate, options.nodeId);
84054
84458
  assertOnlyTargetChanged(before.parsed, parsedCandidate, options.nodeId);
84055
- const validateRoot = (0, import_node_path64.join)(options.journalRoot, `.validate-${safeLease2(options.leaseId)}-${(0, import_node_crypto38.randomUUID)()}`);
84459
+ const validateRoot = (0, import_node_path64.join)(options.journalRoot, `.validate-${safeLease2(options.leaseId)}-${(0, import_node_crypto39.randomUUID)()}`);
84056
84460
  const validateAppDir = (0, import_node_path64.join)(validateRoot, options.appId);
84057
84461
  const validateSourcePath = (0, import_node_path64.join)(validateAppDir, `${options.appId}.flo`);
84058
84462
  (0, import_node_fs68.mkdirSync)(validateAppDir, { recursive: true, mode: 448 });
@@ -84599,7 +85003,7 @@ function structural(value) {
84599
85003
  return JSON.stringify(value);
84600
85004
  }
84601
85005
  function hash2(value) {
84602
- return (0, import_node_crypto38.createHash)("sha256").update(value).digest("hex");
85006
+ return (0, import_node_crypto39.createHash)("sha256").update(value).digest("hex");
84603
85007
  }
84604
85008
  function readRegularFile(path, maxBytes, label2) {
84605
85009
  rejectLink2(path, label2);
@@ -84609,7 +85013,7 @@ function readRegularFile(path, maxBytes, label2) {
84609
85013
  return (0, import_node_fs68.readFileSync)(path);
84610
85014
  }
84611
85015
  function durableWrite3(path, value) {
84612
- const tmp = `${path}.${process.pid}.${(0, import_node_crypto38.randomUUID)()}.tmp`;
85016
+ const tmp = `${path}.${process.pid}.${(0, import_node_crypto39.randomUUID)()}.tmp`;
84613
85017
  const fd2 = (0, import_node_fs68.openSync)(tmp, "wx", 384);
84614
85018
  try {
84615
85019
  (0, import_node_fs68.writeFileSync)(fd2, value);
@@ -84622,7 +85026,7 @@ function durableWrite3(path, value) {
84622
85026
  syncDirectoryBestEffort((0, import_node_path64.dirname)(path));
84623
85027
  }
84624
85028
  function durableReplace4(path, value) {
84625
- const tmp = `${path}.${process.pid}.${(0, import_node_crypto38.randomUUID)()}.tmp`;
85029
+ const tmp = `${path}.${process.pid}.${(0, import_node_crypto39.randomUUID)()}.tmp`;
84626
85030
  const fd2 = (0, import_node_fs68.openSync)(tmp, "wx", 384);
84627
85031
  try {
84628
85032
  (0, import_node_fs68.writeFileSync)(fd2, value);
@@ -85163,7 +85567,7 @@ function verifyRevisionSources(deps, lease) {
85163
85567
  const path = (deps.sourcePathFor ?? snapshotPathFor)(req.id, index);
85164
85568
  if (!path || ref.ext.toLowerCase() !== "pdf") throw new Error("the queued revision PDF set no longer matches this run");
85165
85569
  const data = (0, import_node_fs71.readFileSync)(path);
85166
- if (data.length !== ref.bytes || (0, import_node_fs71.statSync)(path).size !== ref.bytes || (0, import_node_crypto39.createHash)("sha256").update(data).digest("hex") !== ref.sha256) {
85570
+ if (data.length !== ref.bytes || (0, import_node_fs71.statSync)(path).size !== ref.bytes || (0, import_node_crypto40.createHash)("sha256").update(data).digest("hex") !== ref.sha256) {
85167
85571
  throw new Error("the queued PDF source changed after this run was claimed");
85168
85572
  }
85169
85573
  });
@@ -85373,7 +85777,7 @@ function registerTerminalRunRoutes(app, deps) {
85373
85777
  if (!folder) {
85374
85778
  return reply.status(409).send({ ok: false, error: "Choose a project folder for headless runs first.", code: "no-folder" });
85375
85779
  }
85376
- const sessionId = runtime === "claude" ? (0, import_node_crypto39.randomUUID)() : null;
85780
+ const sessionId = runtime === "claude" ? (0, import_node_crypto40.randomUUID)() : null;
85377
85781
  try {
85378
85782
  preflightRunAudit();
85379
85783
  } catch (auditError) {
@@ -85800,7 +86204,7 @@ ${base.lastOutput}`.trim()
85800
86204
  try {
85801
86205
  relay.recordFinalApplied({
85802
86206
  exitCode: 0,
85803
- completionSha256: (0, import_node_crypto39.createHash)("sha256").update(out).digest("hex")
86207
+ completionSha256: (0, import_node_crypto40.createHash)("sha256").update(out).digest("hex")
85804
86208
  });
85805
86209
  await withInstalledAppPublication({
85806
86210
  target: appPublicationTarget(lease.appId),
@@ -85879,11 +86283,11 @@ function prose(out) {
85879
86283
  return typeof ev?.result === "string" ? ev.result : "";
85880
86284
  }
85881
86285
  function reconcileRunsOnBoot(deps) {
85882
- bootSweep = sweep(deps);
86286
+ bootSweep = sweep2(deps);
85883
86287
  return bootSweep;
85884
86288
  }
85885
86289
  var bootSweep = Promise.resolve(0);
85886
- async function sweep(deps) {
86290
+ async function sweep2(deps) {
85887
86291
  const leases = listLeases();
85888
86292
  if (!leases.length) return 0;
85889
86293
  const observed = await processStartTimes([
@@ -88047,7 +88451,7 @@ async function startServer() {
88047
88451
  let snapshot = Object.freeze(AWARE_BRIDGE_HOSTS.filter((host) => (marker?.snapshot ?? []).includes(host) || observedHosts.includes(host) || durable?.target === target && durable.hosts.includes(host)));
88048
88452
  let recoveryMarker = {
88049
88453
  schema: 2,
88050
- transaction: marker?.transaction ?? (0, import_node_crypto40.randomUUID)(),
88454
+ transaction: marker?.transaction ?? (0, import_node_crypto41.randomUUID)(),
88051
88455
  stage: "recovery",
88052
88456
  target,
88053
88457
  snapshot,
@@ -90094,7 +90498,7 @@ async function startServer() {
90094
90498
  }
90095
90499
  async function dropExportSourceId(appId, project) {
90096
90500
  const ownerId = project ? await getOrCreateProjectExportSourceId(project) : await getOrCreateWorkflowExportSourceId(appId);
90097
- return deriveDropExportSourceId(project ? "project" : "workflow", ownerId, (0, import_node_crypto40.randomUUID)());
90501
+ return deriveDropExportSourceId(project ? "project" : "workflow", ownerId, (0, import_node_crypto41.randomUUID)());
90098
90502
  }
90099
90503
  function explicitExportSourceSuffix(input) {
90100
90504
  if (input.kind !== "project" || !input.snapshot.source) return "";
@@ -90155,7 +90559,7 @@ async function startServer() {
90155
90559
  index: parseStepData(artifactBytes),
90156
90560
  bytes: artifactBytes
90157
90561
  });
90158
- const expectedContentSha256 = (0, import_node_crypto40.createHash)("sha256").update(artifactBytes).digest("hex");
90562
+ const expectedContentSha256 = (0, import_node_crypto41.createHash)("sha256").update(artifactBytes).digest("hex");
90159
90563
  const transition = project && projectSnapshot && projectSnapshot.version.n !== null ? prepareProjectExport(project, {
90160
90564
  kind: "ifc",
90161
90565
  filename,
@@ -91029,7 +91433,7 @@ async function startServer() {
91029
91433
  (0, import_node_fs73.rmSync)(tempHome, { recursive: true, force: true });
91030
91434
  return reply.status(502).send({ ok: false, error: `build produced output at ${result.agentDir} but no manifest.yaml` });
91031
91435
  }
91032
- const token2 = (0, import_node_crypto40.randomUUID)();
91436
+ const token2 = (0, import_node_crypto41.randomUUID)();
91033
91437
  registerStage(token2, tempHome, result.agentId);
91034
91438
  const preview2 = buildPreview(manifest, sourceKind, sourceRef, token2);
91035
91439
  if ((0, import_node_fs73.existsSync)((0, import_node_path70.join)(graftAgentsDir(), result.agentId))) {