@visulima/error 4.4.18 → 4.5.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 (45) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/LICENSE.md +125 -0
  3. package/README.md +118 -0
  4. package/dist/index.cjs +11 -0
  5. package/dist/index.d.cts +5 -1
  6. package/dist/index.d.mts +5 -1
  7. package/dist/index.d.ts +5 -1
  8. package/dist/index.mjs +5 -0
  9. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.cts +3 -0
  10. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.mts +3 -0
  11. package/dist/packem_shared/ai-solution-response-BuaDQAEU.d.ts +3 -0
  12. package/dist/packem_shared/aiFinder-BGfwKKxE.cjs +263 -0
  13. package/dist/packem_shared/aiFinder-Bk1vt0_x.mjs +261 -0
  14. package/dist/packem_shared/aiSolutionResponse-BPckbL56.cjs +37 -0
  15. package/dist/packem_shared/aiSolutionResponse-bDi4ad8f.mjs +35 -0
  16. package/dist/packem_shared/errorHintFinder-CQy_qIK3.mjs +23 -0
  17. package/dist/packem_shared/errorHintFinder-DZugFHq0.cjs +25 -0
  18. package/dist/packem_shared/formatStackFrameLine-DcXSX--m.cjs +31 -0
  19. package/dist/packem_shared/formatStackFrameLine-DqkmKWH3.mjs +26 -0
  20. package/dist/packem_shared/ruleBasedFinder-BYrndubA.mjs +227 -0
  21. package/dist/packem_shared/ruleBasedFinder-y_-5kbeT.cjs +229 -0
  22. package/dist/packem_shared/types-BtQS7FHG.d.cts +20 -0
  23. package/dist/packem_shared/types-BtQS7FHG.d.mts +20 -0
  24. package/dist/packem_shared/types-BtQS7FHG.d.ts +20 -0
  25. package/dist/solution/ai/ai-prompt.cjs +42 -0
  26. package/dist/solution/ai/ai-prompt.d.cts +9 -0
  27. package/dist/solution/ai/ai-prompt.d.mts +9 -0
  28. package/dist/solution/ai/ai-prompt.d.ts +9 -0
  29. package/dist/solution/ai/ai-prompt.mjs +40 -0
  30. package/dist/solution/ai/index.cjs +13 -0
  31. package/dist/solution/ai/index.d.cts +16 -0
  32. package/dist/solution/ai/index.d.mts +16 -0
  33. package/dist/solution/ai/index.d.ts +16 -0
  34. package/dist/solution/ai/index.mjs +3 -0
  35. package/dist/solution/index.cjs +11 -0
  36. package/dist/solution/index.d.cts +8 -0
  37. package/dist/solution/index.d.mts +8 -0
  38. package/dist/solution/index.d.ts +8 -0
  39. package/dist/solution/index.mjs +2 -0
  40. package/dist/stacktrace/index.cjs +3 -0
  41. package/dist/stacktrace/index.d.cts +9 -1
  42. package/dist/stacktrace/index.d.mts +9 -1
  43. package/dist/stacktrace/index.d.ts +9 -1
  44. package/dist/stacktrace/index.mjs +1 -0
  45. package/package.json +63 -16
package/CHANGELOG.md CHANGED
@@ -1,3 +1,18 @@
1
+ ## @visulima/error [4.5.0](https://github.com/visulima/visulima/compare/@visulima/error@4.4.18...@visulima/error@4.5.0) (2025-09-07)
2
+
3
+ ### Features
4
+
5
+ * add error solution finder, added new format helper for trace ([82508bc](https://github.com/visulima/visulima/commit/82508bc42476da034b10c4023c823755a3c6b120))
6
+
7
+ ### Bug Fixes
8
+
9
+ * **error:** remove find cache dir dependency and add caching interface ([#514](https://github.com/visulima/visulima/issues/514)) ([caa1bfa](https://github.com/visulima/visulima/commit/caa1bfaf656009d76bcc2991e4a7ff706451670d))
10
+
11
+ ### Miscellaneous Chores
12
+
13
+ * update dependencies and remove obsolete documentation ([9e5e3c2](https://github.com/visulima/visulima/commit/9e5e3c2a68acf50d4b7abf8545d0edb85bb89078))
14
+ * update LICENSE.md with bundled dependencies and their licenses; add new fixture in pnpm-lock.yaml ([49d02a7](https://github.com/visulima/visulima/commit/49d02a7307168d9d2400e846d6f822a631d536e7))
15
+
1
16
  ## @visulima/error [4.4.18](https://github.com/visulima/visulima/compare/@visulima/error@4.4.17...@visulima/error@4.4.18) (2025-06-04)
2
17
 
3
18
 
package/LICENSE.md CHANGED
@@ -27,6 +27,131 @@ The published @visulima/error artifact additionally contains code with the follo
27
27
  MIT
28
28
 
29
29
  # Bundled dependencies:
30
+ ## @visulima/path
31
+ License: MIT
32
+ By: Daniel Bannert
33
+ Repository: git+https://github.com/visulima/visulima.git
34
+
35
+ > MIT License
36
+ >
37
+ > Copyright (c) 2024 visulima
38
+ >
39
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
40
+ > of this software and associated documentation files (the "Software"), to deal
41
+ > in the Software without restriction, including without limitation the rights
42
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
43
+ > copies of the Software, and to permit persons to whom the Software is
44
+ > furnished to do so, subject to the following conditions:
45
+ >
46
+ > The above copyright notice and this permission notice shall be included in all
47
+ > copies or substantial portions of the Software.
48
+ >
49
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
50
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
51
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
52
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
53
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
54
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
55
+ > SOFTWARE.
56
+ >
57
+ > ---
58
+ >
59
+ > MIT License
60
+ >
61
+ > Copyright (c) Pooya Parsa <pooya@pi0.io> - Daniel Roe <daniel@roe.dev>
62
+ >
63
+ > Permission is hereby granted, free of charge, to any person obtaining a copy
64
+ > of this software and associated documentation files (the "Software"), to deal
65
+ > in the Software without restriction, including without limitation the rights
66
+ > to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
67
+ > copies of the Software, and to permit persons to whom the Software is
68
+ > furnished to do so, subject to the following conditions:
69
+ >
70
+ > The above copyright notice and this permission notice shall be included in all
71
+ > copies or substantial portions of the Software.
72
+ >
73
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
74
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
75
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
76
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
77
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
78
+ > OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
79
+ > SOFTWARE.
80
+ >
81
+ > ---
82
+ >
83
+ > Copyright Joyent, Inc. and other Node contributors.
84
+ >
85
+ > Permission is hereby granted, free of charge, to any person obtaining a
86
+ > copy of this software and associated documentation files (the
87
+ > "Software"), to deal in the Software without restriction, including
88
+ > without limitation the rights to use, copy, modify, merge, publish,
89
+ > distribute, sublicense, and/or sell copies of the Software, and to permit
90
+ > persons to whom the Software is furnished to do so, subject to the
91
+ > following conditions:
92
+ >
93
+ > The above copyright notice and this permission notice shall be included
94
+ > in all copies or substantial portions of the Software.
95
+ >
96
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
97
+ > OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
98
+ > MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN
99
+ > NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
100
+ > DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
101
+ > OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE
102
+ > USE OR OTHER DEALINGS IN THE SOFTWARE.
103
+ >
104
+ > ---
105
+ >
106
+ > Bundled zeptomatch (https://github.com/fabiospampinato/zeptomatch)
107
+ >
108
+ > The MIT License (MIT)
109
+ >
110
+ > Copyright (c) 2023-present Fabio Spampinato
111
+ >
112
+ > Permission is hereby granted, free of charge, to any person obtaining a
113
+ > copy of this software and associated documentation files (the "Software"),
114
+ > to deal in the Software without restriction, including without limitation
115
+ > the rights to use, copy, modify, merge, publish, distribute, sublicense,
116
+ > and/or sell copies of the Software, and to permit persons to whom the
117
+ > Software is furnished to do so, subject to the following conditions:
118
+ >
119
+ > The above copyright notice and this permission notice shall be included in
120
+ > all copies or substantial portions of the Software.
121
+ >
122
+ > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
123
+ > IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
124
+ > FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
125
+ > AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
126
+ > LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
127
+ > FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
128
+ > DEALINGS IN THE SOFTWARE.
129
+ >
130
+ >
131
+ >
132
+ > # Licenses of bundled dependencies
133
+ > The published @visulima/path artifact additionally contains code with the following licenses:
134
+ > MIT
135
+ >
136
+ > # Bundled dependencies:
137
+ > ## binary-extensions
138
+ > License: MIT
139
+ > By: Sindre Sorhus
140
+ > Repository: sindresorhus/binary-extensions
141
+ >
142
+ > > MIT License
143
+ > >
144
+ > > Copyright (c) Sindre Sorhus <sindresorhus@gmail.com> (https://sindresorhus.com)
145
+ > > Copyright (c) Paul Miller (https://paulmillr.com)
146
+ > >
147
+ > > Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
148
+ > >
149
+ > > The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
150
+ > >
151
+ > > THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
152
+
153
+ ---------------------------------------
154
+
30
155
  ## is-plain-obj
31
156
  License: MIT
32
157
  By: Sindre Sorhus
package/README.md CHANGED
@@ -39,6 +39,21 @@ yarn add @visulima/error
39
39
  pnpm add @visulima/error
40
40
  ```
41
41
 
42
+ ### Optional: AI integration
43
+
44
+ If you want to generate AI-powered solution hints, install these optional peer dependencies in your app:
45
+
46
+ ```sh
47
+ # pnpm
48
+ pnpm add ai
49
+
50
+ # npm
51
+ npm i ai
52
+
53
+ # yarn
54
+ yarn add ai
55
+ ```
56
+
42
57
  ## Usage
43
58
 
44
59
  ### Extend the VisulimaError
@@ -228,6 +243,109 @@ console.log(stack);
228
243
  // ];
229
244
  ```
230
245
 
246
+ ### Format stacktrace to a string
247
+
248
+ Turn parsed frames into a printable stack string (Node-style), optionally with a header line.
249
+
250
+ ```ts
251
+ import { parseStacktrace, stringifyStackFrames, formatStackFrameLine } from "@visulima/error";
252
+
253
+ const error = new Error("Boom");
254
+
255
+ const frames = parseStacktrace(error);
256
+
257
+ // Full stack as a single string with a header ("Error: Boom")
258
+ const stackText = stringifyStackFrames(frames, {
259
+ header: { name: error.name, message: error.message },
260
+ });
261
+ console.log(stackText);
262
+
263
+ // Format a single frame line (e.g., for custom rendering)
264
+ const firstLine = formatStackFrameLine(frames[0]);
265
+ ```
266
+
267
+ #### API
268
+
269
+ - `stringifyStackFrames(frames, options?)`
270
+ - `frames`: `Trace[]` — parsed frames from `parseStacktrace`
271
+ - `options.header`: `{ name?: string; message?: string }` — optional first-line header
272
+ - `formatStackFrameLine(frame)`
273
+ - `frame`: `Trace`
274
+ - returns a single formatted line like `" at myMethod (/path/file.ts:10:5)"`
275
+
276
+ ## Solutions (finders)
277
+
278
+ Generate helpful hints to fix an error. Two finders ship out of the box:
279
+
280
+ - Rule-based finder: provides best-effort fixes for common errors (ESM/CJS mix, missing default export, DNS issues, hydration mismatch, etc.)
281
+ - Error-hint finder: reads `error.hint` you attach to an `Error` or `VisulimaError`
282
+
283
+ Both return a `Solution` (`{ header?: string; body: string }`) or `undefined`.
284
+
285
+ ```ts
286
+ import { codeFrame } from "@visulima/error";
287
+ import { ruleBasedFinder, errorHintFinder } from "@visulima/error";
288
+
289
+ const error = new Error("Cannot read properties of undefined (reading 'x')");
290
+
291
+ const source = "const o = undefined\nconsole.log(o.x)\n";
292
+ const snippet = codeFrame(source, { start: { line: 2, column: 13 } });
293
+
294
+ const fileCtx = {
295
+ file: "/path/to/file.ts",
296
+ line: 2,
297
+ language: "ts",
298
+ snippet,
299
+ };
300
+
301
+ // 1) Rule-based finder
302
+ const ruleHint = await ruleBasedFinder.handle(error, fileCtx);
303
+ if (ruleHint) {
304
+ console.log(ruleHint.header);
305
+ console.log(ruleHint.body);
306
+ }
307
+
308
+ // 2) Error-hint finder (reads error.hint)
309
+ const custom = new Error("failed") as Error & { hint?: unknown };
310
+ custom.hint = ["Check the environment variables.", "Ensure the service is reachable."];
311
+ const hintHint = await errorHintFinder.handle(custom, { file: "", line: 0 });
312
+ ```
313
+
314
+ ### AI solution helper (optional)
315
+
316
+ You can build an AI prompt with rich context and render the LLM result into a nice HTML snippet.
317
+
318
+ ```ts
319
+ import { aiPrompt, aiSolutionResponse } from "@visulima/error/solution/ai";
320
+ // or
321
+ // import aiPrompt from "@visulima/error/solution/ai/prompt";
322
+
323
+ const prompt = aiPrompt({
324
+ applicationType: undefined,
325
+ error,
326
+ file: fileCtx,
327
+ });
328
+
329
+ // Send `prompt` to your LLM of choice.
330
+ // When you receive the model's text output, format it for display:
331
+ const html = aiSolutionResponse(modelText);
332
+ ```
333
+
334
+ You may also use a convenience finder that calls an AI provider for you (requires optional peer dep `ai`):
335
+
336
+ ```ts
337
+ import { aiFinder } from "@visulima/error/solution/ai";
338
+ import { createOpenAI } from "@ai-sdk/openai";
339
+
340
+ const client = createOpenAI(apiKey ? { apiKey } : undefined);
341
+
342
+ const findAI = aiFinder(client(modelId), {
343
+ temperature: 0,
344
+ });
345
+
346
+ const aiHint = await findAI.handle(error, fileCtx);
347
+ ```
348
+
231
349
  ### API
232
350
 
233
351
  #### error
package/dist/index.cjs CHANGED
@@ -4,18 +4,27 @@ Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toString
4
4
 
5
5
  const codeFrame_index = require('./code-frame/index.cjs');
6
6
  const indexToLineColumn = require('./packem_shared/indexToLineColumn-DjmjeiIY.cjs');
7
+ const solution_ai_aiPrompt = require('./solution/ai/ai-prompt.cjs');
8
+ const aiSolutionResponse = require('./packem_shared/aiSolutionResponse-BPckbL56.cjs');
9
+ const errorHintFinder = require('./packem_shared/errorHintFinder-DZugFHq0.cjs');
10
+ const ruleBasedFinder = require('./packem_shared/ruleBasedFinder-y_-5kbeT.cjs');
7
11
  const captureRawStackTrace = require('./packem_shared/captureRawStackTrace-ClSI1tHb.cjs');
8
12
  const getErrorCauses = require('./packem_shared/getErrorCauses-miTeYJEG.cjs');
9
13
  const parseStacktrace = require('./packem_shared/parseStacktrace-6pFoXW43.cjs');
10
14
  const isVisulimaError = require('./packem_shared/isVisulimaError-BVLWvREw.cjs');
11
15
  const renderError = require('./packem_shared/renderError-CXZTAXig.cjs');
12
16
  const serializeError = require('./packem_shared/serializeError-CT7s0Ffk.cjs');
17
+ const formatStackFrameLine = require('./packem_shared/formatStackFrameLine-DcXSX--m.cjs');
13
18
 
14
19
 
15
20
 
16
21
  exports.CODE_FRAME_POINTER = codeFrame_index.CODE_FRAME_POINTER;
17
22
  exports.codeFrame = codeFrame_index.codeFrame;
18
23
  exports.indexToLineColumn = indexToLineColumn;
24
+ exports.aiPrompt = solution_ai_aiPrompt;
25
+ exports.aiSolutionResponse = aiSolutionResponse;
26
+ exports.errorHintFinder = errorHintFinder;
27
+ exports.ruleBasedFinder = ruleBasedFinder;
19
28
  exports.captureRawStackTrace = captureRawStackTrace;
20
29
  exports.getErrorCauses = getErrorCauses;
21
30
  exports.parseStacktrace = parseStacktrace;
@@ -23,3 +32,5 @@ exports.VisulimaError = isVisulimaError.VisulimaError;
23
32
  exports.isVisulimaError = isVisulimaError.isVisulimaError;
24
33
  exports.renderError = renderError.renderError;
25
34
  exports.serializeError = serializeError.serialize;
35
+ exports.formatStackFrameLine = formatStackFrameLine.formatStackFrameLine;
36
+ 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 { 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';
2
6
  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';
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 { 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';
2
6
  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';
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 { 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';
2
6
  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';
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,13 @@
1
1
  export { CODE_FRAME_POINTER, codeFrame } from './code-frame/index.mjs';
2
2
  export { default as indexToLineColumn } from './packem_shared/indexToLineColumn-Dx91YDU1.mjs';
3
+ export { default as aiPrompt } from './solution/ai/ai-prompt.mjs';
4
+ export { default as aiSolutionResponse } from './packem_shared/aiSolutionResponse-bDi4ad8f.mjs';
5
+ export { default as errorHintFinder } from './packem_shared/errorHintFinder-CQy_qIK3.mjs';
6
+ export { default as ruleBasedFinder } from './packem_shared/ruleBasedFinder-BYrndubA.mjs';
3
7
  export { default as captureRawStackTrace } from './packem_shared/captureRawStackTrace-Tl3Rqkat.mjs';
4
8
  export { default as getErrorCauses } from './packem_shared/getErrorCauses-CG_JRE6j.mjs';
5
9
  export { default as parseStacktrace } from './packem_shared/parseStacktrace-BKGoWCwC.mjs';
6
10
  export { VisulimaError, isVisulimaError } from './packem_shared/isVisulimaError-H6TqEA42.mjs';
7
11
  export { renderError } from './packem_shared/renderError-BWpM2m6k.mjs';
8
12
  export { serialize as serializeError } from './packem_shared/serializeError-DusTUACt.mjs';
13
+ export { formatStackFrameLine, formatStacktrace } from './packem_shared/formatStackFrameLine-DqkmKWH3.mjs';
@@ -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,263 @@
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;