@seqyuan/ennote 0.15.0 → 0.15.1
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.
- package/out/404.html +1 -1
- package/out/__next.__PAGE__.txt +2 -2
- package/out/__next._full.txt +2 -2
- package/out/__next._head.txt +1 -1
- package/out/__next._index.txt +1 -1
- package/out/__next._tree.txt +1 -1
- package/out/_next/static/chunks/{0upcnmb.rkk-u.js → 0j5p~dc9hcv56.js} +1 -1
- package/out/_not-found/__next._full.txt +1 -1
- package/out/_not-found/__next._head.txt +1 -1
- package/out/_not-found/__next._index.txt +1 -1
- package/out/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/out/_not-found/__next._not-found.txt +1 -1
- package/out/_not-found/__next._tree.txt +1 -1
- package/out/_not-found.html +1 -1
- package/out/_not-found.txt +1 -1
- package/out/graphs/__next._full.txt +2 -2
- package/out/graphs/__next._head.txt +1 -1
- package/out/graphs/__next._index.txt +1 -1
- package/out/graphs/__next._tree.txt +1 -1
- package/out/graphs/__next.graphs.__PAGE__.txt +2 -2
- package/out/graphs/__next.graphs.txt +1 -1
- package/out/graphs.html +1 -1
- package/out/graphs.txt +2 -2
- package/out/heroes/__next._full.txt +2 -2
- package/out/heroes/__next._head.txt +1 -1
- package/out/heroes/__next._index.txt +1 -1
- package/out/heroes/__next._tree.txt +1 -1
- package/out/heroes/__next.heroes.__PAGE__.txt +2 -2
- package/out/heroes/__next.heroes.txt +1 -1
- package/out/heroes.html +1 -1
- package/out/heroes.txt +2 -2
- package/out/index.html +2 -2
- package/out/index.txt +2 -2
- package/package.json +1 -1
- /package/out/_next/static/{NNcQQusKb3xj-mW5pnt-E → QzO4obvIvhjjd6K9KPuvm}/_buildManifest.js +0 -0
- /package/out/_next/static/{NNcQQusKb3xj-mW5pnt-E → QzO4obvIvhjjd6K9KPuvm}/_clientMiddlewareManifest.js +0 -0
- /package/out/_next/static/{NNcQQusKb3xj-mW5pnt-E → QzO4obvIvhjjd6K9KPuvm}/_ssgManifest.js +0 -0
|
@@ -3,6 +3,6 @@
|
|
|
3
3
|
>
|
|
4
4
|
> — ${t}`}function rD({history:e,run:a,branches:i,composer:s,actions:r,error:l,clearError:o,projects:c,selectedProject:d,hasModel:u,pinnedProjectIds:p,togglePinProject:h,onSwitchProject:g,onNewProject:x,onOpenSettings:v}){let y=(0,f.useT)(),b=(0,n.useRef)(null),k=(0,n.useRef)(null),j=(0,n.useRef)(!1),w=(0,n.useRef)(0),N=(0,n.useRef)(0),[_,C]=(0,n.useState)(!0),[S,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)(0),M=rF(),R="waiting_for_approval"===a.activeRunStatus||"waiting_delegation_admission"===a.activeRunStatus||!!a.pendingApproval,E=a.pendingApproval?.kind==="question",A=sI(a.status).code===sN&&!R,$=(0,n.useCallback)(()=>{0===c.length?x():M.open?M.close():M.openDropdown()},[M,x,c.length]);async function z(){let t=b.current;if(!t)return;let n=t.scrollHeight,a=t.scrollTop;j.current=!0,await e.loadOlder()?requestAnimationFrame(()=>requestAnimationFrame(()=>{t.scrollTop=a+(t.scrollHeight-n),j.current=!1,w.current=e.messages.length})):j.current=!1}(0,n.useEffect)(()=>{let t=b.current;if(!t||j.current)return;let n=t.scrollHeight-t.scrollTop-t.clientHeight<120;(0===w.current||n)&&k.current?.scrollIntoView({behavior:0===w.current?"auto":"smooth"}),w.current=e.messages.length},[e.messages,a.status]),(0,n.useEffect)(()=>{w.current=0,N.current=0,queueMicrotask(()=>{C(!0),I(!1)})},[e.activeBranchId,e.sessionId]);let F=!!e.sessionId&&!e.activeLeafMessageId&&0===e.messages.length&&!a.activeRun&&!a.pendingApproval,L=!e.sessionId||F,D=function(e,{enabled:t=!0,minWidth:a=640}={}){let[i,s]=(0,n.useState)(null),r=(0,n.useRef)(null);return(0,n.useEffect)(()=>{if(!t)return;let n=e.current;if(!n)return;let i=()=>s(null),l=()=>{null!==r.current&&window.clearTimeout(r.current),r.current=window.setTimeout(()=>{r.current=null,(()=>{if(window.innerWidth<a)return s(null);let e=window.getSelection();if(!e||e.isCollapsed||0===e.rangeCount)return s(null);let t=e.getRangeAt(0),i=t.commonAncestorContainer,r=i instanceof Element?i:i.parentElement;if(!r||!n.contains(r)||r.closest("input, textarea, [contenteditable='true']"))return s(null);let l=e.toString();if(0===l.trim().length)return s(null);let o=t.getBoundingClientRect();0===o.width&&0===o.height?s(null):s({text:l,rect:{top:o.top,bottom:o.bottom,left:o.left,width:o.width}})})()},120)};return document.addEventListener("selectionchange",l),document.addEventListener("pointerup",l),window.addEventListener("resize",i),n.addEventListener("scroll",i,{passive:!0}),()=>{document.removeEventListener("selectionchange",l),document.removeEventListener("pointerup",l),window.removeEventListener("resize",i),n.removeEventListener("scroll",i),null!==r.current&&window.clearTimeout(r.current),r.current=null}},[e,t,a]),{selection:t?i:null,clear:(0,n.useCallback)(()=>{s(null),window.getSelection()?.removeAllRanges()},[])}}(b,{enabled:!L}),{clear:O}=D,q=(0,n.useCallback)(e=>{let t=rL(e,y("selection.source.chat"));t&&(s.setInput([s.input,t].filter(Boolean).join("\n\n")),O(),T(e=>e+1))},[O,s,y]),B=(0,n.useCallback)(e=>{let t=rL(e,y("selection.source.chat"));if(t){var n;s.setInput([s.input,(n=y("selection.explainPrompt"),`${n}
|
|
5
5
|
|
|
6
|
-
${t}`)].filter(Boolean).join("\n\n")),O(),T(e=>e+1)}},[O,s,y]);(0,n.useEffect)(()=>{let e=b.current;if(!e)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;C(t),t&&I(!1)};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[e.sessionId,L]),(0,n.useEffect)(()=>{let t=e.messages.length;t>N.current&&N.current>0&&!_&&I(!0),N.current=t},[e.messages.length,_]);let U=(0,n.useCallback)(()=>{let e=b.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),I(!1))},[]);return(0,t.jsxs)("main",{className:"chat-area","data-phase":L?"welcome":"active",children:[l&&(0,t.jsxs)("div",{className:"error-bar",role:"alert",children:[(0,t.jsx)("span",{children:l}),(0,t.jsx)("button",{onClick:o,"aria-label":y("conversation.chat.dismissError"),children:(0,t.jsx)(m,{size:15,"aria-hidden":"true"})})]}),a.recovery&&(0,t.jsxs)("div",{className:`recovery-bar ${a.recovery.retryable?"is-retryable":"is-blocked"}`,"data-testid":"run-recovery",children:[(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:"interrupted"===a.recovery.run.status?y("conversation.chat.runInterrupted"):y("conversation.chat.runFailed")}),a.recovery.retryable?y("conversation.chat.attemptRetryable",{attempt:String(a.recovery.run.attempt)}):function(e,t){switch(e){case"side_effect_boundary":return t("conversation.chat.recovery.sideEffect");case"projected_output":return t("conversation.chat.recovery.projectedOutput");case"active_run":return t("conversation.chat.recovery.activeRun");default:return t("conversation.chat.recovery.notActive")}}(a.recovery.blockedReason,y)]}),a.recovery.retryable&&(0,t.jsx)("button",{type:"button",onClick:a.retryRun,disabled:a.retrying||!!a.activeRun,children:a.retrying?y("conversation.chat.retrying"):y("conversation.chat.retry")})]}),!L&&(0,t.jsxs)("div",{className:"chat-scroll-region",children:[(0,t.jsx)("div",{className:"messages",ref:b,"data-testid":"chat-messages",children:(0,t.jsxs)("div",{className:"conversation-viewport",children:[e.hasMore&&(0,t.jsx)("div",{className:"history-control",children:(0,t.jsx)("button",{type:"button",onClick:z,disabled:e.loadingOlder,children:e.loadingOlder?y("conversation.chat.loadingEarlier"):y("conversation.chat.loadEarlier")})}),e.loading&&(0,t.jsx)("div",{className:"history-state",children:y("conversation.chat.loading")}),e.error&&(0,t.jsx)("div",{className:"history-state history-state-error",children:y("conversation.chat.historyUnavailable",{message:e.error})}),!e.loading&&0===e.messages.length&&!e.error&&!a.pendingApproval&&(0,t.jsxs)("div",{className:"history-empty",children:[(0,t.jsx)("strong",{children:y("conversation.chat.newConversation")}),(0,t.jsx)("span",{children:y("conversation.chat.startHint")})]}),(0,t.jsx)(r$,{sessionId:e.sessionId??"",nodes:e.messages,pendingApproval:a.pendingApproval,resolvingApproval:a.resolvingApproval,decideApproval:a.decideApproval,answeringQuestion:a.answeringQuestion,answerQuestion:a.answerQuestion,activeLeafMessageId:e.activeLeafMessageId,branchDisabled:!!a.activeRun||i.changing,createBranch:i.createBranch,runStatus:a.activeRun||a.status?{status:a.status,active:!!a.activeRun,waiting:R,waitingForQuestion:E,reconnecting:A,compacting:a.compacting,startedAt:a.startedAt,runId:a.activeRun,cacheReadTokens:a.usage?.cacheReadTokens??0,inputTokens:(a.usage?.uncachedInputTokens??0)+(a.usage?.cacheReadTokens??0)+(a.usage?.cacheWriteTokens??0),outputTokens:a.usage?.outputTokens??0}:void 0}),(0,t.jsx)("div",{ref:k})]})}),(0,t.jsx)(J,{nodes:e.messages,scrollContainer:b}),!_&&(0,t.jsxs)("button",{type:"button",className:"chat-jump-latest","data-new":S||void 0,onClick:U,"aria-label":y(S?"conversation.newMessages":"conversation.jumpLatest"),children:[(0,t.jsx)(K,{size:14,"aria-hidden":"true"}),y(S?"conversation.newMessages":"conversation.jumpLatest")]})]}),!L&&D.selection&&(0,t.jsx)(et,{selection:D.selection,onQuote:q,onExplain:B,onDismiss:O}),!L&&(0,t.jsx)(e8,{sessionId:e.sessionId??void 0}),!L&&s.compaction.open&&(0,t.jsx)(te,{value:s.compaction.instructions,onChange:s.compaction.setInstructions,busy:s.compaction.busy,onConfirm:s.compaction.confirm,onCancel:s.compaction.cancel}),(0,t.jsx)("div",{className:"composer-seat",children:(0,t.jsxs)("div",{className:L?"composer-stack composer-welcome":"composer-stack",children:[L&&(0,t.jsx)(eJ,{}),L&&(0,t.jsx)(eY,{hasModel:u,onOpenSettings:v}),L&&(0,t.jsx)("div",{className:"welcome-workspace-row",children:(0,t.jsx)(eQ,{projects:c,selectedProject:d,pinnedProjectIds:p,togglePinProject:h,onRequestProject:$,onSwitchProject:g,projectSelector:M})}),(0,t.jsx)(eG,{selectedSession:e.sessionId,activeLeafMessageId:e.activeLeafMessageId,input:s.input,setInput:s.setInput,focusNonce:P,activeRun:!!a.activeRun,questionPending:!!E,compacting:a.compacting,hasPendingImage:!!s.pendingImage,reconnecting:A,inert:!d,welcome:L,onRequestProject:$,permissionMode:s.displayedPermissionMode,permissionReady:s.permissionReady,setPermissionMode:s.setPermissionMode,models:s.models,providers:s.providers,selectedModelId:s.selectedModelId,setSelectedModelId:s.setSelectedModelId,thinkingEffort:s.thinkingEffort,setThinkingEffort:s.setThinkingEffort,textAttachments:s.textAttachments,removeTextAttachment:s.removeTextAttachment,pendingImage:s.pendingImage,clearPendingImage:s.clearPendingImage,attachFiles:s.attachFiles,uploadImage:s.uploadImage,submit:r.submit,steer:r.steer,steerText:r.steerText,followUp:r.followUp,cancel:a.cancel,cancelFollowUp:a.cancelFollowUp,compactSession:s.compactSession,pendingFollowUps:a.pendingFollowUps,picker:{templates:s.promptPanel.templates,heroes:s.promptPanel.heroes,graphs:s.promptPanel.flows,skills:s.promptPanel.skills,pendingSkills:s.promptPanel.pendingSkills,pendingGraph:s.promptPanel.pendingGraph,selectedHeroId:s.selectedHeroId,onSelectTemplate:s.promptPanel.onSelect,onSelectHero:s.promptPanel.onHeroSelect,onSelectGraph:s.promptPanel.onFlowSelect,onToggleSkill:s.promptPanel.toggleSkill,onClearGraph:s.promptPanel.clearPendingGraph},expanding:s.promptPanel.expanding,expandDiag:s.promptPanel.expandDiag,contextUsage:a.contextUsage,stats:a.stats})]})})]})}let rO=o("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]),rq=o("panel-right",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),rB=o("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),rU=o("shield-check",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);function rH({item:e,onNavigate:n,onDismiss:a}){let i,s=(0,f.useT)(),r=!e.requiresAction;return(0,t.jsxs)("div",{className:"attention-row",role:"listitem","data-kind":e.kind,"data-attention-id":e.id,children:[(0,t.jsx)("span",{className:"attention-icon",children:(i={size:13,"aria-hidden":!0},"needs_input"===e.kind?(0,t.jsx)(sQ,{...i}):"approval_required"===e.kind?(0,t.jsx)(rU,{...i}):(e.kind,(0,t.jsx)(e0,{...i})))}),(0,t.jsxs)("button",{type:"button",className:"attention-main",onClick:()=>n(e),children:[(0,t.jsx)("strong",{children:function(e,t){let n=e.display;switch(e.kind){case"approval_required":return t(n?.kind==="retry_budget"?"conversation.attention.retryBudget":"conversation.attention.approvalRequired");case"needs_input":if(n?.kind==="question"){let e=n.questionCount??0;return t(1===e?"conversation.attention.questionOne":"conversation.attention.questionMany",{count:e})}return t("conversation.attention.needsInput");case"delegation_completed":return t("conversation.attention.completed");case"delegation_failed":return t("conversation.attention.failed")}return t("conversation.attention.title")}(e,s)}),(0,t.jsx)("span",{children:e.display?.summary??e.sessionId})]}),r?(0,t.jsx)("button",{type:"button",className:"attention-dismiss","aria-label":s("conversation.attention.dismiss"),title:s("conversation.attention.dismiss"),onClick:()=>a(e),children:(0,t.jsx)(m,{size:13,"aria-hidden":"true"})}):(0,t.jsx)("span",{className:"attention-action-tag",children:function(e,t){switch(e){case"answer_question":return t("conversation.attention.actionAnswerQuestion");case"tool_approval":return t("conversation.attention.actionToolApproval");case"delegation_approval":return t("conversation.attention.actionDelegationApproval");case"delegation_input":return t("conversation.attention.actionDelegationInput")}return t("conversation.attention.action")}(e.action?.kind,s)})]})}function rW({projectId:e,onNavigate:a}){let i=(0,f.useT)(),{items:s,pendingCount:r,refresh:l}=function(e){let[t,a]=(0,n.useState)([]),[i,s]=(0,n.useState)(0);(0,n.useEffect)(()=>{let t;if(!e)return;let n=new AbortController,i=async()=>{try{let t=await (0,e3.apiFetch)(`/v1/attention?projectId=${encodeURIComponent(e)}&status=pending&limit=50`,{signal:n.signal});n.signal.aborted||a(t.items??[])}catch{}finally{n.signal.aborted||(t=window.setTimeout(i,5e3))}};return i(),()=>{n.abort(),void 0!==t&&window.clearTimeout(t)}},[e,i]);let r=(0,n.useMemo)(()=>t.filter(e=>"pending"===e.status).length,[t]);return{items:t,pendingCount:r,refresh:()=>s(e=>e+1)}}(e),[o,c]=(0,n.useState)(!1),d=(0,n.useRef)(null);M(o,()=>c(!1)),(0,n.useEffect)(()=>{if(!o)return;let e=e=>{d.current?.contains(e.target)||c(!1)};return document.addEventListener("pointerdown",e),()=>document.removeEventListener("pointerdown",e)},[o]);let u=async e=>{try{await (0,e3.apiFetch)(`/v1/attention/${encodeURIComponent(e.id)}/dismiss`,{method:"POST",body:JSON.stringify({clientRequestId:crypto.randomUUID()})}),l()}catch{l()}},p=[...s].sort((e,t)=>!!t.requiresAction-!!e.requiresAction);return(0,t.jsxs)("div",{className:"attention-panel",ref:d,children:[(0,t.jsxs)("button",{type:"button",className:"attention-bell","aria-label":i("conversation.attention.aria",{count:String(r)}),title:i("conversation.attention.title"),onClick:()=>c(e=>!e),children:[(0,t.jsx)(rB,{size:15,"aria-hidden":"true"}),r>0&&(0,t.jsx)("span",{className:"attention-badge",children:r>99?"99+":r})]}),o&&(0,t.jsxs)("div",{className:"attention-popover",role:"dialog","aria-label":i("conversation.attention.title"),children:[(0,t.jsxs)("div",{className:"attention-popover-header",children:[(0,t.jsx)("strong",{children:i("conversation.attention.title")}),(0,t.jsx)("span",{children:i("conversation.attention.pending",{count:String(r)})})]}),(0,t.jsxs)("div",{className:"attention-list",role:"list",children:[0===p.length&&(0,t.jsx)("div",{className:"attention-empty",children:i("conversation.attention.empty")}),p.map(e=>(0,t.jsx)(rH,{item:e,onNavigate:e=>{c(!1),a(e)},onDismiss:u},e.id))]})]})]})}let rV=o("git-branch",[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]);function rK({branches:e,activeBranchId:a,loading:i,changing:s,disabled:r,activate:l}){let[o,c]=(0,n.useState)(!1),d=(0,n.useRef)(null),u=e.find(e=>e.id===a);return M(o,()=>c(!1)),(0,n.useEffect)(()=>{if(!o)return;let e=e=>{d.current?.contains(e.target)||c(!1)};return window.addEventListener("pointerdown",e),()=>window.removeEventListener("pointerdown",e)},[o]),(0,t.jsxs)("div",{className:"branch-control",ref:d,children:[(0,t.jsxs)("button",{type:"button",className:"branch-trigger","aria-label":"Choose conversation branch",title:"Choose conversation branch","aria-haspopup":"menu","aria-expanded":o,disabled:r||i||s,onClick:()=>c(e=>!e),children:[(0,t.jsx)(rV,{size:15,"aria-hidden":"true"}),(0,t.jsx)("span",{children:u?.label??(i?"Loading":"Main")}),e.length>1&&(0,t.jsx)("small",{children:e.length})]}),o&&(0,t.jsx)("div",{className:"branch-menu",role:"menu","aria-label":"Conversation branches",children:e.map(e=>(0,t.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":e.id===a,onClick:()=>{c(!1),l(e.id)},children:[(0,t.jsx)(rV,{size:14,"aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e.label}),(0,t.jsxs)("small",{children:[e.messageCount," messages"]})]}),e.id===a&&(0,t.jsx)(Y,{size:14,"aria-hidden":"true"})]},e.id))})]})}let rG=o("moon",[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]),rJ=o("sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]),rY=new Set;function rQ(){let e=window.localStorage.getItem("ennote-theme");return"light"===e||"dark"===e?e:"system"}function rZ(e=rQ()){return"dark"===e?"dark":"light"===e?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function rX(){let e=rQ();return`${e}:${rZ(e)}`}function r0(e){rY.add(e);let t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>{"system"===rQ()&&(r1(rZ("system")),rY.forEach(e=>e()))},a=e=>{"ennote-theme"===e.key&&(r1(rZ()),rY.forEach(e=>e()))};return t.addEventListener("change",n),window.addEventListener("storage",a),()=>{rY.delete(e),t.removeEventListener("change",n),window.removeEventListener("storage",a)}}function r1(e){document.documentElement.classList.toggle("dark","dark"===e),document.documentElement.dataset.theme=e}function r2(e,t){let n=()=>{"system"===e?window.localStorage.removeItem("ennote-theme"):window.localStorage.setItem("ennote-theme",e),r1(rZ(e)),rY.forEach(e=>e())},a=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||a)return void n();let i=t?.x??window.innerWidth/2,s=t?.y??window.innerHeight/2,r=Math.hypot(Math.max(i,window.innerWidth-i),Math.max(s,window.innerHeight-s));document.startViewTransition(n).ready.then(()=>document.documentElement.animate({clipPath:[`circle(0 at ${i}px ${s}px)`,`circle(${r}px at ${i}px ${s}px)`]},{duration:420,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})).catch(()=>void 0)}function r4(){let[e,t]=(0,n.useSyncExternalStore)(r0,rX,()=>"system:light").split(":"),a=(0,n.useCallback)((e,t)=>r2(e,t),[]),i=(0,n.useCallback)(e=>r2("dark"===t?"light":"dark",e),[t]);return{mode:e,theme:t,isDark:"dark"===t,setThemeMode:a,toggleTheme:i}}function r5(){let{isDark:e,toggleTheme:n}=r4();return(0,t.jsx)(ru,{label:e?"Switch to light mode":"Switch to dark mode",title:e?"Switch to light mode":"Switch to dark mode","aria-pressed":e,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();n({x:t.left+t.width/2,y:t.top+t.height/2})},children:e?(0,t.jsx)(rJ,{size:15,"aria-hidden":"true"}):(0,t.jsx)(rG,{size:15,"aria-hidden":"true"})})}function r3(e){let{sidebarOpen:n,onToggleSidebar:a,navigationTriggerRef:i,session:s,title:r,projectName:l,projectPath:o,branch:c,rightPanelOpen:d,onToggleRightPanel:u,attention:p}=e,{title:h,editing:m,draft:f,setDraft:x,startEdit:v,save:y,keyDown:b,inputRef:k}=r;return(0,t.jsxs)("div",{className:"app-topbar",children:[(0,t.jsx)(ru,{ref:i,label:n?"Hide navigation":"Open navigation",title:n?"Hide sidebar":"Show sidebar","aria-expanded":n,"aria-controls":"workspace-navigation",onClick:a,children:n?(0,t.jsx)(g,{size:16,"aria-hidden":"true"}):(0,t.jsx)(rO,{size:18,"aria-hidden":"true"})}),(0,t.jsxs)("div",{className:"topbar-title-area",children:[(0,t.jsx)("div",{className:"topbar-title-group",children:m&&s?(0,t.jsx)("input",{ref:k,className:"topbar-title-input",value:f,onChange:e=>x(e.target.value),onKeyDown:b,onBlur:()=>void y()}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"topbar-session-title",title:h,children:h}),s&&(0,t.jsx)("button",{type:"button",className:"topbar-title-edit",onClick:v,title:"Rename session","aria-label":"Rename session",children:(0,t.jsx)(C,{size:12,"aria-hidden":"true"})})]})}),l&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"topbar-project-sep",children:"/"}),(0,t.jsx)("span",{className:"topbar-project-crumb",title:o||l,children:l})]})]}),s&&(0,t.jsx)(rK,{branches:c.branches,activeBranchId:c.activeBranchId,loading:c.loading,changing:c.changing,disabled:c.disabled,activate:c.onActivate}),(0,t.jsx)(r5,{}),(0,t.jsx)(ru,{label:d?"Hide panel":"Show panel",title:d?"Hide panel":"Show panel",active:d,onClick:u,children:(0,t.jsx)(rq,{size:16,"aria-hidden":"true"})}),(0,t.jsx)(rW,{projectId:p.projectId,onNavigate:p.onNavigate})]})}let r6=o("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),r8=o("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),r9=o("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]),r7=o("file-exclamation-point",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function le(e,t){let n=new URLSearchParams({path:t});return`/v1/projects/${encodeURIComponent(e)}/files/content?${n.toString()}`}async function lt(e,t="/workspace",n){let a;return(0,e3.apiFetch)((a=new URLSearchParams({path:t}),`/v1/projects/${encodeURIComponent(e)}/files?${a.toString()}`),{signal:n})}async function ln(e,t,n){let a=await (0,e3.apiResponse)(le(e,t),{signal:n});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??`HTTP ${a.status}`)}return a}function la(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n<=0?{parent:"/workspace",name:t}:{parent:t.slice(0,n),name:t.slice(n+1)}}async function li(e,t){return(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function ls(e,t){return(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files/move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function lr(e,t,n={}){let a=new URLSearchParams({path:t});n.recursive&&a.set("recursive","true"),await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files?${a.toString()}`,{method:"DELETE"})}let ll=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),lo=new Set(["md","mdx","rmd","qmd"]),lc=new Set(["txt","json","yaml","yml","toml","csv","tsv","log","ts","tsx","js","jsx","mjs","cjs","py","r","rb","go","rs","java","c","cpp","h","hpp","css","scss","less","html","htm","xml","sh","bash","zsh","fish","ps1","bat","sql","graphql","gql","conf","cfg","ini","properties"]);function ld({projectId:a,filePath:i,fileName:s}){var r;let[l,o]=(0,n.useState)({kind:"loading"}),c=s??i.split("/").pop()??i,d=lu(c);(0,n.useEffect)(()=>{let t=new AbortController,n=null;return async function(){o({kind:"loading"});try{var s,r,l;let u,p,h=await ln(a,i,t.signal),m=Number(h.headers.get("Content-Length")??0),f=h.headers.get("Content-Type")?.split(";",1)[0]??"application/octet-stream";if(lo.has(d)){if(m>4194304)throw Error("Text preview exceeds the 4 MiB limit");let e=await h.text();t.signal.aborted||o({kind:"markdown",content:e,size:e.length});return}if(s=c,r=f,u=lu(s),p=s.toLowerCase(),r.startsWith("text/")||lc.has(u)||["dockerfile","makefile"].includes(p)||p.startsWith(".env")){let n,a;if(m>4194304)throw Error("Text preview exceeds the 4 MiB limit");let i=await h.text(),s=(l=c,n=lu(l),a=l.toLowerCase(),"dockerfile"===a?"dockerfile":"makefile"===a?"makefile":({ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",py:"python",r:"r",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",json:"json",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"fish",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql"})[n]??null),r=null;if(s)try{let{codeToHtml:t}=await e.A(140);r=await t(i,{lang:s,themes:{light:"github-light",dark:"github-dark"},defaultColor:!1})}catch{r=null}t.signal.aborted||o({kind:"code",content:i,highlighted:r,language:s??"text",size:i.length});return}if(ll.has(d)||f.startsWith("image/")){let e=await h.blob();n=URL.createObjectURL(e),t.signal.aborted||o({kind:"image",url:n,mime:f,size:e.size});return}if("pdf"===d||"application/pdf"===f){let e=await h.blob();n=URL.createObjectURL(e),t.signal.aborted||o({kind:"pdf",url:n,mime:f,size:e.size});return}o({kind:"unsupported",mime:f,size:m})}catch(e){t.signal.aborted||o({kind:"error",message:e.message})}}(),()=>{t.abort(),n&&URL.revokeObjectURL(n)}},[d,i,c,a]);let u="size"in l?(r=l.size)?r<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`:"0 B":null,p="code"===l.kind?l.language:d||l.kind,h=(0,e3.workerAPIPath)(le(a,i));return(0,t.jsxs)("div",{className:"file-viewer",children:[(0,t.jsxs)("div",{className:"file-viewer-status",children:[(0,t.jsx)("span",{className:"file-viewer-type",children:p}),(0,t.jsx)("span",{className:"file-viewer-path",title:i,children:i}),u&&(0,t.jsx)("span",{children:u}),(0,t.jsx)("a",{className:"file-viewer-download",href:h,download:c,title:"Download file","aria-label":`Download ${c}`,children:(0,t.jsx)(sz,{size:13,"aria-hidden":"true"})})]}),(0,t.jsxs)("div",{className:"file-viewer-body",children:["loading"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty",children:[(0,t.jsx)(eZ,{className:"spin",size:18}),"Loading preview..."]}),"error"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty is-error",children:[(0,t.jsx)(r7,{size:20}),l.message]}),"markdown"===l.kind&&(0,t.jsx)("article",{className:"markdown-body file-markdown",children:(0,t.jsx)(a7,{remarkPlugins:[sp],children:l.content})}),"code"===l.kind&&l.highlighted&&(0,t.jsx)("div",{className:"file-code",dangerouslySetInnerHTML:{__html:l.highlighted}}),"code"===l.kind&&!l.highlighted&&(0,t.jsx)("pre",{className:"file-code-plain",children:l.content}),"image"===l.kind&&(0,t.jsx)("div",{className:"file-image-stage",children:(0,t.jsx)("img",{src:l.url,alt:c})}),"pdf"===l.kind&&(0,t.jsx)("iframe",{className:"file-pdf",src:l.url,title:c}),"unsupported"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty",children:[(0,t.jsx)(r7,{size:20}),"Preview is not available for ",l.mime,"."]})]})]})}function lu(e){return e.includes(".")?e.toLowerCase().split(".").pop()??"":""}var lp=e.i(51535);let lh="var(--text-dim)";function lm({size:e=14,open:n=!1}){return n?(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,t.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:lh}),(0,t.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.12"})]}):(0,t.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:(0,t.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.1"})})}function lf({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,t.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.08"}),(0,t.jsx)("path",{d:"M10 2v3h3",stroke:lh,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function lg({label:e,size:n=14}){return(0,t.jsxs)("svg",{width:n,height:n,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:"3.4",fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:lh,children:e})]})}function lx({size:e=14}){return(0,t.jsx)(lg,{label:"PY",size:e})}function lv({size:e=14}){return(0,t.jsx)(lg,{label:"R",size:e})}function ly({size:e=14}){return(0,t.jsx)(lg,{label:"TS",size:e})}function lb({size:e=14}){return(0,t.jsx)(lg,{label:"JS",size:e})}function lk({size:e=14}){return(0,t.jsx)(lg,{label:"{}",size:e})}function lj({size:e=14}){return(0,t.jsx)(lg,{label:"CSS",size:e})}function lw({size:e=14}){return(0,t.jsx)(lg,{label:"HTM",size:e})}function lN({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:lh,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,t.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:lh,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function l_({size:e=14}){return(0,t.jsx)(lg,{label:"YML",size:e})}function lC({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:lh,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,t.jsx)("path",{d:"M7.5 10.5h2.5",stroke:lh,strokeWidth:"0.95",strokeLinecap:"round"})]})}function lS({size:e=14}){return(0,t.jsx)(lg,{label:"GO",size:e})}function lI({size:e=14}){return(0,t.jsx)(lg,{label:"RS",size:e})}function lP({size:e=14}){return(0,t.jsx)(lg,{label:"SQL",size:e})}function lT({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"}),(0,t.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"}),(0,t.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"})]})}function lM({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:lh,strokeWidth:"0.9"}),(0,t.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:lh,strokeWidth:"0.8",strokeLinecap:"round"})]})}function lR(e,n=14){let a=e.toLowerCase(),i=a.split(".").pop()??"";return"dockerfile"===a||a.startsWith("dockerfile.")?(0,t.jsx)(lT,{size:n}):"py"===i?(0,t.jsx)(lx,{size:n}):"r"===i||"rds"===i||"qs"===i?(0,t.jsx)(lv,{size:n}):"ts"===i?(0,t.jsx)(ly,{size:n}):"tsx"===i?(0,t.jsx)(lg,{label:"TSX",size:n}):"js"===i||"mjs"===i||"cjs"===i?(0,t.jsx)(lb,{size:n}):"jsx"===i?(0,t.jsx)(lg,{label:"JSX",size:n}):"json"===i||"jsonl"===i?(0,t.jsx)(lk,{size:n}):"css"===i||"less"===i?(0,t.jsx)(lj,{size:n}):"scss"===i?(0,t.jsx)(lg,{label:"SC",size:n}):"html"===i||"htm"===i?(0,t.jsx)(lw,{size:n}):"md"===i||"mdx"===i?(0,t.jsx)(lN,{size:n}):"yaml"===i||"yml"===i?(0,t.jsx)(l_,{size:n}):"toml"===i?(0,t.jsx)(lg,{label:"TOM",size:n}):"sh"===i||"bash"===i||"zsh"===i||"fish"===i?(0,t.jsx)(lC,{size:n}):"rs"===i?(0,t.jsx)(lI,{size:n}):"go"===i?(0,t.jsx)(lS,{size:n}):"sql"===i?(0,t.jsx)(lP,{size:n}):"tf"===i||"hcl"===i?(0,t.jsx)(lg,{label:"TF",size:n}):"lock"===i?(0,t.jsx)(lg,{label:"LK",size:n}):i.endsWith("config.ts")||i.endsWith("config.js")||i.endsWith("config.mjs")?(0,t.jsx)(lM,{size:n}):(0,t.jsx)(lf,{size:n})}function lE({tabs:e,activeTabId:a,onSelectTab:i,onCloseTab:s,onReorder:r,closeLabel:l}){let[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),p=()=>{c(null),u(null)};return(0,t.jsx)("div",{role:"tablist","aria-label":"Workspace panel tabs",className:lp.default.bar,children:e.map((n,f)=>{let g=n.id===a,x=!1!==n.closable;return(0,t.jsxs)("div",{role:"tab",tabIndex:g?0:-1,"aria-selected":g,onClick:()=>i(n.id),draggable:!!r,"data-dragging":o===n.id||void 0,"data-drop-target":d===n.id||void 0,onDragStart:e=>{r&&(c(n.id),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",n.id))},onDragOver:e=>{r&&null!==o&&o!==n.id&&(e.preventDefault(),e.dataTransfer.dropEffect="move",u(n.id))},onDragLeave:()=>u(e=>e===n.id?null:e),onDrop:e=>{if(!r)return;e.preventDefault();let t=e.dataTransfer.getData("text/plain")||o;t&&t!==n.id&&r(t,n.id),p()},onDragEnd:p,onKeyDown:t=>{if("Enter"===t.key||" "===t.key){t.preventDefault(),i(n.id);return}if("ArrowLeft"!==t.key&&"ArrowRight"!==t.key)return;t.preventDefault();let a=(f+("ArrowRight"===t.key?1:-1)+e.length)%e.length;t.altKey&&r?r(n.id,e[a].id):(i(e[a].id),t.currentTarget.parentElement?.children[a]?.focus())},className:lp.default.tab,"data-active":g||void 0,children:[(0,t.jsx)("span",{className:lp.default.icon,children:"files"===n.icon?(0,t.jsx)(w,{size:13,"aria-hidden":"true"}):"report"===n.icon?(0,t.jsx)(es,{size:13,"aria-hidden":"true"}):"tools"===n.icon?(0,t.jsx)(ta,{size:13,"aria-hidden":"true"}):"graph"===n.icon?(0,t.jsx)(h,{size:13,"aria-hidden":"true"}):lR(n.filePath??n.label,13)}),(0,t.jsx)("span",{className:lp.default.label,title:n.filePath??n.label,children:n.label}),void 0!==n.badge&&n.badge>0||n.dot?(0,t.jsxs)(t.Fragment,{children:[void 0!==n.badge&&n.badge>0&&(0,t.jsx)("span",{className:lp.default.badge,"aria-hidden":"true",children:n.badge}),n.dot&&(0,t.jsx)("span",{className:lp.default.dot,"aria-hidden":"true"}),n.signalLabel&&(0,t.jsx)("span",{className:"sr-only",children:n.signalLabel})]}):null,x&&(0,t.jsx)("button",{type:"button",className:lp.default.close,onClick:e=>{e.stopPropagation(),s(n.id)},title:"Close","aria-label":l?l(n):`Close ${n.label}`,children:(0,t.jsx)(m,{size:10,"aria-hidden":"true"})})]},n.id)})})}function lA(){document.body.style.cursor="",document.body.style.userSelect=""}function l$({side:e,onResize:a,onResizeStart:i,onResizeEnd:s,ariaLabel:r,value:l,min:o,max:c}){let d=(0,n.useRef)(null),u=(0,n.useRef)(!1),p=(0,n.useRef)(0),[h,m]=(0,n.useState)(!1),f=(0,n.useCallback)(e=>{if(!u.current)return;u.current=!1,m(!1);let t=d.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),lA(),s?.()},[s]),g=(0,n.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),u.current=!0,p.current=e.clientX,m(!0),i?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[i]),x=(0,n.useCallback)(e=>{if(!u.current)return;e.preventDefault();let t=e.clientX-p.current;p.current=e.clientX,a(t)},[a]),v=(0,n.useCallback)(e=>{e.preventDefault(),f(e.pointerId)},[f]),y=(0,n.useCallback)(e=>{f(e.pointerId)},[f]);(0,n.useEffect)(()=>()=>{u.current&&(u.current=!1,lA(),s?.())},[s]);let b=(0,n.useCallback)(e=>{if("ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;e.preventDefault();let t="ArrowRight"===e.key?16:-16;i?.(),a(t),s?.()},[a,s,i]);return(0,t.jsx)("div",{ref:d,role:"separator","aria-label":r??"Resize panel","aria-orientation":"vertical","aria-valuemin":o,"aria-valuemax":c,"aria-valuenow":l,tabIndex:0,className:`resize-handle${h?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:g,onPointerMove:x,onPointerUp:v,onPointerCancel:y,onKeyDown:b,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:"var(--layer-drag-overlay)"},children:(0,t.jsx)("div",{className:"resize-handle-line"})})}function lz(e){let t=(0,n.useCallback)(t=>{let n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)},[e]),a=(0,n.useCallback)(()=>window.matchMedia(e).matches,[e]);return(0,n.useSyncExternalStore)(t,a,()=>!1)}function lF(e,t){return Math.max(280,Math.min(1e3,e-t-440-5))}function lL(e,t){return Math.max(220,Math.min(Math.max(220,t-8-264),null!==e&&Number.isFinite(e)?e:280))}function lD(e,t){return t?"narrow":e>=520?"wide":e>=280?"medium":"narrow"}var lO=e.i(73574);function lq(e){let n=(0,f.useT)(),a=lz("(max-width: 960px)"),i=lD(e.width,a),s=lL(e.primaryWidth,e.width);if("narrow"===i)return(0,t.jsxs)("div",{className:lO.default.narrow,children:[e.narrowStrip,(0,t.jsx)("div",{className:lO.default.body,children:e.narrowBody})]});let r=null!==e.inspectorBody,l="medium"===i&&r,o=r&&!e.primaryHidden,c=r&&!l&&e.primaryHidden,d=l&&!e.navigatorOpen,u=l?{width:"min(300px, 78%)"}:c?{display:"none"}:o?{width:s}:{flex:"1 1 auto"},p=l?"medium":c?"fill":o?"wide":"single";return(0,t.jsxs)("div",{className:lO.default.lanes,"data-mode":p,"data-testid":"right-panel-lanes",children:[l&&e.navigatorOpen&&(0,t.jsx)("div",{className:lO.default.backdrop,onPointerDown:e.onToggleNavigator,"aria-hidden":"true"},"backdrop"),(0,t.jsxs)("div",{className:`${lO.default.primary}${l?` ${lO.default["primary-overlay"]}`:""}`,style:u,"data-open":l&&e.navigatorOpen||void 0,"data-parked":d||void 0,"data-testid":"right-panel-primary",inert:d,children:[e.channelStrip,(0,t.jsx)("div",{className:lO.default.body,children:e.channelBody})]},"primary"),o&&!l&&(0,t.jsx)(l$,{side:"right",ariaLabel:n("rightPanel.resizeNavigator"),value:s,min:220,max:Math.max(220,e.width-8-264),onResize:e.onResizePrimary,onResizeStart:e.onResizePrimaryStart,onResizeEnd:e.onResizePrimaryEnd},"divider"),r&&(0,t.jsxs)("div",{className:lO.default.inspector,children:[(0,t.jsxs)("div",{className:lO.default.strip,children:[e.inspectorStrip,(0,t.jsx)("button",{type:"button",className:lO.default["nav-toggle"],"aria-label":n(e.navigatorOpen?"rightPanel.hideNavigator":"rightPanel.showNavigator"),"aria-expanded":e.navigatorOpen,"data-open":e.navigatorOpen||void 0,onClick:e.onToggleNavigator,children:(0,t.jsx)(g,{size:15,"aria-hidden":"true"})})]}),(0,t.jsx)("div",{className:lO.default.body,children:e.inspectorBody})]},"inspector")]})}let lB={files:"rightPanel.files",graph:"rightPanel.graphs",tools:"rightPanel.status"},lU={files:"files",graph:"graph",tools:"tools"};function lH(e,t,n={}){return e.map(e=>({id:e,label:t(lB[e]),closable:!0,icon:lU[e],badge:n[e]?.count,dot:n[e]?.attention,signalLabel:n[e]?.count!==void 0?t("rightPanel.runsCount",{count:n[e]?.count??0}):n[e]?.attention?t("rightPanel.needsAttention"):void 0}))}let lW={files:o("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),graph:h,tools:ta};function lV(e){return(0,t.jsxs)("div",{className:"right-panel-launcher",role:"group","aria-label":e.hint,children:[(0,t.jsx)("p",{className:"right-panel-launcher-hint",children:e.hint}),e.channels.map(n=>{let a=lW[n];return(0,t.jsxs)("button",{type:"button",className:"right-panel-launcher-card",onClick:()=>e.onOpen(n),children:[(0,t.jsx)(a,{size:15,"aria-hidden":"true"}),(0,t.jsx)("span",{children:(0,e.t)(lB[n])})]},n)})]})}let lK=o("file-plus",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),lG=o("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]);function lJ(e){var n;let{entry:a,depth:i,expanded:s,loading:r,errorText:l,tabbable:o,selected:c}=e;return(0,t.jsxs)("div",{className:"file-tree-row",style:{paddingLeft:8+16*i},role:"treeitem","aria-level":i+1,"aria-expanded":a.isDir?s:void 0,"aria-selected":c||void 0,tabIndex:o?0:-1,"data-path":a.path,onClick:e.onClick,onContextMenu:e.onContextMenu,onKeyDown:e.onKeyDown,children:[(0,t.jsxs)("span",{className:"file-tree-main",title:a.path,children:[(0,t.jsx)("span",{className:"file-tree-icon",children:a.isDir?(0,t.jsx)(lm,{size:14,open:s}):lR(a.name,14)}),(0,t.jsx)("span",{className:"file-tree-name",children:a.name}),!a.isDir&&(0,t.jsx)("span",{className:"file-tree-size",children:(n=a.size)<1024?`${n} B`:n<1048576?`${(n/1024).toFixed(1)} K`:`${(n/1048576).toFixed(1)} M`}),r&&(0,t.jsx)("span",{className:"file-tree-loading",children:"..."}),l&&(0,t.jsx)("span",{className:"file-tree-error-mark",title:l,"aria-label":`Could not list ${a.name}: ${l}`,children:"!"})]}),!a.isDir&&(0,t.jsx)("button",{type:"button",className:"file-preview-action",onClick:t=>{t.stopPropagation(),e.onPreview()},"aria-label":`Preview ${a.name} in a floating window`,title:"Open floating preview",onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&e.stopPropagation()},children:(0,t.jsx)(lG,{size:12,"aria-hidden":"true"})})]})}function lY(e){let a=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let e=window.requestAnimationFrame(()=>{let e=a.current;e&&(e.focus(),e.select())});return()=>window.cancelAnimationFrame(e)},[]),(0,t.jsx)("div",{className:"file-tree-row file-tree-row-editing",style:{paddingLeft:8+16*e.depth},children:(0,t.jsxs)("span",{className:"file-tree-main",children:[(0,t.jsx)("span",{className:"file-tree-icon","aria-hidden":"true"}),(0,t.jsx)("input",{ref:a,className:"file-tree-editor","aria-label":e.label,defaultValue:e.initialValue,onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),e.onCommit(t.currentTarget.value)):"Escape"===t.key&&(t.preventDefault(),e.onCancel())},onBlur:()=>e.onCancel()})]})})}function lQ(e){let{entry:a,at:i,onClose:s}=e,r=(0,n.useRef)(null),l=a?.path??null;if((0,n.useEffect)(()=>{if(null===l)return;let e=window.requestAnimationFrame(()=>{r.current?.querySelector('[role="menuitem"]')?.focus()});return()=>window.cancelAnimationFrame(e)},[l]),!a)return null;let o=async()=>{try{await navigator.clipboard.writeText(a.path)}catch{e.onError("The clipboard is unavailable in this window.")}s()},c=e=>()=>{e(),s()};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"file-tree-menu-backdrop",onPointerDown:s,"aria-hidden":"true"}),(0,t.jsxs)("div",{ref:r,className:"file-tree-menu",role:"menu","aria-label":`Actions for ${a.name}`,style:{left:i.x,top:i.y},onKeyDown:e=>{let t=Array.from(r.current?.querySelectorAll('[role="menuitem"]')??[]),n=t.indexOf(document.activeElement);if("Escape"===e.key){e.preventDefault(),s();return}if("ArrowDown"!==e.key&&"ArrowUp"!==e.key)return;e.preventDefault();let a="ArrowDown"===e.key?1:-1;t[(n+a+t.length)%t.length]?.focus()},children:[!a.isDir&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onOpen),children:"Open"}),e.onOpenToSide&&(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onOpenToSide),children:"Open to the side"}),(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onPreview),children:"Open in floating window"})]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onNewFile),children:[(0,t.jsx)(lK,{size:12,"aria-hidden":"true"})," New file"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onNewFolder),children:[(0,t.jsx)(d,{size:12,"aria-hidden":"true"})," New folder"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onRename),children:[(0,t.jsx)(C,{size:12,"aria-hidden":"true"})," Rename"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onDelete),children:[(0,t.jsx)(P,{size:12,"aria-hidden":"true"})," Delete"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>void o(),children:[(0,t.jsx)(Q,{size:12,"aria-hidden":"true"})," Copy path"]})]})]})}function lZ({projectId:e,displayPath:a,onOpenFile:i,onOpenFileToSide:s,canOpenToSide:r=!1,onPreviewFile:l}){let[o,c]=(0,n.useState)([]),[p,h]=(0,n.useState)(!!e),[m,f]=(0,n.useState)(null),[g,x]=(0,n.useState)(new Map),[v,y]=(0,n.useState)(""),[b,k]=(0,n.useState)(new Set),[j,w]=(0,n.useState)(new Set),[N,_]=(0,n.useState)(new Map),[C,S]=(0,n.useState)(null),[I,P]=(0,n.useState)(null),T=(0,n.useRef)(new Map),M=(0,n.useRef)(36),R=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!e)return;let t=new AbortController,n=T.current;return lt(e,"/workspace",t.signal).then(e=>{c(e??[]),f(null)}).catch(e=>{t.signal.aborted||f(e.message)}).finally(()=>{t.signal.aborted||h(!1)}),()=>{t.abort(),n.forEach(e=>e.abort()),n.clear()}},[e]);let E=(0,n.useCallback)(async t=>{if(!e||N.has(t)||T.current.has(t))return;let n=new AbortController;T.current.set(t,n),w(e=>new Set(e).add(t));try{let a=await lt(e,t,n.signal);_(e=>new Map(e).set(t,a)),x(e=>{if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n})}catch(e){n.signal.aborted||(x(n=>new Map(n).set(t,e.message)),k(e=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),n}))}finally{T.current.get(t)===n&&T.current.delete(t),w(e=>{let n=new Set(e);return n.delete(t),n})}},[N,e]),A=(0,n.useCallback)(e=>{k(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),$=(0,n.useCallback)(e=>{k(t=>t.has(e)?t:new Set(t).add(e)),E(e)},[E]),z=v.trim().toLowerCase(),F=(0,n.useMemo)(()=>{let e=[],t=new Map,n=e=>{if(!z)return!0;let a=t.get(e.path);if(void 0!==a)return a;let i=e.name.toLowerCase().includes(z)||e.isDir&&(N.get(e.path)??[]).some(n);return t.set(e.path,i),i},a=(t,i,s)=>{for(let r of t){if(!n(r))continue;e.push({entry:r,depth:i,parentPath:s});let t=r.isDir&&!g.has(r.path)&&(!!z||b.has(r.path));if(!r.isDir||!t)continue;let l=N.get(r.path);l&&a(l,i+1,r.path)}};return a(o,0,null),e},[o,N,b,g,z]);(0,n.useEffect)(()=>{if(!z){M.current=36;return}let e=window.setTimeout(()=>{let e=new Set;for(let t of o)t.isDir&&e.add(t.path);for(let t of N.values())for(let n of t)n.isDir&&e.add(n.path);let t=0;for(let n of e){if(t>=12||M.current<=0)break;N.has(n)||g.has(n)||T.current.has(n)||(E(n),M.current-=1,t+=1)}},250);return()=>window.clearTimeout(e)},[z,o,N,g,E]);let L=(0,n.useCallback)(async t=>{if(e)try{let n=await lt(e,t);"/workspace"===t?c(n??[]):_(e=>new Map(e).set(t,n??[])),f(null)}catch(e){f(e.message)}},[e]),D=(0,n.useCallback)(e=>{_(t=>{let n=new Map(t);for(let t of[...n.keys()])(t===e||t.startsWith(`${e}/`))&&n.delete(t);return n}),k(t=>{let n=new Set([...t].filter(t=>t!==e&&!t.startsWith(`${e}/`)));return n.size===t.size?t:n})},[]),{pending:O,setPending:q,beginCreate:B,beginRename:U,createDepth:H,submitCreate:W,submitRename:V,requestDelete:K}=function(e){let{projectId:t,rows:a,focusedPath:i,menuPath:s,expand:r,focusRow:l,refreshDir:o,forgetDir:c,setError:d}=e,[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(!1),f=(0,n.useRef)(!1),g=e=>e.includes("/")||"."===e||".."===e?"A name cannot contain a slash or be . or ..":null,x=(e,t)=>`${"/workspace"===e?"/workspace":e}/${t}`,v=(0,n.useCallback)(()=>{let e=a.find(e=>e.entry.path===i);return e?.entry.isDir?e.entry.path:e?la(e.entry.path).parent:"/workspace"},[a,i]),y=(0,n.useCallback)(e=>{let t=v();p({kind:"create",parent:t,entryKind:e}),"/workspace"!==t&&r(t)},[v,r]),b=(0,n.useCallback)(()=>{let e=a.find(e=>e.entry.path===i);e&&p({kind:"rename",path:e.entry.path})},[a,i]),k=(0,n.useCallback)(()=>{if(!u||"create"!==u.kind)return 0;let e=a.find(e=>e.entry.path===u.parent);return e?e.depth+1:0},[u,a]),j=(0,n.useCallback)(async e=>{if(!u||"create"!==u.kind||!t)return;let n=e.trim();if(""===n)return void p(null);let a=g(n);if(a)return void d(a);let i=x(u.parent,n);if(!f.current){f.current=!0,m(!0);try{await li(t,{path:i,kind:u.entryKind,content:""}),p(null),await o(u.parent),window.requestAnimationFrame(()=>l(i))}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[u,t,o,l,d]),w=(0,n.useCallback)(async(e,n)=>{if(!t)return;let a=n.trim();if(""===a||a===e.name)return void p(null);let i=g(a);if(i)return void d(i);let s=la(e.path).parent,r=x(s,a);if(!f.current){f.current=!0,m(!0);try{await ls(t,{from:e.path,to:r}),p(null),c(e.path),await o(s),window.requestAnimationFrame(()=>l(r))}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[t,o,c,l,d]),N=(0,n.useCallback)(async()=>{if(!t)return;let e=a.find(e=>e.entry.path===s);if(!e)return;let{entry:n}=e;if(await rx({title:`Delete ${n.name}?`,description:n.isDir?"The directory and everything inside it is deleted. There is no trash.":"The file is deleted. There is no trash.",confirmLabel:"Delete",tone:"danger"})&&!f.current){f.current=!0,m(!0);try{await lr(t,n.path,{recursive:n.isDir}),c(n.path),await o(la(n.path).parent)}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[t,a,s,o,c,d]);return{pending:u,setPending:p,busy:h,beginCreate:y,beginRename:b,createDepth:k,submitCreate:j,submitRename:w,requestDelete:N}}({projectId:e,rows:F,focusedPath:C,menuPath:I?.path??null,expand:$,focusRow:e=>G(e),refreshDir:L,forgetDir:D,setError:f}),G=(0,n.useCallback)(e=>{S(e);let t=R.current;if(!t)return;let n=t.querySelector(`[data-path="${CSS.escape(e)}"]`);n?.focus()},[]),J=(0,n.useCallback)((e,t)=>{let n=F[e+t];n&&G(n.entry.path)},[F,G]),Y=(0,n.useCallback)((e,t)=>{if(e.target!==e.currentTarget&&("Enter"===e.key||" "===e.key))return;let n=F[t];if(n)switch(e.key){case"ArrowDown":e.preventDefault(),J(t,1);break;case"ArrowUp":e.preventDefault(),J(t,-1);break;case"Home":e.preventDefault(),F[0]&&G(F[0].entry.path);break;case"End":e.preventDefault(),F.length>0&&G(F[F.length-1].entry.path);break;case"ArrowRight":if(e.preventDefault(),!n.entry.isDir||z)break;if(!b.has(n.entry.path)){$(n.entry.path);break}if(!N.has(n.entry.path))break;J(t,1);break;case"ArrowLeft":{if(e.preventDefault(),!z&&n.entry.isDir&&b.has(n.entry.path)){A(n.entry.path);break}let t=F.findIndex(e=>e.entry.path===n.parentPath);t>=0&&G(F[t].entry.path);break}case"Enter":case" ":if(e.preventDefault(),n.entry.isDir){if(z)break;b.has(n.entry.path)?A(n.entry.path):$(n.entry.path)}else i(n.entry.path,n.entry.name);break;case"ContextMenu":let a;e.preventDefault(),P({path:n.entry.path,...{x:(a=e.currentTarget.getBoundingClientRect()).left+12,y:a.bottom}})}},[F,b,N,z,A,$,J,G,i]),Q=null===C?-1:F.findIndex(e=>e.entry.path===C),Z=null!==C&&-1===Q;(0,n.useEffect)(()=>{if(!Z)return;let e=window.setTimeout(()=>{let e=R.current?.contains(document.activeElement)??!1,t=F[0]?.entry.path;S(t??null),e&&t&&G(t)},0);return()=>window.clearTimeout(e)},[Z,F,G]);let X=Q>=0?Q:0;return(0,t.jsxs)("div",{className:"file-tree-panel",children:[(0,t.jsxs)("div",{className:"file-tree-header",children:[(0,t.jsx)("div",{className:"file-tree-heading",children:"Files"}),(0,t.jsx)("div",{className:"file-tree-path",title:a??"/workspace",children:e?a??"/workspace":"No project selected"}),(0,t.jsxs)("div",{className:"file-tree-actions",children:[(0,t.jsx)("button",{type:"button",className:"file-tree-action","aria-label":"New file",title:"New file",disabled:!e,onClick:()=>B("file"),children:(0,t.jsx)(lK,{size:13,"aria-hidden":"true"})}),(0,t.jsx)("button",{type:"button",className:"file-tree-action","aria-label":"New folder",title:"New folder",disabled:!e,onClick:()=>B("directory"),children:(0,t.jsx)(d,{size:13,"aria-hidden":"true"})})]}),(0,t.jsxs)("label",{className:"file-filter",children:[(0,t.jsx)(u,{size:12,"aria-hidden":"true"}),(0,t.jsx)("span",{className:"sr-only",children:"Filter files"}),(0,t.jsx)("input",{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{"ArrowDown"===e.key&&0!==F.length&&(e.preventDefault(),G(F[0].entry.path))},placeholder:"Filter files...",disabled:!e})]})]}),(0,t.jsx)("div",{className:"file-tree-list",ref:R,onScroll:()=>P(null),children:e?p?(0,t.jsx)("div",{className:"file-tree-state",children:"Loading..."}):m&&0===o.length?(0,t.jsx)("div",{className:"file-tree-state is-error",children:m}):0===F.length?(0,t.jsxs)(t.Fragment,{children:[m&&(0,t.jsx)("p",{className:"file-tree-inline-error",role:"alert",children:m}),(0,t.jsx)("div",{className:"file-tree-state",children:z?"No files match.":"No files found."})]}):(0,t.jsxs)(t.Fragment,{children:[m&&(0,t.jsx)("p",{className:"file-tree-inline-error",role:"alert",children:m}),(0,t.jsxs)("div",{role:"tree","aria-label":"Workspace files",children:[F.map((e,n)=>{let{entry:a,depth:s}=e,r=z?(N.get(a.path)?.length??0)>0:b.has(a.path);return O&&"rename"===O.kind&&O.path===a.path?(0,t.jsx)(lY,{depth:s,label:`Rename ${a.name}`,initialValue:a.name,onCommit:e=>void V(a,e),onCancel:()=>q(null)},"editor"):(0,t.jsx)(lJ,{entry:a,depth:s,expanded:r,loading:j.has(a.path),errorText:g.get(a.path),tabbable:n===X,selected:C===a.path,onClick:()=>{(S(a.path),a.isDir)?z||(r?A(a.path):$(a.path)):i(a.path,a.name)},onContextMenu:e=>{e.preventDefault(),G(a.path),P({path:a.path,x:e.clientX,y:e.clientY})},onKeyDown:e=>Y(e,n),onPreview:()=>l(a.path,a.name)},a.path)}),O&&"create"===O.kind&&(0,t.jsx)(lY,{depth:H(),label:"directory"===O.entryKind?"New folder name":"New file name",initialValue:"",onCommit:e=>void W(e),onCancel:()=>q(null)},"creator")]})]}):(0,t.jsx)("div",{className:"file-tree-empty",children:"Select a project to browse files."})}),I&&(0,t.jsx)(lQ,{entry:F.find(e=>e.entry.path===I.path)?.entry,at:I,onClose:()=>{let e=I.path;P(null),G(e)},onOpen:()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&i(e.path,e.name)},onOpenToSide:r?()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&s(e.path,e.name)}:void 0,onPreview:()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&l(e.path,e.name)},onNewFile:()=>B("file"),onNewFolder:()=>B("directory"),onRename:()=>U(),onDelete:()=>void K(),onError:e=>f(e)})]})}function lX(e){return(0,t.jsx)(lZ,{projectId:e.projectId,displayPath:e.displayPath,onOpenFile:e.onOpenFile,onOpenFileToSide:e.onOpenFileToSide,canOpenToSide:e.canOpenToSide,onPreviewFile:e.onPreviewFile},e.projectId??"no-project")}var l0=e.i(57840);function l1(e,t,n){if(!n)return"";let a=`${t}.${n}`,i=e(a);return i===a?n:i}function l2({sessionId:e,onCount:a}){let i=(0,f.useT)(),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)({}),[c,d]=(0,n.useState)(null),[u,p]=(0,n.useState)(null),m=(0,n.useCallback)(async()=>{if(e)try{let t=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/graph-runs`)??[];r(t),a?.(t.length),p(null),d(e=>{if(0===t.length)return null;let n=t[0].runId??null;if(null===n)return null;if(null===e||!t.some(t=>t.runId===e))return n;let a=t[0].createdAt,i=t.find(t=>t.runId===e)?.createdAt;return a&&i&&i<a?n:e})}catch(e){p(e.message)}},[e,a]);(0,n.useEffect)(()=>{let e,t=new AbortController,n=!1,a=async()=>{await m(),n||(e=window.setTimeout(a,1500))};return a(),()=>{n=!0,t.abort(),void 0!==e&&window.clearTimeout(e)}},[m]),(0,n.useEffect)(()=>{if(!e||!c)return;let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/graph-runs/${encodeURIComponent(c)}`).then(e=>{t||o(t=>({...t,[c]:e.nodes??[]}))}).catch(()=>{t||p("graph.loadFailed")}),()=>{t=!0}},[c,e]);let g=(0,n.useMemo)(()=>s.filter(e=>"running"===e.state).length,[s]);return(0,t.jsxs)("div",{className:l0.default.root,children:[(0,t.jsxs)("div",{className:l0.default.header,children:[(0,t.jsxs)("span",{className:l0.default.title,children:[(0,t.jsx)(h,{size:13,"aria-hidden":"true"}),i("graph.title")]}),g>0&&(0,t.jsx)("span",{className:l0.default.running,children:i("graph.running",{count:String(g)})})]}),u&&(0,t.jsx)("div",{className:l0.default.error,children:"graph.loadFailed"===u?i(u):u}),(0,t.jsx)("div",{className:l0.default.scroll,children:e?0===s.length?(0,t.jsx)("div",{className:l0.default.empty,children:i("graph.emptyRuns")}):s.map(e=>(0,t.jsx)(l4,{run:e,nodes:l[e.runId??""]??[],expanded:c===e.runId,onToggle:()=>d(t=>t===e.runId?null:e.runId??null),nodesLoading:c===e.runId&&void 0===l[e.runId??""],t:i},e.runId)):(0,t.jsx)("div",{className:l0.default.empty,children:i("graph.emptySession")})})]})}function l4({run:e,nodes:n,expanded:a,onToggle:i,nodesLoading:s,t:r}){let l=e.state,o=n.length,c=n.filter(e=>"completed"===e.terminalState).length,d=l1(r,"graph.flow",l);return(0,t.jsxs)("div",{className:l0.default.card,children:[(0,t.jsxs)("button",{type:"button",onClick:i,className:l0.default.cardButton,"data-expanded":a||void 0,"aria-expanded":a,children:[(0,t.jsx)(j,{size:11,className:l0.default.chevron,"data-expanded":a||void 0,"aria-hidden":"true"}),(0,t.jsx)("span",{className:`${l0.default.stateDot} ${l0.default.flowDot}`,"data-flow-state":l}),(0,t.jsx)("span",{className:l0.default.cardTitle,children:e.inputs?.name?String(e.inputs.name):r("graph.unnamed")}),(0,t.jsx)("span",{className:l0.default.cardSummary,children:o>0?r("graph.tasks",{done:String(c),total:String(o)}):d})]}),a&&(0,t.jsxs)("div",{className:l0.default.details,children:[(0,t.jsxs)("div",{className:l0.default.meta,children:[(0,t.jsx)("span",{children:r("graph.stateLabel",{state:d})}),e.totalTokensUsed?(0,t.jsx)("span",{children:r("graph.tokens",{count:String(e.totalTokensUsed)})}):null,e.createdAt?(0,t.jsx)("span",{children:function(e,t){let n=new Date(e);if(Number.isNaN(n.getTime()))return e;let a=Math.floor((new Date().getTime()-n.getTime())/6e4);return a<1?t("graph.justNow"):a<60?t("graph.minutesAgo",{count:String(a)}):n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}(e.createdAt,r)}):null]}),s?(0,t.jsx)("div",{className:l0.default.stateLine,children:r("graph.loadingTasks")}):0===n.length?(0,t.jsx)("div",{className:l0.default.stateLine,children:r("graph.noTasks")}):(0,t.jsx)("ul",{className:l0.default.nodeList,children:n.map(e=>(0,t.jsxs)("li",{className:l0.default.nodeRow,children:[(0,t.jsx)("span",{className:l0.default.nodeDot,"data-node-state":e.terminalState}),(0,t.jsx)("span",{className:l0.default.nodeName,children:e.handle}),(0,t.jsx)("span",{className:l0.default.nodeState,children:l1(r,"graph.node",e.terminalState)})]},e.taskIndex??e.handle))})]})]})}function l5({sessionId:e,onCount:n}){return(0,t.jsx)(l2,{sessionId:e,onCount:n})}let l3=o("file-clock",[["path",{d:"M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85",key:"ryk6xj"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 14v2.2l1.6 1",key:"6m4bie"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}]]);function l6(e,t=""){return"string"==typeof e?e:t}function l8(e){let t=[];for(let n of e??[]){let e=n??{};switch(e.type){case"text":t.push({kind:"text",text:l6(e.text)});break;case"thinking":t.push({kind:"thinking",text:l6(e.text)});break;case"tool_call":{let n=e.toolCall??{},a=function(e){if(null!=e){if("object"!=typeof e)return String(e);try{return JSON.stringify(e,null,2)}catch{return}}}(n.arguments);t.push({kind:"tool_call",callId:l6(n.id),name:l6(n.name,"tool")||"tool",...void 0===a?{}:{arguments:a}});break}case"tool_result":{let n=e.toolResult??{};t.push({kind:"tool_result",callId:l6(n.toolCallId),name:l6(n.toolName,"tool")||"tool",text:l6(n.content),isError:!0===n.isError});break}case"image":{let n=e.image??{};t.push({kind:"image",width:"number"==typeof n.width?n.width:0,height:"number"==typeof n.height?n.height:0});break}case"image_description":{let n=e.imageDescription??{};t.push({kind:"text",text:l6(n.text)});break}default:t.push({kind:"unknown",type:l6(e.type,"unknown")||"unknown"})}}return t}var l9=e.i(26694);let l7={base:"Platform",hero:"Hero",context:"Project context",skills_catalog:"Skill catalog",skill_preload:"Preloaded skill"},oe={system:"System",user:"User",assistant:"Assistant",tool:"Tool"};function ot({runId:e,composition:a,mcp:i,transcript:s,loading:r,error:l,t:o}){let[c,d]=(0,n.useState)(!1);if(!e)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.noRun")});if(r&&!a)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.loading")});if(l)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:l});if(!a)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.loading")});let u=a.sections??[],p=a.recorded,h=u.filter(e=>"skill_preload"===e.kind&&"user-skill-select"===e.source).map(e=>e.skillId||e.id.replace(/^skill\.preload\./,""));return(0,t.jsxs)("div",{className:l9.default.body,children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.run")}),(0,t.jsx)("div",{className:`${l9.default.digest} ${l9.default.digestValue} ${l9.default.runId}`,title:e,children:e}),(0,t.jsx)("div",{className:l9.default.muted,children:p?o("inspector.frozen"):o("inspector.unrecorded")})]}),p&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:l9.default.heading,children:[o("inspector.composition"),(0,t.jsx)("span",{className:l9.default.headingCount,children:o("inspector.sections",{count:String(u.length)})})]}),h.length>0&&(0,t.jsxs)("div",{className:l9.default.selectedSkills,children:[(0,t.jsx)("span",{className:l9.default.muted,children:o("inspector.selectedSkills")}),h.map(e=>(0,t.jsx)("code",{children:`/${e}`},e))]}),(0,t.jsx)("div",{className:l9.default.group,children:u.map(e=>(0,t.jsx)(on,{section:e},e.id))})]}),(0,t.jsxs)("div",{className:l9.default.digestGroup,children:[(0,t.jsx)(or,{label:o("inspector.sectionsDigest"),value:a.sectionsDigest}),(0,t.jsx)(or,{label:o("inspector.composedDigest"),value:a.composedDigest}),(0,t.jsx)(or,{label:o("inspector.baseDigest"),value:a.digest}),""!==a.skillCatalogState&&(0,t.jsxs)("div",{className:l9.default.catalogRow,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.catalogLabel}`,children:o("inspector.skillCatalog")}),(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.catalogValue}`,children:o(`inspector.catalog.${a.skillCatalogState}`)}),""!==a.skillCatalogDigest&&(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.digestValue}`,title:a.skillCatalogDigest,children:rE(a.skillCatalogDigest,8)})]})]}),p&&void 0!==i&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.mcp")}),null===i||0===(i.servers??[]).length?(0,t.jsx)("div",{className:l9.default.muted,children:o("inspector.mcpNone")}):(0,t.jsx)("div",{className:l9.default.group,children:(i.servers??[]).map(e=>(0,t.jsx)(oa,{server:e,t:o},e.id))})]}),s?(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.transcript")}),(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.transcriptNote}`,children:o("inspector.transcriptNote")}),0===s.messages.length?(0,t.jsx)("div",{className:l9.default.muted,children:o("inspector.transcriptEmpty")}):(0,t.jsx)("div",{className:l9.default.group,children:s.messages.map(e=>(0,t.jsx)(oi,{message:e,t:o},e.id))}),s.hasMore&&(0,t.jsx)("button",{type:"button",className:l9.default.loadOlder,disabled:s.loadingOlder,onClick:s.loadOlder,children:o("inspector.transcriptOlder")})]}):null,p&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("button",{type:"button",className:l9.default.promptToggle,onClick:()=>d(e=>!e),"aria-expanded":c,children:[c?(0,t.jsx)(q,{size:13,"aria-hidden":"true"}):(0,t.jsx)(j,{size:13,"aria-hidden":"true"}),(0,t.jsx)(l3,{size:13,"aria-hidden":"true"}),o("inspector.prompt"),(0,t.jsx)("span",{className:l9.default.promptBytes,children:rA(a.prompt.length)})]}),c&&(0,t.jsx)("pre",{"data-run-prompt":!0,className:l9.default.promptPre,children:a.prompt})]})]})}function on({section:e}){return(0,t.jsxs)("div",{"data-prompt-section":e.kind,className:l9.default.sectionRow,children:[(0,t.jsx)("span",{className:l9.default.sectionKind,children:l7[e.kind]??e.kind}),(0,t.jsxs)("span",{className:l9.default.sectionIdentity,children:[(0,t.jsx)("span",{className:l9.default.sectionId,children:e.id}),(0,t.jsx)("span",{className:l9.default.sectionSource,children:` \xb7 ${e.source}`})]}),(0,t.jsx)("span",{className:l9.default.sectionBytes,children:rA(e.bytes)}),(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.sectionDigest}`,title:e.digest,children:rE(e.digest,8)})]})}function oa({server:e,t:n}){let a=""!==e.unavailableReason;return(0,t.jsxs)("div",{"data-mcp-server":e.bindingId,"data-unavailable":a||void 0,className:l9.default.mcpRow,children:[(0,t.jsxs)("div",{className:l9.default.mcpHead,children:[(0,t.jsxs)("span",{className:l9.default.mcpIdentity,children:[(0,t.jsx)("span",{className:l9.default.mcpBinding,children:e.bindingId}),(0,t.jsx)("span",{className:l9.default.mcpRevision,children:` \xb7 rev ${e.bindingRevision}`})]}),e.required&&(0,t.jsx)("span",{className:l9.default.badge,children:n("inspector.mcpRequired")}),(0,t.jsx)("span",{className:l9.default.mcpTools,children:n("inspector.mcpTools",{count:String((e.tools??[]).length)})})]}),a&&(0,t.jsx)("div",{className:l9.default.mcpUnavailable,children:`${n("inspector.mcpUnavailable")}: ${e.unavailableReason}`}),""!==e.negotiatedProtocol&&(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.mcpProtocol}`,children:`${n("inspector.mcpProtocol")}: ${e.negotiatedProtocol}`}),""!==e.instructions&&(0,t.jsxs)("details",{className:l9.default.mcpInstructions,children:[(0,t.jsx)("summary",{className:l9.default.muted,title:e.instructionsDigest,children:n("inspector.mcpInstructions")}),(0,t.jsx)("div",{className:l9.default.mcpInstructionsBody,"data-mcp-instructions":!0,children:e.instructions})]}),(e.tools??[]).length>0&&(0,t.jsx)("div",{className:l9.default.toolList,children:(e.tools??[]).map(e=>(0,t.jsxs)("div",{className:l9.default.toolRow,children:[(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.toolName}`,title:e.exposedName,children:e.exposedName}),(0,t.jsx)("span",{className:l9.default.toolRisk,children:e.riskClass})]},e.exposedName))})]})}function oi({message:e,t:n}){let a=l8(e.content),i=function(e){let t=new Set,n=[];for(let a of l8(e))"tool_call"!==a.kind||t.has(a.name)||(t.add(a.name),n.push(a.name));return n.join(", ")}(e.content);return(0,t.jsxs)("details",{"data-transcript-ordinal":e.ordinal,className:l9.default.transcriptRow,children:[(0,t.jsxs)("summary",{className:l9.default.transcriptSummary,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.transcriptOrdinal}`,children:e.ordinal}),(0,t.jsx)("span",{className:l9.default.transcriptRole,children:oe[e.role]??e.role}),"private"===e.visibility&&(0,t.jsx)("span",{"data-transcript-private":!0,className:l9.default.privateBadge,children:n("inspector.transcriptPrivate")}),(0,t.jsx)("span",{className:l9.default.transcriptExcerpt,children:i})]}),(0,t.jsx)("div",{className:l9.default.transcriptBody,children:a.map((e,a)=>(0,t.jsx)(os,{entry:e,t:n},a))})]})}function os({entry:e,t:n}){return"text"===e.kind?(0,t.jsx)("div",{className:l9.default.entryPre,children:e.text}):"thinking"===e.kind?(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.entryLabel}`,children:n("inspector.transcriptThinking")}),(0,t.jsx)("div",{className:l9.default.entryPre,children:e.text})]}):"image"===e.kind?(0,t.jsx)("div",{className:l9.default.muted,children:n("inspector.transcriptImage",{width:String(e.width),height:String(e.height)})}):"unknown"===e.kind?(0,t.jsx)("div",{className:l9.default.muted,children:n("inspector.transcriptUnknown",{type:e.type})}):"tool_call"===e.kind?(0,t.jsxs)("details",{children:[(0,t.jsx)("summary",{className:`${l9.default.muted} ${l9.default.entrySummary}`,children:`${n("inspector.transcriptCall")} ${e.name}`}),void 0!==e.arguments&&(0,t.jsx)("div",{className:`${l9.default.entryPre} ${l9.default.entryBlock}`,children:e.arguments})]}):(0,t.jsxs)("details",{children:[(0,t.jsx)("summary",{className:`${l9.default.muted} ${l9.default.entrySummary}`,"data-error":e.isError||void 0,children:`${n(e.isError?"inspector.transcriptError":"inspector.transcriptResult")} ${e.name}`}),(0,t.jsx)("div",{className:`${l9.default.entryPre} ${l9.default.entryBlock}`,children:e.text})]})}function or({label:e,value:n}){return n?(0,t.jsxs)("div",{className:l9.default.digestLine,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.digestLabel}`,children:e}),(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.digestValue}`,title:n,children:n})]}):null}function ol({runId:e,composition:n,mcp:a,transcript:i,loading:s,error:r}){let l=(0,f.useT)();return(0,t.jsx)(ot,{runId:e,composition:n,mcp:a,transcript:i,loading:s,error:r,t:l})}function oo(e){let{runId:a,selectedSession:i,sessionTitle:s,activeRun:r,status:l,permissionMode:o}=e,c=function(e){let[t,a]=(0,n.useState)(null),[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a(null),l(null),s(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{s(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/prompt`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e),l(null))}).catch(e=>{t.signal.aborted||(a(null),l(e instanceof Error?e.message:"Failed to load the run prompt"))}).finally(()=>{t.signal.aborted||s(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]),{composition:t,loading:i,error:r}}(a),d=function(e){let[t,a]=(0,n.useState)(null),[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a(null),l(null),s(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{s(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/mcp`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e),l(null))}).catch(e=>{t.signal.aborted||(a(null),l(e instanceof Error?e.message:"Failed to load the run MCP surface"))}).finally(()=>{t.signal.aborted||s(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]),{frozen:t,loading:i,error:r}}(a),u=function(e){let[t,a]=(0,n.useState)([]),[i,s]=(0,n.useState)(null),[r,l]=(0,n.useState)(!1),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a([]),s(null),u(null),l(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{l(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/messages?limit=200`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e.messages??[]),s(e.hasMore?e.nextBeforeOrdinal??null:null),u(null))}).catch(e=>{t.signal.aborted||(a([]),s(null),u(e instanceof Error?e.message:"Failed to load the run transcript"))}).finally(()=>{t.signal.aborted||l(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]);let p=(0,n.useCallback)(()=>{e&&null!==i&&(c(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/messages?limit=200&beforeOrdinal=${i}`).then(e=>{a(t=>{let n=new Set(t.map(e=>e.ordinal));return[...(e.messages??[]).filter(e=>!n.has(e.ordinal)),...t]}),s(e.hasMore?e.nextBeforeOrdinal??null:null),u(null)}).catch(e=>{u(e instanceof Error?e.message:"Failed to load older transcript messages")}).finally(()=>c(!1)))},[e,i]);return{messages:t,hasMore:null!==i,loading:r,loadingOlder:o,error:d,loadOlder:p}}(a);return(0,t.jsxs)("div",{className:"right-panel-tools",children:[(0,t.jsx)(ol,{runId:a,composition:c.composition,mcp:d.frozen,transcript:u,loading:c.loading,error:c.error}),(0,t.jsx)(oc,{selectedSession:i,sessionTitle:s,activeRun:r,status:l,permissionMode:o})]})}function oc({selectedSession:e,sessionTitle:n,activeRun:a,status:i,permissionMode:s}){let r=(0,f.useT)();return(0,t.jsx)("div",{className:"right-panel-summary",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{children:["Session: ",n]}),(0,t.jsxs)("div",{children:["Active run: ",a||"none"]}),(0,t.jsxs)("div",{children:["Status: ",i?sP(i,r):"idle"]}),(0,t.jsxs)("div",{children:["Permission: ",s]})]}):(0,t.jsx)("div",{children:"No session selected"})})}let od=["files","graph","tools"];function ou(e){return"string"==typeof e&&od.includes(e)}function op(e){return`ennote:right-panel:v1:${e}`}function oh(e){return{version:1,projectId:e,pinnedChannels:[],primaryWidths:{files:280,graph:280,tools:280},open:!1,inspectorTabs:[],activeInspectorId:null,navigatorHidden:!1}}function om(e){return od.filter(t=>e.includes(t))}function of(e){if(!Array.isArray(e))return[];let t=[],n=new Set;for(let a of e){if("object"==typeof a&&null!==a)"string"==typeof a.path&&0!==a.path.length&&(n.has(a.path)||(n.add(a.path),t.push({path:a.path,name:"string"==typeof a.name&&a.name.length>0?a.name:function(e){let t=e.split("/").filter(Boolean);return t[t.length-1]??e}(a.path),pane:"side"===a.pane?"side":"main"})))}return t.slice(-20)}function og(e){let t=om(e.pinnedChannels),n=t.length>0?om(t):[...od];return{projectId:e.projectId,openChannels:n,pinnedChannels:t,activeChannelId:n[0]??null,open:e.open,primaryWidths:{files:ob(e.primaryWidths?.files,ob(e.primaryWidth,280)),graph:ob(e.primaryWidths?.graph,ob(e.primaryWidth,280)),tools:ob(e.primaryWidths?.tools,ob(e.primaryWidth,280))},navigatorHidden:!0===e.navigatorHidden,...function(e){let t=of(e.inspectorTabs),n=e.activeInspectorIds,a=(n,a)=>null!==a&&t.some(t=>(t.pane??"main")===n&&ov(e.projectId,t.path)===a)?a:null,i={main:a("main",n?n.main??null:e.activeInspectorId??null),side:a("side",n?n.side??null:null)};if(null===i.main&&null===i.side&&t.length>0){let n=t[0];i[n.pane??"main"]=ov(e.projectId,n.path)}let s=null!==i.side&&null===i.main?"side":"main";return{inspectorTabs:t,activePanes:i,focusedPane:s,activeLane:null!==i[s]?"inspector":"channel"}}(e)}}function ox(e){let t=e.split(":");return t.length<3?e:t.slice(2).join(":")}function ov(e,t){return`file:${e}:${t}`}function oy(e,t){let n=e.openChannels.includes(t)?e.openChannels:[...e.openChannels,t];return{...e,openChannels:n,activeChannelId:t,activeLane:"channel",open:!0}}function ob(e,t){return"number"==typeof e&&Number.isFinite(e)?Math.max(220,Math.min(2e3,Math.round(e))):t}function ok(e,t,n){let a=e.inspectorTabs.find(e=>e.path===n.path),i=a?.pane??n.pane??"main",s=of([...e.inspectorTabs.filter(e=>e.path!==n.path),{...n,pane:i}]),r=new Set(s.map(t=>ov(e.projectId,t.path))),l={main:null!==e.activePanes.main&&r.has(e.activePanes.main)?e.activePanes.main:null,side:null!==e.activePanes.side&&r.has(e.activePanes.side)?e.activePanes.side:null};return{...e,inspectorTabs:s,activePanes:{...l,[i]:t},focusedPane:i,activeLane:"inspector",open:!0}}function oj(e){let{open:a,onClose:i,resize:s,panel:r,projectId:l,displayPath:o,onOpenFile:c,onOpenFileToSide:d,onPreviewFile:u,selectedSession:p,sessionTitle:h,activeRun:m,inspectorRunId:g,status:x,permissionMode:v}=e,y=(0,f.useT)(),{state:b,fileTabs:k}=r,j=lz("(max-width: 960px)"),w="medium"===lD(s.width,j),[N,_]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null),P=w?N:!b.navigatorHidden,T=b.openChannels,M=r.activeChannelId,R=e=>y("rightPanel.close",{name:e.label}),E=e=>{ou(e)?r.closeChannelTab(e):r.closeTab(e)},A=e=>{r.setActiveTabId(e),w&&_(!1),b.navigatorHidden&&"files"!==e&&r.toggleNavigator()},$=P&&null!==M?lL(b.primaryWidths[M],s.width):0,z=s.width-$-8*($>0),F=s.width-220-8,L=!w&&"wide"===lD(s.width,j)&&(z>=448||F>=448),D=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"right-panel-channel-slot",hidden:"files"!==M,children:(0,t.jsx)(lX,{projectId:l,displayPath:o,onOpenFile:(e,t)=>{c(e,t),w&&_(!1)},onOpenFileToSide:(e,t)=>{z<448&&$>220&&r.resizePrimaryBy(220-$,s.width),d(e,t),w&&_(!1)},canOpenToSide:L,onPreviewFile:u})}),"graph"===M&&(0,t.jsx)(l5,{sessionId:p,onCount:e=>I({session:p,count:e})}),"tools"===M&&(0,t.jsx)(oo,{runId:g,selectedSession:p,sessionTitle:h,activeRun:m,status:x,permissionMode:v}),null===M&&(0,t.jsx)(lV,{channels:od,hint:y("rightPanel.launcherHint"),t:y,onOpen:r.openChannel})]}),O={graph:{count:C?.session===p?C.count:void 0},tools:{attention:!!x&&s_.has(x.split("\x1f")[0])}},q=(e,n)=>{let a=n.find(t=>t.id===e);return a?.projectId&&a.filePath&&a.projectId===l?(0,t.jsx)(ld,{projectId:a.projectId,filePath:a.filePath,fileName:a.label}):null},B=q(r.activePanes.main,r.paneTabs.main),U=q(r.activePanes.side,r.paneTabs.side),H=L&&r.paneTabs.side.length>0,W=q(r.activePanes[r.focusedPane],r.paneTabs[r.focusedPane]),V=H?[B,U]:[r.paneTabs.side.length>0?W:B],K=k.length>0?(0,t.jsx)("div",{className:`right-panel-panes${H?" is-split":""}`,children:V.map((e,n)=>(0,t.jsx)("div",{className:"right-panel-pane","data-testid":H?0===n?"inspector-pane-main":"inspector-pane-side":"inspector-pane-focused",children:e},0===n?"main":"side"))}):null;return(0,t.jsxs)("div",{className:`right-panel-container${a?" right-panel-open":" right-panel-closed"}`,style:{width:s.width,minWidth:s.width,transition:s.isResizing?"none":void 0},children:[(0,t.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>{_(!1),i()},children:[(0,t.jsx)(r6,{size:15,"aria-hidden":"true"}),"Back to conversation"]}),(0,t.jsx)(lq,{width:s.width,channelStrip:(0,t.jsxs)("div",{className:"right-panel-strip",children:[(0,t.jsx)(lE,{tabs:lH(T,y,O),activeTabId:M??"",onSelectTab:A,onCloseTab:E,closeLabel:R}),null!==M&&(0,t.jsx)("button",{type:"button",className:"right-panel-strip-action","aria-pressed":b.pinnedChannels.includes(M),"aria-label":b.pinnedChannels.includes(M)?y("rightPanel.unpin"):y("rightPanel.pin"),title:b.pinnedChannels.includes(M)?y("rightPanel.unpin"):y("rightPanel.pin"),onClick:()=>r.togglePin(M),children:b.pinnedChannels.includes(M)?(0,t.jsx)(r8,{size:13,"aria-hidden":"true"}):(0,t.jsx)(r9,{size:13,"aria-hidden":"true"})}),T.length<od.length&&(0,t.jsx)("button",{type:"button",className:"right-panel-strip-action","aria-label":y("rightPanel.add"),title:y("rightPanel.add"),onClick:()=>{let e=od.find(e=>!T.includes(e));e&&r.openChannel(e)},children:(0,t.jsx)(S,{size:13,"aria-hidden":"true"})})]}),channelBody:D,inspectorStrip:H?(0,t.jsxs)("div",{className:"right-panel-pane-strips",children:[(0,t.jsx)(lE,{tabs:r.paneTabs.main,activeTabId:r.activePanes.main??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R}),(0,t.jsx)(lE,{tabs:r.paneTabs.side,activeTabId:r.activePanes.side??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R})]}):k.length>0?(0,t.jsx)(lE,{tabs:k,activeTabId:r.activeInspectorId??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R}):null,inspectorBody:K,narrowStrip:(0,t.jsx)("div",{className:"right-panel-strip",children:(0,t.jsx)(lE,{tabs:[...lH(T,y,O),...k],activeTabId:r.activeTabId,onSelectTab:A,onCloseTab:E,onReorder:r.reorderTabs,closeLabel:R})}),narrowBody:(0,t.jsx)("div",{className:"right-panel-body",children:r.activeTabId===r.activeInspectorId&&W?W:D}),primaryWidth:b.primaryWidths[M??"files"],onResizePrimary:e=>r.resizePrimaryBy(e,s.width),onResizePrimaryStart:r.beginPrimaryResize,onResizePrimaryEnd:r.endPrimaryResize,navigatorOpen:P&&a,primaryHidden:!P&&"files"===M,onToggleNavigator:()=>w?_(e=>!e):r.toggleNavigator()})]})}function ow({resize:e}){return(0,t.jsx)(l$,{side:"left",ariaLabel:"Resize right panel",value:e.width,min:280,max:e.maxWidth,onResizeStart:e.beginResize,onResize:e.resizeBy,onResizeEnd:e.endResize})}function oN({projectId:e,filePath:a,fileName:i,onClose:s}){let[r,l]=(0,n.useState)(()=>o_()),o=(0,n.useRef)(null),c=(0,n.useRef)(null);M(!0,s);let d=(0,n.useCallback)((e,t)=>{0!==t.button||r.maximized||(t.preventDefault(),c.current={kind:e,x:t.clientX,y:t.clientY,bounds:r},t.currentTarget.setPointerCapture(t.pointerId))},[r]),u=(0,n.useCallback)(e=>{let t=c.current;if(!t)return;e.preventDefault();let n=e.clientX-t.x,a=e.clientY-t.y,i=window.innerWidth,s=window.innerHeight;"move"===t.kind?l({...t.bounds,x:oC(t.bounds.x+n,0,Math.max(0,i-160)),y:oC(t.bounds.y+a,0,Math.max(0,s-44))}):l({...t.bounds,width:oC(t.bounds.width+n,360,Math.max(360,i-t.bounds.x)),height:oC(t.bounds.height+a,260,Math.max(260,s-t.bounds.y))})},[]),p=(0,n.useCallback)(e=>{c.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},[]),h=(0,n.useCallback)(()=>{l(e=>e.maximized?o.current??o_():(o.current=e,{x:12,y:12,width:window.innerWidth-24,height:window.innerHeight-24,maximized:!0}))},[]);return(0,t.jsxs)("section",{className:`file-preview-window${r.maximized?" is-maximized":""}`,role:"dialog","aria-label":`Preview ${i}`,style:{left:r.x,top:r.y,width:r.width,height:r.height},children:[(0,t.jsxs)("header",{className:"file-preview-titlebar",onDoubleClick:h,onPointerDown:e=>d("move",e),onPointerMove:u,onPointerUp:p,onPointerCancel:p,children:[(0,t.jsx)("span",{title:a,children:i}),(0,t.jsxs)("div",{className:"file-preview-window-actions",onPointerDown:e=>e.stopPropagation(),children:[(0,t.jsx)("button",{type:"button",onClick:h,"aria-label":r.maximized?"Restore preview":"Maximize preview",title:r.maximized?"Restore preview":"Maximize preview",children:r.maximized?(0,t.jsx)(eO,{size:14}):(0,t.jsx)(lG,{size:14})}),(0,t.jsx)("button",{type:"button",onClick:s,"aria-label":"Close preview",title:"Close preview",children:(0,t.jsx)(m,{size:15})})]})]}),(0,t.jsx)("div",{className:"file-preview-content",children:(0,t.jsx)(ld,{projectId:e,filePath:a,fileName:i})}),!r.maximized&&(0,t.jsx)("div",{className:"file-preview-resize",role:"separator","aria-label":"Resize preview",onPointerDown:e=>d("resize",e),onPointerMove:u,onPointerUp:p,onPointerCancel:p})]})}function o_(){let e=window.innerWidth,t=window.innerHeight,n=Math.min(760,Math.max(360,e-48)),a=Math.min(600,Math.max(260,t-72));return{x:Math.max(12,Math.round((e-n)/2)),y:Math.max(12,Math.round((t-a)/2)),width:n,height:a,maximized:!1}}function oC(e,t,n){return Math.min(n,Math.max(t,e))}function oS(e){return e.replace(/[\\/]+$/,"").split(/[\\/]/).at(-1)||e}function oI({listing:e,selectedPath:n,showHidden:a,disabled:i,onSelect:s}){let r=a?e.entries:e.entries.filter(e=>!e.hidden||e.path===n);return(0,t.jsx)("div",{className:"project-picker-column",role:"list",children:r.map(e=>{let a=e.path===n;return(0,t.jsx)("span",{role:"listitem",className:"project-picker-row-seat",children:(0,t.jsxs)("button",{type:"button",className:`project-picker-row${a?" selected":""}`,"aria-current":a||void 0,disabled:i,onClick:()=>s(e),children:[a?(0,t.jsx)(N,{size:16,className:"project-picker-folder selected","aria-hidden":"true"}):(0,t.jsx)(w,{size:16,className:"project-picker-folder","aria-hidden":"true"}),(0,t.jsx)("span",{children:e.name}),(0,t.jsx)(j,{size:12,className:"project-picker-row-chevron","aria-hidden":"true"})]})},e.path)})})}function oP({busy:e,onCreate:a,onClose:i}){let s=(0,f.useT)(),[r,l]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),[p,h]=(0,n.useState)(!0),[m,g]=(0,n.useState)(null),[x,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(!1),[k,w]=(0,n.useState)(null),[N,_]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null),P=(0,n.useRef)(0),T=(0,n.useRef)(null),R=(0,n.useCallback)(async e=>{let t=e?`?${new URLSearchParams({path:e})}`:"";return(0,e3.apiFetch)(`/v1/host/directories${t}`)},[]),E=(0,n.useCallback)(async e=>{let t=++P.current;h(!0),g(null);try{let n=await R(e);if(t!==P.current)return;l(n),c(null),u(null),v(null)}catch(e){t===P.current&&g(e.message)}finally{t===P.current&&h(!1)}},[R]);(0,n.useEffect)(()=>{let e=++P.current;return R().then(t=>{e===P.current&&(l(t),h(!1))},t=>{e===P.current&&(g(t.message),h(!1))}),()=>{P.current+=1}},[R]),(0,n.useEffect)(()=>{null!==x&&T.current?.focus()},[x]);let A=(0,n.useCallback)(async e=>{let t=++P.current;c(e),u(null),h(!0),g(null);try{let n=await R(e.path);t===P.current&&u(n)}catch(e){t===P.current&&(c(null),g(e.message))}finally{t===P.current&&h(!1)}},[R]),$=(0,n.useCallback)(e=>{d&&(l(d),A(e))},[d,A]),z=o?.path??r?.path??null,F=z?oS(z):"",L=(0,n.useMemo)(()=>{var e;let t;return r?(e=s("directory.home"),(t=r.crumbs.findIndex(e=>e.path===r.home))<0?r.crumbs:[{name:e,path:r.home,hidden:!1},...r.crumbs.slice(t+1)]):[]},[r,s]),D=r?.roots??[],O=r&&r.home.includes("\\")?"\\":"/",q=e||N;M(!0,()=>{if(!q){if(null!==k)return void w(null);if(null!==x)return void v(null);i()}});let B=async()=>{if(z&&null!==k&&k.trim()&&!N){_(!0),I(null);try{let e=await (0,e3.apiFetch)("/v1/host/directories",{method:"POST",body:JSON.stringify({path:z,name:k})});if(w(null),o&&d){let t=await R(o.path);l(t);let n=t.entries.find(t=>t.path===e.path);n&&await A(n)}else{let t=await R(r?.path);l(t);let n=t.entries.find(t=>t.path===e.path);n&&A(n)}}catch(e){I(e.message)}finally{_(!1)}}},U=async()=>{if(z&&!e&&!p&&null===x){g(null);try{await a(F,z)}catch(e){g(e.message)}}};return(0,t.jsxs)("div",{className:"project-picker-overlay",onPointerDown:e=>{e.target!==e.currentTarget||q||null!==k||i()},children:[(0,t.jsxs)("div",{className:"project-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"project-picker-title",children:[(0,t.jsxs)("header",{className:"project-picker-header",children:[(0,t.jsx)("h2",{id:"project-picker-title",children:s("directory.title")}),(0,t.jsx)("div",{className:`project-picker-crumb-bar${null!==x?" editing":""}`,children:null===x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("nav",{className:"project-picker-crumbs","aria-label":s("directory.path"),children:L.map((e,n)=>(0,t.jsxs)("span",{children:[n>0&&(0,t.jsx)(j,{size:12,"aria-hidden":"true"}),(0,t.jsx)("button",{type:"button",disabled:q,onClick:()=>void E(e.path),children:e.name})]},e.path))}),(0,t.jsx)("button",{type:"button",className:"project-picker-edit-path","aria-label":s("directory.editPath"),title:s("directory.editPath"),disabled:q,onClick:()=>{if(!r||q)return;let e=o?.path??r.path;v(e.endsWith(O)?e:`${e}${O}`)},children:(0,t.jsx)(sM,{size:14,"aria-hidden":"true"})})]}):(0,t.jsx)("input",{ref:T,value:x,"aria-label":s("directory.editPath"),disabled:q,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&x.trim()&&E(x),"Escape"!==e.key||e.nativeEvent.isComposing||(e.stopPropagation(),v(null))}})}),D.length>1&&(0,t.jsx)("nav",{className:"project-picker-roots","aria-label":s("directory.roots"),children:D.map(e=>{var n,a;return(0,t.jsx)("button",{type:"button",className:`project-picker-root${(n=r?.path??null,n&&(n===e||n.startsWith(e.endsWith(O)?e:`${e}${O}`)))?" active":""}`,title:e,disabled:q,onClick:()=>void E(e),children:(a=s("directory.home"),e===(r?.home??"")?a:oS(e))},e)})})]}),(0,t.jsxs)("main",{className:"project-picker-content",children:[(0,t.jsxs)("div",{className:"project-picker-miller-row",children:[r&&(0,t.jsx)(oI,{listing:r,selectedPath:o?.path??null,showHidden:y,disabled:q,onSelect:e=>void A(e)}),o&&(0,t.jsx)("span",{className:"project-picker-divider"}),o&&d&&(0,t.jsx)(oI,{listing:d,selectedPath:null,showHidden:y,disabled:q,onSelect:$})]}),p&&(0,t.jsx)("div",{className:"project-picker-loading",role:"status",children:s("directory.loading")}),(r?.truncated||d?.truncated)&&(0,t.jsx)("div",{className:"project-picker-status",children:s("directory.truncated")}),m&&(0,t.jsx)("div",{className:"project-picker-error",role:"alert",children:m})]}),(0,t.jsxs)("footer",{className:"project-picker-footer",children:[(0,t.jsxs)("button",{type:"button",className:"project-picker-button outline new-folder",disabled:!r||p||q||null!==x,onClick:()=>{w(""),I(null)},children:[(0,t.jsx)(S,{size:14,"aria-hidden":"true"})," ",s("directory.newFolder")]}),(0,t.jsxs)("button",{type:"button",className:`project-picker-show-hidden${y?" active":""}`,"aria-pressed":y,disabled:q,onClick:()=>b(e=>!e),children:[s("directory.showHidden"),y&&(0,t.jsx)(Y,{size:14,"aria-hidden":"true"})]}),(0,t.jsx)("span",{className:"project-picker-footer-gap"}),(0,t.jsx)("button",{type:"button",className:"project-picker-button outline",disabled:q,onClick:i,children:s("directory.cancel")}),(0,t.jsx)("button",{type:"button",className:"project-picker-button primary",disabled:!z||p||q||null!==x,onClick:()=>void U(),children:e?s("directory.opening"):s("directory.open")})]})]}),null!==k&&(0,t.jsx)("div",{className:"project-picker-nested-overlay",onPointerDown:e=>{e.target!==e.currentTarget||N||w(null)},children:(0,t.jsxs)("div",{className:"project-picker-create-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"project-folder-title",children:[(0,t.jsx)("h3",{id:"project-folder-title",children:s("directory.newFolder")}),(0,t.jsx)("p",{children:s("directory.createIn",{name:F})}),(0,t.jsx)("input",{value:k,"aria-label":s("directory.folderName"),placeholder:s("directory.untitledFolder"),autoFocus:!0,disabled:N,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&B(),"Escape"!==e.key||N||e.nativeEvent.isComposing||(e.stopPropagation(),w(null))}}),C&&(0,t.jsx)("div",{className:"project-picker-error",role:"alert",children:C}),(0,t.jsxs)("div",{className:"project-picker-create-actions",children:[(0,t.jsx)("button",{type:"button",className:"project-picker-button outline",disabled:N,onClick:()=>w(null),children:s("directory.cancel")}),(0,t.jsx)("button",{type:"button",className:"project-picker-button primary",disabled:N||!k.trim(),onClick:()=>void B(),children:s("directory.create")})]})]})})]})}let oT=o("database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),oM=o("layers",[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]]),oR=o("package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]),oE=o("plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]]),oA=o("shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]),o$={state:"idle"},oz=(0,n.createContext)({status:o$,markSaving:()=>{},markSaved:()=>{},markError:()=>{}});function oF({children:e}){let[a,i]=(0,n.useState)(o$),s=(0,n.useRef)(void 0),r=(0,n.useCallback)(()=>{void 0!==s.current&&(window.clearTimeout(s.current),s.current=void 0)},[]),l=(0,n.useCallback)(()=>{r(),i({state:"saving"})},[r]),o=(0,n.useCallback)(()=>{r(),i({state:"saved"}),s.current=window.setTimeout(()=>{s.current=void 0,i(o$)},2400)},[r]),c=(0,n.useCallback)(e=>{r(),i({state:"error",message:e})},[r]);(0,n.useEffect)(()=>r,[r]);let d=(0,n.useMemo)(()=>({status:a,markSaving:l,markSaved:o,markError:c}),[a,l,o,c]);return(0,t.jsx)(oz.Provider,{value:d,children:e})}function oL(){return(0,n.useContext)(oz)}function oD(){let{status:e}=oL(),n=(0,f.useT)();if("idle"===e.state)return null;let a=n("saving"===e.state?"settings.status.saving":"saved"===e.state?"settings.status.saved":"settings.status.failed"),i="saving"===e.state?(0,t.jsx)(eZ,{size:13,className:"spin","aria-hidden":"true"}):"saved"===e.state?(0,t.jsx)(Y,{size:13,"aria-hidden":"true"}):(0,t.jsx)(e0,{size:13,"aria-hidden":"true"});return(0,t.jsxs)("span",{className:"settings-save-status","data-state":e.state,role:"status","aria-live":"polite",title:e.message,children:[i,(0,t.jsx)("span",{children:a})]})}function oO(...e){return e.filter(Boolean).join(" ")}function oq({title:e,description:a,actions:i,className:s,children:r}){let l=(0,n.useId)();return(0,t.jsxs)("section",{className:oO("settings-section",s),"aria-labelledby":e?l:void 0,children:[(e||a||i)&&(0,t.jsxs)("div",{className:"settings-section-header",children:[(0,t.jsxs)("div",{children:[e&&(0,t.jsx)("h3",{id:l,children:e}),a&&(0,t.jsx)("p",{children:a})]}),i&&(0,t.jsx)("div",{className:"settings-section-actions",children:i})]}),r]})}function oB({title:e,meta:n,actions:a,children:i,className:s}){return(0,t.jsxs)("div",{className:oO("settings-row",s),children:[(0,t.jsxs)("div",{className:"settings-row-copy",children:[(0,t.jsx)("strong",{children:e}),n&&(0,t.jsx)("span",{children:n})]}),i,a&&(0,t.jsx)("div",{className:"settings-row-actions",children:a})]})}function oU({children:e,className:n}){return(0,t.jsx)("div",{className:oO("settings-list",n),children:e})}function oH({policies:e,models:n,session:a,refresh:i,setError:s,onSessionUpdated:r}){let{markSaving:l,markSaved:o}=oL();async function c(e,t){l();try{await (0,e3.apiFetch)("/v1/policy-profiles",{method:"POST",body:JSON.stringify({name:e,kind:"compaction",config:t})}),s(null),await i(),o()}catch(e){s(e.message)}}async function d(e){l();try{await (0,e3.apiFetch)(`/v1/policy-profiles/${encodeURIComponent(e)}/default`,{method:"PUT"}),s(null),await i(),o()}catch(e){s(e.message)}}async function u(e){if(a){l();try{let t=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",body:JSON.stringify(e)});r(t),s(null),o()}catch(e){s(e.message)}}}return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-context-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-context-heading",children:"Context & session"}),(0,t.jsx)("p",{children:"Compaction policy versions and defaults frozen into the next Session Run."})]}),(0,t.jsx)(oW,{policies:e,models:n,onCreate:c,onDefault:d}),(0,t.jsx)(oq,{title:"Current session",description:a?a.title:"Select a Session to configure its defaults.",className:"current-session-settings",children:(0,t.jsxs)("div",{className:"session-default-grid",children:[(0,t.jsxs)("label",{className:"session-model-select",children:["Default model",(0,t.jsxs)("select",{disabled:!a,value:a?.defaultModelProfileId??"",onChange:e=>void u({defaultModelProfileId:e.target.value||null}),children:[(0,t.jsx)("option",{value:"",children:"Use global default"}),n.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]})]}),(0,t.jsxs)("label",{className:"session-model-select",children:["Context compaction",(0,t.jsxs)("select",{disabled:!a,value:a?.compactionPolicyProfileId??"",onChange:e=>void u({compactionPolicyProfileId:e.target.value||null}),children:[(0,t.jsx)("option",{value:"",children:"Use global default"}),e.filter(e=>"compaction"===e.kind&&"active"===e.status).map(e=>(0,t.jsxs)("option",{value:e.id,children:[e.name," v",e.version]},e.id))]})]})]})}),(0,t.jsx)(oV,{sessionId:a?.id??null})]})}function oW({policies:e,models:a,onCreate:i,onDefault:s}){let r=(0,f.useT)(),[l,o]=(0,n.useState)([]),c=(e,t)=>o(n=>n.map((n,a)=>a===e?{...n,...t}:n));async function d(e){e.preventDefault();let t=e.currentTarget,n=new FormData(t),a=String(n.get("mode")),s="manual_and_auto"===a&&"on"===n.get("allowOverflowRecovery"),r=l.filter(e=>e.modelProfileId).map(e=>({modelProfileId:e.modelProfileId,...void 0!==e.triggerRatio?{triggerRatio:e.triggerRatio}:{},...void 0!==e.tailMaxTokens?{tailMaxTokens:e.tailMaxTokens}:{},...void 0!==e.summaryMaxOutputTokens?{summaryMaxOutputTokens:e.summaryMaxOutputTokens}:{}}));await i(String(n.get("name")),{mode:a,triggerRatio:Number(n.get("triggerRatio")),keepRecentTurns:Number(n.get("keepRecentTurns")),tailTokenRatio:Number(n.get("tailTokenRatio")),tailMinTokens:Number(n.get("tailMinTokens")),tailMaxTokens:Number(n.get("tailMaxTokens")),summaryInputRatio:Number(n.get("summaryInputRatio")),compactionModelProfileId:n.get("compactionModelProfileId")||null,summaryMaxOutputTokens:Number(n.get("summaryMaxOutputTokens")),...r.length>0?{modelPolicies:r}:{},includeReasoning:"on"===n.get("includeReasoning"),allowHistoryLookup:"on"===n.get("allowHistoryLookup"),allowOverflowRecovery:s,maxOverflowRecoveries:+!!s,ineffectiveReclaimRatio:Number(n.get("ineffectiveReclaimRatio")),ineffectiveLimit:Number(n.get("ineffectiveLimit")),failureCooldownSeconds:Number(n.get("failureCooldownSeconds")),promptVersion:"v1"}),t.reset(),o([])}return(0,t.jsxs)(oq,{title:"Context compaction",description:"Manual and bounded automatic context checkpoint behavior.",children:[(0,t.jsxs)("form",{className:"settings-form compaction-form",onSubmit:d,children:[(0,t.jsxs)("label",{children:["Name",(0,t.jsx)("input",{name:"name",required:!0})]}),(0,t.jsxs)("label",{children:["Mode",(0,t.jsxs)("select",{name:"mode",defaultValue:"manual_only",children:[(0,t.jsx)("option",{value:"disabled",children:"Disabled"}),(0,t.jsx)("option",{value:"manual_only",children:"Manual only"}),(0,t.jsx)("option",{value:"manual_and_auto",children:"Manual and automatic"})]})]}),(0,t.jsxs)("label",{children:["Summary model",(0,t.jsxs)("select",{name:"compactionModelProfileId",defaultValue:"",children:[(0,t.jsx)("option",{value:"",children:"Use run model"}),a.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]})]}),(0,t.jsxs)("label",{children:["Trigger ratio",(0,t.jsx)("input",{name:"triggerRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.75",required:!0})]}),(0,t.jsxs)("label",{children:["Recent turns",(0,t.jsx)("input",{name:"keepRecentTurns",type:"number",min:"1",step:"1",defaultValue:"2",required:!0})]}),(0,t.jsxs)("label",{children:["Tail ratio",(0,t.jsx)("input",{name:"tailTokenRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.2",required:!0})]}),(0,t.jsxs)("label",{children:["Tail minimum",(0,t.jsx)("input",{name:"tailMinTokens",type:"number",min:"1",step:"1",defaultValue:"8000",required:!0})]}),(0,t.jsxs)("label",{children:["Tail maximum",(0,t.jsx)("input",{name:"tailMaxTokens",type:"number",min:"1",step:"1",defaultValue:"32000",required:!0})]}),(0,t.jsxs)("label",{children:["Summary input ratio",(0,t.jsx)("input",{name:"summaryInputRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.7",required:!0})]}),(0,t.jsxs)("label",{children:["Summary output",(0,t.jsx)("input",{name:"summaryMaxOutputTokens",type:"number",min:"1",step:"1",defaultValue:"4096",required:!0})]}),(0,t.jsxs)("label",{children:["Cooldown seconds",(0,t.jsx)("input",{name:"failureCooldownSeconds",type:"number",min:"0",step:"1",defaultValue:"600",required:!0})]}),(0,t.jsxs)("label",{children:["Ineffective ratio",(0,t.jsx)("input",{name:"ineffectiveReclaimRatio",type:"number",min:"0",max:"0.99",step:"0.01",defaultValue:"0.1",required:!0})]}),(0,t.jsxs)("label",{children:["Ineffective limit",(0,t.jsx)("input",{name:"ineffectiveLimit",type:"number",min:"1",step:"1",defaultValue:"3",required:!0})]}),(0,t.jsxs)("div",{className:"settings-toggles compaction-toggles",children:[(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"allowHistoryLookup",type:"checkbox",defaultChecked:!0})," History lookup"]}),(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"allowOverflowRecovery",type:"checkbox",defaultChecked:!0})," Overflow recovery"]}),(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"includeReasoning",type:"checkbox"})," Include reasoning"]})]}),(0,t.jsxs)("div",{className:"settings-subsection compaction-model-policies",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h4",{children:"Per-model overrides"}),(0,t.jsx)("p",{children:"Optional budget overrides for a specific model."})]}),l.map((e,n)=>(0,t.jsxs)("div",{className:"model-policy-row",children:[(0,t.jsxs)("select",{value:e.modelProfileId,onChange:e=>c(n,{modelProfileId:e.target.value}),"aria-label":`Override model ${n+1}`,children:[(0,t.jsx)("option",{value:"",children:"Select model…"}),a.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]}),(0,t.jsx)("input",{type:"number",step:"0.01",min:"0.01",max:"0.99",placeholder:"Trigger ratio",value:e.triggerRatio??"",onChange:e=>c(n,{triggerRatio:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("input",{type:"number",step:"1",min:"1",placeholder:"Tail max tokens",value:e.tailMaxTokens??"",onChange:e=>c(n,{tailMaxTokens:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("input",{type:"number",step:"1",min:"1",placeholder:"Summary output",value:e.summaryMaxOutputTokens??"",onChange:e=>c(n,{summaryMaxOutputTokens:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:()=>o(e=>e.filter((e,t)=>t!==n)),"aria-label":r("settings.context.removeOverride",{index:String(n+1)}),children:(0,t.jsx)(m,{size:12,"aria-hidden":"true"})})]},n)),(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:()=>o(e=>[...e,{modelProfileId:""}]),children:"+ Add override"})]}),(0,t.jsx)("button",{type:"submit",children:"Create version"})]}),(0,t.jsx)("div",{className:"settings-list",children:e.filter(e=>"compaction"===e.kind).map(e=>(0,t.jsxs)("div",{className:"settings-row",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("strong",{children:e.name}),(0,t.jsxs)("span",{children:["v",e.version," · ",String(e.config.mode??"configured")]})]}),(0,t.jsx)("button",{className:"secondary-btn",disabled:"active"!==e.status,onClick:()=>s(e.id),children:"Use as default"})]},e.id))})]})}function oV({sessionId:e}){let{markSaving:a,markSaved:i}=oL(),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)(null),[c,d]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!e)return;let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/standing-approvals`).then(n=>{t||(r(n?.items??[]),d(null),o(e))}).catch(n=>{t||(r([]),d(n.message),o(e))}),()=>{t=!0}},[e]);let u=l===e,p=u?s:[],h=!u,m=u?c:null,f=(0,n.useCallback)(async t=>{if(e){a();try{await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/standing-approvals/${encodeURIComponent(t)}/revoke`,{method:"POST"}),r(e=>e.filter(e=>e.id!==t)),d(null),i()}catch(e){d(e.message)}}},[e,a,i]);return e?(0,t.jsxs)(oq,{title:"Standing approvals",description:"Tools automatically authorised for this session. Revoke to require approval again.",className:"standing-approvals-section",children:[h&&(0,t.jsx)("div",{className:"settings-empty",children:"Loading…"}),!h&&m&&(0,t.jsx)("div",{className:"settings-error",children:m}),!h&&!m&&0===p.length&&(0,t.jsx)("div",{className:"settings-empty",children:"No standing approvals for this session."}),!h&&p.length>0&&(0,t.jsx)(oU,{children:p.map(e=>(0,t.jsx)(oB,{title:e.toolName,meta:e.scopeDisplay,actions:(0,t.jsx)("button",{className:"secondary-btn",onClick:()=>f(e.id),children:"Revoke"})},e.id))})]}):null}let oK=o("monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]),oG="ennote-default-permission",oJ="ennote-default-permission-change",oY=["discuss","ask","auto"];function oQ(){try{let e=window.localStorage.getItem(oG);if(null!==e&&oY.includes(e))return e}catch{}return"discuss"}var oZ=e.i(18929),oX=e.i(426);let o0=["discuss","ask","auto"];function o1(){let{mode:e,setThemeMode:a}=r4(),{locale:i,setLocale:s}=(0,f.useLocale)(),[r,l]=(0,n.useState)(()=>oQ()),{markSaved:o}=oL(),c=e=>(0,oX.translate)(i,e),d=[{id:"light",label:"Light",icon:(0,t.jsx)(rJ,{size:15,"aria-hidden":"true"})},{id:"dark",label:"Dark",icon:(0,t.jsx)(rG,{size:15,"aria-hidden":"true"})},{id:"system",label:"System",icon:(0,t.jsx)(oK,{size:15,"aria-hidden":"true"})}];return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-general-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-general-heading",children:c("general.title")}),(0,t.jsx)("p",{children:c("general.desc")})]}),(0,t.jsx)(oq,{title:c("general.appearance"),className:"appearance-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.appearance"),children:d.map(n=>(0,t.jsxs)("button",{type:"button",className:`appearance-cube ${e===n.id?"selected":""}`,"aria-pressed":e===n.id,onClick:()=>{a(n.id),o()},children:[n.icon,(0,t.jsx)("span",{children:n.label})]},n.id))})}),(0,t.jsx)(oq,{title:c("general.permission"),description:c("general.permission.desc"),className:"permission-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.permission"),children:o0.map(e=>(0,t.jsx)("button",{type:"button",className:`appearance-cube ${r===e?"selected":""}`,"aria-pressed":r===e,title:c(`permission.${e}.description`),onClick:()=>{l(e);try{window.localStorage.setItem(oG,e)}catch{}window.dispatchEvent(new CustomEvent(oJ,{detail:e})),o()},children:(0,t.jsx)("span",{children:c(`permission.${e}`)})},e))})}),(0,t.jsx)(oq,{title:c("general.language"),className:"language-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.language"),children:oZ.LOCALES.map(e=>(0,t.jsx)("button",{type:"button",className:`appearance-cube ${i===e?"selected":""}`,"aria-pressed":i===e,onClick:()=>{s(e),o()},children:(0,t.jsx)("span",{children:"en"===e?c("language.en"):c("language.zh")})},e))})})]})}function o2(e,t){return(0,e3.apiFetch)("/v1/packs/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:{kind:"path",path:e},dryRun:t.dryRun,...t.expectedDigest?{expectedDigest:t.expectedDigest}:{}})})}var o4=e.i(67203);function o5({setError:e}){let[a,i]=(0,n.useState)([]),[s,r]=(0,n.useState)(!0),[l,o]=(0,n.useState)(""),[c,d]=(0,n.useState)(!1),[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(null),[f,g]=(0,n.useState)(null),[x,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(null),k=async()=>{try{i(await (0,e3.apiFetch)("/v1/packs")),e(null)}catch(t){e(t.message)}finally{r(!1)}};(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void k(),0);return()=>window.clearTimeout(e)},[]);let j=async t=>{if(!c){d(!0),e(null);try{await t()}catch(t){e(t.message)}finally{d(!1)}}},w=e=>{o(e),m(null),g(null),p(null),b(null)},N=async()=>{!h||f!==l.trim()||await rx({title:`Install ${h.pack.name} ${h.pack.version}?`,description:h.willPublishFlowRevision?"This creates disabled draft objects and publishes an Agent Flow revision.":"This creates disabled draft objects on this Worker. Nothing runs until a revision is published and bound.",confirmLabel:"Install"})&&await j(async()=>{await o2(l.trim(),{dryRun:!1,expectedDigest:h.packDigest}),m(null),g(null),p(null),w(""),await k()})},_=async(t,n)=>{let a,i=2!==(a=t.pack.id.split("/")).length||""===a[0]||""===a[1]?null:{publisher:a[0],name:a[1]};i?await rx({title:n?`Force-remove ${t.pack.name}?`:`Remove ${t.pack.name}?`,description:n?"This also deletes objects that were edited locally or still referenced by another Graph.":"Every object this pack installed is deleted. A locally edited Skill is kept, with a warning.",confirmLabel:n?"Force remove":"Remove",tone:"danger"})&&await j(async()=>{v(t.pack.id);try{await function(e,t,n=!1){return(0,e3.apiFetch)(`/v1/packs/${encodeURIComponent(e)}/${encodeURIComponent(t)}${n?"?force=true":""}`,{method:"DELETE"})}(i.publisher,i.name,n),b(null),await k()}catch(e){throw b(t.pack.id),e}finally{v(null)}}):e(`"${t.pack.id}" is not a publisher/name pack id.`)},C=null===h||f!==l.trim()||h.blockers.length>0;return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-packs-heading",children:[(0,t.jsx)("h3",{id:"settings-packs-heading",className:o4.default.heading,children:"Agent Packs"}),(0,t.jsx)("p",{className:o4.default.note,children:"A pack ships Heroes, Skills, and optionally a Graph or Agent Flow. Installing one only creates disabled drafts on this Worker — nothing runs until a revision is published and bound."}),(0,t.jsxs)("div",{className:o4.default.installer,children:[(0,t.jsxs)("label",{className:o4.default.pathLabel,children:[(0,t.jsx)("span",{children:"Pack path on the Worker host"}),(0,t.jsx)("input",{className:o4.default.pathInput,value:l,placeholder:"/home/me/packs/example.enpack",onChange:e=>w(e.target.value)})]}),(0,t.jsxs)("div",{className:o4.default.actions,children:[(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||""===l.trim(),onClick:()=>j(async()=>{var e;m(null),g(null),p(await (e=l.trim(),(0,e3.apiFetch)("/v1/packs/inspect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:{kind:"path",path:e}})})))}),children:"Inspect"}),(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||""===l.trim(),onClick:()=>j(async()=>{m(await o2(l.trim(),{dryRun:!0})),g(l.trim())}),children:"Check install"}),(0,t.jsx)("button",{type:"button",className:`${o4.default.button} ${o4.default.primary}`,disabled:c||""===l.trim()||C,onClick:N,children:"Install"})]})]}),u&&(0,t.jsxs)("div",{className:o4.default.card,"data-testid":"pack-inspect",children:[(0,t.jsxs)("div",{className:o4.default.cardHead,children:[(0,t.jsx)(oR,{size:14,"aria-hidden":"true"}),(0,t.jsx)("span",{className:o4.default.cardName,children:u.pack.name}),(0,t.jsx)("span",{className:o4.default.badge,children:u.pack.version}),(0,t.jsx)("span",{className:o4.default.badge,children:u.pack.id}),!u.signed&&(0,t.jsx)("span",{className:o4.default.badge,children:"unsigned"})]}),(0,t.jsxs)("div",{className:o4.default.counts,children:[u.flows.length," flows · ",u.heroes.length," heroes · ",u.skills.length," skills · ",u.filesTotal," files"]}),(0,t.jsxs)("div",{className:o4.default.digest,children:["pack digest ",u.packDigest.slice(0,16),"…"]}),(0,t.jsx)(o3,{issues:u.warnings})]}),h&&(0,t.jsxs)("div",{className:o4.default.card,"data-testid":"pack-plan","data-blocked":C||void 0,children:[(0,t.jsxs)("div",{className:o4.default.cardHead,children:[(0,t.jsx)("span",{className:o4.default.cardName,children:"Install plan"}),(0,t.jsxs)("span",{className:o4.default.badge,children:[h.actions.length," actions"]}),h.willPublishFlowRevision&&(0,t.jsx)("span",{className:o4.default.badge,children:"publishes a revision"})]}),(0,t.jsx)("ul",{className:o4.default.actionList,children:h.actions.map(e=>(0,t.jsxs)("li",{className:o4.default.actionRow,children:[(0,t.jsx)("span",{className:o4.default.badge,children:e.kind}),(0,t.jsx)("span",{className:o4.default.actionId,children:e.storeId}),(0,t.jsx)("span",{className:o4.default.actionVerb,"data-action":e.action,children:e.action})]},`${e.kind}:${e.storeId}`))}),(0,t.jsx)(o3,{issues:[...h.blockers.map(e=>({...e,severity:e.severity??"error"})),...h.warnings.map(e=>({...e,severity:e.severity??"warning"}))]})]}),(0,t.jsxs)("div",{className:o4.default.sectionHeader,children:["Installed ",(0,t.jsx)("span",{className:o4.default.sectionCount,children:a.length}),(0,t.jsx)("button",{type:"button",className:o4.default.iconButton,"aria-label":"Refresh installed packs",onClick:()=>void k(),children:(0,t.jsx)(sY,{size:13,"aria-hidden":"true"})})]}),s?(0,t.jsx)("div",{className:o4.default.empty,children:"Loading…"}):0===a.length?(0,t.jsx)("div",{className:o4.default.empty,children:"No packs installed."}):(0,t.jsx)("div",{className:o4.default.stack,children:a.map(e=>(0,t.jsxs)("div",{className:o4.default.row,"data-testid":"pack-row",children:[(0,t.jsxs)("div",{className:o4.default.identity,children:[(0,t.jsxs)("div",{className:o4.default.titleRow,children:[(0,t.jsx)("span",{className:o4.default.name,children:e.pack.name}),(0,t.jsx)("span",{className:o4.default.badge,children:e.pack.version})]}),(0,t.jsxs)("div",{className:o4.default.meta,children:[e.flowCount," flows · ",e.heroCount," heroes · ",e.skillCount," skills"]})]}),y===e.pack.id&&(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||x===e.pack.id,onClick:()=>void _(e,!0),children:"Force remove"}),(0,t.jsx)("button",{type:"button",className:o4.default.iconButton,"aria-label":`Remove ${e.pack.name}`,disabled:c||x===e.pack.id,onClick:()=>void _(e,!1),children:(0,t.jsx)(P,{size:13,"aria-hidden":"true"})})]},e.pack.id))})]})}function o3({issues:e}){return 0===e.length?null:(0,t.jsx)("ul",{className:o4.default.issueList,children:e.map(e=>(0,t.jsxs)("li",{className:o4.default.issueRow,"data-severity":e.severity??"warning",children:[(0,t.jsx)("span",{className:o4.default.badge,children:e.code}),(0,t.jsx)("span",{children:e.message})]},`${e.code}:${e.message}`))})}var o6=e.i(82399);let o8={stdio:"stdio",streamable_http:"Streamable HTTP",legacy_sse:"HTTP + SSE"};function o9({mcp:e}){let{showCreate:n,transport:a,setTransport:i,displayName:s,setDisplayName:r,slug:l,setSlug:o,executable:c,setExecutable:d,argv:u,setArgv:p,endpoint:h,setEndpoint:m,createProfile:f}=e;return(0,t.jsx)(t.Fragment,{children:n&&(0,t.jsxs)("div",{className:o6.default.form,children:[(0,t.jsxs)("div",{className:o6.default.formGrid,children:[(0,t.jsxs)("label",{className:o6.default.field,children:["Display name",(0,t.jsx)("input",{value:s,onChange:e=>r(e.target.value),className:o6.default.input,placeholder:"PubMed"})]}),(0,t.jsxs)("label",{className:o6.default.field,children:["Slug (fixed once bound)",(0,t.jsx)("input",{value:l,onChange:e=>o(e.target.value),className:o6.default.input,placeholder:"pubmed"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:o6.default.transportRow,children:["stdio","streamable_http","legacy_sse"].map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>i(e),className:o6.default.transportButton,"data-active":a===e||void 0,children:o8[e]},e))}),"stdio"===a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("label",{className:o6.default.field,children:["Executable",(0,t.jsx)("input",{value:c,onChange:e=>d(e.target.value),className:o6.default.input,placeholder:"/usr/bin/python3"})]}),(0,t.jsxs)("label",{className:o6.default.field,children:["Arguments (space-separated)",(0,t.jsx)("input",{value:u,onChange:e=>p(e.target.value),className:o6.default.input,placeholder:"/path/to/server.py"})]})]}):(0,t.jsxs)("label",{className:o6.default.field,children:["Endpoint URL",(0,t.jsx)("input",{value:h,onChange:e=>m(e.target.value),className:o6.default.input,placeholder:"https://example.com/mcp"})]})]}),(0,t.jsx)("button",{type:"button",onClick:f,disabled:!s.trim()||!l.trim()||("stdio"===a?!c.trim():!h.trim()),className:o6.default.createButton,children:"Create profile"})]})})}function o7({mcp:e,binding:n}){let{catalogs:a,toolSearch:i,setToolSearch:s,showCreds:r,setShowCreds:l,credEnv:o,setCredEnv:c,credRef:d,setCredRef:u,versionFor:p,updateBinding:h,toggleTool:m,selectAllTools:f,addCredential:g,removeCredential:x,testBinding:v,refreshCatalog:y,removeBinding:b}=e,k=a[n.id]??[],j=n.selectedRemoteToolNames??[],w=p(n),N=w?"stdio"===w.transport?`${w.executable??""} ${(w.argv??[]).join(" ")}`.trim():w.endpoint??"":"";return(0,t.jsxs)("div",{className:o6.default.card,children:[(0,t.jsxs)("div",{className:o6.default.cardHead,children:[(0,t.jsxs)("div",{className:o6.default.cardIdentity,children:[(0,t.jsxs)("div",{className:o6.default.cardTitle,children:[w?o8[w.transport]??w.transport:"MCP server",(0,t.jsxs)("span",{className:o6.default.cardMeta,children:["rev ",n.revision??0," · ",j.length," tools selected"]})]}),N&&(0,t.jsx)("div",{className:o6.default.commandSummary,children:N})]}),(0,t.jsxs)("div",{className:o6.default.actions,children:[(0,t.jsx)("button",{type:"button",title:n.required?"Server is required: Run start fails when unreachable":"Server is optional: Run start continues when unreachable",onClick:()=>h(n,{required:!n.required}),className:o6.default.requiredButton,"data-required":n.required||void 0,children:n.required?"required":"optional"}),(0,t.jsx)("button",{type:"button",title:"Edit credential references for this binding",onClick:()=>l(e=>({...e,[n.id]:!e[n.id]})),className:o6.default.ghostButton,children:"Credentials"}),(0,t.jsx)("button",{type:"button",onClick:async()=>{let e=!n.desiredEnabled;if(e){let e=w?"stdio"===w.transport?`Command: ${N}`:`Endpoint: ${w.endpoint??""}`:"";if(!await rx({title:"Enable this MCP server?",description:`${e}
|
|
6
|
+
${t}`)].filter(Boolean).join("\n\n")),O(),T(e=>e+1)}},[O,s,y]);(0,n.useEffect)(()=>{let e=b.current;if(!e)return;let t=()=>{let t=e.scrollHeight-e.scrollTop-e.clientHeight<80;C(t),t&&I(!1)};return e.addEventListener("scroll",t,{passive:!0}),t(),()=>e.removeEventListener("scroll",t)},[e.sessionId,L]),(0,n.useEffect)(()=>{let t=e.messages.length;t>N.current&&N.current>0&&!_&&I(!0),N.current=t},[e.messages.length,_]);let U=(0,n.useCallback)(()=>{let e=b.current;e&&(e.scrollTo({top:e.scrollHeight,behavior:"smooth"}),I(!1))},[]);return(0,t.jsxs)("main",{className:"chat-area","data-phase":L?"welcome":"active",children:[l&&(0,t.jsxs)("div",{className:"error-bar",role:"alert",children:[(0,t.jsx)("span",{children:l}),(0,t.jsx)("button",{onClick:o,"aria-label":y("conversation.chat.dismissError"),children:(0,t.jsx)(m,{size:15,"aria-hidden":"true"})})]}),a.recovery&&(0,t.jsxs)("div",{className:`recovery-bar ${a.recovery.retryable?"is-retryable":"is-blocked"}`,"data-testid":"run-recovery",children:[(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:"interrupted"===a.recovery.run.status?y("conversation.chat.runInterrupted"):y("conversation.chat.runFailed")}),a.recovery.retryable?y("conversation.chat.attemptRetryable",{attempt:String(a.recovery.run.attempt)}):function(e,t){switch(e){case"side_effect_boundary":return t("conversation.chat.recovery.sideEffect");case"projected_output":return t("conversation.chat.recovery.projectedOutput");case"active_run":return t("conversation.chat.recovery.activeRun");default:return t("conversation.chat.recovery.notActive")}}(a.recovery.blockedReason,y)]}),a.recovery.retryable&&(0,t.jsx)("button",{type:"button",onClick:a.retryRun,disabled:a.retrying||!!a.activeRun,children:a.retrying?y("conversation.chat.retrying"):y("conversation.chat.retry")})]}),!L&&(0,t.jsxs)("div",{className:"chat-scroll-region",children:[(0,t.jsx)("div",{className:"messages",ref:b,"data-testid":"chat-messages",children:(0,t.jsxs)("div",{className:"conversation-viewport",children:[e.hasMore&&(0,t.jsx)("div",{className:"history-control",children:(0,t.jsx)("button",{type:"button",onClick:z,disabled:e.loadingOlder,children:e.loadingOlder?y("conversation.chat.loadingEarlier"):y("conversation.chat.loadEarlier")})}),e.loading&&(0,t.jsx)("div",{className:"history-state",children:y("conversation.chat.loading")}),e.error&&(0,t.jsx)("div",{className:"history-state history-state-error",children:y("conversation.chat.historyUnavailable",{message:e.error})}),!e.loading&&0===e.messages.length&&!e.error&&!a.pendingApproval&&(0,t.jsxs)("div",{className:"history-empty",children:[(0,t.jsx)("strong",{children:y("conversation.chat.newConversation")}),(0,t.jsx)("span",{children:y("conversation.chat.startHint")})]}),(0,t.jsx)(r$,{sessionId:e.sessionId??"",nodes:e.messages,pendingApproval:a.pendingApproval,resolvingApproval:a.resolvingApproval,decideApproval:a.decideApproval,answeringQuestion:a.answeringQuestion,answerQuestion:a.answerQuestion,activeLeafMessageId:e.activeLeafMessageId,branchDisabled:!!a.activeRun||i.changing,createBranch:i.createBranch,runStatus:a.activeRun||a.status?{status:a.status,active:!!a.activeRun,waiting:R,waitingForQuestion:E,reconnecting:A,compacting:a.compacting,startedAt:a.startedAt,runId:a.activeRun,cacheReadTokens:a.usage?.cacheReadTokens??0,inputTokens:(a.usage?.uncachedInputTokens??0)+(a.usage?.cacheReadTokens??0)+(a.usage?.cacheWriteTokens??0),outputTokens:a.usage?.outputTokens??0}:void 0}),(0,t.jsx)("div",{ref:k})]})}),(0,t.jsx)(J,{nodes:e.messages,scrollContainer:b}),!_&&(0,t.jsxs)("button",{type:"button",className:"chat-jump-latest","data-new":S||void 0,onClick:U,"aria-label":y(S?"conversation.newMessages":"conversation.jumpLatest"),children:[(0,t.jsx)(K,{size:14,"aria-hidden":"true"}),y(S?"conversation.newMessages":"conversation.jumpLatest")]})]}),!L&&D.selection&&(0,t.jsx)(et,{selection:D.selection,onQuote:q,onExplain:B,onDismiss:O}),!L&&(0,t.jsx)(e8,{sessionId:e.sessionId??void 0}),!L&&s.compaction.open&&(0,t.jsx)(te,{value:s.compaction.instructions,onChange:s.compaction.setInstructions,busy:s.compaction.busy,onConfirm:s.compaction.confirm,onCancel:s.compaction.cancel}),(0,t.jsx)("div",{className:"composer-seat",children:(0,t.jsxs)("div",{className:L?"composer-stack composer-welcome":"composer-stack",children:[L&&(0,t.jsx)(eJ,{}),L&&(0,t.jsx)(eY,{hasModel:u,onOpenSettings:v}),L&&(0,t.jsx)("div",{className:"welcome-workspace-row",children:(0,t.jsx)(eQ,{projects:c,selectedProject:d,pinnedProjectIds:p,togglePinProject:h,onRequestProject:$,onSwitchProject:g,projectSelector:M})}),(0,t.jsx)(eG,{selectedSession:e.sessionId,activeLeafMessageId:e.activeLeafMessageId,input:s.input,setInput:s.setInput,focusNonce:P,activeRun:!!a.activeRun,questionPending:!!E,compacting:a.compacting,hasPendingImage:!!s.pendingImage,reconnecting:A,inert:!d,welcome:L,onRequestProject:$,permissionMode:s.displayedPermissionMode,permissionReady:s.permissionReady,setPermissionMode:s.setPermissionMode,models:s.models,providers:s.providers,selectedModelId:s.selectedModelId,setSelectedModelId:s.setSelectedModelId,thinkingEffort:s.thinkingEffort,setThinkingEffort:s.setThinkingEffort,textAttachments:s.textAttachments,removeTextAttachment:s.removeTextAttachment,pendingImage:s.pendingImage,clearPendingImage:s.clearPendingImage,attachFiles:s.attachFiles,uploadImage:s.uploadImage,submit:r.submit,steer:r.steer,steerText:r.steerText,followUp:r.followUp,cancel:a.cancel,cancelFollowUp:a.cancelFollowUp,compactSession:s.compactSession,pendingFollowUps:a.pendingFollowUps,picker:{templates:s.promptPanel.templates,heroes:s.promptPanel.heroes,graphs:s.promptPanel.flows,skills:s.promptPanel.skills,pendingSkills:s.promptPanel.pendingSkills,pendingGraph:s.promptPanel.pendingGraph,selectedHeroId:s.selectedHeroId,onSelectTemplate:s.promptPanel.onSelect,onSelectHero:s.promptPanel.onHeroSelect,onSelectGraph:s.promptPanel.onFlowSelect,onToggleSkill:s.promptPanel.toggleSkill,onClearGraph:s.promptPanel.clearPendingGraph},expanding:s.promptPanel.expanding,expandDiag:s.promptPanel.expandDiag,contextUsage:a.contextUsage,stats:a.stats})]})})]})}let rO=o("menu",[["path",{d:"M4 5h16",key:"1tepv9"}],["path",{d:"M4 12h16",key:"1lakjw"}],["path",{d:"M4 19h16",key:"1djgab"}]]),rq=o("panel-right",[["rect",{width:"18",height:"18",x:"3",y:"3",rx:"2",key:"afitv7"}],["path",{d:"M15 3v18",key:"14nvp0"}]]),rB=o("bell",[["path",{d:"M10.268 21a2 2 0 0 0 3.464 0",key:"vwvbt9"}],["path",{d:"M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326",key:"11g9vi"}]]),rU=o("shield-check",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}],["path",{d:"m9 12 2 2 4-4",key:"dzmm74"}]]);function rH({item:e,onNavigate:n,onDismiss:a}){let i,s=(0,f.useT)(),r=!e.requiresAction;return(0,t.jsxs)("div",{className:"attention-row",role:"listitem","data-kind":e.kind,"data-attention-id":e.id,children:[(0,t.jsx)("span",{className:"attention-icon",children:(i={size:13,"aria-hidden":!0},"needs_input"===e.kind?(0,t.jsx)(sQ,{...i}):"approval_required"===e.kind?(0,t.jsx)(rU,{...i}):(e.kind,(0,t.jsx)(e0,{...i})))}),(0,t.jsxs)("button",{type:"button",className:"attention-main",onClick:()=>n(e),children:[(0,t.jsx)("strong",{children:function(e,t){let n=e.display;switch(e.kind){case"approval_required":return t(n?.kind==="retry_budget"?"conversation.attention.retryBudget":"conversation.attention.approvalRequired");case"needs_input":if(n?.kind==="question"){let e=n.questionCount??0;return t(1===e?"conversation.attention.questionOne":"conversation.attention.questionMany",{count:e})}return t("conversation.attention.needsInput");case"delegation_completed":return t("conversation.attention.completed");case"delegation_failed":return t("conversation.attention.failed")}return t("conversation.attention.title")}(e,s)}),(0,t.jsx)("span",{children:e.display?.summary??e.sessionId})]}),r?(0,t.jsx)("button",{type:"button",className:"attention-dismiss","aria-label":s("conversation.attention.dismiss"),title:s("conversation.attention.dismiss"),onClick:()=>a(e),children:(0,t.jsx)(m,{size:13,"aria-hidden":"true"})}):(0,t.jsx)("span",{className:"attention-action-tag",children:function(e,t){switch(e){case"answer_question":return t("conversation.attention.actionAnswerQuestion");case"tool_approval":return t("conversation.attention.actionToolApproval");case"delegation_approval":return t("conversation.attention.actionDelegationApproval");case"delegation_input":return t("conversation.attention.actionDelegationInput")}return t("conversation.attention.action")}(e.action?.kind,s)})]})}function rW({projectId:e,onNavigate:a}){let i=(0,f.useT)(),{items:s,pendingCount:r,refresh:l}=function(e){let[t,a]=(0,n.useState)([]),[i,s]=(0,n.useState)(0);(0,n.useEffect)(()=>{let t;if(!e)return;let n=new AbortController,i=async()=>{try{let t=await (0,e3.apiFetch)(`/v1/attention?projectId=${encodeURIComponent(e)}&status=pending&limit=50`,{signal:n.signal});n.signal.aborted||a(t.items??[])}catch{}finally{n.signal.aborted||(t=window.setTimeout(i,5e3))}};return i(),()=>{n.abort(),void 0!==t&&window.clearTimeout(t)}},[e,i]);let r=(0,n.useMemo)(()=>t.filter(e=>"pending"===e.status).length,[t]);return{items:t,pendingCount:r,refresh:()=>s(e=>e+1)}}(e),[o,c]=(0,n.useState)(!1),d=(0,n.useRef)(null);M(o,()=>c(!1)),(0,n.useEffect)(()=>{if(!o)return;let e=e=>{d.current?.contains(e.target)||c(!1)};return document.addEventListener("pointerdown",e),()=>document.removeEventListener("pointerdown",e)},[o]);let u=async e=>{try{await (0,e3.apiFetch)(`/v1/attention/${encodeURIComponent(e.id)}/dismiss`,{method:"POST",body:JSON.stringify({clientRequestId:crypto.randomUUID()})}),l()}catch{l()}},p=[...s].sort((e,t)=>!!t.requiresAction-!!e.requiresAction);return(0,t.jsxs)("div",{className:"attention-panel",ref:d,children:[(0,t.jsxs)("button",{type:"button",className:"attention-bell","aria-label":i("conversation.attention.aria",{count:String(r)}),title:i("conversation.attention.title"),onClick:()=>c(e=>!e),children:[(0,t.jsx)(rB,{size:15,"aria-hidden":"true"}),r>0&&(0,t.jsx)("span",{className:"attention-badge",children:r>99?"99+":r})]}),o&&(0,t.jsxs)("div",{className:"attention-popover",role:"dialog","aria-label":i("conversation.attention.title"),children:[(0,t.jsxs)("div",{className:"attention-popover-header",children:[(0,t.jsx)("strong",{children:i("conversation.attention.title")}),(0,t.jsx)("span",{children:i("conversation.attention.pending",{count:String(r)})})]}),(0,t.jsxs)("div",{className:"attention-list",role:"list",children:[0===p.length&&(0,t.jsx)("div",{className:"attention-empty",children:i("conversation.attention.empty")}),p.map(e=>(0,t.jsx)(rH,{item:e,onNavigate:e=>{c(!1),a(e)},onDismiss:u},e.id))]})]})]})}let rV=o("git-branch",[["path",{d:"M15 6a9 9 0 0 0-9 9V3",key:"1cii5b"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}]]);function rK({branches:e,activeBranchId:a,loading:i,changing:s,disabled:r,activate:l}){let[o,c]=(0,n.useState)(!1),d=(0,n.useRef)(null),u=e.find(e=>e.id===a);return M(o,()=>c(!1)),(0,n.useEffect)(()=>{if(!o)return;let e=e=>{d.current?.contains(e.target)||c(!1)};return window.addEventListener("pointerdown",e),()=>window.removeEventListener("pointerdown",e)},[o]),(0,t.jsxs)("div",{className:"branch-control",ref:d,children:[(0,t.jsxs)("button",{type:"button",className:"branch-trigger","aria-label":"Choose conversation branch",title:"Choose conversation branch","aria-haspopup":"menu","aria-expanded":o,disabled:r||i||s,onClick:()=>c(e=>!e),children:[(0,t.jsx)(rV,{size:15,"aria-hidden":"true"}),(0,t.jsx)("span",{children:u?.label??(i?"Loading":"Main")}),e.length>1&&(0,t.jsx)("small",{children:e.length})]}),o&&(0,t.jsx)("div",{className:"branch-menu",role:"menu","aria-label":"Conversation branches",children:e.map(e=>(0,t.jsxs)("button",{type:"button",role:"menuitemradio","aria-checked":e.id===a,onClick:()=>{c(!1),l(e.id)},children:[(0,t.jsx)(rV,{size:14,"aria-hidden":"true"}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e.label}),(0,t.jsxs)("small",{children:[e.messageCount," messages"]})]}),e.id===a&&(0,t.jsx)(Y,{size:14,"aria-hidden":"true"})]},e.id))})]})}let rG=o("moon",[["path",{d:"M20.985 12.486a9 9 0 1 1-9.473-9.472c.405-.022.617.46.402.803a6 6 0 0 0 8.268 8.268c.344-.215.825-.004.803.401",key:"kfwtm"}]]),rJ=o("sun",[["circle",{cx:"12",cy:"12",r:"4",key:"4exip2"}],["path",{d:"M12 2v2",key:"tus03m"}],["path",{d:"M12 20v2",key:"1lh1kg"}],["path",{d:"m4.93 4.93 1.41 1.41",key:"149t6j"}],["path",{d:"m17.66 17.66 1.41 1.41",key:"ptbguv"}],["path",{d:"M2 12h2",key:"1t8f8n"}],["path",{d:"M20 12h2",key:"1q8mjw"}],["path",{d:"m6.34 17.66-1.41 1.41",key:"1m8zz5"}],["path",{d:"m19.07 4.93-1.41 1.41",key:"1shlcs"}]]),rY=new Set;function rQ(){let e=window.localStorage.getItem("ennote-theme");return"light"===e||"dark"===e?e:"system"}function rZ(e=rQ()){return"dark"===e?"dark":"light"===e?"light":window.matchMedia("(prefers-color-scheme: dark)").matches?"dark":"light"}function rX(){let e=rQ();return`${e}:${rZ(e)}`}function r0(e){rY.add(e);let t=window.matchMedia("(prefers-color-scheme: dark)"),n=()=>{"system"===rQ()&&(r1(rZ("system")),rY.forEach(e=>e()))},a=e=>{"ennote-theme"===e.key&&(r1(rZ()),rY.forEach(e=>e()))};return t.addEventListener("change",n),window.addEventListener("storage",a),()=>{rY.delete(e),t.removeEventListener("change",n),window.removeEventListener("storage",a)}}function r1(e){document.documentElement.classList.toggle("dark","dark"===e),document.documentElement.dataset.theme=e}function r2(e,t){let n=()=>{"system"===e?window.localStorage.removeItem("ennote-theme"):window.localStorage.setItem("ennote-theme",e),r1(rZ(e)),rY.forEach(e=>e())},a=window.matchMedia("(prefers-reduced-motion: reduce)").matches;if("function"!=typeof document.startViewTransition||a)return void n();let i=t?.x??window.innerWidth/2,s=t?.y??window.innerHeight/2,r=Math.hypot(Math.max(i,window.innerWidth-i),Math.max(s,window.innerHeight-s));document.startViewTransition(n).ready.then(()=>document.documentElement.animate({clipPath:[`circle(0 at ${i}px ${s}px)`,`circle(${r}px at ${i}px ${s}px)`]},{duration:420,easing:"cubic-bezier(0.22, 0.61, 0.36, 1)",pseudoElement:"::view-transition-new(root)"})).catch(()=>void 0)}function r4(){let[e,t]=(0,n.useSyncExternalStore)(r0,rX,()=>"system:light").split(":"),a=(0,n.useCallback)((e,t)=>r2(e,t),[]),i=(0,n.useCallback)(e=>r2("dark"===t?"light":"dark",e),[t]);return{mode:e,theme:t,isDark:"dark"===t,setThemeMode:a,toggleTheme:i}}function r5(){let{isDark:e,toggleTheme:n}=r4();return(0,t.jsx)(ru,{label:e?"Switch to light mode":"Switch to dark mode",title:e?"Switch to light mode":"Switch to dark mode","aria-pressed":e,onClick:e=>{let t=e.currentTarget.getBoundingClientRect();n({x:t.left+t.width/2,y:t.top+t.height/2})},children:e?(0,t.jsx)(rJ,{size:15,"aria-hidden":"true"}):(0,t.jsx)(rG,{size:15,"aria-hidden":"true"})})}function r3(e){let{sidebarOpen:n,onToggleSidebar:a,navigationTriggerRef:i,session:s,title:r,projectName:l,projectPath:o,branch:c,rightPanelOpen:d,onToggleRightPanel:u,attention:p}=e,{title:h,editing:m,draft:f,setDraft:x,startEdit:v,save:y,keyDown:b,inputRef:k}=r;return(0,t.jsxs)("div",{className:"app-topbar",children:[(0,t.jsx)(ru,{ref:i,label:n?"Hide navigation":"Open navigation",title:n?"Hide sidebar":"Show sidebar","aria-expanded":n,"aria-controls":"workspace-navigation",onClick:a,children:n?(0,t.jsx)(g,{size:16,"aria-hidden":"true"}):(0,t.jsx)(rO,{size:18,"aria-hidden":"true"})}),(0,t.jsxs)("div",{className:"topbar-title-area",children:[(0,t.jsx)("div",{className:"topbar-title-group",children:m&&s?(0,t.jsx)("input",{ref:k,className:"topbar-title-input",value:f,onChange:e=>x(e.target.value),onKeyDown:b,onBlur:()=>void y()}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"topbar-session-title",title:h,children:h}),s&&(0,t.jsx)("button",{type:"button",className:"topbar-title-edit",onClick:v,title:"Rename session","aria-label":"Rename session",children:(0,t.jsx)(C,{size:12,"aria-hidden":"true"})})]})}),l&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"topbar-project-sep",children:"/"}),(0,t.jsx)("span",{className:"topbar-project-crumb",title:o||l,children:l})]})]}),s&&(0,t.jsx)(rK,{branches:c.branches,activeBranchId:c.activeBranchId,loading:c.loading,changing:c.changing,disabled:c.disabled,activate:c.onActivate}),(0,t.jsx)(r5,{}),(0,t.jsx)(ru,{label:d?"Hide panel":"Show panel",title:d?"Hide panel":"Show panel",active:d,onClick:u,children:(0,t.jsx)(rq,{size:16,"aria-hidden":"true"})}),(0,t.jsx)(rW,{projectId:p.projectId,onNavigate:p.onNavigate})]})}let r6=o("arrow-left",[["path",{d:"m12 19-7-7 7-7",key:"1l729n"}],["path",{d:"M19 12H5",key:"x3x0zl"}]]),r8=o("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),r9=o("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]),r7=o("file-exclamation-point",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M12 9v4",key:"juzpu7"}],["path",{d:"M12 17h.01",key:"p32p05"}]]);function le(e,t){let n=new URLSearchParams({path:t});return`/v1/projects/${encodeURIComponent(e)}/files/content?${n.toString()}`}async function lt(e,t="/workspace",n){let a;return(0,e3.apiFetch)((a=new URLSearchParams({path:t}),`/v1/projects/${encodeURIComponent(e)}/files?${a.toString()}`),{signal:n})}async function ln(e,t,n){let a=await (0,e3.apiResponse)(le(e,t),{signal:n});if(!a.ok){let e=await a.json().catch(()=>({}));throw Error(e.error?.message??`HTTP ${a.status}`)}return a}function la(e){let t=e.replace(/\/+$/,""),n=t.lastIndexOf("/");return n<=0?{parent:"/workspace",name:t}:{parent:t.slice(0,n),name:t.slice(n+1)}}async function li(e,t){return(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files/create`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function ls(e,t){return(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files/move`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)})}async function lr(e,t,n={}){let a=new URLSearchParams({path:t});n.recursive&&a.set("recursive","true"),await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/files?${a.toString()}`,{method:"DELETE"})}let ll=new Set(["png","jpg","jpeg","gif","webp","svg","bmp","ico","avif"]),lo=new Set(["md","mdx","rmd","qmd"]),lc=new Set(["txt","json","yaml","yml","toml","csv","tsv","log","ts","tsx","js","jsx","mjs","cjs","py","r","rb","go","rs","java","c","cpp","h","hpp","css","scss","less","html","htm","xml","sh","bash","zsh","fish","ps1","bat","sql","graphql","gql","conf","cfg","ini","properties"]);function ld({projectId:a,filePath:i,fileName:s}){var r;let[l,o]=(0,n.useState)({kind:"loading"}),c=s??i.split("/").pop()??i,d=lu(c);(0,n.useEffect)(()=>{let t=new AbortController,n=null;return async function(){o({kind:"loading"});try{var s,r,l;let u,p,h=await ln(a,i,t.signal),m=Number(h.headers.get("Content-Length")??0),f=h.headers.get("Content-Type")?.split(";",1)[0]??"application/octet-stream";if(lo.has(d)){if(m>4194304)throw Error("Text preview exceeds the 4 MiB limit");let e=await h.text();t.signal.aborted||o({kind:"markdown",content:e,size:e.length});return}if(s=c,r=f,u=lu(s),p=s.toLowerCase(),r.startsWith("text/")||lc.has(u)||["dockerfile","makefile"].includes(p)||p.startsWith(".env")){let n,a;if(m>4194304)throw Error("Text preview exceeds the 4 MiB limit");let i=await h.text(),s=(l=c,n=lu(l),a=l.toLowerCase(),"dockerfile"===a?"dockerfile":"makefile"===a?"makefile":({ts:"typescript",tsx:"tsx",js:"javascript",jsx:"jsx",mjs:"javascript",cjs:"javascript",py:"python",r:"r",rb:"ruby",go:"go",rs:"rust",java:"java",c:"c",cpp:"cpp",h:"c",hpp:"cpp",css:"css",scss:"scss",less:"less",html:"html",htm:"html",xml:"xml",json:"json",yaml:"yaml",yml:"yaml",toml:"toml",sh:"bash",bash:"bash",zsh:"bash",fish:"fish",ps1:"powershell",sql:"sql",graphql:"graphql",gql:"graphql"})[n]??null),r=null;if(s)try{let{codeToHtml:t}=await e.A(140);r=await t(i,{lang:s,themes:{light:"github-light",dark:"github-dark"},defaultColor:!1})}catch{r=null}t.signal.aborted||o({kind:"code",content:i,highlighted:r,language:s??"text",size:i.length});return}if(ll.has(d)||f.startsWith("image/")){let e=await h.blob();n=URL.createObjectURL(e),t.signal.aborted||o({kind:"image",url:n,mime:f,size:e.size});return}if("pdf"===d||"application/pdf"===f){let e=await h.blob();n=URL.createObjectURL(e),t.signal.aborted||o({kind:"pdf",url:n,mime:f,size:e.size});return}o({kind:"unsupported",mime:f,size:m})}catch(e){t.signal.aborted||o({kind:"error",message:e.message})}}(),()=>{t.abort(),n&&URL.revokeObjectURL(n)}},[d,i,c,a]);let u="size"in l?(r=l.size)?r<1024?`${r} B`:r<1048576?`${(r/1024).toFixed(1)} KB`:`${(r/1048576).toFixed(1)} MB`:"0 B":null,p="code"===l.kind?l.language:d||l.kind,h=(0,e3.workerAPIPath)(le(a,i));return(0,t.jsxs)("div",{className:"file-viewer",children:[(0,t.jsxs)("div",{className:"file-viewer-status",children:[(0,t.jsx)("span",{className:"file-viewer-type",children:p}),(0,t.jsx)("span",{className:"file-viewer-path",title:i,children:i}),u&&(0,t.jsx)("span",{children:u}),(0,t.jsx)("a",{className:"file-viewer-download",href:h,download:c,title:"Download file","aria-label":`Download ${c}`,children:(0,t.jsx)(sz,{size:13,"aria-hidden":"true"})})]}),(0,t.jsxs)("div",{className:"file-viewer-body",children:["loading"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty",children:[(0,t.jsx)(eZ,{className:"spin",size:18}),"Loading preview..."]}),"error"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty is-error",children:[(0,t.jsx)(r7,{size:20}),l.message]}),"markdown"===l.kind&&(0,t.jsx)("article",{className:"markdown-body file-markdown",children:(0,t.jsx)(a7,{remarkPlugins:[sp],children:l.content})}),"code"===l.kind&&l.highlighted&&(0,t.jsx)("div",{className:"file-code",dangerouslySetInnerHTML:{__html:l.highlighted}}),"code"===l.kind&&!l.highlighted&&(0,t.jsx)("pre",{className:"file-code-plain",children:l.content}),"image"===l.kind&&(0,t.jsx)("div",{className:"file-image-stage",children:(0,t.jsx)("img",{src:l.url,alt:c})}),"pdf"===l.kind&&(0,t.jsx)("iframe",{className:"file-pdf",src:l.url,title:c}),"unsupported"===l.kind&&(0,t.jsxs)("div",{className:"file-viewer-empty",children:[(0,t.jsx)(r7,{size:20}),"Preview is not available for ",l.mime,"."]})]})]})}function lu(e){return e.includes(".")?e.toLowerCase().split(".").pop()??"":""}var lp=e.i(51535);let lh="var(--text-dim)";function lm({size:e=14,open:n=!1}){return n?(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,t.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5h7.5v1H1V4.5Z",fill:lh}),(0,t.jsx)("path",{d:"M1 6h14.5L14 13H2L1 6Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.12"})]}):(0,t.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:(0,t.jsx)("path",{d:"M1 4.5A1 1 0 0 1 2 3.5H5.5L7 5H14a1 1 0 0 1 1 1v6a1 1 0 0 1-1 1H2a1 1 0 0 1-1-1V4.5Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.1"})})}function lf({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none",children:[(0,t.jsx)("path",{d:"M3 2h7l3 3v9H3V2Z",stroke:lh,strokeWidth:"1",fill:lh,fillOpacity:"0.08"}),(0,t.jsx)("path",{d:"M10 2v3h3",stroke:lh,strokeWidth:"1",fill:"none",strokeLinejoin:"round"})]})}function lg({label:e,size:n=14}){return(0,t.jsxs)("svg",{width:n,height:n,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("text",{x:"7",y:"9.5",textAnchor:"middle",fontSize:"3.4",fontFamily:"var(--font-mono), monospace",fontWeight:"600",fill:lh,children:e})]})}function lx({size:e=14}){return(0,t.jsx)(lg,{label:"PY",size:e})}function lv({size:e=14}){return(0,t.jsx)(lg,{label:"R",size:e})}function ly({size:e=14}){return(0,t.jsx)(lg,{label:"TS",size:e})}function lb({size:e=14}){return(0,t.jsx)(lg,{label:"JS",size:e})}function lk({size:e=14}){return(0,t.jsx)(lg,{label:"{}",size:e})}function lj({size:e=14}){return(0,t.jsx)(lg,{label:"CSS",size:e})}function lw({size:e=14}){return(0,t.jsx)(lg,{label:"HTM",size:e})}function lN({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M3.5 9.5V7l1.5 1.5L6.5 7v2.5",stroke:lh,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,t.jsx)("path",{d:"M8 7v2.5M7 9l1 1.5 1-1.5",stroke:lh,strokeWidth:"0.9",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"})]})}function l_({size:e=14}){return(0,t.jsx)(lg,{label:"YML",size:e})}function lC({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M4 7.5l2 1.5-2 1.5",stroke:lh,strokeWidth:"0.95",strokeLinecap:"round",strokeLinejoin:"round",fill:"none"}),(0,t.jsx)("path",{d:"M7.5 10.5h2.5",stroke:lh,strokeWidth:"0.95",strokeLinecap:"round"})]})}function lS({size:e=14}){return(0,t.jsx)(lg,{label:"GO",size:e})}function lI({size:e=14}){return(0,t.jsx)(lg,{label:"RS",size:e})}function lP({size:e=14}){return(0,t.jsx)(lg,{label:"SQL",size:e})}function lT({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("rect",{x:"3.5",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"}),(0,t.jsx)("rect",{x:"6",y:"6.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"}),(0,t.jsx)("rect",{x:"3.5",y:"8.5",width:"2",height:"1.5",rx:"0.3",stroke:lh,strokeWidth:"0.8"})]})}function lM({size:e=14}){return(0,t.jsxs)("svg",{width:e,height:e,viewBox:"0 0 14 14",fill:"none",children:[(0,t.jsx)("path",{d:"M2.5 1h6l3 3v9h-9V1Z",stroke:lh,strokeWidth:"0.9",fill:lh,fillOpacity:"0.07",strokeLinejoin:"round"}),(0,t.jsx)("path",{d:"M8.5 1v3h3",stroke:lh,strokeWidth:"0.9",fill:"none",strokeLinejoin:"round"}),(0,t.jsx)("circle",{cx:"7",cy:"8.5",r:"1.3",stroke:lh,strokeWidth:"0.9"}),(0,t.jsx)("path",{d:"M7 6.5v.7M7 10.3v.7M5 8.5h.7M8.3 8.5H9M5.5 6.9l.5.5M8.5 9.6l-.5-.5M5.5 10.1l.5-.5M8.5 7.4l-.5.5",stroke:lh,strokeWidth:"0.8",strokeLinecap:"round"})]})}function lR(e,n=14){let a=e.toLowerCase(),i=a.split(".").pop()??"";return"dockerfile"===a||a.startsWith("dockerfile.")?(0,t.jsx)(lT,{size:n}):"py"===i?(0,t.jsx)(lx,{size:n}):"r"===i||"rds"===i||"qs"===i?(0,t.jsx)(lv,{size:n}):"ts"===i?(0,t.jsx)(ly,{size:n}):"tsx"===i?(0,t.jsx)(lg,{label:"TSX",size:n}):"js"===i||"mjs"===i||"cjs"===i?(0,t.jsx)(lb,{size:n}):"jsx"===i?(0,t.jsx)(lg,{label:"JSX",size:n}):"json"===i||"jsonl"===i?(0,t.jsx)(lk,{size:n}):"css"===i||"less"===i?(0,t.jsx)(lj,{size:n}):"scss"===i?(0,t.jsx)(lg,{label:"SC",size:n}):"html"===i||"htm"===i?(0,t.jsx)(lw,{size:n}):"md"===i||"mdx"===i?(0,t.jsx)(lN,{size:n}):"yaml"===i||"yml"===i?(0,t.jsx)(l_,{size:n}):"toml"===i?(0,t.jsx)(lg,{label:"TOM",size:n}):"sh"===i||"bash"===i||"zsh"===i||"fish"===i?(0,t.jsx)(lC,{size:n}):"rs"===i?(0,t.jsx)(lI,{size:n}):"go"===i?(0,t.jsx)(lS,{size:n}):"sql"===i?(0,t.jsx)(lP,{size:n}):"tf"===i||"hcl"===i?(0,t.jsx)(lg,{label:"TF",size:n}):"lock"===i?(0,t.jsx)(lg,{label:"LK",size:n}):i.endsWith("config.ts")||i.endsWith("config.js")||i.endsWith("config.mjs")?(0,t.jsx)(lM,{size:n}):(0,t.jsx)(lf,{size:n})}function lE({tabs:e,activeTabId:a,onSelectTab:i,onCloseTab:s,onReorder:r,closeLabel:l}){let[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),p=()=>{c(null),u(null)};return(0,t.jsx)("div",{role:"tablist","aria-label":"Workspace panel tabs",className:lp.default.bar,children:e.map((n,f)=>{let g=n.id===a,x=!1!==n.closable;return(0,t.jsxs)("div",{role:"tab",tabIndex:g?0:-1,"aria-selected":g,onClick:()=>i(n.id),draggable:!!r,"data-dragging":o===n.id||void 0,"data-drop-target":d===n.id||void 0,onDragStart:e=>{r&&(c(n.id),e.dataTransfer.effectAllowed="move",e.dataTransfer.setData("text/plain",n.id))},onDragOver:e=>{r&&null!==o&&o!==n.id&&(e.preventDefault(),e.dataTransfer.dropEffect="move",u(n.id))},onDragLeave:()=>u(e=>e===n.id?null:e),onDrop:e=>{if(!r)return;e.preventDefault();let t=e.dataTransfer.getData("text/plain")||o;t&&t!==n.id&&r(t,n.id),p()},onDragEnd:p,onKeyDown:t=>{if("Enter"===t.key||" "===t.key){t.preventDefault(),i(n.id);return}if("ArrowLeft"!==t.key&&"ArrowRight"!==t.key)return;t.preventDefault();let a=(f+("ArrowRight"===t.key?1:-1)+e.length)%e.length;t.altKey&&r?r(n.id,e[a].id):(i(e[a].id),t.currentTarget.parentElement?.children[a]?.focus())},className:lp.default.tab,"data-active":g||void 0,children:[(0,t.jsx)("span",{className:lp.default.icon,children:"files"===n.icon?(0,t.jsx)(w,{size:13,"aria-hidden":"true"}):"report"===n.icon?(0,t.jsx)(es,{size:13,"aria-hidden":"true"}):"tools"===n.icon?(0,t.jsx)(ta,{size:13,"aria-hidden":"true"}):"graph"===n.icon?(0,t.jsx)(h,{size:13,"aria-hidden":"true"}):lR(n.filePath??n.label,13)}),(0,t.jsx)("span",{className:lp.default.label,title:n.filePath??n.label,children:n.label}),void 0!==n.badge&&n.badge>0||n.dot?(0,t.jsxs)(t.Fragment,{children:[void 0!==n.badge&&n.badge>0&&(0,t.jsx)("span",{className:lp.default.badge,"aria-hidden":"true",children:n.badge}),n.dot&&(0,t.jsx)("span",{className:lp.default.dot,"aria-hidden":"true"}),n.signalLabel&&(0,t.jsx)("span",{className:"sr-only",children:n.signalLabel})]}):null,x&&(0,t.jsx)("button",{type:"button",className:lp.default.close,onClick:e=>{e.stopPropagation(),s(n.id)},title:"Close","aria-label":l?l(n):`Close ${n.label}`,children:(0,t.jsx)(m,{size:10,"aria-hidden":"true"})})]},n.id)})})}function lA(){document.body.style.cursor="",document.body.style.userSelect=""}function l$({side:e,onResize:a,onResizeStart:i,onResizeEnd:s,ariaLabel:r,value:l,min:o,max:c}){let d=(0,n.useRef)(null),u=(0,n.useRef)(!1),p=(0,n.useRef)(0),[h,m]=(0,n.useState)(!1),f=(0,n.useCallback)(e=>{if(!u.current)return;u.current=!1,m(!1);let t=d.current;t&&void 0!==e&&t.hasPointerCapture(e)&&t.releasePointerCapture(e),lA(),s?.()},[s]),g=(0,n.useCallback)(e=>{0===e.button&&e.isPrimary&&(e.preventDefault(),u.current=!0,p.current=e.clientX,m(!0),i?.(),e.currentTarget.setPointerCapture(e.pointerId),document.body.style.cursor="col-resize",document.body.style.userSelect="none")},[i]),x=(0,n.useCallback)(e=>{if(!u.current)return;e.preventDefault();let t=e.clientX-p.current;p.current=e.clientX,a(t)},[a]),v=(0,n.useCallback)(e=>{e.preventDefault(),f(e.pointerId)},[f]),y=(0,n.useCallback)(e=>{f(e.pointerId)},[f]);(0,n.useEffect)(()=>()=>{u.current&&(u.current=!1,lA(),s?.())},[s]);let b=(0,n.useCallback)(e=>{if("ArrowLeft"!==e.key&&"ArrowRight"!==e.key)return;e.preventDefault();let t="ArrowRight"===e.key?16:-16;i?.(),a(t),s?.()},[a,s,i]);return(0,t.jsx)("div",{ref:d,role:"separator","aria-label":r??"Resize panel","aria-orientation":"vertical","aria-valuemin":o,"aria-valuemax":c,"aria-valuenow":l,tabIndex:0,className:`resize-handle${h?" resize-handle-dragging":""}`,"data-side":e,onPointerDown:g,onPointerMove:x,onPointerUp:v,onPointerCancel:y,onKeyDown:b,style:{alignSelf:"stretch",cursor:"col-resize",display:"flex",flexShrink:0,justifyContent:"center",marginLeft:-5,marginRight:-5,position:"relative",touchAction:"none",width:10,zIndex:"var(--layer-drag-overlay)"},children:(0,t.jsx)("div",{className:"resize-handle-line"})})}function lz(e){let t=(0,n.useCallback)(t=>{let n=window.matchMedia(e);return n.addEventListener("change",t),()=>n.removeEventListener("change",t)},[e]),a=(0,n.useCallback)(()=>window.matchMedia(e).matches,[e]);return(0,n.useSyncExternalStore)(t,a,()=>!1)}function lF(e,t){return Math.max(280,Math.min(1e3,e-t-440-5))}function lL(e,t){return Math.max(220,Math.min(Math.max(220,t-8-264),null!==e&&Number.isFinite(e)?e:280))}function lD(e,t){return t?"narrow":e>=520?"wide":e>=280?"medium":"narrow"}var lO=e.i(73574);function lq(e){let n=(0,f.useT)(),a=lz("(max-width: 960px)"),i=lD(e.width,a),s=lL(e.primaryWidth,e.width);if("narrow"===i)return(0,t.jsxs)("div",{className:lO.default.narrow,children:[e.narrowStrip,(0,t.jsx)("div",{className:lO.default.body,children:e.narrowBody})]});let r=null!==e.inspectorBody,l="medium"===i&&r,o=r&&!e.primaryHidden,c=r&&!l&&e.primaryHidden,d=l&&!e.navigatorOpen,u=l?{width:"min(300px, 78%)"}:c?{display:"none"}:o?{width:s}:{flex:"1 1 auto"},p=l?"medium":c?"fill":o?"wide":"single";return(0,t.jsxs)("div",{className:lO.default.lanes,"data-mode":p,"data-testid":"right-panel-lanes",children:[l&&e.navigatorOpen&&(0,t.jsx)("div",{className:lO.default.backdrop,onPointerDown:e.onToggleNavigator,"aria-hidden":"true"},"backdrop"),(0,t.jsxs)("div",{className:`${lO.default.primary}${l?` ${lO.default["primary-overlay"]}`:""}`,style:u,"data-open":l&&e.navigatorOpen||void 0,"data-parked":d||void 0,"data-testid":"right-panel-primary",inert:d,children:[e.channelStrip,(0,t.jsx)("div",{className:lO.default.body,children:e.channelBody})]},"primary"),o&&!l&&(0,t.jsx)(l$,{side:"right",ariaLabel:n("rightPanel.resizeNavigator"),value:s,min:220,max:Math.max(220,e.width-8-264),onResize:e.onResizePrimary,onResizeStart:e.onResizePrimaryStart,onResizeEnd:e.onResizePrimaryEnd},"divider"),r&&(0,t.jsxs)("div",{className:lO.default.inspector,children:[(0,t.jsxs)("div",{className:lO.default.strip,children:[e.inspectorStrip,(0,t.jsx)("button",{type:"button",className:lO.default["nav-toggle"],"aria-label":n(e.navigatorOpen?"rightPanel.hideNavigator":"rightPanel.showNavigator"),"aria-expanded":e.navigatorOpen,"data-open":e.navigatorOpen||void 0,onClick:e.onToggleNavigator,children:(0,t.jsx)(g,{size:15,"aria-hidden":"true"})})]}),(0,t.jsx)("div",{className:lO.default.body,children:e.inspectorBody})]},"inspector")]})}let lB={files:"rightPanel.files",graph:"rightPanel.graphs",tools:"rightPanel.status"},lU={files:"files",graph:"graph",tools:"tools"};function lH(e,t,n={}){return e.map(e=>({id:e,label:t(lB[e]),closable:!0,icon:lU[e],badge:n[e]?.count,dot:n[e]?.attention,signalLabel:n[e]?.count!==void 0?t("rightPanel.runsCount",{count:n[e]?.count??0}):n[e]?.attention?t("rightPanel.needsAttention"):void 0}))}let lW={files:o("files",[["path",{d:"M15 2h-4a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 2-2V8",key:"14sh0y"}],["path",{d:"M16.706 2.706A2.4 2.4 0 0 0 15 2v5a1 1 0 0 0 1 1h5a2.4 2.4 0 0 0-.706-1.706z",key:"1970lx"}],["path",{d:"M5 7a2 2 0 0 0-2 2v11a2 2 0 0 0 2 2h8a2 2 0 0 0 1.732-1",key:"l4dndm"}]]),graph:h,tools:ta};function lV(e){return(0,t.jsxs)("div",{className:"right-panel-launcher",role:"group","aria-label":e.hint,children:[(0,t.jsx)("p",{className:"right-panel-launcher-hint",children:e.hint}),e.channels.map(n=>{let a=lW[n];return(0,t.jsxs)("button",{type:"button",className:"right-panel-launcher-card",onClick:()=>e.onOpen(n),children:[(0,t.jsx)(a,{size:15,"aria-hidden":"true"}),(0,t.jsx)("span",{children:(0,e.t)(lB[n])})]},n)})]})}let lK=o("file-plus",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M9 15h6",key:"cctwl0"}],["path",{d:"M12 18v-6",key:"17g6i2"}]]),lG=o("maximize-2",[["path",{d:"M15 3h6v6",key:"1q9fwt"}],["path",{d:"m21 3-7 7",key:"1l2asr"}],["path",{d:"m3 21 7-7",key:"tjx5ai"}],["path",{d:"M9 21H3v-6",key:"wtvkvv"}]]);function lJ(e){var n;let{entry:a,depth:i,expanded:s,loading:r,errorText:l,tabbable:o,selected:c}=e;return(0,t.jsxs)("div",{className:"file-tree-row",style:{paddingLeft:8+16*i},role:"treeitem","aria-level":i+1,"aria-expanded":a.isDir?s:void 0,"aria-selected":c||void 0,tabIndex:o?0:-1,"data-path":a.path,onClick:e.onClick,onContextMenu:e.onContextMenu,onKeyDown:e.onKeyDown,children:[(0,t.jsxs)("span",{className:"file-tree-main",title:a.path,children:[(0,t.jsx)("span",{className:"file-tree-icon",children:a.isDir?(0,t.jsx)(lm,{size:14,open:s}):lR(a.name,14)}),(0,t.jsx)("span",{className:"file-tree-name",children:a.name}),!a.isDir&&(0,t.jsx)("span",{className:"file-tree-size",children:(n=a.size)<1024?`${n} B`:n<1048576?`${(n/1024).toFixed(1)} K`:`${(n/1048576).toFixed(1)} M`}),r&&(0,t.jsx)("span",{className:"file-tree-loading",children:"..."}),l&&(0,t.jsx)("span",{className:"file-tree-error-mark",title:l,"aria-label":`Could not list ${a.name}: ${l}`,children:"!"})]}),!a.isDir&&(0,t.jsx)("button",{type:"button",className:"file-preview-action",onClick:t=>{t.stopPropagation(),e.onPreview()},"aria-label":`Preview ${a.name} in a floating window`,title:"Open floating preview",onKeyDown:e=>{("Enter"===e.key||" "===e.key)&&e.stopPropagation()},children:(0,t.jsx)(lG,{size:12,"aria-hidden":"true"})})]})}function lY(e){let a=(0,n.useRef)(null);return(0,n.useEffect)(()=>{let e=window.requestAnimationFrame(()=>{let e=a.current;e&&(e.focus(),e.select())});return()=>window.cancelAnimationFrame(e)},[]),(0,t.jsx)("div",{className:"file-tree-row file-tree-row-editing",style:{paddingLeft:8+16*e.depth},children:(0,t.jsxs)("span",{className:"file-tree-main",children:[(0,t.jsx)("span",{className:"file-tree-icon","aria-hidden":"true"}),(0,t.jsx)("input",{ref:a,className:"file-tree-editor","aria-label":e.label,defaultValue:e.initialValue,onKeyDown:t=>{"Enter"===t.key?(t.preventDefault(),e.onCommit(t.currentTarget.value)):"Escape"===t.key&&(t.preventDefault(),e.onCancel())},onBlur:()=>e.onCancel()})]})})}function lQ(e){let{entry:a,at:i,onClose:s}=e,r=(0,n.useRef)(null),l=a?.path??null;if((0,n.useEffect)(()=>{if(null===l)return;let e=window.requestAnimationFrame(()=>{r.current?.querySelector('[role="menuitem"]')?.focus()});return()=>window.cancelAnimationFrame(e)},[l]),!a)return null;let o=async()=>{try{await navigator.clipboard.writeText(a.path)}catch{e.onError("The clipboard is unavailable in this window.")}s()},c=e=>()=>{e(),s()};return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"file-tree-menu-backdrop",onPointerDown:s,"aria-hidden":"true"}),(0,t.jsxs)("div",{ref:r,className:"file-tree-menu",role:"menu","aria-label":`Actions for ${a.name}`,style:{left:i.x,top:i.y},onKeyDown:e=>{let t=Array.from(r.current?.querySelectorAll('[role="menuitem"]')??[]),n=t.indexOf(document.activeElement);if("Escape"===e.key){e.preventDefault(),s();return}if("ArrowDown"!==e.key&&"ArrowUp"!==e.key)return;e.preventDefault();let a="ArrowDown"===e.key?1:-1;t[(n+a+t.length)%t.length]?.focus()},children:[!a.isDir&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onOpen),children:"Open"}),e.onOpenToSide&&(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onOpenToSide),children:"Open to the side"}),(0,t.jsx)("button",{type:"button",role:"menuitem",onClick:c(e.onPreview),children:"Open in floating window"})]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onNewFile),children:[(0,t.jsx)(lK,{size:12,"aria-hidden":"true"})," New file"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onNewFolder),children:[(0,t.jsx)(d,{size:12,"aria-hidden":"true"})," New folder"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onRename),children:[(0,t.jsx)(C,{size:12,"aria-hidden":"true"})," Rename"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:c(e.onDelete),children:[(0,t.jsx)(P,{size:12,"aria-hidden":"true"})," Delete"]}),(0,t.jsxs)("button",{type:"button",role:"menuitem",onClick:()=>void o(),children:[(0,t.jsx)(Q,{size:12,"aria-hidden":"true"})," Copy path"]})]})]})}function lZ({projectId:e,displayPath:a,onOpenFile:i,onOpenFileToSide:s,canOpenToSide:r=!1,onPreviewFile:l}){let[o,c]=(0,n.useState)([]),[p,h]=(0,n.useState)(!!e),[m,f]=(0,n.useState)(null),[g,x]=(0,n.useState)(new Map),[v,y]=(0,n.useState)(""),[b,k]=(0,n.useState)(new Set),[j,w]=(0,n.useState)(new Set),[N,_]=(0,n.useState)(new Map),[C,S]=(0,n.useState)(null),[I,P]=(0,n.useState)(null),T=(0,n.useRef)(new Map),M=(0,n.useRef)(36),R=(0,n.useRef)(null);(0,n.useEffect)(()=>{if(!e)return;let t=new AbortController,n=T.current;return lt(e,"/workspace",t.signal).then(e=>{c(e??[]),f(null)}).catch(e=>{t.signal.aborted||f(e.message)}).finally(()=>{t.signal.aborted||h(!1)}),()=>{t.abort(),n.forEach(e=>e.abort()),n.clear()}},[e]);let E=(0,n.useCallback)(async t=>{if(!e||N.has(t)||T.current.has(t))return;let n=new AbortController;T.current.set(t,n),w(e=>new Set(e).add(t));try{let a=await lt(e,t,n.signal);_(e=>new Map(e).set(t,a)),x(e=>{if(!e.has(t))return e;let n=new Map(e);return n.delete(t),n})}catch(e){n.signal.aborted||(x(n=>new Map(n).set(t,e.message)),k(e=>{if(!e.has(t))return e;let n=new Set(e);return n.delete(t),n}))}finally{T.current.get(t)===n&&T.current.delete(t),w(e=>{let n=new Set(e);return n.delete(t),n})}},[N,e]),A=(0,n.useCallback)(e=>{k(t=>{if(!t.has(e))return t;let n=new Set(t);return n.delete(e),n})},[]),$=(0,n.useCallback)(e=>{k(t=>t.has(e)?t:new Set(t).add(e)),E(e)},[E]),z=v.trim().toLowerCase(),F=(0,n.useMemo)(()=>{let e=[],t=new Map,n=e=>{if(!z)return!0;let a=t.get(e.path);if(void 0!==a)return a;let i=e.name.toLowerCase().includes(z)||e.isDir&&(N.get(e.path)??[]).some(n);return t.set(e.path,i),i},a=(t,i,s)=>{for(let r of t){if(!n(r))continue;e.push({entry:r,depth:i,parentPath:s});let t=r.isDir&&!g.has(r.path)&&(!!z||b.has(r.path));if(!r.isDir||!t)continue;let l=N.get(r.path);l&&a(l,i+1,r.path)}};return a(o,0,null),e},[o,N,b,g,z]);(0,n.useEffect)(()=>{if(!z){M.current=36;return}let e=window.setTimeout(()=>{let e=new Set;for(let t of o)t.isDir&&e.add(t.path);for(let t of N.values())for(let n of t)n.isDir&&e.add(n.path);let t=0;for(let n of e){if(t>=12||M.current<=0)break;N.has(n)||g.has(n)||T.current.has(n)||(E(n),M.current-=1,t+=1)}},250);return()=>window.clearTimeout(e)},[z,o,N,g,E]);let L=(0,n.useCallback)(async t=>{if(e)try{let n=await lt(e,t);"/workspace"===t?c(n??[]):_(e=>new Map(e).set(t,n??[])),f(null)}catch(e){f(e.message)}},[e]),D=(0,n.useCallback)(e=>{_(t=>{let n=new Map(t);for(let t of[...n.keys()])(t===e||t.startsWith(`${e}/`))&&n.delete(t);return n}),k(t=>{let n=new Set([...t].filter(t=>t!==e&&!t.startsWith(`${e}/`)));return n.size===t.size?t:n})},[]),{pending:O,setPending:q,beginCreate:B,beginRename:U,createDepth:H,submitCreate:W,submitRename:V,requestDelete:K}=function(e){let{projectId:t,rows:a,focusedPath:i,menuPath:s,expand:r,focusRow:l,refreshDir:o,forgetDir:c,setError:d}=e,[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(!1),f=(0,n.useRef)(!1),g=e=>e.includes("/")||"."===e||".."===e?"A name cannot contain a slash or be . or ..":null,x=(e,t)=>`${"/workspace"===e?"/workspace":e}/${t}`,v=(0,n.useCallback)(()=>{let e=a.find(e=>e.entry.path===i);return e?.entry.isDir?e.entry.path:e?la(e.entry.path).parent:"/workspace"},[a,i]),y=(0,n.useCallback)(e=>{let t=v();p({kind:"create",parent:t,entryKind:e}),"/workspace"!==t&&r(t)},[v,r]),b=(0,n.useCallback)(()=>{let e=a.find(e=>e.entry.path===i);e&&p({kind:"rename",path:e.entry.path})},[a,i]),k=(0,n.useCallback)(()=>{if(!u||"create"!==u.kind)return 0;let e=a.find(e=>e.entry.path===u.parent);return e?e.depth+1:0},[u,a]),j=(0,n.useCallback)(async e=>{if(!u||"create"!==u.kind||!t)return;let n=e.trim();if(""===n)return void p(null);let a=g(n);if(a)return void d(a);let i=x(u.parent,n);if(!f.current){f.current=!0,m(!0);try{await li(t,{path:i,kind:u.entryKind,content:""}),p(null),await o(u.parent),window.requestAnimationFrame(()=>l(i))}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[u,t,o,l,d]),w=(0,n.useCallback)(async(e,n)=>{if(!t)return;let a=n.trim();if(""===a||a===e.name)return void p(null);let i=g(a);if(i)return void d(i);let s=la(e.path).parent,r=x(s,a);if(!f.current){f.current=!0,m(!0);try{await ls(t,{from:e.path,to:r}),p(null),c(e.path),await o(s),window.requestAnimationFrame(()=>l(r))}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[t,o,c,l,d]),N=(0,n.useCallback)(async()=>{if(!t)return;let e=a.find(e=>e.entry.path===s);if(!e)return;let{entry:n}=e;if(await rx({title:`Delete ${n.name}?`,description:n.isDir?"The directory and everything inside it is deleted. There is no trash.":"The file is deleted. There is no trash.",confirmLabel:"Delete",tone:"danger"})&&!f.current){f.current=!0,m(!0);try{await lr(t,n.path,{recursive:n.isDir}),c(n.path),await o(la(n.path).parent)}catch(e){d(e.message)}finally{f.current=!1,m(!1)}}},[t,a,s,o,c,d]);return{pending:u,setPending:p,busy:h,beginCreate:y,beginRename:b,createDepth:k,submitCreate:j,submitRename:w,requestDelete:N}}({projectId:e,rows:F,focusedPath:C,menuPath:I?.path??null,expand:$,focusRow:e=>G(e),refreshDir:L,forgetDir:D,setError:f}),G=(0,n.useCallback)(e=>{S(e);let t=R.current;if(!t)return;let n=t.querySelector(`[data-path="${CSS.escape(e)}"]`);n?.focus()},[]),J=(0,n.useCallback)((e,t)=>{let n=F[e+t];n&&G(n.entry.path)},[F,G]),Y=(0,n.useCallback)((e,t)=>{if(e.target!==e.currentTarget&&("Enter"===e.key||" "===e.key))return;let n=F[t];if(n)switch(e.key){case"ArrowDown":e.preventDefault(),J(t,1);break;case"ArrowUp":e.preventDefault(),J(t,-1);break;case"Home":e.preventDefault(),F[0]&&G(F[0].entry.path);break;case"End":e.preventDefault(),F.length>0&&G(F[F.length-1].entry.path);break;case"ArrowRight":if(e.preventDefault(),!n.entry.isDir||z)break;if(!b.has(n.entry.path)){$(n.entry.path);break}if(!N.has(n.entry.path))break;J(t,1);break;case"ArrowLeft":{if(e.preventDefault(),!z&&n.entry.isDir&&b.has(n.entry.path)){A(n.entry.path);break}let t=F.findIndex(e=>e.entry.path===n.parentPath);t>=0&&G(F[t].entry.path);break}case"Enter":case" ":if(e.preventDefault(),n.entry.isDir){if(z)break;b.has(n.entry.path)?A(n.entry.path):$(n.entry.path)}else i(n.entry.path,n.entry.name);break;case"ContextMenu":let a;e.preventDefault(),P({path:n.entry.path,...{x:(a=e.currentTarget.getBoundingClientRect()).left+12,y:a.bottom}})}},[F,b,N,z,A,$,J,G,i]),Q=null===C?-1:F.findIndex(e=>e.entry.path===C),Z=null!==C&&-1===Q;(0,n.useEffect)(()=>{if(!Z)return;let e=window.setTimeout(()=>{let e=R.current?.contains(document.activeElement)??!1,t=F[0]?.entry.path;S(t??null),e&&t&&G(t)},0);return()=>window.clearTimeout(e)},[Z,F,G]);let X=Q>=0?Q:0;return(0,t.jsxs)("div",{className:"file-tree-panel",children:[(0,t.jsxs)("div",{className:"file-tree-header",children:[(0,t.jsx)("div",{className:"file-tree-heading",children:"Files"}),(0,t.jsx)("div",{className:"file-tree-path",title:a??"/workspace",children:e?a??"/workspace":"No project selected"}),(0,t.jsxs)("div",{className:"file-tree-actions",children:[(0,t.jsx)("button",{type:"button",className:"file-tree-action","aria-label":"New file",title:"New file",disabled:!e,onClick:()=>B("file"),children:(0,t.jsx)(lK,{size:13,"aria-hidden":"true"})}),(0,t.jsx)("button",{type:"button",className:"file-tree-action","aria-label":"New folder",title:"New folder",disabled:!e,onClick:()=>B("directory"),children:(0,t.jsx)(d,{size:13,"aria-hidden":"true"})})]}),(0,t.jsxs)("label",{className:"file-filter",children:[(0,t.jsx)(u,{size:12,"aria-hidden":"true"}),(0,t.jsx)("span",{className:"sr-only",children:"Filter files"}),(0,t.jsx)("input",{value:v,onChange:e=>y(e.target.value),onKeyDown:e=>{"ArrowDown"===e.key&&0!==F.length&&(e.preventDefault(),G(F[0].entry.path))},placeholder:"Filter files...",disabled:!e})]})]}),(0,t.jsx)("div",{className:"file-tree-list",ref:R,onScroll:()=>P(null),children:e?p?(0,t.jsx)("div",{className:"file-tree-state",children:"Loading..."}):m&&0===o.length?(0,t.jsx)("div",{className:"file-tree-state is-error",children:m}):0===F.length?(0,t.jsxs)(t.Fragment,{children:[m&&(0,t.jsx)("p",{className:"file-tree-inline-error",role:"alert",children:m}),(0,t.jsx)("div",{className:"file-tree-state",children:z?"No files match.":"No files found."})]}):(0,t.jsxs)(t.Fragment,{children:[m&&(0,t.jsx)("p",{className:"file-tree-inline-error",role:"alert",children:m}),(0,t.jsxs)("div",{role:"tree","aria-label":"Workspace files",children:[F.map((e,n)=>{let{entry:a,depth:s}=e,r=z?(N.get(a.path)?.length??0)>0:b.has(a.path);return O&&"rename"===O.kind&&O.path===a.path?(0,t.jsx)(lY,{depth:s,label:`Rename ${a.name}`,initialValue:a.name,onCommit:e=>void V(a,e),onCancel:()=>q(null)},"editor"):(0,t.jsx)(lJ,{entry:a,depth:s,expanded:r,loading:j.has(a.path),errorText:g.get(a.path),tabbable:n===X,selected:C===a.path,onClick:()=>{(S(a.path),a.isDir)?z||(r?A(a.path):$(a.path)):i(a.path,a.name)},onContextMenu:e=>{e.preventDefault(),G(a.path),P({path:a.path,x:e.clientX,y:e.clientY})},onKeyDown:e=>Y(e,n),onPreview:()=>l(a.path,a.name)},a.path)}),O&&"create"===O.kind&&(0,t.jsx)(lY,{depth:H(),label:"directory"===O.entryKind?"New folder name":"New file name",initialValue:"",onCommit:e=>void W(e),onCancel:()=>q(null)},"creator")]})]}):(0,t.jsx)("div",{className:"file-tree-empty",children:"Select a project to browse files."})}),I&&(0,t.jsx)(lQ,{entry:F.find(e=>e.entry.path===I.path)?.entry,at:I,onClose:()=>{let e=I.path;P(null),G(e)},onOpen:()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&i(e.path,e.name)},onOpenToSide:r?()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&s(e.path,e.name)}:void 0,onPreview:()=>{let e=F.find(e=>e.entry.path===I.path)?.entry;e&&!e.isDir&&l(e.path,e.name)},onNewFile:()=>B("file"),onNewFolder:()=>B("directory"),onRename:()=>U(),onDelete:()=>void K(),onError:e=>f(e)})]})}function lX(e){return(0,t.jsx)(lZ,{projectId:e.projectId,displayPath:e.displayPath,onOpenFile:e.onOpenFile,onOpenFileToSide:e.onOpenFileToSide,canOpenToSide:e.canOpenToSide,onPreviewFile:e.onPreviewFile},e.projectId??"no-project")}var l0=e.i(57840);function l1(e,t,n){if(!n)return"";let a=`${t}.${n}`,i=e(a);return i===a?n:i}function l2({sessionId:e,onCount:a}){let i=(0,f.useT)(),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)({}),[c,d]=(0,n.useState)(null),[u,p]=(0,n.useState)(null),m=(0,n.useRef)(null),g=(0,n.useRef)(a);(0,n.useEffect)(()=>{g.current=a},[a]);let x=(0,n.useCallback)(async()=>{if(e)try{let t=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/graph-runs`)??[];r(t),g.current?.(t.length),p(null),d(e=>(function(e,t,n){if(0===t.length)return null;let a=t[0].runId??null;if(null===a)return null;if(null===e||!t.some(t=>t.runId===e))return a===n?null:a;let i=t[0].createdAt,s=t.find(t=>t.runId===e)?.createdAt;return i&&s&&s<i?a===n?null:a:e})(e,t,m.current))}catch(e){p(e.message)}},[e]);(0,n.useEffect)(()=>{let e,t=new AbortController,n=!1,a=async()=>{await x(),n||(e=window.setTimeout(a,1500))};return a(),()=>{n=!0,t.abort(),void 0!==e&&window.clearTimeout(e)}},[x]),(0,n.useEffect)(()=>{if(!e||!c)return;let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/graph-runs/${encodeURIComponent(c)}`).then(e=>{t||o(t=>({...t,[c]:e.nodes??[]}))}).catch(()=>{t||p("graph.loadFailed")}),()=>{t=!0}},[c,e]);let v=(0,n.useMemo)(()=>s.filter(e=>"running"===e.state).length,[s]);return(0,t.jsxs)("div",{className:l0.default.root,children:[(0,t.jsxs)("div",{className:l0.default.header,children:[(0,t.jsxs)("span",{className:l0.default.title,children:[(0,t.jsx)(h,{size:13,"aria-hidden":"true"}),i("graph.title")]}),v>0&&(0,t.jsx)("span",{className:l0.default.running,children:i("graph.running",{count:String(v)})})]}),u&&(0,t.jsx)("div",{className:l0.default.error,children:"graph.loadFailed"===u?i(u):u}),(0,t.jsx)("div",{className:l0.default.scroll,children:e?0===s.length?(0,t.jsx)("div",{className:l0.default.empty,children:i("graph.emptyRuns")}):s.map(e=>(0,t.jsx)(l4,{run:e,nodes:l[e.runId??""]??[],expanded:c===e.runId,onToggle:()=>d(t=>t===e.runId?(m.current=e.runId??null,null):(m.current=null,e.runId??null)),nodesLoading:c===e.runId&&void 0===l[e.runId??""],t:i},e.runId)):(0,t.jsx)("div",{className:l0.default.empty,children:i("graph.emptySession")})})]})}function l4({run:e,nodes:n,expanded:a,onToggle:i,nodesLoading:s,t:r}){let l=e.state,o=n.length,c=n.filter(e=>"completed"===e.terminalState).length,d=l1(r,"graph.flow",l);return(0,t.jsxs)("div",{className:l0.default.card,children:[(0,t.jsxs)("button",{type:"button",onClick:i,className:l0.default.cardButton,"data-expanded":a||void 0,"aria-expanded":a,children:[(0,t.jsx)(j,{size:11,className:l0.default.chevron,"data-expanded":a||void 0,"aria-hidden":"true"}),(0,t.jsx)("span",{className:`${l0.default.stateDot} ${l0.default.flowDot}`,"data-flow-state":l}),(0,t.jsx)("span",{className:l0.default.cardTitle,children:e.inputs?.name?String(e.inputs.name):r("graph.unnamed")}),(0,t.jsx)("span",{className:l0.default.cardSummary,children:o>0?r("graph.tasks",{done:String(c),total:String(o)}):d})]}),a&&(0,t.jsxs)("div",{className:l0.default.details,children:[(0,t.jsxs)("div",{className:l0.default.meta,children:[(0,t.jsx)("span",{children:r("graph.stateLabel",{state:d})}),e.totalTokensUsed?(0,t.jsx)("span",{children:r("graph.tokens",{count:String(e.totalTokensUsed)})}):null,e.createdAt?(0,t.jsx)("span",{children:function(e,t){let n=new Date(e);if(Number.isNaN(n.getTime()))return e;let a=Math.floor((new Date().getTime()-n.getTime())/6e4);return a<1?t("graph.justNow"):a<60?t("graph.minutesAgo",{count:String(a)}):n.toLocaleTimeString([],{hour:"2-digit",minute:"2-digit"})}(e.createdAt,r)}):null]}),s?(0,t.jsx)("div",{className:l0.default.stateLine,children:r("graph.loadingTasks")}):0===n.length?(0,t.jsx)("div",{className:l0.default.stateLine,children:r("graph.noTasks")}):(0,t.jsx)("ul",{className:l0.default.nodeList,children:n.map(e=>(0,t.jsxs)("li",{className:l0.default.nodeRow,children:[(0,t.jsx)("span",{className:l0.default.nodeDot,"data-node-state":e.terminalState}),(0,t.jsx)("span",{className:l0.default.nodeName,children:e.handle}),(0,t.jsx)("span",{className:l0.default.nodeState,children:l1(r,"graph.node",e.terminalState)})]},e.taskIndex??e.handle))})]})]})}function l5({sessionId:e,onCount:n}){return(0,t.jsx)(l2,{sessionId:e,onCount:n})}let l3=o("file-clock",[["path",{d:"M16 22h2a2 2 0 0 0 2-2V8a2.4 2.4 0 0 0-.706-1.706l-3.588-3.588A2.4 2.4 0 0 0 14 2H6a2 2 0 0 0-2 2v2.85",key:"ryk6xj"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M8 14v2.2l1.6 1",key:"6m4bie"}],["circle",{cx:"8",cy:"16",r:"6",key:"10v15b"}]]);function l6(e,t=""){return"string"==typeof e?e:t}function l8(e){let t=[];for(let n of e??[]){let e=n??{};switch(e.type){case"text":t.push({kind:"text",text:l6(e.text)});break;case"thinking":t.push({kind:"thinking",text:l6(e.text)});break;case"tool_call":{let n=e.toolCall??{},a=function(e){if(null!=e){if("object"!=typeof e)return String(e);try{return JSON.stringify(e,null,2)}catch{return}}}(n.arguments);t.push({kind:"tool_call",callId:l6(n.id),name:l6(n.name,"tool")||"tool",...void 0===a?{}:{arguments:a}});break}case"tool_result":{let n=e.toolResult??{};t.push({kind:"tool_result",callId:l6(n.toolCallId),name:l6(n.toolName,"tool")||"tool",text:l6(n.content),isError:!0===n.isError});break}case"image":{let n=e.image??{};t.push({kind:"image",width:"number"==typeof n.width?n.width:0,height:"number"==typeof n.height?n.height:0});break}case"image_description":{let n=e.imageDescription??{};t.push({kind:"text",text:l6(n.text)});break}default:t.push({kind:"unknown",type:l6(e.type,"unknown")||"unknown"})}}return t}var l9=e.i(26694);let l7={base:"Platform",hero:"Hero",context:"Project context",skills_catalog:"Skill catalog",skill_preload:"Preloaded skill"},oe={system:"System",user:"User",assistant:"Assistant",tool:"Tool"};function ot({runId:e,composition:a,mcp:i,transcript:s,loading:r,error:l,t:o}){let[c,d]=(0,n.useState)(!1);if(!e)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.noRun")});if(r&&!a)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.loading")});if(l)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:l});if(!a)return(0,t.jsx)("div",{className:`${l9.default.empty} ${l9.default.muted}`,children:o("inspector.loading")});let u=a.sections??[],p=a.recorded,h=u.filter(e=>"skill_preload"===e.kind&&"user-skill-select"===e.source).map(e=>e.skillId||e.id.replace(/^skill\.preload\./,""));return(0,t.jsxs)("div",{className:l9.default.body,children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.run")}),(0,t.jsx)("div",{className:`${l9.default.digest} ${l9.default.digestValue} ${l9.default.runId}`,title:e,children:e}),(0,t.jsx)("div",{className:l9.default.muted,children:p?o("inspector.frozen"):o("inspector.unrecorded")})]}),p&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:l9.default.heading,children:[o("inspector.composition"),(0,t.jsx)("span",{className:l9.default.headingCount,children:o("inspector.sections",{count:String(u.length)})})]}),h.length>0&&(0,t.jsxs)("div",{className:l9.default.selectedSkills,children:[(0,t.jsx)("span",{className:l9.default.muted,children:o("inspector.selectedSkills")}),h.map(e=>(0,t.jsx)("code",{children:`/${e}`},e))]}),(0,t.jsx)("div",{className:l9.default.group,children:u.map(e=>(0,t.jsx)(on,{section:e},e.id))})]}),(0,t.jsxs)("div",{className:l9.default.digestGroup,children:[(0,t.jsx)(or,{label:o("inspector.sectionsDigest"),value:a.sectionsDigest}),(0,t.jsx)(or,{label:o("inspector.composedDigest"),value:a.composedDigest}),(0,t.jsx)(or,{label:o("inspector.baseDigest"),value:a.digest}),""!==a.skillCatalogState&&(0,t.jsxs)("div",{className:l9.default.catalogRow,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.catalogLabel}`,children:o("inspector.skillCatalog")}),(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.catalogValue}`,children:o(`inspector.catalog.${a.skillCatalogState}`)}),""!==a.skillCatalogDigest&&(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.digestValue}`,title:a.skillCatalogDigest,children:rE(a.skillCatalogDigest,8)})]})]}),p&&void 0!==i&&(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.mcp")}),null===i||0===(i.servers??[]).length?(0,t.jsx)("div",{className:l9.default.muted,children:o("inspector.mcpNone")}):(0,t.jsx)("div",{className:l9.default.group,children:(i.servers??[]).map(e=>(0,t.jsx)(oa,{server:e,t:o},e.id))})]}),s?(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:l9.default.heading,children:o("inspector.transcript")}),(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.transcriptNote}`,children:o("inspector.transcriptNote")}),0===s.messages.length?(0,t.jsx)("div",{className:l9.default.muted,children:o("inspector.transcriptEmpty")}):(0,t.jsx)("div",{className:l9.default.group,children:s.messages.map(e=>(0,t.jsx)(oi,{message:e,t:o},e.id))}),s.hasMore&&(0,t.jsx)("button",{type:"button",className:l9.default.loadOlder,disabled:s.loadingOlder,onClick:s.loadOlder,children:o("inspector.transcriptOlder")})]}):null,p&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("button",{type:"button",className:l9.default.promptToggle,onClick:()=>d(e=>!e),"aria-expanded":c,children:[c?(0,t.jsx)(q,{size:13,"aria-hidden":"true"}):(0,t.jsx)(j,{size:13,"aria-hidden":"true"}),(0,t.jsx)(l3,{size:13,"aria-hidden":"true"}),o("inspector.prompt"),(0,t.jsx)("span",{className:l9.default.promptBytes,children:rA(a.prompt.length)})]}),c&&(0,t.jsx)("pre",{"data-run-prompt":!0,className:l9.default.promptPre,children:a.prompt})]})]})}function on({section:e}){return(0,t.jsxs)("div",{"data-prompt-section":e.kind,className:l9.default.sectionRow,children:[(0,t.jsx)("span",{className:l9.default.sectionKind,children:l7[e.kind]??e.kind}),(0,t.jsxs)("span",{className:l9.default.sectionIdentity,children:[(0,t.jsx)("span",{className:l9.default.sectionId,children:e.id}),(0,t.jsx)("span",{className:l9.default.sectionSource,children:` \xb7 ${e.source}`})]}),(0,t.jsx)("span",{className:l9.default.sectionBytes,children:rA(e.bytes)}),(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.sectionDigest}`,title:e.digest,children:rE(e.digest,8)})]})}function oa({server:e,t:n}){let a=""!==e.unavailableReason;return(0,t.jsxs)("div",{"data-mcp-server":e.bindingId,"data-unavailable":a||void 0,className:l9.default.mcpRow,children:[(0,t.jsxs)("div",{className:l9.default.mcpHead,children:[(0,t.jsxs)("span",{className:l9.default.mcpIdentity,children:[(0,t.jsx)("span",{className:l9.default.mcpBinding,children:e.bindingId}),(0,t.jsx)("span",{className:l9.default.mcpRevision,children:` \xb7 rev ${e.bindingRevision}`})]}),e.required&&(0,t.jsx)("span",{className:l9.default.badge,children:n("inspector.mcpRequired")}),(0,t.jsx)("span",{className:l9.default.mcpTools,children:n("inspector.mcpTools",{count:String((e.tools??[]).length)})})]}),a&&(0,t.jsx)("div",{className:l9.default.mcpUnavailable,children:`${n("inspector.mcpUnavailable")}: ${e.unavailableReason}`}),""!==e.negotiatedProtocol&&(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.mcpProtocol}`,children:`${n("inspector.mcpProtocol")}: ${e.negotiatedProtocol}`}),""!==e.instructions&&(0,t.jsxs)("details",{className:l9.default.mcpInstructions,children:[(0,t.jsx)("summary",{className:l9.default.muted,title:e.instructionsDigest,children:n("inspector.mcpInstructions")}),(0,t.jsx)("div",{className:l9.default.mcpInstructionsBody,"data-mcp-instructions":!0,children:e.instructions})]}),(e.tools??[]).length>0&&(0,t.jsx)("div",{className:l9.default.toolList,children:(e.tools??[]).map(e=>(0,t.jsxs)("div",{className:l9.default.toolRow,children:[(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.toolName}`,title:e.exposedName,children:e.exposedName}),(0,t.jsx)("span",{className:l9.default.toolRisk,children:e.riskClass})]},e.exposedName))})]})}function oi({message:e,t:n}){let a=l8(e.content),i=function(e){let t=new Set,n=[];for(let a of l8(e))"tool_call"!==a.kind||t.has(a.name)||(t.add(a.name),n.push(a.name));return n.join(", ")}(e.content);return(0,t.jsxs)("details",{"data-transcript-ordinal":e.ordinal,className:l9.default.transcriptRow,children:[(0,t.jsxs)("summary",{className:l9.default.transcriptSummary,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.transcriptOrdinal}`,children:e.ordinal}),(0,t.jsx)("span",{className:l9.default.transcriptRole,children:oe[e.role]??e.role}),"private"===e.visibility&&(0,t.jsx)("span",{"data-transcript-private":!0,className:l9.default.privateBadge,children:n("inspector.transcriptPrivate")}),(0,t.jsx)("span",{className:l9.default.transcriptExcerpt,children:i})]}),(0,t.jsx)("div",{className:l9.default.transcriptBody,children:a.map((e,a)=>(0,t.jsx)(os,{entry:e,t:n},a))})]})}function os({entry:e,t:n}){return"text"===e.kind?(0,t.jsx)("div",{className:l9.default.entryPre,children:e.text}):"thinking"===e.kind?(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:`${l9.default.muted} ${l9.default.entryLabel}`,children:n("inspector.transcriptThinking")}),(0,t.jsx)("div",{className:l9.default.entryPre,children:e.text})]}):"image"===e.kind?(0,t.jsx)("div",{className:l9.default.muted,children:n("inspector.transcriptImage",{width:String(e.width),height:String(e.height)})}):"unknown"===e.kind?(0,t.jsx)("div",{className:l9.default.muted,children:n("inspector.transcriptUnknown",{type:e.type})}):"tool_call"===e.kind?(0,t.jsxs)("details",{children:[(0,t.jsx)("summary",{className:`${l9.default.muted} ${l9.default.entrySummary}`,children:`${n("inspector.transcriptCall")} ${e.name}`}),void 0!==e.arguments&&(0,t.jsx)("div",{className:`${l9.default.entryPre} ${l9.default.entryBlock}`,children:e.arguments})]}):(0,t.jsxs)("details",{children:[(0,t.jsx)("summary",{className:`${l9.default.muted} ${l9.default.entrySummary}`,"data-error":e.isError||void 0,children:`${n(e.isError?"inspector.transcriptError":"inspector.transcriptResult")} ${e.name}`}),(0,t.jsx)("div",{className:`${l9.default.entryPre} ${l9.default.entryBlock}`,children:e.text})]})}function or({label:e,value:n}){return n?(0,t.jsxs)("div",{className:l9.default.digestLine,children:[(0,t.jsx)("span",{className:`${l9.default.muted} ${l9.default.digestLabel}`,children:e}),(0,t.jsx)("span",{className:`${l9.default.digest} ${l9.default.digestValue}`,title:n,children:n})]}):null}function ol({runId:e,composition:n,mcp:a,transcript:i,loading:s,error:r}){let l=(0,f.useT)();return(0,t.jsx)(ot,{runId:e,composition:n,mcp:a,transcript:i,loading:s,error:r,t:l})}function oo(e){let{runId:a,selectedSession:i,sessionTitle:s,activeRun:r,status:l,permissionMode:o}=e,c=function(e){let[t,a]=(0,n.useState)(null),[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a(null),l(null),s(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{s(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/prompt`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e),l(null))}).catch(e=>{t.signal.aborted||(a(null),l(e instanceof Error?e.message:"Failed to load the run prompt"))}).finally(()=>{t.signal.aborted||s(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]),{composition:t,loading:i,error:r}}(a),d=function(e){let[t,a]=(0,n.useState)(null),[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a(null),l(null),s(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{s(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/mcp`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e),l(null))}).catch(e=>{t.signal.aborted||(a(null),l(e instanceof Error?e.message:"Failed to load the run MCP surface"))}).finally(()=>{t.signal.aborted||s(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]),{frozen:t,loading:i,error:r}}(a),u=function(e){let[t,a]=(0,n.useState)([]),[i,s]=(0,n.useState)(null),[r,l]=(0,n.useState)(!1),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!e){let e=window.setTimeout(()=>{a([]),s(null),u(null),l(!1)},0);return()=>window.clearTimeout(e)}let t=new AbortController,n=window.setTimeout(()=>{l(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/messages?limit=200`,{signal:t.signal}).then(e=>{t.signal.aborted||(a(e.messages??[]),s(e.hasMore?e.nextBeforeOrdinal??null:null),u(null))}).catch(e=>{t.signal.aborted||(a([]),s(null),u(e instanceof Error?e.message:"Failed to load the run transcript"))}).finally(()=>{t.signal.aborted||l(!1)})},0);return()=>{window.clearTimeout(n),t.abort()}},[e]);let p=(0,n.useCallback)(()=>{e&&null!==i&&(c(!0),(0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(e)}/messages?limit=200&beforeOrdinal=${i}`).then(e=>{a(t=>{let n=new Set(t.map(e=>e.ordinal));return[...(e.messages??[]).filter(e=>!n.has(e.ordinal)),...t]}),s(e.hasMore?e.nextBeforeOrdinal??null:null),u(null)}).catch(e=>{u(e instanceof Error?e.message:"Failed to load older transcript messages")}).finally(()=>c(!1)))},[e,i]);return{messages:t,hasMore:null!==i,loading:r,loadingOlder:o,error:d,loadOlder:p}}(a);return(0,t.jsxs)("div",{className:"right-panel-tools",children:[(0,t.jsx)(ol,{runId:a,composition:c.composition,mcp:d.frozen,transcript:u,loading:c.loading,error:c.error}),(0,t.jsx)(oc,{selectedSession:i,sessionTitle:s,activeRun:r,status:l,permissionMode:o})]})}function oc({selectedSession:e,sessionTitle:n,activeRun:a,status:i,permissionMode:s}){let r=(0,f.useT)();return(0,t.jsx)("div",{className:"right-panel-summary",children:e?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{children:["Session: ",n]}),(0,t.jsxs)("div",{children:["Active run: ",a||"none"]}),(0,t.jsxs)("div",{children:["Status: ",i?sP(i,r):"idle"]}),(0,t.jsxs)("div",{children:["Permission: ",s]})]}):(0,t.jsx)("div",{children:"No session selected"})})}let od=["files","graph","tools"];function ou(e){return"string"==typeof e&&od.includes(e)}function op(e){return`ennote:right-panel:v1:${e}`}function oh(e){return{version:1,projectId:e,pinnedChannels:[],primaryWidths:{files:280,graph:280,tools:280},open:!1,inspectorTabs:[],activeInspectorId:null,navigatorHidden:!1}}function om(e){return od.filter(t=>e.includes(t))}function of(e){if(!Array.isArray(e))return[];let t=[],n=new Set;for(let a of e){if("object"==typeof a&&null!==a)"string"==typeof a.path&&0!==a.path.length&&(n.has(a.path)||(n.add(a.path),t.push({path:a.path,name:"string"==typeof a.name&&a.name.length>0?a.name:function(e){let t=e.split("/").filter(Boolean);return t[t.length-1]??e}(a.path),pane:"side"===a.pane?"side":"main"})))}return t.slice(-20)}function og(e){let t=om(e.pinnedChannels),n=t.length>0?om(t):[...od];return{projectId:e.projectId,openChannels:n,pinnedChannels:t,activeChannelId:n[0]??null,open:e.open,primaryWidths:{files:ob(e.primaryWidths?.files,ob(e.primaryWidth,280)),graph:ob(e.primaryWidths?.graph,ob(e.primaryWidth,280)),tools:ob(e.primaryWidths?.tools,ob(e.primaryWidth,280))},navigatorHidden:!0===e.navigatorHidden,...function(e){let t=of(e.inspectorTabs),n=e.activeInspectorIds,a=(n,a)=>null!==a&&t.some(t=>(t.pane??"main")===n&&ov(e.projectId,t.path)===a)?a:null,i={main:a("main",n?n.main??null:e.activeInspectorId??null),side:a("side",n?n.side??null:null)};if(null===i.main&&null===i.side&&t.length>0){let n=t[0];i[n.pane??"main"]=ov(e.projectId,n.path)}let s=null!==i.side&&null===i.main?"side":"main";return{inspectorTabs:t,activePanes:i,focusedPane:s,activeLane:null!==i[s]?"inspector":"channel"}}(e)}}function ox(e){let t=e.split(":");return t.length<3?e:t.slice(2).join(":")}function ov(e,t){return`file:${e}:${t}`}function oy(e,t){let n=e.openChannels.includes(t)?e.openChannels:[...e.openChannels,t];return{...e,openChannels:n,activeChannelId:t,activeLane:"channel",open:!0}}function ob(e,t){return"number"==typeof e&&Number.isFinite(e)?Math.max(220,Math.min(2e3,Math.round(e))):t}function ok(e,t,n){let a=e.inspectorTabs.find(e=>e.path===n.path),i=a?.pane??n.pane??"main",s=of([...e.inspectorTabs.filter(e=>e.path!==n.path),{...n,pane:i}]),r=new Set(s.map(t=>ov(e.projectId,t.path))),l={main:null!==e.activePanes.main&&r.has(e.activePanes.main)?e.activePanes.main:null,side:null!==e.activePanes.side&&r.has(e.activePanes.side)?e.activePanes.side:null};return{...e,inspectorTabs:s,activePanes:{...l,[i]:t},focusedPane:i,activeLane:"inspector",open:!0}}function oj(e){let{open:a,onClose:i,resize:s,panel:r,projectId:l,displayPath:o,onOpenFile:c,onOpenFileToSide:d,onPreviewFile:u,selectedSession:p,sessionTitle:h,activeRun:m,inspectorRunId:g,status:x,permissionMode:v}=e,y=(0,f.useT)(),{state:b,fileTabs:k}=r,j=lz("(max-width: 960px)"),w="medium"===lD(s.width,j),[N,_]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null),P=w?N:!b.navigatorHidden,T=b.openChannels,M=r.activeChannelId,R=e=>y("rightPanel.close",{name:e.label}),E=e=>{ou(e)?r.closeChannelTab(e):r.closeTab(e)},A=e=>{r.setActiveTabId(e),w&&_(!1),b.navigatorHidden&&"files"!==e&&r.toggleNavigator()},$=P&&null!==M?lL(b.primaryWidths[M],s.width):0,z=s.width-$-8*($>0),F=s.width-220-8,L=!w&&"wide"===lD(s.width,j)&&(z>=448||F>=448),D=(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("div",{className:"right-panel-channel-slot",hidden:"files"!==M,children:(0,t.jsx)(lX,{projectId:l,displayPath:o,onOpenFile:(e,t)=>{c(e,t),w&&_(!1)},onOpenFileToSide:(e,t)=>{z<448&&$>220&&r.resizePrimaryBy(220-$,s.width),d(e,t),w&&_(!1)},canOpenToSide:L,onPreviewFile:u})}),"graph"===M&&(0,t.jsx)(l5,{sessionId:p,onCount:e=>I({session:p,count:e})}),"tools"===M&&(0,t.jsx)(oo,{runId:g,selectedSession:p,sessionTitle:h,activeRun:m,status:x,permissionMode:v}),null===M&&(0,t.jsx)(lV,{channels:od,hint:y("rightPanel.launcherHint"),t:y,onOpen:r.openChannel})]}),O={graph:{count:C?.session===p?C.count:void 0},tools:{attention:!!x&&s_.has(x.split("\x1f")[0])}},q=(e,n)=>{let a=n.find(t=>t.id===e);return a?.projectId&&a.filePath&&a.projectId===l?(0,t.jsx)(ld,{projectId:a.projectId,filePath:a.filePath,fileName:a.label}):null},B=q(r.activePanes.main,r.paneTabs.main),U=q(r.activePanes.side,r.paneTabs.side),H=L&&r.paneTabs.side.length>0,W=q(r.activePanes[r.focusedPane],r.paneTabs[r.focusedPane]),V=H?[B,U]:[r.paneTabs.side.length>0?W:B],K=k.length>0?(0,t.jsx)("div",{className:`right-panel-panes${H?" is-split":""}`,children:V.map((e,n)=>(0,t.jsx)("div",{className:"right-panel-pane","data-testid":H?0===n?"inspector-pane-main":"inspector-pane-side":"inspector-pane-focused",children:e},0===n?"main":"side"))}):null;return(0,t.jsxs)("div",{className:`right-panel-container${a?" right-panel-open":" right-panel-closed"}`,style:{width:s.width,minWidth:s.width,transition:s.isResizing?"none":void 0},children:[(0,t.jsxs)("button",{type:"button",className:"right-panel-back-button",onClick:()=>{_(!1),i()},children:[(0,t.jsx)(r6,{size:15,"aria-hidden":"true"}),"Back to conversation"]}),(0,t.jsx)(lq,{width:s.width,channelStrip:(0,t.jsxs)("div",{className:"right-panel-strip",children:[(0,t.jsx)(lE,{tabs:lH(T,y,O),activeTabId:M??"",onSelectTab:A,onCloseTab:E,closeLabel:R}),null!==M&&(0,t.jsx)("button",{type:"button",className:"right-panel-strip-action","aria-pressed":b.pinnedChannels.includes(M),"aria-label":b.pinnedChannels.includes(M)?y("rightPanel.unpin"):y("rightPanel.pin"),title:b.pinnedChannels.includes(M)?y("rightPanel.unpin"):y("rightPanel.pin"),onClick:()=>r.togglePin(M),children:b.pinnedChannels.includes(M)?(0,t.jsx)(r8,{size:13,"aria-hidden":"true"}):(0,t.jsx)(r9,{size:13,"aria-hidden":"true"})}),T.length<od.length&&(0,t.jsx)("button",{type:"button",className:"right-panel-strip-action","aria-label":y("rightPanel.add"),title:y("rightPanel.add"),onClick:()=>{let e=od.find(e=>!T.includes(e));e&&r.openChannel(e)},children:(0,t.jsx)(S,{size:13,"aria-hidden":"true"})})]}),channelBody:D,inspectorStrip:H?(0,t.jsxs)("div",{className:"right-panel-pane-strips",children:[(0,t.jsx)(lE,{tabs:r.paneTabs.main,activeTabId:r.activePanes.main??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R}),(0,t.jsx)(lE,{tabs:r.paneTabs.side,activeTabId:r.activePanes.side??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R})]}):k.length>0?(0,t.jsx)(lE,{tabs:k,activeTabId:r.activeInspectorId??"",onSelectTab:A,onCloseTab:r.closeTab,onReorder:r.reorderTabs,closeLabel:R}):null,inspectorBody:K,narrowStrip:(0,t.jsx)("div",{className:"right-panel-strip",children:(0,t.jsx)(lE,{tabs:[...lH(T,y,O),...k],activeTabId:r.activeTabId,onSelectTab:A,onCloseTab:E,onReorder:r.reorderTabs,closeLabel:R})}),narrowBody:(0,t.jsx)("div",{className:"right-panel-body",children:r.activeTabId===r.activeInspectorId&&W?W:D}),primaryWidth:b.primaryWidths[M??"files"],onResizePrimary:e=>r.resizePrimaryBy(e,s.width),onResizePrimaryStart:r.beginPrimaryResize,onResizePrimaryEnd:r.endPrimaryResize,navigatorOpen:P&&a,primaryHidden:!P&&"files"===M,onToggleNavigator:()=>w?_(e=>!e):r.toggleNavigator()})]})}function ow({resize:e}){return(0,t.jsx)(l$,{side:"left",ariaLabel:"Resize right panel",value:e.width,min:280,max:e.maxWidth,onResizeStart:e.beginResize,onResize:e.resizeBy,onResizeEnd:e.endResize})}function oN({projectId:e,filePath:a,fileName:i,onClose:s}){let[r,l]=(0,n.useState)(()=>o_()),o=(0,n.useRef)(null),c=(0,n.useRef)(null);M(!0,s);let d=(0,n.useCallback)((e,t)=>{0!==t.button||r.maximized||(t.preventDefault(),c.current={kind:e,x:t.clientX,y:t.clientY,bounds:r},t.currentTarget.setPointerCapture(t.pointerId))},[r]),u=(0,n.useCallback)(e=>{let t=c.current;if(!t)return;e.preventDefault();let n=e.clientX-t.x,a=e.clientY-t.y,i=window.innerWidth,s=window.innerHeight;"move"===t.kind?l({...t.bounds,x:oC(t.bounds.x+n,0,Math.max(0,i-160)),y:oC(t.bounds.y+a,0,Math.max(0,s-44))}):l({...t.bounds,width:oC(t.bounds.width+n,360,Math.max(360,i-t.bounds.x)),height:oC(t.bounds.height+a,260,Math.max(260,s-t.bounds.y))})},[]),p=(0,n.useCallback)(e=>{c.current=null,e.currentTarget.hasPointerCapture(e.pointerId)&&e.currentTarget.releasePointerCapture(e.pointerId)},[]),h=(0,n.useCallback)(()=>{l(e=>e.maximized?o.current??o_():(o.current=e,{x:12,y:12,width:window.innerWidth-24,height:window.innerHeight-24,maximized:!0}))},[]);return(0,t.jsxs)("section",{className:`file-preview-window${r.maximized?" is-maximized":""}`,role:"dialog","aria-label":`Preview ${i}`,style:{left:r.x,top:r.y,width:r.width,height:r.height},children:[(0,t.jsxs)("header",{className:"file-preview-titlebar",onDoubleClick:h,onPointerDown:e=>d("move",e),onPointerMove:u,onPointerUp:p,onPointerCancel:p,children:[(0,t.jsx)("span",{title:a,children:i}),(0,t.jsxs)("div",{className:"file-preview-window-actions",onPointerDown:e=>e.stopPropagation(),children:[(0,t.jsx)("button",{type:"button",onClick:h,"aria-label":r.maximized?"Restore preview":"Maximize preview",title:r.maximized?"Restore preview":"Maximize preview",children:r.maximized?(0,t.jsx)(eO,{size:14}):(0,t.jsx)(lG,{size:14})}),(0,t.jsx)("button",{type:"button",onClick:s,"aria-label":"Close preview",title:"Close preview",children:(0,t.jsx)(m,{size:15})})]})]}),(0,t.jsx)("div",{className:"file-preview-content",children:(0,t.jsx)(ld,{projectId:e,filePath:a,fileName:i})}),!r.maximized&&(0,t.jsx)("div",{className:"file-preview-resize",role:"separator","aria-label":"Resize preview",onPointerDown:e=>d("resize",e),onPointerMove:u,onPointerUp:p,onPointerCancel:p})]})}function o_(){let e=window.innerWidth,t=window.innerHeight,n=Math.min(760,Math.max(360,e-48)),a=Math.min(600,Math.max(260,t-72));return{x:Math.max(12,Math.round((e-n)/2)),y:Math.max(12,Math.round((t-a)/2)),width:n,height:a,maximized:!1}}function oC(e,t,n){return Math.min(n,Math.max(t,e))}function oS(e){return e.replace(/[\\/]+$/,"").split(/[\\/]/).at(-1)||e}function oI({listing:e,selectedPath:n,showHidden:a,disabled:i,onSelect:s}){let r=a?e.entries:e.entries.filter(e=>!e.hidden||e.path===n);return(0,t.jsx)("div",{className:"project-picker-column",role:"list",children:r.map(e=>{let a=e.path===n;return(0,t.jsx)("span",{role:"listitem",className:"project-picker-row-seat",children:(0,t.jsxs)("button",{type:"button",className:`project-picker-row${a?" selected":""}`,"aria-current":a||void 0,disabled:i,onClick:()=>s(e),children:[a?(0,t.jsx)(N,{size:16,className:"project-picker-folder selected","aria-hidden":"true"}):(0,t.jsx)(w,{size:16,className:"project-picker-folder","aria-hidden":"true"}),(0,t.jsx)("span",{children:e.name}),(0,t.jsx)(j,{size:12,className:"project-picker-row-chevron","aria-hidden":"true"})]})},e.path)})})}function oP({busy:e,onCreate:a,onClose:i}){let s=(0,f.useT)(),[r,l]=(0,n.useState)(null),[o,c]=(0,n.useState)(null),[d,u]=(0,n.useState)(null),[p,h]=(0,n.useState)(!0),[m,g]=(0,n.useState)(null),[x,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(!1),[k,w]=(0,n.useState)(null),[N,_]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null),P=(0,n.useRef)(0),T=(0,n.useRef)(null),R=(0,n.useCallback)(async e=>{let t=e?`?${new URLSearchParams({path:e})}`:"";return(0,e3.apiFetch)(`/v1/host/directories${t}`)},[]),E=(0,n.useCallback)(async e=>{let t=++P.current;h(!0),g(null);try{let n=await R(e);if(t!==P.current)return;l(n),c(null),u(null),v(null)}catch(e){t===P.current&&g(e.message)}finally{t===P.current&&h(!1)}},[R]);(0,n.useEffect)(()=>{let e=++P.current;return R().then(t=>{e===P.current&&(l(t),h(!1))},t=>{e===P.current&&(g(t.message),h(!1))}),()=>{P.current+=1}},[R]),(0,n.useEffect)(()=>{null!==x&&T.current?.focus()},[x]);let A=(0,n.useCallback)(async e=>{let t=++P.current;c(e),u(null),h(!0),g(null);try{let n=await R(e.path);t===P.current&&u(n)}catch(e){t===P.current&&(c(null),g(e.message))}finally{t===P.current&&h(!1)}},[R]),$=(0,n.useCallback)(e=>{d&&(l(d),A(e))},[d,A]),z=o?.path??r?.path??null,F=z?oS(z):"",L=(0,n.useMemo)(()=>{var e;let t;return r?(e=s("directory.home"),(t=r.crumbs.findIndex(e=>e.path===r.home))<0?r.crumbs:[{name:e,path:r.home,hidden:!1},...r.crumbs.slice(t+1)]):[]},[r,s]),D=r?.roots??[],O=r&&r.home.includes("\\")?"\\":"/",q=e||N;M(!0,()=>{if(!q){if(null!==k)return void w(null);if(null!==x)return void v(null);i()}});let B=async()=>{if(z&&null!==k&&k.trim()&&!N){_(!0),I(null);try{let e=await (0,e3.apiFetch)("/v1/host/directories",{method:"POST",body:JSON.stringify({path:z,name:k})});if(w(null),o&&d){let t=await R(o.path);l(t);let n=t.entries.find(t=>t.path===e.path);n&&await A(n)}else{let t=await R(r?.path);l(t);let n=t.entries.find(t=>t.path===e.path);n&&A(n)}}catch(e){I(e.message)}finally{_(!1)}}},U=async()=>{if(z&&!e&&!p&&null===x){g(null);try{await a(F,z)}catch(e){g(e.message)}}};return(0,t.jsxs)("div",{className:"project-picker-overlay",onPointerDown:e=>{e.target!==e.currentTarget||q||null!==k||i()},children:[(0,t.jsxs)("div",{className:"project-picker-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"project-picker-title",children:[(0,t.jsxs)("header",{className:"project-picker-header",children:[(0,t.jsx)("h2",{id:"project-picker-title",children:s("directory.title")}),(0,t.jsx)("div",{className:`project-picker-crumb-bar${null!==x?" editing":""}`,children:null===x?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("nav",{className:"project-picker-crumbs","aria-label":s("directory.path"),children:L.map((e,n)=>(0,t.jsxs)("span",{children:[n>0&&(0,t.jsx)(j,{size:12,"aria-hidden":"true"}),(0,t.jsx)("button",{type:"button",disabled:q,onClick:()=>void E(e.path),children:e.name})]},e.path))}),(0,t.jsx)("button",{type:"button",className:"project-picker-edit-path","aria-label":s("directory.editPath"),title:s("directory.editPath"),disabled:q,onClick:()=>{if(!r||q)return;let e=o?.path??r.path;v(e.endsWith(O)?e:`${e}${O}`)},children:(0,t.jsx)(sM,{size:14,"aria-hidden":"true"})})]}):(0,t.jsx)("input",{ref:T,value:x,"aria-label":s("directory.editPath"),disabled:q,onChange:e=>v(e.target.value),onKeyDown:e=>{"Enter"===e.key&&x.trim()&&E(x),"Escape"!==e.key||e.nativeEvent.isComposing||(e.stopPropagation(),v(null))}})}),D.length>1&&(0,t.jsx)("nav",{className:"project-picker-roots","aria-label":s("directory.roots"),children:D.map(e=>{var n,a;return(0,t.jsx)("button",{type:"button",className:`project-picker-root${(n=r?.path??null,n&&(n===e||n.startsWith(e.endsWith(O)?e:`${e}${O}`)))?" active":""}`,title:e,disabled:q,onClick:()=>void E(e),children:(a=s("directory.home"),e===(r?.home??"")?a:oS(e))},e)})})]}),(0,t.jsxs)("main",{className:"project-picker-content",children:[(0,t.jsxs)("div",{className:"project-picker-miller-row",children:[r&&(0,t.jsx)(oI,{listing:r,selectedPath:o?.path??null,showHidden:y,disabled:q,onSelect:e=>void A(e)}),o&&(0,t.jsx)("span",{className:"project-picker-divider"}),o&&d&&(0,t.jsx)(oI,{listing:d,selectedPath:null,showHidden:y,disabled:q,onSelect:$})]}),p&&(0,t.jsx)("div",{className:"project-picker-loading",role:"status",children:s("directory.loading")}),(r?.truncated||d?.truncated)&&(0,t.jsx)("div",{className:"project-picker-status",children:s("directory.truncated")}),m&&(0,t.jsx)("div",{className:"project-picker-error",role:"alert",children:m})]}),(0,t.jsxs)("footer",{className:"project-picker-footer",children:[(0,t.jsxs)("button",{type:"button",className:"project-picker-button outline new-folder",disabled:!r||p||q||null!==x,onClick:()=>{w(""),I(null)},children:[(0,t.jsx)(S,{size:14,"aria-hidden":"true"})," ",s("directory.newFolder")]}),(0,t.jsxs)("button",{type:"button",className:`project-picker-show-hidden${y?" active":""}`,"aria-pressed":y,disabled:q,onClick:()=>b(e=>!e),children:[s("directory.showHidden"),y&&(0,t.jsx)(Y,{size:14,"aria-hidden":"true"})]}),(0,t.jsx)("span",{className:"project-picker-footer-gap"}),(0,t.jsx)("button",{type:"button",className:"project-picker-button outline",disabled:q,onClick:i,children:s("directory.cancel")}),(0,t.jsx)("button",{type:"button",className:"project-picker-button primary",disabled:!z||p||q||null!==x,onClick:()=>void U(),children:e?s("directory.opening"):s("directory.open")})]})]}),null!==k&&(0,t.jsx)("div",{className:"project-picker-nested-overlay",onPointerDown:e=>{e.target!==e.currentTarget||N||w(null)},children:(0,t.jsxs)("div",{className:"project-picker-create-dialog",role:"dialog","aria-modal":"true","aria-labelledby":"project-folder-title",children:[(0,t.jsx)("h3",{id:"project-folder-title",children:s("directory.newFolder")}),(0,t.jsx)("p",{children:s("directory.createIn",{name:F})}),(0,t.jsx)("input",{value:k,"aria-label":s("directory.folderName"),placeholder:s("directory.untitledFolder"),autoFocus:!0,disabled:N,onChange:e=>w(e.target.value),onKeyDown:e=>{"Enter"===e.key&&B(),"Escape"!==e.key||N||e.nativeEvent.isComposing||(e.stopPropagation(),w(null))}}),C&&(0,t.jsx)("div",{className:"project-picker-error",role:"alert",children:C}),(0,t.jsxs)("div",{className:"project-picker-create-actions",children:[(0,t.jsx)("button",{type:"button",className:"project-picker-button outline",disabled:N,onClick:()=>w(null),children:s("directory.cancel")}),(0,t.jsx)("button",{type:"button",className:"project-picker-button primary",disabled:N||!k.trim(),onClick:()=>void B(),children:s("directory.create")})]})]})})]})}let oT=o("database",[["ellipse",{cx:"12",cy:"5",rx:"9",ry:"3",key:"msslwz"}],["path",{d:"M3 5V19A9 3 0 0 0 21 19V5",key:"1wlel7"}],["path",{d:"M3 12A9 3 0 0 0 21 12",key:"mv7ke4"}]]),oM=o("layers",[["path",{d:"M12.83 2.18a2 2 0 0 0-1.66 0L2.6 6.08a1 1 0 0 0 0 1.83l8.58 3.91a2 2 0 0 0 1.66 0l8.58-3.9a1 1 0 0 0 0-1.83z",key:"zw3jo"}],["path",{d:"M2 12a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 12",key:"1wduqc"}],["path",{d:"M2 17a1 1 0 0 0 .58.91l8.6 3.91a2 2 0 0 0 1.65 0l8.58-3.9A1 1 0 0 0 22 17",key:"kqbvx6"}]]),oR=o("package",[["path",{d:"M11 21.73a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16V8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73z",key:"1a0edw"}],["path",{d:"M12 22V12",key:"d0xqtd"}],["polyline",{points:"3.29 7 12 12 20.71 7",key:"ousv84"}],["path",{d:"m7.5 4.27 9 5.15",key:"1c824w"}]]),oE=o("plug",[["path",{d:"M12 22v-5",key:"1ega77"}],["path",{d:"M15 8V2",key:"18g5xt"}],["path",{d:"M17 8a1 1 0 0 1 1 1v4a4 4 0 0 1-4 4h-4a4 4 0 0 1-4-4V9a1 1 0 0 1 1-1z",key:"1xoxul"}],["path",{d:"M9 8V2",key:"14iosj"}]]),oA=o("shield",[["path",{d:"M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z",key:"oel41y"}]]),o$={state:"idle"},oz=(0,n.createContext)({status:o$,markSaving:()=>{},markSaved:()=>{},markError:()=>{}});function oF({children:e}){let[a,i]=(0,n.useState)(o$),s=(0,n.useRef)(void 0),r=(0,n.useCallback)(()=>{void 0!==s.current&&(window.clearTimeout(s.current),s.current=void 0)},[]),l=(0,n.useCallback)(()=>{r(),i({state:"saving"})},[r]),o=(0,n.useCallback)(()=>{r(),i({state:"saved"}),s.current=window.setTimeout(()=>{s.current=void 0,i(o$)},2400)},[r]),c=(0,n.useCallback)(e=>{r(),i({state:"error",message:e})},[r]);(0,n.useEffect)(()=>r,[r]);let d=(0,n.useMemo)(()=>({status:a,markSaving:l,markSaved:o,markError:c}),[a,l,o,c]);return(0,t.jsx)(oz.Provider,{value:d,children:e})}function oL(){return(0,n.useContext)(oz)}function oD(){let{status:e}=oL(),n=(0,f.useT)();if("idle"===e.state)return null;let a=n("saving"===e.state?"settings.status.saving":"saved"===e.state?"settings.status.saved":"settings.status.failed"),i="saving"===e.state?(0,t.jsx)(eZ,{size:13,className:"spin","aria-hidden":"true"}):"saved"===e.state?(0,t.jsx)(Y,{size:13,"aria-hidden":"true"}):(0,t.jsx)(e0,{size:13,"aria-hidden":"true"});return(0,t.jsxs)("span",{className:"settings-save-status","data-state":e.state,role:"status","aria-live":"polite",title:e.message,children:[i,(0,t.jsx)("span",{children:a})]})}function oO(...e){return e.filter(Boolean).join(" ")}function oq({title:e,description:a,actions:i,className:s,children:r}){let l=(0,n.useId)();return(0,t.jsxs)("section",{className:oO("settings-section",s),"aria-labelledby":e?l:void 0,children:[(e||a||i)&&(0,t.jsxs)("div",{className:"settings-section-header",children:[(0,t.jsxs)("div",{children:[e&&(0,t.jsx)("h3",{id:l,children:e}),a&&(0,t.jsx)("p",{children:a})]}),i&&(0,t.jsx)("div",{className:"settings-section-actions",children:i})]}),r]})}function oB({title:e,meta:n,actions:a,children:i,className:s}){return(0,t.jsxs)("div",{className:oO("settings-row",s),children:[(0,t.jsxs)("div",{className:"settings-row-copy",children:[(0,t.jsx)("strong",{children:e}),n&&(0,t.jsx)("span",{children:n})]}),i,a&&(0,t.jsx)("div",{className:"settings-row-actions",children:a})]})}function oU({children:e,className:n}){return(0,t.jsx)("div",{className:oO("settings-list",n),children:e})}function oH({policies:e,models:n,session:a,refresh:i,setError:s,onSessionUpdated:r}){let{markSaving:l,markSaved:o}=oL();async function c(e,t){l();try{await (0,e3.apiFetch)("/v1/policy-profiles",{method:"POST",body:JSON.stringify({name:e,kind:"compaction",config:t})}),s(null),await i(),o()}catch(e){s(e.message)}}async function d(e){l();try{await (0,e3.apiFetch)(`/v1/policy-profiles/${encodeURIComponent(e)}/default`,{method:"PUT"}),s(null),await i(),o()}catch(e){s(e.message)}}async function u(e){if(a){l();try{let t=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(a.id)}`,{method:"PATCH",body:JSON.stringify(e)});r(t),s(null),o()}catch(e){s(e.message)}}}return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-context-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-context-heading",children:"Context & session"}),(0,t.jsx)("p",{children:"Compaction policy versions and defaults frozen into the next Session Run."})]}),(0,t.jsx)(oW,{policies:e,models:n,onCreate:c,onDefault:d}),(0,t.jsx)(oq,{title:"Current session",description:a?a.title:"Select a Session to configure its defaults.",className:"current-session-settings",children:(0,t.jsxs)("div",{className:"session-default-grid",children:[(0,t.jsxs)("label",{className:"session-model-select",children:["Default model",(0,t.jsxs)("select",{disabled:!a,value:a?.defaultModelProfileId??"",onChange:e=>void u({defaultModelProfileId:e.target.value||null}),children:[(0,t.jsx)("option",{value:"",children:"Use global default"}),n.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]})]}),(0,t.jsxs)("label",{className:"session-model-select",children:["Context compaction",(0,t.jsxs)("select",{disabled:!a,value:a?.compactionPolicyProfileId??"",onChange:e=>void u({compactionPolicyProfileId:e.target.value||null}),children:[(0,t.jsx)("option",{value:"",children:"Use global default"}),e.filter(e=>"compaction"===e.kind&&"active"===e.status).map(e=>(0,t.jsxs)("option",{value:e.id,children:[e.name," v",e.version]},e.id))]})]})]})}),(0,t.jsx)(oV,{sessionId:a?.id??null})]})}function oW({policies:e,models:a,onCreate:i,onDefault:s}){let r=(0,f.useT)(),[l,o]=(0,n.useState)([]),c=(e,t)=>o(n=>n.map((n,a)=>a===e?{...n,...t}:n));async function d(e){e.preventDefault();let t=e.currentTarget,n=new FormData(t),a=String(n.get("mode")),s="manual_and_auto"===a&&"on"===n.get("allowOverflowRecovery"),r=l.filter(e=>e.modelProfileId).map(e=>({modelProfileId:e.modelProfileId,...void 0!==e.triggerRatio?{triggerRatio:e.triggerRatio}:{},...void 0!==e.tailMaxTokens?{tailMaxTokens:e.tailMaxTokens}:{},...void 0!==e.summaryMaxOutputTokens?{summaryMaxOutputTokens:e.summaryMaxOutputTokens}:{}}));await i(String(n.get("name")),{mode:a,triggerRatio:Number(n.get("triggerRatio")),keepRecentTurns:Number(n.get("keepRecentTurns")),tailTokenRatio:Number(n.get("tailTokenRatio")),tailMinTokens:Number(n.get("tailMinTokens")),tailMaxTokens:Number(n.get("tailMaxTokens")),summaryInputRatio:Number(n.get("summaryInputRatio")),compactionModelProfileId:n.get("compactionModelProfileId")||null,summaryMaxOutputTokens:Number(n.get("summaryMaxOutputTokens")),...r.length>0?{modelPolicies:r}:{},includeReasoning:"on"===n.get("includeReasoning"),allowHistoryLookup:"on"===n.get("allowHistoryLookup"),allowOverflowRecovery:s,maxOverflowRecoveries:+!!s,ineffectiveReclaimRatio:Number(n.get("ineffectiveReclaimRatio")),ineffectiveLimit:Number(n.get("ineffectiveLimit")),failureCooldownSeconds:Number(n.get("failureCooldownSeconds")),promptVersion:"v1"}),t.reset(),o([])}return(0,t.jsxs)(oq,{title:"Context compaction",description:"Manual and bounded automatic context checkpoint behavior.",children:[(0,t.jsxs)("form",{className:"settings-form compaction-form",onSubmit:d,children:[(0,t.jsxs)("label",{children:["Name",(0,t.jsx)("input",{name:"name",required:!0})]}),(0,t.jsxs)("label",{children:["Mode",(0,t.jsxs)("select",{name:"mode",defaultValue:"manual_only",children:[(0,t.jsx)("option",{value:"disabled",children:"Disabled"}),(0,t.jsx)("option",{value:"manual_only",children:"Manual only"}),(0,t.jsx)("option",{value:"manual_and_auto",children:"Manual and automatic"})]})]}),(0,t.jsxs)("label",{children:["Summary model",(0,t.jsxs)("select",{name:"compactionModelProfileId",defaultValue:"",children:[(0,t.jsx)("option",{value:"",children:"Use run model"}),a.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]})]}),(0,t.jsxs)("label",{children:["Trigger ratio",(0,t.jsx)("input",{name:"triggerRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.75",required:!0})]}),(0,t.jsxs)("label",{children:["Recent turns",(0,t.jsx)("input",{name:"keepRecentTurns",type:"number",min:"1",step:"1",defaultValue:"2",required:!0})]}),(0,t.jsxs)("label",{children:["Tail ratio",(0,t.jsx)("input",{name:"tailTokenRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.2",required:!0})]}),(0,t.jsxs)("label",{children:["Tail minimum",(0,t.jsx)("input",{name:"tailMinTokens",type:"number",min:"1",step:"1",defaultValue:"8000",required:!0})]}),(0,t.jsxs)("label",{children:["Tail maximum",(0,t.jsx)("input",{name:"tailMaxTokens",type:"number",min:"1",step:"1",defaultValue:"32000",required:!0})]}),(0,t.jsxs)("label",{children:["Summary input ratio",(0,t.jsx)("input",{name:"summaryInputRatio",type:"number",min:"0.01",max:"0.99",step:"0.01",defaultValue:"0.7",required:!0})]}),(0,t.jsxs)("label",{children:["Summary output",(0,t.jsx)("input",{name:"summaryMaxOutputTokens",type:"number",min:"1",step:"1",defaultValue:"4096",required:!0})]}),(0,t.jsxs)("label",{children:["Cooldown seconds",(0,t.jsx)("input",{name:"failureCooldownSeconds",type:"number",min:"0",step:"1",defaultValue:"600",required:!0})]}),(0,t.jsxs)("label",{children:["Ineffective ratio",(0,t.jsx)("input",{name:"ineffectiveReclaimRatio",type:"number",min:"0",max:"0.99",step:"0.01",defaultValue:"0.1",required:!0})]}),(0,t.jsxs)("label",{children:["Ineffective limit",(0,t.jsx)("input",{name:"ineffectiveLimit",type:"number",min:"1",step:"1",defaultValue:"3",required:!0})]}),(0,t.jsxs)("div",{className:"settings-toggles compaction-toggles",children:[(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"allowHistoryLookup",type:"checkbox",defaultChecked:!0})," History lookup"]}),(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"allowOverflowRecovery",type:"checkbox",defaultChecked:!0})," Overflow recovery"]}),(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{name:"includeReasoning",type:"checkbox"})," Include reasoning"]})]}),(0,t.jsxs)("div",{className:"settings-subsection compaction-model-policies",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h4",{children:"Per-model overrides"}),(0,t.jsx)("p",{children:"Optional budget overrides for a specific model."})]}),l.map((e,n)=>(0,t.jsxs)("div",{className:"model-policy-row",children:[(0,t.jsxs)("select",{value:e.modelProfileId,onChange:e=>c(n,{modelProfileId:e.target.value}),"aria-label":`Override model ${n+1}`,children:[(0,t.jsx)("option",{value:"",children:"Select model…"}),a.map(e=>(0,t.jsx)("option",{value:e.id,children:e.displayName||e.modelName},e.id))]}),(0,t.jsx)("input",{type:"number",step:"0.01",min:"0.01",max:"0.99",placeholder:"Trigger ratio",value:e.triggerRatio??"",onChange:e=>c(n,{triggerRatio:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("input",{type:"number",step:"1",min:"1",placeholder:"Tail max tokens",value:e.tailMaxTokens??"",onChange:e=>c(n,{tailMaxTokens:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("input",{type:"number",step:"1",min:"1",placeholder:"Summary output",value:e.summaryMaxOutputTokens??"",onChange:e=>c(n,{summaryMaxOutputTokens:""===e.target.value?void 0:Number(e.target.value)})}),(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:()=>o(e=>e.filter((e,t)=>t!==n)),"aria-label":r("settings.context.removeOverride",{index:String(n+1)}),children:(0,t.jsx)(m,{size:12,"aria-hidden":"true"})})]},n)),(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:()=>o(e=>[...e,{modelProfileId:""}]),children:"+ Add override"})]}),(0,t.jsx)("button",{type:"submit",children:"Create version"})]}),(0,t.jsx)("div",{className:"settings-list",children:e.filter(e=>"compaction"===e.kind).map(e=>(0,t.jsxs)("div",{className:"settings-row",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("strong",{children:e.name}),(0,t.jsxs)("span",{children:["v",e.version," · ",String(e.config.mode??"configured")]})]}),(0,t.jsx)("button",{className:"secondary-btn",disabled:"active"!==e.status,onClick:()=>s(e.id),children:"Use as default"})]},e.id))})]})}function oV({sessionId:e}){let{markSaving:a,markSaved:i}=oL(),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)(null),[c,d]=(0,n.useState)(null);(0,n.useEffect)(()=>{if(!e)return;let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/standing-approvals`).then(n=>{t||(r(n?.items??[]),d(null),o(e))}).catch(n=>{t||(r([]),d(n.message),o(e))}),()=>{t=!0}},[e]);let u=l===e,p=u?s:[],h=!u,m=u?c:null,f=(0,n.useCallback)(async t=>{if(e){a();try{await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/standing-approvals/${encodeURIComponent(t)}/revoke`,{method:"POST"}),r(e=>e.filter(e=>e.id!==t)),d(null),i()}catch(e){d(e.message)}}},[e,a,i]);return e?(0,t.jsxs)(oq,{title:"Standing approvals",description:"Tools automatically authorised for this session. Revoke to require approval again.",className:"standing-approvals-section",children:[h&&(0,t.jsx)("div",{className:"settings-empty",children:"Loading…"}),!h&&m&&(0,t.jsx)("div",{className:"settings-error",children:m}),!h&&!m&&0===p.length&&(0,t.jsx)("div",{className:"settings-empty",children:"No standing approvals for this session."}),!h&&p.length>0&&(0,t.jsx)(oU,{children:p.map(e=>(0,t.jsx)(oB,{title:e.toolName,meta:e.scopeDisplay,actions:(0,t.jsx)("button",{className:"secondary-btn",onClick:()=>f(e.id),children:"Revoke"})},e.id))})]}):null}let oK=o("monitor",[["rect",{width:"20",height:"14",x:"2",y:"3",rx:"2",key:"48i651"}],["line",{x1:"8",x2:"16",y1:"21",y2:"21",key:"1svkeh"}],["line",{x1:"12",x2:"12",y1:"17",y2:"21",key:"vw1qmm"}]]),oG="ennote-default-permission",oJ="ennote-default-permission-change",oY=["discuss","ask","auto"];function oQ(){try{let e=window.localStorage.getItem(oG);if(null!==e&&oY.includes(e))return e}catch{}return"discuss"}var oZ=e.i(18929),oX=e.i(426);let o0=["discuss","ask","auto"];function o1(){let{mode:e,setThemeMode:a}=r4(),{locale:i,setLocale:s}=(0,f.useLocale)(),[r,l]=(0,n.useState)(()=>oQ()),{markSaved:o}=oL(),c=e=>(0,oX.translate)(i,e),d=[{id:"light",label:"Light",icon:(0,t.jsx)(rJ,{size:15,"aria-hidden":"true"})},{id:"dark",label:"Dark",icon:(0,t.jsx)(rG,{size:15,"aria-hidden":"true"})},{id:"system",label:"System",icon:(0,t.jsx)(oK,{size:15,"aria-hidden":"true"})}];return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-general-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-general-heading",children:c("general.title")}),(0,t.jsx)("p",{children:c("general.desc")})]}),(0,t.jsx)(oq,{title:c("general.appearance"),className:"appearance-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.appearance"),children:d.map(n=>(0,t.jsxs)("button",{type:"button",className:`appearance-cube ${e===n.id?"selected":""}`,"aria-pressed":e===n.id,onClick:()=>{a(n.id),o()},children:[n.icon,(0,t.jsx)("span",{children:n.label})]},n.id))})}),(0,t.jsx)(oq,{title:c("general.permission"),description:c("general.permission.desc"),className:"permission-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.permission"),children:o0.map(e=>(0,t.jsx)("button",{type:"button",className:`appearance-cube ${r===e?"selected":""}`,"aria-pressed":r===e,title:c(`permission.${e}.description`),onClick:()=>{l(e);try{window.localStorage.setItem(oG,e)}catch{}window.dispatchEvent(new CustomEvent(oJ,{detail:e})),o()},children:(0,t.jsx)("span",{children:c(`permission.${e}`)})},e))})}),(0,t.jsx)(oq,{title:c("general.language"),className:"language-group",children:(0,t.jsx)("div",{className:"appearance-cubes",role:"group","aria-label":c("general.language"),children:oZ.LOCALES.map(e=>(0,t.jsx)("button",{type:"button",className:`appearance-cube ${i===e?"selected":""}`,"aria-pressed":i===e,onClick:()=>{s(e),o()},children:(0,t.jsx)("span",{children:"en"===e?c("language.en"):c("language.zh")})},e))})})]})}function o2(e,t){return(0,e3.apiFetch)("/v1/packs/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:{kind:"path",path:e},dryRun:t.dryRun,...t.expectedDigest?{expectedDigest:t.expectedDigest}:{}})})}var o4=e.i(67203);function o5({setError:e}){let[a,i]=(0,n.useState)([]),[s,r]=(0,n.useState)(!0),[l,o]=(0,n.useState)(""),[c,d]=(0,n.useState)(!1),[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(null),[f,g]=(0,n.useState)(null),[x,v]=(0,n.useState)(null),[y,b]=(0,n.useState)(null),k=async()=>{try{i(await (0,e3.apiFetch)("/v1/packs")),e(null)}catch(t){e(t.message)}finally{r(!1)}};(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void k(),0);return()=>window.clearTimeout(e)},[]);let j=async t=>{if(!c){d(!0),e(null);try{await t()}catch(t){e(t.message)}finally{d(!1)}}},w=e=>{o(e),m(null),g(null),p(null),b(null)},N=async()=>{!h||f!==l.trim()||await rx({title:`Install ${h.pack.name} ${h.pack.version}?`,description:h.willPublishFlowRevision?"This creates disabled draft objects and publishes an Agent Flow revision.":"This creates disabled draft objects on this Worker. Nothing runs until a revision is published and bound.",confirmLabel:"Install"})&&await j(async()=>{await o2(l.trim(),{dryRun:!1,expectedDigest:h.packDigest}),m(null),g(null),p(null),w(""),await k()})},_=async(t,n)=>{let a,i=2!==(a=t.pack.id.split("/")).length||""===a[0]||""===a[1]?null:{publisher:a[0],name:a[1]};i?await rx({title:n?`Force-remove ${t.pack.name}?`:`Remove ${t.pack.name}?`,description:n?"This also deletes objects that were edited locally or still referenced by another Graph.":"Every object this pack installed is deleted. A locally edited Skill is kept, with a warning.",confirmLabel:n?"Force remove":"Remove",tone:"danger"})&&await j(async()=>{v(t.pack.id);try{await function(e,t,n=!1){return(0,e3.apiFetch)(`/v1/packs/${encodeURIComponent(e)}/${encodeURIComponent(t)}${n?"?force=true":""}`,{method:"DELETE"})}(i.publisher,i.name,n),b(null),await k()}catch(e){throw b(t.pack.id),e}finally{v(null)}}):e(`"${t.pack.id}" is not a publisher/name pack id.`)},C=null===h||f!==l.trim()||h.blockers.length>0;return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-packs-heading",children:[(0,t.jsx)("h3",{id:"settings-packs-heading",className:o4.default.heading,children:"Agent Packs"}),(0,t.jsx)("p",{className:o4.default.note,children:"A pack ships Heroes, Skills, and optionally a Graph or Agent Flow. Installing one only creates disabled drafts on this Worker — nothing runs until a revision is published and bound."}),(0,t.jsxs)("div",{className:o4.default.installer,children:[(0,t.jsxs)("label",{className:o4.default.pathLabel,children:[(0,t.jsx)("span",{children:"Pack path on the Worker host"}),(0,t.jsx)("input",{className:o4.default.pathInput,value:l,placeholder:"/home/me/packs/example.enpack",onChange:e=>w(e.target.value)})]}),(0,t.jsxs)("div",{className:o4.default.actions,children:[(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||""===l.trim(),onClick:()=>j(async()=>{var e;m(null),g(null),p(await (e=l.trim(),(0,e3.apiFetch)("/v1/packs/inspect",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({source:{kind:"path",path:e}})})))}),children:"Inspect"}),(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||""===l.trim(),onClick:()=>j(async()=>{m(await o2(l.trim(),{dryRun:!0})),g(l.trim())}),children:"Check install"}),(0,t.jsx)("button",{type:"button",className:`${o4.default.button} ${o4.default.primary}`,disabled:c||""===l.trim()||C,onClick:N,children:"Install"})]})]}),u&&(0,t.jsxs)("div",{className:o4.default.card,"data-testid":"pack-inspect",children:[(0,t.jsxs)("div",{className:o4.default.cardHead,children:[(0,t.jsx)(oR,{size:14,"aria-hidden":"true"}),(0,t.jsx)("span",{className:o4.default.cardName,children:u.pack.name}),(0,t.jsx)("span",{className:o4.default.badge,children:u.pack.version}),(0,t.jsx)("span",{className:o4.default.badge,children:u.pack.id}),!u.signed&&(0,t.jsx)("span",{className:o4.default.badge,children:"unsigned"})]}),(0,t.jsxs)("div",{className:o4.default.counts,children:[u.flows.length," flows · ",u.heroes.length," heroes · ",u.skills.length," skills · ",u.filesTotal," files"]}),(0,t.jsxs)("div",{className:o4.default.digest,children:["pack digest ",u.packDigest.slice(0,16),"…"]}),(0,t.jsx)(o3,{issues:u.warnings})]}),h&&(0,t.jsxs)("div",{className:o4.default.card,"data-testid":"pack-plan","data-blocked":C||void 0,children:[(0,t.jsxs)("div",{className:o4.default.cardHead,children:[(0,t.jsx)("span",{className:o4.default.cardName,children:"Install plan"}),(0,t.jsxs)("span",{className:o4.default.badge,children:[h.actions.length," actions"]}),h.willPublishFlowRevision&&(0,t.jsx)("span",{className:o4.default.badge,children:"publishes a revision"})]}),(0,t.jsx)("ul",{className:o4.default.actionList,children:h.actions.map(e=>(0,t.jsxs)("li",{className:o4.default.actionRow,children:[(0,t.jsx)("span",{className:o4.default.badge,children:e.kind}),(0,t.jsx)("span",{className:o4.default.actionId,children:e.storeId}),(0,t.jsx)("span",{className:o4.default.actionVerb,"data-action":e.action,children:e.action})]},`${e.kind}:${e.storeId}`))}),(0,t.jsx)(o3,{issues:[...h.blockers.map(e=>({...e,severity:e.severity??"error"})),...h.warnings.map(e=>({...e,severity:e.severity??"warning"}))]})]}),(0,t.jsxs)("div",{className:o4.default.sectionHeader,children:["Installed ",(0,t.jsx)("span",{className:o4.default.sectionCount,children:a.length}),(0,t.jsx)("button",{type:"button",className:o4.default.iconButton,"aria-label":"Refresh installed packs",onClick:()=>void k(),children:(0,t.jsx)(sY,{size:13,"aria-hidden":"true"})})]}),s?(0,t.jsx)("div",{className:o4.default.empty,children:"Loading…"}):0===a.length?(0,t.jsx)("div",{className:o4.default.empty,children:"No packs installed."}):(0,t.jsx)("div",{className:o4.default.stack,children:a.map(e=>(0,t.jsxs)("div",{className:o4.default.row,"data-testid":"pack-row",children:[(0,t.jsxs)("div",{className:o4.default.identity,children:[(0,t.jsxs)("div",{className:o4.default.titleRow,children:[(0,t.jsx)("span",{className:o4.default.name,children:e.pack.name}),(0,t.jsx)("span",{className:o4.default.badge,children:e.pack.version})]}),(0,t.jsxs)("div",{className:o4.default.meta,children:[e.flowCount," flows · ",e.heroCount," heroes · ",e.skillCount," skills"]})]}),y===e.pack.id&&(0,t.jsx)("button",{type:"button",className:o4.default.button,disabled:c||x===e.pack.id,onClick:()=>void _(e,!0),children:"Force remove"}),(0,t.jsx)("button",{type:"button",className:o4.default.iconButton,"aria-label":`Remove ${e.pack.name}`,disabled:c||x===e.pack.id,onClick:()=>void _(e,!1),children:(0,t.jsx)(P,{size:13,"aria-hidden":"true"})})]},e.pack.id))})]})}function o3({issues:e}){return 0===e.length?null:(0,t.jsx)("ul",{className:o4.default.issueList,children:e.map(e=>(0,t.jsxs)("li",{className:o4.default.issueRow,"data-severity":e.severity??"warning",children:[(0,t.jsx)("span",{className:o4.default.badge,children:e.code}),(0,t.jsx)("span",{children:e.message})]},`${e.code}:${e.message}`))})}var o6=e.i(82399);let o8={stdio:"stdio",streamable_http:"Streamable HTTP",legacy_sse:"HTTP + SSE"};function o9({mcp:e}){let{showCreate:n,transport:a,setTransport:i,displayName:s,setDisplayName:r,slug:l,setSlug:o,executable:c,setExecutable:d,argv:u,setArgv:p,endpoint:h,setEndpoint:m,createProfile:f}=e;return(0,t.jsx)(t.Fragment,{children:n&&(0,t.jsxs)("div",{className:o6.default.form,children:[(0,t.jsxs)("div",{className:o6.default.formGrid,children:[(0,t.jsxs)("label",{className:o6.default.field,children:["Display name",(0,t.jsx)("input",{value:s,onChange:e=>r(e.target.value),className:o6.default.input,placeholder:"PubMed"})]}),(0,t.jsxs)("label",{className:o6.default.field,children:["Slug (fixed once bound)",(0,t.jsx)("input",{value:l,onChange:e=>o(e.target.value),className:o6.default.input,placeholder:"pubmed"})]})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:o6.default.transportRow,children:["stdio","streamable_http","legacy_sse"].map(e=>(0,t.jsx)("button",{type:"button",onClick:()=>i(e),className:o6.default.transportButton,"data-active":a===e||void 0,children:o8[e]},e))}),"stdio"===a?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("label",{className:o6.default.field,children:["Executable",(0,t.jsx)("input",{value:c,onChange:e=>d(e.target.value),className:o6.default.input,placeholder:"/usr/bin/python3"})]}),(0,t.jsxs)("label",{className:o6.default.field,children:["Arguments (space-separated)",(0,t.jsx)("input",{value:u,onChange:e=>p(e.target.value),className:o6.default.input,placeholder:"/path/to/server.py"})]})]}):(0,t.jsxs)("label",{className:o6.default.field,children:["Endpoint URL",(0,t.jsx)("input",{value:h,onChange:e=>m(e.target.value),className:o6.default.input,placeholder:"https://example.com/mcp"})]})]}),(0,t.jsx)("button",{type:"button",onClick:f,disabled:!s.trim()||!l.trim()||("stdio"===a?!c.trim():!h.trim()),className:o6.default.createButton,children:"Create profile"})]})})}function o7({mcp:e,binding:n}){let{catalogs:a,toolSearch:i,setToolSearch:s,showCreds:r,setShowCreds:l,credEnv:o,setCredEnv:c,credRef:d,setCredRef:u,versionFor:p,updateBinding:h,toggleTool:m,selectAllTools:f,addCredential:g,removeCredential:x,testBinding:v,refreshCatalog:y,removeBinding:b}=e,k=a[n.id]??[],j=n.selectedRemoteToolNames??[],w=p(n),N=w?"stdio"===w.transport?`${w.executable??""} ${(w.argv??[]).join(" ")}`.trim():w.endpoint??"":"";return(0,t.jsxs)("div",{className:o6.default.card,children:[(0,t.jsxs)("div",{className:o6.default.cardHead,children:[(0,t.jsxs)("div",{className:o6.default.cardIdentity,children:[(0,t.jsxs)("div",{className:o6.default.cardTitle,children:[w?o8[w.transport]??w.transport:"MCP server",(0,t.jsxs)("span",{className:o6.default.cardMeta,children:["rev ",n.revision??0," · ",j.length," tools selected"]})]}),N&&(0,t.jsx)("div",{className:o6.default.commandSummary,children:N})]}),(0,t.jsxs)("div",{className:o6.default.actions,children:[(0,t.jsx)("button",{type:"button",title:n.required?"Server is required: Run start fails when unreachable":"Server is optional: Run start continues when unreachable",onClick:()=>h(n,{required:!n.required}),className:o6.default.requiredButton,"data-required":n.required||void 0,children:n.required?"required":"optional"}),(0,t.jsx)("button",{type:"button",title:"Edit credential references for this binding",onClick:()=>l(e=>({...e,[n.id]:!e[n.id]})),className:o6.default.ghostButton,children:"Credentials"}),(0,t.jsx)("button",{type:"button",onClick:async()=>{let e=!n.desiredEnabled;if(e){let e=w?"stdio"===w.transport?`Command: ${N}`:`Endpoint: ${w.endpoint??""}`:"";if(!await rx({title:"Enable this MCP server?",description:`${e}
|
|
7
7
|
|
|
8
8
|
Only selected tools will be exposed to Runs.`,confirmLabel:"Enable server"}))return}await h(n,{desiredEnabled:e})},className:o6.default.enableButton,"data-enabled":n.desiredEnabled||void 0,children:n.desiredEnabled?"Enabled":"Disabled"}),(0,t.jsx)("button",{type:"button",title:"Test connection",onClick:()=>v(n),className:o6.default.ghostButton,children:"Test"}),(0,t.jsx)("button",{type:"button",title:"Refresh tool catalog",onClick:()=>y(n),className:o6.default.ghostButton,children:"Refresh"}),(0,t.jsx)("button",{type:"button",title:"Remove binding",onClick:()=>b(n),className:`${o6.default.ghostButton} ${o6.default.danger}`,children:"Remove"})]})]}),n.desiredEnabled&&(0,t.jsxs)("div",{children:[(0,t.jsxs)("div",{className:o6.default.toolsHeader,children:[(0,t.jsx)("span",{className:o6.default.toolsHint,children:"Selected tools (exact, frozen per Run)"}),k.length>0&&(0,t.jsx)("button",{type:"button",onClick:()=>f(n,k),className:o6.default.ghostButton,children:"Select all current"})]}),0===k.length?(0,t.jsx)("div",{className:o6.default.catalogEmpty,children:"No catalog yet — press Refresh to discover tools from the server."}):(0,t.jsxs)("div",{children:[(0,t.jsx)("input",{type:"search",placeholder:"Search tools…",value:i[n.id]??"",onChange:e=>s(t=>({...t,[n.id]:e.target.value})),className:`${o6.default.input} ${o6.default.toolSearch}`}),(0,t.jsx)("div",{className:o6.default.catalogScroll,children:(0,t.jsx)("table",{className:o6.default.catalogTable,children:(0,t.jsx)("tbody",{children:k.filter(e=>{let t=(i[n.id]??"").toLowerCase();return!t||e.remoteName.toLowerCase().includes(t)||(e.description??"").toLowerCase().includes(t)}).map(e=>(0,t.jsxs)("tr",{className:o6.default.toolRow,children:[(0,t.jsx)("td",{className:o6.default.toolCheckCell,children:(0,t.jsx)("input",{type:"checkbox",className:o6.default.toolCheckbox,"aria-label":e.remoteName,checked:j.includes(e.remoteName),onChange:()=>m(n,e.remoteName)})}),(0,t.jsx)("td",{className:o6.default.toolNameCell,children:e.remoteName}),(0,t.jsx)("td",{className:o6.default.toolDescriptionCell,children:e.description||"—"})]},e.remoteName))})})})]})]}),r[n.id]&&(0,t.jsxs)("div",{className:o6.default.credentials,children:[(0,t.jsx)("div",{className:o6.default.credentialNote,children:"Credential references (env: / file: / keyring: refs only — values never stored or shown)"}),Object.entries(n.credentialRefs??{}).map(([e,a])=>(0,t.jsxs)("div",{className:o6.default.credentialRow,children:[(0,t.jsx)("code",{className:o6.default.credentialEnv,children:e}),(0,t.jsx)("code",{className:o6.default.credentialRef,children:a}),(0,t.jsx)("button",{type:"button",onClick:()=>x(n,e),className:o6.default.ghostButton,children:"Remove"})]},e)),0===Object.keys(n.credentialRefs??{}).length&&(0,t.jsx)("div",{className:o6.default.credentialNote,children:"No binding-level credentials. The profile version's defaults apply."}),(0,t.jsxs)("div",{className:o6.default.credentialInputRow,children:[(0,t.jsx)("input",{value:o[n.id]??"",onChange:e=>c(t=>({...t,[n.id]:e.target.value})),placeholder:"ENV_NAME",className:`${o6.default.input} ${o6.default.credentialEnvInput}`}),(0,t.jsx)("input",{value:d[n.id]??"",onChange:e=>u(t=>({...t,[n.id]:e.target.value})),placeholder:"env:MY_REF / file:... / keyring:...",className:`${o6.default.input} ${o6.default.credentialRefInput}`}),(0,t.jsx)("button",{type:"button",onClick:()=>g(n),disabled:!(o[n.id]??"").trim()||!(d[n.id]??"").trim(),className:o6.default.ghostButton,children:"Add"})]})]})]},n.id)}function ce({mcp:e}){let{profiles:n,candidates:a,bindings:i,versions:s,diffView:r,bindCandidate:l,openProfileDiff:o,archiveProfile:c}=e;return 0===a.length&&0===n.length?null:(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:o6.default.sectionHeader,children:"Discovered servers"}),(0,t.jsxs)("div",{className:o6.default.list,children:[a.map(e=>{let a;return(0,t.jsxs)("div",{className:o6.default.candidateGroup,children:[(0,t.jsxs)("div",{className:o6.default.candidateRow,children:[(0,t.jsxs)("div",{className:o6.default.candidateIdentity,children:[(0,t.jsx)("span",{className:o6.default.candidateName,children:e.displayName??e.slug}),(0,t.jsxs)("span",{className:o6.default.candidateMeta,children:[e.transport," · ",e.sourceKind]}),"project_file"===e.sourceKind&&(0,t.jsx)("div",{className:o6.default.candidateSource,children:e.sourceLocator})]}),(0,t.jsxs)("div",{className:o6.default.candidateActions,children:[e.alreadyBound?(0,t.jsx)("span",{className:o6.default.boundBadge,children:"Bound"}):(0,t.jsx)("button",{type:"button",onClick:()=>l(e),className:o6.default.ghostButton,children:"Bind"}),e.alreadyBound&&e.updateAvailable&&(0,t.jsx)("button",{type:"button",title:"Project file changed; rebind to the new immutable version",onClick:()=>l(e),className:`${o6.default.ghostButton} ${o6.default.accent}`,children:"Update available"}),e.alreadyBound&&e.updateAvailable&&(0,t.jsx)("button",{type:"button",title:"Show the read-only diff between the bound version and the project file",onClick:()=>o(e),className:o6.default.ghostButton,children:"View diff"}),"managed"===e.sourceKind&&!e.alreadyBound&&((a=n.find(t=>t.slug===e.slug&&"active"===t.lifecycleStatus))?(0,t.jsx)("button",{type:"button",title:"Archive MCP profile","aria-label":`Archive MCP profile ${a.displayName??a.slug}`,onClick:()=>c(a),className:`${o6.default.ghostButton} ${o6.default.danger} ${o6.default.archiveButton}`,children:(0,t.jsx)(A,{size:14,"aria-hidden":"true"})}):null)]})]}),r&&r.slug===e.slug&&(0,t.jsxs)("div",{className:o6.default.diffCard,children:[(0,t.jsxs)("div",{className:o6.default.diffTitle,children:["Read-only diff: bound version vs project file",r.digestTo&&(0,t.jsxs)("span",{className:o6.default.diffDigest,children:["new config ",r.digestTo.slice(0,8)]})]}),r.lines.some(e=>e.startsWith("+ ")||e.startsWith("- "))?(0,t.jsx)("div",{className:o6.default.diffBody,children:r.lines.map((e,n)=>(0,t.jsx)("div",{className:o6.default.diffLine,"data-kind":e.startsWith("- ")?"removed":e.startsWith("+ ")?"added":void 0,children:e},n))}):(0,t.jsxs)("div",{className:o6.default.diffUnchanged,children:["Connection fields are unchanged — the project file changed argv, env, headers, or timeout (config digest ",r.digestTo?r.digestTo.slice(0,8):"changed",")."]})]})]},`${e.sourceKind}:${e.slug}`)}),n.filter(e=>!a.some(t=>t.slug===e.slug)).map(e=>{let n=new Set((s[e.id]??[]).map(e=>e.id)),a=i.some(e=>n.has(e.profileVersionId));return(0,t.jsxs)("div",{className:o6.default.candidateRow,children:[(0,t.jsxs)("div",{className:o6.default.candidateIdentity,children:[(0,t.jsx)("span",{className:o6.default.candidateName,children:e.displayName}),(0,t.jsxs)("span",{className:o6.default.candidateMeta,children:[e.slug," · v",e.latestVersion??0," · managed"]})]}),(0,t.jsx)("div",{className:o6.default.candidateActions,children:a?(0,t.jsx)("span",{className:o6.default.boundBadge,children:"Bound"}):(0,t.jsx)("button",{type:"button",title:"Archive MCP profile","aria-label":`Archive MCP profile ${e.displayName??e.slug}`,onClick:()=>c(e),className:`${o6.default.ghostButton} ${o6.default.danger} ${o6.default.archiveButton}`,children:(0,t.jsx)(A,{size:14,"aria-hidden":"true"})})})]},e.id)})]})]})}function ct({projectId:e,setError:a}){let i=function(e,t){let[a,i]=(0,n.useState)([]),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)([]),[c,d]=(0,n.useState)({}),[u,p]=(0,n.useState)({}),[h,m]=(0,n.useState)({}),[f,g]=(0,n.useState)({}),[x,v]=(0,n.useState)({}),[y,b]=(0,n.useState)({}),[k,j]=(0,n.useState)(null),{markSaving:w,markSaved:N}=oL(),[_,C]=(0,n.useState)(!1),[S,I]=(0,n.useState)(!1),[P,T]=(0,n.useState)("stdio"),[M,R]=(0,n.useState)(""),[E,A]=(0,n.useState)(""),[$,z]=(0,n.useState)(""),[F,L]=(0,n.useState)(""),[D,O]=(0,n.useState)(""),q=(0,n.useCallback)(async e=>{let t={};await Promise.all(e.map(async e=>{try{t[e.id]=await (0,e3.apiFetch)(`/v1/mcp/server-profiles/${e.id}/versions`)}catch{}})),p(t)},[]),B=(0,n.useCallback)(e=>{for(let t of Object.values(u)){let n=t.find(t=>t.id===e.profileVersionId);if(n)return n}},[u]),U=(0,n.useCallback)(e=>{if(e)for(let t of Object.values(u)){let n=t.find(t=>t.id===e);if(n)return n}},[u]),H=(0,n.useCallback)(e=>{let t=U(e.boundVersionId),n=JSON.stringify(t?{transport:t.transport,..."stdio"===t.transport?{executable:t.executable??""}:{endpoint:t.endpoint??""}}:{transport:"(unknown bound version)"},null,2),a=JSON.stringify({transport:e.transport,..."stdio"===e.transport?{executable:e.executable??""}:{endpoint:e.endpoint??""}},null,2);j({slug:e.slug??"",lines:function(e,t){let n=e.split("\n"),a=t.split("\n"),i=[],s=Math.max(n.length,a.length);for(let e=0;e<s;e++){let t=n[e],s=a[e];void 0===t?i.push(`+ ${s}`):void 0===s?i.push(`- ${t}`):t===s?i.push(` ${t}`):(i.push(`- ${t}`),i.push(`+ ${s}`))}return i}(n,a),digestTo:e.configDigest??""})},[U]),W=(0,n.useCallback)(async()=>{if(e){C(!0);try{let[t,n,a]=await Promise.all([(0,e3.apiFetch)("/v1/mcp/server-profiles"),(0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings`),(0,e3.apiFetch)(`/v1/projects/${e}/mcp/candidates`)]);i(t),o(n),r(a),q(t);let s={};for(let t of n)if(t.desiredEnabled)try{s[t.id]=await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${t.id}/catalog`)}catch{}d(s)}catch(e){t(e instanceof Error?e.message:"Failed to load MCP settings")}finally{C(!1)}}},[e,t,q]);(0,n.useEffect)(()=>{let n=!1;if(e)return Promise.all([(0,e3.apiFetch)("/v1/mcp/server-profiles"),(0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings`),(0,e3.apiFetch)(`/v1/projects/${e}/mcp/candidates`).catch(()=>{throw Error("Failed to load discovered servers")})]).then(async([t,a,s])=>{if(n)return;i(t),o(a),r(s),q(t);let l={};for(let t of a)if(t.desiredEnabled)try{l[t.id]=await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${t.id}/catalog`)}catch{}n||d(l)}).catch(e=>{n||t(e instanceof Error?e.message:"Failed to load MCP settings")}),()=>{n=!0}},[e,t,q]);let V=async()=>{w();try{let e=await (0,e3.apiFetch)("/v1/mcp/server-profiles",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({displayName:M,slug:E,sourceKind:"managed"})}),t={transport:P};if("stdio"===P){t.executable=$.trim();let e=F.split(/\s+/).filter(Boolean);e.length>0&&(t.argv=e)}else t.endpoint=D.trim();await (0,e3.apiFetch)(`/v1/mcp/server-profiles/${e.id}/versions`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify(t)}),I(!1),R(""),A(""),z(""),L(""),O(""),await W(),N()}catch(e){t(e instanceof Error?e.message:"Failed to create MCP profile")}},K=async(n,a)=>{if(e){w();try{await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${n.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify(a)}),await W(),N()}catch(e){t(e instanceof Error?e.message:"Failed to update MCP binding")}}},G=async(e,t)=>{let n=e.selectedRemoteToolNames??[],a=n.includes(t)?n.filter(e=>e!==t):[...n,t];await K(e,{selectedRemoteToolNames:a})},J=async(e,t)=>{await K(e,{selectedRemoteToolNames:t.map(e=>e.remoteName)})},Y=async e=>{let t=(x[e.id]??"").trim(),n=(y[e.id]??"").trim();if(!t||!n)return;let a={...e.credentialRefs??{}};a[t]=n,await K(e,{credentialRefs:a}),v(t=>({...t,[e.id]:""})),b(t=>({...t,[e.id]:""}))},Q=async(e,t)=>{let n={...e.credentialRefs??{}};delete n[t],await K(e,{credentialRefs:n})};return{profiles:a,candidates:s,bindings:l,catalogs:c,versions:u,toolSearch:h,setToolSearch:m,showCreds:f,setShowCreds:g,credEnv:x,setCredEnv:v,credRef:y,setCredRef:b,diffView:k,loading:_,showCreate:S,setShowCreate:I,transport:P,setTransport:T,displayName:M,setDisplayName:R,slug:E,setSlug:A,executable:$,setExecutable:z,argv:F,setArgv:L,endpoint:D,setEndpoint:O,versionFor:B,openProfileDiff:H,createProfile:V,bindCandidate:async n=>{if(e){w();try{("project_file"!==n.sourceKind||n.boundVersionId||n.updateAvailable)&&n.boundVersionId&&!n.updateAvailable?await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({profileVersionId:n.boundVersionId})}):await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/from-candidate`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({slug:n.slug,transport:n.transport})}),await W(),N()}catch(e){t(e instanceof Error?e.message:"Failed to bind MCP candidate")}}},updateBinding:K,toggleTool:G,selectAllTools:J,addCredential:Y,removeCredential:Q,testBinding:async n=>{if(e)try{await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${n.id}/test`,{method:"POST"}),t(null)}catch(e){t(e instanceof Error?e.message:"Test failed")}},refreshCatalog:async n=>{if(e)try{let a=await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${n.id}/catalog/refresh`,{method:"POST"});d(e=>({...e,[n.id]:a})),t(null)}catch(e){t(e instanceof Error?e.message:"Catalog refresh failed")}},removeBinding:async n=>{if(e&&await rx({title:"Remove this MCP binding?",description:"Tools from this server will no longer be available to Runs in this project.",confirmLabel:"Remove binding",tone:"danger"})){w();try{await (0,e3.apiFetch)(`/v1/projects/${e}/mcp/bindings/${n.id}`,{method:"DELETE"}),await W(),N()}catch(e){t(e instanceof Error?e.message:"Failed to remove binding")}}},archiveProfile:async e=>{if(e.id&&await rx({title:`Archive MCP profile “${e.displayName??e.slug}”?`,description:"Bindings that reference this profile will stop resolving for new Runs.",confirmLabel:"Archive profile",tone:"danger"})){w();try{await (0,e3.apiFetch)(`/v1/mcp/server-profiles/${encodeURIComponent(e.id)}`,{method:"DELETE"}),t(null),await W(),N()}catch(e){t(e instanceof Error?e.message:"Failed to archive MCP profile")}}}}}(e,a);return e?(0,t.jsxs)("div",{className:o6.default.settingsRoot,children:[(0,t.jsxs)("div",{className:o6.default.settingsHeader,children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("div",{className:o6.default.settingsTitle,children:"MCP servers"}),(0,t.jsx)("div",{className:o6.default.settingsDescription,children:"Tools-first client. Servers are discovered, tested, then explicitly enabled per project."})]}),(0,t.jsx)("button",{type:"button",onClick:()=>i.setShowCreate(e=>!e),className:o6.default.addButton,children:i.showCreate?"Cancel":"+ Add server"})]}),(0,t.jsx)(o9,{mcp:i}),(0,t.jsxs)("div",{className:o6.default.bindings,children:[0===i.bindings.length&&!i.loading&&(0,t.jsx)("div",{className:o6.default.emptyText,children:"No MCP servers bound to this project yet."}),i.bindings.map(e=>(0,t.jsx)(o7,{mcp:i,binding:e},e.id))]}),(0,t.jsx)(ce,{mcp:i}),i.loading&&(0,t.jsx)("div",{className:o6.default.loadingText,children:"Loading…"})]}):(0,t.jsx)("div",{className:o6.default.emptyText,children:"Open a project to manage MCP servers."})}var cn=e.i(90239);function ca(e){let{roots:n,loading:a,control:i}=e,{showRootForm:s,setShowRootForm:r,rootName:l,setRootName:o,rootPreset:c,setRootPreset:d,rootPath:u,setRootPath:p,rootBusy:h,addRoot:f,toggleRoot:g,removeRoot:x}=i;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:cn.default.sectionHeader,children:["Skills roots ",(0,t.jsxs)("span",{className:cn.default.sectionCount,children:[n.length," additional"]})]}),(0,t.jsx)("div",{className:cn.default.note,children:"Resolution paths are on the Worker host. Remote clients (Tauri) read the same configured roots — no per-client setup."}),(0,t.jsxs)("div",{className:cn.default.stack,children:[0===n.length&&!a&&(0,t.jsxs)("div",{className:cn.default.empty,children:["No additional roots. Ennote reads ",(0,t.jsx)("code",{children:"$ENNOTE_HOME/skills"})," on the Worker host by default; add pi, Claude Code, Codex, or Cursor skill directories here."]}),n.map(e=>(0,t.jsxs)("div",{className:cn.default.rootRow,children:[(0,t.jsxs)("div",{className:cn.default.rootIdentity,children:[(0,t.jsxs)("div",{className:cn.default.rootTitleRow,children:[(0,t.jsx)("span",{className:cn.default.rootName,children:e.name}),(0,t.jsx)("span",{className:cn.default.badge,children:e.agentKind}),(0,t.jsxs)("span",{className:cn.default.rootPriority,children:["pri ",e.priority]})]}),(0,t.jsx)("div",{className:cn.default.rootPath,children:e.path})]}),(0,t.jsx)("button",{type:"button",onClick:()=>void g(e),disabled:null!==h,className:cn.default.toggle,"data-enabled":e.enabled||void 0,children:e.enabled?"Enabled":"Disabled"}),(0,t.jsx)("button",{type:"button",onClick:()=>void x(e),disabled:null!==h,title:`Stop reading skills from ${e.path}`,className:`${cn.default.ghostButton} ${cn.default.danger}`,children:(0,t.jsx)(m,{size:12,"aria-hidden":"true"})})]},e.id)),s?(0,t.jsxs)("div",{className:cn.default.rootForm,children:[(0,t.jsxs)("div",{className:cn.default.inputRow,children:[(0,t.jsxs)("select",{value:c,onChange:e=>d(e.target.value),"aria-label":"Ecosystem preset",className:`${cn.default.input} ${cn.default.inputPreset}`,disabled:!!u.trim(),children:[(0,t.jsx)("option",{value:"pi",children:"pi"}),(0,t.jsx)("option",{value:"claude",children:"Claude Code"}),(0,t.jsx)("option",{value:"codex",children:"Codex"}),(0,t.jsx)("option",{value:"cursor",children:"Cursor"}),(0,t.jsx)("option",{value:"generic",children:"Custom path"})]}),(0,t.jsx)("input",{value:l,onChange:e=>o(e.target.value),placeholder:"Name (defaults to preset)","aria-label":"Root name",className:`${cn.default.input} ${cn.default.inputName}`}),(0,t.jsx)("input",{value:u,onChange:e=>p(e.target.value),placeholder:"generic"===c?"/absolute/path/to/skills":"Optional explicit path (else preset)","aria-label":"Root path",className:cn.default.input})]}),(0,t.jsxs)("div",{className:cn.default.actionRow,children:[(0,t.jsx)("button",{type:"button",onClick:()=>void f(),disabled:null!==h,className:cn.default.primaryButton,children:"add"===h?"Adding…":"Add root"}),(0,t.jsx)("button",{type:"button",onClick:()=>r(!1),className:cn.default.ghostButton,children:"Cancel"})]})]}):(0,t.jsx)("button",{type:"button",onClick:()=>r(!0),className:cn.default.ghostButton,children:"+ Add skills root"})]})]})}function ci(e){let{projectId:n,projectTrusted:a,query:i,setQuery:s,results:r,searching:l,searched:o,installScope:c,setInstallScope:d,installing:p,onSearch:h,onInstall:m}=e;return(0,t.jsxs)("div",{className:`skills-market-panel ${cn.default.market}`,children:[(0,t.jsx)("div",{className:cn.default.marketTitle,children:"Marketplace"}),(0,t.jsxs)("div",{className:cn.default.searchRow,children:[(0,t.jsx)("input",{type:"search",value:i,onChange:e=>s(e.target.value),onKeyDown:e=>{"Enter"===e.key&&h()},placeholder:"Search skills.sh…","aria-label":"Search skills.sh",className:cn.default.input}),(0,t.jsxs)("select",{value:c,onChange:e=>d(e.target.value),"aria-label":"Install scope",className:`${cn.default.input} ${cn.default.inputScope}`,children:[(0,t.jsx)("option",{value:"global",children:"Global"}),(0,t.jsxs)("option",{value:"project",disabled:!n||!a,children:["Project",!a&&n?" (needs trust)":""]})]}),(0,t.jsxs)("button",{type:"button",onClick:()=>void h(),disabled:l||!i.trim(),className:cn.default.ghostButton,children:[(0,t.jsx)(u,{size:13,"aria-hidden":"true"})," ",l?"Searching…":"Search"]})]}),o&&0===r.length&&!l&&(0,t.jsxs)("div",{className:cn.default.empty,children:['No skills match "',i.trim(),'".']}),r.map(e=>(0,t.jsxs)("div",{className:cn.default.resultRow,children:[(0,t.jsx)("span",{className:cn.default.resultPackage,children:e.package}),e.installs&&(0,t.jsx)("span",{className:cn.default.resultInstalls,children:e.installs}),e.url&&(0,t.jsxs)("a",{href:e.url,target:"_blank",rel:"noreferrer",title:e.url,className:`${cn.default.link} ${cn.default.linkIcon}`,children:[(0,t.jsx)(sq,{size:13,"aria-hidden":"true"}),(0,t.jsxs)("span",{className:"sr-only",children:["Open ",e.package]})]}),(0,t.jsx)("button",{type:"button",disabled:null!==p,onClick:()=>void m(e.package),className:cn.default.installButton,"data-busy":p===e.package||void 0,children:p===e.package?"Installing…":"Install"})]},e.package))]})}function cs(e){let{installed:n,loading:a,updateKey:i,updates:s,checking:r,toggling:l,removing:o,onCheck:c,onUpdate:d,onToggle:u,onRemove:p}=e;return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:cn.default.sectionHeader,children:["Installed ",(0,t.jsx)("span",{className:cn.default.sectionCount,children:n.length})]}),a&&(0,t.jsx)("div",{className:cn.default.empty,children:"Loading…"}),!a&&0===n.length&&(0,t.jsx)("div",{className:cn.default.empty,children:"No installed skills yet — search the marketplace above."}),!a&&n.length>0&&(0,t.jsx)("div",{className:cn.default.stack,children:n.map(e=>{let n=e.install,a=i(n),h=s[a];return(0,t.jsx)("div",{className:cn.default.installedCard,children:(0,t.jsxs)("div",{className:cn.default.installedHead,children:[(0,t.jsxs)("div",{className:cn.default.installedIdentity,children:[(0,t.jsxs)("div",{className:cn.default.installedTitleRow,children:[(0,t.jsx)("strong",{className:cn.default.installedName,children:e.name}),(0,t.jsx)("span",{className:`skill-row-scope ${cn.default.badge}`,children:n.scope}),h?.state==="update-available"&&(0,t.jsx)("span",{className:cn.default.updateBadge,children:"Update available"})]}),e.description&&(0,t.jsx)("div",{className:cn.default.installedDescription,children:e.description}),(0,t.jsxs)("div",{className:cn.default.installedMeta,children:[(0,t.jsx)("span",{className:cn.default.mono,children:n.package}),n.versionHash&&(0,t.jsxs)("span",{className:cn.default.mono,children:["v",n.versionHash.slice(0,8)]}),n.skillsShUrl&&(0,t.jsxs)("a",{href:n.skillsShUrl,target:"_blank",rel:"noreferrer",className:cn.default.link,children:["skills.sh ",(0,t.jsx)(sq,{size:10,"aria-hidden":"true"})]})]})]}),(0,t.jsxs)("div",{className:cn.default.installedActions,children:[(0,t.jsx)("button",{type:"button",title:"Allow or block model invocation for this skill",onClick:()=>void u(e),disabled:l===e.relPath,className:cn.default.toggle,"data-disabled":e.disableModelInvocation||void 0,children:e.disableModelInvocation?"Disabled":"Enabled"}),(0,t.jsx)("button",{type:"button",title:"Check for updates",onClick:()=>void c(n),disabled:null!==r,className:cn.default.ghostButton,children:r===a?(0,t.jsx)(sY,{size:12,"aria-hidden":"true",className:"delivery-spinner"}):"Check"}),h?.state==="update-available"&&(0,t.jsx)("button",{type:"button",onClick:()=>void d(n),disabled:null!==r,className:`${cn.default.ghostButton} ${cn.default.warning}`,children:"Update"}),h?.state==="up-to-date"&&(0,t.jsx)("span",{className:cn.default.statusText,children:"Up to date"}),h?.state==="error"&&h.message&&(0,t.jsx)("span",{className:cn.default.statusError,title:h.message,children:h.message}),h?.state==="unsupported"&&(0,t.jsx)("span",{className:cn.default.statusText,title:h.message??"",children:"No updates"}),(0,t.jsx)("button",{type:"button",title:"Remove skill",onClick:()=>void p(e),disabled:null!==o,className:`${cn.default.ghostButton} ${cn.default.danger}`,children:o===e.relPath?"Removing…":(0,t.jsx)(m,{size:12,"aria-hidden":"true"})})]})]})},`${e.relPath}:${e.skillId}`)})})]})}function cr({local:e}){return 0===e.length?null:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:cn.default.sectionHeader,children:["Catalog ",(0,t.jsx)("span",{className:cn.default.sectionCount,children:e.length})]}),(0,t.jsx)("div",{className:cn.default.stack,children:e.map(e=>(0,t.jsxs)("div",{className:cn.default.catalogRow,children:[(0,t.jsx)("span",{className:cn.default.catalogName,children:e.name}),(0,t.jsx)("span",{className:cn.default.badge,children:e.sourceInfo.scope??"local"}),e.disableModelInvocation&&(0,t.jsx)("span",{className:cn.default.statusText,children:"invocation disabled"})]},`${e.relPath}:${e.skillId}`))})]})}function cl({diagnostics:e}){return 0===e.length?null:(0,t.jsxs)("div",{className:cn.default.diagnostics,children:[(0,t.jsx)("div",{className:cn.default.diagTitle,children:"Catalog diagnostics"}),(0,t.jsx)("div",{className:cn.default.diagList,children:e.map((e,n)=>(0,t.jsxs)("div",{className:cn.default.diagRow,"data-level":"skip"===e.level?"skip":void 0,children:["[",e.level,"] ",e.relPath?`${e.relPath}: `:"",e.message]},n))})]})}function co({projectId:e,setError:a}){let i=function(e,t){let[a,i]=(0,n.useState)([]),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)(!1),[c,d]=(0,n.useState)(!1),[u,p]=(0,n.useState)([]),h=(0,n.useCallback)(async()=>{d(!0);try{let n=e?`?projectID=${encodeURIComponent(e)}`:"",a=await (0,e3.apiFetch)(`/v1/skills${n}`);i(a.skills??[]),r(a.diagnostics??[]),o(!!a.projectResourcesLoaded);let s=await (0,e3.apiFetch)("/v1/skills/roots");p(s.items??[]),t(null)}catch(e){t(e instanceof Error?e.message:"Failed to load skills")}finally{d(!1)}},[e,t]);return(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void h(),0);return()=>window.clearTimeout(e)},[h]),{skills:a,setSkills:i,diagnostics:s,projectTrusted:l,loading:c,roots:u,setRoots:p,load:h}}(e,a),s=function(e,t,a){let[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(""),[o,c]=(0,n.useState)("pi"),[d,u]=(0,n.useState)(""),[p,h]=(0,n.useState)(null),{markSaving:m,markSaved:f}=oL(),g=(0,n.useCallback)(async()=>{h("add"),m();try{await (0,e3.apiFetch)("/v1/skills/roots",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({name:r.trim()||o,agentKind:d.trim()?"generic":o,path:d.trim()||void 0})}),l(""),u(""),s(!1),a(null),await t(),f()}catch(e){a(e instanceof Error?e.message:"Failed to add skill root")}finally{h(null)}},[r,o,d,a,t,m,f]);return{showRootForm:i,setShowRootForm:s,rootName:r,setRootName:l,rootPreset:o,setRootPreset:c,rootPath:d,setRootPath:u,rootBusy:p,addRoot:g,toggleRoot:(0,n.useCallback)(async n=>{h(n.id),m();try{let i=await (0,e3.apiFetch)(`/v1/skills/roots/${n.id}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({enabled:!n.enabled})});e(e=>e.map(e=>e.id===n.id?i:e)),a(null),await t(),f()}catch(e){a(e instanceof Error?e.message:"Toggle failed")}finally{h(null)}},[e,a,t,m,f]),removeRoot:(0,n.useCallback)(async n=>{if(await rx({title:`Stop reading skills from "${n.path}"?`,description:"Installed skills under this root are no longer discovered.",confirmLabel:"Stop reading",tone:"danger"})){h(n.id),m();try{await (0,e3.apiFetch)(`/v1/skills/roots/${n.id}`,{method:"DELETE"}),e(e=>e.filter(e=>e.id!==n.id)),a(null),await t(),f()}catch(e){a(e instanceof Error?e.message:"Remove failed")}finally{h(null)}}},[e,a,t,m,f])}}(i.setRoots,i.load,a),r=function(e,t,a,i){let[s,r]=(0,n.useState)(""),[l,o]=(0,n.useState)([]),[c,d]=(0,n.useState)(!1),[u,p]=(0,n.useState)(!1),[h,m]=(0,n.useState)("global"),[f,g]=(0,n.useState)(null),x=(0,n.useCallback)(async()=>{let e=s.trim();if(e){d(!0);try{let t=await (0,e3.apiFetch)(`/v1/skills/search?q=${encodeURIComponent(e)}&limit=20`);o(t.results??[]),p(!0),i(null)}catch(e){i(e instanceof Error?e.message:"Search failed")}finally{d(!1)}}},[s,i]),v=(0,n.useCallback)(async n=>{if("project"===h&&!t)return void i("Project resources must be trusted before installing project skills.");g(n);try{await (0,e3.apiFetch)("/v1/skills/install",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:n,scope:h,..."project"===h&&e?{projectId:e}:{}})}),i(null),o(e=>e.filter(e=>e.package!==n)),await a()}catch(e){i(e instanceof Error?e.message:"Install failed")}finally{g(null)}},[h,t,e,i,a]);return{query:s,setQuery:r,results:l,searching:c,searched:u,installScope:h,setInstallScope:m,installing:f,search:x,install:v}}(e,i.projectTrusted,i.load,a),l=function(e,t,a,i){let[s,r]=(0,n.useState)({}),[l,o]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[u,p]=(0,n.useState)(null),{markSaving:h,markSaved:m}=oL(),f=(0,n.useCallback)(e=>`${e.scope}\u0000${e.package}`,[]),g=(0,n.useCallback)(async t=>{o(f(t));try{let n=await (0,e3.apiFetch)("/v1/skills/check",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t.package,scope:t.scope,..."project"===t.scope&&e?{projectId:e}:{}})});r(e=>{let t={...e};for(let e of n.updates??[])t[f(e)]=e;return t}),i(null)}catch(e){i(e instanceof Error?e.message:"Update check failed")}finally{o(null)}},[e,i,f]),x=(0,n.useCallback)(async t=>{let n=f(t);o(n),h();try{await (0,e3.apiFetch)("/v1/skills/update",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({package:t.package,scope:t.scope,..."project"===t.scope&&e?{projectId:e}:{}})}),i(null),r(e=>{let t={...e};return delete t[n],t}),await a(),m()}catch(e){i(e instanceof Error?e.message:"Update failed")}finally{o(null)}},[e,i,f,a,h,m]);return{updateKey:f,updates:s,checking:l,toggling:c,removing:u,check:g,update:x,toggle:(0,n.useCallback)(async e=>{d(e.relPath),h();try{await (0,e3.apiFetch)(`/v1/skills/disabled/${e.relPath}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({disabled:!e.disableModelInvocation})}),t(t=>t.map(t=>t.relPath===e.relPath?{...t,disableModelInvocation:!e.disableModelInvocation}:t)),i(null),m()}catch(e){i(e instanceof Error?e.message:"Toggle failed")}finally{d(null)}},[t,i,h,m]),remove:(0,n.useCallback)(async e=>{if(await rx({title:`Remove the skill "${e.name}"?`,description:"The skill files are removed from the managed catalog.",confirmLabel:"Remove skill",tone:"danger"})){p(e.relPath),h();try{await (0,e3.apiFetch)(`/v1/skills/remove/${e.relPath}`,{method:"POST"}),t(t=>t.filter(t=>t.relPath!==e.relPath)),i(null),m()}catch(e){i(e instanceof Error?e.message:"Remove failed")}finally{p(null)}}},[t,i,h,m])}}(e,i.setSkills,i.load,a),o=i.skills.filter(e=>!!e.install),c=i.skills.filter(e=>!e.install);return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-skills-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-skills-heading",children:"Skills"}),(0,t.jsx)("p",{children:"Marketplace installs, catalog browsing, and per-skill invocation control."})]}),(0,t.jsx)(ca,{roots:i.roots,loading:i.loading,control:s}),(0,t.jsx)(ci,{projectId:e,projectTrusted:i.projectTrusted,query:r.query,setQuery:r.setQuery,results:r.results,searching:r.searching,searched:r.searched,installScope:r.installScope,setInstallScope:r.setInstallScope,installing:r.installing,onSearch:r.search,onInstall:r.install}),(0,t.jsx)(cs,{installed:o,loading:i.loading,updateKey:l.updateKey,updates:l.updates,checking:l.checking,toggling:l.toggling,removing:l.removing,onCheck:l.check,onUpdate:l.update,onToggle:l.toggle,onRemove:l.remove}),(0,t.jsx)(cr,{local:c}),(0,t.jsx)(cl,{diagnostics:i.diagnostics})]})}function cc({configured:e,missing:n}){let a=(0,f.useT)();return e?(0,t.jsx)("span",{className:"settings-models-dot settings-models-dot-ok",role:"img","aria-label":a("settings.models.credentialConfigured"),title:a("settings.models.credentialConfigured")}):n?(0,t.jsx)("span",{className:"settings-models-dot settings-models-dot-missing",role:"img","aria-label":a("settings.models.credentialMissing"),title:a("settings.models.credentialMissing")}):null}let cd=o("eye",[["path",{d:"M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0",key:"1nclc0"}],["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}]]),cu=o("eye-off",[["path",{d:"M10.733 5.076a10.744 10.744 0 0 1 11.205 6.575 1 1 0 0 1 0 .696 10.747 10.747 0 0 1-1.444 2.49",key:"ct8e1f"}],["path",{d:"M14.084 14.158a3 3 0 0 1-4.242-4.242",key:"151rxh"}],["path",{d:"M17.479 17.499a10.75 10.75 0 0 1-15.417-5.151 1 1 0 0 1 0-.696 10.75 10.75 0 0 1 4.446-5.143",key:"13bj9a"}],["path",{d:"m2 2 20 20",key:"1ooewy"}]]);function cp({value:e,onChange:a,placeholder:i,ariaLabel:s}){let[r,l]=(0,n.useState)(!1);return(0,t.jsxs)("span",{className:"settings-models-secret",children:[(0,t.jsx)("input",{type:r?"text":"password",value:e,placeholder:i,"aria-label":s,autoComplete:"off",spellCheck:!1,onChange:e=>a(e.target.value)}),(0,t.jsx)("button",{type:"button",className:"settings-models-secret-toggle",title:r?"Hide key":"Show key","aria-label":r?"Hide key":"Show key",onClick:()=>l(e=>!e),children:r?(0,t.jsx)(cu,{size:13,"aria-hidden":"true"}):(0,t.jsx)(cd,{size:13,"aria-hidden":"true"})})]})}function ch(e){let t=e.trim();return 0===t.length?0===e.length?void 0:"keyBlank":/[^\x21-\x7E]/.test(t)||/^[A-Za-z_][A-Za-z0-9_]*=/.test(t)||t.startsWith('"')&&t.endsWith('"')||t.startsWith("'")&&t.endsWith("'")?"keyIllegalCharacters":void 0}async function cm(e){for(let t of(await (0,e3.apiFetch)("/v1/provider-profiles",{method:"POST",body:JSON.stringify({key:e.key,name:e.name,providerType:e.providerType,baseUrl:e.baseUrl,apiKey:e.apiKey||void 0})}),e.models)){let n=String(t.id??"").trim();0!==n.length&&await (0,e3.apiFetch)("/v1/model-profiles",{method:"POST",body:JSON.stringify({providerId:e.key,modelName:n,..."string"==typeof t.name&&t.name.length>0?{displayName:t.name}:{},contextWindow:"number"==typeof t.contextWindow?t.contextWindow:131072,maxOutputTokens:"number"==typeof t.maxTokens?t.maxTokens:16384,supportsToolUse:!0})})}}function cf(e){if(void 0===e)return;let t=Array.isArray(e)?e.map(e=>"object"!=typeof e||null===e||Array.isArray(e)?{}:e):[],n=new Set;for(let[e,a]of t.entries()){let t=a.id,i="string"==typeof t?t.trim():void 0;if(void 0===i||0===i.length)return{index:e,key:"modelIdRequired"};if(n.has(i))return{index:e,key:"modelIdDuplicate"};n.add(i);let s=a.name;if(void 0!==s&&("string"!=typeof s||0===s.length))return{index:e,key:"modelNameInvalid"};let r=a.contextWindow;if(void 0!==r&&("number"!=typeof r||!Number.isInteger(r)||r<=0))return{index:e,key:"modelContextInvalid"};let l=a.maxTokens;if(void 0!==l&&("number"!=typeof l||!Number.isInteger(l)||l<=0))return{index:e,key:"modelMaxTokensInvalid"}}}function cg(e){return{id:e.modelName,...e.displayName?{name:e.displayName}:{},...e.contextWindow?{contextWindow:e.contextWindow}:{},...e.maxOutputTokens?{maxTokens:e.maxOutputTokens}:{}}}function cx({probe:e,existingIds:a,onAdopt:i,onError:s,disabled:r,blockedReason:l}){let o=(0,f.useT)(),[c,d]=(0,n.useState)(!1),[u,p]=(0,n.useState)(null),[h,g]=(0,n.useState)(!1),[x,v]=(0,n.useState)(new Set),y=!!(e.baseUrl&&e.baseUrl.length>0),b=l??(y?void 0:o("settings.models.fetchNeedsBaseUrl")),k=async()=>{g(!0),p(null);try{let t=await (0,e3.apiFetch)("/v1/provider-profiles/discover-models",{method:"POST",body:JSON.stringify({baseUrl:e.baseUrl||void 0,apiKey:e.apiKey||void 0})})??[];if(0===t.length)return void s?.(o("settings.models.fetchEmpty"));let n=new Set(a);p(t),v(new Set(t.filter(e=>!n.has(e.modelName)).map(e=>e.modelName))),d(!0)}catch(e){s?.(e.message)}finally{g(!1)}},j=()=>{d(!1),p(null)},w=null!==u&&u.length>0&&u.every(e=>x.has(e.modelName));return M(c&&null!==u,j),(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",className:"settings-models-link",disabled:r||h||!y||void 0!==l,title:b,onClick:()=>{k()},children:h?o("settings.models.fetching"):o("settings.models.fetchModels")}),c&&u&&(0,t.jsx)("div",{className:"settings-overlay",role:"dialog","aria-modal":"true","aria-label":o("settings.models.fetchTitle"),children:(0,t.jsxs)("div",{className:"project-create-dialog settings-models-fetch",children:[(0,t.jsxs)("div",{className:"project-create-header",children:[(0,t.jsx)("span",{children:o("settings.models.fetchTitle")}),(0,t.jsx)("button",{type:"button",className:"follow-up-close","aria-label":o("settings.models.close"),title:o("settings.models.close"),onClick:j,children:(0,t.jsx)(m,{size:14,"aria-hidden":"true"})})]}),(0,t.jsxs)("div",{className:"project-create-form",children:[(0,t.jsx)("p",{className:"settings-models-hint",children:o("settings.models.fetchDescription")}),(0,t.jsx)("div",{className:"settings-models-fetch-actions",children:(0,t.jsx)("button",{type:"button",className:"settings-models-link",onClick:()=>{u&&v(w?new Set:new Set(u.map(e=>e.modelName)))},children:o(w?"settings.models.fetchDeselectAll":"settings.models.fetchSelectAll")})}),(0,t.jsx)("ul",{className:"settings-models-candidates",children:u.map(e=>(0,t.jsx)("li",{className:"settings-models-candidate",children:(0,t.jsxs)("label",{className:"settings-models-candidate-label",children:[(0,t.jsx)("input",{type:"checkbox",checked:x.has(e.modelName),onChange:()=>{v(t=>{let n=new Set(t);return n.delete(e.modelName)||n.add(e.modelName),n})}}),(0,t.jsx)("span",{className:"settings-models-candidate-id",children:e.modelName})]})},e.modelName))}),(0,t.jsxs)("div",{className:"project-create-actions",children:[(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:j,children:o("settings.models.cancel")}),(0,t.jsx)("button",{type:"button",className:"secondary-btn",onClick:()=>{u&&(i(u.filter(e=>x.has(e.modelName)).map(cg)),j())},children:o("settings.models.fetchAdopt")})]})]})]})})]})}let cv=/^(\d+(?:\.\d+)?)([km])?$/i,cy={k:1e3,m:1e6};function cb(e,t){let n=e[t];return"string"==typeof n?n:""}function ck({open:e}){return(0,t.jsx)(j,{size:14,className:"model-editor-chevron","data-open":e||void 0,"aria-hidden":"true"})}function cj(){return(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:(0,t.jsx)("path",{d:"M2.5 4h11M6.5 4V2.5h3V4M4 4l.7 9a1 1 0 001 .9h4.6a1 1 0 001-.9L12 4M6.5 6.8v4.4M9.5 6.8v4.4",stroke:"currentColor",strokeWidth:"1.3",strokeLinecap:"round",strokeLinejoin:"round"})})}function cw(){return(0,t.jsx)("svg",{width:"14",height:"14",viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:(0,t.jsx)("path",{d:"M8 3v10M3 8h10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}function cN({models:e,onChange:a,overridden:i,onReset:s,disabled:r,probe:l,probeBlocked:o,onFetchError:c}){let d=(0,f.useT)(),[u,p]=(0,n.useState)(()=>new Set),[h,m]=(0,n.useState)(()=>new Map),g=(e,t)=>`${String(e)}:${t}`,x=(t,n)=>{a(e.map((e,a)=>{if(a!==t)return e;let i=new Set(Object.entries(n).filter(([,e])=>void 0===e||""===e).map(([e])=>e));return Object.fromEntries(Object.entries({...e,...n}).filter(([e])=>!i.has(e)))}))},v=(e,t,n)=>{m(a=>new Map(a).set(g(e,t),n)),x(e,{[t]:function(e){let t=e.trim();if(0===t.length)return;let n=cv.exec(t);if(null===n)return NaN;let a=n[2]?.toLowerCase(),i="k"===a||"m"===a?cy[a]:1,s=Number(n[1])*i,r=Math.round(s);return 1e-6>Math.abs(s-r)?r:s}(n)})},y=(e,t,n)=>{let a,i=h.get(g(t,n));if(void 0!==i)return i;let s="number"==typeof(a=e[n])?a:void 0;return void 0===s?"":!Number.isInteger(s)||s<=0?String(s):s%cy.m==0?`${String(s/cy.m)}M`:s%cy.k==0?`${String(s/cy.k)}K`:String(s)},b=e=>("string"==typeof e.id?e.id:"").trim();return(0,t.jsxs)("section",{className:"settings-models-catalog","aria-label":d("settings.models.models"),children:[(0,t.jsxs)("div",{className:"settings-models-list-head",children:[(0,t.jsxs)("div",{className:"settings-models-catalog-heading",children:[(0,t.jsx)("span",{className:"settings-models-catalog-title",children:d("settings.models.models")}),void 0!==i&&(0,t.jsx)("span",{className:"settings-models-catalog-meta",children:i?d("settings.models.modelsCustomized"):d("settings.models.modelsInherited")})]}),!0===i&&void 0!==s&&(0,t.jsx)("button",{type:"button",className:"settings-models-link",disabled:r,onClick:s,children:d("settings.models.resetModels")}),void 0!==l&&(0,t.jsx)(cx,{probe:l,existingIds:e.map(b),onAdopt:t=>{let n=new Map(e.map(e=>[b(e),e]));for(let e of t)n.set(b(e),n.get(b(e))??e);a([...n.values()])},onError:c,disabled:r,blockedReason:o})]}),0===e.length&&(0,t.jsx)("p",{className:"settings-models-catalog-empty",children:d("settings.models.modelsEmpty")}),e.map((n,i)=>(0,t.jsxs)("div",{className:"settings-models-entry",children:[(0,t.jsxs)("div",{className:"settings-models-entry-row",children:[(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:cb(n,"id"),placeholder:d("settings.models.modelId"),"aria-label":`${d("settings.models.modelId")} ${i+1}`,disabled:r,onChange:e=>{x(i,{id:e.target.value})}}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:cb(n,"name"),placeholder:d("settings.models.modelName"),"aria-label":`${d("settings.models.modelName")} ${i+1}`,disabled:r,onChange:e=>{x(i,{name:""===e.target.value?void 0:e.target.value})}}),(0,t.jsx)("button",{type:"button",className:"settings-models-icon","aria-label":`${d("settings.models.modelAdvanced")} ${i+1}`,"aria-expanded":u.has(i),title:d("settings.models.modelAdvanced"),onClick:()=>{p(e=>{let t=new Set(e);return t.delete(i)||t.add(i),t})},children:(0,t.jsx)(ck,{open:u.has(i)})}),(0,t.jsx)("button",{type:"button",className:"settings-models-icon settings-models-icon-danger","aria-label":`${d("settings.models.removeModel")} ${i+1}`,title:d("settings.models.removeModel"),disabled:r,onClick:()=>{a(e.filter((e,t)=>t!==i)),p(e=>{let t=new Set;for(let n of e)n<i?t.add(n):n>i&&t.add(n-1);return t}),m(e=>((e,t)=>{let n=new Map;for(let[a,i]of e){let e=Number(a.slice(0,a.indexOf(":")));e!==t&&n.set(e>t?a.replace(/^\d+/,String(e-1)):a,i)}return n})(e,i))},children:(0,t.jsx)(cj,{})})]}),u.has(i)&&(0,t.jsxs)("div",{className:"settings-models-entry-advanced",children:[(0,t.jsxs)("label",{className:"settings-models-entry-field",children:[(0,t.jsx)("span",{className:"settings-models-entry-field-label",children:d("settings.models.contextWindow")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",inputMode:"numeric",value:y(n,i,"contextWindow"),placeholder:"256K","aria-label":`${d("settings.models.contextWindow")} ${i+1}`,disabled:r,onChange:e=>{v(i,"contextWindow",e.target.value)}})]}),(0,t.jsxs)("label",{className:"settings-models-entry-field",children:[(0,t.jsx)("span",{className:"settings-models-entry-field-label",children:d("settings.models.maxTokens")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",inputMode:"numeric",value:y(n,i,"maxTokens"),placeholder:"32K","aria-label":`${d("settings.models.maxTokens")} ${i+1}`,disabled:r,onChange:e=>{v(i,"maxTokens",e.target.value)}})]})]})]},i)),(0,t.jsxs)("button",{type:"button",className:"settings-models-add-model",disabled:r,onClick:()=>{a([...e,{id:""}])},children:[(0,t.jsx)(cw,{}),d("settings.models.addModel")]})]})}let c_=/^[a-z][a-z0-9]*(?:-[a-z0-9]+)*$/,cC=["openai-compatible","anthropic"];function cS({taken:e,onClose:a,refresh:i,setError:s,onSaved:r}){let l,o=(0,f.useT)(),[c,d]=(0,n.useState)(""),[u,p]=(0,n.useState)(""),[h,m]=(0,n.useState)(""),[g,x]=(0,n.useState)(cC[0]),[v,y]=(0,n.useState)(""),[b,k]=(0,n.useState)([]),[j,w]=(0,n.useState)(!1),[N,_]=(0,n.useState)(void 0),C=c.length>0&&!c_.test(c),S=e.includes(c),I=cf(b),P=ch(v),T=v.trim(),M=c.length>0&&!C&&!S&&h.trim().length>0&&b.length>0&&void 0===I&&void 0===P;async function R(){w(!0),_(void 0);try{await cm({key:c,name:u.trim()||c,providerType:g,baseUrl:h.trim(),apiKey:T||void 0,models:b}),s(null),r?.(u.trim()||c),await i(),a(!0)}catch(e){_(e.message)}finally{w(!1)}}return void 0!==N||M||C||S||void 0!==P||(0===c.length?l=o("settings.models.customRouteHint"):0===h.trim().length?l=o("settings.models.customNeedsBaseUrl"):0===b.length?l=o("settings.models.customNeedsModels"):void 0!==I&&(l=`${o("settings.models.model")} ${I.index+1}: ${o(`settings.models.${I.key}`)}`)),(0,t.jsxs)("div",{className:"settings-row provider-settings-row settings-models-editor",children:[(0,t.jsx)("div",{className:"settings-models-editor-header",children:(0,t.jsx)("span",{className:"settings-models-editor-title",children:o("settings.models.customTitle")})}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:o("settings.models.customRoute")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:c,placeholder:"acme-gateway",disabled:j,"aria-label":o("settings.models.customRoute"),onChange:e=>{d(e.target.value)}}),C||S?(0,t.jsx)("p",{className:"settings-models-error",children:o(C?"settings.models.customRouteInvalid":"settings.models.customRouteTaken")}):(0,t.jsx)("p",{className:"settings-models-hint",children:o("settings.models.customRouteHint")})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:o("settings.models.customDisplayName")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:u,placeholder:0===c.length?o("settings.models.customDisplayName"):c,disabled:j,"aria-label":o("settings.models.customDisplayName"),onChange:e=>{p(e.target.value)}})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:o("settings.models.baseUrl")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:h,placeholder:"https://gateway.example/v1",disabled:j,"aria-label":o("settings.models.baseUrl"),onChange:e=>{m(e.target.value)}})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:o("settings.models.customApi")}),(0,t.jsx)("select",{className:"settings-models-input settings-models-select",value:g,disabled:j,"aria-label":o("settings.models.customApi"),onChange:e=>{x(e.target.value)},children:cC.map(e=>(0,t.jsx)("option",{value:e,children:e},e))})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:o("settings.models.keyInput")}),(0,t.jsx)(cp,{value:v,onChange:y,placeholder:o("settings.models.keyPlaceholder"),ariaLabel:o("settings.models.keyInput")}),void 0===P?null:(0,t.jsx)("p",{className:"settings-models-error",children:o(`settings.models.${P}`)})]}),(0,t.jsx)(cN,{models:b,onChange:k,disabled:j,probe:{baseUrl:h.trim(),apiKey:T},probeBlocked:void 0!==P?o(`settings.models.${P}`):void 0,onFetchError:_}),void 0!==N?(0,t.jsx)("p",{className:"settings-models-error",children:N}):null,void 0===l?null:(0,t.jsx)("p",{className:"settings-models-hint",children:l}),(0,t.jsxs)("div",{className:"settings-models-editor-actions",children:[(0,t.jsx)("button",{type:"button",className:"secondary-btn",disabled:j,onClick:()=>a(!1),children:o("settings.models.cancel")}),(0,t.jsx)("button",{type:"button",className:"settings-models-primary",disabled:j||!M,onClick:()=>{R()},children:o(j?"settings.models.creating":"settings.models.create")})]})]})}function cI({open:e,providerName:n,busy:a,failure:i,onCancel:s,onConfirm:r}){let l=(0,f.useT)();if(M(e,s,{dismissOnEscape:!a}),!e)return null;let o=l("settings.models.deleteTitle",{provider:n}),c=l("settings.models.deleteDescriptionWithCredential",{provider:n}),d=l("settings.models.deleteConfirm",{provider:n}),u=l("settings.models.deleting",{provider:n});return(0,t.jsx)("div",{className:"settings-overlay",role:"dialog","aria-modal":"true","aria-label":o,children:(0,t.jsxs)("div",{className:"project-create-dialog",children:[(0,t.jsxs)("div",{className:"project-create-header",children:[(0,t.jsx)("span",{children:o}),(0,t.jsx)("button",{type:"button",className:"follow-up-close","aria-label":l("settings.models.close"),title:l("settings.models.close"),onClick:s,children:(0,t.jsx)(m,{size:14,"aria-hidden":"true"})})]}),(0,t.jsxs)("div",{className:"project-create-form",children:[(0,t.jsx)("p",{className:"settings-delete-description",children:c}),i&&(0,t.jsx)("p",{className:"settings-delete-error",children:i}),(0,t.jsxs)("div",{className:"project-create-actions",children:[(0,t.jsx)("button",{type:"button",className:"secondary-btn",disabled:a,onClick:s,children:l("settings.models.cancel")}),(0,t.jsx)("button",{type:"button",className:"project-create-submit",disabled:a,onClick:r,children:a?u:d})]})]})]})})}function cP(e,t){let n=e[t];return"string"==typeof n&&n.trim().length>0?n.trim():void 0}function cT(e,t){let n=e[t];return"number"==typeof n?n:void 0}async function cM(e){for(let t of e.toDelete)await (0,e3.apiFetch)(`/v1/model-profiles/${encodeURIComponent(t)}`,{method:"DELETE"});for(let{id:t,input:n}of e.toUpdate)await (0,e3.apiFetch)(`/v1/model-profiles/${encodeURIComponent(t)}`,{method:"PUT",body:JSON.stringify(n)});for(let t of e.toCreate)await (0,e3.apiFetch)("/v1/model-profiles",{method:"POST",body:JSON.stringify(t)})}function cR({provider:e,models:a,creating:i,hideTitle:s,onClose:r,refresh:l,setError:o,onSaved:c}){let d=(0,f.useT)(),[u,p]=(0,n.useState)(""),[h,m]=(0,n.useState)(e.baseUrl??""),[g,x]=(0,n.useState)(e.name??""),[v,y]=(0,n.useState)(()=>i?[]:a.map(e=>({id:e.modelName,...e.displayName&&e.displayName!==e.modelName?{name:e.displayName}:{},contextWindow:e.contextWindow,maxTokens:e.maxOutputTokens}))),[b,k]=(0,n.useState)(!1),[j,w]=(0,n.useState)(void 0),N=ch(u),_=cf(v),C=u.trim(),S=a.map(e=>({id:e.id,modelName:e.modelName,displayName:e.displayName,contextWindow:e.contextWindow,maxOutputTokens:e.maxOutputTokens}));async function I(){k(!0),w(void 0);try{if(i)await cm({key:e.id,name:g.trim()||e.name,providerType:e.providerType,baseUrl:h.trim()||e.baseUrl,apiKey:C||void 0,models:v});else{await (0,e3.apiFetch)(`/v1/provider-profiles/${encodeURIComponent(e.id)}`,{method:"PUT",body:JSON.stringify({name:g.trim()||void 0,baseUrl:h.trim()||void 0,apiKey:C||void 0})});let t=function(e,t,n,a=131072,i=16384){let s={toCreate:[],toDelete:[],toUpdate:[]},r=new Map(t.map(e=>[e.modelName,e])),l=new Set;for(let t of n){var o,c;let n=cP(t,"id");if(void 0===n)continue;l.add(n);let d=r.get(n);if(void 0===d){s.toCreate.push({providerId:e,modelName:n,...void 0===cP(t,"name")?{}:{displayName:cP(t,"name")},contextWindow:cT(t,"contextWindow")??a,maxOutputTokens:cT(t,"maxTokens")??i,supportsToolUse:!0});continue}o=t,c=d,(cP(o,"name")!==(c.displayName&&c.displayName!==c.modelName?c.displayName:void 0)||cT(o,"contextWindow")!==c.contextWindow||cT(o,"maxTokens")!==c.maxOutputTokens)&&s.toUpdate.push({id:d.id,input:{displayName:cP(t,"name")??null,contextWindow:cT(t,"contextWindow")??null,maxOutputTokens:cT(t,"maxTokens")??null}})}for(let e of t)l.has(e.modelName)||s.toDelete.push(e.id);return s}(e.id,S,v);await cM(t)}o(null),c?.(g.trim()||e.name),await l(),r(!0)}catch(e){w(e.message)}finally{k(!1)}}let P=b||void 0!==N||void 0!==_,T=d(e.credentialConfigured?"settings.models.keyStored":"settings.models.keyPlaceholder");return(0,t.jsxs)("div",{className:"settings-row provider-settings-row settings-models-editor",children:[!s&&(0,t.jsxs)("div",{className:"settings-models-editor-header",children:[(0,t.jsx)("span",{className:"settings-models-editor-title",children:e.name}),e.name!==e.id&&(0,t.jsx)("span",{className:"settings-models-editor-route",children:e.id})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:d("settings.models.keyInput")}),(0,t.jsx)(cp,{value:u,onChange:p,placeholder:T,ariaLabel:d("settings.models.keyInput")}),void 0===N?null:(0,t.jsx)("p",{className:"settings-models-error",children:d(`settings.models.${N}`)})]}),(0,t.jsxs)("details",{className:"settings-models-customized",children:[(0,t.jsx)("summary",{className:"settings-models-customized-summary",children:d("settings.models.customized")}),(0,t.jsxs)("div",{className:"settings-models-customized-body",children:[e.custom&&(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:d("settings.models.customDisplayName")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:g,disabled:b,"aria-label":d("settings.models.customDisplayName"),onChange:e=>{x(e.target.value)}})]}),(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:d("settings.models.baseUrl")}),(0,t.jsx)("input",{className:"settings-models-input",type:"text",value:h,disabled:b,placeholder:e.baseUrl||d("settings.models.baseUrlDefault"),"aria-label":d("settings.models.baseUrl"),onChange:e=>{m(e.target.value)}})]}),(0,t.jsx)(cN,{models:v,onChange:y,disabled:b,probe:{baseUrl:h.trim(),apiKey:C},probeBlocked:void 0!==N?d(`settings.models.${N}`):void 0,onFetchError:w})]})]}),void 0!==j?(0,t.jsx)("p",{className:"settings-models-error",children:j}):null,(0,t.jsxs)("div",{className:"settings-models-editor-actions",children:[(0,t.jsx)("button",{type:"button",className:"secondary-btn",disabled:b,onClick:()=>r(!1),children:d("settings.models.cancel")}),(0,t.jsx)("button",{type:"button",className:"settings-models-primary",disabled:P,onClick:()=>{I()},children:d(b?i?"settings.models.creating":"settings.models.applying":i?"settings.models.create":"settings.models.apply")})]})]})}function cE({size:e=14}){return(0,t.jsx)("svg",{width:e,height:e,viewBox:"0 0 16 16",fill:"none","aria-hidden":!0,children:(0,t.jsx)("path",{d:"M8 3v10M3 8h10",stroke:"currentColor",strokeWidth:"1.5",strokeLinecap:"round"})})}function cA({providers:e,models:a,refresh:i,setError:s}){let r=(0,f.useT)(),{markSaving:l,markSaved:o}=oL(),[c,d]=(0,n.useState)(null),[u,p]=(0,n.useState)(!1),[h,m]=(0,n.useState)(!1),[g,x]=(0,n.useState)(null),[v,y]=(0,n.useState)(!1),[b,k]=(0,n.useState)(void 0),[j,w]=(0,n.useState)(null),[N,_]=(0,n.useState)(()=>new Set),C=e.some(e=>e.credentialConfigured),S=e.filter(e=>e.directory),I=u?e.find(e=>e.directory&&e.id===c)??null:null,P=e=>{w(e),o()},T=async()=>{if(null!==g&&!v){y(!0),k(void 0),l();try{await (0,e3.apiFetch)(`/v1/provider-profiles/${encodeURIComponent(g.id)}`,{method:"DELETE"}),s(null),x(null),await i(),o()}catch(e){k(e.message)}finally{y(!1)}}};return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-models-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-models-heading",children:r("settings.models.title")}),(0,t.jsx)("p",{children:r("settings.models.intro")})]}),null!==j&&(0,t.jsx)("p",{className:"settings-models-saved",role:"status","aria-live":"polite",children:r("settings.models.savedProvider",{provider:j})}),(0,t.jsx)("ul",{className:"settings-models-rows",children:e.map(e=>{if(!C&&e.directory&&!N.has(e.id))return(0,t.jsx)("li",{className:"settings-models-setupcard",children:(0,t.jsx)(cR,{provider:e,models:[],creating:!0,refresh:i,setError:s,onSaved:P,onClose:()=>{_(t=>new Set([...t,e.id]))}})},e.id);let n=!u&&c===e.id;return(0,t.jsxs)("li",{className:"settings-models-rowcard",children:[(0,t.jsxs)("div",{className:"settings-models-rowhead",children:[(0,t.jsxs)("span",{className:"settings-models-rowidentity",children:[(0,t.jsx)("span",{className:"settings-models-rowname",children:e.name}),e.custom?(0,t.jsx)("span",{className:"settings-models-rowtag",children:r("settings.models.customTag")}):null,(0,t.jsx)(cc,{configured:e.credentialConfigured,missing:!e.credentialConfigured})]}),(0,t.jsxs)("span",{className:"settings-models-rowactions",children:[(0,t.jsx)("button",{type:"button",className:"settings-models-btn","aria-label":r("settings.models.editProvider",{provider:e.name}),onClick:()=>{w(null),m(!1),p(!1),d(n?null:e.id)},children:r("settings.models.edit")}),e.directory?null:(0,t.jsx)("button",{type:"button",className:"settings-models-btn settings-models-danger","aria-label":r("settings.models.removeProvider",{provider:e.name}),onClick:()=>{w(null),k(void 0),x(e)},children:r("settings.models.remove")})]})]}),n&&(0,t.jsx)(cR,{provider:e,models:a.filter(t=>t.providerId===e.id),creating:e.directory,refresh:i,setError:s,onSaved:P,onClose:()=>{d(null)}})]},e.id)})}),(0,t.jsxs)("div",{className:"settings-models-addblock",children:[null!==I&&(0,t.jsxs)("div",{className:"settings-models-addcard",children:[(0,t.jsxs)("div",{className:"settings-models-field",children:[(0,t.jsx)("span",{className:"settings-models-fieldlabel",children:r("settings.models.provider")}),(0,t.jsx)("select",{className:"settings-models-input settings-models-select",value:I.id,"aria-label":r("settings.models.provider"),onChange:e=>{d(e.target.value)},children:S.map(e=>(0,t.jsx)("option",{value:e.id,children:e.name},e.id))})]}),(0,t.jsx)(cR,{provider:I,models:[],creating:!0,hideTitle:!0,refresh:i,setError:s,onSaved:P,onClose:()=>{p(!1),d(null)}},I.id)]}),h&&(0,t.jsx)("div",{className:"settings-models-addcard",children:(0,t.jsx)(cS,{taken:e.map(e=>e.id),refresh:i,setError:s,onSaved:P,onClose:e=>{m(!1),e&&i()}})}),null===I&&!h&&(0,t.jsxs)("div",{className:"settings-models-addactions",children:[(0,t.jsxs)("button",{type:"button",className:"settings-models-addbutton",disabled:0===S.length,onClick:()=>{w(null),m(!1),p(!0),d(S[0]?.id??null)},children:[(0,t.jsx)(cE,{}),r("settings.models.add")]}),(0,t.jsxs)("button",{type:"button",className:"settings-models-addbutton",onClick:()=>{w(null),p(!1),d(null),m(!0)},children:[(0,t.jsx)(cE,{}),r("settings.models.customAdd")]})]})]}),(0,t.jsx)(cI,{open:null!==g,providerName:g?.name??"",busy:v,failure:b,onCancel:()=>{v||(x(null),k(void 0))},onConfirm:()=>{T()}})]})}let c$=[{kind:"tool",title:"Tool policy",description:"Permission mode and allowed local execution boundaries.",defaultConfig:'{"mode":"restricted","allowedTools":["read","ls","grep","find"],"allowedExecutables":["git","rg"],"maxTimeoutSeconds":300}'},{kind:"turn",title:"Turn routing",description:"Model routing candidates and upgrade thresholds.",defaultConfig:'{"mode":"context_upgrade","threshold":0.7,"candidateModelProfileIds":[]}'},{kind:"vision",title:"Vision",description:"Native image handling and descriptor fallback boundaries.",defaultConfig:'{"mode":"reject","maxImageBytes":10485760,"maxPixels":40000000}'}];function cz({policies:e,refresh:n,setError:a}){let{markSaving:i,markSaved:s}=oL();async function r(e,t){e.preventDefault();let r=e.currentTarget,l=new FormData(r);try{let e=JSON.parse(String(l.get("config")||"{}"));i(),await (0,e3.apiFetch)("/v1/policy-profiles",{method:"POST",body:JSON.stringify({name:l.get("name"),kind:t,config:e})}),r.reset(),a(null),await n(),s()}catch(e){a(e.message)}}async function l(e){i();try{await (0,e3.apiFetch)(`/v1/policy-profiles/${encodeURIComponent(e)}/default`,{method:"PUT"}),a(null),await n(),s()}catch(e){a(e.message)}}async function o(e){if(await rx({title:`Deactivate policy “${e.name}” v${e.version}?`,description:"Existing Runs keep their frozen policy. New Runs will no longer select it as the default.",confirmLabel:"Deactivate",tone:"danger"})){i();try{await (0,e3.apiFetch)(`/v1/policy-profiles/${encodeURIComponent(e.id)}`,{method:"DELETE"}),a(null),await n(),s()}catch(e){a(e.message)}}}return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-policies-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-policies-heading",children:"Policies"}),(0,t.jsx)("p",{children:"Immutable versioned execution, routing, and image handling configuration."})]}),c$.map(n=>(0,t.jsx)(cF,{...n,policies:e,onSubmit:r,onDefault:l,onDeactivate:o},n.kind))]})}function cF({kind:e,title:n,description:a,policies:i,defaultConfig:s,onSubmit:r,onDefault:l,onDeactivate:o}){return(0,t.jsxs)(oq,{title:n,description:a,children:[(0,t.jsxs)("form",{className:"settings-form policy-form",onSubmit:t=>r(t,e),children:[(0,t.jsxs)("label",{children:["Name",(0,t.jsx)("input",{name:"name",required:!0})]}),(0,t.jsxs)("label",{children:["Configuration JSON",(0,t.jsx)("textarea",{name:"config",required:!0,defaultValue:s})]}),(0,t.jsx)("button",{type:"submit",children:"Create version"})]}),(0,t.jsx)(oU,{children:i.filter(t=>t.kind===e).map(e=>(0,t.jsx)(oB,{title:e.name,meta:`v${e.version} \xb7 ${String(e.config.mode??"configured")}`,actions:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{className:"secondary-btn",disabled:"active"!==e.status,onClick:()=>l(e.id),children:"Use as default"}),(0,t.jsx)("button",{className:"secondary-btn",type:"button",disabled:"active"!==e.status,title:"Deactivate policy","aria-label":`Deactivate policy ${e.name} version ${e.version}`,onClick:()=>o(e),children:(0,t.jsx)(A,{size:14,"aria-hidden":"true"})})]})},e.id))})]})}let cL=o("info",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 16v-4",key:"1dtifu"}],["path",{d:"M12 8h.01",key:"e9boi3"}]]),cD=o("save",[["path",{d:"M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z",key:"1c8476"}],["path",{d:"M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7",key:"1ydtos"}],["path",{d:"M7 3v4a1 1 0 0 0 1 1h7",key:"t51u73"}]]);function cO(e){return Promise.all([(0,e3.apiFetch)("/v1/prompt-templates").catch(()=>null),e?(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/prompt-templates`).catch(()=>null):Promise.resolve(null)])}function cq({projectId:e,setError:a}){let[i,s]=(0,n.useState)(null),[r,l]=(0,n.useState)(null),[o,c]=(0,n.useState)(void 0),[d,u]=(0,n.useState)(!1),[p,h]=(0,n.useState)(""),[m,f]=(0,n.useState)(""),[g,x]=(0,n.useState)(""),[v,y]=(0,n.useState)(""),[b,k]=(0,n.useState)(!1),{markSaving:j,markSaved:w}=oL(),[N,_]=(0,n.useState)(null),[C,I]=(0,n.useState)(""),[T,M]=(0,n.useState)(""),[R,E]=(0,n.useState)(""),[A,$]=(0,n.useState)(null),[z,F]=(0,n.useState)(null),L=(0,n.useCallback)(async()=>{try{let[t,n]=await cO(e);s(t),l(n),c(e),a(null)}catch{c(e),a("Failed to load prompt templates")}},[e,a]);(0,n.useEffect)(()=>{let t=!1;return cO(e).then(([n,i])=>{t||(s(n),l(i),c(e),a(null))}).catch(()=>{t||(c(e),a("Failed to load prompt templates"))}),()=>{t=!0}},[e,a]);let D=r??i;async function O(e){if(e.preventDefault(),p.trim()&&v.trim()){k(!0),j();try{await (0,e3.apiFetch)("/v1/prompt-templates",{method:"POST",body:JSON.stringify({name:p.trim(),description:m.trim(),argumentHint:g.trim(),body:v})}),h(""),f(""),x(""),y(""),u(!1),await L(),w()}catch(e){a(e.message)}finally{k(!1)}}}async function q(e){j();try{await (0,e3.apiFetch)(`/v1/prompt-templates/${encodeURIComponent(e)}`,{method:"DELETE"}),F(null),await L(),w()}catch(e){a(e.message)}}async function B(e){if(R.trim()){k(!0),j();try{await (0,e3.apiFetch)(`/v1/prompt-templates/${encodeURIComponent(e)}`,{method:"PUT",body:JSON.stringify({description:C.trim(),argumentHint:T.trim(),body:R})}),_(null),await L(),w()}catch(e){a(e.message)}finally{k(!1)}}}if(o!==e&&!i)return(0,t.jsx)("div",{className:"settings-tab-section",children:(0,t.jsx)("p",{children:"Loading…"})});let U=[...i?.diagnostics??[],...r?.diagnostics??[]],H=i?.globalRecoveryMode??!1;return(0,t.jsxs)("section",{className:"settings-tab-section","aria-labelledby":"settings-templates-heading",children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("h2",{id:"settings-templates-heading",children:"Prompt templates"}),(0,t.jsx)("p",{children:"Manage slash-command prompt templates across builtin, settings, global, and project sources."})]}),U.length>0&&(0,t.jsx)("div",{className:"templates-diag-banner",role:"status",children:U.map((e,n)=>(0,t.jsxs)("div",{className:`templates-diag ${"warning"===e.level?"diag-warn":"diag-info"}`,children:[(0,t.jsx)("span",{className:"templates-diag-icon",children:"warning"===e.level?(0,t.jsx)(sO,{size:14}):(0,t.jsx)(cL,{size:14})}),(0,t.jsxs)("span",{className:"templates-diag-msg",children:[(0,t.jsx)("code",{children:e.code})," ",e.message]})]},n))}),D&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("header",{className:"templates-section-header",children:(0,t.jsxs)("h3",{children:["Effective templates ",e?"(project)":"(global)"]})}),0===D.templates.length?(0,t.jsxs)("p",{className:"templates-empty",children:["No templates available. Create a global template below or add markdown files to your project's ",(0,t.jsx)("code",{children:".ennote/prompts/"})," directory."]}):(0,t.jsx)("ul",{className:"templates-list",children:D.templates.map(e=>(0,t.jsxs)("li",{className:"template-row",children:[(0,t.jsxs)("span",{className:"template-name",children:["/",e.name]}),e.argumentHint&&(0,t.jsx)("span",{className:"template-hint",children:e.argumentHint}),(0,t.jsx)("span",{className:"template-source source-{t.source}",children:e.source}),(0,t.jsx)("span",{className:"template-desc",children:e.description})]},e.name))})]}),(0,t.jsxs)("header",{className:"templates-section-header",children:[(0,t.jsx)("h3",{children:"My global templates"}),!H&&(0,t.jsxs)("button",{type:"button",className:"settings-btn",onClick:()=>u(!d),children:[(0,t.jsx)(S,{size:14})," New"]})]}),H&&(0,t.jsxs)("div",{className:"templates-diag diag-warn templates-diag-block",children:[(0,t.jsx)(sO,{size:14}),(0,t.jsx)("span",{children:"Global store is in recovery mode. Delete some entries to restore normal operation. Create is disabled."})]}),d&&(0,t.jsxs)("form",{className:"template-edit-form",onSubmit:O,children:[(0,t.jsxs)("label",{children:["Name ",(0,t.jsx)("input",{value:p,onChange:e=>h(e.target.value),placeholder:"my-command",required:!0,disabled:b})]}),(0,t.jsxs)("label",{children:["Description ",(0,t.jsx)("input",{value:m,onChange:e=>f(e.target.value),placeholder:"Optional",disabled:b})]}),(0,t.jsxs)("label",{children:["Argument hint ",(0,t.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:"<path> [focus]",disabled:b})]}),(0,t.jsxs)("label",{children:["Body ",(0,t.jsx)("textarea",{value:v,onChange:e=>y(e.target.value),rows:4,placeholder:"Template body with $1, $@, etc.",required:!0,disabled:b})]}),(0,t.jsxs)("div",{className:"template-form-actions",children:[(0,t.jsxs)("button",{type:"submit",className:"settings-btn primary",disabled:b||!p.trim()||!v.trim(),children:[(0,t.jsx)(cD,{size:14})," ",b?"Saving…":"Create"]}),(0,t.jsx)("button",{type:"button",className:"settings-btn",onClick:()=>u(!1),children:"Cancel"})]})]}),i?.globalTemplates&&i.globalTemplates.length>0&&(0,t.jsx)("ul",{className:"templates-list",children:i.globalTemplates.map(e=>(0,t.jsxs)("li",{className:`template-row ${!e.valid?"invalid":""}`,children:[(0,t.jsxs)("span",{className:"template-name",children:["/",e.name]}),e.argumentHint&&(0,t.jsx)("span",{className:"template-hint",children:e.argumentHint}),e.valid?(0,t.jsx)("span",{className:"template-desc",children:e.description}):(0,t.jsxs)("span",{className:"template-desc diag-text",children:[e.diagnostic?.code,": ",e.diagnostic?.message]}),(0,t.jsx)("div",{className:"template-actions",children:e.editable&&N===e.name?(0,t.jsxs)("div",{className:"template-edit-form template-edit-form-inline",children:[e.valid&&(0,t.jsxs)("div",{className:"template-edit-readonly",children:["Name: ",e.name]}),(0,t.jsxs)("label",{children:["Description ",(0,t.jsx)("input",{value:C,onChange:e=>I(e.target.value),disabled:b})]}),(0,t.jsxs)("label",{children:["Argument hint ",(0,t.jsx)("input",{value:T,onChange:e=>M(e.target.value),disabled:b})]}),(0,t.jsxs)("label",{children:["Body ",(0,t.jsx)("textarea",{value:R,onChange:e=>E(e.target.value),rows:4,disabled:b})]}),(0,t.jsxs)("div",{className:"template-form-actions",children:[(0,t.jsxs)("button",{type:"button",className:"settings-btn primary",onClick:()=>B(e.name),disabled:b||!R.trim(),children:[(0,t.jsx)(cD,{size:14})," ",b?"Saving…":e.valid?"Update":"Repair"]}),(0,t.jsx)("button",{type:"button",className:"settings-btn",onClick:()=>_(null),children:"Cancel"})]})]}):e.editable?z===e.name?(0,t.jsxs)("span",{className:"template-confirm",children:[(0,t.jsxs)("span",{children:["Delete /",e.name,"?"]}),(0,t.jsx)("button",{type:"button",className:"settings-btn danger",onClick:()=>q(e.name),disabled:b,children:"Delete"}),(0,t.jsx)("button",{type:"button",className:"settings-btn",onClick:()=>F(null),children:"Cancel"})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("button",{type:"button",className:"settings-btn",onClick:()=>{_(e.name),e.valid?(0,e3.apiFetch)(`/v1/prompt-templates/${encodeURIComponent(e.name)}`).then(e=>{I(e.description),M(e.argumentHint),E(e.body)}).catch(()=>{}):(I(""),M(""),E(""))},children:e.valid?"Edit":"Repair"}),(0,t.jsx)("button",{type:"button",className:"settings-btn danger",onClick:()=>F(e.name),children:(0,t.jsx)(P,{size:14})})]}):(0,t.jsx)("span",{className:"template-manual-cleanup",children:"Manual cleanup required in $ENNOTE_HOME/prompts/"})}),e.valid&&A===e.name&&(0,t.jsx)(cB,{name:e.name,onClose:()=>$(null)})]},e.name))}),(!i?.globalTemplates||0===i.globalTemplates.length)&&!H&&(0,t.jsx)("p",{className:"templates-empty",children:"No global templates yet. Create one above."})]})}function cB({name:e,onClose:a}){let[i,s]=(0,n.useState)(null);return((0,n.useEffect)(()=>{(0,e3.apiFetch)(`/v1/prompt-templates/${encodeURIComponent(e)}`).then(e=>s(e.body)).catch(()=>s("Failed to load"))},[e]),null===i)?(0,t.jsx)("div",{className:"template-body-preview",children:"Loading…"}):(0,t.jsxs)("div",{className:"template-body-preview",children:[(0,t.jsx)("pre",{children:i}),(0,t.jsx)("button",{type:"button",className:"settings-btn",onClick:a,children:"Close"})]})}function cU(e){switch(e){case"general":return(0,t.jsx)(p,{size:15,"aria-hidden":"true"});case"models":return(0,t.jsx)(oT,{size:15,"aria-hidden":"true"});case"policies":return(0,t.jsx)(oA,{size:15,"aria-hidden":"true"});case"context":return(0,t.jsx)(oM,{size:15,"aria-hidden":"true"});case"templates":return(0,t.jsx)(es,{size:15,"aria-hidden":"true"});case"mcp":return(0,t.jsx)(oE,{size:15,"aria-hidden":"true"});case"skills":return(0,t.jsx)(X,{size:15,"aria-hidden":"true"});case"packs":return(0,t.jsx)(oR,{size:15,"aria-hidden":"true"})}}function cH({open:e,onClose:n,initialTab:a,providers:i,models:s,policies:r,session:l,refresh:o,error:c,setError:d,onSessionUpdated:u,projectId:p}){return e?(0,t.jsx)("div",{className:"settings-dialog-backdrop",onClick:e=>{e.target===e.currentTarget&&n()},children:(0,t.jsx)(oF,{children:(0,t.jsx)(cW,{initialTab:a,onClose:n,providers:i,models:s,policies:r,session:l,refresh:o,error:c,setError:d,onSessionUpdated:u,projectId:p},a??"general")})}):null}function cW({onClose:e,initialTab:a,providers:i,models:s,policies:r,session:l,refresh:o,error:c,setError:d,onSessionUpdated:p,projectId:h}){let g=(0,f.useT)(),{markError:x}=oL(),v=(0,n.useCallback)(e=>{d(e),e&&x(e)},[d,x]),[y,b]=(0,n.useState)(a??"general"),[k,j]=(0,n.useState)(""),w=(0,n.useRef)(null),N=(0,n.useRef)(null),_=(0,n.useRef)(null);M(!0,e),(0,n.useEffect)(()=>{let e=window.requestAnimationFrame(()=>N.current?.focus()),t=e=>{if((e.metaKey||e.ctrlKey)&&"k"===e.key.toLowerCase()){e.preventDefault(),_.current?.focus();return}if("Tab"!==e.key||!w.current)return;let t=Array.from(w.current.querySelectorAll('button:not(:disabled), input:not(:disabled), select:not(:disabled), textarea:not(:disabled), [href], [tabindex]:not([tabindex="-1"])'));if(0===t.length)return;let n=t[0],a=t[t.length-1];e.shiftKey&&document.activeElement===n?(e.preventDefault(),a.focus()):e.shiftKey||document.activeElement!==a||(e.preventDefault(),n.focus())};return window.addEventListener("keydown",t),()=>{window.cancelAnimationFrame(e),window.removeEventListener("keydown",t)}},[]);let C=[{id:"general",label:"General",description:"Appearance and theme",icon:cU("general")},{id:"models",label:"Models",description:"Providers, API keys, and model profiles",icon:cU("models")},{id:"policies",label:"Policies",description:"Tool permission and routing policies",icon:cU("policies")},{id:"context",label:"Context & session",description:l?"Session defaults and compaction":"Compaction policy defaults",icon:cU("context")},{id:"templates",label:"Templates",description:"Slash-command prompt templates",icon:cU("templates")},{id:"mcp",label:"MCP",description:"MCP servers and project bindings",icon:cU("mcp")},{id:"skills",label:"Skills",description:"Skill catalog, marketplace, and updates",icon:cU("skills")},{id:"packs",label:"Packs",description:"Agent Packs: inspect, install, and remove",icon:cU("packs")}],S=k.trim().toLowerCase(),I=""===S?C:C.filter(e=>`${e.label} ${e.description}`.toLowerCase().includes(S));return(0,t.jsx)("div",{ref:w,className:"settings-dialog-shell",role:"dialog","aria-modal":"true","aria-label":"Settings",children:(0,t.jsxs)("div",{className:"settings-dialog-body",children:[(0,t.jsxs)("div",{className:"settings-dialog-tabs",role:"tablist","aria-label":"Settings sections",children:[(0,t.jsx)("div",{id:"settings-dialog-title",className:"settings-dialog-navtitle",children:"Settings"}),(0,t.jsxs)("label",{className:"settings-dialog-search",children:[(0,t.jsx)(u,{size:14,"aria-hidden":"true"}),(0,t.jsx)("input",{ref:_,type:"text",value:k,placeholder:g("settings.search.placeholder"),"aria-label":g("settings.search.aria"),onChange:e=>(e=>{j(e);let t=e.trim().toLowerCase();if(""===t)return;let n=C.filter(e=>`${e.label} ${e.description}`.toLowerCase().includes(t));n.length>0&&!n.some(e=>e.id===y)&&b(n[0].id)})(e.target.value),onKeyDown:e=>{if("Escape"===e.key&&""!==k&&!e.nativeEvent.isComposing){e.preventDefault(),e.stopPropagation(),j("");return}"Enter"===e.key&&I.length>0&&(e.preventDefault(),b(I[0].id))}}),""!==k&&(0,t.jsx)("button",{type:"button","aria-label":g("settings.search.clear"),onClick:()=>j(""),children:(0,t.jsx)(m,{size:12,"aria-hidden":"true"})})]}),0===I.length&&(0,t.jsx)("div",{className:"settings-dialog-empty",children:g("settings.search.empty",{query:k.trim()})}),I.map((e,n)=>{let a=y===e.id;return(0,t.jsxs)("button",{type:"button",onClick:()=>b(e.id),onKeyDown:e=>{let t=null;if(("ArrowRight"===e.key||"ArrowDown"===e.key)&&(t=(n+1)%I.length),("ArrowLeft"===e.key||"ArrowUp"===e.key)&&(t=(n-1+I.length)%I.length),"Home"===e.key&&(t=0),"End"===e.key&&(t=I.length-1),null===t)return;e.preventDefault();let a=I[t];b(a.id),window.requestAnimationFrame(()=>document.getElementById(`settings-tab-${a.id}`)?.focus())},className:`settings-dialog-tab ${a?"active":""}`,role:"tab",id:`settings-tab-${e.id}`,"aria-selected":a,"aria-controls":`settings-panel-${e.id}`,children:[(0,t.jsx)("span",{className:"settings-tab-icon",children:e.icon}),(0,t.jsx)("span",{className:"settings-tab-label",children:e.label})]},e.id)})]}),(0,t.jsxs)("div",{className:"settings-dialog-content",children:[(0,t.jsxs)("div",{className:"settings-dialog-header",children:[(0,t.jsxs)("div",{className:"settings-dialog-actions",children:[(0,t.jsx)(oD,{}),(0,t.jsx)("span",{id:"settings-dialog-current",className:"settings-dialog-current",children:C.find(e=>e.id===y)?.label})]}),(0,t.jsx)("button",{ref:N,type:"button",className:"settings-dialog-close",title:"Close settings","aria-label":"Close settings",onClick:e,children:(0,t.jsx)(m,{size:14,"aria-hidden":"true"})})]}),c&&(0,t.jsxs)("div",{className:"error-bar",role:"alert",children:[(0,t.jsx)("span",{children:c}),(0,t.jsx)("button",{type:"button",onClick:()=>d(null),"aria-label":"Dismiss error",children:(0,t.jsx)(m,{size:15,"aria-hidden":"true"})})]}),(0,t.jsxs)("div",{className:"settings-dialog-panel",role:"tabpanel",id:`settings-panel-${y}`,"aria-labelledby":`settings-tab-${y}`,children:["general"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(o1,{})}),"models"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(cA,{providers:i,models:s,refresh:o,setError:v})}),"policies"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(cz,{policies:r,refresh:o,setError:v})}),"context"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(oH,{policies:r,models:s,session:l,refresh:o,setError:v,onSessionUpdated:p})}),"templates"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(cq,{projectId:h,setError:v})}),"mcp"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(ct,{projectId:h,setError:v})}),"skills"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(co,{projectId:h,setError:v})}),"packs"===y&&(0,t.jsx)("div",{className:"settings-tab-scroll",children:(0,t.jsx)(o5,{setError:v})})]})]})]})})}var cV=e.i(85026);function cK({settingsOpen:e,settingsTab:n,onCloseSettings:a,providers:i,models:s,policies:r,session:l,projectId:o,error:c,refresh:d,setError:u,onSessionUpdated:p}){let{createProjectOpen:h,createProjectBusy:m,confirmCreateProject:f,cancelCreateProject:g}=(0,cV.useWorkspace)();return(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(cH,{open:e,onClose:a,initialTab:n,providers:i,models:s,policies:r,session:l,refresh:d,error:c,setError:u,onSessionUpdated:p,projectId:o}),(0,t.jsx)(rv,{}),h&&(0,t.jsx)(oP,{busy:m,onCreate:f,onClose:g})]})}var cG=e.i(48686);function cJ({workerUnreachable:e}){return e?(0,t.jsx)("div",{className:cG.default.banner,role:"status","data-testid":"offline-banner",children:"Worker unreachable — Ennote is read-only until it returns."}):null}function cY({initialWidth:e,minWidth:t,maxWidth:a,storageKey:i,direction:s="right",resolveStored:r,cssVariable:l}){let[o,c]=(0,n.useState)(e),[d,u]=(0,n.useState)(!1),p=(0,n.useRef)(e),h=(0,n.useCallback)(e=>{let n=Math.max(t,Math.min(a,e));c(n),p.current=n,l&&document.documentElement.style.setProperty(l,`${n}px`)},[t,a,l]);(0,n.useEffect)(()=>{let e=window.requestAnimationFrame(()=>{let e=p.current;try{let n=localStorage.getItem(i),s=n?Number.parseInt(n,10):NaN;Number.isFinite(s)&&(r?e=r(s):s>=t&&s<=a&&(e=s))}catch{}h(e)});return()=>window.cancelAnimationFrame(e)},[i,t,a,r,h]);let m=(0,n.useCallback)(()=>{u(!0)},[]),f=(0,n.useCallback)(e=>{let t="left"===s?-1:1;h(p.current+e*t)},[h,s]);return{beginResize:m,endResize:(0,n.useCallback)(()=>{u(!1);try{localStorage.setItem(i,String(p.current))}catch{}},[i]),isResizing:d,resizeBy:f,width:o}}let cQ="ennote:sidebar:collapsed-projects";function cZ(){try{let e=window.localStorage.getItem(cQ);return e?new Set(JSON.parse(e)):new Set}catch{return new Set}}let cX="ennote-onboarding-done";function c0(){let[e,t]=(0,n.useState)([]),[a,i]=(0,n.useState)([]),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)(null),[c,d]=(0,n.useState)(!0),u=(0,n.useRef)(0),p=(0,n.useRef)(null),h=(0,n.useCallback)(async()=>{p.current?.abort();let e=new AbortController;p.current=e;let n=++u.current;try{let[a,s,l]=await Promise.all([(0,e3.apiFetch)("/v1/provider-profiles",{signal:e.signal}),(0,e3.apiFetch)("/v1/model-profiles",{signal:e.signal}),(0,e3.apiFetch)("/v1/policy-profiles",{signal:e.signal})]);if(e.signal.aborted||u.current!==n)return;t(a),i(s),r(l),o(null)}catch(t){e.signal.aborted||u.current!==n||o(t.message)}finally{e.signal.aborted||u.current!==n||d(!1)}},[]);return(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void h(),0);return()=>{window.clearTimeout(e),p.current?.abort()}},[h]),{providers:e,models:a,policies:s,error:l,loading:c,setError:o,refresh:h}}let c1={provider_configuration_invalid:"The provider runtime configuration is invalid.",provider_credential_unavailable:"The configured credential could not be resolved.",provider_authentication_failed:"The provider rejected the configured credential.",provider_model_not_found:"The configured model was not found by the provider.",provider_rate_limited:"The provider rate limit was reached. Try again later.",provider_request_timeout:"The provider did not respond before the timeout.",provider_request_rejected:"The provider rejected the model request.",provider_unavailable:"The provider is currently unavailable.",model_protocol_error:"The provider returned an invalid response.",model_stream_interrupted:"The provider response was interrupted.",context_overflow:"The request exceeds the model context window.",context_overflow_after_compaction:"The request still exceeds the context window after compaction.",context_overflow_in_run:"The active run exceeded the model context window."};function c2(e){let t="string"==typeof e?e:"";return c1[t]??(t?`The run failed (${t}).`:"The run failed.")}function c4(e,t){return e instanceof Error&&e.message?e.message:"string"==typeof e&&e.trim()?e:(console.warn("[ennote] non-Error rejection captured",e),t)}function c5(e){let t=e.toolCallId??e.id??e.recordId;return null!=t?String(t):`event-${e.callIndex??"unknown"}`}let c3={optimistic:[],settled:new Set};function c6(e,t){switch(t.type){case"queue":return{...e,optimistic:[...e.optimistic,t.row]};case"settle":{if(!t.id)return e;let n=new Set(e.settled);return n.add(t.id),{optimistic:e.optimistic.filter(e=>e.id!==t.id),settled:n}}case"reset":return c3}}function c8(){return"u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}class c9 extends Error{}async function c7(e,t,n){let a=await (0,e3.apiResponse)(`/v1/runs/${encodeURIComponent(e)}/events`,{signal:n});if(!a.ok)throw Error(`HTTP ${a.status}`);let i=a.body?.getReader();if(!i)return!1;let s=new TextDecoder,r="";try{for(;;){let{done:e,value:n}=await i.read();if(e)break;let a=(r+=s.decode(n,{stream:!0})).split("\n");for(let e of(r=a.pop()??"",a)){let n=e.endsWith("\r")?e.slice(0,-1):e;if(!n.startsWith("data:"))continue;let a=JSON.parse(n.slice(5).trimStart());switch(a.type){case"context_compaction_started":t(sS("compacting"));break;case"context_compaction_retry_scheduled":t(sS("compaction_retry_wait",String(a.payload?.delayMs??0)));break;case"context_compaction_retry_started":t(sS("compaction_retry"));break;case"context_compaction_completed":t(sS("checkpoint_ready"));break;case"context_compaction_failed":throw new c9("Context compaction failed.");case"context_compaction_cancelled":case"run_cancelled":throw new c9("Context compaction was cancelled.");case"run_succeeded":return!0;case"run_failed":throw new c9(c2(a.payload?.errorCode))}}}}finally{i.releaseLock()}return!1}async function de(e,t,n,a,i,s,r,l,o){let c=new Headers;o.value&&c.set("Last-Event-ID",o.value);let d=await (0,e3.apiResponse)(`/v1/runs/${encodeURIComponent(e)}/events`,{signal:s,headers:c});if(!d.ok)throw Error(`HTTP ${d.status}`);let u=d.body?.getReader();if(!u)return!1;let p=new TextDecoder,h="",{assistants:m,toolDeltas:f,toolOutputs:g}=l,x=null,v=!1,{usageByIteration:y}=l;function b(e){let t=m.get(e)??{text:"",thinking:""};return m.set(e,t),t}function k(n){let a=b(n);t({id:`${e}-assistant-${n}`,role:"assistant",text:a.text,thinking:a.thinking})}function j(n,a,i){let s=c5(n),r=n.arguments&&"object"==typeof n.arguments&&!Array.isArray(n.arguments)?n.arguments:void 0;t({id:`${e}-tool-${s}`,role:"tool",kind:"tool",toolCallId:s,toolName:String(n.toolName??n.name??"tool"),text:String(n.content??n.reason??i),arguments:r,argumentsFragment:"string"==typeof n.argumentsFragment?n.argumentsFragment:void 0,isError:!!n.isError||"failed"===a,toolState:a,runId:e})}try{for(;;){let{done:s,value:c}=await u.read();if(s)break;let d=(h+=p.decode(c,{stream:!0})).split("\n");for(let s of(h=d.pop()??"",d)){let c=s.endsWith("\r")?s.slice(0,-1):s;if(c.startsWith("id:")){let e=c.slice(3).trim();e&&(o.value=e);continue}if(c.startsWith("event:")){x=c.slice(6).trim(),v="live"===x;continue}if(c.startsWith(":")||!c.startsWith("data:"))continue;let d=JSON.parse(c.slice(5).trimStart()),u=v;v=!1;let p=d.payload??{},h="number"==typeof p.iteration?p.iteration:1;switch(d.type){case"usage_updated":{let e=p.usage;e&&function(e,t){y.set(e,{uncachedInputTokens:Number(t.uncachedInputTokens??0),cacheReadTokens:Number(t.cacheReadTokens??0),cacheWriteTokens:Number(t.cacheWriteTokens??0),outputTokens:Number(t.outputTokens??0),reasoningTokens:Number(t.reasoningTokens??0)});let n={uncachedInputTokens:0,cacheReadTokens:0,cacheWriteTokens:0,outputTokens:0,reasoningTokens:0};for(let e of y.values())n.uncachedInputTokens+=e.uncachedInputTokens,n.cacheReadTokens+=e.cacheReadTokens,n.cacheWriteTokens+=e.cacheWriteTokens,n.outputTokens+=e.outputTokens,n.reasoningTokens+=e.reasoningTokens;a(n)}(h,e);break}case"context_usage":p&&"number"==typeof p.contextWindow&&i(p);break;case"text_delta":case"thinking_delta":if(!u)break;"text_delta"===d.type?b(h).text+=String(p.text??""):b(h).thinking+=String(p.text??""),k(h);break;case"model_call_retry_scheduled":m.set(h,{text:"",thinking:""}),k(h),n(sS("model_retry",String(p.delayMs??0)));break;case"context_pruned":n(sS("preparing_context"));break;case"context_compaction_planned":n(sS("compaction_queued"));break;case"context_compaction_started":n(sS("compacting"));break;case"context_compaction_retry_scheduled":n(sS("compaction_retry_wait",String(p.delayMs??0)));break;case"context_compaction_completed":n(sS("checkpoint_ready"));break;case"run_context_compaction_planned":n(sS("preparing_run_context"));break;case"run_context_compaction_started":n(sS("compacting_run"));break;case"run_context_compaction_retry_scheduled":n(sS("run_compaction_retry",String(p.delayMs??0)));break;case"run_context_compaction_completed":n(sS("run_context_compacted"));break;case"run_context_compaction_failed":n(sS("run_compaction_skipped"));break;case"run_context_compaction_cancelled":n("");break;case"context_checkpoint_selected":n(sS("using_checkpoint"));break;case"output_truncated":n(sS(Number(p.partialToolCallCount??0)>0?"recovering_tool":"output_truncated"));break;case"tool_call_delta":{if(!u)break;let e=p.id?String(p.id):"";if(e&&l.finishedTools.has(e))break;let t=`${h}:${p.index??0}`,n=f.get(t)??{id:"",name:"tool",argumentsFragment:""};p.id&&(n.id=String(p.id)),p.name&&(n.name=String(p.name)),n.argumentsFragment+=String(p.argumentsFragment??""),f.set(t,n),j({...p,toolCallId:n.id||t,toolName:n.name,argumentsFragment:n.argumentsFragment},"pending","Collecting tool arguments…");break}case"child_progress":var w;if(!u)break;w={delegationGroupId:String(p.delegationGroupId??""),taskName:String(p.taskName??""),childRunId:String(p.childRunId??""),activity:String(p.activity??""),tokens:Number(p.tokens??0)},ry?.(w);break;case"tool_output_delta":{if(!u)break;let n=function(e){let t=e.toolCallId,n=e.stream,a=e.text;if("string"!=typeof t||""===t)return null;let i="string"==typeof n&&({stdout:!0,stderr:!0,progress:!0})[n]?n:null;if(!i||"string"!=typeof a)return null;let s=e.toolName;return void 0!==s&&"string"!=typeof s?null:{toolCallId:t,stream:i,text:a,...void 0===s?{}:{toolName:s}}}(p);if(!n)break;let a=n.toolCallId;if(l.finishedTools.has(a))break;let i=n.stream,s=n.text,r=g.get(a)??{text:"",name:""};n.toolName&&(r.name=n.toolName),"stderr"===i?r.text+=`[stderr] ${s}`:r.text+=s,g.set(a,r),t({id:`${e}-tool-${a}`,role:"tool",kind:"tool",toolCallId:a,...r.name?{toolName:r.name}:{},text:r.text,isError:!1,toolState:"running",runId:e});break}case"tool_call_started":{let e=c5(p);l.finishedTools.delete(e),l.toolOutputs.delete(e),n(sS("running_tool",String(p.toolName??"tool"))),j(p,"running","Running");break}case"tool_call_completed":{n(""),("delegate_tasks"===p.toolName||"delegate_heroes"===p.toolName)&&r.delegated();let e=c5(p);g.delete(e),l.finishedTools.add(e),j(p,p.isError?"failed":"completed","No output");break}case"tool_call_failed":{let e=c5(p);g.delete(e),l.finishedTools.add(e),j(p,"failed","Tool call failed.");break}case"tool_policy_denied":case"tool_policy_terminated":case"tool_call_skipped":l.finishedTools.add(c5(p)),j(p,String(p.reason??"").includes("approval_rejected")?"rejected":"failed","Tool call skipped.");break;case"model_route_selected":n(sS("using_model",String(p.apiModel??"selected model")));break;case"vision_fallback_started":n(sS("describing_image"));break;case"vision_fallback_completed":n(sS("image_ready"));break;case"approval_requested":n(sS("waiting_approval")),r.requested();break;case"approval_resolved":n(sS("resuming")),r.resolved();break;case"follow_up_consumed":{let e=String(p.queueItemId??"");e&&r.followUpConsumed(e);break}case"input_cancelled":{let e=String(p.queueItemId??"");e&&r.inputCancelled(e);break}case"run_succeeded":return n(sS("completed")),!0;case"run_cancelled":return n(sS("cancelled")),!0;case"run_interrupted":return n(sS("interrupted")),!0;case"run_failed":throw new c9(c2(p.errorCode))}}}}finally{u.releaseLock()}return!1}function dt(e,t,n){let a=e.steps[e.steps.length-1];for(let i of(a?.kind==="tool_batch"?a.activities.push(...t):e.steps.push({kind:"tool_batch",id:`batch-${t[0].id}`,activities:t}),t))n.set(i.toolCallId,i)}function dn(e,t,n){e.set(t,[...e.get(t)??[],n])}function da(e,t){return/approval[_ ]rejected/i.test(e)?"rejected":t?"failed":"completed"}class di{read;timer;dirty;constructor(e){this.read=e,this.timer=null,this.dirty=!1}markDirty(){this.dirty=!0,this.timer||(this.timer=setTimeout(()=>{this.timer=null,this.dirty=!1,this.read()},400))}flush(){this.cancelPending(),this.dirty=!1,this.read()}cancelPending(){this.timer&&(clearTimeout(this.timer),this.timer=null)}takeInterruptedRead(){return!!this.dirty&&(this.dirty=!1,!0)}replaceWindow(){this.cancelPending(),this.dirty=!1}}class ds{sessionId;dataBranchId;requestedBranchId;loaded=!1;canonical=[];checkpoints=[];transient=[];nextCursor;hasMore=!1;loading=!1;loadingOlder=!1;error=null;requestVersion=0;requestController=null;activeRun=null;pendingApproval=null;queuedInputs=[];delegationActive=!1;lastSeq=0;workerInstanceId=null;streamController=null;streamOpen=!1;reconnectTimer=null;reconnectAttempt=0;eventCursor;streamPaused=!1;disposed=!1;windowRefresh=new di(()=>this.refreshLatest());listeners=new Set;snapshot=null;constructor(e){this.sessionId=e}subscribe=e=>(this.listeners.add(e),()=>{this.listeners.delete(e)});getSnapshot=()=>(this.snapshot||(this.snapshot=this.buildSnapshot()),this.snapshot);getServerSnapshot=()=>(this.snapshot||(this.snapshot=this.buildSnapshot()),this.snapshot);ensureLoaded=e=>(this.requestedBranchId=e,this.openStream(),this.loaded&&this.dataBranchId===e)?this.windowRefresh.takeInterruptedRead()?this.refreshLatest():Promise.resolve():(this.resetForBranch(),this.loadInitial(e));loadOlder=async()=>{if(!this.loaded||!this.hasMore||!this.nextCursor||this.loadingOlder)return!1;this.requestVersion+=1;let e=this.requestVersion;this.requestController?.abort();let t=new AbortController;this.requestController=t,this.loadingOlder=!0,this.error=null,this.notify();try{let n,a=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/messages?limit=50&before=${encodeURIComponent(this.nextCursor)}`,{signal:t.signal});if(t.signal.aborted||this.requestVersion!==e)return!1;let i=a.messages??[],s=this.canonical,r=i.length>0?i[i.length-1].seq??0:0,l=s.length>0?s[0].seq??0:0;if(r>0&&l>0&&r+1!==l)return this.error="History window is out of order; re-open the session to re-sync.",!1;return this.canonical=(n=new Set,[...i,...s].filter(e=>!n.has(e.id)&&(n.add(e.id),!0))),this.nextCursor=a.nextCursor,this.hasMore=a.hasMore,!0}catch(n){return t.signal.aborted||this.requestVersion!==e||(this.error=n.message),!1}finally{t.signal.aborted||this.requestVersion!==e||(this.loadingOlder=!1),this.notify()}};refreshLatest=async()=>{if(this.disposed)return;this.requestVersion+=1;let e=this.requestVersion;this.requestController?.abort();let t=new AbortController;this.requestController=t,this.loadingOlder=!1;try{let[n,a]=await Promise.all([(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/messages?limit=50`,{signal:t.signal}),(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/compactions`,{signal:t.signal})]);if(t.signal.aborted||this.requestVersion!==e)return;let i=!this.loaded;this.canonical=i?n.messages??[]:function(e,t){if(0===e.length)return t;if(0===t.length)return e;let n=new Set(t.map(e=>e.id)),a=e.findIndex(e=>n.has(e.id));return a<0?t:[...e.slice(0,a),...t]}(this.canonical,n.messages??[]),this.checkpoints=a??[],i&&(this.nextCursor=n.nextCursor,this.hasMore=n.hasMore),this.dataBranchId=this.requestedBranchId,this.loaded=!0,this.loading=!1,this.transient=[],this.error=null}catch(n){t.signal.aborted||this.requestVersion!==e||(this.error=n.message)}finally{this.notify()}};appendTransient=e=>{this.transient.some(t=>t.id===e.id)||(this.transient=[...this.transient,e],this.notify())};upsertTransient=e=>{let t=this.transient.findIndex(t=>t.id===e.id);if(t<0)this.transient=[...this.transient,e];else{let n=[...this.transient];n[t]={...n[t],...e},this.transient=n}this.notify()};removeTransient=e=>{let t=this.transient.filter(t=>t.id!==e);t.length!==this.transient.length&&(this.transient=t,this.notify())};openStream=()=>{this.streamPaused=!1,this.disposed||this.streamOpen||this.streamController||this.openStreamInternal()};pauseStream=()=>{this.streamPaused=!0,this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.reconnectAttempt=0,this.windowRefresh.cancelPending(),this.streamController?.abort(),this.streamController=null,this.clearProjection(),this.streamOpen&&(this.streamOpen=!1,this.notify())};dispose=()=>{this.disposed=!0,this.requestController?.abort(),this.streamController?.abort(),this.reconnectTimer&&clearTimeout(this.reconnectTimer),this.reconnectTimer=null,this.windowRefresh.replaceWindow(),this.listeners.clear()};async openStreamInternal(){if(this.disposed)return;let e=new AbortController;this.streamController=e,this.streamOpen=!0,this.notify();try{let t={};this.eventCursor&&(t["Last-Event-ID"]=this.eventCursor),await (0,e3.apiEventStream)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/events`,e=>this.handleStreamFrame(e),{signal:e.signal,headers:t})}catch{}finally{this.streamController===e&&(this.streamController=null,this.streamOpen=!1,this.notify(),this.disposed||this.streamPaused||this.scheduleReconnect())}}handleStreamFrame(e){e.id&&(this.eventCursor=e.id),this.reconnectAttempt=0;let t=e.data;if(t&&"object"==typeof t)switch(t.type){case"subscribed":this.workerInstanceId=t.instanceId??null,this.lastSeq=t.lastSeq??0,this.applySnapshot(t.snapshot);break;case"snapshot":this.lastSeq=t.lastSeq??0,this.applySnapshot(t.snapshot);break;case"message_committed":this.lastSeq=Math.max(this.lastSeq,t.lastSeq??0),this.disposed||this.windowRefresh.markDirty();break;case"run_succeeded":case"run_failed":case"run_cancelled":case"run_interrupted":case"context_compaction_completed":case"run_context_compaction_completed":this.disposed||this.windowRefresh.flush()}}clearProjection(){(null!==this.activeRun||null!==this.pendingApproval||0!==this.queuedInputs.length||this.delegationActive)&&(this.activeRun=null,this.pendingApproval=null,this.queuedInputs=[],this.delegationActive=!1,this.notify())}applySnapshot(e){e&&(this.activeRun=e.activeRun??null,this.pendingApproval=e.pendingApproval??null,this.queuedInputs=e.queuedInputs??[],this.delegationActive=e.delegationActive??!1,e.checkpoints&&(this.checkpoints=e.checkpoints.map(e=>({id:e.id,status:e.status,reason:e.reason,summary:e.summary,reclaimedTokens:e.reclaimedTokens,firstKeptMessageId:e.firstKeptMessageId,sourceThroughMessageId:e.sourceThroughMessageId,baseLeafMessageId:e.baseLeafMessageId,createdAt:e.createdAt,promptVersion:e.promptVersion,summaryContractDigest:e.summaryContractDigest}))),this.notify())}scheduleReconnect(){if(this.disposed||this.streamPaused||this.reconnectTimer)return;let e=Math.min(1e3*2**this.reconnectAttempt,15e3);this.reconnectAttempt+=1,this.reconnectTimer=setTimeout(()=>{this.reconnectTimer=null,this.openStream()},e)}resetForBranch(){this.requestVersion+=1,this.requestController?.abort(),this.requestController=new AbortController,this.windowRefresh.replaceWindow(),this.dataBranchId=void 0,this.loaded=!1,this.canonical=[],this.checkpoints=[],this.transient=[],this.nextCursor=void 0,this.hasMore=!1,this.error=null,this.loading=!0,this.loadingOlder=!1,this.notify()}async loadInitial(e){let t=this.requestVersion,n=this.requestController;try{let[a,i]=await Promise.all([(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/messages?limit=50`,{signal:n.signal}),(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(this.sessionId)}/compactions`,{signal:n.signal})]);if(n.signal.aborted||this.requestVersion!==t)return;this.dataBranchId=e,this.canonical=a.messages??[],this.checkpoints=i??[],this.nextCursor=a.nextCursor,this.hasMore=a.hasMore,this.loaded=!0}catch(e){n.signal.aborted||this.requestVersion!==t||(this.error=e.message)}finally{n.signal.aborted||this.requestVersion!==t||(this.loading=!1),this.notify()}}buildSnapshot(){return{sessionId:this.sessionId,dataBranchId:this.dataBranchId,loaded:this.loaded,canonical:this.canonical,checkpoints:this.checkpoints,transient:this.transient,nextCursor:this.nextCursor,hasMore:this.hasMore,loading:this.loading,loadingOlder:this.loadingOlder,error:this.error,activeRun:this.activeRun,pendingApproval:this.pendingApproval,queuedInputs:this.queuedInputs,delegationActive:this.delegationActive,lastSeq:this.lastSeq,workerInstanceId:this.workerInstanceId,streamOpen:this.streamOpen}}notify(){for(let e of(this.snapshot=null,this.listeners))e()}}class dr{stores=new Map;order=[];getStore=e=>{let t=this.stores.get(e);return t||(t=new ds(e),this.stores.set(e,t),this.order.push(e),this.prune(8)),this.touch(e),t};has=e=>this.stores.has(e);disposeStore=e=>{let t=this.stores.get(e);t&&(t.dispose(),this.stores.delete(e));let n=this.order.indexOf(e);n>=0&&this.order.splice(n,1)};prune=e=>{for(;this.order.length>e;){let e=this.order.shift();void 0!==e&&this.disposeStore(e)}};touch(e){let t=this.order.indexOf(e);t>=0&&this.order.splice(t,1),this.order.push(e)}}let dl=new dr,dc={sessionId:"",dataBranchId:void 0,loaded:!1,canonical:[],checkpoints:[],transient:[],nextCursor:void 0,hasMore:!1,loading:!1,loadingOlder:!1,error:null,activeRun:null,pendingApproval:null,queuedInputs:[],delegationActive:!1,lastSeq:0,workerInstanceId:null,streamOpen:!1},dd=()=>()=>{},du=async()=>!1,dp=async()=>{},dh=()=>{},dm=()=>{},df=()=>{},dg={nodes:[],openTurn:null,calls:new Map,syntheticTurn:0};function dx(e){return"discuss"===e||"ask"===e||"auto"===e}function dv(e){return"object"==typeof e&&null!==e?e:void 0}let dy=new Set(["txt","md","mdx","json","yaml","yml","toml","csv","tsv","log","js","jsx","ts","tsx","py","r","go","rs","java","c","cpp","h","hpp","css","html","xml","sh","bash","sql"]);function db(){return"u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36)}function dk(e,t){let n=new Map(t.map(e=>[e.id,e.name]));return e.filter(e=>"active"===e.status).map(e=>({ref:`${n.get(e.providerId)??e.providerId}/${e.modelName}`,label:e.displayName||e.modelName,model:e}))}let dj=["room","reply","fresh","task_only"],dw={room:"Room",reply:"Reply",fresh:"Fresh",task_only:"Task only"},dN=["discuss","ask","auto"];function d_({models:e,providers:a,setError:i}){let s=(0,f.useT)(),r=(0,n.useMemo)(()=>dk(e,a),[e,a]),[l,o]=(0,n.useState)([]),[d,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(null),[g,x]=(0,n.useState)(""),[v,y]=(0,n.useState)(null),[b,k]=(0,n.useState)(!1),[j,w]=(0,n.useState)({id:"",name:""}),[N,_]=(0,n.useState)(!1),[C,I]=(0,n.useState)(null);M(null!==C,()=>I(null));let P=(0,n.useCallback)(async()=>{let e=await (0,e3.apiFetch)("/v1/global-heroes");return o(e),e},[]),T=(0,n.useCallback)(async e=>{y("loading"),p(e);try{m(await (0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(e)}`)),_(!1),I(null),i(null)}catch(e){m(null),i(e.message)}finally{y(null)}},[i]);(0,n.useEffect)(()=>{let e=!1,t=window.setTimeout(()=>{P().then(t=>{let n=t.find(e=>!e.error);!e&&n&&T(n.id)}).catch(t=>{e||i(t.message)})},0);return()=>{e=!0,window.clearTimeout(t)}},[T,P,i]);let R=async()=>{if(!r[0])return void i("Create an active model before creating a Hero.");let e=j.id.trim(),t=j.name.trim();if(e&&t){y("creating");try{var n;let a=await (0,e3.apiFetch)("/v1/global-heroes",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({document:(n=r[0].ref,{schemaVersion:1,handle:e,name:t,description:"",positioning:"",icon:"bot",color:"neutral",model:{ref:n,thinkingEffort:"default",fallbacks:[]},skills:[],authority:"read_only",permissionCeiling:"discuss",allowedTools:["read","ls","grep","find"],context:{defaultMode:"room",allowedModes:["room","fresh","task_only"],ownExecutionContinuity:"none"},delegation:{admission:"auto_within_budget",allowedCallerKinds:["host"],allowedStrategies:["single","parallel"],maxInvocationsPerParentRun:16,maxConcurrentInstances:16,budgetCeiling:{maxModelCalls:4,maxToolCalls:8,maxTotalTokens:2e4,maxOutputTokens:4e3,maxCostUsdMicros:1e5,maxWallTimeMs:12e4}},outputContract:"text-v1",maxLoopIterations:8,prompt:"Perform the requested work independently. Distinguish evidence from assumptions and report a concise result."})})});k(!1),w({id:"",name:""}),m(a),p(a.id),await P(),i(null)}catch(e){i(e.message)}finally{y(null)}}},E=async e=>{if(h&&!v){y("saving");try{let t=await (0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(h.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({expectedDigest:h.digest,document:e})});m(t),o(e=>e.map(e=>e.id===t.id?{...e,name:t.name,digest:t.digest,error:void 0}:e)),_(!1),I(null),i(null)}catch(e){_(!0),i(e.message)}finally{y(null)}}},A=async()=>{if(h)try{I(await (0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(h.id)}`))}catch(e){i(e.message)}},$=async()=>{if(h&&!v){y("publishing");try{await (0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(h.id)}/publish`,{method:"POST"}),i(null)}catch(e){i(e.message)}finally{y(null)}}},z=e=>{h&&m({...h,document:e(h.document)})},F=e=>{if(!h)return;let t=e(h.document);m({...h,document:t}),E(t)},L=l.filter(e=>`${e.name} ${e.id}`.toLowerCase().includes(g.trim().toLowerCase()));return(0,t.jsxs)("div",{className:`global-heroes ${d?"has-selection":""}`,children:[(0,t.jsxs)("aside",{className:"global-heroes-list",children:[(0,t.jsxs)("header",{children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("strong",{children:"Hero catalog"}),(0,t.jsxs)("span",{children:[l.length," global Heroes"]})]}),(0,t.jsx)("button",{type:"button",onClick:()=>k(e=>!e),"aria-label":"Add Hero",children:(0,t.jsx)(S,{size:18})})]}),b&&(0,t.jsxs)("div",{className:"global-hero-create",children:[(0,t.jsx)("input",{value:j.id,onChange:e=>w(t=>({...t,id:e.target.value})),placeholder:"hero-id"}),(0,t.jsx)("input",{value:j.name,onChange:e=>w(t=>({...t,name:e.target.value})),placeholder:"Hero name"}),(0,t.jsx)("button",{type:"button",onClick:()=>void R(),disabled:"creating"===v,children:"creating"===v?"Creating…":"Create"})]}),(0,t.jsxs)("label",{className:"global-hero-search",children:[(0,t.jsx)(u,{size:15}),(0,t.jsx)("input",{value:g,onChange:e=>x(e.target.value),placeholder:"Search Heroes"})]}),(0,t.jsxs)("div",{role:"listbox","aria-label":"Global Heroes",children:[L.map(e=>(0,t.jsxs)("button",{type:"button",role:"option","aria-selected":d===e.id,onClick:()=>void T(e.id),children:[(0,t.jsx)(c,{size:17}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:e.name}),(0,t.jsx)("code",{children:e.id}),e.error&&(0,t.jsx)("small",{children:e.error})]}),(0,t.jsx)(es,{size:14})]},e.id)),0===L.length&&(0,t.jsx)("div",{className:"heroes-empty",children:"No global Heroes"})]})]}),(0,t.jsxs)("section",{className:"global-hero-detail",children:[!h&&"loading"===v&&(0,t.jsxs)("div",{className:"heroes-detail-empty",children:[(0,t.jsx)(eZ,{className:"spin",size:18})," Loading Hero…"]}),!h&&"loading"!==v&&(0,t.jsxs)("div",{className:"heroes-detail-empty",children:[(0,t.jsx)(c,{size:26})," Select or create a Hero"]}),h&&(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("header",{className:"global-hero-commandbar",children:[(0,t.jsxs)("button",{type:"button",className:"global-hero-back",onClick:()=>{p(null),m(null)},children:[(0,t.jsx)(r6,{size:17})," Heroes"]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("strong",{children:h.document.name}),(0,t.jsx)("code",{children:h.path})]}),(0,t.jsxs)("div",{className:"global-hero-command-actions",children:[N?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)("span",{className:"hero-conflict-state",children:"File changed on disk"}),(0,t.jsx)("button",{type:"button",onClick:()=>void A(),children:"Diff"}),(0,t.jsx)("button",{type:"button",onClick:()=>void T(h.id),children:"Reload"})]}):(0,t.jsx)("span",{className:"saving"===v?"is-saving":"",children:"saving"===v?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eZ,{className:"spin",size:14})," Saving"]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Y,{size:14})," Saved"]})}),(0,t.jsx)("button",{type:"button",onClick:()=>void $(),disabled:!!v||N,children:"publishing"===v?"Publishing…":"Publish"})]})]}),(0,t.jsxs)("div",{className:"global-hero-form",children:[(0,t.jsxs)("section",{children:[(0,t.jsx)("h3",{children:"Identity"}),(0,t.jsxs)("div",{className:"global-hero-grid",children:[(0,t.jsxs)("label",{children:["Name",(0,t.jsx)("input",{value:h.document.name,onChange:e=>z(t=>({...t,name:e.target.value})),onBlur:()=>void E(h.document)})]}),(0,t.jsxs)("label",{children:["Handle",(0,t.jsx)("input",{value:h.document.handle,disabled:!0})]}),(0,t.jsxs)("label",{className:"wide",children:["Description",(0,t.jsx)("input",{value:h.document.description,onChange:e=>z(t=>({...t,description:e.target.value})),onBlur:()=>void E(h.document)})]})]})]}),(0,t.jsxs)("section",{children:[(0,t.jsx)("h3",{children:"Runtime"}),(0,t.jsxs)("div",{className:"global-hero-grid",children:[(0,t.jsxs)("label",{className:"wide",children:["Model",(0,t.jsx)("select",{value:h.document.model.ref,onChange:e=>F(t=>({...t,model:{...t.model,ref:e.target.value}})),children:r.map(e=>(0,t.jsxs)("option",{value:e.ref,children:[e.label," · ",e.ref]},e.ref))})]}),(0,t.jsxs)("label",{children:["Thinking",(0,t.jsx)("select",{value:h.document.model.thinkingEffort,onChange:e=>F(t=>({...t,model:{...t.model,thinkingEffort:e.target.value}})),children:["default","low","medium","high"].map(e=>(0,t.jsx)("option",{children:e},e))})]}),(0,t.jsxs)("label",{children:["Permission ceiling",(0,t.jsx)("select",{value:h.document.permissionCeiling,onChange:e=>F(t=>({...t,permissionCeiling:e.target.value})),children:dN.map(e=>(0,t.jsx)("option",{value:e,children:s(`permission.${e}`)},e))})]}),(0,t.jsxs)("label",{className:"wide",children:["Skills",(0,t.jsx)("input",{value:h.document.skills.map(e=>e.id).join(", "),onChange:e=>z(t=>({...t,skills:e.target.value.split(",").map(e=>e.trim()).filter(Boolean).map(e=>({id:e,mode:"available"}))})),onBlur:()=>void E(h.document),placeholder:"report-writing, code-review"})]})]})]}),(0,t.jsxs)("section",{children:[(0,t.jsx)("h3",{children:"Execution context"}),(0,t.jsxs)("div",{className:"global-hero-grid",children:[(0,t.jsxs)("label",{children:["Default mode",(0,t.jsx)("select",{"aria-label":"Default context mode",value:h.document.context.defaultMode,onChange:e=>F(t=>({...t,context:{...t.context,defaultMode:e.target.value}})),children:h.document.context.allowedModes.map(e=>(0,t.jsx)("option",{value:e,children:dw[e]},e))})]}),(0,t.jsxs)("div",{className:"global-hero-modes wide",children:[(0,t.jsx)("span",{children:"Allowed modes"}),(0,t.jsx)("div",{role:"group","aria-label":"Allowed context modes",children:dj.map(e=>{let n=h.document.context.allowedModes.includes(e);return(0,t.jsxs)("label",{className:"global-hero-mode",children:[(0,t.jsx)("input",{type:"checkbox",checked:n,disabled:n&&1===h.document.context.allowedModes.length,onChange:t=>{var n;return n=t.target.checked,void F(t=>{let a=n?dj.filter(n=>n===e||t.context.allowedModes.includes(n)):t.context.allowedModes.filter(t=>t!==e);if(0===a.length)return t;let i=a.includes(t.context.defaultMode)?t.context.defaultMode:a[0];return{...t,context:{...t.context,allowedModes:a,defaultMode:i}}})}}),dw[e]]},e)})}),(0,t.jsx)("p",{className:"global-hero-hint",children:"Task only is required for Heroes that run as delegated children. Reply enables addressing a specific message; Room shares the session lineage; Fresh starts from the addressed request."})]})]})]}),(0,t.jsxs)("section",{children:[(0,t.jsx)("h3",{children:"Hero prompt"}),(0,t.jsx)("label",{className:"global-hero-prompt",children:(0,t.jsx)("textarea",{"aria-label":"Hero prompt",value:h.document.prompt,onChange:e=>z(t=>({...t,prompt:e.target.value})),onBlur:()=>void E(h.document)})})]})]}),C&&(0,t.jsxs)("div",{className:"hero-conflict-dialog",role:"dialog","aria-modal":"true","aria-label":"Hero file diff",children:[(0,t.jsxs)("div",{children:[(0,t.jsxs)("header",{children:[(0,t.jsx)("strong",{children:"Local edits"}),(0,t.jsx)("button",{type:"button",onClick:()=>I(null),children:"Close"})]}),(0,t.jsx)("pre",{children:JSON.stringify(h.document,null,2)})]}),(0,t.jsxs)("div",{children:[(0,t.jsx)("header",{children:(0,t.jsx)("strong",{children:"File on disk"})}),(0,t.jsx)("pre",{children:JSON.stringify(C.document,null,2)})]})]})]})]})]})}function dC({graphId:e,models:a,onApplied:i,setError:s}){let[r,l]=(0,n.useState)(null),[o,d]=(0,n.useState)(""),[u,p]=(0,n.useState)(""),[h,m]=(0,n.useState)(null),f=(0,n.useCallback)(async()=>{m("loading");try{let t=await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(e)}/builder`);l(t),d(t.modelProfileId||a[0]?.model.id||"")}catch(e){s(e.message)}finally{m(null)}},[e,a,s]);(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void f(),0);return()=>window.clearTimeout(e)},[f]);let g=async()=>{if(u.trim()&&o&&!h){m("sending");try{let t=await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(e)}/builder/messages`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({modelProfileId:o,instruction:u.trim()})});l(t),p(""),s(null)}catch(e){s(e.message)}finally{m(null)}}},x=async()=>{if(r?.proposal&&!(r.proposal.diagnostics.length>0)&&!h){m("applying");try{let t=await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(e)}/builder/proposals/${encodeURIComponent(r.proposal.id)}/apply`,{method:"POST"});i(t),await f(),s(null)}catch(e){s(e.message)}finally{m(null)}}};return(0,t.jsxs)("aside",{className:"graph-builder-pane",children:[(0,t.jsxs)("div",{className:"graph-section-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{children:"Builder"}),(0,t.jsx)("p",{children:"Persistent conversation for this Graph."})]}),(0,t.jsx)(c,{size:18})]}),(0,t.jsxs)("div",{className:"graph-builder-content",children:[(0,t.jsxs)("label",{className:"graph-builder-model",children:["Builder model",(0,t.jsx)("select",{value:o,onChange:e=>d(e.target.value),disabled:!!h,children:a.map(e=>(0,t.jsx)("option",{value:e.model.id,children:e.label},e.model.id))})]}),(0,t.jsxs)("div",{className:"graph-builder-messages","aria-live":"polite",children:["loading"===h&&(0,t.jsxs)("div",{className:"graph-builder-loading",children:[(0,t.jsx)(eZ,{className:"spin",size:16})," Loading conversation…"]}),r?.messages.map(e=>(0,t.jsxs)("div",{className:`graph-builder-message is-${e.role}`,children:[(0,t.jsx)("span",{children:"user"===e.role?"You":"Builder"}),(0,t.jsx)("p",{children:e.content})]},e.id)),!h&&(r?.messages.length??0)===0&&(0,t.jsxs)("div",{className:"graph-builder-intro",children:[(0,t.jsx)(c,{size:22}),(0,t.jsx)("p",{children:"Describe Tasks, execution choices, and dependencies. Builder will return a validated proposal."})]})]}),r?.proposal&&(0,t.jsxs)("div",{className:`graph-builder-proposal ${r.proposal.diagnostics.length?"is-invalid":""}`,children:[(0,t.jsxs)("header",{children:[r.proposal.diagnostics.length?(0,t.jsx)(sO,{size:15}):(0,t.jsx)(Y,{size:15}),(0,t.jsx)("strong",{children:"Proposal"}),(0,t.jsxs)("span",{children:[r.proposal.operations.length," changes"]})]}),(0,t.jsx)("p",{children:r.proposal.summary}),(0,t.jsx)("ul",{children:r.proposal.operations.map((e,n)=>(0,t.jsxs)("li",{children:[(0,t.jsx)("code",{children:e.kind}),e.taskId?` \xb7 ${e.taskId}`:""]},n))}),r.proposal.diagnostics.map(e=>(0,t.jsx)("div",{className:"graph-builder-diagnostic",children:e},e)),(0,t.jsx)("button",{type:"button",onClick:()=>void x(),disabled:r.proposal.diagnostics.length>0||!!h,children:"applying"===h?"Applying…":"Apply proposal"})]}),(0,t.jsxs)("div",{className:"graph-builder-composer",children:[(0,t.jsx)("textarea",{value:u,onChange:e=>p(e.target.value),"aria-label":"Graph Builder instruction",placeholder:"Describe the Graph change…",disabled:!!h||!o,onKeyDown:e=>{"Enter"===e.key&&(e.metaKey||e.ctrlKey)&&g()}}),(0,t.jsx)("button",{type:"button",onClick:()=>void g(),disabled:!u.trim()||!o||!!h,"aria-label":"Send Builder instruction",children:"sending"===h?(0,t.jsx)(eZ,{className:"spin",size:17}):(0,t.jsx)(ra,{size:17})})]})]})]})}function dS(e){let t=new Set(Object.keys(e.tasks)),n=new Set,a=[];for(;t.size>0;){let i=[...t].filter(t=>(e.graph[t]??[]).every(e=>n.has(e))).sort();if(0===i.length)return[...a,[...t].sort()];a.push(i),i.forEach(e=>{t.delete(e),n.add(e)})}return a}function dI({document:e,busy:n,onOpenTask:a,onChange:i}){let s=Object.keys(e.tasks).sort();return 0===s.length?(0,t.jsx)("div",{className:"graph-empty-state",children:"Add a Task to start the Graph."}):(0,t.jsxs)("div",{className:"graph-dependency-editor",children:[(0,t.jsx)("div",{className:"graph-levels","aria-label":"Task dependency levels",children:dS(e).map((n,i)=>(0,t.jsxs)("div",{className:"graph-level",children:[(0,t.jsxs)("span",{className:"graph-level-label",children:["Level ",i+1]}),(0,t.jsx)("div",{children:n.map(n=>(0,t.jsx)("button",{type:"button",onClick:()=>a(n),children:e.tasks[n].name},n))}),i<dS(e).length-1&&(0,t.jsx)(j,{size:16,"aria-hidden":!0})]},i))}),(0,t.jsx)("div",{className:"graph-dependency-list",children:s.map(a=>{let r=new Set(e.graph[a]??[]);return(0,t.jsxs)("fieldset",{disabled:n,children:[(0,t.jsx)("legend",{children:e.tasks[a].name}),(0,t.jsxs)("div",{children:[s.filter(e=>e!==a).map(n=>(0,t.jsxs)("label",{children:[(0,t.jsx)("input",{type:"checkbox",checked:r.has(n),onChange:e=>{let t=new Set(r);e.target.checked?t.add(n):t.delete(n),i(a,[...t].sort())}}),e.tasks[n].name]},n)),1===s.length&&(0,t.jsx)("span",{children:"No other Tasks"})]})]},a)})})]})}function dP({graphs:e,selected:n,onSelect:a,onAdd:i}){return(0,t.jsxs)("div",{className:"graph-tabs-row",children:[(0,t.jsx)("div",{className:"graph-tabs",role:"tablist","aria-label":"Graphs",children:e.map(e=>(0,t.jsxs)("button",{type:"button",role:"tab","aria-selected":n===e.id,className:"graph-tab",onClick:()=>a(e.id),children:[(0,t.jsx)("span",{children:e.name}),e.error&&(0,t.jsx)("span",{title:e.error,"aria-label":e.error,role:"img",children:(0,t.jsx)(sO,{size:12,"aria-hidden":"true"})})]},e.id))}),(0,t.jsx)("button",{type:"button",className:"graph-add-tab",onClick:i,"aria-label":"Add Graph",title:"Add Graph",children:(0,t.jsx)(S,{size:18})})]})}function dT({id:e,task:n,expanded:a,busy:i,models:s,onToggle:r,onSave:l,onRemove:o}){let c=!!n.hero,d=s.find(e=>e.ref===n.model),u=d?.model.supportsThinking?d.model.supportedThinkingEfforts:["default"],p=(e,t)=>l({...n,[e]:t});return(0,t.jsxs)("section",{className:"graph-task","data-task-id":e,children:[(0,t.jsxs)("button",{type:"button",className:"graph-task-summary",onClick:r,"aria-expanded":a,children:[a?(0,t.jsx)(q,{size:17}):(0,t.jsx)(j,{size:17}),(0,t.jsxs)("span",{children:[(0,t.jsx)("strong",{children:n.name}),(0,t.jsx)("code",{children:e})]}),(0,t.jsxs)("small",{children:[c?n.hero:n.model,!c&&n.thinking&&"default"!==n.thinking?` \xb7 ${n.thinking}`:""]})]}),a&&(0,t.jsxs)("div",{className:"graph-task-form",children:[(0,t.jsxs)("label",{children:["Task name",(0,t.jsx)("input",{defaultValue:n.name,disabled:i,onBlur:e=>p("name",e.target.value)})]}),(0,t.jsxs)("div",{className:"graph-execution-mode",role:"group","aria-label":"Execution mode",children:[(0,t.jsx)("button",{type:"button","aria-pressed":!c,disabled:i||!s[0],onClick:()=>l({name:n.name,model:n.model||s[0]?.ref,thinking:"default",skills:[],goal:n.goal,writes:n.writes,budget:n.budget}),children:"Inline configuration"}),(0,t.jsx)("button",{type:"button","aria-pressed":c,disabled:i,onClick:()=>l({name:n.name,hero:n.hero||`local/${e}`,goal:n.goal,writes:n.writes,budget:n.budget}),children:"Use a Hero"})]}),c?(0,t.jsxs)("label",{children:["Hero",(0,t.jsx)("input",{defaultValue:n.hero,disabled:i,placeholder:"local/alignment or global/reviewer",onBlur:e=>p("hero",e.target.value)}),(0,t.jsx)("span",{children:"Local Heroes belong only to this Graph. Global Heroes are shared and read-only here."})]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("label",{children:["Model",(0,t.jsx)("select",{value:n.model??"",disabled:i,onChange:e=>p("model",e.target.value),children:s.map(e=>(0,t.jsxs)("option",{value:e.ref,children:[e.label," · ",e.ref]},e.ref))})]}),d?.model.supportsThinking&&(0,t.jsxs)("label",{children:["Thinking",(0,t.jsx)("select",{value:n.thinking??"default",disabled:i,onChange:e=>p("thinking",e.target.value),children:u.map(e=>(0,t.jsx)("option",{value:e,children:e},e))})]}),(0,t.jsxs)("label",{children:["Skills",(0,t.jsx)("input",{defaultValue:(n.skills??[]).join(", "),disabled:i,placeholder:"local/alignment, global/report-writing",onBlur:e=>p("skills",e.target.value.split(",").map(e=>e.trim()).filter(Boolean))}),(0,t.jsx)("span",{children:"Use explicit local/ or global/ references."})]})]}),(0,t.jsxs)("label",{className:"graph-task-goal",children:["Goal",(0,t.jsx)("textarea",{defaultValue:n.goal,disabled:i,onBlur:e=>p("goal",e.target.value)})]}),(0,t.jsxs)("details",{children:[(0,t.jsx)("summary",{children:"Advanced"}),(0,t.jsxs)("label",{children:["Writes",(0,t.jsx)("input",{defaultValue:(n.writes??[]).join(", "),disabled:i,onBlur:e=>p("writes",e.target.value.split(",").map(e=>e.trim()).filter(Boolean))})]})]}),(0,t.jsxs)("button",{type:"button",className:"graph-task-remove",onClick:o,disabled:i,children:[(0,t.jsx)(P,{size:15})," Remove Task"]})]})]})}function dM({setError:e}){let a=c0(),i=(0,n.useMemo)(()=>dk(a.models,a.providers),[a.models,a.providers]),[s,r]=(0,n.useState)([]),[l,o]=(0,n.useState)(null),[c,d]=(0,n.useState)(null),[u,p]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),[g,x]=(0,n.useState)(0),[v,y]=(0,n.useState)(!1);M(v,()=>y(!1));let[b,k]=(0,n.useState)({id:"",name:""}),[j,w]=(0,n.useState)(!1),[N,_]=(0,n.useState)({id:"",name:""}),[C,I]=(0,n.useState)("tasks"),P=(0,n.useCallback)(async e=>{let t=await (0,e3.apiFetch)("/v1/graphs");r(t);let n=e??t.find(e=>!e.error)?.id??null;return o(n),n},[]),T=(0,n.useCallback)(async t=>{f("loading"),o(t),p(null);try{let[n,a]=await Promise.all([(0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(t)}`),(0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(t)}/versions`)]);d(n),x(a.reduce((e,t)=>Math.max(e,t.version),0)),e(null)}catch(t){d(null),e(t.message)}finally{f(null)}},[e]);(0,n.useEffect)(()=>{let t=!1,n=window.setTimeout(()=>{P().then(e=>{!t&&e&&T(e)}).catch(n=>{t||e(n.message)})},0);return()=>{t=!0,window.clearTimeout(n)}},[T,P,e]);let R=async()=>{if(b.id.trim()&&b.name.trim()){f("creating");try{let t=await (0,e3.apiFetch)("/v1/graphs",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({id:b.id.trim(),name:b.name.trim()})});y(!1),k({id:"",name:""}),d(t),x(0),o(t.id),await P(t.id),e(null)}catch(t){e(t.message)}finally{f(null)}}},E=async t=>{if(c&&!m){f("saving");try{let n=await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(c.id)}`,{method:"PATCH",headers:{"Content-Type":"application/json"},body:JSON.stringify({expectedDigest:c.digest,...t})});d(n),r(e=>e.map(e=>e.id===n.id?{...e,name:n.name,digest:n.digest,error:void 0}:e)),e(null)}catch(t){e(t.message)}finally{f(null)}}},A=async()=>{if(c&&!m){f("publishing");try{let t=await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(c.id)}/publish`,{method:"POST"});x(t.version),e(null)}catch(t){e(t.message)}finally{f(null)}}},$=async e=>{await rx({title:`Remove Task “${c?.document.tasks[e]?.name??e}”?`,description:"This removes the task from the graph draft. Published versions are unaffected.",confirmLabel:"Remove task",tone:"danger"})&&await E({task:{id:e,value:null}})},z=async()=>{let t=i[0];if(!t)return void e("Create an active model before adding an inline Task.");let n=N.id.trim(),a=N.name.trim();n&&a&&(await E({task:{id:n,value:{name:a,model:t.ref,thinking:"default",skills:[],goal:"Describe the outcome this Task must produce."}}}),_({id:"",name:""}),w(!1),p(n))};return(0,t.jsxs)("div",{className:"graph-workspace",children:[(0,t.jsx)(dP,{graphs:s,selected:l,onSelect:e=>void T(e),onAdd:()=>y(!0)}),v&&(0,t.jsxs)("div",{className:"graph-create-strip",role:"dialog","aria-label":"Add Graph",children:[(0,t.jsxs)("label",{children:["ID",(0,t.jsx)("input",{autoFocus:!0,value:b.id,onChange:e=>k(t=>({...t,id:e.target.value})),placeholder:"rna-seq"})]}),(0,t.jsxs)("label",{children:["Name",(0,t.jsx)("input",{value:b.name,onChange:e=>k(t=>({...t,name:e.target.value})),placeholder:"RNA-seq"})]}),(0,t.jsx)("button",{type:"button",onClick:()=>void R(),disabled:"creating"===m,children:"creating"===m?"Creating…":"Create Graph"}),(0,t.jsx)("button",{type:"button",onClick:()=>y(!1),children:"Cancel"})]}),(0,t.jsx)("div",{className:"graph-mobile-segments",role:"tablist","aria-label":"Graph views",children:["tasks","graph","build"].map(e=>(0,t.jsx)("button",{type:"button",role:"tab","aria-selected":C===e,onClick:()=>I(e),children:e},e))}),!c&&"loading"===m&&(0,t.jsxs)("div",{className:"graph-loading",children:[(0,t.jsx)(eZ,{className:"spin",size:18})," Loading Graph…"]}),!c&&"loading"!==m&&0===s.length&&(0,t.jsxs)("div",{className:"graph-welcome",children:[(0,t.jsx)(h,{size:28}),(0,t.jsx)("h2",{children:"Create your first Graph"}),(0,t.jsx)("p",{children:"Compose reusable Tasks and their dependencies without choosing a Project."}),(0,t.jsxs)("button",{type:"button",onClick:()=>y(!0),children:[(0,t.jsx)(S,{size:16})," Add Graph"]})]}),c&&(0,t.jsxs)("div",{className:"graph-document",children:[(0,t.jsxs)("header",{className:"graph-document-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{children:"Graph"}),(0,t.jsx)("h2",{children:c.document.name}),(0,t.jsx)("code",{children:c.document.id})]}),(0,t.jsxs)("div",{className:"graph-document-actions",children:[(0,t.jsxs)("span",{children:["v",g||"draft"]}),(0,t.jsx)("div",{className:`graph-save-state ${"saving"===m?"is-saving":""}`,children:"saving"===m?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(eZ,{className:"spin",size:14})," Saving"]}):g>0?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Y,{size:14})," Saved v",g]}):(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(Y,{size:14})," Draft saved"]})}),(0,t.jsx)("button",{type:"button",onClick:()=>void A(),disabled:!!m||0===Object.keys(c.document.tasks).length,children:"publishing"===m?"Publishing…":"Publish"})]})]}),(0,t.jsxs)("main",{className:`graph-editor-view is-${C}`,children:[(0,t.jsxs)("section",{className:"graph-tasks-pane",children:[(0,t.jsxs)("div",{className:"graph-section-heading",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{children:"Tasks"}),(0,t.jsx)("p",{children:"Execution configuration. Tasks are collapsed by default."})]}),(0,t.jsxs)("button",{type:"button",onClick:()=>w(e=>!e),children:[(0,t.jsx)(S,{size:16})," Add Task"]})]}),j&&(0,t.jsxs)("div",{className:"graph-add-task",children:[(0,t.jsx)("input",{value:N.id,onChange:e=>_(t=>({...t,id:e.target.value})),placeholder:"task_id"}),(0,t.jsx)("input",{value:N.name,onChange:e=>_(t=>({...t,name:e.target.value})),placeholder:"Task name"}),(0,t.jsx)("button",{type:"button",onClick:()=>void z(),children:"Add"})]}),(0,t.jsxs)("div",{className:"graph-task-list",children:[Object.keys(c.document.tasks).sort().map(e=>(0,t.jsx)(dT,{id:e,task:c.document.tasks[e],expanded:u===e,busy:!!m,models:i,onToggle:()=>p(t=>t===e?null:e),onSave:t=>{E({task:{id:e,value:t}})},onRemove:()=>void $(e)},e)),0===Object.keys(c.document.tasks).length&&(0,t.jsx)("div",{className:"graph-empty-state",children:"No Tasks yet. Add one or ask Builder to draft the Graph."})]})]}),(0,t.jsxs)("section",{className:"graph-dependencies-pane",children:[(0,t.jsx)("div",{className:"graph-section-heading",children:(0,t.jsxs)("div",{children:[(0,t.jsx)("span",{children:"Graph"}),(0,t.jsx)("p",{children:"Dependency orchestration. Hero details stay inside Tasks."})]})}),(0,t.jsx)(dI,{document:c.document,busy:!!m,onOpenTask:e=>{p(e),I("tasks"),requestAnimationFrame(()=>document.querySelector(`[data-task-id="${CSS.escape(e)}"]`)?.scrollIntoView({behavior:"smooth",block:"start"}))},onChange:(e,t)=>void E({dependencies:{taskId:e,depends:t}})})]}),(0,t.jsx)(dC,{graphId:c.id,models:i,setError:e,onApplied:e=>{d(e),r(t=>t.map(t=>t.id===e.id?{...t,name:e.name,digest:e.digest,error:void 0}:t))}})]})]})]})}function dR({view:e,models:a,providers:i,onBackToChat:s,onOpenMobileNav:r,menuTriggerRef:l}){let[o,c]=(0,n.useState)(null);return(0,t.jsxs)("div",{className:"settings-view","data-testid":"heroes"===e?"heroes-page":"graphs-page",children:[(0,t.jsx)("button",{ref:l,type:"button",className:"workspace-mobile-menu",onClick:r,"aria-label":"Open navigation",children:(0,t.jsx)(rO,{size:20})}),(0,t.jsxs)("header",{className:"workspace-page-header",children:[(0,t.jsxs)("div",{children:[(0,t.jsx)("h1",{children:"heroes"===e?"Heroes":"Graphs"}),(0,t.jsx)("p",{children:"heroes"===e?"Global reusable execution presets for Chat and Graph Tasks.":"Global Task graphs. Every published Graph can run in any Session."})]}),(0,t.jsxs)("button",{type:"button",className:"settings-view-back",onClick:s,children:[(0,t.jsx)(r6,{size:15})," Chat"]})]}),o&&(0,t.jsxs)("div",{className:"error-bar workspace-page-error",role:"alert",children:[(0,t.jsx)("span",{children:o}),(0,t.jsx)("button",{type:"button",onClick:()=>c(null),"aria-label":"Dismiss error",children:(0,t.jsx)(m,{size:16})})]}),(0,t.jsx)("div",{className:"workspace-page-body",children:"heroes"===e?(0,t.jsx)(d_,{models:a,providers:i,setError:c}):(0,t.jsx)(dM,{setError:c})})]})}var dE=e.i(51761);function dA(e){let t=(0,e3.subscribeWorkerReachability)(e),n=()=>{(0,e3.probeWorkerReachability)().catch(()=>{})};return window.addEventListener("online",n),window.addEventListener("offline",n),()=>{t(),window.removeEventListener("online",n),window.removeEventListener("offline",n)}}function d$(){return"unreachable"===(0,e3.getWorkerReachability)()}function dz(){return!1}e.s(["AppShell",0,function({initialView:e="chat"}){let a=lz("(max-width: 640px)"),{projects:i,projectsReady:s,selectedProject:r,switchProject:l,openCreateProject:o,settingsOpen:c,settingsTab:d,openSettings:u,closeSettings:p,workspaceFor:h,togglePinProject:m,pinnedProjectIds:g,renameProject:x,deleteProject:v}=(0,cV.useWorkspace)(),[y,b]=(0,n.useState)(null),k=(0,n.useRef)(null),[j,w]=(0,n.useState)(e??"chat"),N=(0,n.useCallback)(e=>{w(e),window.history.replaceState(null,"","chat"===e?"/":`/?view=${e}`)},[]);(0,n.useEffect)(()=>{let e=()=>{let e=new URLSearchParams(window.location.search).get("view");("heroes"===e||"graphs"===e||"chat"===e)&&w(e)};return e(),window.addEventListener("popstate",e),()=>window.removeEventListener("popstate",e)},[]);let _=(0,n.useCallback)(e=>{k.current=e,b(e),(0,dE.writeStoredId)(dE.SELECTED_SESSION_KEY,e)},[]),C=cY({initialWidth:280,minWidth:264,maxWidth:420,storageKey:"--ennote-sidebar-width",cssVariable:"--ennote-sidebar-width"}),S=rF(),[I,P]=(0,n.useState)(!0),T=function(e){let[t,a]=(0,n.useState)(()=>window.innerWidth);(0,n.useEffect)(()=>{let e=()=>a(window.innerWidth);return window.addEventListener("resize",e),()=>window.removeEventListener("resize",e)},[]);let i=lF(t,e);return{...cY({initialWidth:680,minWidth:280,maxWidth:i,storageKey:"ennote-right-panel-width",direction:"left",resolveStored:(0,n.useCallback)(n=>{let a;return a=lF(t,e),null!==n&&Number.isFinite(n)?Math.max(280,Math.min(a,n)):Math.min(680,a)},[t,e])}),maxWidth:i}}(I&&!a?C.width:0),[E,A]=(0,n.useState)(null),$=(0,n.useRef)(null),z=(0,n.useRef)(null),F=(0,n.useCallback)(()=>{P(!1),window.requestAnimationFrame(()=>{($.current??z.current)?.focus()})},[]);(0,n.useEffect)(()=>{if(!a)return;let e=window.requestAnimationFrame(()=>P(!1));return()=>window.cancelAnimationFrame(e)},[a]),M(a&&I,F),(0,n.useEffect)(()=>{if(!a||!I)return;let e=document.querySelector(".sidebar-container");if(!e)return;let t=t=>{if("Tab"!==t.key)return;let n=Array.from(e.querySelectorAll('button:not(:disabled), input:not(:disabled), select:not(:disabled), [href], [tabindex]:not([tabindex="-1"])')).filter(e=>e.getClientRects().length>0);if(!n.length)return;let a=n[0],i=n[n.length-1];t.shiftKey&&document.activeElement===a?(t.preventDefault(),i.focus()):t.shiftKey||document.activeElement!==i||(t.preventDefault(),a.focus())};return window.addEventListener("keydown",t),()=>window.removeEventListener("keydown",t)},[F,a,I]);let L=function(e){let[t,a]=(0,n.useState)([]),[i,s]=(0,n.useState)([]),[r,l]=(0,n.useState)("active"),[o,c]=(0,n.useState)(""),[d,u]=(0,n.useState)(!1),[p,h]=(0,n.useState)(null),[m,f]=(0,n.useState)(null),[g,x]=(0,n.useState)(null),[v,y]=(0,n.useState)(""),b=(0,n.useRef)(0),k=(0,n.useRef)(null),j=(0,n.useRef)(r),w=(0,n.useCallback)(e=>{j.current=e,l(e)},[]),N=(0,n.useCallback)(async(t=0)=>{if(k.current?.abort(),!e){a([]),s([]),h(null),u(!1);return}let n=new AbortController;k.current=n;let i=++b.current;if(t>0&&await new Promise(e=>setTimeout(e,t)),n.signal.aborted||b.current!==i)return;u(!0);let l=`/v1/projects/${encodeURIComponent(e)}/sessions`,c=new URLSearchParams({status:r}),d=o.trim(),p=`${e}:${r}:${d}`;d&&c.set("q",d);try{let e=(0,e3.apiFetch)(`${l}?status=active`,{signal:n.signal}),t="active"!==r||d?(0,e3.apiFetch)(`${l}?${c.toString()}`,{signal:n.signal}):e,[o,u]=await Promise.all([e,t]);if(n.signal.aborted||b.current!==i)return;a(o??[]),s(u??[]),h(p),x(null)}catch(e){n.signal.aborted||b.current!==i||(h(p),x(e.message))}finally{n.signal.aborted||b.current!==i||u(!1)}},[e,o,r]);(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void N(0),200);return()=>{window.clearTimeout(e),k.current?.abort()}},[N]);let _=(0,n.useCallback)(()=>N(0),[N]),C=(0,n.useCallback)(e=>{a(t=>"active"===e.status?t.some(t=>t.id===e.id)?t.map(t=>t.id===e.id?e:t):[e,...t]:t.filter(t=>t.id!==e.id)),s(t=>t.map(t=>t.id===e.id?e:t).filter(e=>e.status===j.current))},[]),S=(0,n.useCallback)(async(e,t)=>{f(e.id);try{return await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e.id)}/${t}`,{method:"POST",body:"{}"}),y(`${"archive"===t?"Archived":"Restored"} ${e.title}`),x(null),await _(),!0}catch(e){return x(e.message),!1}finally{f(null)}},[_]),I=e?`${e}:${r}:${o.trim()}`:null;return{activeSessions:t,visibleSessions:i,view:r,setView:w,query:o,setQuery:c,loading:d||null!==I&&p!==I,mutatingId:m,error:g,setError:x,announcement:v,refresh:_,replaceSession:C,archive:e=>S(e,"archive"),restore:e=>S(e,"restore")}}(r),D=function(e,t,a){let[i,s]=(0,n.useState)({}),[r,l]=(0,n.useState)({}),[o,c]=(0,n.useState)(cZ),d=(0,n.useRef)(0),u=(0,n.useMemo)(()=>{let e=[],n=t=>{t&&!e.includes(t)&&e.push(t)};for(let e of(n(a),t))n(e);return e},[a,t]),p=(0,n.useCallback)(async t=>{let n=++d.current,a=e.find(e=>e.id===t),i=a?.name??t;s(e=>({...e,[t]:{projectId:t,projectName:i,sessions:[],loading:!0,error:null}}));try{let e=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(t)}/sessions?status=active`)??[];if(d.current!==n)return;s(n=>({...n,[t]:{projectId:t,projectName:i,sessions:e,loading:!1,error:null}}))}catch(e){if(d.current!==n)return;s(n=>({...n,[t]:{projectId:t,projectName:i,sessions:[],loading:!1,error:e.message}}))}},[e]);(0,n.useEffect)(()=>{for(let e of u)i[e]||p(e)},[u,i,p]),(0,n.useEffect)(()=>{a&&p(a)},[a,p]),(0,n.useEffect)(()=>{let e=window.setInterval(()=>{for(let e of u)p(e)},3e4);return()=>window.clearInterval(e)},[u,p]);let h=(0,n.useCallback)(e=>void p(e),[p]),m=(0,n.useCallback)(()=>{for(let e of u)p(e)},[u,p]),f=(0,n.useCallback)(async e=>{if(!r[e])try{let t=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/sessions?status=archived`)??[];l(n=>({...n,[e]:t}))}catch{l(t=>({...t,[e]:[]}))}},[r]),g=(0,n.useCallback)(async e=>{try{let t=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/sessions?status=archived`)??[];l(n=>({...n,[e]:t}))}catch{l(t=>({...t,[e]:[]}))}},[]),x=(0,n.useCallback)(e=>{c(t=>{let n=new Set(t);n.has(e)?n.delete(e):n.add(e);try{window.localStorage.setItem(cQ,JSON.stringify([...n]))}catch{}return n})},[]);return{groups:(0,n.useMemo)(()=>u.map(e=>i[e]).filter(e=>!!e),[u,i]),archived:r,collapsed:o,toggleCollapsed:x,refresh:h,refreshAll:m,openArchived:f,refreshArchived:g}}(i,g,r),O=c0(),q=L.replaceSession,B=L.activeSessions.find(e=>e.id===y),U=function(e){let[t,a]=(0,n.useState)({templates:[],diagnostics:[],loading:!1,error:null}),i=(0,n.useRef)(null),s=(0,n.useCallback)(async()=>{if(!e)return void a({templates:[],diagnostics:[],loading:!1,error:null});i.current?.abort();let t=new AbortController;i.current=t,a(e=>({...e,loading:!0,error:null}));try{let n=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/prompt-templates`,{signal:t.signal});if(t.signal.aborted)return;a({templates:n.templates,diagnostics:n.diagnostics,loading:!1,error:null})}catch(e){if(t.signal.aborted)return;a(t=>({...t,loading:!1,error:e.message??"Failed to load prompt templates"}))}},[e]);return(0,n.useEffect)(()=>{e&&s()},[s,e]),(0,n.useEffect)(()=>()=>{i.current?.abort()},[]),{...t,refresh:s}}(r),H=function(e){var t;let a,i,s,r,l,o,{selectedSession:c,sessionRecord:d,selectedProject:u,promptCatalog:p,settings:h,replaceSession:m}=e,g=(0,n.useMemo)(()=>new Map(h.models.map(e=>[e.id,e.displayName||e.modelName])),[h.models]),x=(0,n.useCallback)((e,t)=>(e?g.get(e):void 0)??t,[g]),v=d?.activeBranchId,y=d?.activeLeafMessageId,b=(0,n.useCallback)(e=>m(e),[m]),k=(0,n.useCallback)(async()=>{if(!c)return null;let e=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(c)}`);return m(e),e},[m,c]),j=(t={resolveModel:x},a=t?.resolveModel,i=c?dl.getStore(c):null,s=(0,n.useSyncExternalStore)(i?i.subscribe:dd,i?i.getSnapshot:()=>dc,i?i.getServerSnapshot:()=>dc),(0,n.useEffect)(()=>{if(i)return i.ensureLoaded(v),()=>i.pauseStream()},[i,v]),r=!!c&&s.loaded&&s.dataBranchId===v,l=function(e,t){let[a,i]=(0,n.useState)(new Map);return(0,n.useEffect)(()=>{if(!e)return void i(new Map);let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/turn-metrics`).then(e=>{t||i(new Map(e.map(e=>[e.runId,e])))}).catch(()=>{}),()=>{t=!0}},[e,t]),a}(c,s.activeRun?.id??null),o=(0,n.useMemo)(()=>r?function(e,t,n,a){let i=[],s=null,r=0,l=new Map,o=()=>{s&&(s.runId&&(s.metrics=n?.get(s.runId)),(s.user||s.steps.length>0)&&i.push(s),s=null,l.clear())};for(let n of function(e,t){let n=e.filter(e=>"private"!==e.visibility&&"room_control"!==e.visibility),a=new Set(n.map(e=>e.id)),i=[...new Map(t.filter(e=>"completed"===e.status).map(e=>[e.id,e])).values()].sort((e,t)=>e.createdAt.localeCompare(t.createdAt)),s=new Map,r=new Map;for(let e of i)e.firstKeptMessageId&&a.has(e.firstKeptMessageId)?dn(s,e.firstKeptMessageId,e):e.sourceThroughMessageId&&a.has(e.sourceThroughMessageId)&&dn(r,e.sourceThroughMessageId,e);return n.flatMap(e=>[...(s.get(e.id)??[]).map(e=>({kind:"checkpoint",value:e})),{kind:"message",value:e},...(r.get(e.id)??[]).map(e=>({kind:"checkpoint",value:e}))])}(e,t)){if("checkpoint"===n.kind){var c;o(),i.push((c=n.value,{kind:"checkpoint",id:`compaction-${c.id}`,reason:c.reason,summary:c.summary,reclaimedTokens:c.reclaimedTokens,createdAt:c.createdAt,promptVersion:c.promptVersion,summaryContractDigest:c.summaryContractDigest}));continue}!function(e){if("user"===e.role){o(),s={kind:"turn",id:`turn-${e.id}`,user:{id:e.id,sourceMessageId:e.id,text:e.parts.map(e=>"text"===e.type?e.text:"image"===e.type?`[Image \xb7 ${e.image.width}\xd7${e.image.height}]`:"image_description"===e.type?e.imageDescription.text:"").filter(Boolean).join("\n\n"),createdAt:e.createdAt},steps:[],messageIds:[e.id]};return}let t=(s||(r+=1,s={kind:"turn",id:`turn-orphan-${r}`,steps:[],messageIds:[]}),s);t.messageIds.push(e.id),e.runId&&(t.runId=t.runId??e.runId),"assistant"===e.role?function(e,t){let n=[],i=[],s=()=>{if(0===n.length)return;let i={...t.speakerSnapshot,modelProfileId:t.modelProfileId,apiModel:t.apiModel};if(a){let e=a(t.modelProfileId,t.apiModel);e&&(i.modelName=e)}e.steps.push({kind:"assistant",id:`${t.id}-assistant-${e.steps.length}`,sourceMessageId:t.id,blocks:n,speaker:i,createdAt:t.createdAt}),n=[]},r=()=>{0!==i.length&&(dt(e,i,l),i=[])};for(let e of t.parts)if("tool_call"===e.type){s();let n={id:`${t.id}-${e.toolCall.id}`,toolCallId:e.toolCall.id,toolName:e.toolCall.name,arguments:e.toolCall.arguments,argumentsFragment:e.toolCall.argumentsFragment,state:e.toolCall.partial?"interrupted":"pending",riskClass:s4(e.toolCall.name),sourceMessageIds:[t.id],runId:t.runId};i.push(n),l.set(n.toolCallId,n)}else{var o;r();let t="text"===(o=e).type?{kind:"text",text:o.text}:"thinking"===o.type?{kind:"thinking",text:o.text}:"image"===o.type?{kind:"image",artifactId:o.image.artifactId,mimeType:o.image.mimeType,width:o.image.width,height:o.image.height}:"image_description"===o.type?{kind:"image_description",artifactId:o.imageDescription.artifactId,text:o.imageDescription.text}:null;t&&n.push(t)}s(),r()}(t,e):"tool"===e.role&&function(e,t){let n=[];for(let e of t.parts){if("tool_result"!==e.type)continue;let a=l.get(e.toolResult.toolCallId);if(a)a.result={content:e.toolResult.content,isError:e.toolResult.isError,artifacts:e.toolResult.artifacts??[]},a.state=da(e.toolResult.content,e.toolResult.isError),a.sourceMessageIds.push(t.id);else{let a={id:`${t.id}-${e.toolResult.toolCallId}`,toolCallId:e.toolResult.toolCallId,toolName:e.toolResult.toolName,result:{content:e.toolResult.content,isError:e.toolResult.isError,artifacts:e.toolResult.artifacts??[]},state:da(e.toolResult.content,e.toolResult.isError),riskClass:s4(e.toolResult.toolName),sourceMessageIds:[t.id],runId:t.runId};l.set(a.toolCallId,a),n.push(a)}}n.length>0&&dt(e,n,l)}(t,e)}(n.value)}return{nodes:i,openTurn:s,calls:l,syntheticTurn:r}}(s.canonical,s.checkpoints,l,a):dg,[r,s.canonical,s.checkpoints,l,a]),{messages:(0,n.useMemo)(()=>(function(e,t,n,a,i){if(0===t.length){let t=function(e,t){if(!e)return null;let n={...e};return(n.runId&&(n.metrics=t?.get(n.runId)),n.user||0!==n.steps.length)?n:null}(e.openTurn,n);return t?[...e.nodes,t]:e.nodes}let s=[...e.nodes],r=new Map(e.calls),l=e.syntheticTurn,o=e.openTurn,c=null!==o,d=()=>{if(!o)return;let e=c?{...o}:o;e.runId&&(e.metrics=n?.get(e.runId)),(e.user||e.steps.length>0)&&s.push(e),o=null,c=!1,r.clear()};for(let e of t)!function(e){if("user"===e.role&&"steer"!==e.kind){d(),o={kind:"turn",id:`turn-${e.id}`,user:{id:e.id,text:e.text,sourceMessageId:e.sourceMessageId,createdAt:e.createdAt},steps:[],messageIds:[e.sourceMessageId??e.id]},c=!1;return}let t=(()=>{if(null===o)return l+=1,o={kind:"turn",id:`turn-orphan-${l}`,steps:[],messageIds:[]},c=!1,o;if(c){var e;for(let t of(o={...e=o,messageIds:[...e.messageIds],steps:e.steps.map(e=>"tool_batch"===e.kind?{...e,activities:e.activities.map(e=>({...e,sourceMessageIds:[...e.sourceMessageIds],result:e.result?{...e.result}:void 0}))}:e)},r.clear(),o.steps))if("tool_batch"===t.kind)for(let e of t.activities)r.set(e.toolCallId,e);c=!1}return o})();if(t.messageIds.push(e.sourceMessageId??e.id),e.runId&&(t.runId=t.runId??e.runId),"user"===e.role&&"steer"===e.kind)return t.steps.push({kind:"steer",id:e.id,text:e.text.replace(/^↪\s*/,""),createdAt:e.createdAt});if("assistant"===e.role){let n=[];e.thinking&&n.push({kind:"thinking",text:e.thinking}),e.text&&n.push({kind:"text",text:e.text}),n.length>0&&t.steps.push({kind:"assistant",id:e.id,sourceMessageId:e.sourceMessageId,blocks:n,speaker:function(e,t){if(!e)return;let n=e.effectiveConfig??{},a=e.requestedConfig??{},i="string"==typeof n.modelProfileId&&n.modelProfileId?n.modelProfileId:"string"==typeof a.modelProfileId?a.modelProfileId:void 0,s="string"==typeof n.apiModel&&n.apiModel?n.apiModel:"string"==typeof a.apiModel?a.apiModel:void 0,r=t?t(i,s):void 0;return{...e.speakerSnapshot,modelProfileId:i,apiModel:s,modelName:r}}(i,a),createdAt:e.createdAt});return}if("tool"===e.role){let n=e.toolCallId??e.id,a=r.get(n);if(a){e.arguments&&(a.arguments=e.arguments),e.runId&&(a.runId=e.runId),e.toolName&&a.toolName!==e.toolName&&(a.toolName=e.toolName,a.riskClass=s4(e.toolName)),a.result="running"===e.toolState?a.result:{content:e.text,isError:!!e.isError,artifacts:[]},a.state=e.toolState??da(e.text,!!e.isError),a.sourceMessageIds.push(e.sourceMessageId??e.id);return}dt(t,[{id:e.id,toolCallId:n,toolName:e.toolName??"tool",arguments:e.arguments,argumentsFragment:e.argumentsFragment,result:"running"===e.toolState?void 0:{content:e.text,isError:!!e.isError,artifacts:[]},state:e.toolState??da(e.text,!!e.isError),riskClass:s4(e.toolName??"tool"),sourceMessageIds:[e.sourceMessageId??e.id],runId:e.runId}],r)}}(e);return d(),s})(o,s.transient,l,a,s.activeRun),[o,s.transient,l,a,s.activeRun]),loading:!!c&&!r&&!s.error||s.loading,loadingOlder:s.loadingOlder,historyError:s.error,hasMore:s.hasMore,loadOlder:i?i.loadOlder:du,refreshLatest:i?i.refreshLatest:dp,appendTransient:i?i.appendTransient:dh,upsertTransient:i?i.upsertTransient:dm,removeTransient:i?i.removeTransient:df,activeRun:s.activeRun,pendingApproval:s.pendingApproval,queuedInputs:s.queuedInputs,delegationActive:s.delegationActive,lastSeq:s.lastSeq,workerInstanceId:s.workerInstanceId,streamOpen:s.streamOpen}),w=function({sessionId:e,lineageId:t,appendMessage:a,upsertMessage:i,refreshLatest:s,refreshSession:r,activeRun:l,pendingApproval:o,queuedInputs:c}){let d=(0,f.useT)(),[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(!1),[g,x]=(0,n.useState)(""),[v,y]=(0,n.useState)(null),[b,k]=(0,n.useState)(null),[j,w]=(0,n.useState)(null),N=(0,n.useRef)(null),_=(0,n.useRef)(null),C=(0,n.useRef)(0),S=(0,n.useRef)(0),I=(0,n.useRef)(e),P=(0,n.useRef)(!1),T=(0,n.useRef)(null),M=(0,n.useRef)(new Map),R=(0,n.useRef)(new Map),[E,A]=(0,n.useState)(0),{rows:$,queue:z,settle:F,reset:L}=function(e){let[t,a]=(0,n.useReducer)(c6,c3),i=(0,n.useCallback)(e=>a({type:"queue",row:e}),[]),s=(0,n.useCallback)(e=>a({type:"settle",id:e}),[]),r=(0,n.useCallback)(()=>a({type:"reset"}),[]);return{rows:(0,n.useMemo)(()=>(function(e,t,n){let a=[],i=new Set;for(let t of e)"follow_up"!==t.kind||n.has(t.id)||i.has(t.id)||(i.add(t.id),a.push({id:t.id,text:t.text}));for(let e of t)n.has(e.id)||i.has(e.id)||(i.add(e.id),a.push(e));return a})(e,t.optimistic,t.settled),[e,t.optimistic,t.settled]),queue:i,settle:s,reset:r}}(c);(0,n.useEffect)(()=>{I.current=e},[e]);let D=(0,n.useCallback)(async(e,t,n)=>{let a=I.current;if(!a||e.sessionId!==a)return;T.current=e.id,P.current=!0,x(o?sS("question"===o.kind?"waiting_answer":"waiting_approval"):"context_compaction"===e.runKind?sS("compaction_queued"):"waiting_children"===e.status?sS("waiting_children"):"waiting_delegation_admission"===e.status?sS("waiting_delegation_admission"):sS("running")),y(null);let l=!1;try{if("context_compaction"===e.runKind)l=await c7(e.id,x,t);else{let a=M.current.get(e.id)??{assistants:new Map,toolDeltas:new Map,toolOutputs:new Map,usageByIteration:new Map,finishedTools:new Set};M.current.set(e.id,a);let s=R.current.get(e.id)??{value:void 0};R.current.set(e.id,s),l=await de(e.id,i,x,y,k,t,{requested:()=>{},resolved:()=>{},delegated:()=>{},followUpConsumed:e=>{C.current===n&&F(e)},inputCancelled:e=>{C.current===n&&F(e)}},a,s)}}catch(e){l=e instanceof c9,t.aborted||C.current!==n||w(e.message)}finally{C.current===n&&(P.current=!1),l||t.aborted||C.current!==n||x(sS(sN)),l&&(M.current.delete(e.id),R.current.delete(e.id)),l&&!t.aborted&&C.current===n&&I.current===a&&(L(),N.current=null,await r().catch(()=>null),await s(),window.setTimeout(()=>{C.current===n&&I.current===a&&x("")},1600))}},[s,r,i,o,L,F]),O=(0,n.useCallback)(e=>{let t=I.current;if(!t||e.sessionId!==t)return;let n=++C.current;N.current?.abort();let a=new AbortController;N.current=a,D(e,a.signal,n)},[D]),q=(0,n.useCallback)(()=>{p(null),x(""),y(null),k(null),w(null),L()},[L]);(0,n.useEffect)(()=>{C.current+=1,N.current?.abort(),_.current?.abort(),T.current=null,M.current.clear(),R.current.clear(),q()},[t,e,q]),(0,n.useEffect)(()=>{if(!e||l?.id)return;let t=!1;return(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/context-usage`).then(e=>{t||k(e)}).catch(()=>{}),()=>{t=!0}},[e,l?.id]),(0,n.useEffect)(()=>{l?l.id!==T.current&&O(l):T.current&&(N.current?.abort(),M.current.delete(T.current),R.current.delete(T.current),T.current=null,q())},[l,O,q]);let B=l?.id??null;(0,n.useEffect)(()=>{if(sI(g).code!==sN||!B)return;let e=window.setTimeout(()=>A(e=>e+1),1e3);return()=>window.clearTimeout(e)},[g,B]);let U=(0,n.useRef)(l);(0,n.useEffect)(()=>{U.current=l},[l]),(0,n.useEffect)(()=>{if(0===E)return;let e=U.current;e&&(T.current=null,O(e))},[E,O]);let H=(0,n.useCallback)(async()=>{if(l)try{await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(l.id)}/cancel`,{method:"POST"}),N.current?.abort(),C.current+=1,x(sS("cancelled")),await r().catch(()=>null),await s()}catch(e){w(e.message)}},[l,s,r]),W=(0,n.useCallback)(async e=>{if(!l||!e.trim())return!1;if(o?.kind==="question")return w(d("run.status.answerQuestionFirst")),!1;try{return x(sS("steering")),await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(l.id)}/inputs`,{method:"POST",body:JSON.stringify({kind:"steer",text:e,clientRequestId:c8()})}),a({id:c8(),role:"user",text:`↪ ${e}`,kind:"steer"}),x("waiting_for_approval"===l.status?sS("waiting_approval"):""),!0}catch(e){return w(c4(e,"Failed to steer the run")),!1}},[l,a,o,d]),V=(0,n.useCallback)(async e=>{if(!l||!e.trim())return{queued:!1,runEnded:!1};if(o?.kind==="question")return w(d("run.status.answerQuestionFirst")),{queued:!1,runEnded:!1};try{let t=await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(l.id)}/inputs`,{method:"POST",body:JSON.stringify({kind:"follow_up",text:e,clientRequestId:c8()})});return z({id:t.id,text:t.text||e}),{queued:!0,runEnded:!1}}catch(n){let e=c4(n,"Failed to send follow-up"),t=/not active|not_active/i.test(e);return t||w(e),{queued:!1,runEnded:t}}},[l,o,z,d]),K=(0,n.useCallback)(async e=>{if(!l)return!1;try{return await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(l.id)}/inputs/${encodeURIComponent(e)}`,{method:"DELETE"}),F(e),!0}catch(e){return w(c4(e,"Failed to cancel the queued message")),!1}},[l,F]),G=(0,n.useCallback)(async e=>{if(o&&"question"===o.kind&&!h){m(!0);try{await (0,e3.apiFetch)(`/v1/approval-requests/${encodeURIComponent(o.id)}/answer`,{method:"POST",headers:{"Idempotency-Key":c8()},body:JSON.stringify({answers:e,clientRequestId:c8()})}),x(sS("answer_submitted")),!P.current&&l&&(T.current=null,O({...l,status:"queued"}))}catch(e){w(c4(e,"Failed to answer the question"))}finally{m(!1)}}},[l,h,o,O]),J=(0,n.useCallback)(async(e,t)=>{if(!o||u)return;_.current?.abort();let n=new AbortController;_.current=n;let a=++S.current;p(e);try{if(await (0,e3.apiFetch)(`/v1/approval-requests/${encodeURIComponent(o.id)}/decision`,{method:"POST",headers:{"Idempotency-Key":c8()},body:JSON.stringify({decision:e,clientRequestId:c8(),standingGrantCallIndexes:t??[]}),signal:n.signal}),n.signal.aborted||S.current!==a)return;x(sS("approved"===e?"approval_granted":"approval_rejected")),!P.current&&l&&(T.current=null,O({...l,status:"queued"}))}catch(e){n.signal.aborted||S.current!==a||w(e.message)}finally{n.signal.aborted||S.current!==a||p(null)}},[l,o,u,O]);return{activeRun:l,activeRunID:l?.id??null,contextUsage:b,compacting:l?.runKind==="context_compaction",pendingApproval:o,resolvingApproval:u,answeringQuestion:h,answerQuestion:G,status:g,setStatus:x,usage:v,error:j,setError:w,watchRun:O,cancel:H,steer:W,followUp:V,cancelFollowUp:K,pendingFollowUps:$,decideApproval:J}}({sessionId:c,lineageId:v,appendMessage:j.appendTransient,upsertMessage:j.upsertTransient,refreshLatest:j.refreshLatest,refreshSession:k,activeRun:j.activeRun,pendingApproval:j.pendingApproval,queuedInputs:j.queuedInputs}),N=function(e,t,a){let[i,s]=(0,n.useState)(null),[r,l]=(0,n.useState)(),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(null),p=(0,n.useRef)(0),h=(0,n.useCallback)(async n=>{if(!e||a)return void s(null);let i=p.current;try{let a=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/recovery`,{signal:n});n?.aborted||p.current!==i||(s(a),l(t),u(null))}catch(e){n?.aborted||p.current!==i||u(e.message)}},[a,t,e]);(0,n.useEffect)(()=>{let e=++p.current,t=new AbortController;return queueMicrotask(()=>{p.current===e&&(s(null),l(void 0),u(null),h(t.signal))}),()=>t.abort()},[t,h]);let m=(0,n.useCallback)(async()=>{if(!i?.retryable||o)return null;c(!0);try{let e="u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36),t=await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(i.run.id)}/retry`,{method:"POST",headers:{"Content-Type":"application/json","Idempotency-Key":e},body:JSON.stringify({clientRequestId:e})});return s(null),u(null),t.run}catch(e){return u(e.message),null}finally{c(!1)}},[i,o]);return{recovery:r===t?i:null,retrying:o,error:d,clearError:(0,n.useCallback)(()=>u(null),[]),retry:m,refresh:h}}(c,v,w.activeRunID),_=function(e,t){let[a,i]=(0,n.useState)(null);return(0,n.useEffect)(()=>{if(!e)return void i(null);let n=!1,a=()=>{(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/stats`).then(e=>{n||i(e)}).catch(()=>{})};a();let s=t?window.setInterval(a,2e3):void 0;return()=>{n=!0,void 0!==s&&window.clearInterval(s)}},[e,t]),a}(c,w.activeRunID),C=function({sessionId:e,activeBranchId:t,onSessionUpdated:a}){let[i,s]=(0,n.useState)([]),[r,l]=(0,n.useState)(null),[o,c]=(0,n.useState)(!1),[d,u]=(0,n.useState)(!1),[p,h]=(0,n.useState)(null),m=(0,n.useRef)(0),f=(0,n.useCallback)(async t=>{if(!e)return;let n=m.current;c(!0);try{let a=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/branches`,{signal:t});t?.aborted||m.current!==n||(s(a??[]),l(e),h(null))}catch(e){t?.aborted||m.current!==n||h(e.message)}finally{t?.aborted||m.current!==n||c(!1)}},[e]);(0,n.useEffect)(()=>{let t=++m.current,n=new AbortController;return queueMicrotask(()=>{m.current===t&&(h(null),e?f(n.signal):c(!1))}),()=>n.abort()},[t,f,e]);let g=(0,n.useCallback)(e=>{m.current+=1,s(e.branches),l(e.session.id),a(e.session),h(null)},[a]),x=(0,n.useCallback)(async(t,n)=>{if(!e||d)return!1;u(!0);try{let a=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/branches`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({fromMessageId:t,...n?.trim()?{label:n.trim()}:{}})});return g(a),!0}catch(e){return h(e.message),!1}finally{u(!1)}},[g,d,e]),v=(0,n.useCallback)(async n=>{if(!e||d||n===t)return!1;u(!0);try{let t=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}/branches/${encodeURIComponent(n)}/activate`,{method:"POST"});return g(t),!0}catch(e){return h(e.message),!1}finally{u(!1)}},[t,g,d,e]);return{branches:r===e?i:[],loading:o,changing:d,error:p,clearError:(0,n.useCallback)(()=>h(null),[]),refresh:f,createBranch:x,activateBranch:v}}({sessionId:c,activeBranchId:v,onSessionUpdated:b}),{composer:S,actions:I}=function(e){let{selectedSession:t,selectedProject:a,sessionRecord:i,promptCatalog:s,settings:r,runtime:l}=e,o=(0,f.useT)(),[c,d]=(0,n.useState)(""),{pendingImage:u,textAttachments:p,uploadImage:h,attachFiles:m,removeTextAttachment:g,clearPendingImage:x,clearAttachments:v,restoreAttachments:y}=function(e){let{selectedProject:t,selectedSession:a,runtime:i}=e,[s,r]=(0,n.useState)(null),[l,o]=(0,n.useState)([]),c=(0,n.useCallback)(async e=>{if(!t||!a)return;let n=new FormData;n.set("sessionId",a),n.set("file",e);try{i.setStatus(sS("uploading_image"));let e=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(t)}/attachments/images`,{method:"POST",body:n});r(e),i.setError(null)}catch(e){i.setError(c4(e,"Failed to attach the image"))}finally{i.setStatus("")}},[t,a,i]),d=(0,n.useCallback)(async e=>{if(!a)return;let t=e.filter(e=>e.type.startsWith("image/")),n=e.filter(e=>!e.type.startsWith("image/"));t[0]&&await c(t[0]),t.length>1&&i.setError("Only one image can be attached to a turn.");let s=[];for(let e of n){if(!function(e){if(e.type.startsWith("text/"))return!0;let t=e.name.toLowerCase().split(".").pop()??"";return dy.has(t)||["dockerfile","makefile"].includes(e.name.toLowerCase())}(e)){i.setError(`${e.name} is not a supported text attachment.`);continue}if(e.size>1048576){i.setError(`${e.name} exceeds the 1 MiB text attachment limit.`);continue}s.push({id:"u">typeof crypto&&crypto.randomUUID?crypto.randomUUID():Math.random().toString(36).slice(2)+Date.now().toString(36),name:e.name,size:e.size,text:await e.text()})}s.length&&(o(e=>[...e,...s].slice(0,3)),l.length+s.length>3&&i.setError("A turn can include at most three text files."))},[a,i,l.length,c]),u=(0,n.useCallback)(e=>{o(t=>t.filter(t=>t.id!==e))},[]),p=(0,n.useCallback)(()=>r(null),[]);return{pendingImage:s,textAttachments:l,uploadImage:c,attachFiles:d,removeTextAttachment:u,clearPendingImage:p,clearAttachments:(0,n.useCallback)(()=>{r(null),o([])},[]),restoreAttachments:(0,n.useCallback)((e,t)=>{r(e),o(t)},[])}}({selectedProject:a,selectedSession:t,runtime:l}),[b,k]=(0,n.useState)({}),[j,w]=(0,n.useState)("discuss");(0,n.useEffect)(()=>{w(oQ());let e=e=>{let t=e.detail;("discuss"===t||"ask"===t||"auto"===t)&&w(t)};return window.addEventListener(oJ,e),()=>window.removeEventListener(oJ,e)},[]);let[N,_]=(0,n.useState)({}),[C,S]=(0,n.useState)({open:!1,instructions:"",busy:!1}),{heroes:I,selectedHeroId:P,setSelectedHeroId:T}=function(e){let[t,a]=(0,n.useState)(null),[i,s]=(0,n.useState)([]);return(0,n.useLayoutEffect)(()=>{a(null)},[e]),(0,n.useEffect)(()=>{if(!e)return;let t=!1;return(0,e3.apiFetch)("/v1/global-heroes").then(async e=>{let n=await Promise.all((e??[]).filter(e=>!e.error).map(async e=>{try{let[t,n]=await Promise.all([(0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(e.id)}`),(0,e3.apiFetch)(`/v1/global-heroes/${encodeURIComponent(e.id)}/versions`)]),a=n.at(-1);if(!a)return null;return{id:e.id,handle:t.document.handle,name:t.document.name,description:t.document.description,positioning:t.document.positioning,icon:t.document.icon,color:t.document.color,scope:"global",status:"active",sourceKind:"managed",sourceLocator:t.path,currentVersionId:`v${String(a.version).padStart(6,"0")}`,currentVersion:a.version,updatedAt:a.publishedAt}}catch{return null}}));if(t)return;let i=n.filter(e=>null!==e);s(i),a(e=>i.some(t=>t.id===e)?e:null)}).catch(()=>{t||s([])}),()=>{t=!0}},[e]),{heroes:i,selectedHeroId:t,setSelectedHeroId:a}}(a),M=function(e){let[t,a]=(0,n.useState)([]),i=(0,n.useCallback)(async(t=()=>!0)=>{try{let n=e?`?${new URLSearchParams({projectID:e})}`:"",i=await (0,e3.apiFetch)(`/v1/skills${n}`);if(!t())return;a((i?.skills??[]).filter(e=>!!e.skillId&&e.sourceInfo?.scope!=="project").map(e=>({id:e.skillId??"",label:e.name||e.skillId||"",description:e.description,heroBound:!0===e.heroBound,boundBy:e.boundBy??[]})))}catch{}},[e]);return(0,n.useEffect)(()=>{let e=!1;return(async()=>{await i(()=>!e)})(),()=>{e=!0}},[i]),{skills:t,refresh:i}}(a),[R,E]=(0,n.useState)([]),[A,$]=(0,n.useState)(null),z=(0,n.useRef)(t),{setInputVersioned:F,expandDraftOrFallback:L,expandedVersion:D,draftVersion:O,flowCatalog:q,commandPanelOpen:B,promptPanelDismissed:U,setPromptPanelDismissed:H,expanding:W,expandDiag:V,setExpandDiag:K}=function(e){let{selectedProject:t,selectedSession:a,input:i,promptCatalog:s,heroes:r,setInput:l,setError:o}=e,[c,d]=(0,n.useState)(0),[u,p]=(0,n.useState)(null),[h,m]=(0,n.useState)(!1),[f,g]=(0,n.useState)(null),[x,v]=(0,n.useState)(!1),y=(0,n.useRef)(null),[b,k]=(0,n.useState)([]),j=(0,n.useCallback)(e=>{l(e),d(e=>e+1),p(null),(!e.startsWith("/")||/\s/.test(e.slice(1)))&&v(!1)},[l]),w=(0,n.useCallback)(async()=>{try{let e=await (0,e3.apiFetch)("/v1/graphs");k((e??[]).filter(e=>(e.latestVersion??0)>0).map(e=>({name:e.id,version:e.latestVersion})))}catch{}},[]);(0,n.useEffect)(()=>{let e=window.setTimeout(()=>void w(),0);return()=>window.clearTimeout(e)},[w]);let N=!!(t&&!i.slice(1).match(/[\s]/)&&(i.startsWith("/")&&s.templates.length>0||i.startsWith("@role")&&r.length>0||i.startsWith("@graph")&&b.length>0||i.startsWith("@")&&(r.length>0||b.length>0))),_=(0,n.useRef)(!1);(0,n.useEffect)(()=>{N&&!_.current&&(s.refresh(),w()),_.current=N},[N,s,w]);let C=(0,n.useCallback)(async(e,t)=>{y.current?.abort();let n=new AbortController;y.current=n;try{let a=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(t)}/prompt-templates/expand`,{method:"POST",body:JSON.stringify({invocation:e}),signal:n.signal});if(n.signal.aborted)return null;return a}catch(e){if(n.signal.aborted)return null;throw e}},[]);return{setInputVersioned:j,expandDraftOrFallback:(0,n.useCallback)(async(e,n,i)=>{m(!0),g(null);try{let i=await C(e,n.project);if(!i||n.project!==t||n.session!==a||n.draftVersion!==c)return null;switch(i.case){case"matched":{let e=i.text.trim();if(!e)return o("Expanded prompt is empty."),{status:"empty"};return l(e),d(e=>e+1),p(c+1),{status:"matched",text:e,diagnostics:i.diagnostics}}case"not_found":case"invalid_invocation":return{status:"fallthrough"}}}catch(e){return o(c4(e,i)),null}finally{m(!1)}},[o,t,a,c,C,l,d,p,m,g]),expandedVersion:u,draftVersion:c,flowCatalog:b,commandPanelOpen:N,promptPanelDismissed:x,setPromptPanelDismissed:v,expanding:h,expandDiag:f,setExpandDiag:g}}({selectedProject:a,selectedSession:t,input:c,promptCatalog:s,heroes:I,setInput:d,setError:l.setError});(0,n.useEffect)(()=>{z.current=t},[t]);let G=(0,n.useRef)(t);(0,n.useLayoutEffect)(()=>{let e=G.current;G.current=t,null===e&&t||(F(""),E([]),$(null),v())},[t,F,v]);let J=t?b[t]??i?.defaultModelProfileId??r.models.find(e=>e.isDefault)?.id??r.models[0]?.id??null:null,Y=t?N[t]??"default":"default",Q=(0,n.useCallback)(e=>{t&&_(n=>({...n,[t]:e}))},[t]),Z=(0,n.useCallback)(()=>{var e;let t,n;return e=r.policies,t=e.filter(e=>"tool"===e.kind&&"active"===e.status&&e.config.mode===j),n=RegExp(`^builtin-tool-${j}-v\\d+$`),t.find(e=>n.test(e.id))?.id??t[0]?.id},[j,r.policies]),X=(0,n.useCallback)(()=>(function(e,t){let n=dv(e?.effectiveConfig),a=dv(n?.hero)?.permissionCeiling;if(dx(a))return a;let i=dv(n?.toolPolicy)?.id,s=dv(e?.requestedConfig)?.toolPolicyProfileId;return function(e,t){if("string"!=typeof t||!t)return;let n=e.find(e=>e.id===t&&"tool"===e.kind),a=n?.config.mode;if(dx(a))return a;let i=/^builtin-tool-(discuss|ask|auto)-v\d+$/.exec(t)?.[1];return"discuss"===i||"ask"===i||"auto"===i?i:void 0}(t,i??s)})(l.activeRunRecord,r.policies)??j,[l.activeRunRecord,j,r.policies]),ee=(0,n.useCallback)(async(e,n)=>{if(!t)return;let a=function(e,t){if(0===t.length)return e;let n=t.map(e=>[`--- Attached file: ${e.name} ---`,e.text,`--- End attached file: ${e.name} ---`].join("\n"));return[e.trim(),...n].filter(Boolean).join("\n\n")}(e,p),i=p.length?`[Files: ${p.map(e=>e.name).join(", ")}]`:"",s=db();F(""),v(),l.setStatus(sS("sending")),l.appendTransient({id:s,role:"user",text:[e,u?`[Image: ${u.name}]`:"",i].filter(Boolean).join("\n")});try{let e=u?{content:[...a?[{type:"text",text:a}]:[],{type:"image",artifactId:u.id}]}:{text:a},i=I.find(e=>e.id===P)??null,s=`/v1/sessions/${encodeURIComponent(t)}/invocations`,r=R.map(e=>({id:e})),o=r.length>0?{...e,skills:r}:e,c=i&&i.currentVersionId?{...o,target:{kind:"hero",objectId:i.id,versionId:i.currentVersionId,contextMode:"room"}}:{...{...o,config:{toolPolicyProfileId:n,...J?{modelProfileId:J}:{},...Y?{thinkingEffort:Y}:{}}},target:{kind:"host"}},d=await (0,e3.apiFetch)(s,{method:"POST",headers:{"Idempotency-Key":db()},body:JSON.stringify(c)});if(z.current!==t)return;E([]),l.setError(null),l.watchRun(d.run)}catch(n){z.current===t&&(F(e),y(u,p),l.removeTransient(s),l.setStatus(""),l.setError(c4(n,"Failed to send the message")))}},[t,u,p,l,J,P,I,R,F,Y,v,y]),et=!!l.activeRunID,en=(0,n.useCallback)(async(e,n,a)=>{if(!t)return l.setError("Select a session before invoking a graph."),!1;let i={};if(a)for(let e of a.split(/\s+/)){let[t,...n]=e.split("=");t&&n.length>0&&(i[t]=n.join("="))}try{return await (0,e3.apiFetch)(`/v1/graphs/${encodeURIComponent(e)}/runs`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({sessionId:t,name:e,version:n??0,inputs:i})}),F(""),l.setError(null),!0}catch(e){return l.setError(e instanceof Error?e.message:"Failed to invoke graph"),!1}},[t,l,F]),ea=Z(),ei=(0,n.useCallback)(async()=>{if(!t||!c.trim()&&!u&&0===p.length&&!A||l.activeRunID)return;let e=c.trim().match(/^\/invoke_agent_flow\s+(\S+)(?:\s+([\s\S]+))?$/);if(e){let[t,n]=e[1].split("@");en(t,n?Number(n):void 0,e[2]);return}if(A){let e=c.trim(),t=e?/(^|\s)[A-Za-z_][\w-]*=/.test(e)?e:`prompt=${JSON.stringify(e)}`:void 0;en(A.name,A.version,t).then(e=>{e&&$(null)});return}let n=c.trim().match(/^@graph:([\w.-]+)(?:@(\d+))?(?:\s+([\s\S]+))?$/);if(n)return void en(n[1],n[2]?Number(n[2]):void 0,n[3]);if(!ea&&!P)return void l.setError(`The ${j} permission policy is unavailable.`);if(c.startsWith("/")&&D!==O&&a){let e=await L(c,{project:a,session:t,draftVersion:O},"Failed to expand prompt template");if(!e)return;if("matched"===e.status){e.diagnostics.some(e=>"arguments_fallback"===e.code)&&K("Arguments could not be fully parsed; using raw input.");return}"fallthrough"===e.status&&ee(c,ea??"");return}ee(c,ea??"")},[t,c,u,p.length,ea,j,A,l,ee,a,P,D,O,en,L,K]),es=(0,n.useCallback)(async()=>{if(l.activeRunID&&c.trim()){if(l.questionPending)return void l.setError(o("composer.answerQuestionFirst"));if(c.startsWith("/")&&D!==O&&a){let e=await L(c,{project:a,session:t,draftVersion:O},"Failed to expand");if(!e||"matched"===e.status)return;"fallthrough"===e.status&&(F(""),await l.steer(c)||F(c));return}F(""),await l.steer(c)||F(c)}},[l,c,a,t,D,O,F,L,o]),er=(0,n.useCallback)(async e=>!!l.activeRunID&&!!e.trim()&&(l.questionPending?(l.setError(o("composer.answerQuestionFirst")),!1):l.steer(e)),[l,o]),el=(0,n.useCallback)(async()=>{if(!l.activeRunID||!c.trim())return;F("");let{queued:e,runEnded:n}=await l.followUp(c);if(!e){if(n&&t)return void ee(c,ea??"");F(c)}},[l,c,ee,ea,t,F]),eo=(0,n.useCallback)(e=>{t&&(k(n=>({...n,[t]:e})),(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(t)}`,{method:"PATCH",body:JSON.stringify({defaultModelProfileId:e})}).then(()=>{z.current===t&&l.refreshSelectedSession()}).catch(e=>{z.current===t&&l.setError(c4(e,"Failed to select model"))}))},[l,t]),ec=(0,n.useCallback)(async()=>{if(!t||l.activeRunID)return;let e=await l.refreshSelectedSession();e?.activeLeafMessageId?S({open:!0,instructions:"",busy:!1}):l.setError("This session has no conversation history to compact.")},[l,t]),ed=(0,n.useCallback)(async()=>{if(!t||l.activeRunID)return;let e=C.instructions.trim();S(e=>({...e,busy:!0}));try{let n=await l.refreshSelectedSession();if(!n?.activeLeafMessageId){l.setError("This session has no conversation history to compact."),S({open:!1,instructions:"",busy:!1});return}let a=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(t)}/compactions`,{method:"POST",headers:{"Idempotency-Key":db()},body:JSON.stringify({baseMessageId:n.activeLeafMessageId,instructions:e})}),i=await (0,e3.apiFetch)(`/v1/runs/${encodeURIComponent(a.runId)}`);l.setError(null),S({open:!1,instructions:"",busy:!1}),l.watchRun(i)}catch(e){l.setError(e.message),S(e=>({...e,busy:!1}))}},[l,C.instructions,t]),eu=(0,n.useCallback)(()=>{S(e=>e.busy?e:{open:!1,instructions:"",busy:!1})},[]);return{composer:{sessionId:t,activeLeafMessageId:i?.activeLeafMessageId,input:c,setInput:F,pendingImage:u,clearPendingImage:x,uploadImage:e=>void h(e),textAttachments:p,removeTextAttachment:g,attachFiles:e=>void m(e),models:r.models.filter(e=>"active"===e.status),providers:r.providers,selectedModelId:J,setSelectedModelId:eo,thinkingEffort:Y,setThinkingEffort:Q,heroes:I,selectedHeroId:P,setSelectedHeroId:T,permissionMode:j,displayedPermissionMode:X(),permissionReady:!!ea,setPermissionMode:w,compactSession:()=>void ec(),compaction:{open:C.open,instructions:C.instructions,busy:C.busy,setInstructions:e=>S(t=>({...t,instructions:e})),confirm:()=>void ed(),cancel:eu},promptPanel:{templates:s.templates,heroes:I.map(e=>({id:e.id,handle:e.handle,name:e.name,description:e.description})),flows:q,show:B&&!U,skills:M.skills,oneShotLocked:et,pendingSkills:R,pendingGraph:A,toggleSkill:e=>E(t=>t.includes(e)?t.filter(t=>t!==e):[...t,e]),clearPendingGraph:()=>$(null),onSelect:e=>{H(!1),F(`/${e} `)},onHeroSelect:e=>{T(""===e?null:e),H(!0)},onFlowSelect:(e,t)=>{H(!1),$({name:e,version:t})},onClose:()=>H(!0),expanding:W,expandDiag:V}},actions:{submit:ei,steer:es,steerText:er,followUp:el}}}({selectedSession:c,selectedProject:u,sessionRecord:d,promptCatalog:p,settings:h,runtime:{activeRunID:w.activeRunID,activeRunRecord:w.activeRun,questionPending:w.pendingApproval?.kind==="question",setStatus:w.setStatus,setError:w.setError,watchRun:w.watchRun,steer:w.steer,followUp:w.followUp,appendTransient:j.appendTransient,removeTransient:j.removeTransient,refreshSelectedSession:k}}),P=w.activeRunID,{decideApproval:T}=w,{createBranch:M}=C,R=(0,n.useCallback)(async e=>{P||await M(e)},[P,M]),E=async e=>{P||await C.activateBranch(e)},A=(0,n.useCallback)(e=>void T(e),[T]),$=(0,n.useCallback)(e=>void R(e),[R]),z=(0,n.useCallback)(async()=>{let e=await N.retry();e&&w.watchRun(e)},[N,w]),F=(0,n.useCallback)(()=>{w.setError(null),N.clearError(),C.clearError()},[w,N,C]),L=w.error??N.error??C.error,D={sessionId:c,activeBranchId:v,activeLeafMessageId:y,messages:j.messages,loading:j.loading,loadingOlder:j.loadingOlder,error:j.historyError,hasMore:j.hasMore,loadOlder:j.loadOlder};return{history:D,run:{activeRun:w.activeRunID,inspectorRunId:w.activeRunID??function(e){for(let t=e.length-1;t>=0;t-=1){let n=e[t];if("turn"===n.kind&&n.runId)return n.runId}return null}(j.messages),activeRunStatus:w.activeRun?.status,startedAt:w.activeRun?.startedAt||w.activeRun?.createdAt||null,status:w.status,usage:w.usage,contextUsage:w.contextUsage,stats:_,compacting:w.compacting,pendingApproval:w.pendingApproval,resolvingApproval:w.resolvingApproval,decideApproval:A,answeringQuestion:w.answeringQuestion,answerQuestion:w.answerQuestion,cancel:()=>void w.cancel(),pendingFollowUps:w.pendingFollowUps,cancelFollowUp:w.cancelFollowUp,recovery:N.recovery,retrying:N.retrying,retryRun:()=>void z(),error:w.error,setError:w.setError,clearError:()=>w.setError(null)},branches:{branches:C.branches,activeBranchId:v,loading:C.loading,changing:C.changing,error:C.error,createBranch:$,activateBranch:e=>void E(e)},composer:S,actions:I,error:L,clearError:F}}({selectedSession:y,sessionRecord:B,selectedProject:r,promptCatalog:U,settings:O,replaceSession:q}),W=function(e,t){let[a,i]=(0,n.useState)(new Set),s=[...new Set(e)].sort().join("\0");return(0,n.useEffect)(()=>{if(!s)return;let e=s.split("\0"),t=new AbortController,n=async()=>{let n=await Promise.all(e.map(async e=>{try{let n=await (0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/active-runs`,{signal:t.signal});return n?.sessionIds??[]}catch{return[]}}));t.signal.aborted||i(new Set(n.flat()))};n();let a=window.setInterval(()=>void n(),15e3);return()=>{t.abort(),window.clearInterval(a)}},[s]),(0,n.useMemo)(()=>{let e=new Set(s?a:[]);return t&&e.add(t),e},[t,a,s])}(D.groups.flatMap(e=>[e.projectId]),H.run.activeRun?y:null),K=O.refresh,G=(0,n.useCallback)(e=>{u(e),K()},[K,u]),{closeSettings:J}=function({loading:e,error:t,providers:a,openSettings:i,closeSettings:s}){let r=(0,n.useRef)(!1),l=(0,n.useCallback)(()=>{try{window.localStorage.setItem(cX,"1")}catch{}s()},[s]);return(0,n.useEffect)(()=>{if(r.current||e||t||a.some(e=>e.credentialConfigured))return;let n=!1;try{n="1"===window.localStorage.getItem(cX)}catch{}n||(r.current=!0,i("models"))},[e,t,a,i]),{closeSettings:l}}({loading:O.loading,error:O.error,providers:O.providers,openSettings:G,closeSettings:p}),Y=(0,n.useCallback)(e=>{l(e),N("chat"),_(null),L.setView("active"),L.setQuery(""),a&&F()},[N,F,a,_,L,l]),Q=(0,n.useCallback)(async e=>{let t=k.current;try{let n=await (0,dE.reuseOrCreateBlankSession)(e,L.activeSessions);H.run.setError(null),L.replaceSession(n),k.current===t&&(_(n.id),N("chat")),await L.refresh(),D.refresh(e)}catch(e){H.run.setError(e.message)}},[N,_,L,D,H.run]),Z=(0,n.useCallback)(async e=>{l(e),await Q(e)},[Q,l]),X=(0,n.useCallback)(async()=>{r&&await Z(r)},[Z,r]);!function(e){let{projectsReady:t,selectedProject:a,selectedSession:i,sessions:s,sessionsLoading:r,selectSession:l,connectBlank:o}=e,c=(0,n.useRef)("waiting");(0,n.useEffect)(()=>{if(!t)return;if(!a){i&&l(null),c.current="done";return}if(r)return;if(i&&s.some(e=>e.id===i)){(0,dE.writeStoredId)(dE.SELECTED_SESSION_KEY,i),c.current="done";return}if("done"===c.current){if(i)return;let e=s.find(R.isBlankSession);e&&l(e.id);return}if("connecting"===c.current)return;let e=(0,dE.readStoredId)(dE.SELECTED_SESSION_KEY);if(e&&s.some(t=>t.id===e)){l(e),c.current="done";return}c.current="connecting",i&&l(null),o(a).finally(()=>{c.current="done"})},[t,a,i,s,r,l,o])}({projectsReady:s,selectedProject:r,selectedSession:y,sessions:L.activeSessions,sessionsLoading:L.loading,selectSession:_,connectBlank:Q});let ee=(0,n.useCallback)(async(e,t)=>{let n=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e.id)}`,{method:"PATCH",body:JSON.stringify({title:t})});L.replaceSession(n),D.refresh(e.projectId)},[L,D]),et=(0,n.useCallback)(async(e,t)=>{await x(e,t),D.refresh(e)},[x,D]),en=(0,n.useCallback)(async e=>{await v(e)},[v]),ea=(0,n.useCallback)(e=>{J(),N("chat"),_(e),(0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(e)}`).then(L.replaceSession).catch(()=>{}),a&&F()},[N,F,J,a,_,L]),ei=(0,n.useCallback)(async e=>{let t=await L.archive(e);t&&(D.refresh(e.projectId),D.refreshArchived(e.projectId)),t&&y===e.id&&_(null)},[_,L,D,y]),es=(0,n.useCallback)(async e=>{await L.restore(e),D.refresh(e.projectId),D.refreshArchived(e.projectId)},[L,D]),er=B?.projectId??r,{currentCwd:el,panel:eo,handleOpenFile:ec,handleOpenFileToSide:ed,handlePreviewFile:eu,panelOpen:ep,openPanel:eh,closePanel:em}=function({projectId:e,workspaceFor:t,setRunError:a,onPreviewFile:i}){let s=e?t(e)??null:null,r=s?.hostPath??null;(0,n.useEffect)(()=>{if(!e||t(e))return;let n=new AbortController;return(0,e3.apiFetch)(`/v1/projects/${encodeURIComponent(e)}/workspace`,{signal:n.signal}).catch(e=>{n.signal.aborted||a(e.message)}),()=>n.abort()},[e,a,t]);let l=function(e){let[t,a]=(0,n.useState)(()=>og(oh(e??""))),[i,s]=(0,n.useState)(null),[r,l]=(0,n.useState)(0),o=(0,n.useRef)(new Map),c=(0,n.useRef)(null),d=(0,n.useRef)(!1),u=(0,n.useRef)(null),p=(0,n.useRef)(!1),h=e??"",m=(0,n.useCallback)(e=>{var t;if(!e||!e.projectId||null===i||p.current||d.current)return;let n=JSON.stringify({version:1,projectId:(t={version:1,projectId:e.projectId,pinnedChannels:om(e.pinnedChannels),primaryWidths:{files:ob(e.primaryWidths.files,280),graph:ob(e.primaryWidths.graph,280),tools:ob(e.primaryWidths.tools,280)},open:e.open,inspectorTabs:of(e.inspectorTabs),activeInspectorIds:e.activePanes,activeInspectorId:e.activePanes[e.focusedPane],navigatorHidden:e.navigatorHidden}).projectId,pinnedChannels:om(t.pinnedChannels),primaryWidths:{files:ob(t.primaryWidths?.files,280),graph:ob(t.primaryWidths?.graph,280),tools:ob(t.primaryWidths?.tools,280)},open:t.open,inspectorTabs:of(t.inspectorTabs),navigatorHidden:!0===t.navigatorHidden,activeInspectorIds:{main:t.activeInspectorIds?t.activeInspectorIds.main??null:t.activeInspectorId??null,side:t.activeInspectorIds?t.activeInspectorIds.side??null:null},activeInspectorId:t.activeInspectorIds?t.activeInspectorIds.main??null:t.activeInspectorId??null});if(c.current!==n)try{window.localStorage.setItem(op(e.projectId),n),c.current=n}catch{}},[i]);(0,n.useEffect)(()=>{if(i===h)return;m(u.current);let t=e?function(e,t){try{return function(e,t){let n;if(null===e)return oh(t);try{n=JSON.parse(e)}catch{return oh(t)}if("object"!=typeof n||null===n)return oh(t);let a=n;if(1!==a.version||a.projectId!==t)return oh(t);let i=Array.isArray(a.pinnedChannels)?om(a.pinnedChannels.filter(ou)):[],s="number"==typeof a.primaryWidth&&Number.isFinite(a.primaryWidth)?a.primaryWidth:280,r="object"==typeof a.primaryWidths&&null!==a.primaryWidths?a.primaryWidths:{},l={files:ob(r.files,s),graph:ob(r.graph,s),tools:ob(r.tools,s)},o=of(a.inspectorTabs),c="string"==typeof a.activeInspectorId?a.activeInspectorId:null,d="object"==typeof a.activeInspectorIds&&null!==a.activeInspectorIds?a.activeInspectorIds:{},u=(e,n)=>{let a="string"==typeof n?n:"main"===e?c:null;return null===a?null:o.some(n=>(n.pane??"main")===e&&`file:${t}:${n.path}`===a)?a:null},p={main:u("main",d.main),side:u("side",d.side)},h=p.main??p.side;return{version:1,projectId:t,pinnedChannels:i,primaryWidths:l,open:!0===a.open,inspectorTabs:o,activeInspectorId:h,activeInspectorIds:p,navigatorHidden:!0===a.navigatorHidden}}(window.localStorage.getItem(op(e)),e)}catch{return t.current=!0,oh(e)}}(e,p):oh("");a(()=>{let n=og(t),a=n.inspectorTabs.map(t=>ov(e??"",t.path)),i=o.current.get(h)??n.activePanes[n.focusedPane]??void 0,s=void 0!==i&&a.includes(i)?i:null;if(null===s){let t=n.inspectorTabs[0];if(!t)return{...n,activePanes:{main:null,side:null},activeLane:"channel"};let a=ov(e??"",t.path),i=t.pane??"main";return{...n,activePanes:{...n.activePanes,[i]:a},focusedPane:i,activeLane:"inspector"}}let r=n.inspectorTabs.find(t=>ov(e??"",t.path)===s)?.pane??"main";return{...n,activePanes:{...n.activePanes,[r]:s},focusedPane:r,activeLane:"inspector"}}),s(h)},[h,e,i,m]);let f=(0,n.useMemo)(()=>{let n=t.projectId===e?t.inspectorTabs:[],a=t=>({id:ov(e??"",t.path),label:t.name,filePath:t.path,projectId:e??void 0});return{main:n.filter(e=>(e.pane??"main")==="main").map(a),side:n.filter(e=>"side"===e.pane).map(a)}},[t.projectId,t.inspectorTabs,e]),g=(0,n.useMemo)(()=>[...f.main,...f.side],[f]),x=(0,n.useMemo)(()=>g.map(e=>e.id),[g]),v=t.activePanes[t.focusedPane],y="inspector"===t.activeLane&&null!==v&&x.includes(v)?v:null,b=ou(t.activeChannelId)&&t.openChannels.includes(t.activeChannelId)?t.activeChannelId:t.openChannels[0]??null;(0,n.useEffect)(()=>{!e||t.projectId!==e||i!==e||d.current||p.current||m(t)},[e,t,i,r,m]),(0,n.useEffect)(()=>{u.current=t},[t]);let k=(0,n.useCallback)((t,n,i="main")=>{if(!e)return;let s=ov(e,t);o.current.set(e,s),a(e=>ok(e,s,{path:t,name:n,pane:i}))},[e]),j=(0,n.useCallback)(t=>{ou(t)||o.current.set(e??"",t),a(e=>ou(t)?oy(e,t):ok(e,t,e.inspectorTabs.find(n=>ov(e.projectId,n.path)===t)??{path:ox(t),name:ox(t).split("/").filter(Boolean).pop()??t}))},[e]),w=(0,n.useCallback)(t=>{ou(t)||(o.current.get(e??"")===t&&o.current.delete(e??""),a(e=>{let n,a,i,s,r,l,o,c,d;return n=ox(t),a=e.inspectorTabs.find(e=>e.path===n),i=e.inspectorTabs.filter(e=>e.path!==n),s=a?.pane??"main",r=i.filter(e=>(e.pane??"main")===s).map(t=>ov(e.projectId,t.path)),(l={...e.activePanes})[s]===t&&(l[s]=r[r.length-1]??null),o="main"===s?"side":"main",c=null===l[s]&&null!==l[o]?o:e.focusedPane,d=i.length>0,{...e,inspectorTabs:i,activePanes:l,focusedPane:c,activeLane:d?e.activeLane:"channel"}}))},[e]),N=(0,n.useCallback)((e,t)=>{a(n=>(function(e,t,n){let a=e.inspectorTabs.findIndex(e=>e.path===t),i=e.inspectorTabs.findIndex(e=>e.path===n);if(a<0||i<0||a===i||(e.inspectorTabs[a].pane??"main")!==(e.inspectorTabs[i].pane??"main"))return e;let s=[...e.inspectorTabs],[r]=s.splice(a,1);return s.splice(i,0,r),{...e,inspectorTabs:s}})(n,ox(e),ox(t)))},[]),_=(0,n.useCallback)(()=>{a(e=>{var t;return t=!e.navigatorHidden,e.navigatorHidden===t?e:{...e,navigatorHidden:t}})},[]),C=(0,n.useCallback)(e=>{a(t=>(function(e,t){if(!e.openChannels.includes(t))return e;let n=e.openChannels.filter(e=>e!==t);if(e.activeChannelId!==t)return{...e,openChannels:n};let a=od.filter(e=>n.includes(e));return{...e,openChannels:n,activeChannelId:a[0]??null,activeLane:e.activeLane}})(t,e))},[]),S=(0,n.useCallback)(e=>{a(t=>oy(t,e))},[]),I=(0,n.useCallback)(e=>{a(t=>{let n;return t.pinnedChannels.includes(e)?t.pinnedChannels.includes(e)?{...t,pinnedChannels:t.pinnedChannels.filter(t=>t!==e)}:t:(n=t.pinnedChannels.includes(e)?t.pinnedChannels:om([...t.pinnedChannels,e]),oy({...t,pinnedChannels:n},e))})},[]),P=(0,n.useCallback)((e,t)=>{a(n=>{var a;let i=ou(n.activeChannelId)?n.activeChannelId:null;if(null===i)return n;let s=lL(n.primaryWidths[i],t);return a=lL(s+e,t),n.primaryWidths[i]===a?n:{...n,primaryWidths:{...n.primaryWidths,[i]:a}}})},[]),T=(0,n.useCallback)(()=>{d.current=!0},[]),M=(0,n.useCallback)(()=>{d.current=!1,l(e=>e+1)},[]);return{fileTabs:g,paneTabs:f,activePanes:t.activePanes,focusedPane:t.focusedPane,activeTabId:y??b??"files",activeInspectorId:y,activeChannelId:b,setActiveTabId:j,openInspector:k,closeTab:w,reorderTabs:N,closeChannelTab:C,toggleNavigator:_,openChannel:S,togglePin:I,resizePrimaryBy:P,beginPrimaryResize:T,endPrimaryResize:M,state:t,open:t.open,openShell:()=>a(e=>e.open?e:{...e,open:!0}),closeShell:()=>a(e=>e.open?{...e,open:!1}:e)}}(e),{openInspector:o}=l,c=(0,n.useCallback)((e,t)=>{o(e,t)},[o]);return{currentWorkspace:s,currentCwd:r,panel:l,handleOpenFile:c,handleOpenFileToSide:(0,n.useCallback)((e,t)=>{o(e,t,"side")},[o]),handlePreviewFile:(0,n.useCallback)((t,n)=>{e&&i({projectId:e,path:t,name:n})},[e,i]),panelOpen:l.open,openPanel:l.openShell,closePanel:l.closeShell}}({projectId:er,workspaceFor:h,setRunError:H.run.setError,onPreviewFile:A}),ef=function(e){let{session:t,replaceSession:a}=e,[i,s]=(0,n.useState)(!1),[r,l]=(0,n.useState)(""),o=(0,n.useRef)(null),c=(0,n.useCallback)(e=>e&&(e.title||e.id?.slice(0,12))||"",[]),d=(0,n.useCallback)(()=>{t&&(l(t.title||c(t)),s(!0),setTimeout(()=>o.current?.select(),0))},[c,t]),u=(0,n.useCallback)(async()=>{if(!t)return void s(!1);let e=r.trim();if(s(!1),e!==(t.title??""))try{let n=await (0,e3.apiFetch)(`/v1/sessions/${encodeURIComponent(t.id)}`,{method:"PATCH",body:JSON.stringify({title:e})});a(n)}catch{}},[t,r,a]),p=(0,n.useCallback)(e=>{"Enter"===e.key?(e.preventDefault(),u()):"Escape"===e.key&&(e.preventDefault(),e.stopPropagation(),s(!1))},[u]);return{title:t?c(t):"No session",editing:i,draft:r,setDraft:l,startEdit:d,save:u,keyDown:p,inputRef:o}}({session:B,replaceSession:L.replaceSession}),eg=el?el.replace(/\/+$/,"").split(/[\\/]/).filter(Boolean).pop()||el:"",ex=(0,t.jsx)(V,{projects:i,groups:D.groups,selectedProject:r,selectedSession:y,settingsOpen:c,query:L.query,setQuery:L.setQuery,mutatingId:L.mutatingId,announcement:L.announcement,pinnedProjectIds:g,togglePinProject:m,renameProject:et,deleteProject:en,collapsed:D.collapsed,toggleCollapsed:D.toggleCollapsed,archived:D.archived,openArchived:D.openArchived,createProject:o,createSession:X,createSessionIn:Z,renameSession:ee,switchProject:Y,switchSession:ea,archiveSession:e=>void ei(e),restoreSession:e=>void es(e),openSettings:G,closeNavigation:F,runningSessionIds:W,onToggleSidebar:()=>P(e=>!e),projectSelector:S,view:j,setView:N}),ev=H.error??L.error,ey=(0,n.useSyncExternalStore)(dA,d$,dz);return(0,t.jsx)(rk,{children:(0,t.jsxs)(t.Fragment,{children:[(0,t.jsxs)("div",{className:"app-shell","data-testid":"ennote-shell",children:[(0,t.jsx)("div",{className:"sidebar-overlay-backdrop","data-open":I||void 0,onClick:F}),(0,t.jsx)("div",{className:`sidebar-container${I?" sidebar-open":" sidebar-closed"}`,role:a&&I?"dialog":void 0,"aria-modal":a&&I?"true":void 0,"aria-label":a&&I?"Navigation":void 0,id:"workspace-navigation",style:{width:a?void 0:I?C.width:0,minWidth:a?void 0:I?C.width:0,transition:I||C.isResizing?"none":void 0},children:ex}),I&&!a&&(0,t.jsx)(l$,{side:"right",ariaLabel:"Resize sidebar",value:C.width,min:264,max:420,onResizeStart:C.beginResize,onResize:C.resizeBy,onResizeEnd:C.endResize}),(0,t.jsxs)("div",{className:"workspace-content",inert:a&&I,children:[(0,t.jsx)(cJ,{workerUnreachable:ey}),"chat"===j?(0,t.jsxs)(t.Fragment,{children:[(0,t.jsx)(r3,{sidebarOpen:I,onToggleSidebar:()=>P(e=>!e),navigationTriggerRef:$,session:B,title:ef,projectName:eg,projectPath:el,branch:{branches:H.branches.branches,activeBranchId:H.branches.activeBranchId,loading:H.branches.loading,changing:H.branches.changing,disabled:!!H.run.activeRun,onActivate:H.branches.activateBranch},rightPanelOpen:ep,onToggleRightPanel:()=>ep?em():eh(),attention:{projectId:r??er??void 0,onNavigate:e=>{e.sessionId&&e.sessionId!==y&&ea(e.sessionId)}}}),(0,t.jsx)(rD,{history:H.history,run:H.run,branches:H.branches,composer:H.composer,actions:H.actions,error:ev,clearError:()=>{H.clearError(),L.setError(null)},projects:i,selectedProject:r,hasModel:O.models.length>0,pinnedProjectIds:g,togglePinProject:m,onSwitchProject:e=>void Z(e),onNewProject:o,onOpenSettings:G})]}):(0,t.jsx)(dR,{view:j,models:O.models,providers:O.providers,onBackToChat:()=>N("chat"),onOpenMobileNav:()=>P(!0),menuTriggerRef:z})]}),"chat"===j&&ep&&(0,t.jsx)(ow,{resize:T}),"chat"===j&&(0,t.jsx)(oj,{open:ep,onClose:em,resize:T,panel:eo,projectId:er??null,displayPath:el,onOpenFile:ec,onOpenFileToSide:ed,onPreviewFile:eu,selectedSession:y,sessionTitle:B?.title||y||"",activeRun:H.run.activeRun,inspectorRunId:H.run.inspectorRunId,status:H.run.status,permissionMode:H.composer.displayedPermissionMode})]}),E&&(0,t.jsx)(oN,{projectId:E.projectId,filePath:E.path,fileName:E.name,onClose:()=>A(null)}),(0,t.jsx)(cK,{settingsOpen:c,settingsTab:d,onCloseSettings:J,providers:O.providers,models:O.models,policies:O.policies,session:B,projectId:r,error:O.error,refresh:O.refresh,setError:O.setError,onSessionUpdated:L.replaceSession})]})})}],59665)}]);
|