fix(server): preprocess oversized images before sending to agent SDK#820
Open
caoer wants to merge 4 commits into
Open
fix(server): preprocess oversized images before sending to agent SDK#820caoer wants to merge 4 commits into
caoer wants to merge 4 commits into
Conversation
The Claude Agent SDK resizes images >2000x2000 using sharp internally, but sharp may fail to load in the spawned CLI process, causing a "[System Error] Unable to resize image" error. Resize images in the daemon's session layer (where sharp is available from the hoisted SDK dependency) before dispatching to any provider. Gracefully falls back to sending the original if sharp is unavailable.
7ec394c to
5c90449
Compare
…fort - Make sharp import non-static (variable module name) so TypeScript doesn't try to resolve it as a dependency at typecheck time - Map xhigh thinking effort to SDK-accepted "high" value via SDK_EFFORT_MAP since the Agent SDK only accepts low/medium/high/max
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
[System Error] Unable to resize image — dimensions exceed the 2000x2000px limit and image processing failederrorpreprocessImages()step in the daemon's session layer that resizes oversized images before dispatching to any agent provider — sharp is available in the daemon process from the hoisted SDK dependencyChanges
packages/server/src/server/agent/preprocess-image.ts— New utility: dynamically imports sharp, checks image dimensions, resizes to fit within 2000×2000 (preserving aspect ratio) and re-encodes as JPEG quality 80packages/server/src/server/agent/preprocess-image.test.ts— Tests: small images pass through unchanged, oversized images get resized with correct aspect ratio, corrupt data handled gracefullypackages/server/src/server/session.ts— BothhandleSendAgentMessage()and thesend_agent_message_requesthandler now callpreprocessImages()beforebuildAgentPrompt()Test plan
[System Error]