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

Function extractRequestMetadata

web/src/llm-api/helpers.ts:30–62  ·  view source on GitHub ↗
(params: {
  body: unknown
  logger: Logger
})

Source from the content-addressed store, hash-verified

28}
29
30export function extractRequestMetadata(params: {
31 body: unknown
32 logger: Logger
33}) {
34 const { body, logger } = params
35
36 const typedBody = body as ChatCompletionRequestBody | undefined
37 const metadata = typedBody?.codebuff_metadata
38
39 const rawClientId = metadata?.client_id
40 const clientId = typeof rawClientId === 'string' ? rawClientId : null
41 if (!clientId) {
42 logger.warn(
43 { request: createRequestAuditRecord(body) },
44 'Received request without client_id',
45 )
46 }
47
48 const rawRunId = metadata?.run_id
49 const clientRequestId: string | null =
50 typeof rawRunId === 'string' ? rawRunId : null
51 if (!clientRequestId) {
52 logger.warn(
53 { request: createRequestAuditRecord(body) },
54 'Received request without run_id',
55 )
56 }
57
58 const n = metadata?.n
59 const rawCostMode = metadata?.cost_mode
60 const costMode = typeof rawCostMode === 'string' ? rawCostMode : undefined
61 return { clientId, clientRequestId, costMode, ...(n && { n }) }
62}
63
64export async function insertMessageToBigQuery(params: {
65 messageId: string

Callers 15

handleOpenAINonStreamFunction · 0.90
handleOpenAIStreamFunction · 0.90
handleOpenRouterStreamFunction · 0.90
handleSiliconFlowStreamFunction · 0.90
handleCanopyWaveStreamFunction · 0.90
handleOpenCodeZenStreamFunction · 0.90
handleMoonshotNonStreamFunction · 0.90
handleMoonshotStreamFunction · 0.90

Calls 1

createRequestAuditRecordFunction · 0.90

Tested by

no test coverage detected