@camstack/addon-notifiers 1.1.15 → 1.1.17
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.
- package/dist/addon.js +1140 -71
- package/dist/addon.mjs +1140 -71
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -4631,7 +4631,7 @@ function _instanceof(cls, params = {}) {
|
|
|
4631
4631
|
return inst;
|
|
4632
4632
|
}
|
|
4633
4633
|
//#endregion
|
|
4634
|
-
//#region ../types/dist/sleep-
|
|
4634
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4635
4635
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4636
4636
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4637
4637
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5444,6 +5444,100 @@ function createDurableState(deps) {
|
|
|
5444
5444
|
};
|
|
5445
5445
|
}
|
|
5446
5446
|
/**
|
|
5447
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5448
|
+
*
|
|
5449
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5450
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5451
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5452
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5453
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5454
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5455
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5456
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5457
|
+
*
|
|
5458
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5459
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5460
|
+
* schema and routes reads/writes through these helpers.
|
|
5461
|
+
*
|
|
5462
|
+
* ## No bare-key fallback — deliberate
|
|
5463
|
+
*
|
|
5464
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5465
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5466
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5467
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5468
|
+
* selection can never leak onto another. (This generalizes the
|
|
5469
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5470
|
+
* arbitrary set of per-node field keys.)
|
|
5471
|
+
*
|
|
5472
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5473
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5474
|
+
*/
|
|
5475
|
+
/**
|
|
5476
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5477
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5478
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5479
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5480
|
+
*/
|
|
5481
|
+
function normalizeNodeId(raw) {
|
|
5482
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5483
|
+
const slashIdx = raw.indexOf("/");
|
|
5484
|
+
if (slashIdx < 0) return raw;
|
|
5485
|
+
const bare = raw.slice(0, slashIdx);
|
|
5486
|
+
return bare === "" ? "hub" : bare;
|
|
5487
|
+
}
|
|
5488
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5489
|
+
function nodeScopedKey(base, nodeId) {
|
|
5490
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5491
|
+
}
|
|
5492
|
+
/**
|
|
5493
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5494
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5495
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5496
|
+
* schema `default` win on `undefined`.
|
|
5497
|
+
*/
|
|
5498
|
+
function readNodeValue(store, base, nodeId) {
|
|
5499
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5500
|
+
}
|
|
5501
|
+
/**
|
|
5502
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5503
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5504
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5505
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5506
|
+
* patch is not mutated.
|
|
5507
|
+
*/
|
|
5508
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5509
|
+
const out = {};
|
|
5510
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5511
|
+
return out;
|
|
5512
|
+
}
|
|
5513
|
+
/**
|
|
5514
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5515
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5516
|
+
* values:
|
|
5517
|
+
*
|
|
5518
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5519
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5520
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5521
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5522
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5523
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5524
|
+
*
|
|
5525
|
+
* Returns a new object — the input store is not mutated.
|
|
5526
|
+
*/
|
|
5527
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5528
|
+
const out = {};
|
|
5529
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5530
|
+
if (key.includes("@")) continue;
|
|
5531
|
+
if (perNodeKeys.has(key)) continue;
|
|
5532
|
+
out[key] = value;
|
|
5533
|
+
}
|
|
5534
|
+
for (const base of perNodeKeys) {
|
|
5535
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5536
|
+
if (value !== void 0) out[base] = value;
|
|
5537
|
+
}
|
|
5538
|
+
return out;
|
|
5539
|
+
}
|
|
5540
|
+
/**
|
|
5447
5541
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5448
5542
|
*
|
|
5449
5543
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5611,23 +5705,63 @@ var BaseAddon = class {
|
|
|
5611
5705
|
deviceSettingsSchema() {
|
|
5612
5706
|
return null;
|
|
5613
5707
|
}
|
|
5614
|
-
async getGlobalSettings(overlay, cap,
|
|
5708
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5615
5709
|
const schema = this.globalSettingsSchema(cap);
|
|
5616
5710
|
if (!schema) return { sections: [] };
|
|
5617
|
-
const
|
|
5711
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5618
5712
|
return hydrateSchema(schema, overlay ? {
|
|
5619
|
-
...
|
|
5713
|
+
...projected,
|
|
5620
5714
|
...overlay
|
|
5621
|
-
} :
|
|
5715
|
+
} : projected);
|
|
5716
|
+
}
|
|
5717
|
+
/**
|
|
5718
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5719
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5720
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5721
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5722
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5723
|
+
*
|
|
5724
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5725
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5726
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5727
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5728
|
+
*/
|
|
5729
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5730
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5731
|
+
const keys = this.perNodeKeys(cap);
|
|
5732
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5733
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5622
5734
|
}
|
|
5623
|
-
async updateGlobalSettings(patch,
|
|
5624
|
-
|
|
5735
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5736
|
+
const keys = this.perNodeKeys();
|
|
5737
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5738
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5739
|
+
const barePatch = patch;
|
|
5740
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5741
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5742
|
+
if (target !== localNode) return;
|
|
5625
5743
|
await this.resolveConfig();
|
|
5626
5744
|
await this.onConfigChanged();
|
|
5627
5745
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5628
5746
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5629
5747
|
}
|
|
5630
5748
|
/**
|
|
5749
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5750
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5751
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5752
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5753
|
+
*/
|
|
5754
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5755
|
+
perNodeKeys(cap) {
|
|
5756
|
+
const cacheKey = cap ?? "";
|
|
5757
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5758
|
+
if (cached) return cached;
|
|
5759
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5760
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5761
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5762
|
+
return keys;
|
|
5763
|
+
}
|
|
5764
|
+
/**
|
|
5631
5765
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5632
5766
|
* schedule an addon restart for the next tick. Deferred via
|
|
5633
5767
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5780,12 +5914,19 @@ var BaseAddon = class {
|
|
|
5780
5914
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5781
5915
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5782
5916
|
* (e.g. from older versions) without polluting the typed config.
|
|
5917
|
+
*
|
|
5918
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5919
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5920
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5921
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5783
5922
|
*/
|
|
5784
5923
|
async resolveConfig() {
|
|
5785
5924
|
const stored = await this.readAddonStoreWithRetry();
|
|
5925
|
+
const perNode = this.perNodeKeys();
|
|
5926
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5786
5927
|
const resolved = { ...this.defaults };
|
|
5787
5928
|
for (const key of Object.keys(this.defaults)) {
|
|
5788
|
-
const storedValue = stored[key];
|
|
5929
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5789
5930
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5790
5931
|
const defaultType = typeof this.defaults[key];
|
|
5791
5932
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5869,6 +6010,27 @@ var BaseAddon = class {
|
|
|
5869
6010
|
}
|
|
5870
6011
|
};
|
|
5871
6012
|
/**
|
|
6013
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6014
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6015
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6016
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6017
|
+
*/
|
|
6018
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6019
|
+
const collected = [];
|
|
6020
|
+
for (const field of fields) {
|
|
6021
|
+
if (field.type === "group") {
|
|
6022
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6023
|
+
continue;
|
|
6024
|
+
}
|
|
6025
|
+
if (field.type === "sub-tabs") {
|
|
6026
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6027
|
+
continue;
|
|
6028
|
+
}
|
|
6029
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6030
|
+
}
|
|
6031
|
+
return collected;
|
|
6032
|
+
}
|
|
6033
|
+
/**
|
|
5872
6034
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5873
6035
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5874
6036
|
* envelopes pass through; void stays void.
|
|
@@ -6276,6 +6438,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6276
6438
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6277
6439
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6278
6440
|
DeviceType["Image"] = "image";
|
|
6441
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6442
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6443
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6444
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6445
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6446
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6447
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6279
6448
|
return DeviceType;
|
|
6280
6449
|
}({});
|
|
6281
6450
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7424,6 +7593,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7424
7593
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7425
7594
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7426
7595
|
/**
|
|
7596
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7597
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7598
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7599
|
+
*/
|
|
7600
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7601
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7602
|
+
var ExpressionParseError = class extends Error {
|
|
7603
|
+
position;
|
|
7604
|
+
constructor(message, position) {
|
|
7605
|
+
super(message);
|
|
7606
|
+
this.name = "ExpressionParseError";
|
|
7607
|
+
this.position = position;
|
|
7608
|
+
}
|
|
7609
|
+
};
|
|
7610
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7611
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7612
|
+
var ExpressionEvalError = class extends Error {
|
|
7613
|
+
constructor(message) {
|
|
7614
|
+
super(message);
|
|
7615
|
+
this.name = "ExpressionEvalError";
|
|
7616
|
+
}
|
|
7617
|
+
};
|
|
7618
|
+
/**
|
|
7619
|
+
* Resource-bound constants for the safe expression engine.
|
|
7620
|
+
*
|
|
7621
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7622
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7623
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7624
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7625
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7626
|
+
*/
|
|
7627
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7628
|
+
* rejected without allocation. */
|
|
7629
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7630
|
+
/** A legal binding / identifier name. */
|
|
7631
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7632
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7633
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7634
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7635
|
+
"now",
|
|
7636
|
+
"true",
|
|
7637
|
+
"false",
|
|
7638
|
+
"null"
|
|
7639
|
+
]);
|
|
7640
|
+
/**
|
|
7641
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7642
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7643
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7644
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7645
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7646
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7647
|
+
* template literals are lexically impossible.
|
|
7648
|
+
*/
|
|
7649
|
+
var KEYWORDS = new Set([
|
|
7650
|
+
"true",
|
|
7651
|
+
"false",
|
|
7652
|
+
"null"
|
|
7653
|
+
]);
|
|
7654
|
+
function isDigit(ch) {
|
|
7655
|
+
return ch >= "0" && ch <= "9";
|
|
7656
|
+
}
|
|
7657
|
+
function isIdentStart(ch) {
|
|
7658
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7659
|
+
}
|
|
7660
|
+
function isIdentPart(ch) {
|
|
7661
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7662
|
+
}
|
|
7663
|
+
function isWhitespace(ch) {
|
|
7664
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7665
|
+
}
|
|
7666
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7667
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7668
|
+
* string. */
|
|
7669
|
+
function tokenize(source) {
|
|
7670
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7671
|
+
const tokens = [];
|
|
7672
|
+
let i = 0;
|
|
7673
|
+
const n = source.length;
|
|
7674
|
+
while (i < n) {
|
|
7675
|
+
const ch = source[i];
|
|
7676
|
+
if (isWhitespace(ch)) {
|
|
7677
|
+
i += 1;
|
|
7678
|
+
continue;
|
|
7679
|
+
}
|
|
7680
|
+
if (isDigit(ch)) {
|
|
7681
|
+
const start = i;
|
|
7682
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7683
|
+
if (i < n && source[i] === ".") {
|
|
7684
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7685
|
+
i += 1;
|
|
7686
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7687
|
+
}
|
|
7688
|
+
const text = source.slice(start, i);
|
|
7689
|
+
const value = Number(text);
|
|
7690
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7691
|
+
tokens.push({
|
|
7692
|
+
type: "number",
|
|
7693
|
+
value,
|
|
7694
|
+
pos: start
|
|
7695
|
+
});
|
|
7696
|
+
continue;
|
|
7697
|
+
}
|
|
7698
|
+
if (ch === "'" || ch === "\"") {
|
|
7699
|
+
const quote = ch;
|
|
7700
|
+
const start = i;
|
|
7701
|
+
i += 1;
|
|
7702
|
+
let out = "";
|
|
7703
|
+
let closed = false;
|
|
7704
|
+
while (i < n) {
|
|
7705
|
+
const c = source[i];
|
|
7706
|
+
if (c === "\\") {
|
|
7707
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7708
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7709
|
+
out += next;
|
|
7710
|
+
i += 2;
|
|
7711
|
+
continue;
|
|
7712
|
+
}
|
|
7713
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7714
|
+
}
|
|
7715
|
+
if (c === quote) {
|
|
7716
|
+
closed = true;
|
|
7717
|
+
i += 1;
|
|
7718
|
+
break;
|
|
7719
|
+
}
|
|
7720
|
+
out += c;
|
|
7721
|
+
i += 1;
|
|
7722
|
+
}
|
|
7723
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7724
|
+
tokens.push({
|
|
7725
|
+
type: "string",
|
|
7726
|
+
value: out,
|
|
7727
|
+
pos: start
|
|
7728
|
+
});
|
|
7729
|
+
continue;
|
|
7730
|
+
}
|
|
7731
|
+
if (isIdentStart(ch)) {
|
|
7732
|
+
const start = i;
|
|
7733
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7734
|
+
const text = source.slice(start, i);
|
|
7735
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7736
|
+
type: "keyword",
|
|
7737
|
+
keyword: keywordOf(text),
|
|
7738
|
+
pos: start
|
|
7739
|
+
});
|
|
7740
|
+
else tokens.push({
|
|
7741
|
+
type: "identifier",
|
|
7742
|
+
name: text,
|
|
7743
|
+
pos: start
|
|
7744
|
+
});
|
|
7745
|
+
continue;
|
|
7746
|
+
}
|
|
7747
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7748
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7749
|
+
tokens.push({
|
|
7750
|
+
type: "punct",
|
|
7751
|
+
punct: two,
|
|
7752
|
+
pos: i
|
|
7753
|
+
});
|
|
7754
|
+
i += 2;
|
|
7755
|
+
continue;
|
|
7756
|
+
}
|
|
7757
|
+
if (isSinglePunct(ch)) {
|
|
7758
|
+
tokens.push({
|
|
7759
|
+
type: "punct",
|
|
7760
|
+
punct: ch,
|
|
7761
|
+
pos: i
|
|
7762
|
+
});
|
|
7763
|
+
i += 1;
|
|
7764
|
+
continue;
|
|
7765
|
+
}
|
|
7766
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7767
|
+
}
|
|
7768
|
+
tokens.push({
|
|
7769
|
+
type: "eof",
|
|
7770
|
+
pos: n
|
|
7771
|
+
});
|
|
7772
|
+
return tokens;
|
|
7773
|
+
}
|
|
7774
|
+
function keywordOf(text) {
|
|
7775
|
+
if (text === "true") return "true";
|
|
7776
|
+
if (text === "false") return "false";
|
|
7777
|
+
return "null";
|
|
7778
|
+
}
|
|
7779
|
+
function isSinglePunct(ch) {
|
|
7780
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7781
|
+
}
|
|
7782
|
+
/**
|
|
7783
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7784
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7785
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7786
|
+
* own-property check against it.
|
|
7787
|
+
*
|
|
7788
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7789
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7790
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7791
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7792
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7793
|
+
*
|
|
7794
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7795
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7796
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7797
|
+
* closed rather than emitting a garbage value.
|
|
7798
|
+
*/
|
|
7799
|
+
function asFiniteNumber(value, name, index) {
|
|
7800
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7801
|
+
return value;
|
|
7802
|
+
}
|
|
7803
|
+
function asString$1(value, name, index) {
|
|
7804
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7805
|
+
return value;
|
|
7806
|
+
}
|
|
7807
|
+
function finiteResult(value, name) {
|
|
7808
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7809
|
+
return value;
|
|
7810
|
+
}
|
|
7811
|
+
function allFiniteNumbers(args, name) {
|
|
7812
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7813
|
+
}
|
|
7814
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7815
|
+
var table = {
|
|
7816
|
+
min: {
|
|
7817
|
+
minArgs: 1,
|
|
7818
|
+
maxArgs: INF,
|
|
7819
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7820
|
+
},
|
|
7821
|
+
max: {
|
|
7822
|
+
minArgs: 1,
|
|
7823
|
+
maxArgs: INF,
|
|
7824
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7825
|
+
},
|
|
7826
|
+
abs: {
|
|
7827
|
+
minArgs: 1,
|
|
7828
|
+
maxArgs: 1,
|
|
7829
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7830
|
+
},
|
|
7831
|
+
floor: {
|
|
7832
|
+
minArgs: 1,
|
|
7833
|
+
maxArgs: 1,
|
|
7834
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7835
|
+
},
|
|
7836
|
+
ceil: {
|
|
7837
|
+
minArgs: 1,
|
|
7838
|
+
maxArgs: 1,
|
|
7839
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7840
|
+
},
|
|
7841
|
+
sqrt: {
|
|
7842
|
+
minArgs: 1,
|
|
7843
|
+
maxArgs: 1,
|
|
7844
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7845
|
+
},
|
|
7846
|
+
round: {
|
|
7847
|
+
minArgs: 1,
|
|
7848
|
+
maxArgs: 2,
|
|
7849
|
+
apply: (args) => {
|
|
7850
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7851
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7852
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7853
|
+
const factor = 10 ** digits;
|
|
7854
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7855
|
+
}
|
|
7856
|
+
},
|
|
7857
|
+
pow: {
|
|
7858
|
+
minArgs: 2,
|
|
7859
|
+
maxArgs: 2,
|
|
7860
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7861
|
+
},
|
|
7862
|
+
clamp: {
|
|
7863
|
+
minArgs: 3,
|
|
7864
|
+
maxArgs: 3,
|
|
7865
|
+
apply: (args) => {
|
|
7866
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7867
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7868
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7869
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7870
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7871
|
+
}
|
|
7872
|
+
},
|
|
7873
|
+
avg: {
|
|
7874
|
+
minArgs: 1,
|
|
7875
|
+
maxArgs: INF,
|
|
7876
|
+
apply: (args) => {
|
|
7877
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7878
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7879
|
+
}
|
|
7880
|
+
},
|
|
7881
|
+
sum: {
|
|
7882
|
+
minArgs: 1,
|
|
7883
|
+
maxArgs: INF,
|
|
7884
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7885
|
+
},
|
|
7886
|
+
coalesce: {
|
|
7887
|
+
minArgs: 1,
|
|
7888
|
+
maxArgs: INF,
|
|
7889
|
+
apply: (args) => {
|
|
7890
|
+
for (const a of args) if (a !== null) return a;
|
|
7891
|
+
return null;
|
|
7892
|
+
}
|
|
7893
|
+
},
|
|
7894
|
+
age: {
|
|
7895
|
+
minArgs: 2,
|
|
7896
|
+
maxArgs: 2,
|
|
7897
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7898
|
+
},
|
|
7899
|
+
convert: {
|
|
7900
|
+
minArgs: 3,
|
|
7901
|
+
maxArgs: 3,
|
|
7902
|
+
apply: (args, hooks) => {
|
|
7903
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7904
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7905
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7906
|
+
if (hooks.convert) {
|
|
7907
|
+
const out = hooks.convert(x, from, to);
|
|
7908
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7909
|
+
return finiteResult(out, "convert");
|
|
7910
|
+
}
|
|
7911
|
+
if (from === to) return x;
|
|
7912
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7913
|
+
}
|
|
7914
|
+
}
|
|
7915
|
+
};
|
|
7916
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7917
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7918
|
+
* callees at parse time (immediate author feedback). */
|
|
7919
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7920
|
+
/**
|
|
7921
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7922
|
+
*
|
|
7923
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7924
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7925
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7926
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7927
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7928
|
+
* that references a since-removed builtin degrades at read.
|
|
7929
|
+
*
|
|
7930
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7931
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7932
|
+
*/
|
|
7933
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7934
|
+
var BINARY_PRECEDENCE = {
|
|
7935
|
+
"||": 1,
|
|
7936
|
+
"&&": 2,
|
|
7937
|
+
"==": 3,
|
|
7938
|
+
"!=": 3,
|
|
7939
|
+
"<": 4,
|
|
7940
|
+
"<=": 4,
|
|
7941
|
+
">": 4,
|
|
7942
|
+
">=": 4,
|
|
7943
|
+
"+": 5,
|
|
7944
|
+
"-": 5,
|
|
7945
|
+
"*": 6,
|
|
7946
|
+
"/": 6,
|
|
7947
|
+
"%": 6
|
|
7948
|
+
};
|
|
7949
|
+
function isLogicalOp(op) {
|
|
7950
|
+
return op === "&&" || op === "||";
|
|
7951
|
+
}
|
|
7952
|
+
function isBinaryOp(op) {
|
|
7953
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7954
|
+
}
|
|
7955
|
+
var Parser = class {
|
|
7956
|
+
tokens;
|
|
7957
|
+
pos = 0;
|
|
7958
|
+
nodeCount = 0;
|
|
7959
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7960
|
+
callees = /* @__PURE__ */ new Set();
|
|
7961
|
+
constructor(tokens) {
|
|
7962
|
+
this.tokens = tokens;
|
|
7963
|
+
}
|
|
7964
|
+
parse() {
|
|
7965
|
+
const ast = this.parseTernary();
|
|
7966
|
+
const tok = this.peek();
|
|
7967
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
7968
|
+
return {
|
|
7969
|
+
ast,
|
|
7970
|
+
identifiers: this.identifiers,
|
|
7971
|
+
callees: this.callees,
|
|
7972
|
+
nodeCount: this.nodeCount
|
|
7973
|
+
};
|
|
7974
|
+
}
|
|
7975
|
+
peek() {
|
|
7976
|
+
return this.tokens[this.pos];
|
|
7977
|
+
}
|
|
7978
|
+
next() {
|
|
7979
|
+
return this.tokens[this.pos++];
|
|
7980
|
+
}
|
|
7981
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
7982
|
+
expectPunct(punct) {
|
|
7983
|
+
const tok = this.peek();
|
|
7984
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
7985
|
+
this.pos += 1;
|
|
7986
|
+
}
|
|
7987
|
+
matchPunct(punct) {
|
|
7988
|
+
const tok = this.peek();
|
|
7989
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
7990
|
+
this.pos += 1;
|
|
7991
|
+
return true;
|
|
7992
|
+
}
|
|
7993
|
+
return false;
|
|
7994
|
+
}
|
|
7995
|
+
countNode() {
|
|
7996
|
+
this.nodeCount += 1;
|
|
7997
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
7998
|
+
}
|
|
7999
|
+
parseTernary() {
|
|
8000
|
+
const test = this.parseBinary(1);
|
|
8001
|
+
if (this.matchPunct("?")) {
|
|
8002
|
+
const consequent = this.parseTernary();
|
|
8003
|
+
this.expectPunct(":");
|
|
8004
|
+
const alternate = this.parseTernary();
|
|
8005
|
+
this.countNode();
|
|
8006
|
+
return {
|
|
8007
|
+
kind: "conditional",
|
|
8008
|
+
test,
|
|
8009
|
+
consequent,
|
|
8010
|
+
alternate
|
|
8011
|
+
};
|
|
8012
|
+
}
|
|
8013
|
+
return test;
|
|
8014
|
+
}
|
|
8015
|
+
parseBinary(minPrec) {
|
|
8016
|
+
let left = this.parseUnary();
|
|
8017
|
+
for (;;) {
|
|
8018
|
+
const tok = this.peek();
|
|
8019
|
+
if (tok.type !== "punct") break;
|
|
8020
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8021
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8022
|
+
const op = tok.punct;
|
|
8023
|
+
this.pos += 1;
|
|
8024
|
+
const right = this.parseBinary(prec + 1);
|
|
8025
|
+
this.countNode();
|
|
8026
|
+
if (isLogicalOp(op)) left = {
|
|
8027
|
+
kind: "logical",
|
|
8028
|
+
op,
|
|
8029
|
+
left,
|
|
8030
|
+
right
|
|
8031
|
+
};
|
|
8032
|
+
else if (isBinaryOp(op)) left = {
|
|
8033
|
+
kind: "binary",
|
|
8034
|
+
op,
|
|
8035
|
+
left,
|
|
8036
|
+
right
|
|
8037
|
+
};
|
|
8038
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8039
|
+
}
|
|
8040
|
+
return left;
|
|
8041
|
+
}
|
|
8042
|
+
parseUnary() {
|
|
8043
|
+
const tok = this.peek();
|
|
8044
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8045
|
+
const op = tok.punct;
|
|
8046
|
+
this.pos += 1;
|
|
8047
|
+
const operand = this.parseUnary();
|
|
8048
|
+
this.countNode();
|
|
8049
|
+
return {
|
|
8050
|
+
kind: "unary",
|
|
8051
|
+
op,
|
|
8052
|
+
operand
|
|
8053
|
+
};
|
|
8054
|
+
}
|
|
8055
|
+
return this.parsePrimary();
|
|
8056
|
+
}
|
|
8057
|
+
parsePrimary() {
|
|
8058
|
+
const tok = this.next();
|
|
8059
|
+
switch (tok.type) {
|
|
8060
|
+
case "number":
|
|
8061
|
+
this.countNode();
|
|
8062
|
+
return {
|
|
8063
|
+
kind: "literal",
|
|
8064
|
+
value: tok.value
|
|
8065
|
+
};
|
|
8066
|
+
case "string":
|
|
8067
|
+
this.countNode();
|
|
8068
|
+
return {
|
|
8069
|
+
kind: "literal",
|
|
8070
|
+
value: tok.value
|
|
8071
|
+
};
|
|
8072
|
+
case "keyword":
|
|
8073
|
+
this.countNode();
|
|
8074
|
+
return {
|
|
8075
|
+
kind: "literal",
|
|
8076
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8077
|
+
};
|
|
8078
|
+
case "identifier": {
|
|
8079
|
+
const nextTok = this.peek();
|
|
8080
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8081
|
+
this.identifiers.add(tok.name);
|
|
8082
|
+
this.countNode();
|
|
8083
|
+
return {
|
|
8084
|
+
kind: "identifier",
|
|
8085
|
+
name: tok.name
|
|
8086
|
+
};
|
|
8087
|
+
}
|
|
8088
|
+
case "punct":
|
|
8089
|
+
if (tok.punct === "(") {
|
|
8090
|
+
const inner = this.parseTernary();
|
|
8091
|
+
this.expectPunct(")");
|
|
8092
|
+
return inner;
|
|
8093
|
+
}
|
|
8094
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8095
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8096
|
+
}
|
|
8097
|
+
}
|
|
8098
|
+
parseCall(callee, pos) {
|
|
8099
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8100
|
+
this.expectPunct("(");
|
|
8101
|
+
const args = [];
|
|
8102
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8103
|
+
args.push(this.parseTernary());
|
|
8104
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8105
|
+
if (this.matchPunct(",")) continue;
|
|
8106
|
+
this.expectPunct(")");
|
|
8107
|
+
break;
|
|
8108
|
+
}
|
|
8109
|
+
this.callees.add(callee);
|
|
8110
|
+
this.countNode();
|
|
8111
|
+
return {
|
|
8112
|
+
kind: "call",
|
|
8113
|
+
callee,
|
|
8114
|
+
args
|
|
8115
|
+
};
|
|
8116
|
+
}
|
|
8117
|
+
};
|
|
8118
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8119
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8120
|
+
function parseExpression(source) {
|
|
8121
|
+
return new Parser(tokenize(source)).parse();
|
|
8122
|
+
}
|
|
8123
|
+
Object.freeze({});
|
|
8124
|
+
/**
|
|
8125
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8126
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8127
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8128
|
+
* one per read on a hot resolve path.
|
|
8129
|
+
*
|
|
8130
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8131
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8132
|
+
* callers is safe and maximises hit rate.
|
|
8133
|
+
*/
|
|
8134
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8135
|
+
function getCached(source) {
|
|
8136
|
+
const hit = cache.get(source);
|
|
8137
|
+
if (hit !== void 0) {
|
|
8138
|
+
cache.delete(source);
|
|
8139
|
+
cache.set(source, hit);
|
|
8140
|
+
return hit;
|
|
8141
|
+
}
|
|
8142
|
+
let result;
|
|
8143
|
+
try {
|
|
8144
|
+
result = {
|
|
8145
|
+
ok: true,
|
|
8146
|
+
parsed: parseExpression(source)
|
|
8147
|
+
};
|
|
8148
|
+
} catch (err) {
|
|
8149
|
+
result = {
|
|
8150
|
+
ok: false,
|
|
8151
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
cache.set(source, result);
|
|
8155
|
+
if (cache.size > 256) {
|
|
8156
|
+
const oldest = cache.keys().next().value;
|
|
8157
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8158
|
+
}
|
|
8159
|
+
return result;
|
|
8160
|
+
}
|
|
8161
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8162
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8163
|
+
function compileExpressionSafe(source) {
|
|
8164
|
+
return getCached(source);
|
|
8165
|
+
}
|
|
8166
|
+
/**
|
|
8167
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8168
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8169
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8170
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8171
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8172
|
+
*/
|
|
8173
|
+
function validateExpressionSource(src) {
|
|
8174
|
+
const names = Object.keys(src.bindings);
|
|
8175
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8176
|
+
for (const name of names) {
|
|
8177
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8178
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8179
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8180
|
+
}
|
|
8181
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8182
|
+
if (!compiled.ok) return compiled.error;
|
|
8183
|
+
const bound = new Set(names);
|
|
8184
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8185
|
+
if (id === "now") continue;
|
|
8186
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8187
|
+
}
|
|
8188
|
+
return null;
|
|
8189
|
+
}
|
|
8190
|
+
/**
|
|
7427
8191
|
* Accessory device helpers — shared across drivers.
|
|
7428
8192
|
*
|
|
7429
8193
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -9519,7 +10283,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
9519
10283
|
});
|
|
9520
10284
|
method(object({
|
|
9521
10285
|
deviceId: number(),
|
|
9522
|
-
frame: FrameInputSchema
|
|
10286
|
+
frame: FrameInputSchema.optional(),
|
|
10287
|
+
frameHandle: FrameHandleSchema.optional()
|
|
9523
10288
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
9524
10289
|
deviceId: number(),
|
|
9525
10290
|
detected: boolean(),
|
|
@@ -9766,6 +10531,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
9766
10531
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
9767
10532
|
steps: array(PipelineStepInputSchema).min(1),
|
|
9768
10533
|
frame: FrameInputSchema.optional(),
|
|
10534
|
+
/**
|
|
10535
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
10536
|
+
* the decoded pixels live in. One more member of the one-of
|
|
10537
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
10538
|
+
*/
|
|
10539
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
9769
10540
|
imageBase64: string().optional(),
|
|
9770
10541
|
/**
|
|
9771
10542
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -9975,6 +10746,31 @@ var ReportMotionInputSchema = object({
|
|
|
9975
10746
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
9976
10747
|
});
|
|
9977
10748
|
/**
|
|
10749
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
10750
|
+
* restream-owner model — P2c).
|
|
10751
|
+
*
|
|
10752
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
10753
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
10754
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
10755
|
+
* behavior change.
|
|
10756
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
10757
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
10758
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
10759
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
10760
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
10761
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
10762
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
10763
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
10764
|
+
* dials for the owner's restream.
|
|
10765
|
+
*/
|
|
10766
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
10767
|
+
kind: literal("remote-restream"),
|
|
10768
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
10769
|
+
ownerNodeId: string(),
|
|
10770
|
+
/** Operator override for the owner host the runner dials. */
|
|
10771
|
+
hubHostnameOverride: string().optional()
|
|
10772
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
10773
|
+
/**
|
|
9978
10774
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
9979
10775
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
9980
10776
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -10072,7 +10868,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
10072
10868
|
*/
|
|
10073
10869
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
10074
10870
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
10075
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
10871
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
10872
|
+
/**
|
|
10873
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
10874
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
10875
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
10876
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
10877
|
+
* `remoteSourcingNodes` rollout setting).
|
|
10878
|
+
*/
|
|
10879
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
10076
10880
|
});
|
|
10077
10881
|
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;
|
|
10078
10882
|
/**
|
|
@@ -10437,6 +11241,113 @@ object({
|
|
|
10437
11241
|
lastFetchedAt: number()
|
|
10438
11242
|
});
|
|
10439
11243
|
DeviceType.Sensor;
|
|
11244
|
+
/**
|
|
11245
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
11246
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
11247
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
11248
|
+
*/
|
|
11249
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
11250
|
+
"normal",
|
|
11251
|
+
"offline",
|
|
11252
|
+
"on_batteries"
|
|
11253
|
+
]);
|
|
11254
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
11255
|
+
object({
|
|
11256
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
11257
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
11258
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
11259
|
+
foodLevel: number().nullable(),
|
|
11260
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
11261
|
+
* single-hopper models. */
|
|
11262
|
+
food1: number().nullable(),
|
|
11263
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
11264
|
+
* single-hopper models. */
|
|
11265
|
+
food2: number().nullable(),
|
|
11266
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
11267
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
11268
|
+
* below the feeder's low threshold. */
|
|
11269
|
+
lowFood: boolean(),
|
|
11270
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
11271
|
+
* device has no battery reading. */
|
|
11272
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
11273
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
11274
|
+
* desiccant sensor. */
|
|
11275
|
+
desiccantLeftDays: number().nullable(),
|
|
11276
|
+
/** True while a feed is in progress. */
|
|
11277
|
+
feeding: boolean(),
|
|
11278
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
11279
|
+
* Null until the device has reported a status. */
|
|
11280
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
11281
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
11282
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
11283
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
11284
|
+
error: string().nullable(),
|
|
11285
|
+
/** Raw device error code (0 / null = no error). */
|
|
11286
|
+
errorCode: number().nullable(),
|
|
11287
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
11288
|
+
isDualHopper: boolean(),
|
|
11289
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
11290
|
+
childLock: boolean(),
|
|
11291
|
+
/** Front indicator-light setting. */
|
|
11292
|
+
indicatorLight: boolean(),
|
|
11293
|
+
/** Play a chime when dispensing. */
|
|
11294
|
+
feedSound: boolean(),
|
|
11295
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
11296
|
+
volume: number(),
|
|
11297
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
11298
|
+
lastFetchedAt: number()
|
|
11299
|
+
});
|
|
11300
|
+
DeviceType.PetFeeder, method(object({
|
|
11301
|
+
deviceId: number().int().nonnegative(),
|
|
11302
|
+
grams: gramsPortion.optional(),
|
|
11303
|
+
hopper1: gramsPortion.optional(),
|
|
11304
|
+
hopper2: gramsPortion.optional()
|
|
11305
|
+
}), _void(), {
|
|
11306
|
+
kind: "mutation",
|
|
11307
|
+
auth: "admin"
|
|
11308
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11309
|
+
kind: "mutation",
|
|
11310
|
+
auth: "admin"
|
|
11311
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11312
|
+
kind: "mutation",
|
|
11313
|
+
auth: "admin"
|
|
11314
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11315
|
+
kind: "mutation",
|
|
11316
|
+
auth: "admin"
|
|
11317
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11318
|
+
kind: "mutation",
|
|
11319
|
+
auth: "admin"
|
|
11320
|
+
}), method(object({
|
|
11321
|
+
deviceId: number().int().nonnegative(),
|
|
11322
|
+
soundId: number().int().nonnegative()
|
|
11323
|
+
}), _void(), {
|
|
11324
|
+
kind: "mutation",
|
|
11325
|
+
auth: "admin"
|
|
11326
|
+
}), method(object({
|
|
11327
|
+
deviceId: number().int().nonnegative(),
|
|
11328
|
+
on: boolean()
|
|
11329
|
+
}), _void(), {
|
|
11330
|
+
kind: "mutation",
|
|
11331
|
+
auth: "admin"
|
|
11332
|
+
}), method(object({
|
|
11333
|
+
deviceId: number().int().nonnegative(),
|
|
11334
|
+
on: boolean()
|
|
11335
|
+
}), _void(), {
|
|
11336
|
+
kind: "mutation",
|
|
11337
|
+
auth: "admin"
|
|
11338
|
+
}), method(object({
|
|
11339
|
+
deviceId: number().int().nonnegative(),
|
|
11340
|
+
on: boolean()
|
|
11341
|
+
}), _void(), {
|
|
11342
|
+
kind: "mutation",
|
|
11343
|
+
auth: "admin"
|
|
11344
|
+
}), method(object({
|
|
11345
|
+
deviceId: number().int().nonnegative(),
|
|
11346
|
+
level: number().int().nonnegative()
|
|
11347
|
+
}), _void(), {
|
|
11348
|
+
kind: "mutation",
|
|
11349
|
+
auth: "admin"
|
|
11350
|
+
});
|
|
10440
11351
|
object({
|
|
10441
11352
|
/** Instantaneous power draw in watts. */
|
|
10442
11353
|
watts: number().optional(),
|
|
@@ -12264,10 +13175,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
12264
13175
|
url: string()
|
|
12265
13176
|
}), _void()), method(object({
|
|
12266
13177
|
sessionId: string(),
|
|
12267
|
-
maxCount: number().default(1)
|
|
13178
|
+
maxCount: number().default(1),
|
|
13179
|
+
waitMs: number().optional()
|
|
12268
13180
|
}), array(DecodedFrameSchema)), method(object({
|
|
12269
13181
|
sessionId: string(),
|
|
12270
|
-
maxCount: number().default(1)
|
|
13182
|
+
maxCount: number().default(1),
|
|
13183
|
+
waitMs: number().optional()
|
|
12271
13184
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
12272
13185
|
sessionId: string(),
|
|
12273
13186
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -12554,14 +13467,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
12554
13467
|
collapsed: boolean().optional()
|
|
12555
13468
|
});
|
|
12556
13469
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
12557
|
-
* `device-management.ts`.
|
|
13470
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
13471
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
13472
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
13473
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
13474
|
+
* source device's full re-sync-stable `stableId`. */
|
|
13475
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
13476
|
+
kind: literal("field").optional(),
|
|
13477
|
+
sourceKey: string(),
|
|
13478
|
+
cap: string(),
|
|
13479
|
+
fieldPath: string()
|
|
13480
|
+
});
|
|
13481
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
13482
|
+
kind: literal("literal"),
|
|
13483
|
+
value: union([
|
|
13484
|
+
string(),
|
|
13485
|
+
number(),
|
|
13486
|
+
boolean(),
|
|
13487
|
+
_null()
|
|
13488
|
+
])
|
|
13489
|
+
});
|
|
13490
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
13491
|
+
kind: literal("global"),
|
|
13492
|
+
sourceStableId: string(),
|
|
13493
|
+
cap: string(),
|
|
13494
|
+
fieldPath: string()
|
|
13495
|
+
});
|
|
13496
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
13497
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
13498
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
13499
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
13500
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
13501
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
13502
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
13503
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
13504
|
+
kind: literal("expression"),
|
|
13505
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
13506
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
13507
|
+
DeviceLinkFieldSourceSchema,
|
|
13508
|
+
DeviceLinkLiteralSourceSchema,
|
|
13509
|
+
DeviceLinkGlobalSourceSchema
|
|
13510
|
+
]))
|
|
13511
|
+
}).superRefine((src, ctx) => {
|
|
13512
|
+
const err = validateExpressionSource(src);
|
|
13513
|
+
if (err !== null) ctx.addIssue({
|
|
13514
|
+
code: "custom",
|
|
13515
|
+
message: err,
|
|
13516
|
+
path: ["expr"]
|
|
13517
|
+
});
|
|
13518
|
+
});
|
|
12558
13519
|
var DeviceLinkSchema = object({
|
|
12559
13520
|
id: string(),
|
|
12560
|
-
source:
|
|
12561
|
-
|
|
12562
|
-
|
|
12563
|
-
|
|
12564
|
-
|
|
13521
|
+
source: union([
|
|
13522
|
+
DeviceLinkFieldSourceSchema,
|
|
13523
|
+
DeviceLinkLiteralSourceSchema,
|
|
13524
|
+
DeviceLinkGlobalSourceSchema,
|
|
13525
|
+
DeviceLinkExpressionSourceSchema
|
|
13526
|
+
]),
|
|
12565
13527
|
target: object({
|
|
12566
13528
|
cap: string(),
|
|
12567
13529
|
fieldPath: string(),
|
|
@@ -12590,6 +13552,31 @@ var DeviceLinkSchema = object({
|
|
|
12590
13552
|
})
|
|
12591
13553
|
]).optional()
|
|
12592
13554
|
});
|
|
13555
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
13556
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
13557
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
13558
|
+
unit: string().min(1).optional(),
|
|
13559
|
+
precision: number().int().min(0).max(10).optional()
|
|
13560
|
+
});
|
|
13561
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
13562
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
13563
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
13564
|
+
var DeviceDisplayOverrideSchema = object({
|
|
13565
|
+
icon: string().min(1).optional(),
|
|
13566
|
+
label: string().min(1).optional(),
|
|
13567
|
+
unit: string().min(1).optional(),
|
|
13568
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13569
|
+
hidden: boolean().optional(),
|
|
13570
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
13571
|
+
});
|
|
13572
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
13573
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
13574
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
13575
|
+
var RoleDisplayDefaultSchema = object({
|
|
13576
|
+
unit: string().min(1).optional(),
|
|
13577
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13578
|
+
icon: string().min(1).optional()
|
|
13579
|
+
});
|
|
12593
13580
|
/**
|
|
12594
13581
|
* Serializable projection of a live IDevice.
|
|
12595
13582
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -12645,7 +13632,9 @@ var DeviceInfoSchema = object({
|
|
|
12645
13632
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
12646
13633
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
12647
13634
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
12648
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
13635
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
13636
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13637
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12649
13638
|
});
|
|
12650
13639
|
var ConfigEntrySchema = object({
|
|
12651
13640
|
key: string(),
|
|
@@ -12710,7 +13699,9 @@ var DeviceMetaSchema = object({
|
|
|
12710
13699
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
12711
13700
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
12712
13701
|
* Optional: only present for accessory children that carry a known role. */
|
|
12713
|
-
role: string().nullable().optional()
|
|
13702
|
+
role: string().nullable().optional(),
|
|
13703
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13704
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12714
13705
|
});
|
|
12715
13706
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
12716
13707
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -12804,7 +13795,19 @@ method(object({
|
|
|
12804
13795
|
}), _void(), {
|
|
12805
13796
|
kind: "mutation",
|
|
12806
13797
|
auth: "admin"
|
|
12807
|
-
}), method(object({
|
|
13798
|
+
}), method(object({
|
|
13799
|
+
deviceId: number(),
|
|
13800
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
13801
|
+
}), _void(), {
|
|
13802
|
+
kind: "mutation",
|
|
13803
|
+
auth: "admin"
|
|
13804
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
13805
|
+
kind: "mutation",
|
|
13806
|
+
auth: "admin"
|
|
13807
|
+
}), method(object({
|
|
13808
|
+
deviceId: number(),
|
|
13809
|
+
includeSynthesizable: boolean().optional()
|
|
13810
|
+
}), object({ caps: array(object({
|
|
12808
13811
|
cap: string(),
|
|
12809
13812
|
fields: array(object({
|
|
12810
13813
|
path: string(),
|
|
@@ -12814,8 +13817,13 @@ method(object({
|
|
|
12814
13817
|
"boolean",
|
|
12815
13818
|
"enum"
|
|
12816
13819
|
]),
|
|
12817
|
-
enumValues: array(string()).optional()
|
|
12818
|
-
|
|
13820
|
+
enumValues: array(string()).optional(),
|
|
13821
|
+
item: boolean().optional()
|
|
13822
|
+
})).readonly(),
|
|
13823
|
+
itemArray: object({
|
|
13824
|
+
path: string(),
|
|
13825
|
+
keyField: string()
|
|
13826
|
+
}).optional()
|
|
12819
13827
|
})).readonly() }), { kind: "query" }), method(object({
|
|
12820
13828
|
deviceId: number(),
|
|
12821
13829
|
role: string().nullable()
|
|
@@ -12885,7 +13893,11 @@ method(object({
|
|
|
12885
13893
|
deviceId: number(),
|
|
12886
13894
|
entries: array(object({
|
|
12887
13895
|
capName: string(),
|
|
12888
|
-
kind: _enum([
|
|
13896
|
+
kind: _enum([
|
|
13897
|
+
"native",
|
|
13898
|
+
"wrapped",
|
|
13899
|
+
"linked"
|
|
13900
|
+
]),
|
|
12889
13901
|
providerAddonId: string(),
|
|
12890
13902
|
providerNodeId: string(),
|
|
12891
13903
|
nativeAddonId: string()
|
|
@@ -12894,7 +13906,11 @@ method(object({
|
|
|
12894
13906
|
deviceId: number(),
|
|
12895
13907
|
entries: array(object({
|
|
12896
13908
|
capName: string(),
|
|
12897
|
-
kind: _enum([
|
|
13909
|
+
kind: _enum([
|
|
13910
|
+
"native",
|
|
13911
|
+
"wrapped",
|
|
13912
|
+
"linked"
|
|
13913
|
+
]),
|
|
12898
13914
|
providerAddonId: string(),
|
|
12899
13915
|
providerNodeId: string(),
|
|
12900
13916
|
nativeAddonId: string()
|
|
@@ -14150,7 +15166,10 @@ var AgentLoadSummarySchema = object({
|
|
|
14150
15166
|
online: boolean(),
|
|
14151
15167
|
load: RunnerLocalLoadSchema,
|
|
14152
15168
|
/** Computed score used by the L2 capacity balancer (lower = less loaded). */
|
|
14153
|
-
score: number()
|
|
15169
|
+
score: number(),
|
|
15170
|
+
/** This node's decode hwaccel backend (per-node `probedBestHwaccel`), or null
|
|
15171
|
+
* when not yet probed — for the cluster Pipeline table UI (P0.2). */
|
|
15172
|
+
decodeHwaccel: string().nullable()
|
|
14154
15173
|
});
|
|
14155
15174
|
/**
|
|
14156
15175
|
* Aggregate metrics across the whole detection cluster. Replaces the legacy
|
|
@@ -16668,7 +17687,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
16668
17687
|
"webgpu",
|
|
16669
17688
|
"none"
|
|
16670
17689
|
]).nullable().optional();
|
|
16671
|
-
var HwAccelResolutionSchema = object({
|
|
17690
|
+
var HwAccelResolutionSchema = object({
|
|
17691
|
+
preferred: array(string()).readonly(),
|
|
17692
|
+
rationale: string()
|
|
17693
|
+
});
|
|
16672
17694
|
var HardwareEncoderIdSchema = _enum([
|
|
16673
17695
|
"h264_videotoolbox",
|
|
16674
17696
|
"hevc_videotoolbox",
|
|
@@ -16683,7 +17705,7 @@ var HardwareEncoderIdSchema = _enum([
|
|
|
16683
17705
|
"libx264",
|
|
16684
17706
|
"libx265"
|
|
16685
17707
|
]);
|
|
16686
|
-
|
|
17708
|
+
object({
|
|
16687
17709
|
encoders: array(object({
|
|
16688
17710
|
encoder: HardwareEncoderIdSchema,
|
|
16689
17711
|
codec: _enum(["H264", "H265"]),
|
|
@@ -16702,15 +17724,7 @@ var HardwareEncodersSchema = object({
|
|
|
16702
17724
|
defaultH265: HardwareEncoderIdSchema,
|
|
16703
17725
|
probedAt: number()
|
|
16704
17726
|
});
|
|
16705
|
-
|
|
16706
|
-
* Decode-side companion to {@link HardwareEncodersSchema}: the `-hwaccel`
|
|
16707
|
-
* methods the configured ffmpeg binary actually supports (parsed from
|
|
16708
|
-
* `ffmpeg -hwaccels`). Used to gate decode-hwaccel attempts so the transcode
|
|
16709
|
-
* egress never spends a spawn on a backend this build cannot offer. Per-stream
|
|
16710
|
-
* decode fragility (e.g. VideoToolbox HEVC) is still handled by the egress's
|
|
16711
|
-
* software fallback — this only filters out wholly-unsupported backends.
|
|
16712
|
-
*/
|
|
16713
|
-
var HardwareDecodeAccelsSchema = object({
|
|
17727
|
+
object({
|
|
16714
17728
|
methods: array(string()).readonly(),
|
|
16715
17729
|
probedAt: number()
|
|
16716
17730
|
});
|
|
@@ -16773,16 +17787,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
16773
17787
|
format: ModelFormatSchema,
|
|
16774
17788
|
reason: string()
|
|
16775
17789
|
});
|
|
16776
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
16777
|
-
prefer: HwAccelBackendInputSchema,
|
|
16778
|
-
nodeId: string().optional()
|
|
16779
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
16780
|
-
kind: "mutation",
|
|
16781
|
-
auth: "admin"
|
|
16782
|
-
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
16783
|
-
kind: "mutation",
|
|
16784
|
-
auth: "admin"
|
|
16785
|
-
});
|
|
17790
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema);
|
|
16786
17791
|
var PtzPresetSchema = object({
|
|
16787
17792
|
id: string(),
|
|
16788
17793
|
name: string()
|
|
@@ -16835,6 +17840,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
16835
17840
|
kind: "mutation",
|
|
16836
17841
|
auth: "admin"
|
|
16837
17842
|
});
|
|
17843
|
+
/**
|
|
17844
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
17845
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
17846
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
17847
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
17848
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
17849
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
17850
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
17851
|
+
* (`interfaces/recording-config.ts`).
|
|
17852
|
+
*/
|
|
16838
17853
|
var RecordingStatusSchema = object({
|
|
16839
17854
|
deviceId: number(),
|
|
16840
17855
|
enabled: boolean(),
|
|
@@ -18471,6 +19486,12 @@ Object.freeze({
|
|
|
18471
19486
|
addonId: null,
|
|
18472
19487
|
access: "view"
|
|
18473
19488
|
},
|
|
19489
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
19490
|
+
capName: "device-manager",
|
|
19491
|
+
capScope: "system",
|
|
19492
|
+
addonId: null,
|
|
19493
|
+
access: "view"
|
|
19494
|
+
},
|
|
18474
19495
|
"deviceManager.getSettingsSchema": {
|
|
18475
19496
|
capName: "device-manager",
|
|
18476
19497
|
capScope: "system",
|
|
@@ -18621,6 +19642,12 @@ Object.freeze({
|
|
|
18621
19642
|
addonId: null,
|
|
18622
19643
|
access: "create"
|
|
18623
19644
|
},
|
|
19645
|
+
"deviceManager.setDisplay": {
|
|
19646
|
+
capName: "device-manager",
|
|
19647
|
+
capScope: "system",
|
|
19648
|
+
addonId: null,
|
|
19649
|
+
access: "create"
|
|
19650
|
+
},
|
|
18624
19651
|
"deviceManager.setIntegrationId": {
|
|
18625
19652
|
capName: "device-manager",
|
|
18626
19653
|
capScope: "system",
|
|
@@ -18663,6 +19690,12 @@ Object.freeze({
|
|
|
18663
19690
|
addonId: null,
|
|
18664
19691
|
access: "create"
|
|
18665
19692
|
},
|
|
19693
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
19694
|
+
capName: "device-manager",
|
|
19695
|
+
capScope: "system",
|
|
19696
|
+
addonId: null,
|
|
19697
|
+
access: "create"
|
|
19698
|
+
},
|
|
18666
19699
|
"deviceManager.setStreamProfileMap": {
|
|
18667
19700
|
capName: "device-manager",
|
|
18668
19701
|
capScope: "system",
|
|
@@ -19713,6 +20746,66 @@ Object.freeze({
|
|
|
19713
20746
|
addonId: null,
|
|
19714
20747
|
access: "create"
|
|
19715
20748
|
},
|
|
20749
|
+
"petFeeder.callPet": {
|
|
20750
|
+
capName: "pet-feeder",
|
|
20751
|
+
capScope: "device",
|
|
20752
|
+
addonId: null,
|
|
20753
|
+
access: "create"
|
|
20754
|
+
},
|
|
20755
|
+
"petFeeder.cancelFeed": {
|
|
20756
|
+
capName: "pet-feeder",
|
|
20757
|
+
capScope: "device",
|
|
20758
|
+
addonId: null,
|
|
20759
|
+
access: "create"
|
|
20760
|
+
},
|
|
20761
|
+
"petFeeder.feed": {
|
|
20762
|
+
capName: "pet-feeder",
|
|
20763
|
+
capScope: "device",
|
|
20764
|
+
addonId: null,
|
|
20765
|
+
access: "create"
|
|
20766
|
+
},
|
|
20767
|
+
"petFeeder.markFoodReplenished": {
|
|
20768
|
+
capName: "pet-feeder",
|
|
20769
|
+
capScope: "device",
|
|
20770
|
+
addonId: null,
|
|
20771
|
+
access: "create"
|
|
20772
|
+
},
|
|
20773
|
+
"petFeeder.playSound": {
|
|
20774
|
+
capName: "pet-feeder",
|
|
20775
|
+
capScope: "device",
|
|
20776
|
+
addonId: null,
|
|
20777
|
+
access: "create"
|
|
20778
|
+
},
|
|
20779
|
+
"petFeeder.resetDesiccant": {
|
|
20780
|
+
capName: "pet-feeder",
|
|
20781
|
+
capScope: "device",
|
|
20782
|
+
addonId: null,
|
|
20783
|
+
access: "delete"
|
|
20784
|
+
},
|
|
20785
|
+
"petFeeder.setChildLock": {
|
|
20786
|
+
capName: "pet-feeder",
|
|
20787
|
+
capScope: "device",
|
|
20788
|
+
addonId: null,
|
|
20789
|
+
access: "create"
|
|
20790
|
+
},
|
|
20791
|
+
"petFeeder.setFeedSound": {
|
|
20792
|
+
capName: "pet-feeder",
|
|
20793
|
+
capScope: "device",
|
|
20794
|
+
addonId: null,
|
|
20795
|
+
access: "create"
|
|
20796
|
+
},
|
|
20797
|
+
"petFeeder.setIndicatorLight": {
|
|
20798
|
+
capName: "pet-feeder",
|
|
20799
|
+
capScope: "device",
|
|
20800
|
+
addonId: null,
|
|
20801
|
+
access: "create"
|
|
20802
|
+
},
|
|
20803
|
+
"petFeeder.setVolume": {
|
|
20804
|
+
capName: "pet-feeder",
|
|
20805
|
+
capScope: "device",
|
|
20806
|
+
addonId: null,
|
|
20807
|
+
access: "create"
|
|
20808
|
+
},
|
|
19716
20809
|
"pipelineAnalytics.clearTracks": {
|
|
19717
20810
|
capName: "pipeline-analytics",
|
|
19718
20811
|
capScope: "device",
|
|
@@ -20319,30 +21412,6 @@ Object.freeze({
|
|
|
20319
21412
|
addonId: null,
|
|
20320
21413
|
access: "view"
|
|
20321
21414
|
},
|
|
20322
|
-
"platformProbe.getHardwareDecodeAccels": {
|
|
20323
|
-
capName: "platform-probe",
|
|
20324
|
-
capScope: "system",
|
|
20325
|
-
addonId: null,
|
|
20326
|
-
access: "view"
|
|
20327
|
-
},
|
|
20328
|
-
"platformProbe.getHardwareEncoders": {
|
|
20329
|
-
capName: "platform-probe",
|
|
20330
|
-
capScope: "system",
|
|
20331
|
-
addonId: null,
|
|
20332
|
-
access: "view"
|
|
20333
|
-
},
|
|
20334
|
-
"platformProbe.refreshHardwareDecodeAccels": {
|
|
20335
|
-
capName: "platform-probe",
|
|
20336
|
-
capScope: "system",
|
|
20337
|
-
addonId: null,
|
|
20338
|
-
access: "create"
|
|
20339
|
-
},
|
|
20340
|
-
"platformProbe.refreshHardwareEncoders": {
|
|
20341
|
-
capName: "platform-probe",
|
|
20342
|
-
capScope: "system",
|
|
20343
|
-
addonId: null,
|
|
20344
|
-
access: "create"
|
|
20345
|
-
},
|
|
20346
21415
|
"platformProbe.resolveHwAccel": {
|
|
20347
21416
|
capName: "platform-probe",
|
|
20348
21417
|
capScope: "system",
|