11import { useTranslation } from 'react-i18next'
2- import { useMemo , useState } from 'react'
2+ import { useState } from 'react'
33import { openUrl } from '../../utils/index.mjs'
44import {
5- isSupportBalance ,
6- isUsingApiKey ,
5+ isUsingOpenAiApiKey ,
76 isUsingAzureOpenAi ,
87 isUsingChatGLMApi ,
98 isUsingClaude2Api ,
@@ -15,6 +14,7 @@ import {
1514 Models ,
1615 ThemeMode ,
1716 TriggerMode ,
17+ isUsingMoonshotApi ,
1818} from '../../config/index.mjs'
1919import Browser from 'webextension-polyfill'
2020import { languageList } from '../../config/language.mjs'
@@ -82,10 +82,6 @@ async function checkBilling(apiKey, apiUrl) {
8282export function GeneralPart ( { config, updateConfig } ) {
8383 const { t, i18n } = useTranslation ( )
8484 const [ balance , setBalance ] = useState ( null )
85- const [ currentModel , setCurrentModel ] = useState ( null )
86- const showBalance = useMemo ( ( ) => {
87- return isSupportBalance ( config )
88- } , [ config ] )
8985
9086 const getBalance = async ( ) => {
9187 const response = await fetch ( `${ config . customOpenAiApiUrl } /dashboard/billing/credit_grants` , {
@@ -145,20 +141,20 @@ export function GeneralPart({ config, updateConfig }) {
145141 < span style = "display: flex; gap: 15px;" >
146142 < select
147143 style = {
148- isUsingApiKey ( config ) ||
144+ isUsingOpenAiApiKey ( config ) ||
149145 isUsingMultiModeModel ( config ) ||
150146 isUsingCustomModel ( config ) ||
151147 isUsingAzureOpenAi ( config ) ||
152148 isUsingClaude2Api ( config ) ||
153- isUsingCustomNameOnlyModel ( config )
149+ isUsingCustomNameOnlyModel ( config ) ||
150+ isUsingMoonshotApi ( config )
154151 ? 'width: 50%;'
155152 : undefined
156153 }
157154 required
158155 onChange = { ( e ) => {
159156 const modelName = e . target . value
160157 updateConfig ( { modelName : modelName } )
161- setCurrentModel ( Models [ modelName ] )
162158 } }
163159 >
164160 { config . activeApiModes . map ( ( modelName ) => {
@@ -200,7 +196,7 @@ export function GeneralPart({ config, updateConfig }) {
200196 } ) }
201197 </ select >
202198 ) }
203- { isUsingApiKey ( config ) && (
199+ { isUsingOpenAiApiKey ( config ) && (
204200 < span style = "width: 50%; display: flex; gap: 5px;" >
205201 < input
206202 type = "password"
@@ -213,29 +209,23 @@ export function GeneralPart({ config, updateConfig }) {
213209 />
214210 { config . apiKey . length === 0 ? (
215211 < a
216- href = {
217- currentModel && 'keyGenerateUrl' in currentModel
218- ? currentModel . keyGenerateUrl
219- : 'https://platform.openai.com/account/api-keys'
220- }
212+ href = "https://platform.openai.com/account/api-keys"
221213 target = "_blank"
222214 rel = "nofollow noopener noreferrer"
223215 >
224216 < button style = "white-space: nowrap;" type = "button" >
225217 { t ( 'Get' ) }
226218 </ button >
227219 </ a >
228- ) : showBalance ? (
229- balance ? (
230- < button type = "button" onClick = { getBalance } >
231- { balance }
232- </ button >
233- ) : (
234- < button type = "button" onClick = { getBalance } >
235- { t ( 'Balance' ) }
236- </ button >
237- )
238- ) : null }
220+ ) : balance ? (
221+ < button type = "button" onClick = { getBalance } >
222+ { balance }
223+ </ button >
224+ ) : (
225+ < button type = "button" onClick = { getBalance } >
226+ { t ( 'Balance' ) }
227+ </ button >
228+ ) }
239229 </ span >
240230 ) }
241231 { isUsingCustomModel ( config ) && (
@@ -298,6 +288,30 @@ export function GeneralPart({ config, updateConfig }) {
298288 } }
299289 />
300290 ) }
291+ { isUsingMoonshotApi ( config ) && (
292+ < span style = "width: 50%; display: flex; gap: 5px;" >
293+ < input
294+ type = "password"
295+ value = { config . moonshotApiKey }
296+ placeholder = { t ( 'Moonshot API Key' ) }
297+ onChange = { ( e ) => {
298+ const apiKey = e . target . value
299+ updateConfig ( { moonshotApiKey : apiKey } )
300+ } }
301+ />
302+ { config . moonshotApiKey . length === 0 && (
303+ < a
304+ href = "https://platform.moonshot.cn/console/api-keys"
305+ target = "_blank"
306+ rel = "nofollow noopener noreferrer"
307+ >
308+ < button style = "white-space: nowrap;" type = "button" >
309+ { t ( 'Get' ) }
310+ </ button >
311+ </ a >
312+ ) }
313+ </ span >
314+ ) }
301315 </ span >
302316 { isUsingCustomModel ( config ) && (
303317 < input
0 commit comments