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

Function createRequestAuditRecord

web/src/llm-api/request-audit.ts:3–77  ·  view source on GitHub ↗
(body: unknown)

Source from the content-addressed store, hash-verified

1import type { ChatCompletionRequestBody } from './types'
2
3export function createRequestAuditRecord(body: unknown) {
4 if (typeof body !== 'object' || body === null || Array.isArray(body)) {
5 return { invalid_request_shape: true }
6 }
7
8 const typedBody = body as Partial<ChatCompletionRequestBody>
9 const messages = Array.isArray(typedBody.messages)
10 ? typedBody.messages
11 : undefined
12 const tools = Array.isArray(typedBody.tools) ? typedBody.tools : undefined
13
14 const messageRoleCounts = messages?.reduce<Record<string, number>>(
15 (counts, message) => {
16 const role =
17 typeof message === 'object' && message !== null && 'role' in message
18 ? String(message.role)
19 : 'unknown'
20 counts[role] = (counts[role] ?? 0) + 1
21 return counts
22 },
23 {},
24 )
25
26 return {
27 model: typeof typedBody.model === 'string' ? typedBody.model : undefined,
28 stream:
29 typeof typedBody.stream === 'boolean' ? typedBody.stream : undefined,
30 temperature:
31 typeof typedBody.temperature === 'number'
32 ? typedBody.temperature
33 : undefined,
34 max_tokens:
35 typeof typedBody.max_tokens === 'number'
36 ? typedBody.max_tokens
37 : undefined,
38 max_completion_tokens:
39 typeof typedBody.max_completion_tokens === 'number'
40 ? typedBody.max_completion_tokens
41 : undefined,
42 top_p: typeof typedBody.top_p === 'number' ? typedBody.top_p : undefined,
43 reasoning_effort:
44 typeof typedBody.reasoning_effort === 'string'
45 ? typedBody.reasoning_effort
46 : undefined,
47 reasoning_enabled:
48 typeof typedBody.reasoning?.enabled === 'boolean'
49 ? typedBody.reasoning.enabled
50 : undefined,
51 reasoning_effort_nested:
52 typeof typedBody.reasoning?.effort === 'string'
53 ? typedBody.reasoning.effort
54 : undefined,
55 usage_include:
56 typeof typedBody.usage?.include === 'boolean'
57 ? typedBody.usage.include
58 : undefined,
59 codebuff_metadata:
60 typeof typedBody.codebuff_metadata === 'object' &&

Callers 15

extractRequestMetadataFunction · 0.90
handleOpenAINonStreamFunction · 0.85
handleOpenAIStreamFunction · 0.85
handleOpenRouterStreamFunction · 0.85
handleSiliconFlowStreamFunction · 0.85
handleCanopyWaveStreamFunction · 0.85
handleOpenCodeZenStreamFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected