MCPcopy Index your code
hub / github.com/CodebuffAI/codebuff / fetchAgentFromDatabase

Function fetchAgentFromDatabase

sdk/src/impl/database.ts:215–300  ·  view source on GitHub ↗
(
  params: ParamsOf<FetchAgentFromDatabaseFn>,
)

Source from the content-addressed store, hash-verified

213}
214
215export async function fetchAgentFromDatabase(
216 params: ParamsOf<FetchAgentFromDatabaseFn>,
217): ReturnType<FetchAgentFromDatabaseFn> {
218 const { apiKey, parsedAgentId, logger } = params
219 const { publisherId, agentId, version } = parsedAgentId
220
221 const url = new URL(
222 `/api/v1/agents/${publisherId}/${agentId}/${version ? version : 'latest'}`,
223 WEBSITE_URL,
224 )
225
226 try {
227 const response = await fetchWithRetry(
228 url,
229 {
230 method: 'GET',
231 headers: {
232 Authorization: `Bearer ${apiKey}`,
233 },
234 },
235 logger,
236 )
237
238 if (!response.ok) {
239 logger.error({ response }, 'fetchAgentFromDatabase request failed')
240 return null
241 }
242
243 const responseJson = await response.json()
244 const parseResult = agentsResponseSchema.safeParse(responseJson)
245 if (!parseResult.success) {
246 logger.error(
247 { responseJson, parseResult },
248 `fetchAgentFromDatabase parse error`,
249 )
250 return null
251 }
252
253 const agentConfig = parseResult.data
254 const rawAgentData = agentConfig.data as DynamicAgentTemplate
255
256 // Validate the raw agent data with the original agentId (not full identifier)
257 const validationResult = validateSingleAgent({
258 template: { ...rawAgentData, id: agentId, version: agentConfig.version },
259 filePath: `${publisherId}/${agentId}@${agentConfig.version}`,
260 })
261
262 if (!validationResult.success) {
263 logger.error(
264 {
265 publisherId,
266 agentId,
267 version: agentConfig.version,
268 error: validationResult.error,
269 },
270 'fetchAgentFromDatabase: Agent validation failed',
271 )
272 return null

Callers 1

getAgentTemplateFunction · 0.85

Calls 3

validateSingleAgentFunction · 0.90
getErrorObjectFunction · 0.90
fetchWithRetryFunction · 0.85

Tested by

no test coverage detected