Skip to content

[Capability] Preserve optional content fields in PromptResultFormatter - #406

Open
chr-hertel wants to merge 2 commits into
mainfrom
prompt-formatter-optional-fields
Open

[Capability] Preserve optional content fields in PromptResultFormatter#406
chr-hertel wants to merge 2 commits into
mainfrom
prompt-formatter-optional-fields

Conversation

@chr-hertel

@chr-hertel chr-hertel commented Jul 27, 2026

Copy link
Copy Markdown
Member

PromptResultFormatter rebuilt typed content arrays from only their required fields, silently dropping annotations (all types) and _meta/explicit mimeType (embedded resources). It now delegates to the schema classes' fromArray(), keeping the historical mimeType defaulting and error contract. Also adds annotations support to ImageContent for parity with the other content types.

Noticed while reviewing #400

🤖 Generated with Claude Code

The formatter's typed-content path rebuilt each Content object from only
its required fields, silently dropping everything else a prompt returned
(annotations on every type, _meta and explicit mimeType on embedded
resource contents). Delegate to the schema classes' fromArray() instead,
keeping the historical mimeType defaulting and RuntimeException-with-
index error contract.

ImageContent was the only content class without annotations support, so
it gains the same constructor/fromArray()/jsonSerialize() handling as
TextContent and AudioContent.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
@chr-hertel chr-hertel added this to the 0.8.0 milestone Jul 27, 2026
@chr-hertel chr-hertel added bug Something isn't working enhancement Request for a new feature that's not currently supported labels Jul 27, 2026
@chr-hertel chr-hertel added the needs review PR needs code review by maintainer label Aug 10, 2026
@chr-hertel
chr-hertel requested a balanced review from Copilot August 10, 2026 23:44

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Preserves optional typed-content fields when formatting prompt results and adds annotation support to images.

Changes:

  • Delegates typed-array conversion to schema classes.
  • Adds ImageContent annotations and serialization.
  • Adds regression tests and changelog entries.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
src/Capability/Formatter/PromptResultFormatter.php Preserves optional content fields during formatting.
src/Schema/Content/ImageContent.php Adds image annotations support.
tests/Unit/Capability/Formatter/PromptResultFormatterTest.php Tests field preservation and errors.
tests/Unit/Schema/Content/ImageContentTest.php Tests image annotation behavior.
CHANGELOG.md Documents the changes.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment thread src/Capability/Formatter/PromptResultFormatter.php
Comment thread src/Capability/Formatter/PromptResultFormatter.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working enhancement Request for a new feature that's not currently supported needs review PR needs code review by maintainer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants