@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
|
@@ -4652,7 +4652,7 @@ function _instanceof(cls, params = {}) {
|
|
|
4652
4652
|
return inst;
|
|
4653
4653
|
}
|
|
4654
4654
|
//#endregion
|
|
4655
|
-
//#region ../types/dist/sleep-
|
|
4655
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4656
4656
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4657
4657
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4658
4658
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5465,6 +5465,100 @@ function createDurableState(deps) {
|
|
|
5465
5465
|
};
|
|
5466
5466
|
}
|
|
5467
5467
|
/**
|
|
5468
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5469
|
+
*
|
|
5470
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5471
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5472
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5473
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5474
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5475
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5476
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5477
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5478
|
+
*
|
|
5479
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5480
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5481
|
+
* schema and routes reads/writes through these helpers.
|
|
5482
|
+
*
|
|
5483
|
+
* ## No bare-key fallback — deliberate
|
|
5484
|
+
*
|
|
5485
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5486
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5487
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5488
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5489
|
+
* selection can never leak onto another. (This generalizes the
|
|
5490
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5491
|
+
* arbitrary set of per-node field keys.)
|
|
5492
|
+
*
|
|
5493
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5494
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5495
|
+
*/
|
|
5496
|
+
/**
|
|
5497
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5498
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5499
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5500
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5501
|
+
*/
|
|
5502
|
+
function normalizeNodeId(raw) {
|
|
5503
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5504
|
+
const slashIdx = raw.indexOf("/");
|
|
5505
|
+
if (slashIdx < 0) return raw;
|
|
5506
|
+
const bare = raw.slice(0, slashIdx);
|
|
5507
|
+
return bare === "" ? "hub" : bare;
|
|
5508
|
+
}
|
|
5509
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5510
|
+
function nodeScopedKey(base, nodeId) {
|
|
5511
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5512
|
+
}
|
|
5513
|
+
/**
|
|
5514
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5515
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5516
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5517
|
+
* schema `default` win on `undefined`.
|
|
5518
|
+
*/
|
|
5519
|
+
function readNodeValue(store, base, nodeId) {
|
|
5520
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5521
|
+
}
|
|
5522
|
+
/**
|
|
5523
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5524
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5525
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5526
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5527
|
+
* patch is not mutated.
|
|
5528
|
+
*/
|
|
5529
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5530
|
+
const out = {};
|
|
5531
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5532
|
+
return out;
|
|
5533
|
+
}
|
|
5534
|
+
/**
|
|
5535
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5536
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5537
|
+
* values:
|
|
5538
|
+
*
|
|
5539
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5540
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5541
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5542
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5543
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5544
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5545
|
+
*
|
|
5546
|
+
* Returns a new object — the input store is not mutated.
|
|
5547
|
+
*/
|
|
5548
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5549
|
+
const out = {};
|
|
5550
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5551
|
+
if (key.includes("@")) continue;
|
|
5552
|
+
if (perNodeKeys.has(key)) continue;
|
|
5553
|
+
out[key] = value;
|
|
5554
|
+
}
|
|
5555
|
+
for (const base of perNodeKeys) {
|
|
5556
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5557
|
+
if (value !== void 0) out[base] = value;
|
|
5558
|
+
}
|
|
5559
|
+
return out;
|
|
5560
|
+
}
|
|
5561
|
+
/**
|
|
5468
5562
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5469
5563
|
*
|
|
5470
5564
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5632,23 +5726,63 @@ var BaseAddon = class {
|
|
|
5632
5726
|
deviceSettingsSchema() {
|
|
5633
5727
|
return null;
|
|
5634
5728
|
}
|
|
5635
|
-
async getGlobalSettings(overlay, cap,
|
|
5729
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5636
5730
|
const schema = this.globalSettingsSchema(cap);
|
|
5637
5731
|
if (!schema) return { sections: [] };
|
|
5638
|
-
const
|
|
5732
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5639
5733
|
return hydrateSchema(schema, overlay ? {
|
|
5640
|
-
...
|
|
5734
|
+
...projected,
|
|
5641
5735
|
...overlay
|
|
5642
|
-
} :
|
|
5736
|
+
} : projected);
|
|
5643
5737
|
}
|
|
5644
|
-
|
|
5645
|
-
|
|
5738
|
+
/**
|
|
5739
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5740
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5741
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5742
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5743
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5744
|
+
*
|
|
5745
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5746
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5747
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5748
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5749
|
+
*/
|
|
5750
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5751
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5752
|
+
const keys = this.perNodeKeys(cap);
|
|
5753
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5754
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5755
|
+
}
|
|
5756
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5757
|
+
const keys = this.perNodeKeys();
|
|
5758
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5759
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5760
|
+
const barePatch = patch;
|
|
5761
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5762
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5763
|
+
if (target !== localNode) return;
|
|
5646
5764
|
await this.resolveConfig();
|
|
5647
5765
|
await this.onConfigChanged();
|
|
5648
5766
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5649
5767
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5650
5768
|
}
|
|
5651
5769
|
/**
|
|
5770
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5771
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5772
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5773
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5774
|
+
*/
|
|
5775
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5776
|
+
perNodeKeys(cap) {
|
|
5777
|
+
const cacheKey = cap ?? "";
|
|
5778
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5779
|
+
if (cached) return cached;
|
|
5780
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5781
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5782
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5783
|
+
return keys;
|
|
5784
|
+
}
|
|
5785
|
+
/**
|
|
5652
5786
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5653
5787
|
* schedule an addon restart for the next tick. Deferred via
|
|
5654
5788
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5801,12 +5935,19 @@ var BaseAddon = class {
|
|
|
5801
5935
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5802
5936
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5803
5937
|
* (e.g. from older versions) without polluting the typed config.
|
|
5938
|
+
*
|
|
5939
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5940
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5941
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5942
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5804
5943
|
*/
|
|
5805
5944
|
async resolveConfig() {
|
|
5806
5945
|
const stored = await this.readAddonStoreWithRetry();
|
|
5946
|
+
const perNode = this.perNodeKeys();
|
|
5947
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5807
5948
|
const resolved = { ...this.defaults };
|
|
5808
5949
|
for (const key of Object.keys(this.defaults)) {
|
|
5809
|
-
const storedValue = stored[key];
|
|
5950
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5810
5951
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5811
5952
|
const defaultType = typeof this.defaults[key];
|
|
5812
5953
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5890,6 +6031,27 @@ var BaseAddon = class {
|
|
|
5890
6031
|
}
|
|
5891
6032
|
};
|
|
5892
6033
|
/**
|
|
6034
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6035
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6036
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6037
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6038
|
+
*/
|
|
6039
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6040
|
+
const collected = [];
|
|
6041
|
+
for (const field of fields) {
|
|
6042
|
+
if (field.type === "group") {
|
|
6043
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6044
|
+
continue;
|
|
6045
|
+
}
|
|
6046
|
+
if (field.type === "sub-tabs") {
|
|
6047
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6048
|
+
continue;
|
|
6049
|
+
}
|
|
6050
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6051
|
+
}
|
|
6052
|
+
return collected;
|
|
6053
|
+
}
|
|
6054
|
+
/**
|
|
5893
6055
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5894
6056
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5895
6057
|
* envelopes pass through; void stays void.
|
|
@@ -6297,6 +6459,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6297
6459
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6298
6460
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6299
6461
|
DeviceType["Image"] = "image";
|
|
6462
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6463
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6464
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6465
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6466
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6467
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6468
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6300
6469
|
return DeviceType;
|
|
6301
6470
|
}({});
|
|
6302
6471
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7445,6 +7614,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7445
7614
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7446
7615
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7447
7616
|
/**
|
|
7617
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7618
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7619
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7620
|
+
*/
|
|
7621
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7622
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7623
|
+
var ExpressionParseError = class extends Error {
|
|
7624
|
+
position;
|
|
7625
|
+
constructor(message, position) {
|
|
7626
|
+
super(message);
|
|
7627
|
+
this.name = "ExpressionParseError";
|
|
7628
|
+
this.position = position;
|
|
7629
|
+
}
|
|
7630
|
+
};
|
|
7631
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7632
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7633
|
+
var ExpressionEvalError = class extends Error {
|
|
7634
|
+
constructor(message) {
|
|
7635
|
+
super(message);
|
|
7636
|
+
this.name = "ExpressionEvalError";
|
|
7637
|
+
}
|
|
7638
|
+
};
|
|
7639
|
+
/**
|
|
7640
|
+
* Resource-bound constants for the safe expression engine.
|
|
7641
|
+
*
|
|
7642
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7643
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7644
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7645
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7646
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7647
|
+
*/
|
|
7648
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7649
|
+
* rejected without allocation. */
|
|
7650
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7651
|
+
/** A legal binding / identifier name. */
|
|
7652
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7653
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7654
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7655
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7656
|
+
"now",
|
|
7657
|
+
"true",
|
|
7658
|
+
"false",
|
|
7659
|
+
"null"
|
|
7660
|
+
]);
|
|
7661
|
+
/**
|
|
7662
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7663
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7664
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7665
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7666
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7667
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7668
|
+
* template literals are lexically impossible.
|
|
7669
|
+
*/
|
|
7670
|
+
var KEYWORDS = new Set([
|
|
7671
|
+
"true",
|
|
7672
|
+
"false",
|
|
7673
|
+
"null"
|
|
7674
|
+
]);
|
|
7675
|
+
function isDigit(ch) {
|
|
7676
|
+
return ch >= "0" && ch <= "9";
|
|
7677
|
+
}
|
|
7678
|
+
function isIdentStart(ch) {
|
|
7679
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7680
|
+
}
|
|
7681
|
+
function isIdentPart(ch) {
|
|
7682
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7683
|
+
}
|
|
7684
|
+
function isWhitespace(ch) {
|
|
7685
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7686
|
+
}
|
|
7687
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7688
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7689
|
+
* string. */
|
|
7690
|
+
function tokenize(source) {
|
|
7691
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7692
|
+
const tokens = [];
|
|
7693
|
+
let i = 0;
|
|
7694
|
+
const n = source.length;
|
|
7695
|
+
while (i < n) {
|
|
7696
|
+
const ch = source[i];
|
|
7697
|
+
if (isWhitespace(ch)) {
|
|
7698
|
+
i += 1;
|
|
7699
|
+
continue;
|
|
7700
|
+
}
|
|
7701
|
+
if (isDigit(ch)) {
|
|
7702
|
+
const start = i;
|
|
7703
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7704
|
+
if (i < n && source[i] === ".") {
|
|
7705
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7706
|
+
i += 1;
|
|
7707
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7708
|
+
}
|
|
7709
|
+
const text = source.slice(start, i);
|
|
7710
|
+
const value = Number(text);
|
|
7711
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7712
|
+
tokens.push({
|
|
7713
|
+
type: "number",
|
|
7714
|
+
value,
|
|
7715
|
+
pos: start
|
|
7716
|
+
});
|
|
7717
|
+
continue;
|
|
7718
|
+
}
|
|
7719
|
+
if (ch === "'" || ch === "\"") {
|
|
7720
|
+
const quote = ch;
|
|
7721
|
+
const start = i;
|
|
7722
|
+
i += 1;
|
|
7723
|
+
let out = "";
|
|
7724
|
+
let closed = false;
|
|
7725
|
+
while (i < n) {
|
|
7726
|
+
const c = source[i];
|
|
7727
|
+
if (c === "\\") {
|
|
7728
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7729
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7730
|
+
out += next;
|
|
7731
|
+
i += 2;
|
|
7732
|
+
continue;
|
|
7733
|
+
}
|
|
7734
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7735
|
+
}
|
|
7736
|
+
if (c === quote) {
|
|
7737
|
+
closed = true;
|
|
7738
|
+
i += 1;
|
|
7739
|
+
break;
|
|
7740
|
+
}
|
|
7741
|
+
out += c;
|
|
7742
|
+
i += 1;
|
|
7743
|
+
}
|
|
7744
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7745
|
+
tokens.push({
|
|
7746
|
+
type: "string",
|
|
7747
|
+
value: out,
|
|
7748
|
+
pos: start
|
|
7749
|
+
});
|
|
7750
|
+
continue;
|
|
7751
|
+
}
|
|
7752
|
+
if (isIdentStart(ch)) {
|
|
7753
|
+
const start = i;
|
|
7754
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7755
|
+
const text = source.slice(start, i);
|
|
7756
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7757
|
+
type: "keyword",
|
|
7758
|
+
keyword: keywordOf(text),
|
|
7759
|
+
pos: start
|
|
7760
|
+
});
|
|
7761
|
+
else tokens.push({
|
|
7762
|
+
type: "identifier",
|
|
7763
|
+
name: text,
|
|
7764
|
+
pos: start
|
|
7765
|
+
});
|
|
7766
|
+
continue;
|
|
7767
|
+
}
|
|
7768
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7769
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7770
|
+
tokens.push({
|
|
7771
|
+
type: "punct",
|
|
7772
|
+
punct: two,
|
|
7773
|
+
pos: i
|
|
7774
|
+
});
|
|
7775
|
+
i += 2;
|
|
7776
|
+
continue;
|
|
7777
|
+
}
|
|
7778
|
+
if (isSinglePunct(ch)) {
|
|
7779
|
+
tokens.push({
|
|
7780
|
+
type: "punct",
|
|
7781
|
+
punct: ch,
|
|
7782
|
+
pos: i
|
|
7783
|
+
});
|
|
7784
|
+
i += 1;
|
|
7785
|
+
continue;
|
|
7786
|
+
}
|
|
7787
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7788
|
+
}
|
|
7789
|
+
tokens.push({
|
|
7790
|
+
type: "eof",
|
|
7791
|
+
pos: n
|
|
7792
|
+
});
|
|
7793
|
+
return tokens;
|
|
7794
|
+
}
|
|
7795
|
+
function keywordOf(text) {
|
|
7796
|
+
if (text === "true") return "true";
|
|
7797
|
+
if (text === "false") return "false";
|
|
7798
|
+
return "null";
|
|
7799
|
+
}
|
|
7800
|
+
function isSinglePunct(ch) {
|
|
7801
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7802
|
+
}
|
|
7803
|
+
/**
|
|
7804
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7805
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7806
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7807
|
+
* own-property check against it.
|
|
7808
|
+
*
|
|
7809
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7810
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7811
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7812
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7813
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7814
|
+
*
|
|
7815
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7816
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7817
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7818
|
+
* closed rather than emitting a garbage value.
|
|
7819
|
+
*/
|
|
7820
|
+
function asFiniteNumber(value, name, index) {
|
|
7821
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7822
|
+
return value;
|
|
7823
|
+
}
|
|
7824
|
+
function asString$1(value, name, index) {
|
|
7825
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7826
|
+
return value;
|
|
7827
|
+
}
|
|
7828
|
+
function finiteResult(value, name) {
|
|
7829
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7830
|
+
return value;
|
|
7831
|
+
}
|
|
7832
|
+
function allFiniteNumbers(args, name) {
|
|
7833
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7834
|
+
}
|
|
7835
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7836
|
+
var table = {
|
|
7837
|
+
min: {
|
|
7838
|
+
minArgs: 1,
|
|
7839
|
+
maxArgs: INF,
|
|
7840
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7841
|
+
},
|
|
7842
|
+
max: {
|
|
7843
|
+
minArgs: 1,
|
|
7844
|
+
maxArgs: INF,
|
|
7845
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7846
|
+
},
|
|
7847
|
+
abs: {
|
|
7848
|
+
minArgs: 1,
|
|
7849
|
+
maxArgs: 1,
|
|
7850
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7851
|
+
},
|
|
7852
|
+
floor: {
|
|
7853
|
+
minArgs: 1,
|
|
7854
|
+
maxArgs: 1,
|
|
7855
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7856
|
+
},
|
|
7857
|
+
ceil: {
|
|
7858
|
+
minArgs: 1,
|
|
7859
|
+
maxArgs: 1,
|
|
7860
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7861
|
+
},
|
|
7862
|
+
sqrt: {
|
|
7863
|
+
minArgs: 1,
|
|
7864
|
+
maxArgs: 1,
|
|
7865
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7866
|
+
},
|
|
7867
|
+
round: {
|
|
7868
|
+
minArgs: 1,
|
|
7869
|
+
maxArgs: 2,
|
|
7870
|
+
apply: (args) => {
|
|
7871
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7872
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7873
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7874
|
+
const factor = 10 ** digits;
|
|
7875
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7876
|
+
}
|
|
7877
|
+
},
|
|
7878
|
+
pow: {
|
|
7879
|
+
minArgs: 2,
|
|
7880
|
+
maxArgs: 2,
|
|
7881
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7882
|
+
},
|
|
7883
|
+
clamp: {
|
|
7884
|
+
minArgs: 3,
|
|
7885
|
+
maxArgs: 3,
|
|
7886
|
+
apply: (args) => {
|
|
7887
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7888
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7889
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7890
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7891
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7892
|
+
}
|
|
7893
|
+
},
|
|
7894
|
+
avg: {
|
|
7895
|
+
minArgs: 1,
|
|
7896
|
+
maxArgs: INF,
|
|
7897
|
+
apply: (args) => {
|
|
7898
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7899
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7900
|
+
}
|
|
7901
|
+
},
|
|
7902
|
+
sum: {
|
|
7903
|
+
minArgs: 1,
|
|
7904
|
+
maxArgs: INF,
|
|
7905
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7906
|
+
},
|
|
7907
|
+
coalesce: {
|
|
7908
|
+
minArgs: 1,
|
|
7909
|
+
maxArgs: INF,
|
|
7910
|
+
apply: (args) => {
|
|
7911
|
+
for (const a of args) if (a !== null) return a;
|
|
7912
|
+
return null;
|
|
7913
|
+
}
|
|
7914
|
+
},
|
|
7915
|
+
age: {
|
|
7916
|
+
minArgs: 2,
|
|
7917
|
+
maxArgs: 2,
|
|
7918
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7919
|
+
},
|
|
7920
|
+
convert: {
|
|
7921
|
+
minArgs: 3,
|
|
7922
|
+
maxArgs: 3,
|
|
7923
|
+
apply: (args, hooks) => {
|
|
7924
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7925
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7926
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7927
|
+
if (hooks.convert) {
|
|
7928
|
+
const out = hooks.convert(x, from, to);
|
|
7929
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7930
|
+
return finiteResult(out, "convert");
|
|
7931
|
+
}
|
|
7932
|
+
if (from === to) return x;
|
|
7933
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7934
|
+
}
|
|
7935
|
+
}
|
|
7936
|
+
};
|
|
7937
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7938
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7939
|
+
* callees at parse time (immediate author feedback). */
|
|
7940
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7941
|
+
/**
|
|
7942
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7943
|
+
*
|
|
7944
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7945
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7946
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7947
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7948
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7949
|
+
* that references a since-removed builtin degrades at read.
|
|
7950
|
+
*
|
|
7951
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7952
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7953
|
+
*/
|
|
7954
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7955
|
+
var BINARY_PRECEDENCE = {
|
|
7956
|
+
"||": 1,
|
|
7957
|
+
"&&": 2,
|
|
7958
|
+
"==": 3,
|
|
7959
|
+
"!=": 3,
|
|
7960
|
+
"<": 4,
|
|
7961
|
+
"<=": 4,
|
|
7962
|
+
">": 4,
|
|
7963
|
+
">=": 4,
|
|
7964
|
+
"+": 5,
|
|
7965
|
+
"-": 5,
|
|
7966
|
+
"*": 6,
|
|
7967
|
+
"/": 6,
|
|
7968
|
+
"%": 6
|
|
7969
|
+
};
|
|
7970
|
+
function isLogicalOp(op) {
|
|
7971
|
+
return op === "&&" || op === "||";
|
|
7972
|
+
}
|
|
7973
|
+
function isBinaryOp(op) {
|
|
7974
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7975
|
+
}
|
|
7976
|
+
var Parser = class {
|
|
7977
|
+
tokens;
|
|
7978
|
+
pos = 0;
|
|
7979
|
+
nodeCount = 0;
|
|
7980
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7981
|
+
callees = /* @__PURE__ */ new Set();
|
|
7982
|
+
constructor(tokens) {
|
|
7983
|
+
this.tokens = tokens;
|
|
7984
|
+
}
|
|
7985
|
+
parse() {
|
|
7986
|
+
const ast = this.parseTernary();
|
|
7987
|
+
const tok = this.peek();
|
|
7988
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
7989
|
+
return {
|
|
7990
|
+
ast,
|
|
7991
|
+
identifiers: this.identifiers,
|
|
7992
|
+
callees: this.callees,
|
|
7993
|
+
nodeCount: this.nodeCount
|
|
7994
|
+
};
|
|
7995
|
+
}
|
|
7996
|
+
peek() {
|
|
7997
|
+
return this.tokens[this.pos];
|
|
7998
|
+
}
|
|
7999
|
+
next() {
|
|
8000
|
+
return this.tokens[this.pos++];
|
|
8001
|
+
}
|
|
8002
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8003
|
+
expectPunct(punct) {
|
|
8004
|
+
const tok = this.peek();
|
|
8005
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8006
|
+
this.pos += 1;
|
|
8007
|
+
}
|
|
8008
|
+
matchPunct(punct) {
|
|
8009
|
+
const tok = this.peek();
|
|
8010
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8011
|
+
this.pos += 1;
|
|
8012
|
+
return true;
|
|
8013
|
+
}
|
|
8014
|
+
return false;
|
|
8015
|
+
}
|
|
8016
|
+
countNode() {
|
|
8017
|
+
this.nodeCount += 1;
|
|
8018
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8019
|
+
}
|
|
8020
|
+
parseTernary() {
|
|
8021
|
+
const test = this.parseBinary(1);
|
|
8022
|
+
if (this.matchPunct("?")) {
|
|
8023
|
+
const consequent = this.parseTernary();
|
|
8024
|
+
this.expectPunct(":");
|
|
8025
|
+
const alternate = this.parseTernary();
|
|
8026
|
+
this.countNode();
|
|
8027
|
+
return {
|
|
8028
|
+
kind: "conditional",
|
|
8029
|
+
test,
|
|
8030
|
+
consequent,
|
|
8031
|
+
alternate
|
|
8032
|
+
};
|
|
8033
|
+
}
|
|
8034
|
+
return test;
|
|
8035
|
+
}
|
|
8036
|
+
parseBinary(minPrec) {
|
|
8037
|
+
let left = this.parseUnary();
|
|
8038
|
+
for (;;) {
|
|
8039
|
+
const tok = this.peek();
|
|
8040
|
+
if (tok.type !== "punct") break;
|
|
8041
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8042
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8043
|
+
const op = tok.punct;
|
|
8044
|
+
this.pos += 1;
|
|
8045
|
+
const right = this.parseBinary(prec + 1);
|
|
8046
|
+
this.countNode();
|
|
8047
|
+
if (isLogicalOp(op)) left = {
|
|
8048
|
+
kind: "logical",
|
|
8049
|
+
op,
|
|
8050
|
+
left,
|
|
8051
|
+
right
|
|
8052
|
+
};
|
|
8053
|
+
else if (isBinaryOp(op)) left = {
|
|
8054
|
+
kind: "binary",
|
|
8055
|
+
op,
|
|
8056
|
+
left,
|
|
8057
|
+
right
|
|
8058
|
+
};
|
|
8059
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8060
|
+
}
|
|
8061
|
+
return left;
|
|
8062
|
+
}
|
|
8063
|
+
parseUnary() {
|
|
8064
|
+
const tok = this.peek();
|
|
8065
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8066
|
+
const op = tok.punct;
|
|
8067
|
+
this.pos += 1;
|
|
8068
|
+
const operand = this.parseUnary();
|
|
8069
|
+
this.countNode();
|
|
8070
|
+
return {
|
|
8071
|
+
kind: "unary",
|
|
8072
|
+
op,
|
|
8073
|
+
operand
|
|
8074
|
+
};
|
|
8075
|
+
}
|
|
8076
|
+
return this.parsePrimary();
|
|
8077
|
+
}
|
|
8078
|
+
parsePrimary() {
|
|
8079
|
+
const tok = this.next();
|
|
8080
|
+
switch (tok.type) {
|
|
8081
|
+
case "number":
|
|
8082
|
+
this.countNode();
|
|
8083
|
+
return {
|
|
8084
|
+
kind: "literal",
|
|
8085
|
+
value: tok.value
|
|
8086
|
+
};
|
|
8087
|
+
case "string":
|
|
8088
|
+
this.countNode();
|
|
8089
|
+
return {
|
|
8090
|
+
kind: "literal",
|
|
8091
|
+
value: tok.value
|
|
8092
|
+
};
|
|
8093
|
+
case "keyword":
|
|
8094
|
+
this.countNode();
|
|
8095
|
+
return {
|
|
8096
|
+
kind: "literal",
|
|
8097
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8098
|
+
};
|
|
8099
|
+
case "identifier": {
|
|
8100
|
+
const nextTok = this.peek();
|
|
8101
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8102
|
+
this.identifiers.add(tok.name);
|
|
8103
|
+
this.countNode();
|
|
8104
|
+
return {
|
|
8105
|
+
kind: "identifier",
|
|
8106
|
+
name: tok.name
|
|
8107
|
+
};
|
|
8108
|
+
}
|
|
8109
|
+
case "punct":
|
|
8110
|
+
if (tok.punct === "(") {
|
|
8111
|
+
const inner = this.parseTernary();
|
|
8112
|
+
this.expectPunct(")");
|
|
8113
|
+
return inner;
|
|
8114
|
+
}
|
|
8115
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8116
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8117
|
+
}
|
|
8118
|
+
}
|
|
8119
|
+
parseCall(callee, pos) {
|
|
8120
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8121
|
+
this.expectPunct("(");
|
|
8122
|
+
const args = [];
|
|
8123
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8124
|
+
args.push(this.parseTernary());
|
|
8125
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8126
|
+
if (this.matchPunct(",")) continue;
|
|
8127
|
+
this.expectPunct(")");
|
|
8128
|
+
break;
|
|
8129
|
+
}
|
|
8130
|
+
this.callees.add(callee);
|
|
8131
|
+
this.countNode();
|
|
8132
|
+
return {
|
|
8133
|
+
kind: "call",
|
|
8134
|
+
callee,
|
|
8135
|
+
args
|
|
8136
|
+
};
|
|
8137
|
+
}
|
|
8138
|
+
};
|
|
8139
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8140
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8141
|
+
function parseExpression(source) {
|
|
8142
|
+
return new Parser(tokenize(source)).parse();
|
|
8143
|
+
}
|
|
8144
|
+
Object.freeze({});
|
|
8145
|
+
/**
|
|
8146
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8147
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8148
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8149
|
+
* one per read on a hot resolve path.
|
|
8150
|
+
*
|
|
8151
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8152
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8153
|
+
* callers is safe and maximises hit rate.
|
|
8154
|
+
*/
|
|
8155
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8156
|
+
function getCached(source) {
|
|
8157
|
+
const hit = cache.get(source);
|
|
8158
|
+
if (hit !== void 0) {
|
|
8159
|
+
cache.delete(source);
|
|
8160
|
+
cache.set(source, hit);
|
|
8161
|
+
return hit;
|
|
8162
|
+
}
|
|
8163
|
+
let result;
|
|
8164
|
+
try {
|
|
8165
|
+
result = {
|
|
8166
|
+
ok: true,
|
|
8167
|
+
parsed: parseExpression(source)
|
|
8168
|
+
};
|
|
8169
|
+
} catch (err) {
|
|
8170
|
+
result = {
|
|
8171
|
+
ok: false,
|
|
8172
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8173
|
+
};
|
|
8174
|
+
}
|
|
8175
|
+
cache.set(source, result);
|
|
8176
|
+
if (cache.size > 256) {
|
|
8177
|
+
const oldest = cache.keys().next().value;
|
|
8178
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8179
|
+
}
|
|
8180
|
+
return result;
|
|
8181
|
+
}
|
|
8182
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8183
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8184
|
+
function compileExpressionSafe(source) {
|
|
8185
|
+
return getCached(source);
|
|
8186
|
+
}
|
|
8187
|
+
/**
|
|
8188
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8189
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8190
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8191
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8192
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8193
|
+
*/
|
|
8194
|
+
function validateExpressionSource(src) {
|
|
8195
|
+
const names = Object.keys(src.bindings);
|
|
8196
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8197
|
+
for (const name of names) {
|
|
8198
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8199
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8200
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8201
|
+
}
|
|
8202
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8203
|
+
if (!compiled.ok) return compiled.error;
|
|
8204
|
+
const bound = new Set(names);
|
|
8205
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8206
|
+
if (id === "now") continue;
|
|
8207
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8208
|
+
}
|
|
8209
|
+
return null;
|
|
8210
|
+
}
|
|
8211
|
+
/**
|
|
7448
8212
|
* Accessory device helpers — shared across drivers.
|
|
7449
8213
|
*
|
|
7450
8214
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -9347,7 +10111,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
9347
10111
|
});
|
|
9348
10112
|
method(object({
|
|
9349
10113
|
deviceId: number(),
|
|
9350
|
-
frame: FrameInputSchema
|
|
10114
|
+
frame: FrameInputSchema.optional(),
|
|
10115
|
+
frameHandle: FrameHandleSchema.optional()
|
|
9351
10116
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
9352
10117
|
deviceId: number(),
|
|
9353
10118
|
detected: boolean(),
|
|
@@ -9594,6 +10359,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
9594
10359
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
9595
10360
|
steps: array(PipelineStepInputSchema).min(1),
|
|
9596
10361
|
frame: FrameInputSchema.optional(),
|
|
10362
|
+
/**
|
|
10363
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
10364
|
+
* the decoded pixels live in. One more member of the one-of
|
|
10365
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
10366
|
+
*/
|
|
10367
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
9597
10368
|
imageBase64: string().optional(),
|
|
9598
10369
|
/**
|
|
9599
10370
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -9803,6 +10574,31 @@ var ReportMotionInputSchema = object({
|
|
|
9803
10574
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
9804
10575
|
});
|
|
9805
10576
|
/**
|
|
10577
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
10578
|
+
* restream-owner model — P2c).
|
|
10579
|
+
*
|
|
10580
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
10581
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
10582
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
10583
|
+
* behavior change.
|
|
10584
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
10585
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
10586
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
10587
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
10588
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
10589
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
10590
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
10591
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
10592
|
+
* dials for the owner's restream.
|
|
10593
|
+
*/
|
|
10594
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
10595
|
+
kind: literal("remote-restream"),
|
|
10596
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
10597
|
+
ownerNodeId: string(),
|
|
10598
|
+
/** Operator override for the owner host the runner dials. */
|
|
10599
|
+
hubHostnameOverride: string().optional()
|
|
10600
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
10601
|
+
/**
|
|
9806
10602
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
9807
10603
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
9808
10604
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -9900,7 +10696,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
9900
10696
|
*/
|
|
9901
10697
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
9902
10698
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
9903
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
10699
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
10700
|
+
/**
|
|
10701
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
10702
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
10703
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
10704
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
10705
|
+
* `remoteSourcingNodes` rollout setting).
|
|
10706
|
+
*/
|
|
10707
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
9904
10708
|
});
|
|
9905
10709
|
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;
|
|
9906
10710
|
/**
|
|
@@ -10265,6 +11069,113 @@ object({
|
|
|
10265
11069
|
lastFetchedAt: number()
|
|
10266
11070
|
});
|
|
10267
11071
|
DeviceType.Sensor;
|
|
11072
|
+
/**
|
|
11073
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
11074
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
11075
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
11076
|
+
*/
|
|
11077
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
11078
|
+
"normal",
|
|
11079
|
+
"offline",
|
|
11080
|
+
"on_batteries"
|
|
11081
|
+
]);
|
|
11082
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
11083
|
+
object({
|
|
11084
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
11085
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
11086
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
11087
|
+
foodLevel: number().nullable(),
|
|
11088
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
11089
|
+
* single-hopper models. */
|
|
11090
|
+
food1: number().nullable(),
|
|
11091
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
11092
|
+
* single-hopper models. */
|
|
11093
|
+
food2: number().nullable(),
|
|
11094
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
11095
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
11096
|
+
* below the feeder's low threshold. */
|
|
11097
|
+
lowFood: boolean(),
|
|
11098
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
11099
|
+
* device has no battery reading. */
|
|
11100
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
11101
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
11102
|
+
* desiccant sensor. */
|
|
11103
|
+
desiccantLeftDays: number().nullable(),
|
|
11104
|
+
/** True while a feed is in progress. */
|
|
11105
|
+
feeding: boolean(),
|
|
11106
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
11107
|
+
* Null until the device has reported a status. */
|
|
11108
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
11109
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
11110
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
11111
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
11112
|
+
error: string().nullable(),
|
|
11113
|
+
/** Raw device error code (0 / null = no error). */
|
|
11114
|
+
errorCode: number().nullable(),
|
|
11115
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
11116
|
+
isDualHopper: boolean(),
|
|
11117
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
11118
|
+
childLock: boolean(),
|
|
11119
|
+
/** Front indicator-light setting. */
|
|
11120
|
+
indicatorLight: boolean(),
|
|
11121
|
+
/** Play a chime when dispensing. */
|
|
11122
|
+
feedSound: boolean(),
|
|
11123
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
11124
|
+
volume: number(),
|
|
11125
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
11126
|
+
lastFetchedAt: number()
|
|
11127
|
+
});
|
|
11128
|
+
DeviceType.PetFeeder, method(object({
|
|
11129
|
+
deviceId: number().int().nonnegative(),
|
|
11130
|
+
grams: gramsPortion.optional(),
|
|
11131
|
+
hopper1: gramsPortion.optional(),
|
|
11132
|
+
hopper2: gramsPortion.optional()
|
|
11133
|
+
}), _void(), {
|
|
11134
|
+
kind: "mutation",
|
|
11135
|
+
auth: "admin"
|
|
11136
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11137
|
+
kind: "mutation",
|
|
11138
|
+
auth: "admin"
|
|
11139
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11140
|
+
kind: "mutation",
|
|
11141
|
+
auth: "admin"
|
|
11142
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11143
|
+
kind: "mutation",
|
|
11144
|
+
auth: "admin"
|
|
11145
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11146
|
+
kind: "mutation",
|
|
11147
|
+
auth: "admin"
|
|
11148
|
+
}), method(object({
|
|
11149
|
+
deviceId: number().int().nonnegative(),
|
|
11150
|
+
soundId: number().int().nonnegative()
|
|
11151
|
+
}), _void(), {
|
|
11152
|
+
kind: "mutation",
|
|
11153
|
+
auth: "admin"
|
|
11154
|
+
}), method(object({
|
|
11155
|
+
deviceId: number().int().nonnegative(),
|
|
11156
|
+
on: boolean()
|
|
11157
|
+
}), _void(), {
|
|
11158
|
+
kind: "mutation",
|
|
11159
|
+
auth: "admin"
|
|
11160
|
+
}), method(object({
|
|
11161
|
+
deviceId: number().int().nonnegative(),
|
|
11162
|
+
on: boolean()
|
|
11163
|
+
}), _void(), {
|
|
11164
|
+
kind: "mutation",
|
|
11165
|
+
auth: "admin"
|
|
11166
|
+
}), method(object({
|
|
11167
|
+
deviceId: number().int().nonnegative(),
|
|
11168
|
+
on: boolean()
|
|
11169
|
+
}), _void(), {
|
|
11170
|
+
kind: "mutation",
|
|
11171
|
+
auth: "admin"
|
|
11172
|
+
}), method(object({
|
|
11173
|
+
deviceId: number().int().nonnegative(),
|
|
11174
|
+
level: number().int().nonnegative()
|
|
11175
|
+
}), _void(), {
|
|
11176
|
+
kind: "mutation",
|
|
11177
|
+
auth: "admin"
|
|
11178
|
+
});
|
|
10268
11179
|
object({
|
|
10269
11180
|
/** Instantaneous power draw in watts. */
|
|
10270
11181
|
watts: number().optional(),
|
|
@@ -12092,10 +13003,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
12092
13003
|
url: string()
|
|
12093
13004
|
}), _void()), method(object({
|
|
12094
13005
|
sessionId: string(),
|
|
12095
|
-
maxCount: number().default(1)
|
|
13006
|
+
maxCount: number().default(1),
|
|
13007
|
+
waitMs: number().optional()
|
|
12096
13008
|
}), array(DecodedFrameSchema)), method(object({
|
|
12097
13009
|
sessionId: string(),
|
|
12098
|
-
maxCount: number().default(1)
|
|
13010
|
+
maxCount: number().default(1),
|
|
13011
|
+
waitMs: number().optional()
|
|
12099
13012
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
12100
13013
|
sessionId: string(),
|
|
12101
13014
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -12382,14 +13295,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
12382
13295
|
collapsed: boolean().optional()
|
|
12383
13296
|
});
|
|
12384
13297
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
12385
|
-
* `device-management.ts`.
|
|
13298
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
13299
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
13300
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
13301
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
13302
|
+
* source device's full re-sync-stable `stableId`. */
|
|
13303
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
13304
|
+
kind: literal("field").optional(),
|
|
13305
|
+
sourceKey: string(),
|
|
13306
|
+
cap: string(),
|
|
13307
|
+
fieldPath: string()
|
|
13308
|
+
});
|
|
13309
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
13310
|
+
kind: literal("literal"),
|
|
13311
|
+
value: union([
|
|
13312
|
+
string(),
|
|
13313
|
+
number(),
|
|
13314
|
+
boolean(),
|
|
13315
|
+
_null()
|
|
13316
|
+
])
|
|
13317
|
+
});
|
|
13318
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
13319
|
+
kind: literal("global"),
|
|
13320
|
+
sourceStableId: string(),
|
|
13321
|
+
cap: string(),
|
|
13322
|
+
fieldPath: string()
|
|
13323
|
+
});
|
|
13324
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
13325
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
13326
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
13327
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
13328
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
13329
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
13330
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
13331
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
13332
|
+
kind: literal("expression"),
|
|
13333
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
13334
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
13335
|
+
DeviceLinkFieldSourceSchema,
|
|
13336
|
+
DeviceLinkLiteralSourceSchema,
|
|
13337
|
+
DeviceLinkGlobalSourceSchema
|
|
13338
|
+
]))
|
|
13339
|
+
}).superRefine((src, ctx) => {
|
|
13340
|
+
const err = validateExpressionSource(src);
|
|
13341
|
+
if (err !== null) ctx.addIssue({
|
|
13342
|
+
code: "custom",
|
|
13343
|
+
message: err,
|
|
13344
|
+
path: ["expr"]
|
|
13345
|
+
});
|
|
13346
|
+
});
|
|
12386
13347
|
var DeviceLinkSchema = object({
|
|
12387
13348
|
id: string(),
|
|
12388
|
-
source:
|
|
12389
|
-
|
|
12390
|
-
|
|
12391
|
-
|
|
12392
|
-
|
|
13349
|
+
source: union([
|
|
13350
|
+
DeviceLinkFieldSourceSchema,
|
|
13351
|
+
DeviceLinkLiteralSourceSchema,
|
|
13352
|
+
DeviceLinkGlobalSourceSchema,
|
|
13353
|
+
DeviceLinkExpressionSourceSchema
|
|
13354
|
+
]),
|
|
12393
13355
|
target: object({
|
|
12394
13356
|
cap: string(),
|
|
12395
13357
|
fieldPath: string(),
|
|
@@ -12418,6 +13380,31 @@ var DeviceLinkSchema = object({
|
|
|
12418
13380
|
})
|
|
12419
13381
|
]).optional()
|
|
12420
13382
|
});
|
|
13383
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
13384
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
13385
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
13386
|
+
unit: string().min(1).optional(),
|
|
13387
|
+
precision: number().int().min(0).max(10).optional()
|
|
13388
|
+
});
|
|
13389
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
13390
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
13391
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
13392
|
+
var DeviceDisplayOverrideSchema = object({
|
|
13393
|
+
icon: string().min(1).optional(),
|
|
13394
|
+
label: string().min(1).optional(),
|
|
13395
|
+
unit: string().min(1).optional(),
|
|
13396
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13397
|
+
hidden: boolean().optional(),
|
|
13398
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
13399
|
+
});
|
|
13400
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
13401
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
13402
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
13403
|
+
var RoleDisplayDefaultSchema = object({
|
|
13404
|
+
unit: string().min(1).optional(),
|
|
13405
|
+
precision: number().int().min(0).max(10).optional(),
|
|
13406
|
+
icon: string().min(1).optional()
|
|
13407
|
+
});
|
|
12421
13408
|
/**
|
|
12422
13409
|
* Serializable projection of a live IDevice.
|
|
12423
13410
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -12473,7 +13460,9 @@ var DeviceInfoSchema = object({
|
|
|
12473
13460
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
12474
13461
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
12475
13462
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
12476
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
13463
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
13464
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13465
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12477
13466
|
});
|
|
12478
13467
|
var ConfigEntrySchema = object({
|
|
12479
13468
|
key: string(),
|
|
@@ -12538,7 +13527,9 @@ var DeviceMetaSchema = object({
|
|
|
12538
13527
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
12539
13528
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
12540
13529
|
* Optional: only present for accessory children that carry a known role. */
|
|
12541
|
-
role: string().nullable().optional()
|
|
13530
|
+
role: string().nullable().optional(),
|
|
13531
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
13532
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
12542
13533
|
});
|
|
12543
13534
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
12544
13535
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -12632,7 +13623,19 @@ method(object({
|
|
|
12632
13623
|
}), _void(), {
|
|
12633
13624
|
kind: "mutation",
|
|
12634
13625
|
auth: "admin"
|
|
12635
|
-
}), method(object({
|
|
13626
|
+
}), method(object({
|
|
13627
|
+
deviceId: number(),
|
|
13628
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
13629
|
+
}), _void(), {
|
|
13630
|
+
kind: "mutation",
|
|
13631
|
+
auth: "admin"
|
|
13632
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
13633
|
+
kind: "mutation",
|
|
13634
|
+
auth: "admin"
|
|
13635
|
+
}), method(object({
|
|
13636
|
+
deviceId: number(),
|
|
13637
|
+
includeSynthesizable: boolean().optional()
|
|
13638
|
+
}), object({ caps: array(object({
|
|
12636
13639
|
cap: string(),
|
|
12637
13640
|
fields: array(object({
|
|
12638
13641
|
path: string(),
|
|
@@ -12642,8 +13645,13 @@ method(object({
|
|
|
12642
13645
|
"boolean",
|
|
12643
13646
|
"enum"
|
|
12644
13647
|
]),
|
|
12645
|
-
enumValues: array(string()).optional()
|
|
12646
|
-
|
|
13648
|
+
enumValues: array(string()).optional(),
|
|
13649
|
+
item: boolean().optional()
|
|
13650
|
+
})).readonly(),
|
|
13651
|
+
itemArray: object({
|
|
13652
|
+
path: string(),
|
|
13653
|
+
keyField: string()
|
|
13654
|
+
}).optional()
|
|
12647
13655
|
})).readonly() }), { kind: "query" }), method(object({
|
|
12648
13656
|
deviceId: number(),
|
|
12649
13657
|
role: string().nullable()
|
|
@@ -12713,7 +13721,11 @@ method(object({
|
|
|
12713
13721
|
deviceId: number(),
|
|
12714
13722
|
entries: array(object({
|
|
12715
13723
|
capName: string(),
|
|
12716
|
-
kind: _enum([
|
|
13724
|
+
kind: _enum([
|
|
13725
|
+
"native",
|
|
13726
|
+
"wrapped",
|
|
13727
|
+
"linked"
|
|
13728
|
+
]),
|
|
12717
13729
|
providerAddonId: string(),
|
|
12718
13730
|
providerNodeId: string(),
|
|
12719
13731
|
nativeAddonId: string()
|
|
@@ -12722,7 +13734,11 @@ method(object({
|
|
|
12722
13734
|
deviceId: number(),
|
|
12723
13735
|
entries: array(object({
|
|
12724
13736
|
capName: string(),
|
|
12725
|
-
kind: _enum([
|
|
13737
|
+
kind: _enum([
|
|
13738
|
+
"native",
|
|
13739
|
+
"wrapped",
|
|
13740
|
+
"linked"
|
|
13741
|
+
]),
|
|
12726
13742
|
providerAddonId: string(),
|
|
12727
13743
|
providerNodeId: string(),
|
|
12728
13744
|
nativeAddonId: string()
|
|
@@ -13964,7 +14980,10 @@ var AgentLoadSummarySchema = object({
|
|
|
13964
14980
|
online: boolean(),
|
|
13965
14981
|
load: RunnerLocalLoadSchema,
|
|
13966
14982
|
/** Computed score used by the L2 capacity balancer (lower = less loaded). */
|
|
13967
|
-
score: number()
|
|
14983
|
+
score: number(),
|
|
14984
|
+
/** This node's decode hwaccel backend (per-node `probedBestHwaccel`), or null
|
|
14985
|
+
* when not yet probed — for the cluster Pipeline table UI (P0.2). */
|
|
14986
|
+
decodeHwaccel: string().nullable()
|
|
13968
14987
|
});
|
|
13969
14988
|
/**
|
|
13970
14989
|
* Aggregate metrics across the whole detection cluster. Replaces the legacy
|
|
@@ -16527,7 +17546,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
16527
17546
|
"webgpu",
|
|
16528
17547
|
"none"
|
|
16529
17548
|
]).nullable().optional();
|
|
16530
|
-
var HwAccelResolutionSchema = object({
|
|
17549
|
+
var HwAccelResolutionSchema = object({
|
|
17550
|
+
preferred: array(string()).readonly(),
|
|
17551
|
+
rationale: string()
|
|
17552
|
+
});
|
|
16531
17553
|
var HardwareEncoderIdSchema = _enum([
|
|
16532
17554
|
"h264_videotoolbox",
|
|
16533
17555
|
"hevc_videotoolbox",
|
|
@@ -16542,7 +17564,7 @@ var HardwareEncoderIdSchema = _enum([
|
|
|
16542
17564
|
"libx264",
|
|
16543
17565
|
"libx265"
|
|
16544
17566
|
]);
|
|
16545
|
-
|
|
17567
|
+
object({
|
|
16546
17568
|
encoders: array(object({
|
|
16547
17569
|
encoder: HardwareEncoderIdSchema,
|
|
16548
17570
|
codec: _enum(["H264", "H265"]),
|
|
@@ -16561,15 +17583,7 @@ var HardwareEncodersSchema = object({
|
|
|
16561
17583
|
defaultH265: HardwareEncoderIdSchema,
|
|
16562
17584
|
probedAt: number()
|
|
16563
17585
|
});
|
|
16564
|
-
|
|
16565
|
-
* Decode-side companion to {@link HardwareEncodersSchema}: the `-hwaccel`
|
|
16566
|
-
* methods the configured ffmpeg binary actually supports (parsed from
|
|
16567
|
-
* `ffmpeg -hwaccels`). Used to gate decode-hwaccel attempts so the transcode
|
|
16568
|
-
* egress never spends a spawn on a backend this build cannot offer. Per-stream
|
|
16569
|
-
* decode fragility (e.g. VideoToolbox HEVC) is still handled by the egress's
|
|
16570
|
-
* software fallback — this only filters out wholly-unsupported backends.
|
|
16571
|
-
*/
|
|
16572
|
-
var HardwareDecodeAccelsSchema = object({
|
|
17586
|
+
object({
|
|
16573
17587
|
methods: array(string()).readonly(),
|
|
16574
17588
|
probedAt: number()
|
|
16575
17589
|
});
|
|
@@ -16632,16 +17646,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
16632
17646
|
format: ModelFormatSchema,
|
|
16633
17647
|
reason: string()
|
|
16634
17648
|
});
|
|
16635
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
16636
|
-
prefer: HwAccelBackendInputSchema,
|
|
16637
|
-
nodeId: string().optional()
|
|
16638
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
16639
|
-
kind: "mutation",
|
|
16640
|
-
auth: "admin"
|
|
16641
|
-
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
16642
|
-
kind: "mutation",
|
|
16643
|
-
auth: "admin"
|
|
16644
|
-
});
|
|
17649
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema);
|
|
16645
17650
|
var PtzPresetSchema = object({
|
|
16646
17651
|
id: string(),
|
|
16647
17652
|
name: string()
|
|
@@ -16694,6 +17699,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
16694
17699
|
kind: "mutation",
|
|
16695
17700
|
auth: "admin"
|
|
16696
17701
|
});
|
|
17702
|
+
/**
|
|
17703
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
17704
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
17705
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
17706
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
17707
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
17708
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
17709
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
17710
|
+
* (`interfaces/recording-config.ts`).
|
|
17711
|
+
*/
|
|
16697
17712
|
var RecordingStatusSchema = object({
|
|
16698
17713
|
deviceId: number(),
|
|
16699
17714
|
enabled: boolean(),
|
|
@@ -18330,6 +19345,12 @@ Object.freeze({
|
|
|
18330
19345
|
addonId: null,
|
|
18331
19346
|
access: "view"
|
|
18332
19347
|
},
|
|
19348
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
19349
|
+
capName: "device-manager",
|
|
19350
|
+
capScope: "system",
|
|
19351
|
+
addonId: null,
|
|
19352
|
+
access: "view"
|
|
19353
|
+
},
|
|
18333
19354
|
"deviceManager.getSettingsSchema": {
|
|
18334
19355
|
capName: "device-manager",
|
|
18335
19356
|
capScope: "system",
|
|
@@ -18480,6 +19501,12 @@ Object.freeze({
|
|
|
18480
19501
|
addonId: null,
|
|
18481
19502
|
access: "create"
|
|
18482
19503
|
},
|
|
19504
|
+
"deviceManager.setDisplay": {
|
|
19505
|
+
capName: "device-manager",
|
|
19506
|
+
capScope: "system",
|
|
19507
|
+
addonId: null,
|
|
19508
|
+
access: "create"
|
|
19509
|
+
},
|
|
18483
19510
|
"deviceManager.setIntegrationId": {
|
|
18484
19511
|
capName: "device-manager",
|
|
18485
19512
|
capScope: "system",
|
|
@@ -18522,6 +19549,12 @@ Object.freeze({
|
|
|
18522
19549
|
addonId: null,
|
|
18523
19550
|
access: "create"
|
|
18524
19551
|
},
|
|
19552
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
19553
|
+
capName: "device-manager",
|
|
19554
|
+
capScope: "system",
|
|
19555
|
+
addonId: null,
|
|
19556
|
+
access: "create"
|
|
19557
|
+
},
|
|
18525
19558
|
"deviceManager.setStreamProfileMap": {
|
|
18526
19559
|
capName: "device-manager",
|
|
18527
19560
|
capScope: "system",
|
|
@@ -19572,6 +20605,66 @@ Object.freeze({
|
|
|
19572
20605
|
addonId: null,
|
|
19573
20606
|
access: "create"
|
|
19574
20607
|
},
|
|
20608
|
+
"petFeeder.callPet": {
|
|
20609
|
+
capName: "pet-feeder",
|
|
20610
|
+
capScope: "device",
|
|
20611
|
+
addonId: null,
|
|
20612
|
+
access: "create"
|
|
20613
|
+
},
|
|
20614
|
+
"petFeeder.cancelFeed": {
|
|
20615
|
+
capName: "pet-feeder",
|
|
20616
|
+
capScope: "device",
|
|
20617
|
+
addonId: null,
|
|
20618
|
+
access: "create"
|
|
20619
|
+
},
|
|
20620
|
+
"petFeeder.feed": {
|
|
20621
|
+
capName: "pet-feeder",
|
|
20622
|
+
capScope: "device",
|
|
20623
|
+
addonId: null,
|
|
20624
|
+
access: "create"
|
|
20625
|
+
},
|
|
20626
|
+
"petFeeder.markFoodReplenished": {
|
|
20627
|
+
capName: "pet-feeder",
|
|
20628
|
+
capScope: "device",
|
|
20629
|
+
addonId: null,
|
|
20630
|
+
access: "create"
|
|
20631
|
+
},
|
|
20632
|
+
"petFeeder.playSound": {
|
|
20633
|
+
capName: "pet-feeder",
|
|
20634
|
+
capScope: "device",
|
|
20635
|
+
addonId: null,
|
|
20636
|
+
access: "create"
|
|
20637
|
+
},
|
|
20638
|
+
"petFeeder.resetDesiccant": {
|
|
20639
|
+
capName: "pet-feeder",
|
|
20640
|
+
capScope: "device",
|
|
20641
|
+
addonId: null,
|
|
20642
|
+
access: "delete"
|
|
20643
|
+
},
|
|
20644
|
+
"petFeeder.setChildLock": {
|
|
20645
|
+
capName: "pet-feeder",
|
|
20646
|
+
capScope: "device",
|
|
20647
|
+
addonId: null,
|
|
20648
|
+
access: "create"
|
|
20649
|
+
},
|
|
20650
|
+
"petFeeder.setFeedSound": {
|
|
20651
|
+
capName: "pet-feeder",
|
|
20652
|
+
capScope: "device",
|
|
20653
|
+
addonId: null,
|
|
20654
|
+
access: "create"
|
|
20655
|
+
},
|
|
20656
|
+
"petFeeder.setIndicatorLight": {
|
|
20657
|
+
capName: "pet-feeder",
|
|
20658
|
+
capScope: "device",
|
|
20659
|
+
addonId: null,
|
|
20660
|
+
access: "create"
|
|
20661
|
+
},
|
|
20662
|
+
"petFeeder.setVolume": {
|
|
20663
|
+
capName: "pet-feeder",
|
|
20664
|
+
capScope: "device",
|
|
20665
|
+
addonId: null,
|
|
20666
|
+
access: "create"
|
|
20667
|
+
},
|
|
19575
20668
|
"pipelineAnalytics.clearTracks": {
|
|
19576
20669
|
capName: "pipeline-analytics",
|
|
19577
20670
|
capScope: "device",
|
|
@@ -20178,30 +21271,6 @@ Object.freeze({
|
|
|
20178
21271
|
addonId: null,
|
|
20179
21272
|
access: "view"
|
|
20180
21273
|
},
|
|
20181
|
-
"platformProbe.getHardwareDecodeAccels": {
|
|
20182
|
-
capName: "platform-probe",
|
|
20183
|
-
capScope: "system",
|
|
20184
|
-
addonId: null,
|
|
20185
|
-
access: "view"
|
|
20186
|
-
},
|
|
20187
|
-
"platformProbe.getHardwareEncoders": {
|
|
20188
|
-
capName: "platform-probe",
|
|
20189
|
-
capScope: "system",
|
|
20190
|
-
addonId: null,
|
|
20191
|
-
access: "view"
|
|
20192
|
-
},
|
|
20193
|
-
"platformProbe.refreshHardwareDecodeAccels": {
|
|
20194
|
-
capName: "platform-probe",
|
|
20195
|
-
capScope: "system",
|
|
20196
|
-
addonId: null,
|
|
20197
|
-
access: "create"
|
|
20198
|
-
},
|
|
20199
|
-
"platformProbe.refreshHardwareEncoders": {
|
|
20200
|
-
capName: "platform-probe",
|
|
20201
|
-
capScope: "system",
|
|
20202
|
-
addonId: null,
|
|
20203
|
-
access: "create"
|
|
20204
|
-
},
|
|
20205
21274
|
"platformProbe.resolveHwAccel": {
|
|
20206
21275
|
capName: "platform-probe",
|
|
20207
21276
|
capScope: "system",
|