MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / request

Method request

apps/kimi-web/src/api/daemon/http.ts:265–377  ·  view source on GitHub ↗
(
    method: string,
    path: string,
    body?: unknown,
    query?: Record<string, string | number | boolean | undefined>,
    allowCodes: number[] = [],
  )

Source from the content-addressed store, hash-verified

263 }
264
265 private async request<T>(
266 method: string,
267 path: string,
268 body?: unknown,
269 query?: Record<string, string | number | boolean | undefined>,
270 allowCodes: number[] = [],
271 ): Promise<T> {
272 // Build URL, appending query string (omit undefined values)
273 let url = buildRestUrl(this.origin, path);
274 if (query) {
275 const params = new URLSearchParams();
276 for (const [key, value] of Object.entries(query)) {
277 if (value !== undefined) {
278 params.set(key, String(value));
279 }
280 }
281 const qs = params.toString();
282 if (qs) url = `${url}?${qs}`;
283 }
284
285 // Build headers
286 const requestId = createRequestId();
287 const headers: Record<string, string> = {
288 'X-Request-Id': requestId,
289 };
290 this.addClientHeaders(headers);
291 if (body !== undefined) {
292 headers['Content-Type'] = 'application/json; charset=utf-8';
293 }
294
295 const startedAt = Date.now();
296 traceRestRequest({ method, path, url, requestId, body });
297
298 // Execute fetch
299 let response: Response;
300 try {
301 response = await fetch(url, {
302 method,
303 headers,
304 body: body !== undefined ? JSON.stringify(body) : undefined,
305 signal: timeoutSignal(),
306 });
307 } catch (err) {
308 traceRestFailure({ method, path, requestId, phase: 'fetch', durationMs: Date.now() - startedAt, error: err });
309 throw new DaemonNetworkError({
310 message: `Network error calling ${method} ${path}`,
311 cause: err,
312 method,
313 path,
314 url,
315 requestId,
316 phase: 'fetch',
317 timeoutMs: REQUEST_TIMEOUT_MS,
318 timestamp: Date.now(),
319 durationMs: Date.now() - startedAt,
320 });
321 }
322

Callers 4

getMethod · 0.95
postMethod · 0.95
patchMethod · 0.95
deleteMethod · 0.95

Calls 14

addClientHeadersMethod · 0.95
checkAuthRequiredMethod · 0.95
buildRestUrlFunction · 0.90
traceRestRequestFunction · 0.90
traceRestFailureFunction · 0.90
traceRestResponseFunction · 0.90
createRequestIdFunction · 0.85
timeoutSignalFunction · 0.85
readResponsePreviewFunction · 0.85
jsonMethod · 0.80
setMethod · 0.65
toStringMethod · 0.65

Tested by

no test coverage detected