6 lines
56 KiB
JavaScript
6 lines
56 KiB
JavaScript
import{r as o,j as e}from"./chunk-UIGDSWPH-BhuNDbxn.js";import{T as H,u as se,B as $,L as W,a6 as te,P as de}from"./main-af3pcbZa.js";import{S as le}from"./Switch-BQnuu7S6.js";import{M as ce}from"./index-ju2wdkG8.js";import{F as ge}from"./FormModal-DkhE3zPR.js";import{S as q}from"./SelectDropdown-C8sZwHi_.js";import{A as me}from"./Alert-BeBw6uu9.js";function oe(I){const{resourceId:t,getEndpoint:d,saveEndpoint:n,initialEnabled:c=!1,extractEnabled:p=x=>(x==null?void 0:x.enabled)??!1,buildPayload:u=(x,C)=>({...x,enabled:C}),onToggleSuccess:y,onToggleError:v,loadOnMount:L=!0}=I,[_,N]=o.useState(c),[M,j]=o.useState(!1),[S,k]=o.useState(null),[w,i]=o.useState(null),E=o.useCallback(async()=>{j(!0),k(null);try{const x=d.replace("{id}",t),C=await H(x);if(C.success&&C.data){const A=C.data;i(A);const z=p(A);N(z)}else i({}),N(c)}catch(x){const C=x instanceof Error?x:new Error(String(x));k(C),console.error(`Error loading state for ${t}:`,C)}finally{j(!1)}},[t,d,p,c]),T=o.useCallback(async x=>{j(!0),k(null);try{const C=n.replace("{id}",t),A=u(w||{},x),z=await H(C,{method:"POST",body:JSON.stringify(A)});if(z.success){const U={...w||{},enabled:x};i(U),N(x),y&&y(x,U)}else throw new Error(z.error||"Failed to save state")}catch(C){const A=C instanceof Error?C:new Error(String(C));k(A),console.error(`Error saving state for ${t}:`,A),v&&v(A)}finally{j(!1)}},[t,n,u,w,y,v]),Z=o.useCallback(async x=>{await T(x)},[T]),F=o.useCallback(async()=>{await E()},[E]);return o.useEffect(()=>{L&&E()},[L]),{enabled:_,toggle:Z,loading:M,error:S,data:w,refresh:F}}function re({icon:I,title:t,description:d,enabled:n,validationStatus:c,onToggle:p,onSettings:u,onDetails:y,integrationId:v,getEndpoint:L,saveEndpoint:_,onToggleSuccess:N,onToggleError:M,modelName:j}){const S=se(),k=v?oe({resourceId:v,getEndpoint:L||"/v1/system/settings/integrations/{id}/",saveEndpoint:_||"/v1/system/settings/integrations/{id}/save/",initialEnabled:!1,onToggleSuccess:(x,C)=>{S.success(`${v} ${x?"enabled":"disabled"}`),N&&N(x,C)},onToggleError:x=>{S.error(`Failed to update ${v}: ${x.message}`),M&&M(x)}}):null,w=k?k.enabled:n??!1,i=k?x=>{k.toggle(x)}:x=>{p&&p(x)},E=k?k.loading:!1,T=()=>!w||c==="not_configured"?"bg-gray-400 dark:bg-gray-500":c==="pending"?"bg-gray-400 dark:bg-gray-500 animate-pulse":c==="success"?"bg-green-500 dark:bg-green-600":c==="error"?"bg-red-500 dark:bg-red-600":"bg-gray-400 dark:bg-gray-500",F=!w||c==="not_configured"?{text:"Disabled",color:"text-gray-400 dark:text-gray-500",bold:!1}:c==="pending"?{text:"Pending",color:"text-gray-400 dark:text-gray-500",bold:!1}:c==="success"?{text:"Enabled",color:"text-gray-800 dark:text-white",bold:!0}:c==="error"?{text:"Error",color:"text-red-600 dark:text-red-400",bold:!1}:{text:"Disabled",color:"text-gray-400 dark:text-gray-500",bold:!1};return e.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[e.jsxs("div",{className:"relative p-5 pb-9",children:[e.jsx("div",{className:"mb-5 inline-flex h-10 w-10 items-center justify-center",children:I}),e.jsx("h3",{className:"mb-3 text-lg font-semibold text-gray-800 dark:text-white/90",children:t}),e.jsx("p",{className:"max-w-xs text-sm text-gray-500 dark:text-gray-400",children:d}),v==="runware"?e.jsx("div",{className:"absolute top-5 right-5",children:e.jsx("span",{className:`text-sm font-semibold ${j?"text-gray-800 dark:text-white":"text-gray-400 dark:text-gray-500"}`,children:j||"Disabled"})}):e.jsxs("div",{className:"absolute top-5 right-5 flex items-center gap-2",children:[e.jsx("span",{className:`text-sm ${F.color} ${F.bold?"font-bold":""} transition-colors duration-200`,children:F.text}),e.jsx("div",{className:`w-[25px] h-[25px] rounded-full ${T()} transition-colors duration-200`,title:c==="not_configured"?"Not configured":c==="pending"?"Validating...":c==="success"?"Validated successfully":c==="error"?"Validation failed":"Unknown status"})]})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 p-5 dark:border-gray-800",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx($,{variant:"outline",size:"md",onClick:u,className:"shadow-theme-xs inline-flex h-11 w-11 items-center justify-center rounded-lg border border-gray-300 text-gray-700 dark:border-gray-700 dark:text-gray-400",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[e.jsx("path",{d:"M5.64615 4.59906C5.05459 4.25752 4.29808 4.46015 3.95654 5.05171L2.69321 7.23986C2.35175 7.83128 2.5544 8.58754 3.14582 8.92899C3.97016 9.40493 3.97017 10.5948 3.14583 11.0707C2.55441 11.4122 2.35178 12.1684 2.69323 12.7598L3.95657 14.948C4.2981 15.5395 5.05461 15.7422 5.64617 15.4006C6.4706 14.9247 7.50129 15.5196 7.50129 16.4715C7.50129 17.1545 8.05496 17.7082 8.73794 17.7082H11.2649C11.9478 17.7082 12.5013 17.1545 12.5013 16.4717C12.5013 15.5201 13.5315 14.9251 14.3556 15.401C14.9469 15.7423 15.7029 15.5397 16.0443 14.9485L17.3079 12.7598C17.6494 12.1684 17.4467 11.4121 16.8553 11.0707C16.031 10.5948 16.031 9.40494 16.8554 8.92902C17.4468 8.58757 17.6494 7.83133 17.3079 7.23992L16.0443 5.05123C15.7029 4.45996 14.9469 4.25737 14.3556 4.59874C13.5315 5.07456 12.5013 4.47961 12.5013 3.52798C12.5013 2.84515 11.9477 2.2915 11.2649 2.2915L8.73795 2.2915C8.05496 2.2915 7.50129 2.84518 7.50129 3.52816C7.50129 4.48015 6.47059 5.07505 5.64615 4.59906Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M12.5714 9.99977C12.5714 11.4196 11.4204 12.5706 10.0005 12.5706C8.58069 12.5706 7.42969 11.4196 7.42969 9.99977C7.42969 8.57994 8.58069 7.42894 10.0005 7.42894C11.4204 7.42894 12.5714 8.57994 12.5714 9.99977Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),e.jsx($,{variant:"outline",size:"md",onClick:y,className:"shadow-theme-xs inline-flex h-11 items-center justify-center rounded-lg border border-gray-300 px-4 py-3 text-sm font-medium text-gray-700 dark:border-gray-700 dark:text-gray-400",children:"Details"})]}),e.jsx(le,{label:"",checked:w,disabled:E,onChange:i})]})]})}function ne({title:I,description:t,integrationId:d,icon:n}){var N;const[c,p]=o.useState(!1),[u,y]=o.useState(null),[v,L]=o.useState(!1);if(d!=="openai"&&d!=="runware")return null;const _=async(M=!1)=>{p(!0),L(M),y(null);try{const j=await H(`/v1/system/settings/integrations/${d}/`);let S="",k="gpt-4.1";if(j.success&&j.data&&(S=j.data.apiKey||"",k=j.data.model||"gpt-4.1"),!S){y({success:!1,message:"API key not configured. Please configure your API key in settings first."}),p(!1);return}const w={apiKey:S};d==="openai"&&(w.config={model:k,with_response:M});const i=await H(`/v1/system/settings/integrations/${d}/test/`,{method:"POST",body:JSON.stringify(w)});i.success?y({success:!0,message:i.message||"API connection successful!",model_used:i.model_used||i.model,response:i.response,tokens_used:i.tokens_used,total_tokens:i.total_tokens,cost:i.cost,full_response:i.full_response||{image_url:i.image_url,provider:i.provider,size:i.size}}):y({success:!1,message:i.error||i.message||"API connection failed"})}catch(j){y({success:!1,message:`API connection failed: ${j.message||"Unknown error"}`})}finally{p(!1)}};return e.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[e.jsxs("div",{className:"relative p-5 pb-6",children:[e.jsx("h3",{className:"mb-2 text-base font-semibold text-gray-800 dark:text-white/90",children:I}),t&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t})]}),e.jsx("div",{className:"border-t border-gray-200 p-5 dark:border-gray-800",children:e.jsxs("div",{className:"space-y-4",children:[e.jsx("div",{className:"flex gap-3",children:d==="openai"?e.jsxs(e.Fragment,{children:[e.jsx($,{variant:"outline",onClick:()=>_(!1),disabled:c,className:"flex-1",children:c&&!v?"Testing...":"Test OpenAI Connection"}),e.jsx($,{variant:"outline",onClick:()=>_(!0),disabled:c,className:"flex-1",children:c&&v?"Testing...":"Test OpenAI Response (Ping)"})]}):e.jsx($,{variant:"outline",onClick:()=>_(!1),disabled:c,className:"flex-1",children:c?"Testing...":"Test Runware Connection"})}),u&&e.jsxs("div",{className:"space-y-3",children:[u.success&&e.jsxs("div",{className:"flex items-center gap-2 text-green-600 dark:text-green-400",children:[e.jsx("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zm3.707-9.293a1 1 0 00-1.414-1.414L9 10.586 7.707 9.293a1 1 0 00-1.414 1.414l2 2a1 1 0 001.414 0l4-4z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm font-medium",children:u.message})]}),!u.success&&e.jsxs("div",{className:"flex items-center gap-2 text-red-600 dark:text-red-400",children:[e.jsx("svg",{className:"w-5 h-5",fill:"currentColor",viewBox:"0 0 20 20",children:e.jsx("path",{fillRule:"evenodd",d:"M10 18a8 8 0 100-16 8 8 0 000 16zM8.707 7.293a1 1 0 00-1.414 1.414L8.586 10l-1.293 1.293a1 1 0 101.414 1.414L10 11.414l1.293 1.293a1 1 0 001.414-1.414L11.414 10l1.293-1.293a1 1 0 00-1.414-1.414L10 8.586 8.707 7.293z",clipRule:"evenodd"})}),e.jsx("span",{className:"text-sm font-medium",children:u.message})]}),u.success&&e.jsx("div",{className:"bg-blue-50 dark:bg-blue-900/20 border-l-4 border-blue-500 p-4 rounded",children:e.jsx("div",{className:"space-y-2 text-sm",children:d==="openai"&&v?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Model Used:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white font-mono-custom",children:u.model_used||"N/A"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Expected:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:'"OK! Ping Received"'})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Actual Response:"})," ",e.jsxs("span",{className:"text-gray-900 dark:text-white",children:['"',u.response||"N/A",'"']})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Token Limit Sent:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:"N/A (from your settings)"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Tokens Used:"})," ",e.jsxs("span",{className:"text-gray-900 dark:text-white",children:[u.tokens_used||"N/A"," (input/output)"]})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Total Tokens:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:u.total_tokens||"N/A"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Cost:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:u.cost||"$0.0000"})]})]}):d==="runware"?e.jsxs(e.Fragment,{children:[e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Provider:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:"Runware"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Model:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white font-mono-custom",children:u.model_used||"runware:97@1"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Image Size:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:"128 x 128 (test image)"})]}),e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Cost:"})," ",e.jsx("span",{className:"text-gray-900 dark:text-white",children:u.cost||"$0.0090"})]}),((N=u.full_response)==null?void 0:N.image_url)&&e.jsxs("div",{children:[e.jsx("strong",{className:"text-gray-700 dark:text-gray-300",children:"Test Image:"})," ",e.jsx("a",{href:u.full_response.image_url,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 dark:text-blue-400 hover:underline",children:"View Image"})]})]}):null})})]})]})})]})}function ue({title:I,description:t,integrationId:d,icon:n}){const c=se(),[p,u]=o.useState(!1),[y,v]=o.useState(""),[L,_]=o.useState("text, watermark, logo, overlay, title, caption, writing on walls, writing on objects, UI, infographic elements, post title"),[N,M]=o.useState("realistic"),[j,S]=o.useState("1024x1024"),[k,w]=o.useState("webp"),[i,E]=o.useState({}),T={"dall-e-3":["1024x1024","1024x1792","1792x1024"],"dall-e-2":["256x256","512x512","1024x1024"]},Z=()=>{const r=(i.service||"openai")==="openai"?i.model||"dall-e-3":null;return r&&T[r]?T[r]:T["dall-e-3"]};o.useEffect(()=>{const s=Z();s.length>0&&!s.includes(j)&&S(s[0])},[i.model,i.service]);const[F,x]=o.useState(null),[C,A]=o.useState(null),z="https://api.igny8.com/api";o.useEffect(()=>{(async()=>{try{const r=await fetch(`${z}/v1/system/settings/integrations/image_generation/`,{credentials:"include"});if(r.ok){const g=await r.json();g.success&&g.data&&E(g.data)}}catch(r){console.error("Error loading image settings:",r)}})()},[z]);const U=async()=>{if(console.log("[ImageGenerationCard] handleGenerate called"),!y.trim()){c.error("Please enter a prompt description");return}u(!0),A(null),x(null);try{const s=i.service||"openai",r=s==="openai"?i.model||"dall-e-3":i.runwareModel||"runware:97@1";console.log("[ImageGenerationCard] Service and model:",{service:s,model:r,imageSettings:i});const g=`Create a high-quality ${N} image. ${y}`;console.log("[ImageGenerationCard] Full prompt:",g.substring(0,100)+"...");const l={prompt:g,negative_prompt:L,image_type:N,image_size:j,image_format:k,provider:s,model:r};console.log("[ImageGenerationCard] Making request to image generation endpoint"),console.log("[ImageGenerationCard] Request body:",l);const f=await H("/v1/system/settings/integrations/image_generation/generate/",{method:"POST",body:JSON.stringify(l)});if(console.log("[ImageGenerationCard] Response data:",f),!f.success)throw new Error(f.error||"Failed to generate image");const m={url:f.image_url,revised_prompt:f.revised_prompt,model:f.model||r,provider:f.provider||s,size:j,format:k.toUpperCase(),cost:f.cost};x(m),window.dispatchEvent(new CustomEvent("imageGenerated",{detail:m})),console.log("[ImageGenerationCard] Image generation successful:",m),c.success("Image generated successfully!")}catch(s){console.error("[ImageGenerationCard] Error in handleGenerate:",{error:s,message:s.message,stack:s.stack});const r=s.message||"Failed to generate image";A(r),window.dispatchEvent(new CustomEvent("imageGenerationError",{detail:r})),c.error(r)}finally{console.log("[ImageGenerationCard] handleGenerate completed"),u(!1)}},Y=()=>{if((i.service||"openai")==="openai"){const r=i.model||"dall-e-3";return`OpenAI ${{"dall-e-3":"DALL·E 3","dall-e-2":"DALL·E 2","gpt-image-1":"GPT Image 1 (Full)","gpt-image-1-mini":"GPT Image 1 Mini"}[r]||r}`}else return"Runware"},Q={"1024x1024":"Square - 1024 x 1024","1024x1792":"Portrait - 1024 x 1792","1792x1024":"Landscape - 1792 x 1024","256x256":"Small - 256 x 256","512x512":"Medium - 512 x 512"},X=Z().map(s=>({value:s,label:Q[s]||s})),ee=[{value:"realistic",label:"Realistic"},{value:"illustration",label:"Illustration"},{value:"3D render",label:"3D Render"},{value:"minimalist",label:"Minimalist"},{value:"cartoon",label:"Cartoon"}],a=[{value:"webp",label:"WEBP"},{value:"jpg",label:"JPG"},{value:"png",label:"PNG"}];return e.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[e.jsxs("div",{className:"relative p-5 pb-6",children:[n&&e.jsx("div",{className:"mb-4 inline-flex h-10 w-10 items-center justify-center",children:n}),e.jsx("h3",{className:"mb-2 text-base font-semibold text-gray-800 dark:text-white/90",children:I}),t&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t})]}),e.jsx("div",{className:"border-t border-gray-200 p-5 dark:border-gray-800",children:e.jsxs("div",{className:"space-y-5",children:[e.jsxs("div",{className:"flex items-center gap-3 rounded-lg bg-blue-50 px-4 py-3 dark:bg-blue-900/20",children:[e.jsx("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",className:"text-blue-600 dark:text-blue-400",children:e.jsx("path",{d:"M10 2L3 7V17C3 17.5304 3.21071 18.0391 3.58579 18.4142C3.96086 18.7893 4.46957 19 5 19H15C15.5304 19 16.0391 18.7893 16.4142 18.4142C16.7893 18.0391 17 17.5304 17 17V7L10 2Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})}),e.jsxs("div",{children:[e.jsx("p",{className:"text-xs font-medium text-blue-600 dark:text-blue-400",children:"Provider & Model"}),e.jsx("p",{className:"text-sm font-semibold text-blue-900 dark:text-blue-200",children:Y()})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Prompt Description *"}),e.jsx("textarea",{value:y,onChange:s=>v(s.target.value),rows:6,className:"w-full rounded-lg border border-gray-300 px-4 py-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-white",placeholder:"Describe the visual elements, style, mood, and composition you want in the image..."}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Describe the visual elements, style, mood, and composition you want in the image."})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Negative Prompt"}),e.jsx("textarea",{value:L,onChange:s=>_(s.target.value),rows:2,className:"w-full rounded-lg border border-gray-300 px-4 py-3 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-white",placeholder:"Describe what you DON'T want in the image..."}),e.jsx("p",{className:"mt-1 text-xs text-gray-500 dark:text-gray-400",children:"Specify elements to avoid in the generated image (text, watermarks, logos, etc.)."})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Image Type"}),e.jsx("select",{value:N,onChange:s=>M(s.target.value),className:"w-full rounded-lg border border-gray-300 px-4 py-2.5 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-white",children:ee.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Image Size"}),e.jsx("select",{value:j,onChange:s=>S(s.target.value),className:"w-full rounded-lg border border-gray-300 px-4 py-2.5 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-white",children:X.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]}),e.jsxs("div",{children:[e.jsx("label",{className:"mb-2 block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Image Format"}),e.jsx("select",{value:k,onChange:s=>w(s.target.value),className:"w-full rounded-lg border border-gray-300 px-4 py-2.5 text-sm focus:border-blue-500 focus:outline-none focus:ring-2 focus:ring-blue-500/20 dark:border-gray-700 dark:bg-gray-800 dark:text-white",children:a.map(s=>e.jsx("option",{value:s.value,children:s.label},s.value))})]})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx($,{onClick:U,disabled:p||!y.trim(),className:"inline-flex items-center gap-2 px-6 py-2.5",children:p?e.jsxs(e.Fragment,{children:[e.jsxs("svg",{className:"h-4 w-4 animate-spin",xmlns:"http://www.w3.org/2000/svg",fill:"none",viewBox:"0 0 24 24",children:[e.jsx("circle",{className:"opacity-25",cx:"12",cy:"12",r:"10",stroke:"currentColor",strokeWidth:"4"}),e.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"})]}),"Generating..."]}):e.jsxs(e.Fragment,{children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("circle",{cx:"9",cy:"9",r:"2"}),e.jsx("path",{d:"M21 15l-3.086-3.086a2 2 0 00-2.828 0L6 21"})]}),"Generate Image"]})})})]})}),C&&e.jsx("div",{className:"mt-4 rounded-lg border border-red-200 bg-red-50 p-4 dark:border-red-800 dark:bg-red-900/20",children:e.jsx("p",{className:"text-sm text-red-600 dark:text-red-400",children:C})})]})}function xe({title:I,description:t,icon:d,generatedImage:n,error:c}){const[p,u]=o.useState(n),[y,v]=o.useState(c);return o.useEffect(()=>{const L=N=>{u(N.detail),v(null)},_=N=>{v(N.detail),u(null)};return window.addEventListener("imageGenerated",L),window.addEventListener("imageGenerationError",_),()=>{window.removeEventListener("imageGenerated",L),window.removeEventListener("imageGenerationError",_)}},[]),o.useEffect(()=>{u(n)},[n]),o.useEffect(()=>{v(c)},[c]),e.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[e.jsxs("div",{className:"relative p-5 pb-6",children:[d&&e.jsx("div",{className:"mb-4 inline-flex h-10 w-10 items-center justify-center",children:d}),e.jsx("h3",{className:"mb-2 text-base font-semibold text-gray-800 dark:text-white/90",children:I}),t&&e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400",children:t})]}),e.jsx("div",{className:"border-t border-gray-200 p-5 dark:border-gray-800",children:y?e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("div",{className:"mb-4 rounded-full bg-red-100 p-4 dark:bg-red-900/20",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-red-600 dark:text-red-400",children:[e.jsx("path",{d:"M10.29 3.86L1.82 18a2 2 0 0 0 1.71 3h16.94a2 2 0 0 0 1.71-3L13.71 3.86a2 2 0 0 0-3.42 0z"}),e.jsx("line",{x1:"12",y1:"9",x2:"12",y2:"13"}),e.jsx("line",{x1:"12",y1:"17",x2:"12.01",y2:"17"})]})}),e.jsx("h4",{className:"mb-2 text-lg font-semibold text-gray-800 dark:text-white",children:"Generation Failed"}),e.jsx("p",{className:"text-sm text-gray-600 dark:text-gray-400",children:y})]}):p!=null&&p.url?e.jsxs("div",{className:"space-y-5",children:[e.jsx("div",{className:"overflow-hidden rounded-lg border border-gray-200 dark:border-gray-700",children:e.jsx("img",{src:p.url,alt:"Generated image",className:"w-full object-contain",style:{maxHeight:"400px"}})}),e.jsxs("div",{className:"space-y-3 rounded-lg bg-gray-50 p-4 dark:bg-gray-800/50",children:[e.jsx("h4",{className:"text-sm font-semibold text-gray-800 dark:text-white",children:"Image Details"}),e.jsxs("div",{className:"grid grid-cols-2 gap-3 text-sm",children:[e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Size:"}),e.jsxs("span",{className:"ml-2 text-gray-800 dark:text-white",children:[p.size||"1024x1024"," pixels"]})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Format:"}),e.jsx("span",{className:"ml-2 text-gray-800 dark:text-white",children:p.format||"WEBP"})]}),e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Model:"}),e.jsx("span",{className:"ml-2 text-gray-800 dark:text-white",children:p.model||"DALL·E 3"})]}),p.cost&&e.jsxs("div",{children:[e.jsx("span",{className:"font-medium text-gray-600 dark:text-gray-400",children:"Cost:"}),e.jsx("span",{className:"ml-2 text-gray-800 dark:text-white",children:p.cost})]})]}),p.revised_prompt&&e.jsxs("div",{className:"mt-3 border-t border-gray-200 pt-3 dark:border-gray-700",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-gray-600 dark:text-gray-400",children:"Revised Prompt:"}),e.jsx("p",{className:"text-xs text-gray-700 dark:text-gray-300",children:p.revised_prompt})]}),p.negative_prompt&&e.jsxs("div",{className:"mt-3 border-t border-gray-200 pt-3 dark:border-gray-700",children:[e.jsx("p",{className:"mb-2 text-xs font-medium text-gray-600 dark:text-gray-400",children:"Negative Prompt:"}),e.jsx("p",{className:"text-xs text-gray-700 dark:text-gray-300",children:p.negative_prompt})]})]}),e.jsxs("div",{className:"flex gap-3",children:[e.jsxs("a",{href:p.url,target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("path",{d:"M18 13v6a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V8a2 2 0 0 1 2-2h6"}),e.jsx("polyline",{points:"15 3 21 3 21 9"}),e.jsx("line",{x1:"10",y1:"14",x2:"21",y2:"3"})]}),"View Original"]}),e.jsxs("button",{onClick:()=>{navigator.clipboard.writeText(p.url)},className:"inline-flex items-center gap-2 rounded-lg border border-gray-300 px-4 py-2 text-sm font-medium text-gray-700 transition-colors hover:bg-gray-50 dark:border-gray-700 dark:text-gray-300 dark:hover:bg-gray-800",children:[e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",children:[e.jsx("rect",{x:"9",y:"9",width:"13",height:"13",rx:"2",ry:"2"}),e.jsx("path",{d:"M5 15H4a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h9a2 2 0 0 1 2 2v1"})]}),"Copy URL"]})]})]}):e.jsxs("div",{className:"flex flex-col items-center justify-center py-12 text-center",children:[e.jsx("div",{className:"mb-4 rounded-full bg-gray-100 p-4 dark:bg-gray-800",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"24",height:"24",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"text-gray-400 dark:text-gray-500",children:[e.jsx("rect",{x:"3",y:"3",width:"18",height:"18",rx:"2"}),e.jsx("circle",{cx:"9",cy:"9",r:"2"}),e.jsx("path",{d:"M21 15l-3.086-3.086a2 2 0 00-2.828 0L6 21"})]})}),e.jsx("p",{className:"text-sm text-gray-400 dark:text-gray-500",children:'No image generated yet. Fill out the form and click "Generate Image" to create your first AI image.'})]})})]})}function pe({icon:I,title:t,description:d,validationStatus:n,onSettings:c,onDetails:p}){const u=se(),y=oe({resourceId:"image_generation",getEndpoint:"/v1/system/settings/integrations/{id}/",saveEndpoint:"/v1/system/settings/integrations/{id}/save/",initialEnabled:!1,onToggleSuccess:w=>{u.success(`Image generation service ${w?"enabled":"disabled"}`)},onToggleError:w=>{u.error(`Failed to update image generation service: ${w.message}`)}}),v=y.enabled,L=y.loading,[_,N]=o.useState({}),M="https://api.igny8.com/api";o.useEffect(()=>{(async()=>{try{const i=await fetch(`${M}/v1/system/settings/integrations/image_generation/`,{credentials:"include"});if(i.ok){const E=await i.json();E.success&&E.data&&N(E.data)}}catch(i){console.error("Error loading image settings:",i)}})()},[M,v]);const j=w=>{y.toggle(w)},S=()=>{const w=_.service||"openai";if(w==="openai"){const i=_.model||"dall-e-3";return`OpenAI ${{"dall-e-3":"DALL·E 3","dall-e-2":"DALL·E 2","gpt-image-1":"GPT Image 1 (Full)","gpt-image-1-mini":"GPT Image 1 Mini"}[i]||i}`}else if(w==="runware"){const i=_.runwareModel||"runware:97@1";return`Runware ${{"runware:97@1":"HiDream-I1 Full","runware:gen3a_turbo":"Gen3a Turbo","runware:gen3a":"Gen3a"}[i]||i}`}return"Not configured"},k=()=>(_.service,!(_.model||_.runwareModel)||n==="not_configured"||n==="pending"?"text-gray-400 dark:text-gray-500":"text-black dark:text-white");return e.jsxs("article",{className:"rounded-2xl border border-gray-200 bg-white dark:border-gray-800 dark:bg-white/3",children:[e.jsxs("div",{className:"relative p-5 pb-9",children:[e.jsx("div",{className:"mb-5 inline-flex h-10 w-10 items-center justify-center",children:I}),e.jsx("h3",{className:"mb-3 text-lg font-semibold text-gray-800 dark:text-white/90",children:t}),e.jsx("p",{className:"max-w-xs text-sm text-gray-500 dark:text-gray-400",children:d}),e.jsx("div",{className:"absolute top-5 right-5 h-fit",children:e.jsx("p",{className:`text-lg font-semibold ${k()} transition-colors duration-200`,children:S()})})]}),e.jsxs("div",{className:"flex items-center justify-between border-t border-gray-200 p-5 dark:border-gray-800",children:[e.jsxs("div",{className:"flex gap-3",children:[e.jsx($,{variant:"outline",size:"md",onClick:c,className:"shadow-theme-xs inline-flex h-11 w-11 items-center justify-center rounded-lg border border-gray-300 text-gray-700 dark:border-gray-700 dark:text-gray-400",children:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"20",height:"20",viewBox:"0 0 20 20",fill:"none",children:[e.jsx("path",{d:"M5.64615 4.59906C5.05459 4.25752 4.29808 4.46015 3.95654 5.05171L2.69321 7.23986C2.35175 7.83128 2.5544 8.58754 3.14582 8.92899C3.97016 9.40493 3.97017 10.5948 3.14583 11.0707C2.55441 11.4122 2.35178 12.1684 2.69323 12.7598L3.95657 14.948C4.2981 15.5395 5.05461 15.7422 5.64617 15.4006C6.4706 14.9247 7.50129 15.5196 7.50129 16.4715C7.50129 17.1545 8.05496 17.7082 8.73794 17.7082H11.2649C11.9478 17.7082 12.5013 17.1545 12.5013 16.4717C12.5013 15.5201 13.5315 14.9251 14.3556 15.401C14.9469 15.7423 15.7029 15.5397 16.0443 14.9485L17.3079 12.7598C17.6494 12.1684 17.4467 11.4121 16.8553 11.0707C16.031 10.5948 16.031 9.40494 16.8554 8.92902C17.4468 8.58757 17.6494 7.83133 17.3079 7.23992L16.0443 5.05123C15.7029 4.45996 14.9469 4.25737 14.3556 4.59874C13.5315 5.07456 12.5013 4.47961 12.5013 3.52798C12.5013 2.84515 11.9477 2.2915 11.2649 2.2915L8.73795 2.2915C8.05496 2.2915 7.50129 2.84518 7.50129 3.52816C7.50129 4.48015 6.47059 5.07505 5.64615 4.59906Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M12.5714 9.99977C12.5714 11.4196 11.4204 12.5706 10.0005 12.5706C8.58069 12.5706 7.42969 11.4196 7.42969 9.99977C7.42969 8.57994 8.58069 7.42894 10.0005 7.42894C11.4204 7.42894 12.5714 8.57994 12.5714 9.99977Z",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round",strokeLinejoin:"round"})]})}),e.jsx($,{variant:"outline",size:"md",onClick:p,className:"shadow-theme-xs inline-flex h-11 items-center justify-center rounded-lg border border-gray-300 px-4 py-3 text-sm font-medium text-gray-700 dark:border-gray-700 dark:text-gray-400",children:"Details"})]}),e.jsx(le,{label:"",checked:v,disabled:L,onChange:j})]})]})}const ae=()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",children:[e.jsx("path",{d:"M12.321 24.9775C11.9035 24.3455 12.9535 23.389 12.5264 22.5859C12.2802 22.1227 11.8779 21.8341 11.3946 21.7735C10.9308 21.7153 10.4531 21.8851 10.1486 22.2169C9.66775 22.7401 9.59299 23.4523 9.68599 23.7043C9.72002 23.7967 9.77351 23.8219 9.81181 23.8273C10.0737 23.8618 10.221 23.1897 10.3115 23.0497C10.5614 22.6639 11.129 22.5471 11.5211 22.8007C12.2643 23.2814 11.6198 24.0584 11.6754 24.7147C11.7295 25.3537 12.1277 25.6105 12.4851 25.6375C12.8328 25.6507 13.0759 25.4575 13.1373 25.3165C13.2845 24.9799 12.6644 25.4975 12.321 24.9775Z",fill:"#0C111D"}),e.jsx("path",{d:"M27.8512 19.1761C27.6563 19.1492 27.4432 19.1498 27.2215 19.1761C27.0532 18.9637 26.9024 18.6199 26.8173 18.2185C26.6659 17.5045 26.6817 16.9873 27.1042 16.9201C27.5266 16.8529 27.7309 17.2849 27.8822 17.9989C27.9837 18.4789 27.9643 18.9199 27.8512 19.1761Z",fill:"#0C111D"}),e.jsx("path",{d:"M23.2243 19.6009C23.241 19.7626 23.2469 19.9262 23.2422 20.0769C23.6509 20.1009 23.9405 20.295 24.0175 20.4182C24.0571 20.4818 24.0412 20.5232 24.0285 20.5424C23.9862 20.6082 23.8955 20.598 23.7055 20.5767C23.5396 20.5581 23.3609 20.5417 23.1752 20.5503C23.0742 20.8602 22.7745 20.8892 22.564 20.66C22.417 20.7048 22.1281 20.8892 22.0421 20.6888C22.0413 20.5893 22.1453 20.4447 22.3337 20.317C22.2051 20.0718 22.1189 19.8092 22.068 19.5373C21.801 19.5854 21.5607 19.6602 21.3725 19.7188C21.284 19.7464 20.9343 19.9044 20.8933 19.7263C20.8659 19.6033 21.0574 19.4005 21.2598 19.2541C21.486 19.0935 21.7369 18.9794 21.997 18.9135C21.9914 18.5263 22.0902 18.2561 22.3716 18.2113C22.7204 18.1558 22.9366 18.4244 23.0863 18.9218C23.5079 19.0389 23.9289 19.3294 24.1148 19.6297C24.1871 19.7461 24.2011 19.8361 24.1543 19.8835C24.0375 20.0046 23.3901 19.6535 23.2243 19.6009Z",fill:"#0C111D"}),e.jsx("path",{d:"M25.9967 21.3415C26.2641 21.4711 26.5583 21.4201 26.6544 21.2275C26.7504 21.0349 26.6112 20.7739 26.3438 20.6443C26.0763 20.5147 25.7821 20.5657 25.6861 20.7583C25.5901 20.9509 25.7292 21.2119 25.9967 21.3415Z",fill:"#0C111D"}),e.jsx("path",{d:"M27.3132 20.3851C27.3181 20.0905 27.4986 19.8553 27.7156 19.8589C27.9326 19.8631 28.1046 20.1043 28.0998 20.3983C28.0949 20.6923 27.9144 20.9275 27.6974 20.9239C27.4804 20.9203 27.3084 20.6791 27.3132 20.3851Z",fill:"#0C111D"}),e.jsx("path",{fillRule:"evenodd",clipRule:"evenodd",d:"M33.1978 23.9929C33.196 23.9868 33.202 24.0079 33.1978 23.9929C33.6336 23.9929 34.318 24.4873 34.318 25.6819C34.318 26.8705 33.8184 28.2169 33.7004 28.5157C31.9006 32.7733 27.605 35.1433 22.4882 34.9933C17.7179 34.8535 13.6497 32.3689 11.8693 28.3183C10.7928 28.3195 9.68291 27.8521 8.83923 27.1141C7.94996 26.3365 7.40169 25.3303 7.29471 24.2809C7.21144 23.4637 7.31294 22.7035 7.57249 22.0405L6.5726 21.2041C1.99679 17.3906 16.3084 1.68861 20.8854 5.6294C20.9085 5.6492 22.4427 7.13479 22.4463 7.13839C24.6532 6.21344 30.5665 4.45236 30.5731 8.55199C30.5755 9.91338 29.6966 11.501 28.2882 12.9416C29.9158 14.4315 29.4867 16.5479 29.7458 18.4897L30.3111 18.6445C31.3888 18.9427 32.1553 19.3405 32.5303 19.7293C32.9054 20.1175 33.0914 20.4937 33.1589 20.9347C33.2221 21.2905 33.2136 21.9187 32.7382 22.6213C32.9094 23.0746 33.0656 23.5264 33.1978 23.9929ZM11.7885 27.2137C11.9483 27.2173 12.107 27.2071 12.2626 27.1807C13.9347 26.8993 14.3724 25.1065 14.097 23.3461C13.7858 21.3583 12.4237 20.6575 11.4991 20.6077C11.242 20.5945 11.0031 20.6173 10.8062 20.6563C9.15591 20.9845 8.22409 22.3705 8.40766 24.1705C8.5736 25.7995 10.2427 27.1729 11.7885 27.2137ZM8.05086 21.1447C8.6046 20.3509 9.50967 19.7767 10.5369 19.5793C11.8444 16.115 14.0277 12.923 16.9174 10.7264C19.0619 8.96058 21.3747 7.69399 21.3747 7.69399C21.3747 7.69399 20.1292 6.26839 19.753 6.16339C17.4389 5.5466 12.4413 8.94858 9.25013 13.4438C7.95908 15.2624 6.11064 18.4831 6.99444 20.1397C7.10324 20.3449 7.7202 20.8723 8.05086 21.1447ZM26.8118 26.4181C26.8154 26.4553 26.7924 26.4937 26.7589 26.5075C26.7589 26.5075 24.8995 27.3613 21.9461 26.4595C22.0523 27.3448 23.1259 27.6803 23.8759 27.8017C27.5357 28.4233 30.9573 26.3575 31.7274 25.8373C31.8596 25.748 31.7258 25.9776 31.7019 26.0113C30.7591 27.2119 28.2244 28.6021 24.9269 28.6015C23.4888 28.6009 22.0512 28.1011 21.5236 27.3325C20.7048 26.1403 21.4829 24.3997 22.8475 24.5809C25.1541 24.838 27.5188 24.6448 29.6541 23.6665C31.5159 22.8133 32.2191 21.8749 32.1134 21.1147C31.9493 19.9366 30.2026 19.7524 29.3197 19.4659C28.9356 19.3405 28.7459 19.2403 28.7028 18.5269C28.6839 18.2155 28.6292 17.129 28.6092 16.6796C28.5739 15.893 28.4779 14.8172 27.802 14.3732C27.6257 14.2574 27.43 14.2016 27.2239 14.1908C27.0596 14.1829 26.9622 14.2055 26.9098 14.2176C26.8981 14.2204 26.8886 14.2226 26.8811 14.2238C26.5161 14.285 26.2925 14.4697 26.0287 14.6874C26.0135 14.7 25.9982 14.7126 25.9827 14.7254C25.1396 15.419 24.4279 15.5324 23.6358 15.4988C23.3892 15.4884 23.135 15.4638 22.8668 15.4378C22.6201 15.4139 22.3617 15.3889 22.0865 15.3728L21.7503 15.3536C20.424 15.2864 19.0017 16.4168 18.7652 18.0223C18.5011 19.8145 19.5028 20.9122 20.1542 21.6261C20.3152 21.8025 20.4548 21.9555 20.5486 22.0897C20.6088 22.1707 20.6787 22.2847 20.6787 22.3933C20.6787 22.5229 20.5936 22.6255 20.5103 22.7131C19.1573 24.0865 18.7245 26.2687 19.2345 28.0873C19.2983 28.3141 19.3792 28.5313 19.4746 28.7389C20.6708 31.4983 24.3823 32.7835 28.0074 31.6147C30.5481 30.7955 32.7929 28.8159 33.25 26.0851C33.3588 25.3735 33.199 25.0987 32.9814 24.9661C32.751 24.8263 32.475 24.8749 32.475 24.8749C32.475 24.8749 32.3492 24.0247 31.993 23.2519C30.936 24.0751 29.5756 24.6535 28.5399 24.9469C26.8804 25.4168 25.0879 25.5998 23.373 25.3782C22.6775 25.2883 22.2102 25.228 22.0099 25.8703C24.2972 26.6971 26.7182 26.3431 26.7182 26.3431C26.765 26.3383 26.8069 26.3719 26.8118 26.4181ZM20.2125 10.3736C18.9616 11.0054 17.5648 12.1304 16.4305 13.4246C16.3904 13.4708 16.45 13.5344 16.4992 13.499C17.479 12.7952 18.8224 12.1412 20.5821 11.7176C22.5533 11.243 24.451 11.4422 25.6101 11.7044C25.6685 11.7176 25.7049 11.6186 25.6533 11.5898C24.8874 11.1656 23.7118 10.8776 22.8779 10.8716C22.8371 10.871 22.814 10.8242 22.8384 10.7918C22.9824 10.6004 23.18 10.4114 23.3605 10.2746C23.4006 10.2434 23.3763 10.1792 23.3252 10.1822C22.2878 10.2451 19.9183 11.3255 19.9268 11.2862C19.9876 10.9982 20.1791 10.6178 20.2781 10.4402C20.3019 10.3982 20.2557 10.352 20.2125 10.3736Z",fill:"#0C111D"})]}),ie=()=>e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",children:[e.jsx("rect",{width:"40",height:"40",rx:"8",fill:"#625DF5"}),e.jsx("path",{d:"M20 12L28 20L20 28L12 20L20 12Z",fill:"white"})]});function ke(){var U,Y,Q,X,ee;const I=se(),[t,d]=o.useState({openai:{id:"openai",enabled:!1,apiKey:"",model:"gpt-4.1"},runware:{id:"runware",enabled:!1,apiKey:""},image_generation:{id:"image_generation",enabled:!1,service:"openai",provider:"openai",model:"dall-e-3",runwareModel:"runware:97@1",image_type:"realistic",max_in_article_images:2,image_format:"webp",desktop_enabled:!0,mobile_enabled:!0,featured_image_size:"1024x1024",desktop_image_size:"1024x1024"}}),[n,c]=o.useState(null),[p,u]=o.useState(!1),[y,v]=o.useState(!1),[L,_]=o.useState(!1),[N,M]=o.useState(!1),[j,S]=o.useState({openai:"not_configured",runware:"not_configured",image_generation:"not_configured"}),k=o.useCallback(async(a,s,r,g)=>{const l="https://api.igny8.com/api";if(!["openai","runware"].includes(a))return;if(!(r&&r.trim()!=="")||!s){S(m=>({...m,[a]:"not_configured"}));return}S(m=>({...m,[a]:"pending"}));try{const m={apiKey:r};a==="openai"&&(m.config={model:g||"gpt-4.1",with_response:!1});const h=await fetch(`${l}/v1/system/settings/integrations/${a}/test/`,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(m)}),D=await h.json();h.ok&&D.success?S(P=>({...P,[a]:"success"})):(console.error(`Validation failed for ${a}:`,D.error||D.message),S(P=>({...P,[a]:"error"})))}catch(m){console.error(`Error validating ${a}:`,m),S(h=>({...h,[a]:"error"}))}},[]),w=o.useCallback(async()=>{d(a=>(["openai","runware"].forEach(s=>{const r=a[s];if(!r)return;const g=r.enabled===!0,l=r.apiKey,f=r.model;k(s,g,l,f)}),a))},[k]);o.useEffect(()=>{i()},[]),o.useEffect(()=>{if(!Object.values(t).some(r=>r.apiKey!==void 0||r.enabled!==void 0))return;const s=setTimeout(()=>{w()},500);return()=>clearTimeout(s)},[t.openai.enabled,t.runware.enabled,t.openai.apiKey,t.runware.apiKey]);const i=async()=>{try{const a="https://api.igny8.com/api",r=["openai","runware","image_generation"].map(async l=>{try{const f=await fetch(`${a}/v1/system/settings/integrations/${l}/`,{credentials:"include"});if(f.ok){const m=await f.json();if(m.success&&m.data)return{id:l,config:m.data}}return{id:l,config:null}}catch(f){return console.error(`Error loading ${l} settings:`,f),{id:l,config:null}}}),g=await Promise.all(r);d(l=>{const f={...l};return g.forEach(({id:m,config:h})=>{h&&l[m]&&(f[m]={...l[m],...h,enabled:h.enabled!==void 0?h.enabled:l[m].enabled})}),f})}catch(a){console.error("Error loading integration settings:",a)}},E=a=>{c(a),v(!0)},T=a=>{c(a),u(!0)},Z=async()=>{if(!n)return;if(n!=="openai"&&n!=="runware"){I.warning("Connection testing is only available for OpenAI and Runware");return}const a=t[n],s=a.apiKey;if(!s){I.error("Please enter an API key first");return}M(!0),n&&S(r=>({...r,[n]:"pending"}));try{const r=await H(`/v1/system/settings/integrations/${n}/test/`,{method:"POST",body:JSON.stringify({apiKey:s,config:a})});if(r.success)I.success(r.message||"API connection test successful!"),r.response&&I.info(`Response: ${r.response}`),r.tokens_used&&I.info(`Tokens used: ${r.tokens_used}`),n&&S(g=>({...g,[n]:"success"}));else throw new Error(r.error||"Connection test failed")}catch(r){console.error("Error testing connection:",r),I.error(`Connection test failed: ${r.message||"Unknown error"}`),n&&S(g=>({...g,[n]:"error"}))}finally{M(!1)}},F=async()=>{if(n){_(!0);try{const a=t[n];let s={...a};if(n==="image_generation"){const h=a.service||"openai",D=h==="openai"?a.model||"dall-e-3":a.runwareModel||"runware:97@1",P=C(h,D),R=P.length>0?P[0].value:"1024x1024",G=P.length>0?P[0].value:"1024x1024";s={...a,provider:a.service||a.provider||"openai",model:h==="openai"?a.model||"dall-e-3":h==="runware"?a.runwareModel||"runware:97@1":a.model,image_type:a.image_type||"realistic",max_in_article_images:a.max_in_article_images||2,image_format:a.image_format||"webp",desktop_enabled:a.desktop_enabled!==void 0?a.desktop_enabled:!0,mobile_enabled:a.mobile_enabled!==void 0?a.mobile_enabled:!0,featured_image_size:a.featured_image_size||R,desktop_image_size:a.desktop_image_size||G}}const g=`https://api.igny8.com/api/v1/system/settings/integrations/${n}/save/`,l=await fetch(g,{method:"POST",headers:{"Content-Type":"application/json"},credentials:"include",body:JSON.stringify(s)});if(!(l.headers.get("content-type")||"").includes("application/json")){const h=await l.text();if(h.trim().startsWith("<!DOCTYPE")||h.trim().startsWith("<html"))throw new Error(`Server returned HTML instead of JSON. This usually means the endpoint doesn't exist (404). Response: ${h.substring(0,200)}`)}let m;try{const h=await l.text();m=h?JSON.parse(h):{}}catch{const D=await l.text();throw new Error(`Failed to parse response as JSON. Response was: ${D.substring(0,200)}`)}if(!l.ok)throw new Error(m.error||`HTTP ${l.status}: ${l.statusText}`);if(m.success)I.success(m.message||"Settings saved successfully"),v(!1),setTimeout(()=>{i().then(()=>{setTimeout(()=>w(),300)}).catch(h=>{console.error("Error reloading settings after save:",h)})},100);else throw new Error(m.error||"Failed to save settings")}catch(a){console.error("Error saving integration settings:",a),I.error(`Failed to save settings: ${a.message||"Unknown error"}`)}finally{_(!1)}}},x=a=>{const s=t[a];if(a==="openai")return[{label:"App Name",value:"OpenAI API"},{label:"API Key",value:s.apiKey?`${s.apiKey.substring(0,20)}...`:"Not configured"},{label:"Model",value:s.model||"Not set"}];if(a==="runware")return[{label:"App Name",value:"Runware API"},{label:"API Key",value:s.apiKey?`${s.apiKey.substring(0,20)}...`:"Not configured"}];if(a==="image_generation"){const r=s.service||"openai",g=r==="openai"?s.model||"Not set":s.runwareModel||"Not set";return[{label:"Service",value:r==="openai"?"OpenAI":"Runware"},{label:"Model",value:g}]}return[]},C=o.useCallback((a,s)=>{if(a==="runware")return[{value:"1280x832",label:"1280×832 pixels - $0.009",price:.009},{value:"1024x1024",label:"1024×1024 pixels - $0.009",price:.009},{value:"512x512",label:"512×512 pixels - $0.006",price:.006}];if(a==="openai"){if(s==="dall-e-2")return[{value:"256x256",label:"256×256 pixels - $0.016",price:.016},{value:"512x512",label:"512×512 pixels - $0.018",price:.018},{value:"1024x1024",label:"1024×1024 pixels - $0.02",price:.02}];if(s==="dall-e-3")return[{value:"1024x1024",label:"1024×1024 pixels - $0.04",price:.04}]}return[{value:"1024x1024",label:"1024×1024 pixels",price:0}]},[]),A=o.useCallback(a=>{const s=t[a];if(a==="openai")return[{key:"apiKey",label:"OpenAI API Key",type:"password",value:s.apiKey||"",onChange:r=>{d({...t,[a]:{...s,apiKey:r}})},placeholder:"Enter your OpenAI API key",required:!0},{key:"model",label:"AI Model",type:"select",value:s.model||"gpt-4.1",onChange:r=>{d({...t,[a]:{...s,model:r}})},options:[{value:"gpt-4.1",label:"GPT-4.1 - $2.00 / $8.00 per 1M tokens"},{value:"gpt-4o-mini",label:"GPT-4o mini - $0.15 / $0.60 per 1M tokens"},{value:"gpt-4o",label:"GPT-4o - $2.50 / $10.00 per 1M tokens"}]}];if(a==="runware")return[{key:"apiKey",label:"Runware API Key",type:"password",value:s.apiKey||"",onChange:r=>{d({...t,[a]:{...s,apiKey:r}})},placeholder:"Enter your Runware API key",required:!0}];if(a==="image_generation"){const r=s.service||"openai",g=[{key:"service",label:"Image Generation Service",type:"select",value:r,onChange:l=>{d({...t,[a]:{...s,service:l,model:l==="openai"?"dall-e-3":void 0,runwareModel:l==="runware"?"runware:97@1":void 0}})},options:[{value:"openai",label:"OpenAI - Multiple models available"},{value:"runware",label:"Runware - $0.009 per image"}]}];return r==="openai"?g.push({key:"model",label:"OpenAI Image Model",type:"select",value:s.model||"dall-e-3",onChange:l=>{d({...t,[a]:{...s,model:l}})},options:[{value:"dall-e-3",label:"DALL·E 3 - $0.040 per image"},{value:"dall-e-2",label:"DALL·E 2 - $0.020 per image"}]}):r==="runware"&&g.push({key:"runwareModel",label:"Runware Model",type:"select",value:s.runwareModel||"runware:97@1",onChange:l=>{d({...t,[a]:{...s,runwareModel:l}})},options:[{value:"runware:97@1",label:"HiDream-I1 Full - $0.009 per image"},{value:"runware:gen3a_turbo",label:"Gen3a Turbo - $0.009 per image"},{value:"runware:gen3a",label:"Gen3a - $0.009 per image"}]}),g.push({key:"image_type",label:"Image Type",type:"select",value:s.image_type||"realistic",onChange:l=>{d({...t,[a]:{...s,image_type:l}})},options:[{value:"realistic",label:"Realistic"},{value:"artistic",label:"Artistic"},{value:"cartoon",label:"Cartoon"}]},{key:"max_in_article_images",label:"Max In-Article Images",type:"select",value:String(s.max_in_article_images||2),onChange:l=>{d({...t,[a]:{...s,max_in_article_images:parseInt(l)}})},options:[{value:"1",label:"1 Image"},{value:"2",label:"2 Images"},{value:"3",label:"3 Images"},{value:"4",label:"4 Images"},{value:"5",label:"5 Images"}]},{key:"image_format",label:"Image Format",type:"select",value:s.image_format||"webp",onChange:l=>{d({...t,[a]:{...s,image_format:l}})},options:[{value:"webp",label:"WEBP"},{value:"jpg",label:"JPG"},{value:"png",label:"PNG"}]}),g}return[]},[t]);o.useEffect(()=>{if(n!=="image_generation"||!y)return;const a=t[n];if(!a)return;const s=a.service||"openai",r=s==="openai"?a.model||"dall-e-3":a.runwareModel||"runware:97@1",g=C(s,r);if(g.length>0){const l=g[0].value,f=a.featured_image_size,m=a.desktop_image_size,h=g.map(P=>P.value);(!f||!h.includes(f)||!m||!h.includes(m))&&d({...t,[n]:{...a,featured_image_size:h.includes(f||"")?f:l,desktop_image_size:h.includes(m||"")?m:l}})}},[(U=t[n])==null?void 0:U.service,(Y=t[n])==null?void 0:Y.model,(Q=t[n])==null?void 0:Q.runwareModel,n,y,C]);const z=o.useMemo(()=>{var a,s,r,g,l,f,m,h,D,P;if(!(n!=="image_generation"||!y))try{const R=A(n),G=R.find(b=>b.key==="service"),J=((a=t[n])==null?void 0:a.service)||"openai",O=R.find(b=>J==="openai"?b.key==="model":b.key==="runwareModel"),B=R.find(b=>b.key==="max_in_article_images"),K=R.find(b=>b.key==="image_type"),V=R.find(b=>b.key==="image_format");return e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[G&&e.jsxs("div",{children:[e.jsxs(W,{className:"mb-2",children:[G.label,G.required&&e.jsx("span",{className:"text-error-500 ml-1",children:"*"})]}),e.jsx(q,{options:G.options||[],placeholder:G.placeholder||G.label,value:G.value||"",onChange:b=>G.onChange(b),className:"w-full"})]}),O&&e.jsxs("div",{children:[e.jsxs(W,{className:"mb-2",children:[O.label,O.required&&e.jsx("span",{className:"text-error-500 ml-1",children:"*"})]}),e.jsx(q,{options:O.options||[],placeholder:O.placeholder||O.label,value:O.value||"",onChange:b=>O.onChange(b),className:"w-full"})]})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx(W,{className:"block text-sm font-medium text-gray-700 dark:text-gray-300",children:"Max Images"}),e.jsxs("div",{className:"p-3 rounded-lg border border-gray-200 dark:border-gray-700 bg-gradient-to-r from-purple-500 to-blue-500 text-white",children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsx("div",{className:"font-medium",children:"Featured Image"}),e.jsx("div",{className:"text-xs bg-white/20 px-2 py-1 rounded",children:"Always Enabled"})]}),e.jsx("div",{className:"w-full [&_.igny8-select-styled]:bg-white/10 [&_.igny8-select-styled]:border-white/20 [&_.igny8-select-styled]:text-white [&_.igny8-select-styled]:placeholder:text-white/70 [&_.igny8-select-styled]:focus:border-white/40 [&_.igny8-select-styled]:focus:ring-white/20",children:e.jsx(q,{options:C(J,J==="openai"?((s=t[n])==null?void 0:s.model)||"dall-e-3":((r=t[n])==null?void 0:r.runwareModel)||"runware:97@1"),value:((g=t[n])==null?void 0:g.featured_image_size)||"1024x1024",onChange:b=>{d({...t,[n]:{...t[n],featured_image_size:b}})},className:"w-full"})})]})]}),e.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[e.jsxs("div",{className:"p-3 rounded-lg border border-gray-200 dark:border-gray-700 space-y-2",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(te,{checked:((l=t[n])==null?void 0:l.desktop_enabled)!==!1,onChange:b=>{d({...t,[n]:{...t[n],desktop_enabled:b}})}}),e.jsx(W,{className:"font-medium text-gray-700 dark:text-gray-300",children:"Desktop Images"})]}),((f=t[n])==null?void 0:f.desktop_enabled)!==!1&&e.jsx(q,{options:C(J,J==="openai"?((m=t[n])==null?void 0:m.model)||"dall-e-3":((h=t[n])==null?void 0:h.runwareModel)||"runware:97@1"),value:((D=t[n])==null?void 0:D.desktop_image_size)||"1024x1024",onChange:b=>{d({...t,[n]:{...t[n],desktop_image_size:b}})},className:"w-full"})]}),e.jsxs("div",{className:"flex items-center gap-3 p-3 rounded-lg border border-gray-200 dark:border-gray-700",children:[e.jsx(te,{checked:((P=t[n])==null?void 0:P.mobile_enabled)!==!1,onChange:b=>{d({...t,[n]:{...t[n],mobile_enabled:b}})}}),e.jsxs("div",{children:[e.jsx(W,{className:"font-medium text-gray-700 dark:text-gray-300",children:"Mobile Images"}),e.jsx("div",{className:"text-xs text-gray-500 dark:text-gray-400",children:"512×512 pixels"})]})]})]}),e.jsxs("div",{className:"grid grid-cols-3 gap-4",children:[B&&e.jsxs("div",{children:[e.jsxs(W,{className:"mb-2",children:[B.label,B.required&&e.jsx("span",{className:"text-error-500 ml-1",children:"*"})]}),e.jsx(q,{options:B.options||[],placeholder:B.placeholder||B.label,value:B.value||"",onChange:b=>B.onChange(b),className:"w-full"})]}),K&&e.jsxs("div",{children:[e.jsxs(W,{className:"mb-2",children:[K.label,K.required&&e.jsx("span",{className:"text-error-500 ml-1",children:"*"})]}),e.jsx(q,{options:K.options||[],placeholder:K.placeholder||K.label,value:K.value||"",onChange:b=>K.onChange(b),className:"w-full"})]}),V&&e.jsxs("div",{children:[e.jsxs(W,{className:"mb-2",children:[V.label,V.required&&e.jsx("span",{className:"text-error-500 ml-1",children:"*"})]}),e.jsx(q,{options:V.options||[],placeholder:V.placeholder||V.label,value:V.value||"",onChange:b=>V.onChange(b),className:"w-full"})]})]})]})}catch(R){return console.error("Error rendering image generation form:",R),e.jsx("div",{className:"text-error-500",children:"Error loading form. Please refresh the page."})}},[n,t,y,A]);return e.jsxs(e.Fragment,{children:[e.jsx(de,{title:"API Integration - IGNY8",description:"External integrations"}),e.jsxs("div",{className:"space-y-8",children:[e.jsxs("div",{className:"grid grid-cols-1 gap-6 sm:grid-cols-2 xl:grid-cols-3",children:[e.jsxs("div",{className:"space-y-5",children:[e.jsx(re,{icon:e.jsx(ae,{}),title:"OpenAI",description:"AI-powered content generation and analysis with DALL-E image generation",validationStatus:j.openai,integrationId:"openai",onToggleSuccess:(a,s)=>{const r=(s==null?void 0:s.apiKey)||t.openai.apiKey,g=(s==null?void 0:s.model)||t.openai.model;k("openai",a,r,g)},onSettings:()=>E("openai"),onDetails:()=>T("openai")}),e.jsx(ne,{title:"OpenAI API Validation",description:"Two-way response validation with actual request and response testing",integrationId:"openai",icon:e.jsx(ae,{})})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(re,{icon:e.jsx(ie,{}),title:"Runware",description:"High-quality AI image generation with Runware's models ($0.009 per image)",validationStatus:j.runware,integrationId:"runware",modelName:((X=t.image_generation)==null?void 0:X.service)==="runware"&&t.image_generation.runwareModel?{"runware:97@1":"HiDream-I1 Full","runware:gen3a_turbo":"Gen3a Turbo","runware:gen3a":"Gen3a"}[t.image_generation.runwareModel]||t.image_generation.runwareModel:void 0,onToggleSuccess:(a,s)=>{const r=(s==null?void 0:s.apiKey)||t.runware.apiKey;k("runware",a,r)},onSettings:()=>E("runware"),onDetails:()=>T("runware")}),e.jsx(ne,{title:"Runware API Validation",description:"Using 128x128 image generation request for connection testing",integrationId:"runware",icon:e.jsx(ie,{})})]}),e.jsxs("div",{className:"space-y-5",children:[e.jsx(pe,{icon:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",children:[e.jsx("rect",{width:"40",height:"40",rx:"8",fill:"#9333EA"}),e.jsx("path",{d:"M12 16L20 10L28 16V28C28 28.5304 27.7893 29.0391 27.4142 29.4142C27.0391 29.7893 26.5304 30 26 30H14C13.4696 30 12.9609 29.7893 12.5858 29.4142C12.2107 29.0391 12 28.5304 12 28V16Z",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M16 30V20H24V30",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]}),title:"Image Generation Service",description:"Default image generation service and model selection for app-wide use",validationStatus:j.image_generation,onSettings:()=>E("image_generation"),onDetails:()=>T("image_generation")}),e.jsx(me,{variant:"info",title:"AI Integration & Image Generation Testing",message:`Configure and test your AI integrations on this page.
|
||
Set up OpenAI and Runware API keys, validate connections, and test image generation with different models and parameters.
|
||
Before you start, please read the documentation for each integration.
|
||
|
||
Make sure to use the correct API keys and models for each integration.`})]})]}),e.jsxs("div",{className:"grid grid-cols-1 gap-6 lg:grid-cols-2",children:[e.jsx(ue,{title:"Generate Image",description:"Configure image generation parameters",integrationId:"openai",icon:e.jsx(ae,{})}),e.jsx(xe,{title:"Generated Image",description:"AI-generated image results",icon:e.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"40",height:"40",viewBox:"0 0 40 40",fill:"none",children:[e.jsx("rect",{width:"40",height:"40",rx:"8",fill:"#10B981"}),e.jsx("path",{d:"M12 16L20 10L28 16V28C28 28.5304 27.7893 29.0391 27.4142 29.4142C27.0391 29.7893 26.5304 30 26 30H14C13.4696 30 12.9609 29.7893 12.5858 29.4142C12.2107 29.0391 12 28.5304 12 28V16Z",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"}),e.jsx("path",{d:"M16 30V20H24V30",stroke:"white",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round"})]})})]})]}),e.jsx(ce,{isOpen:p,onClose:()=>u(!1),className:"max-w-2xl",children:e.jsxs("div",{className:"p-6",children:[e.jsx("h3",{className:"text-lg font-semibold mb-2 text-gray-800 dark:text-white",children:"Integration details"}),e.jsx("p",{className:"text-sm text-gray-500 dark:text-gray-400 mb-6",children:"Check the credentials and settings for your connected app."}),e.jsx("div",{className:"space-y-4",children:n&&x(n).map((a,s)=>e.jsxs("div",{className:"flex justify-between items-start border-b border-gray-200 dark:border-gray-700 pb-3",children:[e.jsx("span",{className:"text-sm font-medium text-gray-700 dark:text-gray-300",children:a.label}),e.jsx("span",{className:"text-sm text-gray-900 dark:text-white text-right max-w-xs break-words",children:a.value})]},s))}),e.jsx("div",{className:"flex justify-end mt-6",children:e.jsx($,{variant:"outline",onClick:()=>u(!1),children:"Close"})})]})}),n&&e.jsx(e.Fragment,{children:e.jsx(ge,{isOpen:y,onClose:()=>v(!1),onSubmit:F,title:"Integration settings",fields:A(n),submitLabel:"Save Changes",cancelLabel:"Close",isLoading:L,customBody:z,customFooter:n==="openai"||n==="runware"?e.jsxs("div",{className:"flex justify-between items-center pt-4",children:[e.jsx($,{type:"button",variant:"secondary",onClick:()=>{Z()},disabled:N||L||!((ee=t[n])!=null&&ee.apiKey),className:"flex items-center gap-2",children:N?"Testing...":"Test Connection"}),e.jsxs("div",{className:"flex gap-3",children:[e.jsx($,{type:"button",variant:"outline",onClick:()=>v(!1),disabled:L||N,children:"Close"}),e.jsx($,{type:"submit",variant:"primary",disabled:L||N,children:L?"Saving...":"Save Changes"})]})]}):void 0})})]})}export{ke as default};
|