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