MCPcopy Create free account
hub / github.com/OpenHands/OpenHands / request

Function request

scripts/mars-api.mjs:162–201  ·  view source on GitHub ↗
(
    method,
    path,
    { query, timeoutMs, body, signal } = {},
  )

Source from the content-addressed store, hash-verified

160 fetchImpl = globalThis.fetch,
161}) {
162 async function request(
163 method,
164 path,
165 { query, timeoutMs, body, signal } = {},
166 ) {
167 const token = await getToken();
168 if (!token) {
169 throw new MarsApiError("Not signed in to DigitalOcean.", { status: 401 });
170 }
171
172 const headers = { Authorization: `Bearer ${token}` };
173 if (deviceId) headers[DEVICE_ID_HEADER] = deviceId;
174 if (body !== undefined) headers["Content-Type"] = "application/json";
175
176 const timeout = AbortSignal.timeout(timeoutMs ?? DEFAULT_TIMEOUT_MS);
177 let response;
178 try {
179 response = await fetchImpl(buildMarsUrl(baseUrl, path, query), {
180 method,
181 headers,
182 body: body === undefined ? undefined : JSON.stringify(body),
183 signal: signal ? AbortSignal.any([signal, timeout]) : timeout,
184 });
185 } catch (error) {
186 throw new MarsApiError(
187 `Could not reach DigitalOcean: ${error instanceof Error ? error.message : String(error)}`,
188 { cause: error },
189 );
190 }
191
192 if (!response.ok) {
193 throw new MarsApiError(await readErrorMessage(response), {
194 status: response.status,
195 });
196 }
197
198 // 204 on pause/resume/delete — no body to parse.
199 if (response.status === 204) return null;
200 return response.json();
201 }
202
203 return {
204 /** `{sessions, next_page_token}`; results are always team-scoped. */

Callers 15

listSessionsFunction · 0.70
getSessionFunction · 0.70
listAgentConfigsFunction · 0.70
createAgentConfigFunction · 0.70
getAgentConfigFunction · 0.70
listConfigSessionsFunction · 0.70
listSandboxSizesFunction · 0.70
createSessionFromConfigFunction · 0.70
pauseSessionFunction · 0.70
resumeSessionFunction · 0.70
destroySessionFunction · 0.70
deleteAgentConfigFunction · 0.70

Calls 3

getTokenFunction · 0.85
buildMarsUrlFunction · 0.85
readErrorMessageFunction · 0.85

Tested by

no test coverage detected