feat: add JSON-RPC method to ServerCallContext.state#463
Conversation
There was a problem hiding this comment.
Summary of Changes
Hello @ovidiutaralesca, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!
This pull request enhances the SDK's ServerCallContext by making the JSON-RPC method available within its state. This allows developers to create more adaptive and method-aware application logic, improving the flexibility and utility of the SDK for various JSON-RPC interactions.
Highlights
- Exposing JSON-RPC Method: The
methodfield from JSON-RPC requests is now accessible viaServerCallContext.state, enabling SDK users to tailor their logic based on the specific method being called (e.g.,message/sendvsmessage/stream). - Enhanced Contextual Information: This change provides more granular context to handlers, similar to how headers are already exposed, allowing for more dynamic and method-specific behavior within the SDK.
- Test Coverage: A new test case has been added to
test_jsonrpc_app.pyto ensure themethodis correctly parsed and stored in theServerCallContext.state.
Using Gemini Code Assist
The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.
Invoking Gemini
You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.
| Feature | Command | Description |
|---|---|---|
| Code Review | /gemini review |
Performs a code review for the current pull request in its current state. |
| Pull Request Summary | /gemini summary |
Provides a summary of the current pull request in its current state. |
| Comment | @gemini-code-assist | Responds in comments when explicitly tagged, both in issue comments and review comments. |
| Help | /gemini help |
Displays a list of available commands. |
Customization
To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.
Limitations & Feedback
Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.
You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.
Footnotes
-
Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution. ↩
There was a problem hiding this comment.
Code Review
This pull request adds the JSON-RPC method name to the ServerCallContext.state so that SDK users can access it. The implementation is straightforward and includes a new test to verify the behavior. My review includes a suggestion to improve the design by making method a first-class attribute of ServerCallContext for better type safety and discoverability, rather than adding it to the generic state dictionary. This would make the API clearer for consumers.
|
Gemini suggests adding |
BEGIN_COMMIT_OVERRIDE
feat: add JSON-RPC
methodtoServerCallContext.stateRelease-As: 0.3.6
END_COMMIT_OVERRIDE
Improvement
SDK users sometimes need to know which JSON-RPC method is being processed to adjust their implementation, e.g.:
message/send, they may want to useinvoke()/run()when calling their LLM API, andstream()/run_streamed()formessage/stream.Implementation
Added a
methodfield toServerCallContext.state, similar toheaders.Tests
Added a small test to ensure that method parsing is correct.
Fixes #451