Skip to content

Commit 8d56a1c

Browse files
Refactor fast-rewrite functions to accept logger as parameter
🤖 Generated with Codebuff Co-Authored-By: Codebuff <noreply@codebuff.com>
1 parent e411838 commit 8d56a1c

File tree

3 files changed

+21
-1
lines changed

3 files changed

+21
-1
lines changed

backend/src/__tests__/fast-rewrite.test.ts

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,15 @@ import { createPatch } from 'diff'
1010

1111
import { rewriteWithOpenAI } from '../fast-rewrite'
1212

13+
import type { Logger } from '@codebuff/types/logger'
14+
15+
const logger: Logger = {
16+
debug: () => {},
17+
info: () => {},
18+
warn: () => {},
19+
error: () => {},
20+
}
21+
1322
describe.skip('rewriteWithOpenAI', () => {
1423
beforeAll(() => {
1524
// Mock database interactions
@@ -52,6 +61,7 @@ describe.skip('rewriteWithOpenAI', () => {
5261
userInputId: 'userInputId',
5362
userId: TEST_USER_ID,
5463
userMessage: undefined,
64+
logger,
5565
})
5666

5767
const patch = createPatch('test.ts', expectedResult, result)

backend/src/fast-rewrite.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import { generateCompactId, hasLazyEdit } from '@codebuff/common/util/string'
66
import { promptFlashWithFallbacks } from './llm-apis/gemini-with-fallbacks'
77
import { promptRelaceAI } from './llm-apis/relace-api'
88
import { promptAiSdk } from './llm-apis/vercel-ai-sdk/ai-sdk'
9-
import { logger } from './util/logger'
109

10+
import type { Logger } from '@codebuff/types/logger'
1111
import type { CodebuffToolMessage } from '@codebuff/common/tools/list'
1212
import type {
1313
Message,
@@ -24,6 +24,7 @@ export async function fastRewrite(params: {
2424
userInputId: string
2525
userId: string | undefined
2626
userMessage: string | undefined
27+
logger: Logger
2728
}) {
2829
const {
2930
initialContent,
@@ -35,6 +36,7 @@ export async function fastRewrite(params: {
3536
userInputId,
3637
userId,
3738
userMessage,
39+
logger,
3840
} = params
3941
const relaceStartTime = Date.now()
4042
const messageId = generateCompactId('cb-')
@@ -69,6 +71,7 @@ export async function fastRewrite(params: {
6971
userInputId,
7072
userId,
7173
userMessage,
74+
logger,
7275
})
7376
logger.debug(
7477
{ filePath, relaceResponse, openaiResponse: response, messageId },
@@ -101,6 +104,7 @@ export async function rewriteWithOpenAI(params: {
101104
userInputId: string
102105
userId: string | undefined
103106
userMessage: string | undefined
107+
logger: Logger
104108
}): Promise<string> {
105109
const {
106110
oldContent,
@@ -111,6 +115,7 @@ export async function rewriteWithOpenAI(params: {
111115
userInputId,
112116
userId,
113117
userMessage,
118+
logger,
114119
} = params
115120
const prompt = `You are an expert programmer tasked with implementing changes to a file. Please rewrite the file to implement the changes shown in the edit snippet, while preserving the original formatting and behavior of unchanged parts.
116121
@@ -163,6 +168,7 @@ export const shouldAddFilePlaceholders = async (params: {
163168
clientSessionId: string
164169
fingerprintId: string
165170
userInputId: string
171+
logger: Logger
166172
}) => {
167173
const {
168174
filePath,
@@ -174,6 +180,7 @@ export const shouldAddFilePlaceholders = async (params: {
174180
clientSessionId,
175181
fingerprintId,
176182
userInputId,
183+
logger,
177184
} = params
178185
const fileWasPreviouslyEdited = messageHistory
179186
.filter(

backend/src/process-file-block.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,7 @@ export async function processFileBlock(params: {
145145
userInputId,
146146
userId,
147147
userMessage: lastUserPrompt,
148+
logger,
148149
})
149150
const shouldAddPlaceholders = await shouldAddFilePlaceholders({
150151
filePath: path,
@@ -156,6 +157,7 @@ export async function processFileBlock(params: {
156157
clientSessionId,
157158
fingerprintId,
158159
userInputId,
160+
logger,
159161
})
160162

161163
if (shouldAddPlaceholders) {
@@ -171,6 +173,7 @@ export async function processFileBlock(params: {
171173
userInputId,
172174
userId,
173175
userMessage: lastUserPrompt,
176+
logger,
174177
})
175178
}
176179
}

0 commit comments

Comments
 (0)