@kodelyth/voice-call 2026.5.42 → 2026.6.2

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 (111) hide show
  1. package/package.json +18 -6
  2. package/api.ts +0 -16
  3. package/cli-metadata.ts +0 -10
  4. package/config-api.ts +0 -12
  5. package/index.test.ts +0 -1075
  6. package/index.ts +0 -863
  7. package/runtime-api.ts +0 -20
  8. package/runtime-entry.ts +0 -1
  9. package/setup-api.ts +0 -47
  10. package/src/allowlist.test.ts +0 -18
  11. package/src/allowlist.ts +0 -19
  12. package/src/cli.test.ts +0 -12
  13. package/src/cli.ts +0 -866
  14. package/src/config-compat.test.ts +0 -130
  15. package/src/config-compat.ts +0 -227
  16. package/src/config.test.ts +0 -542
  17. package/src/config.ts +0 -883
  18. package/src/core-bridge.ts +0 -14
  19. package/src/deep-merge.test.ts +0 -40
  20. package/src/deep-merge.ts +0 -23
  21. package/src/gateway-continue-operation.ts +0 -200
  22. package/src/http-headers.test.ts +0 -16
  23. package/src/http-headers.ts +0 -15
  24. package/src/manager/context.ts +0 -50
  25. package/src/manager/events.test.ts +0 -578
  26. package/src/manager/events.ts +0 -332
  27. package/src/manager/lifecycle.ts +0 -53
  28. package/src/manager/lookup.test.ts +0 -52
  29. package/src/manager/lookup.ts +0 -35
  30. package/src/manager/outbound.test.ts +0 -629
  31. package/src/manager/outbound.ts +0 -508
  32. package/src/manager/state.ts +0 -48
  33. package/src/manager/store.ts +0 -107
  34. package/src/manager/timers.test.ts +0 -127
  35. package/src/manager/timers.ts +0 -113
  36. package/src/manager/twiml.test.ts +0 -13
  37. package/src/manager/twiml.ts +0 -17
  38. package/src/manager.closed-loop.test.ts +0 -259
  39. package/src/manager.inbound-allowlist.test.ts +0 -183
  40. package/src/manager.notify.test.ts +0 -390
  41. package/src/manager.restore.test.ts +0 -310
  42. package/src/manager.test-harness.ts +0 -127
  43. package/src/manager.ts +0 -441
  44. package/src/media-stream.test.ts +0 -953
  45. package/src/media-stream.ts +0 -876
  46. package/src/providers/base.ts +0 -99
  47. package/src/providers/mock.test.ts +0 -86
  48. package/src/providers/mock.ts +0 -185
  49. package/src/providers/plivo.test.ts +0 -93
  50. package/src/providers/plivo.ts +0 -601
  51. package/src/providers/shared/call-status.test.ts +0 -24
  52. package/src/providers/shared/call-status.ts +0 -24
  53. package/src/providers/shared/guarded-json-api.test.ts +0 -127
  54. package/src/providers/shared/guarded-json-api.ts +0 -49
  55. package/src/providers/telnyx.test.ts +0 -489
  56. package/src/providers/telnyx.ts +0 -419
  57. package/src/providers/twilio/api.test.ts +0 -184
  58. package/src/providers/twilio/api.ts +0 -100
  59. package/src/providers/twilio/twiml-policy.test.ts +0 -84
  60. package/src/providers/twilio/twiml-policy.ts +0 -87
  61. package/src/providers/twilio/webhook.ts +0 -34
  62. package/src/providers/twilio.test.ts +0 -607
  63. package/src/providers/twilio.ts +0 -861
  64. package/src/providers/twilio.types.ts +0 -17
  65. package/src/realtime-agent-context.test.ts +0 -101
  66. package/src/realtime-agent-context.ts +0 -149
  67. package/src/realtime-defaults.ts +0 -3
  68. package/src/realtime-fast-context.test.ts +0 -74
  69. package/src/realtime-fast-context.ts +0 -27
  70. package/src/realtime-transcription.runtime.ts +0 -4
  71. package/src/realtime-voice.runtime.ts +0 -5
  72. package/src/response-generator.test.ts +0 -385
  73. package/src/response-generator.ts +0 -348
  74. package/src/response-model.test.ts +0 -71
  75. package/src/response-model.ts +0 -23
  76. package/src/runtime.test.ts +0 -625
  77. package/src/runtime.ts +0 -528
  78. package/src/telephony-audio.test.ts +0 -61
  79. package/src/telephony-audio.ts +0 -12
  80. package/src/telephony-tts.test.ts +0 -196
  81. package/src/telephony-tts.ts +0 -235
  82. package/src/test-fixtures.ts +0 -82
  83. package/src/tts-provider-voice.test.ts +0 -34
  84. package/src/tts-provider-voice.ts +0 -21
  85. package/src/tunnel.test.ts +0 -173
  86. package/src/tunnel.ts +0 -314
  87. package/src/types.ts +0 -311
  88. package/src/utils.test.ts +0 -17
  89. package/src/utils.ts +0 -14
  90. package/src/voice-mapping.test.ts +0 -32
  91. package/src/voice-mapping.ts +0 -65
  92. package/src/webhook/realtime-audio-pacer.test.ts +0 -146
  93. package/src/webhook/realtime-audio-pacer.ts +0 -204
  94. package/src/webhook/realtime-handler.test.ts +0 -1450
  95. package/src/webhook/realtime-handler.ts +0 -1382
  96. package/src/webhook/stale-call-reaper.test.ts +0 -89
  97. package/src/webhook/stale-call-reaper.ts +0 -38
  98. package/src/webhook/stream-frame-adapter.test.ts +0 -187
  99. package/src/webhook/stream-frame-adapter.ts +0 -219
  100. package/src/webhook/tailscale.test.ts +0 -216
  101. package/src/webhook/tailscale.ts +0 -129
  102. package/src/webhook-exposure.test.ts +0 -33
  103. package/src/webhook-exposure.ts +0 -84
  104. package/src/webhook-security.test.ts +0 -813
  105. package/src/webhook-security.ts +0 -982
  106. package/src/webhook.hangup-once.lifecycle.test.ts +0 -179
  107. package/src/webhook.test.ts +0 -1615
  108. package/src/webhook.ts +0 -933
  109. package/src/webhook.types.ts +0 -5
  110. package/src/websocket-test-support.ts +0 -72
  111. package/tsconfig.json +0 -16
@@ -1,173 +0,0 @@
1
- import { EventEmitter } from "node:events";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
-
4
- class FakeChildProcess extends EventEmitter {
5
- readonly stdout = new EventEmitter();
6
- readonly stderr = new EventEmitter();
7
- killedWith: NodeJS.Signals | null = null;
8
-
9
- kill(signal: NodeJS.Signals = "SIGTERM"): boolean {
10
- this.killedWith = signal;
11
- queueMicrotask(() => this.emit("close", null));
12
- return true;
13
- }
14
-
15
- close(code: number | null = 0): void {
16
- this.emit("close", code);
17
- }
18
-
19
- fail(error: Error): void {
20
- this.emit("error", error);
21
- }
22
- }
23
-
24
- const mocks = vi.hoisted(() => ({
25
- spawn: vi.fn(),
26
- getTailscaleDnsName: vi.fn(),
27
- }));
28
-
29
- vi.mock("node:child_process", () => ({
30
- spawn: mocks.spawn,
31
- }));
32
-
33
- vi.mock("./webhook/tailscale.js", () => ({
34
- getTailscaleDnsName: mocks.getTailscaleDnsName,
35
- }));
36
-
37
- import { isNgrokAvailable, startNgrokTunnel, startTailscaleTunnel, startTunnel } from "./tunnel.js";
38
-
39
- function nextProcess(): FakeChildProcess {
40
- const proc = new FakeChildProcess();
41
- mocks.spawn.mockReturnValueOnce(proc as never);
42
- return proc;
43
- }
44
-
45
- function emitNgrokUrl(proc: FakeChildProcess, url: string): void {
46
- proc.stdout.emit("data", Buffer.from(`${JSON.stringify({ msg: "started tunnel", url })}\n`));
47
- }
48
-
49
- describe("voice-call tunnels", () => {
50
- beforeEach(() => {
51
- vi.clearAllMocks();
52
- mocks.getTailscaleDnsName.mockReset();
53
- });
54
-
55
- it("checks ngrok availability from the version command exit code", async () => {
56
- const proc = nextProcess();
57
- const result = isNgrokAvailable();
58
- proc.close(0);
59
-
60
- await expect(result).resolves.toBe(true);
61
- expect(mocks.spawn).toHaveBeenCalledWith("ngrok", ["version"], {
62
- stdio: ["ignore", "pipe", "pipe"],
63
- });
64
- });
65
-
66
- it("treats ngrok spawn failures as unavailable", async () => {
67
- const proc = nextProcess();
68
- const result = isNgrokAvailable();
69
- proc.fail(new Error("spawn ngrok ENOENT"));
70
-
71
- await expect(result).resolves.toBe(false);
72
- });
73
-
74
- it("starts ngrok and appends the webhook path to the public URL", async () => {
75
- const proc = nextProcess();
76
- const result = startNgrokTunnel({ port: 3334, path: "/voice/webhook" });
77
-
78
- emitNgrokUrl(proc, "https://abc.ngrok.io");
79
-
80
- const tunnel = await result;
81
- expect(tunnel.publicUrl).toBe("https://abc.ngrok.io/voice/webhook");
82
- expect(tunnel.provider).toBe("ngrok");
83
- expect(tunnel.stop).toBeTypeOf("function");
84
- expect(mocks.spawn).toHaveBeenCalledWith(
85
- "ngrok",
86
- ["http", "3334", "--log", "stdout", "--log-format", "json"],
87
- {
88
- stdio: ["ignore", "pipe", "pipe"],
89
- },
90
- );
91
- });
92
-
93
- it("sets ngrok auth token before starting the tunnel", async () => {
94
- const authProc = nextProcess();
95
- const tunnelProc = nextProcess();
96
- const result = startNgrokTunnel({
97
- port: 3334,
98
- path: "/hook",
99
- authToken: "token",
100
- });
101
-
102
- authProc.close(0);
103
- await vi.waitFor(() => expect(mocks.spawn).toHaveBeenCalledTimes(2));
104
- emitNgrokUrl(tunnelProc, "https://auth.ngrok.io");
105
-
106
- const tunnel = await result;
107
- expect(tunnel.publicUrl).toBe("https://auth.ngrok.io/hook");
108
- expect(tunnel.provider).toBe("ngrok");
109
- expect(mocks.spawn).toHaveBeenNthCalledWith(1, "ngrok", ["config", "add-authtoken", "token"], {
110
- stdio: ["ignore", "pipe", "pipe"],
111
- });
112
- });
113
-
114
- it("rejects ngrok startup errors from stderr", async () => {
115
- const proc = nextProcess();
116
- const result = startNgrokTunnel({ port: 3334, path: "/hook" });
117
-
118
- proc.stderr.emit("data", Buffer.from("ERR_NGROK_3200: invalid auth token"));
119
-
120
- await expect(result).rejects.toThrow("ngrok error:");
121
- });
122
-
123
- it("starts Tailscale serve using the resolved tailnet DNS name", async () => {
124
- mocks.getTailscaleDnsName.mockResolvedValue("host.tailnet.ts.net");
125
- const proc = nextProcess();
126
- const result = startTailscaleTunnel({
127
- mode: "serve",
128
- port: 3334,
129
- path: "voice/webhook",
130
- });
131
-
132
- await vi.waitFor(() => expect(mocks.spawn).toHaveBeenCalled());
133
- proc.close(0);
134
-
135
- const tunnel = await result;
136
- expect(tunnel.publicUrl).toBe("https://host.tailnet.ts.net/voice/webhook");
137
- expect(tunnel.provider).toBe("tailscale-serve");
138
- expect(tunnel.stop).toBeTypeOf("function");
139
- expect(mocks.spawn).toHaveBeenCalledWith(
140
- "tailscale",
141
- [
142
- "serve",
143
- "--bg",
144
- "--yes",
145
- "--set-path",
146
- "/voice/webhook",
147
- "http://127.0.0.1:3334/voice/webhook",
148
- ],
149
- { stdio: ["ignore", "pipe", "pipe"] },
150
- );
151
- });
152
-
153
- it("rejects Tailscale tunnel startup when the DNS name is unavailable", async () => {
154
- mocks.getTailscaleDnsName.mockResolvedValue(null);
155
-
156
- await expect(
157
- startTailscaleTunnel({ mode: "funnel", port: 3334, path: "/hook" }),
158
- ).rejects.toThrow("Could not get Tailscale DNS name");
159
- expect(mocks.spawn).not.toHaveBeenCalled();
160
- });
161
-
162
- it("dispatches tunnel providers from config", async () => {
163
- await expect(startTunnel({ provider: "none", port: 3334, path: "/hook" })).resolves.toBeNull();
164
-
165
- const proc = nextProcess();
166
- const result = startTunnel({ provider: "ngrok", port: 3334, path: "/hook" });
167
- emitNgrokUrl(proc, "https://dispatch.ngrok.io");
168
-
169
- const tunnel = await result;
170
- expect(tunnel?.publicUrl).toBe("https://dispatch.ngrok.io/hook");
171
- expect(tunnel?.provider).toBe("ngrok");
172
- });
173
- });
package/src/tunnel.ts DELETED
@@ -1,314 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import { getTailscaleDnsName } from "./webhook/tailscale.js";
3
-
4
- /**
5
- * Tunnel configuration for exposing the webhook server.
6
- */
7
- interface TunnelConfig {
8
- /** Tunnel provider: ngrok, tailscale-serve, or tailscale-funnel */
9
- provider: "ngrok" | "tailscale-serve" | "tailscale-funnel" | "none";
10
- /** Local port to tunnel */
11
- port: number;
12
- /** Path prefix for the tunnel (e.g., /voice/webhook) */
13
- path: string;
14
- /** ngrok auth token (optional, enables longer sessions) */
15
- ngrokAuthToken?: string;
16
- /** ngrok custom domain (paid feature) */
17
- ngrokDomain?: string;
18
- }
19
-
20
- /**
21
- * Result of starting a tunnel.
22
- */
23
- export interface TunnelResult {
24
- /** The public URL */
25
- publicUrl: string;
26
- /** Function to stop the tunnel */
27
- stop: () => Promise<void>;
28
- /** Tunnel provider name */
29
- provider: string;
30
- }
31
-
32
- /**
33
- * Start an ngrok tunnel to expose the local webhook server.
34
- *
35
- * Uses the ngrok CLI which must be installed: https://ngrok.com/download
36
- *
37
- * @example
38
- * const tunnel = await startNgrokTunnel({ port: 3334, path: '/voice/webhook' });
39
- * console.log('Public URL:', tunnel.publicUrl);
40
- * // Later: await tunnel.stop();
41
- */
42
- export async function startNgrokTunnel(config: {
43
- port: number;
44
- path: string;
45
- authToken?: string;
46
- domain?: string;
47
- }): Promise<TunnelResult> {
48
- // Set auth token if provided
49
- if (config.authToken) {
50
- await runNgrokCommand(["config", "add-authtoken", config.authToken]);
51
- }
52
-
53
- // Build ngrok command args
54
- const args = ["http", String(config.port), "--log", "stdout", "--log-format", "json"];
55
-
56
- // Add custom domain if provided (paid ngrok feature)
57
- if (config.domain) {
58
- args.push("--domain", config.domain);
59
- }
60
-
61
- return new Promise((resolve, reject) => {
62
- const proc = spawn("ngrok", args, {
63
- stdio: ["ignore", "pipe", "pipe"],
64
- });
65
-
66
- let resolved = false;
67
- let publicUrl: string | null = null;
68
- let outputBuffer = "";
69
-
70
- const timeout = setTimeout(() => {
71
- if (!resolved) {
72
- resolved = true;
73
- proc.kill("SIGTERM");
74
- reject(new Error("ngrok startup timed out (30s)"));
75
- }
76
- }, 30000);
77
-
78
- const processLine = (line: string) => {
79
- try {
80
- const log = JSON.parse(line);
81
-
82
- // ngrok logs the public URL in a 'started tunnel' message
83
- if (log.msg === "started tunnel" && log.url) {
84
- publicUrl = log.url;
85
- }
86
-
87
- // Also check for the URL field directly
88
- if (log.addr && log.url && !publicUrl) {
89
- publicUrl = log.url;
90
- }
91
-
92
- // Check for ready state
93
- if (publicUrl && !resolved) {
94
- resolved = true;
95
- clearTimeout(timeout);
96
-
97
- // Add path to the public URL
98
- const fullUrl = publicUrl + config.path;
99
-
100
- console.log(`[voice-call] ngrok tunnel active: ${fullUrl}`);
101
-
102
- resolve({
103
- publicUrl: fullUrl,
104
- provider: "ngrok",
105
- stop: async () => {
106
- proc.kill("SIGTERM");
107
- await new Promise<void>((res) => {
108
- proc.on("close", () => res());
109
- setTimeout(res, 2000); // Fallback timeout
110
- });
111
- },
112
- });
113
- }
114
- } catch {
115
- // Not JSON, might be startup message
116
- }
117
- };
118
-
119
- proc.stdout.on("data", (data: Buffer) => {
120
- outputBuffer += data.toString();
121
- const lines = outputBuffer.split("\n");
122
- outputBuffer = lines.pop() || "";
123
-
124
- for (const line of lines) {
125
- if (line.trim()) {
126
- processLine(line);
127
- }
128
- }
129
- });
130
-
131
- proc.stderr.on("data", (data: Buffer) => {
132
- const msg = data.toString();
133
- // Check for common errors
134
- if (msg.includes("ERR_NGROK")) {
135
- if (!resolved) {
136
- resolved = true;
137
- clearTimeout(timeout);
138
- reject(new Error(`ngrok error: ${msg}`));
139
- }
140
- }
141
- });
142
-
143
- proc.on("error", (err) => {
144
- if (!resolved) {
145
- resolved = true;
146
- clearTimeout(timeout);
147
- reject(new Error(`Failed to start ngrok: ${err.message}`));
148
- }
149
- });
150
-
151
- proc.on("close", (code) => {
152
- if (!resolved) {
153
- resolved = true;
154
- clearTimeout(timeout);
155
- reject(new Error(`ngrok exited unexpectedly with code ${code}`));
156
- }
157
- });
158
- });
159
- }
160
-
161
- /**
162
- * Run an ngrok command and wait for completion.
163
- */
164
- async function runNgrokCommand(args: string[]): Promise<string> {
165
- return new Promise((resolve, reject) => {
166
- const proc = spawn("ngrok", args, {
167
- stdio: ["ignore", "pipe", "pipe"],
168
- });
169
-
170
- let stdout = "";
171
- let stderr = "";
172
-
173
- proc.stdout.on("data", (data) => {
174
- stdout += data.toString();
175
- });
176
- proc.stderr.on("data", (data) => {
177
- stderr += data.toString();
178
- });
179
-
180
- proc.on("close", (code) => {
181
- if (code === 0) {
182
- resolve(stdout);
183
- } else {
184
- reject(new Error(`ngrok command failed: ${stderr || stdout}`));
185
- }
186
- });
187
-
188
- proc.on("error", reject);
189
- });
190
- }
191
-
192
- /**
193
- * Check if ngrok is installed and available.
194
- */
195
- export async function isNgrokAvailable(): Promise<boolean> {
196
- return new Promise((resolve) => {
197
- const proc = spawn("ngrok", ["version"], {
198
- stdio: ["ignore", "pipe", "pipe"],
199
- });
200
-
201
- proc.on("close", (code) => {
202
- resolve(code === 0);
203
- });
204
-
205
- proc.on("error", () => {
206
- resolve(false);
207
- });
208
- });
209
- }
210
-
211
- /**
212
- * Start a Tailscale serve/funnel tunnel.
213
- */
214
- export async function startTailscaleTunnel(config: {
215
- mode: "serve" | "funnel";
216
- port: number;
217
- path: string;
218
- }): Promise<TunnelResult> {
219
- // Get Tailscale DNS name
220
- const dnsName = await getTailscaleDnsName();
221
- if (!dnsName) {
222
- throw new Error("Could not get Tailscale DNS name. Is Tailscale running?");
223
- }
224
-
225
- const path = config.path.startsWith("/") ? config.path : `/${config.path}`;
226
- const localUrl = `http://127.0.0.1:${config.port}${path}`;
227
-
228
- return new Promise((resolve, reject) => {
229
- const proc = spawn("tailscale", [config.mode, "--bg", "--yes", "--set-path", path, localUrl], {
230
- stdio: ["ignore", "pipe", "pipe"],
231
- });
232
-
233
- const timeout = setTimeout(() => {
234
- proc.kill("SIGKILL");
235
- reject(new Error(`Tailscale ${config.mode} timed out`));
236
- }, 10000);
237
-
238
- proc.on("close", (code) => {
239
- clearTimeout(timeout);
240
- if (code === 0) {
241
- const publicUrl = `https://${dnsName}${path}`;
242
- console.log(`[voice-call] Tailscale ${config.mode} active: ${publicUrl}`);
243
-
244
- resolve({
245
- publicUrl,
246
- provider: `tailscale-${config.mode}`,
247
- stop: async () => {
248
- await stopTailscaleTunnel(config.mode, path);
249
- },
250
- });
251
- } else {
252
- reject(new Error(`Tailscale ${config.mode} failed with code ${code}`));
253
- }
254
- });
255
-
256
- proc.on("error", (err) => {
257
- clearTimeout(timeout);
258
- reject(err);
259
- });
260
- });
261
- }
262
-
263
- /**
264
- * Stop a Tailscale serve/funnel tunnel.
265
- */
266
- async function stopTailscaleTunnel(mode: "serve" | "funnel", path: string): Promise<void> {
267
- return new Promise((resolve) => {
268
- const proc = spawn("tailscale", [mode, "off", path], {
269
- stdio: "ignore",
270
- });
271
-
272
- const timeout = setTimeout(() => {
273
- proc.kill("SIGKILL");
274
- resolve();
275
- }, 5000);
276
-
277
- proc.on("close", () => {
278
- clearTimeout(timeout);
279
- resolve();
280
- });
281
- });
282
- }
283
-
284
- /**
285
- * Start a tunnel based on configuration.
286
- */
287
- export async function startTunnel(config: TunnelConfig): Promise<TunnelResult | null> {
288
- switch (config.provider) {
289
- case "ngrok":
290
- return startNgrokTunnel({
291
- port: config.port,
292
- path: config.path,
293
- authToken: config.ngrokAuthToken,
294
- domain: config.ngrokDomain,
295
- });
296
-
297
- case "tailscale-serve":
298
- return startTailscaleTunnel({
299
- mode: "serve",
300
- port: config.port,
301
- path: config.path,
302
- });
303
-
304
- case "tailscale-funnel":
305
- return startTailscaleTunnel({
306
- mode: "funnel",
307
- port: config.port,
308
- path: config.path,
309
- });
310
-
311
- default:
312
- return null;
313
- }
314
- }