@camstack/server 1.2.847 → 1.2.848

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 (91) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/trpc/generated-cap-routers.js +9 -0
  3. package/dist/core/addon/instance-lifecycle.js +10 -6
  4. package/package.json +9 -8
  5. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/system/dist/builtins/autotrack/index.js +1 -1
  12. package/system/dist/builtins/autotrack/index.mjs +1 -1
  13. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  14. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +2 -2
  15. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  16. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  17. package/system/dist/builtins/camera-grid/index.js +1 -1
  18. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  19. package/system/dist/builtins/composer/composer.addon.js +4 -4
  20. package/system/dist/builtins/composer/composer.addon.mjs +4 -4
  21. package/system/dist/builtins/console-logging/index.js +1 -1
  22. package/system/dist/builtins/console-logging/index.mjs +1 -1
  23. package/system/dist/builtins/core-blocks/core-blocks.addon.js +36 -8
  24. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +36 -8
  25. package/system/dist/builtins/core-blocks/remote-service.d.ts +5 -1
  26. package/system/dist/builtins/core-blocks/remote-wiring.d.ts +3 -1
  27. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  28. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  29. package/system/dist/builtins/device-manager/device-manager.addon.js +2 -2
  30. package/system/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
  31. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  32. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  33. package/system/dist/builtins/keychain/index.js +4 -4
  34. package/system/dist/builtins/keychain/index.mjs +4 -4
  35. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  36. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  37. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  38. package/system/dist/builtins/local-auth/local-auth.addon.mjs +2 -2
  39. package/system/dist/builtins/local-network/local-network.addon.js +3 -3
  40. package/system/dist/builtins/local-network/local-network.addon.mjs +3 -3
  41. package/system/dist/builtins/loki-logging/index.js +1 -1
  42. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  43. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  44. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  45. package/system/dist/builtins/platform-probe/index.js +1 -1
  46. package/system/dist/builtins/platform-probe/index.mjs +1 -1
  47. package/system/dist/builtins/record-entries/index.js +1 -1
  48. package/system/dist/builtins/record-entries/index.mjs +1 -1
  49. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  50. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  51. package/system/dist/builtins/snapshot/index.js +1 -1
  52. package/system/dist/builtins/snapshot/index.mjs +1 -1
  53. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  54. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  55. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  56. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  57. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +3 -3
  58. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +3 -3
  59. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  60. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  61. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  62. package/system/dist/builtins/system-config/system-config.addon.mjs +3 -3
  63. package/system/dist/builtins/winston-logging/index.js +1 -1
  64. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  65. package/system/dist/{capture-engine-BSDgRisG.mjs → capture-engine-BDgAg1_L.mjs} +1 -1
  66. package/system/dist/{capture-engine-B0oRy06v.js → capture-engine-CLow73VK.js} +1 -1
  67. package/system/dist/{composition-sources-ujH0OBVn.mjs → composition-sources-PCla-eR3.mjs} +1 -1
  68. package/system/dist/{composition-sources-SR0LOiwV.js → composition-sources-Xb2YACrP.js} +1 -1
  69. package/system/dist/{constants-B7eUjmLy.mjs → constants-Cjv1STtI.mjs} +1 -1
  70. package/system/dist/{constants-Bu2PpZxT.js → constants-Crx9nPwX.js} +1 -1
  71. package/system/dist/{device-ca-Ddx0w66k.mjs → device-ca-D5bhkYRx.mjs} +1 -1
  72. package/system/dist/{device-ca-DQVQodun.js → device-ca-jaJY-9dh.js} +1 -1
  73. package/system/dist/{dist-Btw-kJec.mjs → dist-CUB8zpv-.mjs} +233 -16
  74. package/system/dist/{dist-C2g-bkW3.js → dist-D9G24tL4.js} +233 -16
  75. package/system/dist/file-host-worker.js +1 -1
  76. package/system/dist/file-host-worker.mjs +1 -1
  77. package/system/dist/{hub-identity-BGQRouDQ.mjs → hub-identity-0lAqqUXZ.mjs} +1 -1
  78. package/system/dist/{hub-identity-DiXO_HL1.js → hub-identity-D6Yzg92a.js} +1 -1
  79. package/system/dist/{hub-mdns-ciao-BR2Zdm6h.js → hub-mdns-ciao-0vZomp05.js} +2 -2
  80. package/system/dist/{hub-mdns-ciao-DGGKuLGZ.mjs → hub-mdns-ciao-dT75vFJK.mjs} +2 -2
  81. package/system/dist/index.js +22 -10
  82. package/system/dist/index.mjs +22 -10
  83. package/system/dist/{legacy-integration-rows-door-50Uc78LM.mjs → legacy-integration-rows-door-CkwpRASZ.mjs} +1 -1
  84. package/system/dist/{legacy-integration-rows-door-OnrCmUJI.js → legacy-integration-rows-door-V0HNtga9.js} +1 -1
  85. package/system/dist/{rename-composition-block-kGqHAdUc.mjs → rename-composition-block-CKO6KFN4.mjs} +1 -1
  86. package/system/dist/{rename-composition-block-CjVxHVX1.js → rename-composition-block-CmNS12Yh.js} +1 -1
  87. package/system/dist/{restore-archive-Cxhhx7mC.mjs → restore-archive-Cp8P5gxb.mjs} +1 -1
  88. package/system/dist/{restore-archive-DQZdAca-.js → restore-archive-DRyTaAb5.js} +1 -1
  89. package/system/dist/{wal-maintenance-DoZE1qG9.mjs → wal-maintenance-CyW12mpW.mjs} +0 -0
  90. package/system/dist/{wal-maintenance-C4WfHqw5.js → wal-maintenance-EJcAHbIL.js} +0 -0
  91. package/system/package.json +1 -1
@@ -1243,7 +1243,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
1243
1243
  */
1244
1244
  var COMPOSED_DEVICE_STABLE_ID_PREFIX = "composed-";
1245
1245
  //#endregion
1246
- //#region ../types/dist/sleep-D0roI_CZ.mjs
1246
+ //#region ../types/dist/sleep-Ba1dJYDo.mjs
1247
1247
  /**
1248
1248
  * The audio chunk plane's byte format, and the ONE expansion from a coded
1249
1249
  * window to float samples (D455).
@@ -8266,7 +8266,10 @@ var ACTUATOR_CAP_VOCABULARY = {
8266
8266
  "ir-transmitter": {
8267
8267
  scope: "device",
8268
8268
  noun: t("IR / RF transmitter", "Trasmettitore IR / RF"),
8269
- notOperatorFacing: { send: "a raw pulse train is not something an operator composes in an automation; the remote that owns the command table sends it" }
8269
+ notOperatorFacing: {
8270
+ send: "a raw pulse train is not something an operator composes in an automation; the remote that owns the command table sends it",
8271
+ learn: "an interactive capture the operator starts from the source dialog and answers by pressing a physical remote; no automation can supply the signal"
8272
+ }
8270
8273
  },
8271
8274
  control: {
8272
8275
  scope: "device",
@@ -53685,11 +53688,13 @@ var IrCodecError = class extends Error {
53685
53688
  this.code = code;
53686
53689
  }
53687
53690
  };
53691
+ /** Maximum number of mark/space entries one pulse train may carry. */
53692
+ var IR_TIMINGS_MAX = 1024;
53688
53693
  /**
53689
53694
  * A pulse train in signed microseconds: mark (+) first, then space (-), strictly
53690
53695
  * alternating, no zeros, 2..1024 entries.
53691
53696
  */
53692
- var IrTimingsSchema = z.array(z.number().int()).min(2).max(1024).superRefine((timings, ctx) => {
53697
+ var IrTimingsSchema = z.array(z.number().int()).min(2).max(IR_TIMINGS_MAX).superRefine((timings, ctx) => {
53693
53698
  timings.forEach((value, index) => {
53694
53699
  const expectMark = index % 2 === 0;
53695
53700
  if (value === 0 || value > 0 !== expectMark) ctx.addIssue({
@@ -53736,15 +53741,186 @@ function decodePronto(code) {
53736
53741
  carrierHz: Math.round(1e6 / unitUs)
53737
53742
  };
53738
53743
  }
53739
- /** What a remote command stores: a raw pulse train, or a learned Pronto code. */
53740
- var IrPayloadSchema = z.discriminatedUnion("kind", [z.object({
53741
- kind: z.literal("raw"),
53742
- timings: z.array(z.number().int()),
53743
- settings: TransmitSettingsSchema.optional()
53744
- }), z.object({
53745
- kind: z.literal("pronto"),
53746
- code: z.string()
53747
- })]);
53744
+ /**
53745
+ * FastLZ level 1: a byte-oriented LZ77 stream. A control byte below 32 starts a
53746
+ * literal run of `ctrl + 1` bytes; otherwise it is a back-reference whose length
53747
+ * is `ctrl >> 5` (extended by one byte when 7) and whose distance is split
53748
+ * between the low 5 bits and the next byte.
53749
+ */
53750
+ var MAX_DISTANCE = 8192;
53751
+ var MAX_LITERAL_RUN = 32;
53752
+ var MIN_MATCH = 3;
53753
+ var MAX_MATCH = 264;
53754
+ /**
53755
+ * Most bytes a decoded IR code may hold: two bytes per timing. A level-1 stream
53756
+ * can expand ~130x, so the decoder checks this bound before every write.
53757
+ */
53758
+ var IR_DECOMPRESSED_MAX = IR_TIMINGS_MAX * 2;
53759
+ function fastlzDecompress(input) {
53760
+ const out = [];
53761
+ let ip = 0;
53762
+ const room = (count) => {
53763
+ if (out.length + count > IR_DECOMPRESSED_MAX) throw new IrCodecError("tuya-malformed", "decompressed code is larger than any IR train");
53764
+ };
53765
+ const next = () => {
53766
+ const byte = input[ip++];
53767
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "compressed stream is truncated");
53768
+ return byte;
53769
+ };
53770
+ while (ip < input.length) {
53771
+ const ctrl = next();
53772
+ if (ctrl < 32) {
53773
+ room(ctrl + 1);
53774
+ for (let i = 0; i <= ctrl; i++) out.push(next());
53775
+ continue;
53776
+ }
53777
+ let len = (ctrl >> 5) - 1;
53778
+ if (len === 6) len += next();
53779
+ const distance = ((ctrl & 31) << 8) + next() + 1;
53780
+ const start = out.length - distance;
53781
+ if (start < 0) throw new IrCodecError("tuya-malformed", "back-reference points before the stream");
53782
+ room(len + 3);
53783
+ for (let i = 0; i < len + 3; i++) {
53784
+ const byte = out[start + i];
53785
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "back-reference is invalid");
53786
+ out.push(byte);
53787
+ }
53788
+ }
53789
+ return Uint8Array.from(out);
53790
+ }
53791
+ function fastlzCompress(input) {
53792
+ const out = [];
53793
+ const lastSeen = /* @__PURE__ */ new Map();
53794
+ let literalStart = 0;
53795
+ const flushLiterals = (end) => {
53796
+ for (let from = literalStart; from < end; from += MAX_LITERAL_RUN) {
53797
+ const to = Math.min(from + MAX_LITERAL_RUN, end);
53798
+ out.push(to - from - 1);
53799
+ for (let i = from; i < to; i++) out.push(input[i] ?? 0);
53800
+ }
53801
+ };
53802
+ let pos = 0;
53803
+ while (pos < input.length) {
53804
+ let matchLen = 0;
53805
+ let matchDistance = 0;
53806
+ if (pos + MIN_MATCH <= input.length) {
53807
+ const key = (input[pos] ?? 0) << 16 | (input[pos + 1] ?? 0) << 8 | (input[pos + 2] ?? 0);
53808
+ const candidate = lastSeen.get(key);
53809
+ lastSeen.set(key, pos);
53810
+ if (candidate !== void 0 && pos - candidate <= MAX_DISTANCE) {
53811
+ let len = 0;
53812
+ while (pos + len < input.length && len < MAX_MATCH && input[candidate + len] === input[pos + len]) len++;
53813
+ if (len >= MIN_MATCH) {
53814
+ matchLen = len;
53815
+ matchDistance = pos - candidate - 1;
53816
+ }
53817
+ }
53818
+ }
53819
+ if (matchLen === 0) {
53820
+ pos++;
53821
+ continue;
53822
+ }
53823
+ flushLiterals(pos);
53824
+ const enc = matchLen - 2;
53825
+ if (enc < 7) out.push(enc << 5 | matchDistance >> 8);
53826
+ else out.push(224 | matchDistance >> 8, enc - 7);
53827
+ out.push(matchDistance & 255);
53828
+ pos += matchLen;
53829
+ literalStart = pos;
53830
+ }
53831
+ flushLiterals(input.length);
53832
+ return Uint8Array.from(out);
53833
+ }
53834
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
53835
+ var MAX_DURATION_US = 65535;
53836
+ function toBase64(bytes) {
53837
+ let out = "";
53838
+ for (let i = 0; i < bytes.length; i += 3) {
53839
+ const a = bytes[i] ?? 0;
53840
+ const b = bytes[i + 1] ?? 0;
53841
+ const c = bytes[i + 2] ?? 0;
53842
+ const word = a << 16 | b << 8 | c;
53843
+ out += ALPHABET[word >> 18 & 63];
53844
+ out += ALPHABET[word >> 12 & 63];
53845
+ out += i + 1 < bytes.length ? ALPHABET[word >> 6 & 63] : "=";
53846
+ out += i + 2 < bytes.length ? ALPHABET[word & 63] : "=";
53847
+ }
53848
+ return out;
53849
+ }
53850
+ function fromBase64(text) {
53851
+ const clean = text.trim().replace(/=+$/, "");
53852
+ if (clean.length === 0 || clean.length % 4 === 1) throw new IrCodecError("tuya-malformed", "not a base64 string");
53853
+ const out = [];
53854
+ let bits = 0;
53855
+ let acc = 0;
53856
+ for (const ch of clean) {
53857
+ const value = ALPHABET.indexOf(ch);
53858
+ if (value < 0) throw new IrCodecError("tuya-malformed", "not a base64 string");
53859
+ acc = acc << 6 | value;
53860
+ bits += 6;
53861
+ if (bits >= 8) {
53862
+ bits -= 8;
53863
+ out.push(acc >> bits & 255);
53864
+ }
53865
+ }
53866
+ return Uint8Array.from(out);
53867
+ }
53868
+ /** Signed pulse train to a Tuya IR code: base64(FastLZ(uint16 LE durations)). */
53869
+ function encodeTuya(timings) {
53870
+ const bytes = new Uint8Array(timings.length * 2);
53871
+ timings.forEach((value, index) => {
53872
+ const duration = Math.abs(value);
53873
+ if (duration === 0 || duration > MAX_DURATION_US) throw new IrCodecError("invalid-timings", `timing ${index} does not fit 16 bits`);
53874
+ bytes[index * 2] = duration & 255;
53875
+ bytes[index * 2 + 1] = duration >> 8;
53876
+ });
53877
+ return toBase64(fastlzCompress(bytes));
53878
+ }
53879
+ /** A Tuya IR code to a signed pulse train (mark first). Throws `IrCodecError`. */
53880
+ function decodeTuya(code) {
53881
+ const bytes = fastlzDecompress(fromBase64(code));
53882
+ if (bytes.length === 0 || bytes.length % 2 !== 0) throw new IrCodecError("tuya-malformed", "payload is not a list of 16-bit durations");
53883
+ const timings = [];
53884
+ for (let i = 0; i < bytes.length; i += 2) {
53885
+ const duration = (bytes[i] ?? 0) | (bytes[i + 1] ?? 0) << 8;
53886
+ timings.push(i / 2 % 2 === 0 ? duration : -duration);
53887
+ }
53888
+ const checked = IrTimingsSchema.safeParse(timings);
53889
+ if (!checked.success) throw new IrCodecError("tuya-malformed", checked.error.message);
53890
+ return checked.data;
53891
+ }
53892
+ /** Device-native IR code formats a transmitter can replay verbatim. */
53893
+ var IrNativeFormatSchema = z.enum(["tuya"]);
53894
+ /**
53895
+ * Longest native code accepted: base64 of the worst-case compressed stream
53896
+ * (every decoded byte as a literal, plus one control byte per 32), with margin.
53897
+ */
53898
+ var IR_NATIVE_CODE_MAX_CHARS = Math.ceil((IR_DECOMPRESSED_MAX + Math.ceil(IR_DECOMPRESSED_MAX / 32)) / 3) * 4 + 256;
53899
+ var IrNativeCodeSchema = z.object({
53900
+ format: IrNativeFormatSchema,
53901
+ code: z.string().min(1).max(IR_NATIVE_CODE_MAX_CHARS)
53902
+ });
53903
+ var IR_NATIVE_CODECS = { tuya: {
53904
+ encode: encodeTuya,
53905
+ decode: decodeTuya
53906
+ } };
53907
+ /** What a remote command stores: a raw pulse train, a learned Pronto code, or a device-native code. */
53908
+ var IrPayloadSchema = z.discriminatedUnion("kind", [
53909
+ z.object({
53910
+ kind: z.literal("raw"),
53911
+ timings: z.array(z.number().int()),
53912
+ settings: TransmitSettingsSchema.optional()
53913
+ }),
53914
+ z.object({
53915
+ kind: z.literal("pronto"),
53916
+ code: z.string()
53917
+ }),
53918
+ z.object({
53919
+ kind: z.literal("native"),
53920
+ format: IrNativeFormatSchema,
53921
+ code: z.string()
53922
+ })
53923
+ ]);
53748
53924
  /** Resolve a payload to what `ir-transmitter.send` takes. Throws `IrCodecError`. */
53749
53925
  function toTimings(payload) {
53750
53926
  if (payload.kind === "pronto") {
@@ -53754,6 +53930,10 @@ function toTimings(payload) {
53754
53930
  settings: { carrierHz: decoded.carrierHz }
53755
53931
  };
53756
53932
  }
53933
+ if (payload.kind === "native") return {
53934
+ timings: IR_NATIVE_CODECS[payload.format].decode(payload.code),
53935
+ settings: {}
53936
+ };
53757
53937
  const checked = IrTimingsSchema.safeParse(payload.timings);
53758
53938
  if (!checked.success) throw new IrCodecError("invalid-timings", checked.error.message);
53759
53939
  return {
@@ -68128,7 +68308,19 @@ var IrSendResultSchema = z.object({
68128
68308
  var IrTransmitterInfoSchema = z.object({
68129
68309
  media: z.array(IrMediumSchema),
68130
68310
  settable: z.array(TransmitSettingKeySchema),
68131
- maxTimings: z.number().int().positive()
68311
+ maxTimings: z.number().int().positive(),
68312
+ /** The transmitter can learn a code (`learn`). */
68313
+ learn: z.boolean().default(false),
68314
+ /** Native code formats the transmitter replays verbatim (`send.native`). */
68315
+ formats: z.array(IrNativeFormatSchema).default([])
68316
+ });
68317
+ var IR_LEARN_TIMEOUT_DEFAULT_MS = 2e4;
68318
+ var IR_LEARN_TIMEOUT_MAX_MS = 6e4;
68319
+ var IrLearnResultSchema = z.object({
68320
+ /** The code in the device's own format, when it reports one. */
68321
+ native: IrNativeCodeSchema.nullable(),
68322
+ timings: IrTimingsSchema,
68323
+ carrierHz: z.number().int().positive().nullable()
68132
68324
  });
68133
68325
  /**
68134
68326
  * ir-transmitter — emit a pulse train (infrared or RF) with settings. One cap
@@ -68139,7 +68331,12 @@ var IrTransmitterInfoSchema = z.object({
68139
68331
  * transmitter cannot be reached) and `ir-transmitter.too-long` (more pulses
68140
68332
  * than the transmitter's `maxTimings`). A setting the transmitter cannot apply
68141
68333
  * is NOT a refusal: the train is sent and the key comes back in
68142
- * `ignoredSettings`.
68334
+ * `ignoredSettings`. `send` takes exactly one of `timings` or `native` (a code
68335
+ * in a format listed in `getInfo.formats`).
68336
+ *
68337
+ * `learn` waits for the user to point a remote at the transmitter and refuses
68338
+ * with `ir-transmitter.learn-unsupported`, `ir-transmitter.learn-timeout` or
68339
+ * `ir-transmitter.learn-undecodable`.
68143
68340
  */
68144
68341
  var irTransmitterCapability = {
68145
68342
  name: "ir-transmitter",
@@ -68150,9 +68347,17 @@ var irTransmitterCapability = {
68150
68347
  methods: {
68151
68348
  send: method(z.object({
68152
68349
  deviceId: z.number().int().nonnegative(),
68153
- timings: IrTimingsSchema,
68350
+ timings: IrTimingsSchema.optional(),
68351
+ native: IrNativeCodeSchema.optional(),
68154
68352
  settings: TransmitSettingsSchema.optional()
68155
- }), IrSendResultSchema, {
68353
+ }).refine((input) => input.timings === void 0 !== (input.native === void 0), { message: "send takes exactly one of timings or native" }), IrSendResultSchema, {
68354
+ kind: "mutation",
68355
+ auth: "protected"
68356
+ }),
68357
+ learn: method(z.object({
68358
+ deviceId: z.number().int().nonnegative(),
68359
+ timeoutMs: z.number().int().positive().max(IR_LEARN_TIMEOUT_MAX_MS).default(IR_LEARN_TIMEOUT_DEFAULT_MS)
68360
+ }), IrLearnResultSchema, {
68156
68361
  kind: "mutation",
68157
68362
  auth: "protected"
68158
68363
  }),
@@ -108669,6 +108874,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
108669
108874
  access: "view",
108670
108875
  role: "viewer"
108671
108876
  },
108877
+ "irTransmitter.learn": {
108878
+ capName: "ir-transmitter",
108879
+ capScope: "device",
108880
+ addonId: null,
108881
+ access: "create",
108882
+ role: "viewer"
108883
+ },
108672
108884
  "irTransmitter.send": {
108673
108885
  capName: "ir-transmitter",
108674
108886
  capScope: "device",
@@ -116766,6 +116978,11 @@ Object.freeze({
116766
116978
  form: "single",
116767
116979
  optional: false
116768
116980
  }],
116981
+ "irTransmitter.learn": [{
116982
+ name: "deviceId",
116983
+ form: "single",
116984
+ optional: false
116985
+ }],
116769
116986
  "irTransmitter.send": [{
116770
116987
  name: "deviceId",
116771
116988
  form: "single",
@@ -1243,7 +1243,7 @@ var DeviceRole = /* @__PURE__ */ function(DeviceRole) {
1243
1243
  */
1244
1244
  var COMPOSED_DEVICE_STABLE_ID_PREFIX = "composed-";
1245
1245
  //#endregion
1246
- //#region ../types/dist/sleep-D0roI_CZ.mjs
1246
+ //#region ../types/dist/sleep-Ba1dJYDo.mjs
1247
1247
  /**
1248
1248
  * The audio chunk plane's byte format, and the ONE expansion from a coded
1249
1249
  * window to float samples (D455).
@@ -8266,7 +8266,10 @@ var ACTUATOR_CAP_VOCABULARY = {
8266
8266
  "ir-transmitter": {
8267
8267
  scope: "device",
8268
8268
  noun: t("IR / RF transmitter", "Trasmettitore IR / RF"),
8269
- notOperatorFacing: { send: "a raw pulse train is not something an operator composes in an automation; the remote that owns the command table sends it" }
8269
+ notOperatorFacing: {
8270
+ send: "a raw pulse train is not something an operator composes in an automation; the remote that owns the command table sends it",
8271
+ learn: "an interactive capture the operator starts from the source dialog and answers by pressing a physical remote; no automation can supply the signal"
8272
+ }
8270
8273
  },
8271
8274
  control: {
8272
8275
  scope: "device",
@@ -53685,11 +53688,13 @@ var IrCodecError = class extends Error {
53685
53688
  this.code = code;
53686
53689
  }
53687
53690
  };
53691
+ /** Maximum number of mark/space entries one pulse train may carry. */
53692
+ var IR_TIMINGS_MAX = 1024;
53688
53693
  /**
53689
53694
  * A pulse train in signed microseconds: mark (+) first, then space (-), strictly
53690
53695
  * alternating, no zeros, 2..1024 entries.
53691
53696
  */
53692
- var IrTimingsSchema = zod.z.array(zod.z.number().int()).min(2).max(1024).superRefine((timings, ctx) => {
53697
+ var IrTimingsSchema = zod.z.array(zod.z.number().int()).min(2).max(IR_TIMINGS_MAX).superRefine((timings, ctx) => {
53693
53698
  timings.forEach((value, index) => {
53694
53699
  const expectMark = index % 2 === 0;
53695
53700
  if (value === 0 || value > 0 !== expectMark) ctx.addIssue({
@@ -53736,15 +53741,186 @@ function decodePronto(code) {
53736
53741
  carrierHz: Math.round(1e6 / unitUs)
53737
53742
  };
53738
53743
  }
53739
- /** What a remote command stores: a raw pulse train, or a learned Pronto code. */
53740
- var IrPayloadSchema = zod.z.discriminatedUnion("kind", [zod.z.object({
53741
- kind: zod.z.literal("raw"),
53742
- timings: zod.z.array(zod.z.number().int()),
53743
- settings: TransmitSettingsSchema.optional()
53744
- }), zod.z.object({
53745
- kind: zod.z.literal("pronto"),
53746
- code: zod.z.string()
53747
- })]);
53744
+ /**
53745
+ * FastLZ level 1: a byte-oriented LZ77 stream. A control byte below 32 starts a
53746
+ * literal run of `ctrl + 1` bytes; otherwise it is a back-reference whose length
53747
+ * is `ctrl >> 5` (extended by one byte when 7) and whose distance is split
53748
+ * between the low 5 bits and the next byte.
53749
+ */
53750
+ var MAX_DISTANCE = 8192;
53751
+ var MAX_LITERAL_RUN = 32;
53752
+ var MIN_MATCH = 3;
53753
+ var MAX_MATCH = 264;
53754
+ /**
53755
+ * Most bytes a decoded IR code may hold: two bytes per timing. A level-1 stream
53756
+ * can expand ~130x, so the decoder checks this bound before every write.
53757
+ */
53758
+ var IR_DECOMPRESSED_MAX = IR_TIMINGS_MAX * 2;
53759
+ function fastlzDecompress(input) {
53760
+ const out = [];
53761
+ let ip = 0;
53762
+ const room = (count) => {
53763
+ if (out.length + count > IR_DECOMPRESSED_MAX) throw new IrCodecError("tuya-malformed", "decompressed code is larger than any IR train");
53764
+ };
53765
+ const next = () => {
53766
+ const byte = input[ip++];
53767
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "compressed stream is truncated");
53768
+ return byte;
53769
+ };
53770
+ while (ip < input.length) {
53771
+ const ctrl = next();
53772
+ if (ctrl < 32) {
53773
+ room(ctrl + 1);
53774
+ for (let i = 0; i <= ctrl; i++) out.push(next());
53775
+ continue;
53776
+ }
53777
+ let len = (ctrl >> 5) - 1;
53778
+ if (len === 6) len += next();
53779
+ const distance = ((ctrl & 31) << 8) + next() + 1;
53780
+ const start = out.length - distance;
53781
+ if (start < 0) throw new IrCodecError("tuya-malformed", "back-reference points before the stream");
53782
+ room(len + 3);
53783
+ for (let i = 0; i < len + 3; i++) {
53784
+ const byte = out[start + i];
53785
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "back-reference is invalid");
53786
+ out.push(byte);
53787
+ }
53788
+ }
53789
+ return Uint8Array.from(out);
53790
+ }
53791
+ function fastlzCompress(input) {
53792
+ const out = [];
53793
+ const lastSeen = /* @__PURE__ */ new Map();
53794
+ let literalStart = 0;
53795
+ const flushLiterals = (end) => {
53796
+ for (let from = literalStart; from < end; from += MAX_LITERAL_RUN) {
53797
+ const to = Math.min(from + MAX_LITERAL_RUN, end);
53798
+ out.push(to - from - 1);
53799
+ for (let i = from; i < to; i++) out.push(input[i] ?? 0);
53800
+ }
53801
+ };
53802
+ let pos = 0;
53803
+ while (pos < input.length) {
53804
+ let matchLen = 0;
53805
+ let matchDistance = 0;
53806
+ if (pos + MIN_MATCH <= input.length) {
53807
+ const key = (input[pos] ?? 0) << 16 | (input[pos + 1] ?? 0) << 8 | (input[pos + 2] ?? 0);
53808
+ const candidate = lastSeen.get(key);
53809
+ lastSeen.set(key, pos);
53810
+ if (candidate !== void 0 && pos - candidate <= MAX_DISTANCE) {
53811
+ let len = 0;
53812
+ while (pos + len < input.length && len < MAX_MATCH && input[candidate + len] === input[pos + len]) len++;
53813
+ if (len >= MIN_MATCH) {
53814
+ matchLen = len;
53815
+ matchDistance = pos - candidate - 1;
53816
+ }
53817
+ }
53818
+ }
53819
+ if (matchLen === 0) {
53820
+ pos++;
53821
+ continue;
53822
+ }
53823
+ flushLiterals(pos);
53824
+ const enc = matchLen - 2;
53825
+ if (enc < 7) out.push(enc << 5 | matchDistance >> 8);
53826
+ else out.push(224 | matchDistance >> 8, enc - 7);
53827
+ out.push(matchDistance & 255);
53828
+ pos += matchLen;
53829
+ literalStart = pos;
53830
+ }
53831
+ flushLiterals(input.length);
53832
+ return Uint8Array.from(out);
53833
+ }
53834
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
53835
+ var MAX_DURATION_US = 65535;
53836
+ function toBase64(bytes) {
53837
+ let out = "";
53838
+ for (let i = 0; i < bytes.length; i += 3) {
53839
+ const a = bytes[i] ?? 0;
53840
+ const b = bytes[i + 1] ?? 0;
53841
+ const c = bytes[i + 2] ?? 0;
53842
+ const word = a << 16 | b << 8 | c;
53843
+ out += ALPHABET[word >> 18 & 63];
53844
+ out += ALPHABET[word >> 12 & 63];
53845
+ out += i + 1 < bytes.length ? ALPHABET[word >> 6 & 63] : "=";
53846
+ out += i + 2 < bytes.length ? ALPHABET[word & 63] : "=";
53847
+ }
53848
+ return out;
53849
+ }
53850
+ function fromBase64(text) {
53851
+ const clean = text.trim().replace(/=+$/, "");
53852
+ if (clean.length === 0 || clean.length % 4 === 1) throw new IrCodecError("tuya-malformed", "not a base64 string");
53853
+ const out = [];
53854
+ let bits = 0;
53855
+ let acc = 0;
53856
+ for (const ch of clean) {
53857
+ const value = ALPHABET.indexOf(ch);
53858
+ if (value < 0) throw new IrCodecError("tuya-malformed", "not a base64 string");
53859
+ acc = acc << 6 | value;
53860
+ bits += 6;
53861
+ if (bits >= 8) {
53862
+ bits -= 8;
53863
+ out.push(acc >> bits & 255);
53864
+ }
53865
+ }
53866
+ return Uint8Array.from(out);
53867
+ }
53868
+ /** Signed pulse train to a Tuya IR code: base64(FastLZ(uint16 LE durations)). */
53869
+ function encodeTuya(timings) {
53870
+ const bytes = new Uint8Array(timings.length * 2);
53871
+ timings.forEach((value, index) => {
53872
+ const duration = Math.abs(value);
53873
+ if (duration === 0 || duration > MAX_DURATION_US) throw new IrCodecError("invalid-timings", `timing ${index} does not fit 16 bits`);
53874
+ bytes[index * 2] = duration & 255;
53875
+ bytes[index * 2 + 1] = duration >> 8;
53876
+ });
53877
+ return toBase64(fastlzCompress(bytes));
53878
+ }
53879
+ /** A Tuya IR code to a signed pulse train (mark first). Throws `IrCodecError`. */
53880
+ function decodeTuya(code) {
53881
+ const bytes = fastlzDecompress(fromBase64(code));
53882
+ if (bytes.length === 0 || bytes.length % 2 !== 0) throw new IrCodecError("tuya-malformed", "payload is not a list of 16-bit durations");
53883
+ const timings = [];
53884
+ for (let i = 0; i < bytes.length; i += 2) {
53885
+ const duration = (bytes[i] ?? 0) | (bytes[i + 1] ?? 0) << 8;
53886
+ timings.push(i / 2 % 2 === 0 ? duration : -duration);
53887
+ }
53888
+ const checked = IrTimingsSchema.safeParse(timings);
53889
+ if (!checked.success) throw new IrCodecError("tuya-malformed", checked.error.message);
53890
+ return checked.data;
53891
+ }
53892
+ /** Device-native IR code formats a transmitter can replay verbatim. */
53893
+ var IrNativeFormatSchema = zod.z.enum(["tuya"]);
53894
+ /**
53895
+ * Longest native code accepted: base64 of the worst-case compressed stream
53896
+ * (every decoded byte as a literal, plus one control byte per 32), with margin.
53897
+ */
53898
+ var IR_NATIVE_CODE_MAX_CHARS = Math.ceil((IR_DECOMPRESSED_MAX + Math.ceil(IR_DECOMPRESSED_MAX / 32)) / 3) * 4 + 256;
53899
+ var IrNativeCodeSchema = zod.z.object({
53900
+ format: IrNativeFormatSchema,
53901
+ code: zod.z.string().min(1).max(IR_NATIVE_CODE_MAX_CHARS)
53902
+ });
53903
+ var IR_NATIVE_CODECS = { tuya: {
53904
+ encode: encodeTuya,
53905
+ decode: decodeTuya
53906
+ } };
53907
+ /** What a remote command stores: a raw pulse train, a learned Pronto code, or a device-native code. */
53908
+ var IrPayloadSchema = zod.z.discriminatedUnion("kind", [
53909
+ zod.z.object({
53910
+ kind: zod.z.literal("raw"),
53911
+ timings: zod.z.array(zod.z.number().int()),
53912
+ settings: TransmitSettingsSchema.optional()
53913
+ }),
53914
+ zod.z.object({
53915
+ kind: zod.z.literal("pronto"),
53916
+ code: zod.z.string()
53917
+ }),
53918
+ zod.z.object({
53919
+ kind: zod.z.literal("native"),
53920
+ format: IrNativeFormatSchema,
53921
+ code: zod.z.string()
53922
+ })
53923
+ ]);
53748
53924
  /** Resolve a payload to what `ir-transmitter.send` takes. Throws `IrCodecError`. */
53749
53925
  function toTimings(payload) {
53750
53926
  if (payload.kind === "pronto") {
@@ -53754,6 +53930,10 @@ function toTimings(payload) {
53754
53930
  settings: { carrierHz: decoded.carrierHz }
53755
53931
  };
53756
53932
  }
53933
+ if (payload.kind === "native") return {
53934
+ timings: IR_NATIVE_CODECS[payload.format].decode(payload.code),
53935
+ settings: {}
53936
+ };
53757
53937
  const checked = IrTimingsSchema.safeParse(payload.timings);
53758
53938
  if (!checked.success) throw new IrCodecError("invalid-timings", checked.error.message);
53759
53939
  return {
@@ -68128,7 +68308,19 @@ var IrSendResultSchema = zod.z.object({
68128
68308
  var IrTransmitterInfoSchema = zod.z.object({
68129
68309
  media: zod.z.array(IrMediumSchema),
68130
68310
  settable: zod.z.array(TransmitSettingKeySchema),
68131
- maxTimings: zod.z.number().int().positive()
68311
+ maxTimings: zod.z.number().int().positive(),
68312
+ /** The transmitter can learn a code (`learn`). */
68313
+ learn: zod.z.boolean().default(false),
68314
+ /** Native code formats the transmitter replays verbatim (`send.native`). */
68315
+ formats: zod.z.array(IrNativeFormatSchema).default([])
68316
+ });
68317
+ var IR_LEARN_TIMEOUT_DEFAULT_MS = 2e4;
68318
+ var IR_LEARN_TIMEOUT_MAX_MS = 6e4;
68319
+ var IrLearnResultSchema = zod.z.object({
68320
+ /** The code in the device's own format, when it reports one. */
68321
+ native: IrNativeCodeSchema.nullable(),
68322
+ timings: IrTimingsSchema,
68323
+ carrierHz: zod.z.number().int().positive().nullable()
68132
68324
  });
68133
68325
  /**
68134
68326
  * ir-transmitter — emit a pulse train (infrared or RF) with settings. One cap
@@ -68139,7 +68331,12 @@ var IrTransmitterInfoSchema = zod.z.object({
68139
68331
  * transmitter cannot be reached) and `ir-transmitter.too-long` (more pulses
68140
68332
  * than the transmitter's `maxTimings`). A setting the transmitter cannot apply
68141
68333
  * is NOT a refusal: the train is sent and the key comes back in
68142
- * `ignoredSettings`.
68334
+ * `ignoredSettings`. `send` takes exactly one of `timings` or `native` (a code
68335
+ * in a format listed in `getInfo.formats`).
68336
+ *
68337
+ * `learn` waits for the user to point a remote at the transmitter and refuses
68338
+ * with `ir-transmitter.learn-unsupported`, `ir-transmitter.learn-timeout` or
68339
+ * `ir-transmitter.learn-undecodable`.
68143
68340
  */
68144
68341
  var irTransmitterCapability = {
68145
68342
  name: "ir-transmitter",
@@ -68150,9 +68347,17 @@ var irTransmitterCapability = {
68150
68347
  methods: {
68151
68348
  send: method(zod.z.object({
68152
68349
  deviceId: zod.z.number().int().nonnegative(),
68153
- timings: IrTimingsSchema,
68350
+ timings: IrTimingsSchema.optional(),
68351
+ native: IrNativeCodeSchema.optional(),
68154
68352
  settings: TransmitSettingsSchema.optional()
68155
- }), IrSendResultSchema, {
68353
+ }).refine((input) => input.timings === void 0 !== (input.native === void 0), { message: "send takes exactly one of timings or native" }), IrSendResultSchema, {
68354
+ kind: "mutation",
68355
+ auth: "protected"
68356
+ }),
68357
+ learn: method(zod.z.object({
68358
+ deviceId: zod.z.number().int().nonnegative(),
68359
+ timeoutMs: zod.z.number().int().positive().max(IR_LEARN_TIMEOUT_MAX_MS).default(IR_LEARN_TIMEOUT_DEFAULT_MS)
68360
+ }), IrLearnResultSchema, {
68156
68361
  kind: "mutation",
68157
68362
  auth: "protected"
68158
68363
  }),
@@ -108669,6 +108874,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
108669
108874
  access: "view",
108670
108875
  role: "viewer"
108671
108876
  },
108877
+ "irTransmitter.learn": {
108878
+ capName: "ir-transmitter",
108879
+ capScope: "device",
108880
+ addonId: null,
108881
+ access: "create",
108882
+ role: "viewer"
108883
+ },
108672
108884
  "irTransmitter.send": {
108673
108885
  capName: "ir-transmitter",
108674
108886
  capScope: "device",
@@ -116766,6 +116978,11 @@ Object.freeze({
116766
116978
  form: "single",
116767
116979
  optional: false
116768
116980
  }],
116981
+ "irTransmitter.learn": [{
116982
+ name: "deviceId",
116983
+ form: "single",
116984
+ optional: false
116985
+ }],
116769
116986
  "irTransmitter.send": [{
116770
116987
  name: "deviceId",
116771
116988
  form: "single",
@@ -1,5 +1,5 @@
1
1
  require("./chunk-Cek0wNdY.js");
2
- const require_wal_maintenance = require("./wal-maintenance-C4WfHqw5.js");
2
+ const require_wal_maintenance = require("./wal-maintenance-EJcAHbIL.js");
3
3
  let node_worker_threads = require("node:worker_threads");
4
4
  //#region src/builtins/sqlite-storage/file-host-worker.ts
5
5
  /**
@@ -1,4 +1,4 @@
1
- import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-DoZE1qG9.mjs";
1
+ import { A as callRecords, C as isFileHostWorkerData, D as RecordsEngine, M as controlTargetOf, O as callControl, S as isFileHostRequest, a as WalMaintenance, b as collectTransferables, d as callMigrate, f as migrateTargetOf, j as callVector, k as callData, l as SqliteSettingsBackend, o as createVectorIndex, s as vectorProviderOf, u as HUB_MIGRATIONS, v as serializeError, w as trustInput } from "./wal-maintenance-CyW12mpW.mjs";
2
2
  import { parentPort, threadId, workerData } from "node:worker_threads";
3
3
  //#region src/builtins/sqlite-storage/file-host-worker.ts
4
4
  /**
@@ -1,4 +1,4 @@
1
- import { Cc as defineRecordKinds } from "./dist-Btw-kJec.mjs";
1
+ import { Cc as defineRecordKinds } from "./dist-CUB8zpv-.mjs";
2
2
  import { C as backdatedNotBefore, S as withUtcTimeEncoding, _ as NameConstraints, a as KeyUsageFlags, c as Pkcs10CertificateRequest, d as SubjectKeyIdentifierExtension, f as X509Certificate$1, g as GeneralSubtrees, h as GeneralSubtree, i as Extension, l as Pkcs10CertificateRequestGenerator, m as cryptoProvider, n as BasicConstraintsExtension, o as KeyUsagesExtension, p as X509CertificateGenerator, r as ExtendedKeyUsageExtension, s as PemConverter, t as AuthorityKeyIdentifierExtension, u as SubjectAlternativeNameExtension, v as GeneralName, x as AsnConvert } from "./x509.es-BRiJgOvu.mjs";
3
3
  import { z } from "zod";
4
4
  import { X509Certificate, createHash, createPrivateKey, randomBytes, webcrypto } from "node:crypto";
@@ -1,5 +1,5 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-C2g-bkW3.js");
2
+ const require_dist = require("./dist-D9G24tL4.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
4
  let zod = require("zod");
5
5
  let node_crypto = require("node:crypto");
@@ -1,7 +1,7 @@
1
1
  const require_chunk = require("./chunk-Cek0wNdY.js");
2
- const require_dist = require("./dist-C2g-bkW3.js");
2
+ const require_dist = require("./dist-D9G24tL4.js");
3
3
  const require_x509_es = require("./x509.es-WtnRNyYS.js");
4
- const require_hub_identity = require("./hub-identity-DiXO_HL1.js");
4
+ const require_hub_identity = require("./hub-identity-D6Yzg92a.js");
5
5
  let node_crypto = require("node:crypto");
6
6
  let _camstack_types_node = require("@camstack/types/node");
7
7
  let node_fs = require("node:fs");