@@ -5,6 +5,7 @@ import { format } from "node:util";
|
5 | 5 | import type { Command } from "commander"; |
6 | 6 | import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime"; |
7 | 7 | import { callGatewayFromCli } from "openclaw/plugin-sdk/gateway-runtime"; |
| 8 | +import { MAX_TCP_PORT, parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime"; |
8 | 9 | import { |
9 | 10 | isRecord, |
10 | 11 | normalizeOptionalLowercaseString, |
@@ -54,7 +55,6 @@ const VOICE_CALL_GATEWAY_DEFAULT_TIMEOUT_MS = 5000;
|
54 | 55 | const VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS = 30000; |
55 | 56 | const VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS = 10000; |
56 | 57 | const VOICE_CALL_GATEWAY_POLL_INTERVAL_MS = 1000; |
57 | | -const DECIMAL_INTEGER_RE = /^\d+$/; |
58 | 58 | |
59 | 59 | const voiceCallCliDeps = { |
60 | 60 | callGatewayFromCli, |
@@ -79,12 +79,12 @@ function writeStdoutJson(value: unknown): void {
|
79 | 79 | function parseVoiceCallIntOption( |
80 | 80 | raw: string | undefined, |
81 | 81 | optionName: string, |
82 | | -opts?: { min?: number }, |
| 82 | +opts?: { min?: number; max?: number }, |
83 | 83 | ): number { |
84 | 84 | const min = opts?.min ?? 0; |
85 | 85 | const value = raw?.trim() ?? ""; |
86 | | -const parsed = DECIMAL_INTEGER_RE.test(value) ? Number(value) : Number.NaN; |
87 | | -if (!Number.isInteger(parsed) || parsed < min) { |
| 86 | +const parsed = parseStrictNonNegativeInteger(value); |
| 87 | +if (parsed === undefined || parsed < min || (opts?.max !== undefined && parsed > opts.max)) { |
88 | 88 | throw new Error(`Invalid numeric value for ${optionName}: ${raw ?? ""}`); |
89 | 89 | } |
90 | 90 | return parsed; |
@@ -823,7 +823,7 @@ export function registerVoiceCallCli(params: {
|
823 | 823 | const servePort = parseVoiceCallIntOption( |
824 | 824 | options.port ?? String(config.serve.port ?? 3334), |
825 | 825 | "--port", |
826 | | -{ min: 1 }, |
| 826 | +{ min: 1, max: MAX_TCP_PORT }, |
827 | 827 | ); |
828 | 828 | const servePath = options.servePath ?? config.serve.path ?? "/voice/webhook"; |
829 | 829 | const tsPath = options.path ?? config.tailscale?.path ?? servePath; |
|