@camstack/types 1.1.20 → 1.1.22

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.
Files changed (49) hide show
  1. package/dist/addon/base-addon.d.ts +30 -4
  2. package/dist/addon/per-node-store.d.ts +68 -0
  3. package/dist/addon.js +1 -1
  4. package/dist/addon.mjs +1 -1
  5. package/dist/capabilities/camera-streams.cap.d.ts +5 -5
  6. package/dist/capabilities/decoder.cap.d.ts +2 -0
  7. package/dist/capabilities/device-manager.cap.d.ts +269 -6
  8. package/dist/capabilities/index.d.ts +3 -1
  9. package/dist/capabilities/metrics-provider.cap.d.ts +2 -2
  10. package/dist/capabilities/motion-detection.cap.d.ts +20 -2
  11. package/dist/capabilities/pet-feeder.cap.d.ts +185 -0
  12. package/dist/capabilities/pipeline-executor.cap.d.ts +29 -2
  13. package/dist/capabilities/pipeline-orchestrator.cap.d.ts +7 -3
  14. package/dist/capabilities/platform-probe.cap.d.ts +1 -1
  15. package/dist/capabilities/schemas/streaming-shared.d.ts +2 -2
  16. package/dist/capabilities/stream-broker.cap.d.ts +1 -1
  17. package/dist/device/device-management.d.ts +61 -2
  18. package/dist/device/device-type.d.ts +8 -1
  19. package/dist/device/index.d.ts +1 -1
  20. package/dist/expression/ast.d.ts +56 -0
  21. package/dist/expression/builtins.d.ts +19 -0
  22. package/dist/expression/compile.d.ts +17 -0
  23. package/dist/expression/errors.d.ts +16 -0
  24. package/dist/expression/evaluator.d.ts +14 -0
  25. package/dist/expression/index.d.ts +25 -0
  26. package/dist/expression/limits.d.ts +30 -0
  27. package/dist/expression/link-expression.d.ts +44 -0
  28. package/dist/expression/parser.d.ts +12 -0
  29. package/dist/expression/tokenizer.d.ts +38 -0
  30. package/dist/generated/addon-api.d.ts +616 -12
  31. package/dist/generated/cap-status-types.d.ts +3 -1
  32. package/dist/generated/capability-router-map.d.ts +5 -2
  33. package/dist/generated/device-local-state.d.ts +3 -0
  34. package/dist/generated/device-proxy.d.ts +4 -1
  35. package/dist/generated/method-access-map.d.ts +1 -1
  36. package/dist/generated/system-proxy.d.ts +1 -1
  37. package/dist/index.d.ts +4 -1
  38. package/dist/index.js +1555 -37
  39. package/dist/index.mjs +1523 -38
  40. package/dist/interfaces/addon.d.ts +15 -2
  41. package/dist/interfaces/agent.d.ts +14 -0
  42. package/dist/interfaces/config-ui.d.ts +19 -1
  43. package/dist/interfaces/pipeline-executor-capability.d.ts +10 -0
  44. package/dist/{sleep-BabrCASa.js → sleep-B8cp-HUn.js} +193 -7
  45. package/dist/{sleep-MHm--th-.mjs → sleep-BiDFW0E7.mjs} +193 -7
  46. package/dist/units/convert.d.ts +49 -0
  47. package/dist/units/index.d.ts +8 -0
  48. package/dist/units/unit-table.d.ts +270 -0
  49. package/package.json +1 -1
@@ -47,7 +47,7 @@ export declare const motionDetectionCapability: {
47
47
  readonly methods: {
48
48
  readonly analyze: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
49
49
  deviceId: z.ZodNumber;
50
- frame: z.ZodObject<{
50
+ frame: z.ZodOptional<z.ZodObject<{
51
51
  data: z.ZodCustom<Uint8Array<ArrayBufferLike>, Uint8Array<ArrayBufferLike>>;
52
52
  format: z.ZodEnum<{
53
53
  jpeg: "jpeg";
@@ -59,7 +59,25 @@ export declare const motionDetectionCapability: {
59
59
  width: z.ZodNumber;
60
60
  height: z.ZodNumber;
61
61
  timestamp: z.ZodNumber;
62
- }, z.core.$strip>;
62
+ }, z.core.$strip>>;
63
+ frameHandle: z.ZodOptional<z.ZodObject<{
64
+ shmId: z.ZodString;
65
+ slot: z.ZodNumber;
66
+ seq: z.ZodNumber;
67
+ width: z.ZodNumber;
68
+ height: z.ZodNumber;
69
+ format: z.ZodEnum<{
70
+ jpeg: "jpeg";
71
+ rgb: "rgb";
72
+ bgr: "bgr";
73
+ yuv420: "yuv420";
74
+ gray: "gray";
75
+ }>;
76
+ pts: z.ZodNumber;
77
+ byteLength: z.ZodNumber;
78
+ nodeId: z.ZodString;
79
+ slotCount: z.ZodNumber;
80
+ }, z.core.$strip>>;
63
81
  }, z.core.$strip>, z.ZodObject<{
64
82
  detected: z.ZodBoolean;
65
83
  regionCount: z.ZodNumber;
@@ -0,0 +1,185 @@
1
+ import { z } from 'zod';
2
+ import { type InferProvider } from './capability-definition.js';
3
+ import { DeviceType } from '../device/device-type.js';
4
+ /**
5
+ * PetKit pet-feeder cap. Models the control + telemetry surface of a
6
+ * cloud-connected smart feeder (Fresh Element / Mini / D3 / D4 / D4S
7
+ * Gemini / D4H / D4SH) as a single coherent slice — bowl food level,
8
+ * battery, desiccant life, feeding state + the four persisted settings
9
+ * (child-lock / indicator-light / feed-sound / volume).
10
+ *
11
+ * Sources: native PetKit (`nodepetkit` `FeederDevice`). Reusable by any
12
+ * feeder integration that speaks the same food/desiccant/hopper surface.
13
+ *
14
+ * `kind: 'poll'` — PetKit exposes only a cloud REST API (no push
15
+ * channel), so the provider refreshes the slice on a poll interval and
16
+ * eagerly after every command.
17
+ *
18
+ * Dual-hopper feeders (D4S/D4SH) split the bowl into two independent
19
+ * hoppers. `isDualHopper` gates the two-hopper UI; `food1`/`food2` carry
20
+ * the per-hopper levels (both `null` on single-hopper models, where
21
+ * `foodLevel` is the single reading). The manual-feed portion honours the
22
+ * PetKit hardware range 4–200 g in 1 g steps.
23
+ *
24
+ * Device status is exposed both raw and decoded, mirroring PetKit's HA
25
+ * integration (RobertD502/py-petkit-api). `status` is the connectivity /
26
+ * power enum (`normal` / `offline` / `on_batteries`); `error` is the
27
+ * decoded human-readable fault message (null / `no_error` = healthy);
28
+ * `errorCode` keeps the raw device integer (0 / null = no error) so a
29
+ * provider that only has the numeric code stays lossless. A provider maps
30
+ * the library's fields onto these; any it cannot determine stays `null`.
31
+ */
32
+ /** PetKit manual-feed portion bounds (grams). Mirrors the HA `manual_feed`
33
+ * number entity (min 4, max 200, step 1, device_class weight). */
34
+ export declare const PET_FEEDER_MANUAL_FEED_MIN = 4;
35
+ export declare const PET_FEEDER_MANUAL_FEED_MAX = 200;
36
+ /**
37
+ * Feeder connectivity / power status — mirrors the HA petkit device-status
38
+ * enum: `normal` (online, mains), `offline` (not reaching PetKit cloud),
39
+ * `on_batteries` (running on battery backup). `null` until first reported.
40
+ */
41
+ export declare const PetFeederDeviceStatusSchema: z.ZodEnum<{
42
+ offline: "offline";
43
+ normal: "normal";
44
+ on_batteries: "on_batteries";
45
+ }>;
46
+ export type PetFeederDeviceStatus = z.infer<typeof PetFeederDeviceStatusSchema>;
47
+ export declare const PetFeederStatusSchema: z.ZodObject<{
48
+ foodLevel: z.ZodNullable<z.ZodNumber>;
49
+ food1: z.ZodNullable<z.ZodNumber>;
50
+ food2: z.ZodNullable<z.ZodNumber>;
51
+ lowFood: z.ZodBoolean;
52
+ batteryPower: z.ZodNullable<z.ZodNumber>;
53
+ desiccantLeftDays: z.ZodNullable<z.ZodNumber>;
54
+ feeding: z.ZodBoolean;
55
+ status: z.ZodNullable<z.ZodEnum<{
56
+ offline: "offline";
57
+ normal: "normal";
58
+ on_batteries: "on_batteries";
59
+ }>>;
60
+ error: z.ZodNullable<z.ZodString>;
61
+ errorCode: z.ZodNullable<z.ZodNumber>;
62
+ isDualHopper: z.ZodBoolean;
63
+ childLock: z.ZodBoolean;
64
+ indicatorLight: z.ZodBoolean;
65
+ feedSound: z.ZodBoolean;
66
+ volume: z.ZodNumber;
67
+ lastFetchedAt: z.ZodNumber;
68
+ }, z.core.$strip>;
69
+ export type PetFeederStatus = z.infer<typeof PetFeederStatusSchema>;
70
+ export declare const petFeederCapability: {
71
+ readonly name: "pet-feeder";
72
+ readonly scope: "device";
73
+ readonly deviceNative: true;
74
+ readonly mode: "singleton";
75
+ readonly deviceTypes: readonly [DeviceType.PetFeeder];
76
+ readonly methods: {
77
+ /**
78
+ * Dispense food now. Single-hopper feeders take `grams`; dual-hopper
79
+ * feeders (D4S/D4SH) accept `hopper1`/`hopper2` to target one or both
80
+ * hoppers. All portions honour the 4–200 g hardware range. At least
81
+ * one of the three must be present — the provider rejects an empty
82
+ * request.
83
+ */
84
+ readonly feed: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
85
+ deviceId: z.ZodNumber;
86
+ grams: z.ZodOptional<z.ZodNumber>;
87
+ hopper1: z.ZodOptional<z.ZodNumber>;
88
+ hopper2: z.ZodOptional<z.ZodNumber>;
89
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
90
+ /** Cancel an in-progress manual feed. */
91
+ readonly cancelFeed: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
92
+ deviceId: z.ZodNumber;
93
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
94
+ /** Reset the desiccant "days remaining" counter after replacing it. */
95
+ readonly resetDesiccant: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
96
+ deviceId: z.ZodNumber;
97
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
98
+ /** Mark a hopper as refilled (D4H/D4S/D4SH). */
99
+ readonly markFoodReplenished: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
100
+ deviceId: z.ZodNumber;
101
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
102
+ /** Call the pet with the recorded prompt (D3). */
103
+ readonly callPet: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
104
+ deviceId: z.ZodNumber;
105
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
106
+ /** Play a stored sound by id (D3 / D4H / D4SH). */
107
+ readonly playSound: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
108
+ deviceId: z.ZodNumber;
109
+ soundId: z.ZodNumber;
110
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
111
+ /** Toggle the child-lock (manual-lock) setting. */
112
+ readonly setChildLock: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
113
+ deviceId: z.ZodNumber;
114
+ on: z.ZodBoolean;
115
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
116
+ /** Toggle the front indicator light. */
117
+ readonly setIndicatorLight: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
118
+ deviceId: z.ZodNumber;
119
+ on: z.ZodBoolean;
120
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
121
+ /** Toggle the dispense chime. */
122
+ readonly setFeedSound: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
123
+ deviceId: z.ZodNumber;
124
+ on: z.ZodBoolean;
125
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
126
+ /** Set the speaker / prompt volume level. */
127
+ readonly setVolume: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
128
+ deviceId: z.ZodNumber;
129
+ level: z.ZodNumber;
130
+ }, z.core.$strip>, z.ZodVoid, "mutation">;
131
+ };
132
+ readonly status: {
133
+ readonly schema: z.ZodObject<{
134
+ foodLevel: z.ZodNullable<z.ZodNumber>;
135
+ food1: z.ZodNullable<z.ZodNumber>;
136
+ food2: z.ZodNullable<z.ZodNumber>;
137
+ lowFood: z.ZodBoolean;
138
+ batteryPower: z.ZodNullable<z.ZodNumber>;
139
+ desiccantLeftDays: z.ZodNullable<z.ZodNumber>;
140
+ feeding: z.ZodBoolean;
141
+ status: z.ZodNullable<z.ZodEnum<{
142
+ offline: "offline";
143
+ normal: "normal";
144
+ on_batteries: "on_batteries";
145
+ }>>;
146
+ error: z.ZodNullable<z.ZodString>;
147
+ errorCode: z.ZodNullable<z.ZodNumber>;
148
+ isDualHopper: z.ZodBoolean;
149
+ childLock: z.ZodBoolean;
150
+ indicatorLight: z.ZodBoolean;
151
+ feedSound: z.ZodBoolean;
152
+ volume: z.ZodNumber;
153
+ lastFetchedAt: z.ZodNumber;
154
+ }, z.core.$strip>;
155
+ readonly kind: "poll";
156
+ };
157
+ /**
158
+ * Runtime-state slice — mirrored by the kernel. UI feeder cards read
159
+ * the full slice via `device.state.petFeeder.value` and refresh on
160
+ * every poll without re-querying the provider.
161
+ */
162
+ readonly runtimeState: z.ZodObject<{
163
+ foodLevel: z.ZodNullable<z.ZodNumber>;
164
+ food1: z.ZodNullable<z.ZodNumber>;
165
+ food2: z.ZodNullable<z.ZodNumber>;
166
+ lowFood: z.ZodBoolean;
167
+ batteryPower: z.ZodNullable<z.ZodNumber>;
168
+ desiccantLeftDays: z.ZodNullable<z.ZodNumber>;
169
+ feeding: z.ZodBoolean;
170
+ status: z.ZodNullable<z.ZodEnum<{
171
+ offline: "offline";
172
+ normal: "normal";
173
+ on_batteries: "on_batteries";
174
+ }>>;
175
+ error: z.ZodNullable<z.ZodString>;
176
+ errorCode: z.ZodNullable<z.ZodNumber>;
177
+ isDualHopper: z.ZodBoolean;
178
+ childLock: z.ZodBoolean;
179
+ indicatorLight: z.ZodBoolean;
180
+ feedSound: z.ZodBoolean;
181
+ volume: z.ZodNumber;
182
+ lastFetchedAt: z.ZodNumber;
183
+ }, z.core.$strip>;
184
+ };
185
+ export type IPetFeederProvider = InferProvider<typeof petFeederCapability>;
@@ -710,11 +710,20 @@ export declare const pipelineExecutorCapability: {
710
710
  * legacy call shape used by existing benchmark code; once all
711
711
  * callers pass it explicitly we make it required.
712
712
  *
713
- * Exactly one of `frame`, `imageBase64`, `referenceImage` must be
714
- * provided:
713
+ * Exactly one of `frame`, `frameHandle`, `imageBase64`,
714
+ * `referenceImage` must be provided:
715
715
  * - `frame`: runtime dispatch path (runner → decoded broker frame).
716
716
  * Carries the raw buffer, dimensions, and format; the executor
717
717
  * uses it directly without base64 round-tripping.
718
+ * - `frameHandle` (CB5): a zero-pixel shm `FrameHandle` for the SAME
719
+ * decoded frame. Both runner and executor are hub-local processes
720
+ * sharing `/dev/shm`, so the executor maps the named segment and
721
+ * reads the pixels back zero-copy — eliminating the ~1.2MB
722
+ * re-serialisation over UDS/MsgPack the `frame` path pays per call.
723
+ * High-risk: the FrameRing is a latest-wins seqlock with no
724
+ * refcount, so a recycled slot yields a null read; the executor
725
+ * then degrades to an empty result and the runner ships pixels via
726
+ * `frame` as the fallback (queue-depth gated on the runner side).
718
727
  * - `imageBase64`: one-shot test path (benchmark ImageTab).
719
728
  * - `referenceImage`: named file from the reference-image store.
720
729
  */
@@ -748,6 +757,24 @@ export declare const pipelineExecutorCapability: {
748
757
  height: z.ZodNumber;
749
758
  timestamp: z.ZodNumber;
750
759
  }, z.core.$strip>>;
760
+ frameHandle: z.ZodOptional<z.ZodObject<{
761
+ shmId: z.ZodString;
762
+ slot: z.ZodNumber;
763
+ seq: z.ZodNumber;
764
+ width: z.ZodNumber;
765
+ height: z.ZodNumber;
766
+ format: z.ZodEnum<{
767
+ jpeg: "jpeg";
768
+ rgb: "rgb";
769
+ bgr: "bgr";
770
+ yuv420: "yuv420";
771
+ gray: "gray";
772
+ }>;
773
+ pts: z.ZodNumber;
774
+ byteLength: z.ZodNumber;
775
+ nodeId: z.ZodString;
776
+ slotCount: z.ZodNumber;
777
+ }, z.core.$strip>>;
751
778
  imageBase64: z.ZodOptional<z.ZodString>;
752
779
  image: z.ZodOptional<z.ZodCustom<Uint8Array<ArrayBuffer>, Uint8Array<ArrayBuffer>>>;
753
780
  referenceImage: z.ZodOptional<z.ZodString>;
@@ -459,7 +459,10 @@ export declare const pipelineOrchestratorCapability: {
459
459
  readonly methods: {
460
460
  /**
461
461
  * Pin a camera's pipeline to a specific agent (L1 affinity).
462
- * The orchestrator re-evaluates the assignment immediately.
462
+ * The orchestrator re-evaluates the assignment immediately and persists
463
+ * the pin under the canonical `pipelineNodeId` device-store key (the
464
+ * legacy `preferredAgent` key is nulled on write and kept only as a
465
+ * read-only fallback for stores written before the unification).
463
466
  */
464
467
  readonly assignPipeline: import("./capability-definition.js").CapabilityMethodSchema<z.ZodObject<{
465
468
  deviceId: z.ZodNumber;
@@ -469,8 +472,9 @@ export declare const pipelineOrchestratorCapability: {
469
472
  }, z.core.$strip>, "mutation">;
470
473
  /**
471
474
  * Clear a camera's pipeline pin and let the auto-balancer re-pick
472
- * the optimal agent. The orchestrator persists `preferredAgent=null`
473
- * (and `pipelineNodeId='auto'`), then re-runs the balancer with the
475
+ * the optimal agent. The orchestrator persists the canonical
476
+ * `pipelineNodeId='auto'` (and nulls the legacy `preferredAgent`),
477
+ * then re-runs the balancer with the
474
478
  * cached `RunnerCameraConfig` and migrates only when the chosen
475
479
  * node differs. The camera stays in `getPipelineAssignments()` —
476
480
  * just with `pinned=false`. If no runner is currently available
@@ -264,9 +264,9 @@ export declare const platformProbeCapability: {
264
264
  directml: "directml";
265
265
  webgpu: "webgpu";
266
266
  }>>>;
267
- nodeId: z.ZodOptional<z.ZodString>;
268
267
  }, z.core.$strip>, z.ZodObject<{
269
268
  preferred: z.ZodReadonly<z.ZodArray<z.ZodString>>;
269
+ rationale: z.ZodString;
270
270
  }, z.core.$strip>, import("./capability-definition.js").CapabilityMethodKind>;
271
271
  /**
272
272
  * Hardware-encoder probe — see Task #185. Cached after first call.
@@ -49,8 +49,8 @@ export declare const CameraStreamSchema: z.ZodObject<{
49
49
  export type CameraStream = z.infer<typeof CameraStreamSchema>;
50
50
  export declare const ProfileSlotStatusSchema: z.ZodEnum<{
51
51
  error: "error";
52
- idle: "idle";
53
52
  unassigned: "unassigned";
53
+ idle: "idle";
54
54
  connecting: "connecting";
55
55
  streaming: "streaming";
56
56
  }>;
@@ -66,8 +66,8 @@ export declare const ProfileSlotSchema: z.ZodObject<{
66
66
  sourceCamStreamId: z.ZodNullable<z.ZodString>;
67
67
  status: z.ZodEnum<{
68
68
  error: "error";
69
- idle: "idle";
70
69
  unassigned: "unassigned";
70
+ idle: "idle";
71
71
  connecting: "connecting";
72
72
  streaming: "streaming";
73
73
  }>;
@@ -413,8 +413,8 @@ export declare const streamBrokerCapability: {
413
413
  sourceCamStreamId: z.ZodNullable<z.ZodString>;
414
414
  status: z.ZodEnum<{
415
415
  error: "error";
416
- idle: "idle";
417
416
  unassigned: "unassigned";
417
+ idle: "idle";
418
418
  connecting: "connecting";
419
419
  streaming: "streaming";
420
420
  }>;
@@ -1,6 +1,6 @@
1
1
  import type { z } from 'zod';
2
- import type { DeviceType } from './device-type.js';
3
2
  import type { IDevice } from './device.js';
3
+ import type { DeviceType } from './device-type.js';
4
4
  import type { SourceInfo } from './source-info.js';
5
5
  export interface DeviceManualCreation {
6
6
  getChildCreationSchema(type: DeviceType): z.ZodObject<z.core.$ZodLooseShape>;
@@ -127,7 +127,22 @@ export interface DeviceLinkGlobalSource {
127
127
  readonly cap: string;
128
128
  readonly fieldPath: string;
129
129
  }
130
- export type DeviceLinkSource = DeviceLinkFieldSource | DeviceLinkLiteralSource | DeviceLinkGlobalSource;
130
+ /** The source kinds a single expression BINDING may use — a sibling FIELD, a
131
+ * per-device LITERAL, or a GLOBAL device field. Never another expression:
132
+ * bindings do not nest, so an expression cannot reference another expression. */
133
+ export type DeviceLinkExpressionBinding = DeviceLinkFieldSource | DeviceLinkLiteralSource | DeviceLinkGlobalSource;
134
+ /** Expression source (Stage X): compute the target field from N named source
135
+ * bindings via a safe, non-Turing-complete infix expression (see
136
+ * `packages/types/src/expression/`). Each binding resolves to an
137
+ * `ExpressionValue` and is exposed to the expression under its record key.
138
+ * `now` (epoch ms) is auto-injected and is a reserved binding name. The
139
+ * evaluated result flows through `transform` exactly like a scalar source. */
140
+ export interface DeviceLinkExpressionSource {
141
+ readonly kind: 'expression';
142
+ readonly expr: string;
143
+ readonly bindings: Readonly<Record<string, DeviceLinkExpressionBinding>>;
144
+ }
145
+ export type DeviceLinkSource = DeviceLinkFieldSource | DeviceLinkLiteralSource | DeviceLinkGlobalSource | DeviceLinkExpressionSource;
131
146
  /** The target field a link writes: a dot-path into the target cap's status. */
132
147
  export interface DeviceLinkTarget {
133
148
  readonly cap: string;
@@ -156,6 +171,42 @@ export interface DeviceLink {
156
171
  readonly transform?: DeviceLinkTransform;
157
172
  }
158
173
  export type DeviceLinks = readonly DeviceLink[];
174
+ /** Per-cap display refinement inside a `DeviceDisplayOverride` — unit/precision
175
+ * only (icon/label/hidden are device-level). Keyed by cap name for devices
176
+ * carrying several numeric caps (e.g. power-meter). */
177
+ export interface DeviceCapDisplayOverride {
178
+ readonly unit?: string;
179
+ readonly precision?: number;
180
+ }
181
+ /** Operator-authored per-device display override. Rides the `DeviceMeta`
182
+ * lifecycle (persist/preserve/project/pre-seed) — deliberately NOT a new
183
+ * cap/store. All fields optional; an empty object is equivalent to absent.
184
+ * `unit` triggers render-time conversion when same-dimension as the live
185
+ * slice unit (storage stays in source units); `precision` applies AFTER
186
+ * conversion; `hidden` removes the device from list surfaces (distinct from
187
+ * the HA-only accessories-cap `hiddenChildIds` mechanism). */
188
+ export interface DeviceDisplayOverride {
189
+ /** Key into ui-library's display icon registry. */
190
+ readonly icon?: string;
191
+ /** Overrides the `DEVICE_ROLE_META` label (NOT the device name). */
192
+ readonly label?: string;
193
+ /** Canonical spelling (`normalizeUnit` applied at write). */
194
+ readonly unit?: string;
195
+ /** Int 0-10, same contract as the slice `precision` field. */
196
+ readonly precision?: number;
197
+ readonly hidden?: boolean;
198
+ readonly perCap?: Readonly<Record<string, DeviceCapDisplayOverride>>;
199
+ }
200
+ /** Operator-authored per-role display default (unit/precision/icon), keyed by
201
+ * `DeviceRole` string. Resolution merges these UNDER any per-device
202
+ * `DeviceDisplayOverride`. Stored whole-record (full replace) in the
203
+ * device-manager addon store's `roleDisplayDefaults` key — NOT on any device's
204
+ * meta row. */
205
+ export interface RoleDisplayDefault {
206
+ readonly unit?: string;
207
+ readonly precision?: number;
208
+ readonly icon?: string;
209
+ }
159
210
  export interface DeviceMeta {
160
211
  readonly id: number;
161
212
  readonly stableId: string;
@@ -207,6 +258,12 @@ export interface DeviceMeta {
207
258
  * cap field). Same create/persist/project/restore lifecycle as `childLayout`.
208
259
  * Absent ⇒ no links. Overlaid onto the target cap's `getStatus` at read time. */
209
260
  readonly deviceLinks?: DeviceLinks;
261
+ /** Operator-authored per-device display override (icon/label/unit/precision/
262
+ * hidden). Same create/persist/project/restore lifecycle as `deviceLinks`.
263
+ * Absent ⇒ no override; the renderer falls back to role default → live slice
264
+ * → canonical unit. Applied at RENDER time only — storage stays in source
265
+ * units. */
266
+ readonly display?: DeviceDisplayOverride;
210
267
  }
211
268
  /**
212
269
  * Initial meta a provider supplies on `onCreateDevice`. Differs
@@ -237,6 +294,8 @@ export interface InitialDeviceMeta {
237
294
  readonly childLayout?: ChildLayout;
238
295
  /** Cross-device field wirings set at create. Mirrors `DeviceMeta.deviceLinks`. */
239
296
  readonly deviceLinks?: DeviceLinks;
297
+ /** Per-device display override set at create. Mirrors `DeviceMeta.display`. */
298
+ readonly display?: DeviceDisplayOverride;
240
299
  }
241
300
  /**
242
301
  * Single-call payload returned by `BaseDeviceProvider.onCreateDevice`.
@@ -81,7 +81,14 @@ export declare enum DeviceType {
81
81
  Container = "container",
82
82
  /** Single still-image entity (HA `image.*`). Read-only display of an
83
83
  * `entity_picture` signed URL the browser loads directly. `image` cap. */
84
- Image = "image"
84
+ Image = "image",
85
+ /** Smart pet feeder — cloud-connected food dispenser with a bowl food
86
+ * level, battery, desiccant life, feeding state and manual-feed /
87
+ * call-pet / maintenance actions. Installed with the `pet-feeder` cap;
88
+ * dual-hopper models (D4S/D4SH) expose per-hopper portions. Sources:
89
+ * native PetKit (`nodepetkit` `FeederDevice`), reusable by other feeder
90
+ * integrations sharing the same food/desiccant/hopper surface. */
91
+ PetFeeder = "pet-feeder"
85
92
  }
86
93
  export declare enum DeviceFeature {
87
94
  BatteryOperated = "battery-operated",
@@ -11,7 +11,7 @@ export type { IDevice } from './device.js';
11
11
  export { DEVICE_PROFILES, BATTERY_DEVICE_PROFILE, deviceMatchesProfile, resolveDeviceProfile, } from './device-profile.js';
12
12
  export type { DeviceProfile, DeviceProfileMatch, DeviceProfileDefaults, PipelinePhaseMode, } from './device-profile.js';
13
13
  export type { ICameraDevice, StreamSourceEntry } from './camera-device.js';
14
- export type { DeviceManualCreation, DeviceDiscovery, DiscoveredDevice, SavedDevice, DeviceMeta, InitialDeviceMeta, CreateDeviceSpec, ChildLayout, ChildLayoutEntry, DeviceLinkFieldSource, DeviceLinkLiteralSource, DeviceLinkGlobalSource, DeviceLinkSource, DeviceLinkTarget, DeviceLinkTransform, DeviceLink, DeviceLinks, } from './device-management.js';
14
+ export type { DeviceManualCreation, DeviceDiscovery, DiscoveredDevice, SavedDevice, DeviceMeta, InitialDeviceMeta, CreateDeviceSpec, ChildLayout, ChildLayoutEntry, DeviceLinkFieldSource, DeviceLinkLiteralSource, DeviceLinkGlobalSource, DeviceLinkExpressionBinding, DeviceLinkExpressionSource, DeviceLinkSource, DeviceLinkTarget, DeviceLinkTransform, DeviceLink, DeviceLinks, } from './device-management.js';
15
15
  export { zodEntriesToConfigUI } from './zod-to-config-ui.js';
16
16
  export type { DeviceConfigEntry } from './zod-to-config-ui.js';
17
17
  export { createRuntimeStateBridge } from './runtime-state-helpers.js';
@@ -0,0 +1,56 @@
1
+ /**
2
+ * AST for the safe expression mini-language.
3
+ *
4
+ * SECURITY BY CONSTRUCTION (spec §4 rule 3): there is deliberately NO member
5
+ * node, NO index node, NO assignment node and NO lambda/function node in this
6
+ * union. `a.b`, `a["b"]`, `a = b` and `() => …` are therefore UNREPRESENTABLE —
7
+ * `__proto__` / `constructor` / `prototype` traversal is impossible at the type
8
+ * level, not by a runtime denylist. `ExpressionCallNode.callee` is a plain
9
+ * string (a builtin name), never a node, so a computed call like `(min)(1)` is
10
+ * unparseable.
11
+ *
12
+ * The value domain is the four JSON primitives — no objects, arrays or
13
+ * functions ever flow through the evaluator.
14
+ */
15
+ /** The only value types the engine produces or consumes. */
16
+ export type ExpressionValue = number | string | boolean | null;
17
+ export type ExpressionBinaryOperator = '+' | '-' | '*' | '/' | '%' | '==' | '!=' | '<' | '<=' | '>' | '>=';
18
+ export type ExpressionLogicalOperator = '&&' | '||';
19
+ export type ExpressionUnaryOperator = '-' | '!';
20
+ export interface ExpressionLiteralNode {
21
+ readonly kind: 'literal';
22
+ readonly value: ExpressionValue;
23
+ }
24
+ export interface ExpressionIdentifierNode {
25
+ readonly kind: 'identifier';
26
+ readonly name: string;
27
+ }
28
+ export interface ExpressionUnaryNode {
29
+ readonly kind: 'unary';
30
+ readonly op: ExpressionUnaryOperator;
31
+ readonly operand: ExpressionNode;
32
+ }
33
+ export interface ExpressionBinaryNode {
34
+ readonly kind: 'binary';
35
+ readonly op: ExpressionBinaryOperator;
36
+ readonly left: ExpressionNode;
37
+ readonly right: ExpressionNode;
38
+ }
39
+ export interface ExpressionLogicalNode {
40
+ readonly kind: 'logical';
41
+ readonly op: ExpressionLogicalOperator;
42
+ readonly left: ExpressionNode;
43
+ readonly right: ExpressionNode;
44
+ }
45
+ export interface ExpressionConditionalNode {
46
+ readonly kind: 'conditional';
47
+ readonly test: ExpressionNode;
48
+ readonly consequent: ExpressionNode;
49
+ readonly alternate: ExpressionNode;
50
+ }
51
+ export interface ExpressionCallNode {
52
+ readonly kind: 'call';
53
+ readonly callee: string;
54
+ readonly args: readonly ExpressionNode[];
55
+ }
56
+ export type ExpressionNode = ExpressionLiteralNode | ExpressionIdentifierNode | ExpressionUnaryNode | ExpressionBinaryNode | ExpressionLogicalNode | ExpressionConditionalNode | ExpressionCallNode;
@@ -0,0 +1,19 @@
1
+ import type { ExpressionValue } from './ast.js';
2
+ /** Optional runtime hooks the evaluator threads through to builtins. Stage U
3
+ * installs the real unit-conversion table here; absent → the `convert` stub. */
4
+ export interface ExpressionEvalHooks {
5
+ /** Convert `value` from unit `from` to unit `to`; `null` when the pair is
6
+ * not convertible. Absent hook → `convert` uses its identity-only stub. */
7
+ readonly convert?: (value: number, from: string, to: string) => number | null;
8
+ }
9
+ export interface ExpressionBuiltin {
10
+ readonly minArgs: number;
11
+ /** `Number.POSITIVE_INFINITY` for variadic builtins. */
12
+ readonly maxArgs: number;
13
+ readonly apply: (args: readonly ExpressionValue[], hooks: ExpressionEvalHooks) => ExpressionValue;
14
+ }
15
+ /** Frozen, null-prototype builtin table. */
16
+ export declare const EXPRESSION_BUILTINS: Readonly<Record<string, ExpressionBuiltin>>;
17
+ /** The set of valid builtin names — used by the parser to reject unknown
18
+ * callees at parse time (immediate author feedback). */
19
+ export declare const EXPRESSION_BUILTIN_NAMES: ReadonlySet<string>;
@@ -0,0 +1,17 @@
1
+ import { type ParsedExpression } from './parser.js';
2
+ export type CompileResult = {
3
+ readonly ok: true;
4
+ readonly parsed: ParsedExpression;
5
+ } | {
6
+ readonly ok: false;
7
+ readonly error: string;
8
+ };
9
+ /** Compile `source` to a `ParsedExpression`, throwing `ExpressionParseError`
10
+ * on failure. LRU/negative-cached. */
11
+ export declare function compileExpression(source: string): ParsedExpression;
12
+ /** Compile `source`, returning a discriminated result instead of throwing.
13
+ * Used by read paths that must degrade rather than raise. LRU/negative-cached. */
14
+ export declare function compileExpressionSafe(source: string): CompileResult;
15
+ /** Test-only: clear the module-level cache. Not part of the public engine
16
+ * surface — used to make cache-behaviour assertions deterministic. */
17
+ export declare function __clearExpressionCompileCache(): void;
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Error types for the safe expression engine. Two distinct classes so callers
3
+ * can tell a compile-time (grammar) failure from a runtime (evaluation)
4
+ * failure — both are non-fatal to the host: read paths degrade to "skip link".
5
+ */
6
+ /** Thrown by the tokenizer / parser. Carries a 0-based source `position` when
7
+ * the failure is anchored to a character (author-facing inline feedback). */
8
+ export declare class ExpressionParseError extends Error {
9
+ readonly position?: number;
10
+ constructor(message: string, position?: number);
11
+ }
12
+ /** Thrown by the evaluator (unknown identifier, type mismatch, non-finite
13
+ * result, unknown builtin, step-budget exceeded). */
14
+ export declare class ExpressionEvalError extends Error {
15
+ constructor(message: string);
16
+ }
@@ -0,0 +1,14 @@
1
+ import { type ExpressionEvalHooks } from './builtins.js';
2
+ import type { ExpressionNode, ExpressionValue } from './ast.js';
3
+ export interface ExpressionEvalOptions {
4
+ readonly hooks?: ExpressionEvalHooks;
5
+ readonly maxSteps?: number;
6
+ }
7
+ /** Build a null-prototype scope from own-enumerable binding entries. Inherited
8
+ * keys of the input (e.g. from a `{__proto__: {...}}` payload) are NOT copied,
9
+ * so nothing smuggles in via the prototype chain. */
10
+ export declare function createExpressionScope(bindings: Readonly<Record<string, ExpressionValue>>): Record<string, ExpressionValue>;
11
+ /** Evaluate an AST node against a scope. Throws `ExpressionEvalError` on any
12
+ * runtime failure (unknown identifier, type mismatch, non-finite result,
13
+ * step-budget exhaustion). */
14
+ export declare function evaluateAst(node: ExpressionNode, scope: Record<string, ExpressionValue>, opts?: ExpressionEvalOptions): ExpressionValue;
@@ -0,0 +1,25 @@
1
+ /**
2
+ * Safe expression engine — public surface. A non-Turing-complete infix
3
+ * mini-language (tokenizer → Pratt parser → whitelisted-AST interpreter) with
4
+ * NO eval / new Function / node:vm, NO member access, NO loops/lambdas, and
5
+ * hard resource bounds. Powers the `expression` DeviceLinkSource kind.
6
+ *
7
+ * This is the module barrel; leaf files inside @camstack/types MUST import from
8
+ * the deep modules (e.g. `../expression/compile.js`), never through this file
9
+ * OR the root barrel (see biome-plugins/no-types-barrel-leaf-import.grit).
10
+ */
11
+ export type { ExpressionValue, ExpressionNode, ExpressionLiteralNode, ExpressionIdentifierNode, ExpressionUnaryNode, ExpressionBinaryNode, ExpressionLogicalNode, ExpressionConditionalNode, ExpressionCallNode, ExpressionBinaryOperator, ExpressionLogicalOperator, ExpressionUnaryOperator, } from './ast.js';
12
+ export { ExpressionParseError, ExpressionEvalError } from './errors.js';
13
+ export { MAX_EXPRESSION_SOURCE_LENGTH, MAX_EXPRESSION_AST_NODES, MAX_EXPRESSION_EVAL_STEPS, MAX_EXPRESSION_BINDINGS, MAX_EXPRESSION_CALL_ARGS, EXPRESSION_COMPILE_CACHE_CAPACITY, EXPRESSION_IDENTIFIER_RE, RESERVED_BINDING_NAMES, } from './limits.js';
14
+ export { tokenize } from './tokenizer.js';
15
+ export type { Token, Punctuator, Keyword } from './tokenizer.js';
16
+ export { parseExpression } from './parser.js';
17
+ export type { ParsedExpression } from './parser.js';
18
+ export { EXPRESSION_BUILTINS, EXPRESSION_BUILTIN_NAMES, } from './builtins.js';
19
+ export type { ExpressionBuiltin, ExpressionEvalHooks } from './builtins.js';
20
+ export { createExpressionScope, evaluateAst } from './evaluator.js';
21
+ export type { ExpressionEvalOptions } from './evaluator.js';
22
+ export { compileExpression, compileExpressionSafe } from './compile.js';
23
+ export type { CompileResult } from './compile.js';
24
+ export { EXPRESSION_INJECTED_NOW, toExpressionValue, validateExpressionSource, evaluateLinkExpression, } from './link-expression.js';
25
+ export type { ExpressionSourceInput, EvaluateLinkExpressionResult, } from './link-expression.js';
@@ -0,0 +1,30 @@
1
+ /**
2
+ * Resource-bound constants for the safe expression engine.
3
+ *
4
+ * Every bound is defense-in-depth: the grammar is non-Turing-complete (no
5
+ * loops, recursion, lambdas or member access — see `ast.ts`), so evaluation is
6
+ * O(nodeCount) by construction. These caps merely put a hard ceiling on the
7
+ * work a single author-supplied expression can request, so a hostile or
8
+ * accidental pathological string can never spend unbounded CPU/memory.
9
+ */
10
+ /** Max source length (chars) — checked BEFORE tokenizing so a huge string is
11
+ * rejected without allocation. */
12
+ export declare const MAX_EXPRESSION_SOURCE_LENGTH = 2048;
13
+ /** Max AST nodes — checked during parse; a deeply nested grouping that exceeds
14
+ * this is rejected as "expression too complex". */
15
+ export declare const MAX_EXPRESSION_AST_NODES = 256;
16
+ /** Defense-in-depth walker step budget — one increment per node visit during
17
+ * evaluation. The grammar guarantees O(nodeCount) walks, so this can only trip
18
+ * on a crafted maximum-size AST. */
19
+ export declare const MAX_EXPRESSION_EVAL_STEPS = 4096;
20
+ /** Max named bindings on one `DeviceLinkExpressionSource`. */
21
+ export declare const MAX_EXPRESSION_BINDINGS = 32;
22
+ /** Max positional arguments to any builtin call. */
23
+ export declare const MAX_EXPRESSION_CALL_ARGS = 16;
24
+ /** LRU compile-cache capacity (parsed ASTs keyed by raw source string). */
25
+ export declare const EXPRESSION_COMPILE_CACHE_CAPACITY = 256;
26
+ /** A legal binding / identifier name. */
27
+ export declare const EXPRESSION_IDENTIFIER_RE: RegExp;
28
+ /** Binding names an author may NOT use: `now` is auto-injected; the literal
29
+ * keywords lex as values, not identifiers, so binding to them is meaningless. */
30
+ export declare const RESERVED_BINDING_NAMES: ReadonlySet<string>;