@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.
@@ -6028,7 +6028,7 @@ var ZodIssueCode = {
6028
6028
  var ZodFirstPartyTypeKind;
6029
6029
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
6030
6030
  //#endregion
6031
- //#region ../types/dist/sleep-BX_MqzUe.mjs
6031
+ //#region ../types/dist/sleep-CmjWurK5.mjs
6032
6032
  /**
6033
6033
  * The audio chunk plane's byte format, and the ONE expansion from a coded
6034
6034
  * window to float samples (D455).
@@ -6712,137 +6712,86 @@ async function runAddonMigrations(host, migrations, logger, options = {}) {
6712
6712
  blockOwner
6713
6713
  };
6714
6714
  }
6715
- /**
6716
- * Build a {@link DurableState} over a single store key. Transport-agnostic:
6717
- * `read`/`write` are the addon-store or device-store accessors. The whole
6718
- * validated value round-trips on every read/write — the schema is the
6719
- * single source of truth for what is persisted, so no hand-listed field
6720
- * set can drop a key on save.
6721
- */
6722
- function createDurableState(deps) {
6723
- const get = async () => {
6724
- const raw = (await deps.read())[deps.key];
6725
- if (raw === void 0) return deps.fallback;
6726
- const parsed = deps.schema.safeParse(raw);
6727
- if (!parsed.success) {
6728
- deps.onParseError?.(deps.key, parsed.error);
6729
- return deps.fallback;
6730
- }
6731
- return parsed.data;
6732
- };
6733
- const set = async (next) => {
6734
- const validated = deps.schema.parse(next);
6735
- await deps.write({ [deps.key]: validated });
6736
- };
6737
- const update = async (fn) => {
6738
- await set(fn(await get()));
6739
- };
6715
+ /** The record calls the one-switch migration makes, over the migration API. */
6716
+ function switchRecordsOverMigrationApi(api) {
6717
+ return { kind: (definition) => {
6718
+ const handle = api.records.kind(definition);
6719
+ return {
6720
+ get: (id) => handle.get({ id }),
6721
+ put: (input, opts) => handle.put({
6722
+ ...input,
6723
+ ...opts?.ifRev === void 0 ? {} : { ifRev: opts.ifRev }
6724
+ }),
6725
+ patch: (id, partial) => handle.patch({
6726
+ id,
6727
+ partial
6728
+ })
6729
+ };
6730
+ } };
6731
+ }
6732
+ function integrationRowsApiOver(api) {
6740
6733
  return {
6741
- get,
6742
- set,
6743
- update
6734
+ list: async () => (await api.integrations.list({})).integrations,
6735
+ readLegacyIntegrationRows: (input) => api.legacyRows.read(input),
6736
+ clearLegacyIntegrationRows: (input) => api.legacyRows.clear(input)
6744
6737
  };
6745
6738
  }
6746
- /**
6747
- * Per-node scoping for the shared addon-settings blob.
6748
- *
6749
- * An addon's settings store is hub-central (the `addon-settings` cap is
6750
- * hub-routed — the hub instance answers for every node), so fields whose
6751
- * value is a NODE fact (decoder backend, engine pick, probed hardware
6752
- * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
6753
- * the single shared blob. The SCHEMA field key stays bare: the write path
6754
- * ({@link scopePatch}) maps the bare field onto the target node's scoped
6755
- * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
6756
- * back, so UI forms and `resolveConfig` only ever see the bare key.
6757
- *
6758
- * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
6759
- * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
6760
- * schema and routes reads/writes through these helpers.
6761
- *
6762
- * ## No bare-key fallback — deliberate
6763
- *
6764
- * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
6765
- * scoped key resolves to `undefined` so the field's schema `default` wins —
6766
- * NEVER `store[base]` and never another node's value. A bare legacy key in
6767
- * the store is invisible to every node, hub included, so one node's
6768
- * selection can never leak onto another. (This generalizes the
6769
- * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
6770
- * arbitrary set of per-node field keys.)
6771
- *
6772
- * Pure functions only — no I/O, no imports beyond the language. This is a
6773
- * LEAF module: import it via its deep path, never from the root barrel.
6774
- */
6775
- /**
6776
- * Normalize a raw kernel node id to the bare node id used for scoping.
6777
- * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
6778
- * processes; per-node settings are per-NODE, so strip the addon segment.
6779
- * `undefined` / `null` / empty falls back to `'hub'`.
6780
- */
6781
- function normalizeNodeId(raw) {
6782
- if (raw === void 0 || raw === null || raw === "") return "hub";
6783
- const slashIdx = raw.indexOf("/");
6784
- if (slashIdx < 0) return raw;
6785
- const bare = raw.slice(0, slashIdx);
6786
- return bare === "" ? "hub" : bare;
6787
- }
6788
- /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
6789
- function nodeScopedKey(base, nodeId) {
6790
- return `${base}@${normalizeNodeId(nodeId)}`;
6791
- }
6792
- /**
6793
- * Read a node's value for a per-node field from the raw shared store:
6794
- * the node-scoped key when present, otherwise `undefined`.
6795
- * Deliberately NO bare-key fallback (see module doc) — the caller lets the
6796
- * schema `default` win on `undefined`.
6797
- */
6798
- function readNodeValue(store, base, nodeId) {
6799
- return store[nodeScopedKey(base, nodeId)];
6800
- }
6801
- /**
6802
- * Re-map a UI/settings patch so every bare perNode field persists under the
6803
- * TARGET node's scoped key; all other keys pass through unchanged. Used on
6804
- * the write path so a save for one node never clobbers another node's value
6805
- * (and the bare key is never written). Returns a new object — the input
6806
- * patch is not mutated.
6807
- */
6808
- function scopePatch(patch, perNodeKeys, nodeId) {
6809
- const out = {};
6810
- for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
6811
- return out;
6812
- }
6813
- /**
6814
- * Project the raw shared store onto the bare schema keys for ONE node so a
6815
- * UI schema (whose field keys are bare) hydrates from that node's own
6816
- * values:
6817
- *
6818
- * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
6819
- * - Every bare perNode key is dropped from the pass-through (a stray bare
6820
- * legacy key must never hydrate any node — no bare fallback).
6821
- * - THIS node's effective value ({@link readNodeValue}) is then laid onto
6822
- * each bare perNode key; when the node has no scoped key the bare key is
6823
- * left ABSENT so the field's schema `default` wins.
6824
- *
6825
- * Returns a new object — the input store is not mutated.
6826
- */
6827
- function projectStore(store, perNodeKeys, nodeId) {
6828
- const out = {};
6829
- for (const [key, value] of Object.entries(store)) {
6830
- if (key.includes("@")) continue;
6831
- if (perNodeKeys.has(key)) continue;
6832
- out[key] = value;
6739
+ var PREFIX = "records/";
6740
+ /** The base of every records failure. `detail` is the human part of the message. */
6741
+ var RecordsError = class extends Error {
6742
+ code;
6743
+ detail;
6744
+ constructor(code, detail) {
6745
+ super(`${PREFIX}${code}: ${detail}`);
6746
+ this.name = "RecordsError";
6747
+ this.code = code;
6748
+ this.detail = detail;
6833
6749
  }
6834
- for (const base of perNodeKeys) {
6835
- const value = readNodeValue(store, base, nodeId);
6836
- if (value !== void 0) out[base] = value;
6750
+ };
6751
+ /** The keychain could not store or serve a value: explicit, never an empty string. */
6752
+ var RecordSecretUnavailableError = class extends RecordsError {
6753
+ constructor(detail) {
6754
+ super("secret-unavailable", detail);
6755
+ this.name = "RecordSecretUnavailableError";
6837
6756
  }
6838
- return out;
6757
+ };
6758
+ var InvalidRecordError = class extends RecordsError {
6759
+ constructor(detail) {
6760
+ super("invalid-record", detail);
6761
+ this.name = "InvalidRecordError";
6762
+ }
6763
+ };
6764
+ /** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
6765
+ var DeclarationRefusedError = class extends RecordsError {
6766
+ constructor(detail) {
6767
+ super("declaration-refused", detail);
6768
+ this.name = "DeclarationRefusedError";
6769
+ }
6770
+ };
6771
+ function linkTargetOf(meta) {
6772
+ if (typeof meta !== "object" || meta === null) return void 0;
6773
+ const link = Reflect.get(meta, "link");
6774
+ const parsed = LinkTargetSchema.safeParse(link);
6775
+ return parsed.success ? parsed.data : void 0;
6776
+ }
6777
+ var LinkTargetSchema = object({
6778
+ cap: string().min(1),
6779
+ kind: string().min(1).optional()
6780
+ });
6781
+ /** The links a kind declares, read from the meta of its body fields. */
6782
+ function linksOfKind(kind) {
6783
+ const schema = kind.schema;
6784
+ if (!(schema instanceof ZodObject)) return [];
6785
+ const links = [];
6786
+ for (const [field, fieldSchema] of Object.entries(schema.shape)) {
6787
+ const to = linkTargetOf(globalRegistry.get(fieldSchema));
6788
+ if (to !== void 0) links.push({
6789
+ field,
6790
+ to
6791
+ });
6792
+ }
6793
+ return links;
6839
6794
  }
6840
- /** Every scope, in the order the guard and the docs list them. */
6841
- var SCOPED_SETTINGS_SCOPES = [
6842
- "cluster",
6843
- "device-defaults",
6844
- "node"
6845
- ];
6846
6795
  /**
6847
6796
  * The address of one keychain value: `secret://<owner>/<scope>/<fieldPath>`.
6848
6797
  *
@@ -6977,6 +6926,643 @@ function parseSecretRef(ref) {
6977
6926
  fieldPath
6978
6927
  };
6979
6928
  }
6929
+ /** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
6930
+ /** The files a kind may live in. `history` is device-history's (D850), never records. */
6931
+ var RECORD_DATABASES = ["settings", "events"];
6932
+ /** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
6933
+ var RECORD_CLASSES = [
6934
+ "config",
6935
+ "ledger",
6936
+ "audit",
6937
+ "mirror",
6938
+ "ephemeral"
6939
+ ];
6940
+ var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
6941
+ var RECORD_MAX_DATA_BYTES = 1024 * 1024;
6942
+ var RECORD_BATCH_MAX = 1e3;
6943
+ var RECORD_QUERY_MAX = 1e3;
6944
+ /** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
6945
+ var RECORD_SETTINGS_MAX_ROWS = 5e4;
6946
+ /** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
6947
+ var RECORD_SECRET_COLLECTION_PREFIX = "records:";
6948
+ /**
6949
+ * Secret fields of a record, addressed the way a Zod schema declares them
6950
+ * (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
6951
+ * (`auth.accessToken`, `headers[].value`).
6952
+ *
6953
+ * `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
6954
+ * names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
6955
+ * key releases exactly that key's secret.
6956
+ *
6957
+ * Array elements are matched by a DECLARED id key (`secretArrayKeys`:
6958
+ * `{ headers: 'name' }`), never by index, so reordering a list keeps every
6959
+ * keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
6960
+ * leaf names its element: `headers[X-Api].value`.
6961
+ *
6962
+ * Pure and browser-safe. Nothing here mutates: every transform returns a new value.
6963
+ */
6964
+ /** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
6965
+ function parseSecretPath(path) {
6966
+ if (path.length === 0) throw new InvalidRecordError("an empty secret path");
6967
+ return path.split(".").map((raw) => {
6968
+ const each = raw.endsWith("[]");
6969
+ const map = raw.endsWith("{}");
6970
+ const key = each || map ? raw.slice(0, -2) : raw;
6971
+ if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
6972
+ return {
6973
+ key,
6974
+ each,
6975
+ map
6976
+ };
6977
+ });
6978
+ }
6979
+ /** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
6980
+ function secretArrayPrefixes(path) {
6981
+ const segments = parseSecretPath(path);
6982
+ const prefixes = [];
6983
+ const walked = [];
6984
+ for (const segment of segments) {
6985
+ walked.push(segment.key);
6986
+ if (segment.each) prefixes.push(walked.join("."));
6987
+ }
6988
+ return prefixes;
6989
+ }
6990
+ function isRecord$6(value) {
6991
+ return typeof value === "object" && value !== null && !Array.isArray(value);
6992
+ }
6993
+ function elementId(element, idKey, declared, prefix) {
6994
+ const id = isRecord$6(element) ? element[idKey] : void 0;
6995
+ 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`);
6996
+ return id;
6997
+ }
6998
+ /**
6999
+ * Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
7000
+ * visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
7001
+ * result is a new body, `data` is untouched.
7002
+ */
7003
+ var REMOVE_LEAF = Symbol("remove-leaf");
7004
+ function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
7005
+ if (!isRecord$6(node)) return node;
7006
+ const segment = segments[index];
7007
+ if (segment === void 0) return node;
7008
+ if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
7009
+ const child = node[segment.key];
7010
+ const keys = [...walkedKeys, segment.key];
7011
+ const last = index === segments.length - 1;
7012
+ if (segment.each) {
7013
+ if (!Array.isArray(child)) return node;
7014
+ const prefix = keys.join(".");
7015
+ const idKey = arrayKeys[prefix];
7016
+ if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
7017
+ const mapped = child.map((element) => {
7018
+ const id = elementId(element, idKey, declared, prefix);
7019
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
7020
+ return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
7021
+ });
7022
+ return {
7023
+ ...node,
7024
+ [segment.key]: mapped
7025
+ };
7026
+ }
7027
+ if (segment.map) {
7028
+ if (!isRecord$6(child)) return node;
7029
+ const kept = Object.entries(child).map(([mapKey, value]) => {
7030
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
7031
+ if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
7032
+ return [mapKey, visit({
7033
+ declared,
7034
+ concrete,
7035
+ value
7036
+ })];
7037
+ }).filter(([, value]) => value !== REMOVE_LEAF);
7038
+ return {
7039
+ ...node,
7040
+ [segment.key]: Object.fromEntries(kept)
7041
+ };
7042
+ }
7043
+ const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
7044
+ if (last) {
7045
+ const replacement = visit({
7046
+ declared,
7047
+ concrete,
7048
+ value: child
7049
+ });
7050
+ if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
7051
+ return {
7052
+ ...node,
7053
+ [segment.key]: replacement
7054
+ };
7055
+ }
7056
+ return {
7057
+ ...node,
7058
+ [segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
7059
+ };
7060
+ }
7061
+ /** Replace/remove every present secret leaf; returns a NEW body. */
7062
+ function mapSecretLeaves(data, paths, arrayKeys, visit) {
7063
+ let current = data;
7064
+ for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
7065
+ return current;
7066
+ }
7067
+ /**
7068
+ * The keychain collection name a kind's secrets live under. Prefixed so a
7069
+ * record's refs never collide with the refs a legacy collection of the same name
7070
+ * already holds during an adoption.
7071
+ */
7072
+ function recordSecretCollection(kind) {
7073
+ return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
7074
+ }
7075
+ /** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
7076
+ function recordSecretRef(owner, kind, rowId, concretePath) {
7077
+ return buildSecretRef({
7078
+ owner,
7079
+ scope: {
7080
+ kind: "row",
7081
+ collection: recordSecretCollection(kind),
7082
+ rowId
7083
+ },
7084
+ fieldPath: concretePath
7085
+ });
7086
+ }
7087
+ /**
7088
+ * A stored secret, as an admin read shows it: a VIEW naming the row's own
7089
+ * keychain ref (`set: true`), never the value and no longer the bare redaction
7090
+ * token. The form hands it to the secret field, which reveals the value by ref
7091
+ * through the audited `keychain-admin.reveal`; sent back untouched it keeps the
7092
+ * stored secret (the records door reads a view as KEEP).
7093
+ *
7094
+ * ONE implementation for the entries service and for every addon that serves
7095
+ * its own instances (`RecordIntegrationInstances`).
7096
+ */
7097
+ function isRecord$5(value) {
7098
+ return typeof value === "object" && value !== null && !Array.isArray(value);
7099
+ }
7100
+ function secretViewsOf(owner, kind, id, decl, data) {
7101
+ if (decl.secretPaths.length === 0) return data;
7102
+ const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
7103
+ if (leaf.value !== "__camstack_redacted__") return leaf.value;
7104
+ return {
7105
+ $secret: recordSecretRef(owner, kind, id, leaf.concrete),
7106
+ v: 1,
7107
+ set: true
7108
+ };
7109
+ });
7110
+ return isRecord$5(shown) ? shown : data;
7111
+ }
7112
+ /** The most instances one addon lists (an integrations page, not a table). */
7113
+ var INSTANCES_LIST_MAX = 1e3;
7114
+ /**
7115
+ * The ONE reader of an instance's switch (D996): an absent field means on, so a row written
7116
+ * before the field existed needs no migration. Every consumer of an instance body asks this.
7117
+ */
7118
+ function isInstanceEnabled(body) {
7119
+ return body.enabled !== false;
7120
+ }
7121
+ /** The body key of the switch; only {@link RecordIntegrationInstances.setInstanceEnabled} writes it. */
7122
+ var SWITCH_KEY = "enabled";
7123
+ /** The keys of the kind's secret fields that sit at the top level of the body. */
7124
+ function topLevelSecretKeys(paths) {
7125
+ return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
7126
+ }
7127
+ /** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
7128
+ function secretMapKeys(paths) {
7129
+ return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
7130
+ }
7131
+ /**
7132
+ * A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
7133
+ * view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
7134
+ * or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
7135
+ */
7136
+ function secretMapPatch(value) {
7137
+ if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
7138
+ const out = {};
7139
+ for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
7140
+ else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
7141
+ return Object.keys(out).length > 0 ? out : null;
7142
+ }
7143
+ var RecordIntegrationInstances = class {
7144
+ records;
7145
+ kind;
7146
+ hooks;
7147
+ handle;
7148
+ secretKeys;
7149
+ secretMaps;
7150
+ nameField;
7151
+ switchListeners = /* @__PURE__ */ new Set();
7152
+ constructor(records, kind, hooks) {
7153
+ this.records = records;
7154
+ this.kind = kind;
7155
+ this.hooks = hooks;
7156
+ this.handle = records.kind(kind);
7157
+ this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
7158
+ this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
7159
+ this.nameField = kind.declaration.entry?.nameField ?? "name";
7160
+ }
7161
+ /**
7162
+ * One instance read for the addon's own runtime; null when absent. When the keychain is
7163
+ * locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
7164
+ * caller can keep what it had instead of reconfiguring with an empty secret (D49).
7165
+ */
7166
+ async readResolved(id) {
7167
+ try {
7168
+ const record = await this.handle.getResolved(id);
7169
+ return record === null ? null : {
7170
+ id,
7171
+ body: record.data,
7172
+ enabled: isInstanceEnabled(record.data),
7173
+ secrets: "resolved"
7174
+ };
7175
+ } catch (err) {
7176
+ if (!(err instanceof RecordSecretUnavailableError)) throw err;
7177
+ const stored = await this.handle.get(id);
7178
+ if (stored === null) return null;
7179
+ return {
7180
+ id,
7181
+ body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
7182
+ enabled: isInstanceEnabled(stored.data),
7183
+ secrets: "unavailable"
7184
+ };
7185
+ }
7186
+ }
7187
+ /** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
7188
+ async getResolved(id) {
7189
+ return (await this.readResolved(id))?.body ?? null;
7190
+ }
7191
+ /** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
7192
+ async listResolved() {
7193
+ const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
7194
+ const out = [];
7195
+ for (const record of page.records) {
7196
+ const read = await this.readResolved(record.id);
7197
+ if (read !== null) out.push(read);
7198
+ }
7199
+ return out;
7200
+ }
7201
+ viewOf(record) {
7202
+ const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
7203
+ const rawName = record.data[this.nameField];
7204
+ const kind = this.hooks.kindOf?.(record.data);
7205
+ const health = this.hooks.health?.(record.data, record.id);
7206
+ return {
7207
+ id: record.id,
7208
+ name: typeof rawName === "string" ? rawName : record.id,
7209
+ configured: this.hooks.configured(record.data),
7210
+ enabled: isInstanceEnabled(record.data),
7211
+ formValues: shown,
7212
+ ...kind !== void 0 ? { kind } : {},
7213
+ ...health?.status !== void 0 ? { status: health.status } : {},
7214
+ ...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
7215
+ };
7216
+ }
7217
+ describe = async () => {
7218
+ const declared = linksOfKind(this.kind);
7219
+ const links = this.hooks.description.links !== void 0 || declared.length === 0 ? {} : { links: declared.map((link) => ({
7220
+ kind: this.kind.name,
7221
+ field: link.field,
7222
+ to: link.to
7223
+ })) };
7224
+ return {
7225
+ ...this.hooks.description,
7226
+ ...links,
7227
+ ...this.hooks.mintId === void 0 ? {} : { mintsId: true }
7228
+ };
7229
+ };
7230
+ instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
7231
+ listInstances = async () => {
7232
+ return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
7233
+ };
7234
+ getInstance = async ({ id }) => {
7235
+ const record = await this.handle.get(id);
7236
+ return record === null ? null : this.viewOf(record);
7237
+ };
7238
+ /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
7239
+ createInstance = async ({ id, name, kind, values }) => {
7240
+ const minted = id ?? this.hooks.mintId?.({
7241
+ name,
7242
+ ...kind !== void 0 ? { kind } : {}
7243
+ });
7244
+ if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
7245
+ await this.handle.put({
7246
+ id: minted,
7247
+ data: this.hooks.initialBody(name, kind)
7248
+ }, { ifRev: 0 });
7249
+ const patch = this.patchOf(values ?? {});
7250
+ if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
7251
+ await this.hooks.onChanged?.(minted, "created");
7252
+ return { id: minted };
7253
+ };
7254
+ updateInstance = async ({ id, name, values }) => {
7255
+ const patch = this.patchOf(values);
7256
+ if (name !== void 0) patch[this.nameField] = name;
7257
+ await this.handle.patch(id, patch);
7258
+ await this.hooks.onChanged?.(id, "updated");
7259
+ return { ok: true };
7260
+ };
7261
+ /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
7262
+ patchOf(values) {
7263
+ const patch = {};
7264
+ for (const [key, value] of Object.entries(values)) {
7265
+ if (value === void 0) continue;
7266
+ if (key === "enabled") continue;
7267
+ if (this.secretMaps.has(key)) {
7268
+ const entries = secretMapPatch(value);
7269
+ if (entries !== null) patch[key] = entries;
7270
+ } else if (!this.secretKeys.has(key)) patch[key] = value;
7271
+ else if (isSecretClear(value)) patch[key] = null;
7272
+ else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
7273
+ }
7274
+ return patch;
7275
+ }
7276
+ /**
7277
+ * Listen to the switch of ANY instance of this helper (in the process that serves it). The
7278
+ * durable replacement of the `integration.enabled` / `integration.disabled` events (D8): the
7279
+ * addon reconciles from the record, whichever way it flipped.
7280
+ */
7281
+ onSwitched(listener) {
7282
+ this.switchListeners.add(listener);
7283
+ }
7284
+ /**
7285
+ * The ONE writer of the switch (D996, D1014): the record body's `enabled`, for every role. A
7286
+ * configured thing is an instance, so an id with no record yet (a default integration that was
7287
+ * never configured) gets its record from `initialBody` before the switch is written.
7288
+ */
7289
+ setInstanceEnabled = async ({ id, enabled }) => {
7290
+ if (await this.handle.get(id) === null) await this.handle.put({
7291
+ id,
7292
+ data: this.hooks.initialBody(id)
7293
+ }, { ifRev: 0 });
7294
+ await this.handle.patch(id, { [SWITCH_KEY]: enabled });
7295
+ await this.hooks.onChanged?.(id, "enabled");
7296
+ for (const listener of this.switchListeners) await listener(id, enabled);
7297
+ return { ok: true };
7298
+ };
7299
+ /** The row and its keychain refs go together (the records door). */
7300
+ deleteInstance = async ({ id }) => {
7301
+ await this.handle.delete(id);
7302
+ await this.hooks.onChanged?.(id, "deleted");
7303
+ return { ok: true };
7304
+ };
7305
+ testInstance = async (input) => {
7306
+ if (this.hooks.test === void 0) return {
7307
+ success: false,
7308
+ status: "unsupported",
7309
+ error: "This integration declares no connection test"
7310
+ };
7311
+ return this.hooks.test(input);
7312
+ };
7313
+ /** The flat provider object to hand to `registerProvider`. */
7314
+ toProvider() {
7315
+ return {
7316
+ describe: this.describe,
7317
+ instanceFormSchema: this.instanceFormSchema,
7318
+ listInstances: this.listInstances,
7319
+ getInstance: this.getInstance,
7320
+ createInstance: this.createInstance,
7321
+ updateInstance: this.updateInstance,
7322
+ setInstanceEnabled: this.setInstanceEnabled,
7323
+ deleteInstance: this.deleteInstance,
7324
+ testInstance: this.testInstance
7325
+ };
7326
+ }
7327
+ };
7328
+ /**
7329
+ * The one-switch migration (epic #440, step 3). An integration's on/off state used to live in the
7330
+ * registry's `enabled` column for a device addon; it now lives only in the instance record's
7331
+ * body (`enabled`, D1007 superseded). This moves a registry `enabled = false` into the body, once.
7332
+ *
7333
+ * For every registry row of the addon that is OFF:
7334
+ * - no record under its id: the record is created from `initialBody(name)` with `enabled: false`
7335
+ * (a default integration that never had settings, Reolink's among them);
7336
+ * - a record whose body states no `enabled`: `enabled: false` is written into it;
7337
+ * - a record that already states `enabled` (either way) is the newer truth and is left alone.
7338
+ * A row that is ON writes nothing: an absent field reads as on. A rerun finds every off row with
7339
+ * a stated switch and does nothing, so nothing switched off comes back on and nothing switched on
7340
+ * goes off. The registry column itself is neither read afterwards nor written; its drop is step 5.
7341
+ *
7342
+ * It runs in the addon process, BEFORE the addon registers its `integration-instances` provider,
7343
+ * which is also why `integrations.list` still answers the stored column at that point.
7344
+ */
7345
+ function registrySwitchToBodyId(addonId, date) {
7346
+ return `${addonId}/${date}-registry-switch-to-body`;
7347
+ }
7348
+ async function moveRegistrySwitchToBody(ports, spec) {
7349
+ const rows = await ports.listIntegrations(spec.addonId);
7350
+ let created = 0;
7351
+ let switched = 0;
7352
+ let kept = 0;
7353
+ for (const row of rows) {
7354
+ if (row.enabled) continue;
7355
+ const body = await ports.readBody(row.id);
7356
+ if (body === null) {
7357
+ if (await ports.createRecord(row.id, {
7358
+ ...spec.initialBody(row.name),
7359
+ ["enabled"]: false
7360
+ }) === "created") created += 1;
7361
+ else kept += 1;
7362
+ continue;
7363
+ }
7364
+ if ("enabled" in body) {
7365
+ kept += 1;
7366
+ continue;
7367
+ }
7368
+ await ports.switchOff(row.id);
7369
+ switched += 1;
7370
+ }
7371
+ const summary = {
7372
+ integrations: rows.length,
7373
+ off: rows.filter((r) => !r.enabled).length,
7374
+ created,
7375
+ switched,
7376
+ kept
7377
+ };
7378
+ return created === 0 && switched === 0 ? {
7379
+ outcome: "already-done",
7380
+ summary
7381
+ } : {
7382
+ outcome: "done",
7383
+ summary
7384
+ };
7385
+ }
7386
+ /** A migration entry: an addon states its kind and how a new body starts, nothing else. */
7387
+ function registrySwitchToBodyMigration(spec) {
7388
+ return {
7389
+ meta: {
7390
+ id: registrySwitchToBodyId(spec.addonId, spec.date),
7391
+ owner: spec.addonId,
7392
+ level: "addon-state",
7393
+ seq: spec.seq,
7394
+ dependsOn: [],
7395
+ store: "settings",
7396
+ scope: "cluster",
7397
+ onFailure: "block-owner",
7398
+ bodyKind: "procedure",
7399
+ description: "Move the registry enabled flag of every switched-off integration into its instance record body, creating the record when there is none",
7400
+ fixtureMark: "enabled"
7401
+ },
7402
+ procedure: (ports) => moveRegistrySwitchToBody(ports, {
7403
+ addonId: spec.addonId,
7404
+ initialBody: spec.initialBody
7405
+ })
7406
+ };
7407
+ }
7408
+ /** The hub and records sides of {@link registrySwitchToBodyMigration}. */
7409
+ function registrySwitchPortsOver(deps) {
7410
+ const handle = deps.records.kind({
7411
+ name: deps.kind.name,
7412
+ declaration: deps.kind.declaration,
7413
+ schema: record(string(), unknown())
7414
+ });
7415
+ return {
7416
+ listIntegrations: async (addonId) => (await deps.api.list()).filter((i) => i.addonId === addonId).map((i) => ({
7417
+ id: i.id,
7418
+ name: i.name,
7419
+ enabled: i.enabled !== false
7420
+ })),
7421
+ readBody: async (id) => (await handle.get(id))?.data ?? null,
7422
+ createRecord: async (id, body) => {
7423
+ if (await handle.get(id) !== null) return "exists";
7424
+ await handle.put({
7425
+ id,
7426
+ data: body
7427
+ }, { ifRev: 0 });
7428
+ return "created";
7429
+ },
7430
+ switchOff: async (id) => {
7431
+ await handle.patch(id, { [SWITCH_KEY]: false });
7432
+ }
7433
+ };
7434
+ }
7435
+ /**
7436
+ * Build a {@link DurableState} over a single store key. Transport-agnostic:
7437
+ * `read`/`write` are the addon-store or device-store accessors. The whole
7438
+ * validated value round-trips on every read/write — the schema is the
7439
+ * single source of truth for what is persisted, so no hand-listed field
7440
+ * set can drop a key on save.
7441
+ */
7442
+ function createDurableState(deps) {
7443
+ const get = async () => {
7444
+ const raw = (await deps.read())[deps.key];
7445
+ if (raw === void 0) return deps.fallback;
7446
+ const parsed = deps.schema.safeParse(raw);
7447
+ if (!parsed.success) {
7448
+ deps.onParseError?.(deps.key, parsed.error);
7449
+ return deps.fallback;
7450
+ }
7451
+ return parsed.data;
7452
+ };
7453
+ const set = async (next) => {
7454
+ const validated = deps.schema.parse(next);
7455
+ await deps.write({ [deps.key]: validated });
7456
+ };
7457
+ const update = async (fn) => {
7458
+ await set(fn(await get()));
7459
+ };
7460
+ return {
7461
+ get,
7462
+ set,
7463
+ update
7464
+ };
7465
+ }
7466
+ /**
7467
+ * Per-node scoping for the shared addon-settings blob.
7468
+ *
7469
+ * An addon's settings store is hub-central (the `addon-settings` cap is
7470
+ * hub-routed — the hub instance answers for every node), so fields whose
7471
+ * value is a NODE fact (decoder backend, engine pick, probed hardware
7472
+ * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
7473
+ * the single shared blob. The SCHEMA field key stays bare: the write path
7474
+ * ({@link scopePatch}) maps the bare field onto the target node's scoped
7475
+ * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
7476
+ * back, so UI forms and `resolveConfig` only ever see the bare key.
7477
+ *
7478
+ * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
7479
+ * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
7480
+ * schema and routes reads/writes through these helpers.
7481
+ *
7482
+ * ## No bare-key fallback — deliberate
7483
+ *
7484
+ * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
7485
+ * scoped key resolves to `undefined` so the field's schema `default` wins —
7486
+ * NEVER `store[base]` and never another node's value. A bare legacy key in
7487
+ * the store is invisible to every node, hub included, so one node's
7488
+ * selection can never leak onto another. (This generalizes the
7489
+ * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
7490
+ * arbitrary set of per-node field keys.)
7491
+ *
7492
+ * Pure functions only — no I/O, no imports beyond the language. This is a
7493
+ * LEAF module: import it via its deep path, never from the root barrel.
7494
+ */
7495
+ /**
7496
+ * Normalize a raw kernel node id to the bare node id used for scoping.
7497
+ * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
7498
+ * processes; per-node settings are per-NODE, so strip the addon segment.
7499
+ * `undefined` / `null` / empty falls back to `'hub'`.
7500
+ */
7501
+ function normalizeNodeId(raw) {
7502
+ if (raw === void 0 || raw === null || raw === "") return "hub";
7503
+ const slashIdx = raw.indexOf("/");
7504
+ if (slashIdx < 0) return raw;
7505
+ const bare = raw.slice(0, slashIdx);
7506
+ return bare === "" ? "hub" : bare;
7507
+ }
7508
+ /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
7509
+ function nodeScopedKey(base, nodeId) {
7510
+ return `${base}@${normalizeNodeId(nodeId)}`;
7511
+ }
7512
+ /**
7513
+ * Read a node's value for a per-node field from the raw shared store:
7514
+ * the node-scoped key when present, otherwise `undefined`.
7515
+ * Deliberately NO bare-key fallback (see module doc) — the caller lets the
7516
+ * schema `default` win on `undefined`.
7517
+ */
7518
+ function readNodeValue(store, base, nodeId) {
7519
+ return store[nodeScopedKey(base, nodeId)];
7520
+ }
7521
+ /**
7522
+ * Re-map a UI/settings patch so every bare perNode field persists under the
7523
+ * TARGET node's scoped key; all other keys pass through unchanged. Used on
7524
+ * the write path so a save for one node never clobbers another node's value
7525
+ * (and the bare key is never written). Returns a new object — the input
7526
+ * patch is not mutated.
7527
+ */
7528
+ function scopePatch(patch, perNodeKeys, nodeId) {
7529
+ const out = {};
7530
+ for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
7531
+ return out;
7532
+ }
7533
+ /**
7534
+ * Project the raw shared store onto the bare schema keys for ONE node so a
7535
+ * UI schema (whose field keys are bare) hydrates from that node's own
7536
+ * values:
7537
+ *
7538
+ * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
7539
+ * - Every bare perNode key is dropped from the pass-through (a stray bare
7540
+ * legacy key must never hydrate any node — no bare fallback).
7541
+ * - THIS node's effective value ({@link readNodeValue}) is then laid onto
7542
+ * each bare perNode key; when the node has no scoped key the bare key is
7543
+ * left ABSENT so the field's schema `default` wins.
7544
+ *
7545
+ * Returns a new object — the input store is not mutated.
7546
+ */
7547
+ function projectStore(store, perNodeKeys, nodeId) {
7548
+ const out = {};
7549
+ for (const [key, value] of Object.entries(store)) {
7550
+ if (key.includes("@")) continue;
7551
+ if (perNodeKeys.has(key)) continue;
7552
+ out[key] = value;
7553
+ }
7554
+ for (const base of perNodeKeys) {
7555
+ const value = readNodeValue(store, base, nodeId);
7556
+ if (value !== void 0) out[base] = value;
7557
+ }
7558
+ return out;
7559
+ }
7560
+ /** Every scope, in the order the guard and the docs list them. */
7561
+ var SCOPED_SETTINGS_SCOPES = [
7562
+ "cluster",
7563
+ "device-defaults",
7564
+ "node"
7565
+ ];
6980
7566
  /** A write to a secret path could not be stored in the keychain, so it was refused. */
6981
7567
  var KeychainWriteRefusedError = class extends Error {
6982
7568
  fieldPath;
@@ -6987,7 +7573,7 @@ var KeychainWriteRefusedError = class extends Error {
6987
7573
  }
6988
7574
  };
6989
7575
  var KEEP = { kind: "keep" };
6990
- function isRecord$6(value) {
7576
+ function isRecord$4(value) {
6991
7577
  return typeof value === "object" && value !== null && !Array.isArray(value);
6992
7578
  }
6993
7579
  function defaultMintId() {
@@ -7000,7 +7586,7 @@ function collectSecretMarkerRefs(value, out = []) {
7000
7586
  return out;
7001
7587
  }
7002
7588
  if (Array.isArray(value)) for (const item of value) collectSecretMarkerRefs(item, out);
7003
- else if (isRecord$6(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
7589
+ else if (isRecord$4(value)) for (const child of Object.values(value)) collectSecretMarkerRefs(child, out);
7004
7590
  return out;
7005
7591
  }
7006
7592
  async function storedValueEquals(secrets, marker, candidate) {
@@ -7055,7 +7641,7 @@ function rowId(row, idKey) {
7055
7641
  return null;
7056
7642
  }
7057
7643
  async function writeArray(ctx, node, incoming, stored, fieldPath) {
7058
- const storedRows = Array.isArray(stored) ? stored.filter(isRecord$6) : [];
7644
+ const storedRows = Array.isArray(stored) ? stored.filter(isRecord$4) : [];
7059
7645
  if (!Array.isArray(incoming)) {
7060
7646
  ctx.deletes.push(...collectSecretMarkerRefs(storedRows));
7061
7647
  return {
@@ -7071,7 +7657,7 @@ async function writeArray(ctx, node, incoming, stored, fieldPath) {
7071
7657
  const kept = /* @__PURE__ */ new Set();
7072
7658
  const rows = [];
7073
7659
  for (const row of incoming) {
7074
- if (!isRecord$6(row)) {
7660
+ if (!isRecord$4(row)) {
7075
7661
  rows.push(row);
7076
7662
  continue;
7077
7663
  }
@@ -7096,7 +7682,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
7096
7682
  case "leaf": return writeLeaf(ctx, incoming, stored, fieldPath);
7097
7683
  case "array": return writeArray(ctx, node, incoming, stored, fieldPath);
7098
7684
  case "object": {
7099
- if (!isRecord$6(incoming)) {
7685
+ if (!isRecord$4(incoming)) {
7100
7686
  if (incoming === void 0) return KEEP;
7101
7687
  ctx.deletes.push(...collectSecretMarkerRefs(stored));
7102
7688
  return {
@@ -7104,7 +7690,7 @@ async function writeNode(ctx, node, incoming, stored, fieldPath) {
7104
7690
  value: incoming
7105
7691
  };
7106
7692
  }
7107
- const storedObj = isRecord$6(stored) ? stored : {};
7693
+ const storedObj = isRecord$4(stored) ? stored : {};
7108
7694
  return {
7109
7695
  kind: "value",
7110
7696
  value: await writeMembers(ctx, node.children, incoming, storedObj, (m) => `${fieldPath}.${m}`)
@@ -7227,7 +7813,7 @@ async function resolveSecretMarkers(value, secrets, options = {}) {
7227
7813
  value: items
7228
7814
  };
7229
7815
  }
7230
- if (isRecord$6(v)) {
7816
+ if (isRecord$4(v)) {
7231
7817
  const out = {};
7232
7818
  for (const [k, child] of Object.entries(v)) {
7233
7819
  const s = substitute(child);
@@ -7259,7 +7845,7 @@ var SecretOverwriteRefusedError = class extends Error {
7259
7845
  this.name = "SecretOverwriteRefusedError";
7260
7846
  }
7261
7847
  };
7262
- function isRecord$5(value) {
7848
+ function isRecord$3(value) {
7263
7849
  return typeof value === "object" && value !== null && !Array.isArray(value);
7264
7850
  }
7265
7851
  function resolvedValue(pass, marker) {
@@ -7288,7 +7874,7 @@ function inArray(pass, incoming, stored) {
7288
7874
  return incoming.map((item, index) => {
7289
7875
  const twin = stored[index];
7290
7876
  if (isSecretMarker(twin)) return typeof item === "string" && item === resolvedValue(pass, twin) ? twin : item;
7291
- if (isRecord$5(item) && isRecord$5(twin)) return inArrayRow(pass, item, twin);
7877
+ if (isRecord$3(item) && isRecord$3(twin)) return inArrayRow(pass, item, twin);
7292
7878
  if (Array.isArray(item) && Array.isArray(twin)) return inArray(pass, item, twin);
7293
7879
  return item;
7294
7880
  });
@@ -7299,7 +7885,7 @@ function inArrayRow(pass, incoming, stored) {
7299
7885
  const twin = stored[key];
7300
7886
  if (isSecretMarker(twin)) {
7301
7887
  if (typeof value === "string" && value === resolvedValue(pass, twin)) out[key] = twin;
7302
- } else if (isRecord$5(value) && isRecord$5(twin)) out[key] = inArrayRow(pass, value, twin);
7888
+ } else if (isRecord$3(value) && isRecord$3(twin)) out[key] = inArrayRow(pass, value, twin);
7303
7889
  else if (Array.isArray(value) && Array.isArray(twin)) out[key] = inArray(pass, value, twin);
7304
7890
  }
7305
7891
  return out;
@@ -7307,7 +7893,7 @@ function inArrayRow(pass, incoming, stored) {
7307
7893
  async function walk(pass, incoming, stored) {
7308
7894
  if (isSecretMarker(stored)) return atMarker(pass, incoming, stored);
7309
7895
  if (Array.isArray(incoming) && Array.isArray(stored)) return inArray(pass, incoming, stored);
7310
- if (!isRecord$5(incoming) || !isRecord$5(stored)) return incoming;
7896
+ if (!isRecord$3(incoming) || !isRecord$3(stored)) return incoming;
7311
7897
  const out = { ...incoming };
7312
7898
  for (const [key, value] of Object.entries(incoming)) out[key] = await walk(pass, value, stored[key]);
7313
7899
  return out;
@@ -7338,7 +7924,7 @@ async function restoreUnchangedSecrets(input) {
7338
7924
  function isJsonEqual(a, b) {
7339
7925
  if (Object.is(a, b)) return true;
7340
7926
  if (Array.isArray(a)) return Array.isArray(b) && a.length === b.length && a.every((v, i) => isJsonEqual(v, b[i]));
7341
- if (isRecord$5(a) && isRecord$5(b)) {
7927
+ if (isRecord$3(a) && isRecord$3(b)) {
7342
7928
  const keys = Object.keys(a);
7343
7929
  if (keys.length !== Object.keys(b).length) return false;
7344
7930
  return keys.every((k) => Object.prototype.hasOwnProperty.call(b, k) && isJsonEqual(a[k], b[k]));
@@ -7362,7 +7948,7 @@ function markerKeysOf(blob, owner) {
7362
7948
  }
7363
7949
  function nodeFromStored(value, owner) {
7364
7950
  if (isSecretMarker(value)) return isSecretRefOwnedBy(value.$secret, owner) ? { kind: "leaf" } : null;
7365
- if (!isRecord$5(value)) return null;
7951
+ if (!isRecord$3(value)) return null;
7366
7952
  const children = /* @__PURE__ */ new Map();
7367
7953
  for (const [key, child] of Object.entries(value)) {
7368
7954
  const node = nodeFromStored(child, owner);
@@ -7859,13 +8445,48 @@ var BaseAddon = class {
7859
8445
  if (api === void 0) throw new Error(`${this.ctx.id}: the migration API is not available on this context`);
7860
8446
  return this.runBound(sets.flatMap((set) => set.bind(api)), options);
7861
8447
  }
7862
- async runBound(migrations, options) {
8448
+ /**
8449
+ * A device addon states its instance kind once, before its migrations run, and the one-switch
8450
+ * migration (registry `enabled` to the instance body, epic #440 step 3) joins whatever
8451
+ * catalogue the addon runs, in the SAME declaration (the engine replaces an owner's catalogue
8452
+ * on every declare).
8453
+ */
8454
+ declareRegistrySwitch(spec) {
8455
+ this.registrySwitchSpec = spec;
8456
+ }
8457
+ registrySwitchSpec = null;
8458
+ registrySwitchBound() {
8459
+ const spec = this.registrySwitchSpec;
8460
+ if (spec === null) return [];
8461
+ const api = this.ctx.migrationApi;
8462
+ if (api === void 0) {
8463
+ this.ctx.logger.warn("the registry switch migration is skipped: the migration API is not available on this context");
8464
+ return [];
8465
+ }
8466
+ return migrationSet([registrySwitchToBodyMigration({
8467
+ addonId: this.ctx.id,
8468
+ date: "2026-11-06",
8469
+ seq: 1e3,
8470
+ initialBody: spec.initialBody
8471
+ })], (a) => registrySwitchPortsOver({
8472
+ api: integrationRowsApiOver(a),
8473
+ records: switchRecordsOverMigrationApi(a),
8474
+ kind: spec.kind
8475
+ })).bind(api);
8476
+ }
8477
+ async runBound(declared, options) {
8478
+ const added = this.registrySwitchBound();
8479
+ const migrations = [...declared, ...added];
8480
+ const phased = options?.only === void 0 || added.length === 0 ? options : {
8481
+ ...options,
8482
+ only: [...options.only, ...added.map((m) => m.meta.id)]
8483
+ };
7863
8484
  const api = this.ctx.api.migrations;
7864
8485
  const report = await runAddonMigrations({
7865
8486
  declareOwner: (input) => api.declareOwner.mutate(input),
7866
8487
  startMigration: (input) => api.startMigration.mutate(input),
7867
8488
  finishMigration: (input) => api.finishMigration.mutate(input)
7868
- }, migrations, this.ctx.logger, options);
8489
+ }, migrations, this.ctx.logger, phased);
7869
8490
  if (report.blockOwner.length > 0) throw new AddonMigrationsBlockedError(report.blockOwner);
7870
8491
  return report;
7871
8492
  }
@@ -8938,221 +9559,6 @@ function normalizeAddonInitResult(result) {
8938
9559
  if (Array.isArray(result)) return { providers: result };
8939
9560
  return result;
8940
9561
  }
8941
- var PREFIX = "records/";
8942
- /** The base of every records failure. `detail` is the human part of the message. */
8943
- var RecordsError = class extends Error {
8944
- code;
8945
- detail;
8946
- constructor(code, detail) {
8947
- super(`${PREFIX}${code}: ${detail}`);
8948
- this.name = "RecordsError";
8949
- this.code = code;
8950
- this.detail = detail;
8951
- }
8952
- };
8953
- /** The keychain could not store or serve a value: explicit, never an empty string. */
8954
- var RecordSecretUnavailableError = class extends RecordsError {
8955
- constructor(detail) {
8956
- super("secret-unavailable", detail);
8957
- this.name = "RecordSecretUnavailableError";
8958
- }
8959
- };
8960
- var InvalidRecordError = class extends RecordsError {
8961
- constructor(detail) {
8962
- super("invalid-record", detail);
8963
- this.name = "InvalidRecordError";
8964
- }
8965
- };
8966
- /** A kind declaration the engine refuses (non-additive change, bad shape, wrong file). */
8967
- var DeclarationRefusedError = class extends RecordsError {
8968
- constructor(detail) {
8969
- super("declaration-refused", detail);
8970
- this.name = "DeclarationRefusedError";
8971
- }
8972
- };
8973
- /** Limits and names of `ctx.records` (D881). One authority; the engine and the facade read it. */
8974
- /** The files a kind may live in. `history` is device-history's (D850), never records. */
8975
- var RECORD_DATABASES = ["settings", "events"];
8976
- /** The classes of a kind: the `@durable` vocabulary, one authority (replaces the annotation). */
8977
- var RECORD_CLASSES = [
8978
- "config",
8979
- "ledger",
8980
- "audit",
8981
- "mirror",
8982
- "ephemeral"
8983
- ];
8984
- var RECORD_DEFAULT_MAX_DATA_BYTES = 64 * 1024;
8985
- var RECORD_MAX_DATA_BYTES = 1024 * 1024;
8986
- var RECORD_BATCH_MAX = 1e3;
8987
- var RECORD_QUERY_MAX = 1e3;
8988
- /** A kind in the `settings` file may not bound itself above this (D447: high volume is `events`). */
8989
- var RECORD_SETTINGS_MAX_ROWS = 5e4;
8990
- /** The `Column`-free proof prefix: a ref collection for a kind's secret fields. */
8991
- var RECORD_SECRET_COLLECTION_PREFIX = "records:";
8992
- /**
8993
- * Secret fields of a record, addressed the way a Zod schema declares them
8994
- * (`collectZodSecretPaths`): dotted keys, `[]` for "each element of this array"
8995
- * (`auth.accessToken`, `headers[].value`).
8996
- *
8997
- * `{}` after a key means "each value of this map" (`applianceSecrets{}`): the map's own key
8998
- * names the value (`applianceSecrets{fridge}`), so no id key is declared and a body that drops a
8999
- * key releases exactly that key's secret.
9000
- *
9001
- * Array elements are matched by a DECLARED id key (`secretArrayKeys`:
9002
- * `{ headers: 'name' }`), never by index, so reordering a list keeps every
9003
- * keychain ref (the same rule as `arrayItemFieldPath`). The concrete path of a
9004
- * leaf names its element: `headers[X-Api].value`.
9005
- *
9006
- * Pure and browser-safe. Nothing here mutates: every transform returns a new value.
9007
- */
9008
- /** The array prefixes (declared form, e.g. `headers` or `a.headers`) of a path. */
9009
- function parseSecretPath(path) {
9010
- if (path.length === 0) throw new InvalidRecordError("an empty secret path");
9011
- return path.split(".").map((raw) => {
9012
- const each = raw.endsWith("[]");
9013
- const map = raw.endsWith("{}");
9014
- const key = each || map ? raw.slice(0, -2) : raw;
9015
- if (key.length === 0) throw new InvalidRecordError(`secret path "${path}" has an empty segment`);
9016
- return {
9017
- key,
9018
- each,
9019
- map
9020
- };
9021
- });
9022
- }
9023
- /** The declared array prefixes of `path` that need an id key (`headers`, `a.rows`). */
9024
- function secretArrayPrefixes(path) {
9025
- const segments = parseSecretPath(path);
9026
- const prefixes = [];
9027
- const walked = [];
9028
- for (const segment of segments) {
9029
- walked.push(segment.key);
9030
- if (segment.each) prefixes.push(walked.join("."));
9031
- }
9032
- return prefixes;
9033
- }
9034
- function isRecord$4(value) {
9035
- return typeof value === "object" && value !== null && !Array.isArray(value);
9036
- }
9037
- function elementId(element, idKey, declared, prefix) {
9038
- const id = isRecord$4(element) ? element[idKey] : void 0;
9039
- 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`);
9040
- return id;
9041
- }
9042
- /**
9043
- * Visit every secret leaf PRESENT in `data` (an absent branch has nothing to
9044
- * visit). `replace` returns the new leaf value, or {@link REMOVE_LEAF}; the
9045
- * result is a new body, `data` is untouched.
9046
- */
9047
- var REMOVE_LEAF = Symbol("remove-leaf");
9048
- function mapAt(node, segments, index, walkedKeys, concretePrefix, declared, arrayKeys, visit) {
9049
- if (!isRecord$4(node)) return node;
9050
- const segment = segments[index];
9051
- if (segment === void 0) return node;
9052
- if (!Object.prototype.hasOwnProperty.call(node, segment.key)) return node;
9053
- const child = node[segment.key];
9054
- const keys = [...walkedKeys, segment.key];
9055
- const last = index === segments.length - 1;
9056
- if (segment.each) {
9057
- if (!Array.isArray(child)) return node;
9058
- const prefix = keys.join(".");
9059
- const idKey = arrayKeys[prefix];
9060
- if (idKey === void 0) throw new InvalidRecordError(`"${declared}": no id key declared for the array "${prefix}"`);
9061
- const mapped = child.map((element) => {
9062
- const id = elementId(element, idKey, declared, prefix);
9063
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}[${encodeURIComponent(id)}]`;
9064
- return last ? element : mapAt(element, segments, index + 1, keys, concrete, declared, arrayKeys, visit);
9065
- });
9066
- return {
9067
- ...node,
9068
- [segment.key]: mapped
9069
- };
9070
- }
9071
- if (segment.map) {
9072
- if (!isRecord$4(child)) return node;
9073
- const kept = Object.entries(child).map(([mapKey, value]) => {
9074
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}{${encodeURIComponent(mapKey)}}`;
9075
- if (!last) return [mapKey, mapAt(value, segments, index + 1, keys, concrete, declared, arrayKeys, visit)];
9076
- return [mapKey, visit({
9077
- declared,
9078
- concrete,
9079
- value
9080
- })];
9081
- }).filter(([, value]) => value !== REMOVE_LEAF);
9082
- return {
9083
- ...node,
9084
- [segment.key]: Object.fromEntries(kept)
9085
- };
9086
- }
9087
- const concrete = `${concretePrefix}${concretePrefix.length > 0 ? "." : ""}${segment.key}`;
9088
- if (last) {
9089
- const replacement = visit({
9090
- declared,
9091
- concrete,
9092
- value: child
9093
- });
9094
- if (replacement === REMOVE_LEAF) return Object.fromEntries(Object.entries(node).filter(([key]) => key !== segment.key));
9095
- return {
9096
- ...node,
9097
- [segment.key]: replacement
9098
- };
9099
- }
9100
- return {
9101
- ...node,
9102
- [segment.key]: mapAt(child, segments, index + 1, keys, concrete, declared, arrayKeys, visit)
9103
- };
9104
- }
9105
- /** Replace/remove every present secret leaf; returns a NEW body. */
9106
- function mapSecretLeaves(data, paths, arrayKeys, visit) {
9107
- let current = data;
9108
- for (const declared of paths) current = mapAt(current, parseSecretPath(declared), 0, [], "", declared, arrayKeys, visit);
9109
- return current;
9110
- }
9111
- /**
9112
- * The keychain collection name a kind's secrets live under. Prefixed so a
9113
- * record's refs never collide with the refs a legacy collection of the same name
9114
- * already holds during an adoption.
9115
- */
9116
- function recordSecretCollection(kind) {
9117
- return `${RECORD_SECRET_COLLECTION_PREFIX}${kind}`;
9118
- }
9119
- /** The ONE ref a row's secret field may carry: the engine and the facade both build it here. */
9120
- function recordSecretRef(owner, kind, rowId, concretePath) {
9121
- return buildSecretRef({
9122
- owner,
9123
- scope: {
9124
- kind: "row",
9125
- collection: recordSecretCollection(kind),
9126
- rowId
9127
- },
9128
- fieldPath: concretePath
9129
- });
9130
- }
9131
- /**
9132
- * A stored secret, as an admin read shows it: a VIEW naming the row's own
9133
- * keychain ref (`set: true`), never the value and no longer the bare redaction
9134
- * token. The form hands it to the secret field, which reveals the value by ref
9135
- * through the audited `keychain-admin.reveal`; sent back untouched it keeps the
9136
- * stored secret (the records door reads a view as KEEP).
9137
- *
9138
- * ONE implementation for the entries service and for every addon that serves
9139
- * its own instances (`RecordIntegrationInstances`).
9140
- */
9141
- function isRecord$3(value) {
9142
- return typeof value === "object" && value !== null && !Array.isArray(value);
9143
- }
9144
- function secretViewsOf(owner, kind, id, decl, data) {
9145
- if (decl.secretPaths.length === 0) return data;
9146
- const shown = mapSecretLeaves(data, decl.secretPaths, decl.secretArrayKeys, (leaf) => {
9147
- if (leaf.value !== "__camstack_redacted__") return leaf.value;
9148
- return {
9149
- $secret: recordSecretRef(owner, kind, id, leaf.concrete),
9150
- v: 1,
9151
- set: true
9152
- };
9153
- });
9154
- return isRecord$3(shown) ? shown : data;
9155
- }
9156
9562
  /**
9157
9563
  * The share-view scope kinds a share-link token can carry. The hub mints
9158
9564
  * and validates them (`ShareViewGrantSchema` builds its
@@ -9406,6 +9812,7 @@ function defineRecordKinds(specs) {
9406
9812
  function entryBody(shape) {
9407
9813
  return object({
9408
9814
  name: string().min(1),
9815
+ enabled: boolean().optional(),
9409
9816
  ...shape
9410
9817
  });
9411
9818
  }
@@ -11245,6 +11652,10 @@ Object.freeze({
11245
11652
  "all",
11246
11653
  "one"
11247
11654
  ]
11655
+ },
11656
+ {
11657
+ "path": "positionUpdatedAt",
11658
+ "valueType": "number"
11248
11659
  }
11249
11660
  ],
11250
11661
  "meter": [{
@@ -11499,22 +11910,6 @@ Object.freeze({
11499
11910
  "path": "pumpRunning",
11500
11911
  "valueType": "boolean"
11501
11912
  },
11502
- {
11503
- "path": "lastDrink",
11504
- "valueType": "number"
11505
- },
11506
- {
11507
- "path": "currentHourDrink",
11508
- "valueType": "number"
11509
- },
11510
- {
11511
- "path": "last24hDrink",
11512
- "valueType": "number"
11513
- },
11514
- {
11515
- "path": "todayDrink",
11516
- "valueType": "number"
11517
- },
11518
11913
  {
11519
11914
  "path": "error",
11520
11915
  "valueType": "string"
@@ -12080,12 +12475,66 @@ Object.freeze({
12080
12475
  }
12081
12476
  ]
12082
12477
  });
12478
+ Object.freeze({
12479
+ "actions": { "run": 363e4 },
12480
+ "audio-analyzer": { "classify": 3e4 },
12481
+ "custom-model-registry": { "importModelBundle": 18e5 },
12482
+ "database-snapshot": { "writeSnapshot": 18e5 },
12483
+ "device-manager": {
12484
+ "migrateDevice": 72e4,
12485
+ "runDiscoverySweep": 12e4
12486
+ },
12487
+ "device-provider": { "reloadDevice": 18e4 },
12488
+ "llm": {
12489
+ "generate": 6e5,
12490
+ "generateVision": 6e5,
12491
+ "testProfile": 6e5
12492
+ },
12493
+ "llm-runtime": {
12494
+ "complete": 6e5,
12495
+ "completeApple": 6e5,
12496
+ "ensureStarted": 6e5,
12497
+ "installModel": 36e5
12498
+ },
12499
+ "local-network": { "scanNetwork": 9e4 },
12500
+ "model-convert": { "convert": 6e5 },
12501
+ "pipeline-analytics": {
12502
+ "addRetrainFrameFromRecording": 6e4,
12503
+ "offerRetrainArchive": 12e4,
12504
+ "proposeRetrainAnnotationsWithLlm": 18e4,
12505
+ "resolveRetrainTrainingCorpus": 6e4,
12506
+ "writeRetrainArchive": 36e5
12507
+ },
12508
+ "server-management": { "applyServerUpdate": 96e4 },
12509
+ "terminal-session": { "pullOutput": 15e3 },
12510
+ "training": {
12511
+ "canaryResult": 12e4,
12512
+ "cancelJob": 12e4,
12513
+ "planJob": 6e4,
12514
+ "registerResult": 18e5,
12515
+ "rollbackCanary": 12e4,
12516
+ "startJob": 12e4,
12517
+ "startJobBatch": 12e4
12518
+ },
12519
+ "training-provider": {
12520
+ "cancelJob": 6e4,
12521
+ "cleanupJob": 3e5,
12522
+ "getJob": 6e4,
12523
+ "listJobEvents": 6e4,
12524
+ "listJobs": 12e4,
12525
+ "offerArtifact": 3e5,
12526
+ "readResult": 3e5,
12527
+ "submitJob": 18e5,
12528
+ "uploadDataset": 72e5,
12529
+ "validateCredentials": 3e4
12530
+ }
12531
+ });
12083
12532
  object({
12084
12533
  code: string().regex(/^[a-z][a-z0-9-]*(\.[a-z0-9-]+)+$/),
12085
12534
  params: record(string(), union([string(), number()])).optional()
12086
12535
  });
12087
12536
  //#endregion
12088
- //#region ../types/dist/composition-pOHbTzRB.mjs
12537
+ //#region ../types/dist/composition-BmBHuDTQ.mjs
12089
12538
  /**
12090
12539
  * The ffmpeg build every CamStack node downloads, per platform and arch.
12091
12540
  *
@@ -12389,7 +12838,7 @@ var table = {
12389
12838
  },
12390
12839
  dwell: {
12391
12840
  minArgs: 3,
12392
- maxArgs: 3,
12841
+ maxArgs: 4,
12393
12842
  apply: () => {
12394
12843
  throw new ExpressionEvalError("dwell: stateful evaluation context is required");
12395
12844
  }
@@ -13432,212 +13881,6 @@ var IntegrationInstanceRefSchema = object({
13432
13881
  ]),
13433
13882
  candidateStableId: string().optional()
13434
13883
  });
13435
- /**
13436
- * `RecordIntegrationInstances` - the `integration-instances` provider over ONE
13437
- * entry kind, so an addon that holds a connection serves it in ~30 lines.
13438
- *
13439
- * Every instance is one record of the addon's own kind, keyed by the
13440
- * `integrations` registry id. The records door does the secret work: a field the
13441
- * kind marks `.meta({ secret: true })` is a keychain marker bound to the row, so
13442
- * deleting the row deletes the secret, and one row's value is never another's.
13443
- *
13444
- * Patch rules for a secret (`updateInstance`): omitted, `''`, the redaction
13445
- * token or the view the form was given KEEP the stored secret;
13446
- * `{ $secretClear: true }` clears it; any other string replaces it.
13447
- */
13448
- /** The most instances one addon lists (an integrations page, not a table). */
13449
- var INSTANCES_LIST_MAX = 1e3;
13450
- /** The keys of the kind's secret fields that sit at the top level of the body. */
13451
- function topLevelSecretKeys(paths) {
13452
- return new Set(paths.filter((p) => !p.includes(".") && !p.includes("[") && !p.includes("{")));
13453
- }
13454
- /** The keys of the kind's top-level MAPS whose values are secrets (`applianceSecrets{}`). */
13455
- function secretMapKeys(paths) {
13456
- return new Set(paths.filter((p) => p.endsWith("{}") && !p.slice(0, -2).match(/[.[{]/)).map((p) => p.slice(0, -2)));
13457
- }
13458
- /**
13459
- * A patch value for a map of secrets: an entry that is omitted, `''`, the redaction token or the
13460
- * view the form was given KEEPS its stored secret (it is left out of the merge); `{ $secretClear }`
13461
- * or `null` removes the entry; any other string replaces it. Null when nothing is left to merge.
13462
- */
13463
- function secretMapPatch(value) {
13464
- if (typeof value !== "object" || value === null || Array.isArray(value)) return null;
13465
- const out = {};
13466
- for (const [key, entry] of Object.entries(value)) if (entry === null || isSecretClear(entry)) out[key] = null;
13467
- else if (typeof entry === "string" && entry !== "" && entry !== "__camstack_redacted__" && !isSecretFieldView(entry)) out[key] = entry;
13468
- return Object.keys(out).length > 0 ? out : null;
13469
- }
13470
- /** Does the kind's body schema carry an `enabled` field? */
13471
- function declaresEnabled(kind) {
13472
- const json = toJSONSchema(kind.schema, {
13473
- unrepresentable: "any",
13474
- io: "input"
13475
- });
13476
- const properties = Reflect.get(json, "properties");
13477
- return typeof properties === "object" && properties !== null && "enabled" in properties;
13478
- }
13479
- var RecordIntegrationInstances = class {
13480
- records;
13481
- kind;
13482
- hooks;
13483
- handle;
13484
- secretKeys;
13485
- secretMaps;
13486
- nameField;
13487
- /** The `integrations` registry owns the on/off switch (`role: devices`); the body has none. */
13488
- registryOwnsEnabled;
13489
- constructor(records, kind, hooks) {
13490
- this.records = records;
13491
- this.kind = kind;
13492
- this.hooks = hooks;
13493
- this.handle = records.kind(kind);
13494
- this.secretKeys = topLevelSecretKeys(kind.declaration.secretPaths);
13495
- this.secretMaps = secretMapKeys(kind.declaration.secretPaths);
13496
- this.nameField = kind.declaration.entry?.nameField ?? "name";
13497
- this.registryOwnsEnabled = hooks.description.role === "devices";
13498
- 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"`);
13499
- }
13500
- /**
13501
- * One instance read for the addon's own runtime; null when absent. When the keychain is
13502
- * locked the row is served WITHOUT its secrets and says so (`secrets: 'unavailable'`), so the
13503
- * caller can keep what it had instead of reconfiguring with an empty secret (D49).
13504
- */
13505
- async readResolved(id) {
13506
- try {
13507
- const record = await this.handle.getResolved(id);
13508
- return record === null ? null : {
13509
- id,
13510
- body: record.data,
13511
- enabled: record.data.enabled !== false,
13512
- secrets: "resolved"
13513
- };
13514
- } catch (err) {
13515
- if (!(err instanceof RecordSecretUnavailableError)) throw err;
13516
- const stored = await this.handle.get(id);
13517
- if (stored === null) return null;
13518
- return {
13519
- id,
13520
- body: Object.fromEntries(Object.entries(stored.data).filter(([key]) => !this.secretKeys.has(key))),
13521
- enabled: stored.data.enabled !== false,
13522
- secrets: "unavailable"
13523
- };
13524
- }
13525
- }
13526
- /** The body of {@link readResolved} alone; a locked keychain yields the row without secrets. */
13527
- async getResolved(id) {
13528
- return (await this.readResolved(id))?.body ?? null;
13529
- }
13530
- /** Every instance, secrets resolved where the keychain allows; an absent one is skipped. */
13531
- async listResolved() {
13532
- const page = await this.handle.query({ limit: INSTANCES_LIST_MAX });
13533
- const out = [];
13534
- for (const record of page.records) {
13535
- const read = await this.readResolved(record.id);
13536
- if (read !== null) out.push(read);
13537
- }
13538
- return out;
13539
- }
13540
- viewOf(record) {
13541
- const shown = secretViewsOf(this.records.owner, this.kind.name, record.id, this.kind.declaration, record.data);
13542
- const rawName = record.data[this.nameField];
13543
- const kind = this.hooks.kindOf?.(record.data);
13544
- const health = this.hooks.health?.(record.data, record.id);
13545
- return {
13546
- id: record.id,
13547
- name: typeof rawName === "string" ? rawName : record.id,
13548
- configured: this.hooks.configured(record.data),
13549
- ...this.registryOwnsEnabled ? {} : { enabled: record.data.enabled !== false },
13550
- formValues: shown,
13551
- ...kind !== void 0 ? { kind } : {},
13552
- ...health?.status !== void 0 ? { status: health.status } : {},
13553
- ...health?.lastCheckedAt !== void 0 ? { lastCheckedAt: health.lastCheckedAt } : {}
13554
- };
13555
- }
13556
- describe = async () => this.hooks.mintId === void 0 ? this.hooks.description : {
13557
- ...this.hooks.description,
13558
- mintsId: true
13559
- };
13560
- instanceFormSchema = async ({ id }) => this.hooks.formSchema(id);
13561
- listInstances = async () => {
13562
- return (await this.handle.query({ limit: INSTANCES_LIST_MAX })).records.map((record) => this.viewOf(record));
13563
- };
13564
- getInstance = async ({ id }) => {
13565
- const record = await this.handle.get(id);
13566
- return record === null ? null : this.viewOf(record);
13567
- };
13568
- /** Insert ONE row (`ifRev: 0`: an existing id is refused, never overwritten). */
13569
- createInstance = async ({ id, name, kind, values }) => {
13570
- const minted = id ?? this.hooks.mintId?.({
13571
- name,
13572
- ...kind !== void 0 ? { kind } : {}
13573
- });
13574
- if (minted === void 0) throw new Error("createInstance needs an id: this provider does not mint one");
13575
- await this.handle.put({
13576
- id: minted,
13577
- data: this.hooks.initialBody(name, kind)
13578
- }, { ifRev: 0 });
13579
- const patch = this.patchOf(values ?? {});
13580
- if (Object.keys(patch).length > 0) await this.handle.patch(minted, patch);
13581
- await this.hooks.onChanged?.(minted, "created");
13582
- return { id: minted };
13583
- };
13584
- updateInstance = async ({ id, name, values }) => {
13585
- const patch = this.patchOf(values);
13586
- if (name !== void 0) patch[this.nameField] = name;
13587
- await this.handle.patch(id, patch);
13588
- await this.hooks.onChanged?.(id, "updated");
13589
- return { ok: true };
13590
- };
13591
- /** The record patch a form `values` object means: secrets kept, cleared or replaced. */
13592
- patchOf(values) {
13593
- const patch = {};
13594
- for (const [key, value] of Object.entries(values)) {
13595
- if (value === void 0) continue;
13596
- if (this.secretMaps.has(key)) {
13597
- const entries = secretMapPatch(value);
13598
- if (entries !== null) patch[key] = entries;
13599
- } else if (!this.secretKeys.has(key)) patch[key] = value;
13600
- else if (isSecretClear(value)) patch[key] = null;
13601
- else if (typeof value === "string" && value !== "" && value !== "__camstack_redacted__" && !isSecretFieldView(value)) patch[key] = value;
13602
- }
13603
- return patch;
13604
- }
13605
- /** The switch lives in the record body; the addon is told so it applies it (D996). */
13606
- setInstanceEnabled = async ({ id, enabled }) => {
13607
- if (this.registryOwnsEnabled) throw new Error(`instance "${id}": the integrations registry owns the on/off switch of this addon; set it with integrations.update`);
13608
- await this.handle.patch(id, { enabled });
13609
- await this.hooks.onChanged?.(id, "enabled");
13610
- return { ok: true };
13611
- };
13612
- /** The row and its keychain refs go together (the records door). */
13613
- deleteInstance = async ({ id }) => {
13614
- await this.handle.delete(id);
13615
- await this.hooks.onChanged?.(id, "deleted");
13616
- return { ok: true };
13617
- };
13618
- testInstance = async (input) => {
13619
- if (this.hooks.test === void 0) return {
13620
- success: false,
13621
- status: "unsupported",
13622
- error: "This integration declares no connection test"
13623
- };
13624
- return this.hooks.test(input);
13625
- };
13626
- /** The flat provider object to hand to `registerProvider`. */
13627
- toProvider() {
13628
- return {
13629
- describe: this.describe,
13630
- instanceFormSchema: this.instanceFormSchema,
13631
- listInstances: this.listInstances,
13632
- getInstance: this.getInstance,
13633
- createInstance: this.createInstance,
13634
- updateInstance: this.updateInstance,
13635
- setInstanceEnabled: this.setInstanceEnabled,
13636
- deleteInstance: this.deleteInstance,
13637
- testInstance: this.testInstance
13638
- };
13639
- }
13640
- };
13641
13884
  var EncodeProfileSchema = object({
13642
13885
  video: object({
13643
13886
  codec: _enum([
@@ -19822,31 +20065,21 @@ var APPLIANCE_CAP_VOCABULARY = {
19822
20065
  "pet-fountain": {
19823
20066
  scope: "device",
19824
20067
  noun: t("Pet fountain", "Fontana per animali"),
19825
- actions: [
19826
- {
19827
- id: "petFountain.pumpOn",
19828
- method: "setPump",
19829
- label: t("Pump on", "Pompa accesa"),
19830
- phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
19831
- icon: "play",
19832
- args: { on: true }
19833
- },
19834
- {
19835
- id: "petFountain.pumpOff",
19836
- method: "setPump",
19837
- label: t("Pump off", "Pompa spenta"),
19838
- phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
19839
- icon: "square",
19840
- args: { on: false }
19841
- },
19842
- {
19843
- id: "petFountain.resetDailyConsumption",
19844
- method: "resetDailyConsumption",
19845
- label: t("Clear daily consumption", "Azzera il consumo giornaliero"),
19846
- phrase: t("Clear the daily water consumption of {device}", "Azzera il consumo giornaliero di acqua di {device}"),
19847
- icon: "rotate-ccw"
19848
- }
19849
- ],
20068
+ actions: [{
20069
+ id: "petFountain.pumpOn",
20070
+ method: "setPump",
20071
+ label: t("Pump on", "Pompa accesa"),
20072
+ phrase: t("Start the pump of {device}", "Avvia la pompa di {device}"),
20073
+ icon: "play",
20074
+ args: { on: true }
20075
+ }, {
20076
+ id: "petFountain.pumpOff",
20077
+ method: "setPump",
20078
+ label: t("Pump off", "Pompa spenta"),
20079
+ phrase: t("Stop the pump of {device}", "Ferma la pompa di {device}"),
20080
+ icon: "square",
20081
+ args: { on: false }
20082
+ }],
19850
20083
  state: [{
19851
20084
  kind: "boolean",
19852
20085
  field: "empty",
@@ -43740,8 +43973,15 @@ var ActionInputSchema = object({
43740
43973
  var ActionRunOriginSchema = object({
43741
43974
  /** The automation block whose step started it. */
43742
43975
  blockId: string().min(1).optional() });
43743
- /** `started` = the caller did not ask to wait. */
43744
- var ActionRunOutcomeSchema = union([AutomationRunOutcomeSchema, literal("started")]);
43976
+ /**
43977
+ * `started` = the caller did not ask to wait. `timed-out` = the run reached the
43978
+ * ceiling (`ACTION_RUN_MAX_MS`) and was stopped; it is never a `ran`.
43979
+ */
43980
+ var ActionRunOutcomeSchema = union([
43981
+ AutomationRunOutcomeSchema,
43982
+ literal("started"),
43983
+ literal("timed-out")
43984
+ ]);
43745
43985
  var ActionRunResultSchema = object({
43746
43986
  runId: string().min(1),
43747
43987
  outcome: ActionRunOutcomeSchema,
@@ -44263,6 +44503,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44263
44503
  kind: "mutation",
44264
44504
  auth: "admin"
44265
44505
  });
44506
+ /** `timeoutMs` of `actions.run`: a waited call outlives any legal run. */
44507
+ var ACTION_RUN_TIMEOUT_MS = 363e4;
44266
44508
  /**
44267
44509
  * actions — the ONE surface for runnable actions, for the UI and for
44268
44510
  * automations. Provided by the core-blocks builtin on the hub.
@@ -44281,6 +44523,12 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44281
44523
  * An admin, and an in-process caller (an automation block), may run any action.
44282
44524
  * Every refusal is typed (`[not-linked] …`) and logged.
44283
44525
  *
44526
+ * **A run lasts at most `ACTION_RUN_MAX_MS` (60 min).** The provider stops a
44527
+ * run that reaches it and answers `timed-out` (never `ran`); an action whose
44528
+ * `wait` steps alone add up to more is refused at create/update
44529
+ * (`[invalid-steps]`). `run` declares a `timeoutMs` above that ceiling, so a
44530
+ * waited call (an automation step) is never cut by the 60 s transport default.
44531
+ *
44284
44532
  * A second `run` of an action that is already running is REFUSED — traced and
44285
44533
  * logged — never queued.
44286
44534
  */
@@ -44307,7 +44555,8 @@ method(object({}), array(ActionEntrySchema), { auth: "admin" }), method(object({
44307
44555
  role: "viewer",
44308
44556
  auth: "protected",
44309
44557
  kind: "mutation",
44310
- caller: "required"
44558
+ caller: "required",
44559
+ timeoutMs: ACTION_RUN_TIMEOUT_MS
44311
44560
  }), method(ActionIdInput, _void(), {
44312
44561
  kind: "mutation",
44313
44562
  auth: "admin"
@@ -48352,6 +48601,9 @@ var MediaPlayerStatusSchema = object({
48352
48601
  /** Repeat mode. Null when no repeat surface.
48353
48602
  * Pair with `DeviceFeature.MediaPlayerRepeat`. */
48354
48603
  repeat: MediaPlayerRepeatSchema.nullable(),
48604
+ /** Ms epoch when `position` was read from the device. Null when the driver
48605
+ * does not say; a UI that advances the position while playing counts from it. */
48606
+ positionUpdatedAt: number().nullable().default(null),
48355
48607
  /** Ms epoch when the slice was last updated. */
48356
48608
  lastChangedAt: number()
48357
48609
  });
@@ -48931,7 +49183,9 @@ var ThresholdTransformDraftSchema = object({
48931
49183
  comparison: _enum(["gte", "lte"]),
48932
49184
  threshold: number(),
48933
49185
  startDwellMs: number().nonnegative(),
48934
- stopDwellMs: number().nonnegative()
49186
+ stopDwellMs: number().nonnegative(),
49187
+ /** Samples a start needs; absent = the compiler's default for the source (2 for running power, else 1). */
49188
+ minSamples: number().int().min(1).optional()
48935
49189
  });
48936
49190
  var CustomizeTransformDraftSchema = discriminatedUnion("kind", [
48937
49191
  IdentityTransformDraftSchema,
@@ -53884,6 +54138,7 @@ var IntegrationWithStateSchema = object({
53884
54138
  id: string(),
53885
54139
  addonId: string(),
53886
54140
  name: string(),
54141
+ /** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
53887
54142
  enabled: boolean(),
53888
54143
  info: record(string(), unknown()).readonly(),
53889
54144
  /** The discovery candidate this integration was set up from (D984). */
@@ -53896,6 +54151,7 @@ var IntegrationLiteSchema = object({
53896
54151
  id: string(),
53897
54152
  addonId: string(),
53898
54153
  name: string(),
54154
+ /** A projection of the instance body's switch (`setInstanceEnabled` is the only writer). */
53899
54155
  enabled: boolean(),
53900
54156
  info: record(string(), unknown()).readonly(),
53901
54157
  /** The discovery candidate this integration was set up from (D984). */
@@ -53995,7 +54251,6 @@ var TestConnectionResultSchema = object({
53995
54251
  var CreateIntegrationInputSchema = object({
53996
54252
  addonId: string(),
53997
54253
  name: string(),
53998
- enabled: boolean().optional(),
53999
54254
  info: record(string(), unknown()).optional(),
54000
54255
  /** `stableId` of the discovery candidate the form was seeded from (D984). */
54001
54256
  originStableId: string().optional(),
@@ -54004,6 +54259,11 @@ var CreateIntegrationInputSchema = object({
54004
54259
  var UpdateIntegrationInputSchema = object({
54005
54260
  id: string(),
54006
54261
  name: string().optional(),
54262
+ /**
54263
+ * Accepted for a FIXED builtin only (`info.fixed`: alarm panel, camera grid, core blocks,
54264
+ * terminal), which keeps no instance record: the registry flag is its one store. Any other
54265
+ * integration is switched through `integration-instances.setInstanceEnabled`.
54266
+ */
54007
54267
  enabled: boolean().optional(),
54008
54268
  info: record(string(), unknown()).optional()
54009
54269
  });
@@ -54051,7 +54311,7 @@ var IntegrationInstanceIdSchema = string().min(1);
54051
54311
  var IntegrationInstanceModeSchema = _enum(["single", "multiple"]);
54052
54312
  /**
54053
54313
  * What the addon's instances ARE for the Integrations page (planning#416). `devices`: each
54054
- * instance is an integration that brings devices (the registry owns its on/off switch);
54314
+ * instance is an integration that brings devices (its record body owns the on/off switch);
54055
54315
  * `services`: a connection configured from the addon's own function page, never listed on
54056
54316
  * Integrations.
54057
54317
  * It is the same vocabulary as the manifest's `integrationRole`, which stays as an override.
@@ -54094,18 +54354,38 @@ var IntegrationInstanceKindSchema = object({
54094
54354
  /** Relative hub path to disconnect that account. */
54095
54355
  disconnectPath: string().min(1).optional()
54096
54356
  });
54357
+ /**
54358
+ * How devices of an instance are found. `none`: the operator adds them by hand; `lan`: the addon
54359
+ * scans the network before any instance exists (the wizard offers the candidates); `account`: the
54360
+ * devices appear after the instance signs in. `scopedToInstance`: a discovery run belongs to ONE
54361
+ * instance and its candidates are claimed by it.
54362
+ */
54363
+ var IntegrationInstanceDiscoverySchema = object({
54364
+ mode: _enum([
54365
+ "none",
54366
+ "lan",
54367
+ "account"
54368
+ ]),
54369
+ scopedToInstance: boolean()
54370
+ });
54371
+ /**
54372
+ * One link a kind of this provider declares (D1013 rule 5): the body `field` of an instance of
54373
+ * `kind` holds the id of an instance of the function cap `to.cap` (of kind `to.kind`, when set).
54374
+ * The hub indexes these so the target's delete is refused while a link names it.
54375
+ */
54376
+ var IntegrationInstanceLinkSchema = object({
54377
+ kind: string().min(1),
54378
+ field: string().min(1),
54379
+ to: object({
54380
+ cap: string().min(1),
54381
+ kind: string().min(1).optional()
54382
+ })
54383
+ });
54097
54384
  var IntegrationInstanceDescriptionSchema = object({
54098
54385
  /** What the instances are for the Integrations page; see {@link IntegrationInstanceRoleSchema}. */
54099
54386
  role: IntegrationInstanceRoleSchema,
54100
54387
  /** How the devices of an instance are found; absent means `{ mode: 'none' }`. */
54101
- discovery: object({
54102
- mode: _enum([
54103
- "none",
54104
- "lan",
54105
- "account"
54106
- ]),
54107
- scopedToInstance: boolean()
54108
- }).optional(),
54388
+ discovery: IntegrationInstanceDiscoverySchema.optional(),
54109
54389
  /** `single`: at most one instance can exist (Loki). `multiple`: an account each. */
54110
54390
  instanceMode: IntegrationInstanceModeSchema,
54111
54391
  /** What the instance is, for the UI (`destination`, `relay`, `account`). */
@@ -54126,7 +54406,9 @@ var IntegrationInstanceDescriptionSchema = object({
54126
54406
  * `createInstance` without an `id` works: the provider mints it. Absent means the caller must
54127
54407
  * send an id (the UI then mints an opaque one).
54128
54408
  */
54129
- mintsId: boolean().optional()
54409
+ mintsId: boolean().optional(),
54410
+ /** The links to other instances the provider's kinds declare; absent means none. */
54411
+ links: array(IntegrationInstanceLinkSchema).optional()
54130
54412
  });
54131
54413
  var IntegrationInstanceStatusSchema = object({
54132
54414
  state: _enum([
@@ -54146,8 +54428,8 @@ var IntegrationInstanceSchema = object({
54146
54428
  configured: boolean(),
54147
54429
  /**
54148
54430
  * The instance's own on/off switch (D996), derived from the record body (`enabled !== false`,
54149
- * so a row written before the field existed is on). Absent when the `integrations` registry
54150
- * owns the switch (`describe().role` is `devices`): read it from the registry row.
54431
+ * so a row written before the field existed is on). The same for every role, `devices` included:
54432
+ * the body is the one store, `setInstanceEnabled` the one writer (epic #440, step 3).
54151
54433
  */
54152
54434
  enabled: boolean().optional(),
54153
54435
  /** The kind of this instance (one of `describe().kinds[].id`), when the provider has kinds. */
@@ -54197,7 +54479,8 @@ var integrationInstancesCapability = {
54197
54479
  auth: "admin"
54198
54480
  }),
54199
54481
  /**
54200
- * Switch ONE instance on or off. A row control, not a form field: `updateInstance.values` is the
54482
+ * Switch ONE instance on or off, for every role; a missing record is created from the addon's
54483
+ * initial body. A row control, not a form field: `updateInstance.values` is the
54201
54484
  * form patch (D62, D996). An off instance keeps its record and secrets and does no work.
54202
54485
  */
54203
54486
  setInstanceEnabled: method(object({
@@ -57008,6 +57291,8 @@ var MigrationIntegrationSchema = object({
57008
57291
  addonId: string(),
57009
57292
  name: string(),
57010
57293
  info: Rows,
57294
+ /** The registry's stored switch: read by the one-switch migration, nothing else. */
57295
+ enabled: boolean().optional(),
57011
57296
  originStableId: string().optional()
57012
57297
  });
57013
57298
  var MigrationDeviceSchema = object({
@@ -66545,14 +66830,6 @@ object({
66545
66830
  empty: boolean().nullable(),
66546
66831
  /** True while the pump is running. Null while unknown. */
66547
66832
  pumpRunning: boolean().nullable(),
66548
- /** Water drunk in the last drink, in litres. */
66549
- lastDrink: number().min(0).nullable().meta(readingMeta("volume")),
66550
- /** Water drunk in the current hour, in litres. */
66551
- currentHourDrink: number().min(0).nullable().meta(readingMeta("volume")),
66552
- /** Water drunk over the last 24 hours (rolling), in litres. */
66553
- last24hDrink: number().min(0).nullable().meta(readingMeta("volume")),
66554
- /** Water drunk since local midnight, in litres. Null when the fountain has no such sensor. */
66555
- todayDrink: number().min(0).nullable().meta(readingMeta("volume")),
66556
66833
  /** Decoded fault message. Null means healthy; a non-null string is an active fault. */
66557
66834
  error: string().nullable(),
66558
66835
  /** Ms epoch when the slice was last refreshed. */
@@ -66565,9 +66842,6 @@ DeviceType.PetFountain, method(object({
66565
66842
  }), _void(), {
66566
66843
  kind: "mutation",
66567
66844
  auth: "protected"
66568
- }), method(object({ deviceId: DeviceIdSchema$1 }), _void(), {
66569
- kind: "mutation",
66570
- auth: "protected"
66571
66845
  });
66572
66846
  /**
66573
66847
  * The wire shapes of the Auto tune plan and apply (D745), used by the
@@ -81941,13 +82215,6 @@ Object.freeze({
81941
82215
  access: "view",
81942
82216
  role: "viewer"
81943
82217
  },
81944
- "petFountain.resetDailyConsumption": {
81945
- capName: "pet-fountain",
81946
- capScope: "device",
81947
- addonId: null,
81948
- access: "delete",
81949
- role: "viewer"
81950
- },
81951
82218
  "petFountain.setPump": {
81952
82219
  capName: "pet-fountain",
81953
82220
  capScope: "device",
@@ -88344,11 +88611,6 @@ Object.freeze({
88344
88611
  form: "single",
88345
88612
  optional: false
88346
88613
  }],
88347
- "petFountain.resetDailyConsumption": [{
88348
- name: "deviceId",
88349
- form: "single",
88350
- optional: false
88351
- }],
88352
88614
  "petFountain.setPump": [{
88353
88615
  name: "deviceId",
88354
88616
  form: "single",
@@ -91092,48 +91354,53 @@ object({
91092
91354
  delay: number().nonnegative().optional(),
91093
91355
  commands: record(string(), unknown())
91094
91356
  });
91095
- var BrokerInUseError = class extends Error {
91096
- brokerId;
91357
+ var InstanceInUseError = class extends Error {
91358
+ instanceId;
91097
91359
  users;
91098
- name = "BrokerInUseError";
91099
- constructor(brokerId, users) {
91100
- super(`broker '${brokerId}' is still in use by ${users.map((u) => `${u.kind} '${u.name ?? u.id}' (${u.id})`).join(", ")}; unlink them first`);
91101
- this.brokerId = brokerId;
91360
+ name = "InstanceInUseError";
91361
+ constructor(instanceId, users) {
91362
+ super(`instance '${instanceId}' is still in use by ${users.map((u) => `${u.kind} '${u.name ?? u.id}' (${u.id})`).join(", ")}; unlink them first`);
91363
+ this.instanceId = instanceId;
91102
91364
  this.users = users;
91103
91365
  }
91104
91366
  };
91105
- /** Throw {@link BrokerInUseError} when any finder names a user of `brokerId`. */
91106
- async function assertBrokerUnused(brokerId, finders) {
91367
+ /** Throw {@link InstanceInUseError} when any finder names a user of `instanceId`. */
91368
+ async function assertInstanceUnused(instanceId, finders) {
91107
91369
  const users = [];
91108
- for (const finder of finders) users.push(...await finder.find(brokerId));
91109
- if (users.length > 0) throw new BrokerInUseError(brokerId, users);
91370
+ for (const finder of finders) users.push(...await finder.find(instanceId));
91371
+ if (users.length > 0) throw new InstanceInUseError(instanceId, users);
91372
+ }
91373
+ function namesInstance(value, instanceId) {
91374
+ if (Array.isArray(value)) return value.includes(instanceId);
91375
+ return value === instanceId;
91110
91376
  }
91111
91377
  /**
91112
91378
  * Users reached through another addon's listed rows (an addon cannot read a record kind it does
91113
- * not own): every row whose `field` holds the broker id. `list` is a cap call the owner serves.
91379
+ * not own): every row whose `field` holds the instance id, as a string or in a string list.
91380
+ * `list` is a cap call the owner serves.
91114
91381
  */
91115
91382
  function fieldUserFinder(spec) {
91116
- return { find: async (brokerId) => (await spec.list()).filter((row) => row.formValues[spec.field] === brokerId).map((row) => ({
91383
+ const fields = typeof spec.field === "string" ? [spec.field] : spec.field;
91384
+ return { find: async (instanceId) => (await spec.list()).filter((row) => fields.some((f) => namesInstance(row.formValues[f], instanceId))).map((row) => ({
91117
91385
  kind: spec.kind,
91118
91386
  id: row.id,
91119
91387
  ...row.name !== void 0 ? { name: row.name } : {}
91120
91388
  })) };
91121
91389
  }
91122
91390
  /**
91123
- * An account provider whose `deleteInstance` is refused while anything still uses the account
91124
- * (D1012). The account is an `integration-instances` kind (D1013), so the refusal lives on the
91125
- * delete the instances page calls, not on a separate broker cap.
91391
+ * A provider whose `deleteInstance` is refused while anything still uses the instance. The
91392
+ * account is an `integration-instances` kind (D1013), so the refusal lives on the delete the
91393
+ * instances page calls.
91126
91394
  */
91127
- function guardBrokerDelete(base, users) {
91395
+ function guardInstanceDelete(base, users) {
91128
91396
  return {
91129
91397
  ...base,
91130
91398
  deleteInstance: async (input) => {
91131
- await assertBrokerUnused(input.id, users());
91399
+ await assertInstanceUnused(input.id, users());
91132
91400
  return base.deleteInstance(input);
91133
91401
  }
91134
91402
  };
91135
91403
  }
91136
- entryBody({ brokerId: string() });
91137
91404
  //#endregion
91138
91405
  //#region ../../node_modules/xtend/immutable.js
91139
91406
  var require_immutable = /* @__PURE__ */ __commonJSMin(((exports, module) => {
@@ -123358,7 +123625,7 @@ var PROBE_LABELS = {
123358
123625
  };
123359
123626
  /** The instance's health word: connected / auth-failed / unreachable / tls-error, latency, clients. */
123360
123627
  function mqttHealthOf(body, live, now) {
123361
- if (body.enabled === false) return { status: {
123628
+ if (!isInstanceEnabled(body)) return { status: {
123362
123629
  state: "off",
123363
123630
  label: "Switched off"
123364
123631
  } };
@@ -123483,7 +123750,7 @@ function buildMqttBrokerInstances(records, deps) {
123483
123750
  onboard: built.onboard
123484
123751
  };
123485
123752
  };
123486
- return guardBrokerDelete({
123753
+ return guardInstanceDelete({
123487
123754
  ...base,
123488
123755
  instanceFormSchema: async ({ id }) => {
123489
123756
  const saved = id === null ? null : await instances.getResolved(id);
@@ -124217,7 +124484,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124217
124484
  getBrokerConfig(id) {
124218
124485
  const external = this.activeExternalBrokers.find((b) => b.id === id);
124219
124486
  if (external) {
124220
- if (external.enabled === false) throw new Error(`mqtt-broker: broker '${id}' is switched off`);
124487
+ if (!isInstanceEnabled(external)) throw new Error(`mqtt-broker: broker '${id}' is switched off`);
124221
124488
  const password = this.storedPassword(external.password);
124222
124489
  return {
124223
124490
  url: external.url,
@@ -124473,7 +124740,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124473
124740
  * entry disappeared, and respawn runtimes whose port changed.
124474
124741
  */
124475
124742
  async reconcileOnboardRuntimes() {
124476
- const desiredEntries = this.activeExternalBrokers.filter(hasOnboard).filter((b) => b.enabled !== false);
124743
+ const desiredEntries = this.activeExternalBrokers.filter(hasOnboard).filter((b) => isInstanceEnabled(b));
124477
124744
  const desired = desiredEntries.map((b) => ({
124478
124745
  id: b.id,
124479
124746
  port: b.onboard.port
@@ -124614,7 +124881,7 @@ var MqttBrokerAddon = class extends BaseAddon {
124614
124881
  collectExternalProbeInputs() {
124615
124882
  const out = [];
124616
124883
  for (const b of this.activeExternalBrokers) {
124617
- if (b.onboard !== void 0 || b.enabled === false) continue;
124884
+ if (b.onboard !== void 0 || !isInstanceEnabled(b)) continue;
124618
124885
  let password;
124619
124886
  try {
124620
124887
  password = this.storedPassword(b.password);