Skip to content

Conversation

JasonTheAdams
Copy link
Member

@JasonTheAdams JasonTheAdams commented Sep 2, 2025

Resolves #81

This introduces the MessageBuilder class — Fluent API for constructing messages, very similar to the PromptBuilder.

Note that I've intentionally moved structure validation to the moment of termination because I don't think we should be checking things against the role and such until the implementor considers the builder complete.

Copy link

github-actions bot commented Sep 2, 2025

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 props-bot label.

If you're merging code through a pull request on GitHub, copy and paste the following into the bottom of the merge commit message.

Co-authored-by: JasonTheAdams <[email protected]>
Co-authored-by: felixarntz <[email protected]>

To understand the WordPress project's expectations around crediting contributors, please review the Contributor Attribution page in the Core Handbook.

@JasonTheAdams JasonTheAdams mentioned this pull request Sep 2, 2025
20 tasks
@felixarntz felixarntz added the [Feature] New feature to highlight in changelogs. label Sep 2, 2025
@felixarntz felixarntz added this to the 0.2.0 milestone Sep 2, 2025
Copy link
Member

@felixarntz felixarntz left a comment

Choose a reason for hiding this comment

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

@JasonTheAdams Thanks for putting this together! Looks great, except one piece that needs to be revised to make it more flexible, especially as we already do it more flexibly in PromptBuilder.

+withImageFile(File $file) self
+withAudioFile(File $file) self
+withVideoFile(File $file) self
+withFile($file, ?string $mimeType) self
Copy link
Member

Choose a reason for hiding this comment

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

Great catch updating these! Since you're already on it, could you revise the PromptBuilder definition here as well, at least replacing similar outdated instances?

* @param string|null $text Optional initial text content.
* @param MessageRoleEnum|null $role Optional role.
*/
public function __construct(?string $text = null, ?MessageRoleEnum $role = null)
Copy link
Member

Choose a reason for hiding this comment

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

This should allow more than just $text - let's make it mixed $input, similar to PromptBuilder.

We should add parity here for all possibilities that identify something within a Message, at least anything that can become a single MessagePart.

At least this should support passing a string (text) or a MessagePart, or a MessagePartArrayShape. Maybe even the lower-level pieces to turn into a MessagePart (which string is already one of), like File, FunctionCall, or FunctionResponse.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Feature] New feature to highlight in changelogs.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Implement the MessageBuilder class
2 participants