Skip to content

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

Allow formats on agent schema (#2603)

Abimael Martell05c76d669a61
diff --git a/apps/api/package.json b/apps/api/package.json
index 2e3207a5c..e95239b4c 100644
--- a/apps/api/package.json
+++ b/apps/api/package.json
@@ -91,6 +91,7 @@
"@types/ws": "^8.5.12",
"ai": "5.0.89",
"ajv": "^8.16.0",
+ "ajv-formats": "^3.0.1",
"amqplib": "^0.10.9",
"async-mutex": "^0.5.0",
"axios": "^1.12.2",
diff --git a/apps/api/pnpm-lock.yaml b/apps/api/pnpm-lock.yaml
index 434b31320..33ab2f5bd 100644
--- a/apps/api/pnpm-lock.yaml
+++ b/apps/api/pnpm-lock.yaml
@@ -78,6 +78,9 @@ importers:
ajv:
specifier: ^8.16.0
version: 8.16.0
+ ajv-formats:
+ specifier: ^3.0.1
+ version: 3.0.1([email protected])
amqplib:
specifier: ^0.10.9
version: 0.10.9
@@ -3108,6 +3111,14 @@ packages:
peerDependencies:
zod: ^3.25.76 || ^4.1.8
+ resolution: {integrity: sha512-8iUql50EUR+uUcdRQ3HDqa6EVyo3docL8g5WJ3FNcWmu62IbkGUue/pEyLBW8VGKKucTPgqeks4fIU1DA4yowQ==}
+ peerDependencies:
+ ajv: ^8.0.0
+ peerDependenciesMeta:
+ ajv:
+ optional: true
+
resolution: {integrity: sha512-F0twR8U1ZU67JIEtekUcLkXkoO5mMMmgGD8sK/xUFzJ805jxHQl92hImFAqqXMyMYjSPOyUPAwHYhB72g5sTXw==}
@@ -6922,7 +6933,7 @@ snapshots:
idb-keyval: 6.2.1
preact: 10.24.2
transitivePeerDependencies:
- '@types/react'
@@ -6996,7 +7007,7 @@ snapshots:
idb-keyval: 6.2.1
preact: 10.24.2
transitivePeerDependencies:
- '@types/react'
@@ -7199,11 +7210,11 @@ snapshots:
ethereum-cryptography: 2.2.1
micro-ftch: 0.3.1
dependencies:
'@metamask/rpc-errors': 7.0.2
eventemitter3: 5.0.1
transitivePeerDependencies:
- supports-color
@@ -8529,7 +8540,7 @@ snapshots:
dependencies:
big.js: 6.2.2
dayjs: 1.11.13
transitivePeerDependencies:
- bufferutil
- typescript
@@ -8542,7 +8553,7 @@ snapshots:
'@reown/appkit-wallet': 1.7.8([email protected])([email protected])([email protected])
valtio: 1.13.2([email protected])
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -8688,7 +8699,7 @@ snapshots:
'@walletconnect/logger': 2.1.2
valtio: 1.13.2([email protected])
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -8741,7 +8752,7 @@ snapshots:
bs58: 6.0.0
valtio: 1.13.2([email protected])
transitivePeerDependencies:
- '@azure/app-configuration'
- '@azure/cosmos'
@@ -8782,7 +8793,7 @@ snapshots:
dependencies:
'@safe-global/safe-gateway-typescript-sdk': 3.23.1
transitivePeerDependencies:
- bufferutil
- typescript
@@ -9787,19 +9798,19 @@ snapshots:
'@vercel/[email protected]': {}
dependencies:
'@safe-global/safe-apps-provider': 0.18.6([email protected])([email protected])([email protected])([email protected])
cbw-sdk: '@coinbase/[email protected]'
optionalDependencies:
typescript: 5.8.3
transitivePeerDependencies:
@@ -9833,11 +9844,11 @@ snapshots:
- wagmi
- zod
dependencies:
eventemitter3: 5.0.1
mipd: 0.0.7([email protected])
optionalDependencies:
'@tanstack/query-core': 5.83.1
@@ -10390,11 +10401,6 @@ snapshots:
typescript: 5.8.3
zod: 3.25.76
- optionalDependencies:
- typescript: 5.8.3
- zod: 4.1.12
-
optionalDependencies:
typescript: 5.8.3
@@ -10449,6 +10455,10 @@ snapshots:
'@opentelemetry/api': 1.9.0
zod: 4.1.12
+ optionalDependencies:
+ ajv: 8.16.0
+
dependencies:
fast-deep-equal: 3.1.3
@@ -12883,21 +12893,6 @@ snapshots:
transitivePeerDependencies:
- zod
- dependencies:
- '@adraffy/ens-normalize': 1.11.1
- '@noble/ciphers': 1.3.0
- '@noble/curves': 1.9.6
- '@noble/hashes': 1.8.0
- '@scure/bip32': 1.7.0
- '@scure/bip39': 1.6.0
- eventemitter3: 5.0.1
- optionalDependencies:
- typescript: 5.8.3
- transitivePeerDependencies:
- - zod
-
dependencies:
'@adraffy/ens-normalize': 1.11.1
@@ -13108,21 +13103,21 @@ snapshots:
dependencies:
hono: 4.9.10
idb-keyval: 6.2.2
mipd: 0.0.7([email protected])
zod: 4.1.12
optionalDependencies:
'@tanstack/react-query': 5.84.1([email protected])
react: 18.3.1
typescript: 5.8.3
transitivePeerDependencies:
- '@types/react'
- immer
@@ -14052,35 +14047,18 @@ snapshots:
- utf-8-validate
- zod
- dependencies:
- '@noble/curves': 1.9.2
- '@noble/hashes': 1.8.0
- '@scure/bip32': 1.7.0
- '@scure/bip39': 1.6.0
- optionalDependencies:
- typescript: 5.8.3
- transitivePeerDependencies:
- - bufferutil
- - utf-8-validate
- - zod
-
dependencies:
xml-name-validator: 5.0.0
dependencies:
'@tanstack/react-query': 5.84.1([email protected])
react: 18.3.1
use-sync-external-store: 1.4.0([email protected])
optionalDependencies:
typescript: 5.8.3
transitivePeerDependencies:
@@ -14289,8 +14267,8 @@ snapshots:
zod: 3.25.76
transitivePeerDependencies:
- '@azure/app-configuration'
diff --git a/apps/api/src/controllers/v2/types.ts b/apps/api/src/controllers/v2/types.ts
index 64d1028e8..5f94b5738 100644
--- a/apps/api/src/controllers/v2/types.ts
+++ b/apps/api/src/controllers/v2/types.ts
@@ -19,6 +19,7 @@ import {
import type { InternalOptions } from "../../scraper/scrapeURL";
import { ErrorCodes } from "../../lib/error";
import Ajv from "ajv";
+import addFormats from "ajv-formats";
import { integrationSchema } from "../../utils/integration";
import { webhookSchema } from "../../services/webhook/schema";
import { BrandingProfile } from "../../types/branding";
@@ -635,6 +636,8 @@ export type BaseScrapeOptions = z.infer<typeof baseScrapeOptions>;
export type ScrapeOptions = BaseScrapeOptions;
const ajv = new Ajv();
+const agentAjv = new Ajv();
+addFormats(agentAjv);
const extractOptions = z
.strictObject({
@@ -714,20 +717,23 @@ export const agentRequestSchema = z.strictObject({
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;
- }
- },
- {
- error: "Invalid JSON schema.",
- },
- ),
+ .superRefine((val, ctx) => {
+ if (!val) return; // Allow undefined schema
+ try {
+ agentAjv.compile(val);
+ } catch (e) {
+ const message =
+ e instanceof Error
+ ? e.message
+ : typeof e === "string"
+ ? e
+ : "Unknown error";
+ ctx.addIssue({
+ code: "custom",
+ message: `Invalid JSON schema: ${message}`,
+ });
+ }
+ }),
origin: z.string().optional().prefault("api"),
integration: integrationSchema.optional().transform(val => val || null),
maxCredits: z.number().optional(),