MCPcopy Index your code
hub / github.com/anomalyco/opencode / prepareRequest

Function prepareRequest

packages/opencode/src/plugin/snowflake-cortex.ts:369–398  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

367 }
368
369 const prepareRequest = () => {
370 const headers = new Headers(requestInput instanceof Request ? requestInput.headers : undefined)
371 if (init?.headers) {
372 const entries =
373 init.headers instanceof Headers
374 ? init.headers.entries()
375 : Array.isArray(init.headers)
376 ? init.headers
377 : Object.entries(init.headers as Record<string, string | undefined>)
378 for (const [key, value] of entries) {
379 if (value !== undefined) headers.set(key, String(value))
380 }
381 }
382 headers.set("authorization", `Bearer ${currentOauth.access}`)
383 headers.set("User-Agent", `opencode/${InstallationVersion}`)
384
385 let body = init?.body
386 if (body && typeof body === "string") {
387 try {
388 const parsed = JSON.parse(body)
389 if ("max_tokens" in parsed) {
390 parsed.max_completion_tokens = parsed.max_tokens
391 delete parsed.max_tokens
392 body = JSON.stringify(parsed)
393 }
394 } catch {}
395 }
396
397 return { ...init, headers, body }
398 }
399
400 const transformResponse = async (response: Response) => {
401 if (!response.ok && response.status === 400) {

Callers 1

fetchFunction · 0.85

Calls 1

setMethod · 0.45

Tested by

no test coverage detected