Files
openclaw/extensions/anthropic/cli-catalog.ts
Peter Steinberger 4c210e22fa Adapt image compression quality by model (#85742)
* feat: adapt image compression quality

* refactor: move image limits into model metadata

* test: cover adaptive image downscaling

* test: cover image tool live providers

* fix: apply media metadata to all image paths

* fix: align providerless image compression

* fix: add chutes runtime image limits

* fix: optimize image data urls with model limits

* fix: type media metadata merge

* fix: optimize data url byte limits after decode

* fix: preserve data url optimizer fallback

* fix: keep low-side image compression fallbacks

* fix: enforce data url image compression policy

* fix: preserve gif data url media policy

* fix: satisfy adaptive image type checks

* test: keep cron provider-runtime mock current
2026-05-23 21:45:55 +01:00

52 lines
1.6 KiB
TypeScript

import type { ModelCatalogEntry } from "openclaw/plugin-sdk/agent-runtime";
import { CLAUDE_CLI_BACKEND_ID, CLAUDE_CLI_DEFAULT_ALLOWLIST_REFS } from "./cli-constants.js";
// Claude CLI auth is subscription-backed, so catalog rows only need picker metadata.
const CLAUDE_CLI_DEFAULT_CONTEXT_WINDOW = 200_000;
const CLAUDE_CLI_MODEL_LABELS: Record<string, string> = {
"claude-opus-4-7": "Claude Opus 4.7 (Claude CLI)",
"claude-opus-4-6": "Claude Opus 4.6 (Claude CLI)",
"claude-sonnet-4-6": "Claude Sonnet 4.6 (Claude CLI)",
};
function resolveClaudeCliImageMediaInput(id: string): ModelCatalogEntry["mediaInput"] {
const maxSidePx = id === "claude-opus-4-7" ? 2576 : 1568;
return {
image: {
maxSidePx,
preferredSidePx: maxSidePx,
tokenMode: "provider",
},
};
}
function extractClaudeCliModelIds(): string[] {
const ids: string[] = [];
const seen = new Set<string>();
for (const ref of CLAUDE_CLI_DEFAULT_ALLOWLIST_REFS) {
if (!ref.startsWith(`${CLAUDE_CLI_BACKEND_ID}/`)) {
continue;
}
const id = ref.slice(CLAUDE_CLI_BACKEND_ID.length + 1);
if (id.length === 0 || seen.has(id)) {
continue;
}
seen.add(id);
ids.push(id);
}
return ids;
}
export function buildClaudeCliCatalogEntries(): ModelCatalogEntry[] {
return extractClaudeCliModelIds().map((id) => ({
id,
name: CLAUDE_CLI_MODEL_LABELS[id] ?? `${id} (Claude CLI)`,
provider: CLAUDE_CLI_BACKEND_ID,
reasoning: true,
input: ["text", "image"],
mediaInput: resolveClaudeCliImageMediaInput(id),
contextWindow: CLAUDE_CLI_DEFAULT_CONTEXT_WINDOW,
}));
}