mirror of
https://github.com/CherryHQ/cherry-studio.git
synced 2026-01-08 06:19:05 +08:00
refactor(types): convert AgentBase interface to zod schema
This change improves type safety and validation by replacing the TypeScript interface with a zod schema definition. The schema provides runtime validation while maintaining the same type inference capabilities.
This commit is contained in:
parent
ac3da51890
commit
0d0ab4dcf5
@ -34,27 +34,29 @@ export const AgentConfigurationSchema = z
|
|||||||
export type AgentConfiguration = z.infer<typeof AgentConfigurationSchema>
|
export type AgentConfiguration = z.infer<typeof AgentConfigurationSchema>
|
||||||
|
|
||||||
// Shared configuration interface for both agents and sessions
|
// Shared configuration interface for both agents and sessions
|
||||||
export interface AgentBase {
|
export const AgentBaseSchema = z.object({
|
||||||
// Basic info
|
// Basic info
|
||||||
name?: string
|
name: z.string().optional(),
|
||||||
description?: string
|
description: z.string().optional(),
|
||||||
accessible_paths: string[] // Array of directory paths the agent can access
|
accessible_paths: z.array(z.string()), // Array of directory paths the agent can access
|
||||||
|
|
||||||
// Instructions for the agent
|
// Instructions for the agent
|
||||||
instructions?: string // System prompt
|
instructions: z.string().optional(), // System prompt
|
||||||
|
|
||||||
// Models
|
// Models
|
||||||
model: string // Main Model ID (required)
|
model: z.string(), // Main Model ID (required)
|
||||||
plan_model?: string // Optional plan/thinking model ID
|
plan_model: z.string().optional(), // Optional plan/thinking model ID
|
||||||
small_model?: string // Optional small/fast model ID
|
small_model: z.string().optional(), // Optional small/fast model ID
|
||||||
|
|
||||||
// Tools
|
// Tools
|
||||||
mcps?: string[] // Array of MCP tool IDs
|
mcps: z.array(z.string()).optional(), // Array of MCP tool IDs
|
||||||
allowed_tools?: string[] // Array of allowed tool IDs (whitelist)
|
allowed_tools: z.array(z.string()).optional(), // Array of allowed tool IDs (whitelist)
|
||||||
|
|
||||||
// Configuration
|
// Configuration
|
||||||
configuration?: AgentConfiguration // Extensible settings like temperature, top_p, etc.
|
configuration: AgentConfigurationSchema.optional() // Extensible settings like temperature, top_p, etc.
|
||||||
}
|
})
|
||||||
|
|
||||||
|
export type AgentBase = z.infer<typeof AgentBaseSchema>
|
||||||
|
|
||||||
// Agent entity representing an autonomous agent configuration
|
// Agent entity representing an autonomous agent configuration
|
||||||
export interface AgentEntity extends AgentBase {
|
export interface AgentEntity extends AgentBase {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user