@@ -3,7 +3,7 @@ import type { Config, ConfigSchema } from './config.js';
33import type { CliContext } from './helpers.js' ;
44import type { Models } from './providers/generic/ai-sdk-provider.js' ;
55
6- module . exports = ( ( globalThis : CliContext ) => {
6+ module . exports = ( async ( globalThis : CliContext ) => {
77 const _localRequire = require ( 'module' ) . createRequire ( __filename ) ;
88 const localRequire = < T > ( module : string ) : T => _localRequire ( module ) ;
99
@@ -16,7 +16,7 @@ module.exports = ((globalThis: CliContext) => {
1616 const chalk = localRequire < typeof import ( 'chalk' ) > ( 'chalk' ) ;
1717class AI {
1818 private readonly replConfig : {
19- set : ( key : string , value : any ) => Promise < void > ;
19+ set : ( key : string , value : unknown ) => Promise < void > ;
2020 get : < T > ( key : string ) => Promise < T > ;
2121 } ;
2222
@@ -36,14 +36,15 @@ class AI {
3636 this . config = new Config ( this . replConfig ) ;
3737
3838 // Set up provider change listener
39+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
3940 this . config . on ( 'change' , async ( event ) => {
4041 switch ( event . key ) {
4142 case 'provider' :
4243 this . ai = this . getProvider ( event . value as ConfigSchema [ 'provider' ] ) ;
4344 break ;
4445 case 'model' :
4546 if ( ! Object . keys ( models ) . includes ( this . config . get ( 'provider' ) as Models ) ) {
46- if ( event . value == 'default' ) {
47+ if ( event . value === 'default' ) {
4748 return ;
4849 }
4950 await this . config . set ( 'model' , 'default' ) ;
@@ -52,13 +53,13 @@ class AI {
5253 try {
5354 this . ai = getAiSdkProvider (
5455 models [ this . config . get ( 'provider' ) as keyof typeof models ] (
55- event . value == 'default' ? undefined : event . value as string ,
56+ event . value === 'default' ? undefined : event . value as string ,
5657 ) ,
5758 this . cliContext ,
5859 this . config ,
5960 ) ;
6061 } catch ( error ) {
61- throw new Error ( `Invalid model, please ensure your name is correct: ${ error } ` ) ;
62+ throw new Error ( `Invalid model, please ensure your name is correct: ${ error as string } ` ) ;
6263 }
6364 break ;
6465 default :
@@ -71,10 +72,9 @@ class AI {
7172 ) ;
7273 wrapAllFunctions ( this . cliContext , this ) ;
7374
74- this . setupConfig ( ) ;
7575 }
7676
77- async setupConfig ( ) {
77+ async setup ( ) {
7878 await this . config . setup ( ) ;
7979
8080 this . ai = this . getProvider ( this . config . get ( 'provider' ) ) ;
@@ -88,13 +88,14 @@ class AI {
8888 return getDocsAiProvider ( this . cliContext , this . config ) ;
8989 case 'openai' :
9090 case 'mistral' :
91- case 'ollama' :
91+ case 'ollama' : {
9292 const model = this . config . get ( 'model' ) ;
9393 return getAiSdkProvider (
9494 models [ provider ] ( model === 'default' ? undefined : model ) ,
9595 this . cliContext ,
9696 this . config ,
9797 ) ;
98+ }
9899 default :
99100 return new EmptyAiProvider ( this . cliContext , this . config ) ;
100101 }
@@ -131,32 +132,32 @@ class AI {
131132 }
132133
133134 @aiCommand ( { requiresPrompt : false } )
134- async help ( ) {
135+ help ( ) {
135136 this . ai . help ( {
136137 provider : this . config . get ( 'provider' ) ,
137138 model : this . config . get ( 'model' ) ,
138139 } ) ;
139140 }
140141
141142 @aiCommand ( )
142- async clear ( ) {
143+ clear ( ) {
143144 this . ai . clear ( ) ;
144145 }
145146
146147 @aiCommand ( )
147- async collection ( name : string ) {
148- await this . ai . collection ( name ) ;
148+ collection ( name : string ) {
149+ this . ai . collection ( name ) ;
149150 }
150151
151152 @aiCommand ( )
152153 async provider ( provider : string ) {
153- this . config . set ( 'provider' , provider ) ;
154+ await this . config . set ( 'provider' , provider ) ;
154155 this . ai . respond ( `Switched to ${ chalk . blue ( provider ) } provider` ) ;
155156 }
156157
157158 @aiCommand ( )
158159 async model ( model : string ) {
159- this . config . set ( 'model' , model ) ;
160+ await this . config . set ( 'model' , model ) ;
160161 this . ai . respond ( `Switched to ${ chalk . blue ( model ) } model` ) ;
161162 }
162163
@@ -168,4 +169,8 @@ class AI {
168169
169170
170171( globalThis as unknown as CliContext ) . ai = new AI ( globalThis as unknown as CliContext ) ;
172+ await ( globalThis as unknown as {
173+ ai : AI ;
174+ } ) . ai . setup ( ) ;
175+
171176} ) ;
0 commit comments