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