@visulima/cerebro 3.0.4 → 3.0.5

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.
@@ -0,0 +1,76 @@
1
+ import{t as P}from"./renderError-BISXNU8L-B47ZikMV.js";import{S as fe,W as pe,X as me,Y as de,G as ye,R as he}from"./renderError-BISXNU8L-B47ZikMV.js";import{h as be,c as ve}from"./VisulimaError-DTMgXonA-CzaryRgZ.js";const E=(e,r)=>{let t=0,n=r.length-2;for(;t<n;){const o=t+(n-t>>1);if(e<r[o])n=o-1;else if(e>=r[o+1])t=o+1;else{t=o;break}}return t},T=/\n|\r(?!\n)/,I=e=>e.split(T).reduce((r,t)=>(r.push(r.at(-1)+t.length+1),r),[0]),G=(e,r,t)=>{const n=t?.skipChecks??!1;if(!n&&(!Array.isArray(e)&&typeof e!="string"||(typeof e=="string"||Array.isArray(e))&&e.length===0))return{column:0,line:0};if(!n&&(typeof r!="number"||typeof e=="string"&&r>=e.length||Array.isArray(e)&&r+1>=e.at(-1)))return{column:0,line:0};if(typeof e=="string"){const a=I(e),s=E(r,a);return{column:r-a[s]+1,line:s+1}}const o=E(r,e);return{column:r-e[o]+1,line:o+1}},Q=({applicationType:e,error:r,file:t})=>`You are a very skilled ${t.language??"unknown"} programmer.
2
+
3
+ ${e?`You are working on a ${e} application.`:""}
4
+
5
+ Use the following context to find a possible fix for the exception message at the end. Limit your answer to 4 or 5 sentences. Also include a few links to documentation that might help.
6
+
7
+ Use this format in your answer, make sure links are json:
8
+
9
+ FIX
10
+ insert the possible fix here
11
+ ENDFIX
12
+ LINKS
13
+ {"title": "Title link 1", "url": "URL link 1"}
14
+ {"title": "Title link 2", "url": "URL link 2"}
15
+ ENDLINKS
16
+ ---
17
+
18
+ Here comes the context and the exception message:
19
+
20
+ Line: ${String(t.line)}
21
+
22
+ File:
23
+ ${t.file}
24
+
25
+ Snippet including line numbers:
26
+ ${t.snippet??""}
27
+
28
+ Exception class:
29
+ ${r.name}
30
+
31
+ Exception message:
32
+ ${r.message}`,d=e=>e.replaceAll("&","&amp;").replaceAll("<","&lt;").replaceAll(">","&gt;").replaceAll('"',"&quot;").replaceAll("'","&#39;"),_=e=>{try{const{protocol:r}=new URL(e);return r==="http:"||r==="https:"}catch{return!1}},$=(e,r,t)=>{const n=t.indexOf(e);if(n===-1)return"";const o=n+e.length,a=t.indexOf(r,o);return a===-1?"":t.slice(o,a).trim()},Z=e=>{const r=$("FIX","ENDFIX",e);if(!r)return["No solution found.",'Provide this response to the Maintainer of <a href="https://github.com/visulima/visulima/issues/new?assignees=&labels=s%3A+pending+triage%2Cc%3A+bug&projects=&template=bug_report.yml" target="_blank" rel="noopener noreferrer" class="text-blue-500 hover:underline inline-flex items-center text-sm">@visulima/error</a>.',`"${d(e)}"`].join("</br></br>");const t=$("LINKS","ENDLINKS",e),n=t?t.split(`
33
+ `).map(a=>a.trim()).filter(Boolean).map(a=>{try{const s=JSON.parse(a);return typeof s.url=="string"&&typeof s.title=="string"&&_(s.url)?{title:s.title,url:s.url}:void 0}catch{return}}).filter(a=>a!==void 0):[],o=n.length>0?`
34
+
35
+ ## Links
36
+
37
+ ${n.map(a=>`- <a href="${d(a.url)}" target="_blank" rel="noopener noreferrer">${d(a.title)}</a>`).join(`
38
+ `)}`:"";return`${d(r).replaceAll(/&quot;(.*?)&quot;(?:\s|\.)/g,"<code>$1</code> ")}${o}
39
+
40
+ --------------------
41
+ This solution was generated with the <a href="https://sdk.vercel.ai/" target="_blank" rel="noopener noreferrer">AI SDK</a> and may not be 100% accurate.`},ee={handle:e=>e.hint===void 0?Promise.resolve(void 0):typeof e.hint=="string"&&e.hint!==""?Promise.resolve({body:e.hint}):typeof e.hint=="object"&&typeof e.hint.body=="string"?Promise.resolve(e.hint):Array.isArray(e.hint)?Promise.resolve({body:e.hint.join(`
42
+ `)}):Promise.resolve(void 0),name:"errorHint",priority:1},C=e=>`\`\`\`
43
+ ${e.trim()}
44
+ \`\`\``,y=e=>`\`\`\`bash
45
+ ${e.trim()}
46
+ \`\`\``,h=e=>`\`\`\`ts
47
+ ${e.trim()}
48
+ \`\`\``,D=e=>`\`\`\`js
49
+ ${e.trim()}
50
+ \`\`\``,c=(e,...r)=>{const t=e.toLowerCase();return r.some(n=>t.includes(n.toLowerCase()))},J=[{name:"esm-cjs-interop",test:e=>{const{message:r}=e;if(c(r,"err_require_esm","cannot use import statement outside a module","must use import to load es module","require() of es module","does not provide an export named"))return{md:["Your project or a dependency may be mixing CommonJS and ES Modules.","","Try:","- Ensure package.json has the correct `type` (either `module` or `commonjs`).","- Use dynamic `import()` when requiring ESM from CJS.","- Prefer ESM-compatible entrypoints from dependencies.","- In Node, align `module` resolution with your bundler config.","","Check Node resolution:",y(`node -v
51
+ cat package.json | jq .type`),"","Example dynamic import in CJS:",D("(async () => { const mod = await import('some-esm'); mod.default(); })();")].join(`
52
+ `),title:"ESM/CJS interop"}}},{name:"missing-default-export",test:e=>{const{message:r}=e;if(c(r,"default export not found","has no default export","does not provide an export named 'default'","is not exported from"))return{md:["Verify your import/export shapes.","","Default export example:",h(`export default function Component() {}
53
+ // import Component from './file'`),"","Named export example:",h(`export function Component() {}
54
+ // import { Component } from './file'`)].join(`
55
+ `),title:"Export mismatch (default vs named)"}}},{name:"port-in-use",test:e=>{const{message:r}=e;if(c(r,"eaddrinuse","address already in use","listen eaddrinuse"))return{md:["Another process is using the port.","","Change the port or stop the other process.","","On macOS/Linux:",y(`lsof -i :3000
56
+ kill -9 <PID>`),"","On Windows (PowerShell):",y(`netstat -ano | findstr :3000
57
+ taskkill /PID <PID> /F`)].join(`
58
+ `),title:"Port already in use"}}},{name:"file-not-found-or-case",test:(e,r)=>{const{message:t}=e;if(c(t,"enoent","module not found","cannot find module"))return{md:["Check the import path and filename case (Linux/macOS are case-sensitive).","If using TS path aliases, verify `tsconfig.paths` and bundler aliases.","","Current file:",C(`${r.file}:${String(r.line)}`)].join(`
59
+ `),title:"Missing file or path case mismatch"}}},{name:"ts-path-mapping",test:e=>{const{message:r}=e;if(c(r,"ts2307","cannot find module")||r.includes("TS2307"))return{md:["If you use path aliases, align TS `paths` with Vite/Webpack resolve aliases.","Ensure file extensions are correct and included in resolver.","","tsconfig.json excerpt:",h(`{
60
+ "compilerOptions": {
61
+ "baseUrl": ".",
62
+ "paths": { "@/*": ["src/*"] }
63
+ }
64
+ }`)].join(`
65
+ `),title:"TypeScript path mapping / resolution"}}},{name:"network-dns-enotfound",test:e=>{const{message:r}=e;if(c(r,"enotfound","getaddrinfo","dns lookup","fetch failed","econnrefused"))return{md:["The host may be unreachable or misconfigured.","","Try:","- Verify the hostname and protocol (http/https).","- Check VPN/proxy and firewall.","- Confirm the service is running and listening on the expected port.","",y(`ping <host>
66
+ nslookup <host>
67
+ curl -v http://<host>:<port>`)].join(`
68
+ `),title:"Network/DNS connection issue"}}},{name:"undefined-property",test:e=>{const{message:r}=e;if(c(r,"cannot read properties of undefined","reading '"))return{md:["A variable or function returned `undefined`.","","Mitigations:","- Add nullish checks before property access.","- Validate function return values and input props/state.","",h("const value = maybe?.prop; // or: if (maybe) { use(maybe.prop) }")].join(`
69
+ `),title:"Accessing property of undefined"}}}],re={handle:(e,r)=>{try{const t=J.map(o=>({match:o.test(e,r),rule:o})).filter(o=>!!o.match);if(t.length===0)return Promise.resolve(void 0);const n=t.toSorted((o,a)=>(o.match.priority??0)-(a.match.priority??0)).map(o=>`#### ${o.match.title}
70
+
71
+ ${o.match.md}`).join(`
72
+
73
+ ---
74
+
75
+ `);return n===""?Promise.resolve(void 0):Promise.resolve({body:n,header:"### Potential fixes detected"})}catch{return Promise.resolve(void 0)}},name:"ruleBasedHints",priority:0};let p=class extends Error{constructor(r){super(r),this.name="NonError"}};const ne=()=>{if(!Error.captureStackTrace)return;const e=new Error;return Error.captureStackTrace(e),e.stack},v=new Map([["Error",Error],["EvalError",EvalError],["RangeError",RangeError],["ReferenceError",ReferenceError],["SyntaxError",SyntaxError],["TypeError",TypeError],["URIError",URIError],...typeof AggregateError>"u"?[]:[["AggregateError",AggregateError]]]),oe=(e,r)=>{let t;try{t=new e}catch(o){throw new Error(`The error constructor "${e.name}" is not compatible`,{cause:o})}const n=r??t.name;if(v.has(n))throw new Error(`The error constructor "${n}" is already known.`);v.set(n,e)},x=e=>v.get(e),b=e=>e!==null&&typeof e=="object"&&typeof e.name=="string"&&typeof e.message=="string"&&(x(e.name)!==void 0||e.name==="Error"),k=e=>{if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype||Object.getPrototypeOf(r)===null},L={maxDepth:Number.POSITIVE_INFINITY},N=(e,r,t=0)=>b(e)?S(e,r,t):r.maxDepth!==void 0&&t>=r.maxDepth?new p(JSON.stringify(e)):new p(JSON.stringify(e)),F=(e,r,t,n,o)=>{const a=r.map(s=>l(s,n,o+1));return new e(a,t)},S=(e,r,t)=>{if(r.maxDepth!==void 0&&t>=r.maxDepth)return new p(JSON.stringify(e));const{cause:n,errors:o,message:a,name:s,stack:i,...m}=e,w=x(s)??Error,u=s==="AggregateError"&&Array.isArray(o)?F(w,o,a,r,t):new w(a);return!u.name&&s&&(u.name=s),a!==void 0&&(u.message=a),i&&(u.stack=i),R(u,m,n,s,r,t),n!==void 0&&(u.cause=l(n,r,t+1)),M(u,e),u},l=(e,r,t)=>{if(k(e)){if(e.__dataType==="Map"&&Array.isArray(e.value))return new Map(e.value.map(([o,a])=>[l(o,r,t+1),l(a,r,t+1)]));if(e.__dataType==="Set"&&Array.isArray(e.value))return new Set(e.value.map(o=>l(o,r,t+1)));if(b(e))return N(e,r,t);const n={};for(const[o,a]of Object.entries(e))o==="__proto__"||o==="constructor"||o==="prototype"||(n[o]=l(a,r,t+1));return n}return Array.isArray(e)?e.map(n=>l(n,r,t)):e},R=(e,r,t,n,o,a)=>{const s=e;for(const[i,m]of Object.entries(r))if(!(i==="__proto__"||i==="constructor"||i==="prototype")){if(i==="cause"&&t!==void 0||i==="errors"&&n==="AggregateError")continue;Object.defineProperty(s,i,{configurable:!0,enumerable:!0,value:l(m,o,a+1),writable:!0})}},M=(e,r)=>{const t=new Set(["message","name","stack"]);for(const n of Object.keys(r))t.add(n);for(const n of t)if(n in e){const o=Object.getOwnPropertyDescriptor(e,n);o&&!o.enumerable&&Object.defineProperty(e,n,{...o,enumerable:!0})}},j=e=>new p(JSON.stringify(e)),U=e=>new p(JSON.stringify(e)),V=(e,r)=>b(e)?S(e,r,0):N(e,r),ae=(e,r={})=>{const t={...L,...r};return e instanceof Error?e:e===null?j(null):typeof e=="string"||typeof e=="number"||typeof e=="boolean"?j(e):Array.isArray(e)?U(e):b(e)?S(e,t,0):k(e)?V(e,t):new p(JSON.stringify(e))},q=P("node:util"),Y=e=>{try{return q().inspect(e)}catch{}try{return String(e)}catch{return"<unprintable>"}},se=e=>{const r=new Set,t=[];let n=e;for(;n;){if(r.has(n)){console.error(`Circular reference detected in error causes: ${Y(e)}`);break}if(t.push(n),r.add(n),typeof n!="object"||!("cause"in n))break;n=n.cause}return t},K=e=>{const r=e.methodName&&e.methodName!=="<unknown>"?`${e.methodName} `:"",t=e.file??"<unknown>",n=String(e.line??0),o=String(e.column??0);return r.trim()?` at ${r}(${t}:${n}:${o})`:` at ${t}:${n}:${o}`},ie=(e,r)=>{const t=[];if(r?.header&&(r.header.name||r.header.message)){const n=r.header.name??"Error",o=r.header.message??"";t.push(`${n}${o?": ":""}${o}`)}for(const n of e)t.push(K(n));return t.join(`
76
+ `)},B=Object.create({},{cause:{enumerable:!1,value:void 0,writable:!0},code:{enumerable:!0,value:void 0,writable:!0},errors:{enumerable:!1,value:void 0,writable:!0},message:{enumerable:!1,value:void 0,writable:!0},name:{enumerable:!1,value:void 0,writable:!0},stack:{enumerable:!1,value:void 0,writable:!0}}),X=e=>{if(typeof e!="object"||e===null)return!1;const r=Object.getPrototypeOf(e);return r===null||r===Object.prototype||Object.getPrototypeOf(r)===null},O=new WeakSet,H=e=>{if(Object.hasOwn(e,"name")&&typeof e.name=="string"&&e.name!=="")return e.name;const r=e.constructor?.name;return typeof r=="string"&&r!==""?r:e.name},A=e=>{const r=Object.getOwnPropertyNames(e);for(const t of r){const n=Object.getOwnPropertyDescriptor(e,t);n&&(n.enumerable||Object.defineProperty(e,t,{...n,enumerable:!0}),n.value&&typeof n.value=="object"&&!Array.isArray(n.value)&&(Object.getPrototypeOf(n.value)===Object.prototype||Object.getPrototypeOf(n.value)===null)&&A(n.value))}},W=e=>{O.add(e);const r=e.toJSON();return O.delete(e),Object.isExtensible(r)&&A(r),r},f=(e,r,t,n,o=new Set)=>{if(e&&e instanceof Uint8Array&&e.constructor.name==="Buffer")return"[object Buffer]";if(e!==null&&typeof e=="object"&&"pipe"in e&&typeof e.pipe=="function")return"[object Stream]";if(e instanceof Error)return r.has(e)?"[Circular]":(t+=1,g(e,n,r,t));if(n.useToJSON&&e!==null&&typeof e=="object"&&"toJSON"in e&&typeof e.toJSON=="function")return e.toJSON();if(e instanceof Date)return e.toISOString();if(e instanceof RegExp)return e.toString();if(typeof URL<"u"&&e instanceof URL)return e.href;if(e instanceof Map){const a=[];for(const[s,i]of e.entries())a.push([f(s,r,t,n,o),f(i,r,t,n,o)]);return{__dataType:"Map",value:a}}if(e instanceof Set){const a=[];for(const s of e.values())a.push(f(s,r,t,n,o));return{__dataType:"Set",value:a}}if(typeof e=="function")return`[Function: ${e.name||"anonymous"}]`;if(typeof e=="bigint")return`${String(e)}n`;if(X(e)){if(o.has(e))return"[Circular]";if(n.maxDepth!==void 0&&n.maxDepth!==Number.POSITIVE_INFINITY&&t+1>=n.maxDepth)return{};t+=1,o.add(e);const a={};for(const s in e)a[s]=f(e[s],r,t,n,o);return o.delete(e),a}try{return e}catch{return"[Not Available]"}},g=(e,r,t,n)=>{if(t.add(e),r.maxDepth===0)return{};if(r.useToJSON&&typeof e.toJSON=="function"&&!O.has(e))return W(e);const o=Object.create(B);if(Object.defineProperty(o,"name",{configurable:!0,enumerable:!0,value:H(e),writable:!0}),Object.defineProperty(o,"message",{configurable:!0,enumerable:!0,value:e.message,writable:!0}),Object.defineProperty(o,"stack",{configurable:!0,enumerable:!0,value:e.stack,writable:!0}),Array.isArray(e.errors)){const s=[];for(const i of e.errors){if(!(i instanceof Error))throw new TypeError("All errors in the 'errors' property must be instances of Error");if(t.has(i))return Object.defineProperty(o,"errors",{configurable:!0,enumerable:!0,value:[],writable:!0}),o;s.push(g(i,r,t,n))}Object.defineProperty(o,"errors",{configurable:!0,enumerable:!0,value:s,writable:!0})}const a=e.cause;if(a!=null)if(a instanceof Error)t.has(a)?Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:"[Circular]",writable:!0}):Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:g(a,r,t,n),writable:!0});else{const s=f(a,t,n,r);Object.defineProperty(o,"cause",{configurable:!0,enumerable:!0,value:s,writable:!0})}for(const s in e){if(s==="name"||s==="message"||s==="stack"||s==="cause"||s==="errors")continue;const i=e[s],m=f(i,t,n,r);Object.defineProperty(o,s,{configurable:!0,enumerable:!0,value:m,writable:!0})}if(Array.isArray(r.exclude)&&r.exclude.length>0)for(const s of r.exclude)try{delete o[s]}catch{}return o},ue=(e,r={})=>g(e,{exclude:r.exclude??[],maxDepth:r.maxDepth??Number.POSITIVE_INFINITY,useToJSON:r.useToJSON??!1},new Set,0);export{fe as CODE_FRAME_POINTER,p as NonError,be as VisulimaError,oe as addKnownErrorConstructor,Q as aiPrompt,Z as aiSolutionResponse,ne as captureRawStackTrace,pe as codeFrame,me as composeFilters,ae as deserializeError,ee as errorHintFinder,K as formatStackFrameLine,ie as formatStacktrace,se as getErrorCauses,G as indexToLineColumn,b as isErrorLike,ve as isVisulimaError,de as parseStacktrace,ye as renderError,re as ruleBasedFinder,ue as serializeError,he as stackFilters};
@@ -0,0 +1 @@
1
+ import{h as r}from"./VisulimaError-DTMgXonA-CzaryRgZ.js";class n extends r{code;context;constructor(e,t,o){super({message:e,name:"CerebroError"}),this.code=t,this.context=o}}export{n as t};