@camstack/addon-remote-storage 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/s3.addon.js +1 -1
- package/dist/s3.addon.mjs +1 -1
- package/dist/sftp.addon.js +1 -1
- package/dist/sftp.addon.mjs +1 -1
- package/dist/{shared-N5OfEciV.js → shared-DAnfUk9-.js} +1140 -71
- package/dist/{shared-D9u4CXu8.mjs → shared-adXJdGLb.mjs} +1140 -71
- package/dist/webdav.addon.js +1 -1
- package/dist/webdav.addon.mjs +1 -1
- package/package.json +1 -1
|
@@ -4629,7 +4629,7 @@ function _instanceof(cls, params = {}) {
|
|
|
4629
4629
|
return inst;
|
|
4630
4630
|
}
|
|
4631
4631
|
//#endregion
|
|
4632
|
-
//#region ../types/dist/sleep-
|
|
4632
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4633
4633
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4634
4634
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4635
4635
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5442,6 +5442,100 @@ function createDurableState(deps) {
|
|
|
5442
5442
|
};
|
|
5443
5443
|
}
|
|
5444
5444
|
/**
|
|
5445
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5446
|
+
*
|
|
5447
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5448
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5449
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5450
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5451
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5452
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5453
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5454
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5455
|
+
*
|
|
5456
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5457
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5458
|
+
* schema and routes reads/writes through these helpers.
|
|
5459
|
+
*
|
|
5460
|
+
* ## No bare-key fallback — deliberate
|
|
5461
|
+
*
|
|
5462
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5463
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5464
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5465
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5466
|
+
* selection can never leak onto another. (This generalizes the
|
|
5467
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5468
|
+
* arbitrary set of per-node field keys.)
|
|
5469
|
+
*
|
|
5470
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5471
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5472
|
+
*/
|
|
5473
|
+
/**
|
|
5474
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5475
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5476
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5477
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5478
|
+
*/
|
|
5479
|
+
function normalizeNodeId(raw) {
|
|
5480
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5481
|
+
const slashIdx = raw.indexOf("/");
|
|
5482
|
+
if (slashIdx < 0) return raw;
|
|
5483
|
+
const bare = raw.slice(0, slashIdx);
|
|
5484
|
+
return bare === "" ? "hub" : bare;
|
|
5485
|
+
}
|
|
5486
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5487
|
+
function nodeScopedKey(base, nodeId) {
|
|
5488
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5489
|
+
}
|
|
5490
|
+
/**
|
|
5491
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5492
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5493
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5494
|
+
* schema `default` win on `undefined`.
|
|
5495
|
+
*/
|
|
5496
|
+
function readNodeValue(store, base, nodeId) {
|
|
5497
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5498
|
+
}
|
|
5499
|
+
/**
|
|
5500
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5501
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5502
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5503
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5504
|
+
* patch is not mutated.
|
|
5505
|
+
*/
|
|
5506
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5507
|
+
const out = {};
|
|
5508
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5509
|
+
return out;
|
|
5510
|
+
}
|
|
5511
|
+
/**
|
|
5512
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5513
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5514
|
+
* values:
|
|
5515
|
+
*
|
|
5516
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5517
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5518
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5519
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5520
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5521
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5522
|
+
*
|
|
5523
|
+
* Returns a new object — the input store is not mutated.
|
|
5524
|
+
*/
|
|
5525
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5526
|
+
const out = {};
|
|
5527
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5528
|
+
if (key.includes("@")) continue;
|
|
5529
|
+
if (perNodeKeys.has(key)) continue;
|
|
5530
|
+
out[key] = value;
|
|
5531
|
+
}
|
|
5532
|
+
for (const base of perNodeKeys) {
|
|
5533
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5534
|
+
if (value !== void 0) out[base] = value;
|
|
5535
|
+
}
|
|
5536
|
+
return out;
|
|
5537
|
+
}
|
|
5538
|
+
/**
|
|
5445
5539
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5446
5540
|
*
|
|
5447
5541
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5609,23 +5703,63 @@ var BaseAddon = class {
|
|
|
5609
5703
|
deviceSettingsSchema() {
|
|
5610
5704
|
return null;
|
|
5611
5705
|
}
|
|
5612
|
-
async getGlobalSettings(overlay, cap,
|
|
5706
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5613
5707
|
const schema = this.globalSettingsSchema(cap);
|
|
5614
5708
|
if (!schema) return { sections: [] };
|
|
5615
|
-
const
|
|
5709
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5616
5710
|
return hydrateSchema(schema, overlay ? {
|
|
5617
|
-
...
|
|
5711
|
+
...projected,
|
|
5618
5712
|
...overlay
|
|
5619
|
-
} :
|
|
5713
|
+
} : projected);
|
|
5620
5714
|
}
|
|
5621
|
-
|
|
5622
|
-
|
|
5715
|
+
/**
|
|
5716
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5717
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5718
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5719
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5720
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5721
|
+
*
|
|
5722
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5723
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5724
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5725
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5726
|
+
*/
|
|
5727
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5728
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5729
|
+
const keys = this.perNodeKeys(cap);
|
|
5730
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5731
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5732
|
+
}
|
|
5733
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5734
|
+
const keys = this.perNodeKeys();
|
|
5735
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5736
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5737
|
+
const barePatch = patch;
|
|
5738
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5739
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5740
|
+
if (target !== localNode) return;
|
|
5623
5741
|
await this.resolveConfig();
|
|
5624
5742
|
await this.onConfigChanged();
|
|
5625
5743
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5626
5744
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5627
5745
|
}
|
|
5628
5746
|
/**
|
|
5747
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5748
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5749
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5750
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5751
|
+
*/
|
|
5752
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5753
|
+
perNodeKeys(cap) {
|
|
5754
|
+
const cacheKey = cap ?? "";
|
|
5755
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5756
|
+
if (cached) return cached;
|
|
5757
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5758
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5759
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5760
|
+
return keys;
|
|
5761
|
+
}
|
|
5762
|
+
/**
|
|
5629
5763
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5630
5764
|
* schedule an addon restart for the next tick. Deferred via
|
|
5631
5765
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5778,12 +5912,19 @@ var BaseAddon = class {
|
|
|
5778
5912
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5779
5913
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5780
5914
|
* (e.g. from older versions) without polluting the typed config.
|
|
5915
|
+
*
|
|
5916
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5917
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5918
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5919
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5781
5920
|
*/
|
|
5782
5921
|
async resolveConfig() {
|
|
5783
5922
|
const stored = await this.readAddonStoreWithRetry();
|
|
5923
|
+
const perNode = this.perNodeKeys();
|
|
5924
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5784
5925
|
const resolved = { ...this.defaults };
|
|
5785
5926
|
for (const key of Object.keys(this.defaults)) {
|
|
5786
|
-
const storedValue = stored[key];
|
|
5927
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5787
5928
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5788
5929
|
const defaultType = typeof this.defaults[key];
|
|
5789
5930
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5867,6 +6008,27 @@ var BaseAddon = class {
|
|
|
5867
6008
|
}
|
|
5868
6009
|
};
|
|
5869
6010
|
/**
|
|
6011
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6012
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6013
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6014
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6015
|
+
*/
|
|
6016
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6017
|
+
const collected = [];
|
|
6018
|
+
for (const field of fields) {
|
|
6019
|
+
if (field.type === "group") {
|
|
6020
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6021
|
+
continue;
|
|
6022
|
+
}
|
|
6023
|
+
if (field.type === "sub-tabs") {
|
|
6024
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6025
|
+
continue;
|
|
6026
|
+
}
|
|
6027
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6028
|
+
}
|
|
6029
|
+
return collected;
|
|
6030
|
+
}
|
|
6031
|
+
/**
|
|
5870
6032
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5871
6033
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5872
6034
|
* envelopes pass through; void stays void.
|
|
@@ -6274,6 +6436,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6274
6436
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6275
6437
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6276
6438
|
DeviceType["Image"] = "image";
|
|
6439
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6440
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6441
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6442
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6443
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6444
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6445
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6277
6446
|
return DeviceType;
|
|
6278
6447
|
}({});
|
|
6279
6448
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7422,6 +7591,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7422
7591
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7423
7592
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7424
7593
|
/**
|
|
7594
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7595
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7596
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7597
|
+
*/
|
|
7598
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7599
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7600
|
+
var ExpressionParseError = class extends Error {
|
|
7601
|
+
position;
|
|
7602
|
+
constructor(message, position) {
|
|
7603
|
+
super(message);
|
|
7604
|
+
this.name = "ExpressionParseError";
|
|
7605
|
+
this.position = position;
|
|
7606
|
+
}
|
|
7607
|
+
};
|
|
7608
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7609
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7610
|
+
var ExpressionEvalError = class extends Error {
|
|
7611
|
+
constructor(message) {
|
|
7612
|
+
super(message);
|
|
7613
|
+
this.name = "ExpressionEvalError";
|
|
7614
|
+
}
|
|
7615
|
+
};
|
|
7616
|
+
/**
|
|
7617
|
+
* Resource-bound constants for the safe expression engine.
|
|
7618
|
+
*
|
|
7619
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7620
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7621
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7622
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7623
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7624
|
+
*/
|
|
7625
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7626
|
+
* rejected without allocation. */
|
|
7627
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7628
|
+
/** A legal binding / identifier name. */
|
|
7629
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7630
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7631
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7632
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7633
|
+
"now",
|
|
7634
|
+
"true",
|
|
7635
|
+
"false",
|
|
7636
|
+
"null"
|
|
7637
|
+
]);
|
|
7638
|
+
/**
|
|
7639
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7640
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7641
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7642
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7643
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7644
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7645
|
+
* template literals are lexically impossible.
|
|
7646
|
+
*/
|
|
7647
|
+
var KEYWORDS = new Set([
|
|
7648
|
+
"true",
|
|
7649
|
+
"false",
|
|
7650
|
+
"null"
|
|
7651
|
+
]);
|
|
7652
|
+
function isDigit(ch) {
|
|
7653
|
+
return ch >= "0" && ch <= "9";
|
|
7654
|
+
}
|
|
7655
|
+
function isIdentStart(ch) {
|
|
7656
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7657
|
+
}
|
|
7658
|
+
function isIdentPart(ch) {
|
|
7659
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7660
|
+
}
|
|
7661
|
+
function isWhitespace(ch) {
|
|
7662
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7663
|
+
}
|
|
7664
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7665
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7666
|
+
* string. */
|
|
7667
|
+
function tokenize(source) {
|
|
7668
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7669
|
+
const tokens = [];
|
|
7670
|
+
let i = 0;
|
|
7671
|
+
const n = source.length;
|
|
7672
|
+
while (i < n) {
|
|
7673
|
+
const ch = source[i];
|
|
7674
|
+
if (isWhitespace(ch)) {
|
|
7675
|
+
i += 1;
|
|
7676
|
+
continue;
|
|
7677
|
+
}
|
|
7678
|
+
if (isDigit(ch)) {
|
|
7679
|
+
const start = i;
|
|
7680
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7681
|
+
if (i < n && source[i] === ".") {
|
|
7682
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7683
|
+
i += 1;
|
|
7684
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7685
|
+
}
|
|
7686
|
+
const text = source.slice(start, i);
|
|
7687
|
+
const value = Number(text);
|
|
7688
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7689
|
+
tokens.push({
|
|
7690
|
+
type: "number",
|
|
7691
|
+
value,
|
|
7692
|
+
pos: start
|
|
7693
|
+
});
|
|
7694
|
+
continue;
|
|
7695
|
+
}
|
|
7696
|
+
if (ch === "'" || ch === "\"") {
|
|
7697
|
+
const quote = ch;
|
|
7698
|
+
const start = i;
|
|
7699
|
+
i += 1;
|
|
7700
|
+
let out = "";
|
|
7701
|
+
let closed = false;
|
|
7702
|
+
while (i < n) {
|
|
7703
|
+
const c = source[i];
|
|
7704
|
+
if (c === "\\") {
|
|
7705
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7706
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7707
|
+
out += next;
|
|
7708
|
+
i += 2;
|
|
7709
|
+
continue;
|
|
7710
|
+
}
|
|
7711
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7712
|
+
}
|
|
7713
|
+
if (c === quote) {
|
|
7714
|
+
closed = true;
|
|
7715
|
+
i += 1;
|
|
7716
|
+
break;
|
|
7717
|
+
}
|
|
7718
|
+
out += c;
|
|
7719
|
+
i += 1;
|
|
7720
|
+
}
|
|
7721
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7722
|
+
tokens.push({
|
|
7723
|
+
type: "string",
|
|
7724
|
+
value: out,
|
|
7725
|
+
pos: start
|
|
7726
|
+
});
|
|
7727
|
+
continue;
|
|
7728
|
+
}
|
|
7729
|
+
if (isIdentStart(ch)) {
|
|
7730
|
+
const start = i;
|
|
7731
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7732
|
+
const text = source.slice(start, i);
|
|
7733
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7734
|
+
type: "keyword",
|
|
7735
|
+
keyword: keywordOf(text),
|
|
7736
|
+
pos: start
|
|
7737
|
+
});
|
|
7738
|
+
else tokens.push({
|
|
7739
|
+
type: "identifier",
|
|
7740
|
+
name: text,
|
|
7741
|
+
pos: start
|
|
7742
|
+
});
|
|
7743
|
+
continue;
|
|
7744
|
+
}
|
|
7745
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7746
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7747
|
+
tokens.push({
|
|
7748
|
+
type: "punct",
|
|
7749
|
+
punct: two,
|
|
7750
|
+
pos: i
|
|
7751
|
+
});
|
|
7752
|
+
i += 2;
|
|
7753
|
+
continue;
|
|
7754
|
+
}
|
|
7755
|
+
if (isSinglePunct(ch)) {
|
|
7756
|
+
tokens.push({
|
|
7757
|
+
type: "punct",
|
|
7758
|
+
punct: ch,
|
|
7759
|
+
pos: i
|
|
7760
|
+
});
|
|
7761
|
+
i += 1;
|
|
7762
|
+
continue;
|
|
7763
|
+
}
|
|
7764
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7765
|
+
}
|
|
7766
|
+
tokens.push({
|
|
7767
|
+
type: "eof",
|
|
7768
|
+
pos: n
|
|
7769
|
+
});
|
|
7770
|
+
return tokens;
|
|
7771
|
+
}
|
|
7772
|
+
function keywordOf(text) {
|
|
7773
|
+
if (text === "true") return "true";
|
|
7774
|
+
if (text === "false") return "false";
|
|
7775
|
+
return "null";
|
|
7776
|
+
}
|
|
7777
|
+
function isSinglePunct(ch) {
|
|
7778
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7779
|
+
}
|
|
7780
|
+
/**
|
|
7781
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7782
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7783
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7784
|
+
* own-property check against it.
|
|
7785
|
+
*
|
|
7786
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7787
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7788
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7789
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7790
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7791
|
+
*
|
|
7792
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7793
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7794
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7795
|
+
* closed rather than emitting a garbage value.
|
|
7796
|
+
*/
|
|
7797
|
+
function asFiniteNumber(value, name, index) {
|
|
7798
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7799
|
+
return value;
|
|
7800
|
+
}
|
|
7801
|
+
function asString$1(value, name, index) {
|
|
7802
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7803
|
+
return value;
|
|
7804
|
+
}
|
|
7805
|
+
function finiteResult(value, name) {
|
|
7806
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7807
|
+
return value;
|
|
7808
|
+
}
|
|
7809
|
+
function allFiniteNumbers(args, name) {
|
|
7810
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7811
|
+
}
|
|
7812
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7813
|
+
var table = {
|
|
7814
|
+
min: {
|
|
7815
|
+
minArgs: 1,
|
|
7816
|
+
maxArgs: INF,
|
|
7817
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7818
|
+
},
|
|
7819
|
+
max: {
|
|
7820
|
+
minArgs: 1,
|
|
7821
|
+
maxArgs: INF,
|
|
7822
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7823
|
+
},
|
|
7824
|
+
abs: {
|
|
7825
|
+
minArgs: 1,
|
|
7826
|
+
maxArgs: 1,
|
|
7827
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7828
|
+
},
|
|
7829
|
+
floor: {
|
|
7830
|
+
minArgs: 1,
|
|
7831
|
+
maxArgs: 1,
|
|
7832
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7833
|
+
},
|
|
7834
|
+
ceil: {
|
|
7835
|
+
minArgs: 1,
|
|
7836
|
+
maxArgs: 1,
|
|
7837
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7838
|
+
},
|
|
7839
|
+
sqrt: {
|
|
7840
|
+
minArgs: 1,
|
|
7841
|
+
maxArgs: 1,
|
|
7842
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7843
|
+
},
|
|
7844
|
+
round: {
|
|
7845
|
+
minArgs: 1,
|
|
7846
|
+
maxArgs: 2,
|
|
7847
|
+
apply: (args) => {
|
|
7848
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7849
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7850
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7851
|
+
const factor = 10 ** digits;
|
|
7852
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7853
|
+
}
|
|
7854
|
+
},
|
|
7855
|
+
pow: {
|
|
7856
|
+
minArgs: 2,
|
|
7857
|
+
maxArgs: 2,
|
|
7858
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7859
|
+
},
|
|
7860
|
+
clamp: {
|
|
7861
|
+
minArgs: 3,
|
|
7862
|
+
maxArgs: 3,
|
|
7863
|
+
apply: (args) => {
|
|
7864
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7865
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7866
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7867
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7868
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7869
|
+
}
|
|
7870
|
+
},
|
|
7871
|
+
avg: {
|
|
7872
|
+
minArgs: 1,
|
|
7873
|
+
maxArgs: INF,
|
|
7874
|
+
apply: (args) => {
|
|
7875
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7876
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7877
|
+
}
|
|
7878
|
+
},
|
|
7879
|
+
sum: {
|
|
7880
|
+
minArgs: 1,
|
|
7881
|
+
maxArgs: INF,
|
|
7882
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7883
|
+
},
|
|
7884
|
+
coalesce: {
|
|
7885
|
+
minArgs: 1,
|
|
7886
|
+
maxArgs: INF,
|
|
7887
|
+
apply: (args) => {
|
|
7888
|
+
for (const a of args) if (a !== null) return a;
|
|
7889
|
+
return null;
|
|
7890
|
+
}
|
|
7891
|
+
},
|
|
7892
|
+
age: {
|
|
7893
|
+
minArgs: 2,
|
|
7894
|
+
maxArgs: 2,
|
|
7895
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7896
|
+
},
|
|
7897
|
+
convert: {
|
|
7898
|
+
minArgs: 3,
|
|
7899
|
+
maxArgs: 3,
|
|
7900
|
+
apply: (args, hooks) => {
|
|
7901
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7902
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7903
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7904
|
+
if (hooks.convert) {
|
|
7905
|
+
const out = hooks.convert(x, from, to);
|
|
7906
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7907
|
+
return finiteResult(out, "convert");
|
|
7908
|
+
}
|
|
7909
|
+
if (from === to) return x;
|
|
7910
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7911
|
+
}
|
|
7912
|
+
}
|
|
7913
|
+
};
|
|
7914
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7915
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7916
|
+
* callees at parse time (immediate author feedback). */
|
|
7917
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7918
|
+
/**
|
|
7919
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7920
|
+
*
|
|
7921
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7922
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7923
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7924
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7925
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7926
|
+
* that references a since-removed builtin degrades at read.
|
|
7927
|
+
*
|
|
7928
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7929
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7930
|
+
*/
|
|
7931
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7932
|
+
var BINARY_PRECEDENCE = {
|
|
7933
|
+
"||": 1,
|
|
7934
|
+
"&&": 2,
|
|
7935
|
+
"==": 3,
|
|
7936
|
+
"!=": 3,
|
|
7937
|
+
"<": 4,
|
|
7938
|
+
"<=": 4,
|
|
7939
|
+
">": 4,
|
|
7940
|
+
">=": 4,
|
|
7941
|
+
"+": 5,
|
|
7942
|
+
"-": 5,
|
|
7943
|
+
"*": 6,
|
|
7944
|
+
"/": 6,
|
|
7945
|
+
"%": 6
|
|
7946
|
+
};
|
|
7947
|
+
function isLogicalOp(op) {
|
|
7948
|
+
return op === "&&" || op === "||";
|
|
7949
|
+
}
|
|
7950
|
+
function isBinaryOp(op) {
|
|
7951
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7952
|
+
}
|
|
7953
|
+
var Parser = class {
|
|
7954
|
+
tokens;
|
|
7955
|
+
pos = 0;
|
|
7956
|
+
nodeCount = 0;
|
|
7957
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7958
|
+
callees = /* @__PURE__ */ new Set();
|
|
7959
|
+
constructor(tokens) {
|
|
7960
|
+
this.tokens = tokens;
|
|
7961
|
+
}
|
|
7962
|
+
parse() {
|
|
7963
|
+
const ast = this.parseTernary();
|
|
7964
|
+
const tok = this.peek();
|
|
7965
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
7966
|
+
return {
|
|
7967
|
+
ast,
|
|
7968
|
+
identifiers: this.identifiers,
|
|
7969
|
+
callees: this.callees,
|
|
7970
|
+
nodeCount: this.nodeCount
|
|
7971
|
+
};
|
|
7972
|
+
}
|
|
7973
|
+
peek() {
|
|
7974
|
+
return this.tokens[this.pos];
|
|
7975
|
+
}
|
|
7976
|
+
next() {
|
|
7977
|
+
return this.tokens[this.pos++];
|
|
7978
|
+
}
|
|
7979
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
7980
|
+
expectPunct(punct) {
|
|
7981
|
+
const tok = this.peek();
|
|
7982
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
7983
|
+
this.pos += 1;
|
|
7984
|
+
}
|
|
7985
|
+
matchPunct(punct) {
|
|
7986
|
+
const tok = this.peek();
|
|
7987
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
7988
|
+
this.pos += 1;
|
|
7989
|
+
return true;
|
|
7990
|
+
}
|
|
7991
|
+
return false;
|
|
7992
|
+
}
|
|
7993
|
+
countNode() {
|
|
7994
|
+
this.nodeCount += 1;
|
|
7995
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
7996
|
+
}
|
|
7997
|
+
parseTernary() {
|
|
7998
|
+
const test = this.parseBinary(1);
|
|
7999
|
+
if (this.matchPunct("?")) {
|
|
8000
|
+
const consequent = this.parseTernary();
|
|
8001
|
+
this.expectPunct(":");
|
|
8002
|
+
const alternate = this.parseTernary();
|
|
8003
|
+
this.countNode();
|
|
8004
|
+
return {
|
|
8005
|
+
kind: "conditional",
|
|
8006
|
+
test,
|
|
8007
|
+
consequent,
|
|
8008
|
+
alternate
|
|
8009
|
+
};
|
|
8010
|
+
}
|
|
8011
|
+
return test;
|
|
8012
|
+
}
|
|
8013
|
+
parseBinary(minPrec) {
|
|
8014
|
+
let left = this.parseUnary();
|
|
8015
|
+
for (;;) {
|
|
8016
|
+
const tok = this.peek();
|
|
8017
|
+
if (tok.type !== "punct") break;
|
|
8018
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8019
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8020
|
+
const op = tok.punct;
|
|
8021
|
+
this.pos += 1;
|
|
8022
|
+
const right = this.parseBinary(prec + 1);
|
|
8023
|
+
this.countNode();
|
|
8024
|
+
if (isLogicalOp(op)) left = {
|
|
8025
|
+
kind: "logical",
|
|
8026
|
+
op,
|
|
8027
|
+
left,
|
|
8028
|
+
right
|
|
8029
|
+
};
|
|
8030
|
+
else if (isBinaryOp(op)) left = {
|
|
8031
|
+
kind: "binary",
|
|
8032
|
+
op,
|
|
8033
|
+
left,
|
|
8034
|
+
right
|
|
8035
|
+
};
|
|
8036
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8037
|
+
}
|
|
8038
|
+
return left;
|
|
8039
|
+
}
|
|
8040
|
+
parseUnary() {
|
|
8041
|
+
const tok = this.peek();
|
|
8042
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8043
|
+
const op = tok.punct;
|
|
8044
|
+
this.pos += 1;
|
|
8045
|
+
const operand = this.parseUnary();
|
|
8046
|
+
this.countNode();
|
|
8047
|
+
return {
|
|
8048
|
+
kind: "unary",
|
|
8049
|
+
op,
|
|
8050
|
+
operand
|
|
8051
|
+
};
|
|
8052
|
+
}
|
|
8053
|
+
return this.parsePrimary();
|
|
8054
|
+
}
|
|
8055
|
+
parsePrimary() {
|
|
8056
|
+
const tok = this.next();
|
|
8057
|
+
switch (tok.type) {
|
|
8058
|
+
case "number":
|
|
8059
|
+
this.countNode();
|
|
8060
|
+
return {
|
|
8061
|
+
kind: "literal",
|
|
8062
|
+
value: tok.value
|
|
8063
|
+
};
|
|
8064
|
+
case "string":
|
|
8065
|
+
this.countNode();
|
|
8066
|
+
return {
|
|
8067
|
+
kind: "literal",
|
|
8068
|
+
value: tok.value
|
|
8069
|
+
};
|
|
8070
|
+
case "keyword":
|
|
8071
|
+
this.countNode();
|
|
8072
|
+
return {
|
|
8073
|
+
kind: "literal",
|
|
8074
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8075
|
+
};
|
|
8076
|
+
case "identifier": {
|
|
8077
|
+
const nextTok = this.peek();
|
|
8078
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8079
|
+
this.identifiers.add(tok.name);
|
|
8080
|
+
this.countNode();
|
|
8081
|
+
return {
|
|
8082
|
+
kind: "identifier",
|
|
8083
|
+
name: tok.name
|
|
8084
|
+
};
|
|
8085
|
+
}
|
|
8086
|
+
case "punct":
|
|
8087
|
+
if (tok.punct === "(") {
|
|
8088
|
+
const inner = this.parseTernary();
|
|
8089
|
+
this.expectPunct(")");
|
|
8090
|
+
return inner;
|
|
8091
|
+
}
|
|
8092
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8093
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8094
|
+
}
|
|
8095
|
+
}
|
|
8096
|
+
parseCall(callee, pos) {
|
|
8097
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8098
|
+
this.expectPunct("(");
|
|
8099
|
+
const args = [];
|
|
8100
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8101
|
+
args.push(this.parseTernary());
|
|
8102
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8103
|
+
if (this.matchPunct(",")) continue;
|
|
8104
|
+
this.expectPunct(")");
|
|
8105
|
+
break;
|
|
8106
|
+
}
|
|
8107
|
+
this.callees.add(callee);
|
|
8108
|
+
this.countNode();
|
|
8109
|
+
return {
|
|
8110
|
+
kind: "call",
|
|
8111
|
+
callee,
|
|
8112
|
+
args
|
|
8113
|
+
};
|
|
8114
|
+
}
|
|
8115
|
+
};
|
|
8116
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8117
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8118
|
+
function parseExpression(source) {
|
|
8119
|
+
return new Parser(tokenize(source)).parse();
|
|
8120
|
+
}
|
|
8121
|
+
Object.freeze({});
|
|
8122
|
+
/**
|
|
8123
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8124
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8125
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8126
|
+
* one per read on a hot resolve path.
|
|
8127
|
+
*
|
|
8128
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8129
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8130
|
+
* callers is safe and maximises hit rate.
|
|
8131
|
+
*/
|
|
8132
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8133
|
+
function getCached(source) {
|
|
8134
|
+
const hit = cache.get(source);
|
|
8135
|
+
if (hit !== void 0) {
|
|
8136
|
+
cache.delete(source);
|
|
8137
|
+
cache.set(source, hit);
|
|
8138
|
+
return hit;
|
|
8139
|
+
}
|
|
8140
|
+
let result;
|
|
8141
|
+
try {
|
|
8142
|
+
result = {
|
|
8143
|
+
ok: true,
|
|
8144
|
+
parsed: parseExpression(source)
|
|
8145
|
+
};
|
|
8146
|
+
} catch (err) {
|
|
8147
|
+
result = {
|
|
8148
|
+
ok: false,
|
|
8149
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8150
|
+
};
|
|
8151
|
+
}
|
|
8152
|
+
cache.set(source, result);
|
|
8153
|
+
if (cache.size > 256) {
|
|
8154
|
+
const oldest = cache.keys().next().value;
|
|
8155
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8156
|
+
}
|
|
8157
|
+
return result;
|
|
8158
|
+
}
|
|
8159
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8160
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8161
|
+
function compileExpressionSafe(source) {
|
|
8162
|
+
return getCached(source);
|
|
8163
|
+
}
|
|
8164
|
+
/**
|
|
8165
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8166
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8167
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8168
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8169
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8170
|
+
*/
|
|
8171
|
+
function validateExpressionSource(src) {
|
|
8172
|
+
const names = Object.keys(src.bindings);
|
|
8173
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8174
|
+
for (const name of names) {
|
|
8175
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8176
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8177
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8178
|
+
}
|
|
8179
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8180
|
+
if (!compiled.ok) return compiled.error;
|
|
8181
|
+
const bound = new Set(names);
|
|
8182
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8183
|
+
if (id === "now") continue;
|
|
8184
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8185
|
+
}
|
|
8186
|
+
return null;
|
|
8187
|
+
}
|
|
8188
|
+
/**
|
|
7425
8189
|
* Accessory device helpers — shared across drivers.
|
|
7426
8190
|
*
|
|
7427
8191
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -9324,7 +10088,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
9324
10088
|
});
|
|
9325
10089
|
method(object({
|
|
9326
10090
|
deviceId: number(),
|
|
9327
|
-
frame: FrameInputSchema
|
|
10091
|
+
frame: FrameInputSchema.optional(),
|
|
10092
|
+
frameHandle: FrameHandleSchema.optional()
|
|
9328
10093
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
9329
10094
|
deviceId: number(),
|
|
9330
10095
|
detected: boolean(),
|
|
@@ -9571,6 +10336,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
9571
10336
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
9572
10337
|
steps: array(PipelineStepInputSchema).min(1),
|
|
9573
10338
|
frame: FrameInputSchema.optional(),
|
|
10339
|
+
/**
|
|
10340
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
10341
|
+
* the decoded pixels live in. One more member of the one-of
|
|
10342
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
10343
|
+
*/
|
|
10344
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
9574
10345
|
imageBase64: string().optional(),
|
|
9575
10346
|
/**
|
|
9576
10347
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -9780,6 +10551,31 @@ var ReportMotionInputSchema = object({
|
|
|
9780
10551
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
9781
10552
|
});
|
|
9782
10553
|
/**
|
|
10554
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
10555
|
+
* restream-owner model — P2c).
|
|
10556
|
+
*
|
|
10557
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
10558
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
10559
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
10560
|
+
* behavior change.
|
|
10561
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
10562
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
10563
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
10564
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
10565
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
10566
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
10567
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
10568
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
10569
|
+
* dials for the owner's restream.
|
|
10570
|
+
*/
|
|
10571
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
10572
|
+
kind: literal("remote-restream"),
|
|
10573
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
10574
|
+
ownerNodeId: string(),
|
|
10575
|
+
/** Operator override for the owner host the runner dials. */
|
|
10576
|
+
hubHostnameOverride: string().optional()
|
|
10577
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
10578
|
+
/**
|
|
9783
10579
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
9784
10580
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
9785
10581
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -9877,7 +10673,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
9877
10673
|
*/
|
|
9878
10674
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
9879
10675
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
9880
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
10676
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
10677
|
+
/**
|
|
10678
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
10679
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
10680
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
10681
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
10682
|
+
* `remoteSourcingNodes` rollout setting).
|
|
10683
|
+
*/
|
|
10684
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
9881
10685
|
});
|
|
9882
10686
|
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;
|
|
9883
10687
|
/**
|
|
@@ -10242,6 +11046,113 @@ object({
|
|
|
10242
11046
|
lastFetchedAt: number()
|
|
10243
11047
|
});
|
|
10244
11048
|
DeviceType.Sensor;
|
|
11049
|
+
/**
|
|
11050
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
11051
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
11052
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
11053
|
+
*/
|
|
11054
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
11055
|
+
"normal",
|
|
11056
|
+
"offline",
|
|
11057
|
+
"on_batteries"
|
|
11058
|
+
]);
|
|
11059
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
11060
|
+
object({
|
|
11061
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
11062
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
11063
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
11064
|
+
foodLevel: number().nullable(),
|
|
11065
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
11066
|
+
* single-hopper models. */
|
|
11067
|
+
food1: number().nullable(),
|
|
11068
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
11069
|
+
* single-hopper models. */
|
|
11070
|
+
food2: number().nullable(),
|
|
11071
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
11072
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
11073
|
+
* below the feeder's low threshold. */
|
|
11074
|
+
lowFood: boolean(),
|
|
11075
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
11076
|
+
* device has no battery reading. */
|
|
11077
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
11078
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
11079
|
+
* desiccant sensor. */
|
|
11080
|
+
desiccantLeftDays: number().nullable(),
|
|
11081
|
+
/** True while a feed is in progress. */
|
|
11082
|
+
feeding: boolean(),
|
|
11083
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
11084
|
+
* Null until the device has reported a status. */
|
|
11085
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
11086
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
11087
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
11088
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
11089
|
+
error: string().nullable(),
|
|
11090
|
+
/** Raw device error code (0 / null = no error). */
|
|
11091
|
+
errorCode: number().nullable(),
|
|
11092
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
11093
|
+
isDualHopper: boolean(),
|
|
11094
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
11095
|
+
childLock: boolean(),
|
|
11096
|
+
/** Front indicator-light setting. */
|
|
11097
|
+
indicatorLight: boolean(),
|
|
11098
|
+
/** Play a chime when dispensing. */
|
|
11099
|
+
feedSound: boolean(),
|
|
11100
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
11101
|
+
volume: number(),
|
|
11102
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
11103
|
+
lastFetchedAt: number()
|
|
11104
|
+
});
|
|
11105
|
+
DeviceType.PetFeeder, method(object({
|
|
11106
|
+
deviceId: number().int().nonnegative(),
|
|
11107
|
+
grams: gramsPortion.optional(),
|
|
11108
|
+
hopper1: gramsPortion.optional(),
|
|
11109
|
+
hopper2: gramsPortion.optional()
|
|
11110
|
+
}), _void(), {
|
|
11111
|
+
kind: "mutation",
|
|
11112
|
+
auth: "admin"
|
|
11113
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11114
|
+
kind: "mutation",
|
|
11115
|
+
auth: "admin"
|
|
11116
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11117
|
+
kind: "mutation",
|
|
11118
|
+
auth: "admin"
|
|
11119
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11120
|
+
kind: "mutation",
|
|
11121
|
+
auth: "admin"
|
|
11122
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11123
|
+
kind: "mutation",
|
|
11124
|
+
auth: "admin"
|
|
11125
|
+
}), method(object({
|
|
11126
|
+
deviceId: number().int().nonnegative(),
|
|
11127
|
+
soundId: number().int().nonnegative()
|
|
11128
|
+
}), _void(), {
|
|
11129
|
+
kind: "mutation",
|
|
11130
|
+
auth: "admin"
|
|
11131
|
+
}), method(object({
|
|
11132
|
+
deviceId: number().int().nonnegative(),
|
|
11133
|
+
on: boolean()
|
|
11134
|
+
}), _void(), {
|
|
11135
|
+
kind: "mutation",
|
|
11136
|
+
auth: "admin"
|
|
11137
|
+
}), method(object({
|
|
11138
|
+
deviceId: number().int().nonnegative(),
|
|
11139
|
+
on: boolean()
|
|
11140
|
+
}), _void(), {
|
|
11141
|
+
kind: "mutation",
|
|
11142
|
+
auth: "admin"
|
|
11143
|
+
}), method(object({
|
|
11144
|
+
deviceId: number().int().nonnegative(),
|
|
11145
|
+
on: boolean()
|
|
11146
|
+
}), _void(), {
|
|
11147
|
+
kind: "mutation",
|
|
11148
|
+
auth: "admin"
|
|
11149
|
+
}), method(object({
|
|
11150
|
+
deviceId: number().int().nonnegative(),
|
|
11151
|
+
level: number().int().nonnegative()
|
|
11152
|
+
}), _void(), {
|
|
11153
|
+
kind: "mutation",
|
|
11154
|
+
auth: "admin"
|
|
11155
|
+
});
|
|
10245
11156
|
object({
|
|
10246
11157
|
/** Instantaneous power draw in watts. */
|
|
10247
11158
|
watts: number().optional(),
|
|
@@ -12069,10 +12980,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
12069
12980
|
url: string()
|
|
12070
12981
|
}), _void()), method(object({
|
|
12071
12982
|
sessionId: string(),
|
|
12072
|
-
maxCount: number().default(1)
|
|
12983
|
+
maxCount: number().default(1),
|
|
12984
|
+
waitMs: number().optional()
|
|
12073
12985
|
}), array(DecodedFrameSchema)), method(object({
|
|
12074
12986
|
sessionId: string(),
|
|
12075
|
-
maxCount: number().default(1)
|
|
12987
|
+
maxCount: number().default(1),
|
|
12988
|
+
waitMs: number().optional()
|
|
12076
12989
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
12077
12990
|
sessionId: string(),
|
|
12078
12991
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -12359,14 +13272,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
12359
13272
|
collapsed: boolean().optional()
|
|
12360
13273
|
});
|
|
12361
13274
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
12362
|
-
* `device-management.ts`.
|
|
13275
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
13276
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
13277
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
13278
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
13279
|
+
* source device's full re-sync-stable `stableId`. */
|
|
13280
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
13281
|
+
kind: literal("field").optional(),
|
|
13282
|
+
sourceKey: string(),
|
|
13283
|
+
cap: string(),
|
|
13284
|
+
fieldPath: string()
|
|
13285
|
+
});
|
|
13286
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
13287
|
+
kind: literal("literal"),
|
|
13288
|
+
value: union([
|
|
13289
|
+
string(),
|
|
13290
|
+
number(),
|
|
13291
|
+
boolean(),
|
|
13292
|
+
_null()
|
|
13293
|
+
])
|
|
13294
|
+
});
|
|
13295
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
13296
|
+
kind: literal("global"),
|
|
13297
|
+
sourceStableId: string(),
|
|
13298
|
+
cap: string(),
|
|
13299
|
+
fieldPath: string()
|
|
13300
|
+
});
|
|
13301
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
13302
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
13303
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
13304
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
13305
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
13306
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
13307
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
13308
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
13309
|
+
kind: literal("expression"),
|
|
13310
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
13311
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
13312
|
+
DeviceLinkFieldSourceSchema,
|
|
13313
|
+
DeviceLinkLiteralSourceSchema,
|
|
13314
|
+
DeviceLinkGlobalSourceSchema
|
|
13315
|
+
]))
|
|
13316
|
+
}).superRefine((src, ctx) => {
|
|
13317
|
+
const err = validateExpressionSource(src);
|
|
13318
|
+
if (err !== null) ctx.addIssue({
|
|
13319
|
+
code: "custom",
|
|
13320
|
+
message: err,
|
|
13321
|
+
path: ["expr"]
|
|
13322
|
+
});
|
|
13323
|
+
});
|
|
12363
13324
|
var DeviceLinkSchema = object({
|
|
12364
13325
|
id: string(),
|
|
12365
|
-
source:
|
|
12366
|
-
|
|
12367
|
-
|
|
12368
|
-
|
|
12369
|
-
|
|
13326
|
+
source: union([
|
|
13327
|
+
DeviceLinkFieldSourceSchema,
|
|
13328
|
+
DeviceLinkLiteralSourceSchema,
|
|
13329
|
+
DeviceLinkGlobalSourceSchema,
|
|
13330
|
+
DeviceLinkExpressionSourceSchema
|
|
13331
|
+
]),
|
|
12370
13332
|
target: object({
|
|
12371
13333
|
cap: string(),
|
|
12372
13334
|
fieldPath: string(),
|
|
@@ -12395,6 +13357,31 @@ var DeviceLinkSchema = object({
|
|
|
12395
13357
|
})
|
|
12396
13358
|
]).optional()
|
|
12397
13359
|
});
|
|
13360
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
13361
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
13362
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
13363
|
+
unit: string().min(1).optional(),
|
|
13364
|
+
precision: number().int().min(0).max(10).optional()
|
|
13365
|
+
});
|
|
13366
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
13367
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
13368
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
13369
|
+
var DeviceDisplayOverrideSchema = object({
|
|
13370
|
+
icon: string().min(1).optional(),
|
|
13371
|
+
label: string().min(1).optional(),
|
|
13372
|
+
unit: string().min(1).optional(),
|
|
13373
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13374
|
+
hidden: boolean().optional(),
|
|
13375
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
13376
|
+
});
|
|
13377
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
13378
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
13379
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
13380
|
+
var RoleDisplayDefaultSchema = object({
|
|
13381
|
+
unit: string().min(1).optional(),
|
|
13382
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13383
|
+
icon: string().min(1).optional()
|
|
13384
|
+
});
|
|
12398
13385
|
/**
|
|
12399
13386
|
* Serializable projection of a live IDevice.
|
|
12400
13387
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -12450,7 +13437,9 @@ var DeviceInfoSchema = object({
|
|
|
12450
13437
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
12451
13438
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
12452
13439
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
12453
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
13440
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
13441
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13442
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12454
13443
|
});
|
|
12455
13444
|
var ConfigEntrySchema = object({
|
|
12456
13445
|
key: string(),
|
|
@@ -12515,7 +13504,9 @@ var DeviceMetaSchema = object({
|
|
|
12515
13504
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
12516
13505
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
12517
13506
|
* Optional: only present for accessory children that carry a known role. */
|
|
12518
|
-
role: string().nullable().optional()
|
|
13507
|
+
role: string().nullable().optional(),
|
|
13508
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13509
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12519
13510
|
});
|
|
12520
13511
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
12521
13512
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -12609,7 +13600,19 @@ method(object({
|
|
|
12609
13600
|
}), _void(), {
|
|
12610
13601
|
kind: "mutation",
|
|
12611
13602
|
auth: "admin"
|
|
12612
|
-
}), method(object({
|
|
13603
|
+
}), method(object({
|
|
13604
|
+
deviceId: number(),
|
|
13605
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
13606
|
+
}), _void(), {
|
|
13607
|
+
kind: "mutation",
|
|
13608
|
+
auth: "admin"
|
|
13609
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
13610
|
+
kind: "mutation",
|
|
13611
|
+
auth: "admin"
|
|
13612
|
+
}), method(object({
|
|
13613
|
+
deviceId: number(),
|
|
13614
|
+
includeSynthesizable: boolean().optional()
|
|
13615
|
+
}), object({ caps: array(object({
|
|
12613
13616
|
cap: string(),
|
|
12614
13617
|
fields: array(object({
|
|
12615
13618
|
path: string(),
|
|
@@ -12619,8 +13622,13 @@ method(object({
|
|
|
12619
13622
|
"boolean",
|
|
12620
13623
|
"enum"
|
|
12621
13624
|
]),
|
|
12622
|
-
enumValues: array(string()).optional()
|
|
12623
|
-
|
|
13625
|
+
enumValues: array(string()).optional(),
|
|
13626
|
+
item: boolean().optional()
|
|
13627
|
+
})).readonly(),
|
|
13628
|
+
itemArray: object({
|
|
13629
|
+
path: string(),
|
|
13630
|
+
keyField: string()
|
|
13631
|
+
}).optional()
|
|
12624
13632
|
})).readonly() }), { kind: "query" }), method(object({
|
|
12625
13633
|
deviceId: number(),
|
|
12626
13634
|
role: string().nullable()
|
|
@@ -12690,7 +13698,11 @@ method(object({
|
|
|
12690
13698
|
deviceId: number(),
|
|
12691
13699
|
entries: array(object({
|
|
12692
13700
|
capName: string(),
|
|
12693
|
-
kind: _enum([
|
|
13701
|
+
kind: _enum([
|
|
13702
|
+
"native",
|
|
13703
|
+
"wrapped",
|
|
13704
|
+
"linked"
|
|
13705
|
+
]),
|
|
12694
13706
|
providerAddonId: string(),
|
|
12695
13707
|
providerNodeId: string(),
|
|
12696
13708
|
nativeAddonId: string()
|
|
@@ -12699,7 +13711,11 @@ method(object({
|
|
|
12699
13711
|
deviceId: number(),
|
|
12700
13712
|
entries: array(object({
|
|
12701
13713
|
capName: string(),
|
|
12702
|
-
kind: _enum([
|
|
13714
|
+
kind: _enum([
|
|
13715
|
+
"native",
|
|
13716
|
+
"wrapped",
|
|
13717
|
+
"linked"
|
|
13718
|
+
]),
|
|
12703
13719
|
providerAddonId: string(),
|
|
12704
13720
|
providerNodeId: string(),
|
|
12705
13721
|
nativeAddonId: string()
|
|
@@ -13941,7 +14957,10 @@ var AgentLoadSummarySchema = object({
|
|
|
13941
14957
|
online: boolean(),
|
|
13942
14958
|
load: RunnerLocalLoadSchema,
|
|
13943
14959
|
/** Computed score used by the L2 capacity balancer (lower = less loaded). */
|
|
13944
|
-
score: number()
|
|
14960
|
+
score: number(),
|
|
14961
|
+
/** This node's decode hwaccel backend (per-node `probedBestHwaccel`), or null
|
|
14962
|
+
* when not yet probed — for the cluster Pipeline table UI (P0.2). */
|
|
14963
|
+
decodeHwaccel: string().nullable()
|
|
13945
14964
|
});
|
|
13946
14965
|
/**
|
|
13947
14966
|
* Aggregate metrics across the whole detection cluster. Replaces the legacy
|
|
@@ -16504,7 +17523,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
16504
17523
|
"webgpu",
|
|
16505
17524
|
"none"
|
|
16506
17525
|
]).nullable().optional();
|
|
16507
|
-
var HwAccelResolutionSchema = object({
|
|
17526
|
+
var HwAccelResolutionSchema = object({
|
|
17527
|
+
preferred: array(string()).readonly(),
|
|
17528
|
+
rationale: string()
|
|
17529
|
+
});
|
|
16508
17530
|
var HardwareEncoderIdSchema = _enum([
|
|
16509
17531
|
"h264_videotoolbox",
|
|
16510
17532
|
"hevc_videotoolbox",
|
|
@@ -16519,7 +17541,7 @@ var HardwareEncoderIdSchema = _enum([
|
|
|
16519
17541
|
"libx264",
|
|
16520
17542
|
"libx265"
|
|
16521
17543
|
]);
|
|
16522
|
-
|
|
17544
|
+
object({
|
|
16523
17545
|
encoders: array(object({
|
|
16524
17546
|
encoder: HardwareEncoderIdSchema,
|
|
16525
17547
|
codec: _enum(["H264", "H265"]),
|
|
@@ -16538,15 +17560,7 @@ var HardwareEncodersSchema = object({
|
|
|
16538
17560
|
defaultH265: HardwareEncoderIdSchema,
|
|
16539
17561
|
probedAt: number()
|
|
16540
17562
|
});
|
|
16541
|
-
|
|
16542
|
-
* Decode-side companion to {@link HardwareEncodersSchema}: the `-hwaccel`
|
|
16543
|
-
* methods the configured ffmpeg binary actually supports (parsed from
|
|
16544
|
-
* `ffmpeg -hwaccels`). Used to gate decode-hwaccel attempts so the transcode
|
|
16545
|
-
* egress never spends a spawn on a backend this build cannot offer. Per-stream
|
|
16546
|
-
* decode fragility (e.g. VideoToolbox HEVC) is still handled by the egress's
|
|
16547
|
-
* software fallback — this only filters out wholly-unsupported backends.
|
|
16548
|
-
*/
|
|
16549
|
-
var HardwareDecodeAccelsSchema = object({
|
|
17563
|
+
object({
|
|
16550
17564
|
methods: array(string()).readonly(),
|
|
16551
17565
|
probedAt: number()
|
|
16552
17566
|
});
|
|
@@ -16609,16 +17623,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
16609
17623
|
format: ModelFormatSchema,
|
|
16610
17624
|
reason: string()
|
|
16611
17625
|
});
|
|
16612
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
16613
|
-
prefer: HwAccelBackendInputSchema,
|
|
16614
|
-
nodeId: string().optional()
|
|
16615
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
16616
|
-
kind: "mutation",
|
|
16617
|
-
auth: "admin"
|
|
16618
|
-
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
16619
|
-
kind: "mutation",
|
|
16620
|
-
auth: "admin"
|
|
16621
|
-
});
|
|
17626
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema);
|
|
16622
17627
|
var PtzPresetSchema = object({
|
|
16623
17628
|
id: string(),
|
|
16624
17629
|
name: string()
|
|
@@ -16671,6 +17676,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
16671
17676
|
kind: "mutation",
|
|
16672
17677
|
auth: "admin"
|
|
16673
17678
|
});
|
|
17679
|
+
/**
|
|
17680
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
17681
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
17682
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
17683
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
17684
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
17685
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
17686
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
17687
|
+
* (`interfaces/recording-config.ts`).
|
|
17688
|
+
*/
|
|
16674
17689
|
var RecordingStatusSchema = object({
|
|
16675
17690
|
deviceId: number(),
|
|
16676
17691
|
enabled: boolean(),
|
|
@@ -18307,6 +19322,12 @@ Object.freeze({
|
|
|
18307
19322
|
addonId: null,
|
|
18308
19323
|
access: "view"
|
|
18309
19324
|
},
|
|
19325
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
19326
|
+
capName: "device-manager",
|
|
19327
|
+
capScope: "system",
|
|
19328
|
+
addonId: null,
|
|
19329
|
+
access: "view"
|
|
19330
|
+
},
|
|
18310
19331
|
"deviceManager.getSettingsSchema": {
|
|
18311
19332
|
capName: "device-manager",
|
|
18312
19333
|
capScope: "system",
|
|
@@ -18457,6 +19478,12 @@ Object.freeze({
|
|
|
18457
19478
|
addonId: null,
|
|
18458
19479
|
access: "create"
|
|
18459
19480
|
},
|
|
19481
|
+
"deviceManager.setDisplay": {
|
|
19482
|
+
capName: "device-manager",
|
|
19483
|
+
capScope: "system",
|
|
19484
|
+
addonId: null,
|
|
19485
|
+
access: "create"
|
|
19486
|
+
},
|
|
18460
19487
|
"deviceManager.setIntegrationId": {
|
|
18461
19488
|
capName: "device-manager",
|
|
18462
19489
|
capScope: "system",
|
|
@@ -18499,6 +19526,12 @@ Object.freeze({
|
|
|
18499
19526
|
addonId: null,
|
|
18500
19527
|
access: "create"
|
|
18501
19528
|
},
|
|
19529
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
19530
|
+
capName: "device-manager",
|
|
19531
|
+
capScope: "system",
|
|
19532
|
+
addonId: null,
|
|
19533
|
+
access: "create"
|
|
19534
|
+
},
|
|
18502
19535
|
"deviceManager.setStreamProfileMap": {
|
|
18503
19536
|
capName: "device-manager",
|
|
18504
19537
|
capScope: "system",
|
|
@@ -19549,6 +20582,66 @@ Object.freeze({
|
|
|
19549
20582
|
addonId: null,
|
|
19550
20583
|
access: "create"
|
|
19551
20584
|
},
|
|
20585
|
+
"petFeeder.callPet": {
|
|
20586
|
+
capName: "pet-feeder",
|
|
20587
|
+
capScope: "device",
|
|
20588
|
+
addonId: null,
|
|
20589
|
+
access: "create"
|
|
20590
|
+
},
|
|
20591
|
+
"petFeeder.cancelFeed": {
|
|
20592
|
+
capName: "pet-feeder",
|
|
20593
|
+
capScope: "device",
|
|
20594
|
+
addonId: null,
|
|
20595
|
+
access: "create"
|
|
20596
|
+
},
|
|
20597
|
+
"petFeeder.feed": {
|
|
20598
|
+
capName: "pet-feeder",
|
|
20599
|
+
capScope: "device",
|
|
20600
|
+
addonId: null,
|
|
20601
|
+
access: "create"
|
|
20602
|
+
},
|
|
20603
|
+
"petFeeder.markFoodReplenished": {
|
|
20604
|
+
capName: "pet-feeder",
|
|
20605
|
+
capScope: "device",
|
|
20606
|
+
addonId: null,
|
|
20607
|
+
access: "create"
|
|
20608
|
+
},
|
|
20609
|
+
"petFeeder.playSound": {
|
|
20610
|
+
capName: "pet-feeder",
|
|
20611
|
+
capScope: "device",
|
|
20612
|
+
addonId: null,
|
|
20613
|
+
access: "create"
|
|
20614
|
+
},
|
|
20615
|
+
"petFeeder.resetDesiccant": {
|
|
20616
|
+
capName: "pet-feeder",
|
|
20617
|
+
capScope: "device",
|
|
20618
|
+
addonId: null,
|
|
20619
|
+
access: "delete"
|
|
20620
|
+
},
|
|
20621
|
+
"petFeeder.setChildLock": {
|
|
20622
|
+
capName: "pet-feeder",
|
|
20623
|
+
capScope: "device",
|
|
20624
|
+
addonId: null,
|
|
20625
|
+
access: "create"
|
|
20626
|
+
},
|
|
20627
|
+
"petFeeder.setFeedSound": {
|
|
20628
|
+
capName: "pet-feeder",
|
|
20629
|
+
capScope: "device",
|
|
20630
|
+
addonId: null,
|
|
20631
|
+
access: "create"
|
|
20632
|
+
},
|
|
20633
|
+
"petFeeder.setIndicatorLight": {
|
|
20634
|
+
capName: "pet-feeder",
|
|
20635
|
+
capScope: "device",
|
|
20636
|
+
addonId: null,
|
|
20637
|
+
access: "create"
|
|
20638
|
+
},
|
|
20639
|
+
"petFeeder.setVolume": {
|
|
20640
|
+
capName: "pet-feeder",
|
|
20641
|
+
capScope: "device",
|
|
20642
|
+
addonId: null,
|
|
20643
|
+
access: "create"
|
|
20644
|
+
},
|
|
19552
20645
|
"pipelineAnalytics.clearTracks": {
|
|
19553
20646
|
capName: "pipeline-analytics",
|
|
19554
20647
|
capScope: "device",
|
|
@@ -20155,30 +21248,6 @@ Object.freeze({
|
|
|
20155
21248
|
addonId: null,
|
|
20156
21249
|
access: "view"
|
|
20157
21250
|
},
|
|
20158
|
-
"platformProbe.getHardwareDecodeAccels": {
|
|
20159
|
-
capName: "platform-probe",
|
|
20160
|
-
capScope: "system",
|
|
20161
|
-
addonId: null,
|
|
20162
|
-
access: "view"
|
|
20163
|
-
},
|
|
20164
|
-
"platformProbe.getHardwareEncoders": {
|
|
20165
|
-
capName: "platform-probe",
|
|
20166
|
-
capScope: "system",
|
|
20167
|
-
addonId: null,
|
|
20168
|
-
access: "view"
|
|
20169
|
-
},
|
|
20170
|
-
"platformProbe.refreshHardwareDecodeAccels": {
|
|
20171
|
-
capName: "platform-probe",
|
|
20172
|
-
capScope: "system",
|
|
20173
|
-
addonId: null,
|
|
20174
|
-
access: "create"
|
|
20175
|
-
},
|
|
20176
|
-
"platformProbe.refreshHardwareEncoders": {
|
|
20177
|
-
capName: "platform-probe",
|
|
20178
|
-
capScope: "system",
|
|
20179
|
-
addonId: null,
|
|
20180
|
-
access: "create"
|
|
20181
|
-
},
|
|
20182
21251
|
"platformProbe.resolveHwAccel": {
|
|
20183
21252
|
capName: "platform-probe",
|
|
20184
21253
|
capScope: "system",
|