@sudocode-ai/local-server 0.1.4 → 0.1.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -558,11 +558,12 @@ https://github.com/highlightjs/highlight.js/issues/2277`),Ut=Q,gt=Ee),Je===void
558
558
  `);const r=n.parentNode;return r?(/ol/i.test(r.nodeName)?"1. ":"- ")+t.replace(/\n/g,`
559
559
  `)+`
560
560
  `:t}}),e.addRule("entityMention",{filter:t=>t.nodeName==="SPAN"&&t.hasAttribute("data-entity-id"),replacement:(t,n)=>{const r=n,s=r.getAttribute("data-entity-id"),i=r.getAttribute("data-display-text"),o=r.getAttribute("data-relationship-type");if(!s)return t;let a=`[[${s}`;return i&&(a+=`|${i}`),a+="]]",o&&(a+=`{ ${o} }`),a}}),e}const oK=_t.create({name:"tabHandler",addKeyboardShortcuts(){return{Tab:()=>{const{state:e}=this.editor,{$from:t}=e.selection,n=t.node(t.depth-1);return n&&n.type.name==="listItem"?this.editor.commands.sinkListItem("listItem"):this.editor.commands.insertContent(" ")},"Shift-Tab":()=>{const{state:e}=this.editor,{$from:t}=e.selection,n=t.node(t.depth-1);return n&&n.type.name==="listItem"?this.editor.commands.liftListItem("listItem"):!1}}}}),aK=_t.create({name:"lineNumbers",addGlobalAttributes(){return[{types:["heading","paragraph","codeBlock","blockquote","orderedList","bulletList"],attributes:{lineNumber:{default:null,parseHTML:e=>e.getAttribute("data-line-number"),renderHTML:e=>e.lineNumber?{"data-line-number":e.lineNumber}:{}}}}]}});function Bd({content:e,editable:t=!1,onSave:n,onChange:r,onCancel:s,className:i="",showToolbar:o=!1,feedback:a=[],onFeedbackClick:l,showLineNumbers:c=!1,selectedLine:u,onLineClick:d,placeholder:f}){const[p,m]=x.useState(""),[g,b]=x.useState(!1),y=x.useRef(!1),w=x.useRef(""),v=mB({extensions:[i4.configure({heading:{levels:[1,2,3,4,5,6],HTMLAttributes:{class:"font-bold"}},codeBlock:!1,code:{HTMLAttributes:{class:"bg-muted/50 rounded px-1.5 py-0.5 font-mono text-sm"}},blockquote:{HTMLAttributes:{class:"border-l-4 border-primary/50 pl-4 italic text-muted-foreground my-4"}},bulletList:!1,orderedList:!1,listItem:!1,listKeymap:!1}),f4.configure({lowlight:iK,HTMLAttributes:{class:"bg-muted/50 rounded-md p-4 font-mono text-sm my-4 overflow-x-auto"}}),h4.configure({placeholder:f,emptyEditorClass:"is-editor-empty"}),YN.extend({addNodeView(){return CC(eK)}}).configure({resizable:!0,HTMLAttributes:{class:"border-collapse table-auto w-full"}}),ZN,JN.configure({HTMLAttributes:{class:"border border-border bg-muted/50 px-4 py-2 text-left font-bold"}}),GN.configure({HTMLAttributes:{class:"border border-border px-4 py-2"}}),Q6.configure({HTMLAttributes:{class:"max-w-full h-auto rounded-md my-4"}}),T$,oK,aK,nK,rK],editable:t,content:p,onUpdate:({editor:A})=>{if(!y.current&&(b(!0),r)){const R=A.getHTML(),I=jv().turndown(R);I!==w.current&&(w.current=I,r(I))}}});x.useEffect(()=>{if(!e){m("");return}const A=sK(e);b1().use(O1).use(sN).use(fN,{allowDangerousHtml:!0}).use(vW,{allowDangerousHtml:!0}).process(A).then(R=>{m(String(R))}).catch(R=>{console.error("Failed to convert markdown to HTML:",R),m(`<pre>${e}</pre>`)})},[e]),x.useEffect(()=>{v&&p&&(v.isFocused||(y.current=!0,v.commands.setContent(p),b(!1),w.current=e,setTimeout(()=>{y.current=!1},100)))},[p,v,e]),x.useEffect(()=>{v&&v.setEditable(t)},[t,v]),x.useEffect(()=>{if(!v||!l)return;const A=T=>{const O=T.target.closest("[data-feedback-id]");if(O){const j=O.getAttribute("data-feedback-id");j&&l(j)}},R=v.view.dom;return R.addEventListener("click",A),()=>{R.removeEventListener("click",A)}},[v,l]),x.useEffect(()=>{if(!v||!c||!e)return;const A=()=>{const T=VW(e),{state:I}=v,{tr:O}=I;let j=0;I.doc.descendants((L,F,q)=>{if(q===I.doc&&L.isBlock){const te=T[j]||j+1;return O.setNodeMarkup(F,void 0,{...L.attrs,lineNumber:String(te)}),j++,!1}return!0}),O.docChanged&&v.view.dispatch(O)},R=setTimeout(()=>{A()},100);return()=>{clearTimeout(R)}},[v,c,e]),x.useEffect(()=>{if(!v||!c)return;const A=T=>{const O=T.target.closest(".ProseMirror > *");if(!O)return;const j=parseInt(O.getAttribute("data-line-number")||"0");j>0&&d&&d(j)},R=v.view.dom;return R.addEventListener("click",A),()=>{R.removeEventListener("click",A)}},[v,c,d]),x.useEffect(()=>{if(!v||!c)return;const A=v.view.dom.querySelectorAll(".ProseMirror > *");A.forEach(R=>R.classList.remove("selected-line")),u&&u>0&&A.forEach(R=>{parseInt(R.getAttribute("data-line-number")||"0")===u&&R.classList.add("selected-line")})},[v,c,u]);const E=()=>{if(!v||!n)return;const A=v.getHTML(),T=jv().turndown(A);n(T),b(!1)},N=()=>{v&&(v.commands.setContent(p),b(!1)),s?.()},k=()=>{const A=window.prompt("Enter image URL:");A&&v&&v.chain().focus().setImage({src:A}).run()},C=()=>{v&&v.chain().focus().insertTable({rows:3,cols:3,withHeaderRow:!0}).run()};return v?h.jsxs("div",{className:i,children:[t&&o&&h.jsxs("div",{className:"flex flex-wrap items-center gap-1 border-b border-border bg-muted/30 px-4 py-2",children:[h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleBold().run(),className:v.isActive("bold")?"bg-muted":"",type:"button",children:h.jsx(rA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleItalic().run(),className:v.isActive("italic")?"bg-muted":"",type:"button",children:h.jsx(mA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleCode().run(),className:v.isActive("code")?"bg-muted":"",type:"button",children:h.jsx(oA,{className:"h-4 w-4"})}),h.jsx("div",{className:"mx-1 h-6 w-px bg-border"}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleHeading({level:1}).run(),className:v.isActive("heading",{level:1})?"bg-muted":"",type:"button",children:h.jsx(uA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleHeading({level:2}).run(),className:v.isActive("heading",{level:2})?"bg-muted":"",type:"button",children:h.jsx(dA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleHeading({level:3}).run(),className:v.isActive("heading",{level:3})?"bg-muted":"",type:"button",children:h.jsx(fA,{className:"h-4 w-4"})}),h.jsx("div",{className:"mx-1 h-6 w-px bg-border"}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleBulletList().run(),className:v.isActive("bulletList")?"bg-muted":"",type:"button",children:h.jsx(yA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleOrderedList().run(),className:v.isActive("orderedList")?"bg-muted":"",type:"button",children:h.jsx(gA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleBlockquote().run(),className:v.isActive("blockquote")?"bg-muted":"",type:"button",children:h.jsx(EA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().toggleCodeBlock().run(),className:v.isActive("codeBlock")?"bg-muted":"",type:"button",children:h.jsx(iA,{className:"h-4 w-4"})}),h.jsx("div",{className:"mx-1 h-6 w-px bg-border"}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:C,className:v.isActive("table")?"bg-muted":"",type:"button",children:h.jsx(_A,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:k,type:"button",children:h.jsx(hA,{className:"h-4 w-4"})}),h.jsx("div",{className:"mx-1 h-6 w-px bg-border"}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().undo().run(),disabled:!v.can().undo(),type:"button",children:h.jsx(TA,{className:"h-4 w-4"})}),h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>v.chain().focus().redo().run(),disabled:!v.can().redo(),type:"button",children:h.jsx(CA,{className:"h-4 w-4"})}),h.jsx("div",{className:"flex-1"}),h.jsx(oe,{variant:"outline",size:"sm",onClick:N,type:"button",children:"Cancel"}),h.jsx(oe,{variant:"default",size:"sm",onClick:E,disabled:!g,type:"button",children:"Save"})]}),h.jsx("div",{className:`p-6 ${c?"tiptap-with-line-numbers":""}`,children:h.jsx(lB,{editor:v,className:"tiptap-editor prose prose-sm dark:prose-invert max-w-none"})})]}):h.jsx("div",{className:i,children:h.jsxs("div",{className:"animate-pulse",children:[h.jsx("div",{className:"mb-2 h-4 w-3/4 rounded bg-muted"}),h.jsx("div",{className:"mb-2 h-4 w-1/2 rounded bg-muted"}),h.jsx("div",{className:"h-4 w-5/6 rounded bg-muted"})]})})}const zv="sudocode:details:viewMode",Fv="sudocode:issue:descriptionCollapsed",lK=[{value:"open",label:"Open"},{value:"in_progress",label:"In Progress"},{value:"blocked",label:"Blocked"},{value:"needs_review",label:"Needs Review"},{value:"closed",label:"Closed"}],cK=[{value:"0",label:"Critical (P0)"},{value:"1",label:"High (P1)"},{value:"2",label:"Medium (P2)"},{value:"3",label:"Low (P3)"},{value:"4",label:"None (P4)"}];function jg({issue:e,onClose:t,onUpdate:n,onDelete:r,onArchive:s,onUnarchive:i,isUpdating:o=!1,isDeleting:a=!1,showOpenDetail:l=!1,hideTopControls:c=!1,viewMode:u,onViewModeChange:d,showViewToggleInline:f=!0}){const p=cr(),[m,g]=x.useState(e.title),[b,y]=x.useState(e.content||""),[w,v]=x.useState(e.status),[E,N]=x.useState(()=>{const ie=localStorage.getItem(zv);return ie!==null?JSON.parse(ie):"formatted"}),[k,C]=x.useState(()=>{const ie=localStorage.getItem(Fv);return ie!==null?JSON.parse(ie):!1}),A=x.useRef(null),R=u??E,T=ie=>{d?d(ie):N(ie)},[I,O]=x.useState(e.priority),[j,L]=x.useState(!1),[F,q]=x.useState(!1),[te,K]=x.useState([]),[le,_]=x.useState(!1),[ae,me]=x.useState(!1),[S,B]=x.useState(!1),$=x.useRef(null),D=x.useRef(null),{createRelationshipAsync:P,deleteRelationshipAsync:W}=QL(),fe=x.useRef(n),ee=x.useRef({title:m,content:b,status:w,priority:I,hasChanges:S});x.useEffect(()=>{fe.current=n},[n]),x.useEffect(()=>{ee.current={title:m,content:b,status:w,priority:I,hasChanges:S}},[m,b,w,I,S]),x.useEffect(()=>{D.current&&(clearTimeout(D.current),D.current=null),B(!1)},[e.id]),x.useEffect(()=>{u||localStorage.setItem(zv,JSON.stringify(E))},[E,u]),x.useEffect(()=>{localStorage.setItem(Fv,JSON.stringify(k))},[k]),x.useEffect(()=>{g(e.title),y(e.content||""),v(e.status),O(e.priority),B(!1)},[e]),x.useEffect(()=>{(async()=>{me(!0);try{const je=await co.getForEntity(e.id,"issue");let it=[];if(Array.isArray(je))it=je;else if(je&&typeof je=="object"&&"outgoing"in je&&"incoming"in je){const tt=je;it=[...tt.outgoing||[],...tt.incoming||[]]}K(it)}catch(je){console.error("Failed to fetch relationships:",je),K([])}finally{me(!1)}})()},[e.id]),x.useEffect(()=>{const ie=je=>{if(!$.current||!t)return;const it=je.target;if($.current.contains(it))return;const tt=it;if(tt.closest("[data-issue-id]")||tt.closest("[data-panel-resize-handle-id]")||tt.classList?.contains("cursor-col-resize"))return;const us=tt.closest('[role="dialog"]'),U=tt.closest('[role="alertdialog"]'),G=tt.closest('[role="listbox"]'),Se=tt.closest("[data-radix-popper-content-wrapper]");if(us||U||G||Se)return;const Ie=tt.closest(".ProseMirror"),Ze=tt.closest(".tiptap-editor"),Ct=tt.closest("[data-tippy-root]"),An=tt.closest(".tippy-box");Ie||Ze||Ct||An||t()};return document.addEventListener("mousedown",ie),()=>{document.removeEventListener("mousedown",ie)}},[t]),x.useEffect(()=>{const ie=je=>{t&&(j||F||le||je.key==="Escape"&&t())};return document.addEventListener("keydown",ie),()=>{document.removeEventListener("keydown",ie)}},[t,j,F,le]),x.useEffect(()=>{if(!(!S||!fe.current))return D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{fe.current?.({title:m,content:b,status:w,priority:I}),B(!1)},1e3),()=>{D.current&&clearTimeout(D.current)}},[m,b,w,I,S]),x.useEffect(()=>()=>{const{hasChanges:ie,title:je,content:it,status:tt,priority:Gn}=ee.current;ie&&fe.current&&fe.current({title:je,content:it,status:tt,priority:Gn})},[]),x.useEffect(()=>{if(R==="markdown"&&A.current){const ie=A.current;ie.style.height="auto",ie.style.height=`${ie.scrollHeight}px`}},[b,R]);const be=ie=>{g(ie),B(!0)},Me=ie=>{y(ie),B(!0)},Le=ie=>{v(ie),B(!0)},Ke=ie=>{O(ie),B(!0)},ce=()=>{r?.(),L(!1)},ne=async(ie,je,it)=>{try{const tt=await P({from_id:e.id,from_type:"issue",to_id:ie,to_type:je,relationship_type:it});K([...te,tt]),_(!1)}catch(tt){console.error("Failed to create relationship:",tt)}},et=async ie=>{try{await W({from_id:ie.from_id,from_type:ie.from_type,to_id:ie.to_id,to_type:ie.to_type,relationship_type:ie.relationship_type}),K(te.filter(je=>!(je.from_id===ie.from_id&&je.to_id===ie.to_id&&je.relationship_type===ie.relationship_type)))}catch(je){console.error("Failed to delete relationship:",je)}},We=async(ie,je)=>{try{const it=await Xn.create(e.id,{config:ie,prompt:je});q(!1),p(`/executions/${it.id}`)}catch(it){console.error("Failed to create execution:",it)}};return h.jsx(Ei,{delayDuration:300,children:h.jsxs("div",{className:"flex h-full flex-col",ref:$,children:[!c&&h.jsxs("div",{className:"flex items-center justify-between px-6 py-3",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[t&&h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsx("button",{onClick:t,className:"text-muted-foreground hover:text-foreground","aria-label":"Back",children:h.jsx(Hu,{className:"h-4 w-4"})})}),h.jsx(Un,{children:"Close (ESC)"})]}),l&&h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsx("button",{onClick:()=>p(`/issues/${e.id}`),className:"text-muted-foreground hover:text-foreground","aria-label":"Open in full page",children:h.jsx(aA,{className:"h-4 w-4"})})}),h.jsx(Un,{children:"Open in full page"})]})]}),h.jsxs("div",{className:"flex items-center gap-4",children:[f&&h.jsxs("div",{className:"mr-4 flex gap-1 rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:R==="formatted"?"outline":"ghost",size:"sm",onClick:()=>T("formatted"),className:`h-7 rounded-sm ${R==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:R==="markdown"?"outline":"ghost",size:"sm",onClick:()=>T("markdown"),className:`h-7 rounded-sm ${R==="markdown"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]}),(s||i)&&h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsx("button",{onClick:()=>e.archived?i?.(e.id):s?.(e.id),className:"text-muted-foreground hover:text-foreground","aria-label":e.archived?"Unarchive":"Archive",disabled:o,children:e.archived?h.jsx(im,{className:"h-4 w-4"}):h.jsx(Oo,{className:"h-4 w-4"})})}),h.jsx(Un,{children:e.archived?"Unarchive":"Archive"})]}),r&&h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsx("button",{onClick:()=>L(!0),className:"text-muted-foreground hover:text-destructive","aria-label":"Delete",disabled:o||a,children:h.jsx(Io,{className:"h-4 w-4"})})}),h.jsx(Un,{children:"Delete issue"})]})]})]}),h.jsx("div",{className:`flex-1 overflow-y-auto px-6 ${c?"py-4":"py-3"}`,children:h.jsxs("div",{className:"space-y-4",children:[h.jsxs("div",{className:"space-y-2 pb-3",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx(st,{variant:"issue",className:"font-mono",children:e.id}),n&&h.jsx("div",{className:"text-xs italic text-muted-foreground",children:o?"Saving...":S?"Unsaved changes...":"All changes saved"})]}),h.jsx(is,{value:m,onChange:ie=>be(ie.target.value),placeholder:"Issue title...",disabled:o,className:"border-none bg-transparent px-0 text-2xl font-semibold shadow-none focus-visible:ring-0"})]}),h.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(sA,{className:"h-4 w-4 text-muted-foreground"}),h.jsxs(Sn,{value:w,onValueChange:ie=>Le(ie),disabled:o,children:[h.jsx(dn,{className:"h-8 w-auto gap-3 rounded-md border-none bg-accent px-3 shadow-none hover:bg-accent/80",children:h.jsx(En,{placeholder:"Status"})}),h.jsx(fn,{children:lK.map(ie=>h.jsx(xt,{value:ie.value,children:ie.label},ie.value))})]})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Jw,{className:"h-4 w-4 text-muted-foreground"}),h.jsxs(Sn,{value:String(I),onValueChange:ie=>Ke(parseInt(ie)),disabled:o,children:[h.jsx(dn,{className:"h-8 w-auto gap-3 rounded-md border-none bg-accent px-3 shadow-none hover:bg-accent/80",children:h.jsx(En,{placeholder:"Priority"})}),h.jsx(fn,{children:cK.map(ie=>h.jsx(xt,{value:ie.value,children:ie.label},ie.value))})]})]}),e.parent_id&&h.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[h.jsx(lm,{className:"h-4 w-4"}),h.jsx("span",{children:e.parent_id})]}),h.jsx("div",{className:"ml-auto text-xs text-muted-foreground",children:e.closed_at?`Closed ${Mc(new Date(e.closed_at.endsWith("Z")?e.closed_at:e.closed_at+"Z"),{addSuffix:!0})}`:`Updated ${Mc(new Date(e.updated_at.endsWith("Z")?e.updated_at:e.updated_at+"Z"),{addSuffix:!0})}`})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsxs("div",{className:"flex items-center gap-1",children:[h.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Relationships"}),h.jsx(st,{variant:"secondary",children:te.length})]}),h.jsxs(oe,{variant:"outline",size:"xs",onClick:()=>_(!le),className:"h-6",children:[h.jsx(Si,{className:"mr-1 h-4 w-4"}),"Add"]})]}),le&&h.jsx("div",{className:"rounded-lg border p-4",children:h.jsx(hS,{fromId:e.id,fromType:"issue",onSubmit:ne,onCancel:()=>_(!1)})}),ae?h.jsx("div",{className:"py-4 text-center text-sm text-muted-foreground",children:"Loading relationships..."}):h.jsx(uS,{relationships:te,currentEntityId:e.id,currentEntityType:"issue",onDelete:et,showEmpty:!1,showGroupHeaders:!1})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Description"}),h.jsx(oe,{variant:"ghost",size:"xs",onClick:()=>C(!k),className:"h-6 gap-1 text-muted-foreground",children:k?h.jsxs(h.Fragment,{children:[h.jsx(Aa,{className:"h-4 w-4"}),"Expand"]}):h.jsxs(h.Fragment,{children:[h.jsx(am,{className:"h-4 w-4"}),"Collapse"]})})]}),h.jsxs("div",{className:"relative",children:[h.jsx("div",{className:`overflow-hidden transition-all duration-300 ease-in-out ${k?"max-h-[200px] cursor-pointer 2xl:max-h-[300px]":""}`,onClick:()=>{k&&C(!1)},children:h.jsx(It,{className:"overflow-hidden rounded-md border",children:R==="formatted"?h.jsx(Bd,{content:b,editable:!k,onChange:Me,onCancel:()=>{y(e.content||""),B(!1)},className:"min-h-[200px]",placeholder:"Issue description..."}):h.jsx("div",{className:"p-4",children:h.jsx("textarea",{ref:A,value:b,onChange:ie=>Me(ie.target.value),placeholder:"Issue description in markdown...",className:"w-full resize-none border-none bg-transparent font-mono text-sm leading-6 outline-none focus:ring-0",spellCheck:!1,disabled:k,style:{minHeight:"200px"}})})})}),k&&h.jsxs(h.Fragment,{children:[h.jsx("div",{className:"pointer-events-none absolute bottom-0 left-0 right-0 h-16 bg-gradient-to-t from-background to-transparent"}),h.jsx("div",{className:"absolute bottom-2 left-1/2 -translate-x-1/2",children:h.jsxs(oe,{variant:"outline",size:"sm",onClick:ie=>{ie.stopPropagation(),C(!1)},className:"gap-1 shadow-sm",children:[h.jsx(Aa,{className:"h-4 w-4"}),"Expand"]})})]})]})]}),e.assignee&&h.jsx("div",{className:"border-t pt-4",children:h.jsxs("div",{className:"text-sm",children:[h.jsx("span",{className:"text-muted-foreground",children:"Assignee: "}),h.jsx("span",{children:e.assignee})]})}),h.jsx(XL,{issueId:e.id})]})}),h.jsx("div",{className:"border-t bg-background px-6 py-3",children:h.jsx("div",{className:"flex items-center justify-end gap-3",children:h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsxs(oe,{onClick:()=>q(!0),disabled:e.archived||o,variant:"default",size:"xs",className:"gap-2",children:[h.jsx(SA,{className:"h-4 w-4"}),"Run Agent"]})}),h.jsx(Un,{children:"Configure and start agent execution"})]})})}),h.jsx(lS,{issue:e,isOpen:j,onClose:()=>L(!1),onConfirm:ce,isDeleting:a}),h.jsx(GL,{issueId:e.id,open:F,onStart:We,onCancel:()=>q(!1)})]})})}const Bv="sudocode:issueEditor:viewMode",uK=[{value:"open",label:"Open"},{value:"in_progress",label:"In Progress"},{value:"blocked",label:"Blocked"},{value:"needs_review",label:"Needs Review"},{value:"closed",label:"Closed"}],dK=[{value:"0",label:"Critical (P0)"},{value:"1",label:"High (P1)"},{value:"2",label:"Medium (P2)"},{value:"3",label:"Low (P3)"},{value:"4",label:"None (P4)"}];function fK({issue:e,onSave:t,onCancel:n,isLoading:r=!1}){const[s,i]=x.useState(e?.title||""),[o,a]=x.useState(e?.content||""),[l,c]=x.useState(e?.status||"open"),[u,d]=x.useState(e?.priority??2),[f,p]=x.useState({}),[m,g]=x.useState(()=>{const v=localStorage.getItem(Bv);return v!==null?JSON.parse(v):"formatted"}),b=x.useRef(null);x.useEffect(()=>{e&&(i(e.title),a(e.content||""),c(e.status),d(e.priority))},[e]),x.useEffect(()=>{localStorage.setItem(Bv,JSON.stringify(m))},[m]),x.useEffect(()=>{if(m==="markdown"&&b.current){const v=b.current;v.style.height="auto",v.style.height=`${v.scrollHeight}px`}},[o,m]);const y=()=>{const v={};return s.trim()?s.length>200&&(v.title="Title must be less than 200 characters"):v.title="Title is required",p(v),Object.keys(v).length===0},w=v=>{v.preventDefault(),y()&&t({title:s,content:o,status:l,priority:u})};return h.jsxs("form",{onSubmit:w,className:"space-y-4",children:[h.jsxs("div",{className:"space-y-2",children:[h.jsxs(Ht,{htmlFor:"title",children:["Title ",h.jsx("span",{className:"text-destructive",children:"*"})]}),h.jsx(is,{id:"title",value:s,onChange:v=>i(v.target.value),placeholder:"Enter issue title...",className:f.title?"border-destructive":"",disabled:r}),f.title&&h.jsx("p",{className:"text-sm text-destructive",children:f.title})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx(Ht,{htmlFor:"content",children:"Details"}),h.jsxs("div",{className:"flex gap-1 rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:m==="formatted"?"outline":"ghost",size:"sm",onClick:()=>g("formatted"),className:`h-7 rounded-sm ${m==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,type:"button",children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:m==="markdown"?"outline":"ghost",size:"sm",onClick:()=>g("markdown"),className:`h-7 rounded-sm ${m==="markdown"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,type:"button",children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]})]}),h.jsx(It,{className:"overflow-hidden rounded-md border",children:m==="formatted"?h.jsx(Bd,{content:o,editable:!0,onChange:v=>a(v),onSave:v=>a(v),onCancel:()=>{e&&a(e.content||"")},className:"min-h-[300px]",placeholder:"Issue description..."}):h.jsx("div",{className:"p-4",children:h.jsx("textarea",{ref:b,value:o,onChange:v=>a(v.target.value),placeholder:"Issue description in markdown...",className:"w-full resize-none border-none bg-transparent font-mono text-sm leading-6 outline-none focus:ring-0",spellCheck:!1,style:{minHeight:"300px"},disabled:r})})})]}),h.jsxs("div",{className:"grid grid-cols-2 gap-4",children:[h.jsxs("div",{className:"space-y-2",children:[h.jsx(Ht,{htmlFor:"status",children:"Status"}),h.jsxs(Sn,{value:l,onValueChange:v=>c(v),disabled:r,children:[h.jsx(dn,{id:"status",children:h.jsx(En,{placeholder:"Select status"})}),h.jsx(fn,{children:uK.map(v=>h.jsx(xt,{value:v.value,children:v.label},v.value))})]})]}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(Ht,{htmlFor:"priority",children:"Priority"}),h.jsxs(Sn,{value:String(u),onValueChange:v=>d(parseInt(v)),disabled:r,children:[h.jsx(dn,{id:"priority",children:h.jsx(En,{placeholder:"Select priority"})}),h.jsx(fn,{children:dK.map(v=>h.jsx(xt,{value:v.value,children:v.label},v.value))})]})]})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[h.jsx(oe,{type:"button",variant:"outline",onClick:n,disabled:r,children:"Cancel"}),h.jsx(oe,{type:"submit",disabled:r,children:r?"Saving...":e?"Update Issue":"Create Issue"})]})]})}function hK({isOpen:e,onClose:t,onCreate:n,isCreating:r=!1,defaultStatus:s}){const[i,o]=x.useState(!1),a=c=>{n(c),o(!1)},l=()=>{i&&!window.confirm("You have unsaved changes. Are you sure you want to close?")||(o(!1),t())};return h.jsx(Bi,{open:e,onOpenChange:l,children:h.jsxs(qs,{className:"max-h-[90vh] max-w-2xl overflow-y-auto",children:[h.jsx(Ws,{children:h.jsx(Ks,{children:"Create New Issue"})}),h.jsx(fK,{issue:s?{status:s,priority:2}:null,onSave:a,onCancel:l,isLoading:r})]})})}const $d=x.createContext(null);$d.displayName="PanelGroupContext";const Rt={group:"data-panel-group",groupDirection:"data-panel-group-direction",groupId:"data-panel-group-id",panel:"data-panel",panelCollapsible:"data-panel-collapsible",panelId:"data-panel-id",panelSize:"data-panel-size",resizeHandle:"data-resize-handle",resizeHandleActive:"data-resize-handle-active",resizeHandleEnabled:"data-panel-resize-handle-enabled",resizeHandleId:"data-panel-resize-handle-id",resizeHandleState:"data-resize-handle-state"},zg=10,xi=x.useLayoutEffect,$v=lT.useId,pK=typeof $v=="function"?$v:()=>null;let mK=0;function Fg(e=null){const t=pK(),n=x.useRef(e||t||null);return n.current===null&&(n.current=""+mK++),e??n.current}function XN({children:e,className:t="",collapsedSize:n,collapsible:r,defaultSize:s,forwardedRef:i,id:o,maxSize:a,minSize:l,onCollapse:c,onExpand:u,onResize:d,order:f,style:p,tagName:m="div",...g}){const b=x.useContext($d);if(b===null)throw Error("Panel components must be rendered within a PanelGroup container");const{collapsePanel:y,expandPanel:w,getPanelSize:v,getPanelStyle:E,groupId:N,isPanelCollapsed:k,reevaluatePanelConstraints:C,registerPanel:A,resizePanel:R,unregisterPanel:T}=b,I=Fg(o),O=x.useRef({callbacks:{onCollapse:c,onExpand:u,onResize:d},constraints:{collapsedSize:n,collapsible:r,defaultSize:s,maxSize:a,minSize:l},id:I,idIsFromProps:o!==void 0,order:f});x.useRef({didLogMissingDefaultSizeWarning:!1}),xi(()=>{const{callbacks:L,constraints:F}=O.current,q={...F};O.current.id=I,O.current.idIsFromProps=o!==void 0,O.current.order=f,L.onCollapse=c,L.onExpand=u,L.onResize=d,F.collapsedSize=n,F.collapsible=r,F.defaultSize=s,F.maxSize=a,F.minSize=l,(q.collapsedSize!==F.collapsedSize||q.collapsible!==F.collapsible||q.maxSize!==F.maxSize||q.minSize!==F.minSize)&&C(O.current,q)}),xi(()=>{const L=O.current;return A(L),()=>{T(L)}},[f,I,A,T]),x.useImperativeHandle(i,()=>({collapse:()=>{y(O.current)},expand:L=>{w(O.current,L)},getId(){return I},getSize(){return v(O.current)},isCollapsed(){return k(O.current)},isExpanded(){return!k(O.current)},resize:L=>{R(O.current,L)}}),[y,w,v,k,I,R]);const j=E(O.current,s);return x.createElement(m,{...g,children:e,className:t,id:I,style:{...j,...p},[Rt.groupId]:N,[Rt.panel]:"",[Rt.panelCollapsible]:r||void 0,[Rt.panelId]:I,[Rt.panelSize]:parseFloat(""+j.flexGrow).toFixed(1)})}const Ja=x.forwardRef((e,t)=>x.createElement(XN,{...e,forwardedRef:t}));XN.displayName="Panel";Ja.displayName="forwardRef(Panel)";let $p=null,xc=-1,Ns=null;function gK(e,t,n){const r=(t&r_)!==0,s=(t&s_)!==0,i=(t&i_)!==0,o=(t&o_)!==0;if(t){if(r)return i?"se-resize":o?"ne-resize":"e-resize";if(s)return i?"sw-resize":o?"nw-resize":"w-resize";if(i)return"s-resize";if(o)return"n-resize"}switch(e){case"horizontal":return"ew-resize";case"intersection":return"move";case"vertical":return"ns-resize"}}function bK(){Ns!==null&&(document.head.removeChild(Ns),$p=null,Ns=null,xc=-1)}function hh(e,t,n){var r,s;const i=gK(e,t);if($p!==i){if($p=i,Ns===null&&(Ns=document.createElement("style"),document.head.appendChild(Ns)),xc>=0){var o;(o=Ns.sheet)===null||o===void 0||o.removeRule(xc)}xc=(r=(s=Ns.sheet)===null||s===void 0?void 0:s.insertRule(`*{cursor: ${i} !important;}`))!==null&&r!==void 0?r:-1}}function QN(e){return e.type==="keydown"}function e_(e){return e.type.startsWith("pointer")}function t_(e){return e.type.startsWith("mouse")}function Ud(e){if(e_(e)){if(e.isPrimary)return{x:e.clientX,y:e.clientY}}else if(t_(e))return{x:e.clientX,y:e.clientY};return{x:1/0,y:1/0}}function yK(){if(typeof matchMedia=="function")return matchMedia("(pointer:coarse)").matches?"coarse":"fine"}function xK(e,t,n){return e.x<t.x+t.width&&e.x+e.width>t.x&&e.y<t.y+t.height&&e.y+e.height>t.y}function vK(e,t){if(e===t)throw new Error("Cannot compare node with itself");const n={a:Vv(e),b:Vv(t)};let r;for(;n.a.at(-1)===n.b.at(-1);)e=n.a.pop(),t=n.b.pop(),r=e;Ue(r,"Stacking order can only be calculated for elements with a common ancestor");const s={a:Hv(Uv(n.a)),b:Hv(Uv(n.b))};if(s.a===s.b){const i=r.childNodes,o={a:n.a.at(-1),b:n.b.at(-1)};let a=i.length;for(;a--;){const l=i[a];if(l===o.a)return 1;if(l===o.b)return-1}}return Math.sign(s.a-s.b)}const wK=/\b(?:position|zIndex|opacity|transform|webkitTransform|mixBlendMode|filter|webkitFilter|isolation)\b/;function kK(e){var t;const n=getComputedStyle((t=n_(e))!==null&&t!==void 0?t:e).display;return n==="flex"||n==="inline-flex"}function SK(e){const t=getComputedStyle(e);return!!(t.position==="fixed"||t.zIndex!=="auto"&&(t.position!=="static"||kK(e))||+t.opacity<1||"transform"in t&&t.transform!=="none"||"webkitTransform"in t&&t.webkitTransform!=="none"||"mixBlendMode"in t&&t.mixBlendMode!=="normal"||"filter"in t&&t.filter!=="none"||"webkitFilter"in t&&t.webkitFilter!=="none"||"isolation"in t&&t.isolation==="isolate"||wK.test(t.willChange)||t.webkitOverflowScrolling==="touch")}function Uv(e){let t=e.length;for(;t--;){const n=e[t];if(Ue(n,"Missing node"),SK(n))return n}return null}function Hv(e){return e&&Number(getComputedStyle(e).zIndex)||0}function Vv(e){const t=[];for(;e;)t.push(e),e=n_(e);return t}function n_(e){const{parentNode:t}=e;return t&&t instanceof ShadowRoot?t.host:t}const r_=1,s_=2,i_=4,o_=8,EK=yK()==="coarse";let xr=[],bo=!1,_s=new Map,Hd=new Map;const Za=new Set;function CK(e,t,n,r,s){var i;const{ownerDocument:o}=t,a={direction:n,element:t,hitAreaMargins:r,setResizeHandlerState:s},l=(i=_s.get(o))!==null&&i!==void 0?i:0;return _s.set(o,l+1),Za.add(a),Tu(),function(){var u;Hd.delete(e),Za.delete(a);const d=(u=_s.get(o))!==null&&u!==void 0?u:1;if(_s.set(o,d-1),Tu(),d===1&&_s.delete(o),xr.includes(a)){const f=xr.indexOf(a);f>=0&&xr.splice(f,1),Vd(),s("up",!0,null)}}}function NK(e){const{target:t}=e,{x:n,y:r}=Ud(e);bo=!0,Bg({target:t,x:n,y:r}),Tu(),xr.length>0&&(Au("down",e),Vd(),e.preventDefault(),a_(t)||e.stopImmediatePropagation())}function ph(e){const{x:t,y:n}=Ud(e);if(bo&&e.type!=="pointerleave"&&e.buttons===0&&(bo=!1,Au("up",e)),!bo){const{target:r}=e;Bg({target:r,x:t,y:n})}Au("move",e),Vd(),xr.length>0&&e.preventDefault()}function mh(e){const{target:t}=e,{x:n,y:r}=Ud(e);Hd.clear(),bo=!1,xr.length>0&&(e.preventDefault(),a_(t)||e.stopImmediatePropagation()),Au("up",e),Bg({target:t,x:n,y:r}),Vd(),Tu()}function a_(e){let t=e;for(;t;){if(t.hasAttribute(Rt.resizeHandle))return!0;t=t.parentElement}return!1}function Bg({target:e,x:t,y:n}){xr.splice(0);let r=null;(e instanceof HTMLElement||e instanceof SVGElement)&&(r=e),Za.forEach(s=>{const{element:i,hitAreaMargins:o}=s,a=i.getBoundingClientRect(),{bottom:l,left:c,right:u,top:d}=a,f=EK?o.coarse:o.fine;if(t>=c-f&&t<=u+f&&n>=d-f&&n<=l+f){if(r!==null&&document.contains(r)&&i!==r&&!i.contains(r)&&!r.contains(i)&&vK(r,i)>0){let m=r,g=!1;for(;m&&!m.contains(i);){if(xK(m.getBoundingClientRect(),a)){g=!0;break}m=m.parentElement}if(g)return}xr.push(s)}})}function gh(e,t){Hd.set(e,t)}function Vd(){let e=!1,t=!1;xr.forEach(r=>{const{direction:s}=r;s==="horizontal"?e=!0:t=!0});let n=0;Hd.forEach(r=>{n|=r}),e&&t?hh("intersection",n):e?hh("horizontal",n):t?hh("vertical",n):bK()}let bh;function Tu(){var e;(e=bh)===null||e===void 0||e.abort(),bh=new AbortController;const t={capture:!0,signal:bh.signal};Za.size&&(bo?(xr.length>0&&_s.forEach((n,r)=>{const{body:s}=r;n>0&&(s.addEventListener("contextmenu",mh,t),s.addEventListener("pointerleave",ph,t),s.addEventListener("pointermove",ph,t))}),_s.forEach((n,r)=>{const{body:s}=r;s.addEventListener("pointerup",mh,t),s.addEventListener("pointercancel",mh,t)})):_s.forEach((n,r)=>{const{body:s}=r;n>0&&(s.addEventListener("pointerdown",NK,t),s.addEventListener("pointermove",ph,t))}))}function Au(e,t){Za.forEach(n=>{const{setResizeHandlerState:r}=n,s=xr.includes(n);r(e,s,t)})}function _K(){const[e,t]=x.useState(0);return x.useCallback(()=>t(n=>n+1),[])}function Ue(e,t){if(!e)throw console.error(t),Error(t)}function Li(e,t,n=zg){return e.toFixed(n)===t.toFixed(n)?0:e>t?1:-1}function Jr(e,t,n=zg){return Li(e,t,n)===0}function $n(e,t,n){return Li(e,t,n)===0}function TK(e,t,n){if(e.length!==t.length)return!1;for(let r=0;r<e.length;r++){const s=e[r],i=t[r];if(!$n(s,i,n))return!1}return!0}function oo({panelConstraints:e,panelIndex:t,size:n}){const r=e[t];Ue(r!=null,`Panel constraints not found for index ${t}`);let{collapsedSize:s=0,collapsible:i,maxSize:o=100,minSize:a=0}=r;if(Li(n,a)<0)if(i){const l=(s+a)/2;Li(n,l)<0?n=s:n=a}else n=a;return n=Math.min(o,n),n=parseFloat(n.toFixed(zg)),n}function la({delta:e,initialLayout:t,panelConstraints:n,pivotIndices:r,prevLayout:s,trigger:i}){if($n(e,0))return t;const o=[...t],[a,l]=r;Ue(a!=null,"Invalid first pivot index"),Ue(l!=null,"Invalid second pivot index");let c=0;if(i==="keyboard"){{const d=e<0?l:a,f=n[d];Ue(f,`Panel constraints not found for index ${d}`);const{collapsedSize:p=0,collapsible:m,minSize:g=0}=f;if(m){const b=t[d];if(Ue(b!=null,`Previous layout not found for panel index ${d}`),$n(b,p)){const y=g-b;Li(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}{const d=e<0?a:l,f=n[d];Ue(f,`No panel constraints found for index ${d}`);const{collapsedSize:p=0,collapsible:m,minSize:g=0}=f;if(m){const b=t[d];if(Ue(b!=null,`Previous layout not found for panel index ${d}`),$n(b,g)){const y=b-p;Li(y,Math.abs(e))>0&&(e=e<0?0-y:y)}}}}{const d=e<0?1:-1;let f=e<0?l:a,p=0;for(;;){const g=t[f];Ue(g!=null,`Previous layout not found for panel index ${f}`);const y=oo({panelConstraints:n,panelIndex:f,size:100})-g;if(p+=y,f+=d,f<0||f>=n.length)break}const m=Math.min(Math.abs(e),Math.abs(p));e=e<0?0-m:m}{let f=e<0?a:l;for(;f>=0&&f<n.length;){const p=Math.abs(e)-Math.abs(c),m=t[f];Ue(m!=null,`Previous layout not found for panel index ${f}`);const g=m-p,b=oo({panelConstraints:n,panelIndex:f,size:g});if(!$n(m,b)&&(c+=m-b,o[f]=b,c.toFixed(3).localeCompare(Math.abs(e).toFixed(3),void 0,{numeric:!0})>=0))break;e<0?f--:f++}}if(TK(s,o))return s;{const d=e<0?l:a,f=t[d];Ue(f!=null,`Previous layout not found for panel index ${d}`);const p=f+c,m=oo({panelConstraints:n,panelIndex:d,size:p});if(o[d]=m,!$n(m,p)){let g=p-m,y=e<0?l:a;for(;y>=0&&y<n.length;){const w=o[y];Ue(w!=null,`Previous layout not found for panel index ${y}`);const v=w+g,E=oo({panelConstraints:n,panelIndex:y,size:v});if($n(w,E)||(g-=E-w,o[y]=E),$n(g,0))break;e>0?y--:y++}}}const u=o.reduce((d,f)=>f+d,0);return $n(u,100)?o:s}function AK({layout:e,panelsArray:t,pivotIndices:n}){let r=0,s=100,i=0,o=0;const a=n[0];Ue(a!=null,"No pivot index found"),t.forEach((d,f)=>{const{constraints:p}=d,{maxSize:m=100,minSize:g=0}=p;f===a?(r=g,s=m):(i+=g,o+=m)});const l=Math.min(s,100-i),c=Math.max(r,100-o),u=e[a];return{valueMax:l,valueMin:c,valueNow:u}}function Ya(e,t=document){return Array.from(t.querySelectorAll(`[${Rt.resizeHandleId}][data-panel-group-id="${e}"]`))}function l_(e,t,n=document){const s=Ya(e,n).findIndex(i=>i.getAttribute(Rt.resizeHandleId)===t);return s??null}function c_(e,t,n){const r=l_(e,t,n);return r!=null?[r,r+1]:[-1,-1]}function MK(e){return e instanceof HTMLElement?!0:typeof e=="object"&&e!==null&&"tagName"in e&&"getAttribute"in e}function u_(e,t=document){if(MK(t)&&t.dataset.panelGroupId==e)return t;const n=t.querySelector(`[data-panel-group][data-panel-group-id="${e}"]`);return n||null}function qd(e,t=document){const n=t.querySelector(`[${Rt.resizeHandleId}="${e}"]`);return n||null}function RK(e,t,n,r=document){var s,i,o,a;const l=qd(t,r),c=Ya(e,r),u=l?c.indexOf(l):-1,d=(s=(i=n[u])===null||i===void 0?void 0:i.id)!==null&&s!==void 0?s:null,f=(o=(a=n[u+1])===null||a===void 0?void 0:a.id)!==null&&o!==void 0?o:null;return[d,f]}function OK({committedValuesRef:e,eagerValuesRef:t,groupId:n,layout:r,panelDataArray:s,panelGroupElement:i,setLayout:o}){x.useRef({didWarnAboutMissingResizeHandle:!1}),xi(()=>{if(!i)return;const a=Ya(n,i);for(let l=0;l<s.length-1;l++){const{valueMax:c,valueMin:u,valueNow:d}=AK({layout:r,panelsArray:s,pivotIndices:[l,l+1]}),f=a[l];if(f!=null){const p=s[l];Ue(p,`No panel data found for index "${l}"`),f.setAttribute("aria-controls",p.id),f.setAttribute("aria-valuemax",""+Math.round(c)),f.setAttribute("aria-valuemin",""+Math.round(u)),f.setAttribute("aria-valuenow",d!=null?""+Math.round(d):"")}}return()=>{a.forEach((l,c)=>{l.removeAttribute("aria-controls"),l.removeAttribute("aria-valuemax"),l.removeAttribute("aria-valuemin"),l.removeAttribute("aria-valuenow")})}},[n,r,s,i]),x.useEffect(()=>{if(!i)return;const a=t.current;Ue(a,"Eager values not found");const{panelDataArray:l}=a,c=u_(n,i);Ue(c!=null,`No group found for id "${n}"`);const u=Ya(n,i);Ue(u,`No resize handles found for group id "${n}"`);const d=u.map(f=>{const p=f.getAttribute(Rt.resizeHandleId);Ue(p,"Resize handle element has no handle id attribute");const[m,g]=RK(n,p,l,i);if(m==null||g==null)return()=>{};const b=y=>{if(!y.defaultPrevented)switch(y.key){case"Enter":{y.preventDefault();const w=l.findIndex(v=>v.id===m);if(w>=0){const v=l[w];Ue(v,`No panel data found for index ${w}`);const E=r[w],{collapsedSize:N=0,collapsible:k,minSize:C=0}=v.constraints;if(E!=null&&k){const A=la({delta:$n(E,N)?C-N:N-E,initialLayout:r,panelConstraints:l.map(R=>R.constraints),pivotIndices:c_(n,p,i),prevLayout:r,trigger:"keyboard"});r!==A&&o(A)}}break}}};return f.addEventListener("keydown",b),()=>{f.removeEventListener("keydown",b)}});return()=>{d.forEach(f=>f())}},[i,e,t,n,r,s,o])}function qv(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!==t[n])return!1;return!0}function d_(e,t){const n=e==="horizontal",{x:r,y:s}=Ud(t);return n?r:s}function IK(e,t,n,r,s){const i=n==="horizontal",o=qd(t,s);Ue(o,`No resize handle element found for id "${t}"`);const a=o.getAttribute(Rt.groupId);Ue(a,"Resize handle element has no group id attribute");let{initialCursorPosition:l}=r;const c=d_(n,e),u=u_(a,s);Ue(u,`No group element found for id "${a}"`);const d=u.getBoundingClientRect(),f=i?d.width:d.height;return(c-l)/f*100}function DK(e,t,n,r,s,i){if(QN(e)){const o=n==="horizontal";let a=0;e.shiftKey?a=100:s!=null?a=s:a=10;let l=0;switch(e.key){case"ArrowDown":l=o?0:a;break;case"ArrowLeft":l=o?-a:0;break;case"ArrowRight":l=o?a:0;break;case"ArrowUp":l=o?0:-a;break;case"End":l=100;break;case"Home":l=-100;break}return l}else return r==null?0:IK(e,t,n,r,i)}function LK({panelDataArray:e}){const t=Array(e.length),n=e.map(i=>i.constraints);let r=0,s=100;for(let i=0;i<e.length;i++){const o=n[i];Ue(o,`Panel constraints not found for index ${i}`);const{defaultSize:a}=o;a!=null&&(r++,t[i]=a,s-=a)}for(let i=0;i<e.length;i++){const o=n[i];Ue(o,`Panel constraints not found for index ${i}`);const{defaultSize:a}=o;if(a!=null)continue;const l=e.length-r,c=s/l;r++,t[i]=c,s-=c}return t}function Wi(e,t,n){t.forEach((r,s)=>{const i=e[s];Ue(i,`Panel data not found for index ${s}`);const{callbacks:o,constraints:a,id:l}=i,{collapsedSize:c=0,collapsible:u}=a,d=n[l];if(d==null||r!==d){n[l]=r;const{onCollapse:f,onExpand:p,onResize:m}=o;m&&m(r,d),u&&(f||p)&&(p&&(d==null||Jr(d,c))&&!Jr(r,c)&&p(),f&&(d==null||!Jr(d,c))&&Jr(r,c)&&f())}})}function ic(e,t){if(e.length!==t.length)return!1;for(let n=0;n<e.length;n++)if(e[n]!=t[n])return!1;return!0}function PK({defaultSize:e,dragState:t,layout:n,panelData:r,panelIndex:s,precision:i=3}){const o=n[s];let a;return o==null?a=e!=null?e.toFixed(i):"1":r.length===1?a="1":a=o.toFixed(i),{flexBasis:0,flexGrow:a,flexShrink:1,overflow:"hidden",pointerEvents:t!==null?"none":void 0}}function jK(e,t=10){let n=null;return(...s)=>{n!==null&&clearTimeout(n),n=setTimeout(()=>{e(...s)},t)}}function Wv(e){try{if(typeof localStorage<"u")e.getItem=t=>localStorage.getItem(t),e.setItem=(t,n)=>{localStorage.setItem(t,n)};else throw new Error("localStorage not supported in this environment")}catch(t){console.error(t),e.getItem=()=>null,e.setItem=()=>{}}}function f_(e){return`react-resizable-panels:${e}`}function h_(e){return e.map(t=>{const{constraints:n,id:r,idIsFromProps:s,order:i}=t;return s?r:i?`${i}:${JSON.stringify(n)}`:JSON.stringify(n)}).sort((t,n)=>t.localeCompare(n)).join(",")}function p_(e,t){try{const n=f_(e),r=t.getItem(n);if(r){const s=JSON.parse(r);if(typeof s=="object"&&s!=null)return s}}catch{}return null}function zK(e,t,n){var r,s;const i=(r=p_(e,n))!==null&&r!==void 0?r:{},o=h_(t);return(s=i[o])!==null&&s!==void 0?s:null}function FK(e,t,n,r,s){var i;const o=f_(e),a=h_(t),l=(i=p_(e,s))!==null&&i!==void 0?i:{};l[a]={expandToSizes:Object.fromEntries(n.entries()),layout:r};try{s.setItem(o,JSON.stringify(l))}catch(c){console.error(c)}}function Kv({layout:e,panelConstraints:t}){const n=[...e],r=n.reduce((i,o)=>i+o,0);if(n.length!==t.length)throw Error(`Invalid ${t.length} panel layout: ${n.map(i=>`${i}%`).join(", ")}`);if(!$n(r,100)&&n.length>0)for(let i=0;i<t.length;i++){const o=n[i];Ue(o!=null,`No layout data found for index ${i}`);const a=100/r*o;n[i]=a}let s=0;for(let i=0;i<t.length;i++){const o=n[i];Ue(o!=null,`No layout data found for index ${i}`);const a=oo({panelConstraints:t,panelIndex:i,size:o});o!=a&&(s+=o-a,n[i]=a)}if(!$n(s,0))for(let i=0;i<t.length;i++){const o=n[i];Ue(o!=null,`No layout data found for index ${i}`);const a=o+s,l=oo({panelConstraints:t,panelIndex:i,size:a});if(o!==l&&(s-=l-o,n[i]=l,$n(s,0)))break}return n}const BK=100,ca={getItem:e=>(Wv(ca),ca.getItem(e)),setItem:(e,t)=>{Wv(ca),ca.setItem(e,t)}},Gv={};function m_({autoSaveId:e=null,children:t,className:n="",direction:r,forwardedRef:s,id:i=null,onLayout:o=null,keyboardResizeBy:a=null,storage:l=ca,style:c,tagName:u="div",...d}){const f=Fg(i),p=x.useRef(null),[m,g]=x.useState(null),[b,y]=x.useState([]),w=_K(),v=x.useRef({}),E=x.useRef(new Map),N=x.useRef(0),k=x.useRef({autoSaveId:e,direction:r,dragState:m,id:f,keyboardResizeBy:a,onLayout:o,storage:l}),C=x.useRef({layout:b,panelDataArray:[],panelDataArrayChanged:!1});x.useRef({didLogIdAndOrderWarning:!1,didLogPanelConstraintsWarning:!1,prevPanelIds:[]}),x.useImperativeHandle(s,()=>({getId:()=>k.current.id,getLayout:()=>{const{layout:S}=C.current;return S},setLayout:S=>{const{onLayout:B}=k.current,{layout:$,panelDataArray:D}=C.current,P=Kv({layout:S,panelConstraints:D.map(W=>W.constraints)});qv($,P)||(y(P),C.current.layout=P,B&&B(P),Wi(D,P,v.current))}}),[]),xi(()=>{k.current.autoSaveId=e,k.current.direction=r,k.current.dragState=m,k.current.id=f,k.current.onLayout=o,k.current.storage=l}),OK({committedValuesRef:k,eagerValuesRef:C,groupId:f,layout:b,panelDataArray:C.current.panelDataArray,setLayout:y,panelGroupElement:p.current}),x.useEffect(()=>{const{panelDataArray:S}=C.current;if(e){if(b.length===0||b.length!==S.length)return;let B=Gv[e];B==null&&(B=jK(FK,BK),Gv[e]=B);const $=[...S],D=new Map(E.current);B(e,$,D,b,l)}},[e,b,l]),x.useEffect(()=>{});const A=x.useCallback(S=>{const{onLayout:B}=k.current,{layout:$,panelDataArray:D}=C.current;if(S.constraints.collapsible){const P=D.map(be=>be.constraints),{collapsedSize:W=0,panelSize:fe,pivotIndices:ee}=si(D,S,$);if(Ue(fe!=null,`Panel size not found for panel "${S.id}"`),!Jr(fe,W)){E.current.set(S.id,fe);const Me=to(D,S)===D.length-1?fe-W:W-fe,Le=la({delta:Me,initialLayout:$,panelConstraints:P,pivotIndices:ee,prevLayout:$,trigger:"imperative-api"});ic($,Le)||(y(Le),C.current.layout=Le,B&&B(Le),Wi(D,Le,v.current))}}},[]),R=x.useCallback((S,B)=>{const{onLayout:$}=k.current,{layout:D,panelDataArray:P}=C.current;if(S.constraints.collapsible){const W=P.map(Ke=>Ke.constraints),{collapsedSize:fe=0,panelSize:ee=0,minSize:be=0,pivotIndices:Me}=si(P,S,D),Le=B??be;if(Jr(ee,fe)){const Ke=E.current.get(S.id),ce=Ke!=null&&Ke>=Le?Ke:Le,et=to(P,S)===P.length-1?ee-ce:ce-ee,We=la({delta:et,initialLayout:D,panelConstraints:W,pivotIndices:Me,prevLayout:D,trigger:"imperative-api"});ic(D,We)||(y(We),C.current.layout=We,$&&$(We),Wi(P,We,v.current))}}},[]),T=x.useCallback(S=>{const{layout:B,panelDataArray:$}=C.current,{panelSize:D}=si($,S,B);return Ue(D!=null,`Panel size not found for panel "${S.id}"`),D},[]),I=x.useCallback((S,B)=>{const{panelDataArray:$}=C.current,D=to($,S);return PK({defaultSize:B,dragState:m,layout:b,panelData:$,panelIndex:D})},[m,b]),O=x.useCallback(S=>{const{layout:B,panelDataArray:$}=C.current,{collapsedSize:D=0,collapsible:P,panelSize:W}=si($,S,B);return Ue(W!=null,`Panel size not found for panel "${S.id}"`),P===!0&&Jr(W,D)},[]),j=x.useCallback(S=>{const{layout:B,panelDataArray:$}=C.current,{collapsedSize:D=0,collapsible:P,panelSize:W}=si($,S,B);return Ue(W!=null,`Panel size not found for panel "${S.id}"`),!P||Li(W,D)>0},[]),L=x.useCallback(S=>{const{panelDataArray:B}=C.current;B.push(S),B.sort(($,D)=>{const P=$.order,W=D.order;return P==null&&W==null?0:P==null?-1:W==null?1:P-W}),C.current.panelDataArrayChanged=!0,w()},[w]);xi(()=>{if(C.current.panelDataArrayChanged){C.current.panelDataArrayChanged=!1;const{autoSaveId:S,onLayout:B,storage:$}=k.current,{layout:D,panelDataArray:P}=C.current;let W=null;if(S){const ee=zK(S,P,$);ee&&(E.current=new Map(Object.entries(ee.expandToSizes)),W=ee.layout)}W==null&&(W=LK({panelDataArray:P}));const fe=Kv({layout:W,panelConstraints:P.map(ee=>ee.constraints)});qv(D,fe)||(y(fe),C.current.layout=fe,B&&B(fe),Wi(P,fe,v.current))}}),xi(()=>{const S=C.current;return()=>{S.layout=[]}},[]);const F=x.useCallback(S=>{let B=!1;const $=p.current;return $&&window.getComputedStyle($,null).getPropertyValue("direction")==="rtl"&&(B=!0),function(P){P.preventDefault();const W=p.current;if(!W)return()=>null;const{direction:fe,dragState:ee,id:be,keyboardResizeBy:Me,onLayout:Le}=k.current,{layout:Ke,panelDataArray:ce}=C.current,{initialLayout:ne}=ee??{},et=c_(be,S,W);let We=DK(P,S,fe,ee,Me,W);const ie=fe==="horizontal";ie&&B&&(We=-We);const je=ce.map(Gn=>Gn.constraints),it=la({delta:We,initialLayout:ne??Ke,panelConstraints:je,pivotIndices:et,prevLayout:Ke,trigger:QN(P)?"keyboard":"mouse-or-touch"}),tt=!ic(Ke,it);(e_(P)||t_(P))&&N.current!=We&&(N.current=We,!tt&&We!==0?ie?gh(S,We<0?r_:s_):gh(S,We<0?i_:o_):gh(S,0)),tt&&(y(it),C.current.layout=it,Le&&Le(it),Wi(ce,it,v.current))}},[]),q=x.useCallback((S,B)=>{const{onLayout:$}=k.current,{layout:D,panelDataArray:P}=C.current,W=P.map(Ke=>Ke.constraints),{panelSize:fe,pivotIndices:ee}=si(P,S,D);Ue(fe!=null,`Panel size not found for panel "${S.id}"`);const Me=to(P,S)===P.length-1?fe-B:B-fe,Le=la({delta:Me,initialLayout:D,panelConstraints:W,pivotIndices:ee,prevLayout:D,trigger:"imperative-api"});ic(D,Le)||(y(Le),C.current.layout=Le,$&&$(Le),Wi(P,Le,v.current))},[]),te=x.useCallback((S,B)=>{const{layout:$,panelDataArray:D}=C.current,{collapsedSize:P=0,collapsible:W}=B,{collapsedSize:fe=0,collapsible:ee,maxSize:be=100,minSize:Me=0}=S.constraints,{panelSize:Le}=si(D,S,$);Le!=null&&(W&&ee&&Jr(Le,P)?Jr(P,fe)||q(S,fe):Le<Me?q(S,Me):Le>be&&q(S,be))},[q]),K=x.useCallback((S,B)=>{const{direction:$}=k.current,{layout:D}=C.current;if(!p.current)return;const P=qd(S,p.current);Ue(P,`Drag handle element not found for id "${S}"`);const W=d_($,B);g({dragHandleId:S,dragHandleRect:P.getBoundingClientRect(),initialCursorPosition:W,initialLayout:D})},[]),le=x.useCallback(()=>{g(null)},[]),_=x.useCallback(S=>{const{panelDataArray:B}=C.current,$=to(B,S);$>=0&&(B.splice($,1),delete v.current[S.id],C.current.panelDataArrayChanged=!0,w())},[w]),ae=x.useMemo(()=>({collapsePanel:A,direction:r,dragState:m,expandPanel:R,getPanelSize:T,getPanelStyle:I,groupId:f,isPanelCollapsed:O,isPanelExpanded:j,reevaluatePanelConstraints:te,registerPanel:L,registerResizeHandle:F,resizePanel:q,startDragging:K,stopDragging:le,unregisterPanel:_,panelGroupElement:p.current}),[A,m,r,R,T,I,f,O,j,te,L,F,q,K,le,_]),me={display:"flex",flexDirection:r==="horizontal"?"row":"column",height:"100%",overflow:"hidden",width:"100%"};return x.createElement($d.Provider,{value:ae},x.createElement(u,{...d,children:t,className:n,id:i,ref:p,style:{...me,...c},[Rt.group]:"",[Rt.groupDirection]:r,[Rt.groupId]:f}))}const $g=x.forwardRef((e,t)=>x.createElement(m_,{...e,forwardedRef:t}));m_.displayName="PanelGroup";$g.displayName="forwardRef(PanelGroup)";function to(e,t){return e.findIndex(n=>n===t||n.id===t.id)}function si(e,t,n){const r=to(e,t),i=r===e.length-1?[r-1,r]:[r,r+1],o=n[r];return{...t.constraints,panelSize:o,pivotIndices:i}}function $K({disabled:e,handleId:t,resizeHandler:n,panelGroupElement:r}){x.useEffect(()=>{if(e||n==null||r==null)return;const s=qd(t,r);if(s==null)return;const i=o=>{if(!o.defaultPrevented)switch(o.key){case"ArrowDown":case"ArrowLeft":case"ArrowRight":case"ArrowUp":case"End":case"Home":{o.preventDefault(),n(o);break}case"F6":{o.preventDefault();const a=s.getAttribute(Rt.groupId);Ue(a,`No group element found for id "${a}"`);const l=Ya(a,r),c=l_(a,t,r);Ue(c!==null,`No resize element found for id "${t}"`);const u=o.shiftKey?c>0?c-1:l.length-1:c+1<l.length?c+1:0;l[u].focus();break}}};return s.addEventListener("keydown",i),()=>{s.removeEventListener("keydown",i)}},[r,e,t,n])}function Ug({children:e=null,className:t="",disabled:n=!1,hitAreaMargins:r,id:s,onBlur:i,onClick:o,onDragging:a,onFocus:l,onPointerDown:c,onPointerUp:u,style:d={},tabIndex:f=0,tagName:p="div",...m}){var g,b;const y=x.useRef(null),w=x.useRef({onClick:o,onDragging:a,onPointerDown:c,onPointerUp:u});x.useEffect(()=>{w.current.onClick=o,w.current.onDragging=a,w.current.onPointerDown=c,w.current.onPointerUp=u});const v=x.useContext($d);if(v===null)throw Error("PanelResizeHandle components must be rendered within a PanelGroup container");const{direction:E,groupId:N,registerResizeHandle:k,startDragging:C,stopDragging:A,panelGroupElement:R}=v,T=Fg(s),[I,O]=x.useState("inactive"),[j,L]=x.useState(!1),[F,q]=x.useState(null),te=x.useRef({state:I});xi(()=>{te.current.state=I}),x.useEffect(()=>{if(n)q(null);else{const ae=k(T);q(()=>ae)}},[n,T,k]);const K=(g=r?.coarse)!==null&&g!==void 0?g:15,le=(b=r?.fine)!==null&&b!==void 0?b:5;x.useEffect(()=>{if(n||F==null)return;const ae=y.current;Ue(ae,"Element ref not attached");let me=!1;return CK(T,ae,E,{coarse:K,fine:le},(B,$,D)=>{if(!$){O("inactive");return}switch(B){case"down":{O("drag"),me=!1,Ue(D,'Expected event to be defined for "down" action'),C(T,D);const{onDragging:P,onPointerDown:W}=w.current;P?.(!0),W?.();break}case"move":{const{state:P}=te.current;me=!0,P!=="drag"&&O("hover"),Ue(D,'Expected event to be defined for "move" action'),F(D);break}case"up":{O("hover"),A();const{onClick:P,onDragging:W,onPointerUp:fe}=w.current;W?.(!1),fe?.(),me||P?.();break}}})},[K,E,n,le,k,T,F,C,A]),$K({disabled:n,handleId:T,resizeHandler:F,panelGroupElement:R});const _={touchAction:"none",userSelect:"none"};return x.createElement(p,{...m,children:e,className:t,id:s,onBlur:()=>{L(!1),i?.()},onFocus:()=>{L(!0),l?.()},ref:y,role:"separator",style:{..._,...d},tabIndex:f,[Rt.groupDirection]:E,[Rt.groupId]:N,[Rt.resizeHandle]:"",[Rt.resizeHandleActive]:I==="drag"?"pointer":j?"keyboard":void 0,[Rt.resizeHandleEnabled]:!n,[Rt.resizeHandleId]:T,[Rt.resizeHandleState]:I})}Ug.displayName="PanelResizeHandle";const Jv="sudocode:issues:sortOption";function UK(){const e=cr(),{issues:t,isLoading:n,isError:r,error:s,createIssueAsync:i,updateIssue:o,deleteIssue:a,archiveIssue:l,unarchiveIssue:c,isCreating:u,isUpdating:d,isDeleting:f}=ed(),p=dO(),[m,g]=x.useState(),[b,y]=x.useState(!1),[w,v]=x.useState(),[E,N]=x.useState(!1),[k,C]=x.useState(""),[A,R]=x.useState(()=>{try{const D=localStorage.getItem(Jv);if(D&&["priority","newest","last-updated"].includes(D))return D}catch(D){console.error("Failed to load sort preference from localStorage:",D)}return"priority"}),[T,I]=x.useState(()=>{try{const D=localStorage.getItem("issuesPage.collapsedColumns");if(D){const P=JSON.parse(D);return new Set(P)}}catch{}return new Set}),O=x.useCallback(D=>{const P=D;R(P);try{localStorage.setItem(Jv,P)}catch(W){console.error("Failed to save sort preference to localStorage:",W)}},[]),j=x.useMemo(()=>{const D=k?t.filter(W=>{const fe=k.toLowerCase();return W.title.toLowerCase().includes(fe)||W.content&&W.content.toLowerCase().includes(fe)}):t,P={open:[],in_progress:[],blocked:[],needs_review:[],closed:[]};return D.forEach(W=>{const fe=W.status.toLowerCase();P[fe]?P[fe].push(W):P.open.push(W)}),Object.keys(P).forEach(W=>{P[W].sort((ee,be)=>{switch(A){case"priority":return ee.priority!==be.priority?ee.priority-be.priority:new Date(be.created_at).getTime()-new Date(ee.created_at).getTime();case"newest":return new Date(be.created_at).getTime()-new Date(ee.created_at).getTime();case"last-updated":return new Date(be.updated_at).getTime()-new Date(ee.updated_at).getTime();default:return 0}})}),P},[t,k,A]),L=x.useCallback(D=>{const{active:P,over:W}=D;if(!W||!P.data.current)return;const fe=P.id,ee=W.id,be=t.find(Me=>Me.id===fe);!be||be.status===ee||p.mutate({id:fe,status:ee})},[t,p]),F=x.useCallback(D=>{g(D)},[]),q=x.useCallback(()=>{g(void 0)},[]),te=x.useCallback(D=>{v(D),y(!0)},[]),K=x.useCallback(async D=>{try{await i(D),y(!1),v(void 0)}catch(P){console.error("Failed to create issue:",P)}},[i]),le=x.useCallback(D=>{m&&o({id:m.id,data:D})},[m,o]),_=x.useCallback(()=>{m&&(a(m.id),g(void 0))},[m,a]),ae=x.useCallback(D=>{l(D)},[l]),me=x.useCallback(D=>{c(D)},[c]),S=x.useCallback(()=>{N(!0)},[]),B=x.useCallback(()=>{(j.closed||[]).forEach(P=>{l(P.id)}),N(!1)},[j.closed,l]),$=x.useCallback(D=>{I(P=>{const W=new Set(P);W.has(D)?W.delete(D):W.add(D);try{localStorage.setItem("issuesPage.collapsedColumns",JSON.stringify(Array.from(W)))}catch{}return W})},[]);return n?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsx("p",{className:"text-muted-foreground",children:"Loading issues..."})}):r?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsxs("p",{className:"text-destructive",children:["Error loading issues: ",s?.message||"Unknown error"]})}):h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("h1",{className:"text-2xl font-bold",children:"Issues"}),h.jsx(st,{variant:"secondary",children:t.length})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter issues...",value:k,onChange:D=>C(D.target.value),className:"h-9 w-64 pl-8"})]}),h.jsxs(Sn,{value:A,onValueChange:O,children:[h.jsx(dn,{className:"h-9 w-[100px]",children:h.jsx(En,{})}),h.jsxs(fn,{children:[h.jsx(xt,{value:"priority",children:"Priority"}),h.jsx(xt,{value:"newest",children:"Newest"}),h.jsx(xt,{value:"last-updated",children:"Updated"})]})]}),h.jsxs(oe,{onClick:()=>e("/issues/archived"),variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-foreground",children:[h.jsx(Oo,{className:"h-4 w-4"}),"Archived"]}),h.jsxs(oe,{onClick:()=>te(),variant:"default",size:"sm",className:"text-primary-foreground hover:bg-primary/90",children:[h.jsx(Si,{className:"mr-2 h-4 w-4"}),"Create Issue"]})]})]}),h.jsx("div",{className:"flex flex-1 overflow-hidden",children:m?h.jsxs($g,{direction:"horizontal",className:"h-full min-h-0",onLayout:D=>{if(D.length===2)try{localStorage.setItem("issuesPage.panelSizes",JSON.stringify(D))}catch{}},children:[h.jsx(Ja,{id:"kanban",order:1,defaultSize:(()=>{try{const D=localStorage.getItem("issuesPage.panelSizes");if(D){const P=JSON.parse(D);if(Array.isArray(P)&&P.length===2)return P[0]}}catch{}return 66})(),minSize:30,className:"min-h-0 min-w-0 overflow-auto",children:h.jsx(Ac,{groupedIssues:j,onDragEnd:L,onViewIssueDetails:F,selectedIssue:m,onArchiveAllClosed:S,collapsedColumns:T,onToggleColumnCollapse:$})}),h.jsxs(Ug,{className:"group relative z-30 w-1 cursor-col-resize touch-none bg-border focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-1 focus-visible:ring-offset-background",children:[h.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border"}),h.jsxs("div",{className:"pointer-events-none absolute left-1/2 top-1/2 flex -translate-x-1/2 -translate-y-1/2 flex-col items-center gap-1 rounded-full border border-border bg-muted/90 px-1.5 py-3 opacity-70 shadow-sm transition-opacity group-hover:opacity-100 group-focus:opacity-100",children:[h.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"h-1 w-1 rounded-full bg-muted-foreground"})]})]}),h.jsx(Ja,{id:"details",order:2,defaultSize:(()=>{try{const D=localStorage.getItem("issuesPage.panelSizes");if(D){const P=JSON.parse(D);if(Array.isArray(P)&&P.length===2)return P[1]}}catch{}return 34})(),minSize:20,className:"min-h-0 min-w-0 overflow-hidden border-l bg-background shadow-lg",children:h.jsx(jg,{issue:m,onClose:q,onUpdate:le,onDelete:_,onArchive:ae,onUnarchive:me,isUpdating:d,isDeleting:f,showOpenDetail:!0})})]}):h.jsx("div",{className:"flex-1 overflow-auto",children:h.jsx(Ac,{groupedIssues:j,onDragEnd:L,onViewIssueDetails:F,selectedIssue:m,onArchiveAllClosed:S,collapsedColumns:T,onToggleColumnCollapse:$})})}),h.jsx(hK,{isOpen:b,onClose:()=>{y(!1),v(void 0)},onCreate:K,isCreating:u,defaultStatus:w}),h.jsx(Tm,{open:E,onOpenChange:N,children:h.jsxs(cd,{children:[h.jsxs(ud,{children:[h.jsx(fd,{children:"Archive All Closed Issues?"}),h.jsxs(hd,{children:["This will archive all ",j.closed?.length||0," closed issues. You can view archived issues later from the Archived Issues page."]})]}),h.jsxs(dd,{children:[h.jsx(md,{children:"Cancel"}),h.jsx(pd,{onClick:B,children:"Archive All"})]})]})})]})}const Zv="sudocode:details:viewMode";function HK(){const{id:e}=em(),t=cr(),{data:n,isLoading:r,isError:s}=uO(e||""),{updateIssue:i,deleteIssue:o,archiveIssue:a,unarchiveIssue:l,isUpdating:c,isDeleting:u}=ed(),[d,f]=x.useState(!1),[p,m]=x.useState(()=>{const v=localStorage.getItem(Zv);return v!==null?JSON.parse(v):"formatted"}),g=v=>{e&&i({id:e,data:v})},b=()=>{e&&(o(e),t("/issues"))},y=v=>{a(v),t("/issues")},w=v=>{l(v),t("/issues")};return x.useEffect(()=>{localStorage.setItem(Zv,JSON.stringify(p))},[p]),r?h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("div",{className:"mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"}),h.jsx("p",{className:"text-muted-foreground",children:"Loading issue..."})]})}):s||!n?h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("h2",{className:"mb-2 text-2xl font-bold",children:"Issue not found"}),h.jsx("p",{className:"mb-4 text-muted-foreground",children:"The issue you're looking for doesn't exist or has been deleted."}),h.jsx(oe,{onClick:()=>t("/issues"),children:"Back to Issues"})]})}):h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsx("div",{className:"flex items-center gap-4",children:h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>t("/issues"),children:"← Back to Issues"})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("div",{className:"mr-4 flex gap-1 rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:p==="formatted"?"outline":"ghost",size:"sm",onClick:()=>m("formatted"),className:`h-7 rounded-sm ${p==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:p==="markdown"?"outline":"ghost",size:"sm",onClick:()=>m("markdown"),className:`h-7 rounded-sm ${p==="markdown"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]}),n.archived?h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>w(n.id),disabled:c,children:[h.jsx(im,{className:"mr-2 h-4 w-4"}),"Unarchive"]}):h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>y(n.id),disabled:c,children:[h.jsx(Oo,{className:"mr-2 h-4 w-4"}),"Archive"]}),h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>f(!0),disabled:c||u,children:[h.jsx(Io,{className:"mr-2 h-4 w-4"}),"Delete"]})]})]}),h.jsx("div",{className:"flex-1 overflow-auto",children:h.jsx(jg,{issue:n,onUpdate:g,isUpdating:c,isDeleting:u,hideTopControls:!0,viewMode:p,onViewModeChange:m,showViewToggleInline:!1})}),h.jsx(lS,{issue:n,isOpen:d,onClose:()=>f(!1),onConfirm:b,isDeleting:u})]})}function Wd(e){const t=rs(),{connected:n,subscribe:r,unsubscribe:s,addMessageHandler:i,removeMessageHandler:o}=Uu(),a=nl({queryKey:e!==void 0?["specs",{archived:e}]:["specs"],queryFn:()=>so.getAll(e)}),l=x.useCallback(m=>{(m.type==="spec_created"||m.type==="spec_updated"||m.type==="spec_deleted")&&t.invalidateQueries({queryKey:["specs"]})},[t]);x.useEffect(()=>{const m="useSpecs";return i(m,l),n&&r("spec"),()=>{o(m),s("spec")}},[n,r,s,i,o,l]);const c=or({mutationFn:({id:m,data:g})=>so.update(m,g),onMutate:async({id:m,data:g})=>{await t.cancelQueries({queryKey:["specs"]});const b=t.getQueryData(["specs"]);return t.setQueryData(["specs"],y=>y?.map(w=>w.id===m?{...w,...g}:w)),{previousSpecs:b}},onError:(m,g,b)=>{b?.previousSpecs&&t.setQueryData(["specs"],b.previousSpecs)},onSettled:()=>{t.invalidateQueries({queryKey:["specs"]})}}),u=or({mutationFn:so.create,onSuccess:()=>{t.invalidateQueries({queryKey:["specs"]})}}),d=or({mutationFn:so.delete,onSuccess:()=>{t.invalidateQueries({queryKey:["specs"]})}}),f=m=>c.mutate({id:m,data:{archived:!0}}),p=m=>c.mutate({id:m,data:{archived:!1}});return{specs:a.data??[],isLoading:a.isLoading,isError:a.isError,error:a.error,updateSpec:c.mutate,updateSpecAsync:c.mutateAsync,createSpec:u.mutate,createSpecAsync:u.mutateAsync,deleteSpec:d.mutate,archiveSpec:f,unarchiveSpec:p,isUpdating:c.isPending,isCreating:u.isPending}}function VK(e){const t=rs(),{connected:n,subscribe:r,unsubscribe:s,addMessageHandler:i,removeMessageHandler:o}=Uu(),a=nl({queryKey:["specs",e],queryFn:()=>so.getById(e),enabled:!!e}),l=x.useCallback(c=>{c.type==="spec_updated"&&c.data.id===e&&t.invalidateQueries({queryKey:["specs",e]})},[e,t]);return x.useEffect(()=>{if(!e)return;const c=`useSpec-${e}`;return i(c,l),n&&r("spec",e),()=>{o(c),s("spec",e)}},[n,e,r,s,i,o,l]),{spec:a.data,isLoading:a.isLoading,isError:a.isError,error:a.error}}function qK(e){const t=rs(),{connected:n,subscribe:r,unsubscribe:s,addMessageHandler:i,removeMessageHandler:o}=Uu(),a=nl({queryKey:["feedback",e],queryFn:()=>so.getFeedback(e),enabled:!!e}),l=x.useCallback(c=>{(c.type==="feedback_created"||c.type==="feedback_updated"||c.type==="feedback_deleted")&&t.invalidateQueries({queryKey:["feedback",e]})},[e,t]);return x.useEffect(()=>{if(!e)return;const c=`useSpecFeedback-${e}`;return i(c,l),n&&r("all"),()=>{o(c),s("all")}},[n,e,r,s,i,o,l]),{feedback:a.data??[],isLoading:a.isLoading,isError:a.isError,error:a.error}}const WK={0:"bg-red-600 dark:bg-red-700",1:"bg-orange-600 dark:bg-orange-700",2:"bg-yellow-600 dark:bg-yellow-700",3:"bg-blue-600 dark:bg-blue-700",4:"bg-gray-600 dark:bg-gray-700"},KK={0:"P0",1:"P1",2:"P2",3:"P3",4:"P4"};function GK({spec:e,onClick:t}){const n=x.useCallback(()=>{t?.(e)},[e,t]),r=e.content?e.content.slice(0,200)+(e.content.length>200?"...":""):"";return h.jsx(It,{className:`cursor-pointer border border-border p-4 transition-shadow hover:shadow-md ${e.archived?"opacity-60":""}`,onClick:n,children:h.jsxs("div",{className:"flex flex-col gap-3",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("div",{className:"flex items-center gap-2",children:h.jsx("span",{className:"font-mono text-xs text-muted-foreground",children:e.id})}),e.priority!==void 0&&e.priority<=3&&h.jsx("span",{className:`shrink-0 rounded-full px-2 py-0.5 text-xs text-white ${WK[e.priority]}`,children:KK[e.priority]})]}),h.jsx("h3",{className:"line-clamp-2 text-lg font-semibold",children:e.title}),r&&h.jsx("p",{className:"line-clamp-3 text-sm text-muted-foreground",children:r}),h.jsx("div",{className:"flex flex-col gap-2",children:e.file_path&&h.jsx("p",{className:"truncate font-mono text-xs text-muted-foreground",children:e.file_path})})]})})}function g_({specs:e,loading:t=!1,emptyMessage:n="No specs found"}){const r=cr(),s=i=>{r(`/specs/${i.id}`)};return t?h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("div",{className:"mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"}),h.jsx("p",{className:"text-muted-foreground",children:"Loading specs..."})]})}):!e||e.length===0?h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("p",{className:"text-lg text-muted-foreground",children:n}),h.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Create a new spec to get started"})]})}):h.jsx("div",{className:"grid gap-4 md:grid-cols-2 lg:grid-cols-3",children:e.map(i=>h.jsx(GK,{spec:i,onClick:s},i.id))})}const Yv="sudocode:specEditor:viewMode";function JK({spec:e,onSave:t,onCancel:n}){const{createSpecAsync:r,updateSpecAsync:s,isCreating:i}=Wd(),[o,a]=x.useState(e?.title||""),[l,c]=x.useState(e?.content||""),[u,d]=x.useState(e?.priority??3),[f,p]=x.useState(null),[m,g]=x.useState(()=>{const w=localStorage.getItem(Yv);return w!==null?JSON.parse(w):"formatted"}),b=x.useRef(null);x.useEffect(()=>{localStorage.setItem(Yv,JSON.stringify(m))},[m]),x.useEffect(()=>{if(m==="markdown"&&b.current){const w=b.current;w.style.height="auto",w.style.height=`${w.scrollHeight}px`}},[l,m]);const y=async w=>{if(w.preventDefault(),p(null),!o.trim()){p("Title is required");return}try{const v={title:o.trim(),content:l.trim()||void 0,priority:u};if(e){const E=await s({id:e.id,data:v});t?.(E)}else{const E=await r(v);t?.(E)}}catch(v){p(v instanceof Error?v.message:"Failed to save spec")}};return h.jsx(It,{className:"p-6",children:h.jsx("form",{onSubmit:y,children:h.jsxs("div",{className:"space-y-4",children:[h.jsx("div",{children:h.jsx("h2",{className:"mb-4 text-2xl font-bold",children:e?"Edit Spec":"New Spec"})}),f&&h.jsx("div",{className:"rounded-md bg-destructive/10 p-3 text-sm text-destructive",children:f}),h.jsxs("div",{children:[h.jsx("label",{htmlFor:"title",className:"mb-2 block text-sm font-medium",children:"Title *"}),h.jsx("input",{id:"title",type:"text",value:o,onChange:w=>a(w.target.value),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm",placeholder:"Enter spec title"})]}),h.jsxs("div",{children:[h.jsxs("div",{className:"mb-2 flex items-center justify-between",children:[h.jsx("label",{htmlFor:"content",className:"text-sm font-medium",children:"Content"}),h.jsxs("div",{className:"flex gap-1 rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:m==="formatted"?"outline":"ghost",size:"sm",onClick:()=>g("formatted"),className:`h-7 rounded-sm ${m==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,type:"button",children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:m==="markdown"?"outline":"ghost",size:"sm",onClick:()=>g("markdown"),className:`h-7 rounded-sm ${m==="markdown"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,type:"button",children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]})]}),h.jsx(It,{className:"overflow-hidden rounded-md border",children:m==="formatted"?h.jsx(Bd,{content:l,editable:!0,onChange:w=>c(w),onSave:w=>c(w),onCancel:()=>{e&&c(e.content||"")},className:"min-h-[300px]",placeholder:"Spec content (markdown supported)..."}):h.jsx("div",{className:"p-4",children:h.jsx("textarea",{ref:b,id:"content",value:l,onChange:w=>c(w.target.value),className:"w-full resize-none border-none bg-transparent font-mono text-sm leading-6 outline-none focus:ring-0",placeholder:"Spec content (markdown supported)...",spellCheck:!1,style:{minHeight:"300px"},disabled:i})})})]}),h.jsxs("div",{children:[h.jsx("label",{htmlFor:"priority",className:"mb-2 block text-sm font-medium",children:"Priority"}),h.jsxs("select",{id:"priority",value:u,onChange:w=>d(Number(w.target.value)),className:"w-full rounded-md border border-input bg-background px-3 py-2 text-sm",children:[h.jsx("option",{value:0,children:"Critical (0)"}),h.jsx("option",{value:1,children:"High (1)"}),h.jsx("option",{value:2,children:"Medium (2)"}),h.jsx("option",{value:3,children:"Low (3)"}),h.jsx("option",{value:4,children:"None (4)"})]})]}),h.jsxs("div",{className:"flex justify-end gap-2 pt-4",children:[n&&h.jsx(oe,{type:"button",variant:"outline",onClick:n,disabled:i,children:"Cancel"}),h.jsx(oe,{type:"submit",disabled:i,children:i?"Saving...":e?"Update":"Create"})]})]})})})}const Xv="sudocode:specs:sortOption";function ZK(){const{specs:e,isLoading:t}=Wd(),[n,r]=x.useState(!1),[s,i]=x.useState(""),[o,a]=x.useState(()=>{try{const f=localStorage.getItem(Xv);if(f&&["priority","newest","last-updated"].includes(f))return f}catch(f){console.error("Failed to load sort preference from localStorage:",f)}return"priority"}),l=cr(),c=f=>{r(!1),l(`/specs/${f.id}`)},u=f=>{const p=f;a(p);try{localStorage.setItem(Xv,p)}catch(m){console.error("Failed to save sort preference to localStorage:",m)}},d=x.useMemo(()=>[...s?e.filter(m=>{const g=s.toLowerCase();return m.title.toLowerCase().includes(g)||m.content&&m.content.toLowerCase().includes(g)}):e].sort((m,g)=>{switch(o){case"priority":return m.priority!==g.priority?m.priority-g.priority:new Date(g.created_at).getTime()-new Date(m.created_at).getTime();case"newest":return new Date(g.created_at).getTime()-new Date(m.created_at).getTime();case"last-updated":return new Date(g.updated_at).getTime()-new Date(m.updated_at).getTime();default:return 0}}),[e,s,o]);return n?h.jsx("div",{className:"flex-1 p-8",children:h.jsx(JK,{onSave:c,onCancel:()=>r(!1)})}):h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("h1",{className:"text-2xl font-bold",children:"Specs"}),h.jsx(st,{variant:"secondary",children:e.length})]}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter specs...",value:s,onChange:f=>i(f.target.value),className:"h-9 w-64 pl-8"})]}),h.jsxs(oe,{onClick:()=>l("/specs/archived"),variant:"ghost",size:"sm",className:"gap-1 text-muted-foreground hover:text-foreground",children:[h.jsx(Oo,{className:"h-4 w-4"}),"Archived"]}),h.jsxs(oe,{onClick:()=>r(!0),variant:"default",size:"sm",className:"text-primary-foreground hover:bg-primary/90",children:[h.jsx(Si,{className:"mr-2 h-4 w-4"}),"Create Spec"]})]})]}),h.jsxs("div",{className:"flex flex-1 flex-col overflow-hidden px-8 py-4",children:[h.jsx("div",{className:"mb-4 flex justify-end",children:h.jsxs(Sn,{value:o,onValueChange:u,children:[h.jsx(dn,{className:"h-9 w-[180px]",children:h.jsx(En,{})}),h.jsxs(fn,{children:[h.jsx(xt,{value:"priority",children:"Priority"}),h.jsx(xt,{value:"newest",children:"Newest"}),h.jsx(xt,{value:"last-updated",children:"Last Updated"})]})]})}),h.jsx("div",{className:"flex-1 overflow-auto",children:h.jsx(g_,{specs:d,loading:t})})]})]})}function YK(e){const t=rs(),n=or({mutationFn:i=>rf.create(i),onSuccess:()=>{t.invalidateQueries({queryKey:["feedback",e]})}}),r=or({mutationFn:({id:i,data:o})=>rf.update(i,o),onMutate:async({id:i,data:o})=>{await t.cancelQueries({queryKey:["feedback",e]});const a=t.getQueryData(["feedback",e]);return t.setQueryData(["feedback",e],l=>l?.map(c=>{if(c.id!==i)return c;const u={};return o.content!==void 0&&(u.content=o.content),o.feedback_type!==void 0&&(u.feedback_type=o.feedback_type),o.dismissed!==void 0&&(u.dismissed=o.dismissed),o.anchor!==void 0&&(u.anchor=typeof o.anchor=="string"?o.anchor:JSON.stringify(o.anchor)),{...c,...u}})),{previousFeedback:a}},onError:(i,o,a)=>{a?.previousFeedback&&t.setQueryData(["feedback",e],a.previousFeedback)},onSettled:()=>{t.invalidateQueries({queryKey:["feedback",e]})}}),s=or({mutationFn:i=>rf.delete(i),onMutate:async i=>{await t.cancelQueries({queryKey:["feedback",e]});const o=t.getQueryData(["feedback",e]);return t.setQueryData(["feedback",e],a=>a?.filter(l=>l.id!==i)),{previousFeedback:o}},onError:(i,o,a)=>{a?.previousFeedback&&t.setQueryData(["feedback",e],a.previousFeedback)},onSettled:()=>{t.invalidateQueries({queryKey:["feedback",e]})}});return{createFeedback:n.mutate,createFeedbackAsync:n.mutateAsync,updateFeedback:r.mutate,updateFeedbackAsync:r.mutateAsync,deleteFeedback:s.mutate,deleteFeedbackAsync:s.mutateAsync,isCreating:n.isPending,isUpdating:r.isPending,isDeleting:s.isPending}}function XK({type:e,count:t=1,onClick:n,className:r=""}){const s=()=>{switch(e){case"comment":return h.jsx(Vu,{className:"h-3 w-3"});case"suggestion":return h.jsx(Kw,{className:"h-3 w-3"});case"request":return h.jsx(ki,{className:"h-3 w-3"})}},i=()=>{switch(e){case"comment":return"bg-blue-600 hover:bg-blue-700 dark:bg-blue-700 dark:hover:bg-blue-800";case"suggestion":return"bg-yellow-600 hover:bg-yellow-700 dark:bg-yellow-700 dark:hover:bg-yellow-800";case"request":return"bg-orange-600 hover:bg-orange-700 dark:bg-orange-700 dark:hover:bg-orange-800"}};return h.jsxs("button",{onClick:n,className:`inline-flex items-center gap-1 rounded-full px-2 py-0.5 text-xs font-medium text-white transition-colors ${i()} ${r}`,title:`${t} ${e}${t>1?"s":""}`,children:[s(),t>1&&h.jsx("span",{children:t})]})}function QK({content:e,showLineNumbers:t=!0,highlightLines:n=[],feedback:r=[],selectedLine:s,onLineClick:i,onTextSelect:o,onFeedbackClick:a,editable:l=!1,onChange:c,className:u=""}){const d=x.useRef(null),f=x.useMemo(()=>e.split(`
561
- `),[e]),p=x.useMemo(()=>{const y=new Map;return r.forEach(w=>{try{const v=w.anchor?JSON.parse(w.anchor):null;if(v?.line_number){const E=y.get(v.line_number)||[];y.set(v.line_number,[...E,w])}}catch(v){console.error("Failed to parse feedback anchor:",v)}}),y},[r]),m=y=>{i?.(y)},g=y=>{if(!o)return;const v=window.getSelection()?.toString().trim();v&&v.length>0&&o(v,y)},b=y=>{c?.(y.target.value)};return x.useEffect(()=>{if(l&&d.current){const y=d.current;y.style.height="auto",y.style.height=`${y.scrollHeight}px`}},[e,l]),h.jsx(It,{className:`overflow-hidden ${u}`,children:h.jsx("div",{className:"relative",children:l?h.jsx("div",{className:"px-4 py-4",children:h.jsx("textarea",{ref:d,value:e,onChange:b,className:"w-full resize-none border-none bg-transparent font-mono text-sm leading-6 outline-none focus:ring-0",spellCheck:!1})}):h.jsx("div",{className:`grid overflow-x-auto ${t?"grid-cols-[auto_1fr]":"grid-cols-1"}`,children:f.flatMap((y,w)=>{const v=w+1,E=p.get(v)||[],N=[];return t&&N.push(h.jsx("div",{className:`select-none border-r border-border bg-muted/30 px-4 py-1 text-right font-mono text-xs leading-6 text-muted-foreground transition-colors hover:bg-primary/10 ${n.includes(v)?"font-bold text-primary":""} ${s===v?"bg-primary/20":""}`,"data-line-number":v,onClick:()=>m(v),children:v},`line-${w}`)),N.push(h.jsx("div",{className:`group relative px-4 py-1 font-mono text-sm leading-6 ${n.includes(v)?"bg-primary/10":""} ${s===v?"bg-primary/20":""}`,"data-line":v,children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx("pre",{className:"m-0 inline flex-1 cursor-pointer whitespace-pre-wrap break-words font-mono transition-colors hover:bg-muted/30",onClick:()=>m(v),onMouseUp:()=>g(v),children:y||" "}),E.length>0&&h.jsx("div",{className:"flex flex-wrap gap-1",children:Array.from(new Set(E.map(k=>k.feedback_type))).map(k=>{const C=E.filter(A=>A.feedback_type===k);return h.jsx(XK,{type:k,count:C.length,onClick:()=>a?.(C[0])},k)})})]})},`content-${w}`)),N})})})})}function eG({content:e,feedback:t=[],selectedLine:n,onLineClick:r,onTextSelect:s,onFeedbackClick:i,onChange:o,viewMode:a="formatted",onViewModeChange:l,className:c=""}){return h.jsx(It,{className:`overflow-hidden ${c}`,children:a==="formatted"?h.jsx(Bd,{content:e,editable:!0,onChange:o,onCancel:()=>{},showLineNumbers:!1,selectedLine:n,onLineClick:r,placeholder:"Spec content..."}):h.jsx(QK,{content:e,feedback:t,selectedLine:n,onLineClick:r,onTextSelect:s,onFeedbackClick:i,showLineNumbers:!1,editable:!0,onChange:o})})}const tG=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,nG=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,rG={};function Qv(e,t){return(rG.jsx?nG:tG).test(e)}var Ki={},yh,ew;function sG(){if(ew)return yh;ew=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,s=/^:\s*/,i=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
562
- `,c="/",u="*",d="",f="comment",p="declaration";yh=function(g,b){if(typeof g!="string")throw new TypeError("First argument must be a string");if(!g)return[];b=b||{};var y=1,w=1;function v(j){var L=j.match(t);L&&(y+=L.length);var F=j.lastIndexOf(l);w=~F?j.length-F:w+j.length}function E(){var j={line:y,column:w};return function(L){return L.position=new N(j),A(),L}}function N(j){this.start=j,this.end={line:y,column:w},this.source=b.source}N.prototype.content=g;function k(j){var L=new Error(b.source+":"+y+":"+w+": "+j);if(L.reason=j,L.filename=b.source,L.line=y,L.column=w,L.source=g,!b.silent)throw L}function C(j){var L=j.exec(g);if(L){var F=L[0];return v(F),g=g.slice(F.length),L}}function A(){C(n)}function R(j){var L;for(j=j||[];L=T();)L!==!1&&j.push(L);return j}function T(){var j=E();if(!(c!=g.charAt(0)||u!=g.charAt(1))){for(var L=2;d!=g.charAt(L)&&(u!=g.charAt(L)||c!=g.charAt(L+1));)++L;if(L+=2,d===g.charAt(L-1))return k("End of comment missing");var F=g.slice(2,L-2);return w+=2,v(F),g=g.slice(L),w+=2,j({type:f,comment:F})}}function I(){var j=E(),L=C(r);if(L){if(T(),!C(s))return k("property missing ':'");var F=C(i),q=j({type:p,property:m(L[0].replace(e,d)),value:F?m(F[0].replace(e,d)):d});return C(o),q}}function O(){var j=[];R(j);for(var L;L=I();)L!==!1&&(j.push(L),R(j));return j}return A(),O()};function m(g){return g?g.replace(a,d):d}return yh}var tw;function iG(){if(tw)return Ki;tw=1;var e=Ki&&Ki.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ki,"__esModule",{value:!0}),Ki.default=n;const t=e(sG());function n(r,s){let i=null;if(!r||typeof r!="string")return i;const o=(0,t.default)(r),a=typeof s=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:u}=l;a?s(c,u,l):u&&(i=i||{},i[c]=u)}),i}return Ki}var ta={},nw;function oG(){if(nw)return ta;nw=1,Object.defineProperty(ta,"__esModule",{value:!0}),ta.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,s=/^-(ms)-/,i=function(c){return!c||n.test(c)||e.test(c)},o=function(c,u){return u.toUpperCase()},a=function(c,u){return"".concat(u,"-")},l=function(c,u){return u===void 0&&(u={}),i(c)?c:(c=c.toLowerCase(),u.reactCompat?c=c.replace(s,a):c=c.replace(r,a),c.replace(t,o))};return ta.camelCase=l,ta}var na,rw;function aG(){if(rw)return na;rw=1;var e=na&&na.__importDefault||function(s){return s&&s.__esModule?s:{default:s}},t=e(iG()),n=oG();function r(s,i){var o={};return!s||typeof s!="string"||(0,t.default)(s,function(a,l){a&&l&&(o[(0,n.camelCase)(a,i)]=l)}),o}return r.default=r,na=r,na}var lG=aG();const cG=tl(lG),Hg={}.hasOwnProperty,uG=new Map,dG=/[A-Z]/g,fG=new Set(["table","tbody","thead","tfoot","tr"]),hG=new Set(["td","th"]),b_="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function pG(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=kG(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=wG(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?wl:wN,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},i=y_(s,e,void 0);return i&&typeof i!="string"?i:s.create(e,s.Fragment,{children:i||void 0},void 0)}function y_(e,t,n){if(t.type==="element")return mG(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return gG(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return yG(e,t,n);if(t.type==="mdxjsEsm")return bG(e,t);if(t.type==="root")return xG(e,t,n);if(t.type==="text")return vG(e,t)}function mG(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=wl,e.schema=s),e.ancestors.push(t);const i=v_(e,t.tagName,!1),o=SG(e,t);let a=qg(e,t);return fG.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!zd(l):!0})),x_(e,o,i,t),Vg(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function gG(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Xa(e,t.position)}function bG(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Xa(e,t.position)}function yG(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=wl,e.schema=s),e.ancestors.push(t);const i=t.name===null?e.Fragment:v_(e,t.name,!0),o=EG(e,t),a=qg(e,t);return x_(e,o,i,t),Vg(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function xG(e,t,n){const r={};return Vg(r,qg(e,t)),e.create(t,e.Fragment,r,n)}function vG(e,t){return t.value}function x_(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Vg(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function wG(e,t,n){return r;function r(s,i,o,a){const c=Array.isArray(o.children)?n:t;return a?c(i,o,a):c(i,o)}}function kG(e,t){return n;function n(r,s,i,o){const a=Array.isArray(i.children),l=Ng(r);return t(s,i,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function SG(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&Hg.call(t.properties,s)){const i=CG(e,s,t.properties[s]);if(i){const[o,a]=i;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&hG.has(t.tagName)?r=a:n[o]=a}}if(r){const i=n.style||(n.style={});i[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function EG(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const i=r.data.estree.body[0];i.type;const o=i.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Xa(e,t.position);else{const s=r.name;let i;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,i=e.evaluater.evaluateExpression(a.expression)}else Xa(e,t.position);else i=r.value===null?!0:r.value;n[s]=i}return n}function qg(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:uG;for(;++r<t.children.length;){const i=t.children[r];let o;if(e.passKeys){const l=i.type==="element"?i.tagName:i.type==="mdxJsxFlowElement"||i.type==="mdxJsxTextElement"?i.name:void 0;if(l){const c=s.get(l)||0;o=l+"-"+c,s.set(l,c+1)}}const a=y_(e,i,o);a!==void 0&&n.push(a)}return n}function CG(e,t,n){const r=vN(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?SN(n):EN(n)),r.property==="style"){let s=typeof n=="object"?n:NG(e,String(n));return e.stylePropertyNameCase==="css"&&(s=_G(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?f9[r.property]||r.property:r.attribute,n]}}function NG(e,t){try{return cG(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new yn("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=b_+"#cannot-parse-style-attribute",s}}function v_(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let i=-1,o;for(;++i<s.length;){const a=Qv(s[i])?{type:"Identifier",name:s[i]}:{type:"Literal",value:s[i]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(i&&a.type==="Literal"),optional:!1}:a}r=o}else r=Qv(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return Hg.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);Xa(e)}function Xa(e,t){const n=new yn("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=b_+"#cannot-handle-mdx-estrees-without-createevaluater",n}function _G(e){const t={};let n;for(n in e)Hg.call(e,n)&&(t[TG(n)]=e[n]);return t}function TG(e){let t=e.replace(dG,AG);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function AG(e){return"-"+e.toLowerCase()}const xh={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},MG="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",sw=[],iw={allowDangerousHtml:!0},RG=/^(https?|ircs?|mailto|xmpp)$/i,OG=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function w_(e){const t=IG(e),n=DG(e);return LG(t.runSync(t.parse(n),n),e)}function IG(e){const t=e.rehypePlugins||sw,n=e.remarkPlugins||sw,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...iw}:iw;return b1().use(O1).use(n).use(fN,r).use(t)}function DG(e){const t=e.children||"",n=new g1;return typeof t=="string"&&(n.value=t),n}function LG(e,t){const n=t.allowedElements,r=t.allowElement,s=t.components,i=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||PG;for(const u of OG)Object.hasOwn(t,u.from)&&(""+u.from+(u.to?"use `"+u.to+"` instead":"remove it")+MG+u.id,void 0);return t.className&&(e={type:"element",tagName:"div",properties:{className:t.className},children:e.type==="root"?e.children:[e]}),Sg(e,c),pG(e,{Fragment:h.Fragment,components:s,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function c(u,d,f){if(u.type==="raw"&&f&&typeof d=="number")return o?f.children.splice(d,1):f.children[d]={type:"text",value:u.value},d;if(u.type==="element"){let p;for(p in xh)if(Object.hasOwn(xh,p)&&Object.hasOwn(u.properties,p)){const m=u.properties[p],g=xh[p];(g===null||g.includes(u.tagName))&&(u.properties[p]=l(String(m||""),p,u))}}if(u.type==="element"){let p=n?!n.includes(u.tagName):i?i.includes(u.tagName):!1;if(!p&&r&&typeof d=="number"&&(p=!r(u,d,f)),p&&f&&typeof d=="number")return a&&u.children?f.children.splice(d,1,...u.children):f.children.splice(d,1),d}}}function PG(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||r!==-1&&t>r||RG.test(e.slice(0,t))?e:""}function jG({feedback:e,onDismiss:t,onDelete:n,onClick:r,className:s="",maxHeight:i=200,isCompact:o=!1}){const[a,l]=x.useState(!1),[c,u]=x.useState(!o),d=cr();let f=null;try{e.anchor&&(f=JSON.parse(e.anchor))}catch(b){console.error("Failed to parse feedback anchor:",b)}const p=b=>{switch(b){case"comment":return h.jsx(Vu,{className:"h-4 w-4"});case"suggestion":return h.jsx(Kw,{className:"h-4 w-4"});case"request":return h.jsx(ki,{className:"h-4 w-4"})}},m=b=>{switch(b){case"comment":return"text-blue-600 bg-blue-50";case"suggestion":return"text-yellow-600 bg-yellow-50";case"request":return"text-orange-600 bg-orange-50"}},g=()=>f?f.line_number?`L${f.line_number}`:f.section_heading?`§ ${f.section_heading}`:f.text_snippet?`"${f.text_snippet.slice(0,30)}${f.text_snippet.length>30?"...":""}"`:null:null;return h.jsx(It,{className:`relative cursor-pointer rounded-lg border-2 bg-card shadow-sm transition-all hover:border-primary/30 hover:shadow-lg ${e.dismissed?"opacity-60":""} ${s}`,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onClick:r,children:h.jsxs("div",{className:"p-3",children:[h.jsxs("div",{className:"mb-2",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:`flex-shrink-0 rounded-full p-1.5 ${m(e.feedback_type)}`,title:e.feedback_type,children:p(e.feedback_type)}),h.jsx("button",{className:"text-xs font-medium text-foreground hover:text-primary hover:underline",onClick:b=>{b.stopPropagation(),d(`/issues/${e.issue_id}`)},children:e.issue_id})]}),(t||n)&&h.jsxs("div",{className:"flex flex-shrink-0 gap-1 transition-opacity duration-150",style:{opacity:a?1:0},children:[!e.dismissed&&t&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),t(e.id)},title:"Dismiss",className:"h-6 w-6 p-0",children:h.jsx(Ww,{className:"h-3 w-3"})}),e.dismissed&&t&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),t(e.id)},title:"Restore",className:"h-6 w-6 p-0",children:h.jsx(da,{className:"h-3 w-3"})}),n&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),n(e.id)},title:"Delete",className:"h-6 w-6 p-0",children:h.jsx(Io,{className:"h-3 w-3"})})]})]}),h.jsxs("div",{className:"ml-9 flex items-center gap-2 text-xs text-muted-foreground",children:[f&&g()&&h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"flex-shrink-0",children:g()}),h.jsx("span",{className:"flex-shrink-0",children:"•"})]}),h.jsx("span",{className:"flex-shrink-0",children:Mc(new Date(e.created_at.endsWith("Z")?e.created_at:e.created_at+"Z"),{addSuffix:!0})})]})]}),h.jsx("div",{className:"prose prose-sm dark:prose-invert text-sm text-foreground max-w-none",style:{maxHeight:c?`${i}px`:"3rem",overflowY:"auto",overflowX:"hidden"},children:h.jsx(w_,{remarkPlugins:[sN],components:{p:({children:b})=>h.jsx("p",{className:"my-1",children:b}),h1:({children:b})=>h.jsx("h1",{className:"text-lg font-bold my-1",children:b}),h2:({children:b})=>h.jsx("h2",{className:"text-base font-bold my-1",children:b}),h3:({children:b})=>h.jsx("h3",{className:"text-sm font-bold my-1",children:b}),ul:({children:b})=>h.jsx("ul",{className:"my-1 pl-4",children:b}),ol:({children:b})=>h.jsx("ol",{className:"my-1 pl-4",children:b}),li:({children:b})=>h.jsx("li",{className:"my-0.5",children:b}),code:({children:b,className:y})=>!y?h.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:b}):h.jsx("code",{className:`block rounded bg-muted p-2 font-mono text-xs my-1 ${y||""}`,children:b}),pre:({children:b})=>h.jsx("pre",{className:"my-1",children:b}),blockquote:({children:b})=>h.jsx("blockquote",{className:"border-l-2 border-muted-foreground/30 pl-2 my-1 italic",children:b}),a:({href:b,children:y})=>h.jsx("a",{href:b,className:"text-primary underline hover:text-primary/80",target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),children:y}),strong:({children:b})=>h.jsx("strong",{className:"font-semibold",children:b}),em:({children:b})=>h.jsx("em",{className:"italic",children:b})},children:e.content})}),e.content.length>100&&h.jsx("button",{className:"mt-1 text-xs text-primary hover:underline",onClick:b=>{b.stopPropagation(),u(!c)},children:c?"Show less":"Show more"})]})})}function zG({positions:e,cardHeight:t=120,minSpacing:n=8}){return x.useMemo(()=>{const r=new Map,s=Array.from(e.entries()).map(([o,a])=>({id:o,idealTop:a})).sort((o,a)=>o.idealTop-a.idealTop),i=[];for(const o of s){let a=o.idealTop,l=!0;for(;l;){l=!1;for(const u of i){const d=u.actualTop+u.height+n,f=a+t;if(a<d&&f>u.actualTop){a=d,l=!0;break}}}const c={id:o.id,idealTop:o.idealTop,actualTop:a,height:t};i.push(c),r.set(o.id,c)}return r},[e,t,n])}const ow="sudocode:specs:showRelationshipsCollapsed";function FG(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function BG({feedback:e,positions:t,onFeedbackClick:n,onDismiss:r,onDelete:s,addFeedbackButton:i,className:o="",relationships:a,currentEntityId:l,onDeleteRelationship:c,onCreateRelationship:u}){const d=x.useRef(null),[f,p]=x.useState(!1),[m,g]=x.useState(()=>{const v=localStorage.getItem(ow);return v!==null?JSON.parse(v):!1}),b=(v,E,N)=>{u&&(u(v,E,N),p(!1))};x.useEffect(()=>{localStorage.setItem(ow,JSON.stringify(m))},[m]);const y=x.useMemo(()=>{const v=new Map,E=16;return e.forEach(N=>{const k=FG(N.anchor);if(!k||!k.line_number)v.set(N.id,E);else{const C=t.get(N.id);C!==void 0&&v.set(N.id,Math.max(C,E))}}),v},[e,t]),w=zG({positions:y,cardHeight:130,minSpacing:0});return h.jsxs("div",{className:`flex h-full w-80 flex-col bg-background md:w-96 lg:w-[28rem] xl:w-[32rem] ${o}`,children:[l&&h.jsxs("div",{className:"p-2",children:[h.jsxs("div",{className:"mb-2 flex cursor-pointer items-center justify-between rounded-md border p-2",onClick:()=>g(!m),children:[h.jsxs("div",{className:"flex items-center gap-2",children:[m?h.jsx(Aa,{className:"h-4 w-4 text-muted-foreground"}):h.jsx(am,{className:"h-4 w-4 text-muted-foreground"}),h.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Relationships"}),a&&a.length>0&&h.jsx(st,{variant:"secondary",children:a.length})]}),u&&h.jsxs(oe,{variant:"outline",size:"xs",onClick:v=>{v.stopPropagation(),p(!0)},className:"h-6",children:[h.jsx(Si,{className:"mr-1 h-4 w-4"}),"Add"]})]}),!m&&a&&a.length>0&&h.jsx(uS,{relationships:a,currentEntityId:l,currentEntityType:"spec",onDelete:c,showEmpty:!1,showGroupHeaders:!1})]}),h.jsx(Bi,{open:f,onOpenChange:p,children:h.jsxs(qs,{children:[h.jsx(Ws,{children:h.jsx(Ks,{children:"Add Relationship"})}),l&&h.jsx(hS,{fromId:l,fromType:"spec",onSubmit:b,onCancel:()=>p(!1)})]})}),i&&h.jsx("div",{className:"p-2",children:i}),h.jsx("div",{className:"relative min-h-full flex-1",children:h.jsxs("div",{ref:d,className:"relative w-full pt-4",children:[e.map(v=>{const E=w.get(v.id);return E?h.jsx("div",{className:"absolute w-full px-1",style:{top:`${E.actualTop}px`,zIndex:10},children:h.jsx(jG,{feedback:v,onClick:()=>n?.(v),onDismiss:r?()=>r(v.id):void 0,onDelete:s?()=>s(v.id):void 0,maxHeight:200,isCompact:!1})},v.id):null}),e.length>0&&h.jsx("div",{style:{height:`${Math.max(...Array.from(w.values()).map(v=>v.actualTop+v.height))+100}px`,pointerEvents:"none"}})]})})]})}function $G({issues:e=[],selectedIssueId:t,onIssueSelect:n,issueId:r,lineNumber:s,textSnippet:i,onSubmit:o,onCancel:a,className:l=""}){const[c,u]=x.useState("comment"),[d,f]=x.useState(""),[p,m]=x.useState(!1),g=t||r,b=async y=>{if(y.preventDefault(),!!d.trim()){m(!0);try{let w;(s||i)&&(w={line_number:s,text_snippet:i,anchor_status:"valid",last_verified_at:new Date().toISOString()}),await o({type:c,content:d.trim(),anchor:w}),f(""),u("comment")}finally{m(!1)}}};return h.jsxs("form",{onSubmit:b,className:`space-y-4 ${l}`,children:[(s||i)&&h.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-sm",children:[s&&h.jsxs("div",{className:"font-medium",children:["Line ",s]}),i&&h.jsxs("div",{className:"text-muted-foreground",children:['"',i.slice(0,60),i.length>60?"...":"",'"']})]}),e.length>0&&n&&h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"issue-select",children:"Issue"}),h.jsxs(Sn,{value:g,onValueChange:n,children:[h.jsx(dn,{id:"issue-select",children:h.jsx(En,{placeholder:"Select an issue..."})}),h.jsx(fn,{children:e.map(y=>h.jsxs(xt,{value:y.id,children:[y.id,": ",y.title]},y.id))})]})]}),h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"feedback-type",children:"Type"}),h.jsxs(Sn,{value:c,onValueChange:y=>u(y),children:[h.jsx(dn,{id:"feedback-type",children:h.jsx(En,{})}),h.jsxs(fn,{children:[h.jsx(xt,{value:"comment",children:"Comment"}),h.jsx(xt,{value:"suggestion",children:"Suggestion"}),h.jsx(xt,{value:"request",children:"Request"})]})]})]}),h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"feedback-content",children:"Content"}),h.jsx(gd,{id:"feedback-content",placeholder:"Enter your feedback...",value:d,onChange:y=>f(y.target.value),rows:4,required:!0,className:"resize-none"})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(oe,{type:"submit",disabled:!d.trim()||!g||p,children:p?"Adding...":"Add Feedback"}),h.jsx(oe,{type:"button",variant:"outline",onClick:a,children:"Cancel"})]})]})}function UG({issues:e,lineNumber:t,textSnippet:n,onSubmit:r,triggerButton:s}){const[i,o]=x.useState(!1),[a,l]=x.useState(),c=async u=>{a&&(await r({issueId:a,...u}),o(!1),l(void 0))};return h.jsxs(Bi,{open:i,onOpenChange:o,children:[h.jsx(MM,{asChild:!0,children:s||h.jsxs(oe,{variant:"outline",size:"sm",children:[h.jsx(cm,{className:"mr-2 h-4 w-4"}),"Add Feedback"]})}),h.jsxs(qs,{className:"sm:max-w-[500px]",children:[h.jsxs(Ws,{children:[h.jsx(Ks,{children:"Add Feedback"}),h.jsxs(Gu,{children:["Add a comment, suggestion, or request to this spec.",t&&` Anchored to line ${t}.`]})]}),h.jsx($G,{issues:e,selectedIssueId:a,onIssueSelect:l,lineNumber:t,textSnippet:n,onSubmit:c,onCancel:()=>o(!1)})]})]})}function HG(e,t){let n=null;return(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function VG(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function qG(e,t){const[n,r]=x.useState(new Map),s=x.useRef(null),i=x.useRef(null);return x.useEffect(()=>{const o=()=>{const u=new Map,d=t.current;if(!d){r(u);return}e.forEach(f=>{const p=VG(f.anchor);if(!p)return;let m=d.querySelector(`[data-feedback-id="${f.id}"]`);if(!m&&p.line_number!==void 0&&(m=d.querySelector(`[data-line-number="${p.line_number}"]`),!m)){const g=Array.from(d.querySelectorAll("[data-line-number]"));if(g.length>0&&p.line_number>0){let b=null,y=0;for(const w of g){const v=parseInt(w.getAttribute("data-line-number")||"0");v>0&&v<=p.line_number&&v>y&&(y=v,b=w)}m=b||g[0]}}if(m){let g=0,b=m;for(;b&&b!==d;)g+=b.offsetTop,b=b.offsetParent;u.set(f.id,g)}}),r(u)},a=()=>{i.current!==null&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(o)},l=HG(o,100),c=t.current;return c?.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",l),s.current=setTimeout(o,50),()=>{c?.removeEventListener("scroll",a),window.removeEventListener("resize",l),s.current&&clearTimeout(s.current),i.current!==null&&cancelAnimationFrame(i.current)}},[e,t]),n}const WG=[{value:"0",label:"Critical (P0)"},{value:"1",label:"High (P1)"},{value:"2",label:"Medium (P2)"},{value:"3",label:"Low (P3)"},{value:"4",label:"None (P4)"}],aw="sudocode:specs:showFeedbackPanel",lw="sudocode:details:viewMode";function KG(){const{id:e}=em(),t=cr(),{spec:n,isLoading:r,isError:s}=VK(e||""),{feedback:i}=qK(e||""),{issues:o}=ed(),{updateSpec:a,isUpdating:l,archiveSpec:c,unarchiveSpec:u}=Wd(),{createFeedback:d,updateFeedback:f,deleteFeedback:p}=YK(e||""),[m,g]=x.useState(null),[b,y]=x.useState(null),[w,v]=x.useState(()=>{const ce=localStorage.getItem(aw);return ce!==null?JSON.parse(ce):!0}),[E,N]=x.useState(()=>{const ce=localStorage.getItem(lw);return ce!==null?JSON.parse(ce):"formatted"}),[k,C]=x.useState(""),[A,R]=x.useState(""),[T,I]=x.useState(2),[O,j]=x.useState(!1),[L,F]=x.useState([]),[q,te]=x.useState(!1),K=x.useRef(null),le=x.useRef(a),_=x.useRef({title:k,content:A,priority:T,hasChanges:O}),ae=x.useRef(e),me=x.useRef(null),S=qG(i,me);if(x.useEffect(()=>{le.current=a},[a]),x.useEffect(()=>{_.current={title:k,content:A,priority:T,hasChanges:O}},[k,A,T,O]),x.useEffect(()=>{ae.current=e},[e]),x.useEffect(()=>{K.current&&(clearTimeout(K.current),K.current=null),j(!1)},[e]),x.useEffect(()=>{n&&(C(n.title),R(n.content||""),I(n.priority??2),j(!1))},[n]),x.useEffect(()=>{(async()=>{if(e){te(!0);try{const ne=await co.getForEntity(e,"spec");let et=[];if(Array.isArray(ne))et=ne;else if(ne&&typeof ne=="object"&&"outgoing"in ne&&"incoming"in ne){const We=ne;et=[...We.outgoing||[],...We.incoming||[]]}F(et)}catch(ne){console.error("Failed to fetch relationships:",ne),F([])}finally{te(!1)}}})()},[e]),x.useEffect(()=>{if(!(!O||!e))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{le.current({id:e,data:{title:k,content:A,priority:T}}),j(!1)},1e3),()=>{K.current&&clearTimeout(K.current)}},[k,A,T,O]),x.useEffect(()=>()=>{const{hasChanges:ce,title:ne,content:et,priority:We}=_.current,ie=ae.current;ce&&ie&&le.current&&le.current({id:ie,data:{title:ne,content:et,priority:We}})},[]),x.useEffect(()=>{localStorage.setItem(aw,JSON.stringify(w))},[w]),x.useEffect(()=>{localStorage.setItem(lw,JSON.stringify(E))},[E]),r)return h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("div",{className:"mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"}),h.jsx("p",{className:"text-muted-foreground",children:"Loading spec..."})]})});if(s||!n)return h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("h2",{className:"mb-2 text-2xl font-bold",children:"Spec not found"}),h.jsx("p",{className:"mb-4 text-muted-foreground",children:"The spec you're looking for doesn't exist or has been deleted."}),h.jsx(oe,{onClick:()=>t("/specs"),children:"Back to Specs"})]})});const B=ce=>{g(ce),y(null),v(!0)},$=(ce,ne)=>{y(ce),g(ne),v(!0)},D=ce=>{try{const ne=ce.anchor?JSON.parse(ce.anchor):null;ne?.line_number&&g(ne.line_number)}catch(ne){console.error("Failed to parse feedback anchor:",ne)}},P=ce=>{C(ce),j(!0)},W=ce=>{R(ce),j(!0)},fe=ce=>{I(ce),j(!0)},ee=ce=>{const ne=i.find(et=>et.id===ce);ne&&f({id:ce,data:{dismissed:!ne.dismissed}})},be=ce=>{p(ce)},Me=async ce=>{if(!e){console.error("Cannot create feedback without spec ID");return}await d({spec_id:e,issue_id:ce.issueId,feedback_type:ce.type,content:ce.content,anchor:ce.anchor})},Le=async ce=>{try{await co.delete({from_id:ce.from_id,from_type:ce.from_type,to_id:ce.to_id,to_type:ce.to_type,relationship_type:ce.relationship_type}),F(L.filter(ne=>!(ne.from_id===ce.from_id&&ne.to_id===ce.to_id&&ne.relationship_type===ce.relationship_type)))}catch(ne){console.error("Failed to delete relationship:",ne)}},Ke=async(ce,ne,et)=>{if(e)try{const We=await co.create({from_id:e,from_type:"spec",to_id:ce,to_type:ne,relationship_type:et});F([...L,We])}catch(We){console.error("Failed to create relationship:",We)}};return h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsx("div",{className:"flex items-center gap-4",children:h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>t("/specs"),children:"← Back to Specs"})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:"flex items-center gap-2",children:h.jsxs("div",{className:"inline-flex rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:E==="formatted"?"outline":"ghost",size:"sm",onClick:()=>N("formatted"),className:`h-7 rounded-sm ${E==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:E==="source"?"outline":"ghost",size:"sm",onClick:()=>N("source"),className:`h-7 rounded-sm ${E==="source"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]})}),h.jsx(Ei,{children:h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>v(!w),children:[w?h.jsx(wA,{className:"h-4 w-4"}):h.jsx(Vu,{className:"h-4 w-4"}),i.length>0&&h.jsx("span",{className:"ml-2 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground",children:i.length})]})}),h.jsx(Un,{children:h.jsxs("p",{children:[w?"Hide":"Show"," feedback"]})})]})}),n.archived?h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>u(n.id),disabled:l,children:[h.jsx(im,{className:"mr-2 h-4 w-4"}),"Unarchive"]}):h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>c(n.id),disabled:l,children:[h.jsx(Oo,{className:"mr-2 h-4 w-4"}),"Archive"]})]})]}),h.jsx("div",{ref:me,className:"flex flex-1 overflow-auto xl:justify-center",children:h.jsxs("div",{className:"flex w-full xl:max-w-[1600px]",children:[h.jsx("div",{className:"flex-1 px-6 py-4 lg:px-12 xl:px-16",children:h.jsxs("div",{className:"mx-auto max-w-4xl space-y-3",children:[h.jsxs("div",{className:"space-y-2 pb-3",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:n.id}),h.jsx("div",{className:"text-xs italic text-muted-foreground",children:l?"Saving...":O?"Unsaved changes...":"All changes saved"})]}),h.jsx(is,{value:k,onChange:ce=>P(ce.target.value),disabled:l,placeholder:"Spec title...",className:"border-none bg-transparent px-0 text-2xl font-semibold shadow-none focus-visible:ring-0"})]}),h.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Jw,{className:"h-4 w-4 text-muted-foreground"}),h.jsxs(Sn,{value:String(T),onValueChange:ce=>fe(parseInt(ce)),disabled:l,children:[h.jsx(dn,{className:"h-8 w-auto gap-3 rounded-md border-none bg-accent px-3 shadow-none hover:bg-accent/80",children:h.jsx(En,{placeholder:"Priority"})}),h.jsx(fn,{children:WG.map(ce=>h.jsx(xt,{value:ce.value,children:ce.label},ce.value))})]})]}),h.jsx("div",{className:"ml-auto flex items-center gap-4 text-xs text-muted-foreground",children:n.updated_at&&h.jsxs("div",{className:"ml-auto flex items-center text-xs text-muted-foreground",children:["Updated ",Mc(new Date(n.updated_at.endsWith("Z")?n.updated_at:n.updated_at+"Z"),{addSuffix:!0})]})})]}),A!==void 0?h.jsx(eG,{content:A,feedback:i,selectedLine:m,onLineClick:B,onTextSelect:$,onFeedbackClick:D,onChange:W,viewMode:E,onViewModeChange:N}):h.jsx(It,{className:"p-8 text-center",children:h.jsx("p",{className:"text-muted-foreground",children:"No content available for this spec."})})]})}),w&&h.jsx(BG,{feedback:i,positions:S,relationships:L,currentEntityId:e,onFeedbackClick:D,onDismiss:ee,onDelete:be,onDeleteRelationship:Le,onCreateRelationship:Ke,addFeedbackButton:h.jsx("div",{className:"flex justify-center",children:h.jsx(UG,{issues:o,lineNumber:m||void 0,onSubmit:Me,triggerButton:h.jsxs(oe,{variant:"secondary",size:"sm",children:[h.jsx(cm,{className:"mr-2 h-4 w-4"}),"Add Feedback"]})})})})]})})]})}function GG(){const e=cr(),{issues:t,isLoading:n,isError:r,error:s,updateIssue:i,deleteIssue:o,unarchiveIssue:a,isUpdating:l,isDeleting:c}=ed(!0),[u,d]=x.useState(),[f,p]=x.useState(""),m=x.useMemo(()=>{const E=f?t.filter(k=>{const C=f.toLowerCase();return k.title.toLowerCase().includes(C)||k.content&&k.content.toLowerCase().includes(C)}):t,N={open:[],in_progress:[],blocked:[],needs_review:[],closed:[]};return E.forEach(k=>{const C=k.status.toLowerCase();N[C]?N[C].push(k):N.open.push(k)}),Object.keys(N).forEach(k=>{const C=k;C==="closed"?N[C].sort((A,R)=>{const T=A.closed_at?new Date(A.closed_at).getTime():0;return(R.closed_at?new Date(R.closed_at).getTime():0)-T}):N[C].sort((A,R)=>A.priority!==R.priority?A.priority-R.priority:new Date(A.created_at).getTime()-new Date(R.created_at).getTime())}),N},[t,f]),g=x.useCallback(E=>{d(E)},[]),b=x.useCallback(()=>{d(void 0)},[]),y=x.useCallback(E=>{u&&i({id:u.id,data:E})},[u,i]),w=x.useCallback(()=>{u&&(o(u.id),d(void 0))},[u,o]),v=x.useCallback(E=>{a(E)},[a]);return n?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsx("p",{className:"text-muted-foreground",children:"Loading archived issues..."})}):r?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsxs("p",{className:"text-destructive",children:["Error loading archived issues: ",s?.message||"Unknown error"]})}):h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>e("/issues"),className:"h-8 w-8 p-0",children:h.jsx(Hu,{className:"h-4 w-4"})}),h.jsxs("div",{children:[h.jsx("h1",{className:"text-2xl font-bold",children:"Archived Issues"}),h.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.length," archived issues"]})]})]}),h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter issues...",value:f,onChange:E=>p(E.target.value),className:"h-9 w-64 pl-8"})]})]}),h.jsx("div",{className:"flex flex-1 overflow-hidden",children:u?h.jsxs($g,{direction:"horizontal",className:"h-full min-h-0",onLayout:E=>{if(E.length===2)try{localStorage.setItem("archivedIssuesPage.panelSizes",JSON.stringify(E))}catch{}},children:[h.jsx(Ja,{id:"kanban",order:1,defaultSize:(()=>{try{const E=localStorage.getItem("archivedIssuesPage.panelSizes");if(E){const N=JSON.parse(E);if(Array.isArray(N)&&N.length===2)return N[0]}}catch{}return 66})(),minSize:30,className:"min-w-0 min-h-0 overflow-auto",children:h.jsx(Ac,{groupedIssues:m,onDragEnd:()=>{},onViewIssueDetails:g,selectedIssue:u})}),h.jsxs(Ug,{className:"relative z-30 w-1 bg-border cursor-col-resize group touch-none focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-1 focus-visible:ring-offset-background",children:[h.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border"}),h.jsxs("div",{className:"pointer-events-none absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center gap-1 bg-muted/90 border border-border rounded-full px-1.5 py-3 opacity-70 group-hover:opacity-100 group-focus:opacity-100 transition-opacity shadow-sm",children:[h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"})]})]}),h.jsx(Ja,{id:"details",order:2,defaultSize:(()=>{try{const E=localStorage.getItem("archivedIssuesPage.panelSizes");if(E){const N=JSON.parse(E);if(Array.isArray(N)&&N.length===2)return N[1]}}catch{}return 34})(),minSize:20,className:"min-w-0 min-h-0 overflow-hidden border-l bg-background shadow-lg",children:h.jsx(jg,{issue:u,onClose:b,onUpdate:y,onDelete:w,onUnarchive:v,isUpdating:l,isDeleting:c})})]}):h.jsx("div",{className:"flex-1 overflow-auto",children:h.jsx(Ac,{groupedIssues:m,onDragEnd:()=>{},onViewIssueDetails:g,selectedIssue:u})})})]})}function JG(){const{specs:e,isLoading:t}=Wd(!0),n=cr(),[r,s]=x.useState(""),i=r?e.filter(o=>{const a=r.toLowerCase();return o.title.toLowerCase().includes(a)||o.content&&o.content.toLowerCase().includes(a)}):e;return h.jsxs("div",{className:"flex-1 p-8",children:[h.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>n("/specs"),className:"h-8 w-8 p-0",children:h.jsx(Hu,{className:"h-4 w-4"})}),h.jsx("h1",{className:"text-3xl font-bold",children:"Archived Specs"})]}),h.jsx("p",{className:"text-muted-foreground ml-10",children:t?"Loading...":`${e.length} archived spec${e.length!==1?"s":""}`})]}),h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter specs...",value:r,onChange:o=>s(o.target.value),className:"h-9 w-64 pl-8"})]})]}),h.jsx(g_,{specs:i,loading:t})]})}var Qe;(function(e){e.assertEqual=s=>{};function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},e.getValidEnumValues=s=>{const i=e.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return e.objectValues(o)},e.objectValues=s=>e.objectKeys(s).map(function(i){return s[i]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},e.find=(s,i)=>{for(const o of s)if(i(o))return o},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}e.joinValues=r,e.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(Qe||(Qe={}));var cw;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(cw||(cw={}));const pe=Qe.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ks=e=>{switch(typeof e){case"undefined":return pe.undefined;case"string":return pe.string;case"number":return Number.isNaN(e)?pe.nan:pe.number;case"boolean":return pe.boolean;case"function":return pe.function;case"bigint":return pe.bigint;case"symbol":return pe.symbol;case"object":return Array.isArray(e)?pe.array:e===null?pe.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?pe.promise:typeof Map<"u"&&e instanceof Map?pe.map:typeof Set<"u"&&e instanceof Set?pe.set:typeof Date<"u"&&e instanceof Date?pe.date:pe.object;default:return pe.unknown}},Y=Qe.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ts extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}format(t){const n=t||function(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){const c=o.path[l];l===o.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(o))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return s(this),r}static assert(t){if(!(t instanceof ts))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Qe.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(t(s))}else r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}ts.create=e=>new ts(e);const Up=(e,t)=>{let n;switch(e.code){case Y.invalid_type:e.received===pe.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case Y.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Qe.jsonStringifyReplacer)}`;break;case Y.unrecognized_keys:n=`Unrecognized key(s) in object: ${Qe.joinValues(e.keys,", ")}`;break;case Y.invalid_union:n="Invalid input";break;case Y.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Qe.joinValues(e.options)}`;break;case Y.invalid_enum_value:n=`Invalid enum value. Expected ${Qe.joinValues(e.options)}, received '${e.received}'`;break;case Y.invalid_arguments:n="Invalid function arguments";break;case Y.invalid_return_type:n="Invalid function return type";break;case Y.invalid_date:n="Invalid date";break;case Y.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Qe.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case Y.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case Y.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case Y.custom:n="Invalid input";break;case Y.invalid_intersection_types:n="Intersection results could not be merged";break;case Y.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case Y.not_finite:n="Number must be finite";break;default:n=t.defaultError,Qe.assertNever(e)}return{message:n}};let ZG=Up;function YG(){return ZG}const XG=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const l=r.filter(c=>!!c).slice().reverse();for(const c of l)a=c(o,{data:t,defaultError:a}).message;return{...s,path:i,message:a}};function he(e,t){const n=YG(),r=XG({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===Up?void 0:Up].filter(s=>!!s)});e.common.issues.push(r)}class Kn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const s of n){if(s.status==="aborted")return Oe;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return Kn.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return Oe;i.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:t.value,value:r}}}const Oe=Object.freeze({status:"aborted"}),ua=e=>({status:"dirty",value:e}),ur=e=>({status:"valid",value:e}),uw=e=>e.status==="aborted",dw=e=>e.status==="dirty",Ao=e=>e.status==="valid",Mu=e=>typeof Promise<"u"&&e instanceof Promise;var ge;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t?.message})(ge||(ge={}));class Hs{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const fw=(e,t)=>{if(Ao(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new ts(e.common.issues);return this._error=n,this._error}}};function qe(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(o,a)=>{const{message:l}=e;return o.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:s}}class Xe{get description(){return this._def.description}_getType(t){return ks(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:ks(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Kn,ctx:{common:t.parent.common,data:t.data,parsedType:ks(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Mu(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){const r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)},s=this._parseSync({data:t,path:r.path,parent:r});return fw(r,s)}"~validate"(t){const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)};if(!this["~standard"].async)try{const r=this._parseSync({data:t,path:[],parent:n});return Ao(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(r=>Ao(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)},s=this._parse({data:t,path:r.path,parent:r}),i=await(Mu(s)?s:Promise.resolve(s));return fw(r,i)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=t(s),a=()=>i.addIssue({code:Y.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(l=>l?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new zi({schema:this,typeName:De.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Qr.create(this,this._def)}nullable(){return Fi.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Ir.create(this)}promise(){return Pu.create(this,this._def)}or(t){return Ou.create([this,t],this._def)}and(t){return Iu.create(this,t,this._def)}transform(t){return new zi({...qe(this._def),schema:this,typeName:De.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new ju({...qe(this._def),innerType:this,defaultValue:n,typeName:De.ZodDefault})}brand(){return new C_({typeName:De.ZodBranded,type:this,...qe(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new zu({...qe(this._def),innerType:this,catchValue:n,typeName:De.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Kg.create(this,t)}readonly(){return Fu.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const QG=/^c[^\s-]{8,}$/i,e8=/^[0-9a-z]+$/,t8=/^[0-9A-HJKMNP-TV-Z]{26}$/i,n8=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,r8=/^[a-z0-9_-]{21}$/i,s8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,i8=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,o8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,a8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let vh;const l8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,c8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,u8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,d8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,f8=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,k_="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",p8=new RegExp(`^${k_}$`);function S_(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${n}`}function m8(e){return new RegExp(`^${S_(e)}$`)}function g8(e){let t=`${k_}T${S_(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function b8(e,t){return!!((t==="v4"||!t)&&l8.test(e)||(t==="v6"||!t)&&u8.test(e))}function y8(e,t){if(!s8.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||t&&s.alg!==t)}catch{return!1}}function x8(e,t){return!!((t==="v4"||!t)&&c8.test(e)||(t==="v6"||!t)&&d8.test(e))}class Os extends Xe{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==pe.string){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.string,received:i.parsedType}),Oe}const r=new Kn;let s;for(const i of this._def.checks)if(i.kind==="min")t.data.length<i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")t.data.length>i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=t.data.length>i.value,a=t.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(t,s),o?he(s,{code:Y.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&he(s,{code:Y.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")o8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"email",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")vh||(vh=new RegExp(a8,"u")),vh.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"emoji",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")n8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"uuid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")r8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"nanoid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")QG.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cuid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")e8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cuid2",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")t8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"ulid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(t.data)}catch{s=this._getOrReturnCtx(t,s),he(s,{validation:"url",code:Y.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"regex",code:Y.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?t.data=t.data.trim():i.kind==="includes"?t.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?t.data=t.data.toLowerCase():i.kind==="toUpperCase"?t.data=t.data.toUpperCase():i.kind==="startsWith"?t.data.startsWith(i.value)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?t.data.endsWith(i.value)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?g8(i).test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?p8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?m8(i).test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?i8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"duration",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?b8(t.data,i.version)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"ip",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?y8(t.data,i.alg)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"jwt",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?x8(t.data,i.version)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cidr",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?f8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"base64",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?h8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"base64url",code:Y.invalid_string,message:i.message}),r.dirty()):Qe.assertNever(i);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(s=>t.test(s),{validation:n,code:Y.invalid_string,...ge.errToObj(r)})}_addCheck(t){return new Os({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...ge.errToObj(t)})}url(t){return this._addCheck({kind:"url",...ge.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...ge.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...ge.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...ge.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...ge.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...ge.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...ge.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...ge.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...ge.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...ge.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...ge.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...ge.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof t?.precision>"u"?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...ge.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof t?.precision>"u"?null:t?.precision,...ge.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...ge.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...ge.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n?.position,...ge.errToObj(n?.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...ge.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...ge.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...ge.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...ge.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...ge.errToObj(n)})}nonempty(t){return this.min(1,ge.errToObj(t))}trim(){return new Os({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Os({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Os({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Os.create=e=>new Os({checks:[],typeName:De.ZodString,coerce:e?.coerce??!1,...qe(e)});function v8(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(e.toFixed(s).replace(".","")),o=Number.parseInt(t.toFixed(s).replace(".",""));return i%o/10**s}class Mo extends Xe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==pe.number){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.number,received:i.parsedType}),Oe}let r;const s=new Kn;for(const i of this._def.checks)i.kind==="int"?Qe.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),he(r,{code:Y.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?v8(t.data,i.value)!==0&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_finite,message:i.message}),s.dirty()):Qe.assertNever(i);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,ge.toString(n))}gt(t,n){return this.setLimit("min",t,!1,ge.toString(n))}lte(t,n){return this.setLimit("max",t,!0,ge.toString(n))}lt(t,n){return this.setLimit("max",t,!1,ge.toString(n))}setLimit(t,n,r,s){return new Mo({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:ge.toString(s)}]})}_addCheck(t){return new Mo({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:ge.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:ge.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:ge.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:ge.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:ge.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:ge.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:ge.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:ge.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:ge.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&Qe.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(n)&&Number.isFinite(t)}}Mo.create=e=>new Mo({checks:[],typeName:De.ZodNumber,coerce:e?.coerce||!1,...qe(e)});class Qa extends Xe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==pe.bigint)return this._getInvalidInput(t);let r;const s=new Kn;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?t.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):Qe.assertNever(i);return{status:s.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return he(n,{code:Y.invalid_type,expected:pe.bigint,received:n.parsedType}),Oe}gte(t,n){return this.setLimit("min",t,!0,ge.toString(n))}gt(t,n){return this.setLimit("min",t,!1,ge.toString(n))}lte(t,n){return this.setLimit("max",t,!0,ge.toString(n))}lt(t,n){return this.setLimit("max",t,!1,ge.toString(n))}setLimit(t,n,r,s){return new Qa({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:ge.toString(s)}]})}_addCheck(t){return new Qa({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:ge.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:ge.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:ge.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:ge.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:ge.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Qa.create=e=>new Qa({checks:[],typeName:De.ZodBigInt,coerce:e?.coerce??!1,...qe(e)});class hw extends Xe{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==pe.boolean){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.boolean,received:r.parsedType}),Oe}return ur(t.data)}}hw.create=e=>new hw({typeName:De.ZodBoolean,coerce:e?.coerce||!1,...qe(e)});class Ru extends Xe{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==pe.date){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.date,received:i.parsedType}),Oe}if(Number.isNaN(t.data.getTime())){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_date}),Oe}const r=new Kn;let s;for(const i of this._def.checks)i.kind==="min"?t.data.getTime()<i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?t.data.getTime()>i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):Qe.assertNever(i);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Ru({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:ge.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:ge.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t!=null?new Date(t):null}}Ru.create=e=>new Ru({checks:[],coerce:e?.coerce||!1,typeName:De.ZodDate,...qe(e)});class pw extends Xe{_parse(t){if(this._getType(t)!==pe.symbol){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.symbol,received:r.parsedType}),Oe}return ur(t.data)}}pw.create=e=>new pw({typeName:De.ZodSymbol,...qe(e)});class Hp extends Xe{_parse(t){if(this._getType(t)!==pe.undefined){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.undefined,received:r.parsedType}),Oe}return ur(t.data)}}Hp.create=e=>new Hp({typeName:De.ZodUndefined,...qe(e)});class Vp extends Xe{_parse(t){if(this._getType(t)!==pe.null){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.null,received:r.parsedType}),Oe}return ur(t.data)}}Vp.create=e=>new Vp({typeName:De.ZodNull,...qe(e)});class qp extends Xe{constructor(){super(...arguments),this._any=!0}_parse(t){return ur(t.data)}}qp.create=e=>new qp({typeName:De.ZodAny,...qe(e)});class mw extends Xe{constructor(){super(...arguments),this._unknown=!0}_parse(t){return ur(t.data)}}mw.create=e=>new mw({typeName:De.ZodUnknown,...qe(e)});class Vs extends Xe{_parse(t){const n=this._getOrReturnCtx(t);return he(n,{code:Y.invalid_type,expected:pe.never,received:n.parsedType}),Oe}}Vs.create=e=>new Vs({typeName:De.ZodNever,...qe(e)});class gw extends Xe{_parse(t){if(this._getType(t)!==pe.undefined){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.void,received:r.parsedType}),Oe}return ur(t.data)}}gw.create=e=>new gw({typeName:De.ZodVoid,...qe(e)});class Ir extends Xe{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==pe.array)return he(n,{code:Y.invalid_type,expected:pe.array,received:n.parsedType}),Oe;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(o||a)&&(he(n,{code:o?Y.too_big:Y.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(he(n,{code:Y.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(he(n,{code:Y.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>s.type._parseAsync(new Hs(n,o,n.path,a)))).then(o=>Kn.mergeArray(r,o));const i=[...n.data].map((o,a)=>s.type._parseSync(new Hs(n,o,n.path,a)));return Kn.mergeArray(r,i)}get element(){return this._def.type}min(t,n){return new Ir({...this._def,minLength:{value:t,message:ge.toString(n)}})}max(t,n){return new Ir({...this._def,maxLength:{value:t,message:ge.toString(n)}})}length(t,n){return new Ir({...this._def,exactLength:{value:t,message:ge.toString(n)}})}nonempty(t){return this.min(1,t)}}Ir.create=(e,t)=>new Ir({type:e,minLength:null,maxLength:null,exactLength:null,typeName:De.ZodArray,...qe(t)});function no(e){if(e instanceof zt){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Qr.create(no(r))}return new zt({...e._def,shape:()=>t})}else return e instanceof Ir?new Ir({...e._def,type:no(e.element)}):e instanceof Qr?Qr.create(no(e.unwrap())):e instanceof Fi?Fi.create(no(e.unwrap())):e instanceof Pi?Pi.create(e.items.map(t=>no(t))):e}class zt extends Xe{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=Qe.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==pe.object){const c=this._getOrReturnCtx(t);return he(c,{code:Y.invalid_type,expected:pe.object,received:c.parsedType}),Oe}const{status:r,ctx:s}=this._processInputParams(t),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof Vs&&this._def.unknownKeys==="strip"))for(const c in s.data)o.includes(c)||a.push(c);const l=[];for(const c of o){const u=i[c],d=s.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new Hs(s,d,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof Vs){const c=this._def.unknownKeys;if(c==="passthrough")for(const u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:s.data[u]}});else if(c==="strict")a.length>0&&(he(s,{code:Y.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const u of a){const d=s.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new Hs(s,d,s.path,u)),alwaysSet:u in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const c=[];for(const u of l){const d=await u.key,f=await u.value;c.push({key:d,value:f,alwaysSet:u.alwaysSet})}return c}).then(c=>Kn.mergeObjectSync(r,c)):Kn.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(t){return ge.errToObj,new zt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{const s=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:ge.errToObj(t).message??s}:{message:s}}}:{}})}strip(){return new zt({...this._def,unknownKeys:"strip"})}passthrough(){return new zt({...this._def,unknownKeys:"passthrough"})}extend(t){return new zt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new zt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:De.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new zt({...this._def,catchall:t})}pick(t){const n={};for(const r of Qe.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new zt({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Qe.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new zt({...this._def,shape:()=>n})}deepPartial(){return no(this)}partial(t){const n={};for(const r of Qe.objectKeys(this.shape)){const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}return new zt({...this._def,shape:()=>n})}required(t){const n={};for(const r of Qe.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Qr;)i=i._def.innerType;n[r]=i}return new zt({...this._def,shape:()=>n})}keyof(){return E_(Qe.objectKeys(this.shape))}}zt.create=(e,t)=>new zt({shape:()=>e,unknownKeys:"strip",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});zt.strictCreate=(e,t)=>new zt({shape:()=>e,unknownKeys:"strict",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});zt.lazycreate=(e,t)=>new zt({shape:e,unknownKeys:"strip",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});class Ou extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new ts(a.ctx.common.issues));return he(n,{code:Y.invalid_union,unionErrors:o}),Oe}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const l of r){const c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!i&&(i={result:u,ctx:c}),c.common.issues.length&&o.push(c.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(l=>new ts(l));return he(n,{code:Y.invalid_union,unionErrors:a}),Oe}}get options(){return this._def.options}}Ou.create=(e,t)=>new Ou({options:e,typeName:De.ZodUnion,...qe(t)});const Kr=e=>e instanceof Kp?Kr(e.schema):e instanceof zi?Kr(e.innerType()):e instanceof Du?[e.value]:e instanceof ji?e.options:e instanceof Lu?Qe.objectValues(e.enum):e instanceof ju?Kr(e._def.innerType):e instanceof Hp?[void 0]:e instanceof Vp?[null]:e instanceof Qr?[void 0,...Kr(e.unwrap())]:e instanceof Fi?[null,...Kr(e.unwrap())]:e instanceof C_||e instanceof Fu?Kr(e.unwrap()):e instanceof zu?Kr(e._def.innerType):[];class Wg extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==pe.object)return he(n,{code:Y.invalid_type,expected:pe.object,received:n.parsedType}),Oe;const r=this.discriminator,s=n.data[r],i=this.optionsMap.get(s);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(he(n,{code:Y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Oe)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const i of n){const o=Kr(i.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of o){if(s.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);s.set(a,i)}}return new Wg({typeName:De.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...qe(r)})}}function Wp(e,t){const n=ks(e),r=ks(t);if(e===t)return{valid:!0,data:e};if(n===pe.object&&r===pe.object){const s=Qe.objectKeys(t),i=Qe.objectKeys(e).filter(a=>s.indexOf(a)!==-1),o={...e,...t};for(const a of i){const l=Wp(e[a],t[a]);if(!l.valid)return{valid:!1};o[a]=l.data}return{valid:!0,data:o}}else if(n===pe.array&&r===pe.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let i=0;i<e.length;i++){const o=e[i],a=t[i],l=Wp(o,a);if(!l.valid)return{valid:!1};s.push(l.data)}return{valid:!0,data:s}}else return n===pe.date&&r===pe.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Iu extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=(i,o)=>{if(uw(i)||uw(o))return Oe;const a=Wp(i.value,o.value);return a.valid?((dw(i)||dw(o))&&n.dirty(),{status:n.value,value:a.data}):(he(r,{code:Y.invalid_intersection_types}),Oe)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Iu.create=(e,t,n)=>new Iu({left:e,right:t,typeName:De.ZodIntersection,...qe(n)});class Pi extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.array)return he(r,{code:Y.invalid_type,expected:pe.array,received:r.parsedType}),Oe;if(r.data.length<this._def.items.length)return he(r,{code:Y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Oe;!this._def.rest&&r.data.length>this._def.items.length&&(he(r,{code:Y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,a)=>{const l=this._def.items[a]||this._def.rest;return l?l._parse(new Hs(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>Kn.mergeArray(n,o)):Kn.mergeArray(n,i)}get items(){return this._def.items}rest(t){return new Pi({...this._def,rest:t})}}Pi.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Pi({items:e,typeName:De.ZodTuple,rest:null,...qe(t)})};class bw extends Xe{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.map)return he(r,{code:Y.invalid_type,expected:pe.map,received:r.parsedType}),Oe;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([a,l],c)=>({key:s._parse(new Hs(r,a,r.path,[c,"key"])),value:i._parse(new Hs(r,l,r.path,[c,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const l of o){const c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return Oe;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const l of o){const c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return Oe;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}}bw.create=(e,t,n)=>new bw({valueType:t,keyType:e,typeName:De.ZodMap,...qe(n)});class el extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.set)return he(r,{code:Y.invalid_type,expected:pe.set,received:r.parsedType}),Oe;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(he(r,{code:Y.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(he(r,{code:Y.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(l){const c=new Set;for(const u of l){if(u.status==="aborted")return Oe;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}const a=[...r.data.values()].map((l,c)=>i._parse(new Hs(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>o(l)):o(a)}min(t,n){return new el({...this._def,minSize:{value:t,message:ge.toString(n)}})}max(t,n){return new el({...this._def,maxSize:{value:t,message:ge.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}el.create=(e,t)=>new el({valueType:e,minSize:null,maxSize:null,typeName:De.ZodSet,...qe(t)});class Kp extends Xe{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Kp.create=(e,t)=>new Kp({getter:e,typeName:De.ZodLazy,...qe(t)});class Du extends Xe{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return he(n,{received:n.data,code:Y.invalid_literal,expected:this._def.value}),Oe}return{status:"valid",value:t.data}}get value(){return this._def.value}}Du.create=(e,t)=>new Du({value:e,typeName:De.ZodLiteral,...qe(t)});function E_(e,t){return new ji({values:e,typeName:De.ZodEnum,...qe(t)})}class ji extends Xe{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return he(n,{expected:Qe.joinValues(r),received:n.parsedType,code:Y.invalid_type}),Oe}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const n=this._getOrReturnCtx(t),r=this._def.values;return he(n,{received:n.data,code:Y.invalid_enum_value,options:r}),Oe}return ur(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return ji.create(t,{...this._def,...n})}exclude(t,n=this._def){return ji.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}ji.create=E_;class Lu extends Xe{_parse(t){const n=Qe.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==pe.string&&r.parsedType!==pe.number){const s=Qe.objectValues(n);return he(r,{expected:Qe.joinValues(s),received:r.parsedType,code:Y.invalid_type}),Oe}if(this._cache||(this._cache=new Set(Qe.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const s=Qe.objectValues(n);return he(r,{received:r.data,code:Y.invalid_enum_value,options:s}),Oe}return ur(t.data)}get enum(){return this._def.values}}Lu.create=(e,t)=>new Lu({values:e,typeName:De.ZodNativeEnum,...qe(t)});class Pu extends Xe{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==pe.promise&&n.common.async===!1)return he(n,{code:Y.invalid_type,expected:pe.promise,received:n.parsedType}),Oe;const r=n.parsedType===pe.promise?n.data:Promise.resolve(n.data);return ur(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Pu.create=(e,t)=>new Pu({type:e,typeName:De.ZodPromise,...qe(t)});class zi extends Xe{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===De.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null,i={addIssue:o=>{he(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return Oe;const l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?Oe:l.status==="dirty"||n.value==="dirty"?ua(l.value):l});{if(n.value==="aborted")return Oe;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?Oe:a.status==="dirty"||n.value==="dirty"?ua(a.value):a}}if(s.type==="refinement"){const o=a=>{const l=s.refinement(a,i);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Oe:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Oe:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Ao(o))return Oe;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>Ao(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:n.value,value:a})):Oe);Qe.assertNever(s)}}zi.create=(e,t,n)=>new zi({schema:e,typeName:De.ZodEffects,effect:t,...qe(n)});zi.createWithPreprocess=(e,t,n)=>new zi({schema:t,effect:{type:"preprocess",transform:e},typeName:De.ZodEffects,...qe(n)});class Qr extends Xe{_parse(t){return this._getType(t)===pe.undefined?ur(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Qr.create=(e,t)=>new Qr({innerType:e,typeName:De.ZodOptional,...qe(t)});class Fi extends Xe{_parse(t){return this._getType(t)===pe.null?ur(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Fi.create=(e,t)=>new Fi({innerType:e,typeName:De.ZodNullable,...qe(t)});class ju extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===pe.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}ju.create=(e,t)=>new ju({innerType:e,typeName:De.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...qe(t)});class zu extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Mu(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new ts(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ts(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}zu.create=(e,t)=>new zu({innerType:e,typeName:De.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...qe(t)});class yw extends Xe{_parse(t){if(this._getType(t)!==pe.nan){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.nan,received:r.parsedType}),Oe}return{status:"valid",value:t.data}}}yw.create=e=>new yw({typeName:De.ZodNaN,...qe(e)});class C_ extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Kg extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?Oe:i.status==="dirty"?(n.dirty(),ua(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Oe:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new Kg({in:t,out:n,typeName:De.ZodPipeline})}}class Fu extends Xe{_parse(t){const n=this._def.innerType._parse(t),r=s=>(Ao(s)&&(s.value=Object.freeze(s.value)),s);return Mu(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Fu.create=(e,t)=>new Fu({innerType:e,typeName:De.ZodReadonly,...qe(t)});var De;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(De||(De={}));const Ae=Os.create,w8=Mo.create,ns=qp.create;Vs.create;const yo=Ir.create,ei=zt.create,N_=Ou.create,__=Wg.create;Iu.create;Pi.create;const He=Du.create;ji.create;const k8=Lu.create;Pu.create;Qr.create;Fi.create;var S8=ei({name:Ae(),arguments:Ae()}),E8=ei({id:Ae(),type:He("function"),function:S8}),Kd=ei({id:Ae(),role:Ae(),content:Ae().optional(),name:Ae().optional()}),C8=Kd.extend({role:He("developer"),content:Ae()}),N8=Kd.extend({role:He("system"),content:Ae()}),_8=Kd.extend({role:He("assistant"),content:Ae().optional(),toolCalls:yo(E8).optional()}),T8=Kd.extend({role:He("user"),content:Ae()}),A8=ei({id:Ae(),content:Ae(),role:He("tool"),toolCallId:Ae(),error:Ae().optional()}),T_=__("role",[C8,N8,_8,T8,A8]);N_([He("developer"),He("system"),He("assistant"),He("user"),He("tool")]);var M8=ei({description:Ae(),value:Ae()}),R8=ei({name:Ae(),description:Ae(),parameters:ns()});ei({threadId:Ae(),runId:Ae(),state:ns(),messages:yo(T_),tools:yo(R8),context:yo(M8),forwardedProps:ns()});var O8=ns(),A_=N_([He("developer"),He("system"),He("assistant"),He("user")]),ln=(e=>(e.TEXT_MESSAGE_START="TEXT_MESSAGE_START",e.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",e.TEXT_MESSAGE_END="TEXT_MESSAGE_END",e.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",e.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",e.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",e.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.THINKING_START="THINKING_START",e.THINKING_END="THINKING_END",e.STATE_SNAPSHOT="STATE_SNAPSHOT",e.STATE_DELTA="STATE_DELTA",e.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",e.RAW="RAW",e.CUSTOM="CUSTOM",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.STEP_STARTED="STEP_STARTED",e.STEP_FINISHED="STEP_FINISHED",e))(ln||{}),Tt=ei({type:k8(ln),timestamp:w8().optional(),rawEvent:ns().optional()}),I8=Tt.extend({type:He("TEXT_MESSAGE_START"),messageId:Ae(),role:A_.default("assistant")}),M_=Tt.extend({type:He("TEXT_MESSAGE_CONTENT"),messageId:Ae(),delta:Ae().refine(e=>e.length>0,"Delta must not be an empty string")}),D8=Tt.extend({type:He("TEXT_MESSAGE_END"),messageId:Ae()}),L8=Tt.extend({type:He("TEXT_MESSAGE_CHUNK"),messageId:Ae().optional(),role:A_.optional(),delta:Ae().optional()}),P8=Tt.extend({type:He("THINKING_TEXT_MESSAGE_START")}),j8=M_.omit({messageId:!0,type:!0}).extend({type:He("THINKING_TEXT_MESSAGE_CONTENT")}),z8=Tt.extend({type:He("THINKING_TEXT_MESSAGE_END")}),F8=Tt.extend({type:He("TOOL_CALL_START"),toolCallId:Ae(),toolCallName:Ae(),parentMessageId:Ae().optional()}),B8=Tt.extend({type:He("TOOL_CALL_ARGS"),toolCallId:Ae(),delta:Ae()}),$8=Tt.extend({type:He("TOOL_CALL_END"),toolCallId:Ae()}),U8=Tt.extend({messageId:Ae(),type:He("TOOL_CALL_RESULT"),toolCallId:Ae(),content:Ae(),role:He("tool").optional()}),H8=Tt.extend({type:He("TOOL_CALL_CHUNK"),toolCallId:Ae().optional(),toolCallName:Ae().optional(),parentMessageId:Ae().optional(),delta:Ae().optional()}),V8=Tt.extend({type:He("THINKING_START"),title:Ae().optional()}),q8=Tt.extend({type:He("THINKING_END")}),W8=Tt.extend({type:He("STATE_SNAPSHOT"),snapshot:O8}),K8=Tt.extend({type:He("STATE_DELTA"),delta:yo(ns())}),G8=Tt.extend({type:He("MESSAGES_SNAPSHOT"),messages:yo(T_)}),J8=Tt.extend({type:He("RAW"),event:ns(),source:Ae().optional()}),Z8=Tt.extend({type:He("CUSTOM"),name:Ae(),value:ns()}),Y8=Tt.extend({type:He("RUN_STARTED"),threadId:Ae(),runId:Ae()}),X8=Tt.extend({type:He("RUN_FINISHED"),threadId:Ae(),runId:Ae(),result:ns().optional()}),Q8=Tt.extend({type:He("RUN_ERROR"),message:Ae(),code:Ae().optional()}),e7=Tt.extend({type:He("STEP_STARTED"),stepName:Ae()}),t7=Tt.extend({type:He("STEP_FINISHED"),stepName:Ae()});__("type",[I8,M_,D8,L8,V8,q8,P8,j8,z8,F8,B8,$8,H8,U8,W8,K8,G8,J8,Z8,Y8,X8,Q8,e7,t7]);function n7(e){const{executionId:t,autoConnect:n=!0,reconnectOnError:r=!1,endpoint:s,onEvent:i}=e,[o,a]=x.useState("idle"),[l,c]=x.useState({runId:null,threadId:null,status:"idle",currentStep:null,error:null,startTime:null,endTime:null}),[u,d]=x.useState(new Map),[f,p]=x.useState(new Map),[m,g]=x.useState({}),[b,y]=x.useState(null),w=x.useRef(null),v=x.useRef(null),E=x.useRef(i),N=x.useRef(!1);x.useEffect(()=>{E.current=i},[i]);const k=x.useCallback(S=>{c(B=>({...B,runId:S.runId,threadId:S.threadId,status:"running",startTime:S.timestamp||Date.now()})),E.current?.onRunStarted?.(S)},[]),C=x.useCallback(S=>{c(B=>({...B,status:"completed",endTime:S.timestamp||Date.now()})),E.current?.onRunFinished?.(S),N.current=!0,w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),A=x.useCallback(S=>{c(B=>({...B,status:"error",error:S.message,endTime:S.timestamp||Date.now()})),y(new Error(S.message)),E.current?.onRunError?.(S),N.current=!0,w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),R=x.useCallback(S=>{c(B=>({...B,currentStep:S.stepName})),E.current?.onStepStarted?.(S)},[]),T=x.useCallback(S=>{E.current?.onStepFinished?.(S)},[]),I=x.useCallback(S=>{d(B=>{const $=new Map(B);return $.set(S.messageId,{messageId:S.messageId,role:S.role||"assistant",content:"",complete:!1,timestamp:S.timestamp||Date.now()}),$})},[]),O=x.useCallback(S=>{d(B=>{const $=new Map(B),D=$.get(S.messageId);if(D){const P={...D,content:D.content+S.delta};$.set(S.messageId,P),E.current?.onMessage?.(P)}return $})},[]),j=x.useCallback(S=>{d(B=>{const $=new Map(B),D=$.get(S.messageId);if(D){const P={...D,complete:!0};$.set(S.messageId,P),E.current?.onMessage?.(P)}return $})},[]),L=x.useCallback(S=>{p(B=>{const $=new Map(B);return $.set(S.toolCallId,{toolCallId:S.toolCallId,toolCallName:S.toolCallName,args:"",status:"started",startTime:S.timestamp||Date.now()}),$}),E.current?.onToolCallStart?.(S)},[]),F=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,args:D.args+S.delta,status:"executing"}),$})},[]),q=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,endTime:S.timestamp||Date.now()}),$}),E.current?.onToolCallEnd?.(S)},[]),te=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,result:S.content,status:"completed"}),$})},[]),K=x.useCallback(S=>{g(S.snapshot),E.current?.onStateUpdate?.(S.snapshot)},[]),le=x.useCallback(S=>{g(B=>{let $={...B};for(const D of S.delta)if(D.op==="replace"){const P=D.path.slice(1);$={...$,[P]:D.value}}else if(D.op==="add"){const P=D.path.slice(1);$={...$,[P]:D.value}}return E.current?.onStateUpdate?.($),$})},[]),_=x.useCallback(()=>{if(N.current){console.debug("[SSE] Skipping connection - execution already completed");return}if(w.current){console.warn("EventSource already connected");return}const S=s||`/api/executions/${t}/stream`;console.debug("[SSE]. Connecting to SSE stream",{executionId:t,url:S,timestamp:new Date().toISOString()}),a("connecting"),y(null);try{const B=new EventSource(S);w.current=B,B.onopen=()=>{console.debug("[SSE]. SSE connection established",{executionId:t,timestamp:new Date().toISOString()}),a("connected")},B.onerror=$=>{if(console.error("EventSource error:",$),N.current){ae();return}a("error"),y(new Error("SSE connection error")),r&&v.current===null&&(console.debug("[SSE] Reconnecting in 3 seconds..."),v.current=setTimeout(()=>{v.current=null,ae(),_()},3e3))},B.addEventListener(ln.RUN_STARTED,$=>{k(JSON.parse($.data))}),B.addEventListener(ln.RUN_FINISHED,$=>{C(JSON.parse($.data))}),B.addEventListener(ln.RUN_ERROR,$=>{A(JSON.parse($.data))}),B.addEventListener(ln.STEP_STARTED,$=>{R(JSON.parse($.data))}),B.addEventListener(ln.STEP_FINISHED,$=>{T(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_START,$=>{I(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_CONTENT,$=>{O(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_END,$=>{j(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_START,$=>{L(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_ARGS,$=>{F(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_END,$=>{q(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_RESULT,$=>{te(JSON.parse($.data))}),B.addEventListener(ln.STATE_SNAPSHOT,$=>{K(JSON.parse($.data))}),B.addEventListener(ln.STATE_DELTA,$=>{le(JSON.parse($.data))})}catch(B){console.error("Failed to create EventSource:",B),a("error"),y(B instanceof Error?B:new Error("Unknown error"))}},[t,s,r,k,C,A,R,T,I,O,j,L,F,q,te,K,le]),ae=x.useCallback(()=>{v.current&&(clearTimeout(v.current),v.current=null),w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),me=x.useCallback(()=>{N.current=!1,ae(),_()},[ae,_]);return x.useEffect(()=>(n&&_(),()=>{v.current&&(clearTimeout(v.current),v.current=null),w.current&&(w.current.close(),w.current=null,a("disconnected"))}),[n,t]),{connectionStatus:o,execution:l,messages:u,toolCalls:f,state:m,error:b,connect:_,disconnect:ae,reconnect:me,isConnected:o==="connected"}}function r7(e,t){const n=[],r=Date.now();switch(e.type){case"assistant":{const s=e.message?.content||[];for(const i of s)if(i.type==="text"&&i.text)n.push({type:"CUSTOM",timestamp:r,name:"TEXT_MESSAGE_CONTENT",value:{content:i.text}});else if(i.type==="tool_use"){const o=i.id||`tool-${Date.now()}`;n.push({type:"TOOL_CALL_START",timestamp:r,toolCallId:o,toolCallName:i.name||"unknown"},{type:"TOOL_CALL_ARGS",timestamp:r,toolCallId:o,delta:JSON.stringify(i.input||{})})}break}case"tool_result":{const s=e.result?.tool_use_id||"unknown",o=(e.result?.content||[]).find(a=>a.type==="text")?.text||"";n.push({type:"TOOL_CALL_END",timestamp:r,toolCallId:s},{type:"TOOL_CALL_RESULT",timestamp:r,messageId:`msg-${s}`,toolCallId:s,content:o});break}case"result":{if(e.usage){const s=e.usage;n.push({type:"CUSTOM",timestamp:r,name:"USAGE_UPDATE",value:{inputTokens:s.input_tokens||0,outputTokens:s.output_tokens||0,cacheTokens:s.cache_read_input_tokens||0,totalTokens:(s.input_tokens||0)+(s.output_tokens||0)}})}break}case"error":{n.push({type:"RUN_ERROR",timestamp:r,message:e.error?.message||"Unknown error",errorType:e.error?.type});break}}return n}async function s7(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const s=e[r].trim();if(s)try{const i=JSON.parse(s),o=r7(i,n);t.push(...o),n+=o.length}catch(i){console.warn(`[parseExecutionLogs] Failed to parse log line ${r+1}:`,i instanceof Error?i.message:String(i))}}return t}function i7(e){const[t,n]=x.useState([]),[r,s]=x.useState(!0),[i,o]=x.useState(null),[a,l]=x.useState(null);return x.useEffect(()=>{s(!0),o(null),n([]),l(null);const c=new AbortController;async function u(){try{const d=await fetch(`/api/executions/${e}/logs`,{signal:c.signal});if(!d.ok)throw d.status===404?new Error(`Execution not found: ${e}`):new Error(`Failed to fetch execution logs: ${d.status} ${d.statusText}`);const f=await d.json();if(!f.success)throw new Error(f.message||"Failed to fetch execution logs");const p=await s7(f.data.logs);n(p),l(f.data.metadata)}catch(d){if(d instanceof Error&&d.name==="AbortError")return;const f=d instanceof Error?d:new Error("Unknown error fetching execution logs");o(f),console.error("[useExecutionLogs] Error:",f)}finally{c.signal.aborted||s(!1)}}return u(),()=>{c.abort()}},[e]),{events:t,loading:r,error:i,metadata:a}}function o7({messages:e,toolCalls:t,renderMarkdown:n=!0,className:r=""}){const s=x.useMemo(()=>{const i=[];return e.forEach(o=>{i.push({type:"message",timestamp:o.timestamp,data:o})}),t.forEach(o=>{i.push({type:"tool_call",timestamp:o.startTime,data:o})}),i.sort((o,a)=>o.timestamp-a.timestamp)},[e,t]);return s.length===0?null:h.jsx("div",{className:`space-y-3 ${r}`,children:s.map(i=>{if(i.type==="message"){const o=i.data;return h.jsxs("div",{className:"flex gap-3 items-start",children:[h.jsx("div",{className:"mt-1 flex-shrink-0",children:h.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-primary/10",children:h.jsx(Vu,{className:"h-4 w-4 text-primary"})})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[h.jsx(st,{variant:"outline",className:"text-xs",children:o.role}),!o.complete&&h.jsx(Ds,{className:"h-3 w-3 animate-spin text-muted-foreground"})]}),h.jsx("div",{className:"rounded-lg bg-muted/50 p-3 text-sm",children:n?h.jsx(w_,{className:"prose prose-sm max-w-none dark:prose-invert",components:{p:({children:a})=>h.jsx("p",{className:"mb-2 last:mb-0",children:a}),code:({inline:a,children:l,...c})=>a?h.jsx("code",{className:"bg-background px-1 py-0.5 rounded text-xs",...c,children:l}):h.jsx("pre",{className:"bg-background p-2 rounded overflow-x-auto",children:h.jsx("code",{...c,children:l})}),ul:({children:a})=>h.jsx("ul",{className:"list-disc pl-4 mb-2",children:a}),ol:({children:a})=>h.jsx("ol",{className:"list-decimal pl-4 mb-2",children:a}),li:({children:a})=>h.jsx("li",{className:"mb-1",children:a}),a:({children:a,href:l})=>h.jsx("a",{href:l,className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",children:a})},children:o.content}):h.jsx("div",{className:"whitespace-pre-wrap",children:o.content})})]})]},`msg-${o.messageId}`)}else{const o=i.data;return h.jsxs("div",{className:"flex gap-3 items-start",children:[h.jsx("div",{className:"mt-1 flex-shrink-0",children:h.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-blue-500/10",children:h.jsx(AA,{className:"h-4 w-4 text-blue-500"})})}),h.jsx("div",{className:"flex-1 min-w-0",children:h.jsxs("div",{className:"rounded-lg border bg-card p-3 text-sm",children:[h.jsxs("div",{className:"flex items-center justify-between mb-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"font-medium",children:o.toolCallName}),h.jsx(st,{variant:o.status==="completed"?"default":o.status==="error"?"destructive":"secondary",className:"text-xs",children:o.status})]}),o.endTime&&h.jsxs("span",{className:"text-xs text-muted-foreground",children:[((o.endTime-o.startTime)/1e3).toFixed(2),"s"]})]}),o.args&&h.jsxs("details",{className:"mt-2",children:[h.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground",children:"Arguments"}),h.jsx("pre",{className:"mt-1 text-xs bg-muted/50 p-2 rounded overflow-x-auto",children:o.args})]}),o.result&&h.jsxs("details",{className:"mt-2",open:o.status==="completed",children:[h.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground",children:"Result"}),h.jsx("pre",{className:"mt-1 text-xs bg-muted/50 p-2 rounded overflow-x-auto max-h-40",children:o.result})]}),o.error&&h.jsx("div",{className:"mt-2 text-xs text-destructive bg-destructive/10 p-2 rounded",children:o.error})]})})]},`tool-${o.toolCallId}`)}})})}function a7({executionId:e,execution:t,onComplete:n,onError:r,className:s=""}){const i=x.useMemo(()=>t?["preparing","pending","running","paused"].includes(t.status):!0,[t]),o=n7({executionId:e,autoConnect:i}),a=i7(e),{connectionStatus:l,execution:c,messages:u,toolCalls:d,state:f,error:p,isConnected:m}=x.useMemo(()=>{if(i)return{connectionStatus:o.connectionStatus,execution:o.execution,messages:o.messages,toolCalls:o.toolCalls,state:o.state,error:o.error,isConnected:o.isConnected};{const v=new Map,E=new Map,N={};return a.events&&a.events.forEach(k=>{if(k.type==="TEXT_MESSAGE_CONTENT"||k.name==="TEXT_MESSAGE_CONTENT"){const C=k.value||k;v.set(v.size,{id:v.size,content:C.content||C.text,timestamp:k.timestamp||Date.now()})}else if(k.type==="TOOL_CALL_START"||k.name==="TOOL_CALL_START"){const C=k.value||k;E.set(C.toolCallId,{id:C.toolCallId,name:C.name,status:"running",timestamp:k.timestamp||Date.now()})}else if(k.type==="TOOL_CALL_RESULT"||k.name==="TOOL_CALL_RESULT"){const C=k.value||k,A=E.get(C.toolCallId);A&&E.set(C.toolCallId,{...A,status:"completed",result:C.result})}}),{connectionStatus:a.loading?"connecting":a.error?"error":"connected",execution:{status:t?.status||"completed",runId:e,currentStep:void 0,error:a.error?.message,startTime:void 0,endTime:void 0},messages:v,toolCalls:E,state:N,error:a.error,isConnected:!1}}},[i,o,a,e,t]);x.useEffect(()=>{c.status==="completed"&&n&&n()},[c.status,n]),x.useEffect(()=>{p&&r&&r(p)},[p,r]);const g=d.size,b=Array.from(d.values()).filter(v=>v.status==="completed").length,y=u.size,w=()=>l==="connecting"?h.jsxs(st,{variant:"outline",className:"flex items-center gap-1",children:[h.jsx(Ds,{className:"h-3 w-3 animate-spin"}),"Connecting..."]}):l==="error"||c.status==="error"?h.jsxs(st,{variant:"destructive",className:"flex items-center gap-1",children:[h.jsx(ao,{className:"h-3 w-3"}),"Error"]}):c.status==="completed"?h.jsxs(st,{variant:"default",className:"flex items-center gap-1 bg-green-600",children:[h.jsx(om,{className:"h-3 w-3"}),"Completed"]}):c.status==="running"?h.jsxs(st,{variant:"default",className:"flex items-center gap-1",children:[h.jsx(Ds,{className:"h-3 w-3 animate-spin"}),"Running"]}):h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(ki,{className:"h-3 w-3"}),"Idle"]});return l==="connecting"&&c.status==="idle"?h.jsx(It,{className:`p-6 ${s}`,children:h.jsxs("div",{className:"flex items-center justify-center gap-2 text-muted-foreground",children:[h.jsx(Ds,{className:"h-4 w-4 animate-spin"}),h.jsx("span",{children:"Connecting to execution stream..."})]})}):h.jsxs(It,{className:`flex flex-col ${s}`,children:[h.jsxs("div",{className:"border-b px-6 py-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("h3",{className:"font-semibold",children:"Execution Monitor"}),w()]}),h.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.runId&&h.jsxs("span",{className:"font-mono text-xs",children:["Run: ",c.runId.slice(0,8)]}),m&&h.jsx(st,{variant:"outline",className:"text-xs",children:"Live"})]})]}),c.currentStep&&h.jsxs("div",{className:"mt-3 text-sm text-muted-foreground",children:[h.jsx("span",{className:"font-medium",children:"Current step:"})," ",c.currentStep]}),f.progress!==void 0&&f.totalSteps&&h.jsxs("div",{className:"mt-3",children:[h.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground mb-1",children:[h.jsx("span",{children:"Progress"}),h.jsxs("span",{children:[f.progress," / ",f.totalSteps]})]}),h.jsx("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:h.jsx("div",{className:"h-full bg-primary transition-all duration-300",style:{width:`${f.progress/f.totalSteps*100}%`}})})]})]}),h.jsxs("div",{className:"flex-1 overflow-auto px-6 py-4",children:[(p||c.error)&&h.jsx("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 p-4 mb-4",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(ao,{className:"h-5 w-5 text-destructive mt-0.5"}),h.jsxs("div",{className:"flex-1",children:[h.jsx("h4",{className:"font-semibold text-destructive",children:"Error"}),h.jsx("p",{className:"text-sm text-destructive/90 mt-1",children:c.error||p?.message})]})]})}),(y>0||g>0)&&h.jsx(o7,{messages:u,toolCalls:d,renderMarkdown:!0}),y===0&&g===0&&!p&&!c.error&&h.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center text-muted-foreground",children:[h.jsx(ki,{className:"h-8 w-8 mb-2"}),h.jsx("p",{className:"text-sm",children:"No execution activity yet"}),h.jsx("p",{className:"text-xs mt-1",children:m?"Waiting for events...":"Connecting..."})]})]}),h.jsx("div",{className:"border-t px-6 py-3 bg-muted/30",children:h.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:g})," tool calls"]}),h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:b})," completed"]}),h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:y})," messages"]})]}),f.tokenUsage&&h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:f.tokenUsage})," tokens"]}),f.cost&&h.jsx("span",{children:h.jsxs("span",{className:"font-medium",children:["$",f.cost.toFixed(4)]})})]}),c.startTime&&c.endTime&&h.jsxs("span",{children:["Duration:"," ",h.jsxs("span",{className:"font-medium",children:[((c.endTime-c.startTime)/1e3).toFixed(2),"s"]})]})]})})]})}function l7({open:e,onSubmit:t,onCancel:n}){const[r,s]=x.useState(""),[i,o]=x.useState(!1),[a,l]=x.useState(null),c=async()=>{if(r.trim().length===0){l("Feedback cannot be empty");return}o(!0),l(null);try{await t(r.trim()),s(""),l(null)}catch(p){l(p instanceof Error?p.message:"Failed to submit feedback")}finally{o(!1)}},u=()=>{i||(s(""),l(null),n())},d=p=>{!p&&!i&&u()},f=r.trim().length>0&&!i;return h.jsx(Bi,{open:e,onOpenChange:d,children:h.jsxs(qs,{className:"max-w-2xl",children:[h.jsxs(Ws,{children:[h.jsx(Ks,{children:"Continue Execution"}),h.jsx(Gu,{children:"Provide additional feedback to continue the agent's work in the same environment."})]}),h.jsxs("div",{className:"space-y-4",children:[a&&h.jsx("div",{className:"rounded-lg border border-destructive bg-destructive/10 p-3",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(ki,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),h.jsx("p",{className:"text-sm text-destructive",children:a})]})}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(Ht,{htmlFor:"feedback",children:"Feedback"}),h.jsx(gd,{id:"feedback",value:r,onChange:p=>s(p.target.value),rows:8,placeholder:`Provide feedback or additional instructions for the agent.
561
+ `),[e]),p=x.useMemo(()=>{const y=new Map;return r.forEach(w=>{try{const v=w.anchor?JSON.parse(w.anchor):null;if(v?.line_number){const E=y.get(v.line_number)||[];y.set(v.line_number,[...E,w])}else if(v?.text_snippet){const E=v.text_snippet.replace(/\.\.\./g,"").trim();if(E){const N=e.split(`
562
+ `);for(let k=0;k<N.length;k++)if(N[k].includes(E)){const C=k+1,A=y.get(C)||[];y.set(C,[...A,w]);break}}}}catch(v){console.error("Failed to parse feedback anchor:",v)}}),y},[r,e]),m=y=>{i?.(y)},g=y=>{if(!o)return;const v=window.getSelection()?.toString().trim();v&&v.length>0&&o(v,y)},b=y=>{c?.(y.target.value)};return x.useEffect(()=>{if(l&&d.current){const y=d.current;y.style.height="auto",y.style.height=`${y.scrollHeight}px`}},[e,l]),h.jsx(It,{className:`overflow-hidden ${u}`,children:h.jsx("div",{className:"relative",children:l?h.jsx("div",{className:"px-4 py-4",children:h.jsx("textarea",{ref:d,value:e,onChange:b,className:"w-full resize-none border-none bg-transparent font-mono text-sm leading-6 outline-none focus:ring-0",spellCheck:!1})}):h.jsx("div",{className:`grid overflow-x-auto ${t?"grid-cols-[auto_1fr]":"grid-cols-1"}`,children:f.flatMap((y,w)=>{const v=w+1,E=p.get(v)||[],N=[];return t&&N.push(h.jsx("div",{className:`select-none border-r border-border bg-muted/30 px-4 py-1 text-right font-mono text-xs leading-6 text-muted-foreground transition-colors hover:bg-primary/10 ${n.includes(v)?"font-bold text-primary":""} ${s===v?"bg-primary/20":""}`,"data-line-number":v,onClick:()=>m(v),children:v},`line-${w}`)),N.push(h.jsx("div",{className:`group relative px-4 py-1 font-mono text-sm leading-6 ${n.includes(v)?"bg-primary/10":""} ${s===v?"bg-primary/20":""}`,"data-line":v,children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx("pre",{className:"m-0 inline flex-1 cursor-pointer whitespace-pre-wrap break-words font-mono transition-colors hover:bg-muted/30",onClick:()=>m(v),onMouseUp:()=>g(v),children:y||" "}),E.length>0&&h.jsx("div",{className:"flex flex-wrap gap-1",children:Array.from(new Set(E.map(k=>k.feedback_type))).map(k=>{const C=E.filter(A=>A.feedback_type===k);return h.jsx(XK,{type:k,count:C.length,onClick:()=>a?.(C[0])},k)})})]})},`content-${w}`)),N})})})})}function eG({content:e,feedback:t=[],selectedLine:n,onLineClick:r,onTextSelect:s,onFeedbackClick:i,onChange:o,viewMode:a="formatted",onViewModeChange:l,className:c=""}){return h.jsx(It,{className:`overflow-hidden ${c}`,children:a==="formatted"?h.jsx(Bd,{content:e,editable:!0,onChange:o,onCancel:()=>{},showLineNumbers:!0,selectedLine:n,onLineClick:r,placeholder:"Spec content..."}):h.jsx(QK,{content:e,feedback:t,selectedLine:n,onLineClick:r,onTextSelect:s,onFeedbackClick:i,showLineNumbers:!1,editable:!0,onChange:o})})}const tG=/^[$_\p{ID_Start}][$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,nG=/^[$_\p{ID_Start}][-$_\u{200C}\u{200D}\p{ID_Continue}]*$/u,rG={};function Qv(e,t){return(rG.jsx?nG:tG).test(e)}var Ki={},yh,ew;function sG(){if(ew)return yh;ew=1;var e=/\/\*[^*]*\*+([^/*][^*]*\*+)*\//g,t=/\n/g,n=/^\s*/,r=/^(\*?[-#/*\\\w]+(\[[0-9a-z_-]+\])?)\s*/,s=/^:\s*/,i=/^((?:'(?:\\'|.)*?'|"(?:\\"|.)*?"|\([^)]*?\)|[^};])+)/,o=/^[;\s]*/,a=/^\s+|\s+$/g,l=`
563
+ `,c="/",u="*",d="",f="comment",p="declaration";yh=function(g,b){if(typeof g!="string")throw new TypeError("First argument must be a string");if(!g)return[];b=b||{};var y=1,w=1;function v(j){var L=j.match(t);L&&(y+=L.length);var F=j.lastIndexOf(l);w=~F?j.length-F:w+j.length}function E(){var j={line:y,column:w};return function(L){return L.position=new N(j),A(),L}}function N(j){this.start=j,this.end={line:y,column:w},this.source=b.source}N.prototype.content=g;function k(j){var L=new Error(b.source+":"+y+":"+w+": "+j);if(L.reason=j,L.filename=b.source,L.line=y,L.column=w,L.source=g,!b.silent)throw L}function C(j){var L=j.exec(g);if(L){var F=L[0];return v(F),g=g.slice(F.length),L}}function A(){C(n)}function R(j){var L;for(j=j||[];L=T();)L!==!1&&j.push(L);return j}function T(){var j=E();if(!(c!=g.charAt(0)||u!=g.charAt(1))){for(var L=2;d!=g.charAt(L)&&(u!=g.charAt(L)||c!=g.charAt(L+1));)++L;if(L+=2,d===g.charAt(L-1))return k("End of comment missing");var F=g.slice(2,L-2);return w+=2,v(F),g=g.slice(L),w+=2,j({type:f,comment:F})}}function I(){var j=E(),L=C(r);if(L){if(T(),!C(s))return k("property missing ':'");var F=C(i),q=j({type:p,property:m(L[0].replace(e,d)),value:F?m(F[0].replace(e,d)):d});return C(o),q}}function O(){var j=[];R(j);for(var L;L=I();)L!==!1&&(j.push(L),R(j));return j}return A(),O()};function m(g){return g?g.replace(a,d):d}return yh}var tw;function iG(){if(tw)return Ki;tw=1;var e=Ki&&Ki.__importDefault||function(r){return r&&r.__esModule?r:{default:r}};Object.defineProperty(Ki,"__esModule",{value:!0}),Ki.default=n;const t=e(sG());function n(r,s){let i=null;if(!r||typeof r!="string")return i;const o=(0,t.default)(r),a=typeof s=="function";return o.forEach(l=>{if(l.type!=="declaration")return;const{property:c,value:u}=l;a?s(c,u,l):u&&(i=i||{},i[c]=u)}),i}return Ki}var ta={},nw;function oG(){if(nw)return ta;nw=1,Object.defineProperty(ta,"__esModule",{value:!0}),ta.camelCase=void 0;var e=/^--[a-zA-Z0-9_-]+$/,t=/-([a-z])/g,n=/^[^-]+$/,r=/^-(webkit|moz|ms|o|khtml)-/,s=/^-(ms)-/,i=function(c){return!c||n.test(c)||e.test(c)},o=function(c,u){return u.toUpperCase()},a=function(c,u){return"".concat(u,"-")},l=function(c,u){return u===void 0&&(u={}),i(c)?c:(c=c.toLowerCase(),u.reactCompat?c=c.replace(s,a):c=c.replace(r,a),c.replace(t,o))};return ta.camelCase=l,ta}var na,rw;function aG(){if(rw)return na;rw=1;var e=na&&na.__importDefault||function(s){return s&&s.__esModule?s:{default:s}},t=e(iG()),n=oG();function r(s,i){var o={};return!s||typeof s!="string"||(0,t.default)(s,function(a,l){a&&l&&(o[(0,n.camelCase)(a,i)]=l)}),o}return r.default=r,na=r,na}var lG=aG();const cG=tl(lG),Hg={}.hasOwnProperty,uG=new Map,dG=/[A-Z]/g,fG=new Set(["table","tbody","thead","tfoot","tr"]),hG=new Set(["td","th"]),b_="https://github.com/syntax-tree/hast-util-to-jsx-runtime";function pG(e,t){if(!t||t.Fragment===void 0)throw new TypeError("Expected `Fragment` in options");const n=t.filePath||void 0;let r;if(t.development){if(typeof t.jsxDEV!="function")throw new TypeError("Expected `jsxDEV` in options when `development: true`");r=kG(n,t.jsxDEV)}else{if(typeof t.jsx!="function")throw new TypeError("Expected `jsx` in production options");if(typeof t.jsxs!="function")throw new TypeError("Expected `jsxs` in production options");r=wG(n,t.jsx,t.jsxs)}const s={Fragment:t.Fragment,ancestors:[],components:t.components||{},create:r,elementAttributeNameCase:t.elementAttributeNameCase||"react",evaluater:t.createEvaluater?t.createEvaluater():void 0,filePath:n,ignoreInvalidStyle:t.ignoreInvalidStyle||!1,passKeys:t.passKeys!==!1,passNode:t.passNode||!1,schema:t.space==="svg"?wl:wN,stylePropertyNameCase:t.stylePropertyNameCase||"dom",tableCellAlignToStyle:t.tableCellAlignToStyle!==!1},i=y_(s,e,void 0);return i&&typeof i!="string"?i:s.create(e,s.Fragment,{children:i||void 0},void 0)}function y_(e,t,n){if(t.type==="element")return mG(e,t,n);if(t.type==="mdxFlowExpression"||t.type==="mdxTextExpression")return gG(e,t);if(t.type==="mdxJsxFlowElement"||t.type==="mdxJsxTextElement")return yG(e,t,n);if(t.type==="mdxjsEsm")return bG(e,t);if(t.type==="root")return xG(e,t,n);if(t.type==="text")return vG(e,t)}function mG(e,t,n){const r=e.schema;let s=r;t.tagName.toLowerCase()==="svg"&&r.space==="html"&&(s=wl,e.schema=s),e.ancestors.push(t);const i=v_(e,t.tagName,!1),o=SG(e,t);let a=qg(e,t);return fG.has(t.tagName)&&(a=a.filter(function(l){return typeof l=="string"?!zd(l):!0})),x_(e,o,i,t),Vg(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function gG(e,t){if(t.data&&t.data.estree&&e.evaluater){const r=t.data.estree.body[0];return r.type,e.evaluater.evaluateExpression(r.expression)}Xa(e,t.position)}function bG(e,t){if(t.data&&t.data.estree&&e.evaluater)return e.evaluater.evaluateProgram(t.data.estree);Xa(e,t.position)}function yG(e,t,n){const r=e.schema;let s=r;t.name==="svg"&&r.space==="html"&&(s=wl,e.schema=s),e.ancestors.push(t);const i=t.name===null?e.Fragment:v_(e,t.name,!0),o=EG(e,t),a=qg(e,t);return x_(e,o,i,t),Vg(o,a),e.ancestors.pop(),e.schema=r,e.create(t,i,o,n)}function xG(e,t,n){const r={};return Vg(r,qg(e,t)),e.create(t,e.Fragment,r,n)}function vG(e,t){return t.value}function x_(e,t,n,r){typeof n!="string"&&n!==e.Fragment&&e.passNode&&(t.node=r)}function Vg(e,t){if(t.length>0){const n=t.length>1?t:t[0];n&&(e.children=n)}}function wG(e,t,n){return r;function r(s,i,o,a){const c=Array.isArray(o.children)?n:t;return a?c(i,o,a):c(i,o)}}function kG(e,t){return n;function n(r,s,i,o){const a=Array.isArray(i.children),l=Ng(r);return t(s,i,o,a,{columnNumber:l?l.column-1:void 0,fileName:e,lineNumber:l?l.line:void 0},void 0)}}function SG(e,t){const n={};let r,s;for(s in t.properties)if(s!=="children"&&Hg.call(t.properties,s)){const i=CG(e,s,t.properties[s]);if(i){const[o,a]=i;e.tableCellAlignToStyle&&o==="align"&&typeof a=="string"&&hG.has(t.tagName)?r=a:n[o]=a}}if(r){const i=n.style||(n.style={});i[e.stylePropertyNameCase==="css"?"text-align":"textAlign"]=r}return n}function EG(e,t){const n={};for(const r of t.attributes)if(r.type==="mdxJsxExpressionAttribute")if(r.data&&r.data.estree&&e.evaluater){const i=r.data.estree.body[0];i.type;const o=i.expression;o.type;const a=o.properties[0];a.type,Object.assign(n,e.evaluater.evaluateExpression(a.argument))}else Xa(e,t.position);else{const s=r.name;let i;if(r.value&&typeof r.value=="object")if(r.value.data&&r.value.data.estree&&e.evaluater){const a=r.value.data.estree.body[0];a.type,i=e.evaluater.evaluateExpression(a.expression)}else Xa(e,t.position);else i=r.value===null?!0:r.value;n[s]=i}return n}function qg(e,t){const n=[];let r=-1;const s=e.passKeys?new Map:uG;for(;++r<t.children.length;){const i=t.children[r];let o;if(e.passKeys){const l=i.type==="element"?i.tagName:i.type==="mdxJsxFlowElement"||i.type==="mdxJsxTextElement"?i.name:void 0;if(l){const c=s.get(l)||0;o=l+"-"+c,s.set(l,c+1)}}const a=y_(e,i,o);a!==void 0&&n.push(a)}return n}function CG(e,t,n){const r=vN(e.schema,t);if(!(n==null||typeof n=="number"&&Number.isNaN(n))){if(Array.isArray(n)&&(n=r.commaSeparated?SN(n):EN(n)),r.property==="style"){let s=typeof n=="object"?n:NG(e,String(n));return e.stylePropertyNameCase==="css"&&(s=_G(s)),["style",s]}return[e.elementAttributeNameCase==="react"&&r.space?f9[r.property]||r.property:r.attribute,n]}}function NG(e,t){try{return cG(t,{reactCompat:!0})}catch(n){if(e.ignoreInvalidStyle)return{};const r=n,s=new yn("Cannot parse `style` attribute",{ancestors:e.ancestors,cause:r,ruleId:"style",source:"hast-util-to-jsx-runtime"});throw s.file=e.filePath||void 0,s.url=b_+"#cannot-parse-style-attribute",s}}function v_(e,t,n){let r;if(!n)r={type:"Literal",value:t};else if(t.includes(".")){const s=t.split(".");let i=-1,o;for(;++i<s.length;){const a=Qv(s[i])?{type:"Identifier",name:s[i]}:{type:"Literal",value:s[i]};o=o?{type:"MemberExpression",object:o,property:a,computed:!!(i&&a.type==="Literal"),optional:!1}:a}r=o}else r=Qv(t)&&!/^[a-z]/.test(t)?{type:"Identifier",name:t}:{type:"Literal",value:t};if(r.type==="Literal"){const s=r.value;return Hg.call(e.components,s)?e.components[s]:s}if(e.evaluater)return e.evaluater.evaluateExpression(r);Xa(e)}function Xa(e,t){const n=new yn("Cannot handle MDX estrees without `createEvaluater`",{ancestors:e.ancestors,place:t,ruleId:"mdx-estree",source:"hast-util-to-jsx-runtime"});throw n.file=e.filePath||void 0,n.url=b_+"#cannot-handle-mdx-estrees-without-createevaluater",n}function _G(e){const t={};let n;for(n in e)Hg.call(e,n)&&(t[TG(n)]=e[n]);return t}function TG(e){let t=e.replace(dG,AG);return t.slice(0,3)==="ms-"&&(t="-"+t),t}function AG(e){return"-"+e.toLowerCase()}const xh={action:["form"],cite:["blockquote","del","ins","q"],data:["object"],formAction:["button","input"],href:["a","area","base","link"],icon:["menuitem"],itemId:null,manifest:["html"],ping:["a","area"],poster:["video"],src:["audio","embed","iframe","img","input","script","source","track","video"]},MG="https://github.com/remarkjs/react-markdown/blob/main/changelog.md",sw=[],iw={allowDangerousHtml:!0},RG=/^(https?|ircs?|mailto|xmpp)$/i,OG=[{from:"astPlugins",id:"remove-buggy-html-in-markdown-parser"},{from:"allowDangerousHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"allowNode",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowElement"},{from:"allowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"allowedElements"},{from:"disallowedTypes",id:"replace-allownode-allowedtypes-and-disallowedtypes",to:"disallowedElements"},{from:"escapeHtml",id:"remove-buggy-html-in-markdown-parser"},{from:"includeElementIndex",id:"#remove-includeelementindex"},{from:"includeNodeIndex",id:"change-includenodeindex-to-includeelementindex"},{from:"linkTarget",id:"remove-linktarget"},{from:"plugins",id:"change-plugins-to-remarkplugins",to:"remarkPlugins"},{from:"rawSourcePos",id:"#remove-rawsourcepos"},{from:"renderers",id:"change-renderers-to-components",to:"components"},{from:"source",id:"change-source-to-children",to:"children"},{from:"sourcePos",id:"#remove-sourcepos"},{from:"transformImageUri",id:"#add-urltransform",to:"urlTransform"},{from:"transformLinkUri",id:"#add-urltransform",to:"urlTransform"}];function w_(e){const t=IG(e),n=DG(e);return LG(t.runSync(t.parse(n),n),e)}function IG(e){const t=e.rehypePlugins||sw,n=e.remarkPlugins||sw,r=e.remarkRehypeOptions?{...e.remarkRehypeOptions,...iw}:iw;return b1().use(O1).use(n).use(fN,r).use(t)}function DG(e){const t=e.children||"",n=new g1;return typeof t=="string"&&(n.value=t),n}function LG(e,t){const n=t.allowedElements,r=t.allowElement,s=t.components,i=t.disallowedElements,o=t.skipHtml,a=t.unwrapDisallowed,l=t.urlTransform||PG;for(const u of OG)Object.hasOwn(t,u.from)&&(""+u.from+(u.to?"use `"+u.to+"` instead":"remove it")+MG+u.id,void 0);return t.className&&(e={type:"element",tagName:"div",properties:{className:t.className},children:e.type==="root"?e.children:[e]}),Sg(e,c),pG(e,{Fragment:h.Fragment,components:s,ignoreInvalidStyle:!0,jsx:h.jsx,jsxs:h.jsxs,passKeys:!0,passNode:!0});function c(u,d,f){if(u.type==="raw"&&f&&typeof d=="number")return o?f.children.splice(d,1):f.children[d]={type:"text",value:u.value},d;if(u.type==="element"){let p;for(p in xh)if(Object.hasOwn(xh,p)&&Object.hasOwn(u.properties,p)){const m=u.properties[p],g=xh[p];(g===null||g.includes(u.tagName))&&(u.properties[p]=l(String(m||""),p,u))}}if(u.type==="element"){let p=n?!n.includes(u.tagName):i?i.includes(u.tagName):!1;if(!p&&r&&typeof d=="number"&&(p=!r(u,d,f)),p&&f&&typeof d=="number")return a&&u.children?f.children.splice(d,1,...u.children):f.children.splice(d,1),d}}}function PG(e){const t=e.indexOf(":"),n=e.indexOf("?"),r=e.indexOf("#"),s=e.indexOf("/");return t===-1||s!==-1&&t>s||n!==-1&&t>n||r!==-1&&t>r||RG.test(e.slice(0,t))?e:""}function jG({feedback:e,onDismiss:t,onDelete:n,onClick:r,className:s="",maxHeight:i=500,isCompact:o=!1}){const[a,l]=x.useState(!1),[c,u]=x.useState(!o),d=cr();let f=null;try{e.anchor&&(f=JSON.parse(e.anchor))}catch(b){console.error("Failed to parse feedback anchor:",b)}const p=b=>{switch(b){case"comment":return h.jsx(Vu,{className:"h-4 w-4"});case"suggestion":return h.jsx(Kw,{className:"h-4 w-4"});case"request":return h.jsx(ki,{className:"h-4 w-4"})}},m=b=>{switch(b){case"comment":return"text-blue-600 bg-blue-50";case"suggestion":return"text-yellow-600 bg-yellow-50";case"request":return"text-orange-600 bg-orange-50"}},g=()=>f?f.line_number?`L${f.line_number}`:f.section_heading?`§ ${f.section_heading}`:f.text_snippet?`"${f.text_snippet.slice(0,30)}${f.text_snippet.length>30?"...":""}"`:null:null;return h.jsx(It,{className:`relative cursor-pointer rounded-lg border-2 bg-card shadow-sm transition-all hover:border-primary/30 hover:shadow-lg ${e.dismissed?"opacity-60":""} ${s}`,onMouseEnter:()=>l(!0),onMouseLeave:()=>l(!1),onClick:r,children:h.jsxs("div",{className:"p-3",children:[h.jsxs("div",{className:"mb-2",children:[h.jsxs("div",{className:"flex items-center justify-between gap-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:`flex-shrink-0 rounded-full p-1.5 ${m(e.feedback_type)}`,title:e.feedback_type,children:p(e.feedback_type)}),h.jsx("button",{className:"text-xs font-medium text-foreground hover:text-primary hover:underline",onClick:b=>{b.stopPropagation(),d(`/issues/${e.issue_id}`)},children:e.issue_id})]}),(t||n)&&h.jsxs("div",{className:"flex flex-shrink-0 gap-1 transition-opacity duration-150",style:{opacity:a?1:0},children:[!e.dismissed&&t&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),t(e.id)},title:"Dismiss",className:"h-6 w-6 p-0",children:h.jsx(Ww,{className:"h-3 w-3"})}),e.dismissed&&t&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),t(e.id)},title:"Restore",className:"h-6 w-6 p-0",children:h.jsx(da,{className:"h-3 w-3"})}),n&&h.jsx(oe,{variant:"ghost",size:"sm",onClick:b=>{b.stopPropagation(),n(e.id)},title:"Delete",className:"h-6 w-6 p-0",children:h.jsx(Io,{className:"h-3 w-3"})})]})]}),h.jsxs("div",{className:"ml-9 flex items-center gap-2 text-xs text-muted-foreground",children:[f&&g()&&h.jsxs(h.Fragment,{children:[h.jsx("span",{className:"flex-shrink-0",children:g()}),h.jsx("span",{className:"flex-shrink-0",children:"•"})]}),h.jsx("span",{className:"flex-shrink-0",children:Mc(new Date(e.created_at.endsWith("Z")?e.created_at:e.created_at+"Z"),{addSuffix:!0})})]})]}),h.jsx("div",{className:"prose prose-sm dark:prose-invert max-w-none text-sm text-foreground",style:{maxHeight:c?`${i}px`:"3rem",overflowY:"auto",overflowX:"hidden"},children:h.jsx(w_,{remarkPlugins:[sN],components:{p:({children:b})=>h.jsx("p",{className:"my-1",children:b}),h1:({children:b})=>h.jsx("h1",{className:"my-1 text-lg font-bold",children:b}),h2:({children:b})=>h.jsx("h2",{className:"my-1 text-base font-bold",children:b}),h3:({children:b})=>h.jsx("h3",{className:"my-1 text-sm font-bold",children:b}),ul:({children:b})=>h.jsx("ul",{className:"my-1 pl-4",children:b}),ol:({children:b})=>h.jsx("ol",{className:"my-1 pl-4",children:b}),li:({children:b})=>h.jsx("li",{className:"my-0.5",children:b}),code:({children:b,className:y})=>!y?h.jsx("code",{className:"rounded bg-muted px-1 py-0.5 font-mono text-xs",children:b}):h.jsx("code",{className:`my-1 block rounded bg-muted p-2 font-mono text-xs ${y||""}`,children:b}),pre:({children:b})=>h.jsx("pre",{className:"my-1",children:b}),blockquote:({children:b})=>h.jsx("blockquote",{className:"my-1 border-l-2 border-muted-foreground/30 pl-2 italic",children:b}),a:({href:b,children:y})=>h.jsx("a",{href:b,className:"text-primary underline hover:text-primary/80",target:"_blank",rel:"noopener noreferrer",onClick:w=>w.stopPropagation(),children:y}),strong:({children:b})=>h.jsx("strong",{className:"font-semibold",children:b}),em:({children:b})=>h.jsx("em",{className:"italic",children:b})},children:e.content})}),e.content.length>100&&h.jsx("button",{className:"mt-1 text-xs text-primary hover:underline",onClick:b=>{b.stopPropagation(),u(!c)},children:c?"Show less":"Show more"})]})})}function zG({positions:e,cardHeight:t=120,minSpacing:n=8}){return x.useMemo(()=>{const r=new Map,s=Array.from(e.entries()).map(([o,a])=>({id:o,idealTop:a})).sort((o,a)=>o.idealTop-a.idealTop),i=[];for(const o of s){let a=o.idealTop,l=!0;for(;l;){l=!1;for(const u of i){const d=u.actualTop+u.height+n,f=a+t;if(a<d&&f>u.actualTop){a=d,l=!0;break}}}const c={id:o.id,idealTop:o.idealTop,actualTop:a,height:t};i.push(c),r.set(o.id,c)}return r},[e,t,n])}const ow="sudocode:specs:showRelationshipsCollapsed";function FG(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function BG({feedback:e,positions:t,onFeedbackClick:n,onDismiss:r,onDelete:s,addFeedbackButton:i,className:o="",relationships:a,currentEntityId:l,onDeleteRelationship:c,onCreateRelationship:u}){const d=x.useRef(null),[f,p]=x.useState(!1),[m,g]=x.useState(()=>{const v=localStorage.getItem(ow);return v!==null?JSON.parse(v):!1}),b=(v,E,N)=>{u&&(u(v,E,N),p(!1))};x.useEffect(()=>{localStorage.setItem(ow,JSON.stringify(m))},[m]);const y=x.useMemo(()=>{const v=new Map,E=16;return e.forEach(N=>{const k=FG(N.anchor);if(!k||!k.line_number)v.set(N.id,E);else{const C=t.get(N.id);C!==void 0&&v.set(N.id,Math.max(C,E))}}),v},[e,t]),w=zG({positions:y,cardHeight:130,minSpacing:0});return h.jsxs("div",{className:`flex h-full w-80 flex-col bg-background md:w-96 lg:w-[28rem] xl:w-[32rem] ${o}`,children:[l&&h.jsxs("div",{className:"p-2",children:[h.jsxs("div",{className:"mb-2 flex cursor-pointer items-center justify-between rounded-md border p-2",onClick:()=>g(!m),children:[h.jsxs("div",{className:"flex items-center gap-2",children:[m?h.jsx(Aa,{className:"h-4 w-4 text-muted-foreground"}):h.jsx(am,{className:"h-4 w-4 text-muted-foreground"}),h.jsx("h3",{className:"text-sm font-medium text-muted-foreground",children:"Relationships"}),a&&a.length>0&&h.jsx(st,{variant:"secondary",children:a.length})]}),u&&h.jsxs(oe,{variant:"outline",size:"xs",onClick:v=>{v.stopPropagation(),p(!0)},className:"h-6",children:[h.jsx(Si,{className:"mr-1 h-4 w-4"}),"Add"]})]}),!m&&a&&a.length>0&&h.jsx(uS,{relationships:a,currentEntityId:l,currentEntityType:"spec",onDelete:c,showEmpty:!1,showGroupHeaders:!1})]}),h.jsx(Bi,{open:f,onOpenChange:p,children:h.jsxs(qs,{children:[h.jsx(Ws,{children:h.jsx(Ks,{children:"Add Relationship"})}),l&&h.jsx(hS,{fromId:l,fromType:"spec",onSubmit:b,onCancel:()=>p(!1)})]})}),i&&h.jsx("div",{className:"p-2",children:i}),h.jsx("div",{className:"relative min-h-full flex-1",children:h.jsxs("div",{ref:d,className:"relative w-full pt-4",children:[e.map(v=>{const E=w.get(v.id);return E?h.jsx("div",{className:"absolute w-full px-1",style:{top:`${E.actualTop}px`,zIndex:10},children:h.jsx(jG,{feedback:v,onClick:()=>n?.(v),onDismiss:r?()=>r(v.id):void 0,onDelete:s?()=>s(v.id):void 0,maxHeight:800,isCompact:!1})},v.id):null}),e.length>0&&h.jsx("div",{style:{height:`${Math.max(...Array.from(w.values()).map(v=>v.actualTop+v.height))+100}px`,pointerEvents:"none"}})]})})]})}function $G({issues:e=[],selectedIssueId:t,onIssueSelect:n,issueId:r,lineNumber:s,textSnippet:i,onSubmit:o,onCancel:a,className:l=""}){const[c,u]=x.useState("comment"),[d,f]=x.useState(""),[p,m]=x.useState(!1),g=t||r,b=async y=>{if(y.preventDefault(),!!d.trim()){m(!0);try{let w;(s||i)&&(w={line_number:s,text_snippet:i,anchor_status:"valid",last_verified_at:new Date().toISOString()}),await o({type:c,content:d.trim(),anchor:w}),f(""),u("comment")}finally{m(!1)}}};return h.jsxs("form",{onSubmit:b,className:`space-y-4 ${l}`,children:[(s||i)&&h.jsxs("div",{className:"rounded-md bg-muted/50 p-2 text-sm",children:[s&&h.jsxs("div",{className:"font-medium",children:["Line ",s]}),i&&h.jsxs("div",{className:"text-muted-foreground",children:['"',i.slice(0,60),i.length>60?"...":"",'"']})]}),e.length>0&&n&&h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"issue-select",children:"Issue"}),h.jsxs(Sn,{value:g,onValueChange:n,children:[h.jsx(dn,{id:"issue-select",children:h.jsx(En,{placeholder:"Select an issue..."})}),h.jsx(fn,{children:e.map(y=>h.jsxs(xt,{value:y.id,children:[y.id,": ",y.title]},y.id))})]})]}),h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"feedback-type",children:"Type"}),h.jsxs(Sn,{value:c,onValueChange:y=>u(y),children:[h.jsx(dn,{id:"feedback-type",children:h.jsx(En,{})}),h.jsxs(fn,{children:[h.jsx(xt,{value:"comment",children:"Comment"}),h.jsx(xt,{value:"suggestion",children:"Suggestion"}),h.jsx(xt,{value:"request",children:"Request"})]})]})]}),h.jsxs("div",{children:[h.jsx(Ht,{htmlFor:"feedback-content",children:"Content"}),h.jsx(gd,{id:"feedback-content",placeholder:"Enter your feedback...",value:d,onChange:y=>f(y.target.value),rows:4,required:!0,className:"resize-none"})]}),h.jsxs("div",{className:"flex gap-2",children:[h.jsx(oe,{type:"submit",disabled:!d.trim()||!g||p,children:p?"Adding...":"Add Feedback"}),h.jsx(oe,{type:"button",variant:"outline",onClick:a,children:"Cancel"})]})]})}function UG({issues:e,lineNumber:t,textSnippet:n,onSubmit:r,triggerButton:s}){const[i,o]=x.useState(!1),[a,l]=x.useState(),c=async u=>{a&&(await r({issueId:a,...u}),o(!1),l(void 0))};return h.jsxs(Bi,{open:i,onOpenChange:o,children:[h.jsx(MM,{asChild:!0,children:s||h.jsxs(oe,{variant:"outline",size:"sm",children:[h.jsx(cm,{className:"mr-2 h-4 w-4"}),"Add Feedback"]})}),h.jsxs(qs,{className:"sm:max-w-[500px]",children:[h.jsxs(Ws,{children:[h.jsx(Ks,{children:"Add Feedback"}),h.jsxs(Gu,{children:["Add a comment, suggestion, or request to this spec.",t&&` Anchored to line ${t}.`]})]}),h.jsx($G,{issues:e,selectedIssueId:a,onIssueSelect:l,lineNumber:t,textSnippet:n,onSubmit:c,onCancel:()=>o(!1)})]})]})}function HG(e,t){let n=null;return(...r)=>{n&&clearTimeout(n),n=setTimeout(()=>e(...r),t)}}function VG(e){if(!e)return null;try{return JSON.parse(e)}catch{return null}}function qG(e,t){const[n,r]=x.useState(new Map),s=x.useRef(null),i=x.useRef(null);return x.useEffect(()=>{const o=()=>{const u=new Map,d=t.current;if(!d){r(u);return}e.forEach(f=>{const p=VG(f.anchor);if(!p)return;let m=d.querySelector(`[data-feedback-id="${f.id}"]`);if(!m&&p.line_number!==void 0&&(m=d.querySelector(`[data-line-number="${p.line_number}"]`),!m)){const g=Array.from(d.querySelectorAll("[data-line-number]"));if(g.length>0&&p.line_number>0){let b=null,y=0;for(const w of g){const v=parseInt(w.getAttribute("data-line-number")||"0");v>0&&v<=p.line_number&&v>y&&(y=v,b=w)}m=b||g[0]}}if(!m&&p.text_snippet){const g=p.text_snippet.replace(/\.\.\./g,"").trim();if(g){const b=Array.from(d.querySelectorAll("[data-line-number]"));for(const y of b)if(y.textContent?.includes(g)){m=y;break}}}if(m){let g=0,b=m;for(;b&&b!==d;)g+=b.offsetTop,b=b.offsetParent;u.set(f.id,g)}}),r(u)},a=()=>{i.current!==null&&cancelAnimationFrame(i.current),i.current=requestAnimationFrame(o)},l=HG(o,100),c=t.current;return c?.addEventListener("scroll",a,{passive:!0}),window.addEventListener("resize",l),s.current=setTimeout(o,50),()=>{c?.removeEventListener("scroll",a),window.removeEventListener("resize",l),s.current&&clearTimeout(s.current),i.current!==null&&cancelAnimationFrame(i.current)}},[e,t]),n}const WG=[{value:"0",label:"Critical (P0)"},{value:"1",label:"High (P1)"},{value:"2",label:"Medium (P2)"},{value:"3",label:"Low (P3)"},{value:"4",label:"None (P4)"}],aw="sudocode:specs:showFeedbackPanel",lw="sudocode:details:viewMode";function KG(){const{id:e}=em(),t=cr(),{spec:n,isLoading:r,isError:s}=VK(e||""),{feedback:i}=qK(e||""),{issues:o}=ed(),{updateSpec:a,isUpdating:l,archiveSpec:c,unarchiveSpec:u}=Wd(),{createFeedback:d,updateFeedback:f,deleteFeedback:p}=YK(e||""),[m,g]=x.useState(null),[b,y]=x.useState(null),[w,v]=x.useState(()=>{const ce=localStorage.getItem(aw);return ce!==null?JSON.parse(ce):!0}),[E,N]=x.useState(()=>{const ce=localStorage.getItem(lw);return ce!==null?JSON.parse(ce):"formatted"}),[k,C]=x.useState(""),[A,R]=x.useState(""),[T,I]=x.useState(2),[O,j]=x.useState(!1),[L,F]=x.useState([]),[q,te]=x.useState(!1),K=x.useRef(null),le=x.useRef(a),_=x.useRef({title:k,content:A,priority:T,hasChanges:O}),ae=x.useRef(e),me=x.useRef(null),S=qG(i,me);if(x.useEffect(()=>{le.current=a},[a]),x.useEffect(()=>{_.current={title:k,content:A,priority:T,hasChanges:O}},[k,A,T,O]),x.useEffect(()=>{ae.current=e},[e]),x.useEffect(()=>{K.current&&(clearTimeout(K.current),K.current=null),j(!1)},[e]),x.useEffect(()=>{n&&(C(n.title),R(n.content||""),I(n.priority??2),j(!1))},[n]),x.useEffect(()=>{(async()=>{if(e){te(!0);try{const ne=await co.getForEntity(e,"spec");let et=[];if(Array.isArray(ne))et=ne;else if(ne&&typeof ne=="object"&&"outgoing"in ne&&"incoming"in ne){const We=ne;et=[...We.outgoing||[],...We.incoming||[]]}F(et)}catch(ne){console.error("Failed to fetch relationships:",ne),F([])}finally{te(!1)}}})()},[e]),x.useEffect(()=>{if(!(!O||!e))return K.current&&clearTimeout(K.current),K.current=setTimeout(()=>{le.current({id:e,data:{title:k,content:A,priority:T}}),j(!1)},1e3),()=>{K.current&&clearTimeout(K.current)}},[k,A,T,O]),x.useEffect(()=>()=>{const{hasChanges:ce,title:ne,content:et,priority:We}=_.current,ie=ae.current;ce&&ie&&le.current&&le.current({id:ie,data:{title:ne,content:et,priority:We}})},[]),x.useEffect(()=>{localStorage.setItem(aw,JSON.stringify(w))},[w]),x.useEffect(()=>{localStorage.setItem(lw,JSON.stringify(E))},[E]),r)return h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("div",{className:"mx-auto mb-4 h-8 w-8 animate-spin rounded-full border-4 border-primary border-t-transparent"}),h.jsx("p",{className:"text-muted-foreground",children:"Loading spec..."})]})});if(s||!n)return h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("h2",{className:"mb-2 text-2xl font-bold",children:"Spec not found"}),h.jsx("p",{className:"mb-4 text-muted-foreground",children:"The spec you're looking for doesn't exist or has been deleted."}),h.jsx(oe,{onClick:()=>t("/specs"),children:"Back to Specs"})]})});const B=ce=>{g(ce),y(null),v(!0)},$=(ce,ne)=>{y(ce),g(ne),v(!0)},D=ce=>{try{const ne=ce.anchor?JSON.parse(ce.anchor):null;ne?.line_number&&g(ne.line_number)}catch(ne){console.error("Failed to parse feedback anchor:",ne)}},P=ce=>{C(ce),j(!0)},W=ce=>{R(ce),j(!0)},fe=ce=>{I(ce),j(!0)},ee=ce=>{const ne=i.find(et=>et.id===ce);ne&&f({id:ce,data:{dismissed:!ne.dismissed}})},be=ce=>{p(ce)},Me=async ce=>{if(!e){console.error("Cannot create feedback without spec ID");return}await d({spec_id:e,issue_id:ce.issueId,feedback_type:ce.type,content:ce.content,anchor:ce.anchor})},Le=async ce=>{try{await co.delete({from_id:ce.from_id,from_type:ce.from_type,to_id:ce.to_id,to_type:ce.to_type,relationship_type:ce.relationship_type}),F(L.filter(ne=>!(ne.from_id===ce.from_id&&ne.to_id===ce.to_id&&ne.relationship_type===ce.relationship_type)))}catch(ne){console.error("Failed to delete relationship:",ne)}},Ke=async(ce,ne,et)=>{if(e)try{const We=await co.create({from_id:e,from_type:"spec",to_id:ce,to_type:ne,relationship_type:et});F([...L,We])}catch(We){console.error("Failed to create relationship:",We)}};return h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsx("div",{className:"flex items-center gap-4",children:h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>t("/specs"),children:"← Back to Specs"})}),h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("div",{className:"flex items-center gap-2",children:h.jsxs("div",{className:"inline-flex rounded-md border border-border bg-muted/30 p-1",children:[h.jsxs(oe,{variant:E==="formatted"?"outline":"ghost",size:"sm",onClick:()=>N("formatted"),className:`h-7 rounded-sm ${E==="formatted"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(ss,{className:"mr-2 h-4 w-4"}),"Formatted"]}),h.jsxs(oe,{variant:E==="source"?"outline":"ghost",size:"sm",onClick:()=>N("source"),className:`h-7 rounded-sm ${E==="source"?"shadow-sm":"text-muted-foreground hover:bg-muted"}`,children:[h.jsx(rl,{className:"mr-2 h-4 w-4"}),"Markdown"]})]})}),h.jsx(Ei,{children:h.jsxs(rr,{children:[h.jsx(sr,{asChild:!0,children:h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>v(!w),children:[w?h.jsx(wA,{className:"h-4 w-4"}):h.jsx(Vu,{className:"h-4 w-4"}),i.length>0&&h.jsx("span",{className:"ml-2 rounded-full bg-primary px-2 py-0.5 text-xs text-primary-foreground",children:i.length})]})}),h.jsx(Un,{children:h.jsxs("p",{children:[w?"Hide":"Show"," feedback"]})})]})}),n.archived?h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>u(n.id),disabled:l,children:[h.jsx(im,{className:"mr-2 h-4 w-4"}),"Unarchive"]}):h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>c(n.id),disabled:l,children:[h.jsx(Oo,{className:"mr-2 h-4 w-4"}),"Archive"]})]})]}),h.jsx("div",{ref:me,className:"flex flex-1 overflow-auto xl:justify-center",children:h.jsxs("div",{className:"flex w-full xl:max-w-[1600px]",children:[h.jsx("div",{className:"flex-1 px-6 py-4 lg:px-12 xl:px-16",children:h.jsxs("div",{className:"mx-auto max-w-4xl space-y-3",children:[h.jsxs("div",{className:"space-y-2 pb-3",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsx("span",{className:"font-mono text-sm text-muted-foreground",children:n.id}),h.jsx("div",{className:"text-xs italic text-muted-foreground",children:l?"Saving...":O?"Unsaved changes...":"All changes saved"})]}),h.jsx(is,{value:k,onChange:ce=>P(ce.target.value),disabled:l,placeholder:"Spec title...",className:"border-none bg-transparent px-0 text-2xl font-semibold shadow-none focus-visible:ring-0"})]}),h.jsxs("div",{className:"flex flex-wrap items-center gap-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(Jw,{className:"h-4 w-4 text-muted-foreground"}),h.jsxs(Sn,{value:String(T),onValueChange:ce=>fe(parseInt(ce)),disabled:l,children:[h.jsx(dn,{className:"h-8 w-auto gap-3 rounded-md border-none bg-accent px-3 shadow-none hover:bg-accent/80",children:h.jsx(En,{placeholder:"Priority"})}),h.jsx(fn,{children:WG.map(ce=>h.jsx(xt,{value:ce.value,children:ce.label},ce.value))})]})]}),h.jsx("div",{className:"ml-auto flex items-center gap-4 text-xs text-muted-foreground",children:n.updated_at&&h.jsxs("div",{className:"ml-auto flex items-center text-xs text-muted-foreground",children:["Updated ",Mc(new Date(n.updated_at.endsWith("Z")?n.updated_at:n.updated_at+"Z"),{addSuffix:!0})]})})]}),A!==void 0?h.jsx(eG,{content:A,feedback:i,selectedLine:m,onLineClick:B,onTextSelect:$,onFeedbackClick:D,onChange:W,viewMode:E,onViewModeChange:N}):h.jsx(It,{className:"p-8 text-center",children:h.jsx("p",{className:"text-muted-foreground",children:"No content available for this spec."})})]})}),w&&h.jsx(BG,{feedback:i,positions:S,relationships:L,currentEntityId:e,onFeedbackClick:D,onDismiss:ee,onDelete:be,onDeleteRelationship:Le,onCreateRelationship:Ke,addFeedbackButton:h.jsx("div",{className:"flex justify-center",children:h.jsx(UG,{issues:o,lineNumber:m||void 0,onSubmit:Me,triggerButton:h.jsxs(oe,{variant:"secondary",size:"sm",children:[h.jsx(cm,{className:"mr-2 h-4 w-4"}),"Add Feedback"]})})})})]})})]})}function GG(){const e=cr(),{issues:t,isLoading:n,isError:r,error:s,updateIssue:i,deleteIssue:o,unarchiveIssue:a,isUpdating:l,isDeleting:c}=ed(!0),[u,d]=x.useState(),[f,p]=x.useState(""),m=x.useMemo(()=>{const E=f?t.filter(k=>{const C=f.toLowerCase();return k.title.toLowerCase().includes(C)||k.content&&k.content.toLowerCase().includes(C)}):t,N={open:[],in_progress:[],blocked:[],needs_review:[],closed:[]};return E.forEach(k=>{const C=k.status.toLowerCase();N[C]?N[C].push(k):N.open.push(k)}),Object.keys(N).forEach(k=>{const C=k;C==="closed"?N[C].sort((A,R)=>{const T=A.closed_at?new Date(A.closed_at).getTime():0;return(R.closed_at?new Date(R.closed_at).getTime():0)-T}):N[C].sort((A,R)=>A.priority!==R.priority?A.priority-R.priority:new Date(A.created_at).getTime()-new Date(R.created_at).getTime())}),N},[t,f]),g=x.useCallback(E=>{d(E)},[]),b=x.useCallback(()=>{d(void 0)},[]),y=x.useCallback(E=>{u&&i({id:u.id,data:E})},[u,i]),w=x.useCallback(()=>{u&&(o(u.id),d(void 0))},[u,o]),v=x.useCallback(E=>{a(E)},[a]);return n?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsx("p",{className:"text-muted-foreground",children:"Loading archived issues..."})}):r?h.jsx("div",{className:"flex items-center justify-center p-8",children:h.jsxs("p",{className:"text-destructive",children:["Error loading archived issues: ",s?.message||"Unknown error"]})}):h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsxs("div",{className:"flex items-center justify-between border-b bg-background p-4",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>e("/issues"),className:"h-8 w-8 p-0",children:h.jsx(Hu,{className:"h-4 w-4"})}),h.jsxs("div",{children:[h.jsx("h1",{className:"text-2xl font-bold",children:"Archived Issues"}),h.jsxs("p",{className:"text-sm text-muted-foreground",children:[t.length," archived issues"]})]})]}),h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter issues...",value:f,onChange:E=>p(E.target.value),className:"h-9 w-64 pl-8"})]})]}),h.jsx("div",{className:"flex flex-1 overflow-hidden",children:u?h.jsxs($g,{direction:"horizontal",className:"h-full min-h-0",onLayout:E=>{if(E.length===2)try{localStorage.setItem("archivedIssuesPage.panelSizes",JSON.stringify(E))}catch{}},children:[h.jsx(Ja,{id:"kanban",order:1,defaultSize:(()=>{try{const E=localStorage.getItem("archivedIssuesPage.panelSizes");if(E){const N=JSON.parse(E);if(Array.isArray(N)&&N.length===2)return N[0]}}catch{}return 66})(),minSize:30,className:"min-w-0 min-h-0 overflow-auto",children:h.jsx(Ac,{groupedIssues:m,onDragEnd:()=>{},onViewIssueDetails:g,selectedIssue:u})}),h.jsxs(Ug,{className:"relative z-30 w-1 bg-border cursor-col-resize group touch-none focus:outline-none focus-visible:ring-2 focus-visible:ring-ring/60 focus-visible:ring-offset-1 focus-visible:ring-offset-background",children:[h.jsx("div",{className:"pointer-events-none absolute inset-y-0 left-1/2 -translate-x-1/2 w-px bg-border"}),h.jsxs("div",{className:"pointer-events-none absolute top-1/2 left-1/2 -translate-x-1/2 -translate-y-1/2 flex flex-col items-center gap-1 bg-muted/90 border border-border rounded-full px-1.5 py-3 opacity-70 group-hover:opacity-100 group-focus:opacity-100 transition-opacity shadow-sm",children:[h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"}),h.jsx("span",{className:"w-1 h-1 rounded-full bg-muted-foreground"})]})]}),h.jsx(Ja,{id:"details",order:2,defaultSize:(()=>{try{const E=localStorage.getItem("archivedIssuesPage.panelSizes");if(E){const N=JSON.parse(E);if(Array.isArray(N)&&N.length===2)return N[1]}}catch{}return 34})(),minSize:20,className:"min-w-0 min-h-0 overflow-hidden border-l bg-background shadow-lg",children:h.jsx(jg,{issue:u,onClose:b,onUpdate:y,onDelete:w,onUnarchive:v,isUpdating:l,isDeleting:c})})]}):h.jsx("div",{className:"flex-1 overflow-auto",children:h.jsx(Ac,{groupedIssues:m,onDragEnd:()=>{},onViewIssueDetails:g,selectedIssue:u})})})]})}function JG(){const{specs:e,isLoading:t}=Wd(!0),n=cr(),[r,s]=x.useState(""),i=r?e.filter(o=>{const a=r.toLowerCase();return o.title.toLowerCase().includes(a)||o.content&&o.content.toLowerCase().includes(a)}):e;return h.jsxs("div",{className:"flex-1 p-8",children:[h.jsxs("div",{className:"mb-6 flex items-center justify-between",children:[h.jsxs("div",{children:[h.jsxs("div",{className:"flex items-center gap-2 mb-2",children:[h.jsx(oe,{variant:"ghost",size:"sm",onClick:()=>n("/specs"),className:"h-8 w-8 p-0",children:h.jsx(Hu,{className:"h-4 w-4"})}),h.jsx("h1",{className:"text-3xl font-bold",children:"Archived Specs"})]}),h.jsx("p",{className:"text-muted-foreground ml-10",children:t?"Loading...":`${e.length} archived spec${e.length!==1?"s":""}`})]}),h.jsxs("div",{className:"relative",children:[h.jsx(qu,{className:"absolute left-2 top-1/2 h-4 w-4 -translate-y-1/2 text-muted-foreground"}),h.jsx(is,{type:"text",placeholder:"Filter specs...",value:r,onChange:o=>s(o.target.value),className:"h-9 w-64 pl-8"})]})]}),h.jsx(g_,{specs:i,loading:t})]})}var Qe;(function(e){e.assertEqual=s=>{};function t(s){}e.assertIs=t;function n(s){throw new Error}e.assertNever=n,e.arrayToEnum=s=>{const i={};for(const o of s)i[o]=o;return i},e.getValidEnumValues=s=>{const i=e.objectKeys(s).filter(a=>typeof s[s[a]]!="number"),o={};for(const a of i)o[a]=s[a];return e.objectValues(o)},e.objectValues=s=>e.objectKeys(s).map(function(i){return s[i]}),e.objectKeys=typeof Object.keys=="function"?s=>Object.keys(s):s=>{const i=[];for(const o in s)Object.prototype.hasOwnProperty.call(s,o)&&i.push(o);return i},e.find=(s,i)=>{for(const o of s)if(i(o))return o},e.isInteger=typeof Number.isInteger=="function"?s=>Number.isInteger(s):s=>typeof s=="number"&&Number.isFinite(s)&&Math.floor(s)===s;function r(s,i=" | "){return s.map(o=>typeof o=="string"?`'${o}'`:o).join(i)}e.joinValues=r,e.jsonStringifyReplacer=(s,i)=>typeof i=="bigint"?i.toString():i})(Qe||(Qe={}));var cw;(function(e){e.mergeShapes=(t,n)=>({...t,...n})})(cw||(cw={}));const pe=Qe.arrayToEnum(["string","nan","number","integer","float","boolean","date","bigint","symbol","function","undefined","null","array","object","unknown","promise","void","never","map","set"]),ks=e=>{switch(typeof e){case"undefined":return pe.undefined;case"string":return pe.string;case"number":return Number.isNaN(e)?pe.nan:pe.number;case"boolean":return pe.boolean;case"function":return pe.function;case"bigint":return pe.bigint;case"symbol":return pe.symbol;case"object":return Array.isArray(e)?pe.array:e===null?pe.null:e.then&&typeof e.then=="function"&&e.catch&&typeof e.catch=="function"?pe.promise:typeof Map<"u"&&e instanceof Map?pe.map:typeof Set<"u"&&e instanceof Set?pe.set:typeof Date<"u"&&e instanceof Date?pe.date:pe.object;default:return pe.unknown}},Y=Qe.arrayToEnum(["invalid_type","invalid_literal","custom","invalid_union","invalid_union_discriminator","invalid_enum_value","unrecognized_keys","invalid_arguments","invalid_return_type","invalid_date","invalid_string","too_small","too_big","invalid_intersection_types","not_multiple_of","not_finite"]);class ts extends Error{get errors(){return this.issues}constructor(t){super(),this.issues=[],this.addIssue=r=>{this.issues=[...this.issues,r]},this.addIssues=(r=[])=>{this.issues=[...this.issues,...r]};const n=new.target.prototype;Object.setPrototypeOf?Object.setPrototypeOf(this,n):this.__proto__=n,this.name="ZodError",this.issues=t}format(t){const n=t||function(i){return i.message},r={_errors:[]},s=i=>{for(const o of i.issues)if(o.code==="invalid_union")o.unionErrors.map(s);else if(o.code==="invalid_return_type")s(o.returnTypeError);else if(o.code==="invalid_arguments")s(o.argumentsError);else if(o.path.length===0)r._errors.push(n(o));else{let a=r,l=0;for(;l<o.path.length;){const c=o.path[l];l===o.path.length-1?(a[c]=a[c]||{_errors:[]},a[c]._errors.push(n(o))):a[c]=a[c]||{_errors:[]},a=a[c],l++}}};return s(this),r}static assert(t){if(!(t instanceof ts))throw new Error(`Not a ZodError: ${t}`)}toString(){return this.message}get message(){return JSON.stringify(this.issues,Qe.jsonStringifyReplacer,2)}get isEmpty(){return this.issues.length===0}flatten(t=n=>n.message){const n={},r=[];for(const s of this.issues)if(s.path.length>0){const i=s.path[0];n[i]=n[i]||[],n[i].push(t(s))}else r.push(t(s));return{formErrors:r,fieldErrors:n}}get formErrors(){return this.flatten()}}ts.create=e=>new ts(e);const Up=(e,t)=>{let n;switch(e.code){case Y.invalid_type:e.received===pe.undefined?n="Required":n=`Expected ${e.expected}, received ${e.received}`;break;case Y.invalid_literal:n=`Invalid literal value, expected ${JSON.stringify(e.expected,Qe.jsonStringifyReplacer)}`;break;case Y.unrecognized_keys:n=`Unrecognized key(s) in object: ${Qe.joinValues(e.keys,", ")}`;break;case Y.invalid_union:n="Invalid input";break;case Y.invalid_union_discriminator:n=`Invalid discriminator value. Expected ${Qe.joinValues(e.options)}`;break;case Y.invalid_enum_value:n=`Invalid enum value. Expected ${Qe.joinValues(e.options)}, received '${e.received}'`;break;case Y.invalid_arguments:n="Invalid function arguments";break;case Y.invalid_return_type:n="Invalid function return type";break;case Y.invalid_date:n="Invalid date";break;case Y.invalid_string:typeof e.validation=="object"?"includes"in e.validation?(n=`Invalid input: must include "${e.validation.includes}"`,typeof e.validation.position=="number"&&(n=`${n} at one or more positions greater than or equal to ${e.validation.position}`)):"startsWith"in e.validation?n=`Invalid input: must start with "${e.validation.startsWith}"`:"endsWith"in e.validation?n=`Invalid input: must end with "${e.validation.endsWith}"`:Qe.assertNever(e.validation):e.validation!=="regex"?n=`Invalid ${e.validation}`:n="Invalid";break;case Y.too_small:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at least":"more than"} ${e.minimum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at least":"over"} ${e.minimum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="bigint"?n=`Number must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${e.minimum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly equal to ":e.inclusive?"greater than or equal to ":"greater than "}${new Date(Number(e.minimum))}`:n="Invalid input";break;case Y.too_big:e.type==="array"?n=`Array must contain ${e.exact?"exactly":e.inclusive?"at most":"less than"} ${e.maximum} element(s)`:e.type==="string"?n=`String must contain ${e.exact?"exactly":e.inclusive?"at most":"under"} ${e.maximum} character(s)`:e.type==="number"?n=`Number must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="bigint"?n=`BigInt must be ${e.exact?"exactly":e.inclusive?"less than or equal to":"less than"} ${e.maximum}`:e.type==="date"?n=`Date must be ${e.exact?"exactly":e.inclusive?"smaller than or equal to":"smaller than"} ${new Date(Number(e.maximum))}`:n="Invalid input";break;case Y.custom:n="Invalid input";break;case Y.invalid_intersection_types:n="Intersection results could not be merged";break;case Y.not_multiple_of:n=`Number must be a multiple of ${e.multipleOf}`;break;case Y.not_finite:n="Number must be finite";break;default:n=t.defaultError,Qe.assertNever(e)}return{message:n}};let ZG=Up;function YG(){return ZG}const XG=e=>{const{data:t,path:n,errorMaps:r,issueData:s}=e,i=[...n,...s.path||[]],o={...s,path:i};if(s.message!==void 0)return{...s,path:i,message:s.message};let a="";const l=r.filter(c=>!!c).slice().reverse();for(const c of l)a=c(o,{data:t,defaultError:a}).message;return{...s,path:i,message:a}};function he(e,t){const n=YG(),r=XG({issueData:t,data:e.data,path:e.path,errorMaps:[e.common.contextualErrorMap,e.schemaErrorMap,n,n===Up?void 0:Up].filter(s=>!!s)});e.common.issues.push(r)}class Kn{constructor(){this.value="valid"}dirty(){this.value==="valid"&&(this.value="dirty")}abort(){this.value!=="aborted"&&(this.value="aborted")}static mergeArray(t,n){const r=[];for(const s of n){if(s.status==="aborted")return Oe;s.status==="dirty"&&t.dirty(),r.push(s.value)}return{status:t.value,value:r}}static async mergeObjectAsync(t,n){const r=[];for(const s of n){const i=await s.key,o=await s.value;r.push({key:i,value:o})}return Kn.mergeObjectSync(t,r)}static mergeObjectSync(t,n){const r={};for(const s of n){const{key:i,value:o}=s;if(i.status==="aborted"||o.status==="aborted")return Oe;i.status==="dirty"&&t.dirty(),o.status==="dirty"&&t.dirty(),i.value!=="__proto__"&&(typeof o.value<"u"||s.alwaysSet)&&(r[i.value]=o.value)}return{status:t.value,value:r}}}const Oe=Object.freeze({status:"aborted"}),ua=e=>({status:"dirty",value:e}),ur=e=>({status:"valid",value:e}),uw=e=>e.status==="aborted",dw=e=>e.status==="dirty",Ao=e=>e.status==="valid",Mu=e=>typeof Promise<"u"&&e instanceof Promise;var ge;(function(e){e.errToObj=t=>typeof t=="string"?{message:t}:t||{},e.toString=t=>typeof t=="string"?t:t?.message})(ge||(ge={}));class Hs{constructor(t,n,r,s){this._cachedPath=[],this.parent=t,this.data=n,this._path=r,this._key=s}get path(){return this._cachedPath.length||(Array.isArray(this._key)?this._cachedPath.push(...this._path,...this._key):this._cachedPath.push(...this._path,this._key)),this._cachedPath}}const fw=(e,t)=>{if(Ao(t))return{success:!0,data:t.value};if(!e.common.issues.length)throw new Error("Validation failed but no issues detected.");return{success:!1,get error(){if(this._error)return this._error;const n=new ts(e.common.issues);return this._error=n,this._error}}};function qe(e){if(!e)return{};const{errorMap:t,invalid_type_error:n,required_error:r,description:s}=e;if(t&&(n||r))throw new Error(`Can't use "invalid_type_error" or "required_error" in conjunction with custom error map.`);return t?{errorMap:t,description:s}:{errorMap:(o,a)=>{const{message:l}=e;return o.code==="invalid_enum_value"?{message:l??a.defaultError}:typeof a.data>"u"?{message:l??r??a.defaultError}:o.code!=="invalid_type"?{message:a.defaultError}:{message:l??n??a.defaultError}},description:s}}class Xe{get description(){return this._def.description}_getType(t){return ks(t.data)}_getOrReturnCtx(t,n){return n||{common:t.parent.common,data:t.data,parsedType:ks(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}_processInputParams(t){return{status:new Kn,ctx:{common:t.parent.common,data:t.data,parsedType:ks(t.data),schemaErrorMap:this._def.errorMap,path:t.path,parent:t.parent}}}_parseSync(t){const n=this._parse(t);if(Mu(n))throw new Error("Synchronous parse encountered promise.");return n}_parseAsync(t){const n=this._parse(t);return Promise.resolve(n)}parse(t,n){const r=this.safeParse(t,n);if(r.success)return r.data;throw r.error}safeParse(t,n){const r={common:{issues:[],async:n?.async??!1,contextualErrorMap:n?.errorMap},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)},s=this._parseSync({data:t,path:r.path,parent:r});return fw(r,s)}"~validate"(t){const n={common:{issues:[],async:!!this["~standard"].async},path:[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)};if(!this["~standard"].async)try{const r=this._parseSync({data:t,path:[],parent:n});return Ao(r)?{value:r.value}:{issues:n.common.issues}}catch(r){r?.message?.toLowerCase()?.includes("encountered")&&(this["~standard"].async=!0),n.common={issues:[],async:!0}}return this._parseAsync({data:t,path:[],parent:n}).then(r=>Ao(r)?{value:r.value}:{issues:n.common.issues})}async parseAsync(t,n){const r=await this.safeParseAsync(t,n);if(r.success)return r.data;throw r.error}async safeParseAsync(t,n){const r={common:{issues:[],contextualErrorMap:n?.errorMap,async:!0},path:n?.path||[],schemaErrorMap:this._def.errorMap,parent:null,data:t,parsedType:ks(t)},s=this._parse({data:t,path:r.path,parent:r}),i=await(Mu(s)?s:Promise.resolve(s));return fw(r,i)}refine(t,n){const r=s=>typeof n=="string"||typeof n>"u"?{message:n}:typeof n=="function"?n(s):n;return this._refinement((s,i)=>{const o=t(s),a=()=>i.addIssue({code:Y.custom,...r(s)});return typeof Promise<"u"&&o instanceof Promise?o.then(l=>l?!0:(a(),!1)):o?!0:(a(),!1)})}refinement(t,n){return this._refinement((r,s)=>t(r)?!0:(s.addIssue(typeof n=="function"?n(r,s):n),!1))}_refinement(t){return new zi({schema:this,typeName:De.ZodEffects,effect:{type:"refinement",refinement:t}})}superRefine(t){return this._refinement(t)}constructor(t){this.spa=this.safeParseAsync,this._def=t,this.parse=this.parse.bind(this),this.safeParse=this.safeParse.bind(this),this.parseAsync=this.parseAsync.bind(this),this.safeParseAsync=this.safeParseAsync.bind(this),this.spa=this.spa.bind(this),this.refine=this.refine.bind(this),this.refinement=this.refinement.bind(this),this.superRefine=this.superRefine.bind(this),this.optional=this.optional.bind(this),this.nullable=this.nullable.bind(this),this.nullish=this.nullish.bind(this),this.array=this.array.bind(this),this.promise=this.promise.bind(this),this.or=this.or.bind(this),this.and=this.and.bind(this),this.transform=this.transform.bind(this),this.brand=this.brand.bind(this),this.default=this.default.bind(this),this.catch=this.catch.bind(this),this.describe=this.describe.bind(this),this.pipe=this.pipe.bind(this),this.readonly=this.readonly.bind(this),this.isNullable=this.isNullable.bind(this),this.isOptional=this.isOptional.bind(this),this["~standard"]={version:1,vendor:"zod",validate:n=>this["~validate"](n)}}optional(){return Qr.create(this,this._def)}nullable(){return Fi.create(this,this._def)}nullish(){return this.nullable().optional()}array(){return Ir.create(this)}promise(){return Pu.create(this,this._def)}or(t){return Ou.create([this,t],this._def)}and(t){return Iu.create(this,t,this._def)}transform(t){return new zi({...qe(this._def),schema:this,typeName:De.ZodEffects,effect:{type:"transform",transform:t}})}default(t){const n=typeof t=="function"?t:()=>t;return new ju({...qe(this._def),innerType:this,defaultValue:n,typeName:De.ZodDefault})}brand(){return new C_({typeName:De.ZodBranded,type:this,...qe(this._def)})}catch(t){const n=typeof t=="function"?t:()=>t;return new zu({...qe(this._def),innerType:this,catchValue:n,typeName:De.ZodCatch})}describe(t){const n=this.constructor;return new n({...this._def,description:t})}pipe(t){return Kg.create(this,t)}readonly(){return Fu.create(this)}isOptional(){return this.safeParse(void 0).success}isNullable(){return this.safeParse(null).success}}const QG=/^c[^\s-]{8,}$/i,e8=/^[0-9a-z]+$/,t8=/^[0-9A-HJKMNP-TV-Z]{26}$/i,n8=/^[0-9a-fA-F]{8}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{4}\b-[0-9a-fA-F]{12}$/i,r8=/^[a-z0-9_-]{21}$/i,s8=/^[A-Za-z0-9-_]+\.[A-Za-z0-9-_]+\.[A-Za-z0-9-_]*$/,i8=/^[-+]?P(?!$)(?:(?:[-+]?\d+Y)|(?:[-+]?\d+[.,]\d+Y$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:(?:[-+]?\d+W)|(?:[-+]?\d+[.,]\d+W$))?(?:(?:[-+]?\d+D)|(?:[-+]?\d+[.,]\d+D$))?(?:T(?=[\d+-])(?:(?:[-+]?\d+H)|(?:[-+]?\d+[.,]\d+H$))?(?:(?:[-+]?\d+M)|(?:[-+]?\d+[.,]\d+M$))?(?:[-+]?\d+(?:[.,]\d+)?S)?)??$/,o8=/^(?!\.)(?!.*\.\.)([A-Z0-9_'+\-\.]*)[A-Z0-9_+-]@([A-Z0-9][A-Z0-9\-]*\.)+[A-Z]{2,}$/i,a8="^(\\p{Extended_Pictographic}|\\p{Emoji_Component})+$";let vh;const l8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])$/,c8=/^(?:(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\.){3}(?:25[0-5]|2[0-4][0-9]|1[0-9][0-9]|[1-9][0-9]|[0-9])\/(3[0-2]|[12]?[0-9])$/,u8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))$/,d8=/^(([0-9a-fA-F]{1,4}:){7,7}[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,7}:|([0-9a-fA-F]{1,4}:){1,6}:[0-9a-fA-F]{1,4}|([0-9a-fA-F]{1,4}:){1,5}(:[0-9a-fA-F]{1,4}){1,2}|([0-9a-fA-F]{1,4}:){1,4}(:[0-9a-fA-F]{1,4}){1,3}|([0-9a-fA-F]{1,4}:){1,3}(:[0-9a-fA-F]{1,4}){1,4}|([0-9a-fA-F]{1,4}:){1,2}(:[0-9a-fA-F]{1,4}){1,5}|[0-9a-fA-F]{1,4}:((:[0-9a-fA-F]{1,4}){1,6})|:((:[0-9a-fA-F]{1,4}){1,7}|:)|fe80:(:[0-9a-fA-F]{0,4}){0,4}%[0-9a-zA-Z]{1,}|::(ffff(:0{1,4}){0,1}:){0,1}((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])|([0-9a-fA-F]{1,4}:){1,4}:((25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9])\.){3,3}(25[0-5]|(2[0-4]|1{0,1}[0-9]){0,1}[0-9]))\/(12[0-8]|1[01][0-9]|[1-9]?[0-9])$/,f8=/^([0-9a-zA-Z+/]{4})*(([0-9a-zA-Z+/]{2}==)|([0-9a-zA-Z+/]{3}=))?$/,h8=/^([0-9a-zA-Z-_]{4})*(([0-9a-zA-Z-_]{2}(==)?)|([0-9a-zA-Z-_]{3}(=)?))?$/,k_="((\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-((0[13578]|1[02])-(0[1-9]|[12]\\d|3[01])|(0[469]|11)-(0[1-9]|[12]\\d|30)|(02)-(0[1-9]|1\\d|2[0-8])))",p8=new RegExp(`^${k_}$`);function S_(e){let t="[0-5]\\d";e.precision?t=`${t}\\.\\d{${e.precision}}`:e.precision==null&&(t=`${t}(\\.\\d+)?`);const n=e.precision?"+":"?";return`([01]\\d|2[0-3]):[0-5]\\d(:${t})${n}`}function m8(e){return new RegExp(`^${S_(e)}$`)}function g8(e){let t=`${k_}T${S_(e)}`;const n=[];return n.push(e.local?"Z?":"Z"),e.offset&&n.push("([+-]\\d{2}:?\\d{2})"),t=`${t}(${n.join("|")})`,new RegExp(`^${t}$`)}function b8(e,t){return!!((t==="v4"||!t)&&l8.test(e)||(t==="v6"||!t)&&u8.test(e))}function y8(e,t){if(!s8.test(e))return!1;try{const[n]=e.split(".");if(!n)return!1;const r=n.replace(/-/g,"+").replace(/_/g,"/").padEnd(n.length+(4-n.length%4)%4,"="),s=JSON.parse(atob(r));return!(typeof s!="object"||s===null||"typ"in s&&s?.typ!=="JWT"||!s.alg||t&&s.alg!==t)}catch{return!1}}function x8(e,t){return!!((t==="v4"||!t)&&c8.test(e)||(t==="v6"||!t)&&d8.test(e))}class Os extends Xe{_parse(t){if(this._def.coerce&&(t.data=String(t.data)),this._getType(t)!==pe.string){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.string,received:i.parsedType}),Oe}const r=new Kn;let s;for(const i of this._def.checks)if(i.kind==="min")t.data.length<i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="max")t.data.length>i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!1,message:i.message}),r.dirty());else if(i.kind==="length"){const o=t.data.length>i.value,a=t.data.length<i.value;(o||a)&&(s=this._getOrReturnCtx(t,s),o?he(s,{code:Y.too_big,maximum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}):a&&he(s,{code:Y.too_small,minimum:i.value,type:"string",inclusive:!0,exact:!0,message:i.message}),r.dirty())}else if(i.kind==="email")o8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"email",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="emoji")vh||(vh=new RegExp(a8,"u")),vh.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"emoji",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="uuid")n8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"uuid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="nanoid")r8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"nanoid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid")QG.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cuid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="cuid2")e8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cuid2",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="ulid")t8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"ulid",code:Y.invalid_string,message:i.message}),r.dirty());else if(i.kind==="url")try{new URL(t.data)}catch{s=this._getOrReturnCtx(t,s),he(s,{validation:"url",code:Y.invalid_string,message:i.message}),r.dirty()}else i.kind==="regex"?(i.regex.lastIndex=0,i.regex.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"regex",code:Y.invalid_string,message:i.message}),r.dirty())):i.kind==="trim"?t.data=t.data.trim():i.kind==="includes"?t.data.includes(i.value,i.position)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{includes:i.value,position:i.position},message:i.message}),r.dirty()):i.kind==="toLowerCase"?t.data=t.data.toLowerCase():i.kind==="toUpperCase"?t.data=t.data.toUpperCase():i.kind==="startsWith"?t.data.startsWith(i.value)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{startsWith:i.value},message:i.message}),r.dirty()):i.kind==="endsWith"?t.data.endsWith(i.value)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:{endsWith:i.value},message:i.message}),r.dirty()):i.kind==="datetime"?g8(i).test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"datetime",message:i.message}),r.dirty()):i.kind==="date"?p8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"date",message:i.message}),r.dirty()):i.kind==="time"?m8(i).test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{code:Y.invalid_string,validation:"time",message:i.message}),r.dirty()):i.kind==="duration"?i8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"duration",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="ip"?b8(t.data,i.version)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"ip",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="jwt"?y8(t.data,i.alg)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"jwt",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="cidr"?x8(t.data,i.version)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"cidr",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="base64"?f8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"base64",code:Y.invalid_string,message:i.message}),r.dirty()):i.kind==="base64url"?h8.test(t.data)||(s=this._getOrReturnCtx(t,s),he(s,{validation:"base64url",code:Y.invalid_string,message:i.message}),r.dirty()):Qe.assertNever(i);return{status:r.value,value:t.data}}_regex(t,n,r){return this.refinement(s=>t.test(s),{validation:n,code:Y.invalid_string,...ge.errToObj(r)})}_addCheck(t){return new Os({...this._def,checks:[...this._def.checks,t]})}email(t){return this._addCheck({kind:"email",...ge.errToObj(t)})}url(t){return this._addCheck({kind:"url",...ge.errToObj(t)})}emoji(t){return this._addCheck({kind:"emoji",...ge.errToObj(t)})}uuid(t){return this._addCheck({kind:"uuid",...ge.errToObj(t)})}nanoid(t){return this._addCheck({kind:"nanoid",...ge.errToObj(t)})}cuid(t){return this._addCheck({kind:"cuid",...ge.errToObj(t)})}cuid2(t){return this._addCheck({kind:"cuid2",...ge.errToObj(t)})}ulid(t){return this._addCheck({kind:"ulid",...ge.errToObj(t)})}base64(t){return this._addCheck({kind:"base64",...ge.errToObj(t)})}base64url(t){return this._addCheck({kind:"base64url",...ge.errToObj(t)})}jwt(t){return this._addCheck({kind:"jwt",...ge.errToObj(t)})}ip(t){return this._addCheck({kind:"ip",...ge.errToObj(t)})}cidr(t){return this._addCheck({kind:"cidr",...ge.errToObj(t)})}datetime(t){return typeof t=="string"?this._addCheck({kind:"datetime",precision:null,offset:!1,local:!1,message:t}):this._addCheck({kind:"datetime",precision:typeof t?.precision>"u"?null:t?.precision,offset:t?.offset??!1,local:t?.local??!1,...ge.errToObj(t?.message)})}date(t){return this._addCheck({kind:"date",message:t})}time(t){return typeof t=="string"?this._addCheck({kind:"time",precision:null,message:t}):this._addCheck({kind:"time",precision:typeof t?.precision>"u"?null:t?.precision,...ge.errToObj(t?.message)})}duration(t){return this._addCheck({kind:"duration",...ge.errToObj(t)})}regex(t,n){return this._addCheck({kind:"regex",regex:t,...ge.errToObj(n)})}includes(t,n){return this._addCheck({kind:"includes",value:t,position:n?.position,...ge.errToObj(n?.message)})}startsWith(t,n){return this._addCheck({kind:"startsWith",value:t,...ge.errToObj(n)})}endsWith(t,n){return this._addCheck({kind:"endsWith",value:t,...ge.errToObj(n)})}min(t,n){return this._addCheck({kind:"min",value:t,...ge.errToObj(n)})}max(t,n){return this._addCheck({kind:"max",value:t,...ge.errToObj(n)})}length(t,n){return this._addCheck({kind:"length",value:t,...ge.errToObj(n)})}nonempty(t){return this.min(1,ge.errToObj(t))}trim(){return new Os({...this._def,checks:[...this._def.checks,{kind:"trim"}]})}toLowerCase(){return new Os({...this._def,checks:[...this._def.checks,{kind:"toLowerCase"}]})}toUpperCase(){return new Os({...this._def,checks:[...this._def.checks,{kind:"toUpperCase"}]})}get isDatetime(){return!!this._def.checks.find(t=>t.kind==="datetime")}get isDate(){return!!this._def.checks.find(t=>t.kind==="date")}get isTime(){return!!this._def.checks.find(t=>t.kind==="time")}get isDuration(){return!!this._def.checks.find(t=>t.kind==="duration")}get isEmail(){return!!this._def.checks.find(t=>t.kind==="email")}get isURL(){return!!this._def.checks.find(t=>t.kind==="url")}get isEmoji(){return!!this._def.checks.find(t=>t.kind==="emoji")}get isUUID(){return!!this._def.checks.find(t=>t.kind==="uuid")}get isNANOID(){return!!this._def.checks.find(t=>t.kind==="nanoid")}get isCUID(){return!!this._def.checks.find(t=>t.kind==="cuid")}get isCUID2(){return!!this._def.checks.find(t=>t.kind==="cuid2")}get isULID(){return!!this._def.checks.find(t=>t.kind==="ulid")}get isIP(){return!!this._def.checks.find(t=>t.kind==="ip")}get isCIDR(){return!!this._def.checks.find(t=>t.kind==="cidr")}get isBase64(){return!!this._def.checks.find(t=>t.kind==="base64")}get isBase64url(){return!!this._def.checks.find(t=>t.kind==="base64url")}get minLength(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxLength(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Os.create=e=>new Os({checks:[],typeName:De.ZodString,coerce:e?.coerce??!1,...qe(e)});function v8(e,t){const n=(e.toString().split(".")[1]||"").length,r=(t.toString().split(".")[1]||"").length,s=n>r?n:r,i=Number.parseInt(e.toFixed(s).replace(".","")),o=Number.parseInt(t.toFixed(s).replace(".",""));return i%o/10**s}class Mo extends Xe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte,this.step=this.multipleOf}_parse(t){if(this._def.coerce&&(t.data=Number(t.data)),this._getType(t)!==pe.number){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.number,received:i.parsedType}),Oe}let r;const s=new Kn;for(const i of this._def.checks)i.kind==="int"?Qe.isInteger(t.data)||(r=this._getOrReturnCtx(t,r),he(r,{code:Y.invalid_type,expected:"integer",received:"float",message:i.message}),s.dirty()):i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_small,minimum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_big,maximum:i.value,type:"number",inclusive:i.inclusive,exact:!1,message:i.message}),s.dirty()):i.kind==="multipleOf"?v8(t.data,i.value)!==0&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):i.kind==="finite"?Number.isFinite(t.data)||(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_finite,message:i.message}),s.dirty()):Qe.assertNever(i);return{status:s.value,value:t.data}}gte(t,n){return this.setLimit("min",t,!0,ge.toString(n))}gt(t,n){return this.setLimit("min",t,!1,ge.toString(n))}lte(t,n){return this.setLimit("max",t,!0,ge.toString(n))}lt(t,n){return this.setLimit("max",t,!1,ge.toString(n))}setLimit(t,n,r,s){return new Mo({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:ge.toString(s)}]})}_addCheck(t){return new Mo({...this._def,checks:[...this._def.checks,t]})}int(t){return this._addCheck({kind:"int",message:ge.toString(t)})}positive(t){return this._addCheck({kind:"min",value:0,inclusive:!1,message:ge.toString(t)})}negative(t){return this._addCheck({kind:"max",value:0,inclusive:!1,message:ge.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:0,inclusive:!0,message:ge.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:0,inclusive:!0,message:ge.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:ge.toString(n)})}finite(t){return this._addCheck({kind:"finite",message:ge.toString(t)})}safe(t){return this._addCheck({kind:"min",inclusive:!0,value:Number.MIN_SAFE_INTEGER,message:ge.toString(t)})._addCheck({kind:"max",inclusive:!0,value:Number.MAX_SAFE_INTEGER,message:ge.toString(t)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}get isInt(){return!!this._def.checks.find(t=>t.kind==="int"||t.kind==="multipleOf"&&Qe.isInteger(t.value))}get isFinite(){let t=null,n=null;for(const r of this._def.checks){if(r.kind==="finite"||r.kind==="int"||r.kind==="multipleOf")return!0;r.kind==="min"?(n===null||r.value>n)&&(n=r.value):r.kind==="max"&&(t===null||r.value<t)&&(t=r.value)}return Number.isFinite(n)&&Number.isFinite(t)}}Mo.create=e=>new Mo({checks:[],typeName:De.ZodNumber,coerce:e?.coerce||!1,...qe(e)});class Qa extends Xe{constructor(){super(...arguments),this.min=this.gte,this.max=this.lte}_parse(t){if(this._def.coerce)try{t.data=BigInt(t.data)}catch{return this._getInvalidInput(t)}if(this._getType(t)!==pe.bigint)return this._getInvalidInput(t);let r;const s=new Kn;for(const i of this._def.checks)i.kind==="min"?(i.inclusive?t.data<i.value:t.data<=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_small,type:"bigint",minimum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="max"?(i.inclusive?t.data>i.value:t.data>=i.value)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.too_big,type:"bigint",maximum:i.value,inclusive:i.inclusive,message:i.message}),s.dirty()):i.kind==="multipleOf"?t.data%i.value!==BigInt(0)&&(r=this._getOrReturnCtx(t,r),he(r,{code:Y.not_multiple_of,multipleOf:i.value,message:i.message}),s.dirty()):Qe.assertNever(i);return{status:s.value,value:t.data}}_getInvalidInput(t){const n=this._getOrReturnCtx(t);return he(n,{code:Y.invalid_type,expected:pe.bigint,received:n.parsedType}),Oe}gte(t,n){return this.setLimit("min",t,!0,ge.toString(n))}gt(t,n){return this.setLimit("min",t,!1,ge.toString(n))}lte(t,n){return this.setLimit("max",t,!0,ge.toString(n))}lt(t,n){return this.setLimit("max",t,!1,ge.toString(n))}setLimit(t,n,r,s){return new Qa({...this._def,checks:[...this._def.checks,{kind:t,value:n,inclusive:r,message:ge.toString(s)}]})}_addCheck(t){return new Qa({...this._def,checks:[...this._def.checks,t]})}positive(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!1,message:ge.toString(t)})}negative(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!1,message:ge.toString(t)})}nonpositive(t){return this._addCheck({kind:"max",value:BigInt(0),inclusive:!0,message:ge.toString(t)})}nonnegative(t){return this._addCheck({kind:"min",value:BigInt(0),inclusive:!0,message:ge.toString(t)})}multipleOf(t,n){return this._addCheck({kind:"multipleOf",value:t,message:ge.toString(n)})}get minValue(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t}get maxValue(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t}}Qa.create=e=>new Qa({checks:[],typeName:De.ZodBigInt,coerce:e?.coerce??!1,...qe(e)});class hw extends Xe{_parse(t){if(this._def.coerce&&(t.data=!!t.data),this._getType(t)!==pe.boolean){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.boolean,received:r.parsedType}),Oe}return ur(t.data)}}hw.create=e=>new hw({typeName:De.ZodBoolean,coerce:e?.coerce||!1,...qe(e)});class Ru extends Xe{_parse(t){if(this._def.coerce&&(t.data=new Date(t.data)),this._getType(t)!==pe.date){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_type,expected:pe.date,received:i.parsedType}),Oe}if(Number.isNaN(t.data.getTime())){const i=this._getOrReturnCtx(t);return he(i,{code:Y.invalid_date}),Oe}const r=new Kn;let s;for(const i of this._def.checks)i.kind==="min"?t.data.getTime()<i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_small,message:i.message,inclusive:!0,exact:!1,minimum:i.value,type:"date"}),r.dirty()):i.kind==="max"?t.data.getTime()>i.value&&(s=this._getOrReturnCtx(t,s),he(s,{code:Y.too_big,message:i.message,inclusive:!0,exact:!1,maximum:i.value,type:"date"}),r.dirty()):Qe.assertNever(i);return{status:r.value,value:new Date(t.data.getTime())}}_addCheck(t){return new Ru({...this._def,checks:[...this._def.checks,t]})}min(t,n){return this._addCheck({kind:"min",value:t.getTime(),message:ge.toString(n)})}max(t,n){return this._addCheck({kind:"max",value:t.getTime(),message:ge.toString(n)})}get minDate(){let t=null;for(const n of this._def.checks)n.kind==="min"&&(t===null||n.value>t)&&(t=n.value);return t!=null?new Date(t):null}get maxDate(){let t=null;for(const n of this._def.checks)n.kind==="max"&&(t===null||n.value<t)&&(t=n.value);return t!=null?new Date(t):null}}Ru.create=e=>new Ru({checks:[],coerce:e?.coerce||!1,typeName:De.ZodDate,...qe(e)});class pw extends Xe{_parse(t){if(this._getType(t)!==pe.symbol){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.symbol,received:r.parsedType}),Oe}return ur(t.data)}}pw.create=e=>new pw({typeName:De.ZodSymbol,...qe(e)});class Hp extends Xe{_parse(t){if(this._getType(t)!==pe.undefined){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.undefined,received:r.parsedType}),Oe}return ur(t.data)}}Hp.create=e=>new Hp({typeName:De.ZodUndefined,...qe(e)});class Vp extends Xe{_parse(t){if(this._getType(t)!==pe.null){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.null,received:r.parsedType}),Oe}return ur(t.data)}}Vp.create=e=>new Vp({typeName:De.ZodNull,...qe(e)});class qp extends Xe{constructor(){super(...arguments),this._any=!0}_parse(t){return ur(t.data)}}qp.create=e=>new qp({typeName:De.ZodAny,...qe(e)});class mw extends Xe{constructor(){super(...arguments),this._unknown=!0}_parse(t){return ur(t.data)}}mw.create=e=>new mw({typeName:De.ZodUnknown,...qe(e)});class Vs extends Xe{_parse(t){const n=this._getOrReturnCtx(t);return he(n,{code:Y.invalid_type,expected:pe.never,received:n.parsedType}),Oe}}Vs.create=e=>new Vs({typeName:De.ZodNever,...qe(e)});class gw extends Xe{_parse(t){if(this._getType(t)!==pe.undefined){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.void,received:r.parsedType}),Oe}return ur(t.data)}}gw.create=e=>new gw({typeName:De.ZodVoid,...qe(e)});class Ir extends Xe{_parse(t){const{ctx:n,status:r}=this._processInputParams(t),s=this._def;if(n.parsedType!==pe.array)return he(n,{code:Y.invalid_type,expected:pe.array,received:n.parsedType}),Oe;if(s.exactLength!==null){const o=n.data.length>s.exactLength.value,a=n.data.length<s.exactLength.value;(o||a)&&(he(n,{code:o?Y.too_big:Y.too_small,minimum:a?s.exactLength.value:void 0,maximum:o?s.exactLength.value:void 0,type:"array",inclusive:!0,exact:!0,message:s.exactLength.message}),r.dirty())}if(s.minLength!==null&&n.data.length<s.minLength.value&&(he(n,{code:Y.too_small,minimum:s.minLength.value,type:"array",inclusive:!0,exact:!1,message:s.minLength.message}),r.dirty()),s.maxLength!==null&&n.data.length>s.maxLength.value&&(he(n,{code:Y.too_big,maximum:s.maxLength.value,type:"array",inclusive:!0,exact:!1,message:s.maxLength.message}),r.dirty()),n.common.async)return Promise.all([...n.data].map((o,a)=>s.type._parseAsync(new Hs(n,o,n.path,a)))).then(o=>Kn.mergeArray(r,o));const i=[...n.data].map((o,a)=>s.type._parseSync(new Hs(n,o,n.path,a)));return Kn.mergeArray(r,i)}get element(){return this._def.type}min(t,n){return new Ir({...this._def,minLength:{value:t,message:ge.toString(n)}})}max(t,n){return new Ir({...this._def,maxLength:{value:t,message:ge.toString(n)}})}length(t,n){return new Ir({...this._def,exactLength:{value:t,message:ge.toString(n)}})}nonempty(t){return this.min(1,t)}}Ir.create=(e,t)=>new Ir({type:e,minLength:null,maxLength:null,exactLength:null,typeName:De.ZodArray,...qe(t)});function no(e){if(e instanceof zt){const t={};for(const n in e.shape){const r=e.shape[n];t[n]=Qr.create(no(r))}return new zt({...e._def,shape:()=>t})}else return e instanceof Ir?new Ir({...e._def,type:no(e.element)}):e instanceof Qr?Qr.create(no(e.unwrap())):e instanceof Fi?Fi.create(no(e.unwrap())):e instanceof Pi?Pi.create(e.items.map(t=>no(t))):e}class zt extends Xe{constructor(){super(...arguments),this._cached=null,this.nonstrict=this.passthrough,this.augment=this.extend}_getCached(){if(this._cached!==null)return this._cached;const t=this._def.shape(),n=Qe.objectKeys(t);return this._cached={shape:t,keys:n},this._cached}_parse(t){if(this._getType(t)!==pe.object){const c=this._getOrReturnCtx(t);return he(c,{code:Y.invalid_type,expected:pe.object,received:c.parsedType}),Oe}const{status:r,ctx:s}=this._processInputParams(t),{shape:i,keys:o}=this._getCached(),a=[];if(!(this._def.catchall instanceof Vs&&this._def.unknownKeys==="strip"))for(const c in s.data)o.includes(c)||a.push(c);const l=[];for(const c of o){const u=i[c],d=s.data[c];l.push({key:{status:"valid",value:c},value:u._parse(new Hs(s,d,s.path,c)),alwaysSet:c in s.data})}if(this._def.catchall instanceof Vs){const c=this._def.unknownKeys;if(c==="passthrough")for(const u of a)l.push({key:{status:"valid",value:u},value:{status:"valid",value:s.data[u]}});else if(c==="strict")a.length>0&&(he(s,{code:Y.unrecognized_keys,keys:a}),r.dirty());else if(c!=="strip")throw new Error("Internal ZodObject error: invalid unknownKeys value.")}else{const c=this._def.catchall;for(const u of a){const d=s.data[u];l.push({key:{status:"valid",value:u},value:c._parse(new Hs(s,d,s.path,u)),alwaysSet:u in s.data})}}return s.common.async?Promise.resolve().then(async()=>{const c=[];for(const u of l){const d=await u.key,f=await u.value;c.push({key:d,value:f,alwaysSet:u.alwaysSet})}return c}).then(c=>Kn.mergeObjectSync(r,c)):Kn.mergeObjectSync(r,l)}get shape(){return this._def.shape()}strict(t){return ge.errToObj,new zt({...this._def,unknownKeys:"strict",...t!==void 0?{errorMap:(n,r)=>{const s=this._def.errorMap?.(n,r).message??r.defaultError;return n.code==="unrecognized_keys"?{message:ge.errToObj(t).message??s}:{message:s}}}:{}})}strip(){return new zt({...this._def,unknownKeys:"strip"})}passthrough(){return new zt({...this._def,unknownKeys:"passthrough"})}extend(t){return new zt({...this._def,shape:()=>({...this._def.shape(),...t})})}merge(t){return new zt({unknownKeys:t._def.unknownKeys,catchall:t._def.catchall,shape:()=>({...this._def.shape(),...t._def.shape()}),typeName:De.ZodObject})}setKey(t,n){return this.augment({[t]:n})}catchall(t){return new zt({...this._def,catchall:t})}pick(t){const n={};for(const r of Qe.objectKeys(t))t[r]&&this.shape[r]&&(n[r]=this.shape[r]);return new zt({...this._def,shape:()=>n})}omit(t){const n={};for(const r of Qe.objectKeys(this.shape))t[r]||(n[r]=this.shape[r]);return new zt({...this._def,shape:()=>n})}deepPartial(){return no(this)}partial(t){const n={};for(const r of Qe.objectKeys(this.shape)){const s=this.shape[r];t&&!t[r]?n[r]=s:n[r]=s.optional()}return new zt({...this._def,shape:()=>n})}required(t){const n={};for(const r of Qe.objectKeys(this.shape))if(t&&!t[r])n[r]=this.shape[r];else{let i=this.shape[r];for(;i instanceof Qr;)i=i._def.innerType;n[r]=i}return new zt({...this._def,shape:()=>n})}keyof(){return E_(Qe.objectKeys(this.shape))}}zt.create=(e,t)=>new zt({shape:()=>e,unknownKeys:"strip",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});zt.strictCreate=(e,t)=>new zt({shape:()=>e,unknownKeys:"strict",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});zt.lazycreate=(e,t)=>new zt({shape:e,unknownKeys:"strip",catchall:Vs.create(),typeName:De.ZodObject,...qe(t)});class Ou extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r=this._def.options;function s(i){for(const a of i)if(a.result.status==="valid")return a.result;for(const a of i)if(a.result.status==="dirty")return n.common.issues.push(...a.ctx.common.issues),a.result;const o=i.map(a=>new ts(a.ctx.common.issues));return he(n,{code:Y.invalid_union,unionErrors:o}),Oe}if(n.common.async)return Promise.all(r.map(async i=>{const o={...n,common:{...n.common,issues:[]},parent:null};return{result:await i._parseAsync({data:n.data,path:n.path,parent:o}),ctx:o}})).then(s);{let i;const o=[];for(const l of r){const c={...n,common:{...n.common,issues:[]},parent:null},u=l._parseSync({data:n.data,path:n.path,parent:c});if(u.status==="valid")return u;u.status==="dirty"&&!i&&(i={result:u,ctx:c}),c.common.issues.length&&o.push(c.common.issues)}if(i)return n.common.issues.push(...i.ctx.common.issues),i.result;const a=o.map(l=>new ts(l));return he(n,{code:Y.invalid_union,unionErrors:a}),Oe}}get options(){return this._def.options}}Ou.create=(e,t)=>new Ou({options:e,typeName:De.ZodUnion,...qe(t)});const Kr=e=>e instanceof Kp?Kr(e.schema):e instanceof zi?Kr(e.innerType()):e instanceof Du?[e.value]:e instanceof ji?e.options:e instanceof Lu?Qe.objectValues(e.enum):e instanceof ju?Kr(e._def.innerType):e instanceof Hp?[void 0]:e instanceof Vp?[null]:e instanceof Qr?[void 0,...Kr(e.unwrap())]:e instanceof Fi?[null,...Kr(e.unwrap())]:e instanceof C_||e instanceof Fu?Kr(e.unwrap()):e instanceof zu?Kr(e._def.innerType):[];class Wg extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==pe.object)return he(n,{code:Y.invalid_type,expected:pe.object,received:n.parsedType}),Oe;const r=this.discriminator,s=n.data[r],i=this.optionsMap.get(s);return i?n.common.async?i._parseAsync({data:n.data,path:n.path,parent:n}):i._parseSync({data:n.data,path:n.path,parent:n}):(he(n,{code:Y.invalid_union_discriminator,options:Array.from(this.optionsMap.keys()),path:[r]}),Oe)}get discriminator(){return this._def.discriminator}get options(){return this._def.options}get optionsMap(){return this._def.optionsMap}static create(t,n,r){const s=new Map;for(const i of n){const o=Kr(i.shape[t]);if(!o.length)throw new Error(`A discriminator value for key \`${t}\` could not be extracted from all schema options`);for(const a of o){if(s.has(a))throw new Error(`Discriminator property ${String(t)} has duplicate value ${String(a)}`);s.set(a,i)}}return new Wg({typeName:De.ZodDiscriminatedUnion,discriminator:t,options:n,optionsMap:s,...qe(r)})}}function Wp(e,t){const n=ks(e),r=ks(t);if(e===t)return{valid:!0,data:e};if(n===pe.object&&r===pe.object){const s=Qe.objectKeys(t),i=Qe.objectKeys(e).filter(a=>s.indexOf(a)!==-1),o={...e,...t};for(const a of i){const l=Wp(e[a],t[a]);if(!l.valid)return{valid:!1};o[a]=l.data}return{valid:!0,data:o}}else if(n===pe.array&&r===pe.array){if(e.length!==t.length)return{valid:!1};const s=[];for(let i=0;i<e.length;i++){const o=e[i],a=t[i],l=Wp(o,a);if(!l.valid)return{valid:!1};s.push(l.data)}return{valid:!0,data:s}}else return n===pe.date&&r===pe.date&&+e==+t?{valid:!0,data:e}:{valid:!1}}class Iu extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=(i,o)=>{if(uw(i)||uw(o))return Oe;const a=Wp(i.value,o.value);return a.valid?((dw(i)||dw(o))&&n.dirty(),{status:n.value,value:a.data}):(he(r,{code:Y.invalid_intersection_types}),Oe)};return r.common.async?Promise.all([this._def.left._parseAsync({data:r.data,path:r.path,parent:r}),this._def.right._parseAsync({data:r.data,path:r.path,parent:r})]).then(([i,o])=>s(i,o)):s(this._def.left._parseSync({data:r.data,path:r.path,parent:r}),this._def.right._parseSync({data:r.data,path:r.path,parent:r}))}}Iu.create=(e,t,n)=>new Iu({left:e,right:t,typeName:De.ZodIntersection,...qe(n)});class Pi extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.array)return he(r,{code:Y.invalid_type,expected:pe.array,received:r.parsedType}),Oe;if(r.data.length<this._def.items.length)return he(r,{code:Y.too_small,minimum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),Oe;!this._def.rest&&r.data.length>this._def.items.length&&(he(r,{code:Y.too_big,maximum:this._def.items.length,inclusive:!0,exact:!1,type:"array"}),n.dirty());const i=[...r.data].map((o,a)=>{const l=this._def.items[a]||this._def.rest;return l?l._parse(new Hs(r,o,r.path,a)):null}).filter(o=>!!o);return r.common.async?Promise.all(i).then(o=>Kn.mergeArray(n,o)):Kn.mergeArray(n,i)}get items(){return this._def.items}rest(t){return new Pi({...this._def,rest:t})}}Pi.create=(e,t)=>{if(!Array.isArray(e))throw new Error("You must pass an array of schemas to z.tuple([ ... ])");return new Pi({items:e,typeName:De.ZodTuple,rest:null,...qe(t)})};class bw extends Xe{get keySchema(){return this._def.keyType}get valueSchema(){return this._def.valueType}_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.map)return he(r,{code:Y.invalid_type,expected:pe.map,received:r.parsedType}),Oe;const s=this._def.keyType,i=this._def.valueType,o=[...r.data.entries()].map(([a,l],c)=>({key:s._parse(new Hs(r,a,r.path,[c,"key"])),value:i._parse(new Hs(r,l,r.path,[c,"value"]))}));if(r.common.async){const a=new Map;return Promise.resolve().then(async()=>{for(const l of o){const c=await l.key,u=await l.value;if(c.status==="aborted"||u.status==="aborted")return Oe;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}})}else{const a=new Map;for(const l of o){const c=l.key,u=l.value;if(c.status==="aborted"||u.status==="aborted")return Oe;(c.status==="dirty"||u.status==="dirty")&&n.dirty(),a.set(c.value,u.value)}return{status:n.value,value:a}}}}bw.create=(e,t,n)=>new bw({valueType:t,keyType:e,typeName:De.ZodMap,...qe(n)});class el extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.parsedType!==pe.set)return he(r,{code:Y.invalid_type,expected:pe.set,received:r.parsedType}),Oe;const s=this._def;s.minSize!==null&&r.data.size<s.minSize.value&&(he(r,{code:Y.too_small,minimum:s.minSize.value,type:"set",inclusive:!0,exact:!1,message:s.minSize.message}),n.dirty()),s.maxSize!==null&&r.data.size>s.maxSize.value&&(he(r,{code:Y.too_big,maximum:s.maxSize.value,type:"set",inclusive:!0,exact:!1,message:s.maxSize.message}),n.dirty());const i=this._def.valueType;function o(l){const c=new Set;for(const u of l){if(u.status==="aborted")return Oe;u.status==="dirty"&&n.dirty(),c.add(u.value)}return{status:n.value,value:c}}const a=[...r.data.values()].map((l,c)=>i._parse(new Hs(r,l,r.path,c)));return r.common.async?Promise.all(a).then(l=>o(l)):o(a)}min(t,n){return new el({...this._def,minSize:{value:t,message:ge.toString(n)}})}max(t,n){return new el({...this._def,maxSize:{value:t,message:ge.toString(n)}})}size(t,n){return this.min(t,n).max(t,n)}nonempty(t){return this.min(1,t)}}el.create=(e,t)=>new el({valueType:e,minSize:null,maxSize:null,typeName:De.ZodSet,...qe(t)});class Kp extends Xe{get schema(){return this._def.getter()}_parse(t){const{ctx:n}=this._processInputParams(t);return this._def.getter()._parse({data:n.data,path:n.path,parent:n})}}Kp.create=(e,t)=>new Kp({getter:e,typeName:De.ZodLazy,...qe(t)});class Du extends Xe{_parse(t){if(t.data!==this._def.value){const n=this._getOrReturnCtx(t);return he(n,{received:n.data,code:Y.invalid_literal,expected:this._def.value}),Oe}return{status:"valid",value:t.data}}get value(){return this._def.value}}Du.create=(e,t)=>new Du({value:e,typeName:De.ZodLiteral,...qe(t)});function E_(e,t){return new ji({values:e,typeName:De.ZodEnum,...qe(t)})}class ji extends Xe{_parse(t){if(typeof t.data!="string"){const n=this._getOrReturnCtx(t),r=this._def.values;return he(n,{expected:Qe.joinValues(r),received:n.parsedType,code:Y.invalid_type}),Oe}if(this._cache||(this._cache=new Set(this._def.values)),!this._cache.has(t.data)){const n=this._getOrReturnCtx(t),r=this._def.values;return he(n,{received:n.data,code:Y.invalid_enum_value,options:r}),Oe}return ur(t.data)}get options(){return this._def.values}get enum(){const t={};for(const n of this._def.values)t[n]=n;return t}get Values(){const t={};for(const n of this._def.values)t[n]=n;return t}get Enum(){const t={};for(const n of this._def.values)t[n]=n;return t}extract(t,n=this._def){return ji.create(t,{...this._def,...n})}exclude(t,n=this._def){return ji.create(this.options.filter(r=>!t.includes(r)),{...this._def,...n})}}ji.create=E_;class Lu extends Xe{_parse(t){const n=Qe.getValidEnumValues(this._def.values),r=this._getOrReturnCtx(t);if(r.parsedType!==pe.string&&r.parsedType!==pe.number){const s=Qe.objectValues(n);return he(r,{expected:Qe.joinValues(s),received:r.parsedType,code:Y.invalid_type}),Oe}if(this._cache||(this._cache=new Set(Qe.getValidEnumValues(this._def.values))),!this._cache.has(t.data)){const s=Qe.objectValues(n);return he(r,{received:r.data,code:Y.invalid_enum_value,options:s}),Oe}return ur(t.data)}get enum(){return this._def.values}}Lu.create=(e,t)=>new Lu({values:e,typeName:De.ZodNativeEnum,...qe(t)});class Pu extends Xe{unwrap(){return this._def.type}_parse(t){const{ctx:n}=this._processInputParams(t);if(n.parsedType!==pe.promise&&n.common.async===!1)return he(n,{code:Y.invalid_type,expected:pe.promise,received:n.parsedType}),Oe;const r=n.parsedType===pe.promise?n.data:Promise.resolve(n.data);return ur(r.then(s=>this._def.type.parseAsync(s,{path:n.path,errorMap:n.common.contextualErrorMap})))}}Pu.create=(e,t)=>new Pu({type:e,typeName:De.ZodPromise,...qe(t)});class zi extends Xe{innerType(){return this._def.schema}sourceType(){return this._def.schema._def.typeName===De.ZodEffects?this._def.schema.sourceType():this._def.schema}_parse(t){const{status:n,ctx:r}=this._processInputParams(t),s=this._def.effect||null,i={addIssue:o=>{he(r,o),o.fatal?n.abort():n.dirty()},get path(){return r.path}};if(i.addIssue=i.addIssue.bind(i),s.type==="preprocess"){const o=s.transform(r.data,i);if(r.common.async)return Promise.resolve(o).then(async a=>{if(n.value==="aborted")return Oe;const l=await this._def.schema._parseAsync({data:a,path:r.path,parent:r});return l.status==="aborted"?Oe:l.status==="dirty"||n.value==="dirty"?ua(l.value):l});{if(n.value==="aborted")return Oe;const a=this._def.schema._parseSync({data:o,path:r.path,parent:r});return a.status==="aborted"?Oe:a.status==="dirty"||n.value==="dirty"?ua(a.value):a}}if(s.type==="refinement"){const o=a=>{const l=s.refinement(a,i);if(r.common.async)return Promise.resolve(l);if(l instanceof Promise)throw new Error("Async refinement encountered during synchronous parse operation. Use .parseAsync instead.");return a};if(r.common.async===!1){const a=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});return a.status==="aborted"?Oe:(a.status==="dirty"&&n.dirty(),o(a.value),{status:n.value,value:a.value})}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(a=>a.status==="aborted"?Oe:(a.status==="dirty"&&n.dirty(),o(a.value).then(()=>({status:n.value,value:a.value}))))}if(s.type==="transform")if(r.common.async===!1){const o=this._def.schema._parseSync({data:r.data,path:r.path,parent:r});if(!Ao(o))return Oe;const a=s.transform(o.value,i);if(a instanceof Promise)throw new Error("Asynchronous transform encountered during synchronous parse operation. Use .parseAsync instead.");return{status:n.value,value:a}}else return this._def.schema._parseAsync({data:r.data,path:r.path,parent:r}).then(o=>Ao(o)?Promise.resolve(s.transform(o.value,i)).then(a=>({status:n.value,value:a})):Oe);Qe.assertNever(s)}}zi.create=(e,t,n)=>new zi({schema:e,typeName:De.ZodEffects,effect:t,...qe(n)});zi.createWithPreprocess=(e,t,n)=>new zi({schema:t,effect:{type:"preprocess",transform:e},typeName:De.ZodEffects,...qe(n)});class Qr extends Xe{_parse(t){return this._getType(t)===pe.undefined?ur(void 0):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Qr.create=(e,t)=>new Qr({innerType:e,typeName:De.ZodOptional,...qe(t)});class Fi extends Xe{_parse(t){return this._getType(t)===pe.null?ur(null):this._def.innerType._parse(t)}unwrap(){return this._def.innerType}}Fi.create=(e,t)=>new Fi({innerType:e,typeName:De.ZodNullable,...qe(t)});class ju extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t);let r=n.data;return n.parsedType===pe.undefined&&(r=this._def.defaultValue()),this._def.innerType._parse({data:r,path:n.path,parent:n})}removeDefault(){return this._def.innerType}}ju.create=(e,t)=>new ju({innerType:e,typeName:De.ZodDefault,defaultValue:typeof t.default=="function"?t.default:()=>t.default,...qe(t)});class zu extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r={...n,common:{...n.common,issues:[]}},s=this._def.innerType._parse({data:r.data,path:r.path,parent:{...r}});return Mu(s)?s.then(i=>({status:"valid",value:i.status==="valid"?i.value:this._def.catchValue({get error(){return new ts(r.common.issues)},input:r.data})})):{status:"valid",value:s.status==="valid"?s.value:this._def.catchValue({get error(){return new ts(r.common.issues)},input:r.data})}}removeCatch(){return this._def.innerType}}zu.create=(e,t)=>new zu({innerType:e,typeName:De.ZodCatch,catchValue:typeof t.catch=="function"?t.catch:()=>t.catch,...qe(t)});class yw extends Xe{_parse(t){if(this._getType(t)!==pe.nan){const r=this._getOrReturnCtx(t);return he(r,{code:Y.invalid_type,expected:pe.nan,received:r.parsedType}),Oe}return{status:"valid",value:t.data}}}yw.create=e=>new yw({typeName:De.ZodNaN,...qe(e)});class C_ extends Xe{_parse(t){const{ctx:n}=this._processInputParams(t),r=n.data;return this._def.type._parse({data:r,path:n.path,parent:n})}unwrap(){return this._def.type}}class Kg extends Xe{_parse(t){const{status:n,ctx:r}=this._processInputParams(t);if(r.common.async)return(async()=>{const i=await this._def.in._parseAsync({data:r.data,path:r.path,parent:r});return i.status==="aborted"?Oe:i.status==="dirty"?(n.dirty(),ua(i.value)):this._def.out._parseAsync({data:i.value,path:r.path,parent:r})})();{const s=this._def.in._parseSync({data:r.data,path:r.path,parent:r});return s.status==="aborted"?Oe:s.status==="dirty"?(n.dirty(),{status:"dirty",value:s.value}):this._def.out._parseSync({data:s.value,path:r.path,parent:r})}}static create(t,n){return new Kg({in:t,out:n,typeName:De.ZodPipeline})}}class Fu extends Xe{_parse(t){const n=this._def.innerType._parse(t),r=s=>(Ao(s)&&(s.value=Object.freeze(s.value)),s);return Mu(n)?n.then(s=>r(s)):r(n)}unwrap(){return this._def.innerType}}Fu.create=(e,t)=>new Fu({innerType:e,typeName:De.ZodReadonly,...qe(t)});var De;(function(e){e.ZodString="ZodString",e.ZodNumber="ZodNumber",e.ZodNaN="ZodNaN",e.ZodBigInt="ZodBigInt",e.ZodBoolean="ZodBoolean",e.ZodDate="ZodDate",e.ZodSymbol="ZodSymbol",e.ZodUndefined="ZodUndefined",e.ZodNull="ZodNull",e.ZodAny="ZodAny",e.ZodUnknown="ZodUnknown",e.ZodNever="ZodNever",e.ZodVoid="ZodVoid",e.ZodArray="ZodArray",e.ZodObject="ZodObject",e.ZodUnion="ZodUnion",e.ZodDiscriminatedUnion="ZodDiscriminatedUnion",e.ZodIntersection="ZodIntersection",e.ZodTuple="ZodTuple",e.ZodRecord="ZodRecord",e.ZodMap="ZodMap",e.ZodSet="ZodSet",e.ZodFunction="ZodFunction",e.ZodLazy="ZodLazy",e.ZodLiteral="ZodLiteral",e.ZodEnum="ZodEnum",e.ZodEffects="ZodEffects",e.ZodNativeEnum="ZodNativeEnum",e.ZodOptional="ZodOptional",e.ZodNullable="ZodNullable",e.ZodDefault="ZodDefault",e.ZodCatch="ZodCatch",e.ZodPromise="ZodPromise",e.ZodBranded="ZodBranded",e.ZodPipeline="ZodPipeline",e.ZodReadonly="ZodReadonly"})(De||(De={}));const Ae=Os.create,w8=Mo.create,ns=qp.create;Vs.create;const yo=Ir.create,ei=zt.create,N_=Ou.create,__=Wg.create;Iu.create;Pi.create;const He=Du.create;ji.create;const k8=Lu.create;Pu.create;Qr.create;Fi.create;var S8=ei({name:Ae(),arguments:Ae()}),E8=ei({id:Ae(),type:He("function"),function:S8}),Kd=ei({id:Ae(),role:Ae(),content:Ae().optional(),name:Ae().optional()}),C8=Kd.extend({role:He("developer"),content:Ae()}),N8=Kd.extend({role:He("system"),content:Ae()}),_8=Kd.extend({role:He("assistant"),content:Ae().optional(),toolCalls:yo(E8).optional()}),T8=Kd.extend({role:He("user"),content:Ae()}),A8=ei({id:Ae(),content:Ae(),role:He("tool"),toolCallId:Ae(),error:Ae().optional()}),T_=__("role",[C8,N8,_8,T8,A8]);N_([He("developer"),He("system"),He("assistant"),He("user"),He("tool")]);var M8=ei({description:Ae(),value:Ae()}),R8=ei({name:Ae(),description:Ae(),parameters:ns()});ei({threadId:Ae(),runId:Ae(),state:ns(),messages:yo(T_),tools:yo(R8),context:yo(M8),forwardedProps:ns()});var O8=ns(),A_=N_([He("developer"),He("system"),He("assistant"),He("user")]),ln=(e=>(e.TEXT_MESSAGE_START="TEXT_MESSAGE_START",e.TEXT_MESSAGE_CONTENT="TEXT_MESSAGE_CONTENT",e.TEXT_MESSAGE_END="TEXT_MESSAGE_END",e.TEXT_MESSAGE_CHUNK="TEXT_MESSAGE_CHUNK",e.THINKING_TEXT_MESSAGE_START="THINKING_TEXT_MESSAGE_START",e.THINKING_TEXT_MESSAGE_CONTENT="THINKING_TEXT_MESSAGE_CONTENT",e.THINKING_TEXT_MESSAGE_END="THINKING_TEXT_MESSAGE_END",e.TOOL_CALL_START="TOOL_CALL_START",e.TOOL_CALL_ARGS="TOOL_CALL_ARGS",e.TOOL_CALL_END="TOOL_CALL_END",e.TOOL_CALL_CHUNK="TOOL_CALL_CHUNK",e.TOOL_CALL_RESULT="TOOL_CALL_RESULT",e.THINKING_START="THINKING_START",e.THINKING_END="THINKING_END",e.STATE_SNAPSHOT="STATE_SNAPSHOT",e.STATE_DELTA="STATE_DELTA",e.MESSAGES_SNAPSHOT="MESSAGES_SNAPSHOT",e.RAW="RAW",e.CUSTOM="CUSTOM",e.RUN_STARTED="RUN_STARTED",e.RUN_FINISHED="RUN_FINISHED",e.RUN_ERROR="RUN_ERROR",e.STEP_STARTED="STEP_STARTED",e.STEP_FINISHED="STEP_FINISHED",e))(ln||{}),Tt=ei({type:k8(ln),timestamp:w8().optional(),rawEvent:ns().optional()}),I8=Tt.extend({type:He("TEXT_MESSAGE_START"),messageId:Ae(),role:A_.default("assistant")}),M_=Tt.extend({type:He("TEXT_MESSAGE_CONTENT"),messageId:Ae(),delta:Ae().refine(e=>e.length>0,"Delta must not be an empty string")}),D8=Tt.extend({type:He("TEXT_MESSAGE_END"),messageId:Ae()}),L8=Tt.extend({type:He("TEXT_MESSAGE_CHUNK"),messageId:Ae().optional(),role:A_.optional(),delta:Ae().optional()}),P8=Tt.extend({type:He("THINKING_TEXT_MESSAGE_START")}),j8=M_.omit({messageId:!0,type:!0}).extend({type:He("THINKING_TEXT_MESSAGE_CONTENT")}),z8=Tt.extend({type:He("THINKING_TEXT_MESSAGE_END")}),F8=Tt.extend({type:He("TOOL_CALL_START"),toolCallId:Ae(),toolCallName:Ae(),parentMessageId:Ae().optional()}),B8=Tt.extend({type:He("TOOL_CALL_ARGS"),toolCallId:Ae(),delta:Ae()}),$8=Tt.extend({type:He("TOOL_CALL_END"),toolCallId:Ae()}),U8=Tt.extend({messageId:Ae(),type:He("TOOL_CALL_RESULT"),toolCallId:Ae(),content:Ae(),role:He("tool").optional()}),H8=Tt.extend({type:He("TOOL_CALL_CHUNK"),toolCallId:Ae().optional(),toolCallName:Ae().optional(),parentMessageId:Ae().optional(),delta:Ae().optional()}),V8=Tt.extend({type:He("THINKING_START"),title:Ae().optional()}),q8=Tt.extend({type:He("THINKING_END")}),W8=Tt.extend({type:He("STATE_SNAPSHOT"),snapshot:O8}),K8=Tt.extend({type:He("STATE_DELTA"),delta:yo(ns())}),G8=Tt.extend({type:He("MESSAGES_SNAPSHOT"),messages:yo(T_)}),J8=Tt.extend({type:He("RAW"),event:ns(),source:Ae().optional()}),Z8=Tt.extend({type:He("CUSTOM"),name:Ae(),value:ns()}),Y8=Tt.extend({type:He("RUN_STARTED"),threadId:Ae(),runId:Ae()}),X8=Tt.extend({type:He("RUN_FINISHED"),threadId:Ae(),runId:Ae(),result:ns().optional()}),Q8=Tt.extend({type:He("RUN_ERROR"),message:Ae(),code:Ae().optional()}),e7=Tt.extend({type:He("STEP_STARTED"),stepName:Ae()}),t7=Tt.extend({type:He("STEP_FINISHED"),stepName:Ae()});__("type",[I8,M_,D8,L8,V8,q8,P8,j8,z8,F8,B8,$8,H8,U8,W8,K8,G8,J8,Z8,Y8,X8,Q8,e7,t7]);function n7(e){const{executionId:t,autoConnect:n=!0,reconnectOnError:r=!1,endpoint:s,onEvent:i}=e,[o,a]=x.useState("idle"),[l,c]=x.useState({runId:null,threadId:null,status:"idle",currentStep:null,error:null,startTime:null,endTime:null}),[u,d]=x.useState(new Map),[f,p]=x.useState(new Map),[m,g]=x.useState({}),[b,y]=x.useState(null),w=x.useRef(null),v=x.useRef(null),E=x.useRef(i),N=x.useRef(!1);x.useEffect(()=>{E.current=i},[i]);const k=x.useCallback(S=>{c(B=>({...B,runId:S.runId,threadId:S.threadId,status:"running",startTime:S.timestamp||Date.now()})),E.current?.onRunStarted?.(S)},[]),C=x.useCallback(S=>{c(B=>({...B,status:"completed",endTime:S.timestamp||Date.now()})),E.current?.onRunFinished?.(S),N.current=!0,w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),A=x.useCallback(S=>{c(B=>({...B,status:"error",error:S.message,endTime:S.timestamp||Date.now()})),y(new Error(S.message)),E.current?.onRunError?.(S),N.current=!0,w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),R=x.useCallback(S=>{c(B=>({...B,currentStep:S.stepName})),E.current?.onStepStarted?.(S)},[]),T=x.useCallback(S=>{E.current?.onStepFinished?.(S)},[]),I=x.useCallback(S=>{d(B=>{const $=new Map(B);return $.set(S.messageId,{messageId:S.messageId,role:S.role||"assistant",content:"",complete:!1,timestamp:S.timestamp||Date.now()}),$})},[]),O=x.useCallback(S=>{d(B=>{const $=new Map(B),D=$.get(S.messageId);if(D){const P={...D,content:D.content+S.delta};$.set(S.messageId,P),E.current?.onMessage?.(P)}return $})},[]),j=x.useCallback(S=>{d(B=>{const $=new Map(B),D=$.get(S.messageId);if(D){const P={...D,complete:!0};$.set(S.messageId,P),E.current?.onMessage?.(P)}return $})},[]),L=x.useCallback(S=>{p(B=>{const $=new Map(B);return $.set(S.toolCallId,{toolCallId:S.toolCallId,toolCallName:S.toolCallName,args:"",status:"started",startTime:S.timestamp||Date.now()}),$}),E.current?.onToolCallStart?.(S)},[]),F=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,args:D.args+S.delta,status:"executing"}),$})},[]),q=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,endTime:S.timestamp||Date.now()}),$}),E.current?.onToolCallEnd?.(S)},[]),te=x.useCallback(S=>{p(B=>{const $=new Map(B),D=$.get(S.toolCallId);return D&&$.set(S.toolCallId,{...D,result:S.content,status:"completed"}),$})},[]),K=x.useCallback(S=>{g(S.snapshot),E.current?.onStateUpdate?.(S.snapshot)},[]),le=x.useCallback(S=>{g(B=>{let $={...B};for(const D of S.delta)if(D.op==="replace"){const P=D.path.slice(1);$={...$,[P]:D.value}}else if(D.op==="add"){const P=D.path.slice(1);$={...$,[P]:D.value}}return E.current?.onStateUpdate?.($),$})},[]),_=x.useCallback(()=>{if(N.current){console.debug("[SSE] Skipping connection - execution already completed");return}if(w.current){console.warn("EventSource already connected");return}const S=s||`/api/executions/${t}/stream`;console.debug("[SSE]. Connecting to SSE stream",{executionId:t,url:S,timestamp:new Date().toISOString()}),a("connecting"),y(null);try{const B=new EventSource(S);w.current=B,B.onopen=()=>{console.debug("[SSE]. SSE connection established",{executionId:t,timestamp:new Date().toISOString()}),a("connected")},B.onerror=$=>{if(console.error("EventSource error:",$),N.current){ae();return}a("error"),y(new Error("SSE connection error")),r&&v.current===null&&(console.debug("[SSE] Reconnecting in 3 seconds..."),v.current=setTimeout(()=>{v.current=null,ae(),_()},3e3))},B.addEventListener(ln.RUN_STARTED,$=>{k(JSON.parse($.data))}),B.addEventListener(ln.RUN_FINISHED,$=>{C(JSON.parse($.data))}),B.addEventListener(ln.RUN_ERROR,$=>{A(JSON.parse($.data))}),B.addEventListener(ln.STEP_STARTED,$=>{R(JSON.parse($.data))}),B.addEventListener(ln.STEP_FINISHED,$=>{T(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_START,$=>{I(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_CONTENT,$=>{O(JSON.parse($.data))}),B.addEventListener(ln.TEXT_MESSAGE_END,$=>{j(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_START,$=>{L(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_ARGS,$=>{F(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_END,$=>{q(JSON.parse($.data))}),B.addEventListener(ln.TOOL_CALL_RESULT,$=>{te(JSON.parse($.data))}),B.addEventListener(ln.STATE_SNAPSHOT,$=>{K(JSON.parse($.data))}),B.addEventListener(ln.STATE_DELTA,$=>{le(JSON.parse($.data))})}catch(B){console.error("Failed to create EventSource:",B),a("error"),y(B instanceof Error?B:new Error("Unknown error"))}},[t,s,r,k,C,A,R,T,I,O,j,L,F,q,te,K,le]),ae=x.useCallback(()=>{v.current&&(clearTimeout(v.current),v.current=null),w.current&&(w.current.close(),w.current=null,a("disconnected"))},[]),me=x.useCallback(()=>{N.current=!1,ae(),_()},[ae,_]);return x.useEffect(()=>(n&&_(),()=>{v.current&&(clearTimeout(v.current),v.current=null),w.current&&(w.current.close(),w.current=null,a("disconnected"))}),[n,t]),{connectionStatus:o,execution:l,messages:u,toolCalls:f,state:m,error:b,connect:_,disconnect:ae,reconnect:me,isConnected:o==="connected"}}function r7(e,t){const n=[],r=Date.now();switch(e.type){case"assistant":{const s=e.message?.content||[];for(const i of s)if(i.type==="text"&&i.text)n.push({type:"CUSTOM",timestamp:r,name:"TEXT_MESSAGE_CONTENT",value:{content:i.text}});else if(i.type==="tool_use"){const o=i.id||`tool-${Date.now()}`;n.push({type:"TOOL_CALL_START",timestamp:r,toolCallId:o,toolCallName:i.name||"unknown"},{type:"TOOL_CALL_ARGS",timestamp:r,toolCallId:o,delta:JSON.stringify(i.input||{})})}break}case"tool_result":{const s=e.result?.tool_use_id||"unknown",o=(e.result?.content||[]).find(a=>a.type==="text")?.text||"";n.push({type:"TOOL_CALL_END",timestamp:r,toolCallId:s},{type:"TOOL_CALL_RESULT",timestamp:r,messageId:`msg-${s}`,toolCallId:s,content:o});break}case"result":{if(e.usage){const s=e.usage;n.push({type:"CUSTOM",timestamp:r,name:"USAGE_UPDATE",value:{inputTokens:s.input_tokens||0,outputTokens:s.output_tokens||0,cacheTokens:s.cache_read_input_tokens||0,totalTokens:(s.input_tokens||0)+(s.output_tokens||0)}})}break}case"error":{n.push({type:"RUN_ERROR",timestamp:r,message:e.error?.message||"Unknown error",errorType:e.error?.type});break}}return n}async function s7(e){const t=[];let n=0;for(let r=0;r<e.length;r++){const s=e[r].trim();if(s)try{const i=JSON.parse(s),o=r7(i,n);t.push(...o),n+=o.length}catch(i){console.warn(`[parseExecutionLogs] Failed to parse log line ${r+1}:`,i instanceof Error?i.message:String(i))}}return t}function i7(e){const[t,n]=x.useState([]),[r,s]=x.useState(!0),[i,o]=x.useState(null),[a,l]=x.useState(null);return x.useEffect(()=>{s(!0),o(null),n([]),l(null);const c=new AbortController;async function u(){try{const d=await fetch(`/api/executions/${e}/logs`,{signal:c.signal});if(!d.ok)throw d.status===404?new Error(`Execution not found: ${e}`):new Error(`Failed to fetch execution logs: ${d.status} ${d.statusText}`);const f=await d.json();if(!f.success)throw new Error(f.message||"Failed to fetch execution logs");const p=await s7(f.data.logs);n(p),l(f.data.metadata)}catch(d){if(d instanceof Error&&d.name==="AbortError")return;const f=d instanceof Error?d:new Error("Unknown error fetching execution logs");o(f),console.error("[useExecutionLogs] Error:",f)}finally{c.signal.aborted||s(!1)}}return u(),()=>{c.abort()}},[e]),{events:t,loading:r,error:i,metadata:a}}function o7({messages:e,toolCalls:t,renderMarkdown:n=!0,className:r=""}){const s=x.useMemo(()=>{const i=[];return e.forEach(o=>{i.push({type:"message",timestamp:o.timestamp,data:o})}),t.forEach(o=>{i.push({type:"tool_call",timestamp:o.startTime,data:o})}),i.sort((o,a)=>o.timestamp-a.timestamp)},[e,t]);return s.length===0?null:h.jsx("div",{className:`space-y-3 ${r}`,children:s.map(i=>{if(i.type==="message"){const o=i.data;return h.jsxs("div",{className:"flex gap-3 items-start",children:[h.jsx("div",{className:"mt-1 flex-shrink-0",children:h.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-primary/10",children:h.jsx(Vu,{className:"h-4 w-4 text-primary"})})}),h.jsxs("div",{className:"flex-1 min-w-0",children:[h.jsxs("div",{className:"flex items-center gap-2 mb-1",children:[h.jsx(st,{variant:"outline",className:"text-xs",children:o.role}),!o.complete&&h.jsx(Ds,{className:"h-3 w-3 animate-spin text-muted-foreground"})]}),h.jsx("div",{className:"rounded-lg bg-muted/50 p-3 text-sm",children:n?h.jsx(w_,{className:"prose prose-sm max-w-none dark:prose-invert",components:{p:({children:a})=>h.jsx("p",{className:"mb-2 last:mb-0",children:a}),code:({inline:a,children:l,...c})=>a?h.jsx("code",{className:"bg-background px-1 py-0.5 rounded text-xs",...c,children:l}):h.jsx("pre",{className:"bg-background p-2 rounded overflow-x-auto",children:h.jsx("code",{...c,children:l})}),ul:({children:a})=>h.jsx("ul",{className:"list-disc pl-4 mb-2",children:a}),ol:({children:a})=>h.jsx("ol",{className:"list-decimal pl-4 mb-2",children:a}),li:({children:a})=>h.jsx("li",{className:"mb-1",children:a}),a:({children:a,href:l})=>h.jsx("a",{href:l,className:"text-primary hover:underline",target:"_blank",rel:"noopener noreferrer",children:a})},children:o.content}):h.jsx("div",{className:"whitespace-pre-wrap",children:o.content})})]})]},`msg-${o.messageId}`)}else{const o=i.data;return h.jsxs("div",{className:"flex gap-3 items-start",children:[h.jsx("div",{className:"mt-1 flex-shrink-0",children:h.jsx("div",{className:"flex h-7 w-7 items-center justify-center rounded-full bg-blue-500/10",children:h.jsx(AA,{className:"h-4 w-4 text-blue-500"})})}),h.jsx("div",{className:"flex-1 min-w-0",children:h.jsxs("div",{className:"rounded-lg border bg-card p-3 text-sm",children:[h.jsxs("div",{className:"flex items-center justify-between mb-2",children:[h.jsxs("div",{className:"flex items-center gap-2",children:[h.jsx("span",{className:"font-medium",children:o.toolCallName}),h.jsx(st,{variant:o.status==="completed"?"default":o.status==="error"?"destructive":"secondary",className:"text-xs",children:o.status})]}),o.endTime&&h.jsxs("span",{className:"text-xs text-muted-foreground",children:[((o.endTime-o.startTime)/1e3).toFixed(2),"s"]})]}),o.args&&h.jsxs("details",{className:"mt-2",children:[h.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground",children:"Arguments"}),h.jsx("pre",{className:"mt-1 text-xs bg-muted/50 p-2 rounded overflow-x-auto",children:o.args})]}),o.result&&h.jsxs("details",{className:"mt-2",open:o.status==="completed",children:[h.jsx("summary",{className:"cursor-pointer text-xs text-muted-foreground hover:text-foreground",children:"Result"}),h.jsx("pre",{className:"mt-1 text-xs bg-muted/50 p-2 rounded overflow-x-auto max-h-40",children:o.result})]}),o.error&&h.jsx("div",{className:"mt-2 text-xs text-destructive bg-destructive/10 p-2 rounded",children:o.error})]})})]},`tool-${o.toolCallId}`)}})})}function a7({executionId:e,execution:t,onComplete:n,onError:r,className:s=""}){const i=x.useMemo(()=>t?["preparing","pending","running","paused"].includes(t.status):!0,[t]),o=n7({executionId:e,autoConnect:i}),a=i7(e),{connectionStatus:l,execution:c,messages:u,toolCalls:d,state:f,error:p,isConnected:m}=x.useMemo(()=>{if(i)return{connectionStatus:o.connectionStatus,execution:o.execution,messages:o.messages,toolCalls:o.toolCalls,state:o.state,error:o.error,isConnected:o.isConnected};{const v=new Map,E=new Map,N={};return a.events&&a.events.forEach(k=>{if(k.type==="TEXT_MESSAGE_CONTENT"||k.name==="TEXT_MESSAGE_CONTENT"){const C=k.value||k;v.set(v.size,{id:v.size,content:C.content||C.text,timestamp:k.timestamp||Date.now()})}else if(k.type==="TOOL_CALL_START"||k.name==="TOOL_CALL_START"){const C=k.value||k;E.set(C.toolCallId,{id:C.toolCallId,name:C.name,status:"running",timestamp:k.timestamp||Date.now()})}else if(k.type==="TOOL_CALL_RESULT"||k.name==="TOOL_CALL_RESULT"){const C=k.value||k,A=E.get(C.toolCallId);A&&E.set(C.toolCallId,{...A,status:"completed",result:C.result})}}),{connectionStatus:a.loading?"connecting":a.error?"error":"connected",execution:{status:t?.status||"completed",runId:e,currentStep:void 0,error:a.error?.message,startTime:void 0,endTime:void 0},messages:v,toolCalls:E,state:N,error:a.error,isConnected:!1}}},[i,o,a,e,t]);x.useEffect(()=>{c.status==="completed"&&n&&n()},[c.status,n]),x.useEffect(()=>{p&&r&&r(p)},[p,r]);const g=d.size,b=Array.from(d.values()).filter(v=>v.status==="completed").length,y=u.size,w=()=>l==="connecting"?h.jsxs(st,{variant:"outline",className:"flex items-center gap-1",children:[h.jsx(Ds,{className:"h-3 w-3 animate-spin"}),"Connecting..."]}):l==="error"||c.status==="error"?h.jsxs(st,{variant:"destructive",className:"flex items-center gap-1",children:[h.jsx(ao,{className:"h-3 w-3"}),"Error"]}):c.status==="completed"?h.jsxs(st,{variant:"default",className:"flex items-center gap-1 bg-green-600",children:[h.jsx(om,{className:"h-3 w-3"}),"Completed"]}):c.status==="running"?h.jsxs(st,{variant:"default",className:"flex items-center gap-1",children:[h.jsx(Ds,{className:"h-3 w-3 animate-spin"}),"Running"]}):h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(ki,{className:"h-3 w-3"}),"Idle"]});return l==="connecting"&&c.status==="idle"?h.jsx(It,{className:`p-6 ${s}`,children:h.jsxs("div",{className:"flex items-center justify-center gap-2 text-muted-foreground",children:[h.jsx(Ds,{className:"h-4 w-4 animate-spin"}),h.jsx("span",{children:"Connecting to execution stream..."})]})}):h.jsxs(It,{className:`flex flex-col ${s}`,children:[h.jsxs("div",{className:"border-b px-6 py-4",children:[h.jsxs("div",{className:"flex items-center justify-between",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("h3",{className:"font-semibold",children:"Execution Monitor"}),w()]}),h.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[c.runId&&h.jsxs("span",{className:"font-mono text-xs",children:["Run: ",c.runId.slice(0,8)]}),m&&h.jsx(st,{variant:"outline",className:"text-xs",children:"Live"})]})]}),c.currentStep&&h.jsxs("div",{className:"mt-3 text-sm text-muted-foreground",children:[h.jsx("span",{className:"font-medium",children:"Current step:"})," ",c.currentStep]}),f.progress!==void 0&&f.totalSteps&&h.jsxs("div",{className:"mt-3",children:[h.jsxs("div",{className:"flex items-center justify-between text-sm text-muted-foreground mb-1",children:[h.jsx("span",{children:"Progress"}),h.jsxs("span",{children:[f.progress," / ",f.totalSteps]})]}),h.jsx("div",{className:"h-2 bg-secondary rounded-full overflow-hidden",children:h.jsx("div",{className:"h-full bg-primary transition-all duration-300",style:{width:`${f.progress/f.totalSteps*100}%`}})})]})]}),h.jsxs("div",{className:"flex-1 overflow-auto px-6 py-4",children:[(p||c.error)&&h.jsx("div",{className:"rounded-md bg-destructive/10 border border-destructive/20 p-4 mb-4",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(ao,{className:"h-5 w-5 text-destructive mt-0.5"}),h.jsxs("div",{className:"flex-1",children:[h.jsx("h4",{className:"font-semibold text-destructive",children:"Error"}),h.jsx("p",{className:"text-sm text-destructive/90 mt-1",children:c.error||p?.message})]})]})}),(y>0||g>0)&&h.jsx(o7,{messages:u,toolCalls:d,renderMarkdown:!0}),y===0&&g===0&&!p&&!c.error&&h.jsxs("div",{className:"flex flex-col items-center justify-center py-8 text-center text-muted-foreground",children:[h.jsx(ki,{className:"h-8 w-8 mb-2"}),h.jsx("p",{className:"text-sm",children:"No execution activity yet"}),h.jsx("p",{className:"text-xs mt-1",children:m?"Waiting for events...":"Connecting..."})]})]}),h.jsx("div",{className:"border-t px-6 py-3 bg-muted/30",children:h.jsxs("div",{className:"flex items-center justify-between text-xs text-muted-foreground",children:[h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:g})," tool calls"]}),h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:b})," completed"]}),h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:y})," messages"]})]}),f.tokenUsage&&h.jsxs("div",{className:"flex items-center gap-4",children:[h.jsxs("span",{children:[h.jsx("span",{className:"font-medium",children:f.tokenUsage})," tokens"]}),f.cost&&h.jsx("span",{children:h.jsxs("span",{className:"font-medium",children:["$",f.cost.toFixed(4)]})})]}),c.startTime&&c.endTime&&h.jsxs("span",{children:["Duration:"," ",h.jsxs("span",{className:"font-medium",children:[((c.endTime-c.startTime)/1e3).toFixed(2),"s"]})]})]})})]})}function l7({open:e,onSubmit:t,onCancel:n}){const[r,s]=x.useState(""),[i,o]=x.useState(!1),[a,l]=x.useState(null),c=async()=>{if(r.trim().length===0){l("Feedback cannot be empty");return}o(!0),l(null);try{await t(r.trim()),s(""),l(null)}catch(p){l(p instanceof Error?p.message:"Failed to submit feedback")}finally{o(!1)}},u=()=>{i||(s(""),l(null),n())},d=p=>{!p&&!i&&u()},f=r.trim().length>0&&!i;return h.jsx(Bi,{open:e,onOpenChange:d,children:h.jsxs(qs,{className:"max-w-2xl",children:[h.jsxs(Ws,{children:[h.jsx(Ks,{children:"Continue Execution"}),h.jsx(Gu,{children:"Provide additional feedback to continue the agent's work in the same environment."})]}),h.jsxs("div",{className:"space-y-4",children:[a&&h.jsx("div",{className:"rounded-lg border border-destructive bg-destructive/10 p-3",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(ki,{className:"h-5 w-5 text-destructive mt-0.5 flex-shrink-0"}),h.jsx("p",{className:"text-sm text-destructive",children:a})]})}),h.jsxs("div",{className:"space-y-2",children:[h.jsx(Ht,{htmlFor:"feedback",children:"Feedback"}),h.jsx(gd,{id:"feedback",value:r,onChange:p=>s(p.target.value),rows:8,placeholder:`Provide feedback or additional instructions for the agent.
563
564
 
564
565
  Examples:
565
566
  • "Please add error handling for edge cases"
566
567
  • "Can you explain the approach you took?"
567
568
  • "Also add tests for this functionality"`,className:"resize-none",disabled:i}),h.jsx("p",{className:"text-xs text-muted-foreground",children:"The agent will continue working in the same environment with this feedback."})]})]}),h.jsxs(hm,{children:[h.jsx(oe,{variant:"outline",onClick:u,disabled:i,children:"Cancel"}),h.jsx(oe,{onClick:c,disabled:!f,children:i?"Submitting...":"Continue"})]})]})})}function c7({worktreePath:e,isOpen:t,onClose:n,onConfirm:r,isDeleting:s=!1}){return e?h.jsx(Tm,{open:t,onOpenChange:n,children:h.jsxs(cd,{children:[h.jsxs(ud,{children:[h.jsx(fd,{children:"Delete Worktree"}),h.jsxs(hd,{children:["Are you sure you want to delete the worktree? This action cannot be undone.",h.jsx("br",{}),h.jsx("br",{}),h.jsx("strong",{children:"Worktree path:"}),h.jsx("br",{}),h.jsx("code",{className:"text-xs",children:e})]})]}),h.jsxs(dd,{children:[h.jsx(md,{disabled:s,children:"Cancel"}),h.jsx(pd,{onClick:r,disabled:s,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:s?"Deleting...":"Delete"})]})]})}):null}function u7({executionId:e,onFollowUpCreated:t}){const[n,r]=x.useState(null),[s,i]=x.useState(!0),[o,a]=x.useState(null),[l,c]=x.useState(!1),[u,d]=x.useState(!1),[f,p]=x.useState(!1),[m,g]=x.useState(!1),[b,y]=x.useState(!1);x.useEffect(()=>{(async()=>{i(!0),a(null);try{const O=await Xn.getById(e);if(r(O),O.worktree_path)try{const j=await Xn.worktreeExists(e);y(j.exists)}catch(j){console.error("Failed to check worktree status:",j),y(!1)}}catch(O){a(O instanceof Error?O.message:"Failed to load execution")}finally{i(!1)}})()},[e]);const w=x.useCallback(async()=>{try{const I=await Xn.getById(e);if(r(I),I.worktree_path)try{const O=await Xn.worktreeExists(e);y(O.exists)}catch(O){console.error("Failed to check worktree status:",O),y(!1)}}catch(I){console.error("Failed to reload execution:",I)}},[e]),v=x.useCallback(I=>{a(I.message)},[]),E=async()=>{if(n){p(!0);try{await Xn.cancel(e);const I=await Xn.getById(e);r(I)}catch(I){a(I instanceof Error?I.message:"Failed to cancel execution")}finally{p(!1)}}},N=async I=>{const O=await Xn.createFollowUp(e,{feedback:I});c(!1),t&&t(O.id)},k=async()=>{if(!(!n||!n.worktree_path)){g(!0);try{await Xn.deleteWorktree(e),y(!1);const I=await Xn.getById(e);r(I),d(!1)}catch(I){a(I instanceof Error?I.message:"Failed to delete worktree")}finally{g(!1)}}},C=I=>{switch(I){case"preparing":return h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(Ma,{className:"h-3 w-3"}),"Preparing"]});case"pending":return h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(Ma,{className:"h-3 w-3"}),"Pending"]});case"running":return h.jsxs(st,{variant:"default",className:"flex items-center gap-1",children:[h.jsx(Ds,{className:"h-3 w-3 animate-spin"}),"Running"]});case"paused":return h.jsxs(st,{variant:"outline",className:"flex items-center gap-1",children:[h.jsx(Gw,{className:"h-3 w-3"}),"Paused"]});case"completed":return h.jsxs(st,{variant:"default",className:"flex items-center gap-1 bg-green-600",children:[h.jsx(om,{className:"h-3 w-3"}),"Completed"]});case"failed":return h.jsxs(st,{variant:"destructive",className:"flex items-center gap-1",children:[h.jsx(ao,{className:"h-3 w-3"}),"Failed"]});case"cancelled":return h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(da,{className:"h-3 w-3"}),"Cancelled"]});case"stopped":return h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(da,{className:"h-3 w-3"}),"Stopped"]});default:return h.jsxs(st,{variant:"secondary",className:"flex items-center gap-1",children:[h.jsx(ki,{className:"h-3 w-3"}),String(I).charAt(0).toUpperCase()+String(I).slice(1)]})}};if(s)return h.jsx(It,{className:"p-6",children:h.jsxs("div",{className:"flex items-center justify-center gap-2 text-muted-foreground",children:[h.jsx(Ds,{className:"h-4 w-4 animate-spin"}),h.jsx("span",{children:"Loading execution..."})]})});if(o||!n)return h.jsx(It,{className:"p-6",children:h.jsxs("div",{className:"flex items-start gap-2 text-destructive",children:[h.jsx(ao,{className:"mt-0.5 h-5 w-5"}),h.jsxs("div",{children:[h.jsx("h4",{className:"font-semibold",children:"Error Loading Execution"}),h.jsx("p",{className:"mt-1 text-sm",children:o||"Execution not found"})]})]})});const A=n.status==="running",R=n.status==="completed"||n.status==="failed"||n.status==="stopped",T=n.worktree_path&&b;return h.jsxs("div",{className:"space-y-4",children:[h.jsx(It,{className:"p-6",children:h.jsxs("div",{className:"flex items-start justify-between",children:[h.jsxs("div",{className:"flex-1 space-y-3",children:[h.jsxs("div",{className:"flex items-center gap-3",children:[h.jsx("h2",{className:"text-xl font-semibold",children:"Execution"}),C(n.status)]}),h.jsxs("div",{className:"grid grid-cols-2 gap-4 text-sm",children:[h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"ID:"}),h.jsx("span",{className:"ml-2 font-mono",children:n.id})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"Issue:"}),h.jsx("span",{className:"ml-2 font-mono",children:n.issue_id})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"Mode:"}),h.jsx("span",{className:"ml-2 capitalize",children:n.mode})]}),h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"Model:"}),h.jsx("span",{className:"ml-2",children:n.model})]}),n.target_branch&&h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"Base Branch:"}),h.jsx("span",{className:"ml-2 font-mono",children:n.target_branch})]}),n.worktree_path&&h.jsxs("div",{children:[h.jsx("span",{className:"text-muted-foreground",children:"Worktree:"}),h.jsx("span",{className:"ml-2 font-mono text-xs",children:n.worktree_path}),b?h.jsx(st,{variant:"secondary",className:"ml-2 text-xs",children:"exists"}):h.jsx(st,{variant:"outline",className:"ml-2 text-xs text-muted-foreground",children:"deleted"})]})]}),h.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[n.created_at&&h.jsxs("div",{children:["Created:"," ",new Date(n.created_at).toLocaleString("en-US",{dateStyle:"short",timeStyle:"short"})]}),n.started_at&&h.jsxs("div",{children:["Started:"," ",new Date(n.started_at).toLocaleString("en-US",{dateStyle:"short",timeStyle:"short"})]}),n.completed_at&&h.jsxs("div",{children:["Completed:"," ",new Date(n.completed_at).toLocaleString("en-US",{dateStyle:"short",timeStyle:"short"})]})]}),n.error&&h.jsx("div",{className:"rounded-md border border-destructive/20 bg-destructive/10 p-3 text-sm",children:h.jsxs("div",{className:"flex items-start gap-2",children:[h.jsx(ao,{className:"mt-0.5 h-4 w-4 text-destructive"}),h.jsxs("div",{children:[h.jsx("h5",{className:"font-medium text-destructive",children:"Execution Error"}),h.jsx("p",{className:"mt-1 text-destructive/90",children:n.error})]})]})})]}),h.jsxs("div",{className:"ml-4 flex gap-2",children:[A&&h.jsx(oe,{variant:"destructive",size:"sm",onClick:E,disabled:f,children:f?h.jsxs(h.Fragment,{children:[h.jsx(Ds,{className:"mr-2 h-4 w-4 animate-spin"}),"Cancelling..."]}):h.jsxs(h.Fragment,{children:[h.jsx(da,{className:"mr-2 h-4 w-4"}),"Cancel"]})}),R&&h.jsxs(oe,{variant:"default",size:"sm",onClick:()=>c(!0),children:[h.jsx(cm,{className:"mr-2 h-4 w-4"}),"Follow Up"]}),T&&h.jsxs(oe,{variant:"outline",size:"sm",onClick:()=>d(!0),disabled:m,children:[h.jsx(Io,{className:"mr-2 h-4 w-4"}),"Delete Worktree"]})]})]})}),(n.status==="running"||n.status==="preparing"||n.status==="pending"||n.status==="paused"||n.status==="completed"||n.status==="failed"||n.status==="cancelled"||n.status==="stopped")&&h.jsx(a7,{executionId:e,execution:n,onComplete:w,onError:v}),h.jsx(l7,{open:l,onSubmit:N,onCancel:()=>c(!1)}),h.jsx(c7,{worktreePath:n.worktree_path,isOpen:u,onClose:()=>d(!1),onConfirm:k,isDeleting:m})]})}function d7(){const{id:e}=em(),t=cr();if(!e)return h.jsx("div",{className:"flex items-center justify-center p-12",children:h.jsxs("div",{className:"text-center",children:[h.jsx("h2",{className:"mb-2 text-2xl font-bold",children:"Invalid Execution"}),h.jsx("p",{className:"mb-4 text-muted-foreground",children:"No execution ID provided."}),h.jsx(oe,{onClick:()=>t("/issues"),children:"Back to Issues"})]})});const n=r=>{t(`/executions/${r}`)};return h.jsxs("div",{className:"flex h-screen flex-col",children:[h.jsx("div",{className:"flex items-center justify-between border-b bg-background p-4",children:h.jsx("div",{className:"flex items-center gap-4",children:h.jsxs(oe,{variant:"ghost",size:"sm",onClick:()=>t(-1),children:[h.jsx(Hu,{className:"mr-2 h-4 w-4"}),"Back"]})})}),h.jsx("div",{className:"flex-1 overflow-auto p-6",children:h.jsx(u7,{executionId:e,onFollowUpCreated:n})})]})}const f7=new jT({defaultOptions:{queries:{staleTime:3e4,gcTime:36e5,refetchOnWindowFocus:!1,retry:1}}});function h7(){return h.jsx(zT,{client:f7,children:h.jsx(XT,{children:h.jsx(ZT,{children:h.jsx(cT,{children:h.jsx(uT,{children:h.jsxs(Br,{path:"/",element:h.jsx(cO,{}),children:[h.jsx(Br,{index:!0,element:h.jsx(dT,{to:"/issues",replace:!0})}),h.jsx(Br,{path:"issues",element:h.jsx(UK,{})}),h.jsx(Br,{path:"issues/archived",element:h.jsx(GG,{})}),h.jsx(Br,{path:"issues/:id",element:h.jsx(HK,{})}),h.jsx(Br,{path:"specs",element:h.jsx(ZK,{})}),h.jsx(Br,{path:"specs/archived",element:h.jsx(JG,{})}),h.jsx(Br,{path:"specs/:id",element:h.jsx(KG,{})}),h.jsx(Br,{path:"executions/:id",element:h.jsx(d7,{})})]})})})})})})}pT.createRoot(document.getElementById("root")).render(h.jsx(at.StrictMode,{children:h.jsx(h7,{})}));
568
- //# sourceMappingURL=index-DKAuvfy4.js.map
569
+ //# sourceMappingURL=index-fLX6-3RP.js.map