feat: support zod v4 & v3 (#1052)

This commit is contained in:
Jim Geurts
2025-12-09 15:29:23 -06:00
committed by GitHub
parent c8321d2bc5
commit 576c3d9076
8 changed files with 87 additions and 3284 deletions
+5
View File
@@ -0,0 +1,5 @@
---
"llama-cloud-services": patch
---
Support zod v3 an v4
+10
View File
@@ -0,0 +1,10 @@
---
"llama-cloud-services": minor
---
feat: support zod v4 & v3
Adds support for zod v4 while maintaining backward compatibility with v3.
- Updated zod peer dependency to accept both v3 and v4: `^3.25.76 || ^4.0.0`
- Migrated all import statements to use `zod/v4` import path for compatibility
+48 -3260
View File
File diff suppressed because it is too large Load Diff
+7 -6
View File
@@ -116,9 +116,9 @@
"@eslint/js": "^9.32.0",
"@hey-api/client-fetch": "^0.10.1",
"@hey-api/openapi-ts": "^0.67.5",
"@llamaindex/core": "^0.6.19",
"@llamaindex/core": "^0.6.22",
"@llamaindex/env": "^0.1.30",
"@llamaindex/workflow-core": "^0.4.1",
"@llamaindex/workflow-core": "^1.3.3",
"@types/node": "^20.19.9",
"@typescript-eslint/eslint-plugin": "^8.38.0",
"@typescript-eslint/parser": "^8.38.0",
@@ -131,18 +131,19 @@
"turbo": "^2.5.5",
"typescript": "^5.8.3",
"typescript-eslint": "^8.38.0",
"vitest": "^2.0.0"
"vitest": "^2.0.0",
"zod": "^4.1.13"
},
"peerDependencies": {
"@llamaindex/core": "^0.6.19",
"@llamaindex/env": "^0.1.30",
"@llamaindex/workflow-core": "^0.4.1"
"@llamaindex/workflow-core": "^1.3.3",
"zod": "^3.25.0 || ^4.0.0"
},
"dependencies": {
"ajv": "^8.17.1",
"file-type": "^21.0.0",
"p-retry": "^6.2.1",
"zod": "^3.25.76"
"p-retry": "^6.2.1"
},
"packageManager": "pnpm@10.8.1"
}
@@ -1,6 +1,6 @@
// This file is auto-generated by @hey-api/openapi-ts
import { z } from "zod";
import { z } from "zod/v4";
export const zNoneSegmentationConfig = z.object({
mode: z.literal("none").optional().default("none"),
@@ -770,7 +770,7 @@ export const zMetadataFilter = z.object({
export const zFilterCondition: z.ZodTypeAny = z.enum(["and", "or", "not"]);
export const zMetadataFilters: z.AnyZodObject = z.object({
export const zMetadataFilters: z.ZodObject<z.ZodRawShape> = z.object({
filters: z.array(z.unknown()),
condition: z.union([zFilterCondition, z.null()]).optional(),
});
@@ -782,7 +782,7 @@ export const zRetrievalMode: z.ZodTypeAny = z.enum([
"auto_routed",
]);
export const zPresetRetrievalParams: z.AnyZodObject = z.object({
export const zPresetRetrievalParams: z.ZodObject<z.ZodRawShape> = z.object({
dense_similarity_top_k: z
.union([z.number().int().gte(1).lte(100), z.null()])
.optional(),
@@ -825,7 +825,7 @@ export const zSupportedLlmModelNames: z.ZodTypeAny = z.enum([
"VERTEX_AI_CLAUDE_3_5_SONNET_V2",
]);
export const zLlmParameters: z.AnyZodObject = z.object({
export const zLlmParameters: z.ZodObject<z.ZodRawShape> = z.object({
model_name: zSupportedLlmModelNames.optional(),
system_prompt: z.union([z.string().max(3000), z.null()]).optional(),
temperature: z.union([z.number(), z.null()]).optional(),
@@ -834,7 +834,7 @@ export const zLlmParameters: z.AnyZodObject = z.object({
class_name: z.string().optional().default("base_component"),
});
export const zChatData: z.AnyZodObject = z.object({
export const zChatData: z.ZodObject<z.ZodRawShape> = z.object({
retrieval_parameters: zPresetRetrievalParams.optional(),
llm_parameters: z.union([zLlmParameters, z.null()]).optional(),
class_name: z.string().optional().default("base_component"),
@@ -2141,7 +2141,7 @@ export const zTextItem = z.object({
value: z.string(),
});
export const zListItem: z.AnyZodObject = z.object({
export const zListItem: z.ZodObject<z.ZodRawShape> = z.object({
type: z.literal("list").optional().default("list"),
bBox: z.union([z.unknown(), z.null()]).optional(),
items: z.array(z.unknown()),
+1 -1
View File
@@ -1,6 +1,6 @@
import { workflowEvent } from "@llamaindex/workflow-core";
import { zodEvent } from "@llamaindex/workflow-core/util/zod";
import { z } from "zod";
import { z } from "zod/v4";
import { parseFormSchema } from "./schema";
export const uploadEvent = zodEvent(
+2 -4
View File
@@ -2,7 +2,7 @@ import type { JSONValue } from "@llamaindex/core/global";
import type { ToolMetadata } from "@llamaindex/core/llms";
import type { BaseQueryEngine } from "@llamaindex/core/query-engine";
import { tool } from "@llamaindex/core/tools";
import { z } from "zod";
import { z } from "zod/v4";
const DEFAULT_NAME = "llama_cloud_index_tool";
const DEFAULT_DESCRIPTION =
@@ -21,9 +21,7 @@ export function createQueryEngineTool(
name: metadata?.name ?? DEFAULT_NAME,
description: metadata?.description ?? DEFAULT_DESCRIPTION,
parameters: z.object({
query: z.string({
description: "The query to search for",
}),
query: z.string().describe("The query to search for"),
}),
execute: async ({ query }) => {
const response = await queryEngine.query({ query });
+8 -7
View File
@@ -1,6 +1,6 @@
import { FailPageMode, ParserLanguages, ParsingMode } from "./client";
import { z } from "zod";
import { z } from "zod/v4";
type Language = ParserLanguages;
const VALUES: [Language, ...Language[]] = [
@@ -52,9 +52,10 @@ export const parseFormSchema = z.object({
html_remove_navigation_elements: z.boolean().optional(),
http_proxy: z
.string()
.url(
'Set a valid URL for the HTTP proxy, e.g., "http://proxy.example.com:8080"',
)
.url({
error:
'Set a valid URL for the HTTP proxy, e.g., "http://proxy.example.com:8080"',
})
.refine(
(url) => {
try {
@@ -67,7 +68,7 @@ export const parseFormSchema = z.object({
}
},
{
message: "Invalid HTTP proxy URL",
error: "Invalid HTTP proxy URL",
},
)
.optional(),
@@ -100,7 +101,7 @@ export const parseFormSchema = z.object({
vendor_multimodal_model_name: z.string().optional(),
model: z.string().optional(),
webhook_url: z.string().url().optional(),
parse_mode: z.nativeEnum(ParsingMode).nullable().optional(),
parse_mode: z.enum(ParsingMode).nullable().optional(),
system_prompt: z.string().optional(),
system_prompt_append: z.string().optional(),
user_prompt: z.string().optional(),
@@ -129,7 +130,7 @@ export const parseFormSchema = z.object({
compact_markdown_table: z.boolean().optional(),
markdown_table_multiline_header_separator: z.string().optional(),
page_error_tolerance: z.number().min(0).max(1).optional(),
replace_failed_page_mode: z.nativeEnum(FailPageMode).nullable().optional(),
replace_failed_page_mode: z.enum(FailPageMode).nullable().optional(),
replace_failed_page_with_error_message_prefix: z.string().optional(),
replace_failed_page_with_error_message_suffix: z.string().optional(),
});