@@ -11,13 +11,14 @@ import aiServer from '@/service/ai';
11
11
import { v4 as uuidv4 } from 'uuid' ;
12
12
import { DatabaseTypeCode , ConsoleStatus } from '@/constants' ;
13
13
import Iconfont from '../Iconfont' ;
14
- import { ITreeNode } from '@/typings' ;
14
+ import { IAiConfig , ITreeNode } from '@/typings' ;
15
15
import { IAIState } from '@/models/ai' ;
16
16
import Popularize from '@/components/Popularize' ;
17
17
import { handleLocalStorageSavedConsole , readLocalStorageSavedConsoleText } from '@/utils' ;
18
18
import { chatErrorForKey , chatErrorToLogin } from '@/constants/chat' ;
19
19
import { AiSqlSourceType } from '@/typings/ai' ;
20
20
import i18n from '@/i18n' ;
21
+ import configService from '@/service/config' ;
21
22
import styles from './index.less' ;
22
23
23
24
enum IPromptType {
@@ -213,8 +214,14 @@ function Console(props: IProps) {
213
214
}
214
215
} ;
215
216
216
- const handleAiChat = async ( content : string , promptType : IPromptType ) => {
217
- const { apiKey } = aiModel ?. aiConfig || { } ;
217
+ const handleAIChatInEditor = async ( content : string , promptType : IPromptType ) => {
218
+ const aiConfig = await configService . getAiSystemConfig ( { } ) ;
219
+ handleAiChat ( content , promptType , aiConfig ) ;
220
+ } ;
221
+
222
+ const handleAiChat = async ( content : string , promptType : IPromptType , aiConfig ?: IAiConfig ) => {
223
+ const { apiKey, aiSqlSource } = aiConfig || props . aiModel ?. aiConfig || { } ;
224
+ const isChat2DBAi = aiSqlSource === AiSqlSourceType . CHAT2DBAI ;
218
225
if ( ! apiKey && isChat2DBAi ) {
219
226
handleApiKeyEmptyOrGetQrCode ( true ) ;
220
227
return ;
@@ -349,17 +356,17 @@ function Console(props: IProps) {
349
356
{
350
357
id : 'explainSQL' ,
351
358
label : i18n ( 'common.text.explainSQL' ) ,
352
- action : ( selectedText : string ) => handleAiChat ( selectedText , IPromptType . SQL_EXPLAIN ) ,
359
+ action : ( selectedText : string ) => handleAIChatInEditor ( selectedText , IPromptType . SQL_EXPLAIN ) ,
353
360
} ,
354
361
{
355
362
id : 'optimizeSQL' ,
356
363
label : i18n ( 'common.text.optimizeSQL' ) ,
357
- action : ( selectedText : string ) => handleAiChat ( selectedText , IPromptType . SQL_OPTIMIZER ) ,
364
+ action : ( selectedText : string ) => handleAIChatInEditor ( selectedText , IPromptType . SQL_OPTIMIZER ) ,
358
365
} ,
359
366
{
360
367
id : 'changeSQL' ,
361
368
label : i18n ( 'common.text.conversionSQL' ) ,
362
- action : ( selectedText : string ) => handleAiChat ( selectedText , IPromptType . SQL_2_SQL ) ,
369
+ action : ( selectedText : string ) => handleAIChatInEditor ( selectedText , IPromptType . SQL_2_SQL ) ,
363
370
} ,
364
371
] ;
365
372
0 commit comments