@@ -116,28 +116,33 @@ export class PearAIHandler extends BaseProvider implements SingleCompletionHandl
116116 }
117117
118118 async * createMessage ( systemPrompt : string , messages : any [ ] ) : AsyncGenerator < any > {
119- const generator = this . handler . createMessage ( systemPrompt , messages )
120- let warningMsg = ""
119+ try {
120+ const generator = this . handler . createMessage ( systemPrompt , messages )
121+ let warningMsg = ""
121122
122- for await ( const chunk of generator ) {
123- console . dir ( chunk )
124- if ( chunk . type === "text" && chunk . metadata ?. ui_only ) {
125- warningMsg += chunk . metadata ?. content
126- continue
123+ for await ( const chunk of generator ) {
124+ console . dir ( chunk )
125+ if ( chunk . type === "text" && chunk . metadata ?. ui_only ) {
126+ warningMsg += chunk . metadata ?. content ?? ""
127+ continue
128+ }
129+ yield chunk
127130 }
128- yield chunk
129- }
130131
131- if ( warningMsg ) {
132- if ( warningMsg . includes ( "pay-as-you-go" ) ) {
133- vscode . window . showInformationMessage ( warningMsg , "View Pay-As-You-Go" ) . then ( ( selection ) => {
134- if ( selection === "View Pay-As-You-Go" ) {
135- vscode . env . openExternal ( vscode . Uri . parse ( "https://trypear.ai/pay-as-you-go" ) )
136- }
137- } )
138- } else {
139- vscode . window . showInformationMessage ( warningMsg )
132+ if ( warningMsg ) {
133+ if ( warningMsg . includes ( "pay-as-you-go" ) ) {
134+ vscode . window . showInformationMessage ( warningMsg , "View Pay-As-You-Go" ) . then ( ( selection ) => {
135+ if ( selection === "View Pay-As-You-Go" ) {
136+ vscode . env . openExternal ( vscode . Uri . parse ( "https://trypear.ai/pay-as-you-go" ) )
137+ }
138+ } )
139+ } else {
140+ vscode . window . showInformationMessage ( warningMsg )
141+ }
140142 }
143+ } catch ( e ) {
144+ const errorMessage = e instanceof Error ? e . message : String ( e )
145+ vscode . window . showWarningMessage ( `Notice: ${ errorMessage } ` )
141146 }
142147 }
143148
0 commit comments