@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,99 +0,0 @@
1
- import type {
2
- AnswerCallInput,
3
- GetCallStatusInput,
4
- GetCallStatusResult,
5
- HangupCallInput,
6
- InitiateCallInput,
7
- InitiateCallResult,
8
- PlayTtsInput,
9
- ProviderName,
10
- SendDtmfInput,
11
- WebhookParseOptions,
12
- ProviderWebhookParseResult,
13
- StartListeningInput,
14
- StopListeningInput,
15
- WebhookContext,
16
- WebhookVerificationResult,
17
- } from "../types.js";
18
-
19
- /**
20
- * Abstract base interface for voice call providers.
21
- *
22
- * Each provider (Telnyx, Twilio, etc.) implements this interface to provide
23
- * a consistent API for the call manager.
24
- *
25
- * Responsibilities:
26
- * - Webhook verification and event parsing
27
- * - Outbound call initiation and hangup
28
- * - Media control (TTS playback, STT listening)
29
- */
30
- export interface VoiceCallProvider {
31
- /** Provider identifier */
32
- readonly name: ProviderName;
33
-
34
- setPublicUrl?(url: string): void;
35
-
36
- /**
37
- * Verify webhook signature/HMAC before processing.
38
- * Must be called before parseWebhookEvent.
39
- */
40
- verifyWebhook(ctx: WebhookContext): WebhookVerificationResult;
41
-
42
- /**
43
- * Parse provider-specific webhook payload into normalized events.
44
- * Returns events and optional response to send back to provider.
45
- */
46
- parseWebhookEvent(ctx: WebhookContext, options?: WebhookParseOptions): ProviderWebhookParseResult;
47
-
48
- /**
49
- * Consume one-time TwiML that must be served before shortcut handlers such as
50
- * realtime media streams take over the webhook response.
51
- */
52
- consumeInitialTwiML?: (ctx: WebhookContext) => string | null;
53
-
54
- /**
55
- * Initiate an outbound call.
56
- * @returns Provider call ID and status
57
- */
58
- initiateCall(input: InitiateCallInput): Promise<InitiateCallResult>;
59
-
60
- /**
61
- * Answer an accepted inbound call when the provider requires an explicit
62
- * answer command after the initial webhook.
63
- */
64
- answerCall?: (input: AnswerCallInput) => Promise<void>;
65
-
66
- /**
67
- * Hang up an active call.
68
- */
69
- hangupCall(input: HangupCallInput): Promise<void>;
70
-
71
- /**
72
- * Play TTS audio to the caller.
73
- * The provider should handle streaming if supported.
74
- */
75
- playTts(input: PlayTtsInput): Promise<void>;
76
-
77
- /**
78
- * Send DTMF digits to an active call.
79
- */
80
- sendDtmf?: (input: SendDtmfInput) => Promise<void>;
81
-
82
- /**
83
- * Start listening for user speech (activate STT).
84
- */
85
- startListening(input: StartListeningInput): Promise<void>;
86
-
87
- /**
88
- * Stop listening for user speech (deactivate STT).
89
- */
90
- stopListening(input: StopListeningInput): Promise<void>;
91
-
92
- /**
93
- * Query provider for current call status.
94
- * Used to verify persisted calls are still active on restart.
95
- * Must return `isUnknown: true` for transient errors (network, 5xx)
96
- * so the caller can keep the call and rely on timer-based fallback.
97
- */
98
- getCallStatus(input: GetCallStatusInput): Promise<GetCallStatusResult>;
99
- }
@@ -1,86 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import type { WebhookContext } from "../types.js";
3
- import { MockProvider } from "./mock.js";
4
-
5
- function createWebhookContext(rawBody: string): WebhookContext {
6
- return {
7
- headers: {},
8
- rawBody,
9
- url: "http://localhost/voice/webhook",
10
- method: "POST",
11
- query: {},
12
- };
13
- }
14
-
15
- describe("MockProvider", () => {
16
- it("preserves explicit falsy event values", () => {
17
- const provider = new MockProvider();
18
- const beforeParse = Date.now();
19
- const result = provider.parseWebhookEvent(
20
- createWebhookContext(
21
- JSON.stringify({
22
- events: [
23
- {
24
- id: "evt-error",
25
- type: "call.error",
26
- callId: "call-1",
27
- timestamp: 0,
28
- error: "",
29
- retryable: false,
30
- },
31
- {
32
- id: "evt-ended",
33
- type: "call.ended",
34
- callId: "call-2",
35
- reason: "",
36
- },
37
- {
38
- id: "evt-speech",
39
- type: "call.speech",
40
- callId: "call-3",
41
- transcript: "",
42
- isFinal: false,
43
- },
44
- ],
45
- }),
46
- ),
47
- );
48
- const afterParse = Date.now();
49
- const endedTimestamp = result.events[1]?.timestamp;
50
- const speechTimestamp = result.events[2]?.timestamp;
51
-
52
- expect(result.events).toEqual([
53
- {
54
- id: "evt-error",
55
- type: "call.error",
56
- callId: "call-1",
57
- providerCallId: undefined,
58
- timestamp: 0,
59
- error: "",
60
- retryable: false,
61
- },
62
- {
63
- id: "evt-ended",
64
- type: "call.ended",
65
- callId: "call-2",
66
- providerCallId: undefined,
67
- timestamp: endedTimestamp,
68
- reason: "",
69
- },
70
- {
71
- id: "evt-speech",
72
- type: "call.speech",
73
- callId: "call-3",
74
- providerCallId: undefined,
75
- timestamp: speechTimestamp,
76
- transcript: "",
77
- isFinal: false,
78
- confidence: undefined,
79
- },
80
- ]);
81
- expect(endedTimestamp).toBeGreaterThanOrEqual(beforeParse);
82
- expect(endedTimestamp).toBeLessThanOrEqual(afterParse);
83
- expect(speechTimestamp).toBeGreaterThanOrEqual(beforeParse);
84
- expect(speechTimestamp).toBeLessThanOrEqual(afterParse);
85
- });
86
- });
@@ -1,185 +0,0 @@
1
- import crypto from "node:crypto";
2
- import { normalizeLowercaseStringOrEmpty } from "klaw/plugin-sdk/string-coerce-runtime";
3
- import type {
4
- EndReason,
5
- GetCallStatusInput,
6
- GetCallStatusResult,
7
- HangupCallInput,
8
- InitiateCallInput,
9
- InitiateCallResult,
10
- NormalizedEvent,
11
- PlayTtsInput,
12
- WebhookParseOptions,
13
- ProviderWebhookParseResult,
14
- SendDtmfInput,
15
- StartListeningInput,
16
- StopListeningInput,
17
- WebhookContext,
18
- WebhookVerificationResult,
19
- } from "../types.js";
20
- import type { VoiceCallProvider } from "./base.js";
21
-
22
- /**
23
- * Mock voice call provider for local testing.
24
- *
25
- * Events are driven via webhook POST with JSON body:
26
- * - { events: NormalizedEvent[] } for bulk events
27
- * - { event: NormalizedEvent } for single event
28
- */
29
- export class MockProvider implements VoiceCallProvider {
30
- readonly name = "mock" as const;
31
-
32
- verifyWebhook(_ctx: WebhookContext): WebhookVerificationResult {
33
- return { ok: true };
34
- }
35
-
36
- parseWebhookEvent(
37
- ctx: WebhookContext,
38
- _options?: WebhookParseOptions,
39
- ): ProviderWebhookParseResult {
40
- try {
41
- const payload = JSON.parse(ctx.rawBody);
42
- const events: NormalizedEvent[] = [];
43
-
44
- if (Array.isArray(payload.events)) {
45
- for (const evt of payload.events) {
46
- const normalized = this.normalizeEvent(evt);
47
- if (normalized) {
48
- events.push(normalized);
49
- }
50
- }
51
- } else if (payload.event) {
52
- const normalized = this.normalizeEvent(payload.event);
53
- if (normalized) {
54
- events.push(normalized);
55
- }
56
- }
57
-
58
- return { events, statusCode: 200 };
59
- } catch {
60
- return { events: [], statusCode: 400 };
61
- }
62
- }
63
-
64
- private normalizeEvent(evt: Partial<NormalizedEvent>): NormalizedEvent | null {
65
- if (!evt.type || !evt.callId) {
66
- return null;
67
- }
68
-
69
- const base = {
70
- id: evt.id ?? crypto.randomUUID(),
71
- callId: evt.callId,
72
- providerCallId: evt.providerCallId,
73
- timestamp: evt.timestamp ?? Date.now(),
74
- };
75
-
76
- switch (evt.type) {
77
- case "call.initiated":
78
- case "call.ringing":
79
- case "call.answered":
80
- case "call.active":
81
- return { ...base, type: evt.type };
82
-
83
- case "call.speaking": {
84
- const payload = evt as Partial<NormalizedEvent & { text?: string }>;
85
- return {
86
- ...base,
87
- type: evt.type,
88
- text: payload.text ?? "",
89
- };
90
- }
91
-
92
- case "call.speech": {
93
- const payload = evt as Partial<
94
- NormalizedEvent & {
95
- transcript?: string;
96
- isFinal?: boolean;
97
- confidence?: number;
98
- }
99
- >;
100
- return {
101
- ...base,
102
- type: evt.type,
103
- transcript: payload.transcript ?? "",
104
- isFinal: payload.isFinal ?? true,
105
- confidence: payload.confidence,
106
- };
107
- }
108
-
109
- case "call.silence": {
110
- const payload = evt as Partial<NormalizedEvent & { durationMs?: number }>;
111
- return {
112
- ...base,
113
- type: evt.type,
114
- durationMs: payload.durationMs ?? 0,
115
- };
116
- }
117
-
118
- case "call.dtmf": {
119
- const payload = evt as Partial<NormalizedEvent & { digits?: string }>;
120
- return {
121
- ...base,
122
- type: evt.type,
123
- digits: payload.digits ?? "",
124
- };
125
- }
126
-
127
- case "call.ended": {
128
- const payload = evt as Partial<NormalizedEvent & { reason?: EndReason }>;
129
- return {
130
- ...base,
131
- type: evt.type,
132
- reason: payload.reason ?? "completed",
133
- };
134
- }
135
-
136
- case "call.error": {
137
- const payload = evt as Partial<NormalizedEvent & { error?: string; retryable?: boolean }>;
138
- return {
139
- ...base,
140
- type: evt.type,
141
- error: payload.error ?? "unknown error",
142
- retryable: payload.retryable,
143
- };
144
- }
145
-
146
- default:
147
- return null;
148
- }
149
- }
150
-
151
- async initiateCall(input: InitiateCallInput): Promise<InitiateCallResult> {
152
- return {
153
- providerCallId: `mock-${input.callId}`,
154
- status: "initiated",
155
- };
156
- }
157
-
158
- async hangupCall(_input: HangupCallInput): Promise<void> {
159
- // No-op for mock
160
- }
161
-
162
- async playTts(_input: PlayTtsInput): Promise<void> {
163
- // No-op for mock
164
- }
165
-
166
- async sendDtmf(_input: SendDtmfInput): Promise<void> {
167
- // No-op for mock
168
- }
169
-
170
- async startListening(_input: StartListeningInput): Promise<void> {
171
- // No-op for mock
172
- }
173
-
174
- async stopListening(_input: StopListeningInput): Promise<void> {
175
- // No-op for mock
176
- }
177
-
178
- async getCallStatus(input: GetCallStatusInput): Promise<GetCallStatusResult> {
179
- const id = normalizeLowercaseStringOrEmpty(input.providerCallId);
180
- if (id.includes("stale") || id.includes("ended") || id.includes("completed")) {
181
- return { status: "completed", isTerminal: true };
182
- }
183
- return { status: "in-progress", isTerminal: false };
184
- }
185
- }
@@ -1,93 +0,0 @@
1
- import { describe, expect, it } from "vitest";
2
- import { PlivoProvider } from "./plivo.js";
3
-
4
- function requireEvent<T>(event: T | undefined, message: string): T {
5
- if (!event) {
6
- throw new Error(message);
7
- }
8
- return event;
9
- }
10
-
11
- function requireResponseBody(body: string | undefined): string {
12
- if (!body) {
13
- throw new Error("Plivo provider did not return a response body");
14
- }
15
- return body;
16
- }
17
-
18
- describe("PlivoProvider", () => {
19
- it("parses answer callback into call.answered and returns keep-alive XML", () => {
20
- const provider = new PlivoProvider({
21
- authId: "MA000000000000000000",
22
- authToken: "test-token",
23
- });
24
-
25
- const result = provider.parseWebhookEvent({
26
- headers: { host: "example.com" },
27
- rawBody:
28
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
29
- url: "https://example.com/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
30
- method: "POST",
31
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
32
- });
33
-
34
- expect(result.events).toHaveLength(1);
35
- const event = requireEvent(result.events[0], "expected Plivo answer event");
36
- expect(event.type).toBe("call.answered");
37
- expect(event.callId).toBe("internal-call-id");
38
- expect(event.providerCallId).toBe("call-uuid");
39
- const responseBody = requireResponseBody(result.providerResponseBody);
40
- expect(responseBody).toContain("<Wait");
41
- expect(responseBody).toContain('length="300"');
42
- });
43
-
44
- it("uses verified request key when provided", () => {
45
- const provider = new PlivoProvider({
46
- authId: "MA000000000000000000",
47
- authToken: "test-token",
48
- });
49
-
50
- const result = provider.parseWebhookEvent(
51
- {
52
- headers: { host: "example.com", "x-plivo-signature-v3-nonce": "nonce-1" },
53
- rawBody:
54
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
55
- url: "https://example.com/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
56
- method: "POST",
57
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
58
- },
59
- { verifiedRequestKey: "plivo:v3:verified" },
60
- );
61
-
62
- expect(result.events).toHaveLength(1);
63
- expect(requireEvent(result.events[0], "expected verified Plivo event").dedupeKey).toBe(
64
- "plivo:v3:verified",
65
- );
66
- });
67
-
68
- it("pins stored callback bases to publicUrl instead of request Host", () => {
69
- const provider = new PlivoProvider(
70
- {
71
- authId: "MA000000000000000000",
72
- authToken: "test-token",
73
- },
74
- {
75
- publicUrl: "https://voice.kodelyth.com/voice/webhook?provider=plivo",
76
- },
77
- );
78
-
79
- provider.parseWebhookEvent({
80
- headers: { host: "attacker.example" },
81
- rawBody:
82
- "CallUUID=call-uuid&CallStatus=in-progress&Direction=outbound&From=%2B15550000000&To=%2B15550000001&Event=StartApp",
83
- url: "https://attacker.example/voice/webhook?provider=plivo&flow=answer&callId=internal-call-id",
84
- method: "POST",
85
- query: { provider: "plivo", flow: "answer", callId: "internal-call-id" },
86
- });
87
-
88
- const callbackMap = (provider as unknown as { callUuidToWebhookUrl: Map<string, string> })
89
- .callUuidToWebhookUrl;
90
-
91
- expect(callbackMap.get("call-uuid")).toBe("https://voice.kodelyth.com/voice/webhook");
92
- });
93
- });