mirror of
https://github.com/diegosouzapw/OmniRoute.git
synced 2026-11-22 04:19:40 +00:00
fix(qoder): count an image nested in a Claude tool_result as image input
hasQoderImageParts only read top-level content parts, so a Claude request whose only image sat inside a tool_result (and that declared no tools) did not require the HTTP transport, and selection could pick a PAT connection.
This commit is contained in:
@@ -20,6 +20,17 @@ export function qoderSupportsCallerTools(credentials: QoderCredentials): boolean
|
||||
/** Image parts as the Chat Completions, Responses and Claude-style content arrays name them. */
|
||||
const QODER_IMAGE_PART_TYPES = new Set(["image_url", "input_image", "image"]);
|
||||
|
||||
/** A Claude `tool_result` can carry image blocks in its nested `content` array. */
|
||||
function isQoderImagePart(part: unknown): boolean {
|
||||
const record = part as Record<string, unknown> | null;
|
||||
if (QODER_IMAGE_PART_TYPES.has(String(record?.type))) return true;
|
||||
return (
|
||||
record?.type === "tool_result" &&
|
||||
Array.isArray(record.content) &&
|
||||
record.content.some(isQoderImagePart)
|
||||
);
|
||||
}
|
||||
|
||||
/** The qodercli prompt is text only, so an image part cannot reach the model on a PAT connection. */
|
||||
export function hasQoderImageParts(body: unknown): boolean {
|
||||
if (!body || typeof body !== "object") return false;
|
||||
@@ -29,12 +40,7 @@ export function hasQoderImageParts(body: unknown): boolean {
|
||||
Array.isArray(turns) &&
|
||||
turns.some((turn) => {
|
||||
const content = (turn as Record<string, unknown> | null)?.content;
|
||||
return (
|
||||
Array.isArray(content) &&
|
||||
content.some((part) =>
|
||||
QODER_IMAGE_PART_TYPES.has(String((part as Record<string, unknown> | null)?.type))
|
||||
)
|
||||
);
|
||||
return Array.isArray(content) && content.some(isQoderImagePart);
|
||||
})
|
||||
);
|
||||
}
|
||||
|
||||
@@ -15,7 +15,8 @@ const core = await import("../../src/lib/db/core.ts");
|
||||
const { createProviderConnection, deleteProviderConnectionsByProvider } =
|
||||
await import("../../src/lib/db/providers.ts");
|
||||
const { QoderExecutor } = await import("../../open-sse/executors/qoder.ts");
|
||||
const { hasQoderImageParts } = await import("../../open-sse/services/qoderCapabilities.ts");
|
||||
const { hasQoderImageParts, requiresQoderHttpTransport } =
|
||||
await import("../../open-sse/services/qoderCapabilities.ts");
|
||||
|
||||
// Built from parts: a literal token-shaped string would trip secret scanners.
|
||||
const PAT = ["pt", "image", "fixture"].join("-");
|
||||
@@ -63,6 +64,32 @@ test("image parts are found in messages and in Responses-style input, plain text
|
||||
assert.equal(hasQoderImageParts({ messages: [null, "x", { content: null }] }), false);
|
||||
});
|
||||
|
||||
test("an image nested in a Claude tool_result needs the HTTP transport even without tools", () => {
|
||||
const body = {
|
||||
messages: [
|
||||
{
|
||||
role: "user",
|
||||
content: [
|
||||
{
|
||||
type: "tool_result",
|
||||
tool_use_id: "toolu_1",
|
||||
content: [
|
||||
{ type: "text", text: "screenshot" },
|
||||
{ type: "image", source: { type: "base64", media_type: "image/png", data: "AAAA" } },
|
||||
],
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
};
|
||||
assert.equal(hasQoderImageParts(body), true);
|
||||
// chat.ts passes this predicate as requireToolCalling, which drops PAT connections.
|
||||
assert.equal(requiresQoderHttpTransport(body), true);
|
||||
const textOnly = structuredClone(body);
|
||||
textOnly.messages[0].content[0].content = [{ type: "text", text: "screenshot" }];
|
||||
assert.equal(requiresQoderHttpTransport(textOnly), false);
|
||||
});
|
||||
|
||||
test("PAT executor rejects image input with a 400 before it launches the local CLI", async () => {
|
||||
await withStubCli(async (marker) => {
|
||||
const { response } = await new QoderExecutor().execute({
|
||||
|
||||
Reference in New Issue
Block a user