@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.
- package/dist/api.js +2 -0
- package/dist/call-status-CXldV5o8.js +32 -0
- package/dist/cli-metadata.js +12 -0
- package/dist/config-7w04YpHh.js +548 -0
- package/dist/config-compat-B0me39_4.js +129 -0
- package/dist/guarded-json-api-Btx5EE4w.js +591 -0
- package/dist/http-headers-BrnxBasF.js +10 -0
- package/dist/index.js +1284 -0
- package/dist/mock-CeKvfVEd.js +135 -0
- package/dist/plivo-B-a7KFoT.js +393 -0
- package/dist/realtime-handler-B63CIDP2.js +325 -0
- package/dist/realtime-transcription.runtime-B2h70y2W.js +2 -0
- package/dist/realtime-voice.runtime-Bkh4nvLn.js +2 -0
- package/dist/response-generator-BrcmwDZU.js +182 -0
- package/dist/response-model-CyF5K80p.js +12 -0
- package/dist/runtime-api.js +6 -0
- package/dist/runtime-entry-88ytYAQa.js +3119 -0
- package/dist/runtime-entry.js +2 -0
- package/dist/setup-api.js +37 -0
- package/dist/telnyx-jjBE8boz.js +260 -0
- package/dist/twilio-1OqbcXLL.js +676 -0
- package/dist/voice-mapping-BYDGdWGx.js +40 -0
- package/package.json +14 -6
- package/api.ts +0 -16
- package/cli-metadata.ts +0 -10
- package/config-api.ts +0 -12
- package/index.test.ts +0 -943
- package/index.ts +0 -794
- package/runtime-api.ts +0 -20
- package/runtime-entry.ts +0 -1
- package/setup-api.ts +0 -47
- package/src/allowlist.test.ts +0 -18
- package/src/allowlist.ts +0 -19
- package/src/cli.ts +0 -845
- package/src/config-compat.test.ts +0 -120
- package/src/config-compat.ts +0 -227
- package/src/config.test.ts +0 -479
- package/src/config.ts +0 -808
- package/src/core-bridge.ts +0 -14
- package/src/deep-merge.test.ts +0 -40
- package/src/deep-merge.ts +0 -23
- package/src/gateway-continue-operation.ts +0 -200
- package/src/http-headers.test.ts +0 -16
- package/src/http-headers.ts +0 -15
- package/src/manager/context.ts +0 -42
- package/src/manager/events.test.ts +0 -581
- package/src/manager/events.ts +0 -288
- package/src/manager/lifecycle.ts +0 -53
- package/src/manager/lookup.test.ts +0 -52
- package/src/manager/lookup.ts +0 -35
- package/src/manager/outbound.test.ts +0 -528
- package/src/manager/outbound.ts +0 -486
- package/src/manager/state.ts +0 -48
- package/src/manager/store.ts +0 -106
- package/src/manager/timers.test.ts +0 -129
- package/src/manager/timers.ts +0 -113
- package/src/manager/twiml.test.ts +0 -13
- package/src/manager/twiml.ts +0 -17
- package/src/manager.closed-loop.test.ts +0 -236
- package/src/manager.inbound-allowlist.test.ts +0 -188
- package/src/manager.notify.test.ts +0 -377
- package/src/manager.restore.test.ts +0 -183
- package/src/manager.test-harness.ts +0 -127
- package/src/manager.ts +0 -392
- package/src/media-stream.test.ts +0 -768
- package/src/media-stream.ts +0 -708
- package/src/providers/base.ts +0 -97
- package/src/providers/mock.test.ts +0 -78
- package/src/providers/mock.ts +0 -185
- package/src/providers/plivo.test.ts +0 -93
- package/src/providers/plivo.ts +0 -601
- package/src/providers/shared/call-status.test.ts +0 -24
- package/src/providers/shared/call-status.ts +0 -24
- package/src/providers/shared/guarded-json-api.test.ts +0 -106
- package/src/providers/shared/guarded-json-api.ts +0 -42
- package/src/providers/telnyx.test.ts +0 -340
- package/src/providers/telnyx.ts +0 -394
- package/src/providers/twilio/api.test.ts +0 -145
- package/src/providers/twilio/api.ts +0 -93
- package/src/providers/twilio/twiml-policy.test.ts +0 -84
- package/src/providers/twilio/twiml-policy.ts +0 -87
- package/src/providers/twilio/webhook.ts +0 -34
- package/src/providers/twilio.test.ts +0 -591
- package/src/providers/twilio.ts +0 -861
- package/src/providers/twilio.types.ts +0 -17
- package/src/realtime-defaults.ts +0 -3
- package/src/realtime-fast-context.test.ts +0 -88
- package/src/realtime-fast-context.ts +0 -165
- package/src/realtime-transcription.runtime.ts +0 -4
- package/src/realtime-voice.runtime.ts +0 -5
- package/src/response-generator.test.ts +0 -321
- package/src/response-generator.ts +0 -318
- package/src/response-model.test.ts +0 -71
- package/src/response-model.ts +0 -23
- package/src/runtime.test.ts +0 -536
- package/src/runtime.ts +0 -510
- package/src/telephony-audio.test.ts +0 -61
- package/src/telephony-audio.ts +0 -12
- package/src/telephony-tts.test.ts +0 -196
- package/src/telephony-tts.ts +0 -235
- package/src/test-fixtures.ts +0 -73
- package/src/tts-provider-voice.test.ts +0 -34
- package/src/tts-provider-voice.ts +0 -21
- package/src/tunnel.test.ts +0 -166
- package/src/tunnel.ts +0 -314
- package/src/types.ts +0 -291
- package/src/utils.test.ts +0 -17
- package/src/utils.ts +0 -14
- package/src/voice-mapping.test.ts +0 -34
- package/src/voice-mapping.ts +0 -68
- package/src/webhook/realtime-handler.test.ts +0 -598
- package/src/webhook/realtime-handler.ts +0 -485
- package/src/webhook/stale-call-reaper.test.ts +0 -88
- package/src/webhook/stale-call-reaper.ts +0 -38
- package/src/webhook/tailscale.test.ts +0 -214
- package/src/webhook/tailscale.ts +0 -129
- package/src/webhook-exposure.test.ts +0 -33
- package/src/webhook-exposure.ts +0 -84
- package/src/webhook-security.test.ts +0 -770
- package/src/webhook-security.ts +0 -994
- package/src/webhook.hangup-once.lifecycle.test.ts +0 -135
- package/src/webhook.test.ts +0 -1470
- package/src/webhook.ts +0 -908
- package/src/webhook.types.ts +0 -5
- package/src/websocket-test-support.ts +0 -72
- package/tsconfig.json +0 -16
|
@@ -1,196 +0,0 @@
|
|
|
1
|
-
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
2
|
-
import type { VoiceCallTtsConfig } from "./config.js";
|
|
3
|
-
import type { CoreConfig } from "./core-bridge.js";
|
|
4
|
-
import { createTelephonyTtsProvider } from "./telephony-tts.js";
|
|
5
|
-
|
|
6
|
-
function createCoreConfig(): CoreConfig {
|
|
7
|
-
const tts: VoiceCallTtsConfig = {
|
|
8
|
-
provider: "openai",
|
|
9
|
-
providers: {
|
|
10
|
-
openai: {
|
|
11
|
-
model: "gpt-4o-mini-tts",
|
|
12
|
-
voice: "alloy",
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
};
|
|
16
|
-
return { messages: { tts } };
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function requireMergedTtsConfig(mergedConfig: CoreConfig | undefined) {
|
|
20
|
-
const tts = mergedConfig?.messages?.tts;
|
|
21
|
-
if (!tts) {
|
|
22
|
-
throw new Error("telephony TTS runtime did not receive merged TTS config");
|
|
23
|
-
}
|
|
24
|
-
return tts as Record<string, unknown>;
|
|
25
|
-
}
|
|
26
|
-
|
|
27
|
-
function requireOpenAIProviderConfig(tts: Record<string, unknown>): Record<string, unknown> {
|
|
28
|
-
const providers =
|
|
29
|
-
tts.providers && typeof tts.providers === "object"
|
|
30
|
-
? (tts.providers as Record<string, unknown>)
|
|
31
|
-
: null;
|
|
32
|
-
const openai = providers?.openai;
|
|
33
|
-
if (!openai || typeof openai !== "object") {
|
|
34
|
-
throw new Error("merged TTS config did not preserve providers.openai");
|
|
35
|
-
}
|
|
36
|
-
return openai as Record<string, unknown>;
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
async function mergeOverride(override: unknown): Promise<Record<string, unknown>> {
|
|
40
|
-
let mergedConfig: CoreConfig | undefined;
|
|
41
|
-
const provider = createTelephonyTtsProvider({
|
|
42
|
-
coreConfig: createCoreConfig(),
|
|
43
|
-
ttsOverride: override as VoiceCallTtsConfig,
|
|
44
|
-
runtime: {
|
|
45
|
-
textToSpeechTelephony: async ({ cfg }) => {
|
|
46
|
-
mergedConfig = cfg;
|
|
47
|
-
return {
|
|
48
|
-
success: true,
|
|
49
|
-
audioBuffer: Buffer.alloc(2),
|
|
50
|
-
sampleRate: 8000,
|
|
51
|
-
};
|
|
52
|
-
},
|
|
53
|
-
},
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
await provider.synthesizeForTelephony("hello");
|
|
57
|
-
return requireMergedTtsConfig(mergedConfig);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
afterEach(() => {
|
|
61
|
-
delete (Object.prototype as Record<string, unknown>).polluted;
|
|
62
|
-
});
|
|
63
|
-
|
|
64
|
-
describe("createTelephonyTtsProvider deepMerge hardening", () => {
|
|
65
|
-
it("merges safe nested overrides", async () => {
|
|
66
|
-
const tts = await mergeOverride({
|
|
67
|
-
providers: { openai: { voice: "coral" } },
|
|
68
|
-
});
|
|
69
|
-
const openai = requireOpenAIProviderConfig(tts);
|
|
70
|
-
|
|
71
|
-
expect(openai.voice).toBe("coral");
|
|
72
|
-
expect(openai.model).toBe("gpt-4o-mini-tts");
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it("blocks top-level __proto__ keys", async () => {
|
|
76
|
-
const tts = await mergeOverride(
|
|
77
|
-
JSON.parse('{"__proto__":{"polluted":"top"},"providers":{"openai":{"voice":"coral"}}}'),
|
|
78
|
-
);
|
|
79
|
-
const openai = requireOpenAIProviderConfig(tts);
|
|
80
|
-
|
|
81
|
-
expect((Object.prototype as Record<string, unknown>).polluted).toBeUndefined();
|
|
82
|
-
expect(tts.polluted).toBeUndefined();
|
|
83
|
-
expect(openai.voice).toBe("coral");
|
|
84
|
-
});
|
|
85
|
-
|
|
86
|
-
it("blocks nested __proto__ keys", async () => {
|
|
87
|
-
const tts = await mergeOverride(
|
|
88
|
-
JSON.parse('{"providers":{"openai":{"model":"safe","__proto__":{"polluted":"nested"}}}}'),
|
|
89
|
-
);
|
|
90
|
-
const openai = requireOpenAIProviderConfig(tts);
|
|
91
|
-
|
|
92
|
-
expect((Object.prototype as Record<string, unknown>).polluted).toBeUndefined();
|
|
93
|
-
expect(openai.polluted).toBeUndefined();
|
|
94
|
-
expect(openai.model).toBe("safe");
|
|
95
|
-
});
|
|
96
|
-
|
|
97
|
-
it("logs fallback metadata when telephony TTS uses a fallback provider", async () => {
|
|
98
|
-
const warn = vi.fn();
|
|
99
|
-
const provider = createTelephonyTtsProvider({
|
|
100
|
-
coreConfig: createCoreConfig(),
|
|
101
|
-
runtime: {
|
|
102
|
-
textToSpeechTelephony: async () => ({
|
|
103
|
-
success: true,
|
|
104
|
-
audioBuffer: Buffer.alloc(2),
|
|
105
|
-
sampleRate: 8000,
|
|
106
|
-
provider: "microsoft",
|
|
107
|
-
fallbackFrom: "elevenlabs",
|
|
108
|
-
attemptedProviders: ["elevenlabs", "microsoft"],
|
|
109
|
-
}),
|
|
110
|
-
},
|
|
111
|
-
logger: { warn },
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
await provider.synthesizeForTelephony("hello");
|
|
115
|
-
expect(warn).toHaveBeenCalledWith(
|
|
116
|
-
"[voice-call] Telephony TTS fallback used from=elevenlabs to=microsoft attempts=elevenlabs -> microsoft",
|
|
117
|
-
);
|
|
118
|
-
});
|
|
119
|
-
|
|
120
|
-
it("strips telephony TTS directive tags before synthesis", async () => {
|
|
121
|
-
let requestText: string | undefined;
|
|
122
|
-
const provider = createTelephonyTtsProvider({
|
|
123
|
-
coreConfig: createCoreConfig(),
|
|
124
|
-
runtime: {
|
|
125
|
-
textToSpeechTelephony: async ({ text }) => {
|
|
126
|
-
requestText = text;
|
|
127
|
-
return {
|
|
128
|
-
success: true,
|
|
129
|
-
audioBuffer: Buffer.alloc(2),
|
|
130
|
-
sampleRate: 8000,
|
|
131
|
-
};
|
|
132
|
-
},
|
|
133
|
-
},
|
|
134
|
-
});
|
|
135
|
-
|
|
136
|
-
await provider.synthesizeForTelephony("[[tts]]Hello caller[[/tts]]");
|
|
137
|
-
|
|
138
|
-
expect(requestText).toBe("Hello caller");
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
it("uses hidden telephony TTS directive text for synthesis", async () => {
|
|
142
|
-
let requestText: string | undefined;
|
|
143
|
-
let requestOverrides: unknown;
|
|
144
|
-
const provider = createTelephonyTtsProvider({
|
|
145
|
-
coreConfig: createCoreConfig(),
|
|
146
|
-
runtime: {
|
|
147
|
-
textToSpeechTelephony: async ({ text, overrides }) => {
|
|
148
|
-
requestText = text;
|
|
149
|
-
requestOverrides = overrides;
|
|
150
|
-
return {
|
|
151
|
-
success: true,
|
|
152
|
-
audioBuffer: Buffer.alloc(2),
|
|
153
|
-
sampleRate: 8000,
|
|
154
|
-
};
|
|
155
|
-
},
|
|
156
|
-
},
|
|
157
|
-
});
|
|
158
|
-
|
|
159
|
-
await provider.synthesizeForTelephony(
|
|
160
|
-
"Visible text [[tts:text]]Speak this instead[[/tts:text]]",
|
|
161
|
-
);
|
|
162
|
-
|
|
163
|
-
expect(requestText).toBe("Speak this instead");
|
|
164
|
-
expect(requestOverrides).toMatchObject({ ttsText: "Speak this instead" });
|
|
165
|
-
});
|
|
166
|
-
|
|
167
|
-
it("exposes configured timeoutMs as synthesisTimeoutMs", () => {
|
|
168
|
-
const provider = createTelephonyTtsProvider({
|
|
169
|
-
coreConfig: { messages: { tts: { provider: "openai", timeoutMs: 15000 } } },
|
|
170
|
-
runtime: {
|
|
171
|
-
textToSpeechTelephony: async () => ({
|
|
172
|
-
success: true,
|
|
173
|
-
audioBuffer: Buffer.alloc(2),
|
|
174
|
-
sampleRate: 8000,
|
|
175
|
-
}),
|
|
176
|
-
},
|
|
177
|
-
});
|
|
178
|
-
|
|
179
|
-
expect(provider.synthesisTimeoutMs).toBe(15000);
|
|
180
|
-
});
|
|
181
|
-
|
|
182
|
-
it("keeps the telephony timeout default when timeoutMs is not configured", () => {
|
|
183
|
-
const provider = createTelephonyTtsProvider({
|
|
184
|
-
coreConfig: createCoreConfig(),
|
|
185
|
-
runtime: {
|
|
186
|
-
textToSpeechTelephony: async () => ({
|
|
187
|
-
success: true,
|
|
188
|
-
audioBuffer: Buffer.alloc(2),
|
|
189
|
-
sampleRate: 8000,
|
|
190
|
-
}),
|
|
191
|
-
},
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
expect(provider.synthesisTimeoutMs).toBe(8000);
|
|
195
|
-
});
|
|
196
|
-
});
|
package/src/telephony-tts.ts
DELETED
|
@@ -1,235 +0,0 @@
|
|
|
1
|
-
import {
|
|
2
|
-
parseTtsDirectives,
|
|
3
|
-
type SpeechModelOverridePolicy,
|
|
4
|
-
type SpeechProviderConfig,
|
|
5
|
-
type TtsDirectiveOverrides,
|
|
6
|
-
} from "openclaw/plugin-sdk/speech";
|
|
7
|
-
import type { VoiceCallTtsConfig } from "./config.js";
|
|
8
|
-
import type { CoreConfig } from "./core-bridge.js";
|
|
9
|
-
import { deepMergeDefined } from "./deep-merge.js";
|
|
10
|
-
import { convertPcmToMulaw8k } from "./telephony-audio.js";
|
|
11
|
-
|
|
12
|
-
export type TelephonyTtsRuntime = {
|
|
13
|
-
textToSpeechTelephony: (params: {
|
|
14
|
-
text: string;
|
|
15
|
-
cfg: CoreConfig;
|
|
16
|
-
prefsPath?: string;
|
|
17
|
-
overrides?: TtsDirectiveOverrides;
|
|
18
|
-
}) => Promise<{
|
|
19
|
-
success: boolean;
|
|
20
|
-
audioBuffer?: Buffer;
|
|
21
|
-
sampleRate?: number;
|
|
22
|
-
provider?: string;
|
|
23
|
-
fallbackFrom?: string;
|
|
24
|
-
attemptedProviders?: string[];
|
|
25
|
-
error?: string;
|
|
26
|
-
}>;
|
|
27
|
-
};
|
|
28
|
-
|
|
29
|
-
export type TelephonyTtsProvider = {
|
|
30
|
-
synthesisTimeoutMs: number;
|
|
31
|
-
synthesizeForTelephony: (text: string) => Promise<Buffer>;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
export const TELEPHONY_DEFAULT_TTS_TIMEOUT_MS = 8000;
|
|
35
|
-
|
|
36
|
-
type TelephonyModelOverrideConfig = {
|
|
37
|
-
enabled?: boolean;
|
|
38
|
-
allowText?: boolean;
|
|
39
|
-
allowProvider?: boolean;
|
|
40
|
-
allowVoice?: boolean;
|
|
41
|
-
allowModelId?: boolean;
|
|
42
|
-
allowVoiceSettings?: boolean;
|
|
43
|
-
allowNormalization?: boolean;
|
|
44
|
-
allowSeed?: boolean;
|
|
45
|
-
};
|
|
46
|
-
|
|
47
|
-
export function createTelephonyTtsProvider(params: {
|
|
48
|
-
coreConfig: CoreConfig;
|
|
49
|
-
ttsOverride?: VoiceCallTtsConfig;
|
|
50
|
-
runtime: TelephonyTtsRuntime;
|
|
51
|
-
logger?: {
|
|
52
|
-
warn?: (message: string) => void;
|
|
53
|
-
};
|
|
54
|
-
}): TelephonyTtsProvider {
|
|
55
|
-
const { coreConfig, ttsOverride, runtime, logger } = params;
|
|
56
|
-
const mergedConfig = applyTtsOverride(coreConfig, ttsOverride);
|
|
57
|
-
const ttsConfig = mergedConfig.messages?.tts;
|
|
58
|
-
const modelOverrides = resolveTelephonyModelOverridePolicy(
|
|
59
|
-
readTelephonyModelOverrides(ttsConfig),
|
|
60
|
-
);
|
|
61
|
-
const providerConfigs = collectTelephonyProviderConfigs(ttsConfig);
|
|
62
|
-
const activeProvider = normalizeProviderId(ttsConfig?.provider);
|
|
63
|
-
const synthesisTimeoutMs =
|
|
64
|
-
mergedConfig.messages?.tts?.timeoutMs ?? TELEPHONY_DEFAULT_TTS_TIMEOUT_MS;
|
|
65
|
-
|
|
66
|
-
return {
|
|
67
|
-
synthesisTimeoutMs,
|
|
68
|
-
synthesizeForTelephony: async (text: string) => {
|
|
69
|
-
const directives = parseTtsDirectives(text, modelOverrides, {
|
|
70
|
-
cfg: mergedConfig,
|
|
71
|
-
providerConfigs,
|
|
72
|
-
preferredProviderId: activeProvider,
|
|
73
|
-
});
|
|
74
|
-
if (directives.warnings.length > 0) {
|
|
75
|
-
logger?.warn?.(
|
|
76
|
-
`[voice-call] Ignored telephony TTS directive overrides (${directives.warnings.join("; ")})`,
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
const cleanText = directives.hasDirective
|
|
80
|
-
? directives.ttsText?.trim() || directives.cleanedText.trim()
|
|
81
|
-
: text;
|
|
82
|
-
const result = await runtime.textToSpeechTelephony({
|
|
83
|
-
text: cleanText,
|
|
84
|
-
cfg: mergedConfig,
|
|
85
|
-
overrides: directives.overrides,
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
if (!result.success || !result.audioBuffer || !result.sampleRate) {
|
|
89
|
-
throw new Error(result.error ?? "TTS conversion failed");
|
|
90
|
-
}
|
|
91
|
-
|
|
92
|
-
if (result.fallbackFrom && result.provider && result.fallbackFrom !== result.provider) {
|
|
93
|
-
const attemptedChain =
|
|
94
|
-
result.attemptedProviders && result.attemptedProviders.length > 0
|
|
95
|
-
? result.attemptedProviders.join(" -> ")
|
|
96
|
-
: `${result.fallbackFrom} -> ${result.provider}`;
|
|
97
|
-
logger?.warn?.(
|
|
98
|
-
`[voice-call] Telephony TTS fallback used from=${result.fallbackFrom} to=${result.provider} attempts=${attemptedChain}`,
|
|
99
|
-
);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
return convertPcmToMulaw8k(result.audioBuffer, result.sampleRate);
|
|
103
|
-
},
|
|
104
|
-
};
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
function applyTtsOverride(coreConfig: CoreConfig, override?: VoiceCallTtsConfig): CoreConfig {
|
|
108
|
-
if (!override) {
|
|
109
|
-
return coreConfig;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
const base = coreConfig.messages?.tts;
|
|
113
|
-
const merged = mergeTtsConfig(base, override);
|
|
114
|
-
if (!merged) {
|
|
115
|
-
return coreConfig;
|
|
116
|
-
}
|
|
117
|
-
|
|
118
|
-
return {
|
|
119
|
-
...coreConfig,
|
|
120
|
-
messages: {
|
|
121
|
-
...coreConfig.messages,
|
|
122
|
-
tts: merged,
|
|
123
|
-
},
|
|
124
|
-
};
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
function mergeTtsConfig(
|
|
128
|
-
base?: VoiceCallTtsConfig,
|
|
129
|
-
override?: VoiceCallTtsConfig,
|
|
130
|
-
): VoiceCallTtsConfig | undefined {
|
|
131
|
-
if (!base && !override) {
|
|
132
|
-
return undefined;
|
|
133
|
-
}
|
|
134
|
-
if (!override) {
|
|
135
|
-
return base;
|
|
136
|
-
}
|
|
137
|
-
if (!base) {
|
|
138
|
-
return override;
|
|
139
|
-
}
|
|
140
|
-
return deepMergeDefined(base, override) as VoiceCallTtsConfig;
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function resolveTelephonyModelOverridePolicy(
|
|
144
|
-
overrides: TelephonyModelOverrideConfig | undefined,
|
|
145
|
-
): SpeechModelOverridePolicy {
|
|
146
|
-
const enabled = overrides?.enabled ?? true;
|
|
147
|
-
if (!enabled) {
|
|
148
|
-
return {
|
|
149
|
-
enabled: false,
|
|
150
|
-
allowText: false,
|
|
151
|
-
allowProvider: false,
|
|
152
|
-
allowVoice: false,
|
|
153
|
-
allowModelId: false,
|
|
154
|
-
allowVoiceSettings: false,
|
|
155
|
-
allowNormalization: false,
|
|
156
|
-
allowSeed: false,
|
|
157
|
-
};
|
|
158
|
-
}
|
|
159
|
-
const allow = (value: boolean | undefined, defaultValue = true) => value ?? defaultValue;
|
|
160
|
-
return {
|
|
161
|
-
enabled: true,
|
|
162
|
-
allowText: allow(overrides?.allowText),
|
|
163
|
-
allowProvider: allow(overrides?.allowProvider, false),
|
|
164
|
-
allowVoice: allow(overrides?.allowVoice),
|
|
165
|
-
allowModelId: allow(overrides?.allowModelId),
|
|
166
|
-
allowVoiceSettings: allow(overrides?.allowVoiceSettings),
|
|
167
|
-
allowNormalization: allow(overrides?.allowNormalization),
|
|
168
|
-
allowSeed: allow(overrides?.allowSeed),
|
|
169
|
-
};
|
|
170
|
-
}
|
|
171
|
-
|
|
172
|
-
function readTelephonyModelOverrides(
|
|
173
|
-
ttsConfig: VoiceCallTtsConfig | undefined,
|
|
174
|
-
): TelephonyModelOverrideConfig | undefined {
|
|
175
|
-
const value = (ttsConfig as Record<string, unknown> | undefined)?.modelOverrides;
|
|
176
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
177
|
-
? (value as TelephonyModelOverrideConfig)
|
|
178
|
-
: undefined;
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
function normalizeProviderId(value: unknown): string | undefined {
|
|
182
|
-
return typeof value === "string" ? value.trim().toLowerCase() || undefined : undefined;
|
|
183
|
-
}
|
|
184
|
-
|
|
185
|
-
function asProviderConfig(value: unknown): SpeechProviderConfig {
|
|
186
|
-
return value && typeof value === "object" && !Array.isArray(value)
|
|
187
|
-
? (value as SpeechProviderConfig)
|
|
188
|
-
: {};
|
|
189
|
-
}
|
|
190
|
-
|
|
191
|
-
function collectTelephonyProviderConfigs(
|
|
192
|
-
ttsConfig: VoiceCallTtsConfig | undefined,
|
|
193
|
-
): Record<string, SpeechProviderConfig> {
|
|
194
|
-
if (!ttsConfig) {
|
|
195
|
-
return {};
|
|
196
|
-
}
|
|
197
|
-
const entries: Record<string, SpeechProviderConfig> = {};
|
|
198
|
-
const rawProviders =
|
|
199
|
-
ttsConfig.providers &&
|
|
200
|
-
typeof ttsConfig.providers === "object" &&
|
|
201
|
-
!Array.isArray(ttsConfig.providers)
|
|
202
|
-
? (ttsConfig.providers as Record<string, unknown>)
|
|
203
|
-
: {};
|
|
204
|
-
for (const [providerId, value] of Object.entries(rawProviders)) {
|
|
205
|
-
const normalized = normalizeProviderId(providerId) ?? providerId;
|
|
206
|
-
entries[normalized] = asProviderConfig(value);
|
|
207
|
-
}
|
|
208
|
-
const reservedKeys = new Set([
|
|
209
|
-
"auto",
|
|
210
|
-
"enabled",
|
|
211
|
-
"maxTextLength",
|
|
212
|
-
"mode",
|
|
213
|
-
"modelOverrides",
|
|
214
|
-
"persona",
|
|
215
|
-
"personas",
|
|
216
|
-
"prefsPath",
|
|
217
|
-
"provider",
|
|
218
|
-
"providers",
|
|
219
|
-
"summaryModel",
|
|
220
|
-
"timeoutMs",
|
|
221
|
-
]);
|
|
222
|
-
for (const [key, value] of Object.entries(ttsConfig as Record<string, unknown>)) {
|
|
223
|
-
if (
|
|
224
|
-
reservedKeys.has(key) ||
|
|
225
|
-
typeof value !== "object" ||
|
|
226
|
-
value === null ||
|
|
227
|
-
Array.isArray(value)
|
|
228
|
-
) {
|
|
229
|
-
continue;
|
|
230
|
-
}
|
|
231
|
-
const normalized = normalizeProviderId(key) ?? key;
|
|
232
|
-
entries[normalized] ??= asProviderConfig(value);
|
|
233
|
-
}
|
|
234
|
-
return entries;
|
|
235
|
-
}
|
package/src/test-fixtures.ts
DELETED
|
@@ -1,73 +0,0 @@
|
|
|
1
|
-
import type { VoiceCallConfig } from "./config.js";
|
|
2
|
-
import { DEFAULT_VOICE_CALL_REALTIME_INSTRUCTIONS } from "./realtime-defaults.js";
|
|
3
|
-
|
|
4
|
-
export function createVoiceCallBaseConfig(params?: {
|
|
5
|
-
provider?: "telnyx" | "twilio" | "plivo" | "mock";
|
|
6
|
-
tunnelProvider?: "none" | "ngrok";
|
|
7
|
-
}): VoiceCallConfig {
|
|
8
|
-
return {
|
|
9
|
-
enabled: true,
|
|
10
|
-
provider: params?.provider ?? "mock",
|
|
11
|
-
fromNumber: "+15550001234",
|
|
12
|
-
inboundPolicy: "disabled",
|
|
13
|
-
allowFrom: [],
|
|
14
|
-
numbers: {},
|
|
15
|
-
outbound: { defaultMode: "notify", notifyHangupDelaySec: 3 },
|
|
16
|
-
maxDurationSeconds: 300,
|
|
17
|
-
staleCallReaperSeconds: 600,
|
|
18
|
-
silenceTimeoutMs: 800,
|
|
19
|
-
transcriptTimeoutMs: 180000,
|
|
20
|
-
ringTimeoutMs: 30000,
|
|
21
|
-
maxConcurrentCalls: 1,
|
|
22
|
-
sessionScope: "per-phone",
|
|
23
|
-
serve: { port: 3334, bind: "127.0.0.1", path: "/voice/webhook" },
|
|
24
|
-
tailscale: { mode: "off", path: "/voice/webhook" },
|
|
25
|
-
tunnel: {
|
|
26
|
-
provider: params?.tunnelProvider ?? "none",
|
|
27
|
-
allowNgrokFreeTierLoopbackBypass: false,
|
|
28
|
-
},
|
|
29
|
-
webhookSecurity: {
|
|
30
|
-
allowedHosts: [],
|
|
31
|
-
trustForwardingHeaders: false,
|
|
32
|
-
trustedProxyIPs: [],
|
|
33
|
-
},
|
|
34
|
-
streaming: {
|
|
35
|
-
enabled: false,
|
|
36
|
-
providers: {
|
|
37
|
-
openai: {
|
|
38
|
-
model: "gpt-4o-transcribe",
|
|
39
|
-
silenceDurationMs: 800,
|
|
40
|
-
vadThreshold: 0.5,
|
|
41
|
-
},
|
|
42
|
-
},
|
|
43
|
-
streamPath: "/voice/stream",
|
|
44
|
-
preStartTimeoutMs: 5000,
|
|
45
|
-
maxPendingConnections: 32,
|
|
46
|
-
maxPendingConnectionsPerIp: 4,
|
|
47
|
-
maxConnections: 128,
|
|
48
|
-
},
|
|
49
|
-
realtime: {
|
|
50
|
-
enabled: false,
|
|
51
|
-
streamPath: "/voice/stream/realtime",
|
|
52
|
-
instructions: DEFAULT_VOICE_CALL_REALTIME_INSTRUCTIONS,
|
|
53
|
-
toolPolicy: "safe-read-only",
|
|
54
|
-
tools: [],
|
|
55
|
-
fastContext: {
|
|
56
|
-
enabled: false,
|
|
57
|
-
timeoutMs: 800,
|
|
58
|
-
maxResults: 3,
|
|
59
|
-
sources: ["memory", "sessions"],
|
|
60
|
-
fallbackToConsult: false,
|
|
61
|
-
},
|
|
62
|
-
providers: {},
|
|
63
|
-
},
|
|
64
|
-
skipSignatureVerification: false,
|
|
65
|
-
tts: {
|
|
66
|
-
provider: "openai",
|
|
67
|
-
providers: {
|
|
68
|
-
openai: { model: "gpt-4o-mini-tts", voice: "coral" },
|
|
69
|
-
},
|
|
70
|
-
},
|
|
71
|
-
responseTimeoutMs: 30000,
|
|
72
|
-
};
|
|
73
|
-
}
|
|
@@ -1,34 +0,0 @@
|
|
|
1
|
-
import { describe, expect, it } from "vitest";
|
|
2
|
-
import { resolvePreferredTtsVoice } from "./tts-provider-voice.js";
|
|
3
|
-
|
|
4
|
-
describe("resolvePreferredTtsVoice", () => {
|
|
5
|
-
it("returns provider voice when present", () => {
|
|
6
|
-
expect(
|
|
7
|
-
resolvePreferredTtsVoice({
|
|
8
|
-
tts: {
|
|
9
|
-
provider: "openai",
|
|
10
|
-
providers: {
|
|
11
|
-
openai: {
|
|
12
|
-
voice: "coral",
|
|
13
|
-
},
|
|
14
|
-
},
|
|
15
|
-
},
|
|
16
|
-
}),
|
|
17
|
-
).toBe("coral");
|
|
18
|
-
});
|
|
19
|
-
|
|
20
|
-
it("falls back to voiceId for providers that use that field", () => {
|
|
21
|
-
expect(
|
|
22
|
-
resolvePreferredTtsVoice({
|
|
23
|
-
tts: {
|
|
24
|
-
provider: "elevenlabs",
|
|
25
|
-
providers: {
|
|
26
|
-
elevenlabs: {
|
|
27
|
-
voiceId: "voice-123",
|
|
28
|
-
},
|
|
29
|
-
},
|
|
30
|
-
},
|
|
31
|
-
}),
|
|
32
|
-
).toBe("voice-123");
|
|
33
|
-
});
|
|
34
|
-
});
|
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
import { normalizeOptionalString } from "openclaw/plugin-sdk/text-runtime";
|
|
2
|
-
import type { VoiceCallTtsConfig } from "./config.js";
|
|
3
|
-
|
|
4
|
-
function resolveProviderVoiceSetting(providerConfig: unknown): string | undefined {
|
|
5
|
-
if (!providerConfig || typeof providerConfig !== "object") {
|
|
6
|
-
return undefined;
|
|
7
|
-
}
|
|
8
|
-
const candidate = providerConfig as {
|
|
9
|
-
voice?: unknown;
|
|
10
|
-
voiceId?: unknown;
|
|
11
|
-
};
|
|
12
|
-
return normalizeOptionalString(candidate.voice) ?? normalizeOptionalString(candidate.voiceId);
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export function resolvePreferredTtsVoice(config: { tts?: VoiceCallTtsConfig }): string | undefined {
|
|
16
|
-
const providerId = config.tts?.provider;
|
|
17
|
-
if (!providerId) {
|
|
18
|
-
return undefined;
|
|
19
|
-
}
|
|
20
|
-
return resolveProviderVoiceSetting(config.tts?.providers?.[providerId]);
|
|
21
|
-
}
|