@openclaw/voice-call 2026.3.13 → 2026.5.1-beta.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +25 -5
- package/api.ts +16 -0
- package/cli-metadata.ts +10 -0
- package/config-api.ts +12 -0
- package/index.test.ts +866 -0
- package/index.ts +353 -148
- package/openclaw.plugin.json +336 -157
- package/package.json +33 -5
- package/runtime-api.ts +20 -0
- package/runtime-entry.ts +1 -0
- package/setup-api.ts +47 -0
- package/src/allowlist.test.ts +18 -0
- package/src/cli.ts +533 -68
- package/src/config-compat.test.ts +120 -0
- package/src/config-compat.ts +227 -0
- package/src/config.test.ts +160 -12
- package/src/config.ts +243 -74
- package/src/core-bridge.ts +2 -147
- package/src/deep-merge.test.ts +40 -0
- package/src/gateway-continue-operation.ts +200 -0
- package/src/http-headers.ts +6 -3
- package/src/manager/context.ts +6 -5
- package/src/manager/events.test.ts +179 -19
- package/src/manager/events.ts +48 -30
- package/src/manager/lifecycle.ts +53 -0
- package/src/manager/lookup.test.ts +52 -0
- package/src/manager/outbound.test.ts +464 -0
- package/src/manager/outbound.ts +148 -55
- package/src/manager/store.ts +18 -6
- package/src/manager/timers.test.ts +129 -0
- package/src/manager/timers.ts +4 -3
- package/src/manager/twiml.test.ts +13 -0
- package/src/manager/twiml.ts +8 -0
- package/src/manager.closed-loop.test.ts +30 -12
- package/src/manager.inbound-allowlist.test.ts +77 -10
- package/src/manager.notify.test.ts +344 -20
- package/src/manager.restore.test.ts +95 -8
- package/src/manager.test-harness.ts +8 -6
- package/src/manager.ts +79 -5
- package/src/media-stream.test.ts +578 -81
- package/src/media-stream.ts +235 -54
- package/src/providers/base.ts +19 -0
- package/src/providers/mock.ts +7 -1
- package/src/providers/plivo.test.ts +50 -6
- package/src/providers/plivo.ts +14 -6
- package/src/providers/shared/call-status.ts +2 -1
- package/src/providers/shared/guarded-json-api.test.ts +106 -0
- package/src/providers/shared/guarded-json-api.ts +1 -1
- package/src/providers/telnyx.test.ts +178 -6
- package/src/providers/telnyx.ts +40 -3
- package/src/providers/twilio/api.test.ts +145 -0
- package/src/providers/twilio/api.ts +67 -16
- package/src/providers/twilio/twiml-policy.ts +6 -10
- package/src/providers/twilio/webhook.ts +1 -1
- package/src/providers/twilio.test.ts +425 -25
- package/src/providers/twilio.ts +230 -77
- package/src/providers/twilio.types.ts +17 -0
- package/src/realtime-defaults.ts +3 -0
- package/src/realtime-fast-context.test.ts +88 -0
- package/src/realtime-fast-context.ts +165 -0
- package/src/realtime-transcription.runtime.ts +4 -0
- package/src/realtime-voice.runtime.ts +5 -0
- package/src/response-generator.test.ts +277 -0
- package/src/response-generator.ts +186 -40
- package/src/response-model.test.ts +71 -0
- package/src/response-model.ts +23 -0
- package/src/runtime.test.ts +351 -0
- package/src/runtime.ts +254 -24
- package/src/telephony-audio.test.ts +61 -0
- package/src/telephony-audio.ts +1 -79
- package/src/telephony-tts.test.ts +133 -12
- package/src/telephony-tts.ts +155 -2
- package/src/test-fixtures.ts +26 -7
- package/src/tts-provider-voice.test.ts +34 -0
- package/src/tts-provider-voice.ts +21 -0
- package/src/tunnel.test.ts +166 -0
- package/src/tunnel.ts +1 -1
- package/src/types.ts +24 -37
- package/src/utils.test.ts +17 -0
- package/src/voice-mapping.test.ts +34 -0
- package/src/voice-mapping.ts +3 -2
- package/src/webhook/realtime-handler.test.ts +598 -0
- package/src/webhook/realtime-handler.ts +485 -0
- package/src/webhook/stale-call-reaper.test.ts +88 -0
- package/src/webhook/stale-call-reaper.ts +5 -0
- package/src/webhook/tailscale.test.ts +214 -0
- package/src/webhook/tailscale.ts +19 -5
- package/src/webhook-exposure.test.ts +33 -0
- package/src/webhook-exposure.ts +84 -0
- package/src/webhook-security.test.ts +172 -21
- package/src/webhook-security.ts +43 -29
- package/src/webhook.hangup-once.lifecycle.test.ts +135 -0
- package/src/webhook.test.ts +1145 -27
- package/src/webhook.ts +513 -100
- package/src/webhook.types.ts +5 -0
- package/src/websocket-test-support.ts +72 -0
- package/tsconfig.json +16 -0
- package/CHANGELOG.md +0 -121
- package/src/providers/index.ts +0 -10
- package/src/providers/stt-openai-realtime.test.ts +0 -42
- package/src/providers/stt-openai-realtime.ts +0 -311
- package/src/providers/tts-openai.test.ts +0 -43
- package/src/providers/tts-openai.ts +0 -221
package/src/runtime.test.ts
CHANGED
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import type { OpenClawConfig } from "openclaw/plugin-sdk/core";
|
|
1
2
|
import { beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
3
|
import type { VoiceCallConfig } from "./config.js";
|
|
3
4
|
import type { CoreConfig } from "./core-bridge.js";
|
|
@@ -5,11 +6,22 @@ import { createVoiceCallBaseConfig } from "./test-fixtures.js";
|
|
|
5
6
|
|
|
6
7
|
const mocks = vi.hoisted(() => ({
|
|
7
8
|
resolveVoiceCallConfig: vi.fn(),
|
|
9
|
+
resolveTwilioAuthToken: vi.fn(),
|
|
8
10
|
validateProviderConfig: vi.fn(),
|
|
9
11
|
managerInitialize: vi.fn(),
|
|
12
|
+
managerGetCall: vi.fn(),
|
|
10
13
|
webhookStart: vi.fn(),
|
|
11
14
|
webhookStop: vi.fn(),
|
|
15
|
+
webhookSetRealtimeHandler: vi.fn(),
|
|
16
|
+
webhookGetRealtimeHandler: vi.fn(),
|
|
12
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(),
|
|
13
25
|
startTunnel: vi.fn(),
|
|
14
26
|
setupTailscaleExposure: vi.fn(),
|
|
15
27
|
cleanupTailscaleExposure: vi.fn(),
|
|
@@ -17,23 +29,48 @@ const mocks = vi.hoisted(() => ({
|
|
|
17
29
|
|
|
18
30
|
vi.mock("./config.js", () => ({
|
|
19
31
|
resolveVoiceCallConfig: mocks.resolveVoiceCallConfig,
|
|
32
|
+
resolveTwilioAuthToken: mocks.resolveTwilioAuthToken,
|
|
20
33
|
validateProviderConfig: mocks.validateProviderConfig,
|
|
21
34
|
}));
|
|
22
35
|
|
|
23
36
|
vi.mock("./manager.js", () => ({
|
|
24
37
|
CallManager: class {
|
|
25
38
|
initialize = mocks.managerInitialize;
|
|
39
|
+
getCall = mocks.managerGetCall;
|
|
26
40
|
},
|
|
27
41
|
}));
|
|
28
42
|
|
|
29
43
|
vi.mock("./webhook.js", () => ({
|
|
30
44
|
VoiceCallWebhookServer: class {
|
|
45
|
+
constructor(...args: unknown[]) {
|
|
46
|
+
mocks.webhookCtorArgs.push(args);
|
|
47
|
+
}
|
|
31
48
|
start = mocks.webhookStart;
|
|
32
49
|
stop = mocks.webhookStop;
|
|
50
|
+
setRealtimeHandler = mocks.webhookSetRealtimeHandler;
|
|
51
|
+
getRealtimeHandler = mocks.webhookGetRealtimeHandler;
|
|
33
52
|
getMediaStreamHandler = mocks.webhookGetMediaStreamHandler;
|
|
34
53
|
},
|
|
35
54
|
}));
|
|
36
55
|
|
|
56
|
+
vi.mock("./realtime-voice.runtime.js", () => ({
|
|
57
|
+
resolveConfiguredRealtimeVoiceProvider: mocks.resolveConfiguredRealtimeVoiceProvider,
|
|
58
|
+
}));
|
|
59
|
+
|
|
60
|
+
vi.mock("./webhook/realtime-handler.js", () => ({
|
|
61
|
+
RealtimeCallHandler: class {
|
|
62
|
+
constructor(...args: unknown[]) {
|
|
63
|
+
mocks.realtimeHandlerCtorArgs.push(args);
|
|
64
|
+
}
|
|
65
|
+
registerToolHandler = mocks.realtimeHandlerRegisterToolHandler;
|
|
66
|
+
setPublicUrl = mocks.realtimeHandlerSetPublicUrl;
|
|
67
|
+
},
|
|
68
|
+
}));
|
|
69
|
+
|
|
70
|
+
vi.mock("openclaw/plugin-sdk/memory-host-search", () => ({
|
|
71
|
+
getActiveMemorySearchManager: mocks.getActiveMemorySearchManager,
|
|
72
|
+
}));
|
|
73
|
+
|
|
37
74
|
vi.mock("./tunnel.js", () => ({
|
|
38
75
|
startTunnel: mocks.startTunnel,
|
|
39
76
|
}));
|
|
@@ -49,15 +86,66 @@ function createBaseConfig(): VoiceCallConfig {
|
|
|
49
86
|
return createVoiceCallBaseConfig({ tunnelProvider: "ngrok" });
|
|
50
87
|
}
|
|
51
88
|
|
|
89
|
+
function createExternalProviderConfig(params: {
|
|
90
|
+
provider: "twilio" | "telnyx" | "plivo";
|
|
91
|
+
publicUrl?: string;
|
|
92
|
+
}): VoiceCallConfig {
|
|
93
|
+
const config = createVoiceCallBaseConfig({
|
|
94
|
+
provider: params.provider,
|
|
95
|
+
tunnelProvider: "none",
|
|
96
|
+
});
|
|
97
|
+
config.twilio = {
|
|
98
|
+
accountSid: "AC123",
|
|
99
|
+
authToken: "secret",
|
|
100
|
+
};
|
|
101
|
+
config.telnyx = {
|
|
102
|
+
apiKey: "key",
|
|
103
|
+
connectionId: "conn",
|
|
104
|
+
publicKey: "pub",
|
|
105
|
+
};
|
|
106
|
+
config.plivo = {
|
|
107
|
+
authId: "MA123",
|
|
108
|
+
authToken: "secret",
|
|
109
|
+
};
|
|
110
|
+
if (params.publicUrl) {
|
|
111
|
+
config.publicUrl = params.publicUrl;
|
|
112
|
+
}
|
|
113
|
+
return config;
|
|
114
|
+
}
|
|
115
|
+
|
|
52
116
|
describe("createVoiceCallRuntime lifecycle", () => {
|
|
53
117
|
beforeEach(() => {
|
|
54
118
|
vi.clearAllMocks();
|
|
55
119
|
mocks.resolveVoiceCallConfig.mockImplementation((cfg: VoiceCallConfig) => cfg);
|
|
120
|
+
mocks.resolveTwilioAuthToken.mockImplementation(
|
|
121
|
+
(cfg: VoiceCallConfig) => cfg.twilio?.authToken,
|
|
122
|
+
);
|
|
56
123
|
mocks.validateProviderConfig.mockReturnValue({ valid: true, errors: [] });
|
|
57
124
|
mocks.managerInitialize.mockResolvedValue(undefined);
|
|
125
|
+
mocks.managerGetCall.mockReset();
|
|
58
126
|
mocks.webhookStart.mockResolvedValue("http://127.0.0.1:3334/voice/webhook");
|
|
59
127
|
mocks.webhookStop.mockResolvedValue(undefined);
|
|
128
|
+
mocks.webhookSetRealtimeHandler.mockReset();
|
|
129
|
+
mocks.webhookGetRealtimeHandler.mockReturnValue({
|
|
130
|
+
setPublicUrl: mocks.realtimeHandlerSetPublicUrl,
|
|
131
|
+
});
|
|
60
132
|
mocks.webhookGetMediaStreamHandler.mockReturnValue(undefined);
|
|
133
|
+
mocks.webhookCtorArgs.length = 0;
|
|
134
|
+
mocks.realtimeHandlerCtorArgs.length = 0;
|
|
135
|
+
mocks.realtimeHandlerRegisterToolHandler.mockReset();
|
|
136
|
+
mocks.realtimeHandlerSetPublicUrl.mockReset();
|
|
137
|
+
mocks.resolveConfiguredRealtimeVoiceProvider.mockResolvedValue({
|
|
138
|
+
provider: { id: "openai" },
|
|
139
|
+
providerConfig: { model: "gpt-realtime" },
|
|
140
|
+
});
|
|
141
|
+
mocks.getActiveMemorySearchManager.mockReset();
|
|
142
|
+
mocks.memorySearch.mockReset();
|
|
143
|
+
mocks.getActiveMemorySearchManager.mockResolvedValue({
|
|
144
|
+
manager: {
|
|
145
|
+
search: mocks.memorySearch,
|
|
146
|
+
},
|
|
147
|
+
});
|
|
148
|
+
mocks.memorySearch.mockResolvedValue([]);
|
|
61
149
|
mocks.startTunnel.mockResolvedValue(null);
|
|
62
150
|
mocks.setupTailscaleExposure.mockResolvedValue(null);
|
|
63
151
|
mocks.cleanupTailscaleExposure.mockResolvedValue(undefined);
|
|
@@ -76,6 +164,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
|
|
|
76
164
|
createVoiceCallRuntime({
|
|
77
165
|
config: createBaseConfig(),
|
|
78
166
|
coreConfig: {},
|
|
167
|
+
agentRuntime: {} as never,
|
|
79
168
|
}),
|
|
80
169
|
).rejects.toThrow("init failed");
|
|
81
170
|
|
|
@@ -95,6 +184,7 @@ describe("createVoiceCallRuntime lifecycle", () => {
|
|
|
95
184
|
const runtime = await createVoiceCallRuntime({
|
|
96
185
|
config: createBaseConfig(),
|
|
97
186
|
coreConfig: {} as CoreConfig,
|
|
187
|
+
agentRuntime: {} as never,
|
|
98
188
|
});
|
|
99
189
|
|
|
100
190
|
await runtime.stop();
|
|
@@ -104,4 +194,265 @@ describe("createVoiceCallRuntime lifecycle", () => {
|
|
|
104
194
|
expect(mocks.cleanupTailscaleExposure).toHaveBeenCalledTimes(1);
|
|
105
195
|
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
106
196
|
});
|
|
197
|
+
|
|
198
|
+
it("passes fullConfig to the webhook server for streaming provider resolution", async () => {
|
|
199
|
+
const coreConfig = { messages: { tts: { provider: "openai" } } } as CoreConfig;
|
|
200
|
+
const fullConfig = {
|
|
201
|
+
plugins: {
|
|
202
|
+
entries: {
|
|
203
|
+
openai: { enabled: true },
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
} as OpenClawConfig;
|
|
207
|
+
|
|
208
|
+
await createVoiceCallRuntime({
|
|
209
|
+
config: createBaseConfig(),
|
|
210
|
+
coreConfig,
|
|
211
|
+
fullConfig,
|
|
212
|
+
agentRuntime: {} as never,
|
|
213
|
+
});
|
|
214
|
+
|
|
215
|
+
expect(mocks.webhookCtorArgs[0]?.[3]).toBe(coreConfig);
|
|
216
|
+
expect(mocks.webhookCtorArgs[0]?.[4]).toBe(fullConfig);
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
it.each(["twilio", "telnyx", "plivo"] as const)(
|
|
220
|
+
"fails closed when %s falls back to a local-only webhook",
|
|
221
|
+
async (provider) => {
|
|
222
|
+
await expect(
|
|
223
|
+
createVoiceCallRuntime({
|
|
224
|
+
config: createExternalProviderConfig({ provider }),
|
|
225
|
+
coreConfig: {} as CoreConfig,
|
|
226
|
+
agentRuntime: {} as never,
|
|
227
|
+
}),
|
|
228
|
+
).rejects.toThrow(`${provider} requires a publicly reachable webhook URL`);
|
|
229
|
+
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
230
|
+
},
|
|
231
|
+
);
|
|
232
|
+
|
|
233
|
+
it.each([
|
|
234
|
+
"http://127.0.0.1:3334/voice/webhook",
|
|
235
|
+
"http://[::1]:3334/voice/webhook",
|
|
236
|
+
"http://[fd00::1]/voice/webhook",
|
|
237
|
+
])("fails closed when Twilio publicUrl %s points at a local-only webhook", async (publicUrl) => {
|
|
238
|
+
await expect(
|
|
239
|
+
createVoiceCallRuntime({
|
|
240
|
+
config: createExternalProviderConfig({
|
|
241
|
+
provider: "twilio",
|
|
242
|
+
publicUrl,
|
|
243
|
+
}),
|
|
244
|
+
coreConfig: {} as CoreConfig,
|
|
245
|
+
agentRuntime: {} as never,
|
|
246
|
+
}),
|
|
247
|
+
).rejects.toThrow("twilio requires a publicly reachable webhook URL");
|
|
248
|
+
expect(mocks.webhookStop).toHaveBeenCalledTimes(1);
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
it("accepts an explicit public URL for external voice providers", async () => {
|
|
252
|
+
const runtime = await createVoiceCallRuntime({
|
|
253
|
+
config: createExternalProviderConfig({
|
|
254
|
+
provider: "twilio",
|
|
255
|
+
publicUrl: "https://voice.example.com/voice/webhook",
|
|
256
|
+
}),
|
|
257
|
+
coreConfig: {} as CoreConfig,
|
|
258
|
+
agentRuntime: {} as never,
|
|
259
|
+
});
|
|
260
|
+
|
|
261
|
+
expect(runtime.webhookUrl).toBe("https://voice.example.com/voice/webhook");
|
|
262
|
+
expect(runtime.publicUrl).toBe("https://voice.example.com/voice/webhook");
|
|
263
|
+
|
|
264
|
+
await runtime.stop();
|
|
265
|
+
});
|
|
266
|
+
|
|
267
|
+
it("does not log duplicate webhook and public URLs when they match", async () => {
|
|
268
|
+
const logger = {
|
|
269
|
+
info: vi.fn(),
|
|
270
|
+
warn: vi.fn(),
|
|
271
|
+
error: vi.fn(),
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
const runtime = await createVoiceCallRuntime({
|
|
275
|
+
config: createExternalProviderConfig({
|
|
276
|
+
provider: "twilio",
|
|
277
|
+
publicUrl: "https://voice.example.com/voice/webhook",
|
|
278
|
+
}),
|
|
279
|
+
coreConfig: {} as CoreConfig,
|
|
280
|
+
agentRuntime: {} as never,
|
|
281
|
+
logger,
|
|
282
|
+
});
|
|
283
|
+
|
|
284
|
+
expect(logger.info).toHaveBeenCalledWith(
|
|
285
|
+
"[voice-call] Webhook URL: https://voice.example.com/voice/webhook",
|
|
286
|
+
);
|
|
287
|
+
expect(logger.info).not.toHaveBeenCalledWith(
|
|
288
|
+
"[voice-call] Public URL: https://voice.example.com/voice/webhook",
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
await runtime.stop();
|
|
292
|
+
});
|
|
293
|
+
|
|
294
|
+
it("wires the shared realtime agent consult tool and handler", async () => {
|
|
295
|
+
const config = createBaseConfig();
|
|
296
|
+
config.inboundPolicy = "allowlist";
|
|
297
|
+
config.realtime.enabled = true;
|
|
298
|
+
config.realtime.tools = [
|
|
299
|
+
{
|
|
300
|
+
type: "function",
|
|
301
|
+
name: "custom_tool",
|
|
302
|
+
description: "Custom tool",
|
|
303
|
+
parameters: { type: "object", properties: {} },
|
|
304
|
+
},
|
|
305
|
+
];
|
|
306
|
+
const sessionStore: Record<string, unknown> = {};
|
|
307
|
+
const runEmbeddedPiAgent = vi.fn(async () => ({
|
|
308
|
+
payloads: [{ text: "Use the shipment status." }],
|
|
309
|
+
meta: {},
|
|
310
|
+
}));
|
|
311
|
+
const agentRuntime = {
|
|
312
|
+
defaults: { provider: "openai", model: "gpt-5.4" },
|
|
313
|
+
resolveAgentDir: vi.fn(() => "/tmp/agent"),
|
|
314
|
+
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
|
315
|
+
resolveAgentIdentity: vi.fn(),
|
|
316
|
+
resolveThinkingDefault: vi.fn(() => "high"),
|
|
317
|
+
resolveAgentTimeoutMs: vi.fn(() => 30_000),
|
|
318
|
+
ensureAgentWorkspace: vi.fn(async () => {}),
|
|
319
|
+
session: {
|
|
320
|
+
resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
|
|
321
|
+
loadSessionStore: vi.fn(() => sessionStore),
|
|
322
|
+
saveSessionStore: vi.fn(async () => {}),
|
|
323
|
+
resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
|
|
324
|
+
},
|
|
325
|
+
runEmbeddedPiAgent,
|
|
326
|
+
};
|
|
327
|
+
mocks.managerGetCall.mockReturnValue({
|
|
328
|
+
callId: "call-1",
|
|
329
|
+
direction: "outbound",
|
|
330
|
+
from: "+15550001234",
|
|
331
|
+
to: "+15550009999",
|
|
332
|
+
transcript: [{ speaker: "user", text: "Can you check shipment status?" }],
|
|
333
|
+
});
|
|
334
|
+
|
|
335
|
+
await createVoiceCallRuntime({
|
|
336
|
+
config,
|
|
337
|
+
coreConfig: {} as CoreConfig,
|
|
338
|
+
agentRuntime: agentRuntime as never,
|
|
339
|
+
});
|
|
340
|
+
|
|
341
|
+
expect(mocks.realtimeHandlerCtorArgs[0]?.[0]).toMatchObject({
|
|
342
|
+
tools: [
|
|
343
|
+
expect.objectContaining({ name: "openclaw_agent_consult" }),
|
|
344
|
+
expect.objectContaining({ name: "custom_tool" }),
|
|
345
|
+
],
|
|
346
|
+
});
|
|
347
|
+
expect(mocks.realtimeHandlerRegisterToolHandler).toHaveBeenCalledWith(
|
|
348
|
+
"openclaw_agent_consult",
|
|
349
|
+
expect.any(Function),
|
|
350
|
+
);
|
|
351
|
+
|
|
352
|
+
const handler = mocks.realtimeHandlerRegisterToolHandler.mock.calls[0]?.[1] as
|
|
353
|
+
| ((
|
|
354
|
+
args: unknown,
|
|
355
|
+
callId: string,
|
|
356
|
+
context?: { partialUserTranscript?: string },
|
|
357
|
+
) => Promise<unknown>)
|
|
358
|
+
| undefined;
|
|
359
|
+
await expect(
|
|
360
|
+
handler?.({ question: "What should I say?" }, "call-1", {
|
|
361
|
+
partialUserTranscript: "Also check the ETA.",
|
|
362
|
+
}),
|
|
363
|
+
).resolves.toEqual({
|
|
364
|
+
text: "Use the shipment status.",
|
|
365
|
+
});
|
|
366
|
+
expect(runEmbeddedPiAgent).toHaveBeenCalledWith(
|
|
367
|
+
expect.objectContaining({
|
|
368
|
+
sessionKey: "voice:15550009999",
|
|
369
|
+
messageProvider: "voice",
|
|
370
|
+
lane: "voice",
|
|
371
|
+
provider: "openai",
|
|
372
|
+
model: "gpt-5.4",
|
|
373
|
+
toolsAllow: ["read", "web_search", "web_fetch", "x_search", "memory_search", "memory_get"],
|
|
374
|
+
extraSystemPrompt: expect.stringContaining("one or two bounded read-only queries"),
|
|
375
|
+
prompt: expect.stringContaining("Caller: Can you check shipment status?"),
|
|
376
|
+
}),
|
|
377
|
+
);
|
|
378
|
+
expect(runEmbeddedPiAgent).toHaveBeenCalledWith(
|
|
379
|
+
expect.objectContaining({
|
|
380
|
+
prompt: expect.stringContaining("Caller: Also check the ETA."),
|
|
381
|
+
}),
|
|
382
|
+
);
|
|
383
|
+
});
|
|
384
|
+
|
|
385
|
+
it("answers realtime consults from fast memory context before starting the full agent", async () => {
|
|
386
|
+
const config = createBaseConfig();
|
|
387
|
+
config.realtime.enabled = true;
|
|
388
|
+
config.realtime.fastContext = {
|
|
389
|
+
enabled: true,
|
|
390
|
+
timeoutMs: 800,
|
|
391
|
+
maxResults: 2,
|
|
392
|
+
sources: ["memory"],
|
|
393
|
+
fallbackToConsult: false,
|
|
394
|
+
};
|
|
395
|
+
const runEmbeddedPiAgent = vi.fn(async () => ({
|
|
396
|
+
payloads: [{ text: "slow answer" }],
|
|
397
|
+
meta: {},
|
|
398
|
+
}));
|
|
399
|
+
const sessionStore: Record<string, unknown> = {};
|
|
400
|
+
const agentRuntime = {
|
|
401
|
+
resolveAgentDir: vi.fn(() => "/tmp/agent"),
|
|
402
|
+
resolveAgentWorkspaceDir: vi.fn(() => "/tmp/workspace"),
|
|
403
|
+
resolveAgentIdentity: vi.fn(),
|
|
404
|
+
resolveThinkingDefault: vi.fn(() => "high"),
|
|
405
|
+
resolveAgentTimeoutMs: vi.fn(() => 30_000),
|
|
406
|
+
ensureAgentWorkspace: vi.fn(async () => {}),
|
|
407
|
+
session: {
|
|
408
|
+
resolveStorePath: vi.fn(() => "/tmp/sessions.json"),
|
|
409
|
+
loadSessionStore: vi.fn(() => sessionStore),
|
|
410
|
+
saveSessionStore: vi.fn(async () => {}),
|
|
411
|
+
resolveSessionFilePath: vi.fn(() => "/tmp/session.json"),
|
|
412
|
+
},
|
|
413
|
+
runEmbeddedPiAgent,
|
|
414
|
+
};
|
|
415
|
+
mocks.managerGetCall.mockReturnValue({
|
|
416
|
+
callId: "call-1",
|
|
417
|
+
direction: "inbound",
|
|
418
|
+
from: "+15550001234",
|
|
419
|
+
to: "+15550009999",
|
|
420
|
+
transcript: [],
|
|
421
|
+
});
|
|
422
|
+
mocks.memorySearch.mockResolvedValue([
|
|
423
|
+
{
|
|
424
|
+
source: "memory",
|
|
425
|
+
path: "MEMORY.md",
|
|
426
|
+
startLine: 12,
|
|
427
|
+
endLine: 14,
|
|
428
|
+
score: 0.91,
|
|
429
|
+
snippet: "The caller's basement lights are on.",
|
|
430
|
+
},
|
|
431
|
+
]);
|
|
432
|
+
|
|
433
|
+
await createVoiceCallRuntime({
|
|
434
|
+
config,
|
|
435
|
+
coreConfig: {} as CoreConfig,
|
|
436
|
+
agentRuntime: agentRuntime as never,
|
|
437
|
+
});
|
|
438
|
+
|
|
439
|
+
const handler = mocks.realtimeHandlerRegisterToolHandler.mock.calls[0]?.[1] as
|
|
440
|
+
| ((
|
|
441
|
+
args: unknown,
|
|
442
|
+
callId: string,
|
|
443
|
+
context?: { partialUserTranscript?: string },
|
|
444
|
+
) => Promise<unknown>)
|
|
445
|
+
| undefined;
|
|
446
|
+
await expect(handler?.({ question: "Are the basement lights on?" }, "call-1")).resolves.toEqual(
|
|
447
|
+
{
|
|
448
|
+
text: expect.stringContaining("The caller's basement lights are on."),
|
|
449
|
+
},
|
|
450
|
+
);
|
|
451
|
+
expect(mocks.memorySearch).toHaveBeenCalledWith("Are the basement lights on?", {
|
|
452
|
+
maxResults: 2,
|
|
453
|
+
sessionKey: "voice:15550001234",
|
|
454
|
+
sources: ["memory"],
|
|
455
|
+
});
|
|
456
|
+
expect(runEmbeddedPiAgent).not.toHaveBeenCalled();
|
|
457
|
+
});
|
|
107
458
|
});
|