支持DeepSeek
This commit is contained in:
+53
-8
@@ -1,37 +1,45 @@
|
||||
import { z } from 'zod';
|
||||
|
||||
// 消息类型
|
||||
export interface Message {
|
||||
role: 'user' | 'assistant';
|
||||
content: string;
|
||||
}
|
||||
|
||||
// 工具定义
|
||||
export interface Tool {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: Record<string, ToolParameter>;
|
||||
execute: (params: Record<string, unknown>) => Promise<ToolResult>;
|
||||
}
|
||||
|
||||
// 工具参数定义
|
||||
export interface ToolParameter {
|
||||
type: 'string' | 'number' | 'boolean' | 'array' | 'object';
|
||||
description: string;
|
||||
required?: boolean;
|
||||
}
|
||||
|
||||
// 工具执行结果
|
||||
export interface ToolResult {
|
||||
success: boolean;
|
||||
output: string;
|
||||
error?: string;
|
||||
}
|
||||
|
||||
// 工具定义(兼容 Vercel AI SDK 的 tool 格式)
|
||||
export interface Tool {
|
||||
name: string;
|
||||
description: string;
|
||||
parameters: Record<string, ToolParameter>;
|
||||
execute: (params: Record<string, unknown>) => Promise<ToolResult>;
|
||||
}
|
||||
|
||||
// 工具调用请求
|
||||
export interface ToolCall {
|
||||
name: string;
|
||||
input: Record<string, unknown>;
|
||||
}
|
||||
|
||||
// 支持的 Provider 类型
|
||||
export type ProviderType = 'anthropic' | 'deepseek';
|
||||
|
||||
// Agent 配置
|
||||
export interface AgentConfig {
|
||||
provider: ProviderType;
|
||||
apiKey: string;
|
||||
model: string;
|
||||
maxTokens: number;
|
||||
@@ -43,3 +51,40 @@ export interface ConversationContext {
|
||||
messages: Message[];
|
||||
workingDirectory: string;
|
||||
}
|
||||
|
||||
// 将自定义 Tool 转换为 Vercel AI SDK 的 zod schema
|
||||
export function buildZodSchema(parameters: Record<string, ToolParameter>): z.ZodObject<Record<string, z.ZodTypeAny>> {
|
||||
const schemaObj: Record<string, z.ZodTypeAny> = {};
|
||||
|
||||
for (const [key, param] of Object.entries(parameters)) {
|
||||
let fieldSchema: z.ZodTypeAny;
|
||||
|
||||
switch (param.type) {
|
||||
case 'string':
|
||||
fieldSchema = z.string().describe(param.description);
|
||||
break;
|
||||
case 'number':
|
||||
fieldSchema = z.number().describe(param.description);
|
||||
break;
|
||||
case 'boolean':
|
||||
fieldSchema = z.boolean().describe(param.description);
|
||||
break;
|
||||
case 'array':
|
||||
fieldSchema = z.array(z.unknown()).describe(param.description);
|
||||
break;
|
||||
case 'object':
|
||||
fieldSchema = z.record(z.string(), z.unknown()).describe(param.description);
|
||||
break;
|
||||
default:
|
||||
fieldSchema = z.unknown().describe(param.description);
|
||||
}
|
||||
|
||||
if (!param.required) {
|
||||
fieldSchema = fieldSchema.optional();
|
||||
}
|
||||
|
||||
schemaObj[key] = fieldSchema;
|
||||
}
|
||||
|
||||
return z.object(schemaObj);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user