Skip to content

Commit 6daf58f

Browse files
Refactor tool-executor.ts to pass logger as parameter
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent 1dc8831 commit 6daf58f

File tree

4 files changed

+52
-40
lines changed

4 files changed

+52
-40
lines changed

backend/src/run-programmatic-step.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -278,6 +278,7 @@ export async function runProgrammaticStep(
278278
userId,
279279
autoInsertEndStepParam: true,
280280
excludeToolFromMessageHistory,
281+
logger,
281282
})
282283

283284
// TODO: Remove messages from state and always use agentState.messageHistory.

backend/src/tools/stream-parser.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,7 @@ export async function processStreamWithTools(options: {
200200
onResponseChunk,
201201
state,
202202
userId,
203+
logger,
203204
})
204205
}
205206
},
@@ -227,6 +228,7 @@ export async function processStreamWithTools(options: {
227228
onResponseChunk,
228229
state,
229230
userId,
231+
logger,
230232
})
231233
},
232234
}

backend/src/tools/tool-executor.ts

Lines changed: 48 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import z from 'zod/v4'
66
import { convertJsonSchemaToZod } from 'zod-from-json-schema'
77

88
import { checkLiveUserInput } from '../live-user-inputs'
9-
import { logger } from '../util/logger'
109
import { requestToolCall } from '../websockets/websocket-action'
1110
import { codebuffToolDefs } from './definitions/list'
1211
import { codebuffToolHandlers } from './handlers/list'
@@ -31,6 +30,7 @@ import type {
3130
customToolDefinitionsSchema,
3231
ProjectFileContext,
3332
} from '@codebuff/common/util/file'
33+
import type { Logger } from '@codebuff/types/logger'
3434
import type { WebSocket } from 'ws'
3535

3636
export type CustomToolCall = {
@@ -131,28 +131,33 @@ export interface ExecuteToolCallParams<T extends string = ToolName> {
131131
userId: string | undefined
132132
autoInsertEndStepParam?: boolean
133133
excludeToolFromMessageHistory?: boolean
134+
logger: Logger
134135
}
135136

136-
export function executeToolCall<T extends ToolName>({
137-
toolName,
138-
input,
139-
toolCalls,
140-
toolResults,
141-
toolResultsToAddAfterStream,
142-
previousToolCallFinished,
143-
ws,
144-
agentTemplate,
145-
fileContext,
146-
agentStepId,
147-
clientSessionId,
148-
userInputId,
149-
fullResponse,
150-
onResponseChunk,
151-
state,
152-
userId,
153-
autoInsertEndStepParam = false,
154-
excludeToolFromMessageHistory = false,
155-
}: ExecuteToolCallParams<T>): Promise<void> {
137+
export function executeToolCall<T extends ToolName>(
138+
params: ExecuteToolCallParams<T>,
139+
): Promise<void> {
140+
const {
141+
toolName,
142+
input,
143+
toolCalls,
144+
toolResults,
145+
toolResultsToAddAfterStream,
146+
previousToolCallFinished,
147+
ws,
148+
agentTemplate,
149+
fileContext,
150+
agentStepId,
151+
clientSessionId,
152+
userInputId,
153+
fullResponse,
154+
onResponseChunk,
155+
state,
156+
userId,
157+
autoInsertEndStepParam = false,
158+
excludeToolFromMessageHistory = false,
159+
logger,
160+
} = params
156161
const toolCall: CodebuffToolCall<T> | ToolCallError = parseRawToolCall<T>({
157162
rawToolCall: {
158163
toolName,
@@ -360,24 +365,28 @@ export function parseRawCustomToolCall(params: {
360365
}
361366
}
362367

363-
export async function executeCustomToolCall({
364-
toolName,
365-
input,
366-
toolCalls,
367-
toolResults,
368-
toolResultsToAddAfterStream,
369-
previousToolCallFinished,
370-
ws,
371-
agentTemplate,
372-
fileContext,
373-
clientSessionId,
374-
userInputId,
375-
onResponseChunk,
376-
state,
377-
userId,
378-
autoInsertEndStepParam = false,
379-
excludeToolFromMessageHistory = false,
380-
}: ExecuteToolCallParams<string>): Promise<void> {
368+
export async function executeCustomToolCall(
369+
params: ExecuteToolCallParams<string>,
370+
): Promise<void> {
371+
const {
372+
toolName,
373+
input,
374+
toolCalls,
375+
toolResults,
376+
toolResultsToAddAfterStream,
377+
previousToolCallFinished,
378+
ws,
379+
agentTemplate,
380+
fileContext,
381+
clientSessionId,
382+
userInputId,
383+
onResponseChunk,
384+
state,
385+
userId,
386+
autoInsertEndStepParam = false,
387+
excludeToolFromMessageHistory = false,
388+
logger,
389+
} = params
381390
const toolCall: CustomToolCall | ToolCallError = parseRawCustomToolCall({
382391
customToolDefs: await getMCPToolData({
383392
ws,

plans/logger-refactor-plan.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ For all other files:
3131

3232
- **Always run full `bun run typecheck`** (not head/tail!) to find ALL errors
3333
- Update function calls to pass object with named properties
34-
- For tests: create mock logger constant called `logger` with all 4 methods (debug, info, warn, error)
34+
- For tests: create a no-op logger constant called `logger` with all 4 methods (debug, info, warn, error)
3535
- Use `allowMultiple: true` in str_replace when updating multiple calls in same file
3636
- **Check carefully** - there may be multiple call sites in the same file!
3737
- Repeat typecheck until ALL errors resolved

0 commit comments

Comments
 (0)