@@ -5,7 +5,12 @@ import { format } from "node:util";
55import type { Command } from "commander" ;
66import { formatErrorMessage } from "openclaw/plugin-sdk/error-runtime" ;
77import { callGatewayFromCli } from "openclaw/plugin-sdk/gateway-runtime" ;
8- import { MAX_TCP_PORT , parseStrictNonNegativeInteger } from "openclaw/plugin-sdk/number-runtime" ;
8+ import {
9+ clampTimerTimeoutMs ,
10+ MAX_TIMER_TIMEOUT_MS ,
11+ MAX_TCP_PORT ,
12+ parseStrictNonNegativeInteger ,
13+ } from "openclaw/plugin-sdk/number-runtime" ;
914import {
1015 isRecord ,
1116 normalizeOptionalLowercaseString ,
@@ -66,6 +71,9 @@ export const testing = {
6671 } ,
6772 isGatewayUnavailableForLocalFallback,
6873 parseVoiceCallIntOption,
74+ resolveGatewayContinueTimeoutMs,
75+ resolveGatewayOperationTimeoutMs,
76+ resolveVoiceCallDeadlineMs,
6977} ;
7078
7179function writeStdoutLine ( ...values : unknown [ ] ) : void {
@@ -128,17 +136,26 @@ async function callVoiceCallGateway(
128136}
129137
130138function resolveGatewayOperationTimeoutMs ( config : VoiceCallConfig ) : number {
131- return Math . max ( VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS , config . ringTimeoutMs + 5000 ) ;
139+ return Math . max (
140+ VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS ,
141+ clampTimerTimeoutMs ( config . ringTimeoutMs + 5000 ) ?? 1 ,
142+ ) ;
132143}
133144
134145function resolveGatewayContinueTimeoutMs ( config : VoiceCallConfig ) : number {
135146 return (
136- config . transcriptTimeoutMs +
137- VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS +
138- VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS
147+ clampTimerTimeoutMs (
148+ config . transcriptTimeoutMs +
149+ VOICE_CALL_GATEWAY_OPERATION_TIMEOUT_MS +
150+ VOICE_CALL_GATEWAY_TRANSCRIPT_BUFFER_MS ,
151+ ) ?? 1
139152 ) ;
140153}
141154
155+ function resolveVoiceCallDeadlineMs ( timeoutMs : number , nowMs = Date . now ( ) ) : number {
156+ return nowMs + ( clampTimerTimeoutMs ( timeoutMs ) ?? MAX_TIMER_TIMEOUT_MS ) ;
157+ }
158+
142159function isUnknownGatewayMethod ( err : unknown , method : VoiceCallGatewayMethod ) : boolean {
143160 return formatErrorMessage ( err ) . includes ( `unknown method: ${ method } ` ) ;
144161}
@@ -185,7 +202,7 @@ async function pollVoiceCallContinueGateway(params: {
185202 operationId : string ;
186203 timeoutMs : number ;
187204} ) : Promise < unknown > {
188- const deadlineMs = Date . now ( ) + params . timeoutMs ;
205+ const deadlineMs = resolveVoiceCallDeadlineMs ( params . timeoutMs ) ;
189206
190207 while ( Date . now ( ) <= deadlineMs ) {
191208 const gateway = await callVoiceCallGateway (
0 commit comments