mirror of
https://github.com/openclaw/openclaw.git
synced 2026-04-05 22:32:12 +00:00
refactor: trim media understanding runner test imports
This commit is contained in:
committed by
Peter Steinberger
parent
19493b681d
commit
25e9ff01cf
18
src/media-understanding/runner.attachments.ts
Normal file
18
src/media-understanding/runner.attachments.ts
Normal file
@@ -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);
|
||||
}
|
||||
@@ -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: {
|
||||
|
||||
@@ -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 };
|
||||
|
||||
@@ -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<string, Promise<string | null>>();
|
||||
const geminiProbeCache = new Map<string, Promise<boolean>>();
|
||||
|
||||
|
||||
@@ -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<typeof import("../agents/model-catalog.js")>(
|
||||
"../agents/model-catalog.js",
|
||||
);
|
||||
return {
|
||||
...actual,
|
||||
loadModelCatalog,
|
||||
};
|
||||
});
|
||||
({ buildProviderRegistry, resolveAutoImageModel, runCapability } = await import("./runner.js"));
|
||||
});
|
||||
|
||||
beforeEach(() => {
|
||||
|
||||
Reference in New Issue
Block a user