diff --git a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx index 4f019b0621..375524023c 100644 --- a/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx +++ b/web/app/(commonLayout)/app/(appDetailLayout)/[appId]/overview/cardView.tsx @@ -17,6 +17,7 @@ import type { App } from '@/types/app' import type { UpdateAppSiteCodeResponse } from '@/models/app' import { asyncRunSafe } from '@/utils' import { NEED_REFRESH_APP_LIST_KEY } from '@/config' +import type { IAppCardProps } from '@/app/components/app/overview/appCard' export type ICardViewProps = { appId: string @@ -68,7 +69,7 @@ const CardView: FC = ({ appId }) => { handleError(err) } - const onSaveSiteConfig = async (params: any) => { + const onSaveSiteConfig: IAppCardProps['onSaveSiteConfig'] = async (params) => { const [err] = await asyncRunSafe( updateAppSiteConfig({ url: `/apps/${appId}/site`, diff --git a/web/app/components/app/chat/answer/index.tsx b/web/app/components/app/chat/answer/index.tsx index ab0f910abb..eb7103559d 100644 --- a/web/app/components/app/chat/answer/index.tsx +++ b/web/app/components/app/chat/answer/index.tsx @@ -225,7 +225,7 @@ const Answer: FC = ({ item, feedbackDisabled = false, isHideFeedba setLoading(true) const res = await onSubmitAnnotation?.(id, inputValue) if (res) - setAnnotation({ ...annotation, content: inputValue } as any) + setAnnotation({ ...annotation, content: inputValue } as Annotation) setLoading(false) setShowEdit(false) }}>{t('common.operation.confirm')} diff --git a/web/app/components/app/chat/index.tsx b/web/app/components/app/chat/index.tsx index 88da1905b9..5f67001d98 100644 --- a/web/app/components/app/chat/index.tsx +++ b/web/app/components/app/chat/index.tsx @@ -81,7 +81,7 @@ const Chat: FC = ({ const isUseInputMethod = useRef(false) const [query, setQuery] = React.useState('') - const handleContentChange = (e: any) => { + const handleContentChange = (e: React.ChangeEvent) => { const value = e.target.value setQuery(value) } @@ -111,7 +111,7 @@ const Chat: FC = ({ setQuery('') } - const handleKeyUp = (e: any) => { + const handleKeyUp = (e: React.KeyboardEvent) => { if (e.code === 'Enter') { e.preventDefault() // prevent send message when using input method enter @@ -120,7 +120,7 @@ const Chat: FC = ({ } } - const handleKeyDown = (e: any) => { + const handleKeyDown = (e: React.KeyboardEvent) => { isUseInputMethod.current = e.nativeEvent.isComposing if (e.code === 'Enter' && !e.shiftKey) { setQuery(query.replace(/\n$/, '')) diff --git a/web/app/components/app/configuration/config-var/input-type-icon.tsx b/web/app/components/app/configuration/config-var/input-type-icon.tsx index ff59a48bda..b45ec922c2 100644 --- a/web/app/components/app/configuration/config-var/input-type-icon.tsx +++ b/web/app/components/app/configuration/config-var/input-type-icon.tsx @@ -1,19 +1,19 @@ 'use client' -import React, { FC, ReactNode } from 'react' -import { ReactElement } from 'react-markdown/lib/react-markdown' +import React from 'react' +import type { FC } from 'react' -export interface IInputTypeIconProps { - type: string +type IInputTypeIconProps = { + type: 'string' | 'select' } -const IconMap = (type: string) => { - const icons: Record = { - 'string': ( +const IconMap = (type: IInputTypeIconProps['type']) => { + const icons = { + string: ( ), - 'select': ( + select: ( @@ -21,11 +21,11 @@ const IconMap = (type: string) => { ), } - return icons[type] as any + return icons[type] } const InputTypeIcon: FC = ({ - type + type, }) => { const Icon = IconMap(type) return Icon diff --git a/web/app/components/app/configuration/dataset-config/card-item/index.tsx b/web/app/components/app/configuration/dataset-config/card-item/index.tsx index 2ad7ad0d66..0f5721fd65 100644 --- a/web/app/components/app/configuration/dataset-config/card-item/index.tsx +++ b/web/app/components/app/configuration/dataset-config/card-item/index.tsx @@ -6,22 +6,17 @@ import { useTranslation } from 'react-i18next' import TypeIcon from '../type-icon' import RemoveIcon from '../../base/icons/remove-icon' import s from './style.module.css' +import type { DataSet } from '@/models/datasets' import { formatNumber } from '@/utils/format' import Tooltip from '@/app/components/base/tooltip' export type ICardItemProps = { className?: string - config: any + config: DataSet onRemove: (id: string) => void readonly?: boolean } -// const RemoveIcon = ({ className, onClick }: { className: string, onClick: () => void }) => ( -// -// -// -// ) - const CardItem: FC = ({ className, config, diff --git a/web/app/components/app/overview/appCard.tsx b/web/app/components/app/overview/appCard.tsx index 1700ddacf3..5c4ae75239 100644 --- a/web/app/components/app/overview/appCard.tsx +++ b/web/app/components/app/overview/appCard.tsx @@ -13,6 +13,7 @@ import SettingsModal from './settings' import EmbeddedModal from './embedded' import CustomizeModal from './customize' import style from './style.module.css' +import type { ConfigParams } from './settings' import Tooltip from '@/app/components/base/tooltip' import AppBasic from '@/app/components/app-sidebar/basic' import { asyncRunSafe, randomString } from '@/utils' @@ -31,9 +32,9 @@ export type IAppCardProps = { appInfo: AppDetailResponse cardType?: 'api' | 'webapp' customBgColor?: string - onChangeStatus: (val: boolean) => Promise - onSaveSiteConfig?: (params: any) => Promise - onGenerateCode?: () => Promise + onChangeStatus: (val: boolean) => Promise + onSaveSiteConfig?: (params: ConfigParams) => Promise + onGenerateCode?: () => Promise } const EmbedIcon: FC<{ className?: string }> = ({ className = '' }) => { @@ -193,7 +194,7 @@ function AppCard({
{!isApp && } - {OPERATIONS_MAP[cardType].map((op: any) => { + {OPERATIONS_MAP[cardType].map((op) => { const disabled = op.opName === t('appOverview.overview.appInfo.settings.entry') ? false diff --git a/web/app/components/app/overview/settings/index.tsx b/web/app/components/app/overview/settings/index.tsx index 8b995c8bfa..c575ed83fc 100644 --- a/web/app/components/app/overview/settings/index.tsx +++ b/web/app/components/app/overview/settings/index.tsx @@ -18,7 +18,7 @@ export type ISettingsModalProps = { isShow: boolean defaultValue?: string onClose: () => void - onSave?: (params: ConfigParams) => Promise + onSave?: (params: ConfigParams) => Promise } export type ConfigParams = { @@ -26,6 +26,10 @@ export type ConfigParams = { description: string default_language: string prompt_public: boolean + copyright: string + privacy_policy: string + icon: string + icon_background: string } const LANGUAGE_MAP: Record = { @@ -82,7 +86,7 @@ const SettingsModal: FC = ({ } const onChange = (field: string) => { - return (e: any) => { + return (e: React.ChangeEvent) => { setInputInfo(item => ({ ...item, [field]: e.target.value })) } } diff --git a/web/app/components/app/text-generate/item/index.tsx b/web/app/components/app/text-generate/item/index.tsx index 8798b9f838..c85acdd58f 100644 --- a/web/app/components/app/text-generate/item/index.tsx +++ b/web/app/components/app/text-generate/item/index.tsx @@ -10,7 +10,7 @@ import { HashtagIcon } from '@heroicons/react/24/solid' import { Markdown } from '@/app/components/base/markdown' import Loading from '@/app/components/base/loading' import Toast from '@/app/components/base/toast' -import type { Feedbacktype } from '@/app/components/app/chat' +import type { Feedbacktype } from '@/app/components/app/chat/type' import { fetchMoreLikeThis, updateFeedback } from '@/service/share' const MAX_DEPTH = 3 @@ -136,7 +136,7 @@ const GenerationItem: FC = ({ } const mainStyle = (() => { - const res: any = !isTop + const res: React.CSSProperties = !isTop ? { background: depth % 2 === 0 ? 'linear-gradient(90.07deg, #F9FAFB 0.05%, rgba(249, 250, 251, 0) 99.93%)' : '#fff', } diff --git a/web/app/components/base/portal-to-follow-elem/index.tsx b/web/app/components/base/portal-to-follow-elem/index.tsx index 912114fd98..28ef0f3732 100644 --- a/web/app/components/base/portal-to-follow-elem/index.tsx +++ b/web/app/components/base/portal-to-follow-elem/index.tsx @@ -1,9 +1,10 @@ 'use client' import { useBoolean } from 'ahooks' -import React, { FC, useEffect, useState, useRef } from 'react' +import React, { useEffect, useRef, useState } from 'react' +import type { FC } from 'react' import { createRoot } from 'react-dom/client' -export interface IPortalToFollowElementProps { +type IPortalToFollowElementProps = { portalElem: React.ReactNode children: React.ReactNode controlShow?: number @@ -14,44 +15,42 @@ const PortalToFollowElement: FC = ({ portalElem, children, controlShow, - controlHide + controlHide, }) => { const [isShowContent, { setTrue: showContent, setFalse: hideContent, toggle: toggleContent }] = useBoolean(false) const [wrapElem, setWrapElem] = useState(null) useEffect(() => { - if (controlShow) { + if (controlShow) showContent() - } }, [controlShow]) useEffect(() => { - if (controlHide) { + if (controlHide) hideContent() - } }, [controlHide]) // todo use click outside hidden - const triggerElemRef = useRef(null) + const triggerElemRef = useRef(null) const calLoc = () => { const triggerElem = triggerElemRef.current if (!triggerElem) { return { - display: 'none' + display: 'none', } } const { left: triggerLeft, top: triggerTop, - height - } = triggerElem.getBoundingClientRect(); + height, + } = triggerElem.getBoundingClientRect() return { position: 'fixed', left: triggerLeft, top: triggerTop + height, - zIndex: 999 + zIndex: 999, } } @@ -63,19 +62,20 @@ const PortalToFollowElement: FC = ({ root.render(
{portalElem} -
+
, ) document.body.appendChild(holder) setWrapElem(holder) console.log(holder) - } else { + } + else { wrapElem?.remove?.() setWrapElem(null) } }, [isShowContent]) return ( -
+
} onClick={toggleContent}> {children}
) diff --git a/web/app/components/base/radio/component/radio/index.tsx b/web/app/components/base/radio/component/radio/index.tsx index 702c3cccca..5767896b15 100644 --- a/web/app/components/base/radio/component/radio/index.tsx +++ b/web/app/components/base/radio/component/radio/index.tsx @@ -26,7 +26,7 @@ export default function Radio({ }: IRadioProps): JSX.Element { const groupContext = useContext(RadioGroupContext) const labelId = useId() - const handleChange = (e: any) => { + const handleChange = (e: IRadioProps['value']) => { if (disabled) return diff --git a/web/app/components/datasets/settings/form/index.tsx b/web/app/components/datasets/settings/form/index.tsx index e2454bba80..f163f0ee82 100644 --- a/web/app/components/datasets/settings/form/index.tsx +++ b/web/app/components/datasets/settings/form/index.tsx @@ -1,5 +1,6 @@ 'use client' import { useEffect, useState } from 'react' +import type { Dispatch } from 'react' import useSWR from 'swr' import { useContext } from 'use-context-selector' import { BookOpenIcon } from '@heroicons/react/24/outline' @@ -24,7 +25,7 @@ const labelClass = ` const inputClass = ` w-[480px] px-3 bg-gray-100 text-sm text-gray-800 rounded-lg outline-none appearance-none ` -const useInitialValue = (depend: any, dispatch: any) => { +const useInitialValue: (depend: T, dispatch: Dispatch) => void = (depend, dispatch) => { useEffect(() => { dispatch(depend) }, [depend]) diff --git a/web/app/components/develop/secret-key/secret-key-modal.tsx b/web/app/components/develop/secret-key/secret-key-modal.tsx index c93f1ce816..ef9e73f9ed 100644 --- a/web/app/components/develop/secret-key/secret-key-modal.tsx +++ b/web/app/components/develop/secret-key/secret-key-modal.tsx @@ -79,7 +79,7 @@ const SecretKeyModal = ({ return `${token.slice(0, 3)}...${token.slice(-20)}` } - const formatDate = (timestamp: any) => { + const formatDate = (timestamp: string) => { if (locale === 'en') return new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' }).format((+timestamp) * 1000) else diff --git a/web/app/components/explore/app-list/index.tsx b/web/app/components/explore/app-list/index.tsx index 4c6d995d0d..382e462c4d 100644 --- a/web/app/components/explore/app-list/index.tsx +++ b/web/app/components/explore/app-list/index.tsx @@ -13,8 +13,10 @@ import AppCard from '@/app/components/explore/app-card' import { fetchAppDetail, fetchAppList, installApp } from '@/service/explore' import { createApp } from '@/service/apps' import CreateAppModal from '@/app/components/explore/create-app-modal' +import type { CreateAppModalProps } from '@/app/components/explore/create-app-modal' import Loading from '@/app/components/base/loading' import { NEED_REFRESH_APP_LIST_KEY } from '@/config' +import { type AppMode } from '@/types/app' const Apps: FC = () => { const { t } = useTranslation() @@ -50,7 +52,7 @@ const Apps: FC = () => { const [currApp, setCurrApp] = React.useState(null) const [isShowCreateModal, setIsShowCreateModal] = React.useState(false) - const onCreate = async ({ name, icon, icon_background }: any) => { + const onCreate: CreateAppModalProps['onConfirm'] = async ({ name, icon, icon_background }) => { const { app_model_config: model_config } = await fetchAppDetail(currApp?.app.id as string) try { @@ -58,7 +60,7 @@ const Apps: FC = () => { name, icon, icon_background, - mode: currApp?.app.mode as any, + mode: currApp?.app.mode as AppMode, config: model_config, }) setIsShowCreateModal(false) diff --git a/web/app/components/explore/create-app-modal/index.tsx b/web/app/components/explore/create-app-modal/index.tsx index 52de4b8720..52e9652c71 100644 --- a/web/app/components/explore/create-app-modal/index.tsx +++ b/web/app/components/explore/create-app-modal/index.tsx @@ -9,10 +9,14 @@ import Toast from '@/app/components/base/toast' import AppIcon from '@/app/components/base/app-icon' import EmojiPicker from '@/app/components/base/emoji-picker' -type IProps = { +export type CreateAppModalProps = { appName: string show: boolean - onConfirm: (info: any) => void + onConfirm: (info: { + name: string + icon: string + icon_background: string + }) => Promise onHide: () => void } @@ -21,7 +25,7 @@ const CreateAppModal = ({ show = false, onConfirm, onHide, -}: IProps) => { +}: CreateAppModalProps) => { const { t } = useTranslation() const [name, setName] = React.useState('') diff --git a/web/app/components/explore/universal-chat/config-view/detail/index.tsx b/web/app/components/explore/universal-chat/config-view/detail/index.tsx index fda11c74b5..debaaef0c3 100644 --- a/web/app/components/explore/universal-chat/config-view/detail/index.tsx +++ b/web/app/components/explore/universal-chat/config-view/detail/index.tsx @@ -6,12 +6,13 @@ import { useTranslation } from 'react-i18next' import s from './style.module.css' import Config from '@/app/components/explore/universal-chat/config' import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations' +import type { DataSet } from '@/models/datasets' type Props = { modelId: string providerName: ProviderEnum plugins: Record - dataSets: any[] + dataSets: DataSet[] } const ConfigViewPanel: FC = ({ modelId, diff --git a/web/app/components/explore/universal-chat/config-view/summary/index.tsx b/web/app/components/explore/universal-chat/config-view/summary/index.tsx index 6acb6fb84b..124903c618 100644 --- a/web/app/components/explore/universal-chat/config-view/summary/index.tsx +++ b/web/app/components/explore/universal-chat/config-view/summary/index.tsx @@ -10,12 +10,13 @@ import ConfigDetail from '@/app/components/explore/universal-chat/config-view/de import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations' import ModelName from '@/app/components/app/configuration/config-model/model-name' import { useProviderContext } from '@/context/provider-context' +import type { DataSet } from '@/models/datasets' export type ISummaryProps = { modelId: string providerName: ProviderEnum plugins: Record - dataSets: any[] + dataSets: DataSet[] } const getColorInfo = (modelId: string) => { diff --git a/web/app/components/explore/universal-chat/config/index.tsx b/web/app/components/explore/universal-chat/config/index.tsx index 7b6f4e59a2..a6d3528ba2 100644 --- a/web/app/components/explore/universal-chat/config/index.tsx +++ b/web/app/components/explore/universal-chat/config/index.tsx @@ -5,6 +5,7 @@ import ModelConfig from './model-config' import DataConfig from './data-config' import PluginConfig from './plugins-config' import type { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations' +import type { DataSet } from '@/models/datasets' export type IConfigProps = { className?: string @@ -14,8 +15,8 @@ export type IConfigProps = { onModelChange?: (modelId: string, providerName: ProviderEnum) => void plugins: Record onPluginChange?: (key: string, value: boolean) => void - dataSets: any[] - onDataSetsChange?: (contexts: any[]) => void + dataSets: DataSet[] + onDataSetsChange?: (contexts: DataSet[]) => void } const Config: FC = ({ diff --git a/web/app/components/explore/universal-chat/config/plugins-config/index.tsx b/web/app/components/explore/universal-chat/config/plugins-config/index.tsx index e374d79fef..25f24989a1 100644 --- a/web/app/components/explore/universal-chat/config/plugins-config/index.tsx +++ b/web/app/components/explore/universal-chat/config/plugins-config/index.tsx @@ -19,7 +19,8 @@ const plugins = [ { key: 'google_search', icon: }, { key: 'web_reader', icon: }, { key: 'wikipedia', icon: }, -] +] as const + const Plugins: FC = ({ readonly, config, diff --git a/web/app/components/header/account-setting/model-page/model-item/Card.tsx b/web/app/components/header/account-setting/model-page/model-item/Card.tsx index 65a98d5c52..98485054df 100644 --- a/web/app/components/header/account-setting/model-page/model-item/Card.tsx +++ b/web/app/components/header/account-setting/model-page/model-item/Card.tsx @@ -8,7 +8,7 @@ import Button from '@/app/components/base/button' type CardProps = { providerType: ProviderEnum - models: any[] + models: Model[] onOpenModal: (v: any) => void onOperate: (v: Record) => void } @@ -33,7 +33,7 @@ const Card: FC = ({ return (
{ - models.map((model: Model) => ( + models.map(model => (
diff --git a/web/app/components/header/account-setting/model-page/model-selector/index.tsx b/web/app/components/header/account-setting/model-page/model-selector/index.tsx index 81592e1b27..f7c300cdd0 100644 --- a/web/app/components/header/account-setting/model-page/model-selector/index.tsx +++ b/web/app/components/header/account-setting/model-page/model-selector/index.tsx @@ -15,6 +15,7 @@ import ModelIcon from '@/app/components/app/configuration/config-model/model-ico import ModelName, { supportI18nModelName } from '@/app/components/app/configuration/config-model/model-name' import ProviderName from '@/app/components/app/configuration/config-model/provider-name' import { useProviderContext } from '@/context/provider-context' + type Props = { value: { providerName: ProviderEnum @@ -28,6 +29,16 @@ type Props = { triggerIconSmall?: boolean } +type ModelOption = { + type: 'model' + value: string + providerName: ProviderEnum + modelDisplayName: string +} | { + type: 'provider' + value: ProviderEnum +} + const ModelSelector: FC = ({ value, modelType, @@ -69,9 +80,9 @@ const ModelSelector: FC = ({ const hasRemoved = value && !modelList.find(({ model_name }) => model_name === value.modelName) - const modelOptions: any[] = (() => { + const modelOptions: ModelOption[] = (() => { const providers = _.uniq(filteredModelList.map(item => item.model_provider.provider_name)) - const res: any[] = [] + const res: ModelOption[] = [] providers.forEach((providerName) => { res.push({ type: 'provider', @@ -162,7 +173,7 @@ const ModelSelector: FC = ({
{ - modelOptions.map((model: any) => { + modelOptions.map((model) => { if (model.type === 'provider') { return (
{ const { t } = useTranslation() const { data: plugins, mutate } = useSWR('/workspaces/current/tool-providers', fetchPluginProviders) - const Plugin_MAP: Record = { + const Plugin_MAP: Record JSX.Element> = { serpapi: (plugin: PluginProvider) => mutate()} />, } diff --git a/web/app/components/share/chat/index.tsx b/web/app/components/share/chat/index.tsx index 53d8ece250..7ba0ad69e3 100644 --- a/web/app/components/share/chat/index.tsx +++ b/web/app/components/share/chat/index.tsx @@ -30,7 +30,7 @@ import { } from '@/service/share' import type { ConversationItem, SiteInfo } from '@/models/share' import type { PromptConfig, SuggestedQuestionsAfterAnswerConfig } from '@/models/debug' -import type { Feedbacktype, IChatItem } from '@/app/components/app/chat' +import type { Feedbacktype, IChatItem } from '@/app/components/app/chat/type' import Chat from '@/app/components/app/chat' import { changeLanguage } from '@/i18n/i18next-config' import useBreakpoints, { MediaType } from '@/hooks/use-breakpoints' diff --git a/web/app/components/share/text-generation/result/content.tsx b/web/app/components/share/text-generation/result/content.tsx index 227c583bdd..21fd5fb6a0 100644 --- a/web/app/components/share/text-generation/result/content.tsx +++ b/web/app/components/share/text-generation/result/content.tsx @@ -1,7 +1,7 @@ import type { FC } from 'react' import React from 'react' import Header from './header' -import type { Feedbacktype } from '@/app/components/app/chat' +import type { Feedbacktype } from '@/app/components/app/chat/type' import { format } from '@/service/base' export type IResultProps = { diff --git a/web/app/components/share/text-generation/result/index.tsx b/web/app/components/share/text-generation/result/index.tsx index f53b39352b..443d0dd1a3 100644 --- a/web/app/components/share/text-generation/result/index.tsx +++ b/web/app/components/share/text-generation/result/index.tsx @@ -8,7 +8,7 @@ import TextGenerationRes from '@/app/components/app/text-generate/item' import NoData from '@/app/components/share/text-generation/no-data' import Toast from '@/app/components/base/toast' import { sendCompletionMessage, updateFeedback } from '@/service/share' -import type { Feedbacktype } from '@/app/components/app/chat' +import type { Feedbacktype } from '@/app/components/app/chat/type' import Loading from '@/app/components/base/loading' import type { PromptConfig } from '@/models/debug' import type { InstalledApp } from '@/models/explore' diff --git a/web/app/signin/normalForm.tsx b/web/app/signin/normalForm.tsx index efb3de7839..515cc283f5 100644 --- a/web/app/signin/normalForm.tsx +++ b/web/app/signin/normalForm.tsx @@ -22,7 +22,11 @@ type IState = { google: boolean } -function reducer(state: IState, action: { type: string; payload: any }) { +type IAction = { + type: 'login' | 'login_failed' | 'github_login' | 'github_login_failed' | 'google_login' | 'google_login_failed' +} + +function reducer(state: IState, action: IAction) { switch (action.type) { case 'login': return { @@ -120,14 +124,14 @@ const NormalForm = () => { useEffect(() => { if (github_error !== undefined) - dispatch({ type: 'github_login_failed', payload: null }) + dispatch({ type: 'github_login_failed' }) if (github) window.location.href = github.redirect_url }, [github, github_error]) useEffect(() => { if (google_error !== undefined) - dispatch({ type: 'google_login_failed', payload: null }) + dispatch({ type: 'google_login_failed' }) if (google) window.location.href = google.redirect_url }, [google, google])