feat(agents): typed API client and shared infra (1/8)#8280
feat(agents): typed API client and shared infra (1/8)#8280VaibhavAcharya wants to merge 1 commit into
Conversation
📝 WalkthroughSummary by CodeRabbit
WalkthroughThis PR introduces a complete Netlify agents API client factory and attachment upload subsystem. It adds configuration constants for agent/session modes and filtering options with terminal state subsets and attachment limits, expands the TypeScript data model with new runner and session fields covering deployment state, contributors, usage metrics, and AI gateway integration. The API client implements HTTP plumbing with centralized error handling, pagination via Total/Link headers, and strongly-typed methods for listing/managing runners and sessions, retrieving diffs, triggering actions, and listing AI gateway providers with in-memory caching. Supporting utilities add validators for prompts, titles, agents, and models; formatters for dates, PR states, bytes, tokens, and diffs; dashboard URL building; MIME type detection; and HTTP header parsing. Attachment upload validates file counts and sizes, requests upload URLs, streams files via PUT with 60-second timeouts, and performs best-effort orphan cleanup on failure. Test infrastructure updates mock API to track originalUrl and support function-based route responses. Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches📝 Generate docstrings
🧪 Generate unit tests (beta)
Comment |
Introduce the typed agents/AI-gateway API module (api.ts), attachment upload handling (attachments.ts), and the supporting types, constants, and utils the expanded agents CLI surface builds on. Models are now fetched live from the AI gateway instead of a static whitelist. No command behavior changes yet: the existing create/list/show/stop commands keep working against the new infra. Subsequent PRs rewrite those commands and add the new subcommands on top of this base. Part 1/8 of the agents CLI revamp split.
c4a30f1 to
5549de6
Compare
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@tests/integration/utils/mock-api.ts`:
- Around line 70-73: The handler currently returns before applying the
configured status when response is a function, so update the logic in the mock
API handler (the branch that checks typeof response === 'function') to call
res.status(status) before invoking response(req, res); ensure you still return
afterwards and preserve existing behavior for non-function responses; reference
the response variable and res.status(...) call in the function branch so
function-based dynamic responses receive the configured HTTP status.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
Run ID: c4c8d79b-38a5-47a2-8f64-ac81a9961d99
📒 Files selected for processing (6)
src/commands/agents/api.tssrc/commands/agents/attachments.tssrc/commands/agents/constants.tssrc/commands/agents/types.tssrc/commands/agents/utils.tstests/integration/utils/mock-api.ts
|
Link EX-2195 |
| // TODO: Migrate to @netlify/api once these endpoints are public. | ||
| // They are marked x-internal in bitballoon (#21736). | ||
| // Method names mirror the bitballoon @operation_id to keep the future swap quick. |
There was a problem hiding this comment.
[nit] a smaller comment with less service specificity
| // TODO: Migrate to @netlify/api once these endpoints are public. | |
| // They are marked x-internal in bitballoon (#21736). | |
| // Method names mirror the bitballoon @operation_id to keep the future swap quick. | |
| // TODO: Migrate to @netlify/api once these endpoints are public. | |
| // Method names mirror the backend @operation_id to keep the future swap quick. |
Summary
Linear: https://linear.app/netlify/issue/EX-2195
Splits the agents CLI revamp (formerly one large PR) into a reviewable stack. This first PR is the foundation: the typed agents API and the shared types, constants, and utilities the rest of the command work builds on. No user-facing command behavior changes yet.
api.ts) so each command file can focus on UX.attachments.ts) with size and per-request limits, plus orphan cleanup on partial failure.The existing
create/list/show/stopcommands keep working unchanged against the new infra; their behavior changes land in the next PR.Stack (merge in order): base → existing commands → diff/open → pr/commit → sync/redeploy → publish/revert → rename/archive → follow-up.
Base branch:
main.For us to review and ship your PR efficiently, please perform the following steps:
passes our tests.