Add @effect-firebase/genkit package for Genkit integration#44
Conversation
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.
…ect-support-aN8Dq
Match the workspace-wide bump performed on next so the new genkit package stays aligned with the rest of the workspace.
|
Important Review skippedDraft detected. Please check the settings in the CodeRabbit UI or the ⚙️ Run configurationConfiguration used: Repository UI Review profile: ASSERTIVE Plan: Pro Run ID: You can disable this status message by setting the Use the checkbox below for a quick retry:
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. Comment |
|
View your CI Pipeline Execution ↗ for commit 53830d6
☁️ Nx Cloud last updated this comment at |
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.
Summary
Introduces a new
@effect-firebase/genkitpackage 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/genkitwith two main exports:makeTool: Converts EffectTool(withSchemaparameters/success/failure) into a GenkitToolAction. 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 EffectSchemaand integrates tools via Genkit's tool resolution.Tool failure handling: Typed failures from Effect tools are encoded through their
failureSchemaand thrown asGenkitErrorwithstatus: 'FAILED_PRECONDITION'and the encoded payload ondetail. Defects surface asGenkitErrorwithstatus: 'INTERNAL'.Runtime integration: Both functions accept a
Runtime<R>fromeffect-firebase, allowing handlers to access Effect services and dependencies.Comprehensive test coverage: Added test suites for both
makeToolandonCallGenkitEffectcovering schema validation, encoding/decoding, failure handling, and defect reporting.Refactored runtime exports: Moved
Runtimetype andrunfunction from@effect-firebase/adminto the coreeffect-firebasepackage for reuse across packages.Notable Implementation Details
FlowConfigdoes not accept JSON Schema (only Zod), so input/output validation foronCallGenkitEffectruns through Effect'sSchemainside the handler rather than at the flow registration level.Schema.decodeUnknownEffectandSchema.encodeUnknownEffectfor bidirectional transformation of input/output.Tool.getJsonSchema()andTool.getJsonSchemaFromSchema().failureSchema) and defects (unexpected errors), mapping them appropriately toGenkitErrorstatus codes.https://claude.ai/code/session_01C9AukQHXZuoTfMPsnrxLUJ