diff --git a/src/media-understanding/runner.attachments.ts b/src/media-understanding/runner.attachments.ts new file mode 100644 index 00000000000..b64804b8cfc --- /dev/null +++ b/src/media-understanding/runner.attachments.ts @@ -0,0 +1,18 @@ +import type { MsgContext } from "../auto-reply/templating.js"; +import { + MediaAttachmentCache, + type MediaAttachmentCacheOptions, + normalizeAttachments, +} from "./attachments.js"; +import type { MediaAttachment } from "./types.js"; + +export function normalizeMediaAttachments(ctx: MsgContext): MediaAttachment[] { + return normalizeAttachments(ctx); +} + +export function createMediaAttachmentCache( + attachments: MediaAttachment[], + options?: MediaAttachmentCacheOptions, +): MediaAttachmentCache { + return new MediaAttachmentCache(attachments, options); +} diff --git a/src/media-understanding/runner.skip-tiny-audio.test.ts b/src/media-understanding/runner.skip-tiny-audio.test.ts index a4021fb52a8..127b5546f22 100644 --- a/src/media-understanding/runner.skip-tiny-audio.test.ts +++ b/src/media-understanding/runner.skip-tiny-audio.test.ts @@ -5,12 +5,8 @@ import { describe, expect, it } from "vitest"; import type { MsgContext } from "../auto-reply/templating.js"; import type { OpenClawConfig } from "../config/config.js"; import { MIN_AUDIO_FILE_BYTES } from "./defaults.js"; -import { - buildProviderRegistry, - createMediaAttachmentCache, - normalizeMediaAttachments, - runCapability, -} from "./runner.js"; +import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js"; +import { buildProviderRegistry, runCapability } from "./runner.js"; import type { AudioTranscriptionRequest } from "./types.js"; async function withAudioFixture(params: { diff --git a/src/media-understanding/runner.test-utils.ts b/src/media-understanding/runner.test-utils.ts index 086418f049d..8b86b97b805 100644 --- a/src/media-understanding/runner.test-utils.ts +++ b/src/media-understanding/runner.test-utils.ts @@ -3,7 +3,7 @@ import os from "node:os"; import path from "node:path"; import { withEnvAsync } from "../test-utils/env.js"; import { MIN_AUDIO_FILE_BYTES } from "./defaults.js"; -import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.js"; +import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js"; type MediaFixtureParams = { ctx: { MediaPath: string; MediaType: string }; diff --git a/src/media-understanding/runner.ts b/src/media-understanding/runner.ts index fa9a7379e23..7eb82cacf43 100644 --- a/src/media-understanding/runner.ts +++ b/src/media-understanding/runner.ts @@ -25,12 +25,7 @@ import { } from "../media/inbound-path-policy.js"; import { getDefaultMediaLocalRoots } from "../media/local-roots.js"; import { runExec } from "../process/exec.js"; -import { - MediaAttachmentCache, - type MediaAttachmentCacheOptions, - normalizeAttachments, - selectAttachments, -} from "./attachments.js"; +import { MediaAttachmentCache, selectAttachments } from "./attachments.js"; import { AUTO_AUDIO_KEY_PROVIDERS, AUTO_IMAGE_KEY_PROVIDERS, @@ -60,6 +55,7 @@ import type { MediaUnderstandingOutput, MediaUnderstandingProvider, } from "./types.js"; +export { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js"; export type ActiveMediaModel = { provider: string; @@ -80,10 +76,6 @@ export function buildProviderRegistry( return buildMediaUnderstandingRegistry(overrides, cfg); } -export function normalizeMediaAttachments(ctx: MsgContext): MediaAttachment[] { - return normalizeAttachments(ctx); -} - export function resolveMediaAttachmentLocalRoots(params: { cfg: OpenClawConfig; ctx: MsgContext; @@ -97,13 +89,6 @@ export function resolveMediaAttachmentLocalRoots(params: { ); } -export function createMediaAttachmentCache( - attachments: MediaAttachment[], - options?: MediaAttachmentCacheOptions, -): MediaAttachmentCache { - return new MediaAttachmentCache(attachments, options); -} - const binaryCache = new Map>(); const geminiProbeCache = new Map>(); diff --git a/src/media-understanding/runner.vision-skip.test.ts b/src/media-understanding/runner.vision-skip.test.ts index c671e8202ff..ba227510737 100644 --- a/src/media-understanding/runner.vision-skip.test.ts +++ b/src/media-understanding/runner.vision-skip.test.ts @@ -10,6 +10,7 @@ import { __testing as loaderTesting } from "../plugins/loader.js"; import { loadPluginManifestRegistry } from "../plugins/manifest-registry.js"; import { createEmptyPluginRegistry } from "../plugins/registry.js"; import { setActivePluginRegistry } from "../plugins/runtime.js"; +import { createMediaAttachmentCache, normalizeMediaAttachments } from "./runner.attachments.js"; const catalog = [ { @@ -33,8 +34,6 @@ vi.mock("../agents/model-catalog.js", async () => { }); let buildProviderRegistry: typeof import("./runner.js").buildProviderRegistry; -let createMediaAttachmentCache: typeof import("./runner.js").createMediaAttachmentCache; -let normalizeMediaAttachments: typeof import("./runner.js").normalizeMediaAttachments; let resolveAutoImageModel: typeof import("./runner.js").resolveAutoImageModel; let runCapability: typeof import("./runner.js").runCapability; @@ -73,13 +72,16 @@ function setCompatibleActiveMediaUnderstandingRegistry( describe("runCapability image skip", () => { beforeAll(async () => { - ({ - buildProviderRegistry, - createMediaAttachmentCache, - normalizeMediaAttachments, - resolveAutoImageModel, - runCapability, - } = await import("./runner.js")); + vi.doMock("../agents/model-catalog.js", async () => { + const actual = await vi.importActual( + "../agents/model-catalog.js", + ); + return { + ...actual, + loadModelCatalog, + }; + }); + ({ buildProviderRegistry, resolveAutoImageModel, runCapability } = await import("./runner.js")); }); beforeEach(() => {