(params: {
body: unknown
logger: Logger
})
| 28 | } |
| 29 | |
| 30 | export 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 | |
| 64 | export async function insertMessageToBigQuery(params: { |
| 65 | messageId: string |
no test coverage detected