feat(dashboard): add agent sessions view for team owners

This commit is contained in:
yiling
2026-07-29 10:10:07 +08:00
parent 825044f16d
commit 03f8ad90d2
34 changed files with 1249 additions and 334 deletions
+60 -1
View File
@@ -1,10 +1,16 @@
import { prisma } from '@shumai/db'
import { prisma, type Prisma } from '@shumai/db'
import {
CreateAgentParams,
DeleteAgentParams,
ListAgentsParams,
UpdateAgentParams,
AgentSessionInfo,
} from '@shumai/dtos'
import {
paginateQuery,
type PaginatedData,
type PaginationParams,
} from '@shumai/core/src/pagination'
import '@shumai/db/src/prisma-json-types'
import { s3Service } from '@shumai/core/src/s3/s3'
import AdmZip from 'adm-zip'
@@ -388,6 +394,59 @@ export class AgentService {
}
})
}
async listSessions(
teamId: string,
params: PaginationParams,
): Promise<PaginatedData<AgentSessionInfo[]>> {
const where: Prisma.AgentSessionWhereInput = {
id: { not: 'pending' },
agent: {
teamId,
},
}
return await paginateQuery(
async (skip, take) => {
const sessions = await this.prismaClient.agentSession.findMany({
where,
skip,
take,
orderBy: { id: 'desc' },
include: {
user: {
select: {
id: true,
name: true,
email: true,
image: true,
},
},
},
})
return sessions.map((s) => ({
id: s.id,
name: s.name,
type: s.type,
createdAt: s.createdAt.toISOString(),
creator: s.user
? {
id: s.user.id,
name: s.user.name,
email: s.user.email,
image: s.user.image,
}
: null,
agentId: s.agentId,
}))
},
async () => {
return this.prismaClient.agentSession.count({ where })
},
params,
)
}
}
export const agentService = new AgentService()