Skip to content

Commit 3a8ab78

Browse files
steipeteAlix-007
andcommitted
fix(qqbot): bound speech transcription requests
Co-authored-by: Alix-007 <[email protected]>
1 parent c9b3358 commit 3a8ab78

3 files changed

Lines changed: 46 additions & 3 deletions

File tree

‎docs/channels/qqbot.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -259,6 +259,11 @@ STT and TTS support two-level configuration with priority fallback:
259259
Set `enabled: false` on either to disable. Account-level TTS overrides use the
260260
same shape as `messages.tts` and deep-merge over channel/global TTS config.
261261

262+
STT requests time out after 60 seconds by default. Plugin-specific STT uses the
263+
selected `models.providers.<id>.timeoutSeconds` override. Framework audio STT
264+
uses `tools.media.audio.models[0].timeoutSeconds`, then
265+
`tools.media.audio.timeoutSeconds`, then the selected provider override.
266+
262267
Inbound QQ voice attachments are exposed to agents as audio media metadata
263268
while keeping raw voice files out of generic `MediaPaths`. `[[audio_as_voice]]`
264269
in a plain-text reply synthesizes TTS and sends a native QQ voice message when

‎extensions/qqbot/src/engine/utils/stt.test.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ function requireFirstSsrfRequest(): {
7575
url?: unknown;
7676
auditContext?: unknown;
7777
init?: RequestInit;
78+
timeoutMs?: unknown;
7879
} {
7980
const [call] = ssrfRuntimeMocks.fetchWithSsrFGuard.mock.calls;
8081
if (!call) {
@@ -84,6 +85,7 @@ function requireFirstSsrfRequest(): {
8485
url?: unknown;
8586
auditContext?: unknown;
8687
init?: RequestInit;
88+
timeoutMs?: unknown;
8789
};
8890
}
8991

@@ -118,6 +120,7 @@ describe("engine/utils/stt", () => {
118120
providers: {
119121
openai: {
120122
apiKey: "provider-key",
123+
timeoutSeconds: 45,
121124
},
122125
},
123126
},
@@ -127,6 +130,7 @@ describe("engine/utils/stt", () => {
127130
baseUrl: "https://api.example.test/v1",
128131
apiKey: "provider-key",
129132
model: "whisper-large",
133+
timeoutMs: 45_000,
130134
});
131135
});
132136

@@ -136,13 +140,14 @@ describe("engine/utils/stt", () => {
136140
tools: {
137141
media: {
138142
audio: {
143+
timeoutSeconds: 90,
139144
models: [{ provider: "local", baseUrl: "https://stt.example.test/", model: "sense" }],
140145
},
141146
},
142147
},
143148
models: {
144149
providers: {
145-
local: { apiKey: "local-key" },
150+
local: { apiKey: "local-key", timeoutSeconds: 120 },
146151
},
147152
},
148153
};
@@ -151,7 +156,11 @@ describe("engine/utils/stt", () => {
151156
baseUrl: "https://stt.example.test",
152157
apiKey: "local-key",
153158
model: "sense",
159+
timeoutMs: 90_000,
154160
});
161+
162+
Object.assign(cfg.tools.media.audio.models[0], { timeoutSeconds: 75 });
163+
expect(resolveSTTConfig(cfg)?.timeoutMs).toBe(75_000);
155164
});
156165

157166
it("returns null when no usable STT credentials are configured", () => {
@@ -191,6 +200,7 @@ describe("engine/utils/stt", () => {
191200
const request = requireFirstSsrfRequest();
192201
expect(request.url).toBe("https://api.example.test/v1/audio/transcriptions");
193202
expect(request.auditContext).toBe("qqbot-stt");
203+
expect(request.timeoutMs).toBe(60_000);
194204
expect(request.init?.method).toBe("POST");
195205
expect(request.init?.headers).toEqual({ Authorization: "Bearer secret" });
196206
expect(request.init?.body).toBeInstanceOf(FormData);

‎extensions/qqbot/src/engine/utils/stt.ts‎

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
import * as fs from "node:fs";
99
import path from "node:path";
1010
import { mimeTypeFromFilePath } from "openclaw/plugin-sdk/media-mime";
11+
import { finiteSecondsToTimerSafeMilliseconds } from "openclaw/plugin-sdk/number-runtime";
1112
import {
1213
readProviderJsonResponse,
1314
readResponseTextLimited,
@@ -22,11 +23,23 @@ import {
2223
} from "./string-normalize.js";
2324

2425
const STT_ERROR_BODY_LIMIT_BYTES = 8 * 1024;
26+
const DEFAULT_STT_TIMEOUT_MS = 60_000;
2527

2628
interface STTConfig {
2729
baseUrl: string;
2830
apiKey: string;
2931
model: string;
32+
timeoutMs: number;
33+
}
34+
35+
function resolveSTTTimeoutMs(...timeoutSeconds: unknown[]): number {
36+
for (const value of timeoutSeconds) {
37+
const timeoutMs = finiteSecondsToTimerSafeMilliseconds(value);
38+
if (timeoutMs !== undefined) {
39+
return timeoutMs;
40+
}
41+
}
42+
return DEFAULT_STT_TIMEOUT_MS;
3043
}
3144

3245
/** Resolve the STT configuration from the nested config object. */
@@ -45,7 +58,12 @@ export function resolveSTTConfig(cfg: Record<string, unknown>): STTConfig | null
4558
const apiKey = readString(channelStt, "apiKey") ?? readString(providerCfg, "apiKey");
4659
const model = readString(channelStt, "model") ?? "whisper-1";
4760
if (baseUrl && apiKey) {
48-
return { baseUrl: baseUrl.replace(/\/+$/, ""), apiKey, model };
61+
return {
62+
baseUrl: baseUrl.replace(/\/+$/, ""),
63+
apiKey,
64+
model,
65+
timeoutMs: resolveSTTTimeoutMs(providerCfg?.timeoutSeconds),
66+
};
4967
}
5068
}
5169

@@ -62,7 +80,16 @@ export function resolveSTTConfig(cfg: Record<string, unknown>): STTConfig | null
6280
const apiKey = readString(audioModelEntry, "apiKey") ?? readString(providerCfg, "apiKey");
6381
const model = readString(audioModelEntry, "model") ?? "whisper-1";
6482
if (baseUrl && apiKey) {
65-
return { baseUrl: baseUrl.replace(/\/+$/, ""), apiKey, model };
83+
return {
84+
baseUrl: baseUrl.replace(/\/+$/, ""),
85+
apiKey,
86+
model,
87+
timeoutMs: resolveSTTTimeoutMs(
88+
audioModelEntry.timeoutSeconds,
89+
audio?.timeoutSeconds,
90+
providerCfg?.timeoutSeconds,
91+
),
92+
};
6693
}
6794
}
6895

@@ -90,6 +117,7 @@ export async function transcribeAudio(
90117
const { response: resp, release } = await fetchWithSsrFGuard({
91118
url: `${sttCfg.baseUrl}/audio/transcriptions`,
92119
auditContext: "qqbot-stt",
120+
timeoutMs: sttCfg.timeoutMs,
93121
init: {
94122
method: "POST",
95123
headers: { Authorization: `Bearer ${sttCfg.apiKey}` },

0 commit comments

Comments
 (0)