mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2025-12-29 14:31:35 +08:00
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:
parent
2201ebbb88
commit
100801821f
@ -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({
|
||||
|
||||
@ -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)
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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>
|
||||
|
||||
Loading…
Reference in New Issue
Block a user