mirror of
https://github.com/shumaiOne/shumai.git
synced 2026-11-24 19:47:35 +00:00
111 lines
3.1 KiB
TypeScript
111 lines
3.1 KiB
TypeScript
import { z } from 'zod'
|
|
|
|
export const agentTypeSchema = z.enum(['chat', 'autofill', 'embedding'])
|
|
export type AgentType = z.infer<typeof agentTypeSchema>
|
|
|
|
export const thinkingLevelSchema = z.enum(['off', 'minimal', 'low', 'medium', 'high', 'xhigh'])
|
|
export type ThinkingLevel = z.infer<typeof thinkingLevelSchema>
|
|
|
|
export const agentSkillSchema = z.object({
|
|
id: z.string().optional(),
|
|
skillId: z.string(),
|
|
skill: z
|
|
.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
})
|
|
.optional(),
|
|
})
|
|
export type AgentSkill = z.infer<typeof agentSkillSchema>
|
|
|
|
export const agentInfoSchema = z.object({
|
|
id: z.string(),
|
|
name: z.string(),
|
|
type: agentTypeSchema,
|
|
enabled: z.boolean(),
|
|
avatar: z.string().optional(),
|
|
providerId: z.string().optional(),
|
|
modelId: z.string().optional(),
|
|
thinkingLevel: thinkingLevelSchema.optional().default('off'),
|
|
systemPrompt: z.string().optional(),
|
|
soul: z.string().optional(),
|
|
skills: z.array(agentSkillSchema).optional(),
|
|
})
|
|
export type AgentInfo = z.infer<typeof agentInfoSchema>
|
|
|
|
const baseAgentRequest = z.object({
|
|
name: z.string().min(1),
|
|
type: agentTypeSchema,
|
|
enabled: z.boolean().optional().default(true),
|
|
avatar: z.string().optional(),
|
|
providerId: z.string().optional(),
|
|
modelId: z.string().optional(),
|
|
thinkingLevel: thinkingLevelSchema.optional().default('off'),
|
|
systemPrompt: z.string().optional(),
|
|
soul: z.string().optional(),
|
|
skills: z.array(z.string()).optional(),
|
|
})
|
|
|
|
export const createAgentRequestSchema = baseAgentRequest.superRefine((data, ctx) => {
|
|
if (data.type === 'chat' || data.type === 'autofill') {
|
|
if (!data.providerId) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: 'providerId is required for chat/autofill agents',
|
|
path: ['providerId'],
|
|
})
|
|
}
|
|
if (!data.modelId) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: 'modelId is required for chat/autofill agents',
|
|
path: ['modelId'],
|
|
})
|
|
}
|
|
}
|
|
})
|
|
export type CreateAgentRequest = z.infer<typeof createAgentRequestSchema>
|
|
|
|
export const updateAgentRequestSchema = baseAgentRequest.superRefine((data, ctx) => {
|
|
if (data.type === 'chat' || data.type === 'autofill') {
|
|
if (!data.providerId) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: 'providerId is required for chat/autofill agents',
|
|
path: ['providerId'],
|
|
})
|
|
}
|
|
if (!data.modelId) {
|
|
ctx.addIssue({
|
|
code: z.ZodIssueCode.custom,
|
|
message: 'modelId is required for chat/autofill agents',
|
|
path: ['modelId'],
|
|
})
|
|
}
|
|
}
|
|
})
|
|
export type UpdateAgentRequest = z.infer<typeof updateAgentRequestSchema>
|
|
|
|
export interface CreateAgentParams extends CreateAgentRequest {
|
|
teamId: string
|
|
}
|
|
|
|
export interface UpdateAgentParams extends UpdateAgentRequest {
|
|
agentId: string
|
|
}
|
|
|
|
export interface DeleteAgentParams {
|
|
agentId: string
|
|
}
|
|
|
|
export interface ListAgentsParams {
|
|
teamId: string
|
|
}
|
|
|
|
export const agentSessionEntrySchema = z.object({
|
|
id: z.string(),
|
|
sessionId: z.string(),
|
|
entry: z.unknown(),
|
|
})
|
|
export type AgentSessionEntryInfo = z.infer<typeof agentSessionEntrySchema>
|