chore: fix vite warning on dynamic imports (#7852)

This commit is contained in:
one 2025-07-05 15:08:02 +08:00 committed by GitHub
parent 19e9ba773f
commit 1ebf546b70
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 9 additions and 23 deletions

View File

@ -1,22 +1,12 @@
import { linter } from '@codemirror/lint' // statically imported by @uiw/codemirror-extensions-basic-setup
import { useCodeStyle } from '@renderer/context/CodeStyleProvider'
import { Extension } from '@uiw/react-codemirror'
import { useEffect, useState } from 'react'
let linterPromise: Promise<any> | null = null
function importLintPackage() {
if (!linterPromise) {
linterPromise = import('@codemirror/lint').then((mod) => mod.linter)
}
return linterPromise
}
// 语言对应的 linter 加载器
const linterLoaders: Record<string, () => Promise<any>> = {
json: async () => {
const [linter, jsonParseLinter] = await Promise.all([
importLintPackage(),
import('@codemirror/lang-json').then((mod) => mod.jsonParseLinter)
])
const jsonParseLinter = await import('@codemirror/lang-json').then((mod) => mod.jsonParseLinter)
return linter(jsonParseLinter())
}
}

View File

@ -1,3 +1,4 @@
import { DEFAULT_MIN_APPS } from '@renderer/config/minapps'
import { useRuntime } from '@renderer/hooks/useRuntime'
import { useSettings } from '@renderer/hooks/useSettings' // 使用设置中的值
import { useAppDispatch } from '@renderer/store'
@ -74,12 +75,10 @@ export const useMinappPopup = () => {
/** Open a minapp by id (look up the minapp in DEFAULT_MIN_APPS) */
const openMinappById = useCallback(
(id: string, keepAlive: boolean = false) => {
import('@renderer/config/minapps').then(({ DEFAULT_MIN_APPS }) => {
const app = DEFAULT_MIN_APPS.find((app) => app?.id === id)
if (app) {
openMinapp(app, keepAlive)
}
})
},
[openMinapp]
)

View File

@ -1,5 +1,6 @@
import db from '@renderer/databases'
import i18n from '@renderer/i18n'
import { fetchMessagesSummary } from '@renderer/services/ApiService'
import { EVENT_NAMES, EventEmitter } from '@renderer/services/EventService'
import { deleteMessageFiles } from '@renderer/services/MessagesService'
import store from '@renderer/store'
@ -133,8 +134,6 @@ export const autoRenameTopic = async (assistant: Assistant, topicId: string) =>
if (topic && topic.name === i18n.t('chat.default.topic.name') && topic.messages.length >= 2) {
try {
startTopicRenaming(topicId)
const { fetchMessagesSummary } = await import('@renderer/services/ApiService')
const summaryText = await fetchMessagesSummary({ messages: topic.messages, assistant })
if (summaryText) {
const data = { ...topic, name: summaryText }

View File

@ -22,6 +22,7 @@ import { fetchWebContents } from '@renderer/utils/fetch'
import { consolidateReferencesByUrl, selectReferences } from '@renderer/utils/websearch'
import dayjs from 'dayjs'
import { LRUCache } from 'lru-cache'
import { sliceByTokens } from 'tokenx'
import { getKnowledgeBaseParams } from './KnowledgeService'
import { getKnowledgeSourceUrl, searchKnowledgeBase } from './KnowledgeService'
@ -384,9 +385,6 @@ class WebSearchService {
const perResultLimit = Math.max(1, Math.floor(config.cutoffLimit / rawResults.length))
// 动态导入 tokenx
const { sliceByTokens } = await import('tokenx')
return rawResults.map((result) => {
if (config.cutoffUnit === 'token') {
// 使用 token 截断