@kodelyth/voice-call 2026.5.42 → 2026.6.1

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 +16 -4
  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,216 +0,0 @@
1
- import { EventEmitter } from "node:events";
2
- import { beforeEach, describe, expect, it, vi } from "vitest";
3
-
4
- const { spawnMock } = vi.hoisted(() => ({
5
- spawnMock: vi.fn(),
6
- }));
7
-
8
- const tailscaleSpawnOptions = { stdio: ["ignore", "pipe", "pipe"] } as const;
9
-
10
- vi.mock("node:child_process", async () => {
11
- const { mockNodeBuiltinModule } = await import("klaw/plugin-sdk/test-node-mocks");
12
- return mockNodeBuiltinModule(
13
- () => vi.importActual<typeof import("node:child_process")>("node:child_process"),
14
- {
15
- spawn: spawnMock,
16
- },
17
- );
18
- });
19
-
20
- import {
21
- cleanupTailscaleExposure,
22
- cleanupTailscaleExposureRoute,
23
- getTailscaleDnsName,
24
- getTailscaleSelfInfo,
25
- setupTailscaleExposure,
26
- setupTailscaleExposureRoute,
27
- } from "./tailscale.js";
28
-
29
- function createProc(params?: { code?: number; stdout?: string }) {
30
- const proc = new EventEmitter() as EventEmitter & {
31
- stdout: EventEmitter;
32
- kill: ReturnType<typeof vi.fn>;
33
- };
34
- proc.stdout = new EventEmitter();
35
- proc.kill = vi.fn();
36
- setTimeout(() => {
37
- if (params?.stdout) {
38
- proc.stdout.emit("data", Buffer.from(params.stdout));
39
- }
40
- proc.emit("close", params?.code ?? 0);
41
- }, 0);
42
- return proc;
43
- }
44
-
45
- function createErrorProc() {
46
- const proc = new EventEmitter() as EventEmitter & {
47
- stdout: EventEmitter;
48
- kill: ReturnType<typeof vi.fn>;
49
- };
50
- proc.stdout = new EventEmitter();
51
- proc.kill = vi.fn();
52
- setTimeout(() => {
53
- proc.emit("error", Object.assign(new Error("spawn tailscale ENOENT"), { code: "ENOENT" }));
54
- }, 0);
55
- return proc;
56
- }
57
-
58
- describe("voice-call tailscale helpers", () => {
59
- beforeEach(() => {
60
- vi.clearAllMocks();
61
- });
62
-
63
- it("reads dns and node id from tailscale status json", async () => {
64
- spawnMock
65
- .mockReturnValueOnce(
66
- createProc({
67
- stdout: JSON.stringify({
68
- Self: {
69
- DNSName: "bot.example.ts.net.",
70
- ID: "node-123",
71
- },
72
- }),
73
- }),
74
- )
75
- .mockReturnValueOnce(
76
- createProc({
77
- stdout: JSON.stringify({
78
- Self: {
79
- DNSName: "bot.example.ts.net.",
80
- ID: "node-123",
81
- },
82
- }),
83
- }),
84
- );
85
-
86
- await expect(getTailscaleSelfInfo()).resolves.toEqual({
87
- dnsName: "bot.example.ts.net",
88
- nodeId: "node-123",
89
- });
90
- await expect(getTailscaleDnsName()).resolves.toBe("bot.example.ts.net");
91
- });
92
-
93
- it("returns null for failing or invalid status responses", async () => {
94
- spawnMock.mockReturnValueOnce(createProc({ code: 1, stdout: "bad" }));
95
- await expect(getTailscaleSelfInfo()).resolves.toBeNull();
96
-
97
- spawnMock.mockReturnValueOnce(createProc({ stdout: "{not-json" }));
98
- await expect(getTailscaleSelfInfo()).resolves.toBeNull();
99
- });
100
-
101
- it("treats missing tailscale binary as unavailable instead of leaking spawn errors", async () => {
102
- spawnMock.mockReturnValueOnce(createErrorProc());
103
-
104
- await expect(getTailscaleSelfInfo()).resolves.toBeNull();
105
- });
106
-
107
- it("sets up and cleans up exposure routes with the selected mode", async () => {
108
- spawnMock
109
- .mockReturnValueOnce(
110
- createProc({
111
- stdout: JSON.stringify({ Self: { DNSName: "bot.example.ts.net." } }),
112
- }),
113
- )
114
- .mockReturnValueOnce(createProc({ code: 0 }))
115
- .mockReturnValueOnce(createProc({ code: 0 }));
116
-
117
- await expect(
118
- setupTailscaleExposureRoute({
119
- mode: "serve",
120
- path: "/voice",
121
- localUrl: "http://127.0.0.1:8787/webhook",
122
- }),
123
- ).resolves.toBe("https://bot.example.ts.net/voice");
124
-
125
- await cleanupTailscaleExposureRoute({ mode: "serve", path: "/voice" });
126
-
127
- expect(spawnMock).toHaveBeenNthCalledWith(
128
- 1,
129
- "tailscale",
130
- ["status", "--json"],
131
- tailscaleSpawnOptions,
132
- );
133
- expect(spawnMock).toHaveBeenNthCalledWith(
134
- 2,
135
- "tailscale",
136
- ["serve", "--bg", "--yes", "--set-path", "/voice", "http://127.0.0.1:8787/webhook"],
137
- tailscaleSpawnOptions,
138
- );
139
- expect(spawnMock).toHaveBeenNthCalledWith(
140
- 3,
141
- "tailscale",
142
- ["serve", "off", "/voice"],
143
- tailscaleSpawnOptions,
144
- );
145
- });
146
-
147
- it("returns null when setup cannot resolve dns or route activation fails", async () => {
148
- spawnMock
149
- .mockReturnValueOnce(createProc({ code: 1 }))
150
- .mockReturnValueOnce(
151
- createProc({
152
- stdout: JSON.stringify({ Self: { DNSName: "bot.example.ts.net." } }),
153
- }),
154
- )
155
- .mockReturnValueOnce(createProc({ code: 1 }));
156
-
157
- await expect(
158
- setupTailscaleExposureRoute({
159
- mode: "funnel",
160
- path: "/voice",
161
- localUrl: "http://127.0.0.1:8787/webhook",
162
- }),
163
- ).resolves.toBeNull();
164
-
165
- await expect(
166
- setupTailscaleExposureRoute({
167
- mode: "funnel",
168
- path: "/voice",
169
- localUrl: "http://127.0.0.1:8787/webhook",
170
- }),
171
- ).resolves.toBeNull();
172
- });
173
-
174
- it("maps config modes to serve or funnel and skips off", async () => {
175
- spawnMock
176
- .mockReturnValueOnce(
177
- createProc({
178
- stdout: JSON.stringify({ Self: { DNSName: "bot.example.ts.net." } }),
179
- }),
180
- )
181
- .mockReturnValueOnce(createProc({ code: 0 }))
182
- .mockReturnValueOnce(createProc({ code: 0 }));
183
-
184
- await expect(
185
- setupTailscaleExposure({
186
- tailscale: { mode: "off", path: "/voice" },
187
- serve: { port: 8787, path: "/webhook" },
188
- } as never),
189
- ).resolves.toBeNull();
190
-
191
- await expect(
192
- setupTailscaleExposure({
193
- tailscale: { mode: "funnel", path: "/voice" },
194
- serve: { port: 8787, path: "/webhook" },
195
- } as never),
196
- ).resolves.toBe("https://bot.example.ts.net/voice");
197
-
198
- await cleanupTailscaleExposure({
199
- tailscale: { mode: "serve", path: "/voice" },
200
- serve: { port: 8787, path: "/webhook" },
201
- } as never);
202
-
203
- expect(spawnMock).toHaveBeenNthCalledWith(
204
- 2,
205
- "tailscale",
206
- ["funnel", "--bg", "--yes", "--set-path", "/voice", "http://127.0.0.1:8787/webhook"],
207
- tailscaleSpawnOptions,
208
- );
209
- expect(spawnMock).toHaveBeenNthCalledWith(
210
- 3,
211
- "tailscale",
212
- ["serve", "off", "/voice"],
213
- tailscaleSpawnOptions,
214
- );
215
- });
216
- });
@@ -1,129 +0,0 @@
1
- import { spawn } from "node:child_process";
2
- import type { VoiceCallConfig } from "../config.js";
3
-
4
- type TailscaleSelfInfo = {
5
- dnsName: string | null;
6
- nodeId: string | null;
7
- };
8
-
9
- function runTailscaleCommand(
10
- args: string[],
11
- timeoutMs = 2500,
12
- ): Promise<{ code: number; stdout: string }> {
13
- return new Promise((resolve) => {
14
- const proc = spawn("tailscale", args, {
15
- stdio: ["ignore", "pipe", "pipe"],
16
- });
17
-
18
- let stdout = "";
19
- let settled = false;
20
- let timer: ReturnType<typeof setTimeout>;
21
- const finish = (result: { code: number; stdout: string }) => {
22
- if (settled) {
23
- return;
24
- }
25
- settled = true;
26
- clearTimeout(timer);
27
- resolve(result);
28
- };
29
-
30
- proc.stdout.on("data", (data) => {
31
- stdout += data;
32
- });
33
-
34
- timer = setTimeout(() => {
35
- proc.kill("SIGKILL");
36
- finish({ code: -1, stdout: "" });
37
- }, timeoutMs);
38
-
39
- proc.on("error", () => {
40
- finish({ code: -1, stdout: "" });
41
- });
42
-
43
- proc.on("close", (code) => {
44
- finish({ code: code ?? -1, stdout });
45
- });
46
- });
47
- }
48
-
49
- export async function getTailscaleSelfInfo(): Promise<TailscaleSelfInfo | null> {
50
- const { code, stdout } = await runTailscaleCommand(["status", "--json"]);
51
- if (code !== 0) {
52
- return null;
53
- }
54
-
55
- try {
56
- const status = JSON.parse(stdout);
57
- return {
58
- dnsName: status.Self?.DNSName?.replace(/\.$/, "") || null,
59
- nodeId: status.Self?.ID || null,
60
- };
61
- } catch {
62
- return null;
63
- }
64
- }
65
-
66
- export async function getTailscaleDnsName(): Promise<string | null> {
67
- const info = await getTailscaleSelfInfo();
68
- return info?.dnsName ?? null;
69
- }
70
-
71
- export async function setupTailscaleExposureRoute(opts: {
72
- mode: "serve" | "funnel";
73
- path: string;
74
- localUrl: string;
75
- }): Promise<string | null> {
76
- const dnsName = await getTailscaleDnsName();
77
- if (!dnsName) {
78
- console.warn("[voice-call] Could not get Tailscale DNS name");
79
- return null;
80
- }
81
-
82
- const { code } = await runTailscaleCommand([
83
- opts.mode,
84
- "--bg",
85
- "--yes",
86
- "--set-path",
87
- opts.path,
88
- opts.localUrl,
89
- ]);
90
-
91
- if (code === 0) {
92
- const publicUrl = `https://${dnsName}${opts.path}`;
93
- console.log(`[voice-call] Tailscale ${opts.mode} active: ${publicUrl}`);
94
- return publicUrl;
95
- }
96
-
97
- console.warn(`[voice-call] Tailscale ${opts.mode} failed`);
98
- return null;
99
- }
100
-
101
- export async function cleanupTailscaleExposureRoute(opts: {
102
- mode: "serve" | "funnel";
103
- path: string;
104
- }): Promise<void> {
105
- await runTailscaleCommand([opts.mode, "off", opts.path]);
106
- }
107
-
108
- export async function setupTailscaleExposure(config: VoiceCallConfig): Promise<string | null> {
109
- if (config.tailscale.mode === "off") {
110
- return null;
111
- }
112
-
113
- const mode = config.tailscale.mode === "funnel" ? "funnel" : "serve";
114
- const localUrl = `http://127.0.0.1:${config.serve.port}${config.serve.path}`;
115
- return setupTailscaleExposureRoute({
116
- mode,
117
- path: config.tailscale.path,
118
- localUrl,
119
- });
120
- }
121
-
122
- export async function cleanupTailscaleExposure(config: VoiceCallConfig): Promise<void> {
123
- if (config.tailscale.mode === "off") {
124
- return;
125
- }
126
-
127
- const mode = config.tailscale.mode === "funnel" ? "funnel" : "serve";
128
- await cleanupTailscaleExposureRoute({ mode, path: config.tailscale.path });
129
- }
@@ -1,33 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { isLocalOnlyWebhookHost, isProviderUnreachableWebhookUrl } from "./webhook-exposure.js";
3
-
4
- describe("webhook exposure host classification", () => {
5
- it.each([
6
- "http://[::]:3334/voice/webhook",
7
- "http://[::1]:3334/voice/webhook",
8
- "http://[fc00::1]/voice/webhook",
9
- "http://[fd00::1]/voice/webhook",
10
- "http://[::ffff:127.0.0.1]/voice/webhook",
11
- "http://[::ffff:10.0.0.1]/voice/webhook",
12
- "http://[::ffff:192.168.0.1]/voice/webhook",
13
- "http://[::ffff:172.16.0.1]/voice/webhook",
14
- "http://[fe80::1]/voice/webhook",
15
- ])("treats local/private webhook URL %s as provider-unreachable", (url) => {
16
- expect(isProviderUnreachableWebhookUrl(url)).toBe(true);
17
- });
18
-
19
- it.each([
20
- "http://[::ffff:8.8.8.8]/voice/webhook",
21
- "https://voice.example.com/voice/webhook",
22
- "https://fcloud.example/voice/webhook",
23
- ])("does not reject public webhook URL %s", (url) => {
24
- expect(isProviderUnreachableWebhookUrl(url)).toBe(false);
25
- });
26
-
27
- it.each(["[::1]", "[fc00::1]", "[fd00::1]", "::ffff:7f00:1", "::ffff:a00:1", "[fe80::1]"])(
28
- "normalizes local/private URL hostnames like %s",
29
- (host) => {
30
- expect(isLocalOnlyWebhookHost(host)).toBe(true);
31
- },
32
- );
33
- });
@@ -1,84 +0,0 @@
1
- import { isBlockedHostnameOrIp } from "../api.js";
2
-
3
- type VoiceCallWebhookExposureConfig = {
4
- provider?: string;
5
- publicUrl?: string;
6
- tunnel?: {
7
- provider?: string;
8
- };
9
- tailscale?: {
10
- mode?: string;
11
- };
12
- };
13
-
14
- type VoiceCallWebhookExposureStatus = {
15
- ok: boolean;
16
- configured: boolean;
17
- message: string;
18
- };
19
-
20
- export function providerRequiresPublicWebhook(providerName: string | undefined): boolean {
21
- return providerName === "twilio" || providerName === "telnyx" || providerName === "plivo";
22
- }
23
-
24
- export function isLocalOnlyWebhookHost(hostname: string): boolean {
25
- return isBlockedHostnameOrIp(hostname);
26
- }
27
-
28
- export function isProviderUnreachableWebhookUrl(webhookUrl: string): boolean {
29
- try {
30
- const parsed = new URL(webhookUrl);
31
- return isLocalOnlyWebhookHost(parsed.hostname);
32
- } catch {
33
- return false;
34
- }
35
- }
36
-
37
- export function resolveWebhookExposureStatus(
38
- config: VoiceCallWebhookExposureConfig,
39
- ): VoiceCallWebhookExposureStatus {
40
- if (config.provider === "mock") {
41
- return {
42
- ok: true,
43
- configured: true,
44
- message: "Mock provider does not need a public webhook",
45
- };
46
- }
47
-
48
- if (config.publicUrl) {
49
- if (isProviderUnreachableWebhookUrl(config.publicUrl)) {
50
- return {
51
- ok: false,
52
- configured: true,
53
- message: `Public webhook URL is local/private and cannot be reached by ${config.provider ?? "the provider"}: ${config.publicUrl}`,
54
- };
55
- }
56
- return {
57
- ok: true,
58
- configured: true,
59
- message: `Public webhook URL configured: ${config.publicUrl}`,
60
- };
61
- }
62
-
63
- if (config.tunnel?.provider && config.tunnel.provider !== "none") {
64
- return {
65
- ok: true,
66
- configured: true,
67
- message: "Webhook exposure configured through tunnel",
68
- };
69
- }
70
-
71
- if (config.tailscale?.mode && config.tailscale.mode !== "off") {
72
- return {
73
- ok: true,
74
- configured: true,
75
- message: "Webhook exposure configured through Tailscale",
76
- };
77
- }
78
-
79
- return {
80
- ok: false,
81
- configured: false,
82
- message: "Set publicUrl or configure tunnel/tailscale so the provider can reach webhooks",
83
- };
84
- }