Agent: document 2000px image downscale
This commit is contained in:
@@ -140,6 +140,8 @@ async function sanitizeSessionMessagesImages(
|
|||||||
messages: AppMessage[],
|
messages: AppMessage[],
|
||||||
label: string,
|
label: string,
|
||||||
): Promise<AppMessage[]> {
|
): Promise<AppMessage[]> {
|
||||||
|
// We sanitize historical session messages because Anthropic can reject a request
|
||||||
|
// if the transcript contains oversized base64 images (see MAX_IMAGE_DIMENSION_PX).
|
||||||
const out: AppMessage[] = [];
|
const out: AppMessage[] = [];
|
||||||
for (const msg of messages) {
|
for (const msg of messages) {
|
||||||
if (!msg || typeof msg !== "object") {
|
if (!msg || typeof msg !== "object") {
|
||||||
|
|||||||
@@ -11,6 +11,12 @@ type ToolContentBlock = AgentToolResult<unknown>["content"][number];
|
|||||||
type ImageContentBlock = Extract<ToolContentBlock, { type: "image" }>;
|
type ImageContentBlock = Extract<ToolContentBlock, { type: "image" }>;
|
||||||
type TextContentBlock = Extract<ToolContentBlock, { type: "text" }>;
|
type TextContentBlock = Extract<ToolContentBlock, { type: "text" }>;
|
||||||
|
|
||||||
|
// Anthropic Messages API limitation (observed in Clawdis sessions):
|
||||||
|
// When sending many images in a single request (e.g. via session history + tool results),
|
||||||
|
// Anthropic rejects any image where *either* dimension exceeds 2000px.
|
||||||
|
//
|
||||||
|
// To keep sessions resilient (and avoid "silent" WhatsApp non-replies), we auto-downscale
|
||||||
|
// all base64 image blocks above this limit while preserving aspect ratio.
|
||||||
const MAX_IMAGE_DIMENSION_PX = 2000;
|
const MAX_IMAGE_DIMENSION_PX = 2000;
|
||||||
|
|
||||||
function sniffMimeFromBase64(base64: string): string | undefined {
|
function sniffMimeFromBase64(base64: string): string | undefined {
|
||||||
|
|||||||
Reference in New Issue
Block a user