@@ -10,6 +10,8 @@ import { XmlMatcher } from "../../utils/xml-matcher"
1010
1111import type { ApiHandlerCreateMessageMetadata , SingleCompletionHandler } from "../index"
1212import { BaseProvider } from "./base-provider"
13+ import { DEFAULT_HEADERS } from "./constants"
14+ import { t } from "../../i18n"
1315
1416const CEREBRAS_BASE_URL = "https://api.cerebras.ai/v1"
1517const CEREBRAS_DEFAULT_TEMPERATURE = 0
@@ -138,9 +140,9 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
138140 const response = await fetch ( `${ CEREBRAS_BASE_URL } /chat/completions` , {
139141 method : "POST" ,
140142 headers : {
143+ ...DEFAULT_HEADERS ,
141144 "Content-Type" : "application/json" ,
142145 Authorization : `Bearer ${ this . apiKey } ` ,
143- "User-Agent" : "roo-cline/1.0.0" ,
144146 } ,
145147 body : JSON . stringify ( requestBody ) ,
146148 } )
@@ -158,24 +160,22 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
158160
159161 // Provide more actionable error messages
160162 if ( response . status === 401 ) {
161- throw new Error (
162- `Cerebras API authentication failed. Please check your API key is valid and not expired.` ,
163- )
163+ throw new Error ( t ( "common:errors.cerebras.authenticationFailed" ) )
164164 } else if ( response . status === 403 ) {
165- throw new Error (
166- `Cerebras API access forbidden. Your API key may not have access to the requested model or feature.` ,
167- )
165+ throw new Error ( t ( "common:errors.cerebras.accessForbidden" ) )
168166 } else if ( response . status === 429 ) {
169- throw new Error ( `Cerebras API rate limit exceeded. Please wait before making another request.` )
167+ throw new Error ( t ( "common:errors.cerebras.rateLimitExceeded" ) )
170168 } else if ( response . status >= 500 ) {
171- throw new Error ( `Cerebras API server error ( ${ response . status } ). Please try again later.` )
169+ throw new Error ( t ( "common:errors.cerebras.serverError" , { status : response . status } ) )
172170 } else {
173- throw new Error ( `Cerebras API Error (${ response . status } ): ${ errorMessage } ` )
171+ throw new Error (
172+ t ( "common:errors.cerebras.genericError" , { status : response . status , message : errorMessage } ) ,
173+ )
174174 }
175175 }
176176
177177 if ( ! response . body ) {
178- throw new Error ( "Cerebras API Error: No response body" )
178+ throw new Error ( t ( "common:errors.cerebras.noResponseBody" ) )
179179 }
180180
181181 // Initialize XmlMatcher to parse <think>...</think> tags
@@ -262,7 +262,7 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
262262 }
263263 } catch ( error ) {
264264 if ( error instanceof Error ) {
265- throw new Error ( `Cerebras API error: ${ error . message } ` )
265+ throw new Error ( t ( "common:errors.cerebras.completionError" , { error : error . message } ) )
266266 }
267267 throw error
268268 }
@@ -282,9 +282,9 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
282282 const response = await fetch ( `${ CEREBRAS_BASE_URL } /chat/completions` , {
283283 method : "POST" ,
284284 headers : {
285+ ...DEFAULT_HEADERS ,
285286 "Content-Type" : "application/json" ,
286287 Authorization : `Bearer ${ this . apiKey } ` ,
287- "User-Agent" : "roo-cline/1.0.0" ,
288288 } ,
289289 body : JSON . stringify ( requestBody ) ,
290290 } )
@@ -294,27 +294,25 @@ export class CerebrasHandler extends BaseProvider implements SingleCompletionHan
294294
295295 // Provide consistent error handling with createMessage
296296 if ( response . status === 401 ) {
297- throw new Error (
298- `Cerebras API authentication failed. Please check your API key is valid and not expired.` ,
299- )
297+ throw new Error ( t ( "common:errors.cerebras.authenticationFailed" ) )
300298 } else if ( response . status === 403 ) {
301- throw new Error (
302- `Cerebras API access forbidden. Your API key may not have access to the requested model or feature.` ,
303- )
299+ throw new Error ( t ( "common:errors.cerebras.accessForbidden" ) )
304300 } else if ( response . status === 429 ) {
305- throw new Error ( `Cerebras API rate limit exceeded. Please wait before making another request.` )
301+ throw new Error ( t ( "common:errors.cerebras.rateLimitExceeded" ) )
306302 } else if ( response . status >= 500 ) {
307- throw new Error ( `Cerebras API server error ( ${ response . status } ). Please try again later.` )
303+ throw new Error ( t ( "common:errors.cerebras.serverError" , { status : response . status } ) )
308304 } else {
309- throw new Error ( `Cerebras API Error (${ response . status } ): ${ errorText } ` )
305+ throw new Error (
306+ t ( "common:errors.cerebras.genericError" , { status : response . status , message : errorText } ) ,
307+ )
310308 }
311309 }
312310
313311 const result = await response . json ( )
314312 return result . choices ?. [ 0 ] ?. message ?. content || ""
315313 } catch ( error ) {
316314 if ( error instanceof Error ) {
317- throw new Error ( `Cerebras completion error: ${ error . message } ` )
315+ throw new Error ( t ( "common:errors.cerebras.completionError" , { error : error . message } ) )
318316 }
319317 throw error
320318 }
0 commit comments