Add Citation DTO core contract to MessagePart - #283
Conversation
|
The following accounts have interacted with this PR and/or linked issues. I will continue to update these lists as activity occurs. You can also manually ask me to refresh this list by adding the If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message. To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook. |
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## trunk #283 +/- ##
============================================
+ Coverage 86.60% 86.94% +0.34%
- Complexity 1335 1362 +27
============================================
Files 68 69 +1
Lines 4314 4436 +122
============================================
+ Hits 3736 3857 +121
- Misses 578 579 +1
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
zahidgh
left a comment
There was a problem hiding this comment.
One validation gap: documentIndex represents an index into the request’s documents array, but the constructor and JSON schema currently allow negative values. A Citation(null, -1, ...) can therefore serialize successfully and leave providers to handle an invalid reference. Please reject documentIndex < 0, add minimum: 0 to its schema, and cover the guard with a unit test.
Implements #277 (Sets up core DTO foundation).
This PR establishes the core DTO foundation to support provider-agnostic source citations, addressing the API-
surface blocker discussed in #277.
Following the feedback and consensus in the issue, this introduces a normalized
Citationobject and attaches itto
MessagePart. The DTO is shaped to represent the common citation formats from Google, OpenAI, and Anthropicwhile keeping the sources checkable:
url(for remote sources) anddocumentIndex(for request-provided documents) to avoid string sniffing.startIndexandendIndexto anchor the citation locally to the owningMessagePart's text string.quotedTextto cleanly carry Anthropic's block-basedcited_text.startIndex <= endIndex), throwing anInvalidArgumentExceptionotherwise.Note: This PR handles the core contract/DTOs within the agnostic client. Follow-up PRs in the respective provider plugin repositories (ai-provider-for-anthropic, etc.) will be required to update their parsing logic to utilize this new format.
AI Disclosure
Model -
Gemini 3.1 ProUsage -
Implementation of functionality and test after discussing in Plan ModeHuman Loop -
Reviewed code against the issue's requirements