@visulima/error 4.6.0 → 4.6.2
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.
- package/CHANGELOG.md +20 -0
- package/dist/code-frame/index.cjs +6 -136
- package/dist/code-frame/index.mjs +6 -131
- package/dist/error/index.cjs +1 -25
- package/dist/error/index.mjs +1 -8
- package/dist/index.cjs +1 -43
- package/dist/index.mjs +1 -16
- package/dist/packem_shared/NonError-CQn4sdxd.cjs +1 -0
- package/dist/packem_shared/NonError-CS10kwil.mjs +1 -0
- package/dist/packem_shared/addKnownErrorConstructor-B5dNFGsR.cjs +1 -0
- package/dist/packem_shared/addKnownErrorConstructor-BqqnTSZp.mjs +1 -0
- package/dist/packem_shared/aiFinder-Be-xHFVO.mjs +1 -0
- package/dist/packem_shared/aiFinder-CN0pneE2.cjs +1 -0
- package/dist/packem_shared/aiSolutionResponse-C5apAmTu.cjs +10 -0
- package/dist/packem_shared/aiSolutionResponse-RD0AK1jh.mjs +10 -0
- package/dist/packem_shared/captureRawStackTrace-B9d1821F.cjs +1 -0
- package/dist/packem_shared/captureRawStackTrace-CQPNHvBG.mjs +1 -0
- package/dist/packem_shared/deserializeError-2C6o7QF7.cjs +1 -0
- package/dist/packem_shared/deserializeError-tzZhIV70.mjs +1 -0
- package/dist/packem_shared/errorHintFinder-C_g0nvml.mjs +2 -0
- package/dist/packem_shared/errorHintFinder-DRCn1Ysx.cjs +2 -0
- package/dist/packem_shared/formatStackFrameLine-DD2DUdW0.cjs +2 -0
- package/dist/packem_shared/formatStackFrameLine-iU54KA81.mjs +2 -0
- package/dist/packem_shared/getErrorCauses-B7_Z_gEF.cjs +1 -0
- package/dist/packem_shared/getErrorCauses-D025FGyO.mjs +1 -0
- package/dist/packem_shared/index-CLFYRLyq.mjs +1 -0
- package/dist/packem_shared/index-CqSGigts.cjs +1 -0
- package/dist/packem_shared/indexToLineColumn-B1F7aNZh.mjs +1 -0
- package/dist/packem_shared/indexToLineColumn-C_v57REF.cjs +1 -0
- package/dist/packem_shared/isVisulimaError-CrvBm0kw.cjs +1 -0
- package/dist/packem_shared/isVisulimaError-jVZgumOU.mjs +1 -0
- package/dist/packem_shared/parseStacktrace-Dnxnc4PL.mjs +2 -0
- package/dist/packem_shared/parseStacktrace-MW4-SLXl.cjs +2 -0
- package/dist/packem_shared/renderError-D7R71d_7.mjs +18 -0
- package/dist/packem_shared/renderError-D8XJnkIF.cjs +18 -0
- package/dist/packem_shared/ruleBasedFinder-B1jRHBM_.cjs +34 -0
- package/dist/packem_shared/ruleBasedFinder-P88d0gpK.mjs +34 -0
- package/dist/packem_shared/serializeError-7S1IG6zs.cjs +1 -0
- package/dist/packem_shared/serializeError-Bc-QciX0.mjs +1 -0
- package/dist/solution/ai/ai-prompt.cjs +7 -17
- package/dist/solution/ai/ai-prompt.mjs +7 -15
- package/dist/solution/ai/index.cjs +1 -13
- package/dist/solution/ai/index.mjs +1 -3
- package/dist/solution/index.cjs +1 -11
- package/dist/solution/index.mjs +1 -2
- package/dist/stacktrace/index.cjs +1 -12
- package/dist/stacktrace/index.mjs +1 -2
- package/package.json +1 -1
- package/dist/packem_shared/NonError-BrwMc2LE.mjs +0 -13
- package/dist/packem_shared/NonError-DqwGL5Cy.cjs +0 -15
- package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +0 -32
- package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +0 -39
- package/dist/packem_shared/aiFinder-BR9Pq804.cjs +0 -259
- package/dist/packem_shared/aiFinder-CFHvOjD8.mjs +0 -257
- package/dist/packem_shared/aiSolutionResponse-BaN1M990.mjs +0 -36
- package/dist/packem_shared/aiSolutionResponse-Cqi0mFxy.cjs +0 -38
- package/dist/packem_shared/captureRawStackTrace-ClSI1tHb.cjs +0 -14
- package/dist/packem_shared/captureRawStackTrace-Tl3Rqkat.mjs +0 -12
- package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +0 -120
- package/dist/packem_shared/deserializeError-DuzHucBb.mjs +0 -118
- package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +0 -23
- package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +0 -25
- package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +0 -31
- package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +0 -26
- package/dist/packem_shared/getErrorCauses-CG_JRE6j.mjs +0 -24
- package/dist/packem_shared/getErrorCauses-miTeYJEG.cjs +0 -26
- package/dist/packem_shared/index-BmoOJLvu.mjs +0 -12
- package/dist/packem_shared/index-C53Tqb7g.cjs +0 -14
- package/dist/packem_shared/indexToLineColumn-CKQKtKEK.mjs +0 -52
- package/dist/packem_shared/indexToLineColumn-Cro5eT8v.cjs +0 -54
- package/dist/packem_shared/isVisulimaError-Bb1_TB6w.cjs +0 -44
- package/dist/packem_shared/isVisulimaError-zyd80Gui.mjs +0 -39
- package/dist/packem_shared/parseStacktrace-BlguTUcF.mjs +0 -275
- package/dist/packem_shared/parseStacktrace-woJgU2XY.cjs +0 -277
- package/dist/packem_shared/renderError-Cn8M0fQ3.mjs +0 -180
- package/dist/packem_shared/renderError-n3kXGdYj.cjs +0 -184
- package/dist/packem_shared/ruleBasedFinder-Cbmc6N7f.mjs +0 -227
- package/dist/packem_shared/ruleBasedFinder-CkybTSHw.cjs +0 -229
- package/dist/packem_shared/serializeError-DHIelq5o.mjs +0 -144
- package/dist/packem_shared/serializeError-Dt7oFM2R.cjs +0 -148
|
@@ -1,259 +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-Cqi0mFxy.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
|
-
message: error.message,
|
|
146
|
-
name: error.name,
|
|
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((cacheDirectory) => {
|
|
166
|
-
if (!node_fs.existsSync(cacheDirectory)) {
|
|
167
|
-
node_fs.mkdirSync(cacheDirectory, { recursive: true });
|
|
168
|
-
}
|
|
169
|
-
}, "ensureCacheDirectory");
|
|
170
|
-
const getCacheFilePath = /* @__PURE__ */ __name((cacheDirectory, key) => join(cacheDirectory, `${key}.json`), "getCacheFilePath");
|
|
171
|
-
const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
|
|
172
|
-
try {
|
|
173
|
-
if (!node_fs.existsSync(cacheFilePath)) {
|
|
174
|
-
return void 0;
|
|
175
|
-
}
|
|
176
|
-
const cacheContent = node_fs.readFileSync(cacheFilePath, "utf8");
|
|
177
|
-
const cacheEntry = JSON.parse(cacheContent);
|
|
178
|
-
const now = Date.now();
|
|
179
|
-
if (now - cacheEntry.timestamp > ttl) {
|
|
180
|
-
return void 0;
|
|
181
|
-
}
|
|
182
|
-
return cacheEntry.solution;
|
|
183
|
-
} catch {
|
|
184
|
-
return void 0;
|
|
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
|
-
node_fs.writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
|
|
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
|
-
const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
|
|
205
|
-
if (cacheOptions?.enabled !== false) {
|
|
206
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
207
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
208
|
-
const cachedSolution = readFromCache(cacheFilePath, ttl);
|
|
209
|
-
if (cachedSolution) {
|
|
210
|
-
return cachedSolution;
|
|
211
|
-
}
|
|
212
|
-
ensureCacheDirectory(cacheDirectory);
|
|
213
|
-
}
|
|
214
|
-
const content = solution_ai_aiPrompt({ applicationType: void 0, error, file });
|
|
215
|
-
try {
|
|
216
|
-
const result = await ai.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(messageContent),
|
|
226
|
-
header: DEFAULT_HEADER
|
|
227
|
-
};
|
|
228
|
-
} else {
|
|
229
|
-
solution = {
|
|
230
|
-
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
231
|
-
header: DEFAULT_HEADER
|
|
232
|
-
};
|
|
233
|
-
}
|
|
234
|
-
if (cacheOptions?.enabled !== false) {
|
|
235
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
236
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
237
|
-
writeToCache(cacheFilePath, solution, ttl);
|
|
238
|
-
}
|
|
239
|
-
return solution;
|
|
240
|
-
} catch (error_) {
|
|
241
|
-
console.error(error_);
|
|
242
|
-
const solution = {
|
|
243
|
-
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
244
|
-
header: DEFAULT_HEADER
|
|
245
|
-
};
|
|
246
|
-
if (cacheOptions?.enabled !== false) {
|
|
247
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
248
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
249
|
-
writeToCache(cacheFilePath, solution, ttl);
|
|
250
|
-
}
|
|
251
|
-
return solution;
|
|
252
|
-
}
|
|
253
|
-
}, "handle"),
|
|
254
|
-
name: "AI SDK",
|
|
255
|
-
priority: 99
|
|
256
|
-
};
|
|
257
|
-
}, "aiFinder");
|
|
258
|
-
|
|
259
|
-
module.exports = aiFinder;
|
|
@@ -1,257 +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-BaN1M990.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
|
-
message: error.message,
|
|
144
|
-
name: error.name,
|
|
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((cacheDirectory) => {
|
|
164
|
-
if (!existsSync(cacheDirectory)) {
|
|
165
|
-
mkdirSync(cacheDirectory, { recursive: true });
|
|
166
|
-
}
|
|
167
|
-
}, "ensureCacheDirectory");
|
|
168
|
-
const getCacheFilePath = /* @__PURE__ */ __name((cacheDirectory, key) => join(cacheDirectory, `${key}.json`), "getCacheFilePath");
|
|
169
|
-
const readFromCache = /* @__PURE__ */ __name((cacheFilePath, ttl) => {
|
|
170
|
-
try {
|
|
171
|
-
if (!existsSync(cacheFilePath)) {
|
|
172
|
-
return void 0;
|
|
173
|
-
}
|
|
174
|
-
const cacheContent = readFileSync(cacheFilePath, "utf8");
|
|
175
|
-
const cacheEntry = JSON.parse(cacheContent);
|
|
176
|
-
const now = Date.now();
|
|
177
|
-
if (now - cacheEntry.timestamp > ttl) {
|
|
178
|
-
return void 0;
|
|
179
|
-
}
|
|
180
|
-
return cacheEntry.solution;
|
|
181
|
-
} catch {
|
|
182
|
-
return void 0;
|
|
183
|
-
}
|
|
184
|
-
}, "readFromCache");
|
|
185
|
-
const writeToCache = /* @__PURE__ */ __name((cacheFilePath, solution, ttl) => {
|
|
186
|
-
try {
|
|
187
|
-
const cacheEntry = {
|
|
188
|
-
solution,
|
|
189
|
-
timestamp: Date.now(),
|
|
190
|
-
ttl
|
|
191
|
-
};
|
|
192
|
-
writeFileSync(cacheFilePath, JSON.stringify(cacheEntry, null, 2), "utf8");
|
|
193
|
-
} catch {
|
|
194
|
-
}
|
|
195
|
-
}, "writeToCache");
|
|
196
|
-
const aiFinder = /* @__PURE__ */ __name((model, options) => {
|
|
197
|
-
return {
|
|
198
|
-
handle: /* @__PURE__ */ __name(async (error, file) => {
|
|
199
|
-
const cacheOptions = options?.cache;
|
|
200
|
-
const temperature = options?.temperature ?? 0;
|
|
201
|
-
const ttl = cacheOptions?.ttl ?? 24 * 60 * 60 * 1e3;
|
|
202
|
-
const cacheDirectory = getCacheDirectory(cacheOptions?.directory);
|
|
203
|
-
if (cacheOptions?.enabled !== false) {
|
|
204
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
205
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
206
|
-
const cachedSolution = readFromCache(cacheFilePath, ttl);
|
|
207
|
-
if (cachedSolution) {
|
|
208
|
-
return cachedSolution;
|
|
209
|
-
}
|
|
210
|
-
ensureCacheDirectory(cacheDirectory);
|
|
211
|
-
}
|
|
212
|
-
const content = aiPrompt({ applicationType: void 0, error, file });
|
|
213
|
-
try {
|
|
214
|
-
const result = await generateText({
|
|
215
|
-
model,
|
|
216
|
-
prompt: content,
|
|
217
|
-
temperature
|
|
218
|
-
});
|
|
219
|
-
const messageContent = result.text;
|
|
220
|
-
let solution;
|
|
221
|
-
if (messageContent) {
|
|
222
|
-
solution = {
|
|
223
|
-
body: aiSolutionResponse(messageContent),
|
|
224
|
-
header: DEFAULT_HEADER
|
|
225
|
-
};
|
|
226
|
-
} else {
|
|
227
|
-
solution = {
|
|
228
|
-
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
229
|
-
header: DEFAULT_HEADER
|
|
230
|
-
};
|
|
231
|
-
}
|
|
232
|
-
if (cacheOptions?.enabled !== false) {
|
|
233
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
234
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
235
|
-
writeToCache(cacheFilePath, solution, ttl);
|
|
236
|
-
}
|
|
237
|
-
return solution;
|
|
238
|
-
} catch (error_) {
|
|
239
|
-
console.error(error_);
|
|
240
|
-
const solution = {
|
|
241
|
-
body: aiSolutionResponse(DEFAULT_ERROR_MESSAGE),
|
|
242
|
-
header: DEFAULT_HEADER
|
|
243
|
-
};
|
|
244
|
-
if (cacheOptions?.enabled !== false) {
|
|
245
|
-
const cacheKey = generateCacheKey(error, file, temperature);
|
|
246
|
-
const cacheFilePath = getCacheFilePath(cacheDirectory, cacheKey);
|
|
247
|
-
writeToCache(cacheFilePath, solution, ttl);
|
|
248
|
-
}
|
|
249
|
-
return solution;
|
|
250
|
-
}
|
|
251
|
-
}, "handle"),
|
|
252
|
-
name: "AI SDK",
|
|
253
|
-
priority: 99
|
|
254
|
-
};
|
|
255
|
-
}, "aiFinder");
|
|
256
|
-
|
|
257
|
-
export { aiFinder as default };
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const between = /* @__PURE__ */ __name((start, end, text) => {
|
|
4
|
-
const startPosition = text.indexOf(start);
|
|
5
|
-
if (startPosition === -1) {
|
|
6
|
-
return "";
|
|
7
|
-
}
|
|
8
|
-
const adjustedStartPosition = startPosition + start.length;
|
|
9
|
-
const endPosition = text.indexOf(end, adjustedStartPosition);
|
|
10
|
-
if (endPosition === -1) {
|
|
11
|
-
return "";
|
|
12
|
-
}
|
|
13
|
-
return text.slice(adjustedStartPosition, endPosition).trim();
|
|
14
|
-
}, "between");
|
|
15
|
-
const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
|
|
16
|
-
const description = between("FIX", "ENDFIX", rawText);
|
|
17
|
-
if (!description) {
|
|
18
|
-
return [
|
|
19
|
-
"No solution found.",
|
|
20
|
-
// eslint-disable-next-line no-secrets/no-secrets
|
|
21
|
-
`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>.`,
|
|
22
|
-
`"${rawText}"`
|
|
23
|
-
].join("</br></br>");
|
|
24
|
-
}
|
|
25
|
-
const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
|
|
26
|
-
return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
|
|
27
|
-
|
|
28
|
-
## Links
|
|
29
|
-
|
|
30
|
-
${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
|
|
31
|
-
|
|
32
|
-
--------------------
|
|
33
|
-
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.`;
|
|
34
|
-
}, "aiSolutionResponse");
|
|
35
|
-
|
|
36
|
-
export { aiSolutionResponse as default };
|
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const between = /* @__PURE__ */ __name((start, end, text) => {
|
|
6
|
-
const startPosition = text.indexOf(start);
|
|
7
|
-
if (startPosition === -1) {
|
|
8
|
-
return "";
|
|
9
|
-
}
|
|
10
|
-
const adjustedStartPosition = startPosition + start.length;
|
|
11
|
-
const endPosition = text.indexOf(end, adjustedStartPosition);
|
|
12
|
-
if (endPosition === -1) {
|
|
13
|
-
return "";
|
|
14
|
-
}
|
|
15
|
-
return text.slice(adjustedStartPosition, endPosition).trim();
|
|
16
|
-
}, "between");
|
|
17
|
-
const aiSolutionResponse = /* @__PURE__ */ __name((rawText) => {
|
|
18
|
-
const description = between("FIX", "ENDFIX", rawText);
|
|
19
|
-
if (!description) {
|
|
20
|
-
return [
|
|
21
|
-
"No solution found.",
|
|
22
|
-
// eslint-disable-next-line no-secrets/no-secrets
|
|
23
|
-
`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>.`,
|
|
24
|
-
`"${rawText}"`
|
|
25
|
-
].join("</br></br>");
|
|
26
|
-
}
|
|
27
|
-
const links = between("LINKS", "ENDLINKS", rawText).split("\n").map((link) => JSON.parse(link));
|
|
28
|
-
return `${description.replaceAll(/"([^"]*)"(\s|\.)/g, "<code>$1</code> ")}
|
|
29
|
-
|
|
30
|
-
## Links
|
|
31
|
-
|
|
32
|
-
${links.map((link) => `- <a href="${link.url}" target="_blank" rel="noopener noreferrer">${link.title}</a>`).join("\n")}
|
|
33
|
-
|
|
34
|
-
--------------------
|
|
35
|
-
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.`;
|
|
36
|
-
}, "aiSolutionResponse");
|
|
37
|
-
|
|
38
|
-
module.exports = aiSolutionResponse;
|
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
var __defProp = Object.defineProperty;
|
|
4
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
5
|
-
const captureRawStackTrace = /* @__PURE__ */ __name(() => {
|
|
6
|
-
if (!Error.captureStackTrace) {
|
|
7
|
-
return void 0;
|
|
8
|
-
}
|
|
9
|
-
const stack = new Error();
|
|
10
|
-
Error.captureStackTrace(stack);
|
|
11
|
-
return stack.stack;
|
|
12
|
-
}, "captureRawStackTrace");
|
|
13
|
-
|
|
14
|
-
module.exports = captureRawStackTrace;
|
|
@@ -1,12 +0,0 @@
|
|
|
1
|
-
var __defProp = Object.defineProperty;
|
|
2
|
-
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
3
|
-
const captureRawStackTrace = /* @__PURE__ */ __name(() => {
|
|
4
|
-
if (!Error.captureStackTrace) {
|
|
5
|
-
return void 0;
|
|
6
|
-
}
|
|
7
|
-
const stack = new Error();
|
|
8
|
-
Error.captureStackTrace(stack);
|
|
9
|
-
return stack.stack;
|
|
10
|
-
}, "captureRawStackTrace");
|
|
11
|
-
|
|
12
|
-
export { captureRawStackTrace as default };
|