Skip to content

Commit ba520bf

Browse files
committed
fix: replace as any casts with proper types in relabel endpoint
- Add System type import from agent-runtime - Add StoredMessage interface for BigQuery trace messages - Add BigQueryTimestamp interface for timestamp handling - Replace all as any casts with proper type assertions
1 parent 03db2d8 commit ba520bf

File tree

1 file changed

+22
-8
lines changed
  • web/src/app/api/admin/relabel-for-user

1 file changed

+22
-8
lines changed

web/src/app/api/admin/relabel-for-user/route.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,18 @@ import { logger } from '../../../../util/logger'
2828

2929
import type { Message } from '@codebuff/common/types/messages/codebuff-message'
3030
import type { NextRequest } from 'next/server'
31+
import type { System } from '@codebuff/agent-runtime/llm-api/claude'
32+
33+
// Type for messages stored in BigQuery traces
34+
interface StoredMessage {
35+
role?: string
36+
content?: string | Array<{ type?: string; text?: string }>
37+
}
38+
39+
// Type for BigQuery timestamp values
40+
interface BigQueryTimestamp {
41+
value?: string | number
42+
}
3143

3244

3345
const STATIC_SESSION_ID = 'relabel-trace-api'
@@ -192,7 +204,7 @@ async function relabelTraceWithModel(params: {
192204
try {
193205
const messages = messagesWithSystem({
194206
messages: (payload.messages || []) as Message[],
195-
system: payload.system as any,
207+
system: payload.system as System,
196208
})
197209

198210
const output = await promptAiSdk({
@@ -408,15 +420,17 @@ async function relabelWithClaudeWithFullFileContext(params: {
408420
? (JSON.parse(trace.payload) as GetRelevantFilesPayload)
409421
: (trace.payload as GetRelevantFilesPayload)
410422

411-
let system = tracePayload.system as any
423+
let system: System = tracePayload.system as System
412424
if (typeof system === 'string') {
413425
system = system + partialFileContext
414426
} else if (Array.isArray(system) && system.length > 0) {
415-
system = [...system]
416-
system[system.length - 1] = {
417-
...system[system.length - 1],
418-
text: `${system[system.length - 1].text}${partialFileContext}`,
427+
const systemCopy = [...system]
428+
const lastBlock = systemCopy[systemCopy.length - 1]
429+
systemCopy[systemCopy.length - 1] = {
430+
...lastBlock,
431+
text: `${lastBlock.text}${partialFileContext}`,
419432
}
433+
system = systemCopy
420434
}
421435

422436
const output = await promptAiSdk({
@@ -459,7 +473,7 @@ function formatTraceResults(traceBundles: TraceBundle[]) {
459473
trace.created_at instanceof Date
460474
? trace.created_at.toISOString()
461475
: new Date(
462-
(trace.created_at as any)?.value ?? trace.created_at,
476+
(trace.created_at as BigQueryTimestamp)?.value ?? trace.created_at,
463477
).toISOString()
464478

465479
const query = extractQueryFromMessages(payload.messages)
@@ -492,7 +506,7 @@ function formatTraceResults(traceBundles: TraceBundle[]) {
492506

493507
function extractQueryFromMessages(messages: unknown): string {
494508
const items = Array.isArray(messages) ? messages : []
495-
const lastMessage = items[items.length - 1] as any
509+
const lastMessage = items[items.length - 1] as StoredMessage | undefined
496510
const content = Array.isArray(lastMessage?.content)
497511
? lastMessage.content[0]?.text
498512
: lastMessage?.content

0 commit comments

Comments
 (0)