Skip to content
This repository was archived by the owner on Jul 16, 2025. It is now read-only.

Conversation

@OskarStark
Copy link
Contributor

@OskarStark OskarStark commented Jul 10, 2025

Summary

This PR updates the message ID type from TimeBasedUidInterface to AbstractUid&TimeBasedUidInterface using PHP's intersection types. This change provides more flexibility while maintaining type safety.

Solution

Using the intersection type AbstractUid&TimeBasedUidInterface ensures that:

  • ✅ Both toRfc4122() (from AbstractUid) and getDateTime() (from TimeBasedUidInterface) are available
  • ✅ Implementations can use any time-based UID type (UUID v1/v6/v7 or ULID)
  • ✅ Type safety is maintained
  • ✅ All existing tests pass without modification

Changes

  • Updated MessageInterface::getId() return type
  • Updated all message implementations (AssistantMessage, SystemMessage, UserMessage, ToolCallMessage)
  • Updated anonymous class in tests

Benefits

  1. Flexibility: Users can now implement messages with either UUID or ULID
  2. Type Safety: The intersection type guarantees all necessary methods are available
  3. Future Proof: Any new Symfony UID types that extend AbstractUid and implement TimeBasedUidInterface will work

Breaking Changes

None - this is backwards compatible since all existing UUID implementations already satisfy the new type constraint.

Testing

All existing tests pass. The implementation has been verified to work with both UUID and ULID.

@OskarStark OskarStark self-assigned this Jul 10, 2025
@OskarStark OskarStark requested a review from chr-hertel July 10, 2025 16:09
@OskarStark OskarStark changed the title fix: use more specific implementation which supports getDateTime refactor!: use more specific implementation which supports getDateTime Jul 10, 2025
@OskarStark OskarStark added the BC BREAK Backwards compatibility break label Jul 10, 2025
@chr-hertel
Copy link
Member

Nice one, good to merge after PHPStan fixes :) 👍

@OskarStark
Copy link
Contributor Author

OskarStark commented Jul 13, 2025

Hmm, I don't really know what to do:

  67     Call to an undefined method Symfony\Component\Uid\TimeBasedUidInterface::toRfc4122().
         🪪 method.notFound

Require UuidV7, or keep Uuid (aka closing this PR)?

@chr-hertel
Copy link
Member

what about Uuid&TimeBasedUidInterface? that should do the trick

@OskarStark OskarStark changed the title refactor!: use more specific implementation which supports getDateTime feat: use intersection type Uuid&TimeBasedUidInterface for message IDs Jul 14, 2025
@OskarStark OskarStark changed the title feat: use intersection type Uuid&TimeBasedUidInterface for message IDs feat: use intersection type Uuid&TimeBasedUidInterface for message IDs Jul 14, 2025
@OskarStark OskarStark changed the title feat: use intersection type Uuid&TimeBasedUidInterface for message IDs feat: use intersection type AbstractUid&TimeBasedUidInterface for flexible message IDs Jul 14, 2025
@OskarStark OskarStark changed the title feat: use intersection type AbstractUid&TimeBasedUidInterface for flexible message IDs feat: use intersection type AbstractUid&TimeBasedUidInterface for flexible message IDs Jul 14, 2025
@OskarStark
Copy link
Contributor Author

cc @llupa

@OskarStark
Copy link
Contributor Author

Good to go from my side @DZunke @chr-hertel

…ible message IDs

This PR updates the message ID type from TimeBasedUidInterface to AbstractUid&TimeBasedUidInterface using PHP's intersection types.

Problem:
- The original implementation returned TimeBasedUidInterface from getId(), but tests were calling toRfc4122() which is not part of that interface
- This caused PHPStan errors

Solution:
- Using the intersection type AbstractUid&TimeBasedUidInterface ensures that both toRfc4122() (from AbstractUid) and getDateTime() (from TimeBasedUidInterface) are available
- This allows implementations to use any time-based UID type (UUID v1/v6/v7 or ULID)

Changes:
- Updated MessageInterface::getId() return type
- Updated all message implementations (AssistantMessage, SystemMessage, UserMessage, ToolCallMessage)
- Added tests to verify interface implementations
- Updated PHPStan configuration

Benefits:
- Flexibility: Users can now implement messages with either UUID or ULID
- Type Safety: The intersection type guarantees all necessary methods are available
- Future Proof: Any new Symfony UID types that extend AbstractUid and implement TimeBasedUidInterface will work
- Backwards Compatible: All existing UUID implementations already satisfy the new type constraint
Copy link
Member

@chr-hertel chr-hertel left a comment

Choose a reason for hiding this comment

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

Let's get this merged and than cherry picked :)

@chr-hertel chr-hertel merged commit bf72975 into main Jul 14, 2025
7 checks passed
@chr-hertel chr-hertel deleted the fix/uuid branch July 14, 2025 22:20
@OskarStark
Copy link
Contributor Author

fyi @llupa

OskarStark added a commit to symfony/ai that referenced this pull request Jul 15, 2025
…idInterface` for flexible message IDs (OskarStark)

This PR was merged into the main branch.

Discussion
----------

[Platform] Use intersection type `AbstractUid&TimeBasedUidInterface` for flexible message IDs

| Q             | A
| ------------- | ---
| Bug fix?      | no
| New feature?  | yes
| Docs?         | no
| Issues        |
| License       | MIT

Cherry picking php-llm/llm-chain#384

Commits
-------

115a9e1 feat: use intersection type `AbstractUid&TimeBasedUidInterface` for flexible message IDs (#384)
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

BC BREAK Backwards compatibility break

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants