mirror of
https://github.com/openclaw/openclaw.git
synced 2026-03-12 07:20:45 +00:00
fix(agents): prevent /v1beta duplication in Gemini PDF URL (#34369)
Strip trailing /v1beta from baseUrl before appending the version segment, so callers that already include /v1beta in their base URL (e.g. subagent-registry) no longer produce /v1beta/v1beta/models/… which results in a 404 from the Gemini API. Closes #34312 Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -137,10 +137,9 @@ export async function geminiAnalyzePdf(params: {
|
||||
}
|
||||
parts.push({ text: params.prompt });
|
||||
|
||||
const baseUrl = (params.baseUrl ?? "https://generativelanguage.googleapis.com").replace(
|
||||
/\/+$/,
|
||||
"",
|
||||
);
|
||||
const baseUrl = (params.baseUrl ?? "https://generativelanguage.googleapis.com")
|
||||
.replace(/\/+$/, "")
|
||||
.replace(/\/v1beta$/, "");
|
||||
const url = `${baseUrl}/v1beta/models/${encodeURIComponent(params.modelId)}:generateContent?key=${encodeURIComponent(apiKey)}`;
|
||||
|
||||
const res = await fetch(url, {
|
||||
|
||||
@@ -711,6 +711,26 @@ describe("native PDF provider API calls", () => {
|
||||
"apiKey required",
|
||||
);
|
||||
});
|
||||
|
||||
it("geminiAnalyzePdf does not duplicate /v1beta when baseUrl already includes it", async () => {
|
||||
const { geminiAnalyzePdf } = await import("./pdf-native-providers.js");
|
||||
const fetchMock = mockFetchResponse({
|
||||
ok: true,
|
||||
json: async () => ({
|
||||
candidates: [{ content: { parts: [{ text: "ok" }] } }],
|
||||
}),
|
||||
});
|
||||
|
||||
await geminiAnalyzePdf(
|
||||
makeGeminiAnalyzeParams({
|
||||
baseUrl: "https://generativelanguage.googleapis.com/v1beta",
|
||||
}),
|
||||
);
|
||||
|
||||
const [url] = fetchMock.mock.calls[0];
|
||||
expect(url).toContain("/v1beta/models/");
|
||||
expect(url).not.toContain("/v1beta/v1beta");
|
||||
});
|
||||
});
|
||||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
Reference in New Issue
Block a user