Refactor/migrate zod v4 (#10002)

* build: 更新 zod 依赖至 v4.1.5

* refactor: 将zod导入从'zod/v4'更新为'zod'

统一使用zod主包而非v4子路径,简化依赖管理

* refactor: 统一使用命名导入方式导入zod库

* refactor(mcpServers): 更新RequestPayloadSchema的url和headers类型定义

* refactor(mcp): 将默认值从pipe移动到string以简化schema

默认值'stdio'从pipe操作中移动到string操作,使schema定义更清晰

* refactor(Markdown): 简化 CitationSchema 中 url 的验证方式

* refactor: 将类型断言改为使用 satisfies 操作符

* build: 更新 aiCore 的 zod 依赖至 v4.1.5

* refactor: 更新zod导入方式并简化基础provider类型定义

将zod从'zod/v4'更新为'zod'导入
将baseProviderSchema替换为更简洁的接口类型定义

* fix(providers): 优化provider配置的schema定义并添加注释

调整creator函数的类型定义,增加输入输出类型约束
This commit is contained in:
Phantom
2025-09-07 16:39:22 +08:00
committed by GitHub
parent 4a5f374b7c
commit 0187f1780e
16 changed files with 38 additions and 36 deletions
@@ -1,7 +1,7 @@
import { Embeddings, type EmbeddingsParams } from '@langchain/core/embeddings'
import { chunkArray } from '@langchain/core/utils/chunk_array'
import { getEnvironmentVariable } from '@langchain/core/utils/env'
import z from 'zod/v4'
import { z } from 'zod'
const jinaModelSchema = z.union([
z.literal('jina-clip-v2'),
+1 -1
View File
@@ -3,7 +3,7 @@ import { loggerService } from '@logger'
import { Server } from '@modelcontextprotocol/sdk/server/index.js'
import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprotocol/sdk/types.js'
import { net } from 'electron'
import * as z from 'zod/v4'
import { z } from 'zod'
const logger = loggerService.withContext('DifyKnowledgeServer')
+2 -2
View File
@@ -8,8 +8,8 @@ import TurndownService from 'turndown'
import { z } from 'zod'
export const RequestPayloadSchema = z.object({
url: z.string().url(),
headers: z.record(z.string()).optional()
url: z.url(),
headers: z.record(z.string(), z.string()).optional()
})
export type RequestPayload = z.infer<typeof RequestPayloadSchema>
+1 -1
View File
@@ -8,7 +8,7 @@ import fs from 'fs/promises'
import { minimatch } from 'minimatch'
import os from 'os'
import path from 'path'
import * as z from 'zod/v4'
import { z } from 'zod'
const logger = loggerService.withContext('MCP:FileSystemServer')
@@ -30,7 +30,7 @@ import {
KnowledgeBaseParams,
KnowledgeSearchResult
} from '@types'
import { uuidv4 } from 'zod/v4'
import { uuidv4 } from 'zod'
import { windowService } from '../WindowService'
import {
@@ -82,7 +82,7 @@ export const memorySearchToolWithExtraction = (assistant: Assistant) => {
role: z.enum(['user', 'assistant', 'system']).describe('Message role')
})
.optional()
}) as z.ZodSchema<MemorySearchWithExtractionInput>,
}) satisfies z.ZodSchema<MemorySearchWithExtractionInput>,
execute: async ({ userMessage }) => {
// console.log('🧠 [memorySearchToolWithExtraction] Processing:', { userMessage, lastAnswer })
@@ -5,7 +5,7 @@ import styled from 'styled-components'
import { z } from 'zod'
export const CitationSchema = z.object({
url: z.string().url(),
url: z.url(),
title: z.string().optional(),
content: z.string().optional()
})
+1 -1
View File
@@ -2,7 +2,7 @@ import type { WebSearchResultBlock } from '@anthropic-ai/sdk/resources'
import type { GenerateImagesConfig, GroundingMetadata, PersonGeneration } from '@google/genai'
import type OpenAI from 'openai'
import type { CSSProperties } from 'react'
import * as z from 'zod/v4'
import { z } from 'zod'
export * from './file'
export * from './note'
+3 -4
View File
@@ -1,4 +1,4 @@
import z from 'zod'
import { z } from 'zod'
import { isBuiltinMCPServerName } from '.'
@@ -17,6 +17,7 @@ export type MCPConfigSample = z.infer<typeof MCPConfigSampleSchema>
*/
export const McpServerTypeSchema = z
.string()
.default('stdio')
.transform((type) => {
if (type.includes('http')) {
return 'streamableHttp'
@@ -24,9 +25,7 @@ export const McpServerTypeSchema = z
return type
}
})
.pipe(
z.union([z.literal('stdio'), z.literal('sse'), z.literal('streamableHttp'), z.literal('inMemory')]).default('stdio') // 大多数情况下默认使用 stdio
)
.pipe(z.union([z.literal('stdio'), z.literal('sse'), z.literal('streamableHttp'), z.literal('inMemory')])) // 大多数情况下默认使用 stdio
/**
* 定义单个 MCP 服务器的配置。
+1 -1
View File
@@ -1,4 +1,4 @@
import * as z from 'zod/v4'
import { z } from 'zod'
export type ToolType = 'builtin' | 'provider' | 'mcp'
+1 -1
View File
@@ -8,7 +8,7 @@ import {
} from '@renderer/types/error'
import { InvalidToolInputError, NoSuchToolError } from 'ai'
import { t } from 'i18next'
import z from 'zod'
import { z } from 'zod'
import { safeSerialize } from './serialize'