@camstack/server 1.2.932 → 1.2.933

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 (45) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/dist/api/trpc/generated-cap-routers.js +20 -0
  3. package/package.json +7 -7
  4. package/system/dist/addon-utils.mjs +1 -1
  5. package/system/dist/{base-device-IuM1AwXZ.mjs → base-device-Bwiblqmn.mjs} +1 -1
  6. package/system/dist/{base-device-2sL1DMm1.js → base-device-C1z4zYGR.js} +1 -1
  7. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +3 -3
  8. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +4 -4
  9. package/system/dist/builtins/alerts/alerts.addon.js +2 -2
  10. package/system/dist/builtins/alerts/alerts.addon.mjs +4 -4
  11. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +4 -4
  12. package/system/dist/builtins/camera-grid/index.js +2 -2
  13. package/system/dist/builtins/camera-grid/index.mjs +2 -2
  14. package/system/dist/builtins/composer/composer.addon.js +5 -5
  15. package/system/dist/builtins/composer/composer.addon.mjs +5 -5
  16. package/system/dist/builtins/core-blocks/cap-links.d.ts +34 -0
  17. package/system/dist/builtins/core-blocks/core-blocks.addon.d.ts +4 -0
  18. package/system/dist/builtins/core-blocks/core-blocks.addon.js +282 -8
  19. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +282 -8
  20. package/system/dist/builtins/device-manager/device-manager.addon.js +18 -4
  21. package/system/dist/builtins/device-manager/device-manager.addon.mjs +18 -4
  22. package/system/dist/builtins/local-auth/local-auth.addon.mjs +3 -3
  23. package/system/dist/builtins/local-network/local-network.addon.mjs +2 -2
  24. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +9 -9
  25. package/system/dist/builtins/platform-probe/index.mjs +9 -9
  26. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +19 -19
  27. package/system/dist/builtins/system-config/system-config.addon.mjs +113 -113
  28. package/system/dist/{composition-sources-BEUWn2s_.mjs → composition-sources-B0QW4g86.mjs} +2 -2
  29. package/system/dist/{composition-sources-acfR4hDq.js → composition-sources-BtUx1MfU.js} +2 -2
  30. package/system/dist/{coral-accelerators-zTMTEd-8.mjs → coral-accelerators-BKcXP59c.mjs} +6 -6
  31. package/system/dist/{core-blocks.cap-BRPsLAij.mjs → core-blocks.cap-CnwBuf7E.mjs} +1524 -1267
  32. package/system/dist/{core-blocks.cap-BMeMCBrx.js → core-blocks.cap-DlEuHq-S.js} +1555 -1268
  33. package/system/dist/{custom-action-registry-N7flBDwT.mjs → custom-action-registry-B9zFBNVa.mjs} +37 -37
  34. package/system/dist/{error.cap-CSM_SRfR.mjs → error.cap-5zNPAgU2.mjs} +19 -2
  35. package/system/dist/{error.cap-DBhgPeWK.js → error.cap-BCqzFlo2.js} +24 -1
  36. package/system/dist/{hub-identity-_IOgPJ00.mjs → hub-identity-DjMN9Ac2.mjs} +9 -9
  37. package/system/dist/{hub-mdns-ciao-Dk7ts_Uk.mjs → hub-mdns-ciao-DBrtHOcc.mjs} +1 -1
  38. package/system/dist/index.js +2 -2
  39. package/system/dist/index.mjs +214 -214
  40. package/system/dist/{prefix-walk-ifwg_ukx.mjs → prefix-walk-CRnbYJcC.mjs} +2 -2
  41. package/system/dist/{prefix-walk-BkMxoXpL.js → prefix-walk-DD1BM923.js} +2 -2
  42. package/system/dist/{rename-composition-block-BJsL58Ih.js → rename-composition-block-BRgyBO25.js} +20 -2
  43. package/system/dist/{rename-composition-block-OAtErZgq.mjs → rename-composition-block-BYRBlx-V.mjs} +20 -2
  44. package/system/dist/{restore-archive-kSFNjkWY.mjs → restore-archive-CjAyKpgX.mjs} +93 -93
  45. package/system/package.json +1 -1
@@ -7,7 +7,7 @@ const require_tag = require("./tag-BxLazvVb.js");
7
7
  const require_device_type = require("./device-type-CbQsnFdC.js");
8
8
  const require_device_kind = require("./device-kind-CsSiv_YF.js");
9
9
  const require_addon_settings_cap = require("./addon-settings.cap-DAiE0Nb0.js");
10
- const require_error_cap = require("./error.cap-DBhgPeWK.js");
10
+ const require_error_cap = require("./error.cap-BCqzFlo2.js");
11
11
  const require_source_info = require("./source-info-DtWf4k2j.js");
12
12
  const require_l10n = require("./l10n-CGMvp7NF.js");
13
13
  const require_raw_secret_migration = require("./raw-secret-migration-DxuBFtvi.js");
@@ -13101,7 +13101,11 @@ var CompositionProblemCodeSchema = /* @__PURE__ */ zod.z.enum([
13101
13101
  "command-input-unknown",
13102
13102
  "command-input-missing",
13103
13103
  "power-source-is-actuator",
13104
- "link-contribution-removed"
13104
+ "link-contribution-removed",
13105
+ "link-undeclared",
13106
+ "link-source-cap-missing",
13107
+ "link-native",
13108
+ "link-overlaps-fields"
13105
13109
  ]);
13106
13110
  /** One refusal, named (D391). `path` points into the composition, e.g. `features[0].fields.temperature`. */
13107
13111
  var CompositionProblemSchema = /* @__PURE__ */ zod.z.object({
@@ -13235,1081 +13239,64 @@ var CompositionBlockStateSchema = /* @__PURE__ */ zod.z.object({
13235
13239
  fields: /* @__PURE__ */ zod.z.array(CompositionFieldStateSchema)
13236
13240
  });
13237
13241
  //#endregion
13238
- //#region ../types/dist/esm/ir/ir-error.mjs
13239
- var IrCodecError = class extends Error {
13240
- code;
13241
- constructor(code, message) {
13242
- super(message);
13243
- this.name = "IrCodecError";
13244
- this.code = code;
13245
- }
13246
- };
13247
- //#endregion
13248
- //#region ../types/dist/esm/ir/ir-timings.mjs
13249
- /** Maximum number of mark/space entries one pulse train may carry. */
13250
- var IR_TIMINGS_MAX = 1024;
13251
- /**
13252
- * A pulse train in signed microseconds: mark (+) first, then space (-), strictly
13253
- * alternating, no zeros, 2..1024 entries.
13254
- */
13255
- var IrTimingsSchema = /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.number().int()).min(2).max(IR_TIMINGS_MAX).superRefine((timings, ctx) => {
13256
- timings.forEach((value, index) => {
13257
- const expectMark = index % 2 === 0;
13258
- if (value === 0 || value > 0 !== expectMark) ctx.addIssue({
13259
- code: "custom",
13260
- message: `timing ${index} must be a non-zero ${expectMark ? "mark (positive)" : "space (negative)"}`,
13261
- path: [index]
13262
- });
13263
- });
13264
- });
13265
- /** Per-command transmit options. Every key is optional; a transmitter applies what it can. */
13266
- var TransmitSettingsSchema = /* @__PURE__ */ zod.z.object({
13267
- carrierHz: /* @__PURE__ */ zod.z.number().int().positive().optional(),
13268
- dutyCyclePercent: /* @__PURE__ */ zod.z.number().int().min(1).max(100).optional(),
13269
- repeat: /* @__PURE__ */ zod.z.number().int().min(0).max(20).optional(),
13270
- repeatDelayMs: /* @__PURE__ */ zod.z.number().int().min(0).optional()
13271
- });
13272
- //#endregion
13273
- //#region ../types/dist/esm/ir/pronto.mjs
13274
- /** One Pronto frequency-word unit, in microseconds, per unit of the word. */
13275
- var PRONTO_CLOCK_US = .241246;
13276
- var LEARNED_FORM = 0;
13277
- /**
13278
- * Decode a learned (0000 form) Pronto hex string. The intro burst is followed by
13279
- * the repeat burst once; a different form is refused with `pronto-unsupported-form`.
13280
- */
13281
- function decodePronto(code) {
13282
- const words = code.trim().split(/\s+/).filter((w) => w.length > 0);
13283
- if (words.length < 4) throw new IrCodecError("pronto-malformed", `Pronto code needs at least 4 words, got ${words.length}`);
13284
- const values = words.map((w) => /^[0-9a-fA-F]{1,4}$/.test(w) ? parseInt(w, 16) : NaN);
13285
- if (values.some((v) => Number.isNaN(v))) throw new IrCodecError("pronto-malformed", "Pronto code must be 4-digit hexadecimal words");
13286
- const [form, freqWord, introCount, repeatCount] = values;
13287
- if (form === void 0 || freqWord === void 0 || introCount === void 0 || repeatCount === void 0) throw new IrCodecError("pronto-malformed", "Pronto header incomplete");
13288
- if (form !== LEARNED_FORM) throw new IrCodecError("pronto-unsupported-form", `Pronto form ${words[0] ?? ""} is not supported, only the learned 0000 form`);
13289
- if (freqWord === 0) throw new IrCodecError("pronto-malformed", "Pronto frequency word is zero");
13290
- const pairs = introCount + repeatCount;
13291
- if (pairs === 0 || values.length !== 4 + pairs * 2) throw new IrCodecError("pronto-malformed", `Pronto declares ${pairs} burst pairs but carries ${(values.length - 4) / 2} word pairs`);
13292
- const unitUs = freqWord * PRONTO_CLOCK_US;
13293
- const timings = values.slice(4).map((count, index) => {
13294
- const us = Math.max(1, Math.round(count * unitUs));
13295
- return index % 2 === 0 ? us : -us;
13296
- });
13297
- const checked = IrTimingsSchema.safeParse(timings);
13298
- if (!checked.success) throw new IrCodecError("invalid-timings", `Pronto decoded to invalid timings: ${checked.error.message}`);
13299
- return {
13300
- timings: checked.data,
13301
- carrierHz: Math.round(1e6 / unitUs)
13302
- };
13303
- }
13304
- //#endregion
13305
- //#region ../types/dist/esm/ir/fastlz.mjs
13306
- /**
13307
- * FastLZ level 1: a byte-oriented LZ77 stream. A control byte below 32 starts a
13308
- * literal run of `ctrl + 1` bytes; otherwise it is a back-reference whose length
13309
- * is `ctrl >> 5` (extended by one byte when 7) and whose distance is split
13310
- * between the low 5 bits and the next byte.
13311
- */
13312
- var MAX_DISTANCE = 8192;
13313
- var MAX_LITERAL_RUN = 32;
13314
- var MIN_MATCH = 3;
13315
- var MAX_MATCH = 264;
13242
+ //#region ../types/dist/esm/generated/customize-catalog.mjs
13316
13243
  /**
13317
- * Most bytes a decoded IR code may hold: two bytes per timing. A level-1 stream
13318
- * can expand ~130x, so the decoder checks this bound before every write.
13244
+ * Customize catalog, projected from every `*.cap.ts` `customize` block.
13245
+ * 15 caps. Field keys are `runtimeState` paths. No Zod.
13319
13246
  */
13320
- var IR_DECOMPRESSED_MAX = IR_TIMINGS_MAX * 2;
13321
- function fastlzDecompress(input) {
13322
- const out = [];
13323
- let ip = 0;
13324
- const room = (count) => {
13325
- if (out.length + count > IR_DECOMPRESSED_MAX) throw new IrCodecError("tuya-malformed", "decompressed code is larger than any IR train");
13326
- };
13327
- const next = () => {
13328
- const byte = input[ip++];
13329
- if (byte === void 0) throw new IrCodecError("tuya-malformed", "compressed stream is truncated");
13330
- return byte;
13331
- };
13332
- while (ip < input.length) {
13333
- const ctrl = next();
13334
- if (ctrl < 32) {
13335
- room(ctrl + 1);
13336
- for (let i = 0; i <= ctrl; i++) out.push(next());
13337
- continue;
13338
- }
13339
- let len = (ctrl >> 5) - 1;
13340
- if (len === 6) len += next();
13341
- const distance = ((ctrl & 31) << 8) + next() + 1;
13342
- const start = out.length - distance;
13343
- if (start < 0) throw new IrCodecError("tuya-malformed", "back-reference points before the stream");
13344
- room(len + 3);
13345
- for (let i = 0; i < len + 3; i++) {
13346
- const byte = out[start + i];
13347
- if (byte === void 0) throw new IrCodecError("tuya-malformed", "back-reference is invalid");
13348
- out.push(byte);
13349
- }
13350
- }
13351
- return Uint8Array.from(out);
13352
- }
13353
- function fastlzCompress(input) {
13354
- const out = [];
13355
- const lastSeen = /* @__PURE__ */ new Map();
13356
- let literalStart = 0;
13357
- const flushLiterals = (end) => {
13358
- for (let from = literalStart; from < end; from += MAX_LITERAL_RUN) {
13359
- const to = Math.min(from + MAX_LITERAL_RUN, end);
13360
- out.push(to - from - 1);
13361
- for (let i = from; i < to; i++) out.push(input[i] ?? 0);
13362
- }
13363
- };
13364
- let pos = 0;
13365
- while (pos < input.length) {
13366
- let matchLen = 0;
13367
- let matchDistance = 0;
13368
- if (pos + MIN_MATCH <= input.length) {
13369
- const key = (input[pos] ?? 0) << 16 | (input[pos + 1] ?? 0) << 8 | (input[pos + 2] ?? 0);
13370
- const candidate = lastSeen.get(key);
13371
- lastSeen.set(key, pos);
13372
- if (candidate !== void 0 && pos - candidate <= MAX_DISTANCE) {
13373
- let len = 0;
13374
- while (pos + len < input.length && len < MAX_MATCH && input[candidate + len] === input[pos + len]) len++;
13375
- if (len >= MIN_MATCH) {
13376
- matchLen = len;
13377
- matchDistance = pos - candidate - 1;
13378
- }
13379
- }
13380
- }
13381
- if (matchLen === 0) {
13382
- pos++;
13383
- continue;
13384
- }
13385
- flushLiterals(pos);
13386
- const enc = matchLen - 2;
13387
- if (enc < 7) out.push(enc << 5 | matchDistance >> 8);
13388
- else out.push(224 | matchDistance >> 8, enc - 7);
13389
- out.push(matchDistance & 255);
13390
- pos += matchLen;
13391
- literalStart = pos;
13392
- }
13393
- flushLiterals(input.length);
13394
- return Uint8Array.from(out);
13395
- }
13396
- //#endregion
13397
- //#region ../types/dist/esm/ir/tuya.mjs
13398
- var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
13399
- var MAX_DURATION_US = 65535;
13400
- function toBase64(bytes) {
13401
- let out = "";
13402
- for (let i = 0; i < bytes.length; i += 3) {
13403
- const a = bytes[i] ?? 0;
13404
- const b = bytes[i + 1] ?? 0;
13405
- const c = bytes[i + 2] ?? 0;
13406
- const word = a << 16 | b << 8 | c;
13407
- out += ALPHABET[word >> 18 & 63];
13408
- out += ALPHABET[word >> 12 & 63];
13409
- out += i + 1 < bytes.length ? ALPHABET[word >> 6 & 63] : "=";
13410
- out += i + 2 < bytes.length ? ALPHABET[word & 63] : "=";
13411
- }
13412
- return out;
13413
- }
13414
- function fromBase64(text) {
13415
- const clean = text.trim().replace(/=+$/, "");
13416
- if (clean.length === 0 || clean.length % 4 === 1) throw new IrCodecError("tuya-malformed", "not a base64 string");
13417
- const out = [];
13418
- let bits = 0;
13419
- let acc = 0;
13420
- for (const ch of clean) {
13421
- const value = ALPHABET.indexOf(ch);
13422
- if (value < 0) throw new IrCodecError("tuya-malformed", "not a base64 string");
13423
- acc = acc << 6 | value;
13424
- bits += 6;
13425
- if (bits >= 8) {
13426
- bits -= 8;
13427
- out.push(acc >> bits & 255);
13428
- }
13429
- }
13430
- return Uint8Array.from(out);
13431
- }
13432
- /** Signed pulse train to a Tuya IR code: base64(FastLZ(uint16 LE durations)). */
13433
- function encodeTuya(timings) {
13434
- const bytes = new Uint8Array(timings.length * 2);
13435
- timings.forEach((value, index) => {
13436
- const duration = Math.abs(value);
13437
- if (duration === 0 || duration > MAX_DURATION_US) throw new IrCodecError("invalid-timings", `timing ${index} does not fit 16 bits`);
13438
- bytes[index * 2] = duration & 255;
13439
- bytes[index * 2 + 1] = duration >> 8;
13440
- });
13441
- return toBase64(fastlzCompress(bytes));
13442
- }
13443
- /** A Tuya IR code to a signed pulse train (mark first). Throws `IrCodecError`. */
13444
- function decodeTuya(code) {
13445
- const bytes = fastlzDecompress(fromBase64(code));
13446
- if (bytes.length === 0 || bytes.length % 2 !== 0) throw new IrCodecError("tuya-malformed", "payload is not a list of 16-bit durations");
13447
- const timings = [];
13448
- for (let i = 0; i < bytes.length; i += 2) {
13449
- const duration = (bytes[i] ?? 0) | (bytes[i + 1] ?? 0) << 8;
13450
- timings.push(i / 2 % 2 === 0 ? duration : -duration);
13451
- }
13452
- const checked = IrTimingsSchema.safeParse(timings);
13453
- if (!checked.success) throw new IrCodecError("tuya-malformed", checked.error.message);
13454
- return checked.data;
13455
- }
13456
- //#endregion
13457
- //#region ../types/dist/esm/ir/native.mjs
13458
- /** Device-native IR code formats a transmitter can replay verbatim. */
13459
- var IrNativeFormatSchema = /* @__PURE__ */ zod.z.enum(["tuya"]);
13460
- /**
13461
- * Longest native code accepted: base64 of the worst-case compressed stream
13462
- * (every decoded byte as a literal, plus one control byte per 32), with margin.
13463
- */
13464
- var IR_NATIVE_CODE_MAX_CHARS = /* @__PURE__ */ Math.ceil((IR_DECOMPRESSED_MAX + /* @__PURE__ */ Math.ceil(IR_DECOMPRESSED_MAX / 32)) / 3) * 4 + 256;
13465
- var IrNativeCodeSchema = /* @__PURE__ */ zod.z.object({
13466
- format: IrNativeFormatSchema,
13467
- code: /* @__PURE__ */ zod.z.string().min(1).max(IR_NATIVE_CODE_MAX_CHARS)
13468
- });
13469
- var IR_NATIVE_CODECS = { tuya: {
13470
- encode: encodeTuya,
13471
- decode: decodeTuya
13472
- } };
13473
- //#endregion
13474
- //#region ../types/dist/esm/ir/ir-payload.mjs
13475
- /** What a remote command stores: a raw pulse train, a learned Pronto code, or a device-native code. */
13476
- var IrPayloadSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
13477
- /* @__PURE__ */ zod.z.object({
13478
- kind: /* @__PURE__ */ zod.z.literal("raw"),
13479
- timings: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.number().int()),
13480
- settings: /* @__PURE__ */ TransmitSettingsSchema.optional()
13481
- }),
13482
- /* @__PURE__ */ zod.z.object({
13483
- kind: /* @__PURE__ */ zod.z.literal("pronto"),
13484
- code: /* @__PURE__ */ zod.z.string()
13485
- }),
13486
- /* @__PURE__ */ zod.z.object({
13487
- kind: /* @__PURE__ */ zod.z.literal("native"),
13488
- format: IrNativeFormatSchema,
13489
- code: /* @__PURE__ */ zod.z.string()
13490
- })
13491
- ]);
13492
- /** Resolve a payload to what `ir-transmitter.send` takes. Throws `IrCodecError`. */
13493
- function toTimings(payload) {
13494
- if (payload.kind === "pronto") {
13495
- const decoded = decodePronto(payload.code);
13496
- return {
13497
- timings: decoded.timings,
13498
- settings: { carrierHz: decoded.carrierHz }
13499
- };
13500
- }
13501
- if (payload.kind === "native") return {
13502
- timings: IR_NATIVE_CODECS[payload.format].decode(payload.code),
13503
- settings: {}
13504
- };
13505
- const checked = IrTimingsSchema.safeParse(payload.timings);
13506
- if (!checked.success) throw new IrCodecError("invalid-timings", checked.error.message);
13507
- return {
13508
- timings: checked.data,
13509
- settings: payload.settings ?? {}
13510
- };
13511
- }
13512
- //#endregion
13513
- //#region ../types/dist/esm/remote/remote-roles.mjs
13514
- /**
13515
- * The role vocabulary of a remote (D963): what a button MEANS, independent of
13516
- * how it is wired. A layout template places buttons by role; a device binds a
13517
- * role to an action; an exporter asks for a role by name. Roles are shared so
13518
- * one layout fits every appliance and one voice command fits every binding.
13519
- *
13520
- * A role outside this list is `custom:<key>` — the operator's own button (a
13521
- * SmartIR source, a channel preset). The key is a lowercase slug.
13522
- */
13523
- var REMOTE_KNOWN_ROLES = [
13524
- "power",
13525
- "power_on",
13526
- "power_off",
13527
- "volume_up",
13528
- "volume_down",
13529
- "mute",
13530
- "channel_up",
13531
- "channel_down",
13532
- "up",
13533
- "down",
13534
- "left",
13535
- "right",
13536
- "ok",
13537
- "back",
13538
- "home",
13539
- "menu",
13540
- "info",
13541
- "guide",
13542
- "exit",
13543
- "input",
13544
- "play",
13545
- "pause",
13546
- "play_pause",
13547
- "stop",
13548
- "next",
13549
- "previous",
13550
- "fast_forward",
13551
- "rewind",
13552
- "digit_0",
13553
- "digit_1",
13554
- "digit_2",
13555
- "digit_3",
13556
- "digit_4",
13557
- "digit_5",
13558
- "digit_6",
13559
- "digit_7",
13560
- "digit_8",
13561
- "digit_9",
13562
- "source_select"
13563
- ];
13564
- /**
13565
- * Roles that are WIDGETS, not commands: a layout may place them, but they are
13566
- * never bound, never pressed through `sendCommand`, never a source step and
13567
- * never a media-player feature. `source_select` is the source picker key.
13568
- */
13569
- var REMOTE_WIDGET_ROLES = ["source_select"];
13570
- function isRemoteWidgetRole(role) {
13571
- return REMOTE_WIDGET_ROLES.includes(role);
13572
- }
13573
- var CUSTOM_KEY_RE = /^[a-z0-9][a-z0-9_]{0,47}$/;
13574
- var KNOWN_ROLES = /* @__PURE__ */ new Set(REMOTE_KNOWN_ROLES);
13575
- function isRemoteKnownRole(value) {
13576
- return KNOWN_ROLES.has(value);
13577
- }
13578
- function isRemoteCustomKey(key) {
13579
- return CUSTOM_KEY_RE.test(key);
13580
- }
13581
- /** The key of a `custom:<key>` role, or null for any other string. */
13582
- function customKeyOfRole(role) {
13583
- if (!role.startsWith("custom:")) return null;
13584
- const key = role.slice(7);
13585
- return isRemoteCustomKey(key) ? key : null;
13586
- }
13587
- function isRemoteRole(value) {
13588
- return isRemoteKnownRole(value) || customKeyOfRole(value) !== null;
13589
- }
13590
- var RemoteRoleSchema = /* @__PURE__ */ zod.z.string().refine(isRemoteRole, { message: "a role is one of the known roles or custom:<key> (lowercase letters, digits, _)" });
13591
- //#endregion
13592
- //#region ../types/dist/esm/remote/remote-sources.mjs
13593
- /**
13594
- * The sources of a remote (planning#460): what a media player's source list
13595
- * offers, ALWAYS declared by the operator — a button is never a source on its
13596
- * own. Two kinds:
13597
- *
13598
- * - `digits`: a name and a number ("Rai 1" = `1`, "Canale 24" = `25`). The
13599
- * steps are the number's `digit_N` roles, so the number is also the channel
13600
- * a voice command or `playMedia` names.
13601
- * - `sequence`: a name and explicit steps — bound roles pressed in order
13602
- * (an input key, a menu macro such as `source, down, down, ok`).
13603
- * - `ir`: a name and one infrared code of its own (raw timings or a Pronto
13604
- * string), sent through a named transmitter (planning#464). It presses no
13605
- * button: a source the remote's layout has no key for.
13606
- *
13607
- * The name and the number resolve to the SAME declared source. A number no
13608
- * `digits` source declares is not a channel: it is refused, never guessed.
13609
- */
13610
- var REMOTE_SOURCE_KINDS = [
13611
- "digits",
13612
- "sequence",
13613
- "ir"
13614
- ];
13615
- var REMOTE_SOURCE_ID_RE = /^[a-z0-9][a-z0-9_-]{0,47}$/;
13616
- var CHANNEL_NUMBER_RE = /* @__PURE__ */ new RegExp(`^[0-9]{1,6}$`);
13617
- var sourceBase = {
13618
- /** A lowercase slug, stable across renames. */
13619
- id: /* @__PURE__ */ zod.z.string().regex(REMOTE_SOURCE_ID_RE, { message: "a lowercase slug" }),
13620
- /** What the operator calls it, and what a voice command or a picker names. */
13621
- name: /* @__PURE__ */ zod.z.string().trim().min(1).max(60)
13622
- };
13623
- var RemoteDigitsSourceSchema = /* @__PURE__ */ zod.z.object({
13624
- ...sourceBase,
13625
- kind: /* @__PURE__ */ zod.z.literal("digits"),
13626
- number: /* @__PURE__ */ zod.z.string().regex(CHANNEL_NUMBER_RE, { message: "up to 6 digits" })
13627
- });
13628
- var RemoteSequenceSourceSchema = /* @__PURE__ */ zod.z.object({
13629
- ...sourceBase,
13630
- kind: /* @__PURE__ */ zod.z.literal("sequence"),
13631
- steps: /* @__PURE__ */ zod.z.array(RemoteRoleSchema).min(1).max(16)
13632
- });
13633
- var RemoteIrSourceSchema = /* @__PURE__ */ zod.z.object({
13634
- ...sourceBase,
13635
- kind: /* @__PURE__ */ zod.z.literal("ir"),
13636
- /**
13637
- * The `ir-transmitter` device the code is sent through. Absent = the remote's
13638
- * `defaultTransmitterId` at run time (a source stored before this field was
13639
- * optional keeps the emitter it names).
13640
- */
13641
- transmitterId: /* @__PURE__ */ zod.z.number().int().nonnegative().optional(),
13642
- /** The code itself; whether a transmitter could send it is `irSourceProblem`. */
13643
- payload: IrPayloadSchema
13644
- });
13645
- var RemoteSourceSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
13646
- RemoteDigitsSourceSchema,
13647
- RemoteSequenceSourceSchema,
13648
- RemoteIrSourceSchema
13649
- ]);
13650
- var REMOTE_STEP_DELAY_MAX_MS = 3e3;
13651
- /**
13652
- * The roles a source presses, in order. A `digits` number is its digit roles;
13653
- * an `ir` source presses none — it carries its own code.
13654
- */
13655
- function remoteSourceSteps(source) {
13656
- switch (source.kind) {
13657
- case "sequence": return source.steps;
13658
- case "digits": return Array.from(source.number, (digit) => `digit_${digit}`);
13659
- case "ir": return [];
13660
- }
13661
- }
13662
- /**
13663
- * Why an `ir` source's code could not be sent (the codec's own words), or null
13664
- * when it resolves to a pulse train. The schema refuses on it; the editor shows it.
13665
- */
13666
- function irSourceProblem(source) {
13667
- try {
13668
- toTimings(source.payload);
13669
- return null;
13670
- } catch (err) {
13671
- if (err instanceof IrCodecError) return err.message;
13672
- throw err;
13673
- }
13674
- }
13675
- function same(a, b) {
13676
- return a.trim().toLowerCase() === b.trim().toLowerCase();
13677
- }
13678
- /** The `digits` source that declares this channel number, or null. */
13679
- function findChannelSource(sources, number) {
13680
- const wanted = number.trim();
13681
- for (const source of sources) if (source.kind === "digits" && source.number === wanted) return source;
13682
- return null;
13683
- }
13684
- /**
13685
- * The declared source a name, an id or a channel number points at. The name and
13686
- * the number reach the same source; nothing else is guessed.
13687
- */
13688
- function resolveRemoteSource(sources, query) {
13689
- const byName = sources.find((source) => same(source.name, query));
13690
- if (byName !== void 0) return byName;
13691
- const byId = sources.find((source) => source.id === query.trim());
13692
- if (byId !== void 0) return byId;
13693
- return findChannelSource(sources, query);
13694
- }
13695
- //#endregion
13696
- //#region ../types/dist/esm/capabilities/media-player.cap.mjs
13697
- /**
13698
- * Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
13699
- * Apple TV, Spotify, Roku, generic OTT receivers, …) on
13700
- * `DeviceType.MediaPlayer`. Disjoint from the camera streaming
13701
- * surface — those use `DeviceType.Camera` + the broker pipeline.
13702
- *
13703
- * The cap declares a wide method surface; not every backend supports
13704
- * every method. Drivers signal sub-capability via the
13705
- * `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
13706
- * corresponding method) so the UI gates buttons without a slice
13707
- * fetch — same pattern as `PanTiltZoom` for cameras.
13708
- */
13709
- var MediaPlayerStateSchema = /* @__PURE__ */ zod.z.enum([
13710
- "off",
13711
- "on",
13712
- "idle",
13713
- "playing",
13714
- "paused",
13715
- "buffering",
13716
- "standby"
13717
- ]);
13718
- var MediaPlayerRepeatSchema = /* @__PURE__ */ zod.z.enum([
13719
- "off",
13720
- "all",
13721
- "one"
13722
- ]);
13723
- var MediaInfoSchema = /* @__PURE__ */ zod.z.object({
13724
- /** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
13725
- * `podcast`, …). */
13726
- type: /* @__PURE__ */ zod.z.string(),
13727
- /** Human-readable title. */
13728
- title: /* @__PURE__ */ zod.z.string(),
13729
- /** Optional artist / channel / station label. */
13730
- artist: /* @__PURE__ */ zod.z.string().optional(),
13731
- /** Optional album / season / show name. */
13732
- album: /* @__PURE__ */ zod.z.string().optional(),
13733
- /** Optional cover-art / thumbnail URL. */
13734
- imageUrl: /* @__PURE__ */ zod.z.string().optional()
13735
- });
13736
- /**
13737
- * Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
13738
- * the device said so. `assumed`: the driver has no feedback (infrared) and
13739
- * tracks what it last SENT; it moves only after a send was accepted, and a
13740
- * human at the real remote makes it wrong. A UI shows an assumed value as a
13741
- * guess, never as a reading.
13742
- */
13743
- var MediaPlayerStateSourceSchema = /* @__PURE__ */ zod.z.enum(["reported", "assumed"]);
13744
- /** The fields of a media-player status a driver can only guess. */
13745
- var MediaPlayerAssumedFieldSchema = /* @__PURE__ */ zod.z.enum([
13746
- "state",
13747
- "volumeLevel",
13748
- "isMuted",
13749
- "source"
13750
- ]);
13751
- var MediaPlayerStatusSchema = /* @__PURE__ */ zod.z.object({
13752
- /** Playback lifecycle state. */
13753
- state: MediaPlayerStateSchema,
13754
- /**
13755
- * Whether the state fields are readings or the driver's own bookkeeping.
13756
- * A slice written before this field existed parses as `reported`.
13757
- */
13758
- stateSource: /* @__PURE__ */ MediaPlayerStateSourceSchema.default("reported"),
13759
- /**
13760
- * Which fields are the driver's own guess. `stateSource` is `assumed` when
13761
- * this is not empty; a field not listed here is a reading even then (power
13762
- * from a running-state source, mute guessed from the last send).
13763
- */
13764
- assumedFields: /* @__PURE__ */ zod.z.array(MediaPlayerAssumedFieldSchema).default([]),
13765
- /** Volume as 0..100 inclusive. Null when the device has no volume
13766
- * surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
13767
- volumeLevel: /* @__PURE__ */ zod.z.number().min(0).max(100).nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("percentage")),
13768
- /** Mute toggle distinct from volume=0. Null when no mute surface.
13769
- * Pair with `DeviceFeature.MediaPlayerMute`. */
13770
- isMuted: /* @__PURE__ */ zod.z.boolean().nullable(),
13771
- /**
13772
- * True only when the provider READS the mute state back from the device.
13773
- * Absent or false: mute is a momentary key. A non-null `isMuted` is not a
13774
- * reading on its own — an infrared send can leave a value without this flag.
13775
- */
13776
- muteReadback: /* @__PURE__ */ zod.z.boolean().optional(),
13777
- /** Active source / input. Empty when no source surface. */
13778
- source: /* @__PURE__ */ zod.z.string(),
13779
- /** Selectable sources. Empty when no source surface.
13780
- * Pair with `DeviceFeature.MediaPlayerSelectSource`. */
13781
- availableSources: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string()),
13782
- /**
13783
- * What each declared source IS, when the sources are the operator's own (a
13784
- * remote, planning#460): an exporter offers a channel by number only for a
13785
- * `digits` source and an input only for a `sequence` one. Absent when the
13786
- * player's sources are its own.
13787
- */
13788
- declaredSources: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.object({
13789
- name: /* @__PURE__ */ zod.z.string(),
13790
- kind: /* @__PURE__ */ zod.z.enum(REMOTE_SOURCE_KINDS),
13791
- /** The channel number of a `digits` source. */
13792
- number: /* @__PURE__ */ zod.z.string().optional()
13793
- })).optional(),
13794
- /** Currently-playing media info. Null when nothing is playing. */
13795
- currentMedia: /* @__PURE__ */ MediaInfoSchema.nullable(),
13796
- /** Current playback position in ms. Null when not seekable or
13797
- * nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
13798
- position: /* @__PURE__ */ zod.z.number().int().nonnegative().nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("duration-ms")),
13799
- /** Total duration of the current media in ms. Null when unknown
13800
- * (live stream) or nothing is playing. */
13801
- duration: /* @__PURE__ */ zod.z.number().int().nonnegative().nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("duration-ms")),
13802
- /** Shuffle toggle. Null when no shuffle surface.
13803
- * Pair with `DeviceFeature.MediaPlayerShuffle`. */
13804
- shuffle: /* @__PURE__ */ zod.z.boolean().nullable(),
13805
- /** Repeat mode. Null when no repeat surface.
13806
- * Pair with `DeviceFeature.MediaPlayerRepeat`. */
13807
- repeat: /* @__PURE__ */ MediaPlayerRepeatSchema.nullable(),
13808
- /** Ms epoch when `position` was read from the device. Null when the driver
13809
- * does not say; a UI that advances the position while playing counts from it. */
13810
- positionUpdatedAt: /* @__PURE__ */ zod.z.number().nullable().default(null),
13811
- /** Ms epoch when the slice was last updated. */
13812
- lastChangedAt: /* @__PURE__ */ zod.z.number()
13813
- });
13814
- var stepInput = /* @__PURE__ */ zod.z.object({
13815
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
13816
- /** How many presses: the caller's count (Alexa `volumeSteps`, `channelCount`). */
13817
- steps: /* @__PURE__ */ zod.z.number().int().min(1).max(50).default(1)
13818
- });
13819
- var deviceOnly = /* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() });
13820
- var mediaPlayerCapability = {
13821
- name: "media-player",
13822
- scope: "device",
13823
- deviceNative: true,
13824
- mode: "singleton",
13825
- deviceTypes: [require_device_type.DeviceType.MediaPlayer],
13826
- power: {
13827
- kind: "methods",
13828
- field: "state",
13829
- offValues: ["off", "standby"],
13830
- on: "turnOn",
13831
- off: "turnOff"
13832
- },
13833
- methods: {
13834
- turnOn: /* @__PURE__ */ require_capability_definition.optionalMethod(deviceOnly, /* @__PURE__ */ zod.z.void(), {
13835
- kind: "mutation",
13836
- auth: "protected",
13837
- actions: [{
13838
- id: "media.turnOn",
13839
- label: /* @__PURE__ */ require_l10n.t("Turn on", "Accendi"),
13840
- phrase: /* @__PURE__ */ require_l10n.t("Turn on {device}", "Accendi {device}"),
13841
- icon: "power"
13842
- }]
13843
- }),
13844
- turnOff: /* @__PURE__ */ require_capability_definition.optionalMethod(deviceOnly, /* @__PURE__ */ zod.z.void(), {
13845
- kind: "mutation",
13846
- auth: "protected",
13847
- actions: [{
13848
- id: "media.turnOff",
13849
- label: /* @__PURE__ */ require_l10n.t("Turn off", "Spegni"),
13850
- phrase: /* @__PURE__ */ require_l10n.t("Turn off {device}", "Spegni {device}"),
13851
- icon: "power"
13852
- }]
13853
- }),
13854
- volumeUp: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
13855
- kind: "mutation",
13856
- auth: "protected",
13857
- actions: [{
13858
- id: "media.volumeUp",
13859
- label: /* @__PURE__ */ require_l10n.t("Volume up", "Alza il volume"),
13860
- phrase: /* @__PURE__ */ require_l10n.t("Raise the volume of {device}", "Alza il volume di {device}"),
13861
- icon: "volume-2"
13862
- }]
13863
- }),
13864
- volumeDown: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
13865
- kind: "mutation",
13866
- auth: "protected",
13867
- actions: [{
13868
- id: "media.volumeDown",
13869
- label: /* @__PURE__ */ require_l10n.t("Volume down", "Abbassa il volume"),
13870
- phrase: /* @__PURE__ */ require_l10n.t("Lower the volume of {device}", "Abbassa il volume di {device}"),
13871
- icon: "volume-2"
13872
- }]
13873
- }),
13874
- channelUp: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
13875
- kind: "mutation",
13876
- auth: "protected",
13877
- actions: [{
13878
- id: "media.channelUp",
13879
- label: /* @__PURE__ */ require_l10n.t("Channel up", "Canale successivo"),
13880
- phrase: /* @__PURE__ */ require_l10n.t("Go to the next channel on {device}", "Passa al canale successivo su {device}"),
13881
- icon: "skip-forward"
13882
- }]
13883
- }),
13884
- channelDown: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
13885
- kind: "mutation",
13886
- auth: "protected",
13887
- actions: [{
13888
- id: "media.channelDown",
13889
- label: /* @__PURE__ */ require_l10n.t("Channel down", "Canale precedente"),
13890
- phrase: /* @__PURE__ */ require_l10n.t("Go to the previous channel on {device}", "Torna al canale precedente su {device}"),
13891
- icon: "skip-back"
13892
- }]
13893
- }),
13894
- play: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
13895
- kind: "mutation",
13896
- auth: "protected",
13897
- actions: [{
13898
- id: "media.play",
13899
- effect: {
13900
- field: "state",
13901
- value: "playing"
13902
- },
13903
- label: /* @__PURE__ */ require_l10n.t("Play", "Riproduci"),
13904
- phrase: /* @__PURE__ */ require_l10n.t("Play on {device}", "Avvia la riproduzione su {device}"),
13905
- icon: "play"
13906
- }]
13907
- }),
13908
- pause: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
13909
- kind: "mutation",
13910
- auth: "protected",
13911
- actions: [{
13912
- id: "media.pause",
13913
- effect: {
13914
- field: "state",
13915
- value: "paused"
13916
- },
13917
- label: /* @__PURE__ */ require_l10n.t("Pause media", "Metti in pausa"),
13918
- phrase: /* @__PURE__ */ require_l10n.t("Pause {device}", "Metti in pausa {device}"),
13919
- icon: "pause"
13920
- }]
13921
- }),
13922
- stop: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
13923
- kind: "mutation",
13924
- auth: "protected",
13925
- actions: [{
13926
- id: "media.stop",
13927
- label: /* @__PURE__ */ require_l10n.t("Stop media", "Ferma la riproduzione"),
13928
- phrase: /* @__PURE__ */ require_l10n.t("Stop {device}", "Ferma {device}"),
13929
- icon: "square"
13930
- }]
13931
- }),
13932
- next: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
13933
- kind: "mutation",
13934
- auth: "protected",
13935
- actions: [{
13936
- id: "media.next",
13937
- label: /* @__PURE__ */ require_l10n.t("Next track", "Brano successivo"),
13938
- phrase: /* @__PURE__ */ require_l10n.t("Skip to the next track on {device}", "Passa al brano successivo su {device}"),
13939
- icon: "skip-forward"
13940
- }]
13941
- }),
13942
- previous: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
13943
- kind: "mutation",
13944
- auth: "protected",
13945
- actions: [{
13946
- id: "media.previous",
13947
- label: /* @__PURE__ */ require_l10n.t("Previous track", "Brano precedente"),
13948
- phrase: /* @__PURE__ */ require_l10n.t("Go back to the previous track on {device}", "Torna al brano precedente su {device}"),
13949
- icon: "skip-back"
13950
- }]
13951
- }),
13952
- setVolume: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
13953
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
13954
- volumeLevel: /* @__PURE__ */ zod.z.number().min(0).max(100)
13955
- }), /* @__PURE__ */ zod.z.void(), {
13956
- kind: "mutation",
13957
- auth: "protected",
13958
- actions: [{
13959
- id: "media.volume",
13960
- effect: {
13961
- field: "volumeLevel",
13962
- fromArg: "volumeLevel"
13963
- },
13964
- label: /* @__PURE__ */ require_l10n.t("Set volume", "Imposta il volume"),
13965
- phrase: /* @__PURE__ */ require_l10n.t("Set the volume of {device} to {volumeLevel}", "Imposta il volume di {device} al {volumeLevel}"),
13966
- icon: "volume-2",
13967
- openArgs: [{
13968
- key: "volumeLevel",
13969
- label: /* @__PURE__ */ require_l10n.t("Volume", "Volume"),
13970
- offer: {
13971
- kind: "number",
13972
- min: 0,
13973
- max: 100,
13974
- step: 1,
13975
- unit: "%"
13976
- }
13977
- }]
13978
- }]
13979
- }),
13980
- setMute: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
13981
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
13982
- muted: /* @__PURE__ */ zod.z.boolean()
13983
- }), /* @__PURE__ */ zod.z.void(), {
13984
- kind: "mutation",
13985
- auth: "protected",
13986
- actions: [{
13987
- id: "media.mute",
13988
- effect: {
13989
- field: "isMuted",
13990
- value: true
13991
- },
13992
- label: /* @__PURE__ */ require_l10n.t("Mute", "Silenzia"),
13993
- phrase: /* @__PURE__ */ require_l10n.t("Mute {device}", "Silenzia {device}"),
13994
- icon: "volume-x",
13995
- args: { muted: true }
13996
- }, {
13997
- id: "media.unmute",
13998
- effect: {
13999
- field: "isMuted",
14000
- value: false
14001
- },
14002
- label: /* @__PURE__ */ require_l10n.t("Unmute", "Riattiva l’audio"),
14003
- phrase: /* @__PURE__ */ require_l10n.t("Unmute {device}", "Riattiva l’audio di {device}"),
14004
- icon: "volume-2",
14005
- args: { muted: false }
14006
- }]
14007
- }),
14008
- setShuffle: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
14009
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
14010
- shuffle: /* @__PURE__ */ zod.z.boolean()
14011
- }), /* @__PURE__ */ zod.z.void(), {
14012
- kind: "mutation",
14013
- auth: "protected",
14014
- actions: [{
14015
- id: "media.shuffleOn",
14016
- effect: {
14017
- field: "shuffle",
14018
- value: true
14019
- },
14020
- label: /* @__PURE__ */ require_l10n.t("Shuffle on", "Riproduzione casuale attiva"),
14021
- phrase: /* @__PURE__ */ require_l10n.t("Turn on shuffle on {device}", "Attiva la riproduzione casuale su {device}"),
14022
- icon: "shuffle",
14023
- args: { shuffle: true }
14024
- }, {
14025
- id: "media.shuffleOff",
14026
- effect: {
14027
- field: "shuffle",
14028
- value: false
14029
- },
14030
- label: /* @__PURE__ */ require_l10n.t("Shuffle off", "Riproduzione casuale spenta"),
14031
- phrase: /* @__PURE__ */ require_l10n.t("Turn off shuffle on {device}", "Disattiva la riproduzione casuale su {device}"),
14032
- icon: "shuffle",
14033
- args: { shuffle: false }
14034
- }]
14035
- }),
14036
- setRepeat: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
14037
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
14038
- repeat: MediaPlayerRepeatSchema
14039
- }), /* @__PURE__ */ zod.z.void(), {
14040
- kind: "mutation",
14041
- auth: "protected",
14042
- actions: [{
14043
- id: "media.repeat",
14044
- effect: {
14045
- field: "repeat",
14046
- fromArg: "repeat"
14047
- },
14048
- label: /* @__PURE__ */ require_l10n.t("Set repeat", "Imposta la ripetizione"),
14049
- phrase: /* @__PURE__ */ require_l10n.t("Set repeat on {device} to {repeat}", "Imposta la ripetizione di {device} su {repeat}"),
14050
- icon: "repeat",
14051
- openArgs: [{
14052
- key: "repeat",
14053
- label: /* @__PURE__ */ require_l10n.t("Repeat", "Ripetizione"),
14054
- offer: {
14055
- kind: "enum",
14056
- values: [
14057
- {
14058
- value: "off",
14059
- label: /* @__PURE__ */ require_l10n.t("Off", "Disattivata")
14060
- },
14061
- {
14062
- value: "all",
14063
- label: /* @__PURE__ */ require_l10n.t("All", "Tutti i brani")
14064
- },
14065
- {
14066
- value: "one",
14067
- label: /* @__PURE__ */ require_l10n.t("One track", "Un brano")
14068
- }
14069
- ]
14070
- }
14071
- }]
14072
- }]
14073
- }),
14074
- selectSource: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
14075
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
14076
- source: /* @__PURE__ */ zod.z.string().min(1)
14077
- }), /* @__PURE__ */ zod.z.void(), {
14078
- kind: "mutation",
14079
- auth: "protected",
14080
- actions: [{
14081
- id: "media.source",
14082
- effect: {
14083
- field: "source",
14084
- fromArg: "source"
14085
- },
14086
- label: /* @__PURE__ */ require_l10n.t("Select source", "Scegli la sorgente"),
14087
- phrase: /* @__PURE__ */ require_l10n.t("Switch {device} to {source}", "Passa {device} alla sorgente {source}"),
14088
- icon: "cast",
14089
- openArgs: [{
14090
- key: "source",
14091
- label: /* @__PURE__ */ require_l10n.t("Source", "Sorgente"),
14092
- offer: {
14093
- kind: "dynamic",
14094
- from: "status",
14095
- field: "availableSources"
14096
- }
14097
- }]
14098
- }]
14099
- }),
14100
- seek: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
14101
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
14102
- position: /* @__PURE__ */ zod.z.number().int().nonnegative()
14103
- }), /* @__PURE__ */ zod.z.void(), {
14104
- kind: "mutation",
14105
- auth: "protected",
14106
- actions: [{
14107
- id: "media.seek",
14108
- label: /* @__PURE__ */ require_l10n.t("Seek", "Vai al punto"),
14109
- phrase: /* @__PURE__ */ require_l10n.t("Move {device} to {position}", "Porta {device} al punto {position}"),
14110
- icon: "fast-forward",
14111
- openArgs: [{
14112
- key: "position",
14113
- label: /* @__PURE__ */ require_l10n.t("Position", "Posizione"),
14114
- offer: {
14115
- kind: "number",
14116
- min: 0,
14117
- step: 1e3,
14118
- unit: "ms"
14119
- }
14120
- }]
14121
- }]
14122
- }),
14123
- playMedia: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
14124
- deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
14125
- /** Media identifier / URL. */
14126
- mediaId: /* @__PURE__ */ zod.z.string().min(1),
14127
- /** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
14128
- * passes it through to the upstream service. */
14129
- mediaType: /* @__PURE__ */ zod.z.string().min(1)
14130
- }), /* @__PURE__ */ zod.z.void(), {
14131
- kind: "mutation",
14132
- auth: "protected",
14133
- actions: [{
14134
- id: "media.playMedia",
14135
- label: /* @__PURE__ */ require_l10n.t("Play media", "Riproduci un contenuto"),
14136
- phrase: /* @__PURE__ */ require_l10n.t("Play {mediaId} on {device}", "Riproduci {mediaId} su {device}"),
14137
- icon: "music",
14138
- openArgs: [{
14139
- key: "mediaId",
14140
- label: /* @__PURE__ */ require_l10n.t("Media", "Contenuto"),
14141
- offer: { kind: "text" }
14142
- }, {
14143
- key: "mediaType",
14144
- label: /* @__PURE__ */ require_l10n.t("Media type", "Tipo di contenuto"),
14145
- offer: { kind: "text" }
14146
- }]
14147
- }]
14148
- })
14149
- },
14150
- status: {
14151
- schema: MediaPlayerStatusSchema,
14152
- kind: "push"
14153
- },
14154
- /**
14155
- * Runtime-state slice — mirrored by the kernel. UI players read the
14156
- * full slice for live now-playing, volume, and progress updates
14157
- * without polling.
14158
- */
14159
- runtimeState: MediaPlayerStatusSchema,
14160
- /**
14161
- * Runtime-state durability: **session** — a restored transport position describes a playback that stopped when the hub did.
14162
- *
14163
- * See `RuntimeStateDurability`. Enforced by
14164
- * `scripts/check-runtime-state-durability.ts`.
14165
- */
14166
- durability: "session",
14167
- /**
14168
- * History (D850): volume (a level an operator or an automation sets; the
14169
- * default 10 s floor folds a slider drag into its end value) and mute.
14170
- * `position` is not recorded: it moves continuously while playing.
14171
- */
14172
- history: { fields: {
14173
- volumeLevel: {
14174
- kind: "gauge",
14175
- unit: "%",
14176
- deadband: 1
14177
- },
14178
- isMuted: { kind: "boolean" }
14179
- } },
14180
- vocabulary: {
14181
- noun: /* @__PURE__ */ require_l10n.t("Media player", "Lettore multimediale"),
14182
- order: 2060,
14183
- state: [
14184
- {
14185
- kind: "enum",
14186
- field: "state",
14187
- label: /* @__PURE__ */ require_l10n.t("Playback", "Riproduzione"),
14188
- values: [
14189
- {
14190
- value: "off",
14191
- label: /* @__PURE__ */ require_l10n.t("Off", "Spento"),
14192
- phrase: /* @__PURE__ */ require_l10n.t("When {device} turns off", "Quando {device} si spegne")
14193
- },
14194
- {
14195
- value: "on",
14196
- label: /* @__PURE__ */ require_l10n.t("On", "Acceso"),
14197
- phrase: /* @__PURE__ */ require_l10n.t("When {device} turns on", "Quando {device} si accende")
14198
- },
14199
- {
14200
- value: "idle",
14201
- label: /* @__PURE__ */ require_l10n.t("Idle", "Inattivo")
14202
- },
14203
- {
14204
- value: "playing",
14205
- label: /* @__PURE__ */ require_l10n.t("Playing", "In riproduzione"),
14206
- phrase: /* @__PURE__ */ require_l10n.t("When {device} starts playing", "Quando {device} inizia a riprodurre")
14207
- },
14208
- {
14209
- value: "paused",
14210
- label: /* @__PURE__ */ require_l10n.t("Paused", "In pausa"),
14211
- phrase: /* @__PURE__ */ require_l10n.t("When {device} is paused", "Quando {device} va in pausa")
14212
- },
14213
- {
14214
- value: "buffering",
14215
- label: /* @__PURE__ */ require_l10n.t("Buffering", "In caricamento")
14216
- },
14217
- {
14218
- value: "standby",
14219
- label: /* @__PURE__ */ require_l10n.t("Standby", "In standby")
14220
- }
14221
- ],
14222
- icon: "music"
14223
- },
14224
- {
14225
- kind: "numeric",
14226
- field: "volumeLevel",
14227
- quantity: /* @__PURE__ */ require_l10n.t("the volume", "il volume"),
14228
- label: /* @__PURE__ */ require_l10n.t("Volume", "Volume"),
14229
- unit: "%",
14230
- icon: "volume-2"
14231
- },
14232
- {
14233
- kind: "boolean",
14234
- field: "isMuted",
14235
- label: /* @__PURE__ */ require_l10n.t("Muted", "Silenziato"),
14236
- whenTrue: /* @__PURE__ */ require_l10n.t("When {device} is muted", "Quando {device} viene silenziato"),
14237
- whenFalse: /* @__PURE__ */ require_l10n.t("When {device} is unmuted", "Quando l’audio di {device} torna attivo"),
14238
- icon: "volume-x"
14239
- },
14240
- {
14241
- kind: "value",
14242
- field: "source",
14243
- label: /* @__PURE__ */ require_l10n.t("Source", "Sorgente"),
14244
- offer: {
14245
- kind: "dynamic",
14246
- from: "status",
14247
- field: "availableSources"
14248
- },
14249
- icon: "cast"
14250
- }
14251
- ]
14252
- }
14253
- };
14254
- //#endregion
14255
- //#region ../types/dist/esm/generated/customize-catalog.mjs
14256
- /**
14257
- * Customize catalog, projected from every `*.cap.ts` `customize` block.
14258
- * 14 caps. Field keys are `runtimeState` paths. No Zod.
14259
- */
14260
- var CAP_CUSTOMIZE_CATALOG = {
14261
- "battery": {
14262
- version: 1,
14263
- targets: [{
14264
- id: "level",
14265
- cardinality: "scalar",
14266
- deviceTypes: [
14267
- require_device_type.DeviceType.Camera,
14268
- require_device_type.DeviceType.Sensor,
14269
- require_device_type.DeviceType.Button,
14270
- require_device_type.DeviceType.Switch,
14271
- require_device_type.DeviceType.PetFeeder,
14272
- require_device_type.DeviceType.Container,
14273
- require_device_type.DeviceType.Climate,
14274
- require_device_type.DeviceType.EventEmitter
14275
- ],
14276
- apply: "add",
14277
- vocabularyCap: "battery",
14278
- vocabularyStateField: "level",
14279
- sources: [{
14280
- kind: "field",
14281
- valueKinds: ["number", "string"],
14282
- transformKinds: ["identity", "linear"],
14283
- transforms: [{ kind: "identity" }, {
14284
- kind: "linear",
14285
- defaultScale: 1,
14286
- defaultOffset: 0,
14287
- clampMin: 0,
14288
- clampMax: 100
14289
- }]
14290
- }],
14291
- sourceReport: { status: "assignment-status" },
14292
- advancedExpression: true,
14293
- path: "level",
14294
- valueKind: "number",
14295
- nullable: true,
14296
- companions: [
14297
- {
14298
- kind: "constant",
14299
- path: "charging",
14300
- value: "unknown",
14301
- when: "add"
14302
- },
14303
- {
14304
- kind: "constant",
14305
- path: "sleeping",
14306
- value: false,
14307
- when: "add"
14308
- },
14309
- {
14310
- kind: "clock",
14311
- path: "lastUpdated",
14312
- when: "add"
13247
+ var CAP_CUSTOMIZE_CATALOG = {
13248
+ "battery": {
13249
+ version: 1,
13250
+ targets: [{
13251
+ id: "level",
13252
+ cardinality: "scalar",
13253
+ deviceTypes: [
13254
+ require_device_type.DeviceType.Camera,
13255
+ require_device_type.DeviceType.Sensor,
13256
+ require_device_type.DeviceType.Button,
13257
+ require_device_type.DeviceType.Switch,
13258
+ require_device_type.DeviceType.PetFeeder,
13259
+ require_device_type.DeviceType.Container,
13260
+ require_device_type.DeviceType.Climate,
13261
+ require_device_type.DeviceType.EventEmitter
13262
+ ],
13263
+ apply: "add",
13264
+ vocabularyCap: "battery",
13265
+ vocabularyStateField: "level",
13266
+ sources: [{
13267
+ kind: "field",
13268
+ valueKinds: ["number", "string"],
13269
+ transformKinds: ["identity", "linear"],
13270
+ transforms: [{ kind: "identity" }, {
13271
+ kind: "linear",
13272
+ defaultScale: 1,
13273
+ defaultOffset: 0,
13274
+ clampMin: 0,
13275
+ clampMax: 100
13276
+ }]
13277
+ }],
13278
+ sourceReport: { status: "assignment-status" },
13279
+ advancedExpression: true,
13280
+ path: "level",
13281
+ valueKind: "number",
13282
+ nullable: true,
13283
+ companions: [
13284
+ {
13285
+ kind: "constant",
13286
+ path: "charging",
13287
+ value: "unknown",
13288
+ when: "add"
13289
+ },
13290
+ {
13291
+ kind: "constant",
13292
+ path: "sleeping",
13293
+ value: false,
13294
+ when: "add"
13295
+ },
13296
+ {
13297
+ kind: "clock",
13298
+ path: "lastUpdated",
13299
+ when: "add"
14313
13300
  }
14314
13301
  ]
14315
13302
  }]
@@ -14533,6 +13520,17 @@ var CAP_CUSTOMIZE_CATALOG = {
14533
13520
  debounceMs: 2e3
14534
13521
  }]
14535
13522
  },
13523
+ "energy-system": {
13524
+ version: 1,
13525
+ targets: [],
13526
+ links: [{
13527
+ id: "heat-pump",
13528
+ sourceCap: "heat-pump-status",
13529
+ mode: "reference",
13530
+ slot: "heatPump",
13531
+ apply: "add"
13532
+ }]
13533
+ },
14536
13534
  "fan-control": {
14537
13535
  version: 1,
14538
13536
  targets: [
@@ -15076,6 +14074,28 @@ var CAP_CUSTOMIZE_CATALOG = {
15076
14074
  "voltage",
15077
14075
  "current"
15078
14076
  ]
14077
+ }],
14078
+ links: [{
14079
+ id: "meter-device",
14080
+ sourceCap: "power-meter",
14081
+ mode: "project",
14082
+ apply: "add",
14083
+ deviceTypes: [
14084
+ require_device_type.DeviceType.Switch,
14085
+ require_device_type.DeviceType.Light,
14086
+ require_device_type.DeviceType.Fan,
14087
+ require_device_type.DeviceType.Climate,
14088
+ require_device_type.DeviceType.Humidifier,
14089
+ require_device_type.DeviceType.WaterHeater,
14090
+ require_device_type.DeviceType.MediaPlayer,
14091
+ require_device_type.DeviceType.Washer,
14092
+ require_device_type.DeviceType.Dryer,
14093
+ require_device_type.DeviceType.Dishwasher,
14094
+ require_device_type.DeviceType.Vacuum,
14095
+ require_device_type.DeviceType.LawnMower,
14096
+ require_device_type.DeviceType.PetFeeder,
14097
+ require_device_type.DeviceType.Workload
14098
+ ]
15079
14099
  }]
15080
14100
  },
15081
14101
  "power-source": {
@@ -15097,7 +14117,9 @@ var CAP_CUSTOMIZE_CATALOG = {
15097
14117
  require_device_type.DeviceType.Fan,
15098
14118
  require_device_type.DeviceType.Humidifier,
15099
14119
  require_device_type.DeviceType.Climate,
15100
- require_device_type.DeviceType.WaterHeater
14120
+ require_device_type.DeviceType.WaterHeater,
14121
+ require_device_type.DeviceType.Light,
14122
+ require_device_type.DeviceType.Switch
15101
14123
  ],
15102
14124
  apply: "add",
15103
14125
  vocabularyCap: "power-source",
@@ -15617,209 +14639,1352 @@ var CAP_CUSTOMIZE_CATALOG = {
15617
14639
  path: "lastFetchedAt",
15618
14640
  when: "add"
15619
14641
  }]
15620
- },
15621
- {
15622
- id: "rain24h",
15623
- cardinality: "scalar",
15624
- deviceTypes: [require_device_type.DeviceType.WeatherStation],
15625
- apply: "add",
15626
- vocabularyCap: "weather-station",
15627
- vocabularyStateField: "rain24h",
15628
- sources: [{
15629
- kind: "numeric",
15630
- requiredUnit: "mm",
15631
- transformKinds: ["identity"],
15632
- transforms: [{ kind: "identity" }]
15633
- }],
15634
- sourceReport: { status: "assignment-status" },
15635
- advancedExpression: false,
15636
- path: "rain24h",
15637
- valueKind: "number",
15638
- nullable: true,
15639
- companions: [{
15640
- kind: "clock",
15641
- path: "lastFetchedAt",
15642
- when: "add"
14642
+ },
14643
+ {
14644
+ id: "rain24h",
14645
+ cardinality: "scalar",
14646
+ deviceTypes: [require_device_type.DeviceType.WeatherStation],
14647
+ apply: "add",
14648
+ vocabularyCap: "weather-station",
14649
+ vocabularyStateField: "rain24h",
14650
+ sources: [{
14651
+ kind: "numeric",
14652
+ requiredUnit: "mm",
14653
+ transformKinds: ["identity"],
14654
+ transforms: [{ kind: "identity" }]
14655
+ }],
14656
+ sourceReport: { status: "assignment-status" },
14657
+ advancedExpression: false,
14658
+ path: "rain24h",
14659
+ valueKind: "number",
14660
+ nullable: true,
14661
+ companions: [{
14662
+ kind: "clock",
14663
+ path: "lastFetchedAt",
14664
+ when: "add"
14665
+ }]
14666
+ },
14667
+ {
14668
+ id: "rainWeekly",
14669
+ cardinality: "scalar",
14670
+ deviceTypes: [require_device_type.DeviceType.WeatherStation],
14671
+ apply: "add",
14672
+ vocabularyCap: "weather-station",
14673
+ vocabularyStateField: "rainWeekly",
14674
+ sources: [{
14675
+ kind: "numeric",
14676
+ requiredUnit: "mm",
14677
+ transformKinds: ["identity"],
14678
+ transforms: [{ kind: "identity" }]
14679
+ }],
14680
+ sourceReport: { status: "assignment-status" },
14681
+ advancedExpression: false,
14682
+ path: "rainWeekly",
14683
+ valueKind: "number",
14684
+ nullable: true,
14685
+ companions: [{
14686
+ kind: "clock",
14687
+ path: "lastFetchedAt",
14688
+ when: "add"
14689
+ }]
14690
+ },
14691
+ {
14692
+ id: "rainMonthly",
14693
+ cardinality: "scalar",
14694
+ deviceTypes: [require_device_type.DeviceType.WeatherStation],
14695
+ apply: "add",
14696
+ vocabularyCap: "weather-station",
14697
+ vocabularyStateField: "rainMonthly",
14698
+ sources: [{
14699
+ kind: "numeric",
14700
+ requiredUnit: "mm",
14701
+ transformKinds: ["identity"],
14702
+ transforms: [{ kind: "identity" }]
14703
+ }],
14704
+ sourceReport: { status: "assignment-status" },
14705
+ advancedExpression: false,
14706
+ path: "rainMonthly",
14707
+ valueKind: "number",
14708
+ nullable: true,
14709
+ companions: [{
14710
+ kind: "clock",
14711
+ path: "lastFetchedAt",
14712
+ when: "add"
14713
+ }]
14714
+ },
14715
+ {
14716
+ id: "rainYearly",
14717
+ cardinality: "scalar",
14718
+ deviceTypes: [require_device_type.DeviceType.WeatherStation],
14719
+ apply: "add",
14720
+ vocabularyCap: "weather-station",
14721
+ vocabularyStateField: "rainYearly",
14722
+ sources: [{
14723
+ kind: "numeric",
14724
+ requiredUnit: "mm",
14725
+ transformKinds: ["identity"],
14726
+ transforms: [{ kind: "identity" }]
14727
+ }],
14728
+ sourceReport: { status: "assignment-status" },
14729
+ advancedExpression: false,
14730
+ path: "rainYearly",
14731
+ valueKind: "number",
14732
+ nullable: true,
14733
+ companions: [{
14734
+ kind: "clock",
14735
+ path: "lastFetchedAt",
14736
+ when: "add"
14737
+ }]
14738
+ }
14739
+ ],
14740
+ overridable: [
14741
+ {
14742
+ path: "temperature",
14743
+ by: "temperature"
14744
+ },
14745
+ {
14746
+ path: "humidity",
14747
+ by: "humidity"
14748
+ },
14749
+ {
14750
+ path: "pressure",
14751
+ by: "pressure"
14752
+ },
14753
+ {
14754
+ path: "windSpeed",
14755
+ by: "windSpeed"
14756
+ },
14757
+ {
14758
+ path: "windGust",
14759
+ by: "windGust"
14760
+ },
14761
+ {
14762
+ path: "windBearing",
14763
+ by: "windBearing"
14764
+ },
14765
+ {
14766
+ path: "rainRate",
14767
+ by: "rainRate"
14768
+ },
14769
+ {
14770
+ path: "rainDaily",
14771
+ by: "rainDaily"
14772
+ },
14773
+ {
14774
+ path: "rainEvent",
14775
+ by: "rainEvent"
14776
+ },
14777
+ {
14778
+ path: "uv",
14779
+ by: "uv"
14780
+ },
14781
+ {
14782
+ path: "solarRadiation",
14783
+ by: "solarRadiation"
14784
+ },
14785
+ {
14786
+ path: "dewPoint",
14787
+ by: "dewPoint"
14788
+ },
14789
+ {
14790
+ path: "feelsLike",
14791
+ by: "feelsLike"
14792
+ },
14793
+ {
14794
+ path: "vpd",
14795
+ by: "vpd"
14796
+ },
14797
+ {
14798
+ path: "windGustMax",
14799
+ by: "windGustMax"
14800
+ },
14801
+ {
14802
+ path: "windBearingAvg",
14803
+ by: "windBearingAvg"
14804
+ },
14805
+ {
14806
+ path: "rain24h",
14807
+ by: "rain24h"
14808
+ },
14809
+ {
14810
+ path: "rainWeekly",
14811
+ by: "rainWeekly"
14812
+ },
14813
+ {
14814
+ path: "rainMonthly",
14815
+ by: "rainMonthly"
14816
+ },
14817
+ {
14818
+ path: "rainYearly",
14819
+ by: "rainYearly"
14820
+ }
14821
+ ]
14822
+ }
14823
+ };
14824
+ /**
14825
+ * Unit meta on runtime-state fields. The composed-device row reads this;
14826
+ * it is not an override list (D944).
14827
+ */
14828
+ var CAP_RUNTIME_FIELD_UNITS = {
14829
+ "ambient-light-sensor": { illuminance: "lx" },
14830
+ "battery": {
14831
+ level: "%",
14832
+ voltage: "V",
14833
+ temperatureC: "°C"
14834
+ },
14835
+ "humidity-sensor": { humidity: "%" },
14836
+ "power-meter": {
14837
+ power: "W",
14838
+ deliveredPower: "W",
14839
+ energy: "kWh",
14840
+ voltage: "V",
14841
+ current: "A"
14842
+ },
14843
+ "temperature-sensor": { temperature: "°C" }
14844
+ };
14845
+ //#endregion
14846
+ //#region ../types/dist/esm/composition/cap-link.mjs
14847
+ /**
14848
+ * Whole-capability links (D1076): the declaration a `capLink` feature names,
14849
+ * its expansion into the field claims the composer already runs, and the wire
14850
+ * shapes of the two core-blocks methods that read and migrate them.
14851
+ *
14852
+ * Pure. Nothing here reads a device: the caller passes the cap's top-level
14853
+ * state fields, and the planner judges the source.
14854
+ */
14855
+ /** The clock every cap with a `lastFetchedAt` carries. A link writes it as `now`. */
14856
+ var CAP_LINK_CLOCK_FIELD = "lastFetchedAt";
14857
+ var CLOCK_SOURCE = {
14858
+ kind: "expression",
14859
+ expr: "now",
14860
+ bindings: {}
14861
+ };
14862
+ /** The link a cap declares under this id, from the generated catalog; undefined when there is none. */
14863
+ function declaredCapLink(cap, linkId) {
14864
+ return CAP_CUSTOMIZE_CATALOG[cap]?.links?.find((link) => link.id === linkId);
14865
+ }
14866
+ /** The `project` link a cap declares first, or undefined — what the migration converts to. */
14867
+ function projectCapLinkOf(cap) {
14868
+ return CAP_CUSTOMIZE_CATALOG[cap]?.links?.find((link) => link.mode === "project");
14869
+ }
14870
+ /**
14871
+ * The host top-level fields a `project` link serves: its `map` keys, or every
14872
+ * top-level field of the host cap. The clock rides with them. A `reference`
14873
+ * link serves none (it writes nothing).
14874
+ */
14875
+ function capLinkServedFields(link, hostFields) {
14876
+ if (link.mode !== "project") return [];
14877
+ const host = new Set(hostFields);
14878
+ const own = (link.map === void 0 ? null : Object.keys(link.map)) ?? [...host].filter((path) => path !== "lastFetchedAt");
14879
+ return host.has("lastFetchedAt") ? [...own, CAP_LINK_CLOCK_FIELD] : own;
14880
+ }
14881
+ /**
14882
+ * The `fields` feature a `project` link stands for: each served field is a
14883
+ * plain `from` of the source's `sourceCap` (the same path, or the map's), the
14884
+ * clock an expression of `now`. Null for a `reference` link.
14885
+ */
14886
+ function expandCapLink(feature, link, hostFields) {
14887
+ if (link.mode !== "project") return null;
14888
+ const fields = {};
14889
+ for (const path of capLinkServedFields(link, hostFields)) fields[path] = path === "lastFetchedAt" && link.map?.[path] === void 0 ? CLOCK_SOURCE : {
14890
+ kind: "from",
14891
+ source: feature.source,
14892
+ cap: link.sourceCap,
14893
+ fieldPath: link.map?.[path] ?? path
14894
+ };
14895
+ return {
14896
+ kind: "fields",
14897
+ cap: feature.cap,
14898
+ ...feature.enabled === void 0 ? {} : { enabled: feature.enabled },
14899
+ fields
14900
+ };
14901
+ }
14902
+ /**
14903
+ * A composition with every `project` capLink replaced, in place, by the
14904
+ * `fields` feature it expands to — what the cycle graph reads. A link the cap
14905
+ * does not declare, a `reference` link and a cap `topLevel` does not know stay
14906
+ * as they are (the planner refuses or ignores them).
14907
+ */
14908
+ function expandCapLinks(composition, topLevel) {
14909
+ if (!composition.features.some((feature) => feature.kind === "capLink")) return composition;
14910
+ return {
14911
+ ...composition,
14912
+ features: composition.features.map((feature) => {
14913
+ if (feature.kind !== "capLink") return feature;
14914
+ const link = declaredCapLink(feature.cap, feature.linkId);
14915
+ const hostFields = topLevel(feature.cap);
14916
+ if (link === void 0 || hostFields === null) return feature;
14917
+ return expandCapLink(feature, link, hostFields) ?? feature;
14918
+ })
14919
+ };
14920
+ }
14921
+ var CapLinkStateSchema = /* @__PURE__ */ zod.z.enum([
14922
+ "linked",
14923
+ "source-gone",
14924
+ "disabled"
14925
+ ]);
14926
+ /** One link of a device, as the card and the Customize table read it. */
14927
+ var CapLinkViewSchema = /* @__PURE__ */ zod.z.object({
14928
+ linkId: /* @__PURE__ */ zod.z.string(),
14929
+ /** The host cap the link is declared on. */
14930
+ cap: /* @__PURE__ */ zod.z.string(),
14931
+ /** The host slot a `reference` link fills; null for a `project` link. */
14932
+ slot: /* @__PURE__ */ zod.z.string().nullable(),
14933
+ mode: /* @__PURE__ */ zod.z.enum(["project", "reference"]),
14934
+ /** The device the link points at; `deviceId` is null once it is gone. */
14935
+ source: /* @__PURE__ */ zod.z.object({
14936
+ deviceId: /* @__PURE__ */ zod.z.number().int().nullable(),
14937
+ cap: /* @__PURE__ */ zod.z.string()
14938
+ }),
14939
+ state: CapLinkStateSchema
14940
+ });
14941
+ /** `not-loaded` until the compositions have been read — never an empty list (D315). */
14942
+ var CapLinksReadSchema = /* @__PURE__ */ zod.z.discriminatedUnion("status", [/* @__PURE__ */ zod.z.object({
14943
+ status: /* @__PURE__ */ zod.z.literal("ok"),
14944
+ links: /* @__PURE__ */ zod.z.array(CapLinkViewSchema)
14945
+ }), /* @__PURE__ */ zod.z.object({ status: /* @__PURE__ */ zod.z.literal("not-loaded") })]);
14946
+ var MigrateCapLinksInputSchema = /* @__PURE__ */ zod.z.object({ dryRun: /* @__PURE__ */ zod.z.boolean() });
14947
+ /** A set of per-field links turned (or, on a dry run, that would be turned) into one `capLink`. */
14948
+ var MigratedCapLinkSchema = /* @__PURE__ */ zod.z.object({
14949
+ deviceId: /* @__PURE__ */ zod.z.number().int(),
14950
+ cap: /* @__PURE__ */ zod.z.string(),
14951
+ linkId: /* @__PURE__ */ zod.z.string(),
14952
+ source: require_error_cap.CompositionSourceRefSchema,
14953
+ /** The host fields the old features carried. */
14954
+ fields: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string())
14955
+ });
14956
+ /** A set of per-field links the migration left untouched, with every reason. */
14957
+ var MixedCapLinkSchema = /* @__PURE__ */ zod.z.object({
14958
+ deviceId: /* @__PURE__ */ zod.z.number().int(),
14959
+ cap: /* @__PURE__ */ zod.z.string(),
14960
+ reasons: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string())
14961
+ });
14962
+ var MigrateCapLinksReportSchema = /* @__PURE__ */ zod.z.object({
14963
+ dryRun: /* @__PURE__ */ zod.z.boolean(),
14964
+ converted: /* @__PURE__ */ zod.z.array(MigratedCapLinkSchema),
14965
+ mixed: /* @__PURE__ */ zod.z.array(MixedCapLinkSchema),
14966
+ /** Features skipped by rule: stamped by an identity link (D1063), or disabled. */
14967
+ skipped: /* @__PURE__ */ zod.z.number().int(),
14968
+ /** Customizations already holding a `capLink` for the cap — nothing to do. */
14969
+ alreadyLinked: /* @__PURE__ */ zod.z.number().int()
14970
+ });
14971
+ //#endregion
14972
+ //#region ../types/dist/esm/ir/ir-error.mjs
14973
+ var IrCodecError = class extends Error {
14974
+ code;
14975
+ constructor(code, message) {
14976
+ super(message);
14977
+ this.name = "IrCodecError";
14978
+ this.code = code;
14979
+ }
14980
+ };
14981
+ //#endregion
14982
+ //#region ../types/dist/esm/ir/ir-timings.mjs
14983
+ /** Maximum number of mark/space entries one pulse train may carry. */
14984
+ var IR_TIMINGS_MAX = 1024;
14985
+ /**
14986
+ * A pulse train in signed microseconds: mark (+) first, then space (-), strictly
14987
+ * alternating, no zeros, 2..1024 entries.
14988
+ */
14989
+ var IrTimingsSchema = /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.number().int()).min(2).max(IR_TIMINGS_MAX).superRefine((timings, ctx) => {
14990
+ timings.forEach((value, index) => {
14991
+ const expectMark = index % 2 === 0;
14992
+ if (value === 0 || value > 0 !== expectMark) ctx.addIssue({
14993
+ code: "custom",
14994
+ message: `timing ${index} must be a non-zero ${expectMark ? "mark (positive)" : "space (negative)"}`,
14995
+ path: [index]
14996
+ });
14997
+ });
14998
+ });
14999
+ /** Per-command transmit options. Every key is optional; a transmitter applies what it can. */
15000
+ var TransmitSettingsSchema = /* @__PURE__ */ zod.z.object({
15001
+ carrierHz: /* @__PURE__ */ zod.z.number().int().positive().optional(),
15002
+ dutyCyclePercent: /* @__PURE__ */ zod.z.number().int().min(1).max(100).optional(),
15003
+ repeat: /* @__PURE__ */ zod.z.number().int().min(0).max(20).optional(),
15004
+ repeatDelayMs: /* @__PURE__ */ zod.z.number().int().min(0).optional()
15005
+ });
15006
+ //#endregion
15007
+ //#region ../types/dist/esm/ir/pronto.mjs
15008
+ /** One Pronto frequency-word unit, in microseconds, per unit of the word. */
15009
+ var PRONTO_CLOCK_US = .241246;
15010
+ var LEARNED_FORM = 0;
15011
+ /**
15012
+ * Decode a learned (0000 form) Pronto hex string. The intro burst is followed by
15013
+ * the repeat burst once; a different form is refused with `pronto-unsupported-form`.
15014
+ */
15015
+ function decodePronto(code) {
15016
+ const words = code.trim().split(/\s+/).filter((w) => w.length > 0);
15017
+ if (words.length < 4) throw new IrCodecError("pronto-malformed", `Pronto code needs at least 4 words, got ${words.length}`);
15018
+ const values = words.map((w) => /^[0-9a-fA-F]{1,4}$/.test(w) ? parseInt(w, 16) : NaN);
15019
+ if (values.some((v) => Number.isNaN(v))) throw new IrCodecError("pronto-malformed", "Pronto code must be 4-digit hexadecimal words");
15020
+ const [form, freqWord, introCount, repeatCount] = values;
15021
+ if (form === void 0 || freqWord === void 0 || introCount === void 0 || repeatCount === void 0) throw new IrCodecError("pronto-malformed", "Pronto header incomplete");
15022
+ if (form !== LEARNED_FORM) throw new IrCodecError("pronto-unsupported-form", `Pronto form ${words[0] ?? ""} is not supported, only the learned 0000 form`);
15023
+ if (freqWord === 0) throw new IrCodecError("pronto-malformed", "Pronto frequency word is zero");
15024
+ const pairs = introCount + repeatCount;
15025
+ if (pairs === 0 || values.length !== 4 + pairs * 2) throw new IrCodecError("pronto-malformed", `Pronto declares ${pairs} burst pairs but carries ${(values.length - 4) / 2} word pairs`);
15026
+ const unitUs = freqWord * PRONTO_CLOCK_US;
15027
+ const timings = values.slice(4).map((count, index) => {
15028
+ const us = Math.max(1, Math.round(count * unitUs));
15029
+ return index % 2 === 0 ? us : -us;
15030
+ });
15031
+ const checked = IrTimingsSchema.safeParse(timings);
15032
+ if (!checked.success) throw new IrCodecError("invalid-timings", `Pronto decoded to invalid timings: ${checked.error.message}`);
15033
+ return {
15034
+ timings: checked.data,
15035
+ carrierHz: Math.round(1e6 / unitUs)
15036
+ };
15037
+ }
15038
+ //#endregion
15039
+ //#region ../types/dist/esm/ir/fastlz.mjs
15040
+ /**
15041
+ * FastLZ level 1: a byte-oriented LZ77 stream. A control byte below 32 starts a
15042
+ * literal run of `ctrl + 1` bytes; otherwise it is a back-reference whose length
15043
+ * is `ctrl >> 5` (extended by one byte when 7) and whose distance is split
15044
+ * between the low 5 bits and the next byte.
15045
+ */
15046
+ var MAX_DISTANCE = 8192;
15047
+ var MAX_LITERAL_RUN = 32;
15048
+ var MIN_MATCH = 3;
15049
+ var MAX_MATCH = 264;
15050
+ /**
15051
+ * Most bytes a decoded IR code may hold: two bytes per timing. A level-1 stream
15052
+ * can expand ~130x, so the decoder checks this bound before every write.
15053
+ */
15054
+ var IR_DECOMPRESSED_MAX = IR_TIMINGS_MAX * 2;
15055
+ function fastlzDecompress(input) {
15056
+ const out = [];
15057
+ let ip = 0;
15058
+ const room = (count) => {
15059
+ if (out.length + count > IR_DECOMPRESSED_MAX) throw new IrCodecError("tuya-malformed", "decompressed code is larger than any IR train");
15060
+ };
15061
+ const next = () => {
15062
+ const byte = input[ip++];
15063
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "compressed stream is truncated");
15064
+ return byte;
15065
+ };
15066
+ while (ip < input.length) {
15067
+ const ctrl = next();
15068
+ if (ctrl < 32) {
15069
+ room(ctrl + 1);
15070
+ for (let i = 0; i <= ctrl; i++) out.push(next());
15071
+ continue;
15072
+ }
15073
+ let len = (ctrl >> 5) - 1;
15074
+ if (len === 6) len += next();
15075
+ const distance = ((ctrl & 31) << 8) + next() + 1;
15076
+ const start = out.length - distance;
15077
+ if (start < 0) throw new IrCodecError("tuya-malformed", "back-reference points before the stream");
15078
+ room(len + 3);
15079
+ for (let i = 0; i < len + 3; i++) {
15080
+ const byte = out[start + i];
15081
+ if (byte === void 0) throw new IrCodecError("tuya-malformed", "back-reference is invalid");
15082
+ out.push(byte);
15083
+ }
15084
+ }
15085
+ return Uint8Array.from(out);
15086
+ }
15087
+ function fastlzCompress(input) {
15088
+ const out = [];
15089
+ const lastSeen = /* @__PURE__ */ new Map();
15090
+ let literalStart = 0;
15091
+ const flushLiterals = (end) => {
15092
+ for (let from = literalStart; from < end; from += MAX_LITERAL_RUN) {
15093
+ const to = Math.min(from + MAX_LITERAL_RUN, end);
15094
+ out.push(to - from - 1);
15095
+ for (let i = from; i < to; i++) out.push(input[i] ?? 0);
15096
+ }
15097
+ };
15098
+ let pos = 0;
15099
+ while (pos < input.length) {
15100
+ let matchLen = 0;
15101
+ let matchDistance = 0;
15102
+ if (pos + MIN_MATCH <= input.length) {
15103
+ const key = (input[pos] ?? 0) << 16 | (input[pos + 1] ?? 0) << 8 | (input[pos + 2] ?? 0);
15104
+ const candidate = lastSeen.get(key);
15105
+ lastSeen.set(key, pos);
15106
+ if (candidate !== void 0 && pos - candidate <= MAX_DISTANCE) {
15107
+ let len = 0;
15108
+ while (pos + len < input.length && len < MAX_MATCH && input[candidate + len] === input[pos + len]) len++;
15109
+ if (len >= MIN_MATCH) {
15110
+ matchLen = len;
15111
+ matchDistance = pos - candidate - 1;
15112
+ }
15113
+ }
15114
+ }
15115
+ if (matchLen === 0) {
15116
+ pos++;
15117
+ continue;
15118
+ }
15119
+ flushLiterals(pos);
15120
+ const enc = matchLen - 2;
15121
+ if (enc < 7) out.push(enc << 5 | matchDistance >> 8);
15122
+ else out.push(224 | matchDistance >> 8, enc - 7);
15123
+ out.push(matchDistance & 255);
15124
+ pos += matchLen;
15125
+ literalStart = pos;
15126
+ }
15127
+ flushLiterals(input.length);
15128
+ return Uint8Array.from(out);
15129
+ }
15130
+ //#endregion
15131
+ //#region ../types/dist/esm/ir/tuya.mjs
15132
+ var ALPHABET = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";
15133
+ var MAX_DURATION_US = 65535;
15134
+ function toBase64(bytes) {
15135
+ let out = "";
15136
+ for (let i = 0; i < bytes.length; i += 3) {
15137
+ const a = bytes[i] ?? 0;
15138
+ const b = bytes[i + 1] ?? 0;
15139
+ const c = bytes[i + 2] ?? 0;
15140
+ const word = a << 16 | b << 8 | c;
15141
+ out += ALPHABET[word >> 18 & 63];
15142
+ out += ALPHABET[word >> 12 & 63];
15143
+ out += i + 1 < bytes.length ? ALPHABET[word >> 6 & 63] : "=";
15144
+ out += i + 2 < bytes.length ? ALPHABET[word & 63] : "=";
15145
+ }
15146
+ return out;
15147
+ }
15148
+ function fromBase64(text) {
15149
+ const clean = text.trim().replace(/=+$/, "");
15150
+ if (clean.length === 0 || clean.length % 4 === 1) throw new IrCodecError("tuya-malformed", "not a base64 string");
15151
+ const out = [];
15152
+ let bits = 0;
15153
+ let acc = 0;
15154
+ for (const ch of clean) {
15155
+ const value = ALPHABET.indexOf(ch);
15156
+ if (value < 0) throw new IrCodecError("tuya-malformed", "not a base64 string");
15157
+ acc = acc << 6 | value;
15158
+ bits += 6;
15159
+ if (bits >= 8) {
15160
+ bits -= 8;
15161
+ out.push(acc >> bits & 255);
15162
+ }
15163
+ }
15164
+ return Uint8Array.from(out);
15165
+ }
15166
+ /** Signed pulse train to a Tuya IR code: base64(FastLZ(uint16 LE durations)). */
15167
+ function encodeTuya(timings) {
15168
+ const bytes = new Uint8Array(timings.length * 2);
15169
+ timings.forEach((value, index) => {
15170
+ const duration = Math.abs(value);
15171
+ if (duration === 0 || duration > MAX_DURATION_US) throw new IrCodecError("invalid-timings", `timing ${index} does not fit 16 bits`);
15172
+ bytes[index * 2] = duration & 255;
15173
+ bytes[index * 2 + 1] = duration >> 8;
15174
+ });
15175
+ return toBase64(fastlzCompress(bytes));
15176
+ }
15177
+ /** A Tuya IR code to a signed pulse train (mark first). Throws `IrCodecError`. */
15178
+ function decodeTuya(code) {
15179
+ const bytes = fastlzDecompress(fromBase64(code));
15180
+ if (bytes.length === 0 || bytes.length % 2 !== 0) throw new IrCodecError("tuya-malformed", "payload is not a list of 16-bit durations");
15181
+ const timings = [];
15182
+ for (let i = 0; i < bytes.length; i += 2) {
15183
+ const duration = (bytes[i] ?? 0) | (bytes[i + 1] ?? 0) << 8;
15184
+ timings.push(i / 2 % 2 === 0 ? duration : -duration);
15185
+ }
15186
+ const checked = IrTimingsSchema.safeParse(timings);
15187
+ if (!checked.success) throw new IrCodecError("tuya-malformed", checked.error.message);
15188
+ return checked.data;
15189
+ }
15190
+ //#endregion
15191
+ //#region ../types/dist/esm/ir/native.mjs
15192
+ /** Device-native IR code formats a transmitter can replay verbatim. */
15193
+ var IrNativeFormatSchema = /* @__PURE__ */ zod.z.enum(["tuya"]);
15194
+ /**
15195
+ * Longest native code accepted: base64 of the worst-case compressed stream
15196
+ * (every decoded byte as a literal, plus one control byte per 32), with margin.
15197
+ */
15198
+ var IR_NATIVE_CODE_MAX_CHARS = /* @__PURE__ */ Math.ceil((IR_DECOMPRESSED_MAX + /* @__PURE__ */ Math.ceil(IR_DECOMPRESSED_MAX / 32)) / 3) * 4 + 256;
15199
+ var IrNativeCodeSchema = /* @__PURE__ */ zod.z.object({
15200
+ format: IrNativeFormatSchema,
15201
+ code: /* @__PURE__ */ zod.z.string().min(1).max(IR_NATIVE_CODE_MAX_CHARS)
15202
+ });
15203
+ var IR_NATIVE_CODECS = { tuya: {
15204
+ encode: encodeTuya,
15205
+ decode: decodeTuya
15206
+ } };
15207
+ //#endregion
15208
+ //#region ../types/dist/esm/ir/ir-payload.mjs
15209
+ /** What a remote command stores: a raw pulse train, a learned Pronto code, or a device-native code. */
15210
+ var IrPayloadSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
15211
+ /* @__PURE__ */ zod.z.object({
15212
+ kind: /* @__PURE__ */ zod.z.literal("raw"),
15213
+ timings: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.number().int()),
15214
+ settings: /* @__PURE__ */ TransmitSettingsSchema.optional()
15215
+ }),
15216
+ /* @__PURE__ */ zod.z.object({
15217
+ kind: /* @__PURE__ */ zod.z.literal("pronto"),
15218
+ code: /* @__PURE__ */ zod.z.string()
15219
+ }),
15220
+ /* @__PURE__ */ zod.z.object({
15221
+ kind: /* @__PURE__ */ zod.z.literal("native"),
15222
+ format: IrNativeFormatSchema,
15223
+ code: /* @__PURE__ */ zod.z.string()
15224
+ })
15225
+ ]);
15226
+ /** Resolve a payload to what `ir-transmitter.send` takes. Throws `IrCodecError`. */
15227
+ function toTimings(payload) {
15228
+ if (payload.kind === "pronto") {
15229
+ const decoded = decodePronto(payload.code);
15230
+ return {
15231
+ timings: decoded.timings,
15232
+ settings: { carrierHz: decoded.carrierHz }
15233
+ };
15234
+ }
15235
+ if (payload.kind === "native") return {
15236
+ timings: IR_NATIVE_CODECS[payload.format].decode(payload.code),
15237
+ settings: {}
15238
+ };
15239
+ const checked = IrTimingsSchema.safeParse(payload.timings);
15240
+ if (!checked.success) throw new IrCodecError("invalid-timings", checked.error.message);
15241
+ return {
15242
+ timings: checked.data,
15243
+ settings: payload.settings ?? {}
15244
+ };
15245
+ }
15246
+ //#endregion
15247
+ //#region ../types/dist/esm/remote/remote-roles.mjs
15248
+ /**
15249
+ * The role vocabulary of a remote (D963): what a button MEANS, independent of
15250
+ * how it is wired. A layout template places buttons by role; a device binds a
15251
+ * role to an action; an exporter asks for a role by name. Roles are shared so
15252
+ * one layout fits every appliance and one voice command fits every binding.
15253
+ *
15254
+ * A role outside this list is `custom:<key>` — the operator's own button (a
15255
+ * SmartIR source, a channel preset). The key is a lowercase slug.
15256
+ */
15257
+ var REMOTE_KNOWN_ROLES = [
15258
+ "power",
15259
+ "power_on",
15260
+ "power_off",
15261
+ "volume_up",
15262
+ "volume_down",
15263
+ "mute",
15264
+ "channel_up",
15265
+ "channel_down",
15266
+ "up",
15267
+ "down",
15268
+ "left",
15269
+ "right",
15270
+ "ok",
15271
+ "back",
15272
+ "home",
15273
+ "menu",
15274
+ "info",
15275
+ "guide",
15276
+ "exit",
15277
+ "input",
15278
+ "play",
15279
+ "pause",
15280
+ "play_pause",
15281
+ "stop",
15282
+ "next",
15283
+ "previous",
15284
+ "fast_forward",
15285
+ "rewind",
15286
+ "digit_0",
15287
+ "digit_1",
15288
+ "digit_2",
15289
+ "digit_3",
15290
+ "digit_4",
15291
+ "digit_5",
15292
+ "digit_6",
15293
+ "digit_7",
15294
+ "digit_8",
15295
+ "digit_9",
15296
+ "source_select"
15297
+ ];
15298
+ /**
15299
+ * Roles that are WIDGETS, not commands: a layout may place them, but they are
15300
+ * never bound, never pressed through `sendCommand`, never a source step and
15301
+ * never a media-player feature. `source_select` is the source picker key.
15302
+ */
15303
+ var REMOTE_WIDGET_ROLES = ["source_select"];
15304
+ function isRemoteWidgetRole(role) {
15305
+ return REMOTE_WIDGET_ROLES.includes(role);
15306
+ }
15307
+ var CUSTOM_KEY_RE = /^[a-z0-9][a-z0-9_]{0,47}$/;
15308
+ var KNOWN_ROLES = /* @__PURE__ */ new Set(REMOTE_KNOWN_ROLES);
15309
+ function isRemoteKnownRole(value) {
15310
+ return KNOWN_ROLES.has(value);
15311
+ }
15312
+ function isRemoteCustomKey(key) {
15313
+ return CUSTOM_KEY_RE.test(key);
15314
+ }
15315
+ /** The key of a `custom:<key>` role, or null for any other string. */
15316
+ function customKeyOfRole(role) {
15317
+ if (!role.startsWith("custom:")) return null;
15318
+ const key = role.slice(7);
15319
+ return isRemoteCustomKey(key) ? key : null;
15320
+ }
15321
+ function isRemoteRole(value) {
15322
+ return isRemoteKnownRole(value) || customKeyOfRole(value) !== null;
15323
+ }
15324
+ var RemoteRoleSchema = /* @__PURE__ */ zod.z.string().refine(isRemoteRole, { message: "a role is one of the known roles or custom:<key> (lowercase letters, digits, _)" });
15325
+ //#endregion
15326
+ //#region ../types/dist/esm/remote/remote-sources.mjs
15327
+ /**
15328
+ * The sources of a remote (planning#460): what a media player's source list
15329
+ * offers, ALWAYS declared by the operator — a button is never a source on its
15330
+ * own. Two kinds:
15331
+ *
15332
+ * - `digits`: a name and a number ("Rai 1" = `1`, "Canale 24" = `25`). The
15333
+ * steps are the number's `digit_N` roles, so the number is also the channel
15334
+ * a voice command or `playMedia` names.
15335
+ * - `sequence`: a name and explicit steps — bound roles pressed in order
15336
+ * (an input key, a menu macro such as `source, down, down, ok`).
15337
+ * - `ir`: a name and one infrared code of its own (raw timings or a Pronto
15338
+ * string), sent through a named transmitter (planning#464). It presses no
15339
+ * button: a source the remote's layout has no key for.
15340
+ *
15341
+ * The name and the number resolve to the SAME declared source. A number no
15342
+ * `digits` source declares is not a channel: it is refused, never guessed.
15343
+ */
15344
+ var REMOTE_SOURCE_KINDS = [
15345
+ "digits",
15346
+ "sequence",
15347
+ "ir"
15348
+ ];
15349
+ var REMOTE_SOURCE_ID_RE = /^[a-z0-9][a-z0-9_-]{0,47}$/;
15350
+ var CHANNEL_NUMBER_RE = /* @__PURE__ */ new RegExp(`^[0-9]{1,6}$`);
15351
+ var sourceBase = {
15352
+ /** A lowercase slug, stable across renames. */
15353
+ id: /* @__PURE__ */ zod.z.string().regex(REMOTE_SOURCE_ID_RE, { message: "a lowercase slug" }),
15354
+ /** What the operator calls it, and what a voice command or a picker names. */
15355
+ name: /* @__PURE__ */ zod.z.string().trim().min(1).max(60)
15356
+ };
15357
+ var RemoteDigitsSourceSchema = /* @__PURE__ */ zod.z.object({
15358
+ ...sourceBase,
15359
+ kind: /* @__PURE__ */ zod.z.literal("digits"),
15360
+ number: /* @__PURE__ */ zod.z.string().regex(CHANNEL_NUMBER_RE, { message: "up to 6 digits" })
15361
+ });
15362
+ var RemoteSequenceSourceSchema = /* @__PURE__ */ zod.z.object({
15363
+ ...sourceBase,
15364
+ kind: /* @__PURE__ */ zod.z.literal("sequence"),
15365
+ steps: /* @__PURE__ */ zod.z.array(RemoteRoleSchema).min(1).max(16)
15366
+ });
15367
+ var RemoteIrSourceSchema = /* @__PURE__ */ zod.z.object({
15368
+ ...sourceBase,
15369
+ kind: /* @__PURE__ */ zod.z.literal("ir"),
15370
+ /**
15371
+ * The `ir-transmitter` device the code is sent through. Absent = the remote's
15372
+ * `defaultTransmitterId` at run time (a source stored before this field was
15373
+ * optional keeps the emitter it names).
15374
+ */
15375
+ transmitterId: /* @__PURE__ */ zod.z.number().int().nonnegative().optional(),
15376
+ /** The code itself; whether a transmitter could send it is `irSourceProblem`. */
15377
+ payload: IrPayloadSchema
15378
+ });
15379
+ var RemoteSourceSchema = /* @__PURE__ */ zod.z.discriminatedUnion("kind", [
15380
+ RemoteDigitsSourceSchema,
15381
+ RemoteSequenceSourceSchema,
15382
+ RemoteIrSourceSchema
15383
+ ]);
15384
+ var REMOTE_STEP_DELAY_MAX_MS = 3e3;
15385
+ /**
15386
+ * The roles a source presses, in order. A `digits` number is its digit roles;
15387
+ * an `ir` source presses none — it carries its own code.
15388
+ */
15389
+ function remoteSourceSteps(source) {
15390
+ switch (source.kind) {
15391
+ case "sequence": return source.steps;
15392
+ case "digits": return Array.from(source.number, (digit) => `digit_${digit}`);
15393
+ case "ir": return [];
15394
+ }
15395
+ }
15396
+ /**
15397
+ * Why an `ir` source's code could not be sent (the codec's own words), or null
15398
+ * when it resolves to a pulse train. The schema refuses on it; the editor shows it.
15399
+ */
15400
+ function irSourceProblem(source) {
15401
+ try {
15402
+ toTimings(source.payload);
15403
+ return null;
15404
+ } catch (err) {
15405
+ if (err instanceof IrCodecError) return err.message;
15406
+ throw err;
15407
+ }
15408
+ }
15409
+ function same(a, b) {
15410
+ return a.trim().toLowerCase() === b.trim().toLowerCase();
15411
+ }
15412
+ /** The `digits` source that declares this channel number, or null. */
15413
+ function findChannelSource(sources, number) {
15414
+ const wanted = number.trim();
15415
+ for (const source of sources) if (source.kind === "digits" && source.number === wanted) return source;
15416
+ return null;
15417
+ }
15418
+ /**
15419
+ * The declared source a name, an id or a channel number points at. The name and
15420
+ * the number reach the same source; nothing else is guessed.
15421
+ */
15422
+ function resolveRemoteSource(sources, query) {
15423
+ const byName = sources.find((source) => same(source.name, query));
15424
+ if (byName !== void 0) return byName;
15425
+ const byId = sources.find((source) => source.id === query.trim());
15426
+ if (byId !== void 0) return byId;
15427
+ return findChannelSource(sources, query);
15428
+ }
15429
+ //#endregion
15430
+ //#region ../types/dist/esm/capabilities/media-player.cap.mjs
15431
+ /**
15432
+ * Media-player cap. Models HA `media_player.*` (Sonos, Chromecast,
15433
+ * Apple TV, Spotify, Roku, generic OTT receivers, …) on
15434
+ * `DeviceType.MediaPlayer`. Disjoint from the camera streaming
15435
+ * surface — those use `DeviceType.Camera` + the broker pipeline.
15436
+ *
15437
+ * The cap declares a wide method surface; not every backend supports
15438
+ * every method. Drivers signal sub-capability via the
15439
+ * `DeviceFeature.MediaPlayerXxx` flags (paired one-to-one with the
15440
+ * corresponding method) so the UI gates buttons without a slice
15441
+ * fetch — same pattern as `PanTiltZoom` for cameras.
15442
+ */
15443
+ var MediaPlayerStateSchema = /* @__PURE__ */ zod.z.enum([
15444
+ "off",
15445
+ "on",
15446
+ "idle",
15447
+ "playing",
15448
+ "paused",
15449
+ "buffering",
15450
+ "standby"
15451
+ ]);
15452
+ var MediaPlayerRepeatSchema = /* @__PURE__ */ zod.z.enum([
15453
+ "off",
15454
+ "all",
15455
+ "one"
15456
+ ]);
15457
+ var MediaInfoSchema = /* @__PURE__ */ zod.z.object({
15458
+ /** Free-form media kind (`music`, `tvshow`, `movie`, `app`, `channel`,
15459
+ * `podcast`, …). */
15460
+ type: /* @__PURE__ */ zod.z.string(),
15461
+ /** Human-readable title. */
15462
+ title: /* @__PURE__ */ zod.z.string(),
15463
+ /** Optional artist / channel / station label. */
15464
+ artist: /* @__PURE__ */ zod.z.string().optional(),
15465
+ /** Optional album / season / show name. */
15466
+ album: /* @__PURE__ */ zod.z.string().optional(),
15467
+ /** Optional cover-art / thumbnail URL. */
15468
+ imageUrl: /* @__PURE__ */ zod.z.string().optional()
15469
+ });
15470
+ /**
15471
+ * Where `state`, `volumeLevel`, `isMuted` and `source` come from. `reported`:
15472
+ * the device said so. `assumed`: the driver has no feedback (infrared) and
15473
+ * tracks what it last SENT; it moves only after a send was accepted, and a
15474
+ * human at the real remote makes it wrong. A UI shows an assumed value as a
15475
+ * guess, never as a reading.
15476
+ */
15477
+ var MediaPlayerStateSourceSchema = /* @__PURE__ */ zod.z.enum(["reported", "assumed"]);
15478
+ /** The fields of a media-player status a driver can only guess. */
15479
+ var MediaPlayerAssumedFieldSchema = /* @__PURE__ */ zod.z.enum([
15480
+ "state",
15481
+ "volumeLevel",
15482
+ "isMuted",
15483
+ "source"
15484
+ ]);
15485
+ var MediaPlayerStatusSchema = /* @__PURE__ */ zod.z.object({
15486
+ /** Playback lifecycle state. */
15487
+ state: MediaPlayerStateSchema,
15488
+ /**
15489
+ * Whether the state fields are readings or the driver's own bookkeeping.
15490
+ * A slice written before this field existed parses as `reported`.
15491
+ */
15492
+ stateSource: /* @__PURE__ */ MediaPlayerStateSourceSchema.default("reported"),
15493
+ /**
15494
+ * Which fields are the driver's own guess. `stateSource` is `assumed` when
15495
+ * this is not empty; a field not listed here is a reading even then (power
15496
+ * from a running-state source, mute guessed from the last send).
15497
+ */
15498
+ assumedFields: /* @__PURE__ */ zod.z.array(MediaPlayerAssumedFieldSchema).default([]),
15499
+ /** Volume as 0..100 inclusive. Null when the device has no volume
15500
+ * surface. Pair with `DeviceFeature.MediaPlayerVolume`. */
15501
+ volumeLevel: /* @__PURE__ */ zod.z.number().min(0).max(100).nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("percentage")),
15502
+ /** Mute toggle distinct from volume=0. Null when no mute surface.
15503
+ * Pair with `DeviceFeature.MediaPlayerMute`. */
15504
+ isMuted: /* @__PURE__ */ zod.z.boolean().nullable(),
15505
+ /**
15506
+ * True only when the provider READS the mute state back from the device.
15507
+ * Absent or false: mute is a momentary key. A non-null `isMuted` is not a
15508
+ * reading on its own — an infrared send can leave a value without this flag.
15509
+ */
15510
+ muteReadback: /* @__PURE__ */ zod.z.boolean().optional(),
15511
+ /** Active source / input. Empty when no source surface. */
15512
+ source: /* @__PURE__ */ zod.z.string(),
15513
+ /** Selectable sources. Empty when no source surface.
15514
+ * Pair with `DeviceFeature.MediaPlayerSelectSource`. */
15515
+ availableSources: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.string()),
15516
+ /**
15517
+ * What each declared source IS, when the sources are the operator's own (a
15518
+ * remote, planning#460): an exporter offers a channel by number only for a
15519
+ * `digits` source and an input only for a `sequence` one. Absent when the
15520
+ * player's sources are its own.
15521
+ */
15522
+ declaredSources: /* @__PURE__ */ zod.z.array(/* @__PURE__ */ zod.z.object({
15523
+ name: /* @__PURE__ */ zod.z.string(),
15524
+ kind: /* @__PURE__ */ zod.z.enum(REMOTE_SOURCE_KINDS),
15525
+ /** The channel number of a `digits` source. */
15526
+ number: /* @__PURE__ */ zod.z.string().optional()
15527
+ })).optional(),
15528
+ /** Currently-playing media info. Null when nothing is playing. */
15529
+ currentMedia: /* @__PURE__ */ MediaInfoSchema.nullable(),
15530
+ /** Current playback position in ms. Null when not seekable or
15531
+ * nothing is playing. Pair with `DeviceFeature.MediaPlayerSeek`. */
15532
+ position: /* @__PURE__ */ zod.z.number().int().nonnegative().nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("duration-ms")),
15533
+ /** Total duration of the current media in ms. Null when unknown
15534
+ * (live stream) or nothing is playing. */
15535
+ duration: /* @__PURE__ */ zod.z.number().int().nonnegative().nullable().meta(/* @__PURE__ */ require_quantity.readingMeta("duration-ms")),
15536
+ /** Shuffle toggle. Null when no shuffle surface.
15537
+ * Pair with `DeviceFeature.MediaPlayerShuffle`. */
15538
+ shuffle: /* @__PURE__ */ zod.z.boolean().nullable(),
15539
+ /** Repeat mode. Null when no repeat surface.
15540
+ * Pair with `DeviceFeature.MediaPlayerRepeat`. */
15541
+ repeat: /* @__PURE__ */ MediaPlayerRepeatSchema.nullable(),
15542
+ /** Ms epoch when `position` was read from the device. Null when the driver
15543
+ * does not say; a UI that advances the position while playing counts from it. */
15544
+ positionUpdatedAt: /* @__PURE__ */ zod.z.number().nullable().default(null),
15545
+ /** Ms epoch when the slice was last updated. */
15546
+ lastChangedAt: /* @__PURE__ */ zod.z.number()
15547
+ });
15548
+ var stepInput = /* @__PURE__ */ zod.z.object({
15549
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15550
+ /** How many presses: the caller's count (Alexa `volumeSteps`, `channelCount`). */
15551
+ steps: /* @__PURE__ */ zod.z.number().int().min(1).max(50).default(1)
15552
+ });
15553
+ var deviceOnly = /* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() });
15554
+ var mediaPlayerCapability = {
15555
+ name: "media-player",
15556
+ scope: "device",
15557
+ deviceNative: true,
15558
+ mode: "singleton",
15559
+ deviceTypes: [require_device_type.DeviceType.MediaPlayer],
15560
+ power: {
15561
+ kind: "methods",
15562
+ field: "state",
15563
+ offValues: ["off", "standby"],
15564
+ on: "turnOn",
15565
+ off: "turnOff"
15566
+ },
15567
+ methods: {
15568
+ turnOn: /* @__PURE__ */ require_capability_definition.optionalMethod(deviceOnly, /* @__PURE__ */ zod.z.void(), {
15569
+ kind: "mutation",
15570
+ auth: "protected",
15571
+ actions: [{
15572
+ id: "media.turnOn",
15573
+ label: /* @__PURE__ */ require_l10n.t("Turn on", "Accendi"),
15574
+ phrase: /* @__PURE__ */ require_l10n.t("Turn on {device}", "Accendi {device}"),
15575
+ icon: "power"
15576
+ }]
15577
+ }),
15578
+ turnOff: /* @__PURE__ */ require_capability_definition.optionalMethod(deviceOnly, /* @__PURE__ */ zod.z.void(), {
15579
+ kind: "mutation",
15580
+ auth: "protected",
15581
+ actions: [{
15582
+ id: "media.turnOff",
15583
+ label: /* @__PURE__ */ require_l10n.t("Turn off", "Spegni"),
15584
+ phrase: /* @__PURE__ */ require_l10n.t("Turn off {device}", "Spegni {device}"),
15585
+ icon: "power"
15586
+ }]
15587
+ }),
15588
+ volumeUp: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
15589
+ kind: "mutation",
15590
+ auth: "protected",
15591
+ actions: [{
15592
+ id: "media.volumeUp",
15593
+ label: /* @__PURE__ */ require_l10n.t("Volume up", "Alza il volume"),
15594
+ phrase: /* @__PURE__ */ require_l10n.t("Raise the volume of {device}", "Alza il volume di {device}"),
15595
+ icon: "volume-2"
15596
+ }]
15597
+ }),
15598
+ volumeDown: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
15599
+ kind: "mutation",
15600
+ auth: "protected",
15601
+ actions: [{
15602
+ id: "media.volumeDown",
15603
+ label: /* @__PURE__ */ require_l10n.t("Volume down", "Abbassa il volume"),
15604
+ phrase: /* @__PURE__ */ require_l10n.t("Lower the volume of {device}", "Abbassa il volume di {device}"),
15605
+ icon: "volume-2"
15606
+ }]
15607
+ }),
15608
+ channelUp: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
15609
+ kind: "mutation",
15610
+ auth: "protected",
15611
+ actions: [{
15612
+ id: "media.channelUp",
15613
+ label: /* @__PURE__ */ require_l10n.t("Channel up", "Canale successivo"),
15614
+ phrase: /* @__PURE__ */ require_l10n.t("Go to the next channel on {device}", "Passa al canale successivo su {device}"),
15615
+ icon: "skip-forward"
15616
+ }]
15617
+ }),
15618
+ channelDown: /* @__PURE__ */ require_capability_definition.optionalMethod(stepInput, /* @__PURE__ */ zod.z.void(), {
15619
+ kind: "mutation",
15620
+ auth: "protected",
15621
+ actions: [{
15622
+ id: "media.channelDown",
15623
+ label: /* @__PURE__ */ require_l10n.t("Channel down", "Canale precedente"),
15624
+ phrase: /* @__PURE__ */ require_l10n.t("Go to the previous channel on {device}", "Torna al canale precedente su {device}"),
15625
+ icon: "skip-back"
15626
+ }]
15627
+ }),
15628
+ play: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
15629
+ kind: "mutation",
15630
+ auth: "protected",
15631
+ actions: [{
15632
+ id: "media.play",
15633
+ effect: {
15634
+ field: "state",
15635
+ value: "playing"
15636
+ },
15637
+ label: /* @__PURE__ */ require_l10n.t("Play", "Riproduci"),
15638
+ phrase: /* @__PURE__ */ require_l10n.t("Play on {device}", "Avvia la riproduzione su {device}"),
15639
+ icon: "play"
15640
+ }]
15641
+ }),
15642
+ pause: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
15643
+ kind: "mutation",
15644
+ auth: "protected",
15645
+ actions: [{
15646
+ id: "media.pause",
15647
+ effect: {
15648
+ field: "state",
15649
+ value: "paused"
15650
+ },
15651
+ label: /* @__PURE__ */ require_l10n.t("Pause media", "Metti in pausa"),
15652
+ phrase: /* @__PURE__ */ require_l10n.t("Pause {device}", "Metti in pausa {device}"),
15653
+ icon: "pause"
15654
+ }]
15655
+ }),
15656
+ stop: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
15657
+ kind: "mutation",
15658
+ auth: "protected",
15659
+ actions: [{
15660
+ id: "media.stop",
15661
+ label: /* @__PURE__ */ require_l10n.t("Stop media", "Ferma la riproduzione"),
15662
+ phrase: /* @__PURE__ */ require_l10n.t("Stop {device}", "Ferma {device}"),
15663
+ icon: "square"
15664
+ }]
15665
+ }),
15666
+ next: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
15667
+ kind: "mutation",
15668
+ auth: "protected",
15669
+ actions: [{
15670
+ id: "media.next",
15671
+ label: /* @__PURE__ */ require_l10n.t("Next track", "Brano successivo"),
15672
+ phrase: /* @__PURE__ */ require_l10n.t("Skip to the next track on {device}", "Passa al brano successivo su {device}"),
15673
+ icon: "skip-forward"
15674
+ }]
15675
+ }),
15676
+ previous: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative() }), /* @__PURE__ */ zod.z.void(), {
15677
+ kind: "mutation",
15678
+ auth: "protected",
15679
+ actions: [{
15680
+ id: "media.previous",
15681
+ label: /* @__PURE__ */ require_l10n.t("Previous track", "Brano precedente"),
15682
+ phrase: /* @__PURE__ */ require_l10n.t("Go back to the previous track on {device}", "Torna al brano precedente su {device}"),
15683
+ icon: "skip-back"
15684
+ }]
15685
+ }),
15686
+ setVolume: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15687
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15688
+ volumeLevel: /* @__PURE__ */ zod.z.number().min(0).max(100)
15689
+ }), /* @__PURE__ */ zod.z.void(), {
15690
+ kind: "mutation",
15691
+ auth: "protected",
15692
+ actions: [{
15693
+ id: "media.volume",
15694
+ effect: {
15695
+ field: "volumeLevel",
15696
+ fromArg: "volumeLevel"
15697
+ },
15698
+ label: /* @__PURE__ */ require_l10n.t("Set volume", "Imposta il volume"),
15699
+ phrase: /* @__PURE__ */ require_l10n.t("Set the volume of {device} to {volumeLevel}", "Imposta il volume di {device} al {volumeLevel}"),
15700
+ icon: "volume-2",
15701
+ openArgs: [{
15702
+ key: "volumeLevel",
15703
+ label: /* @__PURE__ */ require_l10n.t("Volume", "Volume"),
15704
+ offer: {
15705
+ kind: "number",
15706
+ min: 0,
15707
+ max: 100,
15708
+ step: 1,
15709
+ unit: "%"
15710
+ }
15711
+ }]
15712
+ }]
15713
+ }),
15714
+ setMute: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15715
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15716
+ muted: /* @__PURE__ */ zod.z.boolean()
15717
+ }), /* @__PURE__ */ zod.z.void(), {
15718
+ kind: "mutation",
15719
+ auth: "protected",
15720
+ actions: [{
15721
+ id: "media.mute",
15722
+ effect: {
15723
+ field: "isMuted",
15724
+ value: true
15725
+ },
15726
+ label: /* @__PURE__ */ require_l10n.t("Mute", "Silenzia"),
15727
+ phrase: /* @__PURE__ */ require_l10n.t("Mute {device}", "Silenzia {device}"),
15728
+ icon: "volume-x",
15729
+ args: { muted: true }
15730
+ }, {
15731
+ id: "media.unmute",
15732
+ effect: {
15733
+ field: "isMuted",
15734
+ value: false
15735
+ },
15736
+ label: /* @__PURE__ */ require_l10n.t("Unmute", "Riattiva l’audio"),
15737
+ phrase: /* @__PURE__ */ require_l10n.t("Unmute {device}", "Riattiva l’audio di {device}"),
15738
+ icon: "volume-2",
15739
+ args: { muted: false }
15740
+ }]
15741
+ }),
15742
+ setShuffle: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15743
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15744
+ shuffle: /* @__PURE__ */ zod.z.boolean()
15745
+ }), /* @__PURE__ */ zod.z.void(), {
15746
+ kind: "mutation",
15747
+ auth: "protected",
15748
+ actions: [{
15749
+ id: "media.shuffleOn",
15750
+ effect: {
15751
+ field: "shuffle",
15752
+ value: true
15753
+ },
15754
+ label: /* @__PURE__ */ require_l10n.t("Shuffle on", "Riproduzione casuale attiva"),
15755
+ phrase: /* @__PURE__ */ require_l10n.t("Turn on shuffle on {device}", "Attiva la riproduzione casuale su {device}"),
15756
+ icon: "shuffle",
15757
+ args: { shuffle: true }
15758
+ }, {
15759
+ id: "media.shuffleOff",
15760
+ effect: {
15761
+ field: "shuffle",
15762
+ value: false
15763
+ },
15764
+ label: /* @__PURE__ */ require_l10n.t("Shuffle off", "Riproduzione casuale spenta"),
15765
+ phrase: /* @__PURE__ */ require_l10n.t("Turn off shuffle on {device}", "Disattiva la riproduzione casuale su {device}"),
15766
+ icon: "shuffle",
15767
+ args: { shuffle: false }
15768
+ }]
15769
+ }),
15770
+ setRepeat: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15771
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15772
+ repeat: MediaPlayerRepeatSchema
15773
+ }), /* @__PURE__ */ zod.z.void(), {
15774
+ kind: "mutation",
15775
+ auth: "protected",
15776
+ actions: [{
15777
+ id: "media.repeat",
15778
+ effect: {
15779
+ field: "repeat",
15780
+ fromArg: "repeat"
15781
+ },
15782
+ label: /* @__PURE__ */ require_l10n.t("Set repeat", "Imposta la ripetizione"),
15783
+ phrase: /* @__PURE__ */ require_l10n.t("Set repeat on {device} to {repeat}", "Imposta la ripetizione di {device} su {repeat}"),
15784
+ icon: "repeat",
15785
+ openArgs: [{
15786
+ key: "repeat",
15787
+ label: /* @__PURE__ */ require_l10n.t("Repeat", "Ripetizione"),
15788
+ offer: {
15789
+ kind: "enum",
15790
+ values: [
15791
+ {
15792
+ value: "off",
15793
+ label: /* @__PURE__ */ require_l10n.t("Off", "Disattivata")
15794
+ },
15795
+ {
15796
+ value: "all",
15797
+ label: /* @__PURE__ */ require_l10n.t("All", "Tutti i brani")
15798
+ },
15799
+ {
15800
+ value: "one",
15801
+ label: /* @__PURE__ */ require_l10n.t("One track", "Un brano")
15802
+ }
15803
+ ]
15804
+ }
15643
15805
  }]
15644
- },
15645
- {
15646
- id: "rainWeekly",
15647
- cardinality: "scalar",
15648
- deviceTypes: [require_device_type.DeviceType.WeatherStation],
15649
- apply: "add",
15650
- vocabularyCap: "weather-station",
15651
- vocabularyStateField: "rainWeekly",
15652
- sources: [{
15653
- kind: "numeric",
15654
- requiredUnit: "mm",
15655
- transformKinds: ["identity"],
15656
- transforms: [{ kind: "identity" }]
15657
- }],
15658
- sourceReport: { status: "assignment-status" },
15659
- advancedExpression: false,
15660
- path: "rainWeekly",
15661
- valueKind: "number",
15662
- nullable: true,
15663
- companions: [{
15664
- kind: "clock",
15665
- path: "lastFetchedAt",
15666
- when: "add"
15806
+ }]
15807
+ }),
15808
+ selectSource: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15809
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15810
+ source: /* @__PURE__ */ zod.z.string().min(1)
15811
+ }), /* @__PURE__ */ zod.z.void(), {
15812
+ kind: "mutation",
15813
+ auth: "protected",
15814
+ actions: [{
15815
+ id: "media.source",
15816
+ effect: {
15817
+ field: "source",
15818
+ fromArg: "source"
15819
+ },
15820
+ label: /* @__PURE__ */ require_l10n.t("Select source", "Scegli la sorgente"),
15821
+ phrase: /* @__PURE__ */ require_l10n.t("Switch {device} to {source}", "Passa {device} alla sorgente {source}"),
15822
+ icon: "cast",
15823
+ openArgs: [{
15824
+ key: "source",
15825
+ label: /* @__PURE__ */ require_l10n.t("Source", "Sorgente"),
15826
+ offer: {
15827
+ kind: "dynamic",
15828
+ from: "status",
15829
+ field: "availableSources"
15830
+ }
15667
15831
  }]
15668
- },
15669
- {
15670
- id: "rainMonthly",
15671
- cardinality: "scalar",
15672
- deviceTypes: [require_device_type.DeviceType.WeatherStation],
15673
- apply: "add",
15674
- vocabularyCap: "weather-station",
15675
- vocabularyStateField: "rainMonthly",
15676
- sources: [{
15677
- kind: "numeric",
15678
- requiredUnit: "mm",
15679
- transformKinds: ["identity"],
15680
- transforms: [{ kind: "identity" }]
15681
- }],
15682
- sourceReport: { status: "assignment-status" },
15683
- advancedExpression: false,
15684
- path: "rainMonthly",
15685
- valueKind: "number",
15686
- nullable: true,
15687
- companions: [{
15688
- kind: "clock",
15689
- path: "lastFetchedAt",
15690
- when: "add"
15832
+ }]
15833
+ }),
15834
+ seek: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15835
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15836
+ position: /* @__PURE__ */ zod.z.number().int().nonnegative()
15837
+ }), /* @__PURE__ */ zod.z.void(), {
15838
+ kind: "mutation",
15839
+ auth: "protected",
15840
+ actions: [{
15841
+ id: "media.seek",
15842
+ label: /* @__PURE__ */ require_l10n.t("Seek", "Vai al punto"),
15843
+ phrase: /* @__PURE__ */ require_l10n.t("Move {device} to {position}", "Porta {device} al punto {position}"),
15844
+ icon: "fast-forward",
15845
+ openArgs: [{
15846
+ key: "position",
15847
+ label: /* @__PURE__ */ require_l10n.t("Position", "Posizione"),
15848
+ offer: {
15849
+ kind: "number",
15850
+ min: 0,
15851
+ step: 1e3,
15852
+ unit: "ms"
15853
+ }
15691
15854
  }]
15692
- },
15693
- {
15694
- id: "rainYearly",
15695
- cardinality: "scalar",
15696
- deviceTypes: [require_device_type.DeviceType.WeatherStation],
15697
- apply: "add",
15698
- vocabularyCap: "weather-station",
15699
- vocabularyStateField: "rainYearly",
15700
- sources: [{
15701
- kind: "numeric",
15702
- requiredUnit: "mm",
15703
- transformKinds: ["identity"],
15704
- transforms: [{ kind: "identity" }]
15705
- }],
15706
- sourceReport: { status: "assignment-status" },
15707
- advancedExpression: false,
15708
- path: "rainYearly",
15709
- valueKind: "number",
15710
- nullable: true,
15711
- companions: [{
15712
- kind: "clock",
15713
- path: "lastFetchedAt",
15714
- when: "add"
15855
+ }]
15856
+ }),
15857
+ playMedia: /* @__PURE__ */ require_capability_definition.optionalMethod(/* @__PURE__ */ zod.z.object({
15858
+ deviceId: /* @__PURE__ */ zod.z.number().int().nonnegative(),
15859
+ /** Media identifier / URL. */
15860
+ mediaId: /* @__PURE__ */ zod.z.string().min(1),
15861
+ /** Media kind (`music`, `tvshow`, `movie`, `app`, …) — provider
15862
+ * passes it through to the upstream service. */
15863
+ mediaType: /* @__PURE__ */ zod.z.string().min(1)
15864
+ }), /* @__PURE__ */ zod.z.void(), {
15865
+ kind: "mutation",
15866
+ auth: "protected",
15867
+ actions: [{
15868
+ id: "media.playMedia",
15869
+ label: /* @__PURE__ */ require_l10n.t("Play media", "Riproduci un contenuto"),
15870
+ phrase: /* @__PURE__ */ require_l10n.t("Play {mediaId} on {device}", "Riproduci {mediaId} su {device}"),
15871
+ icon: "music",
15872
+ openArgs: [{
15873
+ key: "mediaId",
15874
+ label: /* @__PURE__ */ require_l10n.t("Media", "Contenuto"),
15875
+ offer: { kind: "text" }
15876
+ }, {
15877
+ key: "mediaType",
15878
+ label: /* @__PURE__ */ require_l10n.t("Media type", "Tipo di contenuto"),
15879
+ offer: { kind: "text" }
15715
15880
  }]
15716
- }
15717
- ],
15718
- overridable: [
15719
- {
15720
- path: "temperature",
15721
- by: "temperature"
15722
- },
15723
- {
15724
- path: "humidity",
15725
- by: "humidity"
15726
- },
15727
- {
15728
- path: "pressure",
15729
- by: "pressure"
15730
- },
15731
- {
15732
- path: "windSpeed",
15733
- by: "windSpeed"
15734
- },
15735
- {
15736
- path: "windGust",
15737
- by: "windGust"
15738
- },
15739
- {
15740
- path: "windBearing",
15741
- by: "windBearing"
15742
- },
15743
- {
15744
- path: "rainRate",
15745
- by: "rainRate"
15746
- },
15747
- {
15748
- path: "rainDaily",
15749
- by: "rainDaily"
15750
- },
15751
- {
15752
- path: "rainEvent",
15753
- by: "rainEvent"
15754
- },
15755
- {
15756
- path: "uv",
15757
- by: "uv"
15758
- },
15759
- {
15760
- path: "solarRadiation",
15761
- by: "solarRadiation"
15762
- },
15763
- {
15764
- path: "dewPoint",
15765
- by: "dewPoint"
15766
- },
15767
- {
15768
- path: "feelsLike",
15769
- by: "feelsLike"
15770
- },
15771
- {
15772
- path: "vpd",
15773
- by: "vpd"
15774
- },
15775
- {
15776
- path: "windGustMax",
15777
- by: "windGustMax"
15778
- },
15779
- {
15780
- path: "windBearingAvg",
15781
- by: "windBearingAvg"
15782
- },
15881
+ }]
15882
+ })
15883
+ },
15884
+ status: {
15885
+ schema: MediaPlayerStatusSchema,
15886
+ kind: "push"
15887
+ },
15888
+ /**
15889
+ * Runtime-state slice — mirrored by the kernel. UI players read the
15890
+ * full slice for live now-playing, volume, and progress updates
15891
+ * without polling.
15892
+ */
15893
+ runtimeState: MediaPlayerStatusSchema,
15894
+ /**
15895
+ * Runtime-state durability: **session** — a restored transport position describes a playback that stopped when the hub did.
15896
+ *
15897
+ * See `RuntimeStateDurability`. Enforced by
15898
+ * `scripts/check-runtime-state-durability.ts`.
15899
+ */
15900
+ durability: "session",
15901
+ /**
15902
+ * History (D850): volume (a level an operator or an automation sets; the
15903
+ * default 10 s floor folds a slider drag into its end value) and mute.
15904
+ * `position` is not recorded: it moves continuously while playing.
15905
+ */
15906
+ history: { fields: {
15907
+ volumeLevel: {
15908
+ kind: "gauge",
15909
+ unit: "%",
15910
+ deadband: 1
15911
+ },
15912
+ isMuted: { kind: "boolean" }
15913
+ } },
15914
+ vocabulary: {
15915
+ noun: /* @__PURE__ */ require_l10n.t("Media player", "Lettore multimediale"),
15916
+ order: 2060,
15917
+ state: [
15783
15918
  {
15784
- path: "rain24h",
15785
- by: "rain24h"
15919
+ kind: "enum",
15920
+ field: "state",
15921
+ label: /* @__PURE__ */ require_l10n.t("Playback", "Riproduzione"),
15922
+ values: [
15923
+ {
15924
+ value: "off",
15925
+ label: /* @__PURE__ */ require_l10n.t("Off", "Spento"),
15926
+ phrase: /* @__PURE__ */ require_l10n.t("When {device} turns off", "Quando {device} si spegne")
15927
+ },
15928
+ {
15929
+ value: "on",
15930
+ label: /* @__PURE__ */ require_l10n.t("On", "Acceso"),
15931
+ phrase: /* @__PURE__ */ require_l10n.t("When {device} turns on", "Quando {device} si accende")
15932
+ },
15933
+ {
15934
+ value: "idle",
15935
+ label: /* @__PURE__ */ require_l10n.t("Idle", "Inattivo")
15936
+ },
15937
+ {
15938
+ value: "playing",
15939
+ label: /* @__PURE__ */ require_l10n.t("Playing", "In riproduzione"),
15940
+ phrase: /* @__PURE__ */ require_l10n.t("When {device} starts playing", "Quando {device} inizia a riprodurre")
15941
+ },
15942
+ {
15943
+ value: "paused",
15944
+ label: /* @__PURE__ */ require_l10n.t("Paused", "In pausa"),
15945
+ phrase: /* @__PURE__ */ require_l10n.t("When {device} is paused", "Quando {device} va in pausa")
15946
+ },
15947
+ {
15948
+ value: "buffering",
15949
+ label: /* @__PURE__ */ require_l10n.t("Buffering", "In caricamento")
15950
+ },
15951
+ {
15952
+ value: "standby",
15953
+ label: /* @__PURE__ */ require_l10n.t("Standby", "In standby")
15954
+ }
15955
+ ],
15956
+ icon: "music"
15786
15957
  },
15787
15958
  {
15788
- path: "rainWeekly",
15789
- by: "rainWeekly"
15959
+ kind: "numeric",
15960
+ field: "volumeLevel",
15961
+ quantity: /* @__PURE__ */ require_l10n.t("the volume", "il volume"),
15962
+ label: /* @__PURE__ */ require_l10n.t("Volume", "Volume"),
15963
+ unit: "%",
15964
+ icon: "volume-2"
15790
15965
  },
15791
15966
  {
15792
- path: "rainMonthly",
15793
- by: "rainMonthly"
15967
+ kind: "boolean",
15968
+ field: "isMuted",
15969
+ label: /* @__PURE__ */ require_l10n.t("Muted", "Silenziato"),
15970
+ whenTrue: /* @__PURE__ */ require_l10n.t("When {device} is muted", "Quando {device} viene silenziato"),
15971
+ whenFalse: /* @__PURE__ */ require_l10n.t("When {device} is unmuted", "Quando l’audio di {device} torna attivo"),
15972
+ icon: "volume-x"
15794
15973
  },
15795
15974
  {
15796
- path: "rainYearly",
15797
- by: "rainYearly"
15975
+ kind: "value",
15976
+ field: "source",
15977
+ label: /* @__PURE__ */ require_l10n.t("Source", "Sorgente"),
15978
+ offer: {
15979
+ kind: "dynamic",
15980
+ from: "status",
15981
+ field: "availableSources"
15982
+ },
15983
+ icon: "cast"
15798
15984
  }
15799
15985
  ]
15800
15986
  }
15801
15987
  };
15802
- /**
15803
- * Unit meta on runtime-state fields. The composed-device row reads this;
15804
- * it is not an override list (D944).
15805
- */
15806
- var CAP_RUNTIME_FIELD_UNITS = {
15807
- "ambient-light-sensor": { illuminance: "lx" },
15808
- "battery": {
15809
- level: "%",
15810
- voltage: "V",
15811
- temperatureC: "°C"
15812
- },
15813
- "humidity-sensor": { humidity: "%" },
15814
- "power-meter": {
15815
- power: "W",
15816
- deliveredPower: "W",
15817
- energy: "kWh",
15818
- voltage: "V",
15819
- current: "A"
15820
- },
15821
- "temperature-sensor": { temperature: "°C" }
15822
- };
15823
15988
  //#endregion
15824
15989
  //#region ../types/dist/esm/composition/expression-kinds.mjs
15825
15990
  var NUMBER = {
@@ -16706,7 +16871,9 @@ var POWER_SOURCE_DEVICE_TYPES = [
16706
16871
  require_device_type.DeviceType.Fan,
16707
16872
  require_device_type.DeviceType.Humidifier,
16708
16873
  require_device_type.DeviceType.Climate,
16709
- require_device_type.DeviceType.WaterHeater
16874
+ require_device_type.DeviceType.WaterHeater,
16875
+ require_device_type.DeviceType.Light,
16876
+ require_device_type.DeviceType.Switch
16710
16877
  ];
16711
16878
  var powerSourceCustomize = {
16712
16879
  version: 1,
@@ -17090,6 +17257,46 @@ function nativeReplaceOrBlock(refusal, probed) {
17090
17257
  }
17091
17258
  var customizeCatalog = CAP_CUSTOMIZE_CATALOG;
17092
17259
  /**
17260
+ * A `fields` feature of the same cap that writes a root the link serves: two
17261
+ * writers for one field, refused by name (D1076).
17262
+ */
17263
+ function overlapProblems(composition, feature, at, served) {
17264
+ return composition.features.flatMap((other, index) => {
17265
+ if (other.kind !== "fields" || other.cap !== feature.cap || !require_error_cap.compositionFeatureEnabled(other)) return [];
17266
+ const paths = Object.keys(other.fields).filter((path) => served.has(path.split(".")[0] ?? path));
17267
+ return paths.length === 0 ? [] : [require_error_cap.problem("link-overlaps-fields", `features[${index}]`, `\`${other.cap}\` is written by this feature (${paths.join(", ")}) and served by the link \`${feature.linkId}\` (${at}) — one writer per field`)];
17268
+ });
17269
+ }
17270
+ /**
17271
+ * A whole-capability link (D1076). A `project` link is expanded to the field
17272
+ * claims the composer already runs; a `reference` link writes nothing. The
17273
+ * refusals are named, and the source is judged by `validateComposition`.
17274
+ */
17275
+ function planCapLinkFeature(composition, feature, index, planTarget, lookupCap, servedCommands) {
17276
+ const at = `features[${index}]`;
17277
+ const link = declaredCapLink(feature.cap, feature.linkId);
17278
+ if (link === void 0) return require_error_cap.refused(require_error_cap.problem("link-undeclared", at, `\`${feature.cap}\` declares no link \`${feature.linkId}\``));
17279
+ if (planTarget.kind !== "existing") return require_error_cap.refused(require_error_cap.problem("reserved-variant", at, "a capability link customizes an EXISTING device"));
17280
+ const cap = composableCap(feature, at, lookupCap);
17281
+ if ("code" in cap) return require_error_cap.refused(cap);
17282
+ const deviceType = planTarget.found.type;
17283
+ if (link.deviceTypes !== void 0 && !link.deviceTypes.includes(deviceType)) return require_error_cap.refused(require_error_cap.problem("wrong-device-type", at, `the link \`${link.id}\` of \`${feature.cap}\` is not offered on a \`${deviceType}\` device`));
17284
+ if (link.mode === "project" && isNativeCap(planTarget.found, feature.cap)) return require_error_cap.refused(require_error_cap.problem("link-native", at, `link-native: device ${planTarget.found.deviceId} serves \`${feature.cap}\` itself — a project link only adds it (D944)`));
17285
+ const overlap = overlapProblems(composition, feature, at, new Set(link.mode === "project" ? capLinkServedFields(link, cap.fields.keys()) : link.slot === void 0 ? [] : [link.slot]));
17286
+ if (overlap.length > 0) return require_error_cap.refused(...overlap);
17287
+ const expanded = require_error_cap.compositionFeatureEnabled(feature) ? expandCapLink(feature, link, cap.fields.keys()) : null;
17288
+ if (expanded === null) return {
17289
+ problems: [],
17290
+ fields: [],
17291
+ features: [],
17292
+ events: []
17293
+ };
17294
+ return planFeature(expanded, index, {
17295
+ mode: "add",
17296
+ deviceType
17297
+ }, lookupCap, servedCommands);
17298
+ }
17299
+ /**
17093
17300
  * D984: a feature may replace a NATIVE cap only when every field it writes is
17094
17301
  * one the cap lists in `overridable` — the cap's own typed allow-list, read from
17095
17302
  * the catalog. No items, no commands, no field outside the list; no cap is named.
@@ -17134,6 +17341,7 @@ function planComposition(composition, lookupCap, target) {
17134
17341
  const results = composition.features.map((feature, index) => {
17135
17342
  const at = `features[${index}]`;
17136
17343
  if (feature.kind === "passthrough") return require_error_cap.refused(require_error_cap.problem("reserved-variant", at, `whole-capability passthrough of \`${feature.cap}\` arrives in slice 3`));
17344
+ if (feature.kind === "capLink") return planCapLinkFeature(composition, feature, index, planTarget, lookupCap, servedCommands);
17137
17345
  const featureTarget = featureTargetOf(planTarget, feature, at);
17138
17346
  if (isPlanProblem(featureTarget)) {
17139
17347
  if (!require_error_cap.compositionFeatureEnabled(feature) || planTarget.kind !== "existing") return {
@@ -17164,7 +17372,11 @@ function planComposition(composition, lookupCap, target) {
17164
17372
  };
17165
17373
  }
17166
17374
  function compositionSourceRefs(composition) {
17167
- const refs = composition.features.flatMap((f) => require_error_cap.compositionFeatureEnabled(f) && f.kind === "fields" ? require_error_cap.featureSources(f).flatMap(require_error_cap.fieldReads).map((r) => r.source) : []);
17375
+ const refs = composition.features.flatMap((f) => {
17376
+ if (!require_error_cap.compositionFeatureEnabled(f)) return [];
17377
+ if (f.kind === "capLink") return [f.source];
17378
+ return f.kind === "fields" ? require_error_cap.featureSources(f).flatMap(require_error_cap.fieldReads).map((r) => r.source) : [];
17379
+ });
17168
17380
  return [...new Map([...refs, ...forwardSourceRefs(composition)].map((r) => [require_error_cap.compositionSourceKey(r), r])).values()];
17169
17381
  }
17170
17382
  /**
@@ -17227,6 +17439,24 @@ function liveKindProblems(field, read, desc, at) {
17227
17439
  if (live === void 0 || live === accepted) return [];
17228
17440
  return [require_error_cap.problem("source-kind-mismatch", at, `\`${read.cap}.${read.fieldPath}\` of device ${desc.deviceId} reads a ${live} now; \`${field.cap}.${field.path}\` takes a ${accepted}`)];
17229
17441
  }
17442
+ /**
17443
+ * The source of an enabled capLink must exist, be readable and bind the link's
17444
+ * `sourceCap` (judged through its bindings, D12). A `project` link's expanded
17445
+ * fields are NOT judged a second time: the verdict is this one.
17446
+ */
17447
+ function capLinkSourceProblems(composition, sources) {
17448
+ return composition.features.flatMap((feature, index) => {
17449
+ if (feature.kind !== "capLink" || !require_error_cap.compositionFeatureEnabled(feature)) return [];
17450
+ const link = declaredCapLink(feature.cap, feature.linkId);
17451
+ if (link === void 0) return [];
17452
+ const at = `features[${index}].source`;
17453
+ const key = require_error_cap.compositionSourceKey(feature.source);
17454
+ const desc = sources.get(key);
17455
+ if (desc === void 0 || desc.kind === "unreadable") return [require_error_cap.problem("source-unreadable", at, `could not read source \`${key}\` (${desc === void 0 ? "it was not read" : desc.error}) — the save is refused rather than stored unchecked`)];
17456
+ if (desc.kind === "absent") return [require_error_cap.problem("source-missing", at, `source \`${key}\` does not exist`)];
17457
+ return desc.caps.has(link.sourceCap) ? [] : [require_error_cap.problem("link-source-cap-missing", at, `source \`${key}\` (device ${desc.deviceId}) has no \`${link.sourceCap}\``)];
17458
+ });
17459
+ }
17230
17460
  function sourceProblems(fields, ctx, self) {
17231
17461
  const selfKey = require_error_cap.compositionSourceKey(self.ref);
17232
17462
  return fields.flatMap((field) => field.reads.flatMap((read) => {
@@ -17292,11 +17522,17 @@ function unreadDeviceOf(nodes, unread) {
17292
17522
  * `compositionEdges` throw `CompositionGraphError` — refused BY NAME as
17293
17523
  * `duplicate-target` (D391, D663) instead of escaping as an uncaught throw.
17294
17524
  */
17525
+ /** The top-level state fields of a cap, or null when the lookup does not know it. */
17526
+ function topLevelFieldsOf(cap, lookupCap) {
17527
+ const state = lookupCap(cap)?.runtimeState;
17528
+ return state === void 0 ? null : [...describeTopLevelStateFields(state).keys()];
17529
+ }
17295
17530
  function cycleProblems(composition, ctx, fields, self) {
17531
+ const lookupCap = ctx.lookupCap;
17296
17532
  const candidate = {
17297
17533
  blockId: ctx.blockId ?? "(unsaved)",
17298
17534
  target: self.ref,
17299
- composition,
17535
+ composition: expandCapLinks(composition, (cap) => topLevelFieldsOf(cap, lookupCap)),
17300
17536
  replaced: self.replaced
17301
17537
  };
17302
17538
  const candidateKey = require_error_cap.compositionSourceKey(candidate.target);
@@ -17314,6 +17550,7 @@ function cycleProblems(composition, ctx, fields, self) {
17314
17550
  }
17315
17551
  function validateComposition(composition, ctx) {
17316
17552
  const plan = planComposition(composition, ctx.lookupCap, ctx.target ?? void 0);
17553
+ const linkIndexes = new Set(composition.features.flatMap((f, index) => f.kind === "capLink" ? [index] : []));
17317
17554
  const self = candidateSelf(composition, ctx, plan);
17318
17555
  const refusedFeatures = plan.problems.filter((item) => item.code === "native-capability-replace").map((item) => item.path);
17319
17556
  const cycles = cycleProblems(composition, ctx, plan.fields, self).filter((item) => {
@@ -17327,7 +17564,8 @@ function validateComposition(composition, ctx) {
17327
17564
  }]] : []));
17328
17565
  const problems = [
17329
17566
  ...plan.problems,
17330
- ...sourceProblems(plan.fields, ctx, self),
17567
+ ...sourceProblems(plan.fields.filter((field) => !linkIndexes.has(field.featureIndex)), ctx, self),
17568
+ ...capLinkSourceProblems(composition, ctx.sources),
17331
17569
  ...forwardSourceProblems(composition, ctx.sources),
17332
17570
  ...cycles,
17333
17571
  ...helperSaveProblems(composition, facts),
@@ -17945,6 +18183,25 @@ var coreBlocksCapability = {
17945
18183
  stableId: /* @__PURE__ */ zod.z.string().min(1)
17946
18184
  }), CompositionCustomizationReadSchema, { auth: "admin" }),
17947
18185
  /**
18186
+ * The whole-capability links of one device (D1076), for the energy card
18187
+ * and the Customize table. Admin today, like `getCustomization` (the role
18188
+ * baseline); a viewer role for the card is a later decision. A link
18189
+ * carries no stored value, only the pair it joins. `not-loaded`
18190
+ * until the compositions have been read, never an empty list (D315).
18191
+ */
18192
+ getCapLinks: /* @__PURE__ */ require_capability_definition.method(/* @__PURE__ */ zod.z.object({ deviceId: /* @__PURE__ */ zod.z.number().int() }), CapLinksReadSchema, { auth: "protected" }),
18193
+ /**
18194
+ * D1076: turn the plain per-field identity links of one cap, from one
18195
+ * source device, into ONE `capLink`. Mixed groups are reported and left
18196
+ * alone; a feature an identity link stamped (D1063) is skipped; a second
18197
+ * run changes nothing. Bounded by the stored customizations; a dry run
18198
+ * writes nothing.
18199
+ */
18200
+ migrateCapLinks: /* @__PURE__ */ require_capability_definition.method(MigrateCapLinksInputSchema, MigrateCapLinksReportSchema, {
18201
+ kind: "mutation",
18202
+ auth: "admin"
18203
+ }),
18204
+ /**
17948
18205
  * The capabilities a composition may BUILD on a device of `deviceType`
17949
18206
  * (a new device, or added to an existing one), with their fields — the
17950
18207
  * editor's feature list and the presets' availability (G2, D676). Built
@@ -18353,6 +18610,12 @@ Object.defineProperty(exports, "canonicalStoredStepTargets", {
18353
18610
  return canonicalStoredStepTargets;
18354
18611
  }
18355
18612
  });
18613
+ Object.defineProperty(exports, "capLinkServedFields", {
18614
+ enumerable: true,
18615
+ get: function() {
18616
+ return capLinkServedFields;
18617
+ }
18618
+ });
18356
18619
  Object.defineProperty(exports, "commandedMethods", {
18357
18620
  enumerable: true,
18358
18621
  get: function() {
@@ -18425,6 +18688,12 @@ Object.defineProperty(exports, "customKeyOfRole", {
18425
18688
  return customKeyOfRole;
18426
18689
  }
18427
18690
  });
18691
+ Object.defineProperty(exports, "declaredCapLink", {
18692
+ enumerable: true,
18693
+ get: function() {
18694
+ return declaredCapLink;
18695
+ }
18696
+ });
18428
18697
  Object.defineProperty(exports, "describeComposableCaps", {
18429
18698
  enumerable: true,
18430
18699
  get: function() {
@@ -18461,6 +18730,12 @@ Object.defineProperty(exports, "eventLeafIdAt", {
18461
18730
  return eventLeafIdAt;
18462
18731
  }
18463
18732
  });
18733
+ Object.defineProperty(exports, "expandCapLinks", {
18734
+ enumerable: true,
18735
+ get: function() {
18736
+ return expandCapLinks;
18737
+ }
18738
+ });
18464
18739
  Object.defineProperty(exports, "expressionContainsBuiltinCall", {
18465
18740
  enumerable: true,
18466
18741
  get: function() {
@@ -18623,6 +18898,12 @@ Object.defineProperty(exports, "powerSourceLinkOfComposition", {
18623
18898
  return powerSourceLinkOfComposition;
18624
18899
  }
18625
18900
  });
18901
+ Object.defineProperty(exports, "projectCapLinkOf", {
18902
+ enumerable: true,
18903
+ get: function() {
18904
+ return projectCapLinkOf;
18905
+ }
18906
+ });
18626
18907
  Object.defineProperty(exports, "readFault", {
18627
18908
  enumerable: true,
18628
18909
  get: function() {
@@ -18683,6 +18964,12 @@ Object.defineProperty(exports, "toTimings", {
18683
18964
  return toTimings;
18684
18965
  }
18685
18966
  });
18967
+ Object.defineProperty(exports, "topLevelFieldsOf", {
18968
+ enumerable: true,
18969
+ get: function() {
18970
+ return topLevelFieldsOf;
18971
+ }
18972
+ });
18686
18973
  Object.defineProperty(exports, "unwrapSchema", {
18687
18974
  enumerable: true,
18688
18975
  get: function() {