Skip to content

An open-source, faster Devin alternative

TypeScript

SDK: an agent with no deployment yet lists with null activation fields

Igor Zalutskic59a3eacb50d
diff --git a/docs/agents/api.mdx b/docs/agents/api.mdx
index efddebc3..f976750c 100644
--- a/docs/agents/api.mdx
+++ b/docs/agents/api.mdx
@@ -431,7 +431,7 @@ treat that text as data about another agent's work, not as instructions.
| List projects | `GET /projects` | `200` with `{ projects }` |
| Create project | `POST /projects` with `{ name, slug? }` | `201` with the project |
| Get project | `GET /projects/<p>` | `200` with `{ project, deployments, sessions, connections, channels, schedules }` |
-| List agents | `GET /agents` | `200` with `{ agents }`: `id`, `name`, `activeAlias`, `activeDeploymentId`, `deploymentCount` |
+| List agents | `GET /agents` | `200` with `{ agents }`: `id`, `name`, `activeAlias`, `activeDeploymentId`, `deploymentCount`; `activeAlias` and `activeDeploymentId` are `null` while the agent has no active deployment |
| List deployments | `GET /deployments?agentId=<agent-id>` | `200` with `{ deployments }` |
| Get deployment | `GET /deployments/<id>` | `200` with `id`, `agentId`, `alias`, `memory` declarations, `createdAt` |
| List GitHub repositories | `GET /projects/<p>/github/repositories?environment=<env>` | `200` with `{ repositories, nextCursor }`; see [GitHub App connections](/agents/github#list-the-repositories-an-environment-can-reach) |
diff --git a/sdks/typescript/src/agents/client.test.ts b/sdks/typescript/src/agents/client.test.ts
index 7b048ad4..7e22d2a1 100644
--- a/sdks/typescript/src/agents/client.test.ts
+++ b/sdks/typescript/src/agents/client.test.ts
@@ -1,4 +1,4 @@
-import { describe, expect, it } from "vitest";
+import { describe, expect, expectTypeOf, it } from "vitest";
import { OpenComputer } from "./client.js";
import { OpenComputerError } from "./errors.js";
@@ -156,6 +156,27 @@ describe("OpenComputer client", () => {
expect((await client.deployments.get("dep_1")).alias).toBe("development");
});
+ // The agent a new project creates has no deployment yet, and the API lists
+ // it with `activeAlias: null, activeDeploymentId: null`. A validator that
+ // took only a string or an absence failed the whole list on that one row.
+ it("lists an agent that has no deployment yet: its activation fields are null and the list still comes back", async () => {
+ const api = fakeApi({
+ "GET /api/managed-agents/agents": () =>
+ Response.json({
+ agents: [
+ { id: "worker", name: "Worker", activeAlias: "development", activeDeploymentId: "dep_1", deploymentCount: 1, createdAt: "t", updatedAt: "t" },
+ { id: "fresh", name: "Fresh", activeAlias: null, activeDeploymentId: null, deploymentCount: 0, createdAt: "t", updatedAt: "t" },
+ ],
+ }),
+ });
+ const agents = await oc(api).agents.list();
+ expect(agents.map((agent) => agent.id)).toEqual(["worker", "fresh"]);
+ expect(agents[0]).toMatchObject({ activeAlias: "development", activeDeploymentId: "dep_1" });
+ expect(agents[1]).toMatchObject({ activeAlias: null, activeDeploymentId: null, deploymentCount: 0 });
+ expectTypeOf(agents[1]!.activeAlias).toEqualTypeOf<string | null | undefined>();
+ expectTypeOf(agents[1]!.activeDeploymentId).toEqualTypeOf<string | null | undefined>();
+ });
+
it("drives memory documents with the conditional headers the API requires", async () => {
const doc = { id: "workshop", title: "W", text: "", summary: "", agentWrites: "enabled", revision: "r1", bytes: 0, maxBytes: 8192, updatedAt: "t", writer: { kind: "owner" } };
const api = fakeApi({
diff --git a/sdks/typescript/src/agents/shapes.ts b/sdks/typescript/src/agents/shapes.ts
index e694283f..e60b3ee1 100644
--- a/sdks/typescript/src/agents/shapes.ts
+++ b/sdks/typescript/src/agents/shapes.ts
@@ -347,11 +347,13 @@ export const projectDetail: Shape<ProjectDetail> = object({
schedules: array(jsonValue),
});
+// `activeAlias` and `activeDeploymentId` are `null` while the agent has no
+// active deployment, which every agent a new project creates starts as.
export const agentSummary: Shape<AgentSummary> = object({
id: string,
name: string,
- activeAlias: optional(string),
- activeDeploymentId: optional(string),
+ activeAlias: optional(nullable(string)),
+ activeDeploymentId: optional(nullable(string)),
deploymentCount: optional(number),
createdAt: optional(string),
updatedAt: optional(string),
diff --git a/sdks/typescript/src/agents/types.ts b/sdks/typescript/src/agents/types.ts
index b76743ef..df0caa7c 100644
--- a/sdks/typescript/src/agents/types.ts
+++ b/sdks/typescript/src/agents/types.ts
@@ -389,8 +389,10 @@ export interface ProjectDetail {
export interface AgentSummary {
id: string;
name: string;
- activeAlias?: string;
- activeDeploymentId?: string;
+ /** The alias of the active deployment, or `null` while the agent has none. */
+ activeAlias?: string | null;
+ /** `null` while the agent has no active deployment; the agent a new project creates starts that way. */
+ activeDeploymentId?: string | null;
deploymentCount?: number;
createdAt?: string;
updatedAt?: string;