@visulima/error 5.0.3 → 5.0.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (41) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/code-frame/index.js +125 -6
  3. package/dist/error/index.js +8 -1
  4. package/dist/index.js +16 -1
  5. package/dist/packem_shared/NonError-D5FGLYKY.js +8 -0
  6. package/dist/packem_shared/addKnownErrorConstructor-s_3SsXtQ.js +30 -0
  7. package/dist/packem_shared/aiFinder-HftEgsry.js +277 -0
  8. package/dist/packem_shared/aiSolutionResponse-CJBMLS9t.js +34 -0
  9. package/dist/packem_shared/captureRawStackTrace-ySw7cU0U.js +10 -0
  10. package/dist/packem_shared/deserializeError-E0VQnnm0.js +116 -0
  11. package/dist/packem_shared/errorHintFinder-DEaeRnRW.js +21 -0
  12. package/dist/packem_shared/formatStackFrameLine-D3_6oSWZ.js +24 -0
  13. package/dist/packem_shared/getErrorCauses-DpUsmuqw.js +43 -0
  14. package/dist/packem_shared/index-y_UPkY2Z.js +9 -0
  15. package/dist/packem_shared/indexToLineColumn-Bg8UW1bU.js +50 -0
  16. package/dist/packem_shared/isVisulimaError-DA7QsCxH.js +34 -0
  17. package/dist/packem_shared/parseStacktrace-oQvk7wYp.js +273 -0
  18. package/dist/packem_shared/renderError-C30PRFtU.js +206 -0
  19. package/dist/packem_shared/ruleBasedFinder-C2F8rQ30.js +207 -0
  20. package/dist/packem_shared/serializeError-BZ62KiYZ.js +142 -0
  21. package/dist/solution/ai/ai-prompt.js +13 -7
  22. package/dist/solution/ai/index.js +3 -1
  23. package/dist/solution/index.js +2 -1
  24. package/dist/stacktrace/index.js +2 -1
  25. package/package.json +1 -1
  26. package/dist/packem_shared/NonError-CS10kwil.js +0 -1
  27. package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.js +0 -1
  28. package/dist/packem_shared/aiFinder-DPoqj12B.js +0 -1
  29. package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.js +0 -10
  30. package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.js +0 -1
  31. package/dist/packem_shared/deserializeError-BJM8Kd6G.js +0 -1
  32. package/dist/packem_shared/errorHintFinder-C_g0nvml.js +0 -2
  33. package/dist/packem_shared/formatStackFrameLine-iU54KA81.js +0 -2
  34. package/dist/packem_shared/getErrorCauses-geeK5cwE.js +0 -1
  35. package/dist/packem_shared/index-CLFYRLyq.js +0 -1
  36. package/dist/packem_shared/indexToLineColumn-B1F7aNZh.js +0 -1
  37. package/dist/packem_shared/isVisulimaError-jVZgumOU.js +0 -1
  38. package/dist/packem_shared/parseStacktrace-Dnxnc4PL.js +0 -2
  39. package/dist/packem_shared/renderError-ZMlMvw1N.js +0 -18
  40. package/dist/packem_shared/ruleBasedFinder-P88d0gpK.js +0 -34
  41. package/dist/packem_shared/serializeError-CTpDr3CL.js +0 -1
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## @visulima/error [5.0.4](https://github.com/visulima/visulima/compare/@visulima/error@5.0.3...@visulima/error@5.0.4) (2025-11-07)
2
+
3
+ ### Bug Fixes
4
+
5
+ * update TypeScript configurations and improve linting across multiple packages ([6f25ec7](https://github.com/visulima/visulima/commit/6f25ec7841da7246f8f9166efc5292a7089d37ee))
6
+
7
+ ### Miscellaneous Chores
8
+
9
+ * update npm and pnpm configurations for monorepo optimization ([#564](https://github.com/visulima/visulima/issues/564)) ([5512b42](https://github.com/visulima/visulima/commit/5512b42f672c216b6a3c9e39035199a4ebd9a4b8))
10
+
11
+
12
+ ### Dependencies
13
+
14
+ * **@visulima/path:** upgraded to 2.0.3
15
+
1
16
  ## @visulima/error [5.0.3](https://github.com/visulima/visulima/compare/@visulima/error@5.0.2...@visulima/error@5.0.3) (2025-11-05)
2
17
 
3
18
  ### Bug Fixes
@@ -1,6 +1,125 @@
1
- var M=Object.defineProperty;var v=(t,e)=>M(t,"name",{value:e,configurable:!0});var F=Object.defineProperty,P=v((t,e)=>F(t,"name",{value:e,configurable:!0}),"r$1");const E=P(t=>t.replaceAll(/\r\n|\r(?!\n)|\n/gu,`
2
- `),"normalizeLF"),S=globalThis.process||Object.create(null),y={versions:{}},k=new Proxy(S,{get(t,e){if(e in t)return t[e];if(e in y)return y[e]}});var W=Object.defineProperty,T=v((t,e)=>W(t,"name",{value:e,configurable:!0}),"b");const _=T((t,e,h,n)=>{const f={column:0,line:-1,...t.start},i={...f,...t.end},o=f.line,l=f.column,u=i.line,m=i.column;let g=Math.max(o-(h+1),0),p=Math.min(e.length,u+n);o===-1&&(g=0),u===-1&&(p=e.length);const b=u-o,a={};if(b)for(let r=0;r<=b;r++){const s=r+o;if(!l)a[s]=!0;else if(r===0){const c=e[s-1]?.length;a[s]=[l,(c??0)-l+1]}else if(r===b)a[s]=[0,m];else{const c=e[s-r]?.length;a[s]=[0,c]}}else l===m?a[o]=l?[l,0]:!0:a[o]=[l,(m??0)-(l??0)];return{end:p,markerLines:a,start:g}},"getMarkerLines");var B=Object.defineProperty,$=v((t,e)=>B(t,"name",{value:e,configurable:!0}),"o");const C=k.platform==="win32"&&!k.env?.WT_SESSION?">":"❯",I=$((t,e,h)=>{const n={linesAbove:2,linesBelow:3,prefix:"",showGutter:!0,tabWidth:4,...h,color:{gutter:$(r=>r,"gutter"),marker:$(r=>r,"marker"),message:$(r=>r,"message"),...h?.color}},f=e.start&&typeof e.start.column=="number";let i=E(t).split(`
3
- `);typeof n?.tabWidth=="number"&&(i=i.map(r=>r.replaceAll(" "," ".repeat(n.tabWidth))));const{end:o,markerLines:l,start:u}=_(e,i,n.linesAbove,n.linesBelow),m=String(o).length,{gutter:g,marker:p,message:b}=n.color;let a=i.slice(u,o).map((r,s)=>{const c=u+1+s,d=l[c],j=` ${c}`.slice(-m),O=!l[c+1],x=` ${j}${n.showGutter?" |":""}`;if(d){let A="";if(Array.isArray(d)){const w=r.replaceAll(/[^\t]/g," ").slice(0,Math.max(d[0]-1,0)),L=d[1]||1;A=[`
4
- `,n.prefix+g(x.replaceAll(/\d/g," "))," ",w,p("^").repeat(L)].join(""),O&&n.message&&(A+=` ${b(n.message)}`)}return[n.prefix+p(C),g(x),r.length>0?` ${r}`:"",A].join("")}return`${n.prefix} ${g(x)}${r.length>0?` ${r}`:""}`}).join(`
5
- `);return n.message&&!f&&(a=`${n.prefix+" ".repeat(m+1)+n.message}
6
- ${a}`),a},"codeFrame");export{C as CODE_FRAME_POINTER,I as codeFrame};
1
+ const normalizeLF = (code) => code.replaceAll(/\r\n|\r(?!\n)|\n/gu, "\n");
2
+
3
+ const _process = globalThis.process || /* @__PURE__ */ Object.create(null);
4
+ const processShims = {
5
+ versions: {}
6
+ };
7
+ const process = new Proxy(_process, {
8
+ get(target, property) {
9
+ if (property in target) {
10
+ return target[property];
11
+ }
12
+ if (property in processShims) {
13
+ return processShims[property];
14
+ }
15
+ return void 0;
16
+ }
17
+ });
18
+
19
+ const getMarkerLines = (loc, source, linesAbove, linesBelow) => {
20
+ const startLoc = {
21
+ column: 0,
22
+ // @ts-expect-error Can be overwritten
23
+ line: -1,
24
+ ...loc.start
25
+ };
26
+ const endLoc = {
27
+ ...startLoc,
28
+ ...loc.end
29
+ };
30
+ const startLine = startLoc.line;
31
+ const startColumn = startLoc.column;
32
+ const endLine = endLoc.line;
33
+ const endColumn = endLoc.column;
34
+ let start = Math.max(startLine - (linesAbove + 1), 0);
35
+ let end = Math.min(source.length, endLine + linesBelow);
36
+ if (startLine === -1) {
37
+ start = 0;
38
+ }
39
+ if (endLine === -1) {
40
+ end = source.length;
41
+ }
42
+ const lineDiff = endLine - startLine;
43
+ const markerLines = {};
44
+ if (lineDiff) {
45
+ for (let index = 0; index <= lineDiff; index++) {
46
+ const lineNumber = index + startLine;
47
+ if (!startColumn) {
48
+ markerLines[lineNumber] = true;
49
+ } else if (index === 0) {
50
+ const sourceLength = source[lineNumber - 1]?.length;
51
+ markerLines[lineNumber] = [startColumn, (sourceLength ?? 0) - startColumn + 1];
52
+ } else if (index === lineDiff) {
53
+ markerLines[lineNumber] = [0, endColumn];
54
+ } else {
55
+ const sourceLength = source[lineNumber - index]?.length;
56
+ markerLines[lineNumber] = [0, sourceLength];
57
+ }
58
+ }
59
+ } else if (startColumn === endColumn) {
60
+ markerLines[startLine] = startColumn ? [startColumn, 0] : true;
61
+ } else {
62
+ markerLines[startLine] = [startColumn, (endColumn ?? 0) - (startColumn ?? 0)];
63
+ }
64
+ return { end, markerLines, start };
65
+ };
66
+
67
+ const CODE_FRAME_POINTER = process.platform === "win32" && !process.env?.WT_SESSION ? ">" : "❯";
68
+ const codeFrame = (source, loc, options) => {
69
+ const config = {
70
+ // grab 2 lines before, and 3 lines after focused line
71
+ linesAbove: 2,
72
+ linesBelow: 3,
73
+ prefix: "",
74
+ showGutter: true,
75
+ tabWidth: 4,
76
+ ...options,
77
+ color: {
78
+ gutter: (value) => value,
79
+ marker: (value) => value,
80
+ message: (value) => value,
81
+ ...options?.color
82
+ }
83
+ };
84
+ const hasColumns = loc.start && typeof loc.start.column === "number";
85
+ let lines = normalizeLF(source).split("\n");
86
+ if (typeof config?.tabWidth === "number") {
87
+ lines = lines.map((ln) => ln.replaceAll(" ", " ".repeat(config.tabWidth)));
88
+ }
89
+ const { end, markerLines, start } = getMarkerLines(loc, lines, config.linesAbove, config.linesBelow);
90
+ const numberMaxWidth = String(end).length;
91
+ const { gutter: colorizeGutter, marker: colorizeMarker, message: colorizeMessage } = config.color;
92
+ let frame = lines.slice(start, end).map((line, index) => {
93
+ const number = start + 1 + index;
94
+ const hasMarker = markerLines[number];
95
+ const paddedNumber = ` ${number}`.slice(-numberMaxWidth);
96
+ const lastMarkerLine = !markerLines[number + 1];
97
+ const gutter = ` ${paddedNumber}${config.showGutter ? " |" : ""}`;
98
+ if (hasMarker) {
99
+ let markerLine = "";
100
+ if (Array.isArray(hasMarker)) {
101
+ const markerSpacing = line.replaceAll(/[^\t]/g, " ").slice(0, Math.max(hasMarker[0] - 1, 0));
102
+ const numberOfMarkers = hasMarker[1] || 1;
103
+ markerLine = [
104
+ "\n ",
105
+ config.prefix + colorizeGutter(gutter.replaceAll(/\d/g, " ")),
106
+ " ",
107
+ markerSpacing,
108
+ colorizeMarker("^").repeat(numberOfMarkers)
109
+ ].join("");
110
+ if (lastMarkerLine && config.message) {
111
+ markerLine += ` ${colorizeMessage(config.message)}`;
112
+ }
113
+ }
114
+ return [config.prefix + colorizeMarker(CODE_FRAME_POINTER), colorizeGutter(gutter), line.length > 0 ? ` ${line}` : "", markerLine].join("");
115
+ }
116
+ return `${config.prefix} ${colorizeGutter(gutter)}${line.length > 0 ? ` ${line}` : ""}`;
117
+ }).join("\n");
118
+ if (config.message && !hasColumns) {
119
+ frame = `${config.prefix + " ".repeat(numberMaxWidth + 1) + config.message}
120
+ ${frame}`;
121
+ }
122
+ return frame;
123
+ };
124
+
125
+ export { CODE_FRAME_POINTER, codeFrame };
@@ -1 +1,8 @@
1
- import{default as e}from"../packem_shared/captureRawStackTrace-CQPNHvBG.js";import{default as t}from"../packem_shared/getErrorCauses-geeK5cwE.js";import{renderError as i}from"../packem_shared/renderError-ZMlMvw1N.js";import{default as m}from"../packem_shared/deserializeError-BJM8Kd6G.js";import{addKnownErrorConstructor as p,isErrorLike as u}from"../packem_shared/addKnownErrorConstructor-BqqnTSZp.js";import{default as d}from"../packem_shared/NonError-CS10kwil.js";import{serialize as n}from"../packem_shared/serializeError-CTpDr3CL.js";import{VisulimaError as z,isVisulimaError as k}from"../packem_shared/isVisulimaError-jVZgumOU.js";export{d as NonError,z as VisulimaError,p as addKnownErrorConstructor,e as captureRawStackTrace,m as deserializeError,t as getErrorCauses,u as isErrorLike,k as isVisulimaError,i as renderError,n as serializeError};
1
+ export { default as captureRawStackTrace } from '../packem_shared/captureRawStackTrace-ySw7cU0U.js';
2
+ export { default as getErrorCauses } from '../packem_shared/getErrorCauses-DpUsmuqw.js';
3
+ export { renderError } from '../packem_shared/renderError-C30PRFtU.js';
4
+ export { default as deserializeError } from '../packem_shared/deserializeError-E0VQnnm0.js';
5
+ export { addKnownErrorConstructor, isErrorLike } from '../packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
6
+ export { default as NonError } from '../packem_shared/NonError-D5FGLYKY.js';
7
+ export { serialize as serializeError } from '../packem_shared/serializeError-BZ62KiYZ.js';
8
+ export { VisulimaError, isVisulimaError } from '../packem_shared/isVisulimaError-DA7QsCxH.js';
package/dist/index.js CHANGED
@@ -1 +1,16 @@
1
- import{CODE_FRAME_POINTER as o,codeFrame as a}from"./code-frame/index.js";import{default as f}from"./packem_shared/indexToLineColumn-B1F7aNZh.js";import{default as m}from"./solution/ai/ai-prompt.js";import{default as p}from"./packem_shared/aiSolutionResponse-RD0AK1jh.js";import{default as l}from"./packem_shared/errorHintFinder-C_g0nvml.js";import{default as x}from"./packem_shared/ruleBasedFinder-P88d0gpK.js";import{default as E}from"./packem_shared/captureRawStackTrace-CQPNHvBG.js";import{default as k}from"./packem_shared/deserializeError-BJM8Kd6G.js";import{default as S}from"./packem_shared/getErrorCauses-geeK5cwE.js";import{default as R}from"./packem_shared/NonError-CS10kwil.js";import{default as L}from"./packem_shared/parseStacktrace-Dnxnc4PL.js";import{addKnownErrorConstructor as w,isErrorLike as N}from"./packem_shared/addKnownErrorConstructor-BqqnTSZp.js";import{VisulimaError as P,isVisulimaError as V}from"./packem_shared/isVisulimaError-jVZgumOU.js";import{renderError as g}from"./packem_shared/renderError-ZMlMvw1N.js";import{serialize as B}from"./packem_shared/serializeError-CTpDr3CL.js";import{formatStackFrameLine as H,formatStacktrace as I}from"./packem_shared/formatStackFrameLine-iU54KA81.js";export{o as CODE_FRAME_POINTER,R as NonError,P as VisulimaError,w as addKnownErrorConstructor,m as aiPrompt,p as aiSolutionResponse,E as captureRawStackTrace,a as codeFrame,k as deserializeError,l as errorHintFinder,H as formatStackFrameLine,I as formatStacktrace,S as getErrorCauses,f as indexToLineColumn,N as isErrorLike,V as isVisulimaError,L as parseStacktrace,g as renderError,x as ruleBasedFinder,B as serializeError};
1
+ export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.js';
2
+ export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Bg8UW1bU.js';
3
+ export { default as aiPrompt } from './solution/ai/ai-prompt.js';
4
+ export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-CJBMLS9t.js';
5
+ export { default as errorHintFinder } from './packem_shared/errorHintFinder-DEaeRnRW.js';
6
+ export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-C2F8rQ30.js';
7
+ export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-ySw7cU0U.js';
8
+ export { default as deserializeError } from './packem_shared/deserializeError-E0VQnnm0.js';
9
+ export { default as getErrorCauses } from './packem_shared/getErrorCauses-DpUsmuqw.js';
10
+ export { default as NonError } from './packem_shared/NonError-D5FGLYKY.js';
11
+ export { default as parseStacktrace } from './packem_shared/parseStacktrace-oQvk7wYp.js';
12
+ export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-s_3SsXtQ.js';
13
+ export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-DA7QsCxH.js';
14
+ export { renderError } from './packem_shared/renderError-C30PRFtU.js';
15
+ export { serialize as serializeError } from './packem_shared/serializeError-BZ62KiYZ.js';
16
+ export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-D3_6oSWZ.js';
@@ -0,0 +1,8 @@
1
+ class NonError extends Error {
2
+ constructor(message) {
3
+ super(message);
4
+ this.name = "NonError";
5
+ }
6
+ }
7
+
8
+ export { NonError as default };
@@ -0,0 +1,30 @@
1
+ const defaultErrorConstructors = /* @__PURE__ */ new Map([
2
+ ["Error", Error],
3
+ ["EvalError", EvalError],
4
+ ["RangeError", RangeError],
5
+ ["ReferenceError", ReferenceError],
6
+ ["SyntaxError", SyntaxError],
7
+ ["TypeError", TypeError],
8
+ ["URIError", URIError]
9
+ ]);
10
+ if (typeof AggregateError !== "undefined") {
11
+ defaultErrorConstructors.set("AggregateError", AggregateError);
12
+ }
13
+ const addKnownErrorConstructor = (constructor, name) => {
14
+ let instance;
15
+ try {
16
+ instance = new constructor();
17
+ } catch (error) {
18
+ throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
19
+ }
20
+ const resolvedName = name ?? instance.name;
21
+ if (defaultErrorConstructors.has(resolvedName)) {
22
+ throw new Error(`The error constructor "${resolvedName}" is already known.`);
23
+ }
24
+ defaultErrorConstructors.set(resolvedName, constructor);
25
+ };
26
+ const getKnownErrorConstructors = () => new Map(defaultErrorConstructors);
27
+ const getErrorConstructor = (name) => defaultErrorConstructors.get(name);
28
+ const isErrorLike = (value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error");
29
+
30
+ export { addKnownErrorConstructor, getErrorConstructor, getKnownErrorConstructors, isErrorLike };
@@ -0,0 +1,277 @@
1
+ import { createRequire as __cjs_createRequire } from "node:module";
2
+
3
+ const __cjs_require = __cjs_createRequire(import.meta.url);
4
+
5
+ const __cjs_getProcess = typeof globalThis !== "undefined" && typeof globalThis.process !== "undefined" ? globalThis.process : process;
6
+
7
+ const __cjs_getBuiltinModule = (module) => {
8
+ // Check if we're in Node.js and version supports getBuiltinModule
9
+ if (typeof __cjs_getProcess !== "undefined" && __cjs_getProcess.versions && __cjs_getProcess.versions.node) {
10
+ const [major, minor] = __cjs_getProcess.versions.node.split(".").map(Number);
11
+ // Node.js 20.16.0+ and 22.3.0+
12
+ if (major > 22 || (major === 22 && minor >= 3) || (major === 20 && minor >= 16)) {
13
+ return __cjs_getProcess.getBuiltinModule(module);
14
+ }
15
+ }
16
+ // Fallback to createRequire
17
+ return __cjs_require(module);
18
+ };
19
+
20
+ const {
21
+ createHash
22
+ } = __cjs_getBuiltinModule("node:crypto");
23
+ const {
24
+ existsSync,
25
+ readFileSync,
26
+ mkdirSync,
27
+ writeFileSync
28
+ } = __cjs_getBuiltinModule("node:fs");
29
+ const {
30
+ tmpdir
31
+ } = __cjs_getBuiltinModule("node:os");
32
+ import { generateText } from 'ai';
33
+ import aiPrompt from '../solution/ai/ai-prompt.js';
34
+ import aiSolutionResponse from './aiSolutionResponse-CJBMLS9t.js';
35
+
36
+ const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
37
+ const normalizeWindowsPath = (input = "") => {
38
+ if (!input) {
39
+ return input;
40
+ }
41
+ return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
42
+ };
43
+ const UNC_REGEX = /^[/\\]{2}/;
44
+ const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
45
+ const DRIVE_LETTER_RE = /^[A-Z]:$/i;
46
+ const normalizeString = (path2, allowAboveRoot) => {
47
+ let result = "";
48
+ let lastSegmentLength = 0;
49
+ let lastSlash = -1;
50
+ let dots = 0;
51
+ let char;
52
+ for (let index = 0; index <= path2.length; ++index) {
53
+ if (index < path2.length) {
54
+ char = path2[index];
55
+ } else if (char === "/") {
56
+ break;
57
+ } else {
58
+ char = "/";
59
+ }
60
+ if (char === "/") {
61
+ if (lastSlash === index - 1 || dots === 1) ;
62
+ else if (dots === 2) {
63
+ if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
64
+ if (result.length > 2) {
65
+ const lastSlashIndex = result.lastIndexOf("/");
66
+ if (lastSlashIndex === -1) {
67
+ result = "";
68
+ lastSegmentLength = 0;
69
+ } else {
70
+ result = result.slice(0, lastSlashIndex);
71
+ lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
72
+ }
73
+ lastSlash = index;
74
+ dots = 0;
75
+ continue;
76
+ } else if (result.length > 0) {
77
+ result = "";
78
+ lastSegmentLength = 0;
79
+ lastSlash = index;
80
+ dots = 0;
81
+ continue;
82
+ }
83
+ }
84
+ if (allowAboveRoot) {
85
+ result += result.length > 0 ? "/.." : "..";
86
+ lastSegmentLength = 2;
87
+ }
88
+ } else {
89
+ if (result.length > 0) {
90
+ result += `/${path2.slice(lastSlash + 1, index)}`;
91
+ } else {
92
+ result = path2.slice(lastSlash + 1, index);
93
+ }
94
+ lastSegmentLength = index - lastSlash - 1;
95
+ }
96
+ lastSlash = index;
97
+ dots = 0;
98
+ } else if (char === "." && dots !== -1) {
99
+ ++dots;
100
+ } else {
101
+ dots = -1;
102
+ }
103
+ }
104
+ return result;
105
+ };
106
+ const isAbsolute = (path2) => IS_ABSOLUTE_RE.test(path2);
107
+ const normalize = function(path2) {
108
+ if (path2.length === 0) {
109
+ return ".";
110
+ }
111
+ path2 = normalizeWindowsPath(path2);
112
+ const isUNCPath = UNC_REGEX.exec(path2);
113
+ const isPathAbsolute = isAbsolute(path2);
114
+ const trailingSeparator = path2.at(-1) === "/";
115
+ path2 = normalizeString(path2, !isPathAbsolute);
116
+ if (path2.length === 0) {
117
+ if (isPathAbsolute) {
118
+ return "/";
119
+ }
120
+ return trailingSeparator ? "./" : ".";
121
+ }
122
+ if (trailingSeparator) {
123
+ path2 += "/";
124
+ }
125
+ if (DRIVE_LETTER_RE.test(path2)) {
126
+ path2 += "/";
127
+ }
128
+ if (isUNCPath) {
129
+ if (!isPathAbsolute) {
130
+ return `//./${path2}`;
131
+ }
132
+ return `//${path2}`;
133
+ }
134
+ return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
135
+ };
136
+ const join = (...segments) => {
137
+ let path2 = "";
138
+ for (const seg of segments) {
139
+ if (!seg) {
140
+ continue;
141
+ }
142
+ if (path2.length > 0) {
143
+ const pathTrailing = path2[path2.length - 1] === "/";
144
+ const segLeading = seg[0] === "/";
145
+ const both = pathTrailing && segLeading;
146
+ if (both) {
147
+ path2 += seg.slice(1);
148
+ } else {
149
+ path2 += pathTrailing || segLeading ? seg : `/${seg}`;
150
+ }
151
+ } else {
152
+ path2 += seg;
153
+ }
154
+ }
155
+ return normalize(path2);
156
+ };
157
+
158
+ const DEFAULT_HEADER = "## Ai Generated Solution";
159
+ const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
160
+ const generateCacheKey = (error, file, temperature) => {
161
+ const keyData = {
162
+ error: {
163
+ message: error.message,
164
+ name: error.name,
165
+ stack: error.stack
166
+ },
167
+ file: {
168
+ file: file.file,
169
+ language: file.language,
170
+ line: file.line,
171
+ snippet: file.snippet
172
+ },
173
+ temperature
174
+ };
175
+ return createHash("sha256").update(JSON.stringify(keyData)).digest("hex");
176
+ };
177
+ const getCacheDirectory = (directory) => {
178
+ if (directory) {
179
+ return directory;
180
+ }
181
+ return join(tmpdir(), "visulima-error-cache");
182
+ };
183
+ const ensureCacheDirectory = (cacheDirectory) => {
184
+ if (!existsSync(cacheDirectory)) {
185
+ mkdirSync(cacheDirectory, { recursive: true });
186
+ }
187
+ };
188
+ const getCacheFilePath = (cacheDirectory, key) => join(cacheDirectory, `${key}.json`);
189
+ const readFromCache = (cacheFilePath, ttl) => {
190
+ try {
191
+ if (!existsSync(cacheFilePath)) {
192
+ return void 0;
193
+ }
194
+ const cacheContent = readFileSync(cacheFilePath, "utf8");
195
+ const cacheEntry = JSON.parse(cacheContent);
196
+ const now = Date.now();
197
+ if (now - cacheEntry.timestamp > ttl) {
198
+ return void 0;
199
+ }
200
+ return cacheEntry.solution;
201
+ } catch {
202
+ return void 0;
203
+ }
204
+ };
205
+ const writeToCache = (cacheFilePath, solution, ttl) => {
206
+ try {
207
+ const cacheEntry = {
208
+ solution,
209
+ timestamp: Date.now(),
210
+ ttl
211
+ };
212
+ writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
213
+ } catch {
214
+ }
215
+ };
216
+ const aiFinder = (model, options) => {
217
+ return {
218
+ handle: async (error, file) => {
219
+ const cacheOptions = options?.cache;
220
+ const temperature = options?.temperature ?? 0;
221
+ const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
222
+ const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
223
+ if (cacheOptions?.enabled !== false) {
224
+ const cacheKey = generateCacheKey(error, file, temperature);
225
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
226
+ const cachedSolution = readFromCache(cacheFilePath, ttl);
227
+ if (cachedSolution) {
228
+ return cachedSolution;
229
+ }
230
+ ensureCacheDirectory(cacheDirectory);
231
+ }
232
+ const content = aiPrompt({ applicationType: void 0, error, file });
233
+ try {
234
+ const result = await generateText({
235
+ model,
236
+ prompt: content,
237
+ temperature
238
+ });
239
+ const messageContent = result.text;
240
+ let solution;
241
+ if (messageContent) {
242
+ solution = {
243
+ body: aiSolutionResponse(messageContent),
244
+ header: DEFAULT_HEADER
245
+ };
246
+ } else {
247
+ solution = {
248
+ body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
249
+ header: DEFAULT_HEADER
250
+ };
251
+ }
252
+ if (cacheOptions?.enabled !== false) {
253
+ const cacheKey = generateCacheKey(error, file, temperature);
254
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
255
+ writeToCache(cacheFilePath, solution, ttl);
256
+ }
257
+ return solution;
258
+ } catch (error_) {
259
+ console.error(error_);
260
+ const solution = {
261
+ body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
262
+ header: DEFAULT_HEADER
263
+ };
264
+ if (cacheOptions?.enabled !== false) {
265
+ const cacheKey = generateCacheKey(error, file, temperature);
266
+ const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
267
+ writeToCache(cacheFilePath, solution, ttl);
268
+ }
269
+ return solution;
270
+ }
271
+ },
272
+ name: "AI SDK",
273
+ priority: 99
274
+ };
275
+ };
276
+
277
+ export { aiFinder as default };
@@ -0,0 +1,34 @@
1
+ const between = (start, end, text) => {
2
+ const startPosition = text.indexOf(start);
3
+ if (startPosition === -1) {
4
+ return "";
5
+ }
6
+ const adjustedStartPosition = startPosition + start.length;
7
+ const endPosition = text.indexOf(end, adjustedStartPosition);
8
+ if (endPosition === -1) {
9
+ return "";
10
+ }
11
+ return text.slice(adjustedStartPosition, endPosition).trim();
12
+ };
13
+ const aiSolutionResponse = (rawText) => {
14
+ const description = between("FIX", "ENDFIX", rawText);
15
+ if (!description) {
16
+ return [
17
+ "No solution found.",
18
+ // eslint-disable-next-line no-secrets/no-secrets
19
+ `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">@visulima/error</a>.`,
20
+ `"${rawText}"`
21
+ ].join("</br></br>");
22
+ }
23
+ const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
24
+ return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
25
+
26
+ ## Links
27
+
28
+ ${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
29
+
30
+ --------------------
31
+ 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.`;
32
+ };
33
+
34
+ export { aiSolutionResponse as default };
@@ -0,0 +1,10 @@
1
+ const captureRawStackTrace = () => {
2
+ if (!Error.captureStackTrace) {
3
+ return void 0;
4
+ }
5
+ const stack = new Error();
6
+ Error.captureStackTrace(stack);
7
+ return stack.stack;
8
+ };
9
+
10
+ export { captureRawStackTrace as default };
@@ -0,0 +1,116 @@
1
+ import { i as isPlainObject } from './index-y_UPkY2Z.js';
2
+ import { isErrorLike, getErrorConstructor } from './addKnownErrorConstructor-s_3SsXtQ.js';
3
+ import NonError from './NonError-D5FGLYKY.js';
4
+
5
+ const defaultOptions = {
6
+ maxDepth: Number.POSITIVE_INFINITY
7
+ };
8
+ const deserializePlainObject = (object, options, depth = 0) => {
9
+ if (isErrorLike(object)) {
10
+ return reconstructError(object, options, depth);
11
+ }
12
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
13
+ return new NonError(JSON.stringify(object));
14
+ }
15
+ return new NonError(JSON.stringify(object));
16
+ };
17
+ const reconstructAggregateError = (Constructor, errors, message, options, depth) => {
18
+ const reconstructedErrors = errors.map((error_) => deserializeValue(error_, options, depth + 1));
19
+ return new Constructor(reconstructedErrors, message);
20
+ };
21
+ const reconstructError = (serialized, options, depth) => {
22
+ if (options.maxDepth !== void 0 && depth >= options.maxDepth) {
23
+ return new NonError(JSON.stringify(serialized));
24
+ }
25
+ const { cause, errors, message, name, stack, ...properties } = serialized;
26
+ const Constructor = getErrorConstructor(name) || Error;
27
+ const error = name === "AggregateError" && Array.isArray(errors) ? reconstructAggregateError(Constructor, errors, message, options, depth) : new Constructor(message);
28
+ if (!error.name && name) {
29
+ error.name = name;
30
+ }
31
+ if (message !== void 0) {
32
+ error.message = message;
33
+ }
34
+ if (stack) {
35
+ error.stack = stack;
36
+ }
37
+ restoreErrorProperties(error, properties, cause, name, options, depth);
38
+ if (cause !== void 0) {
39
+ error.cause = deserializeValue(cause, options, depth + 1);
40
+ }
41
+ makePropertiesEnumerable(error, serialized);
42
+ return error;
43
+ };
44
+ const deserializeValue = (value, options, depth) => {
45
+ if (isPlainObject(value)) {
46
+ return deserializePlainObject(value, options, depth);
47
+ }
48
+ if (Array.isArray(value)) {
49
+ return value.map((item) => deserializeValue(item, options, depth));
50
+ }
51
+ return value;
52
+ };
53
+ const restoreErrorProperties = (error, properties, cause, name, options, depth) => {
54
+ const errorCopy = error;
55
+ for (const [key, value] of Object.entries(properties)) {
56
+ if (key === "cause" && cause !== void 0) {
57
+ continue;
58
+ } else if (key === "errors" && name === "AggregateError") {
59
+ continue;
60
+ } else {
61
+ errorCopy[key] = deserializeValue(value, options, depth + 1);
62
+ }
63
+ }
64
+ };
65
+ const makePropertiesEnumerable = (error, serialized) => {
66
+ const errorProperties = /* @__PURE__ */ new Set();
67
+ errorProperties.add("name");
68
+ errorProperties.add("message");
69
+ errorProperties.add("stack");
70
+ for (const key of Object.keys(serialized)) {
71
+ errorProperties.add(key);
72
+ }
73
+ for (const key of errorProperties) {
74
+ if (key in error) {
75
+ const descriptor = Object.getOwnPropertyDescriptor(error, key);
76
+ if (descriptor && !descriptor.enumerable) {
77
+ Object.defineProperty(error, key, {
78
+ ...descriptor,
79
+ enumerable: true
80
+ });
81
+ }
82
+ }
83
+ }
84
+ };
85
+ const handlePrimitive = (value) => new NonError(JSON.stringify(value));
86
+ const handleArray = (value) => new NonError(JSON.stringify(value));
87
+ const handlePlainObject = (value, config) => {
88
+ if (isErrorLike(value)) {
89
+ return reconstructError(value, config, 0);
90
+ }
91
+ return deserializePlainObject(value, config);
92
+ };
93
+ const deserialize = (value, options = {}) => {
94
+ const config = { ...defaultOptions, ...options };
95
+ if (value instanceof Error) {
96
+ return value;
97
+ }
98
+ if (value === null) {
99
+ return handlePrimitive(null);
100
+ }
101
+ if (typeof value === "string" || typeof value === "number" || typeof value === "boolean") {
102
+ return handlePrimitive(value);
103
+ }
104
+ if (Array.isArray(value)) {
105
+ return handleArray(value);
106
+ }
107
+ if (isErrorLike(value)) {
108
+ return reconstructError(value, config, 0);
109
+ }
110
+ if (isPlainObject(value)) {
111
+ return handlePlainObject(value, config);
112
+ }
113
+ return new NonError(JSON.stringify(value));
114
+ };
115
+
116
+ export { deserialize as default };