@frequencytalk/agent 0.2.3 → 0.2.4
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.
- package/dist/cli.js +132 -12
- package/dist/cli.js.map +1 -1
- package/dist/index.d.ts +35 -6
- package/dist/index.js +132 -12
- package/dist/index.js.map +1 -1
- package/dist/mcp/server.js +132 -12
- package/dist/mcp/server.js.map +1 -1
- package/package.json +1 -1
- package/server.json +2 -2
package/dist/mcp/server.js
CHANGED
|
@@ -4653,6 +4653,9 @@ var BlockedWordsSchema = z14.object({ words: z14.array(BlockedWordSchema).max(2e
|
|
|
4653
4653
|
|
|
4654
4654
|
// ../shared/dist/nativeTransport.js
|
|
4655
4655
|
var NATIVE_TRANSPORT_VERSION = 1;
|
|
4656
|
+
var NATIVE_TRANSPORT_WIRE_V2 = 2;
|
|
4657
|
+
var FLAG_CONTROL = 16;
|
|
4658
|
+
var FLAG_CONTENT_KEY = 32;
|
|
4656
4659
|
var NODE_SEQUENCE_BASE = 1n << 63n;
|
|
4657
4660
|
var HEADER = {
|
|
4658
4661
|
/** version (low nibble) + flags (high nibble). */
|
|
@@ -4711,6 +4714,19 @@ var PAYLOAD = {
|
|
|
4711
4714
|
OPUS_OFFSET: 9
|
|
4712
4715
|
};
|
|
4713
4716
|
var PAYLOAD_TYPE = { audio: 0, keepalive: 1, contentKey: 2, videoShard: 3, shareAudio: 4 };
|
|
4717
|
+
var CONTENT_KEY_PAYLOAD = {
|
|
4718
|
+
TYPE_OFFSET: 0,
|
|
4719
|
+
/** uint32. The stream whose audio `K_s` seals. */
|
|
4720
|
+
STREAM_ID_OFFSET: 1,
|
|
4721
|
+
/** uint32, 48 kHz. The talkspurt's timestamp when this key packet was sent; informational. */
|
|
4722
|
+
TIMESTAMP_OFFSET: 5,
|
|
4723
|
+
/** uint32. Monotonic per stream; its LOW BYTE is the generation an audio header carries. */
|
|
4724
|
+
CONTENT_KEY_ID_OFFSET: 9,
|
|
4725
|
+
/** 32 bytes: `K_s`, an AES-256-GCM key. */
|
|
4726
|
+
KEY_OFFSET: 13,
|
|
4727
|
+
LENGTH: 45
|
|
4728
|
+
};
|
|
4729
|
+
var SHARE_CHANNEL_ID = 4294967295;
|
|
4714
4730
|
var VIDEO_SHARD = {
|
|
4715
4731
|
TYPE_OFFSET: 0,
|
|
4716
4732
|
STREAM_ID_OFFSET: 1,
|
|
@@ -4749,8 +4765,13 @@ var PROJECTS_BY_PLATFORM = {
|
|
|
4749
4765
|
// than a rider on `broadcast` (a Windows lane) or `tuner_apple`, for the reason `broadcast` got
|
|
4750
4766
|
// one: the board enforces one in-flight task per PROJECT, so a shared lane makes one app's claim
|
|
4751
4767
|
// answer 409 AGENT_BUSY while the other holds the slot.
|
|
4768
|
+
// `switchboard_apple` is the macOS Switchboard (owner, 2026-11-27: "build switchboard for mac"):
|
|
4769
|
+
// a native build of the same product the Windows `switchboard` lane builds, developed here on the
|
|
4770
|
+
// Mac like `tuner_apple` and `broadcast_apple`. Its own lane rather than a rider on `switchboard`
|
|
4771
|
+
// (a Windows lane) or `switchboard_steamos` (the SteamOS group), for the one-in-flight reason
|
|
4772
|
+
// `broadcast_apple` records above. A Mac lane only: not in the Windows set, not in the SteamOS group.
|
|
4752
4773
|
// The SteamOS group (`STEAMOS_PROJECTS`, above) is on both platforms since 2026-11-03.
|
|
4753
|
-
mac: ["frequency", "tuner_apple", "site", "platform", "broadcast_apple", ...STEAMOS_PROJECTS],
|
|
4774
|
+
mac: ["frequency", "tuner_apple", "site", "platform", "broadcast_apple", "switchboard_apple", ...STEAMOS_PROJECTS],
|
|
4754
4775
|
// `broadcast` is its own lane rather than a rider on `windows` (2026-08-31): the board
|
|
4755
4776
|
// enforces one in-flight task per PROJECT, and `windows` already carries the Jacked
|
|
4756
4777
|
// audio-driver work, so sharing it meant a Broadcast claim answered 409 AGENT_BUSY for
|
|
@@ -5129,6 +5150,8 @@ var NativeSession = class {
|
|
|
5129
5150
|
producing = null;
|
|
5130
5151
|
timestamp = 0;
|
|
5131
5152
|
owners = /* @__PURE__ */ new Map();
|
|
5153
|
+
/** `${connectionId}:${streamId}` -> that stream's content keys (wire v2). */
|
|
5154
|
+
contentKeys = /* @__PURE__ */ new Map();
|
|
5132
5155
|
pending = [];
|
|
5133
5156
|
/** The last 500 signalling events, oldest first. A probe reads them; `waitFor` searches them. */
|
|
5134
5157
|
events = [];
|
|
@@ -5140,7 +5163,7 @@ var NativeSession = class {
|
|
|
5140
5163
|
/** The stale-key watch: consecutive packets that would not open since the last one that did, and when a refresh was last asked for. */
|
|
5141
5164
|
staleRun = 0;
|
|
5142
5165
|
lastStaleRefresh = 0;
|
|
5143
|
-
receiveStats = { frames: 0, unsupportedVersion: 0, unknownChannel: 0, undecryptable: 0, notAudio: 0, misattributed: 0 };
|
|
5166
|
+
receiveStats = { frames: 0, unsupportedVersion: 0, contentKeys: 0, awaitingContentKey: 0, unknownChannel: 0, undecryptable: 0, notAudio: 0, misattributed: 0 };
|
|
5144
5167
|
/** The node-issued datapath identity, 0 until `open()` has authenticated. */
|
|
5145
5168
|
get connectionId() {
|
|
5146
5169
|
return this.connection;
|
|
@@ -5242,7 +5265,7 @@ var NativeSession = class {
|
|
|
5242
5265
|
this.owners.set(streamId, connectionId);
|
|
5243
5266
|
this.options.onStream?.({ streamId, connectionId, producerUserId: event.producerUserId, producerCallsign: event.producerCallsign, channelId: event.channelId });
|
|
5244
5267
|
}
|
|
5245
|
-
if (event.type === "nativeStreamClosed") this.
|
|
5268
|
+
if (event.type === "nativeStreamClosed") this.forgetStream(Number(event.streamId));
|
|
5246
5269
|
if (event.type === "nativeKeysRotated") this.onKeysRotated(String(event.keysetId));
|
|
5247
5270
|
for (const p of [...this.pending]) {
|
|
5248
5271
|
if (p.type === event.type) {
|
|
@@ -5393,12 +5416,24 @@ var NativeSession = class {
|
|
|
5393
5416
|
}
|
|
5394
5417
|
onPacket(packet) {
|
|
5395
5418
|
if (!this.native || packet.length < HEADER.LENGTH + AEAD.TAG_BYTES) return;
|
|
5396
|
-
|
|
5419
|
+
const byte0 = packet[HEADER.VERSION_FLAGS_OFFSET];
|
|
5420
|
+
const version = byte0 & 15;
|
|
5421
|
+
const flags = byte0 & 240;
|
|
5422
|
+
const connectionId = packet.readUInt32BE(HEADER.CONNECTION_ID_OFFSET);
|
|
5423
|
+
const channelNativeId = packet.readUInt32BE(HEADER.CHANNEL_ID_OFFSET);
|
|
5424
|
+
if (version === NATIVE_TRANSPORT_VERSION && flags === FLAG_CONTROL) {
|
|
5425
|
+
this.receiveStats.notAudio += 1;
|
|
5426
|
+
return;
|
|
5427
|
+
}
|
|
5428
|
+
if (version === NATIVE_TRANSPORT_WIRE_V2 && flags === 0 && channelNativeId !== SHARE_CHANNEL_ID) {
|
|
5429
|
+
this.onV2Audio(packet, connectionId, channelNativeId);
|
|
5430
|
+
return;
|
|
5431
|
+
}
|
|
5432
|
+
const keyPacket = version === NATIVE_TRANSPORT_WIRE_V2 && flags === FLAG_CONTENT_KEY;
|
|
5433
|
+
if (!keyPacket && !(version === NATIVE_TRANSPORT_VERSION && flags === 0)) {
|
|
5397
5434
|
this.receiveStats.unsupportedVersion += 1;
|
|
5398
5435
|
return;
|
|
5399
5436
|
}
|
|
5400
|
-
const connectionId = packet.readUInt32BE(HEADER.CONNECTION_ID_OFFSET);
|
|
5401
|
-
const channelNativeId = packet.readUInt32BE(HEADER.CHANNEL_ID_OFFSET);
|
|
5402
5437
|
const entry = Object.values(this.native.channelKeys.keys).find((k) => k.id === channelNativeId);
|
|
5403
5438
|
if (!entry) {
|
|
5404
5439
|
this.receiveStats.unknownChannel += 1;
|
|
@@ -5413,10 +5448,89 @@ var NativeSession = class {
|
|
|
5413
5448
|
return;
|
|
5414
5449
|
}
|
|
5415
5450
|
this.staleRun = 0;
|
|
5451
|
+
if (keyPacket) {
|
|
5452
|
+
this.onContentKey(connectionId, body);
|
|
5453
|
+
return;
|
|
5454
|
+
}
|
|
5416
5455
|
if (body.type !== PAYLOAD_TYPE.audio) {
|
|
5417
5456
|
this.receiveStats.notAudio += 1;
|
|
5418
5457
|
return;
|
|
5419
5458
|
}
|
|
5459
|
+
this.deliver(connectionId, body);
|
|
5460
|
+
}
|
|
5461
|
+
/** A v2 key packet that opened under a channel key: attribute it, then file `K_s` under the stream's home. */
|
|
5462
|
+
onContentKey(connectionId, body) {
|
|
5463
|
+
const rest = body.opus;
|
|
5464
|
+
const restLength = CONTENT_KEY_PAYLOAD.LENGTH - CONTENT_KEY_PAYLOAD.CONTENT_KEY_ID_OFFSET;
|
|
5465
|
+
if (body.type !== PAYLOAD_TYPE.contentKey || rest.length !== restLength) {
|
|
5466
|
+
this.receiveStats.notAudio += 1;
|
|
5467
|
+
return;
|
|
5468
|
+
}
|
|
5469
|
+
const owner = this.owners.get(body.streamId);
|
|
5470
|
+
if (owner === void 0 || owner !== connectionId) {
|
|
5471
|
+
this.receiveStats.misattributed += 1;
|
|
5472
|
+
return;
|
|
5473
|
+
}
|
|
5474
|
+
const contentKeyId = rest.readUInt32BE(0);
|
|
5475
|
+
const key = Buffer.from(rest.subarray(CONTENT_KEY_PAYLOAD.KEY_OFFSET - CONTENT_KEY_PAYLOAD.CONTENT_KEY_ID_OFFSET));
|
|
5476
|
+
const slot = `${connectionId}:${body.streamId}`;
|
|
5477
|
+
let stream = this.contentKeys.get(slot);
|
|
5478
|
+
if (!stream) {
|
|
5479
|
+
stream = { connectionId, streamId: body.streamId, generations: /* @__PURE__ */ new Map() };
|
|
5480
|
+
this.contentKeys.set(slot, stream);
|
|
5481
|
+
}
|
|
5482
|
+
const generation = contentKeyId & 255;
|
|
5483
|
+
const held = stream.generations.get(generation);
|
|
5484
|
+
if (held && held.contentKeyId === contentKeyId) return;
|
|
5485
|
+
stream.generations.delete(generation);
|
|
5486
|
+
stream.generations.set(generation, { contentKeyId, key });
|
|
5487
|
+
while (stream.generations.size > 2) stream.generations.delete(stream.generations.keys().next().value);
|
|
5488
|
+
this.receiveStats.contentKeys += 1;
|
|
5489
|
+
}
|
|
5490
|
+
/**
|
|
5491
|
+
* v2 audio: sealed under `K_s`, found by (connection, home wire id, generation). The stream bound
|
|
5492
|
+
* to that home is tried first; a connection's streams whose home is not yet learned are tried
|
|
5493
|
+
* after (one connection rarely carries more than one), and the first that opens with its own
|
|
5494
|
+
* streamId inside binds the home.
|
|
5495
|
+
*/
|
|
5496
|
+
onV2Audio(packet, connectionId, homeWireId) {
|
|
5497
|
+
const generation = packet[HEADER.KEY_EPOCH_OFFSET];
|
|
5498
|
+
const candidates = [];
|
|
5499
|
+
for (const entry of this.contentKeys.values()) {
|
|
5500
|
+
if (entry.connectionId !== connectionId || !entry.generations.has(generation)) continue;
|
|
5501
|
+
if (entry.homeWireId === homeWireId) candidates.unshift(entry);
|
|
5502
|
+
else if (entry.homeWireId === void 0) candidates.push(entry);
|
|
5503
|
+
}
|
|
5504
|
+
if (candidates.length === 0) {
|
|
5505
|
+
this.receiveStats.awaitingContentKey += 1;
|
|
5506
|
+
return;
|
|
5507
|
+
}
|
|
5508
|
+
for (const stream of candidates) {
|
|
5509
|
+
let body;
|
|
5510
|
+
try {
|
|
5511
|
+
body = open(packet, stream.generations.get(generation).key);
|
|
5512
|
+
} catch {
|
|
5513
|
+
continue;
|
|
5514
|
+
}
|
|
5515
|
+
if (body.type !== PAYLOAD_TYPE.audio) {
|
|
5516
|
+
this.receiveStats.notAudio += 1;
|
|
5517
|
+
return;
|
|
5518
|
+
}
|
|
5519
|
+
if (body.streamId !== stream.streamId) {
|
|
5520
|
+
this.receiveStats.misattributed += 1;
|
|
5521
|
+
return;
|
|
5522
|
+
}
|
|
5523
|
+
if (stream.homeWireId === void 0) {
|
|
5524
|
+
for (const [slot, other] of this.contentKeys) if (other !== stream && other.connectionId === connectionId && other.homeWireId === homeWireId) this.contentKeys.delete(slot);
|
|
5525
|
+
stream.homeWireId = homeWireId;
|
|
5526
|
+
}
|
|
5527
|
+
this.deliver(connectionId, body);
|
|
5528
|
+
return;
|
|
5529
|
+
}
|
|
5530
|
+
this.receiveStats.undecryptable += 1;
|
|
5531
|
+
}
|
|
5532
|
+
/** The owner check and hand-off every opened audio frame goes through, whichever wire version carried it. */
|
|
5533
|
+
deliver(connectionId, body) {
|
|
5420
5534
|
const owner = this.owners.get(body.streamId);
|
|
5421
5535
|
if (owner === void 0 || owner !== connectionId) {
|
|
5422
5536
|
this.receiveStats.misattributed += 1;
|
|
@@ -5427,6 +5541,10 @@ var NativeSession = class {
|
|
|
5427
5541
|
this.options.onAudio?.(frame);
|
|
5428
5542
|
for (const listener of this.audioListeners) listener(frame);
|
|
5429
5543
|
}
|
|
5544
|
+
forgetStream(streamId) {
|
|
5545
|
+
this.owners.delete(streamId);
|
|
5546
|
+
for (const [slot, entry] of this.contentKeys) if (entry.streamId === streamId) this.contentKeys.delete(slot);
|
|
5547
|
+
}
|
|
5430
5548
|
/**
|
|
5431
5549
|
* The backstop for a missed `nativeKeysRotated` (the node announces a rotation only once it
|
|
5432
5550
|
* has a baseline to compare against, so a rotation inside its first poll window is never
|
|
@@ -5493,7 +5611,7 @@ async function createOpus() {
|
|
|
5493
5611
|
return {
|
|
5494
5612
|
encode: (pcm) => enc.encode(Buffer.from(pcm.buffer, pcm.byteOffset, pcm.byteLength)),
|
|
5495
5613
|
decode: (packet) => toInt16(enc.decode(packet)),
|
|
5496
|
-
conceal: () => new Int16Array(
|
|
5614
|
+
conceal: (samples = FRAME_SAMPLES) => new Int16Array(samples),
|
|
5497
5615
|
close: () => enc.delete?.()
|
|
5498
5616
|
};
|
|
5499
5617
|
} catch {
|
|
@@ -5506,7 +5624,7 @@ async function createOpus() {
|
|
|
5506
5624
|
return {
|
|
5507
5625
|
encode: (pcm) => codec.encode(Buffer.from(pcm.buffer, pcm.byteOffset, pcm.byteLength), FRAME_SAMPLES),
|
|
5508
5626
|
decode: (packet) => toInt16(codec.decode(packet)),
|
|
5509
|
-
conceal: () => new Int16Array(
|
|
5627
|
+
conceal: (samples = FRAME_SAMPLES) => new Int16Array(samples),
|
|
5510
5628
|
close: () => codec.delete()
|
|
5511
5629
|
};
|
|
5512
5630
|
}
|
|
@@ -5655,15 +5773,17 @@ var Listener = class {
|
|
|
5655
5773
|
if (!this.options.includeOwn && frame.connectionId === this.session.connectionId) return;
|
|
5656
5774
|
let s = this.streams.get(frame.streamId);
|
|
5657
5775
|
if (!s) {
|
|
5658
|
-
s = { connectionId: frame.connectionId, chunks: [], lastTimestamp: null, first: frame.timestamp };
|
|
5776
|
+
s = { connectionId: frame.connectionId, chunks: [], lastTimestamp: null, lastSamples: 0, first: frame.timestamp };
|
|
5659
5777
|
this.streams.set(frame.streamId, s);
|
|
5660
5778
|
}
|
|
5661
5779
|
if (s.lastTimestamp !== null) {
|
|
5662
|
-
const
|
|
5663
|
-
|
|
5780
|
+
const gap = (frame.timestamp - s.lastTimestamp >>> 0) - s.lastSamples;
|
|
5781
|
+
if (gap > 0 && gap <= 48e3) s.chunks.push(codec.conceal(gap));
|
|
5664
5782
|
}
|
|
5665
|
-
|
|
5783
|
+
const pcm = codec.decode(frame.opus);
|
|
5784
|
+
s.chunks.push(pcm);
|
|
5666
5785
|
s.lastTimestamp = frame.timestamp;
|
|
5786
|
+
s.lastSamples = pcm.length;
|
|
5667
5787
|
};
|
|
5668
5788
|
this.detach = this.session.attachAudio(handler);
|
|
5669
5789
|
}
|