import { Injectable } from "@nestjs/common"; import { PrismaService } from "../../prisma/prisma.service"; import { AgentTreeResponseDto } from "./dto/agent-tree-response.dto"; @Injectable() export class AgentTreeService { constructor(private readonly prisma: PrismaService) {} async getTree(): Promise { const entries = await this.prisma.agentSessionTree.findMany({ orderBy: { spawnedAt: "desc" }, take: 200, }); const response: AgentTreeResponseDto[] = []; for (const entry of entries) { response.push({ sessionId: entry.sessionId, parentSessionId: entry.parentSessionId ?? null, status: entry.status, agentType: entry.agentType ?? null, taskSource: entry.taskSource ?? null, spawnedAt: entry.spawnedAt.toISOString(), completedAt: entry.completedAt?.toISOString() ?? null, }); } return response; } }