@camstack/addon-pipeline-orchestrator 1.1.18 → 1.1.20
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/_stub.js +24 -24
- package/dist/{_virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_orchestrator_widgets-w6ra7ZRn.mjs → _virtual_mf-localSharedImportMap___mfe_internal__addon_pipeline_orchestrator_widgets-BM9L-K3j.mjs} +3 -3
- package/dist/_virtual_mf___mfe_internal__addon_pipeline_orchestrator_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-DPNDc6_1.mjs +26 -0
- package/dist/_virtual_mf___mfe_internal__addon_pipeline_orchestrator_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-DdDNCPJ5.mjs +26 -0
- package/dist/{hostInit-q1JBOKO5.mjs → hostInit-Db9cKu1A.mjs} +3 -3
- package/dist/index.js +1118 -64
- package/dist/index.mjs +1118 -64
- package/dist/remoteEntry.js +1 -1
- package/package.json +1 -1
- package/dist/_virtual_mf___mfe_internal__addon_pipeline_orchestrator_widgets__loadShare___mf_0_camstack_mf_1_types__loadShare__.js-BD6i2VnA.mjs +0 -26
- package/dist/_virtual_mf___mfe_internal__addon_pipeline_orchestrator_widgets__loadShare___mf_0_camstack_mf_1_ui_mf_2_library__loadShare__.js-CImHCYiW.mjs +0 -26
package/dist/index.mjs
CHANGED
|
@@ -4627,7 +4627,7 @@ function _instanceof(cls, params = {}) {
|
|
|
4627
4627
|
return inst;
|
|
4628
4628
|
}
|
|
4629
4629
|
//#endregion
|
|
4630
|
-
//#region ../types/dist/sleep-
|
|
4630
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4631
4631
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4632
4632
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4633
4633
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5456,6 +5456,100 @@ function createDurableState(deps) {
|
|
|
5456
5456
|
};
|
|
5457
5457
|
}
|
|
5458
5458
|
/**
|
|
5459
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5460
|
+
*
|
|
5461
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5462
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5463
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5464
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5465
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5466
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5467
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5468
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5469
|
+
*
|
|
5470
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5471
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5472
|
+
* schema and routes reads/writes through these helpers.
|
|
5473
|
+
*
|
|
5474
|
+
* ## No bare-key fallback — deliberate
|
|
5475
|
+
*
|
|
5476
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5477
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5478
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5479
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5480
|
+
* selection can never leak onto another. (This generalizes the
|
|
5481
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5482
|
+
* arbitrary set of per-node field keys.)
|
|
5483
|
+
*
|
|
5484
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5485
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5486
|
+
*/
|
|
5487
|
+
/**
|
|
5488
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5489
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5490
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5491
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5492
|
+
*/
|
|
5493
|
+
function normalizeNodeId(raw) {
|
|
5494
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5495
|
+
const slashIdx = raw.indexOf("/");
|
|
5496
|
+
if (slashIdx < 0) return raw;
|
|
5497
|
+
const bare = raw.slice(0, slashIdx);
|
|
5498
|
+
return bare === "" ? "hub" : bare;
|
|
5499
|
+
}
|
|
5500
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5501
|
+
function nodeScopedKey(base, nodeId) {
|
|
5502
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5503
|
+
}
|
|
5504
|
+
/**
|
|
5505
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5506
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5507
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5508
|
+
* schema `default` win on `undefined`.
|
|
5509
|
+
*/
|
|
5510
|
+
function readNodeValue(store, base, nodeId) {
|
|
5511
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5512
|
+
}
|
|
5513
|
+
/**
|
|
5514
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5515
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5516
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5517
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5518
|
+
* patch is not mutated.
|
|
5519
|
+
*/
|
|
5520
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5521
|
+
const out = {};
|
|
5522
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5523
|
+
return out;
|
|
5524
|
+
}
|
|
5525
|
+
/**
|
|
5526
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5527
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5528
|
+
* values:
|
|
5529
|
+
*
|
|
5530
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5531
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5532
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5533
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5534
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5535
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5536
|
+
*
|
|
5537
|
+
* Returns a new object — the input store is not mutated.
|
|
5538
|
+
*/
|
|
5539
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5540
|
+
const out = {};
|
|
5541
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5542
|
+
if (key.includes("@")) continue;
|
|
5543
|
+
if (perNodeKeys.has(key)) continue;
|
|
5544
|
+
out[key] = value;
|
|
5545
|
+
}
|
|
5546
|
+
for (const base of perNodeKeys) {
|
|
5547
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5548
|
+
if (value !== void 0) out[base] = value;
|
|
5549
|
+
}
|
|
5550
|
+
return out;
|
|
5551
|
+
}
|
|
5552
|
+
/**
|
|
5459
5553
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5460
5554
|
*
|
|
5461
5555
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5623,23 +5717,63 @@ var BaseAddon = class {
|
|
|
5623
5717
|
deviceSettingsSchema() {
|
|
5624
5718
|
return null;
|
|
5625
5719
|
}
|
|
5626
|
-
async getGlobalSettings(overlay, cap,
|
|
5720
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5627
5721
|
const schema = this.globalSettingsSchema(cap);
|
|
5628
5722
|
if (!schema) return { sections: [] };
|
|
5629
|
-
const
|
|
5723
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5630
5724
|
return hydrateSchema(schema, overlay ? {
|
|
5631
|
-
...
|
|
5725
|
+
...projected,
|
|
5632
5726
|
...overlay
|
|
5633
|
-
} :
|
|
5727
|
+
} : projected);
|
|
5634
5728
|
}
|
|
5635
|
-
|
|
5636
|
-
|
|
5729
|
+
/**
|
|
5730
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5731
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5732
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5733
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5734
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5735
|
+
*
|
|
5736
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5737
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5738
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5739
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5740
|
+
*/
|
|
5741
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5742
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5743
|
+
const keys = this.perNodeKeys(cap);
|
|
5744
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5745
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5746
|
+
}
|
|
5747
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5748
|
+
const keys = this.perNodeKeys();
|
|
5749
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5750
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5751
|
+
const barePatch = patch;
|
|
5752
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5753
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5754
|
+
if (target !== localNode) return;
|
|
5637
5755
|
await this.resolveConfig();
|
|
5638
5756
|
await this.onConfigChanged();
|
|
5639
5757
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5640
5758
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5641
5759
|
}
|
|
5642
5760
|
/**
|
|
5761
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5762
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5763
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5764
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5765
|
+
*/
|
|
5766
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5767
|
+
perNodeKeys(cap) {
|
|
5768
|
+
const cacheKey = cap ?? "";
|
|
5769
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5770
|
+
if (cached) return cached;
|
|
5771
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5772
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5773
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5774
|
+
return keys;
|
|
5775
|
+
}
|
|
5776
|
+
/**
|
|
5643
5777
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5644
5778
|
* schedule an addon restart for the next tick. Deferred via
|
|
5645
5779
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5792,12 +5926,19 @@ var BaseAddon = class {
|
|
|
5792
5926
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5793
5927
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5794
5928
|
* (e.g. from older versions) without polluting the typed config.
|
|
5929
|
+
*
|
|
5930
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5931
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5932
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5933
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5795
5934
|
*/
|
|
5796
5935
|
async resolveConfig() {
|
|
5797
5936
|
const stored = await this.readAddonStoreWithRetry();
|
|
5937
|
+
const perNode = this.perNodeKeys();
|
|
5938
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5798
5939
|
const resolved = { ...this.defaults };
|
|
5799
5940
|
for (const key of Object.keys(this.defaults)) {
|
|
5800
|
-
const storedValue = stored[key];
|
|
5941
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5801
5942
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5802
5943
|
const defaultType = typeof this.defaults[key];
|
|
5803
5944
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5881,6 +6022,27 @@ var BaseAddon = class {
|
|
|
5881
6022
|
}
|
|
5882
6023
|
};
|
|
5883
6024
|
/**
|
|
6025
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6026
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6027
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6028
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6029
|
+
*/
|
|
6030
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6031
|
+
const collected = [];
|
|
6032
|
+
for (const field of fields) {
|
|
6033
|
+
if (field.type === "group") {
|
|
6034
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6035
|
+
continue;
|
|
6036
|
+
}
|
|
6037
|
+
if (field.type === "sub-tabs") {
|
|
6038
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6039
|
+
continue;
|
|
6040
|
+
}
|
|
6041
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6042
|
+
}
|
|
6043
|
+
return collected;
|
|
6044
|
+
}
|
|
6045
|
+
/**
|
|
5884
6046
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5885
6047
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5886
6048
|
* envelopes pass through; void stays void.
|
|
@@ -6648,6 +6810,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6648
6810
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6649
6811
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6650
6812
|
DeviceType["Image"] = "image";
|
|
6813
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6814
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6815
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6816
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6817
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6818
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6819
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6651
6820
|
return DeviceType;
|
|
6652
6821
|
}({});
|
|
6653
6822
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7832,6 +8001,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7832
8001
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7833
8002
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7834
8003
|
/**
|
|
8004
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
8005
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
8006
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
8007
|
+
*/
|
|
8008
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
8009
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
8010
|
+
var ExpressionParseError = class extends Error {
|
|
8011
|
+
position;
|
|
8012
|
+
constructor(message, position) {
|
|
8013
|
+
super(message);
|
|
8014
|
+
this.name = "ExpressionParseError";
|
|
8015
|
+
this.position = position;
|
|
8016
|
+
}
|
|
8017
|
+
};
|
|
8018
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
8019
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
8020
|
+
var ExpressionEvalError = class extends Error {
|
|
8021
|
+
constructor(message) {
|
|
8022
|
+
super(message);
|
|
8023
|
+
this.name = "ExpressionEvalError";
|
|
8024
|
+
}
|
|
8025
|
+
};
|
|
8026
|
+
/**
|
|
8027
|
+
* Resource-bound constants for the safe expression engine.
|
|
8028
|
+
*
|
|
8029
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
8030
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
8031
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
8032
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
8033
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
8034
|
+
*/
|
|
8035
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
8036
|
+
* rejected without allocation. */
|
|
8037
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
8038
|
+
/** A legal binding / identifier name. */
|
|
8039
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
8040
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
8041
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
8042
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
8043
|
+
"now",
|
|
8044
|
+
"true",
|
|
8045
|
+
"false",
|
|
8046
|
+
"null"
|
|
8047
|
+
]);
|
|
8048
|
+
/**
|
|
8049
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
8050
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
8051
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
8052
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
8053
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
8054
|
+
* is a parse error with a source position, so member access / assignment /
|
|
8055
|
+
* template literals are lexically impossible.
|
|
8056
|
+
*/
|
|
8057
|
+
var KEYWORDS = new Set([
|
|
8058
|
+
"true",
|
|
8059
|
+
"false",
|
|
8060
|
+
"null"
|
|
8061
|
+
]);
|
|
8062
|
+
function isDigit(ch) {
|
|
8063
|
+
return ch >= "0" && ch <= "9";
|
|
8064
|
+
}
|
|
8065
|
+
function isIdentStart(ch) {
|
|
8066
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
8067
|
+
}
|
|
8068
|
+
function isIdentPart(ch) {
|
|
8069
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
8070
|
+
}
|
|
8071
|
+
function isWhitespace(ch) {
|
|
8072
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
8073
|
+
}
|
|
8074
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
8075
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
8076
|
+
* string. */
|
|
8077
|
+
function tokenize(source) {
|
|
8078
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
8079
|
+
const tokens = [];
|
|
8080
|
+
let i = 0;
|
|
8081
|
+
const n = source.length;
|
|
8082
|
+
while (i < n) {
|
|
8083
|
+
const ch = source[i];
|
|
8084
|
+
if (isWhitespace(ch)) {
|
|
8085
|
+
i += 1;
|
|
8086
|
+
continue;
|
|
8087
|
+
}
|
|
8088
|
+
if (isDigit(ch)) {
|
|
8089
|
+
const start = i;
|
|
8090
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
8091
|
+
if (i < n && source[i] === ".") {
|
|
8092
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
8093
|
+
i += 1;
|
|
8094
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
8095
|
+
}
|
|
8096
|
+
const text = source.slice(start, i);
|
|
8097
|
+
const value = Number(text);
|
|
8098
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
8099
|
+
tokens.push({
|
|
8100
|
+
type: "number",
|
|
8101
|
+
value,
|
|
8102
|
+
pos: start
|
|
8103
|
+
});
|
|
8104
|
+
continue;
|
|
8105
|
+
}
|
|
8106
|
+
if (ch === "'" || ch === "\"") {
|
|
8107
|
+
const quote = ch;
|
|
8108
|
+
const start = i;
|
|
8109
|
+
i += 1;
|
|
8110
|
+
let out = "";
|
|
8111
|
+
let closed = false;
|
|
8112
|
+
while (i < n) {
|
|
8113
|
+
const c = source[i];
|
|
8114
|
+
if (c === "\\") {
|
|
8115
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
8116
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
8117
|
+
out += next;
|
|
8118
|
+
i += 2;
|
|
8119
|
+
continue;
|
|
8120
|
+
}
|
|
8121
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
8122
|
+
}
|
|
8123
|
+
if (c === quote) {
|
|
8124
|
+
closed = true;
|
|
8125
|
+
i += 1;
|
|
8126
|
+
break;
|
|
8127
|
+
}
|
|
8128
|
+
out += c;
|
|
8129
|
+
i += 1;
|
|
8130
|
+
}
|
|
8131
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
8132
|
+
tokens.push({
|
|
8133
|
+
type: "string",
|
|
8134
|
+
value: out,
|
|
8135
|
+
pos: start
|
|
8136
|
+
});
|
|
8137
|
+
continue;
|
|
8138
|
+
}
|
|
8139
|
+
if (isIdentStart(ch)) {
|
|
8140
|
+
const start = i;
|
|
8141
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
8142
|
+
const text = source.slice(start, i);
|
|
8143
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
8144
|
+
type: "keyword",
|
|
8145
|
+
keyword: keywordOf(text),
|
|
8146
|
+
pos: start
|
|
8147
|
+
});
|
|
8148
|
+
else tokens.push({
|
|
8149
|
+
type: "identifier",
|
|
8150
|
+
name: text,
|
|
8151
|
+
pos: start
|
|
8152
|
+
});
|
|
8153
|
+
continue;
|
|
8154
|
+
}
|
|
8155
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
8156
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
8157
|
+
tokens.push({
|
|
8158
|
+
type: "punct",
|
|
8159
|
+
punct: two,
|
|
8160
|
+
pos: i
|
|
8161
|
+
});
|
|
8162
|
+
i += 2;
|
|
8163
|
+
continue;
|
|
8164
|
+
}
|
|
8165
|
+
if (isSinglePunct(ch)) {
|
|
8166
|
+
tokens.push({
|
|
8167
|
+
type: "punct",
|
|
8168
|
+
punct: ch,
|
|
8169
|
+
pos: i
|
|
8170
|
+
});
|
|
8171
|
+
i += 1;
|
|
8172
|
+
continue;
|
|
8173
|
+
}
|
|
8174
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
8175
|
+
}
|
|
8176
|
+
tokens.push({
|
|
8177
|
+
type: "eof",
|
|
8178
|
+
pos: n
|
|
8179
|
+
});
|
|
8180
|
+
return tokens;
|
|
8181
|
+
}
|
|
8182
|
+
function keywordOf(text) {
|
|
8183
|
+
if (text === "true") return "true";
|
|
8184
|
+
if (text === "false") return "false";
|
|
8185
|
+
return "null";
|
|
8186
|
+
}
|
|
8187
|
+
function isSinglePunct(ch) {
|
|
8188
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
8189
|
+
}
|
|
8190
|
+
/**
|
|
8191
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
8192
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
8193
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
8194
|
+
* own-property check against it.
|
|
8195
|
+
*
|
|
8196
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
8197
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
8198
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
8199
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
8200
|
+
* callable — they are simply "unknown function" at parse time.
|
|
8201
|
+
*
|
|
8202
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
8203
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
8204
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
8205
|
+
* closed rather than emitting a garbage value.
|
|
8206
|
+
*/
|
|
8207
|
+
function asFiniteNumber(value, name, index) {
|
|
8208
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
8209
|
+
return value;
|
|
8210
|
+
}
|
|
8211
|
+
function asString$1(value, name, index) {
|
|
8212
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
8213
|
+
return value;
|
|
8214
|
+
}
|
|
8215
|
+
function finiteResult(value, name) {
|
|
8216
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
8217
|
+
return value;
|
|
8218
|
+
}
|
|
8219
|
+
function allFiniteNumbers(args, name) {
|
|
8220
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
8221
|
+
}
|
|
8222
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
8223
|
+
var table = {
|
|
8224
|
+
min: {
|
|
8225
|
+
minArgs: 1,
|
|
8226
|
+
maxArgs: INF,
|
|
8227
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
8228
|
+
},
|
|
8229
|
+
max: {
|
|
8230
|
+
minArgs: 1,
|
|
8231
|
+
maxArgs: INF,
|
|
8232
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
8233
|
+
},
|
|
8234
|
+
abs: {
|
|
8235
|
+
minArgs: 1,
|
|
8236
|
+
maxArgs: 1,
|
|
8237
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
8238
|
+
},
|
|
8239
|
+
floor: {
|
|
8240
|
+
minArgs: 1,
|
|
8241
|
+
maxArgs: 1,
|
|
8242
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
8243
|
+
},
|
|
8244
|
+
ceil: {
|
|
8245
|
+
minArgs: 1,
|
|
8246
|
+
maxArgs: 1,
|
|
8247
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
8248
|
+
},
|
|
8249
|
+
sqrt: {
|
|
8250
|
+
minArgs: 1,
|
|
8251
|
+
maxArgs: 1,
|
|
8252
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
8253
|
+
},
|
|
8254
|
+
round: {
|
|
8255
|
+
minArgs: 1,
|
|
8256
|
+
maxArgs: 2,
|
|
8257
|
+
apply: (args) => {
|
|
8258
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
8259
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
8260
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
8261
|
+
const factor = 10 ** digits;
|
|
8262
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
8263
|
+
}
|
|
8264
|
+
},
|
|
8265
|
+
pow: {
|
|
8266
|
+
minArgs: 2,
|
|
8267
|
+
maxArgs: 2,
|
|
8268
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
8269
|
+
},
|
|
8270
|
+
clamp: {
|
|
8271
|
+
minArgs: 3,
|
|
8272
|
+
maxArgs: 3,
|
|
8273
|
+
apply: (args) => {
|
|
8274
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
8275
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
8276
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
8277
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
8278
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
8279
|
+
}
|
|
8280
|
+
},
|
|
8281
|
+
avg: {
|
|
8282
|
+
minArgs: 1,
|
|
8283
|
+
maxArgs: INF,
|
|
8284
|
+
apply: (args) => {
|
|
8285
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
8286
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
8287
|
+
}
|
|
8288
|
+
},
|
|
8289
|
+
sum: {
|
|
8290
|
+
minArgs: 1,
|
|
8291
|
+
maxArgs: INF,
|
|
8292
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
8293
|
+
},
|
|
8294
|
+
coalesce: {
|
|
8295
|
+
minArgs: 1,
|
|
8296
|
+
maxArgs: INF,
|
|
8297
|
+
apply: (args) => {
|
|
8298
|
+
for (const a of args) if (a !== null) return a;
|
|
8299
|
+
return null;
|
|
8300
|
+
}
|
|
8301
|
+
},
|
|
8302
|
+
age: {
|
|
8303
|
+
minArgs: 2,
|
|
8304
|
+
maxArgs: 2,
|
|
8305
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
8306
|
+
},
|
|
8307
|
+
convert: {
|
|
8308
|
+
minArgs: 3,
|
|
8309
|
+
maxArgs: 3,
|
|
8310
|
+
apply: (args, hooks) => {
|
|
8311
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
8312
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
8313
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
8314
|
+
if (hooks.convert) {
|
|
8315
|
+
const out = hooks.convert(x, from, to);
|
|
8316
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
8317
|
+
return finiteResult(out, "convert");
|
|
8318
|
+
}
|
|
8319
|
+
if (from === to) return x;
|
|
8320
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
8321
|
+
}
|
|
8322
|
+
}
|
|
8323
|
+
};
|
|
8324
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
8325
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
8326
|
+
* callees at parse time (immediate author feedback). */
|
|
8327
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
8328
|
+
/**
|
|
8329
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
8330
|
+
*
|
|
8331
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
8332
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
8333
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
8334
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
8335
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
8336
|
+
* that references a since-removed builtin degrades at read.
|
|
8337
|
+
*
|
|
8338
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
8339
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
8340
|
+
*/
|
|
8341
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
8342
|
+
var BINARY_PRECEDENCE = {
|
|
8343
|
+
"||": 1,
|
|
8344
|
+
"&&": 2,
|
|
8345
|
+
"==": 3,
|
|
8346
|
+
"!=": 3,
|
|
8347
|
+
"<": 4,
|
|
8348
|
+
"<=": 4,
|
|
8349
|
+
">": 4,
|
|
8350
|
+
">=": 4,
|
|
8351
|
+
"+": 5,
|
|
8352
|
+
"-": 5,
|
|
8353
|
+
"*": 6,
|
|
8354
|
+
"/": 6,
|
|
8355
|
+
"%": 6
|
|
8356
|
+
};
|
|
8357
|
+
function isLogicalOp(op) {
|
|
8358
|
+
return op === "&&" || op === "||";
|
|
8359
|
+
}
|
|
8360
|
+
function isBinaryOp(op) {
|
|
8361
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
8362
|
+
}
|
|
8363
|
+
var Parser = class {
|
|
8364
|
+
tokens;
|
|
8365
|
+
pos = 0;
|
|
8366
|
+
nodeCount = 0;
|
|
8367
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
8368
|
+
callees = /* @__PURE__ */ new Set();
|
|
8369
|
+
constructor(tokens) {
|
|
8370
|
+
this.tokens = tokens;
|
|
8371
|
+
}
|
|
8372
|
+
parse() {
|
|
8373
|
+
const ast = this.parseTernary();
|
|
8374
|
+
const tok = this.peek();
|
|
8375
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
8376
|
+
return {
|
|
8377
|
+
ast,
|
|
8378
|
+
identifiers: this.identifiers,
|
|
8379
|
+
callees: this.callees,
|
|
8380
|
+
nodeCount: this.nodeCount
|
|
8381
|
+
};
|
|
8382
|
+
}
|
|
8383
|
+
peek() {
|
|
8384
|
+
return this.tokens[this.pos];
|
|
8385
|
+
}
|
|
8386
|
+
next() {
|
|
8387
|
+
return this.tokens[this.pos++];
|
|
8388
|
+
}
|
|
8389
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8390
|
+
expectPunct(punct) {
|
|
8391
|
+
const tok = this.peek();
|
|
8392
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8393
|
+
this.pos += 1;
|
|
8394
|
+
}
|
|
8395
|
+
matchPunct(punct) {
|
|
8396
|
+
const tok = this.peek();
|
|
8397
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8398
|
+
this.pos += 1;
|
|
8399
|
+
return true;
|
|
8400
|
+
}
|
|
8401
|
+
return false;
|
|
8402
|
+
}
|
|
8403
|
+
countNode() {
|
|
8404
|
+
this.nodeCount += 1;
|
|
8405
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8406
|
+
}
|
|
8407
|
+
parseTernary() {
|
|
8408
|
+
const test = this.parseBinary(1);
|
|
8409
|
+
if (this.matchPunct("?")) {
|
|
8410
|
+
const consequent = this.parseTernary();
|
|
8411
|
+
this.expectPunct(":");
|
|
8412
|
+
const alternate = this.parseTernary();
|
|
8413
|
+
this.countNode();
|
|
8414
|
+
return {
|
|
8415
|
+
kind: "conditional",
|
|
8416
|
+
test,
|
|
8417
|
+
consequent,
|
|
8418
|
+
alternate
|
|
8419
|
+
};
|
|
8420
|
+
}
|
|
8421
|
+
return test;
|
|
8422
|
+
}
|
|
8423
|
+
parseBinary(minPrec) {
|
|
8424
|
+
let left = this.parseUnary();
|
|
8425
|
+
for (;;) {
|
|
8426
|
+
const tok = this.peek();
|
|
8427
|
+
if (tok.type !== "punct") break;
|
|
8428
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8429
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8430
|
+
const op = tok.punct;
|
|
8431
|
+
this.pos += 1;
|
|
8432
|
+
const right = this.parseBinary(prec + 1);
|
|
8433
|
+
this.countNode();
|
|
8434
|
+
if (isLogicalOp(op)) left = {
|
|
8435
|
+
kind: "logical",
|
|
8436
|
+
op,
|
|
8437
|
+
left,
|
|
8438
|
+
right
|
|
8439
|
+
};
|
|
8440
|
+
else if (isBinaryOp(op)) left = {
|
|
8441
|
+
kind: "binary",
|
|
8442
|
+
op,
|
|
8443
|
+
left,
|
|
8444
|
+
right
|
|
8445
|
+
};
|
|
8446
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8447
|
+
}
|
|
8448
|
+
return left;
|
|
8449
|
+
}
|
|
8450
|
+
parseUnary() {
|
|
8451
|
+
const tok = this.peek();
|
|
8452
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8453
|
+
const op = tok.punct;
|
|
8454
|
+
this.pos += 1;
|
|
8455
|
+
const operand = this.parseUnary();
|
|
8456
|
+
this.countNode();
|
|
8457
|
+
return {
|
|
8458
|
+
kind: "unary",
|
|
8459
|
+
op,
|
|
8460
|
+
operand
|
|
8461
|
+
};
|
|
8462
|
+
}
|
|
8463
|
+
return this.parsePrimary();
|
|
8464
|
+
}
|
|
8465
|
+
parsePrimary() {
|
|
8466
|
+
const tok = this.next();
|
|
8467
|
+
switch (tok.type) {
|
|
8468
|
+
case "number":
|
|
8469
|
+
this.countNode();
|
|
8470
|
+
return {
|
|
8471
|
+
kind: "literal",
|
|
8472
|
+
value: tok.value
|
|
8473
|
+
};
|
|
8474
|
+
case "string":
|
|
8475
|
+
this.countNode();
|
|
8476
|
+
return {
|
|
8477
|
+
kind: "literal",
|
|
8478
|
+
value: tok.value
|
|
8479
|
+
};
|
|
8480
|
+
case "keyword":
|
|
8481
|
+
this.countNode();
|
|
8482
|
+
return {
|
|
8483
|
+
kind: "literal",
|
|
8484
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8485
|
+
};
|
|
8486
|
+
case "identifier": {
|
|
8487
|
+
const nextTok = this.peek();
|
|
8488
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8489
|
+
this.identifiers.add(tok.name);
|
|
8490
|
+
this.countNode();
|
|
8491
|
+
return {
|
|
8492
|
+
kind: "identifier",
|
|
8493
|
+
name: tok.name
|
|
8494
|
+
};
|
|
8495
|
+
}
|
|
8496
|
+
case "punct":
|
|
8497
|
+
if (tok.punct === "(") {
|
|
8498
|
+
const inner = this.parseTernary();
|
|
8499
|
+
this.expectPunct(")");
|
|
8500
|
+
return inner;
|
|
8501
|
+
}
|
|
8502
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8503
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8504
|
+
}
|
|
8505
|
+
}
|
|
8506
|
+
parseCall(callee, pos) {
|
|
8507
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8508
|
+
this.expectPunct("(");
|
|
8509
|
+
const args = [];
|
|
8510
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8511
|
+
args.push(this.parseTernary());
|
|
8512
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8513
|
+
if (this.matchPunct(",")) continue;
|
|
8514
|
+
this.expectPunct(")");
|
|
8515
|
+
break;
|
|
8516
|
+
}
|
|
8517
|
+
this.callees.add(callee);
|
|
8518
|
+
this.countNode();
|
|
8519
|
+
return {
|
|
8520
|
+
kind: "call",
|
|
8521
|
+
callee,
|
|
8522
|
+
args
|
|
8523
|
+
};
|
|
8524
|
+
}
|
|
8525
|
+
};
|
|
8526
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8527
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8528
|
+
function parseExpression(source) {
|
|
8529
|
+
return new Parser(tokenize(source)).parse();
|
|
8530
|
+
}
|
|
8531
|
+
Object.freeze({});
|
|
8532
|
+
/**
|
|
8533
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8534
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8535
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8536
|
+
* one per read on a hot resolve path.
|
|
8537
|
+
*
|
|
8538
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8539
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8540
|
+
* callers is safe and maximises hit rate.
|
|
8541
|
+
*/
|
|
8542
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8543
|
+
function getCached(source) {
|
|
8544
|
+
const hit = cache.get(source);
|
|
8545
|
+
if (hit !== void 0) {
|
|
8546
|
+
cache.delete(source);
|
|
8547
|
+
cache.set(source, hit);
|
|
8548
|
+
return hit;
|
|
8549
|
+
}
|
|
8550
|
+
let result;
|
|
8551
|
+
try {
|
|
8552
|
+
result = {
|
|
8553
|
+
ok: true,
|
|
8554
|
+
parsed: parseExpression(source)
|
|
8555
|
+
};
|
|
8556
|
+
} catch (err) {
|
|
8557
|
+
result = {
|
|
8558
|
+
ok: false,
|
|
8559
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8560
|
+
};
|
|
8561
|
+
}
|
|
8562
|
+
cache.set(source, result);
|
|
8563
|
+
if (cache.size > 256) {
|
|
8564
|
+
const oldest = cache.keys().next().value;
|
|
8565
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8566
|
+
}
|
|
8567
|
+
return result;
|
|
8568
|
+
}
|
|
8569
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8570
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8571
|
+
function compileExpressionSafe(source) {
|
|
8572
|
+
return getCached(source);
|
|
8573
|
+
}
|
|
8574
|
+
/**
|
|
8575
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8576
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8577
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8578
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8579
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8580
|
+
*/
|
|
8581
|
+
function validateExpressionSource(src) {
|
|
8582
|
+
const names = Object.keys(src.bindings);
|
|
8583
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8584
|
+
for (const name of names) {
|
|
8585
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8586
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8587
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8588
|
+
}
|
|
8589
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8590
|
+
if (!compiled.ok) return compiled.error;
|
|
8591
|
+
const bound = new Set(names);
|
|
8592
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8593
|
+
if (id === "now") continue;
|
|
8594
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8595
|
+
}
|
|
8596
|
+
return null;
|
|
8597
|
+
}
|
|
8598
|
+
/**
|
|
7835
8599
|
* Accessory device helpers — shared across drivers.
|
|
7836
8600
|
*
|
|
7837
8601
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -9765,7 +10529,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
9765
10529
|
});
|
|
9766
10530
|
method(object({
|
|
9767
10531
|
deviceId: number(),
|
|
9768
|
-
frame: FrameInputSchema
|
|
10532
|
+
frame: FrameInputSchema.optional(),
|
|
10533
|
+
frameHandle: FrameHandleSchema.optional()
|
|
9769
10534
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
9770
10535
|
deviceId: number(),
|
|
9771
10536
|
detected: boolean(),
|
|
@@ -10072,11 +10837,20 @@ var pipelineExecutorCapability = {
|
|
|
10072
10837
|
* legacy call shape used by existing benchmark code; once all
|
|
10073
10838
|
* callers pass it explicitly we make it required.
|
|
10074
10839
|
*
|
|
10075
|
-
* Exactly one of `frame`, `
|
|
10076
|
-
* provided:
|
|
10840
|
+
* Exactly one of `frame`, `frameHandle`, `imageBase64`,
|
|
10841
|
+
* `referenceImage` must be provided:
|
|
10077
10842
|
* - `frame`: runtime dispatch path (runner → decoded broker frame).
|
|
10078
10843
|
* Carries the raw buffer, dimensions, and format; the executor
|
|
10079
10844
|
* uses it directly without base64 round-tripping.
|
|
10845
|
+
* - `frameHandle` (CB5): a zero-pixel shm `FrameHandle` for the SAME
|
|
10846
|
+
* decoded frame. Both runner and executor are hub-local processes
|
|
10847
|
+
* sharing `/dev/shm`, so the executor maps the named segment and
|
|
10848
|
+
* reads the pixels back zero-copy — eliminating the ~1.2MB
|
|
10849
|
+
* re-serialisation over UDS/MsgPack the `frame` path pays per call.
|
|
10850
|
+
* High-risk: the FrameRing is a latest-wins seqlock with no
|
|
10851
|
+
* refcount, so a recycled slot yields a null read; the executor
|
|
10852
|
+
* then degrades to an empty result and the runner ships pixels via
|
|
10853
|
+
* `frame` as the fallback (queue-depth gated on the runner side).
|
|
10080
10854
|
* - `imageBase64`: one-shot test path (benchmark ImageTab).
|
|
10081
10855
|
* - `referenceImage`: named file from the reference-image store.
|
|
10082
10856
|
*/
|
|
@@ -10084,6 +10858,12 @@ var pipelineExecutorCapability = {
|
|
|
10084
10858
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
10085
10859
|
steps: array(PipelineStepInputSchema).min(1),
|
|
10086
10860
|
frame: FrameInputSchema.optional(),
|
|
10861
|
+
/**
|
|
10862
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
10863
|
+
* the decoded pixels live in. One more member of the one-of
|
|
10864
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
10865
|
+
*/
|
|
10866
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
10087
10867
|
imageBase64: string().optional(),
|
|
10088
10868
|
/**
|
|
10089
10869
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -10977,6 +11757,113 @@ object({
|
|
|
10977
11757
|
lastFetchedAt: number()
|
|
10978
11758
|
});
|
|
10979
11759
|
DeviceType.Sensor;
|
|
11760
|
+
/**
|
|
11761
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
11762
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
11763
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
11764
|
+
*/
|
|
11765
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
11766
|
+
"normal",
|
|
11767
|
+
"offline",
|
|
11768
|
+
"on_batteries"
|
|
11769
|
+
]);
|
|
11770
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
11771
|
+
object({
|
|
11772
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
11773
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
11774
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
11775
|
+
foodLevel: number().nullable(),
|
|
11776
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
11777
|
+
* single-hopper models. */
|
|
11778
|
+
food1: number().nullable(),
|
|
11779
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
11780
|
+
* single-hopper models. */
|
|
11781
|
+
food2: number().nullable(),
|
|
11782
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
11783
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
11784
|
+
* below the feeder's low threshold. */
|
|
11785
|
+
lowFood: boolean(),
|
|
11786
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
11787
|
+
* device has no battery reading. */
|
|
11788
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
11789
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
11790
|
+
* desiccant sensor. */
|
|
11791
|
+
desiccantLeftDays: number().nullable(),
|
|
11792
|
+
/** True while a feed is in progress. */
|
|
11793
|
+
feeding: boolean(),
|
|
11794
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
11795
|
+
* Null until the device has reported a status. */
|
|
11796
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
11797
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
11798
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
11799
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
11800
|
+
error: string().nullable(),
|
|
11801
|
+
/** Raw device error code (0 / null = no error). */
|
|
11802
|
+
errorCode: number().nullable(),
|
|
11803
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
11804
|
+
isDualHopper: boolean(),
|
|
11805
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
11806
|
+
childLock: boolean(),
|
|
11807
|
+
/** Front indicator-light setting. */
|
|
11808
|
+
indicatorLight: boolean(),
|
|
11809
|
+
/** Play a chime when dispensing. */
|
|
11810
|
+
feedSound: boolean(),
|
|
11811
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
11812
|
+
volume: number(),
|
|
11813
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
11814
|
+
lastFetchedAt: number()
|
|
11815
|
+
});
|
|
11816
|
+
DeviceType.PetFeeder, method(object({
|
|
11817
|
+
deviceId: number().int().nonnegative(),
|
|
11818
|
+
grams: gramsPortion.optional(),
|
|
11819
|
+
hopper1: gramsPortion.optional(),
|
|
11820
|
+
hopper2: gramsPortion.optional()
|
|
11821
|
+
}), _void(), {
|
|
11822
|
+
kind: "mutation",
|
|
11823
|
+
auth: "admin"
|
|
11824
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11825
|
+
kind: "mutation",
|
|
11826
|
+
auth: "admin"
|
|
11827
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11828
|
+
kind: "mutation",
|
|
11829
|
+
auth: "admin"
|
|
11830
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11831
|
+
kind: "mutation",
|
|
11832
|
+
auth: "admin"
|
|
11833
|
+
}), method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
11834
|
+
kind: "mutation",
|
|
11835
|
+
auth: "admin"
|
|
11836
|
+
}), method(object({
|
|
11837
|
+
deviceId: number().int().nonnegative(),
|
|
11838
|
+
soundId: number().int().nonnegative()
|
|
11839
|
+
}), _void(), {
|
|
11840
|
+
kind: "mutation",
|
|
11841
|
+
auth: "admin"
|
|
11842
|
+
}), method(object({
|
|
11843
|
+
deviceId: number().int().nonnegative(),
|
|
11844
|
+
on: boolean()
|
|
11845
|
+
}), _void(), {
|
|
11846
|
+
kind: "mutation",
|
|
11847
|
+
auth: "admin"
|
|
11848
|
+
}), method(object({
|
|
11849
|
+
deviceId: number().int().nonnegative(),
|
|
11850
|
+
on: boolean()
|
|
11851
|
+
}), _void(), {
|
|
11852
|
+
kind: "mutation",
|
|
11853
|
+
auth: "admin"
|
|
11854
|
+
}), method(object({
|
|
11855
|
+
deviceId: number().int().nonnegative(),
|
|
11856
|
+
on: boolean()
|
|
11857
|
+
}), _void(), {
|
|
11858
|
+
kind: "mutation",
|
|
11859
|
+
auth: "admin"
|
|
11860
|
+
}), method(object({
|
|
11861
|
+
deviceId: number().int().nonnegative(),
|
|
11862
|
+
level: number().int().nonnegative()
|
|
11863
|
+
}), _void(), {
|
|
11864
|
+
kind: "mutation",
|
|
11865
|
+
auth: "admin"
|
|
11866
|
+
});
|
|
10980
11867
|
object({
|
|
10981
11868
|
/** Instantaneous power draw in watts. */
|
|
10982
11869
|
watts: number().optional(),
|
|
@@ -12910,10 +13797,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
12910
13797
|
url: string()
|
|
12911
13798
|
}), _void()), method(object({
|
|
12912
13799
|
sessionId: string(),
|
|
12913
|
-
maxCount: number().default(1)
|
|
13800
|
+
maxCount: number().default(1),
|
|
13801
|
+
waitMs: number().optional()
|
|
12914
13802
|
}), array(DecodedFrameSchema)), method(object({
|
|
12915
13803
|
sessionId: string(),
|
|
12916
|
-
maxCount: number().default(1)
|
|
13804
|
+
maxCount: number().default(1),
|
|
13805
|
+
waitMs: number().optional()
|
|
12917
13806
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
12918
13807
|
sessionId: string(),
|
|
12919
13808
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -13205,30 +14094,57 @@ var ChildLayoutEntrySchema = object({
|
|
|
13205
14094
|
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
13206
14095
|
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
13207
14096
|
* source device's full re-sync-stable `stableId`. */
|
|
14097
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
14098
|
+
kind: literal("field").optional(),
|
|
14099
|
+
sourceKey: string(),
|
|
14100
|
+
cap: string(),
|
|
14101
|
+
fieldPath: string()
|
|
14102
|
+
});
|
|
14103
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
14104
|
+
kind: literal("literal"),
|
|
14105
|
+
value: union([
|
|
14106
|
+
string(),
|
|
14107
|
+
number(),
|
|
14108
|
+
boolean(),
|
|
14109
|
+
_null()
|
|
14110
|
+
])
|
|
14111
|
+
});
|
|
14112
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
14113
|
+
kind: literal("global"),
|
|
14114
|
+
sourceStableId: string(),
|
|
14115
|
+
cap: string(),
|
|
14116
|
+
fieldPath: string()
|
|
14117
|
+
});
|
|
14118
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
14119
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
14120
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
14121
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
14122
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
14123
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
14124
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
14125
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
14126
|
+
kind: literal("expression"),
|
|
14127
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
14128
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
14129
|
+
DeviceLinkFieldSourceSchema,
|
|
14130
|
+
DeviceLinkLiteralSourceSchema,
|
|
14131
|
+
DeviceLinkGlobalSourceSchema
|
|
14132
|
+
]))
|
|
14133
|
+
}).superRefine((src, ctx) => {
|
|
14134
|
+
const err = validateExpressionSource(src);
|
|
14135
|
+
if (err !== null) ctx.addIssue({
|
|
14136
|
+
code: "custom",
|
|
14137
|
+
message: err,
|
|
14138
|
+
path: ["expr"]
|
|
14139
|
+
});
|
|
14140
|
+
});
|
|
13208
14141
|
var DeviceLinkSchema = object({
|
|
13209
14142
|
id: string(),
|
|
13210
14143
|
source: union([
|
|
13211
|
-
|
|
13212
|
-
|
|
13213
|
-
|
|
13214
|
-
|
|
13215
|
-
fieldPath: string()
|
|
13216
|
-
}),
|
|
13217
|
-
object({
|
|
13218
|
-
kind: literal("literal"),
|
|
13219
|
-
value: union([
|
|
13220
|
-
string(),
|
|
13221
|
-
number(),
|
|
13222
|
-
boolean(),
|
|
13223
|
-
_null()
|
|
13224
|
-
])
|
|
13225
|
-
}),
|
|
13226
|
-
object({
|
|
13227
|
-
kind: literal("global"),
|
|
13228
|
-
sourceStableId: string(),
|
|
13229
|
-
cap: string(),
|
|
13230
|
-
fieldPath: string()
|
|
13231
|
-
})
|
|
14144
|
+
DeviceLinkFieldSourceSchema,
|
|
14145
|
+
DeviceLinkLiteralSourceSchema,
|
|
14146
|
+
DeviceLinkGlobalSourceSchema,
|
|
14147
|
+
DeviceLinkExpressionSourceSchema
|
|
13232
14148
|
]),
|
|
13233
14149
|
target: object({
|
|
13234
14150
|
cap: string(),
|
|
@@ -13258,6 +14174,31 @@ var DeviceLinkSchema = object({
|
|
|
13258
14174
|
})
|
|
13259
14175
|
]).optional()
|
|
13260
14176
|
});
|
|
14177
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
14178
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
14179
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
14180
|
+
unit: string().min(1).optional(),
|
|
14181
|
+
precision: number().int().min(0).max(10).optional()
|
|
14182
|
+
});
|
|
14183
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
14184
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
14185
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
14186
|
+
var DeviceDisplayOverrideSchema = object({
|
|
14187
|
+
icon: string().min(1).optional(),
|
|
14188
|
+
label: string().min(1).optional(),
|
|
14189
|
+
unit: string().min(1).optional(),
|
|
14190
|
+
precision: number().int().min(0).max(10).optional(),
|
|
14191
|
+
hidden: boolean().optional(),
|
|
14192
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
14193
|
+
});
|
|
14194
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
14195
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
14196
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
14197
|
+
var RoleDisplayDefaultSchema = object({
|
|
14198
|
+
unit: string().min(1).optional(),
|
|
14199
|
+
precision: number().int().min(0).max(10).optional(),
|
|
14200
|
+
icon: string().min(1).optional()
|
|
14201
|
+
});
|
|
13261
14202
|
/**
|
|
13262
14203
|
* Serializable projection of a live IDevice.
|
|
13263
14204
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -13313,7 +14254,9 @@ var DeviceInfoSchema = object({
|
|
|
13313
14254
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
13314
14255
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
13315
14256
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
13316
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
14257
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
14258
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
14259
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
13317
14260
|
});
|
|
13318
14261
|
var ConfigEntrySchema = object({
|
|
13319
14262
|
key: string(),
|
|
@@ -13378,7 +14321,9 @@ var DeviceMetaSchema = object({
|
|
|
13378
14321
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
13379
14322
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
13380
14323
|
* Optional: only present for accessory children that carry a known role. */
|
|
13381
|
-
role: string().nullable().optional()
|
|
14324
|
+
role: string().nullable().optional(),
|
|
14325
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
14326
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
13382
14327
|
});
|
|
13383
14328
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
13384
14329
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -13472,6 +14417,15 @@ method(object({
|
|
|
13472
14417
|
}), _void(), {
|
|
13473
14418
|
kind: "mutation",
|
|
13474
14419
|
auth: "admin"
|
|
14420
|
+
}), method(object({
|
|
14421
|
+
deviceId: number(),
|
|
14422
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
14423
|
+
}), _void(), {
|
|
14424
|
+
kind: "mutation",
|
|
14425
|
+
auth: "admin"
|
|
14426
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
14427
|
+
kind: "mutation",
|
|
14428
|
+
auth: "admin"
|
|
13475
14429
|
}), method(object({
|
|
13476
14430
|
deviceId: number(),
|
|
13477
14431
|
includeSynthesizable: boolean().optional()
|
|
@@ -14996,7 +15950,10 @@ var pipelineOrchestratorCapability = {
|
|
|
14996
15950
|
methods: {
|
|
14997
15951
|
/**
|
|
14998
15952
|
* Pin a camera's pipeline to a specific agent (L1 affinity).
|
|
14999
|
-
* The orchestrator re-evaluates the assignment immediately
|
|
15953
|
+
* The orchestrator re-evaluates the assignment immediately and persists
|
|
15954
|
+
* the pin under the canonical `pipelineNodeId` device-store key (the
|
|
15955
|
+
* legacy `preferredAgent` key is nulled on write and kept only as a
|
|
15956
|
+
* read-only fallback for stores written before the unification).
|
|
15000
15957
|
*/
|
|
15001
15958
|
assignPipeline: method(object({
|
|
15002
15959
|
deviceId: number(),
|
|
@@ -15007,8 +15964,9 @@ var pipelineOrchestratorCapability = {
|
|
|
15007
15964
|
}),
|
|
15008
15965
|
/**
|
|
15009
15966
|
* Clear a camera's pipeline pin and let the auto-balancer re-pick
|
|
15010
|
-
* the optimal agent. The orchestrator persists
|
|
15011
|
-
*
|
|
15967
|
+
* the optimal agent. The orchestrator persists the canonical
|
|
15968
|
+
* `pipelineNodeId='auto'` (and nulls the legacy `preferredAgent`),
|
|
15969
|
+
* then re-runs the balancer with the
|
|
15012
15970
|
* cached `RunnerCameraConfig` and migrates only when the chosen
|
|
15013
15971
|
* node differs. The camera stays in `getPipelineAssignments()` —
|
|
15014
15972
|
* just with `pinned=false`. If no runner is currently available
|
|
@@ -17509,7 +18467,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
17509
18467
|
"webgpu",
|
|
17510
18468
|
"none"
|
|
17511
18469
|
]).nullable().optional();
|
|
17512
|
-
var HwAccelResolutionSchema = object({
|
|
18470
|
+
var HwAccelResolutionSchema = object({
|
|
18471
|
+
preferred: array(string()).readonly(),
|
|
18472
|
+
rationale: string()
|
|
18473
|
+
});
|
|
17513
18474
|
var HardwareEncoderIdSchema = _enum([
|
|
17514
18475
|
"h264_videotoolbox",
|
|
17515
18476
|
"hevc_videotoolbox",
|
|
@@ -17614,10 +18575,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
17614
18575
|
format: ModelFormatSchema,
|
|
17615
18576
|
reason: string()
|
|
17616
18577
|
});
|
|
17617
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
17618
|
-
prefer: HwAccelBackendInputSchema,
|
|
17619
|
-
nodeId: string().optional()
|
|
17620
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
18578
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
17621
18579
|
kind: "mutation",
|
|
17622
18580
|
auth: "admin"
|
|
17623
18581
|
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
@@ -19322,6 +20280,12 @@ Object.freeze({
|
|
|
19322
20280
|
addonId: null,
|
|
19323
20281
|
access: "view"
|
|
19324
20282
|
},
|
|
20283
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
20284
|
+
capName: "device-manager",
|
|
20285
|
+
capScope: "system",
|
|
20286
|
+
addonId: null,
|
|
20287
|
+
access: "view"
|
|
20288
|
+
},
|
|
19325
20289
|
"deviceManager.getSettingsSchema": {
|
|
19326
20290
|
capName: "device-manager",
|
|
19327
20291
|
capScope: "system",
|
|
@@ -19472,6 +20436,12 @@ Object.freeze({
|
|
|
19472
20436
|
addonId: null,
|
|
19473
20437
|
access: "create"
|
|
19474
20438
|
},
|
|
20439
|
+
"deviceManager.setDisplay": {
|
|
20440
|
+
capName: "device-manager",
|
|
20441
|
+
capScope: "system",
|
|
20442
|
+
addonId: null,
|
|
20443
|
+
access: "create"
|
|
20444
|
+
},
|
|
19475
20445
|
"deviceManager.setIntegrationId": {
|
|
19476
20446
|
capName: "device-manager",
|
|
19477
20447
|
capScope: "system",
|
|
@@ -19514,6 +20484,12 @@ Object.freeze({
|
|
|
19514
20484
|
addonId: null,
|
|
19515
20485
|
access: "create"
|
|
19516
20486
|
},
|
|
20487
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
20488
|
+
capName: "device-manager",
|
|
20489
|
+
capScope: "system",
|
|
20490
|
+
addonId: null,
|
|
20491
|
+
access: "create"
|
|
20492
|
+
},
|
|
19517
20493
|
"deviceManager.setStreamProfileMap": {
|
|
19518
20494
|
capName: "device-manager",
|
|
19519
20495
|
capScope: "system",
|
|
@@ -20564,6 +21540,66 @@ Object.freeze({
|
|
|
20564
21540
|
addonId: null,
|
|
20565
21541
|
access: "create"
|
|
20566
21542
|
},
|
|
21543
|
+
"petFeeder.callPet": {
|
|
21544
|
+
capName: "pet-feeder",
|
|
21545
|
+
capScope: "device",
|
|
21546
|
+
addonId: null,
|
|
21547
|
+
access: "create"
|
|
21548
|
+
},
|
|
21549
|
+
"petFeeder.cancelFeed": {
|
|
21550
|
+
capName: "pet-feeder",
|
|
21551
|
+
capScope: "device",
|
|
21552
|
+
addonId: null,
|
|
21553
|
+
access: "create"
|
|
21554
|
+
},
|
|
21555
|
+
"petFeeder.feed": {
|
|
21556
|
+
capName: "pet-feeder",
|
|
21557
|
+
capScope: "device",
|
|
21558
|
+
addonId: null,
|
|
21559
|
+
access: "create"
|
|
21560
|
+
},
|
|
21561
|
+
"petFeeder.markFoodReplenished": {
|
|
21562
|
+
capName: "pet-feeder",
|
|
21563
|
+
capScope: "device",
|
|
21564
|
+
addonId: null,
|
|
21565
|
+
access: "create"
|
|
21566
|
+
},
|
|
21567
|
+
"petFeeder.playSound": {
|
|
21568
|
+
capName: "pet-feeder",
|
|
21569
|
+
capScope: "device",
|
|
21570
|
+
addonId: null,
|
|
21571
|
+
access: "create"
|
|
21572
|
+
},
|
|
21573
|
+
"petFeeder.resetDesiccant": {
|
|
21574
|
+
capName: "pet-feeder",
|
|
21575
|
+
capScope: "device",
|
|
21576
|
+
addonId: null,
|
|
21577
|
+
access: "delete"
|
|
21578
|
+
},
|
|
21579
|
+
"petFeeder.setChildLock": {
|
|
21580
|
+
capName: "pet-feeder",
|
|
21581
|
+
capScope: "device",
|
|
21582
|
+
addonId: null,
|
|
21583
|
+
access: "create"
|
|
21584
|
+
},
|
|
21585
|
+
"petFeeder.setFeedSound": {
|
|
21586
|
+
capName: "pet-feeder",
|
|
21587
|
+
capScope: "device",
|
|
21588
|
+
addonId: null,
|
|
21589
|
+
access: "create"
|
|
21590
|
+
},
|
|
21591
|
+
"petFeeder.setIndicatorLight": {
|
|
21592
|
+
capName: "pet-feeder",
|
|
21593
|
+
capScope: "device",
|
|
21594
|
+
addonId: null,
|
|
21595
|
+
access: "create"
|
|
21596
|
+
},
|
|
21597
|
+
"petFeeder.setVolume": {
|
|
21598
|
+
capName: "pet-feeder",
|
|
21599
|
+
capScope: "device",
|
|
21600
|
+
addonId: null,
|
|
21601
|
+
access: "create"
|
|
21602
|
+
},
|
|
20567
21603
|
"pipelineAnalytics.clearTracks": {
|
|
20568
21604
|
capName: "pipeline-analytics",
|
|
20569
21605
|
capScope: "device",
|
|
@@ -23936,6 +24972,14 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
23936
24972
|
if (!this._cameraSettingsState) this._cameraSettingsState = this.state("cameraSettings", CameraSettingsMapSchema, {});
|
|
23937
24973
|
return this._cameraSettingsState;
|
|
23938
24974
|
}
|
|
24975
|
+
/** One-shot `migrateLegacyFlagsToBindings` guard flag. Absent or
|
|
24976
|
+
* corrupt ⇒ `false` (the migration runs — same fallback as the old
|
|
24977
|
+
* raw `store[key] === true` check). */
|
|
24978
|
+
_bindingsMigrationDoneState = null;
|
|
24979
|
+
get bindingsMigrationDoneState() {
|
|
24980
|
+
if (!this._bindingsMigrationDoneState) this._bindingsMigrationDoneState = this.state("bindingsMigration_v1_done", boolean(), false);
|
|
24981
|
+
return this._bindingsMigrationDoneState;
|
|
24982
|
+
}
|
|
23939
24983
|
/**
|
|
23940
24984
|
* Per-camera zones CRUD provider. Constructed lazily in `onInitialize`
|
|
23941
24985
|
* because it captures `this.ctx` for settings + api access; cleared
|
|
@@ -24115,7 +25159,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24115
25159
|
async onInitialize() {
|
|
24116
25160
|
this.initTimestamp = Date.now();
|
|
24117
25161
|
try {
|
|
24118
|
-
const stored = await this.
|
|
25162
|
+
const stored = await this.resolveGlobalStore();
|
|
24119
25163
|
this.globalSettings = { ...stored };
|
|
24120
25164
|
this.applyRuntimeSettings(this.globalSettings);
|
|
24121
25165
|
} catch (err) {
|
|
@@ -24327,7 +25371,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24327
25371
|
this.pendingRetryTimer = setInterval(() => void this.retryPendingDispatches(), PENDING_RETRY_INTERVAL_MS);
|
|
24328
25372
|
this.ctx.logger.info("Pipeline orchestrator detection-wiring subscriptions installed");
|
|
24329
25373
|
this.migrateLegacyFlagsToBindings().catch((err) => {
|
|
24330
|
-
this.
|
|
25374
|
+
this.ctxIfReady?.logger.warn("bindings migration failed — will retry on next boot", { meta: { error: errMsg(err) } });
|
|
24331
25375
|
});
|
|
24332
25376
|
this.zoneRulesProvider = new ZoneRulesProvider({
|
|
24333
25377
|
logger: this.ctx.logger.child("zone-rules"),
|
|
@@ -24457,9 +25501,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24457
25501
|
* persist the flag after a successful pass.
|
|
24458
25502
|
*/
|
|
24459
25503
|
async migrateLegacyFlagsToBindings() {
|
|
24460
|
-
|
|
24461
|
-
const store = await this.ctx.settings?.readAddonStore() ?? {};
|
|
24462
|
-
if (store[MIGRATION_KEY] === true) return;
|
|
25504
|
+
if (await this.bindingsMigrationDoneState.get()) return;
|
|
24463
25505
|
let api = this.api;
|
|
24464
25506
|
for (let i = 0; !api && i < 30; i++) {
|
|
24465
25507
|
await new Promise((r) => setTimeout(r, 200));
|
|
@@ -24515,10 +25557,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24515
25557
|
});
|
|
24516
25558
|
detectionDisabled++;
|
|
24517
25559
|
}
|
|
24518
|
-
await this.
|
|
24519
|
-
...store,
|
|
24520
|
-
[MIGRATION_KEY]: true
|
|
24521
|
-
});
|
|
25560
|
+
await this.bindingsMigrationDoneState.set(true);
|
|
24522
25561
|
this.ctx.logger.info("bindings migration complete", { meta: {
|
|
24523
25562
|
cameras: cameras.length,
|
|
24524
25563
|
audioDisabled,
|
|
@@ -24657,9 +25696,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24657
25696
|
}
|
|
24658
25697
|
}
|
|
24659
25698
|
}
|
|
24660
|
-
const
|
|
24661
|
-
const legacyPreferred = await this.readPreferredAgent(runnerConfig.deviceId);
|
|
24662
|
-
const preferredAgent = typeof pipelinePin === "string" && pipelinePin !== "auto" ? pipelinePin : legacyPreferred;
|
|
25699
|
+
const preferredAgent = await this.readPipelinePin(runnerConfig.deviceId);
|
|
24663
25700
|
const decision = balance({
|
|
24664
25701
|
nodes: await this.collectAgentLoad({ onlyEnabled: true }),
|
|
24665
25702
|
preferredAgent,
|
|
@@ -24731,7 +25768,10 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24731
25768
|
if (!this.ctx) throw new Error("PipelineOrchestrator: assignPipeline called before initialize");
|
|
24732
25769
|
const eligible = this.detectionEligibleNodes(input.deviceId);
|
|
24733
25770
|
if (!eligible.includes(input.agentNodeId)) throw new Error(`Cannot pin camera ${input.deviceId} detection to '${input.agentNodeId}': the node cannot obtain this camera's decoded frames (frame-source nodes: ${eligible.join(", ") || "none"}). Add it to Enabled Decoder Nodes first.`);
|
|
24734
|
-
await this.ctx.settings?.writeDeviceStore(input.deviceId, {
|
|
25771
|
+
await this.ctx.settings?.writeDeviceStore(input.deviceId, {
|
|
25772
|
+
pipelineNodeId: input.agentNodeId,
|
|
25773
|
+
[PREFERRED_AGENT_SETTING]: null
|
|
25774
|
+
}).catch((err) => {
|
|
24735
25775
|
const msg = errMsg(err);
|
|
24736
25776
|
this.ctx.logger.warn("assignPipeline: failed to persist pin", {
|
|
24737
25777
|
tags: { deviceId: input.deviceId },
|
|
@@ -24841,7 +25881,7 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
24841
25881
|
for (const [deviceId, config] of this.cameraConfigs) {
|
|
24842
25882
|
const current = this.assignments.get(deviceId);
|
|
24843
25883
|
if (current?.pinned) continue;
|
|
24844
|
-
const preferredAgent = await this.
|
|
25884
|
+
const preferredAgent = await this.readPipelinePin(deviceId);
|
|
24845
25885
|
const decision = balance({
|
|
24846
25886
|
nodes: talliedLoads(),
|
|
24847
25887
|
preferredAgent,
|
|
@@ -25231,11 +26271,22 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
25231
26271
|
if (timer) clearTimeout(timer);
|
|
25232
26272
|
}
|
|
25233
26273
|
}
|
|
25234
|
-
|
|
26274
|
+
/**
|
|
26275
|
+
* Resolve the persisted pipeline-node pin for a device. `pipelineNodeId` is
|
|
26276
|
+
* the canonical key (matching the sibling `decoderNodeId` / `audioNodeId`
|
|
26277
|
+
* `'auto'`-sentinel pattern); the legacy `preferredAgent` key is a read-only
|
|
26278
|
+
* fallback kept for backward compatibility with stores written before the
|
|
26279
|
+
* unification. A single device-store read serves both. Returns a concrete
|
|
26280
|
+
* node id, or `null` when neither key holds a pin (auto-balance).
|
|
26281
|
+
*/
|
|
26282
|
+
async readPipelinePin(deviceId) {
|
|
25235
26283
|
if (!this.ctx?.settings) return null;
|
|
25236
26284
|
try {
|
|
25237
|
-
const
|
|
25238
|
-
|
|
26285
|
+
const settings = await this.ctx.settings.readDeviceStore(deviceId);
|
|
26286
|
+
const pipelinePin = settings["pipelineNodeId"];
|
|
26287
|
+
if (typeof pipelinePin === "string" && pipelinePin.length > 0 && pipelinePin !== "auto") return pipelinePin;
|
|
26288
|
+
const legacy = settings[PREFERRED_AGENT_SETTING];
|
|
26289
|
+
return typeof legacy === "string" && legacy.length > 0 ? legacy : null;
|
|
25239
26290
|
} catch {
|
|
25240
26291
|
return null;
|
|
25241
26292
|
}
|
|
@@ -25376,7 +26427,10 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
25376
26427
|
} });
|
|
25377
26428
|
continue;
|
|
25378
26429
|
}
|
|
25379
|
-
if (assignment.pinned && this.failoverPolicy.pinnedOnDisconnect === "unpin-and-migrate") await this.ctx.settings?.writeDeviceStore(deviceId, {
|
|
26430
|
+
if (assignment.pinned && this.failoverPolicy.pinnedOnDisconnect === "unpin-and-migrate") await this.ctx.settings?.writeDeviceStore(deviceId, {
|
|
26431
|
+
[PREFERRED_AGENT_SETTING]: null,
|
|
26432
|
+
pipelineNodeId: "auto"
|
|
26433
|
+
}).catch(() => {});
|
|
25380
26434
|
affected.push({
|
|
25381
26435
|
deviceId,
|
|
25382
26436
|
config
|
|
@@ -27129,8 +28183,8 @@ var PipelineOrchestratorAddon = class PipelineOrchestratorAddon extends BaseAddo
|
|
|
27129
28183
|
] });
|
|
27130
28184
|
}
|
|
27131
28185
|
async updateGlobalSettings(patch) {
|
|
27132
|
-
await
|
|
27133
|
-
const full = await this.
|
|
28186
|
+
await super.updateGlobalSettings(patch);
|
|
28187
|
+
const full = await this.resolveGlobalStore();
|
|
27134
28188
|
this.globalSettings = { ...full };
|
|
27135
28189
|
this.applyRuntimeSettings(full);
|
|
27136
28190
|
const pausedIds = [...this.loadShedState.entries()].filter(([, s]) => s.pausedAt !== null).map(([id]) => id);
|