Skip to content

Add @effect-firebase/genkit package for Genkit integration#44

Draft
fwal wants to merge 5 commits into
nextfrom
claude/add-genkit-effect-support-aN8Dq
Draft

Add @effect-firebase/genkit package for Genkit integration#44
fwal wants to merge 5 commits into
nextfrom
claude/add-genkit-effect-support-aN8Dq

Conversation

@fwal
Copy link
Copy Markdown
Owner

@fwal fwal commented May 22, 2026

Summary

Introduces a new @effect-firebase/genkit package that bridges Effect into Genkit and Firebase Cloud Functions' onCallGenkit, enabling schema-driven AI flows with typed Effect handlers.

Key Changes

  • New package @effect-firebase/genkit with two main exports:

    • makeTool: Converts Effect Tool (with Schema parameters/success/failure) into a Genkit ToolAction. Effect schemas are automatically converted to JSON Schema for model consumption.
    • onCallGenkitEffect: Creates a Firebase Functions callable trigger backed by a Genkit flow that runs an Effect handler. Supports optional input/output validation via Effect Schema and integrates tools via Genkit's tool resolution.
  • Tool failure handling: Typed failures from Effect tools are encoded through their failureSchema and thrown as GenkitError with status: 'FAILED_PRECONDITION' and the encoded payload on detail. Defects surface as GenkitError with status: 'INTERNAL'.

  • Runtime integration: Both functions accept a Runtime<R> from effect-firebase, allowing handlers to access Effect services and dependencies.

  • Comprehensive test coverage: Added test suites for both makeTool and onCallGenkitEffect covering schema validation, encoding/decoding, failure handling, and defect reporting.

  • Refactored runtime exports: Moved Runtime type and run function from @effect-firebase/admin to the core effect-firebase package for reuse across packages.

Notable Implementation Details

  • Genkit's FlowConfig does not accept JSON Schema (only Zod), so input/output validation for onCallGenkitEffect runs through Effect's Schema inside the handler rather than at the flow registration level.
  • The implementation uses Effect's Schema.decodeUnknownEffect and Schema.encodeUnknownEffect for bidirectional transformation of input/output.
  • Tool JSON schemas are derived from Effect schemas using Tool.getJsonSchema() and Tool.getJsonSchemaFromSchema().
  • Error handling distinguishes between typed failures (via failureSchema) and defects (unexpected errors), mapping them appropriately to GenkitError status codes.

https://claude.ai/code/session_01C9AukQHXZuoTfMPsnrxLUJ

claude added 4 commits May 20, 2026 19:48
Move Runtime<R> and run() from @effect-firebase/admin into the
effect-firebase base package so packages other than admin can share the
same runtime contract without depending on firebase-admin.

The helpers were only used internally by admin's on-* function modules,
so this is a non-breaking move: admin's public surface is unchanged.
Bridge Effect's Tool primitive and Effect-based handlers into Genkit and
firebase-functions' onCallGenkit.

- makeTool: convert an Effect Tool (with Schema parameters/success/failure)
  into a Genkit ToolAction. Parameters and success are converted to JSON
  Schema; typed failures are encoded through failureSchema and surfaced as
  a GenkitError with the encoded payload on detail.
- onCallGenkitEffect: schema-driven callable backed by a Genkit flow,
  mirroring onCallEffect's overload pattern. Effect Schema handles input
  decoding and output encoding inside the flow handler since FlowConfig
  does not accept JSON Schema.

Includes unit tests for tool registration, runtime handler invocation,
typed-failure mapping, defect handling, and the flow decode/encode pipeline.
Match the workspace-wide bump performed on next so the new genkit
package stays aligned with the rest of the workspace.
@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented May 22, 2026

Important

Review skipped

Draft detected.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: Repository UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 3f0501be-fec0-4fd8-b12c-015f5fa9081e

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented May 22, 2026

View your CI Pipeline Execution ↗ for commit 53830d6

Command Status Duration Result
nx affected -t lint test build ✅ Succeeded 32s View ↗

☁️ Nx Cloud last updated this comment at 2026-05-22 13:00:41 UTC

@fwal fwal added this to the 1.0 - Effect v4 milestone May 22, 2026
Previously a user-thrown GenkitError or UserFacingError lost its protocol
mapping because runPromise wrapped it in a FiberFailure, and makeTool
always rebuilt the error as a fresh FAILED_PRECONDITION GenkitError.

- Add runOrThrow helper: runPromiseExit + Cause.squash, so framework code
  sees the actual error instance.
- onCallGenkitEffect now uses runOrThrow; a handler-thrown GenkitError
  reaches Genkit with its status, message, detail, and source intact.
- makeTool checks instanceof GenkitError first and passes the error
  through; only typed failures matching the tool's failureSchema get
  wrapped in a new FAILED_PRECONDITION GenkitError. Defects that are
  already Error instances are thrown as-is.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants