@camstack/addon-mqtt-broker 1.2.152 → 1.2.153

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.
@@ -6021,7 +6021,7 @@ var ZodIssueCode = {
6021
6021
  var ZodFirstPartyTypeKind;
6022
6022
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6023
6023
  //#endregion
6024
- //#region ../types/dist/sleep-BX_MqzUe.mjs
6024
+ //#region ../types/dist/sleep-CmjWurK5.mjs
6025
6025
  /**
6026
6026
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6027
6027
  * window to float samples (D455).
@@ -6705,137 +6705,86 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
6705
6705
  blockOwner
6706
6706
  };
6707
6707
  }
6708
- /**
6709
- * Build a {@link DurableState} over a single store key. Transport-agnostic:
6710
- * `read`/`write` are the addon-store or device-store accessors. The whole
6711
- * validated value round-trips on every read/write — the schema is the
6712
- * single source of truth for what is persisted, so no hand-listed field
6713
- * set can drop a key on save.
6714
- */
6715
- function createDurableState(deps) {
6716
- const get = async () => {
6717
- const raw = (await deps.read())[deps.key];
6718
- if (raw === void 0) return deps.fallback;
6719
- const parsed = deps.schema.safeParse(raw);
6720
- if (!parsed.success) {
6721
- deps.onParseError?.(deps.key, parsed.error);
6722
- return deps.fallback;
6723
- }
6724
- return parsed.data;
6725
- };
6726
- const set = async (next) => {
6727
- const validated = deps.schema.parse(next);
6728
- await deps.write({ [deps.key]: validated });
6729
- };
6730
- const update = async (fn) => {
6731
- await set(fn(await get()));
6732
- };
6708
+ /** The record calls the one-switch migration makes, over the migration API. */
6709
+ function switchRecordsOverMigrationApi(api) {
6710
+ return { kind: (definition) => {
6711
+ const handle = api.records.kind(definition);
6712
+ return {
6713
+ get: (id) => handle.get({ id }),
6714
+ put: (input, opts) => handle.put({
6715
+ ...input,
6716
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
6717
+ }),
6718
+ patch: (id, partial) => handle.patch({
6719
+ id,
6720
+ partial
6721
+ })
6722
+ };
6723
+ } };
6724
+ }
6725
+ function integrationRowsApiOver(api) {
6733
6726
  return {
6734
- get,
6735
- set,
6736
- update
6727
+ list: async () => (await api.integrations.list({})).integrations,
6728
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
6729
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
6737
6730
  };
6738
6731
  }
6739
- /**
6740
- * Per-node scoping for the shared addon-settings blob.
6741
- *
6742
- * An addon's settings store is hub-central (the `addon-settings` cap is
6743
- * hub-routed — the hub instance answers for every node), so fields whose
6744
- * value is a NODE fact (decoder backend, engine pick, probed hardware
6745
- * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
6746
- * the single shared blob. The SCHEMA field key stays bare: the write path
6747
- * ({@link scopePatch}) maps the bare field onto the target node's scoped
6748
- * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
6749
- * back, so UI forms and `resolveConfig` only ever see the bare key.
6750
- *
6751
- * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
6752
- * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
6753
- * schema and routes reads/writes through these helpers.
6754
- *
6755
- * ## No bare-key fallback — deliberate
6756
- *
6757
- * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
6758
- * scoped key resolves to `undefined` so the field's schema `default` wins —
6759
- * NEVER `store[base]` and never another node's value. A bare legacy key in
6760
- * the store is invisible to every node, hub included, so one node's
6761
- * selection can never leak onto another. (This generalizes the
6762
- * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
6763
- * arbitrary set of per-node field keys.)
6764
- *
6765
- * Pure functions only — no I/O, no imports beyond the language. This is a
6766
- * LEAF module: import it via its deep path, never from the root barrel.
6767
- */
6768
- /**
6769
- * Normalize a raw kernel node id to the bare node id used for scoping.
6770
- * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
6771
- * processes; per-node settings are per-NODE, so strip the addon segment.
6772
- * `undefined` / `null` / empty falls back to `'hub'`.
6773
- */
6774
- function normalizeNodeId(raw) {
6775
- if (raw === void 0 || raw === null || raw === "") return "hub";
6776
- const slashIdx = raw.indexOf("/");
6777
- if (slashIdx < 0) return raw;
6778
- const bare = raw.slice(0, slashIdx);
6779
- return bare === "" ? "hub" : bare;
6780
- }
6781
- /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
6782
- function nodeScopedKey(base, nodeId) {
6783
- return `${base}@${normalizeNodeId(nodeId)}`;
6784
- }
6785
- /**
6786
- * Read a node's value for a per-node field from the raw shared store:
6787
- * the node-scoped key when present, otherwise `undefined`.
6788
- * Deliberately NO bare-key fallback (see module doc) — the caller lets the
6789
- * schema `default` win on `undefined`.
6790
- */
6791
- function readNodeValue(store, base, nodeId) {
6792
- return store[nodeScopedKey(base, nodeId)];
6793
- }
6794
- /**
6795
- * Re-map a UI/settings patch so every bare perNode field persists under the
6796
- * TARGET node's scoped key; all other keys pass through unchanged. Used on
6797
- * the write path so a save for one node never clobbers another node's value
6798
- * (and the bare key is never written). Returns a new object — the input
6799
- * patch is not mutated.
6800
- */
6801
- function scopePatch(patch, perNodeKeys, nodeId) {
6802
- const out = {};
6803
- for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
6804
- return out;
6805
- }
6806
- /**
6807
- * Project the raw shared store onto the bare schema keys for ONE node so a
6808
- * UI schema (whose field keys are bare) hydrates from that node's own
6809
- * values:
6810
- *
6811
- * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
6812
- * - Every bare perNode key is dropped from the pass-through (a stray bare
6813
- * legacy key must never hydrate any node — no bare fallback).
6814
- * - THIS node's effective value ({@link readNodeValue}) is then laid onto
6815
- * each bare perNode key; when the node has no scoped key the bare key is
6816
- * left ABSENT so the field's schema `default` wins.
6817
- *
6818
- * Returns a new object — the input store is not mutated.
6819
- */
6820
- function projectStore(store, perNodeKeys, nodeId) {
6821
- const out = {};
6822
- for (const [key, value] of Object.entries(store)) {
6823
- if (key.includes("@")) continue;
6824
- if (perNodeKeys.has(key)) continue;
6825
- out[key] = value;
6732
+ var PREFIX = "records/";
6733
+ /** The base of every records failure. `detail` is the human part of the message. */
6734
+ var RecordsError = class extends Error {
6735
+ code;
6736
+ detail;
6737
+ constructor(code, detail) {
6738
+ super(`${PREFIX}${code}: ${detail}`);
6739
+ this.name = "RecordsError";
6740
+ this.code = code;
6741
+ this.detail = detail;
6826
6742
  }
6827
- for (const base of perNodeKeys) {
6828
- const value = readNodeValue(store, base, nodeId);
6829
- if (value !== void 0) out[base] = value;
6743
+ };
6744
+ /** The keychain could not store or serve a value: explicit, never an empty string. */
6745
+ var RecordSecretUnavailableError = class extends RecordsError {
6746
+ constructor(detail) {
6747
+ super("secret-unavailable", detail);
6748
+ this.name = "RecordSecretUnavailableError";
6830
6749
  }
6831
- return out;
6750
+ };
6751
+ var InvalidRecordError = class extends RecordsError {
6752
+ constructor(detail) {
6753
+ super("invalid-record", detail);
6754
+ this.name = "InvalidRecordError";
6755
+ }
6756
+ };
6757
+ /** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
6758
+ var DeclarationRefusedError = class extends RecordsError {
6759
+ constructor(detail) {
6760
+ super("declaration-refused", detail);
6761
+ this.name = "DeclarationRefusedError";
6762
+ }
6763
+ };
6764
+ function linkTargetOf(meta) {
6765
+ if (typeof meta !== "object" || meta === null) return void 0;
6766
+ const link = Reflect.get(meta, "link");
6767
+ const parsed = LinkTargetSchema.safeParse(link);
6768
+ return parsed.success ? parsed.data : void 0;
6769
+ }
6770
+ var LinkTargetSchema = object({
6771
+ cap: string().min(1),
6772
+ kind: string().min(1).optional()
6773
+ });
6774
+ /** The links a kind declares, read from the meta of its body fields. */
6775
+ function linksOfKind(kind) {
6776
+ const schema = kind.schema;
6777
+ if (!(schema instanceof ZodObject)) return [];
6778
+ const links = [];
6779
+ for (const [field, fieldSchema] of Object.entries(schema.shape)) {
6780
+ const to = linkTargetOf(globalRegistry.get(fieldSchema));
6781
+ if (to !== void 0) links.push({
6782
+ field,
6783
+ to
6784
+ });
6785
+ }
6786
+ return links;
6832
6787
  }
6833
- /** Every scope, in the order the guard and the docs list them. */
6834
- var SCOPED_SETTINGS_SCOPES = [
6835
- "cluster",
6836
- "device-defaults",
6837
- "node"
6838
- ];
6839
6788
  /**
6840
6789
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6841
6790
  *
@@ -6970,6 +6919,643 @@ function parseSecretRef(ref) {
6970
6919
  fieldPath
6971
6920
  };
6972
6921
  }
6922
+ /** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
6923
+ /** The files a kind may live in. `history` is device-history's (D850), never records. */
6924
+ var RECORD_DATABASES = ["settings", "events"];
6925
+ /** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
6926
+ var RECORD_CLASSES = [
6927
+ "config",
6928
+ "ledger",
6929
+ "audit",
6930
+ "mirror",
6931
+ "ephemeral"
6932
+ ];
6933
+ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
6934
+ var RECORD_MAX_DATA_BYTES = 1024 * 1024;
6935
+ var RECORD_BATCH_MAX = 1e3;
6936
+ var RECORD_QUERY_MAX = 1e3;
6937
+ /** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
6938
+ var RECORD_SETTINGS_MAX_ROWS = 5e4;
6939
+ /** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
6940
+ var RECORD_SECRET_COLLECTION_PREFIX = "records:";
6941
+ /**
6942
+ * Secret fields of a record, addressed the way a Zod schema declares them
6943
+ * (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
6944
+ * (`auth.accessToken`, `headers[].value`).
6945
+ *
6946
+ * `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
6947
+ * names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
6948
+ * key releases exactly that key's secret.
6949
+ *
6950
+ * Array elements are matched by a DECLARED id key (`secretArrayKeys`:
6951
+ * `{ headers: 'name' }`), never by index, so reordering a list keeps every
6952
+ * keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
6953
+ * leaf names its element: `headers[X-Api].value`.
6954
+ *
6955
+ * Pure and browser-safe. Nothing here mutates: every transform returns a new value.
6956
+ */
6957
+ /** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
6958
+ function parseSecretPath(path) {
6959
+ if (path.length === 0) throw new InvalidRecordError("an empty secret path");
6960
+ return path.split(".").map((raw) => {
6961
+ const each = raw.endsWith("[]");
6962
+ const map = raw.endsWith("{}");
6963
+ const key = each || map ? raw.slice(0, -2) : raw;
6964
+ if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
6965
+ return {
6966
+ key,
6967
+ each,
6968
+ map
6969
+ };
6970
+ });
6971
+ }
6972
+ /** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
6973
+ function secretArrayPrefixes(path) {
6974
+ const segments = parseSecretPath(path);
6975
+ const prefixes = [];
6976
+ const walked = [];
6977
+ for (const segment of segments) {
6978
+ walked.push(segment.key);
6979
+ if (segment.each) prefixes.push(walked.join("."));
6980
+ }
6981
+ return prefixes;
6982
+ }
6983
+ function isRecord$6(value) {
6984
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6985
+ }
6986
+ function elementId(element, idKey, declared, prefix) {
6987
+ const id = isRecord$6(element) ? element[idKey] : void 0;
6988
+ if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
6989
+ return id;
6990
+ }
6991
+ /**
6992
+ * Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
6993
+ * visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
6994
+ * result is a new body, `data` is untouched.
6995
+ */
6996
+ var REMOVE_LEAF = Symbol("remove-leaf");
6997
+ function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
6998
+ if (!isRecord$6(node)) return node;
6999
+ const segment = segments[index];
7000
+ if (segment === void 0) return node;
7001
+ if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
7002
+ const child = node[segment.key];
7003
+ const keys = [...walkedKeys, segment.key];
7004
+ const last = index === segments.length - 1;
7005
+ if (segment.each) {
7006
+ if (!Array.isArray(child)) return node;
7007
+ const prefix = keys.join(".");
7008
+ const idKey = arrayKeys[prefix];
7009
+ if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
7010
+ const mapped = child.map((element) => {
7011
+ const id = elementId(element, idKey, declared, prefix);
7012
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
7013
+ return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
7014
+ });
7015
+ return {
7016
+ ...node,
7017
+ [segment.key]: mapped
7018
+ };
7019
+ }
7020
+ if (segment.map) {
7021
+ if (!isRecord$6(child)) return node;
7022
+ const kept = Object.entries(child).map(([mapKey, value]) => {
7023
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
7024
+ if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
7025
+ return [mapKey, visit({
7026
+ declared,
7027
+ concrete,
7028
+ value
7029
+ })];
7030
+ }).filter(([, value]) => value !== REMOVE_LEAF);
7031
+ return {
7032
+ ...node,
7033
+ [segment.key]: Object.fromEntries(kept)
7034
+ };
7035
+ }
7036
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
7037
+ if (last) {
7038
+ const replacement = visit({
7039
+ declared,
7040
+ concrete,
7041
+ value: child
7042
+ });
7043
+ if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
7044
+ return {
7045
+ ...node,
7046
+ [segment.key]: replacement
7047
+ };
7048
+ }
7049
+ return {
7050
+ ...node,
7051
+ [segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
7052
+ };
7053
+ }
7054
+ /** Replace/remove every present secret leaf; returns a NEW body. */
7055
+ function mapSecretLeaves(data, paths, arrayKeys, visit) {
7056
+ let current = data;
7057
+ for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
7058
+ return current;
7059
+ }
7060
+ /**
7061
+ * The keychain collection name a kind's secrets live under. Prefixed so a
7062
+ * record's refs never collide with the refs a legacy collection of the same name
7063
+ * already holds during an adoption.
7064
+ */
7065
+ function recordSecretCollection(kind) {
7066
+ return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
7067
+ }
7068
+ /** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
7069
+ function recordSecretRef(owner, kind, rowId, concretePath) {
7070
+ return buildSecretRef({
7071
+ owner,
7072
+ scope: {
7073
+ kind: "row",
7074
+ collection: recordSecretCollection(kind),
7075
+ rowId
7076
+ },
7077
+ fieldPath: concretePath
7078
+ });
7079
+ }
7080
+ /**
7081
+ * A stored secret, as an admin read shows it: a VIEW naming the row's own
7082
+ * keychain ref (`set: true`), never the value and no longer the bare redaction
7083
+ * token. The form hands it to the secret field, which reveals the value by ref
7084
+ * through the audited `keychain-admin.reveal`; sent back untouched it keeps the
7085
+ * stored secret (the records door reads a view as KEEP).
7086
+ *
7087
+ * ONE implementation for the entries service and for every addon that serves
7088
+ * its own instances (`RecordIntegrationInstances`).
7089
+ */
7090
+ function isRecord$5(value) {
7091
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7092
+ }
7093
+ function secretViewsOf(owner, kind, id, decl, data) {
7094
+ if (decl.secretPaths.length === 0) return data;
7095
+ const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
7096
+ if (leaf.value !== "__camstack_redacted__") return leaf.value;
7097
+ return {
7098
+ $secret: recordSecretRef(owner, kind, id, leaf.concrete),
7099
+ v: 1,
7100
+ set: true
7101
+ };
7102
+ });
7103
+ return isRecord$5(shown) ? shown : data;
7104
+ }
7105
+ /** The most instances one addon lists (an integrations page, not a table). */
7106
+ var INSTANCES_LIST_MAX = 1e3;
7107
+ /**
7108
+ * The ONE reader of an instance's switch (D996): an absent field means on, so a row written
7109
+ * before the field existed needs no migration. Every consumer of an instance body asks this.
7110
+ */
7111
+ function isInstanceEnabled(body) {
7112
+ return body.enabled !== false;
7113
+ }
7114
+ /** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
7115
+ var SWITCH_KEY = "enabled";
7116
+ /** The keys of the kind's secret fields that sit at the top level of the body. */
7117
+ function topLevelSecretKeys(paths) {
7118
+ return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
7119
+ }
7120
+ /** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
7121
+ function secretMapKeys(paths) {
7122
+ return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
7123
+ }
7124
+ /**
7125
+ * A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
7126
+ * view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
7127
+ * or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
7128
+ */
7129
+ function secretMapPatch(value) {
7130
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
7131
+ const out = {};
7132
+ for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
7133
+ else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
7134
+ return Object.keys(out).length > 0 ? out : null;
7135
+ }
7136
+ var RecordIntegrationInstances = class {
7137
+ records;
7138
+ kind;
7139
+ hooks;
7140
+ handle;
7141
+ secretKeys;
7142
+ secretMaps;
7143
+ nameField;
7144
+ switchListeners = /* @__PURE__ */ new Set();
7145
+ constructor(records, kind, hooks) {
7146
+ this.records = records;
7147
+ this.kind = kind;
7148
+ this.hooks = hooks;
7149
+ this.handle = records.kind(kind);
7150
+ this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
7151
+ this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
7152
+ this.nameField = kind.declaration.entry?.nameField ?? "name";
7153
+ }
7154
+ /**
7155
+ * One instance read for the addon's own runtime; null when absent. When the keychain is
7156
+ * locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
7157
+ * caller can keep what it had instead of reconfiguring with an empty secret (D49).
7158
+ */
7159
+ async readResolved(id) {
7160
+ try {
7161
+ const record = await this.handle.getResolved(id);
7162
+ return record === null ? null : {
7163
+ id,
7164
+ body: record.data,
7165
+ enabled: isInstanceEnabled(record.data),
7166
+ secrets: "resolved"
7167
+ };
7168
+ } catch (err) {
7169
+ if (!(err instanceof RecordSecretUnavailableError)) throw err;
7170
+ const stored = await this.handle.get(id);
7171
+ if (stored === null) return null;
7172
+ return {
7173
+ id,
7174
+ body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
7175
+ enabled: isInstanceEnabled(stored.data),
7176
+ secrets: "unavailable"
7177
+ };
7178
+ }
7179
+ }
7180
+ /** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
7181
+ async getResolved(id) {
7182
+ return (await this.readResolved(id))?.body ?? null;
7183
+ }
7184
+ /** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
7185
+ async listResolved() {
7186
+ const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
7187
+ const out = [];
7188
+ for (const record of page.records) {
7189
+ const read = await this.readResolved(record.id);
7190
+ if (read !== null) out.push(read);
7191
+ }
7192
+ return out;
7193
+ }
7194
+ viewOf(record) {
7195
+ const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
7196
+ const rawName = record.data[this.nameField];
7197
+ const kind = this.hooks.kindOf?.(record.data);
7198
+ const health = this.hooks.health?.(record.data, record.id);
7199
+ return {
7200
+ id: record.id,
7201
+ name: typeof rawName === "string" ? rawName : record.id,
7202
+ configured: this.hooks.configured(record.data),
7203
+ enabled: isInstanceEnabled(record.data),
7204
+ formValues: shown,
7205
+ ...kind !== void 0 ? { kind } : {},
7206
+ ...health?.status !== void 0 ? { status: health.status } : {},
7207
+ ...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
7208
+ };
7209
+ }
7210
+ describe = async () => {
7211
+ const declared = linksOfKind(this.kind);
7212
+ const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
7213
+ kind: this.kind.name,
7214
+ field: link.field,
7215
+ to: link.to
7216
+ })) };
7217
+ return {
7218
+ ...this.hooks.description,
7219
+ ...links,
7220
+ ...this.hooks.mintId === void 0 ? {} : { mintsId: true }
7221
+ };
7222
+ };
7223
+ instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
7224
+ listInstances = async () => {
7225
+ return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
7226
+ };
7227
+ getInstance = async ({ id }) => {
7228
+ const record = await this.handle.get(id);
7229
+ return record === null ? null : this.viewOf(record);
7230
+ };
7231
+ /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
7232
+ createInstance = async ({ id, name, kind, values }) => {
7233
+ const minted = id ?? this.hooks.mintId?.({
7234
+ name,
7235
+ ...kind !== void 0 ? { kind } : {}
7236
+ });
7237
+ if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
7238
+ await this.handle.put({
7239
+ id: minted,
7240
+ data: this.hooks.initialBody(name, kind)
7241
+ }, { ifRev: 0 });
7242
+ const patch = this.patchOf(values ?? {});
7243
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
7244
+ await this.hooks.onChanged?.(minted, "created");
7245
+ return { id: minted };
7246
+ };
7247
+ updateInstance = async ({ id, name, values }) => {
7248
+ const patch = this.patchOf(values);
7249
+ if (name !== void 0) patch[this.nameField] = name;
7250
+ await this.handle.patch(id, patch);
7251
+ await this.hooks.onChanged?.(id, "updated");
7252
+ return { ok: true };
7253
+ };
7254
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
7255
+ patchOf(values) {
7256
+ const patch = {};
7257
+ for (const [key, value] of Object.entries(values)) {
7258
+ if (value === void 0) continue;
7259
+ if (key === "enabled") continue;
7260
+ if (this.secretMaps.has(key)) {
7261
+ const entries = secretMapPatch(value);
7262
+ if (entries !== null) patch[key] = entries;
7263
+ } else if (!this.secretKeys.has(key)) patch[key] = value;
7264
+ else if (isSecretClear(value)) patch[key] = null;
7265
+ else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
7266
+ }
7267
+ return patch;
7268
+ }
7269
+ /**
7270
+ * Listen to the switch of ANY instance of this helper (in the process that serves it). The
7271
+ * durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
7272
+ * addon reconciles from the record, whichever way it flipped.
7273
+ */
7274
+ onSwitched(listener) {
7275
+ this.switchListeners.add(listener);
7276
+ }
7277
+ /**
7278
+ * The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
7279
+ * configured thing is an instance, so an id with no record yet (a default integration that was
7280
+ * never configured) gets its record from `initialBody` before the switch is written.
7281
+ */
7282
+ setInstanceEnabled = async ({ id, enabled }) => {
7283
+ if (await this.handle.get(id) === null) await this.handle.put({
7284
+ id,
7285
+ data: this.hooks.initialBody(id)
7286
+ }, { ifRev: 0 });
7287
+ await this.handle.patch(id, { [SWITCH_KEY]: enabled });
7288
+ await this.hooks.onChanged?.(id, "enabled");
7289
+ for (const listener of this.switchListeners) await listener(id, enabled);
7290
+ return { ok: true };
7291
+ };
7292
+ /** The row and its keychain refs go together (the records door). */
7293
+ deleteInstance = async ({ id }) => {
7294
+ await this.handle.delete(id);
7295
+ await this.hooks.onChanged?.(id, "deleted");
7296
+ return { ok: true };
7297
+ };
7298
+ testInstance = async (input) => {
7299
+ if (this.hooks.test === void 0) return {
7300
+ success: false,
7301
+ status: "unsupported",
7302
+ error: "This integration declares no connection test"
7303
+ };
7304
+ return this.hooks.test(input);
7305
+ };
7306
+ /** The flat provider object to hand to `registerProvider`. */
7307
+ toProvider() {
7308
+ return {
7309
+ describe: this.describe,
7310
+ instanceFormSchema: this.instanceFormSchema,
7311
+ listInstances: this.listInstances,
7312
+ getInstance: this.getInstance,
7313
+ createInstance: this.createInstance,
7314
+ updateInstance: this.updateInstance,
7315
+ setInstanceEnabled: this.setInstanceEnabled,
7316
+ deleteInstance: this.deleteInstance,
7317
+ testInstance: this.testInstance
7318
+ };
7319
+ }
7320
+ };
7321
+ /**
7322
+ * The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
7323
+ * registry's `enabled` column for a device addon; it now lives only in the instance record's
7324
+ * body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
7325
+ *
7326
+ * For every registry row of the addon that is OFF:
7327
+ * - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
7328
+ * (a default integration that never had settings, Reolink's among them);
7329
+ * - a record whose body states no `enabled`: `enabled: false` is written into it;
7330
+ * - a record that already states `enabled` (either way) is the newer truth and is left alone.
7331
+ * A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
7332
+ * a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
7333
+ * goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
7334
+ *
7335
+ * It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
7336
+ * which is also why `integrations.list` still answers the stored column at that point.
7337
+ */
7338
+ function registrySwitchToBodyId(addonId, date) {
7339
+ return `${addonId}/${date}-registry-switch-to-body`;
7340
+ }
7341
+ async function moveRegistrySwitchToBody(ports, spec) {
7342
+ const rows = await ports.listIntegrations(spec.addonId);
7343
+ let created = 0;
7344
+ let switched = 0;
7345
+ let kept = 0;
7346
+ for (const row of rows) {
7347
+ if (row.enabled) continue;
7348
+ const body = await ports.readBody(row.id);
7349
+ if (body === null) {
7350
+ if (await ports.createRecord(row.id, {
7351
+ ...spec.initialBody(row.name),
7352
+ ["enabled"]: false
7353
+ }) === "created") created += 1;
7354
+ else kept += 1;
7355
+ continue;
7356
+ }
7357
+ if ("enabled" in body) {
7358
+ kept += 1;
7359
+ continue;
7360
+ }
7361
+ await ports.switchOff(row.id);
7362
+ switched += 1;
7363
+ }
7364
+ const summary = {
7365
+ integrations: rows.length,
7366
+ off: rows.filter((r) => !r.enabled).length,
7367
+ created,
7368
+ switched,
7369
+ kept
7370
+ };
7371
+ return created === 0 && switched === 0 ? {
7372
+ outcome: "already-done",
7373
+ summary
7374
+ } : {
7375
+ outcome: "done",
7376
+ summary
7377
+ };
7378
+ }
7379
+ /** A migration entry: an addon states its kind and how a new body starts, nothing else. */
7380
+ function registrySwitchToBodyMigration(spec) {
7381
+ return {
7382
+ meta: {
7383
+ id: registrySwitchToBodyId(spec.addonId, spec.date),
7384
+ owner: spec.addonId,
7385
+ level: "addon-state",
7386
+ seq: spec.seq,
7387
+ dependsOn: [],
7388
+ store: "settings",
7389
+ scope: "cluster",
7390
+ onFailure: "block-owner",
7391
+ bodyKind: "procedure",
7392
+ description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
7393
+ fixtureMark: "enabled"
7394
+ },
7395
+ procedure: (ports) => moveRegistrySwitchToBody(ports, {
7396
+ addonId: spec.addonId,
7397
+ initialBody: spec.initialBody
7398
+ })
7399
+ };
7400
+ }
7401
+ /** The hub and records sides of {@link registrySwitchToBodyMigration}. */
7402
+ function registrySwitchPortsOver(deps) {
7403
+ const handle = deps.records.kind({
7404
+ name: deps.kind.name,
7405
+ declaration: deps.kind.declaration,
7406
+ schema: record(string(), unknown())
7407
+ });
7408
+ return {
7409
+ listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
7410
+ id: i.id,
7411
+ name: i.name,
7412
+ enabled: i.enabled !== false
7413
+ })),
7414
+ readBody: async (id) => (await handle.get(id))?.data ?? null,
7415
+ createRecord: async (id, body) => {
7416
+ if (await handle.get(id) !== null) return "exists";
7417
+ await handle.put({
7418
+ id,
7419
+ data: body
7420
+ }, { ifRev: 0 });
7421
+ return "created";
7422
+ },
7423
+ switchOff: async (id) => {
7424
+ await handle.patch(id, { [SWITCH_KEY]: false });
7425
+ }
7426
+ };
7427
+ }
7428
+ /**
7429
+ * Build a {@link DurableState} over a single store key. Transport-agnostic:
7430
+ * `read`/`write` are the addon-store or device-store accessors. The whole
7431
+ * validated value round-trips on every read/write — the schema is the
7432
+ * single source of truth for what is persisted, so no hand-listed field
7433
+ * set can drop a key on save.
7434
+ */
7435
+ function createDurableState(deps) {
7436
+ const get = async () => {
7437
+ const raw = (await deps.read())[deps.key];
7438
+ if (raw === void 0) return deps.fallback;
7439
+ const parsed = deps.schema.safeParse(raw);
7440
+ if (!parsed.success) {
7441
+ deps.onParseError?.(deps.key, parsed.error);
7442
+ return deps.fallback;
7443
+ }
7444
+ return parsed.data;
7445
+ };
7446
+ const set = async (next) => {
7447
+ const validated = deps.schema.parse(next);
7448
+ await deps.write({ [deps.key]: validated });
7449
+ };
7450
+ const update = async (fn) => {
7451
+ await set(fn(await get()));
7452
+ };
7453
+ return {
7454
+ get,
7455
+ set,
7456
+ update
7457
+ };
7458
+ }
7459
+ /**
7460
+ * Per-node scoping for the shared addon-settings blob.
7461
+ *
7462
+ * An addon's settings store is hub-central (the `addon-settings` cap is
7463
+ * hub-routed — the hub instance answers for every node), so fields whose
7464
+ * value is a NODE fact (decoder backend, engine pick, probed hardware
7465
+ * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
7466
+ * the single shared blob. The SCHEMA field key stays bare: the write path
7467
+ * ({@link scopePatch}) maps the bare field onto the target node's scoped
7468
+ * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
7469
+ * back, so UI forms and `resolveConfig` only ever see the bare key.
7470
+ *
7471
+ * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
7472
+ * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
7473
+ * schema and routes reads/writes through these helpers.
7474
+ *
7475
+ * ## No bare-key fallback — deliberate
7476
+ *
7477
+ * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
7478
+ * scoped key resolves to `undefined` so the field's schema `default` wins —
7479
+ * NEVER `store[base]` and never another node's value. A bare legacy key in
7480
+ * the store is invisible to every node, hub included, so one node's
7481
+ * selection can never leak onto another. (This generalizes the
7482
+ * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
7483
+ * arbitrary set of per-node field keys.)
7484
+ *
7485
+ * Pure functions only — no I/O, no imports beyond the language. This is a
7486
+ * LEAF module: import it via its deep path, never from the root barrel.
7487
+ */
7488
+ /**
7489
+ * Normalize a raw kernel node id to the bare node id used for scoping.
7490
+ * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
7491
+ * processes; per-node settings are per-NODE, so strip the addon segment.
7492
+ * `undefined` / `null` / empty falls back to `'hub'`.
7493
+ */
7494
+ function normalizeNodeId(raw) {
7495
+ if (raw === void 0 || raw === null || raw === "") return "hub";
7496
+ const slashIdx = raw.indexOf("/");
7497
+ if (slashIdx < 0) return raw;
7498
+ const bare = raw.slice(0, slashIdx);
7499
+ return bare === "" ? "hub" : bare;
7500
+ }
7501
+ /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
7502
+ function nodeScopedKey(base, nodeId) {
7503
+ return `${base}@${normalizeNodeId(nodeId)}`;
7504
+ }
7505
+ /**
7506
+ * Read a node's value for a per-node field from the raw shared store:
7507
+ * the node-scoped key when present, otherwise `undefined`.
7508
+ * Deliberately NO bare-key fallback (see module doc) — the caller lets the
7509
+ * schema `default` win on `undefined`.
7510
+ */
7511
+ function readNodeValue(store, base, nodeId) {
7512
+ return store[nodeScopedKey(base, nodeId)];
7513
+ }
7514
+ /**
7515
+ * Re-map a UI/settings patch so every bare perNode field persists under the
7516
+ * TARGET node's scoped key; all other keys pass through unchanged. Used on
7517
+ * the write path so a save for one node never clobbers another node's value
7518
+ * (and the bare key is never written). Returns a new object — the input
7519
+ * patch is not mutated.
7520
+ */
7521
+ function scopePatch(patch, perNodeKeys, nodeId) {
7522
+ const out = {};
7523
+ for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
7524
+ return out;
7525
+ }
7526
+ /**
7527
+ * Project the raw shared store onto the bare schema keys for ONE node so a
7528
+ * UI schema (whose field keys are bare) hydrates from that node's own
7529
+ * values:
7530
+ *
7531
+ * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
7532
+ * - Every bare perNode key is dropped from the pass-through (a stray bare
7533
+ * legacy key must never hydrate any node — no bare fallback).
7534
+ * - THIS node's effective value ({@link readNodeValue}) is then laid onto
7535
+ * each bare perNode key; when the node has no scoped key the bare key is
7536
+ * left ABSENT so the field's schema `default` wins.
7537
+ *
7538
+ * Returns a new object — the input store is not mutated.
7539
+ */
7540
+ function projectStore(store, perNodeKeys, nodeId) {
7541
+ const out = {};
7542
+ for (const [key, value] of Object.entries(store)) {
7543
+ if (key.includes("@")) continue;
7544
+ if (perNodeKeys.has(key)) continue;
7545
+ out[key] = value;
7546
+ }
7547
+ for (const base of perNodeKeys) {
7548
+ const value = readNodeValue(store, base, nodeId);
7549
+ if (value !== void 0) out[base] = value;
7550
+ }
7551
+ return out;
7552
+ }
7553
+ /** Every scope, in the order the guard and the docs list them. */
7554
+ var SCOPED_SETTINGS_SCOPES = [
7555
+ "cluster",
7556
+ "device-defaults",
7557
+ "node"
7558
+ ];
6973
7559
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6974
7560
  var KeychainWriteRefusedError = class extends Error {
6975
7561
  fieldPath;
@@ -6980,7 +7566,7 @@ var KeychainWriteRefusedError = class extends Error {
6980
7566
  }
6981
7567
  };
6982
7568
  var KEEP = { kind: "keep" };
6983
- function isRecord$6(value) {
7569
+ function isRecord$4(value) {
6984
7570
  return typeof value === "object" && value !== null && !Array.isArray(value);
6985
7571
  }
6986
7572
  function defaultMintId() {
@@ -6993,7 +7579,7 @@ function collectSecretMarkerRefs(value, out = []) {
6993
7579
  return out;
6994
7580
  }
6995
7581
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
6996
- else if (isRecord$6(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
7582
+ else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
6997
7583
  return out;
6998
7584
  }
6999
7585
  async function storedValueEquals(secrets, marker, candidate) {
@@ -7048,7 +7634,7 @@ function rowId(row, idKey) {
7048
7634
  return null;
7049
7635
  }
7050
7636
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
7051
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$6) : [];
7637
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
7052
7638
  if (!Array.isArray(incoming)) {
7053
7639
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
7054
7640
  return {
@@ -7064,7 +7650,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
7064
7650
  const kept = /* @__PURE__ */ new Set();
7065
7651
  const rows = [];
7066
7652
  for (const row of incoming) {
7067
- if (!isRecord$6(row)) {
7653
+ if (!isRecord$4(row)) {
7068
7654
  rows.push(row);
7069
7655
  continue;
7070
7656
  }
@@ -7089,7 +7675,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
7089
7675
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
7090
7676
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
7091
7677
  case "object": {
7092
- if (!isRecord$6(incoming)) {
7678
+ if (!isRecord$4(incoming)) {
7093
7679
  if (incoming === void 0) return KEEP;
7094
7680
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
7095
7681
  return {
@@ -7097,7 +7683,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
7097
7683
  value: incoming
7098
7684
  };
7099
7685
  }
7100
- const storedObj = isRecord$6(stored) ? stored : {};
7686
+ const storedObj = isRecord$4(stored) ? stored : {};
7101
7687
  return {
7102
7688
  kind: "value",
7103
7689
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -7220,7 +7806,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
7220
7806
  value: items
7221
7807
  };
7222
7808
  }
7223
- if (isRecord$6(v)) {
7809
+ if (isRecord$4(v)) {
7224
7810
  const out = {};
7225
7811
  for (const [k, child] of Object.entries(v)) {
7226
7812
  const s = substitute(child);
@@ -7252,7 +7838,7 @@ var SecretOverwriteRefusedError = class extends Error {
7252
7838
  this.name = "SecretOverwriteRefusedError";
7253
7839
  }
7254
7840
  };
7255
- function isRecord$5(value) {
7841
+ function isRecord$3(value) {
7256
7842
  return typeof value === "object" && value !== null && !Array.isArray(value);
7257
7843
  }
7258
7844
  function resolvedValue(pass, marker) {
@@ -7281,7 +7867,7 @@ function inArray(pass, incoming, stored) {
7281
7867
  return incoming.map((item, index) => {
7282
7868
  const twin = stored[index];
7283
7869
  if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
7284
- if (isRecord$5(item) && isRecord$5(twin)) return inArrayRow(pass, item, twin);
7870
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
7285
7871
  if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
7286
7872
  return item;
7287
7873
  });
@@ -7292,7 +7878,7 @@ function inArrayRow(pass, incoming, stored) {
7292
7878
  const twin = stored[key];
7293
7879
  if (isSecretMarker(twin)) {
7294
7880
  if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
7295
- } else if (isRecord$5(value) && isRecord$5(twin)) out[key] = inArrayRow(pass, value, twin);
7881
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
7296
7882
  else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
7297
7883
  }
7298
7884
  return out;
@@ -7300,7 +7886,7 @@ function inArrayRow(pass, incoming, stored) {
7300
7886
  async function walk(pass, incoming, stored) {
7301
7887
  if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
7302
7888
  if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
7303
- if (!isRecord$5(incoming) || !isRecord$5(stored)) return incoming;
7889
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
7304
7890
  const out = { ...incoming };
7305
7891
  for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
7306
7892
  return out;
@@ -7331,7 +7917,7 @@ async function restoreUnchangedSecrets(input) {
7331
7917
  function isJsonEqual(a, b) {
7332
7918
  if (Object.is(a, b)) return true;
7333
7919
  if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
7334
- if (isRecord$5(a) && isRecord$5(b)) {
7920
+ if (isRecord$3(a) && isRecord$3(b)) {
7335
7921
  const keys = Object.keys(a);
7336
7922
  if (keys.length !== Object.keys(b).length) return false;
7337
7923
  return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
@@ -7355,7 +7941,7 @@ function markerKeysOf(blob, owner) {
7355
7941
  }
7356
7942
  function nodeFromStored(value, owner) {
7357
7943
  if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
7358
- if (!isRecord$5(value)) return null;
7944
+ if (!isRecord$3(value)) return null;
7359
7945
  const children = /* @__PURE__ */ new Map();
7360
7946
  for (const [key, child] of Object.entries(value)) {
7361
7947
  const node = nodeFromStored(child, owner);
@@ -7852,13 +8438,48 @@ var BaseAddon = class {
7852
8438
  if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7853
8439
  return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7854
8440
  }
7855
- async runBound(migrations, options) {
8441
+ /**
8442
+ * A device addon states its instance kind once, before its migrations run, and the one-switch
8443
+ * migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
8444
+ * catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
8445
+ * on every declare).
8446
+ */
8447
+ declareRegistrySwitch(spec) {
8448
+ this.registrySwitchSpec = spec;
8449
+ }
8450
+ registrySwitchSpec = null;
8451
+ registrySwitchBound() {
8452
+ const spec = this.registrySwitchSpec;
8453
+ if (spec === null) return [];
8454
+ const api = this.ctx.migrationApi;
8455
+ if (api === void 0) {
8456
+ this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
8457
+ return [];
8458
+ }
8459
+ return migrationSet([registrySwitchToBodyMigration({
8460
+ addonId: this.ctx.id,
8461
+ date: "2026-11-06",
8462
+ seq: 1e3,
8463
+ initialBody: spec.initialBody
8464
+ })], (a) => registrySwitchPortsOver({
8465
+ api: integrationRowsApiOver(a),
8466
+ records: switchRecordsOverMigrationApi(a),
8467
+ kind: spec.kind
8468
+ })).bind(api);
8469
+ }
8470
+ async runBound(declared, options) {
8471
+ const added = this.registrySwitchBound();
8472
+ const migrations = [...declared, ...added];
8473
+ const phased = options?.only === void 0 || added.length === 0 ? options : {
8474
+ ...options,
8475
+ only: [...options.only, ...added.map((m) => m.meta.id)]
8476
+ };
7856
8477
  const api = this.ctx.api.migrations;
7857
8478
  const report = await runAddonMigrations({
7858
8479
  declareOwner: (input) => api.declareOwner.mutate(input),
7859
8480
  startMigration: (input) => api.startMigration.mutate(input),
7860
8481
  finishMigration: (input) => api.finishMigration.mutate(input)
7861
- }, migrations, this.ctx.logger, options);
8482
+ }, migrations, this.ctx.logger, phased);
7862
8483
  if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
7863
8484
  return report;
7864
8485
  }
@@ -8931,221 +9552,6 @@ function normalizeAddonInitResult(result) {
8931
9552
  if (Array.isArray(result)) return { providers: result };
8932
9553
  return result;
8933
9554
  }
8934
- var PREFIX = "records/";
8935
- /** The base of every records failure. `detail` is the human part of the message. */
8936
- var RecordsError = class extends Error {
8937
- code;
8938
- detail;
8939
- constructor(code, detail) {
8940
- super(`${PREFIX}${code}: ${detail}`);
8941
- this.name = "RecordsError";
8942
- this.code = code;
8943
- this.detail = detail;
8944
- }
8945
- };
8946
- /** The keychain could not store or serve a value: explicit, never an empty string. */
8947
- var RecordSecretUnavailableError = class extends RecordsError {
8948
- constructor(detail) {
8949
- super("secret-unavailable", detail);
8950
- this.name = "RecordSecretUnavailableError";
8951
- }
8952
- };
8953
- var InvalidRecordError = class extends RecordsError {
8954
- constructor(detail) {
8955
- super("invalid-record", detail);
8956
- this.name = "InvalidRecordError";
8957
- }
8958
- };
8959
- /** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
8960
- var DeclarationRefusedError = class extends RecordsError {
8961
- constructor(detail) {
8962
- super("declaration-refused", detail);
8963
- this.name = "DeclarationRefusedError";
8964
- }
8965
- };
8966
- /** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
8967
- /** The files a kind may live in. `history` is device-history's (D850), never records. */
8968
- var RECORD_DATABASES = ["settings", "events"];
8969
- /** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
8970
- var RECORD_CLASSES = [
8971
- "config",
8972
- "ledger",
8973
- "audit",
8974
- "mirror",
8975
- "ephemeral"
8976
- ];
8977
- var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
8978
- var RECORD_MAX_DATA_BYTES = 1024 * 1024;
8979
- var RECORD_BATCH_MAX = 1e3;
8980
- var RECORD_QUERY_MAX = 1e3;
8981
- /** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
8982
- var RECORD_SETTINGS_MAX_ROWS = 5e4;
8983
- /** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
8984
- var RECORD_SECRET_COLLECTION_PREFIX = "records:";
8985
- /**
8986
- * Secret fields of a record, addressed the way a Zod schema declares them
8987
- * (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
8988
- * (`auth.accessToken`, `headers[].value`).
8989
- *
8990
- * `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
8991
- * names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
8992
- * key releases exactly that key's secret.
8993
- *
8994
- * Array elements are matched by a DECLARED id key (`secretArrayKeys`:
8995
- * `{ headers: 'name' }`), never by index, so reordering a list keeps every
8996
- * keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
8997
- * leaf names its element: `headers[X-Api].value`.
8998
- *
8999
- * Pure and browser-safe. Nothing here mutates: every transform returns a new value.
9000
- */
9001
- /** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
9002
- function parseSecretPath(path) {
9003
- if (path.length === 0) throw new InvalidRecordError("an empty secret path");
9004
- return path.split(".").map((raw) => {
9005
- const each = raw.endsWith("[]");
9006
- const map = raw.endsWith("{}");
9007
- const key = each || map ? raw.slice(0, -2) : raw;
9008
- if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
9009
- return {
9010
- key,
9011
- each,
9012
- map
9013
- };
9014
- });
9015
- }
9016
- /** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
9017
- function secretArrayPrefixes(path) {
9018
- const segments = parseSecretPath(path);
9019
- const prefixes = [];
9020
- const walked = [];
9021
- for (const segment of segments) {
9022
- walked.push(segment.key);
9023
- if (segment.each) prefixes.push(walked.join("."));
9024
- }
9025
- return prefixes;
9026
- }
9027
- function isRecord$4(value) {
9028
- return typeof value === "object" && value !== null && !Array.isArray(value);
9029
- }
9030
- function elementId(element, idKey, declared, prefix) {
9031
- const id = isRecord$4(element) ? element[idKey] : void 0;
9032
- if (typeof id !== "string" || id.length === 0) throw new InvalidRecordError(`"${declared}": every element of "${prefix}" needs a non-empty string "${idKey}" to carry a secret`);
9033
- return id;
9034
- }
9035
- /**
9036
- * Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
9037
- * visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
9038
- * result is a new body, `data` is untouched.
9039
- */
9040
- var REMOVE_LEAF = Symbol("remove-leaf");
9041
- function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
9042
- if (!isRecord$4(node)) return node;
9043
- const segment = segments[index];
9044
- if (segment === void 0) return node;
9045
- if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
9046
- const child = node[segment.key];
9047
- const keys = [...walkedKeys, segment.key];
9048
- const last = index === segments.length - 1;
9049
- if (segment.each) {
9050
- if (!Array.isArray(child)) return node;
9051
- const prefix = keys.join(".");
9052
- const idKey = arrayKeys[prefix];
9053
- if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
9054
- const mapped = child.map((element) => {
9055
- const id = elementId(element, idKey, declared, prefix);
9056
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
9057
- return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
9058
- });
9059
- return {
9060
- ...node,
9061
- [segment.key]: mapped
9062
- };
9063
- }
9064
- if (segment.map) {
9065
- if (!isRecord$4(child)) return node;
9066
- const kept = Object.entries(child).map(([mapKey, value]) => {
9067
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
9068
- if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
9069
- return [mapKey, visit({
9070
- declared,
9071
- concrete,
9072
- value
9073
- })];
9074
- }).filter(([, value]) => value !== REMOVE_LEAF);
9075
- return {
9076
- ...node,
9077
- [segment.key]: Object.fromEntries(kept)
9078
- };
9079
- }
9080
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
9081
- if (last) {
9082
- const replacement = visit({
9083
- declared,
9084
- concrete,
9085
- value: child
9086
- });
9087
- if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
9088
- return {
9089
- ...node,
9090
- [segment.key]: replacement
9091
- };
9092
- }
9093
- return {
9094
- ...node,
9095
- [segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
9096
- };
9097
- }
9098
- /** Replace/remove every present secret leaf; returns a NEW body. */
9099
- function mapSecretLeaves(data, paths, arrayKeys, visit) {
9100
- let current = data;
9101
- for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
9102
- return current;
9103
- }
9104
- /**
9105
- * The keychain collection name a kind's secrets live under. Prefixed so a
9106
- * record's refs never collide with the refs a legacy collection of the same name
9107
- * already holds during an adoption.
9108
- */
9109
- function recordSecretCollection(kind) {
9110
- return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
9111
- }
9112
- /** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
9113
- function recordSecretRef(owner, kind, rowId, concretePath) {
9114
- return buildSecretRef({
9115
- owner,
9116
- scope: {
9117
- kind: "row",
9118
- collection: recordSecretCollection(kind),
9119
- rowId
9120
- },
9121
- fieldPath: concretePath
9122
- });
9123
- }
9124
- /**
9125
- * A stored secret, as an admin read shows it: a VIEW naming the row's own
9126
- * keychain ref (`set: true`), never the value and no longer the bare redaction
9127
- * token. The form hands it to the secret field, which reveals the value by ref
9128
- * through the audited `keychain-admin.reveal`; sent back untouched it keeps the
9129
- * stored secret (the records door reads a view as KEEP).
9130
- *
9131
- * ONE implementation for the entries service and for every addon that serves
9132
- * its own instances (`RecordIntegrationInstances`).
9133
- */
9134
- function isRecord$3(value) {
9135
- return typeof value === "object" && value !== null && !Array.isArray(value);
9136
- }
9137
- function secretViewsOf(owner, kind, id, decl, data) {
9138
- if (decl.secretPaths.length === 0) return data;
9139
- const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
9140
- if (leaf.value !== "__camstack_redacted__") return leaf.value;
9141
- return {
9142
- $secret: recordSecretRef(owner, kind, id, leaf.concrete),
9143
- v: 1,
9144
- set: true
9145
- };
9146
- });
9147
- return isRecord$3(shown) ? shown : data;
9148
- }
9149
9555
  /**
9150
9556
  * The share-view scope kinds a share-link token can carry. The hub mints
9151
9557
  * and validates them (`ShareViewGrantSchema` builds its
@@ -9399,6 +9805,7 @@ function defineRecordKinds(specs) {
9399
9805
  function entryBody(shape) {
9400
9806
  return object({
9401
9807
  name: string().min(1),
9808
+ enabled: boolean().optional(),
9402
9809
  ...shape
9403
9810
  });
9404
9811
  }
@@ -11238,6 +11645,10 @@ Object.freeze({
11238
11645
  "all",
11239
11646
  "one"
11240
11647
  ]
11648
+ },
11649
+ {
11650
+ "path": "positionUpdatedAt",
11651
+ "valueType": "number"
11241
11652
  }
11242
11653
  ],
11243
11654
  "meter": [{
@@ -11492,22 +11903,6 @@ Object.freeze({
11492
11903
  "path": "pumpRunning",
11493
11904
  "valueType": "boolean"
11494
11905
  },
11495
- {
11496
- "path": "lastDrink",
11497
- "valueType": "number"
11498
- },
11499
- {
11500
- "path": "currentHourDrink",
11501
- "valueType": "number"
11502
- },
11503
- {
11504
- "path": "last24hDrink",
11505
- "valueType": "number"
11506
- },
11507
- {
11508
- "path": "todayDrink",
11509
- "valueType": "number"
11510
- },
11511
11906
  {
11512
11907
  "path": "error",
11513
11908
  "valueType": "string"
@@ -12073,12 +12468,66 @@ Object.freeze({
12073
12468
  }
12074
12469
  ]
12075
12470
  });
12471
+ Object.freeze({
12472
+ "actions": { "run": 363e4 },
12473
+ "audio-analyzer": { "classify": 3e4 },
12474
+ "custom-model-registry": { "importModelBundle": 18e5 },
12475
+ "database-snapshot": { "writeSnapshot": 18e5 },
12476
+ "device-manager": {
12477
+ "migrateDevice": 72e4,
12478
+ "runDiscoverySweep": 12e4
12479
+ },
12480
+ "device-provider": { "reloadDevice": 18e4 },
12481
+ "llm": {
12482
+ "generate": 6e5,
12483
+ "generateVision": 6e5,
12484
+ "testProfile": 6e5
12485
+ },
12486
+ "llm-runtime": {
12487
+ "complete": 6e5,
12488
+ "completeApple": 6e5,
12489
+ "ensureStarted": 6e5,
12490
+ "installModel": 36e5
12491
+ },
12492
+ "local-network": { "scanNetwork": 9e4 },
12493
+ "model-convert": { "convert": 6e5 },
12494
+ "pipeline-analytics": {
12495
+ "addRetrainFrameFromRecording": 6e4,
12496
+ "offerRetrainArchive": 12e4,
12497
+ "proposeRetrainAnnotationsWithLlm": 18e4,
12498
+ "resolveRetrainTrainingCorpus": 6e4,
12499
+ "writeRetrainArchive": 36e5
12500
+ },
12501
+ "server-management": { "applyServerUpdate": 96e4 },
12502
+ "terminal-session": { "pullOutput": 15e3 },
12503
+ "training": {
12504
+ "canaryResult": 12e4,
12505
+ "cancelJob": 12e4,
12506
+ "planJob": 6e4,
12507
+ "registerResult": 18e5,
12508
+ "rollbackCanary": 12e4,
12509
+ "startJob": 12e4,
12510
+ "startJobBatch": 12e4
12511
+ },
12512
+ "training-provider": {
12513
+ "cancelJob": 6e4,
12514
+ "cleanupJob": 3e5,
12515
+ "getJob": 6e4,
12516
+ "listJobEvents": 6e4,
12517
+ "listJobs": 12e4,
12518
+ "offerArtifact": 3e5,
12519
+ "readResult": 3e5,
12520
+ "submitJob": 18e5,
12521
+ "uploadDataset": 72e5,
12522
+ "validateCredentials": 3e4
12523
+ }
12524
+ });
12076
12525
  object({
12077
12526
  code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
12078
12527
  params: record(string(), union([string(), number()])).optional()
12079
12528
  });
12080
12529
  //#endregion
12081
- //#region ../types/dist/composition-pOHbTzRB.mjs
12530
+ //#region ../types/dist/composition-BmBHuDTQ.mjs
12082
12531
  /**
12083
12532
  * The ffmpeg build every CamStack node downloads, per platform and arch.
12084
12533
  *
@@ -12382,7 +12831,7 @@ var table = {
12382
12831
  },
12383
12832
  dwell: {
12384
12833
  minArgs: 3,
12385
- maxArgs: 3,
12834
+ maxArgs: 4,
12386
12835
  apply: () => {
12387
12836
  throw new ExpressionEvalError("dwell: stateful evaluation context is required");
12388
12837
  }
@@ -13425,212 +13874,6 @@ var IntegrationInstanceRefSchema = object({
13425
13874
  ]),
13426
13875
  candidateStableId: string().optional()
13427
13876
  });
13428
- /**
13429
- * `RecordIntegrationInstances` - the `integration-instances` provider over ONE
13430
- * entry kind, so an addon that holds a connection serves it in ~30 lines.
13431
- *
13432
- * Every instance is one record of the addon's own kind, keyed by the
13433
- * `integrations` registry id. The records door does the secret work: a field the
13434
- * kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
13435
- * deleting the row deletes the secret, and one row's value is never another's.
13436
- *
13437
- * Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
13438
- * token or the view the form was given KEEP the stored secret;
13439
- * `{ $secretClear: true }` clears it; any other string replaces it.
13440
- */
13441
- /** The most instances one addon lists (an integrations page, not a table). */
13442
- var INSTANCES_LIST_MAX = 1e3;
13443
- /** The keys of the kind's secret fields that sit at the top level of the body. */
13444
- function topLevelSecretKeys(paths) {
13445
- return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
13446
- }
13447
- /** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
13448
- function secretMapKeys(paths) {
13449
- return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
13450
- }
13451
- /**
13452
- * A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
13453
- * view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
13454
- * or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
13455
- */
13456
- function secretMapPatch(value) {
13457
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
13458
- const out = {};
13459
- for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
13460
- else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
13461
- return Object.keys(out).length > 0 ? out : null;
13462
- }
13463
- /** Does the kind's body schema carry an `enabled` field? */
13464
- function declaresEnabled(kind) {
13465
- const json = toJSONSchema(kind.schema, {
13466
- unrepresentable: "any",
13467
- io: "input"
13468
- });
13469
- const properties = Reflect.get(json, "properties");
13470
- return typeof properties === "object" && properties !== null && "enabled" in properties;
13471
- }
13472
- var RecordIntegrationInstances = class {
13473
- records;
13474
- kind;
13475
- hooks;
13476
- handle;
13477
- secretKeys;
13478
- secretMaps;
13479
- nameField;
13480
- /** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
13481
- registryOwnsEnabled;
13482
- constructor(records, kind, hooks) {
13483
- this.records = records;
13484
- this.kind = kind;
13485
- this.hooks = hooks;
13486
- this.handle = records.kind(kind);
13487
- this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
13488
- this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
13489
- this.nameField = kind.declaration.entry?.nameField ?? "name";
13490
- this.registryOwnsEnabled = hooks.description.role === "devices";
13491
- if (this.registryOwnsEnabled && declaresEnabled(kind)) throw new Error(`kind "${kind.name}": the integrations registry owns the on/off switch of a role "devices" addon, so the body must not declare "enabled"`);
13492
- }
13493
- /**
13494
- * One instance read for the addon's own runtime; null when absent. When the keychain is
13495
- * locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
13496
- * caller can keep what it had instead of reconfiguring with an empty secret (D49).
13497
- */
13498
- async readResolved(id) {
13499
- try {
13500
- const record = await this.handle.getResolved(id);
13501
- return record === null ? null : {
13502
- id,
13503
- body: record.data,
13504
- enabled: record.data.enabled !== false,
13505
- secrets: "resolved"
13506
- };
13507
- } catch (err) {
13508
- if (!(err instanceof RecordSecretUnavailableError)) throw err;
13509
- const stored = await this.handle.get(id);
13510
- if (stored === null) return null;
13511
- return {
13512
- id,
13513
- body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
13514
- enabled: stored.data.enabled !== false,
13515
- secrets: "unavailable"
13516
- };
13517
- }
13518
- }
13519
- /** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
13520
- async getResolved(id) {
13521
- return (await this.readResolved(id))?.body ?? null;
13522
- }
13523
- /** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
13524
- async listResolved() {
13525
- const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
13526
- const out = [];
13527
- for (const record of page.records) {
13528
- const read = await this.readResolved(record.id);
13529
- if (read !== null) out.push(read);
13530
- }
13531
- return out;
13532
- }
13533
- viewOf(record) {
13534
- const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
13535
- const rawName = record.data[this.nameField];
13536
- const kind = this.hooks.kindOf?.(record.data);
13537
- const health = this.hooks.health?.(record.data, record.id);
13538
- return {
13539
- id: record.id,
13540
- name: typeof rawName === "string" ? rawName : record.id,
13541
- configured: this.hooks.configured(record.data),
13542
- ...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
13543
- formValues: shown,
13544
- ...kind !== void 0 ? { kind } : {},
13545
- ...health?.status !== void 0 ? { status: health.status } : {},
13546
- ...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
13547
- };
13548
- }
13549
- describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
13550
- ...this.hooks.description,
13551
- mintsId: true
13552
- };
13553
- instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
13554
- listInstances = async () => {
13555
- return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
13556
- };
13557
- getInstance = async ({ id }) => {
13558
- const record = await this.handle.get(id);
13559
- return record === null ? null : this.viewOf(record);
13560
- };
13561
- /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13562
- createInstance = async ({ id, name, kind, values }) => {
13563
- const minted = id ?? this.hooks.mintId?.({
13564
- name,
13565
- ...kind !== void 0 ? { kind } : {}
13566
- });
13567
- if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
13568
- await this.handle.put({
13569
- id: minted,
13570
- data: this.hooks.initialBody(name, kind)
13571
- }, { ifRev: 0 });
13572
- const patch = this.patchOf(values ?? {});
13573
- if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13574
- await this.hooks.onChanged?.(minted, "created");
13575
- return { id: minted };
13576
- };
13577
- updateInstance = async ({ id, name, values }) => {
13578
- const patch = this.patchOf(values);
13579
- if (name !== void 0) patch[this.nameField] = name;
13580
- await this.handle.patch(id, patch);
13581
- await this.hooks.onChanged?.(id, "updated");
13582
- return { ok: true };
13583
- };
13584
- /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13585
- patchOf(values) {
13586
- const patch = {};
13587
- for (const [key, value] of Object.entries(values)) {
13588
- if (value === void 0) continue;
13589
- if (this.secretMaps.has(key)) {
13590
- const entries = secretMapPatch(value);
13591
- if (entries !== null) patch[key] = entries;
13592
- } else if (!this.secretKeys.has(key)) patch[key] = value;
13593
- else if (isSecretClear(value)) patch[key] = null;
13594
- else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13595
- }
13596
- return patch;
13597
- }
13598
- /** The switch lives in the record body; the addon is told so it applies it (D996). */
13599
- setInstanceEnabled = async ({ id, enabled }) => {
13600
- if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
13601
- await this.handle.patch(id, { enabled });
13602
- await this.hooks.onChanged?.(id, "enabled");
13603
- return { ok: true };
13604
- };
13605
- /** The row and its keychain refs go together (the records door). */
13606
- deleteInstance = async ({ id }) => {
13607
- await this.handle.delete(id);
13608
- await this.hooks.onChanged?.(id, "deleted");
13609
- return { ok: true };
13610
- };
13611
- testInstance = async (input) => {
13612
- if (this.hooks.test === void 0) return {
13613
- success: false,
13614
- status: "unsupported",
13615
- error: "This integration declares no connection test"
13616
- };
13617
- return this.hooks.test(input);
13618
- };
13619
- /** The flat provider object to hand to `registerProvider`. */
13620
- toProvider() {
13621
- return {
13622
- describe: this.describe,
13623
- instanceFormSchema: this.instanceFormSchema,
13624
- listInstances: this.listInstances,
13625
- getInstance: this.getInstance,
13626
- createInstance: this.createInstance,
13627
- updateInstance: this.updateInstance,
13628
- setInstanceEnabled: this.setInstanceEnabled,
13629
- deleteInstance: this.deleteInstance,
13630
- testInstance: this.testInstance
13631
- };
13632
- }
13633
- };
13634
13877
  var EncodeProfileSchema = object({
13635
13878
  video: object({
13636
13879
  codec: _enum([
@@ -19815,31 +20058,21 @@ var APPLIANCE_CAP_VOCABULARY = {
19815
20058
  "pet-fountain": {
19816
20059
  scope: "device",
19817
20060
  noun: t("Pet fountain", "Fontana per animali"),
19818
- actions: [
19819
- {
19820
- id: "petFountain.pumpOn",
19821
- method: "setPump",
19822
- label: t("Pump on", "Pompa accesa"),
19823
- phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
19824
- icon: "play",
19825
- args: { on: true }
19826
- },
19827
- {
19828
- id: "petFountain.pumpOff",
19829
- method: "setPump",
19830
- label: t("Pump off", "Pompa spenta"),
19831
- phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
19832
- icon: "square",
19833
- args: { on: false }
19834
- },
19835
- {
19836
- id: "petFountain.resetDailyConsumption",
19837
- method: "resetDailyConsumption",
19838
- label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
19839
- phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
19840
- icon: "rotate-ccw"
19841
- }
19842
- ],
20061
+ actions: [{
20062
+ id: "petFountain.pumpOn",
20063
+ method: "setPump",
20064
+ label: t("Pump on", "Pompa accesa"),
20065
+ phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
20066
+ icon: "play",
20067
+ args: { on: true }
20068
+ }, {
20069
+ id: "petFountain.pumpOff",
20070
+ method: "setPump",
20071
+ label: t("Pump off", "Pompa spenta"),
20072
+ phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
20073
+ icon: "square",
20074
+ args: { on: false }
20075
+ }],
19843
20076
  state: [{
19844
20077
  kind: "boolean",
19845
20078
  field: "empty",
@@ -43733,8 +43966,15 @@ var ActionInputSchema = object({
43733
43966
  var ActionRunOriginSchema = object({
43734
43967
  /** The automation block whose step started it. */
43735
43968
  blockId: string().min(1).optional() });
43736
- /** `started` = the caller did not ask to wait. */
43737
- var ActionRunOutcomeSchema = union([AutomationRunOutcomeSchema, literal("started")]);
43969
+ /**
43970
+ * `started` = the caller did not ask to wait. `timed-out` = the run reached the
43971
+ * ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
43972
+ */
43973
+ var ActionRunOutcomeSchema = union([
43974
+ AutomationRunOutcomeSchema,
43975
+ literal("started"),
43976
+ literal("timed-out")
43977
+ ]);
43738
43978
  var ActionRunResultSchema = object({
43739
43979
  runId: string().min(1),
43740
43980
  outcome: ActionRunOutcomeSchema,
@@ -44256,6 +44496,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44256
44496
  kind: "mutation",
44257
44497
  auth: "admin"
44258
44498
  });
44499
+ /** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
44500
+ var ACTION_RUN_TIMEOUT_MS = 363e4;
44259
44501
  /**
44260
44502
  * actions — the ONE surface for runnable actions, for the UI and for
44261
44503
  * automations. Provided by the core-blocks builtin on the hub.
@@ -44274,6 +44516,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44274
44516
  * An admin, and an in-process caller (an automation block), may run any action.
44275
44517
  * Every refusal is typed (`[not-linked] …`) and logged.
44276
44518
  *
44519
+ * **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
44520
+ * run that reaches it and answers `timed-out` (never `ran`); an action whose
44521
+ * `wait` steps alone add up to more is refused at create/update
44522
+ * (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
44523
+ * waited call (an automation step) is never cut by the 60 s transport default.
44524
+ *
44277
44525
  * A second `run` of an action that is already running is REFUSED — traced and
44278
44526
  * logged — never queued.
44279
44527
  */
@@ -44300,7 +44548,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44300
44548
  role: "viewer",
44301
44549
  auth: "protected",
44302
44550
  kind: "mutation",
44303
- caller: "required"
44551
+ caller: "required",
44552
+ timeoutMs: ACTION_RUN_TIMEOUT_MS
44304
44553
  }), method(ActionIdInput, _void(), {
44305
44554
  kind: "mutation",
44306
44555
  auth: "admin"
@@ -48345,6 +48594,9 @@ var MediaPlayerStatusSchema = object({
48345
48594
  /** Repeat mode. Null when no repeat surface.
48346
48595
  * Pair with `DeviceFeature.MediaPlayerRepeat`. */
48347
48596
  repeat: MediaPlayerRepeatSchema.nullable(),
48597
+ /** Ms epoch when `position` was read from the device. Null when the driver
48598
+ * does not say; a UI that advances the position while playing counts from it. */
48599
+ positionUpdatedAt: number().nullable().default(null),
48348
48600
  /** Ms epoch when the slice was last updated. */
48349
48601
  lastChangedAt: number()
48350
48602
  });
@@ -48924,7 +49176,9 @@ var ThresholdTransformDraftSchema = object({
48924
49176
  comparison: _enum(["gte", "lte"]),
48925
49177
  threshold: number(),
48926
49178
  startDwellMs: number().nonnegative(),
48927
- stopDwellMs: number().nonnegative()
49179
+ stopDwellMs: number().nonnegative(),
49180
+ /** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
49181
+ minSamples: number().int().min(1).optional()
48928
49182
  });
48929
49183
  var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
48930
49184
  IdentityTransformDraftSchema,
@@ -53877,6 +54131,7 @@ var IntegrationWithStateSchema = object({
53877
54131
  id: string(),
53878
54132
  addonId: string(),
53879
54133
  name: string(),
54134
+ /** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
53880
54135
  enabled: boolean(),
53881
54136
  info: record(string(), unknown()).readonly(),
53882
54137
  /** The discovery candidate this integration was set up from (D984). */
@@ -53889,6 +54144,7 @@ var IntegrationLiteSchema = object({
53889
54144
  id: string(),
53890
54145
  addonId: string(),
53891
54146
  name: string(),
54147
+ /** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
53892
54148
  enabled: boolean(),
53893
54149
  info: record(string(), unknown()).readonly(),
53894
54150
  /** The discovery candidate this integration was set up from (D984). */
@@ -53988,7 +54244,6 @@ var TestConnectionResultSchema = object({
53988
54244
  var CreateIntegrationInputSchema = object({
53989
54245
  addonId: string(),
53990
54246
  name: string(),
53991
- enabled: boolean().optional(),
53992
54247
  info: record(string(), unknown()).optional(),
53993
54248
  /** `stableId` of the discovery candidate the form was seeded from (D984). */
53994
54249
  originStableId: string().optional(),
@@ -53997,6 +54252,11 @@ var CreateIntegrationInputSchema = object({
53997
54252
  var UpdateIntegrationInputSchema = object({
53998
54253
  id: string(),
53999
54254
  name: string().optional(),
54255
+ /**
54256
+ * Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
54257
+ * terminal), which keeps no instance record: the registry flag is its one store. Any other
54258
+ * integration is switched through `integration-instances.setInstanceEnabled`.
54259
+ */
54000
54260
  enabled: boolean().optional(),
54001
54261
  info: record(string(), unknown()).optional()
54002
54262
  });
@@ -54044,7 +54304,7 @@ var IntegrationInstanceIdSchema = string().min(1);
54044
54304
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
54045
54305
  /**
54046
54306
  * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
54047
- * instance is an integration that brings devices (the registry owns its on/off switch);
54307
+ * instance is an integration that brings devices (its record body owns the on/off switch);
54048
54308
  * `services`: a connection configured from the addon's own function page, never listed on
54049
54309
  * Integrations.
54050
54310
  * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
@@ -54087,18 +54347,38 @@ var IntegrationInstanceKindSchema = object({
54087
54347
  /** Relative hub path to disconnect that account. */
54088
54348
  disconnectPath: string().min(1).optional()
54089
54349
  });
54350
+ /**
54351
+ * How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
54352
+ * scans the network before any instance exists (the wizard offers the candidates); `account`: the
54353
+ * devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
54354
+ * instance and its candidates are claimed by it.
54355
+ */
54356
+ var IntegrationInstanceDiscoverySchema = object({
54357
+ mode: _enum([
54358
+ "none",
54359
+ "lan",
54360
+ "account"
54361
+ ]),
54362
+ scopedToInstance: boolean()
54363
+ });
54364
+ /**
54365
+ * One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
54366
+ * `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
54367
+ * The hub indexes these so the target's delete is refused while a link names it.
54368
+ */
54369
+ var IntegrationInstanceLinkSchema = object({
54370
+ kind: string().min(1),
54371
+ field: string().min(1),
54372
+ to: object({
54373
+ cap: string().min(1),
54374
+ kind: string().min(1).optional()
54375
+ })
54376
+ });
54090
54377
  var IntegrationInstanceDescriptionSchema = object({
54091
54378
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
54092
54379
  role: IntegrationInstanceRoleSchema,
54093
54380
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
54094
- discovery: object({
54095
- mode: _enum([
54096
- "none",
54097
- "lan",
54098
- "account"
54099
- ]),
54100
- scopedToInstance: boolean()
54101
- }).optional(),
54381
+ discovery: IntegrationInstanceDiscoverySchema.optional(),
54102
54382
  /** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
54103
54383
  instanceMode: IntegrationInstanceModeSchema,
54104
54384
  /** What the instance is, for the UI (`destination`, `relay`, `account`). */
@@ -54119,7 +54399,9 @@ var IntegrationInstanceDescriptionSchema = object({
54119
54399
  * `createInstance` without an `id` works: the provider mints it. Absent means the caller must
54120
54400
  * send an id (the UI then mints an opaque one).
54121
54401
  */
54122
- mintsId: boolean().optional()
54402
+ mintsId: boolean().optional(),
54403
+ /** The links to other instances the provider's kinds declare; absent means none. */
54404
+ links: array(IntegrationInstanceLinkSchema).optional()
54123
54405
  });
54124
54406
  var IntegrationInstanceStatusSchema = object({
54125
54407
  state: _enum([
@@ -54139,8 +54421,8 @@ var IntegrationInstanceSchema = object({
54139
54421
  configured: boolean(),
54140
54422
  /**
54141
54423
  * The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
54142
- * so a row written before the field existed is on). Absent when the `integrations` registry
54143
- * owns the switch (`describe().role` is `devices`): read it from the registry row.
54424
+ * so a row written before the field existed is on). The same for every role, `devices` included:
54425
+ * the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
54144
54426
  */
54145
54427
  enabled: boolean().optional(),
54146
54428
  /** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
@@ -54190,7 +54472,8 @@ var integrationInstancesCapability = {
54190
54472
  auth: "admin"
54191
54473
  }),
54192
54474
  /**
54193
- * Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
54475
+ * Switch ONE instance on or off, for every role; a missing record is created from the addon's
54476
+ * initial body. A row control, not a form field: `updateInstance.values` is the
54194
54477
  * form patch (D62, D996). An off instance keeps its record and secrets and does no work.
54195
54478
  */
54196
54479
  setInstanceEnabled: method(object({
@@ -57001,6 +57284,8 @@ var MigrationIntegrationSchema = object({
57001
57284
  addonId: string(),
57002
57285
  name: string(),
57003
57286
  info: Rows,
57287
+ /** The registry's stored switch: read by the one-switch migration, nothing else. */
57288
+ enabled: boolean().optional(),
57004
57289
  originStableId: string().optional()
57005
57290
  });
57006
57291
  var MigrationDeviceSchema = object({
@@ -66538,14 +66823,6 @@ object({
66538
66823
  empty: boolean().nullable(),
66539
66824
  /** True while the pump is running. Null while unknown. */
66540
66825
  pumpRunning: boolean().nullable(),
66541
- /** Water drunk in the last drink, in litres. */
66542
- lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
66543
- /** Water drunk in the current hour, in litres. */
66544
- currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
66545
- /** Water drunk over the last 24 hours (rolling), in litres. */
66546
- last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
66547
- /** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
66548
- todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
66549
66826
  /** Decoded fault message. Null means healthy; a non-null string is an active fault. */
66550
66827
  error: string().nullable(),
66551
66828
  /** Ms epoch when the slice was last refreshed. */
@@ -66558,9 +66835,6 @@ DeviceType.PetFountain, method(object({
66558
66835
  }), _void(), {
66559
66836
  kind: "mutation",
66560
66837
  auth: "protected"
66561
- }), method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
66562
- kind: "mutation",
66563
- auth: "protected"
66564
66838
  });
66565
66839
  /**
66566
66840
  * The wire shapes of the Auto tune plan and apply (D745), used by the
@@ -81934,13 +82208,6 @@ Object.freeze({
81934
82208
  access: "view",
81935
82209
  role: "viewer"
81936
82210
  },
81937
- "petFountain.resetDailyConsumption": {
81938
- capName: "pet-fountain",
81939
- capScope: "device",
81940
- addonId: null,
81941
- access: "delete",
81942
- role: "viewer"
81943
- },
81944
82211
  "petFountain.setPump": {
81945
82212
  capName: "pet-fountain",
81946
82213
  capScope: "device",
@@ -88337,11 +88604,6 @@ Object.freeze({
88337
88604
  form: "single",
88338
88605
  optional: false
88339
88606
  }],
88340
- "petFountain.resetDailyConsumption": [{
88341
- name: "deviceId",
88342
- form: "single",
88343
- optional: false
88344
- }],
88345
88607
  "petFountain.setPump": [{
88346
88608
  name: "deviceId",
88347
88609
  form: "single",
@@ -91085,48 +91347,53 @@ object({
91085
91347
  delay: number().nonnegative().optional(),
91086
91348
  commands: record(string(), unknown())
91087
91349
  });
91088
- var BrokerInUseError = class extends Error {
91089
- brokerId;
91350
+ var InstanceInUseError = class extends Error {
91351
+ instanceId;
91090
91352
  users;
91091
- name = "BrokerInUseError";
91092
- constructor(brokerId, users) {
91093
- super(`broker '${brokerId}' is still in use by ${users.map((u) => `${u.kind} '${u.name ?? u.id}' (${u.id})`).join(", ")}; unlink them first`);
91094
- this.brokerId = brokerId;
91353
+ name = "InstanceInUseError";
91354
+ constructor(instanceId, users) {
91355
+ super(`instance '${instanceId}' is still in use by ${users.map((u) => `${u.kind} '${u.name ?? u.id}' (${u.id})`).join(", ")}; unlink them first`);
91356
+ this.instanceId = instanceId;
91095
91357
  this.users = users;
91096
91358
  }
91097
91359
  };
91098
- /** Throw {@link BrokerInUseError} when any finder names a user of `brokerId`. */
91099
- async function assertBrokerUnused(brokerId, finders) {
91360
+ /** Throw {@link InstanceInUseError} when any finder names a user of `instanceId`. */
91361
+ async function assertInstanceUnused(instanceId, finders) {
91100
91362
  const users = [];
91101
- for (const finder of finders) users.push(...await finder.find(brokerId));
91102
- if (users.length > 0) throw new BrokerInUseError(brokerId, users);
91363
+ for (const finder of finders) users.push(...await finder.find(instanceId));
91364
+ if (users.length > 0) throw new InstanceInUseError(instanceId, users);
91365
+ }
91366
+ function namesInstance(value, instanceId) {
91367
+ if (Array.isArray(value)) return value.includes(instanceId);
91368
+ return value === instanceId;
91103
91369
  }
91104
91370
  /**
91105
91371
  * Users reached through another addon's listed rows (an addon cannot read a record kind it does
91106
- * not own): every row whose `field` holds the broker id. `list` is a cap call the owner serves.
91372
+ * not own): every row whose `field` holds the instance id, as a string or in a string list.
91373
+ * `list` is a cap call the owner serves.
91107
91374
  */
91108
91375
  function fieldUserFinder(spec) {
91109
- return { find: async (brokerId) => (await spec.list()).filter((row) => row.formValues[spec.field] === brokerId).map((row) => ({
91376
+ const fields = typeof spec.field === "string" ? [spec.field] : spec.field;
91377
+ return { find: async (instanceId) => (await spec.list()).filter((row) => fields.some((f) => namesInstance(row.formValues[f], instanceId))).map((row) => ({
91110
91378
  kind: spec.kind,
91111
91379
  id: row.id,
91112
91380
  ...row.name !== void 0 ? { name: row.name } : {}
91113
91381
  })) };
91114
91382
  }
91115
91383
  /**
91116
- * An account provider whose `deleteInstance` is refused while anything still uses the account
91117
- * (D1012). The account is an `integration-instances` kind (D1013), so the refusal lives on the
91118
- * delete the instances page calls, not on a separate broker cap.
91384
+ * A provider whose `deleteInstance` is refused while anything still uses the instance. The
91385
+ * account is an `integration-instances` kind (D1013), so the refusal lives on the delete the
91386
+ * instances page calls.
91119
91387
  */
91120
- function guardBrokerDelete(base, users) {
91388
+ function guardInstanceDelete(base, users) {
91121
91389
  return {
91122
91390
  ...base,
91123
91391
  deleteInstance: async (input) => {
91124
- await assertBrokerUnused(input.id, users());
91392
+ await assertInstanceUnused(input.id, users());
91125
91393
  return base.deleteInstance(input);
91126
91394
  }
91127
91395
  };
91128
91396
  }
91129
- entryBody({ brokerId: string() });
91130
91397
  //#endregion
91131
91398
  //#region ../../node_modules/xtend/immutable.js
91132
91399
  var require_immutable = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -123351,7 +123618,7 @@ var PROBE_LABELS = {
123351
123618
  };
123352
123619
  /** The instance's health word: connected / auth-failed / unreachable / tls-error, latency, clients. */
123353
123620
  function mqttHealthOf(body, live, now) {
123354
- if (body.enabled === false) return { status: {
123621
+ if (!isInstanceEnabled(body)) return { status: {
123355
123622
  state: "off",
123356
123623
  label: "Switched off"
123357
123624
  } };
@@ -123476,7 +123743,7 @@ function buildMqttBrokerInstances(records, deps) {
123476
123743
  onboard: built.onboard
123477
123744
  };
123478
123745
  };
123479
- return guardBrokerDelete({
123746
+ return guardInstanceDelete({
123480
123747
  ...base,
123481
123748
  instanceFormSchema: async ({ id }) => {
123482
123749
  const saved = id === null ? null : await instances.getResolved(id);
@@ -124210,7 +124477,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124210
124477
  getBrokerConfig(id) {
124211
124478
  const external = this.activeExternalBrokers.find((b) => b.id === id);
124212
124479
  if (external) {
124213
- if (external.enabled === false) throw new Error(`mqtt-broker: broker '${id}' is switched off`);
124480
+ if (!isInstanceEnabled(external)) throw new Error(`mqtt-broker: broker '${id}' is switched off`);
124214
124481
  const password = this.storedPassword(external.password);
124215
124482
  return {
124216
124483
  url: external.url,
@@ -124466,7 +124733,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124466
124733
  * entry disappeared, and respawn runtimes whose port changed.
124467
124734
  */
124468
124735
  async reconcileOnboardRuntimes() {
124469
- const desiredEntries = this.activeExternalBrokers.filter(hasOnboard).filter((b) => b.enabled !== false);
124736
+ const desiredEntries = this.activeExternalBrokers.filter(hasOnboard).filter((b) => isInstanceEnabled(b));
124470
124737
  const desired = desiredEntries.map((b) => ({
124471
124738
  id: b.id,
124472
124739
  port: b.onboard.port
@@ -124607,7 +124874,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124607
124874
  collectExternalProbeInputs() {
124608
124875
  const out = [];
124609
124876
  for (const b of this.activeExternalBrokers) {
124610
- if (b.onboard !== void 0 || b.enabled === false) continue;
124877
+ if (b.onboard !== void 0 || !isInstanceEnabled(b)) continue;
124611
124878
  let password;
124612
124879
  try {
124613
124880
  password = this.storedPassword(b.password);