ai-error-solution 1.1.2 β†’ 1.1.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (3) hide show
  1. package/CHANGELOG.md +26 -1
  2. package/README.md +400 -400
  3. package/package.json +44 -39
package/CHANGELOG.md CHANGED
@@ -5,6 +5,29 @@ All notable changes to this project will be documented in this file.
5
5
  The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
+ ## [1.1.4] - 2025-12-31
9
+
10
+ ### Fixed
11
+ - GitHub Packages now published with public access (was private by default)
12
+
13
+ ### Changed
14
+ - Updated publish scripts to include --access=public flag
15
+
16
+ ---
17
+
18
+ ## [1.1.3] - 2025-12-31
19
+
20
+ ### Added
21
+ - Dual registry publishing support (npm + GitHub Packages)
22
+ - Automated publish scripts for both registries
23
+ - .npmrc configuration for registry management
24
+
25
+ ### Changed
26
+ - Enhanced package.json with publishConfig
27
+ - Added convenience npm scripts for publishing
28
+
29
+ ---
30
+
8
31
  ## [1.1.2] - 2025-12-31
9
32
 
10
33
  ### Fixed
@@ -73,8 +96,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
73
96
 
74
97
  ## Version History
75
98
 
99
+ - **1.1.4** (2025-12-31) - GitHub Packages now public
100
+ - **1.1.3** (2025-12-31) - Dual registry support (npm + GitHub Packages)
76
101
  - **1.1.2** (2025-12-31) - Bug fixes and optimization
77
- - **1.1.1** (2025-12-31) - Already published (updated author info)
102
+ - **1.1.1** (2025-12-31) - Updated author info
78
103
  - **1.0.0** (2025-12-31) - Initial release
79
104
 
80
105
  ---
package/README.md CHANGED
@@ -1,400 +1,400 @@
1
- # πŸ€– ai-error-solution
2
-
3
- **Lightweight, AI-powered error analysis for Node.js**
4
-
5
- Automatically capture runtime errors and get instant AI-generated explanations, causes, fixes, and documentation linksβ€”all in your console.
6
-
7
- [![npm version](https://img.shields.io/npm/v/ai-error-solution.svg)](https://www.npmjs.com/package/ai-error-solution)
8
- [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
- [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org)
10
-
11
- ---
12
-
13
- ## ✨ Features
14
-
15
- - 🎯 **Zero Dependencies** - Uses native `curl` via `child_process` (no heavy HTTP libraries)
16
- - πŸš€ **Lightweight** - Minimal package size, maximum efficiency
17
- - 🧠 **AI-Powered Analysis** - Leverages OpenAI to explain errors in plain English
18
- - πŸ” **Privacy-First** - No telemetry, no data storage, direct API calls only
19
- - ⚑ **ESM Native** - Modern ES Module support
20
- - 🎨 **Beautiful Output** - Clean, colorized console logging
21
- - πŸ› οΈ **Production-Ready** - Timeout handling, retries, graceful failures
22
-
23
- ---
24
-
25
- ## πŸ“¦ Installation
26
-
27
- ```bash
28
- npm install ai-error-solution
29
- ```
30
-
31
- **Requirements:**
32
- - Node.js 18 or higher
33
- - `curl` installed on your system (usually pre-installed on macOS/Linux, available on Windows)
34
- - OpenAI API key ([get one here](https://platform.openai.com/api-keys))
35
-
36
- ---
37
-
38
- ## πŸš€ Quick Start
39
-
40
- ### 1. Initialize Once
41
-
42
- Set up the package with your OpenAI API key in your main application file:
43
-
44
- ```javascript
45
- import { initAutoErrorSolution, fixError } from 'ai-error-solution';
46
-
47
- // Initialize with your API key (do this once at app startup)
48
- initAutoErrorSolution({
49
- apiKey: process.env.OPENAI_API_KEY,
50
- model: 'gpt-4o-mini' // Optional: defaults to gpt-4o-mini
51
- });
52
- ```
53
-
54
- ### 2. Use Anywhere
55
-
56
- Wrap your error handling with `fixError()`:
57
-
58
- ```javascript
59
- try {
60
- // Your code that might throw errors
61
- const result = riskyFunction();
62
- } catch (err) {
63
- // Get AI-powered analysis
64
- await fixError(err);
65
- }
66
- ```
67
-
68
- ### 3. Enjoy AI-Powered Debugging! πŸŽ‰
69
-
70
- You'll see beautiful, formatted output like this:
71
-
72
- ```
73
- ================================================================================
74
- ❌ Error Detected: TypeError
75
- Cannot read property 'map' of undefined
76
-
77
- 🧠 AI Explanation:
78
- This error occurs when you try to call the .map() method on a variable
79
- that is undefined. The JavaScript engine expected an array but received
80
- undefined instead.
81
-
82
- ⚠️ Likely Causes:
83
- - The variable was never initialized
84
- - An async function hasn't resolved yet
85
- - The API response didn't include expected data
86
-
87
- πŸ”§ Suggested Fixes:
88
- - Add optional chaining: data?.map(...)
89
- - Provide a default value: (data || []).map(...)
90
- - Check existence first: if (data) { data.map(...) }
91
-
92
- πŸ“š References:
93
- - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors
94
- - https://javascript.info/optional-chaining
95
-
96
- πŸ’‘ Note: AI suggestions may not be 100% accurate. Always verify fixes before applying.
97
- ================================================================================
98
- ```
99
-
100
- ---
101
-
102
- ## πŸ“– API Reference
103
-
104
- ### `initAutoErrorSolution(options)`
105
-
106
- Initialize the package with your OpenAI credentials. **Must be called before using `fixError()`.**
107
-
108
- **Parameters:**
109
- - `options.apiKey` (string, **required**) - Your OpenAI API key
110
- - `options.model` (string, optional) - OpenAI model to use (default: `'gpt-4o-mini'`)
111
- - `options.timeout` (number, optional) - API request timeout in milliseconds (default: `30000`)
112
- - `options.maxRetries` (number, optional) - Maximum retry attempts (default: `1`)
113
-
114
- **Example:**
115
- ```javascript
116
- initAutoErrorSolution({
117
- apiKey: process.env.OPENAI_API_KEY,
118
- model: 'gpt-4o-mini',
119
- timeout: 30000,
120
- maxRetries: 2
121
- });
122
- ```
123
-
124
- ---
125
-
126
- ### `fixError(error, options)`
127
-
128
- Analyze an error using OpenAI and display formatted results.
129
-
130
- **Parameters:**
131
- - `error` (Error | string, **required**) - Error object or error message
132
- - `options.silent` (boolean, optional) - Return analysis without logging (default: `false`)
133
-
134
- **Returns:**
135
- - `Promise<null>` - When logging to console (default)
136
- - `Promise<Object>` - When `silent: true`, returns analysis object
137
-
138
- **Example:**
139
- ```javascript
140
- // Standard usage (logs to console)
141
- try {
142
- dangerousCode();
143
- } catch (err) {
144
- await fixError(err);
145
- }
146
-
147
- // Silent mode (returns data)
148
- const analysis = await fixError(err, { silent: true });
149
- console.log(analysis.analysis.explanation);
150
- ```
151
-
152
- ---
153
-
154
- ### `wrapWithErrorHandler(fn)`
155
-
156
- Wrap a function with automatic error handling.
157
-
158
- **Parameters:**
159
- - `fn` (Function) - Function to wrap
160
-
161
- **Returns:**
162
- - `Function` - Wrapped function that automatically calls `fixError()` on errors
163
-
164
- **Example:**
165
- ```javascript
166
- const safeFunction = wrapWithErrorHandler(async () => {
167
- // Code that might throw
168
- return await riskyOperation();
169
- });
170
-
171
- await safeFunction(); // Errors automatically analyzed
172
- ```
173
-
174
- ---
175
-
176
- ### `setupGlobalHandler(options)`
177
-
178
- Register global handlers for uncaught exceptions and unhandled promise rejections.
179
-
180
- **Parameters:**
181
- - `options.exitOnError` (boolean, optional) - Exit process after handling error (default: `false`)
182
-
183
- **Example:**
184
- ```javascript
185
- setupGlobalHandler({ exitOnError: true });
186
-
187
- // Now all uncaught errors will be automatically analyzed
188
- throw new Error('This will be caught and analyzed');
189
- ```
190
-
191
- ---
192
-
193
- ## πŸ” Environment Setup
194
-
195
- ### Using .env file (Recommended)
196
-
197
- 1. Install dotenv:
198
- ```bash
199
- npm install dotenv
200
- ```
201
-
202
- 2. Create `.env`:
203
- ```env
204
- OPENAI_API_KEY=sk-your-api-key-here
205
- ```
206
-
207
- 3. Load in your app:
208
- ```javascript
209
- import 'dotenv/config';
210
- import { initAutoErrorSolution } from 'ai-error-solution';
211
-
212
- initAutoErrorSolution({
213
- apiKey: process.env.OPENAI_API_KEY
214
- });
215
- ```
216
-
217
- ### Using environment variables directly
218
-
219
- ```bash
220
- # Linux/macOS
221
- export OPENAI_API_KEY=sk-your-api-key-here
222
- node app.js
223
-
224
- # Windows (PowerShell)
225
- $env:OPENAI_API_KEY="sk-your-api-key-here"
226
- node app.js
227
-
228
- # Windows (CMD)
229
- set OPENAI_API_KEY=sk-your-api-key-here
230
- node app.js
231
- ```
232
-
233
- ---
234
-
235
- ## 🎯 Use Cases
236
-
237
- ### Express.js Error Middleware
238
-
239
- ```javascript
240
- import express from 'express';
241
- import { initAutoErrorSolution, fixError } from 'ai-error-solution';
242
-
243
- const app = express();
244
-
245
- initAutoErrorSolution({
246
- apiKey: process.env.OPENAI_API_KEY
247
- });
248
-
249
- // Error handling middleware
250
- app.use(async (err, req, res, next) => {
251
- await fixError(err);
252
- res.status(500).json({ error: 'Internal Server Error' });
253
- });
254
- ```
255
-
256
- ### Async Function Wrapper
257
-
258
- ```javascript
259
- const fetchUserData = wrapWithErrorHandler(async (userId) => {
260
- const response = await fetch(`/api/users/${userId}`);
261
- return response.json();
262
- });
263
-
264
- // Automatically analyzes errors
265
- await fetchUserData(123);
266
- ```
267
-
268
- ### Global Error Catching
269
-
270
- ```javascript
271
- import { initAutoErrorSolution, setupGlobalHandler } from 'ai-error-solution';
272
-
273
- initAutoErrorSolution({
274
- apiKey: process.env.OPENAI_API_KEY
275
- });
276
-
277
- setupGlobalHandler({ exitOnError: false });
278
-
279
- // All uncaught errors are now automatically analyzed
280
- ```
281
-
282
- ---
283
-
284
- ## ⚠️ Important Notes
285
-
286
- ### Disclaimers
287
-
288
- - **AI Accuracy**: AI-generated suggestions may not always be correct. Always verify fixes before applying them to production code.
289
- - **API Costs**: Each error analysis makes an API call to OpenAI, which incurs costs based on your OpenAI plan.
290
- - **Privacy**: Error messages and stack traces are sent to OpenAI for analysis. Do not use in production if your errors may contain sensitive data.
291
- - **curl Dependency**: This package requires `curl` to be installed and accessible in your system PATH.
292
-
293
- ### Best Practices
294
-
295
- - βœ… Use in **development** and **debugging** environments
296
- - βœ… Store API keys in environment variables (never commit them)
297
- - βœ… Set reasonable timeout values for production environments
298
- - βœ… Review AI suggestions before implementing fixes
299
-
300
- ---
301
-
302
- ## πŸ—οΈ Architecture
303
-
304
- This package is built with **zero dependencies** and uses:
305
-
306
- - **ESM** - Modern ES Module system
307
- - **Native curl** - No heavy HTTP libraries (axios, node-fetch, etc.)
308
- - **child_process** - Native Node.js process execution
309
- - **Middleware pattern** - One-time API key initialization
310
-
311
- **Why curl?**
312
- - Minimal package size
313
- - No dependency vulnerabilities
314
- - Universal availability across platforms
315
- - Direct OpenAI API communication
316
-
317
- ---
318
-
319
- ## πŸ› οΈ Troubleshooting
320
-
321
- ### "curl is not installed or not in PATH"
322
-
323
- **Solution**: Install curl on your system.
324
-
325
- ```bash
326
- # macOS (via Homebrew)
327
- brew install curl
328
-
329
- # Ubuntu/Debian
330
- sudo apt-get install curl
331
-
332
- # Windows (via Chocolatey)
333
- choco install curl
334
-
335
- # Windows (built-in on Windows 10+)
336
- # curl should already be available
337
- ```
338
-
339
- ### "Package not initialized"
340
-
341
- **Solution**: Make sure you call `initAutoErrorSolution()` before using `fixError()`.
342
-
343
- ### "OpenAI API request timed out"
344
-
345
- **Solution**: Increase timeout or check your internet connection.
346
-
347
- ```javascript
348
- initAutoErrorSolution({
349
- apiKey: process.env.OPENAI_API_KEY,
350
- timeout: 60000 // 60 seconds
351
- });
352
- ```
353
-
354
- ### "OpenAI API error: Invalid API key"
355
-
356
- **Solution**: Verify your API key is correct and has sufficient credits.
357
-
358
- ---
359
-
360
- ## πŸ“„ License
361
-
362
- MIT Β© [Your Name]
363
-
364
- ---
365
-
366
- ## 🀝 Contributing
367
-
368
- Contributions are welcome! Please feel free to submit a Pull Request.
369
-
370
- ---
371
-
372
- ## πŸ”— Links
373
-
374
- - [npm Package](https://www.npmjs.com/package/ai-error-solution)
375
- - [GitHub Repository](https://github.com/Rashidqf/ai-error-solution)
376
- - [OpenAI API Documentation](https://platform.openai.com/docs)
377
- - [Report Issues](https://github.com/Rashidqf/ai-error-solution/issues)
378
-
379
- ---
380
-
381
-
382
- ## 🌟 Why This Package?
383
-
384
- Most error analysis tools either:
385
- - Require heavy dependencies (bloated package size)
386
- - Send data to third-party services (privacy concerns)
387
- - Auto-modify code (risky in production)
388
-
389
- **ai-error-solution** is different:
390
- - βœ… **Lightweight** - No dependencies, tiny package size
391
- - βœ… **Private** - Direct API calls, no intermediaries
392
- - βœ… **Safe** - Never modifies your code
393
- - βœ… **Transparent** - Open source, audit the code yourself
394
-
395
- ---
396
-
397
- **Made with ❀️ for developers who value simplicity and privacy**
398
-
399
- *Star ⭐ this project if you find it helpful!*
400
-
1
+ # πŸ€– ai-error-solution
2
+
3
+ **Lightweight, AI-powered error analysis for Node.js**
4
+
5
+ Automatically capture runtime errors and get instant AI-generated explanations, causes, fixes, and documentation linksβ€”all in your console.
6
+
7
+ [![npm version](https://img.shields.io/npm/v/ai-error-solution.svg)](https://www.npmjs.com/package/ai-error-solution)
8
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
9
+ [![Node.js Version](https://img.shields.io/badge/node-%3E%3D18.0.0-brightgreen)](https://nodejs.org)
10
+
11
+ ---
12
+
13
+ ## ✨ Features
14
+
15
+ - 🎯 **Zero Dependencies** - Uses native `curl` via `child_process` (no heavy HTTP libraries)
16
+ - πŸš€ **Lightweight** - Minimal package size, maximum efficiency
17
+ - 🧠 **AI-Powered Analysis** - Leverages OpenAI to explain errors in plain English
18
+ - πŸ” **Privacy-First** - No telemetry, no data storage, direct API calls only
19
+ - ⚑ **ESM Native** - Modern ES Module support
20
+ - 🎨 **Beautiful Output** - Clean, colorized console logging
21
+ - πŸ› οΈ **Production-Ready** - Timeout handling, retries, graceful failures
22
+
23
+ ---
24
+
25
+ ## πŸ“¦ Installation
26
+
27
+ ```bash
28
+ npm install ai-error-solution
29
+ ```
30
+
31
+ **Requirements:**
32
+ - Node.js 18 or higher
33
+ - `curl` installed on your system (usually pre-installed on macOS/Linux, available on Windows)
34
+ - OpenAI API key ([get one here](https://platform.openai.com/api-keys))
35
+
36
+ ---
37
+
38
+ ## πŸš€ Quick Start
39
+
40
+ ### 1. Initialize Once
41
+
42
+ Set up the package with your OpenAI API key in your main application file:
43
+
44
+ ```javascript
45
+ import { initAutoErrorSolution, fixError } from 'ai-error-solution';
46
+
47
+ // Initialize with your API key (do this once at app startup)
48
+ initAutoErrorSolution({
49
+ apiKey: process.env.OPENAI_API_KEY,
50
+ model: 'gpt-4o-mini' // Optional: defaults to gpt-4o-mini
51
+ });
52
+ ```
53
+
54
+ ### 2. Use Anywhere
55
+
56
+ Wrap your error handling with `fixError()`:
57
+
58
+ ```javascript
59
+ try {
60
+ // Your code that might throw errors
61
+ const result = riskyFunction();
62
+ } catch (err) {
63
+ // Get AI-powered analysis
64
+ await fixError(err);
65
+ }
66
+ ```
67
+
68
+ ### 3. Enjoy AI-Powered Debugging! πŸŽ‰
69
+
70
+ You'll see beautiful, formatted output like this:
71
+
72
+ ```
73
+ ================================================================================
74
+ ❌ Error Detected: TypeError
75
+ Cannot read property 'map' of undefined
76
+
77
+ 🧠 AI Explanation:
78
+ This error occurs when you try to call the .map() method on a variable
79
+ that is undefined. The JavaScript engine expected an array but received
80
+ undefined instead.
81
+
82
+ ⚠️ Likely Causes:
83
+ - The variable was never initialized
84
+ - An async function hasn't resolved yet
85
+ - The API response didn't include expected data
86
+
87
+ πŸ”§ Suggested Fixes:
88
+ - Add optional chaining: data?.map(...)
89
+ - Provide a default value: (data || []).map(...)
90
+ - Check existence first: if (data) { data.map(...) }
91
+
92
+ πŸ“š References:
93
+ - https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Errors
94
+ - https://javascript.info/optional-chaining
95
+
96
+ πŸ’‘ Note: AI suggestions may not be 100% accurate. Always verify fixes before applying.
97
+ ================================================================================
98
+ ```
99
+
100
+ ---
101
+
102
+ ## πŸ“– API Reference
103
+
104
+ ### `initAutoErrorSolution(options)`
105
+
106
+ Initialize the package with your OpenAI credentials. **Must be called before using `fixError()`.**
107
+
108
+ **Parameters:**
109
+ - `options.apiKey` (string, **required**) - Your OpenAI API key
110
+ - `options.model` (string, optional) - OpenAI model to use (default: `'gpt-4o-mini'`)
111
+ - `options.timeout` (number, optional) - API request timeout in milliseconds (default: `30000`)
112
+ - `options.maxRetries` (number, optional) - Maximum retry attempts (default: `1`)
113
+
114
+ **Example:**
115
+ ```javascript
116
+ initAutoErrorSolution({
117
+ apiKey: process.env.OPENAI_API_KEY,
118
+ model: 'gpt-4o-mini',
119
+ timeout: 30000,
120
+ maxRetries: 2
121
+ });
122
+ ```
123
+
124
+ ---
125
+
126
+ ### `fixError(error, options)`
127
+
128
+ Analyze an error using OpenAI and display formatted results.
129
+
130
+ **Parameters:**
131
+ - `error` (Error | string, **required**) - Error object or error message
132
+ - `options.silent` (boolean, optional) - Return analysis without logging (default: `false`)
133
+
134
+ **Returns:**
135
+ - `Promise<null>` - When logging to console (default)
136
+ - `Promise<Object>` - When `silent: true`, returns analysis object
137
+
138
+ **Example:**
139
+ ```javascript
140
+ // Standard usage (logs to console)
141
+ try {
142
+ dangerousCode();
143
+ } catch (err) {
144
+ await fixError(err);
145
+ }
146
+
147
+ // Silent mode (returns data)
148
+ const analysis = await fixError(err, { silent: true });
149
+ console.log(analysis.analysis.explanation);
150
+ ```
151
+
152
+ ---
153
+
154
+ ### `wrapWithErrorHandler(fn)`
155
+
156
+ Wrap a function with automatic error handling.
157
+
158
+ **Parameters:**
159
+ - `fn` (Function) - Function to wrap
160
+
161
+ **Returns:**
162
+ - `Function` - Wrapped function that automatically calls `fixError()` on errors
163
+
164
+ **Example:**
165
+ ```javascript
166
+ const safeFunction = wrapWithErrorHandler(async () => {
167
+ // Code that might throw
168
+ return await riskyOperation();
169
+ });
170
+
171
+ await safeFunction(); // Errors automatically analyzed
172
+ ```
173
+
174
+ ---
175
+
176
+ ### `setupGlobalHandler(options)`
177
+
178
+ Register global handlers for uncaught exceptions and unhandled promise rejections.
179
+
180
+ **Parameters:**
181
+ - `options.exitOnError` (boolean, optional) - Exit process after handling error (default: `false`)
182
+
183
+ **Example:**
184
+ ```javascript
185
+ setupGlobalHandler({ exitOnError: true });
186
+
187
+ // Now all uncaught errors will be automatically analyzed
188
+ throw new Error('This will be caught and analyzed');
189
+ ```
190
+
191
+ ---
192
+
193
+ ## πŸ” Environment Setup
194
+
195
+ ### Using .env file (Recommended)
196
+
197
+ 1. Install dotenv:
198
+ ```bash
199
+ npm install dotenv
200
+ ```
201
+
202
+ 2. Create `.env`:
203
+ ```env
204
+ OPENAI_API_KEY=sk-your-api-key-here
205
+ ```
206
+
207
+ 3. Load in your app:
208
+ ```javascript
209
+ import 'dotenv/config';
210
+ import { initAutoErrorSolution } from 'ai-error-solution';
211
+
212
+ initAutoErrorSolution({
213
+ apiKey: process.env.OPENAI_API_KEY
214
+ });
215
+ ```
216
+
217
+ ### Using environment variables directly
218
+
219
+ ```bash
220
+ # Linux/macOS
221
+ export OPENAI_API_KEY=sk-your-api-key-here
222
+ node app.js
223
+
224
+ # Windows (PowerShell)
225
+ $env:OPENAI_API_KEY="sk-your-api-key-here"
226
+ node app.js
227
+
228
+ # Windows (CMD)
229
+ set OPENAI_API_KEY=sk-your-api-key-here
230
+ node app.js
231
+ ```
232
+
233
+ ---
234
+
235
+ ## 🎯 Use Cases
236
+
237
+ ### Express.js Error Middleware
238
+
239
+ ```javascript
240
+ import express from 'express';
241
+ import { initAutoErrorSolution, fixError } from 'ai-error-solution';
242
+
243
+ const app = express();
244
+
245
+ initAutoErrorSolution({
246
+ apiKey: process.env.OPENAI_API_KEY
247
+ });
248
+
249
+ // Error handling middleware
250
+ app.use(async (err, req, res, next) => {
251
+ await fixError(err);
252
+ res.status(500).json({ error: 'Internal Server Error' });
253
+ });
254
+ ```
255
+
256
+ ### Async Function Wrapper
257
+
258
+ ```javascript
259
+ const fetchUserData = wrapWithErrorHandler(async (userId) => {
260
+ const response = await fetch(`/api/users/${userId}`);
261
+ return response.json();
262
+ });
263
+
264
+ // Automatically analyzes errors
265
+ await fetchUserData(123);
266
+ ```
267
+
268
+ ### Global Error Catching
269
+
270
+ ```javascript
271
+ import { initAutoErrorSolution, setupGlobalHandler } from 'ai-error-solution';
272
+
273
+ initAutoErrorSolution({
274
+ apiKey: process.env.OPENAI_API_KEY
275
+ });
276
+
277
+ setupGlobalHandler({ exitOnError: false });
278
+
279
+ // All uncaught errors are now automatically analyzed
280
+ ```
281
+
282
+ ---
283
+
284
+ ## ⚠️ Important Notes
285
+
286
+ ### Disclaimers
287
+
288
+ - **AI Accuracy**: AI-generated suggestions may not always be correct. Always verify fixes before applying them to production code.
289
+ - **API Costs**: Each error analysis makes an API call to OpenAI, which incurs costs based on your OpenAI plan.
290
+ - **Privacy**: Error messages and stack traces are sent to OpenAI for analysis. Do not use in production if your errors may contain sensitive data.
291
+ - **curl Dependency**: This package requires `curl` to be installed and accessible in your system PATH.
292
+
293
+ ### Best Practices
294
+
295
+ - βœ… Use in **development** and **debugging** environments
296
+ - βœ… Store API keys in environment variables (never commit them)
297
+ - βœ… Set reasonable timeout values for production environments
298
+ - βœ… Review AI suggestions before implementing fixes
299
+
300
+ ---
301
+
302
+ ## πŸ—οΈ Architecture
303
+
304
+ This package is built with **zero dependencies** and uses:
305
+
306
+ - **ESM** - Modern ES Module system
307
+ - **Native curl** - No heavy HTTP libraries (axios, node-fetch, etc.)
308
+ - **child_process** - Native Node.js process execution
309
+ - **Middleware pattern** - One-time API key initialization
310
+
311
+ **Why curl?**
312
+ - Minimal package size
313
+ - No dependency vulnerabilities
314
+ - Universal availability across platforms
315
+ - Direct OpenAI API communication
316
+
317
+ ---
318
+
319
+ ## πŸ› οΈ Troubleshooting
320
+
321
+ ### "curl is not installed or not in PATH"
322
+
323
+ **Solution**: Install curl on your system.
324
+
325
+ ```bash
326
+ # macOS (via Homebrew)
327
+ brew install curl
328
+
329
+ # Ubuntu/Debian
330
+ sudo apt-get install curl
331
+
332
+ # Windows (via Chocolatey)
333
+ choco install curl
334
+
335
+ # Windows (built-in on Windows 10+)
336
+ # curl should already be available
337
+ ```
338
+
339
+ ### "Package not initialized"
340
+
341
+ **Solution**: Make sure you call `initAutoErrorSolution()` before using `fixError()`.
342
+
343
+ ### "OpenAI API request timed out"
344
+
345
+ **Solution**: Increase timeout or check your internet connection.
346
+
347
+ ```javascript
348
+ initAutoErrorSolution({
349
+ apiKey: process.env.OPENAI_API_KEY,
350
+ timeout: 60000 // 60 seconds
351
+ });
352
+ ```
353
+
354
+ ### "OpenAI API error: Invalid API key"
355
+
356
+ **Solution**: Verify your API key is correct and has sufficient credits.
357
+
358
+ ---
359
+
360
+ ## πŸ“„ License
361
+
362
+ MIT Β© [Your Name]
363
+
364
+ ---
365
+
366
+ ## 🀝 Contributing
367
+
368
+ Contributions are welcome! Please feel free to submit a Pull Request.
369
+
370
+ ---
371
+
372
+ ## πŸ”— Links
373
+
374
+ - [npm Package](https://www.npmjs.com/package/ai-error-solution)
375
+ - [GitHub Repository](https://github.com/Rashidqf/ai-error-solution)
376
+ - [OpenAI API Documentation](https://platform.openai.com/docs)
377
+ - [Report Issues](https://github.com/Rashidqf/ai-error-solution/issues)
378
+
379
+ ---
380
+
381
+
382
+ ## 🌟 Why This Package?
383
+
384
+ Most error analysis tools either:
385
+ - Require heavy dependencies (bloated package size)
386
+ - Send data to third-party services (privacy concerns)
387
+ - Auto-modify code (risky in production)
388
+
389
+ **ai-error-solution** is different:
390
+ - βœ… **Lightweight** - No dependencies, tiny package size
391
+ - βœ… **Private** - Direct API calls, no intermediaries
392
+ - βœ… **Safe** - Never modifies your code
393
+ - βœ… **Transparent** - Open source, audit the code yourself
394
+
395
+ ---
396
+
397
+ **Made with ❀️ for developers who value simplicity and privacy**
398
+
399
+ *Star ⭐ this project if you find it helpful!*
400
+
package/package.json CHANGED
@@ -1,39 +1,44 @@
1
- {
2
- "name": "ai-error-solution",
3
- "version": "1.1.2",
4
- "description": "Lightweight Node.js error handler that uses OpenAI to provide explanations, causes, fixes, and documentation links for runtime errors",
5
- "type": "module",
6
- "main": "src/index.js",
7
- "exports": {
8
- ".": "./src/index.js"
9
- },
10
- "engines": {
11
- "node": ">=18.0.0"
12
- },
13
- "scripts": {
14
- "test": "echo \"Error: no test specified\" && exit 1"
15
- },
16
- "keywords": [
17
- "error-handling",
18
- "debugging",
19
- "openai",
20
- "error-analysis",
21
- "ai-debugging",
22
- "error-solution",
23
- "runtime-errors",
24
- "stack-trace"
25
- ],
26
- "author": {
27
- "name": "Rashid",
28
- "url": "https://github.com/Rashidqf"
29
- },
30
- "license": "MIT",
31
- "repository": {
32
- "type": "git",
33
- "url": "git+https://github.com/Rashidqf/ai-error-solution.git"
34
- },
35
- "bugs": {
36
- "url": "https://github.com/Rashidqf/ai-error-solution/issues"
37
- },
38
- "homepage": "https://github.com/Rashidqf/ai-error-solution#readme"
39
- }
1
+ {
2
+ "name": "ai-error-solution",
3
+ "version": "1.1.4",
4
+ "description": "Lightweight Node.js error handler that uses OpenAI to provide explanations, causes, fixes, and documentation links for runtime errors",
5
+ "type": "module",
6
+ "main": "src/index.js",
7
+ "exports": {
8
+ ".": "./src/index.js"
9
+ },
10
+ "engines": {
11
+ "node": ">=18.0.0"
12
+ },
13
+ "scripts": {
14
+ "test": "echo \"Error: no test specified\" && exit 1",
15
+ "publish:npm": "npm publish --registry=https://registry.npmjs.org/",
16
+ "publish:github": "npm publish --registry=https://npm.pkg.github.com/"
17
+ },
18
+ "publishConfig": {
19
+ "registry": "https://registry.npmjs.org/"
20
+ },
21
+ "keywords": [
22
+ "error-handling",
23
+ "debugging",
24
+ "openai",
25
+ "error-analysis",
26
+ "ai-debugging",
27
+ "error-solution",
28
+ "runtime-errors",
29
+ "stack-trace"
30
+ ],
31
+ "author": {
32
+ "name": "Rashid",
33
+ "url": "https://github.com/Rashidqf"
34
+ },
35
+ "license": "MIT",
36
+ "repository": {
37
+ "type": "git",
38
+ "url": "git+https://github.com/Rashidqf/ai-error-solution.git"
39
+ },
40
+ "bugs": {
41
+ "url": "https://github.com/Rashidqf/ai-error-solution/issues"
42
+ },
43
+ "homepage": "https://github.com/Rashidqf/ai-error-solution#readme"
44
+ }