@camstack/addon-provider-homematic 1.1.13 → 1.1.14
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/addon.js +1464 -62
- package/dist/addon.mjs +1464 -62
- package/package.json +1 -1
package/dist/addon.mjs
CHANGED
|
@@ -4652,7 +4652,7 @@ function preprocess(fn, schema) {
|
|
|
4652
4652
|
});
|
|
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.
|
|
@@ -5914,6 +6076,7 @@ var CamStreamKindSchema = _enum([
|
|
|
5914
6076
|
"pull-rtsp",
|
|
5915
6077
|
"pull-rtmp",
|
|
5916
6078
|
"pull-http",
|
|
6079
|
+
"pull-flv",
|
|
5917
6080
|
"pull-rfc4571",
|
|
5918
6081
|
"push-annexb",
|
|
5919
6082
|
"derived"
|
|
@@ -6296,6 +6459,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6296
6459
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6297
6460
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6298
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";
|
|
6299
6469
|
return DeviceType;
|
|
6300
6470
|
}({});
|
|
6301
6471
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7460,6 +7630,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7460
7630
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7461
7631
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7462
7632
|
/**
|
|
7633
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7634
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7635
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7636
|
+
*/
|
|
7637
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7638
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7639
|
+
var ExpressionParseError = class extends Error {
|
|
7640
|
+
position;
|
|
7641
|
+
constructor(message, position) {
|
|
7642
|
+
super(message);
|
|
7643
|
+
this.name = "ExpressionParseError";
|
|
7644
|
+
this.position = position;
|
|
7645
|
+
}
|
|
7646
|
+
};
|
|
7647
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7648
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7649
|
+
var ExpressionEvalError = class extends Error {
|
|
7650
|
+
constructor(message) {
|
|
7651
|
+
super(message);
|
|
7652
|
+
this.name = "ExpressionEvalError";
|
|
7653
|
+
}
|
|
7654
|
+
};
|
|
7655
|
+
/**
|
|
7656
|
+
* Resource-bound constants for the safe expression engine.
|
|
7657
|
+
*
|
|
7658
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7659
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7660
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7661
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7662
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7663
|
+
*/
|
|
7664
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7665
|
+
* rejected without allocation. */
|
|
7666
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7667
|
+
/** A legal binding / identifier name. */
|
|
7668
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7669
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7670
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7671
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7672
|
+
"now",
|
|
7673
|
+
"true",
|
|
7674
|
+
"false",
|
|
7675
|
+
"null"
|
|
7676
|
+
]);
|
|
7677
|
+
/**
|
|
7678
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7679
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7680
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7681
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7682
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7683
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7684
|
+
* template literals are lexically impossible.
|
|
7685
|
+
*/
|
|
7686
|
+
var KEYWORDS = new Set([
|
|
7687
|
+
"true",
|
|
7688
|
+
"false",
|
|
7689
|
+
"null"
|
|
7690
|
+
]);
|
|
7691
|
+
function isDigit(ch) {
|
|
7692
|
+
return ch >= "0" && ch <= "9";
|
|
7693
|
+
}
|
|
7694
|
+
function isIdentStart(ch) {
|
|
7695
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7696
|
+
}
|
|
7697
|
+
function isIdentPart(ch) {
|
|
7698
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7699
|
+
}
|
|
7700
|
+
function isWhitespace(ch) {
|
|
7701
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7702
|
+
}
|
|
7703
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7704
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7705
|
+
* string. */
|
|
7706
|
+
function tokenize(source) {
|
|
7707
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7708
|
+
const tokens = [];
|
|
7709
|
+
let i = 0;
|
|
7710
|
+
const n = source.length;
|
|
7711
|
+
while (i < n) {
|
|
7712
|
+
const ch = source[i];
|
|
7713
|
+
if (isWhitespace(ch)) {
|
|
7714
|
+
i += 1;
|
|
7715
|
+
continue;
|
|
7716
|
+
}
|
|
7717
|
+
if (isDigit(ch)) {
|
|
7718
|
+
const start = i;
|
|
7719
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7720
|
+
if (i < n && source[i] === ".") {
|
|
7721
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7722
|
+
i += 1;
|
|
7723
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7724
|
+
}
|
|
7725
|
+
const text = source.slice(start, i);
|
|
7726
|
+
const value = Number(text);
|
|
7727
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7728
|
+
tokens.push({
|
|
7729
|
+
type: "number",
|
|
7730
|
+
value,
|
|
7731
|
+
pos: start
|
|
7732
|
+
});
|
|
7733
|
+
continue;
|
|
7734
|
+
}
|
|
7735
|
+
if (ch === "'" || ch === "\"") {
|
|
7736
|
+
const quote = ch;
|
|
7737
|
+
const start = i;
|
|
7738
|
+
i += 1;
|
|
7739
|
+
let out = "";
|
|
7740
|
+
let closed = false;
|
|
7741
|
+
while (i < n) {
|
|
7742
|
+
const c = source[i];
|
|
7743
|
+
if (c === "\\") {
|
|
7744
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7745
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7746
|
+
out += next;
|
|
7747
|
+
i += 2;
|
|
7748
|
+
continue;
|
|
7749
|
+
}
|
|
7750
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7751
|
+
}
|
|
7752
|
+
if (c === quote) {
|
|
7753
|
+
closed = true;
|
|
7754
|
+
i += 1;
|
|
7755
|
+
break;
|
|
7756
|
+
}
|
|
7757
|
+
out += c;
|
|
7758
|
+
i += 1;
|
|
7759
|
+
}
|
|
7760
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7761
|
+
tokens.push({
|
|
7762
|
+
type: "string",
|
|
7763
|
+
value: out,
|
|
7764
|
+
pos: start
|
|
7765
|
+
});
|
|
7766
|
+
continue;
|
|
7767
|
+
}
|
|
7768
|
+
if (isIdentStart(ch)) {
|
|
7769
|
+
const start = i;
|
|
7770
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7771
|
+
const text = source.slice(start, i);
|
|
7772
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7773
|
+
type: "keyword",
|
|
7774
|
+
keyword: keywordOf(text),
|
|
7775
|
+
pos: start
|
|
7776
|
+
});
|
|
7777
|
+
else tokens.push({
|
|
7778
|
+
type: "identifier",
|
|
7779
|
+
name: text,
|
|
7780
|
+
pos: start
|
|
7781
|
+
});
|
|
7782
|
+
continue;
|
|
7783
|
+
}
|
|
7784
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7785
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7786
|
+
tokens.push({
|
|
7787
|
+
type: "punct",
|
|
7788
|
+
punct: two,
|
|
7789
|
+
pos: i
|
|
7790
|
+
});
|
|
7791
|
+
i += 2;
|
|
7792
|
+
continue;
|
|
7793
|
+
}
|
|
7794
|
+
if (isSinglePunct(ch)) {
|
|
7795
|
+
tokens.push({
|
|
7796
|
+
type: "punct",
|
|
7797
|
+
punct: ch,
|
|
7798
|
+
pos: i
|
|
7799
|
+
});
|
|
7800
|
+
i += 1;
|
|
7801
|
+
continue;
|
|
7802
|
+
}
|
|
7803
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7804
|
+
}
|
|
7805
|
+
tokens.push({
|
|
7806
|
+
type: "eof",
|
|
7807
|
+
pos: n
|
|
7808
|
+
});
|
|
7809
|
+
return tokens;
|
|
7810
|
+
}
|
|
7811
|
+
function keywordOf(text) {
|
|
7812
|
+
if (text === "true") return "true";
|
|
7813
|
+
if (text === "false") return "false";
|
|
7814
|
+
return "null";
|
|
7815
|
+
}
|
|
7816
|
+
function isSinglePunct(ch) {
|
|
7817
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7818
|
+
}
|
|
7819
|
+
/**
|
|
7820
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7821
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7822
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7823
|
+
* own-property check against it.
|
|
7824
|
+
*
|
|
7825
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7826
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7827
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7828
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7829
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7830
|
+
*
|
|
7831
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7832
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7833
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7834
|
+
* closed rather than emitting a garbage value.
|
|
7835
|
+
*/
|
|
7836
|
+
function asFiniteNumber(value, name, index) {
|
|
7837
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7838
|
+
return value;
|
|
7839
|
+
}
|
|
7840
|
+
function asString$1(value, name, index) {
|
|
7841
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7842
|
+
return value;
|
|
7843
|
+
}
|
|
7844
|
+
function finiteResult(value, name) {
|
|
7845
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7846
|
+
return value;
|
|
7847
|
+
}
|
|
7848
|
+
function allFiniteNumbers(args, name) {
|
|
7849
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7850
|
+
}
|
|
7851
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7852
|
+
var table = {
|
|
7853
|
+
min: {
|
|
7854
|
+
minArgs: 1,
|
|
7855
|
+
maxArgs: INF,
|
|
7856
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7857
|
+
},
|
|
7858
|
+
max: {
|
|
7859
|
+
minArgs: 1,
|
|
7860
|
+
maxArgs: INF,
|
|
7861
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7862
|
+
},
|
|
7863
|
+
abs: {
|
|
7864
|
+
minArgs: 1,
|
|
7865
|
+
maxArgs: 1,
|
|
7866
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7867
|
+
},
|
|
7868
|
+
floor: {
|
|
7869
|
+
minArgs: 1,
|
|
7870
|
+
maxArgs: 1,
|
|
7871
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7872
|
+
},
|
|
7873
|
+
ceil: {
|
|
7874
|
+
minArgs: 1,
|
|
7875
|
+
maxArgs: 1,
|
|
7876
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7877
|
+
},
|
|
7878
|
+
sqrt: {
|
|
7879
|
+
minArgs: 1,
|
|
7880
|
+
maxArgs: 1,
|
|
7881
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7882
|
+
},
|
|
7883
|
+
round: {
|
|
7884
|
+
minArgs: 1,
|
|
7885
|
+
maxArgs: 2,
|
|
7886
|
+
apply: (args) => {
|
|
7887
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7888
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7889
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7890
|
+
const factor = 10 ** digits;
|
|
7891
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7892
|
+
}
|
|
7893
|
+
},
|
|
7894
|
+
pow: {
|
|
7895
|
+
minArgs: 2,
|
|
7896
|
+
maxArgs: 2,
|
|
7897
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7898
|
+
},
|
|
7899
|
+
clamp: {
|
|
7900
|
+
minArgs: 3,
|
|
7901
|
+
maxArgs: 3,
|
|
7902
|
+
apply: (args) => {
|
|
7903
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7904
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7905
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7906
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7907
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7908
|
+
}
|
|
7909
|
+
},
|
|
7910
|
+
avg: {
|
|
7911
|
+
minArgs: 1,
|
|
7912
|
+
maxArgs: INF,
|
|
7913
|
+
apply: (args) => {
|
|
7914
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7915
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7916
|
+
}
|
|
7917
|
+
},
|
|
7918
|
+
sum: {
|
|
7919
|
+
minArgs: 1,
|
|
7920
|
+
maxArgs: INF,
|
|
7921
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7922
|
+
},
|
|
7923
|
+
coalesce: {
|
|
7924
|
+
minArgs: 1,
|
|
7925
|
+
maxArgs: INF,
|
|
7926
|
+
apply: (args) => {
|
|
7927
|
+
for (const a of args) if (a !== null) return a;
|
|
7928
|
+
return null;
|
|
7929
|
+
}
|
|
7930
|
+
},
|
|
7931
|
+
age: {
|
|
7932
|
+
minArgs: 2,
|
|
7933
|
+
maxArgs: 2,
|
|
7934
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7935
|
+
},
|
|
7936
|
+
convert: {
|
|
7937
|
+
minArgs: 3,
|
|
7938
|
+
maxArgs: 3,
|
|
7939
|
+
apply: (args, hooks) => {
|
|
7940
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7941
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7942
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7943
|
+
if (hooks.convert) {
|
|
7944
|
+
const out = hooks.convert(x, from, to);
|
|
7945
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7946
|
+
return finiteResult(out, "convert");
|
|
7947
|
+
}
|
|
7948
|
+
if (from === to) return x;
|
|
7949
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7950
|
+
}
|
|
7951
|
+
}
|
|
7952
|
+
};
|
|
7953
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7954
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7955
|
+
* callees at parse time (immediate author feedback). */
|
|
7956
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7957
|
+
/**
|
|
7958
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7959
|
+
*
|
|
7960
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7961
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7962
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7963
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7964
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7965
|
+
* that references a since-removed builtin degrades at read.
|
|
7966
|
+
*
|
|
7967
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7968
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7969
|
+
*/
|
|
7970
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7971
|
+
var BINARY_PRECEDENCE = {
|
|
7972
|
+
"||": 1,
|
|
7973
|
+
"&&": 2,
|
|
7974
|
+
"==": 3,
|
|
7975
|
+
"!=": 3,
|
|
7976
|
+
"<": 4,
|
|
7977
|
+
"<=": 4,
|
|
7978
|
+
">": 4,
|
|
7979
|
+
">=": 4,
|
|
7980
|
+
"+": 5,
|
|
7981
|
+
"-": 5,
|
|
7982
|
+
"*": 6,
|
|
7983
|
+
"/": 6,
|
|
7984
|
+
"%": 6
|
|
7985
|
+
};
|
|
7986
|
+
function isLogicalOp(op) {
|
|
7987
|
+
return op === "&&" || op === "||";
|
|
7988
|
+
}
|
|
7989
|
+
function isBinaryOp(op) {
|
|
7990
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7991
|
+
}
|
|
7992
|
+
var Parser = class {
|
|
7993
|
+
tokens;
|
|
7994
|
+
pos = 0;
|
|
7995
|
+
nodeCount = 0;
|
|
7996
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7997
|
+
callees = /* @__PURE__ */ new Set();
|
|
7998
|
+
constructor(tokens) {
|
|
7999
|
+
this.tokens = tokens;
|
|
8000
|
+
}
|
|
8001
|
+
parse() {
|
|
8002
|
+
const ast = this.parseTernary();
|
|
8003
|
+
const tok = this.peek();
|
|
8004
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
8005
|
+
return {
|
|
8006
|
+
ast,
|
|
8007
|
+
identifiers: this.identifiers,
|
|
8008
|
+
callees: this.callees,
|
|
8009
|
+
nodeCount: this.nodeCount
|
|
8010
|
+
};
|
|
8011
|
+
}
|
|
8012
|
+
peek() {
|
|
8013
|
+
return this.tokens[this.pos];
|
|
8014
|
+
}
|
|
8015
|
+
next() {
|
|
8016
|
+
return this.tokens[this.pos++];
|
|
8017
|
+
}
|
|
8018
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8019
|
+
expectPunct(punct) {
|
|
8020
|
+
const tok = this.peek();
|
|
8021
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8022
|
+
this.pos += 1;
|
|
8023
|
+
}
|
|
8024
|
+
matchPunct(punct) {
|
|
8025
|
+
const tok = this.peek();
|
|
8026
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8027
|
+
this.pos += 1;
|
|
8028
|
+
return true;
|
|
8029
|
+
}
|
|
8030
|
+
return false;
|
|
8031
|
+
}
|
|
8032
|
+
countNode() {
|
|
8033
|
+
this.nodeCount += 1;
|
|
8034
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8035
|
+
}
|
|
8036
|
+
parseTernary() {
|
|
8037
|
+
const test = this.parseBinary(1);
|
|
8038
|
+
if (this.matchPunct("?")) {
|
|
8039
|
+
const consequent = this.parseTernary();
|
|
8040
|
+
this.expectPunct(":");
|
|
8041
|
+
const alternate = this.parseTernary();
|
|
8042
|
+
this.countNode();
|
|
8043
|
+
return {
|
|
8044
|
+
kind: "conditional",
|
|
8045
|
+
test,
|
|
8046
|
+
consequent,
|
|
8047
|
+
alternate
|
|
8048
|
+
};
|
|
8049
|
+
}
|
|
8050
|
+
return test;
|
|
8051
|
+
}
|
|
8052
|
+
parseBinary(minPrec) {
|
|
8053
|
+
let left = this.parseUnary();
|
|
8054
|
+
for (;;) {
|
|
8055
|
+
const tok = this.peek();
|
|
8056
|
+
if (tok.type !== "punct") break;
|
|
8057
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8058
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8059
|
+
const op = tok.punct;
|
|
8060
|
+
this.pos += 1;
|
|
8061
|
+
const right = this.parseBinary(prec + 1);
|
|
8062
|
+
this.countNode();
|
|
8063
|
+
if (isLogicalOp(op)) left = {
|
|
8064
|
+
kind: "logical",
|
|
8065
|
+
op,
|
|
8066
|
+
left,
|
|
8067
|
+
right
|
|
8068
|
+
};
|
|
8069
|
+
else if (isBinaryOp(op)) left = {
|
|
8070
|
+
kind: "binary",
|
|
8071
|
+
op,
|
|
8072
|
+
left,
|
|
8073
|
+
right
|
|
8074
|
+
};
|
|
8075
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8076
|
+
}
|
|
8077
|
+
return left;
|
|
8078
|
+
}
|
|
8079
|
+
parseUnary() {
|
|
8080
|
+
const tok = this.peek();
|
|
8081
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8082
|
+
const op = tok.punct;
|
|
8083
|
+
this.pos += 1;
|
|
8084
|
+
const operand = this.parseUnary();
|
|
8085
|
+
this.countNode();
|
|
8086
|
+
return {
|
|
8087
|
+
kind: "unary",
|
|
8088
|
+
op,
|
|
8089
|
+
operand
|
|
8090
|
+
};
|
|
8091
|
+
}
|
|
8092
|
+
return this.parsePrimary();
|
|
8093
|
+
}
|
|
8094
|
+
parsePrimary() {
|
|
8095
|
+
const tok = this.next();
|
|
8096
|
+
switch (tok.type) {
|
|
8097
|
+
case "number":
|
|
8098
|
+
this.countNode();
|
|
8099
|
+
return {
|
|
8100
|
+
kind: "literal",
|
|
8101
|
+
value: tok.value
|
|
8102
|
+
};
|
|
8103
|
+
case "string":
|
|
8104
|
+
this.countNode();
|
|
8105
|
+
return {
|
|
8106
|
+
kind: "literal",
|
|
8107
|
+
value: tok.value
|
|
8108
|
+
};
|
|
8109
|
+
case "keyword":
|
|
8110
|
+
this.countNode();
|
|
8111
|
+
return {
|
|
8112
|
+
kind: "literal",
|
|
8113
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8114
|
+
};
|
|
8115
|
+
case "identifier": {
|
|
8116
|
+
const nextTok = this.peek();
|
|
8117
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8118
|
+
this.identifiers.add(tok.name);
|
|
8119
|
+
this.countNode();
|
|
8120
|
+
return {
|
|
8121
|
+
kind: "identifier",
|
|
8122
|
+
name: tok.name
|
|
8123
|
+
};
|
|
8124
|
+
}
|
|
8125
|
+
case "punct":
|
|
8126
|
+
if (tok.punct === "(") {
|
|
8127
|
+
const inner = this.parseTernary();
|
|
8128
|
+
this.expectPunct(")");
|
|
8129
|
+
return inner;
|
|
8130
|
+
}
|
|
8131
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8132
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8133
|
+
}
|
|
8134
|
+
}
|
|
8135
|
+
parseCall(callee, pos) {
|
|
8136
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8137
|
+
this.expectPunct("(");
|
|
8138
|
+
const args = [];
|
|
8139
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8140
|
+
args.push(this.parseTernary());
|
|
8141
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8142
|
+
if (this.matchPunct(",")) continue;
|
|
8143
|
+
this.expectPunct(")");
|
|
8144
|
+
break;
|
|
8145
|
+
}
|
|
8146
|
+
this.callees.add(callee);
|
|
8147
|
+
this.countNode();
|
|
8148
|
+
return {
|
|
8149
|
+
kind: "call",
|
|
8150
|
+
callee,
|
|
8151
|
+
args
|
|
8152
|
+
};
|
|
8153
|
+
}
|
|
8154
|
+
};
|
|
8155
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8156
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8157
|
+
function parseExpression(source) {
|
|
8158
|
+
return new Parser(tokenize(source)).parse();
|
|
8159
|
+
}
|
|
8160
|
+
Object.freeze({});
|
|
8161
|
+
/**
|
|
8162
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8163
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8164
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8165
|
+
* one per read on a hot resolve path.
|
|
8166
|
+
*
|
|
8167
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8168
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8169
|
+
* callers is safe and maximises hit rate.
|
|
8170
|
+
*/
|
|
8171
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8172
|
+
function getCached(source) {
|
|
8173
|
+
const hit = cache.get(source);
|
|
8174
|
+
if (hit !== void 0) {
|
|
8175
|
+
cache.delete(source);
|
|
8176
|
+
cache.set(source, hit);
|
|
8177
|
+
return hit;
|
|
8178
|
+
}
|
|
8179
|
+
let result;
|
|
8180
|
+
try {
|
|
8181
|
+
result = {
|
|
8182
|
+
ok: true,
|
|
8183
|
+
parsed: parseExpression(source)
|
|
8184
|
+
};
|
|
8185
|
+
} catch (err) {
|
|
8186
|
+
result = {
|
|
8187
|
+
ok: false,
|
|
8188
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8189
|
+
};
|
|
8190
|
+
}
|
|
8191
|
+
cache.set(source, result);
|
|
8192
|
+
if (cache.size > 256) {
|
|
8193
|
+
const oldest = cache.keys().next().value;
|
|
8194
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8195
|
+
}
|
|
8196
|
+
return result;
|
|
8197
|
+
}
|
|
8198
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8199
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8200
|
+
function compileExpressionSafe(source) {
|
|
8201
|
+
return getCached(source);
|
|
8202
|
+
}
|
|
8203
|
+
/**
|
|
8204
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8205
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8206
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8207
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8208
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8209
|
+
*/
|
|
8210
|
+
function validateExpressionSource(src) {
|
|
8211
|
+
const names = Object.keys(src.bindings);
|
|
8212
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8213
|
+
for (const name of names) {
|
|
8214
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8215
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8216
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8217
|
+
}
|
|
8218
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8219
|
+
if (!compiled.ok) return compiled.error;
|
|
8220
|
+
const bound = new Set(names);
|
|
8221
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8222
|
+
if (id === "now") continue;
|
|
8223
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8224
|
+
}
|
|
8225
|
+
return null;
|
|
8226
|
+
}
|
|
8227
|
+
/**
|
|
7463
8228
|
* Accessory device helpers — shared across drivers.
|
|
7464
8229
|
*
|
|
7465
8230
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -8304,7 +9069,13 @@ onStatusChanged: { data: object({
|
|
|
8304
9069
|
}) } },
|
|
8305
9070
|
status: {
|
|
8306
9071
|
schema: BatteryStatusSchema,
|
|
8307
|
-
kind: "push"
|
|
9072
|
+
kind: "push",
|
|
9073
|
+
empty: {
|
|
9074
|
+
percentage: 0,
|
|
9075
|
+
charging: "none",
|
|
9076
|
+
sleeping: false,
|
|
9077
|
+
lastUpdated: 0
|
|
9078
|
+
}
|
|
8308
9079
|
},
|
|
8309
9080
|
/**
|
|
8310
9081
|
* Runtime-state slice — every provider that registers this cap
|
|
@@ -9247,21 +10018,38 @@ var connectivityCapability = {
|
|
|
9247
10018
|
},
|
|
9248
10019
|
runtimeState: ConnectivityStatusSchema
|
|
9249
10020
|
};
|
|
10021
|
+
/**
|
|
10022
|
+
* Generic device-consumables capability — surfaces a device's
|
|
10023
|
+
* maintenance items (vacuum filters/brushes, replaceable cartridges,
|
|
10024
|
+
* descaling cycles, …) with their remaining life and an optional
|
|
10025
|
+
* "Replaced" reset action. Device-agnostic: any provider that knows its
|
|
10026
|
+
* device tracks consumables can register it; the cap declares no
|
|
10027
|
+
* vocabulary of its own — the provider names each item verbatim.
|
|
10028
|
+
*
|
|
10029
|
+
* Like `childLayout`, the cap is INERT until a provider sets items: no
|
|
10030
|
+
* provider populates it by guessing (no HA inference). The UI renders a
|
|
10031
|
+
* "No consumables reported" placeholder when `items` is empty.
|
|
10032
|
+
*/
|
|
10033
|
+
/** A single consumable item. Either a continuous `level` (remaining
|
|
10034
|
+
* life %) or a discrete `status` may be known — both may be null when a
|
|
10035
|
+
* provider only knows the item exists. `level` and `status` are not
|
|
10036
|
+
* mutually exclusive; a provider may report both. */
|
|
10037
|
+
var ConsumableItemSchema = object({
|
|
10038
|
+
/** Stable id, e.g. 'main-brush'. */
|
|
10039
|
+
key: string().min(1),
|
|
10040
|
+
/** Display name. */
|
|
10041
|
+
label: string().min(1),
|
|
10042
|
+
/** Remaining life % when known (0..100). */
|
|
10043
|
+
level: number().min(0).max(100).nullable(),
|
|
10044
|
+
/** Discrete state when known (binary mode). */
|
|
10045
|
+
status: _enum(["ok", "replace"]).nullable(),
|
|
10046
|
+
/** Ms epoch of the last replace, when known. */
|
|
10047
|
+
lastResetAt: number().nullable(),
|
|
10048
|
+
/** Whether `reset()` is meaningful for this item. */
|
|
10049
|
+
resettable: boolean()
|
|
10050
|
+
});
|
|
9250
10051
|
var ConsumablesStatusSchema = object({
|
|
9251
|
-
items: array(
|
|
9252
|
-
/** Stable id, e.g. 'main-brush'. */
|
|
9253
|
-
key: string().min(1),
|
|
9254
|
-
/** Display name. */
|
|
9255
|
-
label: string().min(1),
|
|
9256
|
-
/** Remaining life % when known (0..100). */
|
|
9257
|
-
level: number().min(0).max(100).nullable(),
|
|
9258
|
-
/** Discrete state when known (binary mode). */
|
|
9259
|
-
status: _enum(["ok", "replace"]).nullable(),
|
|
9260
|
-
/** Ms epoch of the last replace, when known. */
|
|
9261
|
-
lastResetAt: number().nullable(),
|
|
9262
|
-
/** Whether `reset()` is meaningful for this item. */
|
|
9263
|
-
resettable: boolean()
|
|
9264
|
-
})),
|
|
10052
|
+
items: array(ConsumableItemSchema),
|
|
9265
10053
|
lastChangedAt: number()
|
|
9266
10054
|
});
|
|
9267
10055
|
var consumablesCapability = {
|
|
@@ -9320,7 +10108,25 @@ reset: method(object({
|
|
|
9320
10108
|
}) },
|
|
9321
10109
|
status: {
|
|
9322
10110
|
schema: ConsumablesStatusSchema,
|
|
9323
|
-
kind: "push"
|
|
10111
|
+
kind: "push",
|
|
10112
|
+
empty: {
|
|
10113
|
+
items: [],
|
|
10114
|
+
lastChangedAt: 0
|
|
10115
|
+
},
|
|
10116
|
+
itemArray: {
|
|
10117
|
+
path: "items",
|
|
10118
|
+
keyField: "key",
|
|
10119
|
+
labelField: "label",
|
|
10120
|
+
itemSchema: ConsumableItemSchema,
|
|
10121
|
+
emptyItem: {
|
|
10122
|
+
key: "",
|
|
10123
|
+
label: "",
|
|
10124
|
+
level: null,
|
|
10125
|
+
status: null,
|
|
10126
|
+
lastResetAt: null,
|
|
10127
|
+
resettable: false
|
|
10128
|
+
}
|
|
10129
|
+
}
|
|
9324
10130
|
},
|
|
9325
10131
|
runtimeState: ConsumablesStatusSchema.extend({ lastFetchedAt: number() })
|
|
9326
10132
|
};
|
|
@@ -10562,7 +11368,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
10562
11368
|
});
|
|
10563
11369
|
method(object({
|
|
10564
11370
|
deviceId: number(),
|
|
10565
|
-
frame: FrameInputSchema
|
|
11371
|
+
frame: FrameInputSchema.optional(),
|
|
11372
|
+
frameHandle: FrameHandleSchema.optional()
|
|
10566
11373
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
10567
11374
|
deviceId: number(),
|
|
10568
11375
|
detected: boolean(),
|
|
@@ -10809,6 +11616,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
10809
11616
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
10810
11617
|
steps: array(PipelineStepInputSchema).min(1),
|
|
10811
11618
|
frame: FrameInputSchema.optional(),
|
|
11619
|
+
/**
|
|
11620
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
11621
|
+
* the decoded pixels live in. One more member of the one-of
|
|
11622
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
11623
|
+
*/
|
|
11624
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
10812
11625
|
imageBase64: string().optional(),
|
|
10813
11626
|
/**
|
|
10814
11627
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -11051,6 +11864,31 @@ var ReportMotionInputSchema = object({
|
|
|
11051
11864
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
11052
11865
|
});
|
|
11053
11866
|
/**
|
|
11867
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
11868
|
+
* restream-owner model — P2c).
|
|
11869
|
+
*
|
|
11870
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
11871
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
11872
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
11873
|
+
* behavior change.
|
|
11874
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
11875
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
11876
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
11877
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
11878
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
11879
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
11880
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
11881
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
11882
|
+
* dials for the owner's restream.
|
|
11883
|
+
*/
|
|
11884
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
11885
|
+
kind: literal("remote-restream"),
|
|
11886
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
11887
|
+
ownerNodeId: string(),
|
|
11888
|
+
/** Operator override for the owner host the runner dials. */
|
|
11889
|
+
hubHostnameOverride: string().optional()
|
|
11890
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
11891
|
+
/**
|
|
11054
11892
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
11055
11893
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
11056
11894
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -11148,7 +11986,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
11148
11986
|
*/
|
|
11149
11987
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
11150
11988
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
11151
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
11989
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
11990
|
+
/**
|
|
11991
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
11992
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
11993
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
11994
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
11995
|
+
* `remoteSourcingNodes` rollout setting).
|
|
11996
|
+
*/
|
|
11997
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
11152
11998
|
});
|
|
11153
11999
|
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;
|
|
11154
12000
|
/**
|
|
@@ -11712,6 +12558,157 @@ var numericSensorCapability = {
|
|
|
11712
12558
|
runtimeState: NumericSensorStatusSchema
|
|
11713
12559
|
};
|
|
11714
12560
|
/**
|
|
12561
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
12562
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
12563
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
12564
|
+
*/
|
|
12565
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
12566
|
+
"normal",
|
|
12567
|
+
"offline",
|
|
12568
|
+
"on_batteries"
|
|
12569
|
+
]);
|
|
12570
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
12571
|
+
var PetFeederStatusSchema = object({
|
|
12572
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
12573
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
12574
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
12575
|
+
foodLevel: number().nullable(),
|
|
12576
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
12577
|
+
* single-hopper models. */
|
|
12578
|
+
food1: number().nullable(),
|
|
12579
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
12580
|
+
* single-hopper models. */
|
|
12581
|
+
food2: number().nullable(),
|
|
12582
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
12583
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
12584
|
+
* below the feeder's low threshold. */
|
|
12585
|
+
lowFood: boolean(),
|
|
12586
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
12587
|
+
* device has no battery reading. */
|
|
12588
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
12589
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
12590
|
+
* desiccant sensor. */
|
|
12591
|
+
desiccantLeftDays: number().nullable(),
|
|
12592
|
+
/** True while a feed is in progress. */
|
|
12593
|
+
feeding: boolean(),
|
|
12594
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
12595
|
+
* Null until the device has reported a status. */
|
|
12596
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
12597
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
12598
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
12599
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
12600
|
+
error: string().nullable(),
|
|
12601
|
+
/** Raw device error code (0 / null = no error). */
|
|
12602
|
+
errorCode: number().nullable(),
|
|
12603
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
12604
|
+
isDualHopper: boolean(),
|
|
12605
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
12606
|
+
childLock: boolean(),
|
|
12607
|
+
/** Front indicator-light setting. */
|
|
12608
|
+
indicatorLight: boolean(),
|
|
12609
|
+
/** Play a chime when dispensing. */
|
|
12610
|
+
feedSound: boolean(),
|
|
12611
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
12612
|
+
volume: number(),
|
|
12613
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
12614
|
+
lastFetchedAt: number()
|
|
12615
|
+
});
|
|
12616
|
+
var petFeederCapability = {
|
|
12617
|
+
name: "pet-feeder",
|
|
12618
|
+
scope: "device",
|
|
12619
|
+
deviceNative: true,
|
|
12620
|
+
mode: "singleton",
|
|
12621
|
+
deviceTypes: [DeviceType.PetFeeder],
|
|
12622
|
+
methods: {
|
|
12623
|
+
/**
|
|
12624
|
+
* Dispense food now. Single-hopper feeders take `grams`; dual-hopper
|
|
12625
|
+
* feeders (D4S/D4SH) accept `hopper1`/`hopper2` to target one or both
|
|
12626
|
+
* hoppers. All portions honour the 4–200 g hardware range. At least
|
|
12627
|
+
* one of the three must be present — the provider rejects an empty
|
|
12628
|
+
* request.
|
|
12629
|
+
*/
|
|
12630
|
+
feed: method(object({
|
|
12631
|
+
deviceId: number().int().nonnegative(),
|
|
12632
|
+
grams: gramsPortion.optional(),
|
|
12633
|
+
hopper1: gramsPortion.optional(),
|
|
12634
|
+
hopper2: gramsPortion.optional()
|
|
12635
|
+
}), _void(), {
|
|
12636
|
+
kind: "mutation",
|
|
12637
|
+
auth: "admin"
|
|
12638
|
+
}),
|
|
12639
|
+
/** Cancel an in-progress manual feed. */
|
|
12640
|
+
cancelFeed: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12641
|
+
kind: "mutation",
|
|
12642
|
+
auth: "admin"
|
|
12643
|
+
}),
|
|
12644
|
+
/** Reset the desiccant "days remaining" counter after replacing it. */
|
|
12645
|
+
resetDesiccant: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12646
|
+
kind: "mutation",
|
|
12647
|
+
auth: "admin"
|
|
12648
|
+
}),
|
|
12649
|
+
/** Mark a hopper as refilled (D4H/D4S/D4SH). */
|
|
12650
|
+
markFoodReplenished: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12651
|
+
kind: "mutation",
|
|
12652
|
+
auth: "admin"
|
|
12653
|
+
}),
|
|
12654
|
+
/** Call the pet with the recorded prompt (D3). */
|
|
12655
|
+
callPet: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12656
|
+
kind: "mutation",
|
|
12657
|
+
auth: "admin"
|
|
12658
|
+
}),
|
|
12659
|
+
/** Play a stored sound by id (D3 / D4H / D4SH). */
|
|
12660
|
+
playSound: method(object({
|
|
12661
|
+
deviceId: number().int().nonnegative(),
|
|
12662
|
+
soundId: number().int().nonnegative()
|
|
12663
|
+
}), _void(), {
|
|
12664
|
+
kind: "mutation",
|
|
12665
|
+
auth: "admin"
|
|
12666
|
+
}),
|
|
12667
|
+
/** Toggle the child-lock (manual-lock) setting. */
|
|
12668
|
+
setChildLock: method(object({
|
|
12669
|
+
deviceId: number().int().nonnegative(),
|
|
12670
|
+
on: boolean()
|
|
12671
|
+
}), _void(), {
|
|
12672
|
+
kind: "mutation",
|
|
12673
|
+
auth: "admin"
|
|
12674
|
+
}),
|
|
12675
|
+
/** Toggle the front indicator light. */
|
|
12676
|
+
setIndicatorLight: method(object({
|
|
12677
|
+
deviceId: number().int().nonnegative(),
|
|
12678
|
+
on: boolean()
|
|
12679
|
+
}), _void(), {
|
|
12680
|
+
kind: "mutation",
|
|
12681
|
+
auth: "admin"
|
|
12682
|
+
}),
|
|
12683
|
+
/** Toggle the dispense chime. */
|
|
12684
|
+
setFeedSound: method(object({
|
|
12685
|
+
deviceId: number().int().nonnegative(),
|
|
12686
|
+
on: boolean()
|
|
12687
|
+
}), _void(), {
|
|
12688
|
+
kind: "mutation",
|
|
12689
|
+
auth: "admin"
|
|
12690
|
+
}),
|
|
12691
|
+
/** Set the speaker / prompt volume level. */
|
|
12692
|
+
setVolume: method(object({
|
|
12693
|
+
deviceId: number().int().nonnegative(),
|
|
12694
|
+
level: number().int().nonnegative()
|
|
12695
|
+
}), _void(), {
|
|
12696
|
+
kind: "mutation",
|
|
12697
|
+
auth: "admin"
|
|
12698
|
+
})
|
|
12699
|
+
},
|
|
12700
|
+
status: {
|
|
12701
|
+
schema: PetFeederStatusSchema,
|
|
12702
|
+
kind: "poll"
|
|
12703
|
+
},
|
|
12704
|
+
/**
|
|
12705
|
+
* Runtime-state slice — mirrored by the kernel. UI feeder cards read
|
|
12706
|
+
* the full slice via `device.state.petFeeder.value` and refresh on
|
|
12707
|
+
* every poll without re-querying the provider.
|
|
12708
|
+
*/
|
|
12709
|
+
runtimeState: PetFeederStatusSchema
|
|
12710
|
+
};
|
|
12711
|
+
/**
|
|
11715
12712
|
* Multi-metric electrical meter. One slice can carry any combination
|
|
11716
12713
|
* of instantaneous power (W), cumulative energy (kWh), voltage (V),
|
|
11717
12714
|
* and current (A) — all fields optional so a single-metric source
|
|
@@ -13014,6 +14011,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
|
|
|
13014
14011
|
nativeObjectDetection: nativeObjectDetectionCapability,
|
|
13015
14012
|
notifier: notifierCapability,
|
|
13016
14013
|
numericSensor: numericSensorCapability,
|
|
14014
|
+
petFeeder: petFeederCapability,
|
|
13017
14015
|
powerMeter: powerMeterCapability,
|
|
13018
14016
|
presence: presenceCapability,
|
|
13019
14017
|
pressureSensor: pressureSensorCapability,
|
|
@@ -14979,10 +15977,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
14979
15977
|
url: string()
|
|
14980
15978
|
}), _void()), method(object({
|
|
14981
15979
|
sessionId: string(),
|
|
14982
|
-
maxCount: number().default(1)
|
|
15980
|
+
maxCount: number().default(1),
|
|
15981
|
+
waitMs: number().optional()
|
|
14983
15982
|
}), array(DecodedFrameSchema)), method(object({
|
|
14984
15983
|
sessionId: string(),
|
|
14985
|
-
maxCount: number().default(1)
|
|
15984
|
+
maxCount: number().default(1),
|
|
15985
|
+
waitMs: number().optional()
|
|
14986
15986
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
14987
15987
|
sessionId: string(),
|
|
14988
15988
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -15286,14 +16286,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
15286
16286
|
collapsed: boolean().optional()
|
|
15287
16287
|
});
|
|
15288
16288
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
15289
|
-
* `device-management.ts`.
|
|
16289
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
16290
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
16291
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
16292
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
16293
|
+
* source device's full re-sync-stable `stableId`. */
|
|
16294
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
16295
|
+
kind: literal("field").optional(),
|
|
16296
|
+
sourceKey: string(),
|
|
16297
|
+
cap: string(),
|
|
16298
|
+
fieldPath: string()
|
|
16299
|
+
});
|
|
16300
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
16301
|
+
kind: literal("literal"),
|
|
16302
|
+
value: union([
|
|
16303
|
+
string(),
|
|
16304
|
+
number(),
|
|
16305
|
+
boolean(),
|
|
16306
|
+
_null()
|
|
16307
|
+
])
|
|
16308
|
+
});
|
|
16309
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
16310
|
+
kind: literal("global"),
|
|
16311
|
+
sourceStableId: string(),
|
|
16312
|
+
cap: string(),
|
|
16313
|
+
fieldPath: string()
|
|
16314
|
+
});
|
|
16315
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
16316
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
16317
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
16318
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
16319
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
16320
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
16321
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
16322
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
16323
|
+
kind: literal("expression"),
|
|
16324
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
16325
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
16326
|
+
DeviceLinkFieldSourceSchema,
|
|
16327
|
+
DeviceLinkLiteralSourceSchema,
|
|
16328
|
+
DeviceLinkGlobalSourceSchema
|
|
16329
|
+
]))
|
|
16330
|
+
}).superRefine((src, ctx) => {
|
|
16331
|
+
const err = validateExpressionSource(src);
|
|
16332
|
+
if (err !== null) ctx.addIssue({
|
|
16333
|
+
code: "custom",
|
|
16334
|
+
message: err,
|
|
16335
|
+
path: ["expr"]
|
|
16336
|
+
});
|
|
16337
|
+
});
|
|
15290
16338
|
var DeviceLinkSchema = object({
|
|
15291
16339
|
id: string(),
|
|
15292
|
-
source:
|
|
15293
|
-
|
|
15294
|
-
|
|
15295
|
-
|
|
15296
|
-
|
|
16340
|
+
source: union([
|
|
16341
|
+
DeviceLinkFieldSourceSchema,
|
|
16342
|
+
DeviceLinkLiteralSourceSchema,
|
|
16343
|
+
DeviceLinkGlobalSourceSchema,
|
|
16344
|
+
DeviceLinkExpressionSourceSchema
|
|
16345
|
+
]),
|
|
15297
16346
|
target: object({
|
|
15298
16347
|
cap: string(),
|
|
15299
16348
|
fieldPath: string(),
|
|
@@ -15322,6 +16371,31 @@ var DeviceLinkSchema = object({
|
|
|
15322
16371
|
})
|
|
15323
16372
|
]).optional()
|
|
15324
16373
|
});
|
|
16374
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
16375
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
16376
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
16377
|
+
unit: string().min(1).optional(),
|
|
16378
|
+
precision: number().int().min(0).max(10).optional()
|
|
16379
|
+
});
|
|
16380
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
16381
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
16382
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
16383
|
+
var DeviceDisplayOverrideSchema = object({
|
|
16384
|
+
icon: string().min(1).optional(),
|
|
16385
|
+
label: string().min(1).optional(),
|
|
16386
|
+
unit: string().min(1).optional(),
|
|
16387
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16388
|
+
hidden: boolean().optional(),
|
|
16389
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
16390
|
+
});
|
|
16391
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
16392
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
16393
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
16394
|
+
var RoleDisplayDefaultSchema = object({
|
|
16395
|
+
unit: string().min(1).optional(),
|
|
16396
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16397
|
+
icon: string().min(1).optional()
|
|
16398
|
+
});
|
|
15325
16399
|
/**
|
|
15326
16400
|
* Serializable projection of a live IDevice.
|
|
15327
16401
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -15377,7 +16451,9 @@ var DeviceInfoSchema = object({
|
|
|
15377
16451
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
15378
16452
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
15379
16453
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
15380
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
16454
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
16455
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16456
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15381
16457
|
});
|
|
15382
16458
|
var ConfigEntrySchema = object({
|
|
15383
16459
|
key: string(),
|
|
@@ -15442,7 +16518,9 @@ var DeviceMetaSchema = object({
|
|
|
15442
16518
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
15443
16519
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
15444
16520
|
* Optional: only present for accessory children that carry a known role. */
|
|
15445
|
-
role: string().nullable().optional()
|
|
16521
|
+
role: string().nullable().optional(),
|
|
16522
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16523
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15446
16524
|
});
|
|
15447
16525
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
15448
16526
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -15536,7 +16614,19 @@ method(object({
|
|
|
15536
16614
|
}), _void(), {
|
|
15537
16615
|
kind: "mutation",
|
|
15538
16616
|
auth: "admin"
|
|
15539
|
-
}), method(object({
|
|
16617
|
+
}), method(object({
|
|
16618
|
+
deviceId: number(),
|
|
16619
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
16620
|
+
}), _void(), {
|
|
16621
|
+
kind: "mutation",
|
|
16622
|
+
auth: "admin"
|
|
16623
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
16624
|
+
kind: "mutation",
|
|
16625
|
+
auth: "admin"
|
|
16626
|
+
}), method(object({
|
|
16627
|
+
deviceId: number(),
|
|
16628
|
+
includeSynthesizable: boolean().optional()
|
|
16629
|
+
}), object({ caps: array(object({
|
|
15540
16630
|
cap: string(),
|
|
15541
16631
|
fields: array(object({
|
|
15542
16632
|
path: string(),
|
|
@@ -15546,8 +16636,13 @@ method(object({
|
|
|
15546
16636
|
"boolean",
|
|
15547
16637
|
"enum"
|
|
15548
16638
|
]),
|
|
15549
|
-
enumValues: array(string()).optional()
|
|
15550
|
-
|
|
16639
|
+
enumValues: array(string()).optional(),
|
|
16640
|
+
item: boolean().optional()
|
|
16641
|
+
})).readonly(),
|
|
16642
|
+
itemArray: object({
|
|
16643
|
+
path: string(),
|
|
16644
|
+
keyField: string()
|
|
16645
|
+
}).optional()
|
|
15551
16646
|
})).readonly() }), { kind: "query" }), method(object({
|
|
15552
16647
|
deviceId: number(),
|
|
15553
16648
|
role: string().nullable()
|
|
@@ -15617,7 +16712,11 @@ method(object({
|
|
|
15617
16712
|
deviceId: number(),
|
|
15618
16713
|
entries: array(object({
|
|
15619
16714
|
capName: string(),
|
|
15620
|
-
kind: _enum([
|
|
16715
|
+
kind: _enum([
|
|
16716
|
+
"native",
|
|
16717
|
+
"wrapped",
|
|
16718
|
+
"linked"
|
|
16719
|
+
]),
|
|
15621
16720
|
providerAddonId: string(),
|
|
15622
16721
|
providerNodeId: string(),
|
|
15623
16722
|
nativeAddonId: string()
|
|
@@ -15626,7 +16725,11 @@ method(object({
|
|
|
15626
16725
|
deviceId: number(),
|
|
15627
16726
|
entries: array(object({
|
|
15628
16727
|
capName: string(),
|
|
15629
|
-
kind: _enum([
|
|
16728
|
+
kind: _enum([
|
|
16729
|
+
"native",
|
|
16730
|
+
"wrapped",
|
|
16731
|
+
"linked"
|
|
16732
|
+
]),
|
|
15630
16733
|
providerAddonId: string(),
|
|
15631
16734
|
providerNodeId: string(),
|
|
15632
16735
|
nativeAddonId: string()
|
|
@@ -16116,7 +17219,7 @@ var AddBrokerInputSchema = object({
|
|
|
16116
17219
|
});
|
|
16117
17220
|
var AddBrokerResultSchema = object({ id: string() });
|
|
16118
17221
|
var IdInputSchema = object({ id: string() });
|
|
16119
|
-
var TestResultSchema = discriminatedUnion("ok", [object({
|
|
17222
|
+
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
16120
17223
|
ok: literal(true),
|
|
16121
17224
|
latencyMs: number()
|
|
16122
17225
|
}), object({
|
|
@@ -16139,7 +17242,7 @@ var StatusSchema = object({
|
|
|
16139
17242
|
brokerCount: number(),
|
|
16140
17243
|
embeddedRunning: boolean()
|
|
16141
17244
|
});
|
|
16142
|
-
method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema), method(AddBrokerInputSchema, AddBrokerResultSchema, { kind: "mutation" }), method(IdInputSchema, _void(), { kind: "mutation" }), method(IdInputSchema, TestResultSchema, { kind: "mutation" }), method(StartEmbeddedInputSchema, StartEmbeddedResultSchema, { kind: "mutation" }), method(IdInputSchema, _void(), { kind: "mutation" }), method(_void(), StatusSchema);
|
|
17245
|
+
method(_void(), array(BrokerInfoSchema)), method(IdInputSchema, BrokerConnectionDetailsSchema), method(AddBrokerInputSchema, AddBrokerResultSchema, { kind: "mutation" }), method(IdInputSchema, _void(), { kind: "mutation" }), method(IdInputSchema, TestResultSchema$1, { kind: "mutation" }), method(StartEmbeddedInputSchema, StartEmbeddedResultSchema, { kind: "mutation" }), method(IdInputSchema, _void(), { kind: "mutation" }), method(_void(), StatusSchema);
|
|
16143
17246
|
var NetworkEndpointSchema = object({
|
|
16144
17247
|
url: string(),
|
|
16145
17248
|
hostname: string(),
|
|
@@ -16173,23 +17276,198 @@ var NetworkEndpointEntrySchema = NetworkEndpointSchema.extend({
|
|
|
16173
17276
|
sourcePort: number().optional()
|
|
16174
17277
|
});
|
|
16175
17278
|
method(_void(), NetworkEndpointSchema, { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), method(_void(), NetworkEndpointSchema.nullable()), method(_void(), NetworkAccessStatusSchema), method(_void(), array(NetworkEndpointEntrySchema).readonly());
|
|
16176
|
-
|
|
16177
|
-
|
|
17279
|
+
/**
|
|
17280
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
17281
|
+
*
|
|
17282
|
+
* Apprise-derived model (see
|
|
17283
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
17284
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
17285
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
17286
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
17287
|
+
* message to what the kind supports — callers never special-case a service.
|
|
17288
|
+
*
|
|
17289
|
+
* DESIGN DECISIONS (locked):
|
|
17290
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
17291
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
17292
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
17293
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
17294
|
+
* alternative would fork the UI per addon and cannot host the
|
|
17295
|
+
* discovery→adopt flow.
|
|
17296
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
17297
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
17298
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
17299
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
17300
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
17301
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
17302
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
17303
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
17304
|
+
* base64 fallback needed.
|
|
17305
|
+
*
|
|
17306
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
17307
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
17308
|
+
* admin "Integrations" page.
|
|
17309
|
+
*/
|
|
17310
|
+
/**
|
|
17311
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
17312
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
17313
|
+
*/
|
|
17314
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
17315
|
+
"image",
|
|
17316
|
+
"video",
|
|
17317
|
+
"gif",
|
|
17318
|
+
"audio",
|
|
17319
|
+
"icon"
|
|
17320
|
+
]);
|
|
17321
|
+
/**
|
|
17322
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
17323
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
17324
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
17325
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
17326
|
+
*/
|
|
17327
|
+
var AttachmentSchema = object({
|
|
17328
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
17329
|
+
url: string().optional(),
|
|
17330
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
17331
|
+
mime: string().optional(),
|
|
17332
|
+
name: string().optional()
|
|
17333
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
17334
|
+
var NotificationFormatSchema = _enum([
|
|
17335
|
+
"text",
|
|
17336
|
+
"markdown",
|
|
17337
|
+
"html"
|
|
17338
|
+
]);
|
|
17339
|
+
/** A single tap-through action button. */
|
|
17340
|
+
var NotificationActionSchema = object({
|
|
17341
|
+
id: string(),
|
|
17342
|
+
label: string(),
|
|
17343
|
+
url: string().optional()
|
|
17344
|
+
});
|
|
17345
|
+
/**
|
|
17346
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
17347
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
17348
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
17349
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
17350
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
17351
|
+
* `priority` for that one target.
|
|
17352
|
+
*/
|
|
17353
|
+
var NotificationSchema = object({
|
|
16178
17354
|
body: string(),
|
|
16179
|
-
|
|
17355
|
+
title: string().optional(),
|
|
17356
|
+
format: NotificationFormatSchema.default("text"),
|
|
17357
|
+
priority: number().int().min(1).max(5).default(3),
|
|
17358
|
+
level: string().optional(),
|
|
17359
|
+
attachments: array(AttachmentSchema).optional(),
|
|
17360
|
+
clickUrl: string().optional(),
|
|
17361
|
+
actions: array(NotificationActionSchema).optional(),
|
|
17362
|
+
sound: string().optional(),
|
|
17363
|
+
ttl: number().optional(),
|
|
17364
|
+
tag: string().optional(),
|
|
16180
17365
|
deviceId: number().optional(),
|
|
16181
17366
|
eventId: string().optional(),
|
|
16182
|
-
priority: _enum([
|
|
16183
|
-
"low",
|
|
16184
|
-
"normal",
|
|
16185
|
-
"high",
|
|
16186
|
-
"critical"
|
|
16187
|
-
]).default("normal"),
|
|
16188
17367
|
metadata: record(string(), unknown()).optional()
|
|
16189
|
-
})
|
|
17368
|
+
});
|
|
17369
|
+
/** One declared native severity/priority level for a kind. */
|
|
17370
|
+
var TargetKindLevelSchema = object({
|
|
17371
|
+
id: string(),
|
|
17372
|
+
label: string(),
|
|
17373
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
17374
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
17375
|
+
flags: object({
|
|
17376
|
+
critical: boolean().optional(),
|
|
17377
|
+
silent: boolean().optional(),
|
|
17378
|
+
noPush: boolean().optional()
|
|
17379
|
+
}).optional(),
|
|
17380
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
17381
|
+
requires: array(string()).optional(),
|
|
17382
|
+
description: string().optional()
|
|
17383
|
+
});
|
|
17384
|
+
/** The full capability block consulted before dispatch. */
|
|
17385
|
+
var TargetKindCapsSchema = object({
|
|
17386
|
+
attachments: object({
|
|
17387
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
17388
|
+
mode: _enum([
|
|
17389
|
+
"url",
|
|
17390
|
+
"bytes",
|
|
17391
|
+
"both"
|
|
17392
|
+
]),
|
|
17393
|
+
max: number().int().nonnegative(),
|
|
17394
|
+
maxBytes: number().int().positive().optional()
|
|
17395
|
+
}),
|
|
17396
|
+
/** Max action buttons (0 = none). */
|
|
17397
|
+
actions: number().int().nonnegative(),
|
|
17398
|
+
levels: array(TargetKindLevelSchema),
|
|
17399
|
+
format: array(NotificationFormatSchema),
|
|
17400
|
+
clickUrl: boolean(),
|
|
17401
|
+
sound: boolean(),
|
|
17402
|
+
ttl: boolean(),
|
|
17403
|
+
bodyMaxLen: number().int().positive()
|
|
17404
|
+
});
|
|
17405
|
+
/**
|
|
17406
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
17407
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
17408
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
17409
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
17410
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
17411
|
+
*/
|
|
17412
|
+
var ConfigSchemaPassthrough = unknown();
|
|
17413
|
+
var TargetKindSchema = object({
|
|
17414
|
+
kind: string(),
|
|
17415
|
+
label: string(),
|
|
17416
|
+
icon: string(),
|
|
17417
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
17418
|
+
addonId: string(),
|
|
17419
|
+
configSchema: ConfigSchemaPassthrough,
|
|
17420
|
+
supportsDiscovery: boolean(),
|
|
17421
|
+
caps: TargetKindCapsSchema
|
|
17422
|
+
});
|
|
17423
|
+
/**
|
|
17424
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
17425
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
17426
|
+
* round-trip a stored secret to the UI.
|
|
17427
|
+
*/
|
|
17428
|
+
var TargetSchema = object({
|
|
17429
|
+
id: string(),
|
|
17430
|
+
name: string(),
|
|
17431
|
+
kind: string(),
|
|
17432
|
+
addonId: string(),
|
|
17433
|
+
enabled: boolean(),
|
|
17434
|
+
config: record(string(), unknown())
|
|
17435
|
+
});
|
|
17436
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
17437
|
+
var DiscoveredTargetSchema = object({
|
|
17438
|
+
kind: string(),
|
|
17439
|
+
suggestedName: string(),
|
|
17440
|
+
config: record(string(), unknown())
|
|
17441
|
+
});
|
|
17442
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
17443
|
+
var RenderedAsSchema = object({
|
|
17444
|
+
level: string(),
|
|
17445
|
+
format: NotificationFormatSchema,
|
|
17446
|
+
attachmentsSent: number().int().nonnegative(),
|
|
17447
|
+
actionsSent: number().int().nonnegative(),
|
|
17448
|
+
truncated: boolean(),
|
|
17449
|
+
dropped: array(string())
|
|
17450
|
+
});
|
|
17451
|
+
var SendResultSchema = object({
|
|
16190
17452
|
success: boolean(),
|
|
16191
|
-
error: string().optional()
|
|
16192
|
-
|
|
17453
|
+
error: string().optional(),
|
|
17454
|
+
renderedAs: RenderedAsSchema.optional()
|
|
17455
|
+
});
|
|
17456
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
17457
|
+
var TestResultSchema = SendResultSchema;
|
|
17458
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema)), method(object({
|
|
17459
|
+
kind: string(),
|
|
17460
|
+
config: record(string(), unknown()).optional()
|
|
17461
|
+
}), array(DiscoveredTargetSchema)), method(object({
|
|
17462
|
+
targetId: string(),
|
|
17463
|
+
notification: NotificationSchema
|
|
17464
|
+
}), SendResultSchema, { kind: "mutation" }), method(object({
|
|
17465
|
+
targetId: string(),
|
|
17466
|
+
sample: NotificationSchema.optional()
|
|
17467
|
+
}), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
|
|
17468
|
+
targetId: string(),
|
|
17469
|
+
enabled: boolean()
|
|
17470
|
+
}), _void(), { kind: "mutation" });
|
|
16193
17471
|
/**
|
|
16194
17472
|
* Zod schemas for persisted record types.
|
|
16195
17473
|
*
|
|
@@ -19211,7 +20489,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
19211
20489
|
"webgpu",
|
|
19212
20490
|
"none"
|
|
19213
20491
|
]).nullable().optional();
|
|
19214
|
-
var HwAccelResolutionSchema = object({
|
|
20492
|
+
var HwAccelResolutionSchema = object({
|
|
20493
|
+
preferred: array(string()).readonly(),
|
|
20494
|
+
rationale: string()
|
|
20495
|
+
});
|
|
19215
20496
|
var HardwareEncoderIdSchema = _enum([
|
|
19216
20497
|
"h264_videotoolbox",
|
|
19217
20498
|
"hevc_videotoolbox",
|
|
@@ -19316,10 +20597,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
19316
20597
|
format: ModelFormatSchema,
|
|
19317
20598
|
reason: string()
|
|
19318
20599
|
});
|
|
19319
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
19320
|
-
prefer: HwAccelBackendInputSchema,
|
|
19321
|
-
nodeId: string().optional()
|
|
19322
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
20600
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
19323
20601
|
kind: "mutation",
|
|
19324
20602
|
auth: "admin"
|
|
19325
20603
|
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
@@ -19378,6 +20656,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
19378
20656
|
kind: "mutation",
|
|
19379
20657
|
auth: "admin"
|
|
19380
20658
|
});
|
|
20659
|
+
/**
|
|
20660
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
20661
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
20662
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
20663
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
20664
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
20665
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
20666
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
20667
|
+
* (`interfaces/recording-config.ts`).
|
|
20668
|
+
*/
|
|
19381
20669
|
var RecordingStatusSchema = object({
|
|
19382
20670
|
deviceId: number(),
|
|
19383
20671
|
enabled: boolean(),
|
|
@@ -21014,6 +22302,12 @@ Object.freeze({
|
|
|
21014
22302
|
addonId: null,
|
|
21015
22303
|
access: "view"
|
|
21016
22304
|
},
|
|
22305
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
22306
|
+
capName: "device-manager",
|
|
22307
|
+
capScope: "system",
|
|
22308
|
+
addonId: null,
|
|
22309
|
+
access: "view"
|
|
22310
|
+
},
|
|
21017
22311
|
"deviceManager.getSettingsSchema": {
|
|
21018
22312
|
capName: "device-manager",
|
|
21019
22313
|
capScope: "system",
|
|
@@ -21164,6 +22458,12 @@ Object.freeze({
|
|
|
21164
22458
|
addonId: null,
|
|
21165
22459
|
access: "create"
|
|
21166
22460
|
},
|
|
22461
|
+
"deviceManager.setDisplay": {
|
|
22462
|
+
capName: "device-manager",
|
|
22463
|
+
capScope: "system",
|
|
22464
|
+
addonId: null,
|
|
22465
|
+
access: "create"
|
|
22466
|
+
},
|
|
21167
22467
|
"deviceManager.setIntegrationId": {
|
|
21168
22468
|
capName: "device-manager",
|
|
21169
22469
|
capScope: "system",
|
|
@@ -21206,6 +22506,12 @@ Object.freeze({
|
|
|
21206
22506
|
addonId: null,
|
|
21207
22507
|
access: "create"
|
|
21208
22508
|
},
|
|
22509
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
22510
|
+
capName: "device-manager",
|
|
22511
|
+
capScope: "system",
|
|
22512
|
+
addonId: null,
|
|
22513
|
+
access: "create"
|
|
22514
|
+
},
|
|
21209
22515
|
"deviceManager.setStreamProfileMap": {
|
|
21210
22516
|
capName: "device-manager",
|
|
21211
22517
|
capScope: "system",
|
|
@@ -22184,13 +23490,49 @@ Object.freeze({
|
|
|
22184
23490
|
addonId: null,
|
|
22185
23491
|
access: "create"
|
|
22186
23492
|
},
|
|
23493
|
+
"notificationOutput.deleteTarget": {
|
|
23494
|
+
capName: "notification-output",
|
|
23495
|
+
capScope: "system",
|
|
23496
|
+
addonId: null,
|
|
23497
|
+
access: "delete"
|
|
23498
|
+
},
|
|
23499
|
+
"notificationOutput.discoverTargets": {
|
|
23500
|
+
capName: "notification-output",
|
|
23501
|
+
capScope: "system",
|
|
23502
|
+
addonId: null,
|
|
23503
|
+
access: "view"
|
|
23504
|
+
},
|
|
23505
|
+
"notificationOutput.listTargetKinds": {
|
|
23506
|
+
capName: "notification-output",
|
|
23507
|
+
capScope: "system",
|
|
23508
|
+
addonId: null,
|
|
23509
|
+
access: "view"
|
|
23510
|
+
},
|
|
23511
|
+
"notificationOutput.listTargets": {
|
|
23512
|
+
capName: "notification-output",
|
|
23513
|
+
capScope: "system",
|
|
23514
|
+
addonId: null,
|
|
23515
|
+
access: "view"
|
|
23516
|
+
},
|
|
22187
23517
|
"notificationOutput.send": {
|
|
22188
23518
|
capName: "notification-output",
|
|
22189
23519
|
capScope: "system",
|
|
22190
23520
|
addonId: null,
|
|
22191
23521
|
access: "create"
|
|
22192
23522
|
},
|
|
22193
|
-
"notificationOutput.
|
|
23523
|
+
"notificationOutput.setTargetEnabled": {
|
|
23524
|
+
capName: "notification-output",
|
|
23525
|
+
capScope: "system",
|
|
23526
|
+
addonId: null,
|
|
23527
|
+
access: "create"
|
|
23528
|
+
},
|
|
23529
|
+
"notificationOutput.testTarget": {
|
|
23530
|
+
capName: "notification-output",
|
|
23531
|
+
capScope: "system",
|
|
23532
|
+
addonId: null,
|
|
23533
|
+
access: "create"
|
|
23534
|
+
},
|
|
23535
|
+
"notificationOutput.upsertTarget": {
|
|
22194
23536
|
capName: "notification-output",
|
|
22195
23537
|
capScope: "system",
|
|
22196
23538
|
addonId: null,
|
|
@@ -22220,6 +23562,66 @@ Object.freeze({
|
|
|
22220
23562
|
addonId: null,
|
|
22221
23563
|
access: "create"
|
|
22222
23564
|
},
|
|
23565
|
+
"petFeeder.callPet": {
|
|
23566
|
+
capName: "pet-feeder",
|
|
23567
|
+
capScope: "device",
|
|
23568
|
+
addonId: null,
|
|
23569
|
+
access: "create"
|
|
23570
|
+
},
|
|
23571
|
+
"petFeeder.cancelFeed": {
|
|
23572
|
+
capName: "pet-feeder",
|
|
23573
|
+
capScope: "device",
|
|
23574
|
+
addonId: null,
|
|
23575
|
+
access: "create"
|
|
23576
|
+
},
|
|
23577
|
+
"petFeeder.feed": {
|
|
23578
|
+
capName: "pet-feeder",
|
|
23579
|
+
capScope: "device",
|
|
23580
|
+
addonId: null,
|
|
23581
|
+
access: "create"
|
|
23582
|
+
},
|
|
23583
|
+
"petFeeder.markFoodReplenished": {
|
|
23584
|
+
capName: "pet-feeder",
|
|
23585
|
+
capScope: "device",
|
|
23586
|
+
addonId: null,
|
|
23587
|
+
access: "create"
|
|
23588
|
+
},
|
|
23589
|
+
"petFeeder.playSound": {
|
|
23590
|
+
capName: "pet-feeder",
|
|
23591
|
+
capScope: "device",
|
|
23592
|
+
addonId: null,
|
|
23593
|
+
access: "create"
|
|
23594
|
+
},
|
|
23595
|
+
"petFeeder.resetDesiccant": {
|
|
23596
|
+
capName: "pet-feeder",
|
|
23597
|
+
capScope: "device",
|
|
23598
|
+
addonId: null,
|
|
23599
|
+
access: "delete"
|
|
23600
|
+
},
|
|
23601
|
+
"petFeeder.setChildLock": {
|
|
23602
|
+
capName: "pet-feeder",
|
|
23603
|
+
capScope: "device",
|
|
23604
|
+
addonId: null,
|
|
23605
|
+
access: "create"
|
|
23606
|
+
},
|
|
23607
|
+
"petFeeder.setFeedSound": {
|
|
23608
|
+
capName: "pet-feeder",
|
|
23609
|
+
capScope: "device",
|
|
23610
|
+
addonId: null,
|
|
23611
|
+
access: "create"
|
|
23612
|
+
},
|
|
23613
|
+
"petFeeder.setIndicatorLight": {
|
|
23614
|
+
capName: "pet-feeder",
|
|
23615
|
+
capScope: "device",
|
|
23616
|
+
addonId: null,
|
|
23617
|
+
access: "create"
|
|
23618
|
+
},
|
|
23619
|
+
"petFeeder.setVolume": {
|
|
23620
|
+
capName: "pet-feeder",
|
|
23621
|
+
capScope: "device",
|
|
23622
|
+
addonId: null,
|
|
23623
|
+
access: "create"
|
|
23624
|
+
},
|
|
22223
23625
|
"pipelineAnalytics.clearTracks": {
|
|
22224
23626
|
capName: "pipeline-analytics",
|
|
22225
23627
|
capScope: "device",
|
|
@@ -49662,7 +51064,7 @@ var HomematicProviderAddon = class extends BaseDeviceProvider {
|
|
|
49662
51064
|
}
|
|
49663
51065
|
async onInitialize() {
|
|
49664
51066
|
const regs = await super.onInitialize();
|
|
49665
|
-
const migrated = migrateLegacyConfig(await this.
|
|
51067
|
+
const migrated = migrateLegacyConfig(await this.resolveGlobalStore());
|
|
49666
51068
|
if (this.brokersDiffer(migrated.brokers, this.config.brokers)) await this.updateGlobalSettings({ brokers: migrated.brokers });
|
|
49667
51069
|
this.registry = new HmBrokerRegistry(this.ctx.logger);
|
|
49668
51070
|
this.registry.setOnBrokerConnected((brokerId) => {
|