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

Class DaemonHttpClient

apps/kimi-web/src/api/daemon/http.ts:91–399  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

89}
90
91export class DaemonHttpClient {
92 constructor(
93 private readonly origin: string,
94 private readonly identity?: DaemonHttpClientIdentity,
95 ) {}
96
97 async get<T>(path: string, query?: Record<string, string | number | boolean | undefined>): Promise<T> {
98 return this.request<T>('GET', path, undefined, query);
99 }
100
101 /** Authenticated raw-binary GET (no envelope). Used for file downloads that
102 * must carry the Bearer token — e.g. <video>/<img> src, which the browser
103 * fetches natively and cannot authorize on its own. Returns the body as a
104 * Blob on 2xx; otherwise parses the daemon envelope and throws. */
105 async getBlob(path: string): Promise<Blob> {
106 const url = buildRestUrl(this.origin, path);
107 const requestId = createRequestId();
108 const headers: Record<string, string> = { 'X-Request-Id': requestId };
109 this.addClientHeaders(headers);
110 const startedAt = Date.now();
111 traceRestRequest({ method: 'GET', path, url, requestId });
112 let response: Response;
113 try {
114 response = await fetch(url, { method: 'GET', headers, signal: timeoutSignal() });
115 } catch (err) {
116 traceRestFailure({
117 method: 'GET',
118 path,
119 requestId,
120 phase: 'fetch',
121 durationMs: Date.now() - startedAt,
122 error: err,
123 });
124 throw new DaemonNetworkError({
125 message: `Network error calling GET ${path}`,
126 cause: err,
127 method: 'GET',
128 path,
129 url,
130 requestId,
131 phase: 'fetch',
132 timeoutMs: REQUEST_TIMEOUT_MS,
133 timestamp: Date.now(),
134 durationMs: Date.now() - startedAt,
135 });
136 }
137 if (response.ok) {
138 traceRestResponse({
139 method: 'GET',
140 path,
141 requestId,
142 status: response.status,
143 durationMs: Date.now() - startedAt,
144 code: 0,
145 msg: '',
146 });
147 return response.blob();
148 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected