@camstack/addon-pipeline-orchestrator 1.2.654 → 1.2.655

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.mjs CHANGED
@@ -5984,7 +5984,7 @@ var ZodIssueCode = {
5984
5984
  var ZodFirstPartyTypeKind;
5985
5985
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5986
5986
  //#endregion
5987
- //#region ../types/dist/sleep-BKClVk0K.mjs
5987
+ //#region ../types/dist/sleep-DV4qxEyD.mjs
5988
5988
  /**
5989
5989
  * The audio chunk plane's byte format, and the ONE expansion from a coded
5990
5990
  * window to float samples (D455).
@@ -8088,6 +8088,10 @@ var BaseAddon = class {
8088
8088
  const stored = keychain ? await this.readAddonStoreWithRetry() : {};
8089
8089
  const patch = {};
8090
8090
  for (const key of keys) {
8091
+ if (tree.get(key)?.kind === "array") {
8092
+ patch[key] = [];
8093
+ continue;
8094
+ }
8091
8095
  const keychainStored = tree.has(key) || collectSecretMarkerRefs(stored[key]).length > 0;
8092
8096
  patch[key] = keychain && keychainStored ? SECRET_CLEAR : "";
8093
8097
  }
@@ -94805,9 +94809,114 @@ async function readRawKeys(read, addonId, keys) {
94805
94809
  return found;
94806
94810
  }
94807
94811
  //#endregion
94812
+ //#region src/migrations/blob-to-rows.ts
94813
+ /**
94814
+ * The orchestrator's three id-keyed JSON maps become one row per id (D986 §2):
94815
+ *
94816
+ * - `nodeBindings` and `agentSettings` (a map keyed on node id) become node rows
94817
+ * `<addonId>.<field>@<nodeId>` in `addon-settings`, carrying `nodeId`;
94818
+ * - `cameraSettings` (a map keyed on device id) becomes one device row
94819
+ * `<addonId>:<deviceId>.cameraSettings` in `addon-device-settings`.
94820
+ *
94821
+ * Each entry is copied VERBATIM (the value of a row is the entry the map held), so a field the
94822
+ * schema does not know yet survives byte for byte. The map key stays for a release (the purge is
94823
+ * `retired-settings-keys.ts`, one release later), so a rolled-back build still reads it.
94824
+ *
94825
+ * A row that already exists is never overwritten: it was written by the build that reads rows,
94826
+ * and a seed never overwrites. A plan that has nothing left to copy is empty, so a second run is
94827
+ * a no-op. A read that fails throws, and nothing is written. A map whose shape is not a map of
94828
+ * objects throws too: copying part of it would leave the readers with a half-moved store.
94829
+ */
94830
+ /** The per-device settings table: one row per field, id `<addonId>:<deviceId>.<field>`. */
94831
+ var ADDON_DEVICE_SETTINGS_TABLE = "addon-device-settings";
94832
+ var isRecord = (value) => typeof value === "object" && value !== null && !Array.isArray(value);
94833
+ /** A node id the orchestrator itself refuses to persist (`writeAgentSettings`): never a real node. */
94834
+ var GHOST_NODE_IDS = new Set([
94835
+ "",
94836
+ "undefined",
94837
+ "null"
94838
+ ]);
94839
+ function entriesOf(field, blob) {
94840
+ if (blob === void 0) return [];
94841
+ if (!isRecord(blob)) throw new Error(`${field} is not a map: it is left as it is`);
94842
+ return Object.entries(blob).map(([id, entry]) => {
94843
+ if (!isRecord(entry)) throw new Error(`${field}[${id}] is not an object: nothing is copied, fix it and retry`);
94844
+ return [id, entry];
94845
+ });
94846
+ }
94847
+ /** Copy each node's entry of `field` to its node row `<field>@<nodeId>`. */
94848
+ async function planBlobToNodeRows(addonId, field, ports) {
94849
+ const blob = (await ports.readStored([field]))[field];
94850
+ const entries = entriesOf(field, blob).filter(([nodeId]) => !GHOST_NODE_IDS.has(nodeId) && !nodeId.includes("@"));
94851
+ if (entries.length === 0) return { edits: [] };
94852
+ const rowKey = (nodeId) => `${field}@${nodeId}`;
94853
+ const existing = await ports.readStored(entries.map(([nodeId]) => rowKey(nodeId)));
94854
+ const values = {};
94855
+ for (const [nodeId, entry] of entries) {
94856
+ if (rowKey(nodeId) in existing) continue;
94857
+ values[`${addonId}.${rowKey(nodeId)}`] = {
94858
+ addonId,
94859
+ key: rowKey(nodeId),
94860
+ value: entry,
94861
+ nodeId
94862
+ };
94863
+ }
94864
+ const ids = Object.keys(values);
94865
+ if (ids.length === 0) return { edits: [] };
94866
+ return { edits: [{
94867
+ op: "setKeys",
94868
+ scope: ADDON_SETTINGS_TABLE,
94869
+ values,
94870
+ precondition: preconditionOf(Object.fromEntries(ids.map((id) => [id, null])))
94871
+ }] };
94872
+ }
94873
+ /** A device id as the blob spells it: a positive integer. */
94874
+ function deviceIdOf(key) {
94875
+ const id = Number(key);
94876
+ return Number.isInteger(id) && id > 0 && String(id) === key ? id : null;
94877
+ }
94878
+ /** Copy each device's entry of `field` to its device row `<addonId>:<deviceId>.<field>`. */
94879
+ async function planBlobToDeviceRows(addonId, field, ports) {
94880
+ const blob = (await ports.readStored([field]))[field];
94881
+ const entries = entriesOf(field, blob).flatMap(([key, entry]) => {
94882
+ const deviceId = deviceIdOf(key);
94883
+ return deviceId === null ? [] : [{
94884
+ deviceId,
94885
+ entry
94886
+ }];
94887
+ });
94888
+ if (entries.length === 0) return { edits: [] };
94889
+ const existing = await ports.readDeviceField(entries.map((e) => e.deviceId), field);
94890
+ const values = {};
94891
+ for (const { deviceId, entry } of entries) {
94892
+ if (existing.has(deviceId)) continue;
94893
+ values[`${addonId}:${deviceId}.${field}`] = {
94894
+ addonId,
94895
+ deviceId: String(deviceId),
94896
+ key: field,
94897
+ value: entry
94898
+ };
94899
+ }
94900
+ const ids = Object.keys(values);
94901
+ if (ids.length === 0) return { edits: [] };
94902
+ return { edits: [{
94903
+ op: "setKeys",
94904
+ scope: ADDON_DEVICE_SETTINGS_TABLE,
94905
+ values,
94906
+ precondition: preconditionOf(Object.fromEntries(ids.map((id) => [id, null])))
94907
+ }] };
94908
+ }
94909
+ //#endregion
94808
94910
  //#region src/migrations/index.ts
94809
94911
  var PIPELINE_ORCHESTRATOR_ID = "pipeline-orchestrator";
94810
94912
  var DROP_BINDINGS_MIGRATION_FLAG_ID = "pipeline-orchestrator/2026-11-03-drop-bindings-migration-flag";
94913
+ var NODE_BINDINGS_TO_NODE_ROWS_ID = "pipeline-orchestrator/2026-11-03-node-bindings-to-node-rows";
94914
+ var AGENT_SETTINGS_TO_NODE_ROWS_ID = "pipeline-orchestrator/2026-11-03-agent-settings-to-node-rows";
94915
+ var CAMERA_SETTINGS_TO_DEVICE_ROWS_ID = "pipeline-orchestrator/2026-11-03-camera-settings-to-device-rows";
94916
+ /** The three id-keyed maps this version stopped reading; their keys stay one release. */
94917
+ var NODE_BINDINGS_FIELD = "nodeBindings";
94918
+ var AGENT_SETTINGS_FIELD = "agentSettings";
94919
+ var CAMERA_SETTINGS_FIELD = "cameraSettings";
94811
94920
  /** The one-shot flag of the retired legacy-flags-to-bindings carry-over; the D987 ledger replaces it. */
94812
94921
  var RETIRED_FLAG_KEYS = ["bindingsMigration_v1_done"];
94813
94922
  /**
@@ -94822,22 +94931,72 @@ async function planDropFlag(ports) {
94822
94931
  return planDropKeys(PIPELINE_ORCHESTRATOR_ID, RETIRED_FLAG_KEYS, ports);
94823
94932
  }
94824
94933
  /** The `pipeline-orchestrator` catalogue (D987): offered to the engine when the addon initialises. */
94825
- var ADDON_MIGRATIONS = [{
94826
- meta: {
94827
- id: DROP_BINDINGS_MIGRATION_FLAG_ID,
94828
- owner: PIPELINE_ORCHESTRATOR_ID,
94829
- level: "addon-state",
94830
- seq: 1,
94831
- dependsOn: [],
94832
- store: "settings",
94833
- scope: "cluster",
94834
- onFailure: "tolerate",
94835
- bodyKind: "plan",
94836
- description: "Delete the one-shot flag of the retired legacy-flags-to-bindings carry-over",
94837
- fixtureMark: "a setting the migration does not know"
94838
- },
94839
- plan: planDropFlag
94840
- }];
94934
+ var ADDON_MIGRATIONS = [
94935
+ {
94936
+ meta: {
94937
+ id: DROP_BINDINGS_MIGRATION_FLAG_ID,
94938
+ owner: PIPELINE_ORCHESTRATOR_ID,
94939
+ level: "addon-state",
94940
+ seq: 1,
94941
+ dependsOn: [],
94942
+ store: "settings",
94943
+ scope: "cluster",
94944
+ onFailure: "tolerate",
94945
+ bodyKind: "plan",
94946
+ description: "Delete the one-shot flag of the retired legacy-flags-to-bindings carry-over",
94947
+ fixtureMark: "a setting the migration does not know"
94948
+ },
94949
+ plan: planDropFlag
94950
+ },
94951
+ {
94952
+ meta: {
94953
+ id: NODE_BINDINGS_TO_NODE_ROWS_ID,
94954
+ owner: PIPELINE_ORCHESTRATOR_ID,
94955
+ level: "addon-state",
94956
+ seq: 2,
94957
+ dependsOn: [],
94958
+ store: "settings",
94959
+ scope: "per-node",
94960
+ onFailure: "block-owner",
94961
+ bodyKind: "plan",
94962
+ description: "Explode the node-keyed nodeBindings map into one node row per node",
94963
+ fixtureMark: "a capability binding of one node, and a node that only this map holds"
94964
+ },
94965
+ plan: (ports) => planBlobToNodeRows(PIPELINE_ORCHESTRATOR_ID, NODE_BINDINGS_FIELD, ports)
94966
+ },
94967
+ {
94968
+ meta: {
94969
+ id: AGENT_SETTINGS_TO_NODE_ROWS_ID,
94970
+ owner: PIPELINE_ORCHESTRATOR_ID,
94971
+ level: "addon-state",
94972
+ seq: 3,
94973
+ dependsOn: [NODE_BINDINGS_TO_NODE_ROWS_ID],
94974
+ store: "settings",
94975
+ scope: "per-node",
94976
+ onFailure: "block-owner",
94977
+ bodyKind: "plan",
94978
+ description: "Explode the node-keyed agentSettings map into one node row per node",
94979
+ fixtureMark: "a detection weight and a pinned model of one node"
94980
+ },
94981
+ plan: (ports) => planBlobToNodeRows(PIPELINE_ORCHESTRATOR_ID, AGENT_SETTINGS_FIELD, ports)
94982
+ },
94983
+ {
94984
+ meta: {
94985
+ id: CAMERA_SETTINGS_TO_DEVICE_ROWS_ID,
94986
+ owner: PIPELINE_ORCHESTRATOR_ID,
94987
+ level: "addon-state",
94988
+ seq: 4,
94989
+ dependsOn: [AGENT_SETTINGS_TO_NODE_ROWS_ID],
94990
+ store: "settings",
94991
+ scope: "cluster",
94992
+ onFailure: "block-owner",
94993
+ bodyKind: "plan",
94994
+ description: "Explode the device-keyed cameraSettings map into one device row per camera",
94995
+ fixtureMark: "a step toggle and a step setting of one camera"
94996
+ },
94997
+ plan: (ports) => planBlobToDeviceRows(PIPELINE_ORCHESTRATOR_ID, CAMERA_SETTINGS_FIELD, ports)
94998
+ }
94999
+ ];
94841
95000
  var orchestratorRecordKinds = defineRecordKinds({
94842
95001
  /**
94843
95002
  * One row per APPLIED failover move. The id is `${deviceId}:${at}`.
@@ -107392,6 +107551,8 @@ async function redispatchAffected(deps, cleared) {
107392
107551
  * schema is kept faithful to the on-disk shape rather than overly strict.
107393
107552
  */
107394
107553
  var NodeBindingsSchema = record(string(), record(string(), string()));
107554
+ /** One node's entry of the map: `capName -> addonId`, the value of its `nodeBindings@<node>` row. */
107555
+ var StoredNodeBindingsSchema = record(string(), string());
107395
107556
  var AutoBenchmarkAttemptsSchema = record(string(), record(string(), object({
107396
107557
  count: number().int().min(0),
107397
107558
  lastAtMs: number()
@@ -107427,6 +107588,118 @@ var StoredCameraPipelineSettingsSchema = object({
107427
107588
  });
107428
107589
  var CameraSettingsMapSchema = record(string(), StoredCameraPipelineSettingsSchema);
107429
107590
  //#endregion
107591
+ //#region src/orchestrator-row-maps.ts
107592
+ /** A node id that is a real one: the orchestrator refuses to persist the others. */
107593
+ var isNodeId = (nodeId) => nodeId.length > 0 && nodeId !== "undefined" && nodeId !== "null" && !nodeId.includes("@");
107594
+ /** One node row per node: `<field>@<nodeId>`. */
107595
+ var NodeRows = class {
107596
+ deps;
107597
+ field;
107598
+ schema;
107599
+ constructor(deps, field, schema) {
107600
+ this.deps = deps;
107601
+ this.field = field;
107602
+ this.schema = schema;
107603
+ }
107604
+ keyOf(nodeId) {
107605
+ return `${this.field}@${nodeId}`;
107606
+ }
107607
+ parse(nodeId, raw) {
107608
+ if (raw === void 0) return void 0;
107609
+ const parsed = this.schema.safeParse(raw);
107610
+ if (parsed.success) return parsed.data;
107611
+ this.deps.logger.warn(`${this.field} row failed validation — ignored`, {
107612
+ tags: { nodeId },
107613
+ meta: {
107614
+ field: this.field,
107615
+ error: parsed.error.message
107616
+ }
107617
+ });
107618
+ }
107619
+ async get(nodeId) {
107620
+ return this.parse(nodeId, (await this.deps.readStore())[this.keyOf(nodeId)]);
107621
+ }
107622
+ /** Every node that has a row, by node id. */
107623
+ async getAll() {
107624
+ const prefix = `${this.field}@`;
107625
+ const out = {};
107626
+ for (const [key, raw] of Object.entries(await this.deps.readStore())) {
107627
+ if (!key.startsWith(prefix)) continue;
107628
+ const nodeId = key.slice(prefix.length);
107629
+ if (!isNodeId(nodeId)) continue;
107630
+ const value = this.parse(nodeId, raw);
107631
+ if (value !== void 0) out[nodeId] = value;
107632
+ }
107633
+ return out;
107634
+ }
107635
+ async set(nodeId, value) {
107636
+ await this.deps.state(this.keyOf(nodeId), this.schema, value).set(value);
107637
+ }
107638
+ /** Delete the node's row; whether one existed. A failed read throws. */
107639
+ async remove(nodeId) {
107640
+ if (!(this.keyOf(nodeId) in await this.deps.readStore())) return false;
107641
+ const optional = this.schema.optional();
107642
+ await this.deps.state(this.keyOf(nodeId), optional, void 0).set(void 0);
107643
+ return true;
107644
+ }
107645
+ /**
107646
+ * Make the rows equal `next` given they held `prev`: a node whose entry changed is written, a
107647
+ * node that is gone is removed, an untouched node is not written at all.
107648
+ */
107649
+ async applyDiff(prev, next) {
107650
+ for (const [nodeId, value] of Object.entries(next)) if (JSON.stringify(prev[nodeId]) !== JSON.stringify(value)) await this.set(nodeId, value);
107651
+ for (const nodeId of Object.keys(prev)) if (!(nodeId in next)) await this.remove(nodeId);
107652
+ }
107653
+ };
107654
+ /** One field of the per-device store, per device. */
107655
+ var DeviceRows = class {
107656
+ deps;
107657
+ field;
107658
+ schema;
107659
+ constructor(deps, field, schema) {
107660
+ this.deps = deps;
107661
+ this.field = field;
107662
+ this.schema = schema;
107663
+ }
107664
+ port() {
107665
+ const port = this.deps.deviceSettings();
107666
+ if (port === null) throw new Error(`${this.field}: the per-device settings store is unavailable`);
107667
+ return port;
107668
+ }
107669
+ parse(deviceId, blob) {
107670
+ const raw = blob[this.field];
107671
+ if (raw === void 0) return void 0;
107672
+ const parsed = this.schema.safeParse(raw);
107673
+ if (parsed.success) return parsed.data;
107674
+ this.deps.logger.warn(`${this.field} row failed validation — ignored`, {
107675
+ tags: { deviceId },
107676
+ meta: {
107677
+ field: this.field,
107678
+ error: parsed.error.message
107679
+ }
107680
+ });
107681
+ }
107682
+ async get(deviceId) {
107683
+ return this.parse(deviceId, await this.port().readDeviceStore(deviceId));
107684
+ }
107685
+ /** Every device that has the field, by device id as a string (the legacy map's key). */
107686
+ async getAll() {
107687
+ const port = this.port();
107688
+ const out = {};
107689
+ for (const [deviceId, blob] of await port.readDeviceStoreBatch(await port.listDeviceStoreIds())) {
107690
+ const value = this.parse(deviceId, blob);
107691
+ if (value !== void 0) out[String(deviceId)] = value;
107692
+ }
107693
+ return out;
107694
+ }
107695
+ async set(deviceId, value) {
107696
+ await this.port().writeDeviceStore(deviceId, { [this.field]: this.schema.parse(value) });
107697
+ }
107698
+ async remove(deviceId) {
107699
+ await this.port().writeDeviceStore(deviceId, { [this.field]: void 0 });
107700
+ }
107701
+ };
107702
+ //#endregion
107430
107703
  //#region src/pipeline-settings-store.ts
107431
107704
  var PIPELINE_EXECUTOR_CAP = "pipeline-executor";
107432
107705
  var PipelineSettingsStore = class PipelineSettingsStore {
@@ -107453,8 +107726,17 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107453
107726
  * UNBOUNDED reconcile (cameras are never dispatched with empty steps).
107454
107727
  */
107455
107728
  static SEED_MAX_RECONCILE_ROUNDS = 4;
107729
+ /** One node row per node: the capability bindings (`nodeBindings@<node>`). */
107730
+ bindingRows;
107731
+ /** One node row per node: the agent settings (`agentSettings@<node>`). */
107732
+ agentRows;
107733
+ /** One device row per camera: the pipeline settings (`cameraSettings` of the device store). */
107734
+ cameraRows;
107456
107735
  constructor(deps) {
107457
107736
  this.deps = deps;
107737
+ this.bindingRows = new NodeRows(deps, "nodeBindings", StoredNodeBindingsSchema);
107738
+ this.agentRows = new NodeRows(deps, "agentSettings", StoredAgentPipelineSettingsSchema);
107739
+ this.cameraRows = new DeviceRows(deps, "cameraSettings", StoredCameraPipelineSettingsSchema);
107458
107740
  }
107459
107741
  disposed = false;
107460
107742
  /** Whether `dispose()` has run — a `null` catalog from a bounded wait means "not answered" only while this is false. */
@@ -107467,66 +107749,38 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107467
107749
  }
107468
107750
  blobWriteLock = new KeyedAsyncLock({ isShuttingDown: () => this.disposed });
107469
107751
  static AGENT_SETTINGS_LOCK_KEY = "agentSettings";
107470
- _nodeBindingsState = null;
107471
- _agentSettingsState = null;
107472
- _cameraSettingsState = null;
107473
- get nodeBindingsState() {
107474
- if (!this._nodeBindingsState) this._nodeBindingsState = this.deps.state("nodeBindings", NodeBindingsSchema, {});
107475
- return this._nodeBindingsState;
107476
- }
107477
- get agentSettingsState() {
107478
- if (!this._agentSettingsState) this._agentSettingsState = this.deps.state("agentSettings", AgentSettingsMapSchema, {});
107479
- return this._agentSettingsState;
107480
- }
107481
- get cameraSettingsState() {
107482
- if (!this._cameraSettingsState) this._cameraSettingsState = this.deps.state("cameraSettings", CameraSettingsMapSchema, {});
107483
- return this._cameraSettingsState;
107484
- }
107752
+ static NODE_BINDINGS_LOCK_KEY = "nodeBindings";
107485
107753
  async getCapabilityBindings(nodeId) {
107486
- const perNodeRaw = (await this.nodeBindingsState.get().catch(() => ({})))[nodeId];
107487
- if (!perNodeRaw || typeof perNodeRaw !== "object") return {};
107488
- const perNode = { ...perNodeRaw };
107754
+ const bindings = await this.bindingRows.get(nodeId).catch(() => void 0);
107755
+ if (!bindings) return {};
107489
107756
  const out = {};
107490
- for (const [capName, addonId] of Object.entries(perNode)) if (typeof addonId === "string" && addonId.length > 0) out[capName] = addonId;
107757
+ for (const [capName, addonId] of Object.entries(bindings)) if (typeof addonId === "string" && addonId.length > 0) out[capName] = addonId;
107491
107758
  return out;
107492
107759
  }
107493
107760
  /**
107494
- * Drop one node's capability bindings. `false` when it had none. Read-modify-
107495
- * write over the whole blob, so a concurrent binding for another node is kept.
107496
- * A failed read propagates: an unanswered read never counts as "nothing there".
107761
+ * Drop one node's capability bindings. `false` when it had none. A failed read
107762
+ * propagates: an unanswered read never counts as "nothing there".
107497
107763
  */
107498
107764
  async removeCapabilityBindings(nodeId) {
107499
107765
  let removed = false;
107500
- await this.nodeBindingsState.update((prev) => {
107501
- if (!(nodeId in prev)) return prev;
107502
- const { [nodeId]: _drop, ...rest } = prev;
107503
- removed = true;
107504
- return rest;
107766
+ await this.blobWriteLock.run(PipelineSettingsStore.NODE_BINDINGS_LOCK_KEY, async () => {
107767
+ removed = await this.bindingRows.remove(nodeId);
107505
107768
  });
107506
107769
  return removed;
107507
107770
  }
107508
- /** Read-modify-write the WHOLE `nodeBindings` blob so a concurrent binding for another node/cap can't be dropped. */
107771
+ /** Read-modify-write ONE node's row, so a concurrent binding for another cap of the node is kept. */
107509
107772
  async setCapabilityBinding(nodeId, capName, addonId) {
107510
- await this.nodeBindingsState.update((prev) => {
107511
- const prevBindings = {};
107512
- for (const [nodeKey, nodeVal] of Object.entries(prev)) {
107513
- if (!nodeVal || typeof nodeVal !== "object") continue;
107514
- const nodeAsRecord = { ...nodeVal };
107515
- const nodeBinding = {};
107516
- for (const [cn, aid] of Object.entries(nodeAsRecord)) if (typeof aid === "string") nodeBinding[cn] = aid;
107517
- prevBindings[nodeKey] = nodeBinding;
107518
- }
107519
- const nodeBindings = { ...prevBindings[nodeId] };
107520
- nodeBindings[capName] = addonId;
107521
- return {
107522
- ...prevBindings,
107523
- [nodeId]: nodeBindings
107524
- };
107773
+ await this.blobWriteLock.run(PipelineSettingsStore.NODE_BINDINGS_LOCK_KEY, async () => {
107774
+ const prev = await this.bindingRows.get(nodeId) ?? {};
107775
+ await this.bindingRows.set(nodeId, {
107776
+ ...prev,
107777
+ [capName]: addonId
107778
+ });
107525
107779
  });
107526
107780
  }
107527
107781
  /** Read the `agentSettings` map (keyed on `nodeId`) via the durable handle. */
107528
107782
  async readAgentSettingsMap() {
107529
- return { ...await this.agentSettingsState.get() };
107783
+ return await this.agentRows.getAll();
107530
107784
  }
107531
107785
  /**
107532
107786
  * Drop every per-(node, device) `modelId` pin that names a model deleted
@@ -107539,9 +107793,10 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107539
107793
  async resetRemovedModelPins(isCustom) {
107540
107794
  const cleared = [];
107541
107795
  await this.blobWriteLock.run(PipelineSettingsStore.AGENT_SETTINGS_LOCK_KEY, async () => {
107542
- const swept = sweepAgentSettingsPins(await this.agentSettingsState.get(), isCustom);
107796
+ const prev = await this.agentRows.getAll();
107797
+ const swept = sweepAgentSettingsPins(prev, isCustom);
107543
107798
  if (swept.cleared.length === 0) return;
107544
- await this.agentSettingsState.set(swept.next);
107799
+ await this.agentRows.applyDiff(prev, swept.next);
107545
107800
  cleared.push(...swept.cleared);
107546
107801
  });
107547
107802
  return cleared;
@@ -107558,17 +107813,13 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107558
107813
  return;
107559
107814
  }
107560
107815
  await this.blobWriteLock.run(PipelineSettingsStore.AGENT_SETTINGS_LOCK_KEY, async () => {
107561
- const all = await this.readAgentSettingsMap();
107562
- const existing = all[nodeId];
107816
+ const existing = await this.agentRows.get(nodeId);
107563
107817
  const merged = {
107564
107818
  ...existing,
107565
107819
  ...settings,
107566
107820
  maxCameras: settings.maxCameras !== void 0 ? settings.maxCameras ?? null : existing?.maxCameras ?? null
107567
107821
  };
107568
- await this.agentSettingsState.set({
107569
- ...all,
107570
- [nodeId]: merged
107571
- });
107822
+ await this.agentRows.set(nodeId, merged);
107572
107823
  });
107573
107824
  }
107574
107825
  /**
@@ -107579,7 +107830,8 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107579
107830
  */
107580
107831
  async rewriteAgentSettingsMap(transform) {
107581
107832
  await this.blobWriteLock.run(PipelineSettingsStore.AGENT_SETTINGS_LOCK_KEY, async () => {
107582
- await this.agentSettingsState.set(transform(await this.readAgentSettingsMap()));
107833
+ const prev = await this.agentRows.getAll();
107834
+ await this.agentRows.applyDiff(prev, transform(prev));
107583
107835
  });
107584
107836
  }
107585
107837
  /**
@@ -107591,23 +107843,21 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107591
107843
  async removeAgentSettings(nodeId) {
107592
107844
  let removed = false;
107593
107845
  await this.blobWriteLock.run(PipelineSettingsStore.AGENT_SETTINGS_LOCK_KEY, async () => {
107594
- const all = await this.readAgentSettingsMap();
107595
- if (!(nodeId in all)) return;
107596
- const { [nodeId]: _drop, ...rest } = all;
107597
- await this.agentSettingsState.set(rest);
107598
- removed = true;
107846
+ removed = await this.agentRows.remove(nodeId);
107599
107847
  });
107600
107848
  return removed;
107601
107849
  }
107602
107850
  /** Read the `cameraSettings` map (keyed on `deviceId` as string) via the durable handle. */
107603
107851
  async readCameraSettingsMap() {
107604
- return { ...await this.cameraSettingsState.get() };
107852
+ return await this.cameraRows.getAll();
107853
+ }
107854
+ /** One camera's settings, `null` when it has none. A failed read throws. */
107855
+ async readCameraSettings(deviceId) {
107856
+ return await this.cameraRows.get(deviceId) ?? null;
107605
107857
  }
107606
107858
  /** Overwrite one camera's settings. */
107607
107859
  async writeCameraSettings(deviceId, settings) {
107608
- const all = await this.readCameraSettingsMap();
107609
- all[String(deviceId)] = settings;
107610
- await this.cameraSettingsState.set(all);
107860
+ await this.cameraRows.set(deviceId, settings);
107611
107861
  }
107612
107862
  /**
107613
107863
  * Write or clear one camera's CAMERA-WIDE settings for `addonId` (D754): the
@@ -107616,22 +107866,16 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107616
107866
  * Read-patch-write, immutable. The caller refuses a model-scoped key (D927).
107617
107867
  */
107618
107868
  async writeCameraStepSettings(deviceId, addonId, settings) {
107619
- await this.cameraSettingsState.update((prev) => {
107620
- const key = String(deviceId);
107621
- const camera = prev[key] ?? {};
107622
- const nextLayer = { ...camera.stepSettings };
107623
- if (settings === null || Object.keys(settings).length === 0) delete nextLayer[addonId];
107624
- else nextLayer[addonId] = { ...settings };
107625
- const { stepSettings: _drop, ...rest } = camera;
107626
- const nextCamera = {
107627
- ...rest,
107628
- ...Object.keys(nextLayer).length > 0 ? { stepSettings: nextLayer } : {}
107629
- };
107630
- return {
107631
- ...prev,
107632
- [key]: nextCamera
107633
- };
107634
- });
107869
+ const camera = await this.cameraRows.get(deviceId) ?? {};
107870
+ const nextLayer = { ...camera.stepSettings };
107871
+ if (settings === null || Object.keys(settings).length === 0) delete nextLayer[addonId];
107872
+ else nextLayer[addonId] = { ...settings };
107873
+ const { stepSettings: _drop, ...rest } = camera;
107874
+ const nextCamera = {
107875
+ ...rest,
107876
+ ...Object.keys(nextLayer).length > 0 ? { stepSettings: nextLayer } : {}
107877
+ };
107878
+ await this.cameraRows.set(deviceId, nextCamera);
107635
107879
  }
107636
107880
  /**
107637
107881
  * Write or clear one step's NODE-wide settings (D927) under the agent-blob
@@ -107640,27 +107884,20 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107640
107884
  */
107641
107885
  async writeNodeStepSettings(nodeId, addonId, settings) {
107642
107886
  await this.blobWriteLock.run(PipelineSettingsStore.AGENT_SETTINGS_LOCK_KEY, async () => {
107643
- const all = await this.readAgentSettingsMap();
107644
- const existing = all[nodeId] ?? { maxCameras: null };
107887
+ const existing = await this.agentRows.get(nodeId) ?? { maxCameras: null };
107645
107888
  const layer = { ...existing.stepSettings };
107646
107889
  if (settings === null || Object.keys(settings).length === 0) delete layer[addonId];
107647
107890
  else layer[addonId] = { ...settings };
107648
107891
  const { stepSettings: _drop, ...rest } = existing;
107649
- await this.agentSettingsState.set({
107650
- ...all,
107651
- [nodeId]: {
107652
- ...rest,
107653
- ...Object.keys(layer).length > 0 ? { stepSettings: layer } : {}
107654
- }
107892
+ await this.agentRows.set(nodeId, {
107893
+ ...rest,
107894
+ ...Object.keys(layer).length > 0 ? { stepSettings: layer } : {}
107655
107895
  });
107656
107896
  });
107657
107897
  }
107658
- /** Purge one device's entry through the durable handle (whole-blob round-trip). */
107898
+ /** Purge one device's row. */
107659
107899
  async deleteCameraSettings(deviceId) {
107660
- await this.cameraSettingsState.update((prev) => {
107661
- const { [String(deviceId)]: _c, ...rest } = prev;
107662
- return rest;
107663
- });
107900
+ await this.cameraRows.remove(deviceId);
107664
107901
  }
107665
107902
  catalogCache = /* @__PURE__ */ new Map();
107666
107903
  /**
@@ -107837,7 +108074,7 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107837
108074
  */
107838
108075
  async seedAgentSettingsFromCatalog(nodeId) {
107839
108076
  if (!await this.awaitExecutorCatalog(nodeId, { maxRounds: PipelineSettingsStore.SEED_MAX_RECONCILE_ROUNDS })) return null;
107840
- const existing = (await this.readAgentSettingsMap())[nodeId];
108077
+ const existing = await this.agentRows.get(nodeId);
107841
108078
  if (existing) return existing;
107842
108079
  const next = { maxCameras: null };
107843
108080
  await this.writeAgentSettings(nodeId, next);
@@ -107941,7 +108178,7 @@ var PipelineSettingsStore = class PipelineSettingsStore {
107941
108178
  };
107942
108179
  }
107943
108180
  const hasPackageZone = await this.deps.hasPackageZone(deviceId);
107944
- const cam = (await this.readCameraSettingsMap())[String(deviceId)] ?? null;
108181
+ const cam = await this.cameraRows.get(deviceId) ?? null;
107945
108182
  let catalog;
107946
108183
  if (catalogRead.kind === "await") catalog = (await this.waitForAgentAndCatalog(agentNodeId)).catalog;
107947
108184
  else {
@@ -108060,13 +108297,13 @@ var PipelineSettingsStore = class PipelineSettingsStore {
108060
108297
  while (!this.disposed) {
108061
108298
  const catalog = await this.awaitExecutorCatalog(nodeId);
108062
108299
  if (!catalog) break;
108063
- let agent = (await this.readAgentSettingsMap())[nodeId];
108300
+ let agent = await this.agentRows.get(nodeId);
108064
108301
  if (!agent) {
108065
108302
  if (!await this.seedAgentSettingsFromCatalog(nodeId)) {
108066
108303
  await sleep(2e3);
108067
108304
  continue;
108068
108305
  }
108069
- agent = (await this.readAgentSettingsMap())[nodeId];
108306
+ agent = await this.agentRows.get(nodeId);
108070
108307
  }
108071
108308
  if (!agent) {
108072
108309
  await sleep(2e3);
@@ -108086,7 +108323,7 @@ var PipelineSettingsStore = class PipelineSettingsStore {
108086
108323
  * per-node maximums without polling the store on each decision.
108087
108324
  */
108088
108325
  async buildNodeCaps() {
108089
- const blob = await this.agentSettingsState.get();
108326
+ const blob = await this.agentRows.getAll();
108090
108327
  const caps = {};
108091
108328
  for (const [nodeId, settings] of Object.entries(blob)) caps[nodeId] = settings.maxCameras ?? null;
108092
108329
  return caps;
@@ -108106,7 +108343,7 @@ var PipelineSettingsStore = class PipelineSettingsStore {
108106
108343
  * `manual` applies and what `auto` falls back to before its first answer.
108107
108344
  */
108108
108345
  async buildStoredNodeWeights() {
108109
- const blob = await this.agentSettingsState.get();
108346
+ const blob = await this.agentRows.getAll();
108110
108347
  const weights = {};
108111
108348
  for (const [nodeId, settings] of Object.entries(blob)) if (typeof settings.detectWeight === "number" && settings.detectWeight > 0) weights[nodeId] = settings.detectWeight;
108112
108349
  return weights;
@@ -108135,7 +108372,7 @@ var PipelineSettingsStore = class PipelineSettingsStore {
108135
108372
  * (no attach).
108136
108373
  */
108137
108374
  async buildNodeInferenceDeviceSteps(nodeId, deviceKey) {
108138
- return nodeDeviceBase((await this.agentSettingsState.get())[nodeId], deviceKey);
108375
+ return nodeDeviceBase(await this.agentRows.get(nodeId), deviceKey);
108139
108376
  }
108140
108377
  /**
108141
108378
  * The provisioning SOURCES of every device an attach may run a step on
@@ -108147,9 +108384,8 @@ var PipelineSettingsStore = class PipelineSettingsStore {
108147
108384
  * node's folded settings.
108148
108385
  */
108149
108386
  async readDeviceProvisioning(deviceId, nodeId, deviceKeys) {
108150
- const [agentBlob, cameraMap] = await Promise.all([this.agentSettingsState.get(), this.readCameraSettingsMap()]);
108151
- const node = agentBlob[nodeId];
108152
- const cameraLayer = layerCameraStepSettings(cameraMap[String(deviceId)]?.stepSettings);
108387
+ const [node, camera] = await Promise.all([this.agentRows.get(nodeId), this.cameraRows.get(deviceId)]);
108388
+ const cameraLayer = layerCameraStepSettings(camera?.stepSettings);
108153
108389
  const out = /* @__PURE__ */ new Map();
108154
108390
  for (const deviceKey of deviceKeys) out.set(deviceKey, {
108155
108391
  base: nodeDeviceBase(node, deviceKey),
@@ -111902,6 +112138,8 @@ async function buildOrchestratorControllers(deps) {
111902
112138
  });
111903
112139
  const settingsStore = new PipelineSettingsStore({
111904
112140
  state: deps.state,
112141
+ readStore: () => deps.resolveGlobalStore(),
112142
+ deviceSettings: () => deps.ctxIfReady()?.settings ?? null,
111905
112143
  api: () => deps.ctxIfReady()?.api ?? null,
111906
112144
  acquireCapability: (capName, scope, opts) => {
111907
112145
  const ctx = deps.ctxIfReady();
@@ -114866,9 +115104,25 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
114866
115104
  }
114867
115105
  };
114868
115106
  }
114869
- /** Delete the one-shot flag of the retired legacy-flags-to-bindings carry-over (D987). */
115107
+ /**
115108
+ * The orchestrator's D987 catalogue: the retired bindings flag is deleted, and the three id-keyed
115109
+ * maps become one row per node / per camera (D986 §2). The readers read the rows, so a failure
115110
+ * here blocks the addon (`block-owner`) instead of letting it serve an empty store.
115111
+ */
114870
115112
  async migrateSettings() {
114871
- await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, { readStored: (keys) => readRawKeys((key) => this.readStoredGlobalKey(key), PIPELINE_ORCHESTRATOR_ID, keys) }));
115113
+ await this.runMigrations(defineAddonMigrations(ADDON_MIGRATIONS, {
115114
+ readStored: (keys) => readRawKeys((key) => this.readStoredGlobalKey(key), PIPELINE_ORCHESTRATOR_ID, keys),
115115
+ readDeviceField: async (deviceIds, field) => {
115116
+ const settings = this.ctx.settings;
115117
+ if (settings === void 0) throw new Error("the per-device settings store is unavailable");
115118
+ const found = /* @__PURE__ */ new Map();
115119
+ for (const [deviceId, blob] of await settings.readDeviceStoreBatch(deviceIds)) if (field in blob) found.set(deviceId, blob[field]);
115120
+ return found;
115121
+ }
115122
+ }));
115123
+ this.state(NODE_BINDINGS_FIELD, NodeBindingsSchema, {});
115124
+ this.state(AGENT_SETTINGS_FIELD, AgentSettingsMapSchema, {});
115125
+ this.state(CAMERA_SETTINGS_FIELD, CameraSettingsMapSchema, {});
114872
115126
  }
114873
115127
  async onInitialize() {
114874
115128
  this.initTimestamp = Date.now();
@@ -116612,10 +116866,10 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
116612
116866
  return { success: true };
116613
116867
  }
116614
116868
  async getCameraSettings(input) {
116615
- return (await this.settingsStore.readCameraSettingsMap())[String(input.deviceId)] ?? null;
116869
+ return await this.settingsStore.readCameraSettings(input.deviceId);
116616
116870
  }
116617
116871
  async setCameraStepToggle(input) {
116618
- const existing = (await this.settingsStore.readCameraSettingsMap())[String(input.deviceId)] ?? {};
116872
+ const existing = await this.settingsStore.readCameraSettings(input.deviceId) ?? {};
116619
116873
  const nextToggles = { ...existing.stepToggles };
116620
116874
  if (input.enabled === null) delete nextToggles[input.addonId];
116621
116875
  else nextToggles[input.addonId] = input.enabled;