1- import { globalState } from './ui/localChat/state' ;
1+ import { globalState } from './globalState' ;
2+ import { lng } from './lng' ;
23
34type ServiceType = 'chatgpt' | 'claude' | 'gemini' ;
45type BufferMode = 'buffered' | 'stream' ;
@@ -176,7 +177,7 @@ const services: ServiceHandlers = {
176177 const content = data ?. choices ?. [ 0 ] ?. message ?. content ;
177178
178179 if ( ! content ) {
179- throw new Error ( _ ( 'modai.cmp.failed_request' ) ) ;
180+ throw new Error ( lng ( 'modai.cmp.failed_request' ) ) ;
180181 }
181182
182183 const id = data . id ;
@@ -193,7 +194,7 @@ const services: ServiceHandlers = {
193194 url = data ?. data ?. [ 0 ] ?. b64_json ;
194195
195196 if ( ! url ) {
196- throw new Error ( _ ( 'modai.cmp.failed_request' ) ) ;
197+ throw new Error ( lng ( 'modai.cmp.failed_request' ) ) ;
197198 }
198199
199200 url = `data:image/png;base64,${ url } ` ;
@@ -210,7 +211,7 @@ const services: ServiceHandlers = {
210211 const content = data ?. content ?. [ 0 ] ?. text ;
211212
212213 if ( ! content ) {
213- throw new Error ( _ ( 'modai.cmp.failed_request' ) ) ;
214+ throw new Error ( lng ( 'modai.cmp.failed_request' ) ) ;
214215 }
215216
216217 const id = data . id ;
@@ -226,7 +227,7 @@ const services: ServiceHandlers = {
226227 const content = data ?. candidates ?. [ 0 ] ?. content ?. parts ?. [ 0 ] ?. text ;
227228
228229 if ( ! content ) {
229- throw new Error ( _ ( 'modai.cmp.failed_request' ) ) ;
230+ throw new Error ( lng ( 'modai.cmp.failed_request' ) ) ;
230231 }
231232
232233 return {
@@ -238,7 +239,7 @@ const services: ServiceHandlers = {
238239 const base64 = data ?. predictions ?. [ 0 ] ?. bytesBase64Encoded ;
239240
240241 if ( ! base64 ) {
241- throw new Error ( _ ( 'modai.cmp.failed_request' ) ) ;
242+ throw new Error ( lng ( 'modai.cmp.failed_request' ) ) ;
242243 }
243244
244245 return {
@@ -455,7 +456,7 @@ const serviceExecutor = async <D extends ServiceResponse>(
455456
456457 const callStreamService = async ( details : ForExecutor ) => {
457458 if ( executorDetails . parser !== 'content' ) {
458- throw new Error ( _ ( 'modai.cmp.service_unsupported' ) ) ;
459+ throw new Error ( lng ( 'modai.cmp.service_unsupported' ) ) ;
459460 }
460461
461462 const res = await fetch ( details . url , {
@@ -476,15 +477,15 @@ const serviceExecutor = async <D extends ServiceResponse>(
476477 } ;
477478
478479 if ( ! executorDetails . service || ! executorDetails . parser ) {
479- throw new Error ( _ ( 'modai.cmp.service_required' ) ) ;
480+ throw new Error ( lng ( 'modai.cmp.service_required' ) ) ;
480481 }
481482
482483 if (
483484 ! services [ executorDetails . stream ? 'stream' : ( 'buffered' as BufferMode ) ] ?. [
484485 executorDetails . service as ServiceType
485486 ] ?. [ executorDetails . parser as keyof ServiceHandlers [ BufferMode ] [ ServiceType ] ]
486487 ) {
487- throw new Error ( _ ( 'modai.cmp.service_unsupported' ) ) ;
488+ throw new Error ( lng ( 'modai.cmp.service_unsupported' ) ) ;
488489 }
489490
490491 if ( executorDetails . stream ) {
@@ -557,7 +558,7 @@ const aiFetch = async <D extends ServiceResponse>(
557558
558559 if ( ! service || ! parser ) {
559560 controller . abort ( ) ;
560- throw new Error ( _ ( 'modai.cmp.service_required' ) ) ;
561+ throw new Error ( lng ( 'modai.cmp.service_required' ) ) ;
561562 }
562563
563564 if (
@@ -566,7 +567,7 @@ const aiFetch = async <D extends ServiceResponse>(
566567 ]
567568 ) {
568569 controller . abort ( ) ;
569- throw new Error ( _ ( 'modai.cmp.service_unsupported' ) ) ;
570+ throw new Error ( lng ( 'modai.cmp.service_unsupported' ) ) ;
570571 }
571572
572573 if ( ! stream ) {
@@ -577,7 +578,7 @@ const aiFetch = async <D extends ServiceResponse>(
577578 }
578579
579580 if ( parser !== 'content' ) {
580- throw new Error ( _ ( 'modai.cmp.service_unsupported' ) ) ;
581+ throw new Error ( lng ( 'modai.cmp.service_unsupported' ) ) ;
581582 }
582583
583584 return ( await handleStream (
0 commit comments