@camstack/addon-advanced-notifier 1.1.15 → 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.
Files changed (3) hide show
  1. package/dist/addon.js +1134 -30
  2. package/dist/addon.mjs +1134 -30
  3. package/package.json +1 -1
package/dist/addon.mjs CHANGED
@@ -4628,7 +4628,7 @@ function _instanceof(cls, params = {}) {
4628
4628
  return inst;
4629
4629
  }
4630
4630
  //#endregion
4631
- //#region ../types/dist/sleep-MHm--th-.mjs
4631
+ //#region ../types/dist/sleep-BiDFW0E7.mjs
4632
4632
  var EventCategory = /* @__PURE__ */ function(EventCategory) {
4633
4633
  EventCategory["SystemBoot"] = "system.boot";
4634
4634
  EventCategory["SystemAddonsReady"] = "system.addons-ready";
@@ -5441,6 +5441,100 @@ function createDurableState(deps) {
5441
5441
  };
5442
5442
  }
5443
5443
  /**
5444
+ * Per-node scoping for the shared addon-settings blob.
5445
+ *
5446
+ * An addon's settings store is hub-central (the `addon-settings` cap is
5447
+ * hub-routed — the hub instance answers for every node), so fields whose
5448
+ * value is a NODE fact (decoder backend, engine pick, probed hardware
5449
+ * capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
5450
+ * the single shared blob. The SCHEMA field key stays bare: the write path
5451
+ * ({@link scopePatch}) maps the bare field onto the target node's scoped
5452
+ * key; the read/hydrate path ({@link projectStore}) maps THIS node's value
5453
+ * back, so UI forms and `resolveConfig` only ever see the bare key.
5454
+ *
5455
+ * Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
5456
+ * (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
5457
+ * schema and routes reads/writes through these helpers.
5458
+ *
5459
+ * ## No bare-key fallback — deliberate
5460
+ *
5461
+ * {@link readNodeValue} reads the node-scoped key ONLY. A node with no
5462
+ * scoped key resolves to `undefined` so the field's schema `default` wins —
5463
+ * NEVER `store[base]` and never another node's value. A bare legacy key in
5464
+ * the store is invisible to every node, hub included, so one node's
5465
+ * selection can never leak onto another. (This generalizes the
5466
+ * `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
5467
+ * arbitrary set of per-node field keys.)
5468
+ *
5469
+ * Pure functions only — no I/O, no imports beyond the language. This is a
5470
+ * LEAF module: import it via its deep path, never from the root barrel.
5471
+ */
5472
+ /**
5473
+ * Normalize a raw kernel node id to the bare node id used for scoping.
5474
+ * `localNodeId` can carry a `<node>/<addon>` suffix on forked child
5475
+ * processes; per-node settings are per-NODE, so strip the addon segment.
5476
+ * `undefined` / `null` / empty falls back to `'hub'`.
5477
+ */
5478
+ function normalizeNodeId(raw) {
5479
+ if (raw === void 0 || raw === null || raw === "") return "hub";
5480
+ const slashIdx = raw.indexOf("/");
5481
+ if (slashIdx < 0) return raw;
5482
+ const bare = raw.slice(0, slashIdx);
5483
+ return bare === "" ? "hub" : bare;
5484
+ }
5485
+ /** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
5486
+ function nodeScopedKey(base, nodeId) {
5487
+ return `${base}@${normalizeNodeId(nodeId)}`;
5488
+ }
5489
+ /**
5490
+ * Read a node's value for a per-node field from the raw shared store:
5491
+ * the node-scoped key when present, otherwise `undefined`.
5492
+ * Deliberately NO bare-key fallback (see module doc) — the caller lets the
5493
+ * schema `default` win on `undefined`.
5494
+ */
5495
+ function readNodeValue(store, base, nodeId) {
5496
+ return store[nodeScopedKey(base, nodeId)];
5497
+ }
5498
+ /**
5499
+ * Re-map a UI/settings patch so every bare perNode field persists under the
5500
+ * TARGET node's scoped key; all other keys pass through unchanged. Used on
5501
+ * the write path so a save for one node never clobbers another node's value
5502
+ * (and the bare key is never written). Returns a new object — the input
5503
+ * patch is not mutated.
5504
+ */
5505
+ function scopePatch(patch, perNodeKeys, nodeId) {
5506
+ const out = {};
5507
+ for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
5508
+ return out;
5509
+ }
5510
+ /**
5511
+ * Project the raw shared store onto the bare schema keys for ONE node so a
5512
+ * UI schema (whose field keys are bare) hydrates from that node's own
5513
+ * values:
5514
+ *
5515
+ * - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
5516
+ * - Every bare perNode key is dropped from the pass-through (a stray bare
5517
+ * legacy key must never hydrate any node — no bare fallback).
5518
+ * - THIS node's effective value ({@link readNodeValue}) is then laid onto
5519
+ * each bare perNode key; when the node has no scoped key the bare key is
5520
+ * left ABSENT so the field's schema `default` wins.
5521
+ *
5522
+ * Returns a new object — the input store is not mutated.
5523
+ */
5524
+ function projectStore(store, perNodeKeys, nodeId) {
5525
+ const out = {};
5526
+ for (const [key, value] of Object.entries(store)) {
5527
+ if (key.includes("@")) continue;
5528
+ if (perNodeKeys.has(key)) continue;
5529
+ out[key] = value;
5530
+ }
5531
+ for (const base of perNodeKeys) {
5532
+ const value = readNodeValue(store, base, nodeId);
5533
+ if (value !== void 0) out[base] = value;
5534
+ }
5535
+ return out;
5536
+ }
5537
+ /**
5444
5538
  * Base class for CamStack addons. Eliminates settings boilerplate:
5445
5539
  *
5446
5540
  * - Typed `config` property with automatic resolution from store + defaults
@@ -5608,23 +5702,63 @@ var BaseAddon = class {
5608
5702
  deviceSettingsSchema() {
5609
5703
  return null;
5610
5704
  }
5611
- async getGlobalSettings(overlay, cap, _nodeId) {
5705
+ async getGlobalSettings(overlay, cap, nodeId) {
5612
5706
  const schema = this.globalSettingsSchema(cap);
5613
5707
  if (!schema) return { sections: [] };
5614
- const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5708
+ const projected = await this.resolveGlobalStore(nodeId, cap);
5615
5709
  return hydrateSchema(schema, overlay ? {
5616
- ...raw,
5710
+ ...projected,
5617
5711
  ...overlay
5618
- } : raw);
5712
+ } : projected);
5619
5713
  }
5620
- async updateGlobalSettings(patch, _nodeId) {
5621
- await this._ctx?.settings?.writeAddonStore(patch);
5714
+ /**
5715
+ * The raw addon store PROJECTED onto the target node's bare per-node keys:
5716
+ * every `perNode: true` field carries THAT node's scoped value on its bare
5717
+ * key (absent scoped key ⇒ key absent, so the schema `default` wins — no
5718
+ * bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
5719
+ * A no-op passthrough when the schema declares no `perNode` field.
5720
+ *
5721
+ * This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
5722
+ * the store for custom option logic (option narrowing, value snapping) to
5723
+ * read it per-node — never `ctx.settings.readAddonStore()` directly.
5724
+ * `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
5725
+ */
5726
+ async resolveGlobalStore(nodeId, cap) {
5727
+ const raw = await this._ctx?.settings?.readAddonStore() ?? {};
5728
+ const keys = this.perNodeKeys(cap);
5729
+ const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5730
+ return keys.size > 0 ? projectStore(raw, keys, node) : raw;
5731
+ }
5732
+ async updateGlobalSettings(patch, nodeId) {
5733
+ const keys = this.perNodeKeys();
5734
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5735
+ const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
5736
+ const barePatch = patch;
5737
+ const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
5738
+ await this._ctx?.settings?.writeAddonStore(scoped);
5739
+ if (target !== localNode) return;
5622
5740
  await this.resolveConfig();
5623
5741
  await this.onConfigChanged();
5624
5742
  this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
5625
5743
  this.maybeAutoRestart(patch, this.globalSettingsSchema());
5626
5744
  }
5627
5745
  /**
5746
+ * The set of field keys the global settings schema declares `perNode: true`
5747
+ * — derived once per `cap` argument and memoized (schemas are static
5748
+ * declarations). Empty set ⇒ every per-node code path is bypassed and the
5749
+ * settings API behaves exactly like the legacy node-agnostic one.
5750
+ */
5751
+ _perNodeKeysCache = /* @__PURE__ */ new Map();
5752
+ perNodeKeys(cap) {
5753
+ const cacheKey = cap ?? "";
5754
+ const cached = this._perNodeKeysCache.get(cacheKey);
5755
+ if (cached) return cached;
5756
+ const schema = this.globalSettingsSchema(cap);
5757
+ const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
5758
+ this._perNodeKeysCache.set(cacheKey, keys);
5759
+ return keys;
5760
+ }
5761
+ /**
5628
5762
  * If any field in `patch` is marked `requiresRestart` in `schema`,
5629
5763
  * schedule an addon restart for the next tick. Deferred via
5630
5764
  * `setImmediate` so the tRPC mutation that triggered the write has
@@ -5777,12 +5911,19 @@ var BaseAddon = class {
5777
5911
  * The merge is shallow: each key in `defaults` is checked against the store.
5778
5912
  * Only keys present in defaults are read — the store can contain extra keys
5779
5913
  * (e.g. from older versions) without polluting the typed config.
5914
+ *
5915
+ * Keys the global settings schema declares `perNode: true` resolve from
5916
+ * THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
5917
+ * from the bare key — so a per-node field resolves to this node's own
5918
+ * selection at boot (absent scoped key ⇒ the constructor default wins).
5780
5919
  */
5781
5920
  async resolveConfig() {
5782
5921
  const stored = await this.readAddonStoreWithRetry();
5922
+ const perNode = this.perNodeKeys();
5923
+ const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
5783
5924
  const resolved = { ...this.defaults };
5784
5925
  for (const key of Object.keys(this.defaults)) {
5785
- const storedValue = stored[key];
5926
+ const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
5786
5927
  if (storedValue !== void 0 && storedValue !== null) {
5787
5928
  const defaultType = typeof this.defaults[key];
5788
5929
  if (typeof storedValue === defaultType) resolved[key] = storedValue;
@@ -5866,6 +6007,27 @@ var BaseAddon = class {
5866
6007
  }
5867
6008
  };
5868
6009
  /**
6010
+ * Collect the keys of every field marked `perNode: true`, recursing into
6011
+ * layout containers (`group` fields and `sub-tabs` tabs) the same way
6012
+ * `hydrateSchema` does. Valueless structural fields (separator/info/…)
6013
+ * don't declare `perNode` and are excluded by the `in` narrowing.
6014
+ */
6015
+ function collectPerNodeFieldKeys(fields) {
6016
+ const collected = [];
6017
+ for (const field of fields) {
6018
+ if (field.type === "group") {
6019
+ collected.push(...collectPerNodeFieldKeys(field.fields));
6020
+ continue;
6021
+ }
6022
+ if (field.type === "sub-tabs") {
6023
+ for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
6024
+ continue;
6025
+ }
6026
+ if ("perNode" in field && field.perNode === true) collected.push(field.key);
6027
+ }
6028
+ return collected;
6029
+ }
6030
+ /**
5869
6031
  * Normalize an `ICamstackAddon.initialize()` return value into the
5870
6032
  * `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
5871
6033
  * envelopes pass through; void stays void.
@@ -6273,6 +6435,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
6273
6435
  /** Single still-image entity (HA `image.*`). Read-only display of an
6274
6436
  * `entity_picture` signed URL the browser loads directly. `image` cap. */
6275
6437
  DeviceType["Image"] = "image";
6438
+ /** Smart pet feeder — cloud-connected food dispenser with a bowl food
6439
+ * level, battery, desiccant life, feeding state and manual-feed /
6440
+ * call-pet / maintenance actions. Installed with the `pet-feeder` cap;
6441
+ * dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
6442
+ * native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
6443
+ * integrations sharing the same food/desiccant/hopper surface. */
6444
+ DeviceType["PetFeeder"] = "pet-feeder";
6276
6445
  return DeviceType;
6277
6446
  }({});
6278
6447
  var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
@@ -7435,6 +7604,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
7435
7604
  for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7436
7605
  for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
7437
7606
  /**
7607
+ * Error types for the safe expression engine. Two distinct classes so callers
7608
+ * can tell a compile-time (grammar) failure from a runtime (evaluation)
7609
+ * failure — both are non-fatal to the host: read paths degrade to "skip link".
7610
+ */
7611
+ /** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
7612
+ * the failure is anchored to a character (author-facing inline feedback). */
7613
+ var ExpressionParseError = class extends Error {
7614
+ position;
7615
+ constructor(message, position) {
7616
+ super(message);
7617
+ this.name = "ExpressionParseError";
7618
+ this.position = position;
7619
+ }
7620
+ };
7621
+ /** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
7622
+ * result, unknown builtin, step-budget exceeded). */
7623
+ var ExpressionEvalError = class extends Error {
7624
+ constructor(message) {
7625
+ super(message);
7626
+ this.name = "ExpressionEvalError";
7627
+ }
7628
+ };
7629
+ /**
7630
+ * Resource-bound constants for the safe expression engine.
7631
+ *
7632
+ * Every bound is defense-in-depth: the grammar is non-Turing-complete (no
7633
+ * loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
7634
+ * O(nodeCount) by construction. These caps merely put a hard ceiling on the
7635
+ * work a single author-supplied expression can request, so a hostile or
7636
+ * accidental pathological string can never spend unbounded CPU/memory.
7637
+ */
7638
+ /** Max source length (chars) — checked BEFORE tokenizing so a huge string is
7639
+ * rejected without allocation. */
7640
+ var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
7641
+ /** A legal binding / identifier name. */
7642
+ var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
7643
+ /** Binding names an author may NOT use: `now` is auto-injected; the literal
7644
+ * keywords lex as values, not identifiers, so binding to them is meaningless. */
7645
+ var RESERVED_BINDING_NAMES = new Set([
7646
+ "now",
7647
+ "true",
7648
+ "false",
7649
+ "null"
7650
+ ]);
7651
+ /**
7652
+ * Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
7653
+ * zero-dependency. The grammar is deliberately boring: decimal numbers,
7654
+ * single/double-quoted strings with a tiny escape set, identifiers, the three
7655
+ * value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
7656
+ * outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
7657
+ * is a parse error with a source position, so member access / assignment /
7658
+ * template literals are lexically impossible.
7659
+ */
7660
+ var KEYWORDS = new Set([
7661
+ "true",
7662
+ "false",
7663
+ "null"
7664
+ ]);
7665
+ function isDigit(ch) {
7666
+ return ch >= "0" && ch <= "9";
7667
+ }
7668
+ function isIdentStart(ch) {
7669
+ return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
7670
+ }
7671
+ function isIdentPart(ch) {
7672
+ return isIdentStart(ch) || isDigit(ch);
7673
+ }
7674
+ function isWhitespace(ch) {
7675
+ return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
7676
+ }
7677
+ /** Tokenize `source` into a flat token list ending with a single `eof` token.
7678
+ * Throws `ExpressionParseError` on any illegal character or unterminated
7679
+ * string. */
7680
+ function tokenize(source) {
7681
+ if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
7682
+ const tokens = [];
7683
+ let i = 0;
7684
+ const n = source.length;
7685
+ while (i < n) {
7686
+ const ch = source[i];
7687
+ if (isWhitespace(ch)) {
7688
+ i += 1;
7689
+ continue;
7690
+ }
7691
+ if (isDigit(ch)) {
7692
+ const start = i;
7693
+ while (i < n && isDigit(source[i])) i += 1;
7694
+ if (i < n && source[i] === ".") {
7695
+ if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
7696
+ i += 1;
7697
+ while (i < n && isDigit(source[i])) i += 1;
7698
+ }
7699
+ const text = source.slice(start, i);
7700
+ const value = Number(text);
7701
+ if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
7702
+ tokens.push({
7703
+ type: "number",
7704
+ value,
7705
+ pos: start
7706
+ });
7707
+ continue;
7708
+ }
7709
+ if (ch === "'" || ch === "\"") {
7710
+ const quote = ch;
7711
+ const start = i;
7712
+ i += 1;
7713
+ let out = "";
7714
+ let closed = false;
7715
+ while (i < n) {
7716
+ const c = source[i];
7717
+ if (c === "\\") {
7718
+ const next = i + 1 < n ? source[i + 1] : "";
7719
+ if (next === "\\" || next === "'" || next === "\"") {
7720
+ out += next;
7721
+ i += 2;
7722
+ continue;
7723
+ }
7724
+ throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
7725
+ }
7726
+ if (c === quote) {
7727
+ closed = true;
7728
+ i += 1;
7729
+ break;
7730
+ }
7731
+ out += c;
7732
+ i += 1;
7733
+ }
7734
+ if (!closed) throw new ExpressionParseError("unterminated string literal", start);
7735
+ tokens.push({
7736
+ type: "string",
7737
+ value: out,
7738
+ pos: start
7739
+ });
7740
+ continue;
7741
+ }
7742
+ if (isIdentStart(ch)) {
7743
+ const start = i;
7744
+ while (i < n && isIdentPart(source[i])) i += 1;
7745
+ const text = source.slice(start, i);
7746
+ if (KEYWORDS.has(text)) tokens.push({
7747
+ type: "keyword",
7748
+ keyword: keywordOf(text),
7749
+ pos: start
7750
+ });
7751
+ else tokens.push({
7752
+ type: "identifier",
7753
+ name: text,
7754
+ pos: start
7755
+ });
7756
+ continue;
7757
+ }
7758
+ const two = i + 1 < n ? source.slice(i, i + 2) : "";
7759
+ if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
7760
+ tokens.push({
7761
+ type: "punct",
7762
+ punct: two,
7763
+ pos: i
7764
+ });
7765
+ i += 2;
7766
+ continue;
7767
+ }
7768
+ if (isSinglePunct(ch)) {
7769
+ tokens.push({
7770
+ type: "punct",
7771
+ punct: ch,
7772
+ pos: i
7773
+ });
7774
+ i += 1;
7775
+ continue;
7776
+ }
7777
+ throw new ExpressionParseError(`unexpected character '${ch}'`, i);
7778
+ }
7779
+ tokens.push({
7780
+ type: "eof",
7781
+ pos: n
7782
+ });
7783
+ return tokens;
7784
+ }
7785
+ function keywordOf(text) {
7786
+ if (text === "true") return "true";
7787
+ if (text === "false") return "false";
7788
+ return "null";
7789
+ }
7790
+ function isSinglePunct(ch) {
7791
+ return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
7792
+ }
7793
+ /**
7794
+ * Frozen, null-prototype builtin function table for the expression engine
7795
+ * (spec §4 rule 4). The table is the SOLE surface of callable functions: the
7796
+ * parser rejects any callee not in it, and the evaluator gates each call on an
7797
+ * own-property check against it.
7798
+ *
7799
+ * Because the object has a NULL prototype AND is `Object.freeze`d:
7800
+ * - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
7801
+ * - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
7802
+ * (there is no `Object.prototype` in the chain), so those names are not
7803
+ * callable — they are simply "unknown function" at parse time.
7804
+ *
7805
+ * Every numeric argument is validated as a finite number and every numeric
7806
+ * RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
7807
+ * (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
7808
+ * closed rather than emitting a garbage value.
7809
+ */
7810
+ function asFiniteNumber(value, name, index) {
7811
+ if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
7812
+ return value;
7813
+ }
7814
+ function asString$1(value, name, index) {
7815
+ if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
7816
+ return value;
7817
+ }
7818
+ function finiteResult(value, name) {
7819
+ if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
7820
+ return value;
7821
+ }
7822
+ function allFiniteNumbers(args, name) {
7823
+ return args.map((a, idx) => asFiniteNumber(a, name, idx));
7824
+ }
7825
+ var INF = Number.POSITIVE_INFINITY;
7826
+ var table = {
7827
+ min: {
7828
+ minArgs: 1,
7829
+ maxArgs: INF,
7830
+ apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
7831
+ },
7832
+ max: {
7833
+ minArgs: 1,
7834
+ maxArgs: INF,
7835
+ apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
7836
+ },
7837
+ abs: {
7838
+ minArgs: 1,
7839
+ maxArgs: 1,
7840
+ apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
7841
+ },
7842
+ floor: {
7843
+ minArgs: 1,
7844
+ maxArgs: 1,
7845
+ apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
7846
+ },
7847
+ ceil: {
7848
+ minArgs: 1,
7849
+ maxArgs: 1,
7850
+ apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
7851
+ },
7852
+ sqrt: {
7853
+ minArgs: 1,
7854
+ maxArgs: 1,
7855
+ apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
7856
+ },
7857
+ round: {
7858
+ minArgs: 1,
7859
+ maxArgs: 2,
7860
+ apply: (args) => {
7861
+ const x = asFiniteNumber(args[0], "round", 0);
7862
+ const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
7863
+ if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
7864
+ const factor = 10 ** digits;
7865
+ return finiteResult(Math.round(x * factor) / factor, "round");
7866
+ }
7867
+ },
7868
+ pow: {
7869
+ minArgs: 2,
7870
+ maxArgs: 2,
7871
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
7872
+ },
7873
+ clamp: {
7874
+ minArgs: 3,
7875
+ maxArgs: 3,
7876
+ apply: (args) => {
7877
+ const x = asFiniteNumber(args[0], "clamp", 0);
7878
+ const lo = asFiniteNumber(args[1], "clamp", 1);
7879
+ const hi = asFiniteNumber(args[2], "clamp", 2);
7880
+ if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
7881
+ return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
7882
+ }
7883
+ },
7884
+ avg: {
7885
+ minArgs: 1,
7886
+ maxArgs: INF,
7887
+ apply: (args) => {
7888
+ const nums = allFiniteNumbers(args, "avg");
7889
+ return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
7890
+ }
7891
+ },
7892
+ sum: {
7893
+ minArgs: 1,
7894
+ maxArgs: INF,
7895
+ apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
7896
+ },
7897
+ coalesce: {
7898
+ minArgs: 1,
7899
+ maxArgs: INF,
7900
+ apply: (args) => {
7901
+ for (const a of args) if (a !== null) return a;
7902
+ return null;
7903
+ }
7904
+ },
7905
+ age: {
7906
+ minArgs: 2,
7907
+ maxArgs: 2,
7908
+ apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
7909
+ },
7910
+ convert: {
7911
+ minArgs: 3,
7912
+ maxArgs: 3,
7913
+ apply: (args, hooks) => {
7914
+ const x = asFiniteNumber(args[0], "convert", 0);
7915
+ const from = asString$1(args[1], "convert", 1).trim();
7916
+ const to = asString$1(args[2], "convert", 2).trim();
7917
+ if (hooks.convert) {
7918
+ const out = hooks.convert(x, from, to);
7919
+ if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
7920
+ return finiteResult(out, "convert");
7921
+ }
7922
+ if (from === to) return x;
7923
+ throw new ExpressionEvalError("convert: unit conversion table not installed");
7924
+ }
7925
+ }
7926
+ };
7927
+ Object.freeze(Object.assign(Object.create(null), table));
7928
+ /** The set of valid builtin names — used by the parser to reject unknown
7929
+ * callees at parse time (immediate author feedback). */
7930
+ var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
7931
+ /**
7932
+ * Pratt (precedence-climbing) parser for the safe expression mini-language.
7933
+ *
7934
+ * Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
7935
+ * → relational → additive → multiplicative → unary `! -` → call / primary.
7936
+ * Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
7937
+ * string validated against the builtin table at parse time, so an unknown
7938
+ * function is rejected immediately (author feedback) and a persisted expression
7939
+ * that references a since-removed builtin degrades at read.
7940
+ *
7941
+ * A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
7942
+ * arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
7943
+ */
7944
+ /** Binary/logical operator precedence (higher binds tighter). */
7945
+ var BINARY_PRECEDENCE = {
7946
+ "||": 1,
7947
+ "&&": 2,
7948
+ "==": 3,
7949
+ "!=": 3,
7950
+ "<": 4,
7951
+ "<=": 4,
7952
+ ">": 4,
7953
+ ">=": 4,
7954
+ "+": 5,
7955
+ "-": 5,
7956
+ "*": 6,
7957
+ "/": 6,
7958
+ "%": 6
7959
+ };
7960
+ function isLogicalOp(op) {
7961
+ return op === "&&" || op === "||";
7962
+ }
7963
+ function isBinaryOp(op) {
7964
+ return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
7965
+ }
7966
+ var Parser = class {
7967
+ tokens;
7968
+ pos = 0;
7969
+ nodeCount = 0;
7970
+ identifiers = /* @__PURE__ */ new Set();
7971
+ callees = /* @__PURE__ */ new Set();
7972
+ constructor(tokens) {
7973
+ this.tokens = tokens;
7974
+ }
7975
+ parse() {
7976
+ const ast = this.parseTernary();
7977
+ const tok = this.peek();
7978
+ if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
7979
+ return {
7980
+ ast,
7981
+ identifiers: this.identifiers,
7982
+ callees: this.callees,
7983
+ nodeCount: this.nodeCount
7984
+ };
7985
+ }
7986
+ peek() {
7987
+ return this.tokens[this.pos];
7988
+ }
7989
+ next() {
7990
+ return this.tokens[this.pos++];
7991
+ }
7992
+ /** Consume a punctuator token, erroring if the next token isn't it. */
7993
+ expectPunct(punct) {
7994
+ const tok = this.peek();
7995
+ if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
7996
+ this.pos += 1;
7997
+ }
7998
+ matchPunct(punct) {
7999
+ const tok = this.peek();
8000
+ if (tok.type === "punct" && tok.punct === punct) {
8001
+ this.pos += 1;
8002
+ return true;
8003
+ }
8004
+ return false;
8005
+ }
8006
+ countNode() {
8007
+ this.nodeCount += 1;
8008
+ if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
8009
+ }
8010
+ parseTernary() {
8011
+ const test = this.parseBinary(1);
8012
+ if (this.matchPunct("?")) {
8013
+ const consequent = this.parseTernary();
8014
+ this.expectPunct(":");
8015
+ const alternate = this.parseTernary();
8016
+ this.countNode();
8017
+ return {
8018
+ kind: "conditional",
8019
+ test,
8020
+ consequent,
8021
+ alternate
8022
+ };
8023
+ }
8024
+ return test;
8025
+ }
8026
+ parseBinary(minPrec) {
8027
+ let left = this.parseUnary();
8028
+ for (;;) {
8029
+ const tok = this.peek();
8030
+ if (tok.type !== "punct") break;
8031
+ const prec = BINARY_PRECEDENCE[tok.punct];
8032
+ if (prec === void 0 || prec < minPrec) break;
8033
+ const op = tok.punct;
8034
+ this.pos += 1;
8035
+ const right = this.parseBinary(prec + 1);
8036
+ this.countNode();
8037
+ if (isLogicalOp(op)) left = {
8038
+ kind: "logical",
8039
+ op,
8040
+ left,
8041
+ right
8042
+ };
8043
+ else if (isBinaryOp(op)) left = {
8044
+ kind: "binary",
8045
+ op,
8046
+ left,
8047
+ right
8048
+ };
8049
+ else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
8050
+ }
8051
+ return left;
8052
+ }
8053
+ parseUnary() {
8054
+ const tok = this.peek();
8055
+ if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
8056
+ const op = tok.punct;
8057
+ this.pos += 1;
8058
+ const operand = this.parseUnary();
8059
+ this.countNode();
8060
+ return {
8061
+ kind: "unary",
8062
+ op,
8063
+ operand
8064
+ };
8065
+ }
8066
+ return this.parsePrimary();
8067
+ }
8068
+ parsePrimary() {
8069
+ const tok = this.next();
8070
+ switch (tok.type) {
8071
+ case "number":
8072
+ this.countNode();
8073
+ return {
8074
+ kind: "literal",
8075
+ value: tok.value
8076
+ };
8077
+ case "string":
8078
+ this.countNode();
8079
+ return {
8080
+ kind: "literal",
8081
+ value: tok.value
8082
+ };
8083
+ case "keyword":
8084
+ this.countNode();
8085
+ return {
8086
+ kind: "literal",
8087
+ value: tok.keyword === "null" ? null : tok.keyword === "true"
8088
+ };
8089
+ case "identifier": {
8090
+ const nextTok = this.peek();
8091
+ if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
8092
+ this.identifiers.add(tok.name);
8093
+ this.countNode();
8094
+ return {
8095
+ kind: "identifier",
8096
+ name: tok.name
8097
+ };
8098
+ }
8099
+ case "punct":
8100
+ if (tok.punct === "(") {
8101
+ const inner = this.parseTernary();
8102
+ this.expectPunct(")");
8103
+ return inner;
8104
+ }
8105
+ throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
8106
+ case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
8107
+ }
8108
+ }
8109
+ parseCall(callee, pos) {
8110
+ if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
8111
+ this.expectPunct("(");
8112
+ const args = [];
8113
+ if (!this.matchPunct(")")) for (;;) {
8114
+ args.push(this.parseTernary());
8115
+ if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
8116
+ if (this.matchPunct(",")) continue;
8117
+ this.expectPunct(")");
8118
+ break;
8119
+ }
8120
+ this.callees.add(callee);
8121
+ this.countNode();
8122
+ return {
8123
+ kind: "call",
8124
+ callee,
8125
+ args
8126
+ };
8127
+ }
8128
+ };
8129
+ /** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
8130
+ * `ExpressionParseError` on any lexical or grammatical failure. */
8131
+ function parseExpression(source) {
8132
+ return new Parser(tokenize(source)).parse();
8133
+ }
8134
+ Object.freeze({});
8135
+ /**
8136
+ * LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
8137
+ * by expr"). The cache stores BOTH successes and failures (negative caching),
8138
+ * so a corrupt persisted string costs exactly one tokenize+parse total — not
8139
+ * one per read on a hot resolve path.
8140
+ *
8141
+ * The cache is a module-level singleton: entries are pure, content-addressed
8142
+ * ASTs keyed by the raw source string, so sharing one instance across all
8143
+ * callers is safe and maximises hit rate.
8144
+ */
8145
+ var cache = /* @__PURE__ */ new Map();
8146
+ function getCached(source) {
8147
+ const hit = cache.get(source);
8148
+ if (hit !== void 0) {
8149
+ cache.delete(source);
8150
+ cache.set(source, hit);
8151
+ return hit;
8152
+ }
8153
+ let result;
8154
+ try {
8155
+ result = {
8156
+ ok: true,
8157
+ parsed: parseExpression(source)
8158
+ };
8159
+ } catch (err) {
8160
+ result = {
8161
+ ok: false,
8162
+ error: err instanceof ExpressionParseError ? err.message : String(err)
8163
+ };
8164
+ }
8165
+ cache.set(source, result);
8166
+ if (cache.size > 256) {
8167
+ const oldest = cache.keys().next().value;
8168
+ if (oldest !== void 0) cache.delete(oldest);
8169
+ }
8170
+ return result;
8171
+ }
8172
+ /** Compile `source`, returning a discriminated result instead of throwing.
8173
+ * Used by read paths that must degrade rather than raise. LRU/negative-cached. */
8174
+ function compileExpressionSafe(source) {
8175
+ return getCached(source);
8176
+ }
8177
+ /**
8178
+ * Author-time validation. Returns `null` when the source is valid, else a
8179
+ * human-readable error message. Checks: the expression compiles; binding count
8180
+ * is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
8181
+ * is not reserved (`now`/keywords) and does not shadow a builtin; and every
8182
+ * FREE identifier of the AST is covered by a binding or the injected `now`.
8183
+ */
8184
+ function validateExpressionSource(src) {
8185
+ const names = Object.keys(src.bindings);
8186
+ if (names.length > 32) return `too many bindings (${names.length} > 32)`;
8187
+ for (const name of names) {
8188
+ if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
8189
+ if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
8190
+ if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
8191
+ }
8192
+ const compiled = compileExpressionSafe(src.expr);
8193
+ if (!compiled.ok) return compiled.error;
8194
+ const bound = new Set(names);
8195
+ for (const id of compiled.parsed.identifiers) {
8196
+ if (id === "now") continue;
8197
+ if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
8198
+ }
8199
+ return null;
8200
+ }
8201
+ /**
7438
8202
  * Accessory device helpers — shared across drivers.
7439
8203
  *
7440
8204
  * Many vendor-specific drivers register accessory child devices on
@@ -9337,7 +10101,8 @@ var MotionAnalysisResultSchema = object({
9337
10101
  });
9338
10102
  method(object({
9339
10103
  deviceId: number(),
9340
- frame: FrameInputSchema
10104
+ frame: FrameInputSchema.optional(),
10105
+ frameHandle: FrameHandleSchema.optional()
9341
10106
  }), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
9342
10107
  deviceId: number(),
9343
10108
  detected: boolean(),
@@ -9584,6 +10349,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
9584
10349
  engine: PipelineEngineChoiceSchema.optional(),
9585
10350
  steps: array(PipelineStepInputSchema).min(1),
9586
10351
  frame: FrameInputSchema.optional(),
10352
+ /**
10353
+ * CB5 shm passthrough — a `FrameHandle` naming the same ring slot
10354
+ * the decoded pixels live in. One more member of the one-of
10355
+ * frame/frameHandle/image/imageBase64/referenceImage group.
10356
+ */
10357
+ frameHandle: FrameHandleSchema.optional(),
9587
10358
  imageBase64: string().optional(),
9588
10359
  /**
9589
10360
  * Binary JPEG bytes — preferred over `imageBase64` on internal
@@ -9793,6 +10564,31 @@ var ReportMotionInputSchema = object({
9793
10564
  regions: array(MotionRegionSchema).readonly().optional()
9794
10565
  });
9795
10566
  /**
10567
+ * Where a runner gets a camera's decoded frames (cross-node Phase 2,
10568
+ * restream-owner model — P2c).
10569
+ *
10570
+ * - `local-broker` (DEFAULT): today's path — subscribe to the co-located
10571
+ * stream-broker's shm frame plane. Every pre-P2c attach payload (no
10572
+ * `frameSource` key) parses to this, so the field is additive with zero
10573
+ * behavior change.
10574
+ * - `remote-restream`: the detect node is NOT the camera's source-owner.
10575
+ * The runner acquires the owner's COMPRESSED passthrough restream
10576
+ * (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
10577
+ * double-pull guard) and decodes LOCALLY via a satellite frame plane +
10578
+ * pull-mode decoder session pinned to its own node. The shm ring stays
10579
+ * node-local; only H.264/H.265 packets cross the wire.
10580
+ * `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
10581
+ * when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
10582
+ * dials for the owner's restream.
10583
+ */
10584
+ var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
10585
+ kind: literal("remote-restream"),
10586
+ /** The camera's source-owner node (slice 1: always the hub). */
10587
+ ownerNodeId: string(),
10588
+ /** Operator override for the owner host the runner dials. */
10589
+ hubHostnameOverride: string().optional()
10590
+ })]).describe("Per-camera frame-source mode for the runner (P2c)");
10591
+ /**
9796
10592
  * Camera assignment payload sent by `addon-pipeline-orchestrator` to a
9797
10593
  * specific runner instance via `attachCamera`. Carries everything the
9798
10594
  * runner needs to subscribe to the local broker and execute inference.
@@ -9890,7 +10686,15 @@ var RunnerCameraConfigSchema = object({
9890
10686
  */
9891
10687
  onboardMotionDrivesAnalyzer: boolean().default(true),
9892
10688
  occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
9893
- occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
10689
+ occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
10690
+ /**
10691
+ * Where this runner gets the camera's decoded frames (P2c). Defaulted so
10692
+ * every existing payload behaves as `local-broker` — the pre-Phase-2 path.
10693
+ * Populated with `remote-restream` by the orchestrator ONLY when the
10694
+ * camera's detect node differs from its source-owner (P2d, gated by the
10695
+ * `remoteSourcingNodes` rollout setting).
10696
+ */
10697
+ frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
9894
10698
  });
9895
10699
  motionFpsField.min, motionFpsField.max, motionFpsField.step, motionFpsField.default, detectionFpsField.min, detectionFpsField.max, detectionFpsField.step, detectionFpsField.default, motionCooldownMsField.min, motionCooldownMsField.max, motionCooldownMsField.step, motionCooldownMsField.default, occupancyRecheckSecField.min, occupancyRecheckSecField.max, occupancyRecheckSecField.step, occupancyRecheckSecField.default, occupancyRecheckFramesField.min, occupancyRecheckFramesField.max, occupancyRecheckFramesField.step, occupancyRecheckFramesField.default;
9896
10700
  /**
@@ -10255,6 +11059,113 @@ object({
10255
11059
  lastFetchedAt: number()
10256
11060
  });
10257
11061
  DeviceType.Sensor;
11062
+ /**
11063
+ * Feeder connectivity / power status — mirrors the HA petkit device-status
11064
+ * enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
11065
+ * `on_batteries` (running on battery backup). `null` until first reported.
11066
+ */
11067
+ var PetFeederDeviceStatusSchema = _enum([
11068
+ "normal",
11069
+ "offline",
11070
+ "on_batteries"
11071
+ ]);
11072
+ var gramsPortion = number().int().min(4).max(200);
11073
+ object({
11074
+ /** Food currently in the bowl (grams). Null when the device has not
11075
+ * reported a reading yet. On dual-hopper models this is the combined
11076
+ * bowl reading; per-hopper levels live in `food1`/`food2`. */
11077
+ foodLevel: number().nullable(),
11078
+ /** Hopper-1 food level (grams) on dual-hopper feeders; null on
11079
+ * single-hopper models. */
11080
+ food1: number().nullable(),
11081
+ /** Hopper-2 food level (grams) on dual-hopper feeders; null on
11082
+ * single-hopper models. */
11083
+ food2: number().nullable(),
11084
+ /** Derived low-food flag — mirrors the HA `food_level` binary_sensor
11085
+ * (`device_class: problem`, on = low). True when the bowl is empty /
11086
+ * below the feeder's low threshold. */
11087
+ lowFood: boolean(),
11088
+ /** Battery charge 0..100 (%). Null on mains-powered models or when the
11089
+ * device has no battery reading. */
11090
+ batteryPower: number().min(0).max(100).nullable(),
11091
+ /** Days of desiccant life remaining. Null when the model has no
11092
+ * desiccant sensor. */
11093
+ desiccantLeftDays: number().nullable(),
11094
+ /** True while a feed is in progress. */
11095
+ feeding: boolean(),
11096
+ /** Decoded connectivity / power status (HA petkit device-status enum).
11097
+ * Null until the device has reported a status. */
11098
+ status: PetFeederDeviceStatusSchema.nullable(),
11099
+ /** Decoded human-readable fault message. Null (or the device's `no_error`
11100
+ * sentinel) means healthy; a non-null string is an active fault. Pairs
11101
+ * with `errorCode` for consumers that want the raw integer. */
11102
+ error: string().nullable(),
11103
+ /** Raw device error code (0 / null = no error). */
11104
+ errorCode: number().nullable(),
11105
+ /** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
11106
+ isDualHopper: boolean(),
11107
+ /** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
11108
+ childLock: boolean(),
11109
+ /** Front indicator-light setting. */
11110
+ indicatorLight: boolean(),
11111
+ /** Play a chime when dispensing. */
11112
+ feedSound: boolean(),
11113
+ /** Speaker / prompt volume level (device-scaled integer). */
11114
+ volume: number(),
11115
+ /** Ms epoch when the slice was last refreshed from the cloud. */
11116
+ lastFetchedAt: number()
11117
+ });
11118
+ DeviceType.PetFeeder, method(object({
11119
+ deviceId: number().int().nonnegative(),
11120
+ grams: gramsPortion.optional(),
11121
+ hopper1: gramsPortion.optional(),
11122
+ hopper2: gramsPortion.optional()
11123
+ }), _void(), {
11124
+ kind: "mutation",
11125
+ auth: "admin"
11126
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11127
+ kind: "mutation",
11128
+ auth: "admin"
11129
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11130
+ kind: "mutation",
11131
+ auth: "admin"
11132
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11133
+ kind: "mutation",
11134
+ auth: "admin"
11135
+ }), method(object({ deviceId: number().int().nonnegative() }), _void(), {
11136
+ kind: "mutation",
11137
+ auth: "admin"
11138
+ }), method(object({
11139
+ deviceId: number().int().nonnegative(),
11140
+ soundId: number().int().nonnegative()
11141
+ }), _void(), {
11142
+ kind: "mutation",
11143
+ auth: "admin"
11144
+ }), method(object({
11145
+ deviceId: number().int().nonnegative(),
11146
+ on: boolean()
11147
+ }), _void(), {
11148
+ kind: "mutation",
11149
+ auth: "admin"
11150
+ }), method(object({
11151
+ deviceId: number().int().nonnegative(),
11152
+ on: boolean()
11153
+ }), _void(), {
11154
+ kind: "mutation",
11155
+ auth: "admin"
11156
+ }), method(object({
11157
+ deviceId: number().int().nonnegative(),
11158
+ on: boolean()
11159
+ }), _void(), {
11160
+ kind: "mutation",
11161
+ auth: "admin"
11162
+ }), method(object({
11163
+ deviceId: number().int().nonnegative(),
11164
+ level: number().int().nonnegative()
11165
+ }), _void(), {
11166
+ kind: "mutation",
11167
+ auth: "admin"
11168
+ });
10258
11169
  object({
10259
11170
  /** Instantaneous power draw in watts. */
10260
11171
  watts: number().optional(),
@@ -12094,10 +13005,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
12094
13005
  url: string()
12095
13006
  }), _void()), method(object({
12096
13007
  sessionId: string(),
12097
- maxCount: number().default(1)
13008
+ maxCount: number().default(1),
13009
+ waitMs: number().optional()
12098
13010
  }), array(DecodedFrameSchema)), method(object({
12099
13011
  sessionId: string(),
12100
- maxCount: number().default(1)
13012
+ maxCount: number().default(1),
13013
+ waitMs: number().optional()
12101
13014
  }), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
12102
13015
  sessionId: string(),
12103
13016
  config: DecoderSessionConfigSchema.partial()
@@ -12384,14 +13297,63 @@ var ChildLayoutEntrySchema = object({
12384
13297
  collapsed: boolean().optional()
12385
13298
  });
12386
13299
  /** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
12387
- * `device-management.ts`. */
13300
+ * `device-management.ts`. Source is a union: a FIELD source copies a sibling
13301
+ * accessory's status field (`kind` optional/absent for wire compat); a
13302
+ * LITERAL source carries a per-device constant (no sibling is read); a
13303
+ * GLOBAL source (P2e) copies ANY device's status field, addressed by the
13304
+ * source device's full re-sync-stable `stableId`. */
13305
+ var DeviceLinkFieldSourceSchema = object({
13306
+ kind: literal("field").optional(),
13307
+ sourceKey: string(),
13308
+ cap: string(),
13309
+ fieldPath: string()
13310
+ });
13311
+ var DeviceLinkLiteralSourceSchema = object({
13312
+ kind: literal("literal"),
13313
+ value: union([
13314
+ string(),
13315
+ number(),
13316
+ boolean(),
13317
+ _null()
13318
+ ])
13319
+ });
13320
+ var DeviceLinkGlobalSourceSchema = object({
13321
+ kind: literal("global"),
13322
+ sourceStableId: string(),
13323
+ cap: string(),
13324
+ fieldPath: string()
13325
+ });
13326
+ /** Expression source (Stage X): compute the target field from N named bindings
13327
+ * via the safe expression engine. Bindings are field | literal | global — never
13328
+ * another expression (no nesting). The `superRefine` runs the SAME author-time
13329
+ * validation as `validateExpressionSource` (compiles the expr, checks binding
13330
+ * names + identifier coverage) so every wire boundary that parses a DeviceLink
13331
+ * (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
13332
+ * Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
13333
+ var DeviceLinkExpressionSourceSchema = object({
13334
+ kind: literal("expression"),
13335
+ expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
13336
+ bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
13337
+ DeviceLinkFieldSourceSchema,
13338
+ DeviceLinkLiteralSourceSchema,
13339
+ DeviceLinkGlobalSourceSchema
13340
+ ]))
13341
+ }).superRefine((src, ctx) => {
13342
+ const err = validateExpressionSource(src);
13343
+ if (err !== null) ctx.addIssue({
13344
+ code: "custom",
13345
+ message: err,
13346
+ path: ["expr"]
13347
+ });
13348
+ });
12388
13349
  var DeviceLinkSchema = object({
12389
13350
  id: string(),
12390
- source: object({
12391
- sourceKey: string(),
12392
- cap: string(),
12393
- fieldPath: string()
12394
- }),
13351
+ source: union([
13352
+ DeviceLinkFieldSourceSchema,
13353
+ DeviceLinkLiteralSourceSchema,
13354
+ DeviceLinkGlobalSourceSchema,
13355
+ DeviceLinkExpressionSourceSchema
13356
+ ]),
12395
13357
  target: object({
12396
13358
  cap: string(),
12397
13359
  fieldPath: string(),
@@ -12420,6 +13382,31 @@ var DeviceLinkSchema = object({
12420
13382
  })
12421
13383
  ]).optional()
12422
13384
  });
13385
+ /** Cap-wire shape of a per-cap display refinement — mirrors
13386
+ * `DeviceCapDisplayOverride` in `device-management.ts`. */
13387
+ var DeviceCapDisplayOverrideSchema = object({
13388
+ unit: string().min(1).optional(),
13389
+ precision: number().int().min(0).max(10).optional()
13390
+ });
13391
+ /** Cap-wire shape of an operator-authored per-device display override —
13392
+ * mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
13393
+ * bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
13394
+ var DeviceDisplayOverrideSchema = object({
13395
+ icon: string().min(1).optional(),
13396
+ label: string().min(1).optional(),
13397
+ unit: string().min(1).optional(),
13398
+ precision: number().int().min(0).max(10).optional(),
13399
+ hidden: boolean().optional(),
13400
+ perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
13401
+ });
13402
+ /** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
13403
+ * in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
13404
+ * the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
13405
+ var RoleDisplayDefaultSchema = object({
13406
+ unit: string().min(1).optional(),
13407
+ precision: number().int().min(0).max(10).optional(),
13408
+ icon: string().min(1).optional()
13409
+ });
12423
13410
  /**
12424
13411
  * Serializable projection of a live IDevice.
12425
13412
  * Returned by listAll, getDevice, getChildren.
@@ -12475,7 +13462,9 @@ var DeviceInfoSchema = object({
12475
13462
  * `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
12476
13463
  childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
12477
13464
  /** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
12478
- deviceLinks: array(DeviceLinkSchema).readonly().optional()
13465
+ deviceLinks: array(DeviceLinkSchema).readonly().optional(),
13466
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13467
+ display: DeviceDisplayOverrideSchema.optional()
12479
13468
  });
12480
13469
  var ConfigEntrySchema = object({
12481
13470
  key: string(),
@@ -12540,7 +13529,9 @@ var DeviceMetaSchema = object({
12540
13529
  deviceLinks: array(DeviceLinkSchema).readonly().optional(),
12541
13530
  /** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
12542
13531
  * Optional: only present for accessory children that carry a known role. */
12543
- role: string().nullable().optional()
13532
+ role: string().nullable().optional(),
13533
+ /** Operator-authored per-device display override. See `DeviceMeta.display`. */
13534
+ display: DeviceDisplayOverrideSchema.optional()
12544
13535
  });
12545
13536
  /** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
12546
13537
  var ConfigUISchemaOutput = unknown().nullable();
@@ -12634,7 +13625,19 @@ method(object({
12634
13625
  }), _void(), {
12635
13626
  kind: "mutation",
12636
13627
  auth: "admin"
12637
- }), method(object({ deviceId: number() }), object({ caps: array(object({
13628
+ }), method(object({
13629
+ deviceId: number(),
13630
+ display: DeviceDisplayOverrideSchema.nullable()
13631
+ }), _void(), {
13632
+ kind: "mutation",
13633
+ auth: "admin"
13634
+ }), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
13635
+ kind: "mutation",
13636
+ auth: "admin"
13637
+ }), method(object({
13638
+ deviceId: number(),
13639
+ includeSynthesizable: boolean().optional()
13640
+ }), object({ caps: array(object({
12638
13641
  cap: string(),
12639
13642
  fields: array(object({
12640
13643
  path: string(),
@@ -12644,8 +13647,13 @@ method(object({
12644
13647
  "boolean",
12645
13648
  "enum"
12646
13649
  ]),
12647
- enumValues: array(string()).optional()
12648
- })).readonly()
13650
+ enumValues: array(string()).optional(),
13651
+ item: boolean().optional()
13652
+ })).readonly(),
13653
+ itemArray: object({
13654
+ path: string(),
13655
+ keyField: string()
13656
+ }).optional()
12649
13657
  })).readonly() }), { kind: "query" }), method(object({
12650
13658
  deviceId: number(),
12651
13659
  role: string().nullable()
@@ -12715,7 +13723,11 @@ method(object({
12715
13723
  deviceId: number(),
12716
13724
  entries: array(object({
12717
13725
  capName: string(),
12718
- kind: _enum(["native", "wrapped"]),
13726
+ kind: _enum([
13727
+ "native",
13728
+ "wrapped",
13729
+ "linked"
13730
+ ]),
12719
13731
  providerAddonId: string(),
12720
13732
  providerNodeId: string(),
12721
13733
  nativeAddonId: string()
@@ -12724,7 +13736,11 @@ method(object({
12724
13736
  deviceId: number(),
12725
13737
  entries: array(object({
12726
13738
  capName: string(),
12727
- kind: _enum(["native", "wrapped"]),
13739
+ kind: _enum([
13740
+ "native",
13741
+ "wrapped",
13742
+ "linked"
13743
+ ]),
12728
13744
  providerAddonId: string(),
12729
13745
  providerNodeId: string(),
12730
13746
  nativeAddonId: string()
@@ -16498,7 +17514,10 @@ var HwAccelBackendInputSchema = _enum([
16498
17514
  "webgpu",
16499
17515
  "none"
16500
17516
  ]).nullable().optional();
16501
- var HwAccelResolutionSchema = object({ preferred: array(string()).readonly() });
17517
+ var HwAccelResolutionSchema = object({
17518
+ preferred: array(string()).readonly(),
17519
+ rationale: string()
17520
+ });
16502
17521
  var HardwareEncoderIdSchema = _enum([
16503
17522
  "h264_videotoolbox",
16504
17523
  "hevc_videotoolbox",
@@ -16603,10 +17622,7 @@ var ResolvedInferenceConfigSchema = object({
16603
17622
  format: ModelFormatSchema,
16604
17623
  reason: string()
16605
17624
  });
16606
- method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
16607
- prefer: HwAccelBackendInputSchema,
16608
- nodeId: string().optional()
16609
- }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
17625
+ method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
16610
17626
  kind: "mutation",
16611
17627
  auth: "admin"
16612
17628
  }), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
@@ -16665,6 +17681,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
16665
17681
  kind: "mutation",
16666
17682
  auth: "admin"
16667
17683
  });
17684
+ /**
17685
+ * `recording` cap — footage availability + HLS playback manifests + per-device
17686
+ * recording config. NOTE on events (source of truth, R5/C3): this cap carries
17687
+ * NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
17688
+ * events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
17689
+ * rows); the recorder's internal EventMap markers are ephemeral in-RAM
17690
+ * annotations that are not exposed here and must not be treated as an event
17691
+ * feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
17692
+ * (`interfaces/recording-config.ts`).
17693
+ */
16668
17694
  var RecordingStatusSchema = object({
16669
17695
  deviceId: number(),
16670
17696
  enabled: boolean(),
@@ -18301,6 +19327,12 @@ Object.freeze({
18301
19327
  addonId: null,
18302
19328
  access: "view"
18303
19329
  },
19330
+ "deviceManager.getRoleDisplayDefaults": {
19331
+ capName: "device-manager",
19332
+ capScope: "system",
19333
+ addonId: null,
19334
+ access: "view"
19335
+ },
18304
19336
  "deviceManager.getSettingsSchema": {
18305
19337
  capName: "device-manager",
18306
19338
  capScope: "system",
@@ -18451,6 +19483,12 @@ Object.freeze({
18451
19483
  addonId: null,
18452
19484
  access: "create"
18453
19485
  },
19486
+ "deviceManager.setDisplay": {
19487
+ capName: "device-manager",
19488
+ capScope: "system",
19489
+ addonId: null,
19490
+ access: "create"
19491
+ },
18454
19492
  "deviceManager.setIntegrationId": {
18455
19493
  capName: "device-manager",
18456
19494
  capScope: "system",
@@ -18493,6 +19531,12 @@ Object.freeze({
18493
19531
  addonId: null,
18494
19532
  access: "create"
18495
19533
  },
19534
+ "deviceManager.setRoleDisplayDefaults": {
19535
+ capName: "device-manager",
19536
+ capScope: "system",
19537
+ addonId: null,
19538
+ access: "create"
19539
+ },
18496
19540
  "deviceManager.setStreamProfileMap": {
18497
19541
  capName: "device-manager",
18498
19542
  capScope: "system",
@@ -19543,6 +20587,66 @@ Object.freeze({
19543
20587
  addonId: null,
19544
20588
  access: "create"
19545
20589
  },
20590
+ "petFeeder.callPet": {
20591
+ capName: "pet-feeder",
20592
+ capScope: "device",
20593
+ addonId: null,
20594
+ access: "create"
20595
+ },
20596
+ "petFeeder.cancelFeed": {
20597
+ capName: "pet-feeder",
20598
+ capScope: "device",
20599
+ addonId: null,
20600
+ access: "create"
20601
+ },
20602
+ "petFeeder.feed": {
20603
+ capName: "pet-feeder",
20604
+ capScope: "device",
20605
+ addonId: null,
20606
+ access: "create"
20607
+ },
20608
+ "petFeeder.markFoodReplenished": {
20609
+ capName: "pet-feeder",
20610
+ capScope: "device",
20611
+ addonId: null,
20612
+ access: "create"
20613
+ },
20614
+ "petFeeder.playSound": {
20615
+ capName: "pet-feeder",
20616
+ capScope: "device",
20617
+ addonId: null,
20618
+ access: "create"
20619
+ },
20620
+ "petFeeder.resetDesiccant": {
20621
+ capName: "pet-feeder",
20622
+ capScope: "device",
20623
+ addonId: null,
20624
+ access: "delete"
20625
+ },
20626
+ "petFeeder.setChildLock": {
20627
+ capName: "pet-feeder",
20628
+ capScope: "device",
20629
+ addonId: null,
20630
+ access: "create"
20631
+ },
20632
+ "petFeeder.setFeedSound": {
20633
+ capName: "pet-feeder",
20634
+ capScope: "device",
20635
+ addonId: null,
20636
+ access: "create"
20637
+ },
20638
+ "petFeeder.setIndicatorLight": {
20639
+ capName: "pet-feeder",
20640
+ capScope: "device",
20641
+ addonId: null,
20642
+ access: "create"
20643
+ },
20644
+ "petFeeder.setVolume": {
20645
+ capName: "pet-feeder",
20646
+ capScope: "device",
20647
+ addonId: null,
20648
+ access: "create"
20649
+ },
19546
20650
  "pipelineAnalytics.clearTracks": {
19547
20651
  capName: "pipeline-analytics",
19548
20652
  capScope: "device",