@camstack/system 1.2.219 → 1.2.220

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 (68) hide show
  1. package/dist/addon-runner.js +2 -2
  2. package/dist/addon-runner.mjs +2 -2
  3. package/dist/addon-utils.js +1 -1
  4. package/dist/addon-utils.mjs +1 -1
  5. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.js +1 -1
  6. package/dist/builtins/addon-pages-aggregator/addon-pages-aggregator.addon.mjs +1 -1
  7. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.js +1 -1
  8. package/dist/builtins/addon-widgets-aggregator/addon-widgets-aggregator.addon.mjs +1 -1
  9. package/dist/builtins/alerts/alerts.addon.js +1 -1
  10. package/dist/builtins/alerts/alerts.addon.mjs +1 -1
  11. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.js +1 -1
  12. package/dist/builtins/backup-orchestrator/backup-orchestrator.addon.mjs +1 -1
  13. package/dist/builtins/console-logging/index.js +1 -1
  14. package/dist/builtins/console-logging/index.mjs +1 -1
  15. package/dist/builtins/core-blocks/core-blocks.addon.js +1 -1
  16. package/dist/builtins/core-blocks/core-blocks.addon.mjs +1 -1
  17. package/dist/builtins/device-manager/device-manager.addon.js +2 -2
  18. package/dist/builtins/device-manager/device-manager.addon.mjs +2 -2
  19. package/dist/builtins/doorbell/virtual-doorbell.addon.js +1 -1
  20. package/dist/builtins/doorbell/virtual-doorbell.addon.mjs +1 -1
  21. package/dist/builtins/hub-forwarder/index.js +1 -1
  22. package/dist/builtins/hub-forwarder/index.mjs +1 -1
  23. package/dist/builtins/liveness-monitor/liveness-monitor.addon.js +1 -1
  24. package/dist/builtins/liveness-monitor/liveness-monitor.addon.mjs +1 -1
  25. package/dist/builtins/local-auth/local-auth.addon.js +1 -1
  26. package/dist/builtins/local-auth/local-auth.addon.mjs +1 -1
  27. package/dist/builtins/local-network/local-network.addon.js +1 -1
  28. package/dist/builtins/local-network/local-network.addon.mjs +1 -1
  29. package/dist/builtins/loki-logging/index.js +1 -1
  30. package/dist/builtins/loki-logging/index.mjs +1 -1
  31. package/dist/builtins/native-metrics/native-metrics.addon.js +1 -1
  32. package/dist/builtins/native-metrics/native-metrics.addon.mjs +1 -1
  33. package/dist/builtins/platform-probe/index.js +1 -1
  34. package/dist/builtins/platform-probe/index.mjs +1 -1
  35. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.js +1 -1
  36. package/dist/builtins/remote-access-orchestrator/remote-access-orchestrator.addon.mjs +1 -1
  37. package/dist/builtins/snapshot/index.js +1 -1
  38. package/dist/builtins/snapshot/index.mjs +1 -1
  39. package/dist/builtins/sqlite-storage/filesystem-storage.addon.js +1 -1
  40. package/dist/builtins/sqlite-storage/filesystem-storage.addon.mjs +1 -1
  41. package/dist/builtins/sqlite-storage/sqlite-settings.addon.js +0 -0
  42. package/dist/builtins/sqlite-storage/sqlite-settings.addon.mjs +0 -0
  43. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.js +1 -1
  44. package/dist/builtins/storage-orchestrator/storage-orchestrator.addon.mjs +1 -1
  45. package/dist/builtins/system-config/system-config.addon.js +1 -1
  46. package/dist/builtins/system-config/system-config.addon.mjs +1 -1
  47. package/dist/builtins/winston-logging/index.js +1 -1
  48. package/dist/builtins/winston-logging/index.mjs +1 -1
  49. package/dist/{custom-action-registry-DKWhaWL1.js → custom-action-registry-B42MC_Pv.js} +1 -1
  50. package/dist/{custom-action-registry-B6gOtUWA.mjs → custom-action-registry-CpR58DXT.mjs} +1 -1
  51. package/dist/{dist-Cyz5_i7z.mjs → dist-Ca_jaxXs.mjs} +230 -2
  52. package/dist/{dist-B17W9ngu.js → dist-CllKpcTd.js} +230 -2
  53. package/dist/index.js +71 -32
  54. package/dist/index.mjs +65 -33
  55. package/dist/kernel/gc-census.d.ts +144 -0
  56. package/dist/kernel/heap-watch.d.ts +8 -0
  57. package/dist/kernel/socket-plane-report.d.ts +37 -0
  58. package/dist/kernel/transport/cap-action-census.d.ts +218 -0
  59. package/dist/kernel/transport/cap-child-index.d.ts +49 -0
  60. package/dist/kernel/transport/index.d.ts +2 -0
  61. package/dist/kernel/transport/local-child-registry.d.ts +63 -4
  62. package/dist/kernel/transport/local-transport.d.ts +9 -0
  63. package/dist/kernel/transport/socket-channel.d.ts +21 -0
  64. package/dist/{manifest-system-deps-g_nK0xsF.js → manifest-system-deps-DfpwaXkh.js} +550 -27
  65. package/dist/{manifest-system-deps-C7dihwWT.mjs → manifest-system-deps-iadzxSBr.mjs} +509 -28
  66. package/dist/{retired-settings-keys-CjvB7Etx.js → retired-settings-keys-7iEsSzmD.js} +1 -1
  67. package/dist/{retired-settings-keys-BCYUrdsA.mjs → retired-settings-keys-DQnfr__p.mjs} +1 -1
  68. package/package.json +1 -1
@@ -675,6 +675,86 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
675
675
  EventCategory["ModelConvertProgress"] = "model-convert.progress";
676
676
  return EventCategory;
677
677
  }({});
678
+ //#endregion
679
+ //#region ../types/dist/sleep-BnujYGPe.mjs
680
+ /**
681
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
682
+ * window to float samples (D455).
683
+ *
684
+ * ## Why a format at all
685
+ *
686
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
687
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
688
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
689
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
690
+ * the plane carried four times the source. The plane crosses hub-main twice on
691
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
692
+ *
693
+ * So the plane carries the source BYTES too, and whoever needs floats expands
694
+ * them where it needs them. That is the same argument D450 made for the rate,
695
+ * one step further along the same wire.
696
+ *
697
+ * ## Why the expansion lives here
698
+ *
699
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
700
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
701
+ * `AudioChunkPlane` expands per subscription) and
702
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
703
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
704
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
705
+ * into their own dist (`self-contained` externals), so this travels with a
706
+ * `camstack deploy` and needs no published server.
707
+ *
708
+ * A second μ-law table anywhere else is the defect this module exists to
709
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
710
+ * direction for the WebRTC egress — a different transform, not a copy.)
711
+ *
712
+ * ## Absent means f32le
713
+ *
714
+ * `format` is optional on the wire and its absence means `f32le` — today's
715
+ * bytes, byte for byte. A peer that never heard of the field is served what it
716
+ * has always been served, because the broker only emits a coded window to a
717
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
718
+ * That is the D448 `rawForward` negotiation, and it is what makes this
719
+ * deployable one addon at a time across three nodes.
720
+ */
721
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
722
+ var AUDIO_CHUNK_FORMATS = [
723
+ "f32le",
724
+ "pcmu",
725
+ "pcma"
726
+ ];
727
+ /**
728
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
729
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
730
+ *
731
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
732
+ * it buffers the coded bytes and the plane's consumers expand.
733
+ */
734
+ function buildUlawTable() {
735
+ const table = new Float32Array(256);
736
+ for (let i = 0; i < 256; i++) {
737
+ const complemented = ~i & 255;
738
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
739
+ const exponent = complemented >> 4 & 7;
740
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
741
+ }
742
+ return table;
743
+ }
744
+ /** Build the A-law decode table (ITU-T G.711). */
745
+ function buildAlawTable() {
746
+ const table = new Float32Array(256);
747
+ for (let i = 0; i < 256; i++) {
748
+ const xored = i ^ 85;
749
+ const sign = (xored & 128) !== 0 ? 1 : -1;
750
+ const exponent = xored >> 4 & 7;
751
+ const mantissa = xored & 15;
752
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
753
+ }
754
+ return table;
755
+ }
756
+ buildUlawTable();
757
+ buildAlawTable();
678
758
  /** Lookup map for well-known tabs by ID. */
679
759
  var WELL_KNOWN_TAB_MAP = Object.fromEntries([
680
760
  {
@@ -1975,11 +2055,20 @@ var SubscribeFramesResultSchema = z.object({
1975
2055
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
1976
2056
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
1977
2057
  */
2058
+ var AudioChunkFormatSchema = z.enum(AUDIO_CHUNK_FORMATS);
1978
2059
  var DecodedAudioChunkSchema = z.object({
1979
2060
  data: z.instanceof(Uint8Array),
1980
2061
  sampleRate: z.number().int().positive(),
1981
2062
  channels: z.number().int().positive(),
1982
- timestamp: z.number()
2063
+ timestamp: z.number(),
2064
+ /**
2065
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
2066
+ * byte, for any peer that never heard of this field. A coded window
2067
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
2068
+ * subscription that DECLARED it accepts one, so absence can never mean
2069
+ * "coded bytes a consumer will read as floats" (D455).
2070
+ */
2071
+ format: AudioChunkFormatSchema.optional()
1983
2072
  });
1984
2073
  /**
1985
2074
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -1991,7 +2080,18 @@ var DecodedAudioChunkSchema = z.object({
1991
2080
  var SubscribeAudioChunksInputSchema = z.object({
1992
2081
  brokerId: z.string(),
1993
2082
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
1994
- tag: z.string().optional()
2083
+ tag: z.string().optional(),
2084
+ /**
2085
+ * Byte formats this subscriber can READ, best first. The broker serves the
2086
+ * chunk's own format when it is in this list and expands to `f32le`
2087
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
2088
+ *
2089
+ * Absent (or without the source format) means `f32le` — the behaviour every
2090
+ * subscriber had before D455, unchanged. This is the negotiation half of
2091
+ * the source-bytes lever: it is what lets the broker and its consumers
2092
+ * deploy one at a time across three nodes.
2093
+ */
2094
+ accept: z.array(AudioChunkFormatSchema).readonly().optional()
1995
2095
  });
1996
2096
  /** Result of `stream-broker.subscribeAudioChunks`. */
1997
2097
  var SubscribeAudioChunksResultSchema = z.object({
@@ -7366,6 +7466,51 @@ var AudioAnalysisSettingsSchema = z.object({
7366
7466
  minConfidence: z.number().min(0).max(1).default(.3),
7367
7467
  allowedClasses: z.array(z.string()).default([])
7368
7468
  });
7469
+ /**
7470
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
7471
+ *
7472
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
7473
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
7474
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
7475
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
7476
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
7477
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
7478
+ * way to the one expansion that feeds the model.
7479
+ *
7480
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
7481
+ * window, the per-device node assignment, the settings read) and therefore
7482
+ * still owns the attach/detach pair. It no longer owns the bytes.
7483
+ */
7484
+ var AudioAttachDeviceInputSchema = z.object({
7485
+ deviceId: z.number(),
7486
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
7487
+ brokerId: z.string(),
7488
+ /**
7489
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
7490
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
7491
+ * the orchestrator's poller pinned them before the move.
7492
+ */
7493
+ ingestNodeId: z.string(),
7494
+ /**
7495
+ * Resolved once by the orchestrator at attach time, exactly as it was read
7496
+ * once per subscription before D461. The analyzer does NOT re-resolve per
7497
+ * window: a settings change re-attaches, which is what always happened.
7498
+ */
7499
+ settings: AudioAnalysisSettingsSchema
7500
+ });
7501
+ var AudioAttachDeviceResultSchema = z.object({
7502
+ /** False only when the analyzer is shutting down and refused to attach. */
7503
+ attached: z.boolean(),
7504
+ /**
7505
+ * True when the attachment replaced a live one for the same device. An
7506
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
7507
+ * double the broker's fanout and neither would know about the other.
7508
+ */
7509
+ replaced: z.boolean()
7510
+ });
7511
+ var AudioDetachDeviceResultSchema = z.object({
7512
+ /** False when no attachment existed — detach is idempotent. */
7513
+ detached: z.boolean() });
7369
7514
  var AudioClassificationResultSchema = z.object({
7370
7515
  labels: z.array(AudioClassificationLabelSchema).readonly(),
7371
7516
  rawLabels: z.array(AudioClassificationLabelSchema).readonly().optional(),
@@ -7381,6 +7526,21 @@ var audioAnalyzerCapability = {
7381
7526
  settings: AudioAnalysisSettingsSchema
7382
7527
  }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }),
7383
7528
  classify: method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }),
7529
+ /**
7530
+ * Start pulling this camera's audio from the broker, in THIS process.
7531
+ * Returns as soon as the attachment exists — the first
7532
+ * `subscribeAudioChunks` retries with backoff behind it, because the
7533
+ * broker for a camStream may not be registered yet (that tolerance moved
7534
+ * with the poller, D461). Replaces any live attachment for the device.
7535
+ */
7536
+ attachDevice: method(AudioAttachDeviceInputSchema, AudioAttachDeviceResultSchema, { kind: "mutation" }),
7537
+ /**
7538
+ * Stop pulling this camera's audio and release the broker subscription.
7539
+ * Idempotent. A detach that never arrives is the one failure mode this
7540
+ * split adds, which is why `AudioChunkPlane` reaps a subscription nobody
7541
+ * drains rather than trusting it (D461).
7542
+ */
7543
+ detachDevice: method(z.object({ deviceId: z.number() }), AudioDetachDeviceResultSchema, { kind: "mutation" }),
7384
7544
  isReady: method(z.void(), z.boolean()),
7385
7545
  dispose: method(z.void(), z.void(), { kind: "mutation" }),
7386
7546
  /**
@@ -36736,12 +36896,24 @@ var METHOD_ACCESS_MAP = Object.freeze({
36736
36896
  addonId: null,
36737
36897
  access: "create"
36738
36898
  },
36899
+ "audioAnalyzer.attachDevice": {
36900
+ capName: "audio-analyzer",
36901
+ capScope: "system",
36902
+ addonId: null,
36903
+ access: "create"
36904
+ },
36739
36905
  "audioAnalyzer.classify": {
36740
36906
  capName: "audio-analyzer",
36741
36907
  capScope: "system",
36742
36908
  addonId: null,
36743
36909
  access: "view"
36744
36910
  },
36911
+ "audioAnalyzer.detachDevice": {
36912
+ capName: "audio-analyzer",
36913
+ capScope: "system",
36914
+ addonId: null,
36915
+ access: "create"
36916
+ },
36745
36917
  "audioAnalyzer.dispose": {
36746
36918
  capName: "audio-analyzer",
36747
36919
  capScope: "system",
@@ -42585,11 +42757,21 @@ Object.freeze({
42585
42757
  form: "single",
42586
42758
  optional: false
42587
42759
  }],
42760
+ "audioAnalyzer.attachDevice": [{
42761
+ name: "deviceId",
42762
+ form: "single",
42763
+ optional: false
42764
+ }],
42588
42765
  "audioAnalyzer.classify": [{
42589
42766
  name: "deviceId",
42590
42767
  form: "single",
42591
42768
  optional: true
42592
42769
  }],
42770
+ "audioAnalyzer.detachDevice": [{
42771
+ name: "deviceId",
42772
+ form: "single",
42773
+ optional: false
42774
+ }],
42593
42775
  "audioMetrics.getCurrentSnapshot": [{
42594
42776
  name: "deviceId",
42595
42777
  form: "single",
@@ -44733,6 +44915,52 @@ var SESSION_ONLY_POLICY = {
44733
44915
  durability: "session",
44734
44916
  volatileFields: []
44735
44917
  };
44918
+ var G711_SCALE_CORRECTION_DB = {
44919
+ PCMU: 20 * Math.log10(4),
44920
+ PCMA: 20 * Math.log10(8)
44921
+ };
44922
+ /**
44923
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
44924
+ * same intent on the ITU-T scale (D460).
44925
+ *
44926
+ * ## When this applies, and when it is the wrong thing to reach for
44927
+ *
44928
+ * An absolute-dBFS number in this repo is one of two things, and only one of
44929
+ * them converts:
44930
+ *
44931
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
44932
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
44933
+ * after. The defect was never in the number; it was that 19 of this hub's
44934
+ * 25 cameras did not obey it. Converting such a number takes something
44935
+ * correct and makes it wrong, in order to preserve a bug.
44936
+ * - **A measurement taken through the old decoder** — a value someone read
44937
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
44938
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
44939
+ * louder. That is what this function is for.
44940
+ *
44941
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
44942
+ * and it cannot be answered from the number. It is answered by the comment the
44943
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
44944
+ * mandatory.
44945
+ *
44946
+ * ## Why a function and not a typed-in number
44947
+ *
44948
+ * `-55 + 12.04` written into a source file is, six months later, completely
44949
+ * indistinguishable from a threshold somebody simply preferred. Calling this
44950
+ * keeps the derivation, the law, and the original measurement all visible at
44951
+ * the call site, so a future reader can disagree with the *premise* instead of
44952
+ * having to reverse-engineer the sum.
44953
+ *
44954
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
44955
+ * it is declared. It must never be applied to a live sample or a stored
44956
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
44957
+ * adjusting numbers the decoder already got right is the original defect with
44958
+ * an extra place to argue with (D459).
44959
+ */
44960
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
44961
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
44962
+ }
44963
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
44736
44964
  /** Schema defaults — an untouched sub-field must author exactly these. */
44737
44965
  var NC_AUDIO_DEFAULTS = {
44738
44966
  hitPercent: 60,
@@ -675,6 +675,86 @@ var EventCategory = /* @__PURE__ */ function(EventCategory) {
675
675
  EventCategory["ModelConvertProgress"] = "model-convert.progress";
676
676
  return EventCategory;
677
677
  }({});
678
+ //#endregion
679
+ //#region ../types/dist/sleep-BnujYGPe.mjs
680
+ /**
681
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
682
+ * window to float samples (D455).
683
+ *
684
+ * ## Why a format at all
685
+ *
686
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
687
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
688
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
689
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
690
+ * the plane carried four times the source. The plane crosses hub-main twice on
691
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
692
+ *
693
+ * So the plane carries the source BYTES too, and whoever needs floats expands
694
+ * them where it needs them. That is the same argument D450 made for the rate,
695
+ * one step further along the same wire.
696
+ *
697
+ * ## Why the expansion lives here
698
+ *
699
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
700
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
701
+ * `AudioChunkPlane` expands per subscription) and
702
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
703
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
704
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
705
+ * into their own dist (`self-contained` externals), so this travels with a
706
+ * `camstack deploy` and needs no published server.
707
+ *
708
+ * A second μ-law table anywhere else is the defect this module exists to
709
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
710
+ * direction for the WebRTC egress — a different transform, not a copy.)
711
+ *
712
+ * ## Absent means f32le
713
+ *
714
+ * `format` is optional on the wire and its absence means `f32le` — today's
715
+ * bytes, byte for byte. A peer that never heard of the field is served what it
716
+ * has always been served, because the broker only emits a coded window to a
717
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
718
+ * That is the D448 `rawForward` negotiation, and it is what makes this
719
+ * deployable one addon at a time across three nodes.
720
+ */
721
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
722
+ var AUDIO_CHUNK_FORMATS = [
723
+ "f32le",
724
+ "pcmu",
725
+ "pcma"
726
+ ];
727
+ /**
728
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
729
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
730
+ *
731
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
732
+ * it buffers the coded bytes and the plane's consumers expand.
733
+ */
734
+ function buildUlawTable() {
735
+ const table = new Float32Array(256);
736
+ for (let i = 0; i < 256; i++) {
737
+ const complemented = ~i & 255;
738
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
739
+ const exponent = complemented >> 4 & 7;
740
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
741
+ }
742
+ return table;
743
+ }
744
+ /** Build the A-law decode table (ITU-T G.711). */
745
+ function buildAlawTable() {
746
+ const table = new Float32Array(256);
747
+ for (let i = 0; i < 256; i++) {
748
+ const xored = i ^ 85;
749
+ const sign = (xored & 128) !== 0 ? 1 : -1;
750
+ const exponent = xored >> 4 & 7;
751
+ const mantissa = xored & 15;
752
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
753
+ }
754
+ return table;
755
+ }
756
+ buildUlawTable();
757
+ buildAlawTable();
678
758
  /** Lookup map for well-known tabs by ID. */
679
759
  var WELL_KNOWN_TAB_MAP = Object.fromEntries([
680
760
  {
@@ -1975,11 +2055,20 @@ var SubscribeFramesResultSchema = zod.z.object({
1975
2055
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
1976
2056
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
1977
2057
  */
2058
+ var AudioChunkFormatSchema = zod.z.enum(AUDIO_CHUNK_FORMATS);
1978
2059
  var DecodedAudioChunkSchema = zod.z.object({
1979
2060
  data: zod.z.instanceof(Uint8Array),
1980
2061
  sampleRate: zod.z.number().int().positive(),
1981
2062
  channels: zod.z.number().int().positive(),
1982
- timestamp: zod.z.number()
2063
+ timestamp: zod.z.number(),
2064
+ /**
2065
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
2066
+ * byte, for any peer that never heard of this field. A coded window
2067
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
2068
+ * subscription that DECLARED it accepts one, so absence can never mean
2069
+ * "coded bytes a consumer will read as floats" (D455).
2070
+ */
2071
+ format: AudioChunkFormatSchema.optional()
1983
2072
  });
1984
2073
  /**
1985
2074
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -1991,7 +2080,18 @@ var DecodedAudioChunkSchema = zod.z.object({
1991
2080
  var SubscribeAudioChunksInputSchema = zod.z.object({
1992
2081
  brokerId: zod.z.string(),
1993
2082
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
1994
- tag: zod.z.string().optional()
2083
+ tag: zod.z.string().optional(),
2084
+ /**
2085
+ * Byte formats this subscriber can READ, best first. The broker serves the
2086
+ * chunk's own format when it is in this list and expands to `f32le`
2087
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
2088
+ *
2089
+ * Absent (or without the source format) means `f32le` — the behaviour every
2090
+ * subscriber had before D455, unchanged. This is the negotiation half of
2091
+ * the source-bytes lever: it is what lets the broker and its consumers
2092
+ * deploy one at a time across three nodes.
2093
+ */
2094
+ accept: zod.z.array(AudioChunkFormatSchema).readonly().optional()
1995
2095
  });
1996
2096
  /** Result of `stream-broker.subscribeAudioChunks`. */
1997
2097
  var SubscribeAudioChunksResultSchema = zod.z.object({
@@ -7366,6 +7466,51 @@ var AudioAnalysisSettingsSchema = zod.z.object({
7366
7466
  minConfidence: zod.z.number().min(0).max(1).default(.3),
7367
7467
  allowedClasses: zod.z.array(zod.z.string()).default([])
7368
7468
  });
7469
+ /**
7470
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
7471
+ *
7472
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
7473
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
7474
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
7475
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
7476
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
7477
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
7478
+ * way to the one expansion that feeds the model.
7479
+ *
7480
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
7481
+ * window, the per-device node assignment, the settings read) and therefore
7482
+ * still owns the attach/detach pair. It no longer owns the bytes.
7483
+ */
7484
+ var AudioAttachDeviceInputSchema = zod.z.object({
7485
+ deviceId: zod.z.number(),
7486
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
7487
+ brokerId: zod.z.string(),
7488
+ /**
7489
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
7490
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
7491
+ * the orchestrator's poller pinned them before the move.
7492
+ */
7493
+ ingestNodeId: zod.z.string(),
7494
+ /**
7495
+ * Resolved once by the orchestrator at attach time, exactly as it was read
7496
+ * once per subscription before D461. The analyzer does NOT re-resolve per
7497
+ * window: a settings change re-attaches, which is what always happened.
7498
+ */
7499
+ settings: AudioAnalysisSettingsSchema
7500
+ });
7501
+ var AudioAttachDeviceResultSchema = zod.z.object({
7502
+ /** False only when the analyzer is shutting down and refused to attach. */
7503
+ attached: zod.z.boolean(),
7504
+ /**
7505
+ * True when the attachment replaced a live one for the same device. An
7506
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
7507
+ * double the broker's fanout and neither would know about the other.
7508
+ */
7509
+ replaced: zod.z.boolean()
7510
+ });
7511
+ var AudioDetachDeviceResultSchema = zod.z.object({
7512
+ /** False when no attachment existed — detach is idempotent. */
7513
+ detached: zod.z.boolean() });
7369
7514
  var AudioClassificationResultSchema = zod.z.object({
7370
7515
  labels: zod.z.array(AudioClassificationLabelSchema).readonly(),
7371
7516
  rawLabels: zod.z.array(AudioClassificationLabelSchema).readonly().optional(),
@@ -7381,6 +7526,21 @@ var audioAnalyzerCapability = {
7381
7526
  settings: AudioAnalysisSettingsSchema
7382
7527
  }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }),
7383
7528
  classify: method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }),
7529
+ /**
7530
+ * Start pulling this camera's audio from the broker, in THIS process.
7531
+ * Returns as soon as the attachment exists — the first
7532
+ * `subscribeAudioChunks` retries with backoff behind it, because the
7533
+ * broker for a camStream may not be registered yet (that tolerance moved
7534
+ * with the poller, D461). Replaces any live attachment for the device.
7535
+ */
7536
+ attachDevice: method(AudioAttachDeviceInputSchema, AudioAttachDeviceResultSchema, { kind: "mutation" }),
7537
+ /**
7538
+ * Stop pulling this camera's audio and release the broker subscription.
7539
+ * Idempotent. A detach that never arrives is the one failure mode this
7540
+ * split adds, which is why `AudioChunkPlane` reaps a subscription nobody
7541
+ * drains rather than trusting it (D461).
7542
+ */
7543
+ detachDevice: method(zod.z.object({ deviceId: zod.z.number() }), AudioDetachDeviceResultSchema, { kind: "mutation" }),
7384
7544
  isReady: method(zod.z.void(), zod.z.boolean()),
7385
7545
  dispose: method(zod.z.void(), zod.z.void(), { kind: "mutation" }),
7386
7546
  /**
@@ -36736,12 +36896,24 @@ var METHOD_ACCESS_MAP = Object.freeze({
36736
36896
  addonId: null,
36737
36897
  access: "create"
36738
36898
  },
36899
+ "audioAnalyzer.attachDevice": {
36900
+ capName: "audio-analyzer",
36901
+ capScope: "system",
36902
+ addonId: null,
36903
+ access: "create"
36904
+ },
36739
36905
  "audioAnalyzer.classify": {
36740
36906
  capName: "audio-analyzer",
36741
36907
  capScope: "system",
36742
36908
  addonId: null,
36743
36909
  access: "view"
36744
36910
  },
36911
+ "audioAnalyzer.detachDevice": {
36912
+ capName: "audio-analyzer",
36913
+ capScope: "system",
36914
+ addonId: null,
36915
+ access: "create"
36916
+ },
36745
36917
  "audioAnalyzer.dispose": {
36746
36918
  capName: "audio-analyzer",
36747
36919
  capScope: "system",
@@ -42585,11 +42757,21 @@ Object.freeze({
42585
42757
  form: "single",
42586
42758
  optional: false
42587
42759
  }],
42760
+ "audioAnalyzer.attachDevice": [{
42761
+ name: "deviceId",
42762
+ form: "single",
42763
+ optional: false
42764
+ }],
42588
42765
  "audioAnalyzer.classify": [{
42589
42766
  name: "deviceId",
42590
42767
  form: "single",
42591
42768
  optional: true
42592
42769
  }],
42770
+ "audioAnalyzer.detachDevice": [{
42771
+ name: "deviceId",
42772
+ form: "single",
42773
+ optional: false
42774
+ }],
42593
42775
  "audioMetrics.getCurrentSnapshot": [{
42594
42776
  name: "deviceId",
42595
42777
  form: "single",
@@ -44733,6 +44915,52 @@ var SESSION_ONLY_POLICY = {
44733
44915
  durability: "session",
44734
44916
  volatileFields: []
44735
44917
  };
44918
+ var G711_SCALE_CORRECTION_DB = {
44919
+ PCMU: 20 * Math.log10(4),
44920
+ PCMA: 20 * Math.log10(8)
44921
+ };
44922
+ /**
44923
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
44924
+ * same intent on the ITU-T scale (D460).
44925
+ *
44926
+ * ## When this applies, and when it is the wrong thing to reach for
44927
+ *
44928
+ * An absolute-dBFS number in this repo is one of two things, and only one of
44929
+ * them converts:
44930
+ *
44931
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
44932
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
44933
+ * after. The defect was never in the number; it was that 19 of this hub's
44934
+ * 25 cameras did not obey it. Converting such a number takes something
44935
+ * correct and makes it wrong, in order to preserve a bug.
44936
+ * - **A measurement taken through the old decoder** — a value someone read
44937
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
44938
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
44939
+ * louder. That is what this function is for.
44940
+ *
44941
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
44942
+ * and it cannot be answered from the number. It is answered by the comment the
44943
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
44944
+ * mandatory.
44945
+ *
44946
+ * ## Why a function and not a typed-in number
44947
+ *
44948
+ * `-55 + 12.04` written into a source file is, six months later, completely
44949
+ * indistinguishable from a threshold somebody simply preferred. Calling this
44950
+ * keeps the derivation, the law, and the original measurement all visible at
44951
+ * the call site, so a future reader can disagree with the *premise* instead of
44952
+ * having to reverse-engineer the sum.
44953
+ *
44954
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
44955
+ * it is declared. It must never be applied to a live sample or a stored
44956
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
44957
+ * adjusting numbers the decoder already got right is the original defect with
44958
+ * an extra place to argue with (D459).
44959
+ */
44960
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
44961
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
44962
+ }
44963
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
44736
44964
  /** Schema defaults — an untouched sub-field must author exactly these. */
44737
44965
  var NC_AUDIO_DEFAULTS = {
44738
44966
  hitPercent: 60,