Skip to content

Commit b9bd7e3

Browse files
committed
refactor: convert parseRawToolCall, parseRawCustomToolCall, and fix getUserIdFromAuthToken call sites to use object parameters
1 parent 0b6b66c commit b9bd7e3

File tree

5 files changed

+31
-26
lines changed

5 files changed

+31
-26
lines changed

backend/src/api/org.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ async function isRepoCoveredHandler(
3535
.status(401)
3636
.json({ error: 'Missing x-codebuff-api-key header' })
3737
}
38-
const userId = await getUserIdFromAuthToken(authToken)
38+
const userId = await getUserIdFromAuthToken({ authToken })
3939

4040
if (!userId) {
4141
return res.status(401).json({ error: INVALID_AUTH_TOKEN_MESSAGE })

backend/src/tools/tool-executor.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,15 @@ export type ToolCallError = {
4444
error: string
4545
} & Pick<CodebuffToolCall, 'toolCallId'>
4646

47-
export function parseRawToolCall<T extends ToolName = ToolName>(
47+
export function parseRawToolCall<T extends ToolName = ToolName>(params: {
4848
rawToolCall: {
4949
toolName: T
5050
toolCallId: string
5151
input: Record<string, unknown>
52-
},
53-
autoInsertEndStepParam: boolean = false,
54-
): CodebuffToolCall<T> | ToolCallError {
52+
}
53+
autoInsertEndStepParam?: boolean
54+
}): CodebuffToolCall<T> | ToolCallError {
55+
const { rawToolCall, autoInsertEndStepParam = false } = params
5556
const toolName = rawToolCall.toolName
5657

5758
if (!(toolName in codebuffToolDefs)) {
@@ -152,14 +153,14 @@ export function executeToolCall<T extends ToolName>({
152153
autoInsertEndStepParam = false,
153154
excludeToolFromMessageHistory = false,
154155
}: ExecuteToolCallParams<T>): Promise<void> {
155-
const toolCall: CodebuffToolCall<T> | ToolCallError = parseRawToolCall<T>(
156-
{
156+
const toolCall: CodebuffToolCall<T> | ToolCallError = parseRawToolCall<T>({
157+
rawToolCall: {
157158
toolName,
158159
toolCallId: generateCompactId(),
159160
input,
160161
},
161162
autoInsertEndStepParam,
162-
)
163+
})
163164
if ('error' in toolCall) {
164165
const toolResult: ToolResultPart = {
165166
type: 'tool-result',
@@ -283,15 +284,16 @@ export function executeToolCall<T extends ToolName>({
283284
})
284285
}
285286

286-
export function parseRawCustomToolCall(
287-
customToolDefs: z.infer<typeof customToolDefinitionsSchema>,
287+
export function parseRawCustomToolCall(params: {
288+
customToolDefs: z.infer<typeof customToolDefinitionsSchema>
288289
rawToolCall: {
289290
toolName: string
290291
toolCallId: string
291292
input: Record<string, unknown>
292-
},
293-
autoInsertEndStepParam: boolean = false,
294-
): CustomToolCall | ToolCallError {
293+
}
294+
autoInsertEndStepParam?: boolean
295+
}): CustomToolCall | ToolCallError {
296+
const { customToolDefs, rawToolCall, autoInsertEndStepParam = false } = params
295297
const toolName = rawToolCall.toolName
296298

297299
if (!(toolName in customToolDefs) && !toolName.includes('/')) {
@@ -376,20 +378,20 @@ export async function executeCustomToolCall({
376378
autoInsertEndStepParam = false,
377379
excludeToolFromMessageHistory = false,
378380
}: ExecuteToolCallParams<string>): Promise<void> {
379-
const toolCall: CustomToolCall | ToolCallError = parseRawCustomToolCall(
380-
await getMCPToolData({
381+
const toolCall: CustomToolCall | ToolCallError = parseRawCustomToolCall({
382+
customToolDefs: await getMCPToolData({
381383
ws,
382384
toolNames: agentTemplate.toolNames,
383385
mcpServers: agentTemplate.mcpServers,
384386
writeTo: cloneDeep(fileContext.customToolDefinitions),
385387
}),
386-
{
388+
rawToolCall: {
387389
toolName,
388390
toolCallId: generateCompactId(),
389391
input,
390392
},
391393
autoInsertEndStepParam,
392-
)
394+
})
393395
if ('error' in toolCall) {
394396
const toolResult: ToolResultPart = {
395397
type: 'tool-result',

backend/src/websockets/websocket-action.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,7 @@ const onPrompt = async (
139139
await withLoggerContext(
140140
{ fingerprintId, clientRequestId: promptId, costMode },
141141
async () => {
142-
const userId = await getUserIdFromAuthToken(authToken)
142+
const userId = await getUserIdFromAuthToken({ authToken })
143143
if (!userId) {
144144
throw new Error('User not found')
145145
}
@@ -285,7 +285,7 @@ const onInit = async (
285285
ws: WebSocket,
286286
) => {
287287
await withLoggerContext({ fingerprintId }, async () => {
288-
const userId = await getUserIdFromAuthToken(authToken)
288+
const userId = await getUserIdFromAuthToken({ authToken })
289289

290290
if (!userId) {
291291
sendAction(ws, {
@@ -314,7 +314,7 @@ const onCancelUserInput = async ({
314314
authToken,
315315
promptId,
316316
}: ClientAction<'cancel-user-input'>) => {
317-
const userId = await getUserIdFromAuthToken(authToken)
317+
const userId = await getUserIdFromAuthToken({ authToken })
318318
if (!userId) {
319319
logger.error({ authToken }, 'User id not found for authToken')
320320
return

scripts/ft-file-selection/relabel-for-offline-scoring.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ async function relabelTraceForModel(
169169
const messages = payload.messages as Message[]
170170
const system = payload.system as System
171171

172-
let transformedMessages = messagesWithSystem(messages, system)
172+
let transformedMessages = messagesWithSystem({ messages, system })
173173
if (modelToTest === finetunedVertexModels.ft_filepicker_010) {
174174
transformedMessages = transformedMessages
175175
.map((msg, i) => {

scripts/ft-file-selection/relabel-traces.ts

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,10 @@ async function runTraces() {
5858

5959
if (model.startsWith('claude')) {
6060
output = await promptAiSdk({
61-
messages: messagesWithSystem(
62-
messages as Message[],
63-
system as System,
64-
),
61+
messages: messagesWithSystem({
62+
messages: messages as Message[],
63+
system: system as System,
64+
}),
6565
model: model as typeof models.openrouter_claude_sonnet_4,
6666
clientSessionId: 'relabel-trace-run',
6767
fingerprintId: 'relabel-trace-run',
@@ -70,7 +70,10 @@ async function runTraces() {
7070
})
7171
} else {
7272
output = await promptFlashWithFallbacks(
73-
messagesWithSystem(messages as Message[], system as System),
73+
messagesWithSystem({
74+
messages: messages as Message[],
75+
system: system as System,
76+
}),
7477
{
7578
model:
7679
model as typeof models.openrouter_gemini2_5_pro_preview,

0 commit comments

Comments
 (0)