#!/usr/bin/env node
import{a as v}from"./chunk-RLNOQILG.js";import{a as x,b}from"./chunk-GTNBSMZR.js";import{spawnSync as c}from"node:child_process";import{existsSync as P}from"node:fs";import{dirname as k,join as M}from"node:path";import{fileURLToPath as S}from"node:url";var L={name:"ag-convert v2.3.1 (Hyperion Phase 4: Visual Intelligence)",summary:"Intelligent document and image-to-markdown converter with AI vision",usage:"ag-convert [OPTIONS] <FILE>",description:["Convert documents using smart routing between IBM Docling (precision) and","Microsoft MarkItDown (speed). Phase 4 adds AI-powered visual intelligence","for images with multi-provider LLM support and specialized vision modes.","","Smart Routing Criteria:","  - PDFs >1MB or with tables \u2192 Docling (high precision)","  - Images, Office docs, simple files \u2192 MarkItDown (fast)","","Phase 4 Visual Intelligence:","  - Multi-provider LLM support (OpenAI, Anthropic, Google, Local)","  - Specialized vision modes (OCR, diagram, chart, UI analysis)","  - Custom vision prompts for tailored image descriptions","","This is a 'superpower' command that requires a host Python environment","with 'docling' and 'markitdown' installed."],options:["    --analyze         Show complexity analysis without converting","    --engine <auto|docling|markitdown>","                      Override smart routing (default: auto)","    --high-fidelity   Favor precision over speed (influences routing)","    --json            Output raw structured JSON instead of Markdown","","  Phase 4: Visual Intelligence","    --describe-images Use LLM to describe images","    --llm-provider <openai|anthropic|google|local|azure>","                      LLM provider (default: openai)","    --llm-model <name>","                      Specific model (e.g., gpt-4o, claude-3-5-sonnet)","    --vision-mode <default|ocr|diagram|chart|screenshot|document|technical>","                      Prompt template for image analysis","    --vision-prompt <text>","                      Custom vision prompt (overrides --vision-mode)","","  Other","    --setup           Attempt to install required Python dependencies","    --help            Display this help and exit"],examples:["# Basic conversion","ag-convert report.pdf                    # Auto-selects best engine","ag-convert data.xlsx --analyze           # Show complexity score","","# Phase 4: Visual Intelligence","ag-convert photo.jpg --describe-images   # AI-powered image description","ag-convert diagram.png --describe-images --vision-mode diagram","ag-convert chart.png --vision-mode chart --llm-provider anthropic","ag-convert scan.jpg --vision-mode ocr    # Extract text from image","ag-convert ui.png --vision-mode screenshot --llm-model claude-3-5-sonnet","","# Setup","ag-convert --setup                       # Install dependencies"]},R={name:"ag-convert",async execute(t,r){if(b(t))return x(L);if(t.includes("--setup"))return O();let d="auto",a=!1,o=!1,i=!1,l=!1,p="openai",m=null,f="default",g=null,h=[];for(let e=0;e<t.length;e++){let n=t[e];n==="--engine"?d=t[++e]:n==="--high-fidelity"?a=!0:n==="--json"?o=!0:n==="--analyze"?i=!0:n==="--describe-images"?l=!0:n==="--llm-provider"?p=t[++e]:n==="--llm-model"?m=t[++e]:n==="--vision-mode"?f=t[++e]:n==="--vision-prompt"?g=t[++e]:n.startsWith("-")||h.push(n)}if(h.length===0)return{stdout:"",stderr:`ag-convert: missing file operand
Try 'ag-convert --help' for more information.
`,exitCode:2};let I=k(S(import.meta.url)),u=r.fs.resolvePath(r.cwd,h[0]),y=u;if(typeof r.fs.toRealPath=="function"){let e=r.fs.toRealPath(u);e&&(y=e)}if(!await r.fs.exists(u))return{stdout:"",stderr:`Error: File not found: ${u}
`,exitCode:1};let w=M(I,"hyperion_bridge.py");if(!P(w))return{stdout:"",stderr:`ag-convert: internal error: configuration missing
`,exitCode:1};let C="python3",s=[w,y,"--engine",d];a&&s.push("--high-fidelity"),o&&s.push("--json"),i&&s.push("--analyze"),l&&s.push("--describe-images"),p&&l&&s.push("--llm-provider",p),m&&l&&s.push("--llm-model",m),f&&l&&s.push("--vision-mode",f),g&&l&&s.push("--vision-prompt",g);try{let e=c(C,s,{encoding:"utf-8",maxBuffer:52428800,env:{...process.env}});return e.error?{stdout:"",stderr:`ag-convert: failed to execute python3: ${v(e.error.message)}
`,exitCode:1}:{stdout:e.stdout,stderr:e.stderr,exitCode:e.status??0}}catch(e){return{stdout:"",stderr:`ag-convert: error: ${v(e.message)}
`,exitCode:1}}}};function O(){let t="python3";try{let i=c("python3",["-c","import sys; print(sys.executable)"],{encoding:"utf-8"});i.status===0&&i.stdout.trim()&&(t=i.stdout.trim())}catch{}let r=["/opt/homebrew/bin/uv","/usr/local/bin/uv","/opt/homebrew/Caskroom/miniconda/base/bin/uv",`${process.env.HOME}/.cargo/bin/uv`],d="uv",a=!1;try{c("uv",["--version"]).status===0&&(a=!0)}catch{}if(!a){for(let i of r)if(P(i)){d=i,a=!0;break}}let o;return a&&(o=c(d,["pip","install","--system","--python",t,"docling","markitdown"],{encoding:"utf-8",shell:!0,env:{...process.env}})),(!o||o.status!==0)&&(o&&o.status,o=c(t,["-m","pip","install","docling","markitdown","--break-system-packages"],{encoding:"utf-8",shell:!0,env:{...process.env}})),o.status===0?{stdout:`Successfully installed docling and markitdown.
`,stderr:"",exitCode:0}:{stdout:"",stderr:`Setup failed:
${o.stderr}
Please install manually using uv: uv pip install docling markitdown
`,exitCode:1}}export{R as a};
