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

Function request

cli/src/utils/codebuff-api.ts:296–445  ·  view source on GitHub ↗
(
    method: string,
    path: string,
    body?: unknown,
    options: RequestOptions = {},
  )

Source from the content-addressed store, hash-verified

294 }
295
296 async function request<T>(
297 method: string,
298 path: string,
299 body?: unknown,
300 options: RequestOptions = {},
301 ): Promise<ApiResponse<T>> {
302 const {
303 query,
304 includeAuth = true,
305 includeCookie = false,
306 timeoutMs = defaultTimeoutMs,
307 retry: retryConfig = mergedDefaultRetry,
308 headers: customHeaders = {},
309 } = options
310
311 // Build URL with query parameters
312 let url = `${baseUrl}${path}`
313 if (query && Object.keys(query).length > 0) {
314 const params = new URLSearchParams(query)
315 url += `?${params.toString()}`
316 }
317
318 // Build headers
319 const headers: Record<string, string> = { ...customHeaders }
320 if (authToken && includeAuth) {
321 headers['Authorization'] = `Bearer ${authToken}`
322 }
323 if (authToken && includeCookie) {
324 headers['Cookie'] = `next-auth.session-token=${authToken};`
325 }
326 if (body !== undefined) {
327 headers['Content-Type'] = 'application/json'
328 }
329
330 // Build fetch options
331 const fetchOptions: RequestInit = {
332 method,
333 headers,
334 }
335 if (body !== undefined) {
336 fetchOptions.body = JSON.stringify(body)
337 }
338
339 // Determine retry config
340 const shouldRetry = retryConfig !== false
341 const retryOpts = shouldRetry
342 ? { ...mergedDefaultRetry, ...retryConfig }
343 : null
344
345 let lastError: unknown
346 const maxAttempts = shouldRetry ? (retryOpts?.maxRetries ?? 0) + 1 : 1
347
348 for (let attempt = 0; attempt < maxAttempts; attempt++) {
349 // Create abort controller for timeout
350 const controller = new AbortController()
351 const timeoutId = setTimeout(() => controller.abort(), timeoutMs)
352
353 try {

Callers 12

getFunction · 0.70
postFunction · 0.70
putFunction · 0.70
patchFunction · 0.70
deleteFunction · 0.70
meFunction · 0.70
usageFunction · 0.70
loginCodeFunction · 0.70
loginStatusFunction · 0.70
publishFunction · 0.70
logoutFunction · 0.70
feedbackFunction · 0.70

Calls 5

setTimeoutFunction · 0.85
fetchFnFunction · 0.85
calculateBackoffDelayFunction · 0.85
isRetryableErrorFunction · 0.85
sleepFunction · 0.70

Tested by

no test coverage detected