11import * as commas from 'commas:api/main'
22import { useAIStatus } from './chat'
33import type { RuntimeInformation } from './prompt'
4- import { AnswerSyntaxError , completeCommand , fixCommand , translateCommand } from './prompt'
4+ import { completeCommand , fixCommand , translateCommand } from './prompt'
55
66declare module '@commas/types/settings' {
77 export interface Settings {
@@ -40,25 +40,18 @@ export default () => {
4040 }
4141 if ( query ) {
4242 status = true
43- try {
44- const generator = translateCommand ( query , {
45- cwd,
46- extra : { columns } ,
47- } )
48- // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
49- while ( true ) {
50- const { done, value } = await generator . next ( )
51- if ( done ) {
52- return commas . ipcMain . invoke ( sender , 'ai-chat-fix' , value )
53- } else {
54- yield value
55- }
43+ const generator = translateCommand ( query , {
44+ cwd,
45+ extra : { columns } ,
46+ } )
47+ // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
48+ while ( true ) {
49+ const { done, value } = await generator . next ( )
50+ if ( done ) {
51+ return commas . ipcMain . invoke ( sender , 'ai-chat-fix' , value )
52+ } else {
53+ yield value
5654 }
57- } catch ( err ) {
58- if ( err instanceof AnswerSyntaxError ) {
59- return `# ${ err . message } `
60- }
61- throw err
6255 }
6356 }
6457 } ,
@@ -85,7 +78,7 @@ export default () => {
8578 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
8679 while ( true ) {
8780 const { done, value } = await generator . next ( )
88- if ( done ) return value . value
81+ if ( done && value [ 0 ] ) return value [ 0 ] . value
8982 }
9083 } catch {
9184 return ''
@@ -99,7 +92,7 @@ export default () => {
9992 // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition
10093 while ( true ) {
10194 const { done, value } = await generator . next ( )
102- if ( done ) return value . value
95+ if ( done && value [ 0 ] ) return value [ 0 ] . value
10396 }
10497 } catch {
10598 return ''
0 commit comments