Skip to content

Comments

RFC: [JS] Genkit Client#4803

Draft
Ehesp wants to merge 1 commit intofirebase:mainfrom
Ehesp:js-genkit-client
Draft

RFC: [JS] Genkit Client#4803
Ehesp wants to merge 1 commit intofirebase:mainfrom
Ehesp:js-genkit-client

Conversation

@Ehesp
Copy link
Member

@Ehesp Ehesp commented Feb 21, 2026

This is an RFC for the Genkit JS Client.

See https://github.com/Ehesp/genkit/blob/js-genkit-client/docs/js-genkit-client-rfc.md for more details.

@github-actions github-actions bot added the docs Improvements or additions to documentation label Feb 21, 2026
@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Ehesp, 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 RFC proposes a comprehensive and modern JavaScript/TypeScript client SDK for Genkit. It aims to significantly enhance the developer experience by providing a client factory for centralized configuration, end-to-end type safety for flows, robust built-in retry mechanisms, and framework-specific integrations for React and Vue. The design addresses current limitations by reducing boilerplate, improving resilience, and offering a flexible chat primitive, making it easier to consume Genkit flows in client-side applications.

Highlights

  • Client Factory: Introduced a createGenkitClient factory for shared configuration, including base URL, headers, retry logic, and custom fetch implementation.
  • Type Inference: Proposed end-to-end type safety by inferring input, output, and stream types directly from server-defined flows using TypeScript.
  • Retry and Resilience: Designed built-in retry mechanisms with configurable backoff strategies, jitter, and retryable HTTP status codes.
  • Framework Integration: Introduced React hooks (useFlow, useChat) and Vue composables for managing flow invocations and chat UIs with reactive state.
  • Chat Primitives: Detailed a useChat hook that supports both client-managed and server-managed conversation history via a flexible adapter pattern.
  • Error Handling: Defined a GenkitClientError class to provide structured error details from server responses.
  • Modular Package Structure: Outlined a modular package structure with a browser-safe, framework-agnostic core and separate React/Vue adapters.

🧠 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
  • docs/js-genkit-client-rfc.md
    • Added a new Request for Comments (RFC) document detailing the proposed Genkit Client SDK.
Activity
  • No human activity has been recorded on this pull request yet.
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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

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 pull request 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

  1. 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.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The RFC for the Genkit JS Client is comprehensive and well-thought-out. It effectively addresses the limitations of the current minimal client by proposing a factory pattern, robust type inference, and framework-specific integrations. The inclusion of both client-managed and server-managed chat history approaches via a flexible adapter pattern is a highlight. My feedback focuses on ensuring resource efficiency for long-running chat sessions and clarifying lifecycle management in the React hooks.

Comment on lines +558 to +562
function useFlow<A extends Action>(
client: GenkitClient,
path: string,
options?: UseFlowOptions<A>,
): UseFlowReturn<A>;
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

To ensure consistency with the Vue implementation (line 660), the React useFlow hook should explicitly manage the AbortController lifecycle. It is important that any in-flight requests are automatically aborted when the component unmounts to prevent memory leaks and unnecessary server-side execution.

Comment on lines +721 to +722
**Pros:** Simple, no server-side session state, works with any deployment (serverless, edge).
**Cons:** Full history sent every request (grows with conversation length), no server-side session persistence across page reloads.
Copy link
Contributor

Choose a reason for hiding this comment

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

medium

For 'Approach A' (Client-Managed History), sending the full message array on every request can become problematic as conversations grow. This could eventually hit HTTP payload limits or exceed the model's context window. Consider adding a recommendation or a built-in option for a sliding window or message truncation strategy within the ChatAdapter or hook configuration.

Comment on lines +1230 to +1240
4. **Lightweight flow contract type**: The type inference approach requires `import type { MyFlow } from '../server/flows'`, which imports the `Action` type from `genkit`. While `import type` has zero runtime cost, it still couples the client's type-checking to the server package. Should there be a lighter-weight "flow contract" type that avoids this coupling? For example:

```typescript
// Server
export type MyFlowContract = FlowContract<string, { greeting: string }, string>;

// Client -- no dependency on genkit's Action type
import type { MyFlowContract } from '../shared/contracts';
client.runFlow<MyFlowContract>('/myFlow', 'hello');
```

Copy link
Contributor

Choose a reason for hiding this comment

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

medium

The 'Lightweight flow contract type' is a very important consideration for large-scale applications. Importing the full Action type (and its zod dependencies) from the server can sometimes lead to circular dependencies or bloated type-checking times in complex monorepos. Prioritizing a dependency-agnostic contract definition would improve the scalability of this approach.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

docs Improvements or additions to documentation

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

1 participant