@camstack/addon-provider-dreo 0.1.8 → 0.1.10
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 +1482 -62
- package/dist/addon.mjs +1482 -62
- package/package.json +1 -1
package/dist/addon.js
CHANGED
|
@@ -4664,7 +4664,7 @@ function _instanceof(cls, params = {}) {
|
|
|
4664
4664
|
return inst;
|
|
4665
4665
|
}
|
|
4666
4666
|
//#endregion
|
|
4667
|
-
//#region ../types/dist/sleep-
|
|
4667
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4668
4668
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4669
4669
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4670
4670
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5477,6 +5477,100 @@ function createDurableState(deps) {
|
|
|
5477
5477
|
};
|
|
5478
5478
|
}
|
|
5479
5479
|
/**
|
|
5480
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5481
|
+
*
|
|
5482
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5483
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5484
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5485
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5486
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5487
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5488
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5489
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5490
|
+
*
|
|
5491
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5492
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5493
|
+
* schema and routes reads/writes through these helpers.
|
|
5494
|
+
*
|
|
5495
|
+
* ## No bare-key fallback — deliberate
|
|
5496
|
+
*
|
|
5497
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5498
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5499
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5500
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5501
|
+
* selection can never leak onto another. (This generalizes the
|
|
5502
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5503
|
+
* arbitrary set of per-node field keys.)
|
|
5504
|
+
*
|
|
5505
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5506
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5507
|
+
*/
|
|
5508
|
+
/**
|
|
5509
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5510
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5511
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5512
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5513
|
+
*/
|
|
5514
|
+
function normalizeNodeId(raw) {
|
|
5515
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5516
|
+
const slashIdx = raw.indexOf("/");
|
|
5517
|
+
if (slashIdx < 0) return raw;
|
|
5518
|
+
const bare = raw.slice(0, slashIdx);
|
|
5519
|
+
return bare === "" ? "hub" : bare;
|
|
5520
|
+
}
|
|
5521
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5522
|
+
function nodeScopedKey(base, nodeId) {
|
|
5523
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5524
|
+
}
|
|
5525
|
+
/**
|
|
5526
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5527
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5528
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5529
|
+
* schema `default` win on `undefined`.
|
|
5530
|
+
*/
|
|
5531
|
+
function readNodeValue(store, base, nodeId) {
|
|
5532
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5533
|
+
}
|
|
5534
|
+
/**
|
|
5535
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5536
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5537
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5538
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5539
|
+
* patch is not mutated.
|
|
5540
|
+
*/
|
|
5541
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5542
|
+
const out = {};
|
|
5543
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5544
|
+
return out;
|
|
5545
|
+
}
|
|
5546
|
+
/**
|
|
5547
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5548
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5549
|
+
* values:
|
|
5550
|
+
*
|
|
5551
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5552
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5553
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5554
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5555
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5556
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5557
|
+
*
|
|
5558
|
+
* Returns a new object — the input store is not mutated.
|
|
5559
|
+
*/
|
|
5560
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5561
|
+
const out = {};
|
|
5562
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5563
|
+
if (key.includes("@")) continue;
|
|
5564
|
+
if (perNodeKeys.has(key)) continue;
|
|
5565
|
+
out[key] = value;
|
|
5566
|
+
}
|
|
5567
|
+
for (const base of perNodeKeys) {
|
|
5568
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5569
|
+
if (value !== void 0) out[base] = value;
|
|
5570
|
+
}
|
|
5571
|
+
return out;
|
|
5572
|
+
}
|
|
5573
|
+
/**
|
|
5480
5574
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5481
5575
|
*
|
|
5482
5576
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5644,23 +5738,63 @@ var BaseAddon = class {
|
|
|
5644
5738
|
deviceSettingsSchema() {
|
|
5645
5739
|
return null;
|
|
5646
5740
|
}
|
|
5647
|
-
async getGlobalSettings(overlay, cap,
|
|
5741
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5648
5742
|
const schema = this.globalSettingsSchema(cap);
|
|
5649
5743
|
if (!schema) return { sections: [] };
|
|
5650
|
-
const
|
|
5744
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5651
5745
|
return hydrateSchema(schema, overlay ? {
|
|
5652
|
-
...
|
|
5746
|
+
...projected,
|
|
5653
5747
|
...overlay
|
|
5654
|
-
} :
|
|
5748
|
+
} : projected);
|
|
5655
5749
|
}
|
|
5656
|
-
|
|
5657
|
-
|
|
5750
|
+
/**
|
|
5751
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5752
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5753
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5754
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5755
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5756
|
+
*
|
|
5757
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5758
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5759
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5760
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5761
|
+
*/
|
|
5762
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5763
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5764
|
+
const keys = this.perNodeKeys(cap);
|
|
5765
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5766
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5767
|
+
}
|
|
5768
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5769
|
+
const keys = this.perNodeKeys();
|
|
5770
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5771
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5772
|
+
const barePatch = patch;
|
|
5773
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5774
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5775
|
+
if (target !== localNode) return;
|
|
5658
5776
|
await this.resolveConfig();
|
|
5659
5777
|
await this.onConfigChanged();
|
|
5660
5778
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5661
5779
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5662
5780
|
}
|
|
5663
5781
|
/**
|
|
5782
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5783
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5784
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5785
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5786
|
+
*/
|
|
5787
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5788
|
+
perNodeKeys(cap) {
|
|
5789
|
+
const cacheKey = cap ?? "";
|
|
5790
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5791
|
+
if (cached) return cached;
|
|
5792
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5793
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5794
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5795
|
+
return keys;
|
|
5796
|
+
}
|
|
5797
|
+
/**
|
|
5664
5798
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5665
5799
|
* schedule an addon restart for the next tick. Deferred via
|
|
5666
5800
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5813,12 +5947,19 @@ var BaseAddon = class {
|
|
|
5813
5947
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5814
5948
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5815
5949
|
* (e.g. from older versions) without polluting the typed config.
|
|
5950
|
+
*
|
|
5951
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5952
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5953
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5954
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5816
5955
|
*/
|
|
5817
5956
|
async resolveConfig() {
|
|
5818
5957
|
const stored = await this.readAddonStoreWithRetry();
|
|
5958
|
+
const perNode = this.perNodeKeys();
|
|
5959
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5819
5960
|
const resolved = { ...this.defaults };
|
|
5820
5961
|
for (const key of Object.keys(this.defaults)) {
|
|
5821
|
-
const storedValue = stored[key];
|
|
5962
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5822
5963
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5823
5964
|
const defaultType = typeof this.defaults[key];
|
|
5824
5965
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5902,6 +6043,27 @@ var BaseAddon = class {
|
|
|
5902
6043
|
}
|
|
5903
6044
|
};
|
|
5904
6045
|
/**
|
|
6046
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6047
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6048
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6049
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6050
|
+
*/
|
|
6051
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6052
|
+
const collected = [];
|
|
6053
|
+
for (const field of fields) {
|
|
6054
|
+
if (field.type === "group") {
|
|
6055
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6056
|
+
continue;
|
|
6057
|
+
}
|
|
6058
|
+
if (field.type === "sub-tabs") {
|
|
6059
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6060
|
+
continue;
|
|
6061
|
+
}
|
|
6062
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6063
|
+
}
|
|
6064
|
+
return collected;
|
|
6065
|
+
}
|
|
6066
|
+
/**
|
|
5905
6067
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5906
6068
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5907
6069
|
* envelopes pass through; void stays void.
|
|
@@ -5926,6 +6088,7 @@ var CamStreamKindSchema = _enum([
|
|
|
5926
6088
|
"pull-rtsp",
|
|
5927
6089
|
"pull-rtmp",
|
|
5928
6090
|
"pull-http",
|
|
6091
|
+
"pull-flv",
|
|
5929
6092
|
"pull-rfc4571",
|
|
5930
6093
|
"push-annexb",
|
|
5931
6094
|
"derived"
|
|
@@ -6308,6 +6471,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6308
6471
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6309
6472
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6310
6473
|
DeviceType["Image"] = "image";
|
|
6474
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6475
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6476
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6477
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6478
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6479
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6480
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6311
6481
|
return DeviceType;
|
|
6312
6482
|
}({});
|
|
6313
6483
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7085,7 +7255,21 @@ var StorageLocationDeclarationSchema = object({
|
|
|
7085
7255
|
* slots (e.g. `recordingsLow` → `recordings`) so operators only need to
|
|
7086
7256
|
* configure the primary location.
|
|
7087
7257
|
*/
|
|
7088
|
-
defaultsTo: string().optional()
|
|
7258
|
+
defaultsTo: string().optional(),
|
|
7259
|
+
/**
|
|
7260
|
+
* Which node root the seeded `<id>:default` instance is placed under on a
|
|
7261
|
+
* FRESH install:
|
|
7262
|
+
* - `'data'` (default) — the node's data dir (`CAMSTACK_DATA` / boot dir),
|
|
7263
|
+
* the appData volume. Right for small/durable data (backups, logs, models).
|
|
7264
|
+
* - `'media'` — the dedicated media volume (`CAMSTACK_MEDIA_ROOT`) when that
|
|
7265
|
+
* env is set, else falls back to the data root. Right for bulky, hot media
|
|
7266
|
+
* (recordings, event media) that should stay off the appData disk.
|
|
7267
|
+
*
|
|
7268
|
+
* Only affects the seeded default's `basePath`; operators can repoint any
|
|
7269
|
+
* location afterwards, and a `defaultsTo` slot inherits its parent's root
|
|
7270
|
+
* regardless of this field. Absent (the common case) is treated as `'data'`.
|
|
7271
|
+
*/
|
|
7272
|
+
defaultRoot: _enum(["data", "media"]).optional()
|
|
7089
7273
|
});
|
|
7090
7274
|
var DecoderStatsSchema = object({
|
|
7091
7275
|
inputFps: number(),
|
|
@@ -7458,6 +7642,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7458
7642
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7459
7643
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7460
7644
|
/**
|
|
7645
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7646
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7647
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7648
|
+
*/
|
|
7649
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7650
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7651
|
+
var ExpressionParseError = class extends Error {
|
|
7652
|
+
position;
|
|
7653
|
+
constructor(message, position) {
|
|
7654
|
+
super(message);
|
|
7655
|
+
this.name = "ExpressionParseError";
|
|
7656
|
+
this.position = position;
|
|
7657
|
+
}
|
|
7658
|
+
};
|
|
7659
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7660
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7661
|
+
var ExpressionEvalError = class extends Error {
|
|
7662
|
+
constructor(message) {
|
|
7663
|
+
super(message);
|
|
7664
|
+
this.name = "ExpressionEvalError";
|
|
7665
|
+
}
|
|
7666
|
+
};
|
|
7667
|
+
/**
|
|
7668
|
+
* Resource-bound constants for the safe expression engine.
|
|
7669
|
+
*
|
|
7670
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7671
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7672
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7673
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7674
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7675
|
+
*/
|
|
7676
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7677
|
+
* rejected without allocation. */
|
|
7678
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7679
|
+
/** A legal binding / identifier name. */
|
|
7680
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7681
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7682
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7683
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7684
|
+
"now",
|
|
7685
|
+
"true",
|
|
7686
|
+
"false",
|
|
7687
|
+
"null"
|
|
7688
|
+
]);
|
|
7689
|
+
/**
|
|
7690
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7691
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7692
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7693
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7694
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7695
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7696
|
+
* template literals are lexically impossible.
|
|
7697
|
+
*/
|
|
7698
|
+
var KEYWORDS = new Set([
|
|
7699
|
+
"true",
|
|
7700
|
+
"false",
|
|
7701
|
+
"null"
|
|
7702
|
+
]);
|
|
7703
|
+
function isDigit(ch) {
|
|
7704
|
+
return ch >= "0" && ch <= "9";
|
|
7705
|
+
}
|
|
7706
|
+
function isIdentStart(ch) {
|
|
7707
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7708
|
+
}
|
|
7709
|
+
function isIdentPart(ch) {
|
|
7710
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7711
|
+
}
|
|
7712
|
+
function isWhitespace(ch) {
|
|
7713
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7714
|
+
}
|
|
7715
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7716
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7717
|
+
* string. */
|
|
7718
|
+
function tokenize(source) {
|
|
7719
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7720
|
+
const tokens = [];
|
|
7721
|
+
let i = 0;
|
|
7722
|
+
const n = source.length;
|
|
7723
|
+
while (i < n) {
|
|
7724
|
+
const ch = source[i];
|
|
7725
|
+
if (isWhitespace(ch)) {
|
|
7726
|
+
i += 1;
|
|
7727
|
+
continue;
|
|
7728
|
+
}
|
|
7729
|
+
if (isDigit(ch)) {
|
|
7730
|
+
const start = i;
|
|
7731
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7732
|
+
if (i < n && source[i] === ".") {
|
|
7733
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7734
|
+
i += 1;
|
|
7735
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7736
|
+
}
|
|
7737
|
+
const text = source.slice(start, i);
|
|
7738
|
+
const value = Number(text);
|
|
7739
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7740
|
+
tokens.push({
|
|
7741
|
+
type: "number",
|
|
7742
|
+
value,
|
|
7743
|
+
pos: start
|
|
7744
|
+
});
|
|
7745
|
+
continue;
|
|
7746
|
+
}
|
|
7747
|
+
if (ch === "'" || ch === "\"") {
|
|
7748
|
+
const quote = ch;
|
|
7749
|
+
const start = i;
|
|
7750
|
+
i += 1;
|
|
7751
|
+
let out = "";
|
|
7752
|
+
let closed = false;
|
|
7753
|
+
while (i < n) {
|
|
7754
|
+
const c = source[i];
|
|
7755
|
+
if (c === "\\") {
|
|
7756
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7757
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7758
|
+
out += next;
|
|
7759
|
+
i += 2;
|
|
7760
|
+
continue;
|
|
7761
|
+
}
|
|
7762
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7763
|
+
}
|
|
7764
|
+
if (c === quote) {
|
|
7765
|
+
closed = true;
|
|
7766
|
+
i += 1;
|
|
7767
|
+
break;
|
|
7768
|
+
}
|
|
7769
|
+
out += c;
|
|
7770
|
+
i += 1;
|
|
7771
|
+
}
|
|
7772
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7773
|
+
tokens.push({
|
|
7774
|
+
type: "string",
|
|
7775
|
+
value: out,
|
|
7776
|
+
pos: start
|
|
7777
|
+
});
|
|
7778
|
+
continue;
|
|
7779
|
+
}
|
|
7780
|
+
if (isIdentStart(ch)) {
|
|
7781
|
+
const start = i;
|
|
7782
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7783
|
+
const text = source.slice(start, i);
|
|
7784
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7785
|
+
type: "keyword",
|
|
7786
|
+
keyword: keywordOf(text),
|
|
7787
|
+
pos: start
|
|
7788
|
+
});
|
|
7789
|
+
else tokens.push({
|
|
7790
|
+
type: "identifier",
|
|
7791
|
+
name: text,
|
|
7792
|
+
pos: start
|
|
7793
|
+
});
|
|
7794
|
+
continue;
|
|
7795
|
+
}
|
|
7796
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7797
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7798
|
+
tokens.push({
|
|
7799
|
+
type: "punct",
|
|
7800
|
+
punct: two,
|
|
7801
|
+
pos: i
|
|
7802
|
+
});
|
|
7803
|
+
i += 2;
|
|
7804
|
+
continue;
|
|
7805
|
+
}
|
|
7806
|
+
if (isSinglePunct(ch)) {
|
|
7807
|
+
tokens.push({
|
|
7808
|
+
type: "punct",
|
|
7809
|
+
punct: ch,
|
|
7810
|
+
pos: i
|
|
7811
|
+
});
|
|
7812
|
+
i += 1;
|
|
7813
|
+
continue;
|
|
7814
|
+
}
|
|
7815
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7816
|
+
}
|
|
7817
|
+
tokens.push({
|
|
7818
|
+
type: "eof",
|
|
7819
|
+
pos: n
|
|
7820
|
+
});
|
|
7821
|
+
return tokens;
|
|
7822
|
+
}
|
|
7823
|
+
function keywordOf(text) {
|
|
7824
|
+
if (text === "true") return "true";
|
|
7825
|
+
if (text === "false") return "false";
|
|
7826
|
+
return "null";
|
|
7827
|
+
}
|
|
7828
|
+
function isSinglePunct(ch) {
|
|
7829
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7830
|
+
}
|
|
7831
|
+
/**
|
|
7832
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7833
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7834
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7835
|
+
* own-property check against it.
|
|
7836
|
+
*
|
|
7837
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7838
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7839
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7840
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7841
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7842
|
+
*
|
|
7843
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7844
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7845
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7846
|
+
* closed rather than emitting a garbage value.
|
|
7847
|
+
*/
|
|
7848
|
+
function asFiniteNumber(value, name, index) {
|
|
7849
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7850
|
+
return value;
|
|
7851
|
+
}
|
|
7852
|
+
function asString$1(value, name, index) {
|
|
7853
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7854
|
+
return value;
|
|
7855
|
+
}
|
|
7856
|
+
function finiteResult(value, name) {
|
|
7857
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7858
|
+
return value;
|
|
7859
|
+
}
|
|
7860
|
+
function allFiniteNumbers(args, name) {
|
|
7861
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7862
|
+
}
|
|
7863
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7864
|
+
var table = {
|
|
7865
|
+
min: {
|
|
7866
|
+
minArgs: 1,
|
|
7867
|
+
maxArgs: INF,
|
|
7868
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7869
|
+
},
|
|
7870
|
+
max: {
|
|
7871
|
+
minArgs: 1,
|
|
7872
|
+
maxArgs: INF,
|
|
7873
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7874
|
+
},
|
|
7875
|
+
abs: {
|
|
7876
|
+
minArgs: 1,
|
|
7877
|
+
maxArgs: 1,
|
|
7878
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7879
|
+
},
|
|
7880
|
+
floor: {
|
|
7881
|
+
minArgs: 1,
|
|
7882
|
+
maxArgs: 1,
|
|
7883
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7884
|
+
},
|
|
7885
|
+
ceil: {
|
|
7886
|
+
minArgs: 1,
|
|
7887
|
+
maxArgs: 1,
|
|
7888
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7889
|
+
},
|
|
7890
|
+
sqrt: {
|
|
7891
|
+
minArgs: 1,
|
|
7892
|
+
maxArgs: 1,
|
|
7893
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7894
|
+
},
|
|
7895
|
+
round: {
|
|
7896
|
+
minArgs: 1,
|
|
7897
|
+
maxArgs: 2,
|
|
7898
|
+
apply: (args) => {
|
|
7899
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7900
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7901
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7902
|
+
const factor = 10 ** digits;
|
|
7903
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7904
|
+
}
|
|
7905
|
+
},
|
|
7906
|
+
pow: {
|
|
7907
|
+
minArgs: 2,
|
|
7908
|
+
maxArgs: 2,
|
|
7909
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7910
|
+
},
|
|
7911
|
+
clamp: {
|
|
7912
|
+
minArgs: 3,
|
|
7913
|
+
maxArgs: 3,
|
|
7914
|
+
apply: (args) => {
|
|
7915
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7916
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7917
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7918
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7919
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7920
|
+
}
|
|
7921
|
+
},
|
|
7922
|
+
avg: {
|
|
7923
|
+
minArgs: 1,
|
|
7924
|
+
maxArgs: INF,
|
|
7925
|
+
apply: (args) => {
|
|
7926
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7927
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7928
|
+
}
|
|
7929
|
+
},
|
|
7930
|
+
sum: {
|
|
7931
|
+
minArgs: 1,
|
|
7932
|
+
maxArgs: INF,
|
|
7933
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7934
|
+
},
|
|
7935
|
+
coalesce: {
|
|
7936
|
+
minArgs: 1,
|
|
7937
|
+
maxArgs: INF,
|
|
7938
|
+
apply: (args) => {
|
|
7939
|
+
for (const a of args) if (a !== null) return a;
|
|
7940
|
+
return null;
|
|
7941
|
+
}
|
|
7942
|
+
},
|
|
7943
|
+
age: {
|
|
7944
|
+
minArgs: 2,
|
|
7945
|
+
maxArgs: 2,
|
|
7946
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7947
|
+
},
|
|
7948
|
+
convert: {
|
|
7949
|
+
minArgs: 3,
|
|
7950
|
+
maxArgs: 3,
|
|
7951
|
+
apply: (args, hooks) => {
|
|
7952
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7953
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7954
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7955
|
+
if (hooks.convert) {
|
|
7956
|
+
const out = hooks.convert(x, from, to);
|
|
7957
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7958
|
+
return finiteResult(out, "convert");
|
|
7959
|
+
}
|
|
7960
|
+
if (from === to) return x;
|
|
7961
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7962
|
+
}
|
|
7963
|
+
}
|
|
7964
|
+
};
|
|
7965
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7966
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7967
|
+
* callees at parse time (immediate author feedback). */
|
|
7968
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7969
|
+
/**
|
|
7970
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7971
|
+
*
|
|
7972
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7973
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7974
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7975
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7976
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7977
|
+
* that references a since-removed builtin degrades at read.
|
|
7978
|
+
*
|
|
7979
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7980
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7981
|
+
*/
|
|
7982
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7983
|
+
var BINARY_PRECEDENCE = {
|
|
7984
|
+
"||": 1,
|
|
7985
|
+
"&&": 2,
|
|
7986
|
+
"==": 3,
|
|
7987
|
+
"!=": 3,
|
|
7988
|
+
"<": 4,
|
|
7989
|
+
"<=": 4,
|
|
7990
|
+
">": 4,
|
|
7991
|
+
">=": 4,
|
|
7992
|
+
"+": 5,
|
|
7993
|
+
"-": 5,
|
|
7994
|
+
"*": 6,
|
|
7995
|
+
"/": 6,
|
|
7996
|
+
"%": 6
|
|
7997
|
+
};
|
|
7998
|
+
function isLogicalOp(op) {
|
|
7999
|
+
return op === "&&" || op === "||";
|
|
8000
|
+
}
|
|
8001
|
+
function isBinaryOp(op) {
|
|
8002
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
8003
|
+
}
|
|
8004
|
+
var Parser = class {
|
|
8005
|
+
tokens;
|
|
8006
|
+
pos = 0;
|
|
8007
|
+
nodeCount = 0;
|
|
8008
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
8009
|
+
callees = /* @__PURE__ */ new Set();
|
|
8010
|
+
constructor(tokens) {
|
|
8011
|
+
this.tokens = tokens;
|
|
8012
|
+
}
|
|
8013
|
+
parse() {
|
|
8014
|
+
const ast = this.parseTernary();
|
|
8015
|
+
const tok = this.peek();
|
|
8016
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
8017
|
+
return {
|
|
8018
|
+
ast,
|
|
8019
|
+
identifiers: this.identifiers,
|
|
8020
|
+
callees: this.callees,
|
|
8021
|
+
nodeCount: this.nodeCount
|
|
8022
|
+
};
|
|
8023
|
+
}
|
|
8024
|
+
peek() {
|
|
8025
|
+
return this.tokens[this.pos];
|
|
8026
|
+
}
|
|
8027
|
+
next() {
|
|
8028
|
+
return this.tokens[this.pos++];
|
|
8029
|
+
}
|
|
8030
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8031
|
+
expectPunct(punct) {
|
|
8032
|
+
const tok = this.peek();
|
|
8033
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8034
|
+
this.pos += 1;
|
|
8035
|
+
}
|
|
8036
|
+
matchPunct(punct) {
|
|
8037
|
+
const tok = this.peek();
|
|
8038
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8039
|
+
this.pos += 1;
|
|
8040
|
+
return true;
|
|
8041
|
+
}
|
|
8042
|
+
return false;
|
|
8043
|
+
}
|
|
8044
|
+
countNode() {
|
|
8045
|
+
this.nodeCount += 1;
|
|
8046
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8047
|
+
}
|
|
8048
|
+
parseTernary() {
|
|
8049
|
+
const test = this.parseBinary(1);
|
|
8050
|
+
if (this.matchPunct("?")) {
|
|
8051
|
+
const consequent = this.parseTernary();
|
|
8052
|
+
this.expectPunct(":");
|
|
8053
|
+
const alternate = this.parseTernary();
|
|
8054
|
+
this.countNode();
|
|
8055
|
+
return {
|
|
8056
|
+
kind: "conditional",
|
|
8057
|
+
test,
|
|
8058
|
+
consequent,
|
|
8059
|
+
alternate
|
|
8060
|
+
};
|
|
8061
|
+
}
|
|
8062
|
+
return test;
|
|
8063
|
+
}
|
|
8064
|
+
parseBinary(minPrec) {
|
|
8065
|
+
let left = this.parseUnary();
|
|
8066
|
+
for (;;) {
|
|
8067
|
+
const tok = this.peek();
|
|
8068
|
+
if (tok.type !== "punct") break;
|
|
8069
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8070
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8071
|
+
const op = tok.punct;
|
|
8072
|
+
this.pos += 1;
|
|
8073
|
+
const right = this.parseBinary(prec + 1);
|
|
8074
|
+
this.countNode();
|
|
8075
|
+
if (isLogicalOp(op)) left = {
|
|
8076
|
+
kind: "logical",
|
|
8077
|
+
op,
|
|
8078
|
+
left,
|
|
8079
|
+
right
|
|
8080
|
+
};
|
|
8081
|
+
else if (isBinaryOp(op)) left = {
|
|
8082
|
+
kind: "binary",
|
|
8083
|
+
op,
|
|
8084
|
+
left,
|
|
8085
|
+
right
|
|
8086
|
+
};
|
|
8087
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8088
|
+
}
|
|
8089
|
+
return left;
|
|
8090
|
+
}
|
|
8091
|
+
parseUnary() {
|
|
8092
|
+
const tok = this.peek();
|
|
8093
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8094
|
+
const op = tok.punct;
|
|
8095
|
+
this.pos += 1;
|
|
8096
|
+
const operand = this.parseUnary();
|
|
8097
|
+
this.countNode();
|
|
8098
|
+
return {
|
|
8099
|
+
kind: "unary",
|
|
8100
|
+
op,
|
|
8101
|
+
operand
|
|
8102
|
+
};
|
|
8103
|
+
}
|
|
8104
|
+
return this.parsePrimary();
|
|
8105
|
+
}
|
|
8106
|
+
parsePrimary() {
|
|
8107
|
+
const tok = this.next();
|
|
8108
|
+
switch (tok.type) {
|
|
8109
|
+
case "number":
|
|
8110
|
+
this.countNode();
|
|
8111
|
+
return {
|
|
8112
|
+
kind: "literal",
|
|
8113
|
+
value: tok.value
|
|
8114
|
+
};
|
|
8115
|
+
case "string":
|
|
8116
|
+
this.countNode();
|
|
8117
|
+
return {
|
|
8118
|
+
kind: "literal",
|
|
8119
|
+
value: tok.value
|
|
8120
|
+
};
|
|
8121
|
+
case "keyword":
|
|
8122
|
+
this.countNode();
|
|
8123
|
+
return {
|
|
8124
|
+
kind: "literal",
|
|
8125
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8126
|
+
};
|
|
8127
|
+
case "identifier": {
|
|
8128
|
+
const nextTok = this.peek();
|
|
8129
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8130
|
+
this.identifiers.add(tok.name);
|
|
8131
|
+
this.countNode();
|
|
8132
|
+
return {
|
|
8133
|
+
kind: "identifier",
|
|
8134
|
+
name: tok.name
|
|
8135
|
+
};
|
|
8136
|
+
}
|
|
8137
|
+
case "punct":
|
|
8138
|
+
if (tok.punct === "(") {
|
|
8139
|
+
const inner = this.parseTernary();
|
|
8140
|
+
this.expectPunct(")");
|
|
8141
|
+
return inner;
|
|
8142
|
+
}
|
|
8143
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8144
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8145
|
+
}
|
|
8146
|
+
}
|
|
8147
|
+
parseCall(callee, pos) {
|
|
8148
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8149
|
+
this.expectPunct("(");
|
|
8150
|
+
const args = [];
|
|
8151
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8152
|
+
args.push(this.parseTernary());
|
|
8153
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8154
|
+
if (this.matchPunct(",")) continue;
|
|
8155
|
+
this.expectPunct(")");
|
|
8156
|
+
break;
|
|
8157
|
+
}
|
|
8158
|
+
this.callees.add(callee);
|
|
8159
|
+
this.countNode();
|
|
8160
|
+
return {
|
|
8161
|
+
kind: "call",
|
|
8162
|
+
callee,
|
|
8163
|
+
args
|
|
8164
|
+
};
|
|
8165
|
+
}
|
|
8166
|
+
};
|
|
8167
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8168
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8169
|
+
function parseExpression(source) {
|
|
8170
|
+
return new Parser(tokenize(source)).parse();
|
|
8171
|
+
}
|
|
8172
|
+
Object.freeze({});
|
|
8173
|
+
/**
|
|
8174
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8175
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8176
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8177
|
+
* one per read on a hot resolve path.
|
|
8178
|
+
*
|
|
8179
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8180
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8181
|
+
* callers is safe and maximises hit rate.
|
|
8182
|
+
*/
|
|
8183
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8184
|
+
function getCached(source) {
|
|
8185
|
+
const hit = cache.get(source);
|
|
8186
|
+
if (hit !== void 0) {
|
|
8187
|
+
cache.delete(source);
|
|
8188
|
+
cache.set(source, hit);
|
|
8189
|
+
return hit;
|
|
8190
|
+
}
|
|
8191
|
+
let result;
|
|
8192
|
+
try {
|
|
8193
|
+
result = {
|
|
8194
|
+
ok: true,
|
|
8195
|
+
parsed: parseExpression(source)
|
|
8196
|
+
};
|
|
8197
|
+
} catch (err) {
|
|
8198
|
+
result = {
|
|
8199
|
+
ok: false,
|
|
8200
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8201
|
+
};
|
|
8202
|
+
}
|
|
8203
|
+
cache.set(source, result);
|
|
8204
|
+
if (cache.size > 256) {
|
|
8205
|
+
const oldest = cache.keys().next().value;
|
|
8206
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8207
|
+
}
|
|
8208
|
+
return result;
|
|
8209
|
+
}
|
|
8210
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8211
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8212
|
+
function compileExpressionSafe(source) {
|
|
8213
|
+
return getCached(source);
|
|
8214
|
+
}
|
|
8215
|
+
/**
|
|
8216
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8217
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8218
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8219
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8220
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8221
|
+
*/
|
|
8222
|
+
function validateExpressionSource(src) {
|
|
8223
|
+
const names = Object.keys(src.bindings);
|
|
8224
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8225
|
+
for (const name of names) {
|
|
8226
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8227
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8228
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8229
|
+
}
|
|
8230
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8231
|
+
if (!compiled.ok) return compiled.error;
|
|
8232
|
+
const bound = new Set(names);
|
|
8233
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8234
|
+
if (id === "now") continue;
|
|
8235
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8236
|
+
}
|
|
8237
|
+
return null;
|
|
8238
|
+
}
|
|
8239
|
+
/**
|
|
7461
8240
|
* Accessory device helpers — shared across drivers.
|
|
7462
8241
|
*
|
|
7463
8242
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -8302,7 +9081,13 @@ onStatusChanged: { data: object({
|
|
|
8302
9081
|
}) } },
|
|
8303
9082
|
status: {
|
|
8304
9083
|
schema: BatteryStatusSchema,
|
|
8305
|
-
kind: "push"
|
|
9084
|
+
kind: "push",
|
|
9085
|
+
empty: {
|
|
9086
|
+
percentage: 0,
|
|
9087
|
+
charging: "none",
|
|
9088
|
+
sleeping: false,
|
|
9089
|
+
lastUpdated: 0
|
|
9090
|
+
}
|
|
8306
9091
|
},
|
|
8307
9092
|
/**
|
|
8308
9093
|
* Runtime-state slice — every provider that registers this cap
|
|
@@ -8441,6 +9226,10 @@ var RtspRestreamEntrySchema = object({
|
|
|
8441
9226
|
var BrokerRtspClientSchema = object({
|
|
8442
9227
|
sessionId: string(),
|
|
8443
9228
|
remoteAddr: string(),
|
|
9229
|
+
/** Client `User-Agent` (e.g. `recorder` for the recorder's RTSP pull), or
|
|
9230
|
+
* null/absent when the client sent none. Lets the UI label a consumer by
|
|
9231
|
+
* purpose. Optional so a client built against an older schema stays valid. */
|
|
9232
|
+
userAgent: string().nullish(),
|
|
8444
9233
|
playing: boolean(),
|
|
8445
9234
|
muted: boolean(),
|
|
8446
9235
|
connectedAt: number(),
|
|
@@ -9241,21 +10030,38 @@ var connectivityCapability = {
|
|
|
9241
10030
|
},
|
|
9242
10031
|
runtimeState: ConnectivityStatusSchema
|
|
9243
10032
|
};
|
|
10033
|
+
/**
|
|
10034
|
+
* Generic device-consumables capability — surfaces a device's
|
|
10035
|
+
* maintenance items (vacuum filters/brushes, replaceable cartridges,
|
|
10036
|
+
* descaling cycles, …) with their remaining life and an optional
|
|
10037
|
+
* "Replaced" reset action. Device-agnostic: any provider that knows its
|
|
10038
|
+
* device tracks consumables can register it; the cap declares no
|
|
10039
|
+
* vocabulary of its own — the provider names each item verbatim.
|
|
10040
|
+
*
|
|
10041
|
+
* Like `childLayout`, the cap is INERT until a provider sets items: no
|
|
10042
|
+
* provider populates it by guessing (no HA inference). The UI renders a
|
|
10043
|
+
* "No consumables reported" placeholder when `items` is empty.
|
|
10044
|
+
*/
|
|
10045
|
+
/** A single consumable item. Either a continuous `level` (remaining
|
|
10046
|
+
* life %) or a discrete `status` may be known — both may be null when a
|
|
10047
|
+
* provider only knows the item exists. `level` and `status` are not
|
|
10048
|
+
* mutually exclusive; a provider may report both. */
|
|
10049
|
+
var ConsumableItemSchema = object({
|
|
10050
|
+
/** Stable id, e.g. 'main-brush'. */
|
|
10051
|
+
key: string().min(1),
|
|
10052
|
+
/** Display name. */
|
|
10053
|
+
label: string().min(1),
|
|
10054
|
+
/** Remaining life % when known (0..100). */
|
|
10055
|
+
level: number().min(0).max(100).nullable(),
|
|
10056
|
+
/** Discrete state when known (binary mode). */
|
|
10057
|
+
status: _enum(["ok", "replace"]).nullable(),
|
|
10058
|
+
/** Ms epoch of the last replace, when known. */
|
|
10059
|
+
lastResetAt: number().nullable(),
|
|
10060
|
+
/** Whether `reset()` is meaningful for this item. */
|
|
10061
|
+
resettable: boolean()
|
|
10062
|
+
});
|
|
9244
10063
|
var ConsumablesStatusSchema = object({
|
|
9245
|
-
items: array(
|
|
9246
|
-
/** Stable id, e.g. 'main-brush'. */
|
|
9247
|
-
key: string().min(1),
|
|
9248
|
-
/** Display name. */
|
|
9249
|
-
label: string().min(1),
|
|
9250
|
-
/** Remaining life % when known (0..100). */
|
|
9251
|
-
level: number().min(0).max(100).nullable(),
|
|
9252
|
-
/** Discrete state when known (binary mode). */
|
|
9253
|
-
status: _enum(["ok", "replace"]).nullable(),
|
|
9254
|
-
/** Ms epoch of the last replace, when known. */
|
|
9255
|
-
lastResetAt: number().nullable(),
|
|
9256
|
-
/** Whether `reset()` is meaningful for this item. */
|
|
9257
|
-
resettable: boolean()
|
|
9258
|
-
})),
|
|
10064
|
+
items: array(ConsumableItemSchema),
|
|
9259
10065
|
lastChangedAt: number()
|
|
9260
10066
|
});
|
|
9261
10067
|
var consumablesCapability = {
|
|
@@ -9314,7 +10120,25 @@ reset: method(object({
|
|
|
9314
10120
|
}) },
|
|
9315
10121
|
status: {
|
|
9316
10122
|
schema: ConsumablesStatusSchema,
|
|
9317
|
-
kind: "push"
|
|
10123
|
+
kind: "push",
|
|
10124
|
+
empty: {
|
|
10125
|
+
items: [],
|
|
10126
|
+
lastChangedAt: 0
|
|
10127
|
+
},
|
|
10128
|
+
itemArray: {
|
|
10129
|
+
path: "items",
|
|
10130
|
+
keyField: "key",
|
|
10131
|
+
labelField: "label",
|
|
10132
|
+
itemSchema: ConsumableItemSchema,
|
|
10133
|
+
emptyItem: {
|
|
10134
|
+
key: "",
|
|
10135
|
+
label: "",
|
|
10136
|
+
level: null,
|
|
10137
|
+
status: null,
|
|
10138
|
+
lastResetAt: null,
|
|
10139
|
+
resettable: false
|
|
10140
|
+
}
|
|
10141
|
+
}
|
|
9318
10142
|
},
|
|
9319
10143
|
runtimeState: ConsumablesStatusSchema.extend({ lastFetchedAt: number() })
|
|
9320
10144
|
};
|
|
@@ -10556,7 +11380,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
10556
11380
|
});
|
|
10557
11381
|
method(object({
|
|
10558
11382
|
deviceId: number(),
|
|
10559
|
-
frame: FrameInputSchema
|
|
11383
|
+
frame: FrameInputSchema.optional(),
|
|
11384
|
+
frameHandle: FrameHandleSchema.optional()
|
|
10560
11385
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
10561
11386
|
deviceId: number(),
|
|
10562
11387
|
detected: boolean(),
|
|
@@ -10803,6 +11628,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
10803
11628
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
10804
11629
|
steps: array(PipelineStepInputSchema).min(1),
|
|
10805
11630
|
frame: FrameInputSchema.optional(),
|
|
11631
|
+
/**
|
|
11632
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
11633
|
+
* the decoded pixels live in. One more member of the one-of
|
|
11634
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
11635
|
+
*/
|
|
11636
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
10806
11637
|
imageBase64: string().optional(),
|
|
10807
11638
|
/**
|
|
10808
11639
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -11045,6 +11876,31 @@ var ReportMotionInputSchema = object({
|
|
|
11045
11876
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
11046
11877
|
});
|
|
11047
11878
|
/**
|
|
11879
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
11880
|
+
* restream-owner model — P2c).
|
|
11881
|
+
*
|
|
11882
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
11883
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
11884
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
11885
|
+
* behavior change.
|
|
11886
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
11887
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
11888
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
11889
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
11890
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
11891
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
11892
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
11893
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
11894
|
+
* dials for the owner's restream.
|
|
11895
|
+
*/
|
|
11896
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
11897
|
+
kind: literal("remote-restream"),
|
|
11898
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
11899
|
+
ownerNodeId: string(),
|
|
11900
|
+
/** Operator override for the owner host the runner dials. */
|
|
11901
|
+
hubHostnameOverride: string().optional()
|
|
11902
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
11903
|
+
/**
|
|
11048
11904
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
11049
11905
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
11050
11906
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -11142,7 +11998,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
11142
11998
|
*/
|
|
11143
11999
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
11144
12000
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
11145
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
12001
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
12002
|
+
/**
|
|
12003
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
12004
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
12005
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
12006
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
12007
|
+
* `remoteSourcingNodes` rollout setting).
|
|
12008
|
+
*/
|
|
12009
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
11146
12010
|
});
|
|
11147
12011
|
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;
|
|
11148
12012
|
/**
|
|
@@ -11706,6 +12570,157 @@ var numericSensorCapability = {
|
|
|
11706
12570
|
runtimeState: NumericSensorStatusSchema
|
|
11707
12571
|
};
|
|
11708
12572
|
/**
|
|
12573
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
12574
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
12575
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
12576
|
+
*/
|
|
12577
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
12578
|
+
"normal",
|
|
12579
|
+
"offline",
|
|
12580
|
+
"on_batteries"
|
|
12581
|
+
]);
|
|
12582
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
12583
|
+
var PetFeederStatusSchema = object({
|
|
12584
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
12585
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
12586
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
12587
|
+
foodLevel: number().nullable(),
|
|
12588
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
12589
|
+
* single-hopper models. */
|
|
12590
|
+
food1: number().nullable(),
|
|
12591
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
12592
|
+
* single-hopper models. */
|
|
12593
|
+
food2: number().nullable(),
|
|
12594
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
12595
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
12596
|
+
* below the feeder's low threshold. */
|
|
12597
|
+
lowFood: boolean(),
|
|
12598
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
12599
|
+
* device has no battery reading. */
|
|
12600
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
12601
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
12602
|
+
* desiccant sensor. */
|
|
12603
|
+
desiccantLeftDays: number().nullable(),
|
|
12604
|
+
/** True while a feed is in progress. */
|
|
12605
|
+
feeding: boolean(),
|
|
12606
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
12607
|
+
* Null until the device has reported a status. */
|
|
12608
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
12609
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
12610
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
12611
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
12612
|
+
error: string().nullable(),
|
|
12613
|
+
/** Raw device error code (0 / null = no error). */
|
|
12614
|
+
errorCode: number().nullable(),
|
|
12615
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
12616
|
+
isDualHopper: boolean(),
|
|
12617
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
12618
|
+
childLock: boolean(),
|
|
12619
|
+
/** Front indicator-light setting. */
|
|
12620
|
+
indicatorLight: boolean(),
|
|
12621
|
+
/** Play a chime when dispensing. */
|
|
12622
|
+
feedSound: boolean(),
|
|
12623
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
12624
|
+
volume: number(),
|
|
12625
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
12626
|
+
lastFetchedAt: number()
|
|
12627
|
+
});
|
|
12628
|
+
var petFeederCapability = {
|
|
12629
|
+
name: "pet-feeder",
|
|
12630
|
+
scope: "device",
|
|
12631
|
+
deviceNative: true,
|
|
12632
|
+
mode: "singleton",
|
|
12633
|
+
deviceTypes: [DeviceType.PetFeeder],
|
|
12634
|
+
methods: {
|
|
12635
|
+
/**
|
|
12636
|
+
* Dispense food now. Single-hopper feeders take `grams`; dual-hopper
|
|
12637
|
+
* feeders (D4S/D4SH) accept `hopper1`/`hopper2` to target one or both
|
|
12638
|
+
* hoppers. All portions honour the 4–200 g hardware range. At least
|
|
12639
|
+
* one of the three must be present — the provider rejects an empty
|
|
12640
|
+
* request.
|
|
12641
|
+
*/
|
|
12642
|
+
feed: method(object({
|
|
12643
|
+
deviceId: number().int().nonnegative(),
|
|
12644
|
+
grams: gramsPortion.optional(),
|
|
12645
|
+
hopper1: gramsPortion.optional(),
|
|
12646
|
+
hopper2: gramsPortion.optional()
|
|
12647
|
+
}), _void(), {
|
|
12648
|
+
kind: "mutation",
|
|
12649
|
+
auth: "admin"
|
|
12650
|
+
}),
|
|
12651
|
+
/** Cancel an in-progress manual feed. */
|
|
12652
|
+
cancelFeed: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12653
|
+
kind: "mutation",
|
|
12654
|
+
auth: "admin"
|
|
12655
|
+
}),
|
|
12656
|
+
/** Reset the desiccant "days remaining" counter after replacing it. */
|
|
12657
|
+
resetDesiccant: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12658
|
+
kind: "mutation",
|
|
12659
|
+
auth: "admin"
|
|
12660
|
+
}),
|
|
12661
|
+
/** Mark a hopper as refilled (D4H/D4S/D4SH). */
|
|
12662
|
+
markFoodReplenished: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12663
|
+
kind: "mutation",
|
|
12664
|
+
auth: "admin"
|
|
12665
|
+
}),
|
|
12666
|
+
/** Call the pet with the recorded prompt (D3). */
|
|
12667
|
+
callPet: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12668
|
+
kind: "mutation",
|
|
12669
|
+
auth: "admin"
|
|
12670
|
+
}),
|
|
12671
|
+
/** Play a stored sound by id (D3 / D4H / D4SH). */
|
|
12672
|
+
playSound: method(object({
|
|
12673
|
+
deviceId: number().int().nonnegative(),
|
|
12674
|
+
soundId: number().int().nonnegative()
|
|
12675
|
+
}), _void(), {
|
|
12676
|
+
kind: "mutation",
|
|
12677
|
+
auth: "admin"
|
|
12678
|
+
}),
|
|
12679
|
+
/** Toggle the child-lock (manual-lock) setting. */
|
|
12680
|
+
setChildLock: method(object({
|
|
12681
|
+
deviceId: number().int().nonnegative(),
|
|
12682
|
+
on: boolean()
|
|
12683
|
+
}), _void(), {
|
|
12684
|
+
kind: "mutation",
|
|
12685
|
+
auth: "admin"
|
|
12686
|
+
}),
|
|
12687
|
+
/** Toggle the front indicator light. */
|
|
12688
|
+
setIndicatorLight: method(object({
|
|
12689
|
+
deviceId: number().int().nonnegative(),
|
|
12690
|
+
on: boolean()
|
|
12691
|
+
}), _void(), {
|
|
12692
|
+
kind: "mutation",
|
|
12693
|
+
auth: "admin"
|
|
12694
|
+
}),
|
|
12695
|
+
/** Toggle the dispense chime. */
|
|
12696
|
+
setFeedSound: method(object({
|
|
12697
|
+
deviceId: number().int().nonnegative(),
|
|
12698
|
+
on: boolean()
|
|
12699
|
+
}), _void(), {
|
|
12700
|
+
kind: "mutation",
|
|
12701
|
+
auth: "admin"
|
|
12702
|
+
}),
|
|
12703
|
+
/** Set the speaker / prompt volume level. */
|
|
12704
|
+
setVolume: method(object({
|
|
12705
|
+
deviceId: number().int().nonnegative(),
|
|
12706
|
+
level: number().int().nonnegative()
|
|
12707
|
+
}), _void(), {
|
|
12708
|
+
kind: "mutation",
|
|
12709
|
+
auth: "admin"
|
|
12710
|
+
})
|
|
12711
|
+
},
|
|
12712
|
+
status: {
|
|
12713
|
+
schema: PetFeederStatusSchema,
|
|
12714
|
+
kind: "poll"
|
|
12715
|
+
},
|
|
12716
|
+
/**
|
|
12717
|
+
* Runtime-state slice — mirrored by the kernel. UI feeder cards read
|
|
12718
|
+
* the full slice via `device.state.petFeeder.value` and refresh on
|
|
12719
|
+
* every poll without re-querying the provider.
|
|
12720
|
+
*/
|
|
12721
|
+
runtimeState: PetFeederStatusSchema
|
|
12722
|
+
};
|
|
12723
|
+
/**
|
|
11709
12724
|
* Multi-metric electrical meter. One slice can carry any combination
|
|
11710
12725
|
* of instantaneous power (W), cumulative energy (kWh), voltage (V),
|
|
11711
12726
|
* and current (A) — all fields optional so a single-metric source
|
|
@@ -13008,6 +14023,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
|
|
|
13008
14023
|
nativeObjectDetection: nativeObjectDetectionCapability,
|
|
13009
14024
|
notifier: notifierCapability,
|
|
13010
14025
|
numericSensor: numericSensorCapability,
|
|
14026
|
+
petFeeder: petFeederCapability,
|
|
13011
14027
|
powerMeter: powerMeterCapability,
|
|
13012
14028
|
presence: presenceCapability,
|
|
13013
14029
|
pressureSensor: pressureSensorCapability,
|
|
@@ -14924,10 +15940,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
14924
15940
|
url: string()
|
|
14925
15941
|
}), _void()), method(object({
|
|
14926
15942
|
sessionId: string(),
|
|
14927
|
-
maxCount: number().default(1)
|
|
15943
|
+
maxCount: number().default(1),
|
|
15944
|
+
waitMs: number().optional()
|
|
14928
15945
|
}), array(DecodedFrameSchema)), method(object({
|
|
14929
15946
|
sessionId: string(),
|
|
14930
|
-
maxCount: number().default(1)
|
|
15947
|
+
maxCount: number().default(1),
|
|
15948
|
+
waitMs: number().optional()
|
|
14931
15949
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
14932
15950
|
sessionId: string(),
|
|
14933
15951
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -15231,14 +16249,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
15231
16249
|
collapsed: boolean().optional()
|
|
15232
16250
|
});
|
|
15233
16251
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
15234
|
-
* `device-management.ts`.
|
|
16252
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
16253
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
16254
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
16255
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
16256
|
+
* source device's full re-sync-stable `stableId`. */
|
|
16257
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
16258
|
+
kind: literal("field").optional(),
|
|
16259
|
+
sourceKey: string(),
|
|
16260
|
+
cap: string(),
|
|
16261
|
+
fieldPath: string()
|
|
16262
|
+
});
|
|
16263
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
16264
|
+
kind: literal("literal"),
|
|
16265
|
+
value: union([
|
|
16266
|
+
string(),
|
|
16267
|
+
number(),
|
|
16268
|
+
boolean(),
|
|
16269
|
+
_null()
|
|
16270
|
+
])
|
|
16271
|
+
});
|
|
16272
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
16273
|
+
kind: literal("global"),
|
|
16274
|
+
sourceStableId: string(),
|
|
16275
|
+
cap: string(),
|
|
16276
|
+
fieldPath: string()
|
|
16277
|
+
});
|
|
16278
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
16279
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
16280
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
16281
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
16282
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
16283
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
16284
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
16285
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
16286
|
+
kind: literal("expression"),
|
|
16287
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
16288
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
16289
|
+
DeviceLinkFieldSourceSchema,
|
|
16290
|
+
DeviceLinkLiteralSourceSchema,
|
|
16291
|
+
DeviceLinkGlobalSourceSchema
|
|
16292
|
+
]))
|
|
16293
|
+
}).superRefine((src, ctx) => {
|
|
16294
|
+
const err = validateExpressionSource(src);
|
|
16295
|
+
if (err !== null) ctx.addIssue({
|
|
16296
|
+
code: "custom",
|
|
16297
|
+
message: err,
|
|
16298
|
+
path: ["expr"]
|
|
16299
|
+
});
|
|
16300
|
+
});
|
|
15235
16301
|
var DeviceLinkSchema = object({
|
|
15236
16302
|
id: string(),
|
|
15237
|
-
source:
|
|
15238
|
-
|
|
15239
|
-
|
|
15240
|
-
|
|
15241
|
-
|
|
16303
|
+
source: union([
|
|
16304
|
+
DeviceLinkFieldSourceSchema,
|
|
16305
|
+
DeviceLinkLiteralSourceSchema,
|
|
16306
|
+
DeviceLinkGlobalSourceSchema,
|
|
16307
|
+
DeviceLinkExpressionSourceSchema
|
|
16308
|
+
]),
|
|
15242
16309
|
target: object({
|
|
15243
16310
|
cap: string(),
|
|
15244
16311
|
fieldPath: string(),
|
|
@@ -15267,6 +16334,31 @@ var DeviceLinkSchema = object({
|
|
|
15267
16334
|
})
|
|
15268
16335
|
]).optional()
|
|
15269
16336
|
});
|
|
16337
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
16338
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
16339
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
16340
|
+
unit: string().min(1).optional(),
|
|
16341
|
+
precision: number().int().min(0).max(10).optional()
|
|
16342
|
+
});
|
|
16343
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
16344
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
16345
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
16346
|
+
var DeviceDisplayOverrideSchema = object({
|
|
16347
|
+
icon: string().min(1).optional(),
|
|
16348
|
+
label: string().min(1).optional(),
|
|
16349
|
+
unit: string().min(1).optional(),
|
|
16350
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16351
|
+
hidden: boolean().optional(),
|
|
16352
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
16353
|
+
});
|
|
16354
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
16355
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
16356
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
16357
|
+
var RoleDisplayDefaultSchema = object({
|
|
16358
|
+
unit: string().min(1).optional(),
|
|
16359
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16360
|
+
icon: string().min(1).optional()
|
|
16361
|
+
});
|
|
15270
16362
|
/**
|
|
15271
16363
|
* Serializable projection of a live IDevice.
|
|
15272
16364
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -15322,7 +16414,9 @@ var DeviceInfoSchema = object({
|
|
|
15322
16414
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
15323
16415
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
15324
16416
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
15325
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
16417
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
16418
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16419
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15326
16420
|
});
|
|
15327
16421
|
var ConfigEntrySchema = object({
|
|
15328
16422
|
key: string(),
|
|
@@ -15387,7 +16481,9 @@ var DeviceMetaSchema = object({
|
|
|
15387
16481
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
15388
16482
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
15389
16483
|
* Optional: only present for accessory children that carry a known role. */
|
|
15390
|
-
role: string().nullable().optional()
|
|
16484
|
+
role: string().nullable().optional(),
|
|
16485
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16486
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15391
16487
|
});
|
|
15392
16488
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
15393
16489
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -15481,7 +16577,19 @@ method(object({
|
|
|
15481
16577
|
}), _void(), {
|
|
15482
16578
|
kind: "mutation",
|
|
15483
16579
|
auth: "admin"
|
|
15484
|
-
}), method(object({
|
|
16580
|
+
}), method(object({
|
|
16581
|
+
deviceId: number(),
|
|
16582
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
16583
|
+
}), _void(), {
|
|
16584
|
+
kind: "mutation",
|
|
16585
|
+
auth: "admin"
|
|
16586
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
16587
|
+
kind: "mutation",
|
|
16588
|
+
auth: "admin"
|
|
16589
|
+
}), method(object({
|
|
16590
|
+
deviceId: number(),
|
|
16591
|
+
includeSynthesizable: boolean().optional()
|
|
16592
|
+
}), object({ caps: array(object({
|
|
15485
16593
|
cap: string(),
|
|
15486
16594
|
fields: array(object({
|
|
15487
16595
|
path: string(),
|
|
@@ -15491,8 +16599,13 @@ method(object({
|
|
|
15491
16599
|
"boolean",
|
|
15492
16600
|
"enum"
|
|
15493
16601
|
]),
|
|
15494
|
-
enumValues: array(string()).optional()
|
|
15495
|
-
|
|
16602
|
+
enumValues: array(string()).optional(),
|
|
16603
|
+
item: boolean().optional()
|
|
16604
|
+
})).readonly(),
|
|
16605
|
+
itemArray: object({
|
|
16606
|
+
path: string(),
|
|
16607
|
+
keyField: string()
|
|
16608
|
+
}).optional()
|
|
15496
16609
|
})).readonly() }), { kind: "query" }), method(object({
|
|
15497
16610
|
deviceId: number(),
|
|
15498
16611
|
role: string().nullable()
|
|
@@ -15562,7 +16675,11 @@ method(object({
|
|
|
15562
16675
|
deviceId: number(),
|
|
15563
16676
|
entries: array(object({
|
|
15564
16677
|
capName: string(),
|
|
15565
|
-
kind: _enum([
|
|
16678
|
+
kind: _enum([
|
|
16679
|
+
"native",
|
|
16680
|
+
"wrapped",
|
|
16681
|
+
"linked"
|
|
16682
|
+
]),
|
|
15566
16683
|
providerAddonId: string(),
|
|
15567
16684
|
providerNodeId: string(),
|
|
15568
16685
|
nativeAddonId: string()
|
|
@@ -15571,7 +16688,11 @@ method(object({
|
|
|
15571
16688
|
deviceId: number(),
|
|
15572
16689
|
entries: array(object({
|
|
15573
16690
|
capName: string(),
|
|
15574
|
-
kind: _enum([
|
|
16691
|
+
kind: _enum([
|
|
16692
|
+
"native",
|
|
16693
|
+
"wrapped",
|
|
16694
|
+
"linked"
|
|
16695
|
+
]),
|
|
15575
16696
|
providerAddonId: string(),
|
|
15576
16697
|
providerNodeId: string(),
|
|
15577
16698
|
nativeAddonId: string()
|
|
@@ -16061,7 +17182,7 @@ var AddBrokerInputSchema = object({
|
|
|
16061
17182
|
});
|
|
16062
17183
|
var AddBrokerResultSchema = object({ id: string() });
|
|
16063
17184
|
var IdInputSchema = object({ id: string() });
|
|
16064
|
-
var TestResultSchema = discriminatedUnion("ok", [object({
|
|
17185
|
+
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
16065
17186
|
ok: literal(true),
|
|
16066
17187
|
latencyMs: number()
|
|
16067
17188
|
}), object({
|
|
@@ -16084,7 +17205,7 @@ var StatusSchema = object({
|
|
|
16084
17205
|
brokerCount: number(),
|
|
16085
17206
|
embeddedRunning: boolean()
|
|
16086
17207
|
});
|
|
16087
|
-
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);
|
|
17208
|
+
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);
|
|
16088
17209
|
var NetworkEndpointSchema = object({
|
|
16089
17210
|
url: string(),
|
|
16090
17211
|
hostname: string(),
|
|
@@ -16118,23 +17239,198 @@ var NetworkEndpointEntrySchema = NetworkEndpointSchema.extend({
|
|
|
16118
17239
|
sourcePort: number().optional()
|
|
16119
17240
|
});
|
|
16120
17241
|
method(_void(), NetworkEndpointSchema, { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), method(_void(), NetworkEndpointSchema.nullable()), method(_void(), NetworkAccessStatusSchema), method(_void(), array(NetworkEndpointEntrySchema).readonly());
|
|
16121
|
-
|
|
16122
|
-
|
|
17242
|
+
/**
|
|
17243
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
17244
|
+
*
|
|
17245
|
+
* Apprise-derived model (see
|
|
17246
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
17247
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
17248
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
17249
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
17250
|
+
* message to what the kind supports — callers never special-case a service.
|
|
17251
|
+
*
|
|
17252
|
+
* DESIGN DECISIONS (locked):
|
|
17253
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
17254
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
17255
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
17256
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
17257
|
+
* alternative would fork the UI per addon and cannot host the
|
|
17258
|
+
* discovery→adopt flow.
|
|
17259
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
17260
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
17261
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
17262
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
17263
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
17264
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
17265
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
17266
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
17267
|
+
* base64 fallback needed.
|
|
17268
|
+
*
|
|
17269
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
17270
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
17271
|
+
* admin "Integrations" page.
|
|
17272
|
+
*/
|
|
17273
|
+
/**
|
|
17274
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
17275
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
17276
|
+
*/
|
|
17277
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
17278
|
+
"image",
|
|
17279
|
+
"video",
|
|
17280
|
+
"gif",
|
|
17281
|
+
"audio",
|
|
17282
|
+
"icon"
|
|
17283
|
+
]);
|
|
17284
|
+
/**
|
|
17285
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
17286
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
17287
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
17288
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
17289
|
+
*/
|
|
17290
|
+
var AttachmentSchema = object({
|
|
17291
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
17292
|
+
url: string().optional(),
|
|
17293
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
17294
|
+
mime: string().optional(),
|
|
17295
|
+
name: string().optional()
|
|
17296
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
17297
|
+
var NotificationFormatSchema = _enum([
|
|
17298
|
+
"text",
|
|
17299
|
+
"markdown",
|
|
17300
|
+
"html"
|
|
17301
|
+
]);
|
|
17302
|
+
/** A single tap-through action button. */
|
|
17303
|
+
var NotificationActionSchema = object({
|
|
17304
|
+
id: string(),
|
|
17305
|
+
label: string(),
|
|
17306
|
+
url: string().optional()
|
|
17307
|
+
});
|
|
17308
|
+
/**
|
|
17309
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
17310
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
17311
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
17312
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
17313
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
17314
|
+
* `priority` for that one target.
|
|
17315
|
+
*/
|
|
17316
|
+
var NotificationSchema = object({
|
|
16123
17317
|
body: string(),
|
|
16124
|
-
|
|
17318
|
+
title: string().optional(),
|
|
17319
|
+
format: NotificationFormatSchema.default("text"),
|
|
17320
|
+
priority: number().int().min(1).max(5).default(3),
|
|
17321
|
+
level: string().optional(),
|
|
17322
|
+
attachments: array(AttachmentSchema).optional(),
|
|
17323
|
+
clickUrl: string().optional(),
|
|
17324
|
+
actions: array(NotificationActionSchema).optional(),
|
|
17325
|
+
sound: string().optional(),
|
|
17326
|
+
ttl: number().optional(),
|
|
17327
|
+
tag: string().optional(),
|
|
16125
17328
|
deviceId: number().optional(),
|
|
16126
17329
|
eventId: string().optional(),
|
|
16127
|
-
priority: _enum([
|
|
16128
|
-
"low",
|
|
16129
|
-
"normal",
|
|
16130
|
-
"high",
|
|
16131
|
-
"critical"
|
|
16132
|
-
]).default("normal"),
|
|
16133
17330
|
metadata: record(string(), unknown()).optional()
|
|
16134
|
-
})
|
|
17331
|
+
});
|
|
17332
|
+
/** One declared native severity/priority level for a kind. */
|
|
17333
|
+
var TargetKindLevelSchema = object({
|
|
17334
|
+
id: string(),
|
|
17335
|
+
label: string(),
|
|
17336
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
17337
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
17338
|
+
flags: object({
|
|
17339
|
+
critical: boolean().optional(),
|
|
17340
|
+
silent: boolean().optional(),
|
|
17341
|
+
noPush: boolean().optional()
|
|
17342
|
+
}).optional(),
|
|
17343
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
17344
|
+
requires: array(string()).optional(),
|
|
17345
|
+
description: string().optional()
|
|
17346
|
+
});
|
|
17347
|
+
/** The full capability block consulted before dispatch. */
|
|
17348
|
+
var TargetKindCapsSchema = object({
|
|
17349
|
+
attachments: object({
|
|
17350
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
17351
|
+
mode: _enum([
|
|
17352
|
+
"url",
|
|
17353
|
+
"bytes",
|
|
17354
|
+
"both"
|
|
17355
|
+
]),
|
|
17356
|
+
max: number().int().nonnegative(),
|
|
17357
|
+
maxBytes: number().int().positive().optional()
|
|
17358
|
+
}),
|
|
17359
|
+
/** Max action buttons (0 = none). */
|
|
17360
|
+
actions: number().int().nonnegative(),
|
|
17361
|
+
levels: array(TargetKindLevelSchema),
|
|
17362
|
+
format: array(NotificationFormatSchema),
|
|
17363
|
+
clickUrl: boolean(),
|
|
17364
|
+
sound: boolean(),
|
|
17365
|
+
ttl: boolean(),
|
|
17366
|
+
bodyMaxLen: number().int().positive()
|
|
17367
|
+
});
|
|
17368
|
+
/**
|
|
17369
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
17370
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
17371
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
17372
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
17373
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
17374
|
+
*/
|
|
17375
|
+
var ConfigSchemaPassthrough = unknown();
|
|
17376
|
+
var TargetKindSchema = object({
|
|
17377
|
+
kind: string(),
|
|
17378
|
+
label: string(),
|
|
17379
|
+
icon: string(),
|
|
17380
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
17381
|
+
addonId: string(),
|
|
17382
|
+
configSchema: ConfigSchemaPassthrough,
|
|
17383
|
+
supportsDiscovery: boolean(),
|
|
17384
|
+
caps: TargetKindCapsSchema
|
|
17385
|
+
});
|
|
17386
|
+
/**
|
|
17387
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
17388
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
17389
|
+
* round-trip a stored secret to the UI.
|
|
17390
|
+
*/
|
|
17391
|
+
var TargetSchema = object({
|
|
17392
|
+
id: string(),
|
|
17393
|
+
name: string(),
|
|
17394
|
+
kind: string(),
|
|
17395
|
+
addonId: string(),
|
|
17396
|
+
enabled: boolean(),
|
|
17397
|
+
config: record(string(), unknown())
|
|
17398
|
+
});
|
|
17399
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
17400
|
+
var DiscoveredTargetSchema = object({
|
|
17401
|
+
kind: string(),
|
|
17402
|
+
suggestedName: string(),
|
|
17403
|
+
config: record(string(), unknown())
|
|
17404
|
+
});
|
|
17405
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
17406
|
+
var RenderedAsSchema = object({
|
|
17407
|
+
level: string(),
|
|
17408
|
+
format: NotificationFormatSchema,
|
|
17409
|
+
attachmentsSent: number().int().nonnegative(),
|
|
17410
|
+
actionsSent: number().int().nonnegative(),
|
|
17411
|
+
truncated: boolean(),
|
|
17412
|
+
dropped: array(string())
|
|
17413
|
+
});
|
|
17414
|
+
var SendResultSchema = object({
|
|
16135
17415
|
success: boolean(),
|
|
16136
|
-
error: string().optional()
|
|
16137
|
-
|
|
17416
|
+
error: string().optional(),
|
|
17417
|
+
renderedAs: RenderedAsSchema.optional()
|
|
17418
|
+
});
|
|
17419
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
17420
|
+
var TestResultSchema = SendResultSchema;
|
|
17421
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema)), method(object({
|
|
17422
|
+
kind: string(),
|
|
17423
|
+
config: record(string(), unknown()).optional()
|
|
17424
|
+
}), array(DiscoveredTargetSchema)), method(object({
|
|
17425
|
+
targetId: string(),
|
|
17426
|
+
notification: NotificationSchema
|
|
17427
|
+
}), SendResultSchema, { kind: "mutation" }), method(object({
|
|
17428
|
+
targetId: string(),
|
|
17429
|
+
sample: NotificationSchema.optional()
|
|
17430
|
+
}), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
|
|
17431
|
+
targetId: string(),
|
|
17432
|
+
enabled: boolean()
|
|
17433
|
+
}), _void(), { kind: "mutation" });
|
|
16138
17434
|
/**
|
|
16139
17435
|
* Zod schemas for persisted record types.
|
|
16140
17436
|
*
|
|
@@ -19156,7 +20452,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
19156
20452
|
"webgpu",
|
|
19157
20453
|
"none"
|
|
19158
20454
|
]).nullable().optional();
|
|
19159
|
-
var HwAccelResolutionSchema = object({
|
|
20455
|
+
var HwAccelResolutionSchema = object({
|
|
20456
|
+
preferred: array(string()).readonly(),
|
|
20457
|
+
rationale: string()
|
|
20458
|
+
});
|
|
19160
20459
|
var HardwareEncoderIdSchema = _enum([
|
|
19161
20460
|
"h264_videotoolbox",
|
|
19162
20461
|
"hevc_videotoolbox",
|
|
@@ -19261,10 +20560,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
19261
20560
|
format: ModelFormatSchema,
|
|
19262
20561
|
reason: string()
|
|
19263
20562
|
});
|
|
19264
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
19265
|
-
prefer: HwAccelBackendInputSchema,
|
|
19266
|
-
nodeId: string().optional()
|
|
19267
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
20563
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
19268
20564
|
kind: "mutation",
|
|
19269
20565
|
auth: "admin"
|
|
19270
20566
|
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
@@ -19323,6 +20619,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
19323
20619
|
kind: "mutation",
|
|
19324
20620
|
auth: "admin"
|
|
19325
20621
|
});
|
|
20622
|
+
/**
|
|
20623
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
20624
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
20625
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
20626
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
20627
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
20628
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
20629
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
20630
|
+
* (`interfaces/recording-config.ts`).
|
|
20631
|
+
*/
|
|
19326
20632
|
var RecordingStatusSchema = object({
|
|
19327
20633
|
deviceId: number(),
|
|
19328
20634
|
enabled: boolean(),
|
|
@@ -20959,6 +22265,12 @@ Object.freeze({
|
|
|
20959
22265
|
addonId: null,
|
|
20960
22266
|
access: "view"
|
|
20961
22267
|
},
|
|
22268
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
22269
|
+
capName: "device-manager",
|
|
22270
|
+
capScope: "system",
|
|
22271
|
+
addonId: null,
|
|
22272
|
+
access: "view"
|
|
22273
|
+
},
|
|
20962
22274
|
"deviceManager.getSettingsSchema": {
|
|
20963
22275
|
capName: "device-manager",
|
|
20964
22276
|
capScope: "system",
|
|
@@ -21109,6 +22421,12 @@ Object.freeze({
|
|
|
21109
22421
|
addonId: null,
|
|
21110
22422
|
access: "create"
|
|
21111
22423
|
},
|
|
22424
|
+
"deviceManager.setDisplay": {
|
|
22425
|
+
capName: "device-manager",
|
|
22426
|
+
capScope: "system",
|
|
22427
|
+
addonId: null,
|
|
22428
|
+
access: "create"
|
|
22429
|
+
},
|
|
21112
22430
|
"deviceManager.setIntegrationId": {
|
|
21113
22431
|
capName: "device-manager",
|
|
21114
22432
|
capScope: "system",
|
|
@@ -21151,6 +22469,12 @@ Object.freeze({
|
|
|
21151
22469
|
addonId: null,
|
|
21152
22470
|
access: "create"
|
|
21153
22471
|
},
|
|
22472
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
22473
|
+
capName: "device-manager",
|
|
22474
|
+
capScope: "system",
|
|
22475
|
+
addonId: null,
|
|
22476
|
+
access: "create"
|
|
22477
|
+
},
|
|
21154
22478
|
"deviceManager.setStreamProfileMap": {
|
|
21155
22479
|
capName: "device-manager",
|
|
21156
22480
|
capScope: "system",
|
|
@@ -22129,13 +23453,49 @@ Object.freeze({
|
|
|
22129
23453
|
addonId: null,
|
|
22130
23454
|
access: "create"
|
|
22131
23455
|
},
|
|
23456
|
+
"notificationOutput.deleteTarget": {
|
|
23457
|
+
capName: "notification-output",
|
|
23458
|
+
capScope: "system",
|
|
23459
|
+
addonId: null,
|
|
23460
|
+
access: "delete"
|
|
23461
|
+
},
|
|
23462
|
+
"notificationOutput.discoverTargets": {
|
|
23463
|
+
capName: "notification-output",
|
|
23464
|
+
capScope: "system",
|
|
23465
|
+
addonId: null,
|
|
23466
|
+
access: "view"
|
|
23467
|
+
},
|
|
23468
|
+
"notificationOutput.listTargetKinds": {
|
|
23469
|
+
capName: "notification-output",
|
|
23470
|
+
capScope: "system",
|
|
23471
|
+
addonId: null,
|
|
23472
|
+
access: "view"
|
|
23473
|
+
},
|
|
23474
|
+
"notificationOutput.listTargets": {
|
|
23475
|
+
capName: "notification-output",
|
|
23476
|
+
capScope: "system",
|
|
23477
|
+
addonId: null,
|
|
23478
|
+
access: "view"
|
|
23479
|
+
},
|
|
22132
23480
|
"notificationOutput.send": {
|
|
22133
23481
|
capName: "notification-output",
|
|
22134
23482
|
capScope: "system",
|
|
22135
23483
|
addonId: null,
|
|
22136
23484
|
access: "create"
|
|
22137
23485
|
},
|
|
22138
|
-
"notificationOutput.
|
|
23486
|
+
"notificationOutput.setTargetEnabled": {
|
|
23487
|
+
capName: "notification-output",
|
|
23488
|
+
capScope: "system",
|
|
23489
|
+
addonId: null,
|
|
23490
|
+
access: "create"
|
|
23491
|
+
},
|
|
23492
|
+
"notificationOutput.testTarget": {
|
|
23493
|
+
capName: "notification-output",
|
|
23494
|
+
capScope: "system",
|
|
23495
|
+
addonId: null,
|
|
23496
|
+
access: "create"
|
|
23497
|
+
},
|
|
23498
|
+
"notificationOutput.upsertTarget": {
|
|
22139
23499
|
capName: "notification-output",
|
|
22140
23500
|
capScope: "system",
|
|
22141
23501
|
addonId: null,
|
|
@@ -22165,6 +23525,66 @@ Object.freeze({
|
|
|
22165
23525
|
addonId: null,
|
|
22166
23526
|
access: "create"
|
|
22167
23527
|
},
|
|
23528
|
+
"petFeeder.callPet": {
|
|
23529
|
+
capName: "pet-feeder",
|
|
23530
|
+
capScope: "device",
|
|
23531
|
+
addonId: null,
|
|
23532
|
+
access: "create"
|
|
23533
|
+
},
|
|
23534
|
+
"petFeeder.cancelFeed": {
|
|
23535
|
+
capName: "pet-feeder",
|
|
23536
|
+
capScope: "device",
|
|
23537
|
+
addonId: null,
|
|
23538
|
+
access: "create"
|
|
23539
|
+
},
|
|
23540
|
+
"petFeeder.feed": {
|
|
23541
|
+
capName: "pet-feeder",
|
|
23542
|
+
capScope: "device",
|
|
23543
|
+
addonId: null,
|
|
23544
|
+
access: "create"
|
|
23545
|
+
},
|
|
23546
|
+
"petFeeder.markFoodReplenished": {
|
|
23547
|
+
capName: "pet-feeder",
|
|
23548
|
+
capScope: "device",
|
|
23549
|
+
addonId: null,
|
|
23550
|
+
access: "create"
|
|
23551
|
+
},
|
|
23552
|
+
"petFeeder.playSound": {
|
|
23553
|
+
capName: "pet-feeder",
|
|
23554
|
+
capScope: "device",
|
|
23555
|
+
addonId: null,
|
|
23556
|
+
access: "create"
|
|
23557
|
+
},
|
|
23558
|
+
"petFeeder.resetDesiccant": {
|
|
23559
|
+
capName: "pet-feeder",
|
|
23560
|
+
capScope: "device",
|
|
23561
|
+
addonId: null,
|
|
23562
|
+
access: "delete"
|
|
23563
|
+
},
|
|
23564
|
+
"petFeeder.setChildLock": {
|
|
23565
|
+
capName: "pet-feeder",
|
|
23566
|
+
capScope: "device",
|
|
23567
|
+
addonId: null,
|
|
23568
|
+
access: "create"
|
|
23569
|
+
},
|
|
23570
|
+
"petFeeder.setFeedSound": {
|
|
23571
|
+
capName: "pet-feeder",
|
|
23572
|
+
capScope: "device",
|
|
23573
|
+
addonId: null,
|
|
23574
|
+
access: "create"
|
|
23575
|
+
},
|
|
23576
|
+
"petFeeder.setIndicatorLight": {
|
|
23577
|
+
capName: "pet-feeder",
|
|
23578
|
+
capScope: "device",
|
|
23579
|
+
addonId: null,
|
|
23580
|
+
access: "create"
|
|
23581
|
+
},
|
|
23582
|
+
"petFeeder.setVolume": {
|
|
23583
|
+
capName: "pet-feeder",
|
|
23584
|
+
capScope: "device",
|
|
23585
|
+
addonId: null,
|
|
23586
|
+
access: "create"
|
|
23587
|
+
},
|
|
22168
23588
|
"pipelineAnalytics.clearTracks": {
|
|
22169
23589
|
capName: "pipeline-analytics",
|
|
22170
23590
|
capScope: "device",
|