@ottocode/web-ui 0.1.207 → 0.1.209

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.
@@ -85,9 +85,9 @@ ${d.slice(u)}`;return s(D),setTimeout(()=>{n.setSelectionRange(u,u)},0),!0}if(B=
85
85
 
86
86
  ${W}`:W,te=R.length>0?R.map(VA=>({data:VA.data,mediaType:VA.mediaType})):void 0,Re=j.length>0?j.map(VA=>({type:VA.type,name:VA.name,data:VA.data,mediaType:VA.mediaType,textContent:VA.textContent})):void 0;await m.mutateAsync({content:RA,images:te,files:Re,agent:a||void 0,provider:i||void 0,model:I||void 0,userContext:g||void 0,reasoningText:S&&x.reasoningEnabled?!0:void 0}),z()}catch(aA){console.error("Failed to send message:",aA)}},[m,j,R,z,a,i,I,g,S,x.reasoningEnabled,A,yA]),ee=l.useCallback(()=>{C(W=>!W)},[]),JA=l.useCallback(()=>{C(!1),u(null)},[]),ye=l.useCallback(async W=>{if(W==="models")u("model"),C(!0);else if(W==="agents")u("agent"),C(!0);else if(W==="new")s?.();else if(W==="stage"){const aA=F?.unstaged?.map(te=>te.path)??[],EA=F?.untracked?.map(te=>te.path)??[],RA=[...aA,...EA];RA.length>0&&p.mutate(RA)}else if(W==="commit")f(A);else if(W==="compact")NA("/compact");else if(W==="delete")y.mutate(A,{onSuccess:()=>{o?.()}});else if(W==="share"){const aA=QA.loading("Sharing session...");try{const EA=await v.shareSession(A);EA.shared&&(QA.successWithAction(EA.message==="Already shared"?"Already shared":"Session shared!",{label:"Open",href:EA.url}),b.invalidateQueries({queryKey:["share-status",A]}))}catch(EA){QA.error(EA instanceof Error?EA.message:"Failed to share")}finally{Ie.getState().removeToast(aA)}}else if(W==="sync"){const aA=QA.loading("Syncing session...");try{const EA=await v.syncSession(A);if(EA.synced){const RA=EA.newMessages>0?`Synced ${EA.newMessages} new messages`:"Already synced";QA.successWithAction(RA,{label:"Open",href:EA.url}),b.invalidateQueries({queryKey:["share-status",A]})}}catch(EA){QA.error(EA instanceof Error?EA.message:"Failed to sync")}finally{Ie.getState().removeToast(aA)}}},[s,F,p,f,NA,y,A,o,b]),me=l.useCallback(async W=>{r(W);try{await k.mutateAsync({agent:W})}catch(aA){console.error("Failed to update agent:",aA)}},[k]),re=l.useCallback(async(W,aA)=>{E(W),c(aA);try{await k.mutateAsync({provider:W,model:aA})}catch(EA){console.error("Failed to update model:",EA)}},[k]),oe=l.useCallback(async W=>{if(E(W),I)try{await k.mutateAsync({provider:W,model:I})}catch(aA){console.error("Failed to update provider:",aA)}},[I,k]),Je=l.useCallback(async W=>{c(W);try{await k.mutateAsync({provider:i,model:W})}catch(aA){console.error("Failed to update model:",aA)}},[i,k]),he=l.useCallback(async W=>{const aA=W?"plan":"build";r(aA);try{await k.mutateAsync({agent:aA})}catch(EA){console.error("Failed to switch agent:",EA)}},[k]);return t.jsxs(t.Fragment,{children:[t.jsx(FC,{isOpen:n,onClose:JA,initialFocus:d,chatInputRef:h,agent:a,provider:i,model:I,modelSupportsReasoning:S,onAgentChange:me,onProviderChange:oe,onModelChange:Je,onModelSelectorChange:re}),t.jsx(sC,{ref:h,onSend:NA,onCommand:ye,disabled:m.isPending,onConfigClick:ee,onPlanModeToggle:he,isPlanMode:a==="plan",reasoningEnabled:S&&x.reasoningEnabled,sessionId:A,images:R,documents:j,onFileRemove:H,isDragging:J,onPaste:AA,visionEnabled:O,attachmentEnabled:L,modelName:I,providerName:i,authType:cA,researchContexts:oA,onResearchContextRemove:T,onRefreshBalance:i==="setu"?bA:void 0,isBalanceLoading:q,onModelInfoClick:()=>{u("model"),C(!0)},agent:a,agents:M?.agents,onAgentChange:me},D)]})}));function UC({sessionId:e,onStop:A,disabled:g}){const[s,o]=l.useState(!1),Q=async()=>{if(!s){o(!0);try{await v.abortSession(e),A?.()}catch(B){console.error("Failed to abort stream:",B)}finally{setTimeout(()=>o(!1),1e3)}}};return t.jsxs("button",{type:"button",onClick:Q,disabled:g||s,className:"flex items-center gap-1.5 text-sm text-destructive hover:text-destructive/80 disabled:opacity-50 disabled:cursor-not-allowed transition-colors",title:"Stop generation",children:[t.jsx(Yo,{className:"w-4 h-4"}),t.jsx("span",{className:"font-medium",children:s?"Stopping...":"Stop"})]})}function SC(e){const A=e.split(".").pop()?.toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"text",svelte:"svelte"}[A||""]||"javascript"}function KC(e){const A=e.split(`
87
87
  `),g=[];let s=0,o=0,Q=!1,B="";for(const a of A){if(a.startsWith("*** Update File:")||a.startsWith("*** Add File:")){const i=a.match(/\*\*\* (?:Update|Add) File: (.+)/);i&&(B=i[1]),Q=!0,o=1,s=1}if(a.startsWith("+++")||a.startsWith("*** Update File:")){const i=a.match(/\+\+\+ b\/(.+)/)||a.match(/\*\*\* Update File: (.+)/);i&&(B=i[1])}const r=a.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(r){s=Number.parseInt(r[1],10),o=Number.parseInt(r[2],10),Q=!0,g.push({content:a,codeContent:a,type:"header"});continue}if(a.startsWith("@@")&&!a.match(/^@@ -\d+/)){Q=!0,g.push({content:a,codeContent:a,type:"header"});continue}if(a.startsWith("***")||a.startsWith("diff ")||a.startsWith("index ")||a.startsWith("---")||a.startsWith("+++")){g.push({content:a,codeContent:a,type:"meta"});continue}Q?a.startsWith("+")?g.push({content:a,codeContent:a.slice(1),type:"add",newLineNum:o++}):a.startsWith("-")?g.push({content:a,codeContent:a.slice(1),type:"remove",oldLineNum:s++}):a.startsWith(" ")||a===""?g.push({content:a,codeContent:a.startsWith(" ")?a.slice(1):a,type:"context",oldLineNum:s++,newLineNum:o++}):g.push({content:a,codeContent:a,type:"context"}):g.push({content:a,codeContent:a,type:"meta"})}return{lines:g,filePath:B}}function $e({patch:e}){const{lines:A,filePath:g}=KC(e),s=SC(g),o=document?.documentElement.classList.contains("dark")?ce:de;return t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 max-w-full",children:t.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-96 text-xs font-mono",children:A.map((Q,B)=>{const a=`line-${B}-${Q.content.slice(0,20)}`;if(Q.type==="meta"||Q.type==="header")return t.jsx("div",{className:`px-3 py-0.5 whitespace-pre-wrap break-all ${Q.type==="header"?"text-muted-foreground/80 bg-muted/20":"text-muted-foreground/80"}`,children:Q.content},a);let r="",i="";switch(Q.type){case"add":r="text-emerald-700 dark:text-emerald-300",i="bg-emerald-500/10";break;case"remove":r="text-red-600 dark:text-red-300",i="bg-red-500/10";break;default:r="text-foreground/80"}let E=Q.content;return Q.codeContent.trim()&&s!=="text"&&(E=t.jsx(WA,{language:s,style:o,customStyle:{margin:0,padding:0,background:"transparent",display:"inline",fontSize:"inherit",lineHeight:"inherit"},codeTagProps:{style:{fontFamily:"inherit",background:"transparent"}},PreTag:"span",children:Q.codeContent}),Q.type==="add"?E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:"+"}),E]}):Q.type==="remove"?E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:"-"}),E]}):Q.type==="context"&&(E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:" "}),E]}))),t.jsxs("div",{className:`flex ${i}`,children:[t.jsx("div",{className:"px-2 py-0.5 text-right text-muted-foreground/40 select-none w-12 flex-shrink-0",children:Q.oldLineNum||""}),t.jsx("div",{className:"px-2 py-0.5 text-right text-muted-foreground/40 select-none w-12 flex-shrink-0 border-r border-border/50",children:Q.newLineNum||""}),t.jsx("div",{className:`px-3 py-0.5 flex-1 min-w-0 whitespace-pre-wrap break-all ${r}`,children:E})]},a)})})})}function JC(e){const A=e.split(".").pop()?.toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"text",svelte:"svelte"}[A||""]||"javascript"}function RC(e,A){if(!A)return null;const s={read:["path"],write:["path"],edit:["path"],apply_patch:["path"],glob:["pattern"],grep:["query","pattern"],ripgrep:["query","pattern"],bash:["cmd","command"],terminal:["command"],git_commit:["message"],git_diff:["file"],tree:["path"],ls:["path"],web_search:["query","url"],skill:["name"]}[e];if(!s){for(const[o,Q]of Object.entries(A))if(typeof Q=="string"&&Q.length>0&&Q.length<200)return{key:o,value:Q};return null}for(const o of s){const Q=A[o];if(typeof Q=="string"&&Q.length>0)return{key:o,value:Q}}return null}function LC(e){if(!e)return null;const A=e.cmd??e.command;return typeof A=="string"&&A.length>0?A:null}const jC=l.memo(function({toolName:A,args:g,pendingApproval:s,onApprove:o,onReject:Q}){const[B,a]=l.useState(!1),r=A.replace(/_/g," "),i=RC(A,g),I=(A==="bash"?LC(g):null)||i?.value,c=typeof g?.path=="string"?g.path:"",n=JC(c),C=document?.documentElement.classList.contains("dark")?ce:de,d=()=>{a(!0),o(s.callId)},u=()=>{a(!0),Q(s.callId)},D=()=>{if(A==="apply_patch"&&g?.patch)return t.jsx("div",{className:"ml-6 max-w-full overflow-hidden",children:t.jsx($e,{patch:String(g.patch)})});if(A==="write"&&g?.content){const w=String(g.content);return t.jsx("div",{className:"ml-6 max-w-full overflow-hidden",children:t.jsx("div",{className:"bg-emerald-500/10 border border-emerald-500/30 rounded-lg overflow-hidden max-h-96",children:t.jsx("div",{className:"overflow-x-auto overflow-y-auto max-h-96 text-xs",children:t.jsx(WA,{language:n,style:C,customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"inherit"},showLineNumbers:!0,lineNumberStyle:{minWidth:"2.5em",paddingRight:"1em",color:"var(--muted-foreground)",opacity:.4,userSelect:"none"},children:w})})})})}if(A==="bash"&&g?.cmd){const w=String(g.cmd);return t.jsx("div",{className:"ml-6 max-w-full overflow-hidden",children:t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden",children:t.jsx("div",{className:"overflow-x-auto text-xs",children:t.jsx(WA,{language:"bash",style:C,customStyle:{margin:0,padding:"0.75rem",background:"transparent",fontSize:"inherit"},children:w})})})})}return null};return t.jsxs("div",{className:"flex flex-col gap-2 py-1",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-wrap",children:[t.jsx(Wo,{className:"h-4 w-4 text-amber-500 flex-shrink-0"}),t.jsx("span",{className:"font-medium text-foreground text-sm",children:r}),I&&A!=="bash"&&t.jsx("code",{className:"text-xs font-mono text-foreground/80 bg-muted/50 px-1.5 py-0.5 rounded truncate max-w-xs",children:I}),t.jsx("span",{className:"text-amber-600 dark:text-amber-400 font-medium text-sm",children:"requires approval"})]}),D(),t.jsxs("div",{className:"flex items-center gap-2 ml-6",children:[t.jsxs("button",{type:"button",onClick:u,disabled:B,title:"Reject (N or Esc)",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded border border-border bg-background hover:bg-muted transition-colors disabled:opacity-50",children:[t.jsx(kA,{className:"w-3 h-3"}),"Reject",t.jsx("kbd",{className:"ml-1 text-[10px] text-muted-foreground opacity-70",children:"N"})]}),t.jsxs("button",{type:"button",onClick:d,disabled:B,title:"Approve (Y)",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-amber-600 text-white hover:bg-amber-700 transition-colors disabled:opacity-50",children:[t.jsx(Ae,{className:"w-3 h-3"}),B?"Approving...":"Approve",!B&&t.jsx("kbd",{className:"ml-1 text-[10px] opacity-70",children:"Y"})]})]})]})});function KA(e){return e?e>=1e3?`${(e/1e3).toFixed(1)}s`:`${e}ms`:""}function tt(e){if(!e||typeof e!="object")return!1;const A=e;return A.ok===!1||"error"in A||A.success===!1}function gt(e){if(!e||typeof e!="object")return null;const A=e,g=["error","stderr","message","detail","details","reason"];for(const s of g){const o=A[s];if(typeof o=="string"){const Q=o.trim();if(Q.length)return Q}}return null}function OA({error:e,stack:A,showStack:g=!1}){return t.jsx("div",{className:"mt-2 ml-5 p-3 bg-red-50 dark:bg-red-950/20 border border-red-200 dark:border-red-800 rounded text-sm",children:t.jsxs("div",{className:"flex items-start gap-2",children:[t.jsx(le,{className:"h-4 w-4 flex-shrink-0 text-red-600 dark:text-red-400 mt-0.5"}),t.jsxs("div",{className:"flex-1 space-y-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:"Tool Error:"}),t.jsx("div",{className:"mt-1 text-red-900 dark:text-red-200 whitespace-pre-wrap",children:e})]}),g&&A&&t.jsxs("details",{className:"mt-2",children:[t.jsx("summary",{className:"cursor-pointer text-xs text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200",children:"View stack trace"}),t.jsx("pre",{className:"mt-2 p-2 bg-red-100/50 dark:bg-red-900/20 rounded text-xs overflow-x-auto text-red-800 dark:text-red-300",children:A})]})]})]})})}function vC(e){const A=e.split(".").pop()?.toLowerCase();return{js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"text"}[A||""]||"text"}function qC(e){if(!e)return;const A=e.match(/@(\d+)-(\d+)/);if(A)return Number.parseInt(A[1],10)}function OC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=typeof Q=="object"&&"ok"in Q&&Q.ok===!1,r=a&&"error"in Q&&typeof Q.error=="string"?Q.error:null,i=a&&"stack"in Q&&typeof Q.stack=="string"?Q.stack:void 0,E=String(Q.path||B.path||""),I=String(Q.content||""),c=Q.lineRange,n=I.split(`
88
- `),C=KA(A),d=vC(E),u=document?.documentElement.classList.contains("dark")?ce:de,D=qC(c),w=c?`${E}:${c.replace("@","")}`:E,h=I.length>0||a;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>h&&s(),className:`flex items-center gap-2 transition-colors w-full min-w-0 ${a?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":h?"text-blue-700 dark:text-blue-300 hover:text-blue-600 dark:hover:text-blue-200":"text-blue-700 dark:text-blue-300"}`,children:[h?g?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),a&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["read",a?" error":""]}),!o&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:w,children:w})]}),!a&&n.length>0&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0 whitespace-nowrap",children:["· ",n.length," lines · ",C]}),a&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",C]})]}),g&&a&&r&&t.jsx(OA,{error:r,stack:i,showStack:!0}),g&&!a&&I&&t.jsx("div",{className:"mt-2 ml-5 bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 overflow-y-auto max-w-full",children:t.jsx("div",{className:"overflow-x-auto max-w-full",children:t.jsx(WA,{language:d,style:u,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},showLineNumbers:!0,startingLineNumber:D,wrapLines:!0,wrapLongLines:!0,children:I})})})]})}function TC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=e.artifact,r=typeof Q=="object"&&"ok"in Q&&Q.ok===!1,i=r&&"error"in Q&&typeof Q.error=="string"?Q.error:null,E=r&&"stack"in Q&&typeof Q.stack=="string"?Q.stack:void 0,I=String(Q.path||B.path||""),c=Number(Q.bytes||0),n=a?.patch?String(a.patch):"",C=KA(A),d=n.length>0||r;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>d&&s(),className:`flex items-center gap-2 transition-colors min-w-0 w-full ${r?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":d?"text-emerald-700 dark:text-emerald-300 hover:text-emerald-600 dark:hover:text-emerald-200":"text-emerald-700 dark:text-emerald-300"}`,children:[d?g?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),r&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["write",r?" error":""]}),!o&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:I,children:I})]}),!r&&c>0&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 whitespace-nowrap flex-shrink-0",children:["· ",c," bytes · ",C]}),r&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",C]})]}),g&&r&&i&&t.jsx(OA,{error:i,stack:E,showStack:!0}),g&&!r&&n&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:n})})]})}function YC({args:e,result:A,artifact:g,toolDurationMs:s,isExpanded:o,onToggle:Q}){const B=typeof A=="object"&&"ok"in A&&A.ok===!1,a=B&&"error"in A&&typeof A.error=="string"?A.error:null,r=B&&"stack"in A&&typeof A.stack=="string"?A.stack:void 0,i=String(A.path||e.path||""),E=Number(A.opsApplied||0),I=g?.patch?String(g.patch):"",c=KA(s),n=I.length>0||B;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>n&&Q(),className:`flex items-center gap-2 transition-colors min-w-0 w-full ${B?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":n?"text-purple-700 dark:text-purple-300 hover:text-purple-600 dark:hover:text-purple-200":"text-purple-700 dark:text-purple-300"}`,children:[n?o?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),B&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["edit",B?" error":""]}),t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:i,children:i}),!B&&E>0&&t.jsxs("span",{className:"text-muted-foreground/80 whitespace-nowrap flex-shrink-0",children:["· ",E," ops · ",c]}),B&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",c]})]}),o&&B&&a&&t.jsx(OA,{error:a,stack:r,showStack:!0}),o&&!B&&I&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:I})})]})}const ho={sm:"h-3 w-3",md:"h-4 w-4",lg:"h-5 w-5"},HC={sm:"p-1",md:"p-1.5",lg:"p-2"};function Wt({text:e,className:A="",size:g="sm"}){const[s,o]=l.useState(!1),Q=async B=>{B.stopPropagation();try{await navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)}catch{}};return t.jsx("button",{type:"button",onClick:Q,className:`${HC[g]} rounded hover:bg-muted/50 text-muted-foreground hover:text-foreground transition-colors ${A}`,title:"Copy",children:s?t.jsx(Ae,{className:`${ho[g]} text-emerald-500`}):t.jsx(Ye,{className:ho[g]})})}function dA({title:e,icon:A,subtitle:g,copyText:s,variant:o="default",maxHeight:Q="max-h-80",children:B}){const a=o==="error";return t.jsxs("div",{className:`bg-card/60 border rounded-lg overflow-hidden flex flex-col ${Q} ${a?"border-red-500/50":"border-border"}`,children:[t.jsxs("div",{className:`flex items-center justify-between gap-2 text-xs px-3 py-1.5 border-b border-border sticky top-0 ${a?"text-red-600 dark:text-red-400 bg-red-500/10":"text-muted-foreground bg-muted/30"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[A,t.jsx("span",{children:e}),g&&t.jsx("span",{className:"text-muted-foreground/60",children:g})]}),s&&t.jsx(Wt,{text:s})]}),t.jsx("div",{className:"overflow-auto flex-1",children:B})]})}function BB({images:e}){const[A,g]=l.useState(null);return e.length===0?null:t.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:e.map((s,o)=>{const Q=`data:${s.mimeType};base64,${s.data}`,B=A===o;return t.jsx("div",{className:"relative",children:B?t.jsxs("div",{className:"relative",children:[t.jsx("button",{type:"button",onClick:()=>g(null),className:"absolute top-1 right-1 z-10 p-0.5 rounded bg-black/60 text-white hover:bg-black/80 transition-colors",children:t.jsx(kA,{className:"h-3 w-3"})}),t.jsx("img",{src:Q,alt:`Tool result image ${o+1}`,className:"max-w-full max-h-[32rem] rounded-lg border border-border object-contain"})]}):t.jsxs("button",{type:"button",onClick:()=>g(o),className:"group relative overflow-hidden rounded-lg border border-border hover:border-foreground/30 transition-colors",children:[t.jsx("img",{src:Q,alt:`Tool result image ${o+1}`,className:"w-48 h-32 object-cover"}),t.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors flex items-center justify-center",children:t.jsx(is,{className:"h-5 w-5 text-white opacity-0 group-hover:opacity-80 transition-opacity drop-shadow-lg"})})]})},`img-${o}-${s.mimeType}`)})})}const PC={default:{normal:"text-muted-foreground",hover:"hover:text-foreground",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},blue:{normal:"text-blue-700 dark:text-blue-300",hover:"hover:text-blue-600 dark:hover:text-blue-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},emerald:{normal:"text-emerald-700 dark:text-emerald-300",hover:"hover:text-emerald-600 dark:hover:text-emerald-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},purple:{normal:"text-purple-700 dark:text-purple-300",hover:"hover:text-purple-600 dark:hover:text-purple-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},cyan:{normal:"text-cyan-700 dark:text-cyan-300",hover:"hover:text-cyan-600 dark:hover:text-cyan-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},amber:{normal:"text-amber-700 dark:text-amber-300",hover:"hover:text-amber-600 dark:hover:text-amber-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},red:{normal:"text-red-700 dark:text-red-300",hover:"hover:text-red-600 dark:hover:text-red-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"}};function ie({toolName:e,isExpanded:A,onToggle:g,isError:s=!1,colorVariant:o="default",canExpand:Q=!0,children:B}){const a=PC[o],r=s?`${a.error} ${a.errorHover}`:`${a.normal} ${a.hover}`;return t.jsxs("button",{type:"button",onClick:()=>Q&&g(),className:`flex items-center gap-2 transition-colors w-full min-w-0 ${r}`,children:[Q?A?t.jsx(PA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),s&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:[e,s?" error":""]}),B]})}function eA(){return t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"})}function kt({children:e,className:A=""}){return t.jsx("span",{className:`text-foreground/70 ${A}`,children:e})}function vA({children:e,className:A=""}){return t.jsx("span",{className:`text-muted-foreground/80 flex-shrink-0 whitespace-nowrap ${A}`,children:e})}function st({children:e}){return t.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 flex-shrink-0",children:e})}function Mt({children:e}){return t.jsx("span",{className:"text-red-600 dark:text-red-400 flex-shrink-0",children:e})}function WC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=typeof Q=="object"&&"ok"in Q&&Q.ok===!1,r=a&&"error"in Q&&typeof Q.error=="string"?Q.error:null,i=a&&"stack"in Q&&typeof Q.stack=="string"?Q.stack:void 0,E=String(Q.stdout||""),I=String(Q.stderr||""),c=Number(Q.exitCode??0),n=String(B.cmd||""),C=B.cwd?String(B.cwd):void 0,d=KA(A),u=document?.documentElement.classList.contains("dark")?ce:de,D=E.length>0||I.length>0,w=a||c!==0,h=I.length>0,m=E+(E&&I?`
88
+ `),C=KA(A),d=vC(E),u=document?.documentElement.classList.contains("dark")?ce:de,D=qC(c),w=c?`${E}:${c.replace("@","")}`:E,h=I.length>0||a;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>h&&s(),className:`flex items-center gap-2 transition-colors w-full min-w-0 ${a?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":h?"text-blue-700 dark:text-blue-300 hover:text-blue-600 dark:hover:text-blue-200":"text-blue-700 dark:text-blue-300"}`,children:[h?g?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),a&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["read",a?" error":""]}),!o&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:w,children:`⁦${w}⁩`})]}),!a&&n.length>0&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0 whitespace-nowrap",children:["· ",n.length," lines · ",C]}),a&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",C]})]}),g&&a&&r&&t.jsx(OA,{error:r,stack:i,showStack:!0}),g&&!a&&I&&t.jsx("div",{className:"mt-2 ml-5 bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 overflow-y-auto max-w-full",children:t.jsx("div",{className:"overflow-x-auto max-w-full",children:t.jsx(WA,{language:d,style:u,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},showLineNumbers:!0,startingLineNumber:D,wrapLines:!0,wrapLongLines:!0,children:I})})})]})}function TC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=e.artifact,r=typeof Q=="object"&&"ok"in Q&&Q.ok===!1,i=r&&"error"in Q&&typeof Q.error=="string"?Q.error:null,E=r&&"stack"in Q&&typeof Q.stack=="string"?Q.stack:void 0,I=String(Q.path||B.path||""),c=Number(Q.bytes||0),n=a?.patch?String(a.patch):"",C=KA(A),d=n.length>0||r;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>d&&s(),className:`flex items-center gap-2 transition-colors min-w-0 w-full ${r?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":d?"text-emerald-700 dark:text-emerald-300 hover:text-emerald-600 dark:hover:text-emerald-200":"text-emerald-700 dark:text-emerald-300"}`,children:[d?g?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),r&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["write",r?" error":""]}),!o&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:I,children:`⁦${I}⁩`})]}),!r&&c>0&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 whitespace-nowrap flex-shrink-0",children:["· ",c," bytes · ",C]}),r&&!o&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",C]})]}),g&&r&&i&&t.jsx(OA,{error:i,stack:E,showStack:!0}),g&&!r&&n&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:n})})]})}function YC({args:e,result:A,artifact:g,toolDurationMs:s,isExpanded:o,onToggle:Q}){const B=typeof A=="object"&&"ok"in A&&A.ok===!1,a=B&&"error"in A&&typeof A.error=="string"?A.error:null,r=B&&"stack"in A&&typeof A.stack=="string"?A.stack:void 0,i=String(A.path||e.path||""),E=Number(A.opsApplied||0),I=g?.patch?String(g.patch):"",c=KA(s),n=I.length>0||B;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:()=>n&&Q(),className:`flex items-center gap-2 transition-colors min-w-0 w-full ${B?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":n?"text-purple-700 dark:text-purple-300 hover:text-purple-600 dark:hover:text-purple-200":"text-purple-700 dark:text-purple-300"}`,children:[n?o?t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 rotate-90 transition-transform"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0 transition-transform"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),B&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["edit",B?" error":""]}),t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:i,children:`⁦${i}⁩`}),!B&&E>0&&t.jsxs("span",{className:"text-muted-foreground/80 whitespace-nowrap flex-shrink-0",children:["· ",E," ops · ",c]}),B&&t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",c]})]}),o&&B&&a&&t.jsx(OA,{error:a,stack:r,showStack:!0}),o&&!B&&I&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:I})})]})}const ho={sm:"h-3 w-3",md:"h-4 w-4",lg:"h-5 w-5"},HC={sm:"p-1",md:"p-1.5",lg:"p-2"};function Wt({text:e,className:A="",size:g="sm"}){const[s,o]=l.useState(!1),Q=async B=>{B.stopPropagation();try{await navigator.clipboard.writeText(e),o(!0),setTimeout(()=>o(!1),2e3)}catch{}};return t.jsx("button",{type:"button",onClick:Q,className:`${HC[g]} rounded hover:bg-muted/50 text-muted-foreground hover:text-foreground transition-colors ${A}`,title:"Copy",children:s?t.jsx(Ae,{className:`${ho[g]} text-emerald-500`}):t.jsx(Ye,{className:ho[g]})})}function dA({title:e,icon:A,subtitle:g,copyText:s,variant:o="default",maxHeight:Q="max-h-80",children:B}){const a=o==="error";return t.jsxs("div",{className:`bg-card/60 border rounded-lg overflow-hidden flex flex-col ${Q} ${a?"border-red-500/50":"border-border"}`,children:[t.jsxs("div",{className:`flex items-center justify-between gap-2 text-xs px-3 py-1.5 border-b border-border sticky top-0 ${a?"text-red-600 dark:text-red-400 bg-red-500/10":"text-muted-foreground bg-muted/30"}`,children:[t.jsxs("div",{className:"flex items-center gap-2",children:[A,t.jsx("span",{children:e}),g&&t.jsx("span",{className:"text-muted-foreground/60",children:g})]}),s&&t.jsx(Wt,{text:s})]}),t.jsx("div",{className:"overflow-auto flex-1",children:B})]})}function BB({images:e}){const[A,g]=l.useState(null);return e.length===0?null:t.jsx("div",{className:"flex flex-wrap gap-2 mt-2",children:e.map((s,o)=>{const Q=`data:${s.mimeType};base64,${s.data}`,B=A===o;return t.jsx("div",{className:"relative",children:B?t.jsxs("div",{className:"relative",children:[t.jsx("button",{type:"button",onClick:()=>g(null),className:"absolute top-1 right-1 z-10 p-0.5 rounded bg-black/60 text-white hover:bg-black/80 transition-colors",children:t.jsx(kA,{className:"h-3 w-3"})}),t.jsx("img",{src:Q,alt:`Tool result image ${o+1}`,className:"max-w-full max-h-[32rem] rounded-lg border border-border object-contain"})]}):t.jsxs("button",{type:"button",onClick:()=>g(o),className:"group relative overflow-hidden rounded-lg border border-border hover:border-foreground/30 transition-colors",children:[t.jsx("img",{src:Q,alt:`Tool result image ${o+1}`,className:"w-48 h-32 object-cover"}),t.jsx("div",{className:"absolute inset-0 bg-black/0 group-hover:bg-black/10 transition-colors flex items-center justify-center",children:t.jsx(is,{className:"h-5 w-5 text-white opacity-0 group-hover:opacity-80 transition-opacity drop-shadow-lg"})})]})},`img-${o}-${s.mimeType}`)})})}const PC={default:{normal:"text-muted-foreground",hover:"hover:text-foreground",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},blue:{normal:"text-blue-700 dark:text-blue-300",hover:"hover:text-blue-600 dark:hover:text-blue-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},emerald:{normal:"text-emerald-700 dark:text-emerald-300",hover:"hover:text-emerald-600 dark:hover:text-emerald-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},purple:{normal:"text-purple-700 dark:text-purple-300",hover:"hover:text-purple-600 dark:hover:text-purple-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},cyan:{normal:"text-cyan-700 dark:text-cyan-300",hover:"hover:text-cyan-600 dark:hover:text-cyan-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},amber:{normal:"text-amber-700 dark:text-amber-300",hover:"hover:text-amber-600 dark:hover:text-amber-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"},red:{normal:"text-red-700 dark:text-red-300",hover:"hover:text-red-600 dark:hover:text-red-200",error:"text-red-700 dark:text-red-300",errorHover:"hover:text-red-600 dark:hover:text-red-200"}};function ie({toolName:e,isExpanded:A,onToggle:g,isError:s=!1,colorVariant:o="default",canExpand:Q=!0,children:B}){const a=PC[o],r=s?`${a.error} ${a.errorHover}`:`${a.normal} ${a.hover}`;return t.jsxs("button",{type:"button",onClick:()=>Q&&g(),className:`flex items-center gap-2 transition-colors w-full min-w-0 ${r}`,children:[Q?A?t.jsx(PA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx("div",{className:"w-3 flex-shrink-0"}),s&&t.jsx(le,{className:"h-3 w-3 flex-shrink-0 text-red-600 dark:text-red-400"}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:[e,s?" error":""]}),B]})}function eA(){return t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"})}function kt({children:e,className:A=""}){return t.jsx("span",{className:`text-foreground/70 ${A}`,children:e})}function vA({children:e,className:A=""}){return t.jsx("span",{className:`text-muted-foreground/80 flex-shrink-0 whitespace-nowrap ${A}`,children:e})}function st({children:e}){return t.jsx("span",{className:"text-emerald-600 dark:text-emerald-400 flex-shrink-0",children:e})}function Mt({children:e}){return t.jsx("span",{className:"text-red-600 dark:text-red-400 flex-shrink-0",children:e})}function WC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=typeof Q=="object"&&"ok"in Q&&Q.ok===!1,r=a&&"error"in Q&&typeof Q.error=="string"?Q.error:null,i=a&&"stack"in Q&&typeof Q.stack=="string"?Q.stack:void 0,E=String(Q.stdout||""),I=String(Q.stderr||""),c=Number(Q.exitCode??0),n=String(B.cmd||""),C=B.cwd?String(B.cwd):void 0,d=KA(A),u=document?.documentElement.classList.contains("dark")?ce:de,D=E.length>0||I.length>0,w=a||c!==0,h=I.length>0,m=E+(E&&I?`
89
89
  `:"")+I;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"bash",isExpanded:g,onToggle:s,isError:w,colorVariant:"default",canExpand:!0,children:[!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 min-w-0 truncate font-mono text-[11px]",title:n,children:n})]}),!a&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),c===0?t.jsxs(st,{children:["exit ",c]}):t.jsxs(Mt,{children:["exit ",c]}),t.jsx(eA,{}),t.jsx(vA,{children:d})]}),a&&!o&&t.jsxs(vA,{children:["· ",d]})]}),g&&a&&r&&t.jsx(OA,{error:r,stack:i,showStack:!0}),g&&!a&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"command",icon:t.jsx(we,{className:"h-3 w-3"}),subtitle:C&&C!=="."?`in ${C}`:void 0,copyText:n,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:n})}),D&&(c===0?t.jsx(dA,{title:"output",copyText:m,maxHeight:"max-h-[30rem]",children:t.jsx(WA,{language:"bash",style:u,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:m})}):t.jsxs(t.Fragment,{children:[E&&t.jsx(dA,{title:"stdout",copyText:E,maxHeight:"max-h-60",children:t.jsx(WA,{language:"bash",style:u,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:E})}),h&&t.jsx(dA,{title:"stderr",copyText:I,variant:"error",maxHeight:"max-h-60",children:t.jsx(WA,{language:"bash",style:u,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:I})})]}))]})]})}function zC(e){if(!e||e.length<3)return null;const A=e[0],g=e[1],s=e.slice(3);if(A==="?"&&g==="?")return{status:"??",file:s,type:"untracked"};let o="unstaged";return A!==" "&&g!==" "?o="both":A!==" "&&(o="staged"),{status:`${A}${g}`,file:s,type:o}}function VC(e){return e==="??"?"?":e[0]==="A"||e[1]==="A"?"+":e[0]==="M"||e[1]==="M"?"~":e[0]==="D"||e[1]==="D"?"-":e[0]==="R"||e[1]==="R"?"→":e}function ZC(e){switch(e){case"staged":return"text-emerald-600 dark:text-emerald-400";case"unstaged":return"text-amber-600 dark:text-amber-400";case"untracked":return"text-muted-foreground/60";case"both":return"text-blue-600 dark:text-blue-400"}}function XC({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.result||{},Q=tt(o),B=gt(o),a=Number(o.staged||0),r=Number(o.unstaged||0),i=o.raw||[],E=String(o.summary||""),I=KA(A),c=i.map(zC).filter(Boolean),n=a>0||r>0,C=c.length>0||Q||!!E;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"git status",isExpanded:g,onToggle:s,isError:Q,colorVariant:"blue",canExpand:C,children:[t.jsx(eA,{}),n?t.jsxs(t.Fragment,{children:[a>0&&t.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 flex-shrink-0",children:[a," staged"]}),r>0&&t.jsxs("span",{className:"text-amber-600 dark:text-amber-400 flex-shrink-0",children:[r," unstaged"]})]}):t.jsx("span",{className:"text-muted-foreground/60 flex-shrink-0",children:"clean"}),t.jsx(eA,{}),t.jsx(vA,{children:I})]}),g&&Q&&B&&t.jsx(OA,{error:B}),g&&!Q&&(c.length>0||E)&&t.jsx("div",{className:"mt-2 ml-5",children:c.length>0?t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden max-h-96 overflow-y-auto",children:t.jsx("div",{className:"divide-y divide-border/50",children:c.map((d,u)=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-1.5 font-mono hover:bg-muted/20",children:[t.jsx("span",{className:`font-semibold w-6 flex-shrink-0 ${ZC(d.type)}`,children:VC(d.status)}),t.jsx("span",{className:"text-foreground/80 break-all",children:d.file})]},`${d.file}-${u}`))})}):E&&t.jsx("div",{className:"bg-card/60 border border-border rounded-lg p-3 text-muted-foreground",children:E})})]})}function _C({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.result||{},Q=e.args||{},B=String(o.patch||o.diff||""),a=Q.all||o.all,r=KA(A),i=tt(o)||!!e.error,E=gt(o)||(typeof e.error=="string"?e.error:null),I=o&&typeof o=="object"&&"stack"in o?String(o.stack):void 0,c=B.split(`
90
- `);let n=0,C=0,d=0;for(const D of c)D.startsWith("diff --git")?n+=1:D.startsWith("+")&&!D.startsWith("+++")?C+=1:D.startsWith("-")&&!D.startsWith("---")&&(d+=1);const u=n>0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"git diff",isExpanded:g,onToggle:s,isError:i,colorVariant:"purple",canExpand:!0,children:[a&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-muted-foreground/60",children:"(all)"})]}),t.jsx(eA,{}),u?t.jsxs(t.Fragment,{children:[t.jsxs(kt,{children:[n," ",n===1?"file":"files"]}),C>0&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(st,{children:["+",C]})]}),d>0&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(Mt,{children:["-",d]})]})]}):t.jsx("span",{className:"text-muted-foreground/60",children:"no changes"}),t.jsx(eA,{}),t.jsx(vA,{children:r})]}),g&&i&&E&&t.jsx(OA,{error:E,stack:I,showStack:!0}),g&&!i&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"options",icon:t.jsx(XA,{className:"h-3 w-3"}),maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10",children:a?"git diff (all working tree)":"git diff (staged only)"})}),B&&t.jsx($e,{patch:B}),!B&&t.jsx(dA,{title:"diff",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"No changes to show"})})]})]})}function $C({contentJson:e,toolDurationMs:A}){const g=e.result||{},s=String(g.message||""),o=KA(A),Q=document?.documentElement.classList.contains("dark")?ce:de;return t.jsxs("div",{className:"text-xs space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"font-medium text-emerald-700 dark:text-emerald-300",children:"git commit"}),t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx("span",{className:"text-muted-foreground/80",children:o})]}),s&&t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden max-w-full",children:t.jsx("div",{className:"overflow-x-auto max-w-full",children:t.jsx(WA,{language:"bash",style:Q,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:s})})})]})}function AI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.artifact,Q=KA(A),B=(w,h)=>h<=1?`${w}`:`${w}-${w+h-1}`,a=w=>{const h=`-${B(w.oldStart,w.oldLines)}`,m=`+${B(w.newStart,w.newLines)}`,k=[];w.additions>0&&k.push(`+${w.additions}`),w.deletions>0&&k.push(`-${w.deletions}`);const y=k.length>0?` (${k.join(", ")})`:"";return`${h} ${m}${y}`},r=o?.summary||{},i=Number(r.files||0),E=Number(r.additions||0),I=Number(r.deletions||0),c=o?.patch?String(o.patch):"",n=Array.isArray(e.result?.changes)?e.result?.changes:[],C=i===1&&n.length>0?n[0].filePath:null,d=e.error||e.result&&"ok"in e.result&&e.result.ok===!1,u=typeof e.error=="string"?e.error:e.result&&"error"in e.result&&typeof e.result.error=="string"?e.result.error:null,D=e.result&&typeof e.result=="object"&&"stack"in e.result&&typeof e.result.stack=="string"?e.result.stack:void 0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:s,className:`flex items-center gap-2 transition-colors w-full ${d?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":"text-purple-700 dark:text-purple-300 hover:text-purple-600 dark:hover:text-purple-200"}`,children:[t.jsx(xA,{className:`h-3 w-3 flex-shrink-0 transition-transform ${g?"rotate-90":""}`}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["apply patch",d?" error":""]}),t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),C?t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:C,children:C}):t.jsxs("span",{className:"text-foreground/70 flex-shrink-0",children:[i," ",i===1?"file":"files"]}),t.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 flex-shrink-0",children:["+",E]}),t.jsxs("span",{className:"text-red-600 dark:text-red-400 flex-shrink-0",children:["-",I]}),t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",Q]})]}),g&&d&&u&&t.jsxs("div",{children:[t.jsx(OA,{error:u,stack:D,showStack:!0}),c&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsxs("details",{children:[t.jsx("summary",{className:"cursor-pointer text-xs text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200",children:"Show patch that failed"}),t.jsx("div",{className:"mt-2",children:t.jsx($e,{patch:c})})]})})]}),g&&!d&&n.length>0&&t.jsx("div",{className:"mt-2 ml-5 space-y-2",children:n.map(w=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-mono text-foreground/80",children:w.filePath}),t.jsx("div",{className:"flex flex-wrap gap-2",children:w.hunks.map((h,m)=>t.jsx("span",{className:"rounded bg-muted px-2 py-0.5 text-[0.65rem] font-mono text-muted-foreground",children:a(h)},`apply-patch-${w.filePath}-hunk-${m}`))})]},`apply-patch-${w.filePath}-${w.kind}`))}),g&&!d&&c&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:c})})]})}function eI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.result||{},Q=e.args||{},B=tt(o),a=gt(o),r=o&&typeof o=="object"&&"stack"in o?String(o.stack):void 0,i=o.entries||[],E=KA(A),I=typeof Q.path=="string"?Q.path:".";return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"ls",isExpanded:g,onToggle:s,isError:B,colorVariant:"cyan",canExpand:!0,children:[I&&I!=="."&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 truncate min-w-0",title:I,children:I.length>30?`…${I.slice(-30)}`:I})]}),t.jsx(eA,{}),t.jsxs(kt,{children:[i.length," ",i.length===1?"entry":"entries"]}),t.jsx(eA,{}),t.jsx(vA,{children:E})]}),g&&B&&a&&t.jsx(OA,{error:a,stack:r,showStack:!0}),g&&!B&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"path",icon:t.jsx(zo,{className:"h-3 w-3"}),copyText:I,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:I})}),i.length>0&&t.jsx(dA,{title:"entries",copyText:i.map(c=>c.name||"").join(`
90
+ `);let n=0,C=0,d=0;for(const D of c)D.startsWith("diff --git")?n+=1:D.startsWith("+")&&!D.startsWith("+++")?C+=1:D.startsWith("-")&&!D.startsWith("---")&&(d+=1);const u=n>0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"git diff",isExpanded:g,onToggle:s,isError:i,colorVariant:"purple",canExpand:!0,children:[a&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-muted-foreground/60",children:"(all)"})]}),t.jsx(eA,{}),u?t.jsxs(t.Fragment,{children:[t.jsxs(kt,{children:[n," ",n===1?"file":"files"]}),C>0&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(st,{children:["+",C]})]}),d>0&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(Mt,{children:["-",d]})]})]}):t.jsx("span",{className:"text-muted-foreground/60",children:"no changes"}),t.jsx(eA,{}),t.jsx(vA,{children:r})]}),g&&i&&E&&t.jsx(OA,{error:E,stack:I,showStack:!0}),g&&!i&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"options",icon:t.jsx(XA,{className:"h-3 w-3"}),maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10",children:a?"git diff (all working tree)":"git diff (staged only)"})}),B&&t.jsx($e,{patch:B}),!B&&t.jsx(dA,{title:"diff",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"No changes to show"})})]})]})}function $C({contentJson:e,toolDurationMs:A}){const g=e.result||{},s=String(g.message||""),o=KA(A),Q=document?.documentElement.classList.contains("dark")?ce:de;return t.jsxs("div",{className:"text-xs space-y-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("span",{className:"font-medium text-emerald-700 dark:text-emerald-300",children:"git commit"}),t.jsx("span",{className:"text-muted-foreground/70",children:"·"}),t.jsx("span",{className:"text-muted-foreground/80",children:o})]}),s&&t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden max-w-full",children:t.jsx("div",{className:"overflow-x-auto max-w-full",children:t.jsx(WA,{language:"bash",style:Q,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:s})})})]})}function AI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.artifact,Q=KA(A),B=(w,h)=>h<=1?`${w}`:`${w}-${w+h-1}`,a=w=>{const h=`-${B(w.oldStart,w.oldLines)}`,m=`+${B(w.newStart,w.newLines)}`,k=[];w.additions>0&&k.push(`+${w.additions}`),w.deletions>0&&k.push(`-${w.deletions}`);const y=k.length>0?` (${k.join(", ")})`:"";return`${h} ${m}${y}`},r=o?.summary||{},i=Number(r.files||0),E=Number(r.additions||0),I=Number(r.deletions||0),c=o?.patch?String(o.patch):"",n=Array.isArray(e.result?.changes)?e.result?.changes:[],C=i===1&&n.length>0?n[0].filePath:null,d=e.error||e.result&&"ok"in e.result&&e.result.ok===!1,u=typeof e.error=="string"?e.error:e.result&&"error"in e.result&&typeof e.result.error=="string"?e.result.error:null,D=e.result&&typeof e.result=="object"&&"stack"in e.result&&typeof e.result.stack=="string"?e.result.stack:void 0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs("button",{type:"button",onClick:s,className:`flex items-center gap-2 transition-colors w-full ${d?"text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200":"text-purple-700 dark:text-purple-300 hover:text-purple-600 dark:hover:text-purple-200"}`,children:[t.jsx(xA,{className:`h-3 w-3 flex-shrink-0 transition-transform ${g?"rotate-90":""}`}),t.jsxs("span",{className:"font-medium flex-shrink-0",children:["apply patch",d?" error":""]}),t.jsx("span",{className:"text-muted-foreground/70 flex-shrink-0",children:"·"}),C?t.jsx("span",{className:"text-foreground/70 min-w-0 flex-shrink overflow-hidden text-ellipsis whitespace-nowrap",dir:"rtl",title:C,children:`⁦${C}⁩`}):t.jsxs("span",{className:"text-foreground/70 flex-shrink-0",children:[i," ",i===1?"file":"files"]}),t.jsxs("span",{className:"text-emerald-600 dark:text-emerald-400 flex-shrink-0",children:["+",E]}),t.jsxs("span",{className:"text-red-600 dark:text-red-400 flex-shrink-0",children:["-",I]}),t.jsxs("span",{className:"text-muted-foreground/80 flex-shrink-0",children:["· ",Q]})]}),g&&d&&u&&t.jsxs("div",{children:[t.jsx(OA,{error:u,stack:D,showStack:!0}),c&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsxs("details",{children:[t.jsx("summary",{className:"cursor-pointer text-xs text-red-700 dark:text-red-300 hover:text-red-600 dark:hover:text-red-200",children:"Show patch that failed"}),t.jsx("div",{className:"mt-2",children:t.jsx($e,{patch:c})})]})})]}),g&&!d&&n.length>0&&t.jsx("div",{className:"mt-2 ml-5 space-y-2",children:n.map(w=>t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-mono text-foreground/80",children:w.filePath}),t.jsx("div",{className:"flex flex-wrap gap-2",children:w.hunks.map((h,m)=>t.jsx("span",{className:"rounded bg-muted px-2 py-0.5 text-[0.65rem] font-mono text-muted-foreground",children:a(h)},`apply-patch-${w.filePath}-hunk-${m}`))})]},`apply-patch-${w.filePath}-${w.kind}`))}),g&&!d&&c&&t.jsx("div",{className:"mt-2 ml-5",children:t.jsx($e,{patch:c})})]})}function eI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.result||{},Q=e.args||{},B=tt(o),a=gt(o),r=o&&typeof o=="object"&&"stack"in o?String(o.stack):void 0,i=o.entries||[],E=KA(A),I=typeof Q.path=="string"?Q.path:".";return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"ls",isExpanded:g,onToggle:s,isError:B,colorVariant:"cyan",canExpand:!0,children:[I&&I!=="."&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 truncate min-w-0",title:I,children:I.length>30?`…${I.slice(-30)}`:I})]}),t.jsx(eA,{}),t.jsxs(kt,{children:[i.length," ",i.length===1?"entry":"entries"]}),t.jsx(eA,{}),t.jsx(vA,{children:E})]}),g&&B&&a&&t.jsx(OA,{error:a,stack:r,showStack:!0}),g&&!B&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"path",icon:t.jsx(zo,{className:"h-3 w-3"}),copyText:I,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:I})}),i.length>0&&t.jsx(dA,{title:"entries",copyText:i.map(c=>c.name||"").join(`
91
91
  `),maxHeight:"max-h-80",children:t.jsx("div",{className:"divide-y divide-border/50",children:i.map((c,n)=>{const C=c,d=C.type==="dir"||C.isDirectory;return t.jsxs("div",{className:"flex items-center gap-1.5 px-3 py-1 font-mono text-foreground/80 hover:bg-muted/20",children:[d?t.jsx(Vo,{className:"h-3 w-3 text-blue-500 flex-shrink-0"}):t.jsx(be,{className:"h-3 w-3 text-muted-foreground flex-shrink-0"}),t.jsx("span",{className:"truncate",children:C.name})]},`${C.name}-${n}`)})})}),i.length===0&&t.jsx(dA,{title:"entries",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"Directory is empty"})})]})]})}function tI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s}){const o=e.result||{},Q=e.args||{},B=tt(o),a=gt(o),r=o&&typeof o=="object"&&"stack"in o?String(o.stack):void 0,i=String(o.tree||""),E=i.split(`
92
92
  `).filter(d=>d.length>0).length,I=KA(A),c=document?.documentElement.classList.contains("dark")?ce:de,n=typeof Q.path=="string"?Q.path:".",C=typeof Q.depth=="number"?Q.depth:void 0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"tree",isExpanded:g,onToggle:s,isError:B,colorVariant:"cyan",canExpand:!0,children:[n&&n!=="."&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 truncate min-w-0",title:n,children:n.length>30?`…${n.slice(-30)}`:n})]}),t.jsx(eA,{}),t.jsxs(kt,{children:[E," ",E===1?"item":"items"]}),t.jsx(eA,{}),t.jsx(vA,{children:I})]}),g&&B&&a&&t.jsx(OA,{error:a,stack:r,showStack:!0}),g&&!B&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"path",icon:t.jsx(lt,{className:"h-3 w-3"}),subtitle:C?`depth: ${C}`:void 0,copyText:n,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:n})}),i&&t.jsx(dA,{title:"tree",copyText:i,maxHeight:"max-h-80",children:t.jsx("div",{className:"overflow-x-auto max-w-full",children:t.jsx(WA,{language:"bash",style:c,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:i})})}),!i&&t.jsx(dA,{title:"tree",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"No tree output"})})]})]})}function gI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=Q.matches||[],r=Q.files||[],i=KA(A),E=tt(Q)||!!e.error,I=gt(Q)||(typeof e.error=="string"?e.error:null),c=Q&&typeof Q=="object"&&"stack"in Q?String(Q.stack):void 0,n=a.length>0?a.length:r.length,C=a.length>0?a.length===1?"match":"matches":r.length===1?"file":"files",d=typeof B.pattern=="string"?B.pattern:typeof B.query=="string"?B.query:typeof B.filePattern=="string"?B.filePattern:"",u=(()=>{if(typeof B.path=="string"&&B.path!==".")return B.path})();return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"search",isExpanded:g,onToggle:s,isError:E,colorVariant:"amber",canExpand:!0,children:[d&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs("span",{className:"font-mono text-foreground/90 text-[11px] truncate min-w-0",title:d,children:['"',d.length>30?`${d.slice(0,30)}…`:d,'"']})]}),!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(kt,{children:[n," ",C]}),t.jsx(eA,{}),t.jsx(vA,{children:i})]})]}),g&&E&&I&&t.jsx(OA,{error:I,stack:c,showStack:!0}),g&&!E&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"query",icon:t.jsx(ut,{className:"h-3 w-3"}),subtitle:u,copyText:d,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:d||"(empty)"})}),a.length>0&&t.jsx(dA,{title:"results",copyText:a.map(D=>{const w=D;return`${w.file}:${w.line}: ${w.text}`}).join(`
93
93
  `),maxHeight:"max-h-80",children:t.jsx("div",{className:"divide-y divide-border/50",children:a.map((D,w)=>{const h=D;return t.jsxs("div",{className:"px-3 py-1.5 font-mono hover:bg-muted/20",children:[t.jsxs("div",{className:"text-blue-600 dark:text-blue-400 truncate",children:[h.file,":",h.line]}),t.jsx("div",{className:"text-foreground/80 truncate",children:h.text})]},`${h.file}-${h.line}-${w}`)})})}),r.length>0&&a.length===0&&t.jsx(dA,{title:"files",copyText:r.map(String).join(`
@@ -97,7 +97,7 @@ ${u.url}`).join(`
97
97
  `),maxHeight:"max-h-80",children:t.jsx("div",{className:"divide-y divide-border/50",children:I.map((u,D)=>t.jsxs("div",{className:"px-3 py-2 hover:bg-muted/20",children:[t.jsxs("a",{href:u.url,target:"_blank",rel:"noopener noreferrer",className:"flex items-center gap-1 text-blue-600 dark:text-blue-400 hover:underline font-medium",children:[u.title,t.jsx(jA,{className:"h-3 w-3 flex-shrink-0"})]}),t.jsx("p",{className:"text-muted-foreground text-xs mt-0.5",children:u.snippet}),t.jsx("p",{className:"text-xs text-muted-foreground/60 truncate mt-0.5",children:u.url})]},`${u.url}-${D}`))})}),I.length===0&&t.jsx(dA,{title:"results",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"No results found"})})]})]});const d=C&&C.length>50?`${C.slice(0,50)}...`:C;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"web fetch",isExpanded:g,onToggle:s,isError:a,colorVariant:"purple",canExpand:!0,children:[d&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 truncate min-w-0",title:C,children:d})]}),t.jsx(eA,{}),t.jsx(vA,{children:B})]}),g&&a&&r&&t.jsx(OA,{error:r,stack:i,showStack:!0}),g&&!a&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsx(dA,{title:"url",icon:t.jsx(Qa,{className:"h-3 w-3"}),copyText:C,maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 font-mono text-xs bg-muted/10 break-all",children:t.jsx("a",{href:C,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 dark:text-blue-400 hover:underline",children:C})})}),c.content&&t.jsx(dA,{title:"content",copyText:c.content,maxHeight:"max-h-80",children:t.jsx("div",{className:"px-3 py-2 text-xs text-foreground/80 whitespace-pre-wrap break-words",children:c.content})}),!c.content&&t.jsx(dA,{title:"content",maxHeight:"",children:t.jsx("div",{className:"px-3 py-2 text-muted-foreground/60 italic",children:"No content returned"})})]})]})}function rI({contentJson:e,debug:A,sessionId:g,onRetry:s,onCompact:o}){const[Q,B]=l.useState(!1),a=e.type==="balance_low"||e.errorType==="balance_low",r=e.type==="context_length_exceeded"||e.errorType==="context_length_exceeded";e.isRetryable;let i,E,I,c=!1;e.error&&typeof e.error=="object"?(i=e.error,i.message&&typeof i.message=="string"&&(E=i.message),i.type&&typeof i.type=="string"&&(I=i.type)):e.details&&typeof e.details=="object"?(i=e.details,e.message&&typeof e.message=="string"&&(E=e.message),e.type&&typeof e.type=="string"&&(I=e.type),e.isAborted===!0&&(c=!0)):(e.message&&typeof e.message=="string"&&(E=e.message),e.type&&typeof e.type=="string"&&(I=e.type),e.isAborted===!0&&(c=!0),i=e);let n;if(i?.responseBody&&typeof i.responseBody=="string")try{const h=JSON.parse(i.responseBody);h.error&&typeof h.error=="object"&&(n={type:typeof h.error.type=="string"?h.error.type:void 0,message:typeof h.error.message=="string"?h.error.message:void 0,code:typeof h.error.code=="string"?h.error.code:void 0})}catch{}const C=(n?.code==="model_not_supported"||n?.message?.toLowerCase().includes("model is not supported"))&&(String(i?.url??"").includes("githubcopilot.com")||e.type==="api_error");if(n?.message?.toLowerCase().includes("not accessible via the /chat/completions")&&String(i?.url??"").includes("githubcopilot.com")){const h=i?.requestBodyValues?.model;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-medium text-amber-600 dark:text-amber-400",children:"Model requires Responses API"}),t.jsx("p",{className:"text-sm text-foreground",children:h?t.jsxs(t.Fragment,{children:[t.jsx("code",{className:"px-1 py-0.5 bg-muted rounded text-xs",children:String(h)})," ","is only available via the Responses API, which is not yet supported."]}):"This model is only available via the Responses API, which is not yet supported."}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"Codex models (gpt-5.1-codex, gpt-5.2-codex, etc.) require the Responses API. Try a chat-compatible model like gpt-5, claude-sonnet-4, or gpt-4.1."})]}),s&&t.jsx("div",{className:"pt-1",children:t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[t.jsx(HA,{className:"w-3 h-3"}),"Retry"]})})]})}if(C){const h=i?.requestBodyValues?.model;return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-medium text-amber-600 dark:text-amber-400",children:"Model not available"}),t.jsx("p",{className:"text-sm text-foreground",children:h?t.jsxs(t.Fragment,{children:[t.jsx("code",{className:"px-1 py-0.5 bg-muted rounded text-xs",children:String(h)})," ","is not available. You need a Copilot Pro (or higher) plan and the model must be enabled in your settings."]}):"The requested model is not available. You need a Copilot Pro (or higher) plan and the model must be enabled in your settings."}),t.jsxs("p",{className:"text-xs text-muted-foreground",children:["Enable models at"," ",t.jsx("a",{href:"https://github.com/settings/copilot",target:"_blank",rel:"noopener noreferrer",className:"underline hover:text-foreground transition-colors",onClick:m=>{m.preventDefault(),Ce("https://github.com/settings/copilot")},children:"github.com/settings/copilot"})]})]}),s&&t.jsx("div",{className:"pt-1",children:t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[t.jsx(HA,{className:"w-3 h-3"}),"Retry"]})})]})}if(a)return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ct,{className:"h-4 w-4 text-amber-500"}),t.jsx("span",{className:"font-medium text-foreground",children:"Balance too low"})]}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"Complete your top-up in the modal, then retry your request."}),s&&t.jsx("div",{className:"pt-1",children:t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[t.jsx(HA,{className:"w-3 h-3"}),"Retry"]})})]});if(r)return t.jsxs("div",{className:"space-y-3",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Js,{className:"h-4 w-4 text-amber-500"}),t.jsx("span",{className:"font-medium text-foreground",children:"Context window exceeded"})]}),t.jsx("p",{className:"text-sm text-muted-foreground",children:"The conversation is too long for the model. Compact to reduce context size, then retry."}),t.jsxs("div",{className:"flex items-center gap-2 pt-1",children:[o&&t.jsxs("button",{type:"button",onClick:o,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[t.jsx(Js,{className:"w-3 h-3"}),"Compact"]}),s&&t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded border border-border text-foreground hover:bg-muted transition-colors",children:[t.jsx(HA,{className:"w-3 h-3"}),"Retry"]})]})]});const u=h=>{if(h==null)return t.jsx("span",{className:"text-muted-foreground",children:"null"});if(typeof h=="boolean")return t.jsx("span",{className:"text-amber-600 dark:text-amber-400",children:String(h)});if(typeof h=="number")return t.jsx("span",{className:"text-blue-600 dark:text-blue-400",children:h});if(typeof h=="string"){if(h.startsWith("{")||h.startsWith("["))try{const m=JSON.parse(h);return t.jsx("pre",{className:"mt-1 p-2 bg-muted/50 rounded text-xs overflow-x-auto",children:t.jsx("code",{children:JSON.stringify(m,null,2)})})}catch{}return t.jsx("span",{className:"text-foreground",children:h})}return typeof h=="object"?t.jsx("pre",{className:"mt-1 p-2 bg-muted/50 rounded text-xs overflow-x-auto",children:t.jsx("code",{children:JSON.stringify(h,null,2)})}):t.jsx("span",{className:"text-foreground",children:String(h)})},D=["name","statusCode","url","model","isRetryable","cause"],w=new Set;return t.jsxs("div",{className:"space-y-2 text-sm",children:[c&&t.jsx("div",{className:"text-amber-600 dark:text-amber-400 font-medium",children:"Request aborted"}),n?.message&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:"API Error:"}),t.jsx("div",{className:"text-foreground",children:n.message}),n.type&&t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Type: ",n.type]})]}),!n?.message&&E&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"font-medium text-red-600 dark:text-red-400",children:"Error:"}),t.jsx("div",{className:"text-foreground",children:E}),I&&t.jsxs("div",{className:"text-xs text-muted-foreground",children:["Type: ",I]})]}),s&&t.jsx("div",{className:"pt-2",children:t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-primary text-primary-foreground hover:bg-primary/90 transition-colors",children:[t.jsx(HA,{className:"w-3 h-3"}),"Retry"]})}),i&&t.jsx("div",{className:"space-y-1.5",children:D.map(h=>{const m=i[h];return m==null?null:(w.add(h),t.jsxs("div",{className:"flex gap-2",children:[t.jsxs("span",{className:"font-medium text-muted-foreground min-w-[100px]",children:[h,":"]}),u(m)]},h))})}),i&&t.jsxs("div",{className:"mt-3 border-t border-border pt-2",children:[t.jsxs("button",{type:"button",onClick:()=>B(!Q),className:"flex items-center gap-1 text-xs text-muted-foreground hover:text-foreground transition-colors",children:[Q?t.jsx(PA,{className:"h-3 w-3"}):t.jsx(xA,{className:"h-3 w-3"}),Q?"Hide":"View"," Raw Error Details"]}),Q&&t.jsx("div",{className:"mt-2",children:t.jsx("pre",{className:"p-3 bg-muted/50 rounded text-xs overflow-x-auto max-h-96 overflow-y-auto",children:t.jsx("code",{children:JSON.stringify(i,null,2)})})})]}),A&&t.jsxs("details",{className:"mt-4 text-xs",children:[t.jsx("summary",{className:"cursor-pointer text-muted-foreground",children:"Debug Info"}),t.jsx("pre",{className:"mt-2 p-2 bg-muted/30 rounded overflow-x-auto",children:t.jsx("code",{children:JSON.stringify({contentJson:e,errorDetails:i,apiError:n},null,2)})})]})]})}function aB(e){return e?new Date(e).toLocaleDateString(void 0,{month:"short",day:"numeric",hour:"2-digit",minute:"2-digit"}):""}function Fg({session:e,onNavigate:A,compact:g}){return g?t.jsxs("button",{type:"button",onClick:()=>A?.(e.id),disabled:!A,className:"w-full text-left py-1 px-2 rounded text-xs hover:bg-muted/50 transition-colors flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate text-foreground",children:e.title||"Untitled"}),A&&t.jsx(jA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}):t.jsxs("button",{type:"button",onClick:()=>A?.(e.id),disabled:!A,className:"w-full text-left p-2 rounded-md border border-border hover:bg-muted/50 transition-colors group",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"font-medium text-sm truncate text-foreground",children:e.title||"Untitled"}),A&&t.jsx(jA,{className:"w-3 h-3 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"})]}),t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-1",children:[e.agent&&t.jsx("span",{className:"text-violet-600 dark:text-violet-400",children:e.agent}),e.agent&&e.provider&&t.jsx("span",{children:"·"}),e.provider&&t.jsx("span",{children:e.provider}),e.messageCount!==void 0&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{children:[e.messageCount," msgs"]})]}),e.createdAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:aB(e.createdAt)})]})]})]})}function Do({message:e,onNavigate:A,compact:g}){const s="sessionId"in e?e.sessionId:"",o="sessionTitle"in e?e.sessionTitle:null,Q="content"in e?e.content:"contentPreview"in e?e.contentPreview:"matchedContent"in e?e.matchedContent:"";return g?t.jsxs("button",{type:"button",onClick:()=>A?.(s),disabled:!A||!s,className:"w-full text-left py-1 px-2 rounded text-xs hover:bg-muted/50 transition-colors flex items-center justify-between gap-2",children:[t.jsx("span",{className:"truncate text-foreground/80",children:Q?.slice(0,50)||o||s.slice(0,8)}),A&&s&&t.jsx(jA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"})]}):t.jsxs("button",{type:"button",onClick:()=>A?.(s),disabled:!A||!s,className:"w-full text-left p-2 rounded-md border border-border hover:bg-muted/50 transition-colors group",children:[t.jsxs("div",{className:"flex items-center justify-between gap-2",children:[t.jsx("span",{className:"text-xs text-muted-foreground",children:o||s.slice(0,8)}),A&&s&&t.jsx(jA,{className:"w-3 h-3 text-muted-foreground opacity-0 group-hover:opacity-100 transition-opacity flex-shrink-0"})]}),Q&&t.jsx("div",{className:"text-xs text-foreground/80 mt-1 line-clamp-2",children:Q}),t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground mt-1",children:[e.role&&t.jsx("span",{className:"capitalize",children:e.role}),e.createdAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:aB(e.createdAt)})]})]})]})}function po({args:e,toolName:A}){const g=(B,a)=>a==null||typeof a=="boolean"&&!a||Array.isArray(a)&&a.length===0?null:t.jsxs("span",{className:"inline-flex items-center gap-1 px-1.5 py-0.5 rounded bg-muted text-muted-foreground",children:[t.jsxs("span",{className:"opacity-60",children:[B,":"]}),t.jsx("span",{className:"text-foreground/80",children:typeof a=="string"?a:JSON.stringify(a)})]},B),Q=({query_sessions:["agent","sessionType","startDate","endDate"],query_messages:["sessionId","role","search","toolName"],search_history:["query"],get_session_context:["sessionId","includeMessages"],get_parent_session:["includeMessages"]}[A]||Object.keys(e).slice(0,3)).filter(B=>e[B]!==void 0&&e[B]!==null).map(B=>g(B,e[B])).filter(Boolean);return Q.length===0?null:t.jsxs("div",{className:"flex items-center gap-1.5 flex-wrap text-xs mb-2 pb-2 border-b border-border",children:[t.jsx(aa,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),Q]})}function EI({toolName:e,contentJson:A,toolDurationMs:g,isExpanded:s,onToggle:o,onNavigateToSession:Q,compact:B}){const a=A.result||{},r=A.args||{},i=typeof a=="object"&&"ok"in a&&a.ok===!1,E=i&&"error"in a&&typeof a.error=="string"?a.error:null,I=KA(g);if(e==="present_action"){const C=a.links||[],d=a.summary,u=a.title;return C.length===0&&!d?null:t.jsxs("div",{className:"mt-2 mb-1",children:[u&&t.jsx("div",{className:"text-sm font-medium text-foreground mb-1.5",children:u}),d&&t.jsxs("div",{className:"text-xs text-muted-foreground mb-2 flex items-center gap-1.5",children:[t.jsx(Ba,{className:"w-3.5 h-3.5 text-teal-500"}),t.jsx("span",{children:d})]}),C.length>0&&t.jsx("div",{className:"space-y-1.5",children:C.map(D=>t.jsxs("button",{type:"button",onClick:()=>Q?.(D.sessionId),disabled:!Q,className:"w-full text-left px-3 py-2 rounded-lg border border-teal-500/30 bg-teal-500/5 hover:bg-teal-500/10 transition-colors group flex items-center justify-between gap-2",children:[t.jsxs("div",{children:[t.jsx("div",{className:"font-medium text-sm text-foreground",children:D.title}),D.description&&t.jsx("div",{className:"text-xs text-muted-foreground mt-0.5",children:D.description})]}),Q&&t.jsx(jA,{className:"w-4 h-4 text-teal-600 dark:text-teal-400 opacity-60 group-hover:opacity-100 transition-opacity flex-shrink-0"})]},D.sessionId))})]})}const c=()=>{switch(e){case"query_sessions":{const C=a.sessions||[],d=a.total;return`${C.length} session${C.length!==1?"s":""}${d?` of ${d}`:""}`}case"query_messages":{const C=a.messages||[];return`${C.length} message${C.length!==1?"s":""}`}case"search_history":{const C=r.query,d=a.results||[],u=C?`"${C.slice(0,20)}${C.length>20?"…":""}"`:"";return`${d.length} result${d.length!==1?"s":""}${u?` for ${u}`:""}`}case"get_session_context":return a.session?.title||r.sessionId?.slice(0,8)||"session";case"get_parent_session":return a.parentSession?.title||"parent session";default:return e}},n=()=>{const C=Object.keys(r).length>0&&!B;switch(e){case"query_sessions":{const d=a.sessions||[];return t.jsxs("div",{className:B?"p-1":"p-2",children:[C&&t.jsx(po,{args:r,toolName:e}),d.length===0?t.jsx("div",{className:"text-xs text-muted-foreground",children:"No sessions found"}):t.jsxs("div",{className:B?"space-y-0.5":"space-y-2",children:[d.slice(0,B?5:10).map(u=>t.jsx(Fg,{session:u,onNavigate:Q,compact:B},u.id)),d.length>(B?5:10)&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["+",d.length-(B?5:10)," more"]})]})]})}case"query_messages":{const d=a.messages||[];return t.jsxs("div",{className:B?"p-1":"p-2",children:[C&&t.jsx(po,{args:r,toolName:e}),d.length===0?t.jsx("div",{className:"text-xs text-muted-foreground",children:"No messages found"}):t.jsxs("div",{className:B?"space-y-0.5":"space-y-2",children:[d.slice(0,B?5:10).map(u=>t.jsx(Do,{message:u,onNavigate:Q,compact:B},u.id)),d.length>(B?5:10)&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["+",d.length-(B?5:10)," more"]})]})]})}case"search_history":{const d=a.results||[],u=r.query;return t.jsxs("div",{className:B?"p-1":"p-2",children:[u&&!B&&t.jsxs("div",{className:"flex items-center gap-1.5 text-xs mb-2 pb-2 border-b border-border",children:[t.jsx(ut,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),t.jsx("span",{className:"text-muted-foreground",children:"Query:"}),t.jsxs("span",{className:"text-foreground font-medium",children:['"',u,'"']})]}),d.length===0?t.jsx("div",{className:"text-xs text-muted-foreground",children:"No results found"}):t.jsxs("div",{className:B?"space-y-0.5":"space-y-2",children:[d.slice(0,B?5:10).map((D,w)=>t.jsx(Do,{message:D,onNavigate:Q,compact:B},`${D.sessionId}-${D.messageId}-${w}`)),d.length>(B?5:10)&&t.jsxs("div",{className:"text-xs text-muted-foreground text-center",children:["+",d.length-(B?5:10)," more"]})]})]})}case"get_session_context":case"get_parent_session":{const d=e==="get_parent_session"?a.parentSession:a.session,u=a.stats,D=a.messages;return d?B?t.jsx("div",{className:"p-1",children:t.jsx(Fg,{session:d,onNavigate:Q,compact:!0})}):t.jsxs("div",{className:"p-2 space-y-3",children:[t.jsx(Fg,{session:d,onNavigate:Q}),u&&t.jsxs("div",{className:"flex gap-4 text-xs text-muted-foreground",children:[u.totalMessages!==void 0&&t.jsxs("span",{children:[u.totalMessages," messages"]}),u.totalToolCalls!==void 0&&t.jsxs("span",{children:[u.totalToolCalls," tool calls"]})]}),D&&D.length>0&&t.jsxs("div",{className:"space-y-1",children:[t.jsx("div",{className:"text-xs font-medium text-muted-foreground",children:"Recent messages:"}),t.jsx("div",{className:"space-y-1 max-h-48 overflow-y-auto",children:D.slice(0,5).map(w=>t.jsxs("div",{className:"text-xs p-1.5 rounded bg-muted/30",children:[t.jsxs("span",{className:"font-medium capitalize text-foreground/70",children:[w.role,":"," "]}),t.jsx("span",{className:"text-foreground/60 line-clamp-2",children:w.content})]},w.id))})]})]}):t.jsx("div",{className:`text-xs text-muted-foreground ${B?"p-1":"p-2"}`,children:"Session not found"})}default:return t.jsx("pre",{className:"text-xs p-2 overflow-auto max-h-48",children:JSON.stringify(a,null,2)})}};return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:e,isExpanded:s,onToggle:o,isError:i,colorVariant:"default",canExpand:!0,children:[!B&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 min-w-0 truncate",children:c()})]}),!i&&!B&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(st,{children:"Done"}),t.jsx(eA,{}),t.jsx(vA,{children:I})]}),i&&!B&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(Mt,{children:"Error"}),t.jsxs(vA,{children:["· ",I]})]})]}),s&&i&&E&&t.jsx(OA,{error:E}),s&&!i&&t.jsx("div",{className:B?"mt-1 ml-3":"mt-2 ml-5",children:B?t.jsx("div",{className:"border border-border rounded-md overflow-hidden max-h-48 overflow-y-auto",children:n()}):t.jsx(dA,{title:"results",maxHeight:"max-h-96",children:n()})})]})}const nI='"JetBrainsMono NFM", monospace';let wo=!1,Kt=null;function CI(){return wo?Promise.resolve():Kt||(Kt=II().then(()=>{wo=!0}),Kt)}async function II(){if(typeof document>"u"||!("FontFace"in window))return;const A=[{file:"JetBrainsMonoNerdFontMono-Regular.woff2",weight:"400",style:"normal"},{file:"JetBrainsMonoNerdFontMono-Bold.woff2",weight:"700",style:"normal"},{file:"JetBrainsMonoNerdFontMono-Italic.woff2",weight:"400",style:"italic"},{file:"JetBrainsMonoNerdFontMono-BoldItalic.woff2",weight:"700",style:"italic"}].map(async g=>{try{const s=new URL(Object.assign({"../assets/fonts/JetBrainsMonoNerdFontMono-Bold.woff2":SQ,"../assets/fonts/JetBrainsMonoNerdFontMono-BoldItalic.woff2":KQ,"../assets/fonts/JetBrainsMonoNerdFontMono-Italic.woff2":JQ,"../assets/fonts/JetBrainsMonoNerdFontMono-Regular.woff2":RQ})[`../assets/fonts/${g.file}`],import.meta.url).href,Q=await new FontFace("JetBrainsMono NFM",`url("${s}") format("woff2")`,{weight:g.weight,style:g.style}).load();document.fonts.add(Q)}catch{}});await Promise.allSettled(A)}const lI=/[\x1B\x9B][[()#;?]*(?:[0-9]{1,4}(?:;[0-9]{0,4})*)?[0-9A-ORZcf-nq-uy=><~]/g,cI=/[\x00-\x08\x0B\x0C\x0E-\x1F\x7F]/g;function dI(e){return e.replace(lI,"").replace(cI,"").replace(/\\n/g,`
98
98
  `).replace(/\r\n/g,`
99
99
  `).replace(/\r/g,`
100
- `)}function uI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const[,Q]=l.useState(!1);l.useEffect(()=>{CI().then(()=>Q(!0))},[]);const B=e.result||{},a=e.args||{},r=String(a.operation||a.command||""),i=typeof B=="object"&&"ok"in B&&B.ok===!1,E=i&&"error"in B&&typeof B.error=="string"?B.error:null,I=i&&"stack"in B&&typeof B.stack=="string"?B.stack:void 0,c=KA(A),n=String(B.terminalId||a.terminalId||""),C=n.length>12?`${n.slice(0,12)}…`:n,d=String(B.purpose||a.purpose||""),u=String(B.command||a.command||""),D=()=>{const M=B.pid?`PID ${B.pid}`:"";return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-1 text-xs",children:[u&&t.jsxs("div",{className:"flex items-center gap-2 text-foreground/70",children:[t.jsx(we,{className:"h-3 w-3"}),t.jsx("code",{className:"font-mono",children:u})]}),d&&t.jsx("div",{className:"text-muted-foreground/70",children:d}),t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground/60",children:[C&&t.jsx("span",{className:"font-mono",children:C}),M&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:M})]})]})]})},w=()=>{const M=String(B.text||B.output||""),x=dI(M),F=String(B.status||""),p=B.exitCode,f=typeof B.lines=="number"?B.lines:0;return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/70",children:[C&&t.jsx("span",{className:"font-mono",children:C}),t.jsx("span",{children:"·"}),t.jsxs("span",{children:[f," lines"]}),t.jsx("span",{children:"·"}),t.jsxs("span",{className:F==="running"?"text-emerald-600 dark:text-emerald-400":"",children:[F,F==="exited"&&p!==void 0?` (${p})`:""]})]}),x.trim()&&t.jsx(dA,{title:"output",copyText:x,maxHeight:"max-h-[30rem]",children:t.jsx("pre",{className:"px-3 py-2 text-xs text-foreground/85 whitespace-pre-wrap break-words overflow-x-auto",style:{fontFamily:nI},children:x})})]})},h=()=>{const M=Array.isArray(B.terminals)?B.terminals:[],x=typeof B.count=="number"?B.count:M.length;return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-1 text-xs",children:[t.jsxs("div",{className:"text-muted-foreground/70",children:[x," terminal",x!==1?"s":""]}),M.slice(0,8).map((F,p)=>t.jsxs("div",{className:"flex items-center gap-2 text-foreground/70 font-mono",children:[t.jsx("span",{className:`h-2 w-2 rounded-full ${F.status==="running"?"bg-emerald-500":"bg-muted-foreground/40"}`}),t.jsx("span",{className:"truncate max-w-[100px]",children:String(F.id||"").slice(0,12)}),t.jsx("span",{className:"text-muted-foreground/60 truncate",children:String(F.purpose||"")})]},String(F.id||p)))]})},m=()=>{const M=String(a.input||"");return M?t.jsx("div",{className:"mt-2 ml-5 text-xs",children:t.jsx("code",{className:"font-mono text-foreground/70 whitespace-pre-wrap",children:M})}):null},y=`terminal ${r||"terminal"}`,G=!i&&(r==="start"||r==="read"||r==="list"||r==="write"&&(a.input||B.message));return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:y,isExpanded:g,onToggle:s,isError:!!i,colorVariant:"amber",canExpand:!!G||!!i,children:[!o&&C&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 font-mono text-[11px]",children:C})]}),!o&&d&&!C&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 text-[11px] truncate max-w-xs",children:d})]}),!i&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(st,{children:"ok"}),t.jsx(eA,{}),t.jsx(vA,{children:c})]}),i&&!o&&t.jsxs(vA,{children:["· ",c]})]}),g&&i&&E&&t.jsx(OA,{error:E,stack:I,showStack:!0}),g&&!i&&r==="start"&&D(),g&&!i&&r==="read"&&w(),g&&!i&&r==="list"&&h(),g&&!i&&r==="write"&&m()]})}function hI(e){const A=e.indexOf("__");return A===-1?{server:"",tool:e}:{server:e.slice(0,A),tool:e.slice(A+2)}}function DI(e){return e.includes("__")}function pI({toolName:e,contentJson:A,toolDurationMs:g,isExpanded:s,onToggle:o,compact:Q}){const{server:B,tool:a}=hI(e),r=A.result||{},i=A.args||{},E=KA(g),I=document?.documentElement.classList.contains("dark")?ce:de,c=typeof r=="object"&&"ok"in r&&r.ok===!1,n=c&&"error"in r&&typeof r.error=="string"?r.error:typeof A.error=="string"?A.error:null,C=c&&"stack"in r&&typeof r.stack=="string"?r.stack:void 0,d=typeof r.result=="string"?r.result:r.result&&typeof r.result=="object"?JSON.stringify(r.result,null,2):null,u=Array.isArray(r.images)?r.images:[],D=u.length>0,w=!c&&(d||Object.keys(r).length>0||D),h=d||JSON.stringify(r,null,2),m=h.startsWith("{")||h.startsWith("["),k=Object.entries(i).slice(0,3).map(([G,M])=>{const x=typeof M=="string"?M.length>30?`${M.slice(0,27)}…`:M:JSON.stringify(M);return`${G}=${x}`}).join(" "),y=B?`${B} › ${a}`:a;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:y,isExpanded:s,onToggle:o,isError:!!c,colorVariant:"purple",canExpand:!!w||!!c||D,children:[!Q&&k&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/60 truncate max-w-xs font-mono text-[11px]",children:k})]}),!c&&!Q&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(st,{children:"ok"}),t.jsx(eA,{}),t.jsx(vA,{children:E})]}),c&&!Q&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(Mt,{children:"error"}),t.jsx(eA,{}),t.jsx(vA,{children:E})]})]}),s&&c&&n&&t.jsx(OA,{error:n,stack:C,showStack:!0}),s&&!c&&w&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[D&&t.jsx(BB,{images:u}),h&&!D&&t.jsx(dA,{title:"result",icon:t.jsx(ht,{className:"h-3 w-3"}),copyText:h,maxHeight:"max-h-[30rem]",children:t.jsx(WA,{language:m?"json":"text",style:I,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:h})})]})]})}function wI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=KA(A),r=Array.isArray(B.tools)?B.tools:[],i=Array.isArray(Q.loaded)?Q.loaded:[],E=Array.isArray(Q.notFound)?Q.notFound:[],I=Q.ok===!1,c=i.length>0||E.length>0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"load_mcp_tools",isExpanded:g,onToggle:s,isError:I,colorVariant:"purple",canExpand:c,children:[!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs("span",{className:"text-foreground/60 font-mono text-[11px]",children:[r.length," tool",r.length!==1?"s":""]})]}),!I&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(st,{children:[i.length," loaded"]}),t.jsx(eA,{}),t.jsx(vA,{children:a})]}),I&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(Mt,{children:"error"}),t.jsx(eA,{}),t.jsx(vA,{children:a})]})]}),g&&c&&t.jsxs("div",{className:"mt-1.5 ml-5 flex flex-col gap-1",children:[i.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx(Ae,{className:"h-3 w-3 text-green-500"}),t.jsx(ht,{className:"h-3 w-3 text-purple-400"}),t.jsx("span",{className:"font-mono text-foreground/70",children:n})]},n)),E.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx(kA,{className:"h-3 w-3 text-red-400"}),t.jsx("span",{className:"font-mono text-foreground/40 line-through",children:n})]},n))]})]})}function mI({part:e}){const[A,g]=l.useState(!0),s=l.useRef(null),o=l.useRef(!1);let Q="";const B=e.contentJson||e.content;return B&&typeof B=="object"&&"text"in B?Q=String(B.text):typeof B=="string"&&(Q=B),l.useEffect(()=>{s.current&&A&&!e.completedAt&&!o.current&&(s.current.scrollTop=s.current.scrollHeight)},[Q,A,e.completedAt]),!Q||!Q.trim()?null:t.jsxs("div",{className:"w-full",children:[t.jsxs("button",{type:"button",onClick:()=>g(!A),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors w-full",children:[A?t.jsx(PA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0"}),t.jsx("span",{className:"font-medium",children:"Reasoning"}),!e.completedAt&&t.jsx("span",{className:"text-muted-foreground/60 animate-pulse",children:"thinking..."})]}),A&&t.jsx("div",{ref:s,className:"mt-2 p-3 bg-muted/30 rounded-md border border-border max-h-48 overflow-y-auto",role:"log",onMouseEnter:()=>{o.current=!0},onMouseLeave:()=>{o.current=!1},children:t.jsx("div",{className:"text-sm text-muted-foreground whitespace-pre-wrap font-mono",children:Q})})]})}const xI={Read:"read",Write:"write",Edit:"edit",Ls:"ls",Tree:"tree",Cd:"cd",Pwd:"pwd",Glob:"glob",Grep:"ripgrep",Bash:"bash",Terminal:"terminal",GitStatus:"git_status",GitDiff:"git_diff",GitCommit:"git_commit",ApplyPatch:"apply_patch",UpdateTodos:"update_todos",UpdatePlan:"update_todos",ProgressUpdate:"progress_update",Finish:"finish",WebSearch:"websearch",LoadMcpTools:"load_mcp_tools"};function fI(e){return xI[e]??e}function mo({toolName:e,contentJson:A,toolDurationMs:g,debug:s,onNavigateToSession:o,compact:Q,sessionId:B,onRetry:a,onCompact:r}){const[i,E]=l.useState(!1),I=fI(e),n={contentJson:A,toolDurationMs:g??void 0,isExpanded:i,onToggle:()=>E(!i),compact:Q};if(s)return t.jsx(QI,{...n,toolName:e});switch(I){case"read":return t.jsx(OC,{...n});case"write":return t.jsx(TC,{...n});case"edit":return t.jsx(YC,{...n});case"bash":return t.jsx(WC,{...n});case"git_status":return t.jsx(XC,{...n});case"git_diff":return t.jsx(_C,{...n});case"git_commit":return t.jsx($C,{...n});case"apply_patch":return t.jsx(AI,{...n});case"terminal":return t.jsx(uI,{...n});case"ls":return t.jsx(eI,{...n});case"tree":return t.jsx(tI,{...n});case"ripgrep":case"grep":case"glob":return t.jsx(gI,{...n});case"websearch":return t.jsx(iI,{...n});case"finish":return t.jsx(sI,{...n});case"update_todos":case"update_plan":return t.jsx(BI,{...n});case"progress_update":return t.jsx(aI,{...n});case"load_mcp_tools":return t.jsx(wI,{...n});case"error":return t.jsx(rI,{...n,sessionId:B,onRetry:a,onCompact:r});case"query_sessions":case"query_messages":case"search_history":case"get_session_context":case"get_parent_session":case"present_action":return t.jsx(EI,{toolName:e,...n,onNavigateToSession:o});default:return DI(I)?t.jsx(pI,{...n,toolName:e}):t.jsx(oI,{...n,toolName:e})}}function As(e){const A=e.contentJson;if(A&&typeof A=="object")return A;try{if(e.content){const g=JSON.parse(e.content);if(g&&typeof g=="object"&&!Array.isArray(g))return g}}catch{}return null}function NI(e){const A=As(e);if(!A)return;const g=A.args;if(g&&typeof g=="object"&&!Array.isArray(g))return g}function kI(e){if(!e)return null;const A=["cmd","command","script","input"];for(const g of A){const s=e[g];if(typeof s=="string"&&s.trim().length>0)return s.trim()}return null}function MI(e,A){if(!A)return null;const g=[{key:"path",match:!0},{key:"file",match:!0},{key:"target",match:!0},{key:"cwd",match:!0},{key:"query",match:!0},{key:"pattern",match:!0},{key:"glob",match:!0},{key:"dir",match:!0}];for(const{key:s}of g){const o=A[s];if(typeof o=="string"&&o.trim().length>0)return{key:s,value:o.trim()}}if(e==="bash"){const s=A.command;if(typeof s=="string"&&s.trim().length>0)return{key:"command",value:s.trim()}}return null}function yI(e,A){if(!e)return null;const g=[];for(const[o,Q]of Object.entries(e))if(!(A&&o===A)){if(typeof Q=="string"||typeof Q=="number"){const B=`${o}=${String(Q)}`;g.push(B)}if(g.length>=3)break}if(!g.length)return null;const s=g.join(" ");return s.length>120?`${s.slice(0,117)}…`:s}const xo=l.memo(function({part:A,showLine:g,isLastToolCall:s,isLastProgressUpdate:o,onNavigateToSession:Q,compact:B,pendingApproval:a,onApprove:r,onReject:i,sessionId:E,onRetry:I,onCompact:c}){if(A.type==="tool_call"&&!s&&!a||A.type==="tool_result"&&A.toolName==="progress_update"&&!o)return null;if(A.type==="text"){const h=A.contentJson||A.content;let m="";if(h&&typeof h=="object"&&"text"in h?m=String(h.text):typeof h=="string"&&(m=h),!m||!m.trim())return null}if(A.type==="reasoning"){const h=A.contentJson||A.content;let m="";if(h&&typeof h=="object"&&"text"in h?m=String(h.text):typeof h=="string"&&(m=h),!m||!m.trim())return null}const n=A.type==="tool_call"||A.type==="tool_result",C=["flex-1","min-w-0","max-w-full"];n||A.type==="reasoning"?C.push("pt-1"):A.type==="error"?C.push("pt-0.5"):A.type==="text"?(C.push("pt-0"),C.push("-mt-0.5")):C.push("pt-0");const d=C.join(" "),u=()=>{if(A.type==="reasoning")return t.jsx(Es,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-300"});if(A.type==="tool_call")return t.jsx(CA,{className:"h-4 w-4 text-amber-600 dark:text-amber-300 animate-spin"});if(A.type==="error")return As(A)?.isAborted===!0?t.jsx(ia,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}):t.jsx(le,{className:"h-4 w-4 text-red-600 dark:text-red-400"});if(A.type==="tool_result"){const h=A.toolName||"";return h==="read"?t.jsx(sg,{className:"h-4 w-4 text-blue-600 dark:text-blue-300"}):h==="write"?t.jsx(Pe,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="edit"?t.jsx(Pe,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="ls"?t.jsx(ra,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-300"}):h==="tree"?t.jsx(lt,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-300"}):h==="bash"?t.jsx(we,{className:"h-4 w-4 text-muted-foreground"}):h==="ripgrep"||h==="grep"||h==="glob"?t.jsx(ut,{className:"h-4 w-4 text-amber-600 dark:text-amber-300"}):h==="apply_patch"?t.jsx(Rs,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="git_status"?t.jsx(XA,{className:"h-4 w-4 text-blue-600 dark:text-blue-300"}):h==="git_diff"?t.jsx(Rs,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="git_commit"?t.jsx(Vt,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="finish"?t.jsx(Ae,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="query_sessions"||h==="query_messages"||h==="search_history"||h==="get_session_context"||h==="get_parent_session"?t.jsx(Ea,{className:"h-4 w-4 text-teal-600 dark:text-teal-300"}):h==="terminal"?t.jsx(we,{className:"h-4 w-4 text-amber-600 dark:text-amber-300"}):h.includes("__")?t.jsx(ht,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):t.jsx(we,{className:"h-4 w-4 text-muted-foreground"})}return t.jsx(Te,{className:"h-4 w-4 text-violet-600 dark:text-violet-300"})},D=()=>{const h=A.toolName||"";let m;try{A.contentJson&&typeof A.contentJson=="object"?m=A.contentJson:typeof A.content=="string"?m=JSON.parse(A.content):m={}}catch{m={result:A.content}}return t.jsx(mo,{toolName:h,contentJson:m,toolDurationMs:A.toolDurationMs,debug:!1,onNavigateToSession:Q,compact:B})},w=()=>{if(A.type==="reasoning")return t.jsx(mI,{part:A});if(A.type==="text"){let h="";const m=A.contentJson||A.content;return m&&typeof m=="object"&&"text"in m?h=String(m.text):typeof m=="string"?h=m:m&&(h=JSON.stringify(m,null,2)),t.jsxs("div",{className:"relative group",children:[t.jsx("div",{className:"absolute -top-1 right-0 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:h,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"md"})}),t.jsx("div",{className:"text-base text-foreground leading-relaxed markdown-content max-w-full overflow-x-auto",children:t.jsx(QQ,{remarkPlugins:[BQ],components:{a:({href:k,children:y,...G})=>t.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",onClick:M=>{window.self!==window.top&&k&&(M.preventDefault(),window.parent.postMessage({type:"otto-open-url",url:k},"*"))},...G,children:y}),pre:({children:k,...y})=>{const G=(()=>{if(!k)return"";const M=Array.isArray(k)?k[0]:k;if(M&&typeof M=="object"&&"props"in M){const x=M.props;if(typeof x.children=="string")return x.children}return""})();return t.jsxs("div",{className:"relative group/code my-3",children:[t.jsx("div",{className:"absolute top-2 right-2 opacity-0 group-hover/code:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:G,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"sm"})}),t.jsx("pre",{...y,className:"overflow-x-auto",children:k})]})},table:({children:k,...y})=>t.jsx("div",{className:"overflow-x-auto max-w-full my-3",children:t.jsx("table",{...y,children:k})})},children:h})}),h.length>500&&t.jsx("div",{className:"absolute -bottom-1 right-0 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:h,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"md"})})]})}if(A.type==="error"){let h;try{A.contentJson&&typeof A.contentJson=="object"?h=A.contentJson:typeof A.content=="string"?h=JSON.parse(A.content):h={}}catch{h={message:A.content||"Unknown error"}}return t.jsx(mo,{toolName:"error",contentJson:h,toolDurationMs:A.toolDurationMs,debug:!1,compact:B,sessionId:E,onRetry:I,onCompact:c})}if(A.type==="tool_call"){const h=As(A),m=A.toolName||(typeof h?.name=="string"?h.name:"tool"),k=m.includes("__")?m.replace("__"," › "):m.replace(/_/g," "),y=NI(A),G=a?.args,M=y||G,x=MI(m,M),F=yI(M,x?.key),p=m==="bash"?kI(M):null,f=[];if(p?f.push({key:"cmd",node:t.jsx("code",{className:"font-mono text-foreground/90 truncate max-w-xs",children:p})}):x&&f.push({key:"primary",node:t.jsx("code",{className:"font-mono text-foreground/85 truncate max-w-xs",children:x.value})}),F&&f.push({key:"args",node:t.jsx("span",{className:"text-muted-foreground/80 truncate max-w-xs",children:F})}),a&&a.callId===A.toolCallId&&r&&i)return t.jsx(jC,{toolName:m,args:M,pendingApproval:a,onApprove:r,onReject:i});f.length===0&&f.push({key:"running",node:t.jsx("span",{className:"text-muted-foreground/75",children:"running…"})});const b=["flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-foreground/80 max-w-full"];return A.ephemeral&&b.push("animate-pulse"),t.jsxs("div",{className:b.join(" "),children:[t.jsx("span",{className:"font-medium text-foreground",children:k}),f.map(S=>t.jsxs(l.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/65",children:"·"}),S.node]},S.key))]})}return A.type==="tool_result"?D():null};return t.jsxs("div",{className:"flex gap-3 pb-2 relative max-w-full overflow-hidden",children:[t.jsxs("div",{className:"flex-shrink-0 w-6 flex items-start justify-center relative pt-0.5",children:[t.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full relative bg-background",children:u()}),g&&t.jsx("div",{className:"absolute left-1/2 -translate-x-1/2 w-[2px] bg-border z-0",style:{top:"1.25rem",bottom:"-0.5rem"}})]}),t.jsx("div",{className:d,children:w()})]})},(e,A)=>e.part.id===A.part.id&&e.part.content===A.part.content&&e.part.contentJson===A.part.contentJson&&e.part.ephemeral===A.part.ephemeral&&e.part.completedAt===A.part.completedAt&&e.showLine===A.showLine&&e.isLastToolCall===A.isLastToolCall&&e.isLastProgressUpdate===A.isLastProgressUpdate&&e.onNavigateToSession===A.onNavigateToSession&&e.pendingApproval?.callId===A.pendingApproval?.callId&&e.onApprove===A.onApprove&&e.onReject===A.onReject),bg={currentMessageId:null,queuedMessages:[],queueLength:0};function GI(e){const{data:A}=FA({queryKey:["queueState",e],queryFn:()=>bg,enabled:!!e,initialData:bg,staleTime:1/0});return A??bg}function iB(e,A){const g=GI(e);if(!e||!g)return{isQueued:!1,isRunning:!1,position:null};if(g.currentMessageId===A)return{isQueued:!1,isRunning:!0,position:null};const s=g.queuedMessages.find(o=>o.messageId===A);return s?{isQueued:!0,isRunning:!1,position:s.position}:{isQueued:!1,isRunning:!1,position:null}}function FI(e){const A=sA();return nA({mutationFn:g=>{if(!e)throw new Error("No session ID");return v.createBranch(e,g)},onSuccess:()=>{A.invalidateQueries({queryKey:ke}),e&&A.invalidateQueries({queryKey:["branches",e]})}})}function rB(e){return FA({queryKey:["parentSession",e],queryFn:()=>{if(!e)throw new Error("No session ID");return v.getParentSession(e)},enabled:!!e})}function bI({isOpen:e,onClose:A,sessionId:g,message:s,onBranchCreated:o}){const Q=Ns(g),B=FI(g),[a,r]=l.useState(""),[i,E]=l.useState(!0),I=l.useId(),c=l.useId(),n=s.parts?.find(u=>u.type==="text")?.content||"",C=(()=>{try{return JSON.parse(n)?.text?.slice(0,100)||""}catch{return n.slice(0,100)}})(),d=async u=>{u.preventDefault();try{const D=await B.mutateAsync({fromMessageId:s.id,title:a.trim()||void 0,provider:i?Q?.provider:void 0,model:i?Q?.model:void 0,agent:i?Q?.agent:void 0});A(),o&&D.session&&o(D.session.id)}catch(D){console.error("Failed to create branch:",D)}};return t.jsx(Me,{isOpen:e,onClose:A,title:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(XA,{className:"h-5 w-5 text-primary"}),t.jsx("span",{children:"Branch Session"})]}),maxWidth:"md",children:t.jsxs("form",{onSubmit:d,className:"space-y-4",children:[t.jsxs("div",{className:"text-sm text-muted-foreground",children:[t.jsx("p",{children:"Creating branch from message:"}),t.jsxs("p",{className:"mt-1 p-2 bg-muted/50 rounded text-foreground italic truncate",children:['"',C,'..."']})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{htmlFor:I,className:"block text-sm font-medium text-foreground",children:"Branch Title (optional)"}),t.jsx("input",{id:I,type:"text",value:a,onChange:u=>r(u.target.value),placeholder:`Branch of ${Q?.title||"Untitled"}`,className:"w-full px-3 py-2 bg-background border border-border rounded-md text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/50"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{id:c,type:"checkbox",checked:i,onChange:u=>E(u.target.checked),className:"h-4 w-4 rounded border-border text-primary focus:ring-primary/50"}),t.jsx("label",{htmlFor:c,className:"text-sm text-foreground",children:"Use same provider/model/agent as parent"})]}),Q&&t.jsx("div",{className:"text-xs text-muted-foreground bg-muted/30 rounded p-2",children:t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("span",{children:[t.jsx("strong",{children:"Provider:"})," ",Q.provider]}),t.jsxs("span",{children:[t.jsx("strong",{children:"Model:"})," ",Q.model]}),t.jsxs("span",{children:[t.jsx("strong",{children:"Agent:"})," ",Q.agent]})]})}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{type:"button",onClick:A,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:B.isPending,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:B.isPending?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):t.jsxs(t.Fragment,{children:[t.jsx(XA,{className:"h-4 w-4"}),"Create Branch"]})})]}),B.isError&&t.jsx("p",{className:"text-sm text-red-500",children:B.error?.message||"Failed to create branch"})]})})}const fo=["Generating...","Cooking up something...","Thinking...","Processing...","Working on it...","Crafting response...","Brewing magic...","Computing..."];function UI(e){const A=e.split("").reduce((g,s)=>g+s.charCodeAt(0),0);return fo[A%fo.length]}const EB=l.memo(function({sessionId:A,message:g,showHeader:s,hasNextAssistantMessage:o,onBranchCreated:Q,compact:B,showBranchButton:a=!0,onNavigateToSession:r,onRetry:i,onCompact:E}){const{isQueued:I}=iB(A,g.id),[c,n]=l.useState(!1),[C,d]=l.useState(!1),[u,D]=l.useState(!1),{pendingApprovals:w,removePendingApproval:h}=ms(),m=l.useCallback(async J=>{if(A)try{await v.approveToolCall(A,J,!0),h(J)}catch(H){console.error("Failed to approve tool call:",H)}},[A,h]),k=l.useCallback(async J=>{if(A)try{await v.approveToolCall(A,J,!1),h(J)}catch(H){console.error("Failed to reject tool call:",H)}},[A,h]),y=l.useMemo(()=>w.filter(J=>J.messageId===g.id),[w,g.id]),G=l.useCallback(async()=>{if(A)try{await Promise.all(y.map(J=>v.approveToolCall(A,J.callId,!0)));for(const J of y)h(J.callId)}catch(J){console.error("Failed to approve all tool calls:",J)}},[A,y,h]),M=l.useMemo(()=>[...g.parts||[]].sort((H,z)=>{const AA=(H.index??0)-(z.index??0);return AA!==0?AA:(H.startedAt??0)-(z.startedAt??0)}),[g.parts]),x=M.some(J=>J.toolName==="finish"),F=M.reduce((J,H,z)=>H.type==="tool_result"&&H.toolName==="progress_update"?z:J,-1),p=F>=0?M[F]:null,f=M.some(J=>!(J.type==="tool_result"&&J.toolName==="progress_update")),N=M.findIndex(J=>!(J.type==="tool_result"&&J.toolName==="progress_update")),b=g.status==="pending"&&!x&&!!p,S=g.status==="pending"&&!x&&!p&&!I,O=J=>J?new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",L=g.status==="complete",R=l.useCallback(()=>{const J=M.filter(H=>H.type==="text").map(H=>{try{return JSON.parse(H.content||"{}")?.text||""}catch{return H.content||""}}).join(`
100
+ `)}function uI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const[,Q]=l.useState(!1);l.useEffect(()=>{CI().then(()=>Q(!0))},[]);const B=e.result||{},a=e.args||{},r=String(a.operation||a.command||""),i=typeof B=="object"&&"ok"in B&&B.ok===!1,E=i&&"error"in B&&typeof B.error=="string"?B.error:null,I=i&&"stack"in B&&typeof B.stack=="string"?B.stack:void 0,c=KA(A),n=String(B.terminalId||a.terminalId||""),C=n.length>12?`${n.slice(0,12)}…`:n,d=String(B.purpose||a.purpose||""),u=String(B.command||a.command||""),D=()=>{const M=B.pid?`PID ${B.pid}`:"";return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-1 text-xs",children:[u&&t.jsxs("div",{className:"flex items-center gap-2 text-foreground/70",children:[t.jsx(we,{className:"h-3 w-3"}),t.jsx("code",{className:"font-mono",children:u})]}),d&&t.jsx("div",{className:"text-muted-foreground/70",children:d}),t.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground/60",children:[C&&t.jsx("span",{className:"font-mono",children:C}),M&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsx("span",{children:M})]})]})]})},w=()=>{const M=String(B.text||B.output||""),x=dI(M),F=String(B.status||""),p=B.exitCode,f=typeof B.lines=="number"?B.lines:0;return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground/70",children:[C&&t.jsx("span",{className:"font-mono",children:C}),t.jsx("span",{children:"·"}),t.jsxs("span",{children:[f," lines"]}),t.jsx("span",{children:"·"}),t.jsxs("span",{className:F==="running"?"text-emerald-600 dark:text-emerald-400":"",children:[F,F==="exited"&&p!==void 0?` (${p})`:""]})]}),x.trim()&&t.jsx(dA,{title:"output",copyText:x,maxHeight:"max-h-[30rem]",children:t.jsx("pre",{className:"px-3 py-2 text-xs text-foreground/85 whitespace-pre-wrap break-words overflow-x-auto",style:{fontFamily:nI},children:x})})]})},h=()=>{const M=Array.isArray(B.terminals)?B.terminals:[],x=typeof B.count=="number"?B.count:M.length;return t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-1 text-xs",children:[t.jsxs("div",{className:"text-muted-foreground/70",children:[x," terminal",x!==1?"s":""]}),M.slice(0,8).map((F,p)=>t.jsxs("div",{className:"flex items-center gap-2 text-foreground/70 font-mono",children:[t.jsx("span",{className:`h-2 w-2 rounded-full ${F.status==="running"?"bg-emerald-500":"bg-muted-foreground/40"}`}),t.jsx("span",{className:"truncate max-w-[100px]",children:String(F.id||"").slice(0,12)}),t.jsx("span",{className:"text-muted-foreground/60 truncate",children:String(F.purpose||"")})]},String(F.id||p)))]})},m=()=>{const M=String(a.input||"");return M?t.jsx("div",{className:"mt-2 ml-5 text-xs",children:t.jsx("code",{className:"font-mono text-foreground/70 whitespace-pre-wrap",children:M})}):null},y=`terminal ${r||"terminal"}`,G=!i&&(r==="start"||r==="read"||r==="list"||r==="write"&&(a.input||B.message));return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:y,isExpanded:g,onToggle:s,isError:!!i,colorVariant:"amber",canExpand:!!G||!!i,children:[!o&&C&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 font-mono text-[11px]",children:C})]}),!o&&d&&!C&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/70 text-[11px] truncate max-w-xs",children:d})]}),!i&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(st,{children:"ok"}),t.jsx(eA,{}),t.jsx(vA,{children:c})]}),i&&!o&&t.jsxs(vA,{children:["· ",c]})]}),g&&i&&E&&t.jsx(OA,{error:E,stack:I,showStack:!0}),g&&!i&&r==="start"&&D(),g&&!i&&r==="read"&&w(),g&&!i&&r==="list"&&h(),g&&!i&&r==="write"&&m()]})}function hI(e){const A=e.indexOf("__");return A===-1?{server:"",tool:e}:{server:e.slice(0,A),tool:e.slice(A+2)}}function DI(e){return e.includes("__")}function pI({toolName:e,contentJson:A,toolDurationMs:g,isExpanded:s,onToggle:o,compact:Q}){const{server:B,tool:a}=hI(e),r=A.result||{},i=A.args||{},E=KA(g),I=document?.documentElement.classList.contains("dark")?ce:de,c=typeof r=="object"&&"ok"in r&&r.ok===!1,n=c&&"error"in r&&typeof r.error=="string"?r.error:typeof A.error=="string"?A.error:null,C=c&&"stack"in r&&typeof r.stack=="string"?r.stack:void 0,d=typeof r.result=="string"?r.result:r.result&&typeof r.result=="object"?JSON.stringify(r.result,null,2):null,u=Array.isArray(r.images)?r.images:[],D=u.length>0,w=!c&&(d||Object.keys(r).length>0||D),h=d||JSON.stringify(r,null,2),m=h.startsWith("{")||h.startsWith("["),k=Object.entries(i).slice(0,3).map(([G,M])=>{const x=typeof M=="string"?M.length>30?`${M.slice(0,27)}…`:M:JSON.stringify(M);return`${G}=${x}`}).join(" "),y=B?`${B} › ${a}`:a;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:y,isExpanded:s,onToggle:o,isError:!!c,colorVariant:"purple",canExpand:!!w||!!c||D,children:[!Q&&k&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx("span",{className:"text-foreground/60 truncate max-w-xs font-mono text-[11px]",children:k})]}),!c&&!Q&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(st,{children:"ok"}),t.jsx(eA,{}),t.jsx(vA,{children:E})]}),c&&!Q&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(Mt,{children:"error"}),t.jsx(eA,{}),t.jsx(vA,{children:E})]})]}),s&&c&&n&&t.jsx(OA,{error:n,stack:C,showStack:!0}),s&&!c&&w&&t.jsxs("div",{className:"mt-2 ml-5 flex flex-col gap-2 max-w-full",children:[D&&t.jsx(BB,{images:u}),h&&!D&&t.jsx(dA,{title:"result",icon:t.jsx(ht,{className:"h-3 w-3"}),copyText:h,maxHeight:"max-h-[30rem]",children:t.jsx(WA,{language:m?"json":"text",style:I,customStyle:{margin:0,padding:"0.75rem",fontSize:"0.75rem",lineHeight:"1.5",background:"transparent",maxWidth:"100%"},wrapLines:!0,wrapLongLines:!0,children:h})})]})]})}function wI({contentJson:e,toolDurationMs:A,isExpanded:g,onToggle:s,compact:o}){const Q=e.result||{},B=e.args||{},a=KA(A),r=Array.isArray(B.tools)?B.tools:[],i=Array.isArray(Q.loaded)?Q.loaded:[],E=Array.isArray(Q.notFound)?Q.notFound:[],I=Q.ok===!1,c=i.length>0||E.length>0;return t.jsxs("div",{className:"text-xs",children:[t.jsxs(ie,{toolName:"load_mcp_tools",isExpanded:g,onToggle:s,isError:I,colorVariant:"purple",canExpand:c,children:[!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs("span",{className:"text-foreground/60 font-mono text-[11px]",children:[r.length," tool",r.length!==1?"s":""]})]}),!I&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsxs(st,{children:[i.length," loaded"]}),t.jsx(eA,{}),t.jsx(vA,{children:a})]}),I&&!o&&t.jsxs(t.Fragment,{children:[t.jsx(eA,{}),t.jsx(Mt,{children:"error"}),t.jsx(eA,{}),t.jsx(vA,{children:a})]})]}),g&&c&&t.jsxs("div",{className:"mt-1.5 ml-5 flex flex-col gap-1",children:[i.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx(Ae,{className:"h-3 w-3 text-green-500"}),t.jsx(ht,{className:"h-3 w-3 text-purple-400"}),t.jsx("span",{className:"font-mono text-foreground/70",children:n})]},n)),E.map(n=>t.jsxs("div",{className:"flex items-center gap-1.5 text-[11px]",children:[t.jsx(kA,{className:"h-3 w-3 text-red-400"}),t.jsx("span",{className:"font-mono text-foreground/40 line-through",children:n})]},n))]})]})}function mI({part:e}){const[A,g]=l.useState(!0),s=l.useRef(null),o=l.useRef(!1);let Q="";const B=e.contentJson||e.content;return B&&typeof B=="object"&&"text"in B?Q=String(B.text):typeof B=="string"&&(Q=B),l.useEffect(()=>{s.current&&A&&!e.completedAt&&!o.current&&(s.current.scrollTop=s.current.scrollHeight)},[Q,A,e.completedAt]),!Q||!Q.trim()?null:t.jsxs("div",{className:"w-full",children:[t.jsxs("button",{type:"button",onClick:()=>g(!A),className:"flex items-center gap-2 text-xs text-muted-foreground hover:text-foreground transition-colors w-full",children:[A?t.jsx(PA,{className:"h-3 w-3 flex-shrink-0"}):t.jsx(xA,{className:"h-3 w-3 flex-shrink-0"}),t.jsx("span",{className:"font-medium",children:"Reasoning"}),!e.completedAt&&t.jsx("span",{className:"text-muted-foreground/60 animate-pulse",children:"thinking..."})]}),A&&t.jsx("div",{ref:s,className:"mt-2 p-3 bg-muted/30 rounded-md border border-border max-h-48 overflow-y-auto",role:"log",onMouseEnter:()=>{o.current=!0},onMouseLeave:()=>{o.current=!1},children:t.jsx("div",{className:"text-sm text-muted-foreground whitespace-pre-wrap font-mono",children:Q})})]})}const xI={Read:"read",Write:"write",Edit:"edit",Ls:"ls",Tree:"tree",Cd:"cd",Pwd:"pwd",Glob:"glob",Grep:"ripgrep",Bash:"bash",Terminal:"terminal",GitStatus:"git_status",GitDiff:"git_diff",GitCommit:"git_commit",ApplyPatch:"apply_patch",UpdateTodos:"update_todos",UpdatePlan:"update_todos",ProgressUpdate:"progress_update",Finish:"finish",WebSearch:"websearch",LoadMcpTools:"load_mcp_tools"};function fI(e){return xI[e]??e}function mo({toolName:e,contentJson:A,toolDurationMs:g,debug:s,onNavigateToSession:o,compact:Q,sessionId:B,onRetry:a,onCompact:r}){const[i,E]=l.useState(!1),I=fI(e),n={contentJson:A,toolDurationMs:g??void 0,isExpanded:i,onToggle:()=>E(!i),compact:Q};if(s)return t.jsx(QI,{...n,toolName:e});switch(I){case"read":return t.jsx(OC,{...n});case"write":return t.jsx(TC,{...n});case"edit":return t.jsx(YC,{...n});case"bash":return t.jsx(WC,{...n});case"git_status":return t.jsx(XC,{...n});case"git_diff":return t.jsx(_C,{...n});case"git_commit":return t.jsx($C,{...n});case"apply_patch":return t.jsx(AI,{...n});case"terminal":return t.jsx(uI,{...n});case"ls":return t.jsx(eI,{...n});case"tree":return t.jsx(tI,{...n});case"ripgrep":case"grep":case"glob":return t.jsx(gI,{...n});case"websearch":return t.jsx(iI,{...n});case"finish":return t.jsx(sI,{...n});case"update_todos":case"update_plan":return t.jsx(BI,{...n});case"progress_update":return t.jsx(aI,{...n});case"load_mcp_tools":return t.jsx(wI,{...n});case"error":return t.jsx(rI,{...n,sessionId:B,onRetry:a,onCompact:r});case"query_sessions":case"query_messages":case"search_history":case"get_session_context":case"get_parent_session":case"present_action":return t.jsx(EI,{toolName:e,...n,onNavigateToSession:o});default:return DI(I)?t.jsx(pI,{...n,toolName:e}):t.jsx(oI,{...n,toolName:e})}}function As(e){const A=e.contentJson;if(A&&typeof A=="object")return A;try{if(e.content){const g=JSON.parse(e.content);if(g&&typeof g=="object"&&!Array.isArray(g))return g}}catch{}return null}function NI(e){const A=As(e);if(!A)return;const g=A.args;if(g&&typeof g=="object"&&!Array.isArray(g))return g}function kI(e){if(!e)return null;const A=["cmd","command","script","input"];for(const g of A){const s=e[g];if(typeof s=="string"&&s.trim().length>0)return s.trim()}return null}function MI(e,A){if(!A)return null;const g=[{key:"path",match:!0},{key:"file",match:!0},{key:"target",match:!0},{key:"cwd",match:!0},{key:"query",match:!0},{key:"pattern",match:!0},{key:"glob",match:!0},{key:"dir",match:!0}];for(const{key:s}of g){const o=A[s];if(typeof o=="string"&&o.trim().length>0)return{key:s,value:o.trim()}}if(e==="bash"){const s=A.command;if(typeof s=="string"&&s.trim().length>0)return{key:"command",value:s.trim()}}return null}function yI(e,A){if(!e)return null;const g=[];for(const[o,Q]of Object.entries(e))if(!(A&&o===A)){if(typeof Q=="string"||typeof Q=="number"){const B=`${o}=${String(Q)}`;g.push(B)}if(g.length>=3)break}if(!g.length)return null;const s=g.join(" ");return s.length>120?`${s.slice(0,117)}…`:s}const xo=l.memo(function({part:A,showLine:g,isLastToolCall:s,isLastProgressUpdate:o,onNavigateToSession:Q,compact:B,pendingApproval:a,onApprove:r,onReject:i,sessionId:E,onRetry:I,onCompact:c}){if(A.type==="tool_call"&&!s&&!a||A.type==="tool_result"&&A.toolName==="progress_update"&&!o)return null;if(A.type==="text"){const h=A.contentJson||A.content;let m="";if(h&&typeof h=="object"&&"text"in h?m=String(h.text):typeof h=="string"&&(m=h),!m||!m.trim())return null}if(A.type==="reasoning"){const h=A.contentJson||A.content;let m="";if(h&&typeof h=="object"&&"text"in h?m=String(h.text):typeof h=="string"&&(m=h),!m||!m.trim())return null}const n=A.type==="tool_call"||A.type==="tool_result",C=["flex-1","min-w-0","max-w-full"];n||A.type==="reasoning"?C.push("pt-1"):A.type==="error"?C.push("pt-0.5"):A.type==="text"?(C.push("pt-0"),C.push("-mt-0.5")):C.push("pt-0");const d=C.join(" "),u=()=>{if(A.type==="reasoning")return t.jsx(Es,{className:"h-4 w-4 text-indigo-600 dark:text-indigo-300"});if(A.type==="tool_call")return t.jsx(CA,{className:"h-4 w-4 text-amber-600 dark:text-amber-300 animate-spin"});if(A.type==="error")return As(A)?.isAborted===!0?t.jsx(ia,{className:"h-4 w-4 text-amber-600 dark:text-amber-400"}):t.jsx(le,{className:"h-4 w-4 text-red-600 dark:text-red-400"});if(A.type==="tool_result"){const h=A.toolName||"";return h==="read"?t.jsx(sg,{className:"h-4 w-4 text-blue-600 dark:text-blue-300"}):h==="write"?t.jsx(Pe,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="edit"?t.jsx(Pe,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="ls"?t.jsx(ra,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-300"}):h==="tree"?t.jsx(lt,{className:"h-4 w-4 text-cyan-600 dark:text-cyan-300"}):h==="bash"?t.jsx(we,{className:"h-4 w-4 text-muted-foreground"}):h==="ripgrep"||h==="grep"||h==="glob"?t.jsx(ut,{className:"h-4 w-4 text-amber-600 dark:text-amber-300"}):h==="apply_patch"?t.jsx(Rs,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="git_status"?t.jsx(XA,{className:"h-4 w-4 text-blue-600 dark:text-blue-300"}):h==="git_diff"?t.jsx(Rs,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):h==="git_commit"?t.jsx(Vt,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="finish"?t.jsx(Ae,{className:"h-4 w-4 text-emerald-600 dark:text-emerald-300"}):h==="query_sessions"||h==="query_messages"||h==="search_history"||h==="get_session_context"||h==="get_parent_session"?t.jsx(Ea,{className:"h-4 w-4 text-teal-600 dark:text-teal-300"}):h==="terminal"?t.jsx(we,{className:"h-4 w-4 text-amber-600 dark:text-amber-300"}):h.includes("__")?t.jsx(ht,{className:"h-4 w-4 text-purple-600 dark:text-purple-300"}):t.jsx(we,{className:"h-4 w-4 text-muted-foreground"})}return t.jsx(Te,{className:"h-4 w-4 text-violet-600 dark:text-violet-300"})},D=()=>{const h=A.toolName||"";let m;try{A.contentJson&&typeof A.contentJson=="object"?m=A.contentJson:typeof A.content=="string"?m=JSON.parse(A.content):m={}}catch{m={result:A.content}}return t.jsx(mo,{toolName:h,contentJson:m,toolDurationMs:A.toolDurationMs,debug:!1,onNavigateToSession:Q,compact:B})},w=()=>{if(A.type==="reasoning")return t.jsx(mI,{part:A});if(A.type==="text"){let h="";const m=A.contentJson||A.content;return m&&typeof m=="object"&&"text"in m?h=String(m.text):typeof m=="string"?h=m:m&&(h=JSON.stringify(m,null,2)),t.jsxs("div",{className:"relative group",children:[t.jsx("div",{className:"absolute -top-1 right-0 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:h,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"md"})}),t.jsx("div",{className:"text-base text-foreground leading-relaxed markdown-content max-w-full overflow-x-auto",children:t.jsx(QQ,{remarkPlugins:[BQ],components:{a:({href:k,children:y,...G})=>t.jsx("a",{href:k,target:"_blank",rel:"noopener noreferrer",onClick:M=>{window.self!==window.top&&k&&(M.preventDefault(),window.parent.postMessage({type:"otto-open-url",url:k},"*"))},...G,children:y}),pre:({children:k,...y})=>{const G=(()=>{if(!k)return"";const M=Array.isArray(k)?k[0]:k;if(M&&typeof M=="object"&&"props"in M){const x=M.props;if(typeof x.children=="string")return x.children}return""})();return t.jsxs("div",{className:"relative group/code my-3",children:[t.jsx("div",{className:"absolute top-2 right-2 opacity-0 group-hover/code:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:G,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"sm"})}),t.jsx("pre",{...y,className:"overflow-x-auto",children:k})]})},table:({children:k,...y})=>t.jsx("div",{className:"overflow-x-auto max-w-full min-w-0 my-3",children:t.jsx("table",{...y,children:k})})},children:h})}),h.length>500&&t.jsx("div",{className:"absolute -bottom-1 right-0 opacity-0 group-hover:opacity-100 transition-opacity z-10",children:t.jsx(Wt,{text:h,className:"bg-background/80 backdrop-blur-sm border border-border/50 shadow-sm",size:"md"})})]})}if(A.type==="error"){let h;try{A.contentJson&&typeof A.contentJson=="object"?h=A.contentJson:typeof A.content=="string"?h=JSON.parse(A.content):h={}}catch{h={message:A.content||"Unknown error"}}return t.jsx(mo,{toolName:"error",contentJson:h,toolDurationMs:A.toolDurationMs,debug:!1,compact:B,sessionId:E,onRetry:I,onCompact:c})}if(A.type==="tool_call"){const h=As(A),m=A.toolName||(typeof h?.name=="string"?h.name:"tool"),k=m.includes("__")?m.replace("__"," › "):m.replace(/_/g," "),y=NI(A),G=a?.args,M=y||G,x=MI(m,M),F=yI(M,x?.key),p=m==="bash"?kI(M):null,f=[];if(p?f.push({key:"cmd",node:t.jsx("code",{className:"font-mono text-foreground/90 truncate max-w-xs",children:p})}):x&&f.push({key:"primary",node:t.jsx("code",{className:"font-mono text-foreground/85 truncate max-w-xs",children:x.value})}),F&&f.push({key:"args",node:t.jsx("span",{className:"text-muted-foreground/80 truncate max-w-xs",children:F})}),a&&a.callId===A.toolCallId&&r&&i)return t.jsx(jC,{toolName:m,args:M,pendingApproval:a,onApprove:r,onReject:i});f.length===0&&f.push({key:"running",node:t.jsx("span",{className:"text-muted-foreground/75",children:"running…"})});const b=["flex flex-wrap items-center gap-x-2 gap-y-1 text-xs text-foreground/80 max-w-full"];return A.ephemeral&&b.push("animate-pulse"),t.jsxs("div",{className:b.join(" "),children:[t.jsx("span",{className:"font-medium text-foreground",children:k}),f.map(S=>t.jsxs(l.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/65",children:"·"}),S.node]},S.key))]})}return A.type==="tool_result"?D():null};return t.jsxs("div",{className:"flex gap-3 pb-2 relative max-w-full overflow-hidden",children:[t.jsxs("div",{className:"flex-shrink-0 w-6 flex items-start justify-center relative pt-0.5",children:[t.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full relative bg-background",children:u()}),g&&t.jsx("div",{className:"absolute left-1/2 -translate-x-1/2 w-[2px] bg-border z-0",style:{top:"1.25rem",bottom:"-0.5rem"}})]}),t.jsx("div",{className:d,children:w()})]})},(e,A)=>e.part.id===A.part.id&&e.part.content===A.part.content&&e.part.contentJson===A.part.contentJson&&e.part.ephemeral===A.part.ephemeral&&e.part.completedAt===A.part.completedAt&&e.showLine===A.showLine&&e.isLastToolCall===A.isLastToolCall&&e.isLastProgressUpdate===A.isLastProgressUpdate&&e.onNavigateToSession===A.onNavigateToSession&&e.pendingApproval?.callId===A.pendingApproval?.callId&&e.onApprove===A.onApprove&&e.onReject===A.onReject),bg={currentMessageId:null,queuedMessages:[],queueLength:0};function GI(e){const{data:A}=FA({queryKey:["queueState",e],queryFn:()=>bg,enabled:!!e,initialData:bg,staleTime:1/0});return A??bg}function iB(e,A){const g=GI(e);if(!e||!g)return{isQueued:!1,isRunning:!1,position:null};if(g.currentMessageId===A)return{isQueued:!1,isRunning:!0,position:null};const s=g.queuedMessages.find(o=>o.messageId===A);return s?{isQueued:!0,isRunning:!1,position:s.position}:{isQueued:!1,isRunning:!1,position:null}}function FI(e){const A=sA();return nA({mutationFn:g=>{if(!e)throw new Error("No session ID");return v.createBranch(e,g)},onSuccess:()=>{A.invalidateQueries({queryKey:ke}),e&&A.invalidateQueries({queryKey:["branches",e]})}})}function rB(e){return FA({queryKey:["parentSession",e],queryFn:()=>{if(!e)throw new Error("No session ID");return v.getParentSession(e)},enabled:!!e})}function bI({isOpen:e,onClose:A,sessionId:g,message:s,onBranchCreated:o}){const Q=Ns(g),B=FI(g),[a,r]=l.useState(""),[i,E]=l.useState(!0),I=l.useId(),c=l.useId(),n=s.parts?.find(u=>u.type==="text")?.content||"",C=(()=>{try{return JSON.parse(n)?.text?.slice(0,100)||""}catch{return n.slice(0,100)}})(),d=async u=>{u.preventDefault();try{const D=await B.mutateAsync({fromMessageId:s.id,title:a.trim()||void 0,provider:i?Q?.provider:void 0,model:i?Q?.model:void 0,agent:i?Q?.agent:void 0});A(),o&&D.session&&o(D.session.id)}catch(D){console.error("Failed to create branch:",D)}};return t.jsx(Me,{isOpen:e,onClose:A,title:t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(XA,{className:"h-5 w-5 text-primary"}),t.jsx("span",{children:"Branch Session"})]}),maxWidth:"md",children:t.jsxs("form",{onSubmit:d,className:"space-y-4",children:[t.jsxs("div",{className:"text-sm text-muted-foreground",children:[t.jsx("p",{children:"Creating branch from message:"}),t.jsxs("p",{className:"mt-1 p-2 bg-muted/50 rounded text-foreground italic truncate",children:['"',C,'..."']})]}),t.jsxs("div",{className:"space-y-2",children:[t.jsx("label",{htmlFor:I,className:"block text-sm font-medium text-foreground",children:"Branch Title (optional)"}),t.jsx("input",{id:I,type:"text",value:a,onChange:u=>r(u.target.value),placeholder:`Branch of ${Q?.title||"Untitled"}`,className:"w-full px-3 py-2 bg-background border border-border rounded-md text-foreground placeholder:text-muted-foreground focus:outline-none focus:ring-2 focus:ring-primary/50"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("input",{id:c,type:"checkbox",checked:i,onChange:u=>E(u.target.checked),className:"h-4 w-4 rounded border-border text-primary focus:ring-primary/50"}),t.jsx("label",{htmlFor:c,className:"text-sm text-foreground",children:"Use same provider/model/agent as parent"})]}),Q&&t.jsx("div",{className:"text-xs text-muted-foreground bg-muted/30 rounded p-2",children:t.jsxs("div",{className:"flex gap-4",children:[t.jsxs("span",{children:[t.jsx("strong",{children:"Provider:"})," ",Q.provider]}),t.jsxs("span",{children:[t.jsx("strong",{children:"Model:"})," ",Q.model]}),t.jsxs("span",{children:[t.jsx("strong",{children:"Agent:"})," ",Q.agent]})]})}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx("button",{type:"button",onClick:A,className:"px-4 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:"Cancel"}),t.jsx("button",{type:"submit",disabled:B.isPending,className:"px-4 py-2 text-sm bg-primary text-primary-foreground rounded-md hover:bg-primary/90 disabled:opacity-50 disabled:cursor-not-allowed flex items-center gap-2",children:B.isPending?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"h-4 w-4 animate-spin"}),"Creating..."]}):t.jsxs(t.Fragment,{children:[t.jsx(XA,{className:"h-4 w-4"}),"Create Branch"]})})]}),B.isError&&t.jsx("p",{className:"text-sm text-red-500",children:B.error?.message||"Failed to create branch"})]})})}const fo=["Generating...","Cooking up something...","Thinking...","Processing...","Working on it...","Crafting response...","Brewing magic...","Computing..."];function UI(e){const A=e.split("").reduce((g,s)=>g+s.charCodeAt(0),0);return fo[A%fo.length]}const EB=l.memo(function({sessionId:A,message:g,showHeader:s,hasNextAssistantMessage:o,onBranchCreated:Q,compact:B,showBranchButton:a=!0,onNavigateToSession:r,onRetry:i,onCompact:E}){const{isQueued:I}=iB(A,g.id),[c,n]=l.useState(!1),[C,d]=l.useState(!1),[u,D]=l.useState(!1),{pendingApprovals:w,removePendingApproval:h}=ms(),m=l.useCallback(async J=>{if(A)try{await v.approveToolCall(A,J,!0),h(J)}catch(H){console.error("Failed to approve tool call:",H)}},[A,h]),k=l.useCallback(async J=>{if(A)try{await v.approveToolCall(A,J,!1),h(J)}catch(H){console.error("Failed to reject tool call:",H)}},[A,h]),y=l.useMemo(()=>w.filter(J=>J.messageId===g.id),[w,g.id]),G=l.useCallback(async()=>{if(A)try{await Promise.all(y.map(J=>v.approveToolCall(A,J.callId,!0)));for(const J of y)h(J.callId)}catch(J){console.error("Failed to approve all tool calls:",J)}},[A,y,h]),M=l.useMemo(()=>[...g.parts||[]].sort((H,z)=>{const AA=(H.index??0)-(z.index??0);return AA!==0?AA:(H.startedAt??0)-(z.startedAt??0)}),[g.parts]),x=M.some(J=>J.toolName==="finish"),F=M.reduce((J,H,z)=>H.type==="tool_result"&&H.toolName==="progress_update"?z:J,-1),p=F>=0?M[F]:null,f=M.some(J=>!(J.type==="tool_result"&&J.toolName==="progress_update")),N=M.findIndex(J=>!(J.type==="tool_result"&&J.toolName==="progress_update")),b=g.status==="pending"&&!x&&!!p,S=g.status==="pending"&&!x&&!p&&!I,O=J=>J?new Date(J).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",L=g.status==="complete",R=l.useCallback(()=>{const J=M.filter(H=>H.type==="text").map(H=>{try{return JSON.parse(H.content||"{}")?.text||""}catch{return H.content||""}}).join(`
101
101
  `);navigator.clipboard.writeText(J),D(!0),setTimeout(()=>D(!1),2e3)},[M]),j=l.useCallback(()=>{d(!0)},[]);return I?null:t.jsxs("div",{className:"relative group",onMouseEnter:()=>n(!0),onMouseLeave:()=>n(!1),children:[s&&t.jsxs("div",{className:"pb-2 flex items-center justify-between",children:[t.jsxs("div",{className:"inline-flex items-center bg-violet-500/10 border border-violet-500/30 dark:bg-violet-500/5 dark:border-violet-500/20 rounded-full pr-3 md:pr-4 flex-shrink min-w-0",children:[t.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border border-violet-500/50 bg-violet-500/20 dark:bg-violet-500/10",children:t.jsx(Te,{className:"h-3.5 w-3.5 text-violet-700 dark:text-violet-300"})}),t.jsxs("div",{className:"flex items-center gap-x-1.5 md:gap-x-2 text-xs md:text-sm text-muted-foreground pl-2 md:pl-3 min-w-0",children:[g.agent&&!B&&t.jsx("span",{className:"font-medium text-violet-700 dark:text-violet-300 whitespace-nowrap",children:g.agent}),g.provider&&t.jsxs(t.Fragment,{children:[!B&&g.agent&&t.jsx("span",{className:"text-muted-foreground/50",children:"·"}),t.jsx(ZA,{provider:g.provider,size:14,className:"opacity-70"})]}),g.model&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"hidden md:inline text-muted-foreground/50",children:"·"}),t.jsx("span",{className:`hidden md:inline text-muted-foreground ${B?"truncate max-w-[120px]":""}`,title:g.model,children:g.model})]}),g.createdAt&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground/50",children:"·"}),t.jsx("span",{className:"text-muted-foreground whitespace-nowrap",children:O(g.createdAt)})]})]})]}),c&&L&&A&&a&&t.jsx("button",{type:"button",onClick:j,className:"ml-4 p-1.5 text-muted-foreground hover:text-primary transition-colors flex-shrink-0",title:"Branch from this message",children:t.jsx(XA,{className:"h-4 w-4"})})]}),t.jsxs("div",{className:"relative ml-1",children:[M.map((J,H)=>{const z=H===M.length-1,AA=J.type==="tool_call"&&J.toolCallId?w.find(oA=>oA.callId===J.toolCallId)??null:null,tA=J.type==="tool_result"&&J.toolName==="finish",lA=(!z||o)&&!tA,yA=J.type==="tool_call"&&z;return J.type==="tool_result"&&J.toolName==="progress_update"?null:t.jsx(xo,{part:J,showLine:lA,isFirstPart:H===N&&!s,isLastToolCall:yA,onNavigateToSession:r,compact:B,pendingApproval:AA,onApprove:m,onReject:k,sessionId:A,onRetry:i,onCompact:E},J.id)}),y.length>1&&t.jsxs("div",{className:"flex items-center gap-3 py-2 px-3 my-2 bg-amber-50 dark:bg-amber-950/30 border border-amber-200 dark:border-amber-800 rounded-lg",children:[t.jsx(Wo,{className:"h-4 w-4 text-amber-600 dark:text-amber-400 flex-shrink-0"}),t.jsxs("span",{className:"text-sm text-amber-800 dark:text-amber-200 flex-1",children:[y.length," tools waiting for approval"]}),t.jsxs("button",{type:"button",onClick:G,title:"Approve All (A)",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-amber-600 text-white hover:bg-amber-700 transition-colors",children:[t.jsx(na,{className:"w-3.5 h-3.5"}),"Approve All",t.jsx("kbd",{className:"ml-1 text-[10px] opacity-70",children:"A"})]})]}),b&&p&&t.jsx(xo,{part:p,showLine:o,isFirstPart:!f&&!s,isLastProgressUpdate:!0,compact:B},p.id),S&&t.jsxs("div",{className:"flex gap-3 pb-2 relative",children:[t.jsx("div",{className:"flex-shrink-0 w-6 flex items-start justify-center relative pt-0.5",children:t.jsx("div",{className:"flex h-5 w-5 shrink-0 items-center justify-center rounded-full relative bg-card text-violet-700 dark:bg-background dark:text-violet-300",children:t.jsx(Te,{className:"h-4 w-4"})})}),t.jsx("div",{className:"flex-1 pt-0.5",children:t.jsx("div",{className:"text-base text-foreground animate-pulse",children:UI(g.id)})})]})]}),L&&A&&t.jsx("div",{className:"grid ml-7 transition-[grid-template-rows] duration-200 ease-out",style:{gridTemplateRows:c?"1fr":"0fr"},children:t.jsx("div",{className:"overflow-hidden",children:t.jsxs("div",{className:"flex gap-2 mt-2",children:[a&&t.jsxs("button",{type:"button",onClick:j,className:"flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded transition-colors",children:[t.jsx(XA,{className:"h-3 w-3"}),"Branch"]}),t.jsx("button",{type:"button",onClick:R,className:"flex items-center gap-1.5 px-2 py-1 text-xs text-muted-foreground hover:text-foreground hover:bg-muted/50 rounded transition-colors",children:u?t.jsxs(t.Fragment,{children:[t.jsx(Ae,{className:"h-3 w-3 text-green-500"}),"Copied"]}):t.jsxs(t.Fragment,{children:[t.jsx(Ye,{className:"h-3 w-3"}),"Copy"]})})]})})}),C&&A&&t.jsx(bI,{isOpen:C,onClose:()=>d(!1),sessionId:A,message:g,onBranchCreated:Q})]})},(e,A)=>{const g=e.message.parts||[],s=A.message.parts||[];if(g.length!==s.length)return!1;for(let o=0;o<g.length;o++){const Q=g[o],B=s[o];if(Q.id!==B.id||Q.content!==B.content||Q.contentJson!==B.contentJson||Q.ephemeral!==B.ephemeral||Q.completedAt!==B.completedAt)return!1}return e.message.id===A.message.id&&e.message.status===A.message.status&&e.message.completedAt===A.message.completedAt&&e.showHeader===A.showHeader&&e.hasNextAssistantMessage===A.hasNextAssistantMessage&&e.isLastMessage===A.isLastMessage&&e.sessionId===A.sessionId&&e.compact===A.compact&&e.onNavigateToSession===A.onNavigateToSession}),nB=l.memo(function({sessionId:A,message:g,nextAssistantMessageId:s}){const[o,Q]=l.useState(null),B=g.parts||[],a=sA(),{isQueued:r,position:i}=iB(A,s??""),E=$g(p=>p.setPendingRestoreText),I=B.filter(p=>p.type==="text"),c=B.filter(p=>p.type==="image"),n=B.filter(p=>p.type==="file"),C=I[0];let d="";if(C){const p=C.contentJson||C.content;p&&typeof p=="object"&&"text"in p?d=String(p.text):typeof p=="string"?d=p:p&&(d=JSON.stringify(p,null,2))}const{researchContexts:u,cleanContent:D}=MC(d),w=[];for(const p of c)try{const f=p.contentJson||JSON.parse(p.content||"{}");if(f&&typeof f=="object"&&"data"in f){const N=f,b=`data:${N.mediaType};base64,${N.data}`;w.push({id:p.id,src:b})}}catch{}const h=[];for(const p of n)try{const f=p.contentJson||JSON.parse(p.content||"{}");if(f&&typeof f=="object"&&"type"in f){const N=f;if(N.type==="image"&&N.data){const b=`data:${N.mediaType};base64,${N.data}`;w.push({id:p.id,src:b})}else h.push({id:p.id,type:N.type,name:N.name})}}catch{}const m=p=>p?new Date(p).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"}):"",k=D.trim().length>0,y=w.length>0,G=h.length>0,M=u.length>0;if(!k&&!y&&!G&&!M)return null;const x=async()=>{if(!(!A||!s)){E(D);try{await v.removeFromQueue(A,s),a.invalidateQueries({queryKey:["messages",A]})}catch(p){console.error("Failed to cancel queued message:",p)}}},F=async()=>{if(!(!A||!s))try{await v.removeFromQueue(A,s),a.invalidateQueries({queryKey:["messages",A]})}catch(p){console.error("Failed to delete queued message:",p)}};return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"relative pb-8 pt-6",children:t.jsxs("div",{className:"flex gap-3 md:gap-4 justify-end",children:[t.jsxs("div",{className:"flex flex-col items-end min-w-0 flex-1 max-w-[calc(100%-3rem)] md:max-w-2xl",children:[t.jsxs("div",{className:"flex items-center gap-2 text-xs text-muted-foreground pb-2 justify-end",children:[t.jsx("span",{className:"font-medium text-emerald-700 dark:text-emerald-300",children:"You"}),g.createdAt&&t.jsx("span",{children:"·"}),g.createdAt&&t.jsx("span",{children:m(g.createdAt)}),r&&t.jsxs(t.Fragment,{children:[t.jsx("span",{children:"·"}),t.jsxs("span",{className:"inline-flex items-center gap-1 text-amber-600 dark:text-amber-400",children:[t.jsx(Cs,{className:"h-3 w-3"}),"Queued",i!==null&&i>0?` #${i+1}`:""]})]})]}),t.jsxs("div",{className:"inline-block max-w-full text-sm text-foreground leading-relaxed bg-emerald-500/5 border border-emerald-500/20 rounded-xl px-4 py-3 [word-break:break-word] overflow-hidden",children:[y&&t.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:w.map(p=>t.jsx("button",{type:"button",onClick:()=>Q(p.src),className:"w-16 h-16 rounded-lg overflow-hidden bg-muted hover:ring-2 hover:ring-primary/50 transition-all",children:t.jsx("img",{src:p.src,alt:"Attachment",className:"w-full h-full object-cover"})},p.id))}),G&&t.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:h.map(p=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-muted/50 border border-border",children:[p.type==="pdf"?t.jsx(be,{className:"w-4 h-4 text-red-500 flex-shrink-0"}):t.jsx(sg,{className:"w-4 h-4 text-blue-500 flex-shrink-0"}),t.jsx("span",{className:"text-xs truncate max-w-[150px]",children:p.name})]},p.id))}),M&&t.jsx("div",{className:"flex flex-wrap gap-2 mb-2",children:u.map(p=>t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-lg bg-teal-500/10 border border-teal-500/30",children:[t.jsx(It,{className:"w-4 h-4 text-teal-500 flex-shrink-0"}),t.jsx("span",{className:"text-xs text-teal-600 dark:text-teal-400",children:p.label})]},p.id))}),k&&t.jsx("div",{className:"prose prose-invert prose-sm [&>*:first-child]:mt-0 [&>*:last-child]:mb-0 [&_*]:[word-break:break-word] [&_*]:overflow-wrap-anywhere whitespace-pre-wrap",children:t.jsx(QQ,{remarkPlugins:[BQ],components:{a:({href:p,children:f,...N})=>t.jsx("a",{href:p,target:"_blank",rel:"noopener noreferrer",onClick:b=>{window.self!==window.top&&p&&(b.preventDefault(),window.parent.postMessage({type:"otto-open-url",url:p},"*"))},...N,children:f})},children:D.replace(/\n/g,`
102
102
  `)})})]}),r&&t.jsxs("div",{className:"flex items-center gap-2 mt-2",children:[t.jsxs("button",{type:"button",onClick:x,className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground transition-colors",title:"Cancel and restore to input",children:[t.jsx(Xo,{className:"h-3 w-3"}),"Cancel"]}),t.jsxs("button",{type:"button",onClick:F,className:"inline-flex items-center gap-1.5 px-2.5 py-1 text-xs rounded-md bg-destructive/10 hover:bg-destructive/20 text-destructive transition-colors",title:"Delete from queue",children:[t.jsx(dt,{className:"h-3 w-3"}),"Delete"]})]})]}),t.jsx("div",{className:"flex-shrink-0 w-8 flex items-start justify-center",children:t.jsx("div",{className:"flex h-8 w-8 shrink-0 items-center justify-center rounded-full border-2 border-emerald-500/50 bg-emerald-500/20 dark:bg-emerald-500/10 relative bg-background",children:t.jsx(Qs,{className:"h-4 w-4 text-emerald-700 dark:text-emerald-300"})})})]})}),o&&t.jsxs("div",{role:"dialog","aria-modal":"true",className:"fixed inset-0 z-50 flex items-center justify-center bg-black/80 p-4",onClick:()=>Q(null),onKeyDown:p=>p.key==="Escape"&&Q(null),tabIndex:-1,children:[t.jsx("button",{type:"button",onClick:()=>Q(null),className:"absolute top-4 right-4 p-2 rounded-full bg-white/10 hover:bg-white/20 transition-colors",children:t.jsx(kA,{className:"w-6 h-6 text-white"})}),t.jsx("img",{src:o,alt:"Expanded attachment",className:"max-w-full max-h-full object-contain rounded-lg",onClick:p=>p.stopPropagation(),onKeyDown:p=>p.key==="Enter"&&p.stopPropagation()})]})]})},(e,A)=>{const g=e.message.parts?.[0],s=A.message.parts?.[0];return e.message.id===A.message.id&&g?.content===s?.content&&g?.contentJson===s?.contentJson&&e.message.createdAt===A.message.createdAt&&e.message.parts?.length===A.message.parts?.length&&e.sessionId===A.sessionId&&e.nextAssistantMessageId===A.nextAssistantMessageId}),SI={openai:{id:"openai",models:[{id:"codex-mini-latest",label:"Codex Mini",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-04",releaseDate:"2025-05-16",lastUpdated:"2025-05-16",openWeights:!1,cost:{input:1.5,output:6,cacheRead:.375},limit:{context:2e5,output:1e5}},{id:"gpt-3.5-turbo",label:"GPT-3.5-turbo",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2021-09-01",releaseDate:"2023-03-01",lastUpdated:"2023-11-06",openWeights:!1,cost:{input:.5,output:1.5,cacheRead:1.25},limit:{context:16385,output:4096}},{id:"gpt-4",label:"GPT-4",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-11",releaseDate:"2023-11-06",lastUpdated:"2024-04-09",openWeights:!1,cost:{input:30,output:60},limit:{context:8192,output:8192}},{id:"gpt-4-turbo",label:"GPT-4 Turbo",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-12",releaseDate:"2023-11-06",lastUpdated:"2024-04-09",openWeights:!1,cost:{input:10,output:30},limit:{context:128e3,output:4096}},{id:"gpt-4.1",label:"GPT-4.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:2,output:8,cacheRead:.5},limit:{context:1047576,output:32768}},{id:"gpt-4.1-mini",label:"GPT-4.1 mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:.4,output:1.6,cacheRead:.1},limit:{context:1047576,output:32768}},{id:"gpt-4.1-nano",label:"GPT-4.1 nano",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.03},limit:{context:1047576,output:32768}},{id:"gpt-4o",label:"GPT-4o",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-05-13",lastUpdated:"2024-08-06",openWeights:!1,cost:{input:2.5,output:10,cacheRead:1.25},limit:{context:128e3,output:16384}},{id:"gpt-4o-2024-05-13",label:"GPT-4o (2024-05-13)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-05-13",lastUpdated:"2024-05-13",openWeights:!1,cost:{input:5,output:15},limit:{context:128e3,output:4096}},{id:"gpt-4o-2024-08-06",label:"GPT-4o (2024-08-06)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-08-06",lastUpdated:"2024-08-06",openWeights:!1,cost:{input:2.5,output:10,cacheRead:1.25},limit:{context:128e3,output:16384}},{id:"gpt-4o-2024-11-20",label:"GPT-4o (2024-11-20)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-11-20",lastUpdated:"2024-11-20",openWeights:!1,cost:{input:2.5,output:10,cacheRead:1.25},limit:{context:128e3,output:16384}},{id:"gpt-4o-mini",label:"GPT-4o mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-07-18",lastUpdated:"2024-07-18",openWeights:!1,cost:{input:.15,output:.6,cacheRead:.08},limit:{context:128e3,output:16384}},{id:"gpt-5",label:"GPT-5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"gpt-5-chat-latest",label:"GPT-5 Chat (latest)",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:1.25,output:10},limit:{context:4e5,output:128e3}},{id:"gpt-5-codex",label:"GPT-5-Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-09-15",lastUpdated:"2025-09-15",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"gpt-5-mini",label:"GPT-5 Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:.25,output:2,cacheRead:.025},limit:{context:4e5,output:128e3}},{id:"gpt-5-nano",label:"GPT-5 Nano",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:.05,output:.4,cacheRead:.005},limit:{context:4e5,output:128e3}},{id:"gpt-5-pro",label:"GPT-5 Pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-10-06",lastUpdated:"2025-10-06",openWeights:!1,cost:{input:15,output:120},limit:{context:4e5,output:272e3}},{id:"gpt-5.1",label:"GPT-5.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.13},limit:{context:4e5,output:128e3}},{id:"gpt-5.1-chat-latest",label:"GPT-5.1 Chat",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:128e3,output:16384}},{id:"gpt-5.1-codex",label:"GPT-5.1 Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"gpt-5.1-codex-max",label:"GPT-5.1 Codex Max",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"gpt-5.1-codex-mini",label:"GPT-5.1 Codex mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:.25,output:2,cacheRead:.025},limit:{context:4e5,output:128e3}},{id:"gpt-5.2",label:"GPT-5.2",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3}},{id:"gpt-5.2-chat-latest",label:"GPT-5.2 Chat",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:128e3,output:16384}},{id:"gpt-5.2-codex",label:"GPT-5.2 Codex",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3}},{id:"gpt-5.2-pro",label:"GPT-5.2 Pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:21,output:168},limit:{context:4e5,output:128e3}},{id:"gpt-5.3-codex",label:"GPT-5.3 Codex",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3}},{id:"gpt-5.3-codex-spark",label:"GPT-5.3 Codex Spark",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:128e3,output:32e3}},{id:"o1",label:"o1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2023-09",releaseDate:"2024-12-05",lastUpdated:"2024-12-05",openWeights:!1,cost:{input:15,output:60,cacheRead:7.5},limit:{context:2e5,output:1e5}},{id:"o1-mini",label:"o1-mini",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2023-09",releaseDate:"2024-09-12",lastUpdated:"2024-09-12",openWeights:!1,cost:{input:1.1,output:4.4,cacheRead:.55},limit:{context:128e3,output:65536}},{id:"o1-preview",label:"o1-preview",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2023-09",releaseDate:"2024-09-12",lastUpdated:"2024-09-12",openWeights:!1,cost:{input:15,output:60,cacheRead:7.5},limit:{context:128e3,output:32768}},{id:"o1-pro",label:"o1-pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2023-09",releaseDate:"2025-03-19",lastUpdated:"2025-03-19",openWeights:!1,cost:{input:150,output:600},limit:{context:2e5,output:1e5}},{id:"o3",label:"o3",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05",releaseDate:"2025-04-16",lastUpdated:"2025-04-16",openWeights:!1,cost:{input:2,output:8,cacheRead:.5},limit:{context:2e5,output:1e5}},{id:"o3-deep-research",label:"o3-deep-research",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05",releaseDate:"2024-06-26",lastUpdated:"2024-06-26",openWeights:!1,cost:{input:10,output:40,cacheRead:2.5},limit:{context:2e5,output:1e5}},{id:"o3-mini",label:"o3-mini",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2024-05",releaseDate:"2024-12-20",lastUpdated:"2025-01-29",openWeights:!1,cost:{input:1.1,output:4.4,cacheRead:.55},limit:{context:2e5,output:1e5}},{id:"o3-pro",label:"o3-pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05",releaseDate:"2025-06-10",lastUpdated:"2025-06-10",openWeights:!1,cost:{input:20,output:80},limit:{context:2e5,output:1e5}},{id:"o4-mini",label:"o4-mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05",releaseDate:"2025-04-16",lastUpdated:"2025-04-16",openWeights:!1,cost:{input:1.1,output:4.4,cacheRead:.28},limit:{context:2e5,output:1e5}},{id:"o4-mini-deep-research",label:"o4-mini-deep-research",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05",releaseDate:"2024-06-26",lastUpdated:"2024-06-26",openWeights:!1,cost:{input:2,output:8,cacheRead:.5},limit:{context:2e5,output:1e5}},{id:"text-embedding-3-large",label:"text-embedding-3-large",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2024-01",releaseDate:"2024-01-25",lastUpdated:"2024-01-25",openWeights:!1,cost:{input:.13,output:0},limit:{context:8191,output:3072}},{id:"text-embedding-3-small",label:"text-embedding-3-small",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2024-01",releaseDate:"2024-01-25",lastUpdated:"2024-01-25",openWeights:!1,cost:{input:.02,output:0},limit:{context:8191,output:1536}},{id:"text-embedding-ada-002",label:"text-embedding-ada-002",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2022-12",releaseDate:"2022-12-15",lastUpdated:"2022-12-15",openWeights:!1,cost:{input:.1,output:0},limit:{context:8192,output:1536}}],label:"OpenAI",env:["OPENAI_API_KEY"],npm:"@ai-sdk/openai",doc:"https://platform.openai.com/docs/models"},anthropic:{id:"anthropic",models:[{id:"claude-3-5-haiku-20241022",label:"Claude Haiku 3.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-07-31",releaseDate:"2024-10-22",lastUpdated:"2024-10-22",openWeights:!1,cost:{input:.8,output:4,cacheRead:.08,cacheWrite:1},limit:{context:2e5,output:8192}},{id:"claude-3-5-haiku-latest",label:"Claude Haiku 3.5 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-07-31",releaseDate:"2024-10-22",lastUpdated:"2024-10-22",openWeights:!1,cost:{input:.8,output:4,cacheRead:.08,cacheWrite:1},limit:{context:2e5,output:8192}},{id:"claude-3-5-sonnet-20240620",label:"Claude Sonnet 3.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04-30",releaseDate:"2024-06-20",lastUpdated:"2024-06-20",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:8192}},{id:"claude-3-5-sonnet-20241022",label:"Claude Sonnet 3.5 v2",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04-30",releaseDate:"2024-10-22",lastUpdated:"2024-10-22",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:8192}},{id:"claude-3-7-sonnet-20250219",label:"Claude Sonnet 3.7",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-31",releaseDate:"2025-02-19",lastUpdated:"2025-02-19",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"claude-3-7-sonnet-latest",label:"Claude Sonnet 3.7 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-31",releaseDate:"2025-02-19",lastUpdated:"2025-02-19",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"claude-3-haiku-20240307",label:"Claude Haiku 3",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-08-31",releaseDate:"2024-03-13",lastUpdated:"2024-03-13",openWeights:!1,cost:{input:.25,output:1.25,cacheRead:.03,cacheWrite:.3},limit:{context:2e5,output:4096}},{id:"claude-3-opus-20240229",label:"Claude Opus 3",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-08-31",releaseDate:"2024-02-29",lastUpdated:"2024-02-29",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:4096}},{id:"claude-3-sonnet-20240229",label:"Claude Sonnet 3",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-08-31",releaseDate:"2024-03-04",lastUpdated:"2024-03-04",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:.3},limit:{context:2e5,output:4096}},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-02-28",releaseDate:"2025-10-15",lastUpdated:"2025-10-15",openWeights:!1,cost:{input:1,output:5,cacheRead:.1,cacheWrite:1.25},limit:{context:2e5,output:64e3}},{id:"claude-haiku-4-5-20251001",label:"Claude Haiku 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-02-28",releaseDate:"2025-10-15",lastUpdated:"2025-10-15",openWeights:!1,cost:{input:1,output:5,cacheRead:.1,cacheWrite:1.25},limit:{context:2e5,output:64e3}},{id:"claude-opus-4-0",label:"Claude Opus 4 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"claude-opus-4-1",label:"Claude Opus 4.1 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"claude-opus-4-1-20250805",label:"Claude Opus 4.1",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"claude-opus-4-20250514",label:"Claude Opus 4",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"claude-opus-4-5",label:"Claude Opus 4.5 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-11-24",lastUpdated:"2025-11-24",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:2e5,output:64e3}},{id:"claude-opus-4-5-20251101",label:"Claude Opus 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-11-01",lastUpdated:"2025-11-01",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:2e5,output:64e3}},{id:"claude-opus-4-6",label:"Claude Opus 4.6",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-05",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:2e5,output:128e3}},{id:"claude-sonnet-4-0",label:"Claude Sonnet 4 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"claude-sonnet-4-20250514",label:"Claude Sonnet 4",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"claude-sonnet-4-5",label:"Claude Sonnet 4.5 (latest)",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-07-31",releaseDate:"2025-09-29",lastUpdated:"2025-09-29",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"claude-sonnet-4-5-20250929",label:"Claude Sonnet 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-07-31",releaseDate:"2025-09-29",lastUpdated:"2025-09-29",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}}],label:"Anthropic",env:["ANTHROPIC_API_KEY"],npm:"@ai-sdk/anthropic",doc:"https://docs.anthropic.com/en/docs/about-claude/models"},google:{id:"google",models:[{id:"gemini-1.5-flash",label:"Gemini 1.5 Flash",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2024-05-14",lastUpdated:"2024-05-14",openWeights:!1,cost:{input:.075,output:.3,cacheRead:.01875},limit:{context:1e6,output:8192}},{id:"gemini-1.5-flash-8b",label:"Gemini 1.5 Flash-8B",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2024-10-03",lastUpdated:"2024-10-03",openWeights:!1,cost:{input:.0375,output:.15,cacheRead:.01},limit:{context:1e6,output:8192}},{id:"gemini-1.5-pro",label:"Gemini 1.5 Pro",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2024-02-15",lastUpdated:"2024-02-15",openWeights:!1,cost:{input:1.25,output:5,cacheRead:.3125},limit:{context:1e6,output:8192}},{id:"gemini-2.0-flash",label:"Gemini 2.0 Flash",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2024-12-11",lastUpdated:"2024-12-11",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:8192}},{id:"gemini-2.0-flash-lite",label:"Gemini 2.0 Flash Lite",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2024-12-11",lastUpdated:"2024-12-11",openWeights:!1,cost:{input:.075,output:.3},limit:{context:1048576,output:8192}},{id:"gemini-2.5-flash",label:"Gemini 2.5 Flash",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-03-20",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:.3,output:2.5,cacheRead:.075},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-image",label:"Gemini 2.5 Flash Image",modalities:{input:["text","image"],output:["text","image"]},toolCall:!1,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-06",releaseDate:"2025-08-26",lastUpdated:"2025-08-26",openWeights:!1,cost:{input:.3,output:30,cacheRead:.075},limit:{context:32768,output:32768}},{id:"gemini-2.5-flash-image-preview",label:"Gemini 2.5 Flash Image (Preview)",modalities:{input:["text","image"],output:["text","image"]},toolCall:!1,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-06",releaseDate:"2025-08-26",lastUpdated:"2025-08-26",openWeights:!1,cost:{input:.3,output:30,cacheRead:.075},limit:{context:32768,output:32768}},{id:"gemini-2.5-flash-lite",label:"Gemini 2.5 Flash Lite",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-06-17",lastUpdated:"2025-06-17",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-lite-preview-06-17",label:"Gemini 2.5 Flash Lite Preview 06-17",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-06-17",lastUpdated:"2025-06-17",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-lite-preview-09-2025",label:"Gemini 2.5 Flash Lite Preview 09-25",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-preview-04-17",label:"Gemini 2.5 Flash Preview 04-17",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-04-17",lastUpdated:"2025-04-17",openWeights:!1,cost:{input:.15,output:.6,cacheRead:.0375},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-preview-05-20",label:"Gemini 2.5 Flash Preview 05-20",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-05-20",lastUpdated:"2025-05-20",openWeights:!1,cost:{input:.15,output:.6,cacheRead:.0375},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-preview-09-2025",label:"Gemini 2.5 Flash Preview 09-25",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.3,output:2.5,cacheRead:.075},limit:{context:1048576,output:65536}},{id:"gemini-2.5-flash-preview-tts",label:"Gemini 2.5 Flash Preview TTS",modalities:{input:["text"],output:["audio"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2025-01",releaseDate:"2025-05-01",lastUpdated:"2025-05-01",openWeights:!1,cost:{input:.5,output:10},limit:{context:8e3,output:16e3}},{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-03-20",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"gemini-2.5-pro-preview-05-06",label:"Gemini 2.5 Pro Preview 05-06",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-05-06",lastUpdated:"2025-05-06",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"gemini-2.5-pro-preview-06-05",label:"Gemini 2.5 Pro Preview 06-05",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-06-05",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"gemini-2.5-pro-preview-tts",label:"Gemini 2.5 Pro Preview TTS",modalities:{input:["text"],output:["audio"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2025-01",releaseDate:"2025-05-01",lastUpdated:"2025-05-01",openWeights:!1,cost:{input:1,output:20},limit:{context:8e3,output:16e3}},{id:"gemini-3-flash-preview",label:"Gemini 3 Flash Preview",modalities:{input:["text","image","video","audio","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-17",lastUpdated:"2025-12-17",openWeights:!1,cost:{input:.5,output:3,cacheRead:.05},limit:{context:1048576,output:65536}},{id:"gemini-3-pro-preview",label:"Gemini 3 Pro Preview",modalities:{input:["text","image","video","audio","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-11-18",lastUpdated:"2025-11-18",openWeights:!1,cost:{input:2,output:12,cacheRead:.2},limit:{context:1e6,output:64e3}},{id:"gemini-embedding-001",label:"Gemini Embedding 001",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!1,knowledge:"2025-05",releaseDate:"2025-05-20",lastUpdated:"2025-05-20",openWeights:!1,cost:{input:.15,output:0},limit:{context:2048,output:3072}},{id:"gemini-flash-latest",label:"Gemini Flash Latest",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.3,output:2.5,cacheRead:.075},limit:{context:1048576,output:65536}},{id:"gemini-flash-lite-latest",label:"Gemini Flash-Lite Latest",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"gemini-live-2.5-flash",label:"Gemini Live 2.5 Flash",modalities:{input:["text","image","audio","video"],output:["text","audio"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-01",lastUpdated:"2025-09-01",openWeights:!1,cost:{input:.5,output:2},limit:{context:128e3,output:8e3}},{id:"gemini-live-2.5-flash-preview-native-audio",label:"Gemini Live 2.5 Flash Preview Native Audio",modalities:{input:["text","audio","video"],output:["text","audio"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2025-01",releaseDate:"2025-06-17",lastUpdated:"2025-09-18",openWeights:!1,cost:{input:.5,output:2},limit:{context:131072,output:65536}}],label:"Google",env:["GOOGLE_GENERATIVE_AI_API_KEY","GEMINI_API_KEY"],npm:"@ai-sdk/google",doc:"https://ai.google.dev/gemini-api/docs/pricing"},openrouter:{id:"openrouter",models:[{id:"allenai/molmo-2-8b:free",label:"Molmo2 8B (free)",modalities:{input:["text","image","video"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-09",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:36864,output:36864}},{id:"anthropic/claude-3.5-haiku",label:"Claude Haiku 3.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-07-31",releaseDate:"2024-10-22",lastUpdated:"2024-10-22",openWeights:!1,cost:{input:.8,output:4,cacheRead:.08,cacheWrite:1},limit:{context:2e5,output:8192}},{id:"anthropic/claude-3.7-sonnet",label:"Claude Sonnet 3.7",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-01",releaseDate:"2025-02-19",lastUpdated:"2025-02-19",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:128e3}},{id:"anthropic/claude-haiku-4.5",label:"Claude Haiku 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-02-28",releaseDate:"2025-10-15",lastUpdated:"2025-10-15",openWeights:!1,cost:{input:1,output:5,cacheRead:.1,cacheWrite:1.25},limit:{context:2e5,output:64e3}},{id:"anthropic/claude-opus-4",label:"Claude Opus 4",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"anthropic/claude-opus-4.1",label:"Claude Opus 4.1",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3}},{id:"anthropic/claude-opus-4.5",label:"Claude Opus 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-05-30",releaseDate:"2025-11-24",lastUpdated:"2025-11-24",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:2e5,output:32e3}},{id:"anthropic/claude-opus-4.6",label:"Claude Opus 4.6",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-05-30",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:1e6,output:128e3}},{id:"anthropic/claude-sonnet-4",label:"Claude Sonnet 4",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:2e5,output:64e3}},{id:"anthropic/claude-sonnet-4.5",label:"Claude Sonnet 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-07-31",releaseDate:"2025-09-29",lastUpdated:"2025-09-29",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:1e6,output:64e3}},{id:"arcee-ai/trinity-large-preview:free",label:"Trinity Large Preview",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-28",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"arcee-ai/trinity-mini:free",label:"Trinity Mini",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-28",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"black-forest-labs/flux.2-flex",label:"FLUX.2 Flex",modalities:{input:["image","text"],output:["image","text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-11-25",lastUpdated:"2026-01-31",openWeights:!1,cost:{input:0,output:0},limit:{context:67344,output:67344}},{id:"black-forest-labs/flux.2-klein-4b",label:"FLUX.2 Klein 4B",modalities:{input:["image","text"],output:["image","text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-14",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"black-forest-labs/flux.2-max",label:"FLUX.2 Max",modalities:{input:["image","text"],output:["image","text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-12-16",lastUpdated:"2026-01-31",openWeights:!1,cost:{input:0,output:0},limit:{context:46864,output:46864}},{id:"black-forest-labs/flux.2-pro",label:"FLUX.2 Pro",modalities:{input:["image","text"],output:["image","text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-11-25",lastUpdated:"2026-01-31",openWeights:!1,cost:{input:0,output:0},limit:{context:46864,output:46864}},{id:"bytedance-seed/seedream-4.5",label:"Seedream 4.5",modalities:{input:["image","text"],output:["image","text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-12-23",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:4096,output:4096}},{id:"cognitivecomputations/dolphin-mistral-24b-venice-edition:free",label:"Uncensored (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-07-09",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"cognitivecomputations/dolphin3.0-mistral-24b",label:"Dolphin3.0 Mistral 24B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-02-13",lastUpdated:"2025-02-13",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"cognitivecomputations/dolphin3.0-r1-mistral-24b",label:"Dolphin3.0 R1 Mistral 24B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-02-13",lastUpdated:"2025-02-13",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"deepseek/deepseek-chat-v3-0324",label:"DeepSeek V3 0324",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-24",lastUpdated:"2025-03-24",openWeights:!0,cost:{input:0,output:0},limit:{context:16384,output:8192}},{id:"deepseek/deepseek-chat-v3.1",label:"DeepSeek-V3.1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-08-21",lastUpdated:"2025-08-21",openWeights:!0,cost:{input:.2,output:.8},limit:{context:163840,output:163840}},{id:"deepseek/deepseek-r1-0528-qwen3-8b:free",label:"Deepseek R1 0528 Qwen3 8B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-29",lastUpdated:"2025-05-29",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"deepseek/deepseek-r1-0528:free",label:"R1 0528 (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-28",lastUpdated:"2025-05-28",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"deepseek/deepseek-r1-distill-llama-70b",label:"DeepSeek R1 Distill Llama 70B",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-01-23",lastUpdated:"2025-01-23",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:8192}},{id:"deepseek/deepseek-r1-distill-qwen-14b",label:"DeepSeek R1 Distill Qwen 14B",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-01-29",lastUpdated:"2025-01-29",openWeights:!0,cost:{input:0,output:0},limit:{context:64e3,output:8192}},{id:"deepseek/deepseek-r1:free",label:"R1 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2025-01-20",lastUpdated:"2025-01-20",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"deepseek/deepseek-v3-base:free",label:"DeepSeek V3 Base (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-03",releaseDate:"2025-03-29",lastUpdated:"2025-03-29",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"deepseek/deepseek-v3.1-terminus",label:"DeepSeek V3.1 Terminus",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-09-22",lastUpdated:"2025-09-22",openWeights:!0,cost:{input:.27,output:1},limit:{context:131072,output:65536}},{id:"deepseek/deepseek-v3.1-terminus:exacto",label:"DeepSeek V3.1 Terminus (exacto)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-09-22",lastUpdated:"2025-09-22",openWeights:!0,cost:{input:.27,output:1},limit:{context:131072,output:65536}},{id:"deepseek/deepseek-v3.2",label:"DeepSeek V3.2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-07",releaseDate:"2025-12-01",lastUpdated:"2025-12-01",openWeights:!0,cost:{input:.28,output:.4},limit:{context:163840,output:65536}},{id:"deepseek/deepseek-v3.2-speciale",label:"DeepSeek V3.2 Speciale",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-07",releaseDate:"2025-12-01",lastUpdated:"2025-12-01",openWeights:!0,cost:{input:.27,output:.41},limit:{context:163840,output:65536}},{id:"featherless/qwerky-72b",label:"Qwerky 72B",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-20",lastUpdated:"2025-03-20",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"google/gemini-2.0-flash-001",label:"Gemini 2.0 Flash",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2024-12-11",lastUpdated:"2024-12-11",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:8192}},{id:"google/gemini-2.0-flash-exp:free",label:"Gemini 2.0 Flash Experimental (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-12",releaseDate:"2024-12-11",lastUpdated:"2024-12-11",openWeights:!1,cost:{input:0,output:0},limit:{context:1048576,output:1048576}},{id:"google/gemini-2.5-flash",label:"Gemini 2.5 Flash",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-07-17",lastUpdated:"2025-07-17",openWeights:!1,cost:{input:.3,output:2.5,cacheRead:.0375},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-flash-lite",label:"Gemini 2.5 Flash Lite",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-06-17",lastUpdated:"2025-06-17",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-flash-lite-preview-09-2025",label:"Gemini 2.5 Flash Lite Preview 09-25",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.1,output:.4,cacheRead:.025},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-flash-preview-09-2025",label:"Gemini 2.5 Flash Preview 09-25",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-09-25",lastUpdated:"2025-09-25",openWeights:!1,cost:{input:.3,output:2.5,cacheRead:.031},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-pro",label:"Gemini 2.5 Pro",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-03-20",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-pro-preview-05-06",label:"Gemini 2.5 Pro Preview 05-06",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-05-06",lastUpdated:"2025-05-06",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"google/gemini-2.5-pro-preview-06-05",label:"Gemini 2.5 Pro Preview 06-05",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-06-05",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.31},limit:{context:1048576,output:65536}},{id:"google/gemini-3-flash-preview",label:"Gemini 3 Flash Preview",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-17",lastUpdated:"2025-12-17",openWeights:!1,cost:{input:.5,output:3,cacheRead:.05},limit:{context:1048576,output:65536}},{id:"google/gemini-3-pro-preview",label:"Gemini 3 Pro Preview",modalities:{input:["text","image","audio","video","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-11-18",lastUpdated:"2025-11",openWeights:!1,cost:{input:2,output:12},limit:{context:105e4,output:66e3}},{id:"google/gemma-2-9b-it",label:"Gemma 2 9B",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-06",releaseDate:"2024-06-28",lastUpdated:"2024-06-28",openWeights:!0,cost:{input:.03,output:.09},limit:{context:8192,output:8192}},{id:"google/gemma-3-12b-it",label:"Gemma 3 12B",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-13",lastUpdated:"2025-03-13",openWeights:!0,cost:{input:.03,output:.1},limit:{context:131072,output:131072}},{id:"google/gemma-3-12b-it:free",label:"Gemma 3 12B (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-13",lastUpdated:"2025-03-13",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"google/gemma-3-27b-it",label:"Gemma 3 27B",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-12",lastUpdated:"2025-03-12",openWeights:!0,cost:{input:.04,output:.15},limit:{context:96e3,output:96e3}},{id:"google/gemma-3-27b-it:free",label:"Gemma 3 27B (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-12",lastUpdated:"2025-03-12",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:8192}},{id:"google/gemma-3-4b-it",label:"Gemma 3 4B",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-13",lastUpdated:"2025-03-13",openWeights:!0,cost:{input:.01703,output:.06815},limit:{context:96e3,output:96e3}},{id:"google/gemma-3-4b-it:free",label:"Gemma 3 4B (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-13",lastUpdated:"2025-03-13",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"google/gemma-3n-e2b-it:free",label:"Gemma 3n 2B (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2025-07-09",lastUpdated:"2025-07-09",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:2e3}},{id:"google/gemma-3n-e4b-it",label:"Gemma 3n 4B",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2025-05-20",lastUpdated:"2025-05-20",openWeights:!0,cost:{input:.02,output:.04},limit:{context:32768,output:32768}},{id:"google/gemma-3n-e4b-it:free",label:"Gemma 3n 4B (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2025-05-20",lastUpdated:"2025-05-20",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:2e3}},{id:"kwaipilot/kat-coder-pro:free",label:"Kat Coder Pro (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-11",releaseDate:"2025-11-10",lastUpdated:"2025-11-10",openWeights:!1,cost:{input:0,output:0},limit:{context:256e3,output:65536}},{id:"liquid/lfm-2.5-1.2b-instruct:free",label:"LFM2.5-1.2B-Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-20",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:32768}},{id:"liquid/lfm-2.5-1.2b-thinking:free",label:"LFM2.5-1.2B-Thinking (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-20",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:32768}},{id:"meta-llama/llama-3.1-405b-instruct:free",label:"Llama 3.1 405B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-08",releaseDate:"2024-07-23",lastUpdated:"2025-04-05",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"meta-llama/llama-3.2-11b-vision-instruct",label:"Llama 3.2 11B Vision Instruct",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-12",releaseDate:"2024-09-25",lastUpdated:"2024-09-25",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:8192}},{id:"meta-llama/llama-3.2-3b-instruct:free",label:"Llama 3.2 3B Instruct (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-12",releaseDate:"2024-09-25",lastUpdated:"2024-09-25",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"meta-llama/llama-3.3-70b-instruct:free",label:"Llama 3.3 70B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-12",releaseDate:"2024-12-06",lastUpdated:"2024-12-06",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"meta-llama/llama-4-scout:free",label:"Llama 4 Scout (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-08",releaseDate:"2025-04-05",lastUpdated:"2025-04-05",openWeights:!0,cost:{input:0,output:0},limit:{context:64e3,output:64e3}},{id:"microsoft/mai-ds-r1:free",label:"MAI DS R1 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-21",lastUpdated:"2025-04-21",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"minimax/minimax-01",label:"MiniMax-01",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,releaseDate:"2025-01-15",lastUpdated:"2025-01-15",openWeights:!0,cost:{input:.2,output:1.1},limit:{context:1e6,output:1e6}},{id:"minimax/minimax-m1",label:"MiniMax M1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-06-17",lastUpdated:"2025-06-17",openWeights:!0,cost:{input:.4,output:2.2},limit:{context:1e6,output:4e4}},{id:"minimax/minimax-m2",label:"MiniMax M2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-10-23",lastUpdated:"2025-10-23",openWeights:!0,cost:{input:.28,output:1.15,cacheRead:.28,cacheWrite:1.15},limit:{context:196600,output:118e3}},{id:"minimax/minimax-m2.1",label:"MiniMax M2.1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-12-23",lastUpdated:"2025-12-23",openWeights:!0,cost:{input:.3,output:1.2},limit:{context:204800,output:131072}},{id:"minimax/minimax-m2.5",label:"MiniMax M2.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-02-12",lastUpdated:"2026-02-12",openWeights:!0,cost:{input:.3,output:1.2,cacheRead:.03},limit:{context:204800,output:131072}},{id:"mistralai/codestral-2508",label:"Codestral 2508",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-08-01",lastUpdated:"2025-08-01",openWeights:!0,cost:{input:.3,output:.9},limit:{context:256e3,output:256e3}},{id:"mistralai/devstral-2512",label:"Devstral 2 2512",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-12",releaseDate:"2025-09-12",lastUpdated:"2025-09-12",openWeights:!0,cost:{input:.15,output:.6},limit:{context:262144,output:262144}},{id:"mistralai/devstral-2512:free",label:"Devstral 2 2512 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-12",releaseDate:"2025-09-12",lastUpdated:"2025-09-12",openWeights:!0,cost:{input:0,output:0},limit:{context:262144,output:262144}},{id:"mistralai/devstral-medium-2507",label:"Devstral Medium",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-07-10",lastUpdated:"2025-07-10",openWeights:!0,cost:{input:.4,output:2},limit:{context:131072,output:131072}},{id:"mistralai/devstral-small-2505",label:"Devstral Small",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-07",lastUpdated:"2025-05-07",openWeights:!0,cost:{input:.06,output:.12},limit:{context:128e3,output:128e3}},{id:"mistralai/devstral-small-2505:free",label:"Devstral Small 2505 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-21",lastUpdated:"2025-05-21",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"mistralai/devstral-small-2507",label:"Devstral Small 1.1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-07-10",lastUpdated:"2025-07-10",openWeights:!0,cost:{input:.1,output:.3},limit:{context:131072,output:131072}},{id:"mistralai/mistral-7b-instruct:free",label:"Mistral 7B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-05",releaseDate:"2024-05-27",lastUpdated:"2024-05-27",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"mistralai/mistral-medium-3",label:"Mistral Medium 3",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-07",lastUpdated:"2025-05-07",openWeights:!1,cost:{input:.4,output:2},limit:{context:131072,output:131072}},{id:"mistralai/mistral-medium-3.1",label:"Mistral Medium 3.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-05",releaseDate:"2025-08-12",lastUpdated:"2025-08-12",openWeights:!1,cost:{input:.4,output:2},limit:{context:262144,output:262144}},{id:"mistralai/mistral-nemo:free",label:"Mistral Nemo (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-07",releaseDate:"2024-07-19",lastUpdated:"2024-07-19",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"mistralai/mistral-small-3.1-24b-instruct",label:"Mistral Small 3.1 24B Instruct",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-17",lastUpdated:"2025-03-17",openWeights:!0,cost:{input:0,output:0},limit:{context:128e3,output:8192}},{id:"mistralai/mistral-small-3.2-24b-instruct",label:"Mistral Small 3.2 24B Instruct",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-06-20",lastUpdated:"2025-06-20",openWeights:!0,cost:{input:0,output:0},limit:{context:96e3,output:8192}},{id:"mistralai/mistral-small-3.2-24b-instruct:free",label:"Mistral Small 3.2 24B (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-06",releaseDate:"2025-06-20",lastUpdated:"2025-06-20",openWeights:!0,cost:{input:0,output:0},limit:{context:96e3,output:96e3}},{id:"moonshotai/kimi-dev-72b:free",label:"Kimi Dev 72b (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-06-16",lastUpdated:"2025-06-16",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"moonshotai/kimi-k2",label:"Kimi K2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-07-11",lastUpdated:"2025-07-11",openWeights:!0,cost:{input:.55,output:2.2},limit:{context:131072,output:32768}},{id:"moonshotai/kimi-k2-0905",label:"Kimi K2 Instruct 0905",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:.6,output:2.5},limit:{context:262144,output:16384}},{id:"moonshotai/kimi-k2-0905:exacto",label:"Kimi K2 Instruct 0905 (exacto)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:.6,output:2.5},limit:{context:262144,output:16384}},{id:"moonshotai/kimi-k2-thinking",label:"Kimi K2 Thinking",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-08",releaseDate:"2025-11-06",lastUpdated:"2025-11-06",openWeights:!0,cost:{input:.6,output:2.5,cacheRead:.15},limit:{context:262144,output:262144}},{id:"moonshotai/kimi-k2:free",label:"Kimi K2 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-11",lastUpdated:"2025-07-11",openWeights:!0,cost:{input:0,output:0},limit:{context:32800,output:32800}},{id:"moonshotai/kimi-k2.5",label:"Kimi K2.5",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2026-01-27",lastUpdated:"2026-01-27",openWeights:!0,cost:{input:.6,output:3,cacheRead:.1},limit:{context:262144,output:262144}},{id:"nousresearch/deephermes-3-llama-3-8b-preview",label:"DeepHermes 3 Llama 3 8B Preview",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-04",releaseDate:"2025-02-28",lastUpdated:"2025-02-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:8192}},{id:"nousresearch/hermes-3-llama-3.1-405b:free",label:"Hermes 3 405B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2023-12",releaseDate:"2024-08-16",lastUpdated:"2024-08-16",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"nousresearch/hermes-4-405b",label:"Hermes 4 405B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2023-12",releaseDate:"2025-08-25",lastUpdated:"2025-08-25",openWeights:!0,cost:{input:1,output:3},limit:{context:131072,output:131072}},{id:"nousresearch/hermes-4-70b",label:"Hermes 4 70B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2023-12",releaseDate:"2025-08-25",lastUpdated:"2025-08-25",openWeights:!0,cost:{input:.13,output:.4},limit:{context:131072,output:131072}},{id:"nvidia/nemotron-3-nano-30b-a3b:free",label:"Nemotron 3 Nano 30B A3B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-11",releaseDate:"2025-12-14",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:256e3,output:256e3}},{id:"nvidia/nemotron-nano-12b-v2-vl:free",label:"Nemotron Nano 12B 2 VL (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-11",releaseDate:"2025-10-28",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"nvidia/nemotron-nano-9b-v2",label:"nvidia-nemotron-nano-9b-v2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-09",releaseDate:"2025-08-18",lastUpdated:"2025-08-18",openWeights:!0,cost:{input:.04,output:.16},limit:{context:131072,output:131072}},{id:"nvidia/nemotron-nano-9b-v2:free",label:"Nemotron Nano 9B V2 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-09",releaseDate:"2025-09-05",lastUpdated:"2025-08-18",openWeights:!0,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"openai/gpt-4.1",label:"GPT-4.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:2,output:8,cacheRead:.5},limit:{context:1047576,output:32768}},{id:"openai/gpt-4.1-mini",label:"GPT-4.1 Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:.4,output:1.6,cacheRead:.1},limit:{context:1047576,output:32768}},{id:"openai/gpt-4o-mini",label:"GPT-4o-mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2024-07-18",lastUpdated:"2024-07-18",openWeights:!1,cost:{input:.15,output:.6,cacheRead:.08},limit:{context:128e3,output:16384}},{id:"openai/gpt-5",label:"GPT-5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-01",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:1.25,output:10},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-chat",label:"GPT-5 Chat (latest)",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:1.25,output:10},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-codex",label:"GPT-5 Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-01",releaseDate:"2025-09-15",lastUpdated:"2025-09-15",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-image",label:"GPT-5 Image",modalities:{input:["text","image","pdf"],output:["text","image"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-01",releaseDate:"2025-10-14",lastUpdated:"2025-10-14",openWeights:!1,cost:{input:5,output:10,cacheRead:1.25},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-mini",label:"GPT-5 Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-01",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:.25,output:2},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-nano",label:"GPT-5 Nano",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10-01",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:.05,output:.4},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5-pro",label:"GPT-5 Pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-10-06",lastUpdated:"2025-10-06",openWeights:!1,cost:{input:15,output:120},limit:{context:4e5,output:272e3}},{id:"openai/gpt-5.1",label:"GPT-5.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5.1-chat",label:"GPT-5.1 Chat",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:128e3,output:16384}},{id:"openai/gpt-5.1-codex",label:"GPT-5.1-Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5.1-codex-max",label:"GPT-5.1-Codex-Max",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.1,output:9,cacheRead:.11},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5.1-codex-mini",label:"GPT-5.1-Codex-Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:.25,output:2,cacheRead:.025},limit:{context:4e5,output:1e5}},{id:"openai/gpt-5.2",label:"GPT-5.2",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5.2-chat",label:"GPT-5.2 Chat",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:128e3,output:16384}},{id:"openai/gpt-5.2-codex",label:"GPT-5.2-Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-08-31",releaseDate:"2026-01-14",lastUpdated:"2026-01-14",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3}},{id:"openai/gpt-5.2-pro",label:"GPT-5.2 Pro",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:21,output:168},limit:{context:4e5,output:128e3}},{id:"openai/gpt-oss-120b",label:"GPT OSS 120B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!0,cost:{input:.072,output:.28},limit:{context:131072,output:32768}},{id:"openai/gpt-oss-120b:exacto",label:"GPT OSS 120B (exacto)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!0,cost:{input:.05,output:.24},limit:{context:131072,output:32768}},{id:"openai/gpt-oss-120b:free",label:"gpt-oss-120b (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:32768}},{id:"openai/gpt-oss-20b",label:"GPT OSS 20B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!0,cost:{input:.05,output:.2},limit:{context:131072,output:32768}},{id:"openai/gpt-oss-20b:free",label:"gpt-oss-20b (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-08-05",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:32768}},{id:"openai/gpt-oss-safeguard-20b",label:"GPT OSS Safeguard 20B",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-10-29",lastUpdated:"2025-10-29",openWeights:!1,cost:{input:.075,output:.3},limit:{context:131072,output:65536}},{id:"openai/o4-mini",label:"o4 Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2025-04-16",lastUpdated:"2025-04-16",openWeights:!1,cost:{input:1.1,output:4.4,cacheRead:.28},limit:{context:2e5,output:1e5}},{id:"openrouter/sherlock-dash-alpha",label:"Sherlock Dash Alpha",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-11",releaseDate:"2025-11-15",lastUpdated:"2025-12-14",openWeights:!1,cost:{input:0,output:0},limit:{context:184e4,output:0}},{id:"openrouter/sherlock-think-alpha",label:"Sherlock Think Alpha",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-11",releaseDate:"2025-11-15",lastUpdated:"2025-12-14",openWeights:!1,cost:{input:0,output:0},limit:{context:184e4,output:0}},{id:"qwen/qwen-2.5-coder-32b-instruct",label:"Qwen2.5 Coder 32B Instruct",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2024-11-11",lastUpdated:"2024-11-11",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"qwen/qwen-2.5-vl-7b-instruct:free",label:"Qwen2.5-VL 7B Instruct (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-02",releaseDate:"2024-08-28",lastUpdated:"2024-08-28",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"qwen/qwen2.5-vl-32b-instruct:free",label:"Qwen2.5 VL 32B Instruct (free)",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-03",releaseDate:"2025-03-24",lastUpdated:"2025-03-24",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:8192}},{id:"qwen/qwen2.5-vl-72b-instruct",label:"Qwen2.5 VL 72B Instruct",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-02-01",lastUpdated:"2025-02-01",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"qwen/qwen2.5-vl-72b-instruct:free",label:"Qwen2.5 VL 72B Instruct (free)",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-02",releaseDate:"2025-02-01",lastUpdated:"2025-02-01",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"qwen/qwen3-14b:free",label:"Qwen3 14B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-04-28",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"qwen/qwen3-235b-a22b-07-25",label:"Qwen3 235B A22B Instruct 2507",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-07-21",openWeights:!0,cost:{input:.15,output:.85},limit:{context:262144,output:131072}},{id:"qwen/qwen3-235b-a22b-07-25:free",label:"Qwen3 235B A22B Instruct 2507 (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-07-21",openWeights:!0,cost:{input:0,output:0},limit:{context:262144,output:131072}},{id:"qwen/qwen3-235b-a22b-thinking-2507",label:"Qwen3 235B A22B Thinking 2507",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-25",lastUpdated:"2025-07-25",openWeights:!0,cost:{input:.078,output:.312},limit:{context:262144,output:81920}},{id:"qwen/qwen3-235b-a22b:free",label:"Qwen3 235B A22B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-04-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}},{id:"qwen/qwen3-30b-a3b-instruct-2507",label:"Qwen3 30B A3B Instruct 2507",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-29",lastUpdated:"2025-07-29",openWeights:!0,cost:{input:.2,output:.8},limit:{context:262e3,output:262e3}},{id:"qwen/qwen3-30b-a3b-thinking-2507",label:"Qwen3 30B A3B Thinking 2507",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-29",lastUpdated:"2025-07-29",openWeights:!0,cost:{input:.2,output:.8},limit:{context:262e3,output:262e3}},{id:"qwen/qwen3-30b-a3b:free",label:"Qwen3 30B A3B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-04-28",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"qwen/qwen3-32b:free",label:"Qwen3 32B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-04-28",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"qwen/qwen3-4b:free",label:"Qwen3 4B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-30",lastUpdated:"2025-07-23",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"qwen/qwen3-8b:free",label:"Qwen3 8B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-28",lastUpdated:"2025-04-28",openWeights:!0,cost:{input:0,output:0},limit:{context:40960,output:40960}},{id:"qwen/qwen3-coder",label:"Qwen3 Coder",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-23",lastUpdated:"2025-07-23",openWeights:!0,cost:{input:.3,output:1.2},limit:{context:262144,output:66536}},{id:"qwen/qwen3-coder-30b-a3b-instruct",label:"Qwen3 Coder 30B A3B Instruct",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-31",lastUpdated:"2025-07-31",openWeights:!0,cost:{input:.07,output:.27},limit:{context:16e4,output:65536}},{id:"qwen/qwen3-coder-flash",label:"Qwen3 Coder Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-23",lastUpdated:"2025-07-23",openWeights:!1,cost:{input:.3,output:1.5},limit:{context:128e3,output:66536}},{id:"qwen/qwen3-coder:exacto",label:"Qwen3 Coder (exacto)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-23",lastUpdated:"2025-07-23",openWeights:!0,cost:{input:.38,output:1.53},limit:{context:131072,output:32768}},{id:"qwen/qwen3-coder:free",label:"Qwen3 Coder 480B A35B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-23",lastUpdated:"2025-07-23",openWeights:!0,cost:{input:0,output:0},limit:{context:262144,output:66536}},{id:"qwen/qwen3-max",label:"Qwen3 Max",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!1,cost:{input:1.2,output:6},limit:{context:262144,output:32768}},{id:"qwen/qwen3-next-80b-a3b-instruct",label:"Qwen3 Next 80B A3B Instruct",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-11",lastUpdated:"2025-09-11",openWeights:!0,cost:{input:.14,output:1.4},limit:{context:262144,output:262144}},{id:"qwen/qwen3-next-80b-a3b-instruct:free",label:"Qwen3 Next 80B A3B Instruct (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-11",lastUpdated:"2025-09-11",openWeights:!0,cost:{input:0,output:0},limit:{context:262144,output:262144}},{id:"qwen/qwen3-next-80b-a3b-thinking",label:"Qwen3 Next 80B A3B Thinking",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-11",lastUpdated:"2025-09-11",openWeights:!0,cost:{input:.14,output:1.4},limit:{context:262144,output:262144}},{id:"qwen/qwq-32b:free",label:"QwQ 32B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-03",releaseDate:"2025-03-05",lastUpdated:"2025-03-05",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"rekaai/reka-flash-3",label:"Reka Flash 3",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-03-12",lastUpdated:"2025-03-12",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:8192}},{id:"sarvamai/sarvam-m:free",label:"Sarvam-M (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-05",releaseDate:"2025-05-25",lastUpdated:"2025-05-25",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"sourceful/riverflow-v2-fast-preview",label:"Riverflow V2 Fast Preview",modalities:{input:["text","image"],output:["image"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-12-08",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:8192}},{id:"sourceful/riverflow-v2-max-preview",label:"Riverflow V2 Max Preview",modalities:{input:["text","image"],output:["image"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-12-08",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:8192}},{id:"sourceful/riverflow-v2-standard-preview",label:"Riverflow V2 Standard Preview",modalities:{input:["text","image"],output:["image"]},toolCall:!1,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2025-12-08",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:8192,output:8192}},{id:"stepfun/step-3.5-flash",label:"Step 3.5 Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2026-01-29",lastUpdated:"2026-01-29",openWeights:!0,cost:{input:.1,output:.3,cacheRead:.02},limit:{context:256e3,output:256e3}},{id:"stepfun/step-3.5-flash:free",label:"Step 3.5 Flash (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2026-01-29",lastUpdated:"2026-01-29",openWeights:!0,cost:{input:0,output:0},limit:{context:256e3,output:256e3}},{id:"thudm/glm-z1-32b:free",label:"GLM Z1 32B (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-04-17",lastUpdated:"2025-04-17",openWeights:!0,cost:{input:0,output:0},limit:{context:32768,output:32768}},{id:"tngtech/deepseek-r1t2-chimera:free",label:"DeepSeek R1T2 Chimera (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-07-08",lastUpdated:"2025-07-08",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"tngtech/tng-r1t-chimera:free",label:"R1T Chimera (free)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-11-26",lastUpdated:"2026-01-31",openWeights:!0,cost:{input:0,output:0},limit:{context:163840,output:163840}},{id:"x-ai/grok-3",label:"Grok 3",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-02-17",lastUpdated:"2025-02-17",openWeights:!1,cost:{input:3,output:15,cacheRead:.75,cacheWrite:15},limit:{context:131072,output:8192}},{id:"x-ai/grok-3-beta",label:"Grok 3 Beta",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-02-17",lastUpdated:"2025-02-17",openWeights:!1,cost:{input:3,output:15,cacheRead:.75,cacheWrite:15},limit:{context:131072,output:8192}},{id:"x-ai/grok-3-mini",label:"Grok 3 Mini",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-02-17",lastUpdated:"2025-02-17",openWeights:!1,cost:{input:.3,output:.5,cacheRead:.075,cacheWrite:.5},limit:{context:131072,output:8192}},{id:"x-ai/grok-3-mini-beta",label:"Grok 3 Mini Beta",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-02-17",lastUpdated:"2025-02-17",openWeights:!1,cost:{input:.3,output:.5,cacheRead:.075,cacheWrite:.5},limit:{context:131072,output:8192}},{id:"x-ai/grok-4",label:"Grok 4",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-07",releaseDate:"2025-07-09",lastUpdated:"2025-07-09",openWeights:!1,cost:{input:3,output:15,cacheRead:.75,cacheWrite:15},limit:{context:256e3,output:64e3}},{id:"x-ai/grok-4-fast",label:"Grok 4 Fast",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-08-19",lastUpdated:"2025-08-19",openWeights:!1,cost:{input:.2,output:.5,cacheRead:.05,cacheWrite:.05},limit:{context:2e6,output:3e4}},{id:"x-ai/grok-4.1-fast",label:"Grok 4.1 Fast",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-11",releaseDate:"2025-11-19",lastUpdated:"2025-11-19",openWeights:!1,cost:{input:.2,output:.5,cacheRead:.05,cacheWrite:.05},limit:{context:2e6,output:3e4}},{id:"x-ai/grok-code-fast-1",label:"Grok Code Fast 1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-08",releaseDate:"2025-08-26",lastUpdated:"2025-08-26",openWeights:!1,cost:{input:.2,output:1.5,cacheRead:.02},limit:{context:256e3,output:1e4}},{id:"xiaomi/mimo-v2-flash",label:"MiMo-V2-Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-12",releaseDate:"2025-12-14",lastUpdated:"2025-12-14",openWeights:!0,cost:{input:.1,output:.3,cacheRead:.01},limit:{context:262144,output:65536}},{id:"z-ai/glm-4.5",label:"GLM 4.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:.6,output:2.2},limit:{context:128e3,output:96e3}},{id:"z-ai/glm-4.5-air",label:"GLM 4.5 Air",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:.2,output:1.1},limit:{context:128e3,output:96e3}},{id:"z-ai/glm-4.5-air:free",label:"GLM 4.5 Air (free)",modalities:{input:["text"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:0,output:0},limit:{context:128e3,output:96e3}},{id:"z-ai/glm-4.5v",label:"GLM 4.5V",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-04",releaseDate:"2025-08-11",lastUpdated:"2025-08-11",openWeights:!0,cost:{input:.6,output:1.8},limit:{context:64e3,output:16384}},{id:"z-ai/glm-4.6",label:"GLM 4.6",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-09",releaseDate:"2025-09-30",lastUpdated:"2025-09-30",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.11},limit:{context:2e5,output:128e3}},{id:"z-ai/glm-4.6:exacto",label:"GLM 4.6 (exacto)",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-09",releaseDate:"2025-09-30",lastUpdated:"2025-09-30",openWeights:!0,cost:{input:.6,output:1.9,cacheRead:.11},limit:{context:2e5,output:128e3}},{id:"z-ai/glm-4.7",label:"GLM-4.7",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-22",lastUpdated:"2025-12-22",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.11},limit:{context:204800,output:131072}},{id:"z-ai/glm-4.7-flash",label:"GLM-4.7",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-01-19",lastUpdated:"2026-01-19",openWeights:!0,cost:{input:.07,output:.4},limit:{context:2e5,output:65535}},{id:"z-ai/glm-5",label:"GLM-5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-02-12",lastUpdated:"2026-02-12",openWeights:!0,cost:{input:1,output:3.2,cacheRead:.2},limit:{context:202752,output:131e3}}],label:"OpenRouter",env:["OPENROUTER_API_KEY"],npm:"@openrouter/ai-sdk-provider",api:"https://openrouter.ai/api/v1",doc:"https://openrouter.ai/models"},opencode:{id:"opencode",models:[{id:"big-pickle",label:"Big Pickle",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2025-10-17",lastUpdated:"2025-10-17",openWeights:!1,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:2e5,output:128e3}},{id:"claude-3-5-haiku",label:"Claude Haiku 3.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-07-31",releaseDate:"2024-10-22",lastUpdated:"2024-10-22",openWeights:!1,cost:{input:.8,output:4,cacheRead:.08,cacheWrite:1},limit:{context:2e5,output:8192},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-haiku-4-5",label:"Claude Haiku 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-02-28",releaseDate:"2025-10-15",lastUpdated:"2025-10-15",openWeights:!1,cost:{input:1,output:5,cacheRead:.1,cacheWrite:1.25},limit:{context:2e5,output:64e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-opus-4-1",label:"Claude Opus 4.1",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!1,cost:{input:15,output:75,cacheRead:1.5,cacheWrite:18.75},limit:{context:2e5,output:32e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-opus-4-5",label:"Claude Opus 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-11-24",lastUpdated:"2025-11-24",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:2e5,output:64e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-opus-4-6",label:"Claude Opus 4.6",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-08-31",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:5,output:25,cacheRead:.5,cacheWrite:6.25},limit:{context:1e6,output:128e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-sonnet-4",label:"Claude Sonnet 4",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:1e6,output:64e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"claude-sonnet-4-5",label:"Claude Sonnet 4.5",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-07-31",releaseDate:"2025-09-29",lastUpdated:"2025-09-29",openWeights:!1,cost:{input:3,output:15,cacheRead:.3,cacheWrite:3.75},limit:{context:1e6,output:64e3},provider:{npm:"@ai-sdk/anthropic"}},{id:"gemini-3-flash",label:"Gemini 3 Flash",modalities:{input:["text","image","video","audio","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-17",lastUpdated:"2025-12-17",openWeights:!1,cost:{input:.5,output:3,cacheRead:.05},limit:{context:1048576,output:65536},provider:{npm:"@ai-sdk/google"}},{id:"gemini-3-pro",label:"Gemini 3 Pro",modalities:{input:["text","image","video","audio","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-11-18",lastUpdated:"2025-11-18",openWeights:!1,cost:{input:2,output:12,cacheRead:.2},limit:{context:1048576,output:65536},provider:{npm:"@ai-sdk/google"}},{id:"glm-4.6",label:"GLM-4.6",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-30",lastUpdated:"2025-09-30",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.1},limit:{context:204800,output:131072}},{id:"glm-4.7",label:"GLM-4.7",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-22",lastUpdated:"2025-12-22",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.1},limit:{context:204800,output:131072}},{id:"glm-4.7-free",label:"GLM-4.7 Free",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-22",lastUpdated:"2025-12-22",openWeights:!0,cost:{input:0,output:0,cacheRead:0},limit:{context:204800,output:131072}},{id:"glm-5",label:"GLM-5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2026-02-11",lastUpdated:"2026-02-11",openWeights:!0,cost:{input:1,output:3.2,cacheRead:.2},limit:{context:204800,output:131072}},{id:"gpt-5",label:"GPT-5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:1.07,output:8.5,cacheRead:.107},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5-codex",label:"GPT-5 Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-09-15",lastUpdated:"2025-09-15",openWeights:!1,cost:{input:1.07,output:8.5,cacheRead:.107},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5-nano",label:"GPT-5 Nano",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-05-30",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:0,output:0,cacheRead:0},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.1",label:"GPT-5.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.07,output:8.5,cacheRead:.107},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.1-codex",label:"GPT-5.1 Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.07,output:8.5,cacheRead:.107},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.1-codex-max",label:"GPT-5.1 Codex Max",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:1.25,output:10,cacheRead:.125},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.1-codex-mini",label:"GPT-5.1 Codex Mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:.25,output:2,cacheRead:.025},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.2",label:"GPT-5.2",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"gpt-5.2-codex",label:"GPT-5.2 Codex",modalities:{input:["text","image","pdf"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2026-01-14",lastUpdated:"2026-01-14",openWeights:!1,cost:{input:1.75,output:14,cacheRead:.175},limit:{context:4e5,output:128e3},provider:{npm:"@ai-sdk/openai"}},{id:"grok-code",label:"Grok Code Fast 1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,releaseDate:"2025-08-20",lastUpdated:"2025-08-20",openWeights:!1,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:256e3,output:256e3}},{id:"kimi-k2",label:"Kimi K2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:.4,output:2.5,cacheRead:.4},limit:{context:262144,output:262144}},{id:"kimi-k2-thinking",label:"Kimi K2 Thinking",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:.4,output:2.5,cacheRead:.4},limit:{context:262144,output:262144}},{id:"kimi-k2.5",label:"Kimi K2.5",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2026-01-27",lastUpdated:"2026-01-27",openWeights:!0,cost:{input:.6,output:3,cacheRead:.08},limit:{context:262144,output:262144}},{id:"kimi-k2.5-free",label:"Kimi K2.5 Free",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2026-01-27",lastUpdated:"2026-01-27",openWeights:!0,cost:{input:0,output:0,cacheRead:0},limit:{context:262144,output:262144}},{id:"minimax-m2.1",label:"MiniMax M2.1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-23",lastUpdated:"2025-12-23",openWeights:!0,cost:{input:.3,output:1.2,cacheRead:.1},limit:{context:204800,output:131072}},{id:"minimax-m2.1-free",label:"MiniMax M2.1 Free",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-23",lastUpdated:"2025-12-23",openWeights:!0,cost:{input:0,output:0,cacheRead:0},limit:{context:204800,output:131072},provider:{npm:"@ai-sdk/anthropic"}},{id:"minimax-m2.5",label:"MiniMax M2.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2026-02-12",lastUpdated:"2026-02-12",openWeights:!0,cost:{input:.3,output:1.2,cacheRead:.06},limit:{context:204800,output:131072}},{id:"minimax-m2.5-free",label:"MiniMax M2.5 Free",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-01",releaseDate:"2026-02-12",lastUpdated:"2026-02-12",openWeights:!0,cost:{input:0,output:0,cacheRead:0},limit:{context:204800,output:131072}},{id:"qwen3-coder",label:"Qwen3 Coder",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-23",lastUpdated:"2025-07-23",openWeights:!0,cost:{input:.45,output:1.8},limit:{context:262144,output:65536}},{id:"trinity-large-preview-free",label:"Trinity Large Preview",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2025-06",releaseDate:"2026-01-28",lastUpdated:"2026-01-28",openWeights:!0,cost:{input:0,output:0},limit:{context:131072,output:131072}}],label:"OpenCode Zen",env:["OPENCODE_API_KEY"],npm:"@ai-sdk/openai-compatible",api:"https://opencode.ai/zen/v1",doc:"https://opencode.ai/docs/zen"},zai:{id:"zai",models:[{id:"glm-4.5",label:"GLM-4.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.11,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5-air",label:"GLM-4.5-Air",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:.2,output:1.1,cacheRead:.03,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5-flash",label:"GLM-4.5-Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5v",label:"GLM-4.5V",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-04",releaseDate:"2025-08-11",lastUpdated:"2025-08-11",openWeights:!0,cost:{input:.6,output:1.8},limit:{context:64e3,output:16384}},{id:"glm-4.6",label:"GLM-4.6",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-30",lastUpdated:"2025-09-30",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.11,cacheWrite:0},limit:{context:204800,output:131072}},{id:"glm-4.6v",label:"GLM-4.6V",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-08",lastUpdated:"2025-12-08",openWeights:!0,cost:{input:.3,output:.9},limit:{context:128e3,output:32768}},{id:"glm-4.7",label:"GLM-4.7",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-22",lastUpdated:"2025-12-22",openWeights:!0,cost:{input:.6,output:2.2,cacheRead:.11,cacheWrite:0},limit:{context:204800,output:131072}},{id:"glm-4.7-flash",label:"GLM-4.7-Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2026-01-19",lastUpdated:"2026-01-19",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:2e5,output:131072}},{id:"glm-5",label:"GLM-5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-02-11",lastUpdated:"2026-02-11",openWeights:!1,cost:{input:1,output:3.2,cacheRead:.2,cacheWrite:0},limit:{context:204800,output:131072}}],label:"Z.AI",env:["ZHIPU_API_KEY"],npm:"@ai-sdk/openai-compatible",api:"https://api.z.ai/api/paas/v4",doc:"https://docs.z.ai/guides/overview/pricing"},"zai-coding":{id:"zai-coding",models:[{id:"glm-4.5",label:"GLM-4.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5-air",label:"GLM-4.5-Air",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5-flash",label:"GLM-4.5-Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-07-28",lastUpdated:"2025-07-28",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:131072,output:98304}},{id:"glm-4.5v",label:"GLM-4.5V",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-04",releaseDate:"2025-08-11",lastUpdated:"2025-08-11",openWeights:!0,cost:{input:0,output:0},limit:{context:64e3,output:16384}},{id:"glm-4.6",label:"GLM-4.6",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-09-30",lastUpdated:"2025-09-30",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:204800,output:131072}},{id:"glm-4.6v",label:"GLM-4.6V",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-08",lastUpdated:"2025-12-08",openWeights:!0,cost:{input:0,output:0},limit:{context:128e3,output:32768}},{id:"glm-4.7",label:"GLM-4.7",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2025-12-22",lastUpdated:"2025-12-22",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:204800,output:131072}},{id:"glm-4.7-flash",label:"GLM-4.7-Flash",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-04",releaseDate:"2026-01-19",lastUpdated:"2026-01-19",openWeights:!0,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:2e5,output:131072}},{id:"glm-5",label:"GLM-5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-02-11",lastUpdated:"2026-02-11",openWeights:!1,cost:{input:0,output:0,cacheRead:0,cacheWrite:0},limit:{context:204800,output:131072}}],label:"Z.AI Coding Plan",env:["ZHIPU_API_KEY"],npm:"@ai-sdk/openai-compatible",api:"https://api.z.ai/api/coding/paas/v4",doc:"https://docs.z.ai/devpack/overview"},moonshot:{id:"moonshot",models:[{id:"kimi-k2-0711-preview",label:"Kimi K2 0711",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-07-14",lastUpdated:"2025-07-14",openWeights:!0,cost:{input:.6,output:2.5,cacheRead:.15},limit:{context:131072,output:16384}},{id:"kimi-k2-0905-preview",label:"Kimi K2 0905",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:.6,output:2.5,cacheRead:.15},limit:{context:262144,output:262144}},{id:"kimi-k2-thinking",label:"Kimi K2 Thinking",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-08",releaseDate:"2025-11-06",lastUpdated:"2025-11-06",openWeights:!0,cost:{input:.6,output:2.5,cacheRead:.15},limit:{context:262144,output:262144}},{id:"kimi-k2-thinking-turbo",label:"Kimi K2 Thinking Turbo",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2024-08",releaseDate:"2025-11-06",lastUpdated:"2025-11-06",openWeights:!0,cost:{input:1.15,output:8,cacheRead:.15},limit:{context:262144,output:262144}},{id:"kimi-k2-turbo-preview",label:"Kimi K2 Turbo",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!1,temperature:!0,knowledge:"2024-10",releaseDate:"2025-09-05",lastUpdated:"2025-09-05",openWeights:!0,cost:{input:2.4,output:10,cacheRead:.6},limit:{context:262144,output:262144}},{id:"kimi-k2.5",label:"Kimi K2.5",modalities:{input:["text","image","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2025-01",releaseDate:"2026-01",lastUpdated:"2026-01",openWeights:!0,cost:{input:.6,output:3,cacheRead:.1},limit:{context:262144,output:262144}}],label:"Moonshot AI",env:["MOONSHOT_API_KEY"],npm:"@ai-sdk/openai-compatible",api:"https://api.moonshot.ai/v1",doc:"https://platform.moonshot.ai/docs/api/chat"},minimax:{id:"minimax",models:[{id:"MiniMax-M2",label:"MiniMax-M2",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-10-27",lastUpdated:"2025-10-27",openWeights:!0,cost:{input:.3,output:1.2},limit:{context:196608,output:128e3}},{id:"MiniMax-M2.1",label:"MiniMax-M2.1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2025-12-23",lastUpdated:"2025-12-23",openWeights:!0,cost:{input:.3,output:1.2},limit:{context:204800,output:131072}},{id:"MiniMax-M2.5",label:"MiniMax-M2.5",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,releaseDate:"2026-02-12",lastUpdated:"2026-02-12",openWeights:!0,cost:{input:.3,output:1.2,cacheRead:.03,cacheWrite:.375},limit:{context:204800,output:131072}}],label:"MiniMax (minimax.io)",env:["MINIMAX_API_KEY"],npm:"@ai-sdk/anthropic",api:"https://api.minimax.io/anthropic/v1",doc:"https://platform.minimax.io/docs/guides/quickstart"},copilot:{id:"copilot",models:[{id:"claude-haiku-4.5",label:"Claude Haiku 4.5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-02-28",releaseDate:"2025-10-15",lastUpdated:"2025-10-15",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:32e3}},{id:"claude-opus-4.5",label:"Claude Opus 4.5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-11-24",lastUpdated:"2025-08-01",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:32e3}},{id:"claude-opus-4.6",label:"Claude Opus 4.6",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2026-02-05",lastUpdated:"2026-02-05",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"claude-opus-41",label:"Claude Opus 4.1",modalities:{input:["text","image"],output:["text"]},toolCall:!1,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-08-05",lastUpdated:"2025-08-05",openWeights:!1,cost:{input:0,output:0},limit:{context:8e4,output:16e3}},{id:"claude-sonnet-4",label:"Claude Sonnet 4",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-05-22",lastUpdated:"2025-05-22",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:16e3}},{id:"claude-sonnet-4.5",label:"Claude Sonnet 4.5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-03-31",releaseDate:"2025-09-29",lastUpdated:"2025-09-29",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:32e3}},{id:"gemini-2.5-pro",label:"Gemini 2.5 Pro",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-03-20",lastUpdated:"2025-06-05",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gemini-3-flash-preview",label:"Gemini 3 Flash",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-12-17",lastUpdated:"2025-12-17",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gemini-3-pro-preview",label:"Gemini 3 Pro Preview",modalities:{input:["text","image","audio","video"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2025-01",releaseDate:"2025-11-18",lastUpdated:"2025-11-18",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gpt-4.1",label:"GPT-4.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2024-04",releaseDate:"2025-04-14",lastUpdated:"2025-04-14",openWeights:!1,cost:{input:0,output:0},limit:{context:64e3,output:16384}},{id:"gpt-4o",label:"GPT-4o",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!1,attachment:!0,temperature:!0,knowledge:"2023-09",releaseDate:"2024-05-13",lastUpdated:"2024-05-13",openWeights:!1,cost:{input:0,output:0},limit:{context:64e3,output:16384}},{id:"gpt-5",label:"GPT-5",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-10",releaseDate:"2025-08-07",lastUpdated:"2025-08-07",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"gpt-5-mini",label:"GPT-5-mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!0,knowledge:"2024-06",releaseDate:"2025-08-13",lastUpdated:"2025-08-13",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gpt-5.1",label:"GPT-5.1",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gpt-5.1-codex",label:"GPT-5.1-Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"gpt-5.1-codex-max",label:"GPT-5.1-Codex-max",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-12-04",lastUpdated:"2025-12-04",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"gpt-5.1-codex-mini",label:"GPT-5.1-Codex-mini",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2024-09-30",releaseDate:"2025-11-13",lastUpdated:"2025-11-13",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:128e3}},{id:"gpt-5.2",label:"GPT-5.2",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!0,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}},{id:"gpt-5.2-codex",label:"GPT-5.2-Codex",modalities:{input:["text","image"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!1,knowledge:"2025-08-31",releaseDate:"2025-12-11",lastUpdated:"2025-12-11",openWeights:!1,cost:{input:0,output:0},limit:{context:272e3,output:128e3}},{id:"grok-code-fast-1",label:"Grok Code Fast 1",modalities:{input:["text"],output:["text"]},toolCall:!0,reasoningText:!0,attachment:!1,temperature:!0,knowledge:"2025-08",releaseDate:"2025-08-27",lastUpdated:"2025-08-27",openWeights:!1,cost:{input:0,output:0},limit:{context:128e3,output:64e3}}],label:"GitHub Copilot",env:["GITHUB_TOKEN"],npm:"@ai-sdk/openai-compatible",api:"https://api.githubcopilot.com",doc:"https://docs.github.com/en/copilot"}},CB="setu",KI=e=>e==="codex-mini-latest"?!0:e==="gpt-5.3"||e.startsWith("gpt-5.3-")?!1:!!(e.startsWith("gpt-5")||e.includes("codex")),JI=e=>!!(e.includes("-3-5-")||e.includes("-3.5-")||e.match(/claude-(haiku|sonnet|opus)-3/)||e.includes("-4-")||e.includes("-4.")||e.match(/claude-(haiku|sonnet|opus)-4/)),RI=e=>!!e.startsWith("gemini-3"),LI=e=>!!(e.startsWith("glm-4.7")||e.startsWith("glm-5")),jI=e=>e==="MiniMax-M2.5"||e==="MiniMax-M2.1",vI=[{id:"openai",npm:"@ai-sdk/openai",family:"openai"},{id:"anthropic",npm:"@ai-sdk/anthropic",family:"anthropic"},{id:"moonshot",npm:"@ai-sdk/openai-compatible",family:"moonshot"},{id:"google",npm:"@ai-sdk/google",family:"google"},{id:"zai",npm:"@ai-sdk/openai-compatible",family:"openai-compatible"},{id:"minimax",npm:"@ai-sdk/anthropic",family:"minimax"}];function qI(e){return{...e,modalities:e.modalities?{input:e.modalities.input?[...e.modalities.input]:void 0,output:e.modalities.output?[...e.modalities.output]:void 0}:void 0,cost:e.cost?{...e.cost}:void 0,limit:e.limit?{...e.limit}:void 0,provider:e.provider?{...e.provider}:void 0}}function OI(e){const A=vI.flatMap(({id:o,npm:Q,family:B})=>(e[o]?.models??[]).filter(i=>o==="openai"?KI(i.id):o==="anthropic"?JI(i.id):o==="google"?RI(i.id):o==="zai"?LI(i.id):o==="minimax"?jI(i.id):!0).map(i=>{const E=qI(i);return E.provider={...E.provider??{},npm:Q,family:B},E}));if(!A.length)return null;A.sort((o,Q)=>{const B=o.provider?.npm??"",a=Q.provider?.npm??"";return B===a?o.id.localeCompare(Q.id):B==="@ai-sdk/openai"?-1:a==="@ai-sdk/openai"?1:B.localeCompare(a)});const g="codex-mini-latest",s=A.findIndex(o=>o.id===g);if(s>0){const[o]=A.splice(s,1);A.unshift(o)}return{id:CB,label:"Setu",env:["SETU_PRIVATE_KEY"],api:"https://setu.ottocode.io/v1",doc:"https://setu.ottocode.io/docs",models:A}}function TI(e){const A=OI(e),g={...e};return A&&(g[CB]=A),g}const IB=TI(SI),YI={openai:[{match:e=>e.includes("gpt-4o-mini"),inputPerMillion:.15,outputPerMillion:.6},{match:e=>e.includes("gpt-4o"),inputPerMillion:5,outputPerMillion:15},{match:e=>e.includes("gpt-4.1-mini"),inputPerMillion:1,outputPerMillion:4},{match:e=>e.includes("gpt-4.1"),inputPerMillion:5,outputPerMillion:15}],anthropic:[{match:e=>e.includes("claude-3-haiku"),inputPerMillion:.25,outputPerMillion:1.25},{match:e=>e.includes("claude-3-sonnet"),inputPerMillion:3,outputPerMillion:15},{match:e=>e.includes("claude-3-opus"),inputPerMillion:15,outputPerMillion:75}],google:[{match:e=>e.includes("gemini-1.5-flash"),inputPerMillion:.35,outputPerMillion:1.05},{match:e=>e.includes("gemini-1.5-pro"),inputPerMillion:3.5,outputPerMillion:10.5}],openrouter:[],opencode:[],setu:[],zai:[],"zai-coding":[],moonshot:[],copilot:[]};function HI(e,A){const g=YI[e];if(g)return g.find(s=>{try{return s.match(A)}catch{return!1}})}function PI(e,A){const g=IB[e];if(!g)return;const s=A.toLowerCase();return g.models.find(o=>o.id?.toLowerCase()===s)}function lB(e,A,g){const s=typeof g.inputTokens=="number"?g.inputTokens:0,o=typeof g.outputTokens=="number"?g.outputTokens:0,Q=typeof g.cachedInputTokens=="number"?g.cachedInputTokens:0,B=typeof g.cacheCreationInputTokens=="number"?g.cacheCreationInputTokens:0;if(!s&&!o&&!Q&&!B)return;const a=PI(e,A);if(a?.cost?.input!=null||a?.cost?.output!=null){const n=typeof a.cost?.input=="number"?a.cost.input:0,C=typeof a.cost?.output=="number"?a.cost.output:0,d=typeof a.cost?.cacheRead=="number"?a.cost.cacheRead:0,u=typeof a.cost?.cacheWrite=="number"?a.cost.cacheWrite:0,w=Math.max(0,s-Q-B)*n/1e6,h=o*C/1e6,m=Q*d/1e6,k=B*u/1e6,y=w+h+m+k;return Number.isFinite(y)?Number(y.toFixed(6)):void 0}const r=HI(e,A.toLowerCase());if(!r)return;const E=Math.max(0,s-Q-B)*r.inputPerMillion/1e6,I=o*r.outputPerMillion/1e6,c=E+I;return Number.isFinite(c)?Number(c.toFixed(6)):void 0}function cB(e,A){const g=IB[e];if(g)return g.models?.find(s=>s.id===A)}function WI({session:e,onNavigateToSession:A}){const{data:g}=rB(e.sessionType==="branch"?e.id:void 0),{data:s}=fs(e.id),o=l.useMemo(()=>{const d=e.totalInputTokens||0,u=e.totalOutputTokens||0,D=e.totalCachedTokens||0,w=e.totalCacheCreationTokens||0;return lB(e.provider,e.model,{inputTokens:d,outputTokens:u,cachedInputTokens:D,cacheCreationInputTokens:w})??0},[e.provider,e.model,e.totalInputTokens,e.totalOutputTokens,e.totalCachedTokens,e.totalCacheCreationTokens]),Q=d=>{if(!d)return"0s";const u=Math.floor(d/1e3),D=Math.floor(u/60),w=Math.floor(D/60);return w>0?`${w}h ${D%60}m`:D>0?`${D}m ${u%60}s`:`${u}s`},B=d=>d.toLocaleString("en-US"),a=d=>d>=1e6?`${(d/1e6).toFixed(1)}M`:d>=1e3?`${(d/1e3).toFixed(1)}K`:d.toString(),r=e.currentContextTokens||0,i=e.totalOutputTokens||0,E=e.sessionType==="branch",I=g?.parent,c=l.useMemo(()=>cB(e.provider,e.model)?.limit?.context,[e.provider,e.model]),n=c?r/c*100:0,C=()=>n>=90?"text-red-600 dark:text-red-400":n>=70?"text-amber-600 dark:text-amber-400":"text-foreground";return t.jsx("div",{className:"border-b border-border bg-background/95 backdrop-blur-sm",children:t.jsxs("div",{className:"max-w-3xl mx-auto px-6 py-6",children:[E&&t.jsxs("div",{className:"flex items-center gap-2 mb-3 text-sm",children:[t.jsx(XA,{className:"h-4 w-4 text-violet-500"}),t.jsx("span",{className:"text-violet-600 dark:text-violet-400 font-medium",children:"Branch"}),I&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground",children:"from"}),t.jsxs("button",{type:"button",onClick:()=>A?.(I.id),className:"text-primary hover:underline flex items-center gap-1",children:[I.title||`Session ${I.id.slice(0,8)}`,t.jsx(_o,{className:"h-3 w-3"})]})]}),!I&&e.parentSessionId&&t.jsx("span",{className:"text-muted-foreground italic text-xs",children:"(parent deleted)"})]}),t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx("h1",{className:"text-2xl font-semibold text-foreground leading-tight truncate",children:e.title||"Untitled Session"}),s?.shared&&t.jsxs("button",{type:"button",onClick:()=>Ce(s.url),className:"flex items-center gap-1.5 px-2 py-1 rounded-md bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 hover:bg-emerald-500/20 transition-colors text-xs font-medium flex-shrink-0",children:[t.jsx(ns,{className:"h-3 w-3"}),t.jsx("span",{children:"Shared"}),s.pendingMessages&&s.pendingMessages>0?t.jsxs("span",{className:"flex items-center gap-0.5 text-amber-600 dark:text-amber-400",children:[t.jsx(HA,{className:"h-2.5 w-2.5"}),s.pendingMessages]}):t.jsx(jA,{className:"h-2.5 w-2.5 opacity-60"})]})]}),t.jsxs("div",{className:"flex flex-wrap items-center gap-x-5 gap-y-2 mt-4 text-sm text-muted-foreground",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsxs("div",{className:"flex items-center gap-1.5",title:`Current context window: ${B(r)} tokens`,children:[t.jsx("span",{className:"text-xs opacity-70",children:"ctx"}),t.jsx("span",{className:`font-medium ${C()}`,children:a(r)})]}),t.jsxs("div",{className:"flex items-center gap-1.5",title:`Total output: ${B(i)} tokens`,children:[t.jsx("span",{className:"text-xs opacity-70",children:"out"}),t.jsx("span",{className:"font-medium text-foreground",children:a(i)})]})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(Cs,{className:"w-4 h-4"}),t.jsx("span",{className:"font-medium text-foreground",children:Q(e.totalToolTimeMs)})]}),o>0&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx($o,{className:"w-4 h-4"}),t.jsx("span",{className:"font-medium text-foreground",children:o.toFixed(4)})]}),t.jsxs("div",{className:"flex items-center gap-2 ml-auto",children:[t.jsx(ZA,{provider:e.provider,size:18}),t.jsx("span",{className:"font-medium text-foreground truncate max-w-48",children:e.model})]})]})]})})}const De=MA(e=>({usage:{},isLoading:{},lastFetched:{},isModalOpen:!1,modalProvider:null,setUsage:(A,g)=>e(s=>({usage:{...s.usage,[A]:g}})),setLoading:(A,g)=>e(s=>({isLoading:{...s.isLoading,[A]:g}})),setLastFetched:(A,g)=>e(s=>({lastFetched:{...s.lastFetched,[A]:g}})),openModal:A=>e({isModalOpen:!0,modalProvider:A}),closeModal:()=>e({isModalOpen:!1,modalProvider:null})})),je=22,es=2.5,ts=(je-es)/2,Ug=2*Math.PI*ts;function zI(e){return e>=90?"#ef4444":e>=70?"#f59e0b":"#3b82f6"}const VI=l.memo(function({usage:A,provider:g}){const s=De(a=>a.openModal),o=A.primaryWindow?.usedPercent??0,Q=Ug-o/100*Ug,B=zI(o);return t.jsxs("button",{type:"button",onClick:()=>s(g),className:"relative flex items-center hover:opacity-80 transition-opacity cursor-pointer",title:`Usage: ${Math.round(o)}% (5h window) — Click for details`,children:[t.jsxs("svg",{width:je,height:je,className:"-rotate-90",role:"img","aria-label":"Usage ring",children:[t.jsx("circle",{cx:je/2,cy:je/2,r:ts,fill:"none",stroke:"hsl(var(--muted))",strokeWidth:es}),t.jsx("circle",{cx:je/2,cy:je/2,r:ts,fill:"none",stroke:B,strokeWidth:es,strokeDasharray:Ug,strokeDashoffset:Q,strokeLinecap:"round",className:"transition-all duration-500"})]}),t.jsx("span",{className:"absolute inset-0 flex items-center justify-center rotate-0 font-medium text-muted-foreground",style:{fontSize:7},children:"5h"})]})});function ZI(e){if(!e)return"Unknown";const A=Date.now(),s=new Date(e).getTime()-A;if(s<=0)return"Now";const o=Math.floor(s/864e5),Q=Math.floor(s%864e5/36e5),B=Math.floor(s%36e5/6e4);return o>0?`${o}d ${Q}h`:Q>0?`${Q}h ${B}m`:`${B}m`}function No(e){return e<=18e3?"5 Hour":e<=86400?"24 Hour":"7 Day"}function Sg({label:e,window:A}){const g=Math.min(A.usedPercent,100),s=g>=90?"bg-red-500":g>=70?"bg-amber-500":"bg-blue-500";return t.jsxs("div",{className:"space-y-1.5",children:[t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:e}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsxs("span",{className:"font-medium text-foreground",children:[Math.round(g),"%"]}),A.resetsAt&&t.jsxs("span",{className:"text-xs text-muted-foreground",children:["resets in ",ZI(A.resetsAt)]})]})]}),t.jsx("div",{className:"h-2 rounded-full bg-muted overflow-hidden",children:t.jsx("div",{className:`h-full rounded-full transition-all duration-500 ${s}`,style:{width:`${g}%`}})})]})}const XI=l.memo(function(){const A=De(B=>B.isModalOpen),g=De(B=>B.modalProvider),s=De(B=>B.closeModal),o=De(B=>g?B.usage[g]:void 0),Q=l.useMemo(()=>t.jsxs("div",{className:"flex items-center gap-2",children:[g&&t.jsx(ZA,{provider:g,size:20}),t.jsx("span",{children:"Usage & Limits"})]}),[g]);return o?t.jsx(Me,{isOpen:A,onClose:s,title:Q,maxWidth:"sm",children:t.jsxs("div",{className:"space-y-5",children:[o.limitReached&&t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 rounded-md bg-red-500/10 border border-red-500/20",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-red-500 flex-shrink-0"}),t.jsx("span",{className:"text-sm text-red-600 dark:text-red-400 font-medium",children:"Rate limit reached"})]}),o.primaryWindow&&t.jsx(Sg,{label:`${No(o.primaryWindow.windowSeconds)} Window`,window:o.primaryWindow}),o.secondaryWindow&&t.jsx(Sg,{label:`${No(o.secondaryWindow.windowSeconds)} Window`,window:o.secondaryWindow}),o.sonnetWindow&&o.sonnetWindow.usedPercent>0&&t.jsx(Sg,{label:"Sonnet (7 Day)",window:{usedPercent:o.sonnetWindow.usedPercent,windowSeconds:604800,resetsAt:o.sonnetWindow.resetsAt}}),o.extraUsage?.is_enabled&&t.jsx("div",{className:"pt-2 border-t border-border space-y-1",children:t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Extra Credits"}),t.jsxs("span",{className:"font-medium text-foreground",children:["$",o.extraUsage.used_credits.toFixed(2)," / $",o.extraUsage.monthly_limit]})]})}),o.credits?.has_credits&&t.jsx("div",{className:"pt-2 border-t border-border space-y-1",children:t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Credits"}),t.jsx("span",{className:"font-medium text-foreground",children:o.credits.balance!==null?`$${o.credits.balance.toFixed(2)}`:"Available"})]})}),o.planType&&t.jsx("div",{className:"pt-2 border-t border-border",children:t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Plan"}),t.jsx("span",{className:"font-medium text-foreground capitalize",children:o.planType})]})})]})}):null}),_I=6e4,$I=3e4;function Al(e,A){const g=De(i=>i.setUsage),s=De(i=>i.setLoading),o=De(i=>i.setLastFetched),Q=De(i=>e?i.usage[e]:void 0),B=De(i=>e?i.lastFetched[e]:0),a=A==="oauth"&&(e==="anthropic"||e==="openai"),r=l.useCallback(async()=>{if(!(!e||!a)){s(e,!0);try{const i=await v.getProviderUsage(e);g(e,i),o(e,Date.now())}catch{}finally{s(e,!1)}}},[e,a,g,s,o]);return l.useEffect(()=>{if(!a)return;(!B||Date.now()-B>$I)&&r();const E=setInterval(r,_I);return()=>clearInterval(E)},[a,r,B]),{usage:Q,fetchUsage:r,isOAuthProvider:a}}function el({session:e,isVisible:A,isGenerating:g,onNavigateToSession:s}){const{data:o}=rB(e.sessionType==="branch"?e.id:void 0),{data:Q}=fs(e.id),B=l.useMemo(()=>{const w=e.totalInputTokens||0,h=e.totalOutputTokens||0,m=e.totalCachedTokens||0,k=e.totalCacheCreationTokens||0;return lB(e.provider,e.model,{inputTokens:w,outputTokens:h,cachedInputTokens:m,cacheCreationInputTokens:k})??0},[e.provider,e.model,e.totalInputTokens,e.totalOutputTokens,e.totalCachedTokens,e.totalCacheCreationTokens]),a=w=>w>=1e6?`${(w/1e6).toFixed(1)}M`:w>=1e3?`${(w/1e3).toFixed(1)}K`:w.toString(),r=e.currentContextTokens||0,i=e.sessionType==="branch",E=o?.parent,I=l.useMemo(()=>cB(e.provider,e.model)?.limit?.context,[e.provider,e.model]),c=I?r/I*100:0,n=()=>c>=90?"text-red-600 dark:text-red-400":c>=70?"text-amber-600 dark:text-amber-400":"text-foreground",{data:C}=Nt(),d=C?.[e.provider]?.authType,{usage:u,isOAuthProvider:D}=Al(e.provider,d);return t.jsxs(t.Fragment,{children:[t.jsx("div",{className:`absolute top-0 left-0 right-0 h-14 border-b border-border bg-background/95 backdrop-blur-sm z-10 transition-transform duration-200 ${A?"translate-y-0":"-translate-y-full"}`,children:t.jsxs("div",{className:"h-full px-6 flex items-center justify-between gap-4 text-sm",children:[t.jsxs("div",{className:"flex-1 min-w-0 flex items-center gap-2 text-muted-foreground",children:[i?t.jsx(XA,{className:"w-4 h-4 flex-shrink-0 text-violet-500"}):t.jsx(AQ,{className:"w-4 h-4 flex-shrink-0"}),t.jsx("span",{className:"text-foreground font-medium truncate",children:e.title||"Untitled Session"}),Q?.shared&&t.jsxs("button",{type:"button",onClick:()=>Ce(Q.url),className:"flex items-center gap-1 px-1.5 py-0.5 rounded bg-emerald-500/10 text-emerald-600 dark:text-emerald-400 hover:bg-emerald-500/20 transition-colors text-xs font-medium flex-shrink-0",children:[t.jsx(ns,{className:"h-3 w-3"}),Q.pendingMessages&&Q.pendingMessages>0?t.jsxs("span",{className:"flex items-center gap-0.5 text-amber-600 dark:text-amber-400",children:[t.jsx(HA,{className:"h-2.5 w-2.5"}),Q.pendingMessages]}):t.jsx(jA,{className:"h-2.5 w-2.5 opacity-60"})]}),i&&E&&t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"text-muted-foreground hidden sm:inline",children:"from"}),t.jsxs("button",{type:"button",onClick:()=>s?.(E.id),className:"text-primary hover:underline flex items-center gap-0.5 truncate max-w-32",title:E.title||`Session ${E.id.slice(0,8)}`,children:[t.jsx("span",{className:"truncate",children:E.title||`Session ${E.id.slice(0,8)}`}),t.jsx(_o,{className:"h-3 w-3 flex-shrink-0"})]})]})]}),t.jsxs("div",{className:"flex-shrink-0 flex items-center gap-5 text-muted-foreground",children:[g&&t.jsx(UC,{sessionId:e.id}),D&&u&&t.jsx(VI,{usage:u,provider:e.provider}),t.jsx("div",{className:"flex items-center gap-3",children:t.jsxs("div",{className:"flex items-center gap-1",title:`Current context window: ${r.toLocaleString()} tokens`,children:[t.jsx("span",{className:"text-xs opacity-70",children:"ctx"}),t.jsx("span",{className:`font-medium ${n()}`,children:a(r)})]})}),B>0&&t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx($o,{className:"w-4 h-4"}),t.jsx("span",{className:"text-foreground font-medium",children:B.toFixed(4)})]}),t.jsxs("div",{className:"hidden sm:flex items-center gap-2",children:[t.jsx(ZA,{provider:e.provider,size:16}),t.jsx("span",{className:"font-medium text-foreground truncate max-w-40",children:e.model})]})]})]})}),t.jsx(XI,{})]})}const tl=l.memo(function({pendingTopup:A,onMethodSelected:g,onCancel:s}){const[o,Q]=l.useState(!1),[B,a]=l.useState(null),r=IA(c=>c.openTopupModal),i=async()=>{a("crypto"),Q(!0);try{await v.selectTopupMethod(A.sessionId,"crypto"),g("crypto")}catch(c){QA.error(c instanceof Error?c.message:"Failed to process payment"),Q(!1),a(null)}},E=async()=>{a("fiat"),r(),v.selectTopupMethod(A.sessionId,"fiat").catch(()=>{}),g("fiat")},I=async()=>{Q(!0);try{await v.cancelTopup(A.sessionId),s()}catch(c){QA.error(c instanceof Error?c.message:"Failed to cancel"),Q(!1)}};return t.jsxs("div",{className:"flex flex-col gap-3 py-2",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(le,{className:"h-4 w-4 text-amber-500 flex-shrink-0"}),t.jsx("span",{className:"font-medium text-foreground text-sm",children:"Insufficient Balance"}),t.jsx("span",{className:"text-amber-600 dark:text-amber-400 font-medium text-sm",children:"payment required"})]}),t.jsxs("div",{className:"ml-6 bg-muted/30 rounded-lg p-3 space-y-2 text-sm",children:[t.jsxs("div",{className:"flex justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Request cost"}),t.jsxs("span",{className:"font-mono",children:["~$",A.amountUsd.toFixed(4)]})]}),t.jsxs("div",{className:"flex justify-between",children:[t.jsx("span",{className:"text-muted-foreground",children:"Current balance"}),t.jsxs("span",{className:"font-mono",children:["$",A.currentBalance.toFixed(4)]})]})]}),t.jsxs("div",{className:"ml-6 flex flex-wrap items-center gap-2",children:[t.jsxs("button",{type:"button",onClick:I,disabled:o,title:"Cancel request",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded border border-border bg-background hover:bg-muted transition-colors disabled:opacity-50",children:[t.jsx(kA,{className:"w-3 h-3"}),"Cancel"]}),t.jsxs("button",{type:"button",onClick:i,disabled:o,title:"Pay with USDC from your wallet",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded bg-violet-600 text-white hover:bg-violet-700 transition-colors disabled:opacity-50",children:[B==="crypto"&&o?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):t.jsx(Is,{className:"w-3 h-3"}),"Pay with USDC"]}),t.jsxs("button",{type:"button",onClick:E,disabled:o,title:"Top up balance with card (min $5)",className:"flex items-center gap-1.5 px-3 py-1.5 text-xs font-medium rounded border border-violet-500 text-violet-600 dark:text-violet-400 hover:bg-violet-500/10 transition-colors disabled:opacity-50",children:[B==="fiat"&&o?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):t.jsx(ct,{className:"w-3 h-3"}),"Top up with Card",t.jsx("span",{className:"text-[10px] opacity-70",children:"(min $5)"})]})]}),t.jsx("p",{className:"ml-6 text-xs text-muted-foreground",children:B==="crypto"?"Processing USDC payment from your wallet...":B==="fiat"?"Opening Polar checkout...":"Select a payment method to continue your request."})]})}),tg=MA(e=>({pendingTopup:null,isProcessing:!1,selectedMethod:null,setPendingTopup:A=>e({pendingTopup:A,isProcessing:!1,selectedMethod:null}),setProcessing:A=>e({isProcessing:A}),setSelectedMethod:A=>e({selectedMethod:A}),clearPendingTopup:()=>e({pendingTopup:null,isProcessing:!1,selectedMethod:null})})),gl=l.memo(function({messages:A,session:g,sessionId:s,isGenerating:o,disableAutoScroll:Q=!1,onSelectSession:B}){const a=sA(),r=l.useRef(null),i=l.useRef(null),E=l.useRef(null),[I,c]=l.useState(!0),n=l.useRef(!0),[C,d]=l.useState(!1),u=l.useRef(!1),D=l.useRef(void 0),w=l.useRef(0),h=l.useRef(void 0),m=l.useRef(!1),k=l.useRef(g?.id),y=l.useRef(A.length),G=l.useRef(o),M=l.useRef(0),x=l.useRef(0),F=tg(R=>R.pendingTopup),p=tg(R=>R.clearPendingTopup),f=F&&F.sessionId===s,N=l.useCallback(()=>{const R=i.current;if(!R)return;const{scrollTop:j,scrollHeight:J,clientHeight:H}=R,z=J-j-H,AA=J>M.current,tA=j<x.current-5;M.current=J,x.current=j,z<100?(n.current=!0,c(!0)):tA?(n.current=!1,c(!1),u.current=!0):!AA&&n.current&&(n.current=!1,c(!1)),(tA||!n.current&&z>=100)&&(D.current&&clearTimeout(D.current),D.current=setTimeout(()=>{u.current=!1},150));const lA=E.current;if(lA){const yA=lA.getBoundingClientRect(),P=R.getBoundingClientRect();d(yA.bottom<P.top)}},[]);l.useEffect(()=>{if(Q)return;const R=g?.id!==k.current;if(k.current=g?.id,R&&(m.current=!1),!m.current&&A.length>0){m.current=!0;const j=i.current;j&&(j.scrollTop=j.scrollHeight)}},[A.length,g?.id,Q]),l.useEffect(()=>{if(Q)return;const R=o&&!G.current,j=A.length>y.current;G.current=o,y.current=A.length,R?(u.current=!1,n.current=!0,c(!0),requestAnimationFrame(()=>{requestAnimationFrame(()=>{const J=i.current;J&&(J.scrollTop=J.scrollHeight)})})):j&&!u.current&&!o&&(n.current=!0,c(!0))},[A.length,o,Q]),l.useEffect(()=>{if(Q)return;const R=i.current;if(!R||!I||u.current)return;w.current=R.scrollHeight-R.clientHeight;const j=()=>{const J=i.current;if(!J||u.current)return;const H=J.scrollTop,AA=J.scrollHeight-J.clientHeight-H;if(Math.abs(AA)<1){J.scrollTop=J.scrollHeight-J.clientHeight;return}if(Math.abs(AA)<10){J.scrollTop=J.scrollHeight-J.clientHeight;return}J.scrollTop=H+AA*.15,h.current=requestAnimationFrame(j)};h.current&&cancelAnimationFrame(h.current),h.current=requestAnimationFrame(j)},[A,I]),l.useEffect(()=>()=>{D.current&&clearTimeout(D.current),h.current&&cancelAnimationFrame(h.current)},[]);const b=()=>{u.current=!1,n.current=!0,c(!0);const R=i.current;R&&(R.scrollTop=R.scrollHeight)},S=l.useMemo(()=>A.filter(R=>R.role!=="system"),[A]),O=l.useCallback(R=>async()=>{if(s&&R){a.setQueryData(["messages",s],j=>j&&j.map(J=>{if(J.id!==R)return J;const H=J.parts?.filter(z=>!(z.type==="error"||z.type==="tool_call"&&z.toolName==="finish"))??[];return{...J,status:"pending",parts:H,error:null}}));try{await v.retryMessage(s,R)}catch(j){QA.error(j instanceof Error?j.message:"Failed to retry")}}},[s,a]),L=l.useCallback(async()=>{if(s)try{await v.sendMessage(s,{content:"/compact"})}catch(R){QA.error(R instanceof Error?R.message:"Failed to compact")}},[s]);return A.length===0?t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground text-sm",children:"No messages yet. Start a conversation below."}):t.jsxs("div",{className:"absolute inset-0 flex flex-col",children:[g&&t.jsx(el,{session:g,isVisible:C,isGenerating:o,onNavigateToSession:B}),t.jsxs("div",{ref:i,className:"flex-1 overflow-y-auto",onScroll:N,children:[t.jsx("div",{ref:E,children:g&&t.jsx(WI,{session:g,onNavigateToSession:B})}),t.jsx("div",{className:"p-6 pb-64",children:t.jsxs("div",{className:"max-w-3xl mx-auto space-y-6",children:[S.map((R,j)=>{const J=S[j-1],H=S[j+1],z=j===S.length-1;if(R.role==="user"){const AA=H&&H.role==="assistant"?H:void 0;return t.jsx(nB,{sessionId:s,message:R,isFirst:j===0,nextAssistantMessageId:AA?.id},R.id)}if(R.role==="assistant"){const AA=!J||J.role!=="assistant",tA=H&&H.role==="assistant";return t.jsx(EB,{sessionId:s,message:R,showHeader:AA,hasNextAssistantMessage:tA,isLastMessage:z,onBranchCreated:B,onRetry:z?O(R.id):void 0,onCompact:z?L:void 0},R.id)}return null}),f&&F&&t.jsx("div",{className:"py-4",children:t.jsx(tl,{pendingTopup:F,onMethodSelected:()=>p(),onCancel:()=>p()})}),t.jsx("div",{ref:r})]})})]}),!I&&t.jsxs("button",{type:"button",onClick:b,className:"absolute bottom-36 left-1/2 -translate-x-1/2 flex items-center gap-2 px-4 py-2 bg-background border border-border rounded-full shadow-lg hover:bg-muted/50 transition-all text-sm text-foreground z-10",children:[t.jsx(Ca,{className:"w-4 h-4"}),t.jsx("span",{children:"Scroll to bottom"})]})]})});class dB{abortController=null;handlers=new Map;running=!1;async connect(A){this.abortController&&this.abortController.abort(),this.abortController=new AbortController,this.running=!0;try{const g=await fetch(A,{headers:{Accept:"text/event-stream"},signal:this.abortController.signal});if(!g.ok){console.error("[SSE] Connection failed:",g.status);return}const s=g.body?.getReader();if(!s){console.error("[SSE] No response body");return}const o=new TextDecoder;let Q="";for(;this.running;){const{done:B,value:a}=await s.read();if(B)break;Q+=o.decode(a,{stream:!0});let r=Q.indexOf(`
103
103
 
@@ -124,7 +124,7 @@ ${C?.absPath||""}`,children:g}),s&&t.jsx("span",{className:"text-xs px-2 py-0.5
124
124
  `),g=[];let s=0,o=0,Q=!1,B="";for(const a of A){if(a.startsWith("+++")||a.startsWith("*** Update File:")){const i=a.match(/\+\+\+ b\/(.+)/)||a.match(/\*\*\* Update File: (.+)/);i&&(B=i[1])}if(a.startsWith("*** Add File:")){const i=a.match(/\*\*\* Add File: (.+)/);i&&(B=i[1])}const r=a.match(/^@@ -(\d+)(?:,\d+)? \+(\d+)(?:,\d+)? @@/);if(r){s=Number.parseInt(r[1],10),o=Number.parseInt(r[2],10),Q=!0,g.push({content:a,codeContent:a,type:"header"});continue}if(a.startsWith("***")||a.startsWith("diff ")||a.startsWith("index ")||a.startsWith("---")||a.startsWith("+++")||a.startsWith("@@")&&!Q){g.push({content:a,codeContent:a,type:"meta"});continue}Q?a.startsWith("+")?g.push({content:a,codeContent:a.slice(1),type:"add",newLineNum:o++}):a.startsWith("-")?g.push({content:a,codeContent:a.slice(1),type:"remove",oldLineNum:s++}):a.startsWith(" ")||a===""?g.push({content:a,codeContent:a.startsWith(" ")?a.slice(1):a,type:"context",oldLineNum:s++,newLineNum:o++}):g.push({content:a,codeContent:a,type:"context",oldLineNum:s++,newLineNum:o++}):g.push({content:a,codeContent:a,type:"meta"})}return{lines:g,filePath:B}}function vl({patch:e}){const{lines:A,filePath:g}=jl(e),s=Ll(g),o=document?.documentElement.classList.contains("dark")?ce:de;return t.jsx("div",{className:"bg-card/60 border border-border rounded-lg overflow-hidden h-full",children:t.jsx("div",{className:"overflow-x-auto overflow-y-auto h-full text-xs font-mono",children:A.map((Q,B)=>{const a=`line-${B}-${Q.content.slice(0,20)}`;if(Q.type==="meta"||Q.type==="header")return t.jsx("div",{className:`px-3 py-0.5 whitespace-pre-wrap break-all ${Q.type==="header"?"text-muted-foreground/80 bg-muted/20":"text-muted-foreground/80"}`,children:Q.content},a);let r="",i="";switch(Q.type){case"add":r="text-emerald-700 dark:text-emerald-300",i="bg-emerald-500/10";break;case"remove":r="text-red-600 dark:text-red-300",i="bg-red-500/10";break;default:r="text-foreground/80"}let E=Q.content;return Q.codeContent.trim()&&s!=="text"&&(E=t.jsx(WA,{language:s,style:o,customStyle:{margin:0,padding:0,background:"transparent",display:"inline",fontSize:"inherit",lineHeight:"inherit"},codeTagProps:{style:{fontFamily:"inherit",background:"transparent"}},PreTag:"span",children:Q.codeContent}),Q.type==="add"?E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:"+"}),E]}):Q.type==="remove"?E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:"-"}),E]}):Q.type==="context"&&(E=t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"select-none",children:" "}),E]}))),t.jsxs("div",{className:`flex ${i}`,children:[t.jsx("div",{className:"px-2 py-0.5 text-right text-muted-foreground/40 select-none w-12 flex-shrink-0","aria-hidden":"true",style:{pointerEvents:"none"},children:Q.oldLineNum||""}),t.jsx("div",{className:"px-2 py-0.5 text-right text-muted-foreground/40 select-none w-12 flex-shrink-0 border-r border-border/50","aria-hidden":"true",style:{pointerEvents:"none"},children:Q.newLineNum||""}),t.jsx("div",{className:`px-3 py-0.5 flex-1 min-w-0 whitespace-pre-wrap break-all ${r}`,children:E})]},a)})})})}function ql(e){return new Date(e).toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}const Ol=l.memo(function(){const A=DA(n=>n.isDiffOpen),g=DA(n=>n.selectedFile),s=DA(n=>n.allOperations),o=DA(n=>n.selectedOperationIndex),Q=DA(n=>n.selectOperation),B=DA(n=>n.closeDiff),a=ze(n=>n.setCollapsed),r=l.useRef(null),i=l.useRef(!1),E=s[o],I=l.useMemo(()=>{if(!E||!g)return null;let n=null;if(E.artifact?.patch)n=E.artifact.patch;else if(E.patch)n=E.patch;else if(E.content){const d=E.content.split(`
125
125
  `);n=`*** Add File: ${g}
126
126
  ${d.map(u=>`+${u}`).join(`
127
- `)}`}return n?/@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@/.test(n)?n:Rl(n):null},[E,g]);if(l.useEffect(()=>{if(A&&!i.current){const{isCollapsed:n}=ze.getState();r.current=n,a(!0)}else!A&&i.current&&r.current!==null&&(a(r.current),r.current=null);i.current=A},[A,a]),l.useEffect(()=>{const n=C=>{const d=C.target,u=d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.isContentEditable;(C.key==="Escape"||C.key==="q"&&!u)&&A&&B(),!u&&A&&s.length>1&&(C.key==="ArrowLeft"||C.key==="["?(C.preventDefault(),Q(Math.max(0,o-1))):(C.key==="ArrowRight"||C.key==="]")&&(C.preventDefault(),Q(Math.min(s.length-1,o+1))))};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[A,B,s.length,o,Q]),!A||!g||!E)return null;const c=s.length>1;return t.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3 shrink-0",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:B,title:"Close diff viewer (ESC)",children:t.jsx(kA,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:g,children:g}),t.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-primary/10 text-primary flex-shrink-0 capitalize",children:E.operation}),E.artifact?.summary&&t.jsxs("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[t.jsxs("span",{className:"text-green-500",children:["+",E.artifact.summary.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",E.artifact.summary.deletions]})]})]}),c&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>Q(Math.max(0,o-1)),disabled:o===0,title:"Previous operation (←)",children:t.jsx(ha,{className:"w-4 h-4"})}),t.jsxs("span",{className:"text-xs text-muted-foreground min-w-[60px] text-center",children:[o+1," / ",s.length]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>Q(Math.min(s.length-1,o+1)),disabled:o===s.length-1,title:"Next operation (→)",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),c&&t.jsx("div",{className:"border-b border-border px-4 py-2 flex gap-2 overflow-x-auto shrink-0",children:s.map((n,C)=>t.jsxs("button",{type:"button",onClick:()=>Q(C),className:`px-3 py-1.5 text-xs rounded-md flex items-center gap-2 shrink-0 transition-colors ${C===o?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80 text-muted-foreground"}`,children:[t.jsx("span",{className:"capitalize",children:n.operation}),t.jsx("span",{className:"opacity-70",children:ql(n.timestamp)}),n.artifact?.summary&&t.jsxs("span",{className:"opacity-70",children:["+",n.artifact.summary.additions,"/-",n.artifact.summary.deletions]})]},n.toolCallId))}),t.jsx("div",{className:"flex-1 overflow-hidden p-4",children:I?t.jsx(vl,{patch:I}):t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"No diff content available"})})]})}),Tl={};class Yl{get baseUrl(){const A=window;if(A.OTTO_SERVER_URL)return A.OTTO_SERVER_URL;if(!Tl?.VITE_API_BASE_URL)return TA}async listResearchSessions(A){const g=await fetch(`${this.baseUrl}/v1/sessions/${A}/research`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!g.ok){const s=await g.json().catch(()=>({error:"Failed to fetch research sessions"}));throw new Error(s.error||"Failed to fetch research sessions")}return g.json()}async createResearchSession(A,g){const s=await fetch(`${this.baseUrl}/v1/sessions/${A}/research`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!s.ok){const o=await s.json().catch(()=>({error:"Failed to create research session"}));throw new Error(o.error||"Failed to create research session")}return s.json()}async deleteResearchSession(A){const g=await fetch(`${this.baseUrl}/v1/research/${A}`,{method:"DELETE",headers:{"Content-Type":"application/json"}});if(!g.ok){const s=await g.json().catch(()=>({error:"Failed to delete research session"}));throw new Error(s.error||"Failed to delete research session")}return g.json()}async injectContext(A,g,s){const o=await fetch(`${this.baseUrl}/v1/sessions/${A}/inject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({researchSessionId:g,label:s})});if(!o.ok){const Q=await o.json().catch(()=>({error:"Failed to inject context"}));throw new Error(Q.error||"Failed to inject context")}return o.json()}async exportToNewSession(A,g){const s=await fetch(`${this.baseUrl}/v1/research/${A}/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g??{})});if(!s.ok){const o=await s.json().catch(()=>({error:"Failed to export to session"}));throw new Error(o.error||"Failed to export to session")}return s.json()}}const ug=new Yl;function pB(e){return FA({queryKey:["research","sessions",e],queryFn:()=>ug.listResearchSessions(e),enabled:!!e,staleTime:3e4})}function Hl(){const e=sA();return nA({mutationFn:({parentSessionId:A,data:g})=>ug.createResearchSession(A,g??{}),onSuccess:(A,{parentSessionId:g})=>{e.invalidateQueries({queryKey:["research","sessions",g]})}})}function Pl(){const e=Pt(A=>A.addContext);return nA({mutationFn:({parentSessionId:A,researchSessionId:g,label:s})=>ug.injectContext(A,g,s),onSuccess:(A,{parentSessionId:g})=>{e(g,{id:A.sessionId,sessionId:A.sessionId,label:A.label,content:A.content})}})}function Wl(){const e=sA();return nA({mutationFn:({researchId:A,data:g})=>ug.exportToNewSession(A,g),onSuccess:()=>{e.invalidateQueries({queryKey:ke})}})}const bo="research",Uo=384,zl=384,Vl=640,Zl=l.memo(function({parentSessionId:A,onNavigateToSession:g}){const s=SA(q=>q.isExpanded),o=SA(q=>q.collapseSidebar),Q=Ue(q=>q.widths[bo]??Uo),B=SA(q=>q.activeResearchSessionId),a=SA(q=>q.selectResearchSession),[r,i]=l.useState(!1),[E,I]=l.useState(""),[c,n]=l.useState(!1),[C,d]=l.useState("idle"),u=l.useRef(null),D=l.useRef(null),{data:w,isLoading:h,refetch:m}=pB(A),k=Hl(),y=Pl(),G=Wl(),{data:M}=Nt(),{data:x}=eg(B??void 0),{data:F}=eg(A??void 0);uB(B??void 0);const p=eB(B??""),f=sA(),N=nA({mutationFn:async({sessionId:q,content:BA})=>v.sendMessage(q,{content:BA}),onSuccess:(q,{sessionId:BA})=>{f.invalidateQueries({queryKey:["messages",BA]})}});l.useEffect(()=>{A&&SA.getState().setParentSessionId(A)},[A]),l.useEffect(()=>{w?.sessions?.length?w.sessions.some(BA=>BA.id===B)||a(w.sessions[0].id):w?.sessions?.length===0&&a(null)},[w,B,a]),l.useEffect(()=>{D.current?.scrollIntoView({behavior:"smooth"})},[]);const b=l.useCallback(()=>{const q=u.current;q&&(q.style.height="auto",q.style.height=`${Math.min(q.scrollHeight,120)}px`)},[]);l.useEffect(()=>{b()},[b,E]);const S=l.useCallback(async()=>{if(A)try{const q=await k.mutateAsync({parentSessionId:A,data:{}});await m(),a(q.session.id),i(!1)}catch(q){console.error("Failed to create research session:",q)}},[A,k,a,m]),O=l.useCallback(q=>{a(q.id),i(!1)},[a]),L=l.useCallback(async()=>{if(!A||!B)return;if(F?.some(ee=>ee.role==="system"&&ee.parts?.some(JA=>typeof JA.content=="string"&&JA.content.includes(`from="${B}"`)))){d("error"),setTimeout(()=>d("idle"),3e3);return}const NA=`Research ${new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`;try{await y.mutateAsync({parentSessionId:A,researchSessionId:B,label:NA}),d("success"),setTimeout(()=>d("idle"),5e3),f.invalidateQueries({queryKey:["messages",A]})}catch(ee){console.error("Failed to inject context:",ee),d("error"),setTimeout(()=>d("idle"),3e3)}},[A,B,y,F,f]),R=l.useCallback(async()=>{if(B)try{const q=await G.mutateAsync({researchId:B});g&&q.newSession?.id&&g(q.newSession.id)}catch(q){console.error("Failed to export to session:",q)}},[B,G,g]),j=l.useCallback(async()=>{if(!(!E.trim()||!A))try{let q=B;q||(q=(await k.mutateAsync({parentSessionId:A,data:{}})).session.id,a(q)),await N.mutateAsync({sessionId:q,content:E}),I(""),u.current&&(u.current.style.height="auto")}catch(q){console.error("Failed to send message:",q)}},[E,A,B,k,a,N]),J=l.useCallback(q=>{q.key==="Enter"&&!q.shiftKey&&(q.preventDefault(),j())},[j]),H=l.useMemo(()=>x?.some(q=>q.role==="assistant"&&q.status==="pending")??!1,[x]),z=l.useMemo(()=>!B||!F?!1:F.some(q=>q.role==="system"&&q.parts?.some(BA=>typeof BA.content=="string"&&BA.content.includes(`from="${B}"`))),[B,F]),AA=l.useCallback(async(q,BA)=>{if(!B){n(!1);return}try{await p.mutateAsync({provider:q,model:BA}),await f.invalidateQueries({queryKey:["research","sessions",A]}),n(!1)}catch(YA){console.error("Failed to update research session model:",YA)}},[B,p,f,A]),tA=Ns(A??"");if(!s)return null;const lA=w?.sessions??[],yA=lA.find(q=>q.id===B),P=x??[],oA=yA?.provider??tA?.provider??"",T=yA?.model??tA?.model??"",cA=M?.[oA]?.label??oA,bA=M?.[oA]?.models.find(q=>q.id===T)?.label??T;return t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:Q},children:[t.jsx(et,{panelKey:bo,side:"right",minWidth:zl,maxWidth:Vl,defaultWidth:Uo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[t.jsx(It,{className:"w-4 h-4 text-teal-500"}),t.jsx("span",{className:"font-medium text-foreground text-sm",children:"Research"})]}),t.jsxs("div",{className:"flex items-center gap-0.5",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>i(!r),title:"Research history",className:"h-8 w-8",children:t.jsx(Da,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:S,disabled:!A||k.isPending,title:"New research session",className:"h-8 w-8",children:k.isPending?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsx(fe,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:o,title:"Close sidebar",className:"h-8 w-8",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),r?t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[t.jsx("div",{className:"p-2 border-b border-border",children:t.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Research Sessions"})}),h?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading..."}):lA.length===0?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No research sessions yet"}):t.jsx("div",{className:"p-2 space-y-1",children:lA.map(q=>t.jsxs("button",{type:"button",onClick:()=>O(q),className:`w-full text-left p-2 rounded-md text-sm transition-colors ${q.id===B?"bg-teal-500/10 border border-teal-500/30 text-foreground":"hover:bg-muted"}`,children:[t.jsx("div",{className:"font-medium truncate",children:q.title||"Untitled"}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[q.messageCount," messages •"," ",Xl(q.lastActiveAt??q.createdAt)]})]},q.id))})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3 research-messages text-[13px]",children:B?P.length===0?t.jsx("div",{className:"text-xs text-muted-foreground text-center py-8",children:t.jsx("p",{children:"Ask a question to start researching."})}):t.jsxs("div",{className:"space-y-1.5",children:[P.map((q,BA)=>{if(q.role==="user"){const YA=P[BA+1];return t.jsx(nB,{sessionId:B,message:q,isFirst:BA===0,nextAssistantMessageId:YA?.role==="assistant"?YA.id:void 0},q.id)}if(q.role==="assistant"){const YA=BA>0?P[BA-1]:null,NA=P[BA+1],ee=YA?.role!=="assistant",JA=NA?.role==="assistant";return t.jsx(EB,{sessionId:B,message:q,showHeader:ee,hasNextAssistantMessage:JA,isLastMessage:BA===P.length-1,compact:!0,onNavigateToSession:g},q.id)}return null}),t.jsx("div",{ref:D})]}):t.jsxs("div",{className:"text-xs text-muted-foreground text-center py-8",children:[t.jsx(It,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground/50"}),t.jsx("p",{children:"Start researching by asking a question below."})]})}),t.jsxs("div",{className:"p-3 border-t border-border",children:[t.jsx("div",{className:"relative flex flex-col rounded-3xl bg-card border border-border focus-within:border-teal-500/60 focus-within:ring-1 focus-within:ring-teal-500/40 p-1",children:t.jsxs("div",{className:"flex items-end gap-1",children:[t.jsx(ng,{ref:u,value:E,onChange:q=>I(q.target.value),onKeyDown:J,placeholder:"Ask anything...",disabled:!A||N.isPending||k.isPending,rows:1,className:"flex-1 border-0 bg-transparent pl-2 pr-1 py-2 max-h-[120px] overflow-y-auto leading-normal resize-none scrollbar-hide text-sm focus:ring-0 focus:outline-none",style:{height:"2.25rem"}}),t.jsx("button",{type:"button",onClick:j,disabled:!E.trim()||!A||N.isPending||k.isPending||H,className:`flex items-center justify-center w-9 h-9 rounded-full transition-colors flex-shrink-0 ${E.trim()&&A&&!H?"bg-teal-500 hover:bg-teal-600 text-white":"bg-transparent text-muted-foreground"}`,children:N.isPending||k.isPending?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsx(Po,{className:"w-4 h-4"})})]})}),C==="success"&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-teal-500/10 border border-teal-500/30 text-teal-600 dark:text-teal-400",children:[t.jsx(Ae,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"flex-1",children:"Context injected — will be used on next request"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"hover:text-teal-500",children:t.jsx(kA,{className:"w-3 h-3"})})]}),C==="error"&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-red-500/10 border border-red-500/30 text-red-600 dark:text-red-400",children:[t.jsx(kA,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"flex-1",children:"Failed to inject context"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"hover:text-red-500",children:t.jsx(kA,{className:"w-3 h-3"})})]}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsxs("button",{type:"button",onClick:L,disabled:!B||y.isPending||H||z,className:`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z?"bg-teal-500/10 text-teal-600 dark:text-teal-400 border border-teal-500/30":"bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground"}`,title:z?"Already injected into main session":"Inject findings into main session",children:[y.isPending?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):z?t.jsx(Ae,{className:"w-3 h-3"}):t.jsx(pa,{className:"w-3 h-3"}),z?"Injected":"Inject"]}),t.jsxs("button",{type:"button",onClick:R,disabled:!B||G.isPending||H,className:"flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Export to new main session",children:[G.isPending?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):t.jsx(jA,{className:"w-3 h-3"}),"Export"]})]})]})]}),t.jsxs("div",{className:"h-12 px-3 border-t border-border text-xs text-muted-foreground flex items-center justify-between",children:[t.jsxs("span",{className:"text-[10px]",children:[lA.length," research session",lA.length!==1?"s":""]}),(cA||bA)&&t.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex items-center gap-1 text-[10px] hover:text-foreground transition-colors",children:[t.jsx("span",{className:"opacity-60",children:cA}),t.jsx("span",{className:"opacity-40",children:"/"}),t.jsx("span",{children:bA}),t.jsx(PA,{className:"w-3 h-3 opacity-40"})]})]}),t.jsx(Me,{isOpen:c,onClose:()=>n(!1),title:"Select Model for Research",maxWidth:"md",children:(oA||T)&&t.jsx(QB,{provider:oA,model:T,onChange:AA})})]})]})});function Xl(e){const A=Date.now()-e,g=Math.floor(A/6e4);if(g<1)return"just now";if(g<60)return`${g}m ago`;const s=Math.floor(g/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const _l=l.memo(function({parentSessionId:A}){const g=SA(B=>B.isExpanded),s=SA(B=>B.toggleSidebar),{data:o}=pB(A??null),Q=o?.sessions?.length??0;return t.jsxs("button",{type:"button",onClick:s,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${g?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Research (⌘⇧R)",children:[t.jsx(It,{className:"w-5 h-5 text-muted-foreground mx-auto"}),Q>0&&t.jsx("span",{className:"absolute top-1 right-1 w-5 h-5 bg-primary text-primary-foreground text-xs rounded-full flex items-center justify-center font-semibold",children:Q>9?"9+":Q})]})});var $l=Object.defineProperty,gg=Object.getOwnPropertySymbols,wB=Object.prototype.hasOwnProperty,mB=Object.prototype.propertyIsEnumerable,So=(e,A,g)=>A in e?$l(e,A,{enumerable:!0,configurable:!0,writable:!0,value:g}):e[A]=g,gs=(e,A)=>{for(var g in A||(A={}))wB.call(A,g)&&So(e,g,A[g]);if(gg)for(var g of gg(A))mB.call(A,g)&&So(e,g,A[g]);return e},ss=(e,A)=>{var g={};for(var s in e)wB.call(e,s)&&A.indexOf(s)<0&&(g[s]=e[s]);if(e!=null&&gg)for(var s of gg(e))A.indexOf(s)<0&&mB.call(e,s)&&(g[s]=e[s]);return g};var Ve;(e=>{const A=class gA{constructor(r,i,E,I){if(this.version=r,this.errorCorrectionLevel=i,this.modules=[],this.isFunction=[],r<gA.MIN_VERSION||r>gA.MAX_VERSION)throw new RangeError("Version value out of range");if(I<-1||I>7)throw new RangeError("Mask value out of range");this.size=r*4+17;let c=[];for(let C=0;C<this.size;C++)c.push(!1);for(let C=0;C<this.size;C++)this.modules.push(c.slice()),this.isFunction.push(c.slice());this.drawFunctionPatterns();const n=this.addEccAndInterleave(E);if(this.drawCodewords(n),I==-1){let C=1e9;for(let d=0;d<8;d++){this.applyMask(d),this.drawFormatBits(d);const u=this.getPenaltyScore();u<C&&(I=d,C=u),this.applyMask(d)}}o(0<=I&&I<=7),this.mask=I,this.applyMask(I),this.drawFormatBits(I),this.isFunction=[]}static encodeText(r,i){const E=e.QrSegment.makeSegments(r);return gA.encodeSegments(E,i)}static encodeBinary(r,i){const E=e.QrSegment.makeBytes(r);return gA.encodeSegments([E],i)}static encodeSegments(r,i,E=1,I=40,c=-1,n=!0){if(!(gA.MIN_VERSION<=E&&E<=I&&I<=gA.MAX_VERSION)||c<-1||c>7)throw new RangeError("Invalid value");let C,d;for(C=E;;C++){const h=gA.getNumDataCodewords(C,i)*8,m=B.getTotalBits(r,C);if(m<=h){d=m;break}if(C>=I)throw new RangeError("Data too long")}for(const h of[gA.Ecc.MEDIUM,gA.Ecc.QUARTILE,gA.Ecc.HIGH])n&&d<=gA.getNumDataCodewords(C,h)*8&&(i=h);let u=[];for(const h of r){g(h.mode.modeBits,4,u),g(h.numChars,h.mode.numCharCountBits(C),u);for(const m of h.getData())u.push(m)}o(u.length==d);const D=gA.getNumDataCodewords(C,i)*8;o(u.length<=D),g(0,Math.min(4,D-u.length),u),g(0,(8-u.length%8)%8,u),o(u.length%8==0);for(let h=236;u.length<D;h^=253)g(h,8,u);let w=[];for(;w.length*8<u.length;)w.push(0);return u.forEach((h,m)=>w[m>>>3]|=h<<7-(m&7)),new gA(C,i,w,c)}getModule(r,i){return 0<=r&&r<this.size&&0<=i&&i<this.size&&this.modules[i][r]}getModules(){return this.modules}drawFunctionPatterns(){for(let E=0;E<this.size;E++)this.setFunctionModule(6,E,E%2==0),this.setFunctionModule(E,6,E%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const r=this.getAlignmentPatternPositions(),i=r.length;for(let E=0;E<i;E++)for(let I=0;I<i;I++)E==0&&I==0||E==0&&I==i-1||E==i-1&&I==0||this.drawAlignmentPattern(r[E],r[I]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(r){const i=this.errorCorrectionLevel.formatBits<<3|r;let E=i;for(let c=0;c<10;c++)E=E<<1^(E>>>9)*1335;const I=(i<<10|E)^21522;o(I>>>15==0);for(let c=0;c<=5;c++)this.setFunctionModule(8,c,s(I,c));this.setFunctionModule(8,7,s(I,6)),this.setFunctionModule(8,8,s(I,7)),this.setFunctionModule(7,8,s(I,8));for(let c=9;c<15;c++)this.setFunctionModule(14-c,8,s(I,c));for(let c=0;c<8;c++)this.setFunctionModule(this.size-1-c,8,s(I,c));for(let c=8;c<15;c++)this.setFunctionModule(8,this.size-15+c,s(I,c));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let r=this.version;for(let E=0;E<12;E++)r=r<<1^(r>>>11)*7973;const i=this.version<<12|r;o(i>>>18==0);for(let E=0;E<18;E++){const I=s(i,E),c=this.size-11+E%3,n=Math.floor(E/3);this.setFunctionModule(c,n,I),this.setFunctionModule(n,c,I)}}drawFinderPattern(r,i){for(let E=-4;E<=4;E++)for(let I=-4;I<=4;I++){const c=Math.max(Math.abs(I),Math.abs(E)),n=r+I,C=i+E;0<=n&&n<this.size&&0<=C&&C<this.size&&this.setFunctionModule(n,C,c!=2&&c!=4)}}drawAlignmentPattern(r,i){for(let E=-2;E<=2;E++)for(let I=-2;I<=2;I++)this.setFunctionModule(r+I,i+E,Math.max(Math.abs(I),Math.abs(E))!=1)}setFunctionModule(r,i,E){this.modules[i][r]=E,this.isFunction[i][r]=!0}addEccAndInterleave(r){const i=this.version,E=this.errorCorrectionLevel;if(r.length!=gA.getNumDataCodewords(i,E))throw new RangeError("Invalid argument");const I=gA.NUM_ERROR_CORRECTION_BLOCKS[E.ordinal][i],c=gA.ECC_CODEWORDS_PER_BLOCK[E.ordinal][i],n=Math.floor(gA.getNumRawDataModules(i)/8),C=I-n%I,d=Math.floor(n/I);let u=[];const D=gA.reedSolomonComputeDivisor(c);for(let h=0,m=0;h<I;h++){let k=r.slice(m,m+d-c+(h<C?0:1));m+=k.length;const y=gA.reedSolomonComputeRemainder(k,D);h<C&&k.push(0),u.push(k.concat(y))}let w=[];for(let h=0;h<u[0].length;h++)u.forEach((m,k)=>{(h!=d-c||k>=C)&&w.push(m[h])});return o(w.length==n),w}drawCodewords(r){if(r.length!=Math.floor(gA.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let i=0;for(let E=this.size-1;E>=1;E-=2){E==6&&(E=5);for(let I=0;I<this.size;I++)for(let c=0;c<2;c++){const n=E-c,d=(E+1&2)==0?this.size-1-I:I;!this.isFunction[d][n]&&i<r.length*8&&(this.modules[d][n]=s(r[i>>>3],7-(i&7)),i++)}}o(i==r.length*8)}applyMask(r){if(r<0||r>7)throw new RangeError("Mask value out of range");for(let i=0;i<this.size;i++)for(let E=0;E<this.size;E++){let I;switch(r){case 0:I=(E+i)%2==0;break;case 1:I=i%2==0;break;case 2:I=E%3==0;break;case 3:I=(E+i)%3==0;break;case 4:I=(Math.floor(E/3)+Math.floor(i/2))%2==0;break;case 5:I=E*i%2+E*i%3==0;break;case 6:I=(E*i%2+E*i%3)%2==0;break;case 7:I=((E+i)%2+E*i%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[i][E]&&I&&(this.modules[i][E]=!this.modules[i][E])}}getPenaltyScore(){let r=0;for(let c=0;c<this.size;c++){let n=!1,C=0,d=[0,0,0,0,0,0,0];for(let u=0;u<this.size;u++)this.modules[c][u]==n?(C++,C==5?r+=gA.PENALTY_N1:C>5&&r++):(this.finderPenaltyAddHistory(C,d),n||(r+=this.finderPenaltyCountPatterns(d)*gA.PENALTY_N3),n=this.modules[c][u],C=1);r+=this.finderPenaltyTerminateAndCount(n,C,d)*gA.PENALTY_N3}for(let c=0;c<this.size;c++){let n=!1,C=0,d=[0,0,0,0,0,0,0];for(let u=0;u<this.size;u++)this.modules[u][c]==n?(C++,C==5?r+=gA.PENALTY_N1:C>5&&r++):(this.finderPenaltyAddHistory(C,d),n||(r+=this.finderPenaltyCountPatterns(d)*gA.PENALTY_N3),n=this.modules[u][c],C=1);r+=this.finderPenaltyTerminateAndCount(n,C,d)*gA.PENALTY_N3}for(let c=0;c<this.size-1;c++)for(let n=0;n<this.size-1;n++){const C=this.modules[c][n];C==this.modules[c][n+1]&&C==this.modules[c+1][n]&&C==this.modules[c+1][n+1]&&(r+=gA.PENALTY_N2)}let i=0;for(const c of this.modules)i=c.reduce((n,C)=>n+(C?1:0),i);const E=this.size*this.size,I=Math.ceil(Math.abs(i*20-E*10)/E)-1;return o(0<=I&&I<=9),r+=I*gA.PENALTY_N4,o(0<=r&&r<=2568888),r}getAlignmentPatternPositions(){if(this.version==1)return[];{const r=Math.floor(this.version/7)+2,i=this.version==32?26:Math.ceil((this.version*4+4)/(r*2-2))*2;let E=[6];for(let I=this.size-7;E.length<r;I-=i)E.splice(1,0,I);return E}}static getNumRawDataModules(r){if(r<gA.MIN_VERSION||r>gA.MAX_VERSION)throw new RangeError("Version number out of range");let i=(16*r+128)*r+64;if(r>=2){const E=Math.floor(r/7)+2;i-=(25*E-10)*E-55,r>=7&&(i-=36)}return o(208<=i&&i<=29648),i}static getNumDataCodewords(r,i){return Math.floor(gA.getNumRawDataModules(r)/8)-gA.ECC_CODEWORDS_PER_BLOCK[i.ordinal][r]*gA.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][r]}static reedSolomonComputeDivisor(r){if(r<1||r>255)throw new RangeError("Degree out of range");let i=[];for(let I=0;I<r-1;I++)i.push(0);i.push(1);let E=1;for(let I=0;I<r;I++){for(let c=0;c<i.length;c++)i[c]=gA.reedSolomonMultiply(i[c],E),c+1<i.length&&(i[c]^=i[c+1]);E=gA.reedSolomonMultiply(E,2)}return i}static reedSolomonComputeRemainder(r,i){let E=i.map(I=>0);for(const I of r){const c=I^E.shift();E.push(0),i.forEach((n,C)=>E[C]^=gA.reedSolomonMultiply(n,c))}return E}static reedSolomonMultiply(r,i){if(r>>>8||i>>>8)throw new RangeError("Byte out of range");let E=0;for(let I=7;I>=0;I--)E=E<<1^(E>>>7)*285,E^=(i>>>I&1)*r;return o(E>>>8==0),E}finderPenaltyCountPatterns(r){const i=r[1];o(i<=this.size*3);const E=i>0&&r[2]==i&&r[3]==i*3&&r[4]==i&&r[5]==i;return(E&&r[0]>=i*4&&r[6]>=i?1:0)+(E&&r[6]>=i*4&&r[0]>=i?1:0)}finderPenaltyTerminateAndCount(r,i,E){return r&&(this.finderPenaltyAddHistory(i,E),i=0),i+=this.size,this.finderPenaltyAddHistory(i,E),this.finderPenaltyCountPatterns(E)}finderPenaltyAddHistory(r,i){i[0]==0&&(r+=this.size),i.pop(),i.unshift(r)}};A.MIN_VERSION=1,A.MAX_VERSION=40,A.PENALTY_N1=3,A.PENALTY_N2=3,A.PENALTY_N3=40,A.PENALTY_N4=10,A.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],A.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=A;function g(a,r,i){if(r<0||r>31||a>>>r)throw new RangeError("Value out of range");for(let E=r-1;E>=0;E--)i.push(a>>>E&1)}function s(a,r){return(a>>>r&1)!=0}function o(a){if(!a)throw new Error("Assertion error")}const Q=class wA{constructor(r,i,E){if(this.mode=r,this.numChars=i,this.bitData=E,i<0)throw new RangeError("Invalid argument");this.bitData=E.slice()}static makeBytes(r){let i=[];for(const E of r)g(E,8,i);return new wA(wA.Mode.BYTE,r.length,i)}static makeNumeric(r){if(!wA.isNumeric(r))throw new RangeError("String contains non-numeric characters");let i=[];for(let E=0;E<r.length;){const I=Math.min(r.length-E,3);g(parseInt(r.substring(E,E+I),10),I*3+1,i),E+=I}return new wA(wA.Mode.NUMERIC,r.length,i)}static makeAlphanumeric(r){if(!wA.isAlphanumeric(r))throw new RangeError("String contains unencodable characters in alphanumeric mode");let i=[],E;for(E=0;E+2<=r.length;E+=2){let I=wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E))*45;I+=wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E+1)),g(I,11,i)}return E<r.length&&g(wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E)),6,i),new wA(wA.Mode.ALPHANUMERIC,r.length,i)}static makeSegments(r){return r==""?[]:wA.isNumeric(r)?[wA.makeNumeric(r)]:wA.isAlphanumeric(r)?[wA.makeAlphanumeric(r)]:[wA.makeBytes(wA.toUtf8ByteArray(r))]}static makeEci(r){let i=[];if(r<0)throw new RangeError("ECI assignment value out of range");if(r<128)g(r,8,i);else if(r<16384)g(2,2,i),g(r,14,i);else if(r<1e6)g(6,3,i),g(r,21,i);else throw new RangeError("ECI assignment value out of range");return new wA(wA.Mode.ECI,0,i)}static isNumeric(r){return wA.NUMERIC_REGEX.test(r)}static isAlphanumeric(r){return wA.ALPHANUMERIC_REGEX.test(r)}getData(){return this.bitData.slice()}static getTotalBits(r,i){let E=0;for(const I of r){const c=I.mode.numCharCountBits(i);if(I.numChars>=1<<c)return 1/0;E+=4+c+I.bitData.length}return E}static toUtf8ByteArray(r){r=encodeURI(r);let i=[];for(let E=0;E<r.length;E++)r.charAt(E)!="%"?i.push(r.charCodeAt(E)):(i.push(parseInt(r.substring(E+1,E+3),16)),E+=2);return i}};Q.NUMERIC_REGEX=/^[0-9]*$/,Q.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,Q.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let B=Q;e.QrSegment=Q})(Ve||(Ve={}));(e=>{(A=>{const g=class{constructor(o,Q){this.ordinal=o,this.formatBits=Q}};g.LOW=new g(0,1),g.MEDIUM=new g(1,0),g.QUARTILE=new g(2,3),g.HIGH=new g(3,2),A.Ecc=g})(e.QrCode||(e.QrCode={}))})(Ve||(Ve={}));(e=>{(A=>{const g=class{constructor(o,Q){this.modeBits=o,this.numBitsCharCount=Q}numCharCountBits(o){return this.numBitsCharCount[Math.floor((o+7)/17)]}};g.NUMERIC=new g(1,[10,12,14]),g.ALPHANUMERIC=new g(2,[9,11,13]),g.BYTE=new g(4,[8,16,16]),g.KANJI=new g(8,[8,10,12]),g.ECI=new g(7,[0,0,0]),A.Mode=g})(e.QrSegment||(e.QrSegment={}))})(Ve||(Ve={}));var Xe=Ve;var Ac={L:Xe.QrCode.Ecc.LOW,M:Xe.QrCode.Ecc.MEDIUM,Q:Xe.QrCode.Ecc.QUARTILE,H:Xe.QrCode.Ecc.HIGH},xB=128,fB="L",NB="#FFFFFF",kB="#000000",MB=!1,yB=1,ec=4,tc=0,gc=.1;function GB(e,A=0){const g=[];return e.forEach(function(s,o){let Q=null;s.forEach(function(B,a){if(!B&&Q!==null){g.push(`M${Q+A} ${o+A}h${a-Q}v1H${Q+A}z`),Q=null;return}if(a===s.length-1){if(!B)return;Q===null?g.push(`M${a+A},${o+A} h1v1H${a+A}z`):g.push(`M${Q+A},${o+A} h${a+1-Q}v1H${Q+A}z`);return}B&&Q===null&&(Q=a)})}),g.join("")}function FB(e,A){return e.slice().map((g,s)=>s<A.y||s>=A.y+A.h?g:g.map((o,Q)=>Q<A.x||Q>=A.x+A.w?o:!1))}function sc(e,A,g,s){if(s==null)return null;const o=e.length+g*2,Q=Math.floor(A*gc),B=o/A,a=(s.width||Q)*B,r=(s.height||Q)*B,i=s.x==null?e.length/2-a/2:s.x*B,E=s.y==null?e.length/2-r/2:s.y*B,I=s.opacity==null?1:s.opacity;let c=null;if(s.excavate){let C=Math.floor(i),d=Math.floor(E),u=Math.ceil(a+i-C),D=Math.ceil(r+E-d);c={x:C,y:d,w:u,h:D}}const n=s.crossOrigin;return{x:i,y:E,h:r,w:a,excavation:c,opacity:I,crossOrigin:n}}function oc(e,A){return A!=null?Math.max(Math.floor(A),0):e?ec:tc}function bB({value:e,level:A,minVersion:g,includeMargin:s,marginSize:o,imageSettings:Q,size:B,boostLevel:a}){let r=hA.useMemo(()=>{const C=(Array.isArray(e)?e:[e]).reduce((d,u)=>(d.push(...Xe.QrSegment.makeSegments(u)),d),[]);return Xe.QrCode.encodeSegments(C,Ac[A],g,void 0,void 0,a)},[e,A,g,a]);const{cells:i,margin:E,numCells:I,calculatedImageSettings:c}=hA.useMemo(()=>{let n=r.getModules();const C=oc(s,o),d=n.length+C*2,u=sc(n,B,C,Q);return{cells:n,margin:C,numCells:d,calculatedImageSettings:u}},[r,B,Q,s,o]);return{qrcode:r,margin:E,cells:i,numCells:I,calculatedImageSettings:c}}var Qc=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),Bc=hA.forwardRef(function(A,g){const s=A,{value:o,size:Q=xB,level:B=fB,bgColor:a=NB,fgColor:r=kB,includeMargin:i=MB,minVersion:E=yB,boostLevel:I,marginSize:c,imageSettings:n}=s,d=ss(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:u}=d,D=ss(d,["style"]),w=n?.src,h=hA.useRef(null),m=hA.useRef(null),k=hA.useCallback(b=>{h.current=b,typeof g=="function"?g(b):g&&(g.current=b)},[g]),[y,G]=hA.useState(!1),{margin:M,cells:x,numCells:F,calculatedImageSettings:p}=bB({value:o,level:B,minVersion:E,boostLevel:I,includeMargin:i,marginSize:c,imageSettings:n,size:Q});hA.useEffect(()=>{if(h.current!=null){const b=h.current,S=b.getContext("2d");if(!S)return;let O=x;const L=m.current,R=p!=null&&L!==null&&L.complete&&L.naturalHeight!==0&&L.naturalWidth!==0;R&&p.excavation!=null&&(O=FB(x,p.excavation));const j=window.devicePixelRatio||1;b.height=b.width=Q*j;const J=Q/F*j;S.scale(J,J),S.fillStyle=a,S.fillRect(0,0,F,F),S.fillStyle=r,Qc?S.fill(new Path2D(GB(O,M))):x.forEach(function(H,z){H.forEach(function(AA,tA){AA&&S.fillRect(tA+M,z+M,1,1)})}),p&&(S.globalAlpha=p.opacity),R&&S.drawImage(L,p.x+M,p.y+M,p.w,p.h)}}),hA.useEffect(()=>{G(!1)},[w]);const f=gs({height:Q,width:Q},u);let N=null;return w!=null&&(N=hA.createElement("img",{src:w,key:w,style:{display:"none"},onLoad:()=>{G(!0)},ref:m,crossOrigin:p?.crossOrigin})),hA.createElement(hA.Fragment,null,hA.createElement("canvas",gs({style:f,height:Q,width:Q,ref:k,role:"img"},D)),N)});Bc.displayName="QRCodeCanvas";var hg=hA.forwardRef(function(A,g){const s=A,{value:o,size:Q=xB,level:B=fB,bgColor:a=NB,fgColor:r=kB,includeMargin:i=MB,minVersion:E=yB,boostLevel:I,title:c,marginSize:n,imageSettings:C}=s,d=ss(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:u,cells:D,numCells:w,calculatedImageSettings:h}=bB({value:o,level:B,minVersion:E,boostLevel:I,includeMargin:i,marginSize:n,imageSettings:C,size:Q});let m=D,k=null;C!=null&&h!=null&&(h.excavation!=null&&(m=FB(D,h.excavation)),k=hA.createElement("image",{href:C.src,height:h.h,width:h.w,x:h.x+u,y:h.y+u,preserveAspectRatio:"none",opacity:h.opacity,crossOrigin:h.crossOrigin}));const y=GB(m,u);return hA.createElement("svg",gs({height:Q,width:Q,viewBox:`0 0 ${w} ${w}`,ref:g,role:"img"},d),!!c&&hA.createElement("title",null,c),hA.createElement("path",{fill:a,d:`M0,0 h${w}v${w}H0z`,shapeRendering:"crispEdges"}),hA.createElement("path",{fill:r,d:y,shapeRendering:"crispEdges"}),k)});hg.displayName="QRCodeSVG";const Et=["wallet","defaults"],LA=MA((e,A)=>({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null,authStatus:null,setOpen:g=>e({isOpen:g}),setStep:g=>e({currentStep:g}),setManageMode:g=>e({manageMode:g}),setLoading:g=>e({isLoading:g}),setError:g=>e({error:g}),setAuthStatus:g=>e({authStatus:g}),nextStep:()=>{const{currentStep:g}=A(),s=Et.indexOf(g);s<Et.length-1&&e({currentStep:Et[s+1]})},prevStep:()=>{const{currentStep:g}=A(),s=Et.indexOf(g);s>0&&e({currentStep:Et[s-1]})},reset:()=>e({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null})})),Kg=typeof window<"u"&&window.self!==window.top;function bs(){const e=LA(x=>x.setAuthStatus),A=LA(x=>x.setOpen),g=LA(x=>x.setLoading),s=LA(x=>x.setError),o=LA(x=>x.authStatus),Q=LA(x=>x.isOpen),B=sA(),[a,r]=l.useState(!1),[i,E]=l.useState(!1),I=l.useRef(),c=l.useRef(new Set),n=l.useCallback(async()=>{g(!0),s(null);try{const x=await v.getAuthStatus();return e(x),B.invalidateQueries({queryKey:["config"]}),B.invalidateQueries({queryKey:["models"]}),x}catch(x){const F=x instanceof Error?x.message:"Failed to load";return s(F),null}finally{g(!1)}},[e,g,s,B]),C=l.useCallback(async()=>{const x=await n();if(x){const F=Object.values(x.providers).some(f=>f.configured);(!x.onboardingComplete||!F||!x.setu.configured)&&A(!0)}r(!0)},[n,A]),d=l.useCallback(async()=>{g(!0),s(null);try{const x=await v.setupSetuWallet();return await n(),x}catch(x){const F=x instanceof Error?x.message:"Setup failed";throw s(F),x}finally{g(!1)}},[n,g,s]),u=l.useCallback(async x=>{g(!0),s(null);try{const F=await v.importSetuWallet(x);return await n(),F}catch(F){const p=F instanceof Error?F.message:"Import failed";throw s(p),F}finally{g(!1)}},[n,g,s]),D=l.useCallback(async(x,F)=>{g(!0),s(null);try{const p=await v.addProvider(x,F);return await n(),p}catch(p){const f=p instanceof Error?p.message:"Failed to add provider";throw s(f),p}finally{g(!1)}},[n,g,s]),w=l.useCallback(async x=>{g(!0),s(null);try{const F=await v.removeProvider(x);return await n(),F}catch(F){const p=F instanceof Error?F.message:"Failed to remove provider";throw s(p),F}finally{g(!1)}},[n,g,s]),h=l.useCallback(async()=>{g(!0),s(null);try{await v.completeOnboarding(),await n(),A(!1)}catch(x){const F=x instanceof Error?x.message:"Failed to complete onboarding";throw s(F),x}finally{g(!1)}},[n,g,s,A]),m=l.useCallback(()=>{const x=LA.getState().authStatus;x&&(c.current=new Set(Object.entries(x.providers).filter(([,F])=>F.configured).map(([F])=>F)))},[]),k=l.useCallback((x,F)=>{const p=v.getOAuthStartUrl(x,F);if(Kg)return m(),window.parent.postMessage({type:"otto-open-url",url:p},"*"),E(!0),null;const f=600,N=700,b=window.screenX+(window.outerWidth-f)/2,S=window.screenY+(window.outerHeight-N)/2;return window.open(p,"oauth_popup",`width=${f},height=${N},left=${b},top=${S},toolbar=no,menubar=no`)},[m]),y=l.useCallback(async(x,F)=>{const{url:p,sessionId:f}=await v.getOAuthUrl(x,F);if(Kg)return m(),window.parent.postMessage({type:"otto-open-url",url:p},"*"),E(!0),{popup:null,sessionId:f};const N=600,b=700,S=window.screenX+(window.outerWidth-N)/2,O=window.screenY+(window.outerHeight-b)/2;return{popup:window.open(p,"oauth_popup",`width=${N},height=${b},left=${S},top=${O},toolbar=no,menubar=no`),sessionId:f}},[m]),G=l.useCallback(async(x,F,p)=>{g(!0),s(null);try{return await v.exchangeOAuthCode(x,F,p),await n(),!0}catch(f){const N=f instanceof Error?f.message:"Failed to exchange code";throw s(N),f}finally{g(!1)}},[n,g,s]);l.useEffect(()=>{if(!i||!Kg)return;I.current=setInterval(()=>{n()},3e3);const x=setTimeout(()=>{E(!1)},3e5);return()=>{clearInterval(I.current),clearTimeout(x)}},[i,n]),l.useEffect(()=>{if(!i||!o)return;Object.entries(o.providers).filter(([,p])=>p.configured).some(([p])=>!c.current.has(p))&&E(!1)},[o,i]),l.useEffect(()=>{const x=F=>{F.data?.type==="oauth-success"&&n()};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[n]);const M=l.useCallback(async x=>{const F=await v.pollCopilotDeviceFlow(x);return F.status==="complete"&&await n(),F},[n]);return{authStatus:o,isOpen:Q,initialized:a,fetchAuthStatus:n,checkOnboarding:C,setupWallet:d,importWallet:u,addProvider:D,removeProvider:w,completeOnboarding:h,startOAuth:k,startOAuthManual:y,exchangeOAuthCode:G,startCopilotDeviceFlow:v.startCopilotDeviceFlow.bind(v),pollCopilotDeviceFlow:M}}const Rt="pendingPolarCheckout";function ac(){const e=l.useRef(!1),A=l.useRef(null),g=IA(o=>o.setBalance),s=Ie(o=>o.removeToast);l.useEffect(()=>{if(e.current)return;const Q=new URLSearchParams(window.location.search).get("topup"),B=localStorage.getItem(Rt);if(Q==="pending"||B){e.current=!0;const a=new URL(window.location.href);if(a.searchParams.delete("topup"),window.history.replaceState({},"",a.toString()),!B){QA.info("Checking payment status...");return}A.current=QA.loading("Verifying payment...");let r=0;const i=10,E=2e3,I=()=>{A.current&&(s(A.current),A.current=null)},c=async()=>{r++;try{const n=await v.getPolarTopupStatus(B);if(n?.confirmed){localStorage.removeItem(Rt),I();const C=await v.getSetuBalance();C?.balance!==void 0&&g(C.balance),QA.success(`Payment confirmed! +$${n.amountUsd?.toFixed(2)} credited`);return}r<i?setTimeout(c,E):(localStorage.removeItem(Rt),I(),QA.info("Payment processing. Balance will update automatically."))}catch{r<i?setTimeout(c,E):(localStorage.removeItem(Rt),I(),QA.error("Could not verify payment. Please check your balance."))}};setTimeout(c,1500)}},[g,s])}const Ko="settings",Jo=320,ic=320,rc=500,zt=l.memo(function({title:A,icon:g,children:s,action:o}){return t.jsxs("div",{className:"border-b border-border",children:[t.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 bg-muted/30",children:[g,t.jsx("span",{className:"text-sm font-medium flex-1",children:A}),o]}),t.jsx("div",{className:"px-4 py-3 space-y-3",children:s})]})}),Ro=l.memo(function({label:A,value:g}){return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsx("span",{className:"font-mono text-foreground",children:g})]})}),Jg=l.memo(function({label:A,checked:g,onChange:s}){return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsx("button",{type:"button",role:"switch","aria-checked":g,onClick:()=>s(!g),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${g?"bg-primary":"bg-muted"}`,children:t.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${g?"translate-x-6":"translate-x-1"} ${g?"bg-primary-foreground":"bg-foreground"}`})})]})}),Lt=l.memo(function({label:A,value:g,options:s,onChange:o,disabled:Q}){const[B,a]=l.useState(!1),r=s.find(i=>i.id===g);return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsxs("div",{className:"relative",children:[t.jsxs("button",{type:"button",onClick:()=>!Q&&a(!B),disabled:Q,className:"flex items-center gap-1 px-2 py-1 text-xs font-mono bg-muted hover:bg-muted/80 rounded border border-border disabled:opacity-50",children:[t.jsx("span",{className:"max-w-[120px] truncate",children:r?.label||g||"Select..."}),t.jsx(PA,{className:"w-3 h-3"})]}),B&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>a(!1),role:"presentation"}),t.jsx("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[160px] max-h-[200px] overflow-y-auto bg-popover border border-border rounded-md shadow-lg",children:s.map(i=>t.jsx("button",{type:"button",onClick:()=>{o(i.id),a(!1)},className:`w-full px-3 py-2 text-left text-xs font-mono hover:bg-muted truncate ${i.id===g?"bg-muted/50":""}`,children:i.label},i.id))})]})]})]})}),Ec=l.memo(function(){const A=zA(p=>p.isExpanded),g=zA(p=>p.collapseSidebar),s=Ue(p=>p.widths[Ko]??Jo),{data:o}=Ig(),{data:Q}=Nt(),{preferences:B,updatePreferences:a}=ft(),r=rC(),i=IA(p=>p.balance),E=IA(p=>p.walletAddress),I=IA(p=>p.usdcBalance),c=IA(p=>p.isLoading),n=IA(p=>p.openTopupModal);ac();const C=o?.providers?.includes("setu"),{fetchBalance:d}=dg(C?"setu":void 0),u=LA(p=>p.setOpen),D=LA(p=>p.setStep),w=LA(p=>p.setManageMode),{fetchAuthStatus:h}=bs(),m=l.useCallback(async()=>await v.exportSetuWallet(),[]),k=l.useMemo(()=>!o?.providers||!Q?[]:o.providers.filter(p=>Q[p]).map(p=>({id:p,label:Q[p]?.label||p})),[o?.providers,Q]),y=l.useMemo(()=>{const p=o?.defaults?.provider;return!p||!Q?.[p]?[]:Q[p].models.map(f=>({id:f.id,label:f.label}))},[o?.defaults?.provider,Q]),G=l.useMemo(()=>o?.agents?o.agents.map(p=>({id:p,label:p})):[],[o?.agents]);if(!A)return null;const M=p=>{const f=Q?.[p]?.models?.[0]?.id;r.mutate({provider:p,model:f||o?.defaults?.model,scope:"global"})},x=p=>{r.mutate({model:p,scope:"global"})},F=p=>{r.mutate({agent:p,scope:"global"})};return t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:s},children:[t.jsx(et,{panelKey:Ko,side:"right",minWidth:ic,maxWidth:rc,defaultWidth:Jo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(gQ,{className:"w-4 h-4"}),t.jsx("span",{className:"font-medium",children:"Settings"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[t.jsxs(zt,{title:"Default Model",icon:t.jsx(wa,{className:"w-4 h-4 text-muted-foreground"}),children:[t.jsx(Lt,{label:"Provider",value:o?.defaults?.provider??"",options:k,onChange:M,disabled:r.isPending}),t.jsx(Lt,{label:"Model",value:o?.defaults?.model??"",options:y,onChange:x,disabled:r.isPending}),t.jsx(Lt,{label:"Agent",value:o?.defaults?.agent??"",options:G,onChange:F,disabled:r.isPending})]}),t.jsxs(zt,{title:"Preferences",icon:t.jsx(Qs,{className:"w-4 h-4 text-muted-foreground"}),children:[t.jsx(Jg,{label:"Vim Mode",checked:B.vimMode,onChange:p=>a({vimMode:p})}),t.jsx(Jg,{label:"Show Reasoning",checked:B.reasoningEnabled,onChange:p=>a({reasoningEnabled:p})}),t.jsx(Lt,{label:"Tool Approval",value:o?.defaults?.toolApproval??"auto",options:[{id:"auto",label:"Auto (no approval)"},{id:"dangerous",label:"Dangerous only"},{id:"all",label:"All tools"}],onChange:p=>r.mutate({toolApproval:p,scope:"global"}),disabled:r.isPending}),t.jsx(Jg,{label:"Guided Mode",checked:o?.defaults?.guidedMode??!1,onChange:p=>r.mutate({guidedMode:p,scope:"global"})})]}),t.jsx(zt,{title:"Providers",icon:t.jsx(ma,{className:"w-4 h-4 text-muted-foreground"}),action:t.jsx("button",{type:"button",onClick:()=>{h().then(()=>{D("wallet"),w(!0),u(!0)})},className:"p-1 hover:bg-muted rounded transition-colors",title:"Manage providers",children:t.jsx(Rg,{className:"w-3.5 h-3.5 text-muted-foreground"})}),children:t.jsx("div",{className:"flex flex-wrap gap-2",children:o?.providers?.map(p=>t.jsx("span",{className:"px-2 py-1 text-xs bg-muted rounded-md font-mono",children:p},p))??t.jsx("span",{className:"text-muted-foreground text-sm",children:"None"})})}),o?.providers?.includes("setu")&&t.jsx(nc,{setuWallet:E,setuBalance:i,setuUsdcBalance:I,setuLoading:c,refreshSetuBalance:d,openTopupModal:n,onExportPrivateKey:m}),t.jsx(Gs,{})]})]})]})}),nc=l.memo(function({setuWallet:A,setuBalance:g,setuUsdcBalance:s,setuLoading:o,refreshSetuBalance:Q,openTopupModal:B,onExportPrivateKey:a}){const[r,i]=l.useState(!1),[E,I]=l.useState(!1),[c,n]=l.useState(null),[C,d]=l.useState(!1),[u,D]=l.useState(null),[w,h]=l.useState(!1),m=l.useCallback(async()=>{A&&(await navigator.clipboard.writeText(A),i(!0),setTimeout(()=>i(!1),2e3))},[A]),k=async()=>{I(!0),h(!1),n(null),D(null),d(!0);try{const f=await a();n(f.privateKey)}catch(f){D(f instanceof Error?f.message:"Failed to export private key")}finally{d(!1)}},y=()=>{C||(I(!1),h(!1),n(null),D(null))},G=async()=>{c&&(await navigator.clipboard.writeText(c),h(!0),setTimeout(()=>h(!1),2e3))},M=f=>f?`${f.slice(0,4)}...${f.slice(-4)}`:"Not configured",x=f=>f===null?"—":`$${f.toFixed(4)}`,F=f=>f===null?"—":`${f.toFixed(2)} USDC`,p=A!==null;return t.jsxs(zt,{title:"Setu Credits",icon:t.jsx(Is,{className:"w-4 h-4 text-muted-foreground"}),action:t.jsx("button",{type:"button",onClick:Q,disabled:o,className:"p-1 hover:bg-muted rounded transition-colors disabled:opacity-50",title:"Refresh balances",children:t.jsx(HA,{className:`w-3.5 h-3.5 text-muted-foreground ${o?"animate-spin":""}`})}),children:[p?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center pb-3",children:t.jsx("div",{className:"p-2 bg-white rounded-lg",children:t.jsx(hg,{value:A,size:120,level:"M",includeMargin:!1})})}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Address"}),t.jsxs("button",{type:"button",onClick:m,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy address",children:[M(A),r?t.jsx(Ae,{className:"w-3 h-3 text-green-500"}):t.jsx(Ye,{className:"w-3 h-3 text-muted-foreground"})]})]}),t.jsx(Ro,{label:"Balance",value:x(g)}),t.jsx(Ro,{label:"USDC",value:F(s)})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center pb-3",children:t.jsx("div",{className:"w-[136px] h-[136px] bg-muted rounded-lg animate-pulse"})}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Address"}),t.jsx("div",{className:"w-24 h-4 bg-muted rounded animate-pulse"})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Balance"}),t.jsx("div",{className:"w-16 h-4 bg-muted rounded animate-pulse"})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"USDC"}),t.jsx("div",{className:"w-20 h-4 bg-muted rounded animate-pulse"})]})]}),t.jsxs(_,{variant:"secondary",size:"sm",onClick:B,className:"w-full mt-2 gap-2",children:[t.jsx(fe,{className:"w-4 h-4"}),"Top Up Balance"]}),t.jsxs(_,{variant:"ghost",size:"sm",onClick:k,className:"w-full gap-2",children:[t.jsx(Zt,{className:"w-4 h-4"}),"Export Private Key"]}),E&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(Zt,{className:"w-5 h-5 text-muted-foreground"}),t.jsx("h3",{className:"text-lg font-semibold",children:"Export Setu Private Key"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Keep this private key secret. Anyone with this key can spend funds from your Setu wallet."}),C&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Exporting private key..."]}),!C&&c&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("textarea",{readOnly:!0,value:c,className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground outline-none font-mono text-xs resize-y"}),t.jsxs(_,{variant:"secondary",size:"sm",onClick:G,className:"w-full gap-2",children:[w?t.jsx(Ae,{className:"w-4 h-4 text-green-500"}):t.jsx(Ye,{className:"w-4 h-4"}),w?"Copied":"Copy Private Key"]})]}),!C&&u&&t.jsx("p",{className:"text-sm text-red-500 mt-3",children:u}),t.jsx("div",{className:"flex gap-3 mt-5",children:t.jsx("button",{type:"button",onClick:y,disabled:C,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Close"})})]})]})})]})}),Cc=l.memo(function(){const A=zA(s=>s.isExpanded),g=zA(s=>s.toggleSidebar);return t.jsx("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Settings",children:t.jsx(gQ,{className:"w-5 h-5 text-muted-foreground mx-auto"})})});async function Ic(){const e=await fetch(`${TA}/v1/tunnel/status`);if(!e.ok)throw new Error("Failed to fetch tunnel status");return e.json()}async function lc(){return(await fetch(`${TA}/v1/tunnel/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})})).json()}async function cc(){return(await fetch(`${TA}/v1/tunnel/stop`,{method:"POST"})).json()}function dc(){const e=iA(o=>o.setStatus),A=iA(o=>o.setUrl),g=iA(o=>o.setError),s=FA({queryKey:["tunnel","status"],queryFn:Ic,refetchInterval:3e3});return l.useEffect(()=>{s.data&&(e(s.data.status),A(s.data.url),g(s.data.error))},[s.data,e,A,g]),s}function uc(){const e=sA(),A=iA(Q=>Q.setStatus),g=iA(Q=>Q.setUrl),s=iA(Q=>Q.setError),o=iA(Q=>Q.setProgress);return nA({mutationFn:()=>lc(),onMutate:()=>{A("starting"),o("Connecting..."),s(null)},onSuccess:Q=>{Q.ok&&Q.url?(A("connected"),g(Q.url),o(null)):Q.ok||(A("error"),s(Q.error||"Failed to start tunnel"),o(null)),e.invalidateQueries({queryKey:["tunnel"]})},onError:Q=>{A("error"),s(Q.message),o(null)}})}function hc(){const e=sA(),A=iA(g=>g.reset);return nA({mutationFn:cc,onSuccess:()=>{A(),e.invalidateQueries({queryKey:["tunnel"]})}})}function Dc(){const e=iA(a=>a.setStatus),A=iA(a=>a.setUrl),g=iA(a=>a.setError),s=iA(a=>a.setProgress),o=iA(a=>a.isExpanded),Q=l.useRef(null),B=l.useCallback(()=>{Q.current&&Q.current.close();const a=new EventSource(`${TA}/v1/tunnel/stream`);return Q.current=a,a.onmessage=r=>{try{const i=JSON.parse(r.data);i.type==="status"&&(e(i.status),A(i.url),g(i.error),s(i.progress))}catch{}},a.onerror=()=>{a.close(),Q.current=null},()=>{a.close(),Q.current=null}},[e,A,g,s]);return l.useEffect(()=>o?B():()=>{Q.current&&(Q.current.close(),Q.current=null)},[o,B]),{connect:B}}function pc(e){try{const g=new URL(e).hostname;return g.length>24?`${g.slice(0,12)}...${g.slice(-8)}`:g}catch{return e.length>24?`${e.slice(0,12)}...${e.slice(-8)}`:e}}const wc=l.memo(function(){const A=iA(C=>C.isExpanded),g=iA(C=>C.collapseSidebar),s=iA(C=>C.status),o=iA(C=>C.url),Q=iA(C=>C.error),B=iA(C=>C.progress),a=uc(),r=hc(),[i,E]=l.useState(!1);dc(),Dc();const I=async()=>{o&&(await navigator.clipboard.writeText(o),E(!0),setTimeout(()=>E(!1),2e3))},c=()=>{a.mutate()},n=()=>{r.mutate()};return A?t.jsxs("div",{className:"w-80 border-l border-border bg-background flex flex-col h-full",children:[t.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium text-sm",children:"Remote Access"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"Close sidebar",children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[s==="idle"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[t.jsx(He,{className:"w-12 h-12 text-muted-foreground/30 mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Access from anywhere"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:"Start a secure tunnel to access otto from your phone or another device."}),t.jsx("button",{type:"button",onClick:c,disabled:a.isPending,className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:a.isPending?"Starting...":"Start Tunnel"})]}),s==="starting"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[t.jsx(CA,{className:"w-8 h-8 text-primary animate-spin mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Setting up..."}),B&&t.jsx("p",{className:"text-xs text-muted-foreground max-w-[220px] break-words",children:B})]}),s==="connected"&&o&&t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),t.jsx("span",{className:"text-xs font-medium text-green-600",children:"Connected"})]}),t.jsx("div",{className:"flex justify-center pb-4",children:t.jsx("div",{className:"p-3 bg-white rounded-lg",children:t.jsx(hg,{value:o,size:160,level:"M",includeMargin:!1})})}),t.jsx("p",{className:"text-xs text-muted-foreground mb-4 text-center",children:"Scan with your phone camera"}),t.jsxs("div",{className:"flex items-center justify-between text-sm mb-4",children:[t.jsx("span",{className:"text-muted-foreground",children:"URL"}),t.jsxs("button",{type:"button",onClick:I,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy URL",children:[pc(o),i?t.jsx(Ae,{className:"w-3 h-3 text-green-500"}):t.jsx(Ye,{className:"w-3 h-3 text-muted-foreground"})]})]}),t.jsxs("button",{type:"button",onClick:()=>Ce(o),className:"flex items-center justify-center gap-2 px-4 py-2 border border-border rounded-md text-sm hover:bg-muted transition-colors mb-3",children:[t.jsx(jA,{className:"w-3.5 h-3.5"}),"Open in browser"]}),t.jsx("button",{type:"button",onClick:n,disabled:r.isPending,className:"w-full px-4 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:r.isPending?"Stopping...":"Stop Tunnel"})]}),s==="error"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[Q?.includes("Rate limited")?t.jsxs(t.Fragment,{children:[t.jsx(Cs,{className:"w-8 h-8 text-yellow-500 mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Rate Limited"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[220px]",children:"Cloudflare limits anonymous tunnel requests. Please wait 5-10 minutes before trying again."})]}):t.jsxs(t.Fragment,{children:[t.jsx(le,{className:"w-8 h-8 text-destructive mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Connection failed"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:Q||"Unable to establish tunnel connection."})]}),t.jsx("button",{type:"button",onClick:c,disabled:a.isPending||Q?.includes("Rate limited"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",title:Q?.includes("Rate limited")?"Wait 5-10 minutes":void 0,children:Q?.includes("Rate limited")?"Wait & Try Again":"Try Again"})]})]})]}):null}),mc=l.memo(function(){const A=iA(Q=>Q.isExpanded),g=iA(Q=>Q.toggleSidebar),o=iA(Q=>Q.status)==="connected";return t.jsxs("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Remote Access",children:[t.jsx(He,{className:"w-5 h-5 text-muted-foreground mx-auto"}),o&&t.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full animate-pulse"})]})});async function xc(){const e=await fetch(`${TA}/v1/mcp/servers`);if(!e.ok)throw new Error("Failed to fetch MCP servers");return e.json()}function fc(){const e=uA(g=>g.setServers),A=FA({queryKey:["mcp","servers"],queryFn:xc,refetchInterval:1e4});return l.useEffect(()=>{A.data?.servers&&e(A.data.servers)},[A.data,e]),A}function Nc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}/start`,{method:"POST"})).json();if(!s.ok)throw new Error(s.error||"Failed to start server");return s},onSettled:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function kc(){const e=sA(),A=uA(g=>g.setLoading);return nA({mutationFn:async g=>{A(g,!0);const o=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(g)}/stop`,{method:"POST"})).json();if(!o.ok)throw new Error(o.error||"Failed to stop server");return o},onSettled:(g,s,o)=>{A(o,!1),e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Mc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)})).json();if(!s.ok)throw new Error(s.error||"Failed to add MCP server");return s},onSuccess:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function yc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}`,{method:"DELETE"})).json();if(!s.ok)throw new Error(s.error||"Failed to remove MCP server");return s},onSuccess:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Gc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}/auth`,{method:"POST"})).json();if(!s.ok)throw new Error(s.error||"Failed to initiate auth");return s},onSettled:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Fc(e){return FA({queryKey:["mcp","auth",e],queryFn:async()=>e?(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(e)}/auth/status`)).json():{authenticated:!1},enabled:!!e,refetchInterval:3e3})}function bc(){const e=uA(B=>B.copilotDevice),A=uA(B=>B.setCopilotDevice),g=uA(B=>B.setLoading),s=sA(),o=l.useRef(null),Q=l.useCallback(()=>{o.current&&(clearInterval(o.current),o.current=null)},[]);return l.useEffect(()=>{if(!e){Q();return}const{sessionId:B,serverName:a,interval:r}=e,i=(r||5)*1e3+1e3;return o.current=setInterval(async()=>{try{const I=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(a)}/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:B})})).json();I.status==="complete"?(Q(),A(null),g(a,!1),s.invalidateQueries({queryKey:["mcp","servers"]})):I.status==="error"&&(Q(),A(null),g(a,!1))}catch{Q(),A(null),g(a,!1)}},i),Q},[e,A,g,s,Q]),e}function Uc(e){const A=e.trim().split(/\s+/);return{command:A[0]??"",args:A.slice(1)}}function Sc(e){const A=e.trim();if(!A)return;const g={};for(const s of A.split(`
127
+ `)}`}return n?/@@ -\d+(?:,\d+)? \+\d+(?:,\d+)? @@/.test(n)?n:Rl(n):null},[E,g]);if(l.useEffect(()=>{if(A&&!i.current){const{isCollapsed:n}=ze.getState();r.current=n,a(!0)}else!A&&i.current&&r.current!==null&&(a(r.current),r.current=null);i.current=A},[A,a]),l.useEffect(()=>{const n=C=>{const d=C.target,u=d.tagName==="INPUT"||d.tagName==="TEXTAREA"||d.isContentEditable;(C.key==="Escape"||C.key==="q"&&!u)&&A&&B(),!u&&A&&s.length>1&&(C.key==="ArrowLeft"||C.key==="["?(C.preventDefault(),Q(Math.max(0,o-1))):(C.key==="ArrowRight"||C.key==="]")&&(C.preventDefault(),Q(Math.min(s.length-1,o+1))))};return document.addEventListener("keydown",n),()=>document.removeEventListener("keydown",n)},[A,B,s.length,o,Q]),!A||!g||!E)return null;const c=s.length>1;return t.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3 shrink-0",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:B,title:"Close diff viewer (ESC)",children:t.jsx(kA,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:g,children:g}),t.jsx("span",{className:"text-xs px-2 py-0.5 rounded bg-primary/10 text-primary flex-shrink-0 capitalize",children:E.operation}),E.artifact?.summary&&t.jsxs("div",{className:"flex items-center gap-1 text-xs flex-shrink-0",children:[t.jsxs("span",{className:"text-green-500",children:["+",E.artifact.summary.additions]}),t.jsxs("span",{className:"text-red-500",children:["-",E.artifact.summary.deletions]})]})]}),c&&t.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>Q(Math.max(0,o-1)),disabled:o===0,title:"Previous operation (←)",children:t.jsx(ha,{className:"w-4 h-4"})}),t.jsxs("span",{className:"text-xs text-muted-foreground min-w-[60px] text-center",children:[o+1," / ",s.length]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>Q(Math.min(s.length-1,o+1)),disabled:o===s.length-1,title:"Next operation (→)",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),c&&t.jsx("div",{className:"border-b border-border px-4 py-2 flex gap-2 overflow-x-auto shrink-0",children:s.map((n,C)=>t.jsxs("button",{type:"button",onClick:()=>Q(C),className:`px-3 py-1.5 text-xs rounded-md flex items-center gap-2 shrink-0 transition-colors ${C===o?"bg-primary text-primary-foreground":"bg-muted hover:bg-muted/80 text-muted-foreground"}`,children:[t.jsx("span",{className:"capitalize",children:n.operation}),t.jsx("span",{className:"opacity-70",children:ql(n.timestamp)}),n.artifact?.summary&&t.jsxs("span",{className:"opacity-70",children:["+",n.artifact.summary.additions,"/-",n.artifact.summary.deletions]})]},n.toolCallId))}),t.jsx("div",{className:"flex-1 overflow-hidden p-4",children:I?t.jsx(vl,{patch:I}):t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"No diff content available"})})]})}),Tl={};class Yl{get baseUrl(){const A=window;if(A.OTTO_SERVER_URL)return A.OTTO_SERVER_URL;if(!Tl?.VITE_API_BASE_URL)return TA}async listResearchSessions(A){const g=await fetch(`${this.baseUrl}/v1/sessions/${A}/research`,{method:"GET",headers:{"Content-Type":"application/json"}});if(!g.ok){const s=await g.json().catch(()=>({error:"Failed to fetch research sessions"}));throw new Error(s.error||"Failed to fetch research sessions")}return g.json()}async createResearchSession(A,g){const s=await fetch(`${this.baseUrl}/v1/sessions/${A}/research`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g)});if(!s.ok){const o=await s.json().catch(()=>({error:"Failed to create research session"}));throw new Error(o.error||"Failed to create research session")}return s.json()}async deleteResearchSession(A){const g=await fetch(`${this.baseUrl}/v1/research/${A}`,{method:"DELETE",headers:{"Content-Type":"application/json"}});if(!g.ok){const s=await g.json().catch(()=>({error:"Failed to delete research session"}));throw new Error(s.error||"Failed to delete research session")}return g.json()}async injectContext(A,g,s){const o=await fetch(`${this.baseUrl}/v1/sessions/${A}/inject`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({researchSessionId:g,label:s})});if(!o.ok){const Q=await o.json().catch(()=>({error:"Failed to inject context"}));throw new Error(Q.error||"Failed to inject context")}return o.json()}async exportToNewSession(A,g){const s=await fetch(`${this.baseUrl}/v1/research/${A}/export`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(g??{})});if(!s.ok){const o=await s.json().catch(()=>({error:"Failed to export to session"}));throw new Error(o.error||"Failed to export to session")}return s.json()}}const ug=new Yl;function pB(e){return FA({queryKey:["research","sessions",e],queryFn:()=>ug.listResearchSessions(e),enabled:!!e,staleTime:3e4})}function Hl(){const e=sA();return nA({mutationFn:({parentSessionId:A,data:g})=>ug.createResearchSession(A,g??{}),onSuccess:(A,{parentSessionId:g})=>{e.invalidateQueries({queryKey:["research","sessions",g]})}})}function Pl(){const e=Pt(A=>A.addContext);return nA({mutationFn:({parentSessionId:A,researchSessionId:g,label:s})=>ug.injectContext(A,g,s),onSuccess:(A,{parentSessionId:g})=>{e(g,{id:A.sessionId,sessionId:A.sessionId,label:A.label,content:A.content})}})}function Wl(){const e=sA();return nA({mutationFn:({researchId:A,data:g})=>ug.exportToNewSession(A,g),onSuccess:()=>{e.invalidateQueries({queryKey:ke})}})}const bo="research",Uo=384,zl=384,Vl=640,Zl=l.memo(function({parentSessionId:A,onNavigateToSession:g}){const s=SA(q=>q.isExpanded),o=SA(q=>q.collapseSidebar),Q=Ue(q=>q.widths[bo]??Uo),B=SA(q=>q.activeResearchSessionId),a=SA(q=>q.selectResearchSession),[r,i]=l.useState(!1),[E,I]=l.useState(""),[c,n]=l.useState(!1),[C,d]=l.useState("idle"),u=l.useRef(null),D=l.useRef(null),{data:w,isLoading:h,refetch:m}=pB(A),k=Hl(),y=Pl(),G=Wl(),{data:M}=Nt(),{data:x}=eg(B??void 0),{data:F}=eg(A??void 0);uB(B??void 0);const p=eB(B??""),f=sA(),N=nA({mutationFn:async({sessionId:q,content:BA})=>v.sendMessage(q,{content:BA}),onSuccess:(q,{sessionId:BA})=>{f.invalidateQueries({queryKey:["messages",BA]})}});l.useEffect(()=>{A&&SA.getState().setParentSessionId(A)},[A]),l.useEffect(()=>{w?.sessions?.length?w.sessions.some(BA=>BA.id===B)||a(w.sessions[0].id):w?.sessions?.length===0&&a(null)},[w,B,a]),l.useEffect(()=>{D.current?.scrollIntoView({behavior:"smooth"})},[]);const b=l.useCallback(()=>{const q=u.current;q&&(q.style.height="auto",q.style.height=`${Math.min(q.scrollHeight,120)}px`)},[]);l.useEffect(()=>{b()},[b,E]);const S=l.useCallback(async()=>{if(A)try{const q=await k.mutateAsync({parentSessionId:A,data:{}});await m(),a(q.session.id),i(!1)}catch(q){console.error("Failed to create research session:",q)}},[A,k,a,m]),O=l.useCallback(q=>{a(q.id),i(!1)},[a]),L=l.useCallback(async()=>{if(!A||!B)return;if(F?.some(ee=>ee.role==="system"&&ee.parts?.some(JA=>typeof JA.content=="string"&&JA.content.includes(`from="${B}"`)))){d("error"),setTimeout(()=>d("idle"),3e3);return}const NA=`Research ${new Date().toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}`;try{await y.mutateAsync({parentSessionId:A,researchSessionId:B,label:NA}),d("success"),setTimeout(()=>d("idle"),5e3),f.invalidateQueries({queryKey:["messages",A]})}catch(ee){console.error("Failed to inject context:",ee),d("error"),setTimeout(()=>d("idle"),3e3)}},[A,B,y,F,f]),R=l.useCallback(async()=>{if(B)try{const q=await G.mutateAsync({researchId:B});g&&q.newSession?.id&&g(q.newSession.id)}catch(q){console.error("Failed to export to session:",q)}},[B,G,g]),j=l.useCallback(async()=>{if(!(!E.trim()||!A))try{let q=B;q||(q=(await k.mutateAsync({parentSessionId:A,data:{}})).session.id,a(q)),await N.mutateAsync({sessionId:q,content:E}),I(""),u.current&&(u.current.style.height="auto")}catch(q){console.error("Failed to send message:",q)}},[E,A,B,k,a,N]),J=l.useCallback(q=>{q.key==="Enter"&&!q.shiftKey&&(q.preventDefault(),j())},[j]),H=l.useMemo(()=>x?.some(q=>q.role==="assistant"&&q.status==="pending")??!1,[x]),z=l.useMemo(()=>!B||!F?!1:F.some(q=>q.role==="system"&&q.parts?.some(BA=>typeof BA.content=="string"&&BA.content.includes(`from="${B}"`))),[B,F]),AA=l.useCallback(async(q,BA)=>{if(!B){n(!1);return}try{await p.mutateAsync({provider:q,model:BA}),await f.invalidateQueries({queryKey:["research","sessions",A]}),n(!1)}catch(YA){console.error("Failed to update research session model:",YA)}},[B,p,f,A]),tA=Ns(A??"");if(!s)return null;const lA=w?.sessions??[],yA=lA.find(q=>q.id===B),P=x??[],oA=yA?.provider??tA?.provider??"",T=yA?.model??tA?.model??"",cA=M?.[oA]?.label??oA,bA=M?.[oA]?.models.find(q=>q.id===T)?.label??T;return t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:Q},children:[t.jsx(et,{panelKey:bo,side:"right",minWidth:zl,maxWidth:Vl,defaultWidth:Uo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between",children:[t.jsxs("div",{className:"flex items-center gap-2 flex-1",children:[t.jsx(It,{className:"w-4 h-4 text-teal-500"}),t.jsx("span",{className:"font-medium text-foreground text-sm",children:"Research"})]}),t.jsxs("div",{className:"flex items-center gap-0.5",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>i(!r),title:"Research history",className:"h-8 w-8",children:t.jsx(Da,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:S,disabled:!A||k.isPending,title:"New research session",className:"h-8 w-8",children:k.isPending?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsx(fe,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:o,title:"Close sidebar",className:"h-8 w-8",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),r?t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[t.jsx("div",{className:"p-2 border-b border-border",children:t.jsx("div",{className:"text-xs font-medium text-muted-foreground px-2 py-1",children:"Research Sessions"})}),h?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading..."}):lA.length===0?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No research sessions yet"}):t.jsx("div",{className:"p-2 space-y-1",children:lA.map(q=>t.jsxs("button",{type:"button",onClick:()=>O(q),className:`w-full text-left p-2 rounded-md text-sm transition-colors ${q.id===B?"bg-teal-500/10 border border-teal-500/30 text-foreground":"hover:bg-muted"}`,children:[t.jsx("div",{className:"font-medium truncate",children:q.title||"Untitled"}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[q.messageCount," messages •"," ",Xl(q.lastActiveAt??q.createdAt)]})]},q.id))})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex-1 overflow-y-auto px-3 py-3 research-messages text-[13px]",children:B?P.length===0?t.jsx("div",{className:"text-xs text-muted-foreground text-center py-8",children:t.jsx("p",{children:"Ask a question to start researching."})}):t.jsxs("div",{className:"space-y-1.5",children:[P.map((q,BA)=>{if(q.role==="user"){const YA=P[BA+1];return t.jsx(nB,{sessionId:B,message:q,isFirst:BA===0,nextAssistantMessageId:YA?.role==="assistant"?YA.id:void 0},q.id)}if(q.role==="assistant"){const YA=BA>0?P[BA-1]:null,NA=P[BA+1],ee=YA?.role!=="assistant",JA=NA?.role==="assistant";return t.jsx(EB,{sessionId:B,message:q,showHeader:ee,hasNextAssistantMessage:JA,isLastMessage:BA===P.length-1,compact:!0,onNavigateToSession:g},q.id)}return null}),t.jsx("div",{ref:D})]}):t.jsxs("div",{className:"text-xs text-muted-foreground text-center py-8",children:[t.jsx(It,{className:"w-8 h-8 mx-auto mb-2 text-muted-foreground/50"}),t.jsx("p",{children:"Start researching by asking a question below."})]})}),t.jsxs("div",{className:"p-3 border-t border-border",children:[t.jsx("div",{className:"relative flex flex-col rounded-3xl bg-card border border-border focus-within:border-teal-500/60 focus-within:ring-1 focus-within:ring-teal-500/40 p-1",children:t.jsxs("div",{className:"flex items-end gap-1",children:[t.jsx(ng,{ref:u,value:E,onChange:q=>I(q.target.value),onKeyDown:J,placeholder:"Ask anything...",disabled:!A||N.isPending||k.isPending,rows:1,className:"flex-1 border-0 bg-transparent pl-2 pr-1 py-2 max-h-[120px] overflow-y-auto leading-normal resize-none scrollbar-hide text-sm focus:ring-0 focus:outline-none",style:{height:"2.25rem"}}),t.jsx("button",{type:"button",onClick:j,disabled:!E.trim()||!A||N.isPending||k.isPending||H,className:`flex items-center justify-center w-9 h-9 rounded-full transition-colors flex-shrink-0 ${E.trim()&&A&&!H?"bg-teal-500 hover:bg-teal-600 text-white":"bg-transparent text-muted-foreground"}`,children:N.isPending||k.isPending?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsx(Po,{className:"w-4 h-4"})})]})}),C==="success"&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-teal-500/10 border border-teal-500/30 text-teal-600 dark:text-teal-400",children:[t.jsx(Ae,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"flex-1",children:"Context injected — will be used on next request"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"hover:text-teal-500",children:t.jsx(kA,{className:"w-3 h-3"})})]}),C==="error"&&t.jsxs("div",{className:"flex items-center gap-2 mt-2 px-2 py-1.5 text-xs rounded-lg bg-red-500/10 border border-red-500/30 text-red-600 dark:text-red-400",children:[t.jsx(kA,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"flex-1",children:"Failed to inject context"}),t.jsx("button",{type:"button",onClick:()=>d("idle"),className:"hover:text-red-500",children:t.jsx(kA,{className:"w-3 h-3"})})]}),t.jsxs("div",{className:"flex gap-2 mt-2",children:[t.jsxs("button",{type:"button",onClick:L,disabled:!B||y.isPending||H||z,className:`flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg transition-colors disabled:opacity-50 disabled:cursor-not-allowed ${z?"bg-teal-500/10 text-teal-600 dark:text-teal-400 border border-teal-500/30":"bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground"}`,title:z?"Already injected into main session":"Inject findings into main session",children:[y.isPending?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):z?t.jsx(Ae,{className:"w-3 h-3"}):t.jsx(pa,{className:"w-3 h-3"}),z?"Injected":"Inject"]}),t.jsxs("button",{type:"button",onClick:R,disabled:!B||G.isPending||H,className:"flex-1 flex items-center justify-center gap-1.5 px-2 py-1.5 text-xs rounded-lg bg-muted hover:bg-muted/80 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50 disabled:cursor-not-allowed",title:"Export to new main session",children:[G.isPending?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):t.jsx(jA,{className:"w-3 h-3"}),"Export"]})]})]})]}),t.jsxs("div",{className:"h-12 px-3 border-t border-border text-xs text-muted-foreground flex items-center justify-between",children:[t.jsxs("span",{className:"text-[10px]",children:[lA.length," research session",lA.length!==1?"s":""]}),(cA||bA)&&t.jsxs("button",{type:"button",onClick:()=>n(!0),className:"flex items-center gap-1 text-[10px] hover:text-foreground transition-colors",children:[t.jsx("span",{className:"opacity-60",children:cA}),t.jsx("span",{className:"opacity-40",children:"/"}),t.jsx("span",{children:bA}),t.jsx(PA,{className:"w-3 h-3 opacity-40"})]})]}),t.jsx(Me,{isOpen:c,onClose:()=>n(!1),title:"Select Model for Research",maxWidth:"md",children:(oA||T)&&t.jsx(QB,{provider:oA,model:T,onChange:AA})})]})]})});function Xl(e){const A=Date.now()-e,g=Math.floor(A/6e4);if(g<1)return"just now";if(g<60)return`${g}m ago`;const s=Math.floor(g/60);return s<24?`${s}h ago`:`${Math.floor(s/24)}d ago`}const _l=l.memo(function({parentSessionId:A}){const g=SA(B=>B.isExpanded),s=SA(B=>B.toggleSidebar),{data:o}=pB(A??null),Q=o?.sessions?.length??0;return t.jsxs("button",{type:"button",onClick:s,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${g?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Research (⌘⇧R)",children:[t.jsx(It,{className:"w-5 h-5 text-muted-foreground mx-auto"}),Q>0&&t.jsx("span",{className:"absolute top-1 right-1 w-5 h-5 bg-primary text-primary-foreground text-xs rounded-full flex items-center justify-center font-semibold",children:Q>9?"9+":Q})]})});var $l=Object.defineProperty,gg=Object.getOwnPropertySymbols,wB=Object.prototype.hasOwnProperty,mB=Object.prototype.propertyIsEnumerable,So=(e,A,g)=>A in e?$l(e,A,{enumerable:!0,configurable:!0,writable:!0,value:g}):e[A]=g,gs=(e,A)=>{for(var g in A||(A={}))wB.call(A,g)&&So(e,g,A[g]);if(gg)for(var g of gg(A))mB.call(A,g)&&So(e,g,A[g]);return e},ss=(e,A)=>{var g={};for(var s in e)wB.call(e,s)&&A.indexOf(s)<0&&(g[s]=e[s]);if(e!=null&&gg)for(var s of gg(e))A.indexOf(s)<0&&mB.call(e,s)&&(g[s]=e[s]);return g};var Ve;(e=>{const A=class gA{constructor(r,i,E,I){if(this.version=r,this.errorCorrectionLevel=i,this.modules=[],this.isFunction=[],r<gA.MIN_VERSION||r>gA.MAX_VERSION)throw new RangeError("Version value out of range");if(I<-1||I>7)throw new RangeError("Mask value out of range");this.size=r*4+17;let c=[];for(let C=0;C<this.size;C++)c.push(!1);for(let C=0;C<this.size;C++)this.modules.push(c.slice()),this.isFunction.push(c.slice());this.drawFunctionPatterns();const n=this.addEccAndInterleave(E);if(this.drawCodewords(n),I==-1){let C=1e9;for(let d=0;d<8;d++){this.applyMask(d),this.drawFormatBits(d);const u=this.getPenaltyScore();u<C&&(I=d,C=u),this.applyMask(d)}}o(0<=I&&I<=7),this.mask=I,this.applyMask(I),this.drawFormatBits(I),this.isFunction=[]}static encodeText(r,i){const E=e.QrSegment.makeSegments(r);return gA.encodeSegments(E,i)}static encodeBinary(r,i){const E=e.QrSegment.makeBytes(r);return gA.encodeSegments([E],i)}static encodeSegments(r,i,E=1,I=40,c=-1,n=!0){if(!(gA.MIN_VERSION<=E&&E<=I&&I<=gA.MAX_VERSION)||c<-1||c>7)throw new RangeError("Invalid value");let C,d;for(C=E;;C++){const h=gA.getNumDataCodewords(C,i)*8,m=B.getTotalBits(r,C);if(m<=h){d=m;break}if(C>=I)throw new RangeError("Data too long")}for(const h of[gA.Ecc.MEDIUM,gA.Ecc.QUARTILE,gA.Ecc.HIGH])n&&d<=gA.getNumDataCodewords(C,h)*8&&(i=h);let u=[];for(const h of r){g(h.mode.modeBits,4,u),g(h.numChars,h.mode.numCharCountBits(C),u);for(const m of h.getData())u.push(m)}o(u.length==d);const D=gA.getNumDataCodewords(C,i)*8;o(u.length<=D),g(0,Math.min(4,D-u.length),u),g(0,(8-u.length%8)%8,u),o(u.length%8==0);for(let h=236;u.length<D;h^=253)g(h,8,u);let w=[];for(;w.length*8<u.length;)w.push(0);return u.forEach((h,m)=>w[m>>>3]|=h<<7-(m&7)),new gA(C,i,w,c)}getModule(r,i){return 0<=r&&r<this.size&&0<=i&&i<this.size&&this.modules[i][r]}getModules(){return this.modules}drawFunctionPatterns(){for(let E=0;E<this.size;E++)this.setFunctionModule(6,E,E%2==0),this.setFunctionModule(E,6,E%2==0);this.drawFinderPattern(3,3),this.drawFinderPattern(this.size-4,3),this.drawFinderPattern(3,this.size-4);const r=this.getAlignmentPatternPositions(),i=r.length;for(let E=0;E<i;E++)for(let I=0;I<i;I++)E==0&&I==0||E==0&&I==i-1||E==i-1&&I==0||this.drawAlignmentPattern(r[E],r[I]);this.drawFormatBits(0),this.drawVersion()}drawFormatBits(r){const i=this.errorCorrectionLevel.formatBits<<3|r;let E=i;for(let c=0;c<10;c++)E=E<<1^(E>>>9)*1335;const I=(i<<10|E)^21522;o(I>>>15==0);for(let c=0;c<=5;c++)this.setFunctionModule(8,c,s(I,c));this.setFunctionModule(8,7,s(I,6)),this.setFunctionModule(8,8,s(I,7)),this.setFunctionModule(7,8,s(I,8));for(let c=9;c<15;c++)this.setFunctionModule(14-c,8,s(I,c));for(let c=0;c<8;c++)this.setFunctionModule(this.size-1-c,8,s(I,c));for(let c=8;c<15;c++)this.setFunctionModule(8,this.size-15+c,s(I,c));this.setFunctionModule(8,this.size-8,!0)}drawVersion(){if(this.version<7)return;let r=this.version;for(let E=0;E<12;E++)r=r<<1^(r>>>11)*7973;const i=this.version<<12|r;o(i>>>18==0);for(let E=0;E<18;E++){const I=s(i,E),c=this.size-11+E%3,n=Math.floor(E/3);this.setFunctionModule(c,n,I),this.setFunctionModule(n,c,I)}}drawFinderPattern(r,i){for(let E=-4;E<=4;E++)for(let I=-4;I<=4;I++){const c=Math.max(Math.abs(I),Math.abs(E)),n=r+I,C=i+E;0<=n&&n<this.size&&0<=C&&C<this.size&&this.setFunctionModule(n,C,c!=2&&c!=4)}}drawAlignmentPattern(r,i){for(let E=-2;E<=2;E++)for(let I=-2;I<=2;I++)this.setFunctionModule(r+I,i+E,Math.max(Math.abs(I),Math.abs(E))!=1)}setFunctionModule(r,i,E){this.modules[i][r]=E,this.isFunction[i][r]=!0}addEccAndInterleave(r){const i=this.version,E=this.errorCorrectionLevel;if(r.length!=gA.getNumDataCodewords(i,E))throw new RangeError("Invalid argument");const I=gA.NUM_ERROR_CORRECTION_BLOCKS[E.ordinal][i],c=gA.ECC_CODEWORDS_PER_BLOCK[E.ordinal][i],n=Math.floor(gA.getNumRawDataModules(i)/8),C=I-n%I,d=Math.floor(n/I);let u=[];const D=gA.reedSolomonComputeDivisor(c);for(let h=0,m=0;h<I;h++){let k=r.slice(m,m+d-c+(h<C?0:1));m+=k.length;const y=gA.reedSolomonComputeRemainder(k,D);h<C&&k.push(0),u.push(k.concat(y))}let w=[];for(let h=0;h<u[0].length;h++)u.forEach((m,k)=>{(h!=d-c||k>=C)&&w.push(m[h])});return o(w.length==n),w}drawCodewords(r){if(r.length!=Math.floor(gA.getNumRawDataModules(this.version)/8))throw new RangeError("Invalid argument");let i=0;for(let E=this.size-1;E>=1;E-=2){E==6&&(E=5);for(let I=0;I<this.size;I++)for(let c=0;c<2;c++){const n=E-c,d=(E+1&2)==0?this.size-1-I:I;!this.isFunction[d][n]&&i<r.length*8&&(this.modules[d][n]=s(r[i>>>3],7-(i&7)),i++)}}o(i==r.length*8)}applyMask(r){if(r<0||r>7)throw new RangeError("Mask value out of range");for(let i=0;i<this.size;i++)for(let E=0;E<this.size;E++){let I;switch(r){case 0:I=(E+i)%2==0;break;case 1:I=i%2==0;break;case 2:I=E%3==0;break;case 3:I=(E+i)%3==0;break;case 4:I=(Math.floor(E/3)+Math.floor(i/2))%2==0;break;case 5:I=E*i%2+E*i%3==0;break;case 6:I=(E*i%2+E*i%3)%2==0;break;case 7:I=((E+i)%2+E*i%3)%2==0;break;default:throw new Error("Unreachable")}!this.isFunction[i][E]&&I&&(this.modules[i][E]=!this.modules[i][E])}}getPenaltyScore(){let r=0;for(let c=0;c<this.size;c++){let n=!1,C=0,d=[0,0,0,0,0,0,0];for(let u=0;u<this.size;u++)this.modules[c][u]==n?(C++,C==5?r+=gA.PENALTY_N1:C>5&&r++):(this.finderPenaltyAddHistory(C,d),n||(r+=this.finderPenaltyCountPatterns(d)*gA.PENALTY_N3),n=this.modules[c][u],C=1);r+=this.finderPenaltyTerminateAndCount(n,C,d)*gA.PENALTY_N3}for(let c=0;c<this.size;c++){let n=!1,C=0,d=[0,0,0,0,0,0,0];for(let u=0;u<this.size;u++)this.modules[u][c]==n?(C++,C==5?r+=gA.PENALTY_N1:C>5&&r++):(this.finderPenaltyAddHistory(C,d),n||(r+=this.finderPenaltyCountPatterns(d)*gA.PENALTY_N3),n=this.modules[u][c],C=1);r+=this.finderPenaltyTerminateAndCount(n,C,d)*gA.PENALTY_N3}for(let c=0;c<this.size-1;c++)for(let n=0;n<this.size-1;n++){const C=this.modules[c][n];C==this.modules[c][n+1]&&C==this.modules[c+1][n]&&C==this.modules[c+1][n+1]&&(r+=gA.PENALTY_N2)}let i=0;for(const c of this.modules)i=c.reduce((n,C)=>n+(C?1:0),i);const E=this.size*this.size,I=Math.ceil(Math.abs(i*20-E*10)/E)-1;return o(0<=I&&I<=9),r+=I*gA.PENALTY_N4,o(0<=r&&r<=2568888),r}getAlignmentPatternPositions(){if(this.version==1)return[];{const r=Math.floor(this.version/7)+2,i=this.version==32?26:Math.ceil((this.version*4+4)/(r*2-2))*2;let E=[6];for(let I=this.size-7;E.length<r;I-=i)E.splice(1,0,I);return E}}static getNumRawDataModules(r){if(r<gA.MIN_VERSION||r>gA.MAX_VERSION)throw new RangeError("Version number out of range");let i=(16*r+128)*r+64;if(r>=2){const E=Math.floor(r/7)+2;i-=(25*E-10)*E-55,r>=7&&(i-=36)}return o(208<=i&&i<=29648),i}static getNumDataCodewords(r,i){return Math.floor(gA.getNumRawDataModules(r)/8)-gA.ECC_CODEWORDS_PER_BLOCK[i.ordinal][r]*gA.NUM_ERROR_CORRECTION_BLOCKS[i.ordinal][r]}static reedSolomonComputeDivisor(r){if(r<1||r>255)throw new RangeError("Degree out of range");let i=[];for(let I=0;I<r-1;I++)i.push(0);i.push(1);let E=1;for(let I=0;I<r;I++){for(let c=0;c<i.length;c++)i[c]=gA.reedSolomonMultiply(i[c],E),c+1<i.length&&(i[c]^=i[c+1]);E=gA.reedSolomonMultiply(E,2)}return i}static reedSolomonComputeRemainder(r,i){let E=i.map(I=>0);for(const I of r){const c=I^E.shift();E.push(0),i.forEach((n,C)=>E[C]^=gA.reedSolomonMultiply(n,c))}return E}static reedSolomonMultiply(r,i){if(r>>>8||i>>>8)throw new RangeError("Byte out of range");let E=0;for(let I=7;I>=0;I--)E=E<<1^(E>>>7)*285,E^=(i>>>I&1)*r;return o(E>>>8==0),E}finderPenaltyCountPatterns(r){const i=r[1];o(i<=this.size*3);const E=i>0&&r[2]==i&&r[3]==i*3&&r[4]==i&&r[5]==i;return(E&&r[0]>=i*4&&r[6]>=i?1:0)+(E&&r[6]>=i*4&&r[0]>=i?1:0)}finderPenaltyTerminateAndCount(r,i,E){return r&&(this.finderPenaltyAddHistory(i,E),i=0),i+=this.size,this.finderPenaltyAddHistory(i,E),this.finderPenaltyCountPatterns(E)}finderPenaltyAddHistory(r,i){i[0]==0&&(r+=this.size),i.pop(),i.unshift(r)}};A.MIN_VERSION=1,A.MAX_VERSION=40,A.PENALTY_N1=3,A.PENALTY_N2=3,A.PENALTY_N3=40,A.PENALTY_N4=10,A.ECC_CODEWORDS_PER_BLOCK=[[-1,7,10,15,20,26,18,20,24,30,18,20,24,26,30,22,24,28,30,28,28,28,28,30,30,26,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,10,16,26,18,24,16,18,22,22,26,30,22,22,24,24,28,28,26,26,26,26,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28,28],[-1,13,22,18,26,18,24,18,22,20,24,28,26,24,20,30,24,28,28,26,30,28,30,30,30,30,28,30,30,30,30,30,30,30,30,30,30,30,30,30,30],[-1,17,28,22,16,22,28,26,26,24,28,24,28,22,24,24,30,28,28,26,28,30,24,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30,30]],A.NUM_ERROR_CORRECTION_BLOCKS=[[-1,1,1,1,1,1,2,2,2,2,4,4,4,4,4,6,6,6,6,7,8,8,9,9,10,12,12,12,13,14,15,16,17,18,19,19,20,21,22,24,25],[-1,1,1,1,2,2,4,4,4,5,5,5,8,9,9,10,10,11,13,14,16,17,17,18,20,21,23,25,26,28,29,31,33,35,37,38,40,43,45,47,49],[-1,1,1,2,2,4,4,6,6,8,8,8,10,12,16,12,17,16,18,21,20,23,23,25,27,29,34,34,35,38,40,43,45,48,51,53,56,59,62,65,68],[-1,1,1,2,4,4,4,5,6,8,8,11,11,16,16,18,16,19,21,25,25,25,34,30,32,35,37,40,42,45,48,51,54,57,60,63,66,70,74,77,81]],e.QrCode=A;function g(a,r,i){if(r<0||r>31||a>>>r)throw new RangeError("Value out of range");for(let E=r-1;E>=0;E--)i.push(a>>>E&1)}function s(a,r){return(a>>>r&1)!=0}function o(a){if(!a)throw new Error("Assertion error")}const Q=class wA{constructor(r,i,E){if(this.mode=r,this.numChars=i,this.bitData=E,i<0)throw new RangeError("Invalid argument");this.bitData=E.slice()}static makeBytes(r){let i=[];for(const E of r)g(E,8,i);return new wA(wA.Mode.BYTE,r.length,i)}static makeNumeric(r){if(!wA.isNumeric(r))throw new RangeError("String contains non-numeric characters");let i=[];for(let E=0;E<r.length;){const I=Math.min(r.length-E,3);g(parseInt(r.substring(E,E+I),10),I*3+1,i),E+=I}return new wA(wA.Mode.NUMERIC,r.length,i)}static makeAlphanumeric(r){if(!wA.isAlphanumeric(r))throw new RangeError("String contains unencodable characters in alphanumeric mode");let i=[],E;for(E=0;E+2<=r.length;E+=2){let I=wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E))*45;I+=wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E+1)),g(I,11,i)}return E<r.length&&g(wA.ALPHANUMERIC_CHARSET.indexOf(r.charAt(E)),6,i),new wA(wA.Mode.ALPHANUMERIC,r.length,i)}static makeSegments(r){return r==""?[]:wA.isNumeric(r)?[wA.makeNumeric(r)]:wA.isAlphanumeric(r)?[wA.makeAlphanumeric(r)]:[wA.makeBytes(wA.toUtf8ByteArray(r))]}static makeEci(r){let i=[];if(r<0)throw new RangeError("ECI assignment value out of range");if(r<128)g(r,8,i);else if(r<16384)g(2,2,i),g(r,14,i);else if(r<1e6)g(6,3,i),g(r,21,i);else throw new RangeError("ECI assignment value out of range");return new wA(wA.Mode.ECI,0,i)}static isNumeric(r){return wA.NUMERIC_REGEX.test(r)}static isAlphanumeric(r){return wA.ALPHANUMERIC_REGEX.test(r)}getData(){return this.bitData.slice()}static getTotalBits(r,i){let E=0;for(const I of r){const c=I.mode.numCharCountBits(i);if(I.numChars>=1<<c)return 1/0;E+=4+c+I.bitData.length}return E}static toUtf8ByteArray(r){r=encodeURI(r);let i=[];for(let E=0;E<r.length;E++)r.charAt(E)!="%"?i.push(r.charCodeAt(E)):(i.push(parseInt(r.substring(E+1,E+3),16)),E+=2);return i}};Q.NUMERIC_REGEX=/^[0-9]*$/,Q.ALPHANUMERIC_REGEX=/^[A-Z0-9 $%*+.\/:-]*$/,Q.ALPHANUMERIC_CHARSET="0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:";let B=Q;e.QrSegment=Q})(Ve||(Ve={}));(e=>{(A=>{const g=class{constructor(o,Q){this.ordinal=o,this.formatBits=Q}};g.LOW=new g(0,1),g.MEDIUM=new g(1,0),g.QUARTILE=new g(2,3),g.HIGH=new g(3,2),A.Ecc=g})(e.QrCode||(e.QrCode={}))})(Ve||(Ve={}));(e=>{(A=>{const g=class{constructor(o,Q){this.modeBits=o,this.numBitsCharCount=Q}numCharCountBits(o){return this.numBitsCharCount[Math.floor((o+7)/17)]}};g.NUMERIC=new g(1,[10,12,14]),g.ALPHANUMERIC=new g(2,[9,11,13]),g.BYTE=new g(4,[8,16,16]),g.KANJI=new g(8,[8,10,12]),g.ECI=new g(7,[0,0,0]),A.Mode=g})(e.QrSegment||(e.QrSegment={}))})(Ve||(Ve={}));var Xe=Ve;var Ac={L:Xe.QrCode.Ecc.LOW,M:Xe.QrCode.Ecc.MEDIUM,Q:Xe.QrCode.Ecc.QUARTILE,H:Xe.QrCode.Ecc.HIGH},xB=128,fB="L",NB="#FFFFFF",kB="#000000",MB=!1,yB=1,ec=4,tc=0,gc=.1;function GB(e,A=0){const g=[];return e.forEach(function(s,o){let Q=null;s.forEach(function(B,a){if(!B&&Q!==null){g.push(`M${Q+A} ${o+A}h${a-Q}v1H${Q+A}z`),Q=null;return}if(a===s.length-1){if(!B)return;Q===null?g.push(`M${a+A},${o+A} h1v1H${a+A}z`):g.push(`M${Q+A},${o+A} h${a+1-Q}v1H${Q+A}z`);return}B&&Q===null&&(Q=a)})}),g.join("")}function FB(e,A){return e.slice().map((g,s)=>s<A.y||s>=A.y+A.h?g:g.map((o,Q)=>Q<A.x||Q>=A.x+A.w?o:!1))}function sc(e,A,g,s){if(s==null)return null;const o=e.length+g*2,Q=Math.floor(A*gc),B=o/A,a=(s.width||Q)*B,r=(s.height||Q)*B,i=s.x==null?e.length/2-a/2:s.x*B,E=s.y==null?e.length/2-r/2:s.y*B,I=s.opacity==null?1:s.opacity;let c=null;if(s.excavate){let C=Math.floor(i),d=Math.floor(E),u=Math.ceil(a+i-C),D=Math.ceil(r+E-d);c={x:C,y:d,w:u,h:D}}const n=s.crossOrigin;return{x:i,y:E,h:r,w:a,excavation:c,opacity:I,crossOrigin:n}}function oc(e,A){return A!=null?Math.max(Math.floor(A),0):e?ec:tc}function bB({value:e,level:A,minVersion:g,includeMargin:s,marginSize:o,imageSettings:Q,size:B,boostLevel:a}){let r=hA.useMemo(()=>{const C=(Array.isArray(e)?e:[e]).reduce((d,u)=>(d.push(...Xe.QrSegment.makeSegments(u)),d),[]);return Xe.QrCode.encodeSegments(C,Ac[A],g,void 0,void 0,a)},[e,A,g,a]);const{cells:i,margin:E,numCells:I,calculatedImageSettings:c}=hA.useMemo(()=>{let n=r.getModules();const C=oc(s,o),d=n.length+C*2,u=sc(n,B,C,Q);return{cells:n,margin:C,numCells:d,calculatedImageSettings:u}},[r,B,Q,s,o]);return{qrcode:r,margin:E,cells:i,numCells:I,calculatedImageSettings:c}}var Qc=(function(){try{new Path2D().addPath(new Path2D)}catch{return!1}return!0})(),Bc=hA.forwardRef(function(A,g){const s=A,{value:o,size:Q=xB,level:B=fB,bgColor:a=NB,fgColor:r=kB,includeMargin:i=MB,minVersion:E=yB,boostLevel:I,marginSize:c,imageSettings:n}=s,d=ss(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","marginSize","imageSettings"]),{style:u}=d,D=ss(d,["style"]),w=n?.src,h=hA.useRef(null),m=hA.useRef(null),k=hA.useCallback(b=>{h.current=b,typeof g=="function"?g(b):g&&(g.current=b)},[g]),[y,G]=hA.useState(!1),{margin:M,cells:x,numCells:F,calculatedImageSettings:p}=bB({value:o,level:B,minVersion:E,boostLevel:I,includeMargin:i,marginSize:c,imageSettings:n,size:Q});hA.useEffect(()=>{if(h.current!=null){const b=h.current,S=b.getContext("2d");if(!S)return;let O=x;const L=m.current,R=p!=null&&L!==null&&L.complete&&L.naturalHeight!==0&&L.naturalWidth!==0;R&&p.excavation!=null&&(O=FB(x,p.excavation));const j=window.devicePixelRatio||1;b.height=b.width=Q*j;const J=Q/F*j;S.scale(J,J),S.fillStyle=a,S.fillRect(0,0,F,F),S.fillStyle=r,Qc?S.fill(new Path2D(GB(O,M))):x.forEach(function(H,z){H.forEach(function(AA,tA){AA&&S.fillRect(tA+M,z+M,1,1)})}),p&&(S.globalAlpha=p.opacity),R&&S.drawImage(L,p.x+M,p.y+M,p.w,p.h)}}),hA.useEffect(()=>{G(!1)},[w]);const f=gs({height:Q,width:Q},u);let N=null;return w!=null&&(N=hA.createElement("img",{src:w,key:w,style:{display:"none"},onLoad:()=>{G(!0)},ref:m,crossOrigin:p?.crossOrigin})),hA.createElement(hA.Fragment,null,hA.createElement("canvas",gs({style:f,height:Q,width:Q,ref:k,role:"img"},D)),N)});Bc.displayName="QRCodeCanvas";var hg=hA.forwardRef(function(A,g){const s=A,{value:o,size:Q=xB,level:B=fB,bgColor:a=NB,fgColor:r=kB,includeMargin:i=MB,minVersion:E=yB,boostLevel:I,title:c,marginSize:n,imageSettings:C}=s,d=ss(s,["value","size","level","bgColor","fgColor","includeMargin","minVersion","boostLevel","title","marginSize","imageSettings"]),{margin:u,cells:D,numCells:w,calculatedImageSettings:h}=bB({value:o,level:B,minVersion:E,boostLevel:I,includeMargin:i,marginSize:n,imageSettings:C,size:Q});let m=D,k=null;C!=null&&h!=null&&(h.excavation!=null&&(m=FB(D,h.excavation)),k=hA.createElement("image",{href:C.src,height:h.h,width:h.w,x:h.x+u,y:h.y+u,preserveAspectRatio:"none",opacity:h.opacity,crossOrigin:h.crossOrigin}));const y=GB(m,u);return hA.createElement("svg",gs({height:Q,width:Q,viewBox:`0 0 ${w} ${w}`,ref:g,role:"img"},d),!!c&&hA.createElement("title",null,c),hA.createElement("path",{fill:a,d:`M0,0 h${w}v${w}H0z`,shapeRendering:"crispEdges"}),hA.createElement("path",{fill:r,d:y,shapeRendering:"crispEdges"}),k)});hg.displayName="QRCodeSVG";const Et=["wallet","defaults"],LA=MA((e,A)=>({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null,authStatus:null,setOpen:g=>e({isOpen:g}),setStep:g=>e({currentStep:g}),setManageMode:g=>e({manageMode:g}),setLoading:g=>e({isLoading:g}),setError:g=>e({error:g}),setAuthStatus:g=>e({authStatus:g}),nextStep:()=>{const{currentStep:g}=A(),s=Et.indexOf(g);s<Et.length-1&&e({currentStep:Et[s+1]})},prevStep:()=>{const{currentStep:g}=A(),s=Et.indexOf(g);s>0&&e({currentStep:Et[s-1]})},reset:()=>e({isOpen:!1,currentStep:"wallet",manageMode:!1,isLoading:!1,error:null})})),Kg=typeof window<"u"&&window.self!==window.top;function bs(){const e=LA(x=>x.setAuthStatus),A=LA(x=>x.setOpen),g=LA(x=>x.setLoading),s=LA(x=>x.setError),o=LA(x=>x.authStatus),Q=LA(x=>x.isOpen),B=sA(),[a,r]=l.useState(!1),[i,E]=l.useState(!1),I=l.useRef(),c=l.useRef(new Set),n=l.useCallback(async()=>{g(!0),s(null);try{const x=await v.getAuthStatus();return e(x),B.invalidateQueries({queryKey:["config"]}),B.invalidateQueries({queryKey:["models"]}),x}catch(x){const F=x instanceof Error?x.message:"Failed to load";return s(F),null}finally{g(!1)}},[e,g,s,B]),C=l.useCallback(async()=>{const x=await n();if(x){const F=Object.values(x.providers).some(f=>f.configured);(!x.onboardingComplete||!F||!x.setu.configured)&&A(!0)}r(!0)},[n,A]),d=l.useCallback(async()=>{g(!0),s(null);try{const x=await v.setupSetuWallet();return await n(),x}catch(x){const F=x instanceof Error?x.message:"Setup failed";throw s(F),x}finally{g(!1)}},[n,g,s]),u=l.useCallback(async x=>{g(!0),s(null);try{const F=await v.importSetuWallet(x);return await n(),F}catch(F){const p=F instanceof Error?F.message:"Import failed";throw s(p),F}finally{g(!1)}},[n,g,s]),D=l.useCallback(async(x,F)=>{g(!0),s(null);try{const p=await v.addProvider(x,F);return await n(),p}catch(p){const f=p instanceof Error?p.message:"Failed to add provider";throw s(f),p}finally{g(!1)}},[n,g,s]),w=l.useCallback(async x=>{g(!0),s(null);try{const F=await v.removeProvider(x);return await n(),F}catch(F){const p=F instanceof Error?F.message:"Failed to remove provider";throw s(p),F}finally{g(!1)}},[n,g,s]),h=l.useCallback(async()=>{g(!0),s(null);try{await v.completeOnboarding(),await n(),A(!1)}catch(x){const F=x instanceof Error?x.message:"Failed to complete onboarding";throw s(F),x}finally{g(!1)}},[n,g,s,A]),m=l.useCallback(()=>{const x=LA.getState().authStatus;x&&(c.current=new Set(Object.entries(x.providers).filter(([,F])=>F.configured).map(([F])=>F)))},[]),k=l.useCallback((x,F)=>{const p=v.getOAuthStartUrl(x,F);if(Kg)return m(),window.parent.postMessage({type:"otto-open-url",url:p},"*"),E(!0),null;const f=600,N=700,b=window.screenX+(window.outerWidth-f)/2,S=window.screenY+(window.outerHeight-N)/2;return window.open(p,"oauth_popup",`width=${f},height=${N},left=${b},top=${S},toolbar=no,menubar=no`)},[m]),y=l.useCallback(async(x,F)=>{const{url:p,sessionId:f}=await v.getOAuthUrl(x,F);if(Kg)return m(),window.parent.postMessage({type:"otto-open-url",url:p},"*"),E(!0),{popup:null,sessionId:f};const N=600,b=700,S=window.screenX+(window.outerWidth-N)/2,O=window.screenY+(window.outerHeight-b)/2;return{popup:window.open(p,"oauth_popup",`width=${N},height=${b},left=${S},top=${O},toolbar=no,menubar=no`),sessionId:f}},[m]),G=l.useCallback(async(x,F,p)=>{g(!0),s(null);try{return await v.exchangeOAuthCode(x,F,p),await n(),!0}catch(f){const N=f instanceof Error?f.message:"Failed to exchange code";throw s(N),f}finally{g(!1)}},[n,g,s]);l.useEffect(()=>{if(!i||!Kg)return;I.current=setInterval(()=>{n()},3e3);const x=setTimeout(()=>{E(!1)},3e5);return()=>{clearInterval(I.current),clearTimeout(x)}},[i,n]),l.useEffect(()=>{if(!i||!o)return;Object.entries(o.providers).filter(([,p])=>p.configured).some(([p])=>!c.current.has(p))&&E(!1)},[o,i]),l.useEffect(()=>{const x=F=>{F.data?.type==="oauth-success"&&n()};return window.addEventListener("message",x),()=>window.removeEventListener("message",x)},[n]);const M=l.useCallback(async x=>{const F=await v.pollCopilotDeviceFlow(x);return F.status==="complete"&&await n(),F},[n]);return{authStatus:o,isOpen:Q,initialized:a,fetchAuthStatus:n,checkOnboarding:C,setupWallet:d,importWallet:u,addProvider:D,removeProvider:w,completeOnboarding:h,startOAuth:k,startOAuthManual:y,exchangeOAuthCode:G,startCopilotDeviceFlow:v.startCopilotDeviceFlow.bind(v),pollCopilotDeviceFlow:M}}const Rt="pendingPolarCheckout";function ac(){const e=l.useRef(!1),A=l.useRef(null),g=IA(o=>o.setBalance),s=Ie(o=>o.removeToast);l.useEffect(()=>{if(e.current)return;const Q=new URLSearchParams(window.location.search).get("topup"),B=localStorage.getItem(Rt);if(Q==="pending"||B){e.current=!0;const a=new URL(window.location.href);if(a.searchParams.delete("topup"),window.history.replaceState({},"",a.toString()),!B){QA.info("Checking payment status...");return}A.current=QA.loading("Verifying payment...");let r=0;const i=10,E=2e3,I=()=>{A.current&&(s(A.current),A.current=null)},c=async()=>{r++;try{const n=await v.getPolarTopupStatus(B);if(n?.confirmed){localStorage.removeItem(Rt),I();const C=await v.getSetuBalance();C?.balance!==void 0&&g(C.balance),QA.success(`Payment confirmed! +$${n.amountUsd?.toFixed(2)} credited`);return}r<i?setTimeout(c,E):(localStorage.removeItem(Rt),I(),QA.info("Payment processing. Balance will update automatically."))}catch{r<i?setTimeout(c,E):(localStorage.removeItem(Rt),I(),QA.error("Could not verify payment. Please check your balance."))}};setTimeout(c,1500)}},[g,s])}const Ko="settings",Jo=320,ic=320,rc=500,zt=l.memo(function({title:A,icon:g,children:s,action:o}){return t.jsxs("div",{className:"border-b border-border",children:[t.jsxs("div",{className:"px-4 py-3 flex items-center gap-2 bg-muted/30",children:[g,t.jsx("span",{className:"text-sm font-medium flex-1",children:A}),o]}),t.jsx("div",{className:"px-4 py-3 space-y-3",children:s})]})}),Ro=l.memo(function({label:A,value:g}){return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsx("span",{className:"font-mono text-foreground",children:g})]})}),Jg=l.memo(function({label:A,checked:g,onChange:s}){return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsx("button",{type:"button",role:"switch","aria-checked":g,onClick:()=>s(!g),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${g?"bg-primary":"bg-muted"}`,children:t.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${g?"translate-x-6":"translate-x-1"} ${g?"bg-primary-foreground":"bg-foreground"}`})})]})}),Lt=l.memo(function({label:A,value:g,options:s,onChange:o,disabled:Q}){const[B,a]=l.useState(!1),r=s.find(i=>i.id===g);return t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:A}),t.jsxs("div",{className:"relative",children:[t.jsxs("button",{type:"button",onClick:()=>!Q&&a(!B),disabled:Q,className:"flex items-center gap-1 px-2 py-1 text-xs font-mono bg-muted hover:bg-muted/80 rounded border border-border disabled:opacity-50",children:[t.jsx("span",{className:"max-w-[120px] truncate",children:r?.label||g||"Select..."}),t.jsx(PA,{className:"w-3 h-3"})]}),B&&t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"fixed inset-0 z-40",onClick:()=>a(!1),role:"presentation"}),t.jsx("div",{className:"absolute right-0 top-full mt-1 z-50 min-w-[160px] max-h-[200px] overflow-y-auto bg-popover border border-border rounded-md shadow-lg",children:s.map(i=>t.jsx("button",{type:"button",onClick:()=>{o(i.id),a(!1)},className:`w-full px-3 py-2 text-left text-xs font-mono hover:bg-muted truncate ${i.id===g?"bg-muted/50":""}`,children:i.label},i.id))})]})]})]})}),Ec=l.memo(function(){const A=zA(p=>p.isExpanded),g=zA(p=>p.collapseSidebar),s=Ue(p=>p.widths[Ko]??Jo),{data:o}=Ig(),{data:Q}=Nt(),{preferences:B,updatePreferences:a}=ft(),r=rC(),i=IA(p=>p.balance),E=IA(p=>p.walletAddress),I=IA(p=>p.usdcBalance),c=IA(p=>p.isLoading),n=IA(p=>p.openTopupModal);ac();const C=o?.providers?.includes("setu"),{fetchBalance:d}=dg(C?"setu":void 0),u=LA(p=>p.setOpen),D=LA(p=>p.setStep),w=LA(p=>p.setManageMode),{fetchAuthStatus:h}=bs(),m=l.useCallback(async()=>await v.exportSetuWallet(),[]),k=l.useMemo(()=>!o?.providers||!Q?[]:o.providers.filter(p=>Q[p]).map(p=>({id:p,label:Q[p]?.label||p})),[o?.providers,Q]),y=l.useMemo(()=>{const p=o?.defaults?.provider;return!p||!Q?.[p]?[]:Q[p].models.map(f=>({id:f.id,label:f.label}))},[o?.defaults?.provider,Q]),G=l.useMemo(()=>o?.agents?o.agents.map(p=>({id:p,label:p})):[],[o?.agents]);if(!A)return null;const M=p=>{const f=Q?.[p]?.models?.[0]?.id;r.mutate({provider:p,model:f||o?.defaults?.model,scope:"global"})},x=p=>{r.mutate({model:p,scope:"global"})},F=p=>{r.mutate({agent:p,scope:"global"})};return t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:s},children:[t.jsx(et,{panelKey:Ko,side:"right",minWidth:ic,maxWidth:rc,defaultWidth:Jo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(gQ,{className:"w-4 h-4"}),t.jsx("span",{className:"font-medium",children:"Settings"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto",children:[t.jsxs(zt,{title:"Default Model",icon:t.jsx(wa,{className:"w-4 h-4 text-muted-foreground"}),children:[t.jsx(Lt,{label:"Provider",value:o?.defaults?.provider??"",options:k,onChange:M,disabled:r.isPending}),t.jsx(Lt,{label:"Model",value:o?.defaults?.model??"",options:y,onChange:x,disabled:r.isPending}),t.jsx(Lt,{label:"Agent",value:o?.defaults?.agent??"",options:G,onChange:F,disabled:r.isPending})]}),t.jsxs(zt,{title:"Preferences",icon:t.jsx(Qs,{className:"w-4 h-4 text-muted-foreground"}),children:[t.jsx(Jg,{label:"Vim Mode",checked:B.vimMode,onChange:p=>a({vimMode:p})}),t.jsx(Jg,{label:"Show Reasoning",checked:B.reasoningEnabled,onChange:p=>a({reasoningEnabled:p})}),t.jsx(Lt,{label:"Tool Approval",value:o?.defaults?.toolApproval??"dangerous",options:[{id:"auto",label:"Auto (no approval)"},{id:"dangerous",label:"Dangerous only"},{id:"all",label:"All tools"}],onChange:p=>r.mutate({toolApproval:p,scope:"global"}),disabled:r.isPending}),t.jsx(Jg,{label:"Guided Mode",checked:o?.defaults?.guidedMode??!1,onChange:p=>r.mutate({guidedMode:p,scope:"global"})})]}),t.jsx(zt,{title:"Providers",icon:t.jsx(ma,{className:"w-4 h-4 text-muted-foreground"}),action:t.jsx("button",{type:"button",onClick:()=>{h().then(()=>{D("wallet"),w(!0),u(!0)})},className:"p-1 hover:bg-muted rounded transition-colors",title:"Manage providers",children:t.jsx(Rg,{className:"w-3.5 h-3.5 text-muted-foreground"})}),children:t.jsx("div",{className:"flex flex-wrap gap-2",children:o?.providers?.map(p=>t.jsx("span",{className:"px-2 py-1 text-xs bg-muted rounded-md font-mono",children:p},p))??t.jsx("span",{className:"text-muted-foreground text-sm",children:"None"})})}),o?.providers?.includes("setu")&&t.jsx(nc,{setuWallet:E,setuBalance:i,setuUsdcBalance:I,setuLoading:c,refreshSetuBalance:d,openTopupModal:n,onExportPrivateKey:m}),t.jsx(Gs,{})]})]})]})}),nc=l.memo(function({setuWallet:A,setuBalance:g,setuUsdcBalance:s,setuLoading:o,refreshSetuBalance:Q,openTopupModal:B,onExportPrivateKey:a}){const[r,i]=l.useState(!1),[E,I]=l.useState(!1),[c,n]=l.useState(null),[C,d]=l.useState(!1),[u,D]=l.useState(null),[w,h]=l.useState(!1),m=l.useCallback(async()=>{A&&(await navigator.clipboard.writeText(A),i(!0),setTimeout(()=>i(!1),2e3))},[A]),k=async()=>{I(!0),h(!1),n(null),D(null),d(!0);try{const f=await a();n(f.privateKey)}catch(f){D(f instanceof Error?f.message:"Failed to export private key")}finally{d(!1)}},y=()=>{C||(I(!1),h(!1),n(null),D(null))},G=async()=>{c&&(await navigator.clipboard.writeText(c),h(!0),setTimeout(()=>h(!1),2e3))},M=f=>f?`${f.slice(0,4)}...${f.slice(-4)}`:"Not configured",x=f=>f===null?"—":`$${f.toFixed(4)}`,F=f=>f===null?"—":`${f.toFixed(2)} USDC`,p=A!==null;return t.jsxs(zt,{title:"Setu Credits",icon:t.jsx(Is,{className:"w-4 h-4 text-muted-foreground"}),action:t.jsx("button",{type:"button",onClick:Q,disabled:o,className:"p-1 hover:bg-muted rounded transition-colors disabled:opacity-50",title:"Refresh balances",children:t.jsx(HA,{className:`w-3.5 h-3.5 text-muted-foreground ${o?"animate-spin":""}`})}),children:[p?t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center pb-3",children:t.jsx("div",{className:"p-2 bg-white rounded-lg",children:t.jsx(hg,{value:A,size:120,level:"M",includeMargin:!1})})}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Address"}),t.jsxs("button",{type:"button",onClick:m,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy address",children:[M(A),r?t.jsx(Ae,{className:"w-3 h-3 text-green-500"}):t.jsx(Ye,{className:"w-3 h-3 text-muted-foreground"})]})]}),t.jsx(Ro,{label:"Balance",value:x(g)}),t.jsx(Ro,{label:"USDC",value:F(s)})]}):t.jsxs(t.Fragment,{children:[t.jsx("div",{className:"flex justify-center pb-3",children:t.jsx("div",{className:"w-[136px] h-[136px] bg-muted rounded-lg animate-pulse"})}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Address"}),t.jsx("div",{className:"w-24 h-4 bg-muted rounded animate-pulse"})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"Balance"}),t.jsx("div",{className:"w-16 h-4 bg-muted rounded animate-pulse"})]}),t.jsxs("div",{className:"flex items-center justify-between text-sm",children:[t.jsx("span",{className:"text-muted-foreground",children:"USDC"}),t.jsx("div",{className:"w-20 h-4 bg-muted rounded animate-pulse"})]})]}),t.jsxs(_,{variant:"secondary",size:"sm",onClick:B,className:"w-full mt-2 gap-2",children:[t.jsx(fe,{className:"w-4 h-4"}),"Top Up Balance"]}),t.jsxs(_,{variant:"ghost",size:"sm",onClick:k,className:"w-full gap-2",children:[t.jsx(Zt,{className:"w-4 h-4"}),"Export Private Key"]}),E&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(Zt,{className:"w-5 h-5 text-muted-foreground"}),t.jsx("h3",{className:"text-lg font-semibold",children:"Export Setu Private Key"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Keep this private key secret. Anyone with this key can spend funds from your Setu wallet."}),C&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Exporting private key..."]}),!C&&c&&t.jsxs("div",{className:"space-y-3",children:[t.jsx("textarea",{readOnly:!0,value:c,className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground outline-none font-mono text-xs resize-y"}),t.jsxs(_,{variant:"secondary",size:"sm",onClick:G,className:"w-full gap-2",children:[w?t.jsx(Ae,{className:"w-4 h-4 text-green-500"}):t.jsx(Ye,{className:"w-4 h-4"}),w?"Copied":"Copy Private Key"]})]}),!C&&u&&t.jsx("p",{className:"text-sm text-red-500 mt-3",children:u}),t.jsx("div",{className:"flex gap-3 mt-5",children:t.jsx("button",{type:"button",onClick:y,disabled:C,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Close"})})]})]})})]})}),Cc=l.memo(function(){const A=zA(s=>s.isExpanded),g=zA(s=>s.toggleSidebar);return t.jsx("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Settings",children:t.jsx(gQ,{className:"w-5 h-5 text-muted-foreground mx-auto"})})});async function Ic(){const e=await fetch(`${TA}/v1/tunnel/status`);if(!e.ok)throw new Error("Failed to fetch tunnel status");return e.json()}async function lc(){return(await fetch(`${TA}/v1/tunnel/start`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({})})).json()}async function cc(){return(await fetch(`${TA}/v1/tunnel/stop`,{method:"POST"})).json()}function dc(){const e=iA(o=>o.setStatus),A=iA(o=>o.setUrl),g=iA(o=>o.setError),s=FA({queryKey:["tunnel","status"],queryFn:Ic,refetchInterval:3e3});return l.useEffect(()=>{s.data&&(e(s.data.status),A(s.data.url),g(s.data.error))},[s.data,e,A,g]),s}function uc(){const e=sA(),A=iA(Q=>Q.setStatus),g=iA(Q=>Q.setUrl),s=iA(Q=>Q.setError),o=iA(Q=>Q.setProgress);return nA({mutationFn:()=>lc(),onMutate:()=>{A("starting"),o("Connecting..."),s(null)},onSuccess:Q=>{Q.ok&&Q.url?(A("connected"),g(Q.url),o(null)):Q.ok||(A("error"),s(Q.error||"Failed to start tunnel"),o(null)),e.invalidateQueries({queryKey:["tunnel"]})},onError:Q=>{A("error"),s(Q.message),o(null)}})}function hc(){const e=sA(),A=iA(g=>g.reset);return nA({mutationFn:cc,onSuccess:()=>{A(),e.invalidateQueries({queryKey:["tunnel"]})}})}function Dc(){const e=iA(a=>a.setStatus),A=iA(a=>a.setUrl),g=iA(a=>a.setError),s=iA(a=>a.setProgress),o=iA(a=>a.isExpanded),Q=l.useRef(null),B=l.useCallback(()=>{Q.current&&Q.current.close();const a=new EventSource(`${TA}/v1/tunnel/stream`);return Q.current=a,a.onmessage=r=>{try{const i=JSON.parse(r.data);i.type==="status"&&(e(i.status),A(i.url),g(i.error),s(i.progress))}catch{}},a.onerror=()=>{a.close(),Q.current=null},()=>{a.close(),Q.current=null}},[e,A,g,s]);return l.useEffect(()=>o?B():()=>{Q.current&&(Q.current.close(),Q.current=null)},[o,B]),{connect:B}}function pc(e){try{const g=new URL(e).hostname;return g.length>24?`${g.slice(0,12)}...${g.slice(-8)}`:g}catch{return e.length>24?`${e.slice(0,12)}...${e.slice(-8)}`:e}}const wc=l.memo(function(){const A=iA(C=>C.isExpanded),g=iA(C=>C.collapseSidebar),s=iA(C=>C.status),o=iA(C=>C.url),Q=iA(C=>C.error),B=iA(C=>C.progress),a=uc(),r=hc(),[i,E]=l.useState(!1);dc(),Dc();const I=async()=>{o&&(await navigator.clipboard.writeText(o),E(!0),setTimeout(()=>E(!1),2e3))},c=()=>{a.mutate()},n=()=>{r.mutate()};return A?t.jsxs("div",{className:"w-80 border-l border-border bg-background flex flex-col h-full",children:[t.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(He,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium text-sm",children:"Remote Access"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"Close sidebar",children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsxs("div",{className:"flex-1 overflow-y-auto p-4",children:[s==="idle"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[t.jsx(He,{className:"w-12 h-12 text-muted-foreground/30 mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Access from anywhere"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:"Start a secure tunnel to access otto from your phone or another device."}),t.jsx("button",{type:"button",onClick:c,disabled:a.isPending,className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:a.isPending?"Starting...":"Start Tunnel"})]}),s==="starting"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[t.jsx(CA,{className:"w-8 h-8 text-primary animate-spin mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Setting up..."}),B&&t.jsx("p",{className:"text-xs text-muted-foreground max-w-[220px] break-words",children:B})]}),s==="connected"&&o&&t.jsxs("div",{className:"flex flex-col",children:[t.jsxs("div",{className:"flex items-center gap-2 mb-4",children:[t.jsx("div",{className:"w-2 h-2 rounded-full bg-green-500 animate-pulse"}),t.jsx("span",{className:"text-xs font-medium text-green-600",children:"Connected"})]}),t.jsx("div",{className:"flex justify-center pb-4",children:t.jsx("div",{className:"p-3 bg-white rounded-lg",children:t.jsx(hg,{value:o,size:160,level:"M",includeMargin:!1})})}),t.jsx("p",{className:"text-xs text-muted-foreground mb-4 text-center",children:"Scan with your phone camera"}),t.jsxs("div",{className:"flex items-center justify-between text-sm mb-4",children:[t.jsx("span",{className:"text-muted-foreground",children:"URL"}),t.jsxs("button",{type:"button",onClick:I,className:"flex items-center gap-1.5 font-mono text-foreground hover:text-muted-foreground transition-colors",title:"Copy URL",children:[pc(o),i?t.jsx(Ae,{className:"w-3 h-3 text-green-500"}):t.jsx(Ye,{className:"w-3 h-3 text-muted-foreground"})]})]}),t.jsxs("button",{type:"button",onClick:()=>Ce(o),className:"flex items-center justify-center gap-2 px-4 py-2 border border-border rounded-md text-sm hover:bg-muted transition-colors mb-3",children:[t.jsx(jA,{className:"w-3.5 h-3.5"}),"Open in browser"]}),t.jsx("button",{type:"button",onClick:n,disabled:r.isPending,className:"w-full px-4 py-2 text-sm text-muted-foreground hover:text-foreground transition-colors",children:r.isPending?"Stopping...":"Stop Tunnel"})]}),s==="error"&&t.jsxs("div",{className:"flex flex-col items-center justify-center h-full text-center",children:[Q?.includes("Rate limited")?t.jsxs(t.Fragment,{children:[t.jsx(Cs,{className:"w-8 h-8 text-yellow-500 mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Rate Limited"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[220px]",children:"Cloudflare limits anonymous tunnel requests. Please wait 5-10 minutes before trying again."})]}):t.jsxs(t.Fragment,{children:[t.jsx(le,{className:"w-8 h-8 text-destructive mb-4"}),t.jsx("h3",{className:"text-sm font-medium mb-2",children:"Connection failed"}),t.jsx("p",{className:"text-xs text-muted-foreground mb-6 max-w-[200px]",children:Q||"Unable to establish tunnel connection."})]}),t.jsx("button",{type:"button",onClick:c,disabled:a.isPending||Q?.includes("Rate limited"),className:"px-4 py-2 bg-primary text-primary-foreground rounded-md text-sm font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",title:Q?.includes("Rate limited")?"Wait 5-10 minutes":void 0,children:Q?.includes("Rate limited")?"Wait & Try Again":"Try Again"})]})]})]}):null}),mc=l.memo(function(){const A=iA(Q=>Q.isExpanded),g=iA(Q=>Q.toggleSidebar),o=iA(Q=>Q.status)==="connected";return t.jsxs("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Remote Access",children:[t.jsx(He,{className:"w-5 h-5 text-muted-foreground mx-auto"}),o&&t.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full animate-pulse"})]})});async function xc(){const e=await fetch(`${TA}/v1/mcp/servers`);if(!e.ok)throw new Error("Failed to fetch MCP servers");return e.json()}function fc(){const e=uA(g=>g.setServers),A=FA({queryKey:["mcp","servers"],queryFn:xc,refetchInterval:1e4});return l.useEffect(()=>{A.data?.servers&&e(A.data.servers)},[A.data,e]),A}function Nc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}/start`,{method:"POST"})).json();if(!s.ok)throw new Error(s.error||"Failed to start server");return s},onSettled:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function kc(){const e=sA(),A=uA(g=>g.setLoading);return nA({mutationFn:async g=>{A(g,!0);const o=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(g)}/stop`,{method:"POST"})).json();if(!o.ok)throw new Error(o.error||"Failed to stop server");return o},onSettled:(g,s,o)=>{A(o,!1),e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Mc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(A)})).json();if(!s.ok)throw new Error(s.error||"Failed to add MCP server");return s},onSuccess:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function yc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}`,{method:"DELETE"})).json();if(!s.ok)throw new Error(s.error||"Failed to remove MCP server");return s},onSuccess:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Gc(){const e=sA();return nA({mutationFn:async A=>{const s=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(A)}/auth`,{method:"POST"})).json();if(!s.ok)throw new Error(s.error||"Failed to initiate auth");return s},onSettled:()=>{e.invalidateQueries({queryKey:["mcp","servers"]})}})}function Fc(e){return FA({queryKey:["mcp","auth",e],queryFn:async()=>e?(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(e)}/auth/status`)).json():{authenticated:!1},enabled:!!e,refetchInterval:3e3})}function bc(){const e=uA(B=>B.copilotDevice),A=uA(B=>B.setCopilotDevice),g=uA(B=>B.setLoading),s=sA(),o=l.useRef(null),Q=l.useCallback(()=>{o.current&&(clearInterval(o.current),o.current=null)},[]);return l.useEffect(()=>{if(!e){Q();return}const{sessionId:B,serverName:a,interval:r}=e,i=(r||5)*1e3+1e3;return o.current=setInterval(async()=>{try{const I=await(await fetch(`${TA}/v1/mcp/servers/${encodeURIComponent(a)}/auth/callback`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:B})})).json();I.status==="complete"?(Q(),A(null),g(a,!1),s.invalidateQueries({queryKey:["mcp","servers"]})):I.status==="error"&&(Q(),A(null),g(a,!1))}catch{Q(),A(null),g(a,!1)}},i),Q},[e,A,g,s,Q]),e}function Uc(e){const A=e.trim().split(/\s+/);return{command:A[0]??"",args:A.slice(1)}}function Sc(e){const A=e.trim();if(!A)return;const g={};for(const s of A.split(`
128
128
  `)){const o=s.indexOf("=");o>0&&(g[s.slice(0,o).trim()]=s.slice(o+1).trim())}return Object.keys(g).length>0?g:void 0}function Kc(e){const A=e.trim();if(!A)return;const g={};for(const s of A.split(`
129
129
  `)){const o=s.indexOf(":");o>0&&(g[s.slice(0,o).trim()]=s.slice(o+1).trim())}return Object.keys(g).length>0?g:void 0}const Jc=l.memo(function({isOpen:A,onClose:g}){const[s,o]=l.useState("local"),[Q,B]=l.useState(""),[a,r]=l.useState(""),[i,E]=l.useState(""),[I,c]=l.useState("http"),[n,C]=l.useState(""),[d,u]=l.useState(""),[D,w]=l.useState("global"),[h,m]=l.useState(null),k=Mc(),y=l.useCallback(()=>{B(""),r(""),E(""),c("http"),C(""),u(""),w("global"),m(null),o("local")},[]),G=l.useCallback(()=>{y(),g()},[y,g]),M=l.useCallback(async()=>{m(null);const f=Q.trim();if(!f){m("Server name is required");return}try{if(s==="local"){const N=a.trim();if(!N){m("Command is required");return}if(/^https?:\/\//i.test(N)){m("Local commands cannot be URLs. Switch to Remote (HTTP) for remote servers.");return}const{command:b,args:S}=Uc(N);await k.mutateAsync({name:f,transport:"stdio",command:b,args:S,env:Sc(d),scope:D})}else{const N=i.trim();if(!N){m("URL is required");return}await k.mutateAsync({name:f,transport:I,url:N,headers:Kc(n),scope:D})}G()}catch(N){m(N instanceof Error?N.message:"Failed to add server")}},[Q,s,a,d,i,I,n,D,k,G]),x=l.useRef(null),[F,p]=l.useState(void 0);return l.useEffect(()=>{const f=x.current;if(!f)return;const N=new ResizeObserver(()=>{p(f.scrollHeight)});return N.observe(f),()=>N.disconnect()},[]),t.jsx(Me,{isOpen:A,onClose:G,title:"Add MCP Server",children:t.jsx("div",{className:"overflow-hidden transition-[height] duration-200 ease-in-out",style:{height:F!==void 0?F:"auto"},children:t.jsxs("div",{ref:x,className:"space-y-4",children:[t.jsxs("div",{className:"relative flex w-full rounded-lg bg-muted p-1",children:[t.jsx("div",{className:"absolute top-1 bottom-1 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:s==="local"?"4px":"50%",right:s==="remote"?"4px":"50%"}}),t.jsxs("button",{type:"button",onClick:()=>o("local"),className:`relative z-10 flex items-center justify-center gap-2 flex-1 text-sm font-medium py-2 rounded-md transition-colors duration-200 ${s==="local"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(we,{className:"w-4 h-4"}),"Local (stdio)"]}),t.jsxs("button",{type:"button",onClick:()=>o("remote"),className:`relative z-10 flex items-center justify-center gap-2 flex-1 text-sm font-medium py-2 rounded-md transition-colors duration-200 ${s==="remote"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(He,{className:"w-4 h-4"}),"Remote (HTTP)"]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Name"}),t.jsx(Tt,{value:Q,onChange:f=>B(f.target.value),placeholder:"e.g. github, linear, helius",autoFocus:!0})]}),s==="local"?t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Command"}),t.jsx(Tt,{value:a,onChange:f=>r(f.target.value),placeholder:"e.g. npx -y @modelcontextprotocol/server-github",onKeyDown:f=>{f.key==="Enter"&&M()}}),t.jsxs("p",{className:"text-xs text-muted-foreground mt-1",children:["Like"," ",t.jsx("code",{className:"bg-muted px-1 rounded",children:"npx -y helius-mcp@latest"})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Environment Variables"}),t.jsx("textarea",{value:d,onChange:f=>u(f.target.value),placeholder:`GITHUB_TOKEN=ghp_xxx
130
- API_KEY=sk-xxx`,rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: KEY=VALUE"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"URL"}),t.jsx(Tt,{value:i,onChange:f=>E(f.target.value),placeholder:"e.g. https://mcp.linear.app/mcp",onKeyDown:f=>{f.key==="Enter"&&M()}})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Transport"}),t.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[t.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:I==="http"?"2px":"50%",right:I==="sse"?"2px":"50%"}}),t.jsx("button",{type:"button",onClick:()=>c("http"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${I==="http"?"text-foreground":"text-muted-foreground/50"}`,children:"HTTP (recommended)"}),t.jsx("button",{type:"button",onClick:()=>c("sse"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${I==="sse"?"text-foreground":"text-muted-foreground/50"}`,children:"SSE (legacy)"})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Headers"}),t.jsx("textarea",{value:n,onChange:f=>C(f.target.value),placeholder:"Authorization: Bearer xxx",rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: Header-Name: value"})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"For OAuth servers (Linear, Notion, etc.), leave headers empty and authenticate after adding."})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Scope"}),t.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[t.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:D==="global"?"2px":"50%",right:D==="project"?"2px":"50%"}}),t.jsxs("button",{type:"button",onClick:()=>w("global"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${D==="global"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(sQ,{className:"w-3 h-3"}),"All projects"]}),t.jsxs("button",{type:"button",onClick:()=>w("project"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${D==="project"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(oQ,{className:"w-3 h-3"}),"This project only"]})]}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:D==="global"?"Saved to ~/.config/otto/config.json":"Saved to .otto/config.json (project-local)"})]}),h&&t.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 px-3 py-2 rounded",children:h}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx(_,{variant:"ghost",onClick:G,children:"Cancel"}),t.jsx(_,{variant:"primary",onClick:M,disabled:k.isPending,children:k.isPending?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"w-3 h-3 animate-spin mr-1"}),"Adding..."]}):"Add Server"})]})]})})})}),Rc=l.memo(function({checked:A,loading:g,onChange:s,disabled:o}){return t.jsx("button",{type:"button",role:"switch","aria-checked":A,disabled:o||g,onClick:Q=>{Q.stopPropagation(),s()},className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors duration-200 focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed ${A?"bg-green-500":"bg-muted-foreground/30"}`,children:t.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full transition-transform duration-200 ${A?"translate-x-[18px]":"translate-x-[3px]"} ${g?"bg-transparent":"bg-white"}`,children:g&&t.jsx(CA,{className:"w-3.5 h-3.5 animate-spin text-white"})})})}),Lc=l.memo(function({userCode:A,verificationUri:g}){const[s,o]=l.useState(!1),Q=l.useCallback(()=>{navigator.clipboard.writeText(A).then(()=>{o(!0),setTimeout(()=>o(!1),2e3)})},[A]);return t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsxs("div",{className:"rounded-md bg-yellow-500/10 border border-yellow-500/20 p-2 space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[t.jsx(CA,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),t.jsx("span",{className:"text-yellow-500/80",children:"Enter code at GitHub:"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("code",{className:"text-sm font-mono font-bold text-yellow-400 tracking-wider",children:A}),t.jsx("button",{type:"button",onClick:Q,className:"text-yellow-500/60 hover:text-yellow-400 transition-colors",title:"Copy code",children:t.jsx(xa,{className:"w-3.5 h-3.5"})}),s&&t.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",onClick:B=>{B.preventDefault(),Ce(g)},className:"inline-flex items-center gap-1 text-xs text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open GitHub login",t.jsx(jA,{className:"w-3 h-3"})]})]})})}),jc=l.memo(function({server:A,isLoading:g,authUrl:s,copilotDevice:o,onStart:Q,onStop:B,onRemove:a,onAuth:r}){const[i,E]=l.useState(!1),I=A.connected&&A.tools.length>0,c=A.transport==="http"||A.transport==="sse",n=(!!s||!!o)&&!A.connected,C=l.useCallback(()=>{A.authRequired&&!A.connected?r():A.connected?B():Q()},[A.connected,A.authRequired,r,B,Q]),d=l.useCallback(()=>{I&&E(u=>!u)},[I]);return t.jsxs("div",{className:`rounded-lg border transition-colors duration-200 group ${A.connected?"border-green-500/30 bg-green-500/5":n?"border-yellow-500/30 bg-yellow-500/5":"border-border bg-transparent"}`,children:[t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[t.jsx(Rc,{checked:A.connected,loading:g||n,onChange:C}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-medium truncate",children:A.name}),c&&t.jsx(He,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),A.authRequired&&!A.connected&&t.jsx(fa,{className:"w-3 h-3 text-yellow-500 flex-shrink-0"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:"text-xs text-muted-foreground truncate",children:c?A.url:`${A.command??""} ${A.args.join(" ")}`}),t.jsx("span",{className:"flex items-center flex-shrink-0 opacity-50",title:A.scope==="project"?"Project-local":"Global",children:A.scope==="project"?t.jsx(oQ,{className:"w-3 h-3"}):t.jsx(sQ,{className:"w-3 h-3"})})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[I&&t.jsxs("button",{type:"button",onClick:d,className:"flex items-center gap-0.5 text-xs text-muted-foreground hover:text-foreground px-1.5 py-1 rounded transition-colors",children:[t.jsx(Na,{className:"w-3 h-3"}),A.tools.length,i?t.jsx(PA,{className:"w-3 h-3"}):t.jsx(xA,{className:"w-3 h-3"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:a,title:"Remove server",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(dt,{className:"w-3 h-3 text-muted-foreground hover:text-red-400"})})]})]}),o&&!A.connected&&t.jsx(Lc,{userCode:o.userCode,verificationUri:o.verificationUri}),!o&&n&&s&&t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[t.jsx(CA,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),t.jsx("span",{className:"text-yellow-500/80",children:"Waiting for auth..."}),t.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.preventDefault(),Ce(s)},className:"inline-flex items-center gap-0.5 text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open login",t.jsx(jA,{className:"w-3 h-3"})]})]})}),I&&i&&t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsx("div",{className:"flex flex-wrap gap-1",children:A.tools.map(u=>t.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",title:u,children:u.split("__").pop()},u))})})]})});function vc(e,A){const{data:g}=Fc(e),s=l.useRef(!1);l.useEffect(()=>{g?.authenticated&&!s.current&&A(),s.current=g?.authenticated??!1},[g?.authenticated,A])}const qc=l.memo(function(){const A=uA(f=>f.isExpanded),g=uA(f=>f.collapseSidebar),s=uA(f=>f.servers),o=uA(f=>f.loading),Q=uA(f=>f.authUrls),B=uA(f=>f.setAuthUrl),a=uA(f=>f.setLoading),r=uA(f=>f.setCopilotDevice),{isLoading:i}=fc(),E=Nc(),I=kc(),c=yc(),n=Gc(),C=bc(),[d,u]=l.useState(!1),[D,w]=l.useState(null),[h,m]=l.useState(null),k=sA(),y=l.useCallback(()=>{D&&(B(D,null),w(null),k.invalidateQueries({queryKey:["mcp","servers"]}))},[D,B,k]);vc(D,y),l.useEffect(()=>{for(const f of o)s.find(b=>b.name===f)?.connected&&a(f,!1)},[s,o,a]);const G=l.useCallback((f,N)=>{N.sessionId&&N.userCode&&N.verificationUri&&(r({sessionId:N.sessionId,userCode:N.userCode,verificationUri:N.verificationUri,interval:N.interval??5,serverName:f}),Ce(N.verificationUri))},[r]),M=l.useCallback(async f=>{try{a(f,!0);const N=await n.mutateAsync(f);if(N.authType==="copilot-device"){if(N.authenticated){a(f,!1),k.invalidateQueries({queryKey:["mcp","servers"]});return}G(f,N)}else N.authUrl?(B(f,N.authUrl),w(f),Ce(N.authUrl)):a(f,!1)}catch{a(f,!1),B(f,null)}},[n,B,a,G,k]),x=l.useCallback(async f=>{try{a(f,!0);const N=await E.mutateAsync(f);N.authType==="copilot-device"&&!N.connected?G(f,N):N.authRequired&&N.authUrl?(B(f,N.authUrl),w(f),Ce(N.authUrl)):a(f,!1)}catch{a(f,!1),B(f,null)}},[E,B,a,G]),F=l.useMemo(()=>[...s].sort((f,N)=>f.connected&&!N.connected?-1:!f.connected&&N.connected?1:f.name.localeCompare(N.name)),[s]);if(!A)return null;const p=s.filter(f=>f.connected).length;return t.jsxs("div",{className:"w-80 border-l border-border bg-background flex flex-col h-full",children:[t.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ht,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium text-sm",children:"MCP Servers"}),p>0&&t.jsxs("span",{className:"text-xs bg-green-500/20 text-green-400 px-1.5 py-0.5 rounded-full",children:[p," active"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>u(!0),title:"Add MCP server",className:"h-7 w-7",children:t.jsx(fe,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"Close sidebar",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:i&&s.length===0?t.jsxs("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin mr-2"}),"Loading..."]}):s.length===0?t.jsxs("div",{className:"p-4 text-sm text-muted-foreground space-y-3",children:[t.jsx("p",{children:"No MCP servers configured."}),t.jsxs(_,{variant:"primary",size:"sm",onClick:()=>u(!0),className:"w-full",children:[t.jsx(fe,{className:"w-3 h-3 mr-1"}),"Add MCP Server"]}),t.jsxs("p",{className:"text-xs",children:["Or add servers to"," ",t.jsx("code",{className:"bg-muted px-1 py-0.5 rounded text-xs",children:".otto/config.json"})]})]}):t.jsx("div",{className:"p-2 space-y-1.5",children:F.map(f=>t.jsx(jc,{server:f,isLoading:o.has(f.name),authUrl:Q.get(f.name),copilotDevice:C?.serverName===f.name?C:null,onStart:()=>x(f.name),onStop:()=>I.mutate(f.name),onRemove:()=>m(f.name),onAuth:()=>M(f.name)},f.name))})}),t.jsx(Jc,{isOpen:d,onClose:()=>u(!1)}),t.jsxs(Me,{isOpen:!!h,onClose:()=>m(null),title:"Remove MCP Server",maxWidth:"sm",showCloseButton:!1,children:[t.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Are you sure you want to remove"," ",t.jsx("span",{className:"font-medium text-foreground",children:h}),"? This will stop the server and remove its configuration."]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(_,{variant:"secondary",size:"sm",onClick:()=>m(null),children:"Cancel"}),t.jsx(_,{variant:"primary",size:"sm",className:"bg-red-500 hover:bg-red-600 text-white",onClick:()=>{h&&c.mutate(h),m(null)},children:"Remove"})]})]})]})}),Oc=l.memo(function(){const A=uA(Q=>Q.isExpanded),g=uA(Q=>Q.toggleSidebar),o=uA(Q=>Q.servers).filter(Q=>Q.connected).length;return t.jsxs("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"MCP Servers",children:[t.jsx(ht,{className:"w-5 h-5 text-muted-foreground mx-auto"}),o>0&&t.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full"})]})}),Lo="file-browser",jo=320,Tc=280,Yc=600;function Hc({dirPath:e}){const g=mA(Q=>Q.expandedDirs).has(e),{data:s,isLoading:o}=hB(e,g);return g?o?t.jsx("div",{className:"pl-4 py-1 text-xs text-muted-foreground",children:"Loading..."}):t.jsx("div",{className:"pl-3",children:s?.items.map(Q=>t.jsx(UB,{name:Q.name,path:Q.path,type:Q.type},Q.path))}):null}function UB({name:e,path:A,type:g}){const s=mA(E=>E.expandedDirs),o=mA(E=>E.toggleDir),Q=mA(E=>E.openFile),B=mA(E=>E.selectedFile),a=s.has(A),r=B===A,i=l.useCallback(()=>{g==="directory"?o(A):Q(A)},[g,A,o,Q]);return t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:i,className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-sm hover:bg-muted/50 rounded transition-colors ${r?"bg-muted text-foreground":"text-foreground/80"}`,children:[g==="directory"?t.jsxs(t.Fragment,{children:[a?t.jsx(PA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}):t.jsx(xA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),a?t.jsx(zo,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}):t.jsx(Vo,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3 flex-shrink-0"}),t.jsx(rs,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"})]}),t.jsx("span",{className:"truncate",children:e})]}),g==="directory"&&t.jsx(Hc,{dirPath:A})]})}const Pc=l.memo(function(){const A=mA(a=>a.isExpanded),g=mA(a=>a.collapseSidebar),s=Ue(a=>a.widths[Lo]??jo),{data:o,isLoading:Q,refetch:B}=hB(".");return A?t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:s},children:[t.jsx(et,{panelKey:Lo,side:"right",minWidth:Tc,maxWidth:Yc,defaultWidth:jo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(lt,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium",children:"Files"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-1",children:Q?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading file tree..."}):!o||o.items.length===0?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No files found"}):o.items.map(a=>t.jsx(UB,{name:a.name,path:a.path,type:a.type},a.path))}),t.jsxs("div",{className:"h-12 px-4 border-t border-border text-xs text-muted-foreground flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[t.jsx(lt,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:"Project Files"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>B(),title:"Refresh file tree",className:"h-6 w-6 flex-shrink-0",disabled:Q,children:t.jsx(HA,{className:`w-3 h-3 ${Q?"animate-spin":""}`})})]})]})]}):null}),Wc=l.memo(function(){const A=mA(s=>s.isExpanded),g=mA(s=>s.toggleSidebar);return t.jsx("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Files",children:t.jsx(lt,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),zc={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",svelte:"svelte",toml:"toml",lock:"plaintext"};function Vc(e){const A=e.split(".").pop()?.toLowerCase()??"";return zc[A]??"plaintext"}const Zc=l.memo(function(){const A=mA(r=>r.isViewerOpen),g=mA(r=>r.selectedFile),s=mA(r=>r.closeViewer),{data:o,isLoading:Q}=fl(g);if(l.useEffect(()=>{const r=i=>{const E=i.target,I=E.tagName==="INPUT"||E.tagName==="TEXTAREA"||E.isContentEditable;(i.key==="Escape"||i.key==="q"&&!I)&&A&&s()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[A,s]),!A||!g)return null;const B=document?.documentElement.classList.contains("dark")?ce:de,a=Vc(g);return t.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:s,title:"Close file viewer (ESC)",children:t.jsx(kA,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:g,children:g}),o&&t.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[o.lineCount," lines"]})]}),t.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:Q?t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading file..."}):o?t.jsx("div",{className:"code-with-line-numbers",children:t.jsx(WA,{language:a,style:B,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:o.content})}):t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),Xc=l.memo(function({authStatus:A,onSetupWallet:g,onImportWallet:s,onAddProvider:o,onRemoveProvider:Q,onStartOAuth:B,onStartOAuthManual:a,onExchangeOAuthCode:r,onOpenTopup:i,onNext:E,manageMode:I=!1,onClose:c,hideHeader:n=!1,onStartCopilotDeviceFlow:C,onPollCopilotDeviceFlow:d}){const[u,D]=l.useState(!1),[w,h]=l.useState(!1),[m,k]=l.useState(!1),[y,G]=l.useState(""),[M,x]=l.useState(!1),[F,p]=l.useState(null),[f,N]=l.useState(null),[b,S]=l.useState(""),[O,L]=l.useState(null),[R,j]=l.useState(null),[J,H]=l.useState(null),[z,AA]=l.useState(""),[tA,lA]=l.useState(!1),[yA,P]=l.useState(!1),[oA,T]=l.useState(null),[cA,bA]=l.useState(!1),[q,BA]=l.useState(null),[YA,NA]=l.useState(!1),[ee,JA]=l.useState(!1),[ye,me]=l.useState(!1),re=l.useRef(void 0),oe=l.useRef(!1),Je=l.useRef(d);Je.current=d;const he=IA(Y=>Y.balance),W=IA(Y=>Y.usdcBalance),aA=IA(Y=>Y.isLoading),EA=l.useRef(null),RA=l.useRef(null),te=l.useRef(null),Re=IA(Y=>Y.isTopupModalOpen),VA=l.useRef(!1),{fetchBalance:Qe}=dg("setu");l.useEffect(()=>{VA.current&&!Re&&Qe(),VA.current=Re},[Re,Qe]),l.useEffect(()=>{!A.setu.configured&&!w&&(h(!0),g().finally(()=>h(!1)))},[A.setu.configured,g,w]),l.useEffect(()=>{f&&EA.current&&EA.current.focus()},[f]),l.useEffect(()=>{J&&RA.current&&RA.current.focus()},[J]),l.useEffect(()=>{m&&te.current&&te.current.focus()},[m]),l.useEffect(()=>{if(!cA||!oA||!Je.current)return;oe.current=!1;const Y=Math.max((oA.interval||5)*1e3+2e3,7e3),UA=()=>{re.current=setTimeout(async()=>{if(!oe.current)try{const Ss=Je.current;if(!Ss)return;const fg=await Ss(oA.sessionId);if(oe.current)return;fg.status==="complete"?(T(null),bA(!1),BA(null),JA(!1)):fg.status==="error"?(BA(fg.error||"Authorization failed"),bA(!1)):UA()}catch{oe.current||UA()}},Y)};UA();const Ee=setTimeout(()=>{bA(!1),BA("Authorization timed out. Please try again.")},3e5);return()=>{oe.current=!0,re.current&&clearTimeout(re.current),clearTimeout(Ee)}},[cA,oA]);const Ge=async()=>{A.setu.publicKey&&(await navigator.clipboard.writeText(A.setu.publicKey),D(!0),setTimeout(()=>D(!1),2e3))},yt=Y=>`${Y.slice(0,8)}...${Y.slice(-6)}`,ot=async Y=>{if(b.trim())try{await o(Y,b.trim()),N(null),S("")}catch{}},Gt=async Y=>{if(R===Y){L(Y);try{await Q(Y)}finally{L(null),j(null)}}else j(Y)},pg=()=>{j(null)},Qt=async(Y,UA)=>{Y==="anthropic"?H({provider:Y,sessionId:null,mode:UA}):Y==="copilot"&&C?(BA(null),JA(!0),me(!0),C().then(Ee=>{T(Ee),me(!1)}).catch(Ee=>{BA(Ee instanceof Error?Ee.message:"Failed to start device flow"),me(!1)})):B(Y,UA)},Le=async()=>{if(J){P(!0);try{const{sessionId:Y}=await a(J.provider,J.mode);H({...J,sessionId:Y})}catch(Y){console.error("Failed to start OAuth:",Y)}P(!1)}},Ft=async()=>{if(!(!J||!J.sessionId||!z.trim())){lA(!0);try{await r(J.provider,z.trim(),J.sessionId),H(null),AA("")}catch{}lA(!1)}},Bt=()=>{H(null),AA("")},wg=()=>{oA&&(Ce(oA.verificationUri),bA(!0))},mg=async()=>{oA&&(await navigator.clipboard.writeText(oA.userCode),NA(!0),setTimeout(()=>NA(!1),2e3))},xg=()=>{T(null),bA(!1),BA(null),NA(!1),JA(!1),me(!1),oe.current=!0,re.current&&(clearTimeout(re.current),re.current=void 0)},at=()=>{p(null),G(""),k(!0)},$=()=>{M||(k(!1),p(null),G(""))},Be=async()=>{if(!(!y.trim()||M)){x(!0),p(null);try{await s(y.trim()),k(!1),G(""),Qe()}catch(Y){p(Y instanceof Error?Y.message:"Failed to import wallet")}finally{x(!1)}}},bt=Object.entries(A.providers).filter(([Y,UA])=>UA.configured&&Y!=="setu"),LB=Object.entries(A.providers).filter(([Y,UA])=>!UA.configured&&Y!=="setu");return t.jsxs("div",{className:"min-h-screen flex flex-col",children:[!n&&t.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),!I&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),"Step 1 of 2"]})]}),t.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${n?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:"mb-10",children:[t.jsx("h1",{className:"text-2xl sm:text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:I?"Manage Providers":"Welcome to otto"}),t.jsx("p",{className:"text-lg text-muted-foreground max-w-2xl",children:I?"Add or remove AI providers. Your changes are saved automatically.":"Setu is your default AI provider, powered by your wallet. Add more providers below if you'd like."})]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 sm:gap-8",children:[t.jsx("div",{children:t.jsx("div",{className:"bg-card rounded-2xl border border-border p-5",children:A.setu.configured&&A.setu.publicKey?t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-green-500/10 border border-green-500/20 rounded-lg",children:[t.jsx(ZA,{provider:"setu",size:16}),t.jsx("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:"Setu"}),t.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60 ml-auto",children:"Default Provider"})]}),t.jsx("div",{className:"flex justify-center py-4 mt-4",children:t.jsx("div",{className:"bg-white p-2 rounded-lg",children:t.jsx(hg,{value:A.setu.publicKey,size:140,level:"M"})})}),t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("button",{type:"button",onClick:Ge,className:"w-full flex items-center justify-center gap-2 px-3 py-2 bg-muted hover:bg-muted/80 rounded-lg text-xs font-mono text-muted-foreground transition-colors",children:[yt(A.setu.publicKey),u?t.jsx(Ae,{className:"w-3.5 h-3.5 text-green-500"}):t.jsx(Ye,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/50 rounded-lg",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs("span",{className:"font-mono text-sm text-foreground",children:["$",((he??0)+(W??0)).toFixed(2)]}),t.jsx("button",{type:"button",onClick:Qe,disabled:aA,className:"p-0.5 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:t.jsx(HA,{className:`w-3 h-3 ${aA?"animate-spin":""}`})})]}),t.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[(he??0)>0&&`${(he??0).toFixed(2)} cr`,(he??0)>0&&(W??0)>0&&" + ",(W??0)>0&&`${(W??0).toFixed(2)} usdc`]})]})]}),t.jsxs("div",{className:"flex items-center gap-4 py-4",children:[t.jsx("div",{className:"flex-1 h-px bg-border"}),t.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"OR"}),t.jsx("div",{className:"flex-1 h-px bg-border"})]}),t.jsxs("button",{type:"button",onClick:i,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:bg-primary/90 transition-colors",children:[t.jsx(ct,{className:"w-4 h-4"}),"Pay via Card"]}),t.jsxs("button",{type:"button",onClick:at,className:"w-full mt-2 flex items-center justify-center gap-2 px-4 py-2.5 border border-border text-foreground rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors",children:[t.jsx(Zt,{className:"w-4 h-4"}),"Import Wallet"]})]}):t.jsx("div",{className:"flex items-center justify-center py-16",children:t.jsx(CA,{className:"w-8 h-8 animate-spin text-muted-foreground"})})})}),t.jsxs("div",{className:"sm:col-span-2 space-y-6",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsx("h2",{className:"font-semibold text-foreground",children:"Connected Providers"}),bt.length>0&&t.jsxs("span",{className:"text-sm text-muted-foreground",children:[bt.length," active"]})]}),bt.length===0?t.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"No providers connected yet. Add one below."}):t.jsx("div",{className:"flex flex-wrap gap-2",children:bt.map(([Y,UA])=>t.jsxs("div",{className:`flex items-center gap-2 pl-3 pr-2 py-2 rounded-full transition-all duration-200 ${R===Y?"bg-destructive/10 border border-destructive/30":"group bg-green-500/10 border border-green-500/20"}`,children:[t.jsx(ZA,{provider:Y,size:16}),t.jsx("span",{className:`text-sm font-medium transition-colors ${R===Y?"text-destructive":"text-green-600 dark:text-green-400"}`,children:UA.label}),R!==Y&&t.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60",children:UA.type==="oauth"?"OAuth":"API"}),R===Y?t.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[t.jsx("span",{className:"text-xs text-destructive/80 mr-1",children:"Remove?"}),t.jsx("button",{type:"button",onClick:()=>Gt(Y),disabled:O===Y,className:"px-2 py-0.5 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors disabled:opacity-50",children:O===Y?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):"Yes"}),t.jsx("button",{type:"button",onClick:pg,className:"px-2 py-0.5 text-xs bg-muted text-muted-foreground rounded hover:bg-muted/80 transition-colors",children:"No"})]}):Y!=="setu"&&t.jsx("button",{type:"button",onClick:()=>Gt(Y),className:"ml-1 p-1 text-green-600/40 dark:text-green-500/40 hover:text-green-600/80 dark:hover:text-green-500/80 opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(kA,{className:"w-3 h-3"})})]},Y))})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"font-semibold text-foreground mb-4",children:"Add Providers"}),t.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 items-start",children:LB.map(([Y,UA])=>t.jsx("div",{children:f===Y?t.jsxs("div",{className:"flex items-center gap-2 p-3 bg-card border border-ring rounded-xl overflow-hidden",children:[t.jsx("div",{className:"shrink-0",children:t.jsx(ZA,{provider:Y,size:18})}),t.jsx("input",{ref:EA,type:"password",value:b,onChange:Ee=>S(Ee.target.value),placeholder:`${UA.label} API key...`,className:"flex-1 min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground text-foreground",onKeyDown:Ee=>{Ee.key==="Enter"&&ot(Y),Ee.key==="Escape"&&(N(null),S(""))}}),t.jsx("button",{type:"button",onClick:()=>ot(Y),disabled:!b.trim(),className:"shrink-0 px-3 py-1.5 bg-primary text-primary-foreground text-sm font-medium rounded-lg disabled:opacity-50",children:"Add"}),t.jsx("button",{type:"button",onClick:()=>{N(null),S("")},className:"shrink-0 p-1.5 text-muted-foreground hover:text-foreground",children:t.jsx(kA,{className:"w-4 h-4"})})]}):t.jsxs("div",{className:"flex items-center justify-between p-3 bg-card border border-border hover:border-border/80 rounded-xl transition-colors gap-2",children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx(ZA,{provider:Y,size:20}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium text-foreground truncate",children:UA.label}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[UA.modelCount," models"]})]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[Y!=="copilot"&&t.jsxs("button",{type:"button",onClick:()=>N(Y),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[t.jsx(Zt,{className:"w-3.5 h-3.5"}),"API"]}),UA.supportsOAuth&&t.jsxs("button",{type:"button",onClick:()=>Qt(Y,Y==="anthropic"?"max":void 0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[t.jsx(jA,{className:"w-3.5 h-3.5"}),Y==="anthropic"?"Pro":Y==="copilot"?"Login":"OAuth"]})]})]})},Y))})]})]})]})]})}),t.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:t.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[!I&&t.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground hidden sm:block",children:"You can add more providers later in settings"}),I?t.jsx("button",{type:"button",onClick:c,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors ml-auto",children:"Done"}):t.jsxs("button",{type:"button",onClick:E,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors",children:["Continue",t.jsx(Zo,{className:"w-4 h-4"})]})]})}),m&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("h3",{className:"text-lg font-semibold",children:"Import Setu Wallet"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste your base58 private key to replace the current wallet."}),t.jsx("textarea",{ref:te,value:y,onChange:Y=>G(Y.target.value),placeholder:"Enter private key",className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors font-mono text-xs resize-y",onKeyDown:Y=>{(Y.metaKey||Y.ctrlKey)&&Y.key==="Enter"&&(Y.preventDefault(),Be()),Y.key==="Escape"&&$()}}),F&&t.jsx("p",{className:"text-sm text-red-500 mt-3",children:F}),t.jsxs("div",{className:"flex gap-3 mt-5",children:[t.jsx("button",{type:"button",onClick:$,disabled:M,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Be,disabled:!y.trim()||M,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:M?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):"Import Wallet"})]})]})]})}),J&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:J.provider,size:24}),t.jsxs("h3",{className:"text-lg font-semibold",children:["Connect"," ",A.providers[J.provider]?.label||J.provider]})]}),J.sessionId?t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste the authorization code:"}),t.jsx("input",{type:"text",ref:RA,value:z,onChange:Y=>AA(Y.target.value),placeholder:"Paste code here...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors mb-4 font-mono text-sm",onKeyDown:Y=>{Y.key==="Enter"&&Ft(),Y.key==="Escape"&&Bt()}}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:Bt,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Ft,disabled:!z.trim()||tA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:tA?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):"Connect"})]})]}):t.jsxs("div",{className:"p-6",children:[t.jsxs("p",{className:"text-sm text-muted-foreground mb-6",children:["You'll be redirected to"," ",A.providers[J.provider]?.label||J.provider," ","to authorize access. After authorizing, copy the code and return here."]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:Bt,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Le,disabled:yA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:yA?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsxs(t.Fragment,{children:["Continue",t.jsx(jA,{className:"w-4 h-4"})]})})]})]})]})}),ee&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:"copilot",size:24}),t.jsx("h3",{className:"text-lg font-semibold",children:"Connect GitHub Copilot"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Enter this code on GitHub to authorize:"}),t.jsx("div",{className:"flex items-center justify-center gap-3 mb-6",children:ye?t.jsx("div",{className:"bg-muted px-6 py-3 rounded-lg animate-pulse",children:t.jsx("div",{className:"h-9 w-48 bg-muted-foreground/20 rounded"})}):oA?t.jsxs(t.Fragment,{children:[t.jsx("code",{className:"text-3xl font-mono font-bold tracking-widest text-foreground bg-muted px-6 py-3 rounded-lg select-all",children:oA.userCode}),t.jsx("button",{type:"button",onClick:mg,className:"p-2 text-muted-foreground hover:text-foreground transition-colors",children:YA?t.jsx(Ae,{className:"w-5 h-5 text-green-500"}):t.jsx(Ye,{className:"w-5 h-5"})})]}):null}),q&&t.jsx("p",{className:"text-sm text-red-500 mb-4 text-center",children:q}),cA&&t.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground mb-4",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Waiting for authorization..."]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:xg,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:wg,disabled:cA||ye,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:cA||ye?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsxs(t.Fragment,{children:["Open GitHub",t.jsx(jA,{className:"w-4 h-4"})]})})]})]})]})})]})}),_c=l.memo(function({authStatus:A,onComplete:g,onBack:s,hideHeader:o=!1}){const[Q,B]=l.useState(null),[a,r]=l.useState(null),[i,E]=l.useState(!0),[I,c]=l.useState(!1),[n,C]=l.useState("setu"),[d,u]=l.useState("kimi-k2.5"),[D,w]=l.useState(A.defaults.agent||"build"),[h,m]=l.useState(A.defaults.toolApproval||"auto"),[k,y]=l.useState(!1),G=l.useRef(!1),M=l.useId(),x=l.useId(),F=l.useId(),p=l.useId();l.useEffect(()=>{(async()=>{try{const[O,L]=await Promise.all([v.getConfig(),v.getAllModels()]);B(O),r(L);const R=O?.defaults?.provider||"setu",j=O?.defaults?.model||"kimi-k2.5",J=L?.[R]?.models?.length>0,H=J?R:"setu",z=J&&L[R].models.some(AA=>AA.id===j)?j:L?.[H]?.models?.[0]?.id||"kimi-k2.5";C(H),u(z),O?.defaults?.agent&&w(O.defaults.agent),O?.defaults?.toolApproval&&m(O.defaults.toolApproval),O?.defaults?.guidedMode&&y(O.defaults.guidedMode)}catch{}finally{E(!1)}})()},[]),l.useEffect(()=>{if(Q?.agents?.length){const S=Q.agents;(!D||!S.includes(D))&&w(S.includes("build")?"build":S[0])}},[Q,D]),l.useEffect(()=>{if(a?.[n]&&G.current){const S=a[n];S.models.some(O=>O.id===d)||u(S.models[0]?.id||"")}},[n,a,d]);const f=async()=>{c(!0);try{await v.updateDefaults({provider:n,model:d,agent:D,toolApproval:h,guidedMode:k,scope:"global"}),await g()}catch{}finally{c(!1)}};if(i)return t.jsx("div",{className:"min-h-screen flex items-center justify-center",children:t.jsx(CA,{className:"w-8 h-8 animate-spin text-muted-foreground"})});const N=Q?.providers.filter(S=>(A.providers[S]?.configured||S==="setu")&&a?.[S]?.models?.length>0)||["setu"],b=a?.[n]?.models||[];return t.jsxs("div",{className:"min-h-screen flex flex-col",children:[!o&&t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"}),"Step 2 of 2"]})]}),t.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${o?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:"mb-10",children:[t.jsx("h1",{className:"text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:"Configure Defaults"}),t.jsx("p",{className:"text-lg text-muted-foreground",children:"Set your preferences. You can change these anytime in settings."})]}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[t.jsxs("div",{className:"md:col-span-2",children:[t.jsx("label",{htmlFor:M,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Provider"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:M,value:n,onChange:S=>{G.current=!0,C(S.target.value)},className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:N.map(S=>t.jsx("option",{value:S,children:A.providers[S]?.label||S},S))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{className:"md:col-span-2",children:[t.jsx("label",{htmlFor:x,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Model"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:x,value:d,onChange:S=>u(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:b.map(S=>t.jsx("option",{value:S.id,children:S.label||S.id},S.id))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:F,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Agent"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:F,value:D,onChange:S=>w(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:(Q?.agents||["build"]).map(S=>t.jsx("option",{value:S,children:S},S))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:p,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Tool Approval"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{id:p,value:h,onChange:S=>m(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:[t.jsx("option",{value:"auto",children:"Auto - run without asking"}),t.jsx("option",{value:"dangerous",children:"Dangerous - approve writes only"}),t.jsx("option",{value:"all",children:"All - approve every tool"})]}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]}),t.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Controls when tool executions need approval"})]}),t.jsx("div",{className:"md:col-span-2",children:t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-card border border-border rounded-xl",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Guided Mode"}),t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"AI will run commands and manage services for you instead of giving instructions"})]}),t.jsx("button",{type:"button",role:"switch","aria-checked":k,onClick:()=>y(!k),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${k?"bg-primary":"bg-muted"}`,children:t.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${k?"translate-x-6":"translate-x-1"} ${k?"bg-primary-foreground":"bg-foreground"}`})})]})})]})]})}),t.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:t.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-2 px-4 py-3 text-muted-foreground hover:text-foreground transition-colors",children:[t.jsx(ka,{className:"w-4 h-4"}),"Back"]}),t.jsx("button",{type:"button",onClick:f,disabled:I,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:I?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Setting up..."]}):t.jsxs(t.Fragment,{children:["Start Using otto",t.jsx(Te,{className:"w-4 h-4"})]})})]})})]})}),$c=l.memo(function({hideHeader:A=!1}){const g=LA(m=>m.isOpen),s=LA(m=>m.currentStep),o=LA(m=>m.manageMode),Q=LA(m=>m.authStatus),B=LA(m=>m.nextStep),a=LA(m=>m.prevStep),r=LA(m=>m.reset),i=IA(m=>m.openTopupModal),{setupWallet:E,importWallet:I,addProvider:c,removeProvider:n,completeOnboarding:C,startOAuth:d,startOAuthManual:u,exchangeOAuthCode:D,startCopilotDeviceFlow:w,pollCopilotDeviceFlow:h}=bs();return!g||!Q?null:t.jsxs("div",{className:"fixed inset-0 z-[9999] bg-background text-foreground overflow-y-auto",children:[s==="wallet"&&t.jsx(Xc,{authStatus:Q,onSetupWallet:E,onImportWallet:I,onAddProvider:c,onRemoveProvider:n,onStartOAuth:d,onStartOAuthManual:u,onExchangeOAuthCode:D,onOpenTopup:i,onNext:B,manageMode:o,onClose:r,hideHeader:A,onStartCopilotDeviceFlow:w,onPollCopilotDeviceFlow:h}),s==="defaults"&&t.jsx(_c,{authStatus:Q,onComplete:C,onBack:a,hideHeader:A})]})}),SB="otto-theme";function Ad(){if(typeof window>"u")return"dark";const e=window.localStorage.getItem(SB);return e==="light"||e==="dark"?e:window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function ed(){const[e,A]=l.useState(()=>Ad());l.useEffect(()=>{if(typeof document>"u")return;const s=document.documentElement;e==="dark"?s.classList.add("dark"):s.classList.remove("dark");try{window.localStorage.setItem(SB,e)}catch(o){console.warn("Failed to persist theme preference",o)}window.parent&&window.parent!==window&&window.parent.postMessage({type:"otto-set-theme",theme:e},"*")},[e]),l.useEffect(()=>{if(typeof window>"u")return;const s=o=>{o.data?.type==="otto-set-theme"&&(o.data.theme==="light"||o.data.theme==="dark")&&A(o.data.theme)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[]);const g=l.useCallback(()=>{A(s=>s==="dark"?"light":"dark")},[]);return l.useMemo(()=>({theme:e,setTheme:A,toggleTheme:g}),[e,g])}function td(){const[e,A]=l.useState(null);return l.useEffect(()=>{(async()=>{try{const Q=`${window.OTTO_SERVER_URL||TA}/v1/config/cwd`;console.log("[useWorkingDirectory] Fetching from:",Q);const B=await fetch(Q);if(!B.ok)throw console.error("[useWorkingDirectory] Failed:",B.status,B.statusText),new Error(`Failed to fetch working directory: ${B.status}`);const a=await B.json();console.log("[useWorkingDirectory] Success:",a),a.dirName&&(console.log("[useWorkingDirectory] Setting title to:",a.dirName),A(a.dirName),document.title=a.dirName)}catch(s){console.error("[useWorkingDirectory] Error:",s),document.title="otto"}})()},[]),e}function gd({sessionIds:e,activeSessionId:A,gitFiles:g,onSelectSession:s,onNewSession:o,onStageFile:Q,onUnstageFile:B,onRestoreFile:a,onDeleteFile:r,onStageAll:i,onUnstageAll:E,onOpenCommitModal:I,onViewDiff:c,onReturnToInput:n}){const{currentFocus:C,sessionIndex:d,gitFileIndex:u,setFocus:D,setSessionIndex:w,setGitFileIndex:h,resetGitFileIndex:m}=Fs(),{setCollapsed:k,toggleCollapse:y}=ze(),{isExpanded:G,toggleSidebar:M}=rA(),x=rA(N=>N.closeDiff),F=SA(N=>N.toggleSidebar),p=e.indexOf(A||""),f=l.useCallback(N=>{const b=N.target,S=b.tagName==="INPUT"||b.tagName==="TEXTAREA"||b.isContentEditable,O=!!b.closest("[data-terminal-viewer]");if((N.ctrlKey||N.metaKey)&&N.key==="h"){N.preventDefault(),C==="sessions"?(document.activeElement?.blur(),D("input"),k(!0),setTimeout(()=>n?.(),50)):C==="git"?(document.activeElement?.blur(),D("input"),M(),x(),setTimeout(()=>n?.(),50)):(document.activeElement?.blur(),D("sessions"),k(!1),p>=0&&w(p));return}if((N.ctrlKey||N.metaKey)&&N.key==="l"){N.preventDefault(),C==="git"?(document.activeElement?.blur(),D("input"),M(),x(),setTimeout(()=>n?.(),50)):C==="sessions"?(document.activeElement?.blur(),D("input"),k(!0),setTimeout(()=>n?.(),50)):(document.activeElement?.blur(),G||M(),D("git"),m());return}if((N.ctrlKey||N.metaKey)&&N.key==="/"){N.preventDefault(),y();return}if((N.ctrlKey||N.metaKey)&&N.key==="\\"){N.preventDefault(),M();return}if((N.ctrlKey||N.metaKey)&&N.shiftKey&&N.key==="r"){N.preventDefault(),F();return}if((N.ctrlKey||N.metaKey)&&N.key==="n"){N.preventDefault(),o();return}if(N.key==="Escape"&&!O||N.key==="q"&&!S&&(C==="sessions"||C==="git")){N.preventDefault(),C==="sessions"?k(!0):C==="git"&&(M(),x()),D("input"),n?.();return}if(C==="sessions"&&!S){if(N.key==="j"&&e.length>0){N.preventDefault();const L=Math.min(d+1,e.length-1);w(L);return}if(N.key==="k"&&e.length>0){N.preventDefault();const L=Math.max(d-1,0);w(L);return}if(N.key==="Enter"&&e[d]){N.preventDefault(),s(e[d]),D("input");return}}if(C==="git"&&!S){if(N.key==="j"&&g.length>0){N.preventDefault();const L=Math.min(u+1,g.length-1);h(L);return}if(N.key==="k"&&g.length>0){N.preventDefault();const L=Math.max(u-1,0);h(L);return}if(N.key===" "&&g[u]){N.preventDefault();const L=g[u];L.staged?B?.(L.path):Q?.(L.path);return}if(N.key==="a"){N.preventDefault(),i?.();return}if(N.key==="u"){N.preventDefault(),E?.();return}if(N.key==="R"&&g[u]){N.preventDefault();const L=g[u];!L.staged&&L.status!=="untracked"&&L.status!=="added"&&a?.(L.path);return}if(N.shiftKey&&N.key==="D"||N.key==="Backspace"){N.preventDefault();const L=g[u];L&&!L.staged&&L.status==="untracked"&&r?.(L.path);return}if(N.key==="c"){N.preventDefault(),I?.();return}if(N.key==="Enter"&&g[u]){N.preventDefault();const L=g[u];c?.(L.path,L.staged);return}}},[C,d,u,e,g,p,G,D,w,h,m,k,M,F,y,s,o,Q,B,a,r,i,E,I,c,n,x]);return l.useEffect(()=>(window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)),[f]),{currentFocus:C,sessionIndex:d,gitFileIndex:u}}function sd(e){const A=l.useRef(null),g=l.useRef(null),s=IA(i=>i.setBalance),o=IA(i=>i.setPaymentPending),Q=Ie(i=>i.removeToast),B=Ie(i=>i.updateToast),a=tg(i=>i.setPendingTopup),r=tg(i=>i.clearPendingTopup);l.useEffect(()=>{if(!e)return;const i=new dB;A.current=i;const E=v.getStreamUrl(e);i.connect(E);const I=i.on("*",c=>{const n=c.payload;switch(c.type){case"setu.topup.required":{const C=typeof n?.amountUsd=="number"?n.amountUsd:0,d=typeof n?.currentBalance=="number"?n.currentBalance:0,u=typeof n?.minTopupUsd=="number"?n.minTopupUsd:5,D=typeof n?.suggestedTopupUsd=="number"?n.suggestedTopupUsd:10,w=typeof n?.messageId=="string"?n.messageId:"";a({sessionId:e,messageId:w,amountUsd:C,currentBalance:d,minTopupUsd:u,suggestedTopupUsd:D});break}case"setu.topup.method_selected":{n?.method==="crypto"&&(o(!0),g.current=QA.loading("💳 Processing crypto payment..."));break}case"setu.topup.cancelled":{r();const C=typeof n?.reason=="string"?n.reason:"Request cancelled";QA(`⚠️ ${C}`);break}case"setu.payment.required":{const C=typeof n?.amountUsd=="number"?n.amountUsd:0;o(!0),g.current||(g.current=QA.loading(`💳 Payment required: $${C.toFixed(2)}`));break}case"setu.payment.signing":{g.current?B(g.current,{message:"✍️ Signing transaction..."}):g.current=QA.loading("✍️ Signing transaction...");break}case"setu.payment.complete":{r();const C=n?.amountUsd,d=n?.newBalance,u=typeof n?.transactionId=="string"?n.transactionId:void 0,D=typeof C=="number"?C:typeof C=="string"?parseFloat(C):0,w=typeof d=="number"?d:typeof d=="string"?parseFloat(d):0;s(w),o(!1),g.current&&(Q(g.current),g.current=null);const h=`✅ Paid $${D.toFixed(2)}`;u?QA.successWithAction(h,{label:"View Tx",href:`https://orbmarkets.io/tx/${u}`}):QA.success(h);break}case"setu.fiat.checkout_created":{r(),o(!1),g.current&&(Q(g.current),g.current=null),QA.success("💳 Complete payment, then retry your message");break}case"setu.balance.updated":{const C=n?.balanceRemaining,d=typeof C=="number"?C:typeof C=="string"?parseFloat(C):null;d!==null&&!Number.isNaN(d)&&s(d);break}case"setu.payment.error":{r();const C=typeof n?.error=="string"?n.error:"Payment failed";o(!1),g.current&&(Q(g.current),g.current=null),QA.error(`❌ ${C}`);break}}});return()=>{I(),i.disconnect()}},[e,s,o,Q,B,a,r])}const Dg=OB({component:od});function od(){const{checkOnboarding:e}=bs();return l.useEffect(()=>{e()},[e]),t.jsxs(t.Fragment,{children:[t.jsx(TB,{}),t.jsx($c,{}),t.jsx(Gs,{}),null]})}const Qd=os("/")({beforeLoad:()=>{throw YB({to:"/sessions"})},component:()=>null}),vo="left-sidebar",qo=256,Bd=256,ad=480,id=l.memo(function({children:A,onNewSession:g}){const s=rA(a=>a.isDiffOpen),o=ze(a=>a.isCollapsed),Q=ze(a=>a.toggleCollapse),B=Ue(a=>a.widths[vo]??qo);return l.useEffect(()=>(o?document.body.style.overflow="":document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[o]),o?t.jsxs("aside",{className:"w-12 md:w-12 border-r border-border bg-background flex flex-col transition-all duration-300 ease-in-out hidden md:flex",children:[t.jsx("div",{className:"h-14 border-b border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"New session",className:"rounded-full touch-manipulation",children:t.jsx(Ls,{className:"w-4 h-4"})})}),t.jsx("button",{type:"button",className:"flex-1 cursor-pointer hover:bg-muted/50 transition-colors touch-manipulation",onClick:s?void 0:Q,title:s?void 0:"Expand sidebar","aria-label":"Expand sidebar"}),t.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Expand sidebar",disabled:s,className:"transition-transform duration-200 hover:scale-110 touch-manipulation",children:t.jsx(Ma,{className:"w-4 h-4"})})})]}):t.jsxs(t.Fragment,{children:[!o&&t.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 md:hidden",onClick:Q,"aria-hidden":"true"}),t.jsxs("aside",{className:"border-r border-border bg-background flex transition-all duration-300 ease-in-out fixed md:relative top-0 left-0 z-50 h-screen md:h-auto w-full md:w-auto",style:{maxWidth:"100%"},children:[t.jsxs("div",{className:"flex-1 flex flex-col min-w-0",style:{width:B},children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-2 md:hidden bg-background",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Close menu",className:"touch-manipulation flex-shrink-0","aria-label":"Close menu",children:t.jsx(ya,{className:"w-5 h-5"})}),t.jsx("h1",{className:"text-lg font-semibold text-foreground flex-1",children:"otto"})]}),t.jsx("div",{className:"h-14 border-b border-border px-4 flex items-center gap-2",children:t.jsxs(_,{variant:"primary",size:"sm",onClick:g,className:"flex-1 touch-manipulation",children:[t.jsx(Ls,{className:"w-4 h-4 mr-2"}),"New Session"]})}),t.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-hide",children:A}),t.jsx("div",{className:"h-12 border-t border-border px-2 flex items-center justify-end",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Collapse sidebar",disabled:s,className:"transition-transform duration-200 hover:scale-110 touch-manipulation",children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-300",role:"img","aria-label":"Collapse sidebar",children:[t.jsx("title",{children:"Collapse sidebar"}),t.jsx("path",{d:"M15 18l-6-6 6-6"})]})})})]}),t.jsx("div",{className:"hidden md:block",children:t.jsx(et,{panelKey:vo,side:"left",minWidth:Bd,maxWidth:ad,defaultWidth:qo})})]})]})}),rd=l.memo(function({sidebar:A,children:g,onNewSession:s,theme:o,onToggleTheme:Q,sessionId:B,onNavigateToSession:a,onFixWithAI:r}){return t.jsxs("div",{className:"h-screen flex bg-background touch-manipulation border-t border-border/50",children:[t.jsx(id,{onNewSession:s,children:A}),t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden w-full md:w-auto",children:[t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[t.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[t.jsx(kl,{}),t.jsx(Ol,{}),t.jsx(Zc,{}),g]}),t.jsxs("div",{className:"hidden md:flex",children:[t.jsx(ml,{onFixWithAI:r}),t.jsx(Kl,{sessionId:B}),t.jsx(Zl,{parentSessionId:B??null,onNavigateToSession:a}),t.jsx(Ec,{}),t.jsx(wc,{}),t.jsx(Pc,{}),t.jsx(qc,{}),t.jsxs("div",{className:"flex flex-col w-12 border-l border-border bg-background",children:[t.jsx(xl,{}),t.jsx(Jl,{sessionId:B}),t.jsx(_l,{parentSessionId:B}),t.jsx(Wc,{}),t.jsx(Cc,{}),t.jsx(mc,{}),t.jsx(Oc,{}),t.jsx("div",{className:"flex-1"}),t.jsx(NE,{}),t.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:`Switch to ${o==="dark"?"light":"dark"} mode`,"aria-label":`Switch to ${o==="dark"?"light":"dark"} mode`,className:"touch-manipulation",children:o==="dark"?t.jsx(Ga,{className:"w-4 h-4"}):t.jsx(Fa,{className:"w-4 h-4"})})})]})]})]}),t.jsx(fE,{})]}),t.jsx(Ml,{}),t.jsx(ME,{})]})});function KB({sessionId:e}){const A=l.useRef(null),g=BC(),{data:s}=Ig(),{theme:o,toggleTheme:Q}=ed(),{openCommitModal:B,openDiff:a}=rA(),r=HB(),{data:i=[]}=Cg(),{data:E}=lg(),I=cg(),c=ks(),n=tB(),C=gB(),d=ws(M=>M.openConfirmation);td(),sd(e),dg(s?.defaults?.provider);const u=l.useCallback(()=>{setTimeout(()=>{A.current?.focus()},100)},[]),D=l.useCallback(async()=>{try{const M=await g.mutateAsync({agent:s?.defaults.agent||"general",provider:s?.defaults.provider,model:s?.defaults.model});r({to:"/sessions/$sessionId",params:{sessionId:M.id},replace:!1}),u()}catch(M){console.error("Failed to create session:",M)}},[g,s,r,u]),w=l.useCallback(()=>{r({to:"/sessions"})},[r]),h=l.useCallback(M=>{r({to:"/sessions/$sessionId",params:{sessionId:M}}),u()},[r,u]),m=l.useCallback(async M=>{try{const x=await g.mutateAsync({agent:s?.defaults.agent||"general",provider:s?.defaults.provider,model:s?.defaults.model,title:"Fix Git Error"});r({to:"/sessions/$sessionId",params:{sessionId:x.id},replace:!1}),await v.sendMessage(x.id,{content:M})}catch(x){console.error("Failed to create fix session:",x)}},[g,s,r]),k=l.useMemo(()=>E?[...(E.conflicted??[]).map(M=>({path:M.path,staged:!1,status:M.status})),...E.staged.map(M=>({path:M.path,staged:!0,status:M.status})),...E.unstaged.map(M=>({path:M.path,staged:!1,status:M.status})),...E.untracked.map(M=>({path:M.path,staged:!1,status:M.status}))]:[],[E]),y=l.useMemo(()=>i.map(M=>M.id),[i]);gd({sessionIds:y,activeSessionId:e,gitFiles:k,onSelectSession:h,onNewSession:D,onStageFile:M=>I.mutate([M]),onUnstageFile:M=>c.mutate([M]),onRestoreFile:M=>n.mutate([M]),onDeleteFile:M=>{d({title:"Delete File",message:`Delete ${M}? This will permanently remove the untracked file.`,confirmLabel:"Delete",variant:"destructive",onConfirm:async()=>{await C.mutateAsync([M])}})},onStageAll:()=>{const M=k.filter(x=>!x.staged).map(x=>x.path);M.length>0&&I.mutate(M)},onUnstageAll:()=>{const M=k.filter(x=>x.staged).map(x=>x.path);M.length>0&&c.mutate(M)},onOpenCommitModal:B,onViewDiff:a,onReturnToInput:u}),l.useEffect(()=>{e&&u()},[e,u]);const G=l.useMemo(()=>e?t.jsxs(t.Fragment,{children:[t.jsx(rl,{sessionId:e,onSelectSession:h}),t.jsx(bC,{ref:A,sessionId:e,onNewSession:D,onDeleteSession:w})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a session or create a new one to start"}),[e,D,h,w]);return t.jsxs(t.Fragment,{children:[t.jsx(rd,{onNewSession:D,theme:o,onToggleTheme:Q,sessionId:e,onNavigateToSession:h,onFixWithAI:m,sidebar:t.jsx(nl,{activeSessionId:e,onSelectSession:h}),children:G}),t.jsx(bE,{})]})}const Ed=os("/sessions/")({component:nd});function nd(){return t.jsx(KB,{})}const JB=os("/sessions/$sessionId")({component:Cd});function Cd(){const{sessionId:e}=JB.useParams();return t.jsx(KB,{sessionId:e})}const Id=Qd.update({id:"/",path:"/",getParentRoute:()=>Dg}),ld=Ed.update({id:"/sessions/",path:"/sessions/",getParentRoute:()=>Dg}),cd=JB.update({id:"/sessions/$sessionId",path:"/sessions/$sessionId",getParentRoute:()=>Dg}),dd={IndexRoute:Id,SessionsSessionIdRoute:cd,SessionsIndexRoute:ld},ud=Dg._addFileChildren(dd)._addFileTypes(),hd=()=>{const g=(typeof globalThis<"u"?globalThis.OTTO_ROUTER_BASEPATH:void 0)??"/"??"/";if(!g||g==="/")return"/";const s=g.replace(/\/+$/,"")||"/";return s.startsWith("/")?s:`/${s}`},Dd=PB({routeTree:ud,basepath:hd()}),Us=new WB({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,structuralSharing:!0}}});Us.prefetchQuery({queryKey:["sessions"],queryFn:()=>v.getSessions()});Us.prefetchQuery({queryKey:["config"],queryFn:()=>v.getConfig()});function pd(){return t.jsx(zB,{client:Us,children:t.jsx(VB,{router:Dd})})}const RB=document.getElementById("root");if(!RB)throw new Error("Root element not found");jB.createRoot(RB).render(t.jsx(l.StrictMode,{children:t.jsx(pd,{})}));
130
+ API_KEY=sk-xxx`,rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: KEY=VALUE"})]})]}):t.jsxs(t.Fragment,{children:[t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"URL"}),t.jsx(Tt,{value:i,onChange:f=>E(f.target.value),placeholder:"e.g. https://mcp.linear.app/mcp",onKeyDown:f=>{f.key==="Enter"&&M()}})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Transport"}),t.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[t.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:I==="http"?"2px":"50%",right:I==="sse"?"2px":"50%"}}),t.jsx("button",{type:"button",onClick:()=>c("http"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${I==="http"?"text-foreground":"text-muted-foreground/50"}`,children:"HTTP (recommended)"}),t.jsx("button",{type:"button",onClick:()=>c("sse"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${I==="sse"?"text-foreground":"text-muted-foreground/50"}`,children:"SSE (legacy)"})]})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Headers"}),t.jsx("textarea",{value:n,onChange:f=>C(f.target.value),placeholder:"Authorization: Bearer xxx",rows:2,className:"w-full bg-muted border border-border rounded-md px-3 py-2 text-sm font-mono resize-none focus:outline-none focus:ring-1 focus:ring-primary"}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"One per line: Header-Name: value"})]}),t.jsx("p",{className:"text-xs text-muted-foreground",children:"For OAuth servers (Linear, Notion, etc.), leave headers empty and authenticate after adding."})]}),t.jsxs("div",{children:[t.jsx("div",{className:"text-sm font-medium mb-1",children:"Scope"}),t.jsxs("div",{className:"relative flex w-full rounded-lg border border-border bg-muted/50 p-0.5",children:[t.jsx("div",{className:"absolute top-0.5 bottom-0.5 rounded-md bg-background shadow-md border border-border transition-all duration-200 ease-in-out",style:{left:D==="global"?"2px":"50%",right:D==="project"?"2px":"50%"}}),t.jsxs("button",{type:"button",onClick:()=>w("global"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${D==="global"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(sQ,{className:"w-3 h-3"}),"All projects"]}),t.jsxs("button",{type:"button",onClick:()=>w("project"),className:`relative z-10 flex items-center justify-center gap-1.5 text-xs font-medium py-1.5 rounded-md flex-1 transition-colors duration-200 ${D==="project"?"text-foreground":"text-muted-foreground/50"}`,children:[t.jsx(oQ,{className:"w-3 h-3"}),"This project only"]})]}),t.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:D==="global"?"Saved to ~/.config/otto/config.json":"Saved to .otto/config.json (project-local)"})]}),h&&t.jsx("div",{className:"text-sm text-red-400 bg-red-500/10 px-3 py-2 rounded",children:h}),t.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[t.jsx(_,{variant:"ghost",onClick:G,children:"Cancel"}),t.jsx(_,{variant:"primary",onClick:M,disabled:k.isPending,children:k.isPending?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"w-3 h-3 animate-spin mr-1"}),"Adding..."]}):"Add Server"})]})]})})})}),Rc=l.memo(function({checked:A,loading:g,onChange:s,disabled:o}){return t.jsx("button",{type:"button",role:"switch","aria-checked":A,disabled:o||g,onClick:Q=>{Q.stopPropagation(),s()},className:`relative inline-flex h-5 w-9 flex-shrink-0 items-center rounded-full transition-colors duration-200 focus-visible:outline-none disabled:opacity-50 disabled:cursor-not-allowed ${A?"bg-green-500":"bg-muted-foreground/30"}`,children:t.jsx("span",{className:`inline-block h-3.5 w-3.5 rounded-full transition-transform duration-200 ${A?"translate-x-[18px]":"translate-x-[3px]"} ${g?"bg-transparent":"bg-white"}`,children:g&&t.jsx(CA,{className:"w-3.5 h-3.5 animate-spin text-white"})})})}),Lc=l.memo(function({userCode:A,verificationUri:g}){const[s,o]=l.useState(!1),Q=l.useCallback(()=>{navigator.clipboard.writeText(A).then(()=>{o(!0),setTimeout(()=>o(!1),2e3)})},[A]);return t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsxs("div",{className:"rounded-md bg-yellow-500/10 border border-yellow-500/20 p-2 space-y-1.5",children:[t.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[t.jsx(CA,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),t.jsx("span",{className:"text-yellow-500/80",children:"Enter code at GitHub:"})]}),t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx("code",{className:"text-sm font-mono font-bold text-yellow-400 tracking-wider",children:A}),t.jsx("button",{type:"button",onClick:Q,className:"text-yellow-500/60 hover:text-yellow-400 transition-colors",title:"Copy code",children:t.jsx(xa,{className:"w-3.5 h-3.5"})}),s&&t.jsx("span",{className:"text-xs text-green-400",children:"Copied!"})]}),t.jsxs("a",{href:g,target:"_blank",rel:"noopener noreferrer",onClick:B=>{B.preventDefault(),Ce(g)},className:"inline-flex items-center gap-1 text-xs text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open GitHub login",t.jsx(jA,{className:"w-3 h-3"})]})]})})}),jc=l.memo(function({server:A,isLoading:g,authUrl:s,copilotDevice:o,onStart:Q,onStop:B,onRemove:a,onAuth:r}){const[i,E]=l.useState(!1),I=A.connected&&A.tools.length>0,c=A.transport==="http"||A.transport==="sse",n=(!!s||!!o)&&!A.connected,C=l.useCallback(()=>{A.authRequired&&!A.connected?r():A.connected?B():Q()},[A.connected,A.authRequired,r,B,Q]),d=l.useCallback(()=>{I&&E(u=>!u)},[I]);return t.jsxs("div",{className:`rounded-lg border transition-colors duration-200 group ${A.connected?"border-green-500/30 bg-green-500/5":n?"border-yellow-500/30 bg-yellow-500/5":"border-border bg-transparent"}`,children:[t.jsxs("div",{className:"flex items-center gap-3 px-3 py-2.5",children:[t.jsx(Rc,{checked:A.connected,loading:g||n,onChange:C}),t.jsxs("div",{className:"flex-1 min-w-0",children:[t.jsxs("div",{className:"flex items-center gap-1.5",children:[t.jsx("span",{className:"text-sm font-medium truncate",children:A.name}),c&&t.jsx(He,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),A.authRequired&&!A.connected&&t.jsx(fa,{className:"w-3 h-3 text-yellow-500 flex-shrink-0"})]}),t.jsxs("div",{className:"flex items-center gap-1.5 mt-0.5",children:[t.jsx("span",{className:"text-xs text-muted-foreground truncate",children:c?A.url:`${A.command??""} ${A.args.join(" ")}`}),t.jsx("span",{className:"flex items-center flex-shrink-0 opacity-50",title:A.scope==="project"?"Project-local":"Global",children:A.scope==="project"?t.jsx(oQ,{className:"w-3 h-3"}):t.jsx(sQ,{className:"w-3 h-3"})})]})]}),t.jsxs("div",{className:"flex items-center gap-0.5 flex-shrink-0",children:[I&&t.jsxs("button",{type:"button",onClick:d,className:"flex items-center gap-0.5 text-xs text-muted-foreground hover:text-foreground px-1.5 py-1 rounded transition-colors",children:[t.jsx(Na,{className:"w-3 h-3"}),A.tools.length,i?t.jsx(PA,{className:"w-3 h-3"}):t.jsx(xA,{className:"w-3 h-3"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:a,title:"Remove server",className:"h-6 w-6 opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(dt,{className:"w-3 h-3 text-muted-foreground hover:text-red-400"})})]})]}),o&&!A.connected&&t.jsx(Lc,{userCode:o.userCode,verificationUri:o.verificationUri}),!o&&n&&s&&t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsxs("div",{className:"flex items-center gap-1.5 text-xs",children:[t.jsx(CA,{className:"w-3 h-3 animate-spin text-yellow-500 flex-shrink-0"}),t.jsx("span",{className:"text-yellow-500/80",children:"Waiting for auth..."}),t.jsxs("a",{href:s,target:"_blank",rel:"noopener noreferrer",onClick:u=>{u.preventDefault(),Ce(s)},className:"inline-flex items-center gap-0.5 text-yellow-400 hover:text-yellow-300 underline underline-offset-2",children:["Open login",t.jsx(jA,{className:"w-3 h-3"})]})]})}),I&&i&&t.jsx("div",{className:"px-3 pb-2.5 pt-0",children:t.jsx("div",{className:"flex flex-wrap gap-1",children:A.tools.map(u=>t.jsx("span",{className:"text-xs bg-muted px-1.5 py-0.5 rounded",title:u,children:u.split("__").pop()},u))})})]})});function vc(e,A){const{data:g}=Fc(e),s=l.useRef(!1);l.useEffect(()=>{g?.authenticated&&!s.current&&A(),s.current=g?.authenticated??!1},[g?.authenticated,A])}const qc=l.memo(function(){const A=uA(f=>f.isExpanded),g=uA(f=>f.collapseSidebar),s=uA(f=>f.servers),o=uA(f=>f.loading),Q=uA(f=>f.authUrls),B=uA(f=>f.setAuthUrl),a=uA(f=>f.setLoading),r=uA(f=>f.setCopilotDevice),{isLoading:i}=fc(),E=Nc(),I=kc(),c=yc(),n=Gc(),C=bc(),[d,u]=l.useState(!1),[D,w]=l.useState(null),[h,m]=l.useState(null),k=sA(),y=l.useCallback(()=>{D&&(B(D,null),w(null),k.invalidateQueries({queryKey:["mcp","servers"]}))},[D,B,k]);vc(D,y),l.useEffect(()=>{for(const f of o)s.find(b=>b.name===f)?.connected&&a(f,!1)},[s,o,a]);const G=l.useCallback((f,N)=>{N.sessionId&&N.userCode&&N.verificationUri&&(r({sessionId:N.sessionId,userCode:N.userCode,verificationUri:N.verificationUri,interval:N.interval??5,serverName:f}),Ce(N.verificationUri))},[r]),M=l.useCallback(async f=>{try{a(f,!0);const N=await n.mutateAsync(f);if(N.authType==="copilot-device"){if(N.authenticated){a(f,!1),k.invalidateQueries({queryKey:["mcp","servers"]});return}G(f,N)}else N.authUrl?(B(f,N.authUrl),w(f),Ce(N.authUrl)):a(f,!1)}catch{a(f,!1),B(f,null)}},[n,B,a,G,k]),x=l.useCallback(async f=>{try{a(f,!0);const N=await E.mutateAsync(f);N.authType==="copilot-device"&&!N.connected?G(f,N):N.authRequired&&N.authUrl?(B(f,N.authUrl),w(f),Ce(N.authUrl)):a(f,!1)}catch{a(f,!1),B(f,null)}},[E,B,a,G]),F=l.useMemo(()=>[...s].sort((f,N)=>f.connected&&!N.connected?-1:!f.connected&&N.connected?1:f.name.localeCompare(N.name)),[s]);if(!A)return null;const p=s.filter(f=>f.connected).length;return t.jsxs("div",{className:"w-80 border-l border-border bg-background flex flex-col h-full",children:[t.jsxs("div",{className:"h-14 flex items-center justify-between px-3 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(ht,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium text-sm",children:"MCP Servers"}),p>0&&t.jsxs("span",{className:"text-xs bg-green-500/20 text-green-400 px-1.5 py-0.5 rounded-full",children:[p," active"]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>u(!0),title:"Add MCP server",className:"h-7 w-7",children:t.jsx(fe,{className:"w-4 h-4"})}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"Close sidebar",children:t.jsx(xA,{className:"w-4 h-4"})})]})]}),t.jsx("div",{className:"flex-1 overflow-y-auto",children:i&&s.length===0?t.jsxs("div",{className:"flex items-center justify-center h-32 text-muted-foreground",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin mr-2"}),"Loading..."]}):s.length===0?t.jsxs("div",{className:"p-4 text-sm text-muted-foreground space-y-3",children:[t.jsx("p",{children:"No MCP servers configured."}),t.jsxs(_,{variant:"primary",size:"sm",onClick:()=>u(!0),className:"w-full",children:[t.jsx(fe,{className:"w-3 h-3 mr-1"}),"Add MCP Server"]}),t.jsxs("p",{className:"text-xs",children:["Or add servers to"," ",t.jsx("code",{className:"bg-muted px-1 py-0.5 rounded text-xs",children:".otto/config.json"})]})]}):t.jsx("div",{className:"p-2 space-y-1.5",children:F.map(f=>t.jsx(jc,{server:f,isLoading:o.has(f.name),authUrl:Q.get(f.name),copilotDevice:C?.serverName===f.name?C:null,onStart:()=>x(f.name),onStop:()=>I.mutate(f.name),onRemove:()=>m(f.name),onAuth:()=>M(f.name)},f.name))})}),t.jsx(Jc,{isOpen:d,onClose:()=>u(!1)}),t.jsxs(Me,{isOpen:!!h,onClose:()=>m(null),title:"Remove MCP Server",maxWidth:"sm",showCloseButton:!1,children:[t.jsxs("p",{className:"text-sm text-muted-foreground mb-4",children:["Are you sure you want to remove"," ",t.jsx("span",{className:"font-medium text-foreground",children:h}),"? This will stop the server and remove its configuration."]}),t.jsxs("div",{className:"flex justify-end gap-2",children:[t.jsx(_,{variant:"secondary",size:"sm",onClick:()=>m(null),children:"Cancel"}),t.jsx(_,{variant:"primary",size:"sm",className:"bg-red-500 hover:bg-red-600 text-white",onClick:()=>{h&&c.mutate(h),m(null)},children:"Remove"})]})]})]})}),Oc=l.memo(function(){const A=uA(Q=>Q.isExpanded),g=uA(Q=>Q.toggleSidebar),o=uA(Q=>Q.servers).filter(Q=>Q.connected).length;return t.jsxs("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"MCP Servers",children:[t.jsx(ht,{className:"w-5 h-5 text-muted-foreground mx-auto"}),o>0&&t.jsx("span",{className:"absolute top-2 right-2 w-2 h-2 bg-green-500 rounded-full"})]})}),Lo="file-browser",jo=320,Tc=280,Yc=600;function Hc({dirPath:e}){const g=mA(Q=>Q.expandedDirs).has(e),{data:s,isLoading:o}=hB(e,g);return g?o?t.jsx("div",{className:"pl-4 py-1 text-xs text-muted-foreground",children:"Loading..."}):t.jsx("div",{className:"pl-3",children:s?.items.map(Q=>t.jsx(UB,{name:Q.name,path:Q.path,type:Q.type},Q.path))}):null}function UB({name:e,path:A,type:g}){const s=mA(E=>E.expandedDirs),o=mA(E=>E.toggleDir),Q=mA(E=>E.openFile),B=mA(E=>E.selectedFile),a=s.has(A),r=B===A,i=l.useCallback(()=>{g==="directory"?o(A):Q(A)},[g,A,o,Q]);return t.jsxs("div",{children:[t.jsxs("button",{type:"button",onClick:i,className:`w-full text-left flex items-center gap-1.5 px-2 py-1 text-sm hover:bg-muted/50 rounded transition-colors ${r?"bg-muted text-foreground":"text-foreground/80"}`,children:[g==="directory"?t.jsxs(t.Fragment,{children:[a?t.jsx(PA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}):t.jsx(xA,{className:"w-3 h-3 text-muted-foreground flex-shrink-0"}),a?t.jsx(zo,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"}):t.jsx(Vo,{className:"w-3.5 h-3.5 text-blue-500 flex-shrink-0"})]}):t.jsxs(t.Fragment,{children:[t.jsx("span",{className:"w-3 flex-shrink-0"}),t.jsx(rs,{className:"w-3.5 h-3.5 text-muted-foreground flex-shrink-0"})]}),t.jsx("span",{className:"truncate",children:e})]}),g==="directory"&&t.jsx(Hc,{dirPath:A})]})}const Pc=l.memo(function(){const A=mA(a=>a.isExpanded),g=mA(a=>a.collapseSidebar),s=Ue(a=>a.widths[Lo]??jo),{data:o,isLoading:Q,refetch:B}=hB(".");return A?t.jsxs("div",{className:"border-l border-border bg-background flex h-full relative",style:{width:s},children:[t.jsx(et,{panelKey:Lo,side:"right",minWidth:Tc,maxWidth:Yc,defaultWidth:jo}),t.jsxs("div",{className:"flex-1 flex flex-col h-full min-w-0",children:[t.jsxs("div",{className:"h-14 border-b border-border px-3 flex items-center justify-between shrink-0",children:[t.jsxs("div",{className:"flex items-center gap-2",children:[t.jsx(lt,{className:"w-4 h-4 text-muted-foreground"}),t.jsx("span",{className:"font-medium",children:"Files"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:g,children:t.jsx(xA,{className:"w-4 h-4"})})]}),t.jsx("div",{className:"flex-1 overflow-y-auto p-1",children:Q?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"Loading file tree..."}):!o||o.items.length===0?t.jsx("div",{className:"p-4 text-sm text-muted-foreground",children:"No files found"}):o.items.map(a=>t.jsx(UB,{name:a.name,path:a.path,type:a.type},a.path))}),t.jsxs("div",{className:"h-12 px-4 border-t border-border text-xs text-muted-foreground flex items-center justify-between gap-2",children:[t.jsxs("div",{className:"flex items-center gap-2 min-w-0 flex-1",children:[t.jsx(lt,{className:"w-3 h-3 flex-shrink-0"}),t.jsx("span",{className:"truncate",children:"Project Files"})]}),t.jsx(_,{variant:"ghost",size:"icon",onClick:()=>B(),title:"Refresh file tree",className:"h-6 w-6 flex-shrink-0",disabled:Q,children:t.jsx(HA,{className:`w-3 h-3 ${Q?"animate-spin":""}`})})]})]})]}):null}),Wc=l.memo(function(){const A=mA(s=>s.isExpanded),g=mA(s=>s.toggleSidebar);return t.jsx("button",{type:"button",onClick:g,className:`relative h-14 w-full transition-colors touch-manipulation flex items-center justify-center border-r-2 ${A?"bg-muted border-primary":"border-transparent hover:bg-muted/50"}`,title:"Files",children:t.jsx(lt,{className:"w-5 h-5 text-muted-foreground mx-auto"})})}),zc={js:"javascript",jsx:"jsx",ts:"typescript",tsx:"tsx",py:"python",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",cs:"csharp",php:"php",sh:"bash",bash:"bash",zsh:"bash",sql:"sql",json:"json",yaml:"yaml",yml:"yaml",xml:"xml",html:"html",css:"css",scss:"scss",md:"markdown",txt:"plaintext",svelte:"svelte",toml:"toml",lock:"plaintext"};function Vc(e){const A=e.split(".").pop()?.toLowerCase()??"";return zc[A]??"plaintext"}const Zc=l.memo(function(){const A=mA(r=>r.isViewerOpen),g=mA(r=>r.selectedFile),s=mA(r=>r.closeViewer),{data:o,isLoading:Q}=fl(g);if(l.useEffect(()=>{const r=i=>{const E=i.target,I=E.tagName==="INPUT"||E.tagName==="TEXTAREA"||E.isContentEditable;(i.key==="Escape"||i.key==="q"&&!I)&&A&&s()};return document.addEventListener("keydown",r),()=>document.removeEventListener("keydown",r)},[A,s]),!A||!g)return null;const B=document?.documentElement.classList.contains("dark")?ce:de,a=Vc(g);return t.jsxs("div",{className:"absolute inset-0 bg-background z-50 flex flex-col animate-in slide-in-from-left duration-300",children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-3",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:s,title:"Close file viewer (ESC)",children:t.jsx(kA,{className:"w-4 h-4"})}),t.jsxs("div",{className:"flex-1 flex items-center gap-2 min-w-0",children:[t.jsx("span",{className:"text-sm font-medium text-foreground font-mono truncate",title:g,children:g}),o&&t.jsxs("span",{className:"text-xs text-muted-foreground flex-shrink-0",children:[o.lineCount," lines"]})]}),t.jsx("span",{className:"text-xs text-muted-foreground",children:a})]}),t.jsx("div",{className:"flex-1 overflow-auto",children:Q?t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Loading file..."}):o?t.jsx("div",{className:"code-with-line-numbers",children:t.jsx(WA,{language:a,style:B,wrapLines:!0,wrapLongLines:!0,lineProps:()=>({className:"code-line"}),customStyle:{margin:0,padding:"1rem",background:"transparent",fontSize:"0.75rem",lineHeight:"1.25rem"},codeTagProps:{style:{flex:1}},children:o.content})}):t.jsx("div",{className:"h-full flex items-center justify-center text-muted-foreground",children:"Unable to load file"})})]})}),Xc=l.memo(function({authStatus:A,onSetupWallet:g,onImportWallet:s,onAddProvider:o,onRemoveProvider:Q,onStartOAuth:B,onStartOAuthManual:a,onExchangeOAuthCode:r,onOpenTopup:i,onNext:E,manageMode:I=!1,onClose:c,hideHeader:n=!1,onStartCopilotDeviceFlow:C,onPollCopilotDeviceFlow:d}){const[u,D]=l.useState(!1),[w,h]=l.useState(!1),[m,k]=l.useState(!1),[y,G]=l.useState(""),[M,x]=l.useState(!1),[F,p]=l.useState(null),[f,N]=l.useState(null),[b,S]=l.useState(""),[O,L]=l.useState(null),[R,j]=l.useState(null),[J,H]=l.useState(null),[z,AA]=l.useState(""),[tA,lA]=l.useState(!1),[yA,P]=l.useState(!1),[oA,T]=l.useState(null),[cA,bA]=l.useState(!1),[q,BA]=l.useState(null),[YA,NA]=l.useState(!1),[ee,JA]=l.useState(!1),[ye,me]=l.useState(!1),re=l.useRef(void 0),oe=l.useRef(!1),Je=l.useRef(d);Je.current=d;const he=IA(Y=>Y.balance),W=IA(Y=>Y.usdcBalance),aA=IA(Y=>Y.isLoading),EA=l.useRef(null),RA=l.useRef(null),te=l.useRef(null),Re=IA(Y=>Y.isTopupModalOpen),VA=l.useRef(!1),{fetchBalance:Qe}=dg("setu");l.useEffect(()=>{VA.current&&!Re&&Qe(),VA.current=Re},[Re,Qe]),l.useEffect(()=>{!A.setu.configured&&!w&&(h(!0),g().finally(()=>h(!1)))},[A.setu.configured,g,w]),l.useEffect(()=>{f&&EA.current&&EA.current.focus()},[f]),l.useEffect(()=>{J&&RA.current&&RA.current.focus()},[J]),l.useEffect(()=>{m&&te.current&&te.current.focus()},[m]),l.useEffect(()=>{if(!cA||!oA||!Je.current)return;oe.current=!1;const Y=Math.max((oA.interval||5)*1e3+2e3,7e3),UA=()=>{re.current=setTimeout(async()=>{if(!oe.current)try{const Ss=Je.current;if(!Ss)return;const fg=await Ss(oA.sessionId);if(oe.current)return;fg.status==="complete"?(T(null),bA(!1),BA(null),JA(!1)):fg.status==="error"?(BA(fg.error||"Authorization failed"),bA(!1)):UA()}catch{oe.current||UA()}},Y)};UA();const Ee=setTimeout(()=>{bA(!1),BA("Authorization timed out. Please try again.")},3e5);return()=>{oe.current=!0,re.current&&clearTimeout(re.current),clearTimeout(Ee)}},[cA,oA]);const Ge=async()=>{A.setu.publicKey&&(await navigator.clipboard.writeText(A.setu.publicKey),D(!0),setTimeout(()=>D(!1),2e3))},yt=Y=>`${Y.slice(0,8)}...${Y.slice(-6)}`,ot=async Y=>{if(b.trim())try{await o(Y,b.trim()),N(null),S("")}catch{}},Gt=async Y=>{if(R===Y){L(Y);try{await Q(Y)}finally{L(null),j(null)}}else j(Y)},pg=()=>{j(null)},Qt=async(Y,UA)=>{Y==="anthropic"?H({provider:Y,sessionId:null,mode:UA}):Y==="copilot"&&C?(BA(null),JA(!0),me(!0),C().then(Ee=>{T(Ee),me(!1)}).catch(Ee=>{BA(Ee instanceof Error?Ee.message:"Failed to start device flow"),me(!1)})):B(Y,UA)},Le=async()=>{if(J){P(!0);try{const{sessionId:Y}=await a(J.provider,J.mode);H({...J,sessionId:Y})}catch(Y){console.error("Failed to start OAuth:",Y)}P(!1)}},Ft=async()=>{if(!(!J||!J.sessionId||!z.trim())){lA(!0);try{await r(J.provider,z.trim(),J.sessionId),H(null),AA("")}catch{}lA(!1)}},Bt=()=>{H(null),AA("")},wg=()=>{oA&&(Ce(oA.verificationUri),bA(!0))},mg=async()=>{oA&&(await navigator.clipboard.writeText(oA.userCode),NA(!0),setTimeout(()=>NA(!1),2e3))},xg=()=>{T(null),bA(!1),BA(null),NA(!1),JA(!1),me(!1),oe.current=!0,re.current&&(clearTimeout(re.current),re.current=void 0)},at=()=>{p(null),G(""),k(!0)},$=()=>{M||(k(!1),p(null),G(""))},Be=async()=>{if(!(!y.trim()||M)){x(!0),p(null);try{await s(y.trim()),k(!1),G(""),Qe()}catch(Y){p(Y instanceof Error?Y.message:"Failed to import wallet")}finally{x(!1)}}},bt=Object.entries(A.providers).filter(([Y,UA])=>UA.configured&&Y!=="setu"),LB=Object.entries(A.providers).filter(([Y,UA])=>!UA.configured&&Y!=="setu");return t.jsxs("div",{className:"min-h-screen flex flex-col",children:[!n&&t.jsxs("div",{className:"flex items-center justify-between px-4 sm:px-6 py-4 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),!I&&t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-green-500"}),"Step 1 of 2"]})]}),t.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${n?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:"mb-10",children:[t.jsx("h1",{className:"text-2xl sm:text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:I?"Manage Providers":"Welcome to otto"}),t.jsx("p",{className:"text-lg text-muted-foreground max-w-2xl",children:I?"Add or remove AI providers. Your changes are saved automatically.":"Setu is your default AI provider, powered by your wallet. Add more providers below if you'd like."})]}),t.jsxs("div",{className:"grid grid-cols-1 sm:grid-cols-3 gap-6 sm:gap-8",children:[t.jsx("div",{children:t.jsx("div",{className:"bg-card rounded-2xl border border-border p-5",children:A.setu.configured&&A.setu.publicKey?t.jsxs("div",{className:"flex flex-col h-full",children:[t.jsxs("div",{className:"flex items-center gap-2 px-3 py-2 bg-green-500/10 border border-green-500/20 rounded-lg",children:[t.jsx(ZA,{provider:"setu",size:16}),t.jsx("span",{className:"text-sm font-medium text-green-600 dark:text-green-400",children:"Setu"}),t.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60 ml-auto",children:"Default Provider"})]}),t.jsx("div",{className:"flex justify-center py-4 mt-4",children:t.jsx("div",{className:"bg-white p-2 rounded-lg",children:t.jsx(hg,{value:A.setu.publicKey,size:140,level:"M"})})}),t.jsxs("div",{className:"space-y-2 mt-4",children:[t.jsxs("button",{type:"button",onClick:Ge,className:"w-full flex items-center justify-center gap-2 px-3 py-2 bg-muted hover:bg-muted/80 rounded-lg text-xs font-mono text-muted-foreground transition-colors",children:[yt(A.setu.publicKey),u?t.jsx(Ae,{className:"w-3.5 h-3.5 text-green-500"}):t.jsx(Ye,{className:"w-3.5 h-3.5 text-muted-foreground"})]}),t.jsxs("div",{className:"flex items-center justify-between px-3 py-2 bg-muted/50 rounded-lg",children:[t.jsxs("div",{className:"flex items-center gap-1",children:[t.jsxs("span",{className:"font-mono text-sm text-foreground",children:["$",((he??0)+(W??0)).toFixed(2)]}),t.jsx("button",{type:"button",onClick:Qe,disabled:aA,className:"p-0.5 text-muted-foreground hover:text-foreground transition-colors disabled:opacity-50",children:t.jsx(HA,{className:`w-3 h-3 ${aA?"animate-spin":""}`})})]}),t.jsxs("span",{className:"text-[10px] text-muted-foreground font-mono",children:[(he??0)>0&&`${(he??0).toFixed(2)} cr`,(he??0)>0&&(W??0)>0&&" + ",(W??0)>0&&`${(W??0).toFixed(2)} usdc`]})]})]}),t.jsxs("div",{className:"flex items-center gap-4 py-4",children:[t.jsx("div",{className:"flex-1 h-px bg-border"}),t.jsx("span",{className:"text-xs text-muted-foreground font-medium",children:"OR"}),t.jsx("div",{className:"flex-1 h-px bg-border"})]}),t.jsxs("button",{type:"button",onClick:i,className:"w-full flex items-center justify-center gap-2 px-4 py-2.5 bg-primary text-primary-foreground rounded-lg text-sm font-medium hover:bg-primary/90 transition-colors",children:[t.jsx(ct,{className:"w-4 h-4"}),"Pay via Card"]}),t.jsxs("button",{type:"button",onClick:at,className:"w-full mt-2 flex items-center justify-center gap-2 px-4 py-2.5 border border-border text-foreground rounded-lg text-sm font-medium hover:bg-muted/50 transition-colors",children:[t.jsx(Zt,{className:"w-4 h-4"}),"Import Wallet"]})]}):t.jsx("div",{className:"flex items-center justify-center py-16",children:t.jsx(CA,{className:"w-8 h-8 animate-spin text-muted-foreground"})})})}),t.jsxs("div",{className:"sm:col-span-2 space-y-6",children:[t.jsxs("div",{children:[t.jsxs("div",{className:"flex items-center justify-between mb-4",children:[t.jsx("h2",{className:"font-semibold text-foreground",children:"Connected Providers"}),bt.length>0&&t.jsxs("span",{className:"text-sm text-muted-foreground",children:[bt.length," active"]})]}),bt.length===0?t.jsx("div",{className:"text-sm text-muted-foreground py-4",children:"No providers connected yet. Add one below."}):t.jsx("div",{className:"flex flex-wrap gap-2",children:bt.map(([Y,UA])=>t.jsxs("div",{className:`flex items-center gap-2 pl-3 pr-2 py-2 rounded-full transition-all duration-200 ${R===Y?"bg-destructive/10 border border-destructive/30":"group bg-green-500/10 border border-green-500/20"}`,children:[t.jsx(ZA,{provider:Y,size:16}),t.jsx("span",{className:`text-sm font-medium transition-colors ${R===Y?"text-destructive":"text-green-600 dark:text-green-400"}`,children:UA.label}),R!==Y&&t.jsx("span",{className:"text-xs text-green-600/60 dark:text-green-500/60",children:UA.type==="oauth"?"OAuth":"API"}),R===Y?t.jsxs("div",{className:"flex items-center gap-1 ml-1",children:[t.jsx("span",{className:"text-xs text-destructive/80 mr-1",children:"Remove?"}),t.jsx("button",{type:"button",onClick:()=>Gt(Y),disabled:O===Y,className:"px-2 py-0.5 text-xs bg-destructive text-destructive-foreground rounded hover:bg-destructive/90 transition-colors disabled:opacity-50",children:O===Y?t.jsx(CA,{className:"w-3 h-3 animate-spin"}):"Yes"}),t.jsx("button",{type:"button",onClick:pg,className:"px-2 py-0.5 text-xs bg-muted text-muted-foreground rounded hover:bg-muted/80 transition-colors",children:"No"})]}):Y!=="setu"&&t.jsx("button",{type:"button",onClick:()=>Gt(Y),className:"ml-1 p-1 text-green-600/40 dark:text-green-500/40 hover:text-green-600/80 dark:hover:text-green-500/80 opacity-0 group-hover:opacity-100 transition-opacity",children:t.jsx(kA,{className:"w-3 h-3"})})]},Y))})]}),t.jsxs("div",{children:[t.jsx("h2",{className:"font-semibold text-foreground mb-4",children:"Add Providers"}),t.jsx("div",{className:"grid grid-cols-1 sm:grid-cols-2 gap-3 items-start",children:LB.map(([Y,UA])=>t.jsx("div",{children:f===Y?t.jsxs("div",{className:"flex items-center gap-2 p-3 bg-card border border-ring rounded-xl overflow-hidden",children:[t.jsx("div",{className:"shrink-0",children:t.jsx(ZA,{provider:Y,size:18})}),t.jsx("input",{ref:EA,type:"password",value:b,onChange:Ee=>S(Ee.target.value),placeholder:`${UA.label} API key...`,className:"flex-1 min-w-0 bg-transparent text-sm outline-none placeholder:text-muted-foreground text-foreground",onKeyDown:Ee=>{Ee.key==="Enter"&&ot(Y),Ee.key==="Escape"&&(N(null),S(""))}}),t.jsx("button",{type:"button",onClick:()=>ot(Y),disabled:!b.trim(),className:"shrink-0 px-3 py-1.5 bg-primary text-primary-foreground text-sm font-medium rounded-lg disabled:opacity-50",children:"Add"}),t.jsx("button",{type:"button",onClick:()=>{N(null),S("")},className:"shrink-0 p-1.5 text-muted-foreground hover:text-foreground",children:t.jsx(kA,{className:"w-4 h-4"})})]}):t.jsxs("div",{className:"flex items-center justify-between p-3 bg-card border border-border hover:border-border/80 rounded-xl transition-colors gap-2",children:[t.jsxs("div",{className:"flex items-center gap-3 min-w-0",children:[t.jsx(ZA,{provider:Y,size:20}),t.jsxs("div",{className:"min-w-0",children:[t.jsx("div",{className:"font-medium text-foreground truncate",children:UA.label}),t.jsxs("div",{className:"text-xs text-muted-foreground",children:[UA.modelCount," models"]})]})]}),t.jsxs("div",{className:"flex items-center gap-1",children:[Y!=="copilot"&&t.jsxs("button",{type:"button",onClick:()=>N(Y),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[t.jsx(Zt,{className:"w-3.5 h-3.5"}),"API"]}),UA.supportsOAuth&&t.jsxs("button",{type:"button",onClick:()=>Qt(Y,Y==="anthropic"?"max":void 0),className:"flex items-center gap-1.5 px-3 py-1.5 text-sm text-muted-foreground hover:text-foreground hover:bg-muted rounded-lg transition-colors",children:[t.jsx(jA,{className:"w-3.5 h-3.5"}),Y==="anthropic"?"Pro":Y==="copilot"?"Login":"OAuth"]})]})]})},Y))})]})]})]})]})}),t.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:t.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[!I&&t.jsx("div",{className:"text-xs sm:text-sm text-muted-foreground hidden sm:block",children:"You can add more providers later in settings"}),I?t.jsx("button",{type:"button",onClick:c,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors ml-auto",children:"Done"}):t.jsxs("button",{type:"button",onClick:E,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors",children:["Continue",t.jsx(Zo,{className:"w-4 h-4"})]})]})}),m&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("h3",{className:"text-lg font-semibold",children:"Import Setu Wallet"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste your base58 private key to replace the current wallet."}),t.jsx("textarea",{ref:te,value:y,onChange:Y=>G(Y.target.value),placeholder:"Enter private key",className:"w-full min-h-[110px] px-4 py-3 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors font-mono text-xs resize-y",onKeyDown:Y=>{(Y.metaKey||Y.ctrlKey)&&Y.key==="Enter"&&(Y.preventDefault(),Be()),Y.key==="Escape"&&$()}}),F&&t.jsx("p",{className:"text-sm text-red-500 mt-3",children:F}),t.jsxs("div",{className:"flex gap-3 mt-5",children:[t.jsx("button",{type:"button",onClick:$,disabled:M,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors disabled:opacity-50",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Be,disabled:!y.trim()||M,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:M?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):"Import Wallet"})]})]})]})}),J&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:J.provider,size:24}),t.jsxs("h3",{className:"text-lg font-semibold",children:["Connect"," ",A.providers[J.provider]?.label||J.provider]})]}),J.sessionId?t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Paste the authorization code:"}),t.jsx("input",{type:"text",ref:RA,value:z,onChange:Y=>AA(Y.target.value),placeholder:"Paste code here...",className:"w-full h-11 px-4 bg-muted/50 border border-border rounded-lg text-foreground placeholder:text-muted-foreground outline-none focus:border-foreground/30 transition-colors mb-4 font-mono text-sm",onKeyDown:Y=>{Y.key==="Enter"&&Ft(),Y.key==="Escape"&&Bt()}}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:Bt,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Ft,disabled:!z.trim()||tA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:tA?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):"Connect"})]})]}):t.jsxs("div",{className:"p-6",children:[t.jsxs("p",{className:"text-sm text-muted-foreground mb-6",children:["You'll be redirected to"," ",A.providers[J.provider]?.label||J.provider," ","to authorize access. After authorizing, copy the code and return here."]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:Bt,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:Le,disabled:yA,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:yA?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsxs(t.Fragment,{children:["Continue",t.jsx(jA,{className:"w-4 h-4"})]})})]})]})]})}),ee&&t.jsx("div",{className:"fixed inset-0 z-[9999] flex items-center justify-center bg-black/60 backdrop-blur-sm",children:t.jsxs("div",{className:"bg-background border border-border rounded-xl w-full max-w-lg mx-6 shadow-2xl",children:[t.jsxs("div",{className:"flex items-center gap-3 p-6 border-b border-border",children:[t.jsx(ZA,{provider:"copilot",size:24}),t.jsx("h3",{className:"text-lg font-semibold",children:"Connect GitHub Copilot"})]}),t.jsxs("div",{className:"p-6",children:[t.jsx("p",{className:"text-sm text-muted-foreground mb-4",children:"Enter this code on GitHub to authorize:"}),t.jsx("div",{className:"flex items-center justify-center gap-3 mb-6",children:ye?t.jsx("div",{className:"bg-muted px-6 py-3 rounded-lg animate-pulse",children:t.jsx("div",{className:"h-9 w-48 bg-muted-foreground/20 rounded"})}):oA?t.jsxs(t.Fragment,{children:[t.jsx("code",{className:"text-3xl font-mono font-bold tracking-widest text-foreground bg-muted px-6 py-3 rounded-lg select-all",children:oA.userCode}),t.jsx("button",{type:"button",onClick:mg,className:"p-2 text-muted-foreground hover:text-foreground transition-colors",children:YA?t.jsx(Ae,{className:"w-5 h-5 text-green-500"}):t.jsx(Ye,{className:"w-5 h-5"})})]}):null}),q&&t.jsx("p",{className:"text-sm text-red-500 mb-4 text-center",children:q}),cA&&t.jsxs("div",{className:"flex items-center justify-center gap-2 text-sm text-muted-foreground mb-4",children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Waiting for authorization..."]}),t.jsxs("div",{className:"flex gap-3",children:[t.jsx("button",{type:"button",onClick:xg,className:"flex-1 h-11 px-4 bg-transparent border border-border text-foreground rounded-lg font-medium hover:bg-muted/50 transition-colors",children:"Cancel"}),t.jsx("button",{type:"button",onClick:wg,disabled:cA||ye,className:"flex-1 h-11 px-4 bg-foreground text-background rounded-lg font-medium hover:bg-foreground/90 transition-colors disabled:opacity-50 flex items-center justify-center gap-2",children:cA||ye?t.jsx(CA,{className:"w-4 h-4 animate-spin"}):t.jsxs(t.Fragment,{children:["Open GitHub",t.jsx(jA,{className:"w-4 h-4"})]})})]})]})]})})]})}),_c=l.memo(function({authStatus:A,onComplete:g,onBack:s,hideHeader:o=!1}){const[Q,B]=l.useState(null),[a,r]=l.useState(null),[i,E]=l.useState(!0),[I,c]=l.useState(!1),[n,C]=l.useState("setu"),[d,u]=l.useState("kimi-k2.5"),[D,w]=l.useState(A.defaults.agent||"build"),[h,m]=l.useState(A.defaults.toolApproval||"dangerous"),[k,y]=l.useState(!1),G=l.useRef(!1),M=l.useId(),x=l.useId(),F=l.useId(),p=l.useId();l.useEffect(()=>{(async()=>{try{const[O,L]=await Promise.all([v.getConfig(),v.getAllModels()]);B(O),r(L);const R=O?.defaults?.provider||"setu",j=O?.defaults?.model||"kimi-k2.5",J=L?.[R]?.models?.length>0,H=J?R:"setu",z=J&&L[R].models.some(AA=>AA.id===j)?j:L?.[H]?.models?.[0]?.id||"kimi-k2.5";C(H),u(z),O?.defaults?.agent&&w(O.defaults.agent),O?.defaults?.toolApproval&&m(O.defaults.toolApproval),O?.defaults?.guidedMode&&y(O.defaults.guidedMode)}catch{}finally{E(!1)}})()},[]),l.useEffect(()=>{if(Q?.agents?.length){const S=Q.agents;(!D||!S.includes(D))&&w(S.includes("build")?"build":S[0])}},[Q,D]),l.useEffect(()=>{if(a?.[n]&&G.current){const S=a[n];S.models.some(O=>O.id===d)||u(S.models[0]?.id||"")}},[n,a,d]);const f=async()=>{c(!0);try{await v.updateDefaults({provider:n,model:d,agent:D,toolApproval:h,guidedMode:k,scope:"global"}),await g()}catch{}finally{c(!1)}};if(i)return t.jsx("div",{className:"min-h-screen flex items-center justify-center",children:t.jsx(CA,{className:"w-8 h-8 animate-spin text-muted-foreground"})});const N=Q?.providers.filter(S=>(A.providers[S]?.configured||S==="setu")&&a?.[S]?.models?.length>0)||["setu"],b=a?.[n]?.models||[];return t.jsxs("div",{className:"min-h-screen flex flex-col",children:[!o&&t.jsxs("div",{className:"flex items-center justify-between px-6 py-4 border-b border-border",children:[t.jsxs("div",{className:"flex items-center gap-3",children:[t.jsx(ZA,{provider:"setu",size:24}),t.jsx("span",{className:"font-semibold text-foreground",children:"otto"})]}),t.jsxs("div",{className:"flex items-center gap-2 text-sm text-muted-foreground",children:[t.jsx("span",{className:"w-2 h-2 rounded-full bg-blue-500"}),"Step 2 of 2"]})]}),t.jsx("div",{className:`flex-1 px-4 sm:px-6 lg:px-12 pb-32 ${o?"pt-8 sm:pt-10 lg:pt-14":"pt-6 sm:pt-8 lg:pt-12"}`,children:t.jsxs("div",{className:"max-w-7xl mx-auto",children:[t.jsxs("div",{className:"mb-10",children:[t.jsx("h1",{className:"text-3xl lg:text-4xl font-semibold text-foreground mb-3",children:"Configure Defaults"}),t.jsx("p",{className:"text-lg text-muted-foreground",children:"Set your preferences. You can change these anytime in settings."})]}),t.jsxs("div",{className:"grid grid-cols-1 md:grid-cols-2 gap-6",children:[t.jsxs("div",{className:"md:col-span-2",children:[t.jsx("label",{htmlFor:M,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Provider"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:M,value:n,onChange:S=>{G.current=!0,C(S.target.value)},className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:N.map(S=>t.jsx("option",{value:S,children:A.providers[S]?.label||S},S))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{className:"md:col-span-2",children:[t.jsx("label",{htmlFor:x,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Model"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:x,value:d,onChange:S=>u(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:b.map(S=>t.jsx("option",{value:S.id,children:S.label||S.id},S.id))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:F,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Default Agent"}),t.jsxs("div",{className:"relative",children:[t.jsx("select",{id:F,value:D,onChange:S=>w(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:(Q?.agents||["build"]).map(S=>t.jsx("option",{value:S,children:S},S))}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]})]}),t.jsxs("div",{children:[t.jsx("label",{htmlFor:p,className:"block text-sm font-medium text-muted-foreground mb-2",children:"Tool Approval"}),t.jsxs("div",{className:"relative",children:[t.jsxs("select",{id:p,value:h,onChange:S=>m(S.target.value),className:"w-full px-4 py-3 bg-card border border-border rounded-xl text-foreground appearance-none cursor-pointer focus:outline-none focus:border-ring transition-colors",children:[t.jsx("option",{value:"auto",children:"Auto - run without asking"}),t.jsx("option",{value:"dangerous",children:"Dangerous - approve writes only"}),t.jsx("option",{value:"all",children:"All - approve every tool"})]}),t.jsx(PA,{className:"absolute right-4 top-1/2 -translate-y-1/2 w-5 h-5 text-muted-foreground pointer-events-none"})]}),t.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"Controls when tool executions need approval"})]}),t.jsx("div",{className:"md:col-span-2",children:t.jsxs("div",{className:"flex items-center justify-between px-4 py-3 bg-card border border-border rounded-xl",children:[t.jsxs("div",{children:[t.jsx("span",{className:"text-sm font-medium text-foreground",children:"Guided Mode"}),t.jsx("p",{className:"text-sm text-muted-foreground mt-0.5",children:"AI will run commands and manage services for you instead of giving instructions"})]}),t.jsx("button",{type:"button",role:"switch","aria-checked":k,onClick:()=>y(!k),className:`relative inline-flex h-6 w-11 items-center rounded-full transition-colors focus:outline-none focus:ring-2 focus:ring-primary focus:ring-offset-2 ${k?"bg-primary":"bg-muted"}`,children:t.jsx("span",{className:`inline-block h-4 w-4 transform rounded-full transition-transform ${k?"translate-x-6":"translate-x-1"} ${k?"bg-primary-foreground":"bg-foreground"}`})})]})})]})]})}),t.jsx("div",{className:"fixed bottom-0 left-0 right-0 px-4 sm:px-6 py-4 border-t border-border bg-background",children:t.jsxs("div",{className:"max-w-7xl mx-auto flex items-center justify-between",children:[t.jsxs("button",{type:"button",onClick:s,className:"flex items-center gap-2 px-4 py-3 text-muted-foreground hover:text-foreground transition-colors",children:[t.jsx(ka,{className:"w-4 h-4"}),"Back"]}),t.jsx("button",{type:"button",onClick:f,disabled:I,className:"flex items-center gap-2 px-6 py-3 bg-primary text-primary-foreground rounded-lg font-medium hover:bg-primary/90 transition-colors disabled:opacity-50",children:I?t.jsxs(t.Fragment,{children:[t.jsx(CA,{className:"w-4 h-4 animate-spin"}),"Setting up..."]}):t.jsxs(t.Fragment,{children:["Start Using otto",t.jsx(Te,{className:"w-4 h-4"})]})})]})})]})}),$c=l.memo(function({hideHeader:A=!1}){const g=LA(m=>m.isOpen),s=LA(m=>m.currentStep),o=LA(m=>m.manageMode),Q=LA(m=>m.authStatus),B=LA(m=>m.nextStep),a=LA(m=>m.prevStep),r=LA(m=>m.reset),i=IA(m=>m.openTopupModal),{setupWallet:E,importWallet:I,addProvider:c,removeProvider:n,completeOnboarding:C,startOAuth:d,startOAuthManual:u,exchangeOAuthCode:D,startCopilotDeviceFlow:w,pollCopilotDeviceFlow:h}=bs();return!g||!Q?null:t.jsxs("div",{className:"fixed inset-0 z-[9999] bg-background text-foreground overflow-y-auto",children:[s==="wallet"&&t.jsx(Xc,{authStatus:Q,onSetupWallet:E,onImportWallet:I,onAddProvider:c,onRemoveProvider:n,onStartOAuth:d,onStartOAuthManual:u,onExchangeOAuthCode:D,onOpenTopup:i,onNext:B,manageMode:o,onClose:r,hideHeader:A,onStartCopilotDeviceFlow:w,onPollCopilotDeviceFlow:h}),s==="defaults"&&t.jsx(_c,{authStatus:Q,onComplete:C,onBack:a,hideHeader:A})]})}),SB="otto-theme";function Ad(){if(typeof window>"u")return"dark";const e=window.localStorage.getItem(SB);return e==="light"||e==="dark"?e:window.matchMedia?.("(prefers-color-scheme: light)").matches?"light":"dark"}function ed(){const[e,A]=l.useState(()=>Ad());l.useEffect(()=>{if(typeof document>"u")return;const s=document.documentElement;e==="dark"?s.classList.add("dark"):s.classList.remove("dark");try{window.localStorage.setItem(SB,e)}catch(o){console.warn("Failed to persist theme preference",o)}window.parent&&window.parent!==window&&window.parent.postMessage({type:"otto-set-theme",theme:e},"*")},[e]),l.useEffect(()=>{if(typeof window>"u")return;const s=o=>{o.data?.type==="otto-set-theme"&&(o.data.theme==="light"||o.data.theme==="dark")&&A(o.data.theme)};return window.addEventListener("message",s),()=>window.removeEventListener("message",s)},[]);const g=l.useCallback(()=>{A(s=>s==="dark"?"light":"dark")},[]);return l.useMemo(()=>({theme:e,setTheme:A,toggleTheme:g}),[e,g])}function td(){const[e,A]=l.useState(null);return l.useEffect(()=>{(async()=>{try{const Q=`${window.OTTO_SERVER_URL||TA}/v1/config/cwd`;console.log("[useWorkingDirectory] Fetching from:",Q);const B=await fetch(Q);if(!B.ok)throw console.error("[useWorkingDirectory] Failed:",B.status,B.statusText),new Error(`Failed to fetch working directory: ${B.status}`);const a=await B.json();console.log("[useWorkingDirectory] Success:",a),a.dirName&&(console.log("[useWorkingDirectory] Setting title to:",a.dirName),A(a.dirName),document.title=a.dirName)}catch(s){console.error("[useWorkingDirectory] Error:",s),document.title="otto"}})()},[]),e}function gd({sessionIds:e,activeSessionId:A,gitFiles:g,onSelectSession:s,onNewSession:o,onStageFile:Q,onUnstageFile:B,onRestoreFile:a,onDeleteFile:r,onStageAll:i,onUnstageAll:E,onOpenCommitModal:I,onViewDiff:c,onReturnToInput:n}){const{currentFocus:C,sessionIndex:d,gitFileIndex:u,setFocus:D,setSessionIndex:w,setGitFileIndex:h,resetGitFileIndex:m}=Fs(),{setCollapsed:k,toggleCollapse:y}=ze(),{isExpanded:G,toggleSidebar:M}=rA(),x=rA(N=>N.closeDiff),F=SA(N=>N.toggleSidebar),p=e.indexOf(A||""),f=l.useCallback(N=>{const b=N.target,S=b.tagName==="INPUT"||b.tagName==="TEXTAREA"||b.isContentEditable,O=!!b.closest("[data-terminal-viewer]");if((N.ctrlKey||N.metaKey)&&N.key==="h"){N.preventDefault(),C==="sessions"?(document.activeElement?.blur(),D("input"),k(!0),setTimeout(()=>n?.(),50)):C==="git"?(document.activeElement?.blur(),D("input"),M(),x(),setTimeout(()=>n?.(),50)):(document.activeElement?.blur(),D("sessions"),k(!1),p>=0&&w(p));return}if((N.ctrlKey||N.metaKey)&&N.key==="l"){N.preventDefault(),C==="git"?(document.activeElement?.blur(),D("input"),M(),x(),setTimeout(()=>n?.(),50)):C==="sessions"?(document.activeElement?.blur(),D("input"),k(!0),setTimeout(()=>n?.(),50)):(document.activeElement?.blur(),G||M(),D("git"),m());return}if((N.ctrlKey||N.metaKey)&&N.key==="/"){N.preventDefault(),y();return}if((N.ctrlKey||N.metaKey)&&N.key==="\\"){N.preventDefault(),M();return}if((N.ctrlKey||N.metaKey)&&N.shiftKey&&N.key==="r"){N.preventDefault(),F();return}if((N.ctrlKey||N.metaKey)&&N.key==="n"){N.preventDefault(),o();return}if(N.key==="Escape"&&!O||N.key==="q"&&!S&&(C==="sessions"||C==="git")){N.preventDefault(),C==="sessions"?k(!0):C==="git"&&(M(),x()),D("input"),n?.();return}if(C==="sessions"&&!S){if(N.key==="j"&&e.length>0){N.preventDefault();const L=Math.min(d+1,e.length-1);w(L);return}if(N.key==="k"&&e.length>0){N.preventDefault();const L=Math.max(d-1,0);w(L);return}if(N.key==="Enter"&&e[d]){N.preventDefault(),s(e[d]),D("input");return}}if(C==="git"&&!S){if(N.key==="j"&&g.length>0){N.preventDefault();const L=Math.min(u+1,g.length-1);h(L);return}if(N.key==="k"&&g.length>0){N.preventDefault();const L=Math.max(u-1,0);h(L);return}if(N.key===" "&&g[u]){N.preventDefault();const L=g[u];L.staged?B?.(L.path):Q?.(L.path);return}if(N.key==="a"){N.preventDefault(),i?.();return}if(N.key==="u"){N.preventDefault(),E?.();return}if(N.key==="R"&&g[u]){N.preventDefault();const L=g[u];!L.staged&&L.status!=="untracked"&&L.status!=="added"&&a?.(L.path);return}if(N.shiftKey&&N.key==="D"||N.key==="Backspace"){N.preventDefault();const L=g[u];L&&!L.staged&&L.status==="untracked"&&r?.(L.path);return}if(N.key==="c"){N.preventDefault(),I?.();return}if(N.key==="Enter"&&g[u]){N.preventDefault();const L=g[u];c?.(L.path,L.staged);return}}},[C,d,u,e,g,p,G,D,w,h,m,k,M,F,y,s,o,Q,B,a,r,i,E,I,c,n,x]);return l.useEffect(()=>(window.addEventListener("keydown",f),()=>window.removeEventListener("keydown",f)),[f]),{currentFocus:C,sessionIndex:d,gitFileIndex:u}}function sd(e){const A=l.useRef(null),g=l.useRef(null),s=IA(i=>i.setBalance),o=IA(i=>i.setPaymentPending),Q=Ie(i=>i.removeToast),B=Ie(i=>i.updateToast),a=tg(i=>i.setPendingTopup),r=tg(i=>i.clearPendingTopup);l.useEffect(()=>{if(!e)return;const i=new dB;A.current=i;const E=v.getStreamUrl(e);i.connect(E);const I=i.on("*",c=>{const n=c.payload;switch(c.type){case"setu.topup.required":{const C=typeof n?.amountUsd=="number"?n.amountUsd:0,d=typeof n?.currentBalance=="number"?n.currentBalance:0,u=typeof n?.minTopupUsd=="number"?n.minTopupUsd:5,D=typeof n?.suggestedTopupUsd=="number"?n.suggestedTopupUsd:10,w=typeof n?.messageId=="string"?n.messageId:"";a({sessionId:e,messageId:w,amountUsd:C,currentBalance:d,minTopupUsd:u,suggestedTopupUsd:D});break}case"setu.topup.method_selected":{n?.method==="crypto"&&(o(!0),g.current=QA.loading("💳 Processing crypto payment..."));break}case"setu.topup.cancelled":{r();const C=typeof n?.reason=="string"?n.reason:"Request cancelled";QA(`⚠️ ${C}`);break}case"setu.payment.required":{const C=typeof n?.amountUsd=="number"?n.amountUsd:0;o(!0),g.current||(g.current=QA.loading(`💳 Payment required: $${C.toFixed(2)}`));break}case"setu.payment.signing":{g.current?B(g.current,{message:"✍️ Signing transaction..."}):g.current=QA.loading("✍️ Signing transaction...");break}case"setu.payment.complete":{r();const C=n?.amountUsd,d=n?.newBalance,u=typeof n?.transactionId=="string"?n.transactionId:void 0,D=typeof C=="number"?C:typeof C=="string"?parseFloat(C):0,w=typeof d=="number"?d:typeof d=="string"?parseFloat(d):0;s(w),o(!1),g.current&&(Q(g.current),g.current=null);const h=`✅ Paid $${D.toFixed(2)}`;u?QA.successWithAction(h,{label:"View Tx",href:`https://orbmarkets.io/tx/${u}`}):QA.success(h);break}case"setu.fiat.checkout_created":{r(),o(!1),g.current&&(Q(g.current),g.current=null),QA.success("💳 Complete payment, then retry your message");break}case"setu.balance.updated":{const C=n?.balanceRemaining,d=typeof C=="number"?C:typeof C=="string"?parseFloat(C):null;d!==null&&!Number.isNaN(d)&&s(d);break}case"setu.payment.error":{r();const C=typeof n?.error=="string"?n.error:"Payment failed";o(!1),g.current&&(Q(g.current),g.current=null),QA.error(`❌ ${C}`);break}}});return()=>{I(),i.disconnect()}},[e,s,o,Q,B,a,r])}const Dg=OB({component:od});function od(){const{checkOnboarding:e}=bs();return l.useEffect(()=>{e()},[e]),t.jsxs(t.Fragment,{children:[t.jsx(TB,{}),t.jsx($c,{}),t.jsx(Gs,{}),null]})}const Qd=os("/")({beforeLoad:()=>{throw YB({to:"/sessions"})},component:()=>null}),vo="left-sidebar",qo=256,Bd=256,ad=480,id=l.memo(function({children:A,onNewSession:g}){const s=rA(a=>a.isDiffOpen),o=ze(a=>a.isCollapsed),Q=ze(a=>a.toggleCollapse),B=Ue(a=>a.widths[vo]??qo);return l.useEffect(()=>(o?document.body.style.overflow="":document.body.style.overflow="hidden",()=>{document.body.style.overflow=""}),[o]),o?t.jsxs("aside",{className:"w-12 md:w-12 border-r border-border bg-background flex flex-col transition-all duration-300 ease-in-out hidden md:flex",children:[t.jsx("div",{className:"h-14 border-b border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:g,title:"New session",className:"rounded-full touch-manipulation",children:t.jsx(Ls,{className:"w-4 h-4"})})}),t.jsx("button",{type:"button",className:"flex-1 cursor-pointer hover:bg-muted/50 transition-colors touch-manipulation",onClick:s?void 0:Q,title:s?void 0:"Expand sidebar","aria-label":"Expand sidebar"}),t.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Expand sidebar",disabled:s,className:"transition-transform duration-200 hover:scale-110 touch-manipulation",children:t.jsx(Ma,{className:"w-4 h-4"})})})]}):t.jsxs(t.Fragment,{children:[!o&&t.jsx("div",{className:"fixed inset-0 bg-black/50 z-40 md:hidden",onClick:Q,"aria-hidden":"true"}),t.jsxs("aside",{className:"border-r border-border bg-background flex transition-all duration-300 ease-in-out fixed md:relative top-0 left-0 z-50 h-screen md:h-auto w-full md:w-auto",style:{maxWidth:"100%"},children:[t.jsxs("div",{className:"flex-1 flex flex-col min-w-0",style:{width:B},children:[t.jsxs("div",{className:"h-14 border-b border-border px-4 flex items-center gap-2 md:hidden bg-background",children:[t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Close menu",className:"touch-manipulation flex-shrink-0","aria-label":"Close menu",children:t.jsx(ya,{className:"w-5 h-5"})}),t.jsx("h1",{className:"text-lg font-semibold text-foreground flex-1",children:"otto"})]}),t.jsx("div",{className:"h-14 border-b border-border px-4 flex items-center gap-2",children:t.jsxs(_,{variant:"primary",size:"sm",onClick:g,className:"flex-1 touch-manipulation",children:[t.jsx(Ls,{className:"w-4 h-4 mr-2"}),"New Session"]})}),t.jsx("div",{className:"flex-1 overflow-y-auto scrollbar-hide",children:A}),t.jsx("div",{className:"h-12 border-t border-border px-2 flex items-center justify-end",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:"Collapse sidebar",disabled:s,className:"transition-transform duration-200 hover:scale-110 touch-manipulation",children:t.jsxs("svg",{xmlns:"http://www.w3.org/2000/svg",width:"16",height:"16",viewBox:"0 0 24 24",fill:"none",stroke:"currentColor",strokeWidth:"2",strokeLinecap:"round",strokeLinejoin:"round",className:"transition-transform duration-300",role:"img","aria-label":"Collapse sidebar",children:[t.jsx("title",{children:"Collapse sidebar"}),t.jsx("path",{d:"M15 18l-6-6 6-6"})]})})})]}),t.jsx("div",{className:"hidden md:block",children:t.jsx(et,{panelKey:vo,side:"left",minWidth:Bd,maxWidth:ad,defaultWidth:qo})})]})]})}),rd=l.memo(function({sidebar:A,children:g,onNewSession:s,theme:o,onToggleTheme:Q,sessionId:B,onNavigateToSession:a,onFixWithAI:r}){return t.jsxs("div",{className:"h-screen flex bg-background touch-manipulation border-t border-border/50",children:[t.jsx(id,{onNewSession:s,children:A}),t.jsxs("div",{className:"flex-1 flex flex-col overflow-hidden w-full md:w-auto",children:[t.jsxs("div",{className:"flex-1 flex overflow-hidden",children:[t.jsxs("main",{className:"flex-1 flex flex-col overflow-hidden relative",children:[t.jsx(kl,{}),t.jsx(Ol,{}),t.jsx(Zc,{}),g]}),t.jsxs("div",{className:"hidden md:flex",children:[t.jsx(ml,{onFixWithAI:r}),t.jsx(Kl,{sessionId:B}),t.jsx(Zl,{parentSessionId:B??null,onNavigateToSession:a}),t.jsx(Ec,{}),t.jsx(wc,{}),t.jsx(Pc,{}),t.jsx(qc,{}),t.jsxs("div",{className:"flex flex-col w-12 border-l border-border bg-background",children:[t.jsx(xl,{}),t.jsx(Jl,{sessionId:B}),t.jsx(_l,{parentSessionId:B}),t.jsx(Wc,{}),t.jsx(Cc,{}),t.jsx(mc,{}),t.jsx(Oc,{}),t.jsx("div",{className:"flex-1"}),t.jsx(NE,{}),t.jsx("div",{className:"h-12 border-t border-border flex items-center justify-center",children:t.jsx(_,{variant:"ghost",size:"icon",onClick:Q,title:`Switch to ${o==="dark"?"light":"dark"} mode`,"aria-label":`Switch to ${o==="dark"?"light":"dark"} mode`,className:"touch-manipulation",children:o==="dark"?t.jsx(Ga,{className:"w-4 h-4"}):t.jsx(Fa,{className:"w-4 h-4"})})})]})]})]}),t.jsx(fE,{})]}),t.jsx(Ml,{}),t.jsx(ME,{})]})});function KB({sessionId:e}){const A=l.useRef(null),g=BC(),{data:s}=Ig(),{theme:o,toggleTheme:Q}=ed(),{openCommitModal:B,openDiff:a}=rA(),r=HB(),{data:i=[]}=Cg(),{data:E}=lg(),I=cg(),c=ks(),n=tB(),C=gB(),d=ws(M=>M.openConfirmation);td(),sd(e),dg(s?.defaults?.provider);const u=l.useCallback(()=>{setTimeout(()=>{A.current?.focus()},100)},[]),D=l.useCallback(async()=>{try{const M=await g.mutateAsync({agent:s?.defaults.agent||"general",provider:s?.defaults.provider,model:s?.defaults.model});r({to:"/sessions/$sessionId",params:{sessionId:M.id},replace:!1}),u()}catch(M){console.error("Failed to create session:",M)}},[g,s,r,u]),w=l.useCallback(()=>{r({to:"/sessions"})},[r]),h=l.useCallback(M=>{r({to:"/sessions/$sessionId",params:{sessionId:M}}),u()},[r,u]),m=l.useCallback(async M=>{try{const x=await g.mutateAsync({agent:s?.defaults.agent||"general",provider:s?.defaults.provider,model:s?.defaults.model,title:"Fix Git Error"});r({to:"/sessions/$sessionId",params:{sessionId:x.id},replace:!1}),await v.sendMessage(x.id,{content:M})}catch(x){console.error("Failed to create fix session:",x)}},[g,s,r]),k=l.useMemo(()=>E?[...(E.conflicted??[]).map(M=>({path:M.path,staged:!1,status:M.status})),...E.staged.map(M=>({path:M.path,staged:!0,status:M.status})),...E.unstaged.map(M=>({path:M.path,staged:!1,status:M.status})),...E.untracked.map(M=>({path:M.path,staged:!1,status:M.status}))]:[],[E]),y=l.useMemo(()=>i.map(M=>M.id),[i]);gd({sessionIds:y,activeSessionId:e,gitFiles:k,onSelectSession:h,onNewSession:D,onStageFile:M=>I.mutate([M]),onUnstageFile:M=>c.mutate([M]),onRestoreFile:M=>n.mutate([M]),onDeleteFile:M=>{d({title:"Delete File",message:`Delete ${M}? This will permanently remove the untracked file.`,confirmLabel:"Delete",variant:"destructive",onConfirm:async()=>{await C.mutateAsync([M])}})},onStageAll:()=>{const M=k.filter(x=>!x.staged).map(x=>x.path);M.length>0&&I.mutate(M)},onUnstageAll:()=>{const M=k.filter(x=>x.staged).map(x=>x.path);M.length>0&&c.mutate(M)},onOpenCommitModal:B,onViewDiff:a,onReturnToInput:u}),l.useEffect(()=>{e&&u()},[e,u]);const G=l.useMemo(()=>e?t.jsxs(t.Fragment,{children:[t.jsx(rl,{sessionId:e,onSelectSession:h}),t.jsx(bC,{ref:A,sessionId:e,onNewSession:D,onDeleteSession:w})]}):t.jsx("div",{className:"flex-1 flex items-center justify-center text-muted-foreground",children:"Select a session or create a new one to start"}),[e,D,h,w]);return t.jsxs(t.Fragment,{children:[t.jsx(rd,{onNewSession:D,theme:o,onToggleTheme:Q,sessionId:e,onNavigateToSession:h,onFixWithAI:m,sidebar:t.jsx(nl,{activeSessionId:e,onSelectSession:h}),children:G}),t.jsx(bE,{})]})}const Ed=os("/sessions/")({component:nd});function nd(){return t.jsx(KB,{})}const JB=os("/sessions/$sessionId")({component:Cd});function Cd(){const{sessionId:e}=JB.useParams();return t.jsx(KB,{sessionId:e})}const Id=Qd.update({id:"/",path:"/",getParentRoute:()=>Dg}),ld=Ed.update({id:"/sessions/",path:"/sessions/",getParentRoute:()=>Dg}),cd=JB.update({id:"/sessions/$sessionId",path:"/sessions/$sessionId",getParentRoute:()=>Dg}),dd={IndexRoute:Id,SessionsSessionIdRoute:cd,SessionsIndexRoute:ld},ud=Dg._addFileChildren(dd)._addFileTypes(),hd=()=>{const g=(typeof globalThis<"u"?globalThis.OTTO_ROUTER_BASEPATH:void 0)??"/"??"/";if(!g||g==="/")return"/";const s=g.replace(/\/+$/,"")||"/";return s.startsWith("/")?s:`/${s}`},Dd=PB({routeTree:ud,basepath:hd()}),Us=new WB({defaultOptions:{queries:{refetchOnWindowFocus:!1,retry:1,structuralSharing:!0}}});Us.prefetchQuery({queryKey:["sessions"],queryFn:()=>v.getSessions()});Us.prefetchQuery({queryKey:["config"],queryFn:()=>v.getConfig()});function pd(){return t.jsx(zB,{client:Us,children:t.jsx(VB,{router:Dd})})}const RB=document.getElementById("root");if(!RB)throw new Error("Root element not found");jB.createRoot(RB).render(t.jsx(l.StrictMode,{children:t.jsx(pd,{})}));