@camstack/addon-provider-gree 0.1.11 → 0.1.13
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
|
@@ -4645,7 +4645,7 @@ function preprocess(fn, schema) {
|
|
|
4645
4645
|
});
|
|
4646
4646
|
}
|
|
4647
4647
|
//#endregion
|
|
4648
|
-
//#region ../types/dist/sleep-
|
|
4648
|
+
//#region ../types/dist/sleep-BiDFW0E7.mjs
|
|
4649
4649
|
var EventCategory = /* @__PURE__ */ function(EventCategory) {
|
|
4650
4650
|
EventCategory["SystemBoot"] = "system.boot";
|
|
4651
4651
|
EventCategory["SystemAddonsReady"] = "system.addons-ready";
|
|
@@ -5458,6 +5458,100 @@ function createDurableState(deps) {
|
|
|
5458
5458
|
};
|
|
5459
5459
|
}
|
|
5460
5460
|
/**
|
|
5461
|
+
* Per-node scoping for the shared addon-settings blob.
|
|
5462
|
+
*
|
|
5463
|
+
* An addon's settings store is hub-central (the `addon-settings` cap is
|
|
5464
|
+
* hub-routed — the hub instance answers for every node), so fields whose
|
|
5465
|
+
* value is a NODE fact (decoder backend, engine pick, probed hardware
|
|
5466
|
+
* capabilities) persist under the node-scoped key `<key>@<nodeId>` inside
|
|
5467
|
+
* the single shared blob. The SCHEMA field key stays bare: the write path
|
|
5468
|
+
* ({@link scopePatch}) maps the bare field onto the target node's scoped
|
|
5469
|
+
* key; the read/hydrate path ({@link projectStore}) maps THIS node's value
|
|
5470
|
+
* back, so UI forms and `resolveConfig` only ever see the bare key.
|
|
5471
|
+
*
|
|
5472
|
+
* Fields opt in via the `perNode: true` schema marker on `ConfigFieldBase`
|
|
5473
|
+
* (`interfaces/config-ui.ts`); `BaseAddon` derives the key set from the
|
|
5474
|
+
* schema and routes reads/writes through these helpers.
|
|
5475
|
+
*
|
|
5476
|
+
* ## No bare-key fallback — deliberate
|
|
5477
|
+
*
|
|
5478
|
+
* {@link readNodeValue} reads the node-scoped key ONLY. A node with no
|
|
5479
|
+
* scoped key resolves to `undefined` so the field's schema `default` wins —
|
|
5480
|
+
* NEVER `store[base]` and never another node's value. A bare legacy key in
|
|
5481
|
+
* the store is invisible to every node, hub included, so one node's
|
|
5482
|
+
* selection can never leak onto another. (This generalizes the
|
|
5483
|
+
* `decoder-backend-keys.ts` semantics — the no-fallback variant — over an
|
|
5484
|
+
* arbitrary set of per-node field keys.)
|
|
5485
|
+
*
|
|
5486
|
+
* Pure functions only — no I/O, no imports beyond the language. This is a
|
|
5487
|
+
* LEAF module: import it via its deep path, never from the root barrel.
|
|
5488
|
+
*/
|
|
5489
|
+
/**
|
|
5490
|
+
* Normalize a raw kernel node id to the bare node id used for scoping.
|
|
5491
|
+
* `localNodeId` can carry a `<node>/<addon>` suffix on forked child
|
|
5492
|
+
* processes; per-node settings are per-NODE, so strip the addon segment.
|
|
5493
|
+
* `undefined` / `null` / empty falls back to `'hub'`.
|
|
5494
|
+
*/
|
|
5495
|
+
function normalizeNodeId(raw) {
|
|
5496
|
+
if (raw === void 0 || raw === null || raw === "") return "hub";
|
|
5497
|
+
const slashIdx = raw.indexOf("/");
|
|
5498
|
+
if (slashIdx < 0) return raw;
|
|
5499
|
+
const bare = raw.slice(0, slashIdx);
|
|
5500
|
+
return bare === "" ? "hub" : bare;
|
|
5501
|
+
}
|
|
5502
|
+
/** The node-scoped store key for a per-node field: `<base>@<nodeId>`. */
|
|
5503
|
+
function nodeScopedKey(base, nodeId) {
|
|
5504
|
+
return `${base}@${normalizeNodeId(nodeId)}`;
|
|
5505
|
+
}
|
|
5506
|
+
/**
|
|
5507
|
+
* Read a node's value for a per-node field from the raw shared store:
|
|
5508
|
+
* the node-scoped key when present, otherwise `undefined`.
|
|
5509
|
+
* Deliberately NO bare-key fallback (see module doc) — the caller lets the
|
|
5510
|
+
* schema `default` win on `undefined`.
|
|
5511
|
+
*/
|
|
5512
|
+
function readNodeValue(store, base, nodeId) {
|
|
5513
|
+
return store[nodeScopedKey(base, nodeId)];
|
|
5514
|
+
}
|
|
5515
|
+
/**
|
|
5516
|
+
* Re-map a UI/settings patch so every bare perNode field persists under the
|
|
5517
|
+
* TARGET node's scoped key; all other keys pass through unchanged. Used on
|
|
5518
|
+
* the write path so a save for one node never clobbers another node's value
|
|
5519
|
+
* (and the bare key is never written). Returns a new object — the input
|
|
5520
|
+
* patch is not mutated.
|
|
5521
|
+
*/
|
|
5522
|
+
function scopePatch(patch, perNodeKeys, nodeId) {
|
|
5523
|
+
const out = {};
|
|
5524
|
+
for (const [key, value] of Object.entries(patch)) out[perNodeKeys.has(key) ? nodeScopedKey(key, nodeId) : key] = value;
|
|
5525
|
+
return out;
|
|
5526
|
+
}
|
|
5527
|
+
/**
|
|
5528
|
+
* Project the raw shared store onto the bare schema keys for ONE node so a
|
|
5529
|
+
* UI schema (whose field keys are bare) hydrates from that node's own
|
|
5530
|
+
* values:
|
|
5531
|
+
*
|
|
5532
|
+
* - EVERY `@`-scoped key (any node's) is dropped from the pass-through.
|
|
5533
|
+
* - Every bare perNode key is dropped from the pass-through (a stray bare
|
|
5534
|
+
* legacy key must never hydrate any node — no bare fallback).
|
|
5535
|
+
* - THIS node's effective value ({@link readNodeValue}) is then laid onto
|
|
5536
|
+
* each bare perNode key; when the node has no scoped key the bare key is
|
|
5537
|
+
* left ABSENT so the field's schema `default` wins.
|
|
5538
|
+
*
|
|
5539
|
+
* Returns a new object — the input store is not mutated.
|
|
5540
|
+
*/
|
|
5541
|
+
function projectStore(store, perNodeKeys, nodeId) {
|
|
5542
|
+
const out = {};
|
|
5543
|
+
for (const [key, value] of Object.entries(store)) {
|
|
5544
|
+
if (key.includes("@")) continue;
|
|
5545
|
+
if (perNodeKeys.has(key)) continue;
|
|
5546
|
+
out[key] = value;
|
|
5547
|
+
}
|
|
5548
|
+
for (const base of perNodeKeys) {
|
|
5549
|
+
const value = readNodeValue(store, base, nodeId);
|
|
5550
|
+
if (value !== void 0) out[base] = value;
|
|
5551
|
+
}
|
|
5552
|
+
return out;
|
|
5553
|
+
}
|
|
5554
|
+
/**
|
|
5461
5555
|
* Base class for CamStack addons. Eliminates settings boilerplate:
|
|
5462
5556
|
*
|
|
5463
5557
|
* - Typed `config` property with automatic resolution from store + defaults
|
|
@@ -5625,23 +5719,63 @@ var BaseAddon = class {
|
|
|
5625
5719
|
deviceSettingsSchema() {
|
|
5626
5720
|
return null;
|
|
5627
5721
|
}
|
|
5628
|
-
async getGlobalSettings(overlay, cap,
|
|
5722
|
+
async getGlobalSettings(overlay, cap, nodeId) {
|
|
5629
5723
|
const schema = this.globalSettingsSchema(cap);
|
|
5630
5724
|
if (!schema) return { sections: [] };
|
|
5631
|
-
const
|
|
5725
|
+
const projected = await this.resolveGlobalStore(nodeId, cap);
|
|
5632
5726
|
return hydrateSchema(schema, overlay ? {
|
|
5633
|
-
...
|
|
5727
|
+
...projected,
|
|
5634
5728
|
...overlay
|
|
5635
|
-
} :
|
|
5729
|
+
} : projected);
|
|
5636
5730
|
}
|
|
5637
|
-
|
|
5638
|
-
|
|
5731
|
+
/**
|
|
5732
|
+
* The raw addon store PROJECTED onto the target node's bare per-node keys:
|
|
5733
|
+
* every `perNode: true` field carries THAT node's scoped value on its bare
|
|
5734
|
+
* key (absent scoped key ⇒ key absent, so the schema `default` wins — no
|
|
5735
|
+
* bare fallback), all `@`-scoped and stray bare per-node keys are dropped.
|
|
5736
|
+
* A no-op passthrough when the schema declares no `perNode` field.
|
|
5737
|
+
*
|
|
5738
|
+
* This is the sanctioned way for a `getGlobalSettings` OVERRIDE that needs
|
|
5739
|
+
* the store for custom option logic (option narrowing, value snapping) to
|
|
5740
|
+
* read it per-node — never `ctx.settings.readAddonStore()` directly.
|
|
5741
|
+
* `nodeId` omitted ⇒ the local node (node-blind injection from ctx).
|
|
5742
|
+
*/
|
|
5743
|
+
async resolveGlobalStore(nodeId, cap) {
|
|
5744
|
+
const raw = await this._ctx?.settings?.readAddonStore() ?? {};
|
|
5745
|
+
const keys = this.perNodeKeys(cap);
|
|
5746
|
+
const node = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5747
|
+
return keys.size > 0 ? projectStore(raw, keys, node) : raw;
|
|
5748
|
+
}
|
|
5749
|
+
async updateGlobalSettings(patch, nodeId) {
|
|
5750
|
+
const keys = this.perNodeKeys();
|
|
5751
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5752
|
+
const target = normalizeNodeId(nodeId ?? this._ctx?.kernel?.localNodeId);
|
|
5753
|
+
const barePatch = patch;
|
|
5754
|
+
const scoped = keys.size > 0 ? scopePatch(barePatch, keys, target) : barePatch;
|
|
5755
|
+
await this._ctx?.settings?.writeAddonStore(scoped);
|
|
5756
|
+
if (target !== localNode) return;
|
|
5639
5757
|
await this.resolveConfig();
|
|
5640
5758
|
await this.onConfigChanged();
|
|
5641
5759
|
this.emitLifecycle(EventCategory.AddonUpdated, { level: "global" });
|
|
5642
5760
|
this.maybeAutoRestart(patch, this.globalSettingsSchema());
|
|
5643
5761
|
}
|
|
5644
5762
|
/**
|
|
5763
|
+
* The set of field keys the global settings schema declares `perNode: true`
|
|
5764
|
+
* — derived once per `cap` argument and memoized (schemas are static
|
|
5765
|
+
* declarations). Empty set ⇒ every per-node code path is bypassed and the
|
|
5766
|
+
* settings API behaves exactly like the legacy node-agnostic one.
|
|
5767
|
+
*/
|
|
5768
|
+
_perNodeKeysCache = /* @__PURE__ */ new Map();
|
|
5769
|
+
perNodeKeys(cap) {
|
|
5770
|
+
const cacheKey = cap ?? "";
|
|
5771
|
+
const cached = this._perNodeKeysCache.get(cacheKey);
|
|
5772
|
+
if (cached) return cached;
|
|
5773
|
+
const schema = this.globalSettingsSchema(cap);
|
|
5774
|
+
const keys = new Set(schema ? schema.sections.flatMap((section) => collectPerNodeFieldKeys(section.fields)) : []);
|
|
5775
|
+
this._perNodeKeysCache.set(cacheKey, keys);
|
|
5776
|
+
return keys;
|
|
5777
|
+
}
|
|
5778
|
+
/**
|
|
5645
5779
|
* If any field in `patch` is marked `requiresRestart` in `schema`,
|
|
5646
5780
|
* schedule an addon restart for the next tick. Deferred via
|
|
5647
5781
|
* `setImmediate` so the tRPC mutation that triggered the write has
|
|
@@ -5794,12 +5928,19 @@ var BaseAddon = class {
|
|
|
5794
5928
|
* The merge is shallow: each key in `defaults` is checked against the store.
|
|
5795
5929
|
* Only keys present in defaults are read — the store can contain extra keys
|
|
5796
5930
|
* (e.g. from older versions) without polluting the typed config.
|
|
5931
|
+
*
|
|
5932
|
+
* Keys the global settings schema declares `perNode: true` resolve from
|
|
5933
|
+
* THIS node's scoped key (`<key>@<localNode>`) via `readNodeValue` — never
|
|
5934
|
+
* from the bare key — so a per-node field resolves to this node's own
|
|
5935
|
+
* selection at boot (absent scoped key ⇒ the constructor default wins).
|
|
5797
5936
|
*/
|
|
5798
5937
|
async resolveConfig() {
|
|
5799
5938
|
const stored = await this.readAddonStoreWithRetry();
|
|
5939
|
+
const perNode = this.perNodeKeys();
|
|
5940
|
+
const localNode = normalizeNodeId(this._ctx?.kernel?.localNodeId);
|
|
5800
5941
|
const resolved = { ...this.defaults };
|
|
5801
5942
|
for (const key of Object.keys(this.defaults)) {
|
|
5802
|
-
const storedValue = stored[key];
|
|
5943
|
+
const storedValue = perNode.has(key) ? readNodeValue(stored, key, localNode) : stored[key];
|
|
5803
5944
|
if (storedValue !== void 0 && storedValue !== null) {
|
|
5804
5945
|
const defaultType = typeof this.defaults[key];
|
|
5805
5946
|
if (typeof storedValue === defaultType) resolved[key] = storedValue;
|
|
@@ -5883,6 +6024,27 @@ var BaseAddon = class {
|
|
|
5883
6024
|
}
|
|
5884
6025
|
};
|
|
5885
6026
|
/**
|
|
6027
|
+
* Collect the keys of every field marked `perNode: true`, recursing into
|
|
6028
|
+
* layout containers (`group` fields and `sub-tabs` tabs) the same way
|
|
6029
|
+
* `hydrateSchema` does. Valueless structural fields (separator/info/…)
|
|
6030
|
+
* don't declare `perNode` and are excluded by the `in` narrowing.
|
|
6031
|
+
*/
|
|
6032
|
+
function collectPerNodeFieldKeys(fields) {
|
|
6033
|
+
const collected = [];
|
|
6034
|
+
for (const field of fields) {
|
|
6035
|
+
if (field.type === "group") {
|
|
6036
|
+
collected.push(...collectPerNodeFieldKeys(field.fields));
|
|
6037
|
+
continue;
|
|
6038
|
+
}
|
|
6039
|
+
if (field.type === "sub-tabs") {
|
|
6040
|
+
for (const tab of field.tabs) collected.push(...collectPerNodeFieldKeys(tab.fields));
|
|
6041
|
+
continue;
|
|
6042
|
+
}
|
|
6043
|
+
if ("perNode" in field && field.perNode === true) collected.push(field.key);
|
|
6044
|
+
}
|
|
6045
|
+
return collected;
|
|
6046
|
+
}
|
|
6047
|
+
/**
|
|
5886
6048
|
* Normalize an `ICamstackAddon.initialize()` return value into the
|
|
5887
6049
|
* `AddonInitResult` envelope. Arrays are wrapped into `{ providers }`;
|
|
5888
6050
|
* envelopes pass through; void stays void.
|
|
@@ -5907,6 +6069,7 @@ var CamStreamKindSchema = _enum([
|
|
|
5907
6069
|
"pull-rtsp",
|
|
5908
6070
|
"pull-rtmp",
|
|
5909
6071
|
"pull-http",
|
|
6072
|
+
"pull-flv",
|
|
5910
6073
|
"pull-rfc4571",
|
|
5911
6074
|
"push-annexb",
|
|
5912
6075
|
"derived"
|
|
@@ -6289,6 +6452,13 @@ var DeviceType = /* @__PURE__ */ function(DeviceType) {
|
|
|
6289
6452
|
/** Single still-image entity (HA `image.*`). Read-only display of an
|
|
6290
6453
|
* `entity_picture` signed URL the browser loads directly. `image` cap. */
|
|
6291
6454
|
DeviceType["Image"] = "image";
|
|
6455
|
+
/** Smart pet feeder — cloud-connected food dispenser with a bowl food
|
|
6456
|
+
* level, battery, desiccant life, feeding state and manual-feed /
|
|
6457
|
+
* call-pet / maintenance actions. Installed with the `pet-feeder` cap;
|
|
6458
|
+
* dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
|
|
6459
|
+
* native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
|
|
6460
|
+
* integrations sharing the same food/desiccant/hopper surface. */
|
|
6461
|
+
DeviceType["PetFeeder"] = "pet-feeder";
|
|
6292
6462
|
return DeviceType;
|
|
6293
6463
|
}({});
|
|
6294
6464
|
var DeviceFeature = /* @__PURE__ */ function(DeviceFeature) {
|
|
@@ -7066,7 +7236,21 @@ var StorageLocationDeclarationSchema = object({
|
|
|
7066
7236
|
* slots (e.g. `recordingsLow` → `recordings`) so operators only need to
|
|
7067
7237
|
* configure the primary location.
|
|
7068
7238
|
*/
|
|
7069
|
-
defaultsTo: string().optional()
|
|
7239
|
+
defaultsTo: string().optional(),
|
|
7240
|
+
/**
|
|
7241
|
+
* Which node root the seeded `<id>:default` instance is placed under on a
|
|
7242
|
+
* FRESH install:
|
|
7243
|
+
* - `'data'` (default) — the node's data dir (`CAMSTACK_DATA` / boot dir),
|
|
7244
|
+
* the appData volume. Right for small/durable data (backups, logs, models).
|
|
7245
|
+
* - `'media'` — the dedicated media volume (`CAMSTACK_MEDIA_ROOT`) when that
|
|
7246
|
+
* env is set, else falls back to the data root. Right for bulky, hot media
|
|
7247
|
+
* (recordings, event media) that should stay off the appData disk.
|
|
7248
|
+
*
|
|
7249
|
+
* Only affects the seeded default's `basePath`; operators can repoint any
|
|
7250
|
+
* location afterwards, and a `defaultsTo` slot inherits its parent's root
|
|
7251
|
+
* regardless of this field. Absent (the common case) is treated as `'data'`.
|
|
7252
|
+
*/
|
|
7253
|
+
defaultRoot: _enum(["data", "media"]).optional()
|
|
7070
7254
|
});
|
|
7071
7255
|
var DecoderStatsSchema = object({
|
|
7072
7256
|
inputFps: number(),
|
|
@@ -7439,6 +7623,601 @@ var _macroLookup = /* @__PURE__ */ new Map();
|
|
|
7439
7623
|
for (const [k, v] of Object.entries(YAMNET_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7440
7624
|
for (const [k, v] of Object.entries(APPLE_SA_TO_MACRO.mapping)) _macroLookup.set(k.toLowerCase(), v);
|
|
7441
7625
|
/**
|
|
7626
|
+
* Error types for the safe expression engine. Two distinct classes so callers
|
|
7627
|
+
* can tell a compile-time (grammar) failure from a runtime (evaluation)
|
|
7628
|
+
* failure — both are non-fatal to the host: read paths degrade to "skip link".
|
|
7629
|
+
*/
|
|
7630
|
+
/** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
|
|
7631
|
+
* the failure is anchored to a character (author-facing inline feedback). */
|
|
7632
|
+
var ExpressionParseError = class extends Error {
|
|
7633
|
+
position;
|
|
7634
|
+
constructor(message, position) {
|
|
7635
|
+
super(message);
|
|
7636
|
+
this.name = "ExpressionParseError";
|
|
7637
|
+
this.position = position;
|
|
7638
|
+
}
|
|
7639
|
+
};
|
|
7640
|
+
/** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
|
|
7641
|
+
* result, unknown builtin, step-budget exceeded). */
|
|
7642
|
+
var ExpressionEvalError = class extends Error {
|
|
7643
|
+
constructor(message) {
|
|
7644
|
+
super(message);
|
|
7645
|
+
this.name = "ExpressionEvalError";
|
|
7646
|
+
}
|
|
7647
|
+
};
|
|
7648
|
+
/**
|
|
7649
|
+
* Resource-bound constants for the safe expression engine.
|
|
7650
|
+
*
|
|
7651
|
+
* Every bound is defense-in-depth: the grammar is non-Turing-complete (no
|
|
7652
|
+
* loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
|
|
7653
|
+
* O(nodeCount) by construction. These caps merely put a hard ceiling on the
|
|
7654
|
+
* work a single author-supplied expression can request, so a hostile or
|
|
7655
|
+
* accidental pathological string can never spend unbounded CPU/memory.
|
|
7656
|
+
*/
|
|
7657
|
+
/** Max source length (chars) — checked BEFORE tokenizing so a huge string is
|
|
7658
|
+
* rejected without allocation. */
|
|
7659
|
+
var MAX_EXPRESSION_SOURCE_LENGTH = 2048;
|
|
7660
|
+
/** A legal binding / identifier name. */
|
|
7661
|
+
var EXPRESSION_IDENTIFIER_RE = /^[A-Za-z_][A-Za-z0-9_]*$/;
|
|
7662
|
+
/** Binding names an author may NOT use: `now` is auto-injected; the literal
|
|
7663
|
+
* keywords lex as values, not identifiers, so binding to them is meaningless. */
|
|
7664
|
+
var RESERVED_BINDING_NAMES = new Set([
|
|
7665
|
+
"now",
|
|
7666
|
+
"true",
|
|
7667
|
+
"false",
|
|
7668
|
+
"null"
|
|
7669
|
+
]);
|
|
7670
|
+
/**
|
|
7671
|
+
* Tokenizer for the safe expression mini-language. Hand-rolled, single-pass,
|
|
7672
|
+
* zero-dependency. The grammar is deliberately boring: decimal numbers,
|
|
7673
|
+
* single/double-quoted strings with a tiny escape set, identifiers, the three
|
|
7674
|
+
* value keywords (`true`/`false`/`null`) and a fixed punctuator set. Anything
|
|
7675
|
+
* outside that — a bare `.`, `=`, `[`, `]`, `{`, `}`, `;`, backtick, `&`, `|` —
|
|
7676
|
+
* is a parse error with a source position, so member access / assignment /
|
|
7677
|
+
* template literals are lexically impossible.
|
|
7678
|
+
*/
|
|
7679
|
+
var KEYWORDS = new Set([
|
|
7680
|
+
"true",
|
|
7681
|
+
"false",
|
|
7682
|
+
"null"
|
|
7683
|
+
]);
|
|
7684
|
+
function isDigit(ch) {
|
|
7685
|
+
return ch >= "0" && ch <= "9";
|
|
7686
|
+
}
|
|
7687
|
+
function isIdentStart(ch) {
|
|
7688
|
+
return ch >= "A" && ch <= "Z" || ch >= "a" && ch <= "z" || ch === "_";
|
|
7689
|
+
}
|
|
7690
|
+
function isIdentPart(ch) {
|
|
7691
|
+
return isIdentStart(ch) || isDigit(ch);
|
|
7692
|
+
}
|
|
7693
|
+
function isWhitespace(ch) {
|
|
7694
|
+
return ch === " " || ch === " " || ch === "\n" || ch === "\r" || ch === "\f" || ch === "\v";
|
|
7695
|
+
}
|
|
7696
|
+
/** Tokenize `source` into a flat token list ending with a single `eof` token.
|
|
7697
|
+
* Throws `ExpressionParseError` on any illegal character or unterminated
|
|
7698
|
+
* string. */
|
|
7699
|
+
function tokenize(source) {
|
|
7700
|
+
if (source.length > 2048) throw new ExpressionParseError(`expression too long (${source.length} > ${MAX_EXPRESSION_SOURCE_LENGTH} chars)`, 0);
|
|
7701
|
+
const tokens = [];
|
|
7702
|
+
let i = 0;
|
|
7703
|
+
const n = source.length;
|
|
7704
|
+
while (i < n) {
|
|
7705
|
+
const ch = source[i];
|
|
7706
|
+
if (isWhitespace(ch)) {
|
|
7707
|
+
i += 1;
|
|
7708
|
+
continue;
|
|
7709
|
+
}
|
|
7710
|
+
if (isDigit(ch)) {
|
|
7711
|
+
const start = i;
|
|
7712
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7713
|
+
if (i < n && source[i] === ".") {
|
|
7714
|
+
if (i + 1 >= n || !isDigit(source[i + 1])) throw new ExpressionParseError("malformed number: decimal point needs a digit", i);
|
|
7715
|
+
i += 1;
|
|
7716
|
+
while (i < n && isDigit(source[i])) i += 1;
|
|
7717
|
+
}
|
|
7718
|
+
const text = source.slice(start, i);
|
|
7719
|
+
const value = Number(text);
|
|
7720
|
+
if (!Number.isFinite(value)) throw new ExpressionParseError(`malformed number: '${text}'`, start);
|
|
7721
|
+
tokens.push({
|
|
7722
|
+
type: "number",
|
|
7723
|
+
value,
|
|
7724
|
+
pos: start
|
|
7725
|
+
});
|
|
7726
|
+
continue;
|
|
7727
|
+
}
|
|
7728
|
+
if (ch === "'" || ch === "\"") {
|
|
7729
|
+
const quote = ch;
|
|
7730
|
+
const start = i;
|
|
7731
|
+
i += 1;
|
|
7732
|
+
let out = "";
|
|
7733
|
+
let closed = false;
|
|
7734
|
+
while (i < n) {
|
|
7735
|
+
const c = source[i];
|
|
7736
|
+
if (c === "\\") {
|
|
7737
|
+
const next = i + 1 < n ? source[i + 1] : "";
|
|
7738
|
+
if (next === "\\" || next === "'" || next === "\"") {
|
|
7739
|
+
out += next;
|
|
7740
|
+
i += 2;
|
|
7741
|
+
continue;
|
|
7742
|
+
}
|
|
7743
|
+
throw new ExpressionParseError(`invalid string escape: '\\${next}'`, i);
|
|
7744
|
+
}
|
|
7745
|
+
if (c === quote) {
|
|
7746
|
+
closed = true;
|
|
7747
|
+
i += 1;
|
|
7748
|
+
break;
|
|
7749
|
+
}
|
|
7750
|
+
out += c;
|
|
7751
|
+
i += 1;
|
|
7752
|
+
}
|
|
7753
|
+
if (!closed) throw new ExpressionParseError("unterminated string literal", start);
|
|
7754
|
+
tokens.push({
|
|
7755
|
+
type: "string",
|
|
7756
|
+
value: out,
|
|
7757
|
+
pos: start
|
|
7758
|
+
});
|
|
7759
|
+
continue;
|
|
7760
|
+
}
|
|
7761
|
+
if (isIdentStart(ch)) {
|
|
7762
|
+
const start = i;
|
|
7763
|
+
while (i < n && isIdentPart(source[i])) i += 1;
|
|
7764
|
+
const text = source.slice(start, i);
|
|
7765
|
+
if (KEYWORDS.has(text)) tokens.push({
|
|
7766
|
+
type: "keyword",
|
|
7767
|
+
keyword: keywordOf(text),
|
|
7768
|
+
pos: start
|
|
7769
|
+
});
|
|
7770
|
+
else tokens.push({
|
|
7771
|
+
type: "identifier",
|
|
7772
|
+
name: text,
|
|
7773
|
+
pos: start
|
|
7774
|
+
});
|
|
7775
|
+
continue;
|
|
7776
|
+
}
|
|
7777
|
+
const two = i + 1 < n ? source.slice(i, i + 2) : "";
|
|
7778
|
+
if (two === "<=" || two === ">=" || two === "==" || two === "!=" || two === "&&" || two === "||") {
|
|
7779
|
+
tokens.push({
|
|
7780
|
+
type: "punct",
|
|
7781
|
+
punct: two,
|
|
7782
|
+
pos: i
|
|
7783
|
+
});
|
|
7784
|
+
i += 2;
|
|
7785
|
+
continue;
|
|
7786
|
+
}
|
|
7787
|
+
if (isSinglePunct(ch)) {
|
|
7788
|
+
tokens.push({
|
|
7789
|
+
type: "punct",
|
|
7790
|
+
punct: ch,
|
|
7791
|
+
pos: i
|
|
7792
|
+
});
|
|
7793
|
+
i += 1;
|
|
7794
|
+
continue;
|
|
7795
|
+
}
|
|
7796
|
+
throw new ExpressionParseError(`unexpected character '${ch}'`, i);
|
|
7797
|
+
}
|
|
7798
|
+
tokens.push({
|
|
7799
|
+
type: "eof",
|
|
7800
|
+
pos: n
|
|
7801
|
+
});
|
|
7802
|
+
return tokens;
|
|
7803
|
+
}
|
|
7804
|
+
function keywordOf(text) {
|
|
7805
|
+
if (text === "true") return "true";
|
|
7806
|
+
if (text === "false") return "false";
|
|
7807
|
+
return "null";
|
|
7808
|
+
}
|
|
7809
|
+
function isSinglePunct(ch) {
|
|
7810
|
+
return ch === "(" || ch === ")" || ch === "," || ch === "?" || ch === ":" || ch === "+" || ch === "-" || ch === "*" || ch === "/" || ch === "%" || ch === "!" || ch === "<" || ch === ">";
|
|
7811
|
+
}
|
|
7812
|
+
/**
|
|
7813
|
+
* Frozen, null-prototype builtin function table for the expression engine
|
|
7814
|
+
* (spec §4 rule 4). The table is the SOLE surface of callable functions: the
|
|
7815
|
+
* parser rejects any callee not in it, and the evaluator gates each call on an
|
|
7816
|
+
* own-property check against it.
|
|
7817
|
+
*
|
|
7818
|
+
* Because the object has a NULL prototype AND is `Object.freeze`d:
|
|
7819
|
+
* - it cannot be polluted (no `__proto__` / `constructor` write reaches it);
|
|
7820
|
+
* - a lookup for `toString` / `hasOwnProperty` / `constructor` finds NOTHING
|
|
7821
|
+
* (there is no `Object.prototype` in the chain), so those names are not
|
|
7822
|
+
* callable — they are simply "unknown function" at parse time.
|
|
7823
|
+
*
|
|
7824
|
+
* Every numeric argument is validated as a finite number and every numeric
|
|
7825
|
+
* RESULT is re-checked finite, so `/0`, `sqrt(-1)` (→ NaN) and overflow
|
|
7826
|
+
* (`pow(10,400)` → Infinity) all raise `ExpressionEvalError` and fail the link
|
|
7827
|
+
* closed rather than emitting a garbage value.
|
|
7828
|
+
*/
|
|
7829
|
+
function asFiniteNumber(value, name, index) {
|
|
7830
|
+
if (typeof value !== "number" || !Number.isFinite(value)) throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a finite number`);
|
|
7831
|
+
return value;
|
|
7832
|
+
}
|
|
7833
|
+
function asString$1(value, name, index) {
|
|
7834
|
+
if (typeof value !== "string") throw new ExpressionEvalError(`${name}: argument ${index + 1} must be a string`);
|
|
7835
|
+
return value;
|
|
7836
|
+
}
|
|
7837
|
+
function finiteResult(value, name) {
|
|
7838
|
+
if (!Number.isFinite(value)) throw new ExpressionEvalError(`${name}: produced a non-finite result`);
|
|
7839
|
+
return value;
|
|
7840
|
+
}
|
|
7841
|
+
function allFiniteNumbers(args, name) {
|
|
7842
|
+
return args.map((a, idx) => asFiniteNumber(a, name, idx));
|
|
7843
|
+
}
|
|
7844
|
+
var INF = Number.POSITIVE_INFINITY;
|
|
7845
|
+
var table = {
|
|
7846
|
+
min: {
|
|
7847
|
+
minArgs: 1,
|
|
7848
|
+
maxArgs: INF,
|
|
7849
|
+
apply: (args) => finiteResult(Math.min(...allFiniteNumbers(args, "min")), "min")
|
|
7850
|
+
},
|
|
7851
|
+
max: {
|
|
7852
|
+
minArgs: 1,
|
|
7853
|
+
maxArgs: INF,
|
|
7854
|
+
apply: (args) => finiteResult(Math.max(...allFiniteNumbers(args, "max")), "max")
|
|
7855
|
+
},
|
|
7856
|
+
abs: {
|
|
7857
|
+
minArgs: 1,
|
|
7858
|
+
maxArgs: 1,
|
|
7859
|
+
apply: (args) => finiteResult(Math.abs(asFiniteNumber(args[0], "abs", 0)), "abs")
|
|
7860
|
+
},
|
|
7861
|
+
floor: {
|
|
7862
|
+
minArgs: 1,
|
|
7863
|
+
maxArgs: 1,
|
|
7864
|
+
apply: (args) => finiteResult(Math.floor(asFiniteNumber(args[0], "floor", 0)), "floor")
|
|
7865
|
+
},
|
|
7866
|
+
ceil: {
|
|
7867
|
+
minArgs: 1,
|
|
7868
|
+
maxArgs: 1,
|
|
7869
|
+
apply: (args) => finiteResult(Math.ceil(asFiniteNumber(args[0], "ceil", 0)), "ceil")
|
|
7870
|
+
},
|
|
7871
|
+
sqrt: {
|
|
7872
|
+
minArgs: 1,
|
|
7873
|
+
maxArgs: 1,
|
|
7874
|
+
apply: (args) => finiteResult(Math.sqrt(asFiniteNumber(args[0], "sqrt", 0)), "sqrt")
|
|
7875
|
+
},
|
|
7876
|
+
round: {
|
|
7877
|
+
minArgs: 1,
|
|
7878
|
+
maxArgs: 2,
|
|
7879
|
+
apply: (args) => {
|
|
7880
|
+
const x = asFiniteNumber(args[0], "round", 0);
|
|
7881
|
+
const digits = args.length > 1 ? Math.trunc(asFiniteNumber(args[1], "round", 1)) : 0;
|
|
7882
|
+
if (digits < 0 || digits > 100) throw new ExpressionEvalError("round: digits must be between 0 and 100");
|
|
7883
|
+
const factor = 10 ** digits;
|
|
7884
|
+
return finiteResult(Math.round(x * factor) / factor, "round");
|
|
7885
|
+
}
|
|
7886
|
+
},
|
|
7887
|
+
pow: {
|
|
7888
|
+
minArgs: 2,
|
|
7889
|
+
maxArgs: 2,
|
|
7890
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "pow", 0) ** asFiniteNumber(args[1], "pow", 1), "pow")
|
|
7891
|
+
},
|
|
7892
|
+
clamp: {
|
|
7893
|
+
minArgs: 3,
|
|
7894
|
+
maxArgs: 3,
|
|
7895
|
+
apply: (args) => {
|
|
7896
|
+
const x = asFiniteNumber(args[0], "clamp", 0);
|
|
7897
|
+
const lo = asFiniteNumber(args[1], "clamp", 1);
|
|
7898
|
+
const hi = asFiniteNumber(args[2], "clamp", 2);
|
|
7899
|
+
if (lo > hi) throw new ExpressionEvalError("clamp: lower bound is greater than upper bound");
|
|
7900
|
+
return finiteResult(Math.min(hi, Math.max(lo, x)), "clamp");
|
|
7901
|
+
}
|
|
7902
|
+
},
|
|
7903
|
+
avg: {
|
|
7904
|
+
minArgs: 1,
|
|
7905
|
+
maxArgs: INF,
|
|
7906
|
+
apply: (args) => {
|
|
7907
|
+
const nums = allFiniteNumbers(args, "avg");
|
|
7908
|
+
return finiteResult(nums.reduce((acc, v) => acc + v, 0) / nums.length, "avg");
|
|
7909
|
+
}
|
|
7910
|
+
},
|
|
7911
|
+
sum: {
|
|
7912
|
+
minArgs: 1,
|
|
7913
|
+
maxArgs: INF,
|
|
7914
|
+
apply: (args) => finiteResult(allFiniteNumbers(args, "sum").reduce((acc, v) => acc + v, 0), "sum")
|
|
7915
|
+
},
|
|
7916
|
+
coalesce: {
|
|
7917
|
+
minArgs: 1,
|
|
7918
|
+
maxArgs: INF,
|
|
7919
|
+
apply: (args) => {
|
|
7920
|
+
for (const a of args) if (a !== null) return a;
|
|
7921
|
+
return null;
|
|
7922
|
+
}
|
|
7923
|
+
},
|
|
7924
|
+
age: {
|
|
7925
|
+
minArgs: 2,
|
|
7926
|
+
maxArgs: 2,
|
|
7927
|
+
apply: (args) => finiteResult(asFiniteNumber(args[0], "age", 0) - asFiniteNumber(args[1], "age", 1), "age")
|
|
7928
|
+
},
|
|
7929
|
+
convert: {
|
|
7930
|
+
minArgs: 3,
|
|
7931
|
+
maxArgs: 3,
|
|
7932
|
+
apply: (args, hooks) => {
|
|
7933
|
+
const x = asFiniteNumber(args[0], "convert", 0);
|
|
7934
|
+
const from = asString$1(args[1], "convert", 1).trim();
|
|
7935
|
+
const to = asString$1(args[2], "convert", 2).trim();
|
|
7936
|
+
if (hooks.convert) {
|
|
7937
|
+
const out = hooks.convert(x, from, to);
|
|
7938
|
+
if (out === null) throw new ExpressionEvalError(`convert: cannot convert '${from}' to '${to}'`);
|
|
7939
|
+
return finiteResult(out, "convert");
|
|
7940
|
+
}
|
|
7941
|
+
if (from === to) return x;
|
|
7942
|
+
throw new ExpressionEvalError("convert: unit conversion table not installed");
|
|
7943
|
+
}
|
|
7944
|
+
}
|
|
7945
|
+
};
|
|
7946
|
+
Object.freeze(Object.assign(Object.create(null), table));
|
|
7947
|
+
/** The set of valid builtin names — used by the parser to reject unknown
|
|
7948
|
+
* callees at parse time (immediate author feedback). */
|
|
7949
|
+
var EXPRESSION_BUILTIN_NAMES = new Set(Object.keys(table));
|
|
7950
|
+
/**
|
|
7951
|
+
* Pratt (precedence-climbing) parser for the safe expression mini-language.
|
|
7952
|
+
*
|
|
7953
|
+
* Precedence (low → high): ternary `?:` (right-assoc) → `||` → `&&` → equality
|
|
7954
|
+
* → relational → additive → multiplicative → unary `! -` → call / primary.
|
|
7955
|
+
* Calls are ONLY `IDENT '(' args? ')'` at primary position — the callee is a
|
|
7956
|
+
* string validated against the builtin table at parse time, so an unknown
|
|
7957
|
+
* function is rejected immediately (author feedback) and a persisted expression
|
|
7958
|
+
* that references a since-removed builtin degrades at read.
|
|
7959
|
+
*
|
|
7960
|
+
* A node counter caps total AST size (`MAX_EXPRESSION_AST_NODES`) and call
|
|
7961
|
+
* arity is capped (`MAX_EXPRESSION_CALL_ARGS`) — both raise `ExpressionParseError`.
|
|
7962
|
+
*/
|
|
7963
|
+
/** Binary/logical operator precedence (higher binds tighter). */
|
|
7964
|
+
var BINARY_PRECEDENCE = {
|
|
7965
|
+
"||": 1,
|
|
7966
|
+
"&&": 2,
|
|
7967
|
+
"==": 3,
|
|
7968
|
+
"!=": 3,
|
|
7969
|
+
"<": 4,
|
|
7970
|
+
"<=": 4,
|
|
7971
|
+
">": 4,
|
|
7972
|
+
">=": 4,
|
|
7973
|
+
"+": 5,
|
|
7974
|
+
"-": 5,
|
|
7975
|
+
"*": 6,
|
|
7976
|
+
"/": 6,
|
|
7977
|
+
"%": 6
|
|
7978
|
+
};
|
|
7979
|
+
function isLogicalOp(op) {
|
|
7980
|
+
return op === "&&" || op === "||";
|
|
7981
|
+
}
|
|
7982
|
+
function isBinaryOp(op) {
|
|
7983
|
+
return op === "+" || op === "-" || op === "*" || op === "/" || op === "%" || op === "==" || op === "!=" || op === "<" || op === "<=" || op === ">" || op === ">=";
|
|
7984
|
+
}
|
|
7985
|
+
var Parser = class {
|
|
7986
|
+
tokens;
|
|
7987
|
+
pos = 0;
|
|
7988
|
+
nodeCount = 0;
|
|
7989
|
+
identifiers = /* @__PURE__ */ new Set();
|
|
7990
|
+
callees = /* @__PURE__ */ new Set();
|
|
7991
|
+
constructor(tokens) {
|
|
7992
|
+
this.tokens = tokens;
|
|
7993
|
+
}
|
|
7994
|
+
parse() {
|
|
7995
|
+
const ast = this.parseTernary();
|
|
7996
|
+
const tok = this.peek();
|
|
7997
|
+
if (tok.type !== "eof") throw new ExpressionParseError("unexpected trailing input", tok.pos);
|
|
7998
|
+
return {
|
|
7999
|
+
ast,
|
|
8000
|
+
identifiers: this.identifiers,
|
|
8001
|
+
callees: this.callees,
|
|
8002
|
+
nodeCount: this.nodeCount
|
|
8003
|
+
};
|
|
8004
|
+
}
|
|
8005
|
+
peek() {
|
|
8006
|
+
return this.tokens[this.pos];
|
|
8007
|
+
}
|
|
8008
|
+
next() {
|
|
8009
|
+
return this.tokens[this.pos++];
|
|
8010
|
+
}
|
|
8011
|
+
/** Consume a punctuator token, erroring if the next token isn't it. */
|
|
8012
|
+
expectPunct(punct) {
|
|
8013
|
+
const tok = this.peek();
|
|
8014
|
+
if (tok.type !== "punct" || tok.punct !== punct) throw new ExpressionParseError(`expected '${punct}'`, tok.pos);
|
|
8015
|
+
this.pos += 1;
|
|
8016
|
+
}
|
|
8017
|
+
matchPunct(punct) {
|
|
8018
|
+
const tok = this.peek();
|
|
8019
|
+
if (tok.type === "punct" && tok.punct === punct) {
|
|
8020
|
+
this.pos += 1;
|
|
8021
|
+
return true;
|
|
8022
|
+
}
|
|
8023
|
+
return false;
|
|
8024
|
+
}
|
|
8025
|
+
countNode() {
|
|
8026
|
+
this.nodeCount += 1;
|
|
8027
|
+
if (this.nodeCount > 256) throw new ExpressionParseError("expression too complex", this.peek().pos);
|
|
8028
|
+
}
|
|
8029
|
+
parseTernary() {
|
|
8030
|
+
const test = this.parseBinary(1);
|
|
8031
|
+
if (this.matchPunct("?")) {
|
|
8032
|
+
const consequent = this.parseTernary();
|
|
8033
|
+
this.expectPunct(":");
|
|
8034
|
+
const alternate = this.parseTernary();
|
|
8035
|
+
this.countNode();
|
|
8036
|
+
return {
|
|
8037
|
+
kind: "conditional",
|
|
8038
|
+
test,
|
|
8039
|
+
consequent,
|
|
8040
|
+
alternate
|
|
8041
|
+
};
|
|
8042
|
+
}
|
|
8043
|
+
return test;
|
|
8044
|
+
}
|
|
8045
|
+
parseBinary(minPrec) {
|
|
8046
|
+
let left = this.parseUnary();
|
|
8047
|
+
for (;;) {
|
|
8048
|
+
const tok = this.peek();
|
|
8049
|
+
if (tok.type !== "punct") break;
|
|
8050
|
+
const prec = BINARY_PRECEDENCE[tok.punct];
|
|
8051
|
+
if (prec === void 0 || prec < minPrec) break;
|
|
8052
|
+
const op = tok.punct;
|
|
8053
|
+
this.pos += 1;
|
|
8054
|
+
const right = this.parseBinary(prec + 1);
|
|
8055
|
+
this.countNode();
|
|
8056
|
+
if (isLogicalOp(op)) left = {
|
|
8057
|
+
kind: "logical",
|
|
8058
|
+
op,
|
|
8059
|
+
left,
|
|
8060
|
+
right
|
|
8061
|
+
};
|
|
8062
|
+
else if (isBinaryOp(op)) left = {
|
|
8063
|
+
kind: "binary",
|
|
8064
|
+
op,
|
|
8065
|
+
left,
|
|
8066
|
+
right
|
|
8067
|
+
};
|
|
8068
|
+
else throw new ExpressionParseError(`unexpected operator '${op}'`, tok.pos);
|
|
8069
|
+
}
|
|
8070
|
+
return left;
|
|
8071
|
+
}
|
|
8072
|
+
parseUnary() {
|
|
8073
|
+
const tok = this.peek();
|
|
8074
|
+
if (tok.type === "punct" && (tok.punct === "!" || tok.punct === "-")) {
|
|
8075
|
+
const op = tok.punct;
|
|
8076
|
+
this.pos += 1;
|
|
8077
|
+
const operand = this.parseUnary();
|
|
8078
|
+
this.countNode();
|
|
8079
|
+
return {
|
|
8080
|
+
kind: "unary",
|
|
8081
|
+
op,
|
|
8082
|
+
operand
|
|
8083
|
+
};
|
|
8084
|
+
}
|
|
8085
|
+
return this.parsePrimary();
|
|
8086
|
+
}
|
|
8087
|
+
parsePrimary() {
|
|
8088
|
+
const tok = this.next();
|
|
8089
|
+
switch (tok.type) {
|
|
8090
|
+
case "number":
|
|
8091
|
+
this.countNode();
|
|
8092
|
+
return {
|
|
8093
|
+
kind: "literal",
|
|
8094
|
+
value: tok.value
|
|
8095
|
+
};
|
|
8096
|
+
case "string":
|
|
8097
|
+
this.countNode();
|
|
8098
|
+
return {
|
|
8099
|
+
kind: "literal",
|
|
8100
|
+
value: tok.value
|
|
8101
|
+
};
|
|
8102
|
+
case "keyword":
|
|
8103
|
+
this.countNode();
|
|
8104
|
+
return {
|
|
8105
|
+
kind: "literal",
|
|
8106
|
+
value: tok.keyword === "null" ? null : tok.keyword === "true"
|
|
8107
|
+
};
|
|
8108
|
+
case "identifier": {
|
|
8109
|
+
const nextTok = this.peek();
|
|
8110
|
+
if (nextTok.type === "punct" && nextTok.punct === "(") return this.parseCall(tok.name, tok.pos);
|
|
8111
|
+
this.identifiers.add(tok.name);
|
|
8112
|
+
this.countNode();
|
|
8113
|
+
return {
|
|
8114
|
+
kind: "identifier",
|
|
8115
|
+
name: tok.name
|
|
8116
|
+
};
|
|
8117
|
+
}
|
|
8118
|
+
case "punct":
|
|
8119
|
+
if (tok.punct === "(") {
|
|
8120
|
+
const inner = this.parseTernary();
|
|
8121
|
+
this.expectPunct(")");
|
|
8122
|
+
return inner;
|
|
8123
|
+
}
|
|
8124
|
+
throw new ExpressionParseError(`unexpected token '${tok.punct}'`, tok.pos);
|
|
8125
|
+
case "eof": throw new ExpressionParseError("unexpected end of expression", tok.pos);
|
|
8126
|
+
}
|
|
8127
|
+
}
|
|
8128
|
+
parseCall(callee, pos) {
|
|
8129
|
+
if (!EXPRESSION_BUILTIN_NAMES.has(callee)) throw new ExpressionParseError(`unknown function '${callee}'`, pos);
|
|
8130
|
+
this.expectPunct("(");
|
|
8131
|
+
const args = [];
|
|
8132
|
+
if (!this.matchPunct(")")) for (;;) {
|
|
8133
|
+
args.push(this.parseTernary());
|
|
8134
|
+
if (args.length > 16) throw new ExpressionParseError(`too many arguments to '${callee}'`, pos);
|
|
8135
|
+
if (this.matchPunct(",")) continue;
|
|
8136
|
+
this.expectPunct(")");
|
|
8137
|
+
break;
|
|
8138
|
+
}
|
|
8139
|
+
this.callees.add(callee);
|
|
8140
|
+
this.countNode();
|
|
8141
|
+
return {
|
|
8142
|
+
kind: "call",
|
|
8143
|
+
callee,
|
|
8144
|
+
args
|
|
8145
|
+
};
|
|
8146
|
+
}
|
|
8147
|
+
};
|
|
8148
|
+
/** Tokenize + parse `source` into a validated `ParsedExpression`. Throws
|
|
8149
|
+
* `ExpressionParseError` on any lexical or grammatical failure. */
|
|
8150
|
+
function parseExpression(source) {
|
|
8151
|
+
return new Parser(tokenize(source)).parse();
|
|
8152
|
+
}
|
|
8153
|
+
Object.freeze({});
|
|
8154
|
+
/**
|
|
8155
|
+
* LRU compile cache for parsed expressions (spec §2.4 "parse once … LRU keyed
|
|
8156
|
+
* by expr"). The cache stores BOTH successes and failures (negative caching),
|
|
8157
|
+
* so a corrupt persisted string costs exactly one tokenize+parse total — not
|
|
8158
|
+
* one per read on a hot resolve path.
|
|
8159
|
+
*
|
|
8160
|
+
* The cache is a module-level singleton: entries are pure, content-addressed
|
|
8161
|
+
* ASTs keyed by the raw source string, so sharing one instance across all
|
|
8162
|
+
* callers is safe and maximises hit rate.
|
|
8163
|
+
*/
|
|
8164
|
+
var cache = /* @__PURE__ */ new Map();
|
|
8165
|
+
function getCached(source) {
|
|
8166
|
+
const hit = cache.get(source);
|
|
8167
|
+
if (hit !== void 0) {
|
|
8168
|
+
cache.delete(source);
|
|
8169
|
+
cache.set(source, hit);
|
|
8170
|
+
return hit;
|
|
8171
|
+
}
|
|
8172
|
+
let result;
|
|
8173
|
+
try {
|
|
8174
|
+
result = {
|
|
8175
|
+
ok: true,
|
|
8176
|
+
parsed: parseExpression(source)
|
|
8177
|
+
};
|
|
8178
|
+
} catch (err) {
|
|
8179
|
+
result = {
|
|
8180
|
+
ok: false,
|
|
8181
|
+
error: err instanceof ExpressionParseError ? err.message : String(err)
|
|
8182
|
+
};
|
|
8183
|
+
}
|
|
8184
|
+
cache.set(source, result);
|
|
8185
|
+
if (cache.size > 256) {
|
|
8186
|
+
const oldest = cache.keys().next().value;
|
|
8187
|
+
if (oldest !== void 0) cache.delete(oldest);
|
|
8188
|
+
}
|
|
8189
|
+
return result;
|
|
8190
|
+
}
|
|
8191
|
+
/** Compile `source`, returning a discriminated result instead of throwing.
|
|
8192
|
+
* Used by read paths that must degrade rather than raise. LRU/negative-cached. */
|
|
8193
|
+
function compileExpressionSafe(source) {
|
|
8194
|
+
return getCached(source);
|
|
8195
|
+
}
|
|
8196
|
+
/**
|
|
8197
|
+
* Author-time validation. Returns `null` when the source is valid, else a
|
|
8198
|
+
* human-readable error message. Checks: the expression compiles; binding count
|
|
8199
|
+
* is within `MAX_EXPRESSION_BINDINGS`; every binding name is a legal identifier,
|
|
8200
|
+
* is not reserved (`now`/keywords) and does not shadow a builtin; and every
|
|
8201
|
+
* FREE identifier of the AST is covered by a binding or the injected `now`.
|
|
8202
|
+
*/
|
|
8203
|
+
function validateExpressionSource(src) {
|
|
8204
|
+
const names = Object.keys(src.bindings);
|
|
8205
|
+
if (names.length > 32) return `too many bindings (${names.length} > 32)`;
|
|
8206
|
+
for (const name of names) {
|
|
8207
|
+
if (!EXPRESSION_IDENTIFIER_RE.test(name)) return `invalid binding name '${name}'`;
|
|
8208
|
+
if (RESERVED_BINDING_NAMES.has(name)) return `binding name '${name}' is reserved`;
|
|
8209
|
+
if (EXPRESSION_BUILTIN_NAMES.has(name)) return `binding name '${name}' shadows a builtin function`;
|
|
8210
|
+
}
|
|
8211
|
+
const compiled = compileExpressionSafe(src.expr);
|
|
8212
|
+
if (!compiled.ok) return compiled.error;
|
|
8213
|
+
const bound = new Set(names);
|
|
8214
|
+
for (const id of compiled.parsed.identifiers) {
|
|
8215
|
+
if (id === "now") continue;
|
|
8216
|
+
if (!bound.has(id)) return `expression references unbound identifier '${id}'`;
|
|
8217
|
+
}
|
|
8218
|
+
return null;
|
|
8219
|
+
}
|
|
8220
|
+
/**
|
|
7442
8221
|
* Accessory device helpers — shared across drivers.
|
|
7443
8222
|
*
|
|
7444
8223
|
* Many vendor-specific drivers register accessory child devices on
|
|
@@ -8283,7 +9062,13 @@ onStatusChanged: { data: object({
|
|
|
8283
9062
|
}) } },
|
|
8284
9063
|
status: {
|
|
8285
9064
|
schema: BatteryStatusSchema,
|
|
8286
|
-
kind: "push"
|
|
9065
|
+
kind: "push",
|
|
9066
|
+
empty: {
|
|
9067
|
+
percentage: 0,
|
|
9068
|
+
charging: "none",
|
|
9069
|
+
sleeping: false,
|
|
9070
|
+
lastUpdated: 0
|
|
9071
|
+
}
|
|
8287
9072
|
},
|
|
8288
9073
|
/**
|
|
8289
9074
|
* Runtime-state slice — every provider that registers this cap
|
|
@@ -8422,6 +9207,10 @@ var RtspRestreamEntrySchema = object({
|
|
|
8422
9207
|
var BrokerRtspClientSchema = object({
|
|
8423
9208
|
sessionId: string(),
|
|
8424
9209
|
remoteAddr: string(),
|
|
9210
|
+
/** Client `User-Agent` (e.g. `recorder` for the recorder's RTSP pull), or
|
|
9211
|
+
* null/absent when the client sent none. Lets the UI label a consumer by
|
|
9212
|
+
* purpose. Optional so a client built against an older schema stays valid. */
|
|
9213
|
+
userAgent: string().nullish(),
|
|
8425
9214
|
playing: boolean(),
|
|
8426
9215
|
muted: boolean(),
|
|
8427
9216
|
connectedAt: number(),
|
|
@@ -9222,21 +10011,38 @@ var connectivityCapability = {
|
|
|
9222
10011
|
},
|
|
9223
10012
|
runtimeState: ConnectivityStatusSchema
|
|
9224
10013
|
};
|
|
10014
|
+
/**
|
|
10015
|
+
* Generic device-consumables capability — surfaces a device's
|
|
10016
|
+
* maintenance items (vacuum filters/brushes, replaceable cartridges,
|
|
10017
|
+
* descaling cycles, …) with their remaining life and an optional
|
|
10018
|
+
* "Replaced" reset action. Device-agnostic: any provider that knows its
|
|
10019
|
+
* device tracks consumables can register it; the cap declares no
|
|
10020
|
+
* vocabulary of its own — the provider names each item verbatim.
|
|
10021
|
+
*
|
|
10022
|
+
* Like `childLayout`, the cap is INERT until a provider sets items: no
|
|
10023
|
+
* provider populates it by guessing (no HA inference). The UI renders a
|
|
10024
|
+
* "No consumables reported" placeholder when `items` is empty.
|
|
10025
|
+
*/
|
|
10026
|
+
/** A single consumable item. Either a continuous `level` (remaining
|
|
10027
|
+
* life %) or a discrete `status` may be known — both may be null when a
|
|
10028
|
+
* provider only knows the item exists. `level` and `status` are not
|
|
10029
|
+
* mutually exclusive; a provider may report both. */
|
|
10030
|
+
var ConsumableItemSchema = object({
|
|
10031
|
+
/** Stable id, e.g. 'main-brush'. */
|
|
10032
|
+
key: string().min(1),
|
|
10033
|
+
/** Display name. */
|
|
10034
|
+
label: string().min(1),
|
|
10035
|
+
/** Remaining life % when known (0..100). */
|
|
10036
|
+
level: number().min(0).max(100).nullable(),
|
|
10037
|
+
/** Discrete state when known (binary mode). */
|
|
10038
|
+
status: _enum(["ok", "replace"]).nullable(),
|
|
10039
|
+
/** Ms epoch of the last replace, when known. */
|
|
10040
|
+
lastResetAt: number().nullable(),
|
|
10041
|
+
/** Whether `reset()` is meaningful for this item. */
|
|
10042
|
+
resettable: boolean()
|
|
10043
|
+
});
|
|
9225
10044
|
var ConsumablesStatusSchema = object({
|
|
9226
|
-
items: array(
|
|
9227
|
-
/** Stable id, e.g. 'main-brush'. */
|
|
9228
|
-
key: string().min(1),
|
|
9229
|
-
/** Display name. */
|
|
9230
|
-
label: string().min(1),
|
|
9231
|
-
/** Remaining life % when known (0..100). */
|
|
9232
|
-
level: number().min(0).max(100).nullable(),
|
|
9233
|
-
/** Discrete state when known (binary mode). */
|
|
9234
|
-
status: _enum(["ok", "replace"]).nullable(),
|
|
9235
|
-
/** Ms epoch of the last replace, when known. */
|
|
9236
|
-
lastResetAt: number().nullable(),
|
|
9237
|
-
/** Whether `reset()` is meaningful for this item. */
|
|
9238
|
-
resettable: boolean()
|
|
9239
|
-
})),
|
|
10045
|
+
items: array(ConsumableItemSchema),
|
|
9240
10046
|
lastChangedAt: number()
|
|
9241
10047
|
});
|
|
9242
10048
|
var consumablesCapability = {
|
|
@@ -9295,7 +10101,25 @@ reset: method(object({
|
|
|
9295
10101
|
}) },
|
|
9296
10102
|
status: {
|
|
9297
10103
|
schema: ConsumablesStatusSchema,
|
|
9298
|
-
kind: "push"
|
|
10104
|
+
kind: "push",
|
|
10105
|
+
empty: {
|
|
10106
|
+
items: [],
|
|
10107
|
+
lastChangedAt: 0
|
|
10108
|
+
},
|
|
10109
|
+
itemArray: {
|
|
10110
|
+
path: "items",
|
|
10111
|
+
keyField: "key",
|
|
10112
|
+
labelField: "label",
|
|
10113
|
+
itemSchema: ConsumableItemSchema,
|
|
10114
|
+
emptyItem: {
|
|
10115
|
+
key: "",
|
|
10116
|
+
label: "",
|
|
10117
|
+
level: null,
|
|
10118
|
+
status: null,
|
|
10119
|
+
lastResetAt: null,
|
|
10120
|
+
resettable: false
|
|
10121
|
+
}
|
|
10122
|
+
}
|
|
9299
10123
|
},
|
|
9300
10124
|
runtimeState: ConsumablesStatusSchema.extend({ lastFetchedAt: number() })
|
|
9301
10125
|
};
|
|
@@ -10537,7 +11361,8 @@ var MotionAnalysisResultSchema = object({
|
|
|
10537
11361
|
});
|
|
10538
11362
|
method(object({
|
|
10539
11363
|
deviceId: number(),
|
|
10540
|
-
frame: FrameInputSchema
|
|
11364
|
+
frame: FrameInputSchema.optional(),
|
|
11365
|
+
frameHandle: FrameHandleSchema.optional()
|
|
10541
11366
|
}), MotionAnalysisResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), _void(), { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), object({
|
|
10542
11367
|
deviceId: number(),
|
|
10543
11368
|
detected: boolean(),
|
|
@@ -10784,6 +11609,12 @@ method(_void(), array(PipelineEngineChoiceSchema)), method(_void(), PipelineEngi
|
|
|
10784
11609
|
engine: PipelineEngineChoiceSchema.optional(),
|
|
10785
11610
|
steps: array(PipelineStepInputSchema).min(1),
|
|
10786
11611
|
frame: FrameInputSchema.optional(),
|
|
11612
|
+
/**
|
|
11613
|
+
* CB5 shm passthrough — a `FrameHandle` naming the same ring slot
|
|
11614
|
+
* the decoded pixels live in. One more member of the one-of
|
|
11615
|
+
* frame/frameHandle/image/imageBase64/referenceImage group.
|
|
11616
|
+
*/
|
|
11617
|
+
frameHandle: FrameHandleSchema.optional(),
|
|
10787
11618
|
imageBase64: string().optional(),
|
|
10788
11619
|
/**
|
|
10789
11620
|
* Binary JPEG bytes — preferred over `imageBase64` on internal
|
|
@@ -11026,6 +11857,31 @@ var ReportMotionInputSchema = object({
|
|
|
11026
11857
|
regions: array(MotionRegionSchema).readonly().optional()
|
|
11027
11858
|
});
|
|
11028
11859
|
/**
|
|
11860
|
+
* Where a runner gets a camera's decoded frames (cross-node Phase 2,
|
|
11861
|
+
* restream-owner model — P2c).
|
|
11862
|
+
*
|
|
11863
|
+
* - `local-broker` (DEFAULT): today's path — subscribe to the co-located
|
|
11864
|
+
* stream-broker's shm frame plane. Every pre-P2c attach payload (no
|
|
11865
|
+
* `frameSource` key) parses to this, so the field is additive with zero
|
|
11866
|
+
* behavior change.
|
|
11867
|
+
* - `remote-restream`: the detect node is NOT the camera's source-owner.
|
|
11868
|
+
* The runner acquires the owner's COMPRESSED passthrough restream
|
|
11869
|
+
* (`streamBroker.getStreamWithCodec({video:'copy'})` — refcounted, the
|
|
11870
|
+
* double-pull guard) and decodes LOCALLY via a satellite frame plane +
|
|
11871
|
+
* pull-mode decoder session pinned to its own node. The shm ring stays
|
|
11872
|
+
* node-local; only H.264/H.265 packets cross the wire.
|
|
11873
|
+
* `hubHostnameOverride` mirrors the recorder's `recordingHubHostname`:
|
|
11874
|
+
* when set it overrides the `CAMSTACK_HUB_URL`-derived host the runner
|
|
11875
|
+
* dials for the owner's restream.
|
|
11876
|
+
*/
|
|
11877
|
+
var RunnerFrameSourceSchema = discriminatedUnion("kind", [object({ kind: literal("local-broker") }), object({
|
|
11878
|
+
kind: literal("remote-restream"),
|
|
11879
|
+
/** The camera's source-owner node (slice 1: always the hub). */
|
|
11880
|
+
ownerNodeId: string(),
|
|
11881
|
+
/** Operator override for the owner host the runner dials. */
|
|
11882
|
+
hubHostnameOverride: string().optional()
|
|
11883
|
+
})]).describe("Per-camera frame-source mode for the runner (P2c)");
|
|
11884
|
+
/**
|
|
11029
11885
|
* Camera assignment payload sent by `addon-pipeline-orchestrator` to a
|
|
11030
11886
|
* specific runner instance via `attachCamera`. Carries everything the
|
|
11031
11887
|
* runner needs to subscribe to the local broker and execute inference.
|
|
@@ -11123,7 +11979,15 @@ var RunnerCameraConfigSchema = object({
|
|
|
11123
11979
|
*/
|
|
11124
11980
|
onboardMotionDrivesAnalyzer: boolean().default(true),
|
|
11125
11981
|
occupancyRecheckSec: number().min(occupancyRecheckSecField.min).max(occupancyRecheckSecField.max).default(occupancyRecheckSecField.default),
|
|
11126
|
-
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default)
|
|
11982
|
+
occupancyRecheckFrames: number().min(occupancyRecheckFramesField.min).max(occupancyRecheckFramesField.max).default(occupancyRecheckFramesField.default),
|
|
11983
|
+
/**
|
|
11984
|
+
* Where this runner gets the camera's decoded frames (P2c). Defaulted so
|
|
11985
|
+
* every existing payload behaves as `local-broker` — the pre-Phase-2 path.
|
|
11986
|
+
* Populated with `remote-restream` by the orchestrator ONLY when the
|
|
11987
|
+
* camera's detect node differs from its source-owner (P2d, gated by the
|
|
11988
|
+
* `remoteSourcingNodes` rollout setting).
|
|
11989
|
+
*/
|
|
11990
|
+
frameSource: RunnerFrameSourceSchema.default({ kind: "local-broker" })
|
|
11127
11991
|
});
|
|
11128
11992
|
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;
|
|
11129
11993
|
/**
|
|
@@ -11687,6 +12551,157 @@ var numericSensorCapability = {
|
|
|
11687
12551
|
runtimeState: NumericSensorStatusSchema
|
|
11688
12552
|
};
|
|
11689
12553
|
/**
|
|
12554
|
+
* Feeder connectivity / power status — mirrors the HA petkit device-status
|
|
12555
|
+
* enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
|
|
12556
|
+
* `on_batteries` (running on battery backup). `null` until first reported.
|
|
12557
|
+
*/
|
|
12558
|
+
var PetFeederDeviceStatusSchema = _enum([
|
|
12559
|
+
"normal",
|
|
12560
|
+
"offline",
|
|
12561
|
+
"on_batteries"
|
|
12562
|
+
]);
|
|
12563
|
+
var gramsPortion = number().int().min(4).max(200);
|
|
12564
|
+
var PetFeederStatusSchema = object({
|
|
12565
|
+
/** Food currently in the bowl (grams). Null when the device has not
|
|
12566
|
+
* reported a reading yet. On dual-hopper models this is the combined
|
|
12567
|
+
* bowl reading; per-hopper levels live in `food1`/`food2`. */
|
|
12568
|
+
foodLevel: number().nullable(),
|
|
12569
|
+
/** Hopper-1 food level (grams) on dual-hopper feeders; null on
|
|
12570
|
+
* single-hopper models. */
|
|
12571
|
+
food1: number().nullable(),
|
|
12572
|
+
/** Hopper-2 food level (grams) on dual-hopper feeders; null on
|
|
12573
|
+
* single-hopper models. */
|
|
12574
|
+
food2: number().nullable(),
|
|
12575
|
+
/** Derived low-food flag — mirrors the HA `food_level` binary_sensor
|
|
12576
|
+
* (`device_class: problem`, on = low). True when the bowl is empty /
|
|
12577
|
+
* below the feeder's low threshold. */
|
|
12578
|
+
lowFood: boolean(),
|
|
12579
|
+
/** Battery charge 0..100 (%). Null on mains-powered models or when the
|
|
12580
|
+
* device has no battery reading. */
|
|
12581
|
+
batteryPower: number().min(0).max(100).nullable(),
|
|
12582
|
+
/** Days of desiccant life remaining. Null when the model has no
|
|
12583
|
+
* desiccant sensor. */
|
|
12584
|
+
desiccantLeftDays: number().nullable(),
|
|
12585
|
+
/** True while a feed is in progress. */
|
|
12586
|
+
feeding: boolean(),
|
|
12587
|
+
/** Decoded connectivity / power status (HA petkit device-status enum).
|
|
12588
|
+
* Null until the device has reported a status. */
|
|
12589
|
+
status: PetFeederDeviceStatusSchema.nullable(),
|
|
12590
|
+
/** Decoded human-readable fault message. Null (or the device's `no_error`
|
|
12591
|
+
* sentinel) means healthy; a non-null string is an active fault. Pairs
|
|
12592
|
+
* with `errorCode` for consumers that want the raw integer. */
|
|
12593
|
+
error: string().nullable(),
|
|
12594
|
+
/** Raw device error code (0 / null = no error). */
|
|
12595
|
+
errorCode: number().nullable(),
|
|
12596
|
+
/** True for D4S/D4SH dual-hopper hardware — gates the per-hopper UI. */
|
|
12597
|
+
isDualHopper: boolean(),
|
|
12598
|
+
/** Child-lock (manual-lock) setting — buttons on the unit are disabled. */
|
|
12599
|
+
childLock: boolean(),
|
|
12600
|
+
/** Front indicator-light setting. */
|
|
12601
|
+
indicatorLight: boolean(),
|
|
12602
|
+
/** Play a chime when dispensing. */
|
|
12603
|
+
feedSound: boolean(),
|
|
12604
|
+
/** Speaker / prompt volume level (device-scaled integer). */
|
|
12605
|
+
volume: number(),
|
|
12606
|
+
/** Ms epoch when the slice was last refreshed from the cloud. */
|
|
12607
|
+
lastFetchedAt: number()
|
|
12608
|
+
});
|
|
12609
|
+
var petFeederCapability = {
|
|
12610
|
+
name: "pet-feeder",
|
|
12611
|
+
scope: "device",
|
|
12612
|
+
deviceNative: true,
|
|
12613
|
+
mode: "singleton",
|
|
12614
|
+
deviceTypes: [DeviceType.PetFeeder],
|
|
12615
|
+
methods: {
|
|
12616
|
+
/**
|
|
12617
|
+
* Dispense food now. Single-hopper feeders take `grams`; dual-hopper
|
|
12618
|
+
* feeders (D4S/D4SH) accept `hopper1`/`hopper2` to target one or both
|
|
12619
|
+
* hoppers. All portions honour the 4–200 g hardware range. At least
|
|
12620
|
+
* one of the three must be present — the provider rejects an empty
|
|
12621
|
+
* request.
|
|
12622
|
+
*/
|
|
12623
|
+
feed: method(object({
|
|
12624
|
+
deviceId: number().int().nonnegative(),
|
|
12625
|
+
grams: gramsPortion.optional(),
|
|
12626
|
+
hopper1: gramsPortion.optional(),
|
|
12627
|
+
hopper2: gramsPortion.optional()
|
|
12628
|
+
}), _void(), {
|
|
12629
|
+
kind: "mutation",
|
|
12630
|
+
auth: "admin"
|
|
12631
|
+
}),
|
|
12632
|
+
/** Cancel an in-progress manual feed. */
|
|
12633
|
+
cancelFeed: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12634
|
+
kind: "mutation",
|
|
12635
|
+
auth: "admin"
|
|
12636
|
+
}),
|
|
12637
|
+
/** Reset the desiccant "days remaining" counter after replacing it. */
|
|
12638
|
+
resetDesiccant: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12639
|
+
kind: "mutation",
|
|
12640
|
+
auth: "admin"
|
|
12641
|
+
}),
|
|
12642
|
+
/** Mark a hopper as refilled (D4H/D4S/D4SH). */
|
|
12643
|
+
markFoodReplenished: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12644
|
+
kind: "mutation",
|
|
12645
|
+
auth: "admin"
|
|
12646
|
+
}),
|
|
12647
|
+
/** Call the pet with the recorded prompt (D3). */
|
|
12648
|
+
callPet: method(object({ deviceId: number().int().nonnegative() }), _void(), {
|
|
12649
|
+
kind: "mutation",
|
|
12650
|
+
auth: "admin"
|
|
12651
|
+
}),
|
|
12652
|
+
/** Play a stored sound by id (D3 / D4H / D4SH). */
|
|
12653
|
+
playSound: method(object({
|
|
12654
|
+
deviceId: number().int().nonnegative(),
|
|
12655
|
+
soundId: number().int().nonnegative()
|
|
12656
|
+
}), _void(), {
|
|
12657
|
+
kind: "mutation",
|
|
12658
|
+
auth: "admin"
|
|
12659
|
+
}),
|
|
12660
|
+
/** Toggle the child-lock (manual-lock) setting. */
|
|
12661
|
+
setChildLock: method(object({
|
|
12662
|
+
deviceId: number().int().nonnegative(),
|
|
12663
|
+
on: boolean()
|
|
12664
|
+
}), _void(), {
|
|
12665
|
+
kind: "mutation",
|
|
12666
|
+
auth: "admin"
|
|
12667
|
+
}),
|
|
12668
|
+
/** Toggle the front indicator light. */
|
|
12669
|
+
setIndicatorLight: method(object({
|
|
12670
|
+
deviceId: number().int().nonnegative(),
|
|
12671
|
+
on: boolean()
|
|
12672
|
+
}), _void(), {
|
|
12673
|
+
kind: "mutation",
|
|
12674
|
+
auth: "admin"
|
|
12675
|
+
}),
|
|
12676
|
+
/** Toggle the dispense chime. */
|
|
12677
|
+
setFeedSound: method(object({
|
|
12678
|
+
deviceId: number().int().nonnegative(),
|
|
12679
|
+
on: boolean()
|
|
12680
|
+
}), _void(), {
|
|
12681
|
+
kind: "mutation",
|
|
12682
|
+
auth: "admin"
|
|
12683
|
+
}),
|
|
12684
|
+
/** Set the speaker / prompt volume level. */
|
|
12685
|
+
setVolume: method(object({
|
|
12686
|
+
deviceId: number().int().nonnegative(),
|
|
12687
|
+
level: number().int().nonnegative()
|
|
12688
|
+
}), _void(), {
|
|
12689
|
+
kind: "mutation",
|
|
12690
|
+
auth: "admin"
|
|
12691
|
+
})
|
|
12692
|
+
},
|
|
12693
|
+
status: {
|
|
12694
|
+
schema: PetFeederStatusSchema,
|
|
12695
|
+
kind: "poll"
|
|
12696
|
+
},
|
|
12697
|
+
/**
|
|
12698
|
+
* Runtime-state slice — mirrored by the kernel. UI feeder cards read
|
|
12699
|
+
* the full slice via `device.state.petFeeder.value` and refresh on
|
|
12700
|
+
* every poll without re-querying the provider.
|
|
12701
|
+
*/
|
|
12702
|
+
runtimeState: PetFeederStatusSchema
|
|
12703
|
+
};
|
|
12704
|
+
/**
|
|
11690
12705
|
* Multi-metric electrical meter. One slice can carry any combination
|
|
11691
12706
|
* of instantaneous power (W), cumulative energy (kWh), voltage (V),
|
|
11692
12707
|
* and current (A) — all fields optional so a single-metric source
|
|
@@ -12989,6 +14004,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
|
|
|
12989
14004
|
nativeObjectDetection: nativeObjectDetectionCapability,
|
|
12990
14005
|
notifier: notifierCapability,
|
|
12991
14006
|
numericSensor: numericSensorCapability,
|
|
14007
|
+
petFeeder: petFeederCapability,
|
|
12992
14008
|
powerMeter: powerMeterCapability,
|
|
12993
14009
|
presence: presenceCapability,
|
|
12994
14010
|
pressureSensor: pressureSensorCapability,
|
|
@@ -14905,10 +15921,12 @@ method(object({ codec: string() }), boolean()), method(_void(), object({
|
|
|
14905
15921
|
url: string()
|
|
14906
15922
|
}), _void()), method(object({
|
|
14907
15923
|
sessionId: string(),
|
|
14908
|
-
maxCount: number().default(1)
|
|
15924
|
+
maxCount: number().default(1),
|
|
15925
|
+
waitMs: number().optional()
|
|
14909
15926
|
}), array(DecodedFrameSchema)), method(object({
|
|
14910
15927
|
sessionId: string(),
|
|
14911
|
-
maxCount: number().default(1)
|
|
15928
|
+
maxCount: number().default(1),
|
|
15929
|
+
waitMs: number().optional()
|
|
14912
15930
|
}), array(FrameHandleSchema)), method(object({ handle: FrameHandleSchema }), DecodedFrameSchema.nullable()), method(object({ sessionId: string() }), ShmRingStatsSchema.nullable()), method(object({
|
|
14913
15931
|
sessionId: string(),
|
|
14914
15932
|
config: DecoderSessionConfigSchema.partial()
|
|
@@ -15195,14 +16213,63 @@ var ChildLayoutEntrySchema = object({
|
|
|
15195
16213
|
collapsed: boolean().optional()
|
|
15196
16214
|
});
|
|
15197
16215
|
/** Cap-wire shape of a DeviceLink — structurally mirrors `DeviceLink` in
|
|
15198
|
-
* `device-management.ts`.
|
|
16216
|
+
* `device-management.ts`. Source is a union: a FIELD source copies a sibling
|
|
16217
|
+
* accessory's status field (`kind` optional/absent for wire compat); a
|
|
16218
|
+
* LITERAL source carries a per-device constant (no sibling is read); a
|
|
16219
|
+
* GLOBAL source (P2e) copies ANY device's status field, addressed by the
|
|
16220
|
+
* source device's full re-sync-stable `stableId`. */
|
|
16221
|
+
var DeviceLinkFieldSourceSchema = object({
|
|
16222
|
+
kind: literal("field").optional(),
|
|
16223
|
+
sourceKey: string(),
|
|
16224
|
+
cap: string(),
|
|
16225
|
+
fieldPath: string()
|
|
16226
|
+
});
|
|
16227
|
+
var DeviceLinkLiteralSourceSchema = object({
|
|
16228
|
+
kind: literal("literal"),
|
|
16229
|
+
value: union([
|
|
16230
|
+
string(),
|
|
16231
|
+
number(),
|
|
16232
|
+
boolean(),
|
|
16233
|
+
_null()
|
|
16234
|
+
])
|
|
16235
|
+
});
|
|
16236
|
+
var DeviceLinkGlobalSourceSchema = object({
|
|
16237
|
+
kind: literal("global"),
|
|
16238
|
+
sourceStableId: string(),
|
|
16239
|
+
cap: string(),
|
|
16240
|
+
fieldPath: string()
|
|
16241
|
+
});
|
|
16242
|
+
/** Expression source (Stage X): compute the target field from N named bindings
|
|
16243
|
+
* via the safe expression engine. Bindings are field | literal | global — never
|
|
16244
|
+
* another expression (no nesting). The `superRefine` runs the SAME author-time
|
|
16245
|
+
* validation as `validateExpressionSource` (compiles the expr, checks binding
|
|
16246
|
+
* names + identifier coverage) so every wire boundary that parses a DeviceLink
|
|
16247
|
+
* (tRPC mount, kernel create pre-seed, projection output) validates-at-write.
|
|
16248
|
+
* Compiles are LRU-cached, so repeated validation of the same expr is a hit. */
|
|
16249
|
+
var DeviceLinkExpressionSourceSchema = object({
|
|
16250
|
+
kind: literal("expression"),
|
|
16251
|
+
expr: string().min(1).max(MAX_EXPRESSION_SOURCE_LENGTH),
|
|
16252
|
+
bindings: record(string().regex(EXPRESSION_IDENTIFIER_RE), union([
|
|
16253
|
+
DeviceLinkFieldSourceSchema,
|
|
16254
|
+
DeviceLinkLiteralSourceSchema,
|
|
16255
|
+
DeviceLinkGlobalSourceSchema
|
|
16256
|
+
]))
|
|
16257
|
+
}).superRefine((src, ctx) => {
|
|
16258
|
+
const err = validateExpressionSource(src);
|
|
16259
|
+
if (err !== null) ctx.addIssue({
|
|
16260
|
+
code: "custom",
|
|
16261
|
+
message: err,
|
|
16262
|
+
path: ["expr"]
|
|
16263
|
+
});
|
|
16264
|
+
});
|
|
15199
16265
|
var DeviceLinkSchema = object({
|
|
15200
16266
|
id: string(),
|
|
15201
|
-
source:
|
|
15202
|
-
|
|
15203
|
-
|
|
15204
|
-
|
|
15205
|
-
|
|
16267
|
+
source: union([
|
|
16268
|
+
DeviceLinkFieldSourceSchema,
|
|
16269
|
+
DeviceLinkLiteralSourceSchema,
|
|
16270
|
+
DeviceLinkGlobalSourceSchema,
|
|
16271
|
+
DeviceLinkExpressionSourceSchema
|
|
16272
|
+
]),
|
|
15206
16273
|
target: object({
|
|
15207
16274
|
cap: string(),
|
|
15208
16275
|
fieldPath: string(),
|
|
@@ -15231,6 +16298,31 @@ var DeviceLinkSchema = object({
|
|
|
15231
16298
|
})
|
|
15232
16299
|
]).optional()
|
|
15233
16300
|
});
|
|
16301
|
+
/** Cap-wire shape of a per-cap display refinement — mirrors
|
|
16302
|
+
* `DeviceCapDisplayOverride` in `device-management.ts`. */
|
|
16303
|
+
var DeviceCapDisplayOverrideSchema = object({
|
|
16304
|
+
unit: string().min(1).optional(),
|
|
16305
|
+
precision: number().int().min(0).max(10).optional()
|
|
16306
|
+
});
|
|
16307
|
+
/** Cap-wire shape of an operator-authored per-device display override —
|
|
16308
|
+
* mirrors `DeviceDisplayOverride` in `device-management.ts`. `precision`
|
|
16309
|
+
* bounds mirror `numeric-sensor.cap.ts` (`int 0-10`). */
|
|
16310
|
+
var DeviceDisplayOverrideSchema = object({
|
|
16311
|
+
icon: string().min(1).optional(),
|
|
16312
|
+
label: string().min(1).optional(),
|
|
16313
|
+
unit: string().min(1).optional(),
|
|
16314
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16315
|
+
hidden: boolean().optional(),
|
|
16316
|
+
perCap: record(string(), DeviceCapDisplayOverrideSchema).optional()
|
|
16317
|
+
});
|
|
16318
|
+
/** Cap-wire shape of a per-role display default — mirrors `RoleDisplayDefault`
|
|
16319
|
+
* in `device-management.ts`. Keyed by `DeviceRole` string (role strings cross
|
|
16320
|
+
* the wire as plain strings everywhere else — cf. `DeviceInfoSchema.role`). */
|
|
16321
|
+
var RoleDisplayDefaultSchema = object({
|
|
16322
|
+
unit: string().min(1).optional(),
|
|
16323
|
+
precision: number().int().min(0).max(10).optional(),
|
|
16324
|
+
icon: string().min(1).optional()
|
|
16325
|
+
});
|
|
15234
16326
|
/**
|
|
15235
16327
|
* Serializable projection of a live IDevice.
|
|
15236
16328
|
* Returned by listAll, getDevice, getChildren.
|
|
@@ -15286,7 +16378,9 @@ var DeviceInfoSchema = object({
|
|
|
15286
16378
|
* `DeviceMeta.childLayout`. Absent ⇒ no layout declared. */
|
|
15287
16379
|
childLayout: array(ChildLayoutEntrySchema).readonly().optional(),
|
|
15288
16380
|
/** Operator-authored cross-device field wirings. See `DeviceMeta.deviceLinks`. */
|
|
15289
|
-
deviceLinks: array(DeviceLinkSchema).readonly().optional()
|
|
16381
|
+
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
16382
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16383
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15290
16384
|
});
|
|
15291
16385
|
var ConfigEntrySchema = object({
|
|
15292
16386
|
key: string(),
|
|
@@ -15351,7 +16445,9 @@ var DeviceMetaSchema = object({
|
|
|
15351
16445
|
deviceLinks: array(DeviceLinkSchema).readonly().optional(),
|
|
15352
16446
|
/** Semantic role string (`DeviceRole`) — propagated from the spawn pre-seed.
|
|
15353
16447
|
* Optional: only present for accessory children that carry a known role. */
|
|
15354
|
-
role: string().nullable().optional()
|
|
16448
|
+
role: string().nullable().optional(),
|
|
16449
|
+
/** Operator-authored per-device display override. See `DeviceMeta.display`. */
|
|
16450
|
+
display: DeviceDisplayOverrideSchema.optional()
|
|
15355
16451
|
});
|
|
15356
16452
|
/** ConfigUISchema passed through as unknown — mirrors device-provider's CreationSchemaOutputSchema */
|
|
15357
16453
|
var ConfigUISchemaOutput = unknown().nullable();
|
|
@@ -15445,7 +16541,19 @@ method(object({
|
|
|
15445
16541
|
}), _void(), {
|
|
15446
16542
|
kind: "mutation",
|
|
15447
16543
|
auth: "admin"
|
|
15448
|
-
}), method(object({
|
|
16544
|
+
}), method(object({
|
|
16545
|
+
deviceId: number(),
|
|
16546
|
+
display: DeviceDisplayOverrideSchema.nullable()
|
|
16547
|
+
}), _void(), {
|
|
16548
|
+
kind: "mutation",
|
|
16549
|
+
auth: "admin"
|
|
16550
|
+
}), method(object({}), object({ defaults: record(string(), RoleDisplayDefaultSchema) }), { kind: "query" }), method(object({ defaults: record(string(), RoleDisplayDefaultSchema) }), _void(), {
|
|
16551
|
+
kind: "mutation",
|
|
16552
|
+
auth: "admin"
|
|
16553
|
+
}), method(object({
|
|
16554
|
+
deviceId: number(),
|
|
16555
|
+
includeSynthesizable: boolean().optional()
|
|
16556
|
+
}), object({ caps: array(object({
|
|
15449
16557
|
cap: string(),
|
|
15450
16558
|
fields: array(object({
|
|
15451
16559
|
path: string(),
|
|
@@ -15455,8 +16563,13 @@ method(object({
|
|
|
15455
16563
|
"boolean",
|
|
15456
16564
|
"enum"
|
|
15457
16565
|
]),
|
|
15458
|
-
enumValues: array(string()).optional()
|
|
15459
|
-
|
|
16566
|
+
enumValues: array(string()).optional(),
|
|
16567
|
+
item: boolean().optional()
|
|
16568
|
+
})).readonly(),
|
|
16569
|
+
itemArray: object({
|
|
16570
|
+
path: string(),
|
|
16571
|
+
keyField: string()
|
|
16572
|
+
}).optional()
|
|
15460
16573
|
})).readonly() }), { kind: "query" }), method(object({
|
|
15461
16574
|
deviceId: number(),
|
|
15462
16575
|
role: string().nullable()
|
|
@@ -15526,7 +16639,11 @@ method(object({
|
|
|
15526
16639
|
deviceId: number(),
|
|
15527
16640
|
entries: array(object({
|
|
15528
16641
|
capName: string(),
|
|
15529
|
-
kind: _enum([
|
|
16642
|
+
kind: _enum([
|
|
16643
|
+
"native",
|
|
16644
|
+
"wrapped",
|
|
16645
|
+
"linked"
|
|
16646
|
+
]),
|
|
15530
16647
|
providerAddonId: string(),
|
|
15531
16648
|
providerNodeId: string(),
|
|
15532
16649
|
nativeAddonId: string()
|
|
@@ -15535,7 +16652,11 @@ method(object({
|
|
|
15535
16652
|
deviceId: number(),
|
|
15536
16653
|
entries: array(object({
|
|
15537
16654
|
capName: string(),
|
|
15538
|
-
kind: _enum([
|
|
16655
|
+
kind: _enum([
|
|
16656
|
+
"native",
|
|
16657
|
+
"wrapped",
|
|
16658
|
+
"linked"
|
|
16659
|
+
]),
|
|
15539
16660
|
providerAddonId: string(),
|
|
15540
16661
|
providerNodeId: string(),
|
|
15541
16662
|
nativeAddonId: string()
|
|
@@ -16025,7 +17146,7 @@ var AddBrokerInputSchema = object({
|
|
|
16025
17146
|
});
|
|
16026
17147
|
var AddBrokerResultSchema = object({ id: string() });
|
|
16027
17148
|
var IdInputSchema = object({ id: string() });
|
|
16028
|
-
var TestResultSchema = discriminatedUnion("ok", [object({
|
|
17149
|
+
var TestResultSchema$1 = discriminatedUnion("ok", [object({
|
|
16029
17150
|
ok: literal(true),
|
|
16030
17151
|
latencyMs: number()
|
|
16031
17152
|
}), object({
|
|
@@ -16048,7 +17169,7 @@ var StatusSchema = object({
|
|
|
16048
17169
|
brokerCount: number(),
|
|
16049
17170
|
embeddedRunning: boolean()
|
|
16050
17171
|
});
|
|
16051
|
-
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);
|
|
17172
|
+
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);
|
|
16052
17173
|
var NetworkEndpointSchema = object({
|
|
16053
17174
|
url: string(),
|
|
16054
17175
|
hostname: string(),
|
|
@@ -16082,23 +17203,198 @@ var NetworkEndpointEntrySchema = NetworkEndpointSchema.extend({
|
|
|
16082
17203
|
sourcePort: number().optional()
|
|
16083
17204
|
});
|
|
16084
17205
|
method(_void(), NetworkEndpointSchema, { kind: "mutation" }), method(_void(), _void(), { kind: "mutation" }), method(_void(), NetworkEndpointSchema.nullable()), method(_void(), NetworkAccessStatusSchema), method(_void(), array(NetworkEndpointEntrySchema).readonly());
|
|
16085
|
-
|
|
16086
|
-
|
|
17206
|
+
/**
|
|
17207
|
+
* notification-output — canonical, capability-gated notification delivery.
|
|
17208
|
+
*
|
|
17209
|
+
* Apprise-derived model (see
|
|
17210
|
+
* `docs/superpowers/specs/2026-07-03-notification-output-notifier-matrix.md`):
|
|
17211
|
+
* callers emit ONE canonical `Notification`; each provider declares a
|
|
17212
|
+
* per-kind capability descriptor (`TargetKind`), and the pure degrade
|
|
17213
|
+
* engine (`@camstack/types` `prepareNotification`) transcodes / degrades the
|
|
17214
|
+
* message to what the kind supports — callers never special-case a service.
|
|
17215
|
+
*
|
|
17216
|
+
* DESIGN DECISIONS (locked):
|
|
17217
|
+
* - Target CRUD lives on THIS cap (`upsertTarget` / `deleteTarget` /
|
|
17218
|
+
* `setTargetEnabled`), each provider persisting via the `settings-store`
|
|
17219
|
+
* cap. Rationale: the admin UI needs one uniform surface across the
|
|
17220
|
+
* notifiers addon AND the HA addon; the addon-`globalSettingsSchema`-array
|
|
17221
|
+
* alternative would fork the UI per addon and cannot host the
|
|
17222
|
+
* discovery→adopt flow.
|
|
17223
|
+
* - `listTargetKinds` / `listTargets` / `discoverTargets` return arrays →
|
|
17224
|
+
* the generated cap-mount auto-`concatCollection`-fans them across every
|
|
17225
|
+
* registered provider (notifiers addon + HA addon) so one catalog is
|
|
17226
|
+
* routable. `send` / `testTarget` / CRUD route to ONE provider by the
|
|
17227
|
+
* `addonId` the generated collection router extracts from the call input.
|
|
17228
|
+
* - `Attachment.bytes` is `Uint8Array`. Transport-safe: superjson (the tRPC
|
|
17229
|
+
* transformer) + UDS MsgPack both round-trip typed arrays — already used by
|
|
17230
|
+
* `storage` / `storage-provider` / `recording` caps over the same path. No
|
|
17231
|
+
* base64 fallback needed.
|
|
17232
|
+
*
|
|
17233
|
+
* TODO (deferred, closed-set change — separate decision): add
|
|
17234
|
+
* `providerKind: 'notify'` so notification providers surface on the unified
|
|
17235
|
+
* admin "Integrations" page.
|
|
17236
|
+
*/
|
|
17237
|
+
/**
|
|
17238
|
+
* Zentik-derived typed-media enum — the superset across every kind. Each
|
|
17239
|
+
* adapter picks what it supports and the degrade engine filters the rest.
|
|
17240
|
+
*/
|
|
17241
|
+
var AttachmentMediaTypeSchema = _enum([
|
|
17242
|
+
"image",
|
|
17243
|
+
"video",
|
|
17244
|
+
"gif",
|
|
17245
|
+
"audio",
|
|
17246
|
+
"icon"
|
|
17247
|
+
]);
|
|
17248
|
+
/**
|
|
17249
|
+
* A single attachment. Exactly one of `url` (remote source, most adapters
|
|
17250
|
+
* prefer this) or `bytes` (inline source; required for Pushover-style
|
|
17251
|
+
* bytes-only kinds) MUST be present — the degrade engine expresses a
|
|
17252
|
+
* url→bytes fetch as a `needsFetch` directive the adapter executes.
|
|
17253
|
+
*/
|
|
17254
|
+
var AttachmentSchema = object({
|
|
17255
|
+
mediaType: AttachmentMediaTypeSchema,
|
|
17256
|
+
url: string().optional(),
|
|
17257
|
+
bytes: _instanceof(Uint8Array).optional(),
|
|
17258
|
+
mime: string().optional(),
|
|
17259
|
+
name: string().optional()
|
|
17260
|
+
}).refine((a) => a.url !== void 0 || a.bytes !== void 0, { message: "Attachment requires either `url` or `bytes`" });
|
|
17261
|
+
var NotificationFormatSchema = _enum([
|
|
17262
|
+
"text",
|
|
17263
|
+
"markdown",
|
|
17264
|
+
"html"
|
|
17265
|
+
]);
|
|
17266
|
+
/** A single tap-through action button. */
|
|
17267
|
+
var NotificationActionSchema = object({
|
|
17268
|
+
id: string(),
|
|
17269
|
+
label: string(),
|
|
17270
|
+
url: string().optional()
|
|
17271
|
+
});
|
|
17272
|
+
/**
|
|
17273
|
+
* The canonical notification. `body` is the only hard field (Apprise model).
|
|
17274
|
+
* `priority` is a 5-level ORDINAL (1=lowest … 3=normal(default) … 5=urgent),
|
|
17275
|
+
* NOT a fixed severity enum — each kind declares its own `caps.levels` and
|
|
17276
|
+
* the adapter maps this ordinal onto its native level. `level?` is an
|
|
17277
|
+
* optional kind-native level id (`emergency`, `silent`, …) that overrides
|
|
17278
|
+
* `priority` for that one target.
|
|
17279
|
+
*/
|
|
17280
|
+
var NotificationSchema = object({
|
|
16087
17281
|
body: string(),
|
|
16088
|
-
|
|
17282
|
+
title: string().optional(),
|
|
17283
|
+
format: NotificationFormatSchema.default("text"),
|
|
17284
|
+
priority: number().int().min(1).max(5).default(3),
|
|
17285
|
+
level: string().optional(),
|
|
17286
|
+
attachments: array(AttachmentSchema).optional(),
|
|
17287
|
+
clickUrl: string().optional(),
|
|
17288
|
+
actions: array(NotificationActionSchema).optional(),
|
|
17289
|
+
sound: string().optional(),
|
|
17290
|
+
ttl: number().optional(),
|
|
17291
|
+
tag: string().optional(),
|
|
16089
17292
|
deviceId: number().optional(),
|
|
16090
17293
|
eventId: string().optional(),
|
|
16091
|
-
priority: _enum([
|
|
16092
|
-
"low",
|
|
16093
|
-
"normal",
|
|
16094
|
-
"high",
|
|
16095
|
-
"critical"
|
|
16096
|
-
]).default("normal"),
|
|
16097
17294
|
metadata: record(string(), unknown()).optional()
|
|
16098
|
-
})
|
|
17295
|
+
});
|
|
17296
|
+
/** One declared native severity/priority level for a kind. */
|
|
17297
|
+
var TargetKindLevelSchema = object({
|
|
17298
|
+
id: string(),
|
|
17299
|
+
label: string(),
|
|
17300
|
+
/** Which canonical priority (1..5) this level maps to. `null` = qualitative-only. */
|
|
17301
|
+
ordinal: number().int().min(1).max(5).nullable(),
|
|
17302
|
+
flags: object({
|
|
17303
|
+
critical: boolean().optional(),
|
|
17304
|
+
silent: boolean().optional(),
|
|
17305
|
+
noPush: boolean().optional()
|
|
17306
|
+
}).optional(),
|
|
17307
|
+
/** e.g. Pushover `emergency` requires `retry` / `expire`. */
|
|
17308
|
+
requires: array(string()).optional(),
|
|
17309
|
+
description: string().optional()
|
|
17310
|
+
});
|
|
17311
|
+
/** The full capability block consulted before dispatch. */
|
|
17312
|
+
var TargetKindCapsSchema = object({
|
|
17313
|
+
attachments: object({
|
|
17314
|
+
mediaTypes: array(AttachmentMediaTypeSchema),
|
|
17315
|
+
mode: _enum([
|
|
17316
|
+
"url",
|
|
17317
|
+
"bytes",
|
|
17318
|
+
"both"
|
|
17319
|
+
]),
|
|
17320
|
+
max: number().int().nonnegative(),
|
|
17321
|
+
maxBytes: number().int().positive().optional()
|
|
17322
|
+
}),
|
|
17323
|
+
/** Max action buttons (0 = none). */
|
|
17324
|
+
actions: number().int().nonnegative(),
|
|
17325
|
+
levels: array(TargetKindLevelSchema),
|
|
17326
|
+
format: array(NotificationFormatSchema),
|
|
17327
|
+
clickUrl: boolean(),
|
|
17328
|
+
sound: boolean(),
|
|
17329
|
+
ttl: boolean(),
|
|
17330
|
+
bodyMaxLen: number().int().positive()
|
|
17331
|
+
});
|
|
17332
|
+
/**
|
|
17333
|
+
* `configSchema` is a `ConfigUISchema` tree passed through to the admin
|
|
17334
|
+
* FormBuilder. Stored as `z.unknown()` at the cap seam (mirrors
|
|
17335
|
+
* `device-provider.getChildCreationSchema` `CreationSchemaOutputSchema`) —
|
|
17336
|
+
* the union is large and not meant for runtime validation here; the exported
|
|
17337
|
+
* `TargetKind` type re-tightens `configSchema` to `ConfigUISchema`.
|
|
17338
|
+
*/
|
|
17339
|
+
var ConfigSchemaPassthrough = unknown();
|
|
17340
|
+
var TargetKindSchema = object({
|
|
17341
|
+
kind: string(),
|
|
17342
|
+
label: string(),
|
|
17343
|
+
icon: string(),
|
|
17344
|
+
/** Stamped by each provider so the concat-fanned catalog stays routable. */
|
|
17345
|
+
addonId: string(),
|
|
17346
|
+
configSchema: ConfigSchemaPassthrough,
|
|
17347
|
+
supportsDiscovery: boolean(),
|
|
17348
|
+
caps: TargetKindCapsSchema
|
|
17349
|
+
});
|
|
17350
|
+
/**
|
|
17351
|
+
* A persisted target. `config` holds secrets; providers REDACT secret fields
|
|
17352
|
+
* (return a presence marker only) when serving `listTargets` — never
|
|
17353
|
+
* round-trip a stored secret to the UI.
|
|
17354
|
+
*/
|
|
17355
|
+
var TargetSchema = object({
|
|
17356
|
+
id: string(),
|
|
17357
|
+
name: string(),
|
|
17358
|
+
kind: string(),
|
|
17359
|
+
addonId: string(),
|
|
17360
|
+
enabled: boolean(),
|
|
17361
|
+
config: record(string(), unknown())
|
|
17362
|
+
});
|
|
17363
|
+
/** A discovery-surfaced candidate (config is partial + non-secret). */
|
|
17364
|
+
var DiscoveredTargetSchema = object({
|
|
17365
|
+
kind: string(),
|
|
17366
|
+
suggestedName: string(),
|
|
17367
|
+
config: record(string(), unknown())
|
|
17368
|
+
});
|
|
17369
|
+
/** The degrade engine's report — what was resolved / dropped / degraded. */
|
|
17370
|
+
var RenderedAsSchema = object({
|
|
17371
|
+
level: string(),
|
|
17372
|
+
format: NotificationFormatSchema,
|
|
17373
|
+
attachmentsSent: number().int().nonnegative(),
|
|
17374
|
+
actionsSent: number().int().nonnegative(),
|
|
17375
|
+
truncated: boolean(),
|
|
17376
|
+
dropped: array(string())
|
|
17377
|
+
});
|
|
17378
|
+
var SendResultSchema = object({
|
|
16099
17379
|
success: boolean(),
|
|
16100
|
-
error: string().optional()
|
|
16101
|
-
|
|
17380
|
+
error: string().optional(),
|
|
17381
|
+
renderedAs: RenderedAsSchema.optional()
|
|
17382
|
+
});
|
|
17383
|
+
/** Same shape as SendResult — kept as a distinct name for the test panel. */
|
|
17384
|
+
var TestResultSchema = SendResultSchema;
|
|
17385
|
+
method(object({}), array(TargetKindSchema)), method(object({}), array(TargetSchema)), method(object({
|
|
17386
|
+
kind: string(),
|
|
17387
|
+
config: record(string(), unknown()).optional()
|
|
17388
|
+
}), array(DiscoveredTargetSchema)), method(object({
|
|
17389
|
+
targetId: string(),
|
|
17390
|
+
notification: NotificationSchema
|
|
17391
|
+
}), SendResultSchema, { kind: "mutation" }), method(object({
|
|
17392
|
+
targetId: string(),
|
|
17393
|
+
sample: NotificationSchema.optional()
|
|
17394
|
+
}), TestResultSchema, { kind: "mutation" }), method(object({ target: TargetSchema }), TargetSchema, { kind: "mutation" }), method(object({ targetId: string() }), _void(), { kind: "mutation" }), method(object({
|
|
17395
|
+
targetId: string(),
|
|
17396
|
+
enabled: boolean()
|
|
17397
|
+
}), _void(), { kind: "mutation" });
|
|
16102
17398
|
/**
|
|
16103
17399
|
* Zod schemas for persisted record types.
|
|
16104
17400
|
*
|
|
@@ -19120,7 +20416,10 @@ var HwAccelBackendInputSchema = _enum([
|
|
|
19120
20416
|
"webgpu",
|
|
19121
20417
|
"none"
|
|
19122
20418
|
]).nullable().optional();
|
|
19123
|
-
var HwAccelResolutionSchema = object({
|
|
20419
|
+
var HwAccelResolutionSchema = object({
|
|
20420
|
+
preferred: array(string()).readonly(),
|
|
20421
|
+
rationale: string()
|
|
20422
|
+
});
|
|
19124
20423
|
var HardwareEncoderIdSchema = _enum([
|
|
19125
20424
|
"h264_videotoolbox",
|
|
19126
20425
|
"hevc_videotoolbox",
|
|
@@ -19225,10 +20524,7 @@ var ResolvedInferenceConfigSchema = object({
|
|
|
19225
20524
|
format: ModelFormatSchema,
|
|
19226
20525
|
reason: string()
|
|
19227
20526
|
});
|
|
19228
|
-
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({
|
|
19229
|
-
prefer: HwAccelBackendInputSchema,
|
|
19230
|
-
nodeId: string().optional()
|
|
19231
|
-
}), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
20527
|
+
method(_void(), PlatformCapabilitiesSchema), method(_void(), HardwareInfoSchema), method(object({ requirements: array(ModelRequirementSchema).readonly() }), ResolvedInferenceConfigSchema), method(object({ prefer: HwAccelBackendInputSchema }), HwAccelResolutionSchema), method(_void(), HardwareEncodersSchema), method(_void(), HardwareEncodersSchema, {
|
|
19232
20528
|
kind: "mutation",
|
|
19233
20529
|
auth: "admin"
|
|
19234
20530
|
}), method(_void(), HardwareDecodeAccelsSchema), method(_void(), HardwareDecodeAccelsSchema, {
|
|
@@ -19287,6 +20583,16 @@ DeviceType.Camera, DeviceType.Sensor, DeviceType.Switch, method(object({ deviceI
|
|
|
19287
20583
|
kind: "mutation",
|
|
19288
20584
|
auth: "admin"
|
|
19289
20585
|
});
|
|
20586
|
+
/**
|
|
20587
|
+
* `recording` cap — footage availability + HLS playback manifests + per-device
|
|
20588
|
+
* recording config. NOTE on events (source of truth, R5/C3): this cap carries
|
|
20589
|
+
* NO event surface — `getPlaybackManifest` returns playlist URLs only. Timeline
|
|
20590
|
+
* events (motion/object/audio) come from `pipelineAnalytics` (durable SQLite
|
|
20591
|
+
* rows); the recorder's internal EventMap markers are ephemeral in-RAM
|
|
20592
|
+
* annotations that are not exposed here and must not be treated as an event
|
|
20593
|
+
* feed. Event<->footage joins are by time, padded with the shared `EVENT_PAD_MS`
|
|
20594
|
+
* (`interfaces/recording-config.ts`).
|
|
20595
|
+
*/
|
|
19290
20596
|
var RecordingStatusSchema = object({
|
|
19291
20597
|
deviceId: number(),
|
|
19292
20598
|
enabled: boolean(),
|
|
@@ -20923,6 +22229,12 @@ Object.freeze({
|
|
|
20923
22229
|
addonId: null,
|
|
20924
22230
|
access: "view"
|
|
20925
22231
|
},
|
|
22232
|
+
"deviceManager.getRoleDisplayDefaults": {
|
|
22233
|
+
capName: "device-manager",
|
|
22234
|
+
capScope: "system",
|
|
22235
|
+
addonId: null,
|
|
22236
|
+
access: "view"
|
|
22237
|
+
},
|
|
20926
22238
|
"deviceManager.getSettingsSchema": {
|
|
20927
22239
|
capName: "device-manager",
|
|
20928
22240
|
capScope: "system",
|
|
@@ -21073,6 +22385,12 @@ Object.freeze({
|
|
|
21073
22385
|
addonId: null,
|
|
21074
22386
|
access: "create"
|
|
21075
22387
|
},
|
|
22388
|
+
"deviceManager.setDisplay": {
|
|
22389
|
+
capName: "device-manager",
|
|
22390
|
+
capScope: "system",
|
|
22391
|
+
addonId: null,
|
|
22392
|
+
access: "create"
|
|
22393
|
+
},
|
|
21076
22394
|
"deviceManager.setIntegrationId": {
|
|
21077
22395
|
capName: "device-manager",
|
|
21078
22396
|
capScope: "system",
|
|
@@ -21115,6 +22433,12 @@ Object.freeze({
|
|
|
21115
22433
|
addonId: null,
|
|
21116
22434
|
access: "create"
|
|
21117
22435
|
},
|
|
22436
|
+
"deviceManager.setRoleDisplayDefaults": {
|
|
22437
|
+
capName: "device-manager",
|
|
22438
|
+
capScope: "system",
|
|
22439
|
+
addonId: null,
|
|
22440
|
+
access: "create"
|
|
22441
|
+
},
|
|
21118
22442
|
"deviceManager.setStreamProfileMap": {
|
|
21119
22443
|
capName: "device-manager",
|
|
21120
22444
|
capScope: "system",
|
|
@@ -22093,13 +23417,49 @@ Object.freeze({
|
|
|
22093
23417
|
addonId: null,
|
|
22094
23418
|
access: "create"
|
|
22095
23419
|
},
|
|
23420
|
+
"notificationOutput.deleteTarget": {
|
|
23421
|
+
capName: "notification-output",
|
|
23422
|
+
capScope: "system",
|
|
23423
|
+
addonId: null,
|
|
23424
|
+
access: "delete"
|
|
23425
|
+
},
|
|
23426
|
+
"notificationOutput.discoverTargets": {
|
|
23427
|
+
capName: "notification-output",
|
|
23428
|
+
capScope: "system",
|
|
23429
|
+
addonId: null,
|
|
23430
|
+
access: "view"
|
|
23431
|
+
},
|
|
23432
|
+
"notificationOutput.listTargetKinds": {
|
|
23433
|
+
capName: "notification-output",
|
|
23434
|
+
capScope: "system",
|
|
23435
|
+
addonId: null,
|
|
23436
|
+
access: "view"
|
|
23437
|
+
},
|
|
23438
|
+
"notificationOutput.listTargets": {
|
|
23439
|
+
capName: "notification-output",
|
|
23440
|
+
capScope: "system",
|
|
23441
|
+
addonId: null,
|
|
23442
|
+
access: "view"
|
|
23443
|
+
},
|
|
22096
23444
|
"notificationOutput.send": {
|
|
22097
23445
|
capName: "notification-output",
|
|
22098
23446
|
capScope: "system",
|
|
22099
23447
|
addonId: null,
|
|
22100
23448
|
access: "create"
|
|
22101
23449
|
},
|
|
22102
|
-
"notificationOutput.
|
|
23450
|
+
"notificationOutput.setTargetEnabled": {
|
|
23451
|
+
capName: "notification-output",
|
|
23452
|
+
capScope: "system",
|
|
23453
|
+
addonId: null,
|
|
23454
|
+
access: "create"
|
|
23455
|
+
},
|
|
23456
|
+
"notificationOutput.testTarget": {
|
|
23457
|
+
capName: "notification-output",
|
|
23458
|
+
capScope: "system",
|
|
23459
|
+
addonId: null,
|
|
23460
|
+
access: "create"
|
|
23461
|
+
},
|
|
23462
|
+
"notificationOutput.upsertTarget": {
|
|
22103
23463
|
capName: "notification-output",
|
|
22104
23464
|
capScope: "system",
|
|
22105
23465
|
addonId: null,
|
|
@@ -22129,6 +23489,66 @@ Object.freeze({
|
|
|
22129
23489
|
addonId: null,
|
|
22130
23490
|
access: "create"
|
|
22131
23491
|
},
|
|
23492
|
+
"petFeeder.callPet": {
|
|
23493
|
+
capName: "pet-feeder",
|
|
23494
|
+
capScope: "device",
|
|
23495
|
+
addonId: null,
|
|
23496
|
+
access: "create"
|
|
23497
|
+
},
|
|
23498
|
+
"petFeeder.cancelFeed": {
|
|
23499
|
+
capName: "pet-feeder",
|
|
23500
|
+
capScope: "device",
|
|
23501
|
+
addonId: null,
|
|
23502
|
+
access: "create"
|
|
23503
|
+
},
|
|
23504
|
+
"petFeeder.feed": {
|
|
23505
|
+
capName: "pet-feeder",
|
|
23506
|
+
capScope: "device",
|
|
23507
|
+
addonId: null,
|
|
23508
|
+
access: "create"
|
|
23509
|
+
},
|
|
23510
|
+
"petFeeder.markFoodReplenished": {
|
|
23511
|
+
capName: "pet-feeder",
|
|
23512
|
+
capScope: "device",
|
|
23513
|
+
addonId: null,
|
|
23514
|
+
access: "create"
|
|
23515
|
+
},
|
|
23516
|
+
"petFeeder.playSound": {
|
|
23517
|
+
capName: "pet-feeder",
|
|
23518
|
+
capScope: "device",
|
|
23519
|
+
addonId: null,
|
|
23520
|
+
access: "create"
|
|
23521
|
+
},
|
|
23522
|
+
"petFeeder.resetDesiccant": {
|
|
23523
|
+
capName: "pet-feeder",
|
|
23524
|
+
capScope: "device",
|
|
23525
|
+
addonId: null,
|
|
23526
|
+
access: "delete"
|
|
23527
|
+
},
|
|
23528
|
+
"petFeeder.setChildLock": {
|
|
23529
|
+
capName: "pet-feeder",
|
|
23530
|
+
capScope: "device",
|
|
23531
|
+
addonId: null,
|
|
23532
|
+
access: "create"
|
|
23533
|
+
},
|
|
23534
|
+
"petFeeder.setFeedSound": {
|
|
23535
|
+
capName: "pet-feeder",
|
|
23536
|
+
capScope: "device",
|
|
23537
|
+
addonId: null,
|
|
23538
|
+
access: "create"
|
|
23539
|
+
},
|
|
23540
|
+
"petFeeder.setIndicatorLight": {
|
|
23541
|
+
capName: "pet-feeder",
|
|
23542
|
+
capScope: "device",
|
|
23543
|
+
addonId: null,
|
|
23544
|
+
access: "create"
|
|
23545
|
+
},
|
|
23546
|
+
"petFeeder.setVolume": {
|
|
23547
|
+
capName: "pet-feeder",
|
|
23548
|
+
capScope: "device",
|
|
23549
|
+
addonId: null,
|
|
23550
|
+
access: "create"
|
|
23551
|
+
},
|
|
22132
23552
|
"pipelineAnalytics.clearTracks": {
|
|
22133
23553
|
capName: "pipeline-analytics",
|
|
22134
23554
|
capScope: "device",
|