Skip to content

feat: Phase 1 attachment system – chat.Document, pkg/attachment, per-provider convertDocument#2639

Open
simonferquel-clanker wants to merge 2 commits intodocker:mainfrom
simonferquel-clanker:feat/phase1-attachment-system
Open

feat: Phase 1 attachment system – chat.Document, pkg/attachment, per-provider convertDocument#2639
simonferquel-clanker wants to merge 2 commits intodocker:mainfrom
simonferquel-clanker:feat/phase1-attachment-system

Conversation

@simonferquel-clanker
Copy link
Copy Markdown
Contributor

Summary

Implements Phase 1 of the structured attachment system. Part of #2595.

What's added

pkg/chat/document.go (new)

  • MessagePartTypeDocument constant
  • DocumentSource struct (InlineText / InlineData / URL fields)
  • Document struct (Name, MimeType, Size, Source)
  • Document *Document field added to MessagePart
  • Deprecated MessagePartTypeFile, MessagePartTypeImageURL, and their corresponding fields with godoc comments

pkg/attachment/ (new package)

  • attachment.go: Strategy type, Decide() routing function, TXTEnvelope() helper, Advisor interface
  • modelcaps/modelcaps.go: ModelCapabilities backed by models.dev data (via pkg/modelsdev store); Supports(mimeType) checks image/vision and PDF capability; text/* always allowed

Per-provider attachments.go (new files)

Added convertDocument(ctx, doc, modelID) and SupportedMIMETypes() to:

  • pkg/model/provider/oaistream — image → data-URI image part; other binary → TXT envelope fallback; wired into ConvertMultiContent
  • pkg/model/provider/openai — same via ResponseInputContentUnionParam for the Responses API
  • pkg/model/provider/anthropic — image → BetaImageBlockParam (base64); PDF → BetaRequestDocumentBlock; text → BetaTextBlockParam envelope
  • pkg/model/provider/gemini — binary → genai.Blob; text → genai.Text envelope
  • pkg/model/provider/bedrock — image → ContentBlockMemberImage; PDF → ContentBlockMemberDocument; text → ContentBlockMemberText envelope

Signature changes

ConvertMessages and ConvertMultiContent in oaistream now accept a modelID string parameter 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-miss
  • pkg/attachment/modelcaps/modelcaps_test.go — in-memory store, vision/text-only/unknown model cases
  • Per-provider attachments_test.go — TXT strategy, Drop strategy, envelope format verified

What's NOT changed

  • Existing MessagePartTypeFile and MessagePartTypeImageURL handling is preserved unchanged (just deprecated with comments)
  • No config schema changes (Phase 1 is API-only)

Part of #2595

…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
@simonferquel-clanker simonferquel-clanker requested a review from a team as a code owner May 5, 2026 14:08
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
@docker-agent
Copy link
Copy Markdown

docker-agent Bot commented May 5, 2026

PR Review Failed — The review agent encountered an error and could not complete the review. View logs.

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.

1 participant