Skip to content

Conversation

@ziyak97
Copy link
Contributor

@ziyak97 ziyak97 commented Sep 25, 2025

In some environments (non-secure origins like http, older browsers, certain test runners), crypto.randomUUID is not available, causing runtime errors.

This change preserves the existing fast path when crypto.randomUUID exists, and adds a RFC4122 v4-shaped fallback for other cases:

  • Detects availability via: typeof crypto !== 'undefined' && crypto.randomUUID
  • Uses crypto.randomUUID.bind(crypto) when present
  • Otherwise formats a UUID using 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(...) with Math.random, ensuring version (4) and variant (8|9|a|b) bits
  • Keeps strict typing with template-literal UUID type for DX

No breaking changes.

…HTTP/older envs)

In some environments (non-secure origins like http, older browsers, certain test runners),
`crypto.randomUUID` is not available, causing runtime errors.

This change preserves the existing fast path when `crypto.randomUUID` exists, and adds a
RFC4122 v4-shaped fallback for other cases:

- Detects availability via: typeof crypto !== 'undefined' && crypto.randomUUID
- Uses `crypto.randomUUID.bind(crypto)` when present
- Otherwise formats a UUID using 'xxxxxxxx-xxxx-4xxx-yxxx-xxxxxxxxxxxx'.replace(...)
  with Math.random, ensuring version (4) and variant (8|9|a|b) bits
- Keeps strict typing with template-literal UUID type for DX

No breaking changes.
@changeset-bot
Copy link

changeset-bot bot commented Sep 25, 2025

🦋 Changeset detected

Latest commit: 62d8648

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 4 packages
Name Type
@openai/agents-core Patch
@openai/agents-openai Patch
@openai/agents-realtime Patch
@openai/agents Patch

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR

@seratch seratch added enhancement New feature or request package:agents-core labels Sep 25, 2025
@seratch
Copy link
Member

seratch commented Sep 25, 2025

@ziyak97 This looks great. Could you add some unit tests to help with long-term maintenance?

@ziyak97
Copy link
Contributor Author

ziyak97 commented Sep 25, 2025

Done @seratch

Copy link
Member

@seratch seratch left a comment

Choose a reason for hiding this comment

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

LGTM; thank you!

@seratch seratch merged commit 8516799 into openai:main Sep 26, 2025
5 checks passed
@ziyak97 ziyak97 deleted the fix/randomuuid-fallback branch September 26, 2025 05:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants