fix(regression): normalize image tool provider config aliases

This commit is contained in:
Tak Hoffman 2026-03-27 22:08:37 -05:00
parent 21136238ce
commit 8c60e4e9f9
No known key found for this signature in database
2 changed files with 38 additions and 3 deletions

View File

@ -1,5 +1,6 @@
import type { AssistantMessage } from "@mariozechner/pi-ai";
import type { OpenClawConfig } from "../../config/config.js";
import { findNormalizedProviderValue } from "../model-selection.js";
import { extractAssistantText } from "../pi-embedded-utils.js";
import { coerceToolModelConfig, type ToolModelConfig } from "./model-config.helpers.js";
@ -59,9 +60,10 @@ export function resolveProviderVisionModelFromConfig(params: {
cfg?: OpenClawConfig;
provider: string;
}): string | null {
const providerCfg = params.cfg?.models?.providers?.[params.provider] as unknown as
| { models?: Array<{ id?: string; input?: string[] }> }
| undefined;
const providerCfg = findNormalizedProviderValue(
params.cfg?.models?.providers,
params.provider,
) as unknown as { models?: Array<{ id?: string; input?: string[] }> } | undefined;
const models = providerCfg?.models ?? [];
const picked = models.find((m) => Boolean((m?.id ?? "").trim()) && m.input?.includes("image"));
const id = (picked?.id ?? "").trim();

View File

@ -591,6 +591,39 @@ describe("image tool implicit imageModel config", () => {
});
});
it("pairs a provider when config uses an alias key", async () => {
await withTempAgentDir(async (agentDir) => {
await writeAuthProfiles(agentDir, {
version: 1,
profiles: {
"amazon-bedrock:default": {
type: "api_key",
provider: "amazon-bedrock",
key: "sk-test",
},
},
});
const cfg: OpenClawConfig = {
agents: { defaults: { model: { primary: "aws-bedrock/text-1" } } },
models: {
providers: {
"amazon-bedrock": {
baseUrl: "https://example.com",
models: [
makeModelDefinition("text-1", ["text"]),
makeModelDefinition("vision-1", ["text", "image"]),
],
},
},
},
};
expect(resolveImageModelConfigForTool({ cfg, agentDir })).toEqual({
primary: "amazon-bedrock/vision-1",
});
expect(createImageTool({ config: cfg, agentDir })).not.toBeNull();
});
});
it("prefers explicit agents.defaults.imageModel", async () => {
await withTempAgentDir(async (agentDir) => {
const cfg: OpenClawConfig = {