@camstack/server 1.2.731 → 1.2.732

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 (101) hide show
  1. package/CHANGELOG.md +7 -0
  2. package/dist/api/core/cap-providers.js +1 -0
  3. package/dist/api/core/logging-settings.js +88 -1
  4. package/dist/api/trpc/generated-cap-routers.js +49 -0
  5. package/dist/core/addon/addon-registry.service.js +61 -59
  6. package/package.json +14 -19
  7. package/system/dist/addon-runner.js +82911 -12
  8. package/system/dist/addon-runner.mjs +82910 -11
  9. package/system/dist/addon-utils.mjs +1 -1
  10. package/system/dist/{agent-https-AJPmB73W.mjs → agent-https-CDtAIEne.mjs} +1 -1
  11. package/system/dist/{agent-https-CLJhq0GZ.js → agent-https-DKMO-__h.js} +1 -1
  12. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  13. package/system/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +4 -4
  14. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  15. package/system/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +5 -5
  16. package/system/dist/builtins/alerts/alerts.addon.js +1 -1
  17. package/system/dist/builtins/alerts/alerts.addon.mjs +1 -1
  18. package/system/dist/builtins/autotrack/index.js +1 -1
  19. package/system/dist/builtins/autotrack/index.mjs +1 -1
  20. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +2 -2
  21. package/system/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +5 -5
  22. package/system/dist/builtins/calendars/calendars.addon.js +1 -1
  23. package/system/dist/builtins/calendars/calendars.addon.mjs +1 -1
  24. package/system/dist/builtins/camera-grid/index.js +1 -1
  25. package/system/dist/builtins/camera-grid/index.mjs +1 -1
  26. package/system/dist/builtins/composer/composer.addon.js +3 -3
  27. package/system/dist/builtins/composer/composer.addon.mjs +3 -3
  28. package/system/dist/builtins/console-logging/index.js +1 -1
  29. package/system/dist/builtins/console-logging/index.mjs +1 -1
  30. package/system/dist/builtins/core-blocks/core-blocks.addon.js +2 -2
  31. package/system/dist/builtins/core-blocks/core-blocks.addon.mjs +2 -2
  32. package/system/dist/builtins/device-history/device-history.addon.js +2 -2
  33. package/system/dist/builtins/device-history/device-history.addon.mjs +2 -2
  34. package/system/dist/builtins/device-manager/device-manager.addon.js +220 -16
  35. package/system/dist/builtins/device-manager/device-manager.addon.mjs +220 -16
  36. package/system/dist/builtins/device-manager/discovery-proposal-service.d.ts +38 -0
  37. package/system/dist/builtins/device-manager/discovery-proposal-store.d.ts +28 -0
  38. package/system/dist/builtins/device-manager/record-kinds.d.ts +2 -1
  39. package/system/dist/builtins/hub-forwarder/index.js +1 -1
  40. package/system/dist/builtins/hub-forwarder/index.mjs +1 -1
  41. package/system/dist/builtins/keychain/index.js +3 -3
  42. package/system/dist/builtins/keychain/index.mjs +3 -3
  43. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  44. package/system/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  45. package/system/dist/builtins/local-auth/local-auth.addon.js +2 -2
  46. package/system/dist/builtins/local-auth/local-auth.addon.mjs +5 -5
  47. package/system/dist/builtins/local-network/local-network.addon.d.ts +10 -0
  48. package/system/dist/builtins/local-network/local-network.addon.js +250 -181
  49. package/system/dist/builtins/local-network/local-network.addon.mjs +244 -175
  50. package/system/dist/builtins/local-network/passive/discovery-watcher.d.ts +60 -0
  51. package/system/dist/builtins/local-network/passive/passive-io-node.d.ts +2 -0
  52. package/system/dist/builtins/local-network/passive/passive-packets.d.ts +10 -0
  53. package/system/dist/builtins/loki-logging/index.js +1 -1
  54. package/system/dist/builtins/loki-logging/index.mjs +1 -1
  55. package/system/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  56. package/system/dist/builtins/native-metrics/native-metrics.addon.mjs +10 -10
  57. package/system/dist/builtins/platform-probe/index.js +1 -1
  58. package/system/dist/builtins/platform-probe/index.mjs +10 -10
  59. package/system/dist/builtins/record-entries/index.js +1 -1
  60. package/system/dist/builtins/record-entries/index.mjs +1 -1
  61. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  62. package/system/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  63. package/system/dist/builtins/snapshot/index.js +1 -1
  64. package/system/dist/builtins/snapshot/index.mjs +1 -1
  65. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  66. package/system/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +20 -20
  67. package/system/dist/builtins/sqlite-storage/index.js +1 -1
  68. package/system/dist/builtins/sqlite-storage/index.mjs +1 -1
  69. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.js +2 -2
  70. package/system/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +2 -2
  71. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  72. package/system/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  73. package/system/dist/builtins/system-config/system-config.addon.js +3 -3
  74. package/system/dist/builtins/system-config/system-config.addon.mjs +115 -115
  75. package/system/dist/builtins/winston-logging/index.js +1 -1
  76. package/system/dist/builtins/winston-logging/index.mjs +1 -1
  77. package/system/dist/{composition-sources-D-S2hhdw.mjs → composition-sources-Ca7JEbmu.mjs} +1 -1
  78. package/system/dist/{composition-sources-BNBlJAgu.js → composition-sources-UQohOHgd.js} +1 -1
  79. package/system/dist/{constants-CKwdQTnw.js → constants-CLA4ogvA.js} +1 -1
  80. package/system/dist/{constants-DmithOex.mjs → constants-iG57sUNp.mjs} +1 -1
  81. package/system/dist/{coral-accelerators-BW3OcrLD.mjs → coral-accelerators-DBlgWB8k.mjs} +6 -6
  82. package/system/dist/{custom-action-registry-BIJZBObd.mjs → custom-action-registry-oHl1xltx.mjs} +37 -37
  83. package/system/dist/{device-ca-D-Cvxobt.mjs → device-ca--iHw76cR.mjs} +1 -1
  84. package/system/dist/{device-ca-TbdQfW4d.js → device-ca-BUcHAAew.js} +1 -1
  85. package/system/dist/{dist-yrk6fm65.mjs → dist-C_cZ9rGK.mjs} +230 -3
  86. package/system/dist/{dist-dQKZfa3-.js → dist-qO48FNMZ.js} +253 -2
  87. package/system/dist/dns-wire-CHXO1qSl.js +199 -0
  88. package/system/dist/dns-wire-DcL6a0L-.mjs +170 -0
  89. package/system/dist/file-host-worker.js +1 -1
  90. package/system/dist/file-host-worker.mjs +1 -1
  91. package/system/dist/{hub-mdns-ciao-Cae5VWUc.mjs → hub-mdns-ciao-9wPOmsXd.mjs} +2 -2
  92. package/system/dist/{hub-mdns-ciao-DP3_GNZw.js → hub-mdns-ciao-DDmMPZCN.js} +2 -2
  93. package/system/dist/index.js +24 -7
  94. package/system/dist/index.mjs +235 -218
  95. package/system/dist/{restore-archive-BJ5gxMvf.mjs → restore-archive-BHVjOlza.mjs} +94 -94
  96. package/system/dist/{restore-archive-X9c_wEBY.js → restore-archive-Cravj5LG.js} +1 -1
  97. package/system/dist/{retention-DRT2wUyB.js → retention-B_eloRtb.js} +1 -1
  98. package/system/dist/{retention-DBrdAv12.mjs → retention-C_9dxCQn.mjs} +1 -1
  99. package/system/dist/{wal-maintenance-hsgNGrjh.js → wal-maintenance-CfKeIQAG.js} +0 -0
  100. package/system/dist/{wal-maintenance-Bi4yImEY.mjs → wal-maintenance-Dw7rplkv.mjs} +0 -0
  101. package/system/package.json +1 -1
@@ -14160,6 +14160,81 @@ var StorageLocationDeclarationSchema = zod.z.object({
14160
14160
  "backup"
14161
14161
  ]).optional()
14162
14162
  });
14163
+ /** Every debug channel's name starts with this; the ring denies it by default. */
14164
+ var DEBUG_CHANNEL_PREFIX = "debug.";
14165
+ function isDebugChannelName(name) {
14166
+ return name.startsWith(DEBUG_CHANNEL_PREFIX);
14167
+ }
14168
+ /**
14169
+ * Who is watching what, in THIS process. In-memory, moved off the log path.
14170
+ *
14171
+ * `active` is a plain boolean FIELD, read first: with no watch anywhere, a
14172
+ * `ctx.debug` call is one load and one branch.
14173
+ */
14174
+ var DebugInterest = class {
14175
+ active = false;
14176
+ windows = /* @__PURE__ */ new Map();
14177
+ /**
14178
+ * Replace the interest with the FULL set of windows. Non-debug windows are
14179
+ * ignored and an absent one is dropped, so a lost disarm cannot leave a
14180
+ * channel running.
14181
+ */
14182
+ apply(windows, nowMs) {
14183
+ this.windows.clear();
14184
+ for (const window of windows) {
14185
+ if (!isDebugChannelName(window.channel) || window.armedUntilMs <= nowMs) continue;
14186
+ const ids = window.deviceIds;
14187
+ this.windows.set(window.channel, {
14188
+ untilMs: window.armedUntilMs,
14189
+ devices: ids === null || ids.length === 0 ? null : new Set(ids)
14190
+ });
14191
+ }
14192
+ this.active = this.windows.size > 0;
14193
+ }
14194
+ /** Drop what has lapsed. Called on a timer, never from a log path. */
14195
+ tick(nowMs) {
14196
+ const closed = [];
14197
+ for (const [name, window] of this.windows) if (window.untilMs <= nowMs) {
14198
+ this.windows.delete(name);
14199
+ closed.push(name);
14200
+ }
14201
+ this.active = this.windows.size > 0;
14202
+ return closed;
14203
+ }
14204
+ /** `channel` is the full name, `debug.<channel>`. */
14205
+ wants(channel, deviceId) {
14206
+ if (!this.active) return false;
14207
+ const window = this.windows.get(channel);
14208
+ if (window === void 0) return false;
14209
+ return window.devices === null || window.devices.has(deviceId);
14210
+ }
14211
+ };
14212
+ var interestInstance = null;
14213
+ function getDebugInterest() {
14214
+ interestInstance ??= new DebugInterest();
14215
+ return interestInstance;
14216
+ }
14217
+ /**
14218
+ * Build `ctx.debug`. The thunk runs ONLY when somebody watches this
14219
+ * (channel, device) pair, and the line carries `tags: { deviceId }` plus the
14220
+ * `debug.<channel>` name as `logChannel`.
14221
+ */
14222
+ function createDebugEmitter(logger, interest = getDebugInterest()) {
14223
+ return (channel, deviceId, thunk) => {
14224
+ if (!interest.active) return;
14225
+ const name = `${DEBUG_CHANNEL_PREFIX}${channel}`;
14226
+ if (!interest.wants(name, deviceId)) return;
14227
+ const line = thunk();
14228
+ const tags = {
14229
+ deviceId,
14230
+ logChannel: name
14231
+ };
14232
+ logger.info(line.message, line.meta === void 0 ? { tags } : {
14233
+ tags,
14234
+ meta: line.meta
14235
+ });
14236
+ };
14237
+ }
14163
14238
  /**
14164
14239
  * Per-component log CHANNELS — the gate a hot path consults, and the registry
14165
14240
  * an addon declares its channels in.
@@ -14250,8 +14325,18 @@ var LogChannelDescriptorSchema = zod.z.object({
14250
14325
  * the operator narrows to one camera, sees nothing, and concludes the code
14251
14326
  * path was never taken.
14252
14327
  */
14253
- perDevice: zod.z.boolean()
14254
- });
14328
+ perDevice: zod.z.boolean(),
14329
+ /**
14330
+ * What the channel is FOR, so the UI can list the channels an addon offers.
14331
+ *
14332
+ * - `diagnostic` (the default): a per-component diagnostic armed from the
14333
+ * Levels page, emitted at its declared level.
14334
+ * - `debug`: a `debug.<channel>` dump watched live for a short window
14335
+ * (`ctx.debug`). Always per-device, and its lines are denied by the log
14336
+ * ring unless somebody is watching that device.
14337
+ */
14338
+ kind: zod.z.enum(["diagnostic", "debug"]).default("diagnostic")
14339
+ }).refine((d) => d.kind !== "debug" || d.name.startsWith("debug.") && d.perDevice, { message: "a debug channel is named debug.<channel> and is per-device" });
14255
14340
  /**
14256
14341
  * An armed window over one channel, as the document hands it to a mirror.
14257
14342
  *
@@ -56153,6 +56238,45 @@ var deviceProviderCapability = {
56153
56238
  }
56154
56239
  };
56155
56240
  /**
56241
+ * What the passive listener of `local-network` saw on the wire, before any
56242
+ * provider classified it. Device-manager turns an observation into the hits
56243
+ * of the providers whose declared discovery modes it matches.
56244
+ */
56245
+ var DiscoveryObservationSchema = zod.z.discriminatedUnion("kind", [zod.z.object({
56246
+ kind: zod.z.literal("mdns"),
56247
+ /** Normalised DNS-SD service type, e.g. `_esphomelib._tcp`. */
56248
+ serviceType: zod.z.string(),
56249
+ instance: zod.z.string(),
56250
+ host: zod.z.string(),
56251
+ /** The A record address when the announcement carried one. */
56252
+ address: zod.z.string().nullable(),
56253
+ port: zod.z.number().int(),
56254
+ txt: zod.z.record(zod.z.string(), zod.z.string())
56255
+ }), zod.z.object({
56256
+ kind: zod.z.literal("ssdp"),
56257
+ /** Sender address of the datagram. */
56258
+ host: zod.z.string(),
56259
+ port: zod.z.number().int(),
56260
+ /** `NT` of a NOTIFY, `ST` of a search response. */
56261
+ target: zod.z.string(),
56262
+ headers: zod.z.record(zod.z.string(), zod.z.string())
56263
+ })]);
56264
+ var DiscoveryProposalBodySchema = zod.z.object({
56265
+ addonId: zod.z.string(),
56266
+ candidate: DiscoveryCandidateSchema,
56267
+ firstSeenAt: zod.z.number(),
56268
+ lastSeenAt: zod.z.number(),
56269
+ dismissed: zod.z.boolean()
56270
+ });
56271
+ var DiscoveryProposalSchema = zod.z.object({
56272
+ id: zod.z.string(),
56273
+ addonId: zod.z.string(),
56274
+ candidate: DiscoveryCandidateSchema,
56275
+ firstSeenAt: zod.z.number(),
56276
+ lastSeenAt: zod.z.number(),
56277
+ dismissed: zod.z.boolean()
56278
+ });
56279
+ /**
56156
56280
  * Device Manager capability — hub-side singleton that unifies device persistence,
56157
56281
  * live registry access, and all management operations into a single tRPC surface.
56158
56282
  *
@@ -57476,6 +57600,27 @@ var deviceManagerCapability = {
57476
57600
  kind: "mutation",
57477
57601
  auth: "admin"
57478
57602
  }),
57603
+ /** Proposals still worth showing: not dismissed, not adopted, not an integration we own. */
57604
+ listDiscoveryProposals: method(zod.z.object({}), zod.z.object({ proposals: zod.z.array(DiscoveryProposalSchema).readonly() }), { auth: "admin" }),
57605
+ /** Hide a proposal for good; seeing the device again does not bring it back. */
57606
+ dismissDiscoveryProposal: method(zod.z.object({ id: zod.z.string() }), zod.z.object({ dismissed: zod.z.boolean() }), {
57607
+ kind: "mutation",
57608
+ auth: "admin"
57609
+ }),
57610
+ /** Raw passive sightings from `local-network`; classified by the matching providers. */
57611
+ reportDiscoveryObservations: method(zod.z.object({ observations: zod.z.array(DiscoveryObservationSchema).max(512) }), zod.z.object({ proposed: zod.z.number().int() }), {
57612
+ kind: "mutation",
57613
+ auth: "admin"
57614
+ }),
57615
+ /** Run the providers' discovery once and record what it found as proposals. */
57616
+ runDiscoverySweep: method(zod.z.object({}), zod.z.object({
57617
+ providers: zod.z.number().int(),
57618
+ proposed: zod.z.number().int()
57619
+ }), {
57620
+ kind: "mutation",
57621
+ auth: "admin",
57622
+ timeoutMs: 12e4
57623
+ }),
57479
57624
  /** The device type a provider creates via manual add (Camera/Container/Hub),
57480
57625
  * so the Add-Device dialog uses the right type instead of assuming Camera. */
57481
57626
  providerCreationType: method(zod.z.object({ addonId: zod.z.string() }), zod.z.object({ deviceType: zod.z.enum(DeviceType).nullable() }), { auth: "admin" }),
@@ -87028,6 +87173,40 @@ var LoggingSettingsStateSchema = zod.z.object({
87028
87173
  opsLogRetentionDays: zod.z.number().int().min(0),
87029
87174
  persisted: zod.z.boolean()
87030
87175
  });
87176
+ /**
87177
+ * Debug WATCH — a short, per-device window over `debug.<channel>` lines.
87178
+ *
87179
+ * `start` opens (or re-arms) a 10 minute window; `rearm` extends a LIVE one
87180
+ * and never revives a lapsed one; `stop` closes it; `list` only reads. No
87181
+ * chain of re-arms outlives 60 minutes from the first start. The hub holds the
87182
+ * watches in memory and pushes the interest to every node, so a watch lapses
87183
+ * by itself and survives nothing — a restart is a stop.
87184
+ */
87185
+ var DebugWatchInputSchema = zod.z.object({
87186
+ action: zod.z.enum([
87187
+ "list",
87188
+ "start",
87189
+ "rearm",
87190
+ "stop"
87191
+ ]),
87192
+ /** Full channel names, `debug.<channel>`, each declared with `kind: 'debug'`. */
87193
+ channels: zod.z.array(zod.z.string().min(1)).readonly().default([]),
87194
+ /** Numeric device ids. Required (non-empty) for `start`. */
87195
+ deviceIds: zod.z.array(zod.z.number().int()).readonly().default([])
87196
+ });
87197
+ var DebugWatchStateSchema = zod.z.object({
87198
+ channel: zod.z.string(),
87199
+ deviceIds: zod.z.array(zod.z.number().int()).readonly(),
87200
+ startedAtMs: zod.z.number(),
87201
+ untilMs: zod.z.number(),
87202
+ capAtMs: zod.z.number()
87203
+ });
87204
+ var DebugWatchResultSchema = zod.z.object({
87205
+ nowMs: zod.z.number(),
87206
+ watches: zod.z.array(DebugWatchStateSchema).readonly(),
87207
+ /** Channels a `rearm` found already lapsed: nothing was revived. */
87208
+ lapsed: zod.z.array(zod.z.string()).readonly()
87209
+ });
87031
87210
  var systemCapability = {
87032
87211
  name: "system",
87033
87212
  scope: "system",
@@ -87141,6 +87320,14 @@ var systemCapability = {
87141
87320
  setLoggingSettings: method(SetLoggingSettingsInputSchema, LoggingSettingsStateSchema, {
87142
87321
  kind: "mutation",
87143
87322
  auth: "admin"
87323
+ }),
87324
+ /**
87325
+ * Start, re-arm, stop or list the live debug watches. See
87326
+ * {@link DebugWatchInputSchema}.
87327
+ */
87328
+ debugWatch: method(DebugWatchInputSchema, DebugWatchResultSchema, {
87329
+ kind: "mutation",
87330
+ auth: "admin"
87144
87331
  })
87145
87332
  },
87146
87333
  /** BIG PLAN 2: declarative mount hint — read by `@camstack/server/system` `buildCapRouters`. */
@@ -95700,6 +95887,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
95700
95887
  access: "view",
95701
95888
  role: "admin"
95702
95889
  },
95890
+ "deviceManager.dismissDiscoveryProposal": {
95891
+ capName: "device-manager",
95892
+ capScope: "system",
95893
+ addonId: null,
95894
+ access: "create",
95895
+ role: "admin"
95896
+ },
95703
95897
  "deviceManager.enable": {
95704
95898
  capName: "device-manager",
95705
95899
  capScope: "system",
@@ -95882,6 +96076,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
95882
96076
  access: "view",
95883
96077
  role: "viewer"
95884
96078
  },
96079
+ "deviceManager.listDiscoveryProposals": {
96080
+ capName: "device-manager",
96081
+ capScope: "system",
96082
+ addonId: null,
96083
+ access: "view",
96084
+ role: "admin"
96085
+ },
95885
96086
  "deviceManager.listLocationDescriptions": {
95886
96087
  capName: "device-manager",
95887
96088
  capScope: "system",
@@ -96036,6 +96237,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
96036
96237
  access: "create",
96037
96238
  role: "admin"
96038
96239
  },
96240
+ "deviceManager.reportDiscoveryObservations": {
96241
+ capName: "device-manager",
96242
+ capScope: "system",
96243
+ addonId: null,
96244
+ access: "create",
96245
+ role: "admin"
96246
+ },
96039
96247
  "deviceManager.runDeviceAction": {
96040
96248
  capName: "device-manager",
96041
96249
  capScope: "system",
@@ -96043,6 +96251,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
96043
96251
  access: "create",
96044
96252
  role: "admin"
96045
96253
  },
96254
+ "deviceManager.runDiscoverySweep": {
96255
+ capName: "device-manager",
96256
+ capScope: "system",
96257
+ addonId: null,
96258
+ access: "create",
96259
+ role: "admin"
96260
+ },
96046
96261
  "deviceManager.setChildLayout": {
96047
96262
  capName: "device-manager",
96048
96263
  capScope: "system",
@@ -102630,6 +102845,13 @@ var METHOD_ACCESS_MAP = Object.freeze({
102630
102845
  access: "create",
102631
102846
  role: "viewer"
102632
102847
  },
102848
+ "system.debugWatch": {
102849
+ capName: "system",
102850
+ capScope: "system",
102851
+ addonId: null,
102852
+ access: "create",
102853
+ role: "admin"
102854
+ },
102633
102855
  "system.detectSiteLocation": {
102634
102856
  capName: "system",
102635
102857
  capScope: "system",
@@ -106637,6 +106859,11 @@ Object.freeze({
106637
106859
  form: "single",
106638
106860
  optional: false
106639
106861
  }],
106862
+ "system.debugWatch": [{
106863
+ name: "deviceIds",
106864
+ form: "array",
106865
+ optional: true
106866
+ }],
106640
106867
  "tamper.getStatus": [{
106641
106868
  name: "deviceId",
106642
106869
  form: "single",
@@ -109495,6 +109722,12 @@ Object.defineProperty(exports, "DeviceType", {
109495
109722
  return DeviceType;
109496
109723
  }
109497
109724
  });
109725
+ Object.defineProperty(exports, "DiscoveryProposalBodySchema", {
109726
+ enumerable: true,
109727
+ get: function() {
109728
+ return DiscoveryProposalBodySchema;
109729
+ }
109730
+ });
109498
109731
  Object.defineProperty(exports, "EMPTY_AUTOMATION_STATE", {
109499
109732
  enumerable: true,
109500
109733
  get: function() {
@@ -110383,6 +110616,12 @@ Object.defineProperty(exports, "coverCapability", {
110383
110616
  return coverCapability;
110384
110617
  }
110385
110618
  });
110619
+ Object.defineProperty(exports, "createDebugEmitter", {
110620
+ enumerable: true,
110621
+ get: function() {
110622
+ return createDebugEmitter;
110623
+ }
110624
+ });
110386
110625
  Object.defineProperty(exports, "createDeviceExtensionProvider", {
110387
110626
  enumerable: true,
110388
110627
  get: function() {
@@ -110683,6 +110922,12 @@ Object.defineProperty(exports, "gbToBytes", {
110683
110922
  return gbToBytes;
110684
110923
  }
110685
110924
  });
110925
+ Object.defineProperty(exports, "getDebugInterest", {
110926
+ enumerable: true,
110927
+ get: function() {
110928
+ return getDebugInterest;
110929
+ }
110930
+ });
110686
110931
  Object.defineProperty(exports, "groupCommandsCapability", {
110687
110932
  enumerable: true,
110688
110933
  get: function() {
@@ -110773,6 +111018,12 @@ Object.defineProperty(exports, "isCredentialTokenPayload", {
110773
111018
  return isCredentialTokenPayload;
110774
111019
  }
110775
111020
  });
111021
+ Object.defineProperty(exports, "isDebugChannelName", {
111022
+ enumerable: true,
111023
+ get: function() {
111024
+ return isDebugChannelName;
111025
+ }
111026
+ });
110776
111027
  Object.defineProperty(exports, "isDefaultAppConnectionEndpoint", {
110777
111028
  enumerable: true,
110778
111029
  get: function() {
@@ -0,0 +1,199 @@
1
+ //#region src/builtins/local-network/scan/dns-wire.ts
2
+ /**
3
+ * DNS-SD wire format for the scan engine: one PTR question per service type,
4
+ * and a parser that turns an answer into services (instance, host, port, TXT).
5
+ */
6
+ /** Top bit of the question class: ask for a unicast reply (RFC 6762). */
7
+ var MDNS_QU_CLASS = 32769;
8
+ var A = 1;
9
+ var PTR = 12;
10
+ var TXT = 16;
11
+ var SRV = 33;
12
+ var SRV_FIXED = 6;
13
+ var MAX_NAME_HOPS = 16;
14
+ var MDNS_PORT = 5353;
15
+ var MDNS_GROUP = "224.0.0.251";
16
+ /** `_esphomelib._tcp` and `_esphomelib._tcp.local.` name the same service. */
17
+ function normalizeServiceType(serviceType) {
18
+ const lower = serviceType.trim().toLowerCase().replace(/\.$/, "");
19
+ return lower.endsWith(".local") ? lower.slice(0, -6) : lower;
20
+ }
21
+ function readName(buf, start) {
22
+ const labels = [];
23
+ let pos = start;
24
+ let end = start;
25
+ let jumped = false;
26
+ for (let hops = 0; hops < MAX_NAME_HOPS; hops++) {
27
+ if (pos < 0 || pos >= buf.length) return null;
28
+ const len = buf[pos] ?? 0;
29
+ if (len === 0) {
30
+ if (!jumped) end = pos + 1;
31
+ return {
32
+ name: labels.join("."),
33
+ end
34
+ };
35
+ }
36
+ if ((len & 192) === 192) {
37
+ if (pos + 1 >= buf.length) return null;
38
+ if (!jumped) end = pos + 2;
39
+ jumped = true;
40
+ pos = (len & 63) << 8 | (buf[pos + 1] ?? 0);
41
+ continue;
42
+ }
43
+ if ((len & 192) !== 0 || pos + 1 + len > buf.length) return null;
44
+ labels.push(buf.subarray(pos + 1, pos + 1 + len).toString("utf8"));
45
+ pos += 1 + len;
46
+ if (!jumped) end = pos;
47
+ }
48
+ return null;
49
+ }
50
+ function readRecords(buf, offset, count) {
51
+ const records = [];
52
+ let pos = offset;
53
+ for (let i = 0; i < count; i++) {
54
+ const name = readName(buf, pos);
55
+ if (name === null || name.end + 10 > buf.length) return null;
56
+ const type = buf.readUInt16BE(name.end);
57
+ const dataLength = buf.readUInt16BE(name.end + 8);
58
+ const dataOffset = name.end + 10;
59
+ if (dataOffset + dataLength > buf.length) return null;
60
+ records.push({
61
+ name: name.name,
62
+ type,
63
+ dataOffset,
64
+ dataLength
65
+ });
66
+ pos = dataOffset + dataLength;
67
+ }
68
+ return {
69
+ records,
70
+ next: pos
71
+ };
72
+ }
73
+ function parseTxt(buf, offset, length) {
74
+ const out = {};
75
+ let pos = offset;
76
+ const end = offset + length;
77
+ while (pos < end) {
78
+ const len = buf[pos] ?? 0;
79
+ pos += 1;
80
+ if (len === 0 || pos + len > end) break;
81
+ const entry = buf.subarray(pos, pos + len).toString("utf8");
82
+ pos += len;
83
+ const eq = entry.indexOf("=");
84
+ if (eq < 0) out[entry] = "";
85
+ else out[entry.slice(0, eq)] = entry.slice(eq + 1);
86
+ }
87
+ return out;
88
+ }
89
+ /** One PTR question per service type, all with the unicast-reply bit. */
90
+ function buildPtrQuery(serviceTypes) {
91
+ const header = Buffer.alloc(12);
92
+ header.writeUInt16BE(serviceTypes.length, 4);
93
+ const questions = serviceTypes.map((type) => {
94
+ const encoded = `${normalizeServiceType(type)}.local`.split(".").filter((part) => part.length > 0).map((l) => Buffer.concat([Buffer.from([l.length]), Buffer.from(l)]));
95
+ const tail = Buffer.alloc(4);
96
+ tail.writeUInt16BE(PTR, 0);
97
+ tail.writeUInt16BE(MDNS_QU_CLASS, 2);
98
+ return Buffer.concat([
99
+ ...encoded,
100
+ Buffer.from([0]),
101
+ tail
102
+ ]);
103
+ });
104
+ return Buffer.concat([header, ...questions]);
105
+ }
106
+ /** The services advertised on one mDNS message; a malformed packet yields none. */
107
+ function parseMdnsMessage(buf) {
108
+ if (buf.length < 12) return [];
109
+ const [questions = 0, answers = 0, authorities = 0, extra = 0] = [
110
+ 4,
111
+ 6,
112
+ 8,
113
+ 10
114
+ ].map((o) => buf.readUInt16BE(o));
115
+ let pos = 12;
116
+ for (let i = 0; i < questions; i++) {
117
+ const name = readName(buf, pos);
118
+ if (name === null) return [];
119
+ pos = name.end + 4;
120
+ if (pos > buf.length) return [];
121
+ }
122
+ const records = [];
123
+ for (const count of [
124
+ answers,
125
+ authorities,
126
+ extra
127
+ ]) {
128
+ const read = readRecords(buf, pos, count);
129
+ if (read === null) return [];
130
+ records.push(...read.records);
131
+ pos = read.next;
132
+ }
133
+ const ptrs = [];
134
+ const srv = /* @__PURE__ */ new Map();
135
+ const txt = /* @__PURE__ */ new Map();
136
+ const addresses = /* @__PURE__ */ new Map();
137
+ for (const rec of records) {
138
+ const key = rec.name.toLowerCase();
139
+ if (rec.type === PTR) {
140
+ const target = readName(buf, rec.dataOffset);
141
+ if (target !== null) ptrs.push({
142
+ serviceType: rec.name,
143
+ instance: target.name
144
+ });
145
+ } else if (rec.type === SRV && rec.dataLength >= SRV_FIXED) {
146
+ const target = readName(buf, rec.dataOffset + SRV_FIXED);
147
+ if (target !== null) srv.set(key, {
148
+ target: target.name,
149
+ port: buf.readUInt16BE(rec.dataOffset + 4)
150
+ });
151
+ } else if (rec.type === TXT) txt.set(key, parseTxt(buf, rec.dataOffset, rec.dataLength));
152
+ else if (rec.type === A && rec.dataLength === 4) addresses.set(key, `${buf[rec.dataOffset]}.${buf[rec.dataOffset + 1]}.${buf[rec.dataOffset + 2]}.${buf[rec.dataOffset + 3]}`);
153
+ }
154
+ const out = [];
155
+ for (const { serviceType, instance } of ptrs) {
156
+ const service = srv.get(instance.toLowerCase());
157
+ const target = service?.target ?? instance;
158
+ out.push({
159
+ serviceType: normalizeServiceType(serviceType),
160
+ instance,
161
+ address: addresses.get(target.toLowerCase()) ?? addresses.get(instance.toLowerCase()) ?? null,
162
+ host: target,
163
+ port: service?.port ?? 0,
164
+ txt: txt.get(instance.toLowerCase()) ?? {}
165
+ });
166
+ }
167
+ return out;
168
+ }
169
+ //#endregion
170
+ Object.defineProperty(exports, "MDNS_GROUP", {
171
+ enumerable: true,
172
+ get: function() {
173
+ return MDNS_GROUP;
174
+ }
175
+ });
176
+ Object.defineProperty(exports, "MDNS_PORT", {
177
+ enumerable: true,
178
+ get: function() {
179
+ return MDNS_PORT;
180
+ }
181
+ });
182
+ Object.defineProperty(exports, "buildPtrQuery", {
183
+ enumerable: true,
184
+ get: function() {
185
+ return buildPtrQuery;
186
+ }
187
+ });
188
+ Object.defineProperty(exports, "normalizeServiceType", {
189
+ enumerable: true,
190
+ get: function() {
191
+ return normalizeServiceType;
192
+ }
193
+ });
194
+ Object.defineProperty(exports, "parseMdnsMessage", {
195
+ enumerable: true,
196
+ get: function() {
197
+ return parseMdnsMessage;
198
+ }
199
+ });