MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / handleLine

Function handleLine

web/src/llm-api/fireworks.ts:496–579  ·  view source on GitHub ↗
({
  userId,
  stripeCustomerId,
  agentId,
  clientId,
  clientRequestId,
  costMode,
  startTime,
  request,
  originalModel,
  line,
  state,
  logger,
  insertMessage,
}: {
  userId: string
  stripeCustomerId?: string | null
  agentId: string
  clientId: string | null
  clientRequestId: string | null
  costMode: string | undefined
  startTime: Date
  request: unknown
  originalModel: string
  line: string
  state: StreamState
  logger: Logger
  insertMessage: InsertMessageBigqueryFn
})

Source from the content-addressed store, hash-verified

494}
495
496async function handleLine({
497 userId,
498 stripeCustomerId,
499 agentId,
500 clientId,
501 clientRequestId,
502 costMode,
503 startTime,
504 request,
505 originalModel,
506 line,
507 state,
508 logger,
509 insertMessage,
510}: {
511 userId: string
512 stripeCustomerId?: string | null
513 agentId: string
514 clientId: string | null
515 clientRequestId: string | null
516 costMode: string | undefined
517 startTime: Date
518 request: unknown
519 originalModel: string
520 line: string
521 state: StreamState
522 logger: Logger
523 insertMessage: InsertMessageBigqueryFn
524}): Promise<LineResult> {
525 if (!line.startsWith('data: ')) {
526 return { state, patchedLine: line }
527 }
528
529 const raw = line.slice('data: '.length)
530 if (raw === '[DONE]\n' || raw === '[DONE]') {
531 return { state, patchedLine: line }
532 }
533
534 let obj: Record<string, unknown>
535 try {
536 obj = JSON.parse(raw)
537 } catch (error) {
538 logger.warn(
539 { error: getErrorObject(error, { includeRawError: true }) },
540 'Received non-JSON Fireworks response',
541 )
542 return { state, patchedLine: line }
543 }
544
545 // Patch model and provider for SDK compatibility
546 if (obj.model) obj.model = originalModel
547 if (!obj.provider) obj.provider = 'Fireworks'
548
549 // Process the chunk for billing / state tracking
550 const result = await handleResponse({
551 userId,
552 stripeCustomerId,
553 agentId,

Callers 1

startFunction · 0.70

Calls 4

getErrorObjectFunction · 0.90
parseMethod · 0.80
handleResponseFunction · 0.70
creditsToFakeCostFunction · 0.70

Tested by

no test coverage detected