feat: Phase 1 attachment system – chat.Document, pkg/attachment, per-provider convertDocument#2639
Open
simonferquel-clanker wants to merge 2 commits intodocker:mainfrom
Open
Conversation
…provider convertDocument Implements Phase 1 of the attachment system per spec: - pkg/chat/document.go: Document, DocumentSource types; MessagePartTypeDocument const - pkg/chat/chat.go: Document field added to MessagePart; deprecated old ImageURL/File fields - pkg/attachment/attachment.go: Decide(), TXTEnvelope(), Advisor interface - pkg/attachment/modelcaps/modelcaps.go: ModelCapabilities.Supports() backed by models.dev data - Per-provider convertDocument and SupportedMIMETypes in: - pkg/model/provider/oaistream (+ backward-compat wrappers for ConvertMessages/ConvertMultiContent) - pkg/model/provider/openai (Responses API) - pkg/model/provider/anthropic (Beta API) - pkg/model/provider/gemini - pkg/model/provider/bedrock - Full test coverage: decide_test.go, modelcaps_test.go, per-provider attachments_test.go Part of docker#2595 Assisted-By: docker-agent
Blockers fixed: - B1: Replace // Deprecated: godoc tags with // Note: superseded comments to avoid SA1019 staticcheck errors on all in-tree call sites - B2: Replace context.Background() with t.Context() in all 5 provider attachments_test.go files (also fixed in bedrock/client_test.go and gemini/client_test.go) - B3: Fix gci import ordering in decide_test.go and chat.go (golangci-lint --fix) - B4: Add B64 success-path tests to all 5 providers using convertDocumentWithCaps injection helper; image+PDF cases verified with native block assertions Suggestions addressed: - S5: Delete ConvertMessagesLegacy/ConvertMultiContentLegacy (no callers) - S7: Add convertDocumentWithCaps injection variants in all 5 providers - S10: Thread request ctx through ConvertMultiContent, ConvertMessages, and convertMessagesToResponseInput instead of using context.Background() - S13: Add TODO(phase2) and stronger constraint comment to DocumentSource.URL Assisted-By: docker-agent
|
❌ PR Review Failed — The review agent encountered an error and could not complete the review. View logs. |
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
Implements Phase 1 of the structured attachment system. Part of #2595.
What's added
pkg/chat/document.go(new)MessagePartTypeDocumentconstantDocumentSourcestruct (InlineText / InlineData / URL fields)Documentstruct (Name, MimeType, Size, Source)Document *Documentfield added toMessagePartMessagePartTypeFile,MessagePartTypeImageURL, and their corresponding fields with godoc commentspkg/attachment/(new package)attachment.go:Strategytype,Decide()routing function,TXTEnvelope()helper,Advisorinterfacemodelcaps/modelcaps.go:ModelCapabilitiesbacked by models.dev data (viapkg/modelsdevstore);Supports(mimeType)checks image/vision and PDF capability; text/* always allowedPer-provider
attachments.go(new files)Added
convertDocument(ctx, doc, modelID)andSupportedMIMETypes()to:pkg/model/provider/oaistream— image → data-URI image part; other binary → TXT envelope fallback; wired intoConvertMultiContentpkg/model/provider/openai— same viaResponseInputContentUnionParamfor the Responses APIpkg/model/provider/anthropic— image →BetaImageBlockParam(base64); PDF →BetaRequestDocumentBlock; text →BetaTextBlockParamenvelopepkg/model/provider/gemini— binary →genai.Blob; text →genai.Textenvelopepkg/model/provider/bedrock— image →ContentBlockMemberImage; PDF →ContentBlockMemberDocument; text →ContentBlockMemberTextenvelopeSignature changes
ConvertMessagesandConvertMultiContentinoaistreamnow accept amodelID stringparameter for capability routing. Backward-compat aliases (ConvertMessagesLegacy,ConvertMultiContentLegacy) added for any external consumers.Tests
pkg/attachment/decide_test.go— table-driven, all 3 strategy outcomes + MIME-misspkg/attachment/modelcaps/modelcaps_test.go— in-memory store, vision/text-only/unknown model casesattachments_test.go— TXT strategy, Drop strategy, envelope format verifiedWhat's NOT changed
MessagePartTypeFileandMessagePartTypeImageURLhandling is preserved unchanged (just deprecated with comments)Part of #2595