MCPcopy Create free account
hub / github.com/SecureAI-Tools/SecureAI-Tools / makeRequestStreaming

Function makeRequestStreaming

apps/web/lib/fe/api.ts:90–121  ·  view source on GitHub ↗
({
  method,
  input,
  req,
  init,
  onGeneratedChunk,
  onFinish,
}: {
  method: HttpMethod;
  input: RequestInfo;
  req: REQ | null;
  init?: RequestInit;
  onGeneratedChunk?: (chunk: string, generatedContent: string) => void;
  onFinish?: (generatedContent: string) => void;
})

Source from the content-addressed store, hash-verified

88}
89
90async function makeRequestStreaming<REQ>({
91 method,
92 input,
93 req,
94 init,
95 onGeneratedChunk,
96 onFinish,
97}: {
98 method: HttpMethod;
99 input: RequestInfo;
100 req: REQ | null;
101 init?: RequestInit;
102 onGeneratedChunk?: (chunk: string, generatedContent: string) => void;
103 onFinish?: (generatedContent: string) => void;
104}): Promise<void> {
105 const res = await fetchHelper(method, input, req, init);
106 if (!res || !res.body) {
107 throw new Error(`received null response! ${res}, ${res.body}`);
108 }
109
110 const reader = res.body.pipeThrough(new TextDecoderStream()).getReader();
111 let generatedContent = "";
112 while (true) {
113 const { value: chunk, done } = await reader.read();
114 if (done) {
115 break;
116 }
117 generatedContent += chunk;
118 onGeneratedChunk?.(chunk, generatedContent);
119 }
120 onFinish?.(generatedContent);
121}
122
123async function fetchHelper<REQ>(
124 method: HttpMethod,

Callers

nothing calls this directly

Calls 2

fetchHelperFunction · 0.85
readMethod · 0.80

Tested by

no test coverage detected