fix: harden gateway auth defaults

This commit is contained in:
Peter Steinberger
2026-01-11 01:50:46 +01:00
parent 49e7004664
commit d33285a9cd
9 changed files with 187 additions and 30 deletions

View File

@@ -9,19 +9,35 @@ import { runExec } from "../process/exec.js";
import type { RuntimeEnv } from "../runtime.js";
import { applyTemplate, type MsgContext } from "./templating.js";
const AUDIO_TRANSCRIPTION_BINARY = "whisper";
export function isAudio(mediaType?: string | null) {
return Boolean(mediaType?.startsWith("audio"));
}
export function hasAudioTranscriptionConfig(cfg: ClawdbotConfig): boolean {
if (cfg.tools?.audio?.transcription?.args?.length) return true;
return Boolean(cfg.audio?.transcription?.command?.length);
}
export async function transcribeInboundAudio(
cfg: ClawdbotConfig,
ctx: MsgContext,
runtime: RuntimeEnv,
): Promise<{ text: string } | undefined> {
const transcriber = cfg.audio?.transcription;
if (!transcriber?.command?.length) return undefined;
const toolTranscriber = cfg.tools?.audio?.transcription;
const legacyTranscriber = cfg.audio?.transcription;
const hasToolTranscriber = Boolean(toolTranscriber?.args?.length);
if (!hasToolTranscriber && !legacyTranscriber?.command?.length) {
return undefined;
}
const timeoutMs = Math.max((transcriber.timeoutSeconds ?? 45) * 1000, 1_000);
const timeoutMs = Math.max(
(toolTranscriber?.timeoutSeconds ??
legacyTranscriber?.timeoutSeconds ??
45) * 1000,
1_000,
);
let tmpPath: string | undefined;
let mediaPath = ctx.MediaPath;
try {
@@ -45,9 +61,13 @@ export async function transcribeInboundAudio(
if (!mediaPath) return undefined;
const templCtx: MsgContext = { ...ctx, MediaPath: mediaPath };
const argv = transcriber.command.map((part) =>
applyTemplate(part, templCtx),
);
const argv = hasToolTranscriber
? [AUDIO_TRANSCRIPTION_BINARY, ...(toolTranscriber?.args ?? [])].map(
(part, index) => (index === 0 ? part : applyTemplate(part, templCtx)),
)
: (legacyTranscriber?.command ?? []).map((part) =>
applyTemplate(part, templCtx),
);
if (shouldLogVerbose()) {
logVerbose(`Transcribing audio via command: ${argv.join(" ")}`);
}