diff --git a/eslint.config.mjs b/eslint.config.mjs index be4a95cd60..fcc952ed65 100644 --- a/eslint.config.mjs +++ b/eslint.config.mjs @@ -2,6 +2,7 @@ import tseslint from '@electron-toolkit/eslint-config-ts' import eslint from '@eslint/js' import eslintReact from '@eslint-react/eslint-plugin' import { defineConfig } from 'eslint/config' +import importZod from 'eslint-plugin-import-zod' import oxlint from 'eslint-plugin-oxlint' import reactHooks from 'eslint-plugin-react-hooks' import simpleImportSort from 'eslint-plugin-simple-import-sort' @@ -15,7 +16,8 @@ export default defineConfig([ { plugins: { 'simple-import-sort': simpleImportSort, - 'unused-imports': unusedImports + 'unused-imports': unusedImports, + 'import-zod': importZod }, rules: { '@typescript-eslint/explicit-function-return-type': 'off', @@ -25,6 +27,7 @@ export default defineConfig([ 'simple-import-sort/exports': 'error', 'unused-imports/no-unused-imports': 'error', '@eslint-react/no-prop-types': 'error', + 'import-zod/prefer-zod-namespace': 'error' } }, // Configuration for ensuring compatibility with the original ESLint(8.x) rules diff --git a/package.json b/package.json index ad34ea1cc4..01c3dd534e 100644 --- a/package.json +++ b/package.json @@ -257,6 +257,7 @@ "emoji-picker-element": "^1.22.1", "epub": "patch:epub@npm%3A1.3.0#~/.yarn/patches/epub-npm-1.3.0-8325494ffe.patch", "eslint": "^9.22.0", + "eslint-plugin-import-zod": "^1.2.0", "eslint-plugin-oxlint": "^1.15.0", "eslint-plugin-react-hooks": "^5.2.0", "eslint-plugin-simple-import-sort": "^12.1.1", @@ -295,7 +296,7 @@ "notion-helper": "^1.3.22", "npx-scope-finder": "^1.2.0", "openai": "patch:openai@npm%3A5.12.2#~/.yarn/patches/openai-npm-5.12.2-30b075401c.patch", - "oxlint": "^1.15.0", + "oxlint": "^1.22.0", "oxlint-tsgolint": "^0.2.0", "p-queue": "^8.1.0", "pdf-lib": "^1.17.1", diff --git a/packages/aiCore/src/core/providers/schemas.ts b/packages/aiCore/src/core/providers/schemas.ts index 83338cf057..f5a8b60a29 100644 --- a/packages/aiCore/src/core/providers/schemas.ts +++ b/packages/aiCore/src/core/providers/schemas.ts @@ -13,7 +13,7 @@ import { LanguageModelV2 } from '@ai-sdk/provider' import { createXai } from '@ai-sdk/xai' import { createOpenRouter } from '@openrouter/ai-sdk-provider' import { customProvider, Provider } from 'ai' -import { z } from 'zod' +import * as z from 'zod' /** * 基础 Provider IDs diff --git a/src/main/mcpServers/dify-knowledge.ts b/src/main/mcpServers/dify-knowledge.ts index 04f010ce16..d1f2c07e1d 100644 --- a/src/main/mcpServers/dify-knowledge.ts +++ b/src/main/mcpServers/dify-knowledge.ts @@ -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 { z } from 'zod' +import * as z from 'zod' const logger = loggerService.withContext('DifyKnowledgeServer') diff --git a/src/main/mcpServers/fetch.ts b/src/main/mcpServers/fetch.ts index f170cc54c0..af7bf1ac6a 100644 --- a/src/main/mcpServers/fetch.ts +++ b/src/main/mcpServers/fetch.ts @@ -5,7 +5,7 @@ import { CallToolRequestSchema, ListToolsRequestSchema } from '@modelcontextprot import { net } from 'electron' import { JSDOM } from 'jsdom' import TurndownService from 'turndown' -import { z } from 'zod' +import * as z from 'zod' export const RequestPayloadSchema = z.object({ url: z.url(), diff --git a/src/main/mcpServers/filesystem.ts b/src/main/mcpServers/filesystem.ts index 9ec5ced0b0..ba10783881 100644 --- a/src/main/mcpServers/filesystem.ts +++ b/src/main/mcpServers/filesystem.ts @@ -8,7 +8,7 @@ import fs from 'fs/promises' import { minimatch } from 'minimatch' import os from 'os' import path from 'path' -import { z } from 'zod' +import * as z from 'zod' const logger = loggerService.withContext('MCP:FileSystemServer') diff --git a/src/main/services/mcp/oauth/types.ts b/src/main/services/mcp/oauth/types.ts index de631c1629..f081fbe70c 100644 --- a/src/main/services/mcp/oauth/types.ts +++ b/src/main/services/mcp/oauth/types.ts @@ -4,7 +4,7 @@ import { OAuthTokens } from '@modelcontextprotocol/sdk/shared/auth.js' import EventEmitter from 'events' -import { z } from 'zod' +import * as z from 'zod' export interface OAuthStorageData { clientInfo?: OAuthClientInformation diff --git a/src/main/services/ocr/builtin/PpocrService.ts b/src/main/services/ocr/builtin/PpocrService.ts index 2079f2d6b8..4b00be4bed 100644 --- a/src/main/services/ocr/builtin/PpocrService.ts +++ b/src/main/services/ocr/builtin/PpocrService.ts @@ -1,7 +1,7 @@ import { loadOcrImage } from '@main/utils/ocr' import { ImageFileMetadata, isImageFileMetadata, OcrPpocrConfig, OcrResult, SupportedOcrFile } from '@types' import { net } from 'electron' -import { z } from 'zod' +import * as z from 'zod' import { OcrBaseService } from './OcrBaseService' diff --git a/src/renderer/src/aiCore/tools/KnowledgeSearchTool.ts b/src/renderer/src/aiCore/tools/KnowledgeSearchTool.ts index 314eb9ba01..f3a4761894 100644 --- a/src/renderer/src/aiCore/tools/KnowledgeSearchTool.ts +++ b/src/renderer/src/aiCore/tools/KnowledgeSearchTool.ts @@ -4,7 +4,7 @@ import type { Assistant, KnowledgeReference } from '@renderer/types' import { ExtractResults, KnowledgeExtractResults } from '@renderer/utils/extract' import { type InferToolInput, type InferToolOutput, tool } from 'ai' import { isEmpty } from 'lodash' -import { z } from 'zod' +import * as z from 'zod' /** * 知识库搜索工具 diff --git a/src/renderer/src/aiCore/tools/MemorySearchTool.ts b/src/renderer/src/aiCore/tools/MemorySearchTool.ts index 8e67363595..20064dd1b2 100644 --- a/src/renderer/src/aiCore/tools/MemorySearchTool.ts +++ b/src/renderer/src/aiCore/tools/MemorySearchTool.ts @@ -1,7 +1,7 @@ import store from '@renderer/store' import { selectCurrentUserId, selectGlobalMemoryEnabled, selectMemoryConfig } from '@renderer/store/memory' import { type InferToolInput, type InferToolOutput, tool } from 'ai' -import { z } from 'zod' +import * as z from 'zod' import { MemoryProcessor } from '../../services/MemoryProcessor' diff --git a/src/renderer/src/aiCore/tools/WebSearchTool.ts b/src/renderer/src/aiCore/tools/WebSearchTool.ts index 2d6e318306..61d5d3b2c1 100644 --- a/src/renderer/src/aiCore/tools/WebSearchTool.ts +++ b/src/renderer/src/aiCore/tools/WebSearchTool.ts @@ -3,7 +3,7 @@ import WebSearchService from '@renderer/services/WebSearchService' import { WebSearchProvider, WebSearchProviderResponse } from '@renderer/types' import { ExtractResults } from '@renderer/utils/extract' import { type InferToolInput, type InferToolOutput, tool } from 'ai' -import { z } from 'zod' +import * as z from 'zod' /** * 使用预提取关键词的网络搜索工具 diff --git a/src/renderer/src/pages/home/Markdown/CitationTooltip.tsx b/src/renderer/src/pages/home/Markdown/CitationTooltip.tsx index 1c66be71c0..0458144c50 100644 --- a/src/renderer/src/pages/home/Markdown/CitationTooltip.tsx +++ b/src/renderer/src/pages/home/Markdown/CitationTooltip.tsx @@ -2,7 +2,7 @@ import Favicon from '@renderer/components/Icons/FallbackFavicon' import { Tooltip } from 'antd' import React, { memo, useCallback, useMemo } from 'react' import styled from 'styled-components' -import { z } from 'zod' +import * as z from 'zod' export const CitationSchema = z.object({ url: z.url(), diff --git a/src/renderer/src/types/agent.ts b/src/renderer/src/types/agent.ts index 542212af88..96a8e70b02 100644 --- a/src/renderer/src/types/agent.ts +++ b/src/renderer/src/types/agent.ts @@ -5,7 +5,7 @@ * WARNING: Any null value will be converted to undefined from api. */ import { ModelMessage, TextStreamPart } from 'ai' -import { z } from 'zod' +import * as z from 'zod' import type { Message, MessageBlock } from './newMessage' diff --git a/src/renderer/src/types/apiModels.ts b/src/renderer/src/types/apiModels.ts index 2a2aee6369..68141bf68c 100644 --- a/src/renderer/src/types/apiModels.ts +++ b/src/renderer/src/types/apiModels.ts @@ -1,5 +1,5 @@ import { Model } from '@types' -import { z } from 'zod' +import * as z from 'zod' import { ProviderTypeSchema } from './provider' diff --git a/src/renderer/src/types/provider.ts b/src/renderer/src/types/provider.ts index fd87397a47..e5233c196e 100644 --- a/src/renderer/src/types/provider.ts +++ b/src/renderer/src/types/provider.ts @@ -1,5 +1,5 @@ import { Model } from '@types' -import z from 'zod' +import * as z from 'zod' export const ProviderTypeSchema = z.enum([ 'openai', diff --git a/src/renderer/src/types/tool.ts b/src/renderer/src/types/tool.ts index ad6f2727e1..c803c76fcb 100644 --- a/src/renderer/src/types/tool.ts +++ b/src/renderer/src/types/tool.ts @@ -1,4 +1,4 @@ -import { z } from 'zod' +import * as z from 'zod' export type ToolType = 'builtin' | 'provider' | 'mcp' diff --git a/src/renderer/src/utils/bocha.ts b/src/renderer/src/utils/bocha.ts index 45d83cd8bf..485a17cb76 100644 --- a/src/renderer/src/utils/bocha.ts +++ b/src/renderer/src/utils/bocha.ts @@ -1,4 +1,4 @@ -import { z } from 'zod' +import * as z from 'zod' export const freshnessOptions = ['oneDay', 'oneWeek', 'oneMonth', 'oneYear', 'noLimit'] as const diff --git a/src/renderer/src/utils/error.ts b/src/renderer/src/utils/error.ts index 6f15e86d20..737baf4119 100644 --- a/src/renderer/src/utils/error.ts +++ b/src/renderer/src/utils/error.ts @@ -11,7 +11,8 @@ import { import { InvalidToolInputError, NoSuchToolError } from 'ai' import { AxiosError, isAxiosError } from 'axios' import { t } from 'i18next' -import { z, ZodError } from 'zod' +import * as z from 'zod' +import { ZodError } from 'zod' import { parseJSON } from './json' import { safeSerialize } from './serialize' diff --git a/src/renderer/src/utils/memory-prompts.ts b/src/renderer/src/utils/memory-prompts.ts index 3b4589c652..c704cbc1d7 100644 --- a/src/renderer/src/utils/memory-prompts.ts +++ b/src/renderer/src/utils/memory-prompts.ts @@ -1,4 +1,4 @@ -import { z } from 'zod' +import * as z from 'zod' // Define Zod schema for fact retrieval output export const FactRetrievalSchema = z.object({ diff --git a/yarn.lock b/yarn.lock index 4ec7b1315e..04d8ecec25 100644 --- a/yarn.lock +++ b/yarn.lock @@ -7815,58 +7815,58 @@ __metadata: languageName: node linkType: hard -"@oxlint/darwin-arm64@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/darwin-arm64@npm:1.15.0" +"@oxlint/darwin-arm64@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/darwin-arm64@npm:1.22.0" conditions: os=darwin & cpu=arm64 languageName: node linkType: hard -"@oxlint/darwin-x64@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/darwin-x64@npm:1.15.0" +"@oxlint/darwin-x64@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/darwin-x64@npm:1.22.0" conditions: os=darwin & cpu=x64 languageName: node linkType: hard -"@oxlint/linux-arm64-gnu@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/linux-arm64-gnu@npm:1.15.0" +"@oxlint/linux-arm64-gnu@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/linux-arm64-gnu@npm:1.22.0" conditions: os=linux & cpu=arm64 & libc=glibc languageName: node linkType: hard -"@oxlint/linux-arm64-musl@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/linux-arm64-musl@npm:1.15.0" +"@oxlint/linux-arm64-musl@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/linux-arm64-musl@npm:1.22.0" conditions: os=linux & cpu=arm64 & libc=musl languageName: node linkType: hard -"@oxlint/linux-x64-gnu@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/linux-x64-gnu@npm:1.15.0" +"@oxlint/linux-x64-gnu@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/linux-x64-gnu@npm:1.22.0" conditions: os=linux & cpu=x64 & libc=glibc languageName: node linkType: hard -"@oxlint/linux-x64-musl@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/linux-x64-musl@npm:1.15.0" +"@oxlint/linux-x64-musl@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/linux-x64-musl@npm:1.22.0" conditions: os=linux & cpu=x64 & libc=musl languageName: node linkType: hard -"@oxlint/win32-arm64@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/win32-arm64@npm:1.15.0" +"@oxlint/win32-arm64@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/win32-arm64@npm:1.22.0" conditions: os=win32 & cpu=arm64 languageName: node linkType: hard -"@oxlint/win32-x64@npm:1.15.0": - version: 1.15.0 - resolution: "@oxlint/win32-x64@npm:1.15.0" +"@oxlint/win32-x64@npm:1.22.0": + version: 1.22.0 + resolution: "@oxlint/win32-x64@npm:1.22.0" conditions: os=win32 & cpu=x64 languageName: node linkType: hard @@ -14423,6 +14423,7 @@ __metadata: emoji-picker-element: "npm:^1.22.1" epub: "patch:epub@npm%3A1.3.0#~/.yarn/patches/epub-npm-1.3.0-8325494ffe.patch" eslint: "npm:^9.22.0" + eslint-plugin-import-zod: "npm:^1.2.0" eslint-plugin-oxlint: "npm:^1.15.0" eslint-plugin-react-hooks: "npm:^5.2.0" eslint-plugin-simple-import-sort: "npm:^12.1.1" @@ -14467,7 +14468,7 @@ __metadata: officeparser: "npm:^4.2.0" openai: "patch:openai@npm%3A5.12.2#~/.yarn/patches/openai-npm-5.12.2-30b075401c.patch" os-proxy-config: "npm:^1.1.2" - oxlint: "npm:^1.15.0" + oxlint: "npm:^1.22.0" oxlint-tsgolint: "npm:^0.2.0" p-queue: "npm:^8.1.0" pdf-lib: "npm:^1.17.1" @@ -18590,6 +18591,16 @@ __metadata: languageName: node linkType: hard +"eslint-plugin-import-zod@npm:^1.2.0": + version: 1.2.0 + resolution: "eslint-plugin-import-zod@npm:1.2.0" + peerDependencies: + "@typescript-eslint/utils": ^8.35.1 + eslint: ">=9" + checksum: 10c0/c03f3059c4e55fa50ad43da6db989bb4c51c6466ab17bd7ec7d096421d060a20488ee1ef0df80fa61706ad0b6a4534622540ceab0638d3b6887df7d810ef1d22 + languageName: node + linkType: hard + "eslint-plugin-oxlint@npm:^1.15.0": version: 1.15.0 resolution: "eslint-plugin-oxlint@npm:1.15.0" @@ -24597,18 +24608,18 @@ __metadata: languageName: node linkType: hard -"oxlint@npm:^1.15.0": - version: 1.15.0 - resolution: "oxlint@npm:1.15.0" +"oxlint@npm:^1.22.0": + version: 1.22.0 + resolution: "oxlint@npm:1.22.0" dependencies: - "@oxlint/darwin-arm64": "npm:1.15.0" - "@oxlint/darwin-x64": "npm:1.15.0" - "@oxlint/linux-arm64-gnu": "npm:1.15.0" - "@oxlint/linux-arm64-musl": "npm:1.15.0" - "@oxlint/linux-x64-gnu": "npm:1.15.0" - "@oxlint/linux-x64-musl": "npm:1.15.0" - "@oxlint/win32-arm64": "npm:1.15.0" - "@oxlint/win32-x64": "npm:1.15.0" + "@oxlint/darwin-arm64": "npm:1.22.0" + "@oxlint/darwin-x64": "npm:1.22.0" + "@oxlint/linux-arm64-gnu": "npm:1.22.0" + "@oxlint/linux-arm64-musl": "npm:1.22.0" + "@oxlint/linux-x64-gnu": "npm:1.22.0" + "@oxlint/linux-x64-musl": "npm:1.22.0" + "@oxlint/win32-arm64": "npm:1.22.0" + "@oxlint/win32-x64": "npm:1.22.0" peerDependencies: oxlint-tsgolint: ">=0.2.0" dependenciesMeta: @@ -24634,7 +24645,7 @@ __metadata: bin: oxc_language_server: bin/oxc_language_server oxlint: bin/oxlint - checksum: 10c0/3eb2a27b972f2a02200b068345ab6a3a17f7bc29c4546c6b3478727388d8d59b94a554f9b6bb1320b71a75cc598b728de0ffee5e4e70ac27457104b8efebb257 + checksum: 10c0/652c93b9360ea66c7ee87f649a56ba2b8eddc5e32494a53a61ca86749d87ce2be354960e135a60ab7054105e6b187e9d4ec56959cdb02d517423c23d6a523894 languageName: node linkType: hard