-
Notifications
You must be signed in to change notification settings - Fork 682
Add support for dynamic headers in EdgeChatAdapter #1711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for dynamic headers in EdgeChatAdapter #1711
Conversation
@kubk is attempting to deploy a commit to the assistant-ui Team on Vercel. A member of the Team first needs to authorize it. |
LGTM 👍 |
WalkthroughThe changes define a new type alias, Warning There were issues while running some tools. Please review the errors and either fix the tool’s configuration or disable the tool if it’s a critical failure. 🔧 ESLint
packages/react/src/runtimes/edge/EdgeChatAdapter.tsOops! Something went wrong! :( ESLint: 9.21.0 ESLint couldn't find an eslint.config.(js|mjs|cjs) file. From ESLint v9.0.0, the default configuration file is now eslint.config.js. https://eslint.org/docs/latest/use/configure/migration-guide If you still have problems after following the migration guide, please stop by ✨ Finishing Touches
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
📜 Review details
Configuration used: CodeRabbit UI
Review profile: ASSERTIVE
Plan: Pro
📒 Files selected for processing (1)
packages/react/src/runtimes/edge/EdgeChatAdapter.ts
(3 hunks)
🔇 Additional comments (3)
packages/react/src/runtimes/edge/EdgeChatAdapter.ts (3)
38-38
: Good abstraction for header values.The new
HeadersValue
type alias is a clean way to handle the two possible formats for headers. This makes the codebase more maintainable and type-safe.
71-76
: Well-documented headers property with improved flexibility.The JSDoc comments clearly explain the two options for providing headers. This is a good enhancement that enables dynamic header generation at request time, which will be useful for token refreshing and other runtime header needs.
123-128
:✅ Verification successful
Verify proper consumption of headers across the codebase.
This change introduces dynamic header resolution which affects the timing of when headers are available. Ensure that all code paths consuming the EdgeChatAdapter properly handle this asynchronous behavior and that it doesn't introduce race conditions or timing issues.
🏁 Script executed:
#!/bin/bash # Description: Search for usages of EdgeChatAdapter to verify compatibility with dynamic headers # Look for imports of EdgeChatAdapter echo "Searching for EdgeChatAdapter imports..." rg -A 5 "import.*EdgeChatAdapter" --type ts # Look for instantiations of EdgeChatAdapter echo "Searching for EdgeChatAdapter instantiations..." rg -A 10 "new EdgeChatAdapter" --type ts # Look for usage of headers property in EdgeChatAdapterOptions echo "Searching for headers usage in EdgeChatAdapterOptions..." rg -A 3 "headers\s*[=:]" --type ts | grep -B 5 -A 3 "EdgeChatAdapter"Length of output: 3189
Dynamic header resolution verification complete – no issues found.
The asynchronous resolution of headers in
EdgeChatAdapter.ts
is properly encapsulated within the adapter’s internal fetch call, and our grep results (especially the instantiation inpackages/react/src/runtimes/edge/useEdgeRuntime.ts
) show that consumers do not prematurely assume synchronous header availability. No race conditions or timing issues were evident across the code paths consuming the adapter.
- Verified imports and instantiations in
useEdgeRuntime.ts
indicate that the adapter is used with proper asynchronous handling.- No other consumers rely on a synchronous headers value; the asynchronous invocation is fully contained within the adapter.
📝 Documentation updates detected! You can review documentation updates here |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Summary
The PR adds dynamic header support to EdgeChatAdapter, enabling runtime header updates for authentication token refreshing and other dynamic use cases.
- Added
HeadersValue
type supporting both staticRecord<string, string>
andHeaders
objects - Enhanced
EdgeChatAdapterOptions.headers
to accept either static headers or an async function returning headers - Implemented header resolution logic in
run()
method to await function-based headers before making requests - Added JSDoc documentation for the new headers functionality
- Maintains backward compatibility while solving the token refresh issue from #1703
💡 (1/5) You can manually trigger the bot by mentioning @greptileai in a comment!
1 file(s) reviewed, 1 comment(s)
Edit PR Review Bot Settings | Greptile
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM 👍
need to add a changeset before I merge this (note to self: we should use the changesets github bot that tells PR creators to add a changeset) I can get to adding the changeset tonight or you can do it by running |
👋 Hey! As a free user, you're receiving reviews for every 5th PR. Upgrade to get reviews on every pull request and boost your code quality! Learn more here 🚀 |
@Yonom Thank you, I've added the changeset 👌 |
Pull request summary
|
HI @Yonom , just wanted to follow up on this PR. I think it’s ready to go and would love to get it merged. Let me know if there’s anything else you need from me. Thanks! |
Thank you! |
Closes #1703
This PR enhances the EdgeChatAdapter by adding support for dynamic headers in API requests.
Motivation:
This change allows for dynamic generation of headers at request time, which is useful for:
Changes:
Testing:
The implementation maintains backward compatibility with existing code while adding the new functionality.
Important
Add support for dynamic headers in
EdgeChatAdapter
by allowingheaders
to be a function returning a promise.EdgeChatAdapterOptions.headers
now accepts a function returning aPromise
of headers, in addition to static headers.run()
inEdgeChatAdapter
resolves dynamic headers if a function is provided.HeadersValue
type for header values inEdgeChatAdapter.ts
.headers
inEdgeChatAdapterOptions
.This description was created by
for c41ed25. It will automatically update as commits are pushed.