You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
32 lines
998 B
32 lines
998 B
import { z } from "zod";
|
|
|
|
export const searchConfigSchema = z.object({
|
|
engine: z
|
|
.enum(["bing", "baidu", "google"])
|
|
.default("bing")
|
|
.describe("搜索引擎: bing(必应), baidu(百度), google(谷歌)"),
|
|
maxResults: z.number().int().positive().max(20).default(10),
|
|
timeout: z.number().int().positive().max(30000).default(10000),
|
|
language: z.string().min(1).default("zh-CN"),
|
|
region: z.string().min(1).default("CN"),
|
|
snippetLength: z.number().int().positive().max(500).default(200),
|
|
});
|
|
|
|
export type SearchToolConfig = z.infer<typeof searchConfigSchema>;
|
|
|
|
export const DEFAULT_SEARCH_CONFIG: SearchToolConfig = {
|
|
engine: "bing",
|
|
maxResults: 10,
|
|
timeout: 10000,
|
|
language: "zh-CN",
|
|
region: "CN",
|
|
snippetLength: 200,
|
|
};
|
|
|
|
export function parseSearchConfig(raw: unknown): SearchToolConfig {
|
|
const parsed = searchConfigSchema.safeParse(raw);
|
|
if (!parsed.success) {
|
|
throw new Error(`Invalid search config: ${parsed.error.message}`);
|
|
}
|
|
return parsed.data;
|
|
}
|
|
|