const DEFAULT_MAX_CHARS = 4e4;
function truncateResult(value, maxChars = DEFAULT_MAX_CHARS) {
  if (value === void 0) return "undefined";
  let serialized;
  try {
    serialized = JSON.stringify(value, circularReplacer(), 2);
  } catch {
    serialized = String(value);
  }
  if (serialized.length <= maxChars) return serialized;
  return serialized.slice(0, maxChars) + "\n\n... (truncated \u2014 refine your code to return less data)";
}
function circularReplacer() {
  const seen = /* @__PURE__ */ new WeakSet();
  return (_key, value) => {
    if (typeof value === "object" && value !== null) {
      if (seen.has(value)) return "[Circular]";
      seen.add(value);
    }
    return value;
  };
}
export {
  truncateResult
};
//# sourceMappingURL=truncate.js.map
