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