feat(js/ai): implemented generate middleware#5043
feat(js/ai): implemented generate middleware#5043pavelgj merged 21 commits intopj/gm-refactor-generate-api-into-aifrom
Conversation
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive middleware system for Genkit, allowing developers to intercept and modify the high-level generation process, model calls, and tool executions. It includes new utilities for defining and normalizing middleware, along with integration into the core registry and plugin architecture. Feedback indicates a regression in error handling within resolveToolRequest where the removal of a try-catch block leaves resumed and restarted tool calls unprotected against interrupts, and suggests simplifying redundant logic in resolveToolRequests once error handling is centralized.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new middleware system for Genkit, allowing developers to intercept and modify the top-level generate action, underlying model execution, and individual tool calls. It includes the addition of a generateMiddleware factory, a normalization process for different middleware representations, and updates to the core generation logic to support these hooks. One piece of feedback was provided regarding the restoration of a comment explaining a specific error check for better maintainability.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a new middleware system for Genkit's generate action, allowing for interceptors at the generate, model, and tool execution levels. It includes a new normalizeMiddleware utility to handle various middleware formats and integrates this system into the generation pipeline. I have reviewed the proposed changes and identified an issue with the tool middleware hook signature where allowing a void return type could lead to inconsistent conversation states.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a comprehensive middleware system for Genkit AI, enabling interception and modification of generation, model, and tool execution. It includes new interfaces, normalization logic for various middleware formats, and updates to the tool resolution process to support middleware-injected tools. Feedback highlights a bug in resolveRestartedTools where tools injected by middleware are overlooked during resolution, which could lead to failures for interrupted tools.
Co-authored-by: Michael Doyle <michaeldoyle@google.com>
Co-authored-by: Michael Doyle <michaeldoyle@google.com>
05e924d
into
pj/gm-refactor-generate-api-into-ai
Checklist (if applicable):