MCPcopy Create free account
hub / github.com/TraderAlice/OpenAlice / fetchAliceWebRequest

Function fetchAliceWebRequest

apps/desktop/src/ipc.ts:289–314  ·  view source on GitHub ↗
(request: Request, child: ChildProcess | null, timeoutMs = 30_000)

Source from the content-addressed store, hash-verified

287}
288
289export async function fetchAliceWebRequest(request: Request, child: ChildProcess | null, timeoutMs = 30_000): Promise<Response> {
290 if (!child || !child.connected) {
291 return new Response('Alice IPC unavailable', { status: 503 })
292 }
293 const id = randomId()
294 const method = request.method.toUpperCase()
295 const body = method === 'GET' || method === 'HEAD'
296 ? undefined
297 : Buffer.from(await request.arrayBuffer())
298
299 return new Promise<Response>((resolvePromise, rejectPromise) => {
300 const timer = setTimeout(() => {
301 pendingWebRequests.delete(id)
302 rejectPromise(new Error(`Alice IPC request timed out: ${method} ${request.url}`))
303 }, timeoutMs)
304 pendingWebRequests.set(id, { resolve: resolvePromise, reject: rejectPromise, timer })
305 child.send({
306 type: MSG_WEB_REQUEST,
307 id,
308 method,
309 url: request.url,
310 headers: [...request.headers.entries()],
311 ...(body ? { body } : {}),
312 })
313 })
314}
315
316export function handleOpenAliceIpcMessage(raw: unknown): boolean {
317 const msg = raw && typeof raw === 'object' ? raw as Record<string, unknown> : null

Callers 2

waitForAliceReadyFunction · 0.85
main.tsFile · 0.85

Calls 5

fromMethod · 0.80
randomIdFunction · 0.70
deleteMethod · 0.65
setMethod · 0.65
sendMethod · 0.65

Tested by

no test coverage detected