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.
31 lines
1.0 KiB
31 lines
1.0 KiB
import { z } from "zod";
|
|
|
|
export const fetchConfigSchema = z.object({
|
|
defaultMethod: z.enum(["GET", "POST"]).default("GET"),
|
|
defaultHeaders: z.record(z.string(), z.string()).default({}),
|
|
timeout: z.number().int().positive().max(60000).default(10000),
|
|
maxResponseSize: z.number().int().positive().max(1048576).default(102400),
|
|
allowedDomains: z.array(z.string().min(1)).default(["*"]),
|
|
blockedDomains: z.array(z.string().min(1)).default([]),
|
|
parseMode: z.enum(["raw", "markdown", "json"]).default("markdown"),
|
|
});
|
|
|
|
export type FetchToolConfig = z.infer<typeof fetchConfigSchema>;
|
|
|
|
export const DEFAULT_FETCH_CONFIG: FetchToolConfig = {
|
|
defaultMethod: "GET",
|
|
defaultHeaders: {},
|
|
timeout: 10000,
|
|
maxResponseSize: 102400,
|
|
allowedDomains: ["*"],
|
|
blockedDomains: [],
|
|
parseMode: "markdown",
|
|
};
|
|
|
|
export function parseFetchConfig(raw: unknown): FetchToolConfig {
|
|
const parsed = fetchConfigSchema.safeParse(raw);
|
|
if (!parsed.success) {
|
|
throw new Error(`Invalid fetch config: ${parsed.error.message}`);
|
|
}
|
|
return parsed.data;
|
|
}
|
|
|