@camstack/addon-post-analysis 1.1.14 → 1.1.16

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.
@@ -4649,7 +4649,7 @@ function _instanceof(cls, params = {}) {
4649
4649
  return inst;
4650
4650
  }
4651
4651
  //#endregion
4652
- //#region ../types/dist/sleep-MHm--th-.mjs
4652
+ //#region ../types/dist/sleep-BiDFW0E7.mjs
4653
4653
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
4654
4654
  EventCategory["SystemBoot"] = "system.boot";
4655
4655
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -5462,6 +5462,100 @@ function createDurableState(deps) {
5462
5462
  };
5463
5463
  }
5464
5464
  /**
5465
+ * Per-node scoping for the shared addon-settings blob.
5466
+ *
5467
+ * An addon's settings store is hub-central (the `addon-settings` cap is
5468
+ * hub-routed — the hub instance answers for every node), so fields whose
5469
+ * value is a NODE fact (decoder backend, engine pick, probed hardware
5470
+ * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
5471
+ * the single shared blob. The SCHEMA field key stays bare: the write path
5472
+ * ({@link scopePatch}) maps the bare field onto the target node's scoped
5473
+ * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
5474
+ * back, so UI forms and `resolveConfig` only ever see the bare key.
5475
+ *
5476
+ * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
5477
+ * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
5478
+ * schema and routes reads/writes through these helpers.
5479
+ *
5480
+ * ## No bare-key fallback — deliberate
5481
+ *
5482
+ * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
5483
+ * scoped key resolves to `undefined` so the field's schema `default` wins —
5484
+ * NEVER `store[base]` and never another node's value. A bare legacy key in
5485
+ * the store is invisible to every node, hub included, so one node's
5486
+ * selection can never leak onto another. (This generalizes the
5487
+ * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
5488
+ * arbitrary set of per-node field keys.)
5489
+ *
5490
+ * Pure functions only — no I/O, no imports beyond the language. This is a
5491
+ * LEAF module: import it via its deep path, never from the root barrel.
5492
+ */
5493
+ /**
5494
+ * Normalize a raw kernel node id to the bare node id used for scoping.
5495
+ * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
5496
+ * processes; per-node settings are per-NODE, so strip the addon segment.
5497
+ * `undefined` / `null` / empty falls back to `'hub'`.
5498
+ */
5499
+ function normalizeNodeId(raw) {
5500
+ if (raw === void 0 || raw === null || raw === "") return "hub";
5501
+ const slashIdx = raw.indexOf("/");
5502
+ if (slashIdx < 0) return raw;
5503
+ const bare = raw.slice(0, slashIdx);
5504
+ return bare === "" ? "hub" : bare;
5505
+ }
5506
+ /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
5507
+ function nodeScopedKey(base, nodeId) {
5508
+ return `${base}@${normalizeNodeId(nodeId)}`;
5509
+ }
5510
+ /**
5511
+ * Read a node's value for a per-node field from the raw shared store:
5512
+ * the node-scoped key when present, otherwise `undefined`.
5513
+ * Deliberately NO bare-key fallback (see module doc) — the caller lets the
5514
+ * schema `default` win on `undefined`.
5515
+ */
5516
+ function readNodeValue(store, base, nodeId) {
5517
+ return store[nodeScopedKey(base, nodeId)];
5518
+ }
5519
+ /**
5520
+ * Re-map a UI/settings patch so every bare perNode field persists under the
5521
+ * TARGET node's scoped key; all other keys pass through unchanged. Used on
5522
+ * the write path so a save for one node never clobbers another node's value
5523
+ * (and the bare key is never written). Returns a new object — the input
5524
+ * patch is not mutated.
5525
+ */
5526
+ function scopePatch(patch, perNodeKeys, nodeId) {
5527
+ const out = {};
5528
+ for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
5529
+ return out;
5530
+ }
5531
+ /**
5532
+ * Project the raw shared store onto the bare schema keys for ONE node so a
5533
+ * UI schema (whose field keys are bare) hydrates from that node's own
5534
+ * values:
5535
+ *
5536
+ * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
5537
+ * - Every bare perNode key is dropped from the pass-through (a stray bare
5538
+ * legacy key must never hydrate any node — no bare fallback).
5539
+ * - THIS node's effective value ({@link readNodeValue}) is then laid onto
5540
+ * each bare perNode key; when the node has no scoped key the bare key is
5541
+ * left ABSENT so the field's schema `default` wins.
5542
+ *
5543
+ * Returns a new object — the input store is not mutated.
5544
+ */
5545
+ function projectStore(store, perNodeKeys, nodeId) {
5546
+ const out = {};
5547
+ for (const [key, value] of Object.entries(store)) {
5548
+ if (key.includes("@")) continue;
5549
+ if (perNodeKeys.has(key)) continue;
5550
+ out[key] = value;
5551
+ }
5552
+ for (const base of perNodeKeys) {
5553
+ const value = readNodeValue(store, base, nodeId);
5554
+ if (value !== void 0) out[base] = value;
5555
+ }
5556
+ return out;
5557
+ }
5558
+ /**
5465
5559
  * Base class for CamStack addons. Eliminates settings boilerplate:
5466
5560
  *
5467
5561
  * - Typed `config` property with automatic resolution from store + defaults
@@ -5629,23 +5723,63 @@ var BaseAddon = class {
5629
5723
  deviceSettingsSchema() {
5630
5724
  return null;
5631
5725
  }
5632
- async getGlobalSettings(overlay, cap, _nodeId) {
5726
+ async getGlobalSettings(overlay, cap, nodeId) {
5633
5727
  const schema = this.globalSettingsSchema(cap);
5634
5728
  if (!schema) return { sections: [] };
5635
- const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5729
+ const projected = await this.resolveGlobalStore(nodeId, cap);
5636
5730
  return hydrateSchema(schema, overlay ? {
5637
- ...raw,
5731
+ ...projected,
5638
5732
  ...overlay
5639
- } : raw);
5733
+ } : projected);
5640
5734
  }
5641
- async updateGlobalSettings(patch, _nodeId) {
5642
- await this._ctx?.settings?.writeAddonStore(patch);
5735
+ /**
5736
+ * The raw addon store PROJECTED onto the target node's bare per-node keys:
5737
+ * every `perNode: true` field carries THAT node's scoped value on its bare
5738
+ * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
5739
+ * bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
5740
+ * A no-op passthrough when the schema declares no `perNode` field.
5741
+ *
5742
+ * This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
5743
+ * the store for custom option logic (option narrowing, value snapping) to
5744
+ * read it per-node — never `ctx.settings.readAddonStore()` directly.
5745
+ * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
5746
+ */
5747
+ async resolveGlobalStore(nodeId, cap) {
5748
+ const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5749
+ const keys = this.perNodeKeys(cap);
5750
+ const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5751
+ return keys.size > 0 ? projectStore(raw, keys, node) : raw;
5752
+ }
5753
+ async updateGlobalSettings(patch, nodeId) {
5754
+ const keys = this.perNodeKeys();
5755
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5756
+ const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5757
+ const barePatch = patch;
5758
+ const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
5759
+ await this._ctx?.settings?.writeAddonStore(scoped);
5760
+ if (target !== localNode) return;
5643
5761
  await this.resolveConfig();
5644
5762
  await this.onConfigChanged();
5645
5763
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
5646
5764
  this.maybeAutoRestart(patch, this.globalSettingsSchema());
5647
5765
  }
5648
5766
  /**
5767
+ * The set of field keys the global settings schema declares `perNode: true`
5768
+ * — derived once per `cap` argument and memoized (schemas are static
5769
+ * declarations). Empty set ⇒ every per-node code path is bypassed and the
5770
+ * settings API behaves exactly like the legacy node-agnostic one.
5771
+ */
5772
+ _perNodeKeysCache = /* @__PURE__ */ new Map();
5773
+ perNodeKeys(cap) {
5774
+ const cacheKey = cap ?? "";
5775
+ const cached = this._perNodeKeysCache.get(cacheKey);
5776
+ if (cached) return cached;
5777
+ const schema = this.globalSettingsSchema(cap);
5778
+ const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
5779
+ this._perNodeKeysCache.set(cacheKey, keys);
5780
+ return keys;
5781
+ }
5782
+ /**
5649
5783
  * If any field in `patch` is marked `requiresRestart` in `schema`,
5650
5784
  * schedule an addon restart for the next tick. Deferred via
5651
5785
  * `setImmediate` so the tRPC mutation that triggered the write has
@@ -5798,12 +5932,19 @@ var BaseAddon = class {
5798
5932
  * The merge is shallow: each key in `defaults` is checked against the store.
5799
5933
  * Only keys present in defaults are read — the store can contain extra keys
5800
5934
  * (e.g. from older versions) without polluting the typed config.
5935
+ *
5936
+ * Keys the global settings schema declares `perNode: true` resolve from
5937
+ * THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
5938
+ * from the bare key — so a per-node field resolves to this node's own
5939
+ * selection at boot (absent scoped key ⇒ the constructor default wins).
5801
5940
  */
5802
5941
  async resolveConfig() {
5803
5942
  const stored = await this.readAddonStoreWithRetry();
5943
+ const perNode = this.perNodeKeys();
5944
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5804
5945
  const resolved = { ...this.defaults };
5805
5946
  for (const key of Object.keys(this.defaults)) {
5806
- const storedValue = stored[key];
5947
+ const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
5807
5948
  if (storedValue !== void 0 && storedValue !== null) {
5808
5949
  const defaultType = typeof this.defaults[key];
5809
5950
  if (typeof storedValue === defaultType) resolved[key] = storedValue;
@@ -5887,6 +6028,27 @@ var BaseAddon = class {
5887
6028
  }
5888
6029
  };
5889
6030
  /**
6031
+ * Collect the keys of every field marked `perNode: true`, recursing into
6032
+ * layout containers (`group` fields and `sub-tabs` tabs) the same way
6033
+ * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6034
+ * don't declare `perNode` and are excluded by the `in` narrowing.
6035
+ */
6036
+ function collectPerNodeFieldKeys(fields) {
6037
+ const collected = [];
6038
+ for (const field of fields) {
6039
+ if (field.type === "group") {
6040
+ collected.push(...collectPerNodeFieldKeys(field.fields));
6041
+ continue;
6042
+ }
6043
+ if (field.type === "sub-tabs") {
6044
+ for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
6045
+ continue;
6046
+ }
6047
+ if ("perNode" in field && field.perNode === true) collected.push(field.key);
6048
+ }
6049
+ return collected;
6050
+ }
6051
+ /**
5890
6052
  * Normalize an `ICamstackAddon.initialize()` return value into the
5891
6053
  * `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
5892
6054
  * envelopes pass through; void stays void.
@@ -6299,6 +6461,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
6299
6461
  /** Single still-image entity (HA `image.*`). Read-only display of an
6300
6462
  * `entity_picture` signed URL the browser loads directly. `image` cap. */
6301
6463
  DeviceType["Image"] = "image";
6464
+ /** Smart pet feeder — cloud-connected food dispenser with a bowl food
6465
+ * level, battery, desiccant life, feeding state and manual-feed /
6466
+ * call-pet / maintenance actions. Installed with the `pet-feeder` cap;
6467
+ * dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
6468
+ * native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
6469
+ * integrations sharing the same food/desiccant/hopper surface. */
6470
+ DeviceType["PetFeeder"] = "pet-feeder";
6302
6471
  return DeviceType;
6303
6472
  }({});
6304
6473
  var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
@@ -7495,6 +7664,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
7495
7664
  for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7496
7665
  for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7497
7666
  /**
7667
+ * Error types for the safe expression engine. Two distinct classes so callers
7668
+ * can tell a compile-time (grammar) failure from a runtime (evaluation)
7669
+ * failure — both are non-fatal to the host: read paths degrade to "skip link".
7670
+ */
7671
+ /** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
7672
+ * the failure is anchored to a character (author-facing inline feedback). */
7673
+ var ExpressionParseError = class extends Error {
7674
+ position;
7675
+ constructor(message, position) {
7676
+ super(message);
7677
+ this.name = "ExpressionParseError";
7678
+ this.position = position;
7679
+ }
7680
+ };
7681
+ /** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
7682
+ * result, unknown builtin, step-budget exceeded). */
7683
+ var ExpressionEvalError = class extends Error {
7684
+ constructor(message) {
7685
+ super(message);
7686
+ this.name = "ExpressionEvalError";
7687
+ }
7688
+ };
7689
+ /**
7690
+ * Resource-bound constants for the safe expression engine.
7691
+ *
7692
+ * Every bound is defense-in-depth: the grammar is non-Turing-complete (no
7693
+ * loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
7694
+ * O(nodeCount) by construction. These caps merely put a hard ceiling on the
7695
+ * work a single author-supplied expression can request, so a hostile or
7696
+ * accidental pathological string can never spend unbounded CPU/memory.
7697
+ */
7698
+ /** Max source length (chars) — checked BEFORE tokenizing so a huge string is
7699
+ * rejected without allocation. */
7700
+ var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
7701
+ /** A legal binding / identifier name. */
7702
+ var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
7703
+ /** Binding names an author may NOT use: `now` is auto-injected; the literal
7704
+ * keywords lex as values, not identifiers, so binding to them is meaningless. */
7705
+ var RESERVED_BINDING_NAMES = new Set([
7706
+ "now",
7707
+ "true",
7708
+ "false",
7709
+ "null"
7710
+ ]);
7711
+ /**
7712
+ * Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
7713
+ * zero-dependency. The grammar is deliberately boring: decimal numbers,
7714
+ * single/double-quoted strings with a tiny escape set, identifiers, the three
7715
+ * value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
7716
+ * outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
7717
+ * is a parse error with a source position, so member access / assignment /
7718
+ * template literals are lexically impossible.
7719
+ */
7720
+ var KEYWORDS = new Set([
7721
+ "true",
7722
+ "false",
7723
+ "null"
7724
+ ]);
7725
+ function isDigit(ch) {
7726
+ return ch >= "0" && ch <= "9";
7727
+ }
7728
+ function isIdentStart(ch) {
7729
+ return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
7730
+ }
7731
+ function isIdentPart(ch) {
7732
+ return isIdentStart(ch) || isDigit(ch);
7733
+ }
7734
+ function isWhitespace(ch) {
7735
+ return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
7736
+ }
7737
+ /** Tokenize `source` into a flat token list ending with a single `eof` token.
7738
+ * Throws `ExpressionParseError` on any illegal character or unterminated
7739
+ * string. */
7740
+ function tokenize(source) {
7741
+ if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
7742
+ const tokens = [];
7743
+ let i = 0;
7744
+ const n = source.length;
7745
+ while (i < n) {
7746
+ const ch = source[i];
7747
+ if (isWhitespace(ch)) {
7748
+ i += 1;
7749
+ continue;
7750
+ }
7751
+ if (isDigit(ch)) {
7752
+ const start = i;
7753
+ while (i < n && isDigit(source[i])) i += 1;
7754
+ if (i < n && source[i] === ".") {
7755
+ if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
7756
+ i += 1;
7757
+ while (i < n && isDigit(source[i])) i += 1;
7758
+ }
7759
+ const text = source.slice(start, i);
7760
+ const value = Number(text);
7761
+ if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
7762
+ tokens.push({
7763
+ type: "number",
7764
+ value,
7765
+ pos: start
7766
+ });
7767
+ continue;
7768
+ }
7769
+ if (ch === "'" || ch === "\"") {
7770
+ const quote = ch;
7771
+ const start = i;
7772
+ i += 1;
7773
+ let out = "";
7774
+ let closed = false;
7775
+ while (i < n) {
7776
+ const c = source[i];
7777
+ if (c === "\\") {
7778
+ const next = i + 1 < n ? source[i + 1] : "";
7779
+ if (next === "\\" || next === "'" || next === "\"") {
7780
+ out += next;
7781
+ i += 2;
7782
+ continue;
7783
+ }
7784
+ throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
7785
+ }
7786
+ if (c === quote) {
7787
+ closed = true;
7788
+ i += 1;
7789
+ break;
7790
+ }
7791
+ out += c;
7792
+ i += 1;
7793
+ }
7794
+ if (!closed) throw new ExpressionParseError("unterminated string literal", start);
7795
+ tokens.push({
7796
+ type: "string",
7797
+ value: out,
7798
+ pos: start
7799
+ });
7800
+ continue;
7801
+ }
7802
+ if (isIdentStart(ch)) {
7803
+ const start = i;
7804
+ while (i < n && isIdentPart(source[i])) i += 1;
7805
+ const text = source.slice(start, i);
7806
+ if (KEYWORDS.has(text)) tokens.push({
7807
+ type: "keyword",
7808
+ keyword: keywordOf(text),
7809
+ pos: start
7810
+ });
7811
+ else tokens.push({
7812
+ type: "identifier",
7813
+ name: text,
7814
+ pos: start
7815
+ });
7816
+ continue;
7817
+ }
7818
+ const two = i + 1 < n ? source.slice(i, i + 2) : "";
7819
+ if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
7820
+ tokens.push({
7821
+ type: "punct",
7822
+ punct: two,
7823
+ pos: i
7824
+ });
7825
+ i += 2;
7826
+ continue;
7827
+ }
7828
+ if (isSinglePunct(ch)) {
7829
+ tokens.push({
7830
+ type: "punct",
7831
+ punct: ch,
7832
+ pos: i
7833
+ });
7834
+ i += 1;
7835
+ continue;
7836
+ }
7837
+ throw new ExpressionParseError(`unexpected character '${ch}'`, i);
7838
+ }
7839
+ tokens.push({
7840
+ type: "eof",
7841
+ pos: n
7842
+ });
7843
+ return tokens;
7844
+ }
7845
+ function keywordOf(text) {
7846
+ if (text === "true") return "true";
7847
+ if (text === "false") return "false";
7848
+ return "null";
7849
+ }
7850
+ function isSinglePunct(ch) {
7851
+ return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
7852
+ }
7853
+ /**
7854
+ * Frozen, null-prototype builtin function table for the expression engine
7855
+ * (spec §4 rule 4). The table is the SOLE surface of callable functions: the
7856
+ * parser rejects any callee not in it, and the evaluator gates each call on an
7857
+ * own-property check against it.
7858
+ *
7859
+ * Because the object has a NULL prototype AND is `Object.freeze`d:
7860
+ * - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
7861
+ * - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
7862
+ * (there is no `Object.prototype` in the chain), so those names are not
7863
+ * callable — they are simply "unknown function" at parse time.
7864
+ *
7865
+ * Every numeric argument is validated as a finite number and every numeric
7866
+ * RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
7867
+ * (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
7868
+ * closed rather than emitting a garbage value.
7869
+ */
7870
+ function asFiniteNumber(value, name, index) {
7871
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
7872
+ return value;
7873
+ }
7874
+ function asString$1(value, name, index) {
7875
+ if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
7876
+ return value;
7877
+ }
7878
+ function finiteResult(value, name) {
7879
+ if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
7880
+ return value;
7881
+ }
7882
+ function allFiniteNumbers(args, name) {
7883
+ return args.map((a, idx) => asFiniteNumber(a, name, idx));
7884
+ }
7885
+ var INF = Number.POSITIVE_INFINITY;
7886
+ var table = {
7887
+ min: {
7888
+ minArgs: 1,
7889
+ maxArgs: INF,
7890
+ apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
7891
+ },
7892
+ max: {
7893
+ minArgs: 1,
7894
+ maxArgs: INF,
7895
+ apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
7896
+ },
7897
+ abs: {
7898
+ minArgs: 1,
7899
+ maxArgs: 1,
7900
+ apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
7901
+ },
7902
+ floor: {
7903
+ minArgs: 1,
7904
+ maxArgs: 1,
7905
+ apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
7906
+ },
7907
+ ceil: {
7908
+ minArgs: 1,
7909
+ maxArgs: 1,
7910
+ apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
7911
+ },
7912
+ sqrt: {
7913
+ minArgs: 1,
7914
+ maxArgs: 1,
7915
+ apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
7916
+ },
7917
+ round: {
7918
+ minArgs: 1,
7919
+ maxArgs: 2,
7920
+ apply: (args) => {
7921
+ const x = asFiniteNumber(args[0], "round", 0);
7922
+ const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
7923
+ if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
7924
+ const factor = 10 ** digits;
7925
+ return finiteResult(Math.round(x * factor) / factor, "round");
7926
+ }
7927
+ },
7928
+ pow: {
7929
+ minArgs: 2,
7930
+ maxArgs: 2,
7931
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
7932
+ },
7933
+ clamp: {
7934
+ minArgs: 3,
7935
+ maxArgs: 3,
7936
+ apply: (args) => {
7937
+ const x = asFiniteNumber(args[0], "clamp", 0);
7938
+ const lo = asFiniteNumber(args[1], "clamp", 1);
7939
+ const hi = asFiniteNumber(args[2], "clamp", 2);
7940
+ if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
7941
+ return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
7942
+ }
7943
+ },
7944
+ avg: {
7945
+ minArgs: 1,
7946
+ maxArgs: INF,
7947
+ apply: (args) => {
7948
+ const nums = allFiniteNumbers(args, "avg");
7949
+ return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
7950
+ }
7951
+ },
7952
+ sum: {
7953
+ minArgs: 1,
7954
+ maxArgs: INF,
7955
+ apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
7956
+ },
7957
+ coalesce: {
7958
+ minArgs: 1,
7959
+ maxArgs: INF,
7960
+ apply: (args) => {
7961
+ for (const a of args) if (a !== null) return a;
7962
+ return null;
7963
+ }
7964
+ },
7965
+ age: {
7966
+ minArgs: 2,
7967
+ maxArgs: 2,
7968
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
7969
+ },
7970
+ convert: {
7971
+ minArgs: 3,
7972
+ maxArgs: 3,
7973
+ apply: (args, hooks) => {
7974
+ const x = asFiniteNumber(args[0], "convert", 0);
7975
+ const from = asString$1(args[1], "convert", 1).trim();
7976
+ const to = asString$1(args[2], "convert", 2).trim();
7977
+ if (hooks.convert) {
7978
+ const out = hooks.convert(x, from, to);
7979
+ if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
7980
+ return finiteResult(out, "convert");
7981
+ }
7982
+ if (from === to) return x;
7983
+ throw new ExpressionEvalError("convert: unit conversion table not installed");
7984
+ }
7985
+ }
7986
+ };
7987
+ Object.freeze(Object.assign(Object.create(null), table));
7988
+ /** The set of valid builtin names — used by the parser to reject unknown
7989
+ * callees at parse time (immediate author feedback). */
7990
+ var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
7991
+ /**
7992
+ * Pratt (precedence-climbing) parser for the safe expression mini-language.
7993
+ *
7994
+ * Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
7995
+ * → relational → additive → multiplicative → unary `! -` → call / primary.
7996
+ * Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
7997
+ * string validated against the builtin table at parse time, so an unknown
7998
+ * function is rejected immediately (author feedback) and a persisted expression
7999
+ * that references a since-removed builtin degrades at read.
8000
+ *
8001
+ * A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
8002
+ * arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
8003
+ */
8004
+ /** Binary/logical operator precedence (higher binds tighter). */
8005
+ var BINARY_PRECEDENCE = {
8006
+ "||": 1,
8007
+ "&&": 2,
8008
+ "==": 3,
8009
+ "!=": 3,
8010
+ "<": 4,
8011
+ "<=": 4,
8012
+ ">": 4,
8013
+ ">=": 4,
8014
+ "+": 5,
8015
+ "-": 5,
8016
+ "*": 6,
8017
+ "/": 6,
8018
+ "%": 6
8019
+ };
8020
+ function isLogicalOp(op) {
8021
+ return op === "&&" || op === "||";
8022
+ }
8023
+ function isBinaryOp(op) {
8024
+ return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
8025
+ }
8026
+ var Parser = class {
8027
+ tokens;
8028
+ pos = 0;
8029
+ nodeCount = 0;
8030
+ identifiers = /* @__PURE__ */ new Set();
8031
+ callees = /* @__PURE__ */ new Set();
8032
+ constructor(tokens) {
8033
+ this.tokens = tokens;
8034
+ }
8035
+ parse() {
8036
+ const ast = this.parseTernary();
8037
+ const tok = this.peek();
8038
+ if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
8039
+ return {
8040
+ ast,
8041
+ identifiers: this.identifiers,
8042
+ callees: this.callees,
8043
+ nodeCount: this.nodeCount
8044
+ };
8045
+ }
8046
+ peek() {
8047
+ return this.tokens[this.pos];
8048
+ }
8049
+ next() {
8050
+ return this.tokens[this.pos++];
8051
+ }
8052
+ /** Consume a punctuator token, erroring if the next token isn't it. */
8053
+ expectPunct(punct) {
8054
+ const tok = this.peek();
8055
+ if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
8056
+ this.pos += 1;
8057
+ }
8058
+ matchPunct(punct) {
8059
+ const tok = this.peek();
8060
+ if (tok.type === "punct" && tok.punct === punct) {
8061
+ this.pos += 1;
8062
+ return true;
8063
+ }
8064
+ return false;
8065
+ }
8066
+ countNode() {
8067
+ this.nodeCount += 1;
8068
+ if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
8069
+ }
8070
+ parseTernary() {
8071
+ const test = this.parseBinary(1);
8072
+ if (this.matchPunct("?")) {
8073
+ const consequent = this.parseTernary();
8074
+ this.expectPunct(":");
8075
+ const alternate = this.parseTernary();
8076
+ this.countNode();
8077
+ return {
8078
+ kind: "conditional",
8079
+ test,
8080
+ consequent,
8081
+ alternate
8082
+ };
8083
+ }
8084
+ return test;
8085
+ }
8086
+ parseBinary(minPrec) {
8087
+ let left = this.parseUnary();
8088
+ for (;;) {
8089
+ const tok = this.peek();
8090
+ if (tok.type !== "punct") break;
8091
+ const prec = BINARY_PRECEDENCE[tok.punct];
8092
+ if (prec === void 0 || prec < minPrec) break;
8093
+ const op = tok.punct;
8094
+ this.pos += 1;
8095
+ const right = this.parseBinary(prec + 1);
8096
+ this.countNode();
8097
+ if (isLogicalOp(op)) left = {
8098
+ kind: "logical",
8099
+ op,
8100
+ left,
8101
+ right
8102
+ };
8103
+ else if (isBinaryOp(op)) left = {
8104
+ kind: "binary",
8105
+ op,
8106
+ left,
8107
+ right
8108
+ };
8109
+ else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
8110
+ }
8111
+ return left;
8112
+ }
8113
+ parseUnary() {
8114
+ const tok = this.peek();
8115
+ if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
8116
+ const op = tok.punct;
8117
+ this.pos += 1;
8118
+ const operand = this.parseUnary();
8119
+ this.countNode();
8120
+ return {
8121
+ kind: "unary",
8122
+ op,
8123
+ operand
8124
+ };
8125
+ }
8126
+ return this.parsePrimary();
8127
+ }
8128
+ parsePrimary() {
8129
+ const tok = this.next();
8130
+ switch (tok.type) {
8131
+ case "number":
8132
+ this.countNode();
8133
+ return {
8134
+ kind: "literal",
8135
+ value: tok.value
8136
+ };
8137
+ case "string":
8138
+ this.countNode();
8139
+ return {
8140
+ kind: "literal",
8141
+ value: tok.value
8142
+ };
8143
+ case "keyword":
8144
+ this.countNode();
8145
+ return {
8146
+ kind: "literal",
8147
+ value: tok.keyword === "null" ? null : tok.keyword === "true"
8148
+ };
8149
+ case "identifier": {
8150
+ const nextTok = this.peek();
8151
+ if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
8152
+ this.identifiers.add(tok.name);
8153
+ this.countNode();
8154
+ return {
8155
+ kind: "identifier",
8156
+ name: tok.name
8157
+ };
8158
+ }
8159
+ case "punct":
8160
+ if (tok.punct === "(") {
8161
+ const inner = this.parseTernary();
8162
+ this.expectPunct(")");
8163
+ return inner;
8164
+ }
8165
+ throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
8166
+ case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
8167
+ }
8168
+ }
8169
+ parseCall(callee, pos) {
8170
+ if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
8171
+ this.expectPunct("(");
8172
+ const args = [];
8173
+ if (!this.matchPunct(")")) for (;;) {
8174
+ args.push(this.parseTernary());
8175
+ if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
8176
+ if (this.matchPunct(",")) continue;
8177
+ this.expectPunct(")");
8178
+ break;
8179
+ }
8180
+ this.callees.add(callee);
8181
+ this.countNode();
8182
+ return {
8183
+ kind: "call",
8184
+ callee,
8185
+ args
8186
+ };
8187
+ }
8188
+ };
8189
+ /** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
8190
+ * `ExpressionParseError` on any lexical or grammatical failure. */
8191
+ function parseExpression(source) {
8192
+ return new Parser(tokenize(source)).parse();
8193
+ }
8194
+ Object.freeze({});
8195
+ /**
8196
+ * LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
8197
+ * by expr"). The cache stores BOTH successes and failures (negative caching),
8198
+ * so a corrupt persisted string costs exactly one tokenize+parse total — not
8199
+ * one per read on a hot resolve path.
8200
+ *
8201
+ * The cache is a module-level singleton: entries are pure, content-addressed
8202
+ * ASTs keyed by the raw source string, so sharing one instance across all
8203
+ * callers is safe and maximises hit rate.
8204
+ */
8205
+ var cache = /* @__PURE__ */ new Map();
8206
+ function getCached(source) {
8207
+ const hit = cache.get(source);
8208
+ if (hit !== void 0) {
8209
+ cache.delete(source);
8210
+ cache.set(source, hit);
8211
+ return hit;
8212
+ }
8213
+ let result;
8214
+ try {
8215
+ result = {
8216
+ ok: true,
8217
+ parsed: parseExpression(source)
8218
+ };
8219
+ } catch (err) {
8220
+ result = {
8221
+ ok: false,
8222
+ error: err instanceof ExpressionParseError ? err.message : String(err)
8223
+ };
8224
+ }
8225
+ cache.set(source, result);
8226
+ if (cache.size > 256) {
8227
+ const oldest = cache.keys().next().value;
8228
+ if (oldest !== void 0) cache.delete(oldest);
8229
+ }
8230
+ return result;
8231
+ }
8232
+ /** Compile `source`, returning a discriminated result instead of throwing.
8233
+ * Used by read paths that must degrade rather than raise. LRU/negative-cached. */
8234
+ function compileExpressionSafe(source) {
8235
+ return getCached(source);
8236
+ }
8237
+ /**
8238
+ * Author-time validation. Returns `null` when the source is valid, else a
8239
+ * human-readable error message. Checks: the expression compiles; binding count
8240
+ * is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
8241
+ * is not reserved (`now`/keywords) and does not shadow a builtin; and every
8242
+ * FREE identifier of the AST is covered by a binding or the injected `now`.
8243
+ */
8244
+ function validateExpressionSource(src) {
8245
+ const names = Object.keys(src.bindings);
8246
+ if (names.length > 32) return `too many bindings (${names.length} > 32)`;
8247
+ for (const name of names) {
8248
+ if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
8249
+ if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
8250
+ if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
8251
+ }
8252
+ const compiled = compileExpressionSafe(src.expr);
8253
+ if (!compiled.ok) return compiled.error;
8254
+ const bound = new Set(names);
8255
+ for (const id of compiled.parsed.identifiers) {
8256
+ if (id === "now") continue;
8257
+ if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
8258
+ }
8259
+ return null;
8260
+ }
8261
+ /**
7498
8262
  * Accessory device helpers — shared across drivers.
7499
8263
  *
7500
8264
  * Many vendor-specific drivers register accessory child devices on
@@ -9426,7 +10190,8 @@ var MotionAnalysisResultSchema = object({
9426
10190
  });
9427
10191
  method(object({
9428
10192
  deviceId: number(),
9429
- frame: FrameInputSchema
10193
+ frame: FrameInputSchema.optional(),
10194
+ frameHandle: FrameHandleSchema.optional()
9430
10195
  }), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
9431
10196
  deviceId: number(),
9432
10197
  detected: boolean(),
@@ -9673,6 +10438,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
9673
10438
  engine: PipelineEngineChoiceSchema.optional(),
9674
10439
  steps: array(PipelineStepInputSchema).min(1),
9675
10440
  frame: FrameInputSchema.optional(),
10441
+ /**
10442
+ * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
10443
+ * the decoded pixels live in. One more member of the one-of
10444
+ * frame/frameHandle/image/imageBase64/referenceImage group.
10445
+ */
10446
+ frameHandle: FrameHandleSchema.optional(),
9676
10447
  imageBase64: string().optional(),
9677
10448
  /**
9678
10449
  * Binary JPEG bytes — preferred over `imageBase64` on internal
@@ -10377,6 +11148,113 @@ object({
10377
11148
  lastFetchedAt: number()
10378
11149
  });
10379
11150
  DeviceType.Sensor;
11151
+ /**
11152
+ * Feeder connectivity / power status — mirrors the HA petkit device-status
11153
+ * enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
11154
+ * `on_batteries` (running on battery backup). `null` until first reported.
11155
+ */
11156
+ var PetFeederDeviceStatusSchema = _enum([
11157
+ "normal",
11158
+ "offline",
11159
+ "on_batteries"
11160
+ ]);
11161
+ var gramsPortion = number().int().min(4).max(200);
11162
+ object({
11163
+ /** Food currently in the bowl (grams). Null when the device has not
11164
+ * reported a reading yet. On dual-hopper models this is the combined
11165
+ * bowl reading; per-hopper levels live in `food1`/`food2`. */
11166
+ foodLevel: number().nullable(),
11167
+ /** Hopper-1 food level (grams) on dual-hopper feeders; null on
11168
+ * single-hopper models. */
11169
+ food1: number().nullable(),
11170
+ /** Hopper-2 food level (grams) on dual-hopper feeders; null on
11171
+ * single-hopper models. */
11172
+ food2: number().nullable(),
11173
+ /** Derived low-food flag — mirrors the HA `food_level` binary_sensor
11174
+ * (`device_class: problem`, on = low). True when the bowl is empty /
11175
+ * below the feeder's low threshold. */
11176
+ lowFood: boolean(),
11177
+ /** Battery charge 0..100 (%). Null on mains-powered models or when the
11178
+ * device has no battery reading. */
11179
+ batteryPower: number().min(0).max(100).nullable(),
11180
+ /** Days of desiccant life remaining. Null when the model has no
11181
+ * desiccant sensor. */
11182
+ desiccantLeftDays: number().nullable(),
11183
+ /** True while a feed is in progress. */
11184
+ feeding: boolean(),
11185
+ /** Decoded connectivity / power status (HA petkit device-status enum).
11186
+ * Null until the device has reported a status. */
11187
+ status: PetFeederDeviceStatusSchema.nullable(),
11188
+ /** Decoded human-readable fault message. Null (or the device's `no_error`
11189
+ * sentinel) means healthy; a non-null string is an active fault. Pairs
11190
+ * with `errorCode` for consumers that want the raw integer. */
11191
+ error: string().nullable(),
11192
+ /** Raw device error code (0 / null = no error). */
11193
+ errorCode: number().nullable(),
11194
+ /** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
11195
+ isDualHopper: boolean(),
11196
+ /** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
11197
+ childLock: boolean(),
11198
+ /** Front indicator-light setting. */
11199
+ indicatorLight: boolean(),
11200
+ /** Play a chime when dispensing. */
11201
+ feedSound: boolean(),
11202
+ /** Speaker / prompt volume level (device-scaled integer). */
11203
+ volume: number(),
11204
+ /** Ms epoch when the slice was last refreshed from the cloud. */
11205
+ lastFetchedAt: number()
11206
+ });
11207
+ DeviceType.PetFeeder, method(object({
11208
+ deviceId: number().int().nonnegative(),
11209
+ grams: gramsPortion.optional(),
11210
+ hopper1: gramsPortion.optional(),
11211
+ hopper2: gramsPortion.optional()
11212
+ }), _void(), {
11213
+ kind: "mutation",
11214
+ auth: "admin"
11215
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11216
+ kind: "mutation",
11217
+ auth: "admin"
11218
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11219
+ kind: "mutation",
11220
+ auth: "admin"
11221
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11222
+ kind: "mutation",
11223
+ auth: "admin"
11224
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11225
+ kind: "mutation",
11226
+ auth: "admin"
11227
+ }), method(object({
11228
+ deviceId: number().int().nonnegative(),
11229
+ soundId: number().int().nonnegative()
11230
+ }), _void(), {
11231
+ kind: "mutation",
11232
+ auth: "admin"
11233
+ }), method(object({
11234
+ deviceId: number().int().nonnegative(),
11235
+ on: boolean()
11236
+ }), _void(), {
11237
+ kind: "mutation",
11238
+ auth: "admin"
11239
+ }), method(object({
11240
+ deviceId: number().int().nonnegative(),
11241
+ on: boolean()
11242
+ }), _void(), {
11243
+ kind: "mutation",
11244
+ auth: "admin"
11245
+ }), method(object({
11246
+ deviceId: number().int().nonnegative(),
11247
+ on: boolean()
11248
+ }), _void(), {
11249
+ kind: "mutation",
11250
+ auth: "admin"
11251
+ }), method(object({
11252
+ deviceId: number().int().nonnegative(),
11253
+ level: number().int().nonnegative()
11254
+ }), _void(), {
11255
+ kind: "mutation",
11256
+ auth: "admin"
11257
+ });
10380
11258
  object({
10381
11259
  /** Instantaneous power draw in watts. */
10382
11260
  watts: number().optional(),
@@ -12259,10 +13137,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
12259
13137
  url: string()
12260
13138
  }), _void()), method(object({
12261
13139
  sessionId: string(),
12262
- maxCount: number().default(1)
13140
+ maxCount: number().default(1),
13141
+ waitMs: number().optional()
12263
13142
  }), array(DecodedFrameSchema)), method(object({
12264
13143
  sessionId: string(),
12265
- maxCount: number().default(1)
13144
+ maxCount: number().default(1),
13145
+ waitMs: number().optional()
12266
13146
  }), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
12267
13147
  sessionId: string(),
12268
13148
  config: DecoderSessionConfigSchema.partial()
@@ -12549,14 +13429,63 @@ var ChildLayoutEntrySchema = object({
12549
13429
  collapsed: boolean().optional()
12550
13430
  });
12551
13431
  /** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
12552
- * `device-management.ts`. */
13432
+ * `device-management.ts`. Source is a union: a FIELD source copies a sibling
13433
+ * accessory's status field (`kind` optional/absent for wire compat); a
13434
+ * LITERAL source carries a per-device constant (no sibling is read); a
13435
+ * GLOBAL source (P2e) copies ANY device's status field, addressed by the
13436
+ * source device's full re-sync-stable `stableId`. */
13437
+ var DeviceLinkFieldSourceSchema = object({
13438
+ kind: literal("field").optional(),
13439
+ sourceKey: string(),
13440
+ cap: string(),
13441
+ fieldPath: string()
13442
+ });
13443
+ var DeviceLinkLiteralSourceSchema = object({
13444
+ kind: literal("literal"),
13445
+ value: union([
13446
+ string(),
13447
+ number(),
13448
+ boolean(),
13449
+ _null()
13450
+ ])
13451
+ });
13452
+ var DeviceLinkGlobalSourceSchema = object({
13453
+ kind: literal("global"),
13454
+ sourceStableId: string(),
13455
+ cap: string(),
13456
+ fieldPath: string()
13457
+ });
13458
+ /** Expression source (Stage X): compute the target field from N named bindings
13459
+ * via the safe expression engine. Bindings are field | literal | global — never
13460
+ * another expression (no nesting). The `superRefine` runs the SAME author-time
13461
+ * validation as `validateExpressionSource` (compiles the expr, checks binding
13462
+ * names + identifier coverage) so every wire boundary that parses a DeviceLink
13463
+ * (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
13464
+ * Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
13465
+ var DeviceLinkExpressionSourceSchema = object({
13466
+ kind: literal("expression"),
13467
+ expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
13468
+ bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
13469
+ DeviceLinkFieldSourceSchema,
13470
+ DeviceLinkLiteralSourceSchema,
13471
+ DeviceLinkGlobalSourceSchema
13472
+ ]))
13473
+ }).superRefine((src, ctx) => {
13474
+ const err = validateExpressionSource(src);
13475
+ if (err !== null) ctx.addIssue({
13476
+ code: "custom",
13477
+ message: err,
13478
+ path: ["expr"]
13479
+ });
13480
+ });
12553
13481
  var DeviceLinkSchema = object({
12554
13482
  id: string(),
12555
- source: object({
12556
- sourceKey: string(),
12557
- cap: string(),
12558
- fieldPath: string()
12559
- }),
13483
+ source: union([
13484
+ DeviceLinkFieldSourceSchema,
13485
+ DeviceLinkLiteralSourceSchema,
13486
+ DeviceLinkGlobalSourceSchema,
13487
+ DeviceLinkExpressionSourceSchema
13488
+ ]),
12560
13489
  target: object({
12561
13490
  cap: string(),
12562
13491
  fieldPath: string(),
@@ -12585,6 +13514,31 @@ var DeviceLinkSchema = object({
12585
13514
  })
12586
13515
  ]).optional()
12587
13516
  });
13517
+ /** Cap-wire shape of a per-cap display refinement — mirrors
13518
+ * `DeviceCapDisplayOverride` in `device-management.ts`. */
13519
+ var DeviceCapDisplayOverrideSchema = object({
13520
+ unit: string().min(1).optional(),
13521
+ precision: number().int().min(0).max(10).optional()
13522
+ });
13523
+ /** Cap-wire shape of an operator-authored per-device display override —
13524
+ * mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
13525
+ * bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
13526
+ var DeviceDisplayOverrideSchema = object({
13527
+ icon: string().min(1).optional(),
13528
+ label: string().min(1).optional(),
13529
+ unit: string().min(1).optional(),
13530
+ precision: number().int().min(0).max(10).optional(),
13531
+ hidden: boolean().optional(),
13532
+ perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
13533
+ });
13534
+ /** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
13535
+ * in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
13536
+ * the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
13537
+ var RoleDisplayDefaultSchema = object({
13538
+ unit: string().min(1).optional(),
13539
+ precision: number().int().min(0).max(10).optional(),
13540
+ icon: string().min(1).optional()
13541
+ });
12588
13542
  /**
12589
13543
  * Serializable projection of a live IDevice.
12590
13544
  * Returned by listAll, getDevice, getChildren.
@@ -12640,7 +13594,9 @@ var DeviceInfoSchema = object({
12640
13594
  * `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
12641
13595
  childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
12642
13596
  /** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
12643
- deviceLinks: array(DeviceLinkSchema).readonly().optional()
13597
+ deviceLinks: array(DeviceLinkSchema).readonly().optional(),
13598
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13599
+ display: DeviceDisplayOverrideSchema.optional()
12644
13600
  });
12645
13601
  var ConfigEntrySchema = object({
12646
13602
  key: string(),
@@ -12705,7 +13661,9 @@ var DeviceMetaSchema = object({
12705
13661
  deviceLinks: array(DeviceLinkSchema).readonly().optional(),
12706
13662
  /** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
12707
13663
  * Optional: only present for accessory children that carry a known role. */
12708
- role: string().nullable().optional()
13664
+ role: string().nullable().optional(),
13665
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13666
+ display: DeviceDisplayOverrideSchema.optional()
12709
13667
  });
12710
13668
  /** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
12711
13669
  var ConfigUISchemaOutput = unknown().nullable();
@@ -12799,7 +13757,19 @@ method(object({
12799
13757
  }), _void(), {
12800
13758
  kind: "mutation",
12801
13759
  auth: "admin"
12802
- }), method(object({ deviceId: number() }), object({ caps: array(object({
13760
+ }), method(object({
13761
+ deviceId: number(),
13762
+ display: DeviceDisplayOverrideSchema.nullable()
13763
+ }), _void(), {
13764
+ kind: "mutation",
13765
+ auth: "admin"
13766
+ }), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
13767
+ kind: "mutation",
13768
+ auth: "admin"
13769
+ }), method(object({
13770
+ deviceId: number(),
13771
+ includeSynthesizable: boolean().optional()
13772
+ }), object({ caps: array(object({
12803
13773
  cap: string(),
12804
13774
  fields: array(object({
12805
13775
  path: string(),
@@ -12809,8 +13779,13 @@ method(object({
12809
13779
  "boolean",
12810
13780
  "enum"
12811
13781
  ]),
12812
- enumValues: array(string()).optional()
12813
- })).readonly()
13782
+ enumValues: array(string()).optional(),
13783
+ item: boolean().optional()
13784
+ })).readonly(),
13785
+ itemArray: object({
13786
+ path: string(),
13787
+ keyField: string()
13788
+ }).optional()
12814
13789
  })).readonly() }), { kind: "query" }), method(object({
12815
13790
  deviceId: number(),
12816
13791
  role: string().nullable()
@@ -12880,7 +13855,11 @@ method(object({
12880
13855
  deviceId: number(),
12881
13856
  entries: array(object({
12882
13857
  capName: string(),
12883
- kind: _enum(["native", "wrapped"]),
13858
+ kind: _enum([
13859
+ "native",
13860
+ "wrapped",
13861
+ "linked"
13862
+ ]),
12884
13863
  providerAddonId: string(),
12885
13864
  providerNodeId: string(),
12886
13865
  nativeAddonId: string()
@@ -12889,7 +13868,11 @@ method(object({
12889
13868
  deviceId: number(),
12890
13869
  entries: array(object({
12891
13870
  capName: string(),
12892
- kind: _enum(["native", "wrapped"]),
13871
+ kind: _enum([
13872
+ "native",
13873
+ "wrapped",
13874
+ "linked"
13875
+ ]),
12893
13876
  providerAddonId: string(),
12894
13877
  providerNodeId: string(),
12895
13878
  nativeAddonId: string()
@@ -14199,7 +15182,10 @@ var AgentLoadSummarySchema = object({
14199
15182
  online: boolean(),
14200
15183
  load: RunnerLocalLoadSchema,
14201
15184
  /** Computed score used by the L2 capacity balancer (lower = less loaded). */
14202
- score: number()
15185
+ score: number(),
15186
+ /** This node's decode hwaccel backend (per-node `probedBestHwaccel`), or null
15187
+ * when not yet probed — for the cluster Pipeline table UI (P0.2). */
15188
+ decodeHwaccel: string().nullable()
14203
15189
  });
14204
15190
  /**
14205
15191
  * Aggregate metrics across the whole detection cluster. Replaces the legacy
@@ -16777,7 +17763,10 @@ var HwAccelBackendInputSchema = _enum([
16777
17763
  "webgpu",
16778
17764
  "none"
16779
17765
  ]).nullable().optional();
16780
- var HwAccelResolutionSchema = object({ preferred: array(string()).readonly() });
17766
+ var HwAccelResolutionSchema = object({
17767
+ preferred: array(string()).readonly(),
17768
+ rationale: string()
17769
+ });
16781
17770
  var HardwareEncoderIdSchema = _enum([
16782
17771
  "h264_videotoolbox",
16783
17772
  "hevc_videotoolbox",
@@ -16792,7 +17781,7 @@ var HardwareEncoderIdSchema = _enum([
16792
17781
  "libx264",
16793
17782
  "libx265"
16794
17783
  ]);
16795
- var HardwareEncodersSchema = object({
17784
+ object({
16796
17785
  encoders: array(object({
16797
17786
  encoder: HardwareEncoderIdSchema,
16798
17787
  codec: _enum(["H264", "H265"]),
@@ -16811,15 +17800,7 @@ var HardwareEncodersSchema = object({
16811
17800
  defaultH265: HardwareEncoderIdSchema,
16812
17801
  probedAt: number()
16813
17802
  });
16814
- /**
16815
- * Decode-side companion to {@link HardwareEncodersSchema}: the `-hwaccel`
16816
- * methods the configured ffmpeg binary actually supports (parsed from
16817
- * `ffmpeg -hwaccels`). Used to gate decode-hwaccel attempts so the transcode
16818
- * egress never spends a spawn on a backend this build cannot offer. Per-stream
16819
- * decode fragility (e.g. VideoToolbox HEVC) is still handled by the egress's
16820
- * software fallback — this only filters out wholly-unsupported backends.
16821
- */
16822
- var HardwareDecodeAccelsSchema = object({
17803
+ object({
16823
17804
  methods: array(string()).readonly(),
16824
17805
  probedAt: number()
16825
17806
  });
@@ -16882,16 +17863,7 @@ var ResolvedInferenceConfigSchema = object({
16882
17863
  format: ModelFormatSchema,
16883
17864
  reason: string()
16884
17865
  });
16885
- method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
16886
- prefer: HwAccelBackendInputSchema,
16887
- nodeId: string().optional()
16888
- }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
16889
- kind: "mutation",
16890
- auth: "admin"
16891
- }), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
16892
- kind: "mutation",
16893
- auth: "admin"
16894
- });
17866
+ method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema);
16895
17867
  var PtzPresetSchema = object({
16896
17868
  id: string(),
16897
17869
  name: string()
@@ -18590,6 +19562,12 @@ Object.freeze({
18590
19562
  addonId: null,
18591
19563
  access: "view"
18592
19564
  },
19565
+ "deviceManager.getRoleDisplayDefaults": {
19566
+ capName: "device-manager",
19567
+ capScope: "system",
19568
+ addonId: null,
19569
+ access: "view"
19570
+ },
18593
19571
  "deviceManager.getSettingsSchema": {
18594
19572
  capName: "device-manager",
18595
19573
  capScope: "system",
@@ -18740,6 +19718,12 @@ Object.freeze({
18740
19718
  addonId: null,
18741
19719
  access: "create"
18742
19720
  },
19721
+ "deviceManager.setDisplay": {
19722
+ capName: "device-manager",
19723
+ capScope: "system",
19724
+ addonId: null,
19725
+ access: "create"
19726
+ },
18743
19727
  "deviceManager.setIntegrationId": {
18744
19728
  capName: "device-manager",
18745
19729
  capScope: "system",
@@ -18782,6 +19766,12 @@ Object.freeze({
18782
19766
  addonId: null,
18783
19767
  access: "create"
18784
19768
  },
19769
+ "deviceManager.setRoleDisplayDefaults": {
19770
+ capName: "device-manager",
19771
+ capScope: "system",
19772
+ addonId: null,
19773
+ access: "create"
19774
+ },
18785
19775
  "deviceManager.setStreamProfileMap": {
18786
19776
  capName: "device-manager",
18787
19777
  capScope: "system",
@@ -19832,6 +20822,66 @@ Object.freeze({
19832
20822
  addonId: null,
19833
20823
  access: "create"
19834
20824
  },
20825
+ "petFeeder.callPet": {
20826
+ capName: "pet-feeder",
20827
+ capScope: "device",
20828
+ addonId: null,
20829
+ access: "create"
20830
+ },
20831
+ "petFeeder.cancelFeed": {
20832
+ capName: "pet-feeder",
20833
+ capScope: "device",
20834
+ addonId: null,
20835
+ access: "create"
20836
+ },
20837
+ "petFeeder.feed": {
20838
+ capName: "pet-feeder",
20839
+ capScope: "device",
20840
+ addonId: null,
20841
+ access: "create"
20842
+ },
20843
+ "petFeeder.markFoodReplenished": {
20844
+ capName: "pet-feeder",
20845
+ capScope: "device",
20846
+ addonId: null,
20847
+ access: "create"
20848
+ },
20849
+ "petFeeder.playSound": {
20850
+ capName: "pet-feeder",
20851
+ capScope: "device",
20852
+ addonId: null,
20853
+ access: "create"
20854
+ },
20855
+ "petFeeder.resetDesiccant": {
20856
+ capName: "pet-feeder",
20857
+ capScope: "device",
20858
+ addonId: null,
20859
+ access: "delete"
20860
+ },
20861
+ "petFeeder.setChildLock": {
20862
+ capName: "pet-feeder",
20863
+ capScope: "device",
20864
+ addonId: null,
20865
+ access: "create"
20866
+ },
20867
+ "petFeeder.setFeedSound": {
20868
+ capName: "pet-feeder",
20869
+ capScope: "device",
20870
+ addonId: null,
20871
+ access: "create"
20872
+ },
20873
+ "petFeeder.setIndicatorLight": {
20874
+ capName: "pet-feeder",
20875
+ capScope: "device",
20876
+ addonId: null,
20877
+ access: "create"
20878
+ },
20879
+ "petFeeder.setVolume": {
20880
+ capName: "pet-feeder",
20881
+ capScope: "device",
20882
+ addonId: null,
20883
+ access: "create"
20884
+ },
19835
20885
  "pipelineAnalytics.clearTracks": {
19836
20886
  capName: "pipeline-analytics",
19837
20887
  capScope: "device",
@@ -20438,30 +21488,6 @@ Object.freeze({
20438
21488
  addonId: null,
20439
21489
  access: "view"
20440
21490
  },
20441
- "platformProbe.getHardwareDecodeAccels": {
20442
- capName: "platform-probe",
20443
- capScope: "system",
20444
- addonId: null,
20445
- access: "view"
20446
- },
20447
- "platformProbe.getHardwareEncoders": {
20448
- capName: "platform-probe",
20449
- capScope: "system",
20450
- addonId: null,
20451
- access: "view"
20452
- },
20453
- "platformProbe.refreshHardwareDecodeAccels": {
20454
- capName: "platform-probe",
20455
- capScope: "system",
20456
- addonId: null,
20457
- access: "create"
20458
- },
20459
- "platformProbe.refreshHardwareEncoders": {
20460
- capName: "platform-probe",
20461
- capScope: "system",
20462
- addonId: null,
20463
- access: "create"
20464
- },
20465
21491
  "platformProbe.resolveHwAccel": {
20466
21492
  capName: "platform-probe",
20467
21493
  capScope: "system",