mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 14:29:15 +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 { loggerService } from '@logger'
|
||||||
|
import { ListAgentsResponse } from '@types'
|
||||||
import { Request, Response } from 'express'
|
import { Request, Response } from 'express'
|
||||||
|
|
||||||
import { agentService } from '../../../../services/agents'
|
import { agentService } from '../../../../services/agents'
|
||||||
@ -131,7 +132,7 @@ export const listAgents = async (req: Request, res: Response): Promise<Response>
|
|||||||
total: result.total,
|
total: result.total,
|
||||||
limit,
|
limit,
|
||||||
offset
|
offset
|
||||||
})
|
} satisfies ListAgentsResponse)
|
||||||
} catch (error: any) {
|
} catch (error: any) {
|
||||||
logger.error('Error listing agents:', error)
|
logger.error('Error listing agents:', error)
|
||||||
return res.status(500).json({
|
return res.status(500).json({
|
||||||
|
|||||||
@ -6,7 +6,6 @@ import type {
|
|||||||
CreateAgentRequest,
|
CreateAgentRequest,
|
||||||
CreateAgentResponse,
|
CreateAgentResponse,
|
||||||
GetAgentResponse,
|
GetAgentResponse,
|
||||||
ListAgentsResponse,
|
|
||||||
ListOptions,
|
ListOptions,
|
||||||
UpdateAgentRequest,
|
UpdateAgentRequest,
|
||||||
UpdateAgentResponse
|
UpdateAgentResponse
|
||||||
@ -87,7 +86,7 @@ export class AgentService extends BaseService {
|
|||||||
return agent
|
return agent
|
||||||
}
|
}
|
||||||
|
|
||||||
async listAgents(options: ListOptions = {}): Promise<ListAgentsResponse> {
|
async listAgents(options: ListOptions = {}): Promise<{ agents: AgentEntity[]; total: number }> {
|
||||||
this.ensureInitialized() // Build query with pagination
|
this.ensureInitialized() // Build query with pagination
|
||||||
|
|
||||||
const totalResult = await this.database.select({ count: count() }).from(agentsTable)
|
const totalResult = await this.database.select({ count: count() }).from(agentsTable)
|
||||||
|
|||||||
@ -12,7 +12,7 @@ export const useAgents = () => {
|
|||||||
const key = client.agentPaths.base
|
const key = client.agentPaths.base
|
||||||
const fetcher = useCallback(async () => {
|
const fetcher = useCallback(async () => {
|
||||||
const result = await client.listAgents()
|
const result = await client.listAgents()
|
||||||
return result.agents
|
return result.data
|
||||||
}, [client])
|
}, [client])
|
||||||
const { data, error, isLoading, mutate } = useSWR(key, fetcher)
|
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 type GetAgentResponse = z.infer<typeof GetAgentResponseSchema>
|
||||||
|
|
||||||
export const ListAgentsResponseSchema = z.object({
|
export const ListAgentsResponseSchema = z.object({
|
||||||
agents: z.array(GetAgentResponseSchema),
|
data: z.array(GetAgentResponseSchema),
|
||||||
total: z.number()
|
total: z.int(),
|
||||||
|
limit: z.int(),
|
||||||
|
offset: z.int()
|
||||||
})
|
})
|
||||||
|
|
||||||
export type ListAgentsResponse = z.infer<typeof ListAgentsResponseSchema>
|
export type ListAgentsResponse = z.infer<typeof ListAgentsResponseSchema>
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user