Thanks to visit codestin.com
Credit goes to github.com

Skip to content

feat(agents): typed API client and shared infra (1/8)#8280

Open
VaibhavAcharya wants to merge 3 commits into
mainfrom
agent/cli/pr8237-base
Open

feat(agents): typed API client and shared infra (1/8)#8280
VaibhavAcharya wants to merge 3 commits into
mainfrom
agent/cli/pr8237-base

Conversation

@VaibhavAcharya

@VaibhavAcharya VaibhavAcharya commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

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.

  • The static model whitelist is gone. Models are fetched live from the AI gateway, so adding a model upstream no longer needs a CLI patch.
  • API calls live in a typed module (api.ts) so each command file can focus on UX.
  • Attachment upload handling (attachments.ts) with size and per-request limits, plus orphan cleanup on partial failure.

The existing create/list/show/stop commands 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:

  • Open a bug/issue before writing your code 🧑‍💻. This ensures we can discuss the changes and get feedback from everyone that should be involved. If you`re fixing a typo or something that`s on fire 🔥 (e.g. incident related), you can skip this step.
  • Read the contribution guidelines 📖. This ensures your code follows our style guide and
    passes our tests.
  • Update or add tests (if any source code was changed or added) 🧪
  • Update or add documentation (if features were changed or added) 📝
  • Make sure the status checks below are successful ✅

@coderabbitai

coderabbitai Bot commented Jun 1, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

No actionable comments were generated in the recent review. 🎉

ℹ️ Recent review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: CHILL

Plan: Pro

Run ID: ba74c7f7-5a41-4e29-a045-3cd5c2e0e8b3

📥 Commits

Reviewing files that changed from the base of the PR and between 5549de6 and e732dfa.

📒 Files selected for processing (4)
  • src/commands/agents/api.ts
  • src/commands/agents/utils.ts
  • tests/integration/utils/mock-api.ts
  • tests/unit/commands/agents/utils.test.ts
🔗 Linked repositories identified

CodeRabbit considers these linked repositories for cross-repo context during reviews:

  • netlify/blueprints (manual)
🚧 Files skipped from review as they are similar to previous changes (3)
  • tests/integration/utils/mock-api.ts
  • src/commands/agents/api.ts
  • src/commands/agents/utils.ts

📝 Walkthrough

Summary by CodeRabbit

  • New Features
    • Added a Netlify-backed agents API client for managing agent runners, sessions, diffs, and runner actions.
    • Introduced attachment upload support with per-file upload URLs and structured upload results.
  • Improvements
    • Expanded agent/session metadata and configuration options, including richer filtering, modes, usage formatting, and dashboard link building.
    • Added pagination and link-header parsing for diff/session listing.
  • Bug Fixes
    • Improved handling for missing diffs/sessions (graceful empty results) and best-effort cleanup on partial upload failures.
  • Tests
    • Enhanced request tracking in the integration mock utilities.

Walkthrough

This 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)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the primary change: introduction of a typed API client and supporting infrastructure for the agents command revamp.
Description check ✅ Passed The description is directly related to the changeset, explaining the foundational infrastructure changes across API, types, constants, utilities, and attachment handling.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
📝 Generate docstrings
  • Create stacked PR
  • Commit on current branch
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch agent/cli/pr8237-base

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

@github-actions

github-actions Bot commented Jun 1, 2026

Copy link
Copy Markdown

📊 Benchmark results

Comparing with 77982eb

  • Dependency count: 1,127 (no change)
  • Package size: 379 MB (no change)
  • Number of ts-expect-error directives: 352 (no change)

@VaibhavAcharya VaibhavAcharya changed the title feat(agents): typed API client and shared infra (1/8 of #8237) feat(agents): typed API client and shared infra (1/8) Jun 1, 2026
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.
@VaibhavAcharya VaibhavAcharya force-pushed the agent/cli/pr8237-base branch from c4a30f1 to 5549de6 Compare June 1, 2026 09:59
@VaibhavAcharya VaibhavAcharya marked this pull request as ready for review June 1, 2026 10:19
@VaibhavAcharya VaibhavAcharya requested a review from a team as a code owner June 1, 2026 10:19

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

📥 Commits

Reviewing files that changed from the base of the PR and between c9d1772 and 5549de6.

📒 Files selected for processing (6)
  • src/commands/agents/api.ts
  • src/commands/agents/attachments.ts
  • src/commands/agents/constants.ts
  • src/commands/agents/types.ts
  • src/commands/agents/utils.ts
  • tests/integration/utils/mock-api.ts

Comment thread tests/integration/utils/mock-api.ts
@VaibhavAcharya

Copy link
Copy Markdown
Contributor Author

Link EX-2195

Comment thread src/commands/agents/api.ts Outdated
Comment thread src/commands/agents/utils.ts

import type { NetlifyOptions } from '../types.js'
import { parseLinkHeader } from './utils.js'
import type {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VaibhavAcharya I would have split this file up as well, start with 1 command and the methods we need for it, and the same for the types. This makes it easier to understand how they are being used in the following PR's that need to be reviewed.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not necessary to do now btw! But for a next time :)

Comment thread src/commands/agents/api.ts Outdated
Comment thread src/commands/agents/utils.ts Outdated
Comment thread src/commands/agents/api.ts

@khendrikse khendrikse left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@VaibhavAcharya I left a few comments :) some are nitty, feel free to do with it what you want!

- encode all path id/sessionId params, not just account slug
- reuse isListStatusFilter in validateListStatusFilter
- apply mock-api status before function responses
- trim api client comment, drop internal issue ref
- add unit tests for agents utils
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