Skip to content

feat(js): add "fetch" plugin #4802

Open
Ehesp wants to merge 8 commits intofirebase:mainfrom
Ehesp:js-web-plugin
Open

feat(js): add "fetch" plugin #4802
Ehesp wants to merge 8 commits intofirebase:mainfrom
Ehesp:js-web-plugin

Conversation

@Ehesp
Copy link
Member

@Ehesp Ehesp commented Feb 21, 2026

While Genkit currently supports Express, the modern JavaScript ecosystem is rapidly consolidating around Web Standard APIs (Request, Response, Headers). This PR introduces a new plugin that allows Genkit flows to be exposed via the Fetch API standard, making Genkit natively compatible with virtually every modern JS runtime and framework.

By moving away from Node-specific HTTP abstractions, Genkit can now run seamlessly at the Edge, in Serverless environments, and in high-performance runtimes like Bun and Deno:

Runtimes:

  • Bun
  • Deno
  • Cloudflare Workers (Workerd)
  • Node (18+) via fetch
  • Edge (Vercel, Netlify, Fastly)
  • ... and probably more

Frameworks:

  • Hono
  • Elysia
  • Astro
  • Remix
  • Nitro (+ frameworks built on-top of it)
  • TanStack Start
  • ... and probably more

Usage (e.g. Hono):

const app = new Hono();

// Mount a single flow
app.all('/myFlow', (c) => handleFlow(c.req.raw, myFlow));

// Mount Genkit flows under /api - handleFlows routes by path
app.all('/api/*', (c) => handleFlows(c.req.raw, flows, '/api'));

This PR also includes a sample js-hono.

Checklist (if applicable):

TODO:

  • Not sure on the plugin name web - might be a bit too generic.

@github-actions github-actions bot added docs Improvements or additions to documentation js config sample labels 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 pull request significantly expands Genkit's deployment flexibility by introducing a new web plugin. This plugin leverages Web Standard APIs to enable Genkit flows to run efficiently across diverse JavaScript environments, from edge functions to serverless platforms and various modern frameworks. It streamlines the process of exposing Genkit functionalities over HTTP, providing robust tools for handling requests, managing context, and supporting durable streaming, thereby broadening Genkit's ecosystem integration capabilities.

Highlights

  • New Web Plugin Introduction: Introduced a new @genkit-ai/web plugin that enables Genkit flows to be exposed via Web Standard APIs (Request, Response, Headers), making Genkit compatible with a wide array of modern JavaScript runtimes and frameworks.
  • Broad Runtime and Framework Compatibility: The plugin allows Genkit to run seamlessly at the Edge, in Serverless environments, and high-performance runtimes like Bun and Deno, as well as frameworks such as Hono, Elysia, Astro, and Remix, by moving away from Node-specific HTTP abstractions.
  • Core API for Flow Handling: Provided handleFlow for single flow execution and handleFlows for routing multiple flows based on URL paths, both designed to work with standard Web API Request and Response objects.
  • Enhanced Flow Configuration: Added withFlowOptions to wrap flows with custom configurations, including context providers for authentication and stream managers for durable streaming, allowing for more flexible and robust flow deployments.
  • Durable Streaming Support: Implemented durable streaming capabilities, allowing clients to disconnect and reconnect to a stream without losing state, with options for both in-memory and production-ready stream managers.
  • New Hono Sample Application: Included a new sample application (js-hono) demonstrating how to integrate Genkit flows with the Hono framework using the new web plugin, showcasing practical usage with authentication and streaming examples.

🧠 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
  • js/plugins/web/.npmignore
    • Added ignore rules for build artifacts and configuration files.
  • js/plugins/web/README.md
    • Added comprehensive documentation detailing installation, usage examples (single/multiple flows, auth, durable streaming, client-side calling), and an API summary for the new web plugin.
  • js/plugins/web/package.json
    • Defined the new @genkit-ai/web package, including metadata, scripts, and peer dependencies.
  • js/plugins/web/src/index.ts
    • Implemented core functions handleFlow and handleFlows for processing Web API requests, withFlowOptions for flow customization, and logic for streaming and durable streaming.
  • js/plugins/web/src/utils.ts
    • Added utility functions getErrorMessage and getErrorStack for consistent error handling.
  • js/plugins/web/tests/web_test.ts
    • Added extensive unit tests covering handleFlow and handleFlows functionalities, including various input types, authentication, streaming, and durable streaming scenarios.
  • js/plugins/web/tsconfig.json
    • Added TypeScript configuration for the new web plugin.
  • js/plugins/web/tsup.config.ts
    • Added tsup build configuration for the new web plugin.
  • js/plugins/web/typedoc.json
    • Added TypeDoc configuration for generating API documentation for the web plugin.
  • js/pnpm-lock.yaml
    • Updated the pnpm lockfile to include new dependencies and reflect changes from the added web plugin and Hono sample.
  • samples/js-hono/.gitignore
    • Added a .gitignore file for the new Hono sample to exclude build artifacts and node modules.
  • samples/js-hono/README.md
    • Added documentation for the new js-hono sample, explaining its setup, usage, and how it integrates Genkit with Hono using the web plugin.
  • samples/js-hono/package.json
    • Defined the new js-hono sample package, including dependencies on @genkit-ai/web and Hono, and scripts for development and building.
  • samples/js-hono/src/index.ts
    • Implemented a Hono server that exposes several Genkit flows (hello, greeting, streaming, secureGreeting) using the new @genkit-ai/web plugin, demonstrating context providers and streaming.
  • samples/js-hono/tsconfig.json
    • Added TypeScript configuration for the new js-hono sample application.
  • samples/package.json
    • Updated the build:all-samples script to include the new js-hono sample build process.
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

This pull request introduces a new 'web' plugin for Genkit, enabling compatibility with modern Web Standard APIs (Request/Response). This allows Genkit flows to run on various runtimes like Bun, Deno, and Cloudflare Workers. The implementation is solid and well-integrated with Genkit's core concepts. I have identified a few issues regarding path routing logic, error logging robustness, and cross-runtime compatibility that should be addressed.

@Ehesp Ehesp marked this pull request as ready for review February 24, 2026 19:37
@Ehesp
Copy link
Member Author

Ehesp commented Feb 24, 2026

Sample CI check failing due to the new package not being published (I think!)

@Ehesp Ehesp changed the title feat(js): add "web" plugin feat(js): add "fetch" plugin Feb 24, 2026
type RequestData,
} from 'genkit/context';
import { logger } from 'genkit/logging';
import { getErrorMessage, getErrorStack } from './utils';
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
import { getErrorMessage, getErrorStack } from './utils';
import { getErrorMessage, getErrorStack } from './utils.js';

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

Labels

config docs Improvements or additions to documentation js sample

Projects

Status: No status

Development

Successfully merging this pull request may close these issues.

2 participants