Skip to content

Commit 2b5651f

Browse files
committed
Switch agent validation to a web route
1 parent 4852954 commit 2b5651f

File tree

6 files changed

+129
-353
lines changed

6 files changed

+129
-353
lines changed

backend/src/templates/dynamic-agents.knowledge.md

Lines changed: 0 additions & 312 deletions
This file was deleted.

backend/src/websockets/websocket-action.ts

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@ import {
77
import { AnalyticsEvent } from '@codebuff/common/constants/analytics-events'
88
import db from '@codebuff/common/db/index'
99
import * as schema from '@codebuff/common/db/schema'
10-
import { formatValidationErrorMessage } from '@codebuff/common/util/agent-template-validation'
1110
import { buildArray } from '@codebuff/common/util/array'
1211
import { ensureEndsWithNewline } from '@codebuff/common/util/file'
1312
import { generateCompactId } from '@codebuff/common/util/string'
@@ -296,25 +295,6 @@ const onInit = async (
296295
return
297296
}
298297

299-
// Assemble local agent templates from fileContext
300-
const { agentTemplates, validationErrors } =
301-
assembleLocalAgentTemplates(fileContext)
302-
303-
if (validationErrors.length > 0) {
304-
logger.warn(
305-
{ errorCount: validationErrors.length },
306-
'Agent template validation errors found',
307-
)
308-
}
309-
310-
const errorMessage = formatValidationErrorMessage(validationErrors)
311-
312-
// Get all agent names for frontend
313-
const allAgentNames: Record<string, string> = {}
314-
for (const [id, template] of Object.entries(agentTemplates)) {
315-
allAgentNames[id] = template.displayName
316-
}
317-
318298
// Send combined init and usage response
319299
const usageResponse = await genUsageResponse(
320300
fingerprintId,
@@ -324,10 +304,6 @@ const onInit = async (
324304
sendAction(ws, {
325305
...usageResponse,
326306
type: 'init-response',
327-
message: errorMessage
328-
? `**Agent Template Validation Errors:**\n${errorMessage}`
329-
: undefined,
330-
agentNames: allAgentNames,
331307
})
332308
})
333309
}

npm-app/src/client.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ import {
8181
storeSubagentChunk,
8282
} from './subagent-storage'
8383
import { handleToolCall } from './tool-handlers'
84+
import { validateAgentConfigsIfAuthenticated } from './utils/agent-validation'
8485
import { identifyUser, trackEvent } from './utils/analytics'
8586
import { getRepoMetrics, gitCommandIsAvailable } from './utils/git'
8687
import { logger, loggerContext } from './utils/logger'
@@ -1546,6 +1547,11 @@ Go to https://www.codebuff.com/config for more information.`) +
15461547
throw new Error('Failed to initialize project file context')
15471548
}
15481549

1550+
await validateAgentConfigsIfAuthenticated(
1551+
this.user,
1552+
fileContext.agentTemplates,
1553+
)
1554+
15491555
this.webSocket.subscribe('init-response', (a) => {
15501556
const parsedAction = InitResponseSchema.safeParse(a)
15511557
if (!parsedAction.success) {

0 commit comments

Comments
 (0)