Skip to content

Commit 8c070b6

Browse files
committed
remove custom file picker logic
1 parent d79135e commit 8c070b6

File tree

1 file changed

+1
-117
lines changed

1 file changed

+1
-117
lines changed

backend/src/find-files/request-files-prompt.ts

Lines changed: 1 addition & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,20 @@
11
import { dirname, isAbsolute, normalize } from 'path'
22

3-
import { CustomFilePickerConfigSchema } from '@codebuff/agent-runtime/find-files/custom-file-picker-config'
43
import { promptFlashWithFallbacks } from '@codebuff/agent-runtime/llm-api/gemini-with-fallbacks'
54
import {
65
castAssistantMessage,
76
messagesWithSystem,
87
getMessagesSubset,
98
} from '@codebuff/agent-runtime/util/messages'
109
import { insertTrace } from '@codebuff/bigquery'
11-
import db from '@codebuff/common/db'
12-
import * as schema from '@codebuff/common/db/schema'
1310
import {
1411
finetunedVertexModels,
1512
models,
1613
type FinetunedVertexModel,
1714
} from '@codebuff/common/old-constants'
1815
import { getAllFilePaths } from '@codebuff/common/project-file-tree'
19-
import { and, eq } from 'drizzle-orm'
2016
import { range, shuffle, uniq } from 'lodash'
2117

22-
import { getRequestContext } from '../websockets/request-context'
23-
24-
import type { CustomFilePickerConfig } from '@codebuff/agent-runtime/find-files/custom-file-picker-config'
2518
import type { TextBlock } from '@codebuff/agent-runtime/llm-api/claude'
2619
import type {
2720
GetExpandedFileContextForTrainingTrace,
@@ -36,91 +29,6 @@ import type { ProjectFileContext } from '@codebuff/common/util/file'
3629
const NUMBER_OF_EXAMPLE_FILES = 100
3730
const MAX_FILES_PER_REQUEST = 30
3831

39-
export async function getCustomFilePickerConfigForOrg(params: {
40-
orgId: string | undefined
41-
isRepoApprovedForUserInOrg: boolean | undefined
42-
logger: Logger
43-
}): Promise<CustomFilePickerConfig | null> {
44-
const { orgId, isRepoApprovedForUserInOrg, logger } = params
45-
if (!orgId || !isRepoApprovedForUserInOrg) {
46-
return null
47-
}
48-
49-
try {
50-
const orgFeature = await db
51-
.select()
52-
.from(schema.orgFeature)
53-
.where(
54-
and(
55-
eq(schema.orgFeature.org_id, orgId),
56-
eq(schema.orgFeature.feature, 'custom-file-picker'),
57-
eq(schema.orgFeature.is_active, true),
58-
),
59-
)
60-
.limit(1)
61-
.then((rows) => rows[0])
62-
63-
if (orgFeature?.config && typeof orgFeature.config === 'string') {
64-
// Check if config is a string
65-
let parsedConfigObject
66-
try {
67-
parsedConfigObject = JSON.parse(orgFeature.config)
68-
} catch (jsonParseError) {
69-
logger.error(
70-
{ error: jsonParseError, orgId, configString: orgFeature.config },
71-
'Failed to parse customFilePickerConfig JSON string',
72-
)
73-
return null // Parsing the string itself failed
74-
}
75-
76-
const parseResult =
77-
CustomFilePickerConfigSchema.safeParse(parsedConfigObject) // Parse the object
78-
if (parseResult.success) {
79-
logger.info(
80-
{ orgId, modelName: parseResult.data.modelName },
81-
'Using custom file picker configuration for organization',
82-
)
83-
return parseResult.data
84-
} else {
85-
logger.error(
86-
{ error: parseResult.error, orgId, configObject: parsedConfigObject }, // Log the object that failed parsing
87-
'Invalid custom file picker configuration, using defaults',
88-
)
89-
}
90-
} else if (orgFeature?.config) {
91-
// If config is not a string but exists, it might be an object already (e.g. from a direct mock)
92-
// or an unexpected type. Let's try to parse it directly, assuming it might be an object.
93-
const parseResult = CustomFilePickerConfigSchema.safeParse(
94-
orgFeature.config,
95-
)
96-
if (parseResult.success) {
97-
logger.info(
98-
{ orgId, modelName: parseResult.data.modelName },
99-
'Using custom file picker configuration for organization (pre-parsed config object)',
100-
)
101-
return parseResult.data
102-
} else {
103-
logger.error(
104-
{ error: parseResult.error, orgId, configValue: orgFeature.config },
105-
'Invalid custom file picker configuration (non-string config value), using defaults',
106-
)
107-
}
108-
}
109-
} catch (error) {
110-
logger.error(
111-
{ error, orgId },
112-
'Error fetching custom file picker configuration',
113-
)
114-
}
115-
return null
116-
}
117-
118-
function isValidFilePickerModelName(
119-
modelName: string,
120-
): modelName is keyof typeof finetunedVertexModels {
121-
return Object.keys(finetunedVertexModels).includes(modelName)
122-
}
123-
12432
export async function requestRelevantFiles(
12533
params: {
12634
messages: Message[]
@@ -140,23 +48,10 @@ export async function requestRelevantFiles(
14048
>,
14149
) {
14250
const { messages, fileContext, assistantPrompt, logger } = params
143-
// Check for organization custom file picker feature
144-
const requestContext = getRequestContext()
145-
const orgId = requestContext?.approvedOrgIdForRepo
146-
const customFilePickerConfig = null satisfies Awaited<
147-
ReturnType<typeof getCustomFilePickerConfigForOrg>
148-
> as Awaited<ReturnType<typeof getCustomFilePickerConfigForOrg>>
149-
// const customFilePickerConfig = await getCustomFilePickerConfigForOrg({
150-
// orgId,
151-
// isRepoApprovedForUserInOrg: requestContext?.isRepoApprovedForUserInOrg,
152-
// logger,
153-
// })
15451

15552
const countPerRequest = 12
15653

15754
// Use custom max files per request if specified, otherwise default to 30
158-
const maxFilesPerRequest =
159-
customFilePickerConfig?.maxFilesPerRequest ?? MAX_FILES_PER_REQUEST
16055

16156
const lastMessage = messages[messages.length - 1]
16257
const messagesExcludingLastIfByUser =
@@ -177,17 +72,6 @@ export async function requestRelevantFiles(
17772
)
17873

17974
let modelIdForRequest: FinetunedVertexModel | undefined = undefined
180-
const modelName = customFilePickerConfig?.modelName
181-
if (modelName) {
182-
if (isValidFilePickerModelName(modelName)) {
183-
modelIdForRequest = finetunedVertexModels[modelName]
184-
} else {
185-
logger.warn(
186-
{ modelName: customFilePickerConfig.modelName },
187-
'Custom file picker modelName not found in finetunedVertexModel, using default',
188-
)
189-
}
190-
}
19175

19276
const keyPromise = getRelevantFiles({
19377
...params,
@@ -214,7 +98,7 @@ export async function requestRelevantFiles(
21498
// 'requestRelevantFiles: results',
21599
// )
216100

217-
return candidateFiles.slice(0, maxFilesPerRequest)
101+
return candidateFiles.slice(0, MAX_FILES_PER_REQUEST)
218102
}
219103

220104
export async function requestRelevantFilesForTraining(

0 commit comments

Comments
 (0)