@oscharko-dev/keiko 0.2.13 → 0.2.14
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/dist/ui/csp-hashes.json +11 -11
- package/dist/ui/static/404.html +1 -1
- package/dist/ui/static/__next.__PAGE__.txt +2 -2
- package/dist/ui/static/__next._full.txt +2 -2
- package/dist/ui/static/__next._head.txt +1 -1
- package/dist/ui/static/__next._index.txt +1 -1
- package/dist/ui/static/__next._tree.txt +1 -1
- package/dist/ui/static/_next/static/chunks/{1a_fruu6pucj3.js → 00z66zbbbra-j.js} +3 -3
- package/dist/ui/static/_next/static/chunks/{43qhz7noctvzl.js → 1r5hnsrgkrath.js} +1 -1
- package/dist/ui/static/_next/static/chunks/{1fi98c2i0d9nw.js → 3324vgiq57xc4.js} +1 -1
- package/dist/ui/static/_next/static/chunks/3e9ez0whrt_3e.js +1 -0
- package/dist/ui/static/_next/static/chunks/3m-1c900pj68k.css +1 -0
- package/dist/ui/static/_next/static/chunks/3uf9j0-nj02sh.js +1 -0
- package/dist/ui/static/_not-found/__next._full.txt +1 -1
- package/dist/ui/static/_not-found/__next._head.txt +1 -1
- package/dist/ui/static/_not-found/__next._index.txt +1 -1
- package/dist/ui/static/_not-found/__next._not-found.__PAGE__.txt +1 -1
- package/dist/ui/static/_not-found/__next._not-found.txt +1 -1
- package/dist/ui/static/_not-found/__next._tree.txt +1 -1
- package/dist/ui/static/_not-found.html +1 -1
- package/dist/ui/static/_not-found.txt +1 -1
- package/dist/ui/static/index.html +1 -1
- package/dist/ui/static/index.txt +2 -2
- package/dist/ui/static/launch/__next._full.txt +2 -2
- package/dist/ui/static/launch/__next._head.txt +1 -1
- package/dist/ui/static/launch/__next._index.txt +1 -1
- package/dist/ui/static/launch/__next._tree.txt +1 -1
- package/dist/ui/static/launch/__next.launch.__PAGE__.txt +2 -2
- package/dist/ui/static/launch/__next.launch.txt +1 -1
- package/dist/ui/static/launch.html +1 -1
- package/dist/ui/static/launch.txt +2 -2
- package/dist/ui/static/local-knowledge/__next._full.txt +2 -2
- package/dist/ui/static/local-knowledge/__next._head.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._index.txt +1 -1
- package/dist/ui/static/local-knowledge/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/__next.local-knowledge.__PAGE__.txt +2 -2
- package/dist/ui/static/local-knowledge/__next.local-knowledge.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._full.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._head.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._index.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next._tree.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.__PAGE__.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.capsule.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule/__next.local-knowledge.txt +1 -1
- package/dist/ui/static/local-knowledge/capsule.html +1 -1
- package/dist/ui/static/local-knowledge/capsule.txt +1 -1
- package/dist/ui/static/local-knowledge.html +1 -1
- package/dist/ui/static/local-knowledge.txt +2 -2
- package/dist/ui/static/memoriaviva/__next._full.txt +1 -1
- package/dist/ui/static/memoriaviva/__next._head.txt +1 -1
- package/dist/ui/static/memoriaviva/__next._index.txt +1 -1
- package/dist/ui/static/memoriaviva/__next._tree.txt +1 -1
- package/dist/ui/static/memoriaviva/__next.memoriaviva.__PAGE__.txt +1 -1
- package/dist/ui/static/memoriaviva/__next.memoriaviva.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next._full.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next._head.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next._index.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next._tree.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.consolidation.__PAGE__.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.consolidation.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation/__next.memoriaviva.txt +1 -1
- package/dist/ui/static/memoriaviva/consolidation.html +1 -1
- package/dist/ui/static/memoriaviva/consolidation.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next._full.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next._head.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next._index.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next._tree.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.detail.__PAGE__.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.detail.txt +1 -1
- package/dist/ui/static/memoriaviva/detail/__next.memoriaviva.txt +1 -1
- package/dist/ui/static/memoriaviva/detail.html +1 -1
- package/dist/ui/static/memoriaviva/detail.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next._full.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next._head.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next._index.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next._tree.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.review-queue.__PAGE__.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.review-queue.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue/__next.memoriaviva.txt +1 -1
- package/dist/ui/static/memoriaviva/review-queue.html +1 -1
- package/dist/ui/static/memoriaviva/review-queue.txt +1 -1
- package/dist/ui/static/memoriaviva.html +1 -1
- package/dist/ui/static/memoriaviva.txt +1 -1
- package/node_modules/@oscharko-dev/keiko-cli/package.json +14 -14
- package/node_modules/@oscharko-dev/keiko-contracts/dist/documentation-browser.d.ts +83 -0
- package/node_modules/@oscharko-dev/keiko-contracts/dist/documentation-browser.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-contracts/dist/documentation-browser.js +307 -0
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts +4 -2
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/index.js +3 -2
- package/node_modules/@oscharko-dev/keiko-contracts/dist/local-knowledge-embedding-profiles.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-contracts/dist/local-knowledge-embedding-profiles.js +7 -0
- package/node_modules/@oscharko-dev/keiko-contracts/package.json +1 -1
- package/node_modules/@oscharko-dev/keiko-evaluations/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-evidence/package.json +4 -4
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-harness/package.json +6 -6
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/store-content-encryption.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/store-content-encryption.js +10 -3
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-local-knowledge/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-capture/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-consolidation/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-governance/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-retrieval/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-memory-vault/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-model-gateway/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-quality-intelligence/package.json +3 -3
- package/node_modules/@oscharko-dev/keiko-sandbox/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-sdk/package.json +9 -9
- package/node_modules/@oscharko-dev/keiko-security/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-security/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-security/package.json +2 -2
- package/node_modules/@oscharko-dev/keiko-server/dist/docs-browser.d.ts +4 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/docs-browser.d.ts.map +1 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/docs-browser.js +137 -0
- package/node_modules/@oscharko-dev/keiko-server/dist/grounded-retrieval-eval.js +4 -4
- package/node_modules/@oscharko-dev/keiko-server/dist/routes.d.ts.map +1 -1
- package/node_modules/@oscharko-dev/keiko-server/dist/routes.js +3 -0
- package/node_modules/@oscharko-dev/keiko-server/package.json +19 -19
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-tools/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-verification/package.json +5 -5
- package/node_modules/@oscharko-dev/keiko-workflows/package.json +10 -10
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.d.ts +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/dist/version.js +1 -1
- package/node_modules/@oscharko-dev/keiko-workspace/package.json +3 -3
- package/package.json +22 -22
- package/release-impact.catalog.json +47 -0
- package/dist/ui/static/_next/static/chunks/10_smqoa8jvj7.js +0 -1
- /package/dist/ui/static/_next/static/{r0VdLXKyCNsr8xWF_pD0_ → jl8jH3yyn14ivcsupg7WV}/_buildManifest.js +0 -0
- /package/dist/ui/static/_next/static/{r0VdLXKyCNsr8xWF_pD0_ → jl8jH3yyn14ivcsupg7WV}/_clientMiddlewareManifest.js +0 -0
- /package/dist/ui/static/_next/static/{r0VdLXKyCNsr8xWF_pD0_ → jl8jH3yyn14ivcsupg7WV}/_ssgManifest.js +0 -0
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,89199,e=>{"use strict";let t,n;var l=e.i(43476),r=e.i(71645),i=e.i(80144);let a=(0,r.createContext)(null);function o(e){let{value:t,children:n}=e;return(0,l.jsx)(a.Provider,{value:t,children:n});}let s=(0,r.createContext)(null);function c(e){let{children:t}=e,[n,i]=(0,r.useState)(""),[a,o]=(0,r.useState)(""),c=(0,r.useRef)(0),d=(0,r.useCallback)((e,t)=>{c.current+=1;let n=c.current%2==0?e:`${e}`;(null==t?void 0:t.assertive)===!0?o(n):i(n);},[]),u=(0,r.useMemo)(()=>({announce:d}),[d]);return(0,l.jsxs)(s.Provider,{value:u,children:[t,(0,l.jsx)("div",{className:"visually-hidden",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"app-announcer-polite",children:n}),(0,l.jsx)("div",{className:"visually-hidden",role:"alert","aria-live":"assertive","aria-atomic":"true","data-testid":"app-announcer-assertive",children:a})]});}var d=e.i(70045);let u=["provisioning","active","paused","handoff-ready","archived","merged","abandoned","recovery-required","failed","cleanup-pending"],p={provisioning:["active","recovery-required","failed","cleanup-pending"],active:["paused","handoff-ready","recovery-required","failed","cleanup-pending"],paused:["active","handoff-ready","archived","abandoned","recovery-required","cleanup-pending"],"handoff-ready":["active","merged","archived","abandoned","recovery-required","cleanup-pending"],merged:["archived","cleanup-pending"],archived:["cleanup-pending"],abandoned:["cleanup-pending"],"recovery-required":["active","paused","failed","abandoned","cleanup-pending"],failed:["recovery-required","abandoned","cleanup-pending"],"cleanup-pending":["archived","abandoned","recovery-required"]},f=["retryable","repairable","blocked","policy-denied","terminal"];async function m(e,t){return(0,d.bffFetchJson)(e,t,{enrichError:(e,t)=>{let n=null==t?void 0:t.error.failureClass;Object.assign(e,{failureClass:"string"==typeof n&&f.includes(n)?n:void 0});}});}async function h(e){return m("/api/task-workspaces",{method:"POST",body:JSON.stringify(e)});}async function g(e){let t=new URLSearchParams();return t.set("root",e),(await m(`/api/task-workspaces?${t.toString()}`)).instances;}async function v(){return(await m("/api/task-workspaces/active")).active;}async function w(e){return m("/api/task-workspaces/active",{method:"POST",body:JSON.stringify(e)});}async function y(){await m("/api/task-workspaces/active",{method:"DELETE"});}async function b(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/pause`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function k(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/resume`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function x(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/handoff`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}let C="studio-operator",j={instances:[],active:null,loading:!1,switching:!1,error:null};function S(e,t){switch(t.kind){case"load-start":return{...e,loading:!0,error:null};case"mutate-start":return{...e,switching:!0,error:null};case"settle":return{instances:t.instances,active:t.active,loading:!1,switching:!1,error:null};case"fail":return{...e,loading:!1,switching:!1,error:t.error};default:return e;}}function N(e){return e instanceof Error?e.message:"Task workspace action failed.";}var I=e.i(17161);let E={success:"var(--feedback-success, #2e7d32)",warning:"var(--feedback-warning, #b8860b)",danger:"var(--feedback-danger, #c0392b)",info:"var(--feedback-info, #2b6cb0)",muted:"var(--text-tertiary, #888)"},R={healthy:"success",degraded:"warning",drifted:"warning","locked-out":"danger",missing:"danger",unknown:"muted"};function A(e){return e.driftMarkers.includes("uncommitted-changes");}function P(e,t,n){let r=E[t],i={display:"inline-flex",alignItems:"center",gap:"0.25rem",padding:"0.05rem 0.4rem",borderRadius:"var(--radius-sm, 4px)",fontSize:"0.72rem",fontWeight:600,color:"var(--text-primary, #111)",background:`color-mix(in oklch, ${r} 18%, var(--surface-raised, var(--surface, transparent)))`,border:`1px solid color-mix(in oklch, ${r} 48%, var(--border-subtle, transparent))`};return(0,l.jsx)("span",{className:"tw-switcher-badge",style:i,title:n,children:e});}function M(e){var t,n;let r,{instance:i}=e,a=A(i);return(0,l.jsxs)("div",{className:"tw-switcher-active",children:[(0,l.jsxs)("div",{className:"tw-switcher-identity",children:[(0,l.jsx)("strong",{className:"tw-switcher-task",title:i.taskId,children:i.taskId}),(0,l.jsxs)("span",{className:"tw-switcher-branch",title:i.taskBranch,children:[i.taskBranch,(0,l.jsxs)("span",{className:"tw-switcher-base",children:[" ← ",i.baseBranch]})]})]}),(0,l.jsxs)("div",{className:"tw-switcher-badges",style:{display:"flex",flexWrap:"wrap",gap:"0.3rem"},children:[P(i.lifecycleState,"info","Lifecycle state"),P(i.health,R[i.health],"Workspace health"),a?P("uncommitted","warning","The worktree has uncommitted changes"):P("clean","success","The worktree is clean"),null!==i.lock?P(`locked: ${i.lock.reason}`,"danger",`Held by ${i.lock.owner}`):null]}),(0,l.jsx)("p",{className:"tw-switcher-path",style:{fontSize:"0.72rem",color:E.muted},children:(0,l.jsx)("span",{title:i.managedWorktreePath,children:null!=(n=(r=(t=i.managedWorktreePath).replace(/[/\\]+$/u,"").split(/[/\\]/u))[r.length-1])?n:t})}),(0,l.jsxs)("p",{className:"tw-switcher-activity",style:{fontSize:"0.7rem",color:E.muted},children:["Updated ",i.updatedAt]}),i.recoveryHints.length>0?(0,l.jsxs)("details",{className:"tw-switcher-recovery",children:[(0,l.jsxs)("summary",{children:["Recovery hints (",i.recoveryHints.length,")"]}),(0,l.jsx)("ul",{children:i.recoveryHints.map((e,t)=>(0,l.jsxs)("li",{children:[e.marker,": ",e.strategy,e.operatorActionRequired?" (operator action required)":""]},`${e.marker}-${String(t)}`))})]}):null]});}function T(e){let t=!e.enabled||e.busy;return(0,l.jsx)("button",{type:"button",className:"tw-switcher-action","aria-disabled":t,onClick:()=>{t||e.onClick();},children:e.label});}let z=(0,r.memo)(function(){var e,t,n,i,o,s;let c=function(){let e=(0,r.useContext)(a);if(null===e)throw Error("useActiveWorkspace must be used inside ActiveWorkspaceProvider");return e;}(),[d,f]=(0,r.useState)(!1),[m,h]=(0,r.useState)(""),[g,v]=(0,r.useState)(""),w=(0,r.useId)(),y=(0,r.useId)(),b=(0,r.useRef)(null),k=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!d)return;let e=e=>{if("Escape"===e.key){var t;f(!1),null==(t=b.current)||t.focus();}};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e);};},[d]),(0,r.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;t instanceof Node&&null!==k.current&&!k.current.contains(t)&&f(!1);};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[d]);let x=c.activeInstance,C=null!==x&&"string"==typeof(s=o=x.lifecycleState)&&u.includes(s)?p[o]:[],j=null!==x&&C.includes("paused"),S=null!==x&&C.includes("handoff-ready"),N=null===x?"No active task workspace":`Active: ${x.taskId} on ${x.taskBranch} (${x.lifecycleState}, ${x.health})`,R=null===x?"Task workspace context: no active workspace":`Task workspace context: ${x.taskId}`,z=null!=(e=null!=(t=null==(n=c.activeInstance)?void 0:n.repositoryRoot)?t:null==(i=c.instances[0])?void 0:i.repositoryRoot)?e:null,F=c.switching||null===z||""===m.trim()||""===g.trim();return(0,l.jsxs)("div",{ref:k,className:"tw-switcher",style:{position:"relative"},children:[(0,l.jsxs)("button",{ref:b,type:"button",className:"tw-switcher-trigger","aria-expanded":d,"aria-controls":w,"aria-describedby":y,"aria-label":R,"aria-busy":c.switching,onClick:()=>{f(e=>!e);},"data-active":null!==x?"true":"false",children:[(0,l.jsx)(I.Icons.branch,{size:14}),(0,l.jsx)("span",{className:"tw-switcher-trigger-label",children:null===x?"Task workspace":x.taskId}),c.switching?(0,l.jsx)("span",{"aria-hidden":"true",children:"…"}):null]}),(0,l.jsx)("div",{id:y,role:"status","aria-live":"polite",className:"tw-switcher-status-sr",children:N}),d?(0,l.jsxs)("div",{id:w,className:"tw-switcher-panel",role:"group","aria-label":"Task workspace context",children:[(0,l.jsxs)("div",{className:"tw-switcher-panel-head",children:[(0,l.jsx)("span",{className:"tw-switcher-kicker",children:"Task workspace"}),(0,l.jsx)("strong",{children:null===x?"No workspace bound":x.taskId})]}),null!==c.error?(0,l.jsx)("p",{role:"alert",className:"tw-switcher-error",style:{color:E.danger},children:c.error}):null,null!==x?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(M,{instance:x}),(0,l.jsxs)("div",{className:"tw-switcher-actions",style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",marginTop:"0.4rem"},children:[T({label:"Pause",onClick:()=>void c.pause(x.workspaceId),enabled:j,busy:c.switching}),T({label:"Prepare handoff",onClick:()=>void c.prepareHandoff(x.workspaceId),enabled:S&&!A(x),busy:c.switching}),T({label:"Clear active",onClick:()=>void c.clearActive(),enabled:!0,busy:c.switching})]})]}):(0,l.jsxs)("div",{className:"tw-switcher-empty",children:[(0,l.jsx)("span",{className:"tw-switcher-empty-icon","aria-hidden":"true",children:(0,l.jsx)(I.Icons.branch,{size:16})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("strong",{children:"No active task workspace"}),(0,l.jsx)("p",{children:null===z?"Open a project before creating a managed task workspace.":"Switch to an existing workspace or create one for this repository."})]})]}),(0,l.jsxs)("div",{className:"tw-switcher-section",children:[(0,l.jsx)("div",{className:"tw-switcher-section-title",children:"Available workspaces"}),0===c.instances.length?(0,l.jsx)("p",{className:"tw-switcher-list-empty",children:c.loading?"Loading workspaces…":"No managed task workspaces yet."}):(0,l.jsx)("div",{className:"tw-switcher-list",role:"list","aria-label":"Task workspaces",children:c.instances.map(e=>{let t=(null==x?void 0:x.workspaceId)===e.workspaceId;return(0,l.jsxs)("div",{role:"listitem",className:"tw-switcher-list-item",children:[(0,l.jsxs)("span",{className:"tw-switcher-list-label",title:e.managedWorktreePath,children:[(0,l.jsx)("strong",{children:e.taskId}),(0,l.jsx)("span",{children:e.lifecycleState}),A(e)?P("dirty","warning"):null]}),T({label:t?"Active":"Switch",onClick:()=>void c.switchTo(e.workspaceId),enabled:!t&&("active"===e.lifecycleState||"paused"===e.lifecycleState||"handoff-ready"===e.lifecycleState),busy:c.switching})]},e.workspaceId);})})]}),null!==z?(0,l.jsxs)("div",{className:"tw-switcher-section",children:[(0,l.jsx)("div",{className:"tw-switcher-section-title",children:"Create workspace"}),(0,l.jsxs)("form",{className:"tw-switcher-create",onSubmit:e=>{e.preventDefault(),F||c.provision({root:z,taskId:m.trim(),baseBranch:g.trim()}).then(()=>{h(""),v("");});},children:[(0,l.jsxs)("label",{className:"tw-switcher-field",children:[(0,l.jsx)("span",{children:"Task id"}),(0,l.jsx)("input",{type:"text",value:m,onChange:e=>{h(e.target.value);},placeholder:"e.g. 446-binding"})]}),(0,l.jsxs)("label",{className:"tw-switcher-field",children:[(0,l.jsx)("span",{children:"Base branch"}),(0,l.jsx)("input",{type:"text",value:g,onChange:e=>{v(e.target.value);},placeholder:"e.g. dev"})]}),(0,l.jsx)("button",{type:"submit",className:"tw-switcher-create-submit",disabled:F,"aria-disabled":F,children:"Create task workspace"})]})]}):null]}):null]});});var F=e.i(31987),L=e.i(98723),W=e.i(76055),$=e.i(50850),D=e.i(95313),O=e.i(48143);let K=(0,r.memo)(function(e){let{winCount:t,windows:n,windowPaletteOpen:i,onToggleWindowPalette:a,onSelectWindow:o,onCloseWindowPalette:s,statusRef:c}=e,d=(0,$.useTranslate)(),u=(0,r.useRef)(null),p=(0,r.useRef)(null),f=(0,r.useRef)(null),[m,h]=(0,r.useState)(d("footer.versionLoading")),g=1===t?d("footer.windowSingular",{count:t}):d("footer.windowPlural",{count:t}),v=(0,r.useMemo)(()=>[...n].sort((e,t)=>t.z-e.z),[n]);return(0,r.useEffect)(()=>{let e=!1;return async function(){try{let t=await(0,W.fetchHealth)();e||h(t.version);}catch{e||h(d("footer.versionUnavailable"));}}(),()=>{e=!0;};},[d]),(0,r.useEffect)(()=>{if(!i)return;if(0===t)return void s();let e=e=>{let t=e.target;t instanceof Node&&null!==u.current&&!u.current.contains(t)&&s();},n=e=>{if("Escape"===e.key){var t;s(),null==(t=p.current)||t.focus();}};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",n);};},[s,t,i]),(0,r.useEffect)(()=>{if(!i||0===t)return;let e=f.current;if(null===e)return;let n=e.querySelector(".ft-window-card");(null!=n?n:e).focus();},[i,t]),(0,l.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":d("footer.status"),"aria-live":"polite",children:[(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("span",{className:"ft-brand","aria-label":d("footer.version",{version:m}),children:["Keiko | ",m]}),(0,l.jsxs)("span",{className:"ft-window-wrap",ref:u,children:[(0,l.jsxs)("button",{ref:p,type:"button",className:"ft-seg ft-accent ft-window-trigger","aria-atomic":"true","aria-expanded":i,"aria-controls":"footer-window-palette",disabled:0===t,onClick:a,children:[(0,l.jsx)(I.Icons.tile,{size:13})," ",g]}),i&&t>0?(0,l.jsxs)("div",{ref:f,id:"footer-window-palette",className:"ft-window-palette",role:"group","aria-label":d("footer.openWindows"),tabIndex:-1,children:[(0,l.jsx)("div",{className:"ft-window-palette-head",children:d("footer.openWindows")}),(0,l.jsx)("div",{className:"ft-window-list",children:v.map(e=>{let t=D.WIN_TYPES[e.type],n=I.Icons[t.icon],r=(0,O.subText)(e.type,e.cfg),i=!0===e.minimized?d("footer.minimized"):e.max?d("footer.fullscreen"):d("footer.visible"),a=!0===e.minimized?d("footer.restore"):d("footer.focus"),s=null!==r?` - ${r}`:"";return(0,l.jsxs)("button",{type:"button",className:"ft-window-card","data-minimized":!0===e.minimized?"true":"false","aria-label":d("footer.windowAction",{action:a,title:t.title,suffix:s}),onClick:()=>o(e.id),children:[(0,l.jsx)("span",{className:"ft-window-icon",style:{color:!0===t.accent?"var(--accent)":void 0},children:(0,l.jsx)(n,{size:14})}),(0,l.jsxs)("span",{className:"ft-window-copy",children:[(0,l.jsx)("span",{className:"ft-window-title",children:t.title}),(0,l.jsx)("span",{className:"ft-window-sub",title:null!=r?r:i,children:null!=r?r:i})]}),(0,l.jsx)("span",{className:"ft-window-state",children:i})]},e.id);})})]}):null]})]});}),q=(0,r.memo)(function(e){let{onTileAll:t,onSplitFront:n,onCascade:r,contextControl:i}=e,a=(0,$.useTranslate)();return(0,l.jsxs)("header",{className:"header",children:[(0,l.jsxs)("div",{className:"hd-brand",children:[(0,l.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,l.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),void 0!==i?(0,l.jsx)("div",{className:"hd-context",children:i}):null,(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("div",{className:"hd-tools",children:[(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:t,"data-tip":a("header.tileAll"),"aria-label":a("header.tileAll"),children:(0,l.jsx)(I.Icons.tile,{size:16})}),(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:n,"data-tip":a("header.splitFront"),"aria-label":a("header.splitFront"),children:(0,l.jsx)(I.Icons.split,{size:16})}),(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:r,"data-tip":a("header.cascade"),"aria-label":a("header.cascade"),children:(0,l.jsx)(I.Icons.cascade,{size:16})})]})]});}),B=[{id:"chatHistory",icon:"archive"}];function _(e){let{tool:t,label:n,active:r,onClick:i}=e,a=I.Icons[t.icon];return(0,l.jsx)("button",{type:"button",className:"rail-btn","data-active":r?"true":"false","data-side":"left","aria-label":n,"aria-pressed":r,"data-tip":n,onClick:i,children:void 0!==t.img?(0,l.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,l.jsx)(a,{size:19})});}let G=(0,r.memo)(function(e){let{openTools:t,onTool:n,onNewChat:r,theme:i,onToggleTheme:a}=e,o=(0,$.useTranslate)(),s="light"===i?o("rail.darkMode"):o("rail.lightMode");return(0,l.jsxs)("nav",{className:"rail rail-left","aria-label":o("rail.primaryNavigation"),children:[(0,l.jsx)("button",{type:"button",className:"rail-new",onClick:r,"data-side":"left","aria-label":o("rail.newChat"),"data-tip":o("rail.newChat"),children:(0,l.jsx)(I.Icons.newChat,{size:18})}),(0,l.jsx)("div",{className:"rail-div"}),(0,l.jsx)("div",{className:"rail-group",children:B.map(e=>(0,l.jsx)(_,{tool:e,label:o("rail.chatHistory"),active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("div",{className:"rail-group",children:[(0,l.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has("memoria")?"true":"false","data-side":"left","aria-label":o("rail.memoria"),"aria-pressed":t.has("memoria"),"data-tip":o("rail.memoria"),onClick:()=>n("memoria"),children:(0,l.jsx)(I.Icons.brain,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":o("rail.quality"),"aria-pressed":t.has("quality"),"data-tip":o("rail.quality"),onClick:()=>n("quality"),children:(0,l.jsx)(I.Icons.check,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("promptEnhancer")?"true":"false","aria-label":o("rail.promptEnhancer"),"aria-pressed":t.has("promptEnhancer"),"data-tip":o("rail.promptEnhancer"),onClick:()=>n("promptEnhancer"),children:(0,l.jsx)(I.Icons.spark,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("governedGit")?"true":"false","aria-label":"Git","aria-pressed":t.has("governedGit"),"data-tip":"Git",onClick:()=>n("governedGit"),children:(0,l.jsx)(I.Icons.git,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("localKnowledge")?"true":"false","aria-label":o("rail.localKnowledge"),"aria-pressed":t.has("localKnowledge"),"data-tip":o("rail.localKnowledge"),onClick:()=>n("localKnowledge"),children:(0,l.jsx)(I.Icons.localKnowledge,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("figma")?"true":"false","aria-label":o("rail.figma"),"aria-pressed":t.has("figma"),"data-tip":o("rail.figma"),onClick:()=>n("figma"),children:(0,l.jsx)(I.Icons.layers,{size:19})})]}),(0,l.jsx)("div",{className:"rail-div"}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":s,"aria-pressed":"light"===i,"data-tip":s,onClick:a,children:"light"===i?(0,l.jsx)(I.Icons.moon,{size:19}):(0,l.jsx)(I.Icons.sun,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":o("rail.settings"),"aria-pressed":t.has("settings"),"data-tip":o("rail.settings"),onClick:()=>n("settings"),children:(0,l.jsx)(I.Icons.settings,{size:19})})]});}),U=(0,r.memo)(function(e){return(0,l.jsx)("div",{className:"rail rail-right",children:(0,l.jsx)("span",{className:"spacer"})});});var J=e.i(70703);function V(e){return e.toFixed(2);}function Y(e){let{onNewWindow:t}=e,n=(0,r.useId)(),i=`ewb-${n.replace(/:/gu,"")}`,a=`ewb-desc-${n.replace(/:/gu,"")}`,o=(0,r.useRef)(null),s=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{var t;null==(t=o.current)||t.setAttribute("d",function(e){var t,n,l,r;let i=[];for(let t=0;t<150;t++){let n=t/150*Math.PI*2,l=1+.07*(.55*Math.sin(3*n+e)+.32*Math.sin(5*n-.8*e+1.7)+.22*Math.sin(2*n+.5*e+.4));i.push([140+127.44000000000001*l*Math.cos(n),140+118*l*Math.sin(n)]);}let a=`M${V(null!=(t=null==(l=i[0])?void 0:l[0])?t:140)} ${V(null!=(n=null==(r=i[0])?void 0:r[1])?n:140)} `;for(let e=0;e<i.length;e++){let t=i[(e-1+i.length)%i.length],n=i[e],l=i[(e+1)%i.length],r=i[(e+2)%i.length],o=n[0]+(l[0]-t[0])/6,s=n[1]+(l[1]-t[1])/6,c=l[0]-(r[0]-n[0])/6,d=l[1]-(r[1]-n[1])/6;a+=`C${V(o)} ${V(s)} ${V(c)} ${V(d)} ${V(l[0])} ${V(l[1])} `;}return`${a}Z`;}(e));};if(e(.7),"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame)return;let t=0,n=()=>{0!==t&&(window.cancelAnimationFrame(t),t=0);},l=n=>{e(85e-5*n),t=window.requestAnimationFrame(l);},r=()=>{0===t&&!0!==document.hidden&&(t=window.requestAnimationFrame(l));},i=()=>{!0===document.hidden?n():r();};return r(),document.addEventListener("visibilitychange",i),window.addEventListener("blur",n),window.addEventListener("focus",r),()=>{n(),document.removeEventListener("visibilitychange",i),window.removeEventListener("blur",n),window.removeEventListener("focus",r);};},[]);let c=(0,r.useCallback)(()=>{let e=s.current;null!==e&&(e.classList.remove("is-pulse"),e.getBoundingClientRect(),e.classList.add("is-pulse")),t();},[t]);return(0,l.jsxs)("button",{type:"button",className:"empty-workspace-blob","aria-label":"Open a new window","aria-describedby":a,onClick:c,children:[(0,l.jsx)("span",{id:a,className:"visually-hidden",children:"Empty workspace. Open a window to start working."}),(0,l.jsxs)("svg",{width:"320",height:"320",viewBox:"0 0 280 280","aria-hidden":"true",children:[(0,l.jsx)("defs",{children:(0,l.jsxs)("mask",{id:i,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"280",height:"280",children:[(0,l.jsx)("rect",{x:"0",y:"0",width:"280",height:"280",fill:"#fff"}),(0,l.jsx)("g",{transform:"translate(107,64) scale(0.080625)",children:(0,l.jsx)("g",{transform:"translate(1024 0) scale(-1 1)",children:(0,l.jsx)("g",{transform:"translate(1024,1024) scale(-0.1,-0.1)",fill:"#000",children:(0,l.jsx)("path",{d:"M3465 8223 c-144 -8 -314 -52 -408 -105 -69 -39 -146 -99 -146 -113 0 -5 30 -24 68 -42 146 -70 323 -229 377 -340 25 -49 29 -70 29 -138 -1 -72 -5 -88 -39 -160 -36 -75 -54 -95 -265 -305 -134 -132 -270 -279 -331 -355 -339 -425 -552 -896 -626 -1390 -25 -165 -25 -549 0 -720 92 -645 368 -1196 826 -1655 322 -324 710 -562 1145 -704 389 -126 793 -172 1155 -130 235 27 377 63 579 149 205 87 268 86 423 -7 102 -62 231 -115 335 -138 247 -56 562 -26 794 74 92 40 244 136 232 146 -4 3 -26 12 -48 19 -86 28 -246 116 -385 211 -162 112 -284 182 -357 207 l-48 17 40 15 c185 70 436 223 595 363 438 386 695 1014 678 1663 l-3 120 -50 -70 c-64 -90 -248 -280 -350 -362 -171 -136 -366 -255 -645 -391 -288 -140 -442 -243 -590 -391 -136 -137 -247 -316 -325 -526 -47 -127 -114 -262 -160 -326 -79 -107 -237 -224 -384 -283 -136 -55 -355 -96 -514 -96 -274 0 -548 71 -832 215 -242 123 -375 216 -553 389 -175 171 -287 332 -361 517 -44 114 -63 216 -63 359 0 152 17 233 74 350 35 70 59 102 136 179 l95 94 21 -29 c55 -75 219 -277 277 -338 171 -183 337 -256 582 -256 56 0 126 -3 155 -7 53 -6 54 -7 76 -57 30 -66 97 -128 172 -156 151 -57 318 11 395 160 33 62 34 193 3 261 -30 64 -88 125 -148 157 -44 23 -63 27 -141 27 -78 0 -97 -4 -140 -27 -58 -30 -131 -105 -141 -142 -6 -25 -8 -26 -93 -26 -47 0 -131 5 -186 10 -87 8 -111 15 -182 51 -45 22 -109 66 -143 96 -59 53 -326 361 -319 367 14 11 179 47 241 52 102 9 177 -7 318 -66 158 -66 243 -89 357 -99 157 -12 413 5 582 40 l93 19 44 -39 c59 -52 135 -75 228 -69 117 8 212 72 262 176 23 47 28 71 28 138 0 70 -4 89 -29 138 -55 110 -145 167 -270 174 -65 3 -91 0 -137 -18 -107 -40 -183 -140 -195 -257 l-6 -52 -51 -11 c-104 -23 -285 -41 -411 -42 -149 -1 -211 12 -402 88 -186 74 -256 88 -403 81 -193 -8 -377 -70 -546 -182 -342 -228 -485 -611 -399 -1064 30 -157 119 -388 209 -541 20 -35 35 -64 33 -66 -8 -8 -111 108 -190 214 -154 206 -278 489 -324 737 -28 154 -25 492 6 635 46 216 133 391 256 514 82 82 161 128 271 156 152 39 300 23 529 -57 217 -76 308 -101 410 -114 137 -17 284 -7 426 30 272 70 414 145 809 425 217 153 399 238 610 283 64 14 129 18 265 18 197 0 269 -9 615 -76 461 -89 843 -149 952 -149 41 0 41 0 23 -20 -28 -31 -169 -119 -254 -158 -167 -77 -388 -145 -716 -222 -399 -93 -508 -128 -608 -194 -102 -68 -160 -160 -217 -346 -35 -115 -102 -286 -149 -378 -85 -168 -227 -341 -377 -458 -105 -82 -115 -107 -69 -162 29 -34 65 -44 109 -29 86 29 261 181 371 322 126 162 201 309 295 581 61 176 90 232 145 283 62 57 163 93 470 165 439 104 640 169 863 278 206 100 368 240 434 375 32 67 33 71 33 198 -1 120 -3 138 -34 229 -98 294 -319 655 -573 936 -381 421 -968 723 -1618 834 -448 76 -767 83 -1169 25 -80 -12 -165 -19 -190 -17 -26 3 -90 26 -146 53 -343 162 -576 233 -842 255 -114 9 -141 10 -248 3z m2926 -1227 c164 -27 346 -102 485 -202 181 -129 354 -348 354 -448 0 -64 -75 -126 -154 -126 -60 0 -63 4 -52 70 8 50 7 65 -9 100 -29 64 -74 93 -151 98 -54 4 -70 1 -107 -21 -42 -25 -61 -52 -91 -129 -25 -64 -55 -73 -246 -73 -121 0 -187 5 -248 18 -318 70 -556 242 -556 402 0 218 388 374 775 311z m-2249 -611 c119 -21 208 -50 321 -106 114 -56 177 -100 266 -184 67 -63 157 -173 148 -181 -2 -3 -61 18 -130 45 -131 52 -298 100 -427 122 -113 20 -367 17 -470 -4 -502 -106 -885 -433 -1160 -992 -70 -142 -160 -379 -160 -424 0 -9 -5 -23 -11 -31 -13 -19 -5 316 10 410 80 482 295 846 661 1117 145 107 350 197 522 228 100 18 326 18 430 0z m1485 -1456 c95 -36 119 -159 42 -223 -78 -66 -209 -1 -209 104 0 60 33 100 99 121 36 10 36 10 68 -2z m-591 -822 c29 -26 37 -42 40 -77 6 -54 -9 -86 -55 -117 -41 -28 -70 -29 -119 -4 -44 22 -62 55 -62 112 0 51 13 75 53 99 50 31 101 26 143 -13z"})})})}),(0,l.jsx)("text",{x:"140",y:"172",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"16",fontWeight:"700",children:"Empty workspace"}),(0,l.jsx)("text",{x:"140",y:"191",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"11",fontWeight:"400",children:"Open a window to start working"})]})}),(0,l.jsx)("g",{ref:s,className:"empty-workspace-blob__group",children:(0,l.jsx)("path",{ref:o,className:"empty-workspace-blob__fill",mask:`url(#${i})`})})]})]});}var X=e.i(80137);let H=new Set(["files","connector","browser","plugins","agents","quality"]);function Z(e){return{left:e.x,top:e.y,right:e.x+e.w,bottom:e.y+e.h};}function Q(e,t){return e>=4||t>=8192;}function ee(e){let{pathId:t,intensity:n}=e,r="heavy"===n?3:1,i="heavy"===n?1.1:2.2;return(0,l.jsx)(l.Fragment,{children:Array.from({length:r},(e,a)=>(0,l.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,l.jsx)("animateMotion",{dur:`${String(i)}s`,repeatCount:"indefinite",begin:`${String(i/r*a)}s`,rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,l.jsx)("mpath",{href:`#${t}`})})},a))});}let et=(0,r.memo)(function(e){let{wins:t,conns:n,connecting:a,api:o}=e,s=(0,i.useOptionalChatSessionActivity)(),c=function(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)");t(e.matches);let n=e=>t(e.matches);return e.addEventListener("change",n),()=>e.removeEventListener("change",n);},[]),e;}(),{armedId:d,arm:u,disarm:p,autoCancelledNonce:f}=function(){let[e,t]=(0,r.useState)(null),[n,l]=(0,r.useState)(0);return(0,r.useEffect)(()=>{if(null===e)return;let n=setTimeout(()=>{t(null),l(e=>e+1);},3e3);return()=>clearTimeout(n);},[e]),{armedId:e,arm:e=>t(e),disarm:()=>t(null),autoCancelledNonce:n};}(),[m,h]=(0,r.useState)(""),g=(0,r.useRef)(f);(0,r.useEffect)(()=>{f!==g.current&&(g.current=f,h("Removal cancelled — the connection was not removed."));},[f]);let{flowing:v,intensity:w}=function(e,t){let[n,l]=(0,r.useState)("light"),[i,a]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(void 0===t)return;l(function(e){switch(e.groundingKind){case"connected-context":return Q(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return Q(e.contextPack.folder.usage.filesRead,e.contextPack.folder.usage.excerptBytes)||e.contextPack.knowledge.referencesUsed>=4?"heavy":"light";case"local-knowledge":return e.contextPack.referencesUsed>=4?"heavy":"light";default:return"light";}}(t)),a(!0);let e=setTimeout(()=>a(!1),2500);return()=>clearTimeout(e);},[t]),{flowing:e||i,intensity:n};}((null==s?void 0:s.sending)===!0,null==s?void 0:s.latestGrounded),y=(0,r.useMemo)(()=>function(e,t){let n=new Map(e.map(e=>[e.id,e])),l=[];for(let e of t){let t=n.get(e.a),r=n.get(e.b);if(void 0===t||void 0===r)continue;let i=(0,O.connPath)(t,r);l.push({c:e,d:i.d,mid:i.mid,label:(0,O.relLabel)(t,r),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),l="chat"===e.type?H.has(t.type):H.has(e.type);return n&&l;}(t,r)});}return l;}(t,n),[t,n]),b=(0,r.useMemo)(()=>{let e=t.filter(e=>!0!==e.minimized).map(Z),n=new Set();for(let t of y)(function(e,t,n){let l,r=(l=Math.min(240,Math.max(40,7.2*e.label.length))+(44+18*!!n),{left:e.mid.x-l/2,right:e.mid.x+l/2,top:e.mid.y-13,bottom:e.mid.y+13});return!t.some(e=>r.left<e.right&&r.right>e.left&&r.top<e.bottom&&r.bottom>e.top);})(t,e,v&&t.dataChannel)&&n.add(t.c.id);return n;},[v,y,t]),k=null!==a?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let l={x:n.x+n.w/2,y:n.y+n.h/2},r=e.x-l.x,i=e.y-l.y,a=Math.abs(r)>=Math.abs(i),o=a?{x:r>=0?n.x+n.w:n.x,y:l.y}:{x:l.x,y:i>=0?n.y+n.h:n.y},s=Math.max(40,Math.abs(a?r:i)/2),c=a?{x:o.x+(r>=0?s:-s),y:o.y}:{x:o.x,y:o.y+(i>=0?s:-s)},d=e.x,u=e.y;return{d:`M${String(o.x)},${String(o.y)} C${String(c.x)},${String(c.y)} ${String(d)},${String(u)} ${String(d)},${String(u)}`,ex:d,ey:u};}(a,t):null;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"conn-layer",children:(0,l.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[y.map(e=>{let t=v&&e.dataChannel,n=`conn-path-${e.c.id}`;return(0,l.jsxs)("g",{children:[(0,l.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?w:void 0,"data-reduced-motion":t&&c?"true":void 0}),t&&!c?(0,l.jsx)(ee,{pathId:n,intensity:w}):null]},e.c.id);}),null!==k?(0,l.jsx)("path",{className:"conn-path conn-temp",d:k.d}):null,null!==k?(0,l.jsx)("circle",{className:"conn-dot",cx:k.ex,cy:k.ey,r:"5"}):null]})}),(0,l.jsxs)("div",{className:"conn-badge-layer",children:[(0,l.jsx)("div",{className:"visually-hidden",role:"status","aria-live":"polite",children:m}),y.map(e=>{let t,n=v&&e.dataChannel;if(!b.has(e.c.id))return null;let r=d===e.c.id,i=(t=[`Connection: ${e.label}`],void 0!==e.c.boundRoot&&t.push(`Root: ${e.c.boundRoot}`),void 0!==e.c.boundScopeKind&&t.push(`Scope: ${e.c.boundScopeKind}`),void 0!==e.c.boundRelativePath&&e.c.boundRelativePath.length>0&&t.push(`Path: ${e.c.boundRelativePath}`),void 0!==e.c.boundConnectorKind&&void 0!==e.c.boundConnectorId&&t.push(`Knowledge: ${e.c.boundConnectorKind} ${e.c.boundConnectorId}`),t.join("\n"));return(0,l.jsxs)("button",{type:"button",className:"conn-badge","data-active":n?"true":void 0,"data-intensity":n?w:void 0,"data-armed":r?"true":void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>{r?(p(),o.removeConn(e.c.id)):u(e.c.id);},onBlur:()=>{r&&p();},title:r?`Click again to remove: ${e.label}
|
|
1
|
+
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,89199,e=>{"use strict";let t,n;var l=e.i(43476),r=e.i(71645),i=e.i(80144);let a=(0,r.createContext)(null);function o(e){let{value:t,children:n}=e;return(0,l.jsx)(a.Provider,{value:t,children:n});}let s=(0,r.createContext)(null);function c(e){let{children:t}=e,[n,i]=(0,r.useState)(""),[a,o]=(0,r.useState)(""),c=(0,r.useRef)(0),d=(0,r.useCallback)((e,t)=>{c.current+=1;let n=c.current%2==0?e:`${e}`;(null==t?void 0:t.assertive)===!0?o(n):i(n);},[]),u=(0,r.useMemo)(()=>({announce:d}),[d]);return(0,l.jsxs)(s.Provider,{value:u,children:[t,(0,l.jsx)("div",{className:"visually-hidden",role:"status","aria-live":"polite","aria-atomic":"true","data-testid":"app-announcer-polite",children:n}),(0,l.jsx)("div",{className:"visually-hidden",role:"alert","aria-live":"assertive","aria-atomic":"true","data-testid":"app-announcer-assertive",children:a})]});}var d=e.i(70045);let u=["provisioning","active","paused","handoff-ready","archived","merged","abandoned","recovery-required","failed","cleanup-pending"],p={provisioning:["active","recovery-required","failed","cleanup-pending"],active:["paused","handoff-ready","recovery-required","failed","cleanup-pending"],paused:["active","handoff-ready","archived","abandoned","recovery-required","cleanup-pending"],"handoff-ready":["active","merged","archived","abandoned","recovery-required","cleanup-pending"],merged:["archived","cleanup-pending"],archived:["cleanup-pending"],abandoned:["cleanup-pending"],"recovery-required":["active","paused","failed","abandoned","cleanup-pending"],failed:["recovery-required","abandoned","cleanup-pending"],"cleanup-pending":["archived","abandoned","recovery-required"]},f=["retryable","repairable","blocked","policy-denied","terminal"];async function m(e,t){return(0,d.bffFetchJson)(e,t,{enrichError:(e,t)=>{let n=null==t?void 0:t.error.failureClass;Object.assign(e,{failureClass:"string"==typeof n&&f.includes(n)?n:void 0});}});}async function h(e){return m("/api/task-workspaces",{method:"POST",body:JSON.stringify(e)});}async function g(e){let t=new URLSearchParams();return t.set("root",e),(await m(`/api/task-workspaces?${t.toString()}`)).instances;}async function v(){return(await m("/api/task-workspaces/active")).active;}async function w(e){return m("/api/task-workspaces/active",{method:"POST",body:JSON.stringify(e)});}async function y(){await m("/api/task-workspaces/active",{method:"DELETE"});}async function b(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/pause`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function k(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/resume`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}async function x(e){return m(`/api/task-workspaces/${encodeURIComponent(e.workspaceId)}/handoff`,{method:"POST",body:JSON.stringify({requestedBy:e.requestedBy})});}let j="studio-operator",C={instances:[],active:null,loading:!1,switching:!1,error:null};function S(e,t){switch(t.kind){case"load-start":return{...e,loading:!0,error:null};case"mutate-start":return{...e,switching:!0,error:null};case"settle":return{instances:t.instances,active:t.active,loading:!1,switching:!1,error:null};case"fail":return{...e,loading:!1,switching:!1,error:t.error};default:return e;}}function N(e){return e instanceof Error?e.message:"Task workspace action failed.";}var I=e.i(17161);let E={success:"var(--feedback-success, #2e7d32)",warning:"var(--feedback-warning, #b8860b)",danger:"var(--feedback-danger, #c0392b)",info:"var(--feedback-info, #2b6cb0)",muted:"var(--text-tertiary, #888)"},R={healthy:"success",degraded:"warning",drifted:"warning","locked-out":"danger",missing:"danger",unknown:"muted"};function A(e){return e.driftMarkers.includes("uncommitted-changes");}function P(e,t,n){let r=E[t],i={display:"inline-flex",alignItems:"center",gap:"0.25rem",padding:"0.05rem 0.4rem",borderRadius:"var(--radius-sm, 4px)",fontSize:"0.72rem",fontWeight:600,color:"var(--text-primary, #111)",background:`color-mix(in oklch, ${r} 18%, var(--surface-raised, var(--surface, transparent)))`,border:`1px solid color-mix(in oklch, ${r} 48%, var(--border-subtle, transparent))`};return(0,l.jsx)("span",{className:"tw-switcher-badge",style:i,title:n,children:e});}function M(e){var t,n;let r,{instance:i}=e,a=A(i);return(0,l.jsxs)("div",{className:"tw-switcher-active",children:[(0,l.jsxs)("div",{className:"tw-switcher-identity",children:[(0,l.jsx)("strong",{className:"tw-switcher-task",title:i.taskId,children:i.taskId}),(0,l.jsxs)("span",{className:"tw-switcher-branch",title:i.taskBranch,children:[i.taskBranch,(0,l.jsxs)("span",{className:"tw-switcher-base",children:[" ← ",i.baseBranch]})]})]}),(0,l.jsxs)("div",{className:"tw-switcher-badges",style:{display:"flex",flexWrap:"wrap",gap:"0.3rem"},children:[P(i.lifecycleState,"info","Lifecycle state"),P(i.health,R[i.health],"Workspace health"),a?P("uncommitted","warning","The worktree has uncommitted changes"):P("clean","success","The worktree is clean"),null!==i.lock?P(`locked: ${i.lock.reason}`,"danger",`Held by ${i.lock.owner}`):null]}),(0,l.jsx)("p",{className:"tw-switcher-path",style:{fontSize:"0.72rem",color:E.muted},children:(0,l.jsx)("span",{title:i.managedWorktreePath,children:null!=(n=(r=(t=i.managedWorktreePath).replace(/[/\\]+$/u,"").split(/[/\\]/u))[r.length-1])?n:t})}),(0,l.jsxs)("p",{className:"tw-switcher-activity",style:{fontSize:"0.7rem",color:E.muted},children:["Updated ",i.updatedAt]}),i.recoveryHints.length>0?(0,l.jsxs)("details",{className:"tw-switcher-recovery",children:[(0,l.jsxs)("summary",{children:["Recovery hints (",i.recoveryHints.length,")"]}),(0,l.jsx)("ul",{children:i.recoveryHints.map((e,t)=>(0,l.jsxs)("li",{children:[e.marker,": ",e.strategy,e.operatorActionRequired?" (operator action required)":""]},`${e.marker}-${String(t)}`))})]}):null]});}function T(e){let t=!e.enabled||e.busy;return(0,l.jsx)("button",{type:"button",className:"tw-switcher-action","aria-disabled":t,onClick:()=>{t||e.onClick();},children:e.label});}let z=(0,r.memo)(function(){var e,t,n,i,o,s;let c=function(){let e=(0,r.useContext)(a);if(null===e)throw Error("useActiveWorkspace must be used inside ActiveWorkspaceProvider");return e;}(),[d,f]=(0,r.useState)(!1),[m,h]=(0,r.useState)(""),[g,v]=(0,r.useState)(""),w=(0,r.useId)(),y=(0,r.useId)(),b=(0,r.useRef)(null),k=(0,r.useRef)(null);(0,r.useEffect)(()=>{if(!d)return;let e=e=>{if("Escape"===e.key){var t;f(!1),null==(t=b.current)||t.focus();}};return document.addEventListener("keydown",e),()=>{document.removeEventListener("keydown",e);};},[d]),(0,r.useEffect)(()=>{if(!d)return;let e=e=>{let t=e.target;t instanceof Node&&null!==k.current&&!k.current.contains(t)&&f(!1);};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[d]);let x=c.activeInstance,j=null!==x&&"string"==typeof(s=o=x.lifecycleState)&&u.includes(s)?p[o]:[],C=null!==x&&j.includes("paused"),S=null!==x&&j.includes("handoff-ready"),N=null===x?"No active task workspace":`Active: ${x.taskId} on ${x.taskBranch} (${x.lifecycleState}, ${x.health})`,R=null===x?"Task workspace context: no active workspace":`Task workspace context: ${x.taskId}`,z=null!=(e=null!=(t=null==(n=c.activeInstance)?void 0:n.repositoryRoot)?t:null==(i=c.instances[0])?void 0:i.repositoryRoot)?e:null,F=c.switching||null===z||""===m.trim()||""===g.trim();return(0,l.jsxs)("div",{ref:k,className:"tw-switcher",style:{position:"relative"},children:[(0,l.jsxs)("button",{ref:b,type:"button",className:"tw-switcher-trigger","aria-expanded":d,"aria-controls":w,"aria-describedby":y,"aria-label":R,"aria-busy":c.switching,onClick:()=>{f(e=>!e);},"data-active":null!==x?"true":"false",children:[(0,l.jsx)(I.Icons.branch,{size:14}),(0,l.jsx)("span",{className:"tw-switcher-trigger-label",children:null===x?"Task workspace":x.taskId}),c.switching?(0,l.jsx)("span",{"aria-hidden":"true",children:"…"}):null]}),(0,l.jsx)("div",{id:y,role:"status","aria-live":"polite",className:"tw-switcher-status-sr",children:N}),d?(0,l.jsxs)("div",{id:w,className:"tw-switcher-panel",role:"group","aria-label":"Task workspace context",children:[(0,l.jsxs)("div",{className:"tw-switcher-panel-head",children:[(0,l.jsx)("span",{className:"tw-switcher-kicker",children:"Task workspace"}),(0,l.jsx)("strong",{children:null===x?"No workspace bound":x.taskId})]}),null!==c.error?(0,l.jsx)("p",{role:"alert",className:"tw-switcher-error",style:{color:E.danger},children:c.error}):null,null!==x?(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)(M,{instance:x}),(0,l.jsxs)("div",{className:"tw-switcher-actions",style:{display:"flex",gap:"0.4rem",flexWrap:"wrap",marginTop:"0.4rem"},children:[T({label:"Pause",onClick:()=>void c.pause(x.workspaceId),enabled:C,busy:c.switching}),T({label:"Prepare handoff",onClick:()=>void c.prepareHandoff(x.workspaceId),enabled:S&&!A(x),busy:c.switching}),T({label:"Clear active",onClick:()=>void c.clearActive(),enabled:!0,busy:c.switching})]})]}):(0,l.jsxs)("div",{className:"tw-switcher-empty",children:[(0,l.jsx)("span",{className:"tw-switcher-empty-icon","aria-hidden":"true",children:(0,l.jsx)(I.Icons.branch,{size:16})}),(0,l.jsxs)("div",{children:[(0,l.jsx)("strong",{children:"No active task workspace"}),(0,l.jsx)("p",{children:null===z?"Open a project before creating a managed task workspace.":"Switch to an existing workspace or create one for this repository."})]})]}),(0,l.jsxs)("div",{className:"tw-switcher-section",children:[(0,l.jsx)("div",{className:"tw-switcher-section-title",children:"Available workspaces"}),0===c.instances.length?(0,l.jsx)("p",{className:"tw-switcher-list-empty",children:c.loading?"Loading workspaces…":"No managed task workspaces yet."}):(0,l.jsx)("div",{className:"tw-switcher-list",role:"list","aria-label":"Task workspaces",children:c.instances.map(e=>{let t=(null==x?void 0:x.workspaceId)===e.workspaceId;return(0,l.jsxs)("div",{role:"listitem",className:"tw-switcher-list-item",children:[(0,l.jsxs)("span",{className:"tw-switcher-list-label",title:e.managedWorktreePath,children:[(0,l.jsx)("strong",{children:e.taskId}),(0,l.jsx)("span",{children:e.lifecycleState}),A(e)?P("dirty","warning"):null]}),T({label:t?"Active":"Switch",onClick:()=>void c.switchTo(e.workspaceId),enabled:!t&&("active"===e.lifecycleState||"paused"===e.lifecycleState||"handoff-ready"===e.lifecycleState),busy:c.switching})]},e.workspaceId);})})]}),null!==z?(0,l.jsxs)("div",{className:"tw-switcher-section",children:[(0,l.jsx)("div",{className:"tw-switcher-section-title",children:"Create workspace"}),(0,l.jsxs)("form",{className:"tw-switcher-create",onSubmit:e=>{e.preventDefault(),F||c.provision({root:z,taskId:m.trim(),baseBranch:g.trim()}).then(()=>{h(""),v("");});},children:[(0,l.jsxs)("label",{className:"tw-switcher-field",children:[(0,l.jsx)("span",{children:"Task id"}),(0,l.jsx)("input",{type:"text",value:m,onChange:e=>{h(e.target.value);},placeholder:"e.g. 446-binding"})]}),(0,l.jsxs)("label",{className:"tw-switcher-field",children:[(0,l.jsx)("span",{children:"Base branch"}),(0,l.jsx)("input",{type:"text",value:g,onChange:e=>{v(e.target.value);},placeholder:"e.g. dev"})]}),(0,l.jsx)("button",{type:"submit",className:"tw-switcher-create-submit",disabled:F,"aria-disabled":F,children:"Create task workspace"})]})]}):null]}):null]});});var F=e.i(31987),L=e.i(98723),W=e.i(76055),$=e.i(50850),D=e.i(95313),O=e.i(48143);let K=(0,r.memo)(function(e){let{winCount:t,windows:n,windowPaletteOpen:i,onToggleWindowPalette:a,onSelectWindow:o,onCloseWindowPalette:s,statusRef:c}=e,d=(0,$.useTranslate)(),u=(0,r.useRef)(null),p=(0,r.useRef)(null),f=(0,r.useRef)(null),[m,h]=(0,r.useState)(d("footer.versionLoading")),g=1===t?d("footer.windowSingular",{count:t}):d("footer.windowPlural",{count:t}),v=(0,r.useMemo)(()=>[...n].sort((e,t)=>t.z-e.z),[n]);return(0,r.useEffect)(()=>{let e=!1;return async function(){try{let t=await(0,W.fetchHealth)();e||h(t.version);}catch{e||h(d("footer.versionUnavailable"));}}(),()=>{e=!0;};},[d]),(0,r.useEffect)(()=>{if(!i)return;if(0===t)return void s();let e=e=>{let t=e.target;t instanceof Node&&null!==u.current&&!u.current.contains(t)&&s();},n=e=>{if("Escape"===e.key){var t;s(),null==(t=p.current)||t.focus();}};return document.addEventListener("pointerdown",e),document.addEventListener("keydown",n),()=>{document.removeEventListener("pointerdown",e),document.removeEventListener("keydown",n);};},[s,t,i]),(0,r.useEffect)(()=>{if(!i||0===t)return;let e=f.current;if(null===e)return;let n=e.querySelector(".ft-window-card");(null!=n?n:e).focus();},[i,t]),(0,l.jsxs)("footer",{ref:c,className:"footer mono",tabIndex:-1,"aria-label":d("footer.status"),"aria-live":"polite",children:[(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("span",{className:"ft-brand","aria-label":d("footer.version",{version:m}),children:["Keiko | ",m]}),(0,l.jsxs)("span",{className:"ft-window-wrap",ref:u,children:[(0,l.jsxs)("button",{ref:p,type:"button",className:"ft-seg ft-accent ft-window-trigger","aria-atomic":"true","aria-expanded":i,"aria-controls":"footer-window-palette",disabled:0===t,onClick:a,children:[(0,l.jsx)(I.Icons.tile,{size:13})," ",g]}),i&&t>0?(0,l.jsxs)("div",{ref:f,id:"footer-window-palette",className:"ft-window-palette",role:"group","aria-label":d("footer.openWindows"),tabIndex:-1,children:[(0,l.jsx)("div",{className:"ft-window-palette-head",children:d("footer.openWindows")}),(0,l.jsx)("div",{className:"ft-window-list",children:v.map(e=>{let t=D.WIN_TYPES[e.type],n=I.Icons[t.icon],r=(0,O.subText)(e.type,e.cfg),i=!0===e.minimized?d("footer.minimized"):e.max?d("footer.fullscreen"):d("footer.visible"),a=!0===e.minimized?d("footer.restore"):d("footer.focus"),s=null!==r?` - ${r}`:"";return(0,l.jsxs)("button",{type:"button",className:"ft-window-card","data-minimized":!0===e.minimized?"true":"false","aria-label":d("footer.windowAction",{action:a,title:t.title,suffix:s}),onClick:()=>o(e.id),children:[(0,l.jsx)("span",{className:"ft-window-icon",style:{color:!0===t.accent?"var(--accent)":void 0},children:(0,l.jsx)(n,{size:14})}),(0,l.jsxs)("span",{className:"ft-window-copy",children:[(0,l.jsx)("span",{className:"ft-window-title",children:t.title}),(0,l.jsx)("span",{className:"ft-window-sub",title:null!=r?r:i,children:null!=r?r:i})]}),(0,l.jsx)("span",{className:"ft-window-state",children:i})]},e.id);})})]}):null]})]});}),q=(0,r.memo)(function(e){let{onTileAll:t,onSplitFront:n,onCascade:r,contextControl:i}=e,a=(0,$.useTranslate)();return(0,l.jsxs)("header",{className:"header",children:[(0,l.jsxs)("div",{className:"hd-brand",children:[(0,l.jsx)("img",{className:"hd-logo",src:"/assets/keiko-logo.svg",alt:""}),(0,l.jsx)("span",{className:"hd-wordmark",children:"Keiko"})]}),void 0!==i?(0,l.jsx)("div",{className:"hd-context",children:i}):null,(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("div",{className:"hd-tools",children:[(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:t,"data-tip":a("header.tileAll"),"aria-label":a("header.tileAll"),children:(0,l.jsx)(I.Icons.tile,{size:16})}),(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:n,"data-tip":a("header.splitFront"),"aria-label":a("header.splitFront"),children:(0,l.jsx)(I.Icons.split,{size:16})}),(0,l.jsx)("button",{type:"button",className:"hd-tool ui-tip",onClick:r,"data-tip":a("header.cascade"),"aria-label":a("header.cascade"),children:(0,l.jsx)(I.Icons.cascade,{size:16})})]})]});}),B=[{id:"chatHistory",icon:"archive"}];function _(e){let{tool:t,label:n,active:r,onClick:i}=e,a=I.Icons[t.icon];return(0,l.jsx)("button",{type:"button",className:"rail-btn","data-active":r?"true":"false","data-side":"left","aria-label":n,"aria-pressed":r,"data-tip":n,onClick:i,children:void 0!==t.img?(0,l.jsx)("img",{className:"rail-img",src:t.img,alt:""}):(0,l.jsx)(a,{size:19})});}let G=(0,r.memo)(function(e){let{openTools:t,onTool:n,onNewChat:r,theme:i,onToggleTheme:a}=e,o=(0,$.useTranslate)(),s="light"===i?o("rail.darkMode"):o("rail.lightMode");return(0,l.jsxs)("nav",{className:"rail rail-left","aria-label":o("rail.primaryNavigation"),children:[(0,l.jsx)("button",{type:"button",className:"rail-new",onClick:r,"data-side":"left","aria-label":o("rail.newChat"),"data-tip":o("rail.newChat"),children:(0,l.jsx)(I.Icons.newChat,{size:18})}),(0,l.jsx)("div",{className:"rail-div"}),(0,l.jsx)("div",{className:"rail-group",children:B.map(e=>(0,l.jsx)(_,{tool:e,label:o("rail.chatHistory"),active:t.has(e.id),onClick:()=>n(e.id)},e.id))}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsxs)("div",{className:"rail-group",children:[(0,l.jsx)("button",{type:"button",className:"rail-btn","data-active":t.has("memoria")?"true":"false","data-side":"left","aria-label":o("rail.memoria"),"aria-pressed":t.has("memoria"),"data-tip":o("rail.memoria"),onClick:()=>n("memoria"),children:(0,l.jsx)(I.Icons.brain,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("quality")?"true":"false","aria-label":o("rail.quality"),"aria-pressed":t.has("quality"),"data-tip":o("rail.quality"),onClick:()=>n("quality"),children:(0,l.jsx)(I.Icons.check,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("promptEnhancer")?"true":"false","aria-label":o("rail.promptEnhancer"),"aria-pressed":t.has("promptEnhancer"),"data-tip":o("rail.promptEnhancer"),onClick:()=>n("promptEnhancer"),children:(0,l.jsx)(I.Icons.spark,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("governedGit")?"true":"false","aria-label":"Git","aria-pressed":t.has("governedGit"),"data-tip":"Git",onClick:()=>n("governedGit"),children:(0,l.jsx)(I.Icons.git,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("localKnowledge")?"true":"false","aria-label":o("rail.localKnowledge"),"aria-pressed":t.has("localKnowledge"),"data-tip":o("rail.localKnowledge"),onClick:()=>n("localKnowledge"),children:(0,l.jsx)(I.Icons.localKnowledge,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("figma")?"true":"false","aria-label":o("rail.figma"),"aria-pressed":t.has("figma"),"data-tip":o("rail.figma"),onClick:()=>n("figma"),children:(0,l.jsx)(I.Icons.layers,{size:19})})]}),(0,l.jsx)("div",{className:"rail-div"}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","aria-label":s,"aria-pressed":"light"===i,"data-tip":s,onClick:a,children:"light"===i?(0,l.jsx)(I.Icons.moon,{size:19}):(0,l.jsx)(I.Icons.sun,{size:19})}),(0,l.jsx)("button",{type:"button",className:"rail-btn","data-side":"left","data-active":t.has("settings")?"true":"false","aria-label":o("rail.settings"),"aria-pressed":t.has("settings"),"data-tip":o("rail.settings"),onClick:()=>n("settings"),children:(0,l.jsx)(I.Icons.settings,{size:19})})]});}),U=(0,r.memo)(function(e){return(0,l.jsx)("div",{className:"rail rail-right",children:(0,l.jsx)("span",{className:"spacer"})});});var J=e.i(70703);function V(e){return e.toFixed(2);}function Y(e){let{onNewWindow:t}=e,n=(0,r.useId)(),i=`ewb-${n.replace(/:/gu,"")}`,a=`ewb-desc-${n.replace(/:/gu,"")}`,o=(0,r.useRef)(null),s=(0,r.useRef)(null);(0,r.useEffect)(()=>{let e=e=>{var t;null==(t=o.current)||t.setAttribute("d",function(e){var t,n,l,r;let i=[];for(let t=0;t<150;t++){let n=t/150*Math.PI*2,l=1+.07*(.55*Math.sin(3*n+e)+.32*Math.sin(5*n-.8*e+1.7)+.22*Math.sin(2*n+.5*e+.4));i.push([140+127.44000000000001*l*Math.cos(n),140+118*l*Math.sin(n)]);}let a=`M${V(null!=(t=null==(l=i[0])?void 0:l[0])?t:140)} ${V(null!=(n=null==(r=i[0])?void 0:r[1])?n:140)} `;for(let e=0;e<i.length;e++){let t=i[(e-1+i.length)%i.length],n=i[e],l=i[(e+1)%i.length],r=i[(e+2)%i.length],o=n[0]+(l[0]-t[0])/6,s=n[1]+(l[1]-t[1])/6,c=l[0]-(r[0]-n[0])/6,d=l[1]-(r[1]-n[1])/6;a+=`C${V(o)} ${V(s)} ${V(c)} ${V(d)} ${V(l[0])} ${V(l[1])} `;}return`${a}Z`;}(e));};if(e(.7),"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame)return;let t=0,n=()=>{0!==t&&(window.cancelAnimationFrame(t),t=0);},l=n=>{e(85e-5*n),t=window.requestAnimationFrame(l);},r=()=>{0===t&&!0!==document.hidden&&(t=window.requestAnimationFrame(l));},i=()=>{!0===document.hidden?n():r();};return r(),document.addEventListener("visibilitychange",i),window.addEventListener("blur",n),window.addEventListener("focus",r),()=>{n(),document.removeEventListener("visibilitychange",i),window.removeEventListener("blur",n),window.removeEventListener("focus",r);};},[]);let c=(0,r.useCallback)(()=>{let e=s.current;null!==e&&(e.classList.remove("is-pulse"),e.getBoundingClientRect(),e.classList.add("is-pulse")),t();},[t]);return(0,l.jsxs)("button",{type:"button",className:"empty-workspace-blob","aria-label":"Open a new window","aria-describedby":a,onClick:c,children:[(0,l.jsx)("span",{id:a,className:"visually-hidden",children:"Empty workspace. Open a window to start working."}),(0,l.jsxs)("svg",{width:"320",height:"320",viewBox:"0 0 280 280","aria-hidden":"true",children:[(0,l.jsx)("defs",{children:(0,l.jsxs)("mask",{id:i,maskUnits:"userSpaceOnUse",x:"0",y:"0",width:"280",height:"280",children:[(0,l.jsx)("rect",{x:"0",y:"0",width:"280",height:"280",fill:"#fff"}),(0,l.jsx)("g",{transform:"translate(107,64) scale(0.080625)",children:(0,l.jsx)("g",{transform:"translate(1024 0) scale(-1 1)",children:(0,l.jsx)("g",{transform:"translate(1024,1024) scale(-0.1,-0.1)",fill:"#000",children:(0,l.jsx)("path",{d:"M3465 8223 c-144 -8 -314 -52 -408 -105 -69 -39 -146 -99 -146 -113 0 -5 30 -24 68 -42 146 -70 323 -229 377 -340 25 -49 29 -70 29 -138 -1 -72 -5 -88 -39 -160 -36 -75 -54 -95 -265 -305 -134 -132 -270 -279 -331 -355 -339 -425 -552 -896 -626 -1390 -25 -165 -25 -549 0 -720 92 -645 368 -1196 826 -1655 322 -324 710 -562 1145 -704 389 -126 793 -172 1155 -130 235 27 377 63 579 149 205 87 268 86 423 -7 102 -62 231 -115 335 -138 247 -56 562 -26 794 74 92 40 244 136 232 146 -4 3 -26 12 -48 19 -86 28 -246 116 -385 211 -162 112 -284 182 -357 207 l-48 17 40 15 c185 70 436 223 595 363 438 386 695 1014 678 1663 l-3 120 -50 -70 c-64 -90 -248 -280 -350 -362 -171 -136 -366 -255 -645 -391 -288 -140 -442 -243 -590 -391 -136 -137 -247 -316 -325 -526 -47 -127 -114 -262 -160 -326 -79 -107 -237 -224 -384 -283 -136 -55 -355 -96 -514 -96 -274 0 -548 71 -832 215 -242 123 -375 216 -553 389 -175 171 -287 332 -361 517 -44 114 -63 216 -63 359 0 152 17 233 74 350 35 70 59 102 136 179 l95 94 21 -29 c55 -75 219 -277 277 -338 171 -183 337 -256 582 -256 56 0 126 -3 155 -7 53 -6 54 -7 76 -57 30 -66 97 -128 172 -156 151 -57 318 11 395 160 33 62 34 193 3 261 -30 64 -88 125 -148 157 -44 23 -63 27 -141 27 -78 0 -97 -4 -140 -27 -58 -30 -131 -105 -141 -142 -6 -25 -8 -26 -93 -26 -47 0 -131 5 -186 10 -87 8 -111 15 -182 51 -45 22 -109 66 -143 96 -59 53 -326 361 -319 367 14 11 179 47 241 52 102 9 177 -7 318 -66 158 -66 243 -89 357 -99 157 -12 413 5 582 40 l93 19 44 -39 c59 -52 135 -75 228 -69 117 8 212 72 262 176 23 47 28 71 28 138 0 70 -4 89 -29 138 -55 110 -145 167 -270 174 -65 3 -91 0 -137 -18 -107 -40 -183 -140 -195 -257 l-6 -52 -51 -11 c-104 -23 -285 -41 -411 -42 -149 -1 -211 12 -402 88 -186 74 -256 88 -403 81 -193 -8 -377 -70 -546 -182 -342 -228 -485 -611 -399 -1064 30 -157 119 -388 209 -541 20 -35 35 -64 33 -66 -8 -8 -111 108 -190 214 -154 206 -278 489 -324 737 -28 154 -25 492 6 635 46 216 133 391 256 514 82 82 161 128 271 156 152 39 300 23 529 -57 217 -76 308 -101 410 -114 137 -17 284 -7 426 30 272 70 414 145 809 425 217 153 399 238 610 283 64 14 129 18 265 18 197 0 269 -9 615 -76 461 -89 843 -149 952 -149 41 0 41 0 23 -20 -28 -31 -169 -119 -254 -158 -167 -77 -388 -145 -716 -222 -399 -93 -508 -128 -608 -194 -102 -68 -160 -160 -217 -346 -35 -115 -102 -286 -149 -378 -85 -168 -227 -341 -377 -458 -105 -82 -115 -107 -69 -162 29 -34 65 -44 109 -29 86 29 261 181 371 322 126 162 201 309 295 581 61 176 90 232 145 283 62 57 163 93 470 165 439 104 640 169 863 278 206 100 368 240 434 375 32 67 33 71 33 198 -1 120 -3 138 -34 229 -98 294 -319 655 -573 936 -381 421 -968 723 -1618 834 -448 76 -767 83 -1169 25 -80 -12 -165 -19 -190 -17 -26 3 -90 26 -146 53 -343 162 -576 233 -842 255 -114 9 -141 10 -248 3z m2926 -1227 c164 -27 346 -102 485 -202 181 -129 354 -348 354 -448 0 -64 -75 -126 -154 -126 -60 0 -63 4 -52 70 8 50 7 65 -9 100 -29 64 -74 93 -151 98 -54 4 -70 1 -107 -21 -42 -25 -61 -52 -91 -129 -25 -64 -55 -73 -246 -73 -121 0 -187 5 -248 18 -318 70 -556 242 -556 402 0 218 388 374 775 311z m-2249 -611 c119 -21 208 -50 321 -106 114 -56 177 -100 266 -184 67 -63 157 -173 148 -181 -2 -3 -61 18 -130 45 -131 52 -298 100 -427 122 -113 20 -367 17 -470 -4 -502 -106 -885 -433 -1160 -992 -70 -142 -160 -379 -160 -424 0 -9 -5 -23 -11 -31 -13 -19 -5 316 10 410 80 482 295 846 661 1117 145 107 350 197 522 228 100 18 326 18 430 0z m1485 -1456 c95 -36 119 -159 42 -223 -78 -66 -209 -1 -209 104 0 60 33 100 99 121 36 10 36 10 68 -2z m-591 -822 c29 -26 37 -42 40 -77 6 -54 -9 -86 -55 -117 -41 -28 -70 -29 -119 -4 -44 22 -62 55 -62 112 0 51 13 75 53 99 50 31 101 26 143 -13z"})})})}),(0,l.jsx)("text",{x:"140",y:"172",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"16",fontWeight:"700",children:"Empty workspace"}),(0,l.jsx)("text",{x:"140",y:"191",textAnchor:"middle",fill:"#000",fontFamily:"var(--font-ui)",fontSize:"11",fontWeight:"400",children:"Open a window to start working"})]})}),(0,l.jsx)("g",{ref:s,className:"empty-workspace-blob__group",children:(0,l.jsx)("path",{ref:o,className:"empty-workspace-blob__fill",mask:`url(#${i})`})})]})]});}var X=e.i(80137);let H=new Set(["files","connector","browser","plugins","agents","quality"]);function Z(e){return{left:e.x,top:e.y,right:e.x+e.w,bottom:e.y+e.h};}function Q(e,t){return e>=4||t>=8192;}function ee(e){let{pathId:t,intensity:n}=e,r="heavy"===n?3:1,i="heavy"===n?1.1:2.2;return(0,l.jsx)(l.Fragment,{children:Array.from({length:r},(e,a)=>(0,l.jsx)("circle",{className:"conn-particle",r:"heavy"===n?3:2.4,"aria-hidden":"true",children:(0,l.jsx)("animateMotion",{dur:`${String(i)}s`,repeatCount:"indefinite",begin:`${String(i/r*a)}s`,rotate:"auto",keyPoints:"0;1",keyTimes:"0;1",calcMode:"linear",children:(0,l.jsx)("mpath",{href:`#${t}`})})},a))});}let et=(0,r.memo)(function(e){let{wins:t,conns:n,connecting:a,api:o}=e,s=(0,i.useOptionalChatSessionActivity)(),c=function(){let[e,t]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{let e=window.matchMedia("(prefers-reduced-motion: reduce)");t(e.matches);let n=e=>t(e.matches);return e.addEventListener("change",n),()=>e.removeEventListener("change",n);},[]),e;}(),{armedId:d,arm:u,disarm:p,autoCancelledNonce:f}=function(){let[e,t]=(0,r.useState)(null),[n,l]=(0,r.useState)(0);return(0,r.useEffect)(()=>{if(null===e)return;let n=setTimeout(()=>{t(null),l(e=>e+1);},3e3);return()=>clearTimeout(n);},[e]),{armedId:e,arm:e=>t(e),disarm:()=>t(null),autoCancelledNonce:n};}(),[m,h]=(0,r.useState)(""),g=(0,r.useRef)(f);(0,r.useEffect)(()=>{f!==g.current&&(g.current=f,h("Removal cancelled — the connection was not removed."));},[f]);let{flowing:v,intensity:w}=function(e,t){let[n,l]=(0,r.useState)("light"),[i,a]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{if(void 0===t)return;l(function(e){switch(e.groundingKind){case"connected-context":return Q(e.contextPack.usage.filesRead,e.contextPack.usage.excerptBytes)?"heavy":"light";case"hybrid":return Q(e.contextPack.folder.usage.filesRead,e.contextPack.folder.usage.excerptBytes)||e.contextPack.knowledge.referencesUsed>=4?"heavy":"light";case"local-knowledge":return e.contextPack.referencesUsed>=4?"heavy":"light";default:return"light";}}(t)),a(!0);let e=setTimeout(()=>a(!1),2500);return()=>clearTimeout(e);},[t]),{flowing:e||i,intensity:n};}((null==s?void 0:s.sending)===!0,null==s?void 0:s.latestGrounded),y=(0,r.useMemo)(()=>function(e,t){let n=new Map(e.map(e=>[e.id,e])),l=[];for(let e of t){let t=n.get(e.a),r=n.get(e.b);if(void 0===t||void 0===r)continue;let i=(0,O.connPath)(t,r);l.push({c:e,d:i.d,mid:i.mid,label:(0,O.relLabel)(t,r),dataChannel:function(e,t){let n=[e.type,t.type].includes("chat"),l="chat"===e.type?H.has(t.type):H.has(e.type);return n&&l;}(t,r)});}return l;}(t,n),[t,n]),b=(0,r.useMemo)(()=>{let e=t.filter(e=>!0!==e.minimized).map(Z),n=new Set();for(let t of y)(function(e,t,n){let l,r=(l=Math.min(240,Math.max(40,7.2*e.label.length))+(44+18*!!n),{left:e.mid.x-l/2,right:e.mid.x+l/2,top:e.mid.y-13,bottom:e.mid.y+13});return!t.some(e=>r.left<e.right&&r.right>e.left&&r.top<e.bottom&&r.bottom>e.top);})(t,e,v&&t.dataChannel)&&n.add(t.c.id);return n;},[v,y,t]),k=null!==a?function(e,t){let n=t.find(t=>t.id===e.from);if(void 0===n)return null;let l={x:n.x+n.w/2,y:n.y+n.h/2},r=e.x-l.x,i=e.y-l.y,a=Math.abs(r)>=Math.abs(i),o=a?{x:r>=0?n.x+n.w:n.x,y:l.y}:{x:l.x,y:i>=0?n.y+n.h:n.y},s=Math.max(40,Math.abs(a?r:i)/2),c=a?{x:o.x+(r>=0?s:-s),y:o.y}:{x:o.x,y:o.y+(i>=0?s:-s)},d=e.x,u=e.y;return{d:`M${String(o.x)},${String(o.y)} C${String(c.x)},${String(c.y)} ${String(d)},${String(u)} ${String(d)},${String(u)}`,ex:d,ey:u};}(a,t):null;return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsx)("div",{className:"conn-layer",children:(0,l.jsxs)("svg",{className:"conn-svg",viewBox:"-10000 -10000 20000 20000",preserveAspectRatio:"xMidYMid meet",children:[y.map(e=>{let t=v&&e.dataChannel,n=`conn-path-${e.c.id}`;return(0,l.jsxs)("g",{children:[(0,l.jsx)("path",{id:n,className:"conn-path",d:e.d,"data-active":t?"true":void 0,"data-intensity":t?w:void 0,"data-reduced-motion":t&&c?"true":void 0}),t&&!c?(0,l.jsx)(ee,{pathId:n,intensity:w}):null]},e.c.id);}),null!==k?(0,l.jsx)("path",{className:"conn-path conn-temp",d:k.d}):null,null!==k?(0,l.jsx)("circle",{className:"conn-dot",cx:k.ex,cy:k.ey,r:"5"}):null]})}),(0,l.jsxs)("div",{className:"conn-badge-layer",children:[(0,l.jsx)("div",{className:"visually-hidden",role:"status","aria-live":"polite",children:m}),y.map(e=>{let t,n=v&&e.dataChannel;if(!b.has(e.c.id))return null;let r=d===e.c.id,i=(t=[`Connection: ${e.label}`],void 0!==e.c.boundRoot&&t.push(`Root: ${e.c.boundRoot}`),void 0!==e.c.boundScopeKind&&t.push(`Scope: ${e.c.boundScopeKind}`),void 0!==e.c.boundRelativePath&&e.c.boundRelativePath.length>0&&t.push(`Path: ${e.c.boundRelativePath}`),void 0!==e.c.boundConnectorKind&&void 0!==e.c.boundConnectorId&&t.push(`Knowledge: ${e.c.boundConnectorKind} ${e.c.boundConnectorId}`),t.join("\n"));return(0,l.jsxs)("button",{type:"button",className:"conn-badge","data-active":n?"true":void 0,"data-intensity":n?w:void 0,"data-armed":r?"true":void 0,style:{left:e.mid.x,top:e.mid.y},onClick:()=>{r?(p(),o.removeConn(e.c.id)):u(e.c.id);},onBlur:()=>{r&&p();},title:r?`Click again to remove: ${e.label}
|
|
2
2
|
|
|
3
3
|
${i}`:`${i}
|
|
4
4
|
|
|
5
|
-
Click once to arm removal.`,"aria-label":r?`Confirm removal of connection: ${e.label}. Activate again to remove.`:n?`${e.label} — ${w} data exchange in progress. Activate to remove connection.`:`Remove connection: ${e.label}`,children:[(0,l.jsx)(I.Icons.git,{size:11})," ",(0,l.jsx)("span",{children:r?"Remove?":e.label}),n&&!r?(0,l.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===w?"⇶":"→"}):null]},e.c.id);})]})]});}),en=["n","s","e","w","ne","nw","se","sw"],el=["t","r","b","l"];function er(e){let{icon:t,label:n}=e,r=I.Icons[t];return(0,l.jsxs)("div",{className:"too-small",children:[(0,l.jsx)("div",{className:"ts-ico",children:(0,l.jsx)(r,{size:28})}),(0,l.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,l.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom its content out"}),(0,l.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,l.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,l.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]});}function ei(e,t){return"figmaView"===e&&"string"==typeof t.selectedScreenIdsJson&&t.selectedScreenIdsJson.length>0;}function ea(e,t){return e.x===t.x&&e.y===t.y&&e.w===t.w&&e.h===t.h;}let eo=Object.freeze([]),es=Object.freeze({linkedRoot:null,linkedFilePath:void 0,linkedRoots:eo,linkedCapsuleIds:eo,linkedCapsuleSetIds:eo,linkedFigmaSnapshotRunIds:eo,linkedFigmaSnapshotSources:void 0,linkedImageSources:void 0}),ec=(0,r.memo)(function(e){var t,n,i;let{win:o,top:s,connState:c,api:d,wsRef:u,linkRevision:p}=e,f=D.WIN_TYPES[o.type],m=(0,O.hasConnectablePeer)(o.type),h=I.Icons[f.icon],g=(0,r.useContext)(a),v=null!=(t=null==g?void 0:g.activeRoot)?t:null,w=null!=(n=null==g?void 0:g.activeBinding)?n:null,[y,b]=(0,r.useState)(!1),k=(0,r.useRef)(null),x=(0,r.useRef)(null),
|
|
5
|
+
Click once to arm removal.`,"aria-label":r?`Confirm removal of connection: ${e.label}. Activate again to remove.`:n?`${e.label} — ${w} data exchange in progress. Activate to remove connection.`:`Remove connection: ${e.label}`,children:[(0,l.jsx)(I.Icons.git,{size:11})," ",(0,l.jsx)("span",{children:r?"Remove?":e.label}),n&&!r?(0,l.jsx)("span",{className:"conn-flow-tag","aria-hidden":"true",children:"heavy"===w?"⇶":"→"}):null]},e.c.id);})]})]});}),en=["n","s","e","w","ne","nw","se","sw"],el=["t","r","b","l"];function er(e){let{icon:t,label:n}=e,r=I.Icons[t];return(0,l.jsxs)("div",{className:"too-small",children:[(0,l.jsx)("div",{className:"ts-ico",children:(0,l.jsx)(r,{size:28})}),(0,l.jsxs)("div",{className:"ts-title",children:["Too small to show ",n]}),(0,l.jsx)("div",{className:"ts-sub",children:"Enlarge the window or zoom its content out"}),(0,l.jsx)("div",{className:"ts-arrow","aria-hidden":"true",children:(0,l.jsx)("svg",{width:"22",height:"22",viewBox:"0 0 22 22",fill:"none",stroke:"currentColor",strokeWidth:"1.7",strokeLinecap:"round",strokeLinejoin:"round",children:(0,l.jsx)("path",{d:"M8 8l8 8M16 11v5h-5"})})})]});}function ei(e,t){return"figmaView"===e&&"string"==typeof t.selectedScreenIdsJson&&t.selectedScreenIdsJson.length>0;}function ea(e,t){return e.x===t.x&&e.y===t.y&&e.w===t.w&&e.h===t.h;}let eo=Object.freeze([]),es=Object.freeze({linkedRoot:null,linkedFilePath:void 0,linkedRoots:eo,linkedCapsuleIds:eo,linkedCapsuleSetIds:eo,linkedFigmaSnapshotRunIds:eo,linkedFigmaSnapshotSources:void 0,linkedImageSources:void 0}),ec=(0,r.memo)(function(e){var t,n,i;let{win:o,top:s,connState:c,api:d,wsRef:u,linkRevision:p}=e,f=D.WIN_TYPES[o.type],m=(0,O.hasConnectablePeer)(o.type),h=I.Icons[f.icon],g=(0,r.useContext)(a),v=null!=(t=null==g?void 0:g.activeRoot)?t:null,w=null!=(n=null==g?void 0:g.activeBinding)?n:null,[y,b]=(0,r.useState)(!1),k=(0,r.useRef)(null),x=(0,r.useRef)(null),j=(0,r.useRef)(null),C=null!=(i=o.zoom)?i:1,S=function(e,t){if(!ei(e,t))return null;let n="string"==typeof t.snapshotRunId?t.snapshotRunId:"",l="string"==typeof t.selectedScreenIdsJson?t.selectedScreenIdsJson:"",r="string"==typeof t.selectedScreenName?t.selectedScreenName:"";return`${n}
|
|
6
6
|
${l}
|
|
7
|
-
${r}`;}(o.type,o.cfg),N=(0,r.useMemo)(()=>{var e,t,n,l,r;let i,a,s,c,u,p,f,m,h,g;return e=o.type,t=o.id,i=(0,O.receivesFilesContext)(e),a=(0,O.receivesFocusedFileContext)(e),s="quality"===e||"editor"===e,c=i?d.linkedFilesRoot(t):null,u=a?null==(n=d.linkedFilesContext(t))?void 0:n.activeFilePath:void 0,p="quality"===e||"promptEnhancer"===e?d.linkedAllFilesRoots(t):null!==c?[c]:eo,f=s?d.linkedConnectorCapsuleIds(t):eo,m=s?d.linkedConnectorCapsuleSetIds(t):eo,h="quality"===e?d.linkedFigmaSnapshotRunIds(t):eo,null===(g={linkedRoot:c,linkedFilePath:u,linkedRoots:p,linkedCapsuleIds:f,linkedCapsuleSetIds:m,linkedFigmaSnapshotRunIds:h,linkedFigmaSnapshotSources:"quality"===e?null==(l=d.linkedFigmaSnapshotSources)?void 0:l.call(d,t):void 0,linkedImageSources:"quality"===e?null==(r=d.linkedImageSources)?void 0:r.call(d,t):void 0}).linkedRoot&&void 0===g.linkedFilePath&&0===g.linkedRoots.length&&0===g.linkedCapsuleIds.length&&0===g.linkedCapsuleSetIds.length&&0===g.linkedFigmaSnapshotRunIds.length&&(void 0===g.linkedFigmaSnapshotSources||0===g.linkedFigmaSnapshotSources.length)&&(void 0===g.linkedImageSources||0===g.linkedImageSources.length)?es:g;},[d,o.type,o.id,p]),E=Math.round(Math.max(0,o.w-2)/j*1e3)/1e3,R=Math.round(Math.max(0,o.h-2)/j*1e3)/1e3,A=(0,r.useRef)(o.cfg);A.current=o.cfg;let P=(0,r.useCallback)(e=>{d.update(o.id,{cfg:{...A.current,...e}});},[d,o.id]),M=(0,r.useCallback)((e,t)=>d.add(e,t),[d]),T=(0,r.useCallback)(e=>d.openEditorFile(e),[d]),z=(0,r.useCallback)(e=>d.focus(e),[d]),F=(0,r.useCallback)(e=>d.restore(e),[d]),L=(0,r.useCallback)((e,t)=>d.update(e,t),[d]),W=function(e,t,n){if("chat"===e){let e=+(t<D.CHAT_MINI_W);return`chat:${String(+(t<640))}${String(+(t<520))}${String(+(t<360||n<320))}${String(e)}`;}let l=D.WIN_TYPES[e],r=+(t<l.tiny.w||n<l.tiny.h);return`gen:${String(r)}`;}(o.type,E,R),{mode:$,node:K}=(0,r.useMemo)(()=>function(e,t,n,r,i,a,o,s,c,d,u,p,f,m,h,g,v,w,y,b,k){let x=D.WIN_TYPES[t];if("chat"===t){let t=n<520,l=n<D.CHAT_MINI_W;return{mode:l?"mini":"full",node:x.render(i,{windowId:e,mini:l,minimalChat:n<360||r<320,compact:n<640,controlsNarrow:t,barCompact:n<520,workflowCompact:t,linkedRoot:a,linkedFilePath:o,linkedRoots:s,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:f,activeRoot:m,activeBinding:h,updateCfg:g,openWindow:v,focusWindow:w,restoreWindow:y,updateWindow:b,openEditorFile:k})};}return n<x.tiny.w||r<x.tiny.h?{mode:"tiny",node:(0,l.jsx)(er,{icon:x.icon,label:x.title})}:{mode:"full",node:x.render(i,{windowId:e,linkedRoot:a,linkedFilePath:o,linkedRoots:s,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:f,activeRoot:m,activeBinding:h,updateCfg:g,openWindow:v,focusWindow:w,restoreWindow:y,updateWindow:b,openEditorFile:k})};}(o.id,o.type,E,R,o.cfg,N.linkedRoot,N.linkedFilePath,N.linkedRoots,N.linkedCapsuleIds,N.linkedCapsuleSetIds,N.linkedFigmaSnapshotRunIds,N.linkedFigmaSnapshotSources,N.linkedImageSources,v,w,P,M,z,F,L,T),[o.id,o.type,o.cfg,W,N,v,w,P,M,z,F,L,T]),q=(0,r.useCallback)(e=>d.update(o.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[d,o.id]);(0,r.useEffect)(()=>{C.current!==S&&(C.current=null);},[S]);let B=(0,r.useCallback)(()=>{null!==S&&(C.current=S);},[S]);(0,r.useEffect)(()=>{if(!ei(o.type,o.cfg)||o.max||"full"!==$||null===S)return;let e=k.current;if(null===e)return;let t=null,n=()=>{if(t=null,C.current===S)return;let n=e.scrollHeight-e.clientHeight;if(n<=8)return;let l=Math.ceil(o.h+n);l<=o.h+8||d.update(o.id,{h:l});},l=()=>{null===t&&(t="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(n):window.setTimeout(n,0));};l();let r="u">typeof ResizeObserver?new ResizeObserver(l):null;null==r||r.observe(e);let i=e.firstElementChild;return null!==i&&(null==r||r.observe(i)),()=>{null!==t&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(t):window.clearTimeout(t)),null==r||r.disconnect();};},[d,$,S,o.cfg,o.h,o.id,o.max,o.type]),(0,r.useEffect)(()=>()=>{var e;null==(e=x.current)||e.call(x),x.current=null;},[]);let _=(0,r.useCallback)(e=>{(0,X.isTextEntryTarget)(e)?window.setTimeout(()=>d.focus(o.id),180):(0,X.isInteractiveControlTarget)(e)?window.setTimeout(()=>d.focus(o.id),0):d.focus(o.id);},[d,o.id]),G=(0,r.useCallback)(e=>{var t,n,l,r,i,a,s,p;let f,m,h,g,v,w,y,k,x,C,j,S,N,I;if(!(0,X.isWindowDragPointer)(e)||"valid"===c)return;e.preventDefault(),_(e.target);let E=u.current;if(null===E)return;let R=(i=E.getBoundingClientRect(),{z:f=(a=d.currentView()).zoom,vpx0:-a.x/f,vpy0:-a.y/f,vpw:i.width/f,vph:i.height/f,toWX:e=>(e-i.left-a.x)/f,toWY:e=>(e-i.top-a.y)/f}),A=o.max,P=A?null!=(t=null==(l=o.prev)?void 0:l.w)?t:480:o.w,M=A?null!=(n=null==(r=o.prev)?void 0:r.h)?n:360:o.h,T=A?P/2:R.toWX(e.clientX)-o.x,z=A?18:R.toWY(e.clientY)-o.y;A&&d.update(o.id,{max:!1,w:P,h:M}),b(!0),s={winId:o.id,offX:T,offY:z,W:P},p=()=>b(!1),h=30/R.z,g=0,v=0,w=null,y=!1,k=null,x=null,C=null,j=()=>{C=null,y&&(y=!1,w!==m&&(m=w,d.setSnap(w)),(g!==k||v!==x)&&(k=g,x=v,d.update(s.winId,{x:g,y:v})));},S=e=>{let t,n,l,r,i=R.toWX(e.clientX),a=R.toWY(e.clientY),o=i-s.offX,c=a-s.offY;o=Math.max(R.vpx0-(s.W-120),Math.min(R.vpx0+R.vpw-120,o)),c=Math.max(R.vpy0,Math.min(R.vpy0+R.vph-38,c)),g=o,v=c,t=i-R.vpx0<h,n=R.vpx0+R.vpw-i<h,l=a-R.vpy0<h,r=R.vpy0+R.vph-a<h,w=l&&t?"tl":l&&n?"tr":r&&t?"bl":r&&n?"br":t?"left":n?"right":l?"maxi":null,y=!0,null===C&&(C="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(j):window.setTimeout(j,0));},N=()=>{window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),null!==C&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(C):window.clearTimeout(C),C=null),j(),d.commitSnap(s.winId),I(),null==p||p();},I=(0,X.acquireGrabbingBodyStyle)(),window.addEventListener("pointermove",S),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N);},[d,o.id,o.x,o.y,o.w,o.h,o.max,o.prev,u,c,_]),U=(0,r.useCallback)(e=>t=>{var n;if(!(0,X.isPrimaryActivationPointer)(t))return;t.preventDefault(),t.stopPropagation(),null==(n=x.current)||n.call(x),x.current=null,d.focus(o.id);let l={x:o.x,y:o.y,w:o.w,h:o.h},r=l,i=t.clientX,a=t.clientY,s=d.currentView().zoom,c=document.body.style.cursor,u=!0,p=null,f=null,m=()=>{if(f=null,null===p)return;let e=p;p=null,ea(r,e)||(r=e,d.update(o.id,{...e,max:!1}));},h=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];u&&(u=!1,window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g),window.removeEventListener("blur",g),e?null!==p&&null===f&&(f="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(m):window.setTimeout(m,0)):(null!==f&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(f):window.clearTimeout(f),f=null),p=null),document.body.style.cursor=c,x.current===h&&(x.current=null));},g=()=>{h(!0);},v=t=>{var n;!u||(0===t.buttons?h(!0):(n=function(e,t,n,l,r){let{x:i,y:a,w:o,h:s}=e;t.includes("e")&&(o=e.w+n),t.includes("s")&&(s=e.h+l),t.includes("w")&&(o=e.w-n,i=e.x+n),t.includes("n")&&(s=e.h-l,a=e.y+l);let c=D.WIN_TYPES[r].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return o<d&&(t.includes("w")&&(i-=d-o),o=d),s<u&&(t.includes("n")&&(a-=u-s),s=u),{x:i,y:a,w:o,h:s};}(l,e,(t.clientX-i)/s,(t.clientY-a)/s,o.type),null!==p&&ea(p,n)||null===p&&ea(r,n)||(B(),p=n,null===f&&(f="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(m):window.setTimeout(m,0)))));};document.body.style.cursor="n"===e||"s"===e?"ns-resize":"e"===e||"w"===e?"ew-resize":"ne"===e||"sw"===e?"nesw-resize":"nwse-resize",window.addEventListener("pointermove",v),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),window.addEventListener("blur",g),x.current=h;},[d,o.id,o.x,o.y,o.w,o.h,o.type,B]),J=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();d.startConnect(o.id,{clientX:"clientX"in t?t.clientX:n.left+n.width/2,clientY:"clientY"in t?t.clientY:n.top+n.height/2,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()});},[d,o.id]),V=(0,r.useCallback)(e=>{(0,X.isPrimaryActivationPointer)(e)&&(e.preventDefault(),e.stopPropagation(),J(e.currentTarget,e));},[J]),Y=(0,r.useCallback)(e=>{if("Enter"===e.key||" "===e.key||"Spacebar"===e.key){if("valid"===c)return void d.confirmConnect(o.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});e.preventDefault(),e.stopPropagation(),J(e.currentTarget,e);}},[J,c,d,o.id]),H=(0,r.useCallback)(()=>{let e=s?null:document.querySelector('.window[data-top="true"]');requestAnimationFrame(()=>{var t,n,l;let r=null!=(t=null!=(n=null!=(l=null!==e&&e.isConnected?e:null)?l:document.querySelector('.window[data-top="true"]'))?n:document.querySelector(".ws-fab"))?t:document.querySelector(".window[data-window-id]");null==r||r.focus({preventScroll:!0});});},[s]),Z=(0,r.useCallback)(()=>{d.close(o.id),H();},[d,o.id,H]),Q=(0,r.useCallback)(()=>{d.minimize(o.id),H();},[d,o.id,H]),ee=(0,r.useCallback)(e=>{e.target!==e.currentTarget||"valid"!==c||"Enter"===e.key&&d.confirmConnect(o.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});},[d,o.id,c]),et="full"===$?(0,O.subText)(o.type,o.cfg):null,ec="full"===$&&E>=340,ed="full"===$&&"editor"!==o.type,eu=(0,r.useMemo)(()=>ed?{contain:"layout style paint",contentVisibility:"auto",containIntrinsicSize:`${String(Math.round(E))}px ${String(Math.round(R))}px`}:{contain:"layout style paint"},[ed,E,R]),ep=(0,r.useMemo)(()=>({left:0,top:0,width:o.w,height:o.h,zIndex:o.z,transform:`translate3d(${String(o.x)}px, ${String(o.y)}px, 0)`}),[o.x,o.y,o.w,o.h,o.z]),ef=(0,r.useMemo)(()=>({width:E,height:R,transform:`scale(${String(j)})`,transformOrigin:"0 0"}),[E,R,j]);return(0,l.jsxs)("section",{className:"window","aria-label":null!==et?`${f.title} — ${et}`:f.title,"aria-roledescription":"window","data-top":s?"true":"false","data-max":o.max?"true":"false","data-conn":null!=c?c:void 0,"data-dragging":y?"true":void 0,"data-window-id":o.id,style:ep,tabIndex:-1,onPointerDown:e=>{"valid"===c&&d.confirmConnect(o.id,e),_(e.target);},onKeyDown:ee,onFocusCapture:()=>{s||window.setTimeout(()=>d.focus(o.id),0);},children:[(0,l.jsx)("div",{className:"win-frame-clip",children:(0,l.jsxs)("div",{className:"win-content-zoom",style:ef,children:[(0,l.jsxs)("header",{className:"win-head",onPointerDown:G,onDoubleClick:e=>{(function(e){let t=e.target;if(t instanceof Element&&null!==t.closest("button,[role='button']"))return!1;let n=e.currentTarget.getBoundingClientRect(),l=Math.min(210,n.width/2);return e.clientX<n.right-l;})(e)&&d.maximize(o.id);},children:[(0,l.jsx)("span",{className:"win-ico",style:{color:!0===f.accent?"var(--accent)":"var(--fg-muted)"},children:(0,l.jsx)(h,{size:14})}),(0,l.jsx)("span",{className:"win-title",children:f.title}),null!==et?(0,l.jsx)("span",{className:"win-sub mono",title:et,children:(0,l.jsx)("span",{className:"win-sub-text",children:et})}):null,(0,l.jsx)("span",{className:"spacer"}),ec?(0,l.jsxs)("div",{className:"win-zoom",children:[(0,l.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content out","aria-label":`Zoom ${f.title} content out`,disabled:j<=.5,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>q(j-.1),children:(0,l.jsx)(I.Icons.zoomOut,{size:13})}),(0,l.jsxs)("button",{type:"button",className:"win-zpct ui-tip","data-tip":"Reset content zoom to 100%","aria-label":`${String(Math.round(100*j))}% — reset ${f.title} content zoom`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>d.update(o.id,{zoom:1}),children:[Math.round(100*j),"%"]}),(0,l.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content in","aria-label":`Zoom ${f.title} content in`,disabled:j>=2,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>q(j+.1),children:(0,l.jsx)(I.Icons.zoomIn,{size:13})})]}):null,(0,l.jsxs)("div",{className:"win-traffic",role:"group","aria-label":`${f.title} window controls`,children:[(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-minimize ui-tip","data-tip":"Minimize","aria-label":`Minimize ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:Q,children:(0,l.jsx)(I.Icons.minimize,{size:17})}),(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-maximize ui-tip","data-tip":o.max?"Restore":"Full screen","aria-label":o.max?`Restore ${f.title} window`:`Full screen ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>d.maximize(o.id),children:o.max?(0,l.jsx)(I.Icons.restore,{size:17}):(0,l.jsx)(I.Icons.maximize,{size:17})}),(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-close ui-tip","data-tip":"Close","aria-label":`Close ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:Z,children:(0,l.jsx)(I.Icons.close,{size:17})})]})]}),(0,l.jsx)("div",{ref:k,className:"win-body","data-mode":$,style:eu,children:K})]})}),o.max?null:en.map(e=>(0,l.jsx)("div",{className:`wz wz-${e}`,"aria-hidden":"true",onPointerDown:U(e)},e)),!o.max&&m?el.map(e=>(0,l.jsx)("button",{type:"button",className:`win-port wp-${e}`,title:"Click to connect to another window","aria-label":`Connect ${f.title} from ${"t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"} edge`,onPointerDown:V,onKeyDown:Y},`p${e}`)):null]});}),ed=[/\bsk-[A-Za-z0-9_-]{20,}\b/,/\bAKIA[0-9A-Z]{16}\b/,/\bgh[pousr]_[A-Za-z0-9]{36,}\b/,/\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,/-----BEGIN [A-Z ]*PRIVATE KEY-----/],eu=/\b(?:\d[ -]?){13,19}\b/g;var ep=e.i(7877);let ef=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],em=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],eh=[".env",".env.local",".env.development",".env.test",".env.production"],eg={chat:["chatId"],editor:["openFiles","layoutJson"],files:["activeFilePath","activeDirectoryPath","resolvedRoot"],figma:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaView:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaJson:["snapshotRunId","screenId","selectedScreenIdsJson","selectedScreenName"],figmaImage:["snapshotRunId","screenId","selectedScreenName","imageSrc"],pdfCitationPreview:["anchorQuality","currentPage","documentLabel","failureMessage","failureRetryable","failureTitle","pageLabel","pageNumber","rotation","sourceLabel","zoomMode","zoomValue"]};function ev(e){return"number"==typeof e&&Number.isFinite(e);}function ew(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function ey(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of ed)if(t.test(e))return!0;for(let t of e.matchAll(eu)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let l=e.length-1;l>=0;l-=1){let r=Number(e[l]);n&&(r*=2)>9&&(r-=9),t+=r,n=!n;}return t%10==0;}(e))return!0;}return!1;}(t)||function(e){let t="bearer ",n=e.toLowerCase().indexOf(t);if(-1===n)return!1;let l=0;for(let i=n+t.length;i<e.length;i+=1){var r;if(0===(null!=(r=e[i])?r:"").trim().length)break;l+=1;}return l>=8;}(t)||function(e){if(!e.includes("://"))return!1;try{let t=new URL(e);return t.username.length>0||t.password.length>0;}catch{return!1;}}(t)||em.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,l;let r=null!=(n=t[e])?n:"",i=null!=(l=t[e+1])?l:"";if(eh.includes(r)||".npmrc"===r||"credentials.json"===r||".aws"===r&&"credentials"===i||".ssh"===r&&i.startsWith("id_"))return!0;}return!1;}(t);}function eb(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||ey(e))return!1;for(let t of e)if(!function(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||46===t||95===t||45===t;}(t))return!1;return!0;}function ek(e){if(0===e.length||e.length>256||e.trim()!==e||ey(e))return!1;for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,l=e>=65&&e<=90,r=e>=97&&e<=122,i=46===e||58===e||95===e||45===e;if(!n&&!l&&!r&&!i)return!1;}return!0;}function ex(e,t){let n,l;if("string"!=typeof e)return;let r=e.trim();if(!(0===r.length||r.length>t||ey(r)||(l=(n=r.trim()).replace(/\\/gu,"/"),/^file:/iu.test(n)||/^[A-Za-z]:\//u.test(l)||l.startsWith("/")||l.startsWith("~/")||l.includes("/Users/")||l.includes("/home/")||l.includes("/Volumes/")||l.includes("../"))))return r;}function eC(e){if(!Array.isArray(e)||0===e.length)return;let t=[];for(let n of e){if("string"!=typeof n)return;let e=n.trim().replace(/\\/gu,"/").replace(/^\/+/u,"");if(!(0===e.length||e.length>512||e.replace(/\\/gu,"/").split("/").some(e=>".."===e)||ey(e)||t.includes(e))&&(t.push(e),t.length>=64))break;}return t.length>0?t:void 0;}function ej(e){let t=[];for(let n of e){let e=function(e){var t;if(!ew(e)||!("string"==typeof(t=e.type)&&t in D.WIN_TYPES))return null;let n=e.type;if("transient"===ep.WIN_META[n].persistence||"string"!=typeof e.id||!ev(e.x)||!ev(e.y)||!ev(e.w)||!ev(e.h)||!ev(e.z)||"boolean"!=typeof e.max)return null;let l={id:e.id,type:n,x:e.x,y:e.y,w:e.w,h:e.h,z:e.z,cfg:function(e,t){var n,l;if(!ew(t)||"durable.config"===ep.WIN_META[e].persistence)return{};let r=new Set([...(null!=(n=D.WIN_TYPES[e].config)?n:[]).map(e=>e.key),...(null!=(l=eg[e])?l:[])]),i={};for(let[n,l]of Object.entries(t)){if(!r.has(n))continue;let t=function(e,t,n){let l;if("editor"===e&&"openFiles"===t)return eC(n);if("editor"===e&&"layoutJson"===t)return function(e){let t;if("string"!=typeof e||0===e.length)return;try{t=JSON.parse(e);}catch{return;}if("object"!=typeof t||null===t||Array.isArray(t))return;let n=t;if(2===n.schemaVersion||2===n.version){let e=ew(n.panes)?n.panes:{},t={};for(let[n,r]of Object.entries(e)){var l;if(!ew(r))continue;let e="string"==typeof r.activeFile?eC([r.activeFile]):void 0,i=null==e?void 0:e[0],a=eC(r.openFiles),o=null!=(l=eC(r.tabOrder))?l:a;if(void 0===a&&void 0===i)continue;let s=null!=a?a:e;if(void 0===s)continue;let c=void 0!==i&&s.includes(i)?i:s[0];t[n.slice(0,48)]={id:n.slice(0,48),activeFile:c,openFiles:s,tabOrder:null!=o?o:s};}let r=new Set(Object.keys(t)),i=e=>{if(!ew(e))return null;if("pane"===e.type&&"string"==typeof e.paneId&&r.has(e.paneId))return{type:"pane",paneId:e.paneId};if("split"===e.type){let t=i(e.first),n=i(e.second);if(null===t||null===n)return null;let l="number"==typeof e.ratio&&Number.isFinite(e.ratio)?Math.min(85,Math.max(15,Math.round(e.ratio))):50;return{type:"split",id:"string"==typeof e.id?e.id.slice(0,48):"split-1",direction:"column"===e.direction?"column":"row",ratio:l,first:t,second:n};}return null;},a=i(n.tree),o=Object.keys(t)[0];if(null===a||void 0===o)return;let s="string"==typeof n.activePaneId&&r.has(n.activePaneId)?n.activePaneId:o,c="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260;return JSON.stringify({schemaVersion:2,root:function(e){if("string"!=typeof e)return"";let t=e.trim();return 0===t.length||t.length>512||ey(t)?"":t;}(n.root),activePaneId:s,tree:a,panes:t,sidebarWidth:c,sidebarCollapsed:!0===n.sidebarCollapsed});}let r=Array.isArray(n.panes)?n.panes.slice(0,2):[],i=[];for(let[e,t]of r.entries()){if("object"!=typeof t||null===t||Array.isArray(t))return;let n="string"==typeof t.file?t.file.trim():"",l=eC(t.openFiles);if(n.length>512||ey(n))continue;let r=null!=l?l:n.length>0?eC([n]):void 0;void 0!==r&&i.push({id:"string"==typeof t.id&&t.id.trim().length>0?t.id.trim().slice(0,32):`pane-${e+1}`,file:n.length>0?n.replace(/\\/gu,"/").replace(/^\/+/u,""):r[0],openFiles:r});}if(0===i.length)return;let a="column"===n.direction?"column":"row",o="number"==typeof n.splitRatio&&Number.isFinite(n.splitRatio)?Math.min(75,Math.max(25,Math.round(n.splitRatio))):50,s="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260,c="string"==typeof n.activePaneId&&i.some(e=>e.id===n.activePaneId)?n.activePaneId:i[0].id;return JSON.stringify({version:1,panes:i,activePaneId:c,direction:a,splitRatio:o,sidebarWidth:s,sidebarCollapsed:!0===n.sidebarCollapsed});}(n);if("pdfCitationPreview"===e)return"documentLabel"===t||"pageLabel"===t||"sourceLabel"===t?ex(n,240):"failureTitle"===t||"failureMessage"===t?ex(n,360):"currentPage"===t||"pageNumber"===t?Number.isInteger(n)&&"number"==typeof n&&n>0&&n<=1e5?n:void 0:"rotation"===t?"number"==typeof n&&Number.isFinite(n)?(90*Math.round(n/90)%360+360)%360:void 0:"zoomValue"===t?"number"==typeof n&&Number.isFinite(n)?Math.min(2,Math.max(.5,Math.round(10*n)/10)):void 0:"failureRetryable"===t?"boolean"==typeof n?n:void 0:"anchorQuality"===t?"page-only"===n||"approximate"===n||"unavailable"===n?n:void 0:"zoomMode"===t&&("fit-width"===n||"fit-page"===n||"manual"===n)?n:void 0;if("figma"===e||"figmaView"===e||"figmaJson"===e||"figmaImage"===e)return function(e,t){if("string"==typeof t){if("snapshotRunId"===e)return eb(t)?t:void 0;if("screenId"===e)return ek(t)?t:void 0;if("imageSrc"===e)return /^\/api\/figma\/snapshots\/[^/?#]+\/screens\/\d+\/image$/u.test(t)?t:void 0;if("selectedScreenIdsJson"===e){let e;try{e=JSON.parse(t);}catch{return;}if(!Array.isArray(e)||0===e.length||e.length>16)return;let n=[];for(let t of e){if("string"!=typeof t)return;let e=t.trim();if(!ek(e))return;n.push(e);}return JSON.stringify(n);}if("selectedScreenName"===e){if(t.length>256||ey(t))return;return t;}}}(t,n);if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||(l=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t;}(t),ef.some(e=>l.includes(e))))return;if("string"!=typeof n)return n;let r=ep.WIN_META[e].persistence;return"evidence-reference"===r?eb(n)?n:void 0:ey(n)?"durable.ui"===r?"[REDACTED]":void 0:n;}(e,n,l);void 0!==t&&(i[n]=t);}return i;}(n,e.cfg),max:e.max},r=function(e){if(ew(e)&&ev(e.x)&&ev(e.y)&&ev(e.w)&&ev(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h};}(e.prev);return{...l,...(!0===e.minimized?{minimized:!0}:{}),...(void 0!==r?{prev:r}:{}),...(ev(e.zoom)?{zoom:Math.max(.5,Math.min(2,e.zoom))}:{})};}(n);null!==e&&t.push("figma"!==e.type||void 0===function(e){let t=e.selectedScreenIdsJson;if("string"==typeof t)try{let e=JSON.parse(t);if(!Array.isArray(e))return;let n=e[0];return"string"==typeof n&&n.length>0?n:void 0;}catch{return;}}(e.cfg)?e:{...e,type:"figmaView",cfg:{...e.cfg}});}let n=new Map();for(let e of t){if(!0!==D.WIN_TYPES[e.type].singleton)continue;let t=n.get(e.type);(void 0===t||e.z>t.z)&&n.set(e.type,e);}return t.filter(e=>!0!==D.WIN_TYPES[e.type].singleton||n.get(e.type)===e);}function eS(e,t){let n=new Set(t.map(e=>e.id)),l=[];for(let t of e){if("string"!=typeof t.id||"string"!=typeof t.a||"string"!=typeof t.b||!n.has(t.a)||!n.has(t.b))continue;let e=!0===t.boundScopeElided||"string"==typeof t.boundRoot||"string"==typeof t.boundScopeKind||"string"==typeof t.boundRelativePath,r="string"==typeof t.boundChatWindowId&&t.boundChatWindowId.length>0&&n.has(t.boundChatWindowId),i=("capsule"===t.boundConnectorKind||"capsule-set"===t.boundConnectorKind)&&"string"==typeof t.boundConnectorId&&t.boundConnectorId.length>0;l.push({id:t.id,a:t.a,b:t.b,...(r?{boundChatWindowId:t.boundChatWindowId}:{}),...(e?{boundScopeElided:!0}:{}),...(i?{boundConnectorKind:t.boundConnectorKind,boundConnectorId:t.boundConnectorId}:{})});}return l;}var eN=e.i(68611);let eI="keiko.workspace.v4",eE="keiko.conns.v1",eR="keiko.view",eA="/api/workspace/state";function eP(){try{let e=window.localStorage.getItem(eR);if(null===e)return{zoom:1,x:0,y:0};let t=JSON.parse(e);if("object"==typeof t&&null!==t&&"zoom"in t&&"number"==typeof t.zoom)return{zoom:Number.isFinite(t.zoom)?eM(t.zoom):1,x:"number"==typeof t.x&&Number.isFinite(t.x)?t.x:0,y:"number"==typeof t.y&&Number.isFinite(t.y)?t.y:0};}catch{}return{zoom:1,x:0,y:0};}function eM(e){return Math.max(.3,Math.min(2.5,e));}function eT(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10));}function ez(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function eF(e){let t=null,n=null,l=()=>{null!==t&&(clearTimeout(t),t=null);let e=n;n=null,null!==e&&e();};return{schedule:r=>{n=r,null!==t&&clearTimeout(t),t=setTimeout(l,e);},flush:l,cancel:()=>{null!==t&&(clearTimeout(t),t=null),n=null;}};}function eL(e){let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:2===e.deltaMode?800:1;return{x:e.deltaX*t,y:e.deltaY*t};}function eW(e){return 1-Math.pow(1-e,3);}function e$(e,t,n){return{zoom:e.zoom+(t.zoom-e.zoom)*n,x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n};}function eD(){let e=null;try{e=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=ej(t);return n.length>0?n:null;}catch{return null;}}(window.localStorage.getItem(eI));}catch{e=null;}let t=null!=e?e:[];try{return{wins:t,conns:function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return eS(n,t);}catch{return[];}}(window.localStorage.getItem(eE),t)};}catch{return{wins:t,conns:[]};}}function eO(e){return`"workspace-state-${String(e)}"`;}async function eK(e){if("function"!=typeof fetch)return null;try{let t={Accept:"application/json"};t["If-None-Match"]=eO(e);let n=await fetch(eA,{headers:t});if(304===n.status||!n.ok)return null;let l=await n.json();if("object"!=typeof l||null===l||!("workspace"in l))return null;let r=l.workspace;if("object"!=typeof r||null===r||"number"!=typeof r.revision||!Array.isArray(r.windows)||!Array.isArray(r.connections))return null;return{revision:r.revision,windows:r.windows,connections:r.connections};}catch{return null;}}function eq(e){return"function"==typeof Blob?new Blob([e]).size:"function"==typeof TextEncoder?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length;}let eB=0;async function e_(e,t,n){var l,r;if("function"!=typeof fetch)return null;let i=JSON.stringify({windows:e,connections:t}),a=!0===n.keepalive;a&&eq(i)>61440&&(l=eq(i),eB+=1,"u">typeof console&&"function"==typeof console.warn&&console.warn(`workspace-state: keepalive body ${String(l)}B over budget; retrying without keepalive`),a=!1);try{let e=await fetch(eA,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json","If-Match":eO(n.baseRevision),"X-Keiko-CSRF":"1"},body:i,...(a?{keepalive:!0}:{}),...(void 0!==n.signal?{signal:n.signal}:{})});if(412===e.status||428===e.status){let t;return{kind:"conflict",revision:(r=e.headers.get("etag"),t=/^"workspace-state-(\d+)"$/u.exec(null!=r?r:""),null===t?null:Number.parseInt(t[1],10))};}if(!e.ok)return null;let t=await e.json(),l="object"==typeof t&&null!==t&&"workspace"in t?t.workspace:void 0;if("object"!=typeof l||null===l)return null;let o=l.revision;return"number"==typeof o?{kind:"ok",revision:o}:null;}catch{return null;}}function eG(e,t){let n=ej(e),l=eS(t,n);return{wins:n,conns:l,serialized:JSON.stringify({windows:n,connections:l})};}function eU(e,t,n,l){l.current=e.wins.reduce((e,t)=>Math.max(e,t.z),1),t(e.wins),n(e.conns);}function eJ(e){let t=ej(e.wins);return JSON.stringify({windows:t,connections:eS(e.conns,t)});}let eV={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"maxi",ArrowDown:null},eY={Equal:"=",NumpadAdd:"+",Minus:"-",NumpadSubtract:"-",Digit0:"0",Numpad0:"0"};function eX(e,t){if(null!==t){let n=e.find(e=>e.id===t);return void 0!==n&&!0!==n.minimized?n:null;}let n=null;for(let t=0;t<e.length;t++){let l=e[t];if(!0!==l.minimized){if(null===n){n=l;continue;}l.z>n.z&&(n=l);}}return n;}var eH=e.i(18004),eZ=e.i(98408),eQ=e.i(19047),e0=e.i(89860),e1=e.i(18138);let e2=(0,J.default)(()=>e.A(27555).then(e=>e.WorkspaceShader),{loadableGenerated:{modules:[47865]},ssr:!1,loading:()=>null}),e4={w:260,h:220},e3={w:360,h:360},e5={w:520,h:540},e6={w:560,h:420};function e8(e){let{clientX:t,clientY:n,rect:l,view:r,size:i=e4}=e;return{x:Math.round((t-l.left-r.x)/r.zoom-i.w/2),y:Math.round((n-l.top-r.y)/r.zoom-28)};}function e7(e,t){let n=e+t;return e<1&&n>1||e>1&&n<1?1:n;}function e9(e,t,n){var l;t.preventDefault();let r=t.currentTarget;null==(l=r.setPointerCapture)||l.call(r,t.pointerId);let i=t.clientX,a=t.clientY,o=(0,X.acquireGrabbingBodyStyle)();n(!0);let s=t=>{e(t.clientX-i,t.clientY-a),i=t.clientX,a=t.clientY;},c=()=>{var e,l;window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",c),window.removeEventListener("pointercancel",c),n(!1),(null==(e=r.hasPointerCapture)?void 0:e.call(r,t.pointerId))===!0&&(null==(l=r.releasePointerCapture)||l.call(r,t.pointerId)),o();};window.addEventListener("pointermove",s),window.addEventListener("pointerup",c),window.addEventListener("pointercancel",c);}function te(e){let{wins:t,connecting:n,conns:i}=e,[a,o]=(0,r.useState)(""),s=(0,r.useRef)(null),c=(0,r.useRef)(i.length);return(0,r.useEffect)(()=>{let e=s.current;s.current=n;let l=c.current;if(c.current=i.length,null===e&&null!==n){let e=null==t?void 0:t.find(e=>e.id===n.from),l=void 0!==e?D.WIN_TYPES[e.type].title:"window";o(`Connecting from ${l}. Tab to a highlighted window and press Enter on it or one of its connection ports to connect. Press Escape to cancel.`);return;}if(null!==e&&null===n)if(i.length>l){let e=i[i.length-1],n=void 0!==e?null==t?void 0:t.find(t=>t.id===e.a):void 0,l=void 0!==e?null==t?void 0:t.find(t=>t.id===e.b):void 0;o(void 0!==n&&void 0!==l?`Connected: ${(0,O.relLabel)(n,l)}`:"Connected");}else o("Connection cancelled");},[n,i,t]),(0,l.jsx)("div",{className:"sr-only","aria-live":"polite",children:a});}let tt=[];function tn(e){var t,n;let{ws:i,wsRef:a,openPalette:o,palette:s,children:c}=e,{wins:d,view:u,snapPrev:p,conns:f,connecting:m,api:h}=i,g=(0,r.useRef)(u);g.current=u;let[v,w]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),k=(0,r.useRef)(!1),x=function(e){let[t,n]=(0,r.useState)(!1),l=(0,r.useRef)(e),i=(0,r.useRef)(null);return(0,r.useEffect)(()=>{e!==l.current&&(l.current=e,n(!0),null!==i.current&&clearTimeout(i.current),i.current=setTimeout(()=>n(!1),160));},[e]),(0,r.useEffect)(()=>()=>{null!==i.current&&clearTimeout(i.current);},[]),t;}(u.zoom),C=(0,r.useMemo)(()=>null===d?null:d.filter(e=>!0!==e.minimized),[d]),j=function(e,t){let n=(0,r.useRef)(0),l=(0,r.useRef)(null),{keys:i,cfgs:a}=(0,r.useMemo)(()=>null===e?{keys:"",cfgs:tt}:{keys:e.map(e=>`${e.id}:${e.type}`).join("|"),cfgs:e.map(e=>e.cfg)},[e]),o=l.current;return(null===o||o.conns!==t||o.keys!==i||o.cfgs.length!==a.length||a.some((e,t)=>e!==o.cfgs[t]))&&(n.current+=1,l.current={conns:t,keys:i,cfgs:a}),n.current;}(d,f),S=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(C),N=null!==m&&null!==C&&null!=(t=C.find(e=>e.id===m.from))?t:null,E=(0,r.useMemo)(()=>{let e=new Map();if(null===N||null===C)return e;for(let t of C)e.set(t.id,t.id===N.id?"source":(0,O.canConnect)(N.type,t.type)?"valid":"invalid");return e;},[N,C]);(0,r.useEffect)(()=>{let e=e=>{k.current=e,b(e);},t=t=>{!("Space"!==t.code||(0,X.isHandToolKeyIgnoredTarget)(t.target))&&(t.preventDefault(),k.current||e(!0));},n=t=>{"Space"===t.code&&e(!1);},l=()=>{e(!1);};return window.addEventListener("keydown",t),window.addEventListener("keyup",n),window.addEventListener("blur",l),()=>{window.removeEventListener("keydown",t),window.removeEventListener("keyup",n),window.removeEventListener("blur",l);};},[]);let R=(0,r.useMemo)(()=>({backgroundSize:`${String(22*u.zoom)}px ${String(22*u.zoom)}px`,backgroundPosition:`${String(u.x)}px ${String(u.y)}px`}),[u]),A=(0,r.useMemo)(()=>x?{transform:`translate(${String(u.x)}px, ${String(u.y)}px) scale(${String(u.zoom)})`,transformOrigin:"0 0"}:{transform:`translate(${String(u.x/u.zoom)}px, ${String(u.y/u.zoom)}px)`,transformOrigin:"0 0",zoom:u.zoom},[u,x]),P=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("connector",{presentation:"node",selectedKind:e.kind,selectedId:e.id,...(void 0!==e.label?{selectedLabel:e.label}:{}),...(void 0!==e.lifecycleState?{selectedState:e.lifecycleState}:{})});null!==r&&h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current}),...e4});},[h]),M=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaView",{snapshotRunId:e.snapshotRunId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});null!==r&&h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e3}),...e3});},[h]),T=(0,r.useCallback)(e=>{if(null===d)return[];let t=new Map(d.map(e=>[e.id,e])),n=[];for(let l of f){let r=l.a===e?l.b:l.b===e?l.a:null;if(null===r)continue;let i=t.get(r);(null==i?void 0:i.type)==="quality"&&n.push({connId:l.id,qualityId:i.id});}return n;},[f,d]),z=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaJson",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});if(null===r||(h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e5}),...e5}),void 0===e.sourceWindowId))return;let i=T(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(r,e.qualityId);},0);}},[h,T]),F=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaImage",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenName:e.name,imageSrc:e.imageSrc});if(null===r||(h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e6}),...e6}),void 0===e.sourceWindowId))return;let i=T(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(r,e.qualityId);},0);}},[h,T]);(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;if("number"!=typeof e.clientX||"number"!=typeof e.clientY||"object"!=typeof t||null===t)return!1;let n=t.kind;return("capsule"===n||"capsule-set"===n)&&"string"==typeof t.id;}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||P(i,l,r,n);};return window.addEventListener(eH.LOCAL_KNOWLEDGE_CONNECTOR_DROP_EVENT,e),()=>{window.removeEventListener(eH.LOCAL_KNOWLEDGE_CONNECTOR_DROP_EVENT,e);};},[P,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name;}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||M(i,l,r,n);};return window.addEventListener(eZ.FIGMA_VIEW_DROP_EVENT,e),()=>{window.removeEventListener(eZ.FIGMA_VIEW_DROP_EVENT,e);};},[M,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||z(i,l,r,n);};return window.addEventListener(eQ.FIGMA_JSON_DROP_EVENT,e),()=>{window.removeEventListener(eQ.FIGMA_JSON_DROP_EVENT,e);};},[z,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&"string"==typeof t.imageSrc&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||F(i,l,r,n);};return window.addEventListener(e0.FIGMA_IMAGE_DROP_EVENT,e),()=>{window.removeEventListener(e0.FIGMA_IMAGE_DROP_EVENT,e);};},[F,a]);let L=(0,r.useMemo)(()=>null===d?"":d.map(e=>`${e.id}:${e.type}:${!0===e.minimized?"1":"0"}:${"string"==typeof e.cfg.chatId?e.cfg.chatId:""}`).join("|"),[d]);(0,r.useEffect)(()=>{(0,e1.syncPdfCitationPreviewWindowRegistry)(d);},[L]);let W=null!==d&&0===d.length,$=null!=(n=null==d?void 0:d.some(e=>e.max))&&n;return(0,l.jsxs)("main",{className:"workspace",ref:a,"aria-label":"Workspace surface",tabIndex:0,"data-window-maxed":$?"true":void 0,"data-canvas-overlays-hidden":$?"true":"false","data-connecting":null!==m?"true":void 0,"data-panning":v?"true":void 0,"data-hand-tool":y?"true":void 0,onPointerDownCapture:e=>{if((0,X.workspaceInteractionLocked)())return;if(k.current&&(0,X.isPrimaryActivationPointer)(e)&&null===m&&!(0,X.isTextEntryTarget)(e.target)&&!(0,X.isInteractiveSurfaceTarget)(e.target)){e9(h.panBy,e,w),e.stopPropagation();return;}if(0!==e.button||null===m||null===N||null===C)return;let t=function(e){if(!(e instanceof Element))return;let t=e.closest(".window[data-window-id]");return null==t?void 0:t.dataset.windowId;}(e.target);if(void 0===t||t===N.id)return;let n=C.find(e=>e.id===t);void 0!==n&&(0,O.canConnect)(N.type,n.type)&&h.confirmConnect(n.id,e);},onPointerDown:e=>{if(!((0,X.workspaceInteractionLocked)()||(0,X.isInteractiveSurfaceTarget)(e.target))){if(null!==m){(0,X.isPrimaryActivationPointer)(e)&&h.cancelConnect();return;}(0,X.isCanvasPanPointer)(e)&&e9(h.panBy,e,w);}},onKeyDown:e=>{if(e.target!==e.currentTarget)return;let t=e.shiftKey?192:48;switch(e.key){case"ArrowLeft":h.panBy(t,0);break;case"ArrowRight":h.panBy(-t,0);break;case"ArrowUp":h.panBy(0,t);break;case"ArrowDown":h.panBy(0,-t);break;default:return;}e.preventDefault();},onDragOver:e=>{(null!==(0,eH.parseLocalKnowledgeConnectorDrag)(e.dataTransfer)||null!==(0,eZ.parseFigmaViewDrag)(e.dataTransfer)||null!==(0,eQ.parseFigmaJsonDrag)(e.dataTransfer)||null!==(0,e0.parseFigmaImageDrag)(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy");},onDrop:e=>{let t=(0,eH.parseLocalKnowledgeConnectorDrag)(e.dataTransfer),n=(0,eZ.parseFigmaViewDrag)(e.dataTransfer),l=(0,eQ.parseFigmaJsonDrag)(e.dataTransfer),r=(0,e0.parseFigmaImageDrag)(e.dataTransfer);if(null===t&&null===n&&null===l&&null===r)return;e.preventDefault(),e.stopPropagation();let i=e.currentTarget.getBoundingClientRect();null!==t?P(t,e.clientX,e.clientY,i):null!==n?M(n,e.clientX,e.clientY,i):null!==l?z(l,e.clientX,e.clientY,i):null!==r&&F(r,e.clientX,e.clientY,i);},children:[(0,l.jsx)(e2,{}),(0,l.jsx)("div",{className:"ws-grid",style:R,"aria-hidden":"true"}),(0,l.jsx)(te,{wins:C,connecting:m,conns:f}),null!==m?(0,l.jsx)("div",{className:"ws-connect-hint","aria-hidden":"true",children:"Click a highlighted window to connect — Esc to cancel"}):null,W?(0,l.jsx)("div",{className:"ws-empty",children:(0,l.jsx)(Y,{onNewWindow:o})}):null,(0,l.jsxs)("div",{className:"ws-scene",style:A,children:[null!==p?(0,l.jsx)("div",{className:"snap-ghost",style:{left:p.x,top:p.y,width:p.w,height:p.h}}):null,null!==C?(0,l.jsx)(et,{wins:C,conns:f,connecting:m,api:h}):null,null!==C?C.map(e=>{var t;return(0,l.jsx)(ec,{win:e,top:null!==S&&e.id===S.id,connState:null!=(t=E.get(e.id))?t:null,api:h,wsRef:a,linkRevision:j},e.id);}):null]}),(0,l.jsxs)("div",{className:"ws-zoom",children:[(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:()=>h.zoomTo(e7(u.zoom,-.2)),disabled:u.zoom<=.3,"aria-label":"Zoom out","data-tip":"Zoom out",children:(0,l.jsx)(I.Icons.zoomOut,{size:15})}),(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:h.fitView,disabled:null===C||0===C.length,"aria-label":"Fit workspace to windows","data-tip":"Fit workspace to windows",children:(0,l.jsx)(I.Icons.expand,{size:15})}),(0,l.jsxs)("button",{type:"button",className:"ws-zoom-pct mono ui-tip",onClick:h.resetView,"aria-label":`${String(Math.round(100*u.zoom))}% — reset`,"data-tip":"Reset",children:[Math.round(100*u.zoom),"%"]}),(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-end",onClick:()=>h.zoomTo(e7(u.zoom,.2)),disabled:u.zoom>=2.5,"aria-label":"Zoom in","data-tip":"Zoom in",children:(0,l.jsx)(I.Icons.zoomIn,{size:15})})]}),(0,l.jsx)("button",{type:"button",className:"ws-fab ui-tip cmp-tip-end",onPointerDown:e=>e.stopPropagation(),onClick:o,"aria-label":"New window","data-tip":"New window",children:(0,l.jsx)(I.Icons.add,{size:20})}),$?null:null!=s?s:null,c]});}var tl=e.i(31578);function tr(e){let{commands:t,onClose:n}=e,[i,a]=(0,r.useState)(""),[o,s]=(0,r.useState)(0),c=(0,r.useRef)(null),d=(0,r.useRef)(null),u=(0,r.useRef)(null);(0,r.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t);}),[]),(0,r.useEffect)(()=>{var e;null==(e=c.current)||e.focus();},[]);let p=(0,r.useMemo)(()=>{let e=i.toLowerCase();return t.filter(t=>{var n;return`${t.label} ${null!=(n=t.group)?n:""}`.toLowerCase().includes(e);});},[t,i]);(0,r.useEffect)(()=>{s(0);},[i]),(0,r.useEffect)(()=>{var e,t;null==(t=document.getElementById(`cmdk-row-${String(o)}`))||null==(e=t.scrollIntoView)||e.call(t,{block:"nearest"});},[o,p]);let f=e=>{void 0!==e&&(e.run(),n());};return(0,l.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,l.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,l;let n=Array.from(null!=(t=null==(l=u.current)?void 0:l.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?t:[]);if(n.length>0){let t=n[0],l=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),l.focus();return;}if(!e.shiftKey&&document.activeElement===l){e.preventDefault(),t.focus();return;}}}if("ArrowDown"===e.key){e.preventDefault(),s(e=>Math.min(p.length-1,e+1));return;}if("ArrowUp"===e.key){e.preventDefault(),s(e=>Math.max(0,e-1));return;}if("Enter"===e.key){e.preventDefault(),f(p[o]);return;}"Escape"===e.key&&n();},children:[(0,l.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,l.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,l.jsxs)("div",{className:"cmdk-input",children:[(0,l.jsx)(I.Icons.search,{size:16}),(0,l.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":p.length>0?`cmdk-row-${String(o)}`:void 0,"aria-label":"Command query",placeholder:"Type a command…",value:i,onChange:e=>a(e.target.value)}),(0,l.jsx)("span",{className:"kbd",children:"esc"})]}),(0,l.jsx)("div",{className:"sr-only",role:"status",children:0===p.length?"No matching commands":`${String(p.length)} command${1===p.length?"":"s"}`}),(0,l.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===p.length&&(0,l.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),p.map((e,t)=>{var n,r;let i;return(0,l.jsxs)("div",{role:"option",id:`cmdk-row-${String(t)}`,"aria-selected":t===o,className:"cmdk-row","data-sel":t===o,tabIndex:-1,onMouseEnter:()=>s(t),onClick:()=>f(e),children:[(0,l.jsx)("span",{className:"cmdk-ico",children:(n=e.icon,i=null!=(r=I.Icons[n])?r:I.Icons.spark,(0,l.jsx)(i,{size:16}))}),(0,l.jsx)("span",{className:"cmdk-label",children:e.label}),(0,l.jsx)("span",{className:"spacer"}),void 0!==e.shortcut&&(0,l.jsx)("span",{className:"kbd",children:e.shortcut}),void 0!==e.group&&(0,l.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id);})]})]})});}var ti=e.i(70307),ta=e.i(67914);let to=[["ask","Ask every action"],["full","Full access"]];function ts(e){let{cfg:t,set:n}=e,r=!1!==t.keikoMode,i="full"===t.access?"full":"ask",a=r?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===i?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,l.jsxs)("div",{className:"permctl",children:[(0,l.jsxs)("button",{type:"button",className:"perm-toggle","data-on":r,role:"switch","aria-checked":r,onClick:()=>n("keikoMode",!r),children:[(0,l.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,l.jsxs)("span",{className:"perm-tt",children:[(0,l.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,l.jsx)("span",{className:"perm-desc",children:"Zero standing rights · Keiko governs"})]}),(0,l.jsx)("span",{className:"perm-sw"+(r?" on":""),children:(0,l.jsx)("span",{})})]}),!r&&(0,l.jsx)("div",{className:"perm-legacy",role:"radiogroup","aria-label":"Legacy access mode",children:to.map(e=>{let[t,r]=e;return(0,l.jsx)("button",{type:"button",className:"perm-opt","data-on":i===t,role:"radio","aria-checked":i===t,onClick:()=>n("access",t),children:r},t);})}),(0,l.jsx)("div",{className:"perm-note",children:a})]});}function tc(e){if(e instanceof W.ApiError){if("BAD_ROOT"===e.code)return"Enter an absolute folder path.";if("DENIED"===e.code)return"That location is excluded.";}return e instanceof Error?e.message:"Unable to read directories.";}function td(e){let{value:t,projectId:n,selectProjectRoot:i=!1,onSelect:a,onClose:o}=e,[s,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(t),[p,f]=(0,r.useState)(!1),[m,h]=(0,r.useState)(null),g=null!=n?n:t.trim(),v=(0,r.useCallback)(async e=>{if(0===g.length){c(null),h("Enter an absolute folder path.");return;}f(!0),h(null);try{let t=await(0,W.fetchFilesDirectories)(g,e);c(t),u(t.path);}catch(e){h(tc(e));}finally{f(!1);}},[g]);return(0,r.useEffect)(()=>{v(t.length>0?t:void 0);},[]),(0,l.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,l.jsxs)("div",{className:"dir-top",children:[(0,l.jsx)("input",{className:"dlg-input mono dir-path",value:d,"aria-label":"Folder path",placeholder:"/absolute/folder/path",onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),v(d));}}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==s?(0,l.jsx)("div",{className:"dir-roots",children:s.roots.map(e=>(0,l.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},`${e.label}:${e.path}`))}):null,(0,l.jsxs)("div",{className:"dir-list",children:[(null==s?void 0:s.parent)!==null&&(null==s?void 0:s.parent)!==void 0?(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=s.parent)?e:void 0);},children:[(0,l.jsx)(I.Icons.back,{size:14}),(0,l.jsx)("span",{children:"Parent directory"})]}):null,null==s?void 0:s.entries.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,l.jsx)(I.Icons.folder,{size:14}),(0,l.jsx)("span",{children:e.name})]},e.path)),p?(0,l.jsx)("div",{className:"dir-note",role:"status",children:"Loading directories…"}):null,p||null===s||0!==s.entries.length?null:(0,l.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==m?(0,l.jsx)("div",{className:"dir-error",role:"alert",children:m}):null]}),(0,l.jsxs)("div",{className:"dir-actions",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:o,children:"Close"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==s){var e,t;a(i&&null!=(e=null==(t=s.roots[0])?void 0:t.path)?e:s.path),o();}},disabled:null===s,children:"Use directory"})]})]});}let tu=[{id:"unit-test-generation",label:"Unit Test Agent",scope:"Source file"},{id:"bug-investigation",label:"Bugfix Agent",scope:"Bug report"}];function tp(e){return e.filter(e=>e.available).map(e=>e.path);}function tf(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0);}function tm(e){let t=tg(e.trim()).replace(/\/+$/u,""),n=t.lastIndexOf("/");return n>0?t.slice(0,n):"";}let th=function(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput;};function tg(e){return e.replaceAll("\\","/");}function tv(e,t){let n=tg(t.trim());if(0===n.length)return"";let l=tg(e.trim()).replace(/\/+$/u,"");if(0===l.length)return n;if(n===l)return".";let r=`${l}/`;return n.startsWith(r)?n.slice(r.length):n;}function tw(e){let{root:t,value:n,onSelect:i,onClose:a}=e,o=tv(t,n),[s,c]=(0,r.useState)(tm(o)),[d,u]=(0,r.useState)(o),[p,f]=(0,r.useState)([]),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),[w,y]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(0===t.trim().length){f([]),h(!1),v(!1),y("Select a repository first.");return;}let e=!1;return v(!0),y(null),(0,W.fetchFilesTree)(t.trim(),s).then(t=>{e||(f(t.entries),h(t.truncated));}).catch(t=>{e||(f([]),h(!1),y(tc(t)));}).finally(()=>{e||v(!1);}),()=>{e=!0;};},[s,t]);let b=p.filter(e=>"directory"===e.kind),k=p.filter(e=>"directory"!==e.kind);return(0,l.jsxs)("div",{className:"file-picker",role:"group","aria-label":"File picker",children:[(0,l.jsx)("div",{className:"file-picker-head",children:(0,l.jsx)("span",{className:"file-picker-path mono",children:0===s.length?"Repository root":s})}),(0,l.jsxs)("div",{className:"dir-list file-picker-list",children:[s.length>0?(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>c(tm(s)),children:[(0,l.jsx)(I.Icons.back,{size:14}),(0,l.jsx)("span",{children:"Parent folder"})]}):null,b.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row file-picker-row",disabled:!e.readable,onClick:()=>c(e.path),title:e.path,children:[(0,l.jsx)(I.Icons.folder,{size:14}),(0,l.jsx)("span",{children:e.name})]},e.path)),k.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row file-picker-row","data-selected":d===e.path?"true":void 0,disabled:!e.readable,"aria-pressed":d===e.path,onClick:()=>u(e.path),title:e.path,children:[(0,l.jsx)(I.Icons.file,{size:14}),(0,l.jsx)("span",{children:e.name}),(0,l.jsx)("span",{className:"file-picker-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l+=1;let r=0===l?n.toFixed(0):n.toFixed(n>=10?1:2);return`${r} ${t[l]}`;}(e.sizeBytes)})]},e.path)),g?(0,l.jsx)("div",{className:"dir-note",role:"status",children:"Loading files…"}):null,g||null!==w||0!==p.length?null:(0,l.jsx)("div",{className:"dir-note",children:"No files in this folder."}),m?(0,l.jsxs)("div",{className:"dir-note file-picker-warning",role:"status",children:["Showing only the first ",p.length.toString()," entries."]}):null,null!==w?(0,l.jsx)("div",{className:"dir-error",role:"alert",children:w}):null]}),(0,l.jsxs)("div",{className:"dir-actions",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:a,children:"Close"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{0!==d.trim().length&&(i(tv(t,d)),a());},disabled:0===d.trim().length,children:"Use file"})]})]});}function ty(e){var t,n,i,a;let{filesContext:o,directoryField:s,setDirectoryField:c,setDialogError:d,onConfirm:u,onClose:p}=e,[f,m]=(0,r.useState)("unit-test-generation"),[h,g]=(0,r.useState)(null!=(t=null==o?void 0:o.root)?t:""),[v,w]=(0,r.useState)(""),[y,b]=(0,r.useState)([]),[k,x]=(0,r.useState)([]),[C,j]=(0,r.useState)(()=>{var e,t,n,l;let r;return n=null!=(e=null==o?void 0:o.root)?e:"",{verifyTargetFiles:r=null===(l=null!=(t=null==o?void 0:o.activeFilePath)?t:null)?"":tv(n,l),explainFilePath:r,explainQuestion:"",unitFilePath:r,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:r};}),[S,N]=(0,r.useState)(!0),[E,R]=(0,r.useState)(!1),[A,P]=(0,r.useState)(!1),M=h.trim(),T=null!==o&&o.root===M&&void 0!==o.activeFilePath?o.activeFilePath:null,z=M.length>0&&k.includes(M),F=0===M.length?"Repository is required.":0===v.length?"No compatible model is available.":"explain-plan"===f&&0===C.explainFilePath.trim().length?"Explain plan requires a file path.":"unit-test-generation"===f&&0===C.unitFilePath.trim().length?"Unit Test Agent requires a source file.":"bug-investigation"===f&&0===C.bugDescription.trim().length?"Bugfix Agent requires an observed behavior.":null,L=null===F&&z&&!A&&!S,$=null!=(n=tu.find(e=>e.id===f))?n:tu[0],D="unit-test-generation"===f?"Start Unit Test Agent":"Start Bugfix Agent",O=null!=(i=k[0])?i:"",K=M.length>0?M:null!=(a=null==o?void 0:o.root)?a:O,q=K.length>0,B="agent-repository-browse-help",_="agent-source-file-browse-help";(0,r.useEffect)(()=>{let e=!1;return N(!0),d(null),Promise.all([(0,W.fetchModels)(),(0,W.fetchProjects)()]).then(t=>{let[n,l]=t;if(e)return;let r=n.models.filter(th);b(r),w(e=>{var t,n;return e||(null!=(t=null==(n=r[0])?void 0:n.id)?t:"");}),x(tp(l.projects));}).catch(t=>{e||d(tc(t));}).finally(()=>{e||N(!1);}),()=>{e=!0;};},[d]);let G=e=>{j(t=>({...t,...e}));};(0,r.useEffect)(()=>{if(null===T)return;let e=tv(M,T);j(t=>{let n={};return 0===t.verifyTargetFiles.trim().length&&(n.verifyTargetFiles=e),0===t.explainFilePath.trim().length&&(n.explainFilePath=e),0===t.unitFilePath.trim().length&&(n.unitFilePath=e),0===t.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n};});},[T,M]);let U=async()=>{x(tp((await(0,W.fetchProjects)()).projects));},J=async()=>{if(0!==M.length){R(!0),d(null);try{await(0,W.createProject)({path:M}),await U();}catch(e){d(tc(e));}finally{R(!1);}}},V=async()=>{if(!L)return void d(null!=F?F:"Repository is not registered.");P(!0),d(null);let e=function(e,t,n,l){if("verify"===e){let e=tf(l.verifyTargetFiles).map(e=>tv(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...(e.length>0?{targetFiles:e}:{})}};}return"explain-plan"===e?{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:tv(t,l.explainFilePath),...(l.explainQuestion.trim().length>0?{question:l.explainQuestion.trim()}:{})}}:"unit-test-generation"===e?{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:{kind:"file",filePath:tv(t,l.unitFilePath)}}}:{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...(l.bugDescription.trim().length>0?{description:l.bugDescription.trim()}:{}),...(l.bugFailingOutput.trim().length>0?{failingOutput:l.bugFailingOutput.trim()}:{}),...(l.bugStackTrace.trim().length>0?{stackTrace:l.bugStackTrace.trim()}:{}),...(tf(l.bugTargetFiles).length>0?{targetFiles:tf(l.bugTargetFiles).map(e=>tv(t,e))}:{})}}};}(f,M,v,C);try{let t=await(0,W.startRun)(e);u({workflow:f,model:v,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:M,inputJson:JSON.stringify(e.input),...(null!==o&&o.root===M?{__connectFilesId:o.id}:{})});}catch(e){e instanceof W.ApiError&&"WORKSPACE_NOT_REGISTERED"===e.code?(await U().catch(()=>void 0),d("Repository is not registered.")):d(tc(e));}finally{P(!1);}};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"dlg-agent-grid",children:[(0,l.jsxs)("div",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Agent"}),(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input",value:f,ariaLabel:"Agent",autoFocus:!0,menuTitle:"Agent",menuCountLabel:`${tu.length.toString()} agents`,sections:[{options:tu.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{let t=tu.find(t=>t.id===e);void 0!==t&&m(t.id);}})})]}),(0,l.jsxs)("div",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Model"}),(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input mono",value:v,ariaLabel:"Model",disabled:0===y.length,menuTitle:"Model",mono:!0,sections:[{options:y.map(e=>({value:e.id,label:e.id}))}],onValueChange:w})})]})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Repository"}),(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{className:"dlg-input mono",value:h,placeholder:"/absolute/repository/path",onChange:e=>g(e.target.value)}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",disabled:!q,"aria-describedby":q?void 0:B,onClick:()=>{q&&(0===M.length&&g(K),c("agentWorkspace"));},children:"Browse"})]}),q?null:(0,l.jsx)("span",{id:B,className:"dlg-note",children:"Enter an absolute repository path to enable Browse."}),"agentWorkspace"===s?(0,l.jsx)(td,{value:K,projectId:k.includes(K)?K:void 0,onSelect:g,onClose:()=>c(null)}):null]}),M.length>0&&!z?(0,l.jsxs)("div",{className:"dlg-agent-warning",children:[(0,l.jsx)("span",{children:"Repository is not registered."}),(0,l.jsx)("button",{type:"button",className:"dlg-btn",disabled:E,onClick:()=>void J(),children:E?"Registering…":"Register repository"})]}):null,null!==T?(0,l.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===T)return;let e=tv(M,T);"unit-test-generation"===f?G({unitFilePath:e}):G({bugTargetFiles:e});},title:T,children:[(0,l.jsx)(I.Icons.files,{size:13})," Use current file ",(0,l.jsx)("span",{className:"mono",children:T})]}):null,(0,l.jsxs)("div",{className:"dlg-agent-task",children:[(0,l.jsxs)("div",{className:"dlg-agent-task-head",children:[(0,l.jsx)("span",{className:"dlg-agent-task-title",children:$.label}),(0,l.jsx)("span",{className:"dlg-agent-task-scope",children:$.scope})]}),"unit-test-generation"===f?(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Source file"}),(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:C.unitFilePath,onChange:e=>G({unitFilePath:e.target.value}),onBlur:e=>G({unitFilePath:tv(M,e.target.value)})}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn","aria-label":"Browse source file",disabled:!z,"aria-describedby":z?void 0:_,onClick:()=>{z&&c("unitSourceFile");},children:"Browse"})]}),z?null:(0,l.jsx)("span",{id:_,className:"dlg-note",children:"Select a registered repository before browsing source files."}),"unitSourceFile"===s?(0,l.jsx)(tw,{root:M,value:C.unitFilePath,onSelect:e=>G({unitFilePath:e}),onClose:()=>c(null)}):null]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Observed behavior"}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:C.bugDescription,onChange:e=>G({bugDescription:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:C.bugFailingOutput,onChange:e=>G({bugFailingOutput:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:C.bugStackTrace,onChange:e=>G({bugStackTrace:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Related files ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:C.bugTargetFiles,onChange:e=>G({bugTargetFiles:e.target.value}),onBlur:e=>G({bugTargetFiles:tf(e.target.value).map(e=>tv(M,e)).join(", ")})})]})]})]}),(0,l.jsxs)("div",{className:"dlg-agent-actions",children:[S?(0,l.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:"Loading models and projects…"}):null,S||null===F?null:(0,l.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:F}),(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:p,children:"Cancel"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!L,"aria-busy":A,"aria-describedby":L||A?void 0:"agent-start-validation",onClick:()=>void V(),children:A?"Starting…":D})]})]});}function tb(e){var t;let{type:n,types:i,filesContext:a=null,onConfirm:o,onClose:s}=e,c=(0,$.useTranslate)(),d=i[n],u=(0,r.useMemo)(()=>{var e,t;return t=null!=(e=d.config)?e:[],"chat"!==n?t:t.map(e=>"title"===e.key?{...e,label:c("newWindow.chat.fieldTitle"),def:c("newWindow.chat.defaultTitle"),placeholder:c("newWindow.chat.placeholder")}:e);},[c,d.config,n]),[p,f]=(0,r.useState)(()=>function(e){let t={};for(let l of e){var n;t[l.key]=null!=(n=l.def)?n:"";}return t;}(u)),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),[w,y]=(0,r.useState)(null),b=(0,r.useRef)(null),k=(0,r.useRef)(null),x=(0,r.useRef)(null),C="chat"===n?c("newWindow.chat.title"):`New ${d.title} window`,j="chat"===n?c("newWindow.chat.description"):d.desc,S="chat"===n?c("newWindow.chat.open"):null!=(t=d.cta)?t:`Open ${d.title}`;(0,r.useEffect)(()=>(x.current=document.activeElement,()=>{let e=x.current;null!==e&&e.isConnected?e.focus():requestAnimationFrame(()=>{var e,t;(null!=(e=null!=(t=document.querySelector('.window[data-top="true"]'))?t:document.querySelector(".ws-fab"))?e:document.body).focus({preventScroll:!0});});}),[]),(0,r.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e,t;h(!0),null==(t=null!=(e=b.current)?e:k.current)||t.focus();});return()=>cancelAnimationFrame(e);},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s();};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[s]),(0,r.useEffect)(()=>{if("files"!==n&&"editor"!==n)return;let e=!1,t=p.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,W.fetchProjects)().then(t=>{let n=tp(t.projects)[0];e||void 0===n||f(e=>({...e,root:n}));}).catch(t=>{e||v(tc(t));}),()=>{e=!0;};},[p.root,n]);let N=(e,t)=>f(n=>({...n,[e]:t})),E=()=>{"agents"!==n&&o(p);},R=I.Icons[d.icon];return(0,l.jsx)("div",{className:"dlg-overlay"+(m?" in":""),onPointerDown:s,children:(0,l.jsxs)("div",{ref:k,className:"agents"===n?"dlg dlg-agents":"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{let t,n;if("Escape"===e.key)return void s();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void E();if("Enter"===e.key){let t=e.target instanceof HTMLElement?e.target.tagName:"";("INPUT"===t||"SELECT"===t)&&(e.preventDefault(),E());return;}if("Tab"!==e.key)return;let l=(t=e.currentTarget.querySelectorAll("button,input,select,textarea"),n=[],t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e);}),n);if(0===l.length)return;let r=l[0],i=l[l.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),r.focus());},children:[(0,l.jsxs)("div",{className:"dlg-head",children:[(0,l.jsx)("span",{className:"dlg-ico",children:(0,l.jsx)(R,{size:20})}),(0,l.jsxs)("div",{className:"dlg-htext",children:[(0,l.jsx)("span",{id:"new-window-title",className:"dlg-title",children:C}),(0,l.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:j})]}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsx)("button",{type:"button",className:"palette-x",onClick:s,"aria-label":c("common.cancel"),title:c("common.cancel"),children:(0,l.jsx)(I.Icons.close,{size:16})})]}),(0,l.jsxs)("div",{className:"dlg-body",children:["agents"===n?(0,l.jsx)(ty,{filesContext:a,directoryField:w,setDirectoryField:y,setDialogError:v,onConfirm:o,onClose:s}):0===u.length&&(0,l.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==n&&u.map((e,t)=>(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,l.jsx)("span",{className:"dlg-opt",children:c("common.optional")})]}),function(e,t,n,r,i){var a,o,s,c;if("perm"===e.type)return(0,l.jsx)(ts,{cfg:t,set:n});let d=t[e.key],u="string"==typeof d?d:void 0===d?"":String(d);if("select"===e.type){let t=null!=(o=e.options)?o:[];return(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input mono",value:u,disabled:0===t.length,autoFocus:null!==r,menuTitle:e.label,mono:!0,sections:[{options:t.map(t=>{var n;return{value:t,label:`${null!=(n=e.prefix)?n:""}${t}`};})}],onValueChange:t=>n(e.key,t)})});}return"textarea"===e.type?(0,l.jsx)("textarea",{ref:null!=r?r:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(s=e.placeholder)?s:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{ref:null!=r?r:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onClick:()=>i(e.key),onChange:t=>n(e.key,t.target.value)}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>i(e.key),children:"Browse"})]}):(0,l.jsx)("input",{ref:null!=r?r:void 0,className:"dlg-input mono",placeholder:null!=(a=e.placeholder)?a:e.label,value:u,onChange:t=>n(e.key,t.target.value)});}(e,p,N,0===t?e=>{b.current=e;}:null,y),"directory"===e.type&&w===e.key?(0,l.jsx)(td,{value:"string"==typeof p[e.key]?p[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>N(e.key,t),onClose:()=>y(null)}):null]},e.key)),null!==g?(0,l.jsx)("div",{className:"dlg-error",role:"alert",children:g}):null]}),"agents"!==n?(0,l.jsxs)("div",{className:"dlg-foot",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:s,children:c("common.cancel")}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:E,children:S})]}):null]})});}function tk(e){let{types:t,order:n,onAdd:i,onClose:a}=e,o=n.length<=4?2:3,s=(0,r.useRef)(null),c=(0,r.useRef)(null),[d,u]=(0,r.useState)(0);return(0,r.useEffect)(()=>{var e;c.current=document.activeElement;let t=null==(e=s.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;let n=document.activeElement;(null===n||n===document.body)&&(null==(t=c.current)||null==(e=t.focus)||e.call(t));};},[]),(0,r.useEffect)(()=>{let e=e=>{null!==s.current&&e.target instanceof Node&&!s.current.contains(e.target)&&a();};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[a]),(0,l.jsxs)("div",{ref:s,className:"palette",role:"dialog","aria-labelledby":"palette-title","aria-describedby":"palette-desc",tabIndex:-1,style:{cursor:"default"},onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{var t,n,l;if("Escape"===e.key){e.preventDefault(),a();return;}if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("pal-card"))return;let r=Array.from(null!=(t=null==(n=s.current)?void 0:n.querySelectorAll(".pal-card"))?t:[]),i=function(e,t,n,l){let r;if(0===n)return null;if("Home"===e)return 0;if("End"===e)return n-1;if("ArrowRight"===e)r=1;else if("ArrowLeft"===e)r=-1;else if("ArrowDown"===e)r=l;else{if("ArrowUp"!==e)return null;r=-l;}return Math.max(0,Math.min(n-1,t+r));}(e.key,r.indexOf(e.target),r.length,o);null!==i&&(e.preventDefault(),u(i),null==(l=r[i])||l.focus());},onBlur:e=>{var t;e.relatedTarget instanceof Node&&(null==(t=s.current)?void 0:t.contains(e.relatedTarget))!==!0&&a();},"data-columns":o,children:[(0,l.jsxs)("div",{className:"palette-head",children:[(0,l.jsx)("span",{className:"palette-badge",children:(0,l.jsx)(I.Icons.add,{size:17})}),(0,l.jsxs)("div",{className:"palette-htext",children:[(0,l.jsx)("span",{id:"palette-title",className:"palette-title",children:"New window"}),(0,l.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsx)("button",{type:"button",className:"palette-x",onClick:a,"aria-label":"Close",title:"Close",children:(0,l.jsx)(I.Icons.close,{size:16})})]}),(0,l.jsx)("div",{className:"palette-grid",children:n.map((e,n)=>{let r=t[e],a=I.Icons[r.icon];return(0,l.jsxs)("button",{type:"button",className:"pal-card pal-main",tabIndex:n===d?0:-1,onFocus:()=>u(n),onClick:()=>i(e),children:[(0,l.jsx)("span",{className:"pal-ico",children:(0,l.jsx)(a,{size:18})}),(0,l.jsx)("span",{className:"pal-name",children:r.title}),(0,l.jsx)("span",{className:"pal-desc",children:r.desc}),(0,l.jsx)("span",{className:"pal-add","aria-hidden":"true",children:(0,l.jsx)(I.Icons.plus,{size:15})})]},e);})})]});}var tx=e.i(26428),tC=e.i(83500);let tj=new Set(["completed","dry-run","fix-applied","fix-proposed","investigation-only"]);function tS(e){return e.length>200?e.slice(0,200):e;}function tN(e){if(null!==e&&"object"==typeof e)return e;}function tI(){return"Investigation complete; root cause documented.";}function tE(e){let t=e.workflowId;return"unit-test-generation"===t||"unit-tests"===t?"unit-tests":"bug-investigation"===t?"bug":"verify"===e.taskType?"verify":"explain-plan"===e.taskType?"explain":"other";}var tR=e.i(89956),tA=e.i(86090);let tP="\n…[truncated]",tM=["text/"],tT=new Set(["application/json","application/x-yaml","application/yaml"]),tz=new TextEncoder();function tF(e){return tz.encode(e).length;}function tL(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e;}let tW=`${String(256)} KB`;function t$(e){return`"${e}" won't be sent — the ${tW} attachment limit was already used by earlier files.`;}async function tD(e,t){var n,l;let r,i,a,o,s;if(e.remainingAggregate<=0)return t$(tL(t.name));try{let e=65536+tF(tP)+4;r=await t.file.slice(0,e).text();}catch{return n=tL(t.name),`Couldn't read "${n}" — it will be skipped. Your message will be sent without it.`;}let c=Math.min(65536,Math.max(e.remainingAggregate-tF(tP),0));if(c<=0)return t$(tL(t.name));let{entry:d,consumed:u}=(a=(i=tF(l=r)>c)?function(e,t){if(t<=0)return"";if(tF(e)<=t)return e;let n=0,l="";for(let r of e){let e=n+tF(r);if(e>t)break;n=e,l+=r;}return l;}(l,c):l,o=tF(a),s=i?tF(tP):0,{entry:{id:t.id,displayName:tL(t.name),mimeType:t.mimeType,sizeBytes:t.sizeBytes,extractedBytes:o,truncated:i,truncationMarker:i?tP:void 0,text:a},consumed:o+s});if(0===d.text.length)return 0===r.length?void 0:t$(tL(t.name));e.entries.push(d),e.remainingAggregate-=u;}async function tO(e){var t,n;let l=[],r=[];for(let n of e)(function(e){return!!tM.some(t=>e.startsWith(t))||tT.has(e);})(n.mimeType)?r.push(n):l.push((t=tL(n.name),`Couldn't extract text from "${t}" — it will be sent without document text.`));let i=r.slice(0,16),a={entries:[],remainingAggregate:262144};for(let e of i){let t=await tD(a,e);void 0!==t&&l.push(t);}for(let e of r.slice(16))l.push((n=tL(e.name),`"${n}" won't be sent — only the first ${String(16)} documents are included.`));return{entries:a.entries,failures:l};}var tK=e.i(45624);function tq(e){void 0!==e.previewUrl&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(e.previewUrl);}let tB="New chat",t_="keiko:chat-upsert",tG="keiko:chat-delete",tU=["completed","failed","cancelled"];function tJ(e){return"idle"!==e&&!tU.includes(e);}let tV="The model request completed, but the provider did not return any answer text. Retry once; if it happens again, check the selected model deployment in Settings.",tY=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),tX=["context length","context_length_exceeded","max_tokens","too many tokens"],tH=["empty assistant response","empty grounded answer","without assistant content"];function tZ(e){let t;return function(e){if(e instanceof W.ApiError&&tY.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&tX.some(e=>t.includes(e));}(e)?"The conversation context exceeded the model's window. Open a new chat or pick a larger-context model.":0!==(t=e instanceof Error?e.message.toLowerCase():"").length&&tH.some(e=>t.includes(e))?e instanceof W.ApiError?`${tV} (${e.code})`:tV:(0,tA.formatUserError)(e,"Something went wrong. Try again.");}async function tQ(e){var t;let n,l=Date.now(),r={...e,idempotencyKey:null!=(t=e.idempotencyKey)?t:"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,messages:e.messages.map((e,t)=>{var n;return{...e,timestamp:null!=(n=e.timestamp)?n:l+t};})};for(let e=0;e<2;e+=1)try{return await(0,W.appendDesktopChatVoiceTurn)(r);}catch(e){if(n=e,!(!(e instanceof W.ApiError)||e.status>=500))break;}throw n;}function t0(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt);}let t1=new Set(),t2=!1;function t4(e){for(let t of t1)t(e);}function t3(e){let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.projectPath&&"string"==typeof t.title&&"string"==typeof t.selectedModel&&(ni(),t4({type:"upsert",chat:t}));}function t5(e){let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.chatId&&(ni(),t4({type:"delete",chatId:t.chatId}));}function t6(e){ni(),window.dispatchEvent(new CustomEvent(t_,{detail:e}));}function t8(e){var t;return null==(t=e.find(tR.isConversationEligibleModel))?void 0:t.id;}function t7(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,tR.isConversationEligibleModel)(t))?e:t8(t);}function t9(e){return void 0!==e.connectedScope||void 0!==e.connectedScopes&&e.connectedScopes.length>0||void 0!==e.localKnowledgeScope||void 0!==e.localKnowledgeScopes&&e.localKnowledgeScopes.length>0;}let ne={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0},nt=0,nn=new Map(),nl=new Map();function nr(e){let t={...e};return void 0!==e.projects&&(t.projects=[...e.projects]),void 0!==e.chats&&(t.chats=[...e.chats]),void 0!==e.messages&&(t.messages=[...e.messages]),void 0!==e.models&&(t.models=[...e.models]),t;}function ni(){nt+=1,t=void 0,n=void 0;}function na(e){return{chats:Array.from(e.chats)};}function no(e){return{messages:Array.from(e.messages)};}function ns(e){let t=nn.get(e);if(void 0!==t)return t.then(na);let n=(0,W.fetchChats)(e).then(na).finally(()=>{nn.get(e)===n&&nn.delete(e);});return nn.set(e,n),n.then(na);}function nc(e,t){let n=`${t}\u0000${e}`,l=nl.get(n);if(void 0!==l)return l.then(no);let r=(0,W.fetchChatMessages)(e,t).then(no).finally(()=>{nl.get(n)===r&&nl.delete(n);});return nl.set(n,r),r.then(no);}class nd extends Error{constructor(){super("run-summary poll aborted"),this.name="PollAbortError";}}let nu=new Map();async function np(e,t,n,l){var r;let i=n.runId;if(void 0===i)return;let a={...(void 0===n.workflowId?{}:{workflowId:n.workflowId}),...(void 0===n.taskType?{}:{taskType:n.taskType})};for(let o=0;o<120;o+=1){let s;if((null==l?void 0:l.aborted)===!0)break;try{let e=await(0,W.fetchRunReport)(i),t=function(e,t){let n=tN(e);if(void 0===n)return{kind:"unknown"};let l=function(e){let t=e.status;if("string"==typeof t)return t;}(n),r=tE(t);return"running"===l?{kind:"running"}:"cancelled"===l?{kind:"terminal",summary:{workflowStatus:"cancelled",shortResult:"Run cancelled."}}:"failed"===l||"rejected"===l?{kind:"terminal",summary:{workflowStatus:"failed",shortResult:tS(function(e){let t,n,l=(t=tN(e.failure),n=null==t?void 0:t.message,"string"==typeof n&&n.length>0?n:void 0);return void 0!==l?tS(`Run failed: ${l}.`):"Run failed.";}(n))}}:void 0!==l&&tj.has(l)?{kind:"terminal",summary:{workflowStatus:"completed",shortResult:tS(function(e,t){if("unit-tests"===t)return function(e){let t,n=e.addedTestFiles;if(Array.isArray(n)){let e=0,l=!1;for(let t of n){let n=tN(t),r=null==n?void 0:n.estimatedTestCount;"number"==typeof r&&Number.isFinite(r)&&(e+=r,l=!0);}l&&(t=e);}let l=Array.isArray(n)?n.length:0;return l>0&&void 0!==t?`Generated ${String(l)} test files; ${String(t)} tests proposed.`:l>0?`Generated ${String(l)} test files.`:"Completed.";}(e);if("bug"===t)return tI();if("verify"===t){let t,n;return t=tN(e.verificationSummary),n=null==t?void 0:t.results,Array.isArray(n)&&n.length>0?`Verification passed: ${String(n.length)} classifications.`:"Verification passed.";}if("explain"===t){let t=e.dryRunPreview;if("string"==typeof t&&t.length>0){let e=t.split("\n").filter(e=>e.trim().length>0);if(e.length>0)return`Plan generated; ${String(e.length)} steps.`;}return"Plan generated.";}return"Completed.";}(n,r))}}:{kind:"unknown"};}(e.report,a);"terminal"===t.kind&&(s=t.summary);}catch(e){if(e instanceof W.ApiError&&404===e.status)try{let e=await(0,W.fetchEvidenceManifest)(i),t=function(e,t){let n=tN(e),l=void 0===n?void 0:tN(n.run),r=void 0===l?void 0:l.outcome,i=tE(t);return"cancelled"===r?{workflowStatus:"cancelled",shortResult:"Run cancelled."}:"failed"===r||"limit-exceeded"===r?{workflowStatus:"failed",shortResult:"Run failed."}:"completed"===r?{workflowStatus:"completed",shortResult:tS("bug"===i?tI():"verify"===i?"Verification passed.":"explain"===i?"Plan generated.":"unit-tests"===i?"Generated tests.":"Completed.")}:{workflowStatus:"completed",shortResult:"Completed."};}(e.manifest,a);s={workflowStatus:"failed"===t.workflowStatus||"cancelled"===t.workflowStatus?t.workflowStatus:"completed",shortResult:t.shortResult};}catch{}else break;}if(void 0!==s){let l=await(0,W.patchChatMessage)(n.id,e.id,t,s);return{chatId:e.id,messageId:n.id,message:l.message};}if(o<119)try{await function(e,t){return(null==t?void 0:t.aborted)===!0?Promise.reject(new nd()):new Promise((n,l)=>{let r=globalThis.setTimeout(()=>{null==t||t.removeEventListener("abort",i),n();},e),i=()=>{globalThis.clearTimeout(r),l(new nd());};null==t||t.addEventListener("abort",i,{once:!0});});}((r=o,Math.min(1e3*2**Math.min(r,4),15e3)),l);}catch{break;}}}async function nf(e){var t;let n=(await(0,W.fetchModels)()).models.filter(tR.isConversationEligibleModel),l=t8(n),r=[...(await(0,W.fetchProjects)().catch(()=>({projects:[]}))).projects].sort((e,t)=>e.favorite!==t.favorite?e.favorite?-1:1:e.lastOpenedAt!==t.lastOpenedAt?t.lastOpenedAt-e.lastOpenedAt:e.path.localeCompare(t.path)),i=null!=(t=r.find(e=>e.available))?t:r[0];if(void 0!==i){let e=t0((await ns(i.path).catch(()=>({chats:[]}))).chats),t=e[0];if(void 0!==t){let l=await nc(t.id,i.path),a=t7(t.selectedModel,n);return{models:n,selectedModel:a,projects:Array.from(r),activeProject:i,chats:e,activeChat:t,messages:Array.from(l.messages)};}}if(void 0===l||!e)return{models:n,selectedModel:l,projects:Array.from(r),activeProject:i,chats:[],activeChat:void 0,messages:[]};let a={modelId:l,title:tB};(null==i?void 0:i.available)===!0&&(a.projectPath=i.path);let o=await(0,W.createDesktopChat)(a);return t6(o.chat),{models:n,selectedModel:o.chat.selectedModel,projects:Array.from(o.projects),activeProject:o.project,chats:t0(o.chats),activeChat:o.chat,messages:Array.from(o.messages)};}let nm="keiko.theme",nh="dark";var ng=e.i(24477);let nv=[{key:"t",mod:["cmd"]},{key:"t",mod:["ctrl"]},{key:"r",mod:["cmd"]},{key:"r",mod:["ctrl"]},{key:"n",mod:["cmd","shift"]},{key:"n",mod:["ctrl","shift"]},{key:"w",mod:["cmd"]},{key:"w",mod:["ctrl"]}];function nw(e){switch(e.kind){case"ui.window.move":return"Move window";case"ui.window.resize":return"Resize window";case"ui.window.zorder":return"Reorder window";case"ui.window.close":return"Close window";case"ui.window.open":return"Open window";case"ui.workspace.pan":return"Pan workspace";case"ui.workspace.zoom":return"Zoom workspace";case"ui.workspace.fit":return"Fit workspace to view";case"ui.panel.toggle":return`Toggle ${e.panel} panel`;case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab";}}function ny(e){let t=[...e.mod].sort();return`${t.join("+")}|${e.key.toLowerCase()}`;}let nb={undoStack:[],redoStack:[]};var nk=e.i(99749);class nx extends Error{constructor(e){super(`Workspace keyboard shortcut conflicts detected: ${e.map(e=>`${ny(e.chord)} (${e.commandIds.join(", ")})`).join("; ")}`),(0,nk._)(this,"conflicts",void 0),this.name="WorkspaceShortcutConflictError",this.conflicts=e;}}class nC extends Error{constructor(e){super(`Workspace keyboard shortcut bindings refused: ${e.map(e=>`${e.commandId} → ${ny(e.chord)}`).join("; ")} are browser-reserved`),(0,nk._)(this,"reserved",void 0),this.name="WorkspaceShortcutReservedError",this.reserved=e;}}var nj=e.i(70478);let nS=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];var nN=e.i(20405),nI=e.i(56782);let nE=()=>(0,l.jsx)("div",{className:"lk-loading",children:"Loading..."}),nR=(0,J.default)(()=>e.A(33333).then(e=>e.ChatWindow),{loadableGenerated:{modules:[72117]},ssr:!1,loading:nE}),nA=(0,J.default)(()=>e.A(44543).then(e=>e.ProjectPanel),{loadableGenerated:{modules:[26507]},ssr:!1,loading:nE}),nP=(0,J.default)(()=>e.A(17024).then(e=>e.ChatHistoryPanel),{loadableGenerated:{modules:[510]},ssr:!1,loading:nE}),nM=(0,J.default)(()=>e.A(50426).then(e=>e.SearchPanel),{loadableGenerated:{modules:[58873]},ssr:!1,loading:nE}),nT=(0,J.default)(()=>e.A(59683).then(e=>e.PromptEnhancerPanel),{loadableGenerated:{modules:[38661]},ssr:!1,loading:nE}),nz=(0,J.default)(()=>e.A(51058).then(e=>e.PluginsPanel),{loadableGenerated:{modules:[27066]},ssr:!1,loading:nE}),nF=(0,J.default)(()=>e.A(53232).then(e=>e.AutomationsPanel),{loadableGenerated:{modules:[21550]},ssr:!1,loading:nE}),nL=(0,J.default)(()=>e.A(42885).then(e=>e.MobilePanel),{loadableGenerated:{modules:[43045]},ssr:!1,loading:nE}),nW=(0,J.default)(()=>e.A(31266).then(e=>e.InspectorPanel),{loadableGenerated:{modules:[1466]},ssr:!1,loading:nE}),n$=(0,J.default)(()=>e.A(4232).then(e=>e.NotificationsPanel),{loadableGenerated:{modules:[90330]},ssr:!1,loading:nE}),nD=(0,J.default)(()=>e.A(45416).then(e=>e.ResourcesPanel),{loadableGenerated:{modules:[82109]},ssr:!1,loading:nE}),nO=(0,J.default)(()=>e.A(68932).then(e=>e.TimelinePanel),{loadableGenerated:{modules:[44884]},ssr:!1,loading:nE}),nK=(0,J.default)(()=>e.A(58212).then(e=>e.KeikoTwinPanel),{loadableGenerated:{modules:[49532]},ssr:!1,loading:nE}),nq=(0,J.default)(()=>e.A(38673).then(e=>e.SettingsPanel),{loadableGenerated:{modules:[91236]},ssr:!1,loading:nE}),nB=(0,J.default)(()=>e.A(70404).then(e=>e.UpdateWindow),{loadableGenerated:{modules:[55263]},ssr:!1,loading:nE}),n_=(0,J.default)(()=>e.A(34479).then(e=>e.FilesWidget),{loadableGenerated:{modules:[31798]},ssr:!1,loading:nE}),nG=(0,J.default)(()=>e.A(55249).then(e=>e.EditorWidget),{loadableGenerated:{modules:[26019]},ssr:!1,loading:nE}),nU=(0,J.default)(()=>e.A(65).then(e=>e.BrowserWidget),{loadableGenerated:{modules:[3246]},ssr:!1,loading:nE}),nJ=(0,J.default)(()=>e.A(34722).then(e=>e.TerminalWidget),{loadableGenerated:{modules:[43554]},ssr:!1,loading:nE}),nV=(0,J.default)(()=>e.A(75888).then(e=>e.CommandsWidget),{loadableGenerated:{modules:[34484]},ssr:!1,loading:nE}),nY=(0,J.default)(()=>e.A(82309).then(e=>e.RuntimeHubWidget),{loadableGenerated:{modules:[94680]},ssr:!1,loading:nE}),nX=(0,J.default)(()=>e.A(81847).then(e=>e.GitClientWindow),{loadableGenerated:{modules:[12525]},ssr:!1,loading:nE}),nH=(0,J.default)(()=>e.A(97072).then(e=>e.GovernedPullRequestCard),{loadableGenerated:{modules:[67988]},ssr:!1,loading:nE}),nZ=(0,J.default)(()=>e.A(9e4).then(e=>e.GovernedMergeCard),{loadableGenerated:{modules:[86531]},ssr:!1,loading:nE}),nQ=(0,J.default)(()=>e.A(6814).then(e=>e.ContainerStatusWidget),{loadableGenerated:{modules:[50746]},ssr:!1,loading:nE}),n0=(0,J.default)(()=>e.A(20678).then(e=>e.ReviewWidget),{loadableGenerated:{modules:[34264]},ssr:!1,loading:nE}),n1=(0,J.default)(()=>e.A(61721).then(e=>e.AgentRunWidget),{loadableGenerated:{modules:[1867]},ssr:!1,loading:nE}),n2=(0,J.default)(()=>e.A(43759).then(e=>e.IntegrationsWidget),{loadableGenerated:{modules:[21659]},ssr:!1,loading:nE}),n4=(0,J.default)(()=>e.A(99462).then(e=>e.ConnectorPickerWidget),{loadableGenerated:{modules:[20900]},ssr:!1,loading:nE}),n3=(0,J.default)(()=>e.A(93261).then(e=>e.PdfCitationPreviewWindow),{loadableGenerated:{modules:[28867]},ssr:!1,loading:nE}),n5=(0,J.default)(()=>e.A(22699).then(e=>e.FigmaSnapshotWindow),{loadableGenerated:{modules:[7492]},ssr:!1,loading:nE}),n6=(0,J.default)(()=>e.A(58860).then(e=>e.FigmaJsonSourceWindow),{loadableGenerated:{modules:[68188]},ssr:!1,loading:nE}),n8=(0,J.default)(()=>e.A(28945).then(e=>e.FigmaImageSourceWindow),{loadableGenerated:{modules:[41785]},ssr:!1,loading:nE}),n7=(0,J.default)(()=>e.A(25802).then(e=>e.QiHubPanel),{loadableGenerated:{modules:[12124]},ssr:!1,loading:nE}),n9=(0,J.default)(()=>e.A(24100).then(e=>e.QiRunCard),{loadableGenerated:{modules:[64403]},ssr:!1,loading:nE}),le=(0,J.default)(()=>e.A(39644).then(e=>e.RelationshipsView),{loadableGenerated:{modules:[76253]},ssr:!1,loading:nE}),lt=(0,J.default)(()=>e.A(44124).then(e=>e.MemoriaVivaWindow),{loadableGenerated:{modules:[76724]},ssr:!1,loading:nE}),ln=(0,J.default)(()=>e.A(12938).then(e=>e.ConnectorGraph),{loadableGenerated:{modules:[60597]},ssr:!1,loading:nE});function ll(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function lr(e,t){var n,l,r;return null!=(n=null!=(l=null!=(r=e.activeRoot)?r:t)?l:e.linkedRoot)?n:void 0;}function li(e,t){let n=e[t];return"number"==typeof n&&Number.isFinite(n)?n:void 0;}function la(e,t){let n=ll(e,t);if(void 0===n||0===n.trim().length)return[];try{let e=JSON.parse(n);if(!Array.isArray(e))return[];return e.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());}catch{return[];}}function lo(e){var t;let{cfg:n,ctx:a}=e,o=(0,i.useChatSessionContext)(),s=(0,r.useRef)(!1),c=ll(n,"chatId"),d=ll(n,"title"),{updateCfg:u}=a,{activeChat:p,activeProject:f,chats:m,loading:h,openChat:g,openNewChat:v}=o,w=void 0!==p&&"closed"!==p.status?p:void 0;(0,r.useEffect)(()=>{if(!h){if(void 0!==c){if((null==w?void 0:w.id)===c)return;let e=m.find(e=>e.id===c&&"closed"!==e.status);void 0!==e&&g(e);return;}s.current||(s.current=!0,v(void 0,d).then(e=>{void 0!==e&&u({chatId:e.id,title:e.title});}).finally(()=>{s.current=!1;}));}},[c,null==w?void 0:w.id,m,h,g,v,d,u]),(0,r.useEffect)(()=>{h||void 0===c||(null==w?void 0:w.id)!==c||w.title!==d&&u({title:w.title});},[null==w?void 0:w.id,null==w?void 0:w.title,c,h,d,u]);let y=void 0!==c&&!o.loading&&(null==w?void 0:w.id)!==c&&!o.chats.some(e=>e.id===c&&"closed"!==e.status),b=o.loading||void 0!==c&&(null==w?void 0:w.id)!==c,k=(0,r.useCallback)(e=>{var t,n;if(void 0===e.runId)return;let l={runId:e.runId},r=null!=(t=e.workflowId)?t:e.taskType;void 0!==r&&(l.workflow=r);let i=null!=(n=a.activeRoot)?n:null==f?void 0:f.path;void 0!==i&&(l.workspaceRoot=i),a.openWindow("agents",l);},[null==f?void 0:f.path,a]);return y?(0,l.jsxs)("div",{className:"lk-empty",children:[(0,l.jsx)("p",{className:"lk-empty-title",children:"Chat not found"}),(0,l.jsx)("p",{className:"lk-empty-body",children:"This conversation was deleted or is no longer available."})]}):b?(0,l.jsx)("div",{className:"lk-loading",children:"Opening chat..."}):(0,l.jsx)(nR,{windowId:a.windowId,mini:!0===a.mini,minimalChat:!0===a.minimalChat,compact:!0===a.compact,controlsNarrow:!0===a.controlsNarrow,barCompact:!0===a.barCompact,workflowCompact:!0===a.workflowCompact,linkedRoot:null!=(t=a.activeRoot)?t:a.linkedRoot,linkedRoots:a.linkedRoots,openEditorFile:a.openEditorFile,previewWindows:{add:a.openWindow,focus:a.focusWindow,update:a.updateWindow},onOpenRunResult:k});}(0,D.registerWindowRender)("chat",(e,t)=>(0,l.jsx)(lo,{cfg:e,ctx:t})),(0,D.registerWindowRender)("chatHistory",(e,t)=>(0,l.jsx)(nP,{openChatWindow:e=>{t.openWindow("chat",{chatId:e.id,title:e.title});}})),(0,D.registerWindowRender)("project",()=>(0,l.jsx)(nA,{})),(0,D.registerWindowRender)("promptEnhancer",(e,t)=>{var n;return(0,l.jsx)(nT,{connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots});}),(0,D.registerWindowRender)("search",()=>(0,l.jsx)(nM,{})),(0,D.registerWindowRender)("plugins",()=>(0,l.jsx)(nz,{})),(0,D.registerWindowRender)("automations",()=>(0,l.jsx)(nF,{})),(0,D.registerWindowRender)("mobile",()=>(0,l.jsx)(nL,{})),(0,D.registerWindowRender)("inspector",()=>(0,l.jsx)(nW,{})),(0,D.registerWindowRender)("notifications",()=>(0,l.jsx)(n$,{})),(0,D.registerWindowRender)("resources",()=>(0,l.jsx)(nD,{})),(0,D.registerWindowRender)("activity",()=>(0,l.jsx)(nO,{})),(0,D.registerWindowRender)("keiko",()=>(0,l.jsx)(nK,{})),(0,D.registerWindowRender)("settings",(e,t)=>(0,l.jsx)(nq,{openUpdatesWindow:()=>t.openWindow("updates",{entrypoint:"settings"})})),(0,D.registerWindowRender)("updates",()=>(0,l.jsx)(nB,{})),(0,D.registerWindowRender)("localKnowledge",()=>(0,l.jsx)(ln,{showBackToWorkspace:!1})),(0,D.registerWindowRender)("pdfCitationPreview",(e,t)=>(0,l.jsx)(n3,{cfg:e,focusWindow:t.focusWindow,restoreWindow:t.restoreWindow,updateCfg:t.updateCfg,windowId:t.windowId})),(0,D.registerWindowRender)("quality",(e,t)=>{var n;return(0,l.jsx)(n7,{openRun:(e,n)=>{var l;let r,i=void 0!==n?(0,nI.connectedRunSourcesCfgFromInlineSources)(n):(r=(0,nI.buildConnectedRunSources)({connectedFilePath:null!=(l=t.linkedFilePath)?l:null,connectedRoot:t.linkedRoot,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources}),(0,nI.connectedRunSourcesCfgFromSources)(r));t.openWindow("qiRun",{runId:e,...i});},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources});}),(0,D.registerWindowRender)("qiRun",(e,t)=>{let n=ll(e,"runId");if(void 0===n||""===n)return(0,l.jsx)("div",{className:"lk-empty",children:(0,l.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let r=(0,nI.connectedRunSourcesFromWindowCfg)(e),i=(0,nI.connectedRunSourcesCfgFromSources)(r);return(0,l.jsx)(n9,{runId:n,connectedSources:r,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...i});}});}),(0,D.registerWindowRender)("relationships",()=>(0,l.jsx)(le,{})),(0,D.registerWindowRender)("files",(e,t)=>{let n=lr(t,ll(e,"root")),r=(e,n,l)=>{let r={activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0};void 0!==l&&(r.activeDirectoryPath=null!=l?l:void 0),t.updateCfg(r);},i=e=>{t.updateCfg({root:e,activeFilePath:void 0,activeDirectoryPath:void 0,resolvedRoot:void 0});},a=(e,n)=>{t.openWindow("editor",{root:e,file:n,openFiles:[n]});},o=e=>{t.openWindow("governedGit",{projectPath:e});};return void 0!==n?(0,l.jsx)(n_,{root:n,onActiveFileChange:r,onRootChange:i,onOpenFile:a,onOpenGitDelivery:o}):(0,l.jsx)(n_,{onActiveFileChange:r,onRootChange:i,onOpenFile:a,onOpenGitDelivery:o});}),(0,D.registerWindowRender)("editor",(e,t)=>{var n;let r=lr(t,ll(e,"root")),i=ll(e,"file"),a=function(e,t){let n=e[t];if(!Array.isArray(n))return;let l=n.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());return l.length>0?l:void 0;}(e,"openFiles"),o=ll(e,"layoutJson"),s=li(e,"revealLineStart"),c=li(e,"revealLineEnd"),d=ll(e,"revealRequestId"),u={};return void 0!==r&&(u.root=r),void 0!==i&&(u.file=i),void 0!==a&&(u.openFiles=a),void 0!==o&&(u.layoutJson=o),void 0!==s&&(u.revealLineStart=s),void 0!==c&&(u.revealLineEnd=c),void 0!==d&&(u.revealRequestId=d),u.linkedRoot=t.linkedRoot,u.linkedFilePath=t.linkedFilePath,u.linkedCapsuleIds=t.linkedCapsuleIds,u.linkedCapsuleSetIds=t.linkedCapsuleSetIds,u.windowId=t.windowId,u.onWorkspaceChange=e=>{t.updateCfg(e);},(0,l.jsx)(nG,{...u},null!=(n=t.activeRoot)?n:"unbound");}),(0,D.registerWindowRender)("browser",e=>{let t=ll(e,"url");return void 0!==t&&""!==t?(0,l.jsx)(nU,{url:t}):(0,l.jsx)(nU,{});}),(0,D.registerWindowRender)("terminal",(e,t)=>{var n;let r=lr(t,ll(e,"projectPath")),i=null!=(n=t.activeRoot)?n:ll(e,"cwd"),a={};return void 0!==i&&(a.cwd=i),void 0!==r&&(a.projectPath=r),(0,l.jsx)(nJ,{...a});}),(0,D.registerWindowRender)("commands",(e,t)=>{let n=lr(t,ll(e,"projectPath")),r={};return void 0!==n&&(r.projectPath=n),(0,l.jsx)(nV,{...r});}),(0,D.registerWindowRender)("runtime",(e,t)=>{let n=lr(t,ll(e,"projectPath")),r=(e,n)=>{t.openWindow(e,{projectPath:n});};return(0,l.jsx)(nY,{projectPath:n,onProjectPathChange:e=>t.updateCfg({projectPath:e}),onOpenFiles:e=>{t.openWindow("files",void 0!==e?{root:e}:void 0);},onOpenCommands:e=>r("commands",e),onOpenContainers:e=>{t.openWindow("containerStatus",void 0!==e?{projectPath:e}:void 0);},onOpenGovernedGit:e=>r("governedGit",e),onOpenPullRequest:e=>r("governedPullRequest",e),onOpenMerge:e=>r("governedMerge",e)});}),(0,D.registerWindowRender)("governedGit",(e,t)=>{var n;let r=lr(t,null!=(n=ll(e,"projectPath"))?n:ll(e,"workspaceRoot"));return(0,l.jsx)(nX,{projectId:r,onOpenFiles:e=>t.openWindow("files",{root:e}),onOpenEditor:e=>t.openWindow("editor",{root:e}),updateCfg:e=>t.updateCfg(e)});}),(0,D.registerWindowRender)("governedPullRequest",(e,t)=>{var n,r;let i=lr(t,null!=(n=ll(e,"projectPath"))?n:ll(e,"workspaceRoot")),a=null!=(r=ll(e,"headBranchName"))?r:void 0;return(0,l.jsx)(nH,{projectId:i,headBranchName:a});}),(0,D.registerWindowRender)("governedMerge",(e,t)=>{var n,r;let i=lr(t,null!=(n=ll(e,"projectPath"))?n:ll(e,"workspaceRoot")),a=null!=(r=ll(e,"headBranchName"))?r:void 0;return(0,l.jsx)(nZ,{projectId:i,headBranchName:a});}),(0,D.registerWindowRender)("containerStatus",(e,t)=>{let n=lr(t,ll(e,"projectPath")),r={};return void 0!==n&&(r.projectPath=n),(0,l.jsx)(nQ,{...r});}),(0,D.registerWindowRender)("review",(e,t)=>{let n=ll(e,"runId"),r=e=>{t.updateCfg({runId:e});};return void 0!==n&&""!==n?(0,l.jsx)(n0,{runId:n,onRunIdSubmit:r}):(0,l.jsx)(n0,{onRunIdSubmit:r});}),(0,D.registerWindowRender)("agents",(e,t)=>{var n;let r,i,a,o,s,c,d,u,p,f,m;return(0,l.jsx)(n1,{cfg:(a={},void 0!==(o=ll(n=e,"workflow"))&&(a.workflow=o),void 0!==(s=ll(n,"model"))&&(a.model=s),void 0!==(c=ll(n,"runId"))&&(a.runId=c),void 0!==(d=ll(n,"fingerprint"))&&(a.fingerprint=d),void 0!==(u=ll(n,"workspaceRoot"))&&(a.workspaceRoot=u),void 0!==(p=ll(n,"inputJson"))&&(a.inputJson=p),void 0!==(f="boolean"==typeof(r=n.keikoMode)?r:void 0)&&(a.keikoMode=f),void 0!==(m="ask"===(i=n.access)||"full"===i?i:void 0)&&(a.access=m),a),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath});}),(0,D.registerWindowRender)("memoria",()=>(0,l.jsx)(lt,{})),(0,D.registerWindowRender)("integ",()=>(0,l.jsx)(n2,{})),(0,D.registerWindowRender)("figma",(e,t)=>{let n=ll(e,"snapshotRunId"),r=la(e,"selectedScreenIdsJson"),i=ll(e,"selectedScreenName");return(0,l.jsx)(n5,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:r,selectedScreenName:i,openScreenSource:e=>{let{snapshotRunId:n,screenId:l,name:r}=e;t.openWindow("figmaView",{snapshotRunId:n,selectedScreenIdsJson:JSON.stringify([l]),selectedScreenName:r});},openTokenSettings:()=>{(0,nN.requestGatewaySetup)(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),(0,D.registerWindowRender)("figmaView",(e,t)=>{let n=ll(e,"snapshotRunId"),r=la(e,"selectedScreenIdsJson"),i=ll(e,"selectedScreenName");return(0,l.jsx)(n5,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:r,selectedScreenName:i,openTokenSettings:()=>{(0,nN.requestGatewaySetup)(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),(0,D.registerWindowRender)("figmaJson",e=>{let t=ll(e,"snapshotRunId"),n=ll(e,"screenId"),r=ll(e,"selectedScreenName");return(0,l.jsx)(n6,{snapshotRunId:t,screenId:n,screenName:r});}),(0,D.registerWindowRender)("figmaImage",e=>{let t=ll(e,"imageSrc"),n=ll(e,"selectedScreenName");return(0,l.jsx)(n8,{imageSrc:t,screenName:n});}),(0,D.registerWindowRender)("connector",(e,t)=>{let n=ll(e,"presentation"),r=ll(e,"selectedKind"),i=ll(e,"selectedId"),a=ll(e,"selectedLabel"),o=ll(e,"selectedState");return(0,l.jsx)(n4,{presentation:n,selectedKind:r,selectedId:i,selectedLabel:a,selectedState:o,onSelect:e=>{t.updateCfg(e);},onManageConnectors:()=>{t.openWindow("localKnowledge");}});});let ls={supported:{heading:"Install Keiko",body:"Keep Keiko in your app shelf for fast access.",install:"Install Keiko"},"ios-add-to-home":{heading:"Install Keiko",body:'On iOS Safari, tap Share, then "Add to Home Screen".',install:null}};function lc(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,r.useState)(!1),n=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=e=>{e.preventDefault(),function(e){if("function"!=typeof e.prompt)return!1;let t=e.userChoice;return"object"==typeof t&&null!==t&&"function"==typeof t.then;}(e)&&(n.current=e,t(!0));},l=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",l),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",l);};},[]),{available:e,triggerInstall:(0,r.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:l}=await e.userChoice;"accepted"===l&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);},[])};}(),[n,i]=(0,r.useState)(!1),[a]=(0,r.useState)(()=>{let e;return"u">typeof navigator?(e=navigator.userAgent.toLowerCase()).includes("crios/")?"manual":e.includes("chrome/")&&!e.includes("mobile")||e.includes("edg/")||e.includes("chromium/")?"supported":e.includes("firefox/")?"manual":e.includes("safari/")&&(e.includes("iphone")||e.includes("ipad")||e.includes("ipod"))?"ios-add-to-home":(e.includes("safari/")&&e.includes("macintosh"),"manual"):"manual";}),o=(0,r.useRef)(null),s=(0,r.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),i(!0);},[]),c=(0,r.useCallback)(async()=>{await t();},[t]),d=(0,r.useCallback)(e=>{"Escape"!==e.key||e.defaultPrevented||s();},[s]);if(n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||function(){let e=localStorage.getItem("keiko.pwa.dismissed");if(null===e)return!1;let t=Date.parse(e);return!!Number.isNaN(t)||Date.now()-t<2592e6;}()||"supported"===a&&!e||"supported"!==a&&"ios-add-to-home"!==a)return null;let u=ls[a];return(0,l.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",onKeyDown:d,children:(0,l.jsxs)("div",{className:"install-banner-body",children:[(0,l.jsxs)("div",{className:"install-banner-text",children:[(0,l.jsx)("span",{className:"install-banner-heading",children:u.heading}),(0,l.jsx)("span",{className:"install-banner-desc",children:u.body})]}),(0,l.jsxs)("div",{className:"install-banner-actions",children:[null!==u.install&&(0,l.jsx)("button",{ref:o,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:u.install}),(0,l.jsx)("button",{type:"button",className:"install-banner-btn-dismiss",onClick:s,children:"Not now"})]})]})});}e.i(47167);let ld="keiko.service-worker-update-reload-pending",lu=!1;function lp(){lu||function(){try{if("true"!==window.sessionStorage.getItem(ld))return!1;return window.sessionStorage.removeItem(ld),!0;}catch{return!0;}}()&&(lu=!0,window.location.reload());}function lf(e){let t=e.waiting;if(null!==t){try{window.sessionStorage.setItem(ld,"true");}catch{}try{t.postMessage({type:"KEIKO_ACTIVATE_WAITING_SERVICE_WORKER"});}catch{try{window.sessionStorage.removeItem(ld);}catch{}}}}var lm=e.i(71187);function lh(e){var t;return`keiko.updateStartupNotice.dismissed.${[e.currentVersion,null!=(t=e.targetVersion)?t:"no-target",e.status,e.severity,e.manualUpdateRequired?"manual":"automatic",e.userActionRequired?"action":"no-action",e.blockers.map(e=>e.code).slice().sort().join(",")].join("|")}`;}function lg(e){try{window.localStorage.setItem(lh(e),"1");}catch{}}function lv(e){var t;let{ready:n,openUpdates:i,fetchReport:a=W.fetchStartupUpdatePreflight}=e,o=(0,$.useTranslate)(),[s,c]=(0,r.useState)({status:"idle"});if((0,r.useEffect)(()=>{if(!n||"idle"!==s.status)return;let e=!1;return a().then(t=>{if(!e&&(0,lm.hasStartupUpdateSignal)(t)){if(function(e){try{return"1"===window.localStorage.getItem(lh(e));}catch{return!1;}}(t))return void c({status:"dismissed"});c({status:"ready",report:t});}}).catch(()=>void 0),()=>{e=!0;};},[a,n,s.status]),"ready"!==s.status)return null;let d="critical"===s.report.severity,u=null!=(t=s.report.targetVersion)?t:o("updates.versionUnknown");return(0,l.jsxs)("aside",{className:"update-notice","data-severity":d?"critical":"normal",role:d?"alert":"status","aria-live":d?"assertive":"polite","aria-label":o("updates.notice.aria"),children:[(0,l.jsx)("span",{className:"update-notice-icon","aria-hidden":"true",children:d?(0,l.jsx)(I.Icons.info,{size:17}):(0,l.jsx)(I.Icons.activity,{size:17})}),(0,l.jsxs)("div",{className:"update-notice-body",children:[(0,l.jsx)("strong",{children:o(d?"updates.notice.criticalTitle":"updates.notice.title")}),(0,l.jsx)("span",{children:o("updates.notice.body",{version:u})})]}),(0,l.jsxs)("div",{className:"update-notice-actions",children:[(0,l.jsx)("button",{type:"button",className:"update-notice-primary",onClick:()=>{lg(s.report),i(),c({status:"dismissed"});},children:o("updates.notice.review")}),(0,l.jsx)("button",{type:"button",className:"update-notice-dismiss",onClick:()=>{lg(s.report),c({status:"dismissed"});},children:o("updates.notice.notNow")})]})]});}function lw(e){return null===e||void 0===e.root?null:[e.root.replace(/\\/gu,"/").replace(/\/+$/u,""),e.kind,...e.relativePaths.map(e=>e.replace(/\\/gu,"/").replace(/^\/+|\/+$/gu,""))].join("\0");}function ly(e,t){if(/^\/+$/u.test(e.trim().replace(/\\/gu,"/"))){let e=t.trim().replace(/\\/gu,"/");return 0===e.length?"":e.replace(/^\/+/u,"");}let n=(0,nj.resolveWorkspaceFileIdentifier)(e,t);return"relative"===n.kind?n.path:"root"===n.kind||"empty"===n.kind?"":null;}let lb=["chat","connector","files","editor","agents"],lk=["chatHistory","memoria","settings","automations","mobile","inspector","activity","notifications","resources","localKnowledge","governedGit","figma","quality","promptEnhancer","relationships"];function lx(e){requestAnimationFrame(()=>{var t;let n=document.querySelector(`[data-window-id="${e}"]`);null===n||(null!=(t=n.querySelector("textarea, input, select, button, [tabindex]"))?t:n).focus();});}function lC(){var e,a,s,d,u,p,f,m,I,E,R;let A,P=(0,$.useTranslate)(),{theme:M,toggle:T}=function(){let[e,t]=(0,r.useState)(nh),[n,l]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(nm);return"light"===e||"dark"===e?e:nh;}catch{return nh;}}()),l(!0);},[]),(0,r.useEffect)(()=>{if(n){"u">typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(nm,e);}catch{}}},[e,n]),{theme:e,toggle:(0,r.useCallback)(()=>{t(e=>"light"===e?"dark":"light");},[])};}(),O=(0,F.useTwin)(),B=function(){var e,l,i,a;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=null==(e=o.autoCreate)||e,[c,d]=(0,r.useState)(ne),[u,p]=(0,r.useState)(),[f,m]=(0,r.useState)(""),[h,g]=(0,r.useState)(!0),[v,w]=(0,r.useState)("idle"),[y,b]=(0,r.useState)(),k=tJ(v),x=(0,r.useRef)("idle"),C=(0,r.useRef)(null),[j,S]=(0,r.useState)(),[N,I]=(0,r.useState)(),[E,R]=(0,r.useState)(),{memoryEnabled:A,setMemoryEnabled:P,memoryBudgetTokens:M,setMemoryBudgetTokens:T}=(0,tK.useConversationMemorySettings)(),z=(0,r.useRef)(!0),F=(0,r.useRef)(void 0),L=(e,t)=>t.aborted||F.current!==e,$=(0,r.useRef)(void 0),D=(0,r.useRef)(new Set()),O=(0,r.useRef)(new AbortController()),K=(0,r.useRef)(new Set()),q=(0,r.useRef)(0),B=(0,r.useRef)([]),[_,G]=(0,r.useState)([]),U=(0,r.useRef)([]);U.current=_;let[J,V]=(0,r.useState)([]),Y=(0,r.useCallback)(async e=>{var t;let n,l;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>tx.MAX_ATTACHMENT_BYTES)return{ok:!1,reason:"oversized"};let r=(t=e.type,"unsupported"===(l=(0,tx.classifyAttachmentMime)(t))?"unsupported-type":l);if("unsupported-type"===r)return{ok:!1,reason:"unsupported-type"};let i=c.models.find(e=>e.id===c.selectedModel);if(void 0!==i&&("image"===r&&!i.supportsImageInput||"document"===r&&!i.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===r)try{n=URL.createObjectURL(e);}catch{return{ok:!1,reason:"unsupported-type"};}let a={id:crypto.randomUUID(),kind:r,name:e.name,mimeType:e.type,sizeBytes:e.size,previewUrl:n,file:e};return G(e=>[...e,a]),{ok:!0};},[c.models,c.selectedModel]),X=(0,r.useCallback)(e=>{G(t=>{let n=t.find(t=>t.id===e);return void 0!==n&&tq(n),t.filter(t=>t.id!==e);});},[]),H=(0,r.useCallback)(()=>{G(e=>{for(let t of e)tq(t);return 0===e.length?e:[];});},[]),Z=(0,r.useCallback)(async()=>{let e=_.filter(e=>"document"===e.kind&&void 0!==e.file).map(e=>({id:e.id,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes,file:e.file}));if(0===e.length)return{entries:[],disclosures:[]};let{entries:t,failures:n}=await tO(e);n.length>0&&S(n.join(" "));let l=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:l};},[_]),Q=(0,r.useCallback)(()=>_.map(e=>({id:e.id,kind:e.kind,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes})),[_]),ee=(0,r.useCallback)(()=>{R(void 0);},[]),et=(0,r.useCallback)((e,t)=>({enabled:A,budgetTokens:M,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[M,A]),en=(0,r.useCallback)(async e=>{await(0,tC.acceptMemoryProposal)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),el=(0,r.useCallback)(async e=>{await(0,tC.rejectMemoryProposal)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),er=(0,r.useCallback)(async e=>{await(0,tC.forgetMemory)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)});},[]),ei=(0,r.useCallback)(e=>{x.current=e,w(e);},[]),ea=(0,r.useCallback)(async(e,t,n,l)=>{try{var r;let i=await function(e,t,n,l){var r;let i=`${e.id}:${t}:${n.id}:${null!=(r=n.runId)?r:""}`,a=nu.get(i);if(void 0!==a)return a;let o=np(e,t,n,l).finally(()=>{nu.get(i)===o&&nu.delete(i);});return nu.set(i,o),o;}(e,t,n,null==(r=O.current)?void 0:r.signal);if(void 0===i){z.current&&K.current.add(l);return;}if(!z.current||F.current!==e.id)return;d(t=>{var n;return(null==(n=t.activeChat)?void 0:n.id)!==e.id?t:{...t,messages:t.messages.map(e=>e.id===i.messageId?i.message:e)};});}finally{D.current.delete(l);}},[]);(0,r.useEffect)(()=>{var e;F.current=null==(e=c.activeChat)?void 0:e.id;},[null==(l=c.activeChat)?void 0:l.id]),(0,r.useEffect)(()=>{var e;$.current=null==(e=c.activeProject)?void 0:e.path;},[null==(i=c.activeProject)?void 0:i.path]),(0,r.useEffect)(()=>{B.current=c.models;},[c.models]),(0,r.useEffect)(()=>{let e=!1;return async function(){g(!0),S(void 0);try{let l=await function(e){if(e)return nf(e);let l=Date.now();if(void 0!==t&&t.expiresAt>l)return Promise.resolve(nr(t.value));if(void 0!==n)return n.then(nr);let r=nt,i=nf(!1).then(e=>{let n=nr(e);return nt===r&&(t={expiresAt:Date.now()+2e3,value:n}),nr(n);}).finally(()=>{n===i&&(n=void 0);});return n=i,i.then(nr);}(s);e||d(e=>({...e,...l}));}catch(t){e||S(tZ(t));}finally{e||g(!1);}}(),()=>{e=!0;};},[s]),(0,r.useEffect)(()=>{var e;return e=e=>{if("upsert"===e.type){let{chat:t}=e;d(e=>{var n,l;return{...e,chats:t0([t,...e.chats.filter(e=>e.id!==t.id)]),activeChat:(null==(n=e.activeChat)?void 0:n.id)===t.id?t:e.activeChat,selectedModel:(null==(l=e.activeChat)?void 0:l.id)===t.id?t7(t.selectedModel,e.models):e.selectedModel};});return;}d(t=>{var n,l;return{...t,chats:t.chats.filter(t=>t.id!==e.chatId),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chatId?void 0:t.activeChat,messages:(null==(l=t.activeChat)?void 0:l.id)===e.chatId?[]:t.messages};});},t1.add(e),t2||(window.addEventListener(t_,t3),window.addEventListener(tG,t5),t2=!0),()=>{t1.delete(e),t2&&!(t1.size>0)&&(window.removeEventListener(t_,t3),window.removeEventListener(tG,t5),t2=!1);};},[]),(0,r.useEffect)(()=>(z.current=!0,O.current.signal.aborted&&(O.current=new AbortController()),()=>{var e;for(let t of(z.current=!1,null==(e=C.current)||e.abort(),O.current.abort(),U.current))tq(t);}),[]),(0,r.useEffect)(()=>{let e=c.activeChat,t=c.activeProject;if(void 0!==e&&void 0!==t)for(let n of c.messages){if("system"!==n.role||"string"!=typeof n.runId||void 0!==n.workflowStatus&&"pending"!==n.workflowStatus&&"running"!==n.workflowStatus)continue;let l=n.runId;if(void 0===l)continue;let r=`${n.id}:${l}`;!D.current.has(r)&&(K.current.has(r)||(D.current.add(r),ea(e,t.path,n,r)));}},[c.activeChat,c.activeProject,c.messages,ea]);let eo=(0,r.useCallback)(e=>{let t;S(void 0),d(n=>(t={selectedModel:n.selectedModel,activeChat:n.activeChat,chats:n.chats},{...n,selectedModel:e,activeChat:void 0===n.activeChat?n.activeChat:{...n.activeChat,selectedModel:e},chats:n.chats.map(t=>void 0!==n.activeChat&&t.id===n.activeChat.id?{...t,selectedModel:e}:t)})),G(t=>{let n=t.filter(t=>{let n;return void 0===(n=B.current.find(t=>t.id===e))||("image"===t.kind?n.supportsImageInput:n.supportsDocumentInput);});if(n.length===t.length)return t;let l=new Set(n.map(e=>e.id));for(let e of t)l.has(e.id)||tq(e);return n;});let n=F.current;if(void 0===n)return;let l=q.current+1;q.current=l,(0,W.updateChat)(n,{selectedModel:e}).then(e=>{q.current!==l||F.current===e.chat.id&&(t6(e.chat),d(t=>{var n;return{...t,selectedModel:e.chat.selectedModel,activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chat.id?e.chat:t.activeChat,chats:t.chats.map(t=>t.id===e.chat.id?e.chat:t)};}));}).catch(e=>{if(q.current===l&&F.current===n&&(S(tZ(e)),void 0!==t)){let e=t;d(t=>{var l,r;return{...t,selectedModel:(null==(l=t.activeChat)?void 0:l.id)===n?e.selectedModel:t.selectedModel,activeChat:(null==(r=t.activeChat)?void 0:r.id)===n?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==n)return t;let l=e.chats.find(e=>e.id===n);return void 0!==l?{...t,selectedModel:l.selectedModel}:t;})};});}});},[]),es=(0,r.useCallback)(async(e,t)=>{let n=t7(c.selectedModel,c.models);if(void 0===n)return void S("No conversation-eligible model is configured. Connect a gateway in Settings.");S(void 0),p(void 0);try{var l,r;let i=null==t?void 0:t.trim(),a={modelId:n,title:void 0!==i&&i.length>0?i:tB},o=null!=(l=null==e?void 0:e.path)?l:null==(r=c.activeProject)?void 0:r.path;void 0!==o&&(a.projectPath=o);let s=await(0,W.createDesktopChat)(a);if(void 0!==o&&$.current!==o)return;return F.current=s.chat.id,$.current=s.project.path,t6(s.chat),d({projects:Array.from(s.projects),chats:t0(s.chats),messages:Array.from(s.messages),models:c.models,activeProject:s.project,activeChat:s.chat,selectedModel:s.chat.selectedModel}),s.chat;}catch(e){S(tZ(e));return;}},[c.selectedModel,c.activeProject,c.models]),ec=(0,r.useCallback)(async e=>{S(void 0),p(void 0),$.current=e.path,d(t=>({...t,activeProject:e}));try{let t=await ns(e.path);if($.current!==e.path)return;let n=t0(t.chats),l=n[0];if(void 0===l){if($.current!==e.path)return;await es(e);return;}let r=await nc(l.id,e.path);if($.current!==e.path)return;F.current=l.id;let i=t7(l.selectedModel,c.models);d(e=>({...e,chats:n,activeChat:l,selectedModel:i,messages:Array.from(r.messages)})),R(void 0);}catch(t){if($.current!==e.path)return;S(tZ(t));}},[es,c.models]),ed=(0,r.useCallback)(async e=>{var t,n;if(F.current!==e.id||(null==(t=c.activeChat)?void 0:t.id)!==e.id){S(void 0),p(void 0),null==(n=C.current)||n.abort(),C.current=null,F.current=e.id,I(void 0),R(void 0),V([]);try{let t,n=await nc(e.id,e.projectPath);if(t=e.id,F.current!==t)return;let l=t7(e.selectedModel,c.models);d(t=>{let r=t.projects.find(t=>t.path===e.projectPath);return{...t,activeProject:r,activeChat:e,selectedModel:l,messages:Array.from(n.messages)};});}catch(n){let t;if(t=e.id,F.current!==t)return;S(tZ(n));}}},[null==(a=c.activeChat)?void 0:a.id,c.models]),eu=(0,r.useCallback)(async e=>{let t=e.trim();if(0!==t.length){S(void 0);try{let e=await(0,W.createProject)({path:t}),n=await(0,W.fetchProjects)();d(e=>({...e,projects:Array.from(n.projects)})),await es(e.project);}catch(e){S(tZ(e));}}},[es]),ep=(0,r.useCallback)(e=>{p(t=>(null==t?void 0:t.id)===e?void 0:t),d(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}));},[]),ef=(0,r.useCallback)((e,t,n,l,r)=>{let i=!1,a="",o=null,s="function"==typeof requestAnimationFrame,c=()=>{if(o=null,0===a.length)return;let e=a;a="",p(n=>(null==n?void 0:n.id)===t?{...n,content:n.content+e}:n);},u=()=>{null!==o&&"function"==typeof cancelAnimationFrame&&cancelAnimationFrame(o),o=null;};return{onToken:t=>{if(!L(e,l)){if(i||(ei("streaming"),i=!0),a+=t,!s)return void c();null===o&&(o=requestAnimationFrame(c));}},onDone:i=>{if(u(),c(),L(e,l)){p(e=>(null==e?void 0:e.id)===t?void 0:e),r("cancelled");return;}p(e=>(null==e?void 0:e.id)===t?void 0:e),d(e=>({...e,activeChat:i.chat,chats:t0([i.chat,...e.chats.filter(e=>e.id!==i.chat.id)]),messages:[...e.messages.filter(e=>e.id!==n&&e.id!==t),...Array.from(i.messages)]})),t6(i.chat),void 0!==i.memory&&R(i.memory),r("completed");},onError:n=>{let{code:i,message:o}=n;if(u(),a="",L(e,l)){ep(t),r("cancelled");return;}S(tZ(new W.ApiError(i,o,0))),ep(t),r("failed");},onCancelled:()=>{u(),a="",ep(t),r("cancelled");}};},[ep,ei]),em=(0,r.useCallback)((e,t,n,l,r,i,a,o)=>{let s=`stream-${String(Date.now())}`;p({id:s,chatId:e.id,role:"assistant",content:"",timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0});let c={chatId:e.id,projectPath:t.path,content:n,modelId:r,memory:et(e,t),...(a.length>0?{documentContext:a}:{}),...(o.length>0?{attachments:o}:{})};return new Promise((t,n)=>{let r=ef(e.id,s,l,i,t);(0,W.sendDesktopChatStream)(c,i,r).catch(r=>{ep(s),r instanceof W.StreamingUnavailableError?n(r):r instanceof DOMException&&"AbortError"===r.name||L(e.id,i)?t("cancelled"):(S(tZ(r)),d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),t("failed"));});});},[et,ef,ep]),eh=(0,r.useCallback)(async(e,t,n,l,r,i,a,o)=>{try{ei("contacting");let s=await(0,W.sendDesktopChat)({chatId:e.id,projectPath:t.path,content:n,modelId:r,memory:et(e,t),...(a.length>0?{documentContext:a}:{}),...(o.length>0?{attachments:o}:{})},i);if(L(e.id,i))return"cancelled";return d(e=>({...e,activeChat:s.chat,chats:t0([s.chat,...e.chats.filter(e=>e.id!==s.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(s.messages)]})),t6(s.chat),R(s.memory),"completed";}catch(n){if(n instanceof DOMException&&"AbortError"===n.name||L(e.id,i))return"cancelled";S(tZ(n));try{let n=await(0,W.fetchChatMessages)(e.id,t.path);d(e=>({...e,messages:Array.from(n.messages)}));}catch{d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}));}return"failed";}},[et,ei]),eg=(0,r.useCallback)(async(e,t,n,l,r,i,a,o)=>{var s;if((null==(s=c.models.find(e=>e.id===r))?void 0:s.streaming)!==!0)return eh(e,t,n,l,r,i,a,o);ei("contacting");try{return await em(e,t,n,l,r,i,a,o);}catch(e){if(!(e instanceof W.StreamingUnavailableError))throw e;}return eh(e,t,n,l,r,i,a,o);},[c.models,eh,em,ei]),ev=(0,r.useCallback)(async(e,t,n,l,r,i)=>{I(void 0);try{let t;ei("contacting");let l=await(0,W.askGrounded)({chatId:e.id,content:n,modelId:r},i);if(t=e.id,F.current!==t)return"completed";if(i.aborted)return"cancelled";I(l),R(void 0);let[a,o]=await Promise.all([(0,W.fetchChatMessages)(e.id,e.projectPath),(0,W.fetchChats)(e.projectPath)]),s=o.chats.find(t=>t.id===e.id);return d(e=>({...e,messages:Array.from(a.messages),chats:t0(o.chats),activeChat:null!=s?s:e.activeChat})),void 0!==s&&t6(s),"completed";}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return S(tZ(e)),d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed";}},[ei]),ew=(0,r.useCallback)(()=>{var e;tJ(x.current)&&(null==(e=C.current)||e.abort(),C.current=null,b(void 0),ei("cancelled"));},[ei]),ey=(0,r.useCallback)(async e=>{var t;if(tJ(x.current))return;let n=(null!=(t=null==e?void 0:e.text)?t:f).trim(),l=c.activeChat,r=c.activeProject,i=t7(c.selectedModel,c.models);if(0===n.length||void 0===l||void 0===r||void 0===i)return;if(t9(l)&&_.length>0)return void S("Attachments are not supported for grounded chats. Remove the attachment or switch to a non-grounded chat.");let a={id:`local-${String(Date.now())}`,chatId:l.id,role:"user",content:n,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};ei("queued"),m(""),S(void 0),d(e=>({...e,messages:[...e.messages,a]}));let o=new AbortController();C.current=o,R(void 0);try{let e=t9(l),{entries:t,disclosures:s}=e?{entries:[],disclosures:[]}:await Z(),c=e?[]:Q(),d=e?await ev(l,r,n,a.id,i,o.signal):await eg(l,r,n,a.id,i,o.signal,t,c);"cancelled"===x.current||ei(d),"completed"===d&&(H(),V(s));}finally{C.current=null;}},[f,c.activeChat,c.activeProject,c.selectedModel,c.models,_,ev,eg,Z,Q,H,ei]),eb=(0,r.useCallback)(async e=>{if(tJ(x.current))return;let t=c.activeChat,n=c.activeProject,l=t7(c.selectedModel,c.models);if(void 0===t||void 0===n||void 0===l)return;ei("queued"),b(e),S(void 0),I(void 0),R(void 0);let r=new AbortController();C.current=r;try{ei("contacting");let i=await(0,W.regenerateDesktopChat)({chatId:t.id,projectPath:n.path,assistantMessageId:e,modelId:l,memory:et(t,n)},r.signal);if(r.signal.aborted)return void ei("cancelled");let a=i.messages.find(t=>t.id===e);d(t=>({...t,activeChat:i.chat,chats:t0([i.chat,...t.chats.filter(e=>e.id!==i.chat.id)]),messages:void 0===a?t.messages:t.messages.map(t=>t.id===e?a:t)})),t6(i.chat),R(i.memory),ei("completed");}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return void ei("cancelled");S(tZ(e)),ei("failed");}finally{C.current=null,b(void 0);}},[c.activeChat,c.activeProject,c.selectedModel,c.models,et,ei]),ek=(0,r.useCallback)(async e=>{var t,n,l;let r=c.activeChat;if(void 0===r||0===e.length)return;let i=null!=(t=null==(n=c.activeProject)?void 0:n.path)?t:r.projectPath,a=t7(c.selectedModel,c.models);try{let t,n=await tQ({chatId:r.id,projectPath:i,messages:e,...(void 0===a?{}:{modelId:a}),memory:et(r,null!=(l=c.activeProject)?l:{path:i})});if(!z.current)return;t6(n.chat),t=r.id,F.current===t&&void 0!==n.memory&&R(n.memory),d(e=>{var t;let l=(null==(t=e.activeChat)?void 0:t.id)===r.id,i=new Set(e.messages.map(e=>e.id)),a=l?n.messages.filter(e=>!i.has(e.id)):[],o=t0([n.chat,...e.chats.filter(e=>e.id!==n.chat.id)]);return{...e,activeChat:l?n.chat:e.activeChat,chats:o,messages:[...e.messages,...a]};});}catch(e){S(tZ(e));}},[et,c.activeChat,c.activeProject,c.models,c.selectedModel]),ex=(0,r.useCallback)(async(e,t)=>{var n;let l,r=c.activeChat;if(void 0===r)throw Error("No active chat is available for grounded voice.");let i=null!=(n=c.activeProject)?n:{path:r.projectPath},a=t7(c.selectedModel,c.models),o=await(0,W.runRealtimeGroundedTool)({chatId:r.id,projectPath:i.path,callId:e.callId,query:e.query,...(void 0===e.userTranscript?{}:{userTranscript:e.userTranscript}),...(void 0===a?{}:{modelId:a}),memory:et(r,i)},t);return z.current&&(l=r.id,F.current===l)&&(t6(o.chat),I(o.groundedAnswer),void 0!==o.memory&&R(o.memory),d(e=>{var t;if((null==(t=e.activeChat)?void 0:t.id)!==r.id)return e;let n=new Set(e.messages.map(e=>e.id)),l=o.messages.filter(e=>!n.has(e.id));return{...e,activeChat:o.chat,chats:t0([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages,...l]};})),o.toolOutput;},[et,c.activeChat,c.activeProject,c.models,c.selectedModel]),eC=(0,r.useCallback)(e=>{t6(e),d(t=>{var n;return{...t,chats:t.chats.map(t=>t.id===e.id?e:t),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.id?e:t.activeChat};});},[]),ej=(0,r.useCallback)(()=>{S(void 0);},[]),eS=!h&&void 0===t7(c.selectedModel,c.models);return(0,r.useMemo)(()=>({projects:c.projects,chats:c.chats,messages:c.messages,streamingAssistantMessage:u,models:c.models,activeProject:c.activeProject,activeChat:c.activeChat,selectedModel:c.selectedModel,noEligibleModels:eS,draft:f,loading:h,sending:k,sendStatus:v,regeneratingMessageId:y,error:j,clearError:ej,setDraft:m,setSelectedModel:eo,openNewChat:es,openProject:ec,openChat:ed,addProject:eu,sendMessage:ey,regenerateMessage:eb,appendVoiceTurn:ek,runRealtimeGroundedTool:ex,cancelSend:ew,replaceChat:eC,latestGrounded:N,cancelGrounded:ew,pendingAttachments:_,addPendingAttachment:Y,removePendingAttachment:X,clearPendingAttachments:H,lastSentDocuments:J,memoryEnabled:A,setMemoryEnabled:P,memoryBudgetTokens:M,setMemoryBudgetTokens:T,latestMemory:E,clearLatestMemory:ee,acceptMemoryCandidate:en,rejectMemoryCandidate:el,forgetMemoryAction:er}),[c.projects,c.chats,c.messages,u,c.models,c.activeProject,c.activeChat,c.selectedModel,eS,f,h,k,v,y,j,ej,eo,es,ec,ed,eu,ey,eb,ek,ex,ew,eC,N,ew,_,Y,X,H,J,A,P,M,T,E,ee,en,el,er]);}({autoCreate:!1}),_=function(){var e,t,n,l;let[i,a]=(0,r.useReducer)(S,j),o=(0,r.useRef)(null),s=(0,r.useRef)(0),c=(0,r.useCallback)(async e=>{let t=o.current,[n,l]=await Promise.all([v(),null===t||0===t.length?Promise.resolve([]):g(t).catch(()=>[])]);s.current===e&&a({kind:"settle",instances:l,active:n});},[]),d=(0,r.useCallback)(async e=>{void 0!==e&&(o.current=e);let t=s.current+=1;a({kind:"load-start"});try{await c(t);}catch(e){if(s.current!==t)return;a({kind:"fail",error:N(e)});}},[c]),u=(0,r.useCallback)(async e=>{let t=s.current+=1;a({kind:"mutate-start"});try{if(await e(),s.current!==t)return;await c(t);}catch(e){if(s.current!==t)return;a({kind:"fail",error:N(e)});}},[c]),p=(0,r.useCallback)(e=>u(()=>w({workspaceId:e,requestedBy:C})),[u]),f=(0,r.useCallback)(()=>u(()=>y()),[u]),m=(0,r.useCallback)(e=>u(()=>b({workspaceId:e,requestedBy:C})),[u]),I=(0,r.useCallback)(e=>u(()=>k({workspaceId:e,requestedBy:C})),[u]),E=(0,r.useCallback)(e=>u(()=>x({workspaceId:e,requestedBy:C})),[u]),R=(0,r.useCallback)(e=>u(async()=>{o.current=e.root,await h({...e,requestedBy:C});}),[u]),A=null!=(e=null==(n=i.active)?void 0:n.binding)?e:null,P=null!=(t=null==(l=i.active)?void 0:l.instance)?t:null;return(0,r.useMemo)(()=>{var e;return{instances:i.instances,activeBinding:A,activeInstance:P,activeRoot:null!=(e=null==A?void 0:A.activeRoot)?e:null,loading:i.loading,switching:i.switching,error:i.error,refresh:d,switchTo:p,clearActive:f,pause:m,resume:I,prepareHandoff:E,provision:R};},[i.instances,i.loading,i.switching,i.error,A,P,d,p,f,m,I,E,R]);}(),J=(0,r.useRef)(null),V=(0,r.useRef)(null),[Y,X]=(0,r.useState)(tx.DEFAULT_GROUNDING_LIMITS);(0,r.useEffect)(()=>{(0,W.fetchConfig)().then(e=>X(e.effectiveGroundingLimits)).catch(()=>void 0);},[]);let H=_.refresh,Z=null==(s=B.activeProject)?void 0:s.path;(0,r.useEffect)(()=>{H(Z);},[H,Z]);let[Q,ee]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(null===Q)return;let e=window.setTimeout(()=>ee(null),1e4);return()=>window.clearTimeout(e);},[Q]);let et=(0,r.useCallback)((e,t)=>(ee(`Source limit reached — this chat already has ${String(e)} of ${String(t)} connected sources. Disconnect a source before connecting another.`),!1),[]),en=(0,r.useCallback)(e=>(ee(e),!1),[]),el=(0,r.useCallback)(e=>{var t,n,l;let r=function(e){if((null==e?void 0:e.type)!=="chat")return;let t=e.cfg.chatId;return"string"==typeof t&&t.length>0?t:void 0;}(null==(n=V.current)?void 0:n.find(t=>t.id===e));if(void 0===r)return;let i=null!=(t=B.chats.find(e=>e.id===r))?t:(null==(l=B.activeChat)?void 0:l.id)===r?B.activeChat:void 0;return(null==i?void 0:i.status)==="closed"?void 0:i;},[B.activeChat,B.chats]),er=(0,r.useCallback)(async function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=el(e);if(void 0===l)return en("Open a ready chat window before connecting a source.");let r=null===n?(0,eN.effectiveScopes)(l):(0,eN.removeConnectedScope)((0,eN.effectiveScopes)(l),n),i=(0,eN.effectiveLocalKnowledgeScopes)(l);if((0,eN.isScopeConnected)(r,t)){if(null!==n){let e=await(0,W.updateChatConnectedScopes)(l.id,r.length>0?r:null);B.replaceChat(e.chat);}return!0;}let a=(0,eN.totalSourceCap)(Y);if(r.length+i.length>=a)return et(r.length+i.length,a);let o={...t,connectedAtMs:Date.now()},s=(0,eN.appendConnectedScope)(r,o,Y.maxConnectedSources);if(null===s)return en("Choose a local folder before connecting it to chat.");if(s===r)return et(r.length+i.length,a);try{var c;let e=await(0,W.updateChatConnectedScopes)(l.id,s);B.replaceChat(e.chat),ee(null);let t=function(e){var t;if(void 0===e.root)return null;let n=null==(t=e.relativePaths[0])?void 0:t.replace(/\\/gu,"/").replace(/^\/+/u,"");if(void 0===n||0===n.length)return e.root;let l=e.root.replace(/\\/gu,"/").replace(/\/+$/u,"");return`${l}/${n}`;}(o);return null!==t&&(c=l.id,0!==c.length&&0!==t.length&&(0,ng.createRelationship)({type:"reads-context",source:{kind:"chat",id:c},target:{kind:"workspace-path",id:t}},function(e,t){let n=0x811c9dc5,l=`${e}|${t}`;for(let e=0;e<l.length;e+=1)n=Math.imul(n^l.charCodeAt(e),0x1000193);return`rc-${(n>>>0).toString(36)}-${(65535&l.length).toString(36)}`;}(c,t)).catch(e=>{e instanceof ng.RelationshipApiError;})),!0;}catch{return en("Keiko could not connect that source. Check that it is still available and try again.");}},[el,B.replaceChat,Y,et,en]),ei=(0,r.useCallback)(async(e,t)=>er(e,t),[er]),ea=(0,r.useCallback)((e,t)=>{let n=el(e);if(void 0===n)return;let l=(0,eN.removeConnectedScope)((0,eN.effectiveScopes)(n),t);(0,W.updateChatConnectedScopes)(n.id,l.length>0?l:null).then(e=>{B.replaceChat(e.chat);}).catch(e=>{console.warn("[keiko] connected-scope unbind failed",e);});},[el,B.replaceChat]),eo=(0,r.useCallback)(async(e,t)=>{let n=el(e);if(void 0===n)return en("Open a ready chat window before connecting a source.");let l=(0,eN.effectiveLocalKnowledgeScopes)(n),r=(0,eN.effectiveScopes)(n);if((0,eN.isConnectorScopeConnected)(l,t))return!0;let i=(0,eN.totalSourceCap)(Y);if(r.length+l.length>=i)return et(r.length+l.length,i);let a=(0,eN.appendConnectorScope)(l,t,Y.maxLocalKnowledgeSources);if(a===l)return et(r.length+l.length,i);try{let e=await(0,W.updateChatLocalKnowledgeScopes)(n.id,a);return B.replaceChat(e.chat),ee(null),!0;}catch{return en("Keiko could not connect that knowledge source. Check that it is still available and try again.");}},[el,B.replaceChat,Y,et,en]),es=(0,r.useCallback)((e,t)=>{let n=el(e);if(void 0===n)return;let l="capsule"===t.kind?`capsule:${t.capsuleId}`:`set:${t.capsuleSetId}`,r=(0,eN.removeConnectorScope)((0,eN.effectiveLocalKnowledgeScopes)(n),l);(0,W.updateChatLocalKnowledgeScopes)(n.id,r.length>0?r:null).then(e=>{B.replaceChat(e.chat);}).catch(()=>void 0);},[el,B.replaceChat]),[ec,ed]=(0,r.useState)(tl.readWorkspaceCameraSmoothness);(0,r.useEffect)(()=>{let e=e=>{let t=e.detail;ed("number"==typeof t?t:0);};return window.addEventListener(tl.WORKSPACE_CAMERA_SMOOTHNESS_EVENT,e),()=>{window.removeEventListener(tl.WORKSPACE_CAMERA_SMOOTHNESS_EVENT,e);};},[]);let eu=function(e){var t,n;let l,i,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[o,s]=(0,r.useState)(null),[c,d]=(0,r.useState)(null),[u,p]=(0,r.useState)(!1),[f,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[v,w]=(0,r.useState)(eP),{cameraSmoothness:y=0,onScopeBind:b,onScopeUnbind:k,onConnectorBind:x,onConnectorUnbind:C}=a,j=(0,r.useRef)(b);j.current=b;let S=(0,r.useRef)(k);S.current=k;let N=(0,r.useRef)(x);N.current=x;let I=(0,r.useRef)(C);I.current=C;let E=(0,r.useCallback)((e,t)=>{var n,l;return null==(n=null==(l=j.current)?void 0:l.call(j,e,t))||n;},[]),R=(0,r.useCallback)((e,t)=>{var n;null==(n=S.current)||n.call(S,e,t);},[]),A=(0,r.useCallback)((e,t)=>{var n,l;return null==(n=null==(l=N.current)?void 0:l.call(N,e,t))||n;},[]),P=(0,r.useCallback)((e,t)=>{var n;null==(n=I.current)||n.call(I,e,t);},[]),M=(0,r.useRef)(3),T=(0,r.useRef)(null),z=(0,r.useRef)(!1),F=(0,r.useRef)(null),L=(0,r.useRef)(!1),W=(0,r.useCallback)(()=>{z.current=!0;},[]),$=(0,r.useRef)([]);$.current=null!=o?o:[];let O=(0,r.useRef)([]);O.current=f;let K=(0,r.useMemo)(()=>new Map((null!=o?o:[]).map(e=>[e.id,e])),[o]),q=(0,r.useMemo)(()=>new Map(f.map(e=>[e.id,e])),[f]),B=(0,r.useMemo)(()=>{let e=new Map();for(let t of f){let n=e.get(t.a);void 0===n?e.set(t.a,[t]):n.push(t);let l=e.get(t.b);void 0===l?e.set(t.b,[t]):l.push(t);}return e;},[f]),_=(0,r.useRef)(K);_.current=K;let G=(0,r.useRef)(q);G.current=q;let U=(0,r.useRef)(B);U.current=B;let J=(0,r.useRef)(null);J.current=h;let V=(0,r.useRef)(null),Y=(0,r.useRef)(()=>void 0),X=(0,r.useRef)(null),{viewRef:H,worldVP:Z,zoomTo:Q,fitView:ee,resetView:et,panBy:en,rect:el}=function(e){let{wsRef:t,view:n,cameraSmoothness:l,winsRef:i,setView:a,setWins:o}=e,s=(0,r.useRef)(n);s.current=n;let c=(0,r.useRef)(n);c.current=n;let d=(0,r.useRef)(null),u=(0,r.useRef)(1),p=(0,r.useRef)(90),f=(0,r.useRef)(null),m=(0,r.useRef)(null),h=(0,r.useRef)(n),g=(0,r.useRef)(n),v=(0,r.useRef)(0),w=(0,r.useRef)(null);null===w.current&&(w.current=eF(300));let y=(0,r.useCallback)(()=>{var e;null==(e=w.current)||e.schedule(()=>ez(eR,s.current));},[]),b=(0,r.useRef)(null),k=(0,r.useCallback)(()=>{let e=t.current;null!==e&&(e.dataset.viewActive="true",null!==b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null;let e=t.current;null!==e&&delete e.dataset.viewActive;},160));},[t]);(0,r.useEffect)(()=>()=>{null!==b.current&&clearTimeout(b.current);},[]),(0,r.useEffect)(()=>{let e=w.current;if(null===e)return;let t=()=>e.flush(),n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),e.flush();};},[]),(0,r.useEffect)(()=>()=>{null!==f.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(f.current),null!==m.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(m.current);},[]);let x=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:90,r=Math.min(100,Math.max(0,l*t));if(r<=0||"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){null!==m.current&&(window.cancelAnimationFrame(m.current),m.current=null),a(e);return;}let i=n+(280-n)*r/100,o="u">typeof performance&&"function"==typeof performance.now?performance.now():Date.now();if(h.current=null===m.current?c.current:e$(h.current,g.current,eW(Math.min(1,(o-v.current)/i))),g.current=e,v.current=o,null!==m.current)return;let s=e=>{let t=Math.min(1,Math.max(0,(e-v.current)/i)),n=eW(t);if(t>=1){m.current=null,a(g.current);return;}a(e$(h.current,g.current,n)),m.current=window.requestAnimationFrame(s);};m.current=window.requestAnimationFrame(s);},[l,a]),C=(0,r.useCallback)(()=>{null!==m.current&&"function"==typeof window.cancelAnimationFrame&&(window.cancelAnimationFrame(m.current),m.current=null,a(g.current),c.current=g.current);},[a]),j=(0,r.useCallback)(function(e){var t,n,l;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null!=(t=d.current)?t:s.current,o="function"==typeof e?e(i):e,c=null!=(n=r.smoothnessScale)?n:1,m=null!=(l=r.minDurationMs)?l:90;if(s.current=o,d.current=o,u.current=c,p.current=m,y(),k(),"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){d.current=null,a(o);return;}null===f.current&&(f.current=window.requestAnimationFrame(()=>{f.current=null;let e=d.current,t=u.current,n=p.current;d.current=null,u.current=1,p.current=90,null!==e&&x(e,t,n);}));},[x,y,k,a]);(0,r.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){var n,l,r;t.preventDefault();let i=(n=t.target)instanceof Element&&null!=(l=null==(r=n.closest(".window[data-window-id]"))?void 0:r.dataset.windowId)?l:null;if(null!==i){C(),o(e=>null===e?e:e.map(e=>{var n,l,r;let a,o;return e.id===i?(n=e,l=t.deltaY,(o=eT((a=null!=(r=n.zoom)?r:1)*Math.exp(-(.0015*l))))===a?n:{...n,zoom:o}):e;}));return;}let a=e.getBoundingClientRect(),c=s.current,d=eL(t),u=eM(c.zoom*Math.exp(-(.0015*d.y))),p=(t.clientX-a.left-c.x)/c.zoom,f=(t.clientY-a.top-c.y)/c.zoom;j({zoom:u,x:t.clientX-a.left-p*u,y:t.clientY-a.top-f*u});return;}let i=t.target;if(i instanceof Element&&null!==i.closest(".window"))return;t.preventDefault();let a=eL(t);j(e=>({...e,x:e.x-a.x,y:e.y-a.y}),{minDurationMs:0,smoothnessScale:0});};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n);};},[t,o,j,C]);let S=(0,r.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),N=(0,r.useCallback)(()=>{let e=S();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom};},[S]),I=(0,r.useCallback)(e=>{let t=S();if(null===t)return;let n=s.current,l=t.width/2,r=t.height/2,i=(l-n.x)/n.zoom,a=(r-n.y)/n.zoom,o=eM(e);j({zoom:o,x:l-i*o,y:r-a*o});},[S,j]),E=(0,r.useCallback)(()=>{let e=S();null!==e&&j(function(e,t){let n=e.filter(e=>!0!==e.minimized);if(0===n.length)return{zoom:1,x:0,y:0};let l=1/0,r=1/0,i=-1/0,a=-1/0;for(let e of n)l=Math.min(l,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.w),a=Math.max(a,e.y+e.h);let o=Math.max(1,i-l),s=Math.max(1,a-r),c=eM(Math.min(1,Math.max(1,t.width-144)/o,Math.max(1,t.height-144)/s)),d=l+o/2,u=r+s/2;return{zoom:c,x:Math.round(t.width/2-d*c),y:Math.round(t.height/2-u*c)};}(i.current,e));},[S,i,j]);return{viewRef:s,worldVP:N,zoomTo:I,fitView:E,resetView:(0,r.useCallback)(()=>j({zoom:1,x:0,y:0}),[j]),panBy:(0,r.useCallback)((e,t)=>j(n=>({...n,x:n.x+e,y:n.y+t}),{minDurationMs:0,smoothnessScale:0}),[j]),rect:S};}({wsRef:e,view:v,cameraSmoothness:y,winsRef:$,setView:w,setWins:s});!function(e){let{wsRef:t,setWins:n,setConns:l,zc:i,lastAppliedSerializedRef:a}=e;(0,r.useLayoutEffect)(()=>{if(null===t.current)return;let e=eD();a.current=eJ(e),eU(e,n,l,i);},[t,n,l,i,a]);}({wsRef:e,setWins:s,setConns:m,zc:M,lastAppliedSerializedRef:F}),function(e){let{setWins:t,setConns:n,zc:l,beforeApplyRemote:i,lastAppliedSerializedRef:a,suppressNextLocalPersistRef:o}=e;(0,r.useEffect)(()=>{let e=e=>{if(null!==e.storageArea&&e.storageArea!==window.localStorage||e.key!==eI&&e.key!==eE)return;let r=eD(),s=eJ(r);s!==a.current&&(a.current=s,i(),o.current=!0,eU(r,t,n,l));};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e);};},[t,n,l,i,a,o]);}({setWins:s,setConns:m,zc:M,beforeApplyRemote:W,lastAppliedSerializedRef:F,suppressNextLocalPersistRef:L}),function(e){let{wins:t,conns:n,setWins:l,setConns:i,zc:a,suppressNextPersistRef:o}=e,s=(0,r.useRef)(0),c=(0,r.useRef)(t);c.current=t;let d=(0,r.useRef)(n);d.current=n;let u=(0,r.useRef)(null);null===u.current&&(u.current=eF(300));let p=(0,r.useRef)(null),f=(0,r.useRef)(!1),m=(0,r.useRef)(null);null!==t&&t.length>0&&null===m.current&&(f.current=!0);let h="u"<typeof navigator||!0!==navigator.webdriver,g=(0,r.useCallback)(e=>{var t;let n=c.current;if(null===n)return;let l=eG(n,d.current);if(l.serialized===m.current){f.current=!1;return;}null==(t=p.current)||t.abort();let r="function"==typeof AbortController?new AbortController():null;p.current=r;let i=s.current;e_(l.wins,l.conns,{baseRevision:i,...(null!==r?{signal:r.signal}:{}),keepalive:e}).then(e=>{if((null==e?void 0:e.kind)==="conflict"){null!==e.revision&&e.revision>s.current&&(s.current=e.revision);return;}(null==e?void 0:e.kind)==="ok"&&(m.current=l.serialized,f.current=!1,e.revision>s.current&&(s.current=e.revision));});},[]),v=(0,r.useCallback)(e=>{var t,n;let r,c=(t=e.windows,n=e.connections,{wins:r=ej(t),conns:eS(n,r)});m.current=JSON.stringify({windows:c.wins,connections:c.conns}),f.current=!1,e.revision>s.current&&(s.current=e.revision),o.current=!0,eU(c,l,i,a);},[l,i,a,o]);(0,r.useEffect)(()=>{if(!h)return;let e=!1,t=null,n=async()=>{var t,n;let l=await eK(s.current);e||null===l||l.revision<=s.current||0===s.current&&0===l.windows.length&&(null!=(t=null==(n=c.current)?void 0:n.length)?t:0)>0||f.current||v(l);},l=()=>{null!==t&&(window.clearInterval(t),t=null);},r=()=>{"u">typeof document&&"hidden"===document.visibilityState?l():(n(),null===t&&(t=window.setInterval(()=>{n();},1500)));};return r(),document.addEventListener("visibilitychange",r),()=>{e=!0,l(),document.removeEventListener("visibilitychange",r);};},[v,h]),(0,r.useEffect)(()=>{var e;if(!h||null===t)return;if(o.current){o.current=!1;return;}let l=eG(t,n);if(null===m.current&&0===l.wins.length&&0===l.conns.length){m.current=l.serialized,f.current=!1;return;}if(l.serialized===m.current){f.current=!1;return;}f.current=!0,null==(e=u.current)||e.schedule(()=>g(!1));},[t,n,o,h,g]),(0,r.useEffect)(()=>{if(!h)return;let e=u.current,t=()=>{null==e||e.cancel(),g(!0);},n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&t();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),null==e||e.flush();};},[h,g]);}({wins:o,conns:f,setWins:s,setConns:m,zc:M,suppressNextPersistRef:z}),(0,r.useEffect)(()=>{if(null===o)return;let e=new Set(o.map(e=>e.id));m(t=>{let n=t.filter(t=>e.has(t.a)&&e.has(t.b));return n.length===t.length?t:n;});},[o,m]),t=()=>{if(null===o)return;if(L.current){L.current=!1;return;}let e=ej(o),t=eS(f,e);ez(eI,e),ez(eE,t),F.current=JSON.stringify({windows:e,connections:t});},n=[f,o],null===(l=(0,r.useRef)(null)).current&&(l.current=eF(300)),(i=(0,r.useRef)(t)).current=t,(0,r.useEffect)(()=>{var e;null==(e=l.current)||e.schedule(()=>i.current());},n),(0,r.useEffect)(()=>{let e=l.current;if(null===e)return;let t=()=>e.flush(),n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),e.flush();};},[]),function(e){let{setWins:t,rect:n,cancelConnectRef:l,snapRef:i}=e;(0,r.useEffect)(()=>{let e=e=>{var r,a,o,s;let c;if("Escape"===e.key)return void l.current();if(null!==(r=document.activeElement)&&("INPUT"===r.tagName||"TEXTAREA"===r.tagName||"SELECT"===r.tagName))return;let d=(c="u"<typeof document?null:document.activeElement)instanceof Element&&null!=(a=null==(o=c.closest(".window[data-window-id]"))?void 0:o.dataset.windowId)?a:null,u=eY[e.code];if((e.metaKey||e.ctrlKey)&&e.altKey&&void 0!==u){e.preventDefault(),null!==d&&t(e=>{var t,n;if(null===e||0===e.length)return e;let l=eX(e,d);if(null===l)return e;let r=(n=null!=(t=l.zoom)?t:1,"0"===u?1:"-"===u||"_"===u?eT(n-.1):eT(n+.1));return e.map(e=>e.id===l.id?{...e,zoom:r}:e);});return;}if(!/^Arrow/.test(e.key))return;if((e.metaKey||e.ctrlKey)&&e.altKey){let t=eV[e.key];e.preventDefault();let n=i.current;null!=t&&null!==n&&null!==d&&(n.setSnap(t),n.commitSnap(d));return;}let p=e.metaKey||e.ctrlKey,f=e.altKey;if(!p&&!f||(e.preventDefault(),null===d))return;let m=n();null!==m&&(s={key:e.key,shift:e.shiftKey},t(e=>{let t,n,l,r,i,a,o;if(null===e||0===e.length)return e;let c=eX(e,d);if(null===c)return e;let u=f?(t=s.shift?1:16,n=c.w,l=c.h,"ArrowRight"===s.key?n+=t:"ArrowLeft"===s.key?n-=t:"ArrowDown"===s.key?l+=t:"ArrowUp"===s.key&&(l-=t),n=Math.max((r=D.WIN_TYPES[c.type].min).w,Math.min(m.width,n)),l=Math.max(r.h,Math.min(m.height,l)),{x:c.x,y:c.y,w:n,h:l}):(i=s.shift?1:16,a=c.x,o=c.y,"ArrowRight"===s.key?a+=i:"ArrowLeft"===s.key?a-=i:"ArrowDown"===s.key?o+=i:"ArrowUp"===s.key&&(o-=i),{x:a=Math.max(-(c.w-120),Math.min(m.width-120,a)),y:o=Math.max(0,Math.min(m.height-38,o)),w:c.w,h:c.h});return e.map(e=>e.id===c.id?{...e,...u,max:!1}:e);}));};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[t,n,l,i]);}({setWins:s,rect:el,cancelConnectRef:Y,snapRef:X}),function(e){let{wsRef:t,viewRef:n,setWins:l}=e;(0,r.useEffect)(()=>{let e=t.current;if(null===e||"u"<typeof ResizeObserver)return;let r=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),r=n.current,i={x:-r.x/r.zoom,y:-r.y/r.zoom,w:t.width/r.zoom,h:t.height/r.zoom};l(e=>{let t;return null===e?e:(t=e.map(e=>function(e,t){if(e.max)return{...e,x:t.x,y:t.y,w:t.w,h:t.h};let n=Math.max(t.x-(e.w-120),Math.min(t.x+t.w-120,e.x)),l=Math.max(t.y,Math.min(t.y+t.h-38,e.y));return n===e.x&&l===e.y?e:{...e,x:n,y:l};}(e,i))).every((t,n)=>t===e[n])?e:t;});});return r.observe(e),()=>{r.disconnect();};},[t,n,l]);}({wsRef:e,viewRef:H,setWins:s});let er=(0,r.useMemo)(()=>(0,eN.makeMutations)({setWins:s,zc:M,worldVP:Z,winsRef:$}),[s,M,Z,$]),ei=(0,r.useMemo)(()=>(0,eN.makeLayoutActions)({setWins:s,worldVP:Z}),[s,Z]),ea=(0,r.useMemo)(()=>(0,eN.makeSnapActions)({setSnapPrev:d,snapZone:T,worldVP:Z,update:er.update}),[d,T,Z,er]);X.current=ea;let eo=(0,r.useMemo)(()=>(0,eN.makeConnectActions)({wsRef:e,viewRef:H,winsRef:$,connsRef:O,winsByIdRef:_,connsByIdRef:G,connsByEndpointRef:U,connectingRef:J,connectCleanupRef:V,focus:er.focus,setConns:m,setConnecting:g,onScopeBind:E,onScopeUnbind:R,onConnectorBind:A,onConnectorUnbind:P}),[e,H,$,O,_,G,U,J,V,er,m,g,E,R,A,P]);Y.current=eo.cancelConnect;let es=(0,r.useCallback)(e=>{let t=_.current.get(e);if(void 0!==t){var n,l,r,i;for(let a of null!=(n=U.current.get(e))?n:[]){let n=a.a===e?a.b:a.b===e?a.a:null;if(null===n)continue;let o=_.current.get(n);if(void 0===o)continue;let s=null!=(l=a.boundChatWindowId)?l:"chat"===t.type?t.id:"chat"===o.type?o.id:null,c=null!=(r=(0,eN.boundScopeOf)(a))?r:!0===a.boundScopeElided?null:(0,eN.filesChatBindScope)(t,o,Date.now());null!==c&&null!==s&&R(s,c);let d=null!=(i=(0,eN.boundConnectorScopeOf)(a))?i:(0,eN.connectorChatBind)(t,o);null!==d&&null!==s&&P(s,d);}}er.close(e);},[_,U,er,R,P]),ec=(0,r.useCallback)((e,t)=>{m(n=>n.map(n=>n.id===e?{...n,boundScopeKind:t.kind,...(void 0!==t.root?{boundRoot:t.root}:{}),...(void 0!==t.relativePaths[0]?{boundRelativePath:t.relativePaths[0]}:{})}:n));},[m]),ed=(0,r.useCallback)(()=>H.current,[H]);(0,r.useEffect)(()=>()=>{null!==V.current&&(V.current(),V.current=null);},[]);let eu=(0,r.useMemo)(()=>({add:er.add,openEditorFile:er.openEditorFile,toggleTool:er.toggleTool,focus:er.focus,close:es,minimize:er.minimize,restore:er.restore,maximize:er.maximize,update:er.update,setSnap:ea.setSnap,commitSnap:ea.commitSnap,tileAll:ei.tileAll,splitFront:ei.splitFront,cascade:ei.cascade,startConnect:eo.startConnect,confirmConnect:eo.confirmConnect,cancelConnect:eo.cancelConnect,removeConn:eo.removeConn,updateConnBoundScope:ec,connect:eo.connect,linkedFilesRoot:eo.linkedFilesRoot,linkedFilesContext:eo.linkedFilesContext,linkedAllFilesRoots:eo.linkedAllFilesRoots,linkedConnectorCapsuleIds:eo.linkedConnectorCapsuleIds,linkedConnectorCapsuleSetIds:eo.linkedConnectorCapsuleSetIds,linkedFigmaSnapshotRunIds:eo.linkedFigmaSnapshotRunIds,linkedFigmaSnapshotSources:eo.linkedFigmaSnapshotSources,linkedImageSources:eo.linkedImageSources,currentFilesContext:eo.currentFilesContext,zoomTo:Q,fitView:ee,resetView:et,panBy:en,rect:el,currentView:ed}),[er,ea,ei,eo,es,ec,ed,Q,ee,et,en,el]);return{wins:o,winsById:K,snapPrev:c,palOpen:u,setPalOpen:p,conns:f,connecting:h,view:v,api:eu};}(J,{cameraSmoothness:ec,onScopeBind:ei,onScopeUnbind:ea,onConnectorBind:eo,onConnectorUnbind:es});V.current=eu.wins,(0,r.useEffect)(()=>{if(null!==eu.wins)for(let t of eu.conns){var e;let n=eu.winsById.get(t.a),l=eu.winsById.get(t.b);if(void 0===n||void 0===l)continue;let r=null!=(e=t.boundChatWindowId)?e:"chat"===n.type?n.id:"chat"===l.type?l.id:null;if(null===r)continue;let i=(0,eN.filesChatBindScope)(n,l,Date.now());if(null===i)continue;let a=(0,eN.boundScopeOf)(t);lw(a)!==lw(i)&&er(r,i,a).then(e=>{e&&eu.api.updateConnBoundScope(t.id,i);});}},[er,eu.api,eu.conns,eu.wins,eu.winsById]);let[ep,ef]=(0,r.useState)(!1),[em,eh]=(0,r.useState)(null),[eg,ev]=(0,r.useState)(!1),[ew,ey]=(0,r.useState)(!1),eb=null!=(e=null==(d=eu.wins)?void 0:d.length)?e:0,ek=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(eu.wins),ex=(0,r.useMemo)(()=>function(e){if(null===e)return new Set();let t=new Set();for(let n of e)!0===D.WIN_TYPES[n.type].tool&&t.add(n.type);return t;}(eu.wins),[eu.wins]),eC=(0,r.useMemo)(()=>({active:ek,winCount:eb}),[ek,eb]),eA=(0,r.useMemo)(()=>(0,l.jsx)(z,{}),[]),eO=(0,r.useCallback)(()=>ef(!0),[]),eq=(0,r.useCallback)(()=>ef(!1),[]),eB=(0,r.useCallback)(()=>ey(e=>!e),[]),eH=(0,r.useCallback)(()=>ey(!1),[]),eZ=(0,r.useCallback)(e=>{eu.api.restore(e),ey(!1);},[eu.api]),eQ=(0,r.useCallback)(e=>{if(ef(!1),"connector"===e){let t=eu.api.add(e);null!==t&&lx(t);return;}eh(e);},[eu.api]),e0=(0,r.useCallback)(e=>{if(eh(null),null===em)return;let{__connectFilesId:t,...n}="editor"===em?function(e){let t="string"==typeof e.root?e.root.trim():"",n="string"==typeof e.file?e.file.trim():"";if(0===t.length)return e;let l=ly(t,n),r={...e,root:t},i=function(e,t,n){let l=[],r=t=>{let n=ly(e,t);null===n||0===n.length||l.includes(n)||l.push(n);};if(Array.isArray(t))for(let e of t)"string"==typeof e&&r(e);return n.length>0&&r(n),l;}(t,e.openFiles,null!=l?l:"");return null!==l&&l.length>0?r.file=l:delete r.file,i.length>0?r.openFiles=i:delete r.openFiles,r;}(e):e,l=eu.api.add(em,n);"agents"===em&&null!==l&&"string"==typeof t&&t.length>0&&eu.api.connect(l,t),null!==l&&lx(l);},[em,eu.api]),e1=(0,r.useCallback)(()=>eh(null),[]),e2=(0,r.useCallback)(()=>ev(!1),[]),e4=(0,r.useCallback)(()=>ev(!0),[]),e3=(0,r.useRef)(null),e5=(0,r.useCallback)(e=>{e3.current=e;},[]),e6=function(e){var t;let{apply:n}=e,l=null!=(t=e.limit)?t:100,[i,a]=(0,r.useState)(nb),o=(0,r.useRef)(n);o.current=n;let s=(0,r.useRef)(i);s.current=i;let c=(0,r.useCallback)(e=>{a(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>l?n.slice(n.length-l):n,redoStack:[]};});},[l]),d=(0,r.useCallback)(()=>{let e=s.current;if(0===e.undoStack.length)return;let t=e.undoStack[e.undoStack.length-1],n=function(e){switch(e.kind){case"ui.window.move":case"ui.window.resize":case"ui.window.zorder":case"ui.workspace.pan":case"ui.workspace.zoom":case"ui.workspace.fit":case"ui.panel.toggle":case"ui.selection.change":case"ui.tab.switch":return{...e,before:e.after,after:e.before};case"ui.window.close":return{...e,kind:"ui.window.open"};case"ui.window.open":return{...e,kind:"ui.window.close"};}}(t);a({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),o.current(n);},[]),u=(0,r.useCallback)(()=>{let e=s.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];a({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),o.current(t);},[]),p=(0,r.useCallback)(()=>{a(nb);},[]);return(0,r.useMemo)(()=>{let e=i.undoStack[i.undoStack.length-1],t=i.redoStack[i.redoStack.length-1];return{canUndo:i.undoStack.length>0,canRedo:i.redoStack.length>0,undoLabel:void 0!==e?nw(e):null,redoLabel:void 0!==t?nw(t):null,push:c,undo:d,redo:u,clear:p};},[i,c,d,u,p]);}({apply:(0,r.useCallback)(e=>{var t;return t=eu.api,void("ui.panel.toggle"===e.kind&&e.panel in D.WIN_TYPES&&t.toggleTool(e.panel));},[eu.api])}),e8=(0,r.useCallback)(e=>{if(!(e in D.WIN_TYPES))return;let t=ex.has(e);eu.api.toggleTool(e),e6.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t});},[eu.api,ex,e6]),e7=(0,r.useCallback)(()=>eQ("chat"),[eQ]),e9=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(e9.current||null===eu.wins)return;e9.current=!0;let e=window.location.pathname.replace(/\/+$/u,""),t="/relationships"===e?"relationships":"/local-knowledge"===e?"localKnowledge":null;null!==t&&(eu.wins.some(e=>e.type===t)||e8(t),window.history.replaceState(null,"","/"));},[eu.wins,e8]),function(e){var t;let{bindings:n,dispatch:l}=e,i=null!=(t=e.platform)?t:function(){if("u"<typeof navigator)return"other";let e=navigator.platform||"";return /Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other";}(),a=(0,r.useRef)(l);a.current=l;let o=(0,r.useMemo)(()=>function(e){let t=new Map();for(let n of e){let e=ny(n.chord),l=t.get(e);void 0!==l?l.push(n.commandId):t.set(e,[n.commandId]);}let n=[];for(let[,l]of t)if(l.length>1){let t=e.find(e=>l.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:l});}return n;}(n),[n]),s=(0,r.useMemo)(()=>n.filter(e=>function(e){for(let t of nv)if(ny(e)===ny(t))return!0;return!1;}(e.chord)),[n]);if(o.length>0)throw new nx(o);if(s.length>0)throw new nC(s);(0,r.useEffect)(()=>{function e(e){if(!function(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t;}(e.target)){for(let t of n)if(function(e,t,n){if(!(e.key.toLowerCase()===t.key.toLowerCase()||t.mod.includes("alt")&&/^[a-z]$/i.test(t.key)&&e.code===`Key${t.key.toUpperCase()}`))return!1;let l=function(e,t){let n=new Set();for(let l of e)"cmd"===l?n.add("mac"===t?"meta":"ctrl"):"ctrl"===l?n.add("ctrl"):"alt"===l?n.add("alt"):"shift"===l&&n.add("shift");return n;}(t.mod,n);return e.metaKey===l.has("meta")&&e.ctrlKey===l.has("ctrl")&&e.altKey===l.has("alt")&&e.shiftKey===l.has("shift");}(e,t.chord,i)){e.preventDefault(),a.current(t.commandId);return;}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);},[n,i]),(0,r.useMemo)(()=>({bindings:n,conflicts:o,reserved:s}),[n,o,s]);}({bindings:nS,dispatch:(0,r.useCallback)(e=>{var t;"undo"===e?e6.undo():"redo"===e?e6.redo():"focus-status"===e&&(null==(t=e3.current)||t.focus());},[e6])}),(0,r.useEffect)(()=>{let e=document.documentElement,t=()=>{e.setAttribute("data-input-modality","pointer");},n=t=>{t.metaKey||t.ctrlKey||t.altKey||"Tab"===t.key&&e.setAttribute("data-input-modality","keyboard");};return e.setAttribute("data-input-modality","pointer"),window.addEventListener("pointerdown",t,!0),window.addEventListener("mousedown",t,!0),window.addEventListener("keydown",n,!0),()=>{window.removeEventListener("pointerdown",t,!0),window.removeEventListener("mousedown",t,!0),window.removeEventListener("keydown",n,!0),e.removeAttribute("data-input-modality");};},[]);let te=(0,r.useMemo)(()=>function(e,t,n,l,r,i){let a=[];for(let e of lb){let t=D.WIN_TYPES[e];a.push({id:`new-${e}`,label:`New ${t.title}`,group:"Create",icon:t.icon,run:()=>n(e)});}for(let e of lk){let n=D.WIN_TYPES[e];a.push({id:`open-${e}`,label:`Open ${n.title}`,group:"Tools",icon:n.icon,run:()=>t(e)});}return a.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),a.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),a.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),a.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===l?"moon":"sun",run:r}),a.push({id:"undo",label:null!==i.undoLabel?`Undo: ${i.undoLabel}`:"Undo (window and panel changes only)",group:"Edit",icon:"back",shortcut:"⌘Z",run:i.undo}),a.push({id:"redo",label:null!==i.redoLabel?`Redo: ${i.redoLabel}`:"Redo (window and panel changes only)",group:"Edit",icon:"fwd",shortcut:"⇧⌘Z",run:i.redo}),a;}(eu.api,e8,eQ,M,T,e6),[eu.api,e8,eQ,M,T,e6]),tt=!B.loading&&void 0===B.error&&0===B.models.length,ta=(m=null==(u=B.activeProject)?void 0:u.name,B.loading?"Loading project…":void 0!==m&&m.trim().length>0?m:"No project selected"),to=void 0!==B.activeProject,ts=(null==(p=B.activeProject)?void 0:p.available)===!0,tc=(I={loading:B.loading,error:B.error,hasProject:to,projectAvailable:ts,noEligibleModels:B.noEligibleModels}).loading?"Loading shell…":void 0!==I.error?"Shell error":I.hasProject?I.projectAvailable?I.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",td=0===(A=(null!=(E=eu.wins)?E:[]).filter(e=>"review"===e.type)).length?"No review open":A.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review window open",tu=void 0!==(R=null==(f=B.activeChat)?void 0:f.branchLabel)&&R.trim().length>0?R:"No branch selected",tp=null!==eu.wins&&!B.loading&&!tt,tf=(0,r.useCallback)(()=>{let e=eu.api.add("updates",{entrypoint:"startup"});null!==e&&lx(e);},[eu.api]),tm=ep?(0,l.jsx)(tk,{types:D.WIN_TYPES,order:lb,onAdd:eQ,onClose:eq}):null,th=null!==em||eg||tt,tg=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=tg.current;null!==e&&(th?e.setAttribute("inert",""):e.removeAttribute("inert"));},[th]),(0,l.jsx)(o,{value:_,children:(0,l.jsx)(i.ChatSessionProvider,{value:B,children:(0,l.jsx)(L.WsContext.Provider,{value:eC,children:(0,l.jsx)(c,{children:(0,l.jsxs)("div",{className:"app",children:[(0,l.jsx)("a",{className:"skip-link",href:"#main",children:P("app.skipToContent")}),(0,l.jsx)("h1",{className:"visually-hidden",children:P("app.workspaceHeading")}),(0,l.jsx)(q,{openPalette:eO,openCommandPalette:e4,onTileAll:eu.api.tileAll,onSplitFront:eu.api.splitFront,onCascade:eu.api.cascade,contextControl:eA}),(0,l.jsxs)("div",{className:"mid",children:[tt?null:(0,l.jsx)(G,{openTools:ex,onTool:e8,onNewChat:e7,theme:M,onToggleTheme:T}),(0,l.jsxs)("div",{ref:tg,className:"stage",id:"main",tabIndex:-1,"aria-hidden":!!th||void 0,children:[(0,l.jsx)(tn,{ws:eu,wsRef:J,openPalette:eO,palette:tm,children:(0,l.jsx)(lv,{ready:tp,openUpdates:tf})}),null!==Q&&(0,l.jsxs)("div",{className:"source-limit-alert",role:"alert",children:[(0,l.jsx)("span",{children:Q}),(0,l.jsx)("button",{type:"button",className:"source-limit-alert-dismiss","aria-label":"Dismiss source connection notice",onClick:()=>ee(null),children:"×"})]})]}),tt?null:(0,l.jsx)(U,{openTools:ex,onTool:e8})]}),(0,l.jsx)(K,{winCount:eb,windows:null!=(a=eu.wins)?a:[],windowPaletteOpen:ew,onToggleWindowPalette:eB,onSelectWindow:eZ,onCloseWindowPalette:eH,mode:O.mode,selectedModel:B.selectedModel,projectName:ta,branchLabel:tu,shellStatusLabel:tc,evidenceStatusLabel:td,statusRef:e5}),null!==em&&(0,l.jsx)(tb,{type:em,types:D.WIN_TYPES,filesContext:eu.api.currentFilesContext(),onConfirm:e0,onClose:e1}),eg&&(0,l.jsx)(tr,{commands:te,onClose:e2}),tt?(0,l.jsx)(ti.GatewaySetupDialog,{}):null,(0,l.jsx)(lc,{})]})})})})});}function lj(){let[e,t]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{try{window.sessionStorage.removeItem("keiko.app-boot-recovery-reload-count");}catch{}t(!0);},[]),(0,r.useEffect)(()=>{!function(){if(!("u">typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).then(t=>{e.addEventListener("controllerchange",lp),null!==e.controller&&lf(t),t.addEventListener("updatefound",()=>{let n;n=t.installing,null!==n&&n.addEventListener("statechange",()=>{"installed"!==n.state||null!==e.controller&&lf(t);});});}).catch(e=>{});}catch{}}();},[]),e)?(0,l.jsx)($.I18nProvider,{children:(0,l.jsx)(F.TwinProvider,{children:(0,l.jsx)(lC,{})})}):(0,l.jsx)("div",{className:"app","aria-hidden":"true",children:(0,l.jsx)("div",{className:"app-boot",children:(0,l.jsx)("img",{className:"app-boot-logo",src:"/assets/keiko-logo.svg",alt:""})})});}e.s(["KeikoDesktop",0,function(){return(0,l.jsx)(lj,{});}],89199);}]);
|
|
7
|
+
${r}`;}(o.type,o.cfg),N=(0,r.useMemo)(()=>{var e,t,n,l,r;let i,a,s,c,u,p,f,m,h,g;return e=o.type,t=o.id,i=(0,O.receivesFilesContext)(e),a=(0,O.receivesFocusedFileContext)(e),s="quality"===e||"editor"===e,c=i?d.linkedFilesRoot(t):null,u=a?null==(n=d.linkedFilesContext(t))?void 0:n.activeFilePath:void 0,p="quality"===e||"promptEnhancer"===e?d.linkedAllFilesRoots(t):null!==c?[c]:eo,f=s?d.linkedConnectorCapsuleIds(t):eo,m=s?d.linkedConnectorCapsuleSetIds(t):eo,h="quality"===e?d.linkedFigmaSnapshotRunIds(t):eo,null===(g={linkedRoot:c,linkedFilePath:u,linkedRoots:p,linkedCapsuleIds:f,linkedCapsuleSetIds:m,linkedFigmaSnapshotRunIds:h,linkedFigmaSnapshotSources:"quality"===e?null==(l=d.linkedFigmaSnapshotSources)?void 0:l.call(d,t):void 0,linkedImageSources:"quality"===e?null==(r=d.linkedImageSources)?void 0:r.call(d,t):void 0}).linkedRoot&&void 0===g.linkedFilePath&&0===g.linkedRoots.length&&0===g.linkedCapsuleIds.length&&0===g.linkedCapsuleSetIds.length&&0===g.linkedFigmaSnapshotRunIds.length&&(void 0===g.linkedFigmaSnapshotSources||0===g.linkedFigmaSnapshotSources.length)&&(void 0===g.linkedImageSources||0===g.linkedImageSources.length)?es:g;},[d,o.type,o.id,p]),E=Math.round(Math.max(0,o.w-2)/C*1e3)/1e3,R=Math.round(Math.max(0,o.h-2)/C*1e3)/1e3,A=(0,r.useRef)(o.cfg);A.current=o.cfg;let P=(0,r.useCallback)(e=>{d.update(o.id,{cfg:{...A.current,...e}});},[d,o.id]),M=(0,r.useCallback)((e,t)=>d.add(e,t),[d]),T=(0,r.useCallback)(e=>d.openEditorFile(e),[d]),z=(0,r.useCallback)(e=>d.focus(e),[d]),F=(0,r.useCallback)(e=>d.restore(e),[d]),L=(0,r.useCallback)((e,t)=>d.update(e,t),[d]),W=function(e,t,n){if("chat"===e){let e=+(t<D.CHAT_MINI_W);return`chat:${String(+(t<640))}${String(+(t<520))}${String(+(t<360||n<320))}${String(e)}`;}let l=D.WIN_TYPES[e],r=+(t<l.tiny.w||n<l.tiny.h);return`gen:${String(r)}`;}(o.type,E,R),{mode:$,node:K}=(0,r.useMemo)(()=>function(e,t,n,r,i,a,o,s,c,d,u,p,f,m,h,g,v,w,y,b,k){let x=D.WIN_TYPES[t];if("chat"===t){let t=n<520,l=n<D.CHAT_MINI_W;return{mode:l?"mini":"full",node:x.render(i,{windowId:e,mini:l,minimalChat:n<360||r<320,compact:n<640,controlsNarrow:t,barCompact:n<520,workflowCompact:t,linkedRoot:a,linkedFilePath:o,linkedRoots:s,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:f,activeRoot:m,activeBinding:h,updateCfg:g,openWindow:v,focusWindow:w,restoreWindow:y,updateWindow:b,openEditorFile:k})};}return n<x.tiny.w||r<x.tiny.h?{mode:"tiny",node:(0,l.jsx)(er,{icon:x.icon,label:x.title})}:{mode:"full",node:x.render(i,{windowId:e,linkedRoot:a,linkedFilePath:o,linkedRoots:s,linkedCapsuleIds:c,linkedCapsuleSetIds:d,linkedFigmaSnapshotRunIds:u,linkedFigmaSnapshotSources:p,linkedImageSources:f,activeRoot:m,activeBinding:h,updateCfg:g,openWindow:v,focusWindow:w,restoreWindow:y,updateWindow:b,openEditorFile:k})};}(o.id,o.type,E,R,o.cfg,N.linkedRoot,N.linkedFilePath,N.linkedRoots,N.linkedCapsuleIds,N.linkedCapsuleSetIds,N.linkedFigmaSnapshotRunIds,N.linkedFigmaSnapshotSources,N.linkedImageSources,v,w,P,M,z,F,L,T),[o.id,o.type,o.cfg,W,N,v,w,P,M,z,F,L,T]),q=(0,r.useCallback)(e=>d.update(o.id,{zoom:Math.max(.5,Math.min(2,Math.round(10*e)/10))}),[d,o.id]);(0,r.useEffect)(()=>{j.current!==S&&(j.current=null);},[S]);let B=(0,r.useCallback)(()=>{null!==S&&(j.current=S);},[S]);(0,r.useEffect)(()=>{if(!ei(o.type,o.cfg)||o.max||"full"!==$||null===S)return;let e=k.current;if(null===e)return;let t=null,n=()=>{if(t=null,j.current===S)return;let n=e.scrollHeight-e.clientHeight;if(n<=8)return;let l=Math.ceil(o.h+n);l<=o.h+8||d.update(o.id,{h:l});},l=()=>{null===t&&(t="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(n):window.setTimeout(n,0));};l();let r="u">typeof ResizeObserver?new ResizeObserver(l):null;null==r||r.observe(e);let i=e.firstElementChild;return null!==i&&(null==r||r.observe(i)),()=>{null!==t&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(t):window.clearTimeout(t)),null==r||r.disconnect();};},[d,$,S,o.cfg,o.h,o.id,o.max,o.type]),(0,r.useEffect)(()=>()=>{var e;null==(e=x.current)||e.call(x),x.current=null;},[]);let _=(0,r.useCallback)(e=>{(0,X.isTextEntryTarget)(e)?window.setTimeout(()=>d.focus(o.id),180):(0,X.isInteractiveControlTarget)(e)?window.setTimeout(()=>d.focus(o.id),0):d.focus(o.id);},[d,o.id]),G=(0,r.useCallback)(e=>{var t,n,l,r,i,a,s,p;let f,m,h,g,v,w,y,k,x,j,C,S,N,I;if(!(0,X.isWindowDragPointer)(e)||"valid"===c)return;e.preventDefault(),_(e.target);let E=u.current;if(null===E)return;let R=(i=E.getBoundingClientRect(),{z:f=(a=d.currentView()).zoom,vpx0:-a.x/f,vpy0:-a.y/f,vpw:i.width/f,vph:i.height/f,toWX:e=>(e-i.left-a.x)/f,toWY:e=>(e-i.top-a.y)/f}),A=o.max,P=A?null!=(t=null==(l=o.prev)?void 0:l.w)?t:480:o.w,M=A?null!=(n=null==(r=o.prev)?void 0:r.h)?n:360:o.h,T=A?P/2:R.toWX(e.clientX)-o.x,z=A?18:R.toWY(e.clientY)-o.y;A&&d.update(o.id,{max:!1,w:P,h:M}),b(!0),s={winId:o.id,offX:T,offY:z,W:P},p=()=>b(!1),h=30/R.z,g=0,v=0,w=null,y=!1,k=null,x=null,j=null,C=()=>{j=null,y&&(y=!1,w!==m&&(m=w,d.setSnap(w)),(g!==k||v!==x)&&(k=g,x=v,d.update(s.winId,{x:g,y:v})));},S=e=>{let t,n,l,r,i=R.toWX(e.clientX),a=R.toWY(e.clientY),o=i-s.offX,c=a-s.offY;o=Math.max(R.vpx0-(s.W-120),Math.min(R.vpx0+R.vpw-120,o)),c=Math.max(R.vpy0,Math.min(R.vpy0+R.vph-38,c)),g=o,v=c,t=i-R.vpx0<h,n=R.vpx0+R.vpw-i<h,l=a-R.vpy0<h,r=R.vpy0+R.vph-a<h,w=l&&t?"tl":l&&n?"tr":r&&t?"bl":r&&n?"br":t?"left":n?"right":l?"maxi":null,y=!0,null===j&&(j="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(C):window.setTimeout(C,0));},N=()=>{window.removeEventListener("pointermove",S),window.removeEventListener("pointerup",N),window.removeEventListener("pointercancel",N),null!==j&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(j):window.clearTimeout(j),j=null),C(),d.commitSnap(s.winId),I(),null==p||p();},I=(0,X.acquireGrabbingBodyStyle)(),window.addEventListener("pointermove",S),window.addEventListener("pointerup",N),window.addEventListener("pointercancel",N);},[d,o.id,o.x,o.y,o.w,o.h,o.max,o.prev,u,c,_]),U=(0,r.useCallback)(e=>t=>{var n;if(!(0,X.isPrimaryActivationPointer)(t))return;t.preventDefault(),t.stopPropagation(),null==(n=x.current)||n.call(x),x.current=null,d.focus(o.id);let l={x:o.x,y:o.y,w:o.w,h:o.h},r=l,i=t.clientX,a=t.clientY,s=d.currentView().zoom,c=document.body.style.cursor,u=!0,p=null,f=null,m=()=>{if(f=null,null===p)return;let e=p;p=null,ea(r,e)||(r=e,d.update(o.id,{...e,max:!1}));},h=function(){let e=arguments.length>0&&void 0!==arguments[0]&&arguments[0];u&&(u=!1,window.removeEventListener("pointermove",v),window.removeEventListener("pointerup",g),window.removeEventListener("pointercancel",g),window.removeEventListener("blur",g),e?null!==p&&null===f&&(f="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(m):window.setTimeout(m,0)):(null!==f&&("function"==typeof window.cancelAnimationFrame?window.cancelAnimationFrame(f):window.clearTimeout(f),f=null),p=null),document.body.style.cursor=c,x.current===h&&(x.current=null));},g=()=>{h(!0);},v=t=>{var n;!u||(0===t.buttons?h(!0):(n=function(e,t,n,l,r){let{x:i,y:a,w:o,h:s}=e;t.includes("e")&&(o=e.w+n),t.includes("s")&&(s=e.h+l),t.includes("w")&&(o=e.w-n,i=e.x+n),t.includes("n")&&(s=e.h-l,a=e.y+l);let c=D.WIN_TYPES[r].min,d=c.w>0?c.w:240,u=c.h>0?c.h:150;return o<d&&(t.includes("w")&&(i-=d-o),o=d),s<u&&(t.includes("n")&&(a-=u-s),s=u),{x:i,y:a,w:o,h:s};}(l,e,(t.clientX-i)/s,(t.clientY-a)/s,o.type),null!==p&&ea(p,n)||null===p&&ea(r,n)||(B(),p=n,null===f&&(f="function"==typeof window.requestAnimationFrame?window.requestAnimationFrame(m):window.setTimeout(m,0)))));};document.body.style.cursor="n"===e||"s"===e?"ns-resize":"e"===e||"w"===e?"ew-resize":"ne"===e||"sw"===e?"nesw-resize":"nwse-resize",window.addEventListener("pointermove",v),window.addEventListener("pointerup",g),window.addEventListener("pointercancel",g),window.addEventListener("blur",g),x.current=h;},[d,o.id,o.x,o.y,o.w,o.h,o.type,B]),J=(0,r.useCallback)((e,t)=>{let n=e.getBoundingClientRect();d.startConnect(o.id,{clientX:"clientX"in t?t.clientX:n.left+n.width/2,clientY:"clientY"in t?t.clientY:n.top+n.height/2,preventDefault:()=>t.preventDefault(),stopPropagation:()=>t.stopPropagation()});},[d,o.id]),V=(0,r.useCallback)(e=>{(0,X.isPrimaryActivationPointer)(e)&&(e.preventDefault(),e.stopPropagation(),J(e.currentTarget,e));},[J]),Y=(0,r.useCallback)(e=>{if("Enter"===e.key||" "===e.key||"Spacebar"===e.key){if("valid"===c)return void d.confirmConnect(o.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});e.preventDefault(),e.stopPropagation(),J(e.currentTarget,e);}},[J,c,d,o.id]),H=(0,r.useCallback)(()=>{let e=s?null:document.querySelector('.window[data-top="true"]');requestAnimationFrame(()=>{var t,n,l;let r=null!=(t=null!=(n=null!=(l=null!==e&&e.isConnected?e:null)?l:document.querySelector('.window[data-top="true"]'))?n:document.querySelector(".ws-fab"))?t:document.querySelector(".window[data-window-id]");null==r||r.focus({preventScroll:!0});});},[s]),Z=(0,r.useCallback)(()=>{d.close(o.id),H();},[d,o.id,H]),Q=(0,r.useCallback)(()=>{d.minimize(o.id),H();},[d,o.id,H]),ee=(0,r.useCallback)(e=>{e.target!==e.currentTarget||"valid"!==c||"Enter"===e.key&&d.confirmConnect(o.id,{preventDefault:()=>e.preventDefault(),stopPropagation:()=>e.stopPropagation()});},[d,o.id,c]),et="full"===$?(0,O.subText)(o.type,o.cfg):null,ec="full"===$&&E>=340,ed="full"===$&&"editor"!==o.type,eu=(0,r.useMemo)(()=>ed?{contain:"layout style paint",contentVisibility:"auto",containIntrinsicSize:`${String(Math.round(E))}px ${String(Math.round(R))}px`}:{contain:"layout style paint"},[ed,E,R]),ep=(0,r.useMemo)(()=>({left:0,top:0,width:o.w,height:o.h,zIndex:o.z,transform:`translate3d(${String(o.x)}px, ${String(o.y)}px, 0)`}),[o.x,o.y,o.w,o.h,o.z]),ef=(0,r.useMemo)(()=>({width:E,height:R,transform:`scale(${String(C)})`,transformOrigin:"0 0"}),[E,R,C]);return(0,l.jsxs)("section",{className:"window","aria-label":null!==et?`${f.title} — ${et}`:f.title,"aria-roledescription":"window","data-top":s?"true":"false","data-max":o.max?"true":"false","data-conn":null!=c?c:void 0,"data-dragging":y?"true":void 0,"data-window-id":o.id,style:ep,tabIndex:-1,onPointerDown:e=>{"valid"===c&&d.confirmConnect(o.id,e),_(e.target);},onKeyDown:ee,onFocusCapture:()=>{s||window.setTimeout(()=>d.focus(o.id),0);},children:[(0,l.jsx)("div",{className:"win-frame-clip",children:(0,l.jsxs)("div",{className:"win-content-zoom",style:ef,children:[(0,l.jsxs)("header",{className:"win-head",onPointerDown:G,onDoubleClick:e=>{(function(e){let t=e.target;if(t instanceof Element&&null!==t.closest("button,[role='button']"))return!1;let n=e.currentTarget.getBoundingClientRect(),l=Math.min(210,n.width/2);return e.clientX<n.right-l;})(e)&&d.maximize(o.id);},children:[(0,l.jsx)("span",{className:"win-ico",style:{color:!0===f.accent?"var(--accent)":"var(--fg-muted)"},children:(0,l.jsx)(h,{size:14})}),(0,l.jsx)("span",{className:"win-title",children:f.title}),null!==et?(0,l.jsx)("span",{className:"win-sub mono",title:et,children:(0,l.jsx)("span",{className:"win-sub-text",children:et})}):null,(0,l.jsx)("span",{className:"spacer"}),ec?(0,l.jsxs)("div",{className:"win-zoom",children:[(0,l.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content out","aria-label":`Zoom ${f.title} content out`,disabled:C<=.5,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>q(C-.1),children:(0,l.jsx)(I.Icons.zoomOut,{size:13})}),(0,l.jsxs)("button",{type:"button",className:"win-zpct ui-tip","data-tip":"Reset content zoom to 100%","aria-label":`${String(Math.round(100*C))}% — reset ${f.title} content zoom`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>d.update(o.id,{zoom:1}),children:[Math.round(100*C),"%"]}),(0,l.jsx)("button",{type:"button",className:"win-zbtn ui-tip","data-tip":"Zoom content in","aria-label":`Zoom ${f.title} content in`,disabled:C>=2,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>q(C+.1),children:(0,l.jsx)(I.Icons.zoomIn,{size:13})})]}):null,(0,l.jsxs)("div",{className:"win-traffic",role:"group","aria-label":`${f.title} window controls`,children:[(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-minimize ui-tip","data-tip":"Minimize","aria-label":`Minimize ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:Q,children:(0,l.jsx)(I.Icons.minimize,{size:17})}),(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-maximize ui-tip","data-tip":o.max?"Restore":"Full screen","aria-label":o.max?`Restore ${f.title} window`:`Full screen ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:()=>d.maximize(o.id),children:o.max?(0,l.jsx)(I.Icons.restore,{size:17}):(0,l.jsx)(I.Icons.maximize,{size:17})}),(0,l.jsx)("button",{type:"button",className:"win-traffic-btn win-traffic-close ui-tip","data-tip":"Close","aria-label":`Close ${f.title} window`,onPointerDown:e=>e.stopPropagation(),onDoubleClick:e=>{e.stopPropagation();},onClick:Z,children:(0,l.jsx)(I.Icons.close,{size:17})})]})]}),(0,l.jsx)("div",{ref:k,className:"win-body","data-mode":$,style:eu,children:K})]})}),o.max?null:en.map(e=>(0,l.jsx)("div",{className:`wz wz-${e}`,"aria-hidden":"true",onPointerDown:U(e)},e)),!o.max&&m?el.map(e=>(0,l.jsx)("button",{type:"button",className:`win-port wp-${e}`,title:"Click to connect to another window","aria-label":`Connect ${f.title} from ${"t"===e?"top":"r"===e?"right":"b"===e?"bottom":"left"} edge`,onPointerDown:V,onKeyDown:Y},`p${e}`)):null]});}),ed=[/\bsk-[A-Za-z0-9_-]{20,}\b/,/\bAKIA[0-9A-Z]{16}\b/,/\bgh[pousr]_[A-Za-z0-9]{36,}\b/,/\bxox[abporsu]-[A-Za-z0-9-]{10,}\b/,/\beyJ[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\.[A-Za-z0-9_-]{8,}\b/,/-----BEGIN [A-Z ]*PRIVATE KEY-----/],eu=/\b(?:\d[ -]?){13,19}\b/g;var ep=e.i(7877);let ef=["apikey","accesskey","clientsecret","credential","password","privatekey","secret","token"],em=["api_key=","apikey=","client_secret=","clientsecret=","credential=","authorization:","password=","secret=","token="],eh=[".env",".env.local",".env.development",".env.test",".env.production"],eg={chat:["chatId"],editor:["openFiles","layoutJson"],files:["activeFilePath","activeDirectoryPath","resolvedRoot"],figma:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaView:["snapshotRunId","selectedScreenIdsJson","selectedScreenName"],figmaJson:["snapshotRunId","screenId","selectedScreenIdsJson","selectedScreenName"],figmaImage:["snapshotRunId","screenId","selectedScreenName","imageSrc"],pdfCitationPreview:["anchorQuality","currentPage","documentLabel","failureMessage","failureRetryable","failureTitle","pageLabel","pageNumber","rotation","sourceLabel","zoomMode","zoomValue"]};function ev(e){return"number"==typeof e&&Number.isFinite(e);}function ew(e){return"object"==typeof e&&null!==e&&!Array.isArray(e);}function ey(e){let t=e.trim();if(0===t.length)return!1;let n=t.toLowerCase();return function(e){for(let t of ed)if(t.test(e))return!0;for(let t of e.matchAll(eu)){let e=t[0].replaceAll(/[ -]/g,"");if(e.length>=13&&e.length<=19&&function(e){let t=0,n=!1;for(let l=e.length-1;l>=0;l-=1){let r=Number(e[l]);n&&(r*=2)>9&&(r-=9),t+=r,n=!n;}return t%10==0;}(e))return!0;}return!1;}(t)||function(e){let t="bearer ",n=e.toLowerCase().indexOf(t);if(-1===n)return!1;let l=0;for(let i=n+t.length;i<e.length;i+=1){var r;if(0===(null!=(r=e[i])?r:"").trim().length)break;l+=1;}return l>=8;}(t)||function(e){if(!e.includes("://"))return!1;try{let t=new URL(e);return t.username.length>0||t.password.length>0;}catch{return!1;}}(t)||em.some(e=>n.includes(e))||function(e){let t=e.toLowerCase().replaceAll("\\","/").split("/");for(let e=0;e<t.length;e+=1){var n,l;let r=null!=(n=t[e])?n:"",i=null!=(l=t[e+1])?l:"";if(eh.includes(r)||".npmrc"===r||"credentials.json"===r||".aws"===r&&"credentials"===i||".ssh"===r&&i.startsWith("id_"))return!0;}return!1;}(t);}function eb(e){if(0===e.length||e.length>256||e.startsWith(".")||e.trim()!==e||ey(e))return!1;for(let t of e)if(!function(e){let t=e.charCodeAt(0);return t>=48&&t<=57||t>=65&&t<=90||t>=97&&t<=122||46===t||95===t||45===t;}(t))return!1;return!0;}function ek(e){if(0===e.length||e.length>256||e.trim()!==e||ey(e))return!1;for(let t of e){let e=t.charCodeAt(0),n=e>=48&&e<=57,l=e>=65&&e<=90,r=e>=97&&e<=122,i=46===e||58===e||95===e||45===e;if(!n&&!l&&!r&&!i)return!1;}return!0;}function ex(e,t){let n,l;if("string"!=typeof e)return;let r=e.trim();if(!(0===r.length||r.length>t||ey(r)||(l=(n=r.trim()).replace(/\\/gu,"/"),/^file:/iu.test(n)||/^[A-Za-z]:\//u.test(l)||l.startsWith("/")||l.startsWith("~/")||l.includes("/Users/")||l.includes("/home/")||l.includes("/Volumes/")||l.includes("../"))))return r;}function ej(e){if(!Array.isArray(e)||0===e.length)return;let t=[];for(let n of e){if("string"!=typeof n)return;let e=n.trim().replace(/\\/gu,"/").replace(/^\/+/u,"");if(!(0===e.length||e.length>512||e.replace(/\\/gu,"/").split("/").some(e=>".."===e)||ey(e)||t.includes(e))&&(t.push(e),t.length>=64))break;}return t.length>0?t:void 0;}function eC(e){let t=[];for(let n of e){let e=function(e){var t;if(!ew(e)||!("string"==typeof(t=e.type)&&t in D.WIN_TYPES))return null;let n=e.type;if("transient"===ep.WIN_META[n].persistence||"string"!=typeof e.id||!ev(e.x)||!ev(e.y)||!ev(e.w)||!ev(e.h)||!ev(e.z)||"boolean"!=typeof e.max)return null;let l={id:e.id,type:n,x:e.x,y:e.y,w:e.w,h:e.h,z:e.z,cfg:function(e,t){var n,l;if(!ew(t)||"durable.config"===ep.WIN_META[e].persistence)return{};let r=new Set([...(null!=(n=D.WIN_TYPES[e].config)?n:[]).map(e=>e.key),...(null!=(l=eg[e])?l:[])]),i={};for(let[n,l]of Object.entries(t)){if(!r.has(n))continue;let t=function(e,t,n){let l;if("editor"===e&&"openFiles"===t)return ej(n);if("editor"===e&&"layoutJson"===t)return function(e){let t;if("string"!=typeof e||0===e.length)return;try{t=JSON.parse(e);}catch{return;}if("object"!=typeof t||null===t||Array.isArray(t))return;let n=t;if(2===n.schemaVersion||2===n.version){let e=ew(n.panes)?n.panes:{},t={};for(let[n,r]of Object.entries(e)){var l;if(!ew(r))continue;let e="string"==typeof r.activeFile?ej([r.activeFile]):void 0,i=null==e?void 0:e[0],a=ej(r.openFiles),o=null!=(l=ej(r.tabOrder))?l:a;if(void 0===a&&void 0===i)continue;let s=null!=a?a:e;if(void 0===s)continue;let c=void 0!==i&&s.includes(i)?i:s[0];t[n.slice(0,48)]={id:n.slice(0,48),activeFile:c,openFiles:s,tabOrder:null!=o?o:s};}let r=new Set(Object.keys(t)),i=e=>{if(!ew(e))return null;if("pane"===e.type&&"string"==typeof e.paneId&&r.has(e.paneId))return{type:"pane",paneId:e.paneId};if("split"===e.type){let t=i(e.first),n=i(e.second);if(null===t||null===n)return null;let l="number"==typeof e.ratio&&Number.isFinite(e.ratio)?Math.min(85,Math.max(15,Math.round(e.ratio))):50;return{type:"split",id:"string"==typeof e.id?e.id.slice(0,48):"split-1",direction:"column"===e.direction?"column":"row",ratio:l,first:t,second:n};}return null;},a=i(n.tree),o=Object.keys(t)[0];if(null===a||void 0===o)return;let s="string"==typeof n.activePaneId&&r.has(n.activePaneId)?n.activePaneId:o,c="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260;return JSON.stringify({schemaVersion:2,root:function(e){if("string"!=typeof e)return"";let t=e.trim();return 0===t.length||t.length>512||ey(t)?"":t;}(n.root),activePaneId:s,tree:a,panes:t,sidebarWidth:c,sidebarCollapsed:!0===n.sidebarCollapsed});}let r=Array.isArray(n.panes)?n.panes.slice(0,2):[],i=[];for(let[e,t]of r.entries()){if("object"!=typeof t||null===t||Array.isArray(t))return;let n="string"==typeof t.file?t.file.trim():"",l=ej(t.openFiles);if(n.length>512||ey(n))continue;let r=null!=l?l:n.length>0?ej([n]):void 0;void 0!==r&&i.push({id:"string"==typeof t.id&&t.id.trim().length>0?t.id.trim().slice(0,32):`pane-${e+1}`,file:n.length>0?n.replace(/\\/gu,"/").replace(/^\/+/u,""):r[0],openFiles:r});}if(0===i.length)return;let a="column"===n.direction?"column":"row",o="number"==typeof n.splitRatio&&Number.isFinite(n.splitRatio)?Math.min(75,Math.max(25,Math.round(n.splitRatio))):50,s="number"==typeof n.sidebarWidth&&Number.isFinite(n.sidebarWidth)?Math.min(440,Math.max(180,Math.round(n.sidebarWidth))):260,c="string"==typeof n.activePaneId&&i.some(e=>e.id===n.activePaneId)?n.activePaneId:i[0].id;return JSON.stringify({version:1,panes:i,activePaneId:c,direction:a,splitRatio:o,sidebarWidth:s,sidebarCollapsed:!0===n.sidebarCollapsed});}(n);if("pdfCitationPreview"===e)return"documentLabel"===t||"pageLabel"===t||"sourceLabel"===t?ex(n,240):"failureTitle"===t||"failureMessage"===t?ex(n,360):"currentPage"===t||"pageNumber"===t?Number.isInteger(n)&&"number"==typeof n&&n>0&&n<=1e5?n:void 0:"rotation"===t?"number"==typeof n&&Number.isFinite(n)?(90*Math.round(n/90)%360+360)%360:void 0:"zoomValue"===t?"number"==typeof n&&Number.isFinite(n)?Math.min(2,Math.max(.5,Math.round(10*n)/10)):void 0:"failureRetryable"===t?"boolean"==typeof n?n:void 0:"anchorQuality"===t?"page-only"===n||"approximate"===n||"unavailable"===n?n:void 0:"zoomMode"===t&&("fit-width"===n||"fit-page"===n||"manual"===n)?n:void 0;if("figma"===e||"figmaView"===e||"figmaJson"===e||"figmaImage"===e)return function(e,t){if("string"==typeof t){if("snapshotRunId"===e)return eb(t)?t:void 0;if("screenId"===e)return ek(t)?t:void 0;if("imageSrc"===e)return /^\/api\/figma\/snapshots\/[^/?#]+\/screens\/\d+\/image$/u.test(t)?t:void 0;if("selectedScreenIdsJson"===e){let e;try{e=JSON.parse(t);}catch{return;}if(!Array.isArray(e)||0===e.length||e.length>16)return;let n=[];for(let t of e){if("string"!=typeof t)return;let e=t.trim();if(!ek(e))return;n.push(e);}return JSON.stringify(n);}if("selectedScreenName"===e){if(t.length>256||ey(t))return;return t;}}}(t,n);if("string"!=typeof n&&"number"!=typeof n&&"boolean"!=typeof n||(l=function(e){let t="";for(let n of e.toLowerCase())(n>="a"&&n<="z"||n>="0"&&n<="9")&&(t+=n);return t;}(t),ef.some(e=>l.includes(e))))return;if("string"!=typeof n)return n;let r=ep.WIN_META[e].persistence;return"evidence-reference"===r?eb(n)?n:void 0:ey(n)?"durable.ui"===r?"[REDACTED]":void 0:n;}(e,n,l);void 0!==t&&(i[n]=t);}return i;}(n,e.cfg),max:e.max},r=function(e){if(ew(e)&&ev(e.x)&&ev(e.y)&&ev(e.w)&&ev(e.h))return{x:e.x,y:e.y,w:e.w,h:e.h};}(e.prev);return{...l,...(!0===e.minimized?{minimized:!0}:{}),...(void 0!==r?{prev:r}:{}),...(ev(e.zoom)?{zoom:Math.max(.5,Math.min(2,e.zoom))}:{})};}(n);null!==e&&t.push("figma"!==e.type||void 0===function(e){let t=e.selectedScreenIdsJson;if("string"==typeof t)try{let e=JSON.parse(t);if(!Array.isArray(e))return;let n=e[0];return"string"==typeof n&&n.length>0?n:void 0;}catch{return;}}(e.cfg)?e:{...e,type:"figmaView",cfg:{...e.cfg}});}let n=new Map();for(let e of t){if(!0!==D.WIN_TYPES[e.type].singleton)continue;let t=n.get(e.type);(void 0===t||e.z>t.z)&&n.set(e.type,e);}return t.filter(e=>!0!==D.WIN_TYPES[e.type].singleton||n.get(e.type)===e);}function eS(e,t){let n=new Set(t.map(e=>e.id)),l=[];for(let t of e){if("string"!=typeof t.id||"string"!=typeof t.a||"string"!=typeof t.b||!n.has(t.a)||!n.has(t.b))continue;let e=!0===t.boundScopeElided||"string"==typeof t.boundRoot||"string"==typeof t.boundScopeKind||"string"==typeof t.boundRelativePath,r="string"==typeof t.boundChatWindowId&&t.boundChatWindowId.length>0&&n.has(t.boundChatWindowId),i=("capsule"===t.boundConnectorKind||"capsule-set"===t.boundConnectorKind)&&"string"==typeof t.boundConnectorId&&t.boundConnectorId.length>0;l.push({id:t.id,a:t.a,b:t.b,...(r?{boundChatWindowId:t.boundChatWindowId}:{}),...(e?{boundScopeElided:!0}:{}),...(i?{boundConnectorKind:t.boundConnectorKind,boundConnectorId:t.boundConnectorId}:{})});}return l;}var eN=e.i(68611);let eI="keiko.workspace.v4",eE="keiko.conns.v1",eR="keiko.view",eA="/api/workspace/state";function eP(){try{let e=window.localStorage.getItem(eR);if(null===e)return{zoom:1,x:0,y:0};let t=JSON.parse(e);if("object"==typeof t&&null!==t&&"zoom"in t&&"number"==typeof t.zoom)return{zoom:Number.isFinite(t.zoom)?eM(t.zoom):1,x:"number"==typeof t.x&&Number.isFinite(t.x)?t.x:0,y:"number"==typeof t.y&&Number.isFinite(t.y)?t.y:0};}catch{}return{zoom:1,x:0,y:0};}function eM(e){return Math.max(.3,Math.min(2.5,e));}function eT(e){return Math.max(.5,Math.min(2,Math.round(10*e)/10));}function ez(e,t){try{window.localStorage.setItem(e,JSON.stringify(t));}catch{}}function eF(e){let t=null,n=null,l=()=>{null!==t&&(clearTimeout(t),t=null);let e=n;n=null,null!==e&&e();};return{schedule:r=>{n=r,null!==t&&clearTimeout(t),t=setTimeout(l,e);},flush:l,cancel:()=>{null!==t&&(clearTimeout(t),t=null),n=null;}};}function eL(e){let t=e.deltaMode===WheelEvent.DOM_DELTA_LINE?16:2===e.deltaMode?800:1;return{x:e.deltaX*t,y:e.deltaY*t};}function eW(e){return 1-Math.pow(1-e,3);}function e$(e,t,n){return{zoom:e.zoom+(t.zoom-e.zoom)*n,x:e.x+(t.x-e.x)*n,y:e.y+(t.y-e.y)*n};}function eD(){let e=null;try{e=function(e){if(null===e)return null;try{let t=JSON.parse(e);if(!Array.isArray(t)||0===t.length)return null;let n=eC(t);return n.length>0?n:null;}catch{return null;}}(window.localStorage.getItem(eI));}catch{e=null;}let t=null!=e?e:[];try{return{wins:t,conns:function(e,t){if(null===e)return[];try{let n=JSON.parse(e);if(!Array.isArray(n))return[];return eS(n,t);}catch{return[];}}(window.localStorage.getItem(eE),t)};}catch{return{wins:t,conns:[]};}}function eO(e){return`"workspace-state-${String(e)}"`;}async function eK(e){if("function"!=typeof fetch)return null;try{let t={Accept:"application/json"};t["If-None-Match"]=eO(e);let n=await fetch(eA,{headers:t});if(304===n.status||!n.ok)return null;let l=await n.json();if("object"!=typeof l||null===l||!("workspace"in l))return null;let r=l.workspace;if("object"!=typeof r||null===r||"number"!=typeof r.revision||!Array.isArray(r.windows)||!Array.isArray(r.connections))return null;return{revision:r.revision,windows:r.windows,connections:r.connections};}catch{return null;}}function eq(e){return"function"==typeof Blob?new Blob([e]).size:"function"==typeof TextEncoder?new TextEncoder().encode(e).length:unescape(encodeURIComponent(e)).length;}let eB=0;async function e_(e,t,n){var l,r;if("function"!=typeof fetch)return null;let i=JSON.stringify({windows:e,connections:t}),a=!0===n.keepalive;a&&eq(i)>61440&&(l=eq(i),eB+=1,"u">typeof console&&"function"==typeof console.warn&&console.warn(`workspace-state: keepalive body ${String(l)}B over budget; retrying without keepalive`),a=!1);try{let e=await fetch(eA,{method:"PUT",headers:{Accept:"application/json","Content-Type":"application/json","If-Match":eO(n.baseRevision),"X-Keiko-CSRF":"1"},body:i,...(a?{keepalive:!0}:{}),...(void 0!==n.signal?{signal:n.signal}:{})});if(412===e.status||428===e.status){let t;return{kind:"conflict",revision:(r=e.headers.get("etag"),t=/^"workspace-state-(\d+)"$/u.exec(null!=r?r:""),null===t?null:Number.parseInt(t[1],10))};}if(!e.ok)return null;let t=await e.json(),l="object"==typeof t&&null!==t&&"workspace"in t?t.workspace:void 0;if("object"!=typeof l||null===l)return null;let o=l.revision;return"number"==typeof o?{kind:"ok",revision:o}:null;}catch{return null;}}function eG(e,t){let n=eC(e),l=eS(t,n);return{wins:n,conns:l,serialized:JSON.stringify({windows:n,connections:l})};}function eU(e,t,n,l){l.current=e.wins.reduce((e,t)=>Math.max(e,t.z),1),t(e.wins),n(e.conns);}function eJ(e){let t=eC(e.wins);return JSON.stringify({windows:t,connections:eS(e.conns,t)});}let eV={ArrowLeft:"left",ArrowRight:"right",ArrowUp:"maxi",ArrowDown:null},eY={Equal:"=",NumpadAdd:"+",Minus:"-",NumpadSubtract:"-",Digit0:"0",Numpad0:"0"};function eX(e,t){if(null!==t){let n=e.find(e=>e.id===t);return void 0!==n&&!0!==n.minimized?n:null;}let n=null;for(let t=0;t<e.length;t++){let l=e[t];if(!0!==l.minimized){if(null===n){n=l;continue;}l.z>n.z&&(n=l);}}return n;}var eH=e.i(18004),eZ=e.i(98408),eQ=e.i(19047),e0=e.i(89860),e1=e.i(18138);let e2=(0,J.default)(()=>e.A(27555).then(e=>e.WorkspaceShader),{loadableGenerated:{modules:[47865]},ssr:!1,loading:()=>null}),e4={w:260,h:220},e3={w:360,h:360},e5={w:520,h:540},e6={w:560,h:420};function e8(e){let{clientX:t,clientY:n,rect:l,view:r,size:i=e4}=e;return{x:Math.round((t-l.left-r.x)/r.zoom-i.w/2),y:Math.round((n-l.top-r.y)/r.zoom-28)};}function e7(e,t){let n=e+t;return e<1&&n>1||e>1&&n<1?1:n;}function e9(e,t,n){var l;t.preventDefault();let r=t.currentTarget;null==(l=r.setPointerCapture)||l.call(r,t.pointerId);let i=t.clientX,a=t.clientY,o=(0,X.acquireGrabbingBodyStyle)();n(!0);let s=t=>{e(t.clientX-i,t.clientY-a),i=t.clientX,a=t.clientY;},c=()=>{var e,l;window.removeEventListener("pointermove",s),window.removeEventListener("pointerup",c),window.removeEventListener("pointercancel",c),n(!1),(null==(e=r.hasPointerCapture)?void 0:e.call(r,t.pointerId))===!0&&(null==(l=r.releasePointerCapture)||l.call(r,t.pointerId)),o();};window.addEventListener("pointermove",s),window.addEventListener("pointerup",c),window.addEventListener("pointercancel",c);}function te(e){let{wins:t,connecting:n,conns:i}=e,[a,o]=(0,r.useState)(""),s=(0,r.useRef)(null),c=(0,r.useRef)(i.length);return(0,r.useEffect)(()=>{let e=s.current;s.current=n;let l=c.current;if(c.current=i.length,null===e&&null!==n){let e=null==t?void 0:t.find(e=>e.id===n.from),l=void 0!==e?D.WIN_TYPES[e.type].title:"window";o(`Connecting from ${l}. Tab to a highlighted window and press Enter on it or one of its connection ports to connect. Press Escape to cancel.`);return;}if(null!==e&&null===n)if(i.length>l){let e=i[i.length-1],n=void 0!==e?null==t?void 0:t.find(t=>t.id===e.a):void 0,l=void 0!==e?null==t?void 0:t.find(t=>t.id===e.b):void 0;o(void 0!==n&&void 0!==l?`Connected: ${(0,O.relLabel)(n,l)}`:"Connected");}else o("Connection cancelled");},[n,i,t]),(0,l.jsx)("div",{className:"sr-only","aria-live":"polite",children:a});}let tt=[];function tn(e){var t,n;let{ws:i,wsRef:a,openPalette:o,palette:s,children:c}=e,{wins:d,view:u,snapPrev:p,conns:f,connecting:m,api:h}=i,g=(0,r.useRef)(u);g.current=u;let[v,w]=(0,r.useState)(!1),[y,b]=(0,r.useState)(!1),k=(0,r.useRef)(!1),x=function(e){let[t,n]=(0,r.useState)(!1),l=(0,r.useRef)(e),i=(0,r.useRef)(null);return(0,r.useEffect)(()=>{e!==l.current&&(l.current=e,n(!0),null!==i.current&&clearTimeout(i.current),i.current=setTimeout(()=>n(!1),160));},[e]),(0,r.useEffect)(()=>()=>{null!==i.current&&clearTimeout(i.current);},[]),t;}(u.zoom),j=(0,r.useMemo)(()=>null===d?null:d.filter(e=>!0!==e.minimized),[d]),C=function(e,t){let n=(0,r.useRef)(0),l=(0,r.useRef)(null),{keys:i,cfgs:a}=(0,r.useMemo)(()=>null===e?{keys:"",cfgs:tt}:{keys:e.map(e=>`${e.id}:${e.type}`).join("|"),cfgs:e.map(e=>e.cfg)},[e]),o=l.current;return(null===o||o.conns!==t||o.keys!==i||o.cfgs.length!==a.length||a.some((e,t)=>e!==o.cfgs[t]))&&(n.current+=1,l.current={conns:t,keys:i,cfgs:a}),n.current;}(d,f),S=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(j),N=null!==m&&null!==j&&null!=(t=j.find(e=>e.id===m.from))?t:null,E=(0,r.useMemo)(()=>{let e=new Map();if(null===N||null===j)return e;for(let t of j)e.set(t.id,t.id===N.id?"source":(0,O.canConnect)(N.type,t.type)?"valid":"invalid");return e;},[N,j]);(0,r.useEffect)(()=>{let e=e=>{k.current=e,b(e);},t=t=>{!("Space"!==t.code||(0,X.isHandToolKeyIgnoredTarget)(t.target))&&(t.preventDefault(),k.current||e(!0));},n=t=>{"Space"===t.code&&e(!1);},l=()=>{e(!1);};return window.addEventListener("keydown",t),window.addEventListener("keyup",n),window.addEventListener("blur",l),()=>{window.removeEventListener("keydown",t),window.removeEventListener("keyup",n),window.removeEventListener("blur",l);};},[]);let R=(0,r.useMemo)(()=>({backgroundSize:`${String(22*u.zoom)}px ${String(22*u.zoom)}px`,backgroundPosition:`${String(u.x)}px ${String(u.y)}px`}),[u]),A=(0,r.useMemo)(()=>x?{transform:`translate(${String(u.x)}px, ${String(u.y)}px) scale(${String(u.zoom)})`,transformOrigin:"0 0"}:{transform:`translate(${String(u.x/u.zoom)}px, ${String(u.y/u.zoom)}px)`,transformOrigin:"0 0",zoom:u.zoom},[u,x]),P=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("connector",{presentation:"node",selectedKind:e.kind,selectedId:e.id,...(void 0!==e.label?{selectedLabel:e.label}:{}),...(void 0!==e.lifecycleState?{selectedState:e.lifecycleState}:{})});null!==r&&h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current}),...e4});},[h]),M=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaView",{snapshotRunId:e.snapshotRunId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});null!==r&&h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e3}),...e3});},[h]),T=(0,r.useCallback)(e=>{if(null===d)return[];let t=new Map(d.map(e=>[e.id,e])),n=[];for(let l of f){let r=l.a===e?l.b:l.b===e?l.a:null;if(null===r)continue;let i=t.get(r);(null==i?void 0:i.type)==="quality"&&n.push({connId:l.id,qualityId:i.id});}return n;},[f,d]),z=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaJson",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenIdsJson:JSON.stringify([e.screenId]),selectedScreenName:e.name});if(null===r||(h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e5}),...e5}),void 0===e.sourceWindowId))return;let i=T(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(r,e.qualityId);},0);}},[h,T]),F=(0,r.useCallback)((e,t,n,l)=>{let r=h.add("figmaImage",{snapshotRunId:e.snapshotRunId,screenId:e.screenId,selectedScreenName:e.name,imageSrc:e.imageSrc});if(null===r||(h.update(r,{...e8({clientX:t,clientY:n,rect:l,view:g.current,size:e6}),...e6}),void 0===e.sourceWindowId))return;let i=T(e.sourceWindowId);if(0!==i.length){for(let e of i)h.removeConn(e.connId);window.setTimeout(()=>{for(let e of i)h.connect(r,e.qualityId);},0);}},[h,T]);(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;if("number"!=typeof e.clientX||"number"!=typeof e.clientY||"object"!=typeof t||null===t)return!1;let n=t.kind;return("capsule"===n||"capsule-set"===n)&&"string"==typeof t.id;}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||P(i,l,r,n);};return window.addEventListener(eH.LOCAL_KNOWLEDGE_CONNECTOR_DROP_EVENT,e),()=>{window.removeEventListener(eH.LOCAL_KNOWLEDGE_CONNECTOR_DROP_EVENT,e);};},[P,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name;}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||M(i,l,r,n);};return window.addEventListener(eZ.FIGMA_VIEW_DROP_EVENT,e),()=>{window.removeEventListener(eZ.FIGMA_VIEW_DROP_EVENT,e);};},[M,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||z(i,l,r,n);};return window.addEventListener(eQ.FIGMA_JSON_DROP_EVENT,e),()=>{window.removeEventListener(eQ.FIGMA_JSON_DROP_EVENT,e);};},[z,a]),(0,r.useEffect)(()=>{let e=e=>{var t;if(!(e instanceof CustomEvent)||!function(e){if("object"!=typeof e||null===e)return!1;let t=e.payload;return"number"==typeof e.clientX&&"number"==typeof e.clientY&&"object"==typeof t&&null!==t&&"string"==typeof t.snapshotRunId&&"string"==typeof t.screenId&&"string"==typeof t.name&&"string"==typeof t.imageSrc&&(void 0===t.sourceWindowId||"string"==typeof t.sourceWindowId);}(e.detail))return;let n=null==(t=a.current)?void 0:t.getBoundingClientRect();if(void 0===n)return;let{clientX:l,clientY:r,payload:i}=e.detail;l<n.left||l>n.right||r<n.top||r>n.bottom||F(i,l,r,n);};return window.addEventListener(e0.FIGMA_IMAGE_DROP_EVENT,e),()=>{window.removeEventListener(e0.FIGMA_IMAGE_DROP_EVENT,e);};},[F,a]);let L=(0,r.useMemo)(()=>null===d?"":d.map(e=>`${e.id}:${e.type}:${!0===e.minimized?"1":"0"}:${"string"==typeof e.cfg.chatId?e.cfg.chatId:""}`).join("|"),[d]);(0,r.useEffect)(()=>{(0,e1.syncPdfCitationPreviewWindowRegistry)(d);},[L]);let W=null!==d&&0===d.length,$=null!=(n=null==d?void 0:d.some(e=>e.max))&&n;return(0,l.jsxs)("main",{className:"workspace",ref:a,"aria-label":"Workspace surface",tabIndex:0,"data-window-maxed":$?"true":void 0,"data-canvas-overlays-hidden":$?"true":"false","data-connecting":null!==m?"true":void 0,"data-panning":v?"true":void 0,"data-hand-tool":y?"true":void 0,onPointerDownCapture:e=>{if((0,X.workspaceInteractionLocked)())return;if(k.current&&(0,X.isPrimaryActivationPointer)(e)&&null===m&&!(0,X.isTextEntryTarget)(e.target)&&!(0,X.isInteractiveSurfaceTarget)(e.target)){e9(h.panBy,e,w),e.stopPropagation();return;}if(0!==e.button||null===m||null===N||null===j)return;let t=function(e){if(!(e instanceof Element))return;let t=e.closest(".window[data-window-id]");return null==t?void 0:t.dataset.windowId;}(e.target);if(void 0===t||t===N.id)return;let n=j.find(e=>e.id===t);void 0!==n&&(0,O.canConnect)(N.type,n.type)&&h.confirmConnect(n.id,e);},onPointerDown:e=>{if(!((0,X.workspaceInteractionLocked)()||(0,X.isInteractiveSurfaceTarget)(e.target))){if(null!==m){(0,X.isPrimaryActivationPointer)(e)&&h.cancelConnect();return;}(0,X.isCanvasPanPointer)(e)&&e9(h.panBy,e,w);}},onKeyDown:e=>{if(e.target!==e.currentTarget)return;let t=e.shiftKey?192:48;switch(e.key){case"ArrowLeft":h.panBy(t,0);break;case"ArrowRight":h.panBy(-t,0);break;case"ArrowUp":h.panBy(0,t);break;case"ArrowDown":h.panBy(0,-t);break;default:return;}e.preventDefault();},onDragOver:e=>{(null!==(0,eH.parseLocalKnowledgeConnectorDrag)(e.dataTransfer)||null!==(0,eZ.parseFigmaViewDrag)(e.dataTransfer)||null!==(0,eQ.parseFigmaJsonDrag)(e.dataTransfer)||null!==(0,e0.parseFigmaImageDrag)(e.dataTransfer))&&(e.preventDefault(),e.dataTransfer.dropEffect="copy");},onDrop:e=>{let t=(0,eH.parseLocalKnowledgeConnectorDrag)(e.dataTransfer),n=(0,eZ.parseFigmaViewDrag)(e.dataTransfer),l=(0,eQ.parseFigmaJsonDrag)(e.dataTransfer),r=(0,e0.parseFigmaImageDrag)(e.dataTransfer);if(null===t&&null===n&&null===l&&null===r)return;e.preventDefault(),e.stopPropagation();let i=e.currentTarget.getBoundingClientRect();null!==t?P(t,e.clientX,e.clientY,i):null!==n?M(n,e.clientX,e.clientY,i):null!==l?z(l,e.clientX,e.clientY,i):null!==r&&F(r,e.clientX,e.clientY,i);},children:[(0,l.jsx)(e2,{}),(0,l.jsx)("div",{className:"ws-grid",style:R,"aria-hidden":"true"}),(0,l.jsx)(te,{wins:j,connecting:m,conns:f}),null!==m?(0,l.jsx)("div",{className:"ws-connect-hint","aria-hidden":"true",children:"Click a highlighted window to connect — Esc to cancel"}):null,W?(0,l.jsx)("div",{className:"ws-empty",children:(0,l.jsx)(Y,{onNewWindow:o})}):null,(0,l.jsxs)("div",{className:"ws-scene",style:A,children:[null!==p?(0,l.jsx)("div",{className:"snap-ghost",style:{left:p.x,top:p.y,width:p.w,height:p.h}}):null,null!==j?(0,l.jsx)(et,{wins:j,conns:f,connecting:m,api:h}):null,null!==j?j.map(e=>{var t;return(0,l.jsx)(ec,{win:e,top:null!==S&&e.id===S.id,connState:null!=(t=E.get(e.id))?t:null,api:h,wsRef:a,linkRevision:C},e.id);}):null]}),(0,l.jsxs)("div",{className:"ws-zoom",children:[(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:()=>h.zoomTo(e7(u.zoom,-.2)),disabled:u.zoom<=.3,"aria-label":"Zoom out","data-tip":"Zoom out",children:(0,l.jsx)(I.Icons.zoomOut,{size:15})}),(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-start",onClick:h.fitView,disabled:null===j||0===j.length,"aria-label":"Fit workspace to windows","data-tip":"Fit workspace to windows",children:(0,l.jsx)(I.Icons.expand,{size:15})}),(0,l.jsxs)("button",{type:"button",className:"ws-zoom-pct mono ui-tip",onClick:h.resetView,"aria-label":`${String(Math.round(100*u.zoom))}% — reset`,"data-tip":"Reset",children:[Math.round(100*u.zoom),"%"]}),(0,l.jsx)("button",{type:"button",className:"ws-zoom-btn ui-tip cmp-tip-end",onClick:()=>h.zoomTo(e7(u.zoom,.2)),disabled:u.zoom>=2.5,"aria-label":"Zoom in","data-tip":"Zoom in",children:(0,l.jsx)(I.Icons.zoomIn,{size:15})})]}),(0,l.jsx)("button",{type:"button",className:"ws-fab ui-tip cmp-tip-end",onPointerDown:e=>e.stopPropagation(),onClick:o,"aria-label":"New window","data-tip":"New window",children:(0,l.jsx)(I.Icons.add,{size:20})}),$?null:null!=s?s:null,c]});}var tl=e.i(31578);function tr(e){let{commands:t,onClose:n}=e,[i,a]=(0,r.useState)(""),[o,s]=(0,r.useState)(0),c=(0,r.useRef)(null),d=(0,r.useRef)(null),u=(0,r.useRef)(null);(0,r.useEffect)(()=>(d.current=document.activeElement,()=>{var e,t;null==(t=d.current)||null==(e=t.focus)||e.call(t);}),[]),(0,r.useEffect)(()=>{var e;null==(e=c.current)||e.focus();},[]);let p=(0,r.useMemo)(()=>{let e=i.toLowerCase();return t.filter(t=>{var n;return`${t.label} ${null!=(n=t.group)?n:""}`.toLowerCase().includes(e);});},[t,i]);(0,r.useEffect)(()=>{s(0);},[i]),(0,r.useEffect)(()=>{var e,t;null==(t=document.getElementById(`cmdk-row-${String(o)}`))||null==(e=t.scrollIntoView)||e.call(t,{block:"nearest"});},[o,p]);let f=e=>{void 0!==e&&(e.run(),n());};return(0,l.jsx)("div",{className:"cmdk-overlay",onPointerDown:n,children:(0,l.jsxs)("div",{ref:u,className:"cmdk",role:"dialog","aria-modal":"true","aria-labelledby":"cmdk-title","aria-describedby":"cmdk-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{if("Tab"===e.key){var t,l;let n=Array.from(null!=(t=null==(l=u.current)?void 0:l.querySelectorAll("button:not([disabled]),input:not([disabled]),[tabindex]:not([tabindex='-1'])"))?t:[]);if(n.length>0){let t=n[0],l=n[n.length-1];if(e.shiftKey&&document.activeElement===t){e.preventDefault(),l.focus();return;}if(!e.shiftKey&&document.activeElement===l){e.preventDefault(),t.focus();return;}}}if("ArrowDown"===e.key){e.preventDefault(),s(e=>Math.min(p.length-1,e+1));return;}if("ArrowUp"===e.key){e.preventDefault(),s(e=>Math.max(0,e-1));return;}if("Enter"===e.key){e.preventDefault(),f(p[o]);return;}"Escape"===e.key&&n();},children:[(0,l.jsx)("h2",{id:"cmdk-title",className:"sr-only",children:"Command palette"}),(0,l.jsx)("p",{id:"cmdk-desc",className:"sr-only",children:"Search commands and press Enter to run the selected action."}),(0,l.jsxs)("div",{className:"cmdk-input",children:[(0,l.jsx)(I.Icons.search,{size:16}),(0,l.jsx)("input",{ref:c,role:"combobox","aria-expanded":"true","aria-controls":"cmdk-list","aria-activedescendant":p.length>0?`cmdk-row-${String(o)}`:void 0,"aria-label":"Command query",placeholder:"Type a command…",value:i,onChange:e=>a(e.target.value)}),(0,l.jsx)("span",{className:"kbd",children:"esc"})]}),(0,l.jsx)("div",{className:"sr-only",role:"status",children:0===p.length?"No matching commands":`${String(p.length)} command${1===p.length?"":"s"}`}),(0,l.jsxs)("div",{id:"cmdk-list",role:"listbox",className:"cmdk-list",children:[0===p.length&&(0,l.jsx)("div",{className:"cmdk-empty",children:"No matching commands"}),p.map((e,t)=>{var n,r;let i;return(0,l.jsxs)("div",{role:"option",id:`cmdk-row-${String(t)}`,"aria-selected":t===o,className:"cmdk-row","data-sel":t===o,tabIndex:-1,onMouseEnter:()=>s(t),onClick:()=>f(e),children:[(0,l.jsx)("span",{className:"cmdk-ico",children:(n=e.icon,i=null!=(r=I.Icons[n])?r:I.Icons.spark,(0,l.jsx)(i,{size:16}))}),(0,l.jsx)("span",{className:"cmdk-label",children:e.label}),(0,l.jsx)("span",{className:"spacer"}),void 0!==e.shortcut&&(0,l.jsx)("span",{className:"kbd",children:e.shortcut}),void 0!==e.group&&(0,l.jsx)("span",{className:"cmdk-group mono",children:e.group})]},e.id);})]})]})});}var ti=e.i(70307),ta=e.i(67914);let to=[["ask","Ask every action"],["full","Full access"]];function ts(e){let{cfg:t,set:n}=e,r=!1!==t.keikoMode,i="full"===t.access?"full":"ask",a=r?"No rights by default. You approve while manual; Keiko governs per policy when autonomous.":"full"===i?"Legacy: agent acts without prompts.":"Legacy: you approve each privileged action.";return(0,l.jsxs)("div",{className:"permctl",children:[(0,l.jsxs)("button",{type:"button",className:"perm-toggle","data-on":r,role:"switch","aria-checked":r,onClick:()=>n("keikoMode",!r),children:[(0,l.jsx)("img",{className:"perm-orca",src:"/assets/keiko-logo.svg",alt:""}),(0,l.jsxs)("span",{className:"perm-tt",children:[(0,l.jsx)("span",{className:"perm-name",children:"Keiko-Mode"}),(0,l.jsx)("span",{className:"perm-desc",children:"Zero standing rights · Keiko governs"})]}),(0,l.jsx)("span",{className:"perm-sw"+(r?" on":""),children:(0,l.jsx)("span",{})})]}),!r&&(0,l.jsx)("div",{className:"perm-legacy",role:"radiogroup","aria-label":"Legacy access mode",children:to.map(e=>{let[t,r]=e;return(0,l.jsx)("button",{type:"button",className:"perm-opt","data-on":i===t,role:"radio","aria-checked":i===t,onClick:()=>n("access",t),children:r},t);})}),(0,l.jsx)("div",{className:"perm-note",children:a})]});}function tc(e){if(e instanceof W.ApiError){if("BAD_ROOT"===e.code)return"Enter an absolute folder path.";if("DENIED"===e.code)return"That location is excluded.";}return e instanceof Error?e.message:"Unable to read directories.";}function td(e){let{value:t,projectId:n,selectProjectRoot:i=!1,onSelect:a,onClose:o}=e,[s,c]=(0,r.useState)(null),[d,u]=(0,r.useState)(t),[p,f]=(0,r.useState)(!1),[m,h]=(0,r.useState)(null),g=null!=n?n:t.trim(),v=(0,r.useCallback)(async e=>{if(0===g.length){c(null),h("Enter an absolute folder path.");return;}f(!0),h(null);try{let t=await(0,W.fetchFilesDirectories)(g,e);c(t),u(t.path);}catch(e){h(tc(e));}finally{f(!1);}},[g]);return(0,r.useEffect)(()=>{v(t.length>0?t:void 0);},[]),(0,l.jsxs)("div",{className:"dir-picker",role:"group","aria-label":"Directory picker",children:[(0,l.jsxs)("div",{className:"dir-top",children:[(0,l.jsx)("input",{className:"dlg-input mono dir-path",value:d,"aria-label":"Folder path",placeholder:"/absolute/folder/path",onChange:e=>u(e.target.value),onKeyDown:e=>{"Enter"===e.key&&(e.preventDefault(),e.stopPropagation(),v(d));}}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dir-go",onClick:()=>void v(d),children:"Go"})]}),null!==s?(0,l.jsx)("div",{className:"dir-roots",children:s.roots.map(e=>(0,l.jsx)("button",{type:"button",className:"dir-chip",onClick:()=>void v(e.path),children:e.label},`${e.label}:${e.path}`))}):null,(0,l.jsxs)("div",{className:"dir-list",children:[(null==s?void 0:s.parent)!==null&&(null==s?void 0:s.parent)!==void 0?(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>{var e;v(null!=(e=s.parent)?e:void 0);},children:[(0,l.jsx)(I.Icons.back,{size:14}),(0,l.jsx)("span",{children:"Parent directory"})]}):null,null==s?void 0:s.entries.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>void v(e.path),children:[(0,l.jsx)(I.Icons.folder,{size:14}),(0,l.jsx)("span",{children:e.name})]},e.path)),p?(0,l.jsx)("div",{className:"dir-note",role:"status",children:"Loading directories…"}):null,p||null===s||0!==s.entries.length?null:(0,l.jsx)("div",{className:"dir-note",children:"No child directories."}),null!==m?(0,l.jsx)("div",{className:"dir-error",role:"alert",children:m}):null]}),(0,l.jsxs)("div",{className:"dir-actions",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:o,children:"Close"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{if(null!==s){var e,t;a(i&&null!=(e=null==(t=s.roots[0])?void 0:t.path)?e:s.path),o();}},disabled:null===s,children:"Use directory"})]})]});}let tu=[{id:"unit-test-generation",label:"Unit Test Agent",scope:"Source file"},{id:"bug-investigation",label:"Bugfix Agent",scope:"Bug report"}];function tp(e){return e.filter(e=>e.available).map(e=>e.path);}function tf(e){return e.split(/[\n,]/u).map(e=>e.trim()).filter(e=>e.length>0);}function tm(e){let t=tg(e.trim()).replace(/\/+$/u,""),n=t.lastIndexOf("/");return n>0?t.slice(0,n):"";}let th=function(e){return"chat"===e.kind&&e.toolCalling&&e.structuredOutput;};function tg(e){return e.replaceAll("\\","/");}function tv(e,t){let n=tg(t.trim());if(0===n.length)return"";let l=tg(e.trim()).replace(/\/+$/u,"");if(0===l.length)return n;if(n===l)return".";let r=`${l}/`;return n.startsWith(r)?n.slice(r.length):n;}function tw(e){let{root:t,value:n,onSelect:i,onClose:a}=e,o=tv(t,n),[s,c]=(0,r.useState)(tm(o)),[d,u]=(0,r.useState)(o),[p,f]=(0,r.useState)([]),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(!1),[w,y]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(0===t.trim().length){f([]),h(!1),v(!1),y("Select a repository first.");return;}let e=!1;return v(!0),y(null),(0,W.fetchFilesTree)(t.trim(),s).then(t=>{e||(f(t.entries),h(t.truncated));}).catch(t=>{e||(f([]),h(!1),y(tc(t)));}).finally(()=>{e||v(!1);}),()=>{e=!0;};},[s,t]);let b=p.filter(e=>"directory"===e.kind),k=p.filter(e=>"directory"!==e.kind);return(0,l.jsxs)("div",{className:"file-picker",role:"group","aria-label":"File picker",children:[(0,l.jsx)("div",{className:"file-picker-head",children:(0,l.jsx)("span",{className:"file-picker-path mono",children:0===s.length?"Repository root":s})}),(0,l.jsxs)("div",{className:"dir-list file-picker-list",children:[s.length>0?(0,l.jsxs)("button",{type:"button",className:"dir-row",onClick:()=>c(tm(s)),children:[(0,l.jsx)(I.Icons.back,{size:14}),(0,l.jsx)("span",{children:"Parent folder"})]}):null,b.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row file-picker-row",disabled:!e.readable,onClick:()=>c(e.path),title:e.path,children:[(0,l.jsx)(I.Icons.folder,{size:14}),(0,l.jsx)("span",{children:e.name})]},e.path)),k.map(e=>(0,l.jsxs)("button",{type:"button",className:"dir-row file-picker-row","data-selected":d===e.path?"true":void 0,disabled:!e.readable,"aria-pressed":d===e.path,onClick:()=>u(e.path),title:e.path,children:[(0,l.jsx)(I.Icons.file,{size:14}),(0,l.jsx)("span",{children:e.name}),(0,l.jsx)("span",{className:"file-picker-meta mono",children:function(e){if(!Number.isFinite(e)||e<=0)return"0 B";let t=["B","KB","MB","GB"],n=e,l=0;for(;n>=1024&&l<t.length-1;)n/=1024,l+=1;let r=0===l?n.toFixed(0):n.toFixed(n>=10?1:2);return`${r} ${t[l]}`;}(e.sizeBytes)})]},e.path)),g?(0,l.jsx)("div",{className:"dir-note",role:"status",children:"Loading files…"}):null,g||null!==w||0!==p.length?null:(0,l.jsx)("div",{className:"dir-note",children:"No files in this folder."}),m?(0,l.jsxs)("div",{className:"dir-note file-picker-warning",role:"status",children:["Showing only the first ",p.length.toString()," entries."]}):null,null!==w?(0,l.jsx)("div",{className:"dir-error",role:"alert",children:w}):null]}),(0,l.jsxs)("div",{className:"dir-actions",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:a,children:"Close"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:()=>{0!==d.trim().length&&(i(tv(t,d)),a());},disabled:0===d.trim().length,children:"Use file"})]})]});}function ty(e){var t,n,i,a;let{filesContext:o,directoryField:s,setDirectoryField:c,setDialogError:d,onConfirm:u,onClose:p}=e,[f,m]=(0,r.useState)("unit-test-generation"),[h,g]=(0,r.useState)(null!=(t=null==o?void 0:o.root)?t:""),[v,w]=(0,r.useState)(""),[y,b]=(0,r.useState)([]),[k,x]=(0,r.useState)([]),[j,C]=(0,r.useState)(()=>{var e,t,n,l;let r;return n=null!=(e=null==o?void 0:o.root)?e:"",{verifyTargetFiles:r=null===(l=null!=(t=null==o?void 0:o.activeFilePath)?t:null)?"":tv(n,l),explainFilePath:r,explainQuestion:"",unitFilePath:r,bugDescription:"",bugFailingOutput:"",bugStackTrace:"",bugTargetFiles:r};}),[S,N]=(0,r.useState)(!0),[E,R]=(0,r.useState)(!1),[A,P]=(0,r.useState)(!1),M=h.trim(),T=null!==o&&o.root===M&&void 0!==o.activeFilePath?o.activeFilePath:null,z=M.length>0&&k.includes(M),F=0===M.length?"Repository is required.":0===v.length?"No compatible model is available.":"explain-plan"===f&&0===j.explainFilePath.trim().length?"Explain plan requires a file path.":"unit-test-generation"===f&&0===j.unitFilePath.trim().length?"Unit Test Agent requires a source file.":"bug-investigation"===f&&0===j.bugDescription.trim().length?"Bugfix Agent requires an observed behavior.":null,L=null===F&&z&&!A&&!S,$=null!=(n=tu.find(e=>e.id===f))?n:tu[0],D="unit-test-generation"===f?"Start Unit Test Agent":"Start Bugfix Agent",O=null!=(i=k[0])?i:"",K=M.length>0?M:null!=(a=null==o?void 0:o.root)?a:O,q=K.length>0,B="agent-repository-browse-help",_="agent-source-file-browse-help";(0,r.useEffect)(()=>{let e=!1;return N(!0),d(null),Promise.all([(0,W.fetchModels)(),(0,W.fetchProjects)()]).then(t=>{let[n,l]=t;if(e)return;let r=n.models.filter(th);b(r),w(e=>{var t,n;return e||(null!=(t=null==(n=r[0])?void 0:n.id)?t:"");}),x(tp(l.projects));}).catch(t=>{e||d(tc(t));}).finally(()=>{e||N(!1);}),()=>{e=!0;};},[d]);let G=e=>{C(t=>({...t,...e}));};(0,r.useEffect)(()=>{if(null===T)return;let e=tv(M,T);C(t=>{let n={};return 0===t.verifyTargetFiles.trim().length&&(n.verifyTargetFiles=e),0===t.explainFilePath.trim().length&&(n.explainFilePath=e),0===t.unitFilePath.trim().length&&(n.unitFilePath=e),0===t.bugTargetFiles.trim().length&&(n.bugTargetFiles=e),0===Object.keys(n).length?t:{...t,...n};});},[T,M]);let U=async()=>{x(tp((await(0,W.fetchProjects)()).projects));},J=async()=>{if(0!==M.length){R(!0),d(null);try{await(0,W.createProject)({path:M}),await U();}catch(e){d(tc(e));}finally{R(!1);}}},V=async()=>{if(!L)return void d(null!=F?F:"Repository is not registered.");P(!0),d(null);let e=function(e,t,n,l){if("verify"===e){let e=tf(l.verifyTargetFiles).map(e=>tv(t,e));return{taskType:"verify",modelId:n,input:{workspaceRoot:t,...(e.length>0?{targetFiles:e}:{})}};}return"explain-plan"===e?{taskType:"explain-plan",modelId:n,input:{workspaceRoot:t,filePath:tv(t,l.explainFilePath),...(l.explainQuestion.trim().length>0?{question:l.explainQuestion.trim()}:{})}}:"unit-test-generation"===e?{workflowId:"unit-test-generation",modelId:n,input:{workspaceRoot:t,target:{kind:"file",filePath:tv(t,l.unitFilePath)}}}:{workflowId:"bug-investigation",modelId:n,input:{workspaceRoot:t,report:{...(l.bugDescription.trim().length>0?{description:l.bugDescription.trim()}:{}),...(l.bugFailingOutput.trim().length>0?{failingOutput:l.bugFailingOutput.trim()}:{}),...(l.bugStackTrace.trim().length>0?{stackTrace:l.bugStackTrace.trim()}:{}),...(tf(l.bugTargetFiles).length>0?{targetFiles:tf(l.bugTargetFiles).map(e=>tv(t,e))}:{})}}};}(f,M,v,j);try{let t=await(0,W.startRun)(e);u({workflow:f,model:v,runId:t.runId,fingerprint:t.fingerprint,workspaceRoot:M,inputJson:JSON.stringify(e.input),...(null!==o&&o.root===M?{__connectFilesId:o.id}:{})});}catch(e){e instanceof W.ApiError&&"WORKSPACE_NOT_REGISTERED"===e.code?(await U().catch(()=>void 0),d("Repository is not registered.")):d(tc(e));}finally{P(!1);}};return(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("div",{className:"dlg-agent-grid",children:[(0,l.jsxs)("div",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Agent"}),(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input",value:f,ariaLabel:"Agent",autoFocus:!0,menuTitle:"Agent",menuCountLabel:`${tu.length.toString()} agents`,sections:[{options:tu.map(e=>({value:e.id,label:e.label}))}],onValueChange:e=>{let t=tu.find(t=>t.id===e);void 0!==t&&m(t.id);}})})]}),(0,l.jsxs)("div",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Model"}),(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input mono",value:v,ariaLabel:"Model",disabled:0===y.length,menuTitle:"Model",mono:!0,sections:[{options:y.map(e=>({value:e.id,label:e.id}))}],onValueChange:w})})]})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Repository"}),(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{className:"dlg-input mono",value:h,placeholder:"/absolute/repository/path",onChange:e=>g(e.target.value)}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",disabled:!q,"aria-describedby":q?void 0:B,onClick:()=>{q&&(0===M.length&&g(K),c("agentWorkspace"));},children:"Browse"})]}),q?null:(0,l.jsx)("span",{id:B,className:"dlg-note",children:"Enter an absolute repository path to enable Browse."}),"agentWorkspace"===s?(0,l.jsx)(td,{value:K,projectId:k.includes(K)?K:void 0,onSelect:g,onClose:()=>c(null)}):null]}),M.length>0&&!z?(0,l.jsxs)("div",{className:"dlg-agent-warning",children:[(0,l.jsx)("span",{children:"Repository is not registered."}),(0,l.jsx)("button",{type:"button",className:"dlg-btn",disabled:E,onClick:()=>void J(),children:E?"Registering…":"Register repository"})]}):null,null!==T?(0,l.jsxs)("button",{type:"button",className:"dlg-current-file",onClick:()=>{if(null===T)return;let e=tv(M,T);"unit-test-generation"===f?G({unitFilePath:e}):G({bugTargetFiles:e});},title:T,children:[(0,l.jsx)(I.Icons.files,{size:13})," Use current file ",(0,l.jsx)("span",{className:"mono",children:T})]}):null,(0,l.jsxs)("div",{className:"dlg-agent-task",children:[(0,l.jsxs)("div",{className:"dlg-agent-task-head",children:[(0,l.jsx)("span",{className:"dlg-agent-task-title",children:$.label}),(0,l.jsx)("span",{className:"dlg-agent-task-scope",children:$.scope})]}),"unit-test-generation"===f?(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Source file"}),(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{className:"dlg-input mono",placeholder:"src/file.ts",value:j.unitFilePath,onChange:e=>G({unitFilePath:e.target.value}),onBlur:e=>G({unitFilePath:tv(M,e.target.value)})}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn","aria-label":"Browse source file",disabled:!z,"aria-describedby":z?void 0:_,onClick:()=>{z&&c("unitSourceFile");},children:"Browse"})]}),z?null:(0,l.jsx)("span",{id:_,className:"dlg-note",children:"Select a registered repository before browsing source files."}),"unitSourceFile"===s?(0,l.jsx)(tw,{root:M,value:j.unitFilePath,onSelect:e=>G({unitFilePath:e}),onClose:()=>c(null)}):null]}):(0,l.jsxs)(l.Fragment,{children:[(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsx)("span",{className:"dlg-label",children:"Observed behavior"}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea",rows:2,placeholder:"Describe the observed bug.",value:j.bugDescription,onChange:e=>G({bugDescription:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Failing output ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:j.bugFailingOutput,onChange:e=>G({bugFailingOutput:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Stack trace ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,value:j.bugStackTrace,onChange:e=>G({bugStackTrace:e.target.value})})]}),(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:["Related files ",(0,l.jsx)("span",{className:"dlg-opt",children:"optional"})]}),(0,l.jsx)("textarea",{className:"dlg-input dlg-textarea mono",rows:2,placeholder:"src/file.ts, src/other.ts",value:j.bugTargetFiles,onChange:e=>G({bugTargetFiles:e.target.value}),onBlur:e=>G({bugTargetFiles:tf(e.target.value).map(e=>tv(M,e)).join(", ")})})]})]})]}),(0,l.jsxs)("div",{className:"dlg-agent-actions",children:[S?(0,l.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:"Loading models and projects…"}):null,S||null===F?null:(0,l.jsx)("span",{id:"agent-start-validation",className:"dlg-note",role:"status",children:F}),(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:p,children:"Cancel"}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",disabled:!L,"aria-busy":A,"aria-describedby":L||A?void 0:"agent-start-validation",onClick:()=>void V(),children:A?"Starting…":D})]})]});}function tb(e){var t;let{type:n,types:i,filesContext:a=null,onConfirm:o,onClose:s}=e,c=(0,$.useTranslate)(),d=i[n],u=(0,r.useMemo)(()=>{var e,t;return t=null!=(e=d.config)?e:[],"chat"!==n?t:t.map(e=>"title"===e.key?{...e,label:c("newWindow.chat.fieldTitle"),def:c("newWindow.chat.defaultTitle"),placeholder:c("newWindow.chat.placeholder")}:e);},[c,d.config,n]),[p,f]=(0,r.useState)(()=>function(e){let t={};for(let l of e){var n;t[l.key]=null!=(n=l.def)?n:"";}return t;}(u)),[m,h]=(0,r.useState)(!1),[g,v]=(0,r.useState)(null),[w,y]=(0,r.useState)(null),b=(0,r.useRef)(null),k=(0,r.useRef)(null),x=(0,r.useRef)(null),j="chat"===n?c("newWindow.chat.title"):`New ${d.title} window`,C="chat"===n?c("newWindow.chat.description"):d.desc,S="chat"===n?c("newWindow.chat.open"):null!=(t=d.cta)?t:`Open ${d.title}`;(0,r.useEffect)(()=>(x.current=document.activeElement,()=>{let e=x.current;null!==e&&e.isConnected?e.focus():requestAnimationFrame(()=>{var e,t;(null!=(e=null!=(t=document.querySelector('.window[data-top="true"]'))?t:document.querySelector(".ws-fab"))?e:document.body).focus({preventScroll:!0});});}),[]),(0,r.useEffect)(()=>{let e=requestAnimationFrame(()=>{var e,t;h(!0),null==(t=null!=(e=b.current)?e:k.current)||t.focus();});return()=>cancelAnimationFrame(e);},[]),(0,r.useEffect)(()=>{let e=e=>{"Escape"===e.key&&s();};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[s]),(0,r.useEffect)(()=>{if("files"!==n&&"editor"!==n)return;let e=!1,t=p.root;if("string"!=typeof t||!(t.length>0))return v(null),(0,W.fetchProjects)().then(t=>{let n=tp(t.projects)[0];e||void 0===n||f(e=>({...e,root:n}));}).catch(t=>{e||v(tc(t));}),()=>{e=!0;};},[p.root,n]);let N=(e,t)=>f(n=>({...n,[e]:t})),E=()=>{"agents"!==n&&o(p);},R=I.Icons[d.icon];return(0,l.jsx)("div",{className:"dlg-overlay"+(m?" in":""),onPointerDown:s,children:(0,l.jsxs)("div",{ref:k,className:"agents"===n?"dlg dlg-agents":"dlg",role:"dialog","aria-modal":"true","aria-labelledby":"new-window-title","aria-describedby":"new-window-desc",tabIndex:-1,onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{let t,n;if("Escape"===e.key)return void s();if("Enter"===e.key&&(e.metaKey||e.ctrlKey))return void E();if("Enter"===e.key){let t=e.target instanceof HTMLElement?e.target.tagName:"";("INPUT"===t||"SELECT"===t)&&(e.preventDefault(),E());return;}if("Tab"!==e.key)return;let l=(t=e.currentTarget.querySelectorAll("button,input,select,textarea"),n=[],t.forEach(e=>{e.hasAttribute("disabled")||(null!==e.offsetParent||"BUTTON"===e.tagName)&&n.push(e);}),n);if(0===l.length)return;let r=l[0],i=l[l.length-1];e.shiftKey&&document.activeElement===r?(e.preventDefault(),i.focus()):e.shiftKey||document.activeElement!==i||(e.preventDefault(),r.focus());},children:[(0,l.jsxs)("div",{className:"dlg-head",children:[(0,l.jsx)("span",{className:"dlg-ico",children:(0,l.jsx)(R,{size:20})}),(0,l.jsxs)("div",{className:"dlg-htext",children:[(0,l.jsx)("span",{id:"new-window-title",className:"dlg-title",children:j}),(0,l.jsx)("span",{id:"new-window-desc",className:"dlg-sub",children:C})]}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsx)("button",{type:"button",className:"palette-x",onClick:s,"aria-label":c("common.cancel"),title:c("common.cancel"),children:(0,l.jsx)(I.Icons.close,{size:16})})]}),(0,l.jsxs)("div",{className:"dlg-body",children:["agents"===n?(0,l.jsx)(ty,{filesContext:a,directoryField:w,setDirectoryField:y,setDialogError:v,onConfirm:o,onClose:s}):0===u.length&&(0,l.jsxs)("div",{className:"dlg-empty",children:["Add a new ",d.title," window to your workspace."]}),"agents"!==n&&u.map((e,t)=>(0,l.jsxs)("label",{className:"dlg-field",children:[(0,l.jsxs)("span",{className:"dlg-label",children:[e.label,!0===e.optional&&(0,l.jsx)("span",{className:"dlg-opt",children:c("common.optional")})]}),function(e,t,n,r,i){var a,o,s,c;if("perm"===e.type)return(0,l.jsx)(ts,{cfg:t,set:n});let d=t[e.key],u="string"==typeof d?d:void 0===d?"":String(d);if("select"===e.type){let t=null!=(o=e.options)?o:[];return(0,l.jsx)("span",{className:"dlg-selwrap",children:(0,l.jsx)(ta.default,{triggerClassName:"dlg-input mono",value:u,disabled:0===t.length,autoFocus:null!==r,menuTitle:e.label,mono:!0,sections:[{options:t.map(t=>{var n;return{value:t,label:`${null!=(n=e.prefix)?n:""}${t}`};})}],onValueChange:t=>n(e.key,t)})});}return"textarea"===e.type?(0,l.jsx)("textarea",{ref:null!=r?r:void 0,className:"dlg-input dlg-textarea",rows:3,placeholder:null!=(s=e.placeholder)?s:"",value:u,onChange:t=>n(e.key,t.target.value)}):"directory"===e.type?(0,l.jsxs)("span",{className:"dlg-dirwrap",children:[(0,l.jsx)("input",{ref:null!=r?r:void 0,className:"dlg-input mono",placeholder:null!=(c=e.placeholder)?c:e.label,value:u,onClick:()=>i(e.key),onChange:t=>n(e.key,t.target.value)}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-dirbtn",onClick:()=>i(e.key),children:"Browse"})]}):(0,l.jsx)("input",{ref:null!=r?r:void 0,className:"dlg-input mono",placeholder:null!=(a=e.placeholder)?a:e.label,value:u,onChange:t=>n(e.key,t.target.value)});}(e,p,N,0===t?e=>{b.current=e;}:null,y),"directory"===e.type&&w===e.key?(0,l.jsx)(td,{value:"string"==typeof p[e.key]?p[e.key]:"",selectProjectRoot:"root"===e.key,onSelect:t=>N(e.key,t),onClose:()=>y(null)}):null]},e.key)),null!==g?(0,l.jsx)("div",{className:"dlg-error",role:"alert",children:g}):null]}),"agents"!==n?(0,l.jsxs)("div",{className:"dlg-foot",children:[(0,l.jsx)("button",{type:"button",className:"dlg-btn",onClick:s,children:c("common.cancel")}),(0,l.jsx)("button",{type:"button",className:"dlg-btn dlg-primary",onClick:E,children:S})]}):null]})});}function tk(e){let{types:t,order:n,onAdd:i,onClose:a}=e,o=n.length<=4?2:3,s=(0,r.useRef)(null),c=(0,r.useRef)(null),[d,u]=(0,r.useState)(0);return(0,r.useEffect)(()=>{var e;c.current=document.activeElement;let t=null==(e=s.current)?void 0:e.querySelector(".pal-card");return null==t||t.focus(),()=>{var e,t;let n=document.activeElement;(null===n||n===document.body)&&(null==(t=c.current)||null==(e=t.focus)||e.call(t));};},[]),(0,r.useEffect)(()=>{let e=e=>{null!==s.current&&e.target instanceof Node&&!s.current.contains(e.target)&&a();};return document.addEventListener("pointerdown",e),()=>{document.removeEventListener("pointerdown",e);};},[a]),(0,l.jsxs)("div",{ref:s,className:"palette",role:"dialog","aria-labelledby":"palette-title","aria-describedby":"palette-desc",tabIndex:-1,style:{cursor:"default"},onPointerDown:e=>e.stopPropagation(),onKeyDown:e=>{var t,n,l;if("Escape"===e.key){e.preventDefault(),a();return;}if(!(e.target instanceof HTMLElement)||!e.target.classList.contains("pal-card"))return;let r=Array.from(null!=(t=null==(n=s.current)?void 0:n.querySelectorAll(".pal-card"))?t:[]),i=function(e,t,n,l){let r;if(0===n)return null;if("Home"===e)return 0;if("End"===e)return n-1;if("ArrowRight"===e)r=1;else if("ArrowLeft"===e)r=-1;else if("ArrowDown"===e)r=l;else{if("ArrowUp"!==e)return null;r=-l;}return Math.max(0,Math.min(n-1,t+r));}(e.key,r.indexOf(e.target),r.length,o);null!==i&&(e.preventDefault(),u(i),null==(l=r[i])||l.focus());},onBlur:e=>{var t;e.relatedTarget instanceof Node&&(null==(t=s.current)?void 0:t.contains(e.relatedTarget))!==!0&&a();},"data-columns":o,children:[(0,l.jsxs)("div",{className:"palette-head",children:[(0,l.jsx)("span",{className:"palette-badge",children:(0,l.jsx)(I.Icons.add,{size:17})}),(0,l.jsxs)("div",{className:"palette-htext",children:[(0,l.jsx)("span",{id:"palette-title",className:"palette-title",children:"New window"}),(0,l.jsx)("span",{id:"palette-desc",className:"palette-sub",children:"Pick a card to add to your workspace"})]}),(0,l.jsx)("span",{className:"spacer"}),(0,l.jsx)("button",{type:"button",className:"palette-x",onClick:a,"aria-label":"Close",title:"Close",children:(0,l.jsx)(I.Icons.close,{size:16})})]}),(0,l.jsx)("div",{className:"palette-grid",children:n.map((e,n)=>{let r=t[e],a=I.Icons[r.icon];return(0,l.jsxs)("button",{type:"button",className:"pal-card pal-main",tabIndex:n===d?0:-1,onFocus:()=>u(n),onClick:()=>i(e),children:[(0,l.jsx)("span",{className:"pal-ico",children:(0,l.jsx)(a,{size:18})}),(0,l.jsx)("span",{className:"pal-name",children:r.title}),(0,l.jsx)("span",{className:"pal-desc",children:r.desc}),(0,l.jsx)("span",{className:"pal-add","aria-hidden":"true",children:(0,l.jsx)(I.Icons.plus,{size:15})})]},e);})})]});}var tx=e.i(26428),tj=e.i(83500);let tC=new Set(["completed","dry-run","fix-applied","fix-proposed","investigation-only"]);function tS(e){return e.length>200?e.slice(0,200):e;}function tN(e){if(null!==e&&"object"==typeof e)return e;}function tI(){return"Investigation complete; root cause documented.";}function tE(e){let t=e.workflowId;return"unit-test-generation"===t||"unit-tests"===t?"unit-tests":"bug-investigation"===t?"bug":"verify"===e.taskType?"verify":"explain-plan"===e.taskType?"explain":"other";}var tR=e.i(89956),tA=e.i(86090);let tP="\n…[truncated]",tM=["text/"],tT=new Set(["application/json","application/x-yaml","application/yaml"]),tz=new TextEncoder();function tF(e){return tz.encode(e).length;}function tL(e){let t=Math.max(e.lastIndexOf("/"),e.lastIndexOf("\\"));return t>=0?e.slice(t+1):e;}let tW=`${String(256)} KB`;function t$(e){return`"${e}" won't be sent — the ${tW} attachment limit was already used by earlier files.`;}async function tD(e,t){var n,l;let r,i,a,o,s;if(e.remainingAggregate<=0)return t$(tL(t.name));try{let e=65536+tF(tP)+4;r=await t.file.slice(0,e).text();}catch{return n=tL(t.name),`Couldn't read "${n}" — it will be skipped. Your message will be sent without it.`;}let c=Math.min(65536,Math.max(e.remainingAggregate-tF(tP),0));if(c<=0)return t$(tL(t.name));let{entry:d,consumed:u}=(a=(i=tF(l=r)>c)?function(e,t){if(t<=0)return"";if(tF(e)<=t)return e;let n=0,l="";for(let r of e){let e=n+tF(r);if(e>t)break;n=e,l+=r;}return l;}(l,c):l,o=tF(a),s=i?tF(tP):0,{entry:{id:t.id,displayName:tL(t.name),mimeType:t.mimeType,sizeBytes:t.sizeBytes,extractedBytes:o,truncated:i,truncationMarker:i?tP:void 0,text:a},consumed:o+s});if(0===d.text.length)return 0===r.length?void 0:t$(tL(t.name));e.entries.push(d),e.remainingAggregate-=u;}async function tO(e){var t,n;let l=[],r=[];for(let n of e)(function(e){return!!tM.some(t=>e.startsWith(t))||tT.has(e);})(n.mimeType)?r.push(n):l.push((t=tL(n.name),`Couldn't extract text from "${t}" — it will be sent without document text.`));let i=r.slice(0,16),a={entries:[],remainingAggregate:262144};for(let e of i){let t=await tD(a,e);void 0!==t&&l.push(t);}for(let e of r.slice(16))l.push((n=tL(e.name),`"${n}" won't be sent — only the first ${String(16)} documents are included.`));return{entries:a.entries,failures:l};}var tK=e.i(45624);function tq(e){void 0!==e.previewUrl&&"function"==typeof URL.revokeObjectURL&&URL.revokeObjectURL(e.previewUrl);}let tB="New chat",t_="keiko:chat-upsert",tG="keiko:chat-delete",tU=["completed","failed","cancelled"];function tJ(e){return"idle"!==e&&!tU.includes(e);}let tV="The model request completed, but the provider did not return any answer text. Retry once; if it happens again, check the selected model deployment in Settings.",tY=new Set(["CONVERSATION_OVERSIZED_CONTEXT","GATEWAY_CONTEXT_OVERFLOW"]),tX=["context length","context_length_exceeded","max_tokens","too many tokens"],tH=["empty assistant response","empty grounded answer","without assistant content"];function tZ(e){let t;return function(e){if(e instanceof W.ApiError&&tY.has(e.code))return!0;let t=e instanceof Error?e.message.toLowerCase():"";return 0!==t.length&&tX.some(e=>t.includes(e));}(e)?"The conversation context exceeded the model's window. Open a new chat or pick a larger-context model.":0!==(t=e instanceof Error?e.message.toLowerCase():"").length&&tH.some(e=>t.includes(e))?e instanceof W.ApiError?`${tV} (${e.code})`:tV:(0,tA.formatUserError)(e,"Something went wrong. Try again.");}async function tQ(e){var t;let n,l=Date.now(),r={...e,idempotencyKey:null!=(t=e.idempotencyKey)?t:"u">typeof crypto&&"function"==typeof crypto.randomUUID?crypto.randomUUID():`${Date.now().toString(36)}-${Math.random().toString(36).slice(2)}`,messages:e.messages.map((e,t)=>{var n;return{...e,timestamp:null!=(n=e.timestamp)?n:l+t};})};for(let e=0;e<2;e+=1)try{return await(0,W.appendDesktopChatVoiceTurn)(r);}catch(e){if(n=e,!(!(e instanceof W.ApiError)||e.status>=500))break;}throw n;}function t0(e){return[...e].sort((e,t)=>t.updatedAt-e.updatedAt);}let t1=new Set(),t2=!1;function t4(e){for(let t of t1)t(e);}function t3(e){let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.id&&"string"==typeof t.projectPath&&"string"==typeof t.title&&"string"==typeof t.selectedModel&&(ni(),t4({type:"upsert",chat:t}));}function t5(e){let t=e.detail;"object"==typeof t&&null!==t&&"string"==typeof t.chatId&&(ni(),t4({type:"delete",chatId:t.chatId}));}function t6(e){ni(),window.dispatchEvent(new CustomEvent(t_,{detail:e}));}function t8(e){var t;return null==(t=e.find(tR.isConversationEligibleModel))?void 0:t.id;}function t7(e,t){return void 0!==e&&t.some(t=>t.id===e&&(0,tR.isConversationEligibleModel)(t))?e:t8(t);}function t9(e){return void 0!==e.connectedScope||void 0!==e.connectedScopes&&e.connectedScopes.length>0||void 0!==e.localKnowledgeScope||void 0!==e.localKnowledgeScopes&&e.localKnowledgeScopes.length>0;}let ne={projects:[],chats:[],messages:[],models:[],activeProject:void 0,activeChat:void 0,selectedModel:void 0},nt=0,nn=new Map(),nl=new Map();function nr(e){let t={...e};return void 0!==e.projects&&(t.projects=[...e.projects]),void 0!==e.chats&&(t.chats=[...e.chats]),void 0!==e.messages&&(t.messages=[...e.messages]),void 0!==e.models&&(t.models=[...e.models]),t;}function ni(){nt+=1,t=void 0,n=void 0;}function na(e){return{chats:Array.from(e.chats)};}function no(e){return{messages:Array.from(e.messages)};}function ns(e){let t=nn.get(e);if(void 0!==t)return t.then(na);let n=(0,W.fetchChats)(e).then(na).finally(()=>{nn.get(e)===n&&nn.delete(e);});return nn.set(e,n),n.then(na);}function nc(e,t){let n=`${t}\u0000${e}`,l=nl.get(n);if(void 0!==l)return l.then(no);let r=(0,W.fetchChatMessages)(e,t).then(no).finally(()=>{nl.get(n)===r&&nl.delete(n);});return nl.set(n,r),r.then(no);}class nd extends Error{constructor(){super("run-summary poll aborted"),this.name="PollAbortError";}}let nu=new Map();async function np(e,t,n,l){var r;let i=n.runId;if(void 0===i)return;let a={...(void 0===n.workflowId?{}:{workflowId:n.workflowId}),...(void 0===n.taskType?{}:{taskType:n.taskType})};for(let o=0;o<120;o+=1){let s;if((null==l?void 0:l.aborted)===!0)break;try{let e=await(0,W.fetchRunReport)(i),t=function(e,t){let n=tN(e);if(void 0===n)return{kind:"unknown"};let l=function(e){let t=e.status;if("string"==typeof t)return t;}(n),r=tE(t);return"running"===l?{kind:"running"}:"cancelled"===l?{kind:"terminal",summary:{workflowStatus:"cancelled",shortResult:"Run cancelled."}}:"failed"===l||"rejected"===l?{kind:"terminal",summary:{workflowStatus:"failed",shortResult:tS(function(e){let t,n,l=(t=tN(e.failure),n=null==t?void 0:t.message,"string"==typeof n&&n.length>0?n:void 0);return void 0!==l?tS(`Run failed: ${l}.`):"Run failed.";}(n))}}:void 0!==l&&tC.has(l)?{kind:"terminal",summary:{workflowStatus:"completed",shortResult:tS(function(e,t){if("unit-tests"===t)return function(e){let t,n=e.addedTestFiles;if(Array.isArray(n)){let e=0,l=!1;for(let t of n){let n=tN(t),r=null==n?void 0:n.estimatedTestCount;"number"==typeof r&&Number.isFinite(r)&&(e+=r,l=!0);}l&&(t=e);}let l=Array.isArray(n)?n.length:0;return l>0&&void 0!==t?`Generated ${String(l)} test files; ${String(t)} tests proposed.`:l>0?`Generated ${String(l)} test files.`:"Completed.";}(e);if("bug"===t)return tI();if("verify"===t){let t,n;return t=tN(e.verificationSummary),n=null==t?void 0:t.results,Array.isArray(n)&&n.length>0?`Verification passed: ${String(n.length)} classifications.`:"Verification passed.";}if("explain"===t){let t=e.dryRunPreview;if("string"==typeof t&&t.length>0){let e=t.split("\n").filter(e=>e.trim().length>0);if(e.length>0)return`Plan generated; ${String(e.length)} steps.`;}return"Plan generated.";}return"Completed.";}(n,r))}}:{kind:"unknown"};}(e.report,a);"terminal"===t.kind&&(s=t.summary);}catch(e){if(e instanceof W.ApiError&&404===e.status)try{let e=await(0,W.fetchEvidenceManifest)(i),t=function(e,t){let n=tN(e),l=void 0===n?void 0:tN(n.run),r=void 0===l?void 0:l.outcome,i=tE(t);return"cancelled"===r?{workflowStatus:"cancelled",shortResult:"Run cancelled."}:"failed"===r||"limit-exceeded"===r?{workflowStatus:"failed",shortResult:"Run failed."}:"completed"===r?{workflowStatus:"completed",shortResult:tS("bug"===i?tI():"verify"===i?"Verification passed.":"explain"===i?"Plan generated.":"unit-tests"===i?"Generated tests.":"Completed.")}:{workflowStatus:"completed",shortResult:"Completed."};}(e.manifest,a);s={workflowStatus:"failed"===t.workflowStatus||"cancelled"===t.workflowStatus?t.workflowStatus:"completed",shortResult:t.shortResult};}catch{}else break;}if(void 0!==s){let l=await(0,W.patchChatMessage)(n.id,e.id,t,s);return{chatId:e.id,messageId:n.id,message:l.message};}if(o<119)try{await function(e,t){return(null==t?void 0:t.aborted)===!0?Promise.reject(new nd()):new Promise((n,l)=>{let r=globalThis.setTimeout(()=>{null==t||t.removeEventListener("abort",i),n();},e),i=()=>{globalThis.clearTimeout(r),l(new nd());};null==t||t.addEventListener("abort",i,{once:!0});});}((r=o,Math.min(1e3*2**Math.min(r,4),15e3)),l);}catch{break;}}}async function nf(e){var t;let n=(await(0,W.fetchModels)()).models.filter(tR.isConversationEligibleModel),l=t8(n),r=[...(await(0,W.fetchProjects)().catch(()=>({projects:[]}))).projects].sort((e,t)=>e.favorite!==t.favorite?e.favorite?-1:1:e.lastOpenedAt!==t.lastOpenedAt?t.lastOpenedAt-e.lastOpenedAt:e.path.localeCompare(t.path)),i=null!=(t=r.find(e=>e.available))?t:r[0];if(void 0!==i){let e=t0((await ns(i.path).catch(()=>({chats:[]}))).chats),t=e[0];if(void 0!==t){let l=await nc(t.id,i.path),a=t7(t.selectedModel,n);return{models:n,selectedModel:a,projects:Array.from(r),activeProject:i,chats:e,activeChat:t,messages:Array.from(l.messages)};}}if(void 0===l||!e)return{models:n,selectedModel:l,projects:Array.from(r),activeProject:i,chats:[],activeChat:void 0,messages:[]};let a={modelId:l,title:tB};(null==i?void 0:i.available)===!0&&(a.projectPath=i.path);let o=await(0,W.createDesktopChat)(a);return t6(o.chat),{models:n,selectedModel:o.chat.selectedModel,projects:Array.from(o.projects),activeProject:o.project,chats:t0(o.chats),activeChat:o.chat,messages:Array.from(o.messages)};}let nm="keiko.theme",nh="dark";var ng=e.i(24477);let nv=[{key:"t",mod:["cmd"]},{key:"t",mod:["ctrl"]},{key:"r",mod:["cmd"]},{key:"r",mod:["ctrl"]},{key:"n",mod:["cmd","shift"]},{key:"n",mod:["ctrl","shift"]},{key:"w",mod:["cmd"]},{key:"w",mod:["ctrl"]}];function nw(e){switch(e.kind){case"ui.window.move":return"Move window";case"ui.window.resize":return"Resize window";case"ui.window.zorder":return"Reorder window";case"ui.window.close":return"Close window";case"ui.window.open":return"Open window";case"ui.workspace.pan":return"Pan workspace";case"ui.workspace.zoom":return"Zoom workspace";case"ui.workspace.fit":return"Fit workspace to view";case"ui.panel.toggle":return`Toggle ${e.panel} panel`;case"ui.selection.change":return"Change selection";case"ui.tab.switch":return"Switch tab";}}function ny(e){let t=[...e.mod].sort();return`${t.join("+")}|${e.key.toLowerCase()}`;}let nb={undoStack:[],redoStack:[]};var nk=e.i(99749);class nx extends Error{constructor(e){super(`Workspace keyboard shortcut conflicts detected: ${e.map(e=>`${ny(e.chord)} (${e.commandIds.join(", ")})`).join("; ")}`),(0,nk._)(this,"conflicts",void 0),this.name="WorkspaceShortcutConflictError",this.conflicts=e;}}class nj extends Error{constructor(e){super(`Workspace keyboard shortcut bindings refused: ${e.map(e=>`${e.commandId} → ${ny(e.chord)}`).join("; ")} are browser-reserved`),(0,nk._)(this,"reserved",void 0),this.name="WorkspaceShortcutReservedError",this.reserved=e;}}var nC=e.i(70478);let nS=[{commandId:"undo",chord:{key:"z",mod:["cmd"]}},{commandId:"redo",chord:{key:"z",mod:["cmd","shift"]}},{commandId:"focus-status",chord:{key:"s",mod:["alt"]}}];var nN=e.i(20405),nI=e.i(56782);let nE=()=>(0,l.jsx)("div",{className:"lk-loading",children:"Loading..."}),nR=(0,J.default)(()=>e.A(33333).then(e=>e.ChatWindow),{loadableGenerated:{modules:[72117]},ssr:!1,loading:nE}),nA=(0,J.default)(()=>e.A(44543).then(e=>e.ProjectPanel),{loadableGenerated:{modules:[26507]},ssr:!1,loading:nE}),nP=(0,J.default)(()=>e.A(17024).then(e=>e.ChatHistoryPanel),{loadableGenerated:{modules:[510]},ssr:!1,loading:nE}),nM=(0,J.default)(()=>e.A(50426).then(e=>e.SearchPanel),{loadableGenerated:{modules:[58873]},ssr:!1,loading:nE}),nT=(0,J.default)(()=>e.A(59683).then(e=>e.PromptEnhancerPanel),{loadableGenerated:{modules:[38661]},ssr:!1,loading:nE}),nz=(0,J.default)(()=>e.A(51058).then(e=>e.PluginsPanel),{loadableGenerated:{modules:[27066]},ssr:!1,loading:nE}),nF=(0,J.default)(()=>e.A(53232).then(e=>e.AutomationsPanel),{loadableGenerated:{modules:[21550]},ssr:!1,loading:nE}),nL=(0,J.default)(()=>e.A(42885).then(e=>e.MobilePanel),{loadableGenerated:{modules:[43045]},ssr:!1,loading:nE}),nW=(0,J.default)(()=>e.A(31266).then(e=>e.InspectorPanel),{loadableGenerated:{modules:[1466]},ssr:!1,loading:nE}),n$=(0,J.default)(()=>e.A(4232).then(e=>e.NotificationsPanel),{loadableGenerated:{modules:[90330]},ssr:!1,loading:nE}),nD=(0,J.default)(()=>e.A(45416).then(e=>e.ResourcesPanel),{loadableGenerated:{modules:[82109]},ssr:!1,loading:nE}),nO=(0,J.default)(()=>e.A(68932).then(e=>e.TimelinePanel),{loadableGenerated:{modules:[44884]},ssr:!1,loading:nE}),nK=(0,J.default)(()=>e.A(58212).then(e=>e.KeikoTwinPanel),{loadableGenerated:{modules:[49532]},ssr:!1,loading:nE}),nq=(0,J.default)(()=>e.A(38673).then(e=>e.SettingsPanel),{loadableGenerated:{modules:[91236]},ssr:!1,loading:nE}),nB=(0,J.default)(()=>e.A(70404).then(e=>e.UpdateWindow),{loadableGenerated:{modules:[55263]},ssr:!1,loading:nE}),n_=(0,J.default)(()=>e.A(34479).then(e=>e.FilesWidget),{loadableGenerated:{modules:[31798]},ssr:!1,loading:nE}),nG=(0,J.default)(()=>e.A(55249).then(e=>e.EditorWidget),{loadableGenerated:{modules:[26019]},ssr:!1,loading:nE}),nU=(0,J.default)(()=>e.A(65).then(e=>e.BrowserWidget),{loadableGenerated:{modules:[3246]},ssr:!1,loading:nE}),nJ=(0,J.default)(()=>e.A(45389).then(e=>e.DocumentationBrowserWidget),{loadableGenerated:{modules:[41853]},ssr:!1,loading:nE}),nV=(0,J.default)(()=>e.A(34722).then(e=>e.TerminalWidget),{loadableGenerated:{modules:[43554]},ssr:!1,loading:nE}),nY=(0,J.default)(()=>e.A(75888).then(e=>e.CommandsWidget),{loadableGenerated:{modules:[34484]},ssr:!1,loading:nE}),nX=(0,J.default)(()=>e.A(82309).then(e=>e.RuntimeHubWidget),{loadableGenerated:{modules:[94680]},ssr:!1,loading:nE}),nH=(0,J.default)(()=>e.A(81847).then(e=>e.GitClientWindow),{loadableGenerated:{modules:[12525]},ssr:!1,loading:nE}),nZ=(0,J.default)(()=>e.A(97072).then(e=>e.GovernedPullRequestCard),{loadableGenerated:{modules:[67988]},ssr:!1,loading:nE}),nQ=(0,J.default)(()=>e.A(9e4).then(e=>e.GovernedMergeCard),{loadableGenerated:{modules:[86531]},ssr:!1,loading:nE}),n0=(0,J.default)(()=>e.A(6814).then(e=>e.ContainerStatusWidget),{loadableGenerated:{modules:[50746]},ssr:!1,loading:nE}),n1=(0,J.default)(()=>e.A(20678).then(e=>e.ReviewWidget),{loadableGenerated:{modules:[34264]},ssr:!1,loading:nE}),n2=(0,J.default)(()=>e.A(61721).then(e=>e.AgentRunWidget),{loadableGenerated:{modules:[1867]},ssr:!1,loading:nE}),n4=(0,J.default)(()=>e.A(43759).then(e=>e.IntegrationsWidget),{loadableGenerated:{modules:[21659]},ssr:!1,loading:nE}),n3=(0,J.default)(()=>e.A(99462).then(e=>e.ConnectorPickerWidget),{loadableGenerated:{modules:[20900]},ssr:!1,loading:nE}),n5=(0,J.default)(()=>e.A(93261).then(e=>e.PdfCitationPreviewWindow),{loadableGenerated:{modules:[28867]},ssr:!1,loading:nE}),n6=(0,J.default)(()=>e.A(22699).then(e=>e.FigmaSnapshotWindow),{loadableGenerated:{modules:[7492]},ssr:!1,loading:nE}),n8=(0,J.default)(()=>e.A(58860).then(e=>e.FigmaJsonSourceWindow),{loadableGenerated:{modules:[68188]},ssr:!1,loading:nE}),n7=(0,J.default)(()=>e.A(28945).then(e=>e.FigmaImageSourceWindow),{loadableGenerated:{modules:[41785]},ssr:!1,loading:nE}),n9=(0,J.default)(()=>e.A(25802).then(e=>e.QiHubPanel),{loadableGenerated:{modules:[12124]},ssr:!1,loading:nE}),le=(0,J.default)(()=>e.A(24100).then(e=>e.QiRunCard),{loadableGenerated:{modules:[64403]},ssr:!1,loading:nE}),lt=(0,J.default)(()=>e.A(39644).then(e=>e.RelationshipsView),{loadableGenerated:{modules:[76253]},ssr:!1,loading:nE}),ln=(0,J.default)(()=>e.A(44124).then(e=>e.MemoriaVivaWindow),{loadableGenerated:{modules:[76724]},ssr:!1,loading:nE}),ll=(0,J.default)(()=>e.A(12938).then(e=>e.ConnectorGraph),{loadableGenerated:{modules:[60597]},ssr:!1,loading:nE});function lr(e,t){let n=e[t];return"string"==typeof n?n:void 0;}function li(e,t){var n,l,r;return null!=(n=null!=(l=null!=(r=e.activeRoot)?r:t)?l:e.linkedRoot)?n:void 0;}function la(e,t){let n=e[t];return"number"==typeof n&&Number.isFinite(n)?n:void 0;}function lo(e,t){let n=lr(e,t);if(void 0===n||0===n.trim().length)return[];try{let e=JSON.parse(n);if(!Array.isArray(e))return[];return e.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());}catch{return[];}}function ls(e){var t;let{cfg:n,ctx:a}=e,o=(0,i.useChatSessionContext)(),s=(0,r.useRef)(!1),c=lr(n,"chatId"),d=lr(n,"title"),{updateCfg:u}=a,{activeChat:p,activeProject:f,chats:m,loading:h,openChat:g,openNewChat:v}=o,w=void 0!==p&&"closed"!==p.status?p:void 0;(0,r.useEffect)(()=>{if(!h){if(void 0!==c){if((null==w?void 0:w.id)===c)return;let e=m.find(e=>e.id===c&&"closed"!==e.status);void 0!==e&&g(e);return;}s.current||(s.current=!0,v(void 0,d).then(e=>{void 0!==e&&u({chatId:e.id,title:e.title});}).finally(()=>{s.current=!1;}));}},[c,null==w?void 0:w.id,m,h,g,v,d,u]),(0,r.useEffect)(()=>{h||void 0===c||(null==w?void 0:w.id)!==c||w.title!==d&&u({title:w.title});},[null==w?void 0:w.id,null==w?void 0:w.title,c,h,d,u]);let y=void 0!==c&&!o.loading&&(null==w?void 0:w.id)!==c&&!o.chats.some(e=>e.id===c&&"closed"!==e.status),b=o.loading||void 0!==c&&(null==w?void 0:w.id)!==c,k=(0,r.useCallback)(e=>{var t,n;if(void 0===e.runId)return;let l={runId:e.runId},r=null!=(t=e.workflowId)?t:e.taskType;void 0!==r&&(l.workflow=r);let i=null!=(n=a.activeRoot)?n:null==f?void 0:f.path;void 0!==i&&(l.workspaceRoot=i),a.openWindow("agents",l);},[null==f?void 0:f.path,a]);return y?(0,l.jsxs)("div",{className:"lk-empty",children:[(0,l.jsx)("p",{className:"lk-empty-title",children:"Chat not found"}),(0,l.jsx)("p",{className:"lk-empty-body",children:"This conversation was deleted or is no longer available."})]}):b?(0,l.jsx)("div",{className:"lk-loading",children:"Opening chat..."}):(0,l.jsx)(nR,{windowId:a.windowId,mini:!0===a.mini,minimalChat:!0===a.minimalChat,compact:!0===a.compact,controlsNarrow:!0===a.controlsNarrow,barCompact:!0===a.barCompact,workflowCompact:!0===a.workflowCompact,linkedRoot:null!=(t=a.activeRoot)?t:a.linkedRoot,linkedRoots:a.linkedRoots,openEditorFile:a.openEditorFile,previewWindows:{add:a.openWindow,focus:a.focusWindow,update:a.updateWindow},onOpenRunResult:k});}(0,D.registerWindowRender)("chat",(e,t)=>(0,l.jsx)(ls,{cfg:e,ctx:t})),(0,D.registerWindowRender)("chatHistory",(e,t)=>(0,l.jsx)(nP,{openChatWindow:e=>{t.openWindow("chat",{chatId:e.id,title:e.title});}})),(0,D.registerWindowRender)("project",()=>(0,l.jsx)(nA,{})),(0,D.registerWindowRender)("promptEnhancer",(e,t)=>{var n;return(0,l.jsx)(nT,{connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots});}),(0,D.registerWindowRender)("search",()=>(0,l.jsx)(nM,{})),(0,D.registerWindowRender)("plugins",()=>(0,l.jsx)(nz,{})),(0,D.registerWindowRender)("automations",()=>(0,l.jsx)(nF,{})),(0,D.registerWindowRender)("mobile",()=>(0,l.jsx)(nL,{})),(0,D.registerWindowRender)("inspector",()=>(0,l.jsx)(nW,{})),(0,D.registerWindowRender)("notifications",()=>(0,l.jsx)(n$,{})),(0,D.registerWindowRender)("resources",()=>(0,l.jsx)(nD,{})),(0,D.registerWindowRender)("activity",()=>(0,l.jsx)(nO,{})),(0,D.registerWindowRender)("keiko",()=>(0,l.jsx)(nK,{})),(0,D.registerWindowRender)("settings",(e,t)=>(0,l.jsx)(nq,{openUpdatesWindow:()=>t.openWindow("updates",{entrypoint:"settings"})})),(0,D.registerWindowRender)("updates",()=>(0,l.jsx)(nB,{})),(0,D.registerWindowRender)("localKnowledge",()=>(0,l.jsx)(ll,{showBackToWorkspace:!1})),(0,D.registerWindowRender)("pdfCitationPreview",(e,t)=>(0,l.jsx)(n5,{cfg:e,focusWindow:t.focusWindow,restoreWindow:t.restoreWindow,updateCfg:t.updateCfg,windowId:t.windowId})),(0,D.registerWindowRender)("quality",(e,t)=>{var n;return(0,l.jsx)(n9,{openRun:(e,n)=>{var l;let r,i=void 0!==n?(0,nI.connectedRunSourcesCfgFromInlineSources)(n):(r=(0,nI.buildConnectedRunSources)({connectedFilePath:null!=(l=t.linkedFilePath)?l:null,connectedRoot:t.linkedRoot,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources}),(0,nI.connectedRunSourcesCfgFromSources)(r));t.openWindow("qiRun",{runId:e,...i});},connectedRoot:t.linkedRoot,connectedFilePath:null!=(n=t.linkedFilePath)?n:null,connectedRoots:t.linkedRoots,connectedCapsuleIds:t.linkedCapsuleIds,connectedCapsuleSetIds:t.linkedCapsuleSetIds,connectedFigmaSnapshotRunIds:t.linkedFigmaSnapshotRunIds,connectedFigmaSnapshotSources:t.linkedFigmaSnapshotSources,connectedImageSources:t.linkedImageSources});}),(0,D.registerWindowRender)("qiRun",(e,t)=>{let n=lr(e,"runId");if(void 0===n||""===n)return(0,l.jsx)("div",{className:"lk-empty",children:(0,l.jsx)("p",{className:"lk-empty-body",children:"Open a run from the Quality Intelligence hub."})});let r=(0,nI.connectedRunSourcesFromWindowCfg)(e),i=(0,nI.connectedRunSourcesCfgFromSources)(r);return(0,l.jsx)(le,{runId:n,connectedSources:r,onRegenerated:e=>{t.openWindow("qiRun",{runId:e.runId,...i});}});}),(0,D.registerWindowRender)("relationships",()=>(0,l.jsx)(lt,{})),(0,D.registerWindowRender)("files",(e,t)=>{let n=li(t,lr(e,"root")),r=(e,n,l)=>{let r={activeFilePath:null!=e?e:void 0,resolvedRoot:null!=n?n:void 0};void 0!==l&&(r.activeDirectoryPath=null!=l?l:void 0),t.updateCfg(r);},i=e=>{t.updateCfg({root:e,activeFilePath:void 0,activeDirectoryPath:void 0,resolvedRoot:void 0});},a=(e,n)=>{t.openWindow("editor",{root:e,file:n,openFiles:[n]});},o=e=>{t.openWindow("governedGit",{projectPath:e});};return void 0!==n?(0,l.jsx)(n_,{root:n,onActiveFileChange:r,onRootChange:i,onOpenFile:a,onOpenGitDelivery:o}):(0,l.jsx)(n_,{onActiveFileChange:r,onRootChange:i,onOpenFile:a,onOpenGitDelivery:o});}),(0,D.registerWindowRender)("editor",(e,t)=>{var n;let r=li(t,lr(e,"root")),i=lr(e,"file"),a=function(e,t){let n=e[t];if(!Array.isArray(n))return;let l=n.filter(e=>"string"==typeof e&&e.trim().length>0).map(e=>e.trim());return l.length>0?l:void 0;}(e,"openFiles"),o=lr(e,"layoutJson"),s=la(e,"revealLineStart"),c=la(e,"revealLineEnd"),d=lr(e,"revealRequestId"),u={};return void 0!==r&&(u.root=r),void 0!==i&&(u.file=i),void 0!==a&&(u.openFiles=a),void 0!==o&&(u.layoutJson=o),void 0!==s&&(u.revealLineStart=s),void 0!==c&&(u.revealLineEnd=c),void 0!==d&&(u.revealRequestId=d),u.linkedRoot=t.linkedRoot,u.linkedFilePath=t.linkedFilePath,u.linkedCapsuleIds=t.linkedCapsuleIds,u.linkedCapsuleSetIds=t.linkedCapsuleSetIds,u.windowId=t.windowId,u.onWorkspaceChange=e=>{t.updateCfg(e);},(0,l.jsx)(nG,{...u},null!=(n=t.activeRoot)?n:"unbound");}),(0,D.registerWindowRender)("browser",e=>{let t=lr(e,"url");return void 0!==t&&""!==t?(0,l.jsx)(nU,{url:t}):(0,l.jsx)(nU,{});}),(0,D.registerWindowRender)("docbrowser",e=>{let t=lr(e,"target");return void 0!==t&&""!==t?(0,l.jsx)(nJ,{target:t}):(0,l.jsx)(nJ,{});}),(0,D.registerWindowRender)("terminal",(e,t)=>{var n;let r=li(t,lr(e,"projectPath")),i=null!=(n=t.activeRoot)?n:lr(e,"cwd"),a={};return void 0!==i&&(a.cwd=i),void 0!==r&&(a.projectPath=r),(0,l.jsx)(nV,{...a});}),(0,D.registerWindowRender)("commands",(e,t)=>{let n=li(t,lr(e,"projectPath")),r={};return void 0!==n&&(r.projectPath=n),(0,l.jsx)(nY,{...r});}),(0,D.registerWindowRender)("runtime",(e,t)=>{let n=li(t,lr(e,"projectPath")),r=(e,n)=>{t.openWindow(e,{projectPath:n});};return(0,l.jsx)(nX,{projectPath:n,onProjectPathChange:e=>t.updateCfg({projectPath:e}),onOpenFiles:e=>{t.openWindow("files",void 0!==e?{root:e}:void 0);},onOpenCommands:e=>r("commands",e),onOpenContainers:e=>{t.openWindow("containerStatus",void 0!==e?{projectPath:e}:void 0);},onOpenGovernedGit:e=>r("governedGit",e),onOpenPullRequest:e=>r("governedPullRequest",e),onOpenMerge:e=>r("governedMerge",e)});}),(0,D.registerWindowRender)("governedGit",(e,t)=>{var n;let r=li(t,null!=(n=lr(e,"projectPath"))?n:lr(e,"workspaceRoot"));return(0,l.jsx)(nH,{projectId:r,onOpenFiles:e=>t.openWindow("files",{root:e}),onOpenEditor:e=>t.openWindow("editor",{root:e}),updateCfg:e=>t.updateCfg(e)});}),(0,D.registerWindowRender)("governedPullRequest",(e,t)=>{var n,r;let i=li(t,null!=(n=lr(e,"projectPath"))?n:lr(e,"workspaceRoot")),a=null!=(r=lr(e,"headBranchName"))?r:void 0;return(0,l.jsx)(nZ,{projectId:i,headBranchName:a});}),(0,D.registerWindowRender)("governedMerge",(e,t)=>{var n,r;let i=li(t,null!=(n=lr(e,"projectPath"))?n:lr(e,"workspaceRoot")),a=null!=(r=lr(e,"headBranchName"))?r:void 0;return(0,l.jsx)(nQ,{projectId:i,headBranchName:a});}),(0,D.registerWindowRender)("containerStatus",(e,t)=>{let n=li(t,lr(e,"projectPath")),r={};return void 0!==n&&(r.projectPath=n),(0,l.jsx)(n0,{...r});}),(0,D.registerWindowRender)("review",(e,t)=>{let n=lr(e,"runId"),r=e=>{t.updateCfg({runId:e});};return void 0!==n&&""!==n?(0,l.jsx)(n1,{runId:n,onRunIdSubmit:r}):(0,l.jsx)(n1,{onRunIdSubmit:r});}),(0,D.registerWindowRender)("agents",(e,t)=>{var n;let r,i,a,o,s,c,d,u,p,f,m;return(0,l.jsx)(n2,{cfg:(a={},void 0!==(o=lr(n=e,"workflow"))&&(a.workflow=o),void 0!==(s=lr(n,"model"))&&(a.model=s),void 0!==(c=lr(n,"runId"))&&(a.runId=c),void 0!==(d=lr(n,"fingerprint"))&&(a.fingerprint=d),void 0!==(u=lr(n,"workspaceRoot"))&&(a.workspaceRoot=u),void 0!==(p=lr(n,"inputJson"))&&(a.inputJson=p),void 0!==(f="boolean"==typeof(r=n.keikoMode)?r:void 0)&&(a.keikoMode=f),void 0!==(m="ask"===(i=n.access)||"full"===i?i:void 0)&&(a.access=m),a),linkedRoot:t.linkedRoot,linkedFilePath:t.linkedFilePath});}),(0,D.registerWindowRender)("memoria",()=>(0,l.jsx)(ln,{})),(0,D.registerWindowRender)("integ",()=>(0,l.jsx)(n4,{})),(0,D.registerWindowRender)("figma",(e,t)=>{let n=lr(e,"snapshotRunId"),r=lo(e,"selectedScreenIdsJson"),i=lr(e,"selectedScreenName");return(0,l.jsx)(n6,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:r,selectedScreenName:i,openScreenSource:e=>{let{snapshotRunId:n,screenId:l,name:r}=e;t.openWindow("figmaView",{snapshotRunId:n,selectedScreenIdsJson:JSON.stringify([l]),selectedScreenName:r});},openTokenSettings:()=>{(0,nN.requestGatewaySetup)(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),(0,D.registerWindowRender)("figmaView",(e,t)=>{let n=lr(e,"snapshotRunId"),r=lo(e,"selectedScreenIdsJson"),i=lr(e,"selectedScreenName");return(0,l.jsx)(n6,{sourceWindowId:t.windowId,snapshotRunId:n,selectedScreenIds:r,selectedScreenName:i,openTokenSettings:()=>{(0,nN.requestGatewaySetup)(),t.openWindow("settings");},updateCfg:e=>{t.updateCfg(e);}});}),(0,D.registerWindowRender)("figmaJson",e=>{let t=lr(e,"snapshotRunId"),n=lr(e,"screenId"),r=lr(e,"selectedScreenName");return(0,l.jsx)(n8,{snapshotRunId:t,screenId:n,screenName:r});}),(0,D.registerWindowRender)("figmaImage",e=>{let t=lr(e,"imageSrc"),n=lr(e,"selectedScreenName");return(0,l.jsx)(n7,{imageSrc:t,screenName:n});}),(0,D.registerWindowRender)("connector",(e,t)=>{let n=lr(e,"presentation"),r=lr(e,"selectedKind"),i=lr(e,"selectedId"),a=lr(e,"selectedLabel"),o=lr(e,"selectedState");return(0,l.jsx)(n3,{presentation:n,selectedKind:r,selectedId:i,selectedLabel:a,selectedState:o,onSelect:e=>{t.updateCfg(e);},onManageConnectors:()=>{t.openWindow("localKnowledge");}});});let lc={supported:{heading:"Install Keiko",body:"Keep Keiko in your app shelf for fast access.",install:"Install Keiko"},"ios-add-to-home":{heading:"Install Keiko",body:'On iOS Safari, tap Share, then "Add to Home Screen".',install:null}};function ld(){let{available:e,triggerInstall:t}=function(){let[e,t]=(0,r.useState)(!1),n=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=e=>{e.preventDefault(),function(e){if("function"!=typeof e.prompt)return!1;let t=e.userChoice;return"object"==typeof t&&null!==t&&"function"==typeof t.then;}(e)&&(n.current=e,t(!0));},l=()=>{localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);};return window.addEventListener("beforeinstallprompt",e,{passive:!1}),window.addEventListener("appinstalled",l),()=>{window.removeEventListener("beforeinstallprompt",e),window.removeEventListener("appinstalled",l);};},[]),{available:e,triggerInstall:(0,r.useCallback)(async()=>{let e=n.current;if(null===e)return;await e.prompt();let{outcome:l}=await e.userChoice;"accepted"===l&&localStorage.setItem("keiko.pwa.installed","true"),n.current=null,t(!1);},[])};}(),[n,i]=(0,r.useState)(!1),[a]=(0,r.useState)(()=>{let e;return"u">typeof navigator?(e=navigator.userAgent.toLowerCase()).includes("crios/")?"manual":e.includes("chrome/")&&!e.includes("mobile")||e.includes("edg/")||e.includes("chromium/")?"supported":e.includes("firefox/")?"manual":e.includes("safari/")&&(e.includes("iphone")||e.includes("ipad")||e.includes("ipod"))?"ios-add-to-home":(e.includes("safari/")&&e.includes("macintosh"),"manual"):"manual";}),o=(0,r.useRef)(null),s=(0,r.useCallback)(()=>{localStorage.setItem("keiko.pwa.dismissed",new Date().toISOString()),i(!0);},[]),c=(0,r.useCallback)(async()=>{await t();},[t]),d=(0,r.useCallback)(e=>{"Escape"!==e.key||e.defaultPrevented||s();},[s]);if(n||window.matchMedia("(display-mode: standalone)").matches||"true"===localStorage.getItem("keiko.pwa.installed")||function(){let e=localStorage.getItem("keiko.pwa.dismissed");if(null===e)return!1;let t=Date.parse(e);return!!Number.isNaN(t)||Date.now()-t<2592e6;}()||"supported"===a&&!e||"supported"!==a&&"ios-add-to-home"!==a)return null;let u=lc[a];return(0,l.jsx)("aside",{className:"install-banner",role:"region","aria-label":"Install Keiko",onKeyDown:d,children:(0,l.jsxs)("div",{className:"install-banner-body",children:[(0,l.jsxs)("div",{className:"install-banner-text",children:[(0,l.jsx)("span",{className:"install-banner-heading",children:u.heading}),(0,l.jsx)("span",{className:"install-banner-desc",children:u.body})]}),(0,l.jsxs)("div",{className:"install-banner-actions",children:[null!==u.install&&(0,l.jsx)("button",{ref:o,type:"button",className:"install-banner-btn-install",onClick:()=>void c(),children:u.install}),(0,l.jsx)("button",{type:"button",className:"install-banner-btn-dismiss",onClick:s,children:"Not now"})]})]})});}e.i(47167);let lu="keiko.service-worker-update-reload-pending",lp=!1;function lf(){lp||function(){try{if("true"!==window.sessionStorage.getItem(lu))return!1;return window.sessionStorage.removeItem(lu),!0;}catch{return!0;}}()&&(lp=!0,window.location.reload());}function lm(e){let t=e.waiting;if(null!==t){try{window.sessionStorage.setItem(lu,"true");}catch{}try{t.postMessage({type:"KEIKO_ACTIVATE_WAITING_SERVICE_WORKER"});}catch{try{window.sessionStorage.removeItem(lu);}catch{}}}}var lh=e.i(71187);function lg(e){var t;return`keiko.updateStartupNotice.dismissed.${[e.currentVersion,null!=(t=e.targetVersion)?t:"no-target",e.status,e.severity,e.manualUpdateRequired?"manual":"automatic",e.userActionRequired?"action":"no-action",e.blockers.map(e=>e.code).slice().sort().join(",")].join("|")}`;}function lv(e){try{window.localStorage.setItem(lg(e),"1");}catch{}}function lw(e){var t;let{ready:n,openUpdates:i,fetchReport:a=W.fetchStartupUpdatePreflight}=e,o=(0,$.useTranslate)(),[s,c]=(0,r.useState)({status:"idle"});if((0,r.useEffect)(()=>{if(!n||"idle"!==s.status)return;let e=!1;return a().then(t=>{if(!e&&(0,lh.hasStartupUpdateSignal)(t)){if(function(e){try{return"1"===window.localStorage.getItem(lg(e));}catch{return!1;}}(t))return void c({status:"dismissed"});c({status:"ready",report:t});}}).catch(()=>void 0),()=>{e=!0;};},[a,n,s.status]),"ready"!==s.status)return null;let d="critical"===s.report.severity,u=null!=(t=s.report.targetVersion)?t:o("updates.versionUnknown");return(0,l.jsxs)("aside",{className:"update-notice","data-severity":d?"critical":"normal",role:d?"alert":"status","aria-live":d?"assertive":"polite","aria-label":o("updates.notice.aria"),children:[(0,l.jsx)("span",{className:"update-notice-icon","aria-hidden":"true",children:d?(0,l.jsx)(I.Icons.info,{size:17}):(0,l.jsx)(I.Icons.activity,{size:17})}),(0,l.jsxs)("div",{className:"update-notice-body",children:[(0,l.jsx)("strong",{children:o(d?"updates.notice.criticalTitle":"updates.notice.title")}),(0,l.jsx)("span",{children:o("updates.notice.body",{version:u})})]}),(0,l.jsxs)("div",{className:"update-notice-actions",children:[(0,l.jsx)("button",{type:"button",className:"update-notice-primary",onClick:()=>{lv(s.report),i(),c({status:"dismissed"});},children:o("updates.notice.review")}),(0,l.jsx)("button",{type:"button",className:"update-notice-dismiss",onClick:()=>{lv(s.report),c({status:"dismissed"});},children:o("updates.notice.notNow")})]})]});}function ly(e){return null===e||void 0===e.root?null:[e.root.replace(/\\/gu,"/").replace(/\/+$/u,""),e.kind,...e.relativePaths.map(e=>e.replace(/\\/gu,"/").replace(/^\/+|\/+$/gu,""))].join("\0");}function lb(e,t){if(/^\/+$/u.test(e.trim().replace(/\\/gu,"/"))){let e=t.trim().replace(/\\/gu,"/");return 0===e.length?"":e.replace(/^\/+/u,"");}let n=(0,nC.resolveWorkspaceFileIdentifier)(e,t);return"relative"===n.kind?n.path:"root"===n.kind||"empty"===n.kind?"":null;}let lk=["chat","connector","files","editor","agents","docbrowser"],lx=["chatHistory","memoria","settings","automations","mobile","inspector","activity","notifications","resources","localKnowledge","governedGit","figma","quality","promptEnhancer","relationships"];function lj(e){requestAnimationFrame(()=>{var t;let n=document.querySelector(`[data-window-id="${e}"]`);null===n||(null!=(t=n.querySelector("textarea, input, select, button, [tabindex]"))?t:n).focus();});}function lC(){var e,a,s,d,u,p,f,m,I,E,R;let A,P=(0,$.useTranslate)(),{theme:M,toggle:T}=function(){let[e,t]=(0,r.useState)(nh),[n,l]=(0,r.useState)(!1);return(0,r.useEffect)(()=>{t(function(){try{let e=window.localStorage.getItem(nm);return"light"===e||"dark"===e?e:nh;}catch{return nh;}}()),l(!0);},[]),(0,r.useEffect)(()=>{if(n){"u">typeof document&&(document.documentElement.dataset.theme=e);try{window.localStorage.setItem(nm,e);}catch{}}},[e,n]),{theme:e,toggle:(0,r.useCallback)(()=>{t(e=>"light"===e?"dark":"light");},[])};}(),O=(0,F.useTwin)(),B=function(){var e,l,i,a;let o=arguments.length>0&&void 0!==arguments[0]?arguments[0]:{},s=null==(e=o.autoCreate)||e,[c,d]=(0,r.useState)(ne),[u,p]=(0,r.useState)(),[f,m]=(0,r.useState)(""),[h,g]=(0,r.useState)(!0),[v,w]=(0,r.useState)("idle"),[y,b]=(0,r.useState)(),k=tJ(v),x=(0,r.useRef)("idle"),j=(0,r.useRef)(null),[C,S]=(0,r.useState)(),[N,I]=(0,r.useState)(),[E,R]=(0,r.useState)(),{memoryEnabled:A,setMemoryEnabled:P,memoryBudgetTokens:M,setMemoryBudgetTokens:T}=(0,tK.useConversationMemorySettings)(),z=(0,r.useRef)(!0),F=(0,r.useRef)(void 0),L=(e,t)=>t.aborted||F.current!==e,$=(0,r.useRef)(void 0),D=(0,r.useRef)(new Set()),O=(0,r.useRef)(new AbortController()),K=(0,r.useRef)(new Set()),q=(0,r.useRef)(0),B=(0,r.useRef)([]),[_,G]=(0,r.useState)([]),U=(0,r.useRef)([]);U.current=_;let[J,V]=(0,r.useState)([]),Y=(0,r.useCallback)(async e=>{var t;let n,l;if(0===e.size)return{ok:!1,reason:"empty"};if(e.size>tx.MAX_ATTACHMENT_BYTES)return{ok:!1,reason:"oversized"};let r=(t=e.type,"unsupported"===(l=(0,tx.classifyAttachmentMime)(t))?"unsupported-type":l);if("unsupported-type"===r)return{ok:!1,reason:"unsupported-type"};let i=c.models.find(e=>e.id===c.selectedModel);if(void 0!==i&&("image"===r&&!i.supportsImageInput||"document"===r&&!i.supportsDocumentInput))return{ok:!1,reason:"text-only-model"};if("image"===r)try{n=URL.createObjectURL(e);}catch{return{ok:!1,reason:"unsupported-type"};}let a={id:crypto.randomUUID(),kind:r,name:e.name,mimeType:e.type,sizeBytes:e.size,previewUrl:n,file:e};return G(e=>[...e,a]),{ok:!0};},[c.models,c.selectedModel]),X=(0,r.useCallback)(e=>{G(t=>{let n=t.find(t=>t.id===e);return void 0!==n&&tq(n),t.filter(t=>t.id!==e);});},[]),H=(0,r.useCallback)(()=>{G(e=>{for(let t of e)tq(t);return 0===e.length?e:[];});},[]),Z=(0,r.useCallback)(async()=>{let e=_.filter(e=>"document"===e.kind&&void 0!==e.file).map(e=>({id:e.id,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes,file:e.file}));if(0===e.length)return{entries:[],disclosures:[]};let{entries:t,failures:n}=await tO(e);n.length>0&&S(n.join(" "));let l=t.map(e=>({id:e.id,displayName:e.displayName,truncated:e.truncated}));return{entries:t,disclosures:l};},[_]),Q=(0,r.useCallback)(()=>_.map(e=>({id:e.id,kind:e.kind,name:e.name,mimeType:e.mimeType,sizeBytes:e.sizeBytes})),[_]),ee=(0,r.useCallback)(()=>{R(void 0);},[]),et=(0,r.useCallback)((e,t)=>({enabled:A,budgetTokens:M,context:{userId:"local-operator",workspaceId:t.path,projectId:t.path,conversationId:e.id}}),[M,A]),en=(0,r.useCallback)(async e=>{await(0,tj.acceptMemoryProposal)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),el=(0,r.useCallback)(async e=>{await(0,tj.rejectMemoryProposal)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"candidate"!==t.kind||t.proposalId!==e)});},[]),er=(0,r.useCallback)(async e=>{await(0,tj.forgetMemory)(e),R(t=>void 0===t?t:{...t,actions:t.actions.filter(t=>"forget"!==t.kind||t.memoryId!==e)});},[]),ei=(0,r.useCallback)(e=>{x.current=e,w(e);},[]),ea=(0,r.useCallback)(async(e,t,n,l)=>{try{var r;let i=await function(e,t,n,l){var r;let i=`${e.id}:${t}:${n.id}:${null!=(r=n.runId)?r:""}`,a=nu.get(i);if(void 0!==a)return a;let o=np(e,t,n,l).finally(()=>{nu.get(i)===o&&nu.delete(i);});return nu.set(i,o),o;}(e,t,n,null==(r=O.current)?void 0:r.signal);if(void 0===i){z.current&&K.current.add(l);return;}if(!z.current||F.current!==e.id)return;d(t=>{var n;return(null==(n=t.activeChat)?void 0:n.id)!==e.id?t:{...t,messages:t.messages.map(e=>e.id===i.messageId?i.message:e)};});}finally{D.current.delete(l);}},[]);(0,r.useEffect)(()=>{var e;F.current=null==(e=c.activeChat)?void 0:e.id;},[null==(l=c.activeChat)?void 0:l.id]),(0,r.useEffect)(()=>{var e;$.current=null==(e=c.activeProject)?void 0:e.path;},[null==(i=c.activeProject)?void 0:i.path]),(0,r.useEffect)(()=>{B.current=c.models;},[c.models]),(0,r.useEffect)(()=>{let e=!1;return async function(){g(!0),S(void 0);try{let l=await function(e){if(e)return nf(e);let l=Date.now();if(void 0!==t&&t.expiresAt>l)return Promise.resolve(nr(t.value));if(void 0!==n)return n.then(nr);let r=nt,i=nf(!1).then(e=>{let n=nr(e);return nt===r&&(t={expiresAt:Date.now()+2e3,value:n}),nr(n);}).finally(()=>{n===i&&(n=void 0);});return n=i,i.then(nr);}(s);e||d(e=>({...e,...l}));}catch(t){e||S(tZ(t));}finally{e||g(!1);}}(),()=>{e=!0;};},[s]),(0,r.useEffect)(()=>{var e;return e=e=>{if("upsert"===e.type){let{chat:t}=e;d(e=>{var n,l;return{...e,chats:t0([t,...e.chats.filter(e=>e.id!==t.id)]),activeChat:(null==(n=e.activeChat)?void 0:n.id)===t.id?t:e.activeChat,selectedModel:(null==(l=e.activeChat)?void 0:l.id)===t.id?t7(t.selectedModel,e.models):e.selectedModel};});return;}d(t=>{var n,l;return{...t,chats:t.chats.filter(t=>t.id!==e.chatId),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chatId?void 0:t.activeChat,messages:(null==(l=t.activeChat)?void 0:l.id)===e.chatId?[]:t.messages};});},t1.add(e),t2||(window.addEventListener(t_,t3),window.addEventListener(tG,t5),t2=!0),()=>{t1.delete(e),t2&&!(t1.size>0)&&(window.removeEventListener(t_,t3),window.removeEventListener(tG,t5),t2=!1);};},[]),(0,r.useEffect)(()=>(z.current=!0,O.current.signal.aborted&&(O.current=new AbortController()),()=>{var e;for(let t of(z.current=!1,null==(e=j.current)||e.abort(),O.current.abort(),U.current))tq(t);}),[]),(0,r.useEffect)(()=>{let e=c.activeChat,t=c.activeProject;if(void 0!==e&&void 0!==t)for(let n of c.messages){if("system"!==n.role||"string"!=typeof n.runId||void 0!==n.workflowStatus&&"pending"!==n.workflowStatus&&"running"!==n.workflowStatus)continue;let l=n.runId;if(void 0===l)continue;let r=`${n.id}:${l}`;!D.current.has(r)&&(K.current.has(r)||(D.current.add(r),ea(e,t.path,n,r)));}},[c.activeChat,c.activeProject,c.messages,ea]);let eo=(0,r.useCallback)(e=>{let t;S(void 0),d(n=>(t={selectedModel:n.selectedModel,activeChat:n.activeChat,chats:n.chats},{...n,selectedModel:e,activeChat:void 0===n.activeChat?n.activeChat:{...n.activeChat,selectedModel:e},chats:n.chats.map(t=>void 0!==n.activeChat&&t.id===n.activeChat.id?{...t,selectedModel:e}:t)})),G(t=>{let n=t.filter(t=>{let n;return void 0===(n=B.current.find(t=>t.id===e))||("image"===t.kind?n.supportsImageInput:n.supportsDocumentInput);});if(n.length===t.length)return t;let l=new Set(n.map(e=>e.id));for(let e of t)l.has(e.id)||tq(e);return n;});let n=F.current;if(void 0===n)return;let l=q.current+1;q.current=l,(0,W.updateChat)(n,{selectedModel:e}).then(e=>{q.current!==l||F.current===e.chat.id&&(t6(e.chat),d(t=>{var n;return{...t,selectedModel:e.chat.selectedModel,activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.chat.id?e.chat:t.activeChat,chats:t.chats.map(t=>t.id===e.chat.id?e.chat:t)};}));}).catch(e=>{if(q.current===l&&F.current===n&&(S(tZ(e)),void 0!==t)){let e=t;d(t=>{var l,r;return{...t,selectedModel:(null==(l=t.activeChat)?void 0:l.id)===n?e.selectedModel:t.selectedModel,activeChat:(null==(r=t.activeChat)?void 0:r.id)===n?e.activeChat:t.activeChat,chats:t.chats.map(t=>{if(t.id!==n)return t;let l=e.chats.find(e=>e.id===n);return void 0!==l?{...t,selectedModel:l.selectedModel}:t;})};});}});},[]),es=(0,r.useCallback)(async(e,t)=>{let n=t7(c.selectedModel,c.models);if(void 0===n)return void S("No conversation-eligible model is configured. Connect a gateway in Settings.");S(void 0),p(void 0);try{var l,r;let i=null==t?void 0:t.trim(),a={modelId:n,title:void 0!==i&&i.length>0?i:tB},o=null!=(l=null==e?void 0:e.path)?l:null==(r=c.activeProject)?void 0:r.path;void 0!==o&&(a.projectPath=o);let s=await(0,W.createDesktopChat)(a);if(void 0!==o&&$.current!==o)return;return F.current=s.chat.id,$.current=s.project.path,t6(s.chat),d({projects:Array.from(s.projects),chats:t0(s.chats),messages:Array.from(s.messages),models:c.models,activeProject:s.project,activeChat:s.chat,selectedModel:s.chat.selectedModel}),s.chat;}catch(e){S(tZ(e));return;}},[c.selectedModel,c.activeProject,c.models]),ec=(0,r.useCallback)(async e=>{S(void 0),p(void 0),$.current=e.path,d(t=>({...t,activeProject:e}));try{let t=await ns(e.path);if($.current!==e.path)return;let n=t0(t.chats),l=n[0];if(void 0===l){if($.current!==e.path)return;await es(e);return;}let r=await nc(l.id,e.path);if($.current!==e.path)return;F.current=l.id;let i=t7(l.selectedModel,c.models);d(e=>({...e,chats:n,activeChat:l,selectedModel:i,messages:Array.from(r.messages)})),R(void 0);}catch(t){if($.current!==e.path)return;S(tZ(t));}},[es,c.models]),ed=(0,r.useCallback)(async e=>{var t,n;if(F.current!==e.id||(null==(t=c.activeChat)?void 0:t.id)!==e.id){S(void 0),p(void 0),null==(n=j.current)||n.abort(),j.current=null,F.current=e.id,I(void 0),R(void 0),V([]);try{let t,n=await nc(e.id,e.projectPath);if(t=e.id,F.current!==t)return;let l=t7(e.selectedModel,c.models);d(t=>{let r=t.projects.find(t=>t.path===e.projectPath);return{...t,activeProject:r,activeChat:e,selectedModel:l,messages:Array.from(n.messages)};});}catch(n){let t;if(t=e.id,F.current!==t)return;S(tZ(n));}}},[null==(a=c.activeChat)?void 0:a.id,c.models]),eu=(0,r.useCallback)(async e=>{let t=e.trim();if(0!==t.length){S(void 0);try{let e=await(0,W.createProject)({path:t}),n=await(0,W.fetchProjects)();d(e=>({...e,projects:Array.from(n.projects)})),await es(e.project);}catch(e){S(tZ(e));}}},[es]),ep=(0,r.useCallback)(e=>{p(t=>(null==t?void 0:t.id)===e?void 0:t),d(t=>({...t,messages:t.messages.filter(t=>t.id!==e)}));},[]),ef=(0,r.useCallback)((e,t,n,l,r)=>{let i=!1,a="",o=null,s="function"==typeof requestAnimationFrame,c=()=>{if(o=null,0===a.length)return;let e=a;a="",p(n=>(null==n?void 0:n.id)===t?{...n,content:n.content+e}:n);},u=()=>{null!==o&&"function"==typeof cancelAnimationFrame&&cancelAnimationFrame(o),o=null;};return{onToken:t=>{if(!L(e,l)){if(i||(ei("streaming"),i=!0),a+=t,!s)return void c();null===o&&(o=requestAnimationFrame(c));}},onDone:i=>{if(u(),c(),L(e,l)){p(e=>(null==e?void 0:e.id)===t?void 0:e),r("cancelled");return;}p(e=>(null==e?void 0:e.id)===t?void 0:e),d(e=>({...e,activeChat:i.chat,chats:t0([i.chat,...e.chats.filter(e=>e.id!==i.chat.id)]),messages:[...e.messages.filter(e=>e.id!==n&&e.id!==t),...Array.from(i.messages)]})),t6(i.chat),void 0!==i.memory&&R(i.memory),r("completed");},onError:n=>{let{code:i,message:o}=n;if(u(),a="",L(e,l)){ep(t),r("cancelled");return;}S(tZ(new W.ApiError(i,o,0))),ep(t),r("failed");},onCancelled:()=>{u(),a="",ep(t),r("cancelled");}};},[ep,ei]),em=(0,r.useCallback)((e,t,n,l,r,i,a,o)=>{let s=`stream-${String(Date.now())}`;p({id:s,chatId:e.id,role:"assistant",content:"",timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0});let c={chatId:e.id,projectPath:t.path,content:n,modelId:r,memory:et(e,t),...(a.length>0?{documentContext:a}:{}),...(o.length>0?{attachments:o}:{})};return new Promise((t,n)=>{let r=ef(e.id,s,l,i,t);(0,W.sendDesktopChatStream)(c,i,r).catch(r=>{ep(s),r instanceof W.StreamingUnavailableError?n(r):r instanceof DOMException&&"AbortError"===r.name||L(e.id,i)?t("cancelled"):(S(tZ(r)),d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),t("failed"));});});},[et,ef,ep]),eh=(0,r.useCallback)(async(e,t,n,l,r,i,a,o)=>{try{ei("contacting");let s=await(0,W.sendDesktopChat)({chatId:e.id,projectPath:t.path,content:n,modelId:r,memory:et(e,t),...(a.length>0?{documentContext:a}:{}),...(o.length>0?{attachments:o}:{})},i);if(L(e.id,i))return"cancelled";return d(e=>({...e,activeChat:s.chat,chats:t0([s.chat,...e.chats.filter(e=>e.id!==s.chat.id)]),messages:[...e.messages.filter(e=>e.id!==l),...Array.from(s.messages)]})),t6(s.chat),R(s.memory),"completed";}catch(n){if(n instanceof DOMException&&"AbortError"===n.name||L(e.id,i))return"cancelled";S(tZ(n));try{let n=await(0,W.fetchChatMessages)(e.id,t.path);d(e=>({...e,messages:Array.from(n.messages)}));}catch{d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)}));}return"failed";}},[et,ei]),eg=(0,r.useCallback)(async(e,t,n,l,r,i,a,o)=>{var s;if((null==(s=c.models.find(e=>e.id===r))?void 0:s.streaming)!==!0)return eh(e,t,n,l,r,i,a,o);ei("contacting");try{return await em(e,t,n,l,r,i,a,o);}catch(e){if(!(e instanceof W.StreamingUnavailableError))throw e;}return eh(e,t,n,l,r,i,a,o);},[c.models,eh,em,ei]),ev=(0,r.useCallback)(async(e,t,n,l,r,i)=>{I(void 0);try{let t;ei("contacting");let l=await(0,W.askGrounded)({chatId:e.id,content:n,modelId:r},i);if(t=e.id,F.current!==t)return"completed";if(i.aborted)return"cancelled";I(l),R(void 0);let[a,o]=await Promise.all([(0,W.fetchChatMessages)(e.id,e.projectPath),(0,W.fetchChats)(e.projectPath)]),s=o.chats.find(t=>t.id===e.id);return d(e=>({...e,messages:Array.from(a.messages),chats:t0(o.chats),activeChat:null!=s?s:e.activeChat})),void 0!==s&&t6(s),"completed";}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return"cancelled";return S(tZ(e)),d(e=>({...e,messages:e.messages.filter(e=>e.id!==l)})),"failed";}},[ei]),ew=(0,r.useCallback)(()=>{var e;tJ(x.current)&&(null==(e=j.current)||e.abort(),j.current=null,b(void 0),ei("cancelled"));},[ei]),ey=(0,r.useCallback)(async e=>{var t;if(tJ(x.current))return;let n=(null!=(t=null==e?void 0:e.text)?t:f).trim(),l=c.activeChat,r=c.activeProject,i=t7(c.selectedModel,c.models);if(0===n.length||void 0===l||void 0===r||void 0===i)return;if(t9(l)&&_.length>0)return void S("Attachments are not supported for grounded chats. Remove the attachment or switch to a non-grounded chat.");let a={id:`local-${String(Date.now())}`,chatId:l.id,role:"user",content:n,timestamp:Date.now(),runId:void 0,workflowId:void 0,workflowStatus:void 0,shortResult:void 0,taskType:void 0};ei("queued"),m(""),S(void 0),d(e=>({...e,messages:[...e.messages,a]}));let o=new AbortController();j.current=o,R(void 0);try{let e=t9(l),{entries:t,disclosures:s}=e?{entries:[],disclosures:[]}:await Z(),c=e?[]:Q(),d=e?await ev(l,r,n,a.id,i,o.signal):await eg(l,r,n,a.id,i,o.signal,t,c);"cancelled"===x.current||ei(d),"completed"===d&&(H(),V(s));}finally{j.current=null;}},[f,c.activeChat,c.activeProject,c.selectedModel,c.models,_,ev,eg,Z,Q,H,ei]),eb=(0,r.useCallback)(async e=>{if(tJ(x.current))return;let t=c.activeChat,n=c.activeProject,l=t7(c.selectedModel,c.models);if(void 0===t||void 0===n||void 0===l)return;ei("queued"),b(e),S(void 0),I(void 0),R(void 0);let r=new AbortController();j.current=r;try{ei("contacting");let i=await(0,W.regenerateDesktopChat)({chatId:t.id,projectPath:n.path,assistantMessageId:e,modelId:l,memory:et(t,n)},r.signal);if(r.signal.aborted)return void ei("cancelled");let a=i.messages.find(t=>t.id===e);d(t=>({...t,activeChat:i.chat,chats:t0([i.chat,...t.chats.filter(e=>e.id!==i.chat.id)]),messages:void 0===a?t.messages:t.messages.map(t=>t.id===e?a:t)})),t6(i.chat),R(i.memory),ei("completed");}catch(e){if(e instanceof DOMException&&"AbortError"===e.name)return void ei("cancelled");S(tZ(e)),ei("failed");}finally{j.current=null,b(void 0);}},[c.activeChat,c.activeProject,c.selectedModel,c.models,et,ei]),ek=(0,r.useCallback)(async e=>{var t,n,l;let r=c.activeChat;if(void 0===r||0===e.length)return;let i=null!=(t=null==(n=c.activeProject)?void 0:n.path)?t:r.projectPath,a=t7(c.selectedModel,c.models);try{let t,n=await tQ({chatId:r.id,projectPath:i,messages:e,...(void 0===a?{}:{modelId:a}),memory:et(r,null!=(l=c.activeProject)?l:{path:i})});if(!z.current)return;t6(n.chat),t=r.id,F.current===t&&void 0!==n.memory&&R(n.memory),d(e=>{var t;let l=(null==(t=e.activeChat)?void 0:t.id)===r.id,i=new Set(e.messages.map(e=>e.id)),a=l?n.messages.filter(e=>!i.has(e.id)):[],o=t0([n.chat,...e.chats.filter(e=>e.id!==n.chat.id)]);return{...e,activeChat:l?n.chat:e.activeChat,chats:o,messages:[...e.messages,...a]};});}catch(e){S(tZ(e));}},[et,c.activeChat,c.activeProject,c.models,c.selectedModel]),ex=(0,r.useCallback)(async(e,t)=>{var n;let l,r=c.activeChat;if(void 0===r)throw Error("No active chat is available for grounded voice.");let i=null!=(n=c.activeProject)?n:{path:r.projectPath},a=t7(c.selectedModel,c.models),o=await(0,W.runRealtimeGroundedTool)({chatId:r.id,projectPath:i.path,callId:e.callId,query:e.query,...(void 0===e.userTranscript?{}:{userTranscript:e.userTranscript}),...(void 0===a?{}:{modelId:a}),memory:et(r,i)},t);return z.current&&(l=r.id,F.current===l)&&(t6(o.chat),I(o.groundedAnswer),void 0!==o.memory&&R(o.memory),d(e=>{var t;if((null==(t=e.activeChat)?void 0:t.id)!==r.id)return e;let n=new Set(e.messages.map(e=>e.id)),l=o.messages.filter(e=>!n.has(e.id));return{...e,activeChat:o.chat,chats:t0([o.chat,...e.chats.filter(e=>e.id!==o.chat.id)]),messages:[...e.messages,...l]};})),o.toolOutput;},[et,c.activeChat,c.activeProject,c.models,c.selectedModel]),ej=(0,r.useCallback)(e=>{t6(e),d(t=>{var n;return{...t,chats:t.chats.map(t=>t.id===e.id?e:t),activeChat:(null==(n=t.activeChat)?void 0:n.id)===e.id?e:t.activeChat};});},[]),eC=(0,r.useCallback)(()=>{S(void 0);},[]),eS=!h&&void 0===t7(c.selectedModel,c.models);return(0,r.useMemo)(()=>({projects:c.projects,chats:c.chats,messages:c.messages,streamingAssistantMessage:u,models:c.models,activeProject:c.activeProject,activeChat:c.activeChat,selectedModel:c.selectedModel,noEligibleModels:eS,draft:f,loading:h,sending:k,sendStatus:v,regeneratingMessageId:y,error:C,clearError:eC,setDraft:m,setSelectedModel:eo,openNewChat:es,openProject:ec,openChat:ed,addProject:eu,sendMessage:ey,regenerateMessage:eb,appendVoiceTurn:ek,runRealtimeGroundedTool:ex,cancelSend:ew,replaceChat:ej,latestGrounded:N,cancelGrounded:ew,pendingAttachments:_,addPendingAttachment:Y,removePendingAttachment:X,clearPendingAttachments:H,lastSentDocuments:J,memoryEnabled:A,setMemoryEnabled:P,memoryBudgetTokens:M,setMemoryBudgetTokens:T,latestMemory:E,clearLatestMemory:ee,acceptMemoryCandidate:en,rejectMemoryCandidate:el,forgetMemoryAction:er}),[c.projects,c.chats,c.messages,u,c.models,c.activeProject,c.activeChat,c.selectedModel,eS,f,h,k,v,y,C,eC,eo,es,ec,ed,eu,ey,eb,ek,ex,ew,ej,N,ew,_,Y,X,H,J,A,P,M,T,E,ee,en,el,er]);}({autoCreate:!1}),_=function(){var e,t,n,l;let[i,a]=(0,r.useReducer)(S,C),o=(0,r.useRef)(null),s=(0,r.useRef)(0),c=(0,r.useCallback)(async e=>{let t=o.current,[n,l]=await Promise.all([v(),null===t||0===t.length?Promise.resolve([]):g(t).catch(()=>[])]);s.current===e&&a({kind:"settle",instances:l,active:n});},[]),d=(0,r.useCallback)(async e=>{void 0!==e&&(o.current=e);let t=s.current+=1;a({kind:"load-start"});try{await c(t);}catch(e){if(s.current!==t)return;a({kind:"fail",error:N(e)});}},[c]),u=(0,r.useCallback)(async e=>{let t=s.current+=1;a({kind:"mutate-start"});try{if(await e(),s.current!==t)return;await c(t);}catch(e){if(s.current!==t)return;a({kind:"fail",error:N(e)});}},[c]),p=(0,r.useCallback)(e=>u(()=>w({workspaceId:e,requestedBy:j})),[u]),f=(0,r.useCallback)(()=>u(()=>y()),[u]),m=(0,r.useCallback)(e=>u(()=>b({workspaceId:e,requestedBy:j})),[u]),I=(0,r.useCallback)(e=>u(()=>k({workspaceId:e,requestedBy:j})),[u]),E=(0,r.useCallback)(e=>u(()=>x({workspaceId:e,requestedBy:j})),[u]),R=(0,r.useCallback)(e=>u(async()=>{o.current=e.root,await h({...e,requestedBy:j});}),[u]),A=null!=(e=null==(n=i.active)?void 0:n.binding)?e:null,P=null!=(t=null==(l=i.active)?void 0:l.instance)?t:null;return(0,r.useMemo)(()=>{var e;return{instances:i.instances,activeBinding:A,activeInstance:P,activeRoot:null!=(e=null==A?void 0:A.activeRoot)?e:null,loading:i.loading,switching:i.switching,error:i.error,refresh:d,switchTo:p,clearActive:f,pause:m,resume:I,prepareHandoff:E,provision:R};},[i.instances,i.loading,i.switching,i.error,A,P,d,p,f,m,I,E,R]);}(),J=(0,r.useRef)(null),V=(0,r.useRef)(null),[Y,X]=(0,r.useState)(tx.DEFAULT_GROUNDING_LIMITS);(0,r.useEffect)(()=>{(0,W.fetchConfig)().then(e=>X(e.effectiveGroundingLimits)).catch(()=>void 0);},[]);let H=_.refresh,Z=null==(s=B.activeProject)?void 0:s.path;(0,r.useEffect)(()=>{H(Z);},[H,Z]);let[Q,ee]=(0,r.useState)(null);(0,r.useEffect)(()=>{if(null===Q)return;let e=window.setTimeout(()=>ee(null),1e4);return()=>window.clearTimeout(e);},[Q]);let et=(0,r.useCallback)((e,t)=>(ee(`Source limit reached — this chat already has ${String(e)} of ${String(t)} connected sources. Disconnect a source before connecting another.`),!1),[]),en=(0,r.useCallback)(e=>(ee(e),!1),[]),el=(0,r.useCallback)(e=>{var t,n,l;let r=function(e){if((null==e?void 0:e.type)!=="chat")return;let t=e.cfg.chatId;return"string"==typeof t&&t.length>0?t:void 0;}(null==(n=V.current)?void 0:n.find(t=>t.id===e));if(void 0===r)return;let i=null!=(t=B.chats.find(e=>e.id===r))?t:(null==(l=B.activeChat)?void 0:l.id)===r?B.activeChat:void 0;return(null==i?void 0:i.status)==="closed"?void 0:i;},[B.activeChat,B.chats]),er=(0,r.useCallback)(async function(e,t){let n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:null,l=el(e);if(void 0===l)return en("Open a ready chat window before connecting a source.");let r=null===n?(0,eN.effectiveScopes)(l):(0,eN.removeConnectedScope)((0,eN.effectiveScopes)(l),n),i=(0,eN.effectiveLocalKnowledgeScopes)(l);if((0,eN.isScopeConnected)(r,t)){if(null!==n){let e=await(0,W.updateChatConnectedScopes)(l.id,r.length>0?r:null);B.replaceChat(e.chat);}return!0;}let a=(0,eN.totalSourceCap)(Y);if(r.length+i.length>=a)return et(r.length+i.length,a);let o={...t,connectedAtMs:Date.now()},s=(0,eN.appendConnectedScope)(r,o,Y.maxConnectedSources);if(null===s)return en("Choose a local folder before connecting it to chat.");if(s===r)return et(r.length+i.length,a);try{var c;let e=await(0,W.updateChatConnectedScopes)(l.id,s);B.replaceChat(e.chat),ee(null);let t=function(e){var t;if(void 0===e.root)return null;let n=null==(t=e.relativePaths[0])?void 0:t.replace(/\\/gu,"/").replace(/^\/+/u,"");if(void 0===n||0===n.length)return e.root;let l=e.root.replace(/\\/gu,"/").replace(/\/+$/u,"");return`${l}/${n}`;}(o);return null!==t&&(c=l.id,0!==c.length&&0!==t.length&&(0,ng.createRelationship)({type:"reads-context",source:{kind:"chat",id:c},target:{kind:"workspace-path",id:t}},function(e,t){let n=0x811c9dc5,l=`${e}|${t}`;for(let e=0;e<l.length;e+=1)n=Math.imul(n^l.charCodeAt(e),0x1000193);return`rc-${(n>>>0).toString(36)}-${(65535&l.length).toString(36)}`;}(c,t)).catch(e=>{e instanceof ng.RelationshipApiError;})),!0;}catch{return en("Keiko could not connect that source. Check that it is still available and try again.");}},[el,B.replaceChat,Y,et,en]),ei=(0,r.useCallback)(async(e,t)=>er(e,t),[er]),ea=(0,r.useCallback)((e,t)=>{let n=el(e);if(void 0===n)return;let l=(0,eN.removeConnectedScope)((0,eN.effectiveScopes)(n),t);(0,W.updateChatConnectedScopes)(n.id,l.length>0?l:null).then(e=>{B.replaceChat(e.chat);}).catch(e=>{console.warn("[keiko] connected-scope unbind failed",e);});},[el,B.replaceChat]),eo=(0,r.useCallback)(async(e,t)=>{let n=el(e);if(void 0===n)return en("Open a ready chat window before connecting a source.");let l=(0,eN.effectiveLocalKnowledgeScopes)(n),r=(0,eN.effectiveScopes)(n);if((0,eN.isConnectorScopeConnected)(l,t))return!0;let i=(0,eN.totalSourceCap)(Y);if(r.length+l.length>=i)return et(r.length+l.length,i);let a=(0,eN.appendConnectorScope)(l,t,Y.maxLocalKnowledgeSources);if(a===l)return et(r.length+l.length,i);try{let e=await(0,W.updateChatLocalKnowledgeScopes)(n.id,a);return B.replaceChat(e.chat),ee(null),!0;}catch{return en("Keiko could not connect that knowledge source. Check that it is still available and try again.");}},[el,B.replaceChat,Y,et,en]),es=(0,r.useCallback)((e,t)=>{let n=el(e);if(void 0===n)return;let l="capsule"===t.kind?`capsule:${t.capsuleId}`:`set:${t.capsuleSetId}`,r=(0,eN.removeConnectorScope)((0,eN.effectiveLocalKnowledgeScopes)(n),l);(0,W.updateChatLocalKnowledgeScopes)(n.id,r.length>0?r:null).then(e=>{B.replaceChat(e.chat);}).catch(()=>void 0);},[el,B.replaceChat]),[ec,ed]=(0,r.useState)(tl.readWorkspaceCameraSmoothness);(0,r.useEffect)(()=>{let e=e=>{let t=e.detail;ed("number"==typeof t?t:0);};return window.addEventListener(tl.WORKSPACE_CAMERA_SMOOTHNESS_EVENT,e),()=>{window.removeEventListener(tl.WORKSPACE_CAMERA_SMOOTHNESS_EVENT,e);};},[]);let eu=function(e){var t,n;let l,i,a=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},[o,s]=(0,r.useState)(null),[c,d]=(0,r.useState)(null),[u,p]=(0,r.useState)(!1),[f,m]=(0,r.useState)([]),[h,g]=(0,r.useState)(null),[v,w]=(0,r.useState)(eP),{cameraSmoothness:y=0,onScopeBind:b,onScopeUnbind:k,onConnectorBind:x,onConnectorUnbind:j}=a,C=(0,r.useRef)(b);C.current=b;let S=(0,r.useRef)(k);S.current=k;let N=(0,r.useRef)(x);N.current=x;let I=(0,r.useRef)(j);I.current=j;let E=(0,r.useCallback)((e,t)=>{var n,l;return null==(n=null==(l=C.current)?void 0:l.call(C,e,t))||n;},[]),R=(0,r.useCallback)((e,t)=>{var n;null==(n=S.current)||n.call(S,e,t);},[]),A=(0,r.useCallback)((e,t)=>{var n,l;return null==(n=null==(l=N.current)?void 0:l.call(N,e,t))||n;},[]),P=(0,r.useCallback)((e,t)=>{var n;null==(n=I.current)||n.call(I,e,t);},[]),M=(0,r.useRef)(3),T=(0,r.useRef)(null),z=(0,r.useRef)(!1),F=(0,r.useRef)(null),L=(0,r.useRef)(!1),W=(0,r.useCallback)(()=>{z.current=!0;},[]),$=(0,r.useRef)([]);$.current=null!=o?o:[];let O=(0,r.useRef)([]);O.current=f;let K=(0,r.useMemo)(()=>new Map((null!=o?o:[]).map(e=>[e.id,e])),[o]),q=(0,r.useMemo)(()=>new Map(f.map(e=>[e.id,e])),[f]),B=(0,r.useMemo)(()=>{let e=new Map();for(let t of f){let n=e.get(t.a);void 0===n?e.set(t.a,[t]):n.push(t);let l=e.get(t.b);void 0===l?e.set(t.b,[t]):l.push(t);}return e;},[f]),_=(0,r.useRef)(K);_.current=K;let G=(0,r.useRef)(q);G.current=q;let U=(0,r.useRef)(B);U.current=B;let J=(0,r.useRef)(null);J.current=h;let V=(0,r.useRef)(null),Y=(0,r.useRef)(()=>void 0),X=(0,r.useRef)(null),{viewRef:H,worldVP:Z,zoomTo:Q,fitView:ee,resetView:et,panBy:en,rect:el}=function(e){let{wsRef:t,view:n,cameraSmoothness:l,winsRef:i,setView:a,setWins:o}=e,s=(0,r.useRef)(n);s.current=n;let c=(0,r.useRef)(n);c.current=n;let d=(0,r.useRef)(null),u=(0,r.useRef)(1),p=(0,r.useRef)(90),f=(0,r.useRef)(null),m=(0,r.useRef)(null),h=(0,r.useRef)(n),g=(0,r.useRef)(n),v=(0,r.useRef)(0),w=(0,r.useRef)(null);null===w.current&&(w.current=eF(300));let y=(0,r.useCallback)(()=>{var e;null==(e=w.current)||e.schedule(()=>ez(eR,s.current));},[]),b=(0,r.useRef)(null),k=(0,r.useCallback)(()=>{let e=t.current;null!==e&&(e.dataset.viewActive="true",null!==b.current&&clearTimeout(b.current),b.current=setTimeout(()=>{b.current=null;let e=t.current;null!==e&&delete e.dataset.viewActive;},160));},[t]);(0,r.useEffect)(()=>()=>{null!==b.current&&clearTimeout(b.current);},[]),(0,r.useEffect)(()=>{let e=w.current;if(null===e)return;let t=()=>e.flush(),n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),e.flush();};},[]),(0,r.useEffect)(()=>()=>{null!==f.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(f.current),null!==m.current&&"function"==typeof window.cancelAnimationFrame&&window.cancelAnimationFrame(m.current);},[]);let x=(0,r.useCallback)(function(e){let t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:1,n=arguments.length>2&&void 0!==arguments[2]?arguments[2]:90,r=Math.min(100,Math.max(0,l*t));if(r<=0||"function"==typeof window.matchMedia&&window.matchMedia("(prefers-reduced-motion: reduce)").matches||"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){null!==m.current&&(window.cancelAnimationFrame(m.current),m.current=null),a(e);return;}let i=n+(280-n)*r/100,o="u">typeof performance&&"function"==typeof performance.now?performance.now():Date.now();if(h.current=null===m.current?c.current:e$(h.current,g.current,eW(Math.min(1,(o-v.current)/i))),g.current=e,v.current=o,null!==m.current)return;let s=e=>{let t=Math.min(1,Math.max(0,(e-v.current)/i)),n=eW(t);if(t>=1){m.current=null,a(g.current);return;}a(e$(h.current,g.current,n)),m.current=window.requestAnimationFrame(s);};m.current=window.requestAnimationFrame(s);},[l,a]),j=(0,r.useCallback)(()=>{null!==m.current&&"function"==typeof window.cancelAnimationFrame&&(window.cancelAnimationFrame(m.current),m.current=null,a(g.current),c.current=g.current);},[a]),C=(0,r.useCallback)(function(e){var t,n,l;let r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:{},i=null!=(t=d.current)?t:s.current,o="function"==typeof e?e(i):e,c=null!=(n=r.smoothnessScale)?n:1,m=null!=(l=r.minDurationMs)?l:90;if(s.current=o,d.current=o,u.current=c,p.current=m,y(),k(),"function"!=typeof window.requestAnimationFrame||"function"!=typeof window.cancelAnimationFrame){d.current=null,a(o);return;}null===f.current&&(f.current=window.requestAnimationFrame(()=>{f.current=null;let e=d.current,t=u.current,n=p.current;d.current=null,u.current=1,p.current=90,null!==e&&x(e,t,n);}));},[x,y,k,a]);(0,r.useEffect)(()=>{let e=t.current;if(null===e)return;let n=t=>{if(t.metaKey||t.ctrlKey){var n,l,r;t.preventDefault();let i=(n=t.target)instanceof Element&&null!=(l=null==(r=n.closest(".window[data-window-id]"))?void 0:r.dataset.windowId)?l:null;if(null!==i){j(),o(e=>null===e?e:e.map(e=>{var n,l,r;let a,o;return e.id===i?(n=e,l=t.deltaY,(o=eT((a=null!=(r=n.zoom)?r:1)*Math.exp(-(.0015*l))))===a?n:{...n,zoom:o}):e;}));return;}let a=e.getBoundingClientRect(),c=s.current,d=eL(t),u=eM(c.zoom*Math.exp(-(.0015*d.y))),p=(t.clientX-a.left-c.x)/c.zoom,f=(t.clientY-a.top-c.y)/c.zoom;C({zoom:u,x:t.clientX-a.left-p*u,y:t.clientY-a.top-f*u});return;}let i=t.target;if(i instanceof Element&&null!==i.closest(".window"))return;t.preventDefault();let a=eL(t);C(e=>({...e,x:e.x-a.x,y:e.y-a.y}),{minDurationMs:0,smoothnessScale:0});};return e.addEventListener("wheel",n,{passive:!1}),()=>{e.removeEventListener("wheel",n);};},[t,o,C,j]);let S=(0,r.useCallback)(()=>null===t.current?null:t.current.getBoundingClientRect(),[t]),N=(0,r.useCallback)(()=>{let e=S();if(null===e)return null;let t=s.current;return{x:-t.x/t.zoom,y:-t.y/t.zoom,w:e.width/t.zoom,h:e.height/t.zoom};},[S]),I=(0,r.useCallback)(e=>{let t=S();if(null===t)return;let n=s.current,l=t.width/2,r=t.height/2,i=(l-n.x)/n.zoom,a=(r-n.y)/n.zoom,o=eM(e);C({zoom:o,x:l-i*o,y:r-a*o});},[S,C]),E=(0,r.useCallback)(()=>{let e=S();null!==e&&C(function(e,t){let n=e.filter(e=>!0!==e.minimized);if(0===n.length)return{zoom:1,x:0,y:0};let l=1/0,r=1/0,i=-1/0,a=-1/0;for(let e of n)l=Math.min(l,e.x),r=Math.min(r,e.y),i=Math.max(i,e.x+e.w),a=Math.max(a,e.y+e.h);let o=Math.max(1,i-l),s=Math.max(1,a-r),c=eM(Math.min(1,Math.max(1,t.width-144)/o,Math.max(1,t.height-144)/s)),d=l+o/2,u=r+s/2;return{zoom:c,x:Math.round(t.width/2-d*c),y:Math.round(t.height/2-u*c)};}(i.current,e));},[S,i,C]);return{viewRef:s,worldVP:N,zoomTo:I,fitView:E,resetView:(0,r.useCallback)(()=>C({zoom:1,x:0,y:0}),[C]),panBy:(0,r.useCallback)((e,t)=>C(n=>({...n,x:n.x+e,y:n.y+t}),{minDurationMs:0,smoothnessScale:0}),[C]),rect:S};}({wsRef:e,view:v,cameraSmoothness:y,winsRef:$,setView:w,setWins:s});!function(e){let{wsRef:t,setWins:n,setConns:l,zc:i,lastAppliedSerializedRef:a}=e;(0,r.useLayoutEffect)(()=>{if(null===t.current)return;let e=eD();a.current=eJ(e),eU(e,n,l,i);},[t,n,l,i,a]);}({wsRef:e,setWins:s,setConns:m,zc:M,lastAppliedSerializedRef:F}),function(e){let{setWins:t,setConns:n,zc:l,beforeApplyRemote:i,lastAppliedSerializedRef:a,suppressNextLocalPersistRef:o}=e;(0,r.useEffect)(()=>{let e=e=>{if(null!==e.storageArea&&e.storageArea!==window.localStorage||e.key!==eI&&e.key!==eE)return;let r=eD(),s=eJ(r);s!==a.current&&(a.current=s,i(),o.current=!0,eU(r,t,n,l));};return window.addEventListener("storage",e),()=>{window.removeEventListener("storage",e);};},[t,n,l,i,a,o]);}({setWins:s,setConns:m,zc:M,beforeApplyRemote:W,lastAppliedSerializedRef:F,suppressNextLocalPersistRef:L}),function(e){let{wins:t,conns:n,setWins:l,setConns:i,zc:a,suppressNextPersistRef:o}=e,s=(0,r.useRef)(0),c=(0,r.useRef)(t);c.current=t;let d=(0,r.useRef)(n);d.current=n;let u=(0,r.useRef)(null);null===u.current&&(u.current=eF(300));let p=(0,r.useRef)(null),f=(0,r.useRef)(!1),m=(0,r.useRef)(null);null!==t&&t.length>0&&null===m.current&&(f.current=!0);let h="u"<typeof navigator||!0!==navigator.webdriver,g=(0,r.useCallback)(e=>{var t;let n=c.current;if(null===n)return;let l=eG(n,d.current);if(l.serialized===m.current){f.current=!1;return;}null==(t=p.current)||t.abort();let r="function"==typeof AbortController?new AbortController():null;p.current=r;let i=s.current;e_(l.wins,l.conns,{baseRevision:i,...(null!==r?{signal:r.signal}:{}),keepalive:e}).then(e=>{if((null==e?void 0:e.kind)==="conflict"){null!==e.revision&&e.revision>s.current&&(s.current=e.revision);return;}(null==e?void 0:e.kind)==="ok"&&(m.current=l.serialized,f.current=!1,e.revision>s.current&&(s.current=e.revision));});},[]),v=(0,r.useCallback)(e=>{var t,n;let r,c=(t=e.windows,n=e.connections,{wins:r=eC(t),conns:eS(n,r)});m.current=JSON.stringify({windows:c.wins,connections:c.conns}),f.current=!1,e.revision>s.current&&(s.current=e.revision),o.current=!0,eU(c,l,i,a);},[l,i,a,o]);(0,r.useEffect)(()=>{if(!h)return;let e=!1,t=null,n=async()=>{var t,n;let l=await eK(s.current);e||null===l||l.revision<=s.current||0===s.current&&0===l.windows.length&&(null!=(t=null==(n=c.current)?void 0:n.length)?t:0)>0||f.current||v(l);},l=()=>{null!==t&&(window.clearInterval(t),t=null);},r=()=>{"u">typeof document&&"hidden"===document.visibilityState?l():(n(),null===t&&(t=window.setInterval(()=>{n();},1500)));};return r(),document.addEventListener("visibilitychange",r),()=>{e=!0,l(),document.removeEventListener("visibilitychange",r);};},[v,h]),(0,r.useEffect)(()=>{var e;if(!h||null===t)return;if(o.current){o.current=!1;return;}let l=eG(t,n);if(null===m.current&&0===l.wins.length&&0===l.conns.length){m.current=l.serialized,f.current=!1;return;}if(l.serialized===m.current){f.current=!1;return;}f.current=!0,null==(e=u.current)||e.schedule(()=>g(!1));},[t,n,o,h,g]),(0,r.useEffect)(()=>{if(!h)return;let e=u.current,t=()=>{null==e||e.cancel(),g(!0);},n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&t();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),null==e||e.flush();};},[h,g]);}({wins:o,conns:f,setWins:s,setConns:m,zc:M,suppressNextPersistRef:z}),(0,r.useEffect)(()=>{if(null===o)return;let e=new Set(o.map(e=>e.id));m(t=>{let n=t.filter(t=>e.has(t.a)&&e.has(t.b));return n.length===t.length?t:n;});},[o,m]),t=()=>{if(null===o)return;if(L.current){L.current=!1;return;}let e=eC(o),t=eS(f,e);ez(eI,e),ez(eE,t),F.current=JSON.stringify({windows:e,connections:t});},n=[f,o],null===(l=(0,r.useRef)(null)).current&&(l.current=eF(300)),(i=(0,r.useRef)(t)).current=t,(0,r.useEffect)(()=>{var e;null==(e=l.current)||e.schedule(()=>i.current());},n),(0,r.useEffect)(()=>{let e=l.current;if(null===e)return;let t=()=>e.flush(),n=()=>{"u">typeof document&&"hidden"===document.visibilityState&&e.flush();};return window.addEventListener("pagehide",t),document.addEventListener("visibilitychange",n),()=>{window.removeEventListener("pagehide",t),document.removeEventListener("visibilitychange",n),e.flush();};},[]),function(e){let{setWins:t,rect:n,cancelConnectRef:l,snapRef:i}=e;(0,r.useEffect)(()=>{let e=e=>{var r,a,o,s;let c;if("Escape"===e.key)return void l.current();if(null!==(r=document.activeElement)&&("INPUT"===r.tagName||"TEXTAREA"===r.tagName||"SELECT"===r.tagName))return;let d=(c="u"<typeof document?null:document.activeElement)instanceof Element&&null!=(a=null==(o=c.closest(".window[data-window-id]"))?void 0:o.dataset.windowId)?a:null,u=eY[e.code];if((e.metaKey||e.ctrlKey)&&e.altKey&&void 0!==u){e.preventDefault(),null!==d&&t(e=>{var t,n;if(null===e||0===e.length)return e;let l=eX(e,d);if(null===l)return e;let r=(n=null!=(t=l.zoom)?t:1,"0"===u?1:"-"===u||"_"===u?eT(n-.1):eT(n+.1));return e.map(e=>e.id===l.id?{...e,zoom:r}:e);});return;}if(!/^Arrow/.test(e.key))return;if((e.metaKey||e.ctrlKey)&&e.altKey){let t=eV[e.key];e.preventDefault();let n=i.current;null!=t&&null!==n&&null!==d&&(n.setSnap(t),n.commitSnap(d));return;}let p=e.metaKey||e.ctrlKey,f=e.altKey;if(!p&&!f||(e.preventDefault(),null===d))return;let m=n();null!==m&&(s={key:e.key,shift:e.shiftKey},t(e=>{let t,n,l,r,i,a,o;if(null===e||0===e.length)return e;let c=eX(e,d);if(null===c)return e;let u=f?(t=s.shift?1:16,n=c.w,l=c.h,"ArrowRight"===s.key?n+=t:"ArrowLeft"===s.key?n-=t:"ArrowDown"===s.key?l+=t:"ArrowUp"===s.key&&(l-=t),n=Math.max((r=D.WIN_TYPES[c.type].min).w,Math.min(m.width,n)),l=Math.max(r.h,Math.min(m.height,l)),{x:c.x,y:c.y,w:n,h:l}):(i=s.shift?1:16,a=c.x,o=c.y,"ArrowRight"===s.key?a+=i:"ArrowLeft"===s.key?a-=i:"ArrowDown"===s.key?o+=i:"ArrowUp"===s.key&&(o-=i),{x:a=Math.max(-(c.w-120),Math.min(m.width-120,a)),y:o=Math.max(0,Math.min(m.height-38,o)),w:c.w,h:c.h});return e.map(e=>e.id===c.id?{...e,...u,max:!1}:e);}));};return window.addEventListener("keydown",e),()=>{window.removeEventListener("keydown",e);};},[t,n,l,i]);}({setWins:s,rect:el,cancelConnectRef:Y,snapRef:X}),function(e){let{wsRef:t,viewRef:n,setWins:l}=e;(0,r.useEffect)(()=>{let e=t.current;if(null===e||"u"<typeof ResizeObserver)return;let r=new ResizeObserver(()=>{let t=e.getBoundingClientRect(),r=n.current,i={x:-r.x/r.zoom,y:-r.y/r.zoom,w:t.width/r.zoom,h:t.height/r.zoom};l(e=>{let t;return null===e?e:(t=e.map(e=>function(e,t){if(e.max)return{...e,x:t.x,y:t.y,w:t.w,h:t.h};let n=Math.max(t.x-(e.w-120),Math.min(t.x+t.w-120,e.x)),l=Math.max(t.y,Math.min(t.y+t.h-38,e.y));return n===e.x&&l===e.y?e:{...e,x:n,y:l};}(e,i))).every((t,n)=>t===e[n])?e:t;});});return r.observe(e),()=>{r.disconnect();};},[t,n,l]);}({wsRef:e,viewRef:H,setWins:s});let er=(0,r.useMemo)(()=>(0,eN.makeMutations)({setWins:s,zc:M,worldVP:Z,winsRef:$}),[s,M,Z,$]),ei=(0,r.useMemo)(()=>(0,eN.makeLayoutActions)({setWins:s,worldVP:Z}),[s,Z]),ea=(0,r.useMemo)(()=>(0,eN.makeSnapActions)({setSnapPrev:d,snapZone:T,worldVP:Z,update:er.update}),[d,T,Z,er]);X.current=ea;let eo=(0,r.useMemo)(()=>(0,eN.makeConnectActions)({wsRef:e,viewRef:H,winsRef:$,connsRef:O,winsByIdRef:_,connsByIdRef:G,connsByEndpointRef:U,connectingRef:J,connectCleanupRef:V,focus:er.focus,setConns:m,setConnecting:g,onScopeBind:E,onScopeUnbind:R,onConnectorBind:A,onConnectorUnbind:P}),[e,H,$,O,_,G,U,J,V,er,m,g,E,R,A,P]);Y.current=eo.cancelConnect;let es=(0,r.useCallback)(e=>{let t=_.current.get(e);if(void 0!==t){var n,l,r,i;for(let a of null!=(n=U.current.get(e))?n:[]){let n=a.a===e?a.b:a.b===e?a.a:null;if(null===n)continue;let o=_.current.get(n);if(void 0===o)continue;let s=null!=(l=a.boundChatWindowId)?l:"chat"===t.type?t.id:"chat"===o.type?o.id:null,c=null!=(r=(0,eN.boundScopeOf)(a))?r:!0===a.boundScopeElided?null:(0,eN.filesChatBindScope)(t,o,Date.now());null!==c&&null!==s&&R(s,c);let d=null!=(i=(0,eN.boundConnectorScopeOf)(a))?i:(0,eN.connectorChatBind)(t,o);null!==d&&null!==s&&P(s,d);}}er.close(e);},[_,U,er,R,P]),ec=(0,r.useCallback)((e,t)=>{m(n=>n.map(n=>n.id===e?{...n,boundScopeKind:t.kind,...(void 0!==t.root?{boundRoot:t.root}:{}),...(void 0!==t.relativePaths[0]?{boundRelativePath:t.relativePaths[0]}:{})}:n));},[m]),ed=(0,r.useCallback)(()=>H.current,[H]);(0,r.useEffect)(()=>()=>{null!==V.current&&(V.current(),V.current=null);},[]);let eu=(0,r.useMemo)(()=>({add:er.add,openEditorFile:er.openEditorFile,toggleTool:er.toggleTool,focus:er.focus,close:es,minimize:er.minimize,restore:er.restore,maximize:er.maximize,update:er.update,setSnap:ea.setSnap,commitSnap:ea.commitSnap,tileAll:ei.tileAll,splitFront:ei.splitFront,cascade:ei.cascade,startConnect:eo.startConnect,confirmConnect:eo.confirmConnect,cancelConnect:eo.cancelConnect,removeConn:eo.removeConn,updateConnBoundScope:ec,connect:eo.connect,linkedFilesRoot:eo.linkedFilesRoot,linkedFilesContext:eo.linkedFilesContext,linkedAllFilesRoots:eo.linkedAllFilesRoots,linkedConnectorCapsuleIds:eo.linkedConnectorCapsuleIds,linkedConnectorCapsuleSetIds:eo.linkedConnectorCapsuleSetIds,linkedFigmaSnapshotRunIds:eo.linkedFigmaSnapshotRunIds,linkedFigmaSnapshotSources:eo.linkedFigmaSnapshotSources,linkedImageSources:eo.linkedImageSources,currentFilesContext:eo.currentFilesContext,zoomTo:Q,fitView:ee,resetView:et,panBy:en,rect:el,currentView:ed}),[er,ea,ei,eo,es,ec,ed,Q,ee,et,en,el]);return{wins:o,winsById:K,snapPrev:c,palOpen:u,setPalOpen:p,conns:f,connecting:h,view:v,api:eu};}(J,{cameraSmoothness:ec,onScopeBind:ei,onScopeUnbind:ea,onConnectorBind:eo,onConnectorUnbind:es});V.current=eu.wins,(0,r.useEffect)(()=>{if(null!==eu.wins)for(let t of eu.conns){var e;let n=eu.winsById.get(t.a),l=eu.winsById.get(t.b);if(void 0===n||void 0===l)continue;let r=null!=(e=t.boundChatWindowId)?e:"chat"===n.type?n.id:"chat"===l.type?l.id:null;if(null===r)continue;let i=(0,eN.filesChatBindScope)(n,l,Date.now());if(null===i)continue;let a=(0,eN.boundScopeOf)(t);ly(a)!==ly(i)&&er(r,i,a).then(e=>{e&&eu.api.updateConnBoundScope(t.id,i);});}},[er,eu.api,eu.conns,eu.wins,eu.winsById]);let[ep,ef]=(0,r.useState)(!1),[em,eh]=(0,r.useState)(null),[eg,ev]=(0,r.useState)(!1),[ew,ey]=(0,r.useState)(!1),eb=null!=(e=null==(d=eu.wins)?void 0:d.length)?e:0,ek=function(e){if(null===e||0===e.length)return null;let t=null;for(let n=0;n<e.length;n++){let l=e[n];if(!0!==l.minimized){if(null===t){t=l;continue;}l.z>t.z&&(t=l);}}return t;}(eu.wins),ex=(0,r.useMemo)(()=>function(e){if(null===e)return new Set();let t=new Set();for(let n of e)!0===D.WIN_TYPES[n.type].tool&&t.add(n.type);return t;}(eu.wins),[eu.wins]),ej=(0,r.useMemo)(()=>({active:ek,winCount:eb}),[ek,eb]),eA=(0,r.useMemo)(()=>(0,l.jsx)(z,{}),[]),eO=(0,r.useCallback)(()=>ef(!0),[]),eq=(0,r.useCallback)(()=>ef(!1),[]),eB=(0,r.useCallback)(()=>ey(e=>!e),[]),eH=(0,r.useCallback)(()=>ey(!1),[]),eZ=(0,r.useCallback)(e=>{eu.api.restore(e),ey(!1);},[eu.api]),eQ=(0,r.useCallback)(e=>{if(ef(!1),"connector"===e||"docbrowser"===e){let t=eu.api.add(e);null!==t&&lj(t);return;}eh(e);},[eu.api]),e0=(0,r.useCallback)(e=>{if(eh(null),null===em)return;let{__connectFilesId:t,...n}="editor"===em?function(e){let t="string"==typeof e.root?e.root.trim():"",n="string"==typeof e.file?e.file.trim():"";if(0===t.length)return e;let l=lb(t,n),r={...e,root:t},i=function(e,t,n){let l=[],r=t=>{let n=lb(e,t);null===n||0===n.length||l.includes(n)||l.push(n);};if(Array.isArray(t))for(let e of t)"string"==typeof e&&r(e);return n.length>0&&r(n),l;}(t,e.openFiles,null!=l?l:"");return null!==l&&l.length>0?r.file=l:delete r.file,i.length>0?r.openFiles=i:delete r.openFiles,r;}(e):e,l=eu.api.add(em,n);"agents"===em&&null!==l&&"string"==typeof t&&t.length>0&&eu.api.connect(l,t),null!==l&&lj(l);},[em,eu.api]),e1=(0,r.useCallback)(()=>eh(null),[]),e2=(0,r.useCallback)(()=>ev(!1),[]),e4=(0,r.useCallback)(()=>ev(!0),[]),e3=(0,r.useRef)(null),e5=(0,r.useCallback)(e=>{e3.current=e;},[]),e6=function(e){var t;let{apply:n}=e,l=null!=(t=e.limit)?t:100,[i,a]=(0,r.useState)(nb),o=(0,r.useRef)(n);o.current=n;let s=(0,r.useRef)(i);s.current=i;let c=(0,r.useCallback)(e=>{a(t=>{let n=[...t.undoStack,e];return{undoStack:n.length>l?n.slice(n.length-l):n,redoStack:[]};});},[l]),d=(0,r.useCallback)(()=>{let e=s.current;if(0===e.undoStack.length)return;let t=e.undoStack[e.undoStack.length-1],n=function(e){switch(e.kind){case"ui.window.move":case"ui.window.resize":case"ui.window.zorder":case"ui.workspace.pan":case"ui.workspace.zoom":case"ui.workspace.fit":case"ui.panel.toggle":case"ui.selection.change":case"ui.tab.switch":return{...e,before:e.after,after:e.before};case"ui.window.close":return{...e,kind:"ui.window.open"};case"ui.window.open":return{...e,kind:"ui.window.close"};}}(t);a({undoStack:e.undoStack.slice(0,-1),redoStack:[...e.redoStack,t]}),o.current(n);},[]),u=(0,r.useCallback)(()=>{let e=s.current;if(0===e.redoStack.length)return;let t=e.redoStack[e.redoStack.length-1];a({undoStack:[...e.undoStack,t],redoStack:e.redoStack.slice(0,-1)}),o.current(t);},[]),p=(0,r.useCallback)(()=>{a(nb);},[]);return(0,r.useMemo)(()=>{let e=i.undoStack[i.undoStack.length-1],t=i.redoStack[i.redoStack.length-1];return{canUndo:i.undoStack.length>0,canRedo:i.redoStack.length>0,undoLabel:void 0!==e?nw(e):null,redoLabel:void 0!==t?nw(t):null,push:c,undo:d,redo:u,clear:p};},[i,c,d,u,p]);}({apply:(0,r.useCallback)(e=>{var t;return t=eu.api,void("ui.panel.toggle"===e.kind&&e.panel in D.WIN_TYPES&&t.toggleTool(e.panel));},[eu.api])}),e8=(0,r.useCallback)(e=>{if(!(e in D.WIN_TYPES))return;let t=ex.has(e);eu.api.toggleTool(e),e6.push({kind:"ui.panel.toggle",panel:e,before:t,after:!t});},[eu.api,ex,e6]),e7=(0,r.useCallback)(()=>eQ("chat"),[eQ]),e9=(0,r.useRef)(!1);(0,r.useEffect)(()=>{if(e9.current||null===eu.wins)return;e9.current=!0;let e=window.location.pathname.replace(/\/+$/u,""),t="/relationships"===e?"relationships":"/local-knowledge"===e?"localKnowledge":null;null!==t&&(eu.wins.some(e=>e.type===t)||e8(t),window.history.replaceState(null,"","/"));},[eu.wins,e8]),function(e){var t;let{bindings:n,dispatch:l}=e,i=null!=(t=e.platform)?t:function(){if("u"<typeof navigator)return"other";let e=navigator.platform||"";return /Mac|iPhone|iPad|iPod/i.test(e)?"mac":"other";}(),a=(0,r.useRef)(l);a.current=l;let o=(0,r.useMemo)(()=>function(e){let t=new Map();for(let n of e){let e=ny(n.chord),l=t.get(e);void 0!==l?l.push(n.commandId):t.set(e,[n.commandId]);}let n=[];for(let[,l]of t)if(l.length>1){let t=e.find(e=>l.includes(e.commandId));void 0!==t&&n.push({chord:t.chord,commandIds:l});}return n;}(n),[n]),s=(0,r.useMemo)(()=>n.filter(e=>function(e){for(let t of nv)if(ny(e)===ny(t))return!0;return!1;}(e.chord)),[n]);if(o.length>0)throw new nx(o);if(s.length>0)throw new nj(s);(0,r.useEffect)(()=>{function e(e){if(!function(e){if(!(e instanceof HTMLElement))return!1;if(e.isContentEditable)return!0;let t=e.tagName;return"INPUT"===t||"TEXTAREA"===t||"SELECT"===t;}(e.target)){for(let t of n)if(function(e,t,n){if(!(e.key.toLowerCase()===t.key.toLowerCase()||t.mod.includes("alt")&&/^[a-z]$/i.test(t.key)&&e.code===`Key${t.key.toUpperCase()}`))return!1;let l=function(e,t){let n=new Set();for(let l of e)"cmd"===l?n.add("mac"===t?"meta":"ctrl"):"ctrl"===l?n.add("ctrl"):"alt"===l?n.add("alt"):"shift"===l&&n.add("shift");return n;}(t.mod,n);return e.metaKey===l.has("meta")&&e.ctrlKey===l.has("ctrl")&&e.altKey===l.has("alt")&&e.shiftKey===l.has("shift");}(e,t.chord,i)){e.preventDefault(),a.current(t.commandId);return;}}}return window.addEventListener("keydown",e),()=>window.removeEventListener("keydown",e);},[n,i]),(0,r.useMemo)(()=>({bindings:n,conflicts:o,reserved:s}),[n,o,s]);}({bindings:nS,dispatch:(0,r.useCallback)(e=>{var t;"undo"===e?e6.undo():"redo"===e?e6.redo():"focus-status"===e&&(null==(t=e3.current)||t.focus());},[e6])}),(0,r.useEffect)(()=>{let e=document.documentElement,t=()=>{e.setAttribute("data-input-modality","pointer");},n=t=>{t.metaKey||t.ctrlKey||t.altKey||"Tab"===t.key&&e.setAttribute("data-input-modality","keyboard");};return e.setAttribute("data-input-modality","pointer"),window.addEventListener("pointerdown",t,!0),window.addEventListener("mousedown",t,!0),window.addEventListener("keydown",n,!0),()=>{window.removeEventListener("pointerdown",t,!0),window.removeEventListener("mousedown",t,!0),window.removeEventListener("keydown",n,!0),e.removeAttribute("data-input-modality");};},[]);let te=(0,r.useMemo)(()=>function(e,t,n,l,r,i){let a=[];for(let e of lk){let t=D.WIN_TYPES[e];a.push({id:`new-${e}`,label:`New ${t.title}`,group:"Create",icon:t.icon,run:()=>n(e)});}for(let e of lx){let n=D.WIN_TYPES[e];a.push({id:`open-${e}`,label:`Open ${n.title}`,group:"Tools",icon:n.icon,run:()=>t(e)});}return a.push({id:"tile",label:"Tile all windows",group:"Layout",icon:"tile",run:e.tileAll}),a.push({id:"split",label:"Split front windows",group:"Layout",icon:"split",run:e.splitFront}),a.push({id:"cascade",label:"Cascade windows",group:"Layout",icon:"cascade",run:e.cascade}),a.push({id:"theme",label:"Toggle light / dark theme",group:"View",icon:"light"===l?"moon":"sun",run:r}),a.push({id:"undo",label:null!==i.undoLabel?`Undo: ${i.undoLabel}`:"Undo (window and panel changes only)",group:"Edit",icon:"back",shortcut:"⌘Z",run:i.undo}),a.push({id:"redo",label:null!==i.redoLabel?`Redo: ${i.redoLabel}`:"Redo (window and panel changes only)",group:"Edit",icon:"fwd",shortcut:"⇧⌘Z",run:i.redo}),a;}(eu.api,e8,eQ,M,T,e6),[eu.api,e8,eQ,M,T,e6]),tt=!B.loading&&void 0===B.error&&0===B.models.length,ta=(m=null==(u=B.activeProject)?void 0:u.name,B.loading?"Loading project…":void 0!==m&&m.trim().length>0?m:"No project selected"),to=void 0!==B.activeProject,ts=(null==(p=B.activeProject)?void 0:p.available)===!0,tc=(I={loading:B.loading,error:B.error,hasProject:to,projectAvailable:ts,noEligibleModels:B.noEligibleModels}).loading?"Loading shell…":void 0!==I.error?"Shell error":I.hasProject?I.projectAvailable?I.noEligibleModels?"Gateway setup required":"Ready":"Project unavailable":"No project selected",td=0===(A=(null!=(E=eu.wins)?E:[]).filter(e=>"review"===e.type)).length?"No review open":A.some(e=>"string"==typeof e.cfg.runId&&e.cfg.runId.length>0)?"Evidence ready":"Review window open",tu=void 0!==(R=null==(f=B.activeChat)?void 0:f.branchLabel)&&R.trim().length>0?R:"No branch selected",tp=null!==eu.wins&&!B.loading&&!tt,tf=(0,r.useCallback)(()=>{let e=eu.api.add("updates",{entrypoint:"startup"});null!==e&&lj(e);},[eu.api]),tm=ep?(0,l.jsx)(tk,{types:D.WIN_TYPES,order:lk,onAdd:eQ,onClose:eq}):null,th=null!==em||eg||tt,tg=(0,r.useRef)(null);return(0,r.useEffect)(()=>{let e=tg.current;null!==e&&(th?e.setAttribute("inert",""):e.removeAttribute("inert"));},[th]),(0,l.jsx)(o,{value:_,children:(0,l.jsx)(i.ChatSessionProvider,{value:B,children:(0,l.jsx)(L.WsContext.Provider,{value:ej,children:(0,l.jsx)(c,{children:(0,l.jsxs)("div",{className:"app",children:[(0,l.jsx)("a",{className:"skip-link",href:"#main",children:P("app.skipToContent")}),(0,l.jsx)("h1",{className:"visually-hidden",children:P("app.workspaceHeading")}),(0,l.jsx)(q,{openPalette:eO,openCommandPalette:e4,onTileAll:eu.api.tileAll,onSplitFront:eu.api.splitFront,onCascade:eu.api.cascade,contextControl:eA}),(0,l.jsxs)("div",{className:"mid",children:[tt?null:(0,l.jsx)(G,{openTools:ex,onTool:e8,onNewChat:e7,theme:M,onToggleTheme:T}),(0,l.jsxs)("div",{ref:tg,className:"stage",id:"main",tabIndex:-1,"aria-hidden":!!th||void 0,children:[(0,l.jsx)(tn,{ws:eu,wsRef:J,openPalette:eO,palette:tm,children:(0,l.jsx)(lw,{ready:tp,openUpdates:tf})}),null!==Q&&(0,l.jsxs)("div",{className:"source-limit-alert",role:"alert",children:[(0,l.jsx)("span",{children:Q}),(0,l.jsx)("button",{type:"button",className:"source-limit-alert-dismiss","aria-label":"Dismiss source connection notice",onClick:()=>ee(null),children:"×"})]})]}),tt?null:(0,l.jsx)(U,{openTools:ex,onTool:e8})]}),(0,l.jsx)(K,{winCount:eb,windows:null!=(a=eu.wins)?a:[],windowPaletteOpen:ew,onToggleWindowPalette:eB,onSelectWindow:eZ,onCloseWindowPalette:eH,mode:O.mode,selectedModel:B.selectedModel,projectName:ta,branchLabel:tu,shellStatusLabel:tc,evidenceStatusLabel:td,statusRef:e5}),null!==em&&(0,l.jsx)(tb,{type:em,types:D.WIN_TYPES,filesContext:eu.api.currentFilesContext(),onConfirm:e0,onClose:e1}),eg&&(0,l.jsx)(tr,{commands:te,onClose:e2}),tt?(0,l.jsx)(ti.GatewaySetupDialog,{}):null,(0,l.jsx)(ld,{})]})})})})});}function lS(){let[e,t]=(0,r.useState)(!1);return((0,r.useEffect)(()=>{try{window.sessionStorage.removeItem("keiko.app-boot-recovery-reload-count");}catch{}t(!0);},[]),(0,r.useEffect)(()=>{!function(){if(!("u">typeof navigator&&"serviceWorker"in navigator))return;let e=navigator.serviceWorker;try{e.register("/sw.js",{scope:"/"}).then(t=>{e.addEventListener("controllerchange",lf),null!==e.controller&&lm(t),t.addEventListener("updatefound",()=>{let n;n=t.installing,null!==n&&n.addEventListener("statechange",()=>{"installed"!==n.state||null!==e.controller&&lm(t);});});}).catch(e=>{});}catch{}}();},[]),e)?(0,l.jsx)($.I18nProvider,{children:(0,l.jsx)(F.TwinProvider,{children:(0,l.jsx)(lC,{})})}):(0,l.jsx)("div",{className:"app","aria-hidden":"true",children:(0,l.jsx)("div",{className:"app-boot",children:(0,l.jsx)("img",{className:"app-boot-logo",src:"/assets/keiko-logo.svg",alt:""})})});}e.s(["KeikoDesktop",0,function(){return(0,l.jsx)(lS,{});}],89199);}]);
|