@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,578 +0,0 @@
1
- import fs from "node:fs";
2
- import os from "node:os";
3
- import path from "node:path";
4
- import { afterEach, describe, expect, it } from "vitest";
5
- import { VoiceCallConfigSchema } from "../config.js";
6
- import type { VoiceCallProvider } from "../providers/base.js";
7
- import type { AnswerCallInput, HangupCallInput, NormalizedEvent } from "../types.js";
8
- import type { CallManagerContext } from "./context.js";
9
- import { processEvent } from "./events.js";
10
- import { flushPendingCallRecordWritesForTest } from "./store.js";
11
-
12
- const contexts: CallManagerContext[] = [];
13
-
14
- afterEach(async () => {
15
- for (const ctx of contexts.splice(0)) {
16
- for (const timer of ctx.maxDurationTimers.values()) {
17
- clearTimeout(timer);
18
- }
19
- ctx.maxDurationTimers.clear();
20
- for (const waiter of ctx.transcriptWaiters.values()) {
21
- clearTimeout(waiter.timeout);
22
- }
23
- ctx.transcriptWaiters.clear();
24
- await flushPendingCallRecordWritesForTest();
25
- fs.rmSync(ctx.storePath, { recursive: true, force: true });
26
- }
27
- });
28
-
29
- function createContext(overrides: Partial<CallManagerContext> = {}): CallManagerContext {
30
- const storePath = fs.mkdtempSync(path.join(os.tmpdir(), "klaw-voice-call-events-test-"));
31
- const ctx: CallManagerContext = {
32
- activeCalls: new Map(),
33
- providerCallIdMap: new Map(),
34
- processedEventIds: new Set(),
35
- rejectedProviderCallIds: new Set(),
36
- provider: null,
37
- config: VoiceCallConfigSchema.parse({
38
- enabled: true,
39
- provider: "plivo",
40
- fromNumber: "+15550000000",
41
- }),
42
- storePath,
43
- webhookUrl: null,
44
- activeTurnCalls: new Set(),
45
- transcriptWaiters: new Map(),
46
- maxDurationTimers: new Map(),
47
- initialMessageInFlight: new Set(),
48
- ...overrides,
49
- };
50
- contexts.push(ctx);
51
- return ctx;
52
- }
53
-
54
- function createProvider(overrides: Partial<VoiceCallProvider> = {}): VoiceCallProvider {
55
- return {
56
- name: "plivo",
57
- verifyWebhook: () => ({ ok: true }),
58
- parseWebhookEvent: () => ({ events: [] }),
59
- initiateCall: async () => ({ providerCallId: "provider-call-id", status: "initiated" }),
60
- hangupCall: async () => {},
61
- playTts: async () => {},
62
- startListening: async () => {},
63
- stopListening: async () => {},
64
- getCallStatus: async () => ({ status: "in-progress", isTerminal: false }),
65
- ...overrides,
66
- };
67
- }
68
-
69
- function createInboundDisabledConfig() {
70
- return VoiceCallConfigSchema.parse({
71
- enabled: true,
72
- provider: "plivo",
73
- fromNumber: "+15550000000",
74
- inboundPolicy: "disabled",
75
- });
76
- }
77
-
78
- function createInboundInitiatedEvent(params: {
79
- id: string;
80
- providerCallId: string;
81
- from: string;
82
- }): NormalizedEvent {
83
- return {
84
- id: params.id,
85
- type: "call.initiated",
86
- callId: params.providerCallId,
87
- providerCallId: params.providerCallId,
88
- timestamp: Date.now(),
89
- direction: "inbound",
90
- from: params.from,
91
- to: "+15550000000",
92
- };
93
- }
94
-
95
- function createRejectingInboundContext(): {
96
- ctx: CallManagerContext;
97
- hangupCalls: HangupCallInput[];
98
- } {
99
- const hangupCalls: HangupCallInput[] = [];
100
- const provider = createProvider({
101
- hangupCall: async (input: HangupCallInput): Promise<void> => {
102
- hangupCalls.push(input);
103
- },
104
- });
105
- const ctx = createContext({
106
- config: createInboundDisabledConfig(),
107
- provider,
108
- });
109
- return { ctx, hangupCalls };
110
- }
111
-
112
- function requireFirstActiveCall(ctx: CallManagerContext) {
113
- const call = [...ctx.activeCalls.values()][0];
114
- if (!call) {
115
- throw new Error("expected one active call");
116
- }
117
- return call;
118
- }
119
-
120
- describe("processEvent (functional)", () => {
121
- it("calls provider hangup when rejecting inbound call", () => {
122
- const { ctx, hangupCalls } = createRejectingInboundContext();
123
- const event = createInboundInitiatedEvent({
124
- id: "evt-1",
125
- providerCallId: "prov-1",
126
- from: "+15559999999",
127
- });
128
-
129
- processEvent(ctx, event);
130
-
131
- expect(ctx.activeCalls.size).toBe(0);
132
- expect(hangupCalls).toHaveLength(1);
133
- expect(hangupCalls[0]).toEqual({
134
- callId: "prov-1",
135
- providerCallId: "prov-1",
136
- reason: "hangup-bot",
137
- });
138
- });
139
-
140
- it("does not call hangup when provider is null", () => {
141
- const ctx = createContext({
142
- config: createInboundDisabledConfig(),
143
- provider: null,
144
- });
145
- const event = createInboundInitiatedEvent({
146
- id: "evt-2",
147
- providerCallId: "prov-2",
148
- from: "+15551111111",
149
- });
150
-
151
- processEvent(ctx, event);
152
-
153
- expect(ctx.activeCalls.size).toBe(0);
154
- });
155
-
156
- it("calls hangup only once for duplicate events for same rejected call", () => {
157
- const { ctx, hangupCalls } = createRejectingInboundContext();
158
- const event1 = createInboundInitiatedEvent({
159
- id: "evt-init",
160
- providerCallId: "prov-dup",
161
- from: "+15552222222",
162
- });
163
- const event2: NormalizedEvent = {
164
- id: "evt-ring",
165
- type: "call.ringing",
166
- callId: "prov-dup",
167
- providerCallId: "prov-dup",
168
- timestamp: Date.now(),
169
- direction: "inbound",
170
- from: "+15552222222",
171
- to: "+15550000000",
172
- };
173
-
174
- processEvent(ctx, event1);
175
- processEvent(ctx, event2);
176
-
177
- expect(ctx.activeCalls.size).toBe(0);
178
- expect(hangupCalls).toEqual([
179
- {
180
- callId: "prov-dup",
181
- providerCallId: "prov-dup",
182
- reason: "hangup-bot",
183
- },
184
- ]);
185
- });
186
-
187
- it("answers accepted inbound calls when the provider requires an answer command", () => {
188
- const answerCalls: AnswerCallInput[] = [];
189
- const provider = createProvider({
190
- answerCall: async (input: AnswerCallInput): Promise<void> => {
191
- answerCalls.push(input);
192
- },
193
- });
194
- const ctx = createContext({
195
- config: VoiceCallConfigSchema.parse({
196
- enabled: true,
197
- provider: "telnyx",
198
- fromNumber: "+15550000000",
199
- inboundPolicy: "open",
200
- telnyx: {
201
- apiKey: "KEY123",
202
- connectionId: "CONN456",
203
- },
204
- skipSignatureVerification: true,
205
- }),
206
- provider,
207
- });
208
- const event = createInboundInitiatedEvent({
209
- id: "evt-answer",
210
- providerCallId: "call-control-1",
211
- from: "+15552222222",
212
- });
213
-
214
- processEvent(ctx, event);
215
-
216
- const call = requireFirstActiveCall(ctx);
217
- expect(answerCalls).toEqual([
218
- {
219
- callId: call.callId,
220
- providerCallId: "call-control-1",
221
- },
222
- ]);
223
- });
224
-
225
- it("updates providerCallId map when provider ID changes", () => {
226
- const now = Date.now();
227
- const ctx = createContext();
228
- ctx.activeCalls.set("call-1", {
229
- callId: "call-1",
230
- providerCallId: "request-uuid",
231
- provider: "plivo",
232
- direction: "outbound",
233
- state: "initiated",
234
- from: "+15550000000",
235
- to: "+15550000001",
236
- startedAt: now,
237
- transcript: [],
238
- processedEventIds: [],
239
- metadata: {},
240
- });
241
- ctx.providerCallIdMap.set("request-uuid", "call-1");
242
-
243
- processEvent(ctx, {
244
- id: "evt-provider-id-change",
245
- type: "call.answered",
246
- callId: "call-1",
247
- providerCallId: "call-uuid",
248
- timestamp: now + 1,
249
- });
250
-
251
- const activeCall = ctx.activeCalls.get("call-1");
252
- if (!activeCall) {
253
- throw new Error("expected active call after provider id change");
254
- }
255
- expect(activeCall.providerCallId).toBe("call-uuid");
256
- expect(ctx.providerCallIdMap.get("call-uuid")).toBe("call-1");
257
- expect(ctx.providerCallIdMap.has("request-uuid")).toBe(false);
258
- });
259
-
260
- it("does not burn replay keys for unknown calls before a later replay can resolve them", () => {
261
- const now = Date.now();
262
- const ctx = createContext();
263
- const event: NormalizedEvent = {
264
- id: "evt-late-call",
265
- dedupeKey: "stable-late-call",
266
- type: "call.answered",
267
- callId: "call-late",
268
- providerCallId: "provider-late",
269
- timestamp: now + 1,
270
- };
271
-
272
- processEvent(ctx, event);
273
-
274
- expect(ctx.processedEventIds.size).toBe(0);
275
-
276
- ctx.activeCalls.set("call-late", {
277
- callId: "call-late",
278
- providerCallId: "provider-late",
279
- provider: "plivo",
280
- direction: "inbound",
281
- state: "ringing",
282
- from: "+15550000002",
283
- to: "+15550000000",
284
- startedAt: now,
285
- transcript: [],
286
- processedEventIds: [],
287
- metadata: {},
288
- });
289
- ctx.providerCallIdMap.set("provider-late", "call-late");
290
-
291
- processEvent(ctx, event);
292
-
293
- const call = ctx.activeCalls.get("call-late");
294
- if (!call) {
295
- throw new Error("expected replayed event to resolve after call registration");
296
- }
297
- expect(call.state).toBe("answered");
298
- expect(call.answeredAt).toBe(now + 1);
299
- expect(Array.from(ctx.processedEventIds)).toEqual(["stable-late-call"]);
300
- });
301
-
302
- it("invokes onCallAnswered hook for answered events", () => {
303
- const now = Date.now();
304
- let answeredCallId: string | null = null;
305
- const ctx = createContext({
306
- onCallAnswered: (call) => {
307
- answeredCallId = call.callId;
308
- },
309
- });
310
- ctx.activeCalls.set("call-2", {
311
- callId: "call-2",
312
- providerCallId: "call-2-provider",
313
- provider: "plivo",
314
- direction: "inbound",
315
- state: "ringing",
316
- from: "+15550000002",
317
- to: "+15550000000",
318
- startedAt: now,
319
- transcript: [],
320
- processedEventIds: [],
321
- metadata: {},
322
- });
323
- ctx.providerCallIdMap.set("call-2-provider", "call-2");
324
-
325
- processEvent(ctx, {
326
- id: "evt-answered-hook",
327
- type: "call.answered",
328
- callId: "call-2",
329
- providerCallId: "call-2-provider",
330
- timestamp: now + 1,
331
- });
332
-
333
- expect(answeredCallId).toBe("call-2");
334
- });
335
-
336
- it("removes active call even when hangup rejects", () => {
337
- const provider = createProvider({
338
- hangupCall: async (): Promise<void> => {
339
- throw new Error("provider down");
340
- },
341
- });
342
- const ctx = createContext({
343
- config: createInboundDisabledConfig(),
344
- provider,
345
- });
346
- const event = createInboundInitiatedEvent({
347
- id: "evt-fail",
348
- providerCallId: "prov-fail",
349
- from: "+15553333333",
350
- });
351
-
352
- processEvent(ctx, event);
353
- expect(ctx.activeCalls.size).toBe(0);
354
- });
355
-
356
- it("auto-registers externally-initiated outbound-api calls with correct direction", () => {
357
- const ctx = createContext();
358
- const event: NormalizedEvent = {
359
- id: "evt-external-1",
360
- type: "call.initiated",
361
- callId: "CA-external-123",
362
- providerCallId: "CA-external-123",
363
- timestamp: Date.now(),
364
- direction: "outbound",
365
- from: "+15550000000",
366
- to: "+15559876543",
367
- };
368
-
369
- processEvent(ctx, event);
370
-
371
- // Call should be registered in activeCalls and providerCallIdMap
372
- expect(ctx.activeCalls.size).toBe(1);
373
- const call = requireFirstActiveCall(ctx);
374
- expect(ctx.providerCallIdMap.get("CA-external-123")).toBe(call.callId);
375
- expect(call.providerCallId).toBe("CA-external-123");
376
- expect(call.direction).toBe("outbound");
377
- expect(call.from).toBe("+15550000000");
378
- expect(call.to).toBe("+15559876543");
379
- });
380
-
381
- it("does not reject externally-initiated outbound calls even with disabled inbound policy", () => {
382
- const { ctx, hangupCalls } = createRejectingInboundContext();
383
- const event: NormalizedEvent = {
384
- id: "evt-external-2",
385
- type: "call.initiated",
386
- callId: "CA-external-456",
387
- providerCallId: "CA-external-456",
388
- timestamp: Date.now(),
389
- direction: "outbound",
390
- from: "+15550000000",
391
- to: "+15559876543",
392
- };
393
-
394
- processEvent(ctx, event);
395
-
396
- // External outbound calls bypass inbound policy — they should be accepted
397
- expect(ctx.activeCalls.size).toBe(1);
398
- expect(hangupCalls).toHaveLength(0);
399
- const call = requireFirstActiveCall(ctx);
400
- expect(call.direction).toBe("outbound");
401
- });
402
-
403
- it("preserves inbound direction for auto-registered inbound calls", () => {
404
- const ctx = createContext({
405
- config: VoiceCallConfigSchema.parse({
406
- enabled: true,
407
- provider: "plivo",
408
- fromNumber: "+15550000000",
409
- inboundPolicy: "open",
410
- }),
411
- });
412
- const event: NormalizedEvent = {
413
- id: "evt-inbound-dir",
414
- type: "call.initiated",
415
- callId: "CA-inbound-789",
416
- providerCallId: "CA-inbound-789",
417
- timestamp: Date.now(),
418
- direction: "inbound",
419
- from: "+15554444444",
420
- to: "+15550000000",
421
- };
422
-
423
- processEvent(ctx, event);
424
-
425
- expect(ctx.activeCalls.size).toBe(1);
426
- const call = requireFirstActiveCall(ctx);
427
- expect(call.direction).toBe("inbound");
428
- });
429
-
430
- it("assigns per-call session keys to inbound calls when configured", () => {
431
- const ctx = createContext({
432
- config: VoiceCallConfigSchema.parse({
433
- enabled: true,
434
- provider: "plivo",
435
- fromNumber: "+15550000000",
436
- inboundPolicy: "open",
437
- sessionScope: "per-call",
438
- }),
439
- });
440
- const event: NormalizedEvent = {
441
- id: "evt-inbound-session-scope",
442
- type: "call.initiated",
443
- callId: "CA-inbound-session-scope",
444
- providerCallId: "CA-inbound-session-scope",
445
- timestamp: Date.now(),
446
- direction: "inbound",
447
- from: "+15554444444",
448
- to: "+15550000000",
449
- };
450
-
451
- processEvent(ctx, event);
452
-
453
- const call = requireFirstActiveCall(ctx);
454
- expect(call.sessionKey).toBe(`voice:call:${call.callId}`);
455
- });
456
-
457
- it("applies per-number inbound greeting and stores the matched route key", () => {
458
- const ctx = createContext({
459
- config: VoiceCallConfigSchema.parse({
460
- enabled: true,
461
- provider: "plivo",
462
- fromNumber: "+15550000000",
463
- inboundPolicy: "open",
464
- inboundGreeting: "Hello from global.",
465
- numbers: {
466
- "+15550002222": {
467
- inboundGreeting: "Silver Fox Cards, how can I help?",
468
- },
469
- },
470
- }),
471
- });
472
- const event: NormalizedEvent = {
473
- id: "evt-inbound-number-route",
474
- type: "call.initiated",
475
- callId: "CA-inbound-number-route",
476
- providerCallId: "CA-inbound-number-route",
477
- timestamp: Date.now(),
478
- direction: "inbound",
479
- from: "+15554444444",
480
- to: "+1 (555) 000-2222",
481
- };
482
-
483
- processEvent(ctx, event);
484
-
485
- const call = requireFirstActiveCall(ctx);
486
- expect(call.metadata?.initialMessage).toBe("Silver Fox Cards, how can I help?");
487
- expect(call.metadata?.numberRouteKey).toBe("+15550002222");
488
- });
489
-
490
- it("deduplicates by dedupeKey even when event IDs differ", () => {
491
- const now = Date.now();
492
- const ctx = createContext();
493
- ctx.activeCalls.set("call-dedupe", {
494
- callId: "call-dedupe",
495
- providerCallId: "provider-dedupe",
496
- provider: "plivo",
497
- direction: "outbound",
498
- state: "answered",
499
- from: "+15550000000",
500
- to: "+15550000001",
501
- startedAt: now,
502
- transcript: [],
503
- processedEventIds: [],
504
- metadata: {},
505
- });
506
- ctx.providerCallIdMap.set("provider-dedupe", "call-dedupe");
507
-
508
- processEvent(ctx, {
509
- id: "evt-1",
510
- dedupeKey: "stable-key-1",
511
- type: "call.speech",
512
- callId: "call-dedupe",
513
- providerCallId: "provider-dedupe",
514
- timestamp: now + 1,
515
- transcript: "hello",
516
- isFinal: true,
517
- });
518
-
519
- processEvent(ctx, {
520
- id: "evt-2",
521
- dedupeKey: "stable-key-1",
522
- type: "call.speech",
523
- callId: "call-dedupe",
524
- providerCallId: "provider-dedupe",
525
- timestamp: now + 2,
526
- transcript: "hello",
527
- isFinal: true,
528
- });
529
-
530
- const call = ctx.activeCalls.get("call-dedupe");
531
- if (!call) {
532
- throw new Error("expected deduped call to remain active");
533
- }
534
- expect(call.transcript).toHaveLength(1);
535
- expect(Array.from(ctx.processedEventIds)).toEqual(["stable-key-1"]);
536
- });
537
-
538
- it("keeps retryable call.error events replayable", () => {
539
- const now = Date.now();
540
- const ctx = createContext();
541
- ctx.activeCalls.set("call-retryable-error", {
542
- callId: "call-retryable-error",
543
- providerCallId: "provider-retryable-error",
544
- provider: "plivo",
545
- direction: "outbound",
546
- state: "active",
547
- from: "+15550000000",
548
- to: "+15550000001",
549
- startedAt: now,
550
- transcript: [],
551
- processedEventIds: [],
552
- metadata: {},
553
- });
554
- ctx.providerCallIdMap.set("provider-retryable-error", "call-retryable-error");
555
-
556
- const event: NormalizedEvent = {
557
- id: "evt-retryable-error",
558
- dedupeKey: "stable-retryable-error",
559
- type: "call.error",
560
- callId: "call-retryable-error",
561
- providerCallId: "provider-retryable-error",
562
- timestamp: now + 1,
563
- error: "temporary upstream failure",
564
- retryable: true,
565
- };
566
-
567
- processEvent(ctx, event);
568
- processEvent(ctx, event);
569
-
570
- const call = ctx.activeCalls.get("call-retryable-error");
571
- if (!call) {
572
- throw new Error("expected retryable error call to remain active");
573
- }
574
- expect(call.state).toBe("active");
575
- expect(Array.from(ctx.processedEventIds)).toStrictEqual([]);
576
- expect(call.processedEventIds).toStrictEqual([]);
577
- });
578
- });