@openclaw/voice-call 2026.5.2 → 2026.5.3-beta.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 (126) hide show
  1. package/dist/api.js +2 -0
  2. package/dist/call-status-CXldV5o8.js +32 -0
  3. package/dist/cli-metadata.js +12 -0
  4. package/dist/config-7w04YpHh.js +548 -0
  5. package/dist/config-compat-B0me39_4.js +129 -0
  6. package/dist/guarded-json-api-Btx5EE4w.js +591 -0
  7. package/dist/http-headers-BrnxBasF.js +10 -0
  8. package/dist/index.js +1284 -0
  9. package/dist/mock-CeKvfVEd.js +135 -0
  10. package/dist/plivo-B-a7KFoT.js +393 -0
  11. package/dist/realtime-handler-B63CIDP2.js +325 -0
  12. package/dist/realtime-transcription.runtime-B2h70y2W.js +2 -0
  13. package/dist/realtime-voice.runtime-Bkh4nvLn.js +2 -0
  14. package/dist/response-generator-BrcmwDZU.js +182 -0
  15. package/dist/response-model-CyF5K80p.js +12 -0
  16. package/dist/runtime-api.js +6 -0
  17. package/dist/runtime-entry-88ytYAQa.js +3119 -0
  18. package/dist/runtime-entry.js +2 -0
  19. package/dist/setup-api.js +37 -0
  20. package/dist/telnyx-jjBE8boz.js +260 -0
  21. package/dist/twilio-1OqbcXLL.js +676 -0
  22. package/dist/voice-mapping-BYDGdWGx.js +40 -0
  23. package/package.json +14 -6
  24. package/api.ts +0 -16
  25. package/cli-metadata.ts +0 -10
  26. package/config-api.ts +0 -12
  27. package/index.test.ts +0 -943
  28. package/index.ts +0 -794
  29. package/runtime-api.ts +0 -20
  30. package/runtime-entry.ts +0 -1
  31. package/setup-api.ts +0 -47
  32. package/src/allowlist.test.ts +0 -18
  33. package/src/allowlist.ts +0 -19
  34. package/src/cli.ts +0 -845
  35. package/src/config-compat.test.ts +0 -120
  36. package/src/config-compat.ts +0 -227
  37. package/src/config.test.ts +0 -479
  38. package/src/config.ts +0 -808
  39. package/src/core-bridge.ts +0 -14
  40. package/src/deep-merge.test.ts +0 -40
  41. package/src/deep-merge.ts +0 -23
  42. package/src/gateway-continue-operation.ts +0 -200
  43. package/src/http-headers.test.ts +0 -16
  44. package/src/http-headers.ts +0 -15
  45. package/src/manager/context.ts +0 -42
  46. package/src/manager/events.test.ts +0 -581
  47. package/src/manager/events.ts +0 -288
  48. package/src/manager/lifecycle.ts +0 -53
  49. package/src/manager/lookup.test.ts +0 -52
  50. package/src/manager/lookup.ts +0 -35
  51. package/src/manager/outbound.test.ts +0 -528
  52. package/src/manager/outbound.ts +0 -486
  53. package/src/manager/state.ts +0 -48
  54. package/src/manager/store.ts +0 -106
  55. package/src/manager/timers.test.ts +0 -129
  56. package/src/manager/timers.ts +0 -113
  57. package/src/manager/twiml.test.ts +0 -13
  58. package/src/manager/twiml.ts +0 -17
  59. package/src/manager.closed-loop.test.ts +0 -236
  60. package/src/manager.inbound-allowlist.test.ts +0 -188
  61. package/src/manager.notify.test.ts +0 -377
  62. package/src/manager.restore.test.ts +0 -183
  63. package/src/manager.test-harness.ts +0 -127
  64. package/src/manager.ts +0 -392
  65. package/src/media-stream.test.ts +0 -768
  66. package/src/media-stream.ts +0 -708
  67. package/src/providers/base.ts +0 -97
  68. package/src/providers/mock.test.ts +0 -78
  69. package/src/providers/mock.ts +0 -185
  70. package/src/providers/plivo.test.ts +0 -93
  71. package/src/providers/plivo.ts +0 -601
  72. package/src/providers/shared/call-status.test.ts +0 -24
  73. package/src/providers/shared/call-status.ts +0 -24
  74. package/src/providers/shared/guarded-json-api.test.ts +0 -106
  75. package/src/providers/shared/guarded-json-api.ts +0 -42
  76. package/src/providers/telnyx.test.ts +0 -340
  77. package/src/providers/telnyx.ts +0 -394
  78. package/src/providers/twilio/api.test.ts +0 -145
  79. package/src/providers/twilio/api.ts +0 -93
  80. package/src/providers/twilio/twiml-policy.test.ts +0 -84
  81. package/src/providers/twilio/twiml-policy.ts +0 -87
  82. package/src/providers/twilio/webhook.ts +0 -34
  83. package/src/providers/twilio.test.ts +0 -591
  84. package/src/providers/twilio.ts +0 -861
  85. package/src/providers/twilio.types.ts +0 -17
  86. package/src/realtime-defaults.ts +0 -3
  87. package/src/realtime-fast-context.test.ts +0 -88
  88. package/src/realtime-fast-context.ts +0 -165
  89. package/src/realtime-transcription.runtime.ts +0 -4
  90. package/src/realtime-voice.runtime.ts +0 -5
  91. package/src/response-generator.test.ts +0 -321
  92. package/src/response-generator.ts +0 -318
  93. package/src/response-model.test.ts +0 -71
  94. package/src/response-model.ts +0 -23
  95. package/src/runtime.test.ts +0 -536
  96. package/src/runtime.ts +0 -510
  97. package/src/telephony-audio.test.ts +0 -61
  98. package/src/telephony-audio.ts +0 -12
  99. package/src/telephony-tts.test.ts +0 -196
  100. package/src/telephony-tts.ts +0 -235
  101. package/src/test-fixtures.ts +0 -73
  102. package/src/tts-provider-voice.test.ts +0 -34
  103. package/src/tts-provider-voice.ts +0 -21
  104. package/src/tunnel.test.ts +0 -166
  105. package/src/tunnel.ts +0 -314
  106. package/src/types.ts +0 -291
  107. package/src/utils.test.ts +0 -17
  108. package/src/utils.ts +0 -14
  109. package/src/voice-mapping.test.ts +0 -34
  110. package/src/voice-mapping.ts +0 -68
  111. package/src/webhook/realtime-handler.test.ts +0 -598
  112. package/src/webhook/realtime-handler.ts +0 -485
  113. package/src/webhook/stale-call-reaper.test.ts +0 -88
  114. package/src/webhook/stale-call-reaper.ts +0 -38
  115. package/src/webhook/tailscale.test.ts +0 -214
  116. package/src/webhook/tailscale.ts +0 -129
  117. package/src/webhook-exposure.test.ts +0 -33
  118. package/src/webhook-exposure.ts +0 -84
  119. package/src/webhook-security.test.ts +0 -770
  120. package/src/webhook-security.ts +0 -994
  121. package/src/webhook.hangup-once.lifecycle.test.ts +0 -135
  122. package/src/webhook.test.ts +0 -1470
  123. package/src/webhook.ts +0 -908
  124. package/src/webhook.types.ts +0 -5
  125. package/src/websocket-test-support.ts +0 -72
  126. package/tsconfig.json +0 -16
@@ -1,581 +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(), "openclaw-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
- expect.objectContaining({
180
- providerCallId: "prov-dup",
181
- reason: "hangup-bot",
182
- }),
183
- ]);
184
- });
185
-
186
- it("answers accepted inbound calls when the provider requires an answer command", () => {
187
- const answerCalls: AnswerCallInput[] = [];
188
- const provider = createProvider({
189
- answerCall: async (input: AnswerCallInput): Promise<void> => {
190
- answerCalls.push(input);
191
- },
192
- });
193
- const ctx = createContext({
194
- config: VoiceCallConfigSchema.parse({
195
- enabled: true,
196
- provider: "telnyx",
197
- fromNumber: "+15550000000",
198
- inboundPolicy: "open",
199
- telnyx: {
200
- apiKey: "KEY123",
201
- connectionId: "CONN456",
202
- },
203
- skipSignatureVerification: true,
204
- }),
205
- provider,
206
- });
207
- const event = createInboundInitiatedEvent({
208
- id: "evt-answer",
209
- providerCallId: "call-control-1",
210
- from: "+15552222222",
211
- });
212
-
213
- processEvent(ctx, event);
214
-
215
- const call = requireFirstActiveCall(ctx);
216
- expect(answerCalls).toEqual([
217
- {
218
- callId: call.callId,
219
- providerCallId: "call-control-1",
220
- },
221
- ]);
222
- });
223
-
224
- it("updates providerCallId map when provider ID changes", () => {
225
- const now = Date.now();
226
- const ctx = createContext();
227
- ctx.activeCalls.set("call-1", {
228
- callId: "call-1",
229
- providerCallId: "request-uuid",
230
- provider: "plivo",
231
- direction: "outbound",
232
- state: "initiated",
233
- from: "+15550000000",
234
- to: "+15550000001",
235
- startedAt: now,
236
- transcript: [],
237
- processedEventIds: [],
238
- metadata: {},
239
- });
240
- ctx.providerCallIdMap.set("request-uuid", "call-1");
241
-
242
- processEvent(ctx, {
243
- id: "evt-provider-id-change",
244
- type: "call.answered",
245
- callId: "call-1",
246
- providerCallId: "call-uuid",
247
- timestamp: now + 1,
248
- });
249
-
250
- const activeCall = ctx.activeCalls.get("call-1");
251
- if (!activeCall) {
252
- throw new Error("expected active call after provider id change");
253
- }
254
- expect(activeCall.providerCallId).toBe("call-uuid");
255
- expect(ctx.providerCallIdMap.get("call-uuid")).toBe("call-1");
256
- expect(ctx.providerCallIdMap.has("request-uuid")).toBe(false);
257
- });
258
-
259
- it("does not burn replay keys for unknown calls before a later replay can resolve them", () => {
260
- const now = Date.now();
261
- const ctx = createContext();
262
- const event: NormalizedEvent = {
263
- id: "evt-late-call",
264
- dedupeKey: "stable-late-call",
265
- type: "call.answered",
266
- callId: "call-late",
267
- providerCallId: "provider-late",
268
- timestamp: now + 1,
269
- };
270
-
271
- processEvent(ctx, event);
272
-
273
- expect(ctx.processedEventIds.size).toBe(0);
274
-
275
- ctx.activeCalls.set("call-late", {
276
- callId: "call-late",
277
- providerCallId: "provider-late",
278
- provider: "plivo",
279
- direction: "inbound",
280
- state: "ringing",
281
- from: "+15550000002",
282
- to: "+15550000000",
283
- startedAt: now,
284
- transcript: [],
285
- processedEventIds: [],
286
- metadata: {},
287
- });
288
- ctx.providerCallIdMap.set("provider-late", "call-late");
289
-
290
- processEvent(ctx, event);
291
-
292
- const call = ctx.activeCalls.get("call-late");
293
- if (!call) {
294
- throw new Error("expected replayed event to resolve after call registration");
295
- }
296
- expect(call.state).toBe("answered");
297
- expect(call.answeredAt).toBe(now + 1);
298
- expect(Array.from(ctx.processedEventIds)).toEqual(["stable-late-call"]);
299
- });
300
-
301
- it("invokes onCallAnswered hook for answered events", () => {
302
- const now = Date.now();
303
- let answeredCallId: string | null = null;
304
- const ctx = createContext({
305
- onCallAnswered: (call) => {
306
- answeredCallId = call.callId;
307
- },
308
- });
309
- ctx.activeCalls.set("call-2", {
310
- callId: "call-2",
311
- providerCallId: "call-2-provider",
312
- provider: "plivo",
313
- direction: "inbound",
314
- state: "ringing",
315
- from: "+15550000002",
316
- to: "+15550000000",
317
- startedAt: now,
318
- transcript: [],
319
- processedEventIds: [],
320
- metadata: {},
321
- });
322
- ctx.providerCallIdMap.set("call-2-provider", "call-2");
323
-
324
- processEvent(ctx, {
325
- id: "evt-answered-hook",
326
- type: "call.answered",
327
- callId: "call-2",
328
- providerCallId: "call-2-provider",
329
- timestamp: now + 1,
330
- });
331
-
332
- expect(answeredCallId).toBe("call-2");
333
- });
334
-
335
- it("when hangup throws, logs and does not throw", () => {
336
- const provider = createProvider({
337
- hangupCall: async (): Promise<void> => {
338
- throw new Error("provider down");
339
- },
340
- });
341
- const ctx = createContext({
342
- config: createInboundDisabledConfig(),
343
- provider,
344
- });
345
- const event = createInboundInitiatedEvent({
346
- id: "evt-fail",
347
- providerCallId: "prov-fail",
348
- from: "+15553333333",
349
- });
350
-
351
- expect(() => processEvent(ctx, event)).not.toThrow();
352
- expect(ctx.activeCalls.size).toBe(0);
353
- });
354
-
355
- it("auto-registers externally-initiated outbound-api calls with correct direction", () => {
356
- const ctx = createContext();
357
- const event: NormalizedEvent = {
358
- id: "evt-external-1",
359
- type: "call.initiated",
360
- callId: "CA-external-123",
361
- providerCallId: "CA-external-123",
362
- timestamp: Date.now(),
363
- direction: "outbound",
364
- from: "+15550000000",
365
- to: "+15559876543",
366
- };
367
-
368
- processEvent(ctx, event);
369
-
370
- // Call should be registered in activeCalls and providerCallIdMap
371
- expect(ctx.activeCalls.size).toBe(1);
372
- const call = requireFirstActiveCall(ctx);
373
- expect(ctx.providerCallIdMap.get("CA-external-123")).toBe(call.callId);
374
- expect(call.providerCallId).toBe("CA-external-123");
375
- expect(call.direction).toBe("outbound");
376
- expect(call.from).toBe("+15550000000");
377
- expect(call.to).toBe("+15559876543");
378
- });
379
-
380
- it("does not reject externally-initiated outbound calls even with disabled inbound policy", () => {
381
- const { ctx, hangupCalls } = createRejectingInboundContext();
382
- const event: NormalizedEvent = {
383
- id: "evt-external-2",
384
- type: "call.initiated",
385
- callId: "CA-external-456",
386
- providerCallId: "CA-external-456",
387
- timestamp: Date.now(),
388
- direction: "outbound",
389
- from: "+15550000000",
390
- to: "+15559876543",
391
- };
392
-
393
- processEvent(ctx, event);
394
-
395
- // External outbound calls bypass inbound policy — they should be accepted
396
- expect(ctx.activeCalls.size).toBe(1);
397
- expect(hangupCalls).toHaveLength(0);
398
- const call = requireFirstActiveCall(ctx);
399
- expect(call.direction).toBe("outbound");
400
- });
401
-
402
- it("preserves inbound direction for auto-registered inbound calls", () => {
403
- const ctx = createContext({
404
- config: VoiceCallConfigSchema.parse({
405
- enabled: true,
406
- provider: "plivo",
407
- fromNumber: "+15550000000",
408
- inboundPolicy: "open",
409
- }),
410
- });
411
- const event: NormalizedEvent = {
412
- id: "evt-inbound-dir",
413
- type: "call.initiated",
414
- callId: "CA-inbound-789",
415
- providerCallId: "CA-inbound-789",
416
- timestamp: Date.now(),
417
- direction: "inbound",
418
- from: "+15554444444",
419
- to: "+15550000000",
420
- };
421
-
422
- processEvent(ctx, event);
423
-
424
- expect(ctx.activeCalls.size).toBe(1);
425
- const call = requireFirstActiveCall(ctx);
426
- expect(call.direction).toBe("inbound");
427
- });
428
-
429
- it("assigns per-call session keys to inbound calls when configured", () => {
430
- const ctx = createContext({
431
- config: VoiceCallConfigSchema.parse({
432
- enabled: true,
433
- provider: "plivo",
434
- fromNumber: "+15550000000",
435
- inboundPolicy: "open",
436
- sessionScope: "per-call",
437
- }),
438
- });
439
- const event: NormalizedEvent = {
440
- id: "evt-inbound-session-scope",
441
- type: "call.initiated",
442
- callId: "CA-inbound-session-scope",
443
- providerCallId: "CA-inbound-session-scope",
444
- timestamp: Date.now(),
445
- direction: "inbound",
446
- from: "+15554444444",
447
- to: "+15550000000",
448
- };
449
-
450
- processEvent(ctx, event);
451
-
452
- const call = requireFirstActiveCall(ctx);
453
- expect(call.sessionKey).toBe(`voice:call:${call.callId}`);
454
- });
455
-
456
- it("applies per-number inbound greeting and stores the matched route key", () => {
457
- const ctx = createContext({
458
- config: VoiceCallConfigSchema.parse({
459
- enabled: true,
460
- provider: "plivo",
461
- fromNumber: "+15550000000",
462
- inboundPolicy: "open",
463
- inboundGreeting: "Hello from global.",
464
- numbers: {
465
- "+15550002222": {
466
- inboundGreeting: "Silver Fox Cards, how can I help?",
467
- },
468
- },
469
- }),
470
- });
471
- const event: NormalizedEvent = {
472
- id: "evt-inbound-number-route",
473
- type: "call.initiated",
474
- callId: "CA-inbound-number-route",
475
- providerCallId: "CA-inbound-number-route",
476
- timestamp: Date.now(),
477
- direction: "inbound",
478
- from: "+15554444444",
479
- to: "+1 (555) 000-2222",
480
- };
481
-
482
- processEvent(ctx, event);
483
-
484
- const call = requireFirstActiveCall(ctx);
485
- expect(call.metadata).toEqual(
486
- expect.objectContaining({
487
- initialMessage: "Silver Fox Cards, how can I help?",
488
- numberRouteKey: "+15550002222",
489
- }),
490
- );
491
- });
492
-
493
- it("deduplicates by dedupeKey even when event IDs differ", () => {
494
- const now = Date.now();
495
- const ctx = createContext();
496
- ctx.activeCalls.set("call-dedupe", {
497
- callId: "call-dedupe",
498
- providerCallId: "provider-dedupe",
499
- provider: "plivo",
500
- direction: "outbound",
501
- state: "answered",
502
- from: "+15550000000",
503
- to: "+15550000001",
504
- startedAt: now,
505
- transcript: [],
506
- processedEventIds: [],
507
- metadata: {},
508
- });
509
- ctx.providerCallIdMap.set("provider-dedupe", "call-dedupe");
510
-
511
- processEvent(ctx, {
512
- id: "evt-1",
513
- dedupeKey: "stable-key-1",
514
- type: "call.speech",
515
- callId: "call-dedupe",
516
- providerCallId: "provider-dedupe",
517
- timestamp: now + 1,
518
- transcript: "hello",
519
- isFinal: true,
520
- });
521
-
522
- processEvent(ctx, {
523
- id: "evt-2",
524
- dedupeKey: "stable-key-1",
525
- type: "call.speech",
526
- callId: "call-dedupe",
527
- providerCallId: "provider-dedupe",
528
- timestamp: now + 2,
529
- transcript: "hello",
530
- isFinal: true,
531
- });
532
-
533
- const call = ctx.activeCalls.get("call-dedupe");
534
- if (!call) {
535
- throw new Error("expected deduped call to remain active");
536
- }
537
- expect(call.transcript).toHaveLength(1);
538
- expect(Array.from(ctx.processedEventIds)).toEqual(["stable-key-1"]);
539
- });
540
-
541
- it("keeps retryable call.error events replayable", () => {
542
- const now = Date.now();
543
- const ctx = createContext();
544
- ctx.activeCalls.set("call-retryable-error", {
545
- callId: "call-retryable-error",
546
- providerCallId: "provider-retryable-error",
547
- provider: "plivo",
548
- direction: "outbound",
549
- state: "active",
550
- from: "+15550000000",
551
- to: "+15550000001",
552
- startedAt: now,
553
- transcript: [],
554
- processedEventIds: [],
555
- metadata: {},
556
- });
557
- ctx.providerCallIdMap.set("provider-retryable-error", "call-retryable-error");
558
-
559
- const event: NormalizedEvent = {
560
- id: "evt-retryable-error",
561
- dedupeKey: "stable-retryable-error",
562
- type: "call.error",
563
- callId: "call-retryable-error",
564
- providerCallId: "provider-retryable-error",
565
- timestamp: now + 1,
566
- error: "temporary upstream failure",
567
- retryable: true,
568
- };
569
-
570
- processEvent(ctx, event);
571
- processEvent(ctx, event);
572
-
573
- const call = ctx.activeCalls.get("call-retryable-error");
574
- if (!call) {
575
- throw new Error("expected retryable error call to remain active");
576
- }
577
- expect(call.state).toBe("active");
578
- expect(Array.from(ctx.processedEventIds)).toEqual([]);
579
- expect(call.processedEventIds).toEqual([]);
580
- });
581
- });