22import fs from 'fs' ;
33import { pathToFileURL } from 'url' ;
44import { KeyvFile } from 'keyv-file' ;
5- import ChatGPTClient from '../src/ChatGPTClient.js' ;
65import boxen from 'boxen' ;
76import ora from 'ora' ;
87import clipboard from 'clipboardy' ;
98import inquirer from 'inquirer' ;
109import inquirerAutocompletePrompt from 'inquirer-autocomplete-prompt' ;
10+ import ChatGPTClient from '../src/ChatGPTClient.js' ;
1111import BingAIClient from '../src/BingAIClient.js' ;
1212
13- const arg = process . argv . find ( ( arg ) => arg . startsWith ( '--settings' ) ) ;
14- let path ;
15- if ( arg ) {
16- path = arg . split ( '=' ) [ 1 ] ;
17- } else {
18- path = './settings.js' ;
19- }
13+ const arg = process . argv . find ( _arg => _arg . startsWith ( '--settings' ) ) ;
14+ const path = arg ?. split ( '=' ) [ 1 ] ?? './settings.js' ;
2015
2116let settings ;
2217if ( fs . existsSync ( path ) ) {
@@ -25,9 +20,9 @@ if (fs.existsSync(path)) {
2520 settings = ( await import ( pathToFileURL ( fullPath ) . toString ( ) ) ) . default ;
2621} else {
2722 if ( arg ) {
28- console . error ( ` Error: the file specified by the --settings parameter does not exist.` ) ;
23+ console . error ( ' Error: the file specified by the --settings parameter does not exist.' ) ;
2924 } else {
30- console . error ( ` Error: the settings.js file does not exist.` ) ;
25+ console . error ( ' Error: the settings.js file does not exist.' ) ;
3126 }
3227 process . exit ( 1 ) ;
3328}
@@ -95,7 +90,9 @@ switch (clientToUse) {
9590 break ;
9691}
9792
98- console . log ( tryBoxen ( 'ChatGPT CLI' , { padding : 0.7 , margin : 1 , borderStyle : 'double' , dimBorder : true } ) ) ;
93+ console . log ( tryBoxen ( 'ChatGPT CLI' , {
94+ padding : 0.7 , margin : 1 , borderStyle : 'double' , dimBorder : true ,
95+ } ) ) ;
9996
10097await conversation ( ) ;
10198
@@ -116,13 +113,13 @@ async function conversation() {
116113 prompt . ui . activePrompt . firstRender = false ;
117114 // The below is a hack to allow selecting items from the autocomplete menu while also being able to submit messages.
118115 // This basically simulates a hybrid between having `suggestOnly: false` and `suggestOnly: true`.
119- await new Promise ( ( resolve ) => setTimeout ( resolve , 0 ) ) ;
116+ await new Promise ( resolve => setTimeout ( resolve , 0 ) ) ;
120117 prompt . ui . activePrompt . opt . source = ( answers , input ) => {
121118 if ( ! input ) {
122119 return [ ] ;
123120 }
124121 prompt . ui . activePrompt . opt . suggestOnly = ! input . startsWith ( '!' ) ;
125- return availableCommands . filter ( ( command ) => command . value . startsWith ( input ) ) ;
122+ return availableCommands . filter ( command => command . value . startsWith ( input ) ) ;
126123 } ;
127124 let { message } = await prompt ;
128125 message = message . trim ( ) ;
@@ -143,6 +140,8 @@ async function conversation() {
143140 return deleteAllConversations ( ) ;
144141 case '!exit' :
145142 return true ;
143+ default :
144+ return conversation ( ) ;
146145 }
147146 }
148147 return onMessage ( message ) ;
@@ -172,7 +171,9 @@ async function onMessage(message) {
172171 ...conversationData ,
173172 onProgress : ( token ) => {
174173 reply += token ;
175- const output = tryBoxen ( `${ reply . trim ( ) } █` , { title : aiLabel , padding : 0.7 , margin : 1 , dimBorder : true } ) ;
174+ const output = tryBoxen ( `${ reply . trim ( ) } █` , {
175+ title : aiLabel , padding : 0.7 , margin : 1 , dimBorder : true ,
176+ } ) ;
176177 spinner . text = `${ spinnerPrefix } \n${ output } ` ;
177178 } ,
178179 } ) ;
@@ -192,10 +193,10 @@ async function onMessage(message) {
192193 conversationData = {
193194 parentMessageId : response . messageId ,
194195 jailbreakConversationId : response . jailbreakConversationId ,
195- //conversationId: response.conversationId,
196- //conversationSignature: response.conversationSignature,
197- //clientId: response.clientId,
198- //invocationId: response.invocationId,
196+ // conversationId: response.conversationId,
197+ // conversationSignature: response.conversationSignature,
198+ // clientId: response.clientId,
199+ // invocationId: response.invocationId,
199200 } ;
200201 break ;
201202 default :
@@ -206,7 +207,9 @@ async function onMessage(message) {
206207 break ;
207208 }
208209 await client . conversationsCache . set ( 'lastConversation' , conversationData ) ;
209- const output = tryBoxen ( responseText , { title : aiLabel , padding : 0.7 , margin : 1 , dimBorder : true } ) ;
210+ const output = tryBoxen ( responseText , {
211+ title : aiLabel , padding : 0.7 , margin : 1 , dimBorder : true ,
212+ } ) ;
210213 console . log ( output ) ;
211214 } catch ( error ) {
212215 spinner . stop ( ) ;
@@ -271,7 +274,7 @@ async function copyConversation() {
271274 // get the last message ID
272275 const lastMessageId = messages [ messages . length - 1 ] . id ;
273276 const orderedMessages = ChatGPTClient . getMessagesForConversation ( messages , lastMessageId ) ;
274- const conversationString = orderedMessages . map ( ( message ) => `#### ${ message . role } :\n${ message . message } ` ) . join ( '\n\n' ) ;
277+ const conversationString = orderedMessages . map ( message => `#### ${ message . role } :\n${ message . message } ` ) . join ( '\n\n' ) ;
275278 try {
276279 await clipboard . write ( `${ conversationString } \n\n----\nMade with ChatGPT CLI: <https://github.com/waylaidwanderer/node-chatgpt-api>` ) ;
277280 logSuccess ( 'Copied conversation to clipboard.' ) ;
@@ -282,15 +285,21 @@ async function copyConversation() {
282285}
283286
284287function logError ( message ) {
285- console . log ( tryBoxen ( message , { title : 'Error' , padding : 0.7 , margin : 1 , borderColor : 'red' } ) ) ;
288+ console . log ( tryBoxen ( message , {
289+ title : 'Error' , padding : 0.7 , margin : 1 , borderColor : 'red' ,
290+ } ) ) ;
286291}
287292
288293function logSuccess ( message ) {
289- console . log ( tryBoxen ( message , { title : 'Success' , padding : 0.7 , margin : 1 , borderColor : 'green' } ) ) ;
294+ console . log ( tryBoxen ( message , {
295+ title : 'Success' , padding : 0.7 , margin : 1 , borderColor : 'green' ,
296+ } ) ) ;
290297}
291298
292299function logWarning ( message ) {
293- console . log ( tryBoxen ( message , { title : 'Warning' , padding : 0.7 , margin : 1 , borderColor : 'yellow' } ) ) ;
300+ console . log ( tryBoxen ( message , {
301+ title : 'Warning' , padding : 0.7 , margin : 1 , borderColor : 'yellow' ,
302+ } ) ) ;
294303}
295304
296305/**
0 commit comments