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

Function handleLine

web/src/llm-api/siliconflow.ts:331–410  ·  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

329}
330
331async function handleLine({
332 userId,
333 stripeCustomerId,
334 agentId,
335 clientId,
336 clientRequestId,
337 costMode,
338 startTime,
339 request,
340 originalModel,
341 line,
342 state,
343 logger,
344 insertMessage,
345}: {
346 userId: string
347 stripeCustomerId?: string | null
348 agentId: string
349 clientId: string | null
350 clientRequestId: string | null
351 costMode: string | undefined
352 startTime: Date
353 request: unknown
354 originalModel: string
355 line: string
356 state: StreamState
357 logger: Logger
358 insertMessage: InsertMessageBigqueryFn
359}): Promise<LineResult> {
360 if (!line.startsWith('data: ')) {
361 return { state, patchedLine: line }
362 }
363
364 const raw = line.slice('data: '.length)
365 if (raw === '[DONE]\n' || raw === '[DONE]') {
366 return { state, patchedLine: line }
367 }
368
369 let obj: Record<string, unknown>
370 try {
371 obj = JSON.parse(raw)
372 } catch (error) {
373 logger.warn(
374 { error: getErrorObject(error, { includeRawError: true }) },
375 'Received non-JSON SiliconFlow response',
376 )
377 return { state, patchedLine: line }
378 }
379
380 // Patch model and provider for SDK compatibility
381 if (obj.model) obj.model = originalModel
382 if (!obj.provider) obj.provider = 'SiliconFlow'
383
384 // Process the chunk for billing / state tracking
385 const result = await handleResponse({
386 userId,
387 stripeCustomerId,
388 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