@visulima/error 4.4.18 → 4.6.0

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 (70) hide show
  1. package/CHANGELOG.md +30 -0
  2. package/LICENSE.md +125 -0
  3. package/README.md +262 -0
  4. package/dist/code-frame/index.cjs +6 -5
  5. package/dist/code-frame/index.mjs +6 -5
  6. package/dist/error/index.cjs +10 -3
  7. package/dist/error/index.d.cts +19 -1
  8. package/dist/error/index.d.mts +19 -1
  9. package/dist/error/index.d.ts +19 -1
  10. package/dist/error/index.mjs +6 -3
  11. package/dist/index.cjs +23 -5
  12. package/dist/index.d.cts +6 -2
  13. package/dist/index.d.mts +6 -2
  14. package/dist/index.d.ts +6 -2
  15. package/dist/index.mjs +13 -5
  16. package/dist/packem_shared/NonError-BrwMc2LE.mjs +13 -0
  17. package/dist/packem_shared/NonError-DqwGL5Cy.cjs +15 -0
  18. package/dist/packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs +32 -0
  19. package/dist/packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs +39 -0
  20. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.cts +3 -0
  21. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.mts +3 -0
  22. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.ts +3 -0
  23. package/dist/packem_shared/aiFinder-BR9Pq804.cjs +259 -0
  24. package/dist/packem_shared/aiFinder-CFHvOjD8.mjs +257 -0
  25. package/dist/packem_shared/aiSolutionResponse-BaN1M990.mjs +36 -0
  26. package/dist/packem_shared/aiSolutionResponse-Cqi0mFxy.cjs +38 -0
  27. package/dist/packem_shared/deserializeError-Be3qOGBQ.cjs +120 -0
  28. package/dist/packem_shared/deserializeError-DuzHucBb.mjs +118 -0
  29. package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +23 -0
  30. package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +25 -0
  31. package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +31 -0
  32. package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +26 -0
  33. package/dist/packem_shared/index-BmoOJLvu.mjs +12 -0
  34. package/dist/packem_shared/index-C53Tqb7g.cjs +14 -0
  35. package/dist/packem_shared/{indexToLineColumn-Dx91YDU1.mjs → indexToLineColumn-CKQKtKEK.mjs} +0 -2
  36. package/dist/packem_shared/{indexToLineColumn-DjmjeiIY.cjs → indexToLineColumn-Cro5eT8v.cjs} +0 -2
  37. package/dist/packem_shared/{isVisulimaError-BVLWvREw.cjs → isVisulimaError-Bb1_TB6w.cjs} +0 -1
  38. package/dist/packem_shared/{isVisulimaError-H6TqEA42.mjs → isVisulimaError-zyd80Gui.mjs} +0 -1
  39. package/dist/packem_shared/{parseStacktrace-BKGoWCwC.mjs → parseStacktrace-BlguTUcF.mjs} +10 -15
  40. package/dist/packem_shared/{parseStacktrace-6pFoXW43.cjs → parseStacktrace-woJgU2XY.cjs} +10 -15
  41. package/dist/packem_shared/{renderError-BWpM2m6k.mjs → renderError-Cn8M0fQ3.mjs} +37 -22
  42. package/dist/packem_shared/{renderError-CXZTAXig.cjs → renderError-n3kXGdYj.cjs} +35 -20
  43. package/dist/packem_shared/ruleBasedFinder-Cbmc6N7f.mjs +227 -0
  44. package/dist/packem_shared/ruleBasedFinder-CkybTSHw.cjs +229 -0
  45. package/dist/packem_shared/{serializeError-DusTUACt.mjs → serializeError-DHIelq5o.mjs} +2 -11
  46. package/dist/packem_shared/{serializeError-CT7s0Ffk.cjs → serializeError-Dt7oFM2R.cjs} +3 -12
  47. package/dist/packem_shared/types-BtQS7FHG.d.cts +20 -0
  48. package/dist/packem_shared/types-BtQS7FHG.d.mts +20 -0
  49. package/dist/packem_shared/types-BtQS7FHG.d.ts +20 -0
  50. package/dist/solution/ai/ai-prompt.cjs +42 -0
  51. package/dist/solution/ai/ai-prompt.d.cts +9 -0
  52. package/dist/solution/ai/ai-prompt.d.mts +9 -0
  53. package/dist/solution/ai/ai-prompt.d.ts +9 -0
  54. package/dist/solution/ai/ai-prompt.mjs +40 -0
  55. package/dist/solution/ai/index.cjs +13 -0
  56. package/dist/solution/ai/index.d.cts +16 -0
  57. package/dist/solution/ai/index.d.mts +16 -0
  58. package/dist/solution/ai/index.d.ts +16 -0
  59. package/dist/solution/ai/index.mjs +3 -0
  60. package/dist/solution/index.cjs +11 -0
  61. package/dist/solution/index.d.cts +8 -0
  62. package/dist/solution/index.d.mts +8 -0
  63. package/dist/solution/index.d.ts +8 -0
  64. package/dist/solution/index.mjs +2 -0
  65. package/dist/stacktrace/index.cjs +4 -1
  66. package/dist/stacktrace/index.d.cts +10 -2
  67. package/dist/stacktrace/index.d.mts +10 -2
  68. package/dist/stacktrace/index.d.ts +10 -2
  69. package/dist/stacktrace/index.mjs +2 -1
  70. package/package.json +63 -16
package/dist/index.cjs CHANGED
@@ -3,23 +3,41 @@
3
3
  Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
4
 
5
5
  const codeFrame_index = require('./code-frame/index.cjs');
6
- const indexToLineColumn = require('./packem_shared/indexToLineColumn-DjmjeiIY.cjs');
6
+ const indexToLineColumn = require('./packem_shared/indexToLineColumn-Cro5eT8v.cjs');
7
+ const solution_ai_aiPrompt = require('./solution/ai/ai-prompt.cjs');
8
+ const aiSolutionResponse = require('./packem_shared/aiSolutionResponse-Cqi0mFxy.cjs');
9
+ const errorHintFinder = require('./packem_shared/errorHintFinder-DZugFHq0.cjs');
10
+ const ruleBasedFinder = require('./packem_shared/ruleBasedFinder-CkybTSHw.cjs');
7
11
  const captureRawStackTrace = require('./packem_shared/captureRawStackTrace-ClSI1tHb.cjs');
12
+ const deserializeError = require('./packem_shared/deserializeError-Be3qOGBQ.cjs');
8
13
  const getErrorCauses = require('./packem_shared/getErrorCauses-miTeYJEG.cjs');
9
- const parseStacktrace = require('./packem_shared/parseStacktrace-6pFoXW43.cjs');
10
- const isVisulimaError = require('./packem_shared/isVisulimaError-BVLWvREw.cjs');
11
- const renderError = require('./packem_shared/renderError-CXZTAXig.cjs');
12
- const serializeError = require('./packem_shared/serializeError-CT7s0Ffk.cjs');
14
+ const NonError = require('./packem_shared/NonError-DqwGL5Cy.cjs');
15
+ const parseStacktrace = require('./packem_shared/parseStacktrace-woJgU2XY.cjs');
16
+ const addKnownErrorConstructor = require('./packem_shared/addKnownErrorConstructor-J1_ZUURa.cjs');
17
+ const isVisulimaError = require('./packem_shared/isVisulimaError-Bb1_TB6w.cjs');
18
+ const renderError = require('./packem_shared/renderError-n3kXGdYj.cjs');
19
+ const serializeError = require('./packem_shared/serializeError-Dt7oFM2R.cjs');
20
+ const formatStackFrameLine = require('./packem_shared/formatStackFrameLine-DcXSX--m.cjs');
13
21
 
14
22
 
15
23
 
16
24
  exports.CODE_FRAME_POINTER = codeFrame_index.CODE_FRAME_POINTER;
17
25
  exports.codeFrame = codeFrame_index.codeFrame;
18
26
  exports.indexToLineColumn = indexToLineColumn;
27
+ exports.aiPrompt = solution_ai_aiPrompt;
28
+ exports.aiSolutionResponse = aiSolutionResponse;
29
+ exports.errorHintFinder = errorHintFinder;
30
+ exports.ruleBasedFinder = ruleBasedFinder;
19
31
  exports.captureRawStackTrace = captureRawStackTrace;
32
+ exports.deserializeError = deserializeError;
20
33
  exports.getErrorCauses = getErrorCauses;
34
+ exports.NonError = NonError;
21
35
  exports.parseStacktrace = parseStacktrace;
36
+ exports.addKnownErrorConstructor = addKnownErrorConstructor.addKnownErrorConstructor;
37
+ exports.isErrorLike = addKnownErrorConstructor.isErrorLike;
22
38
  exports.VisulimaError = isVisulimaError.VisulimaError;
23
39
  exports.isVisulimaError = isVisulimaError.isVisulimaError;
24
40
  exports.renderError = renderError.renderError;
25
41
  exports.serializeError = serializeError.serialize;
42
+ exports.formatStackFrameLine = formatStackFrameLine.formatStackFrameLine;
43
+ exports.formatStacktrace = formatStackFrameLine.formatStacktrace;
package/dist/index.d.cts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.cjs';
2
- export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.cjs';
3
- export { Trace, TraceType, parseStacktrace } from './stacktrace/index.cjs';
2
+ export { default as aiPrompt } from './solution/ai/ai-prompt.cjs';
3
+ export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.cjs';
4
+ export { errorHintFinder, ruleBasedFinder } from './solution/index.cjs';
5
+ export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.cjs';
6
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.cjs';
7
+ export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.cjs';
4
8
  export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.cjs';
5
9
 
6
10
  declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
package/dist/index.d.mts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.mjs';
2
- export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.mjs';
3
- export { Trace, TraceType, parseStacktrace } from './stacktrace/index.mjs';
2
+ export { default as aiPrompt } from './solution/ai/ai-prompt.mjs';
3
+ export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.mjs';
4
+ export { errorHintFinder, ruleBasedFinder } from './solution/index.mjs';
5
+ export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.mjs';
6
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.mjs';
7
+ export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.mjs';
4
8
  export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.mjs';
5
9
 
6
10
  declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
package/dist/index.d.ts CHANGED
@@ -1,6 +1,10 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.js';
2
- export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, RenderErrorOptions, SerializedError, VisulimaError, captureRawStackTrace, getErrorCauses, isVisulimaError, renderError, serializeError } from './error/index.js';
3
- export { Trace, TraceType, parseStacktrace } from './stacktrace/index.js';
2
+ export { default as aiPrompt } from './solution/ai/ai-prompt.js';
3
+ export { a as aiSolutionResponse } from './packem_shared/ai-solution-response-BuaDQAEU.js';
4
+ export { errorHintFinder, ruleBasedFinder } from './solution/index.js';
5
+ export { S as Solution, a as SolutionError, b as SolutionFinder, c as SolutionFinderFile } from './packem_shared/types-BtQS7FHG.js';
6
+ export { ErrorHint, ErrorLocation, ErrorProperties, ErrorWithCauseSerializerOptions, NonError, RenderErrorOptions, SerializedError, VisulimaError, addKnownErrorConstructor, captureRawStackTrace, deserializeError, getErrorCauses, isErrorLike, isVisulimaError, renderError, serializeError } from './error/index.js';
7
+ export { Trace, TraceType, formatStackFrameLine, formatStacktrace, parseStacktrace } from './stacktrace/index.js';
4
8
  export { C as CodeFrameLocation, a as CodeFrameNodeLocation, b as CodeFrameOptions, c as ColorizeMethod } from './packem_shared/types-CrVmNoPV.js';
5
9
 
6
10
  declare const indexToLineColumn: (input: number[] | string, index: number, options?: {
package/dist/index.mjs CHANGED
@@ -1,8 +1,16 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.mjs';
2
- export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Dx91YDU1.mjs';
2
+ export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-CKQKtKEK.mjs';
3
+ export { default as aiPrompt } from './solution/ai/ai-prompt.mjs';
4
+ export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-BaN1M990.mjs';
5
+ export { default as errorHintFinder } from './packem_shared/errorHintFinder-CQy_qIK3.mjs';
6
+ export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-Cbmc6N7f.mjs';
3
7
  export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-Tl3Rqkat.mjs';
8
+ export { default as deserializeError } from './packem_shared/deserializeError-DuzHucBb.mjs';
4
9
  export { default as getErrorCauses } from './packem_shared/getErrorCauses-CG_JRE6j.mjs';
5
- export { default as parseStacktrace } from './packem_shared/parseStacktrace-BKGoWCwC.mjs';
6
- export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-H6TqEA42.mjs';
7
- export { renderError } from './packem_shared/renderError-BWpM2m6k.mjs';
8
- export { serialize as serializeError } from './packem_shared/serializeError-DusTUACt.mjs';
10
+ export { default as NonError } from './packem_shared/NonError-BrwMc2LE.mjs';
11
+ export { default as parseStacktrace } from './packem_shared/parseStacktrace-BlguTUcF.mjs';
12
+ export { addKnownErrorConstructor, isErrorLike } from './packem_shared/addKnownErrorConstructor-DBmmT2OF.mjs';
13
+ export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-zyd80Gui.mjs';
14
+ export { renderError } from './packem_shared/renderError-Cn8M0fQ3.mjs';
15
+ export { serialize as serializeError } from './packem_shared/serializeError-DHIelq5o.mjs';
16
+ export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-DqkmKWH3.mjs';
@@ -0,0 +1,13 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ class NonError extends Error {
4
+ static {
5
+ __name(this, "NonError");
6
+ }
7
+ constructor(message) {
8
+ super(message);
9
+ this.name = "NonError";
10
+ }
11
+ }
12
+
13
+ export { NonError as default };
@@ -0,0 +1,15 @@
1
+ 'use strict';
2
+
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
5
+ class NonError extends Error {
6
+ static {
7
+ __name(this, "NonError");
8
+ }
9
+ constructor(message) {
10
+ super(message);
11
+ this.name = "NonError";
12
+ }
13
+ }
14
+
15
+ module.exports = NonError;
@@ -0,0 +1,32 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
3
+ const defaultErrorConstructors = /* @__PURE__ */ new Map([
4
+ ["Error", Error],
5
+ ["EvalError", EvalError],
6
+ ["RangeError", RangeError],
7
+ ["ReferenceError", ReferenceError],
8
+ ["SyntaxError", SyntaxError],
9
+ ["TypeError", TypeError],
10
+ ["URIError", URIError]
11
+ ]);
12
+ if (typeof AggregateError !== "undefined") {
13
+ defaultErrorConstructors.set("AggregateError", AggregateError);
14
+ }
15
+ const addKnownErrorConstructor = /* @__PURE__ */ __name((constructor, name) => {
16
+ let instance;
17
+ try {
18
+ instance = new constructor();
19
+ } catch (error) {
20
+ throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
21
+ }
22
+ const resolvedName = name ?? instance.name;
23
+ if (defaultErrorConstructors.has(resolvedName)) {
24
+ throw new Error(`The error constructor "${resolvedName}" is already known.`);
25
+ }
26
+ defaultErrorConstructors.set(resolvedName, constructor);
27
+ }, "addKnownErrorConstructor");
28
+ const getKnownErrorConstructors = /* @__PURE__ */ __name(() => new Map(defaultErrorConstructors), "getKnownErrorConstructors");
29
+ const getErrorConstructor = /* @__PURE__ */ __name((name) => defaultErrorConstructors.get(name), "getErrorConstructor");
30
+ const isErrorLike = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error"), "isErrorLike");
31
+
32
+ export { addKnownErrorConstructor, getErrorConstructor, getKnownErrorConstructors, isErrorLike };
@@ -0,0 +1,39 @@
1
+ 'use strict';
2
+
3
+ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: 'Module' } });
4
+
5
+ var __defProp = Object.defineProperty;
6
+ var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
7
+ const defaultErrorConstructors = /* @__PURE__ */ new Map([
8
+ ["Error", Error],
9
+ ["EvalError", EvalError],
10
+ ["RangeError", RangeError],
11
+ ["ReferenceError", ReferenceError],
12
+ ["SyntaxError", SyntaxError],
13
+ ["TypeError", TypeError],
14
+ ["URIError", URIError]
15
+ ]);
16
+ if (typeof AggregateError !== "undefined") {
17
+ defaultErrorConstructors.set("AggregateError", AggregateError);
18
+ }
19
+ const addKnownErrorConstructor = /* @__PURE__ */ __name((constructor, name) => {
20
+ let instance;
21
+ try {
22
+ instance = new constructor();
23
+ } catch (error) {
24
+ throw new Error(`The error constructor "${constructor.name}" is not compatible`, { cause: error });
25
+ }
26
+ const resolvedName = name ?? instance.name;
27
+ if (defaultErrorConstructors.has(resolvedName)) {
28
+ throw new Error(`The error constructor "${resolvedName}" is already known.`);
29
+ }
30
+ defaultErrorConstructors.set(resolvedName, constructor);
31
+ }, "addKnownErrorConstructor");
32
+ const getKnownErrorConstructors = /* @__PURE__ */ __name(() => new Map(defaultErrorConstructors), "getKnownErrorConstructors");
33
+ const getErrorConstructor = /* @__PURE__ */ __name((name) => defaultErrorConstructors.get(name), "getErrorConstructor");
34
+ const isErrorLike = /* @__PURE__ */ __name((value) => value !== null && typeof value === "object" && typeof value.name === "string" && typeof value.message === "string" && (getErrorConstructor(value.name) !== void 0 || value.name === "Error"), "isErrorLike");
35
+
36
+ exports.addKnownErrorConstructor = addKnownErrorConstructor;
37
+ exports.getErrorConstructor = getErrorConstructor;
38
+ exports.getKnownErrorConstructors = getKnownErrorConstructors;
39
+ exports.isErrorLike = isErrorLike;
@@ -0,0 +1,3 @@
1
+ declare const aiSolutionResponse: (rawText: string) => string;
2
+
3
+ export { aiSolutionResponse as a };
@@ -0,0 +1,3 @@
1
+ declare const aiSolutionResponse: (rawText: string) => string;
2
+
3
+ export { aiSolutionResponse as a };
@@ -0,0 +1,3 @@
1
+ declare const aiSolutionResponse: (rawText: string) => string;
2
+
3
+ export { aiSolutionResponse as a };
@@ -0,0 +1,259 @@
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;