mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-08 10:01:24 +00:00
refactor(core): dedupe infra, media, pairing, and plugin helpers
This commit is contained in:
@@ -89,6 +89,21 @@ describe("resolveEntriesWithActiveFallback", () => {
|
||||
});
|
||||
}
|
||||
|
||||
function expectResolvedProviders(params: {
|
||||
cfg: OpenClawConfig;
|
||||
capability: ResolveWithFallbackInput["capability"];
|
||||
config: ResolveWithFallbackInput["config"];
|
||||
providers: string[];
|
||||
}) {
|
||||
const entries = resolveWithActiveFallback({
|
||||
cfg: params.cfg,
|
||||
capability: params.capability,
|
||||
config: params.config,
|
||||
});
|
||||
expect(entries).toHaveLength(params.providers.length);
|
||||
expect(entries.map((entry) => entry.provider)).toEqual(params.providers);
|
||||
}
|
||||
|
||||
it("uses active model when enabled and no models are configured", () => {
|
||||
const cfg: OpenClawConfig = {
|
||||
tools: {
|
||||
@@ -98,13 +113,12 @@ describe("resolveEntriesWithActiveFallback", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const entries = resolveWithActiveFallback({
|
||||
expectResolvedProviders({
|
||||
cfg,
|
||||
capability: "audio",
|
||||
config: cfg.tools?.media?.audio,
|
||||
providers: ["groq"],
|
||||
});
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0]?.provider).toBe("groq");
|
||||
});
|
||||
|
||||
it("ignores active model when configured entries exist", () => {
|
||||
@@ -116,13 +130,12 @@ describe("resolveEntriesWithActiveFallback", () => {
|
||||
},
|
||||
};
|
||||
|
||||
const entries = resolveWithActiveFallback({
|
||||
expectResolvedProviders({
|
||||
cfg,
|
||||
capability: "audio",
|
||||
config: cfg.tools?.media?.audio,
|
||||
providers: ["openai"],
|
||||
});
|
||||
expect(entries).toHaveLength(1);
|
||||
expect(entries[0]?.provider).toBe("openai");
|
||||
});
|
||||
|
||||
it("skips active model when provider lacks capability", () => {
|
||||
|
||||
@@ -400,33 +400,21 @@ export async function runProviderEntry(params: {
|
||||
timeoutMs,
|
||||
});
|
||||
const provider = getMediaUnderstandingProvider(providerId, params.providerRegistry);
|
||||
const result = provider?.describeImage
|
||||
? await provider.describeImage({
|
||||
buffer: media.buffer,
|
||||
fileName: media.fileName,
|
||||
mime: media.mime,
|
||||
model: modelId,
|
||||
provider: providerId,
|
||||
prompt,
|
||||
timeoutMs,
|
||||
profile: entry.profile,
|
||||
preferredProfile: entry.preferredProfile,
|
||||
agentDir: params.agentDir,
|
||||
cfg: params.cfg,
|
||||
})
|
||||
: await describeImageWithModel({
|
||||
buffer: media.buffer,
|
||||
fileName: media.fileName,
|
||||
mime: media.mime,
|
||||
model: modelId,
|
||||
provider: providerId,
|
||||
prompt,
|
||||
timeoutMs,
|
||||
profile: entry.profile,
|
||||
preferredProfile: entry.preferredProfile,
|
||||
agentDir: params.agentDir,
|
||||
cfg: params.cfg,
|
||||
});
|
||||
const imageInput = {
|
||||
buffer: media.buffer,
|
||||
fileName: media.fileName,
|
||||
mime: media.mime,
|
||||
model: modelId,
|
||||
provider: providerId,
|
||||
prompt,
|
||||
timeoutMs,
|
||||
profile: entry.profile,
|
||||
preferredProfile: entry.preferredProfile,
|
||||
agentDir: params.agentDir,
|
||||
cfg: params.cfg,
|
||||
};
|
||||
const describeImage = provider?.describeImage ?? describeImageWithModel;
|
||||
const result = await describeImage(imageInput);
|
||||
return {
|
||||
kind: "image.description",
|
||||
attachmentIndex: params.attachmentIndex,
|
||||
|
||||
Reference in New Issue
Block a user