refactor(packages/agents): extract shared generate/stream setup#13
refactor(packages/agents): extract shared generate/stream setup#13zrosenbauer merged 4 commits intomainfrom
Conversation
Extract prepareGeneration() in agent.ts and prepareFlowAgent() in flow-agent.ts to deduplicate ~170 lines of identical setup code between generate() and stream() methods. No behavior change. Co-Authored-By: Claude <noreply@anthropic.com>
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
🦋 Changeset detectedLatest commit: 27f60ca The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Run ID: 📒 Files selected for processing (3)
📝 WalkthroughWalkthroughExtracted shared preparation logic into dedicated helpers for base and flow agents (prepareGeneration and prepareFlowAgent), consolidating validation, model/tool/system/prompt/output resolution, context/logger setup, and hook invocation; generate() and stream() now call these preparers and use their returned prepared context. Changes
Sequence Diagram(s)sequenceDiagram
participant Caller as Caller
participant AgentPrep as prepareGeneration / prepareFlowAgent
participant AgentExec as Agent (generate / stream)
participant Model as LanguageModel/Tools
participant Hooks as Hooks (onStart,onStepFinish,onError)
Caller->>AgentPrep: invoke generate/stream with input & overrides
AgentPrep-->>AgentPrep: validate input, resolve logger, context, prompts, outputs
AgentPrep->>Hooks: fire onStart with prepared context
AgentPrep->>AgentExec: return prepared context
Caller->>AgentExec: proceed with execution (uses prepared context)
AgentExec->>Model: call model/tools with resolved prompts/context
Model-->>AgentExec: respond with generation/results
AgentExec->>Hooks: onStepFinish (toolCalls/toolResults/usage transformed)
alt error
AgentExec->>Hooks: onError (uses validated.input)
AgentExec-->>Caller: throw/error propagate
else success
AgentExec-->>Caller: return final result/stream
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. 📝 Coding Plan
Comment |
Co-Authored-By: Claude <noreply@anthropic.com>
Co-Authored-By: Claude <noreply@anthropic.com>
There was a problem hiding this comment.
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/agents/src/core/agents/flow/flow-agent.ts (1)
1-1:⚠️ Potential issue | 🟡 MinorPipeline failure: OXFMT formatting check.
CI reports
OXFMT formatting check failed for this file. Runoxfmt --writeto fix.🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@packages/agents/src/core/agents/flow/flow-agent.ts` at line 1, The file fails OXFMT formatting; run the formatter and commit the changes: execute `oxfmt --write` (or your project's formatting script) on the file containing the import of AsyncIterableStream in packages/agents/src/core/agents/flow/flow-agent.ts, then stage and commit the updated formatted file so the OXFMT CI check passes.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Outside diff comments:
In `@packages/agents/src/core/agents/flow/flow-agent.ts`:
- Line 1: The file fails OXFMT formatting; run the formatter and commit the
changes: execute `oxfmt --write` (or your project's formatting script) on the
file containing the import of AsyncIterableStream in
packages/agents/src/core/agents/flow/flow-agent.ts, then stage and commit the
updated formatted file so the OXFMT CI check passes.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: ASSERTIVE
Plan: Pro
Run ID: 7e63887a-6a8d-418c-ada5-1886e368390d
📒 Files selected for processing (2)
packages/agents/src/core/agents/base/agent.tspackages/agents/src/core/agents/flow/flow-agent.ts
Summary
prepareGeneration()inagent.tsto deduplicate ~170 lines of identical setup betweengenerate()andstream()(model resolution, tool building, prompt building, output resolution, hook firing, step counter)prepareFlowAgent()inflow-agent.tsto deduplicate input validation, logger resolution, context creation, step builder creation, user message push, andonStarthook firingTest plan
pnpm test --filter=@funkai/agentspasses (all existing tests)pnpm typecheckpassespnpm build --filter=@funkai/agentssucceeds