Skip to content

Supercharge your AI agents with data from the web and beyond. Building the library for superintelligence. 🔥

Update types.ts

Nicolasdd14744850b6
diff --git a/apps/api/src/controllers/v1/types.ts b/apps/api/src/controllers/v1/types.ts
index 8727f7066..1c9112c5e 100644
--- a/apps/api/src/controllers/v1/types.ts
+++ b/apps/api/src/controllers/v1/types.ts
@@ -186,6 +186,10 @@ export const scrapeOptions = z
export type ScrapeOptions = z.infer<typeof scrapeOptions>;
+import Ajv from "ajv";
+
+const ajv = new Ajv();
+
export const extractV1Options = z
.object({
urls: url
@@ -193,7 +197,20 @@ export const extractV1Options = z
.max(10, "Maximum of 10 URLs allowed per request while in beta."),
prompt: z.string().optional(),
systemPrompt: z.string().optional(),
- schema: z.any().optional(),
+ schema: z
+ .any()
+ .optional()
+ .refine((val) => {
+ if (!val) return true; // Allow undefined schema
+ try {
+ const validate = ajv.compile(val);
+ return typeof validate === "function";
+ } catch (e) {
+ return false;
+ }
+ }, {
+ message: "Invalid JSON schema.",
+ }),
limit: z.number().int().positive().finite().safe().optional(),
ignoreSitemap: z.boolean().default(false),
includeSubdomains: z.boolean().default(true),