@spencerboucher/switchyard 0.3.0 → 0.4.0
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/README.md +2 -2
- package/dist/switchyard.mjs +1243 -742
- package/package.json +1 -1
- package/web-dist/assets/{AutomationView-Bt_v8JDx.js → AutomationView-BhEfjAtI.js} +2 -2
- package/web-dist/assets/{AutomationView-Bt_v8JDx.js.map → AutomationView-BhEfjAtI.js.map} +1 -1
- package/web-dist/assets/{InteractionCard-BRI9KgrO.js → InteractionCard-DxEZUNrD.js} +2 -2
- package/web-dist/assets/{InteractionCard-BRI9KgrO.js.map → InteractionCard-DxEZUNrD.js.map} +1 -1
- package/web-dist/assets/Menu-C4GUY_ym.js +2 -0
- package/web-dist/assets/Menu-C4GUY_ym.js.map +1 -0
- package/web-dist/assets/{Overlay-B9h5oAe6.js → Overlay-C-GqmwUn.js} +2 -2
- package/web-dist/assets/{Overlay-B9h5oAe6.js.map → Overlay-C-GqmwUn.js.map} +1 -1
- package/web-dist/assets/{attention-VkuGuoSf.js → attention-Dzqdk9Gz.js} +2 -2
- package/web-dist/assets/{attention-VkuGuoSf.js.map → attention-Dzqdk9Gz.js.map} +1 -1
- package/web-dist/assets/{automations-BY88rXFv.js → automations-DzTTwxBl.js} +2 -2
- package/web-dist/assets/{automations-BY88rXFv.js.map → automations-DzTTwxBl.js.map} +1 -1
- package/web-dist/assets/{board-OzxtnPgh.js → board-C5mG_8rg.js} +2 -2
- package/web-dist/assets/{board-OzxtnPgh.js.map → board-C5mG_8rg.js.map} +1 -1
- package/web-dist/assets/code-9shyh1Gw.js +8 -0
- package/web-dist/assets/code-9shyh1Gw.js.map +1 -0
- package/web-dist/assets/{describe-CRXLn3O6.js → describe-BbCZVvJP.js} +2 -2
- package/web-dist/assets/{describe-CRXLn3O6.js.map → describe-BbCZVvJP.js.map} +1 -1
- package/web-dist/assets/dist-PaQekTP8.js +56 -0
- package/web-dist/assets/dist-PaQekTP8.js.map +1 -0
- package/web-dist/assets/{enroll-C9-fBIKO.js → enroll-DWJANJtw.js} +2 -2
- package/web-dist/assets/{enroll-C9-fBIKO.js.map → enroll-DWJANJtw.js.map} +1 -1
- package/web-dist/assets/index-ByiuDoG0.css +2 -0
- package/web-dist/assets/{index-B11DJFHW.js → index-afOJ8NRR.js} +3 -3
- package/web-dist/assets/{index-B11DJFHW.js.map → index-afOJ8NRR.js.map} +1 -1
- package/web-dist/assets/{more-BUvq82hI.js → more-B6qxC6M-.js} +2 -2
- package/web-dist/assets/{more-BUvq82hI.js.map → more-B6qxC6M-.js.map} +1 -1
- package/web-dist/assets/{now-DR2wt1DG.js → now-BOWxgbt3.js} +2 -2
- package/web-dist/assets/{now-DR2wt1DG.js.map → now-BOWxgbt3.js.map} +1 -1
- package/web-dist/assets/settings-BpkmIv_4.js +8 -0
- package/web-dist/assets/settings-BpkmIv_4.js.map +1 -0
- package/web-dist/assets/{send-CFwekPNi.js → sliders-horizontal-S3tmwxsP.js} +2 -2
- package/web-dist/assets/sliders-horizontal-S3tmwxsP.js.map +1 -0
- package/web-dist/assets/{useNow-ChB9z-N6.js → useNow-D9Zxr5Jb.js} +2 -2
- package/web-dist/assets/{useNow-ChB9z-N6.js.map → useNow-D9Zxr5Jb.js.map} +1 -1
- package/web-dist/index.html +2 -2
- package/web-dist/sw.js +1 -1
- package/web-dist/sw.js.map +1 -1
- package/web-dist/assets/Menu-Cqil5qVF.js +0 -2
- package/web-dist/assets/Menu-Cqil5qVF.js.map +0 -1
- package/web-dist/assets/code-BR4PKt8F.js +0 -8
- package/web-dist/assets/code-BR4PKt8F.js.map +0 -1
- package/web-dist/assets/dist-C4YmDHPG.js +0 -56
- package/web-dist/assets/dist-C4YmDHPG.js.map +0 -1
- package/web-dist/assets/index-DGGOgcLZ.css +0 -2
- package/web-dist/assets/send-CFwekPNi.js.map +0 -1
- package/web-dist/assets/settings-C4tDpSCU.js +0 -7
- package/web-dist/assets/settings-C4tDpSCU.js.map +0 -1
|
@@ -1,2 +0,0 @@
|
|
|
1
|
-
import{_ as e,m as t,n,t as r}from"./jsx-runtime-D13aM9HY.js";import{h as i}from"./states-DrTQuYXw.js";var a={name:`arrow-down`,size:24,node:[[`path`,{d:`M12 5v14`,key:`s699le`}],[`path`,{d:`m19 12-7 7-7-7`,key:`1idqje`}]]};a.node;var o=n(a),s={name:`chevron-down`,size:24,node:[[`path`,{d:`m6 9 6 6 6-6`,key:`qrunsl`}]]};s.node;var c=n(s),l={name:`panel-right-open`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m10 15-3-3 3-3`,key:`1pgupc`}]]};l.node;var u=n(l),d=e(t(),1),f=r();function p({trigger:e,items:t,align:n=`end`,label:r}){let[a,o]=(0,d.useState)(!1),s=(0,d.useId)(),c=(0,d.useRef)(null),l=(0,d.useRef)(null),u=e=>m(l.current,e);(0,d.useEffect)(()=>{if(!a)return;requestAnimationFrame(()=>m(l.current,`first`));let e=e=>{!l.current?.contains(e.target)&&!c.current?.contains(e.target)&&o(!1)};return document.addEventListener(`pointerdown`,e),()=>document.removeEventListener(`pointerdown`,e)},[a]);let p=(e=!0)=>{o(!1),e&&c.current?.focus()};return(0,f.jsxs)(`div`,{className:`relative inline-flex`,children:[e({ref:c,onClick:()=>o(e=>!e),onKeyDown:e=>{(e.key===`ArrowDown`||e.key===`ArrowUp`)&&(e.preventDefault(),o(!0))},"aria-haspopup":`menu`,"aria-expanded":a,"aria-controls":s}),a&&(0,f.jsx)(`div`,{ref:l,id:s,role:`menu`,"aria-label":r,tabIndex:-1,className:i(`absolute top-full z-40 mt-1 min-w-48 max-w-[min(20rem,calc(100vw-1rem))] rounded-lg border border-border bg-surface py-1 shadow-pop`,n===`end`?`right-0`:`left-0`),onKeyDown:e=>{e.key===`ArrowDown`?(e.preventDefault(),u(1)):e.key===`ArrowUp`?(e.preventDefault(),u(-1)):e.key===`Home`?(e.preventDefault(),u(`first`)):e.key===`End`?(e.preventDefault(),u(`last`)):e.key===`Escape`?(e.preventDefault(),e.stopPropagation(),p()):e.key===`Tab`&&p(!1)},children:t.map((e,t)=>e===`separator`?(0,f.jsx)(`hr`,{className:`my-1 border-t border-border`},`sep-${t}`):(0,f.jsxs)(`button`,{type:`button`,role:`menuitem`,disabled:e.disabled,className:i(`tap flex w-full items-start gap-2 px-3 py-2 text-left text-sm hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:opacity-55`,e.danger?`text-danger`:`text-text`),onClick:()=>{p(),e.onSelect()},children:[e.icon&&(0,f.jsx)(`span`,{className:`mt-0.5 shrink-0`,children:e.icon}),(0,f.jsxs)(`span`,{className:`min-w-0`,children:[(0,f.jsx)(`span`,{className:`block`,children:e.label}),e.hint&&(0,f.jsx)(`span`,{className:`block text-xs text-muted`,children:e.hint})]})]},e.id))})]})}function m(e,t){let n=[...e?.querySelectorAll(`[role="menuitem"]:not([disabled])`)??[]];if(n.length===0)return;let r=n.indexOf(document.activeElement),i=0;i=t===`first`?0:t===`last`?n.length-1:(r+t+n.length)%n.length,n[i].focus()}export{o as i,u as n,c as r,p as t};
|
|
2
|
-
//# sourceMappingURL=Menu-Cqil5qVF.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"Menu-Cqil5qVF.js","names":["__iconData","__iconData","useState","useId","useRef","__toESM","require_react","require_jsx_runtime","cn","__iconData$2","ArrowDown","createLucideIcon","__iconData$1","ChevronDown","__iconData","PanelRightOpen","import_react","import_jsx_runtime","Menu","open","setOpen","id","btnRef","menuRef","focusItem","focusMenuItem","dir","onDoc","close","refocus","trigger","o","label","align","items","item","i","els","menu","idx","next"],"sources":["../../../../node_modules/.pnpm/lucide-react@1.61.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/arrow-down.mjs","../../../../node_modules/.pnpm/lucide-react@1.61.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/chevron-down.mjs","../../../../node_modules/.pnpm/lucide-react@1.61.0_@types+react@19.3.0_react@19.3.1/node_modules/lucide-react/dist/esm/icons/panel-right-open.mjs","../../src/components/ui/Menu.tsx"],"sourcesContent":["/**\n * @license lucide-react v1.61.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n name: \"arrow-down\",\n size: 24,\n node: [\n [\"path\", { d: \"M12 5v14\", key: \"s699le\" }],\n [\"path\", { d: \"m19 12-7 7-7-7\", key: \"1idqje\" }]\n ]\n};\n__iconData.node;\nconst ArrowDown = createLucideIcon(__iconData);\n\nexport { __iconData, ArrowDown as default };\n//# sourceMappingURL=arrow-down.mjs.map\n","/**\n * @license lucide-react v1.61.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n name: \"chevron-down\",\n size: 24,\n node: [[\"path\", { d: \"m6 9 6 6 6-6\", key: \"qrunsl\" }]]\n};\n__iconData.node;\nconst ChevronDown = createLucideIcon(__iconData);\n\nexport { __iconData, ChevronDown as default };\n//# sourceMappingURL=chevron-down.mjs.map\n","/**\n * @license lucide-react v1.61.0 - ISC\n *\n * This source code is licensed under the ISC license.\n * See the LICENSE file in the root directory of this source tree.\n */\n\nimport createLucideIcon from '../createLucideIcon.mjs';\n\nconst __iconData = {\n name: \"panel-right-open\",\n size: 24,\n node: [\n [\"rect\", { width: \"18\", height: \"18\", x: \"3\", y: \"3\", rx: \"2\", key: \"afitv7\" }],\n [\"path\", { d: \"M15 3v18\", key: \"14nvp0\" }],\n [\"path\", { d: \"m10 15-3-3 3-3\", key: \"1pgupc\" }]\n ]\n};\n__iconData.node;\nconst PanelRightOpen = createLucideIcon(__iconData);\n\nexport { __iconData, PanelRightOpen as default };\n//# sourceMappingURL=panel-right-open.mjs.map\n","import { type ReactNode, useEffect, useId, useRef, useState } from \"react\";\nimport { cn } from \"../../lib/cn\";\n\nexport interface MenuItem {\n id: string;\n label: string;\n icon?: ReactNode;\n onSelect: () => void;\n danger?: boolean;\n disabled?: boolean;\n /** Short explanation shown under the label (e.g. why it is disabled). */\n hint?: string;\n}\n\nexport interface MenuProps {\n /** Render the trigger; spread the given props onto a button. */\n trigger: (props: {\n ref: React.Ref<HTMLButtonElement>;\n onClick: () => void;\n onKeyDown: (e: React.KeyboardEvent) => void;\n \"aria-haspopup\": \"menu\";\n \"aria-expanded\": boolean;\n \"aria-controls\": string;\n }) => ReactNode;\n items: (MenuItem | \"separator\")[];\n align?: \"start\" | \"end\";\n /** Accessible name of the menu. */\n label: string;\n}\n\n/** Popup menu with arrow-key navigation, Escape and outside click to close. */\nexport function Menu({ trigger, items, align = \"end\", label }: MenuProps) {\n const [open, setOpen] = useState(false);\n const id = useId();\n const btnRef = useRef<HTMLButtonElement>(null);\n const menuRef = useRef<HTMLDivElement>(null);\n\n const focusItem = (dir: 1 | -1 | \"first\" | \"last\") => focusMenuItem(menuRef.current, dir);\n\n useEffect(() => {\n if (!open) return;\n requestAnimationFrame(() => focusMenuItem(menuRef.current, \"first\"));\n const onDoc = (e: PointerEvent) => {\n if (\n !menuRef.current?.contains(e.target as Node) &&\n !btnRef.current?.contains(e.target as Node)\n ) {\n setOpen(false);\n }\n };\n document.addEventListener(\"pointerdown\", onDoc);\n return () => document.removeEventListener(\"pointerdown\", onDoc);\n }, [open]);\n\n const close = (refocus = true) => {\n setOpen(false);\n if (refocus) btnRef.current?.focus();\n };\n\n return (\n <div className=\"relative inline-flex\">\n {trigger({\n ref: btnRef,\n onClick: () => setOpen((o) => !o),\n onKeyDown: (e) => {\n if (e.key === \"ArrowDown\" || e.key === \"ArrowUp\") {\n e.preventDefault();\n setOpen(true);\n }\n },\n \"aria-haspopup\": \"menu\",\n \"aria-expanded\": open,\n \"aria-controls\": id,\n })}\n {open && (\n <div\n ref={menuRef}\n id={id}\n role=\"menu\"\n aria-label={label}\n tabIndex={-1}\n className={cn(\n \"absolute top-full z-40 mt-1 min-w-48 max-w-[min(20rem,calc(100vw-1rem))] rounded-lg border border-border bg-surface py-1 shadow-pop\",\n align === \"end\" ? \"right-0\" : \"left-0\",\n )}\n onKeyDown={(e) => {\n if (e.key === \"ArrowDown\") {\n e.preventDefault();\n focusItem(1);\n } else if (e.key === \"ArrowUp\") {\n e.preventDefault();\n focusItem(-1);\n } else if (e.key === \"Home\") {\n e.preventDefault();\n focusItem(\"first\");\n } else if (e.key === \"End\") {\n e.preventDefault();\n focusItem(\"last\");\n } else if (e.key === \"Escape\") {\n e.preventDefault();\n e.stopPropagation();\n close();\n } else if (e.key === \"Tab\") {\n close(false);\n }\n }}\n >\n {items.map((item, i) =>\n item === \"separator\" ? (\n // biome-ignore lint/suspicious/noArrayIndexKey: separators have no identity\n <hr key={`sep-${i}`} className=\"my-1 border-t border-border\" />\n ) : (\n <button\n key={item.id}\n type=\"button\"\n role=\"menuitem\"\n disabled={item.disabled}\n className={cn(\n \"tap flex w-full items-start gap-2 px-3 py-2 text-left text-sm hover:bg-surface-2 focus:bg-surface-2 focus:outline-none disabled:opacity-55\",\n item.danger ? \"text-danger\" : \"text-text\",\n )}\n onClick={() => {\n close();\n item.onSelect();\n }}\n >\n {item.icon && <span className=\"mt-0.5 shrink-0\">{item.icon}</span>}\n <span className=\"min-w-0\">\n <span className=\"block\">{item.label}</span>\n {item.hint && <span className=\"block text-xs text-muted\">{item.hint}</span>}\n </span>\n </button>\n ),\n )}\n </div>\n )}\n </div>\n );\n}\n\nfunction focusMenuItem(menu: HTMLElement | null, dir: 1 | -1 | \"first\" | \"last\"): void {\n const els = [...(menu?.querySelectorAll<HTMLElement>('[role=\"menuitem\"]:not([disabled])') ?? [])];\n if (els.length === 0) return;\n const idx = els.indexOf(document.activeElement as HTMLElement);\n let next = 0;\n if (dir === \"first\") next = 0;\n else if (dir === \"last\") next = els.length - 1;\n else next = (idx + dir + els.length) % els.length;\n els[next]!.focus();\n}\n"],"ignoreList":[0,1,2],"mappings":"A,uGASA,IAAMA,EAAa,CACjB,KAAM,aACN,KAAM,GACN,KAAM,CACJ,CAAC,OAAQ,CAAE,EAAG,WAAY,IAAK,QAAS,CAAC,EACzC,CAAC,OAAQ,CAAE,EAAG,iBAAkB,IAAK,QAAS,CAAC,CACjD,CACF,EACAA,EAAW,KACX,IAAMU,EAAYC,EAAiBX,CAAU,ECTvCC,EAAa,CACjB,KAAM,eACN,KAAM,GACN,KAAM,CAAC,CAAC,OAAQ,CAAE,EAAG,eAAgB,IAAK,QAAS,CAAC,CAAC,CACvD,EACAA,EAAW,KACX,IAAMY,EAAcF,EAAiBV,CAAU,ECNzCa,EAAa,CACjB,KAAM,mBACN,KAAM,GACN,KAAM,CACJ,CAAC,OAAQ,CAAE,MAAO,KAAM,OAAQ,KAAM,EAAG,IAAK,EAAG,IAAK,GAAI,IAAK,IAAK,QAAS,CAAC,EAC9E,CAAC,OAAQ,CAAE,EAAG,WAAY,IAAK,QAAS,CAAC,EACzC,CAAC,OAAQ,CAAE,EAAG,iBAAkB,IAAK,QAAS,CAAC,CACjD,CACF,EACAA,EAAW,KACX,IAAMC,EAAiBJ,EAAiBG,CAAU,E,iBCYlD,SAAgBI,EAAK,CAAE,UAAS,QAAO,QAAQ,MAAO,SAAoB,CACxE,GAAM,CAACC,EAAMC,IAAA,EAAWlB,EAAAA,SAAAA,CAAS,EAAK,EAChCmB,GAAA,EAAKlB,EAAAA,MAAAA,CAAM,EACXmB,GAAA,EAASlB,EAAAA,OAAAA,CAA0B,IAAI,EACvCmB,GAAA,EAAUnB,EAAAA,OAAAA,CAAuB,IAAI,EAErCoB,EAAa,GAAmCC,EAAcF,EAAQ,QAASG,CAAG,GAExF,EAAAV,EAAA,UAAA,KAAgB,CACd,GAAI,CAACG,EAAM,OACX,0BAA4BM,EAAcF,EAAQ,QAAS,OAAO,CAAC,EACnE,IAAMI,EAAS,GAAoB,CAE/B,CAACJ,EAAQ,SAAS,SAAS,EAAE,MAAc,GAC3C,CAACD,EAAO,SAAS,SAAS,EAAE,MAAc,GAE1CF,EAAQ,EAAK,CAEjB,EAEA,OADA,SAAS,iBAAiB,cAAeO,CAAK,MACjC,SAAS,oBAAoB,cAAeA,CAAK,CAChE,EAAG,CAACR,CAAI,CAAC,EAET,IAAMS,GAAS,EAAU,KAAS,CAChCR,EAAQ,EAAK,EACTS,GAASP,EAAO,SAAS,MAAM,CACrC,EAEA,OACE,EAAAL,EAAA,KAAA,CAAC,MAAD,CAAK,UAAU,uBAAf,SAAA,CACGa,EAAQ,CACP,IAAKR,EACL,YAAeF,EAAS,GAAM,CAACW,CAAC,EAChC,UAAY,GAAM,EACZ,EAAE,MAAQ,aAAe,EAAE,MAAQ,aACrC,EAAE,eAAe,EACjBX,EAAQ,EAAI,EAEhB,EACA,gBAAiB,OACjB,gBAAiBD,EACjB,gBAAiBE,CACnB,CAAC,EACAF,IACC,EAAAF,EAAA,IAAA,CAAC,MAAD,CACE,IAAKM,EACD,KACJ,KAAK,OACL,aAAYS,EACZ,SAAU,GACV,UAAWxB,EACT,sIACAyB,IAAU,MAAQ,UAAY,QAChC,EACA,UAAY,GAAM,CACZ,EAAE,MAAQ,aACZ,EAAE,eAAe,EACjBT,EAAU,CAAC,GACF,EAAE,MAAQ,WACnB,EAAE,eAAe,EACjBA,EAAU,EAAE,GACH,EAAE,MAAQ,QACnB,EAAE,eAAe,EACjBA,EAAU,OAAO,GACR,EAAE,MAAQ,OACnB,EAAE,eAAe,EACjBA,EAAU,MAAM,GACP,EAAE,MAAQ,UACnB,EAAE,eAAe,EACjB,EAAE,gBAAgB,EAClBI,EAAM,GACG,EAAE,MAAQ,OACnBA,EAAM,EAAK,CAEf,EAEC,SAAAM,EAAM,KAAK,EAAM,IAChBC,IAAS,aAEP,EAAAlB,EAAA,IAAA,CAAC,KAAD,CAAqB,UAAU,6BAA+B,EAArD,OAAOmB,GAA8C,GAE9D,EAAAnB,EAAA,KAAA,CAAC,SAAD,CAEE,KAAK,SACL,KAAK,WACL,SAAUkB,EAAK,SACf,UAAW3B,EACT,6IACA2B,EAAK,OAAS,cAAgB,WAChC,EACA,YAAe,CACbP,EAAM,EACNO,EAAK,SAAS,CAChB,EAZF,SAAA,CAcGA,EAAK,OAAQ,EAAAlB,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,kBAAmB,SAAAkB,EAAK,IAAW,CAAA,GACjE,EAAAlB,EAAA,KAAA,CAAC,OAAD,CAAM,UAAU,UAAhB,SAAA,EACE,EAAAA,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,QAAS,SAAAkB,EAAK,KAAY,CAAA,EACzCA,EAAK,OAAQ,EAAAlB,EAAA,IAAA,CAAC,OAAD,CAAM,UAAU,2BAA4B,SAAAkB,EAAK,IAAW,CAAA,CACtE,CACA,CAAA,CAAA,CAlBD,EAAAA,EAAK,EAkBJ,CAEZ,CACG,CAAA,CAEJ,C,EAET,CAEA,SAASV,EAAc,EAA0B,EAAsC,CACrF,IAAMY,EAAM,CAAC,GAAIC,GAAM,iBAA8B,mCAAmC,GAAK,CAAC,CAAE,EAChG,GAAID,EAAI,SAAW,EAAG,OACtB,IAAME,EAAMF,EAAI,QAAQ,SAAS,aAA4B,EACzDG,EAAO,EACX,AAEKA,EAFDd,IAAQ,QAAgB,EACnBA,IAAQ,OAAeW,EAAI,OAAS,GAChCE,EAAMb,EAAMW,EAAI,QAAUA,EAAI,OAC3CA,EAAIG,EAAK,CAAE,MAAM,CACnB,C"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import{_ as e,a as t,f as n,i as r,m as i,n as a,o,p as s,t as c,u as l}from"./jsx-runtime-D13aM9HY.js";import{A as u,E as d,G as f,I as p,M as m,N as h,O as g,P as _,U as v,V as y,W as b,_ as x,a as S,c as C,d as w,f as T,g as E,h as D,i as O,j as k,k as A,l as j,m as M,n as N,o as P,p as F,t as I,x as L,y as ee}from"./states-DrTQuYXw.js";import{n as te}from"./presence-05bJD5G3.js";import{i as ne,n as re,r as ie,t as ae}from"./Menu-Cqil5qVF.js";import{t as oe}from"./arrow-left-C6YWM6y6.js";import{n as se,t as ce}from"./server-SxFxIScj.js";import{n as le,r as R,t as ue}from"./send-CFwekPNi.js";import{t as z}from"./chevron-right-evVLS6hq.js";import{t as de}from"./copy-oWgGHmkS.js";import{i as fe,n as pe,r as me,t as he}from"./InteractionCard-BRI9KgrO.js";import{n as ge,t as _e}from"./pencil-DI8QbCN8.js";import{t as ve}from"./hand-UPoHamrn.js";import{t as ye}from"./link-2-CaMlUDRG.js";import{t as be}from"./play-CjoDg3ws.js";import{t as xe}from"./plus-BLP-wIYD.js";import{t as Se}from"./search-C6cn5WOo.js";import{t as Ce}from"./trash-C6X2OLrI.js";import{A as we,C as Te,I as Ee,T as De,a as B,b as Oe,c as V,d as H,g as ke,i as Ae,m as je,n as Me,o as Ne,s as U,x as Pe}from"./index-B11DJFHW.js";import{n as Fe,t as Ie}from"./TextArea-BsQHOQMe.js";import{i as Le,n as Re,r as ze,t as Be}from"./Markdown-jXkvZeRp.js";import{t as Ve}from"./SegmentedControl-ChdVilXb.js";import{i as W,n as He,r as Ue,t as We}from"./Overlay-B9h5oAe6.js";var Ge={name:`archive`,size:24,node:[[`rect`,{width:`20`,height:`5`,x:`2`,y:`3`,rx:`1`,key:`1wp1u1`}],[`path`,{d:`M4 8v11a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8`,key:`1s80jp`}],[`path`,{d:`M10 12h4`,key:`a56b0p`}]]};Ge.node;var Ke=a(Ge),qe={name:`bot`,size:24,node:[[`path`,{d:`M12 8V4H8`,key:`hb8ula`}],[`rect`,{width:`16`,height:`12`,x:`4`,y:`8`,rx:`2`,key:`enze0r`}],[`path`,{d:`M2 14h2`,key:`vft8re`}],[`path`,{d:`M20 14h2`,key:`4cs60a`}],[`path`,{d:`M15 13v2`,key:`1xurst`}],[`path`,{d:`M9 13v2`,key:`rq6x2g`}]]};qe.node;var Je=a(qe),Ye={name:`brain`,size:24,node:[[`path`,{d:`M12 18V5`,key:`adv99a`}],[`path`,{d:`M15 13a4.17 4.17 0 01-3-4 4.17 4.17 0 01-3 4`,key:`5nuw1p`}],[`path`,{d:`M17.707 6.294A3 3 0 1012 5a3 3 0 10-5.707 1.294`,key:`18ldcf`}],[`path`,{d:`M17.996 5.125a4 4 0 012.526 5.77`,key:`1sdu8q`}],[`path`,{d:`M18 18a4 4 0 002-7.465`,key:`7xqqvr`}],[`path`,{d:`M19.967 17.482a4 4 0 11-7.967.517 4 4 0 11-7.967-.517`,key:`t46ysz`}],[`path`,{d:`M6 18a4 4 0 01-2-7.465`,key:`1y2m15`}],[`path`,{d:`M6.004 5.125a4 4 0 00-2.526 5.77`,key:`3cw1ss`}]]};Ye.node;var Xe=a(Ye),Ze={name:`camera`,size:24,node:[[`path`,{d:`M13.997 4a2 2 0 0 1 1.76 1.05l.486.9A2 2 0 0 0 18.003 7H20a2 2 0 0 1 2 2v9a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V9a2 2 0 0 1 2-2h1.997a2 2 0 0 0 1.759-1.048l.489-.904A2 2 0 0 1 10.004 4z`,key:`18u6gg`}],[`circle`,{cx:`12`,cy:`13`,r:`3`,key:`1vg3eu`}]]};Ze.node;var Qe=a(Ze),$e={name:`chevron-up`,size:24,node:[[`path`,{d:`m18 15-6-6-6 6`,key:`153udz`}]]};$e.node;var et=a($e),tt={name:`chevrons-down-up`,size:24,node:[[`path`,{d:`m7 20 5-5 5 5`,key:`13a0gw`}],[`path`,{d:`m7 4 5 5 5-5`,key:`1kwcof`}]]};tt.node;var nt=a(tt),rt={name:`chevrons-up-down`,size:24,node:[[`path`,{d:`m7 15 5 5 5-5`,key:`1hf1tw`}],[`path`,{d:`m7 9 5-5 5 5`,key:`sgt6xg`}]]};rt.node;var it=a(rt),at={name:`ellipsis-vertical`,size:24,node:[[`circle`,{cx:`12`,cy:`12`,r:`1`,key:`41hilf`}],[`circle`,{cx:`12`,cy:`5`,r:`1`,key:`gxeob9`}],[`circle`,{cx:`12`,cy:`19`,r:`1`,key:`lyex9k`}]],aliases:[`more-vertical`]};at.node;var ot=a(at),st={name:`file-diff`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M9 10h6`,key:`9gxzsh`}],[`path`,{d:`M12 13V7`,key:`h0r20n`}],[`path`,{d:`M9 17h6`,key:`r8uit2`}]]};st.node;var ct=a(st),lt={name:`file`,size:24,node:[[`path`,{d:`M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z`,key:`1oefj6`}],[`path`,{d:`M14 2v5a1 1 0 0 0 1 1h5`,key:`wfsgrz`}]]};lt.node;var ut=a(lt),dt={name:`folder-open`,size:24,node:[[`path`,{d:`m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2`,key:`usdka0`}]]};dt.node;var ft=a(dt),pt={name:`folder`,size:24,node:[[`path`,{d:`M20 20a2 2 0 0 0 2-2V8a2 2 0 0 0-2-2h-7.9a2 2 0 0 1-1.69-.9L9.6 3.9A2 2 0 0 0 7.93 3H4a2 2 0 0 0-2 2v13a2 2 0 0 0 2 2Z`,key:`1kt360`}]]};pt.node;var mt=a(pt),ht={name:`image-plus`,size:24,node:[[`path`,{d:`M16 5h6`,key:`1vod17`}],[`path`,{d:`M19 2v6`,key:`4bpg5p`}],[`path`,{d:`M21 11.5V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7.5`,key:`1ue2ih`}],[`path`,{d:`m21 15-3.086-3.086a2 2 0 0 0-2.828 0L6 21`,key:`1xmnt7`}],[`circle`,{cx:`9`,cy:`9`,r:`2`,key:`af1f0g`}]]};ht.node;var gt=a(ht),_t={name:`list-plus`,size:24,node:[[`path`,{d:`M16 5H3`,key:`m91uny`}],[`path`,{d:`M11 12H3`,key:`51ecnj`}],[`path`,{d:`M16 19H3`,key:`zzsher`}],[`path`,{d:`M18 9v6`,key:`1twb98`}],[`path`,{d:`M21 12h-6`,key:`bt1uis`}]]};_t.node;var vt=a(_t),yt={name:`message-square-plus`,size:24,node:[[`path`,{d:`M22 17a2 2 0 0 1-2 2H6.828a2 2 0 0 0-1.414.586l-2.202 2.202A.71.71 0 0 1 2 21.286V5a2 2 0 0 1 2-2h16a2 2 0 0 1 2 2z`,key:`18887p`}],[`path`,{d:`M12 8v6`,key:`1ib9pf`}],[`path`,{d:`M9 11h6`,key:`1fldmi`}]]};yt.node;var bt=a(yt),xt={name:`mouse-pointer-click`,size:24,node:[[`path`,{d:`M14 4.1 12 6`,key:`ita8i4`}],[`path`,{d:`m5.1 8-2.9-.8`,key:`1go3kf`}],[`path`,{d:`m6 12-1.9 2`,key:`mnht97`}],[`path`,{d:`M7.2 2.2 8 5.1`,key:`1cfko1`}],[`path`,{d:`M9.037 9.69a.498.498 0 0 1 .653-.653l11 4.5a.5.5 0 0 1-.074.949l-4.349 1.041a1 1 0 0 0-.74.739l-1.04 4.35a.5.5 0 0 1-.95.074z`,key:`s0h3yz`}]]};xt.node;var St=a(xt),Ct={name:`navigation`,size:24,node:[[`polygon`,{points:`3 11 22 2 13 21 11 13 3 11`,key:`1ltx0t`}]]};Ct.node;var wt=a(Ct),Tt={name:`network`,size:24,node:[[`rect`,{x:`16`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`4q2zg0`}],[`rect`,{x:`2`,y:`16`,width:`6`,height:`6`,rx:`1`,key:`8cvhb9`}],[`rect`,{x:`9`,y:`2`,width:`6`,height:`6`,rx:`1`,key:`1egb70`}],[`path`,{d:`M5 16v-3a1 1 0 0 1 1-1h12a1 1 0 0 1 1 1v3`,key:`1jsf9p`}],[`path`,{d:`M12 12V8`,key:`2874zd`}]]};Tt.node;var Et=a(Tt),Dt={name:`panel-right-close`,size:24,node:[[`rect`,{width:`18`,height:`18`,x:`3`,y:`3`,rx:`2`,key:`afitv7`}],[`path`,{d:`M15 3v18`,key:`14nvp0`}],[`path`,{d:`m8 9 3 3-3 3`,key:`12hl5m`}]]};Dt.node;var Ot=a(Dt),kt={name:`paperclip`,size:24,node:[[`path`,{d:`m16 6-8.414 8.586a2 2 0 0 0 2.829 2.829l8.414-8.586a4 4 0 1 0-5.657-5.657l-8.379 8.551a6 6 0 1 0 8.485 8.485l8.379-8.551`,key:`1miecu`}]]};kt.node;var At=a(kt),jt={name:`search-x`,size:24,node:[[`path`,{d:`m13.5 8.5-5 5`,key:`1cs55j`}],[`path`,{d:`m8.5 8.5 5 5`,key:`a8mexj`}],[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`path`,{d:`m21 21-4.3-4.3`,key:`1qie3q`}]]};jt.node;var Mt=a(jt),Nt={name:`send-horizontal`,size:24,node:[[`path`,{d:`M3.714 3.048a.498.498 0 0 0-.683.627l2.843 7.627a2 2 0 0 1 0 1.396l-2.842 7.627a.498.498 0 0 0 .682.627l18-8.5a.5.5 0 0 0 0-.904z`,key:`117uat`}],[`path`,{d:`M6 12h16`,key:`s4cdu5`}]],aliases:[`send-horizonal`]};Nt.node;var Pt=a(Nt),Ft={name:`slash`,size:24,node:[[`path`,{d:`M22 2 2 22`,key:`y4kqgn`}]]};Ft.node;var It=a(Ft),Lt={name:`undo-2`,size:24,node:[[`path`,{d:`M9 14 4 9l5-5`,key:`102s5s`}],[`path`,{d:`M4 9h10.5a5.5 5.5 0 0 1 5.5 5.5a5.5 5.5 0 0 1-5.5 5.5H11`,key:`f3b9sd`}]]};Lt.node;var Rt=a(Lt),zt={name:`user`,size:24,node:[[`path`,{d:`M19 21v-2a4 4 0 0 0-4-4H9a4 4 0 0 0-4 4v2`,key:`975kel`}],[`circle`,{cx:`12`,cy:`7`,r:`4`,key:`17ys0d`}]]};zt.node;var Bt=a(zt),Vt={name:`wand-sparkles`,size:24,node:[[`path`,{d:`m21.64 3.64-1.28-1.28a1.21 1.21 0 0 0-1.72 0L2.36 18.64a1.21 1.21 0 0 0 0 1.72l1.28 1.28a1.2 1.2 0 0 0 1.72 0L21.64 5.36a1.2 1.2 0 0 0 0-1.72`,key:`ul74o6`}],[`path`,{d:`m14 7 3 3`,key:`1r5n42`}],[`path`,{d:`M5 6v4`,key:`ilb8ba`}],[`path`,{d:`M19 14v4`,key:`blhpug`}],[`path`,{d:`M10 2v2`,key:`7u0qdc`}],[`path`,{d:`M7 8H3`,key:`zfb6yr`}],[`path`,{d:`M21 16h-4`,key:`1cnmox`}],[`path`,{d:`M11 3H9`,key:`1obp7u`}]],aliases:[`wand-2`]};Vt.node;var Ht=a(Vt),G=e(i(),1),K=c();function Ut({value:e,min:t,max:n,onChange:r,label:i,pane:a=`before`,step:o=16,onReset:s,className:c}){let l=(0,G.useRef)(null),u=e=>Math.round(Math.min(n,Math.max(t,e))),d=a===`before`?1:-1;return(0,K.jsx)(`div`,{role:`separator`,"aria-orientation":`vertical`,"aria-label":i,"aria-valuenow":Math.round(e),"aria-valuemin":t,"aria-valuemax":n,tabIndex:0,className:D(`group relative z-10 w-1.5 shrink-0 cursor-col-resize touch-none select-none`,`focus-visible:outline-none`,c),onPointerDown:t=>{t.preventDefault(),t.currentTarget.setPointerCapture(t.pointerId),l.current={x:t.clientX,value:e}},onPointerMove:e=>{l.current&&r(u(l.current.value+d*(e.clientX-l.current.x)))},onPointerUp:e=>{l.current=null,e.currentTarget.releasePointerCapture(e.pointerId)},onPointerCancel:()=>{l.current=null},onDoubleClick:s,onKeyDown:i=>{let a=i.shiftKey?o*4:o;if(i.key===`ArrowRight`)r(u(e+d*a));else if(i.key===`ArrowLeft`)r(u(e-d*a));else if(i.key===`Home`)r(t);else if(i.key===`End`)r(n);else if(i.key===`Enter`&&s)s();else return;i.preventDefault()},children:(0,K.jsx)(`div`,{"aria-hidden":!0,className:`absolute inset-y-0 left-1/2 w-px -translate-x-1/2 bg-border group-hover:w-0.5 group-hover:bg-accent group-focus-visible:w-0.5 group-focus-visible:bg-accent`})})}var Wt=(0,G.createContext)({mobile:!1}),Gt=()=>(0,G.useContext)(Wt),Kt=[`starting`,`idle`,`running`,`waiting_input`],qt=[`running`,`waiting_input`];function Jt(e){return Kt.includes(e.runtime)}function Yt(e){return qt.includes(e.runtime)}function Xt(e){return e.replaceAll(`/`,`-`)}var Zt=`.worktrees`;function Qt(e,t,n=Zt){return`${e.replace(/\/+$/,``)}/${n}/${Xt(t.trim())}`}function $t(e){let t=e.trim();return t?/\s/.test(t)?`Branch names cannot contain spaces.`:t.startsWith(`-`)?`Branch names cannot start with '-'.`:t.startsWith(`/`)||t.endsWith(`/`)?`Branch names cannot start or end with '/'.`:t.includes(`..`)?`Branch names cannot contain '..'.`:t.includes(`//`)?`Branch names cannot contain '//'.`:t.endsWith(`.lock`)||t.endsWith(`.`)?`Branch names cannot end with '.lock' or '.'.`:[...t].some(e=>e.charCodeAt(0)<32||e.charCodeAt(0)===127)||/[~^:?*[\\]/.test(t)||t.includes(`@{`)?`Branch names cannot contain ~ ^ : ? * [ \\ or '@{'.`:null:`Enter a branch name.`}function en(e,t){let n=new Set;for(let t of Object.values(e))t.sessionId&&t.resolvedAt===null&&n.add(t.sessionId);for(let e of Object.values(t))e.state===`pending`&&n.add(e.sessionId);return n}function tn(e){return e.replace(/\/+$/,``).split(`/`).pop()||e}function nn(e,t){return e?e.branch?e.branch:`${tn(e.path)} (detached)`:t?tn(t):`No workspace`}function rn(e,t){let n=t.query.trim().toLowerCase(),r=en(e.attention,e.interactions),i=new Map,a=new Map,o=t=>{let n=t??`__none`,r=i.get(n);if(!r){let a=t?e.projects[t]??null:null;r={key:n,project:a,label:a?.name??(t?`Unknown project`:`Other sessions`),workspaces:[],sessionCount:0},i.set(n,r)}return r},s=(t,n,r,i)=>{let o=n?n.id:`${t.key}:${r}`,s=a.get(o);if(!s){let r=n?.hostId??i?.hostId??null;s={key:o,workspace:n,label:nn(n,i?.cwd),hostName:r?e.hosts[r]?.name??`Unknown host`:null,sessions:[]},a.set(o,s),t.workspaces.push(s)}return s},c=(e,t,r)=>!n||[e.title,e.subtitle??``,t?.branch??``,r?.name??``,e.cwd].join(`
|
|
2
|
-
`).toLowerCase().includes(n),l=Object.values(e.sessions).filter(e=>e.archivedAt===null).sort((e,t)=>t.lastActivityAt.localeCompare(e.lastActivityAt));for(let n of l){let i=r.has(n.id);if(t.filter===`active`&&!Jt(n)&&!i||t.filter===`attention`&&!i)continue;let a=n.workspaceId?e.workspaces[n.workspaceId]??null:null,l=n.projectId??a?.projectId??null;if(!c(n,a,l?e.projects[l]??null:null))continue;let u=o(l);s(u,a,a?a.id:`cwd:${n.hostId}:${n.cwd}`,n).sessions.push({session:n,attention:i}),u.sessionCount++}if(t.filter===`all`){for(let t of Object.values(e.workspaces)){if(t.archivedAt)continue;let r=e.projects[t.projectId]??null;(!n||[t.branch??``,r?.name??``,t.path].join(`
|
|
3
|
-
`).toLowerCase().includes(n))&&s(o(t.projectId),t,t.id)}if(!n)for(let t of Object.values(e.projects))o(t.id)}let u=[...i.values()];for(let e of u)e.workspaces.sort((e,t)=>{let n=e.sessions[0]?.session.lastActivityAt??``,r=t.sessions[0]?.session.lastActivityAt??``;return n===r?(e.workspace?.provenance===`main`?0:1)-(t.workspace?.provenance===`main`?0:1)||e.label.localeCompare(t.label):r.localeCompare(n)});return u.sort((e,t)=>e.key===`__none`?1:t.key===`__none`?-1:e.label.localeCompare(t.label))}var an=[`queued`,`dispatching`,`uncertain`,`running`,`waiting_input`,`checking`];function on(e,t){if(t.runId&&e[t.runId])return e[t.runId];let n=null;for(let r of Object.values(e))r.sessionId===t.id&&an.includes(r.state)&&(!n||r.createdAt>n.createdAt)&&(n=r);return n}function sn(e){return e?e.controlMode:`none`}var cn={automation:`Automation`,human:`You have control`,none:`Manual session`};function ln(e,t){return e?.revokedAt?`unreachable`:e?.connectivity??t.connectivity}var un=`Subagent: view only. Live control is not supported.`;function dn(e){return e.provenance===`subagent`&&e.readOnly}function fn(e){let{session:t,hostLink:n}=e;return t.readOnly?{reason:un}:t.archivedAt?{reason:`Session archived: unarchive it to send`}:n===`connected`?t.runtime===`starting`?{reason:`Starting… you can send once Pi is ready`}:Jt(t)?null:{reason:t.nativeHandle?`Session stopped: Resume to send`:`Session stopped: no native Pi session to resume`,action:t.nativeHandle?`resume`:void 0}:{reason:n===`reconnecting`?`Host offline: ${e.hostName} is reconnecting`:`Host offline: ${e.hostName} is unreachable`}}function pn(e,t){return Yt(e)?{prompt:!1,steer:t?.steer===!0,followUp:!t||t.followUp}:{prompt:!0,steer:!1,followUp:!1}}function mn(e,t,n){let r=new Map(t.map(e=>[e.itemId,e])),i=[],a=new Set;for(let t of e){let e=r.get(t.id)??null;e&&r.delete(t.id),t.kind===`interaction`&&a.add(t.data.interactionId),i.push({type:`item`,key:t.id,item:t,stream:e})}let o=[...r.values()].sort((e,t)=>(e.order??2**53-1)-(t.order??2**53-1));for(let e of o)(e.text||e.thinking||e.toolArgs||e.toolOutput)&&i.push({type:`stream`,key:`stream:${e.itemId}`,stream:e});for(let e of n)a.has(e.id)||i.push({type:`interaction`,key:`interaction:${e.id}`,interaction:e});return i}function hn(e,t){if(t===null)return e.length;let n=e.findIndex(e=>e.key===t);return n<0?0:e.length-n-1}function gn(e){return`interaction-${e}`}function _n(e){let t=/^data:([^;,]+)?(;base64)?,(.*)$/s.exec(e);return t?.[2]?{mimeType:t[1]??`application/octet-stream`,data:t[3]??``}:null}function vn(e){return new Promise((t,n)=>{if(!e.type.startsWith(`image/`)){n(Error(`${e.name} is not an image`));return}if(e.size>10485760){n(Error(`${e.name} is larger than 10 MB`));return}let r=new FileReader;r.onerror=()=>n(r.error??Error(`Could not read ${e.name}`)),r.onload=()=>{let i=_n(String(r.result??``));i?t({id:`att_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,name:e.name,mimeType:i.mimeType||e.type,data:i.data,size:e.size}):n(Error(`Could not read ${e.name}`))},r.readAsDataURL(e)})}function yn(e){if(e==null)return``;if(typeof e==`string`)return e;try{return JSON.stringify(e,null,2)}catch{return String(e)}}function bn(e,t=6){let n=e.replace(/\n+$/,``).split(`
|
|
4
|
-
`);if(n.length<=t&&e.length<=600)return{text:e,truncated:!1};let r=n.slice(-t).join(`
|
|
5
|
-
`);return{text:r.length>600?r.slice(-600):r,truncated:!0}}var xn=6;function Sn(e,t,n){if(e<=0)return{nav:t,insp:n};let r=n===null?xn:12,i=t+(n??0)+r+420-e,a=n,o=t;if(i>0&&a!==null){let e=Math.min(i,a-B.inspector.min);a-=e,i-=e}if(i>0){let e=Math.min(i,o-B.navigator.min);o-=e}return{nav:o,insp:a}}var Cn=[];function wn(e){let t=_(t=>e?t.hosts[e.hostId]:void 0),n=_(t=>e?.projectId?t.projects[e.projectId]:void 0),r=_(t=>e?.workspaceId?t.workspaces[e.workspaceId]:void 0),i=_(e=>e.runs),a=_(e=>e.tasks),o=_(t=>e?t.adapters[e.hostId]??Cn:Cn);return(0,G.useMemo)(()=>{if(!e)return null;let s=on(i,e),c=e.taskId??s?.taskId??null;return{session:e,host:t,hostName:t?.name??`Unknown host`,link:ln(t,e),project:n,workspace:r,run:s,task:c?a[c]:void 0,control:sn(s),adapters:o}},[e,t,n,r,i,a,o])}function q(e,t={}){let[n,r]=(0,G.useState)(!1),[i,a]=(0,G.useState)(null),o=(0,G.useRef)(e);o.current=e;let s=(0,G.useRef)(t);s.current=t;let c=(0,G.useRef)(!0);return(0,G.useEffect)(()=>(c.current=!0,()=>{c.current=!1}),[]),{run:(0,G.useCallback)(async(...e)=>{r(!0),a(null);try{let t=await o.current(...e),{success:n}=s.current,r=typeof n==`function`?n(t):n;return r&&V.success(r),!0}catch(e){return c.current&&a(e),s.current.errorToast&&V.error(b(e)),!1}finally{c.current&&r(!1)}},[]),busy:n,error:i,reset:(0,G.useCallback)(()=>a(null),[])}}function Tn(e,t=1e3){let[n,r]=(0,G.useState)(()=>Date.now());return(0,G.useEffect)(()=>{if(!e)return;r(Date.now());let n=setInterval(()=>r(Date.now()),t);return()=>clearInterval(n)},[e,t]),n}var En=`sy:draft:`,Dn=`sy:review:`;function On(e){try{return localStorage.getItem(e)}catch{return null}}function kn(e,t){try{t===null||t===``?localStorage.removeItem(e):localStorage.setItem(e,t)}catch{}}function An(e){return On(En+e)??``}var J=new Map;function jn(e,t){let n=J.get(e);n&&clearTimeout(n.timer);let r=setTimeout(()=>{J.delete(e),kn(En+e,t)},300);J.set(e,{timer:r,text:t})}function Mn(e){let t=J.get(e);t&&(clearTimeout(t.timer),J.delete(e),kn(En+e,t.text))}function Nn(e){let t=J.get(e);t&&clearTimeout(t.timer),J.delete(e),kn(En+e,null)}typeof window<`u`&&window.addEventListener(`pagehide`,()=>{for(let e of[...J.keys()])Mn(e)});function Pn(e){let[t,n]=(0,G.useState)(()=>e?An(e):``),r=(0,G.useRef)(e);return(0,G.useEffect)(()=>(r.current=e,n(e?An(e):``),()=>{e&&Mn(e)}),[e]),[t,(0,G.useCallback)(e=>{n(e),r.current&&jn(r.current,e)},[]),(0,G.useCallback)(()=>{n(``),r.current&&Nn(r.current)},[])]}function Fn(e){let t=On(Dn+e);if(!t)return[];try{let e=JSON.parse(t);return Array.isArray(e)?e:[]}catch{return[]}}function In(e,t){kn(Dn+e,t.length?JSON.stringify(t):null)}function Ln(e){let t=[`Please address these review comments:`,``];for(let n of e){let e=n.line===null?n.file:`${n.file}:${n.line}`;t.push(`- ${e}: ${n.text}`),n.excerpt&&t.push(` > ${n.excerpt}`)}return t.join(`
|
|
6
|
-
`)}function Rn(e){let[t,n]=(0,G.useState)(()=>e?Fn(e):[]);(0,G.useEffect)(()=>{n(e?Fn(e):[])},[e]);let r=(0,G.useCallback)(t=>{n(t),e&&In(e,t)},[e]);return{comments:t,add:(0,G.useCallback)(t=>{let r={...t,id:`rc_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`,createdAt:new Date().toISOString()};n(t=>{let n=[...t,r];return e&&In(e,n),n})},[e]),remove:(0,G.useCallback)(t=>{n(n=>{let r=n.filter(e=>e.id!==t);return e&&In(e,r),r})},[e]),clear:(0,G.useCallback)(()=>r([]),[r]),set:r}}var Y=e=>`/api/sessions/${encodeURIComponent(e)}`,zn=e=>`/api/workspaces/${encodeURIComponent(e)}`,Bn=e=>`/api/tasks/${encodeURIComponent(e)}`,X={createSession:e=>v(`/api/sessions`,e),prompt:(e,t)=>v(`${Y(e)}/prompt`,t),abort:(e,t=!1)=>v(`${Y(e)}/abort`,{clearQueue:t}),stop:e=>v(`${Y(e)}/stop`),resume:e=>v(`${Y(e)}/resume`),takeover:e=>v(`${Y(e)}/takeover`),returnToAutomation:e=>v(`${Y(e)}/return-to-automation`),rename:(e,t)=>v(`${Y(e)}/rename`,{title:t}),archive:e=>v(`${Y(e)}/archive`),unarchive:e=>v(`${Y(e)}/unarchive`),adapterAction:(e,t,n,r)=>v(`${Y(e)}/adapter-action`,{adapterId:t,actionId:n,payload:r}),diff:(e,t,n)=>y(`${zn(e)}/diff`,t?{file:t}:void 0,n),files:async(e,t,n)=>Vn(await y(`${zn(e)}/files`,{dir:t},n)),file:async(e,t,n)=>Hn(await y(`${zn(e)}/file`,{path:t},n)),refreshWorkspace:e=>v(`${zn(e)}/refresh`),requestChanges:(e,t)=>v(`${Bn(e)}/request-changes`,{feedback:t}),accept:(e,t)=>v(`${Bn(e)}/accept`,t?{confirm:!0}:{})};function Vn(e){let t=Array.isArray(e)?e:e?.entries??e?.files??[];return Array.isArray(t)?t.filter(e=>e&&typeof e.name==`string`).sort((e,t)=>(e.kind===`dir`?0:1)-(t.kind===`dir`?0:1)||e.name.localeCompare(t.name)):[]}function Hn(e){if(typeof e==`string`)return{text:e,binary:!1,truncated:!1,size:null};let t=e??{},n=typeof t.content==`string`?t.content:typeof t.text==`string`?t.text:null;return{text:n,binary:t.binary===!0||n===null&&t.encoding===`base64`,truncated:t.truncated===!0,size:typeof t.size==`number`?t.size:null}}function Un(e){let t=e.workspace,n=e.link===`connected`,[r,i]=(0,G.useState)(null),[a,o]=(0,G.useState)(!1),[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(0),p=t?.id??null;return(0,G.useEffect)(()=>{if(!p||!n)return;let e=new AbortController;return o(!0),c(null),X.diff(p,void 0,e.signal).then(e=>{i(e),u(new Date().toISOString())}).catch(t=>{e.signal.aborted||c(t)}).finally(()=>{e.signal.aborted||o(!1)}),()=>e.abort()},[p,n,d]),(0,G.useEffect)(()=>{i(null),u(null)},[p]),{result:r,parsed:(0,G.useMemo)(()=>{let e=new Map;if(r?.patch)for(let t of fe(r.patch))e.set(t.path,t);return e},[r]),loading:a,error:s,fetchedAt:l,outdated:!!t&&!!l&&t.updatedAt>l,refresh:(0,G.useCallback)(()=>f(e=>e+1),[])}}function Wn(e,t,n){let r=n?t.parsed.get(n):void 0,[i,a]=(0,G.useState)(null),[o,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(0),u=e.workspace?.id;if((0,G.useEffect)(()=>{if(!n||r||!u||e.link!==`connected`)return;let t=new AbortController;return s(null),X.diff(u,n,t.signal).then(e=>{let t=e.patch?fe(e.patch):[];a({path:n,file:t.find(e=>e.path===n)??t[0]??null})}).catch(e=>{t.signal.aborted||s(e)}),()=>t.abort()},[n,r,u,e.link,c,t.fetchedAt]),!n)return{file:null,loading:!1,error:null,retry:()=>{}};if(r)return{file:r,loading:!1,error:null,retry:()=>{}};let d=i?.path===n?i:null;return{file:d?.file??null,loading:!d&&!o,error:o,retry:()=>l(e=>e+1)}}var Gn={added:`Added`,modified:`Modified`,deleted:`Deleted`,renamed:`Renamed`,untracked:`Untracked`,binary:`Binary`};function Kn({files:e,selected:t,onSelect:n,commentCounts:r,large:i}){return(0,K.jsx)(`ul`,{"aria-label":`Changed files`,className:`flex min-w-0 flex-col`,children:e.map(e=>{let a=r.get(e.path)??0;return(0,K.jsx)(`li`,{className:`min-w-0`,children:(0,K.jsxs)(`button`,{type:`button`,"aria-current":t===e.path?`true`:void 0,onClick:()=>n(e.path),className:D(`tap flex w-full min-w-0 items-center gap-2 rounded-md px-2 text-left text-sm hover:bg-surface-2`,i?`min-h-12 py-2`:`py-1.5`,t===e.path&&`bg-accent-soft`),children:[(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`block truncate font-mono text-xs`,title:e.path,children:e.path}),(0,K.jsxs)(`span`,{className:`block text-xs text-muted`,children:[Gn[e.status],a>0&&` · ${a} comment${a===1?``:`s`}`]})]}),(0,K.jsxs)(`span`,{className:`shrink-0 font-mono text-xs tabular-nums`,children:[(0,K.jsxs)(`span`,{className:`text-success`,children:[`+`,e.added,(0,K.jsx)(`span`,{className:`sr-only`,children:` added`})]}),` `,(0,K.jsxs)(`span`,{className:`text-danger`,children:[`-`,e.deleted,(0,K.jsx)(`span`,{className:`sr-only`,children:` deleted`})]})]}),i&&(0,K.jsx)(z,{"aria-hidden":!0,className:`size-4 shrink-0 text-subtle`})]})},e.path)})})}function qn({ctx:e,diff:t,path:n,comments:r,onComment:i}){let a=Wn(e,t,n);if(a.error)return(0,K.jsx)(N,{compact:!0,title:`Could not load this diff`,error:a.error,onRetry:a.retry});if(a.loading)return(0,K.jsx)(P,{label:`Loading diff…`});if(!a.file)return(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No textual diff for this file.`});let o=new Set(r.filter(e=>e.file===n).map(e=>e.line));return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,K.jsx)(me,{files:[a.file],onLineClick:({file:e,line:t})=>i({file:e,line:t.newLine??t.oldLine,excerpt:t.text}),isLineMarked:({line:e})=>o.has(e.newLine??e.oldLine)}),(0,K.jsx)(j,{size:`sm`,variant:`ghost`,icon:(0,K.jsx)(bt,{className:`size-4`}),onClick:()=>i({file:n,line:null,excerpt:null}),className:`self-start`,children:`Comment on this file`})]})}function Jn({draft:e,mobile:t,onClose:n,onSave:r}){let[i,a]=(0,G.useState)(``),o=(0,G.useRef)(null);(0,G.useEffect)(()=>a(``),[e]);let s=t?Ue:We,c=e?e.line===null?e.file:`${e.file}:${e.line}`:``;return(0,K.jsxs)(s,{open:!!e,onClose:n,title:`Add review comment`,description:c,initialFocus:o,footer:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(j,{onClick:n,children:`Cancel`}),(0,K.jsx)(j,{variant:`primary`,disabled:!i.trim(),onClick:()=>r(i.trim()),children:`Add comment`})]}),children:[e?.excerpt&&(0,K.jsx)(`pre`,{className:`mb-2 max-w-full overflow-x-auto rounded bg-surface-2 px-2 py-1 font-mono text-xs`,children:e.excerpt}),(0,K.jsx)(`label`,{htmlFor:`sy-review-comment`,className:`sr-only`,children:`Comment`}),(0,K.jsx)(Ie,{id:`sy-review-comment`,ref:o,minRows:3,value:i,placeholder:`What should change here?`,onChange:e=>a(e.target.value)}),(0,K.jsx)(`p`,{className:`mt-1 text-xs text-muted`,children:`Comments are collected and sent together, never one at a time.`})]})}function Yn({ctx:e,review:t}){let{session:n,task:r}=e,[i,a]=(0,G.useState)(``),o=fn({session:n,hostLink:e.link,hostName:e.hostName}),s=q(()=>X.prompt(n.id,{text:Ln(t.comments),mode:Yt(n)?`followUp`:`prompt`}),{success:`Review comments sent as one follow-up.`}),c=[...i.trim()?[i.trim()]:[],...t.comments.map(e=>`${e.line===null?e.file:`${e.file}:${e.line}`}: ${e.text}`)],l=q(()=>X.requestChanges(r.id,c),{success:`Changes requested. The task stays in Review until a new attempt starts.`}),u=q(e=>X.accept(r.id,e),{success:`Task accepted and marked Done.`}),d=f(u.error,`invalid_transition`)&&u.error.details?.needsConfirm===!0,p=r?.state===`review`,m=t.comments.length===0?`Add comments by selecting diff lines`:o?.reason;return(0,K.jsxs)(`section`,{"aria-label":`Review`,className:`flex min-w-0 flex-col gap-2 border-t border-border pt-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-semibold`,children:[`Review comments`,t.comments.length>0&&` (${t.comments.length})`]}),t.comments.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`Select a diff line to add a comment.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:t.comments.map(e=>(0,K.jsxs)(`li`,{className:`flex min-w-0 items-start gap-2 rounded-md border border-border px-2 py-1.5`,children:[(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`truncate font-mono text-xs text-muted`,children:e.line===null?e.file:`${e.file}:${e.line}`}),(0,K.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e.text})]}),(0,K.jsx)(W,{size:`sm`,label:`Remove comment`,icon:(0,K.jsx)(Ce,{className:`size-3.5`}),onClick:()=>t.remove(e.id)})]},e.id))}),(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(j,{size:`sm`,variant:p?`secondary`:`primary`,icon:(0,K.jsx)(ue,{className:`size-3.5`}),disabled:!!m,busy:s.busy,onClick:()=>void s.run().then(e=>e&&t.clear()),children:`Send as one follow-up`}),t.comments.length>0&&(0,K.jsx)(j,{size:`sm`,variant:`ghost`,onClick:t.clear,children:`Clear all`})]}),m&&t.comments.length>0&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:m}),s.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Comments not sent; they are kept.`,error:b(s.error),onRetry:()=>void s.run().then(e=>e&&t.clear())}),r&&p&&(0,K.jsxs)(`div`,{className:`mt-2 flex flex-col gap-2 rounded-md border border-border p-3`,children:[(0,K.jsxs)(`h3`,{className:`text-sm font-semibold`,children:[`Task review: `,r.title]}),(0,K.jsx)(`label`,{htmlFor:`sy-overall-feedback`,className:`text-xs font-medium text-muted`,children:`Overall feedback (optional, sent with the comments above)`}),(0,K.jsx)(Ie,{id:`sy-overall-feedback`,minRows:2,value:i,onChange:e=>a(e.target.value)}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(Rt,{className:`size-3.5`}),disabled:c.length===0,busy:l.busy,onClick:()=>void l.run().then(e=>{e&&(t.clear(),a(``))}),children:`Request changes`}),(0,K.jsx)(j,{size:`sm`,variant:`primary`,icon:(0,K.jsx)(se,{className:`size-3.5`}),busy:u.busy,onClick:()=>void u.run(!1),children:`Accept task`})]}),c.length===0&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Request changes needs at least one comment.`}),(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Accepting marks the task Done. It does not merge or push.`}),l.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Could not request changes`,error:b(l.error)}),u.error!==null&&(d?(0,K.jsxs)(`div`,{role:`alert`,className:`flex flex-col gap-2 rounded-md bg-warning-soft p-2 text-sm`,children:[(0,K.jsx)(`p`,{className:`break-words`,children:b(u.error)}),(0,K.jsx)(j,{size:`sm`,variant:`primary`,className:`self-start`,busy:u.busy,onClick:()=>void u.run(!0),children:`Accept anyway`})]}):(0,K.jsx)(N,{compact:!0,title:`Could not accept`,error:b(u.error)}))]}),r?.review.changesRequested&&r.state===`review`&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Changes requested. The task stays in Review until a new attempt is requested.`})]})}function Xn(e){return(0,G.useMemo)(()=>{let t=new Map;for(let n of e)t.set(n.file,(t.get(n.file)??0)+1);return t},[e])}function Zn({ctx:e}){return e.workspace?(0,K.jsx)(O,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.host?.lastSeenAt,detail:`Changes are read from the host; they load when it reconnects.`}):(0,K.jsx)(C,{capability:`Changes`,reason:`This session is not linked to a Switchyard workspace (it runs in ${e.session.cwd}).`,fallback:`Open a session in a project workspace to review changes.`})}function Qn({diff:e}){return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-xs text-muted`,children:[(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[e.result?`Against ${e.result.base}`:``,e.fetchedAt&&` · updated ${M(e.fetchedAt)}`,e.outdated&&` · workspace changed since`]}),(0,K.jsx)(j,{size:`sm`,variant:e.outdated?`secondary`:`ghost`,icon:(0,K.jsx)(x,{className:D(`size-3.5`,e.loading&&`animate-spin`)}),disabled:e.loading,onClick:e.refresh,children:e.loading?`Refreshing…`:`Refresh`})]})}function $n({ctx:e}){let t=Un(e),n=Rn(e.session.id),r=Xn(n.comments),[i,a]=(0,G.useState)(null),[o,s]=(0,G.useState)(null),c=t.result?.files??[];return!e.workspace||e.link!==`connected`?(0,K.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,K.jsx)(Zn,{ctx:e}),n.comments.length>0&&(0,K.jsx)(Yn,{ctx:e,review:n})]}):(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,K.jsx)(Qn,{diff:t}),t.error!==null&&!t.result?(0,K.jsx)(N,{compact:!0,title:`Could not load changes`,error:t.error,onRetry:t.refresh}):t.result?c.length===0?(0,K.jsx)(I,{icon:(0,K.jsx)(ct,{className:`size-8`}),title:`No changes yet`,description:`Nothing differs from ${t.result.base} in this workspace.`,className:`py-6`}):(0,K.jsxs)(K.Fragment,{children:[t.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Refresh failed; showing earlier changes`,error:t.error,onRetry:t.refresh}),(0,K.jsx)(Kn,{files:c,selected:i,onSelect:e=>a(t=>t===e?null:e),commentCounts:r}),i&&(0,K.jsx)(qn,{ctx:e,diff:t,path:i,comments:n.comments,onComment:s})]}):(0,K.jsx)(P,{label:`Loading changes…`}),(0,K.jsx)(Yn,{ctx:e,review:n}),(0,K.jsx)(Jn,{draft:o,mobile:!1,onClose:()=>s(null),onSave:e=>{o&&n.add({...o,text:e}),s(null)}})]})}function er({ctx:e}){let t=Un(e),n=Rn(e.session.id),r=Xn(n.comments),[i,a]=(0,G.useState)(null),[o,s]=(0,G.useState)(null),c=t.result?.files??[],l=i?c.findIndex(e=>e.path===i):-1;return i&&l>=0?(0,K.jsx)(tr,{ctx:e,diff:t,file:c[l],index:l,total:c.length,comments:n.comments,onBack:()=>a(null),onPrev:()=>a(c[l-1]?.path??i),onNext:()=>a(c[l+1]?.path??i),commentDraft:o,setCommentDraft:s,onSaveComment:e=>{o&&n.add({...o,text:e}),s(null)}}):(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-3 px-3 py-3`,children:[!e.workspace||e.link!==`connected`?(0,K.jsx)(Zn,{ctx:e}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Qn,{diff:t}),t.error!==null&&!t.result?(0,K.jsx)(N,{title:`Could not load changes`,error:t.error,onRetry:t.refresh}):t.result?c.length===0?(0,K.jsx)(I,{icon:(0,K.jsx)(ct,{className:`size-8`}),title:`No changes yet`,description:`Nothing differs from ${t.result.base} in this workspace.`}):(0,K.jsx)(Kn,{files:c,selected:null,onSelect:a,commentCounts:r,large:!0}):(0,K.jsx)(P,{label:`Loading changes…`})]}),(0,K.jsx)(Yn,{ctx:e,review:n})]})}function tr({ctx:e,diff:t,file:n,index:r,total:i,comments:a,onBack:o,onPrev:s,onNext:c,commentDraft:l,setCommentDraft:u,onSaveComment:d}){Ae(!0);let f=(0,G.useRef)(null);(0,G.useEffect)(()=>f.current?.focus(),[n.path]);let p=a.filter(e=>e.file===n.path).length;return(0,K.jsxs)(`section`,{"aria-label":`Diff of ${n.path}`,className:`fixed inset-0 z-40 flex min-w-0 flex-col bg-bg safe-pt safe-px`,onKeyDown:e=>{e.key===`Escape`&&!l&&(e.preventDefault(),o())},children:[(0,K.jsxs)(`header`,{className:`flex min-w-0 shrink-0 items-center gap-1 border-b border-border bg-surface px-2 py-1.5`,children:[(0,K.jsx)(W,{ref:f,label:`Back to changed files`,icon:(0,K.jsx)(oe,{className:`size-4`}),onClick:o}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`truncate font-mono text-xs`,title:n.path,children:n.path}),(0,K.jsxs)(`div`,{className:`text-xs text-muted`,children:[`File `,r+1,` of `,i,` · +`,n.added,` -`,n.deleted,p>0&&` · ${p} comment${p===1?``:`s`}`]})]}),(0,K.jsx)(W,{label:`Previous file`,icon:(0,K.jsx)(R,{className:`size-4`}),disabled:r===0,onClick:s}),(0,K.jsx)(W,{label:`Next file`,icon:(0,K.jsx)(z,{className:`size-4`}),disabled:r>=i-1,onClick:c})]}),(0,K.jsxs)(`div`,{className:`min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain px-2 py-2 safe-pb`,children:[(0,K.jsx)(`p`,{className:`mb-2 text-xs text-muted`,children:`Tap a line to add a review comment.`}),(0,K.jsx)(qn,{ctx:e,diff:t,path:n.path,comments:a,onComment:u})]}),(0,K.jsx)(Jn,{draft:l,mobile:!0,onClose:()=>u(null),onSave:d})]})}function nr(e){if(!e||typeof e!=`object`)return!1;let t=e;return t.type===`action`&&typeof t.actionId==`string`||t.type===`resize`&&typeof t.height==`number`}function rr({hostId:e,adapterId:t,node:n,state:r,onAction:i,title:a,className:o,minHeight:s=80,maxHeight:c=1200}){let l=(0,G.useRef)(null),[u,d]=(0,G.useState)(s),[f,p]=(0,G.useState)(!1),m=(0,G.useRef)(i);m.current=i,(0,G.useEffect)(()=>{let e=e=>{e.source===l.current?.contentWindow&&nr(e.data)&&(e.data.type===`resize`?d(Math.min(c,Math.max(s,Math.ceil(e.data.height)))):m.current?.(e.data.actionId,e.data.payload))};return window.addEventListener(`message`,e),()=>window.removeEventListener(`message`,e)},[s,c]),(0,G.useEffect)(()=>{f&&l.current?.contentWindow?.postMessage({type:`render`,node:n,state:r},`*`)},[f,n,r]);let h=`/adapter-frames/${encodeURIComponent(e)}/${encodeURIComponent(t)}`;return(0,K.jsx)(`iframe`,{ref:l,title:a,src:h,sandbox:`allow-scripts`,referrerPolicy:`no-referrer`,loading:`lazy`,onLoad:()=>p(!0),style:{height:u},className:D(`block w-full rounded-md border border-border bg-surface`,o)})}function ir({ctx:e,className:t}){if(e.control===`none`)return null;let n=e.control===`automation`;return(0,K.jsx)(H,{kind:`custom`,size:`sm`,className:t,status:{label:cn[e.control],icon:n?Je:ve,tone:n?`info`:`neutral`}})}function ar({ctx:e}){return(0,K.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-xs text-muted`,children:[(0,K.jsx)(ce,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate`,children:e.hostName}),e.link!==`connected`&&(0,K.jsx)(H,{kind:`host`,value:e.link,size:`sm`,className:`ml-1`})]})}function or(e,t){return[{id:`rename`,label:`Rename`,icon:(0,K.jsx)(_e,{className:`size-4`}),onSelect:t.openRename,disabled:e.session.readOnly},{id:`archive`,label:`Archive`,icon:(0,K.jsx)(Ke,{className:`size-4`}),onSelect:t.requestArchive,disabled:!!t.archiveBlocked,hint:t.archiveBlocked??void 0},{id:`info`,label:`Native session information`,icon:(0,K.jsx)(De,{className:`size-4`}),onSelect:t.openInfo}]}function sr({ctx:e,actions:t,inspector:n}){let{session:i,project:a,workspace:o,task:s}=e;return(0,K.jsxs)(`header`,{className:`flex min-w-0 shrink-0 flex-col gap-1.5 border-b border-border bg-surface px-4 py-2.5`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-2`,children:[(0,K.jsx)(`h1`,{className:`min-w-0 flex-1 truncate text-base font-semibold`,title:i.title,children:i.title}),s&&(0,K.jsxs)(r,{to:`/tasks/${encodeURIComponent(s.id)}`,className:w(`ghost`,`sm`),title:`Open linked task: ${s.title}`,children:[(0,K.jsx)(Pe,{"aria-hidden":!0,className:`size-4`}),(0,K.jsx)(`span`,{className:`hidden xl:inline`,children:`Open linked task`}),(0,K.jsx)(`span`,{className:`xl:hidden`,children:`Task`})]}),t.canTakeover&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(ve,{className:`size-3.5`}),busy:t.busy.takeover,onClick:t.takeover,children:`Take over`}),t.canReturn&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(Je,{className:`size-3.5`}),busy:t.busy.ret,onClick:t.returnToAutomation,children:`Return to automation`}),t.canResume&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(be,{className:`size-3.5`}),busy:t.busy.resume,onClick:t.resume,children:`Resume`}),t.canStop&&(0,K.jsx)(j,{size:`sm`,variant:`danger`,icon:(0,K.jsx)(Oe,{className:`size-3.5`}),busy:t.busy.stop,onClick:t.requestStop,children:`Stop`}),(0,K.jsx)(ae,{label:`Session menu`,items:or(e,t),trigger:e=>(0,K.jsx)(W,{...e,label:`Session menu`,icon:(0,K.jsx)(ot,{className:`size-4`})})}),(0,K.jsx)(W,{label:n.label,"aria-expanded":n.open,icon:n.open?(0,K.jsx)(Ot,{className:`size-4`}):(0,K.jsx)(re,{className:`size-4`}),onClick:n.toggle})]}),(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-x-3 gap-y-1`,children:[(0,K.jsx)(H,{kind:`runtime`,value:i.runtime,size:`sm`}),(0,K.jsx)(ir,{ctx:e}),(0,K.jsxs)(`span`,{className:`inline-flex min-w-0 items-center gap-1 text-xs text-muted`,children:[(0,K.jsx)(`span`,{className:`truncate`,children:a?.name??`No project`}),(0,K.jsx)(ge,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),(0,K.jsx)(`span`,{className:`truncate font-mono`,children:nn(o,i.cwd)})]}),(0,K.jsx)(ar,{ctx:e}),i.readOnly&&(0,K.jsx)(`span`,{className:D(`text-xs text-muted`),children:`Subagent: view only. Live control is not supported.`})]})]})}function Z({title:e,children:t,className:n}){return(0,K.jsxs)(`section`,{"aria-label":e,className:D(`flex min-w-0 flex-col gap-2`,n),children:[(0,K.jsx)(`h3`,{className:`text-sm font-semibold`,children:e}),t]})}function cr({ctx:e,actions:t}){let n=e.control!==`none`;return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(ir,{ctx:e}),!n&&(0,K.jsx)(`span`,{className:`text-sm text-muted`,children:`Manual session: no automation run controls it.`})]}),(0,K.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,K.jsx)(j,{icon:(0,K.jsx)(ve,{className:`size-4`}),disabled:!t.canTakeover,busy:t.busy.takeover,onClick:t.takeover,children:`Take over`}),(0,K.jsx)(j,{icon:(0,K.jsx)(Je,{className:`size-4`}),disabled:!t.canReturn,busy:t.busy.ret,onClick:t.returnToAutomation,children:`Return to automation`}),(0,K.jsx)(j,{variant:`danger`,icon:(0,K.jsx)(Oe,{className:`size-4`}),disabled:!t.canStop,busy:t.busy.stop,onClick:t.requestStop,children:`Stop`})]}),(0,K.jsxs)(`p`,{className:`text-xs text-muted`,children:[n?e.control===`automation`?`Taking over pauses automatic continuations; Pi keeps running.`:`You have control; returning lets automation continue.`:`Take over and Return to automation apply to sessions run by a task.`,` `,!t.canStop&&(e.link===`connected`?`Stop is available while Pi is running.`:`Stop needs the host to be online.`)]})]})}function lr({run:e}){return(0,K.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-0.5 rounded-md border border-border px-2 py-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,K.jsxs)(`span`,{className:`text-sm font-medium`,children:[`Attempt `,e.attempt]}),(0,K.jsx)(H,{kind:`run`,value:e.state,size:`sm`}),(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:e.startedAt?M(e.startedAt):M(e.createdAt)})]}),e.outcome&&(0,K.jsx)(`p`,{className:`text-xs break-words text-muted`,children:e.outcome.summary}),(0,K.jsxs)(`p`,{className:`text-xs text-muted`,children:[e.usage.accounting===`available`?[e.usage.tokens===null?null:`${e.usage.tokens.toLocaleString()} tokens`,e.usage.costUsd===null?null:`$${e.usage.costUsd.toFixed(2)}`].filter(Boolean).join(` · `)||`No usage reported`:e.usage.note??`Token/cost accounting not reported`,e.continuationsUsed>0&&` · ${e.continuationsUsed} continuations`]})]})}function ur({task:e,run:t}){let n=t?.limits??e.policy.continuation;return(0,K.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Continuation`}),(0,K.jsx)(`dd`,{children:n.enabled?`Enabled`:`Off: stops after one turn`}),n.enabled&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Continuations`}),(0,K.jsxs)(`dd`,{children:[t?`${t.continuationsUsed} of `:`up to `,n.maxContinuations]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Time limit`}),(0,K.jsxs)(`dd`,{children:[n.maxElapsedMinutes,` min`]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Token limit`}),(0,K.jsx)(`dd`,{children:n.maxTokens?.toLocaleString()??`None`}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Cost limit`}),(0,K.jsx)(`dd`,{children:n.maxCostUsd===null?`None`:`$${n.maxCostUsd}`})]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Checks`}),(0,K.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.policy.completion.checks===null?`Project checks`:e.policy.completion.checks.length?e.policy.completion.checks.join(`, `):`None`}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Human review`}),(0,K.jsx)(`dd`,{children:e.policy.completion.requireHumanReview?`Required`:`Not required`})]})}function dr({ctx:e,actions:t,showControls:n=!0}){let{task:i,run:a}=e,o=k(i?.id),s=_(e=>e.tasks);return i?(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,K.jsx)(`h3`,{className:`min-w-0 flex-1 text-sm font-semibold break-words`,children:i.title}),(0,K.jsx)(H,{kind:`task`,value:i.state,size:`sm`})]}),i.blocked&&(0,K.jsxs)(`p`,{className:`text-sm text-warning`,children:[`Blocked: `,i.blocked.reason]}),(0,K.jsxs)(r,{to:`/tasks/${encodeURIComponent(i.id)}`,className:w(`secondary`,`sm`,`self-start`),children:[(0,K.jsx)(Pe,{"aria-hidden":!0,className:`size-4`}),`Open task`]})]}),(0,K.jsx)(Z,{title:`Objective`,children:i.objective?(0,K.jsx)(Be,{text:i.objective}):(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No objective written.`})}),(0,K.jsx)(Z,{title:`Acceptance criteria`,children:i.acceptanceCriteria.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`None.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.acceptanceCriteria.map(e=>(0,K.jsxs)(`li`,{className:`flex items-start gap-2 text-sm`,children:[(0,K.jsx)(Ee,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-muted`}),(0,K.jsx)(`span`,{className:`min-w-0 break-words`,children:e})]},e))})}),(0,K.jsx)(Z,{title:`Dependencies`,children:i.dependencies.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`None.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1`,children:i.dependencies.map(e=>{let t=s[e];return(0,K.jsxs)(`li`,{className:`flex min-w-0 items-center gap-2 text-sm`,children:[t?(0,K.jsx)(H,{kind:`task`,value:t.state,size:`sm`}):null,(0,K.jsx)(r,{to:`/tasks/${encodeURIComponent(e)}`,className:`min-w-0 truncate text-accent underline underline-offset-2`,children:t?.title??e})]},e)})})}),(0,K.jsx)(Z,{title:`Limits`,children:(0,K.jsx)(ur,{task:i,run:a})}),n&&(0,K.jsx)(Z,{title:`Control`,children:(0,K.jsx)(cr,{ctx:e,actions:t})}),(0,K.jsx)(Z,{title:`Run history`,children:o.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No runs yet.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:o.map(e=>(0,K.jsx)(lr,{run:e},e.id))})})]}):(0,K.jsx)(I,{icon:(0,K.jsx)(Pe,{className:`size-8`}),title:`No linked task`,description:`This session was started directly. Tasks are optional; create one on the Board to automate work.`,action:{label:`Open Board`,to:`/board`},className:`py-6`})}var fr={active:{label:`Active`,tone:`success`},disabled:{label:`Disabled`,tone:`neutral`},error:{label:`Error`,tone:`danger`}};function pr({a:e}){let t=fr[e.status];return(0,K.jsxs)(`li`,{className:`flex min-w-0 flex-col gap-0.5 rounded-md border border-border px-2 py-1.5`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-2`,children:[(0,K.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm`,children:e.id}),(0,K.jsxs)(`span`,{className:`text-xs text-muted`,children:[`v`,e.version]}),(0,K.jsxs)(`span`,{className:`rounded-full border border-border px-1.5 text-xs text-muted`,children:[`Tier: `,e.tier]}),(0,K.jsx)(H,{kind:`custom`,size:`sm`,status:{label:t.label,tone:t.tone,icon:e.status===`active`?Ee:Oe}})]}),(0,K.jsxs)(`p`,{className:`text-xs break-words text-muted`,children:[`For `,e.target.extension,` `,e.target.versionRange,e.target.testedVersions.length>0&&` (tested ${e.target.testedVersions.join(`, `)})`]}),e.capabilities.length>0&&(0,K.jsxs)(`p`,{className:`text-xs text-muted`,children:[`Provides: `,e.capabilities.join(`, `)]}),e.detail&&(0,K.jsx)(`p`,{className:`text-xs break-words text-warning`,children:e.detail})]})}function mr({ctx:e,panel:t}){let{mobile:n,openFile:r}=Gt(),i=(n,r)=>{X.adapterAction(e.session.id,t.adapterId,n,r).then(()=>V.success(`Action sent`)).catch(e=>V.error(b(e)))},a;return a=t.webRenderer&&!n&&e.host?(0,K.jsx)(rr,{hostId:e.session.hostId,adapterId:t.adapterId,node:t.node,title:t.title,onAction:i}):t.node?(0,K.jsxs)(K.Fragment,{children:[t.webRenderer&&n&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Showing the portable version; this panel's custom renderer is desktop-only.`}),(0,K.jsx)(pe,{node:t.node,onAction:e=>i(e),onOpenFile:r})]}):(0,K.jsx)(C,{capability:`This panel`,reason:`It only has a custom web renderer, which is desktop-only and is not shown on mobile.`,fallback:(0,K.jsx)(`p`,{className:`text-sm`,children:t.mobileFallback??`The adapter provides no mobile fallback text.`})}),(0,K.jsxs)(`article`,{className:`flex min-w-0 flex-col gap-2 rounded-md border border-border p-2`,children:[(0,K.jsxs)(`header`,{className:`flex min-w-0 items-baseline gap-2`,children:[(0,K.jsx)(`h4`,{className:`min-w-0 flex-1 truncate text-sm font-medium`,children:t.title}),(0,K.jsx)(`span`,{className:`shrink-0 font-mono text-xs text-subtle`,children:t.adapterId})]}),a]})}function hr({ctx:e}){let t=g(e.session.id),n=_(e=>e.diagnostics),i=(0,G.useMemo)(()=>new Set(e.adapters.map(e=>e.id)),[e.adapters]),a=(0,G.useMemo)(()=>n.filter(t=>t.sessionId===e.session.id||t.sessionId===null&&t.adapterId!==null&&i.has(t.adapterId)).slice(-20).reverse(),[n,e.session.id,i]),o=e.host?.capabilities;return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[(0,K.jsx)(Z,{title:`Panels`,children:t.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No extension panels for this session.`}):t.map(t=>(0,K.jsx)(mr,{ctx:e,panel:t},`${t.adapterId}:${t.slot}`))}),(0,K.jsx)(Z,{title:`Adapters on ${e.hostName}`,children:e.adapters.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No adapters reported by this host.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1.5`,children:e.adapters.map(e=>(0,K.jsx)(pr,{a:e},e.id))})}),(o?.unsupported.length||e.host?.piCompatible===!1)&&(0,K.jsxs)(Z,{title:`Runtime limitations`,children:[e.host?.piCompatible===!1&&(0,K.jsx)(C,{capability:`This Pi version`,reason:`Pi ${e.host.piVersion??`(not found)`} on ${e.hostName} is outside the tested range.`}),o?.unsupported.map(e=>(0,K.jsx)(C,{capability:e.capability,reason:e.reason},e.capability))]}),(0,K.jsxs)(Z,{title:`Diagnostics`,children:[a.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No diagnostics.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1`,children:a.map((e,t)=>(0,K.jsxs)(`li`,{className:`min-w-0 rounded-md bg-surface-2 px-2 py-1 text-xs`,children:[(0,K.jsx)(`span`,{className:D(`font-medium`,e.level===`error`&&`text-danger`,e.level===`warning`&&`text-warning`),children:e.level===`error`?`Error`:e.level===`warning`?`Warning`:`Info`}),` `,e.adapterId&&(0,K.jsxs)(`span`,{className:`font-mono`,children:[e.adapterId,`: `]}),(0,K.jsx)(`span`,{className:`break-words`,children:e.message}),` `,(0,K.jsx)(`span`,{className:`text-subtle`,children:F(e.at)})]},`${e.at}-${t}`))}),(0,K.jsx)(r,{to:`/settings/diagnostics`,className:`text-sm text-accent underline`,children:`All diagnostics`})]})]})}function gr({ctx:e,actions:t}){let{session:n,workspace:i,host:a}=e,o=p(n.id).items.filter(e=>e.kind===`subagent`);return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-5 px-3 py-3`,children:[(0,K.jsx)(Z,{title:`Automation and control`,children:(0,K.jsx)(cr,{ctx:e,actions:t})}),(0,K.jsx)(Z,{title:`Task`,children:(0,K.jsx)(dr,{ctx:e,actions:t,showControls:!1})}),(0,K.jsxs)(Z,{title:`Host and workspace`,children:[e.link!==`connected`&&(0,K.jsx)(O,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:a?.lastSeenAt}),(0,K.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 text-sm`,children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Host`}),(0,K.jsxs)(`dd`,{className:`min-w-0 break-words`,children:[e.hostName,a?.piVersion&&` · Pi ${a.piVersion}`]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Branch`}),(0,K.jsxs)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:[nn(i,n.cwd),i?.baseBranch&&` (from ${i.baseBranch})`]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Path`}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:i?.path??n.cwd}),i&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Git`}),(0,K.jsxs)(`dd`,{children:[i.git.dirty?`${i.git.changedFiles} changed files`:`Clean`,i.git.ahead>0&&` · ${i.git.ahead} ahead`,i.git.behind>0&&` · ${i.git.behind} behind`]})]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Profile`}),(0,K.jsxs)(`dd`,{className:`min-w-0 break-words`,children:[n.profileSnapshot.name,n.profileSnapshot.model&&` · ${n.profileSnapshot.model}`,n.profileSnapshot.thinking&&` · effort ${n.profileSnapshot.thinking}`]})]})]}),(0,K.jsx)(Z,{title:`Subagents`,children:o.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`No subagents in the loaded transcript.`}):(0,K.jsx)(`ul`,{className:`flex flex-col gap-1`,children:o.map(e=>e.kind===`subagent`?(0,K.jsxs)(`li`,{className:`flex min-w-0 flex-wrap items-center gap-2 text-sm`,children:[(0,K.jsx)(`span`,{className:`min-w-0 truncate`,children:e.data.label}),(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:e.data.status}),e.data.linkedSessionId&&(0,K.jsx)(r,{to:`/code/${encodeURIComponent(e.data.linkedSessionId)}`,className:`text-accent underline`,children:`Open (view only)`})]},e.id):null)})}),(0,K.jsx)(Z,{title:`Extensions`,children:(0,K.jsx)(hr,{ctx:e})})]})}function _r(e){let t=e.split(`/`).filter(Boolean);return t.pop(),t.join(`/`)}function vr(e){return/\.([A-Za-z0-9]+)$/.exec(e)?.[1]}function yr({ctx:e,openPath:t}){let n=e.workspace,[r,i]=(0,G.useState)(``),[a,o]=(0,G.useState)(null),[s,c]=(0,G.useState)(null),[l,u]=(0,G.useState)(null),[d,f]=(0,G.useState)(null),[p,m]=(0,G.useState)(!1),[h,g]=(0,G.useState)(0),_=e.link===`connected`;if((0,G.useEffect)(()=>{if(!t||!n)return;let e=t.path.startsWith(`${n.path}/`)?t.path.slice(n.path.length+1):t.path.replace(/^\.\//,``);o(e),i(_r(e))},[t,n]),(0,G.useEffect)(()=>{if(!n||!_)return;let e=new AbortController;return m(!0),f(null),(a?X.file(n.id,a,e.signal).then(e=>u(e)):X.files(n.id,r,e.signal).then(e=>c(e))).catch(t=>{e.signal.aborted||f(t)}).finally(()=>{e.signal.aborted||m(!1)}),()=>e.abort()},[n?.id,_,r,a,h]),!n)return(0,K.jsx)(C,{capability:`File browsing`,reason:`This session is not linked to a Switchyard workspace (it runs in ${e.session.cwd}).`});if(!_)return(0,K.jsx)(O,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.host?.lastSeenAt,detail:`Files are read from the host; browsing resumes when it reconnects.`});let v=r.split(`/`).filter(Boolean);return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,K.jsxs)(`nav`,{"aria-label":`Folder`,className:`flex min-w-0 flex-wrap items-center gap-1 text-xs`,children:[(0,K.jsx)(`button`,{type:`button`,className:`tap rounded px-1 font-mono text-accent hover:underline`,onClick:()=>{o(null),i(``)},children:n.branch??`root`}),v.map((e,t)=>{let n=v.slice(0,t+1).join(`/`);return(0,K.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`text-subtle`,children:`/`}),(0,K.jsx)(`button`,{type:`button`,className:`tap rounded px-1 font-mono text-accent hover:underline`,onClick:()=>{o(null),i(n)},children:e})]},n)}),a&&(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1`,children:[(0,K.jsx)(`span`,{"aria-hidden":!0,className:`text-subtle`,children:`/`}),(0,K.jsx)(`span`,{className:`truncate font-mono`,children:a.split(`/`).pop()})]})]}),(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Read-only in this version.`}),d===null?p?(0,K.jsx)(P,{label:a?`Loading file…`:`Loading folder…`}):a?(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(0,K.jsx)(j,{size:`sm`,variant:`ghost`,className:`self-start`,icon:(0,K.jsx)(oe,{className:`size-3.5`}),onClick:()=>o(null),children:`Back to folder`}),l?l.binary||l.text===null?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`Binary file not shown.`}):(0,K.jsxs)(K.Fragment,{children:[l.truncated&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Showing the beginning of a large file.`}),(0,K.jsx)(Re,{text:l.text,lang:vr(a),maxHeight:`70vh`})]}):null]}):s&&s.length===0?(0,K.jsx)(I,{title:`Empty folder`,className:`py-6`}):(0,K.jsxs)(`ul`,{"aria-label":`Folder contents`,className:`flex min-w-0 flex-col`,children:[r&&(0,K.jsx)(`li`,{children:(0,K.jsxs)(`button`,{type:`button`,className:`tap flex w-full items-center gap-2 rounded px-2 py-1.5 text-left text-sm hover:bg-surface-2`,onClick:()=>i(_r(r)),children:[(0,K.jsx)(ft,{"aria-hidden":!0,className:`size-4 text-muted`}),`..`]})}),(s??[]).map(e=>{let t=e.kind===`dir`?mt:e.kind===`symlink`?ye:ut,a=e.path?e.path.startsWith(`${n.path}/`)?e.path.slice(n.path.length+1):e.path:r?`${r}/${e.name}`:e.name;return(0,K.jsx)(`li`,{className:`min-w-0`,children:(0,K.jsxs)(`button`,{type:`button`,className:`tap flex w-full min-w-0 items-center gap-2 rounded px-2 py-1.5 text-left text-sm hover:bg-surface-2`,onClick:()=>e.kind===`dir`?i(a):o(a),children:[(0,K.jsx)(t,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate font-mono text-xs`,children:e.name}),(0,K.jsx)(`span`,{className:`sr-only`,children:e.kind===`dir`?`folder`:`file`}),e.size!==null&&e.kind===`file`&&(0,K.jsx)(`span`,{className:`shrink-0 text-xs text-subtle tabular-nums`,children:e.size<1024?`${e.size} B`:`${Math.round(e.size/1024)} KB`})]})},a)})]}):(0,K.jsx)(N,{compact:!0,title:a?`Could not read this file`:`Could not list this folder`,error:d,onRetry:()=>g(e=>e+1)})]})}function br({ctx:e,actions:t,tab:n,onTab:r,openPath:i,className:a,hideTitle:o}){let s=(0,G.useId)(),c=g(e.session.id),l=e.workspace?.git.changedFiles??0;return(0,K.jsxs)(`aside`,{"data-testid":`inspector`,"aria-label":`Inspector`,className:D(`flex min-h-0 min-w-0 flex-col bg-surface`,a),children:[!o&&(0,K.jsx)(`h2`,{className:`sr-only`,children:`Inspector`}),(0,K.jsx)(Le,{idPrefix:s,label:`Inspector`,value:n,onChange:e=>r(e),className:`shrink-0 px-2`,scrollable:!0,tabs:[{id:`changes`,label:`Changes`,badge:(0,K.jsx)(je,{count:l,label:`changed files`,tone:`neutral`})},{id:`files`,label:`Files`},{id:`task`,label:`Task`},{id:`extensions`,label:`Extensions`,badge:(0,K.jsx)(je,{count:c.length,label:`panels`,tone:`neutral`})}]}),(0,K.jsxs)(ze,{idPrefix:s,id:n,className:`relative min-h-0 min-w-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain p-3`,children:[n===`changes`&&(0,K.jsx)($n,{ctx:e}),n===`files`&&(0,K.jsx)(yr,{ctx:e,openPath:i}),n===`task`&&(0,K.jsx)(dr,{ctx:e,actions:t}),n===`extensions`&&(0,K.jsx)(hr,{ctx:e})]})]})}var xr={filter:`active`,query:``,collapsed:[]};function Sr({selectedId:e,onNewSession:t,variant:n,className:r,style:i}){let a=n===`screen`,[o,s]=Ne(a?`sessionList`:`navigator`,xr),c={...xr,...o},l=_(e=>e.hydrated),f=_(e=>e.projects),p=_(e=>e.workspaces),m=_(e=>e.sessions),h=_(e=>e.hosts),g=_(e=>e.attention),v=_(e=>e.interactions),y=d(),b=u(),x=(0,G.useMemo)(()=>rn({projects:f,workspaces:p,sessions:m,hosts:h,attention:g,interactions:v},{filter:c.filter,query:c.query}),[f,p,m,h,g,v,c.filter,c.query]),S=new Set(c.collapsed),C=e=>{let t=new Set(S);t.has(e)?t.delete(e):t.add(e),s({...c,collapsed:[...t]})},w=x.flatMap(e=>[e.key,...e.workspaces.map(e=>e.key)]),T=w.some(e=>!S.has(e)),E=a?[{value:`active`,label:`Active`},{value:`attention`,label:`Needs input`},{value:`all`,label:`All`}]:[{value:`active`,label:`Active`},{value:`all`,label:`All`}],O;return O=l?y.length===0?(0,K.jsx)(I,{icon:(0,K.jsx)(ce,{className:`size-8`}),title:`Connect a host`,description:`Sessions run on a host: a computer with Pi and the Switchyard host agent.`,action:{label:`Connect a host`,to:`/settings/hosts`},secondaryAction:b.length===0?{label:`Add a project`,to:`/settings/projects`}:void 0}):b.length===0?(0,K.jsx)(I,{icon:(0,K.jsx)(le,{className:`size-8`}),title:`Add a project`,description:`Point Switchyard at a Git checkout on one of your hosts to start sessions there.`,action:{label:`Add a project`,to:`/settings/projects`}}):x.length===0||x.every(e=>e.workspaces.length===0)?c.query?(0,K.jsx)(I,{icon:(0,K.jsx)(Se,{className:`size-8`}),title:`No matches`,description:`Nothing matches "${c.query}".`,action:{label:`Clear search`,onClick:()=>s({...c,query:``})}}):(0,K.jsx)(I,{title:c.filter===`attention`?`Nothing needs your input`:c.filter===`active`?`No active sessions`:`No sessions yet`,description:`Start a session in one of your projects; a task is not required.`,action:{label:`New session`,onClick:t},secondaryAction:c.filter===`all`?void 0:{label:`Show all`,onClick:()=>s({...c,filter:`all`})}}):(0,K.jsx)(`ul`,{"aria-label":`Projects`,className:`flex min-w-0 flex-col gap-1 pb-4`,children:x.map(t=>(0,K.jsx)(Cr,{group:t,collapsed:S,toggle:C,selectedId:e,screen:a},t.key))}):(0,K.jsx)(P,{label:`Loading sessions…`}),(0,K.jsxs)(`nav`,{"data-testid":`navigator`,"aria-label":`Sessions`,style:i,className:D(`flex min-h-0 min-w-0 flex-col bg-surface`,r),children:[(0,K.jsxs)(`div`,{className:`flex shrink-0 flex-col gap-2 border-b border-border px-3 pt-3 pb-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,K.jsx)(`h2`,{className:D(`min-w-0 flex-1 font-semibold`,a?`text-lg`:`text-sm`),children:`Sessions`}),(0,K.jsx)(j,{"data-testid":`new-session`,size:`sm`,variant:`primary`,icon:(0,K.jsx)(xe,{className:`size-4`}),onClick:t,disabled:!l||y.length===0||b.length===0,title:y.length===0?`Connect a host first`:b.length===0?`Add a project first`:void 0,children:`New session`})]}),(0,K.jsxs)(`div`,{className:`relative`,children:[(0,K.jsx)(Se,{"aria-hidden":!0,className:`pointer-events-none absolute top-1/2 left-2.5 size-4 -translate-y-1/2 text-subtle`}),(0,K.jsx)(Fe,{type:`search`,"aria-label":`Search sessions`,placeholder:`Search sessions, branches`,value:c.query,onChange:e=>s({...c,query:e.target.value}),className:`pl-8`})]}),(0,K.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1`,children:[(0,K.jsx)(Ve,{label:`Session filter`,options:E,value:c.filter,onChange:e=>s({...c,filter:e}),className:`min-w-0 flex-1`,block:!0}),(0,K.jsx)(W,{label:T?`Collapse all`:`Expand all`,icon:T?(0,K.jsx)(nt,{className:`size-4`}):(0,K.jsx)(it,{className:`size-4`}),onClick:()=>s({...c,collapsed:T?w:[]})})]})]}),(0,K.jsx)(`div`,{className:`relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-2 pt-2`,children:O})]})}function Cr({group:e,collapsed:t,toggle:n,selectedId:r,screen:i}){let a=!t.has(e.key);return(0,K.jsxs)(`li`,{className:`min-w-0`,children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>n(e.key),className:`tap flex w-full min-w-0 items-center gap-1.5 rounded-md px-1.5 py-1.5 text-left text-sm font-semibold hover:bg-surface-2`,children:[(0,K.jsx)(a?ie:z,{"aria-hidden":!0,className:`size-4 shrink-0 text-muted`}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate`,children:e.label}),(0,K.jsxs)(`span`,{className:`shrink-0 text-xs font-normal text-muted`,children:[e.sessionCount,(0,K.jsx)(`span`,{className:`sr-only`,children:` sessions`})]})]}),a&&(0,K.jsxs)(`ul`,{className:`flex min-w-0 flex-col`,children:[e.workspaces.length===0&&(0,K.jsx)(`li`,{className:`px-7 py-1 text-xs text-muted`,children:`No workspaces discovered yet.`}),e.workspaces.map(e=>{let a=!t.has(e.key);return(0,K.jsxs)(`li`,{className:`min-w-0`,children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":a,onClick:()=>n(e.key),className:`tap flex w-full min-w-0 items-center gap-1.5 rounded-md py-1 pr-1.5 pl-4 text-left hover:bg-surface-2`,children:[(0,K.jsx)(a?ie:z,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,K.jsx)(ge,{"aria-hidden":!0,className:`size-3.5 shrink-0 text-muted`}),(0,K.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`span`,{className:`block truncate font-mono text-xs`,title:e.workspace?.path,children:e.label}),e.hostName&&(0,K.jsx)(`span`,{className:`block truncate text-xs text-muted`,children:e.hostName})]})]}),a&&e.sessions.length>0&&(0,K.jsx)(`ul`,{className:`flex min-w-0 flex-col gap-0.5 py-0.5`,children:e.sessions.map(e=>(0,K.jsx)(wr,{row:e,selected:e.session.id===r,screen:i},e.session.id))})]},e.key)})]})]})}function wr({row:e,selected:t,screen:n}){let{session:i,attention:a}=e;return(0,K.jsx)(`li`,{className:`min-w-0`,children:(0,K.jsxs)(r,{"data-testid":`session-row`,to:`/code/${encodeURIComponent(i.id)}`,"aria-current":t?`page`:void 0,className:D(`tap flex min-w-0 flex-col gap-0.5 rounded-md py-1.5 pr-2 pl-9 hover:bg-surface-2`,n&&`py-2.5`,t&&`bg-accent-soft hover:bg-accent-soft`),children:[(0,K.jsxs)(`span`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,K.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm`,children:i.title}),a&&(0,K.jsxs)(`span`,{className:`inline-flex shrink-0 items-center gap-0.5 text-xs font-medium text-warning`,children:[(0,K.jsx)(ee,{"aria-hidden":!0,className:`size-3.5`}),`Needs you`]})]}),(0,K.jsxs)(`span`,{className:`flex min-w-0 flex-wrap items-center gap-x-1.5 gap-y-0.5`,children:[(0,K.jsx)(H,{kind:`runtime`,value:i.runtime,size:`sm`}),i.provenance===`subagent`&&(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:`Subagent`}),(0,K.jsx)(`span`,{className:`truncate text-xs text-muted`,children:F(i.lastActivityAt)})]})]})})}var Tr=`tap block h-9 w-full rounded-md border border-border bg-surface px-2 text-base text-text md:text-sm focus:border-accent focus:outline-none disabled:opacity-55`;function Er({label:e,htmlFor:t,hint:n,children:r}){return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-1`,children:[(0,K.jsx)(`label`,{htmlFor:t,className:`text-sm font-medium`,children:e}),r,n&&(0,K.jsx)(`div`,{className:`text-xs text-muted`,children:n})]})}function Q(e){return!!e&&!e.revokedAt&&e.connectivity===`connected`}function Dr(e){let t=u(),n=_(e=>e.workspaces),r=_(e=>e.checkouts),i=_(e=>e.profiles),a=_(e=>e.hosts),o=U(e=>e.selectedProjectId),s=(0,G.useMemo)(()=>Object.values(i).sort((e,t)=>e.name.localeCompare(t.name)),[i]),[c,l]=(0,G.useState)(``),[d,f]=(0,G.useState)(`new`),[p,m]=(0,G.useState)(``),[h,g]=(0,G.useState)(``),[v,y]=(0,G.useState)(``),[b,x]=(0,G.useState)(``),[S,C]=(0,G.useState)(``),[w,T]=(0,G.useState)(``);(0,G.useEffect)(()=>{if(!e)return;let n=t.find(e=>e.id===o)??t[0]??null;l(n?.id??``)},[e]);let E=t.find(e=>e.id===c),D=(0,G.useMemo)(()=>Object.values(n).filter(e=>e.projectId===c&&!e.archivedAt).sort((e,t)=>(e.provenance===`main`?0:1)-(t.provenance===`main`?0:1)||(e.branch??``).localeCompare(t.branch??``)),[n,c]),O=(0,G.useMemo)(()=>Object.values(r).filter(e=>e.projectId===c),[r,c]);(0,G.useEffect)(()=>{if(!E)return;let e=O.find(e=>e.hostId===E.defaultHostId&&Q(a[e.hostId]))??O.find(e=>Q(a[e.hostId]))??O[0];g(e?.id??``);let t=D.find(e=>Q(a[e.hostId]))??D[0];m(t?.id??``),C(E.defaultProfileId??s[0]?.id??``),x(``)},[c]);let k=n[p],A=r[h],j=d===`existing`?k?.hostId:A?.hostId,M=j?a[j]:void 0,N=[];if(E||N.push(`Select a project.`),d===`existing`&&!k&&N.push(`Select a workspace.`),d===`new`){A||N.push(`Select a host checkout.`);let e=$t(v);e&&N.push(e)}return M&&!Q(M)&&N.push(`Host ${M.name} is offline.`),M&&!M.piCompatible&&N.push(`Pi ${M.piVersion??`(not found)`} on ${M.name} is outside the tested range.`),{projects:t,profiles:s,hosts:a,projectWorkspaces:D,projectCheckouts:O,project:E,workspace:k,checkout:A,host:M,preview:d===`existing`?k?{branch:nn(k),path:k.path}:null:A&&v.trim()?{branch:v.trim(),path:Qt(A.path,v,E?.worktreeDir)}:null,problems:N,values:{projectId:c,mode:d,workspaceId:p,checkoutId:h,branch:v,base:b,profileId:S,prompt:w},set:{projectId:l,mode:f,workspaceId:m,checkoutId:g,branch:y,base:x,profileId:C,prompt:T},reset:()=>{y(``),x(``),T(``)}}}function Or({form:e,id:t}){return(0,K.jsx)(Er,{label:`Project`,htmlFor:`${t}-project`,children:(0,K.jsx)(`select`,{id:`${t}-project`,className:Tr,value:e.values.projectId,onChange:t=>e.set.projectId(t.target.value),children:e.projects.map(e=>(0,K.jsx)(`option`,{value:e.id,children:e.name},e.id))})})}function kr({form:e,id:t}){let{values:n,set:r,hosts:i}=e;return(0,K.jsxs)(`fieldset`,{className:`flex min-w-0 flex-col gap-3`,children:[(0,K.jsx)(`legend`,{className:`mb-1 text-sm font-medium`,children:`Workspace`}),(0,K.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`${t}-wsmode`,checked:n.mode===`new`,onChange:()=>r.mode(`new`),className:`size-4`}),`Create a new worktree`]}),(0,K.jsxs)(`label`,{className:`flex items-center gap-2 text-sm`,children:[(0,K.jsx)(`input`,{type:`radio`,name:`${t}-wsmode`,checked:n.mode===`existing`,onChange:()=>r.mode(`existing`),disabled:e.projectWorkspaces.length===0,className:`size-4`}),`Use an existing workspace`,e.projectWorkspaces.length===0&&(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:`(none discovered)`})]})]}),n.mode===`existing`?(0,K.jsx)(Er,{label:`Existing workspace`,htmlFor:`${t}-ws`,hint:e.host?`Runs on ${e.host.name}`:void 0,children:(0,K.jsx)(`select`,{id:`${t}-ws`,className:Tr,value:n.workspaceId,onChange:e=>r.workspaceId(e.target.value),children:e.projectWorkspaces.map(e=>{let t=i[e.hostId];return(0,K.jsxs)(`option`,{value:e.id,disabled:!Q(t),children:[nn(e),` on `,t?.name??`unknown host`,Q(t)?``:` (host offline)`]},e.id)})})}):(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Er,{label:`Host and checkout`,htmlFor:`${t}-checkout`,children:(0,K.jsxs)(`select`,{id:`${t}-checkout`,className:Tr,value:n.checkoutId,onChange:e=>r.checkoutId(e.target.value),children:[e.projectCheckouts.length===0&&(0,K.jsx)(`option`,{value:``,children:`No checkouts`}),e.projectCheckouts.map(e=>{let t=i[e.hostId];return(0,K.jsxs)(`option`,{value:e.id,disabled:!Q(t),children:[t?.name??`Unknown host`,`: `,e.path,Q(t)?``:` (host offline)`]},e.id)})]})}),(0,K.jsx)(Er,{label:`New branch`,htmlFor:`${t}-branch`,hint:n.branch?$t(n.branch):void 0,children:(0,K.jsx)(Fe,{id:`${t}-branch`,value:n.branch,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,placeholder:`e.g. fix/login-retry`,onChange:e=>r.branch(e.target.value)})}),(0,K.jsx)(Er,{label:`Base branch (optional)`,htmlFor:`${t}-base`,hint:`Defaults to ${e.checkout?.defaultBranch??`the default branch`}.`,children:(0,K.jsx)(Fe,{id:`${t}-base`,value:n.base,autoCapitalize:`off`,autoCorrect:`off`,spellCheck:!1,placeholder:e.checkout?.defaultBranch??`main`,onChange:e=>r.base(e.target.value)})})]})]})}function Ar({form:e,id:t}){let n=e.profiles.find(t=>t.id===e.values.profileId);return(0,K.jsx)(Er,{label:`Pi profile`,htmlFor:`${t}-profile`,hint:n?[n.provider,n.model,n.thinking?`effort ${n.thinking}`:null].filter(Boolean).join(` · `)||`Pi defaults`:void 0,children:(0,K.jsx)(`select`,{id:`${t}-profile`,className:Tr,value:e.values.profileId,onChange:t=>e.set.profileId(t.target.value),children:e.profiles.map(t=>(0,K.jsxs)(`option`,{value:t.id,children:[t.name,e.project?.defaultProfileId===t.id?` (project default)`:``]},t.id))})})}function jr({form:e,id:t}){return(0,K.jsx)(Er,{label:`Initial prompt (optional)`,htmlFor:`${t}-prompt`,children:(0,K.jsx)(Ie,{id:`${t}-prompt`,minRows:3,maxHeight:`30vh`,value:e.values.prompt,placeholder:`What should Pi work on?`,onChange:t=>e.set.prompt(t.target.value)})})}function Mr({form:e}){return(0,K.jsxs)(`section`,{"aria-label":`Preview`,"data-testid":`new-session-preview`,className:`flex min-w-0 flex-col gap-1 rounded-md border border-border bg-surface-2 p-3 text-sm`,children:[(0,K.jsxs)(`h3`,{className:`flex items-center gap-1.5 font-medium`,children:[(0,K.jsx)(ge,{"aria-hidden":!0,className:`size-4`}),`Result`]}),e.preview?(0,K.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-0.5`,children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Branch`}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:e.preview.branch}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Path`}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:e.preview.path}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Host`}),(0,K.jsx)(`dd`,{className:`min-w-0 break-words`,children:e.host?.name??`Unknown`})]}):(0,K.jsx)(`p`,{className:`text-muted`,children:`Choose a workspace to see the branch and path.`}),e.values.mode===`new`&&e.preview&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`A new Git worktree is created at this path.`})]})}function Nr({problems:e}){return e.length===0?null:(0,K.jsx)(`ul`,{className:`flex flex-col gap-0.5 text-xs text-muted`,"aria-live":`polite`,children:e.map(e=>(0,K.jsx)(`li`,{children:e},e))})}var Pr=[`Project`,`Workspace`,`Profile`,`Prompt`];function Fr({open:e,onClose:t,onCreated:n,mobile:r}){let i=(0,G.useId)(),a=Dr(e),[o,s]=(0,G.useState)(0),[c,l]=(0,G.useState)(!1),[u,d]=(0,G.useState)(null),[f,p]=(0,G.useState)(null),[m,h]=(0,G.useState)(!1),g=_(e=>f?!!e.sessions[f]:!1);(0,G.useEffect)(()=>{e||(s(0),d(null),p(null),h(!1),l(!1))},[e]);let v=(0,G.useRef)(null),{reset:y}=a;(0,G.useEffect)(()=>{f&&g&&v.current!==f&&(v.current=f,y(),n(f))},[f,g,n,y]),(0,G.useEffect)(()=>{if(!f)return;let e=setTimeout(()=>h(!0),1e4);return()=>clearTimeout(e)},[f]);let x=async()=>{if(a.problems.length||c)return;let e=a.values;l(!0),d(null);try{let t=await X.createSession({projectId:e.projectId,workspace:e.mode===`existing`?{existingId:e.workspaceId}:{checkoutId:e.checkoutId,newBranch:e.branch.trim(),base:e.base.trim()||null},profileId:e.profileId||null,prompt:e.prompt});p(t.id)}catch(e){d(e)}finally{l(!1)}},S=f!==null,C=S?(0,K.jsxs)(`div`,{className:`flex flex-col items-center gap-2`,children:[(0,K.jsx)(P,{label:`Starting…`,className:`py-4`}),m&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`p`,{className:`text-center text-sm text-muted`,children:`The coordinator accepted the session but it has not synced yet. It may still be creating the worktree.`}),(0,K.jsx)(j,{onClick:()=>f&&n(f),children:`Open session`})]})]}):null,w=u===null?null:(0,K.jsx)(N,{compact:!0,title:`Could not create the session`,error:b(u),onRetry:()=>void x()});if(!r)return(0,K.jsx)(We,{open:e,onClose:t,title:`New session`,description:`A task is not required.`,dismissOnBackdrop:!c&&!S,className:`max-w-xl`,footer:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(j,{onClick:t,children:S?`Close`:`Cancel`}),(0,K.jsx)(j,{variant:`primary`,busy:c||S,disabled:a.problems.length>0,onClick:()=>void x(),children:S?`Starting…`:`Create session`})]}),children:a.projects.length===0?(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`Add a project in Settings first.`}):(0,K.jsxs)(`form`,{className:`flex min-w-0 flex-col gap-4`,onSubmit:e=>{e.preventDefault(),x()},children:[(0,K.jsx)(Or,{form:a,id:i}),(0,K.jsx)(kr,{form:a,id:i}),(0,K.jsx)(Ar,{form:a,id:i}),(0,K.jsx)(jr,{form:a,id:i}),(0,K.jsx)(Mr,{form:a}),(0,K.jsx)(Nr,{problems:a.problems}),w,C]})});let T=o===Pr.length-1,E=o===0?a.project?[]:[`Select a project.`]:o===1?a.problems.filter(e=>e!==`Select a project.`):[];return(0,K.jsxs)(Ue,{open:e,onClose:t,title:`New session: ${Pr[o]}`,description:`Step ${o+1} of ${Pr.length}`,dismissOnBackdrop:!c&&!S,footer:(0,K.jsxs)(K.Fragment,{children:[o>0&&!S&&(0,K.jsx)(j,{onClick:()=>s(e=>e-1),disabled:c,children:`Back`}),T?(0,K.jsx)(j,{variant:`primary`,busy:c||S,disabled:a.problems.length>0,onClick:()=>void x(),children:S?`Starting…`:`Create session`}):(0,K.jsx)(j,{variant:`primary`,disabled:E.length>0,onClick:()=>s(e=>e+1),children:`Next`})]}),children:[(0,K.jsx)(`ol`,{"aria-label":`Steps`,className:`mb-3 flex gap-1`,children:Pr.map((e,t)=>(0,K.jsx)(`li`,{"aria-current":t===o?`step`:void 0,className:D(`h-1 flex-1 rounded-full`,t<=o?`bg-accent`:`bg-border`),children:(0,K.jsxs)(`span`,{className:`sr-only`,children:[e,t<o?` (done)`:``]})},e))}),(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-4`,children:[o===0&&(0,K.jsx)(Or,{form:a,id:i}),o===1&&(0,K.jsx)(kr,{form:a,id:i}),o===2&&(0,K.jsx)(Ar,{form:a,id:i}),o===3&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(jr,{form:a,id:i}),(0,K.jsx)(Mr,{form:a})]}),o===1&&(0,K.jsx)(Mr,{form:a}),(0,K.jsx)(Nr,{problems:T?a.problems:E}),w,C]})]})}function Ir(e){let{session:t,run:r,control:i}=e,a=n(),[o,s]=(0,G.useState)(null),[c,l]=(0,G.useState)(t.title),u=q(()=>X.takeover(t.id),{success:`You have control. Automatic continuations are paused.`,errorToast:!0}),d=q(()=>X.returnToAutomation(t.id),{success:`Returned to automation.`,errorToast:!0}),f=q(()=>X.stop(t.id),{success:`Session stopped.`}),p=q(()=>X.resume(t.id),{success:`Session resumed.`,errorToast:!0}),m=q(e=>X.rename(t.id,e),{success:`Session renamed.`}),h=q(()=>X.archive(t.id),{success:`Session archived.`}),g=e.link===`connected`,_=()=>{s(null),f.reset(),m.reset(),h.reset()},v=t.archivedAt?`Already archived`:Yt(t)?`Stop the session before archiving it`:null,y=(0,K.jsxs)(K.Fragment,{children:[(0,K.jsxs)(We,{open:o===`stop`,onClose:_,title:`Stop this session?`,description:`Stops the current execution and clears queued messages.`,footer:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(j,{onClick:_,children:`Cancel`}),(0,K.jsx)(j,{variant:`danger`,busy:f.busy,onClick:()=>void f.run().then(e=>e&&s(null)),children:`Stop session`})]}),children:[(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:r?`The task keeps its run, marked interrupted and blocked (Stopped by user). Automation settings are unchanged.`:`Pi stays available; you can send a new message afterwards.`}),f.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Could not stop`,error:b(f.error)})]}),(0,K.jsx)(We,{open:o===`rename`,onClose:_,title:`Rename session`,footer:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(j,{onClick:_,children:`Cancel`}),(0,K.jsx)(j,{variant:`primary`,type:`submit`,form:`sy-rename-form`,busy:m.busy,disabled:!c.trim(),children:`Save`})]}),children:(0,K.jsxs)(`form`,{id:`sy-rename-form`,onSubmit:e=>{e.preventDefault(),c.trim()&&m.run(c.trim()).then(e=>e&&s(null))},className:`flex flex-col gap-2`,children:[(0,K.jsx)(`label`,{htmlFor:`sy-rename-input`,className:`text-sm font-medium`,children:`Title`}),(0,K.jsx)(Fe,{id:`sy-rename-input`,value:c,maxLength:200,onChange:e=>l(e.target.value)}),m.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Could not rename`,error:b(m.error)})]})}),(0,K.jsxs)(We,{open:o===`archive`,onClose:_,title:`Archive this session?`,description:`It leaves the navigator. The Pi session file stays on the host.`,footer:(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(j,{onClick:_,children:`Cancel`}),(0,K.jsx)(j,{variant:`primary`,busy:h.busy,onClick:()=>void h.run().then(e=>{e&&(s(null),a(`/code`))}),children:`Archive`})]}),children:[t.runtime===`idle`&&(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`The idle Pi process is stopped first.`}),h.error!==null&&(0,K.jsx)(N,{compact:!0,title:`Could not archive`,error:b(h.error)})]}),(0,K.jsx)(We,{open:o===`info`,onClose:_,title:`Native session information`,children:(0,K.jsxs)(`dl`,{className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-2 text-sm`,children:[(0,K.jsx)($,{label:`Switchyard session`,value:t.id}),(0,K.jsx)($,{label:`Pi session id`,value:t.nativeHandle?.sessionId??`Not started`}),(0,K.jsx)($,{label:`Session file`,value:t.nativeHandle?.sessionFile??`None yet`}),(0,K.jsx)($,{label:`Host`,value:`${e.hostName} (${e.link})`}),(0,K.jsx)($,{label:`Working directory`,value:t.cwd}),(0,K.jsx)($,{label:`Origin`,value:t.provenance}),(0,K.jsx)($,{label:`Profile`,value:t.profileSnapshot.name}),(0,K.jsx)($,{label:`Created`,value:M(t.createdAt)})]})})]});return{canTakeover:i===`automation`,canReturn:i===`human`,canStop:Yt(t)&&g,canResume:!Jt(t)&&!!t.nativeHandle&&!t.readOnly&&g,archiveBlocked:v,takeover:()=>void u.run(),returnToAutomation:()=>void d.run(),requestStop:()=>s(`stop`),resume:()=>void p.run(),openRename:()=>{l(t.title),s(`rename`)},requestArchive:()=>{v?V.info(v):s(`archive`)},openInfo:()=>s(`info`),busy:{takeover:u.busy,ret:d.busy,stop:f.busy,resume:p.busy},dialogs:y}}function $({label:e,value:t}){return(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:e}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono text-xs break-all`,children:t})]})}var Lr=`Automation is active; take over to stop automatic continuations`;function Rr({ctx:e,draft:t,setDraft:n,clearDraft:r,mobile:i,onTakeover:a,takeoverBusy:o,onResume:s,resumeBusy:c,className:l}){let{session:u,host:d}=e,f=U(e=>e.sendWithEnter),[p,m]=(0,G.useState)([]),[h,g]=(0,G.useState)(null),[_,v]=(0,G.useState)(null),[y,x]=(0,G.useState)(!1),[S,C]=(0,G.useState)(!1),[w,T]=(0,G.useState)(!1),[O,k]=(0,G.useState)(!1),A=(0,G.useRef)(null),M=(0,G.useRef)(null),P=(0,G.useRef)(null),F=(0,G.useId)();Ae(i&&y),(0,G.useEffect)(()=>{m([]),v(null)},[u.id]);let I=fn({session:u,hostLink:e.link,hostName:e.hostName}),L=pn(u,d?.capabilities),ee=Yt(u),te=t.trim(),ne=!te,re=e.adapters.filter(e=>e.status===`active`&&e.capabilities.includes(`commands`)),ie=!i&&!O&&/^\/\S*$/.test(t)&&y,ae=async e=>{if(I||ne||h)return;let n=t;g(e),v(null);try{let t=await X.prompt(u.id,{text:te,mode:e,images:p.map(e=>({mimeType:e.mimeType,data:e.data})),clientMessageId:`cm_${Date.now().toString(36)}_${Math.random().toString(36).slice(2,7)}`});A.current?.value===n&&r(),m([]),k(!1),t?.automationActive?V.info(Lr):e===`followUp`?V.success(`Follow-up queued`):e===`steer`&&V.success(`Steering message sent`)}catch(t){v({error:t,mode:e})}finally{g(null)}},oe=L.prompt?`prompt`:L.followUp?`followUp`:L.steer?`steer`:null,se=async e=>{if(e)for(let t of Array.from(e))try{let e=await vn(t);m(t=>[...t,e])}catch(e){V.error(b(e))}},ce=I?I.reason:ee&&!oe?`Pi is running and this runtime cannot queue messages; wait or stop the session`:ne&&p.length>0?`Add a message to send with the images`:null,le=i?{onPointerDown:e=>e.preventDefault()}:void 0,R=u.profileSnapshot,ue=[R.name,R.provider&&R.model?`${R.provider}/${R.model}`:R.model??null,R.thinking?`effort ${R.thinking}`:null].filter(Boolean).join(` · `),z=u.queue.steering.length+u.queue.followUp.length;return(0,K.jsxs)(`section`,{"data-testid":`composer`,"aria-label":`Composer`,className:D(`shrink-0 border-t border-border bg-surface px-3 pt-2 pb-2`,l),children:[(0,K.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl min-w-0 flex-col gap-2`,children:[e.control===`automation`&&!I&&(0,K.jsxs)(`div`,{role:`note`,className:`flex flex-wrap items-center gap-2 rounded-md bg-warning-soft px-3 py-1.5 text-sm`,children:[(0,K.jsx)(E,{"aria-hidden":!0,className:`size-4 shrink-0 text-warning`}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1`,children:Lr}),a&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(ve,{className:`size-3.5`}),busy:o,onClick:a,children:`Take over`})]}),e.control===`human`&&(0,K.jsxs)(`p`,{className:`flex items-center gap-1.5 text-xs text-muted`,children:[(0,K.jsx)(ve,{"aria-hidden":!0,className:`size-3.5`}),`You have control. Automatic continuations are paused.`]}),I&&(0,K.jsxs)(`div`,{role:`status`,className:`flex flex-wrap items-center gap-2 rounded-md bg-surface-2 px-3 py-1.5 text-sm`,children:[(0,K.jsx)(`span`,{className:`min-w-0 flex-1 font-medium`,children:I.reason}),I.action===`resume`&&s&&(0,K.jsx)(j,{size:`sm`,variant:`primary`,icon:(0,K.jsx)(be,{className:`size-3.5`}),busy:c,onClick:s,children:`Resume`})]}),z>0&&(0,K.jsxs)(`p`,{className:`text-xs text-muted`,children:[u.queue.steering.length>0&&`${u.queue.steering.length} steering message${u.queue.steering.length===1?``:`s`} pending. `,u.queue.followUp.length>0&&`${u.queue.followUp.length} follow-up${u.queue.followUp.length===1?``:`s`} queued.`]}),p.length>0&&(0,K.jsx)(`ul`,{"aria-label":`Attachments`,className:`flex flex-wrap gap-2`,children:p.map(e=>(0,K.jsxs)(`li`,{className:`relative flex items-center gap-2 rounded-md border border-border bg-surface-2 py-1 pr-1 pl-1`,children:[(0,K.jsx)(`img`,{src:`data:${e.mimeType};base64,${e.data}`,alt:``,className:`size-9 rounded object-cover`}),(0,K.jsx)(`span`,{className:`max-w-32 truncate text-xs`,children:e.name}),(0,K.jsx)(W,{size:`sm`,label:`Remove ${e.name}`,icon:(0,K.jsx)(ke,{className:`size-3.5`}),onClick:()=>m(t=>t.filter(t=>t.id!==e.id))})]},e.id))}),(0,K.jsxs)(`div`,{className:`relative min-w-0`,children:[ie&&(0,K.jsx)(zr,{className:`absolute bottom-full left-0 z-20 mb-1 w-full rounded-lg border border-border bg-surface p-3 shadow-pop`,adapters:re.map(e=>e.id),onClose:()=>k(!0)}),(0,K.jsx)(`label`,{htmlFor:`${F}-input`,className:`sr-only`,children:`Message to Pi`}),(0,K.jsx)(Ie,{id:`${F}-input`,ref:A,value:t,minRows:i?1:2,maxHeight:`33vh`,disabled:u.readOnly,"aria-describedby":ce?`${F}-reason`:void 0,placeholder:u.readOnly?un:ee?`Steer Pi or queue a follow-up…`:`Message Pi… ( / for commands)`,onChange:e=>{n(e.target.value),e.target.value.startsWith(`/`)||k(!1)},onFocus:()=>x(!0),onBlur:()=>x(!1),onPaste:e=>{let t=[...e.clipboardData.files].filter(e=>e.type.startsWith(`image/`));t.length&&(e.preventDefault(),se(t))},enterKeyHint:i?`enter`:`send`,onKeyDown:e=>{e.key===`Escape`&&ie?(e.preventDefault(),k(!0)):e.key!==`Enter`||e.nativeEvent.isComposing||i||(f?!e.shiftKey:e.metaKey||e.ctrlKey)&&(e.preventDefault(),oe&&ae(oe))}})]}),(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-center gap-1.5`,children:[(0,K.jsx)(`input`,{ref:M,type:`file`,accept:`image/*`,multiple:!0,hidden:!0,onChange:e=>{se(e.target.files),e.target.value=``,C(!1)}}),(0,K.jsx)(`input`,{ref:P,type:`file`,accept:`image/*`,capture:`environment`,hidden:!0,onChange:e=>{se(e.target.files),e.target.value=``,C(!1)}}),(0,K.jsx)(W,{label:`Attach images`,icon:(0,K.jsx)(At,{className:`size-4`}),disabled:u.readOnly,onClick:()=>i?C(!0):M.current?.click()}),(0,K.jsx)(W,{label:`Commands`,icon:(0,K.jsx)(It,{className:`size-4`}),disabled:u.readOnly,onClick:()=>{i?T(!0):(t.startsWith(`/`)||n(`/${t}`),k(!1),A.current?.focus())}}),(0,K.jsx)(`span`,{className:`hidden min-w-0 flex-1 truncate text-xs text-muted sm:inline`,title:`Profile, model and effort come from the session's Pi profile (Settings › Profiles). They apply when a session starts.`,children:ue}),(0,K.jsx)(`span`,{className:`min-w-0 flex-1 sm:hidden`}),!i&&!ee&&(0,K.jsx)(`span`,{className:`hidden text-xs text-subtle lg:inline`,children:f?`Enter to send · Shift+Enter for newline`:`Ctrl+Enter to send`}),ee?(0,K.jsxs)(K.Fragment,{children:[L.steer&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(wt,{className:`size-3.5`}),busy:h===`steer`,disabled:!!I||ne||h!==null&&h!==`steer`,onClick:()=>void ae(`steer`),...le,children:`Steer`}),L.followUp&&(0,K.jsx)(j,{size:`sm`,variant:`primary`,icon:(0,K.jsx)(vt,{className:`size-3.5`}),busy:h===`followUp`,disabled:!!I||ne||h!==null&&h!==`followUp`,onClick:()=>void ae(`followUp`),...le,children:`Queue follow-up`})]}):(0,K.jsx)(j,{size:`sm`,variant:`primary`,icon:(0,K.jsx)(Pt,{className:`size-3.5`}),busy:h===`prompt`,disabled:!!I||ne,onClick:()=>void ae(`prompt`),...le,children:`Send`})]}),ee&&!L.steer&&d?.capabilities&&(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Immediate steering is not supported by this runtime; messages are queued as follow-ups.`}),ce&&!I&&(0,K.jsx)(`p`,{id:`${F}-reason`,className:`text-xs text-muted`,children:ce}),I&&(0,K.jsxs)(`p`,{id:`${F}-reason`,className:`sr-only`,children:[`Sending is unavailable: `,I.reason]}),_&&(0,K.jsx)(N,{compact:!0,title:`Message not sent. Your draft is kept.`,error:b(_.error),onRetry:()=>void ae(_.mode)})]}),(0,K.jsx)(Ue,{open:S,onClose:()=>C(!1),title:`Attach images`,children:(0,K.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,K.jsx)(j,{block:!0,icon:(0,K.jsx)(gt,{className:`size-4`}),onClick:()=>M.current?.click(),children:`Choose photos`}),(0,K.jsx)(j,{block:!0,icon:(0,K.jsx)(Qe,{className:`size-4`}),onClick:()=>P.current?.click(),children:`Take photo`}),(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Images up to 10 MB are sent with your next message.`})]})}),(0,K.jsxs)(Ue,{open:w,onClose:()=>T(!1),title:`Commands`,children:[(0,K.jsx)(zr,{adapters:re.map(e=>e.id)}),(0,K.jsx)(`div`,{className:`mt-3`,children:(0,K.jsx)(j,{block:!0,variant:`primary`,onClick:()=>{t.startsWith(`/`)||n(`/${t}`),T(!1),requestAnimationFrame(()=>A.current?.focus())},children:`Start a command`})})]})]})}function zr({adapters:e,onClose:t,className:n}){return(0,K.jsxs)(`div`,{role:`note`,"aria-label":`Slash commands`,className:n,children:[(0,K.jsxs)(`div`,{className:`flex items-start gap-2`,children:[(0,K.jsxs)(`p`,{className:`min-w-0 flex-1 text-sm`,children:[`Text starting with `,(0,K.jsx)(`code`,{className:`font-mono`,children:`/`}),` is sent to Pi as a command (extension commands and prompt templates). Switchyard does not list Pi's commands; type the command name.`]}),t&&(0,K.jsx)(W,{size:`sm`,label:`Close command hint`,icon:(0,K.jsx)(ke,{className:`size-3.5`}),onClick:t})]}),e.length>0&&(0,K.jsxs)(`p`,{className:`mt-1 text-xs text-muted`,children:[`Extensions with commands on this host: `,e.join(`, `)]})]})}function Br(e){let{entry:t}=e;if(t.type===`stream`)return(0,K.jsx)(ei,{stream:t.stream});if(t.type===`interaction`)return(0,K.jsx)($r,{interaction:t.interaction,readOnly:e.interactionReadOnly,highlight:e.highlightInteractionId===t.interaction.id});let{item:n,stream:r}=t;switch(n.kind){case`user`:return(0,K.jsx)(Hr,{item:n});case`assistant`:return(0,K.jsx)(Ur,{text:n.data.text+(r?.text??``),thinking:r?.thinking??``,streaming:!!r||n.data.streaming===!0});case`thinking`:return(0,K.jsx)(Wr,{text:n.data.text+(r?.thinking??``),live:!!r});case`tool`:return(0,K.jsx)(Kr,{data:n.data,stream:r,sessionId:e.sessionId});case`notice`:return(0,K.jsx)(Yr,{level:n.data.level,text:n.data.text});case`system`:return(0,K.jsx)(Xr,{text:n.data.text,suggestion:n.data.suggestion===!0,draftEmpty:e.draftEmpty,onUse:e.onUseSuggestion});case`subagent`:return(0,K.jsx)(Zr,{data:n.data});case`interaction`:return(0,K.jsx)(Qr,{interactionId:n.data.interactionId,readOnly:e.interactionReadOnly,highlight:e.highlightInteractionId===n.data.interactionId})}}function Vr({icon:e,children:t}){return(0,K.jsxs)(`div`,{className:`mb-1 flex items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,K.jsx)(e,{"aria-hidden":!0,className:`size-3.5 shrink-0`}),t]})}function Hr({item:e}){return(0,K.jsxs)(`div`,{className:`min-w-0 rounded-lg border border-border bg-surface-2 px-3 py-2`,children:[(0,K.jsxs)(Vr,{icon:Bt,children:[`You `,(0,K.jsxs)(`span`,{className:`font-normal text-subtle`,children:[`· `,M(e.at)]})]}),(0,K.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e.data.text}),e.data.images?(0,K.jsxs)(`p`,{className:`mt-1 text-xs text-muted`,children:[e.data.images,` image`,e.data.images===1?``:`s`,` attached`]}):null]})}function Ur({text:e,thinking:t,streaming:n}){return(0,K.jsxs)(`div`,{className:`min-w-0 px-1`,children:[(0,K.jsxs)(Vr,{icon:Je,children:[`Pi`,n&&(0,K.jsxs)(`span`,{className:`inline-flex items-center gap-1 font-normal`,children:[(0,K.jsx)(Te,{"aria-hidden":!0,className:`size-3 animate-spin`}),`Writing…`]})]}),t&&(0,K.jsx)(Wr,{text:t,live:!0}),e?(0,K.jsx)(Be,{text:e}):!t&&(0,K.jsx)(`p`,{className:`text-sm text-muted`,children:`…`})]})}function Wr({text:e,live:t}){return(0,K.jsxs)(`details`,{className:`group min-w-0 rounded-md border border-border bg-surface px-3 py-1.5`,children:[(0,K.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,K.jsx)(z,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),(0,K.jsx)(Xe,{"aria-hidden":!0,className:`size-3.5`}),t?`Thinking…`:`Thinking`]}),(0,K.jsx)(`p`,{className:`mt-1 text-xs break-words whitespace-pre-wrap text-muted`,children:e})]})}var Gr={running:{label:`Running`,icon:Te},ok:{label:`Done`,icon:Ee},error:{label:`Failed`,icon:we}};function Kr({data:e,stream:t,sessionId:n}){let{mobile:r,openFile:i}=Gt(),[a,o]=(0,G.useState)(!1),s=e.status===`running`,c=Tn(s),l=e.durationMs??(s?Math.max(0,c-Date.parse(e.startedAt)):null),u=Gr[e.status],d=u.icon,f=yn(e.args)||t?.toolArgs||``,p=e.output+(t?.toolOutput??``),m=bn(p);return(0,K.jsxs)(`article`,{"data-testid":`tool-card`,"aria-label":`Tool ${e.name}: ${u.label}`,className:`min-w-0 rounded-md border border-border bg-surface`,children:[(0,K.jsxs)(`header`,{className:`flex min-w-0 flex-wrap items-center gap-x-2 gap-y-0.5 px-3 py-2`,children:[(0,K.jsx)(d,{"aria-hidden":!0,className:D(`size-4 shrink-0`,s&&`animate-spin text-info`,e.status===`ok`&&`text-success`,e.status===`error`&&`text-danger`)}),(0,K.jsx)(`span`,{className:`min-w-0 truncate font-mono text-sm font-medium`,children:e.name}),(0,K.jsx)(`span`,{className:D(`text-xs`,e.status===`error`?`text-danger`:s?`text-info`:`text-muted`),children:u.label}),l!==null&&(0,K.jsx)(`span`,{className:`ml-auto text-xs text-subtle tabular-nums`,children:T(l)}),e.summary&&(0,K.jsx)(`p`,{className:`w-full min-w-0 truncate text-xs text-muted`,title:e.summary,children:e.summary})]}),e.card&&(0,K.jsx)(`div`,{className:`border-t border-border px-3 py-2`,children:(0,K.jsx)(pe,{node:e.card,onAction:t=>{e.adapterId&&X.adapterAction(n,e.adapterId,t).then(()=>V.success(`Action sent`)).catch(e=>V.error(b(e)))},onOpenFile:i})}),(f||p)&&(0,K.jsxs)(`div`,{className:`flex flex-col gap-1 border-t border-border px-3 py-1.5`,children:[f&&(0,K.jsxs)(`details`,{className:`group min-w-0`,children:[(0,K.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1 text-xs font-medium text-muted`,children:[(0,K.jsx)(z,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),`Arguments`]}),(0,K.jsx)(Re,{text:f,className:`mt-1`,maxHeight:`16rem`})]}),p&&(r?(0,K.jsxs)(`div`,{className:`min-w-0`,children:[(0,K.jsxs)(`div`,{className:`text-xs font-medium text-muted`,children:[`Output`,m.truncated?` (last lines)`:``]}),(0,K.jsx)(Re,{text:m.text,className:`mt-1`}),m.truncated&&(0,K.jsx)(j,{size:`sm`,variant:`ghost`,onClick:()=>o(!0),children:`Show full output`}),(0,K.jsx)(Ue,{open:a,onClose:()=>o(!1),title:`${e.name} output`,children:(0,K.jsx)(Re,{text:p})})]}):(0,K.jsxs)(`details`,{className:`group min-w-0`,children:[(0,K.jsxs)(`summary`,{className:`tap flex cursor-pointer list-none items-center gap-1 text-xs font-medium text-muted`,children:[(0,K.jsx)(z,{"aria-hidden":!0,className:`size-3.5 transition-transform group-open:rotate-90`}),`Output`,(0,K.jsxs)(`span`,{className:`font-normal text-subtle`,children:[`(`,p.split(`
|
|
7
|
-
`).length,` lines)`]})]}),(0,K.jsx)(Re,{text:p,className:`mt-1`,maxHeight:`24rem`})]}))]})]})}var qr={info:De,warning:E,error:L},Jr={info:`Notice`,warning:`Warning`,error:`Error`};function Yr({level:e,text:t}){let n=qr[e];return(0,K.jsxs)(`div`,{role:e===`error`?`alert`:`note`,className:D(`flex min-w-0 items-start gap-2 rounded-md border px-3 py-2 text-sm`,e===`info`&&`border-border bg-surface-2`,e===`warning`&&`border-transparent bg-warning-soft`,e===`error`&&`border-transparent bg-danger-soft`),children:[(0,K.jsx)(n,{"aria-hidden":!0,className:D(`mt-0.5 size-4 shrink-0`,e===`warning`&&`text-warning`,e===`error`&&`text-danger`,e===`info`&&`text-muted`)}),(0,K.jsxs)(`span`,{className:`sr-only`,children:[Jr[e],`: `]}),(0,K.jsx)(`span`,{className:`min-w-0 break-words whitespace-pre-wrap`,children:t})]})}function Xr({text:e,suggestion:t,draftEmpty:n,onUse:r}){return t?(0,K.jsxs)(`div`,{className:`min-w-0 rounded-md border border-dashed border-border-strong px-3 py-2`,children:[(0,K.jsx)(Vr,{icon:Ht,children:`Suggested next message`}),(0,K.jsx)(`p`,{className:`text-sm break-words whitespace-pre-wrap`,children:e}),(0,K.jsxs)(`div`,{className:`mt-2 flex flex-wrap items-center gap-2`,children:[(0,K.jsx)(j,{size:`sm`,disabled:!n,onClick:()=>r(e),children:`Use suggestion`}),(0,K.jsx)(j,{size:`sm`,variant:`ghost`,icon:(0,K.jsx)(de,{className:`size-3.5`}),onClick:()=>void navigator.clipboard?.writeText(e).then(()=>V.success(`Copied`)),children:`Copy`}),!n&&(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:`Your draft is not empty; clear it to use this suggestion.`})]})]}):(0,K.jsx)(`p`,{className:`px-1 text-xs break-words whitespace-pre-wrap text-muted`,children:e})}function Zr({data:e}){let t=_(t=>e.linkedSessionId?t.sessions[e.linkedSessionId]:void 0),n=e.status.toLowerCase(),i=/run|start|progress/.test(n)?Te:/fail|error/.test(n)?we:/done|complete|success|ok/.test(n)?Ee:Et;return(0,K.jsxs)(`div`,{className:`flex min-w-0 items-start gap-2 rounded-md border border-border bg-surface px-3 py-2`,children:[(0,K.jsx)(i,{"aria-hidden":!0,className:D(`mt-0.5 size-4 shrink-0 text-muted`,i===Te&&`animate-spin`)}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-wrap items-baseline gap-x-2`,children:[(0,K.jsx)(`span`,{className:`text-xs font-medium text-muted`,children:`Subagent`}),(0,K.jsx)(`span`,{className:`min-w-0 truncate text-sm font-medium`,children:e.label}),(0,K.jsx)(`span`,{className:`text-xs text-muted`,children:e.status})]}),e.linkedSessionId?(0,K.jsxs)(r,{to:`/code/${encodeURIComponent(e.linkedSessionId)}`,className:`text-sm text-accent underline underline-offset-2`,children:[`Open `,t?.title??`subagent session`]}):(0,K.jsx)(`p`,{className:`text-xs break-all text-muted`,children:e.sessionFile?`Session file: ${e.sessionFile}`:`Session not linked yet.`}),(0,K.jsx)(`p`,{className:`text-xs text-muted`,children:`Subagent: view only. Live control is not supported.`})]})]})}function Qr({interactionId:e,readOnly:t,highlight:n}){let r=_(t=>t.interactions[e]);return r?(0,K.jsx)($r,{interaction:r,readOnly:t,highlight:n}):(0,K.jsx)(`p`,{id:gn(e),className:`px-1 text-xs text-muted`,children:`Question (details not loaded yet)`})}function $r({interaction:e,readOnly:t,highlight:n}){return(0,K.jsx)(`div`,{"data-testid":`interaction-card`,"data-interaction-id":e.id,"data-state":e.state,className:D(`min-w-0 scroll-mt-16 rounded-lg transition-shadow`,n&&`ring-2 ring-accent ring-offset-2 ring-offset-bg`),children:(0,K.jsx)(he,{id:gn(e.id),interaction:e,readOnlyReason:e.state===`pending`||e.state===`unsupported`?t:null,className:`w-full`})})}function ei({stream:e}){return(0,K.jsxs)(`div`,{className:`flex min-w-0 flex-col gap-2`,children:[(e.text||e.thinking)&&(0,K.jsx)(Ur,{text:e.text,thinking:e.thinking,streaming:!0}),(e.toolArgs||e.toolOutput)&&(0,K.jsxs)(`div`,{className:`min-w-0 rounded-md border border-border bg-surface px-3 py-2`,children:[(0,K.jsxs)(`div`,{className:`flex items-center gap-1.5 text-xs font-medium text-muted`,children:[(0,K.jsx)(Te,{"aria-hidden":!0,className:`size-3.5 animate-spin`}),`Tool running…`]}),e.toolArgs&&(0,K.jsx)(Re,{text:e.toolArgs,className:`mt-1`,maxHeight:`8rem`}),e.toolOutput&&(0,K.jsx)(Re,{text:bn(e.toolOutput).text,className:`mt-1`})]})]})}function ti(e,t,n=!1){let r=e.getBoundingClientRect(),i=t.getBoundingClientRect(),a=e.scrollTop+(i.top-r.top)-Math.max(0,(r.height-i.height)/2);e.scrollTo({top:Math.max(0,a),behavior:n?`smooth`:`auto`})}var ni=160,ri=4e3;function ii({sessionId:e,draftEmpty:t,onUseSuggestion:n,interactionReadOnly:r,focusInteractionId:i,className:a}){let o=p(e),s=h(e),c=A(e),l=_(e=>e.loadOlderTranscript),u=_(e=>e.loadTranscript),d=(0,G.useMemo)(()=>mn(o.items,s,c),[o.items,s,c]),f=(0,G.useRef)(null),m=(0,G.useRef)(!0),[g,v]=(0,G.useState)(!0),[y,b]=(0,G.useState)(null),x=(0,G.useRef)(null),[C,w]=(0,G.useState)(null),T=d.length?d[d.length-1].key:null,E=d.length?d[0].key:null,O=s.reduce((e,t)=>e+t.text.length+t.thinking.length+t.toolArgs.length+t.toolOutput.length,0);(0,G.useEffect)(()=>{m.current=!0,v(!0),b(null),x.current=null},[e]);let k=(0,G.useCallback)(()=>{let t=f.current;t&&o.hasMore&&!o.loading&&(x.current=t.scrollHeight,l(e))},[o.hasMore,o.loading,l,e]),M=()=>{let e=f.current;if(!e)return;let t=e.scrollHeight-e.scrollTop-e.clientHeight<=48;t!==m.current&&(m.current=t,v(t),b(t?null:T)),e.scrollTop<ni&&k()};(0,G.useLayoutEffect)(()=>{let e=f.current;if(e){if(x.current!==null){let t=e.scrollHeight-x.current;if(x.current=null,!m.current&&t>0){e.scrollTop+=t;return}}m.current&&(e.scrollTop=e.scrollHeight)}},[d.length,T,E,O,o.loaded]);let F=(0,G.useRef)(null),I=(0,G.useRef)(0);(0,G.useLayoutEffect)(()=>{if(!i||F.current===i||!o.loaded)return;let e=document.getElementById(gn(i));e?(F.current=i,I.current=0,m.current=!1,v(!1),b(T),f.current&&ti(f.current,e),w(i)):o.hasMore&&!o.loading&&I.current<5&&(I.current++,k())}),(0,G.useEffect)(()=>{if(!C)return;let e=setTimeout(()=>w(null),ri);return()=>clearTimeout(e)},[C]);let L=()=>{let e=f.current;e&&(m.current=!0,v(!0),b(null),e.scrollTo({top:e.scrollHeight,behavior:`smooth`}))},ee=()=>{let e=c[0];if(!e)return;let t=document.getElementById(gn(e.id));t&&(m.current=!1,v(!1),b(T),f.current&&ti(f.current,t,!0),w(e.id),(t.querySelector(`input, select, textarea, button:not([disabled])`)??t).focus({preventScroll:!0}))},te=g?0:hn(d,y);return(0,K.jsxs)(`div`,{className:D(`relative flex min-h-0 min-w-0 flex-1 flex-col`,a),children:[c.length>0&&(0,K.jsx)(`div`,{"data-testid":`needs-answer-strip`,className:`shrink-0 px-3 pt-2`,children:(0,K.jsx)(S,{count:c.length,onOpen:ee,label:c.length===1?`Needs your answer: ${c[0].title}`:`${c.length} questions need your answer`})}),(0,K.jsx)(`div`,{ref:f,"data-testid":`transcript`,role:`log`,"aria-live":`off`,"aria-label":`Transcript`,onScroll:M,className:`relative min-h-0 flex-1 overflow-x-hidden overflow-y-auto overscroll-contain px-3 py-3 [overflow-anchor:none] focus-visible:outline-offset-[-2px]`,children:(0,K.jsxs)(`div`,{className:`mx-auto flex w-full max-w-3xl min-w-0 flex-col gap-3`,children:[o.loaded&&o.hasMore&&(0,K.jsx)(`div`,{className:`flex justify-center`,children:(0,K.jsx)(j,{size:`sm`,variant:`ghost`,busy:o.loading,onClick:k,children:`Load earlier messages`})}),o.error&&o.loaded&&(0,K.jsx)(N,{compact:!0,title:`Could not load more of the transcript`,error:o.error,onRetry:k}),!o.loaded&&o.error?(0,K.jsx)(N,{title:`Could not load the transcript`,error:o.error,onRetry:()=>void u(e,{force:!0})}):!o.loaded&&d.length===0?(0,K.jsx)(P,{label:`Loading transcript…`}):d.length===0?(0,K.jsx)(`p`,{className:`py-10 text-center text-sm text-muted`,children:`No messages yet. Write a prompt below to start.`}):d.map(i=>(0,K.jsx)(Br,{entry:i,sessionId:e,interactionReadOnly:r,draftEmpty:t,onUseSuggestion:n,highlightInteractionId:C},i.key)),o.stale&&o.loaded&&(0,K.jsx)(`p`,{role:`status`,className:`text-center text-xs text-muted`,children:`Refreshing transcript…`})]})}),!g&&(0,K.jsx)(`div`,{className:`pointer-events-none absolute inset-x-0 bottom-3 flex justify-center`,children:(0,K.jsxs)(j,{"data-testid":`jump-to-latest`,size:`sm`,variant:`secondary`,className:`pointer-events-auto shadow-pop`,icon:(0,K.jsx)(ne,{className:`size-4`}),onClick:L,children:[`Jump to latest`,te>0?` (${te})`:``]})})]})}function ai(e){return e.session.readOnly?`${un} Answer in the parent session.`:e.link===`connected`?null:`Host ${e.hostName} is offline; answers can be sent when it reconnects.`}function oi({ctx:e,actions:t}){let{session:n}=e,i=_(e=>e.loadTranscript),a=dn(n);return(0,G.useEffect)(()=>{a&&i(n.id,{force:!0})},[a,n.id,i]),(0,K.jsxs)(K.Fragment,{children:[e.link!==`connected`&&(0,K.jsx)(`div`,{className:`shrink-0 px-3 pt-2`,children:(0,K.jsx)(O,{compact:!0,hostName:e.hostName,connectivity:e.link===`reconnecting`?`reconnecting`:`unreachable`,lastSeenAt:e.host?.lastSeenAt,detail:`Showing the last known transcript. Sending and answers resume when the host reconnects.`})}),n.runtime===`failed`&&(0,K.jsx)(`div`,{className:`shrink-0 px-3 pt-2`,children:(0,K.jsxs)(`div`,{role:`alert`,className:`flex flex-wrap items-start gap-2 rounded-md border border-border bg-danger-soft px-3 py-2 text-sm`,children:[(0,K.jsx)(L,{"aria-hidden":!0,className:`mt-0.5 size-4 shrink-0 text-danger`}),(0,K.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,K.jsx)(`div`,{className:`font-medium`,children:`This session failed`}),(0,K.jsx)(`div`,{className:`break-words text-muted`,children:n.runtimeDetail??`Pi exited with an error.`}),(0,K.jsx)(r,{to:`/settings/diagnostics`,className:`text-accent underline`,children:`Open diagnostics`})]}),t.canResume&&(0,K.jsx)(j,{size:`sm`,icon:(0,K.jsx)(be,{className:`size-3.5`}),busy:t.busy.resume,onClick:t.resume,children:`Resume`})]})}),n.runtime===`interrupted`&&n.runtimeDetail&&(0,K.jsxs)(`p`,{role:`status`,className:`shrink-0 px-4 pt-2 text-sm text-muted`,children:[`Interrupted: `,n.runtimeDetail]}),n.archivedAt&&(0,K.jsx)(`p`,{role:`status`,className:`shrink-0 px-4 pt-2 text-sm text-muted`,children:`This session is archived.`})]})}function si(e){let[t,n,r]=Pn(e);return{draft:t,setDraft:n,clearDraft:r,onUseSuggestion:e=>{t.trim()===``&&n(e)}}}function ci({ctx:e,actions:t,focusInteractionId:n,inspector:r}){let i=si(e.session.id);return(0,K.jsxs)(`section`,{"data-testid":`conversation`,"aria-label":`Conversation`,className:`flex h-full min-h-0 min-w-0 flex-col bg-bg`,children:[(0,K.jsx)(sr,{ctx:e,actions:t,inspector:r}),(0,K.jsx)(oi,{ctx:e,actions:t}),(0,K.jsx)(ii,{sessionId:e.session.id,draftEmpty:i.draft.trim()===``,onUseSuggestion:i.onUseSuggestion,interactionReadOnly:ai(e),focusInteractionId:n}),(0,K.jsx)(Rr,{ctx:e,draft:i.draft,setDraft:i.setDraft,clearDraft:i.clearDraft,mobile:!1,onTakeover:t.takeover,takeoverBusy:t.busy.takeover,onResume:t.resume,resumeBusy:t.busy.resume}),t.dialogs]})}function li(e){return e?e===`changes`?`changes`:`details`:`chat`}function ui({ctx:e,actions:t,focusInteractionId:i,tabRequest:a}){let{session:o,project:s,workspace:c,task:l}=e,u=n(),[d,f]=(0,G.useState)(()=>li(a?.tab)),[p,m]=(0,G.useState)(!1),h=A(o.id),g=si(o.id),_=a?`${a.tab}:${a.key}`:null;(0,G.useEffect)(()=>f(li(a?.tab)),[o.id,i,_]);let v=(0,G.useMemo)(()=>({mobile:!0,openInspector:e=>f(e===`changes`?`changes`:`details`)}),[]),y=[...l?[{id:`task`,label:`Open linked task`,icon:(0,K.jsx)(Pe,{className:`size-4`}),onSelect:()=>u(`/tasks/${encodeURIComponent(l.id)}`)}]:[],...t.canResume?[{id:`resume`,label:`Resume`,icon:(0,K.jsx)(be,{className:`size-4`}),onSelect:t.resume}]:[],...or(e,t)];return(0,K.jsx)(Wt.Provider,{value:v,children:(0,K.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0 flex-col bg-bg`,children:[(0,K.jsxs)(`header`,{className:`flex min-w-0 shrink-0 items-center gap-1 border-b border-border bg-surface px-1.5 py-1 safe-pt`,children:[(0,K.jsx)(r,{to:`/code`,"aria-label":`Back to sessions`,title:`Back to sessions`,className:w(`ghost`,`md`,`size-11 px-0`),children:(0,K.jsx)(oe,{"aria-hidden":!0,className:`size-5`})}),(0,K.jsx)(`div`,{className:`min-w-0 flex-1`,children:(0,K.jsx)(`h1`,{className:`truncate text-base leading-6 font-semibold`,title:o.title,children:o.title})}),(0,K.jsx)(H,{kind:`runtime`,value:o.runtime,size:`sm`,className:`shrink-0`}),(0,K.jsx)(ae,{label:`Session actions`,items:y,trigger:e=>(0,K.jsx)(W,{...e,label:`More actions`,icon:(0,K.jsx)(ot,{className:`size-5`})})})]}),(0,K.jsxs)(`div`,{className:`shrink-0 border-b border-border bg-surface px-3`,children:[(0,K.jsxs)(`button`,{type:`button`,"aria-expanded":p,"aria-controls":`sy-session-meta`,onClick:()=>m(e=>!e),className:`tap flex w-full min-w-0 items-center gap-2 py-1.5 text-left text-xs text-muted`,children:[(0,K.jsxs)(`span`,{className:`min-w-0 flex-1 truncate`,children:[s?.name??`No project`,` · `,nn(c,o.cwd),` ·`,` `,e.hostName,e.link===`connected`?``:` (offline)`,` · `,cn[e.control]]}),p?(0,K.jsx)(et,{"aria-hidden":!0,className:`size-4 shrink-0`}):(0,K.jsx)(ie,{"aria-hidden":!0,className:`size-4 shrink-0`}),(0,K.jsx)(`span`,{className:`sr-only`,children:p?`Hide details`:`Show details`})]}),p&&(0,K.jsxs)(`dl`,{id:`sy-session-meta`,className:`grid grid-cols-[auto_minmax(0,1fr)] gap-x-3 gap-y-1 pb-2 text-xs`,children:[(0,K.jsx)(`dt`,{className:`text-muted`,children:`Project`}),(0,K.jsx)(`dd`,{className:`min-w-0 break-words`,children:s?.name??`None`}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Branch`}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono break-all`,children:nn(c,o.cwd)}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Host`}),(0,K.jsxs)(`dd`,{className:`min-w-0 break-words`,children:[e.hostName,` (`,e.link,`)`]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Control`}),(0,K.jsxs)(`dd`,{children:[(0,K.jsx)(ir,{ctx:e}),e.control===`none`&&`Manual session`]}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Path`}),(0,K.jsx)(`dd`,{className:`min-w-0 font-mono break-all`,children:o.cwd}),(0,K.jsx)(`dt`,{className:`text-muted`,children:`Profile`}),(0,K.jsx)(`dd`,{className:`min-w-0 break-words`,children:o.profileSnapshot.name})]})]}),(0,K.jsx)(`div`,{className:`shrink-0 bg-surface px-3 py-2`,"data-testid":`mobile-tabs`,children:(0,K.jsx)(Ve,{label:`Session view`,block:!0,value:d,onChange:f,options:[{value:`chat`,label:`Chat`,badge:h.length>0?(0,K.jsxs)(`span`,{className:`rounded-full bg-warning-soft px-1.5 text-xs text-warning`,children:[h.length,(0,K.jsx)(`span`,{className:`sr-only`,children:` pending questions`})]}):void 0},{value:`changes`,label:`Changes`},{value:`details`,label:`Details`}]})}),(0,K.jsxs)(`div`,{className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[d===`chat`&&(0,K.jsxs)(`section`,{"data-testid":`conversation`,"aria-label":`Chat`,className:`flex min-h-0 min-w-0 flex-1 flex-col`,children:[(0,K.jsx)(oi,{ctx:e,actions:t}),(0,K.jsx)(ii,{sessionId:o.id,draftEmpty:g.draft.trim()===``,onUseSuggestion:g.onUseSuggestion,interactionReadOnly:ai(e),focusInteractionId:i}),(0,K.jsx)(Rr,{ctx:e,draft:g.draft,setDraft:g.setDraft,clearDraft:g.clearDraft,mobile:!0,onTakeover:t.takeover,takeoverBusy:t.busy.takeover,onResume:t.resume,resumeBusy:t.busy.resume,className:`safe-pb`})]}),d===`changes`&&(0,K.jsx)(`section`,{"aria-label":`Changes`,className:`relative min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,K.jsx)(er,{ctx:e})}),d===`details`&&(0,K.jsx)(`section`,{"aria-label":`Details`,className:`relative min-h-0 min-w-0 flex-1 overflow-y-auto overscroll-contain`,children:(0,K.jsx)(gr,{ctx:e,actions:t})})]}),t.dialogs]})})}function di(){let e=(0,G.useRef)(null),[t,n]=(0,G.useState)(0);return(0,G.useLayoutEffect)(()=>{let t=e.current;if(!t)return;n(t.clientWidth);let r=new ResizeObserver(([e])=>{e&&n(e.contentRect.width)});return r.observe(t),()=>r.disconnect()},[]),[e,t]}function fi({missing:e}){return e?(0,K.jsx)(I,{icon:(0,K.jsx)(Mt,{className:`size-8`}),title:`Session not found`,description:`It may have been archived, or this link points to another coordinator.`,action:{label:`Back to sessions`,to:`/code`}}):(0,K.jsx)(I,{icon:(0,K.jsx)(St,{className:`size-8`}),title:`Select a session`,description:`Pick a session in the navigator, or start a new one.`})}function pi({compact:e,...t}){let r=n(),i=U(e=>e.paneSizes),a=U(e=>e.setPaneSize),o=U(e=>e.inspectorCollapsed),s=U(e=>e.set),[c,l]=(0,G.useState)(!1),[u,d]=(0,G.useState)(!1),[f,p]=di(),m=wn(t.session),h=!e&&!o&&!!m,g=Sn(p,i.navigator,h?i.inspector:null),_=(0,G.useCallback)(e=>{l(!1),r(`/code/${encodeURIComponent(e)}`)},[r]);return(0,K.jsxs)(`div`,{ref:f,className:`absolute inset-0 flex min-w-0 overflow-hidden`,children:[(0,K.jsx)(Sr,{variant:`pane`,selectedId:t.sessionId,onNewSession:()=>l(!0),className:`shrink-0 border-r border-border`,style:{width:g.nav}}),(0,K.jsx)(Ut,{label:`Resize navigator`,value:g.nav,min:B.navigator.min,max:B.navigator.max,onChange:e=>a(`navigator`,e),onReset:()=>a(`navigator`,B.navigator.default),className:`-ml-1.5`}),(0,K.jsx)(`div`,{className:`relative min-h-0 min-w-0 flex-1`,style:{minWidth:420},children:!t.hydrated&&t.sessionId?(0,K.jsx)(P,{label:`Loading session…`}):m?(0,K.jsx)(mi,{ctx:m,compact:e,showInspector:h,inspectorWidth:g.insp,setInspectorWidth:e=>a(`inspector`,e),collapsed:o,setCollapsed:e=>s(`inspectorCollapsed`,e),drawerOpen:u,setDrawerOpen:d,focusInteractionId:t.focusInteractionId,tabRequest:t.tabRequest},m.session.id):(0,K.jsx)(fi,{missing:!!t.sessionId})}),(0,K.jsx)(Fr,{open:c,onClose:()=>l(!1),onCreated:_,mobile:!1})]})}function mi({ctx:e,compact:t,showInspector:n,inspectorWidth:r,setInspectorWidth:i,collapsed:a,setCollapsed:o,drawerOpen:s,setDrawerOpen:c,focusInteractionId:l,tabRequest:u}){let d=Ir(e),[f,p]=(0,G.useState)(u?.tab??`changes`),[m,h]=(0,G.useState)(null),g=(0,G.useCallback)(e=>{p(e),t?c(!0):o(!1)},[t,c,o]),_=(0,G.useMemo)(()=>({mobile:!1,openInspector:g,openFile:e=>{h({path:e,nonce:Date.now()}),g(`files`)}}),[g]),v=u?`${u.tab}:${u.key}`:null;(0,G.useEffect)(()=>{u&&g(u.tab)},[v]),(0,G.useEffect)(()=>{t||c(!1)},[t,c]);let y=t?s:!a,b={open:y,label:y?`Hide inspector`:`Show inspector`,toggle:()=>t?c(!s):o(!a)};return(0,K.jsxs)(Wt.Provider,{value:_,children:[(0,K.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0`,children:[(0,K.jsx)(`div`,{className:`min-h-0 min-w-0 flex-1`,children:(0,K.jsx)(ci,{ctx:e,actions:d,focusInteractionId:l,inspector:b})}),n&&r!==null&&(0,K.jsxs)(K.Fragment,{children:[(0,K.jsx)(Ut,{label:`Resize inspector`,pane:`after`,value:r,min:B.inspector.min,max:B.inspector.max,onChange:i,onReset:()=>i(B.inspector.default),className:`-mr-1.5`}),(0,K.jsx)(`div`,{className:`min-h-0 shrink-0 border-l border-border`,style:{width:r},children:(0,K.jsx)(br,{ctx:e,actions:d,tab:f,onTab:p,openPath:m,className:`h-full`})})]})]}),t&&(0,K.jsx)(He,{open:s,onClose:()=>c(!1),title:`Inspector`,width:440,className:`[&>div:last-child]:p-0`,children:(0,K.jsx)(br,{ctx:e,actions:d,tab:f,onTab:p,openPath:m,hideTitle:!0})})]})}function hi(e){let t=n(),[r,i]=(0,G.useState)(!1),a=wn(e.session),o=(0,G.useCallback)(e=>{i(!1),t(`/code/${encodeURIComponent(e)}`)},[t]);return e.sessionId?e.hydrated?a?(0,K.jsx)(gi,{ctx:a,focus:e.focusInteractionId,tabRequest:e.tabRequest},a.session.id):(0,K.jsx)(fi,{missing:!0}):(0,K.jsx)(P,{label:`Loading session…`}):(0,K.jsxs)(`div`,{className:`absolute inset-0 flex min-w-0 flex-col`,children:[(0,K.jsx)(Sr,{variant:`screen`,selectedId:null,onNewSession:()=>i(!0),className:`min-h-0 flex-1 safe-pt`}),(0,K.jsx)(Fr,{open:r,onClose:()=>i(!1),onCreated:o,mobile:!0})]})}function gi({ctx:e,focus:t,tabRequest:n}){let r=Ir(e);return(0,K.jsx)(ui,{ctx:e,actions:r,focusInteractionId:t,tabRequest:n})}var _i=[`changes`,`files`,`task`,`extensions`];function vi(){let{sessionId:e}=s(),n=e??null,[r]=t(),i=r.get(`interaction`),a=r.get(`tab`),c=a&&_i.includes(a)?a:null,{key:u}=l(),d=Me(),f=_(e=>e.hydrated),p=m(n),h=U(e=>e.lastSessionId),g=m(h),v=U(e=>e.set);if(te(p?p.id:null),(0,G.useEffect)(()=>{p&&p.id!==U.getState().lastSessionId&&v(`lastSessionId`,p.id)},[p,v]),!n&&d!==`mobile`&&f&&g&&g.archivedAt===null)return(0,K.jsx)(o,{to:`/code/${encodeURIComponent(g.id)}`,replace:!0});let y={session:p,sessionId:n,hydrated:f,focusInteractionId:i,tabRequest:c?{tab:c,key:u}:null};return d===`mobile`?(0,K.jsx)(hi,{...y}):(0,K.jsx)(pi,{...y,compact:d===`compact`})}export{vi as default};
|
|
8
|
-
//# sourceMappingURL=code-BR4PKt8F.js.map
|