@@ -18,9 +18,6 @@ import type { ProjectFileContext } from '@codebuff/common/util/file'
1818
1919export type AgentRegistry = Record < string , AgentTemplate >
2020
21- // Global database cache - only state in the system
22- const databaseAgentCache = new Map < string , AgentTemplate | null > ( )
23-
2421/**
2522 * Fetch and validate an agent from the database by publisher/agent-id[@version] format
2623 */
@@ -132,10 +129,16 @@ export async function getAgentTemplate(params: {
132129 agentId : string
133130 localAgentTemplates : Record < string , AgentTemplate >
134131 fetchAgentFromDatabase : FetchAgentFromDatabaseFn
132+ databaseAgentCache : Map < string , AgentTemplate | null >
135133 logger : Logger
136134} ) : Promise < AgentTemplate | null > {
137- const { agentId, localAgentTemplates, fetchAgentFromDatabase, logger } =
138- params
135+ const {
136+ agentId,
137+ localAgentTemplates,
138+ fetchAgentFromDatabase,
139+ databaseAgentCache,
140+ logger,
141+ } = params
139142 // 1. Check localAgentTemplates first (dynamic agents + static templates)
140143 if ( localAgentTemplates [ agentId ] ) {
141144 return localAgentTemplates [ agentId ]
@@ -203,6 +206,10 @@ export function assembleLocalAgentTemplates(params: {
203206/**
204207 * Clear the database agent cache (useful for testing)
205208 */
206- export function clearDatabaseCache ( ) : void {
209+ export function clearDatabaseCache ( params : {
210+ databaseAgentCache : Map < string , AgentTemplate | null >
211+ } ) : void {
212+ const { databaseAgentCache } = params
213+
207214 databaseAgentCache . clear ( )
208215}
0 commit comments