MCPcopy Index your code
hub / github.com/simstudioai/sim / forwardToCopilot

Function forwardToCopilot

apps/sim/app/api/copilot/byok/route.ts:45–73  ·  view source on GitHub ↗
(
  method: 'GET' | 'POST' | 'DELETE',
  query: URLSearchParams,
  body?: string
)

Source from the content-addressed store, hash-verified

43}
44
45async function forwardToCopilot(
46 method: 'GET' | 'POST' | 'DELETE',
47 query: URLSearchParams,
48 body?: string
49) {
50 const headers: Record<string, string> = { ...getMothershipSourceEnvHeaders() }
51 if (env.COPILOT_API_KEY) headers['x-api-key'] = env.COPILOT_API_KEY
52 if (body !== undefined) headers['Content-Type'] = 'application/json'
53
54 const qs = query.toString()
55 const targetUrl = `${SIM_AGENT_API_URL}/api/admin/byok${qs ? `?${qs}` : ''}`
56
57 try {
58 const upstream = await fetch(targetUrl, {
59 method,
60 headers,
61 ...(body !== undefined ? { body } : {}),
62 })
63 const text = await upstream.text()
64 // boundary-raw-fetch: copilot returns JSON; tolerate an empty body.
65 const data = text ? JSON.parse(text) : {}
66 return NextResponse.json(data, { status: upstream.status })
67 } catch (error) {
68 return NextResponse.json(
69 { error: `Failed to reach copilot: ${getErrorMessage(error, 'Unknown error')}` },
70 { status: 502 }
71 )
72 }
73}
74
75export const GET = withRouteHandler(async (req: NextRequest) => {
76 const userId = await getAuthorizedSuperUserId()

Callers 1

route.tsFile · 0.85

Calls 5

getErrorMessageFunction · 0.90
textMethod · 0.80
parseMethod · 0.80
toStringMethod · 0.45

Tested by

no test coverage detected