@juspay/neurolink 9.88.3 → 9.88.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.
package/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## [9.88.4](https://github.com/juspay/neurolink/compare/v9.88.3...v9.88.4) (2026-07-15)
2
+
3
+ ### Bug Fixes
4
+
5
+ - **(file-detector):** disambiguate M4A/MOV/WebM/AAC by container brand & DocType ([6fac501](https://github.com/juspay/neurolink/commit/6fac501f496c55f9306536a4883d165b6015b3a1)), closes [#431](https://github.com/juspay/neurolink/issues/431) [#435](https://github.com/juspay/neurolink/issues/435) [#424](https://github.com/juspay/neurolink/issues/424)
6
+
1
7
  ## [9.88.3](https://github.com/juspay/neurolink/compare/v9.88.2...v9.88.3) (2026-07-15)
2
8
 
3
9
  ### Bug Fixes
@@ -1003,7 +1003,7 @@ Data:
1003
1003
  ${l.headers.join(" ")}
1004
1004
  ${d}
1005
1005
  `;let p=l.rowCount-20;p>0&&(c+=`... (${p} more rows)
1006
- `)}return{type:"xlsx",content:c,mimeType:t.mimeType,metadata:t.metadata}}}}catch(o){return g.warn(`[FileDetector] ExcelProcessor failed for ${n}, using fallback`,o instanceof Error?o.message:String(o)),{type:"xlsx",content:r.formatInformativePlaceholder("Spreadsheet",n,e,t,o),mimeType:t.mimeType,metadata:t.metadata}}return{type:"xlsx",content:r.formatInformativePlaceholder("Spreadsheet",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processDocxFile(e,t){let n=t.metadata.filename||"document",o=t.extension?.toLowerCase();try{if(o==="odt"){let{openDocumentProcessor:s}=await Promise.resolve().then(()=>(Soe(),Toe)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/vnd.oasis.opendocument.text",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}else if(o==="rtf"){let{rtfProcessor:s}=await Promise.resolve().then(()=>(K1e(),W1e)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/rtf",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}else{let{wordProcessor:s}=await Promise.resolve().then(()=>(Coe(),koe)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/vnd.openxmlformats-officedocument.wordprocessingml.document",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}}catch(s){return g.warn(`[FileDetector] Document processor failed for ${n}, using fallback`,s instanceof Error?s.message:String(s)),{type:"docx",content:r.formatInformativePlaceholder("Document",n,e,t,s),mimeType:t.mimeType,metadata:t.metadata}}return{type:"docx",content:r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processPptxFile(e,t){let n=t.metadata.filename||"presentation";try{let{PptxProcessor:o}=await Promise.resolve().then(()=>(XV(),YV)),s=await o.extractText(e);if(s)return{type:"pptx",content:s,mimeType:t.mimeType,metadata:t.metadata}}catch(o){return g.warn(`[FileDetector] PptxProcessor failed for ${n}, using fallback`,o instanceof Error?o.message:String(o)),{type:"pptx",content:r.formatInformativePlaceholder("Presentation",n,e,t,o),mimeType:t.mimeType,metadata:t.metadata}}return{type:"pptx",content:r.formatInformativePlaceholder("Presentation",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processSvgAsText(e,t){try{let{processSvg:n}=await Promise.resolve().then(()=>(rUe(),tUe)),o=await n({id:"svg-file",name:t.metadata.filename||"image.svg",mimetype:"image/svg+xml",size:e.length,buffer:e});return o.success&&o.data?(g.info(`[FileDetector] SVG processed as text: ${t.metadata.filename||"image.svg"}`),{type:"svg",content:o.data.textContent,mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}}):(g.warn(`[FileDetector] SVG processor failed, returning safe empty SVG: ${o.error?.userMessage}`),{type:"svg",content:'<svg xmlns="http://www.w3.org/2000/svg"></svg>',mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}})}catch(n){return g.warn(`[FileDetector] SVG processor not available, returning safe empty SVG: ${n instanceof Error?n.message:String(n)}`),{type:"svg",content:'<svg xmlns="http://www.w3.org/2000/svg"></svg>',mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}}}}static async loadFromURL(e,t){let n=t?.maxSize||209715200,o=t?.timeout||r.DEFAULT_NETWORK_TIMEOUT,s=t?.maxRetries??nUe,i=t?.retryDelay??oUe;return $7t(async()=>{let a=await BE(e,{dispatcher:FE().compose($E.redirect({maxRedirections:5})),method:"GET",headersTimeout:o,bodyTimeout:o});if(a.statusCode!==200)throw new Error(`HTTP ${a.statusCode} fetching ${e}`);let c=[],l=0;for await(let u of a.body){if(l+=u.length,l>n)throw new Error(`File too large: ${W_(l)} (max: ${W_(n)})`);c.push(u)}return Buffer.concat(c)},{maxRetries:s,retryDelay:i})}static async loadFromPath(e,t){let n=t?.maxSize||209715200;if(e.includes("\0"))throw new Error("Invalid file path: contains a null byte");if(t?.allowedBaseDir){let s,i;try{s=await bj(rm(t.allowedBaseDir)),i=await bj(e)}catch{throw new Error(`Access denied: "${e}" could not be resolved within the allowed base directory`)}let a=vY(s,i);if(a===".."||a.startsWith(`..${uI}`)||bY(a))throw new Error(`Access denied: "${e}" resolves outside the allowed base directory`)}let o=await ire(e,"r");try{let s=await o.stat();if(!s.isFile())throw new Error(`Not a file: ${e}`);if(s.size>n)throw new Error(`File too large: ${e} is ${W_(s.size)} (max: ${W_(n)})`);return await o.readFile()}finally{await o.close()}}static loadFromDataURI(e){let t=e.match(/^data:([^;]+);base64,(.+)$/);if(!t)throw new Error(`Invalid data URI format (expected "data:<mime>;base64,<data>"): "${e.slice(0,32)}\u2026"`);return Buffer.from(t[2],"base64")}},Ooe=class{async detect(e){return Buffer.isBuffer(e)?this.isPNG(e)?this.result("image","image/png",95):this.isJPEG(e)?this.result("image","image/jpeg",95):this.isGIF(e)?this.result("image","image/gif",95):this.isWebP(e)?this.result("image","image/webp",95):this.isPDF(e)?this.result("pdf","application/pdf",95):e.length>=8&&e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112?this.result("video","video/mp4",95):e.length>=4&&e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163?this.result("video","video/x-matroska",90):e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===65&&e[9]===86&&e[10]===73&&e[11]===32?this.result("video","video/x-msvideo",95):e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69?this.result("audio","audio/wav",95):e.length>=3&&e[0]===73&&e[1]===68&&e[2]===51?this.result("audio","audio/mpeg",95):e.length>=2&&e[0]===255&&(e[1]&224)===224?this.result("audio","audio/mpeg",80):e.length>=4&&e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67?this.result("audio","audio/flac",95):e.length>=4&&e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83?this.result("audio","audio/ogg",90):e.length>=4&&e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4?this.result("archive","application/zip",70):e.length>=2&&e[0]===31&&e[1]===139?this.result("archive","application/gzip",90):e.length>=4&&e[0]===82&&e[1]===97&&e[2]===114&&e[3]===33?this.result("archive","application/x-rar-compressed",95):this.unknown():this.unknown()}isPNG(e){return e.length>=4&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}isJPEG(e){return e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255}isGIF(e){return e.length>=4&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56}isWebP(e){return e.length>=12&&e.slice(0,4).toString()==="RIFF"&&e.slice(8,12).toString()==="WEBP"}isPDF(e){return e.length>=5&&e.slice(0,5).toString()==="%PDF-"}result(e,t,n){return{type:e,mimeType:t,extension:null,source:"buffer",metadata:{confidence:n}}}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Noe=class{async detect(e){if(typeof e!="string"||!this.isURL(e))return this.unknown();try{let n=(await BE(e,{dispatcher:FE().compose($E.redirect({maxRedirections:5})),method:"HEAD",headersTimeout:Td.DEFAULT_HEAD_TIMEOUT,bodyTimeout:Td.DEFAULT_HEAD_TIMEOUT})).headers["content-type"]||"",o=this.mimeToFileType(n);return{type:o,mimeType:n.split(";")[0].trim(),extension:null,source:"url",metadata:{confidence:o!=="unknown"?85:0}}}catch{return this.unknown()}}mimeToFileType(e){let t=e.toLowerCase().split(";")[0].trim();return t==="text/csv"||t==="text/tab-separated-values"?"csv":t==="image/svg+xml"?"svg":t.startsWith("image/")?"image":t==="application/pdf"?"pdf":t.startsWith("video/")?"video":t.startsWith("audio/")?"audio":t==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||t==="application/msword"?"docx":t==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"||t==="application/vnd.ms-excel"?"xlsx":t==="application/vnd.openxmlformats-officedocument.presentationml.presentation"||t==="application/vnd.ms-powerpoint"?"pptx":t==="application/vnd.oasis.opendocument.text"?"docx":t==="application/vnd.oasis.opendocument.spreadsheet"?"xlsx":t==="application/vnd.oasis.opendocument.presentation"?"pptx":t==="application/rtf"||t==="text/rtf"?"docx":t==="application/zip"||t==="application/x-zip-compressed"||t==="application/gzip"||t==="application/x-gzip"||t==="application/x-tar"||t==="application/x-compressed-tar"||t==="application/java-archive"||t==="application/x-rar-compressed"||t==="application/vnd.rar"||t==="application/x-7z-compressed"?"archive":t==="text/plain"||t==="text/markdown"||t==="text/html"||t==="text/css"||t==="text/javascript"||t==="text/typescript"||t==="application/json"||t==="application/xml"||t==="text/xml"||t==="application/yaml"||t==="application/x-yaml"||t.startsWith("text/x-")||t.startsWith("text/")?"text":"unknown"}isURL(e){return e.startsWith("http://")||e.startsWith("https://")}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Doe=class{async detect(e){if(typeof e!="string")return this.unknown();let t=this.getExtension(e);if(!t)return this.unknown();let o={csv:"csv",tsv:"csv",jpg:"image",jpeg:"image",png:"image",gif:"image",webp:"image",bmp:"image",tiff:"image",tif:"image",svg:"svg",avif:"image",pdf:"pdf",mp4:"video",mkv:"video",mov:"video",avi:"video",webm:"video",wmv:"video",flv:"video",mp3:"audio",wav:"audio",ogg:"audio",flac:"audio",m4a:"audio",aac:"audio",wma:"audio",opus:"audio",zip:"archive",tar:"archive",gz:"archive",tgz:"archive",rar:"archive","7z":"archive",jar:"archive",xlsx:"xlsx",xls:"xlsx",docx:"docx",doc:"docx",pptx:"pptx",ppt:"pptx",odt:"docx",ods:"xlsx",odp:"pptx",rtf:"docx",txt:"text",md:"text",markdown:"text",json:"text",xml:"text",yaml:"text",yml:"text",html:"text",htm:"text",css:"text",log:"text",conf:"text",cfg:"text",ini:"text",env:"text",toml:"text",properties:"text",gitignore:"text",dockerignore:"text",editorconfig:"text",prettierrc:"text",eslintrc:"text",babelrc:"text",js:"text",mjs:"text",cjs:"text",jsx:"text",ts:"text",tsx:"text",py:"text",java:"text",go:"text",rs:"text",rb:"text",php:"text",c:"text",cpp:"text",cc:"text",h:"text",hpp:"text",cs:"text",swift:"text",kt:"text",kts:"text",scala:"text",sh:"text",bash:"text",zsh:"text",ps1:"text",sql:"text",r:"text",lua:"text",pl:"text",perl:"text",dart:"text",ex:"text",exs:"text",erl:"text",hs:"text",clj:"text",lisp:"text",vim:"text",m4v:"video",ico:"image"}[t.toLowerCase()];return{type:o||"unknown",mimeType:this.getMimeType(t),extension:t,source:this.detectSource(e),metadata:{confidence:o?85:0}}}getExtension(e){let t=e.trim(),n=t;if(this.isURL(t))try{n=new URL(t).pathname;try{n=decodeURIComponent(n)}catch{}}catch{n=t}let o=n.trim().match(/\.([^.]+)$/);if(!o)return null;let s=o[1].split(/[?#]/)[0].toLowerCase();return/^[a-z0-9]+$/.test(s)?s:null}isURL(e){let t=e.trim();return t.startsWith("http://")||t.startsWith("https://")}detectSource(e){let t=e.trim();if(t.startsWith("data:"))return"datauri";if(this.isURL(t))try{return new URL(t),"url"}catch{return"path"}return"path"}getMimeType(e){return{csv:"text/csv",tsv:"text/tab-separated-values",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",bmp:"image/bmp",tiff:"image/tiff",tif:"image/tiff",svg:"image/svg+xml",avif:"image/avif",pdf:"application/pdf",mp4:"video/mp4",mkv:"video/x-matroska",mov:"video/quicktime",avi:"video/x-msvideo",webm:"video/webm",wmv:"video/x-ms-wmv",flv:"video/x-flv",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",flac:"audio/flac",m4a:"audio/mp4",aac:"audio/aac",wma:"audio/x-ms-wma",opus:"audio/opus",zip:"application/zip",tar:"application/x-tar",gz:"application/gzip",tgz:"application/gzip",rar:"application/x-rar-compressed","7z":"application/x-7z-compressed",jar:"application/java-archive",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xls:"application/vnd.ms-excel",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",doc:"application/msword",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",ppt:"application/vnd.ms-powerpoint",odt:"application/vnd.oasis.opendocument.text",ods:"application/vnd.oasis.opendocument.spreadsheet",odp:"application/vnd.oasis.opendocument.presentation",rtf:"application/rtf",txt:"text/plain",md:"text/markdown",markdown:"text/markdown",json:"application/json",xml:"application/xml",yaml:"application/yaml",yml:"application/yaml",html:"text/html",htm:"text/html",css:"text/css",log:"text/plain",conf:"text/plain",cfg:"text/plain",ini:"text/plain",env:"text/plain",toml:"text/plain",properties:"text/plain",gitignore:"text/plain",dockerignore:"text/plain",editorconfig:"text/plain",prettierrc:"application/json",eslintrc:"application/json",babelrc:"application/json",js:"text/javascript",mjs:"text/javascript",cjs:"text/javascript",jsx:"text/javascript",ts:"text/typescript",tsx:"text/typescript",py:"text/x-python",java:"text/x-java-source",go:"text/x-go",rs:"text/x-rustsrc",rb:"text/x-ruby",php:"text/x-php",c:"text/x-c",cpp:"text/x-c++",cc:"text/x-c++",h:"text/x-c",hpp:"text/x-c++",cs:"text/x-csharp",swift:"text/x-swift",kt:"text/x-kotlin",kts:"text/x-kotlin",scala:"text/x-scala",sh:"text/x-shellscript",bash:"text/x-shellscript",zsh:"text/x-shellscript",ps1:"text/x-powershell",sql:"text/x-sql",r:"text/x-r",lua:"text/x-lua",pl:"text/x-perl",perl:"text/x-perl",dart:"text/x-dart",ex:"text/x-elixir",exs:"text/x-elixir",erl:"text/x-erlang",hs:"text/x-haskell",clj:"text/x-clojure",lisp:"text/x-lisp",vim:"text/plain",m4v:"video/mp4",ico:"image/x-icon"}[e.toLowerCase()]||"application/octet-stream"}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Loe=class{async detect(e){let t;if(Buffer.isBuffer(e))t=e;else if(typeof e=="string")if(e.startsWith("data:")){let o=e.match(/^data:([^;]+);base64,(.+)$/);if(!o)return this.unknown();t=Buffer.from(o[2],"base64")}else{if(e.startsWith("http://")||e.startsWith("https://"))return this.unknown();try{t=await VE(e)}catch{return this.unknown()}}else return this.unknown();let n=t.toString("utf-8",0,Math.min(2e3,t.length));if(this.looksLikeJSON(n))return this.result("text","application/json",75);if(this.looksLikeCSV(n))return this.result("csv","text/csv",75);if(this.looksLikeXML(n)){let o=n.includes("<!DOCTYPE html")||n.includes("<html");return this.result("text",o?"text/html":"application/xml",70)}return this.looksLikeYAML(n)?this.result("text","application/yaml",70):this.looksLikeText(n)?this.result("text","text/plain",60):this.unknown()}looksLikeCSV(e){let t=e.trim().split(`
1006
+ `)}return{type:"xlsx",content:c,mimeType:t.mimeType,metadata:t.metadata}}}}catch(o){return g.warn(`[FileDetector] ExcelProcessor failed for ${n}, using fallback`,o instanceof Error?o.message:String(o)),{type:"xlsx",content:r.formatInformativePlaceholder("Spreadsheet",n,e,t,o),mimeType:t.mimeType,metadata:t.metadata}}return{type:"xlsx",content:r.formatInformativePlaceholder("Spreadsheet",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processDocxFile(e,t){let n=t.metadata.filename||"document",o=t.extension?.toLowerCase();try{if(o==="odt"){let{openDocumentProcessor:s}=await Promise.resolve().then(()=>(Soe(),Toe)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/vnd.oasis.opendocument.text",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}else if(o==="rtf"){let{rtfProcessor:s}=await Promise.resolve().then(()=>(K1e(),W1e)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/rtf",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}else{let{wordProcessor:s}=await Promise.resolve().then(()=>(Coe(),koe)),i=await s.processFile({id:n,name:n,mimetype:t.mimeType||"application/vnd.openxmlformats-officedocument.wordprocessingml.document",size:e.length,buffer:e});if(i.success&&i.data)return{type:"docx",content:i.data.textContent||r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}}catch(s){return g.warn(`[FileDetector] Document processor failed for ${n}, using fallback`,s instanceof Error?s.message:String(s)),{type:"docx",content:r.formatInformativePlaceholder("Document",n,e,t,s),mimeType:t.mimeType,metadata:t.metadata}}return{type:"docx",content:r.formatInformativePlaceholder("Document",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processPptxFile(e,t){let n=t.metadata.filename||"presentation";try{let{PptxProcessor:o}=await Promise.resolve().then(()=>(XV(),YV)),s=await o.extractText(e);if(s)return{type:"pptx",content:s,mimeType:t.mimeType,metadata:t.metadata}}catch(o){return g.warn(`[FileDetector] PptxProcessor failed for ${n}, using fallback`,o instanceof Error?o.message:String(o)),{type:"pptx",content:r.formatInformativePlaceholder("Presentation",n,e,t,o),mimeType:t.mimeType,metadata:t.metadata}}return{type:"pptx",content:r.formatInformativePlaceholder("Presentation",n,e,t),mimeType:t.mimeType,metadata:t.metadata}}static async processSvgAsText(e,t){try{let{processSvg:n}=await Promise.resolve().then(()=>(rUe(),tUe)),o=await n({id:"svg-file",name:t.metadata.filename||"image.svg",mimetype:"image/svg+xml",size:e.length,buffer:e});return o.success&&o.data?(g.info(`[FileDetector] SVG processed as text: ${t.metadata.filename||"image.svg"}`),{type:"svg",content:o.data.textContent,mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}}):(g.warn(`[FileDetector] SVG processor failed, returning safe empty SVG: ${o.error?.userMessage}`),{type:"svg",content:'<svg xmlns="http://www.w3.org/2000/svg"></svg>',mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}})}catch(n){return g.warn(`[FileDetector] SVG processor not available, returning safe empty SVG: ${n instanceof Error?n.message:String(n)}`),{type:"svg",content:'<svg xmlns="http://www.w3.org/2000/svg"></svg>',mimeType:"image/svg+xml",metadata:{confidence:t.metadata.confidence,size:e.length,filename:t.metadata.filename,extension:t.extension}}}}static async loadFromURL(e,t){let n=t?.maxSize||209715200,o=t?.timeout||r.DEFAULT_NETWORK_TIMEOUT,s=t?.maxRetries??nUe,i=t?.retryDelay??oUe;return $7t(async()=>{let a=await BE(e,{dispatcher:FE().compose($E.redirect({maxRedirections:5})),method:"GET",headersTimeout:o,bodyTimeout:o});if(a.statusCode!==200)throw new Error(`HTTP ${a.statusCode} fetching ${e}`);let c=[],l=0;for await(let u of a.body){if(l+=u.length,l>n)throw new Error(`File too large: ${W_(l)} (max: ${W_(n)})`);c.push(u)}return Buffer.concat(c)},{maxRetries:s,retryDelay:i})}static async loadFromPath(e,t){let n=t?.maxSize||209715200;if(e.includes("\0"))throw new Error("Invalid file path: contains a null byte");if(t?.allowedBaseDir){let s,i;try{s=await bj(rm(t.allowedBaseDir)),i=await bj(e)}catch{throw new Error(`Access denied: "${e}" could not be resolved within the allowed base directory`)}let a=vY(s,i);if(a===".."||a.startsWith(`..${uI}`)||bY(a))throw new Error(`Access denied: "${e}" resolves outside the allowed base directory`)}let o=await ire(e,"r");try{let s=await o.stat();if(!s.isFile())throw new Error(`Not a file: ${e}`);if(s.size>n)throw new Error(`File too large: ${e} is ${W_(s.size)} (max: ${W_(n)})`);return await o.readFile()}finally{await o.close()}}static loadFromDataURI(e){let t=e.match(/^data:([^;]+);base64,(.+)$/);if(!t)throw new Error(`Invalid data URI format (expected "data:<mime>;base64,<data>"): "${e.slice(0,32)}\u2026"`);return Buffer.from(t[2],"base64")}},Ooe=class{async detect(e){if(!Buffer.isBuffer(e))return this.unknown();if(this.isPNG(e))return this.result("image","image/png",95);if(this.isJPEG(e))return this.result("image","image/jpeg",95);if(this.isGIF(e))return this.result("image","image/gif",95);if(this.isWebP(e))return this.result("image","image/webp",95);if(this.isPDF(e))return this.result("pdf","application/pdf",95);if(e.length>=8&&e[4]===102&&e[5]===116&&e[6]===121&&e[7]===112){let t=e.length>=12?e.toString("latin1",8,12):"";return/^(M4A|M4B|M4P|F4A|F4B)/.test(t)?this.result("audio","audio/mp4",95):t.startsWith("qt")?this.result("video","video/quicktime",95):this.result("video","video/mp4",95)}return e.length>=4&&e[0]===26&&e[1]===69&&e[2]===223&&e[3]===163?e.toString("latin1",0,Math.min(e.length,64)).includes("webm")?this.result("video","video/webm",92):this.result("video","video/x-matroska",90):e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===65&&e[9]===86&&e[10]===73&&e[11]===32?this.result("video","video/x-msvideo",95):e.length>=12&&e[0]===82&&e[1]===73&&e[2]===70&&e[3]===70&&e[8]===87&&e[9]===65&&e[10]===86&&e[11]===69?this.result("audio","audio/wav",95):e.length>=3&&e[0]===73&&e[1]===68&&e[2]===51?this.result("audio","audio/mpeg",95):e.length>=2&&e[0]===255&&(e[1]&246)===240?this.result("audio","audio/aac",85):e.length>=2&&e[0]===255&&(e[1]&224)===224?this.result("audio","audio/mpeg",80):e.length>=4&&e[0]===102&&e[1]===76&&e[2]===97&&e[3]===67?this.result("audio","audio/flac",95):e.length>=4&&e[0]===79&&e[1]===103&&e[2]===103&&e[3]===83?this.result("audio","audio/ogg",90):e.length>=4&&e[0]===80&&e[1]===75&&e[2]===3&&e[3]===4?this.result("archive","application/zip",70):e.length>=2&&e[0]===31&&e[1]===139?this.result("archive","application/gzip",90):e.length>=4&&e[0]===82&&e[1]===97&&e[2]===114&&e[3]===33?this.result("archive","application/x-rar-compressed",95):this.unknown()}isPNG(e){return e.length>=4&&e[0]===137&&e[1]===80&&e[2]===78&&e[3]===71}isJPEG(e){return e.length>=3&&e[0]===255&&e[1]===216&&e[2]===255}isGIF(e){return e.length>=4&&e[0]===71&&e[1]===73&&e[2]===70&&e[3]===56}isWebP(e){return e.length>=12&&e.slice(0,4).toString()==="RIFF"&&e.slice(8,12).toString()==="WEBP"}isPDF(e){return e.length>=5&&e.slice(0,5).toString()==="%PDF-"}result(e,t,n){return{type:e,mimeType:t,extension:null,source:"buffer",metadata:{confidence:n}}}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Noe=class{async detect(e){if(typeof e!="string"||!this.isURL(e))return this.unknown();try{let n=(await BE(e,{dispatcher:FE().compose($E.redirect({maxRedirections:5})),method:"HEAD",headersTimeout:Td.DEFAULT_HEAD_TIMEOUT,bodyTimeout:Td.DEFAULT_HEAD_TIMEOUT})).headers["content-type"]||"",o=this.mimeToFileType(n);return{type:o,mimeType:n.split(";")[0].trim(),extension:null,source:"url",metadata:{confidence:o!=="unknown"?85:0}}}catch{return this.unknown()}}mimeToFileType(e){let t=e.toLowerCase().split(";")[0].trim();return t==="text/csv"||t==="text/tab-separated-values"?"csv":t==="image/svg+xml"?"svg":t.startsWith("image/")?"image":t==="application/pdf"?"pdf":t.startsWith("video/")?"video":t.startsWith("audio/")?"audio":t==="application/vnd.openxmlformats-officedocument.wordprocessingml.document"||t==="application/msword"?"docx":t==="application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"||t==="application/vnd.ms-excel"?"xlsx":t==="application/vnd.openxmlformats-officedocument.presentationml.presentation"||t==="application/vnd.ms-powerpoint"?"pptx":t==="application/vnd.oasis.opendocument.text"?"docx":t==="application/vnd.oasis.opendocument.spreadsheet"?"xlsx":t==="application/vnd.oasis.opendocument.presentation"?"pptx":t==="application/rtf"||t==="text/rtf"?"docx":t==="application/zip"||t==="application/x-zip-compressed"||t==="application/gzip"||t==="application/x-gzip"||t==="application/x-tar"||t==="application/x-compressed-tar"||t==="application/java-archive"||t==="application/x-rar-compressed"||t==="application/vnd.rar"||t==="application/x-7z-compressed"?"archive":t==="text/plain"||t==="text/markdown"||t==="text/html"||t==="text/css"||t==="text/javascript"||t==="text/typescript"||t==="application/json"||t==="application/xml"||t==="text/xml"||t==="application/yaml"||t==="application/x-yaml"||t.startsWith("text/x-")||t.startsWith("text/")?"text":"unknown"}isURL(e){return e.startsWith("http://")||e.startsWith("https://")}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Doe=class{async detect(e){if(typeof e!="string")return this.unknown();let t=this.getExtension(e);if(!t)return this.unknown();let o={csv:"csv",tsv:"csv",jpg:"image",jpeg:"image",png:"image",gif:"image",webp:"image",bmp:"image",tiff:"image",tif:"image",svg:"svg",avif:"image",pdf:"pdf",mp4:"video",mkv:"video",mov:"video",avi:"video",webm:"video",wmv:"video",flv:"video",mp3:"audio",wav:"audio",ogg:"audio",flac:"audio",m4a:"audio",aac:"audio",wma:"audio",opus:"audio",zip:"archive",tar:"archive",gz:"archive",tgz:"archive",rar:"archive","7z":"archive",jar:"archive",xlsx:"xlsx",xls:"xlsx",docx:"docx",doc:"docx",pptx:"pptx",ppt:"pptx",odt:"docx",ods:"xlsx",odp:"pptx",rtf:"docx",txt:"text",md:"text",markdown:"text",json:"text",xml:"text",yaml:"text",yml:"text",html:"text",htm:"text",css:"text",log:"text",conf:"text",cfg:"text",ini:"text",env:"text",toml:"text",properties:"text",gitignore:"text",dockerignore:"text",editorconfig:"text",prettierrc:"text",eslintrc:"text",babelrc:"text",js:"text",mjs:"text",cjs:"text",jsx:"text",ts:"text",tsx:"text",py:"text",java:"text",go:"text",rs:"text",rb:"text",php:"text",c:"text",cpp:"text",cc:"text",h:"text",hpp:"text",cs:"text",swift:"text",kt:"text",kts:"text",scala:"text",sh:"text",bash:"text",zsh:"text",ps1:"text",sql:"text",r:"text",lua:"text",pl:"text",perl:"text",dart:"text",ex:"text",exs:"text",erl:"text",hs:"text",clj:"text",lisp:"text",vim:"text",m4v:"video",ico:"image"}[t.toLowerCase()];return{type:o||"unknown",mimeType:this.getMimeType(t),extension:t,source:this.detectSource(e),metadata:{confidence:o?85:0}}}getExtension(e){let t=e.trim(),n=t;if(this.isURL(t))try{n=new URL(t).pathname;try{n=decodeURIComponent(n)}catch{}}catch{n=t}let o=n.trim().match(/\.([^.]+)$/);if(!o)return null;let s=o[1].split(/[?#]/)[0].toLowerCase();return/^[a-z0-9]+$/.test(s)?s:null}isURL(e){let t=e.trim();return t.startsWith("http://")||t.startsWith("https://")}detectSource(e){let t=e.trim();if(t.startsWith("data:"))return"datauri";if(this.isURL(t))try{return new URL(t),"url"}catch{return"path"}return"path"}getMimeType(e){return{csv:"text/csv",tsv:"text/tab-separated-values",jpg:"image/jpeg",jpeg:"image/jpeg",png:"image/png",gif:"image/gif",webp:"image/webp",bmp:"image/bmp",tiff:"image/tiff",tif:"image/tiff",svg:"image/svg+xml",avif:"image/avif",pdf:"application/pdf",mp4:"video/mp4",mkv:"video/x-matroska",mov:"video/quicktime",avi:"video/x-msvideo",webm:"video/webm",wmv:"video/x-ms-wmv",flv:"video/x-flv",mp3:"audio/mpeg",wav:"audio/wav",ogg:"audio/ogg",flac:"audio/flac",m4a:"audio/mp4",aac:"audio/aac",wma:"audio/x-ms-wma",opus:"audio/opus",zip:"application/zip",tar:"application/x-tar",gz:"application/gzip",tgz:"application/gzip",rar:"application/x-rar-compressed","7z":"application/x-7z-compressed",jar:"application/java-archive",xlsx:"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet",xls:"application/vnd.ms-excel",docx:"application/vnd.openxmlformats-officedocument.wordprocessingml.document",doc:"application/msword",pptx:"application/vnd.openxmlformats-officedocument.presentationml.presentation",ppt:"application/vnd.ms-powerpoint",odt:"application/vnd.oasis.opendocument.text",ods:"application/vnd.oasis.opendocument.spreadsheet",odp:"application/vnd.oasis.opendocument.presentation",rtf:"application/rtf",txt:"text/plain",md:"text/markdown",markdown:"text/markdown",json:"application/json",xml:"application/xml",yaml:"application/yaml",yml:"application/yaml",html:"text/html",htm:"text/html",css:"text/css",log:"text/plain",conf:"text/plain",cfg:"text/plain",ini:"text/plain",env:"text/plain",toml:"text/plain",properties:"text/plain",gitignore:"text/plain",dockerignore:"text/plain",editorconfig:"text/plain",prettierrc:"application/json",eslintrc:"application/json",babelrc:"application/json",js:"text/javascript",mjs:"text/javascript",cjs:"text/javascript",jsx:"text/javascript",ts:"text/typescript",tsx:"text/typescript",py:"text/x-python",java:"text/x-java-source",go:"text/x-go",rs:"text/x-rustsrc",rb:"text/x-ruby",php:"text/x-php",c:"text/x-c",cpp:"text/x-c++",cc:"text/x-c++",h:"text/x-c",hpp:"text/x-c++",cs:"text/x-csharp",swift:"text/x-swift",kt:"text/x-kotlin",kts:"text/x-kotlin",scala:"text/x-scala",sh:"text/x-shellscript",bash:"text/x-shellscript",zsh:"text/x-shellscript",ps1:"text/x-powershell",sql:"text/x-sql",r:"text/x-r",lua:"text/x-lua",pl:"text/x-perl",perl:"text/x-perl",dart:"text/x-dart",ex:"text/x-elixir",exs:"text/x-elixir",erl:"text/x-erlang",hs:"text/x-haskell",clj:"text/x-clojure",lisp:"text/x-lisp",vim:"text/plain",m4v:"video/mp4",ico:"image/x-icon"}[e.toLowerCase()]||"application/octet-stream"}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}},Loe=class{async detect(e){let t;if(Buffer.isBuffer(e))t=e;else if(typeof e=="string")if(e.startsWith("data:")){let o=e.match(/^data:([^;]+);base64,(.+)$/);if(!o)return this.unknown();t=Buffer.from(o[2],"base64")}else{if(e.startsWith("http://")||e.startsWith("https://"))return this.unknown();try{t=await VE(e)}catch{return this.unknown()}}else return this.unknown();let n=t.toString("utf-8",0,Math.min(2e3,t.length));if(this.looksLikeJSON(n))return this.result("text","application/json",75);if(this.looksLikeCSV(n))return this.result("csv","text/csv",75);if(this.looksLikeXML(n)){let o=n.includes("<!DOCTYPE html")||n.includes("<html");return this.result("text",o?"text/html":"application/xml",70)}return this.looksLikeYAML(n)?this.result("text","application/yaml",70):this.looksLikeText(n)?this.result("text","text/plain",60):this.unknown()}looksLikeCSV(e){let t=e.trim().split(`
1007
1007
  `);if(t.length<2)return!1;let n=t[0],s=[",",";"," ","|"].find(u=>n.includes(u));if(!s){if(e.startsWith("---")||/^[\s]*-\s+/m.test(e)||/^[\s]*[a-zA-Z_][a-zA-Z0-9_-]*:\s*/m.test(e)||e.startsWith("<")||e.includes("<?xml")||e.startsWith("{")&&e.includes("}")||e.startsWith("[")&&e.includes("]")||t.some(T=>T.trim().split(/\s+/).length>4))return!1;let d=t.every(T=>T.length>0&&T.length<1e3),p=!e.includes("\0"),f=t.map(T=>T.length),h=f.reduce((T,S)=>T+S,0)/f.length,y=f.reduce((T,S)=>T+(S-h)**2,0)/f.length,b=Math.sqrt(y)/h<.75;return d&&p&&b}let i=s==="|"?/\|/g:new RegExp(s,"g"),a=t.map(u=>(u.match(i)||[]).length),c=a[0];return a.filter(u=>u===c).length/t.length>=.8}looksLikeJSON(e){return B7t(e)}looksLikeXML(e){let t=e.trim();if(t.startsWith("<?xml")||t.includes("<!DOCTYPE html")||t.toLowerCase().includes("<html"))return!0;if(!t.startsWith("<")||!/<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?>/.test(t))return!1;let o=/<\/[a-zA-Z][a-zA-Z0-9-]*>/.test(t),s=/<[a-zA-Z][a-zA-Z0-9-]*(?:\s[^>]*)?\s*\/\s*>/.test(t);return o||s}looksLikeYAML(e){let t=e.trim();if(t.length===0)return!1;let n=t.split(`
1008
1008
  `);if(n.length===1)return t==="---"||t==="...";let o=[];o.push(t.startsWith("---")),o.push(/^\.\.\.$|[\n]\.\.\.$/.test(t)),o.push(/^[\s]*-\s+[^-]/m.test(t));let s=/^[\s]*[a-zA-Z_][a-zA-Z0-9_-]*:\s*(.+)$/,i=n.filter(d=>s.test(d)).length;o.push(i>=2);let a=!1,c=n.slice(0,10);for(let d=0;d<c.length-1;d++){let p=c[d].trim(),f=c[d+1];if(p.length>0&&f.length>0&&/[:-]$/.test(p)){let h=c[d].match(/^[\s]*/)?.[0].length??0;if((f.match(/^[\s]*/)?.[0].length??0)>h){a=!0;break}}}o.push(a),o.push(/^\s*#\s+/m.test(t));let l=n.filter(d=>/^[\s]*-[\s]/.test(d)).length;return o.push(l>=2),o.push(/{\s*[a-zA-Z_]/.test(t)||/\[.*\]/.test(t)),o.filter(Boolean).length>=2}looksLikeText(e){if(e.includes("\0"))return!1;let t=0;for(let n=0;n<e.length;n++){let o=e.charCodeAt(n);(o>=32&&o<127||o===9||o===10||o===13||o>127)&&t++}return t/e.length>=.85}result(e,t,n){return{type:e,mimeType:t,extension:null,source:"buffer",metadata:{confidence:n}}}unknown(){return{type:"unknown",mimeType:"application/octet-stream",extension:null,source:"buffer",metadata:{confidence:0}}}}});function sUe(r){return r?z7t[r]??1:1}function bn(r,e,t){if(!r||r.length===0)return 0;let n=t?3:4,o=Math.ceil(r.length/n),s=sUe(e),i=o*s,a=o*.05;return Math.ceil(i+a)}function j7t(r,e){let t="";if(r.content)if(typeof r.content=="string")t=r.content;else try{t=JSON.stringify(r.content)}catch{t=String(r.content)}return bn(t,e)+4}function So(r,e){return!r||r.length===0?0:r.reduce((n,o)=>n+j7t(o,e),0)+24}function QV(r,e,t){if(bn(r,t)<=e)return{text:r,truncated:!1};let o=sUe(t)+.05,s=Math.floor(e/o*4);if(s<=0)return{text:"",truncated:!0};let i=r.slice(0,s),a=Math.max(i.lastIndexOf(". "),i.lastIndexOf("! "),i.lastIndexOf("? "),i.lastIndexOf(`
1009
1009
  `)),c=a>s*.5?a+1:s;return{text:r.slice(0,c)+"...",truncated:!0}}var z7t,Sd=k(()=>{"use strict";z7t={anthropic:1.23,"google-ai":1.18,vertex:1.18,mistral:1.26,openai:1,azure:1,bedrock:1.23,ollama:1,litellm:1,huggingface:1,sagemaker:1}});function q7t(r){let e=r.split("?")[0].split("#")[0],t=e.lastIndexOf(".");if(t===-1)return;let n=e.slice(t+1).toLowerCase();return V7t[n]}function H7t(r){if(!(r.length<4)){if(r[0]===137&&r[1]===80&&r[2]===78&&r[3]===71||r[0]===255&&r[1]===216&&r[2]===255||r[0]===71&&r[1]===73&&r[2]===70||r.length>=12&&r[0]===82&&r[1]===73&&r[2]===70&&r[3]===70&&r[8]===87&&r[9]===69&&r[10]===66&&r[11]===80)return"image";if(r[0]===37&&r[1]===80&&r[2]===68&&r[3]===70)return"pdf";if(r.length>=8&&r[4]===102&&r[5]===116&&r[6]===121&&r[7]===112||r[0]===26&&r[1]===69&&r[2]===223&&r[3]===163||r.length>=12&&r[0]===82&&r[1]===73&&r[2]===70&&r[3]===70&&r[8]===65&&r[9]===86&&r[10]===73&&r[11]===32)return"video";if(r.length>=12&&r[0]===82&&r[1]===73&&r[2]===70&&r[3]===70&&r[8]===87&&r[9]===65&&r[10]===86&&r[11]===69||r[0]===73&&r[1]===68&&r[2]===51||r[0]===102&&r[1]===76&&r[2]===97&&r[3]===67||r[0]===79&&r[1]===103&&r[2]===103&&r[3]===83)return"audio";if(r[0]===80&&r[1]===75&&r[2]===3&&r[3]===4||r[0]===31&&r[1]===139||r[0]===82&&r[1]===97&&r[2]===114&&r[3]===33)return"archive"}}function aUe(r){return typeof r=="object"&&!Buffer.isBuffer(r)&&"data"in r}function W7t(r){return aUe(r)?r.data:r}function iUe(r){if(aUe(r))return r.altText}function K7t(r){return r.role==="user"||r.role==="assistant"||r.role==="system"?r.content.trim()===""?null:{role:r.role,content:r.content}:null}function e4(r){let e=[];if(r.rowCount!==void 0&&e.push(`${r.rowCount} data rows`),r.columnCount!==void 0&&e.push(`${r.columnCount} columns`),r.columnNames&&r.columnNames.length>0){let t=r.columnNames.join(", ");e.push(`Columns: [${t}]`)}return r.hasEmptyColumns&&e.push("\u26A0\uFE0F Contains empty column names"),e.length>0?`**Metadata**: ${e.join(" | ")}`:""}function cUe(r){return!!r.schema&&(r.output?.format==="json"||r.output?.format==="structured")}function lUe(r,e){if(!g.shouldLog("debug"))return;let t={},n=0;for(let o of r){let s=typeof o.content=="string"?o.content.length:0;t[o.role]=(t[o.role]||0)+1,n+=s}g.debug("[MessageBuilder] Composed",{requestId:e,totalMessages:r.length,roles:t,totalChars:n,estimatedTokens:Math.ceil(n/4)})}async function t4(r){let e=[],t=r.conversationMessages&&r.conversationMessages.length>0,n=r.systemPrompt?.trim()||"";if(t&&(n=`${n.trim()}${Qte}`),cUe(r)&&(n=`${n.trim()}${ere}`),n.trim()&&e.push({role:"system",content:n.trim(),providerOptions:{anthropic:{cacheControl:{type:"ephemeral"}}}}),t&&r.conversationMessages)for(let i of r.conversationMessages){let a=K7t(i);a&&e.push(a)}let o;if("prompt"in r&&r.prompt?o=r.prompt:"input"in r&&r.input?.text&&(o=r.input.text),"input"in r&&r.input){let i=r.input,a="",c="csvOptions"in r?r.csvOptions:void 0;if(i.csvFiles&&i.csvFiles.length>0)for(let l=0;l<i.csvFiles.length;l++){let u=i.csvFiles[l],d=Wy(u,l),p=typeof u=="string"?u:d;try{let f=await Td.detectAndProcess(u,{allowedTypes:["csv"],csvOptions:c}),h=`
@@ -1441,20 +1441,34 @@ class MagicBytesStrategy {
1441
1441
  if (this.isPDF(input)) {
1442
1442
  return this.result("pdf", "application/pdf", 95);
1443
1443
  }
1444
- // MP4/MOV: "ftyp" at offset 4
1444
+ // ISO-BMFF ("ftyp" at offset 4): MP4 video, QuickTime MOV, or M4A/M4B/M4P
1445
+ // audio all share this box — disambiguate by the major brand at offset 8-11,
1446
+ // otherwise an .m4a audio file is misrouted to the video pipeline.
1445
1447
  if (input.length >= 8 &&
1446
1448
  input[4] === 0x66 &&
1447
1449
  input[5] === 0x74 &&
1448
1450
  input[6] === 0x79 &&
1449
1451
  input[7] === 0x70) {
1452
+ const brand = input.length >= 12 ? input.toString("latin1", 8, 12) : "";
1453
+ if (/^(M4A|M4B|M4P|F4A|F4B)/.test(brand)) {
1454
+ return this.result("audio", "audio/mp4", 95);
1455
+ }
1456
+ if (brand.startsWith("qt")) {
1457
+ return this.result("video", "video/quicktime", 95);
1458
+ }
1450
1459
  return this.result("video", "video/mp4", 95);
1451
1460
  }
1452
- // MKV/WebM: EBML header
1461
+ // EBML container (MKV/WebM) both share the 0x1A45DFA3 header; the DocType
1462
+ // string in the header disambiguates WebM from generic Matroska.
1453
1463
  if (input.length >= 4 &&
1454
1464
  input[0] === 0x1a &&
1455
1465
  input[1] === 0x45 &&
1456
1466
  input[2] === 0xdf &&
1457
1467
  input[3] === 0xa3) {
1468
+ const head = input.toString("latin1", 0, Math.min(input.length, 64));
1469
+ if (head.includes("webm")) {
1470
+ return this.result("video", "video/webm", 92);
1471
+ }
1458
1472
  return this.result("video", "video/x-matroska", 90);
1459
1473
  }
1460
1474
  // AVI: "RIFF" + "AVI "
@@ -1488,7 +1502,13 @@ class MagicBytesStrategy {
1488
1502
  input[2] === 0x33) {
1489
1503
  return this.result("audio", "audio/mpeg", 95);
1490
1504
  }
1491
- // MP3: sync word
1505
+ // AAC (ADTS): 12-bit syncword 0xFFF with the 2 layer bits == 00. This must be
1506
+ // checked before the MP3 sync word below, because an ADTS header also satisfies
1507
+ // the looser 11-bit MPEG sync mask and would otherwise be mislabeled audio/mpeg.
1508
+ if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xf6) === 0xf0) {
1509
+ return this.result("audio", "audio/aac", 85);
1510
+ }
1511
+ // MP3: sync word (MPEG audio — layer bits are non-zero, unlike ADTS AAC above)
1492
1512
  if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xe0) === 0xe0) {
1493
1513
  return this.result("audio", "audio/mpeg", 80);
1494
1514
  }
@@ -1441,20 +1441,34 @@ class MagicBytesStrategy {
1441
1441
  if (this.isPDF(input)) {
1442
1442
  return this.result("pdf", "application/pdf", 95);
1443
1443
  }
1444
- // MP4/MOV: "ftyp" at offset 4
1444
+ // ISO-BMFF ("ftyp" at offset 4): MP4 video, QuickTime MOV, or M4A/M4B/M4P
1445
+ // audio all share this box — disambiguate by the major brand at offset 8-11,
1446
+ // otherwise an .m4a audio file is misrouted to the video pipeline.
1445
1447
  if (input.length >= 8 &&
1446
1448
  input[4] === 0x66 &&
1447
1449
  input[5] === 0x74 &&
1448
1450
  input[6] === 0x79 &&
1449
1451
  input[7] === 0x70) {
1452
+ const brand = input.length >= 12 ? input.toString("latin1", 8, 12) : "";
1453
+ if (/^(M4A|M4B|M4P|F4A|F4B)/.test(brand)) {
1454
+ return this.result("audio", "audio/mp4", 95);
1455
+ }
1456
+ if (brand.startsWith("qt")) {
1457
+ return this.result("video", "video/quicktime", 95);
1458
+ }
1450
1459
  return this.result("video", "video/mp4", 95);
1451
1460
  }
1452
- // MKV/WebM: EBML header
1461
+ // EBML container (MKV/WebM) both share the 0x1A45DFA3 header; the DocType
1462
+ // string in the header disambiguates WebM from generic Matroska.
1453
1463
  if (input.length >= 4 &&
1454
1464
  input[0] === 0x1a &&
1455
1465
  input[1] === 0x45 &&
1456
1466
  input[2] === 0xdf &&
1457
1467
  input[3] === 0xa3) {
1468
+ const head = input.toString("latin1", 0, Math.min(input.length, 64));
1469
+ if (head.includes("webm")) {
1470
+ return this.result("video", "video/webm", 92);
1471
+ }
1458
1472
  return this.result("video", "video/x-matroska", 90);
1459
1473
  }
1460
1474
  // AVI: "RIFF" + "AVI "
@@ -1488,7 +1502,13 @@ class MagicBytesStrategy {
1488
1502
  input[2] === 0x33) {
1489
1503
  return this.result("audio", "audio/mpeg", 95);
1490
1504
  }
1491
- // MP3: sync word
1505
+ // AAC (ADTS): 12-bit syncword 0xFFF with the 2 layer bits == 00. This must be
1506
+ // checked before the MP3 sync word below, because an ADTS header also satisfies
1507
+ // the looser 11-bit MPEG sync mask and would otherwise be mislabeled audio/mpeg.
1508
+ if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xf6) === 0xf0) {
1509
+ return this.result("audio", "audio/aac", 85);
1510
+ }
1511
+ // MP3: sync word (MPEG audio — layer bits are non-zero, unlike ADTS AAC above)
1492
1512
  if (input.length >= 2 && input[0] === 0xff && (input[1] & 0xe0) === 0xe0) {
1493
1513
  return this.result("audio", "audio/mpeg", 80);
1494
1514
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@juspay/neurolink",
3
- "version": "9.88.3",
3
+ "version": "9.88.4",
4
4
  "packageManager": "pnpm@10.15.1",
5
5
  "description": "TypeScript AI SDK with 24+ LLM providers behind one consistent API. MCP-native (58+ servers), voice TTS/STT/realtime, RAG, agents, memory, context compaction. OpenAI · Anthropic · Gemini · Bedrock · Azure · Ollama · DeepSeek · NVIDIA NIM and more.",
6
6
  "author": {