@visulima/error 4.5.0 → 4.6.1

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 (85) hide show
  1. package/CHANGELOG.md +25 -0
  2. package/README.md +148 -4
  3. package/dist/code-frame/index.cjs +6 -135
  4. package/dist/code-frame/index.mjs +6 -130
  5. package/dist/error/index.cjs +1 -18
  6. package/dist/error/index.d.cts +19 -1
  7. package/dist/error/index.d.mts +19 -1
  8. package/dist/error/index.d.ts +19 -1
  9. package/dist/error/index.mjs +1 -5
  10. package/dist/index.cjs +1 -36
  11. package/dist/index.d.cts +1 -1
  12. package/dist/index.d.mts +1 -1
  13. package/dist/index.d.ts +1 -1
  14. package/dist/index.mjs +1 -13
  15. package/dist/packem_shared/NonError-CQn4sdxd.cjs +1 -0
  16. package/dist/packem_shared/NonError-CS10kwil.mjs +1 -0
  17. package/dist/packem_shared/addKnownErrorConstructor-B5dNFGsR.cjs +1 -0
  18. package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.mjs +1 -0
  19. package/dist/packem_shared/aiFinder-Be-xHFVO.mjs +1 -0
  20. package/dist/packem_shared/aiFinder-CN0pneE2.cjs +1 -0
  21. package/dist/packem_shared/aiSolutionResponse-C5apAmTu.cjs +10 -0
  22. package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.mjs +10 -0
  23. package/dist/packem_shared/captureRawStackTrace-B9d1821F.cjs +1 -0
  24. package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.mjs +1 -0
  25. package/dist/packem_shared/deserializeError-2C6o7QF7.cjs +1 -0
  26. package/dist/packem_shared/deserializeError-tzZhIV70.mjs +1 -0
  27. package/dist/packem_shared/errorHintFinder-C_g0nvml.mjs +2 -0
  28. package/dist/packem_shared/errorHintFinder-DRCn1Ysx.cjs +2 -0
  29. package/dist/packem_shared/formatStackFrameLine-DD2DUdW0.cjs +2 -0
  30. package/dist/packem_shared/formatStackFrameLine-iU54KA81.mjs +2 -0
  31. package/dist/packem_shared/getErrorCauses-B7_Z_gEF.cjs +1 -0
  32. package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +1 -0
  33. package/dist/packem_shared/index-CLFYRLyq.mjs +1 -0
  34. package/dist/packem_shared/index-CqSGigts.cjs +1 -0
  35. package/dist/packem_shared/indexToLineColumn-B1F7aNZh.mjs +1 -0
  36. package/dist/packem_shared/indexToLineColumn-C_v57REF.cjs +1 -0
  37. package/dist/packem_shared/isVisulimaError-CrvBm0kw.cjs +1 -0
  38. package/dist/packem_shared/isVisulimaError-jVZgumOU.mjs +1 -0
  39. package/dist/packem_shared/parseStacktrace-Dnxnc4PL.mjs +2 -0
  40. package/dist/packem_shared/parseStacktrace-MW4-SLXl.cjs +2 -0
  41. package/dist/packem_shared/renderError-D7R71d_7.mjs +18 -0
  42. package/dist/packem_shared/renderError-D8XJnkIF.cjs +18 -0
  43. package/dist/packem_shared/ruleBasedFinder-DTyLJeCs.cjs +35 -0
  44. package/dist/packem_shared/ruleBasedFinder-W5UXhtHl.mjs +35 -0
  45. package/dist/packem_shared/serializeError-7S1IG6zs.cjs +1 -0
  46. package/dist/packem_shared/serializeError-Bc-QciX0.mjs +1 -0
  47. package/dist/solution/ai/ai-prompt.cjs +7 -17
  48. package/dist/solution/ai/ai-prompt.mjs +7 -15
  49. package/dist/solution/ai/index.cjs +1 -13
  50. package/dist/solution/ai/index.d.cts +2 -2
  51. package/dist/solution/ai/index.d.mts +2 -2
  52. package/dist/solution/ai/index.d.ts +2 -2
  53. package/dist/solution/ai/index.mjs +1 -3
  54. package/dist/solution/index.cjs +1 -11
  55. package/dist/solution/index.mjs +1 -2
  56. package/dist/stacktrace/index.cjs +1 -12
  57. package/dist/stacktrace/index.d.cts +2 -2
  58. package/dist/stacktrace/index.d.mts +2 -2
  59. package/dist/stacktrace/index.d.ts +2 -2
  60. package/dist/stacktrace/index.mjs +1 -2
  61. package/package.json +1 -1
  62. package/dist/packem_shared/aiFinder-BGfwKKxE.cjs +0 -263
  63. package/dist/packem_shared/aiFinder-Bk1vt0_x.mjs +0 -261
  64. package/dist/packem_shared/aiSolutionResponse-BPckbL56.cjs +0 -37
  65. package/dist/packem_shared/aiSolutionResponse-bDi4ad8f.mjs +0 -35
  66. package/dist/packem_shared/captureRawStackTrace-ClSI1tHb.cjs +0 -14
  67. package/dist/packem_shared/captureRawStackTrace-Tl3Rqkat.mjs +0 -12
  68. package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +0 -23
  69. package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +0 -25
  70. package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +0 -31
  71. package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +0 -26
  72. package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +0 -24
  73. package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +0 -26
  74. package/dist/packem_shared/indexToLineColumn-DjmjeiIY.cjs +0 -56
  75. package/dist/packem_shared/indexToLineColumn-Dx91YDU1.mjs +0 -54
  76. package/dist/packem_shared/isVisulimaError-BVLWvREw.cjs +0 -45
  77. package/dist/packem_shared/isVisulimaError-H6TqEA42.mjs +0 -40
  78. package/dist/packem_shared/parseStacktrace-6pFoXW43.cjs +0 -282
  79. package/dist/packem_shared/parseStacktrace-BKGoWCwC.mjs +0 -280
  80. package/dist/packem_shared/renderError-BWpM2m6k.mjs +0 -165
  81. package/dist/packem_shared/renderError-CXZTAXig.cjs +0 -169
  82. package/dist/packem_shared/ruleBasedFinder-BYrndubA.mjs +0 -227
  83. package/dist/packem_shared/ruleBasedFinder-y_-5kbeT.cjs +0 -229
  84. package/dist/packem_shared/serializeError-CT7s0Ffk.cjs +0 -157
  85. package/dist/packem_shared/serializeError-DusTUACt.mjs +0 -153
@@ -4,13 +4,13 @@ export { default as aiPrompt } from './ai-prompt.cjs';
4
4
  export { a as aiSolutionResponse } from '../../packem_shared/ai-solution-response-BuaDQAEU.cjs';
5
5
 
6
6
  interface CacheOptions {
7
- enabled?: boolean;
8
7
  directory?: string;
8
+ enabled?: boolean;
9
9
  ttl?: number;
10
10
  }
11
11
  declare const aiFinder: (model: LanguageModel, options?: {
12
- temperature?: number;
13
12
  cache?: CacheOptions;
13
+ temperature?: number;
14
14
  }) => SolutionFinder;
15
15
 
16
16
  export { aiFinder };
@@ -4,13 +4,13 @@ export { default as aiPrompt } from './ai-prompt.mjs';
4
4
  export { a as aiSolutionResponse } from '../../packem_shared/ai-solution-response-BuaDQAEU.mjs';
5
5
 
6
6
  interface CacheOptions {
7
- enabled?: boolean;
8
7
  directory?: string;
8
+ enabled?: boolean;
9
9
  ttl?: number;
10
10
  }
11
11
  declare const aiFinder: (model: LanguageModel, options?: {
12
- temperature?: number;
13
12
  cache?: CacheOptions;
13
+ temperature?: number;
14
14
  }) => SolutionFinder;
15
15
 
16
16
  export { aiFinder };
@@ -4,13 +4,13 @@ export { default as aiPrompt } from './ai-prompt.js';
4
4
  export { a as aiSolutionResponse } from '../../packem_shared/ai-solution-response-BuaDQAEU.js';
5
5
 
6
6
  interface CacheOptions {
7
- enabled?: boolean;
8
7
  directory?: string;
8
+ enabled?: boolean;
9
9
  ttl?: number;
10
10
  }
11
11
  declare const aiFinder: (model: LanguageModel, options?: {
12
- temperature?: number;
13
12
  cache?: CacheOptions;
13
+ temperature?: number;
14
14
  }) => SolutionFinder;
15
15
 
16
16
  export { aiFinder };
@@ -1,3 +1 @@
1
- export { default as aiFinder } from '../../packem_shared/aiFinder-Bk1vt0_x.mjs';
2
- export { default as aiPrompt } from './ai-prompt.mjs';
3
- export { default as aiSolutionResponse } from '../../packem_shared/aiSolutionResponse-bDi4ad8f.mjs';
1
+ import{default as e}from"../../packem_shared/aiFinder-Be-xHFVO.mjs";import{default as t}from"./ai-prompt.mjs";import{default as i}from"../../packem_shared/aiSolutionResponse-RD0AK1jh.mjs";export{e as aiFinder,t as aiPrompt,i as aiSolutionResponse};
@@ -1,11 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const errorHintFinder = require('../packem_shared/errorHintFinder-DZugFHq0.cjs');
6
- const ruleBasedFinder = require('../packem_shared/ruleBasedFinder-y_-5kbeT.cjs');
7
-
8
-
9
-
10
- exports.errorHintFinder = errorHintFinder;
11
- exports.ruleBasedFinder = ruleBasedFinder;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const e=require("../packem_shared/errorHintFinder-DRCn1Ysx.cjs"),r=require("../packem_shared/ruleBasedFinder-DTyLJeCs.cjs");exports.errorHintFinder=e;exports.ruleBasedFinder=r;
@@ -1,2 +1 @@
1
- export { default as errorHintFinder } from '../packem_shared/errorHintFinder-CQy_qIK3.mjs';
2
- export { default as ruleBasedFinder } from '../packem_shared/ruleBasedFinder-BYrndubA.mjs';
1
+ import{default as a}from"../packem_shared/errorHintFinder-C_g0nvml.mjs";import{default as o}from"../packem_shared/ruleBasedFinder-W5UXhtHl.mjs";export{a as errorHintFinder,o as ruleBasedFinder};
@@ -1,12 +1 @@
1
- 'use strict';
2
-
3
- Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
-
5
- const parseStacktrace = require('../packem_shared/parseStacktrace-6pFoXW43.cjs');
6
- const formatStackFrameLine = require('../packem_shared/formatStackFrameLine-DcXSX--m.cjs');
7
-
8
-
9
-
10
- exports.parseStacktrace = parseStacktrace;
11
- exports.formatStackFrameLine = formatStackFrameLine.formatStackFrameLine;
12
- exports.formatStacktrace = formatStackFrameLine.formatStacktrace;
1
+ "use strict";Object.defineProperties(exports,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}});const a=require("../packem_shared/parseStacktrace-MW4-SLXl.cjs"),e=require("../packem_shared/formatStackFrameLine-DD2DUdW0.cjs");exports.parseStacktrace=a;exports.formatStackFrameLine=e.formatStackFrameLine;exports.formatStacktrace=e.formatStacktrace;
@@ -9,7 +9,7 @@ interface Trace {
9
9
  type?: TraceType | undefined;
10
10
  }
11
11
 
12
- declare const parse: (error: Error, { filter, frameLimit }?: Partial<{
12
+ declare const parseStacktrace: (error: Error, { filter, frameLimit }?: Partial<{
13
13
  filter?: (line: string) => boolean;
14
14
  frameLimit: number;
15
15
  }>) => Trace[];
@@ -22,4 +22,4 @@ declare const formatStacktrace: (frames: Trace[], options?: {
22
22
  };
23
23
  }) => string;
24
24
 
25
- export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parse as parseStacktrace };
25
+ export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace };
@@ -9,7 +9,7 @@ interface Trace {
9
9
  type?: TraceType | undefined;
10
10
  }
11
11
 
12
- declare const parse: (error: Error, { filter, frameLimit }?: Partial<{
12
+ declare const parseStacktrace: (error: Error, { filter, frameLimit }?: Partial<{
13
13
  filter?: (line: string) => boolean;
14
14
  frameLimit: number;
15
15
  }>) => Trace[];
@@ -22,4 +22,4 @@ declare const formatStacktrace: (frames: Trace[], options?: {
22
22
  };
23
23
  }) => string;
24
24
 
25
- export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parse as parseStacktrace };
25
+ export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace };
@@ -9,7 +9,7 @@ interface Trace {
9
9
  type?: TraceType | undefined;
10
10
  }
11
11
 
12
- declare const parse: (error: Error, { filter, frameLimit }?: Partial<{
12
+ declare const parseStacktrace: (error: Error, { filter, frameLimit }?: Partial<{
13
13
  filter?: (line: string) => boolean;
14
14
  frameLimit: number;
15
15
  }>) => Trace[];
@@ -22,4 +22,4 @@ declare const formatStacktrace: (frames: Trace[], options?: {
22
22
  };
23
23
  }) => string;
24
24
 
25
- export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parse as parseStacktrace };
25
+ export { type Trace, type TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace };
@@ -1,2 +1 @@
1
- export { default as parseStacktrace } from '../packem_shared/parseStacktrace-BKGoWCwC.mjs';
2
- export { formatStackFrameLine, formatStacktrace } from '../packem_shared/formatStackFrameLine-DqkmKWH3.mjs';
1
+ import{default as t}from"../packem_shared/parseStacktrace-Dnxnc4PL.mjs";import{formatStackFrameLine as o,formatStacktrace as c}from"../packem_shared/formatStackFrameLine-iU54KA81.mjs";export{o as formatStackFrameLine,c as formatStacktrace,t as parseStacktrace};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@visulima/error",
3
- "version": "4.5.0",
3
+ "version": "4.6.1",
4
4
  "description": "Error with more than just a message, stacktrace parsing.",
5
5
  "keywords": [
6
6
  "anolilab",
@@ -1,263 +0,0 @@
1
- 'use strict';
2
-
3
- const node_crypto = require('node:crypto');
4
- const node_fs = require('node:fs');
5
- const node_os = require('node:os');
6
- const ai = require('ai');
7
- const solution_ai_aiPrompt = require('../solution/ai/ai-prompt.cjs');
8
- const aiSolutionResponse = require('./aiSolutionResponse-BPckbL56.cjs');
9
-
10
- var __defProp$1 = Object.defineProperty;
11
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
12
- var __defProp$1$1 = Object.defineProperty;
13
- var __name$1$1 = /* @__PURE__ */ __name$1((target, value) => __defProp$1$1(target, "name", { value, configurable: true }), "__name$1");
14
- const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
15
- const normalizeWindowsPath = /* @__PURE__ */ __name$1$1((input = "") => {
16
- if (!input) {
17
- return input;
18
- }
19
- return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
20
- }, "normalizeWindowsPath");
21
- var __defProp2 = Object.defineProperty;
22
- var __name2 = /* @__PURE__ */ __name$1((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
23
- const UNC_REGEX = /^[/\\]{2}/;
24
- const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
25
- const DRIVE_LETTER_RE = /^[A-Z]:$/i;
26
- const normalizeString = /* @__PURE__ */ __name2((path2, allowAboveRoot) => {
27
- let result = "";
28
- let lastSegmentLength = 0;
29
- let lastSlash = -1;
30
- let dots = 0;
31
- let char = null;
32
- for (let index = 0; index <= path2.length; ++index) {
33
- if (index < path2.length) {
34
- char = path2[index];
35
- } else if (char === "/") {
36
- break;
37
- } else {
38
- char = "/";
39
- }
40
- if (char === "/") {
41
- if (lastSlash === index - 1 || dots === 1) ;
42
- else if (dots === 2) {
43
- if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
44
- if (result.length > 2) {
45
- const lastSlashIndex = result.lastIndexOf("/");
46
- if (lastSlashIndex === -1) {
47
- result = "";
48
- lastSegmentLength = 0;
49
- } else {
50
- result = result.slice(0, lastSlashIndex);
51
- lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
52
- }
53
- lastSlash = index;
54
- dots = 0;
55
- continue;
56
- } else if (result.length > 0) {
57
- result = "";
58
- lastSegmentLength = 0;
59
- lastSlash = index;
60
- dots = 0;
61
- continue;
62
- }
63
- }
64
- if (allowAboveRoot) {
65
- result += result.length > 0 ? "/.." : "..";
66
- lastSegmentLength = 2;
67
- }
68
- } else {
69
- if (result.length > 0) {
70
- result += `/${path2.slice(lastSlash + 1, index)}`;
71
- } else {
72
- result = path2.slice(lastSlash + 1, index);
73
- }
74
- lastSegmentLength = index - lastSlash - 1;
75
- }
76
- lastSlash = index;
77
- dots = 0;
78
- } else if (char === "." && dots !== -1) {
79
- ++dots;
80
- } else {
81
- dots = -1;
82
- }
83
- }
84
- return result;
85
- }, "normalizeString");
86
- const isAbsolute = /* @__PURE__ */ __name2((path2) => IS_ABSOLUTE_RE.test(path2), "isAbsolute");
87
- const normalize = /* @__PURE__ */ __name2(function(path2) {
88
- if (path2.length === 0) {
89
- return ".";
90
- }
91
- path2 = normalizeWindowsPath(path2);
92
- const isUNCPath = UNC_REGEX.exec(path2);
93
- const isPathAbsolute = isAbsolute(path2);
94
- const trailingSeparator = path2.at(-1) === "/";
95
- path2 = normalizeString(path2, !isPathAbsolute);
96
- if (path2.length === 0) {
97
- if (isPathAbsolute) {
98
- return "/";
99
- }
100
- return trailingSeparator ? "./" : ".";
101
- }
102
- if (trailingSeparator) {
103
- path2 += "/";
104
- }
105
- if (DRIVE_LETTER_RE.test(path2)) {
106
- path2 += "/";
107
- }
108
- if (isUNCPath) {
109
- if (!isPathAbsolute) {
110
- return `//./${path2}`;
111
- }
112
- return `//${path2}`;
113
- }
114
- return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
115
- }, "normalize");
116
- const join = /* @__PURE__ */ __name2((...segments) => {
117
- let path2 = "";
118
- for (const seg of segments) {
119
- if (!seg) {
120
- continue;
121
- }
122
- if (path2.length > 0) {
123
- const pathTrailing = path2[path2.length - 1] === "/";
124
- const segLeading = seg[0] === "/";
125
- const both = pathTrailing && segLeading;
126
- if (both) {
127
- path2 += seg.slice(1);
128
- } else {
129
- path2 += pathTrailing || segLeading ? seg : `/${seg}`;
130
- }
131
- } else {
132
- path2 += seg;
133
- }
134
- }
135
- return normalize(path2);
136
- }, "join");
137
-
138
- var __defProp = Object.defineProperty;
139
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
140
- const DEFAULT_HEADER = "## Ai Generated Solution";
141
- const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
142
- const generateCacheKey = /* @__PURE__ */ __name((error, file, temperature) => {
143
- const keyData = {
144
- error: {
145
- name: error.name,
146
- message: error.message,
147
- stack: error.stack
148
- },
149
- file: {
150
- file: file.file,
151
- language: file.language,
152
- line: file.line,
153
- snippet: file.snippet
154
- },
155
- temperature
156
- };
157
- return node_crypto.createHash("sha256").update(JSON.stringify(keyData)).digest("hex");
158
- }, "generateCacheKey");
159
- const getCacheDirectory = /* @__PURE__ */ __name((directory) => {
160
- if (directory) {
161
- return directory;
162
- }
163
- return join(node_os.tmpdir(), "visulima-error-cache");
164
- }, "getCacheDirectory");
165
- const ensureCacheDirectory = /* @__PURE__ */ __name((cacheDir) => {
166
- if (!node_fs.existsSync(cacheDir)) {
167
- node_fs.mkdirSync(cacheDir, { recursive: true });
168
- }
169
- }, "ensureCacheDirectory");
170
- const getCacheFilePath = /* @__PURE__ */ __name((cacheDir, key) => {
171
- return join(cacheDir, `${key}.json`);
172
- }, "getCacheFilePath");
173
- const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
174
- try {
175
- if (!node_fs.existsSync(cacheFilePath)) {
176
- return null;
177
- }
178
- const cacheContent = node_fs.readFileSync(cacheFilePath, "utf-8");
179
- const cacheEntry = JSON.parse(cacheContent);
180
- const now = Date.now();
181
- if (now - cacheEntry.timestamp > ttl) {
182
- return null;
183
- }
184
- return cacheEntry.solution;
185
- } catch {
186
- return null;
187
- }
188
- }, "readFromCache");
189
- const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
190
- try {
191
- const cacheEntry = {
192
- solution,
193
- timestamp: Date.now(),
194
- ttl
195
- };
196
- node_fs.writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf-8");
197
- } catch {
198
- }
199
- }, "writeToCache");
200
- const aiFinder = /* @__PURE__ */ __name((model, options) => {
201
- return {
202
- handle: /* @__PURE__ */ __name(async (error, file) => {
203
- const cacheOptions = options?.cache;
204
- const temperature = options?.temperature ?? 0;
205
- const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
206
- if (cacheOptions?.enabled !== false) {
207
- const cacheKey = generateCacheKey(error, file, temperature);
208
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
209
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
210
- const cachedSolution = readFromCache(cacheFilePath, ttl);
211
- if (cachedSolution) {
212
- return cachedSolution;
213
- }
214
- ensureCacheDirectory(cacheDir);
215
- }
216
- const content = solution_ai_aiPrompt({ applicationType: void 0, error, file });
217
- try {
218
- const result = await ai.generateText({
219
- model,
220
- prompt: content,
221
- temperature
222
- });
223
- const messageContent = result.text;
224
- let solution;
225
- if (!messageContent) {
226
- solution = {
227
- body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
228
- header: DEFAULT_HEADER
229
- };
230
- } else {
231
- solution = {
232
- body: aiSolutionResponse(messageContent),
233
- header: DEFAULT_HEADER
234
- };
235
- }
236
- if (cacheOptions?.enabled !== false) {
237
- const cacheKey = generateCacheKey(error, file, temperature);
238
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
239
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
240
- writeToCache(cacheFilePath, solution, ttl);
241
- }
242
- return solution;
243
- } catch (error_) {
244
- console.error(error_);
245
- const solution = {
246
- body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
247
- header: DEFAULT_HEADER
248
- };
249
- if (cacheOptions?.enabled !== false) {
250
- const cacheKey = generateCacheKey(error, file, temperature);
251
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
252
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
253
- writeToCache(cacheFilePath, solution, ttl);
254
- }
255
- return solution;
256
- }
257
- }, "handle"),
258
- name: "AI SDK",
259
- priority: 99
260
- };
261
- }, "aiFinder");
262
-
263
- module.exports = aiFinder;
@@ -1,261 +0,0 @@
1
- import { createHash } from 'node:crypto';
2
- import { existsSync, readFileSync, mkdirSync, writeFileSync } from 'node:fs';
3
- import { tmpdir } from 'node:os';
4
- import { generateText } from 'ai';
5
- import aiPrompt from '../solution/ai/ai-prompt.mjs';
6
- import aiSolutionResponse from './aiSolutionResponse-bDi4ad8f.mjs';
7
-
8
- var __defProp$1 = Object.defineProperty;
9
- var __name$1 = (target, value) => __defProp$1(target, "name", { value, configurable: true });
10
- var __defProp$1$1 = Object.defineProperty;
11
- var __name$1$1 = /* @__PURE__ */ __name$1((target, value) => __defProp$1$1(target, "name", { value, configurable: true }), "__name$1");
12
- const DRIVE_LETTER_START_RE = /^[A-Z]:\//i;
13
- const normalizeWindowsPath = /* @__PURE__ */ __name$1$1((input = "") => {
14
- if (!input) {
15
- return input;
16
- }
17
- return input.replaceAll("\\", "/").replace(DRIVE_LETTER_START_RE, (r) => r.toUpperCase());
18
- }, "normalizeWindowsPath");
19
- var __defProp2 = Object.defineProperty;
20
- var __name2 = /* @__PURE__ */ __name$1((target, value) => __defProp2(target, "name", { value, configurable: true }), "__name");
21
- const UNC_REGEX = /^[/\\]{2}/;
22
- const IS_ABSOLUTE_RE = /^[/\\](?![/\\])|^[/\\]{2}(?!\.)|^[A-Z]:[/\\]/i;
23
- const DRIVE_LETTER_RE = /^[A-Z]:$/i;
24
- const normalizeString = /* @__PURE__ */ __name2((path2, allowAboveRoot) => {
25
- let result = "";
26
- let lastSegmentLength = 0;
27
- let lastSlash = -1;
28
- let dots = 0;
29
- let char = null;
30
- for (let index = 0; index <= path2.length; ++index) {
31
- if (index < path2.length) {
32
- char = path2[index];
33
- } else if (char === "/") {
34
- break;
35
- } else {
36
- char = "/";
37
- }
38
- if (char === "/") {
39
- if (lastSlash === index - 1 || dots === 1) ;
40
- else if (dots === 2) {
41
- if (result.length < 2 || lastSegmentLength !== 2 || !result.endsWith(".") || result.at(-2) !== ".") {
42
- if (result.length > 2) {
43
- const lastSlashIndex = result.lastIndexOf("/");
44
- if (lastSlashIndex === -1) {
45
- result = "";
46
- lastSegmentLength = 0;
47
- } else {
48
- result = result.slice(0, lastSlashIndex);
49
- lastSegmentLength = result.length - 1 - result.lastIndexOf("/");
50
- }
51
- lastSlash = index;
52
- dots = 0;
53
- continue;
54
- } else if (result.length > 0) {
55
- result = "";
56
- lastSegmentLength = 0;
57
- lastSlash = index;
58
- dots = 0;
59
- continue;
60
- }
61
- }
62
- if (allowAboveRoot) {
63
- result += result.length > 0 ? "/.." : "..";
64
- lastSegmentLength = 2;
65
- }
66
- } else {
67
- if (result.length > 0) {
68
- result += `/${path2.slice(lastSlash + 1, index)}`;
69
- } else {
70
- result = path2.slice(lastSlash + 1, index);
71
- }
72
- lastSegmentLength = index - lastSlash - 1;
73
- }
74
- lastSlash = index;
75
- dots = 0;
76
- } else if (char === "." && dots !== -1) {
77
- ++dots;
78
- } else {
79
- dots = -1;
80
- }
81
- }
82
- return result;
83
- }, "normalizeString");
84
- const isAbsolute = /* @__PURE__ */ __name2((path2) => IS_ABSOLUTE_RE.test(path2), "isAbsolute");
85
- const normalize = /* @__PURE__ */ __name2(function(path2) {
86
- if (path2.length === 0) {
87
- return ".";
88
- }
89
- path2 = normalizeWindowsPath(path2);
90
- const isUNCPath = UNC_REGEX.exec(path2);
91
- const isPathAbsolute = isAbsolute(path2);
92
- const trailingSeparator = path2.at(-1) === "/";
93
- path2 = normalizeString(path2, !isPathAbsolute);
94
- if (path2.length === 0) {
95
- if (isPathAbsolute) {
96
- return "/";
97
- }
98
- return trailingSeparator ? "./" : ".";
99
- }
100
- if (trailingSeparator) {
101
- path2 += "/";
102
- }
103
- if (DRIVE_LETTER_RE.test(path2)) {
104
- path2 += "/";
105
- }
106
- if (isUNCPath) {
107
- if (!isPathAbsolute) {
108
- return `//./${path2}`;
109
- }
110
- return `//${path2}`;
111
- }
112
- return isPathAbsolute && !isAbsolute(path2) ? `/${path2}` : path2;
113
- }, "normalize");
114
- const join = /* @__PURE__ */ __name2((...segments) => {
115
- let path2 = "";
116
- for (const seg of segments) {
117
- if (!seg) {
118
- continue;
119
- }
120
- if (path2.length > 0) {
121
- const pathTrailing = path2[path2.length - 1] === "/";
122
- const segLeading = seg[0] === "/";
123
- const both = pathTrailing && segLeading;
124
- if (both) {
125
- path2 += seg.slice(1);
126
- } else {
127
- path2 += pathTrailing || segLeading ? seg : `/${seg}`;
128
- }
129
- } else {
130
- path2 += seg;
131
- }
132
- }
133
- return normalize(path2);
134
- }, "join");
135
-
136
- var __defProp = Object.defineProperty;
137
- var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
138
- const DEFAULT_HEADER = "## Ai Generated Solution";
139
- const DEFAULT_ERROR_MESSAGE = "Creation of a AI solution failed.";
140
- const generateCacheKey = /* @__PURE__ */ __name((error, file, temperature) => {
141
- const keyData = {
142
- error: {
143
- name: error.name,
144
- message: error.message,
145
- stack: error.stack
146
- },
147
- file: {
148
- file: file.file,
149
- language: file.language,
150
- line: file.line,
151
- snippet: file.snippet
152
- },
153
- temperature
154
- };
155
- return createHash("sha256").update(JSON.stringify(keyData)).digest("hex");
156
- }, "generateCacheKey");
157
- const getCacheDirectory = /* @__PURE__ */ __name((directory) => {
158
- if (directory) {
159
- return directory;
160
- }
161
- return join(tmpdir(), "visulima-error-cache");
162
- }, "getCacheDirectory");
163
- const ensureCacheDirectory = /* @__PURE__ */ __name((cacheDir) => {
164
- if (!existsSync(cacheDir)) {
165
- mkdirSync(cacheDir, { recursive: true });
166
- }
167
- }, "ensureCacheDirectory");
168
- const getCacheFilePath = /* @__PURE__ */ __name((cacheDir, key) => {
169
- return join(cacheDir, `${key}.json`);
170
- }, "getCacheFilePath");
171
- const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
172
- try {
173
- if (!existsSync(cacheFilePath)) {
174
- return null;
175
- }
176
- const cacheContent = readFileSync(cacheFilePath, "utf-8");
177
- const cacheEntry = JSON.parse(cacheContent);
178
- const now = Date.now();
179
- if (now - cacheEntry.timestamp > ttl) {
180
- return null;
181
- }
182
- return cacheEntry.solution;
183
- } catch {
184
- return null;
185
- }
186
- }, "readFromCache");
187
- const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
188
- try {
189
- const cacheEntry = {
190
- solution,
191
- timestamp: Date.now(),
192
- ttl
193
- };
194
- writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf-8");
195
- } catch {
196
- }
197
- }, "writeToCache");
198
- const aiFinder = /* @__PURE__ */ __name((model, options) => {
199
- return {
200
- handle: /* @__PURE__ */ __name(async (error, file) => {
201
- const cacheOptions = options?.cache;
202
- const temperature = options?.temperature ?? 0;
203
- const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
204
- if (cacheOptions?.enabled !== false) {
205
- const cacheKey = generateCacheKey(error, file, temperature);
206
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
207
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
208
- const cachedSolution = readFromCache(cacheFilePath, ttl);
209
- if (cachedSolution) {
210
- return cachedSolution;
211
- }
212
- ensureCacheDirectory(cacheDir);
213
- }
214
- const content = aiPrompt({ applicationType: void 0, error, file });
215
- try {
216
- const result = await generateText({
217
- model,
218
- prompt: content,
219
- temperature
220
- });
221
- const messageContent = result.text;
222
- let solution;
223
- if (!messageContent) {
224
- solution = {
225
- body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
226
- header: DEFAULT_HEADER
227
- };
228
- } else {
229
- solution = {
230
- body: aiSolutionResponse(messageContent),
231
- header: DEFAULT_HEADER
232
- };
233
- }
234
- if (cacheOptions?.enabled !== false) {
235
- const cacheKey = generateCacheKey(error, file, temperature);
236
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
237
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
238
- writeToCache(cacheFilePath, solution, ttl);
239
- }
240
- return solution;
241
- } catch (error_) {
242
- console.error(error_);
243
- const solution = {
244
- body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
245
- header: DEFAULT_HEADER
246
- };
247
- if (cacheOptions?.enabled !== false) {
248
- const cacheKey = generateCacheKey(error, file, temperature);
249
- const cacheDir = getCacheDirectory(cacheOptions?.directory);
250
- const cacheFilePath = getCacheFilePath(cacheDir, cacheKey);
251
- writeToCache(cacheFilePath, solution, ttl);
252
- }
253
- return solution;
254
- }
255
- }, "handle"),
256
- name: "AI SDK",
257
- priority: 99
258
- };
259
- }, "aiFinder");
260
-
261
- export { aiFinder as default };