@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.
@@ -4627,7 +4627,7 @@ function _instanceof(cls, params = {}) {
4627
4627
  return inst;
4628
4628
  }
4629
4629
  //#endregion
4630
- //#region ../types/dist/sleep-MHm--th-.mjs
4630
+ //#region ../types/dist/sleep-BiDFW0E7.mjs
4631
4631
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
4632
4632
  EventCategory["SystemBoot"] = "system.boot";
4633
4633
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -5440,6 +5440,100 @@ function createDurableState(deps) {
5440
5440
  };
5441
5441
  }
5442
5442
  /**
5443
+ * Per-node scoping for the shared addon-settings blob.
5444
+ *
5445
+ * An addon's settings store is hub-central (the `addon-settings` cap is
5446
+ * hub-routed — the hub instance answers for every node), so fields whose
5447
+ * value is a NODE fact (decoder backend, engine pick, probed hardware
5448
+ * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
5449
+ * the single shared blob. The SCHEMA field key stays bare: the write path
5450
+ * ({@link scopePatch}) maps the bare field onto the target node's scoped
5451
+ * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
5452
+ * back, so UI forms and `resolveConfig` only ever see the bare key.
5453
+ *
5454
+ * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
5455
+ * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
5456
+ * schema and routes reads/writes through these helpers.
5457
+ *
5458
+ * ## No bare-key fallback — deliberate
5459
+ *
5460
+ * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
5461
+ * scoped key resolves to `undefined` so the field's schema `default` wins —
5462
+ * NEVER `store[base]` and never another node's value. A bare legacy key in
5463
+ * the store is invisible to every node, hub included, so one node's
5464
+ * selection can never leak onto another. (This generalizes the
5465
+ * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
5466
+ * arbitrary set of per-node field keys.)
5467
+ *
5468
+ * Pure functions only — no I/O, no imports beyond the language. This is a
5469
+ * LEAF module: import it via its deep path, never from the root barrel.
5470
+ */
5471
+ /**
5472
+ * Normalize a raw kernel node id to the bare node id used for scoping.
5473
+ * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
5474
+ * processes; per-node settings are per-NODE, so strip the addon segment.
5475
+ * `undefined` / `null` / empty falls back to `'hub'`.
5476
+ */
5477
+ function normalizeNodeId(raw) {
5478
+ if (raw === void 0 || raw === null || raw === "") return "hub";
5479
+ const slashIdx = raw.indexOf("/");
5480
+ if (slashIdx < 0) return raw;
5481
+ const bare = raw.slice(0, slashIdx);
5482
+ return bare === "" ? "hub" : bare;
5483
+ }
5484
+ /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
5485
+ function nodeScopedKey(base, nodeId) {
5486
+ return `${base}@${normalizeNodeId(nodeId)}`;
5487
+ }
5488
+ /**
5489
+ * Read a node's value for a per-node field from the raw shared store:
5490
+ * the node-scoped key when present, otherwise `undefined`.
5491
+ * Deliberately NO bare-key fallback (see module doc) — the caller lets the
5492
+ * schema `default` win on `undefined`.
5493
+ */
5494
+ function readNodeValue(store, base, nodeId) {
5495
+ return store[nodeScopedKey(base, nodeId)];
5496
+ }
5497
+ /**
5498
+ * Re-map a UI/settings patch so every bare perNode field persists under the
5499
+ * TARGET node's scoped key; all other keys pass through unchanged. Used on
5500
+ * the write path so a save for one node never clobbers another node's value
5501
+ * (and the bare key is never written). Returns a new object — the input
5502
+ * patch is not mutated.
5503
+ */
5504
+ function scopePatch(patch, perNodeKeys, nodeId) {
5505
+ const out = {};
5506
+ for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
5507
+ return out;
5508
+ }
5509
+ /**
5510
+ * Project the raw shared store onto the bare schema keys for ONE node so a
5511
+ * UI schema (whose field keys are bare) hydrates from that node's own
5512
+ * values:
5513
+ *
5514
+ * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
5515
+ * - Every bare perNode key is dropped from the pass-through (a stray bare
5516
+ * legacy key must never hydrate any node — no bare fallback).
5517
+ * - THIS node's effective value ({@link readNodeValue}) is then laid onto
5518
+ * each bare perNode key; when the node has no scoped key the bare key is
5519
+ * left ABSENT so the field's schema `default` wins.
5520
+ *
5521
+ * Returns a new object — the input store is not mutated.
5522
+ */
5523
+ function projectStore(store, perNodeKeys, nodeId) {
5524
+ const out = {};
5525
+ for (const [key, value] of Object.entries(store)) {
5526
+ if (key.includes("@")) continue;
5527
+ if (perNodeKeys.has(key)) continue;
5528
+ out[key] = value;
5529
+ }
5530
+ for (const base of perNodeKeys) {
5531
+ const value = readNodeValue(store, base, nodeId);
5532
+ if (value !== void 0) out[base] = value;
5533
+ }
5534
+ return out;
5535
+ }
5536
+ /**
5443
5537
  * Base class for CamStack addons. Eliminates settings boilerplate:
5444
5538
  *
5445
5539
  * - Typed `config` property with automatic resolution from store + defaults
@@ -5607,23 +5701,63 @@ var BaseAddon = class {
5607
5701
  deviceSettingsSchema() {
5608
5702
  return null;
5609
5703
  }
5610
- async getGlobalSettings(overlay, cap, _nodeId) {
5704
+ async getGlobalSettings(overlay, cap, nodeId) {
5611
5705
  const schema = this.globalSettingsSchema(cap);
5612
5706
  if (!schema) return { sections: [] };
5613
- const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5707
+ const projected = await this.resolveGlobalStore(nodeId, cap);
5614
5708
  return hydrateSchema(schema, overlay ? {
5615
- ...raw,
5709
+ ...projected,
5616
5710
  ...overlay
5617
- } : raw);
5711
+ } : projected);
5618
5712
  }
5619
- async updateGlobalSettings(patch, _nodeId) {
5620
- await this._ctx?.settings?.writeAddonStore(patch);
5713
+ /**
5714
+ * The raw addon store PROJECTED onto the target node's bare per-node keys:
5715
+ * every `perNode: true` field carries THAT node's scoped value on its bare
5716
+ * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
5717
+ * bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
5718
+ * A no-op passthrough when the schema declares no `perNode` field.
5719
+ *
5720
+ * This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
5721
+ * the store for custom option logic (option narrowing, value snapping) to
5722
+ * read it per-node — never `ctx.settings.readAddonStore()` directly.
5723
+ * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
5724
+ */
5725
+ async resolveGlobalStore(nodeId, cap) {
5726
+ const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5727
+ const keys = this.perNodeKeys(cap);
5728
+ const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5729
+ return keys.size > 0 ? projectStore(raw, keys, node) : raw;
5730
+ }
5731
+ async updateGlobalSettings(patch, nodeId) {
5732
+ const keys = this.perNodeKeys();
5733
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5734
+ const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5735
+ const barePatch = patch;
5736
+ const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
5737
+ await this._ctx?.settings?.writeAddonStore(scoped);
5738
+ if (target !== localNode) return;
5621
5739
  await this.resolveConfig();
5622
5740
  await this.onConfigChanged();
5623
5741
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
5624
5742
  this.maybeAutoRestart(patch, this.globalSettingsSchema());
5625
5743
  }
5626
5744
  /**
5745
+ * The set of field keys the global settings schema declares `perNode: true`
5746
+ * — derived once per `cap` argument and memoized (schemas are static
5747
+ * declarations). Empty set ⇒ every per-node code path is bypassed and the
5748
+ * settings API behaves exactly like the legacy node-agnostic one.
5749
+ */
5750
+ _perNodeKeysCache = /* @__PURE__ */ new Map();
5751
+ perNodeKeys(cap) {
5752
+ const cacheKey = cap ?? "";
5753
+ const cached = this._perNodeKeysCache.get(cacheKey);
5754
+ if (cached) return cached;
5755
+ const schema = this.globalSettingsSchema(cap);
5756
+ const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
5757
+ this._perNodeKeysCache.set(cacheKey, keys);
5758
+ return keys;
5759
+ }
5760
+ /**
5627
5761
  * If any field in `patch` is marked `requiresRestart` in `schema`,
5628
5762
  * schedule an addon restart for the next tick. Deferred via
5629
5763
  * `setImmediate` so the tRPC mutation that triggered the write has
@@ -5776,12 +5910,19 @@ var BaseAddon = class {
5776
5910
  * The merge is shallow: each key in `defaults` is checked against the store.
5777
5911
  * Only keys present in defaults are read — the store can contain extra keys
5778
5912
  * (e.g. from older versions) without polluting the typed config.
5913
+ *
5914
+ * Keys the global settings schema declares `perNode: true` resolve from
5915
+ * THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
5916
+ * from the bare key — so a per-node field resolves to this node's own
5917
+ * selection at boot (absent scoped key ⇒ the constructor default wins).
5779
5918
  */
5780
5919
  async resolveConfig() {
5781
5920
  const stored = await this.readAddonStoreWithRetry();
5921
+ const perNode = this.perNodeKeys();
5922
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5782
5923
  const resolved = { ...this.defaults };
5783
5924
  for (const key of Object.keys(this.defaults)) {
5784
- const storedValue = stored[key];
5925
+ const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
5785
5926
  if (storedValue !== void 0 && storedValue !== null) {
5786
5927
  const defaultType = typeof this.defaults[key];
5787
5928
  if (typeof storedValue === defaultType) resolved[key] = storedValue;
@@ -5865,6 +6006,27 @@ var BaseAddon = class {
5865
6006
  }
5866
6007
  };
5867
6008
  /**
6009
+ * Collect the keys of every field marked `perNode: true`, recursing into
6010
+ * layout containers (`group` fields and `sub-tabs` tabs) the same way
6011
+ * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6012
+ * don't declare `perNode` and are excluded by the `in` narrowing.
6013
+ */
6014
+ function collectPerNodeFieldKeys(fields) {
6015
+ const collected = [];
6016
+ for (const field of fields) {
6017
+ if (field.type === "group") {
6018
+ collected.push(...collectPerNodeFieldKeys(field.fields));
6019
+ continue;
6020
+ }
6021
+ if (field.type === "sub-tabs") {
6022
+ for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
6023
+ continue;
6024
+ }
6025
+ if ("perNode" in field && field.perNode === true) collected.push(field.key);
6026
+ }
6027
+ return collected;
6028
+ }
6029
+ /**
5868
6030
  * Normalize an `ICamstackAddon.initialize()` return value into the
5869
6031
  * `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
5870
6032
  * envelopes pass through; void stays void.
@@ -6277,6 +6439,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
6277
6439
  /** Single still-image entity (HA `image.*`). Read-only display of an
6278
6440
  * `entity_picture` signed URL the browser loads directly. `image` cap. */
6279
6441
  DeviceType["Image"] = "image";
6442
+ /** Smart pet feeder — cloud-connected food dispenser with a bowl food
6443
+ * level, battery, desiccant life, feeding state and manual-feed /
6444
+ * call-pet / maintenance actions. Installed with the `pet-feeder` cap;
6445
+ * dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
6446
+ * native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
6447
+ * integrations sharing the same food/desiccant/hopper surface. */
6448
+ DeviceType["PetFeeder"] = "pet-feeder";
6280
6449
  return DeviceType;
6281
6450
  }({});
6282
6451
  var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
@@ -7473,6 +7642,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
7473
7642
  for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7474
7643
  for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7475
7644
  /**
7645
+ * Error types for the safe expression engine. Two distinct classes so callers
7646
+ * can tell a compile-time (grammar) failure from a runtime (evaluation)
7647
+ * failure — both are non-fatal to the host: read paths degrade to "skip link".
7648
+ */
7649
+ /** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
7650
+ * the failure is anchored to a character (author-facing inline feedback). */
7651
+ var ExpressionParseError = class extends Error {
7652
+ position;
7653
+ constructor(message, position) {
7654
+ super(message);
7655
+ this.name = "ExpressionParseError";
7656
+ this.position = position;
7657
+ }
7658
+ };
7659
+ /** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
7660
+ * result, unknown builtin, step-budget exceeded). */
7661
+ var ExpressionEvalError = class extends Error {
7662
+ constructor(message) {
7663
+ super(message);
7664
+ this.name = "ExpressionEvalError";
7665
+ }
7666
+ };
7667
+ /**
7668
+ * Resource-bound constants for the safe expression engine.
7669
+ *
7670
+ * Every bound is defense-in-depth: the grammar is non-Turing-complete (no
7671
+ * loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
7672
+ * O(nodeCount) by construction. These caps merely put a hard ceiling on the
7673
+ * work a single author-supplied expression can request, so a hostile or
7674
+ * accidental pathological string can never spend unbounded CPU/memory.
7675
+ */
7676
+ /** Max source length (chars) — checked BEFORE tokenizing so a huge string is
7677
+ * rejected without allocation. */
7678
+ var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
7679
+ /** A legal binding / identifier name. */
7680
+ var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
7681
+ /** Binding names an author may NOT use: `now` is auto-injected; the literal
7682
+ * keywords lex as values, not identifiers, so binding to them is meaningless. */
7683
+ var RESERVED_BINDING_NAMES = new Set([
7684
+ "now",
7685
+ "true",
7686
+ "false",
7687
+ "null"
7688
+ ]);
7689
+ /**
7690
+ * Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
7691
+ * zero-dependency. The grammar is deliberately boring: decimal numbers,
7692
+ * single/double-quoted strings with a tiny escape set, identifiers, the three
7693
+ * value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
7694
+ * outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
7695
+ * is a parse error with a source position, so member access / assignment /
7696
+ * template literals are lexically impossible.
7697
+ */
7698
+ var KEYWORDS = new Set([
7699
+ "true",
7700
+ "false",
7701
+ "null"
7702
+ ]);
7703
+ function isDigit(ch) {
7704
+ return ch >= "0" && ch <= "9";
7705
+ }
7706
+ function isIdentStart(ch) {
7707
+ return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
7708
+ }
7709
+ function isIdentPart(ch) {
7710
+ return isIdentStart(ch) || isDigit(ch);
7711
+ }
7712
+ function isWhitespace(ch) {
7713
+ return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
7714
+ }
7715
+ /** Tokenize `source` into a flat token list ending with a single `eof` token.
7716
+ * Throws `ExpressionParseError` on any illegal character or unterminated
7717
+ * string. */
7718
+ function tokenize(source) {
7719
+ if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
7720
+ const tokens = [];
7721
+ let i = 0;
7722
+ const n = source.length;
7723
+ while (i < n) {
7724
+ const ch = source[i];
7725
+ if (isWhitespace(ch)) {
7726
+ i += 1;
7727
+ continue;
7728
+ }
7729
+ if (isDigit(ch)) {
7730
+ const start = i;
7731
+ while (i < n && isDigit(source[i])) i += 1;
7732
+ if (i < n && source[i] === ".") {
7733
+ if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
7734
+ i += 1;
7735
+ while (i < n && isDigit(source[i])) i += 1;
7736
+ }
7737
+ const text = source.slice(start, i);
7738
+ const value = Number(text);
7739
+ if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
7740
+ tokens.push({
7741
+ type: "number",
7742
+ value,
7743
+ pos: start
7744
+ });
7745
+ continue;
7746
+ }
7747
+ if (ch === "'" || ch === "\"") {
7748
+ const quote = ch;
7749
+ const start = i;
7750
+ i += 1;
7751
+ let out = "";
7752
+ let closed = false;
7753
+ while (i < n) {
7754
+ const c = source[i];
7755
+ if (c === "\\") {
7756
+ const next = i + 1 < n ? source[i + 1] : "";
7757
+ if (next === "\\" || next === "'" || next === "\"") {
7758
+ out += next;
7759
+ i += 2;
7760
+ continue;
7761
+ }
7762
+ throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
7763
+ }
7764
+ if (c === quote) {
7765
+ closed = true;
7766
+ i += 1;
7767
+ break;
7768
+ }
7769
+ out += c;
7770
+ i += 1;
7771
+ }
7772
+ if (!closed) throw new ExpressionParseError("unterminated string literal", start);
7773
+ tokens.push({
7774
+ type: "string",
7775
+ value: out,
7776
+ pos: start
7777
+ });
7778
+ continue;
7779
+ }
7780
+ if (isIdentStart(ch)) {
7781
+ const start = i;
7782
+ while (i < n && isIdentPart(source[i])) i += 1;
7783
+ const text = source.slice(start, i);
7784
+ if (KEYWORDS.has(text)) tokens.push({
7785
+ type: "keyword",
7786
+ keyword: keywordOf(text),
7787
+ pos: start
7788
+ });
7789
+ else tokens.push({
7790
+ type: "identifier",
7791
+ name: text,
7792
+ pos: start
7793
+ });
7794
+ continue;
7795
+ }
7796
+ const two = i + 1 < n ? source.slice(i, i + 2) : "";
7797
+ if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
7798
+ tokens.push({
7799
+ type: "punct",
7800
+ punct: two,
7801
+ pos: i
7802
+ });
7803
+ i += 2;
7804
+ continue;
7805
+ }
7806
+ if (isSinglePunct(ch)) {
7807
+ tokens.push({
7808
+ type: "punct",
7809
+ punct: ch,
7810
+ pos: i
7811
+ });
7812
+ i += 1;
7813
+ continue;
7814
+ }
7815
+ throw new ExpressionParseError(`unexpected character '${ch}'`, i);
7816
+ }
7817
+ tokens.push({
7818
+ type: "eof",
7819
+ pos: n
7820
+ });
7821
+ return tokens;
7822
+ }
7823
+ function keywordOf(text) {
7824
+ if (text === "true") return "true";
7825
+ if (text === "false") return "false";
7826
+ return "null";
7827
+ }
7828
+ function isSinglePunct(ch) {
7829
+ return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
7830
+ }
7831
+ /**
7832
+ * Frozen, null-prototype builtin function table for the expression engine
7833
+ * (spec §4 rule 4). The table is the SOLE surface of callable functions: the
7834
+ * parser rejects any callee not in it, and the evaluator gates each call on an
7835
+ * own-property check against it.
7836
+ *
7837
+ * Because the object has a NULL prototype AND is `Object.freeze`d:
7838
+ * - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
7839
+ * - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
7840
+ * (there is no `Object.prototype` in the chain), so those names are not
7841
+ * callable — they are simply "unknown function" at parse time.
7842
+ *
7843
+ * Every numeric argument is validated as a finite number and every numeric
7844
+ * RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
7845
+ * (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
7846
+ * closed rather than emitting a garbage value.
7847
+ */
7848
+ function asFiniteNumber(value, name, index) {
7849
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
7850
+ return value;
7851
+ }
7852
+ function asString$1(value, name, index) {
7853
+ if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
7854
+ return value;
7855
+ }
7856
+ function finiteResult(value, name) {
7857
+ if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
7858
+ return value;
7859
+ }
7860
+ function allFiniteNumbers(args, name) {
7861
+ return args.map((a, idx) => asFiniteNumber(a, name, idx));
7862
+ }
7863
+ var INF = Number.POSITIVE_INFINITY;
7864
+ var table = {
7865
+ min: {
7866
+ minArgs: 1,
7867
+ maxArgs: INF,
7868
+ apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
7869
+ },
7870
+ max: {
7871
+ minArgs: 1,
7872
+ maxArgs: INF,
7873
+ apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
7874
+ },
7875
+ abs: {
7876
+ minArgs: 1,
7877
+ maxArgs: 1,
7878
+ apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
7879
+ },
7880
+ floor: {
7881
+ minArgs: 1,
7882
+ maxArgs: 1,
7883
+ apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
7884
+ },
7885
+ ceil: {
7886
+ minArgs: 1,
7887
+ maxArgs: 1,
7888
+ apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
7889
+ },
7890
+ sqrt: {
7891
+ minArgs: 1,
7892
+ maxArgs: 1,
7893
+ apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
7894
+ },
7895
+ round: {
7896
+ minArgs: 1,
7897
+ maxArgs: 2,
7898
+ apply: (args) => {
7899
+ const x = asFiniteNumber(args[0], "round", 0);
7900
+ const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
7901
+ if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
7902
+ const factor = 10 ** digits;
7903
+ return finiteResult(Math.round(x * factor) / factor, "round");
7904
+ }
7905
+ },
7906
+ pow: {
7907
+ minArgs: 2,
7908
+ maxArgs: 2,
7909
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
7910
+ },
7911
+ clamp: {
7912
+ minArgs: 3,
7913
+ maxArgs: 3,
7914
+ apply: (args) => {
7915
+ const x = asFiniteNumber(args[0], "clamp", 0);
7916
+ const lo = asFiniteNumber(args[1], "clamp", 1);
7917
+ const hi = asFiniteNumber(args[2], "clamp", 2);
7918
+ if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
7919
+ return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
7920
+ }
7921
+ },
7922
+ avg: {
7923
+ minArgs: 1,
7924
+ maxArgs: INF,
7925
+ apply: (args) => {
7926
+ const nums = allFiniteNumbers(args, "avg");
7927
+ return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
7928
+ }
7929
+ },
7930
+ sum: {
7931
+ minArgs: 1,
7932
+ maxArgs: INF,
7933
+ apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
7934
+ },
7935
+ coalesce: {
7936
+ minArgs: 1,
7937
+ maxArgs: INF,
7938
+ apply: (args) => {
7939
+ for (const a of args) if (a !== null) return a;
7940
+ return null;
7941
+ }
7942
+ },
7943
+ age: {
7944
+ minArgs: 2,
7945
+ maxArgs: 2,
7946
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
7947
+ },
7948
+ convert: {
7949
+ minArgs: 3,
7950
+ maxArgs: 3,
7951
+ apply: (args, hooks) => {
7952
+ const x = asFiniteNumber(args[0], "convert", 0);
7953
+ const from = asString$1(args[1], "convert", 1).trim();
7954
+ const to = asString$1(args[2], "convert", 2).trim();
7955
+ if (hooks.convert) {
7956
+ const out = hooks.convert(x, from, to);
7957
+ if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
7958
+ return finiteResult(out, "convert");
7959
+ }
7960
+ if (from === to) return x;
7961
+ throw new ExpressionEvalError("convert: unit conversion table not installed");
7962
+ }
7963
+ }
7964
+ };
7965
+ Object.freeze(Object.assign(Object.create(null), table));
7966
+ /** The set of valid builtin names — used by the parser to reject unknown
7967
+ * callees at parse time (immediate author feedback). */
7968
+ var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
7969
+ /**
7970
+ * Pratt (precedence-climbing) parser for the safe expression mini-language.
7971
+ *
7972
+ * Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
7973
+ * → relational → additive → multiplicative → unary `! -` → call / primary.
7974
+ * Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
7975
+ * string validated against the builtin table at parse time, so an unknown
7976
+ * function is rejected immediately (author feedback) and a persisted expression
7977
+ * that references a since-removed builtin degrades at read.
7978
+ *
7979
+ * A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
7980
+ * arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
7981
+ */
7982
+ /** Binary/logical operator precedence (higher binds tighter). */
7983
+ var BINARY_PRECEDENCE = {
7984
+ "||": 1,
7985
+ "&&": 2,
7986
+ "==": 3,
7987
+ "!=": 3,
7988
+ "<": 4,
7989
+ "<=": 4,
7990
+ ">": 4,
7991
+ ">=": 4,
7992
+ "+": 5,
7993
+ "-": 5,
7994
+ "*": 6,
7995
+ "/": 6,
7996
+ "%": 6
7997
+ };
7998
+ function isLogicalOp(op) {
7999
+ return op === "&&" || op === "||";
8000
+ }
8001
+ function isBinaryOp(op) {
8002
+ return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
8003
+ }
8004
+ var Parser = class {
8005
+ tokens;
8006
+ pos = 0;
8007
+ nodeCount = 0;
8008
+ identifiers = /* @__PURE__ */ new Set();
8009
+ callees = /* @__PURE__ */ new Set();
8010
+ constructor(tokens) {
8011
+ this.tokens = tokens;
8012
+ }
8013
+ parse() {
8014
+ const ast = this.parseTernary();
8015
+ const tok = this.peek();
8016
+ if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
8017
+ return {
8018
+ ast,
8019
+ identifiers: this.identifiers,
8020
+ callees: this.callees,
8021
+ nodeCount: this.nodeCount
8022
+ };
8023
+ }
8024
+ peek() {
8025
+ return this.tokens[this.pos];
8026
+ }
8027
+ next() {
8028
+ return this.tokens[this.pos++];
8029
+ }
8030
+ /** Consume a punctuator token, erroring if the next token isn't it. */
8031
+ expectPunct(punct) {
8032
+ const tok = this.peek();
8033
+ if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
8034
+ this.pos += 1;
8035
+ }
8036
+ matchPunct(punct) {
8037
+ const tok = this.peek();
8038
+ if (tok.type === "punct" && tok.punct === punct) {
8039
+ this.pos += 1;
8040
+ return true;
8041
+ }
8042
+ return false;
8043
+ }
8044
+ countNode() {
8045
+ this.nodeCount += 1;
8046
+ if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
8047
+ }
8048
+ parseTernary() {
8049
+ const test = this.parseBinary(1);
8050
+ if (this.matchPunct("?")) {
8051
+ const consequent = this.parseTernary();
8052
+ this.expectPunct(":");
8053
+ const alternate = this.parseTernary();
8054
+ this.countNode();
8055
+ return {
8056
+ kind: "conditional",
8057
+ test,
8058
+ consequent,
8059
+ alternate
8060
+ };
8061
+ }
8062
+ return test;
8063
+ }
8064
+ parseBinary(minPrec) {
8065
+ let left = this.parseUnary();
8066
+ for (;;) {
8067
+ const tok = this.peek();
8068
+ if (tok.type !== "punct") break;
8069
+ const prec = BINARY_PRECEDENCE[tok.punct];
8070
+ if (prec === void 0 || prec < minPrec) break;
8071
+ const op = tok.punct;
8072
+ this.pos += 1;
8073
+ const right = this.parseBinary(prec + 1);
8074
+ this.countNode();
8075
+ if (isLogicalOp(op)) left = {
8076
+ kind: "logical",
8077
+ op,
8078
+ left,
8079
+ right
8080
+ };
8081
+ else if (isBinaryOp(op)) left = {
8082
+ kind: "binary",
8083
+ op,
8084
+ left,
8085
+ right
8086
+ };
8087
+ else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
8088
+ }
8089
+ return left;
8090
+ }
8091
+ parseUnary() {
8092
+ const tok = this.peek();
8093
+ if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
8094
+ const op = tok.punct;
8095
+ this.pos += 1;
8096
+ const operand = this.parseUnary();
8097
+ this.countNode();
8098
+ return {
8099
+ kind: "unary",
8100
+ op,
8101
+ operand
8102
+ };
8103
+ }
8104
+ return this.parsePrimary();
8105
+ }
8106
+ parsePrimary() {
8107
+ const tok = this.next();
8108
+ switch (tok.type) {
8109
+ case "number":
8110
+ this.countNode();
8111
+ return {
8112
+ kind: "literal",
8113
+ value: tok.value
8114
+ };
8115
+ case "string":
8116
+ this.countNode();
8117
+ return {
8118
+ kind: "literal",
8119
+ value: tok.value
8120
+ };
8121
+ case "keyword":
8122
+ this.countNode();
8123
+ return {
8124
+ kind: "literal",
8125
+ value: tok.keyword === "null" ? null : tok.keyword === "true"
8126
+ };
8127
+ case "identifier": {
8128
+ const nextTok = this.peek();
8129
+ if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
8130
+ this.identifiers.add(tok.name);
8131
+ this.countNode();
8132
+ return {
8133
+ kind: "identifier",
8134
+ name: tok.name
8135
+ };
8136
+ }
8137
+ case "punct":
8138
+ if (tok.punct === "(") {
8139
+ const inner = this.parseTernary();
8140
+ this.expectPunct(")");
8141
+ return inner;
8142
+ }
8143
+ throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
8144
+ case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
8145
+ }
8146
+ }
8147
+ parseCall(callee, pos) {
8148
+ if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
8149
+ this.expectPunct("(");
8150
+ const args = [];
8151
+ if (!this.matchPunct(")")) for (;;) {
8152
+ args.push(this.parseTernary());
8153
+ if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
8154
+ if (this.matchPunct(",")) continue;
8155
+ this.expectPunct(")");
8156
+ break;
8157
+ }
8158
+ this.callees.add(callee);
8159
+ this.countNode();
8160
+ return {
8161
+ kind: "call",
8162
+ callee,
8163
+ args
8164
+ };
8165
+ }
8166
+ };
8167
+ /** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
8168
+ * `ExpressionParseError` on any lexical or grammatical failure. */
8169
+ function parseExpression(source) {
8170
+ return new Parser(tokenize(source)).parse();
8171
+ }
8172
+ Object.freeze({});
8173
+ /**
8174
+ * LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
8175
+ * by expr"). The cache stores BOTH successes and failures (negative caching),
8176
+ * so a corrupt persisted string costs exactly one tokenize+parse total — not
8177
+ * one per read on a hot resolve path.
8178
+ *
8179
+ * The cache is a module-level singleton: entries are pure, content-addressed
8180
+ * ASTs keyed by the raw source string, so sharing one instance across all
8181
+ * callers is safe and maximises hit rate.
8182
+ */
8183
+ var cache = /* @__PURE__ */ new Map();
8184
+ function getCached(source) {
8185
+ const hit = cache.get(source);
8186
+ if (hit !== void 0) {
8187
+ cache.delete(source);
8188
+ cache.set(source, hit);
8189
+ return hit;
8190
+ }
8191
+ let result;
8192
+ try {
8193
+ result = {
8194
+ ok: true,
8195
+ parsed: parseExpression(source)
8196
+ };
8197
+ } catch (err) {
8198
+ result = {
8199
+ ok: false,
8200
+ error: err instanceof ExpressionParseError ? err.message : String(err)
8201
+ };
8202
+ }
8203
+ cache.set(source, result);
8204
+ if (cache.size > 256) {
8205
+ const oldest = cache.keys().next().value;
8206
+ if (oldest !== void 0) cache.delete(oldest);
8207
+ }
8208
+ return result;
8209
+ }
8210
+ /** Compile `source`, returning a discriminated result instead of throwing.
8211
+ * Used by read paths that must degrade rather than raise. LRU/negative-cached. */
8212
+ function compileExpressionSafe(source) {
8213
+ return getCached(source);
8214
+ }
8215
+ /**
8216
+ * Author-time validation. Returns `null` when the source is valid, else a
8217
+ * human-readable error message. Checks: the expression compiles; binding count
8218
+ * is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
8219
+ * is not reserved (`now`/keywords) and does not shadow a builtin; and every
8220
+ * FREE identifier of the AST is covered by a binding or the injected `now`.
8221
+ */
8222
+ function validateExpressionSource(src) {
8223
+ const names = Object.keys(src.bindings);
8224
+ if (names.length > 32) return `too many bindings (${names.length} > 32)`;
8225
+ for (const name of names) {
8226
+ if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
8227
+ if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
8228
+ if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
8229
+ }
8230
+ const compiled = compileExpressionSafe(src.expr);
8231
+ if (!compiled.ok) return compiled.error;
8232
+ const bound = new Set(names);
8233
+ for (const id of compiled.parsed.identifiers) {
8234
+ if (id === "now") continue;
8235
+ if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
8236
+ }
8237
+ return null;
8238
+ }
8239
+ /**
7476
8240
  * Accessory device helpers — shared across drivers.
7477
8241
  *
7478
8242
  * Many vendor-specific drivers register accessory child devices on
@@ -9404,7 +10168,8 @@ var MotionAnalysisResultSchema = object({
9404
10168
  });
9405
10169
  method(object({
9406
10170
  deviceId: number(),
9407
- frame: FrameInputSchema
10171
+ frame: FrameInputSchema.optional(),
10172
+ frameHandle: FrameHandleSchema.optional()
9408
10173
  }), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
9409
10174
  deviceId: number(),
9410
10175
  detected: boolean(),
@@ -9651,6 +10416,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
9651
10416
  engine: PipelineEngineChoiceSchema.optional(),
9652
10417
  steps: array(PipelineStepInputSchema).min(1),
9653
10418
  frame: FrameInputSchema.optional(),
10419
+ /**
10420
+ * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
10421
+ * the decoded pixels live in. One more member of the one-of
10422
+ * frame/frameHandle/image/imageBase64/referenceImage group.
10423
+ */
10424
+ frameHandle: FrameHandleSchema.optional(),
9654
10425
  imageBase64: string().optional(),
9655
10426
  /**
9656
10427
  * Binary JPEG bytes — preferred over `imageBase64` on internal
@@ -10355,6 +11126,113 @@ object({
10355
11126
  lastFetchedAt: number()
10356
11127
  });
10357
11128
  DeviceType.Sensor;
11129
+ /**
11130
+ * Feeder connectivity / power status — mirrors the HA petkit device-status
11131
+ * enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
11132
+ * `on_batteries` (running on battery backup). `null` until first reported.
11133
+ */
11134
+ var PetFeederDeviceStatusSchema = _enum([
11135
+ "normal",
11136
+ "offline",
11137
+ "on_batteries"
11138
+ ]);
11139
+ var gramsPortion = number().int().min(4).max(200);
11140
+ object({
11141
+ /** Food currently in the bowl (grams). Null when the device has not
11142
+ * reported a reading yet. On dual-hopper models this is the combined
11143
+ * bowl reading; per-hopper levels live in `food1`/`food2`. */
11144
+ foodLevel: number().nullable(),
11145
+ /** Hopper-1 food level (grams) on dual-hopper feeders; null on
11146
+ * single-hopper models. */
11147
+ food1: number().nullable(),
11148
+ /** Hopper-2 food level (grams) on dual-hopper feeders; null on
11149
+ * single-hopper models. */
11150
+ food2: number().nullable(),
11151
+ /** Derived low-food flag — mirrors the HA `food_level` binary_sensor
11152
+ * (`device_class: problem`, on = low). True when the bowl is empty /
11153
+ * below the feeder's low threshold. */
11154
+ lowFood: boolean(),
11155
+ /** Battery charge 0..100 (%). Null on mains-powered models or when the
11156
+ * device has no battery reading. */
11157
+ batteryPower: number().min(0).max(100).nullable(),
11158
+ /** Days of desiccant life remaining. Null when the model has no
11159
+ * desiccant sensor. */
11160
+ desiccantLeftDays: number().nullable(),
11161
+ /** True while a feed is in progress. */
11162
+ feeding: boolean(),
11163
+ /** Decoded connectivity / power status (HA petkit device-status enum).
11164
+ * Null until the device has reported a status. */
11165
+ status: PetFeederDeviceStatusSchema.nullable(),
11166
+ /** Decoded human-readable fault message. Null (or the device's `no_error`
11167
+ * sentinel) means healthy; a non-null string is an active fault. Pairs
11168
+ * with `errorCode` for consumers that want the raw integer. */
11169
+ error: string().nullable(),
11170
+ /** Raw device error code (0 / null = no error). */
11171
+ errorCode: number().nullable(),
11172
+ /** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
11173
+ isDualHopper: boolean(),
11174
+ /** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
11175
+ childLock: boolean(),
11176
+ /** Front indicator-light setting. */
11177
+ indicatorLight: boolean(),
11178
+ /** Play a chime when dispensing. */
11179
+ feedSound: boolean(),
11180
+ /** Speaker / prompt volume level (device-scaled integer). */
11181
+ volume: number(),
11182
+ /** Ms epoch when the slice was last refreshed from the cloud. */
11183
+ lastFetchedAt: number()
11184
+ });
11185
+ DeviceType.PetFeeder, method(object({
11186
+ deviceId: number().int().nonnegative(),
11187
+ grams: gramsPortion.optional(),
11188
+ hopper1: gramsPortion.optional(),
11189
+ hopper2: gramsPortion.optional()
11190
+ }), _void(), {
11191
+ kind: "mutation",
11192
+ auth: "admin"
11193
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11194
+ kind: "mutation",
11195
+ auth: "admin"
11196
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11197
+ kind: "mutation",
11198
+ auth: "admin"
11199
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11200
+ kind: "mutation",
11201
+ auth: "admin"
11202
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11203
+ kind: "mutation",
11204
+ auth: "admin"
11205
+ }), method(object({
11206
+ deviceId: number().int().nonnegative(),
11207
+ soundId: number().int().nonnegative()
11208
+ }), _void(), {
11209
+ kind: "mutation",
11210
+ auth: "admin"
11211
+ }), method(object({
11212
+ deviceId: number().int().nonnegative(),
11213
+ on: boolean()
11214
+ }), _void(), {
11215
+ kind: "mutation",
11216
+ auth: "admin"
11217
+ }), method(object({
11218
+ deviceId: number().int().nonnegative(),
11219
+ on: boolean()
11220
+ }), _void(), {
11221
+ kind: "mutation",
11222
+ auth: "admin"
11223
+ }), method(object({
11224
+ deviceId: number().int().nonnegative(),
11225
+ on: boolean()
11226
+ }), _void(), {
11227
+ kind: "mutation",
11228
+ auth: "admin"
11229
+ }), method(object({
11230
+ deviceId: number().int().nonnegative(),
11231
+ level: number().int().nonnegative()
11232
+ }), _void(), {
11233
+ kind: "mutation",
11234
+ auth: "admin"
11235
+ });
10358
11236
  object({
10359
11237
  /** Instantaneous power draw in watts. */
10360
11238
  watts: number().optional(),
@@ -12237,10 +13115,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
12237
13115
  url: string()
12238
13116
  }), _void()), method(object({
12239
13117
  sessionId: string(),
12240
- maxCount: number().default(1)
13118
+ maxCount: number().default(1),
13119
+ waitMs: number().optional()
12241
13120
  }), array(DecodedFrameSchema)), method(object({
12242
13121
  sessionId: string(),
12243
- maxCount: number().default(1)
13122
+ maxCount: number().default(1),
13123
+ waitMs: number().optional()
12244
13124
  }), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
12245
13125
  sessionId: string(),
12246
13126
  config: DecoderSessionConfigSchema.partial()
@@ -12527,14 +13407,63 @@ var ChildLayoutEntrySchema = object({
12527
13407
  collapsed: boolean().optional()
12528
13408
  });
12529
13409
  /** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
12530
- * `device-management.ts`. */
13410
+ * `device-management.ts`. Source is a union: a FIELD source copies a sibling
13411
+ * accessory's status field (`kind` optional/absent for wire compat); a
13412
+ * LITERAL source carries a per-device constant (no sibling is read); a
13413
+ * GLOBAL source (P2e) copies ANY device's status field, addressed by the
13414
+ * source device's full re-sync-stable `stableId`. */
13415
+ var DeviceLinkFieldSourceSchema = object({
13416
+ kind: literal("field").optional(),
13417
+ sourceKey: string(),
13418
+ cap: string(),
13419
+ fieldPath: string()
13420
+ });
13421
+ var DeviceLinkLiteralSourceSchema = object({
13422
+ kind: literal("literal"),
13423
+ value: union([
13424
+ string(),
13425
+ number(),
13426
+ boolean(),
13427
+ _null()
13428
+ ])
13429
+ });
13430
+ var DeviceLinkGlobalSourceSchema = object({
13431
+ kind: literal("global"),
13432
+ sourceStableId: string(),
13433
+ cap: string(),
13434
+ fieldPath: string()
13435
+ });
13436
+ /** Expression source (Stage X): compute the target field from N named bindings
13437
+ * via the safe expression engine. Bindings are field | literal | global — never
13438
+ * another expression (no nesting). The `superRefine` runs the SAME author-time
13439
+ * validation as `validateExpressionSource` (compiles the expr, checks binding
13440
+ * names + identifier coverage) so every wire boundary that parses a DeviceLink
13441
+ * (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
13442
+ * Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
13443
+ var DeviceLinkExpressionSourceSchema = object({
13444
+ kind: literal("expression"),
13445
+ expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
13446
+ bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
13447
+ DeviceLinkFieldSourceSchema,
13448
+ DeviceLinkLiteralSourceSchema,
13449
+ DeviceLinkGlobalSourceSchema
13450
+ ]))
13451
+ }).superRefine((src, ctx) => {
13452
+ const err = validateExpressionSource(src);
13453
+ if (err !== null) ctx.addIssue({
13454
+ code: "custom",
13455
+ message: err,
13456
+ path: ["expr"]
13457
+ });
13458
+ });
12531
13459
  var DeviceLinkSchema = object({
12532
13460
  id: string(),
12533
- source: object({
12534
- sourceKey: string(),
12535
- cap: string(),
12536
- fieldPath: string()
12537
- }),
13461
+ source: union([
13462
+ DeviceLinkFieldSourceSchema,
13463
+ DeviceLinkLiteralSourceSchema,
13464
+ DeviceLinkGlobalSourceSchema,
13465
+ DeviceLinkExpressionSourceSchema
13466
+ ]),
12538
13467
  target: object({
12539
13468
  cap: string(),
12540
13469
  fieldPath: string(),
@@ -12563,6 +13492,31 @@ var DeviceLinkSchema = object({
12563
13492
  })
12564
13493
  ]).optional()
12565
13494
  });
13495
+ /** Cap-wire shape of a per-cap display refinement — mirrors
13496
+ * `DeviceCapDisplayOverride` in `device-management.ts`. */
13497
+ var DeviceCapDisplayOverrideSchema = object({
13498
+ unit: string().min(1).optional(),
13499
+ precision: number().int().min(0).max(10).optional()
13500
+ });
13501
+ /** Cap-wire shape of an operator-authored per-device display override —
13502
+ * mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
13503
+ * bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
13504
+ var DeviceDisplayOverrideSchema = object({
13505
+ icon: string().min(1).optional(),
13506
+ label: string().min(1).optional(),
13507
+ unit: string().min(1).optional(),
13508
+ precision: number().int().min(0).max(10).optional(),
13509
+ hidden: boolean().optional(),
13510
+ perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
13511
+ });
13512
+ /** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
13513
+ * in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
13514
+ * the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
13515
+ var RoleDisplayDefaultSchema = object({
13516
+ unit: string().min(1).optional(),
13517
+ precision: number().int().min(0).max(10).optional(),
13518
+ icon: string().min(1).optional()
13519
+ });
12566
13520
  /**
12567
13521
  * Serializable projection of a live IDevice.
12568
13522
  * Returned by listAll, getDevice, getChildren.
@@ -12618,7 +13572,9 @@ var DeviceInfoSchema = object({
12618
13572
  * `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
12619
13573
  childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
12620
13574
  /** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
12621
- deviceLinks: array(DeviceLinkSchema).readonly().optional()
13575
+ deviceLinks: array(DeviceLinkSchema).readonly().optional(),
13576
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13577
+ display: DeviceDisplayOverrideSchema.optional()
12622
13578
  });
12623
13579
  var ConfigEntrySchema = object({
12624
13580
  key: string(),
@@ -12683,7 +13639,9 @@ var DeviceMetaSchema = object({
12683
13639
  deviceLinks: array(DeviceLinkSchema).readonly().optional(),
12684
13640
  /** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
12685
13641
  * Optional: only present for accessory children that carry a known role. */
12686
- role: string().nullable().optional()
13642
+ role: string().nullable().optional(),
13643
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13644
+ display: DeviceDisplayOverrideSchema.optional()
12687
13645
  });
12688
13646
  /** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
12689
13647
  var ConfigUISchemaOutput = unknown().nullable();
@@ -12777,7 +13735,19 @@ method(object({
12777
13735
  }), _void(), {
12778
13736
  kind: "mutation",
12779
13737
  auth: "admin"
12780
- }), method(object({ deviceId: number() }), object({ caps: array(object({
13738
+ }), method(object({
13739
+ deviceId: number(),
13740
+ display: DeviceDisplayOverrideSchema.nullable()
13741
+ }), _void(), {
13742
+ kind: "mutation",
13743
+ auth: "admin"
13744
+ }), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
13745
+ kind: "mutation",
13746
+ auth: "admin"
13747
+ }), method(object({
13748
+ deviceId: number(),
13749
+ includeSynthesizable: boolean().optional()
13750
+ }), object({ caps: array(object({
12781
13751
  cap: string(),
12782
13752
  fields: array(object({
12783
13753
  path: string(),
@@ -12787,8 +13757,13 @@ method(object({
12787
13757
  "boolean",
12788
13758
  "enum"
12789
13759
  ]),
12790
- enumValues: array(string()).optional()
12791
- })).readonly()
13760
+ enumValues: array(string()).optional(),
13761
+ item: boolean().optional()
13762
+ })).readonly(),
13763
+ itemArray: object({
13764
+ path: string(),
13765
+ keyField: string()
13766
+ }).optional()
12792
13767
  })).readonly() }), { kind: "query" }), method(object({
12793
13768
  deviceId: number(),
12794
13769
  role: string().nullable()
@@ -12858,7 +13833,11 @@ method(object({
12858
13833
  deviceId: number(),
12859
13834
  entries: array(object({
12860
13835
  capName: string(),
12861
- kind: _enum(["native", "wrapped"]),
13836
+ kind: _enum([
13837
+ "native",
13838
+ "wrapped",
13839
+ "linked"
13840
+ ]),
12862
13841
  providerAddonId: string(),
12863
13842
  providerNodeId: string(),
12864
13843
  nativeAddonId: string()
@@ -12867,7 +13846,11 @@ method(object({
12867
13846
  deviceId: number(),
12868
13847
  entries: array(object({
12869
13848
  capName: string(),
12870
- kind: _enum(["native", "wrapped"]),
13849
+ kind: _enum([
13850
+ "native",
13851
+ "wrapped",
13852
+ "linked"
13853
+ ]),
12871
13854
  providerAddonId: string(),
12872
13855
  providerNodeId: string(),
12873
13856
  nativeAddonId: string()
@@ -14177,7 +15160,10 @@ var AgentLoadSummarySchema = object({
14177
15160
  online: boolean(),
14178
15161
  load: RunnerLocalLoadSchema,
14179
15162
  /** Computed score used by the L2 capacity balancer (lower = less loaded). */
14180
- score: number()
15163
+ score: number(),
15164
+ /** This node's decode hwaccel backend (per-node `probedBestHwaccel`), or null
15165
+ * when not yet probed — for the cluster Pipeline table UI (P0.2). */
15166
+ decodeHwaccel: string().nullable()
14181
15167
  });
14182
15168
  /**
14183
15169
  * Aggregate metrics across the whole detection cluster. Replaces the legacy
@@ -16755,7 +17741,10 @@ var HwAccelBackendInputSchema = _enum([
16755
17741
  "webgpu",
16756
17742
  "none"
16757
17743
  ]).nullable().optional();
16758
- var HwAccelResolutionSchema = object({ preferred: array(string()).readonly() });
17744
+ var HwAccelResolutionSchema = object({
17745
+ preferred: array(string()).readonly(),
17746
+ rationale: string()
17747
+ });
16759
17748
  var HardwareEncoderIdSchema = _enum([
16760
17749
  "h264_videotoolbox",
16761
17750
  "hevc_videotoolbox",
@@ -16770,7 +17759,7 @@ var HardwareEncoderIdSchema = _enum([
16770
17759
  "libx264",
16771
17760
  "libx265"
16772
17761
  ]);
16773
- var HardwareEncodersSchema = object({
17762
+ object({
16774
17763
  encoders: array(object({
16775
17764
  encoder: HardwareEncoderIdSchema,
16776
17765
  codec: _enum(["H264", "H265"]),
@@ -16789,15 +17778,7 @@ var HardwareEncodersSchema = object({
16789
17778
  defaultH265: HardwareEncoderIdSchema,
16790
17779
  probedAt: number()
16791
17780
  });
16792
- /**
16793
- * Decode-side companion to {@link HardwareEncodersSchema}: the `-hwaccel`
16794
- * methods the configured ffmpeg binary actually supports (parsed from
16795
- * `ffmpeg -hwaccels`). Used to gate decode-hwaccel attempts so the transcode
16796
- * egress never spends a spawn on a backend this build cannot offer. Per-stream
16797
- * decode fragility (e.g. VideoToolbox HEVC) is still handled by the egress's
16798
- * software fallback — this only filters out wholly-unsupported backends.
16799
- */
16800
- var HardwareDecodeAccelsSchema = object({
17781
+ object({
16801
17782
  methods: array(string()).readonly(),
16802
17783
  probedAt: number()
16803
17784
  });
@@ -16860,16 +17841,7 @@ var ResolvedInferenceConfigSchema = object({
16860
17841
  format: ModelFormatSchema,
16861
17842
  reason: string()
16862
17843
  });
16863
- method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
16864
- prefer: HwAccelBackendInputSchema,
16865
- nodeId: string().optional()
16866
- }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
16867
- kind: "mutation",
16868
- auth: "admin"
16869
- }), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
16870
- kind: "mutation",
16871
- auth: "admin"
16872
- });
17844
+ method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema);
16873
17845
  var PtzPresetSchema = object({
16874
17846
  id: string(),
16875
17847
  name: string()
@@ -18568,6 +19540,12 @@ Object.freeze({
18568
19540
  addonId: null,
18569
19541
  access: "view"
18570
19542
  },
19543
+ "deviceManager.getRoleDisplayDefaults": {
19544
+ capName: "device-manager",
19545
+ capScope: "system",
19546
+ addonId: null,
19547
+ access: "view"
19548
+ },
18571
19549
  "deviceManager.getSettingsSchema": {
18572
19550
  capName: "device-manager",
18573
19551
  capScope: "system",
@@ -18718,6 +19696,12 @@ Object.freeze({
18718
19696
  addonId: null,
18719
19697
  access: "create"
18720
19698
  },
19699
+ "deviceManager.setDisplay": {
19700
+ capName: "device-manager",
19701
+ capScope: "system",
19702
+ addonId: null,
19703
+ access: "create"
19704
+ },
18721
19705
  "deviceManager.setIntegrationId": {
18722
19706
  capName: "device-manager",
18723
19707
  capScope: "system",
@@ -18760,6 +19744,12 @@ Object.freeze({
18760
19744
  addonId: null,
18761
19745
  access: "create"
18762
19746
  },
19747
+ "deviceManager.setRoleDisplayDefaults": {
19748
+ capName: "device-manager",
19749
+ capScope: "system",
19750
+ addonId: null,
19751
+ access: "create"
19752
+ },
18763
19753
  "deviceManager.setStreamProfileMap": {
18764
19754
  capName: "device-manager",
18765
19755
  capScope: "system",
@@ -19810,6 +20800,66 @@ Object.freeze({
19810
20800
  addonId: null,
19811
20801
  access: "create"
19812
20802
  },
20803
+ "petFeeder.callPet": {
20804
+ capName: "pet-feeder",
20805
+ capScope: "device",
20806
+ addonId: null,
20807
+ access: "create"
20808
+ },
20809
+ "petFeeder.cancelFeed": {
20810
+ capName: "pet-feeder",
20811
+ capScope: "device",
20812
+ addonId: null,
20813
+ access: "create"
20814
+ },
20815
+ "petFeeder.feed": {
20816
+ capName: "pet-feeder",
20817
+ capScope: "device",
20818
+ addonId: null,
20819
+ access: "create"
20820
+ },
20821
+ "petFeeder.markFoodReplenished": {
20822
+ capName: "pet-feeder",
20823
+ capScope: "device",
20824
+ addonId: null,
20825
+ access: "create"
20826
+ },
20827
+ "petFeeder.playSound": {
20828
+ capName: "pet-feeder",
20829
+ capScope: "device",
20830
+ addonId: null,
20831
+ access: "create"
20832
+ },
20833
+ "petFeeder.resetDesiccant": {
20834
+ capName: "pet-feeder",
20835
+ capScope: "device",
20836
+ addonId: null,
20837
+ access: "delete"
20838
+ },
20839
+ "petFeeder.setChildLock": {
20840
+ capName: "pet-feeder",
20841
+ capScope: "device",
20842
+ addonId: null,
20843
+ access: "create"
20844
+ },
20845
+ "petFeeder.setFeedSound": {
20846
+ capName: "pet-feeder",
20847
+ capScope: "device",
20848
+ addonId: null,
20849
+ access: "create"
20850
+ },
20851
+ "petFeeder.setIndicatorLight": {
20852
+ capName: "pet-feeder",
20853
+ capScope: "device",
20854
+ addonId: null,
20855
+ access: "create"
20856
+ },
20857
+ "petFeeder.setVolume": {
20858
+ capName: "pet-feeder",
20859
+ capScope: "device",
20860
+ addonId: null,
20861
+ access: "create"
20862
+ },
19813
20863
  "pipelineAnalytics.clearTracks": {
19814
20864
  capName: "pipeline-analytics",
19815
20865
  capScope: "device",
@@ -20416,30 +21466,6 @@ Object.freeze({
20416
21466
  addonId: null,
20417
21467
  access: "view"
20418
21468
  },
20419
- "platformProbe.getHardwareDecodeAccels": {
20420
- capName: "platform-probe",
20421
- capScope: "system",
20422
- addonId: null,
20423
- access: "view"
20424
- },
20425
- "platformProbe.getHardwareEncoders": {
20426
- capName: "platform-probe",
20427
- capScope: "system",
20428
- addonId: null,
20429
- access: "view"
20430
- },
20431
- "platformProbe.refreshHardwareDecodeAccels": {
20432
- capName: "platform-probe",
20433
- capScope: "system",
20434
- addonId: null,
20435
- access: "create"
20436
- },
20437
- "platformProbe.refreshHardwareEncoders": {
20438
- capName: "platform-probe",
20439
- capScope: "system",
20440
- addonId: null,
20441
- access: "create"
20442
- },
20443
21469
  "platformProbe.resolveHwAccel": {
20444
21470
  capName: "platform-probe",
20445
21471
  capScope: "system",