Conversation
Summary of ChangesHello, 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 significantly enhances the developer experience in Genkit by introducing robust type safety for application-specific context within flows and tools. By allowing developers to define and infer custom context types, it eliminates the need for manual type casting and reduces potential runtime errors, making Genkit applications more predictable and easier to maintain. The changes also clarify that context is always available, streamlining its usage. Highlights
🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console. Changelog
Activity
Using Gemini Code AssistThe 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 by creating a comment using either
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 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
|
There was a problem hiding this comment.
Code Review
This pull request is a great improvement for Genkit's developer experience, introducing type-safety for context objects in flows and tools. The changes are well-implemented across the core, AI, and Genkit packages, enabling both inferred and declared context typing. The removal of | undefined from the context type is also a welcome change that simplifies usage. I've found a couple of minor issues: one is a redundant type cast that can be removed, and the other is an incorrect README file for the new test application. Overall, this is a solid feature addition.
Currently when dealing with Context in Genkit, the type returned everywhere is a static
ActionContext, which looks like:When providing context within Genkit, e.g. within flows, you lose all type-safety:
Here,
context.hellois ananytype. This means you end up having to write your own definitions, and casting context:This then doesn't scale, as context is inherited everywhere, and it becomes a bit PITA to type, resulting in bad DX.
This PR enables typed and inferred context typing:
Inferred:
Declared:
Additionally, context returned from actions is currently typed as
ActionContext | undefined, which caused more issues having to docontext?.something. However looking at the code, context is always defined, even if the result is an empty object:So this PR also removes the
| undefinedtype (happy to be proved wrong here!). Note, I don't think this is a breaking change.Because this PR allows typed context, I'd of ideally liked to remove the
[additionalContext: string]: any;withinActionContext:interface ActionContext { /** Information about the currently authenticated user if provided. */ auth?: Record<string, any>; - [additionalContext: string]: any; }However, technically I think this would end up being a breaking change since users relying on the
anywould all of a sudden get type errors.Checklist (if applicable):