mirror of
https://github.com/hanzoai/bot.git
synced 2026-11-01 18:02:28 +00:00
Auto-formatted 221 files restored from rebrand bridge to match the project's oxfmt style conventions.
51 lines
1.6 KiB
TypeScript
51 lines
1.6 KiB
TypeScript
import type { MsgContext } from "../auto-reply/templating.js";
|
|
import type { BotConfig } from "../config/config.js";
|
|
import type { MediaAttachment, MediaUnderstandingProvider } from "./types.js";
|
|
import {
|
|
type ActiveMediaModel,
|
|
buildProviderRegistry,
|
|
createMediaAttachmentCache,
|
|
normalizeMediaAttachments,
|
|
runCapability,
|
|
} from "./runner.js";
|
|
|
|
export async function runAudioTranscription(params: {
|
|
ctx: MsgContext;
|
|
cfg: BotConfig;
|
|
attachments?: MediaAttachment[];
|
|
agentDir?: string;
|
|
providers?: Record<string, MediaUnderstandingProvider>;
|
|
activeModel?: ActiveMediaModel;
|
|
localPathRoots?: readonly string[];
|
|
}): Promise<{ transcript: string | undefined; attachments: MediaAttachment[] }> {
|
|
const attachments = params.attachments ?? normalizeMediaAttachments(params.ctx);
|
|
if (attachments.length === 0) {
|
|
return { transcript: undefined, attachments };
|
|
}
|
|
|
|
const providerRegistry = buildProviderRegistry(params.providers);
|
|
const cache = createMediaAttachmentCache(
|
|
attachments,
|
|
params.localPathRoots ? { localPathRoots: params.localPathRoots } : undefined,
|
|
);
|
|
|
|
try {
|
|
const result = await runCapability({
|
|
capability: "audio",
|
|
cfg: params.cfg,
|
|
ctx: params.ctx,
|
|
attachments: cache,
|
|
media: attachments,
|
|
agentDir: params.agentDir,
|
|
providerRegistry,
|
|
config: params.cfg.tools?.media?.audio,
|
|
activeModel: params.activeModel,
|
|
});
|
|
const output = result.outputs.find((entry) => entry.kind === "audio.transcription");
|
|
const transcript = output?.text?.trim();
|
|
return { transcript: transcript || undefined, attachments };
|
|
} finally {
|
|
await cache.cleanup();
|
|
}
|
|
}
|