Files
igny8/frontend/dist/assets/js/date-Cc7ORwbK.js
IGNY8 VPS (Salman) 3c100be1cf more
2025-11-13 14:12:36 +00:00

6 lines
26 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import{R as Q,r as w,j as A}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{M as J}from"./index-ju2wdkG8.js";import{B as Y,T as Z}from"./main-af3pcbZa.js";const L=(x,y,o)=>{const S=(x==null?void 0:x.toLowerCase())||(y==null?void 0:y.toLowerCase())||"",v=(p,h)=>{var M;for(const I of h){const l=(M=I.message)==null?void 0:M.match(p);if(l&&l[1])return l[1]}return""};if(S.includes("cluster")){const p=v(/(\d+)\s+keyword/i,o||[]),h=v(/(\d+)\s+cluster/i,o||[]);return p&&h?`Clustering complete
${p} keyword${p!=="1"?"s":""} mapped and grouped into ${h} cluster${h!=="1"?"s":""}`:h?`Clustering complete
${h} cluster${h!=="1"?"s":""} created`:p?`Clustering complete
${p} keyword${p!=="1"?"s":""} mapped and grouped into clusters`:`Clustering complete
Keywords mapped and grouped into clusters`}if(S.includes("idea"))return v(/(\d+)\s+idea/i,o||[]),"Content ideas & outlines created successfully";if(S.includes("content")){const p=v(/(\d+)\s+task/i,o||[]),h=v(/(\d+)\s+article/i,o||[]);return h?`Article${h!=="1"?"s":""} drafted successfully — ${h} article${h!=="1"?"s":""} generated.`:p?`Article${p!=="1"?"s":""} drafted successfully — ${p} task${p!=="1"?"s":""} completed.`:"Article drafted successfully."}if(S.includes("image")&&S.includes("from")){const p=v(/(\d+)\s+image/i,o||[]);return p?`${p} image${p!=="1"?"s":""} generated successfully`:"Images generated successfully"}else if(S.includes("image")&&(S.includes("prompt")||S.includes("extract"))){const p=o==null?void 0:o.find(I=>I.stepName==="SAVE");if(p!=null&&p.message){const I=p.message.match(/Assigning (\d+)\s+Prompts/i);if(I){const l=parseInt(I[1],10),j=l>1?l-1:0;return j>0?`Featured Image and ${j} Inarticle Image Prompts ready for image generation`:"Featured Image Prompt ready for image generation"}}const h=o==null?void 0:o.find(I=>I.stepName==="PREP");if(h!=null&&h.message){const I=h.message.match(/Mapping Content for (\d+)\s+Image Prompts/i);if(I&&I[1]){const l=parseInt(I[1],10),j=l>1?l-1:0;return j>0?`Featured Image and ${j} Inarticle Image Prompts ready for image generation`:"Featured Image Prompt ready for image generation"}}const M=v(/(\d+)\s+prompt/i,o||[]);if(M){const I=parseInt(M,10),l=I>1?I-1:0;return l>0?`Featured Image and ${l} Inarticle Image Prompts ready for image generation`:"Featured Image Prompt ready for image generation"}return"Featured Image and X Inarticle Image Prompts ready for image generation"}return"Task completed successfully."},ee=(x,y)=>{const o=(x==null?void 0:x.toLowerCase())||(y==null?void 0:y.toLowerCase())||"";return o.includes("cluster")?[{phase:"INIT",label:"Validating keywords"},{phase:"PREP",label:"Loading keyword data"},{phase:"AI_CALL",label:"Generating clusters with Igny8 Semantic SEO Model"},{phase:"PARSE",label:"Organizing clusters"},{phase:"SAVE",label:"Saving clusters"}]:o.includes("idea")?[{phase:"INIT",label:"Verifying cluster integrity"},{phase:"PREP",label:"Loading cluster keywords"},{phase:"AI_CALL",label:"Generating ideas with Igny8 Semantic AI"},{phase:"PARSE",label:"High-opportunity ideas generated"},{phase:"SAVE",label:"Content Outline for Ideas generated"}]:o.includes("content")?[{phase:"INIT",label:"Validating task"},{phase:"PREP",label:"Preparing content idea"},{phase:"AI_CALL",label:"Writing article with Igny8 Semantic AI"},{phase:"PARSE",label:"Formatting content"},{phase:"SAVE",label:"Saving article"}]:o.includes("image")&&o.includes("from")?[{phase:"INIT",label:"Validating image prompts"},{phase:"PREP",label:"Preparing image generation queue"},{phase:"AI_CALL",label:"Generating images with AI"},{phase:"PARSE",label:"Processing image URLs"},{phase:"SAVE",label:"Saving image URLs"}]:o.includes("image")&&(o.includes("prompt")||o.includes("extract"))?[{phase:"INIT",label:"Checking content and image slots"},{phase:"PREP",label:"Mapping Content for X Image Prompts"},{phase:"AI_CALL",label:"Writing Featured Image Prompts"},{phase:"PARSE",label:"Writing X Inarticle Image Prompts"},{phase:"SAVE",label:"Assigning Prompts to Dedicated Slots"}]:[{phase:"INIT",label:"Initializing..."},{phase:"PREP",label:"Preparing..."},{phase:"AI_CALL",label:"Processing with Igny8 Semantic AI..."},{phase:"PARSE",label:"Processing results..."},{phase:"SAVE",label:"Saving results..."}]},te=(x,y)=>x.length>0?x[x.length-1].stepName||"":y<10?"INIT":y<25?"PREP":y<70?"AI_CALL":y<85?"PARSE":y<100?"SAVE":"DONE",re=(x,y,o)=>{const S=["INIT","PREP","AI_CALL","PARSE","SAVE","DONE"],v=S.indexOf(x);return S.indexOf(y)>v?!0:o.some(h=>h.stepName===x&&h.status==="success")};function ie({isOpen:x,title:y,percentage:o,status:S,message:v,onClose:p,onCancel:h,taskId:M,functionId:I,stepLogs:l=[]}){const[j,U]=Q.useState(new Set),z=w.useRef(new Map),F=w.useRef(new Set),_=w.useRef(""),D=w.useRef(""),E=w.useRef(0);w.useEffect(()=>{F.current=j},[j]);const C=j.size,V=w.useMemo(()=>ee(I,y),[I,y]),q=w.useMemo(()=>te(l,o),[l,o]),W=w.useMemo(()=>JSON.stringify(l.map(r=>({stepName:r.stepName,status:r.status}))),[l]),B=(r,s,N,i,k,e)=>{var d,m,$,G,O;const n=(k||e||"").toLowerCase(),u=(s==null?void 0:s.message)||N,c=t=>{const a=u.match(t);return a&&a[1]?a[1]:""};if(n.includes("cluster"))if(r==="INIT"){if(u&&u!==N&&u.includes("Validating")){const t=u.match(/(\d+)\s+more keyword/i);if(t){const f=3+parseInt(t[1],10);return`Validating ${f} keyword${f!==1?"s":""}`}for(const a of i){const b=(d=a.message)==null?void 0:d.match(/(\d+)\s+keyword/i);if(b){const f=parseInt(b[1],10);return`Validating ${f} keyword${f!==1?"s":""}`}}return u}for(const t of i){const a=(m=t.message)==null?void 0:m.match(/(\d+)\s+keyword/i);if(a){const b=parseInt(a[1],10);return`Validating ${b} keyword${b!==1?"s":""}`}}return N}else if(r==="PREP"){const t=c(/(\d+)\s+keyword/i);return t?`Loading ${t} keyword${t!=="1"?"s":""} for clustering`:u}else{if(r==="AI_CALL")return"Generating clusters with Igny8 Semantic SEO Model";if(r==="PARSE"){const t=c(/(\d+)\s+cluster/i);if(t)return`${t} cluster${t!=="1"?"s":""} created`;for(const a of i){const b=($=a.message)==null?void 0:$.match(/(\d+)\s+cluster/i);if(b&&b[1])return`${b[1]} cluster${b[1]!=="1"?"s":""} created`}return u}else if(r==="SAVE"){const t=c(/(\d+)\s+cluster/i);return t?`Saving ${t} cluster${t!=="1"?"s":""}`:u}}else if(n.includes("idea")){if(r==="INIT")return"Verifying cluster integrity";if(r==="PREP")return"Loading cluster keywords";if(r==="AI_CALL")return"Generating ideas with Igny8 Semantic AI";if(r==="PARSE"){const t=c(/(\d+)\s+idea/i);if(t)return`${t} high-opportunity idea${t!=="1"?"s":""} generated`;for(const a of i){const b=(G=a.message)==null?void 0:G.match(/(\d+)\s+idea/i);if(b&&b[1])return`${b[1]} high-opportunity idea${b[1]!=="1"?"s":""} generated`}return u}else if(r==="SAVE")return"Content Outline for Ideas generated"}else if(n.includes("content")){if(r==="AI_CALL")return"Writing article with Igny8 Semantic AI";if(r==="PARSE"){const t=c(/(\d+)\s+article/i);if(t)return`${t} article${t!=="1"?"s":""} created`}}else if(n.includes("image")&&n.includes("from")){if(r==="PREP"){const t=c(/(\d+)\s+image/i);if(t)return`Preparing to generate ${t} image${t!=="1"?"s":""}`;if(s!=null&&s.message){const a=s.message.match(/Preparing to generate (\d+)\s+image/i);if(a&&a[1])return`Preparing to generate ${a[1]} image${a[1]!=="1"?"s":""}`}return"Preparing image generation queue"}else if(r==="AI_CALL"){const t=(O=s==null?void 0:s.message)==null?void 0:O.match(/Generating.*image (\d+)/i);return t&&t[1]?`Generating image ${t[1]} with AI`:"Generating images with AI"}else if(r==="PARSE"){const t=c(/(\d+)\s+image/i);if(t)return`${t} image${t!=="1"?"s":""} generated successfully`;if(s!=null&&s.message){const a=s.message.match(/(\d+)\s+image.*generated/i);if(a&&a[1])return`${a[1]} image${a[1]!=="1"?"s":""} generated successfully`}return"Processing image URLs"}else if(r==="SAVE"){const t=c(/(\d+)\s+image/i);if(t)return`Saving ${t} image${t!=="1"?"s":""}`;if(s!=null&&s.message){const a=s.message.match(/Saved image (\d+)/i);if(a&&a[1])return`Saving image ${a[1]}`}return"Saving image URLs"}}else if(n.includes("image")&&(n.includes("prompt")||n.includes("extract")))if(r==="PREP"){const t=c(/(\d+)\s+Image Prompts/i)||c(/(\d+)\s+image/i);if(t)return`Mapping Content for ${t} Image Prompts`;if(s!=null&&s.message){const a=s.message.match(/Mapping Content for (\d+)\s+Image Prompts/i);if(a&&a[1])return`Mapping Content for ${a[1]} Image Prompts`}return"Mapping Content for X Image Prompts"}else{if(r==="AI_CALL")return"Writing Featured Image Prompts";if(r==="PARSE"){const t=c(/(\d+)\s+Inarticle/i)||c(/(\d+)\s+In-article/i);if(t)return`Writing ${t} Inarticle Image Prompts`;if(s!=null&&s.message){const a=s.message.match(/Writing (\d+)\s+In[-]article Image Prompts/i);if(a&&a[1])return`Writing ${a[1]} Inarticle Image Prompts`}return"Writing X Inarticle Image Prompts"}else if(r==="SAVE"){const t=c(/(\d+)\s+Prompts/i)||c(/(\d+)\s+prompt/i);if(t)return`Assigning ${t} Prompts to Dedicated Slots`;if(s!=null&&s.message){const a=s.message.match(/Assigning (\d+)\s+Prompts/i);if(a&&a[1])return`Assigning ${a[1]} Prompts to Dedicated Slots`}return"Assigning Prompts to Dedicated Slots"}}return u},H=w.useMemo(()=>V.map(r=>{re(r.phase,q,l);const s=j.has(r.phase),N=!1,i=l.find(e=>e.stepName===r.phase);return{label:B(r.phase,i,r.label,l,I,y),phase:r.phase,completed:s,inProgress:N}}),[V,q,l,j,I,y]),K=V.length>0&&V.every(r=>j.has(r.phase));w.useEffect(()=>{if(!x){U(new Set),F.current=new Set,_.current="",D.current="",E.current=0,z.current.forEach(e=>clearTimeout(e)),z.current.clear();return}const r=W!==_.current,s=q!==D.current,N=C>E.current;if(!r&&!s&&!N)return;_.current=W,D.current=q,E.current=C;const i=["INIT","PREP","AI_CALL","PARSE","SAVE","DONE"],k=S==="completed";for(let e=0;e<V.length;e++){const u=V[e].phase,c=i.indexOf(u),d=i.indexOf(q);if((k||d>c||l.some($=>$.stepName===u&&$.status==="success"))&&!F.current.has(u)&&!z.current.has(u)){const $=e>0?V[e-1]:null;if(!$||F.current.has($.phase)){const t=setTimeout(()=>{U(a=>{const b=new Set([...a,u]);return z.current.delete(u),b})},$?2e3:0);z.current.set(u,t);break}else break}}return()=>{z.current.forEach(e=>clearTimeout(e)),z.current.clear()}},[x,q,W,V,S,C]);const P=S==="completed"&&K,T=L(I,y,l);return A.jsx(J,{isOpen:x,onClose:p||(()=>{}),className:"max-w-lg",showCloseButton:!1,children:A.jsxs("div",{className:"p-6 min-h-[200px]",children:[A.jsxs("div",{className:"mb-6",children:[A.jsx("h3",{className:"text-lg font-semibold text-gray-900 dark:text-white mb-1 text-center",children:(()=>{var s;const r=(I||y||"").toLowerCase();if(r.includes("cluster")){const N=l.find(i=>i.stepName==="INIT");if(N!=null&&N.message){const i=N.message,k=i.match(/(\d+)\s+more keyword/i);if(k)return`Mapping ${3+parseInt(k[1],10)} Keywords into Keyword Clusters`;const e=i.match(/(\d+)\s+keyword/i);if(e)return`Mapping ${e[1]} Keywords into Keyword Clusters`}for(const i of l){const k=(s=i.message)==null?void 0:s.match(/(\d+)\s+keyword/i);if(k)return`Mapping ${k[1]} Keywords into Keyword Clusters`}}else{if(r.includes("idea"))return"Generating Content Ideas & Outline";if(r.includes("image")&&r.includes("from"))return"Generate Images";if(r.includes("image")&&(r.includes("prompt")||r.includes("extract")))return"Smart Image Prompts";if(r.includes("image"))return"Generate Images"}return y})()}),(()=>{const r=(I||y||"").toLowerCase();return r.includes("image")&&r.includes("from")?A.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center mt-1",children:"Generating images from prompts using AI"}):r.includes("image")&&(r.includes("prompt")||r.includes("extract"))?A.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 text-center mt-1",children:"Powered by Igny8 Visual Intelligence"}):null})(),!P&&S!=="completed"&&A.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 text-center",children:(()=>{const r=(I||y||"").toLowerCase();if(r.includes("image")&&r.includes("from")){const s=l.find(i=>i.stepName===q);if(s!=null&&s.message)return s.message;const N=V.find(i=>i.phase===q);return(N==null?void 0:N.label)||"Generating images..."}return v})()}),S==="completed"&&!K&&A.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400 text-center",children:"Processing..."}),(S==="processing"||S==="completed"&&!K)&&A.jsx("div",{className:"flex justify-center mt-4",children:A.jsxs("svg",{className:"w-8 h-8 text-brand-500 animate-spin",fill:"none",viewBox:"0 0 24 24",children:[A.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),A.jsx("path",{className:"opacity-75",fill:"currentColor",d:"M4 12a8 8 0 018-8V0C5.373 0 0 5.373 0 12h4zm2 5.291A7.962 7.962 0 014 12H0c0 3.042 1.135 5.824 3 7.938l3-2.647z"})]})})]}),P&&A.jsxs("div",{className:"mb-6",children:[A.jsx("div",{className:"flex justify-center mb-4",children:A.jsx("div",{className:"w-16 h-16 rounded-full bg-green-600 dark:bg-green-700 flex items-center justify-center",children:A.jsx("svg",{className:"w-10 h-10 text-white",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})})})}),A.jsx("div",{className:"p-5 rounded-lg bg-green-600 dark:bg-green-700 border border-green-700 dark:border-green-600",children:A.jsx("div",{className:"text-base font-semibold text-white text-center whitespace-pre-line",children:T})})]}),A.jsx("div",{className:"mb-6 space-y-3",children:H.map((r,s)=>A.jsxs("div",{className:`flex items-center gap-3 p-3 rounded-lg border transition-all ${r.completed?"bg-green-50 dark:bg-green-900/20 border-green-200 dark:border-green-800":"bg-gray-50 dark:bg-gray-800 border-gray-200 dark:border-gray-700 opacity-60"}`,children:[A.jsx("div",{className:"flex-shrink-0",children:r.completed?A.jsx("svg",{className:"w-5 h-5 text-green-600 dark:text-green-400",fill:"currentColor",viewBox:"0 0 20 20",children:A.jsx("path",{fillRule:"evenodd",d:"M16.707 5.293a1 1 0 010 1.414l-8 8a1 1 0 01-1.414 0l-4-4a1 1 0 011.414-1.414L8 12.586l7.293-7.293a1 1 0 011.414 0z",clipRule:"evenodd"})}):A.jsx("div",{className:"w-5 h-5 rounded-full border-2 border-gray-300 dark:border-gray-600"})}),A.jsx("span",{className:`flex-1 text-sm font-medium ${r.completed?"text-green-800 dark:text-green-300":"text-gray-500 dark:text-gray-400"}`,children:r.label})]},s))}),P&&p&&A.jsx("div",{className:"flex justify-center mt-6",children:A.jsx(Y,{variant:"primary",size:"lg",onClick:p,className:"bg-green-600 hover:bg-green-700 dark:bg-green-700 dark:hover:bg-green-800 text-white px-8 py-3 text-base font-semibold",children:"Close"})}),h&&!P&&S!=="error"&&A.jsx("div",{className:"flex justify-end gap-3 mt-6",children:A.jsx(Y,{variant:"secondary",size:"sm",onClick:h,disabled:S==="processing",children:"Cancel"})}),S==="error"&&p&&A.jsx("div",{className:"flex justify-end gap-3 mt-6",children:A.jsx(Y,{variant:"primary",size:"sm",onClick:p,children:"Dismiss"})})]})})}function ce(){const[x,y]=w.useState(!1),[o,S]=w.useState(null),[v,p]=w.useState(""),[h,M]=w.useState(void 0),[I,l]=w.useState({percentage:0,message:"Initializing...",status:"pending"}),[j,U]=w.useState([]),[z,F]=w.useState(void 0),_=w.useRef(0),D=w.useRef(null),E=w.useRef(null),C=w.useRef(null),V=(P,T="",r=[])=>{const s=(P==null?void 0:P.toUpperCase())||"",N=T.toLowerCase(),i=(t,a)=>{const b=a.match(t);return b&&b[1]?b[1]:""};let k=i(/(\d+)\s+keyword/i,T),e=i(/(\d+)\s+cluster/i,T),n=i(/(\d+)\s+task/i,T),u=i(/(\d+)\s+item/i,T);if(!k&&!n&&!u){const t=i(/loaded\s+(\d+)\s+items?/i,T);t&&(u=t)}if(!e){const t=i(/created\s+(\d+)\s+clusters?/i,T);t&&(e=t)}if(!k&&!n&&!u)for(const t of r){const a=t.message||"";if(k||(k=i(/(\d+)\s+keyword/i,a)),n||(n=i(/(\d+)\s+task/i,a)),u||(u=i(/loaded\s+(\d+)\s+items?/i,a)),e||(e=i(/(\d+)\s+cluster/i,a)||i(/created\s+(\d+)\s+clusters?/i,a)),(k||n||u)&&e)break}const c=k,d=e,m=n||u,$=N.includes("content")||N.includes("generating content")||N.includes("article"),G=N.includes("cluster")&&!N.includes("content"),O=N.includes("idea");return s.includes("INIT")||s.includes("INITIALIZ")?{percentage:0,friendlyMessage:"Getting started..."}:s.includes("PREP")||s.includes("PREPAR")?$?{percentage:10,friendlyMessage:m?`Preparing ${m} task${m!=="1"?"s":""}...`:"Preparing content generation..."}:G?{percentage:16,friendlyMessage:c?`Preparing ${c} keyword${c!=="1"?"s":""}...`:"Preparing your keywords..."}:O?{percentage:10,friendlyMessage:d?`Preparing ${d} cluster${d!=="1"?"s":""}...`:"Preparing clusters..."}:{percentage:10,friendlyMessage:"Preparing..."}:s.includes("AI_CALL")||s.includes("CALLING")?$?{percentage:50,friendlyMessage:"Writing article with Igny8 Semantic AI..."}:G?{percentage:50,friendlyMessage:"Generating clusters with Igny8 Semantic SEO Model..."}:O?{percentage:50,friendlyMessage:"Generating ideas with Igny8 Semantic AI..."}:{percentage:50,friendlyMessage:"Processing with Igny8 Semantic AI..."}:s.includes("PARSE")||s.includes("PARSING")?$?{percentage:70,friendlyMessage:"Processing content..."}:G?{percentage:70,friendlyMessage:"Organizing results..."}:O?{percentage:70,friendlyMessage:"Processing ideas..."}:{percentage:70,friendlyMessage:"Processing results..."}:s.includes("SAVE")||s.includes("SAVING")||s.includes("CREAT")&&!s.includes("CONTENT")?$?{percentage:85,friendlyMessage:m?`Saving content for ${m} task${m!=="1"?"s":""}...`:"Saving content..."}:G?{percentage:85,friendlyMessage:d?`Saving ${d} cluster${d!=="1"?"s":""}...`:"Saving clusters..."}:O?{percentage:85,friendlyMessage:m?`Saving ${m} idea${m!=="1"?"s":""}...`:"Saving ideas..."}:{percentage:85,friendlyMessage:"Saving results..."}:s.includes("DONE")||s.includes("COMPLETE")?$?{percentage:100,friendlyMessage:m?`Done! Generated content for ${m} task${m!=="1"?"s":""}`:"Done! Content generation complete"}:G?{percentage:100,friendlyMessage:c&&d?`Done! Created ${d} cluster${d!=="1"?"s":""} from ${c} keyword${c!=="1"?"s":""}`:c?`Done! Processed ${c} keyword${c!=="1"?"s":""}`:d?`Done! Created ${d} cluster${d!=="1"?"s":""}`:"Done! Clustering complete"}:O?{percentage:100,friendlyMessage:m?`Done! Generated ${m} idea${m!=="1"?"s":""}`:"Done! Ideas generation complete"}:{percentage:100,friendlyMessage:"Done! Task complete"}:{percentage:_.current,friendlyMessage:T||"Processing..."}};w.useEffect(()=>{if(!o||!x||o.startsWith("temp-"))return;let P=null,T=0,r=!1;const s=300,N=async()=>{if(!r)try{if(T++,T>s){l({percentage:0,message:"Task is taking longer than expected. Please check manually.",status:"error"}),r=!0,P&&(clearInterval(P),P=null);return}const i=await Z(`/v1/system/settings/task_progress/${o}/`),k=()=>{C.current&&(clearInterval(C.current),C.current=null),_.current<80&&(C.current=setInterval(()=>{l(n=>{if(n.status!=="processing")return C.current&&(clearInterval(C.current),C.current=null),n;const u=_.current;if(u<80){const c=Math.min(u+1,80);return _.current=c,c>=80&&C.current&&(clearInterval(C.current),C.current=null),{...n,percentage:c}}else return C.current&&(clearInterval(C.current),C.current=null),n})},350))};if(i.state==="PROGRESS"){const e=i.meta||{};let n=null;const u=[...e.request_steps||[],...e.response_steps||[]];if(u.length>0){const g=[...u].sort((R,X)=>(X.stepNumber||0)-(R.stepNumber||0))[0];if(g&&g.stepName){const R=g.stepName.toUpperCase();R.includes("INIT")?n="INIT":R.includes("PREP")?n="PREP":R.includes("AI_CALL")||R.includes("CALL")?n="AI_CALL":R.includes("PARSE")?n="PARSE":R.includes("SAVE")||R.includes("CREAT")?n="SAVE":R.includes("DONE")||R.includes("COMPLETE")?n="DONE":n=R}}if(!n){const f=(e.phase||"").toUpperCase(),g=(e.message||"").toLowerCase();f==="INIT"||f.includes("INIT")?n="INIT":f==="PREP"||f.includes("PREP")?n="PREP":f==="AI_CALL"||f.includes("AI_CALL")||f.includes("CALL")?n="AI_CALL":f==="PARSE"||f.includes("PARSE")?n="PARSE":f==="SAVE"||f.includes("SAVE")||f.includes("CREAT")?n="SAVE":f==="DONE"||f.includes("DONE")||f.includes("COMPLETE")?n="DONE":g.includes("initializ")||g.includes("getting started")?n="INIT":g.includes("prepar")||g.includes("loading")?n="PREP":g.includes("generating")||g.includes("analyzing")||g.includes("finding related")?n="AI_CALL":g.includes("pars")||g.includes("organizing")||g.includes("processing content")?n="PARSE":g.includes("sav")||g.includes("creat")||g.includes("cluster")&&!g.includes("content")?n="SAVE":(g.includes("done")||g.includes("complet"))&&(n="DONE")}const c=e.message||"",d=`${v} ${c}`,m=V(n||"",d,u),$=e.percentage!==void 0?e.percentage:null,G=$!==null?$:m.percentage,O=m.friendlyMessage,t=D.current!==n,a=_.current;C.current&&(clearInterval(C.current),C.current=null),E.current&&(clearTimeout(E.current),E.current=null);const b=Math.max(G,a);if(b>a){let f=a;const g=()=>{if(f<b){const R=b-f,X=R<=5?1:Math.min(2,Math.ceil(R/10));f=Math.min(f+X,b),_.current=f,l({percentage:f,message:O,status:"processing",details:{current:e.current||0,total:e.total||0,completed:e.completed||0,currentItem:e.current_item,phase:e.phase}}),f<b?E.current=setTimeout(g,150):(E.current=null,b<80&&k())}};t&&D.current!==null?E.current=setTimeout(()=>{D.current=n,g()},200):(D.current=n,g())}else D.current=n,l(f=>({...f,message:O,details:{current:e.current||0,total:e.total||0,completed:e.completed||0,currentItem:e.current_item,phase:e.phase}})),a<80&&b===a&&k();if(e.image_queue&&Array.isArray(e.image_queue)&&F(e.image_queue),e.request_steps||e.response_steps){const f=[];e.request_steps&&Array.isArray(e.request_steps)&&e.request_steps.forEach(g=>{f.push({stepNumber:g.stepNumber||0,stepName:g.stepName||"Unknown",status:g.status||"success",message:g.message||"",timestamp:g.timestamp})}),e.response_steps&&Array.isArray(e.response_steps)&&e.response_steps.forEach(g=>{f.push({stepNumber:g.stepNumber||0,stepName:g.stepName||"Unknown",status:g.status||"success",message:g.message||"",timestamp:g.timestamp})}),f.sort((g,R)=>g.stepNumber-R.stepNumber),U(f)}}else if(i.state==="SUCCESS"){const e=i.meta||{};E.current&&(clearTimeout(E.current),E.current=null);const n=e.message||"",u=[...e.request_steps||[],...e.response_steps||[]],c=V("DONE",n,u);if(D.current="DONE",_.current=100,l({percentage:100,message:c.friendlyMessage,status:"completed",details:e.details}),e.request_steps||e.response_steps){const d=[];e.request_steps&&Array.isArray(e.request_steps)&&e.request_steps.forEach(m=>{d.push({stepNumber:m.stepNumber||0,stepName:m.stepName||"Unknown",status:m.status||"success",message:m.message||"",timestamp:m.timestamp})}),e.response_steps&&Array.isArray(e.response_steps)&&e.response_steps.forEach(m=>{d.push({stepNumber:m.stepNumber||0,stepName:m.stepName||"Unknown",status:m.status||"success",message:m.message||"",timestamp:m.timestamp})}),d.sort((m,$)=>m.stepNumber-$.stepNumber),U(d)}r=!0,P&&(clearInterval(P),P=null)}else if(i.state==="FAILURE"){const e=i.meta||{},n=e.error||e.message||i.error||"Task failed - exception details unavailable",u=e.error_type||"Error";if(l({percentage:0,message:n.includes("exception details unavailable")?n:`Error: ${n}`,status:"error",details:e.error_type?`${u}: ${n}`:n}),e.request_steps||e.response_steps){const c=[];e.request_steps&&Array.isArray(e.request_steps)&&e.request_steps.forEach(d=>{c.push({stepNumber:d.stepNumber||0,stepName:d.stepName||"Unknown",status:d.status||"error",message:d.message||"",timestamp:d.timestamp})}),e.response_steps&&Array.isArray(e.response_steps)&&e.response_steps.forEach(d=>{c.push({stepNumber:d.stepNumber||0,stepName:d.stepName||"Unknown",status:d.status||"error",message:d.message||"",timestamp:d.timestamp})}),c.sort((d,m)=>d.stepNumber-m.stepNumber),U(c)}r=!0,P&&(clearInterval(P),P=null)}else l({percentage:0,message:"Task is starting...",status:"pending"})}catch(i){if(console.error("Error polling task status:",i),T>5){let k=i.message||"Unknown error";k.includes("HTTP_ERROR")&&(k=k.replace(/^API Error \(\d+\): HTTP_ERROR - /,"").trim()||"Server error"),l({percentage:0,message:`Error checking task status: ${k}`,status:"error"}),r=!0,P&&(clearInterval(P),P=null)}}};return N(),P=setInterval(()=>{r||N()},2e3),()=>{r=!0,P&&(clearInterval(P),P=null),E.current&&(clearTimeout(E.current),E.current=null),C.current&&(clearInterval(C.current),C.current=null),_.current=0,D.current=null}},[o,x]);const q=w.useCallback((P,T,r)=>{E.current&&(clearTimeout(E.current),E.current=null),C.current&&(clearInterval(C.current),C.current=null),_.current=0,D.current=null,U([]),S(P),p(T),M(r),y(!0),l({percentage:0,message:"Getting started...",status:"pending"})},[]),W=w.useCallback(P=>{S(P),l({percentage:0,message:"Initializing...",status:"pending"})},[]),B=w.useCallback(()=>{E.current&&(clearTimeout(E.current),E.current=null),C.current&&(clearInterval(C.current),C.current=null),_.current=0,D.current=null,U([]),F(void 0),y(!1),S(null),p("")},[]),H=w.useCallback(P=>{l({percentage:0,message:P,status:"error"})},[]),K=w.useCallback(()=>{E.current&&(clearTimeout(E.current),E.current=null),C.current&&(clearInterval(C.current),C.current=null),_.current=0,D.current=null,l({percentage:0,message:"Getting started...",status:"pending"}),U([]),F(void 0),S(null),p(""),y(!1)},[]);return{progress:I,isOpen:x,openModal:q,updateTaskId:W,closeModal:B,setError:H,reset:K,title:v,taskId:o,functionId:h,stepLogs:j,imageQueue:z}}const le={key:"title",label:"Title",sortable:!0,width:"auto"},ue={key:"keyword",label:"Keyword",sortable:!0,width:"auto"},oe={key:"status",label:"Status",sortable:!0,badge:!0,width:"120px"},de={key:"volume",label:"Volume",sortable:!0,numeric:!0,width:"100px"},me={key:"difficulty",label:"Difficulty",sortable:!0,badge:!0,width:"120px"},ge={key:"intent",label:"Intent",sortable:!0,badge:!0,width:"120px"},fe={key:"cluster",label:"Cluster",sortable:!0,width:"200px"},pe={key:"created_at",label:"Created",sortable:!0,date:!0,width:"150px"},he={key:"word_count",label:"Word Count",sortable:!0,numeric:!0,width:"120px"},ye={key:"sector_name",label:"Sector",sortable:!1,width:"150px"};function Ie(x){if(!x)return"Today";const y=typeof x=="string"?new Date(x):x;if(isNaN(y.getTime()))return"Today";const o=new Date,S=new Date(o.getFullYear(),o.getMonth(),o.getDate()),v=new Date(y.getFullYear(),y.getMonth(),y.getDate()),p=S.getTime()-v.getTime(),h=Math.floor(p/(1e3*60*60*24));if(h===0)return"Today";if(h===1)return"Yesterday";if(h<30)return`${h} days ago`;if(h<365){const M=Math.floor(h/30),I=h%30;return I===0?`${M} month${M>1?"s":""} ago`:`${M} month${M>1?"s":""} ${I} day${I>1?"s":""} ago`}else{const M=Math.floor(h/365),I=Math.floor(h%365/30);return I===0?`${M} year${M>1?"s":""} ago`:`${M} year${M>1?"s":""} ${I} month${I>1?"s":""} ago`}}export{ie as P,oe as a,pe as b,fe as c,me as d,Ie as f,ge as i,ue as k,ye as s,le as t,ce as u,de as v,he as w};