@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
package/src/runtime.test.ts
DELETED
|
@@ -1,536 +0,0 @@
|
|
|
1
|
-
import type { OpenClawConfig } from "openclaw/plugin-sdk/core";
|
|
2
|
-
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
3
|
-
import type { VoiceCallConfig } from "./config.js";
|
|
4
|
-
import type { CoreConfig } from "./core-bridge.js";
|
|
5
|
-
import { createVoiceCallBaseConfig } from "./test-fixtures.js";
|
|
6
|
-
|
|
7
|
-
const mocks = vi.hoisted(() => ({
|
|
8
|
-
resolveVoiceCallConfig: vi.fn(),
|
|
9
|
-
resolveTwilioAuthToken: vi.fn(),
|
|
10
|
-
validateProviderConfig: vi.fn(),
|
|
11
|
-
managerInitialize: vi.fn(),
|
|
12
|
-
managerGetCall: vi.fn(),
|
|
13
|
-
webhookStart: vi.fn(),
|
|
14
|
-
webhookStop: vi.fn(),
|
|
15
|
-
webhookSetRealtimeHandler: vi.fn(),
|
|
16
|
-
webhookGetRealtimeHandler: vi.fn(),
|
|
17
|
-
webhookGetMediaStreamHandler: vi.fn(),
|
|
18
|
-
webhookCtorArgs: [] as unknown[][],
|
|
19
|
-
realtimeHandlerCtorArgs: [] as unknown[][],
|
|
20
|
-
realtimeHandlerRegisterToolHandler: vi.fn(),
|
|
21
|
-
realtimeHandlerSetPublicUrl: vi.fn(),
|
|
22
|
-
resolveConfiguredRealtimeVoiceProvider: vi.fn(),
|
|
23
|
-
getActiveMemorySearchManager: vi.fn(),
|
|
24
|
-
memorySearch: vi.fn(),
|
|
25
|
-
startTunnel: vi.fn(),
|
|
26
|
-
setupTailscaleExposure: vi.fn(),
|
|
27
|
-
cleanupTailscaleExposure: vi.fn(),
|
|
28
|
-
}));
|
|
29
|
-
|
|
30
|
-
vi.mock("./config.js", () => ({
|
|
31
|
-
resolveVoiceCallSessionKey: (params: {
|
|
32
|
-
config: Pick<VoiceCallConfig, "sessionScope">;
|
|
33
|
-
callId: string;
|
|
34
|
-
phone?: string;
|
|
35
|
-
explicitSessionKey?: string;
|
|
36
|
-
}) => {
|
|
37
|
-
const explicit = params.explicitSessionKey?.trim();
|
|
38
|
-
if (explicit) {
|
|
39
|
-
return explicit;
|
|
40
|
-
}
|
|
41
|
-
if (params.config.sessionScope === "per-call") {
|
|
42
|
-
return `voice:call:${params.callId}`;
|
|
43
|
-
}
|
|
44
|
-
const normalizedPhone = params.phone?.replace(/\D/g, "");
|
|
45
|
-
return normalizedPhone ? `voice:${normalizedPhone}` : `voice:${params.callId}`;
|
|
46
|
-
},
|
|
47
|
-
resolveVoiceCallEffectiveConfig: (config: VoiceCallConfig) => ({ config }),
|
|
48
|
-
resolveVoiceCallConfig: mocks.resolveVoiceCallConfig,
|
|
49
|
-
resolveTwilioAuthToken: mocks.resolveTwilioAuthToken,
|
|
50
|
-
validateProviderConfig: mocks.validateProviderConfig,
|
|
51
|
-
}));
|
|
52
|
-
|
|
53
|
-
vi.mock("./manager.js", () => ({
|
|
54
|
-
CallManager: class {
|
|
55
|
-
initialize = mocks.managerInitialize;
|
|
56
|
-
getCall = mocks.managerGetCall;
|
|
57
|
-
},
|
|
58
|
-
}));
|
|
59
|
-
|
|
60
|
-
vi.mock("./webhook.js", () => ({
|
|
61
|
-
VoiceCallWebhookServer: class {
|
|
62
|
-
constructor(...args: unknown[]) {
|
|
63
|
-
mocks.webhookCtorArgs.push(args);
|
|
64
|
-
}
|
|
65
|
-
start = mocks.webhookStart;
|
|
66
|
-
stop = mocks.webhookStop;
|
|
67
|
-
setRealtimeHandler = mocks.webhookSetRealtimeHandler;
|
|
68
|
-
getRealtimeHandler = mocks.webhookGetRealtimeHandler;
|
|
69
|
-
getMediaStreamHandler = mocks.webhookGetMediaStreamHandler;
|
|
70
|
-
},
|
|
71
|
-
}));
|
|
72
|
-
|
|
73
|
-
vi.mock("./realtime-voice.runtime.js", () => ({
|
|
74
|
-
resolveConfiguredRealtimeVoiceProvider: mocks.resolveConfiguredRealtimeVoiceProvider,
|
|
75
|
-
}));
|
|
76
|
-
|
|
77
|
-
vi.mock("./webhook/realtime-handler.js", () => ({
|
|
78
|
-
RealtimeCallHandler: class {
|
|
79
|
-
constructor(...args: unknown[]) {
|
|
80
|
-
mocks.realtimeHandlerCtorArgs.push(args);
|
|
81
|
-
}
|
|
82
|
-
registerToolHandler = mocks.realtimeHandlerRegisterToolHandler;
|
|
83
|
-
setPublicUrl = mocks.realtimeHandlerSetPublicUrl;
|
|
84
|
-
},
|
|
85
|
-
}));
|
|
86
|
-
|
|
87
|
-
vi.mock("openclaw/plugin-sdk/memory-host-search", () => ({
|
|
88
|
-
getActiveMemorySearchManager: mocks.getActiveMemorySearchManager,
|
|
89
|
-
}));
|
|
90
|
-
|
|
91
|
-
vi.mock("./tunnel.js", () => ({
|
|
92
|
-
startTunnel: mocks.startTunnel,
|
|
93
|
-
}));
|
|
94
|
-
|
|
95
|
-
vi.mock("./webhook/tailscale.js", () => ({
|
|
96
|
-
setupTailscaleExposure: mocks.setupTailscaleExposure,
|
|
97
|
-
cleanupTailscaleExposure: mocks.cleanupTailscaleExposure,
|
|
98
|
-
}));
|
|
99
|
-
|
|
100
|
-
import { createVoiceCallRuntime } from "./runtime.js";
|
|
101
|
-
|
|
102
|
-
function createBaseConfig(): VoiceCallConfig {
|
|
103
|
-
return createVoiceCallBaseConfig({ tunnelProvider: "ngrok" });
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function createExternalProviderConfig(params: {
|
|
107
|
-
provider: "twilio" | "telnyx" | "plivo";
|
|
108
|
-
publicUrl?: string;
|
|
109
|
-
}): VoiceCallConfig {
|
|
110
|
-
const config = createVoiceCallBaseConfig({
|
|
111
|
-
provider: params.provider,
|
|
112
|
-
tunnelProvider: "none",
|
|
113
|
-
});
|
|
114
|
-
config.twilio = {
|
|
115
|
-
accountSid: "AC123",
|
|
116
|
-
authToken: "secret",
|
|
117
|
-
};
|
|
118
|
-
config.telnyx = {
|
|
119
|
-
apiKey: "key",
|
|
120
|
-
connectionId: "conn",
|
|
121
|
-
publicKey: "pub",
|
|
122
|
-
};
|
|
123
|
-
config.plivo = {
|
|
124
|
-
authId: "MA123",
|
|
125
|
-
authToken: "secret",
|
|
126
|
-
};
|
|
127
|
-
if (params.publicUrl) {
|
|
128
|
-
config.publicUrl = params.publicUrl;
|
|
129
|
-
}
|
|
130
|
-
return config;
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
describe("createVoiceCallRuntime lifecycle", () => {
|
|
134
|
-
beforeEach(() => {
|
|
135
|
-
vi.clearAllMocks();
|
|
136
|
-
mocks.resolveVoiceCallConfig.mockImplementation((cfg: VoiceCallConfig) => cfg);
|
|
137
|
-
mocks.resolveTwilioAuthToken.mockImplementation(
|
|
138
|
-
(cfg: VoiceCallConfig) => cfg.twilio?.authToken,
|
|
139
|
-
);
|
|
140
|
-
mocks.validateProviderConfig.mockReturnValue({ valid: true, errors: [] });
|
|
141
|
-
mocks.managerInitialize.mockResolvedValue(undefined);
|
|
142
|
-
mocks.managerGetCall.mockReset();
|
|
143
|
-
mocks.webhookStart.mockResolvedValue("http://127.0.0.1:3334/voice/webhook");
|
|
144
|
-
mocks.webhookStop.mockResolvedValue(undefined);
|
|
145
|
-
mocks.webhookSetRealtimeHandler.mockReset();
|
|
146
|
-
mocks.webhookGetRealtimeHandler.mockReturnValue({
|
|
147
|
-
setPublicUrl: mocks.realtimeHandlerSetPublicUrl,
|
|
148
|
-
});
|
|
149
|
-
mocks.webhookGetMediaStreamHandler.mockReturnValue(undefined);
|
|
150
|
-
mocks.webhookCtorArgs.length = 0;
|
|
151
|
-
mocks.realtimeHandlerCtorArgs.length = 0;
|
|
152
|
-
mocks.realtimeHandlerRegisterToolHandler.mockReset();
|
|
153
|
-
mocks.realtimeHandlerSetPublicUrl.mockReset();
|
|
154
|
-
mocks.resolveConfiguredRealtimeVoiceProvider.mockResolvedValue({
|
|
155
|
-
provider: { id: "openai" },
|
|
156
|
-
providerConfig: { model: "gpt-realtime" },
|
|
157
|
-
});
|
|
158
|
-
mocks.getActiveMemorySearchManager.mockReset();
|
|
159
|
-
mocks.memorySearch.mockReset();
|
|
160
|
-
mocks.getActiveMemorySearchManager.mockResolvedValue({
|
|
161
|
-
manager: {
|
|
162
|
-
search: mocks.memorySearch,
|
|
163
|
-
},
|
|
164
|
-
});
|
|
165
|
-
mocks.memorySearch.mockResolvedValue([]);
|
|
166
|
-
mocks.startTunnel.mockResolvedValue(null);
|
|
167
|
-
mocks.setupTailscaleExposure.mockResolvedValue(null);
|
|
168
|
-
mocks.cleanupTailscaleExposure.mockResolvedValue(undefined);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it("cleans up tunnel, tailscale, and webhook server when init fails after start", async () => {
|
|
172
|
-
const tunnelStop = vi.fn().mockResolvedValue(undefined);
|
|
173
|
-
mocks.startTunnel.mockResolvedValue({
|
|
174
|
-
publicUrl: "https://public.example/voice/webhook",
|
|
175
|
-
provider: "ngrok",
|
|
176
|
-
stop: tunnelStop,
|
|
177
|
-
});
|
|
178
|
-
mocks.managerInitialize.mockRejectedValue(new Error("init failed"));
|
|
179
|
-
|
|
180
|
-
await expect(
|
|
181
|
-
createVoiceCallRuntime({
|
|
182
|
-
config: createBaseConfig(),
|
|
183
|
-
coreConfig: {},
|
|
184
|
-
agentRuntime: {} as never,
|
|
185
|
-
}),
|
|
186
|
-
).rejects.toThrow("init failed");
|
|
187
|
-
|
|
188
|
-
expect(tunnelStop).toHaveBeenCalledTimes(1);
|
|
189
|
-
expect(mocks.cleanupTailscaleExposure).toHaveBeenCalledTimes(1);
|
|
190
|
-
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
191
|
-
});
|
|
192
|
-
|
|
193
|
-
it("returns an idempotent stop handler", async () => {
|
|
194
|
-
const tunnelStop = vi.fn().mockResolvedValue(undefined);
|
|
195
|
-
mocks.startTunnel.mockResolvedValue({
|
|
196
|
-
publicUrl: "https://public.example/voice/webhook",
|
|
197
|
-
provider: "ngrok",
|
|
198
|
-
stop: tunnelStop,
|
|
199
|
-
});
|
|
200
|
-
|
|
201
|
-
const runtime = await createVoiceCallRuntime({
|
|
202
|
-
config: createBaseConfig(),
|
|
203
|
-
coreConfig: {} as CoreConfig,
|
|
204
|
-
agentRuntime: {} as never,
|
|
205
|
-
});
|
|
206
|
-
|
|
207
|
-
await runtime.stop();
|
|
208
|
-
await runtime.stop();
|
|
209
|
-
|
|
210
|
-
expect(tunnelStop).toHaveBeenCalledTimes(1);
|
|
211
|
-
expect(mocks.cleanupTailscaleExposure).toHaveBeenCalledTimes(1);
|
|
212
|
-
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
213
|
-
});
|
|
214
|
-
|
|
215
|
-
it("passes fullConfig to the webhook server for streaming provider resolution", async () => {
|
|
216
|
-
const coreConfig = { messages: { tts: { provider: "openai" } } } as CoreConfig;
|
|
217
|
-
const fullConfig = {
|
|
218
|
-
plugins: {
|
|
219
|
-
entries: {
|
|
220
|
-
openai: { enabled: true },
|
|
221
|
-
},
|
|
222
|
-
},
|
|
223
|
-
} as OpenClawConfig;
|
|
224
|
-
|
|
225
|
-
await createVoiceCallRuntime({
|
|
226
|
-
config: createBaseConfig(),
|
|
227
|
-
coreConfig,
|
|
228
|
-
fullConfig,
|
|
229
|
-
agentRuntime: {} as never,
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
expect(mocks.webhookCtorArgs[0]?.[3]).toBe(coreConfig);
|
|
233
|
-
expect(mocks.webhookCtorArgs[0]?.[4]).toBe(fullConfig);
|
|
234
|
-
});
|
|
235
|
-
|
|
236
|
-
it.each(["twilio", "telnyx", "plivo"] as const)(
|
|
237
|
-
"fails closed when %s falls back to a local-only webhook",
|
|
238
|
-
async (provider) => {
|
|
239
|
-
await expect(
|
|
240
|
-
createVoiceCallRuntime({
|
|
241
|
-
config: createExternalProviderConfig({ provider }),
|
|
242
|
-
coreConfig: {} as CoreConfig,
|
|
243
|
-
agentRuntime: {} as never,
|
|
244
|
-
}),
|
|
245
|
-
).rejects.toThrow(`${provider} requires a publicly reachable webhook URL`);
|
|
246
|
-
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
247
|
-
},
|
|
248
|
-
);
|
|
249
|
-
|
|
250
|
-
it.each([
|
|
251
|
-
"http://127.0.0.1:3334/voice/webhook",
|
|
252
|
-
"http://[::1]:3334/voice/webhook",
|
|
253
|
-
"http://[fd00::1]/voice/webhook",
|
|
254
|
-
])("fails closed when Twilio publicUrl %s points at a local-only webhook", async (publicUrl) => {
|
|
255
|
-
await expect(
|
|
256
|
-
createVoiceCallRuntime({
|
|
257
|
-
config: createExternalProviderConfig({
|
|
258
|
-
provider: "twilio",
|
|
259
|
-
publicUrl,
|
|
260
|
-
}),
|
|
261
|
-
coreConfig: {} as CoreConfig,
|
|
262
|
-
agentRuntime: {} as never,
|
|
263
|
-
}),
|
|
264
|
-
).rejects.toThrow("twilio requires a publicly reachable webhook URL");
|
|
265
|
-
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
266
|
-
});
|
|
267
|
-
|
|
268
|
-
it("accepts an explicit public URL for external voice providers", async () => {
|
|
269
|
-
const runtime = await createVoiceCallRuntime({
|
|
270
|
-
config: createExternalProviderConfig({
|
|
271
|
-
provider: "twilio",
|
|
272
|
-
publicUrl: "https://voice.example.com/voice/webhook",
|
|
273
|
-
}),
|
|
274
|
-
coreConfig: {} as CoreConfig,
|
|
275
|
-
agentRuntime: {} as never,
|
|
276
|
-
});
|
|
277
|
-
|
|
278
|
-
expect(runtime.webhookUrl).toBe("https://voice.example.com/voice/webhook");
|
|
279
|
-
expect(runtime.publicUrl).toBe("https://voice.example.com/voice/webhook");
|
|
280
|
-
|
|
281
|
-
await runtime.stop();
|
|
282
|
-
});
|
|
283
|
-
|
|
284
|
-
it("does not log duplicate webhook and public URLs when they match", async () => {
|
|
285
|
-
const logger = {
|
|
286
|
-
info: vi.fn(),
|
|
287
|
-
warn: vi.fn(),
|
|
288
|
-
error: vi.fn(),
|
|
289
|
-
};
|
|
290
|
-
|
|
291
|
-
const runtime = await createVoiceCallRuntime({
|
|
292
|
-
config: createExternalProviderConfig({
|
|
293
|
-
provider: "twilio",
|
|
294
|
-
publicUrl: "https://voice.example.com/voice/webhook",
|
|
295
|
-
}),
|
|
296
|
-
coreConfig: {} as CoreConfig,
|
|
297
|
-
agentRuntime: {} as never,
|
|
298
|
-
logger,
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
expect(logger.info).toHaveBeenCalledWith(
|
|
302
|
-
"[voice-call] Webhook URL: https://voice.example.com/voice/webhook",
|
|
303
|
-
);
|
|
304
|
-
expect(logger.info).not.toHaveBeenCalledWith(
|
|
305
|
-
"[voice-call] Public URL: https://voice.example.com/voice/webhook",
|
|
306
|
-
);
|
|
307
|
-
|
|
308
|
-
await runtime.stop();
|
|
309
|
-
});
|
|
310
|
-
|
|
311
|
-
it("wires the shared realtime agent consult tool and handler", async () => {
|
|
312
|
-
const config = createBaseConfig();
|
|
313
|
-
config.inboundPolicy = "allowlist";
|
|
314
|
-
config.realtime.enabled = true;
|
|
315
|
-
config.realtime.tools = [
|
|
316
|
-
{
|
|
317
|
-
type: "function",
|
|
318
|
-
name: "custom_tool",
|
|
319
|
-
description: "Custom tool",
|
|
320
|
-
parameters: { type: "object", properties: {} },
|
|
321
|
-
},
|
|
322
|
-
];
|
|
323
|
-
const sessionStore: Record<string, unknown> = {};
|
|
324
|
-
const runEmbeddedPiAgent = vi.fn(async () => ({
|
|
325
|
-
payloads: [{ text: "Use the shipment status." }],
|
|
326
|
-
meta: {},
|
|
327
|
-
}));
|
|
328
|
-
const agentRuntime = {
|
|
329
|
-
defaults: { provider: "openai", model: "gpt-5.4" },
|
|
330
|
-
resolveAgentDir: vi.fn(() => "/tmp/agent"),
|
|
331
|
-
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
|
332
|
-
resolveAgentIdentity: vi.fn(),
|
|
333
|
-
resolveThinkingDefault: vi.fn(() => "high"),
|
|
334
|
-
resolveAgentTimeoutMs: vi.fn(() => 30_000),
|
|
335
|
-
ensureAgentWorkspace: vi.fn(async () => {}),
|
|
336
|
-
session: {
|
|
337
|
-
resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
|
|
338
|
-
loadSessionStore: vi.fn(() => sessionStore),
|
|
339
|
-
saveSessionStore: vi.fn(async () => {}),
|
|
340
|
-
updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
|
|
341
|
-
resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
|
|
342
|
-
},
|
|
343
|
-
runEmbeddedPiAgent,
|
|
344
|
-
};
|
|
345
|
-
mocks.managerGetCall.mockReturnValue({
|
|
346
|
-
callId: "call-1",
|
|
347
|
-
direction: "outbound",
|
|
348
|
-
from: "+15550001234",
|
|
349
|
-
to: "+15550009999",
|
|
350
|
-
transcript: [{ speaker: "user", text: "Can you check shipment status?" }],
|
|
351
|
-
});
|
|
352
|
-
|
|
353
|
-
await createVoiceCallRuntime({
|
|
354
|
-
config,
|
|
355
|
-
coreConfig: {} as CoreConfig,
|
|
356
|
-
agentRuntime: agentRuntime as never,
|
|
357
|
-
});
|
|
358
|
-
|
|
359
|
-
expect(mocks.realtimeHandlerCtorArgs[0]?.[0]).toMatchObject({
|
|
360
|
-
tools: [
|
|
361
|
-
expect.objectContaining({ name: "openclaw_agent_consult" }),
|
|
362
|
-
expect.objectContaining({ name: "custom_tool" }),
|
|
363
|
-
],
|
|
364
|
-
});
|
|
365
|
-
expect(mocks.realtimeHandlerRegisterToolHandler).toHaveBeenCalledWith(
|
|
366
|
-
"openclaw_agent_consult",
|
|
367
|
-
expect.any(Function),
|
|
368
|
-
);
|
|
369
|
-
|
|
370
|
-
const handler = mocks.realtimeHandlerRegisterToolHandler.mock.calls[0]?.[1] as
|
|
371
|
-
| ((
|
|
372
|
-
args: unknown,
|
|
373
|
-
callId: string,
|
|
374
|
-
context?: { partialUserTranscript?: string },
|
|
375
|
-
) => Promise<unknown>)
|
|
376
|
-
| undefined;
|
|
377
|
-
await expect(
|
|
378
|
-
handler?.({ question: "What should I say?" }, "call-1", {
|
|
379
|
-
partialUserTranscript: "Also check the ETA.",
|
|
380
|
-
}),
|
|
381
|
-
).resolves.toEqual({
|
|
382
|
-
text: "Use the shipment status.",
|
|
383
|
-
});
|
|
384
|
-
expect(runEmbeddedPiAgent).toHaveBeenCalledWith(
|
|
385
|
-
expect.objectContaining({
|
|
386
|
-
sessionKey: "voice:15550009999",
|
|
387
|
-
messageProvider: "voice",
|
|
388
|
-
lane: "voice",
|
|
389
|
-
provider: "openai",
|
|
390
|
-
model: "gpt-5.4",
|
|
391
|
-
toolsAllow: ["read", "web_search", "web_fetch", "x_search", "memory_search", "memory_get"],
|
|
392
|
-
extraSystemPrompt: expect.stringContaining("one or two bounded read-only queries"),
|
|
393
|
-
prompt: expect.stringContaining("Caller: Can you check shipment status?"),
|
|
394
|
-
}),
|
|
395
|
-
);
|
|
396
|
-
expect(runEmbeddedPiAgent).toHaveBeenCalledWith(
|
|
397
|
-
expect.objectContaining({
|
|
398
|
-
prompt: expect.stringContaining("Caller: Also check the ETA."),
|
|
399
|
-
}),
|
|
400
|
-
);
|
|
401
|
-
});
|
|
402
|
-
|
|
403
|
-
it("uses persisted per-call session keys for realtime consults", async () => {
|
|
404
|
-
const config = createBaseConfig();
|
|
405
|
-
config.inboundPolicy = "allowlist";
|
|
406
|
-
config.realtime.enabled = true;
|
|
407
|
-
config.sessionScope = "per-call";
|
|
408
|
-
const runEmbeddedPiAgent = vi.fn(async () => ({
|
|
409
|
-
payloads: [{ text: "Per-call consult answer." }],
|
|
410
|
-
meta: {},
|
|
411
|
-
}));
|
|
412
|
-
const sessionStore: Record<string, unknown> = {};
|
|
413
|
-
const agentRuntime = {
|
|
414
|
-
defaults: { provider: "openai", model: "gpt-5.4" },
|
|
415
|
-
resolveAgentDir: vi.fn(() => "/tmp/agent"),
|
|
416
|
-
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
|
417
|
-
resolveAgentIdentity: vi.fn(),
|
|
418
|
-
resolveThinkingDefault: vi.fn(() => "high"),
|
|
419
|
-
resolveAgentTimeoutMs: vi.fn(() => 30_000),
|
|
420
|
-
ensureAgentWorkspace: vi.fn(async () => {}),
|
|
421
|
-
session: {
|
|
422
|
-
resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
|
|
423
|
-
loadSessionStore: vi.fn(() => sessionStore),
|
|
424
|
-
saveSessionStore: vi.fn(async () => {}),
|
|
425
|
-
updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
|
|
426
|
-
resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
|
|
427
|
-
},
|
|
428
|
-
runEmbeddedPiAgent,
|
|
429
|
-
};
|
|
430
|
-
mocks.managerGetCall.mockReturnValue({
|
|
431
|
-
callId: "call-1",
|
|
432
|
-
sessionKey: "voice:call:call-1",
|
|
433
|
-
direction: "inbound",
|
|
434
|
-
from: "+15550001234",
|
|
435
|
-
to: "+15550009999",
|
|
436
|
-
transcript: [],
|
|
437
|
-
});
|
|
438
|
-
|
|
439
|
-
await createVoiceCallRuntime({
|
|
440
|
-
config,
|
|
441
|
-
coreConfig: {} as CoreConfig,
|
|
442
|
-
agentRuntime: agentRuntime as never,
|
|
443
|
-
});
|
|
444
|
-
|
|
445
|
-
const handler = mocks.realtimeHandlerRegisterToolHandler.mock.calls[0]?.[1] as
|
|
446
|
-
| ((
|
|
447
|
-
args: unknown,
|
|
448
|
-
callId: string,
|
|
449
|
-
context?: { partialUserTranscript?: string },
|
|
450
|
-
) => Promise<unknown>)
|
|
451
|
-
| undefined;
|
|
452
|
-
await expect(handler?.({ question: "What should I say?" }, "call-1")).resolves.toEqual({
|
|
453
|
-
text: "Per-call consult answer.",
|
|
454
|
-
});
|
|
455
|
-
expect(runEmbeddedPiAgent).toHaveBeenCalledWith(
|
|
456
|
-
expect.objectContaining({
|
|
457
|
-
sessionKey: "voice:call:call-1",
|
|
458
|
-
}),
|
|
459
|
-
);
|
|
460
|
-
});
|
|
461
|
-
|
|
462
|
-
it("answers realtime consults from fast memory context before starting the full agent", async () => {
|
|
463
|
-
const config = createBaseConfig();
|
|
464
|
-
config.realtime.enabled = true;
|
|
465
|
-
config.realtime.fastContext = {
|
|
466
|
-
enabled: true,
|
|
467
|
-
timeoutMs: 800,
|
|
468
|
-
maxResults: 2,
|
|
469
|
-
sources: ["memory"],
|
|
470
|
-
fallbackToConsult: false,
|
|
471
|
-
};
|
|
472
|
-
const runEmbeddedPiAgent = vi.fn(async () => ({
|
|
473
|
-
payloads: [{ text: "slow answer" }],
|
|
474
|
-
meta: {},
|
|
475
|
-
}));
|
|
476
|
-
const sessionStore: Record<string, unknown> = {};
|
|
477
|
-
const agentRuntime = {
|
|
478
|
-
resolveAgentDir: vi.fn(() => "/tmp/agent"),
|
|
479
|
-
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
|
480
|
-
resolveAgentIdentity: vi.fn(),
|
|
481
|
-
resolveThinkingDefault: vi.fn(() => "high"),
|
|
482
|
-
resolveAgentTimeoutMs: vi.fn(() => 30_000),
|
|
483
|
-
ensureAgentWorkspace: vi.fn(async () => {}),
|
|
484
|
-
session: {
|
|
485
|
-
resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
|
|
486
|
-
loadSessionStore: vi.fn(() => sessionStore),
|
|
487
|
-
saveSessionStore: vi.fn(async () => {}),
|
|
488
|
-
updateSessionStore: vi.fn(async (_storePath, mutator) => mutator(sessionStore as never)),
|
|
489
|
-
resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
|
|
490
|
-
},
|
|
491
|
-
runEmbeddedPiAgent,
|
|
492
|
-
};
|
|
493
|
-
mocks.managerGetCall.mockReturnValue({
|
|
494
|
-
callId: "call-1",
|
|
495
|
-
direction: "inbound",
|
|
496
|
-
from: "+15550001234",
|
|
497
|
-
to: "+15550009999",
|
|
498
|
-
transcript: [],
|
|
499
|
-
});
|
|
500
|
-
mocks.memorySearch.mockResolvedValue([
|
|
501
|
-
{
|
|
502
|
-
source: "memory",
|
|
503
|
-
path: "MEMORY.md",
|
|
504
|
-
startLine: 12,
|
|
505
|
-
endLine: 14,
|
|
506
|
-
score: 0.91,
|
|
507
|
-
snippet: "The caller's basement lights are on.",
|
|
508
|
-
},
|
|
509
|
-
]);
|
|
510
|
-
|
|
511
|
-
await createVoiceCallRuntime({
|
|
512
|
-
config,
|
|
513
|
-
coreConfig: {} as CoreConfig,
|
|
514
|
-
agentRuntime: agentRuntime as never,
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
const handler = mocks.realtimeHandlerRegisterToolHandler.mock.calls[0]?.[1] as
|
|
518
|
-
| ((
|
|
519
|
-
args: unknown,
|
|
520
|
-
callId: string,
|
|
521
|
-
context?: { partialUserTranscript?: string },
|
|
522
|
-
) => Promise<unknown>)
|
|
523
|
-
| undefined;
|
|
524
|
-
await expect(handler?.({ question: "Are the basement lights on?" }, "call-1")).resolves.toEqual(
|
|
525
|
-
{
|
|
526
|
-
text: expect.stringContaining("The caller's basement lights are on."),
|
|
527
|
-
},
|
|
528
|
-
);
|
|
529
|
-
expect(mocks.memorySearch).toHaveBeenCalledWith("Are the basement lights on?", {
|
|
530
|
-
maxResults: 2,
|
|
531
|
-
sessionKey: "voice:15550001234",
|
|
532
|
-
sources: ["memory"],
|
|
533
|
-
});
|
|
534
|
-
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
|
535
|
-
});
|
|
536
|
-
});
|