Command Code dropped vision and ignored client effort through the router:
image blocks became "[image omitted]", HTTP image URLs were never inlined,
and reasoning_effort landed on the envelope wrapper instead of params (so the
DeepSeek family mapping remapped low -> high). The catalog also treated
deepseek/deepseek-v4.1-flash as text-only, so the vision adapter stole those
requests to another provider.
- Map OpenAI image_url / Claude image blocks (base64 or data-URI) to the
native {type:"image", image:"data:...;base64,...", mimeType} generate block.
- Add FORMATS.COMMANDCODE to TARGETS_NEED_BASE64 so remote http(s) images are
inlined by the existing SSRF-safe fetcher before translation.
- Write reasoning_effort inside params for targetFormat commandcode and pass
low|medium|high|xhigh|max through unmapped; allow it in thinkingLevels.
- Provider-scoped capabilities for commandcode/cmc: vision except the CLI
text-only denylist, thinkingFormat commandcode, so family patterns
(deepseek-v4 -> thinkingFormat deepseek, vision false) no longer win.
- Quota Tracker: whoami + billing credits/subscriptions (credits vs plan cap,
5h and weekly windows), labels from AI_PROVIDERS[].name.
76 lines
3.5 KiB
JavaScript
76 lines
3.5 KiB
JavaScript
import { describe, it, expect, vi, beforeEach, afterEach } from "vitest";
|
|
|
|
vi.mock("../../open-sse/translator/concerns/image.js", async (orig) => {
|
|
const actual = await orig();
|
|
return {
|
|
...actual,
|
|
fetchImageAsBase64: vi.fn(async () => ({ url: "data:image/png;base64,QUJD", mimeType: "image/png" })),
|
|
};
|
|
});
|
|
|
|
import { prefetchRemoteImages } from "../../open-sse/translator/concerns/prefetch.js";
|
|
import { fetchImageAsBase64 } from "../../open-sse/translator/concerns/image.js";
|
|
import { FORMATS } from "../../open-sse/translator/formats.js";
|
|
|
|
beforeEach(() => { fetchImageAsBase64.mockClear(); });
|
|
afterEach(() => { vi.restoreAllMocks(); });
|
|
|
|
describe("prefetchRemoteImages", () => {
|
|
it("no-op for targets that accept remote URLs (openai)", async () => {
|
|
const body = { messages: [{ role: "user", content: [{ type: "image_url", image_url: { url: "https://x/a.png" } }] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.OPENAI, FORMATS.OPENAI);
|
|
expect(n).toBe(0);
|
|
expect(body.messages[0].content[0].image_url.url).toBe("https://x/a.png");
|
|
});
|
|
|
|
it("openai source -> ollama target: converts remote URL to base64", async () => {
|
|
const body = { messages: [{ role: "user", content: [{ type: "image_url", image_url: { url: "https://x/a.png" } }] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.OPENAI, FORMATS.OLLAMA);
|
|
expect(n).toBe(1);
|
|
expect(body.messages[0].content[0].image_url.url.startsWith("data:image/png;base64,")).toBe(true);
|
|
});
|
|
|
|
it("skips data URI (already inline)", async () => {
|
|
const body = { messages: [{ role: "user", content: [{ type: "image_url", image_url: { url: "data:image/png;base64,xx" } }] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.OPENAI, FORMATS.OLLAMA);
|
|
expect(n).toBe(0);
|
|
expect(fetchImageAsBase64).not.toHaveBeenCalled();
|
|
});
|
|
|
|
it("gemini source -> gemini target: fileData URL -> inlineData base64", async () => {
|
|
const body = { contents: [{ role: "user", parts: [
|
|
{ fileData: { mimeType: "image/png", fileUri: "https://x/a.png" } },
|
|
] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.GEMINI, FORMATS.GEMINI);
|
|
expect(n).toBe(1);
|
|
expect(body.contents[0].parts[0].inlineData).toBeTruthy();
|
|
expect(body.contents[0].parts[0].fileData).toBeUndefined();
|
|
});
|
|
|
|
it("claude source -> kiro target: source.url -> base64", async () => {
|
|
const body = { messages: [{ role: "user", content: [
|
|
{ type: "image", source: { type: "url", url: "https://x/a.png" } },
|
|
] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.CLAUDE, FORMATS.KIRO);
|
|
expect(n).toBe(1);
|
|
expect(body.messages[0].content[0].source.type).toBe("base64");
|
|
});
|
|
|
|
it("openai source -> commandcode target: converts remote URL to base64", async () => {
|
|
const body = { messages: [{ role: "user", content: [{ type: "image_url", image_url: { url: "https://x/a.png" } }] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.OPENAI, FORMATS.COMMANDCODE);
|
|
expect(n).toBe(1);
|
|
expect(body.messages[0].content[0].image_url.url.startsWith("data:image/png;base64,")).toBe(true);
|
|
expect(fetchImageAsBase64).toHaveBeenCalled();
|
|
});
|
|
|
|
it("claude source -> commandcode target: source.url -> base64", async () => {
|
|
const body = { messages: [{ role: "user", content: [
|
|
{ type: "image", source: { type: "url", url: "https://x/a.png" } },
|
|
] }] };
|
|
const n = await prefetchRemoteImages(body, FORMATS.CLAUDE, FORMATS.COMMANDCODE);
|
|
expect(n).toBe(1);
|
|
expect(body.messages[0].content[0].source.type).toBe("base64");
|
|
});
|
|
});
|