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

Method request

packages/server-e2e/src/http.ts:65–137  ·  view source on GitHub ↗
(
    method: string,
    path: string,
    body: unknown,
  )

Source from the content-addressed store, hash-verified

63 }
64
65 private async request<T>(
66 method: string,
67 path: string,
68 body: unknown,
69 ): Promise<T> {
70 const startedAt = Date.now();
71 const headers: Record<string, string> = { accept: 'application/json' };
72 let init: RequestInit;
73 if (body !== undefined) {
74 headers['content-type'] = 'application/json';
75 init = { method, headers, body: JSON.stringify(body) };
76 } else {
77 init = { method, headers };
78 }
79 const url = this.url(path);
80 let res: Response;
81 let text = '';
82 try {
83 res = await this.opts.fetchImpl(url, init);
84 text = await res.text();
85 } catch (error) {
86 recordReportEvent(
87 {
88 kind: 'http',
89 method,
90 path,
91 url,
92 durationMs: Date.now() - startedAt,
93 request: requestForReport(body),
94 error: errorForReport(error),
95 },
96 { reportDir: this.opts.reportDir },
97 );
98 throw error;
99 }
100 let envelope: Envelope<T>;
101 try {
102 envelope = JSON.parse(text) as Envelope<T>;
103 } catch (error) {
104 recordReportEvent(
105 {
106 kind: 'http',
107 method,
108 path,
109 url,
110 status: res.status,
111 durationMs: Date.now() - startedAt,
112 request: requestForReport(body),
113 response: { raw: text.slice(0, 2_000) },
114 error: errorForReport(error),
115 },
116 { reportDir: this.opts.reportDir },
117 );
118 throw new Error(
119 `server ${method} ${path} returned non-JSON (HTTP ${res.status}): ${text.slice(0, 200)}`,
120 { cause: error },
121 );
122 }

Callers 15

getAuthMethod · 0.95
listModelsMethod · 0.95
setDefaultModelMethod · 0.95
listProvidersMethod · 0.95
getProviderMethod · 0.95
createSessionMethod · 0.95
getSessionMethod · 0.95
listSessionsMethod · 0.95
updateSessionMethod · 0.95
forkSessionMethod · 0.95
compactSessionMethod · 0.95
undoSessionMethod · 0.95

Calls 7

urlMethod · 0.95
recordReportEventFunction · 0.85
requestForReportFunction · 0.85
unwrapFunction · 0.85
errorForReportFunction · 0.70
nowMethod · 0.65
textMethod · 0.65

Tested by

no test coverage detected