fix(agents): update agents list response structure to match API

Align frontend and backend types for agents list response. The API now returns paginated data with limit/offset and renamed 'agents' field to 'data' for consistency. Update related type definitions and usage across the codebase.
This commit is contained in:
icarus 2025-09-18 22:26:54 +08:00
parent 2201ebbb88
commit 100801821f
4 changed files with 8 additions and 6 deletions

View File

@ -1,4 +1,5 @@
import { loggerService } from '@logger'
import { ListAgentsResponse } from '@types'
import { Request, Response } from 'express'
import { agentService } from '../../../../services/agents'
@ -131,7 +132,7 @@ export const listAgents = async (req: Request, res: Response): Promise<Response>
total: result.total,
limit,
offset
})
} satisfies ListAgentsResponse)
} catch (error: any) {
logger.error('Error listing agents:', error)
return res.status(500).json({

View File

@ -6,7 +6,6 @@ import type {
CreateAgentRequest,
CreateAgentResponse,
GetAgentResponse,
ListAgentsResponse,
ListOptions,
UpdateAgentRequest,
UpdateAgentResponse
@ -87,7 +86,7 @@ export class AgentService extends BaseService {
return agent
}
async listAgents(options: ListOptions = {}): Promise<ListAgentsResponse> {
async listAgents(options: ListOptions = {}): Promise<{ agents: AgentEntity[]; total: number }> {
this.ensureInitialized() // Build query with pagination
const totalResult = await this.database.select({ count: count() }).from(agentsTable)

View File

@ -12,7 +12,7 @@ export const useAgents = () => {
const key = client.agentPaths.base
const fetcher = useCallback(async () => {
const result = await client.listAgents()
return result.agents
return result.data
}, [client])
const { data, error, isLoading, mutate } = useSWR(key, fetcher)

View File

@ -171,8 +171,10 @@ export const GetAgentResponseSchema = AgentEntitySchema.extend({
export type GetAgentResponse = z.infer<typeof GetAgentResponseSchema>
export const ListAgentsResponseSchema = z.object({
agents: z.array(GetAgentResponseSchema),
total: z.number()
data: z.array(GetAgentResponseSchema),
total: z.int(),
limit: z.int(),
offset: z.int()
})
export type ListAgentsResponse = z.infer<typeof ListAgentsResponseSchema>