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

Function handleLine

web/src/llm-api/canopywave.ts:366–445  ·  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

364}
365
366async function handleLine({
367 userId,
368 stripeCustomerId,
369 agentId,
370 clientId,
371 clientRequestId,
372 costMode,
373 startTime,
374 request,
375 originalModel,
376 line,
377 state,
378 logger,
379 insertMessage,
380}: {
381 userId: string
382 stripeCustomerId?: string | null
383 agentId: string
384 clientId: string | null
385 clientRequestId: string | null
386 costMode: string | undefined
387 startTime: Date
388 request: unknown
389 originalModel: string
390 line: string
391 state: StreamState
392 logger: Logger
393 insertMessage: InsertMessageBigqueryFn
394}): Promise<LineResult> {
395 if (!line.startsWith('data: ')) {
396 return { state, patchedLine: line }
397 }
398
399 const raw = line.slice('data: '.length)
400 if (raw === '[DONE]\n' || raw === '[DONE]') {
401 return { state, patchedLine: line }
402 }
403
404 let obj: Record<string, unknown>
405 try {
406 obj = JSON.parse(raw)
407 } catch (error) {
408 logger.warn(
409 { error: getErrorObject(error, { includeRawError: true }) },
410 'Received non-JSON CanopyWave response',
411 )
412 return { state, patchedLine: line }
413 }
414
415 // Patch model and provider for SDK compatibility
416 if (obj.model) obj.model = originalModel
417 if (!obj.provider) obj.provider = 'CanopyWave'
418
419 // Process the chunk for billing / state tracking
420 const result = await handleResponse({
421 userId,
422 stripeCustomerId,
423 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