parent
827c97f0d3
commit
60e0bbd713
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 13 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 13 KiB |
File diff suppressed because one or more lines are too long
|
After Width: | Height: | Size: 10 KiB |
File diff suppressed because one or more lines are too long
@ -0,0 +1,16 @@
|
||||
// GENERATE BY script
|
||||
// DON NOT EDIT IT MANUALLY
|
||||
|
||||
import * as React from 'react'
|
||||
import data from './Zhipuai.json'
|
||||
import IconBase from '@/app/components/base/icons/IconBase'
|
||||
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
|
||||
|
||||
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
|
||||
props,
|
||||
ref,
|
||||
) => <IconBase {...props} ref={ref} data={data as IconData} />)
|
||||
|
||||
Icon.displayName = 'Zhipuai'
|
||||
|
||||
export default Icon
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,16 @@
|
||||
// GENERATE BY script
|
||||
// DON NOT EDIT IT MANUALLY
|
||||
|
||||
import * as React from 'react'
|
||||
import data from './ZhipuaiText.json'
|
||||
import IconBase from '@/app/components/base/icons/IconBase'
|
||||
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
|
||||
|
||||
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
|
||||
props,
|
||||
ref,
|
||||
) => <IconBase {...props} ref={ref} data={data as IconData} />)
|
||||
|
||||
Icon.displayName = 'ZhipuaiText'
|
||||
|
||||
export default Icon
|
||||
File diff suppressed because one or more lines are too long
@ -0,0 +1,16 @@
|
||||
// GENERATE BY script
|
||||
// DON NOT EDIT IT MANUALLY
|
||||
|
||||
import * as React from 'react'
|
||||
import data from './ZhipuaiTextCn.json'
|
||||
import IconBase from '@/app/components/base/icons/IconBase'
|
||||
import type { IconBaseProps, IconData } from '@/app/components/base/icons/IconBase'
|
||||
|
||||
const Icon = React.forwardRef<React.MutableRefObject<SVGElement>, Omit<IconBaseProps, 'data'>>((
|
||||
props,
|
||||
ref,
|
||||
) => <IconBase {...props} ref={ref} data={data as IconData} />)
|
||||
|
||||
Icon.displayName = 'ZhipuaiTextCn'
|
||||
|
||||
export default Icon
|
||||
@ -0,0 +1,55 @@
|
||||
import { ProviderEnum } from '../declarations'
|
||||
import type { ProviderConfig } from '../declarations'
|
||||
import { Zhipuai, ZhipuaiText, ZhipuaiTextCn } from '@/app/components/base/icons/src/public/llm'
|
||||
|
||||
const config: ProviderConfig = {
|
||||
selector: {
|
||||
name: {
|
||||
'en': 'ZHIPU AI',
|
||||
'zh-Hans': '智谱 AI',
|
||||
},
|
||||
icon: <Zhipuai className='w-full h-full' />,
|
||||
},
|
||||
item: {
|
||||
key: ProviderEnum.zhipuai,
|
||||
titleIcon: {
|
||||
'en': <ZhipuaiText className='-ml-1 h-7' />,
|
||||
'zh-Hans': <ZhipuaiTextCn className='h-8' />,
|
||||
},
|
||||
},
|
||||
modal: {
|
||||
key: ProviderEnum.zhipuai,
|
||||
title: {
|
||||
'en': 'ZHIPU AI',
|
||||
'zh-Hans': '智谱 AI',
|
||||
},
|
||||
icon: <Zhipuai className='w-6 h-6' />,
|
||||
link: {
|
||||
href: 'https://open.bigmodel.cn/usercenter/apikeys',
|
||||
label: {
|
||||
'en': 'Get your API key from ZHIPU AI',
|
||||
'zh-Hans': '从智谱 AI 获取 API Key',
|
||||
},
|
||||
},
|
||||
validateKeys: [
|
||||
'api_key',
|
||||
],
|
||||
fields: [
|
||||
{
|
||||
type: 'text',
|
||||
key: 'api_key',
|
||||
required: true,
|
||||
label: {
|
||||
'en': 'APIKey',
|
||||
'zh-Hans': 'APIKey',
|
||||
},
|
||||
placeholder: {
|
||||
'en': 'Enter your APIKey here',
|
||||
'zh-Hans': '在此输入您的 APIKey',
|
||||
},
|
||||
},
|
||||
],
|
||||
},
|
||||
}
|
||||
|
||||
export default config
|
||||
@ -1,71 +0,0 @@
|
||||
'use client'
|
||||
|
||||
import { useEffect, useState } from 'react'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import useSWR from 'swr'
|
||||
import { useSearchParams } from 'next/navigation'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import I18n from '@/context/i18n'
|
||||
import { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations'
|
||||
import { fetchSparkFreeQuotaVerify } from '@/service/common'
|
||||
import type { ConfirmCommonProps } from '@/app/components/base/confirm/common'
|
||||
|
||||
export type ConfirmType = Pick<ConfirmCommonProps, 'type' | 'title' | 'desc'>
|
||||
|
||||
export const useAnthropicCheckPay = () => {
|
||||
const { t } = useTranslation()
|
||||
const [confirm, setConfirm] = useState<ConfirmType | null>(null)
|
||||
const searchParams = useSearchParams()
|
||||
const providerName = searchParams.get('provider_name')
|
||||
const paymentResult = searchParams.get('payment_result')
|
||||
|
||||
useEffect(() => {
|
||||
if (providerName === ProviderEnum.anthropic && (paymentResult === 'succeeded' || paymentResult === 'cancelled')) {
|
||||
setConfirm({
|
||||
type: paymentResult === 'succeeded' ? 'success' : 'danger',
|
||||
title: paymentResult === 'succeeded' ? t('common.actionMsg.paySucceeded') : t('common.actionMsg.payCancelled'),
|
||||
})
|
||||
}
|
||||
}, [providerName, paymentResult, t])
|
||||
|
||||
return confirm
|
||||
}
|
||||
|
||||
const QUOTA_RECEIVE_STATUS = {
|
||||
success: {
|
||||
'en': 'Anthropic',
|
||||
'zh-Hans': '领取成功,将在 5 分钟后自动增加配额',
|
||||
},
|
||||
fail: {
|
||||
'en': 'Anthropic',
|
||||
'zh-Hans': '领取失败',
|
||||
},
|
||||
}
|
||||
|
||||
export const useSparkCheckQuota = () => {
|
||||
const { locale } = useContext(I18n)
|
||||
const [shouldVerify, setShouldVerify] = useState(false)
|
||||
const { data } = useSWR(
|
||||
shouldVerify
|
||||
? `/workspaces/current/model-providers/${ProviderEnum.spark}/free-quota-qualification-verify`
|
||||
: null,
|
||||
fetchSparkFreeQuotaVerify,
|
||||
)
|
||||
const searchParams = useSearchParams()
|
||||
const type = searchParams.get('type')
|
||||
const provider = searchParams.get('provider')
|
||||
const result = searchParams.get('result')
|
||||
|
||||
useEffect(() => {
|
||||
if (type === 'provider_apply_callback' && provider === ProviderEnum.spark && result === 'success')
|
||||
setShouldVerify(true)
|
||||
}, [type, provider, result])
|
||||
|
||||
return data
|
||||
? {
|
||||
type: data.flag ? 'success' : 'danger',
|
||||
title: data.flag ? QUOTA_RECEIVE_STATUS.success[locale] : QUOTA_RECEIVE_STATUS.fail[locale],
|
||||
desc: !data.flag ? data.reason : undefined,
|
||||
}
|
||||
: null
|
||||
}
|
||||
@ -0,0 +1,124 @@
|
||||
'use client'
|
||||
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import { useRouter, useSearchParams } from 'next/navigation'
|
||||
import { useTranslation } from 'react-i18next'
|
||||
import useSWR from 'swr'
|
||||
import { useContext } from 'use-context-selector'
|
||||
import I18n from '@/context/i18n'
|
||||
import { ProviderEnum } from '@/app/components/header/account-setting/model-page/declarations'
|
||||
import { fetchFreeQuotaVerify } from '@/service/common'
|
||||
import type { ConfirmCommonProps } from '@/app/components/base/confirm/common'
|
||||
import Confirm from '@/app/components/base/confirm/common'
|
||||
|
||||
export type ConfirmType = Pick<ConfirmCommonProps, 'type' | 'title' | 'desc'>
|
||||
|
||||
export const useAnthropicCheckPay = () => {
|
||||
const { t } = useTranslation()
|
||||
const [confirm, setConfirm] = useState<ConfirmType | null>(null)
|
||||
const searchParams = useSearchParams()
|
||||
const providerName = searchParams.get('provider_name')
|
||||
const paymentResult = searchParams.get('payment_result')
|
||||
|
||||
useEffect(() => {
|
||||
if (providerName === ProviderEnum.anthropic && (paymentResult === 'succeeded' || paymentResult === 'cancelled')) {
|
||||
setConfirm({
|
||||
type: paymentResult === 'succeeded' ? 'success' : 'danger',
|
||||
title: paymentResult === 'succeeded' ? t('common.actionMsg.paySucceeded') : t('common.actionMsg.payCancelled'),
|
||||
})
|
||||
}
|
||||
}, [providerName, paymentResult, t])
|
||||
|
||||
return confirm
|
||||
}
|
||||
|
||||
const QUOTA_RECEIVE_STATUS = {
|
||||
[ProviderEnum.spark]: {
|
||||
success: {
|
||||
'en': 'Successful collection, the quota will be automatically increased after 5 minutes.',
|
||||
'zh-Hans': '领取成功,将在 5 分钟后自动增加配额',
|
||||
},
|
||||
fail: {
|
||||
'en': 'Failure to collect',
|
||||
'zh-Hans': '领取失败',
|
||||
},
|
||||
},
|
||||
[ProviderEnum.zhipuai]: {
|
||||
success: {
|
||||
'en': 'Successful collection',
|
||||
'zh-Hans': '领取成功',
|
||||
},
|
||||
fail: {
|
||||
'en': 'Failure to collect',
|
||||
'zh-Hans': '领取失败',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
const FREE_CHECK_PROVIDER = [ProviderEnum.spark, ProviderEnum.zhipuai]
|
||||
export const useCheckFreeQuota = () => {
|
||||
const { locale } = useContext(I18n)
|
||||
const router = useRouter()
|
||||
const [shouldVerify, setShouldVerify] = useState(false)
|
||||
const searchParams = useSearchParams()
|
||||
const type = searchParams.get('type')
|
||||
const provider = searchParams.get('provider') as (ProviderEnum.spark | ProviderEnum.zhipuai)
|
||||
const result = searchParams.get('result')
|
||||
const token = searchParams.get('token')
|
||||
|
||||
const { data, error } = useSWR(
|
||||
shouldVerify
|
||||
? `/workspaces/current/model-providers/${provider}/free-quota-qualification-verify?token=${token}`
|
||||
: null,
|
||||
fetchFreeQuotaVerify,
|
||||
)
|
||||
|
||||
useEffect(() => {
|
||||
if (error)
|
||||
router.replace('/', { forceOptimisticNavigation: false })
|
||||
}, [error, router])
|
||||
|
||||
useEffect(() => {
|
||||
if (type === 'provider_apply_callback' && FREE_CHECK_PROVIDER.includes(provider) && result === 'success')
|
||||
setShouldVerify(true)
|
||||
}, [type, provider, result])
|
||||
|
||||
return (data && provider)
|
||||
? {
|
||||
type: data.flag ? 'success' : 'danger',
|
||||
title: data.flag ? QUOTA_RECEIVE_STATUS[provider].success[locale] : QUOTA_RECEIVE_STATUS[provider].fail[locale],
|
||||
desc: !data.flag ? data.reason : undefined,
|
||||
}
|
||||
: null
|
||||
}
|
||||
|
||||
export const CheckModal = () => {
|
||||
const router = useRouter()
|
||||
const { t } = useTranslation()
|
||||
const [showPayStatusModal, setShowPayStatusModal] = useState(true)
|
||||
const anthropicConfirmInfo = useAnthropicCheckPay()
|
||||
const freeQuotaConfirmInfo = useCheckFreeQuota()
|
||||
|
||||
const handleCancelShowPayStatusModal = useCallback(() => {
|
||||
setShowPayStatusModal(false)
|
||||
router.replace('/', { forceOptimisticNavigation: false })
|
||||
}, [router])
|
||||
|
||||
const confirmInfo = anthropicConfirmInfo || freeQuotaConfirmInfo
|
||||
|
||||
if (!confirmInfo || !showPayStatusModal)
|
||||
return null
|
||||
|
||||
return (
|
||||
<Confirm
|
||||
isShow
|
||||
onCancel={handleCancelShowPayStatusModal}
|
||||
onConfirm={handleCancelShowPayStatusModal}
|
||||
type={confirmInfo.type}
|
||||
title={confirmInfo.title}
|
||||
desc={confirmInfo.desc}
|
||||
showOperateCancel={false}
|
||||
confirmText={(confirmInfo.type === 'danger' && t('common.operation.ok')) || ''}
|
||||
/>
|
||||
)
|
||||
}
|
||||
Loading…
Reference in New Issue