@visulima/error
Version:
Error with more than just a message, stacktrace parsing.
35 lines (30 loc) • 1.5 kB
JavaScript
const between = (start, end, text) => {
const startPosition = text.indexOf(start);
if (startPosition === -1) {
return "";
}
const adjustedStartPosition = startPosition + start.length;
const endPosition = text.indexOf(end, adjustedStartPosition);
if (endPosition === -1) {
return "";
}
return text.slice(adjustedStartPosition, endPosition).trim();
};
const aiSolutionResponse = (rawText) => {
const description = between("FIX", "ENDFIX", rawText);
if (!description) {
return [
"No solution found.",
// eslint-disable-next-line no-secrets/no-secrets
`Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">/error</a>.`,
`"${rawText}"`
].join("</br></br>");
}
const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
## Links
${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
--------------------
This solution was generated with the <a href="https://sdk.vercel.ai/" target="_blank" rel="noopener noreferrer">AI SDK</a> and may not be 100% accurate.`;
};
export { aiSolutionResponse as default };