realtime-voice-agents 2.4.0 → 2.5.0

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 (46) hide show
  1. package/README.md +30 -11
  2. package/dist/{BaseRealtimeProvider-CWJ81HIt.d.mts → BaseRealtimeProvider-BJQO-hpu.d.mts} +44 -1
  3. package/dist/{BaseRealtimeProvider-BL75_HHh.d.cts → BaseRealtimeProvider-CO9N8jt-.d.cts} +44 -1
  4. package/dist/{BaseRealtimeProvider-C9C3s8jx.mjs → BaseRealtimeProvider-Cj6JWR2k.mjs} +1 -1
  5. package/dist/{BaseRealtimeProvider-C2mRn1V_.cjs → BaseRealtimeProvider-ZfFzijdr.cjs} +1 -1
  6. package/dist/{GeminiLiveProvider-Cc1dkxW6.d.cts → GeminiLiveProvider-C_LQCTX5.d.mts} +1 -1
  7. package/dist/{GeminiLiveProvider-TvY_cQQZ.d.mts → GeminiLiveProvider-DM-GwD0w.d.cts} +1 -1
  8. package/dist/{InMemorySessionStore-CRBmmCA6.d.cts → InMemorySessionStore-BlsyPnIp.d.cts} +2 -0
  9. package/dist/{InMemorySessionStore-CRBmmCA6.d.mts → InMemorySessionStore-BlsyPnIp.d.mts} +2 -0
  10. package/dist/{OpenAICompatibleProvider-D-2OOVBU.mjs → OpenAICompatibleProvider-Dqje-boq.mjs} +3 -3
  11. package/dist/{OpenAICompatibleProvider-Mp0Mefbh.cjs → OpenAICompatibleProvider-j2Nza2q2.cjs} +8 -2
  12. package/dist/{events-BylBSBW-.mjs → events-D-pvCH_F.mjs} +2 -1
  13. package/dist/{events-BxDTIKKq.cjs → events-DWX9535M.cjs} +2 -1
  14. package/dist/gemini.cjs +1 -1
  15. package/dist/gemini.d.cts +2 -2
  16. package/dist/gemini.d.mts +2 -2
  17. package/dist/gemini.mjs +1 -1
  18. package/dist/gpt-live.cjs +954 -0
  19. package/dist/gpt-live.d.cts +261 -0
  20. package/dist/gpt-live.d.mts +261 -0
  21. package/dist/gpt-live.mjs +936 -0
  22. package/dist/index.cjs +116 -19
  23. package/dist/index.d.cts +7 -3
  24. package/dist/index.d.mts +7 -3
  25. package/dist/index.mjs +116 -19
  26. package/dist/openai.cjs +2 -2
  27. package/dist/openai.d.cts +1 -1
  28. package/dist/openai.d.mts +1 -1
  29. package/dist/openai.mjs +2 -2
  30. package/dist/{rest-BYqiVOhe.mjs → rest-D-DWWVIj.mjs} +1 -1
  31. package/dist/{rest-BvUKut_k.cjs → rest-OR4VhEif.cjs} +1 -1
  32. package/dist/{session-config-CbifLlkV.mjs → session-config-C31WZESg.mjs} +1 -1
  33. package/dist/{session-config-CqJm2Kxz.cjs → session-config-CYjxBqpF.cjs} +1 -1
  34. package/dist/store.d.cts +1 -1
  35. package/dist/store.d.mts +1 -1
  36. package/dist/testing.cjs +376 -0
  37. package/dist/testing.d.cts +119 -2
  38. package/dist/testing.d.mts +119 -2
  39. package/dist/testing.mjs +374 -2
  40. package/dist/twilio.cjs +1 -1
  41. package/dist/twilio.mjs +1 -1
  42. package/dist/xai.cjs +3 -3
  43. package/dist/xai.d.cts +1 -1
  44. package/dist/xai.d.mts +1 -1
  45. package/dist/xai.mjs +3 -3
  46. package/package.json +14 -2
@@ -1,4 +1,4 @@
1
- const require_events = require("./events-BxDTIKKq.cjs");
1
+ const require_events = require("./events-DWX9535M.cjs");
2
2
  //#region src/twilio/messages.ts
3
3
  const INBOUND_EVENTS = /* @__PURE__ */ new Set([
4
4
  "connected",
@@ -1,4 +1,4 @@
1
- import { n as deepMerge } from "./BaseRealtimeProvider-C9C3s8jx.mjs";
1
+ import { n as deepMerge } from "./BaseRealtimeProvider-Cj6JWR2k.mjs";
2
2
  //#region src/providers/openai-compatible/session-config.ts
3
3
  /**
4
4
  * session.update payload construction — GA Realtime API only.
@@ -1,4 +1,4 @@
1
- const require_BaseRealtimeProvider = require("./BaseRealtimeProvider-C2mRn1V_.cjs");
1
+ const require_BaseRealtimeProvider = require("./BaseRealtimeProvider-ZfFzijdr.cjs");
2
2
  //#region src/providers/openai-compatible/session-config.ts
3
3
  /**
4
4
  * session.update payload construction — GA Realtime API only.
package/dist/store.d.cts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as UsageInfo, n as SessionStore, o as HandoffRecord, r as CallSnapshot, s as TranscriptEntry, t as InMemorySessionStore } from "./InMemorySessionStore-CRBmmCA6.cjs";
1
+ import { i as UsageInfo, n as SessionStore, o as HandoffRecord, r as CallSnapshot, s as TranscriptEntry, t as InMemorySessionStore } from "./InMemorySessionStore-BlsyPnIp.cjs";
2
2
  export { type CallSnapshot, type HandoffRecord, InMemorySessionStore, type SessionStore, type TranscriptEntry, type UsageInfo };
package/dist/store.d.mts CHANGED
@@ -1,2 +1,2 @@
1
- import { i as UsageInfo, n as SessionStore, o as HandoffRecord, r as CallSnapshot, s as TranscriptEntry, t as InMemorySessionStore } from "./InMemorySessionStore-CRBmmCA6.mjs";
1
+ import { i as UsageInfo, n as SessionStore, o as HandoffRecord, r as CallSnapshot, s as TranscriptEntry, t as InMemorySessionStore } from "./InMemorySessionStore-BlsyPnIp.mjs";
2
2
  export { type CallSnapshot, type HandoffRecord, InMemorySessionStore, type SessionStore, type TranscriptEntry, type UsageInfo };
package/dist/testing.cjs CHANGED
@@ -563,9 +563,385 @@ var FakeGeminiLive = class {
563
563
  }
564
564
  };
565
565
  //#endregion
566
+ //#region src/testing/FakeGptLiveServer.ts
567
+ let sessionCounter = 0;
568
+ let callCounter = 0;
569
+ /** `ms` of base64 μ-law digital silence, in 100 ms deltas like the real stream. */
570
+ function mulawSilenceDeltas(ms) {
571
+ const deltas = [];
572
+ for (let sent = 0; sent < ms; sent += 100) {
573
+ const len = Math.min(100, ms - sent) * 8;
574
+ deltas.push(Buffer.alloc(len, 255).toString("base64"));
575
+ }
576
+ return deltas;
577
+ }
578
+ /** `ms` of a 440 Hz tone at ≈ −20 dBFS as one base64 μ-law delta (reads as speech to the gate). */
579
+ function mulawToneBase64(ms, amplitude = 3200) {
580
+ const samples = ms * 8;
581
+ const pcm = new Int16Array(samples);
582
+ for (let i = 0; i < samples; i++) pcm[i] = Math.round(amplitude * Math.sin(2 * Math.PI * 440 * i / 8e3));
583
+ return Buffer.from(require_mulaw.pcm16ToMulaw(pcm)).toString("base64");
584
+ }
585
+ var FakeGptLiveConnection = class {
586
+ socket;
587
+ /** Every parsed client → server frame, in order. */
588
+ received = [];
589
+ upgradeHeaders;
590
+ /** The resolved session sent back in `session.started`. */
591
+ session = null;
592
+ /** Running session-timeline position for scripted speech / transcripts. */
593
+ timelineMs = 0;
594
+ server;
595
+ constructor(server, socket, upgradeHeaders = {}) {
596
+ this.server = server;
597
+ this.socket = socket;
598
+ this.upgradeHeaders = upgradeHeaders;
599
+ }
600
+ /** The `session` object of the client's `session.start`, once received. */
601
+ get startFrame() {
602
+ return this.received.find((f) => f.type === "session.start");
603
+ }
604
+ /** Base64 payloads from `session.input_audio.append` frames. */
605
+ get appendedAudio() {
606
+ return this.received.filter((f) => f.type === "session.input_audio.append").map((f) => f.audio);
607
+ }
608
+ /** Text appends (instructions / thinking / commentary), in order. */
609
+ get appends() {
610
+ return this.received.filter((f) => /^session\.(instructions|thinking|commentary)\.append$/.test(f.type)).map((f) => ({
611
+ type: f.type,
612
+ content: f.content,
613
+ delegation_id: f.delegation_id ?? null
614
+ }));
615
+ }
616
+ eventsOfType(type) {
617
+ return this.received.filter((f) => f.type === type);
618
+ }
619
+ async waitForEvent(predicate, timeoutMs = 2e3) {
620
+ const matches = typeof predicate === "string" ? (frame) => frame.type === predicate : predicate;
621
+ const deadline = Date.now() + timeoutMs;
622
+ let seen = 0;
623
+ while (Date.now() < deadline) {
624
+ for (; seen < this.received.length; seen++) {
625
+ const frame = this.received[seen];
626
+ if (matches(frame)) return frame;
627
+ }
628
+ await (0, node_timers_promises.setTimeout)(5);
629
+ }
630
+ throw new Error(`timed out waiting for client event; got: ${this.received.map((f) => f.type).join(", ")}`);
631
+ }
632
+ send(frame) {
633
+ if (this.socket.readyState === this.socket.OPEN) this.socket.send(JSON.stringify(frame));
634
+ }
635
+ /** Stream one utterance: speech chunks, then silence that closes the gate, then its transcript. */
636
+ sendSpeech(options) {
637
+ const startMs = options.startMs ?? this.timelineMs;
638
+ let cursor = startMs;
639
+ for (const chunk of options.chunks) {
640
+ this.send({
641
+ type: "session.output_audio.delta",
642
+ event_id: `evt_${Date.now()}`,
643
+ delta: chunk
644
+ });
645
+ cursor += Buffer.from(chunk, "base64").length / 8 | 0;
646
+ }
647
+ const endMs = cursor;
648
+ for (const chunk of mulawSilenceDeltas(options.silenceMs ?? 1e3)) this.send({
649
+ type: "session.output_audio.delta",
650
+ event_id: `evt_${Date.now()}`,
651
+ delta: chunk
652
+ });
653
+ this.timelineMs = cursor + (options.silenceMs ?? 1e3);
654
+ if (options.transcript) this.sendOutputTranscript(options.transcript, {
655
+ startMs,
656
+ endMs
657
+ });
658
+ return {
659
+ startMs,
660
+ endMs
661
+ };
662
+ }
663
+ /** Continuous idle output: `ms` of digital silence (what the real stream sends while quiet). */
664
+ sendSilence(ms) {
665
+ for (const chunk of mulawSilenceDeltas(ms)) this.send({
666
+ type: "session.output_audio.delta",
667
+ event_id: `evt_${Date.now()}`,
668
+ delta: chunk
669
+ });
670
+ this.timelineMs += ms;
671
+ }
672
+ /** Caller transcript, one fragment per word across [startMs, endMs] on the session timeline. */
673
+ sendInputTranscript(text, range = {}) {
674
+ this.sendFragments("session.input_transcript.delta", text, range);
675
+ }
676
+ sendOutputTranscript(text, range = {}) {
677
+ this.sendFragments("session.output_transcript.delta", text, range);
678
+ }
679
+ /** A backend function call: delegation created, then the call in a `response.event` envelope. */
680
+ sendFunctionCall(options) {
681
+ const callId = options.callId ?? `call_${++callCounter}`;
682
+ const delegationId = options.delegationId ?? `item_${callCounter}`;
683
+ this.send({
684
+ type: "session.delegation.created",
685
+ event_id: `evt_${Date.now()}`,
686
+ offset_ms: this.timelineMs,
687
+ delegation: {
688
+ id: delegationId,
689
+ type: "delegation",
690
+ target: "responses",
691
+ response_id: `resp_${callCounter}`
692
+ }
693
+ });
694
+ this.send({
695
+ type: "response.event",
696
+ event_id: `evt_${Date.now()}`,
697
+ delegation_id: delegationId,
698
+ event: {
699
+ type: "response.output_item.done",
700
+ output_index: 0,
701
+ item: {
702
+ type: "function_call",
703
+ id: `fc_${callCounter}`,
704
+ call_id: callId,
705
+ name: options.name,
706
+ arguments: options.argumentsJson ?? "{}",
707
+ status: "completed"
708
+ }
709
+ }
710
+ });
711
+ return callId;
712
+ }
713
+ /** The backend finished a response (carries token usage). */
714
+ sendBackendCompleted(options = {}) {
715
+ this.send({
716
+ type: "response.event",
717
+ event_id: `evt_${Date.now()}`,
718
+ delegation_id: options.delegationId ?? null,
719
+ event: {
720
+ type: "response.completed",
721
+ response: {
722
+ id: `resp_${Date.now()}`,
723
+ status: "completed",
724
+ usage: options.usage ?? {
725
+ input_tokens: 100,
726
+ output_tokens: 10,
727
+ total_tokens: 110
728
+ },
729
+ output: options.text ? [{
730
+ type: "message",
731
+ content: [{
732
+ type: "output_text",
733
+ text: options.text
734
+ }]
735
+ }] : []
736
+ }
737
+ }
738
+ });
739
+ }
740
+ /** Cumulative session seconds, like the real 15 s ticks. */
741
+ sendUsage(seconds, contextRatio = .01) {
742
+ this.send({
743
+ type: "session.usage.updated",
744
+ event_id: `evt_${Date.now()}`,
745
+ usage: { seconds },
746
+ context_window: { usage_ratio: contextRatio }
747
+ });
748
+ }
749
+ sendError(error) {
750
+ this.send({
751
+ type: "error",
752
+ event_id: `evt_${Date.now()}`,
753
+ error
754
+ });
755
+ }
756
+ /** Server-side session end (`expired`, `content`…): session.closed then the socket. */
757
+ closeSession(reason, usageSeconds = 0) {
758
+ this.send({
759
+ type: "session.closed",
760
+ event_id: `evt_${Date.now()}`,
761
+ reason,
762
+ usage: { seconds: usageSeconds },
763
+ session: this.session
764
+ });
765
+ this.socket.close(1e3, reason);
766
+ }
767
+ drop(code = 1011, reason = "fake server drop") {
768
+ this.socket.close(code, reason);
769
+ }
770
+ sendFragments(type, text, range) {
771
+ const words = text.split(/(\s+)/).filter((w) => w.length > 0);
772
+ const startMs = range.startMs ?? this.timelineMs;
773
+ const endMs = range.endMs ?? startMs + Math.max(200, words.length * 200);
774
+ const step = words.length > 0 ? (endMs - startMs) / words.length : 0;
775
+ words.forEach((word, index) => {
776
+ const s = Math.round(startMs + index * step);
777
+ const e = Math.round(index === words.length - 1 ? endMs : startMs + (index + 1) * step);
778
+ this.send({
779
+ type,
780
+ event_id: `evt_${Date.now()}_${index}`,
781
+ delta: word,
782
+ start_ms: s,
783
+ end_ms: e
784
+ });
785
+ });
786
+ if (range.startMs === void 0) this.timelineMs = Math.max(this.timelineMs, endMs);
787
+ }
788
+ /** @internal server plumbing */
789
+ handleClientFrame(frame) {
790
+ this.received.push(frame);
791
+ const options = this.server.options;
792
+ if (frame.type === "session.start") {
793
+ if (options.rejectStart) {
794
+ this.send({
795
+ type: "error",
796
+ event_id: `evt_${Date.now()}`,
797
+ error: {
798
+ type: "invalid_request_error",
799
+ ...options.rejectStart,
800
+ client_event_id: frame.event_id
801
+ }
802
+ });
803
+ return;
804
+ }
805
+ this.session = {
806
+ id: `live_fake_${++sessionCounter}`,
807
+ expires_at: Math.floor(Date.now() / 1e3) + (options.sessionTtlSeconds ?? 7200),
808
+ ...frame.session
809
+ };
810
+ this.send({
811
+ type: "session.started",
812
+ event_id: `evt_${Date.now()}`,
813
+ client_event_id: frame.event_id,
814
+ session: this.session
815
+ });
816
+ return;
817
+ }
818
+ if (frame.type === "session.close") {
819
+ this.send({
820
+ type: "session.closed",
821
+ event_id: `evt_${Date.now()}`,
822
+ client_event_id: frame.event_id,
823
+ reason: "close_requested",
824
+ usage: { seconds: Math.round(this.timelineMs / 1e3) },
825
+ session: this.session
826
+ });
827
+ this.socket.close(1e3, "close_requested");
828
+ return;
829
+ }
830
+ if (options.autoAck === false) return;
831
+ const ackType = {
832
+ "session.instructions.append": "session.instructions.appended",
833
+ "session.thinking.append": "session.thinking.appended",
834
+ "session.commentary.append": "session.commentary.appended",
835
+ "session.update": "session.updated",
836
+ "session.input_audio.mute": "session.input_audio.muted",
837
+ "session.input_audio.unmute": "session.input_audio.unmuted"
838
+ }[frame.type];
839
+ if (!ackType) return;
840
+ const ack = {
841
+ type: ackType,
842
+ event_id: `evt_${Date.now()}`,
843
+ client_event_id: frame.event_id
844
+ };
845
+ if (ackType.endsWith("appended")) {
846
+ ack.start_ms = this.timelineMs;
847
+ ack.end_ms = this.timelineMs + 200;
848
+ }
849
+ if (ackType === "session.updated") ack.session = {
850
+ ...this.session,
851
+ ...frame.session
852
+ };
853
+ this.send(ack);
854
+ }
855
+ };
856
+ var FakeGptLiveServer = class FakeGptLiveServer {
857
+ connections = [];
858
+ refuseConnections;
859
+ refusedConnections = 0;
860
+ rejectUpgrade;
861
+ rejectedUpgrades = 0;
862
+ url;
863
+ /** @internal */
864
+ options;
865
+ wss;
866
+ constructor(wss, url, options) {
867
+ this.wss = wss;
868
+ this.url = url;
869
+ this.options = options;
870
+ this.refuseConnections = options.refuseConnections ?? false;
871
+ this.rejectUpgrade = options.rejectUpgrade ?? null;
872
+ wss.on("connection", (socket, request) => {
873
+ if (this.refuseConnections) {
874
+ this.refusedConnections++;
875
+ socket.close(1011, "fake server refusing sessions");
876
+ return;
877
+ }
878
+ const connection = new FakeGptLiveConnection(this, socket, request.headers);
879
+ this.connections.push(connection);
880
+ socket.on("message", (raw) => {
881
+ let frame;
882
+ try {
883
+ frame = JSON.parse(raw.toString());
884
+ } catch {
885
+ return;
886
+ }
887
+ connection.handleClientFrame(frame);
888
+ });
889
+ });
890
+ }
891
+ static async start(options = {}) {
892
+ const holder = {};
893
+ const wss = new ws.WebSocketServer({
894
+ port: 0,
895
+ host: "127.0.0.1",
896
+ verifyClient: (_info, done) => {
897
+ const reject = holder.server?.rejectUpgrade;
898
+ if (reject) {
899
+ holder.server.rejectedUpgrades++;
900
+ done(false, reject.status, reject.body ?? "rejected by fake server");
901
+ return;
902
+ }
903
+ done(true);
904
+ }
905
+ });
906
+ await new Promise((resolve, reject) => {
907
+ wss.once("listening", resolve);
908
+ wss.once("error", reject);
909
+ });
910
+ const address = wss.address();
911
+ if (typeof address === "string" || address === null) throw new Error("no server address");
912
+ const server = new FakeGptLiveServer(wss, `ws://127.0.0.1:${address.port}`, options);
913
+ holder.server = server;
914
+ return server;
915
+ }
916
+ get latest() {
917
+ const connection = this.connections[this.connections.length - 1];
918
+ if (!connection) throw new Error("no connections yet");
919
+ return connection;
920
+ }
921
+ async waitForConnection(timeoutMs = 2e3) {
922
+ const count = this.connections.length;
923
+ const deadline = Date.now() + timeoutMs;
924
+ while (Date.now() < deadline) {
925
+ if (this.connections.length > count) return this.connections[this.connections.length - 1];
926
+ await (0, node_timers_promises.setTimeout)(5);
927
+ }
928
+ throw new Error("timed out waiting for a provider connection");
929
+ }
930
+ async close() {
931
+ for (const connection of this.connections) try {
932
+ connection.socket.terminate();
933
+ } catch {}
934
+ await new Promise((resolve) => this.wss.close(() => resolve()));
935
+ }
936
+ };
937
+ //#endregion
566
938
  exports.FakeGeminiLive = FakeGeminiLive;
567
939
  exports.FakeGeminiSession = FakeGeminiSession;
940
+ exports.FakeGptLiveConnection = FakeGptLiveConnection;
941
+ exports.FakeGptLiveServer = FakeGptLiveServer;
568
942
  exports.FakeOpenAIConnection = FakeOpenAIConnection;
569
943
  exports.FakeOpenAIServer = FakeOpenAIServer;
570
944
  exports.FakeTwilioMediaStream = FakeTwilioMediaStream;
571
945
  exports.mulawSilenceBase64 = mulawSilenceBase64;
946
+ exports.mulawSilenceDeltas = mulawSilenceDeltas;
947
+ exports.mulawToneBase64 = mulawToneBase64;
@@ -1,4 +1,4 @@
1
- import { a as GeminiLiveSessionLike, n as GeminiLiveConnector, t as GeminiConnectParams } from "./GeminiLiveProvider-Cc1dkxW6.cjs";
1
+ import { a as GeminiLiveSessionLike, n as GeminiLiveConnector, t as GeminiConnectParams } from "./GeminiLiveProvider-DM-GwD0w.cjs";
2
2
  import { i as WebSocketLike } from "./transport-B_PJFIVd.cjs";
3
3
  import { IncomingHttpHeaders } from "node:http";
4
4
  import { WebSocket } from "ws";
@@ -218,4 +218,121 @@ declare class FakeGeminiLive {
218
218
  waitForSessions(count: number, timeoutMs?: number): Promise<FakeGeminiSession>;
219
219
  }
220
220
  //#endregion
221
- export { type FakeAudioResponseOptions, type FakeConnectOptions, FakeGeminiLive, FakeGeminiSession, FakeOpenAIConnection, FakeOpenAIServer, type FakeOpenAIServerOptions, FakeTwilioMediaStream, mulawSilenceBase64 };
221
+ //#region src/testing/FakeGptLiveServer.d.ts
222
+ interface FakeGptLiveServerOptions {
223
+ /** Auto-ack appends / session.update with their `…ed` event. Default true. */
224
+ autoAck?: boolean;
225
+ /** Reject every `session.start` with this error (strict-schema style). */
226
+ rejectStart?: {
227
+ code: string;
228
+ message: string;
229
+ param?: string;
230
+ };
231
+ /** Close each new socket before `session.started` (provider down). Mutable at runtime. */
232
+ refuseConnections?: boolean;
233
+ /** Reject the HTTP upgrade itself (401 bad key, 403 no access…). Mutable at runtime. */
234
+ rejectUpgrade?: {
235
+ status: number;
236
+ body?: string;
237
+ };
238
+ /** Seconds until `expires_at` in `session.started`. Default 7200 (the real limit). */
239
+ sessionTtlSeconds?: number;
240
+ }
241
+ interface FakeSpeechOptions {
242
+ /** Base64 μ-law deltas of the utterance (use `mulawToneBase64`). */
243
+ chunks: string[];
244
+ /** Digital silence streamed after the chunks, closing the gate. Default 1000 (> the 800 ms quiet window). */
245
+ silenceMs?: number;
246
+ /** Output transcript sent as one fragment per word, on the session timeline. */
247
+ transcript?: string;
248
+ /** Session-timeline position of the utterance. Default: after the previous one. */
249
+ startMs?: number;
250
+ }
251
+ /** `ms` of base64 μ-law digital silence, in 100 ms deltas like the real stream. */
252
+ declare function mulawSilenceDeltas(ms: number): string[];
253
+ /** `ms` of a 440 Hz tone at ≈ −20 dBFS as one base64 μ-law delta (reads as speech to the gate). */
254
+ declare function mulawToneBase64(ms: number, amplitude?: number): string;
255
+ declare class FakeGptLiveConnection {
256
+ readonly socket: WebSocket;
257
+ /** Every parsed client → server frame, in order. */
258
+ readonly received: Array<Record<string, any>>;
259
+ readonly upgradeHeaders: IncomingHttpHeaders;
260
+ /** The resolved session sent back in `session.started`. */
261
+ session: Record<string, any> | null;
262
+ /** Running session-timeline position for scripted speech / transcripts. */
263
+ timelineMs: number;
264
+ private readonly server;
265
+ constructor(server: FakeGptLiveServer, socket: WebSocket, upgradeHeaders?: IncomingHttpHeaders);
266
+ /** The `session` object of the client's `session.start`, once received. */
267
+ get startFrame(): Record<string, any> | undefined;
268
+ /** Base64 payloads from `session.input_audio.append` frames. */
269
+ get appendedAudio(): string[];
270
+ /** Text appends (instructions / thinking / commentary), in order. */
271
+ get appends(): Array<{
272
+ type: string;
273
+ content: string;
274
+ delegation_id: string | null;
275
+ }>;
276
+ eventsOfType(type: string): Array<Record<string, any>>;
277
+ waitForEvent(predicate: string | ((frame: Record<string, any>) => boolean), timeoutMs?: number): Promise<Record<string, any>>;
278
+ send(frame: Record<string, unknown>): void;
279
+ /** Stream one utterance: speech chunks, then silence that closes the gate, then its transcript. */
280
+ sendSpeech(options: FakeSpeechOptions): {
281
+ startMs: number;
282
+ endMs: number;
283
+ };
284
+ /** Continuous idle output: `ms` of digital silence (what the real stream sends while quiet). */
285
+ sendSilence(ms: number): void;
286
+ /** Caller transcript, one fragment per word across [startMs, endMs] on the session timeline. */
287
+ sendInputTranscript(text: string, range?: {
288
+ startMs?: number;
289
+ endMs?: number;
290
+ }): void;
291
+ sendOutputTranscript(text: string, range?: {
292
+ startMs?: number;
293
+ endMs?: number;
294
+ }): void;
295
+ /** A backend function call: delegation created, then the call in a `response.event` envelope. */
296
+ sendFunctionCall(options: {
297
+ name: string;
298
+ argumentsJson?: string;
299
+ callId?: string;
300
+ delegationId?: string;
301
+ }): string;
302
+ /** The backend finished a response (carries token usage). */
303
+ sendBackendCompleted(options?: {
304
+ delegationId?: string;
305
+ usage?: Record<string, unknown>;
306
+ text?: string;
307
+ }): void;
308
+ /** Cumulative session seconds, like the real 15 s ticks. */
309
+ sendUsage(seconds: number, contextRatio?: number): void;
310
+ sendError(error: Record<string, unknown>): void;
311
+ /** Server-side session end (`expired`, `content`…): session.closed then the socket. */
312
+ closeSession(reason: 'expired' | 'content' | 'remote_hangup' | 'connection_lost' | 'close_requested', usageSeconds?: number): void;
313
+ drop(code?: number, reason?: string): void;
314
+ private sendFragments;
315
+ /** @internal server plumbing */
316
+ handleClientFrame(frame: Record<string, any>): void;
317
+ }
318
+ declare class FakeGptLiveServer {
319
+ readonly connections: FakeGptLiveConnection[];
320
+ refuseConnections: boolean;
321
+ refusedConnections: number;
322
+ rejectUpgrade: {
323
+ status: number;
324
+ body?: string;
325
+ } | null;
326
+ rejectedUpgrades: number;
327
+ readonly url: string;
328
+ /** @internal */
329
+ readonly options: FakeGptLiveServerOptions;
330
+ private readonly wss;
331
+ private constructor();
332
+ static start(options?: FakeGptLiveServerOptions): Promise<FakeGptLiveServer>;
333
+ get latest(): FakeGptLiveConnection;
334
+ waitForConnection(timeoutMs?: number): Promise<FakeGptLiveConnection>;
335
+ close(): Promise<void>;
336
+ }
337
+ //#endregion
338
+ export { type FakeAudioResponseOptions, type FakeConnectOptions, FakeGeminiLive, FakeGeminiSession, FakeGptLiveConnection, FakeGptLiveServer, type FakeGptLiveServerOptions, FakeOpenAIConnection, FakeOpenAIServer, type FakeOpenAIServerOptions, type FakeSpeechOptions, FakeTwilioMediaStream, mulawSilenceBase64, mulawSilenceDeltas, mulawToneBase64 };
@@ -1,4 +1,4 @@
1
- import { a as GeminiLiveSessionLike, n as GeminiLiveConnector, t as GeminiConnectParams } from "./GeminiLiveProvider-TvY_cQQZ.mjs";
1
+ import { a as GeminiLiveSessionLike, n as GeminiLiveConnector, t as GeminiConnectParams } from "./GeminiLiveProvider-C_LQCTX5.mjs";
2
2
  import { i as WebSocketLike } from "./transport-CEaLFV4E.mjs";
3
3
  import { WebSocket } from "ws";
4
4
  import { IncomingHttpHeaders } from "node:http";
@@ -218,4 +218,121 @@ declare class FakeGeminiLive {
218
218
  waitForSessions(count: number, timeoutMs?: number): Promise<FakeGeminiSession>;
219
219
  }
220
220
  //#endregion
221
- export { type FakeAudioResponseOptions, type FakeConnectOptions, FakeGeminiLive, FakeGeminiSession, FakeOpenAIConnection, FakeOpenAIServer, type FakeOpenAIServerOptions, FakeTwilioMediaStream, mulawSilenceBase64 };
221
+ //#region src/testing/FakeGptLiveServer.d.ts
222
+ interface FakeGptLiveServerOptions {
223
+ /** Auto-ack appends / session.update with their `…ed` event. Default true. */
224
+ autoAck?: boolean;
225
+ /** Reject every `session.start` with this error (strict-schema style). */
226
+ rejectStart?: {
227
+ code: string;
228
+ message: string;
229
+ param?: string;
230
+ };
231
+ /** Close each new socket before `session.started` (provider down). Mutable at runtime. */
232
+ refuseConnections?: boolean;
233
+ /** Reject the HTTP upgrade itself (401 bad key, 403 no access…). Mutable at runtime. */
234
+ rejectUpgrade?: {
235
+ status: number;
236
+ body?: string;
237
+ };
238
+ /** Seconds until `expires_at` in `session.started`. Default 7200 (the real limit). */
239
+ sessionTtlSeconds?: number;
240
+ }
241
+ interface FakeSpeechOptions {
242
+ /** Base64 μ-law deltas of the utterance (use `mulawToneBase64`). */
243
+ chunks: string[];
244
+ /** Digital silence streamed after the chunks, closing the gate. Default 1000 (> the 800 ms quiet window). */
245
+ silenceMs?: number;
246
+ /** Output transcript sent as one fragment per word, on the session timeline. */
247
+ transcript?: string;
248
+ /** Session-timeline position of the utterance. Default: after the previous one. */
249
+ startMs?: number;
250
+ }
251
+ /** `ms` of base64 μ-law digital silence, in 100 ms deltas like the real stream. */
252
+ declare function mulawSilenceDeltas(ms: number): string[];
253
+ /** `ms` of a 440 Hz tone at ≈ −20 dBFS as one base64 μ-law delta (reads as speech to the gate). */
254
+ declare function mulawToneBase64(ms: number, amplitude?: number): string;
255
+ declare class FakeGptLiveConnection {
256
+ readonly socket: WebSocket;
257
+ /** Every parsed client → server frame, in order. */
258
+ readonly received: Array<Record<string, any>>;
259
+ readonly upgradeHeaders: IncomingHttpHeaders;
260
+ /** The resolved session sent back in `session.started`. */
261
+ session: Record<string, any> | null;
262
+ /** Running session-timeline position for scripted speech / transcripts. */
263
+ timelineMs: number;
264
+ private readonly server;
265
+ constructor(server: FakeGptLiveServer, socket: WebSocket, upgradeHeaders?: IncomingHttpHeaders);
266
+ /** The `session` object of the client's `session.start`, once received. */
267
+ get startFrame(): Record<string, any> | undefined;
268
+ /** Base64 payloads from `session.input_audio.append` frames. */
269
+ get appendedAudio(): string[];
270
+ /** Text appends (instructions / thinking / commentary), in order. */
271
+ get appends(): Array<{
272
+ type: string;
273
+ content: string;
274
+ delegation_id: string | null;
275
+ }>;
276
+ eventsOfType(type: string): Array<Record<string, any>>;
277
+ waitForEvent(predicate: string | ((frame: Record<string, any>) => boolean), timeoutMs?: number): Promise<Record<string, any>>;
278
+ send(frame: Record<string, unknown>): void;
279
+ /** Stream one utterance: speech chunks, then silence that closes the gate, then its transcript. */
280
+ sendSpeech(options: FakeSpeechOptions): {
281
+ startMs: number;
282
+ endMs: number;
283
+ };
284
+ /** Continuous idle output: `ms` of digital silence (what the real stream sends while quiet). */
285
+ sendSilence(ms: number): void;
286
+ /** Caller transcript, one fragment per word across [startMs, endMs] on the session timeline. */
287
+ sendInputTranscript(text: string, range?: {
288
+ startMs?: number;
289
+ endMs?: number;
290
+ }): void;
291
+ sendOutputTranscript(text: string, range?: {
292
+ startMs?: number;
293
+ endMs?: number;
294
+ }): void;
295
+ /** A backend function call: delegation created, then the call in a `response.event` envelope. */
296
+ sendFunctionCall(options: {
297
+ name: string;
298
+ argumentsJson?: string;
299
+ callId?: string;
300
+ delegationId?: string;
301
+ }): string;
302
+ /** The backend finished a response (carries token usage). */
303
+ sendBackendCompleted(options?: {
304
+ delegationId?: string;
305
+ usage?: Record<string, unknown>;
306
+ text?: string;
307
+ }): void;
308
+ /** Cumulative session seconds, like the real 15 s ticks. */
309
+ sendUsage(seconds: number, contextRatio?: number): void;
310
+ sendError(error: Record<string, unknown>): void;
311
+ /** Server-side session end (`expired`, `content`…): session.closed then the socket. */
312
+ closeSession(reason: 'expired' | 'content' | 'remote_hangup' | 'connection_lost' | 'close_requested', usageSeconds?: number): void;
313
+ drop(code?: number, reason?: string): void;
314
+ private sendFragments;
315
+ /** @internal server plumbing */
316
+ handleClientFrame(frame: Record<string, any>): void;
317
+ }
318
+ declare class FakeGptLiveServer {
319
+ readonly connections: FakeGptLiveConnection[];
320
+ refuseConnections: boolean;
321
+ refusedConnections: number;
322
+ rejectUpgrade: {
323
+ status: number;
324
+ body?: string;
325
+ } | null;
326
+ rejectedUpgrades: number;
327
+ readonly url: string;
328
+ /** @internal */
329
+ readonly options: FakeGptLiveServerOptions;
330
+ private readonly wss;
331
+ private constructor();
332
+ static start(options?: FakeGptLiveServerOptions): Promise<FakeGptLiveServer>;
333
+ get latest(): FakeGptLiveConnection;
334
+ waitForConnection(timeoutMs?: number): Promise<FakeGptLiveConnection>;
335
+ close(): Promise<void>;
336
+ }
337
+ //#endregion
338
+ export { type FakeAudioResponseOptions, type FakeConnectOptions, FakeGeminiLive, FakeGeminiSession, FakeGptLiveConnection, FakeGptLiveServer, type FakeGptLiveServerOptions, FakeOpenAIConnection, FakeOpenAIServer, type FakeOpenAIServerOptions, type FakeSpeechOptions, FakeTwilioMediaStream, mulawSilenceBase64, mulawSilenceDeltas, mulawToneBase64 };