@camstack/addon-provider-homematic 1.1.12 → 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 +1483 -63
- package/dist/addon.mjs +1483 -63
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -4651,7 +4651,7 @@ function preprocess(fn, schema) {
|
|
|
4651
4651
|
});
|
|
4652
4652
|
}
|
|
4653
4653
|
//#endregion
|
|
4654
|
-
//#region ../types/dist/sleep-
|
|
4654
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4655
4655
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4656
4656
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4657
4657
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5464,6 +5464,100 @@ function createDurableState(deps) {
|
|
|
5464
5464
|
};
|
|
5465
5465
|
}
|
|
5466
5466
|
/**
|
|
5467
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5468
|
+
*
|
|
5469
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5470
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5471
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5472
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5473
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5474
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5475
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5476
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5477
|
+
*
|
|
5478
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5479
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5480
|
+
* schema and routes reads/writes through these helpers.
|
|
5481
|
+
*
|
|
5482
|
+
* ## No bare-key fallback — deliberate
|
|
5483
|
+
*
|
|
5484
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5485
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5486
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5487
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5488
|
+
* selection can never leak onto another. (This generalizes the
|
|
5489
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5490
|
+
* arbitrary set of per-node field keys.)
|
|
5491
|
+
*
|
|
5492
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5493
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5494
|
+
*/
|
|
5495
|
+
/**
|
|
5496
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5497
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5498
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5499
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5500
|
+
*/
|
|
5501
|
+
function normalizeNodeId(raw) {
|
|
5502
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5503
|
+
const slashIdx = raw.indexOf("/");
|
|
5504
|
+
if (slashIdx < 0) return raw;
|
|
5505
|
+
const bare = raw.slice(0, slashIdx);
|
|
5506
|
+
return bare === "" ? "hub" : bare;
|
|
5507
|
+
}
|
|
5508
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5509
|
+
function nodeScopedKey(base, nodeId) {
|
|
5510
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5511
|
+
}
|
|
5512
|
+
/**
|
|
5513
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5514
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5515
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5516
|
+
* schema `default` win on `undefined`.
|
|
5517
|
+
*/
|
|
5518
|
+
function readNodeValue(store, base, nodeId) {
|
|
5519
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5520
|
+
}
|
|
5521
|
+
/**
|
|
5522
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5523
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5524
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5525
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5526
|
+
* patch is not mutated.
|
|
5527
|
+
*/
|
|
5528
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5529
|
+
const out = {};
|
|
5530
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5531
|
+
return out;
|
|
5532
|
+
}
|
|
5533
|
+
/**
|
|
5534
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5535
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5536
|
+
* values:
|
|
5537
|
+
*
|
|
5538
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5539
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5540
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5541
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5542
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5543
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5544
|
+
*
|
|
5545
|
+
* Returns a new object — the input store is not mutated.
|
|
5546
|
+
*/
|
|
5547
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5548
|
+
const out = {};
|
|
5549
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5550
|
+
if (key.includes("@")) continue;
|
|
5551
|
+
if (perNodeKeys.has(key)) continue;
|
|
5552
|
+
out[key] = value;
|
|
5553
|
+
}
|
|
5554
|
+
for (const base of perNodeKeys) {
|
|
5555
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5556
|
+
if (value !== void 0) out[base] = value;
|
|
5557
|
+
}
|
|
5558
|
+
return out;
|
|
5559
|
+
}
|
|
5560
|
+
/**
|
|
5467
5561
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5468
5562
|
*
|
|
5469
5563
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5631,23 +5725,63 @@ var BaseAddon = class {
|
|
|
5631
5725
|
deviceSettingsSchema() {
|
|
5632
5726
|
return null;
|
|
5633
5727
|
}
|
|
5634
|
-
async getGlobalSettings(overlay, cap,
|
|
5728
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5635
5729
|
const schema = this.globalSettingsSchema(cap);
|
|
5636
5730
|
if (!schema) return { sections: [] };
|
|
5637
|
-
const
|
|
5731
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5638
5732
|
return hydrateSchema(schema, overlay ? {
|
|
5639
|
-
...
|
|
5733
|
+
...projected,
|
|
5640
5734
|
...overlay
|
|
5641
|
-
} :
|
|
5735
|
+
} : projected);
|
|
5642
5736
|
}
|
|
5643
|
-
|
|
5644
|
-
|
|
5737
|
+
/**
|
|
5738
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5739
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5740
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5741
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5742
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5743
|
+
*
|
|
5744
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5745
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5746
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5747
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5748
|
+
*/
|
|
5749
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5750
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5751
|
+
const keys = this.perNodeKeys(cap);
|
|
5752
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5753
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5754
|
+
}
|
|
5755
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5756
|
+
const keys = this.perNodeKeys();
|
|
5757
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5758
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5759
|
+
const barePatch = patch;
|
|
5760
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5761
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5762
|
+
if (target !== localNode) return;
|
|
5645
5763
|
await this.resolveConfig();
|
|
5646
5764
|
await this.onConfigChanged();
|
|
5647
5765
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5648
5766
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5649
5767
|
}
|
|
5650
5768
|
/**
|
|
5769
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5770
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5771
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5772
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5773
|
+
*/
|
|
5774
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5775
|
+
perNodeKeys(cap) {
|
|
5776
|
+
const cacheKey = cap ?? "";
|
|
5777
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5778
|
+
if (cached) return cached;
|
|
5779
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5780
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5781
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5782
|
+
return keys;
|
|
5783
|
+
}
|
|
5784
|
+
/**
|
|
5651
5785
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5652
5786
|
* schedule an addon restart for the next tick. Deferred via
|
|
5653
5787
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5800,12 +5934,19 @@ var BaseAddon = class {
|
|
|
5800
5934
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5801
5935
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5802
5936
|
* (e.g. from older versions) without polluting the typed config.
|
|
5937
|
+
*
|
|
5938
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5939
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5940
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5941
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5803
5942
|
*/
|
|
5804
5943
|
async resolveConfig() {
|
|
5805
5944
|
const stored = await this.readAddonStoreWithRetry();
|
|
5945
|
+
const perNode = this.perNodeKeys();
|
|
5946
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5806
5947
|
const resolved = { ...this.defaults };
|
|
5807
5948
|
for (const key of Object.keys(this.defaults)) {
|
|
5808
|
-
const storedValue = stored[key];
|
|
5949
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5809
5950
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5810
5951
|
const defaultType = typeof this.defaults[key];
|
|
5811
5952
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5889,6 +6030,27 @@ var BaseAddon = class {
|
|
|
5889
6030
|
}
|
|
5890
6031
|
};
|
|
5891
6032
|
/**
|
|
6033
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6034
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6035
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6036
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6037
|
+
*/
|
|
6038
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6039
|
+
const collected = [];
|
|
6040
|
+
for (const field of fields) {
|
|
6041
|
+
if (field.type === "group") {
|
|
6042
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6043
|
+
continue;
|
|
6044
|
+
}
|
|
6045
|
+
if (field.type === "sub-tabs") {
|
|
6046
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6047
|
+
continue;
|
|
6048
|
+
}
|
|
6049
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6050
|
+
}
|
|
6051
|
+
return collected;
|
|
6052
|
+
}
|
|
6053
|
+
/**
|
|
5892
6054
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5893
6055
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5894
6056
|
* envelopes pass through; void stays void.
|
|
@@ -5913,6 +6075,7 @@ var CamStreamKindSchema = _enum([
|
|
|
5913
6075
|
"pull-rtsp",
|
|
5914
6076
|
"pull-rtmp",
|
|
5915
6077
|
"pull-http",
|
|
6078
|
+
"pull-flv",
|
|
5916
6079
|
"pull-rfc4571",
|
|
5917
6080
|
"push-annexb",
|
|
5918
6081
|
"derived"
|
|
@@ -6295,6 +6458,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6295
6458
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6296
6459
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6297
6460
|
DeviceType["Image"] = "image";
|
|
6461
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6462
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6463
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6464
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6465
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6466
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6467
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6298
6468
|
return DeviceType;
|
|
6299
6469
|
}({});
|
|
6300
6470
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7072,7 +7242,21 @@ var StorageLocationDeclarationSchema = object({
|
|
|
7072
7242
|
* slots (e.g. `recordingsLow` → `recordings`) so operators only need to
|
|
7073
7243
|
* configure the primary location.
|
|
7074
7244
|
*/
|
|
7075
|
-
defaultsTo: string().optional()
|
|
7245
|
+
defaultsTo: string().optional(),
|
|
7246
|
+
/**
|
|
7247
|
+
* Which node root the seeded `<id>:default` instance is placed under on a
|
|
7248
|
+
* FRESH install:
|
|
7249
|
+
* - `'data'` (default) — the node's data dir (`CAMSTACK_DATA` / boot dir),
|
|
7250
|
+
* the appData volume. Right for small/durable data (backups, logs, models).
|
|
7251
|
+
* - `'media'` — the dedicated media volume (`CAMSTACK_MEDIA_ROOT`) when that
|
|
7252
|
+
* env is set, else falls back to the data root. Right for bulky, hot media
|
|
7253
|
+
* (recordings, event media) that should stay off the appData disk.
|
|
7254
|
+
*
|
|
7255
|
+
* Only affects the seeded default's `basePath`; operators can repoint any
|
|
7256
|
+
* location afterwards, and a `defaultsTo` slot inherits its parent's root
|
|
7257
|
+
* regardless of this field. Absent (the common case) is treated as `'data'`.
|
|
7258
|
+
*/
|
|
7259
|
+
defaultRoot: _enum(["data", "media"]).optional()
|
|
7076
7260
|
});
|
|
7077
7261
|
var DecoderStatsSchema = object({
|
|
7078
7262
|
inputFps: number(),
|
|
@@ -7445,6 +7629,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7445
7629
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7446
7630
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7447
7631
|
/**
|
|
7632
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7633
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7634
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7635
|
+
*/
|
|
7636
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7637
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7638
|
+
var ExpressionParseError = class extends Error {
|
|
7639
|
+
position;
|
|
7640
|
+
constructor(message, position) {
|
|
7641
|
+
super(message);
|
|
7642
|
+
this.name = "ExpressionParseError";
|
|
7643
|
+
this.position = position;
|
|
7644
|
+
}
|
|
7645
|
+
};
|
|
7646
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7647
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7648
|
+
var ExpressionEvalError = class extends Error {
|
|
7649
|
+
constructor(message) {
|
|
7650
|
+
super(message);
|
|
7651
|
+
this.name = "ExpressionEvalError";
|
|
7652
|
+
}
|
|
7653
|
+
};
|
|
7654
|
+
/**
|
|
7655
|
+
* Resource-bound constants for the safe expression engine.
|
|
7656
|
+
*
|
|
7657
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7658
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7659
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7660
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7661
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7662
|
+
*/
|
|
7663
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7664
|
+
* rejected without allocation. */
|
|
7665
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7666
|
+
/** A legal binding / identifier name. */
|
|
7667
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7668
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7669
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7670
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7671
|
+
"now",
|
|
7672
|
+
"true",
|
|
7673
|
+
"false",
|
|
7674
|
+
"null"
|
|
7675
|
+
]);
|
|
7676
|
+
/**
|
|
7677
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7678
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7679
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7680
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7681
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7682
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7683
|
+
* template literals are lexically impossible.
|
|
7684
|
+
*/
|
|
7685
|
+
var KEYWORDS = new Set([
|
|
7686
|
+
"true",
|
|
7687
|
+
"false",
|
|
7688
|
+
"null"
|
|
7689
|
+
]);
|
|
7690
|
+
function isDigit(ch) {
|
|
7691
|
+
return ch >= "0" && ch <= "9";
|
|
7692
|
+
}
|
|
7693
|
+
function isIdentStart(ch) {
|
|
7694
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7695
|
+
}
|
|
7696
|
+
function isIdentPart(ch) {
|
|
7697
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7698
|
+
}
|
|
7699
|
+
function isWhitespace(ch) {
|
|
7700
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7701
|
+
}
|
|
7702
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7703
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7704
|
+
* string. */
|
|
7705
|
+
function tokenize(source) {
|
|
7706
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7707
|
+
const tokens = [];
|
|
7708
|
+
let i = 0;
|
|
7709
|
+
const n = source.length;
|
|
7710
|
+
while (i < n) {
|
|
7711
|
+
const ch = source[i];
|
|
7712
|
+
if (isWhitespace(ch)) {
|
|
7713
|
+
i += 1;
|
|
7714
|
+
continue;
|
|
7715
|
+
}
|
|
7716
|
+
if (isDigit(ch)) {
|
|
7717
|
+
const start = i;
|
|
7718
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7719
|
+
if (i < n && source[i] === ".") {
|
|
7720
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7721
|
+
i += 1;
|
|
7722
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7723
|
+
}
|
|
7724
|
+
const text = source.slice(start, i);
|
|
7725
|
+
const value = Number(text);
|
|
7726
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7727
|
+
tokens.push({
|
|
7728
|
+
type: "number",
|
|
7729
|
+
value,
|
|
7730
|
+
pos: start
|
|
7731
|
+
});
|
|
7732
|
+
continue;
|
|
7733
|
+
}
|
|
7734
|
+
if (ch === "'" || ch === "\"") {
|
|
7735
|
+
const quote = ch;
|
|
7736
|
+
const start = i;
|
|
7737
|
+
i += 1;
|
|
7738
|
+
let out = "";
|
|
7739
|
+
let closed = false;
|
|
7740
|
+
while (i < n) {
|
|
7741
|
+
const c = source[i];
|
|
7742
|
+
if (c === "\\") {
|
|
7743
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7744
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7745
|
+
out += next;
|
|
7746
|
+
i += 2;
|
|
7747
|
+
continue;
|
|
7748
|
+
}
|
|
7749
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7750
|
+
}
|
|
7751
|
+
if (c === quote) {
|
|
7752
|
+
closed = true;
|
|
7753
|
+
i += 1;
|
|
7754
|
+
break;
|
|
7755
|
+
}
|
|
7756
|
+
out += c;
|
|
7757
|
+
i += 1;
|
|
7758
|
+
}
|
|
7759
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7760
|
+
tokens.push({
|
|
7761
|
+
type: "string",
|
|
7762
|
+
value: out,
|
|
7763
|
+
pos: start
|
|
7764
|
+
});
|
|
7765
|
+
continue;
|
|
7766
|
+
}
|
|
7767
|
+
if (isIdentStart(ch)) {
|
|
7768
|
+
const start = i;
|
|
7769
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7770
|
+
const text = source.slice(start, i);
|
|
7771
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7772
|
+
type: "keyword",
|
|
7773
|
+
keyword: keywordOf(text),
|
|
7774
|
+
pos: start
|
|
7775
|
+
});
|
|
7776
|
+
else tokens.push({
|
|
7777
|
+
type: "identifier",
|
|
7778
|
+
name: text,
|
|
7779
|
+
pos: start
|
|
7780
|
+
});
|
|
7781
|
+
continue;
|
|
7782
|
+
}
|
|
7783
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7784
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7785
|
+
tokens.push({
|
|
7786
|
+
type: "punct",
|
|
7787
|
+
punct: two,
|
|
7788
|
+
pos: i
|
|
7789
|
+
});
|
|
7790
|
+
i += 2;
|
|
7791
|
+
continue;
|
|
7792
|
+
}
|
|
7793
|
+
if (isSinglePunct(ch)) {
|
|
7794
|
+
tokens.push({
|
|
7795
|
+
type: "punct",
|
|
7796
|
+
punct: ch,
|
|
7797
|
+
pos: i
|
|
7798
|
+
});
|
|
7799
|
+
i += 1;
|
|
7800
|
+
continue;
|
|
7801
|
+
}
|
|
7802
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7803
|
+
}
|
|
7804
|
+
tokens.push({
|
|
7805
|
+
type: "eof",
|
|
7806
|
+
pos: n
|
|
7807
|
+
});
|
|
7808
|
+
return tokens;
|
|
7809
|
+
}
|
|
7810
|
+
function keywordOf(text) {
|
|
7811
|
+
if (text === "true") return "true";
|
|
7812
|
+
if (text === "false") return "false";
|
|
7813
|
+
return "null";
|
|
7814
|
+
}
|
|
7815
|
+
function isSinglePunct(ch) {
|
|
7816
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7817
|
+
}
|
|
7818
|
+
/**
|
|
7819
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7820
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7821
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7822
|
+
* own-property check against it.
|
|
7823
|
+
*
|
|
7824
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7825
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7826
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7827
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7828
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7829
|
+
*
|
|
7830
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7831
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7832
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7833
|
+
* closed rather than emitting a garbage value.
|
|
7834
|
+
*/
|
|
7835
|
+
function asFiniteNumber(value, name, index) {
|
|
7836
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7837
|
+
return value;
|
|
7838
|
+
}
|
|
7839
|
+
function asString$1(value, name, index) {
|
|
7840
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7841
|
+
return value;
|
|
7842
|
+
}
|
|
7843
|
+
function finiteResult(value, name) {
|
|
7844
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7845
|
+
return value;
|
|
7846
|
+
}
|
|
7847
|
+
function allFiniteNumbers(args, name) {
|
|
7848
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7849
|
+
}
|
|
7850
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7851
|
+
var table = {
|
|
7852
|
+
min: {
|
|
7853
|
+
minArgs: 1,
|
|
7854
|
+
maxArgs: INF,
|
|
7855
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7856
|
+
},
|
|
7857
|
+
max: {
|
|
7858
|
+
minArgs: 1,
|
|
7859
|
+
maxArgs: INF,
|
|
7860
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7861
|
+
},
|
|
7862
|
+
abs: {
|
|
7863
|
+
minArgs: 1,
|
|
7864
|
+
maxArgs: 1,
|
|
7865
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7866
|
+
},
|
|
7867
|
+
floor: {
|
|
7868
|
+
minArgs: 1,
|
|
7869
|
+
maxArgs: 1,
|
|
7870
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7871
|
+
},
|
|
7872
|
+
ceil: {
|
|
7873
|
+
minArgs: 1,
|
|
7874
|
+
maxArgs: 1,
|
|
7875
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7876
|
+
},
|
|
7877
|
+
sqrt: {
|
|
7878
|
+
minArgs: 1,
|
|
7879
|
+
maxArgs: 1,
|
|
7880
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7881
|
+
},
|
|
7882
|
+
round: {
|
|
7883
|
+
minArgs: 1,
|
|
7884
|
+
maxArgs: 2,
|
|
7885
|
+
apply: (args) => {
|
|
7886
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7887
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7888
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7889
|
+
const factor = 10 ** digits;
|
|
7890
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7891
|
+
}
|
|
7892
|
+
},
|
|
7893
|
+
pow: {
|
|
7894
|
+
minArgs: 2,
|
|
7895
|
+
maxArgs: 2,
|
|
7896
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7897
|
+
},
|
|
7898
|
+
clamp: {
|
|
7899
|
+
minArgs: 3,
|
|
7900
|
+
maxArgs: 3,
|
|
7901
|
+
apply: (args) => {
|
|
7902
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7903
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7904
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7905
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7906
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7907
|
+
}
|
|
7908
|
+
},
|
|
7909
|
+
avg: {
|
|
7910
|
+
minArgs: 1,
|
|
7911
|
+
maxArgs: INF,
|
|
7912
|
+
apply: (args) => {
|
|
7913
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7914
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7915
|
+
}
|
|
7916
|
+
},
|
|
7917
|
+
sum: {
|
|
7918
|
+
minArgs: 1,
|
|
7919
|
+
maxArgs: INF,
|
|
7920
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7921
|
+
},
|
|
7922
|
+
coalesce: {
|
|
7923
|
+
minArgs: 1,
|
|
7924
|
+
maxArgs: INF,
|
|
7925
|
+
apply: (args) => {
|
|
7926
|
+
for (const a of args) if (a !== null) return a;
|
|
7927
|
+
return null;
|
|
7928
|
+
}
|
|
7929
|
+
},
|
|
7930
|
+
age: {
|
|
7931
|
+
minArgs: 2,
|
|
7932
|
+
maxArgs: 2,
|
|
7933
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7934
|
+
},
|
|
7935
|
+
convert: {
|
|
7936
|
+
minArgs: 3,
|
|
7937
|
+
maxArgs: 3,
|
|
7938
|
+
apply: (args, hooks) => {
|
|
7939
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7940
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7941
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7942
|
+
if (hooks.convert) {
|
|
7943
|
+
const out = hooks.convert(x, from, to);
|
|
7944
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7945
|
+
return finiteResult(out, "convert");
|
|
7946
|
+
}
|
|
7947
|
+
if (from === to) return x;
|
|
7948
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7949
|
+
}
|
|
7950
|
+
}
|
|
7951
|
+
};
|
|
7952
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7953
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7954
|
+
* callees at parse time (immediate author feedback). */
|
|
7955
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7956
|
+
/**
|
|
7957
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7958
|
+
*
|
|
7959
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7960
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7961
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7962
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7963
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7964
|
+
* that references a since-removed builtin degrades at read.
|
|
7965
|
+
*
|
|
7966
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7967
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7968
|
+
*/
|
|
7969
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7970
|
+
var BINARY_PRECEDENCE = {
|
|
7971
|
+
"||": 1,
|
|
7972
|
+
"&&": 2,
|
|
7973
|
+
"==": 3,
|
|
7974
|
+
"!=": 3,
|
|
7975
|
+
"<": 4,
|
|
7976
|
+
"<=": 4,
|
|
7977
|
+
">": 4,
|
|
7978
|
+
">=": 4,
|
|
7979
|
+
"+": 5,
|
|
7980
|
+
"-": 5,
|
|
7981
|
+
"*": 6,
|
|
7982
|
+
"/": 6,
|
|
7983
|
+
"%": 6
|
|
7984
|
+
};
|
|
7985
|
+
function isLogicalOp(op) {
|
|
7986
|
+
return op === "&&" || op === "||";
|
|
7987
|
+
}
|
|
7988
|
+
function isBinaryOp(op) {
|
|
7989
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7990
|
+
}
|
|
7991
|
+
var Parser = class {
|
|
7992
|
+
tokens;
|
|
7993
|
+
pos = 0;
|
|
7994
|
+
nodeCount = 0;
|
|
7995
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7996
|
+
callees = /* @__PURE__ */ new Set();
|
|
7997
|
+
constructor(tokens) {
|
|
7998
|
+
this.tokens = tokens;
|
|
7999
|
+
}
|
|
8000
|
+
parse() {
|
|
8001
|
+
const ast = this.parseTernary();
|
|
8002
|
+
const tok = this.peek();
|
|
8003
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
8004
|
+
return {
|
|
8005
|
+
ast,
|
|
8006
|
+
identifiers: this.identifiers,
|
|
8007
|
+
callees: this.callees,
|
|
8008
|
+
nodeCount: this.nodeCount
|
|
8009
|
+
};
|
|
8010
|
+
}
|
|
8011
|
+
peek() {
|
|
8012
|
+
return this.tokens[this.pos];
|
|
8013
|
+
}
|
|
8014
|
+
next() {
|
|
8015
|
+
return this.tokens[this.pos++];
|
|
8016
|
+
}
|
|
8017
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8018
|
+
expectPunct(punct) {
|
|
8019
|
+
const tok = this.peek();
|
|
8020
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8021
|
+
this.pos += 1;
|
|
8022
|
+
}
|
|
8023
|
+
matchPunct(punct) {
|
|
8024
|
+
const tok = this.peek();
|
|
8025
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8026
|
+
this.pos += 1;
|
|
8027
|
+
return true;
|
|
8028
|
+
}
|
|
8029
|
+
return false;
|
|
8030
|
+
}
|
|
8031
|
+
countNode() {
|
|
8032
|
+
this.nodeCount += 1;
|
|
8033
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8034
|
+
}
|
|
8035
|
+
parseTernary() {
|
|
8036
|
+
const test = this.parseBinary(1);
|
|
8037
|
+
if (this.matchPunct("?")) {
|
|
8038
|
+
const consequent = this.parseTernary();
|
|
8039
|
+
this.expectPunct(":");
|
|
8040
|
+
const alternate = this.parseTernary();
|
|
8041
|
+
this.countNode();
|
|
8042
|
+
return {
|
|
8043
|
+
kind: "conditional",
|
|
8044
|
+
test,
|
|
8045
|
+
consequent,
|
|
8046
|
+
alternate
|
|
8047
|
+
};
|
|
8048
|
+
}
|
|
8049
|
+
return test;
|
|
8050
|
+
}
|
|
8051
|
+
parseBinary(minPrec) {
|
|
8052
|
+
let left = this.parseUnary();
|
|
8053
|
+
for (;;) {
|
|
8054
|
+
const tok = this.peek();
|
|
8055
|
+
if (tok.type !== "punct") break;
|
|
8056
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8057
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8058
|
+
const op = tok.punct;
|
|
8059
|
+
this.pos += 1;
|
|
8060
|
+
const right = this.parseBinary(prec + 1);
|
|
8061
|
+
this.countNode();
|
|
8062
|
+
if (isLogicalOp(op)) left = {
|
|
8063
|
+
kind: "logical",
|
|
8064
|
+
op,
|
|
8065
|
+
left,
|
|
8066
|
+
right
|
|
8067
|
+
};
|
|
8068
|
+
else if (isBinaryOp(op)) left = {
|
|
8069
|
+
kind: "binary",
|
|
8070
|
+
op,
|
|
8071
|
+
left,
|
|
8072
|
+
right
|
|
8073
|
+
};
|
|
8074
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8075
|
+
}
|
|
8076
|
+
return left;
|
|
8077
|
+
}
|
|
8078
|
+
parseUnary() {
|
|
8079
|
+
const tok = this.peek();
|
|
8080
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8081
|
+
const op = tok.punct;
|
|
8082
|
+
this.pos += 1;
|
|
8083
|
+
const operand = this.parseUnary();
|
|
8084
|
+
this.countNode();
|
|
8085
|
+
return {
|
|
8086
|
+
kind: "unary",
|
|
8087
|
+
op,
|
|
8088
|
+
operand
|
|
8089
|
+
};
|
|
8090
|
+
}
|
|
8091
|
+
return this.parsePrimary();
|
|
8092
|
+
}
|
|
8093
|
+
parsePrimary() {
|
|
8094
|
+
const tok = this.next();
|
|
8095
|
+
switch (tok.type) {
|
|
8096
|
+
case "number":
|
|
8097
|
+
this.countNode();
|
|
8098
|
+
return {
|
|
8099
|
+
kind: "literal",
|
|
8100
|
+
value: tok.value
|
|
8101
|
+
};
|
|
8102
|
+
case "string":
|
|
8103
|
+
this.countNode();
|
|
8104
|
+
return {
|
|
8105
|
+
kind: "literal",
|
|
8106
|
+
value: tok.value
|
|
8107
|
+
};
|
|
8108
|
+
case "keyword":
|
|
8109
|
+
this.countNode();
|
|
8110
|
+
return {
|
|
8111
|
+
kind: "literal",
|
|
8112
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8113
|
+
};
|
|
8114
|
+
case "identifier": {
|
|
8115
|
+
const nextTok = this.peek();
|
|
8116
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8117
|
+
this.identifiers.add(tok.name);
|
|
8118
|
+
this.countNode();
|
|
8119
|
+
return {
|
|
8120
|
+
kind: "identifier",
|
|
8121
|
+
name: tok.name
|
|
8122
|
+
};
|
|
8123
|
+
}
|
|
8124
|
+
case "punct":
|
|
8125
|
+
if (tok.punct === "(") {
|
|
8126
|
+
const inner = this.parseTernary();
|
|
8127
|
+
this.expectPunct(")");
|
|
8128
|
+
return inner;
|
|
8129
|
+
}
|
|
8130
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8131
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8132
|
+
}
|
|
8133
|
+
}
|
|
8134
|
+
parseCall(callee, pos) {
|
|
8135
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8136
|
+
this.expectPunct("(");
|
|
8137
|
+
const args = [];
|
|
8138
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8139
|
+
args.push(this.parseTernary());
|
|
8140
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8141
|
+
if (this.matchPunct(",")) continue;
|
|
8142
|
+
this.expectPunct(")");
|
|
8143
|
+
break;
|
|
8144
|
+
}
|
|
8145
|
+
this.callees.add(callee);
|
|
8146
|
+
this.countNode();
|
|
8147
|
+
return {
|
|
8148
|
+
kind: "call",
|
|
8149
|
+
callee,
|
|
8150
|
+
args
|
|
8151
|
+
};
|
|
8152
|
+
}
|
|
8153
|
+
};
|
|
8154
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8155
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8156
|
+
function parseExpression(source) {
|
|
8157
|
+
return new Parser(tokenize(source)).parse();
|
|
8158
|
+
}
|
|
8159
|
+
Object.freeze({});
|
|
8160
|
+
/**
|
|
8161
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8162
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8163
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8164
|
+
* one per read on a hot resolve path.
|
|
8165
|
+
*
|
|
8166
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8167
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8168
|
+
* callers is safe and maximises hit rate.
|
|
8169
|
+
*/
|
|
8170
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8171
|
+
function getCached(source) {
|
|
8172
|
+
const hit = cache.get(source);
|
|
8173
|
+
if (hit !== void 0) {
|
|
8174
|
+
cache.delete(source);
|
|
8175
|
+
cache.set(source, hit);
|
|
8176
|
+
return hit;
|
|
8177
|
+
}
|
|
8178
|
+
let result;
|
|
8179
|
+
try {
|
|
8180
|
+
result = {
|
|
8181
|
+
ok: true,
|
|
8182
|
+
parsed: parseExpression(source)
|
|
8183
|
+
};
|
|
8184
|
+
} catch (err) {
|
|
8185
|
+
result = {
|
|
8186
|
+
ok: false,
|
|
8187
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8188
|
+
};
|
|
8189
|
+
}
|
|
8190
|
+
cache.set(source, result);
|
|
8191
|
+
if (cache.size > 256) {
|
|
8192
|
+
const oldest = cache.keys().next().value;
|
|
8193
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8194
|
+
}
|
|
8195
|
+
return result;
|
|
8196
|
+
}
|
|
8197
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8198
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8199
|
+
function compileExpressionSafe(source) {
|
|
8200
|
+
return getCached(source);
|
|
8201
|
+
}
|
|
8202
|
+
/**
|
|
8203
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8204
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8205
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8206
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8207
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8208
|
+
*/
|
|
8209
|
+
function validateExpressionSource(src) {
|
|
8210
|
+
const names = Object.keys(src.bindings);
|
|
8211
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8212
|
+
for (const name of names) {
|
|
8213
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8214
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8215
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8216
|
+
}
|
|
8217
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8218
|
+
if (!compiled.ok) return compiled.error;
|
|
8219
|
+
const bound = new Set(names);
|
|
8220
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8221
|
+
if (id === "now") continue;
|
|
8222
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8223
|
+
}
|
|
8224
|
+
return null;
|
|
8225
|
+
}
|
|
8226
|
+
/**
|
|
7448
8227
|
* Accessory device helpers — shared across drivers.
|
|
7449
8228
|
*
|
|
7450
8229
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -8289,7 +9068,13 @@ onStatusChanged: { data: object({
|
|
|
8289
9068
|
}) } },
|
|
8290
9069
|
status: {
|
|
8291
9070
|
schema: BatteryStatusSchema,
|
|
8292
|
-
kind: "push"
|
|
9071
|
+
kind: "push",
|
|
9072
|
+
empty: {
|
|
9073
|
+
percentage: 0,
|
|
9074
|
+
charging: "none",
|
|
9075
|
+
sleeping: false,
|
|
9076
|
+
lastUpdated: 0
|
|
9077
|
+
}
|
|
8293
9078
|
},
|
|
8294
9079
|
/**
|
|
8295
9080
|
* Runtime-state slice — every provider that registers this cap
|
|
@@ -8428,6 +9213,10 @@ var RtspRestreamEntrySchema = object({
|
|
|
8428
9213
|
var BrokerRtspClientSchema = object({
|
|
8429
9214
|
sessionId: string(),
|
|
8430
9215
|
remoteAddr: string(),
|
|
9216
|
+
/** Client `User-Agent` (e.g. `recorder` for the recorder's RTSP pull), or
|
|
9217
|
+
* null/absent when the client sent none. Lets the UI label a consumer by
|
|
9218
|
+
* purpose. Optional so a client built against an older schema stays valid. */
|
|
9219
|
+
userAgent: string().nullish(),
|
|
8431
9220
|
playing: boolean(),
|
|
8432
9221
|
muted: boolean(),
|
|
8433
9222
|
connectedAt: number(),
|
|
@@ -9228,21 +10017,38 @@ var connectivityCapability = {
|
|
|
9228
10017
|
},
|
|
9229
10018
|
runtimeState: ConnectivityStatusSchema
|
|
9230
10019
|
};
|
|
10020
|
+
/**
|
|
10021
|
+
* Generic device-consumables capability — surfaces a device's
|
|
10022
|
+
* maintenance items (vacuum filters/brushes, replaceable cartridges,
|
|
10023
|
+
* descaling cycles, …) with their remaining life and an optional
|
|
10024
|
+
* "Replaced" reset action. Device-agnostic: any provider that knows its
|
|
10025
|
+
* device tracks consumables can register it; the cap declares no
|
|
10026
|
+
* vocabulary of its own — the provider names each item verbatim.
|
|
10027
|
+
*
|
|
10028
|
+
* Like `childLayout`, the cap is INERT until a provider sets items: no
|
|
10029
|
+
* provider populates it by guessing (no HA inference). The UI renders a
|
|
10030
|
+
* "No consumables reported" placeholder when `items` is empty.
|
|
10031
|
+
*/
|
|
10032
|
+
/** A single consumable item. Either a continuous `level` (remaining
|
|
10033
|
+
* life %) or a discrete `status` may be known — both may be null when a
|
|
10034
|
+
* provider only knows the item exists. `level` and `status` are not
|
|
10035
|
+
* mutually exclusive; a provider may report both. */
|
|
10036
|
+
var ConsumableItemSchema = object({
|
|
10037
|
+
/** Stable id, e.g. 'main-brush'. */
|
|
10038
|
+
key: string().min(1),
|
|
10039
|
+
/** Display name. */
|
|
10040
|
+
label: string().min(1),
|
|
10041
|
+
/** Remaining life % when known (0..100). */
|
|
10042
|
+
level: number().min(0).max(100).nullable(),
|
|
10043
|
+
/** Discrete state when known (binary mode). */
|
|
10044
|
+
status: _enum(["ok", "replace"]).nullable(),
|
|
10045
|
+
/** Ms epoch of the last replace, when known. */
|
|
10046
|
+
lastResetAt: number().nullable(),
|
|
10047
|
+
/** Whether `reset()` is meaningful for this item. */
|
|
10048
|
+
resettable: boolean()
|
|
10049
|
+
});
|
|
9231
10050
|
var ConsumablesStatusSchema = object({
|
|
9232
|
-
items: array(
|
|
9233
|
-
/** Stable id, e.g. 'main-brush'. */
|
|
9234
|
-
key: string().min(1),
|
|
9235
|
-
/** Display name. */
|
|
9236
|
-
label: string().min(1),
|
|
9237
|
-
/** Remaining life % when known (0..100). */
|
|
9238
|
-
level: number().min(0).max(100).nullable(),
|
|
9239
|
-
/** Discrete state when known (binary mode). */
|
|
9240
|
-
status: _enum(["ok", "replace"]).nullable(),
|
|
9241
|
-
/** Ms epoch of the last replace, when known. */
|
|
9242
|
-
lastResetAt: number().nullable(),
|
|
9243
|
-
/** Whether `reset()` is meaningful for this item. */
|
|
9244
|
-
resettable: boolean()
|
|
9245
|
-
})),
|
|
10051
|
+
items: array(ConsumableItemSchema),
|
|
9246
10052
|
lastChangedAt: number()
|
|
9247
10053
|
});
|
|
9248
10054
|
var consumablesCapability = {
|
|
@@ -9301,7 +10107,25 @@ reset: method(object({
|
|
|
9301
10107
|
}) },
|
|
9302
10108
|
status: {
|
|
9303
10109
|
schema: ConsumablesStatusSchema,
|
|
9304
|
-
kind: "push"
|
|
10110
|
+
kind: "push",
|
|
10111
|
+
empty: {
|
|
10112
|
+
items: [],
|
|
10113
|
+
lastChangedAt: 0
|
|
10114
|
+
},
|
|
10115
|
+
itemArray: {
|
|
10116
|
+
path: "items",
|
|
10117
|
+
keyField: "key",
|
|
10118
|
+
labelField: "label",
|
|
10119
|
+
itemSchema: ConsumableItemSchema,
|
|
10120
|
+
emptyItem: {
|
|
10121
|
+
key: "",
|
|
10122
|
+
label: "",
|
|
10123
|
+
level: null,
|
|
10124
|
+
status: null,
|
|
10125
|
+
lastResetAt: null,
|
|
10126
|
+
resettable: false
|
|
10127
|
+
}
|
|
10128
|
+
}
|
|
9305
10129
|
},
|
|
9306
10130
|
runtimeState: ConsumablesStatusSchema.extend({ lastFetchedAt: number() })
|
|
9307
10131
|
};
|
|
@@ -10543,7 +11367,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
10543
11367
|
});
|
|
10544
11368
|
method(object({
|
|
10545
11369
|
deviceId: number(),
|
|
10546
|
-
frame: FrameInputSchema
|
|
11370
|
+
frame: FrameInputSchema.optional(),
|
|
11371
|
+
frameHandle: FrameHandleSchema.optional()
|
|
10547
11372
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
10548
11373
|
deviceId: number(),
|
|
10549
11374
|
detected: boolean(),
|
|
@@ -10790,6 +11615,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
10790
11615
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
10791
11616
|
steps: array(PipelineStepInputSchema).min(1),
|
|
10792
11617
|
frame: FrameInputSchema.optional(),
|
|
11618
|
+
/**
|
|
11619
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
11620
|
+
* the decoded pixels live in. One more member of the one-of
|
|
11621
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
11622
|
+
*/
|
|
11623
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
10793
11624
|
imageBase64: string().optional(),
|
|
10794
11625
|
/**
|
|
10795
11626
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -11032,6 +11863,31 @@ var ReportMotionInputSchema = object({
|
|
|
11032
11863
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
11033
11864
|
});
|
|
11034
11865
|
/**
|
|
11866
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
11867
|
+
* restream-owner model — P2c).
|
|
11868
|
+
*
|
|
11869
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
11870
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
11871
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
11872
|
+
* behavior change.
|
|
11873
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
11874
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
11875
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
11876
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
11877
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
11878
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
11879
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
11880
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
11881
|
+
* dials for the owner's restream.
|
|
11882
|
+
*/
|
|
11883
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
11884
|
+
kind: literal("remote-restream"),
|
|
11885
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
11886
|
+
ownerNodeId: string(),
|
|
11887
|
+
/** Operator override for the owner host the runner dials. */
|
|
11888
|
+
hubHostnameOverride: string().optional()
|
|
11889
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
11890
|
+
/**
|
|
11035
11891
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
11036
11892
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
11037
11893
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -11129,7 +11985,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
11129
11985
|
*/
|
|
11130
11986
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
11131
11987
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
11132
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
11988
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
11989
|
+
/**
|
|
11990
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
11991
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
11992
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
11993
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
11994
|
+
* `remoteSourcingNodes` rollout setting).
|
|
11995
|
+
*/
|
|
11996
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
11133
11997
|
});
|
|
11134
11998
|
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;
|
|
11135
11999
|
/**
|
|
@@ -11693,6 +12557,157 @@ var numericSensorCapability = {
|
|
|
11693
12557
|
runtimeState: NumericSensorStatusSchema
|
|
11694
12558
|
};
|
|
11695
12559
|
/**
|
|
12560
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
12561
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
12562
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
12563
|
+
*/
|
|
12564
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
12565
|
+
"normal",
|
|
12566
|
+
"offline",
|
|
12567
|
+
"on_batteries"
|
|
12568
|
+
]);
|
|
12569
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
12570
|
+
var PetFeederStatusSchema = object({
|
|
12571
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
12572
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
12573
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
12574
|
+
foodLevel: number().nullable(),
|
|
12575
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
12576
|
+
* single-hopper models. */
|
|
12577
|
+
food1: number().nullable(),
|
|
12578
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
12579
|
+
* single-hopper models. */
|
|
12580
|
+
food2: number().nullable(),
|
|
12581
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
12582
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
12583
|
+
* below the feeder's low threshold. */
|
|
12584
|
+
lowFood: boolean(),
|
|
12585
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
12586
|
+
* device has no battery reading. */
|
|
12587
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
12588
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
12589
|
+
* desiccant sensor. */
|
|
12590
|
+
desiccantLeftDays: number().nullable(),
|
|
12591
|
+
/** True while a feed is in progress. */
|
|
12592
|
+
feeding: boolean(),
|
|
12593
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
12594
|
+
* Null until the device has reported a status. */
|
|
12595
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
12596
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
12597
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
12598
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
12599
|
+
error: string().nullable(),
|
|
12600
|
+
/** Raw device error code (0 / null = no error). */
|
|
12601
|
+
errorCode: number().nullable(),
|
|
12602
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
12603
|
+
isDualHopper: boolean(),
|
|
12604
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
12605
|
+
childLock: boolean(),
|
|
12606
|
+
/** Front indicator-light setting. */
|
|
12607
|
+
indicatorLight: boolean(),
|
|
12608
|
+
/** Play a chime when dispensing. */
|
|
12609
|
+
feedSound: boolean(),
|
|
12610
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
12611
|
+
volume: number(),
|
|
12612
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
12613
|
+
lastFetchedAt: number()
|
|
12614
|
+
});
|
|
12615
|
+
var petFeederCapability = {
|
|
12616
|
+
name: "pet-feeder",
|
|
12617
|
+
scope: "device",
|
|
12618
|
+
deviceNative: true,
|
|
12619
|
+
mode: "singleton",
|
|
12620
|
+
deviceTypes: [DeviceType.PetFeeder],
|
|
12621
|
+
methods: {
|
|
12622
|
+
/**
|
|
12623
|
+
* Dispense food now. Single-hopper feeders take `grams`; dual-hopper
|
|
12624
|
+
* feeders (D4S/D4SH) accept `hopper1`/`hopper2` to target one or both
|
|
12625
|
+
* hoppers. All portions honour the 4–200 g hardware range. At least
|
|
12626
|
+
* one of the three must be present — the provider rejects an empty
|
|
12627
|
+
* request.
|
|
12628
|
+
*/
|
|
12629
|
+
feed: method(object({
|
|
12630
|
+
deviceId: number().int().nonnegative(),
|
|
12631
|
+
grams: gramsPortion.optional(),
|
|
12632
|
+
hopper1: gramsPortion.optional(),
|
|
12633
|
+
hopper2: gramsPortion.optional()
|
|
12634
|
+
}), _void(), {
|
|
12635
|
+
kind: "mutation",
|
|
12636
|
+
auth: "admin"
|
|
12637
|
+
}),
|
|
12638
|
+
/** Cancel an in-progress manual feed. */
|
|
12639
|
+
cancelFeed: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12640
|
+
kind: "mutation",
|
|
12641
|
+
auth: "admin"
|
|
12642
|
+
}),
|
|
12643
|
+
/** Reset the desiccant "days remaining" counter after replacing it. */
|
|
12644
|
+
resetDesiccant: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12645
|
+
kind: "mutation",
|
|
12646
|
+
auth: "admin"
|
|
12647
|
+
}),
|
|
12648
|
+
/** Mark a hopper as refilled (D4H/D4S/D4SH). */
|
|
12649
|
+
markFoodReplenished: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12650
|
+
kind: "mutation",
|
|
12651
|
+
auth: "admin"
|
|
12652
|
+
}),
|
|
12653
|
+
/** Call the pet with the recorded prompt (D3). */
|
|
12654
|
+
callPet: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12655
|
+
kind: "mutation",
|
|
12656
|
+
auth: "admin"
|
|
12657
|
+
}),
|
|
12658
|
+
/** Play a stored sound by id (D3 / D4H / D4SH). */
|
|
12659
|
+
playSound: method(object({
|
|
12660
|
+
deviceId: number().int().nonnegative(),
|
|
12661
|
+
soundId: number().int().nonnegative()
|
|
12662
|
+
}), _void(), {
|
|
12663
|
+
kind: "mutation",
|
|
12664
|
+
auth: "admin"
|
|
12665
|
+
}),
|
|
12666
|
+
/** Toggle the child-lock (manual-lock) setting. */
|
|
12667
|
+
setChildLock: method(object({
|
|
12668
|
+
deviceId: number().int().nonnegative(),
|
|
12669
|
+
on: boolean()
|
|
12670
|
+
}), _void(), {
|
|
12671
|
+
kind: "mutation",
|
|
12672
|
+
auth: "admin"
|
|
12673
|
+
}),
|
|
12674
|
+
/** Toggle the front indicator light. */
|
|
12675
|
+
setIndicatorLight: method(object({
|
|
12676
|
+
deviceId: number().int().nonnegative(),
|
|
12677
|
+
on: boolean()
|
|
12678
|
+
}), _void(), {
|
|
12679
|
+
kind: "mutation",
|
|
12680
|
+
auth: "admin"
|
|
12681
|
+
}),
|
|
12682
|
+
/** Toggle the dispense chime. */
|
|
12683
|
+
setFeedSound: method(object({
|
|
12684
|
+
deviceId: number().int().nonnegative(),
|
|
12685
|
+
on: boolean()
|
|
12686
|
+
}), _void(), {
|
|
12687
|
+
kind: "mutation",
|
|
12688
|
+
auth: "admin"
|
|
12689
|
+
}),
|
|
12690
|
+
/** Set the speaker / prompt volume level. */
|
|
12691
|
+
setVolume: method(object({
|
|
12692
|
+
deviceId: number().int().nonnegative(),
|
|
12693
|
+
level: number().int().nonnegative()
|
|
12694
|
+
}), _void(), {
|
|
12695
|
+
kind: "mutation",
|
|
12696
|
+
auth: "admin"
|
|
12697
|
+
})
|
|
12698
|
+
},
|
|
12699
|
+
status: {
|
|
12700
|
+
schema: PetFeederStatusSchema,
|
|
12701
|
+
kind: "poll"
|
|
12702
|
+
},
|
|
12703
|
+
/**
|
|
12704
|
+
* Runtime-state slice — mirrored by the kernel. UI feeder cards read
|
|
12705
|
+
* the full slice via `device.state.petFeeder.value` and refresh on
|
|
12706
|
+
* every poll without re-querying the provider.
|
|
12707
|
+
*/
|
|
12708
|
+
runtimeState: PetFeederStatusSchema
|
|
12709
|
+
};
|
|
12710
|
+
/**
|
|
11696
12711
|
* Multi-metric electrical meter. One slice can carry any combination
|
|
11697
12712
|
* of instantaneous power (W), cumulative energy (kWh), voltage (V),
|
|
11698
12713
|
* and current (A) — all fields optional so a single-metric source
|
|
@@ -12995,6 +14010,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
|
|
|
12995
14010
|
nativeObjectDetection: nativeObjectDetectionCapability,
|
|
12996
14011
|
notifier: notifierCapability,
|
|
12997
14012
|
numericSensor: numericSensorCapability,
|
|
14013
|
+
petFeeder: petFeederCapability,
|
|
12998
14014
|
powerMeter: powerMeterCapability,
|
|
12999
14015
|
presence: presenceCapability,
|
|
13000
14016
|
pressureSensor: pressureSensorCapability,
|
|
@@ -14960,10 +15976,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
14960
15976
|
url: string()
|
|
14961
15977
|
}), _void()), method(object({
|
|
14962
15978
|
sessionId: string(),
|
|
14963
|
-
maxCount: number().default(1)
|
|
15979
|
+
maxCount: number().default(1),
|
|
15980
|
+
waitMs: number().optional()
|
|
14964
15981
|
}), array(DecodedFrameSchema)), method(object({
|
|
14965
15982
|
sessionId: string(),
|
|
14966
|
-
maxCount: number().default(1)
|
|
15983
|
+
maxCount: number().default(1),
|
|
15984
|
+
waitMs: number().optional()
|
|
14967
15985
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
14968
15986
|
sessionId: string(),
|
|
14969
15987
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -15267,14 +16285,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
15267
16285
|
collapsed: boolean().optional()
|
|
15268
16286
|
});
|
|
15269
16287
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
15270
|
-
* `device-management.ts`.
|
|
16288
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
16289
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
16290
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
16291
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
16292
|
+
* source device's full re-sync-stable `stableId`. */
|
|
16293
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
16294
|
+
kind: literal("field").optional(),
|
|
16295
|
+
sourceKey: string(),
|
|
16296
|
+
cap: string(),
|
|
16297
|
+
fieldPath: string()
|
|
16298
|
+
});
|
|
16299
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
16300
|
+
kind: literal("literal"),
|
|
16301
|
+
value: union([
|
|
16302
|
+
string(),
|
|
16303
|
+
number(),
|
|
16304
|
+
boolean(),
|
|
16305
|
+
_null()
|
|
16306
|
+
])
|
|
16307
|
+
});
|
|
16308
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
16309
|
+
kind: literal("global"),
|
|
16310
|
+
sourceStableId: string(),
|
|
16311
|
+
cap: string(),
|
|
16312
|
+
fieldPath: string()
|
|
16313
|
+
});
|
|
16314
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
16315
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
16316
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
16317
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
16318
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
16319
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
16320
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
16321
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
16322
|
+
kind: literal("expression"),
|
|
16323
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
16324
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
16325
|
+
DeviceLinkFieldSourceSchema,
|
|
16326
|
+
DeviceLinkLiteralSourceSchema,
|
|
16327
|
+
DeviceLinkGlobalSourceSchema
|
|
16328
|
+
]))
|
|
16329
|
+
}).superRefine((src, ctx) => {
|
|
16330
|
+
const err = validateExpressionSource(src);
|
|
16331
|
+
if (err !== null) ctx.addIssue({
|
|
16332
|
+
code: "custom",
|
|
16333
|
+
message: err,
|
|
16334
|
+
path: ["expr"]
|
|
16335
|
+
});
|
|
16336
|
+
});
|
|
15271
16337
|
var DeviceLinkSchema = object({
|
|
15272
16338
|
id: string(),
|
|
15273
|
-
source:
|
|
15274
|
-
|
|
15275
|
-
|
|
15276
|
-
|
|
15277
|
-
|
|
16339
|
+
source: union([
|
|
16340
|
+
DeviceLinkFieldSourceSchema,
|
|
16341
|
+
DeviceLinkLiteralSourceSchema,
|
|
16342
|
+
DeviceLinkGlobalSourceSchema,
|
|
16343
|
+
DeviceLinkExpressionSourceSchema
|
|
16344
|
+
]),
|
|
15278
16345
|
target: object({
|
|
15279
16346
|
cap: string(),
|
|
15280
16347
|
fieldPath: string(),
|
|
@@ -15303,6 +16370,31 @@ var DeviceLinkSchema = object({
|
|
|
15303
16370
|
})
|
|
15304
16371
|
]).optional()
|
|
15305
16372
|
});
|
|
16373
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
16374
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
16375
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
16376
|
+
unit: string().min(1).optional(),
|
|
16377
|
+
precision: number().int().min(0).max(10).optional()
|
|
16378
|
+
});
|
|
16379
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
16380
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
16381
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
16382
|
+
var DeviceDisplayOverrideSchema = object({
|
|
16383
|
+
icon: string().min(1).optional(),
|
|
16384
|
+
label: string().min(1).optional(),
|
|
16385
|
+
unit: string().min(1).optional(),
|
|
16386
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16387
|
+
hidden: boolean().optional(),
|
|
16388
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
16389
|
+
});
|
|
16390
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
16391
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
16392
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
16393
|
+
var RoleDisplayDefaultSchema = object({
|
|
16394
|
+
unit: string().min(1).optional(),
|
|
16395
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16396
|
+
icon: string().min(1).optional()
|
|
16397
|
+
});
|
|
15306
16398
|
/**
|
|
15307
16399
|
* Serializable projection of a live IDevice.
|
|
15308
16400
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -15358,7 +16450,9 @@ var DeviceInfoSchema = object({
|
|
|
15358
16450
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
15359
16451
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
15360
16452
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
15361
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
16453
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
16454
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16455
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15362
16456
|
});
|
|
15363
16457
|
var ConfigEntrySchema = object({
|
|
15364
16458
|
key: string(),
|
|
@@ -15423,7 +16517,9 @@ var DeviceMetaSchema = object({
|
|
|
15423
16517
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
15424
16518
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
15425
16519
|
* Optional: only present for accessory children that carry a known role. */
|
|
15426
|
-
role: string().nullable().optional()
|
|
16520
|
+
role: string().nullable().optional(),
|
|
16521
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16522
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15427
16523
|
});
|
|
15428
16524
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
15429
16525
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -15517,7 +16613,19 @@ method(object({
|
|
|
15517
16613
|
}), _void(), {
|
|
15518
16614
|
kind: "mutation",
|
|
15519
16615
|
auth: "admin"
|
|
15520
|
-
}), method(object({
|
|
16616
|
+
}), method(object({
|
|
16617
|
+
deviceId: number(),
|
|
16618
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
16619
|
+
}), _void(), {
|
|
16620
|
+
kind: "mutation",
|
|
16621
|
+
auth: "admin"
|
|
16622
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
16623
|
+
kind: "mutation",
|
|
16624
|
+
auth: "admin"
|
|
16625
|
+
}), method(object({
|
|
16626
|
+
deviceId: number(),
|
|
16627
|
+
includeSynthesizable: boolean().optional()
|
|
16628
|
+
}), object({ caps: array(object({
|
|
15521
16629
|
cap: string(),
|
|
15522
16630
|
fields: array(object({
|
|
15523
16631
|
path: string(),
|
|
@@ -15527,8 +16635,13 @@ method(object({
|
|
|
15527
16635
|
"boolean",
|
|
15528
16636
|
"enum"
|
|
15529
16637
|
]),
|
|
15530
|
-
enumValues: array(string()).optional()
|
|
15531
|
-
|
|
16638
|
+
enumValues: array(string()).optional(),
|
|
16639
|
+
item: boolean().optional()
|
|
16640
|
+
})).readonly(),
|
|
16641
|
+
itemArray: object({
|
|
16642
|
+
path: string(),
|
|
16643
|
+
keyField: string()
|
|
16644
|
+
}).optional()
|
|
15532
16645
|
})).readonly() }), { kind: "query" }), method(object({
|
|
15533
16646
|
deviceId: number(),
|
|
15534
16647
|
role: string().nullable()
|
|
@@ -15598,7 +16711,11 @@ method(object({
|
|
|
15598
16711
|
deviceId: number(),
|
|
15599
16712
|
entries: array(object({
|
|
15600
16713
|
capName: string(),
|
|
15601
|
-
kind: _enum([
|
|
16714
|
+
kind: _enum([
|
|
16715
|
+
"native",
|
|
16716
|
+
"wrapped",
|
|
16717
|
+
"linked"
|
|
16718
|
+
]),
|
|
15602
16719
|
providerAddonId: string(),
|
|
15603
16720
|
providerNodeId: string(),
|
|
15604
16721
|
nativeAddonId: string()
|
|
@@ -15607,7 +16724,11 @@ method(object({
|
|
|
15607
16724
|
deviceId: number(),
|
|
15608
16725
|
entries: array(object({
|
|
15609
16726
|
capName: string(),
|
|
15610
|
-
kind: _enum([
|
|
16727
|
+
kind: _enum([
|
|
16728
|
+
"native",
|
|
16729
|
+
"wrapped",
|
|
16730
|
+
"linked"
|
|
16731
|
+
]),
|
|
15611
16732
|
providerAddonId: string(),
|
|
15612
16733
|
providerNodeId: string(),
|
|
15613
16734
|
nativeAddonId: string()
|
|
@@ -16097,7 +17218,7 @@ var AddBrokerInputSchema = object({
|
|
|
16097
17218
|
});
|
|
16098
17219
|
var AddBrokerResultSchema = object({ id: string() });
|
|
16099
17220
|
var IdInputSchema = object({ id: string() });
|
|
16100
|
-
var TestResultSchema = discriminatedUnion("ok", [object({
|
|
17221
|
+
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
16101
17222
|
ok: literal(true),
|
|
16102
17223
|
latencyMs: number()
|
|
16103
17224
|
}), object({
|
|
@@ -16120,7 +17241,7 @@ var StatusSchema = object({
|
|
|
16120
17241
|
brokerCount: number(),
|
|
16121
17242
|
embeddedRunning: boolean()
|
|
16122
17243
|
});
|
|
16123
|
-
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);
|
|
17244
|
+
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);
|
|
16124
17245
|
var NetworkEndpointSchema = object({
|
|
16125
17246
|
url: string(),
|
|
16126
17247
|
hostname: string(),
|
|
@@ -16154,23 +17275,198 @@ var NetworkEndpointEntrySchema = NetworkEndpointSchema.extend({
|
|
|
16154
17275
|
sourcePort: number().optional()
|
|
16155
17276
|
});
|
|
16156
17277
|
method(_void(), NetworkEndpointSchema, { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), method(_void(), NetworkEndpointSchema.nullable()), method(_void(), NetworkAccessStatusSchema), method(_void(), array(NetworkEndpointEntrySchema).readonly());
|
|
16157
|
-
|
|
16158
|
-
|
|
17278
|
+
/**
|
|
17279
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
17280
|
+
*
|
|
17281
|
+
* Apprise-derived model (see
|
|
17282
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
17283
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
17284
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
17285
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
17286
|
+
* message to what the kind supports — callers never special-case a service.
|
|
17287
|
+
*
|
|
17288
|
+
* DESIGN DECISIONS (locked):
|
|
17289
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
17290
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
17291
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
17292
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
17293
|
+
* alternative would fork the UI per addon and cannot host the
|
|
17294
|
+
* discovery→adopt flow.
|
|
17295
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
17296
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
17297
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
17298
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
17299
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
17300
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
17301
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
17302
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
17303
|
+
* base64 fallback needed.
|
|
17304
|
+
*
|
|
17305
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
17306
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
17307
|
+
* admin "Integrations" page.
|
|
17308
|
+
*/
|
|
17309
|
+
/**
|
|
17310
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
17311
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
17312
|
+
*/
|
|
17313
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
17314
|
+
"image",
|
|
17315
|
+
"video",
|
|
17316
|
+
"gif",
|
|
17317
|
+
"audio",
|
|
17318
|
+
"icon"
|
|
17319
|
+
]);
|
|
17320
|
+
/**
|
|
17321
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
17322
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
17323
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
17324
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
17325
|
+
*/
|
|
17326
|
+
var AttachmentSchema = object({
|
|
17327
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
17328
|
+
url: string().optional(),
|
|
17329
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
17330
|
+
mime: string().optional(),
|
|
17331
|
+
name: string().optional()
|
|
17332
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
17333
|
+
var NotificationFormatSchema = _enum([
|
|
17334
|
+
"text",
|
|
17335
|
+
"markdown",
|
|
17336
|
+
"html"
|
|
17337
|
+
]);
|
|
17338
|
+
/** A single tap-through action button. */
|
|
17339
|
+
var NotificationActionSchema = object({
|
|
17340
|
+
id: string(),
|
|
17341
|
+
label: string(),
|
|
17342
|
+
url: string().optional()
|
|
17343
|
+
});
|
|
17344
|
+
/**
|
|
17345
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
17346
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
17347
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
17348
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
17349
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
17350
|
+
* `priority` for that one target.
|
|
17351
|
+
*/
|
|
17352
|
+
var NotificationSchema = object({
|
|
16159
17353
|
body: string(),
|
|
16160
|
-
|
|
17354
|
+
title: string().optional(),
|
|
17355
|
+
format: NotificationFormatSchema.default("text"),
|
|
17356
|
+
priority: number().int().min(1).max(5).default(3),
|
|
17357
|
+
level: string().optional(),
|
|
17358
|
+
attachments: array(AttachmentSchema).optional(),
|
|
17359
|
+
clickUrl: string().optional(),
|
|
17360
|
+
actions: array(NotificationActionSchema).optional(),
|
|
17361
|
+
sound: string().optional(),
|
|
17362
|
+
ttl: number().optional(),
|
|
17363
|
+
tag: string().optional(),
|
|
16161
17364
|
deviceId: number().optional(),
|
|
16162
17365
|
eventId: string().optional(),
|
|
16163
|
-
priority: _enum([
|
|
16164
|
-
"low",
|
|
16165
|
-
"normal",
|
|
16166
|
-
"high",
|
|
16167
|
-
"critical"
|
|
16168
|
-
]).default("normal"),
|
|
16169
17366
|
metadata: record(string(), unknown()).optional()
|
|
16170
|
-
})
|
|
17367
|
+
});
|
|
17368
|
+
/** One declared native severity/priority level for a kind. */
|
|
17369
|
+
var TargetKindLevelSchema = object({
|
|
17370
|
+
id: string(),
|
|
17371
|
+
label: string(),
|
|
17372
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
17373
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
17374
|
+
flags: object({
|
|
17375
|
+
critical: boolean().optional(),
|
|
17376
|
+
silent: boolean().optional(),
|
|
17377
|
+
noPush: boolean().optional()
|
|
17378
|
+
}).optional(),
|
|
17379
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
17380
|
+
requires: array(string()).optional(),
|
|
17381
|
+
description: string().optional()
|
|
17382
|
+
});
|
|
17383
|
+
/** The full capability block consulted before dispatch. */
|
|
17384
|
+
var TargetKindCapsSchema = object({
|
|
17385
|
+
attachments: object({
|
|
17386
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
17387
|
+
mode: _enum([
|
|
17388
|
+
"url",
|
|
17389
|
+
"bytes",
|
|
17390
|
+
"both"
|
|
17391
|
+
]),
|
|
17392
|
+
max: number().int().nonnegative(),
|
|
17393
|
+
maxBytes: number().int().positive().optional()
|
|
17394
|
+
}),
|
|
17395
|
+
/** Max action buttons (0 = none). */
|
|
17396
|
+
actions: number().int().nonnegative(),
|
|
17397
|
+
levels: array(TargetKindLevelSchema),
|
|
17398
|
+
format: array(NotificationFormatSchema),
|
|
17399
|
+
clickUrl: boolean(),
|
|
17400
|
+
sound: boolean(),
|
|
17401
|
+
ttl: boolean(),
|
|
17402
|
+
bodyMaxLen: number().int().positive()
|
|
17403
|
+
});
|
|
17404
|
+
/**
|
|
17405
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
17406
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
17407
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
17408
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
17409
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
17410
|
+
*/
|
|
17411
|
+
var ConfigSchemaPassthrough = unknown();
|
|
17412
|
+
var TargetKindSchema = object({
|
|
17413
|
+
kind: string(),
|
|
17414
|
+
label: string(),
|
|
17415
|
+
icon: string(),
|
|
17416
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
17417
|
+
addonId: string(),
|
|
17418
|
+
configSchema: ConfigSchemaPassthrough,
|
|
17419
|
+
supportsDiscovery: boolean(),
|
|
17420
|
+
caps: TargetKindCapsSchema
|
|
17421
|
+
});
|
|
17422
|
+
/**
|
|
17423
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
17424
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
17425
|
+
* round-trip a stored secret to the UI.
|
|
17426
|
+
*/
|
|
17427
|
+
var TargetSchema = object({
|
|
17428
|
+
id: string(),
|
|
17429
|
+
name: string(),
|
|
17430
|
+
kind: string(),
|
|
17431
|
+
addonId: string(),
|
|
17432
|
+
enabled: boolean(),
|
|
17433
|
+
config: record(string(), unknown())
|
|
17434
|
+
});
|
|
17435
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
17436
|
+
var DiscoveredTargetSchema = object({
|
|
17437
|
+
kind: string(),
|
|
17438
|
+
suggestedName: string(),
|
|
17439
|
+
config: record(string(), unknown())
|
|
17440
|
+
});
|
|
17441
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
17442
|
+
var RenderedAsSchema = object({
|
|
17443
|
+
level: string(),
|
|
17444
|
+
format: NotificationFormatSchema,
|
|
17445
|
+
attachmentsSent: number().int().nonnegative(),
|
|
17446
|
+
actionsSent: number().int().nonnegative(),
|
|
17447
|
+
truncated: boolean(),
|
|
17448
|
+
dropped: array(string())
|
|
17449
|
+
});
|
|
17450
|
+
var SendResultSchema = object({
|
|
16171
17451
|
success: boolean(),
|
|
16172
|
-
error: string().optional()
|
|
16173
|
-
|
|
17452
|
+
error: string().optional(),
|
|
17453
|
+
renderedAs: RenderedAsSchema.optional()
|
|
17454
|
+
});
|
|
17455
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
17456
|
+
var TestResultSchema = SendResultSchema;
|
|
17457
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema)), method(object({
|
|
17458
|
+
kind: string(),
|
|
17459
|
+
config: record(string(), unknown()).optional()
|
|
17460
|
+
}), array(DiscoveredTargetSchema)), method(object({
|
|
17461
|
+
targetId: string(),
|
|
17462
|
+
notification: NotificationSchema
|
|
17463
|
+
}), SendResultSchema, { kind: "mutation" }), method(object({
|
|
17464
|
+
targetId: string(),
|
|
17465
|
+
sample: NotificationSchema.optional()
|
|
17466
|
+
}), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
|
|
17467
|
+
targetId: string(),
|
|
17468
|
+
enabled: boolean()
|
|
17469
|
+
}), _void(), { kind: "mutation" });
|
|
16174
17470
|
/**
|
|
16175
17471
|
* Zod schemas for persisted record types.
|
|
16176
17472
|
*
|
|
@@ -19192,7 +20488,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
19192
20488
|
"webgpu",
|
|
19193
20489
|
"none"
|
|
19194
20490
|
]).nullable().optional();
|
|
19195
|
-
var HwAccelResolutionSchema = object({
|
|
20491
|
+
var HwAccelResolutionSchema = object({
|
|
20492
|
+
preferred: array(string()).readonly(),
|
|
20493
|
+
rationale: string()
|
|
20494
|
+
});
|
|
19196
20495
|
var HardwareEncoderIdSchema = _enum([
|
|
19197
20496
|
"h264_videotoolbox",
|
|
19198
20497
|
"hevc_videotoolbox",
|
|
@@ -19297,10 +20596,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
19297
20596
|
format: ModelFormatSchema,
|
|
19298
20597
|
reason: string()
|
|
19299
20598
|
});
|
|
19300
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
19301
|
-
prefer: HwAccelBackendInputSchema,
|
|
19302
|
-
nodeId: string().optional()
|
|
19303
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
20599
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
19304
20600
|
kind: "mutation",
|
|
19305
20601
|
auth: "admin"
|
|
19306
20602
|
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
@@ -19359,6 +20655,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
19359
20655
|
kind: "mutation",
|
|
19360
20656
|
auth: "admin"
|
|
19361
20657
|
});
|
|
20658
|
+
/**
|
|
20659
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
20660
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
20661
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
20662
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
20663
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
20664
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
20665
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
20666
|
+
* (`interfaces/recording-config.ts`).
|
|
20667
|
+
*/
|
|
19362
20668
|
var RecordingStatusSchema = object({
|
|
19363
20669
|
deviceId: number(),
|
|
19364
20670
|
enabled: boolean(),
|
|
@@ -20995,6 +22301,12 @@ Object.freeze({
|
|
|
20995
22301
|
addonId: null,
|
|
20996
22302
|
access: "view"
|
|
20997
22303
|
},
|
|
22304
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
22305
|
+
capName: "device-manager",
|
|
22306
|
+
capScope: "system",
|
|
22307
|
+
addonId: null,
|
|
22308
|
+
access: "view"
|
|
22309
|
+
},
|
|
20998
22310
|
"deviceManager.getSettingsSchema": {
|
|
20999
22311
|
capName: "device-manager",
|
|
21000
22312
|
capScope: "system",
|
|
@@ -21145,6 +22457,12 @@ Object.freeze({
|
|
|
21145
22457
|
addonId: null,
|
|
21146
22458
|
access: "create"
|
|
21147
22459
|
},
|
|
22460
|
+
"deviceManager.setDisplay": {
|
|
22461
|
+
capName: "device-manager",
|
|
22462
|
+
capScope: "system",
|
|
22463
|
+
addonId: null,
|
|
22464
|
+
access: "create"
|
|
22465
|
+
},
|
|
21148
22466
|
"deviceManager.setIntegrationId": {
|
|
21149
22467
|
capName: "device-manager",
|
|
21150
22468
|
capScope: "system",
|
|
@@ -21187,6 +22505,12 @@ Object.freeze({
|
|
|
21187
22505
|
addonId: null,
|
|
21188
22506
|
access: "create"
|
|
21189
22507
|
},
|
|
22508
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
22509
|
+
capName: "device-manager",
|
|
22510
|
+
capScope: "system",
|
|
22511
|
+
addonId: null,
|
|
22512
|
+
access: "create"
|
|
22513
|
+
},
|
|
21190
22514
|
"deviceManager.setStreamProfileMap": {
|
|
21191
22515
|
capName: "device-manager",
|
|
21192
22516
|
capScope: "system",
|
|
@@ -22165,13 +23489,49 @@ Object.freeze({
|
|
|
22165
23489
|
addonId: null,
|
|
22166
23490
|
access: "create"
|
|
22167
23491
|
},
|
|
23492
|
+
"notificationOutput.deleteTarget": {
|
|
23493
|
+
capName: "notification-output",
|
|
23494
|
+
capScope: "system",
|
|
23495
|
+
addonId: null,
|
|
23496
|
+
access: "delete"
|
|
23497
|
+
},
|
|
23498
|
+
"notificationOutput.discoverTargets": {
|
|
23499
|
+
capName: "notification-output",
|
|
23500
|
+
capScope: "system",
|
|
23501
|
+
addonId: null,
|
|
23502
|
+
access: "view"
|
|
23503
|
+
},
|
|
23504
|
+
"notificationOutput.listTargetKinds": {
|
|
23505
|
+
capName: "notification-output",
|
|
23506
|
+
capScope: "system",
|
|
23507
|
+
addonId: null,
|
|
23508
|
+
access: "view"
|
|
23509
|
+
},
|
|
23510
|
+
"notificationOutput.listTargets": {
|
|
23511
|
+
capName: "notification-output",
|
|
23512
|
+
capScope: "system",
|
|
23513
|
+
addonId: null,
|
|
23514
|
+
access: "view"
|
|
23515
|
+
},
|
|
22168
23516
|
"notificationOutput.send": {
|
|
22169
23517
|
capName: "notification-output",
|
|
22170
23518
|
capScope: "system",
|
|
22171
23519
|
addonId: null,
|
|
22172
23520
|
access: "create"
|
|
22173
23521
|
},
|
|
22174
|
-
"notificationOutput.
|
|
23522
|
+
"notificationOutput.setTargetEnabled": {
|
|
23523
|
+
capName: "notification-output",
|
|
23524
|
+
capScope: "system",
|
|
23525
|
+
addonId: null,
|
|
23526
|
+
access: "create"
|
|
23527
|
+
},
|
|
23528
|
+
"notificationOutput.testTarget": {
|
|
23529
|
+
capName: "notification-output",
|
|
23530
|
+
capScope: "system",
|
|
23531
|
+
addonId: null,
|
|
23532
|
+
access: "create"
|
|
23533
|
+
},
|
|
23534
|
+
"notificationOutput.upsertTarget": {
|
|
22175
23535
|
capName: "notification-output",
|
|
22176
23536
|
capScope: "system",
|
|
22177
23537
|
addonId: null,
|
|
@@ -22201,6 +23561,66 @@ Object.freeze({
|
|
|
22201
23561
|
addonId: null,
|
|
22202
23562
|
access: "create"
|
|
22203
23563
|
},
|
|
23564
|
+
"petFeeder.callPet": {
|
|
23565
|
+
capName: "pet-feeder",
|
|
23566
|
+
capScope: "device",
|
|
23567
|
+
addonId: null,
|
|
23568
|
+
access: "create"
|
|
23569
|
+
},
|
|
23570
|
+
"petFeeder.cancelFeed": {
|
|
23571
|
+
capName: "pet-feeder",
|
|
23572
|
+
capScope: "device",
|
|
23573
|
+
addonId: null,
|
|
23574
|
+
access: "create"
|
|
23575
|
+
},
|
|
23576
|
+
"petFeeder.feed": {
|
|
23577
|
+
capName: "pet-feeder",
|
|
23578
|
+
capScope: "device",
|
|
23579
|
+
addonId: null,
|
|
23580
|
+
access: "create"
|
|
23581
|
+
},
|
|
23582
|
+
"petFeeder.markFoodReplenished": {
|
|
23583
|
+
capName: "pet-feeder",
|
|
23584
|
+
capScope: "device",
|
|
23585
|
+
addonId: null,
|
|
23586
|
+
access: "create"
|
|
23587
|
+
},
|
|
23588
|
+
"petFeeder.playSound": {
|
|
23589
|
+
capName: "pet-feeder",
|
|
23590
|
+
capScope: "device",
|
|
23591
|
+
addonId: null,
|
|
23592
|
+
access: "create"
|
|
23593
|
+
},
|
|
23594
|
+
"petFeeder.resetDesiccant": {
|
|
23595
|
+
capName: "pet-feeder",
|
|
23596
|
+
capScope: "device",
|
|
23597
|
+
addonId: null,
|
|
23598
|
+
access: "delete"
|
|
23599
|
+
},
|
|
23600
|
+
"petFeeder.setChildLock": {
|
|
23601
|
+
capName: "pet-feeder",
|
|
23602
|
+
capScope: "device",
|
|
23603
|
+
addonId: null,
|
|
23604
|
+
access: "create"
|
|
23605
|
+
},
|
|
23606
|
+
"petFeeder.setFeedSound": {
|
|
23607
|
+
capName: "pet-feeder",
|
|
23608
|
+
capScope: "device",
|
|
23609
|
+
addonId: null,
|
|
23610
|
+
access: "create"
|
|
23611
|
+
},
|
|
23612
|
+
"petFeeder.setIndicatorLight": {
|
|
23613
|
+
capName: "pet-feeder",
|
|
23614
|
+
capScope: "device",
|
|
23615
|
+
addonId: null,
|
|
23616
|
+
access: "create"
|
|
23617
|
+
},
|
|
23618
|
+
"petFeeder.setVolume": {
|
|
23619
|
+
capName: "pet-feeder",
|
|
23620
|
+
capScope: "device",
|
|
23621
|
+
addonId: null,
|
|
23622
|
+
access: "create"
|
|
23623
|
+
},
|
|
22204
23624
|
"pipelineAnalytics.clearTracks": {
|
|
22205
23625
|
capName: "pipeline-analytics",
|
|
22206
23626
|
capScope: "device",
|
|
@@ -49643,7 +51063,7 @@ var HomematicProviderAddon = class extends BaseDeviceProvider {
|
|
|
49643
51063
|
}
|
|
49644
51064
|
async onInitialize() {
|
|
49645
51065
|
const regs = await super.onInitialize();
|
|
49646
|
-
const migrated = migrateLegacyConfig(await this.
|
|
51066
|
+
const migrated = migrateLegacyConfig(await this.resolveGlobalStore());
|
|
49647
51067
|
if (this.brokersDiffer(migrated.brokers, this.config.brokers)) await this.updateGlobalSettings({ brokers: migrated.brokers });
|
|
49648
51068
|
this.registry = new HmBrokerRegistry(this.ctx.logger);
|
|
49649
51069
|
this.registry.setOnBrokerConnected((brokerId) => {
|