@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,179 +0,0 @@
1
- import { afterEach, describe, expect, it } from "vitest";
2
- import { VoiceCallConfigSchema, type VoiceCallConfig } from "./config.js";
3
- import { CallManager } from "./manager.js";
4
- import { createTestStorePath, FakeProvider } from "./manager.test-harness.js";
5
- import { flushPendingCallRecordWritesForTest } from "./manager/store.js";
6
- import type { WebhookContext, WebhookParseOptions } from "./types.js";
7
- import { VoiceCallWebhookServer } from "./webhook.js";
8
-
9
- const createConfig = (overrides: Partial<VoiceCallConfig> = {}): VoiceCallConfig => {
10
- const base = VoiceCallConfigSchema.parse({
11
- enabled: true,
12
- provider: "plivo",
13
- fromNumber: "+15550000000",
14
- inboundPolicy: "disabled",
15
- });
16
- base.serve.port = 0;
17
-
18
- return {
19
- ...base,
20
- ...overrides,
21
- serve: {
22
- ...base.serve,
23
- ...overrides.serve,
24
- },
25
- };
26
- };
27
-
28
- async function postWebhookForm(server: VoiceCallWebhookServer, baseUrl: string, body: string) {
29
- const address = (
30
- server as unknown as { server?: { address?: () => unknown } }
31
- ).server?.address?.();
32
- const requestUrl = new URL(baseUrl);
33
- if (
34
- !address ||
35
- typeof address !== "object" ||
36
- !("port" in address) ||
37
- (typeof address.port !== "number" && typeof address.port !== "string") ||
38
- !address.port
39
- ) {
40
- throw new Error("voice webhook server did not expose a bound port");
41
- }
42
- requestUrl.port = String(address.port);
43
- return await fetch(requestUrl.toString(), {
44
- method: "POST",
45
- headers: {
46
- "content-type": "application/x-www-form-urlencoded",
47
- "x-plivo-signature-v2": "sig",
48
- "x-plivo-signature-v2-nonce": "nonce",
49
- },
50
- body,
51
- });
52
- }
53
-
54
- async function runDuplicateInboundReplayLifecycleTest(provider: FakeProvider) {
55
- const config = createConfig();
56
- const manager = new CallManager(config, createTestStorePath());
57
- await manager.initialize(provider, "https://example.com/voice/webhook");
58
- const server = new VoiceCallWebhookServer(config, manager, provider);
59
-
60
- try {
61
- const baseUrl = await server.start();
62
- const first = await postWebhookForm(server, baseUrl, "CallSid=CA123&From=%2B15552222222");
63
- const second = await postWebhookForm(server, baseUrl, "CallSid=CA123&From=%2B15552222222");
64
- return { first, second, manager };
65
- } finally {
66
- await server.stop();
67
- }
68
- }
69
-
70
- function expectSingleRejectedReplayHangup(params: {
71
- first: Response;
72
- second: Response;
73
- provider: FakeProvider;
74
- manager: CallManager;
75
- }) {
76
- expect(params.first.status).toBe(200);
77
- expect(params.second.status).toBe(200);
78
- expect(params.provider.hangupCalls).toHaveLength(1);
79
- const [hangupCall] = params.provider.hangupCalls;
80
- if (!hangupCall) {
81
- throw new Error("Expected rejected replay hangup call");
82
- }
83
- expect(hangupCall.providerCallId).toBe("provider-inbound-1");
84
- expect(hangupCall.reason).toBe("hangup-bot");
85
- expect(params.manager.getCallByProviderCallId("provider-inbound-1")).toBeUndefined();
86
- }
87
-
88
- class RejectInboundReplayProvider extends FakeProvider {
89
- override verifyWebhook() {
90
- return { ok: true, verifiedRequestKey: "verified:req:reject-once" };
91
- }
92
-
93
- override parseWebhookEvent(_ctx: WebhookContext, options?: WebhookParseOptions) {
94
- return {
95
- statusCode: 200,
96
- events: [
97
- {
98
- id: "evt-reject-once",
99
- dedupeKey: options?.verifiedRequestKey,
100
- type: "call.initiated" as const,
101
- callId: "provider-inbound-1",
102
- providerCallId: "provider-inbound-1",
103
- timestamp: Date.now(),
104
- direction: "inbound" as const,
105
- from: "+15552222222",
106
- to: "+15550000000",
107
- },
108
- ],
109
- };
110
- }
111
- }
112
-
113
- class RejectInboundReplayWithHangupFailureProvider extends RejectInboundReplayProvider {
114
- override async hangupCall(input: Parameters<FakeProvider["hangupCall"]>[0]): Promise<void> {
115
- this.hangupCalls.push(input);
116
- throw new Error("hangup failed");
117
- }
118
- }
119
-
120
- describe("Voice-call webhook hangup-once lifecycle", () => {
121
- afterEach(() => {
122
- // Each test uses an isolated store path, so only server cleanup is needed.
123
- });
124
-
125
- it("hangs up a rejected inbound replay only once across duplicate webhook delivery", async () => {
126
- const provider = new RejectInboundReplayProvider("plivo");
127
- const { first, second, manager } = await runDuplicateInboundReplayLifecycleTest(provider);
128
- expectSingleRejectedReplayHangup({ first, second, provider, manager });
129
- });
130
-
131
- it("does not attempt a second hangup when replay arrives after the first hangup fails", async () => {
132
- const provider = new RejectInboundReplayWithHangupFailureProvider("plivo");
133
- const { first, second, manager } = await runDuplicateInboundReplayLifecycleTest(provider);
134
- expectSingleRejectedReplayHangup({ first, second, provider, manager });
135
- });
136
-
137
- it("keeps rejected inbound replay keys after manager restart", async () => {
138
- const storePath = createTestStorePath();
139
- const config = createConfig();
140
- const firstProvider = new RejectInboundReplayProvider("plivo");
141
- const firstManager = new CallManager(config, storePath);
142
- await firstManager.initialize(firstProvider, "https://example.com/voice/webhook");
143
- const firstServer = new VoiceCallWebhookServer(config, firstManager, firstProvider);
144
-
145
- try {
146
- const baseUrl = await firstServer.start();
147
- const first = await postWebhookForm(
148
- firstServer,
149
- baseUrl,
150
- "CallSid=CA123&From=%2B15552222222",
151
- );
152
- expect(first.status).toBe(200);
153
- } finally {
154
- await firstServer.stop();
155
- }
156
- await flushPendingCallRecordWritesForTest();
157
- expect(firstProvider.hangupCalls).toHaveLength(1);
158
-
159
- const secondProvider = new RejectInboundReplayProvider("plivo");
160
- const secondManager = new CallManager(config, storePath);
161
- await secondManager.initialize(secondProvider, "https://example.com/voice/webhook");
162
- const secondServer = new VoiceCallWebhookServer(config, secondManager, secondProvider);
163
-
164
- try {
165
- const baseUrl = await secondServer.start();
166
- const replay = await postWebhookForm(
167
- secondServer,
168
- baseUrl,
169
- "CallSid=CA123&From=%2B15552222222",
170
- );
171
- expect(replay.status).toBe(200);
172
- } finally {
173
- await secondServer.stop();
174
- }
175
-
176
- expect(secondProvider.hangupCalls).toHaveLength(0);
177
- expect(secondManager.getCallByProviderCallId("provider-inbound-1")).toBeUndefined();
178
- });
179
- });