Skip to content

Conversation

@Saurabhkmr98
Copy link
Member

@Saurabhkmr98 Saurabhkmr98 commented Dec 11, 2025

Description

  • Added AgentRun and AgentRunActivity API client, model and tests

Type of Change

  • Bug fix (non-breaking change which fixes an issue)
  • Feature (non-breaking change which adds functionality)
  • Improvement (change that would cause existing functionality to not work as expected)
  • Code refactoring
  • Performance improvements
  • Documentation update

Screenshots and Media (if applicable)

Test Scenarios

References

Summary by CodeRabbit

  • New Features

    • Agent Runs API: create and retrieve agent runs and manage their activities.
    • Agent Run Activities API: list, retrieve, and create varied activity types within runs.
    • New data types to model agent runs and activity content.
  • Tests

    • End-to-end unit tests for agent runs and activities added.
  • Chores

    • Added TEST_AGENT_SLUG to environment examples and test config.

✏️ Tip: You can customize this high-level summary in your review settings.

@makeplane
Copy link

makeplane bot commented Dec 11, 2025

Linked to Plane Work Item(s)

This comment was auto-generated by Plane

@coderabbitai
Copy link

coderabbitai bot commented Dec 11, 2025

Walkthrough

Adds a new Agent Runs feature: typed AgentRun models, API resources for agent runs and their activities, PlaneClient integration, unit tests, and a TEST_AGENT_SLUG configuration entry.

Changes

Cohort / File(s) Summary
Agent Runs API Resources
src/api/AgentRuns/Activities.ts, src/api/AgentRuns/index.ts
New resource classes: Activities with list, retrieve, create for agent run activities; AgentRuns with create and retrieve, and an activities property wired to Activities.
Client Integration
src/client/plane-client.ts
Added AgentRuns import, public agentRuns property, and initialization in the PlaneClient constructor.
Models & Type Definitions
src/models/AgentRun.ts, src/models/index.ts
New AgentRun model file: union types (status, type, activity signal/type), AgentRun and AgentRunActivity interfaces, create request shapes, and discriminated activity content unions. Re-exported from models index.
Public API Exports
src/index.ts
Re-exported AgentRuns and AgentRunActivities (alias) from the public API surface.
Configuration
env.example, tests/unit/constants.ts
Added TEST_AGENT_SLUG entries to env.example and added agentSlug: process.env.TEST_AGENT_SLUG! to test constants.
Unit Tests
tests/unit/agent-runs/activities.test.ts, tests/unit/agent-runs/agent-runs.test.ts
New tests covering agent run creation and retrieval, and activity creation, listing, and retrieval across activity types.

Sequence Diagram

sequenceDiagram
    actor User
    participant PlaneClient
    participant AgentRuns
    participant Activities
    participant API

    User->>PlaneClient: instantiate client (config)
    PlaneClient->>AgentRuns: new AgentRuns(config)
    PlaneClient->>Activities: new Activities(config)
    AgentRuns->>Activities: this.activities = new Activities(config)

    User->>PlaneClient: agentRuns.create(workspaceSlug, data)
    PlaneClient->>AgentRuns: create(workspaceSlug, data)
    AgentRuns->>API: POST /workspaces/{workspaceSlug}/runs/
    API-->>AgentRuns: AgentRun
    AgentRuns-->>PlaneClient: Promise<AgentRun>
    PlaneClient-->>User: AgentRun

    User->>PlaneClient: agentRuns.retrieve(workspaceSlug, runId)
    PlaneClient->>AgentRuns: retrieve(workspaceSlug, runId)
    AgentRuns->>API: GET /workspaces/{workspaceSlug}/runs/{runId}/
    API-->>AgentRuns: AgentRun
    AgentRuns-->>PlaneClient: Promise<AgentRun>
    PlaneClient-->>User: AgentRun

    User->>PlaneClient: agentRuns.activities.list(workspaceSlug, runId)
    PlaneClient->>Activities: list(workspaceSlug, runId, params?)
    Activities->>API: GET /workspaces/{workspaceSlug}/runs/{runId}/activities/
    API-->>Activities: PaginatedResponse<AgentRunActivity>
    Activities-->>PlaneClient: Promise<PaginatedResponse<AgentRunActivity>>
    PlaneClient-->>User: Activities list

    User->>PlaneClient: agentRuns.activities.create(workspaceSlug, runId, data)
    PlaneClient->>Activities: create(workspaceSlug, runId, data)
    Activities->>API: POST /workspaces/{workspaceSlug}/runs/{runId}/activities/
    API-->>Activities: AgentRunActivity
    Activities-->>PlaneClient: Promise<AgentRunActivity>
    PlaneClient-->>User: AgentRunActivity
Loading

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~25 minutes

  • Review discriminated unions and request/response typings in src/models/AgentRun.ts for correctness and exhaustiveness.
  • Verify API paths and method signatures in src/api/AgentRuns/* match backend contracts.
  • Confirm PlaneClient initialization pattern in src/client/plane-client.ts follows existing resources.
  • Inspect unit tests for proper conditional execution and teardown to avoid flakiness.
  • Check tests/unit/constants.ts non-null assertion usage for test environment assumptions.

Poem

🐰 I nibbled code in morning light,
New runs hop forth, activities bright,
Types arranged, endpoints sing,
Tests applaud with every spring,
A rabbit cheers: play, run, delight!

Pre-merge checks and finishing touches

✅ Passed checks (3 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly describes the main changes: adding Agent Runs API, related models, activities, and tests. It is specific, concise, and directly reflects the content of the changeset.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch feat-agent_sessions

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.

❤️ Share

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

@Saurabhkmr98 Saurabhkmr98 self-assigned this Dec 11, 2025
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/agent-runs/agent-runs.test.ts (1)

7-46: Avoid inter-test coupling by creating the agent run in shared setup

The suite gives good coverage of create/retrieve/resume, but agentRun is initialized inside "should create an agent run" and is then reused by the retrieve/resume tests. This couples test outcomes and makes it harder to run tests in isolation or to debug when the first test fails.

Consider moving the client.agentRuns.create(...) call into beforeAll (or a dedicated setup block) and having each it only assert behavior against that shared agentRun. That keeps create exercised while making tests less order-dependent.

tests/unit/agent-runs/activities.test.ts (1)

7-118: Reduce inter-test coupling around the shared activity instance

These tests nicely cover create/list/retrieve and multiple activity types, but the "list" and "retrieve" cases depend on activity being created in the first "should create an agent run activity" test. This implicit ordering can make tests brittle if run individually or reordered.

Consider moving creation of the baseline activity into beforeAll (or a small nested describe with its own setup) so that each test’s expectations don’t rely on another test’s side effects.

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 29b5b10 and daeed27.

📒 Files selected for processing (10)
  • env.example (1 hunks)
  • src/api/AgentRuns/Activities.ts (1 hunks)
  • src/api/AgentRuns/index.ts (1 hunks)
  • src/client/plane-client.ts (3 hunks)
  • src/index.ts (2 hunks)
  • src/models/AgentRun.ts (1 hunks)
  • src/models/index.ts (1 hunks)
  • tests/unit/agent-runs/activities.test.ts (1 hunks)
  • tests/unit/agent-runs/agent-runs.test.ts (1 hunks)
  • tests/unit/constants.ts (1 hunks)
🧰 Additional context used
🧬 Code graph analysis (4)
src/client/plane-client.ts (2)
src/api/AgentRuns/index.ts (1)
  • AgentRuns (10-47)
src/index.ts (1)
  • AgentRuns (30-30)
src/api/AgentRuns/index.ts (2)
src/api/AgentRuns/Activities.ts (1)
  • Activities (10-54)
src/models/AgentRun.ts (2)
  • CreateAgentRunRequest (55-63)
  • AgentRun (34-50)
tests/unit/agent-runs/agent-runs.test.ts (4)
tests/unit/constants.ts (1)
  • config (1-11)
src/client/plane-client.ts (1)
  • PlaneClient (27-83)
src/index.ts (1)
  • PlaneClient (2-2)
src/models/AgentRun.ts (1)
  • AgentRun (34-50)
src/api/AgentRuns/Activities.ts (2)
src/index.ts (3)
  • Activities (36-36)
  • Activities (47-47)
  • BaseResource (8-8)
src/models/AgentRun.ts (2)
  • AgentRunActivity (90-102)
  • CreateAgentRunActivityRequest (107-114)
🪛 GitHub Actions: Build and Test Node SDK
src/models/AgentRun.ts

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues in this file.

🔇 Additional comments (16)
env.example (1)

25-27: Agent configuration env var matches test usage

Adding TEST_AGENT_SLUG under a dedicated “Agent configuration” section keeps test config organized and matches the new config.agentSlug usage in tests. No issues from my side.

src/client/plane-client.ts (1)

21-21: AgentRuns integration into PlaneClient is consistent

The AgentRuns import, public agentRuns property, and constructor initialization mirror the existing resource patterns and keep the client surface coherent. Looks good.

Also applies to: 48-48, 81-81

tests/unit/constants.ts (1)

10-10: agentSlug config wiring aligns with env.example and tests

Exposing agentSlug from TEST_AGENT_SLUG keeps configuration consistent with other IDs/slugs and supports the new agent run tests. No further changes needed.

src/models/index.ts (1)

17-17: Barrel export for AgentRun is correct

Re-exporting ./AgentRun here is consistent with the rest of the models index and allows clean imports in tests and consumers.

src/index.ts (1)

30-30: Public exports for AgentRuns and AgentRunActivities look good

Exposing AgentRuns and aliasing Activities as AgentRunActivities matches the existing export style for other resources/sub-resources and makes the new API surface discoverable from the package root.

Also applies to: 47-47

src/api/AgentRuns/index.ts (1)

1-47: AgentRuns API resource is consistent and well-scoped

The AgentRuns resource, its activities sub-resource, and the create/retrieve/resume methods all follow the established BaseResource pattern and use the expected endpoint shapes. The typing with AgentRun and CreateAgentRunRequest looks appropriate. No changes requested.

src/api/AgentRuns/Activities.ts (4)

1-13: LGTM! Class setup follows established patterns.

The imports, class declaration, and constructor are correctly structured. The constructor simply delegates to BaseResource, which is a common pattern in this codebase.


15-31: LGTM! The list method is well-implemented.

Proper pagination support with optional per_page and cursor parameters, correct return type, and clear JSDoc documentation.


33-42: LGTM! The retrieve method is clean and correct.

Single resource retrieval with proper typing and documentation.


44-54: LGTM! The create method correctly posts activity data.

The method properly uses CreateAgentRunActivityRequest for input and returns the created AgentRunActivity.

src/models/AgentRun.ts (6)

3-14: LGTM! Status type covers the agent run lifecycle well.

The AgentRunStatus union type provides comprehensive coverage of possible run states including creation, execution, completion, and failure scenarios.


16-29: LGTM! Activity-related type definitions are clear.

The signal and activity type unions are well-defined. AgentRunType being a single value currently is fine - it can be extended when new run types are added.


31-50: LGTM! AgentRun interface is comprehensive.

All necessary fields for tracking agent runs are present, including timing fields, status, metadata, and relationships to workspace/project/issue.


52-63: LGTM! Create request interface is appropriately minimal.

Only agent_slug is required; other fields are optional, providing flexibility for different use cases.


65-85: LGTM! Discriminated union for activity content is well-designed.

The type field serves as the discriminant, enabling TypeScript to narrow the type correctly when checking content.type === "action" vs other types.


87-114: LGTM! Activity interfaces correctly model the domain.

AgentRunActivity extends BaseModel appropriately, and CreateAgentRunActivityRequest correctly excludes "prompt" from allowed types, enforcing that prompts are system-generated rather than user-created.

@@ -0,0 +1,115 @@
import { BaseModel } from "./common";
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🟡 Minor

Run Prettier to fix formatting issues.

The pipeline indicates a Prettier formatting check failure for this file. Run prettier --write src/models/AgentRun.ts to fix the code style issues.

🧰 Tools
🪛 GitHub Actions: Build and Test Node SDK

[error] 1-1: Prettier formatting check failed. Run 'prettier --write' to fix code style issues in this file.

🤖 Prompt for AI Agents
In src/models/AgentRun.ts at line 1, the file fails the repository Prettier
formatting check; run the formatter and apply the changes. Execute: prettier
--write src/models/AgentRun.ts (or run your editor/IDE Prettier integration),
stage the updated file, and commit the formatted changes so the CI Prettier
check passes.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🧹 Nitpick comments (2)
tests/unit/agent-runs/agent-runs.test.ts (1)

16-28: Consider adding cleanup in afterAll.

The test creates a work item and comment in beforeAll but doesn't clean them up. This could lead to resource accumulation in the test environment.

🔎 Add cleanup logic:
afterAll(async () => {
  if (workItem?.id) {
    await client.workItems.delete(workspaceSlug, projectId, workItem.id);
  }
});
src/api/AgentRuns/index.ts (1)

10-37: Consider adding list method for completeness.

The AgentRuns resource currently only supports create and retrieve operations. Consider adding a list method to retrieve all agent runs for a workspace, similar to the Activities resource pattern.

Example implementation:
/**
 * List agent runs for a workspace
 * @param workspaceSlug - The workspace slug
 * @param params - Optional query parameters for pagination
 * @returns Paginated list of agent runs
 */
async list(
  workspaceSlug: string,
  params?: { per_page?: number; cursor?: string }
): Promise<PaginatedResponse<AgentRun>> {
  return this.get<PaginatedResponse<AgentRun>>(
    `/workspaces/${workspaceSlug}/runs/`,
    params
  );
}
📜 Review details

Configuration used: defaults

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between daeed27 and 78a9dbf.

📒 Files selected for processing (4)
  • env.example (2 hunks)
  • src/api/AgentRuns/index.ts (1 hunks)
  • tests/unit/agent-runs/activities.test.ts (1 hunks)
  • tests/unit/agent-runs/agent-runs.test.ts (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • tests/unit/agent-runs/activities.test.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/api/AgentRuns/index.ts (2)
src/api/AgentRuns/Activities.ts (1)
  • Activities (10-54)
src/models/AgentRun.ts (2)
  • CreateAgentRunRequest (55-63)
  • AgentRun (34-50)
tests/unit/agent-runs/agent-runs.test.ts (3)
tests/unit/constants.ts (1)
  • config (1-11)
src/client/plane-client.ts (1)
  • PlaneClient (27-83)
src/models/AgentRun.ts (1)
  • AgentRun (34-50)
🔇 Additional comments (6)
tests/unit/agent-runs/agent-runs.test.ts (3)

1-6: LGTM!

Imports are well-organized and appropriate for the test suite. The conditional test pattern using describeIf is a good practice.


30-41: LGTM!

The test correctly verifies agent run creation with appropriate assertions on id, status, and workspace.


43-49: LGTM!

The retrieval test correctly verifies that the agent run can be fetched by ID. The test dependency on the previous test is acceptable for integration tests.

src/api/AgentRuns/index.ts (3)

1-16: LGTM!

The class structure follows the established pattern in the codebase. The nested Activities resource is properly initialized with the same configuration.


18-26: LGTM!

The create method is well-documented and follows RESTful conventions. The URL pattern and types are consistent with the codebase.


28-36: LGTM!

The retrieve method is well-implemented with proper documentation and type safety. The URL pattern correctly includes both workspace slug and run ID.

Comment on lines +28 to +30

# Agent configuration
TEST_AGENT_SLUG=your-agent-slug
Copy link

Choose a reason for hiding this comment

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

⚠️ Potential issue | 🔴 Critical

Remove duplicate TEST_AGENT_SLUG declaration.

The TEST_AGENT_SLUG variable is already declared at lines 11-12. This duplication will confuse users and could lead to configuration errors.

🔎 Apply this diff to remove the duplicate:
-# Agent configuration
-TEST_AGENT_SLUG=your-agent-slug
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
# Agent configuration
TEST_AGENT_SLUG=your-agent-slug
🤖 Prompt for AI Agents
In env.example around lines 28 to 30, there's a duplicate TEST_AGENT_SLUG
declaration that repeats the one at lines 11-12; remove the second declaration
(lines 28-30) so TEST_AGENT_SLUG is defined only once, leaving the original
entry at lines 11-12 intact and ensuring no extra blank lines or stray
whitespace remain.

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