import{c as U,u as V,r as T,j as e,t as I,a as Q}from"./index-qMrAuFFG.js";import{c as A,F as b,R,a as w,L as C,u as W,s as E,d as X,e as Z,f as D,b as L}from"./badge-BOFxe4_3.js";import{I as P,H as ee,B,J as se,S as te,a as ae,b as re,c as le,d as K,e as q,K as G,M as ne,N as S,O as y,Q as H,T as j,_ as ie,L as oe,f as ce}from"./loading-PETOxw4W.js";import{A as Y,C as de,S as he,M as ue}from"./MineruConfig-Bd9buqsB.js";import{T as pe,A as z}from"./alert-message-DBiN770l.js";import{j as ge,k as me,a as M}from"./queries-B0q6a4VE.js";import{F as xe,C as ke}from"./file-text-ixReJvsZ.js";import{F as ve}from"./folder-DSkD5gAR.js";/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const be=[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]],je=U("ArrowRight",be);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const fe=[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]],ye=U("Layers",fe);/**
 * @license lucide-react v0.476.0 - ISC
 *
 * This source code is licensed under the ISC license.
 * See the LICENSE file in the root directory of this source tree.
 */const Ce=[["path",{d:"M21 15v4a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2v-4",key:"ih7n3h"}],["polyline",{points:"17 8 12 3 7 8",key:"t8dd8p"}],["line",{x1:"12",x2:"12",y1:"3",y2:"15",key:"widbto"}]],J=U("Upload",Ce);function Ne({form:n}){const{t:a}=V(),o=T.useMemo(()=>[{value:A.enum.HYBRID,label:a("tasks.create.chunk.strategies.hybrid.label"),description:a("tasks.create.chunk.strategies.hybrid.description")},{value:A.enum.MERGE,label:a("tasks.create.chunk.strategies.merge.label"),description:a("tasks.create.chunk.strategies.merge.description")},{value:A.enum.RECURSIVE,label:a("tasks.create.chunk.strategies.recursive.label"),description:a("tasks.create.chunk.strategies.recursive.description")}],[a]);return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-4",children:a("tasks.create.chunk.heading")}),e.jsx("p",{className:"text-gray-600 mb-6",children:a("tasks.create.chunk.subheading")})]}),e.jsx(n.Field,{name:"shouldChunk",children:c=>e.jsx(b,{label:a("tasks.create.chunk.enable.label"),htmlFor:"shouldChunk",required:!0,help:a("tasks.create.chunk.enable.help"),children:e.jsxs(R,{value:c.state.value?"true":"false",onValueChange:t=>c.handleChange(t==="true"),className:"flex items-center space-x-6 mt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"true",id:"chunk-enabled"}),e.jsx(C,{htmlFor:"chunk-enabled",children:a("tasks.create.chunk.enable.optionEnabled")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"false",id:"chunk-disabled"}),e.jsx(C,{htmlFor:"chunk-disabled",children:a("tasks.create.chunk.enable.optionDisabled")})]})]})})}),e.jsx(n.Subscribe,{selector:c=>c.values.shouldChunk,children:c=>c?e.jsxs(e.Fragment,{children:[e.jsx(n.Field,{name:"chunkStrategy",children:t=>e.jsx(b,{label:a("tasks.create.chunk.strategy.label"),htmlFor:"chunkStrategy",required:!0,error:t.state.meta.errors[0],help:a("tasks.create.chunk.strategy.help"),children:e.jsx(R,{value:t.state.value||"",onValueChange:i=>t.handleChange(i),className:"grid gap-3 md:grid-cols-3",children:o.map(i=>e.jsx(C,{htmlFor:`chunk-strategy-${i.value.toLowerCase()}`,className:"flex cursor-pointer flex-col items-start gap-3 rounded-lg border p-3 text-left has-[[data-state=checked]]:border-blue-600 dark:has-[[data-state=checked]]:border-blue-900 dark:has-[[data-state=checked]]:bg-blue-950",children:e.jsxs("div",{className:"flex items-start gap-2",children:[e.jsx(w,{value:i.value,className:"mt-0.5",id:`chunk-strategy-${i.value.toLowerCase()}`}),e.jsxs("div",{className:"flex flex-col text-sm font-medium text-gray-900",children:[i.label,e.jsx("span",{className:"text-xs leading-relaxed text-gray-500",children:i.description})]})]})},i.value))})})}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsx(n.Field,{name:"chunkSize",children:t=>e.jsx(b,{label:a("tasks.create.chunk.size.label"),htmlFor:"chunkSize",required:!0,error:t.state.meta.errors[0],help:a("tasks.create.chunk.size.help"),children:e.jsx(P,{id:"chunkSize",type:"number",min:1,max:8192,value:t.state.value===void 0?"":String(t.state.value),onChange:i=>{const s=i.target.value;t.handleChange(s===""?void 0:Number.parseInt(s,10))},onBlur:t.handleBlur})})}),e.jsx(n.Field,{name:"chunkOverlap",children:t=>e.jsx(b,{label:a("tasks.create.chunk.overlap.label"),htmlFor:"chunkOverlap",required:!0,error:t.state.meta.errors[0],help:a("tasks.create.chunk.overlap.help"),children:e.jsx(P,{id:"chunkOverlap",type:"number",min:0,max:4096,value:t.state.value===void 0?"":String(t.state.value),onChange:i=>{const s=i.target.value;t.handleChange(s===""?void 0:Number.parseInt(s,10))},onBlur:t.handleBlur})})})]})]}):null})]})}function we({steps:n,currentStep:a,form:o}){return e.jsx("div",{className:"mb-8",children:e.jsx("div",{className:"flex items-center justify-between",children:n.map((c,t)=>{const i=c.getStatus(o.state.values,a),s=t===a,r=t<a,d=r&&i.isCompleted;return e.jsxs("div",{className:"flex items-center",children:[e.jsxs("div",{className:"flex items-center",children:[e.jsx("div",{className:`
                    w-10 h-10 rounded-full flex items-center justify-center border-2 transition-colors
                    ${d?"bg-green-600 border-green-600 text-white":s||r?"bg-blue-600 border-blue-600 text-white":i.isCompleted?"bg-green-100 border-green-300 text-green-600":"border-gray-300 text-gray-400"}
                  `,children:d?e.jsx(ee,{className:"w-5 h-5"}):e.jsx(c.icon,{className:"w-5 h-5"})}),e.jsxs("div",{className:"ml-3",children:[e.jsxs("p",{className:`text-sm font-medium ${s||r?"text-gray-900":"text-gray-400"}`,children:[c.title,i.isCompleted&&!s&&e.jsx("span",{className:"ml-2 text-green-600",children:"✓"})]}),e.jsx("p",{className:`text-xs ${s||r?"text-gray-600":"text-gray-400"}`,children:c.description})]})]}),t<n.length-1&&e.jsx("div",{className:`
                    flex-1 h-0.5 mx-4 transition-colors
                    ${d?"bg-green-600":r?"bg-blue-600":"bg-gray-300"}
                  `})]},c.id)})})})}function Se({currentStep:n,stepsLength:a,isPending:o,prevStep:c,nextStep:t,handleCancel:i,handleSubmit:s}){const{t:r}=V();return e.jsx("div",{className:"border-t border-gray-200 px-8 py-6",children:e.jsxs("div",{className:"flex justify-between",children:[e.jsxs(B,{variant:"outline",onClick:c,disabled:n===0||o,children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),r("tasks.create.navigation.previous")]}),e.jsxs("div",{className:"flex space-x-3",children:[e.jsx(B,{variant:"outline",onClick:i,disabled:o,children:r("common.cancel")}),n<a-1?e.jsxs(B,{onClick:t,disabled:o,children:[r("tasks.create.navigation.next"),e.jsx(je,{className:"w-4 h-4 ml-2"})]}):e.jsx(se,{loading:o,onClick:s,disabled:o,className:"px-6 py-2 bg-blue-600 text-white rounded-md hover:bg-blue-700 disabled:opacity-50 disabled:cursor-not-allowed",children:r(o?"tasks.create.navigation.submitting":"tasks.create.navigation.submit")})]})]})})}const Ie=".pdf,.doc,.docx,.ppt,.pptx,.jpg,.jpeg,.png",Fe=".pdf,.png,.jpg,.jpeg";function Te({form:n,ossConfigs:a,mineruConfigs:o}){const c=T.useRef(null),t=T.useRef(null),i=ge(),{t:s}=V(),r=T.useMemo(()=>{var x;const u=n.state.values.mineruConfigId;if(!u||!o)return"selfhost";const l=o.find(h=>h.id===u);return((x=l==null?void 0:l.value)==null?void 0:x.type)??"selfhost"},[n.state.values.mineruConfigId,o]),d=r==="saas"?Ie:Fe,g=s(r==="saas"?"tasks.create.file.supportedFormats.saas":"tasks.create.file.supportedFormats.selfhost"),m=async u=>{if(!u||u.length===0)return;const l=Array.from(u),x=I.loading(s("tasks.create.file.uploading",{count:u.length}));try{const h=await i.mutateAsync(l);n.setFieldValue("storagePath",h.path),I.success(s("tasks.create.file.uploadSuccess"),{id:x})}catch(h){I.error(s("tasks.create.file.uploadError"),{id:x}),console.error("Upload error:",h)}},p=u=>{m(u.target.files)},v=u=>{m(u.target.files)},N=()=>{var u;return(u=c.current)==null?void 0:u.click()},f=()=>{var u;return(u=t.current)==null?void 0:u.click()};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-4",children:s("tasks.create.file.heading")}),e.jsx("p",{className:"text-gray-600 mb-6",children:s("tasks.create.file.subheading")})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(n.Field,{name:"storageType",children:u=>e.jsx(b,{label:s("tasks.create.file.source.label"),htmlFor:"storageType",children:e.jsxs(R,{value:u.state.value,onValueChange:l=>{u.handleChange(l),n.setFieldValue("storagePath",""),l!=="s3"&&n.setFieldValue("ossConfigId",void 0)},className:"flex items-center space-x-4 mt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"local",id:"local"}),e.jsx(C,{htmlFor:"local",children:s("tasks.create.file.source.options.local")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"s3",id:"s3"}),e.jsx(C,{htmlFor:"s3",children:s("tasks.create.file.source.options.s3")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"url",id:"url"}),e.jsx(C,{htmlFor:"url",children:s("tasks.create.file.source.options.url")})]})]})})}),e.jsx(n.Subscribe,{selector:u=>u.values.storageType,children:u=>e.jsxs(e.Fragment,{children:[u==="local"&&e.jsxs("div",{className:"space-y-4",children:[e.jsxs("div",{className:"border-2 border-dashed border-gray-300 rounded-lg p-8 text-center hover:border-gray-400 transition-colors",children:[e.jsx(J,{className:"w-12 h-12 text-gray-400 mx-auto mb-4"}),e.jsx("p",{className:"text-gray-600 mb-2",children:s("tasks.create.file.local.dropHint")}),e.jsx("p",{className:"text-sm text-gray-500 mb-4",children:g}),e.jsxs("div",{className:"flex justify-center gap-3",children:[e.jsxs(B,{type:"button",variant:"outline",onClick:N,className:"flex items-center gap-2",children:[e.jsx(xe,{className:"w-4 h-4"}),s("tasks.create.file.local.selectFiles")]}),e.jsxs(B,{type:"button",variant:"outline",onClick:f,className:"flex items-center gap-2",children:[e.jsx(ve,{className:"w-4 h-4"}),s("tasks.create.file.local.selectDirectory")]})]})]}),e.jsx(n.Field,{name:"storagePath",validators:{onChange:({value:l})=>!l||l.trim().length===0?s("tasks.create.file.local.errors.missingUpload"):void 0},children:l=>e.jsxs(b,{label:s("tasks.create.file.local.pathLabel"),htmlFor:"storagePath",required:!0,children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(P,{id:"storagePath",value:l.state.value,onChange:x=>l.handleChange(x.target.value),onBlur:l.handleBlur,placeholder:s("tasks.create.file.local.pathPlaceholder"),className:"flex-1 bg-gray-100",readOnly:!0}),i.isSuccess&&e.jsx(ke,{className:"w-5 h-5 text-green-600"}),i.isError&&e.jsx(pe,{className:"w-5 h-5 text-red-600"})]}),l.state.meta.errors.length>0&&e.jsx(z,{content:l.state.meta.errors[0],type:"warning",className:"mt-1"})]})})]}),u==="s3"&&e.jsxs("div",{className:"space-y-4",children:[e.jsx(n.Field,{name:"ossConfigId",children:l=>{var x;return e.jsx(b,{label:s("tasks.create.file.s3.configLabel"),htmlFor:"ossConfigId",help:s("tasks.create.file.s3.configHelp"),children:e.jsxs(te,{value:((x=l.state.value)==null?void 0:x.toString())||"",onValueChange:h=>l.handleChange(h?Number.parseInt(h):void 0),children:[e.jsx(ae,{children:e.jsx(re,{placeholder:s("tasks.create.file.s3.configPlaceholder")})}),e.jsx(le,{children:a&&a.length>0?a.map(h=>e.jsx(K,{value:h.id.toString(),children:h.name},h.id)):e.jsx(K,{value:"no-options",disabled:!0,children:s("tasks.create.common.noOptions")})})]})})}}),e.jsx(n.Field,{name:"storagePath",validators:{onChange:({value:l})=>{if(!l||l.trim().length===0)return s("tasks.create.file.s3.pathRequired");if(!/^s3:\/\/[a-z0-9][a-z0-9.-]*[a-z0-9]\/.+/.test(l))return s("tasks.create.file.s3.pathInvalid")}},children:l=>e.jsxs(b,{label:s("tasks.create.file.s3.pathLabel"),htmlFor:"storagePath",required:!0,help:s("tasks.create.file.s3.pathHelp"),children:[e.jsx(P,{id:"storagePath",value:l.state.value,onChange:x=>l.handleChange(x.target.value),onBlur:l.handleBlur,placeholder:s("tasks.create.file.s3.pathPlaceholder")}),l.state.meta.errors.length>0&&e.jsx(z,{content:l.state.meta.errors[0],type:"warning",className:"mt-1"})]})})]}),u==="url"&&e.jsx(n.Field,{name:"storagePath",validators:{onChange:({value:l})=>{if(!l||l.trim().length===0)return s("tasks.create.file.url.required");try{const x=new URL(l);if(!["http:","https:"].includes(x.protocol))return s("tasks.create.file.url.protocol")}catch{return s("tasks.create.file.url.invalid")}}},children:l=>e.jsxs(b,{label:s("tasks.create.file.url.label"),htmlFor:"storagePath",required:!0,help:s("tasks.create.file.url.help"),children:[e.jsx(P,{id:"storagePath",value:l.state.value,onChange:x=>l.handleChange(x.target.value),onBlur:l.handleBlur,placeholder:s("tasks.create.file.url.placeholder")}),l.state.meta.errors.length>0&&e.jsx(z,{content:l.state.meta.errors[0],type:"warning",className:"mt-1"})]})})]})}),e.jsx("input",{ref:c,type:"file",onChange:p,className:"hidden",accept:d,multiple:!0}),e.jsx("input",{ref:t,type:"file",onChange:v,className:"hidden",webkitdirectory:"",directory:"",multiple:!0})]})]})}function Pe({form:n,knowledgeBaseConfigs:a}){const{t:o}=V();return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h2",{className:"text-xl font-semibold text-gray-900 mb-4",children:o("tasks.create.knowledge.heading")}),e.jsx("p",{className:"text-gray-600 mb-6",children:o("tasks.create.knowledge.subheading")})]}),e.jsxs("div",{className:"space-y-6",children:[e.jsx(n.Field,{name:"shouldImportToKb",children:c=>e.jsx(b,{label:o("tasks.create.knowledge.import.label"),htmlFor:"shouldImportToKb",required:!0,help:o("tasks.create.knowledge.import.help"),children:e.jsxs(R,{value:c.state.value.toString(),onValueChange:t=>c.handleChange(t==="true"),className:"flex items-center space-x-6 mt-2",children:[e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"true",id:"import-yes"}),e.jsx(C,{htmlFor:"import-yes",children:o("tasks.create.knowledge.import.options.enabled")})]}),e.jsxs("div",{className:"flex items-center space-x-2",children:[e.jsx(w,{value:"false",id:"import-no"}),e.jsx(C,{htmlFor:"import-no",children:o("tasks.create.knowledge.import.options.disabled")})]})]})})}),e.jsx(n.Subscribe,{selector:c=>c.values.shouldImportToKb,children:c=>c?e.jsx(n.Field,{name:"knowledgeBaseConfigIds",children:t=>e.jsx(b,{label:o("tasks.create.knowledge.selection.label"),htmlFor:"knowledgeBaseConfigIds",required:!0,help:o("tasks.create.knowledge.selection.help"),children:e.jsx("div",{className:"space-y-2",children:a&&a.length>0?a.map(i=>{var m;const s=i.value,r=String(i.id),d=s.type?o(`tasks.create.knowledge.types.${s.type}`,{defaultValue:s.type}):o("common.unknownType"),g=(m=t.state.value)==null?void 0:m.includes(i.id);return e.jsx("div",{children:e.jsxs(C,{className:"flex items-start gap-3 rounded-lg border p-3 has-[[aria-checked=true]]:border-blue-600 dark:has-[[aria-checked=true]]:border-blue-900 dark:has-[[aria-checked=true]]:bg-blue-950",children:[e.jsx(de,{id:`kb-${i.id}`,checked:g,className:"data-[state=checked]:border-blue-600 data-[state=checked]:bg-blue-600 data-[state=checked]:text-white dark:data-[state=checked]:border-blue-700 dark:data-[state=checked]:bg-blue-700",onCheckedChange:p=>{const v=t.state.value||[];if(p===!0){v.includes(i.id)||t.handleChange([...v,i.id]);const f=n.state.values.knowledgeBaseOverrides||{};f[r]||n.setFieldValue("knowledgeBaseOverrides",{...f,[r]:{datasetId:s.datasetId||"",importAsChunk:s.importAsChunk??!1}})}else{t.handleChange(v.filter(u=>u!==i.id));const f=n.state.values.knowledgeBaseOverrides||{};if(f[r]){const{[r]:u,...l}=f;n.setFieldValue("knowledgeBaseOverrides",l)}}}}),e.jsxs("div",{className:"grid gap-1.5 font-normal flex-1",children:[e.jsxs("div",{className:"text-sm leading-none font-medium flex gap-2 items-center",children:[e.jsx(q,{className:"w-4 h-4"}),e.jsx("span",{children:i.name}),e.jsxs("span",{className:"text-xs text-gray-500",children:["(",d,")"]})]}),g&&e.jsx("div",{className:"mt-4 space-y-4",children:s.type==="ragflow"&&e.jsxs(e.Fragment,{children:[e.jsx(n.Field,{name:`knowledgeBaseOverrides.${r}.datasetId`,validators:{onBlur:({value:p})=>!p||p.trim().length===0?o("tasks.create.steps.knowledge.errors.datasetId"):void 0},children:p=>{const v=p.state.meta.isTouched&&!p.state.meta.isValid;return e.jsx(b,{label:o("tasks.create.knowledge.datasetIdLabel"),htmlFor:`datasetId-${i.id}`,required:!0,error:p.state.meta.errors[0],children:e.jsx(P,{id:`datasetId-${i.id}`,placeholder:o("tasks.create.knowledge.datasetPlaceholder"),"aria-invalid":v,value:p.state.value??s.datasetId??"",onChange:N=>p.handleChange(N.target.value),onBlur:p.handleBlur})})}}),e.jsx(n.Subscribe,{selector:p=>p.values.shouldChunk,children:p=>p?e.jsx(n.Field,{name:`knowledgeBaseOverrides.${r}.importAsChunk`,children:v=>e.jsx(b,{label:o("tasks.create.knowledge.importChunk.label"),htmlFor:`importAsChunk-${i.id}`,inline:!0,help:o("tasks.create.knowledge.importChunk.help"),children:e.jsx(he,{id:`importAsChunk-${i.id}`,checked:v.state.value??s.importAsChunk??!1,onCheckedChange:N=>v.handleChange(N)})})}):null})]})})]})]})},i.id)}):e.jsxs("div",{className:"flex items-center gap-2 text-gray-500",children:[e.jsx(q,{className:"w-4 h-4"}),e.jsx("span",{children:o("tasks.create.common.noOptions")})]})})})}):null})]})]})}const Be=G({datasetId:j().optional(),importAsChunk:y().optional()}).passthrough(),Oe=G({storageType:ie(["url","local","s3"]),storagePath:j().min(1,"存储路径不能为空"),ossConfigId:S().optional(),mineruConfigId:S().optional(),enableFormula:y().optional(),enableTable:y().optional(),language:j().optional(),callbackUrl:j().optional(),seed:j().optional(),enableOcr:y().optional(),extraFormats:H(j()).optional(),modelVersion:j().optional(),parseMethod:j().optional(),serverUrl:j().optional(),backendType:j().optional(),returnContentList:y().optional(),returnImages:y().optional(),returnMd:y().optional(),startPage:S().optional(),endPage:S().optional(),shouldImportToKb:y(),knowledgeBaseConfigIds:H(S()).optional(),shouldChunk:y(),chunkStrategy:A.optional(),chunkSize:S().min(1,"分块大小必须大于0").max(8192,"分块大小不能超过8192").optional(),chunkOverlap:S().min(0,"分块重叠不能为负数").max(4096,"分块重叠不能超过4096").optional(),knowledgeBaseOverrides:ne(j(),Be).optional()});function Ve({form:n,ossConfigs:a,mineruConfigs:o,knowledgeBaseConfigs:c},t){return[{id:"mineru",title:t("tasks.create.steps.mineru.title"),description:t("tasks.create.steps.mineru.description"),icon:ce,getStatus:s=>({isCompleted:!!s.mineruConfigId,hasError:!1}),validate:({values:s})=>{const r=[];return s.mineruConfigId||r.push(t("tasks.create.steps.mineru.errors.selectConfig")),s.backendType&&["vlm-sglang-client","vlm-vllm-http-client"].includes(s.backendType)&&(!s.serverUrl||s.serverUrl.trim()==="")&&r.push(t("tasks.create.steps.mineru.errors.serverUrl")),{isValid:r.length===0,errors:r}},render:()=>e.jsx(ue,{form:n,mineruConfigs:o})},{id:"chunk",title:t("tasks.create.steps.chunk.title"),description:t("tasks.create.steps.chunk.description"),icon:ye,getStatus:(s,r)=>({isCompleted:r>1,hasError:!1}),validate:({values:s})=>{if(!s.shouldChunk)return{isValid:!0,errors:[]};const r=[];return s.chunkStrategy||r.push(t("tasks.create.steps.chunk.errors.strategy")),(!s.chunkSize||s.chunkSize<=0)&&r.push(t("tasks.create.steps.chunk.errors.size")),(s.chunkOverlap===void 0||s.chunkOverlap<0)&&r.push(t("tasks.create.steps.chunk.errors.overlap")),s.chunkSize&&s.chunkOverlap!==void 0&&s.chunkOverlap>=s.chunkSize&&r.push(t("tasks.create.steps.chunk.errors.overlapRange")),{isValid:r.length===0,errors:r}},render:()=>e.jsx(Ne,{form:n})},{id:"knowledge",title:t("tasks.create.steps.knowledge.title"),description:t("tasks.create.steps.knowledge.description"),icon:q,getStatus:(s,r)=>({isCompleted:s.shouldImportToKb?!!(s.knowledgeBaseConfigIds&&s.knowledgeBaseConfigIds.length>0):r>2,hasError:!1}),validate:({values:s})=>{const r=[];return s.shouldImportToKb&&(!s.knowledgeBaseConfigIds||s.knowledgeBaseConfigIds.length===0)&&r.push(t("tasks.create.steps.knowledge.errors.selectConfig")),s.knowledgeBaseOverrides&&Object.keys(s.knowledgeBaseOverrides).forEach(d=>{var p;const g=c==null?void 0:c.find(v=>v.id===Number(d));((p=g==null?void 0:g.value)==null?void 0:p.type)==="ragflow"&&(s.knowledgeBaseOverrides[d].datasetId||r.push(t("tasks.create.steps.knowledge.errors.datasetId")))}),{isValid:r.length===0,errors:r}},render:()=>e.jsx(Pe,{form:n,knowledgeBaseConfigs:c})},{id:"file",title:t("tasks.create.steps.file.title"),description:t("tasks.create.steps.file.description"),icon:J,getStatus:s=>({isCompleted:!!(s.storagePath&&s.storagePath.trim()!==""),hasError:!1}),validate:({values:s,form:r})=>{var m;const d=[],g=((m=s.storagePath)==null?void 0:m.trim())??"";if(g||(r.validateField("storagePath","change"),d.push(t("tasks.create.steps.file.errors.pathRequired"))),s.storageType==="s3"&&(s.ossConfigId||d.push(t("tasks.create.steps.file.errors.ossRequired")),g&&(/^s3:\/\/[a-z0-9][a-z0-9.-]*[a-z0-9]\/.+/.test(g)||d.push(t("tasks.create.steps.file.errors.s3Invalid")))),s.storageType==="url"&&g)try{const p=new URL(g);["http:","https:"].includes(p.protocol)||d.push(t("tasks.create.steps.file.errors.urlProtocol"))}catch{d.push(t("tasks.create.steps.file.errors.urlInvalid"))}return{isValid:d.length===0,errors:d}},render:()=>e.jsx(Te,{form:n,ossConfigs:a,mineruConfigs:o})}]}function Ae(n,a){const o=r=>n.find(d=>d.id===r);let c,t,i,s;if(a.storageType==="s3"&&a.ossConfigId){const{value:r}=o(a.ossConfigId)||{};c=E.parse({...r,type:a.storageType,storagePath:a.storagePath})}if(a.storageType==="local"&&a.storagePath&&(c=E.parse({type:a.storageType,storagePath:a.storagePath})),a.storageType==="url"&&a.storagePath&&(c=E.parse({type:a.storageType,storagePath:a.storagePath})),a.mineruConfigId){const{value:r}=o(a.mineruConfigId)||{};r.type==="saas"?t=X.parse({...a,...r}):t=Z.parse({...a,...r})}if(a.knowledgeBaseConfigIds){const r=a.knowledgeBaseOverrides||{};i=a.knowledgeBaseConfigIds.map(d=>{const g=o(d);if(!g)return;const m=g.value,p=r[d]??r[String(d)];return p?m.type==="ragflow"?{...m,datasetId:p.datasetId??m.datasetId,importAsChunk:p.importAsChunk??m.importAsChunk}:{...m,...p}:m}).filter(d=>!!d)}return a.shouldChunk&&(s={strategy:a.chunkStrategy??"HYBRID",chunk_size:a.chunkSize??1e3,chunk_overlap:a.chunkOverlap??200}),D.parse({source:c,mineru:t,knowledgeBases:i,chunk:s})}function $e(){const n=Q(),[a,o]=T.useState(0),c=me(),{t}=V(),{data:i}=M({type:L.S3}),{data:s}=M({type:L.MINERU}),{data:r}=M({type:L.KNOWLEDGE_BASE}),d=W({defaultValues:{storageType:"local",storagePath:"",ossConfigId:void 0,mineruConfigId:void 0,enableFormula:!0,enableTable:!0,language:"ch",callbackUrl:"",seed:"",enableOcr:!1,extraFormats:[],modelVersion:"pipeline",parseMethod:"auto",serverUrl:"",backendType:"pipeline",returnContentList:!0,returnImages:!0,returnMd:!0,startPage:void 0,endPage:void 0,shouldImportToKb:!1,knowledgeBaseConfigIds:[],shouldChunk:!1,chunkStrategy:"HYBRID",chunkSize:1e3,chunkOverlap:200,knowledgeBaseOverrides:{}},onSubmit:async({value:h})=>{try{const k=Oe.parse(h),O=Ae([...i||[],...s||[],...r||[]],k);await c.mutateAsync({filePath:k.storagePath,config:O}),I.success(t("tasks.create.toastSuccess")),n({to:"/tasks"})}catch(k){I.error(t("tasks.create.toastError")),console.error("Create task error:",k)}}}),g=T.useMemo(()=>Ve({form:d,ossConfigs:i,mineruConfigs:s,knowledgeBaseConfigs:r},t),[d,i,s,r,t]),m=()=>({form:d,values:d.state.values}),p=(h,k)=>!h||!h.validate?{isValid:!0,errors:[]}:h.validate(m()),v=()=>{const h=p(g[a]);if(!h.isValid&&h.errors.length>0){const k=h.errors.join(t("tasks.create.validation.separator"));I.error(t("tasks.create.validation.message",{errors:k}))}return h.isValid},N=async()=>{v()&&a<g.length-1&&o(k=>k+1)},f=()=>{a>0&&o(h=>h-1)},u=async()=>{const h=m();let k=-1,O=[];for(let F=0;F<g.length;F++){const _=g[F];if(!_.validate)continue;const $=_.validate(h);if(!$.isValid){k=F,O=$.errors;break}}if(k!==-1){if(O.length>0){const F=O.join(t("tasks.create.validation.separator"));I.error(t("tasks.create.validation.message",{errors:F}))}o(k);return}await d.handleSubmit()},l=()=>{c.isPending||Object.values(d.state.values).some(k=>!!k)&&!window.confirm(t("tasks.create.cancelConfirm"))||n({to:"/tasks"})},x=()=>{const h=g[a];return h?h.render():null};return e.jsxs("div",{className:"container mx-auto px-4",children:[e.jsx("div",{className:"mb-8",children:e.jsx("div",{className:"flex items-center mb-4",children:e.jsxs(B,{variant:"ghost",onClick:l,className:"mr-4",disabled:c.isPending,children:[e.jsx(Y,{className:"w-4 h-4 mr-2"}),t("tasks.create.backToList")]})})}),e.jsx(we,{steps:g,currentStep:a,form:d}),e.jsx("div",{className:"bg-white rounded-lg shadow-sm border",children:e.jsxs(oe,{loading:c.isPending,loadingText:t("tasks.create.loading"),children:[e.jsx("div",{className:"p-8",children:x()}),e.jsx(Se,{currentStep:a,stepsLength:g.length,isPending:c.isPending,prevStep:f,nextStep:N,handleCancel:l,handleSubmit:u})]})})]})}export{$e as component};
