@openclaw/voice-call 2026.8.2 → 2026.9.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/dist/api.js +2 -2
- package/dist/cli-DNq2qUU0.js +630 -0
- package/dist/config-DQwvsxeV.js +697 -0
- package/dist/{guarded-json-api-BL8mhcJj.js → guarded-json-api-9je4i7qf.js} +1 -1
- package/dist/index.js +17 -580
- package/dist/{plivo-CgYWuWVr.js → plivo-BfKoYCMW.js} +2 -2
- package/dist/{realtime-handler-oehCkuE2.js → realtime-handler-BYWqpZ6N.js} +23 -16
- package/dist/{response-generator-BPKgHnuI.js → response-generator-C0577tL-.js} +2 -1
- package/dist/runtime-api.js +2 -2
- package/dist/{runtime-entry-CJkbbEgg.js → runtime-entry-gE2Yd4V8.js} +33 -715
- package/dist/runtime-entry.js +1 -1
- package/dist/{telnyx-BWmhDBtd.js → telnyx-rcjslHOP.js} +1 -1
- package/dist/{twilio-78mzH8Lk.js → twilio-B100ALoj.js} +2 -2
- package/openclaw.plugin.json +1 -1
- package/package.json +4 -4
package/dist/api.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { TtsAutoSchema, TtsConfigSchema, TtsModeSchema, TtsProviderSchema, definePluginEntry, fetchWithSsrFGuard, isBlockedHostnameOrIp, isRequestBodyLimitError, readRequestBodyWithLimit, requestBodyErrorToText, sleep } from "./runtime-api.js";
|
|
2
|
-
export { TtsAutoSchema, TtsConfigSchema, TtsModeSchema, TtsProviderSchema, definePluginEntry, fetchWithSsrFGuard, isBlockedHostnameOrIp, isRequestBodyLimitError, readRequestBodyWithLimit, requestBodyErrorToText, sleep };
|
|
1
|
+
import { TtsAutoSchema, TtsConfigSchema, TtsModeSchema, TtsProviderSchema, definePluginEntry, fetchWithSsrFGuard, isBlockedHostnameOrIp, isRequestBodyLimitError, readRequestBodyWithLimit, requestBodyErrorToText, sendHttpRequestRejection, sleep } from "./runtime-api.js";
|
|
2
|
+
export { TtsAutoSchema, TtsConfigSchema, TtsModeSchema, TtsProviderSchema, definePluginEntry, fetchWithSsrFGuard, isBlockedHostnameOrIp, isRequestBodyLimitError, readRequestBodyWithLimit, requestBodyErrorToText, sendHttpRequestRejection, sleep };
|
|
@@ -0,0 +1,630 @@
|
|
|
1
|
+
import { sleep } from "./runtime-api.js";
|
|
2
|
+
import "./api.js";
|
|
3
|
+
import { l as resolveVoiceCallStreamExposurePaths, u as validateProviderConfig } from "./config-DQwvsxeV.js";
|
|
4
|
+
import { _ as resolveUserPath, c as resolveWebhookExposureStatus, d as setupTailscaleExposureRoutes, g as resolveVoiceCallAgentId, l as cleanupTailscaleExposureRoute, u as getTailscaleSelfInfo } from "./runtime-entry-gE2Yd4V8.js";
|
|
5
|
+
import { b as setVoiceCallStateRuntime, d as loadActiveCallsFromStore, l as findCallInStore, o as MAX_CALL_RECORD_EVENTS, t as resolveDefaultVoiceCallStoreDir, u as getCallHistoryFromStore } from "./store-path-C_z9zKnA.js";
|
|
6
|
+
import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime";
|
|
7
|
+
import { callGatewayFromCli, isGatewayClientRequestError, isGatewayTransportError, redactSensitiveUrlLikeString } from "openclaw/plugin-sdk/gateway-runtime";
|
|
8
|
+
import { isRecord, normalizeOptionalLowercaseString } from "openclaw/plugin-sdk/string-coerce-runtime";
|
|
9
|
+
import { MAX_TCP_PORT, MAX_TIMER_TIMEOUT_MS, addTimerTimeoutGraceMs, clampTimerTimeoutMs, parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime";
|
|
10
|
+
import fs from "node:fs";
|
|
11
|
+
import path from "node:path";
|
|
12
|
+
import { once } from "node:events";
|
|
13
|
+
import { format } from "node:util";
|
|
14
|
+
//#region extensions/voice-call/src/cli-command-io.ts
|
|
15
|
+
function writeCliLine(...values) {
|
|
16
|
+
process.stdout.write(`${format(...values)}\n`);
|
|
17
|
+
}
|
|
18
|
+
function writeCliJson(value) {
|
|
19
|
+
process.stdout.write(`${JSON.stringify(value, null, 2)}\n`);
|
|
20
|
+
}
|
|
21
|
+
function parseCliInteger(raw, optionName, opts) {
|
|
22
|
+
const min = opts?.min ?? 0;
|
|
23
|
+
const parsed = parseStrictNonNegativeInteger(raw?.trim() ?? "");
|
|
24
|
+
if (parsed === void 0 || parsed < min || opts?.max !== void 0 && parsed > opts.max) throw new Error(`Invalid numeric value for ${optionName}: ${raw ?? ""}`);
|
|
25
|
+
return parsed;
|
|
26
|
+
}
|
|
27
|
+
//#endregion
|
|
28
|
+
//#region extensions/voice-call/src/cli-call-log.ts
|
|
29
|
+
const READ_BYTES = 65536;
|
|
30
|
+
async function writeLogChunk(chunk) {
|
|
31
|
+
if (!process.stdout.write(chunk)) await once(process.stdout, "drain");
|
|
32
|
+
}
|
|
33
|
+
function* readLogLine({ fd, start, end }) {
|
|
34
|
+
for (let offset = start; offset < end;) {
|
|
35
|
+
const chunk = Buffer.alloc(Math.min(READ_BYTES, end - offset));
|
|
36
|
+
const bytesRead = fs.readSync(fd, chunk, 0, chunk.length, offset);
|
|
37
|
+
if (!bytesRead) throw new Error("Voice-call log was truncated while reading a record");
|
|
38
|
+
offset += bytesRead;
|
|
39
|
+
yield chunk.subarray(0, bytesRead);
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
async function* readLogLines(file, last, pollMs) {
|
|
43
|
+
let initial = true;
|
|
44
|
+
let offset = 0;
|
|
45
|
+
let lineStart = 0;
|
|
46
|
+
let previous;
|
|
47
|
+
const buffer = Buffer.alloc(READ_BYTES);
|
|
48
|
+
for (;;) {
|
|
49
|
+
let fd;
|
|
50
|
+
try {
|
|
51
|
+
fd = fs.openSync(file, "r");
|
|
52
|
+
} catch (error) {
|
|
53
|
+
if (initial || pollMs === void 0 || !isRecord(error) || error.code !== "ENOENT") throw error;
|
|
54
|
+
await sleep(pollMs);
|
|
55
|
+
continue;
|
|
56
|
+
}
|
|
57
|
+
try {
|
|
58
|
+
const stat = fs.fstatSync(fd);
|
|
59
|
+
if (previous && (stat.ino !== previous.ino || stat.dev !== previous.dev || stat.size < previous.size)) offset = lineStart = 0;
|
|
60
|
+
previous = stat;
|
|
61
|
+
const selected = [];
|
|
62
|
+
let count = 0;
|
|
63
|
+
while (offset < stat.size) {
|
|
64
|
+
const length = Math.min(buffer.length, stat.size - offset);
|
|
65
|
+
const bytesRead = fs.readSync(fd, buffer, 0, length, offset);
|
|
66
|
+
if (!bytesRead) break;
|
|
67
|
+
const start = offset;
|
|
68
|
+
offset += bytesRead;
|
|
69
|
+
for (let index = buffer.indexOf(10); index >= 0 && index < bytesRead; index = buffer.indexOf(10, index + 1)) {
|
|
70
|
+
const line = {
|
|
71
|
+
fd,
|
|
72
|
+
start: lineStart,
|
|
73
|
+
end: start + index
|
|
74
|
+
};
|
|
75
|
+
lineStart = line.end + 1;
|
|
76
|
+
if (line.end > line.start) {
|
|
77
|
+
if (!initial) yield line;
|
|
78
|
+
else if (last > 0) selected[count++ % last] = line;
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (!initial && bytesRead < length) break;
|
|
82
|
+
}
|
|
83
|
+
if (pollMs === void 0 && lineStart < offset) selected[count++ % last] = {
|
|
84
|
+
fd,
|
|
85
|
+
start: lineStart,
|
|
86
|
+
end: offset
|
|
87
|
+
};
|
|
88
|
+
yield* selected.splice(last === 0 ? 0 : count % last);
|
|
89
|
+
yield* selected;
|
|
90
|
+
} finally {
|
|
91
|
+
fs.closeSync(fd);
|
|
92
|
+
}
|
|
93
|
+
initial = false;
|
|
94
|
+
if (pollMs === void 0) return;
|
|
95
|
+
await sleep(pollMs);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
function percentile(values, p) {
|
|
99
|
+
if (values.length === 0) return 0;
|
|
100
|
+
const sorted = [...values].toSorted((a, b) => a - b);
|
|
101
|
+
return sorted[Math.min(sorted.length - 1, Math.max(0, Math.ceil(p / 100 * sorted.length) - 1))] ?? 0;
|
|
102
|
+
}
|
|
103
|
+
function summarizeSeries(values) {
|
|
104
|
+
if (values.length === 0) return {
|
|
105
|
+
count: 0,
|
|
106
|
+
minMs: 0,
|
|
107
|
+
maxMs: 0,
|
|
108
|
+
avgMs: 0,
|
|
109
|
+
p50Ms: 0,
|
|
110
|
+
p95Ms: 0
|
|
111
|
+
};
|
|
112
|
+
const minMs = values.reduce((min, value) => value < min ? value : min);
|
|
113
|
+
const maxMs = values.reduce((max, value) => value > max ? value : max);
|
|
114
|
+
const avgMs = values.reduce((sum, value) => sum + value, 0) / values.length;
|
|
115
|
+
return {
|
|
116
|
+
count: values.length,
|
|
117
|
+
minMs,
|
|
118
|
+
maxMs,
|
|
119
|
+
avgMs,
|
|
120
|
+
p50Ms: percentile(values, 50),
|
|
121
|
+
p95Ms: percentile(values, 95)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
async function writeVoiceCallLatencySummary(calls) {
|
|
125
|
+
let recordsScanned = 0;
|
|
126
|
+
const turnLatencyMs = [];
|
|
127
|
+
const listenWaitMs = [];
|
|
128
|
+
for await (const call of calls) {
|
|
129
|
+
recordsScanned++;
|
|
130
|
+
const metadata = isRecord(call) && isRecord(call.metadata) ? call.metadata : void 0;
|
|
131
|
+
const latency = metadata?.lastTurnLatencyMs;
|
|
132
|
+
const listenWait = metadata?.lastTurnListenWaitMs;
|
|
133
|
+
if (typeof latency === "number" && Number.isFinite(latency)) turnLatencyMs.push(latency);
|
|
134
|
+
if (typeof listenWait === "number" && Number.isFinite(listenWait)) listenWaitMs.push(listenWait);
|
|
135
|
+
}
|
|
136
|
+
writeCliJson({
|
|
137
|
+
recordsScanned,
|
|
138
|
+
turnLatency: summarizeSeries(turnLatencyMs),
|
|
139
|
+
listenWait: summarizeSeries(listenWaitMs)
|
|
140
|
+
});
|
|
141
|
+
}
|
|
142
|
+
function registerVoiceCallLogs(params) {
|
|
143
|
+
params.root.command("tail").description("Tail persisted voice-call records or a custom JSONL log").option("--file <path>", "Path to calls.jsonl", params.defaultFile).option("--since <n>", "Print last N lines first", "25").option("--poll <ms>", "Poll interval in ms", "250").action(async (options) => {
|
|
144
|
+
const file = options.file;
|
|
145
|
+
const since = parseCliInteger(options.since, "--since", { min: 0 });
|
|
146
|
+
const pollMs = parseCliInteger(options.poll, "--poll", { min: 50 });
|
|
147
|
+
if (fs.existsSync(file) && path.basename(file) !== "calls.jsonl") for await (const line of readLogLines(file, since, pollMs)) {
|
|
148
|
+
for (const chunk of readLogLine(line)) await writeLogChunk(chunk);
|
|
149
|
+
await writeLogChunk("\n");
|
|
150
|
+
}
|
|
151
|
+
else {
|
|
152
|
+
params.ensureHistoryStateRuntime();
|
|
153
|
+
let initial = true;
|
|
154
|
+
let seen = /* @__PURE__ */ new Set();
|
|
155
|
+
for (;;) {
|
|
156
|
+
const lines = (await getCallHistoryFromStore(path.dirname(file), MAX_CALL_RECORD_EVENTS)).map((call) => JSON.stringify(call));
|
|
157
|
+
for (const line of initial ? lines.slice(Math.max(0, lines.length - since)) : lines) if (!seen.has(line)) {
|
|
158
|
+
await writeLogChunk(`${line}\n`);
|
|
159
|
+
seen.add(line);
|
|
160
|
+
}
|
|
161
|
+
seen = new Set(lines);
|
|
162
|
+
initial = false;
|
|
163
|
+
await sleep(pollMs);
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
});
|
|
167
|
+
params.root.command("latency").description("Summarize turn latency metrics from voice-call history or a custom JSONL log").option("--file <path>", "Path to calls.jsonl", params.defaultFile).option("--last <n>", "Analyze last N records", "200").action(async (options) => {
|
|
168
|
+
const file = options.file;
|
|
169
|
+
const last = parseCliInteger(options.last, "--last", { min: 1 });
|
|
170
|
+
if (fs.existsSync(file) && path.basename(file) !== "calls.jsonl") {
|
|
171
|
+
async function* readCalls() {
|
|
172
|
+
for await (const line of readLogLines(file, last)) try {
|
|
173
|
+
const parsed = JSON.parse(Buffer.concat([...readLogLine(line)]).toString("utf8"));
|
|
174
|
+
const call = (isRecord(parsed) ? parsed.call : void 0) ?? parsed;
|
|
175
|
+
if (call !== null) yield call;
|
|
176
|
+
} catch (error) {
|
|
177
|
+
if (!(error instanceof SyntaxError)) throw error;
|
|
178
|
+
}
|
|
179
|
+
}
|
|
180
|
+
await writeVoiceCallLatencySummary(readCalls());
|
|
181
|
+
} else {
|
|
182
|
+
params.ensureHistoryStateRuntime();
|
|
183
|
+
await writeVoiceCallLatencySummary(await getCallHistoryFromStore(path.dirname(file), last));
|
|
184
|
+
}
|
|
185
|
+
});
|
|
186
|
+
}
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region extensions/voice-call/src/cli-gateway-call.ts
|
|
189
|
+
const VOICE_CALL_GATEWAY_DEFAULT_TIMEOUT_MS = 5e3;
|
|
190
|
+
const VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS = 3e4;
|
|
191
|
+
const VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS = 1e4;
|
|
192
|
+
const VOICE_CALL_GATEWAY_POLL_INTERVAL_MS = 1e3;
|
|
193
|
+
function isGatewayUnavailableForLocalFallback(err) {
|
|
194
|
+
return isGatewayTransportError(err) && err.kind === "closed" && (err.code === void 0 || err.code === 1006);
|
|
195
|
+
}
|
|
196
|
+
function isGatewayCredentialFailure(err) {
|
|
197
|
+
return err instanceof Error && (err.name === "GatewayCredentialsRequiredError" || err.name === "GatewayExplicitAuthRequiredError" || err.name === "GatewaySecretRefUnavailableError");
|
|
198
|
+
}
|
|
199
|
+
function gatewayOperationalError(err) {
|
|
200
|
+
const message = formatErrorMessage(err);
|
|
201
|
+
const detail = (() => {
|
|
202
|
+
if (isGatewayClientRequestError(err)) return `Gateway responded but voicecall failed: ${message}\nThe running Gateway owns the voice-call runtime; check \`openclaw gateway status\` or restart it.`;
|
|
203
|
+
if (isGatewayCredentialFailure(err)) return `Gateway requires credentials: ${message}\nConfigure gateway.auth or pair this device with \`openclaw devices approve --latest\`.`;
|
|
204
|
+
if (isGatewayTransportError(err)) {
|
|
205
|
+
const url = err.connectionDetails.url;
|
|
206
|
+
if (err.kind === "timeout") return `Gateway at ${url} did not answer within ${err.timeoutMs === void 0 ? "the configured timeout" : `${err.timeoutMs}ms`}: ${message}\nIt may be starting or wedged; check \`openclaw gateway status\`.`;
|
|
207
|
+
return `Gateway connection at ${url} failed: ${message}\nCheck gateway.auth and \`openclaw gateway status\`, then retry.`;
|
|
208
|
+
}
|
|
209
|
+
return `Gateway voicecall request failed: ${message}\nCheck \`openclaw gateway status\`, then retry.`;
|
|
210
|
+
})();
|
|
211
|
+
return new Error(redactSensitiveUrlLikeString(detail));
|
|
212
|
+
}
|
|
213
|
+
function isUnknownMethod(err, method) {
|
|
214
|
+
return formatErrorMessage(err).includes(`unknown method: ${method}`);
|
|
215
|
+
}
|
|
216
|
+
async function callVoiceCallGateway(method, params, opts) {
|
|
217
|
+
try {
|
|
218
|
+
const timeoutMs = typeof opts?.timeoutMs === "number" && Number.isFinite(opts.timeoutMs) ? Math.max(1, Math.ceil(opts.timeoutMs)) : VOICE_CALL_GATEWAY_DEFAULT_TIMEOUT_MS;
|
|
219
|
+
return {
|
|
220
|
+
ok: true,
|
|
221
|
+
payload: await callGatewayFromCli(method, {
|
|
222
|
+
json: true,
|
|
223
|
+
timeout: String(timeoutMs)
|
|
224
|
+
}, params, { progress: false })
|
|
225
|
+
};
|
|
226
|
+
} catch (err) {
|
|
227
|
+
if (isGatewayUnavailableForLocalFallback(err)) return {
|
|
228
|
+
ok: false,
|
|
229
|
+
error: err
|
|
230
|
+
};
|
|
231
|
+
throw gatewayOperationalError(err);
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
function resolveOperationTimeout(config) {
|
|
235
|
+
return Math.max(VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS, addTimerTimeoutGraceMs(config.ringTimeoutMs) ?? 1);
|
|
236
|
+
}
|
|
237
|
+
function resolveContinueTimeout(config) {
|
|
238
|
+
return clampTimerTimeoutMs(config.transcriptTimeoutMs + VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS + VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS) ?? 1;
|
|
239
|
+
}
|
|
240
|
+
function resolveVoiceCallDeadlineMs(timeoutMs, nowMs = Date.now()) {
|
|
241
|
+
return nowMs + (clampTimerTimeoutMs(timeoutMs) ?? MAX_TIMER_TIMEOUT_MS);
|
|
242
|
+
}
|
|
243
|
+
function readGatewayOperationId(payload) {
|
|
244
|
+
if (isRecord(payload) && typeof payload.operationId === "string" && payload.operationId) return payload.operationId;
|
|
245
|
+
throw new Error("voicecall gateway response missing operationId");
|
|
246
|
+
}
|
|
247
|
+
function readGatewayPollTimeoutMs(payload, fallbackTimeoutMs) {
|
|
248
|
+
if (isRecord(payload) && typeof payload.pollTimeoutMs === "number") return clampTimerTimeoutMs(payload.pollTimeoutMs) ?? fallbackTimeoutMs;
|
|
249
|
+
return fallbackTimeoutMs;
|
|
250
|
+
}
|
|
251
|
+
function readCompletedContinueResult(payload) {
|
|
252
|
+
if (!isRecord(payload)) throw new Error("voicecall gateway response missing operation status");
|
|
253
|
+
if (payload.status === "pending") return { status: "pending" };
|
|
254
|
+
if (payload.status === "failed") return {
|
|
255
|
+
status: "failed",
|
|
256
|
+
error: typeof payload.error === "string" ? payload.error : "continue failed"
|
|
257
|
+
};
|
|
258
|
+
if (payload.status === "completed") return {
|
|
259
|
+
status: "completed",
|
|
260
|
+
result: payload.result
|
|
261
|
+
};
|
|
262
|
+
throw new Error("voicecall gateway response has unknown operation status");
|
|
263
|
+
}
|
|
264
|
+
async function pollContinueGateway(payload, fallbackTimeoutMs) {
|
|
265
|
+
if (!isRecord(payload) || typeof payload.operationId !== "string") return payload;
|
|
266
|
+
const params = {
|
|
267
|
+
operationId: readGatewayOperationId(payload),
|
|
268
|
+
timeoutMs: readGatewayPollTimeoutMs(payload, fallbackTimeoutMs)
|
|
269
|
+
};
|
|
270
|
+
const deadlineMs = resolveVoiceCallDeadlineMs(params.timeoutMs);
|
|
271
|
+
for (;;) {
|
|
272
|
+
const remainingMs = deadlineMs - Date.now();
|
|
273
|
+
if (remainingMs <= 0) break;
|
|
274
|
+
const gateway = await callVoiceCallGateway("voicecall.continue.result", { operationId: params.operationId }, { timeoutMs: Math.min(VOICE_CALL_GATEWAY_DEFAULT_TIMEOUT_MS, remainingMs) });
|
|
275
|
+
if (!gateway.ok) throw new Error(`gateway unavailable while waiting for voicecall continue result: ${formatErrorMessage(gateway.error)}`);
|
|
276
|
+
const result = readCompletedContinueResult(gateway.payload);
|
|
277
|
+
if (result.status === "completed") return result.result;
|
|
278
|
+
if (result.status === "failed") throw new Error(result.error);
|
|
279
|
+
const sleepMs = Math.min(VOICE_CALL_GATEWAY_POLL_INTERVAL_MS, deadlineMs - Date.now());
|
|
280
|
+
if (sleepMs <= 0) break;
|
|
281
|
+
await sleep(sleepMs);
|
|
282
|
+
}
|
|
283
|
+
throw new Error("voicecall continue timed out waiting for gateway operation");
|
|
284
|
+
}
|
|
285
|
+
async function ensureStandaloneRuntime(params) {
|
|
286
|
+
try {
|
|
287
|
+
return await params.ensureRuntime();
|
|
288
|
+
} catch (err) {
|
|
289
|
+
if (err instanceof Error && "code" in err && err.code === "EADDRINUSE") throw new Error(`Voice-call webhook port ${params.config.serve.port} is already in use. A running Gateway probably already serves it; operational commands route through that Gateway. Check \`openclaw gateway status\` and retry.`, { cause: err });
|
|
290
|
+
throw err;
|
|
291
|
+
}
|
|
292
|
+
}
|
|
293
|
+
async function runGatewayManagerCommand(params) {
|
|
294
|
+
const gateway = await params.gatewayCall();
|
|
295
|
+
if (gateway.ok) {
|
|
296
|
+
writeCliJson(params.resolveGatewayPayload ? await params.resolveGatewayPayload(gateway.payload) : gateway.payload);
|
|
297
|
+
return;
|
|
298
|
+
}
|
|
299
|
+
const runtime = await ensureStandaloneRuntime(params);
|
|
300
|
+
const result = await params.managerFallback(runtime.manager);
|
|
301
|
+
if (!result.success) throw new Error(result.error || `${params.failureLabel} failed`);
|
|
302
|
+
writeCliJson(result);
|
|
303
|
+
}
|
|
304
|
+
function readGatewayCallId(payload, invalidCallIdMessage) {
|
|
305
|
+
if (isRecord(payload) && typeof payload.callId === "string") {
|
|
306
|
+
if (!invalidCallIdMessage || payload.callId) return payload.callId;
|
|
307
|
+
}
|
|
308
|
+
if (invalidCallIdMessage) throw new Error(invalidCallIdMessage);
|
|
309
|
+
if (isRecord(payload) && typeof payload.error === "string") throw new Error(payload.error);
|
|
310
|
+
throw new Error("voicecall gateway response missing callId");
|
|
311
|
+
}
|
|
312
|
+
async function initiateVoiceCall(params) {
|
|
313
|
+
const mode = params.mode === "notify" || params.mode === "conversation" ? params.mode : params.defaultMode;
|
|
314
|
+
const gateway = await callVoiceCallGateway(params.method, {
|
|
315
|
+
...params.to ? { to: params.to } : {},
|
|
316
|
+
...params.message ? { message: params.message } : {},
|
|
317
|
+
...mode ? { mode } : {}
|
|
318
|
+
}, { timeoutMs: resolveOperationTimeout(params.config) });
|
|
319
|
+
if (gateway.ok) return readGatewayCallId(gateway.payload, params.failureMessage);
|
|
320
|
+
const runtime = await ensureStandaloneRuntime(params);
|
|
321
|
+
const to = params.to ?? runtime.config.toNumber;
|
|
322
|
+
if (!to) throw new Error("Missing --to and no toNumber configured");
|
|
323
|
+
const result = await runtime.manager.initiateCall(to, void 0, {
|
|
324
|
+
message: params.message,
|
|
325
|
+
mode
|
|
326
|
+
});
|
|
327
|
+
if (!result.success) throw new Error(result.error || params.failureMessage || "initiate failed");
|
|
328
|
+
if (params.failureMessage && !result.callId) throw new Error(params.failureMessage);
|
|
329
|
+
return result.callId;
|
|
330
|
+
}
|
|
331
|
+
//#endregion
|
|
332
|
+
//#region extensions/voice-call/src/cli.ts
|
|
333
|
+
function resolveMode(input) {
|
|
334
|
+
const raw = normalizeOptionalLowercaseString(input) ?? "";
|
|
335
|
+
if (raw === "serve" || raw === "off") return raw;
|
|
336
|
+
return "funnel";
|
|
337
|
+
}
|
|
338
|
+
function resolveDefaultStorePath(config) {
|
|
339
|
+
const base = config.store?.trim() ? resolveUserPath(config.store) : resolveDefaultVoiceCallStoreDir();
|
|
340
|
+
return path.join(base, "calls.jsonl");
|
|
341
|
+
}
|
|
342
|
+
function buildSetupStatus(config, coreConfig) {
|
|
343
|
+
const validation = validateProviderConfig(config);
|
|
344
|
+
const webhookExposure = resolveWebhookExposureStatus(config);
|
|
345
|
+
const checks = [
|
|
346
|
+
{
|
|
347
|
+
id: "plugin-enabled",
|
|
348
|
+
ok: config.enabled,
|
|
349
|
+
message: config.enabled ? "Voice Call plugin is enabled" : "Enable plugins.entries.voice-call.enabled"
|
|
350
|
+
},
|
|
351
|
+
{
|
|
352
|
+
id: "provider",
|
|
353
|
+
ok: Boolean(config.provider),
|
|
354
|
+
message: config.provider ? `Provider configured: ${config.provider}` : "Set plugins.entries.voice-call.config.provider"
|
|
355
|
+
},
|
|
356
|
+
{
|
|
357
|
+
id: "provider-config",
|
|
358
|
+
ok: validation.valid,
|
|
359
|
+
message: validation.valid ? "Provider credentials/config look complete" : validation.errors.join("; ")
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
id: "webhook-exposure",
|
|
363
|
+
ok: webhookExposure.ok,
|
|
364
|
+
message: webhookExposure.message
|
|
365
|
+
},
|
|
366
|
+
{
|
|
367
|
+
id: "mode",
|
|
368
|
+
ok: !(config.streaming.enabled && config.realtime.enabled),
|
|
369
|
+
message: config.streaming.enabled && config.realtime.enabled ? "streaming.enabled and realtime.enabled cannot both be true" : config.realtime.enabled ? `Realtime voice enabled (${config.realtime.provider ?? "first registered provider"})` : config.streaming.enabled ? `Streaming transcription enabled (${config.streaming.provider ?? "first registered provider"})` : "Notify/conversation calls use normal TTS/STT flow"
|
|
370
|
+
}
|
|
371
|
+
];
|
|
372
|
+
try {
|
|
373
|
+
const agentId = resolveVoiceCallAgentId(config, coreConfig);
|
|
374
|
+
checks.push({
|
|
375
|
+
id: "agent-owner",
|
|
376
|
+
ok: true,
|
|
377
|
+
message: `Response agent: ${agentId}`
|
|
378
|
+
});
|
|
379
|
+
} catch (error) {
|
|
380
|
+
checks.push({
|
|
381
|
+
id: "agent-owner",
|
|
382
|
+
ok: false,
|
|
383
|
+
message: formatErrorMessage(error)
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return {
|
|
387
|
+
ok: checks.every((check) => check.ok),
|
|
388
|
+
checks
|
|
389
|
+
};
|
|
390
|
+
}
|
|
391
|
+
function writeSetupStatus(status) {
|
|
392
|
+
writeCliLine("Voice Call setup: %s", status.ok ? "OK" : "needs attention");
|
|
393
|
+
for (const check of status.checks) writeCliLine("%s %s: %s", check.ok ? "OK" : "FAIL", check.id, check.message);
|
|
394
|
+
}
|
|
395
|
+
function registerVoiceCallCli(params) {
|
|
396
|
+
const { program, config, coreConfig, ensureRuntime, stateRuntime } = params;
|
|
397
|
+
const ensureHistoryStateRuntime = () => {
|
|
398
|
+
if (stateRuntime) setVoiceCallStateRuntime({ state: stateRuntime });
|
|
399
|
+
};
|
|
400
|
+
const root = program.command("voicecall").description("Voice call utilities").addHelpText("after", () => `\nDocs: https://docs.openclaw.ai/cli/voicecall\n`);
|
|
401
|
+
root.command("setup").description("Show Voice Call provider and webhook setup status").option("--json", "Print machine-readable JSON").action((options) => {
|
|
402
|
+
const status = buildSetupStatus(config, coreConfig);
|
|
403
|
+
if (options.json) {
|
|
404
|
+
writeCliJson(status);
|
|
405
|
+
return;
|
|
406
|
+
}
|
|
407
|
+
writeSetupStatus(status);
|
|
408
|
+
});
|
|
409
|
+
root.command("smoke").description("Check Voice Call readiness and optionally place a short outbound test call").option("-t, --to <phone>", "Phone number to call for a live smoke").option("--message <text>", "Message to speak during the smoke call", "OpenClaw voice call smoke test.").option("--mode <mode>", "Call mode: notify or conversation", "notify").option("--yes", "Actually place the live outbound call").option("--json", "Print machine-readable JSON").action(async (options) => {
|
|
410
|
+
const setup = buildSetupStatus(config, coreConfig);
|
|
411
|
+
if (!setup.ok) {
|
|
412
|
+
if (options.json) writeCliJson({
|
|
413
|
+
ok: false,
|
|
414
|
+
setup
|
|
415
|
+
});
|
|
416
|
+
else writeSetupStatus(setup);
|
|
417
|
+
process.exitCode = 1;
|
|
418
|
+
return;
|
|
419
|
+
}
|
|
420
|
+
if (!options.to) {
|
|
421
|
+
if (options.json) writeCliJson({
|
|
422
|
+
ok: true,
|
|
423
|
+
setup,
|
|
424
|
+
liveCall: false
|
|
425
|
+
});
|
|
426
|
+
else {
|
|
427
|
+
writeSetupStatus(setup);
|
|
428
|
+
writeCliLine("live-call: skipped (pass --to and --yes to place one)");
|
|
429
|
+
}
|
|
430
|
+
return;
|
|
431
|
+
}
|
|
432
|
+
if (!options.yes) {
|
|
433
|
+
if (options.json) writeCliJson({
|
|
434
|
+
ok: true,
|
|
435
|
+
setup,
|
|
436
|
+
liveCall: false,
|
|
437
|
+
wouldCall: options.to
|
|
438
|
+
});
|
|
439
|
+
else {
|
|
440
|
+
writeSetupStatus(setup);
|
|
441
|
+
writeCliLine("live-call: dry run for %s (add --yes to place it)", options.to);
|
|
442
|
+
}
|
|
443
|
+
return;
|
|
444
|
+
}
|
|
445
|
+
const callId = await initiateVoiceCall({
|
|
446
|
+
ensureRuntime,
|
|
447
|
+
config,
|
|
448
|
+
method: "voicecall.start",
|
|
449
|
+
to: options.to,
|
|
450
|
+
message: options.message,
|
|
451
|
+
mode: options.mode,
|
|
452
|
+
defaultMode: "notify",
|
|
453
|
+
failureMessage: "smoke call failed"
|
|
454
|
+
});
|
|
455
|
+
if (options.json) {
|
|
456
|
+
writeCliJson({
|
|
457
|
+
ok: true,
|
|
458
|
+
setup,
|
|
459
|
+
liveCall: true,
|
|
460
|
+
callId
|
|
461
|
+
});
|
|
462
|
+
return;
|
|
463
|
+
}
|
|
464
|
+
writeSetupStatus(setup);
|
|
465
|
+
writeCliLine("live-call: started %s", callId);
|
|
466
|
+
});
|
|
467
|
+
root.command("call").description("Initiate an outbound voice call").requiredOption("-m, --message <text>", "Message to speak when call connects").option("-t, --to <phone>", "Phone number to call (E.164 format, uses config toNumber if not set)").option("--mode <mode>", "Call mode: notify (hangup after message) or conversation (stay open)", "conversation").action(async (options) => {
|
|
468
|
+
writeCliJson({ callId: await initiateVoiceCall({
|
|
469
|
+
ensureRuntime,
|
|
470
|
+
config,
|
|
471
|
+
method: "voicecall.initiate",
|
|
472
|
+
to: options.to,
|
|
473
|
+
message: options.message,
|
|
474
|
+
mode: options.mode
|
|
475
|
+
}) });
|
|
476
|
+
});
|
|
477
|
+
root.command("start").description("Alias for voicecall call").requiredOption("--to <phone>", "Phone number to call").option("--message <text>", "Message to speak when call connects").option("--mode <mode>", "Call mode: notify (hangup after message) or conversation (stay open)", "conversation").action(async (options) => {
|
|
478
|
+
writeCliJson({ callId: await initiateVoiceCall({
|
|
479
|
+
ensureRuntime,
|
|
480
|
+
config,
|
|
481
|
+
method: "voicecall.start",
|
|
482
|
+
to: options.to,
|
|
483
|
+
message: options.message,
|
|
484
|
+
mode: options.mode
|
|
485
|
+
}) });
|
|
486
|
+
});
|
|
487
|
+
root.command("continue").description("Speak a message and wait for a response").requiredOption("--call-id <id>", "Call ID").requiredOption("--message <text>", "Message to speak").action(async (options) => {
|
|
488
|
+
const gatewayParams = {
|
|
489
|
+
callId: options.callId,
|
|
490
|
+
message: options.message
|
|
491
|
+
};
|
|
492
|
+
const continueTimeoutMs = resolveContinueTimeout(config);
|
|
493
|
+
await runGatewayManagerCommand({
|
|
494
|
+
config,
|
|
495
|
+
ensureRuntime,
|
|
496
|
+
gatewayCall: async () => {
|
|
497
|
+
try {
|
|
498
|
+
return await callVoiceCallGateway("voicecall.continue.start", gatewayParams, { timeoutMs: resolveOperationTimeout(config) });
|
|
499
|
+
} catch (err) {
|
|
500
|
+
if (!isUnknownMethod(err, "voicecall.continue.start")) throw err;
|
|
501
|
+
return callVoiceCallGateway("voicecall.continue", gatewayParams, { timeoutMs: continueTimeoutMs });
|
|
502
|
+
}
|
|
503
|
+
},
|
|
504
|
+
resolveGatewayPayload: (payload) => pollContinueGateway(payload, continueTimeoutMs),
|
|
505
|
+
managerFallback: (manager) => manager.continueCall(options.callId, options.message),
|
|
506
|
+
failureLabel: "continue"
|
|
507
|
+
});
|
|
508
|
+
});
|
|
509
|
+
root.command("speak").description("Speak a message without waiting for response").requiredOption("--call-id <id>", "Call ID").requiredOption("--message <text>", "Message to speak").action(async (options) => {
|
|
510
|
+
await runGatewayManagerCommand({
|
|
511
|
+
config,
|
|
512
|
+
ensureRuntime,
|
|
513
|
+
gatewayCall: () => callVoiceCallGateway("voicecall.speak", {
|
|
514
|
+
callId: options.callId,
|
|
515
|
+
message: options.message
|
|
516
|
+
}),
|
|
517
|
+
managerFallback: (manager) => manager.speak(options.callId, options.message),
|
|
518
|
+
failureLabel: "speak"
|
|
519
|
+
});
|
|
520
|
+
});
|
|
521
|
+
root.command("dtmf").description("Send DTMF digits to an active call").requiredOption("--call-id <id>", "Call ID").requiredOption("--digits <digits>", "DTMF digits").action(async (options) => {
|
|
522
|
+
await runGatewayManagerCommand({
|
|
523
|
+
config,
|
|
524
|
+
ensureRuntime,
|
|
525
|
+
gatewayCall: () => callVoiceCallGateway("voicecall.dtmf", {
|
|
526
|
+
callId: options.callId,
|
|
527
|
+
digits: options.digits
|
|
528
|
+
}),
|
|
529
|
+
managerFallback: (manager) => manager.sendDtmf(options.callId, options.digits),
|
|
530
|
+
failureLabel: "dtmf"
|
|
531
|
+
});
|
|
532
|
+
});
|
|
533
|
+
root.command("end").description("Hang up an active call").requiredOption("--call-id <id>", "Call ID").action(async (options) => {
|
|
534
|
+
await runGatewayManagerCommand({
|
|
535
|
+
config,
|
|
536
|
+
ensureRuntime,
|
|
537
|
+
gatewayCall: () => callVoiceCallGateway("voicecall.end", { callId: options.callId }),
|
|
538
|
+
managerFallback: (manager) => manager.endCall(options.callId),
|
|
539
|
+
failureLabel: "end"
|
|
540
|
+
});
|
|
541
|
+
});
|
|
542
|
+
root.command("status").description("Show call status").option("--call-id <id>", "Call ID").option("--json", "Print machine-readable JSON").action(async (options) => {
|
|
543
|
+
const gateway = await callVoiceCallGateway("voicecall.status", options.callId ? { callId: options.callId } : void 0);
|
|
544
|
+
if (gateway.ok) {
|
|
545
|
+
if (options.callId && isRecord(gateway.payload)) {
|
|
546
|
+
if (gateway.payload.found === true && "call" in gateway.payload) {
|
|
547
|
+
writeCliJson(gateway.payload.call);
|
|
548
|
+
return;
|
|
549
|
+
}
|
|
550
|
+
if (gateway.payload.found === false) {
|
|
551
|
+
writeCliJson({ found: false });
|
|
552
|
+
return;
|
|
553
|
+
}
|
|
554
|
+
}
|
|
555
|
+
writeCliJson(gateway.payload);
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
ensureHistoryStateRuntime();
|
|
559
|
+
const storePath = path.dirname(resolveDefaultStorePath(config));
|
|
560
|
+
if (options.callId) {
|
|
561
|
+
writeCliJson(findCallInStore(storePath, options.callId) ?? { found: false });
|
|
562
|
+
return;
|
|
563
|
+
}
|
|
564
|
+
writeCliJson({
|
|
565
|
+
found: true,
|
|
566
|
+
calls: Array.from(loadActiveCallsFromStore(storePath).activeCalls.values())
|
|
567
|
+
});
|
|
568
|
+
});
|
|
569
|
+
registerVoiceCallLogs({
|
|
570
|
+
root,
|
|
571
|
+
defaultFile: resolveDefaultStorePath(config),
|
|
572
|
+
ensureHistoryStateRuntime
|
|
573
|
+
});
|
|
574
|
+
root.command("expose").description("Enable/disable Tailscale serve/funnel for the webhook").option("--mode <mode>", "off | serve (tailnet) | funnel (public)", "funnel").option("--path <path>", "Tailscale path to expose (recommend matching serve.path)").option("--port <port>", "Local webhook port").option("--serve-path <path>", "Local webhook path").action(async (options) => {
|
|
575
|
+
const mode = resolveMode(options.mode ?? "funnel");
|
|
576
|
+
const servePort = parseCliInteger(options.port ?? String(config.serve.port ?? 3334), "--port", {
|
|
577
|
+
min: 1,
|
|
578
|
+
max: MAX_TCP_PORT
|
|
579
|
+
});
|
|
580
|
+
const servePath = options.servePath ?? config.serve.path ?? "/voice/webhook";
|
|
581
|
+
const tsPath = options.path ?? config.tailscale?.path ?? servePath;
|
|
582
|
+
const streamExposurePaths = resolveVoiceCallStreamExposurePaths(config, {
|
|
583
|
+
publicWebhookPath: tsPath,
|
|
584
|
+
localWebhookPath: servePath
|
|
585
|
+
});
|
|
586
|
+
const streamPaths = streamExposurePaths.map(({ publicPath }) => publicPath);
|
|
587
|
+
const localUrl = `http://127.0.0.1:${servePort}${servePath}`;
|
|
588
|
+
if (mode === "off") {
|
|
589
|
+
for (const exposurePath of [tsPath, ...streamPaths]) for (const tailscaleMode of ["serve", "funnel"]) await cleanupTailscaleExposureRoute({
|
|
590
|
+
mode: tailscaleMode,
|
|
591
|
+
port: config.tailscale.port,
|
|
592
|
+
path: exposurePath
|
|
593
|
+
});
|
|
594
|
+
writeCliJson({
|
|
595
|
+
ok: true,
|
|
596
|
+
mode: "off",
|
|
597
|
+
path: tsPath,
|
|
598
|
+
streamPaths
|
|
599
|
+
});
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
const publicUrl = await setupTailscaleExposureRoutes({
|
|
603
|
+
mode,
|
|
604
|
+
port: config.tailscale.port,
|
|
605
|
+
routes: [{
|
|
606
|
+
path: tsPath,
|
|
607
|
+
localUrl
|
|
608
|
+
}, ...streamExposurePaths.map(({ publicPath, localPath }) => ({
|
|
609
|
+
path: publicPath,
|
|
610
|
+
localUrl: `http://127.0.0.1:${servePort}${localPath}`
|
|
611
|
+
}))]
|
|
612
|
+
});
|
|
613
|
+
const tsInfo = publicUrl ? null : await getTailscaleSelfInfo();
|
|
614
|
+
const enableUrl = tsInfo?.nodeId ? `https://login.tailscale.com/f/${mode}?node=${tsInfo.nodeId}` : null;
|
|
615
|
+
writeCliJson({
|
|
616
|
+
ok: Boolean(publicUrl),
|
|
617
|
+
mode,
|
|
618
|
+
path: tsPath,
|
|
619
|
+
streamPaths,
|
|
620
|
+
localUrl,
|
|
621
|
+
publicUrl,
|
|
622
|
+
hint: publicUrl ? void 0 : {
|
|
623
|
+
note: "Tailscale serve/funnel may be disabled on this tailnet (or require admin enable).",
|
|
624
|
+
enableUrl
|
|
625
|
+
}
|
|
626
|
+
});
|
|
627
|
+
});
|
|
628
|
+
}
|
|
629
|
+
//#endregion
|
|
630
|
+
export { registerVoiceCallCli };
|