@openclaw/voice-call 2026.5.2 → 2026.5.3-beta.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 (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,288 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
3
- import { isAllowlistedCaller, normalizePhoneNumber } from "../allowlist.js";
4
- import { resolveVoiceCallEffectiveConfig, resolveVoiceCallSessionKey } from "../config.js";
5
- import type { CallRecord, NormalizedEvent } from "../types.js";
6
- import type { CallManagerContext } from "./context.js";
7
- import { finalizeCall } from "./lifecycle.js";
8
- import { findCall } from "./lookup.js";
9
- import { endCall } from "./outbound.js";
10
- import { addTranscriptEntry, transitionState } from "./state.js";
11
- import { persistCallRecord } from "./store.js";
12
- import { resolveTranscriptWaiter, startMaxDurationTimer } from "./timers.js";
13
-
14
- type EventContext = Pick<
15
- CallManagerContext,
16
- | "activeCalls"
17
- | "providerCallIdMap"
18
- | "processedEventIds"
19
- | "rejectedProviderCallIds"
20
- | "provider"
21
- | "config"
22
- | "storePath"
23
- | "transcriptWaiters"
24
- | "maxDurationTimers"
25
- | "onCallAnswered"
26
- >;
27
-
28
- function shouldAcceptInbound(config: EventContext["config"], from: string | undefined): boolean {
29
- const { inboundPolicy: policy, allowFrom } = config;
30
-
31
- switch (policy) {
32
- case "disabled":
33
- console.log("[voice-call] Inbound call rejected: policy is disabled");
34
- return false;
35
-
36
- case "open":
37
- console.log("[voice-call] Inbound call accepted: policy is open");
38
- return true;
39
-
40
- case "allowlist":
41
- case "pairing": {
42
- const normalized = normalizePhoneNumber(from);
43
- if (!normalized) {
44
- console.log("[voice-call] Inbound call rejected: missing caller ID");
45
- return false;
46
- }
47
- const allowed = isAllowlistedCaller(normalized, allowFrom);
48
- const status = allowed ? "accepted" : "rejected";
49
- console.log(
50
- `[voice-call] Inbound call ${status}: ${from} ${allowed ? "is in" : "not in"} allowlist`,
51
- );
52
- return allowed;
53
- }
54
-
55
- default:
56
- return false;
57
- }
58
- }
59
-
60
- function createWebhookCall(params: {
61
- ctx: EventContext;
62
- providerCallId: string;
63
- direction: "inbound" | "outbound";
64
- from: string;
65
- to: string;
66
- }): CallRecord {
67
- const callId = crypto.randomUUID();
68
- const effective = resolveVoiceCallEffectiveConfig(
69
- params.ctx.config,
70
- params.direction === "inbound" ? params.to : undefined,
71
- );
72
- const effectiveConfig = effective.config;
73
-
74
- const callRecord: CallRecord = {
75
- callId,
76
- providerCallId: params.providerCallId,
77
- provider: params.ctx.provider?.name || "twilio",
78
- direction: params.direction,
79
- state: "ringing",
80
- from: params.from,
81
- to: params.to,
82
- sessionKey: resolveVoiceCallSessionKey({
83
- config: effectiveConfig,
84
- callId,
85
- phone: params.direction === "outbound" ? params.to : params.from,
86
- }),
87
- startedAt: Date.now(),
88
- transcript: [],
89
- processedEventIds: [],
90
- metadata: {
91
- initialMessage:
92
- params.direction === "inbound"
93
- ? effectiveConfig.inboundGreeting || "Hello! How can I help you today?"
94
- : undefined,
95
- ...(effective.numberRouteKey ? { numberRouteKey: effective.numberRouteKey } : {}),
96
- },
97
- };
98
-
99
- params.ctx.activeCalls.set(callId, callRecord);
100
- params.ctx.providerCallIdMap.set(params.providerCallId, callId);
101
- persistCallRecord(params.ctx.storePath, callRecord);
102
-
103
- console.log(
104
- `[voice-call] Created ${params.direction} call record: ${callId} from ${params.from}`,
105
- );
106
- return callRecord;
107
- }
108
-
109
- export function processEvent(ctx: EventContext, event: NormalizedEvent): void {
110
- const dedupeKey = event.dedupeKey || event.id;
111
- if (ctx.processedEventIds.has(dedupeKey)) {
112
- return;
113
- }
114
-
115
- let call = findCall({
116
- activeCalls: ctx.activeCalls,
117
- providerCallIdMap: ctx.providerCallIdMap,
118
- callIdOrProviderCallId: event.callId,
119
- });
120
-
121
- const providerCallId = event.providerCallId;
122
- const eventDirection =
123
- event.direction === "inbound" || event.direction === "outbound" ? event.direction : undefined;
124
-
125
- // Auto-register untracked calls arriving via webhook. This covers both
126
- // true inbound calls and externally-initiated outbound-api calls (e.g. calls
127
- // placed directly via the Twilio REST API pointing at our webhook URL).
128
- if (!call && providerCallId && eventDirection) {
129
- // Apply inbound policy for true inbound calls; external outbound-api calls
130
- // are implicitly trusted because the caller controls the webhook URL.
131
- if (eventDirection === "inbound" && !shouldAcceptInbound(ctx.config, event.from)) {
132
- const pid = providerCallId;
133
- if (!ctx.provider) {
134
- console.warn(
135
- `[voice-call] Inbound call rejected by policy but no provider to hang up (providerCallId: ${pid}, from: ${event.from}); call will time out on provider side.`,
136
- );
137
- return;
138
- }
139
- ctx.processedEventIds.add(dedupeKey);
140
- if (ctx.rejectedProviderCallIds.has(pid)) {
141
- return;
142
- }
143
- ctx.rejectedProviderCallIds.add(pid);
144
- const callId = event.callId ?? pid;
145
- console.log(`[voice-call] Rejecting inbound call by policy: ${pid}`);
146
- void ctx.provider
147
- .hangupCall({
148
- callId,
149
- providerCallId: pid,
150
- reason: "hangup-bot",
151
- })
152
- .catch((err) => {
153
- ctx.rejectedProviderCallIds.delete(pid);
154
- const message = formatErrorMessage(err);
155
- console.warn(`[voice-call] Failed to reject inbound call ${pid}:`, message);
156
- });
157
- return;
158
- }
159
-
160
- call = createWebhookCall({
161
- ctx,
162
- providerCallId,
163
- direction: eventDirection === "outbound" ? "outbound" : "inbound",
164
- from: event.from || "unknown",
165
- to: event.to || ctx.config.fromNumber || "unknown",
166
- });
167
-
168
- // Normalize event to internal ID for downstream consumers.
169
- event.callId = call.callId;
170
- }
171
-
172
- if (!call) {
173
- return;
174
- }
175
-
176
- if (event.providerCallId && event.providerCallId !== call.providerCallId) {
177
- const previousProviderCallId = call.providerCallId;
178
- call.providerCallId = event.providerCallId;
179
- ctx.providerCallIdMap.set(event.providerCallId, call.callId);
180
- if (previousProviderCallId) {
181
- const mapped = ctx.providerCallIdMap.get(previousProviderCallId);
182
- if (mapped === call.callId) {
183
- ctx.providerCallIdMap.delete(previousProviderCallId);
184
- }
185
- }
186
- }
187
-
188
- const shouldCommitReplayKey = !(event.type === "call.error" && event.retryable);
189
- if (shouldCommitReplayKey) {
190
- ctx.processedEventIds.add(dedupeKey);
191
- call.processedEventIds.push(dedupeKey);
192
- }
193
-
194
- switch (event.type) {
195
- case "call.initiated":
196
- transitionState(call, "initiated");
197
- if (call.direction === "inbound" && call.providerCallId && ctx.provider?.answerCall) {
198
- void ctx.provider
199
- .answerCall({
200
- callId: call.callId,
201
- providerCallId: call.providerCallId,
202
- })
203
- .catch((err) => {
204
- const message = formatErrorMessage(err);
205
- console.warn(
206
- `[voice-call] Failed to answer inbound call ${call.providerCallId}:`,
207
- message,
208
- );
209
- });
210
- }
211
- break;
212
-
213
- case "call.ringing":
214
- transitionState(call, "ringing");
215
- break;
216
-
217
- case "call.answered":
218
- call.answeredAt = event.timestamp;
219
- transitionState(call, "answered");
220
- startMaxDurationTimer({
221
- ctx,
222
- callId: call.callId,
223
- onTimeout: async (callId) => {
224
- await endCall(ctx, callId, { reason: "timeout" });
225
- },
226
- });
227
- ctx.onCallAnswered?.(call);
228
- break;
229
-
230
- case "call.active":
231
- transitionState(call, "active");
232
- break;
233
-
234
- case "call.speaking":
235
- transitionState(call, "speaking");
236
- break;
237
-
238
- case "call.speech":
239
- if (event.isFinal) {
240
- const hadWaiter = ctx.transcriptWaiters.has(call.callId);
241
- const resolved = resolveTranscriptWaiter(
242
- ctx,
243
- call.callId,
244
- event.transcript,
245
- event.turnToken,
246
- );
247
- if (hadWaiter && !resolved) {
248
- console.warn(
249
- `[voice-call] Ignoring speech event with mismatched turn token for ${call.callId}`,
250
- );
251
- break;
252
- }
253
- addTranscriptEntry(call, "user", event.transcript);
254
- }
255
- transitionState(call, "listening");
256
- break;
257
-
258
- case "call.silence":
259
- case "call.dtmf":
260
- break;
261
-
262
- case "call.ended":
263
- finalizeCall({
264
- ctx,
265
- call,
266
- endReason: event.reason,
267
- endedAt: event.timestamp,
268
- });
269
- return;
270
-
271
- case "call.error":
272
- if (!event.retryable) {
273
- finalizeCall({
274
- ctx,
275
- call,
276
- endReason: "error",
277
- endedAt: event.timestamp,
278
- transcriptRejectReason: `Call error: ${event.error}`,
279
- });
280
- return;
281
- }
282
- // Keep retryable provider errors replayable so a redelivery can still
283
- // drive later recovery or terminal handling for the same event key.
284
- break;
285
- }
286
-
287
- persistCallRecord(ctx.storePath, call);
288
- }
@@ -1,53 +0,0 @@
1
- import type { CallRecord, EndReason } from "../types.js";
2
- import type { CallManagerContext } from "./context.js";
3
- import { transitionState } from "./state.js";
4
- import { persistCallRecord } from "./store.js";
5
- import { clearMaxDurationTimer, rejectTranscriptWaiter } from "./timers.js";
6
-
7
- type CallLifecycleContext = Pick<
8
- CallManagerContext,
9
- "activeCalls" | "providerCallIdMap" | "storePath"
10
- > &
11
- Partial<Pick<CallManagerContext, "transcriptWaiters" | "maxDurationTimers">>;
12
-
13
- function removeProviderCallMapping(
14
- providerCallIdMap: Map<string, string>,
15
- call: Pick<CallRecord, "callId" | "providerCallId">,
16
- ): void {
17
- if (!call.providerCallId) {
18
- return;
19
- }
20
- const mappedCallId = providerCallIdMap.get(call.providerCallId);
21
- if (mappedCallId === call.callId) {
22
- providerCallIdMap.delete(call.providerCallId);
23
- }
24
- }
25
-
26
- export function finalizeCall(params: {
27
- ctx: CallLifecycleContext;
28
- call: CallRecord;
29
- endReason: EndReason;
30
- endedAt?: number;
31
- transcriptRejectReason?: string;
32
- }): void {
33
- const { ctx, call, endReason } = params;
34
-
35
- call.endedAt = params.endedAt ?? Date.now();
36
- call.endReason = endReason;
37
- transitionState(call, endReason);
38
- persistCallRecord(ctx.storePath, call);
39
-
40
- if (ctx.maxDurationTimers) {
41
- clearMaxDurationTimer({ maxDurationTimers: ctx.maxDurationTimers }, call.callId);
42
- }
43
- if (ctx.transcriptWaiters) {
44
- rejectTranscriptWaiter(
45
- { transcriptWaiters: ctx.transcriptWaiters },
46
- call.callId,
47
- params.transcriptRejectReason ?? `Call ended: ${endReason}`,
48
- );
49
- }
50
-
51
- ctx.activeCalls.delete(call.callId);
52
- removeProviderCallMapping(ctx.providerCallIdMap, call);
53
- }
@@ -1,52 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { findCall, getCallByProviderCallId } from "./lookup.js";
3
-
4
- describe("voice-call manager lookup", () => {
5
- it("resolves provider call ids from the explicit map first", () => {
6
- const activeCalls = new Map([
7
- ["call-1", { id: "call-1", providerCallId: "prov-1" }],
8
- ["call-2", { id: "call-2", providerCallId: "prov-2" }],
9
- ]);
10
- const providerCallIdMap = new Map([["provider-lookup", "call-2"]]);
11
-
12
- expect(
13
- getCallByProviderCallId({
14
- activeCalls: activeCalls as never,
15
- providerCallIdMap,
16
- providerCallId: "provider-lookup",
17
- }),
18
- ).toEqual({ id: "call-2", providerCallId: "prov-2" });
19
- });
20
-
21
- it("falls back to scanning active calls and supports direct call ids", () => {
22
- const activeCalls = new Map([
23
- ["call-1", { id: "call-1", providerCallId: "prov-1" }],
24
- ["call-2", { id: "call-2", providerCallId: "prov-2" }],
25
- ]);
26
- const providerCallIdMap = new Map<string, string>();
27
-
28
- expect(
29
- getCallByProviderCallId({
30
- activeCalls: activeCalls as never,
31
- providerCallIdMap,
32
- providerCallId: "prov-1",
33
- }),
34
- ).toEqual({ id: "call-1", providerCallId: "prov-1" });
35
-
36
- expect(
37
- findCall({
38
- activeCalls: activeCalls as never,
39
- providerCallIdMap,
40
- callIdOrProviderCallId: "call-2",
41
- }),
42
- ).toEqual({ id: "call-2", providerCallId: "prov-2" });
43
-
44
- expect(
45
- findCall({
46
- activeCalls: activeCalls as never,
47
- providerCallIdMap,
48
- callIdOrProviderCallId: "missing",
49
- }),
50
- ).toBeUndefined();
51
- });
52
- });
@@ -1,35 +0,0 @@
1
- import type { CallId, CallRecord } from "../types.js";
2
-
3
- export function getCallByProviderCallId(params: {
4
- activeCalls: Map<CallId, CallRecord>;
5
- providerCallIdMap: Map<string, CallId>;
6
- providerCallId: string;
7
- }): CallRecord | undefined {
8
- const callId = params.providerCallIdMap.get(params.providerCallId);
9
- if (callId) {
10
- return params.activeCalls.get(callId);
11
- }
12
-
13
- for (const call of params.activeCalls.values()) {
14
- if (call.providerCallId === params.providerCallId) {
15
- return call;
16
- }
17
- }
18
- return undefined;
19
- }
20
-
21
- export function findCall(params: {
22
- activeCalls: Map<CallId, CallRecord>;
23
- providerCallIdMap: Map<string, CallId>;
24
- callIdOrProviderCallId: string;
25
- }): CallRecord | undefined {
26
- const directCall = params.activeCalls.get(params.callIdOrProviderCallId);
27
- if (directCall) {
28
- return directCall;
29
- }
30
- return getCallByProviderCallId({
31
- activeCalls: params.activeCalls,
32
- providerCallIdMap: params.providerCallIdMap,
33
- providerCallId: params.callIdOrProviderCallId,
34
- });
35
- }