Skip to content
12 changes: 6 additions & 6 deletions apps/sim/app/api/a2a/agents/[agentId]/route.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { db } from '@sim/db'
import { a2aAgent, workflow } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { eq } from 'drizzle-orm'
import { and, eq, isNull } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { generateAgentCard, generateSkillsFromWorkflow } from '@/lib/a2a/agent-card'
import type { AgentCapabilities, AgentSkill } from '@/lib/a2a/types'
Expand Down Expand Up @@ -31,8 +31,8 @@ export async function GET(request: NextRequest, { params }: { params: Promise<Ro
workflow: workflow,
})
.from(a2aAgent)
.innerJoin(workflow, eq(a2aAgent.workflowId, workflow.id))
.where(eq(a2aAgent.id, agentId))
.innerJoin(workflow, and(eq(a2aAgent.workflowId, workflow.id), isNull(workflow.archivedAt)))
.where(and(eq(a2aAgent.id, agentId), isNull(a2aAgent.archivedAt)))
.limit(1)

if (!agent) {
Expand Down Expand Up @@ -94,7 +94,7 @@ export async function PUT(request: NextRequest, { params }: { params: Promise<Ro
const [existingAgent] = await db
.select()
.from(a2aAgent)
.where(eq(a2aAgent.id, agentId))
.where(and(eq(a2aAgent.id, agentId), isNull(a2aAgent.archivedAt)))
.limit(1)

if (!existingAgent) {
Expand Down Expand Up @@ -164,7 +164,7 @@ export async function DELETE(request: NextRequest, { params }: { params: Promise
const [existingAgent] = await db
.select()
.from(a2aAgent)
.where(eq(a2aAgent.id, agentId))
.where(and(eq(a2aAgent.id, agentId), isNull(a2aAgent.archivedAt)))
.limit(1)

if (!existingAgent) {
Expand Down Expand Up @@ -203,7 +203,7 @@ export async function POST(request: NextRequest, { params }: { params: Promise<R
const [existingAgent] = await db
.select()
.from(a2aAgent)
.where(eq(a2aAgent.id, agentId))
.where(and(eq(a2aAgent.id, agentId), isNull(a2aAgent.archivedAt)))
.limit(1)

if (!existingAgent) {
Expand Down
22 changes: 17 additions & 5 deletions apps/sim/app/api/a2a/agents/route.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import { db } from '@sim/db'
import { a2aAgent, workflow } from '@sim/db/schema'
import { createLogger } from '@sim/logger'
import { and, eq, sql } from 'drizzle-orm'
import { and, eq, isNull, sql } from 'drizzle-orm'
import { type NextRequest, NextResponse } from 'next/server'
import { v4 as uuidv4 } from 'uuid'
import { generateSkillsFromWorkflow } from '@/lib/a2a/agent-card'
Expand Down Expand Up @@ -72,8 +72,8 @@ export async function GET(request: NextRequest) {
)`.as('task_count'),
})
.from(a2aAgent)
.leftJoin(workflow, eq(a2aAgent.workflowId, workflow.id))
.where(eq(a2aAgent.workspaceId, workspaceId))
.leftJoin(workflow, and(eq(a2aAgent.workflowId, workflow.id), isNull(workflow.archivedAt)))
.where(and(eq(a2aAgent.workspaceId, workspaceId), isNull(a2aAgent.archivedAt)))
.orderBy(a2aAgent.createdAt)

logger.info(`Listed ${agents.length} A2A agents for workspace ${workspaceId}`)
Expand Down Expand Up @@ -123,7 +123,13 @@ export async function POST(request: NextRequest) {
isDeployed: workflow.isDeployed,
})
.from(workflow)
.where(and(eq(workflow.id, workflowId), eq(workflow.workspaceId, workspaceId)))
.where(
and(
eq(workflow.id, workflowId),
eq(workflow.workspaceId, workspaceId),
isNull(workflow.archivedAt)
)
)
.limit(1)

if (!wf) {
Expand All @@ -144,7 +150,13 @@ export async function POST(request: NextRequest) {
const [existing] = await db
.select({ id: a2aAgent.id })
.from(a2aAgent)
.where(and(eq(a2aAgent.workspaceId, workspaceId), eq(a2aAgent.workflowId, workflowId)))
.where(
and(
eq(a2aAgent.workspaceId, workspaceId),
eq(a2aAgent.workflowId, workflowId),
isNull(a2aAgent.archivedAt)
)
)
.limit(1)

if (existing) {
Expand Down
Loading