MCPcopy Create free account
hub / github.com/TeleBoxOrg/TeleBox_Plugins / readResponseBodyAsText

Function readResponseBodyAsText

ai/ai.ts:1877–1897  ·  view source on GitHub ↗
(data: any)

Source from the content-addressed store, hash-verified

1875
1876const readResponseBodyAsText = async (data: any): Promise<string> => {
1877 if (typeof data === "string") return data;
1878 if (Buffer.isBuffer(data)) return data.toString("utf8");
1879 if (data instanceof Uint8Array) return Buffer.from(data).toString("utf8");
1880 if (!isAsyncIterable(data)) return "";
1881
1882 let body = "";
1883 for await (const chunk of data) {
1884 if (typeof chunk === "string") {
1885 body += chunk;
1886 } else if (Buffer.isBuffer(chunk)) {
1887 body += chunk.toString("utf8");
1888 } else if (chunk instanceof Uint8Array) {
1889 body += Buffer.from(chunk).toString("utf8");
1890 } else if (chunk !== undefined && chunk !== null) {
1891 body += String(chunk);
1892 }
1893 }
1894
1895 return body;
1896};
1897
1898const collectOpenAISources = (
1899 data: any,
1900): Array<{ url: string; title?: string }> => {

Callers 1

parseOpenAIResponseDataFunction · 0.85

Calls 1

isAsyncIterableFunction · 0.85

Tested by

no test coverage detected