Skip to content

Comments

feat(input): provide convenience constructors for image input segments#24

Merged
activadee merged 5 commits intomainfrom
codex/provide-convenience-constructors-that-create-image-input-segments-42
Nov 6, 2025
Merged

feat(input): provide convenience constructors for image input segments#24
activadee merged 5 commits intomainfrom
codex/provide-convenience-constructors-that-create-image-input-segments-42

Conversation

@activadee
Copy link
Owner

@activadee activadee commented Nov 6, 2025

Summary

  • Add convenience constructors to create image input segments from URLs and in-memory bytes, with automatic temp-file handling and cleanup.

Changes

  • feat(input):
    • Add URLImageSegment to download an image, validate Content-Type, and store in a temp file.
    • Add BytesImageSegment to write provided bytes to a temp file with an appropriate extension.
    • Extend InputSegment with an internal cleanup hook; update normalizeInput to collect and expose a cleanup function.
  • fix(thread):
    • Ensure temporary image files are always cleaned up in streamed runs (on error and on completion).
  • test(input):
    • Add tests for URLImageSegment, BytesImageSegment, and cleanup behavior.
  • docs(readme):
    • Rename section and document the new constructors with examples.

Notes

  • Backwards compatible: existing TextSegment and LocalImageSegment usage remains unchanged.
  • Temporary files created by the helpers are cleaned automatically after each run.

closes #12

activadee added 4 commits November 6, 2025 20:26
…RLImageSegment and BytesImageSegment\n- Write temp image files with automatic cleanup\n- Extend InputSegment with cleanup hook\n- Update normalizeInput to collect cleanups and expose a cleanup function
…pared.cleanup() on error and via defer to avoid leaking temp files\n- Rename schema cleanup var to avoid shadowing and ensure proper ordering
…behavior\n\n- Download and cleanup test using httptest server\n- Validate non-image content-type is rejected\n- Ensure bytes segment picks a .png extension and cleans up
…e\n\n- Rename section to include remote and in-memory images\n- Add examples for URLImageSegment and BytesImageSegment with cleanup behavior explained
input.go Outdated
return InputSegment{}, fmt.Errorf("download image: content-type %q is not an image", mediaType)
}

data, err := io.ReadAll(resp.Body)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

URLImageSegment currently slurps the entire response into memory via io.ReadAll. Because the helper is intended for arbitrary remote URLs, a large or malicious server response can easily exhaust memory and make the process unstable. Please stream the download to disk (or at least cap the bytes you buffer up front for type sniffing) instead of reading the full body into RAM.

@github-actions
Copy link
Contributor

github-actions bot commented Nov 6, 2025

Codex Review Summary

Recommendation: ✅ Ready to merge – no blocking issues detected.

Summary:
No issues found. The new streaming download path enforces the 8 MiB cap safely using an io.LimitedReader, verifies the Content-Type before writing, and streams into the temp file without buffering the full payload in memory. The validator cleanup logic removes partial files when the size check fails, and the added test covers the size-limit branch. I’m confident in the change after tracing the limit/cleanup flow and ensuring existing nil-body safeguards remain intact.

Inline findings:

  • No inline findings.

Generated at 2025-11-06T19:43:29.925Z.

@activadee activadee merged commit d7e9d37 into main Nov 6, 2025
2 checks passed
@activadee activadee deleted the codex/provide-convenience-constructors-that-create-image-input-segments-42 branch November 6, 2025 19:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

SDK DX: image input helpers (URLImageSegment, BytesImageSegment)

1 participant