@camstack/addon-agent-ui 1.2.100 → 1.2.101

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 (2) hide show
  1. package/dist/addon.js +217 -4
  2. package/package.json +1 -1
package/dist/addon.js CHANGED
@@ -5346,6 +5346,86 @@ var ZodIssueCode = {
5346
5346
  /** @deprecated Do not use. Stub definition, only included for zod-to-json-schema compatibility. */
5347
5347
  var ZodFirstPartyTypeKind;
5348
5348
  ZodFirstPartyTypeKind || (ZodFirstPartyTypeKind = {});
5349
+ //#endregion
5350
+ //#region ../types/dist/sleep-BnujYGPe.mjs
5351
+ /**
5352
+ * The audio chunk plane's byte format, and the ONE expansion from a coded
5353
+ * window to float samples (D455).
5354
+ *
5355
+ * ## Why a format at all
5356
+ *
5357
+ * D450 took the plane off its 8 → 16 kHz upsample: it carries the SOURCE
5358
+ * RATE, and the one consumer that needs 16 kHz resamples next to the model.
5359
+ * It left the FORMAT alone — the broker still turned each G.711 byte into a
5360
+ * 4-byte f32le sample before the bytes entered the transport, so every leg of
5361
+ * the plane carried four times the source. The plane crosses hub-main twice on
5362
+ * the way to the analyzer, and the fleet's G.711 cameras are ~79 % of it.
5363
+ *
5364
+ * So the plane carries the source BYTES too, and whoever needs floats expands
5365
+ * them where it needs them. That is the same argument D450 made for the rate,
5366
+ * one step further along the same wire.
5367
+ *
5368
+ * ## Why the expansion lives here
5369
+ *
5370
+ * Two packages need it and they must never disagree: `addon-pipeline`'s broker
5371
+ * (which still has to serve a subscriber that did NOT ask for coded bytes —
5372
+ * `AudioChunkPlane` expands per subscription) and
5373
+ * `addon-pipeline-orchestrator`'s `AudioWindowAccumulator` (which flushes an
5374
+ * f32le window to the analyzer cap, whose `AudioChunkInput` contract is
5375
+ * unchanged and stays f32le). Both bundle the bare `@camstack/types` entry
5376
+ * into their own dist (`self-contained` externals), so this travels with a
5377
+ * `camstack deploy` and needs no published server.
5378
+ *
5379
+ * A second μ-law table anywhere else is the defect this module exists to
5380
+ * prevent. (`stream-broker.ts`'s `mulawToPcm` / `alawToPcm` are the ENCODE
5381
+ * direction for the WebRTC egress — a different transform, not a copy.)
5382
+ *
5383
+ * ## Absent means f32le
5384
+ *
5385
+ * `format` is optional on the wire and its absence means `f32le` — today's
5386
+ * bytes, byte for byte. A peer that never heard of the field is served what it
5387
+ * has always been served, because the broker only emits a coded window to a
5388
+ * subscription that DECLARED it accepts one (`AudioSubscribeOptions.accept`).
5389
+ * That is the D448 `rawForward` negotiation, and it is what makes this
5390
+ * deployable one addon at a time across three nodes.
5391
+ */
5392
+ /** Every byte format the audio chunk plane can carry. `f32le` is the default. */
5393
+ var AUDIO_CHUNK_FORMATS = [
5394
+ "f32le",
5395
+ "pcmu",
5396
+ "pcma"
5397
+ ];
5398
+ /**
5399
+ * Build the μ-law decode table (ITU-T G.711). Each of the 256 byte values maps
5400
+ * to a 16-bit PCM sample, normalised to [-1.0, 1.0] for f32le output.
5401
+ *
5402
+ * Moved here verbatim from `audio-rtp-decoder.ts`, which no longer decodes:
5403
+ * it buffers the coded bytes and the plane's consumers expand.
5404
+ */
5405
+ function buildUlawTable() {
5406
+ const table = new Float32Array(256);
5407
+ for (let i = 0; i < 256; i++) {
5408
+ const complemented = ~i & 255;
5409
+ const sign = (complemented & 128) !== 0 ? -1 : 1;
5410
+ const exponent = complemented >> 4 & 7;
5411
+ table[i] = sign * ((8 * (complemented & 15) + 132 << exponent) - 132) / 32768;
5412
+ }
5413
+ return table;
5414
+ }
5415
+ /** Build the A-law decode table (ITU-T G.711). */
5416
+ function buildAlawTable() {
5417
+ const table = new Float32Array(256);
5418
+ for (let i = 0; i < 256; i++) {
5419
+ const xored = i ^ 85;
5420
+ const sign = (xored & 128) !== 0 ? 1 : -1;
5421
+ const exponent = xored >> 4 & 7;
5422
+ const mantissa = xored & 15;
5423
+ table[i] = sign * (exponent === 0 ? 16 * mantissa + 8 : 16 * mantissa + 264 << exponent - 1) / 32768;
5424
+ }
5425
+ return table;
5426
+ }
5427
+ buildUlawTable();
5428
+ buildAlawTable();
5349
5429
  Object.fromEntries([
5350
5430
  {
5351
5431
  id: "overview",
@@ -6638,11 +6718,20 @@ var SubscribeFramesResultSchema = object({
6638
6718
  * (the wire-serialisable supertype of `Buffer`) to match `DecodedFrameSchema`
6639
6719
  * / `EncodedPacketSchema`'s precedent; a `Buffer` is assignable to it.
6640
6720
  */
6721
+ var AudioChunkFormatSchema = _enum(AUDIO_CHUNK_FORMATS);
6641
6722
  var DecodedAudioChunkSchema = object({
6642
6723
  data: _instanceof(Uint8Array),
6643
6724
  sampleRate: number().int().positive(),
6644
6725
  channels: number().int().positive(),
6645
- timestamp: number()
6726
+ timestamp: number(),
6727
+ /**
6728
+ * Byte format of `data`. ABSENT MEANS `f32le` — today's bytes, byte for
6729
+ * byte, for any peer that never heard of this field. A coded window
6730
+ * (`pcmu` / `pcma`, one byte per sample) is only ever emitted to a
6731
+ * subscription that DECLARED it accepts one, so absence can never mean
6732
+ * "coded bytes a consumer will read as floats" (D455).
6733
+ */
6734
+ format: AudioChunkFormatSchema.optional()
6646
6735
  });
6647
6736
  /**
6648
6737
  * Input for `stream-broker.subscribeAudioChunks` (Phase 5 / D9). The
@@ -6654,7 +6743,18 @@ var DecodedAudioChunkSchema = object({
6654
6743
  var SubscribeAudioChunksInputSchema = object({
6655
6744
  brokerId: string(),
6656
6745
  /** Short caller-identity tag (`audio-analyzer`, …) for `listClients`. */
6657
- tag: string().optional()
6746
+ tag: string().optional(),
6747
+ /**
6748
+ * Byte formats this subscriber can READ, best first. The broker serves the
6749
+ * chunk's own format when it is in this list and expands to `f32le`
6750
+ * otherwise, so a subscriber is never handed bytes it cannot interpret.
6751
+ *
6752
+ * Absent (or without the source format) means `f32le` — the behaviour every
6753
+ * subscriber had before D455, unchanged. This is the negotiation half of
6754
+ * the source-bytes lever: it is what lets the broker and its consumers
6755
+ * deploy one at a time across three nodes.
6756
+ */
6757
+ accept: array(AudioChunkFormatSchema).readonly().optional()
6658
6758
  });
6659
6759
  /** Result of `stream-broker.subscribeAudioChunks`. */
6660
6760
  var SubscribeAudioChunksResultSchema = object({
@@ -10644,6 +10744,51 @@ var AudioAnalysisSettingsSchema = object({
10644
10744
  minConfidence: number().min(0).max(1).default(.3),
10645
10745
  allowedClasses: array(string()).default([])
10646
10746
  });
10747
+ /**
10748
+ * `attachDevice` — the analyzer PULLS a camera's audio from the broker (D461).
10749
+ *
10750
+ * Until D461 the orchestrator drained the broker's chunk plane, accumulated
10751
+ * ~1 s windows and pushed them back out as `analyseChunk`. It neither produced
10752
+ * nor consumed the audio: the PCM crossed hub-main twice for a process that
10753
+ * only buffered it. `attachDevice` inverts the direction — the analyzer opens
10754
+ * its own `subscribeAudioChunks` against the broker and the subscriber IS the
10755
+ * decoder, so the coded G.711 bytes D455 put on the plane stay coded all the
10756
+ * way to the one expansion that feeds the model.
10757
+ *
10758
+ * The orchestrator still owns the POLICY (the `audioMode` gate, the on-motion
10759
+ * window, the per-device node assignment, the settings read) and therefore
10760
+ * still owns the attach/detach pair. It no longer owns the bytes.
10761
+ */
10762
+ var AudioAttachDeviceInputSchema = object({
10763
+ deviceId: number(),
10764
+ /** Broker id (`<deviceId>/<camStreamId>`) carrying this camera's audio. */
10765
+ brokerId: string(),
10766
+ /**
10767
+ * `clusterRoles.ingestNode` — the node whose broker owns the source dial.
10768
+ * Every `streamBroker` call the attachment makes is pinned to it, exactly as
10769
+ * the orchestrator's poller pinned them before the move.
10770
+ */
10771
+ ingestNodeId: string(),
10772
+ /**
10773
+ * Resolved once by the orchestrator at attach time, exactly as it was read
10774
+ * once per subscription before D461. The analyzer does NOT re-resolve per
10775
+ * window: a settings change re-attaches, which is what always happened.
10776
+ */
10777
+ settings: AudioAnalysisSettingsSchema
10778
+ });
10779
+ var AudioAttachDeviceResultSchema = object({
10780
+ /** False only when the analyzer is shutting down and refused to attach. */
10781
+ attached: boolean(),
10782
+ /**
10783
+ * True when the attachment replaced a live one for the same device. An
10784
+ * attach is idempotent by REPLACEMENT — two pollers on one camera would
10785
+ * double the broker's fanout and neither would know about the other.
10786
+ */
10787
+ replaced: boolean()
10788
+ });
10789
+ var AudioDetachDeviceResultSchema = object({
10790
+ /** False when no attachment existed — detach is idempotent. */
10791
+ detached: boolean() });
10647
10792
  var AudioClassificationResultSchema = object({
10648
10793
  labels: array(AudioClassificationLabelSchema).readonly(),
10649
10794
  rawLabels: array(AudioClassificationLabelSchema).readonly().optional(),
@@ -10652,7 +10797,7 @@ var AudioClassificationResultSchema = object({
10652
10797
  method(object({
10653
10798
  chunk: AudioChunkInputSchema,
10654
10799
  settings: AudioAnalysisSettingsSchema
10655
- }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10800
+ }), AudioAnalysisResultSchema.nullable(), { kind: "mutation" }), method(AudioChunkInputSchema, AudioClassificationResultSchema, { timeoutMs: 3e4 }), method(AudioAttachDeviceInputSchema, AudioAttachDeviceResultSchema, { kind: "mutation" }), method(object({ deviceId: number() }), AudioDetachDeviceResultSchema, { kind: "mutation" }), method(_void(), boolean()), method(_void(), _void(), { kind: "mutation" }), method(_void(), object({ backend: string() }), {
10656
10801
  kind: "mutation",
10657
10802
  auth: "admin"
10658
10803
  });
@@ -30547,12 +30692,24 @@ Object.freeze({
30547
30692
  addonId: null,
30548
30693
  access: "create"
30549
30694
  },
30695
+ "audioAnalyzer.attachDevice": {
30696
+ capName: "audio-analyzer",
30697
+ capScope: "system",
30698
+ addonId: null,
30699
+ access: "create"
30700
+ },
30550
30701
  "audioAnalyzer.classify": {
30551
30702
  capName: "audio-analyzer",
30552
30703
  capScope: "system",
30553
30704
  addonId: null,
30554
30705
  access: "view"
30555
30706
  },
30707
+ "audioAnalyzer.detachDevice": {
30708
+ capName: "audio-analyzer",
30709
+ capScope: "system",
30710
+ addonId: null,
30711
+ access: "create"
30712
+ },
30556
30713
  "audioAnalyzer.dispose": {
30557
30714
  capName: "audio-analyzer",
30558
30715
  capScope: "system",
@@ -36396,11 +36553,21 @@ Object.freeze({
36396
36553
  form: "single",
36397
36554
  optional: false
36398
36555
  }],
36556
+ "audioAnalyzer.attachDevice": [{
36557
+ name: "deviceId",
36558
+ form: "single",
36559
+ optional: false
36560
+ }],
36399
36561
  "audioAnalyzer.classify": [{
36400
36562
  name: "deviceId",
36401
36563
  form: "single",
36402
36564
  optional: true
36403
36565
  }],
36566
+ "audioAnalyzer.detachDevice": [{
36567
+ name: "deviceId",
36568
+ form: "single",
36569
+ optional: false
36570
+ }],
36404
36571
  "audioMetrics.getCurrentSnapshot": [{
36405
36572
  name: "deviceId",
36406
36573
  form: "single",
@@ -38252,6 +38419,52 @@ Object.freeze({
38252
38419
  "network-access": "ingress",
38253
38420
  "smtp-provider": "email"
38254
38421
  });
38422
+ var G711_SCALE_CORRECTION_DB = {
38423
+ PCMU: 20 * Math.log10(4),
38424
+ PCMA: 20 * Math.log10(8)
38425
+ };
38426
+ /**
38427
+ * Restate a dBFS number that was MEASURED through the pre-epoch decoder as the
38428
+ * same intent on the ITU-T scale (D460).
38429
+ *
38430
+ * ## When this applies, and when it is the wrong thing to reach for
38431
+ *
38432
+ * An absolute-dBFS number in this repo is one of two things, and only one of
38433
+ * them converts:
38434
+ *
38435
+ * - **A statement about the scale** — "-55 dBFS is near silence", "-25 dBFS
38436
+ * is loud". It was true on the ITU-T scale before the epoch and it is true
38437
+ * after. The defect was never in the number; it was that 19 of this hub's
38438
+ * 25 cameras did not obey it. Converting such a number takes something
38439
+ * correct and makes it wrong, in order to preserve a bug.
38440
+ * - **A measurement taken through the old decoder** — a value someone read
38441
+ * off a meter that under-reported by exactly 4× (PCMU) or 8× (PCMA). It
38442
+ * describes a sound that was really {@link G711_SCALE_CORRECTION_DB} dB
38443
+ * louder. That is what this function is for.
38444
+ *
38445
+ * Telling the two apart is a question about PROVENANCE, not about arithmetic,
38446
+ * and it cannot be answered from the number. It is answered by the comment the
38447
+ * author left — which is why `scripts/check-dbfs-era.mts` makes leaving one
38448
+ * mandatory.
38449
+ *
38450
+ * ## Why a function and not a typed-in number
38451
+ *
38452
+ * `-55 + 12.04` written into a source file is, six months later, completely
38453
+ * indistinguishable from a threshold somebody simply preferred. Calling this
38454
+ * keeps the derivation, the law, and the original measurement all visible at
38455
+ * the call site, so a future reader can disagree with the *premise* instead of
38456
+ * having to reverse-engineer the sum.
38457
+ *
38458
+ * **This is not a runtime gain.** It converts an authored CONSTANT once, where
38459
+ * it is declared. It must never be applied to a live sample or a stored
38460
+ * `AudioEvent.dbfs`: the decoder is correct now, and a second authority
38461
+ * adjusting numbers the decoder already got right is the original defect with
38462
+ * an extra place to argue with (D459).
38463
+ */
38464
+ function ituDbfsFromPreEpoch(law, authoredDbfs) {
38465
+ return authoredDbfs + G711_SCALE_CORRECTION_DB[law];
38466
+ }
38467
+ Math.round(ituDbfsFromPreEpoch("PCMU", -55));
38255
38468
  /** Schema defaults — an untouched sub-field must author exactly these. */
38256
38469
  var NC_AUDIO_DEFAULTS = {
38257
38470
  hitPercent: 60,
@@ -38755,7 +38968,7 @@ var AgentUIAddon = class extends BaseAddon {
38755
38968
  capability: adminUiCapability,
38756
38969
  provider: {
38757
38970
  getStaticDir: async () => ({ staticDir: path.resolve(__dirname) }),
38758
- getVersion: async () => ({ version: "1.2.100" })
38971
+ getVersion: async () => ({ version: "1.2.101" })
38759
38972
  }
38760
38973
  }];
38761
38974
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@camstack/addon-agent-ui",
3
- "version": "1.2.100",
3
+ "version": "1.2.101",
4
4
  "description": "Agent UI — lightweight status dashboard served by every agent node",
5
5
  "keywords": [
6
6
  "camstack",