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

Function handleLine

web/src/llm-api/opencode-zen.ts:480–560  ·  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

478}
479
480async function handleLine({
481 userId,
482 stripeCustomerId,
483 agentId,
484 clientId,
485 clientRequestId,
486 costMode,
487 startTime,
488 request,
489 originalModel,
490 line,
491 state,
492 logger,
493 insertMessage,
494}: {
495 userId: string
496 stripeCustomerId?: string | null
497 agentId: string
498 clientId: string | null
499 clientRequestId: string | null
500 costMode: string | undefined
501 startTime: Date
502 request: unknown
503 originalModel: string
504 line: string
505 state: StreamState
506 logger: Logger
507 insertMessage: InsertMessageBigqueryFn
508}): Promise<LineResult> {
509 if (!line.startsWith('data: ')) {
510 return { state, patchedLine: line }
511 }
512
513 const raw = line.slice('data: '.length)
514 if (raw === '[DONE]\n' || raw === '[DONE]') {
515 return { state, patchedLine: line }
516 }
517
518 let obj: Record<string, unknown>
519 try {
520 obj = JSON.parse(raw)
521 } catch (error) {
522 logger.warn(
523 { error: getErrorObject(error, { includeRawError: true }) },
524 'Received non-JSON OpenCode Zen response',
525 )
526 return { state, patchedLine: line }
527 }
528
529 if (obj.model) obj.model = originalModel
530 if (!obj.provider) obj.provider = 'OpenCode Zen'
531
532 const result = await handleResponse({
533 userId,
534 stripeCustomerId,
535 agentId,
536 clientId,
537 clientRequestId,

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