@floless/app 0.128.2 → 0.130.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.2" : void 0,
54983
+ define: true ? "0.130.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.2" : void 0,
54999
+ define: true ? "0.130.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");
@@ -60364,9 +60486,44 @@ function releaseLease(leaseId) {
60364
60486
  }
60365
60487
  return false;
60366
60488
  }
60489
+ function psRejectionIsEmptyMatch(err2) {
60490
+ return err2.code === 1 && !err2.signal && !err2.killed && typeof err2.stdout === "string" && !err2.stdout.trim() && typeof err2.stderr === "string" && !err2.stderr.trim();
60491
+ }
60492
+ function pidProvenDead(pid) {
60493
+ try {
60494
+ process.kill(pid, 0);
60495
+ return false;
60496
+ } catch (e) {
60497
+ return e.code === "ESRCH";
60498
+ }
60499
+ }
60500
+ async function posixStartTimes(wanted, queryPs, provenDead = pidProvenDead) {
60501
+ let stdout;
60502
+ try {
60503
+ stdout = await queryPs(wanted);
60504
+ } catch (err2) {
60505
+ if (!psRejectionIsEmptyMatch(err2)) return null;
60506
+ stdout = "";
60507
+ }
60508
+ const out = /* @__PURE__ */ new Map();
60509
+ const now = Date.now();
60510
+ for (const [pid, secs] of pairs(stdout)) out.set(pid, now - secs * 1e3);
60511
+ for (const pid of wanted) {
60512
+ if (out.has(pid)) continue;
60513
+ if (!provenDead(pid)) return null;
60514
+ }
60515
+ return out;
60516
+ }
60517
+ function psQuery(pids) {
60518
+ return run(
60519
+ "ps",
60520
+ ["-o", "pid=,etimes=", "-p", pids.join(",")],
60521
+ { encoding: "utf8", timeout: 1e4, maxBuffer: 8 * 1024 * 1024 }
60522
+ ).then((r) => r.stdout);
60523
+ }
60367
60524
  async function processStartTimes(pids) {
60368
60525
  const out = /* @__PURE__ */ new Map();
60369
- const wanted = [...new Set(pids)].filter((p) => Number.isInteger(p) && p > 0);
60526
+ const wanted = [...new Set(pids)].filter((p) => Number.isInteger(p) && p > 0 && p <= 2147483647);
60370
60527
  if (!wanted.length) return out;
60371
60528
  try {
60372
60529
  if (WIN) {
@@ -60374,9 +60531,7 @@ async function processStartTimes(pids) {
60374
60531
  const script = `Get-CimInstance Win32_Process -Filter '${filter}' | ForEach-Object { "$($_.ProcessId) $([int64]($_.CreationDate.ToUniversalTime() - [datetime]'1970-01-01').TotalMilliseconds)" }`;
60375
60532
  for (const [pid, t] of pairs(await psLines(script))) out.set(pid, t);
60376
60533
  } else {
60377
- const { stdout } = await run("ps", ["-o", "pid=,etimes=", "-p", wanted.join(",")]);
60378
- const now = Date.now();
60379
- for (const [pid, secs] of pairs(stdout)) out.set(pid, now - secs * 1e3);
60534
+ return await posixStartTimes(wanted, psQuery);
60380
60535
  }
60381
60536
  } catch {
60382
60537
  return null;
@@ -60911,7 +61066,6 @@ var TYPE_SET = {
60911
61066
  "knowledge-adjust": true,
60912
61067
  "knowledge-consult": true
60913
61068
  };
60914
- var REQUEST_TYPES = Object.keys(TYPE_SET);
60915
61069
  function isRequestType(t) {
60916
61070
  return typeof t === "string" && Object.prototype.hasOwnProperty.call(TYPE_SET, t);
60917
61071
  }
@@ -70856,7 +71010,7 @@ function registerSteelPrepassRoute(app, deps) {
70856
71010
  }
70857
71011
 
70858
71012
  // reference-routes.ts
70859
- var import_node_crypto28 = require("node:crypto");
71013
+ var import_node_crypto29 = require("node:crypto");
70860
71014
 
70861
71015
  // reference-import.ts
70862
71016
  var import_node_fs42 = require("node:fs");
@@ -71111,6 +71265,91 @@ function toReferenceObjects(raw) {
71111
71265
  selected: toSelection(raw.selected)
71112
71266
  };
71113
71267
  }
71268
+ var PREVIEW_BATCH_SIZE = 500;
71269
+ var PREVIEW_MAX_OBJECTS = WARN_OBJECTS;
71270
+ function toPreviewObjects(raw) {
71271
+ if (!raw || typeof raw !== "object" || Array.isArray(raw)) return [];
71272
+ const doc = raw;
71273
+ if (!Array.isArray(doc.objects)) return [];
71274
+ const alreadyZUp = doc.frame === FILE_Z_UP;
71275
+ if (!alreadyZUp && doc.frame !== void 0 && doc.frame !== FILE_Y_UP) return [];
71276
+ return doc.objects.filter(renderable).map((o) => ({
71277
+ positions: alreadyZUp ? o.positions : yUpToZUp(o.positions),
71278
+ indices: o.indices
71279
+ }));
71280
+ }
71281
+ var SEGMENT_CONCURRENCY = 2;
71282
+ function createSegmentPump(companionId, sink) {
71283
+ const controller = new AbortController();
71284
+ const seen = /* @__PURE__ */ new Set();
71285
+ let painted = 0;
71286
+ let active2 = 0;
71287
+ let stopped = false;
71288
+ const queue2 = [];
71289
+ const stop = (reason) => {
71290
+ if (stopped) return;
71291
+ stopped = true;
71292
+ queue2.length = 0;
71293
+ controller.abort();
71294
+ try {
71295
+ sink.onStop(reason);
71296
+ } catch {
71297
+ }
71298
+ };
71299
+ const pump = () => {
71300
+ while (!stopped && active2 < SEGMENT_CONCURRENCY && queue2.length) {
71301
+ const job = queue2.shift();
71302
+ active2++;
71303
+ void (async () => {
71304
+ try {
71305
+ const text4 = await aware.readRunArtifact(companionId, job.id, job.runId, { signal: controller.signal });
71306
+ if (stopped) return;
71307
+ const objects = toPreviewObjects(JSON.parse(text4));
71308
+ if (!objects.length) return;
71309
+ if (painted + objects.length > PREVIEW_MAX_OBJECTS) {
71310
+ stop("cap");
71311
+ return;
71312
+ }
71313
+ painted += objects.length;
71314
+ sink.onBatch(objects, { seq: job.seq, painted });
71315
+ } catch (e) {
71316
+ if (!stopped) {
71317
+ console.warn(
71318
+ "[reference] preview segment failed; preview abandoned",
71319
+ { seq: job.seq, artifact: job.id, runId: job.runId, painted, error: e instanceof Error ? e.message : String(e) }
71320
+ );
71321
+ stop("error");
71322
+ }
71323
+ } finally {
71324
+ active2--;
71325
+ pump();
71326
+ }
71327
+ })();
71328
+ }
71329
+ };
71330
+ try {
71331
+ sink.onAbortable?.(() => stop("aborted"));
71332
+ } catch {
71333
+ }
71334
+ return {
71335
+ onRecord(rec) {
71336
+ if (stopped) return;
71337
+ if (rec.phase === "progress-suppressed") {
71338
+ stop("suppressed");
71339
+ return;
71340
+ }
71341
+ if (rec.phase !== "batch") return;
71342
+ const seq = rec.artifact?.seq ?? rec.seq;
71343
+ if (!rec.artifact?.id || typeof seq !== "number" || seen.has(seq)) return;
71344
+ seen.add(seq);
71345
+ queue2.push({ seq, id: rec.artifact.id, runId: rec.runId });
71346
+ pump();
71347
+ },
71348
+ abort(reason) {
71349
+ stop(reason);
71350
+ }
71351
+ };
71352
+ }
71114
71353
  var REFERENCE_DIR = "references";
71115
71354
  var SAFE_NAME = /[^A-Za-z0-9._-]+/g;
71116
71355
  function projectRelativeReferencePath(fileName, taken = /* @__PURE__ */ new Set()) {
@@ -71128,7 +71367,10 @@ function projectRelativeReferencePath(fileName, taken = /* @__PURE__ */ new Set(
71128
71367
  return candidate;
71129
71368
  }
71130
71369
  var readerChain2 = Promise.resolve();
71131
- function writeReaderApp2(companionId, command, ifcPath, filter) {
71370
+ function wantsSegments(command, filter) {
71371
+ return command === "read-model" && !emittedFilter(filter);
71372
+ }
71373
+ function writeReaderApp2(companionId, command, ifcPath, filter, progressive = false) {
71132
71374
  const dir = appPath(companionId);
71133
71375
  (0, import_node_fs42.mkdirSync)(dir, { recursive: true });
71134
71376
  const flo = (0, import_node_path39.join)(dir, `${companionId}.flo`);
@@ -71169,6 +71411,7 @@ function writeReaderApp2(companionId, command, ifcPath, filter) {
71169
71411
  const emit = emittedFilter(filter);
71170
71412
  if (emit?.storeys) lines.push(` storeys: ${JSON.stringify(emit.storeys)}`);
71171
71413
  if (emit?.ifcTypes) lines.push(` ifc-types: ${JSON.stringify(emit.ifcTypes)}`);
71414
+ if (progressive && wantsSegments(command, filter)) lines.push(` batch-size: ${PREVIEW_BATCH_SIZE}`);
71172
71415
  }
71173
71416
  lines.push("");
71174
71417
  (0, import_node_fs42.writeFileSync)(flo, lines.join("\n"));
@@ -71206,8 +71449,9 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71206
71449
  readerChain2 = new Promise((r) => release = r);
71207
71450
  await prev.catch(() => {
71208
71451
  });
71452
+ const pump = opts.preview && wantsSegments(command, opts.filter) ? createSegmentPump(companionId, opts.preview) : null;
71209
71453
  try {
71210
- const flo = writeReaderApp2(companionId, command, ifcPath, opts.filter);
71454
+ const flo = writeReaderApp2(companionId, command, ifcPath, opts.filter, !!pump);
71211
71455
  try {
71212
71456
  await aware.compile(flo);
71213
71457
  } catch (e) {
@@ -71218,7 +71462,12 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71218
71462
  try {
71219
71463
  ({ traceText, runId } = await aware.run(companionId, {
71220
71464
  ticket: opts.ticket,
71221
- timeoutMs: readerRunTimeout(command)
71465
+ timeoutMs: readerRunTimeout(command),
71466
+ // Records arrive on a 100 ms poll of the trace WHILE this await is still pending. Nothing here
71467
+ // waits on the pump: `aware.run` resolves when the reader exits, and the pump is aborted
71468
+ // immediately below rather than drained, so preview work can never make the authoritative
71469
+ // response slower than it is today.
71470
+ ...pump ? { onProgress: (rec) => pump.onRecord(rec) } : {}
71222
71471
  }));
71223
71472
  } catch (e) {
71224
71473
  const reason = e instanceof AwareError ? String(e.detail?.stderr ?? "").trim() : "";
@@ -71246,6 +71495,7 @@ async function runReader2(companionId, command, ifcPath, opts = {}) {
71246
71495
  }
71247
71496
  return artifact;
71248
71497
  } finally {
71498
+ pump?.abort("aborted");
71249
71499
  release();
71250
71500
  }
71251
71501
  }
@@ -71275,8 +71525,126 @@ async function readReferenceModel(companionId, ifcPath, opts = {}) {
71275
71525
  return read2;
71276
71526
  }
71277
71527
 
71278
- // reference-store.ts
71528
+ // reference-progress.ts
71279
71529
  var import_node_crypto27 = require("node:crypto");
71530
+ var MAX_BUFFER_BYTES = 8 * 1024 * 1024;
71531
+ var SESSION_TTL_MS = 10 * 6e4;
71532
+ var UNCLAIMED_TTL_MS = 2 * 6e4;
71533
+ var SWEEP_MS = 3e4;
71534
+ var sessions = /* @__PURE__ */ new Map();
71535
+ function createProgressSession(appId, project) {
71536
+ const id = (0, import_node_crypto27.randomUUID)();
71537
+ sessions.set(id, {
71538
+ id,
71539
+ appId,
71540
+ project,
71541
+ createdAt: Date.now(),
71542
+ seq: 0,
71543
+ buffered: [],
71544
+ bytes: 0,
71545
+ droppedBefore: 0,
71546
+ subscriber: null,
71547
+ terminal: false,
71548
+ onDead: null
71549
+ });
71550
+ return id;
71551
+ }
71552
+ function claimProgressSession(id, appId, project, onDead) {
71553
+ if (!id) return null;
71554
+ const s = sessions.get(id);
71555
+ if (!s || s.terminal || s.onDead || s.appId !== appId || s.project !== project) return null;
71556
+ s.onDead = onDead;
71557
+ return id;
71558
+ }
71559
+ function frameOf(seq, event) {
71560
+ return `id: ${seq}
71561
+ data: ${JSON.stringify(event)}
71562
+
71563
+ `;
71564
+ }
71565
+ function push(s, seq, frame) {
71566
+ if (!s.subscriber) return false;
71567
+ try {
71568
+ s.subscriber.raw.write(frame);
71569
+ return true;
71570
+ } catch {
71571
+ endSubscriber(s);
71572
+ return false;
71573
+ }
71574
+ }
71575
+ function publishProgress(id, event) {
71576
+ const s = sessions.get(id);
71577
+ if (!s || s.terminal) return;
71578
+ const seq = ++s.seq;
71579
+ const frame = frameOf(seq, event);
71580
+ push(s, seq, frame);
71581
+ s.buffered.push({ seq, frame });
71582
+ s.bytes += frame.length;
71583
+ while (s.bytes > MAX_BUFFER_BYTES && s.buffered.length > 1) {
71584
+ const dropped = s.buffered.shift();
71585
+ s.bytes -= dropped.frame.length;
71586
+ s.droppedBefore = dropped.seq;
71587
+ }
71588
+ }
71589
+ function subscribeProgress(id, reply, afterSeq, owner2) {
71590
+ const s = sessions.get(id);
71591
+ if (!s || s.appId !== owner2.appId || s.project !== owner2.project) return false;
71592
+ if (s.subscriber && s.subscriber !== reply) endSubscriber(s);
71593
+ s.subscriber = reply;
71594
+ reply.raw.on("close", () => {
71595
+ if (s.subscriber !== reply) return;
71596
+ s.subscriber = null;
71597
+ if (!s.onDead) closeProgressSession(id, "unsubscribed");
71598
+ });
71599
+ if (afterSeq > 0 && afterSeq < s.droppedBefore) {
71600
+ closeProgressSession(id, "gap");
71601
+ return true;
71602
+ }
71603
+ for (const b of s.buffered) {
71604
+ if (b.seq > afterSeq) push(s, b.seq, b.frame);
71605
+ }
71606
+ if (s.terminal) endSubscriber(s);
71607
+ return true;
71608
+ }
71609
+ function endSubscriber(s) {
71610
+ const sub = s.subscriber;
71611
+ s.subscriber = null;
71612
+ if (!sub) return;
71613
+ try {
71614
+ sub.raw.end();
71615
+ } catch {
71616
+ }
71617
+ }
71618
+ function closeProgressSession(id, reason) {
71619
+ const s = sessions.get(id);
71620
+ if (!s || s.terminal) return;
71621
+ s.terminal = true;
71622
+ const seq = ++s.seq;
71623
+ push(s, seq, frameOf(seq, { type: "stopped", reason }));
71624
+ s.buffered = [];
71625
+ s.bytes = 0;
71626
+ endSubscriber(s);
71627
+ sessions.delete(id);
71628
+ const dead = s.onDead;
71629
+ s.onDead = null;
71630
+ if (dead && reason !== "done" && reason !== "aborted") {
71631
+ try {
71632
+ dead();
71633
+ } catch {
71634
+ }
71635
+ }
71636
+ }
71637
+ var sweep = setInterval(() => {
71638
+ const now = Date.now();
71639
+ for (const [id, s] of [...sessions]) {
71640
+ const ttl = s.onDead ? SESSION_TTL_MS : UNCLAIMED_TTL_MS;
71641
+ if (now - s.createdAt > ttl) closeProgressSession(id, "expired");
71642
+ }
71643
+ }, SWEEP_MS);
71644
+ sweep.unref?.();
71645
+
71646
+ // reference-store.ts
71647
+ var import_node_crypto28 = require("node:crypto");
71280
71648
  var import_node_fs43 = require("node:fs");
71281
71649
  var import_promises4 = require("node:stream/promises");
71282
71650
  var import_node_path40 = require("node:path");
@@ -71312,7 +71680,7 @@ function safeId2(refId2) {
71312
71680
  return s;
71313
71681
  }
71314
71682
  async function hashFile(path) {
71315
- const h = (0, import_node_crypto27.createHash)("sha256");
71683
+ const h = (0, import_node_crypto28.createHash)("sha256");
71316
71684
  await (0, import_promises4.pipeline)((0, import_node_fs43.createReadStream)(path), h);
71317
71685
  return h.digest("hex");
71318
71686
  }
@@ -71506,7 +71874,62 @@ function importRefusal(e) {
71506
71874
  }
71507
71875
  return null;
71508
71876
  }
71877
+ function previewFor(sessionId, appId, project) {
71878
+ let abortPump = null;
71879
+ const id = claimProgressSession(sessionId, appId, project, () => {
71880
+ abortPump?.();
71881
+ });
71882
+ if (!id) return null;
71883
+ return {
71884
+ id,
71885
+ sink: {
71886
+ onAbortable(abort) {
71887
+ abortPump = abort;
71888
+ },
71889
+ onBatch(objects, meta) {
71890
+ publishProgress(id, { type: "batch", objects, painted: meta.painted });
71891
+ },
71892
+ // TERMINAL, AND IMMEDIATE. A client told nothing would keep a progress indicator spinning until
71893
+ // the HTTP result finally landed — which for a suppressed channel or a crossed cap is the whole
71894
+ // remaining duration of the read, i.e. exactly the wait this feature exists to remove.
71895
+ onStop(reason) {
71896
+ closeProgressSession(id, reason);
71897
+ }
71898
+ }
71899
+ };
71900
+ }
71509
71901
  function registerReferenceRoutes(app, deps) {
71902
+ app.post(
71903
+ "/api/steel/:appId/reference/progress",
71904
+ async (req, reply) => {
71905
+ const g = gate2(deps, req.params.appId, req.query.project);
71906
+ if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71907
+ return { ok: true, sessionId: createProgressSession(g.appId, g.project) };
71908
+ }
71909
+ );
71910
+ app.get(
71911
+ "/api/steel/:appId/reference/progress/:sessionId",
71912
+ async (req, reply) => {
71913
+ const g = gate2(deps, req.params.appId, req.query.project);
71914
+ if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71915
+ const header = req.headers["last-event-id"];
71916
+ const raw = (Array.isArray(header) ? header[0] : header) ?? req.query.afterSeq ?? "0";
71917
+ const afterSeq = Number.isFinite(Number(raw)) && Number(raw) >= 0 ? Math.floor(Number(raw)) : 0;
71918
+ reply.raw.writeHead(200, {
71919
+ "Content-Type": "text/event-stream",
71920
+ "Cache-Control": "no-cache, no-transform",
71921
+ Connection: "keep-alive",
71922
+ "X-Accel-Buffering": "no"
71923
+ });
71924
+ if (!subscribeProgress(req.params.sessionId, reply, afterSeq, { appId: g.appId, project: g.project })) {
71925
+ reply.raw.write(`data: ${JSON.stringify({ type: "stopped", reason: "unknown" })}
71926
+
71927
+ `);
71928
+ reply.raw.end();
71929
+ }
71930
+ return reply;
71931
+ }
71932
+ );
71510
71933
  app.post(
71511
71934
  "/api/steel/:appId/reference/probe",
71512
71935
  { bodyLimit: REFERENCE_BODY_LIMIT },
@@ -71559,7 +71982,7 @@ function registerReferenceRoutes(app, deps) {
71559
71982
  const scope = runScope(deps, reply, { detachOnDisconnect: true });
71560
71983
  const g = gate2(deps, req.params.appId, req.query.project);
71561
71984
  if (!g.ok) return reply.status(g.refusal.status).send(g.refusal.body);
71562
- const { sha, name, placement } = req.body ?? {};
71985
+ const { sha, name, placement, progressId: sessionId } = req.body ?? {};
71563
71986
  if (!sha) return reply.status(400).send({ ok: false, error: "probe the file first \u2014 its sha is required" });
71564
71987
  const asked = req.body?.filter;
71565
71988
  const names = (v) => Array.isArray(v) ? v.filter((s) => typeof s === "string" && !!s.trim()) : [];
@@ -71576,7 +71999,7 @@ function registerReferenceRoutes(app, deps) {
71576
71999
  return reply.status(404).send({ ok: false, error: "the uploaded IFC is no longer available \u2014 drop the file again" });
71577
72000
  }
71578
72001
  const displayName = String(name || "model.ifc");
71579
- const id = (0, import_node_crypto28.randomUUID)();
72002
+ const id = (0, import_node_crypto29.randomUUID)();
71580
72003
  let rel;
71581
72004
  try {
71582
72005
  rel = await withLifecycleLock("project", g.project, () => {
@@ -71593,6 +72016,7 @@ function registerReferenceRoutes(app, deps) {
71593
72016
  throw e;
71594
72017
  }
71595
72018
  let committed = false;
72019
+ let preview2 = null;
71596
72020
  const rollback = () => {
71597
72021
  if (committed) return;
71598
72022
  try {
@@ -71615,7 +72039,12 @@ function registerReferenceRoutes(app, deps) {
71615
72039
  error: tooMany(`"${displayName}" would load about ${estimate.toLocaleString("en-US")} objects`, probe)
71616
72040
  });
71617
72041
  }
71618
- const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket(), filter });
72042
+ preview2 = previewFor(sessionId, g.appId, g.project);
72043
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, {
72044
+ ticket: scope.ticket(),
72045
+ filter,
72046
+ ...preview2 ? { preview: preview2.sink } : {}
72047
+ });
71619
72048
  if (scope.gone()) throw new ReferenceImportError("cancelled");
71620
72049
  const missed = unmatchedNames(geometry.selected);
71621
72050
  if (!geometry.objects.length && hasUnmatched(geometry.selected)) {
@@ -71675,6 +72104,7 @@ function registerReferenceRoutes(app, deps) {
71675
72104
  app.log.error({ appId: g.appId, err: e instanceof Error ? e.message : e }, "reference insert failed");
71676
72105
  return reply.status(500).send({ ok: false, error: "could not load that reference model" });
71677
72106
  } finally {
72107
+ if (preview2) closeProgressSession(preview2.id, "done");
71678
72108
  scope.finish();
71679
72109
  }
71680
72110
  }
@@ -71712,8 +72142,14 @@ function registerReferenceRoutes(app, deps) {
71712
72142
  const stored2 = entry2.filter;
71713
72143
  const hit = rebuild ? null : cachedGeometry(g.project, entry2.id, sourceHash, stored2);
71714
72144
  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) };
72145
+ let preview2 = null;
71715
72146
  try {
71716
- const geometry = await deps.reader.readModel(companion(g.appId), abs, { ticket: scope.ticket(), filter: stored2 });
72147
+ preview2 = previewFor(req.query.progressId, g.appId, g.project);
72148
+ const geometry = await deps.reader.readModel(companion(g.appId), abs, {
72149
+ ticket: scope.ticket(),
72150
+ filter: stored2,
72151
+ ...preview2 ? { preview: preview2.sink } : {}
72152
+ });
71717
72153
  const missed = unmatchedNames(geometry.selected);
71718
72154
  if (!geometry.objects.length && hasUnmatched(geometry.selected)) {
71719
72155
  return reply.status(409).send({
@@ -71748,6 +72184,7 @@ function registerReferenceRoutes(app, deps) {
71748
72184
  app.log.error({ appId: g.appId, id: entry2.id, err: e instanceof Error ? e.message : e }, "reference rebuild failed");
71749
72185
  return reply.status(500).send({ ok: false, error: `could not re-read "${entry2.name}"` });
71750
72186
  } finally {
72187
+ if (preview2) closeProgressSession(preview2.id, "done");
71751
72188
  scope.finish();
71752
72189
  }
71753
72190
  }
@@ -76261,7 +76698,7 @@ function buildApprovalReview(input) {
76261
76698
  }
76262
76699
 
76263
76700
  // working-revision-manifest.ts
76264
- var import_node_crypto29 = require("node:crypto");
76701
+ var import_node_crypto30 = require("node:crypto");
76265
76702
  var import_node_fs46 = require("node:fs");
76266
76703
  var import_node_path43 = require("node:path");
76267
76704
  var pathOf = (projectId) => (0, import_node_path43.join)(projectDir(projectId), ".floless-working-revision-state-v1.json");
@@ -76291,7 +76728,7 @@ function ensureWorkingRevisionManifest(input) {
76291
76728
  schema: 1,
76292
76729
  projectUuid: assertProject(input.project),
76293
76730
  publicationIdentity: input.publicationIdentity,
76294
- revisionId: (0, import_node_crypto29.randomUUID)(),
76731
+ revisionId: (0, import_node_crypto30.randomUUID)(),
76295
76732
  epoch: 0,
76296
76733
  source: { kind: "working" },
76297
76734
  workingBase: input.workingBase,
@@ -76312,7 +76749,7 @@ function advanceWorkingRevisionManifest(input) {
76312
76749
  if (current.publicationIdentity !== input.publicationIdentity) throw new Error("working revision belongs to another app publication");
76313
76750
  const body = {
76314
76751
  ...bodyOf(current),
76315
- revisionId: (0, import_node_crypto29.randomUUID)(),
76752
+ revisionId: (0, import_node_crypto30.randomUUID)(),
76316
76753
  epoch: current.epoch + 1,
76317
76754
  source: input.source,
76318
76755
  workingBase: input.workingBase,
@@ -76570,7 +77007,7 @@ function projectApprovalCandidateAccepted(appId, projectId, candidate) {
76570
77007
  }
76571
77008
 
76572
77009
  // project-checkpoints-store.ts
76573
- var import_node_crypto30 = require("node:crypto");
77010
+ var import_node_crypto31 = require("node:crypto");
76574
77011
  var import_node_fs47 = require("node:fs");
76575
77012
  var import_node_path44 = require("node:path");
76576
77013
  var HASH_RE3 = /^[0-9a-f]{64}$/;
@@ -76614,7 +77051,7 @@ function requireIdentity(project) {
76614
77051
  function appendEvent(projectId, event) {
76615
77052
  (0, import_node_fs47.mkdirSync)(root5(projectId), { recursive: true });
76616
77053
  const log2 = readEvents(projectId);
76617
- const row = { ...event, eventId: (0, import_node_crypto30.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
77054
+ const row = { ...event, eventId: (0, import_node_crypto31.randomUUID)(), at: (/* @__PURE__ */ new Date()).toISOString() };
76618
77055
  log2.events.push(row);
76619
77056
  writeJsonAtomic(eventsPath(projectId), log2);
76620
77057
  return row;
@@ -76674,7 +77111,7 @@ function markProjectCheckpoint(project, checkpointId, kind, expectedEventId) {
76674
77111
  }
76675
77112
 
76676
77113
  // export-source.ts
76677
- var import_node_crypto31 = require("node:crypto");
77114
+ var import_node_crypto32 = require("node:crypto");
76678
77115
  var import_node_fs48 = require("node:fs");
76679
77116
  var import_node_os26 = require("node:os");
76680
77117
  var import_node_path45 = require("node:path");
@@ -76761,7 +77198,7 @@ function captureExportSource(projectId, selector = { kind: "latest-approved" },
76761
77198
  }
76762
77199
  const contentHash = hashOf(contract);
76763
77200
  const capturedAt = (/* @__PURE__ */ new Date()).toISOString();
76764
- const handleId = (0, import_node_crypto31.randomUUID)();
77201
+ const handleId = (0, import_node_crypto32.randomUUID)();
76765
77202
  const shortHash = contentHash.slice(0, 8);
76766
77203
  const filenameLabel = kind === "approved" ? `v${approvedVersion}` : kind === "working" ? `Working-DRAFT-${shortHash}` : `Checkpoint-${sourceRef.slice(0, 8)}-DRAFT-${shortHash}`;
76767
77204
  const body = {
@@ -76803,7 +77240,7 @@ function cloneExportHandle(handleId, copies) {
76803
77240
  const created = [];
76804
77241
  try {
76805
77242
  for (let index = 0; index < copies; index++) {
76806
- const value = index === 0 ? original : stored({ ...withoutChecksum(original), handleId: (0, import_node_crypto31.randomUUID)(), resultRefs: [] });
77243
+ const value = index === 0 ? original : stored({ ...withoutChecksum(original), handleId: (0, import_node_crypto32.randomUUID)(), resultRefs: [] });
76807
77244
  if (index > 0) {
76808
77245
  writeJsonAtomic(handlePath(value.handleId), value);
76809
77246
  created.push(value.handleId);
@@ -76874,7 +77311,7 @@ function collectExpiredExportHandles(now = Date.now()) {
76874
77311
  }
76875
77312
 
76876
77313
  // file-publication.ts
76877
- var import_node_crypto32 = require("node:crypto");
77314
+ var import_node_crypto33 = require("node:crypto");
76878
77315
  var import_node_fs49 = require("node:fs");
76879
77316
  var import_node_path46 = require("node:path");
76880
77317
  var FilePublicationError = class extends Error {
@@ -76889,7 +77326,7 @@ var FilePublicationError = class extends Error {
76889
77326
  };
76890
77327
  var proofOfBytes = (bytes) => ({
76891
77328
  bytes: bytes.byteLength,
76892
- sha256: (0, import_node_crypto32.createHash)("sha256").update(bytes).digest("hex")
77329
+ sha256: (0, import_node_crypto33.createHash)("sha256").update(bytes).digest("hex")
76893
77330
  });
76894
77331
  function readFileProof2(path) {
76895
77332
  try {
@@ -76905,7 +77342,7 @@ function fileProofEquals2(a, b) {
76905
77342
  function durableCanonicalJson(path, value) {
76906
77343
  const dir = (0, import_node_path46.dirname)(path);
76907
77344
  (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`);
77345
+ const temp = (0, import_node_path46.join)(dir, `.${(0, import_node_path46.basename)(path)}.${process.pid}.${(0, import_node_crypto33.randomUUID)()}.tmp`);
76909
77346
  try {
76910
77347
  (0, import_node_fs49.writeFileSync)(temp, `${canonicalJson(value)}
76911
77348
  `, { encoding: "utf8", flag: "wx" });
@@ -76952,7 +77389,7 @@ function assertSameVolume(a, b) {
76952
77389
  }
76953
77390
  function uniqueArtifact(dir, label2, livePath) {
76954
77391
  (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)}`);
77392
+ return (0, import_node_path46.join)(dir, `.floless-${label2}-${(0, import_node_crypto33.randomUUID)()}-${(0, import_node_path46.basename)(livePath)}`);
76956
77393
  }
76957
77394
  function publishFileExclusive(input) {
76958
77395
  const { livePath, stagedPath, expectedLive, artifactDir } = input;
@@ -77051,7 +77488,7 @@ function withAppSourceLock(appId, label2, fn, options = {}) {
77051
77488
  }
77052
77489
 
77053
77490
  // app-publication-manifest.ts
77054
- var import_node_crypto33 = require("node:crypto");
77491
+ var import_node_crypto34 = require("node:crypto");
77055
77492
  var import_node_fs51 = require("node:fs");
77056
77493
  var import_yaml7 = __toESM(require_dist6(), 1);
77057
77494
  var APP_PUBLICATION_MANIFEST_SCHEMA = 1;
@@ -77123,7 +77560,7 @@ function bootstrapAppPublicationManifest(input) {
77123
77560
  const observed2 = observeAppPublication(input.sourcePath, input.lockPath);
77124
77561
  const rebound = {
77125
77562
  schema: APP_PUBLICATION_MANIFEST_SCHEMA,
77126
- publicationId: (0, import_node_crypto33.randomUUID)(),
77563
+ publicationId: (0, import_node_crypto34.randomUUID)(),
77127
77564
  appId: input.appId,
77128
77565
  generation: 0,
77129
77566
  state: observed2.coherent ? "ready-clean" : "ready-dirty",
@@ -77144,7 +77581,7 @@ function bootstrapAppPublicationManifest(input) {
77144
77581
  const observed = observeAppPublication(input.sourcePath, input.lockPath);
77145
77582
  const manifest = {
77146
77583
  schema: APP_PUBLICATION_MANIFEST_SCHEMA,
77147
- publicationId: (0, import_node_crypto33.randomUUID)(),
77584
+ publicationId: (0, import_node_crypto34.randomUUID)(),
77148
77585
  appId: input.appId,
77149
77586
  generation: 0,
77150
77587
  state: observed.coherent ? "ready-clean" : "ready-dirty",
@@ -77292,7 +77729,7 @@ function withAppPublicationWhileProjectLocked(input) {
77292
77729
  }
77293
77730
 
77294
77731
  // approval-app-publication.ts
77295
- var import_node_crypto34 = require("node:crypto");
77732
+ var import_node_crypto35 = require("node:crypto");
77296
77733
  var import_node_fs52 = require("node:fs");
77297
77734
  var import_node_path49 = require("node:path");
77298
77735
  var JOURNAL = ".floless-approval-publication-journal-v1.json";
@@ -77336,7 +77773,7 @@ function readApprovalPublicationJournal(sourcePath2) {
77336
77773
  }
77337
77774
  async function stageApprovalPublication(input) {
77338
77775
  const appRoot = (0, import_node_path49.dirname)(input.sourcePath);
77339
- const id = (0, import_node_crypto34.randomUUID)();
77776
+ const id = (0, import_node_crypto35.randomUUID)();
77340
77777
  const stageDir = (0, import_node_path49.join)(stagingRoot2(input.sourcePath), `${input.appId}-${id}`);
77341
77778
  const stagedAppRoot = (0, import_node_path49.join)(stageDir, "app");
77342
77779
  let stagedSourcePath = "";
@@ -79334,7 +79771,7 @@ async function teklaVersionToBake() {
79334
79771
  }
79335
79772
 
79336
79773
  // export-companion.ts
79337
- var import_node_crypto35 = require("node:crypto");
79774
+ var import_node_crypto36 = require("node:crypto");
79338
79775
  var import_node_fs57 = require("node:fs");
79339
79776
  var import_node_path52 = require("node:path");
79340
79777
  var PREFIX2 = "floless-export-tmp-";
@@ -79365,7 +79802,7 @@ function removeScratch(path, appsRoot) {
79365
79802
  }
79366
79803
  function createExportCompanion(ownerId, sink, appsRoot = defaultAppsRoot()) {
79367
79804
  const safeOwner = ownerId.replace(/[^a-z0-9._-]/gi, "-").slice(0, 80) || "app";
79368
- const token2 = (0, import_node_crypto35.randomUUID)();
79805
+ const token2 = (0, import_node_crypto36.randomUUID)();
79369
79806
  const id = `${PREFIX2}${safeOwner}-${sink}-${token2}`;
79370
79807
  const root6 = (0, import_node_path52.resolve)(appsRoot);
79371
79808
  const path = (0, import_node_path52.resolve)(root6, id);
@@ -80405,7 +80842,7 @@ var defaultDeps = {
80405
80842
  onChange: (id, snapshot) => broadcast({ type: "trigger-session-changed", id, snapshot }),
80406
80843
  onReport: (id, workflow, report) => broadcast({ type: "trigger-report", id, workflow, nodeId: report.nodeId, html: report.html })
80407
80844
  };
80408
- var sessions = /* @__PURE__ */ new Map();
80845
+ var sessions2 = /* @__PURE__ */ new Map();
80409
80846
  var sessionOperations = /* @__PURE__ */ new Map();
80410
80847
  function serializeSession(id, operation) {
80411
80848
  const prior = sessionOperations.get(id) ?? Promise.resolve();
@@ -80424,7 +80861,7 @@ function isLive(s) {
80424
80861
  return s.handle !== null && s.snapshot.state === "listening";
80425
80862
  }
80426
80863
  function hostWatcherActive(exceptId) {
80427
- for (const [id, s] of sessions) {
80864
+ for (const [id, s] of sessions2) {
80428
80865
  if (id !== exceptId && s.spec.hostBacked && isLive(s)) return true;
80429
80866
  }
80430
80867
  return false;
@@ -80444,15 +80881,15 @@ async function startSessionUnlocked(spec, deps) {
80444
80881
  if (spec.hostBacked && hostWatcherActive(spec.id)) {
80445
80882
  return { ok: false, reason: "another host watcher is live \u2014 stop it first (one live model = one watcher)" };
80446
80883
  }
80447
- const prior = sessions.get(spec.id);
80884
+ const prior = sessions2.get(spec.id);
80448
80885
  if (prior?.handle) await prior.handle.stop();
80449
80886
  const session = {
80450
80887
  spec,
80451
80888
  handle: null,
80452
80889
  snapshot: { state: "listening", firedCount: 0, lastEvent: null, error: null }
80453
80890
  };
80454
- sessions.set(spec.id, session);
80455
- const current = () => sessions.get(spec.id) === session;
80891
+ sessions2.set(spec.id, session);
80892
+ const current = () => sessions2.get(spec.id) === session;
80456
80893
  const emit = () => {
80457
80894
  if (current()) deps.onChange(spec.id, session.snapshot);
80458
80895
  };
@@ -80496,7 +80933,7 @@ async function stopSession(id) {
80496
80933
  await serializeSession(id, () => stopSessionUnlocked(id));
80497
80934
  }
80498
80935
  async function stopSessionUnlocked(id) {
80499
- const s = sessions.get(id);
80936
+ const s = sessions2.get(id);
80500
80937
  if (!s) return;
80501
80938
  const handle = s.handle;
80502
80939
  s.handle = null;
@@ -80505,14 +80942,14 @@ async function stopSessionUnlocked(id) {
80505
80942
  if (handle) await handle.stop();
80506
80943
  }
80507
80944
  function getSnapshot(id) {
80508
- return sessions.get(id)?.snapshot ?? null;
80945
+ return sessions2.get(id)?.snapshot ?? null;
80509
80946
  }
80510
80947
  async function stopAllSessions() {
80511
80948
  while (sessionOperations.size > 0) {
80512
80949
  await Promise.allSettled([...sessionOperations.values()]);
80513
80950
  }
80514
- await Promise.all([...sessions.keys()].map((id) => stopSession(id)));
80515
- sessions.clear();
80951
+ await Promise.all([...sessions2.keys()].map((id) => stopSession(id)));
80952
+ sessions2.clear();
80516
80953
  }
80517
80954
 
80518
80955
  // routines.ts
@@ -81843,7 +82280,7 @@ function unregisterAutostart() {
81843
82280
 
81844
82281
  // updater.ts
81845
82282
  var import_node_child_process11 = require("node:child_process");
81846
- var import_node_crypto36 = require("node:crypto");
82283
+ var import_node_crypto37 = require("node:crypto");
81847
82284
  var import_node_fs66 = require("node:fs");
81848
82285
  var import_node_stream3 = require("node:stream");
81849
82286
  var import_promises5 = require("node:stream/promises");
@@ -82000,7 +82437,7 @@ async function checkForUpdate() {
82000
82437
  return { supported: true, currentVersion: cur, updateAvailable: true, targetVersion: latest.Version, asset: latest };
82001
82438
  }
82002
82439
  async function sha1OfFile(path) {
82003
- const hash3 = (0, import_node_crypto36.createHash)("sha1");
82440
+ const hash3 = (0, import_node_crypto37.createHash)("sha1");
82004
82441
  await (0, import_promises5.pipeline)((0, import_node_fs66.createReadStream)(path), hash3);
82005
82442
  return hash3.digest("hex").toUpperCase();
82006
82443
  }
@@ -82684,7 +83121,7 @@ if (entry === "launch.mjs") {
82684
83121
 
82685
83122
  // aware-update.ts
82686
83123
  var import_promises6 = require("node:fs/promises");
82687
- var import_node_crypto37 = require("node:crypto");
83124
+ var import_node_crypto38 = require("node:crypto");
82688
83125
  var import_node_path62 = require("node:path");
82689
83126
  var REGISTRY_LATEST = "https://registry.npmjs.org/@aware-aeco/cli/latest";
82690
83127
  var FEED_TIMEOUT_MS2 = 15e3;
@@ -82824,7 +83261,7 @@ function validateMarker(value) {
82824
83261
  function createMaintenanceMarkerStore(markerPath2, options = {}) {
82825
83262
  const io = options.io ?? nodeMarkerIo;
82826
83263
  const maxBytes = Math.min(options.maxBytes ?? MARKER_MAX_BYTES, MARKER_MAX_BYTES);
82827
- const randomId = options.randomId ?? import_node_crypto37.randomUUID;
83264
+ const randomId = options.randomId ?? import_node_crypto38.randomUUID;
82828
83265
  const directory = (0, import_node_path62.dirname)(markerPath2);
82829
83266
  return {
82830
83267
  async read() {
@@ -82882,7 +83319,7 @@ function validatePending(value) {
82882
83319
  }
82883
83320
  function createBridgePendingStore(pendingPath, options = {}) {
82884
83321
  const io = options.io ?? nodeMarkerIo;
82885
- const randomId = options.randomId ?? import_node_crypto37.randomUUID;
83322
+ const randomId = options.randomId ?? import_node_crypto38.randomUUID;
82886
83323
  const directory = (0, import_node_path62.dirname)(pendingPath);
82887
83324
  return {
82888
83325
  async read() {
@@ -84008,12 +84445,12 @@ function registerDebugNodeRoute(app, deps) {
84008
84445
  var import_node_child_process14 = require("node:child_process");
84009
84446
  var import_node_child_process15 = require("node:child_process");
84010
84447
  var import_node_fs71 = require("node:fs");
84011
- var import_node_crypto39 = require("node:crypto");
84448
+ var import_node_crypto40 = require("node:crypto");
84012
84449
  var import_node_os36 = require("node:os");
84013
84450
  var import_node_path67 = require("node:path");
84014
84451
 
84015
84452
  // run-file-relay.ts
84016
- var import_node_crypto38 = require("node:crypto");
84453
+ var import_node_crypto39 = require("node:crypto");
84017
84454
  var import_node_fs68 = require("node:fs");
84018
84455
  var import_node_path64 = require("node:path");
84019
84456
  var import_yaml11 = __toESM(require_dist6(), 1);
@@ -84052,7 +84489,7 @@ function createRunFileRelay(options) {
84052
84489
  }
84053
84490
  const parsedCandidate = parseWorkflow(candidate, options.nodeId);
84054
84491
  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)()}`);
84492
+ const validateRoot = (0, import_node_path64.join)(options.journalRoot, `.validate-${safeLease2(options.leaseId)}-${(0, import_node_crypto39.randomUUID)()}`);
84056
84493
  const validateAppDir = (0, import_node_path64.join)(validateRoot, options.appId);
84057
84494
  const validateSourcePath = (0, import_node_path64.join)(validateAppDir, `${options.appId}.flo`);
84058
84495
  (0, import_node_fs68.mkdirSync)(validateAppDir, { recursive: true, mode: 448 });
@@ -84599,7 +85036,7 @@ function structural(value) {
84599
85036
  return JSON.stringify(value);
84600
85037
  }
84601
85038
  function hash2(value) {
84602
- return (0, import_node_crypto38.createHash)("sha256").update(value).digest("hex");
85039
+ return (0, import_node_crypto39.createHash)("sha256").update(value).digest("hex");
84603
85040
  }
84604
85041
  function readRegularFile(path, maxBytes, label2) {
84605
85042
  rejectLink2(path, label2);
@@ -84609,7 +85046,7 @@ function readRegularFile(path, maxBytes, label2) {
84609
85046
  return (0, import_node_fs68.readFileSync)(path);
84610
85047
  }
84611
85048
  function durableWrite3(path, value) {
84612
- const tmp = `${path}.${process.pid}.${(0, import_node_crypto38.randomUUID)()}.tmp`;
85049
+ const tmp = `${path}.${process.pid}.${(0, import_node_crypto39.randomUUID)()}.tmp`;
84613
85050
  const fd2 = (0, import_node_fs68.openSync)(tmp, "wx", 384);
84614
85051
  try {
84615
85052
  (0, import_node_fs68.writeFileSync)(fd2, value);
@@ -84622,7 +85059,7 @@ function durableWrite3(path, value) {
84622
85059
  syncDirectoryBestEffort((0, import_node_path64.dirname)(path));
84623
85060
  }
84624
85061
  function durableReplace4(path, value) {
84625
- const tmp = `${path}.${process.pid}.${(0, import_node_crypto38.randomUUID)()}.tmp`;
85062
+ const tmp = `${path}.${process.pid}.${(0, import_node_crypto39.randomUUID)()}.tmp`;
84626
85063
  const fd2 = (0, import_node_fs68.openSync)(tmp, "wx", 384);
84627
85064
  try {
84628
85065
  (0, import_node_fs68.writeFileSync)(fd2, value);
@@ -85163,7 +85600,7 @@ function verifyRevisionSources(deps, lease) {
85163
85600
  const path = (deps.sourcePathFor ?? snapshotPathFor)(req.id, index);
85164
85601
  if (!path || ref.ext.toLowerCase() !== "pdf") throw new Error("the queued revision PDF set no longer matches this run");
85165
85602
  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) {
85603
+ 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
85604
  throw new Error("the queued PDF source changed after this run was claimed");
85168
85605
  }
85169
85606
  });
@@ -85373,7 +85810,7 @@ function registerTerminalRunRoutes(app, deps) {
85373
85810
  if (!folder) {
85374
85811
  return reply.status(409).send({ ok: false, error: "Choose a project folder for headless runs first.", code: "no-folder" });
85375
85812
  }
85376
- const sessionId = runtime === "claude" ? (0, import_node_crypto39.randomUUID)() : null;
85813
+ const sessionId = runtime === "claude" ? (0, import_node_crypto40.randomUUID)() : null;
85377
85814
  try {
85378
85815
  preflightRunAudit();
85379
85816
  } catch (auditError) {
@@ -85800,7 +86237,7 @@ ${base.lastOutput}`.trim()
85800
86237
  try {
85801
86238
  relay.recordFinalApplied({
85802
86239
  exitCode: 0,
85803
- completionSha256: (0, import_node_crypto39.createHash)("sha256").update(out).digest("hex")
86240
+ completionSha256: (0, import_node_crypto40.createHash)("sha256").update(out).digest("hex")
85804
86241
  });
85805
86242
  await withInstalledAppPublication({
85806
86243
  target: appPublicationTarget(lease.appId),
@@ -85879,11 +86316,11 @@ function prose(out) {
85879
86316
  return typeof ev?.result === "string" ? ev.result : "";
85880
86317
  }
85881
86318
  function reconcileRunsOnBoot(deps) {
85882
- bootSweep = sweep(deps);
86319
+ bootSweep = sweep2(deps);
85883
86320
  return bootSweep;
85884
86321
  }
85885
86322
  var bootSweep = Promise.resolve(0);
85886
- async function sweep(deps) {
86323
+ async function sweep2(deps) {
85887
86324
  const leases = listLeases();
85888
86325
  if (!leases.length) return 0;
85889
86326
  const observed = await processStartTimes([
@@ -88047,7 +88484,7 @@ async function startServer() {
88047
88484
  let snapshot = Object.freeze(AWARE_BRIDGE_HOSTS.filter((host) => (marker?.snapshot ?? []).includes(host) || observedHosts.includes(host) || durable?.target === target && durable.hosts.includes(host)));
88048
88485
  let recoveryMarker = {
88049
88486
  schema: 2,
88050
- transaction: marker?.transaction ?? (0, import_node_crypto40.randomUUID)(),
88487
+ transaction: marker?.transaction ?? (0, import_node_crypto41.randomUUID)(),
88051
88488
  stage: "recovery",
88052
88489
  target,
88053
88490
  snapshot,
@@ -90094,7 +90531,7 @@ async function startServer() {
90094
90531
  }
90095
90532
  async function dropExportSourceId(appId, project) {
90096
90533
  const ownerId = project ? await getOrCreateProjectExportSourceId(project) : await getOrCreateWorkflowExportSourceId(appId);
90097
- return deriveDropExportSourceId(project ? "project" : "workflow", ownerId, (0, import_node_crypto40.randomUUID)());
90534
+ return deriveDropExportSourceId(project ? "project" : "workflow", ownerId, (0, import_node_crypto41.randomUUID)());
90098
90535
  }
90099
90536
  function explicitExportSourceSuffix(input) {
90100
90537
  if (input.kind !== "project" || !input.snapshot.source) return "";
@@ -90155,7 +90592,7 @@ async function startServer() {
90155
90592
  index: parseStepData(artifactBytes),
90156
90593
  bytes: artifactBytes
90157
90594
  });
90158
- const expectedContentSha256 = (0, import_node_crypto40.createHash)("sha256").update(artifactBytes).digest("hex");
90595
+ const expectedContentSha256 = (0, import_node_crypto41.createHash)("sha256").update(artifactBytes).digest("hex");
90159
90596
  const transition = project && projectSnapshot && projectSnapshot.version.n !== null ? prepareProjectExport(project, {
90160
90597
  kind: "ifc",
90161
90598
  filename,
@@ -91029,7 +91466,7 @@ async function startServer() {
91029
91466
  (0, import_node_fs73.rmSync)(tempHome, { recursive: true, force: true });
91030
91467
  return reply.status(502).send({ ok: false, error: `build produced output at ${result.agentDir} but no manifest.yaml` });
91031
91468
  }
91032
- const token2 = (0, import_node_crypto40.randomUUID)();
91469
+ const token2 = (0, import_node_crypto41.randomUUID)();
91033
91470
  registerStage(token2, tempHome, result.agentId);
91034
91471
  const preview2 = buildPreview(manifest, sourceKind, sourceRef, token2);
91035
91472
  if ((0, import_node_fs73.existsSync)((0, import_node_path70.join)(graftAgentsDir(), result.agentId))) {