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

Function handleLine

web/src/llm-api/moonshot.ts:500–580  ·  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

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