Skip to content

The open-source app everyone uses to manage agents at work

fix: exclude terminated agents from list and org chart endpoints

Numman Ali7b334ff2b785
diff --git a/server/src/services/agents.ts b/server/src/services/agents.ts
index 54d4804586..703a3f955c 100644
--- a/server/src/services/agents.ts
+++ b/server/src/services/agents.ts
@@ -1,5 +1,5 @@
import { createHash, randomBytes } from "node:crypto";
-import { and, desc, eq, inArray } from "drizzle-orm";
+import { and, desc, eq, inArray, ne } from "drizzle-orm";
import type { Db } from "@paperclipai/db";
import {
agents,
@@ -251,8 +251,12 @@ export function agentService(db: Db) {
}
return {
- list: async (companyId: string) => {
- const rows = await db.select().from(agents).where(eq(agents.companyId, companyId));
+ list: async (companyId: string, options?: { includeTerminated?: boolean }) => {
+ const conditions = [eq(agents.companyId, companyId)];
+ if (!options?.includeTerminated) {
+ conditions.push(ne(agents.status, "terminated"));
+ }
+ const rows = await db.select().from(agents).where(and(...conditions));
return rows.map(normalizeAgentRow);
},
@@ -469,7 +473,10 @@ export function agentService(db: Db) {
},
orgForCompany: async (companyId: string) => {
- const rows = await db.select().from(agents).where(eq(agents.companyId, companyId));
+ const rows = await db
+ .select()
+ .from(agents)
+ .where(and(eq(agents.companyId, companyId), ne(agents.status, "terminated")));
const normalizedRows = rows.map(normalizeAgentRow);
const byManager = new Map<string | null, typeof normalizedRows>();
for (const row of normalizedRows) {
diff --git a/server/src/services/company-portability.ts b/server/src/services/company-portability.ts
index 8457588189..a80a334ae6 100644
--- a/server/src/services/company-portability.ts
+++ b/server/src/services/company-portability.ts
@@ -556,7 +556,7 @@ export function companyPortabilityService(db: Db) {
requiredSecrets: [],
};
- const allAgentRows = include.agents ? await agents.list(companyId) : [];
+ const allAgentRows = include.agents ? await agents.list(companyId, { includeTerminated: true }) : [];
const agentRows = allAgentRows.filter((agent) => agent.status !== "terminated");
if (include.agents) {
const skipped = allAgentRows.length - agentRows.length;