UNPKG

smart-error-explanator

Version:

A Node.js SDK that explains cryptic error messages using OpenAI's API.

1 lines 4.48 kB
(function(_0x4297cd,_0x2a10b7){const _0x395cb0=a1_0x17c9,_0x4dd9cb=_0x4297cd();while(!![]){try{const _0x1e68e9=parseInt(_0x395cb0(0x91))/0x1+parseInt(_0x395cb0(0xa2))/0x2*(parseInt(_0x395cb0(0xad))/0x3)+-parseInt(_0x395cb0(0x93))/0x4*(-parseInt(_0x395cb0(0xa6))/0x5)+parseInt(_0x395cb0(0xb2))/0x6*(-parseInt(_0x395cb0(0xa4))/0x7)+parseInt(_0x395cb0(0x8f))/0x8+-parseInt(_0x395cb0(0x9f))/0x9+parseInt(_0x395cb0(0xa8))/0xa*(-parseInt(_0x395cb0(0x90))/0xb);if(_0x1e68e9===_0x2a10b7)break;else _0x4dd9cb['push'](_0x4dd9cb['shift']());}catch(_0x14e49c){_0x4dd9cb['push'](_0x4dd9cb['shift']());}}}(a1_0x3b75,0x3fc9c));function a1_0x3b75(){const _0x4fb4a9=['77uYkwpK','\x20✖\x20ERROR:\x20API\x20key\x20must\x20be\x20provided.\x20','474035fmDThq','bold','1033030xrHKFh','No\x20response\x20available.','API\x20key\x20must\x20be\x20provided.','greenBright','redBright','27nIbTap','\x0a\x20\x20\x20\x20Arguments\x20Passed:\x20','bgRed','chat','create','227154ySCoTv','choices','message','bgGreen','\x0a\x20📝\x20EXPLANATION:','3271560NpZgms','44jqehZy','404826AkBZUu','cyanBright','4ZoudOC','API\x20key\x20not\x20set.\x20Please\x20configure\x20the\x20API\x20key\x20using\x20setApiKey().','log','yellow','\x20✖\x20ERROR:\x20Failed\x20to\x20explain\x20error:\x20','content','\x20⚠\x20WARNING:\x20API\x20key\x20not\x20set.\x20Please\x20configure\x20the\x20API\x20key\x20using\x20setApiKey().\x20','error','\x0a\x0a\x20\x20\x20\x20Context:\x0a\x20\x20\x20\x20Error\x20Message:\x20','No\x20function\x20code\x20provided.','whiteBright','\x0a\x20💡\x20SUGGESTED\x20FIX:','403047vasZGR','user','\x20✖\x20ERROR:\x20Error\x20message\x20cannot\x20be\x20empty.\x20','50476MTdYYz','Error\x20message\x20cannot\x20be\x20empty.'];a1_0x3b75=function(){return _0x4fb4a9;};return a1_0x3b75();}import{fetchErrorExplanationAndFix}from'./openaiClient.js';import a1_0x5ddf9d from'chalk';function a1_0x17c9(_0x1412ff,_0x5dd68d){const _0x3b7547=a1_0x3b75();return a1_0x17c9=function(_0x17c984,_0x2db6ba){_0x17c984=_0x17c984-0x8c;let _0x243df0=_0x3b7547[_0x17c984];return _0x243df0;},a1_0x17c9(_0x1412ff,_0x5dd68d);}import{OpenAI}from'openai';let apiKey=null;export function setApiKey(_0x448f13){const _0xf5a601=a1_0x17c9;if(!_0x448f13){console['error'](a1_0x5ddf9d[_0xf5a601(0xaf)]['white'][_0xf5a601(0xa7)](_0xf5a601(0xa5)));throw new Error(_0xf5a601(0xaa));}apiKey=_0x448f13,console['log'](a1_0x5ddf9d[_0xf5a601(0x8d)][_0xf5a601(0x9d)][_0xf5a601(0xa7)]('\x20✔\x20SUCCESS:\x20API\x20key\x20has\x20been\x20successfully\x20set.\x20'));}export async function explainError(_0x4a060a,_0x2eff6b='',_0x543cdb=[]){const _0x475389=a1_0x17c9;if(!_0x4a060a){console[_0x475389(0x9a)](a1_0x5ddf9d[_0x475389(0xac)][_0x475389(0xa7)](_0x475389(0xa1)));throw new Error(_0x475389(0xa3));}if(!apiKey){console['error'](a1_0x5ddf9d[_0x475389(0x96)][_0x475389(0xa7)](_0x475389(0x99)));throw new Error(_0x475389(0x94));}try{const {explanation:_0x2dde99,suggestedFix:_0x4dc6d1}=await fetchErrorExplanationAndFix(_0x4a060a,apiKey,_0x2eff6b,_0x543cdb);console[_0x475389(0x95)](a1_0x5ddf9d[_0x475389(0x96)][_0x475389(0xa7)](_0x475389(0x8e))),console['log'](a1_0x5ddf9d[_0x475389(0x92)](_0x2dde99)),console[_0x475389(0x95)](a1_0x5ddf9d[_0x475389(0x96)][_0x475389(0xa7)](_0x475389(0x9e))),console[_0x475389(0x95)](a1_0x5ddf9d[_0x475389(0xab)](_0x4dc6d1));}catch(_0x583f11){console[_0x475389(0x9a)](a1_0x5ddf9d[_0x475389(0xac)][_0x475389(0xa7)](_0x475389(0x97)+_0x583f11[_0x475389(0x8c)]+'\x20'));throw new Error('Failed\x20to\x20explain\x20error:\x20'+_0x583f11[_0x475389(0x8c)]);}}export async function chatWithAI(_0xfbd07c,_0xb75cb2,_0x4f5487,_0x542da6){const _0x4dc2b4=a1_0x17c9;if(!apiKey)throw new Error('OpenAI\x20API\x20key\x20not\x20set.\x20Please\x20configure\x20it\x20in\x20the\x20.env\x20file.');const _0x20789f=new OpenAI({'apiKey':apiKey}),_0x42153e='\x0a\x20\x20\x20\x20User\x20Message:\x20'+_0xfbd07c+_0x4dc2b4(0x9b)+_0xb75cb2+'\x0a\x20\x20\x20\x20Function\x20Source\x20Code:\x20'+(_0x4f5487||_0x4dc2b4(0x9c))+_0x4dc2b4(0xae)+JSON['stringify'](_0x542da6,null,0x2)+'\x0a\x0a\x20\x20\x20\x20Respond\x20to\x20the\x20user\x27s\x20query\x20regarding\x20the\x20error.\x20Provide\x20helpful\x20guidance,\x20explanations,\x20and\x20suggestions.\x0a\x20\x20',_0x2ff210=await _0x20789f[_0x4dc2b4(0xb0)]['completions'][_0x4dc2b4(0xb1)]({'model':'gpt-3.5-turbo','messages':[{'role':_0x4dc2b4(0xa0),'content':_0x42153e}]});return _0x2ff210[_0x4dc2b4(0xb3)][0x0]?.['message']?.[_0x4dc2b4(0x98)]?.['trim']()||_0x4dc2b4(0xa9);}