@camstack/types 1.2.569 → 1.2.570

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/index.js CHANGED
@@ -1,5 +1,5 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
- const require_sleep = require("./sleep-DR76P1OE.js");
2
+ const require_sleep = require("./sleep-Cr2-wtyQ.js");
3
3
  const require_event_category = require("./event-category-d9kiqCqC.js");
4
4
  const require_composed_stable_id = require("./composed-stable-id-C3NfRTj8.js");
5
5
  const require_implemented_methods = require("./implemented-methods-C7ScGvEz.js");
@@ -50773,7 +50773,7 @@ function groupTemplate(id) {
50773
50773
  //#region src/generated/history-catalog.ts
50774
50774
  /**
50775
50775
  * Cap history catalog, projected from every `*.cap.ts` `history` block.
50776
- * 45 caps with series (104 series), 38 caps answered `'none'`.
50776
+ * 45 caps with series (104 series), 39 caps answered `'none'`.
50777
50777
  * Field keys are `runtimeState` paths (`a.b` into fixed objects only).
50778
50778
  */
50779
50779
  var HISTORY_CATALOG = {
@@ -51345,6 +51345,7 @@ var HISTORY_NONE_CAPS = [
51345
51345
  "control",
51346
51346
  "day-night",
51347
51347
  "doorbell",
51348
+ "error",
51348
51349
  "event-emitter",
51349
51350
  "feature-probe",
51350
51351
  "group-active",
@@ -60738,6 +60739,87 @@ var enumSensorCapability = {
60738
60739
  }
60739
60740
  };
60740
60741
  //#endregion
60742
+ //#region src/capabilities/error.cap.ts
60743
+ /** How loudly a fault wants the operator. Both tiers raise the attention event. */
60744
+ var DeviceErrorSeveritySchema = zod.z.enum(["warning", "error"]);
60745
+ /** One fault of a device that can raise several at once. */
60746
+ var DeviceFaultSchema = zod.z.object({
60747
+ /** The device's own code, as the vendor names it. */
60748
+ code: zod.z.string(),
60749
+ /** Already translated by the provider (it owns the vendor vocabulary). */
60750
+ label: zod.z.string(),
60751
+ severity: DeviceErrorSeveritySchema
60752
+ });
60753
+ /**
60754
+ * The fault a device reports right now. One slice per device.
60755
+ *
60756
+ * `active` is tri-state: `null` is "the provider has not read it yet" and is
60757
+ * never drawn as "no fault" nor as a fault (D315, D393). The provider filters
60758
+ * what is not a fault (a completion or reminder code) BEFORE it writes `true`.
60759
+ *
60760
+ * The cap's name is the key a template reads (`{{ alias.error.label }}`, D1021).
60761
+ */
60762
+ var ErrorStatusSchema = zod.z.object({
60763
+ active: zod.z.boolean().nullable(),
60764
+ /** The code of the principal fault; `null` when none (or unknown). */
60765
+ code: zod.z.string().nullable(),
60766
+ /** The principal fault's words, provider-translated; `null` when none. */
60767
+ label: zod.z.string().nullable(),
60768
+ severity: DeviceErrorSeveritySchema,
60769
+ /** Ms epoch the current fault started; `null` when none or not known. */
60770
+ since: zod.z.number().nullable(),
60771
+ /** Every fault, for a device that raises several. The principal is the first. */
60772
+ faults: zod.z.array(DeviceFaultSchema).optional(),
60773
+ /** Ms epoch of the last read the provider made of the fault. */
60774
+ lastFetchedAt: zod.z.number()
60775
+ });
60776
+ /** The slice before the provider has read anything: unknown, not "fine". */
60777
+ var ERROR_STATUS_COLD = {
60778
+ active: null,
60779
+ code: null,
60780
+ label: null,
60781
+ severity: "error",
60782
+ since: null,
60783
+ lastFetchedAt: 0
60784
+ };
60785
+ var errorCapability = {
60786
+ name: "error",
60787
+ scope: "device",
60788
+ deviceNative: true,
60789
+ mode: "singleton",
60790
+ methods: {},
60791
+ status: {
60792
+ schema: ErrorStatusSchema,
60793
+ kind: "push",
60794
+ empty: ERROR_STATUS_COLD
60795
+ },
60796
+ runtimeState: ErrorStatusSchema,
60797
+ /**
60798
+ * Runtime-state durability: **restored** — the previous observation is what
60799
+ * lets the first reading after a restart be a COMPARISON: a fault that was
60800
+ * already open must not announce itself a second time.
60801
+ *
60802
+ * See `RuntimeStateDurability`. Enforced by
60803
+ * `scripts/check-runtime-state-durability.ts`.
60804
+ */
60805
+ durability: "restored",
60806
+ volatileStateFields: ["lastFetchedAt"],
60807
+ /** The fault itself is carried by the attention alerts; no series is recorded. */
60808
+ history: "none",
60809
+ vocabulary: {
60810
+ noun: require_sleep.t("Fault", "Guasto"),
60811
+ order: 5265,
60812
+ state: [{
60813
+ kind: "boolean",
60814
+ field: "active",
60815
+ label: require_sleep.t("Fault", "Guasto"),
60816
+ whenTrue: require_sleep.t("When {device} reports a fault", "Quando {device} segnala un guasto"),
60817
+ whenFalse: require_sleep.t("When the fault of {device} clears", "Quando il guasto di {device} si risolve"),
60818
+ icon: "triangle-alert"
60819
+ }]
60820
+ }
60821
+ };
60822
+ //#endregion
60741
60823
  //#region src/capabilities/face-gallery.cap.ts
60742
60824
  var IdentitySchema = zod.z.object({
60743
60825
  id: zod.z.string(),
@@ -101338,6 +101420,7 @@ var CAPABILITY_NAMES = {
101338
101420
  embeddingEncoder: "embedding-encoder",
101339
101421
  energySystem: "energy-system",
101340
101422
  enumSensor: "enum-sensor",
101423
+ error: "error",
101341
101424
  eventEmitter: "event-emitter",
101342
101425
  faceGallery: "face-gallery",
101343
101426
  failureContribution: "failure-contribution",
@@ -101764,6 +101847,10 @@ var CAPABILITY_ROUTER_KEYS = [
101764
101847
  key: "enumSensor",
101765
101848
  name: "enum-sensor"
101766
101849
  },
101850
+ {
101851
+ key: "error",
101852
+ name: "error"
101853
+ },
101767
101854
  {
101768
101855
  key: "eventEmitter",
101769
101856
  name: "event-emitter"
@@ -102387,6 +102474,7 @@ var ALL_CAPABILITY_DEFINITIONS = [
102387
102474
  embeddingEncoderCapability,
102388
102475
  energySystemCapability,
102389
102476
  enumSensorCapability,
102477
+ errorCapability,
102390
102478
  eventEmitterCapability,
102391
102479
  faceGalleryCapability,
102392
102480
  failureContributionCapability,
@@ -110057,6 +110145,7 @@ var DEVICE_LOCAL_STATE_CAPS = {
110057
110145
  doorbell: doorbellCapability,
110058
110146
  energySystem: energySystemCapability,
110059
110147
  enumSensor: enumSensorCapability,
110148
+ error: errorCapability,
110060
110149
  eventEmitter: eventEmitterCapability,
110061
110150
  fanControl: fanControlCapability,
110062
110151
  featureProbe: featureProbeCapability,
@@ -110119,6 +110208,56 @@ var DEVICE_LOCAL_STATE_CAPS = {
110119
110208
  zones: zonesCapability
110120
110209
  };
110121
110210
  //#endregion
110211
+ //#region src/device/device-error-episode.ts
110212
+ /**
110213
+ * The edge between two readings, or `null` for no edge.
110214
+ *
110215
+ * - `null`/cold → `true` is a START (a fault already open at boot is one);
110216
+ * - `true` → `false` is a RESOLVE;
110217
+ * - an UNKNOWN reading (`active: null`) is never an edge, in either direction —
110218
+ * a failed read must neither raise nor close an episode (D393, D49);
110219
+ * - `true` → `true` is the same episode, whatever the code did.
110220
+ */
110221
+ function deviceErrorEdge(previous, next) {
110222
+ if (next.active === true && previous?.active !== true) return "start";
110223
+ if (next.active === false && previous?.active === true) return "resolve";
110224
+ return null;
110225
+ }
110226
+ function deviceErrorAlertId(deviceId) {
110227
+ return `device-error:${String(deviceId)}`;
110228
+ }
110229
+ /** The alert that opens an episode. `since` is the fault's own start, else `now`. */
110230
+ function buildDeviceErrorAlert(deviceId, deviceName, status, now) {
110231
+ const label = status.label ?? status.code ?? "Fault";
110232
+ const startedAt = status.since ?? now;
110233
+ const alertId = deviceErrorAlertId(deviceId);
110234
+ return {
110235
+ id: alertId,
110236
+ category: "device.error",
110237
+ severity: "critical",
110238
+ title: `${deviceName}: ${label}`,
110239
+ message: `${deviceName} reports a fault: ${label}.`,
110240
+ action: {
110241
+ label: "Open device",
110242
+ href: `/devices/${String(deviceId)}`,
110243
+ navigation: "app"
110244
+ },
110245
+ status: "active",
110246
+ read: false,
110247
+ createdAt: now,
110248
+ updatedAt: now,
110249
+ source: {
110250
+ type: "device",
110251
+ id: String(deviceId)
110252
+ },
110253
+ metadata: {
110254
+ episodeId: `${alertId}@${String(startedAt)}`,
110255
+ code: status.code,
110256
+ deviceSeverity: status.severity
110257
+ }
110258
+ };
110259
+ }
110260
+ //#endregion
110122
110261
  //#region src/device/base-device.ts
110123
110262
  var BaseDevice = class {
110124
110263
  id;
@@ -110419,6 +110558,68 @@ var BaseDevice = class {
110419
110558
  } catch (err) {}
110420
110559
  }
110421
110560
  /**
110561
+ * Declare that this device can report a fault (the `error` cap). The slice
110562
+ * starts UNKNOWN — a restored slice is kept, so a fault that was open before
110563
+ * a restart is compared, not announced again.
110564
+ */
110565
+ registerErrorCap() {
110566
+ this.ctx.registerNativeCap?.(errorCapability, {});
110567
+ if (this.runtimeState.getCapState(errorCapability.name) === void 0) this.setCapSlice(errorCapability, ERROR_STATUS_COLD);
110568
+ }
110569
+ /**
110570
+ * Publish the device's fault. The slice is written; on an EDGE (a fault
110571
+ * starts, or one resolves) an attention episode opens or closes through the
110572
+ * alerts cap, which the notification center announces as
110573
+ * `device-attention-required` / `-resolved`. An unknown reading is never an
110574
+ * edge. No rule exists by default: it notifies when the operator makes one.
110575
+ */
110576
+ async publishError(reading) {
110577
+ const previous = this.getCapSlice(errorCapability);
110578
+ if (reading.active === null && previous !== null && previous.active !== null) return;
110579
+ const now = Date.now();
110580
+ const edge = deviceErrorEdge(previous, reading);
110581
+ const next = edge === "start" && reading.since === null ? {
110582
+ ...reading,
110583
+ since: now
110584
+ } : reading;
110585
+ this.setCapSlice(errorCapability, next);
110586
+ if (edge === null) return;
110587
+ const alerts = this.ctx.api.alerts;
110588
+ if (alerts === void 0) {
110589
+ this.ctx.logger.warn("device error: attention event skipped — alerts capability missing", {
110590
+ tags: { deviceId: this.id },
110591
+ meta: { edge }
110592
+ });
110593
+ return;
110594
+ }
110595
+ try {
110596
+ if (edge === "start") await alerts.emit.mutate(buildDeviceErrorAlert(this.id, this.name, next, now));
110597
+ else await alerts.update.mutate({
110598
+ alertId: deviceErrorAlertId(this.id),
110599
+ patch: {
110600
+ status: "completed",
110601
+ read: true,
110602
+ updatedAt: now
110603
+ }
110604
+ });
110605
+ this.ctx.logger.info(`device error: ${edge === "start" ? "raised" : "resolved"}`, {
110606
+ tags: { deviceId: this.id },
110607
+ meta: {
110608
+ code: next.code,
110609
+ label: next.label
110610
+ }
110611
+ });
110612
+ } catch (err) {
110613
+ this.ctx.logger.warn("device error: attention event failed", {
110614
+ tags: { deviceId: this.id },
110615
+ meta: {
110616
+ edge,
110617
+ error: require_composed_stable_id.errMsg(err)
110618
+ }
110619
+ });
110620
+ }
110621
+ }
110622
+ /**
110422
110623
  * Typed read-through to a cap-keyed runtime-state slice. Drivers
110423
110624
  * call `this.getCapSlice(batteryCapability)` and the return type
110424
110625
  * is inferred from the cap's `runtimeState` Zod schema — no string
@@ -119797,6 +119998,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
119797
119998
  access: "view",
119798
119999
  role: "viewer"
119799
120000
  },
120001
+ "error.getStatus": {
120002
+ capName: "error",
120003
+ capScope: "device",
120004
+ addonId: null,
120005
+ access: "view",
120006
+ role: "viewer"
120007
+ },
119800
120008
  "eventEmitter.getStatus": {
119801
120009
  capName: "event-emitter",
119802
120010
  capScope: "device",
@@ -127026,6 +127234,7 @@ var KNOWN_CAP_NAMES = [
127026
127234
  "embedding-encoder",
127027
127235
  "energy-system",
127028
127236
  "enum-sensor",
127237
+ "error",
127029
127238
  "event-emitter",
127030
127239
  "face-gallery",
127031
127240
  "failure-contribution",
@@ -127200,6 +127409,7 @@ var DEVICE_CAP_NAMES = [
127200
127409
  "doorbell",
127201
127410
  "energy-system",
127202
127411
  "enum-sensor",
127412
+ "error",
127203
127413
  "event-emitter",
127204
127414
  "fan-control",
127205
127415
  "feature-probe",
@@ -129329,6 +129539,7 @@ var CAP_NAMES_WITH_STATUS = [
129329
129539
  "doorbell",
129330
129540
  "energy-system",
129331
129541
  "enum-sensor",
129542
+ "error",
129332
129543
  "event-emitter",
129333
129544
  "fan-control",
129334
129545
  "feature-probe",
@@ -130374,6 +130585,11 @@ var METHOD_DEVICE_SELECTORS = Object.freeze({
130374
130585
  form: "single",
130375
130586
  optional: false
130376
130587
  }],
130588
+ "error.getStatus": [{
130589
+ name: "deviceId",
130590
+ form: "single",
130591
+ optional: false
130592
+ }],
130377
130593
  "eventEmitter.getStatus": [{
130378
130594
  name: "deviceId",
130379
130595
  form: "single",
@@ -132767,7 +132983,7 @@ function getCapsByProviderKind(kind) {
132767
132983
  //#region src/generated/runtime-state-durability.ts
132768
132984
  /**
132769
132985
  * Per-cap runtime-state policy, projected from every `*.cap.ts` that declares
132770
- * `runtimeState`. 84 caps: 42 `restored`, 42 `session`.
132986
+ * `runtimeState`. 85 caps: 43 `restored`, 42 `session`.
132771
132987
  *
132772
132988
  * A cap absent from this map has no runtime-state slice at all. A cap PRESENT
132773
132989
  * with `durability: 'session'` has one and has decided not to keep it.
@@ -132870,6 +133086,10 @@ var RUNTIME_STATE_POLICY = {
132870
133086
  durability: "restored",
132871
133087
  volatileFields: ["lastFetchedAt", "timestamp"]
132872
133088
  },
133089
+ "error": {
133090
+ durability: "restored",
133091
+ volatileFields: ["lastFetchedAt"]
133092
+ },
132873
133093
  "event-emitter": {
132874
133094
  durability: "session",
132875
133095
  volatileFields: []
@@ -133148,6 +133368,7 @@ var RESTORED_CAP_NAMES = [
133148
133368
  "device-status",
133149
133369
  "doorbell",
133150
133370
  "enum-sensor",
133371
+ "error",
133151
133372
  "flood",
133152
133373
  "gas",
133153
133374
  "humidity-sensor",
@@ -147330,11 +147551,13 @@ exports.DeviceCredentialSchema = DeviceCredentialSchema;
147330
147551
  exports.DeviceCredentialStatusSchema = DeviceCredentialStatusSchema;
147331
147552
  exports.DeviceDataEntrySchema = DeviceDataEntrySchema;
147332
147553
  exports.DeviceEnrollProofSchema = DeviceEnrollProofSchema;
147554
+ exports.DeviceErrorSeveritySchema = DeviceErrorSeveritySchema;
147333
147555
  exports.DeviceExportExposeInputSchema = ExposeInputSchema;
147334
147556
  exports.DeviceExportInstancePinSchema = InstancePinSchema;
147335
147557
  exports.DeviceExportSetExposedNameInputSchema = SetExposedNameInputSchema;
147336
147558
  exports.DeviceExportStatusSchema = DeviceExportStatusSchema;
147337
147559
  exports.DeviceExportUnexposeInputSchema = UnexposeInputSchema;
147560
+ exports.DeviceFaultSchema = DeviceFaultSchema;
147338
147561
  exports.DeviceFeature = require_composed_stable_id.DeviceFeature;
147339
147562
  exports.DeviceFiredMatchSchema = DeviceFiredMatchSchema;
147340
147563
  exports.DeviceFiredWatch = DeviceFiredWatch;
@@ -147426,6 +147649,7 @@ exports.EMBEDDING_REQUIREMENTS_UNAVAILABLE = EMBEDDING_REQUIREMENTS_UNAVAILABLE;
147426
147649
  exports.EMPTY_AUTOMATION_STATE = EMPTY_AUTOMATION_STATE;
147427
147650
  exports.EMPTY_REMOTE_ASSUMED_STATE = EMPTY_REMOTE_ASSUMED_STATE;
147428
147651
  exports.EMPTY_REMOTE_CONFIG = EMPTY_REMOTE_CONFIG;
147652
+ exports.ERROR_STATUS_COLD = ERROR_STATUS_COLD;
147429
147653
  exports.ESTIMATE_COMPUTE_RATIO_MAX = ESTIMATE_COMPUTE_RATIO_MAX;
147430
147654
  exports.ESTIMATE_COMPUTE_RATIO_MIN = ESTIMATE_COMPUTE_RATIO_MIN;
147431
147655
  exports.EVENTFUL_CAP_NAMES = EVENTFUL_CAP_NAMES;
@@ -147484,6 +147708,7 @@ exports.EnumSensorDateTimeFormatSchema = EnumSensorDateTimeFormatSchema;
147484
147708
  exports.EnumSensorStatusSchema = EnumSensorStatusSchema;
147485
147709
  exports.ErrorCodeSchema = require_sleep.ErrorCodeSchema;
147486
147710
  exports.ErrorI18nPayloadSchema = require_sleep.ErrorI18nPayloadSchema;
147711
+ exports.ErrorStatusSchema = ErrorStatusSchema;
147487
147712
  exports.EventCategory = require_event_category.EventCategory;
147488
147713
  exports.EventDensityBucketSchema = EventDensityBucketSchema;
147489
147714
  exports.EventDensityForDeviceSchema = EventDensityForDeviceSchema;
@@ -149403,6 +149628,7 @@ exports.buildBenchStepTree = buildBenchStepTree;
149403
149628
  exports.buildCapabilityLookup = buildCapabilityLookup;
149404
149629
  exports.buildDeviceAdminUrl = buildDeviceAdminUrl;
149405
149630
  exports.buildDeviceEnrollmentLink = buildDeviceEnrollmentLink;
149631
+ exports.buildDeviceErrorAlert = buildDeviceErrorAlert;
149406
149632
  exports.buildDeviceSignatureMessage = buildDeviceSignatureMessage;
149407
149633
  exports.buildDraftJsonSchema = buildDraftJsonSchema;
149408
149634
  exports.buildDraftPrompt = buildDraftPrompt;
@@ -149671,6 +149897,8 @@ exports.deviceAttentionKind = deviceAttentionKind;
149671
149897
  exports.deviceBackendToFormat = deviceBackendToFormat;
149672
149898
  exports.deviceCredentialsCapability = deviceCredentialsCapability;
149673
149899
  exports.deviceCustomAction = require_sleep.deviceCustomAction;
149900
+ exports.deviceErrorAlertId = deviceErrorAlertId;
149901
+ exports.deviceErrorEdge = deviceErrorEdge;
149674
149902
  exports.deviceExportCapability = deviceExportCapability;
149675
149903
  exports.deviceExportStatusInstanceOf = statusInstanceOf;
149676
149904
  exports.deviceExtensionCapability = deviceExtensionCapability;
@@ -149731,6 +149959,7 @@ exports.enumerateInferenceDevices = enumerateInferenceDevices;
149731
149959
  exports.enumerateItemArrayFields = enumerateItemArrayFields;
149732
149960
  exports.enumerateSchemaFields = enumerateSchemaFields;
149733
149961
  exports.errMsg = require_composed_stable_id.errMsg;
149962
+ exports.errorCapability = errorCapability;
149734
149963
  exports.estimateNodeBenchmarkDurationMs = estimateNodeBenchmarkDurationMs;
149735
149964
  exports.evaluateAggregate = evaluateAggregate;
149736
149965
  exports.evaluateAst = require_implemented_methods.evaluateAst;