Skip to content

armgit / pibot

Public Imported from GitHub
0

Open-source, local-first AI agent team for your desktop: multi-agent group chats, computer use, browser, MCP, routines and approvals. macOS, Windows, Linux + Android. Built on pi.

607 B
Raw Blame
import { readProviderError } from "../core/provider-response-error.ts";

/** Only the local chat failure hint receives the redacted first line. */
export function providerDetail(error: unknown, redact: (text: string) => string) {
  const raw = error instanceof Error ? error.message : error;
  if (typeof raw !== "string") return;
  const { message } = readProviderError(raw);
  if (!message) return;
  const line = redact(message)
    .split(/[\r\n\p{Zl}\p{Zp}]/u, 1)[0]
    ?.trim();
  if (!line) return;
  return line.length <= 300 ? line : `${line.slice(0, 299).replace(/[\uD800-\uDBFF]$/u, "")}…`;
}