Add MIME hints to provider-file attachments (FIG-616 item 2)#133
Merged
Conversation
Carry optional validated media types through core and remote provider-file attachments. Anthropic uses the hint to select image or document file blocks and rejects missing hints before transport, while OpenAI and Google continue resolving file types server-side. Release-Notes: Breaking: Provider-file attachments now carry an optional media type, and Anthropic provider file ids require that hint so Lash can choose the image or document modality.
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.
AttachmentSource::ProviderFilewas the only variant carrying no MIME (Inline,ExternalUrlandStored'sAttachmentRefall have one). Becausesource.media_type()returnedNonefor it, the Anthropic adapter had an early return hardcoding adocumentblock — so an image file id produced a wire error or the wrong modality, since Anthropic requires image file ids in animageblock.Design (grilled and ratified)
media_type: Option<MediaType>— optional, not required. Verified that only Anthropic needs it: OpenAI validates the provider scope and emits by file id, Google emits{"fileData":{"fileUri":id}}; both resolve the type server-side. Requiring it would tax the two providers that never consume it and invite invented values.MediaTypeis deliberately a validated newtype overString("Lash deliberately does not maintain a closed media catalog", FIG-564), and a closed catalog would contradict that and need a lash release per new provider MIME.documentearly return is gone; provider file ids now flow through the normalis_image()dispatch. When the hint is absent it fails before the network (provider_file_media_type_required, Validation kind) rather than silently guessingdocument— unknown stays representable for the providers that don't care, but can never produce the wrong modality.Verification
Type size 104 B, under the existing
size_of <= 128compile-time ceiling (unchanged). Serde omits the field whenNone, so existing payloads deserialize; core↔remote round-trip preserves bothSomeandNone. Tests cover image/document block selection, the absent-hint refusal, and serde compatibility — independently re-run, 12/12 green. OpenAI and Google behaviour unchanged.Breaking at source level only: the
provider_filehelper gains a third argument and direct enum construction gains a field; serialized payloads are unaffected.Closes FIG-616 item 2. Item 3 was separately ratified as keep all 12 OpenAI MIMEs — OpenAI's live docs disprove the PDF-centric premise, and our list is in fact a subset of what they accept.