@copilotkit/shared
Version:
<img src="https://github.com/user-attachments/assets/0a6b64d9-e193-4940-a3f6-60334ac34084" alt="banner" style="border-radius: 12px; border: 2px solid #d6d4fa;" />
91 lines (90 loc) • 2.65 kB
JavaScript
;
var __defProp = Object.defineProperty;
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
var __getOwnPropNames = Object.getOwnPropertyNames;
var __hasOwnProp = Object.prototype.hasOwnProperty;
var __export = (target, all) => {
for (var name in all)
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
// src/utils/requests.ts
var requests_exports = {};
__export(requests_exports, {
readBody: () => readBody
});
module.exports = __toCommonJS(requests_exports);
async function readBody(r) {
const method = "method" in r ? r.method.toUpperCase() : void 0;
if (method === "GET" || method === "HEAD") {
return void 0;
}
if (!("body" in r) || r.body == null) {
return void 0;
}
try {
return await r.clone().json();
} catch {
try {
const text = await r.clone().text();
const trimmed = text.trim();
if (trimmed.length === 0)
return text;
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
try {
return JSON.parse(trimmed);
} catch {
return text;
}
}
return text;
} catch {
try {
const c = r.clone();
const stream = c.body ?? null;
if (!stream)
return void 0;
const reader = stream.getReader();
const decoder = new TextDecoder();
let out = "";
while (true) {
const { done, value } = await reader.read();
if (done)
break;
if (typeof value === "string") {
out += value;
} else {
out += decoder.decode(value, { stream: true });
}
}
out += decoder.decode();
const trimmed = out.trim();
if (trimmed.length === 0)
return out;
if (trimmed.startsWith("{") || trimmed.startsWith("[")) {
try {
return JSON.parse(trimmed);
} catch {
return out;
}
}
return out;
} catch {
return void 0;
}
}
}
}
// Annotate the CommonJS export names for ESM import in node:
0 && (module.exports = {
readBody
});
//# sourceMappingURL=requests.js.map