@puddle-code/cli 0.3.11 → 0.3.13

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.
Files changed (65) hide show
  1. package/CHANGELOG.md +8 -2
  2. package/dist/host-control.mjs +20 -0
  3. package/dist/index.js +25 -3
  4. package/dist/public/assets/App-Dtn-lPJX.js +2 -0
  5. package/dist/public/assets/CompilationCommandForm-Bzt5OaiJ.js +1 -0
  6. package/dist/public/assets/Dashboard-D6cwjmKX.js +1 -0
  7. package/dist/public/assets/{EditorTabClose-DwhahpvS.js → EditorTabClose-xasqNn4b.js} +1 -1
  8. package/dist/public/assets/LazyTerminal-B2eXi-NW.js +2 -0
  9. package/dist/public/assets/{ModelRefcount-njA_f4bS.js → ModelRefcount-Dfulry9I.js} +1 -1
  10. package/dist/public/assets/NewProjectDialog-DTZfXXpH.js +1 -0
  11. package/dist/public/assets/{NotebookWidget-Cwd77EGL.js → NotebookWidget-D2ddZny7.js} +1 -1
  12. package/dist/public/assets/{PaneEditorBody-RaUBrZPu.js → PaneEditorBody-DM3RxU9y.js} +6 -6
  13. package/dist/public/assets/PdfViewer-BR_qnX0w.js +2 -0
  14. package/dist/public/assets/PdfViewer-Re37jQgv.css +1 -0
  15. package/dist/public/assets/SettingsDialog-DK_xpwwR.js +8 -0
  16. package/dist/public/assets/{Terminal-_10Xyj1h.js → Terminal-C56yFFee.js} +3 -3
  17. package/dist/public/assets/Workspace-DJGOiast.js +20 -0
  18. package/dist/public/assets/{api-i6xNY3bF.js → api-CfmzEbQ_.js} +1 -1
  19. package/dist/public/assets/{auth-GfOuXpIe.js → auth-CIb9G2C5.js} +1 -1
  20. package/dist/public/assets/{buffer-store-eMnMxbpI.js → buffer-store-JDgXuYJp.js} +1 -1
  21. package/dist/public/assets/chevron-right-BRjnLYaO.js +1 -0
  22. package/dist/public/assets/command-BUOkDmUW.js +1 -0
  23. package/dist/public/assets/{context-DW21k43a.js → context-CwZ4epwz.js} +1 -1
  24. package/dist/public/assets/context-menu-D-5BvS0X.js +1 -0
  25. package/dist/public/assets/dist-CBag2On7.js +1 -0
  26. package/dist/public/assets/dist-CcLyf3-2.js +1 -0
  27. package/dist/public/assets/{errors-O9DWXa3f.js → errors-DTaodZDR.js} +1 -1
  28. package/dist/public/assets/{forward-link-RM7_5Shu.js → forward-link-C-8Xn8gf.js} +1 -1
  29. package/dist/public/assets/{hotkeys-1uTWFYAL.js → hotkeys-DOpJ1a7g.js} +1 -1
  30. package/dist/public/assets/{index-np8JXeG6.js → index-B_fYaxIG.js} +3 -3
  31. package/dist/public/assets/index-ChK3zzci.css +2 -0
  32. package/dist/public/assets/{markdown-mermaid-CNYDlgGt.js → markdown-mermaid-BVt1aqNY.js} +1 -1
  33. package/dist/public/assets/media-refresh-store-DDvrEM5K.js +1 -0
  34. package/dist/public/assets/{notification-delivery-Dfvdt_1U.js → notification-delivery-DhFtFhEH.js} +1 -1
  35. package/dist/public/assets/popover-CtxJVkPi.js +1 -0
  36. package/dist/public/assets/{protocol-support-BGmIChNK.js → protocol-support-BGk73LFk.js} +1 -1
  37. package/dist/public/assets/{scroll-restoration-OVgiE4G9.js → scroll-restoration-xYrqc2k4.js} +1 -1
  38. package/dist/public/assets/select-9OADuw7W.js +1 -0
  39. package/dist/public/assets/{selection-actions-D875GPFU.js → selection-actions--OSfjvlG.js} +1 -1
  40. package/dist/public/assets/{session-order-f7QxTbVD.js → session-order-SN_zG4Us.js} +1 -1
  41. package/dist/public/assets/switch-iVuj74VW.js +1 -0
  42. package/dist/public/assets/use-ui-state-DEsKtleW.js +1 -0
  43. package/dist/public/assets/{ws-CMPCIzY4.js → ws-CspBmo8M.js} +1 -1
  44. package/dist/public/index.html +3 -3
  45. package/dist/pudl.js +21 -1
  46. package/package.json +1 -1
  47. package/dist/public/assets/App-CNB4a07v.js +0 -2
  48. package/dist/public/assets/Dashboard-v3OproVW.js +0 -1
  49. package/dist/public/assets/LazyTerminal-CgQryH0p.js +0 -2
  50. package/dist/public/assets/NewProjectDialog-BT8rR4yn.js +0 -1
  51. package/dist/public/assets/PdfViewer-Bppu4-0-.js +0 -2
  52. package/dist/public/assets/SettingsDialog-CaHklYzG.js +0 -8
  53. package/dist/public/assets/Workspace-GgVr1uYN.js +0 -20
  54. package/dist/public/assets/command-D7m0dmA-.js +0 -1
  55. package/dist/public/assets/context-menu-CMWkmDu6.js +0 -1
  56. package/dist/public/assets/disclosure-CHXbNzgZ.js +0 -1
  57. package/dist/public/assets/dist-C_x5-hi8.js +0 -1
  58. package/dist/public/assets/dist-Ds3438NL.js +0 -1
  59. package/dist/public/assets/index-CPHfr3MU.css +0 -2
  60. package/dist/public/assets/input-CxgRsoVg.js +0 -1
  61. package/dist/public/assets/media-refresh-store-Bu4kWCGq.js +0 -1
  62. package/dist/public/assets/popover-CCHRaCvX.js +0 -1
  63. package/dist/public/assets/select-Bg0rWqco.js +0 -1
  64. package/dist/public/assets/switch-DhNyUV8C.js +0 -1
  65. package/dist/public/assets/use-ui-state-CHqXhyx4.js +0 -1
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/SettingsDialog-CaHklYzG.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/auth-GfOuXpIe.js","assets/LazyTerminal-CgQryH0p.js","assets/jsx-runtime-By8HlURe.js","assets/preload-helper-Czpn1I53.js","assets/dialog-BMWRC2HO.js","assets/react-dom-cJyBB_A4.js","assets/x-DCpy1q13.js","assets/createLucideIcon-DyMAgLa3.js","assets/input-CxgRsoVg.js","assets/notification-delivery-Dfvdt_1U.js","assets/api-i6xNY3bF.js","assets/hotkeys-1uTWFYAL.js","assets/protocol-support-BGmIChNK.js","assets/switch-DhNyUV8C.js","assets/dist-Cde1E3eV.js","assets/client-settings-CwqpIric.js","assets/index-np8JXeG6.js","assets/index-CPHfr3MU.css","assets/dist-BOS6OKSE.js","assets/button-BgeBH2Uc.js","assets/select-Bg0rWqco.js","assets/chevron-down--sjpQEHH.js","assets/dist-Ds3438NL.js","assets/code-DRWf9a5s.js","assets/rotate-ccw-CNjR2LSi.js","assets/errors-O9DWXa3f.js","assets/use-debounced-value-C86N-mOK.js","assets/popover-CCHRaCvX.js","assets/disclosure-CHXbNzgZ.js","assets/Dashboard-v3OproVW.js","assets/session-order-f7QxTbVD.js","assets/context-menu-CMWkmDu6.js","assets/dist-C_x5-hi8.js","assets/NewProjectDialog-BT8rR4yn.js","assets/ws-CMPCIzY4.js","assets/Workspace-GgVr1uYN.js","assets/forward-link-RM7_5Shu.js","assets/media-refresh-store-Bu4kWCGq.js","assets/use-ui-state-CHqXhyx4.js","assets/preview-kind-DiWpvEc0.js","assets/debounce-B9DrqirV.js","assets/whole-word-2m2pmAFT.js","assets/selection-actions-D875GPFU.js","assets/copy-CGsu8426.js","assets/drafts-B_tChlzR.js","assets/buffer-logic-BAkSBQT7.js","assets/scroll-restoration-OVgiE4G9.js","assets/Workspace-DdL3ODEC.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{t as n}from"./react-dom-cJyBB_A4.js";import{P as r,U as i,W as a,f as o,j as s,o as c,r as l,x as u}from"./auth-GfOuXpIe.js";import{a as d,c as f,o as p}from"./LazyTerminal-CgQryH0p.js";import{a as m,d as h,f as g,g as _,h as v,i as y,l as b,m as x,o as S,s as C,t as w,u as T}from"./notification-delivery-Dfvdt_1U.js";import{i as E,r as D,t as O}from"./client-settings-CwqpIric.js";import{t as ee}from"./jsx-runtime-By8HlURe.js";import{t as k}from"./preload-helper-Czpn1I53.js";import{a as A,n as te,o as ne,r as re,t as j}from"./index-np8JXeG6.js";import{n as ie}from"./api-i6xNY3bF.js";import{_ as M,d as ae,g as N,h as oe,i as se,l as ce,m as le,o as ue,p as de,r as fe,s as pe,u as me,v as he}from"./hotkeys-1uTWFYAL.js";import{t as ge}from"./forward-link-RM7_5Shu.js";import{$ as _e,At as ve,B as ye,Bt as be,C as xe,Ct as Se,Dt as Ce,E as we,F as Te,Ft as Ee,H as De,Ht as Oe,It as ke,J as Ae,K as je,L as Me,Lt as P,M as Ne,Mt as Pe,Nt as Fe,Pt as Ie,Q as Le,Rt as Re,T as ze,Tt as Be,Vt as Ve,Z as He,_t as Ue,at as We,b as Ge,et as Ke,it as qe,j as Je,jt as F,o as Ye,ot as Xe,pt as Ze,q as Qe,rt as $e,st as et,v as tt,w as nt,wt as rt,x as it,y as at,zt as ot}from"./protocol-support-BGmIChNK.js";import{a as st,c as ct,d as I,f as lt,h as ut,l as dt,m as ft,o as pt,p as mt,r as ht,u as gt}from"./session-order-f7QxTbVD.js";import{n as L,t as _t}from"./dist-BOS6OKSE.js";import{n as R}from"./x-DCpy1q13.js";import{n as vt,t as z}from"./input-CxgRsoVg.js";import{n as yt,r as B}from"./dist-Cde1E3eV.js";import{$ as bt,G as xt,H as St,J as Ct,K as wt,Q as Tt,U as Et,W as Dt,X as Ot,Y as kt,at as V,d as At,et as jt,f as Mt,h as H,i as Nt,it as Pt,m as Ft,nt as U,p as It,q as Lt,r as Rt,rt as W,t as zt,tt as Bt}from"./use-ui-state-CHqXhyx4.js";import{t as G}from"./button-BgeBH2Uc.js";import{t as K}from"./createLucideIcon-DyMAgLa3.js";import{c as Vt,i as Ht,s as Ut,t as Wt,u as Gt}from"./switch-DhNyUV8C.js";import{t as Kt}from"./copy-CGsu8426.js";import{t as qt}from"./NewProjectDialog-BT8rR4yn.js";import{n as q}from"./errors-O9DWXa3f.js";import{t as J}from"./ws-CMPCIzY4.js";import{a as Jt,c as Yt,i as Xt,n as Zt,o as Qt,r as $t,s as en}from"./command-D7m0dmA-.js";import{n as tn,r as nn,t as rn}from"./popover-CCHRaCvX.js";var Y=e(t(),1),X=ee();function an(){let[e,t]=(0,Y.useState)(`Opening forwarded application…`);return(0,Y.useEffect)(()=>{if(!/^\/forward\/([^/]+)\/(\d+)$/.exec(window.location.pathname)){t(`This forwarding link is invalid.`);return}let e=!0;return ge(new URL(window.location.href)).then(t=>{e&&window.location.replace(t)}).catch(()=>{e&&t(`The application is unavailable. Reconnect to Puddle and open this link again.`)}),()=>{e=!1}},[]),(0,X.jsx)(`p`,{className:`p-8 text-sm text-fg-secondary`,children:e})}var on=class extends Oe{constructor(e={}){super(),this.config=e,this.#e=new Set,this.#t=new Map,this.#n=0}#e;#t;#n;build(e,t,n){let r=new Be({client:e,mutationCache:this,mutationId:++this.#n,options:e.defaultMutationOptions(t),state:n});return this.add(r),r}add(e){this.#e.add(e);let t=sn(e);if(typeof t==`string`){let n=this.#t.get(t);n?n.push(e):this.#t.set(t,[e])}this.notify({type:`added`,mutation:e})}remove(e){if(this.#e.delete(e)){let t=sn(e);if(typeof t==`string`){let n=this.#t.get(t);if(n)if(n.length>1){let t=n.indexOf(e);t!==-1&&n.splice(t,1)}else n[0]===e&&this.#t.delete(t)}}this.notify({type:`removed`,mutation:e})}canRun(e){let t=sn(e);if(typeof t==`string`){let n=this.#t.get(t)?.find(e=>e.state.status===`pending`);return!n||n===e}else return!0}runNext(e){let t=sn(e);return typeof t==`string`?(this.#t.get(t)?.find(t=>t!==e&&t.state.isPaused))?.continue()??Promise.resolve():Promise.resolve()}clear(){F.batch(()=>{this.#e.forEach(e=>{this.notify({type:`removed`,mutation:e})}),this.#e.clear(),this.#t.clear()})}getAll(){return Array.from(this.#e)}find(e){let t={exact:!0,...e};return this.getAll().find(e=>Ee(t,e))}findAll(e={}){return this.getAll().filter(t=>Ee(e,t))}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}resumePausedMutations(){let e=this.getAll().filter(e=>e.state.isPaused);return F.batch(()=>Promise.all(e.map(e=>e.continue().catch(P))))}};function sn(e){return e.options.scope?.id}var cn=class extends Oe{constructor(e={}){super(),this.config=e,this.#e=new Map}#e;build(e,t,n){let r=t.queryKey,i=t.queryHash??Ie(r,t),a=this.get(i);return a||(a=new Ce({client:e,queryKey:r,queryHash:i,options:e.defaultQueryOptions(t),state:n,defaultOptions:e.getQueryDefaults(r)}),this.add(a)),a}add(e){this.#e.has(e.queryHash)||(this.#e.set(e.queryHash,e),this.notify({type:`added`,query:e}))}remove(e){let t=this.#e.get(e.queryHash);t&&(e.destroy(),t===e&&this.#e.delete(e.queryHash),this.notify({type:`removed`,query:e}))}clear(){F.batch(()=>{this.getAll().forEach(e=>{this.remove(e)})})}get(e){return this.#e.get(e)}getAll(){return[...this.#e.values()]}find(e){let t={exact:!0,...e};return this.getAll().find(e=>ke(t,e))}findAll(e={}){let t=this.getAll();return Object.keys(e).length>0?t.filter(t=>ke(e,t)):t}notify(e){F.batch(()=>{this.listeners.forEach(t=>{t(e)})})}onFocus(){F.batch(()=>{this.getAll().forEach(e=>{e.onFocus()})})}onOnline(){F.batch(()=>{this.getAll().forEach(e=>{e.onOnline()})})}},ln=class{#e;#t;#n;#r;#i;#a;#o;#s;constructor(e={}){this.#e=e.queryCache||new cn,this.#t=e.mutationCache||new on,this.#n=e.defaultOptions||{},this.#r=new Map,this.#i=new Map,this.#a=0}mount(){this.#a++,this.#a===1&&(this.#o=Ve.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onFocus())}),this.#s=ve.subscribe(async e=>{e&&(await this.resumePausedMutations(),this.#e.onOnline())}))}unmount(){this.#a--,this.#a===0&&(this.#o?.(),this.#o=void 0,this.#s?.(),this.#s=void 0)}isFetching(e){return this.#e.findAll({...e,fetchStatus:`fetching`}).length}isMutating(e){return this.#t.findAll({...e,status:`pending`}).length}getQueryData(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state.data}ensureQueryData(e){let t=this.defaultQueryOptions(e),n=this.#e.build(this,t),r=n.state.data;return r===void 0?this.fetchQuery(e):(e.revalidateIfStale&&n.isStaleByTime(ot(t.staleTime,n))&&this.prefetchQuery(t),Promise.resolve(r))}getQueriesData(e){return this.#e.findAll(e).map(({queryKey:e,state:t})=>[e,t.data])}setQueryData(e,t,n){let r=this.defaultQueryOptions({queryKey:e}),i=this.#e.get(r.queryHash)?.state.data,a=Pe(t,i);if(a!==void 0)return this.#e.build(this,r).setData(a,{...n,manual:!0})}setQueriesData(e,t,n){return F.batch(()=>this.#e.findAll(e).map(({queryKey:e})=>[e,this.setQueryData(e,t,n)]))}getQueryState(e){let t=this.defaultQueryOptions({queryKey:e});return this.#e.get(t.queryHash)?.state}removeQueries(e){let t=this.#e;F.batch(()=>{t.findAll(e).forEach(e=>{t.remove(e)})})}resetQueries(e,t){let n=this.#e;return F.batch(()=>(n.findAll(e).forEach(e=>{e.reset()}),this.refetchQueries({type:`active`,...e},t)))}cancelQueries(e,t={}){let n={revert:!0,...t},r=F.batch(()=>this.#e.findAll(e).map(e=>e.cancel(n)));return Promise.all(r).then(P).catch(P)}invalidateQueries(e,t={}){return F.batch(()=>(this.#e.findAll(e).forEach(e=>{e.invalidate()}),e?.refetchType===`none`?Promise.resolve():this.refetchQueries({...e,type:e?.refetchType??e?.type??`active`},t)))}refetchQueries(e,t={}){let n={...t,cancelRefetch:t.cancelRefetch??!0},r=F.batch(()=>this.#e.findAll(e).filter(e=>!e.isDisabled()&&!e.isStatic()).map(e=>{let t=e.fetch(void 0,n);return n.throwOnError||(t=t.catch(P)),e.state.fetchStatus===`paused`?Promise.resolve():t}));return Promise.all(r).then(P)}fetchQuery(e){let t=this.defaultQueryOptions(e);t.retry===void 0&&(t.retry=!1);let n=this.#e.build(this,t);return n.isStaleByTime(ot(t.staleTime,n))?n.fetch(t):Promise.resolve(n.state.data)}prefetchQuery(e){return this.fetchQuery(e).then(P).catch(P)}fetchInfiniteQuery(e){return e._type=`infinite`,this.fetchQuery(e)}prefetchInfiniteQuery(e){return this.fetchInfiniteQuery(e).then(P).catch(P)}ensureInfiniteQueryData(e){return e._type=`infinite`,this.ensureQueryData(e)}resumePausedMutations(){return ve.isOnline()?this.#t.resumePausedMutations():Promise.resolve()}getQueryCache(){return this.#e}getMutationCache(){return this.#t}getDefaultOptions(){return this.#n}setDefaultOptions(e){this.#n=e}setQueryDefaults(e,t){this.#r.set(Fe(e),{queryKey:e,defaultOptions:t})}getQueryDefaults(e){let t=[...this.#r.values()],n={};return t.forEach(t=>{Re(e,t.queryKey)&&Object.assign(n,t.defaultOptions)}),n}setMutationDefaults(e,t){this.#i.set(Fe(e),{mutationKey:e,defaultOptions:t})}getMutationDefaults(e){let t=[...this.#i.values()],n={};return t.forEach(t=>{Re(e,t.mutationKey)&&Object.assign(n,t.defaultOptions)}),n}defaultQueryOptions(e){if(e._defaulted)return e;let t={...this.#n.queries,...this.getQueryDefaults(e.queryKey),...e,_defaulted:!0};return t.queryHash||=Ie(t.queryKey,t),t.refetchOnReconnect===void 0&&(t.refetchOnReconnect=t.networkMode!==`always`),t.throwOnError===void 0&&(t.throwOnError=!!t.suspense),!t.networkMode&&t.persister&&(t.networkMode=`offlineFirst`),t.queryFn===be&&(t.enabled=!1),t}defaultMutationOptions(e){return e?._defaulted?e:{...this.#n.mutations,...e?.mutationKey&&this.getMutationDefaults(e.mutationKey),...e,_defaulted:!0}}clear(){this.#e.clear(),this.#t.clear()}},un=class extends Y.Component{state={error:null};static getDerivedStateFromError(e){return{error:e}}componentDidUpdate(e){this.state.error!==null&&e.resetOn!==this.props.resetOn&&this.setState({error:null})}componentDidCatch(e,t){console.error(`Puddle: the ${this.props.scope} crashed`,e,t.componentStack)}render(){let{error:e}=this.state;return e===null?this.props.children:(0,X.jsxs)(`div`,{className:`flex h-full min-h-40 flex-col items-center justify-center gap-4 px-8 py-10 text-center`,children:[(0,X.jsxs)(`p`,{className:`text-sm text-fg`,children:[`The `,this.props.scope,` stopped rendering.`]}),(0,X.jsx)(`p`,{className:`max-w-lg font-mono text-2xs leading-relaxed text-interrupted`,children:e.message||String(e)}),(0,X.jsx)(`p`,{className:`max-w-sm text-2xs leading-relaxed text-fg-muted`,children:`Your sessions and their worktrees are on the daemon and untouched; the layout is saved. The console has the full stack.`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-4`,children:[(0,X.jsx)(`button`,{type:`button`,onClick:()=>this.setState({error:null}),className:`text-2xs font-medium text-fg-gold transition-colors hover:underline`,children:`Try again`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>window.location.reload(),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Reload`})]})]})}};function dn(){return(0,X.jsx)(_t,{theme:(0,Y.useSyncExternalStore)(A,re),position:`bottom-right`,toastOptions:{style:{background:`var(--bg-elevated)`,border:`none`,boxShadow:`0 8px 30px rgb(0 0 0 / 0.25)`,color:`var(--text-primary)`},classNames:{description:`whitespace-pre-wrap break-words font-mono text-2xs leading-snug max-h-40 overflow-y-auto`}}})}function fn(){return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-24`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-3 text-sm leading-relaxed text-fg-secondary`,children:[(0,X.jsxs)(`p`,{children:[`Authorise this browser by running`,` `,(0,X.jsx)(`span`,{className:`font-mono text-accent`,children:`puddle launch`}),` in a terminal.`]}),(0,X.jsx)(`p`,{children:`Use the link it opens. Your sessions, drafts and layouts stay in place.`})]})]})})}var pn=e(n(),1),mn=`a, button, [role="button"], [role="slider"], input, select, textarea, summary, label, [onclick], .cursor-pointer`,hn=`.monaco-editor`;function gn(e,t){return e?.closest(hn)&&!e.closest(t)?`text`:e?.closest(mn)?`interactive`:`default`}function _n(e,t=`.no-custom-caret`){(0,Y.useEffect)(()=>{let n=e.current;if(!n)return;let r=window.matchMedia(`(pointer: fine)`),i=()=>{n.style.opacity=`0`},a=e=>{if(e.pointerType===`touch`||!r.matches){i();return}n.style.transform=`translate3d(${e.clientX}px, ${e.clientY}px, 0) translate(-50%, -50%)`;let a=e.target instanceof Element?e.target:null;if(a instanceof HTMLIFrameElement){i();return}n.style.opacity=`1`;let o=a?.closest(hn),s=gn(a,t),c=s===`text`,l=s===`interactive`,u=c;if(c&&o){let e=getComputedStyle(o);n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`)}else if(!l&&a&&!a.closest(t)&&Array.from(a.childNodes).some(e=>e.nodeType===Node.TEXT_NODE&&e.textContent?.trim())){let e=getComputedStyle(a);e.userSelect!==`none`&&(u=!0,n.style.setProperty(`--custom-cursor-caret-height`,`${Math.round(Number.parseFloat(e.fontSize)*1.3)}px`))}n.classList.toggle(`is-interactive`,l),n.classList.toggle(`is-text`,u)};return window.addEventListener(`pointermove`,a,{passive:!0}),document.documentElement.addEventListener(`pointerleave`,i),window.addEventListener(`blur`,i),()=>{window.removeEventListener(`pointermove`,a),document.documentElement.removeEventListener(`pointerleave`,i),window.removeEventListener(`blur`,i)}},[t,e])}var vn=[`top`,`right`,`bottom`,`left`];function yn(){let e=(0,Y.useRef)(null);return _n(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor drafting-cursor`,"aria-hidden":`true`,children:vn.map(e=>(0,X.jsx)(`span`,{className:`drafting-cursor-tick`,"data-side":e},e))})}function bn(){let e=(0,Y.useRef)(null);return _n(e),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor invert-cursor`,"aria-hidden":`true`})}var xn=`h1, h2, h3, h4, h5, h6, .no-rangefinder-caret`,Z=40.5,Q=4.05,Sn=Q*Math.sqrt(3)/2;function Cn(){let e=[],t=[],n=Z/2,r=Math.ceil(n/Sn)+1,i=e=>Math.round(e*100)/100,a=e=>`M${e.map(([e,t])=>`${i(e)} ${i(t)}`).join(`L`)}Z`;for(let i=-r;i<r;i+=1){let o=n+i*Sn,s=o+Sn,c=(i%2+2)%2*(Q/2);for(let i=-r;i<r;i+=1){let r=n+i*Q+c,l=[[r+Q/2,o],[r,s],[r+Q,s]],u=[[r+Q/2,o],[r+3*Q/2,o],[r+Q,s]],d=e=>{let t=e.map(([e])=>e),n=e.map(([,e])=>e);return Math.max(...t)>0&&Math.min(...t)<Z&&Math.max(...n)>0&&Math.min(...n)<Z};d(l)&&e.push(a(l)),d(u)&&t.push(a(u))}}return{light:e.join(``),dark:t.join(``)}}var wn=Cn();function Tn(){let e=(0,Y.useRef)(null);return _n(e,xn),(0,X.jsx)(`div`,{ref:e,className:`custom-cursor rangefinder-cursor`,"aria-hidden":`true`,children:(0,X.jsxs)(`svg`,{className:`rangefinder-cursor-facets`,viewBox:`0 0 ${Z} ${Z}`,focusable:`false`,children:[(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-light`,d:wn.light}),(0,X.jsx)(`path`,{className:`rangefinder-cursor-facet-dark`,d:wn.dark})]})})}function En(){let{cursorPackage:e}=E(),t=null;switch(e){case`rangefinder`:t=(0,X.jsx)(Tn,{});break;case`drafting`:t=(0,X.jsx)(yn,{});break;case`invert`:t=(0,X.jsx)(bn,{});break;case`system`:return null}return(0,pn.createPortal)(t,document.body)}var Dn=K(`corner-down-left`,[[`path`,{d:`M20 4v7a4 4 0 0 1-4 4H4`,key:`6o5b7l`}],[`path`,{d:`m9 10-5 5 5 5`,key:`1kshq7`}]]),On=K(`layout-template`,[[`rect`,{width:`18`,height:`7`,x:`3`,y:`3`,rx:`1`,key:`f1a2em`}],[`rect`,{width:`9`,height:`7`,x:`3`,y:`14`,rx:`1`,key:`jqznyg`}],[`rect`,{width:`5`,height:`7`,x:`16`,y:`14`,rx:`1`,key:`q5h2i8`}]]),kn=K(`monitor-cog`,[[`path`,{d:`M12 17v4`,key:`1riwvh`}],[`path`,{d:`m14.305 7.53.923-.382`,key:`1mlnsw`}],[`path`,{d:`m15.228 4.852-.923-.383`,key:`82mpwg`}],[`path`,{d:`m16.852 3.228-.383-.924`,key:`ln4sir`}],[`path`,{d:`m16.852 8.772-.383.923`,key:`1dejw0`}],[`path`,{d:`m19.148 3.228.383-.924`,key:`192kgf`}],[`path`,{d:`m19.53 9.696-.382-.924`,key:`fiavlr`}],[`path`,{d:`m20.772 4.852.924-.383`,key:`1j8mgp`}],[`path`,{d:`m20.772 7.148.924.383`,key:`zix9be`}],[`path`,{d:`M22 13v2a2 2 0 0 1-2 2H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h7`,key:`1tnzv8`}],[`path`,{d:`M8 21h8`,key:`1ev6f3`}],[`circle`,{cx:`18`,cy:`6`,r:`3`,key:`1h7g24`}]]),An=K(`notebook-pen`,[[`path`,{d:`M13.4 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-7.4`,key:`re6nr2`}],[`path`,{d:`M2 6h4`,key:`aawbzj`}],[`path`,{d:`M2 10h4`,key:`l0bgd4`}],[`path`,{d:`M2 14h4`,key:`1gsvsf`}],[`path`,{d:`M2 18h4`,key:`1bu2t1`}],[`path`,{d:`M21.378 5.626a1 1 0 1 0-3.004-3.004l-5.01 5.012a2 2 0 0 0-.506.854l-.837 2.87a.5.5 0 0 0 .62.62l2.87-.837a2 2 0 0 0 .854-.506z`,key:`pqwjuv`}]]),jn=K(`save`,[[`path`,{d:`M15.2 3a2 2 0 0 1 1.4.6l3.8 3.8a2 2 0 0 1 .6 1.4V19a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2z`,key:`1c8476`}],[`path`,{d:`M17 21v-7a1 1 0 0 0-1-1H8a1 1 0 0 0-1 1v7`,key:`1ydtos`}],[`path`,{d:`M7 3v4a1 1 0 0 0 1 1h7`,key:`t51u73`}]]),Mn=K(`settings-2`,[[`path`,{d:`M14 17H5`,key:`gfn3mx`}],[`path`,{d:`M19 7h-9`,key:`6i9tg`}],[`circle`,{cx:`17`,cy:`17`,r:`3`,key:`18b49y`}],[`circle`,{cx:`7`,cy:`7`,r:`3`,key:`dfmy0x`}]]),Nn=K(`settings`,[[`path`,{d:`M9.671 4.136a2.34 2.34 0 0 1 4.659 0 2.34 2.34 0 0 0 3.319 1.915 2.34 2.34 0 0 1 2.33 4.033 2.34 2.34 0 0 0 0 3.831 2.34 2.34 0 0 1-2.33 4.033 2.34 2.34 0 0 0-3.319 1.915 2.34 2.34 0 0 1-4.659 0 2.34 2.34 0 0 0-3.32-1.915 2.34 2.34 0 0 1-2.33-4.033 2.34 2.34 0 0 0 0-3.831A2.34 2.34 0 0 1 6.35 6.051a2.34 2.34 0 0 0 3.319-1.915`,key:`1i5ecw`}],[`circle`,{cx:`12`,cy:`12`,r:`3`,key:`1v7zrd`}]]);function Pn(){let e=We(),t=Ne(),[n,i]=(0,Y.useState)(``),[a,o]=(0,Y.useState)(r),s=()=>{n.trim()&&t.mutate({name:n.trim(),branch_prefix:a.trim()},{onSuccess:e=>oe(e.id)})},c=(e.data?.length??0)>0;return(0,X.jsx)(`div`,{className:`flex min-h-screen items-center justify-center bg-ground`,children:(0,X.jsxs)(`div`,{className:`flex w-full max-w-md flex-col gap-10 px-8 pb-16`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-2`,children:[(0,X.jsx)(`h1`,{className:`font-mono text-2xl font-semibold text-fg`,children:`Puddle`}),(0,X.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Who is working?`})]}),c&&(0,X.jsx)(`div`,{className:`flex flex-col`,children:e.data.map(e=>(0,X.jsxs)(`button`,{onClick:()=>oe(e.id),className:`flex items-center gap-3 rounded-md px-3 py-2.5 text-left transition-colors hover:bg-elevated active:bg-border/70`,children:[(0,X.jsx)(g,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,X.jsx)(`span`,{className:R(`text-base`,d(e.icon_colour)||`text-fg`),children:e.name}),e.branch_prefix&&(0,X.jsxs)(`span`,{className:`ml-auto text-2xs text-fg-muted`,children:[e.branch_prefix,`…`]})]},e.id))}),(0,X.jsxs)(`form`,{className:`flex flex-col gap-5`,onSubmit:e=>{e.preventDefault(),s()},children:[c&&(0,X.jsx)(`p`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`or create a profile`}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(f,{htmlFor:`profile-name`,children:`Name`}),(0,X.jsx)(z,{id:`profile-name`,placeholder:`e.g. alice`,value:n,onChange:e=>i(e.target.value),className:`h-10`,autoFocus:!c})]}),(0,X.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,X.jsx)(f,{htmlFor:`branch-prefix`,children:`Branch prefix`}),(0,X.jsx)(z,{id:`branch-prefix`,placeholder:`no prefix`,value:a,onChange:e=>o(e.target.value),className:`h-10`})]}),t.error&&(0,X.jsx)(`p`,{className:`text-xs text-danger`,children:t.error.message}),(0,X.jsx)(G,{type:`submit`,size:`lg`,className:`self-start px-6`,disabled:!n.trim()||t.isPending,children:`Create profile`})]})]})})}var Fn=new class{transport;reload;pause;phase=`idle`;pending=null;constructor(e=fetch,t=()=>window.location.reload(),n=e=>new Promise(t=>setTimeout(t,e))){this.transport=e,this.reload=t,this.pause=n}refresh(e=12e4){return this.pending||=this.run(e).finally(()=>{this.pending=null}),this.pending}async run(e){this.phase=`requesting`;let t={authorization:`Bearer ${l.get()??``}`,"content-type":`application/json`};try{let n=await this.transport(`/cockpit/refresh`,{method:`POST`,headers:t,signal:AbortSignal.timeout(1e4),body:JSON.stringify({refreshId:crypto.randomUUID()})});if(n.status!==202)throw Error(`refresh rejected`);let r=u.parse(await n.json());this.phase=`waiting`;let i=Date.now()+e;for(;Date.now()<i;){await this.pause(1e3);try{let e=await this.transport(`/cockpit/status`,{headers:t,cache:`no-store`,signal:AbortSignal.timeout(3e3)});if(!e.ok)continue;let n=o.parse(await e.json());if(n.instance===r.instance||n.refreshId!==r.refreshId||n.upstream!==`ready`)continue;return this.phase=`complete`,this.reload(),!0}catch{}}}catch{}return this.phase=`failed`,!1}},In=null;function Ln(e){return In=e,()=>{In===e&&(In=null)}}function Rn(){In?.()}var zn=new Set;function Bn(){return[...zn].flatMap(e=>e())}function Vn({onNewSession:e,onNewProject:t}){let[n,r]=(0,Y.useState)(!1),[i,a]=(0,Y.useState)(`commands`),[o,s]=(0,Y.useState)(``),[c,l]=(0,Y.useState)(null),[u,d]=(0,Y.useState)(!1),f=ft(),p=ut(),m=N(),h=p.id,g=et(m??void 0),_=qe(m??void 0),y=Ue(h),b=kt();(0,Y.useEffect)(()=>me(`palette.toggle`,()=>r(e=>!e)),[]),(0,Y.useEffect)(()=>bt(()=>r(!0)),[]),(0,Y.useEffect)(()=>{n||(a(`commands`),s(``),l(null),d(!1))},[n]);let S=(0,Y.useMemo)(()=>{let n=[],r=ht((g.data??[]).filter(e=>!e.archived),_.data?.projectOrder??[]);for(let e of r)n.push({id:`project-${e.id}`,group:`Projects`,label:e.name,icon:pt,keywords:`switch project open`,run:()=>void f(`/project/${e.id}`)});for(let e of y.data??[])e.status!==`archived`&&n.push({id:`session-${e.id}`,group:`Sessions`,label:b(e),icon:st,keywords:`switch session ${e.branch}`,run:()=>void f(`/project/${e.project_id}/session/${e.id}`)});return h!==void 0&&e&&n.push({id:`new-agent`,group:`Actions`,label:`New agent`,icon:Gt,keywords:`new agent create start session`,run:()=>e()},{id:`new-terminal`,group:`Actions`,label:`New terminal`,icon:st,keywords:`new terminal create start shell session`,run:()=>e({kind:`terminal`})}),h!==void 0&&n.push({id:`open-path`,group:`Actions`,label:`Open path`,icon:pt,keywords:`open path file directory folder editor tree browse absolute relative home`,closeOnRun:!1,run:()=>{s(``),l(null),a(`path`)}}),t&&n.push({id:`new-project`,group:`Actions`,label:`New project`,icon:B,keywords:`new project open create repository repo workspace`,run:t}),n.push({id:`theme-dark`,group:`Theme`,label:`Switch theme: dark`,icon:v,keywords:`switch theme dark appearance`,run:()=>void j(`dark`)},{id:`theme-light`,group:`Theme`,label:`Switch theme: light`,icon:x,keywords:`switch theme light appearance`,run:()=>void j(`light`)},{id:`theme-system`,group:`Theme`,label:`Switch theme: system`,icon:kn,keywords:`switch theme system appearance`,run:()=>void j(`system`)},{id:`open-settings`,group:`Actions`,label:`Settings`,icon:Nn,keywords:`open settings preferences options configure`,run:()=>Ht()},{id:`switch-profile`,group:`Actions`,label:`Switch profile`,icon:Ut,keywords:`switch profile identity user change`,run:()=>le.set(null)},{id:`refresh-connection`,group:`Actions`,label:`Refresh connection`,icon:Vt,keywords:`refresh connection reconnect restart cockpit tunnel ssh daemon`,run:()=>Rn()}),[...n,...Bn()]},[g.data,_.data?.projectOrder,y.data,h,f,e,t,b]),C=(0,Y.useMemo)(()=>{let e=new Map;for(let t of S){let n=e.get(t.group)??[];n.push(t),e.set(t.group,n)}return[...e.entries()]},[S]),w=async()=>{let e=o.trim();if(!(e===``||u)){d(!0),l(null);try{await Ot(e),r(!1)}catch(e){l(e instanceof Error?e.message:`Could not open that path.`)}finally{d(!1)}}};return(0,X.jsxs)(Zt,{open:n,onOpenChange:r,children:[(0,X.jsx)(Jt,{value:o,onValueChange:e=>{s(e),l(null)},placeholder:i===`path`?`Enter a path…`:`Type a command or search…`,onKeyDown:e=>{i===`path`&&(e.key===`Enter`?(e.preventDefault(),e.stopPropagation(),w()):e.key===`Escape`&&(e.preventDefault(),e.stopPropagation(),a(`commands`),s(``),l(null)))}}),i===`path`?(0,X.jsx)(en,{children:(0,X.jsxs)(`div`,{className:`px-3 py-3 text-xs text-fg-muted`,children:[(0,X.jsx)(`p`,{children:`Relative paths start from the bound worktree or project. Absolute and ~ paths work too.`}),(0,X.jsx)(`p`,{className:c?`mt-2 text-danger`:`mt-2`,"aria-live":`polite`,children:c??(u?`Opening…`:`Press Enter to open.`)})]})}):(0,X.jsxs)(en,{children:[(0,X.jsx)($t,{children:`Nothing matches.`}),C.map(([e,t])=>(0,X.jsx)(Xt,{heading:e,children:t.map(e=>{let t=e.icon;return(0,X.jsxs)(Qt,{value:`${e.label} ${e.keywords??``}`,onSelect:()=>{e.closeOnRun!==!1&&r(!1),e.run()},children:[t&&(0,X.jsx)(t,{}),e.label,e.shortcut&&(0,X.jsx)(Yt,{children:e.shortcut})]},e.id)})},e))]})]})}function Hn(){let e=document.activeElement;return e instanceof Element&&e.closest(`.xterm`)!==null}function Un(){let e=document.activeElement;return e instanceof Element&&e.closest(`.monaco-editor`)!==null}function Wn(){let e=qe(N()??void 0).data?.hotkeys;return(0,Y.useEffect)(()=>{ae(e&&typeof e==`object`?e:void 0)},[e]),(0,Y.useEffect)(()=>me(`window.close`,()=>{let e=M();e?.closeWindow?e.closeWindow():window.close()}),[]),(0,Y.useEffect)(()=>{let e=e=>{let t=se(e);if(!t)return;let n=fe(t);if(!n)return;let r=ue(n);if(!r||!ce(r,Un()))return;let i=pe(n);i&&(e.preventDefault(),e.stopPropagation(),i())},t=e=>{let t=se(e);if(!t)return;let n=fe(t);if(!n)return;let r=ue(n);if(!r||r.editor&&Un()||r.deferInTerminal&&Hn())return;let i=pe(n);i&&(e.preventDefault(),i())};return window.addEventListener(`keydown`,e,!0),window.addEventListener(`keydown`,t),()=>{window.removeEventListener(`keydown`,e,!0),window.removeEventListener(`keydown`,t)}},[]),null}var Gn=4e3;function Kn(){let[e,t]=(0,Y.useState)(`hidden`),n=(0,Y.useRef)(e);n.current=e,(0,Y.useEffect)(()=>{let e=null,r=J.onConnectionChange(r=>{if(r){e!==null&&clearTimeout(e),e=null,n.current===`lost`&&t(`hidden`);return}e!==null||n.current!==`hidden`||(e=setTimeout(()=>{e=null,n.current===`hidden`&&t(`lost`)},Gn))});return()=>{r(),e!==null&&clearTimeout(e)}},[]);let r=(0,Y.useCallback)(async()=>{n.current!==`refreshing`&&(t(`refreshing`),await Fn.refresh()||(L.error(`The cockpit has not come back — it may need a terminal (ssh re-auth): puddle refresh`),t(J.isConnected()?`hidden`:`lost`)))},[]);return(0,Y.useEffect)(()=>Ln(()=>void r()),[r]),e===`hidden`?null:(0,X.jsxs)(`div`,{className:`flex shrink-0 items-center gap-3 bg-elevated px-3 py-2`,children:[(0,X.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:e===`refreshing`?`Restarting the cockpit.`:`Connection to the daemon lost.`}),e===`lost`&&(0,X.jsxs)(G,{size:`sm`,className:`ml-auto`,onClick:()=>void r(),children:[(0,X.jsx)(Vt,{}),`Refresh connection`]})]})}function qn({label:e,percentage:t,hint:n}){let r=Math.max(0,Math.min(100,t));return(0,X.jsxs)(`span`,{className:`flex items-center gap-2`,children:[(0,X.jsx)(`span`,{className:`w-24 shrink-0 truncate text-2xs text-fg-muted`,title:e,children:e}),(0,X.jsx)(`span`,{className:`relative h-1.5 min-w-0 flex-1 overflow-hidden rounded-full bg-border`,children:(0,X.jsx)(`span`,{className:`absolute inset-y-0 left-0 rounded-full ${r>=90?`bg-danger`:r>=75?`bg-warning`:`bg-action`}`,style:{width:`${r}%`}})}),(0,X.jsxs)(`span`,{className:`shrink-0 text-2xs tabular-nums text-fg-muted`,children:[Math.round(r),`%`,n?` · ${n}`:``]})]})}function Jn(e){return e>=1e6?`${(e/1e6).toFixed(1)}M`:e>=1e3?`${(e/1e3).toFixed(1)}k`:String(e)}function Yn(e){if(e===null)return`never`;let t=new Date(e).getTime(),n=Math.max(0,Math.round((Date.now()-t)/1e3));if(n<60)return`just now`;let r=Math.round(n/60);if(r<60)return`${r}m ago`;let i=Math.round(r/60);return i<24?`${i}h ago`:`${Math.round(i/24)}d ago`}function Xn({account:e,onLogin:t,onStartSession:n,installed:r=!0}){let i=xe(e.id),a=e.logged_in?n:r?t:null,o=i.data?.subscription;return(0,X.jsxs)(`div`,{className:`rounded-md px-2 py-2 transition-colors hover:bg-elevated`,children:[(0,X.jsxs)(`button`,{type:`button`,disabled:a===null,onClick:()=>a?.(),className:`flex w-full items-center gap-3 text-left disabled:cursor-default`,children:[(0,X.jsx)(`span`,{className:`size-2 shrink-0 rounded-full ${e.logged_in?`bg-success`:`bg-idle`}`,"aria-hidden":!0}),(0,X.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,X.jsx)(`span`,{className:`block truncate text-sm text-fg`,children:e.label}),(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[e.logged_in?`logged in`:`logged out`,i.data&&(0,X.jsxs)(X.Fragment,{children:[` · `,i.data.session_count,` session`,i.data.session_count===1?``:`s`,i.data.active_session_count>0&&` (${i.data.active_session_count} active)`,` · `,`last `,Yn(i.data.last_activity_at)]})]}),i.data?.agent_usage&&(0,X.jsxs)(`span`,{className:`block text-2xs text-fg-muted`,children:[Jn(i.data.agent_usage.input_tokens),` in ·`,` `,Jn(i.data.agent_usage.output_tokens),` out ·`,` `,Jn(i.data.agent_usage.cache_read_input_tokens),` cached ·`,` `,i.data.agent_usage.message_count,` msgs`]}),i.data?.live_usage?.context_used_percentage!=null&&(0,X.jsx)(`span`,{className:`mt-1 block`,children:(0,X.jsx)(qn,{label:`context`,percentage:i.data.live_usage.context_used_percentage})})]}),(0,X.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted`,children:r?e.logged_in?n?`new agent`:``:(0,X.jsxs)(`span`,{className:`flex items-center gap-1 text-warning`,children:[(0,X.jsx)(_,{className:`size-3`}),`sign in`]}):`unavailable`})]}),o!=null&&o.windows.length>0&&(0,X.jsx)(`div`,{className:`mt-2 flex flex-col gap-1 pl-5`,children:o.windows.map(e=>(0,X.jsx)(qn,{label:e.label,percentage:e.used_percentage,hint:e.resets==null?void 0:`resets ${e.resets}`},e.key))})]})}function Zn(){let[e,t]=(0,Y.useState)(!1),[n,r]=(0,Y.useState)(!1),i=N(),a=We(),o=_e(),s=a.data?.find(e=>e.id===i),c=nt(i??void 0),l=ze(),u=Ae(),{open:f,handler:p}=Ct(),[m,_]=(0,Y.useState)(null),v=e=>u.mutate(e.id,{onSuccess:t=>_({stream:t.stream,label:`${e.agent_type}/${e.label}`}),onError:e=>q(e)}),y=e=>{t(!1),f({accountId:e.id})};return n&&s?(0,X.jsxs)(`div`,{className:`flex h-8 items-center gap-2 px-3`,children:[(0,X.jsx)(g,{icon:s.icon,colour:s.icon_colour}),(0,X.jsx)(jt,{initial:s.name,maxLength:100,className:R(`w-32 text-sm`,d(s.icon_colour)),onCommit:e=>{r(!1);let t=e.trim();!i||!t||t===s?.name||o.mutate({id:i,name:t},{onError:e=>q(e)})},onCancel:()=>r(!1)})]}):(0,X.jsxs)(X.Fragment,{children:[(0,X.jsxs)(rn,{open:e,onOpenChange:t,children:[(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsx)(nn,{asChild:!0,children:(0,X.jsxs)(G,{variant:`ghost`,size:`sm`,className:`font-sans compact:h-7 compact:px-1.5`,children:[(0,X.jsx)(g,{icon:s?.icon,colour:s?.icon_colour}),(0,X.jsx)(`span`,{className:d(s?.icon_colour),...Bt(()=>{t(!1),r(!0)}),children:s?.name??`…`})]})})}),(0,X.jsx)(W,{children:`Profile`})]}),(0,X.jsxs)(tn,{className:`w-[28rem] max-w-[calc(100vw-1rem)]`,children:[(0,X.jsxs)(`div`,{className:`flex flex-col gap-4`,children:[(l.data??[]).map(e=>{let t=c.data?.filter(t=>t.agent_type===e.id)??[];if(t.length===0)return null;let n=e.available!==!1;return(0,X.jsxs)(`div`,{className:`flex flex-col gap-0.5`,children:[(0,X.jsxs)(`span`,{className:`px-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:[e.display_name,!n&&(0,X.jsxs)(`span`,{className:`ml-2 normal-case tracking-normal text-fg-muted`,children:[`not installed — no `,e.binary??e.id,` on PATH`]})]}),t.map(e=>(0,X.jsx)(Xn,{account:e,onLogin:()=>v(e),onStartSession:p&&n?()=>y(e):null,installed:n},e.id))]},e.id)}),c.data?.length===0&&(0,X.jsx)(`p`,{className:`px-2 text-sm text-fg-muted`,children:`No accounts yet — add one in settings.`})]}),(0,X.jsxs)(`div`,{className:`mt-4 flex items-center gap-2`,children:[(0,X.jsxs)(G,{variant:`ghost`,size:`sm`,onClick:()=>{t(!1),Ht(`accounts`)},children:[(0,X.jsx)(B,{}),`Add account`]}),(0,X.jsxs)(G,{variant:`ghost`,size:`sm`,className:`ml-auto`,onClick:()=>{t(!1),le.set(null)},children:[(0,X.jsx)(Mn,{}),`Switch profile`]})]})]})]}),m&&(0,X.jsx)(h,{stream:m.stream,label:m.label,onClose:()=>_(null)})]})}var Qn=`desktop-update`;function $n(){let e=(0,Y.useRef)(null);return(0,Y.useEffect)(()=>{let t=M();if(t?.updateReady===void 0||t.onUpdateReady===void 0)return;let n=t=>{e.current!==t&&(e.current=t,L(`Puddle ${t} is downloaded and ready.`,{id:Qn,duration:1/0,closeButton:!0,action:{label:`Restart to update`,onClick:()=>{M()?.installUpdate?.(),L.loading(`Restarting into Puddle ${t}…`,{id:`${Qn}-restarting`,duration:1/0})}}}))};return t.updateReady().then(e=>{e!==null&&n(e)}),t.onUpdateReady(n)},[]),null}function er(){let e=N(),t=We().data?.find(t=>t.id===e),n=qe(e??void 0),r=Ze(e??void 0,void 0),i=E(),a=S(),o=C(),s=Ke(e??``),c=_e(),l=Te(),[u,d]=(0,Y.useReducer)(e=>e+1,0);(0,Y.useEffect)(()=>A(()=>d()),[]);let f=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{f.current=null},[t?.name]);let p=a.data?.available===!0?a.data.file:void 0,h=t!==void 0&&e!==null&&n.data!==void 0&&r.data!==void 0&&p!==void 0,g=t&&p?m(p,t.name):void 0,_=s.isPending||c.isPending||l.isPending||o.isPending||n.isFetching||r.isFetching;(0,Y.useEffect)(()=>{if(!h||!g?.enabled||_)return;let a={client:i,theme:ne(),profileSettings:n.data,profile:t,scratchpad:r.data},u={setClient:e=>D(e),setTheme:e=>{typeof e==`string`&&j(e)},patchProfileSettings:e=>s.mutate(e),patchProfileColumns:t=>c.mutate({id:e,...t}),createScratchpad:t=>{for(let n of t)l.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},d=JSON.stringify(g.doc);if(f.current!==d){f.current=d,b(g.doc,u,a,g.groups);return}let p=T(g.groups,a),m=JSON.stringify(p);m!==d&&(f.current=m,o.mutate({profile:t.name,entry:{...g,doc:p,updatedAt:new Date().toISOString()}}))})}function tr(e){let t=t=>{let n=a.safeParse(t);n.success&&e(n.data)},n=M()?.onNotificationClick?.((e,n)=>t(n)),r=e=>{e.data?.t===`notification-click`&&t(e.data.target)};return navigator.serviceWorker?.addEventListener(`message`,r),()=>{n?.(),navigator.serviceWorker?.removeEventListener(`message`,r)}}var nr=5e3,rr=`[data-notification-session]`;function ir(e){let t=null,n=()=>{t=null},r=e=>e.target instanceof Element?e.target.closest(rr):null,i=e=>{if(!e.isTrusted)return;let n=r(e),i=n?.dataset.notificationSession;t=n&&i?{element:n,session:i,at:performance.now()}:null},a=e=>{r(e)!==t?.element&&n()},o=[`pointerdown`,`keydown`,`input`,`paste`];for(let t of o)e.addEventListener(t,i,!0);return e.addEventListener(`focusin`,a,!0),e.addEventListener(`visibilitychange`,n),e.defaultView?.addEventListener(`blur`,n),{isInteracting(n){return t!==null&&t.session===n&&performance.now()-t.at<nr&&e.visibilityState===`visible`&&e.hasFocus()&&t.element.isConnected&&t.element.dataset.notificationSession===n&&t.element.getClientRects().length>0},dispose(){n();for(let t of o)e.removeEventListener(t,i,!0);e.removeEventListener(`focusin`,a,!0),e.removeEventListener(`visibilitychange`,n),e.defaultView?.removeEventListener(`blur`,n)}}}var ar=new Set,or=e=>!!e&&ar.has(e),sr=i.parse({});function cr(e){return e.prefs.muted_projects.includes(e.projectId)?{desktop:!1,sound:!1}:{desktop:e.prefs.desktop&&(e.permission===`granted`||e.permission===`unverified`)&&(e.prefs.when_focused||!e.sessionFocused),sound:e.prefs.sound}}function lr(e,t){for(let[,n]of e.getQueriesData({queryKey:[`sessions`]})){let e=n?.find(e=>e.id===t);if(e)return e}for(let[,n]of e.getQueriesData({queryKey:[`project`]})){let e=n?.sessions.find(e=>e.id===t);if(e)return e}}function ur(e){return e.title??e.agent_title??e.osc_title??e.id.slice(0,8)}function dr(){try{let e=new AudioContext,t=e.createGain();t.gain.value=.04,t.connect(e.destination);for(let[n,r]of[[880,0],[1318.5,.09]]){let i=e.createOscillator();i.type=`sine`,i.frequency.value=n,i.connect(t),i.start(e.currentTime+r),i.stop(e.currentTime+r+.12)}setTimeout(()=>void e.close(),400)}catch{}}function fr(){let e=ft(),t=(0,Y.useRef)(null);(0,Y.useEffect)(()=>{let e=ir(document);return t.current=e,()=>{t.current=null,e.dispose()}},[]),(0,Y.useEffect)(()=>tr(t=>{t.host||e(`/project/${t.project}/session/${t.session}`,{state:{notificationSession:t.session}})}),[e]),pr(t=>{e(`/project/${t.project_id}/session/${t.id}`,{state:{notificationSession:t.id}})},e=>t.current?.isInteracting(e.id)??!1)}function pr(e,t=()=>document.hasFocus()){let n=rt(),r=(0,Y.useRef)(e);r.current=e;let a=(0,Y.useRef)(t);a.current=t;let o=Ge(je().data)??`Puddle`,s=(0,Y.useRef)(o);(0,Y.useEffect)(()=>{document.title===s.current&&(document.title=o),s.current=o},[o]),(0,Y.useEffect)(()=>{let e=new Set,t=()=>{document.title=e.size>0?`(${e.size}) ${s.current}`:s.current},o=!0,l=async e=>{let t=lr(n,e.session);if(!t)try{t=(await tt(n)).find(t=>t.id===e.session)}catch{return}if(!o||!t)return;let l=t,u,d;try{let e=await n.fetchQuery({queryKey:[`project`,l.project_id],queryFn:()=>ie(`GET`,`/api/projects/${l.project_id}`),staleTime:1e4});if(!o)return;d=e.project;let t=d.profile_id,r=await n.fetchQuery({queryKey:[`profile-settings`,t],queryFn:()=>ie(`GET`,`/api/profiles/${t}/settings`),staleTime:1e4});u=i.catch(sr).parse(r.notifications??{})}catch{return}if(!o)return;let f=cr({prefs:u,projectId:l.project_id,sessionFocused:a.current(l),permission:y()});f.sound&&dr(),f.desktop&&!or(c()?.scope)&&await w({id:e.id?`puddle-event-${e.id}`:`puddle-agent-${l.id}`,title:e.content?.title??ur(l).slice(0,160),body:e.content?.body??(e.reason===`exited`?`Agent finished running`:`Waiting for your input`),target:{project:l.project_id,session:l.id,...c()?.notificationHost?{host:c().notificationHost}:{}}},()=>{o&&r.current(l)},{host:s.current,project:d})},u=J.onAgentNotification(e=>{l(e)}),d=J.onStatus(r=>{let i=e.has(r.session);r.status===`waiting_input`?e.add(r.session):e.delete(r.session),t(),!(r.status!==`waiting_input`||i)&&n.fetchQuery({queryKey:[`version`],queryFn:()=>ie(`GET`,`/api/version`),staleTime:1/0}).then(e=>{if(!(e.protocol.major>22||e.protocol.major===22&&e.protocol.minor>=3))return l({session:r.session,reason:`waiting_input`})}).catch(()=>{})});return()=>{o=!1,d(),u(),document.title=s.current}},[n])}function mr({initial:e,defaultScope:t,allowProject:n=!0,agents:r,onSave:i,onCancel:a}){let[o,s]=(0,Y.useState)(e?.title??``),[c,l]=(0,Y.useState)(e?.body??``),[u,d]=(0,Y.useState)(n?e?.scope??t:`profile`),[f,p]=(0,Y.useState)((e?.tags??[]).join(`, `)),[m,h]=(0,Y.useState)(e?.agent_type??null),g=()=>{let e=c.trim();e&&i({title:o.trim()||null,body:e,scope:u,tags:f.split(`,`).map(e=>e.trim()).filter(Boolean),agent_type:m})};return(0,X.jsxs)(`div`,{className:`flex flex-col gap-3`,children:[(0,X.jsx)(z,{value:o,placeholder:`Title (optional)`,spellCheck:!1,onChange:e=>s(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-9 text-sm font-medium`}),(0,X.jsx)(vt,{autoFocus:!0,value:c,placeholder:`Prompt or note…`,spellCheck:!1,rows:10,onChange:e=>l(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`?a():e.key===`Enter`&&(e.metaKey||e.ctrlKey)&&g()},className:`resize-y text-sm leading-relaxed`}),(0,X.jsx)(z,{value:f,placeholder:`tags, comma, separated`,spellCheck:!1,onChange:e=>p(e.target.value),onKeyDown:e=>e.stopPropagation(),className:`h-8 text-xs`}),(0,X.jsxs)(`div`,{className:`flex items-center gap-2`,children:[n&&(0,X.jsxs)(`label`,{className:`flex items-center gap-1.5 text-2xs text-fg-secondary`,children:[(0,X.jsx)(Wt,{checked:u===`profile`,onCheckedChange:e=>d(e?`profile`:`project`)}),`Profile-wide`]}),(0,X.jsx)(`div`,{className:`ml-auto flex items-center gap-1`,children:r.map(e=>(0,X.jsxs)(`button`,{type:`button`,title:e.display_name,"aria-pressed":m===e.id,onClick:()=>h(t=>t===e.id?null:e.id),className:R(`rounded-md p-1 transition-colors`,m===e.id?`bg-surface text-fg`:`text-fg-gold hover:bg-surface hover:text-fg`),children:[(0,X.jsx)(wt,{type:e.id,className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:e.display_name})]},e.id))})]}),(0,X.jsxs)(`div`,{className:`flex items-center justify-end gap-1.5`,children:[(0,X.jsx)(G,{variant:`ghost`,size:`sm`,onClick:a,children:`Cancel`}),(0,X.jsx)(G,{size:`sm`,disabled:!c.trim(),onClick:g,children:`Save`})]})]})}function hr(){let e=xt(),t=N(),n=ut().id,r=Ze(t??void 0,n).data??[],i=ze().data??[],a=Te(),o=$e(),s=De(),c=Dt(),[l,u]=(0,Y.useState)(null),[d,f]=(0,Y.useState)(null),[p,m]=(0,Y.useState)(null),[h,g]=(0,Y.useState)(null),[_,v]=(0,Y.useState)(null);(0,Y.useEffect)(()=>me(`scratchpad.toggle`,Et),[]),(0,Y.useEffect)(()=>{e||(u(null),f(null),m(null))},[e]);let y=(0,Y.useMemo)(()=>[...new Set(r.flatMap(e=>e.tags))].sort((e,t)=>e.localeCompare(t)),[r]),b=(0,Y.useMemo)(()=>[...new Set(r.map(e=>e.agent_type).filter(e=>e!==null))],[r]),x=d!==null||p!==null,S=r.filter(e=>(d===null||e.tags.includes(d))&&(p===null||e.agent_type===p)),C=x?S:_??r,w=e=>{t&&(a.mutate({profile_id:t,scope:e.scope,project_id:e.scope===`project`?n:void 0,title:e.title??void 0,body:e.body,tags:e.tags,agent_type:e.agent_type??void 0}),u(null))},T=(e,t)=>{o.mutate({id:e,scope:t.scope,project_id:t.scope===`project`?n??null:null,title:t.title,body:t.body,tags:t.tags,agent_type:t.agent_type}),u(null)},E=(e,t)=>{let n=_??r,i=n.findIndex(t=>t.id===e),a=n.findIndex(e=>e.id===t);if(i===-1||a===-1||i===a)return;let o=n.slice(),[s]=o.splice(i,1);o.splice(a,0,s),v(o)},D=()=>{let e=h,t=_;if(g(null),v(null),e===null||!t)return;let n=t.findIndex(t=>t.id===e);if(n===-1)return;let r=t[n-1],i=t[n+1],a=r?i?(r.position+i.position)/2:r.position+1:(i?i.position:0)-1;o.mutate({id:e,position:a})},O=e=>{navigator.clipboard?.writeText(e.body),L.success(`Copied to clipboard`)};return(0,X.jsxs)(rn,{open:e,onOpenChange:St,children:[(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsx)(nn,{asChild:!0,children:(0,X.jsxs)(G,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(An,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Scratchpad`})]})})}),(0,X.jsx)(W,{children:`Scratchpad`})]}),(0,X.jsxs)(tn,{className:`w-[34rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Scratchpad`}),(0,X.jsxs)(`button`,{type:`button`,onClick:()=>u(l===`new`?null:`new`),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,X.jsx)(B,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`New entry`})]})]}),(y.length>0||b.length>0)&&(0,X.jsxs)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:[y.map(e=>(0,X.jsx)(`button`,{type:`button`,onClick:()=>f(t=>t===e?null:e),className:R(`rounded-full px-2 py-0.5 text-2xs transition-colors`,d===e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:e},e)),b.map(e=>(0,X.jsx)(`button`,{type:`button`,"aria-pressed":p===e,onClick:()=>m(t=>t===e?null:e),className:R(`rounded-md p-1 transition-colors`,p===e?`bg-action text-action-ink`:`text-fg-gold hover:bg-surface`),children:(0,X.jsx)(wt,{type:e,className:`size-3.5`})},e))]}),(0,X.jsxs)(`div`,{className:`no-scrollbar max-h-[65vh] overflow-y-auto px-2 pb-3`,children:[l===`new`&&(0,X.jsx)(`div`,{className:`px-3 py-2`,children:(0,X.jsx)(mr,{defaultScope:n?`project`:`profile`,allowProject:n!==void 0,agents:i,onSave:w,onCancel:()=>u(null)})}),C.length===0&&l!==`new`&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:x?`Nothing matches this filter.`:`No entries yet — press + to add a reusable prompt or note.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:C.map(e=>l===e.id?(0,X.jsx)(`li`,{className:`px-3 py-2`,children:(0,X.jsx)(mr,{initial:e,defaultScope:e.scope,allowProject:n!==void 0||e.scope===`project`,agents:i,onSave:t=>T(e.id,t),onCancel:()=>u(null)})},e.id):(0,X.jsx)(`li`,{draggable:!x&&l===null,onDragStart:t=>{t.dataTransfer.effectAllowed=`move`,g(e.id)},onDragOver:t=>{h!==null&&(t.preventDefault(),h!==e.id&&E(h,e.id))},onDragEnd:D,className:R(`transition-opacity`,h===e.id&&`opacity-50`),children:(0,X.jsx)(gr,{entry:e,onInsert:c?()=>{c(e.body),St(!1)}:null,onCopy:()=>O(e),onEdit:()=>u(e.id),onDelete:()=>s.mutate(e.id)})},e.id))})]})]})]})}function gr({entry:e,onInsert:t,onCopy:n,onEdit:r,onDelete:i}){let[a,o]=(0,Y.useState)(!1);return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button`)||r()},className:`cursor-pointer rounded-md px-3 py-2.5 transition-colors hover:bg-surface`,children:[e.title&&(0,X.jsx)(`p`,{className:`text-sm font-medium text-fg`,children:e.title}),(0,X.jsx)(`p`,{className:R(`line-clamp-3 whitespace-pre-wrap text-sm text-fg-secondary`,e.title&&`mt-0.5`),children:e.body}),a?(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:`Delete this entry? This can’t be undone.`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>{o(!1),i()},className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:`Delete`}),(0,X.jsx)(`button`,{type:`button`,onClick:()=>o(!1),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:e.scope===`profile`?`Profile-wide`:`Project`}),e.agent_type&&(0,X.jsx)(wt,{type:e.agent_type,className:`size-3 text-fg-gold`}),e.tags.map(e=>(0,X.jsx)(`span`,{className:`rounded-full bg-surface px-1.5 text-2xs text-fg-secondary`,children:e},e)),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[t&&(0,X.jsx)(_r,{icon:Dn,label:`Insert into focused terminal`,onClick:t}),(0,X.jsx)(_r,{icon:Kt,label:`Copy`,onClick:n}),(0,X.jsx)(_r,{icon:p,label:`Edit`,onClick:r}),(0,X.jsx)(_r,{icon:yt,label:`Delete`,onClick:()=>o(!0)})]})]})]})}function _r({icon:e,label:t,onClick:n}){return(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(W,{children:t})]})}var vr=s.parse({});function yr(e,t){let[n,r]=(0,Y.useState)(null),i=we(t).data,a=et(e??void 0,t&&e!==null).data;return(0,Y.useEffect)(()=>{if(!t||e===null){r(null);return}let n=!1,i;try{i=zt(sessionStorage.getItem(Rt(e)))}catch{i={kind:`absent`}}if(i.kind===`present`){r(i.snapshot);return}return at(e).then(e=>{n||r(e?e.ui_state:vr)}).catch(()=>{n||r(vr)}),()=>{n=!0}},[t,e]),(0,Y.useMemo)(()=>{if(!t||e===null||n===null)return null;let o=t=>{if(!i||!a)return!1;let{patch:o,projectBased:s}=Nt(n,t,{alive:new Set(i.filter(e=>e.status!==`archived`).map(e=>e.id)),sessionProject:new Map(i.map(e=>[e.id,e.project_id])),projectIds:a.map(e=>e.id),currentProject:null}),c={...n,...o};r(c),it(e,c).catch(e=>console.warn(`ui-state save failed: ${e.message}`));try{sessionStorage.setItem(Rt(e),JSON.stringify(c))}catch(e){console.warn(`ui-state write failed: ${e.message}`)}return O().projectBasedLayout!==s&&D({projectBasedLayout:s}),!0},s=Object.fromEntries(Object.entries(n.project_layouts).map(([e,t])=>[e,{layoutRef:t.layout_ref,signature:H(t.layout_tree)}]));return(n.layout_mode??`profile`)===`project`?{headless:!0,scope:`project`,projectId:``,layoutRef:null,signature:H(null),slices:s,capture:()=>({layout_tree:null,active_session:null}),apply:o}:{scope:`profile`,projectId:``,layoutRef:n.layout_ref,signature:H(n.layout_tree),slices:s,capture:()=>({layout_tree:n.layout_tree,active_session:n.active_session}),apply:o}},[t,e,n,i,a])}var br=H(null);function xr(){let e=Ft(),t=ft(),n=N(),r=It(),i=yr(n,e&&r===null),a=r??i,o=Qe(n??void 0,void 0).data??[],s=et(n??void 0,e&&n!==null).data??[],c=Je(),l=Le(),u=ye(),[d,f]=(0,Y.useState)(``),[p,m]=(0,Y.useState)(!1),[h,g]=(0,Y.useState)(null);(0,Y.useEffect)(()=>me(`layouts.toggle`,Mt),[]),(0,Y.useEffect)(()=>{e||(f(``),m(!1),g(null))},[e]);let _=a?.headless===!0,v=a===null||_?null:o.find(e=>e.id===a.layoutRef)??null,y=a!==null&&!_&&(v===null?a.signature!==br:H(v.layout_tree)!==a.signature),b=e=>{let t=a?.slices?.[e];if(!t)return!1;let n=t.layoutRef===null?null:o.find(e=>e.id===t.layoutRef)??null;return n?H(n.layout_tree)!==t.signature:t.signature!==br},x=e=>a===null?!1:e.scope===`profile`?a.scope===`profile`&&y:e.project_id===null?!1:a.scope===`project`?!_&&e.project_id===a.projectId?y:b(e.project_id):y||b(e.project_id),S=e=>v!==null&&e.id===v.id,C=e=>(e===null?void 0:s.find(t=>t.id===e)?.name)??`Project`,w=a!==null&&!_&&a.scope===`project`?o.filter(e=>e.scope===`profile`||e.project_id===a.projectId):o,T=[...w.some(e=>e.scope===`profile`)?[{key:`profile`,name:`Profile-wide`}]:[],...[...new Set(w.flatMap(e=>e.project_id===null?[]:[e.project_id]))].map(e=>({key:e,name:C(e)})).sort((e,t)=>e.name.localeCompare(t.name))],E=h===null?w:h===`profile`?w.filter(e=>e.scope===`profile`):w.filter(e=>e.project_id===h),D=e=>a!==null&&e.scope===a.scope&&(a.scope===`profile`||e.project_id===a.projectId),O=(e,t,r)=>{!a||!n||c.mutate({profile_id:n,scope:a.scope,project_id:a.scope===`project`?a.projectId:void 0,name:e,...t},{onSuccess:e=>{r&&a.apply(e)},onError:e=>q(e)})},ee=e=>{if(!a)return;let t=D(e)?e:o.find(t=>t.name===e.name&&D(t));if(!t){O(e.name,a.capture(),!0);return}l.mutate({id:t.id,...a.capture()},{onSuccess:e=>a.apply(e),onError:e=>q(e)})},k=(e,t)=>O(t,{layout_tree:e.layout_tree,active_session:e.active_session},!1),A=e=>{if(a){if(!a.apply(e)){L.error(`Workspace is still loading — try again in a moment`);return}e.project_id!==null&&e.project_id!==a.projectId&&t(`/project/${e.project_id}`),At(!1)}};return(0,X.jsxs)(rn,{open:e,onOpenChange:At,children:[(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsx)(nn,{asChild:!0,children:(0,X.jsxs)(G,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,children:[(0,X.jsx)(On,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Layouts`})]})})}),(0,X.jsx)(W,{children:`Layouts`})]}),(0,X.jsxs)(tn,{className:`w-[26rem] max-w-[calc(100vw-1rem)] p-0`,children:[(0,X.jsxs)(`div`,{className:`flex items-center gap-2 px-5 pb-2 pt-4`,children:[(0,X.jsx)(`span`,{className:`text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:`Layouts`}),a!==null&&!_&&(0,X.jsxs)(`button`,{type:`button`,onClick:()=>m(e=>!e),className:`ml-auto flex items-center rounded-md p-1 text-fg-gold transition-colors hover:bg-surface hover:text-fg`,children:[(0,X.jsx)(B,{className:`size-4`}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Save the current layout as a new layout`})]})]}),a===null?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Loading the profile’s layout state…`}):_?(0,X.jsx)(`p`,{className:`px-5 pb-3 text-sm text-fg-muted`,children:`Project-based layout is on — every project keeps its own layout. Open a project to name or save it; loading works from here.`}):(v===null||p)&&(0,X.jsxs)(`div`,{className:`flex flex-col gap-2 px-5 pb-3`,children:[v===null&&(0,X.jsxs)(`div`,{className:`flex items-baseline gap-2`,children:[(0,X.jsx)(`span`,{className:`text-sm font-medium text-fg`,children:`Unnamed layout`}),(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:a.scope===`profile`?`Profile-wide`:`Project`}),(0,X.jsx)(`span`,{className:`ml-auto text-2xs text-interrupted`,children:`Unsaved`})]}),(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:e=>{e.preventDefault();let t=d.trim();t&&(O(t,a.capture(),!0),f(``),m(!1))},children:[(0,X.jsx)(z,{autoFocus:p,value:d,placeholder:v===null?`Name this layout…`:`Save as a new layout…`,spellCheck:!1,onChange:e=>f(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&m(!1)},className:`h-8 flex-1 text-sm`}),(0,X.jsx)(G,{size:`sm`,type:`submit`,disabled:!d.trim(),children:`Save`}),v!==null&&(0,X.jsx)(G,{variant:`ghost`,size:`sm`,onClick:()=>m(!1),children:`Cancel`})]})]}),T.length>1&&(0,X.jsx)(`div`,{className:`flex flex-wrap items-center gap-1 px-5 pb-2`,children:T.map(e=>(0,X.jsx)(wr,{active:h===e.key,onClick:()=>g(t=>t===e.key?null:e.key),children:e.name},e.key))}),(0,X.jsxs)(`div`,{className:`no-scrollbar max-h-[60vh] overflow-y-auto px-2 pb-3`,children:[E.length===0&&(0,X.jsx)(`p`,{className:`px-3 py-3 text-sm text-fg-muted`,children:h===null?`No layouts yet — name and save the current layout to keep it.`:`Nothing matches this filter.`}),(0,X.jsx)(`ul`,{className:`flex flex-col`,children:E.map(e=>(0,X.jsx)(`li`,{children:(0,X.jsx)(Sr,{layout:e,projectLabel:e.scope===`profile`?null:C(e.project_id),isCurrent:S(e),dirty:y,loadable:a!==null,savable:a!==null&&!_,confirmBeforeLoad:x(e),overwrites:D(e),onLoad:()=>A(e),onRename:t=>l.mutate({id:e.id,name:t}),onDelete:()=>u.mutate(e.id),onSaveAs:()=>ee(e),onDuplicate:t=>k(e,t)})},e.id))})]})]})]})}function Sr({layout:e,projectLabel:t,isCurrent:n,dirty:r,loadable:i,savable:a,confirmBeforeLoad:o,overwrites:s,onLoad:c,onRename:l,onDelete:u,onSaveAs:d,onDuplicate:f}){let[m,h]=(0,Y.useState)(null),[g,_]=(0,Y.useState)(null),[v,y]=(0,Y.useState)(e.name),b=()=>{if(!(!i||g!==null)){if(o&&m!==`load`){h(`load`);return}h(null),c()}},x=t=>{h(null),y(t===`rename`?e.name:`${e.name} copy`),_(t)},S=()=>{if(n){d();return}h(`save`)},C=n?r?`unsaved`:`active`:null;return(0,X.jsxs)(`div`,{onClick:e=>{e.target.closest(`button, input`)||b()},className:R(`rounded-md px-3 py-2.5 transition-colors`,i&&`cursor-pointer hover:bg-surface`),children:[g===null?(0,X.jsxs)(`p`,{className:R(`flex items-baseline gap-2 text-sm font-medium`,C===`active`?`text-success`:C===`unsaved`?`text-interrupted`:`text-fg`),children:[e.name,C!==null&&(0,X.jsx)(`span`,{className:`text-2xs font-normal`,children:C===`active`?`Active`:`Unsaved`})]}):(0,X.jsxs)(`form`,{className:`flex items-center gap-1.5`,onSubmit:t=>{t.preventDefault();let n=v.trim();n&&(g===`rename`?n!==e.name&&l(n):f(n)),_(null)},children:[(0,X.jsx)(z,{autoFocus:!0,value:v,spellCheck:!1,onChange:e=>y(e.target.value),onKeyDown:e=>{e.stopPropagation(),e.key===`Escape`&&_(null)},className:`h-7 flex-1 text-sm`}),(0,X.jsx)(G,{size:`sm`,type:`submit`,disabled:!v.trim(),children:g===`rename`?`Rename`:`Save`})]}),m===`save`?(0,X.jsx)(Cr,{question:s?`Overwrite “${e.name}” with the current layout?`:`Save the current layout as “${e.name}” here?`,verb:s?`Overwrite`:`Save`,onConfirm:()=>{h(null),d()},onCancel:()=>h(null)}):m===`delete`?(0,X.jsx)(Cr,{question:`Delete this layout? This can’t be undone.`,verb:`Delete`,onConfirm:()=>{h(null),u()},onCancel:()=>h(null)}):m===`load`?(0,X.jsx)(Cr,{question:`Loading discards unsaved layout changes.`,verb:`Load`,onConfirm:b,onCancel:()=>h(null)}):(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-1.5`,children:[t!==null&&(0,X.jsx)(`span`,{className:`text-2xs uppercase tracking-wide text-fg-muted`,children:t}),(0,X.jsxs)(`div`,{className:`ml-auto flex items-center gap-1`,children:[a&&(0,X.jsxs)(X.Fragment,{children:[(0,X.jsx)(Tr,{icon:jn,label:n?`Save`:`Save the current layout as “${e.name}”`,onClick:S}),(0,X.jsx)(Tr,{icon:Kt,label:`Duplicate`,onClick:()=>x(`duplicate`)})]}),(0,X.jsx)(Tr,{icon:p,label:`Rename`,onClick:()=>x(`rename`)}),(0,X.jsx)(Tr,{icon:yt,label:`Delete`,onClick:()=>h(`delete`)})]})]})]})}function Cr({question:e,verb:t,onConfirm:n,onCancel:r}){return(0,X.jsxs)(`div`,{className:`mt-2 flex items-center gap-3`,children:[(0,X.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e}),(0,X.jsx)(`button`,{type:`button`,onClick:n,className:`text-2xs font-medium text-interrupted transition-colors hover:underline`,children:t}),(0,X.jsx)(`button`,{type:`button`,onClick:r,className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:`Cancel`})]})}function wr({active:e,onClick:t,children:n}){return(0,X.jsx)(`button`,{type:`button`,"aria-pressed":e,onClick:t,className:R(`rounded-full px-2 py-0.5 text-2xs transition-colors`,e?`bg-action text-action-ink`:`bg-surface text-fg-secondary hover:text-fg`),children:n})}function Tr({icon:e,label:t,onClick:n}){return(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsxs)(`button`,{type:`button`,onClick:n,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,X.jsx)(e,{className:`size-3.5`}),(0,X.jsx)(`span`,{className:`sr-only`,children:t})]})}),(0,X.jsx)(W,{children:t})]})}var $=M()!==void 0&&/Mac/.test(navigator.platform),Er=(0,Y.lazy)(()=>k(()=>import(`./SettingsDialog-CaHklYzG.js`).then(e=>({default:e.SettingsDialog})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,30,31])));function Dr(){let e=rt();(0,Y.useEffect)(()=>{let t=t=>{for(let[n,r]of e.getQueriesData({queryKey:[`sessions`]}))r&&e.setQueryData(n,r.map(t));for(let[n,r]of e.getQueriesData({queryKey:[`project`]}))r&&e.setQueryData(n,{...r,sessions:r.sessions.map(t)})},n=J.onStatus(e=>t(t=>t.id===e.session?{...t,status:e.status,last_activity_at:e.last_activity_at}:t)),r=J.onRenamed(e=>t(t=>t.id===e.session?{...t,title:e.title,agent_title:`agent_title`in e?e.agent_title:t.agent_title,osc_title:`osc_title`in e?e.osc_title:t.osc_title}:t)),i=J.onAccount(t=>{for(let[n,r]of e.getQueriesData({queryKey:[`accounts`]}))r&&e.setQueryData(n,r.map(e=>e.id===t.account_id?{...e,logged_in:t.logged_in}:e))}),a=t=>{e.invalidateQueries({queryKey:[`sessions`]});for(let n of t)e.invalidateQueries({queryKey:[`project`,n]})},o=J.onSessionsChanged(e=>a(e.project_ids)),s=J.onSessionSwitched(e=>a([e.target_project]));return()=>{n(),r(),i(),o(),s()}},[e])}function Or(){let e=je(),t=He(),[n,r]=(0,Y.useState)(!1),i=Ge(e.data),a=n=>{r(!1);let a=n.trim();a!==i&&t.mutate({displayName:a===e.data?.hostname?``:a},{onError:e=>q(e)})},o=!$&&(0,X.jsx)(`img`,{src:`/puddle.svg`,alt:`Puddle`,className:`size-4`}),s=R(`flex shrink-0 items-center gap-2`,$&&`[-webkit-app-region:no-drag]`),c=`truncate text-sm font-semibold text-fg-secondary`;return n&&i!==void 0?(0,X.jsxs)(`div`,{className:s,children:[o,(0,X.jsx)(jt,{initial:e.data?.displayName??i,maxLength:64,className:R(c,`w-40`),onCommit:a,onCancel:()=>r(!1)})]}):(0,X.jsxs)(dt,{to:`/`,className:R(s,`transition-opacity hover:opacity-70`),title:`All projects`,children:[o,i!==void 0&&(0,X.jsx)(`span`,{className:c,...Bt(()=>r(!0)),children:i})]})}function kr(){let e=ut(),t=de(`palette.toggle`),n=Xe(e.id).data?.project,r=n!==void 0&&n.id===e.id?n.name:void 0;return(0,X.jsxs)(`button`,{type:`button`,onClick:Tt,className:R(`absolute left-1/2 flex h-6 w-[min(30rem,42%)] -translate-x-1/2 items-center justify-center gap-2 rounded-md bg-ground text-fg-muted transition-colors hover:bg-elevated hover:text-fg-secondary`,$&&`[-webkit-app-region:no-drag]`),children:[(0,X.jsx)(`span`,{className:R(`truncate text-xs`,r&&d(n?.colour)),children:r??`Puddle`}),(0,X.jsx)(`span`,{className:`text-2xs`,children:t})]})}function Ar(){let{fullScreen:e,animate:t}=he();return(0,X.jsxs)(`header`,{className:R(`relative flex h-9 shrink-0 items-center gap-3 bg-surface pl-3 pr-3`,$&&!e&&`pl-[88px] [-webkit-app-region:drag]`,t&&`transition-[padding] duration-200 ease-out`),children:[(0,X.jsx)(Or,{}),(0,X.jsx)(kr,{}),(0,X.jsxs)(`div`,{className:R(`ml-auto flex items-center`,$&&`[-webkit-app-region:no-drag]`),children:[(0,X.jsxs)(U,{children:[(0,X.jsx)(V,{asChild:!0,children:(0,X.jsxs)(G,{variant:`ghost`,size:`icon`,className:`compact:h-7 compact:w-7`,onClick:()=>Ht(),children:[(0,X.jsx)(Nn,{}),(0,X.jsx)(`span`,{className:`sr-only`,children:`Settings`})]})}),(0,X.jsx)(W,{children:`Settings`})]}),(0,X.jsx)(xr,{}),(0,X.jsx)(hr,{}),(0,X.jsx)(Zn,{})]})]})}function jr(){Dr(),er(),fr();let{handler:e}=Ct(),t=N(),{pathname:n}=mt(),[r,i]=(0,Y.useState)(!1),a=Me(),o=a.data!==void 0&&Ye(a.data.protocol);return(0,Y.useEffect)(()=>{if(!o)return;let e=()=>{let e=te();J.reportTheme(e(`--text-primary`),e(`--bg-base`))};return e(),A(e)},[o]),(0,X.jsxs)(`div`,{className:`flex h-screen flex-col overflow-hidden overscroll-y-none bg-ground`,children:[(0,X.jsx)(Ar,{}),(0,X.jsx)(`main`,{className:`min-h-0 flex-1`,children:(0,X.jsx)(un,{resetOn:n,scope:n.startsWith(`/project/`)?`workspace`:`view`,children:(0,X.jsx)(gt,{})})}),(0,X.jsx)(Kn,{}),(0,X.jsx)($n,{}),(0,X.jsx)(Vn,{onNewSession:e??void 0,onNewProject:()=>i(!0)}),t!==null&&(0,X.jsx)(qt,{profileId:t,open:r,onOpenChange:i}),(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(Er,{})}),(0,X.jsx)(Wn,{})]})}function Mr(){return(0,X.jsx)(Lt,{children:(0,X.jsx)(jr,{})})}var Nr=(0,Y.lazy)(()=>k(()=>import(`./Dashboard-v3OproVW.js`).then(e=>({default:e.Dashboard})),__vite__mapDeps([32,1,2,3,4,5,6,7,8,9,10,11,14,15,13,33,22,34,25,35,36,29,28,21,37]))),Pr=(0,Y.lazy)(()=>k(()=>import(`./Workspace-GgVr1uYN.js`).then(e=>({default:e.Workspace})),__vite__mapDeps([38,1,2,8,3,4,5,6,7,9,10,11,18,19,20,13,14,39,15,40,21,25,35,33,17,41,16,42,43,22,34,44,23,24,45,46,37,28,47,48,49,31,50]))),Fr=new ln({defaultOptions:{queries:{retry:1,staleTime:5e3}},mutationCache:new on({onError:e=>q(e)})});function Ir(){let e=N(),t=We(),n=e!==null&&t.data!==void 0&&!t.data.some(t=>t.id===e);return e===null||n?(0,X.jsx)(Pn,{}):(0,X.jsx)(ct,{useTransitions:!1,children:(0,X.jsx)(Y.Suspense,{fallback:null,children:(0,X.jsx)(lt,{children:(0,X.jsxs)(I,{element:(0,X.jsx)(Mr,{}),children:[(0,X.jsx)(I,{path:`/`,element:(0,X.jsx)(Nr,{})}),(0,X.jsx)(I,{path:`/project/:id`,element:(0,X.jsx)(Pr,{})}),(0,X.jsx)(I,{path:`/project/:id/session/:sid`,element:(0,X.jsx)(Pr,{})})]})})})})}function Lr(){let e=(0,Y.useSyncExternalStore)(l.subscribe,l.get);return(0,X.jsx)(Se,{client:Fr,children:(0,X.jsxs)(Pt,{delayDuration:300,children:[(0,X.jsx)(En,{}),(0,X.jsx)(un,{scope:`app`,children:e?window.location.pathname.startsWith(`/forward/`)?(0,X.jsx)(an,{}):(0,X.jsx)(Ir,{}):(0,X.jsx)(fn,{})}),(0,X.jsx)(dn,{})]})})}export{Lr as App};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{y as n}from"./auth-GfOuXpIe.js";import{a as r,c as i,d as a,i as o,o as s,s as c,t as l,u}from"./LazyTerminal-CgQryH0p.js";import{t as d}from"./jsx-runtime-By8HlURe.js";import{g as f,p}from"./hotkeys-1uTWFYAL.js";import{L as m,_t as h,et as g,ft as _,h as v,it as y,st as b,tt as x}from"./protocol-support-BGmIChNK.js";import{a as S,i as C,l as w,o as T,r as E}from"./session-order-f7QxTbVD.js";import{a as D,i as O,n as k,o as A,t as ee}from"./dialog-BMWRC2HO.js";import{n as j}from"./x-DCpy1q13.js";import{t as M}from"./input-CxgRsoVg.js";import{t as N}from"./button-BgeBH2Uc.js";import{c as P,d as F,n as te,r as I,t as L,u as R}from"./context-menu-CMWkmDu6.js";import{r as z}from"./dist-Ds3438NL.js";import{t as B}from"./NewProjectDialog-BT8rR4yn.js";import{n as V}from"./errors-O9DWXa3f.js";import{t as H}from"./ws-CMPCIzY4.js";var U=e(t(),1),W=d(),G=!1;function K(){let[e,t]=(0,U.useState)(G),[r,i]=(0,U.useState)(null);(0,U.useEffect)(()=>{if(!e)return;let t=!1;return H.spawnShell(n).then(e=>{t||i(e)}),()=>{t=!0}},[e]);let a=()=>{G=!1,t(!1),i(null)};return{open:e,term:r,toggle:()=>{e?(r&&H.killShell(n,r),a()):(G=!0,t(!0))},onExit:a}}function q({term:e,onExit:t}){return(0,W.jsx)(`div`,{className:`h-72 shrink-0 pb-6`,children:(0,W.jsx)(`div`,{className:`mx-auto size-full max-w-4xl px-6`,children:e!==null&&(0,W.jsx)(l,{stream:`home`,term:e,onExit:t})})})}var J=`group block w-full rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,Y=[{status:`running`,colour:`bg-running`},{status:`waiting_input`,colour:`bg-waiting`},{status:`interrupted`,colour:`bg-interrupted`}];function X({project:e,repoPath:t,sessions:n}){let i=n.filter(e=>e.status!==`archived`);return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(`h2`,{className:j(`truncate pr-16 text-base font-semibold`,r(e.colour)||`text-fg group-hover:text-accent`),children:e.name}),(0,W.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:t??`…`}),(0,W.jsxs)(`div`,{className:`mt-3 flex flex-wrap items-center gap-3 text-2xs text-fg-muted tabular-nums`,children:[(0,W.jsxs)(`span`,{children:[i.length,` session`,i.length===1?``:`s`]}),Y.map(({status:e,colour:t})=>{let n=i.filter(t=>t.status===e).length;return n>0?(0,W.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,W.jsx)(`span`,{className:`size-1.5 rounded-full ${t}`}),n,` `,e.replace(`_`,` `)]},e):null})]})]})}function Z({icon:e,label:t,onClick:n}){return(0,W.jsx)(`button`,{type:`button`,"aria-label":t,title:t,onClick:e=>{e.preventDefault(),e.stopPropagation(),n()},className:`flex items-center rounded-md p-1.5 text-fg-muted transition-colors hover:bg-ground hover:text-fg`,children:(0,W.jsx)(e,{className:`size-4`})})}function Q({project:e,repoPath:t,draggable:n,dragging:c,onDragStart:l,onDragEnd:d,onDragOver:f}){let p=x(),g=v(m().data?.protocol),_=h(e.id),[y,b]=(0,U.useState)(!1),[S,C]=(0,U.useState)(e.name),[T,E]=(0,U.useState)(a(e)),[z,B]=(0,U.useState)(e.colour??null),H=t=>p.mutate({id:e.id,archived:t},{onError:e=>V(e)}),G=()=>{C(e.name),B(e.colour??null),E(a(e)),b(!0)},K=()=>{let t=S.trim(),n=u(T);if(!t){b(!1);return}let r={...t===e.name?{}:{name:t},...n&&n!==a(e)?{abbrev:n}:{},...g&&z!==(e.colour??null)?{colour:z}:{}};if(Object.keys(r).length===0){b(!1);return}p.mutate({id:e.id,...r},{onSuccess:()=>b(!1),onError:e=>V(e)})};return(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(L,{children:[(0,W.jsx)(P,{asChild:!0,children:(0,W.jsxs)(`div`,{draggable:n,onDragStart:l,onDragEnd:d,onDragOver:f,className:j(`group relative transition-opacity`,c&&`opacity-50`),children:[(0,W.jsx)(w,{draggable:!1,to:`/project/${e.id}`,className:J,children:(0,W.jsx)(X,{project:e,repoPath:t,sessions:_.data??[]})}),(0,W.jsx)(`div`,{className:`absolute right-2 top-2 hidden gap-0.5 group-hover:flex has-[[data-state=open]]:flex pointer-coarse:flex`,children:e.archived?(0,W.jsx)(Z,{icon:F,label:`Reopen project`,onClick:()=>H(!1)}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsx)(Z,{icon:s,label:`Edit project`,onClick:G}),(0,W.jsx)(Z,{icon:R,label:`Archive project`,onClick:()=>H(!0)})]})})]})}),(0,W.jsx)(te,{children:e.archived?(0,W.jsxs)(I,{onSelect:()=>H(!1),children:[(0,W.jsx)(F,{}),` Reopen`]}):(0,W.jsxs)(W.Fragment,{children:[(0,W.jsxs)(I,{onSelect:G,children:[(0,W.jsx)(s,{}),` Edit`]}),(0,W.jsxs)(I,{onSelect:()=>H(!0),children:[(0,W.jsx)(R,{}),` Archive`]})]})})]}),(0,W.jsx)(ee,{open:y,onOpenChange:b,children:(0,W.jsxs)(k,{children:[(0,W.jsx)(D,{children:(0,W.jsx)(A,{children:`Edit project`})}),(0,W.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),K()},children:[(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(i,{htmlFor:`project-name-${e.id}`,children:`Name`}),(0,W.jsx)(M,{id:`project-name-${e.id}`,value:S,className:r(z),onChange:e=>C(e.target.value),autoFocus:!0})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,W.jsx)(i,{htmlFor:`project-abbrev-${e.id}`,children:`Abbreviation`}),(0,W.jsx)(M,{id:`project-abbrev-${e.id}`,maxLength:5,value:T,onChange:e=>E(u(e.target.value)),className:`w-24 uppercase`}),(0,W.jsxs)(`p`,{className:`text-2xs text-fg-muted`,children:[`Up to `,5,` characters — the label on the collapsed sidebar rail.`]})]}),g&&(0,W.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,W.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:`Colour`}),(0,W.jsx)(o,{value:z,onChange:B,label:`Project colour`})]}),(0,W.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,W.jsx)(i,{className:`text-fg-muted`,children:`Path`}),(0,W.jsx)(`p`,{className:`truncate text-2xs text-fg-muted`,children:t??`…`})]}),(0,W.jsxs)(O,{children:[(0,W.jsx)(N,{type:`button`,variant:`ghost`,onClick:()=>b(!1),children:`Cancel`}),(0,W.jsx)(N,{type:`submit`,disabled:!S.trim()||p.isPending,children:`Save`})]})]})]})})]})}function $({icon:e,label:t,hint:n,onClick:r}){return(0,W.jsxs)(`button`,{type:`button`,onClick:r,className:`group flex flex-col rounded-lg bg-surface p-4 text-left transition-colors hover:bg-elevated`,children:[(0,W.jsxs)(`h2`,{className:`flex items-center gap-2 truncate text-base font-semibold text-fg group-hover:text-accent`,children:[(0,W.jsx)(e,{className:`size-4 shrink-0`}),t]}),(0,W.jsx)(`p`,{className:`mt-1 truncate text-2xs text-fg-muted`,children:n})]})}function ne(){let e=f(),t=b(e??void 0),n=_(),r=y(e??void 0),i=g(e??``),[a,o]=(0,U.useState)(!1),[s,l]=(0,U.useState)(null),[u,d]=(0,U.useState)(!1),m=K(),h=p(`palette.toggle`),v=e=>n.data?.find(t=>t.id===e)?.path,x=t.data??[],w=r.data?.projectOrder??[],D=E(x.filter(e=>!e.archived),w),O=x.filter(e=>e.archived),k=(e,t)=>{e!==t&&i.mutate({projectOrder:C(D.map(e=>e.id),e,t)})};return(0,W.jsxs)(`div`,{className:`flex h-full flex-col`,children:[(0,W.jsx)(`div`,{className:`min-h-0 flex-1 overflow-y-auto`,children:(0,W.jsxs)(`div`,{className:`mx-auto max-w-4xl p-6`,children:[x.length===0&&(0,W.jsxs)(`div`,{className:`mb-8 mt-16 flex flex-col items-center gap-3 text-center`,children:[(0,W.jsx)(c,{className:`size-8 text-fg-muted`}),(0,W.jsxs)(`p`,{className:`text-sm text-fg-secondary`,children:[`No projects yet — open one below, or press `,h,`.`]})]}),(0,W.jsxs)(`div`,{className:`grid auto-rows-fr grid-cols-1 gap-3 sm:grid-cols-2`,children:[D.map(e=>(0,W.jsx)(Q,{project:e,repoPath:v(e.repo_id),draggable:!0,dragging:s===e.id,onDragStart:()=>l(e.id),onDragEnd:()=>l(null),onDragOver:t=>{t.preventDefault(),s&&s!==e.id&&k(s,e.id)}},e.id)),(0,W.jsx)($,{icon:T,label:`Open project`,hint:`Point at a repository on this host`,onClick:()=>o(!0)}),(0,W.jsx)($,{icon:S,label:m.open?`Close terminal`:`Open terminal`,hint:m.open?`End the shell below`:`A shell at ~ for cloning repositories`,onClick:m.toggle})]}),O.length>0&&(0,W.jsxs)(`div`,{className:`mt-6`,children:[(0,W.jsxs)(`button`,{type:`button`,onClick:()=>d(e=>!e),className:`flex items-center gap-1.5 px-1 py-1.5 text-2xs uppercase tracking-wide text-fg-muted transition-colors hover:text-fg`,children:[(0,W.jsx)(z,{className:j(`size-3 transition-transform`,u&&`rotate-90`)}),(0,W.jsx)(R,{className:`size-3`}),(0,W.jsx)(`span`,{children:`Archived`}),(0,W.jsx)(`span`,{className:`tabular-nums`,children:O.length})]}),u&&(0,W.jsx)(`div`,{className:`mt-2 grid grid-cols-1 gap-3 sm:grid-cols-2`,children:O.map(e=>(0,W.jsx)(Q,{project:e,repoPath:v(e.repo_id),draggable:!1,dragging:!1,onDragStart:()=>{},onDragEnd:()=>{},onDragOver:()=>{}},e.id))})]})]})}),m.open&&(0,W.jsx)(q,{term:m.term,onExit:m.onExit}),e!==null&&(0,W.jsx)(B,{profileId:e,open:a,onOpenChange:o})]})}export{ne as Dashboard};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/Terminal-_10Xyj1h.js","assets/rolldown-runtime-QTnfLwEv.js","assets/react-CZI7_Jkm.js","assets/react-dom-cJyBB_A4.js","assets/auth-GfOuXpIe.js","assets/client-settings-CwqpIric.js","assets/jsx-runtime-By8HlURe.js","assets/preload-helper-Czpn1I53.js","assets/index-np8JXeG6.js","assets/index-CPHfr3MU.css","assets/hotkeys-1uTWFYAL.js","assets/forward-link-RM7_5Shu.js","assets/api-i6xNY3bF.js","assets/protocol-support-BGmIChNK.js","assets/dist-BOS6OKSE.js","assets/x-DCpy1q13.js","assets/createLucideIcon-DyMAgLa3.js","assets/FindWidget-CVH9U-_P.js","assets/whole-word-2m2pmAFT.js","assets/chevron-down--sjpQEHH.js","assets/selection-actions-D875GPFU.js","assets/button-BgeBH2Uc.js","assets/copy-CGsu8426.js","assets/ws-CMPCIzY4.js","assets/code-DRWf9a5s.js","assets/errors-O9DWXa3f.js","assets/math-delimiters-BCnTi7Ii.js","assets/Terminal-BrP-ENHg.css"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{z as n}from"./auth-GfOuXpIe.js";import{t as r}from"./jsx-runtime-By8HlURe.js";import{t as i}from"./preload-helper-Czpn1I53.js";import{S as a}from"./dialog-BMWRC2HO.js";import{n as o}from"./x-DCpy1q13.js";import{t as s}from"./input-CxgRsoVg.js";import{t as c}from"./createLucideIcon-DyMAgLa3.js";function l(e){return e.trim().slice(0,5).toUpperCase()}function u(e){return e.abbrev??l(e.name)}function d(e){return e.trim().toUpperCase().slice(0,5)}var f=e(t(),1),p=r(),m=`Label`,h=f.forwardRef((e,t)=>(0,p.jsx)(a.label,{...e,ref:t,onMouseDown:t=>{t.target.closest(`button, input, select, textarea`)||(e.onMouseDown?.(t),!t.defaultPrevented&&t.detail>1&&t.preventDefault())}}));h.displayName=m;var g=h;function _({className:e,...t}){return(0,p.jsx)(g,{className:o(`text-xs font-medium text-fg-secondary peer-disabled:cursor-not-allowed peer-disabled:opacity-50`,e),...t})}var v=c(`folder-git-2`,[[`path`,{d:`M18 19a5 5 0 0 1-5-5v8`,key:`sz5oeg`}],[`path`,{d:`M9 20H4a2 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.9H20a2 2 0 0 1 2 2v5`,key:`1w6njk`}],[`circle`,{cx:`13`,cy:`12`,r:`2`,key:`1j92g6`}],[`circle`,{cx:`20`,cy:`19`,r:`2`,key:`1obnsp`}]]),y=c(`pencil`,[[`path`,{d:`M21.174 6.812a1 1 0 0 0-3.986-3.987L3.842 16.174a2 2 0 0 0-.5.83l-1.321 4.352a.5.5 0 0 0 .623.622l4.353-1.32a2 2 0 0 0 .83-.497z`,key:`1a8usu`}],[`path`,{d:`m15 5 4 4`,key:`1mk7zo`}]]),b={navy:`text-fg`,gold:`text-fg-gold`,blue:`text-icon-blue`,green:`text-icon-green`,amber:`text-icon-amber`,red:`text-icon-red`,violet:`text-icon-violet`,cyan:`text-icon-cyan`,accent:`text-accent`};function x(e){return e&&b[e]||``}function S({value:e,onChange:t,disabled:r=!1,label:i=`Colour`}){return(0,p.jsx)(`div`,{role:`group`,"aria-label":i,className:`flex flex-wrap items-center gap-1`,children:[null,...n].map(n=>(0,p.jsx)(`button`,{type:`button`,title:n??`Default`,"aria-label":n??`Default colour`,"aria-pressed":(e??null)===n,disabled:r,onClick:()=>t(n),className:o(`flex size-7 cursor-pointer items-center justify-center rounded-md transition-colors hover:bg-border/50 focus-visible:bg-border/50 disabled:cursor-default disabled:opacity-50`,(e??null)===n&&`bg-border/50`),children:(0,p.jsx)(`span`,{className:o(`size-3.5 rounded-full`,n?o(`bg-current`,x(n)):`bg-fg-muted`)})},n??`default`))})}function C({id:e,value:t,onValueChange:n,onChoose:r,hints:i,placeholder:a,className:c,hintsClassName:l,autoFocus:u}){let[d,m]=(0,f.useState)(!1),[h,g]=(0,f.useState)(0),_=e=>{n(e.value),r?.(e),m(!1)};return(0,p.jsxs)(`div`,{className:`relative`,children:[(0,p.jsx)(s,{id:e,value:t,onChange:e=>{n(e.target.value),m(!0),g(0)},onFocus:()=>m(!0),onBlur:()=>m(!1),onKeyDown:e=>{if(!(!d||i.length===0))if(e.key===`ArrowDown`)e.preventDefault(),g(e=>(e+1)%i.length);else if(e.key===`ArrowUp`)e.preventDefault(),g(e=>(e-1+i.length)%i.length);else if(e.key===`Enter`||e.key===`Tab`){let t=i[h]??i[0];t&&(e.preventDefault(),_(t))}else e.key===`Escape`&&(e.stopPropagation(),m(!1))},placeholder:a,className:c,autoComplete:`off`,spellCheck:!1,autoFocus:u}),d&&i.length>0&&(0,p.jsx)(`ul`,{className:o(`absolute top-full z-10 mt-1 max-h-56 overflow-y-auto rounded-md bg-elevated p-1 shadow-xl`,l??`w-full`),children:i.map((e,t)=>(0,p.jsx)(`li`,{children:(0,p.jsxs)(`button`,{type:`button`,onMouseDown:t=>{t.preventDefault(),_(e)},onMouseEnter:()=>g(t),className:o(`relative flex cursor-pointer select-none items-center gap-2 rounded-sm px-2 py-1.5 text-sm text-fg outline-none transition-colors`,`data-[selected=true]:bg-action data-[selected=true]:text-action-ink data-[disabled=true]:pointer-events-none data-[disabled=true]:opacity-50`,`w-full text-xs`),"data-selected":t===h,children:[(0,p.jsx)(`span`,{className:`truncate`,children:e.label??e.value}),e.badge&&(0,p.jsx)(`span`,{className:`ml-auto shrink-0 text-2xs opacity-70`,children:e.badge})]})},e.value))})]})}var w=(0,f.lazy)(()=>i(()=>import(`./Terminal-_10Xyj1h.js`).then(e=>({default:e.Terminal})),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]))),T=null;async function E(){T=(await i(()=>import(`./Terminal-_10Xyj1h.js`),__vite__mapDeps([0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27]))).Terminal}function D(e){return T?(0,p.jsx)(T,{...e}):(0,p.jsx)(f.Suspense,{fallback:(0,p.jsx)(`div`,{className:`size-full bg-ground`}),children:(0,p.jsx)(w,{...e})})}export{x as a,_ as c,u as d,S as i,l,E as n,y as o,C as r,v as s,D as t,d as u};
@@ -1 +0,0 @@
1
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{a as n,c as r,i,l as a,r as ee,s as o,u as s}from"./LazyTerminal-CgQryH0p.js";import{t as c}from"./jsx-runtime-By8HlURe.js";import{K as l,L as u,N as d,P as te,U as f,c as ne,ft as re,h as ie}from"./protocol-support-BGmIChNK.js";import{m as ae,s as p}from"./session-order-f7QxTbVD.js";import{a as m,i as h,n as g,o as _,r as v,t as y}from"./dialog-BMWRC2HO.js";import{t as b}from"./input-CxgRsoVg.js";import{t as x}from"./button-BgeBH2Uc.js";import{t as S}from"./createLucideIcon-DyMAgLa3.js";import{t as oe}from"./use-debounced-value-C86N-mOK.js";var C=S(`folder`,[[`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`}]]),w=e(t(),1),T=c();function E(e){let t=e.trim().replace(/\/+$/,``);return t===``?`/`:t}function D(e){return e.startsWith(`/`)||e.startsWith(`~`)}function O(e){let t=e.replace(/\/+$/,``),n=t.lastIndexOf(`/`);return n<=0?`/`:t.slice(0,n)}function se({dir:e,onNavigate:t,onChoose:n}){let r=f(e.endsWith(`/`)?e:`${e}/`);return(0,T.jsxs)(`div`,{className:`flex flex-col gap-1`,children:[(0,T.jsxs)(`div`,{className:`flex min-w-0 items-center gap-1.5`,children:[(0,T.jsxs)(`button`,{type:`button`,onClick:()=>t(O(e)),disabled:e===`/`,title:`Parent directory`,className:`shrink-0 rounded-sm p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg disabled:pointer-events-none disabled:opacity-40`,children:[(0,T.jsx)(p,{className:`size-3.5`}),(0,T.jsx)(`span`,{className:`sr-only`,children:`Parent directory`})]}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>n(e),className:`ml-auto shrink-0 text-2xs text-fg-muted transition-colors hover:text-fg`,children:`choose this folder`})]}),(0,T.jsxs)(`div`,{className:`max-h-48 overflow-y-auto`,children:[(r.data?.entries??[]).map(e=>(0,T.jsxs)(`div`,{className:`flex items-center rounded-md transition-colors hover:bg-elevated`,children:[(0,T.jsxs)(`button`,{type:`button`,onClick:()=>t(e.path),className:`flex min-w-0 flex-1 items-center gap-2 px-2 py-1 text-left`,children:[e.is_git?(0,T.jsx)(o,{className:`size-3.5 shrink-0 text-success`}):(0,T.jsx)(C,{className:`size-3.5 shrink-0 text-fg-gold`}),(0,T.jsx)(`span`,{className:`truncate text-xs text-fg`,children:e.name})]}),e.is_git&&(0,T.jsx)(`button`,{type:`button`,onClick:()=>n(e.path),className:`shrink-0 px-2 py-1 text-2xs text-fg-muted transition-colors hover:text-fg`,children:`choose`})]},e.path)),r.data!==void 0&&r.data.entries.length===0&&(0,T.jsx)(`p`,{className:`px-2 py-1 text-xs text-fg-muted`,children:`No subdirectories.`})]})]})}function k({profileId:e,open:t,onOpenChange:o}){let c=re(),p=u().data?.protocol,S=ne(p),C=ie(p),O=te(),k=d(),A=ae(),j=l(),[M,N]=(0,w.useState)(``),[P,F]=(0,w.useState)(``),[I,L]=(0,w.useState)(!1),[R,z]=(0,w.useState)(``),[B,V]=(0,w.useState)(null),[H,U]=(0,w.useState)(!1),[W,G]=(0,w.useState)(null),[K,q]=(0,w.useState)(null),J=j.data?.home,ce=()=>{let e=M.trim(),t=D(e)&&J!==void 0?E(e.replace(/^~(?=\/|$)/,J)):D(e)&&e.startsWith(`/`)?E(e):J??`/`;X(t)},Y=e=>{F(e),H||z(a(e))},X=e=>{q(e),N(e)},le=e=>{N(e),q(null),Y(e.split(`/`).filter(Boolean).pop()??``),L(!0)},Z=f(oe(M,150)),ue=(0,w.useMemo)(()=>{if(!D(M))return(c.data??[]).map(e=>({value:e.path,badge:`registered`,is_git:!0}));let e=new Set((c.data??[]).map(e=>e.path));return(Z.data?.entries??[]).map(t=>({value:t.path,label:t.name,badge:e.has(t.path)?`registered`:t.is_git?`git`:void 0,is_git:t.is_git}))},[M,c.data,Z.data]),Q=async()=>{G(null);try{let t=E(M),n=c.data?.find(e=>e.path===t)?.id??(await O.mutateAsync({path:t,...S?{default_base_branch:``}:{}})).id,r=await k.mutateAsync({profile_id:e,repo_id:n,name:P.trim(),...C?{colour:B}:{},...s(R)?{abbrev:s(R)}:{}});o(!1),A(`/project/${r.id}`)}catch(e){G(e instanceof Error?e.message:String(e))}},$=P.trim()!==``&&D(M.trim());return(0,T.jsx)(y,{open:t,onOpenChange:o,children:(0,T.jsxs)(g,{children:[(0,T.jsxs)(m,{children:[(0,T.jsx)(_,{children:`New project`}),(0,T.jsx)(v,{children:`Point at a git repository on the daemon host — known repositories are reused.`})]}),(0,T.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),$&&Q()},children:[(0,T.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,T.jsxs)(`div`,{className:`flex items-center justify-between`,children:[(0,T.jsx)(r,{htmlFor:`repo-path`,children:`Repository path`}),(0,T.jsx)(`button`,{type:`button`,onClick:()=>K===null?ce():q(null),className:`text-2xs text-fg-muted transition-colors hover:text-fg`,children:K===null?`browse…`:`hide browser`})]}),(0,T.jsx)(ee,{id:`repo-path`,placeholder:`~/src/my-repo`,value:M,onValueChange:N,onChoose:e=>{!I&&e.is_git&&Y(e.value.split(`/`).filter(Boolean).pop()??``)},hints:ue}),K!==null&&(0,T.jsx)(se,{dir:K,onNavigate:X,onChoose:le})]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,T.jsx)(r,{htmlFor:`project-name`,children:`Project name`}),(0,T.jsx)(b,{id:`project-name`,placeholder:`e.g. checkout-rework`,value:P,className:n(B),onChange:e=>{Y(e.target.value),L(!0)}})]}),(0,T.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,T.jsx)(r,{htmlFor:`project-abbrev`,children:`Abbreviation`}),(0,T.jsx)(b,{id:`project-abbrev`,placeholder:P.trim()?a(P):`ABBRV`,maxLength:5,value:R,onChange:e=>{z(s(e.target.value)),U(!0)},className:`w-24 uppercase`}),(0,T.jsxs)(`p`,{className:`text-2xs text-fg-muted`,children:[`Up to `,5,` characters — the project's label on the collapsed sidebar rail.`]})]}),C&&(0,T.jsxs)(`div`,{className:`flex flex-wrap items-center justify-between gap-2`,children:[(0,T.jsx)(`span`,{className:`text-xs text-fg-secondary`,children:`Colour`}),(0,T.jsx)(i,{value:B,onChange:V,label:`Project colour`})]}),W&&(0,T.jsx)(`p`,{className:`text-xs text-danger`,children:W}),(0,T.jsxs)(h,{children:[(0,T.jsx)(x,{type:`button`,variant:`ghost`,onClick:()=>o(!1),children:`Cancel`}),(0,T.jsx)(x,{type:`submit`,disabled:!$||O.isPending||k.isPending,children:`Create project`})]})]})]})})}export{k as t};
@@ -1,2 +0,0 @@
1
- const __vite__mapDeps=(i,m=__vite__mapDeps,d=(m.f||(m.f=["assets/pdf-EQHMWEbX.js","assets/preload-helper-Czpn1I53.js"])))=>i.map(i=>d[i]);
2
- import{r as e}from"./rolldown-runtime-QTnfLwEv.js";import{t}from"./react-CZI7_Jkm.js";import{O as n}from"./auth-GfOuXpIe.js";import{t as r}from"./jsx-runtime-By8HlURe.js";import{t as i}from"./preload-helper-Czpn1I53.js";import{n as a}from"./api-i6xNY3bF.js";import{n as o}from"./dist-BOS6OKSE.js";import{t as s}from"./createLucideIcon-DyMAgLa3.js";import{i as c,n as l,t as u}from"./scroll-restoration-OVgiE4G9.js";var d=s(`zoom-in`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`line`,{x1:`21`,x2:`16.65`,y1:`21`,y2:`16.65`,key:`13gj7c`}],[`line`,{x1:`11`,x2:`11`,y1:`8`,y2:`14`,key:`1vmskp`}],[`line`,{x1:`8`,x2:`14`,y1:`11`,y2:`11`,key:`durymu`}]]),f=s(`zoom-out`,[[`circle`,{cx:`11`,cy:`11`,r:`8`,key:`4ej97u`}],[`line`,{x1:`21`,x2:`16.65`,y1:`21`,y2:`16.65`,key:`13gj7c`}],[`line`,{x1:`8`,x2:`14`,y1:`11`,y2:`11`,key:`durymu`}]]),p=e(t(),1);function m(e,t){let n=e.getBoundingClientRect(),r=t?.clientX??n.left+e.clientWidth/2,i=t?.clientY??n.top+e.clientHeight/2,a=null,o=1/0;for(let t of e.querySelectorAll(`[data-pdf-page]`)){let e=t.getBoundingClientRect(),n=Math.max(e.top-i,i-e.bottom,0);n<o&&(a=t,o=n)}if(!a)return null;let s=a.getBoundingClientRect();return!s.width||!s.height?null:{page:a,clientX:r,clientY:i,x:(r-s.left)/s.width,y:(i-s.top)/s.height}}function h(e,t){if(!e.contains(t.page))return;let n=t.page.getBoundingClientRect();e.scrollLeft+=n.left+t.x*n.width-t.clientX,e.scrollTop+=n.top+t.y*n.height-t.clientY}var g=[.5,.75,1,1.25,1.5,2,3],_=g[0],v=g.at(-1);function y(e){return E(e,_,v)}function b(e,t){return y(e*Math.exp(-t*.01))}function x(e,t,n){return y(t<=0||n<=0?e:n/t*e)}function S(e){let t=Math.round(y(e)*1e3)/10;return`${Number.isInteger(t)?t.toFixed(0):t.toFixed(1)}%`}function C(e,t){return t===`in`?g.find(t=>t>e+2**-52)??g.at(-1):[...g].reverse().find(t=>t<e-2**-52)??g[0]}function w(e,t,n,r=12e6){let i=Math.max(1,Math.min(n||1,2.5)),a=e*t;return a<=0||r<=0?1:Math.max(.25,Math.min(i,Math.sqrt(r/a)))}function T(e,t,n,r,i){if(n.width<=0||n.height<=0||r<=0||i<=0)return null;let a=E(e-n.left,0,n.width),o=E(t-n.top,0,n.height);return{x:a/n.width*r,y:o/n.height*i}}function E(e,t,n){return Math.min(n,Math.max(t,e))}var D=r(),O=null,k=new l;function A({blob:e,session:t,path:r,root:i,onRevealSource:s,onDownload:l}){let d=c(`pdf`,[t,i,r]),f=(0,p.useRef)(null),g=(0,p.useRef)(null),S=(0,p.useRef)(null),w=(0,p.useRef)(null),[T,E]=(0,p.useState)(()=>k.get(d)??1),O=(0,p.useRef)(T),A=(0,p.useRef)(!1),[I,V]=(0,p.useState)(null),[H,U]=(0,p.useState)(!1),W=L(f);(0,p.useLayoutEffect)(()=>{let e=f.current,t=g.current;if(!e||!t||!I)return;let n=u(e,t,d,()=>t.isConnected&&!A.current&&t.querySelectorAll(`[data-scroll-ready="true"]`).length===I.numPages);return S.current=n,()=>{n.dispose(),S.current=null}},[I,d,W!==null]),(0,p.useLayoutEffect)(()=>{let e=f.current,t=w.current;e&&t&&h(e,t),w.current=null,A.current=!1,t&&S.current?.capture()},[T]);let G=(0,p.useCallback)((e,t)=>{let n=y(e);if(Math.abs(n-O.current)<2**-52)return;let r=f.current;w.current=r?m(r,t):null,O.current=n,k.set(d,n),A.current=!0,E(n)},[d]);(0,p.useEffect)(()=>{let e=f.current;if(!e)return;let t=null,n=t=>{if(!t.ctrlKey)return;t.preventDefault();let n=M(t,e.clientHeight);G(b(O.current,n),t)},r=e=>{if(e.touches.length!==2){t=null;return}t={distance:N(e.touches),zoom:O.current}},i=e=>{!t||e.touches.length!==2||(e.preventDefault(),G(x(t.zoom,t.distance,N(e.touches)),P(e.touches)))},a=e=>{e.touches.length<2&&(t=null)};return e.addEventListener(`wheel`,n,{passive:!1}),e.addEventListener(`touchstart`,r,{passive:!0}),e.addEventListener(`touchmove`,i,{passive:!1}),e.addEventListener(`touchend`,a,{passive:!0}),e.addEventListener(`touchcancel`,a,{passive:!0}),()=>{e.removeEventListener(`wheel`,n),e.removeEventListener(`touchstart`,r),e.removeEventListener(`touchmove`,i),e.removeEventListener(`touchend`,a),e.removeEventListener(`touchcancel`,a)}},[G]),(0,p.useEffect)(()=>{let t=!1,n=null,r=null;return V(null),U(!1),Promise.all([B(),e.arrayBuffer()]).then(([e,r])=>t?null:(n=e.getDocument({data:r}),n.promise)).then(e=>{if(e){if(r=e,t){n?.destroy();return}V(e)}}).catch(e=>{!t&&!z(e)&&U(!0)}),()=>{t=!0,V(null),r&&r.cleanup(),n&&n.destroy()}},[e]);let K=(0,p.useCallback)(async(e,c,l)=>{if(s)try{let o=await a(`POST`,`/api/latex/synctex`,{session:t,path:r,root:i,page:e,x:c,y:l});s(n.parse(o))}catch(e){o.error(e instanceof Error?e.message:`Couldn’t locate the TeX source`)}},[s,r,i,t]);return H?(0,D.jsxs)(R,{children:[(0,D.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`Couldn’t display this PDF.`}),l&&(0,D.jsx)(`button`,{type:`button`,onClick:l,className:`rounded-md bg-elevated px-3 py-1.5 text-sm text-fg transition-colors hover:bg-border/70`,children:`Download`})]}):(0,D.jsxs)(`div`,{className:`relative h-full w-full bg-ground`,children:[(0,D.jsx)(`div`,{ref:f,role:`region`,"aria-label":`PDF document`,className:`h-full w-full overflow-auto`,children:!I||W===null?(0,D.jsx)(R,{children:(0,D.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Loading PDF…`})}):(0,D.jsx)(`div`,{ref:g,className:`flex min-h-full w-max min-w-full flex-col items-center gap-4 p-4`,children:Array.from({length:I.numPages},(e,t)=>(0,D.jsx)(F,{document:I,pageNumber:t+1,availableWidth:W*T,scrollRoot:f.current,inverseSearch:s?K:void 0},t+1))})}),I&&W!==null&&(0,D.jsx)(j,{zoom:T,minimum:_,maximum:v,onZoomOut:()=>G(C(T,`out`)),onReset:()=>G(1),onZoomIn:()=>G(C(T,`in`))})]})}function j({zoom:e,minimum:t,maximum:n,onZoomOut:r,onReset:i,onZoomIn:a}){let o=S(e);return(0,D.jsxs)(`div`,{className:`absolute right-3 top-3 z-10 flex items-center gap-0.5 rounded-md bg-surface/90 p-1 shadow-sm backdrop-blur-sm`,children:[(0,D.jsx)(`button`,{type:`button`,disabled:e<=t,onClick:r,className:`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,"aria-label":`Zoom out`,title:`Zoom out`,children:(0,D.jsx)(f,{className:`size-3.5`})}),(0,D.jsx)(`button`,{type:`button`,onClick:i,className:`min-w-12 cursor-pointer rounded-sm px-1.5 py-1 font-mono text-[11px] tabular-nums text-fg-secondary transition-colors hover:bg-elevated hover:text-fg`,"aria-label":`Zoom ${o}; reset to fit width`,title:`Reset to fit width`,children:o}),(0,D.jsx)(`button`,{type:`button`,disabled:e>=n,onClick:a,className:`cursor-pointer rounded-sm p-1 text-fg-muted transition-colors hover:bg-elevated hover:text-fg disabled:cursor-default disabled:opacity-40`,"aria-label":`Zoom in`,title:`Zoom in`,children:(0,D.jsx)(d,{className:`size-3.5`})})]})}function M(e,t){return e.deltaMode===WheelEvent.DOM_DELTA_LINE?e.deltaY*16:e.deltaMode===WheelEvent.DOM_DELTA_PAGE?e.deltaY*t:e.deltaY}function N(e){let t=e.item(0),n=e.item(1);return!t||!n?0:Math.hypot(n.clientX-t.clientX,n.clientY-t.clientY)}function P(e){let t=e.item(0),n=e.item(1);if(!(!t||!n))return{clientX:(t.clientX+n.clientX)/2,clientY:(t.clientY+n.clientY)/2}}function F({document:e,pageNumber:t,availableWidth:n,scrollRoot:r,inverseSearch:i}){let a=(0,p.useRef)(null),o=(0,p.useRef)(null),s=(0,p.useRef)(null),[c,l]=(0,p.useState)(null),[u,d]=(0,p.useState)(null),[f,m]=(0,p.useState)(!1),h=I(a,r,t<=2);(0,p.useEffect)(()=>{let n=!1,r=null;return l(null),d(null),m(!1),e.getPage(t).then(e=>{if(r=e,n){e.cleanup();return}let t=e.getViewport({scale:1});d({width:t.width,height:t.height}),l(e)}).catch(e=>{!n&&!z(e)&&m(!0)}),()=>{n=!0,s.current?.cancel(),s.current=null,r?.cleanup()}},[e,t]),(0,p.useEffect)(()=>{let e=o.current;if(!e||!c||!u||!h)return;let t=n/u.width,r=c.getViewport({scale:t}),i=w(r.width,r.height,window.devicePixelRatio||1),a=c.getViewport({scale:t*i});s.current?.cancel(),e.width=Math.max(1,Math.floor(a.width)),e.height=Math.max(1,Math.floor(a.height)),e.style.width=`${r.width}px`,e.style.height=`${r.height}px`;let l=c.render({canvas:e,viewport:a});return s.current=l,l.promise.catch(e=>{z(e)||m(!0)}).finally(()=>{s.current===l&&(s.current=null)}),()=>{l.cancel(),s.current===l&&(s.current=null)}},[n,c,u,h]);let g=e=>{if(!e.metaKey&&!e.ctrlKey||!i||!u)return;let n=T(e.clientX,e.clientY,e.currentTarget.getBoundingClientRect(),u.width,u.height);n&&(e.preventDefault(),i(t,n.x,n.y))};if(f)return(0,D.jsxs)(`p`,{"data-scroll-ready":`true`,className:`py-8 text-xs text-fg-muted`,children:[`Couldn’t render page `,t,`.`]});let _=Math.round(u?n/u.width*u.height:n*1.3);return(0,D.jsx)(`div`,{ref:a,"data-scroll-ready":u!==null,"data-pdf-page":t,className:`shrink-0 bg-elevated shadow-sm`,style:{width:n,height:_},"aria-label":`PDF page ${t}`,children:(0,D.jsx)(`canvas`,{ref:o,onClick:g,className:`block`,title:i?`Command-click to open the corresponding TeX source`:void 0})})}function I(e,t,n){let[r,i]=(0,p.useState)(n);return(0,p.useEffect)(()=>{if(r)return;let n=e.current;if(!n)return;let a=new IntersectionObserver(e=>{e.some(e=>e.isIntersecting)&&(i(!0),a.disconnect())},{root:t,rootMargin:`100% 0px`});return a.observe(n),()=>a.disconnect()},[r,e,t]),r}function L(e){let[t,n]=(0,p.useState)(null);return(0,p.useLayoutEffect)(()=>{let t=e.current;if(!t)return;let r=0,i=()=>{cancelAnimationFrame(r),r=requestAnimationFrame(()=>{t.clientWidth>32&&n(t.clientWidth-32)})};i();let a=new ResizeObserver(i);return a.observe(t),()=>{cancelAnimationFrame(r),a.disconnect()}},[e]),t}function R({children:e}){return(0,D.jsx)(`div`,{className:`flex h-full min-h-32 w-full flex-col items-center justify-center gap-3 p-4`,children:e})}function z(e){return e instanceof Error&&(e.name===`RenderingCancelledException`||e.name===`AbortException`)}async function B(){return O??=Promise.all([i(()=>import(`./pdf-EQHMWEbX.js`),__vite__mapDeps([0,1])),i(()=>import(`./pdf.worker.min-C8Ts8bNu.js`),[])]).then(([e,t])=>(e.GlobalWorkerOptions.workerSrc=t.default,e)).catch(e=>{throw O=null,e}),O}export{A as PdfViewer};
@@ -1,8 +0,0 @@
1
- import{r as e,t}from"./rolldown-runtime-QTnfLwEv.js";import{t as n}from"./react-CZI7_Jkm.js";import{B as r,F as i,I as a,L as o,R as s,U as c,_ as l,g as u,h as d,m as f,v as p}from"./auth-GfOuXpIe.js";import{c as m,i as h,o as g,r as _,s as v}from"./LazyTerminal-CgQryH0p.js";import{a as y,c as b,d as x,f as S,g as C,i as w,l as ee,n as T,o as te,p as ne,r as re,s as ie,t as ae,u as oe}from"./notification-delivery-Dfvdt_1U.js";import{a as se,i as ce,r as E,t as le}from"./client-settings-CwqpIric.js";import{t as ue}from"./jsx-runtime-By8HlURe.js";import{d as de,o as fe,t as pe}from"./index-np8JXeG6.js";import{n as me,t as he}from"./api-i6xNY3bF.js";import{_ as ge,a as _e,f as ve,g as D,i as ye,m as be,n as xe,t as Se}from"./hotkeys-1uTWFYAL.js";import{$ as Ce,A as we,F as Te,J as Ee,K as De,L as Oe,R as ke,T as Ae,U as je,V as Me,W as Ne,X as Pe,Z as Fe,at as Ie,c as Le,et as O,ft as Re,it as k,k as ze,n as Be,nt as Ve,pt as He,st as Ue,w as We,wt as Ge,xt as Ke}from"./protocol-support-BGmIChNK.js";import{n as A}from"./dist-BOS6OKSE.js";import{a as qe,i as j,n as M,o as N,r as P,t as F}from"./dialog-BMWRC2HO.js";import{n as I}from"./x-DCpy1q13.js";import{n as Je,t as L}from"./input-CxgRsoVg.js";import{n as Ye,r as Xe}from"./dist-Cde1E3eV.js";import{t as R}from"./button-BgeBH2Uc.js";import{t as z}from"./createLucideIcon-DyMAgLa3.js";import{a as Ze,c as Qe,i as $e,l as et,n as tt,r as nt,s as rt,t as B}from"./switch-DhNyUV8C.js";import{a as V,i as H,n as U,r as W,t as G}from"./select-Bg0rWqco.js";import{t as it}from"./code-DRWf9a5s.js";import{t as at}from"./rotate-ccw-CNjR2LSi.js";import{n as K}from"./errors-O9DWXa3f.js";import{t as ot}from"./use-debounced-value-C86N-mOK.js";import{n as st,r as ct,t as lt}from"./popover-CCHRaCvX.js";import{d as ut,i as dt,n as ft,o as pt,s as mt,t as ht}from"./disclosure-CHXbNzgZ.js";var gt=z(`bell`,[[`path`,{d:`M10.268 21a2 2 0 0 0 3.464 0`,key:`vwvbt9`}],[`path`,{d:`M3.262 15.326A1 1 0 0 0 4 17h16a1 1 0 0 0 .74-1.673C19.41 13.956 18 12.499 18 8A6 6 0 0 0 6 8c0 4.499-1.411 5.956-2.738 7.326`,key:`11g9vi`}]]),_t=z(`keyboard`,[[`path`,{d:`M10 8h.01`,key:`1r9ogq`}],[`path`,{d:`M12 12h.01`,key:`1mp3jc`}],[`path`,{d:`M14 8h.01`,key:`1primd`}],[`path`,{d:`M16 12h.01`,key:`1l6xoz`}],[`path`,{d:`M18 8h.01`,key:`emo2bl`}],[`path`,{d:`M6 8h.01`,key:`x9i8wu`}],[`path`,{d:`M7 16h10`,key:`wp8him`}],[`path`,{d:`M8 12h.01`,key:`czm47f`}],[`rect`,{width:`20`,height:`16`,x:`2`,y:`4`,rx:`2`,key:`18n3k1`}]]),vt=z(`server`,[[`rect`,{width:`20`,height:`8`,x:`2`,y:`2`,rx:`2`,ry:`2`,key:`ngkwjq`}],[`rect`,{width:`20`,height:`8`,x:`2`,y:`14`,rx:`2`,ry:`2`,key:`iecqi9`}],[`line`,{x1:`6`,x2:`6.01`,y1:`6`,y2:`6`,key:`16zg32`}],[`line`,{x1:`6`,x2:`6.01`,y1:`18`,y2:`18`,key:`nzw8ys`}]]),yt=z(`shield-alert`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`M12 8v4`,key:`1got3b`}],[`path`,{d:`M12 16h.01`,key:`1drbdi`}]]),bt=z(`shield-check`,[[`path`,{d:`M20 13c0 5-3.5 7.5-7.66 8.95a1 1 0 0 1-.67-.01C7.5 20.5 4 18 4 13V6a1 1 0 0 1 1-1c2 0 4.5-1.2 6.24-2.72a1.17 1.17 0 0 1 1.52 0C14.51 3.81 17 5 19 5a1 1 0 0 1 1 1z`,key:`oel41y`}],[`path`,{d:`m9 12 2 2 4-4`,key:`dzmm74`}]]),xt=z(`sliders-horizontal`,[[`path`,{d:`M10 5H3`,key:`1qgfaw`}],[`path`,{d:`M12 19H3`,key:`yhmn1j`}],[`path`,{d:`M14 3v4`,key:`1sua03`}],[`path`,{d:`M16 17v4`,key:`1q0r14`}],[`path`,{d:`M21 12h-9`,key:`1o4lsq`}],[`path`,{d:`M21 19h-5`,key:`1rlt1p`}],[`path`,{d:`M21 5h-7`,key:`1oszz2`}],[`path`,{d:`M8 10v4`,key:`tgpxqk`}],[`path`,{d:`M8 12H3`,key:`a7s4jb`}]]),St=z(`users`,[[`path`,{d:`M16 21v-2a4 4 0 0 0-4-4H6a4 4 0 0 0-4 4v2`,key:`1yyitq`}],[`path`,{d:`M16 3.128a4 4 0 0 1 0 7.744`,key:`16gr8j`}],[`path`,{d:`M22 21v-2a4 4 0 0 0-3-3.87`,key:`kshegd`}],[`circle`,{cx:`9`,cy:`7`,r:`4`,key:`nufk8`}]]),q=e(n(),1),J=ue();function Ct({id:e,value:t,min:n,max:r,step:i,className:a,onCommit:o}){let[s,c]=(0,q.useState)(String(t));return(0,q.useEffect)(()=>c(String(t)),[t]),(0,J.jsx)(L,{id:e,type:`number`,min:n,max:r,step:i,className:a,value:s,onChange:e=>c(e.target.value),onBlur:()=>{let e=Number(s);if(s.trim()===``||!Number.isFinite(e)){c(String(t));return}let i=Math.min(r??e,Math.max(n??e,e));c(String(i)),i!==t&&o(i)},onKeyDown:e=>{e.key===`Enter`&&e.target.blur()}})}function Y({label:e,description:t,descriptionClassName:n,htmlFor:r,children:i,className:a}){return(0,J.jsxs)(`div`,{className:I(`flex items-center gap-4 py-2.5`,a),children:[(0,J.jsxs)(`label`,{htmlFor:r,className:`flex min-w-0 flex-1 flex-col gap-0.5`,children:[(0,J.jsx)(`span`,{className:`text-sm text-fg`,children:e}),t&&(0,J.jsx)(`span`,{className:I(`text-xs text-fg-muted`,n),children:t})]}),(0,J.jsx)(`div`,{className:`flex shrink-0 items-center gap-2`,children:i})]})}function X({children:e,note:t}){return(0,J.jsxs)(`div`,{className:`mb-2 flex flex-col gap-0.5`,children:[(0,J.jsx)(`h2`,{className:`text-base font-semibold text-fg`,children:e}),t&&(0,J.jsx)(`span`,{className:`text-xs text-fg-muted`,children:t})]})}function wt(){let e=ce(),[t,n]=(0,q.useState)(fe());return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Appearance`}),(0,J.jsx)(Y,{label:`Theme`,children:(0,J.jsxs)(G,{value:t,onValueChange:e=>{n(e),pe(e)},children:[(0,J.jsx)(H,{className:`w-32`,children:(0,J.jsx)(V,{})}),(0,J.jsxs)(U,{children:[(0,J.jsx)(W,{value:`dark`,children:`Dark`}),(0,J.jsx)(W,{value:`light`,children:`Light`}),(0,J.jsx)(W,{value:`system`,children:`System`})]})]})}),(0,J.jsx)(Y,{label:`Cursor style`,children:(0,J.jsxs)(G,{value:e.cursorPackage,onValueChange:e=>E({cursorPackage:e}),children:[(0,J.jsx)(H,{className:`w-36`,children:(0,J.jsx)(V,{})}),(0,J.jsx)(U,{children:se.map(e=>(0,J.jsx)(W,{value:e.id,children:e.label},e.id))})]})}),(0,J.jsx)(Y,{label:`UI font size`,htmlFor:`ui-font-size`,children:(0,J.jsx)(Ct,{id:`ui-font-size`,min:12,max:24,step:.5,className:`w-20 tabular-nums`,value:e.uiFontSize,onCommit:e=>E({uiFontSize:e})})}),(0,J.jsx)(Y,{label:`Terminal font size`,htmlFor:`terminal-font-size`,children:(0,J.jsx)(Ct,{id:`terminal-font-size`,min:9,max:24,className:`w-20 tabular-nums`,value:e.terminalFontSize,onCommit:e=>E({terminalFontSize:e})})}),(0,J.jsx)(Y,{label:`Editor font size`,htmlFor:`editor-font-size`,children:(0,J.jsx)(Ct,{id:`editor-font-size`,min:9,max:32,step:.5,className:`w-20 tabular-nums`,value:e.editorFontSize,onCommit:e=>E({editorFontSize:e})})}),(0,J.jsx)(Y,{label:`Density`,children:(0,J.jsxs)(G,{value:e.density,onValueChange:e=>E({density:e}),children:[(0,J.jsx)(H,{className:`w-36`,children:(0,J.jsx)(V,{})}),(0,J.jsxs)(U,{children:[(0,J.jsx)(W,{value:`compact`,children:`Compact`}),(0,J.jsx)(W,{value:`comfortable`,children:`Comfortable`})]})]})}),(0,J.jsx)(Y,{label:`Project-based layout`,description:`Editor layouts are separated across projects.`,htmlFor:`project-based-layout`,children:(0,J.jsx)(B,{id:`project-based-layout`,checked:e.projectBasedLayout,onCheckedChange:e=>E({projectBasedLayout:e})})}),(0,J.jsx)(Y,{label:`All projects in the session list`,description:`Right sidebar displays sessions from all projects.`,htmlFor:`show-all-project-sessions`,children:(0,J.jsx)(B,{id:`show-all-project-sessions`,checked:e.showAllProjectSessions,onCheckedChange:e=>E({showAllProjectSessions:e})})})]})}function Tt({profile:e}){let t=Ce(),[n,r]=(0,q.useState)(!1),i=n=>{t.mutate({id:e.id,icon:n},{onError:e=>K(e)}),r(!1)};return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{label:`Icon`,children:(0,J.jsxs)(lt,{open:n,onOpenChange:r,children:[(0,J.jsx)(ct,{asChild:!0,children:(0,J.jsxs)(`button`,{type:`button`,className:`flex size-9 items-center justify-center rounded-md text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,J.jsx)(S,{icon:e.icon,colour:e.icon_colour,className:`size-5`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Choose an icon`})]})}),(0,J.jsx)(st,{align:`end`,className:`w-72`,children:(0,J.jsxs)(`div`,{className:`grid grid-cols-8 gap-1`,children:[(0,J.jsx)(`button`,{type:`button`,title:`Default`,onClick:()=>i(null),className:I(`flex h-8 items-center justify-center rounded-md text-fg-secondary transition-colors hover:bg-elevated hover:text-fg`,!e.icon&&`bg-elevated text-fg`),children:(0,J.jsx)(S,{icon:null,colour:null,className:`size-4`})}),ne.map(({name:t,Icon:n})=>(0,J.jsx)(`button`,{type:`button`,title:t,onClick:()=>i(t),className:I(`flex h-8 items-center justify-center rounded-md text-fg-secondary transition-colors hover:bg-elevated hover:text-fg`,e.icon===t&&`bg-elevated text-fg`),children:(0,J.jsx)(n,{className:`size-4`})},t))]})})]})}),(0,J.jsx)(Y,{label:`Icon colour`,children:(0,J.jsx)(h,{value:e.icon_colour,onChange:n=>t.mutate({id:e.id,icon_colour:n},{onError:e=>K(e)}),label:`Icon colour`})})]})}var Et=`__none__`;function Dt(){let e=D(),t=Ie().data?.find(t=>t.id===e),n=We(e??void 0),r=k(e??void 0),i=Ce(),a=O(e??``),o=Me(),[s,c]=(0,q.useState)(``),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(!1),[p,h]=(0,q.useState)(``);if((0,q.useEffect)(()=>{t&&(c(t.name),u(t.branch_prefix))},[t]),!t)return null;let g=r.data?.default_account_id;return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Profile`}),(0,J.jsxs)(Y,{label:`Name`,description:`Letters, digits, dot, underscore and hyphen.`,htmlFor:`profile-name`,children:[(0,J.jsx)(L,{id:`profile-name`,value:s,onChange:e=>c(e.target.value),className:`w-44`}),(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:s===t.name||s.trim()===``||i.isPending,onClick:()=>i.mutate({id:t.id,name:s},{onError:e=>K(e)}),children:`Save`})]}),(0,J.jsxs)(Y,{label:`Branch prefix`,description:`Session branches become <prefix><slug(title)>.`,htmlFor:`branch-prefix`,children:[(0,J.jsx)(L,{id:`branch-prefix`,value:l,onChange:e=>u(e.target.value),placeholder:`no prefix`,className:`w-44`}),(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:l===t.branch_prefix||i.isPending,onClick:()=>i.mutate({id:t.id,branch_prefix:l},{onError:e=>K(e)}),children:`Save`})]}),(0,J.jsx)(Tt,{profile:t}),(0,J.jsx)(Y,{label:`Default account`,description:`Preselected in the new-session modal.`,children:(0,J.jsxs)(G,{value:typeof g==`number`?String(g):Et,onValueChange:e=>a.mutate({default_account_id:e===Et?null:Number(e)},{onError:e=>K(e)}),children:[(0,J.jsx)(H,{className:`w-56`,children:(0,J.jsx)(V,{})}),(0,J.jsxs)(U,{children:[(0,J.jsx)(W,{value:Et,children:`First available`}),n.data?.map(e=>(0,J.jsx)(W,{value:String(e.id),children:(0,J.jsxs)(`span`,{children:[e.agent_type,`/`,e.label]})},e.id))]})]})}),(0,J.jsx)(Y,{label:`Delete profile`,description:`Non-archived sessions block deletion.`,className:`mt-4`,children:(0,J.jsx)(R,{variant:`danger`,size:`sm`,onClick:()=>f(!0),children:`Delete…`})}),(0,J.jsx)(F,{open:d,onOpenChange:e=>{e||(f(!1),h(``))},children:(0,J.jsxs)(M,{children:[(0,J.jsxs)(qe,{children:[(0,J.jsxs)(N,{children:[`Delete profile `,(0,J.jsx)(`span`,{className:`text-fg`,children:t.name}),`?`]}),(0,J.jsx)(P,{children:`Everything this profile owns goes with it: projects, workspace layouts, accounts and their credential directories, and archived session history. Branches, repositories, and terminal logs on disk are untouched. This cannot be undone.`})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsxs)(m,{htmlFor:`delete-confirm-name`,children:[`Type `,(0,J.jsx)(`span`,{className:`text-fg`,children:t.name}),` to confirm`]}),(0,J.jsx)(L,{id:`delete-confirm-name`,value:p,onChange:e=>h(e.target.value),autoFocus:!0})]}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,onClick:()=>{f(!1),h(``)},children:`Cancel`}),(0,J.jsx)(R,{variant:`danger`,disabled:p!==t.name||o.isPending,onClick:()=>o.mutate(t.id,{onSuccess:()=>{nt(),be.set(null)},onError:e=>{f(!1),h(``),K(e)}}),children:`Delete profile`})]})]})})]})}function Ot({agent:e,profileId:t,onClose:n,onCreated:r}){let i=we(),[a,o]=(0,q.useState)(``),[s,c]=(0,q.useState)(``),l=je(ot(s,150)),u=s.trim(),d=u===``||u.startsWith(`/`)||u.startsWith(`~`),f=a.trim()!==``&&d,p=()=>{!f||i.isPending||i.mutate({profile_id:t,agent_type:e.id,label:a.trim(),...u===``?{}:{import_dir:u}},{onSuccess:e=>{n(),r(e,u!==``)},onError:e=>K(e)})};return(0,J.jsx)(F,{open:!0,onOpenChange:e=>!e&&n(),children:(0,J.jsxs)(M,{children:[(0,J.jsxs)(qe,{children:[(0,J.jsxs)(N,{children:[`Add a `,e.display_name,` account`]}),(0,J.jsxs)(P,{children:[`Accounts are isolated config dirs under this profile. Naming one is enough — Puddle creates it and takes you straight to `,e.display_name,`’s login. To reuse an account you already have on this machine, give its config directory: it is copied in and the original is never touched.`]})]}),(0,J.jsxs)(`form`,{className:`flex flex-col gap-3`,onSubmit:e=>{e.preventDefault(),p()},children:[(0,J.jsx)(L,{autoFocus:!0,placeholder:`label, e.g. personal`,value:a,onChange:e=>o(e.target.value)}),(0,J.jsx)(_,{value:s,onValueChange:c,placeholder:`(optional) existing config dir, e.g. ~/.claude`,hints:(l.data?.entries??[]).map(e=>({value:e.path,label:e.name}))})]}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,onClick:n,children:`Cancel`}),(0,J.jsxs)(R,{disabled:!f||i.isPending,onClick:p,children:[(0,J.jsx)(Xe,{}),`Add account`]})]})]})})}function kt({account:e,gateOpen:t,installed:n}){let r=Ee(),i=Pe(),a=ke(),[o,s]=(0,q.useState)(null),[c,l]=(0,q.useState)(!1),[u,d]=(0,q.useState)(e.label),f=(0,q.useRef)(null);return(0,q.useEffect)(()=>d(e.label),[e.label]),(0,J.jsxs)(`div`,{className:`flex items-center gap-3 rounded-md bg-surface px-3 py-2`,children:[(0,J.jsxs)(`span`,{className:`min-w-0 flex-1`,children:[(0,J.jsxs)(`span`,{className:`flex items-center gap-1`,children:[(0,J.jsx)(`input`,{ref:f,value:u,onChange:e=>d(e.target.value),onBlur:()=>{let t=u.trim();if(t!==e.label){if(t===``){d(e.label);return}i.mutate({id:e.id,label:t},{onError:t=>{K(t),d(e.label)}})}},onKeyDown:t=>{t.key===`Enter`?t.currentTarget.blur():t.key===`Escape`&&(d(e.label),t.currentTarget.blur())},"aria-label":`Account name`,className:`-mx-1 block w-full min-w-0 truncate rounded-sm bg-transparent px-1 py-0.5 text-sm text-fg transition-colors hover:bg-elevated focus:bg-elevated focus:outline-none`}),(0,J.jsxs)(`button`,{type:`button`,title:`Rename account`,onClick:()=>{f.current?.focus(),f.current?.select()},className:`shrink-0 rounded-sm p-0.5 text-fg-muted transition-colors hover:bg-elevated hover:text-fg`,children:[(0,J.jsx)(g,{className:`size-3`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Rename account`})]})]}),(0,J.jsx)(`span`,{className:`text-2xs ${e.logged_in?`text-success`:`text-warning`}`,children:e.logged_in?`logged in`:`not logged in`})]}),t&&(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-xs text-fg-secondary`,children:[`skip prompts`,(0,J.jsx)(B,{checked:e.skip_permissions_default,onCheckedChange:t=>i.mutate({id:e.id,skip_permissions_default:t},{onError:e=>K(e)})})]}),(0,J.jsxs)(R,{size:`sm`,variant:`secondary`,disabled:r.isPending||!n,onClick:()=>r.mutate(e.id,{onSuccess:e=>s({stream:e.stream,hint:e.hint}),onError:e=>K(e)}),children:[(0,J.jsx)(C,{}),e.logged_in?`Re-login`:`Login`]}),(0,J.jsxs)(R,{size:`icon`,variant:`ghost`,className:`size-7 text-fg-muted hover:text-danger`,onClick:()=>l(!0),children:[(0,J.jsx)(Ye,{}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Delete account`})]}),o&&(0,J.jsx)(x,{stream:o.stream,hint:o.hint,label:`${e.agent_type}/${e.label}`,onClose:()=>s(null)}),(0,J.jsx)(F,{open:c,onOpenChange:l,children:(0,J.jsxs)(M,{children:[(0,J.jsxs)(qe,{children:[(0,J.jsxs)(N,{children:[`Delete `,(0,J.jsx)(`span`,{className:`text-fg`,children:e.label}),`?`]}),(0,J.jsx)(P,{children:`Removes the account, its archived session history, and its credential directory — this logs the account out. Non-archived sessions block deletion.`})]}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,onClick:()=>l(!1),children:`Cancel`}),(0,J.jsx)(R,{variant:`danger`,disabled:a.isPending,onClick:()=>a.mutate(e.id,{onSuccess:()=>l(!1),onError:e=>{l(!1),K(e)}}),children:`Delete account`})]})]})})]})}function At(){let e=D(),t=Ae(),n=We(e??void 0),r=k(e??void 0),i=Ee(),[a,o]=(0,q.useState)(null),[s,c]=(0,q.useState)(null),l=r.data?.allowSkipPermissions===!0;return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Accounts`}),t.data?.map(e=>{let t=n.data?.filter(t=>t.agent_type===e.id)??[],r=e.available!==!1;return(0,J.jsxs)(`div`,{className:`mb-5`,children:[(0,J.jsx)(Y,{label:e.display_name,description:r?`Accounts are initialised in config dirs owned by this profile.`:`No ${e.binary??e.id} on the daemon’s PATH. Install it or add its directory to the agent search path in Sessions.`,className:`py-1`,children:(0,J.jsx)(`span`,{className:`text-2xs text-fg-muted`,children:e.id})}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[t.map(t=>(0,J.jsx)(kt,{account:t,gateOpen:l&&e.capabilities.skip_permissions,installed:r},t.id)),(0,J.jsx)(`div`,{className:`flex`,children:(0,J.jsxs)(R,{type:`button`,size:`sm`,variant:`secondary`,disabled:!r,onClick:()=>c(e),children:[(0,J.jsx)(Xe,{}),`Add account`]})})]})]},e.id)}),a&&(0,J.jsx)(x,{stream:a.stream,label:a.label,hint:a.hint,onClose:()=>o(null)}),s!==null&&e!==null&&(0,J.jsx)(Ot,{agent:s,profileId:e,onClose:()=>c(null),onCreated:(e,t)=>{if(t){e.logged_in||A.info(`Imported without credentials — press Login to authenticate.`);return}i.mutate(e.id,{onSuccess:t=>o({stream:t.stream,label:`${e.agent_type}/${e.label}`,hint:t.hint}),onError:e=>K(e)})}})]})}function jt(){let e=ze(),t=Fe(),[n,r]=(0,q.useState)(``);return(0,q.useEffect)(()=>{e.data&&r(e.data.agentPath)},[e.data]),(0,J.jsx)(Y,{label:`Agent search path (host-wide)`,description:`Colon-separated dirs the daemon prepends to PATH; helps find agent CLIs like claude (e.g. ~/.local/bin).`,htmlFor:`agent-path`,children:(0,J.jsx)(L,{id:`agent-path`,type:`text`,className:`w-64 text-2xs`,value:n,onChange:e=>r(e.target.value),onBlur:()=>{e.data&&n!==e.data.agentPath&&t.mutate({agentPath:n})}})})}function Mt({kind:e,heading:t,settings:n,onSave:r,pending:i}){let a=ut(e,n),o=n.sessionDefaults??{},[s,c]=(0,q.useState)(a.baseBranch),l=t=>r({...o,[e]:{...o[e],...t}});return(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(`p`,{className:`mb-1 mt-4 text-xs font-medium uppercase tracking-wide text-fg-gold`,children:t}),(0,J.jsx)(Y,{label:`Base branch`,description:`Blank = the repository's default base branch.`,htmlFor:`${e}-default-base`,children:(0,J.jsx)(L,{id:`${e}-default-base`,type:`text`,placeholder:`repository default`,className:`w-48`,value:s,onChange:e=>c(e.target.value),onBlur:()=>{s.trim()!==a.baseBranch&&l({baseBranch:s.trim()})}})}),(0,J.jsx)(Y,{label:`Separate branch`,description:`Start on a fresh branch off the base, in its own directory.`,htmlFor:`${e}-default-branch`,children:(0,J.jsx)(B,{id:`${e}-default-branch`,checked:a.separateBranch,disabled:i,onCheckedChange:e=>l({separateBranch:e})})}),(0,J.jsx)(Y,{label:`Separate directory`,description:a.separateBranch?`Always on while a separate branch is used.`:`Start on working copy of the selected branch instead of sharing one directory.`,htmlFor:`${e}-default-dir`,children:(0,J.jsx)(B,{id:`${e}-default-dir`,checked:a.separateWorktree,disabled:i||a.separateBranch,onCheckedChange:e=>l({separateWorktree:e})})})]})}function Nt(){return(0,J.jsx)(Y,{label:`Terminal scrollback`,htmlFor:`scrollback`,children:(0,J.jsx)(Ct,{id:`scrollback`,min:500,max:1e5,step:500,className:`w-28 tabular-nums`,value:ce().terminalScrollback,onCommit:e=>E({terminalScrollback:e})})})}function Pt({id:e,label:t,description:n,initial:r,defaultText:i,onSave:a,pending:o}){let[s,c]=(0,q.useState)(r);return(0,J.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,J.jsxs)(`label`,{htmlFor:e,className:`flex flex-col gap-0.5 text-sm text-fg`,children:[t,(0,J.jsx)(`span`,{className:`text-xs text-fg-muted`,children:n})]}),(0,J.jsx)(Je,{id:e,value:s,onChange:e=>c(e.target.value),rows:6,className:`font-mono`}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:s===r||o,onClick:()=>a(s),children:`Save`}),(0,J.jsx)(R,{size:`sm`,variant:`ghost`,disabled:s===i||o,onClick:()=>{c(i),a(i)},children:`Reset to default`})]})]})}var Ft={id:`4f3c2b1a-7e6d-5c4b-3a2f-1e0d9c8b7a6f`,title:null,agent_title:`Refactor the auth flow`,osc_title:`claude`,branch:`alice/refactor-auth`,worktree_path:`/home/alice/code/app--refactor-auth`,status:`waiting_input`,agent_type:`claude-code`};function It({initial:e,onSave:t,pending:n}){let[i,a]=(0,q.useState)(e),o=i.length>0?i:s;return(0,J.jsxs)(`div`,{className:`mt-3 flex flex-col gap-1.5`,children:[(0,J.jsxs)(`label`,{htmlFor:`tab-title-template`,className:`flex flex-col gap-0.5 text-sm text-fg`,children:[`Template`,(0,J.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Compose the label from the parts below. Empty falls back to the default.`})]}),(0,J.jsx)(L,{id:`tab-title-template`,value:i,onChange:e=>a(e.target.value),className:`font-mono`,placeholder:s}),(0,J.jsxs)(`p`,{className:`text-xs text-fg-muted`,children:[`Preview`,` `,(0,J.jsx)(`span`,{className:`ml-1 font-sans text-fg`,children:tt(Ft,o)})]}),(0,J.jsx)(`dl`,{className:`mt-1 flex flex-col gap-0.5 text-xs`,children:r.map(([e,t])=>(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(`dt`,{className:`w-24 shrink-0 font-mono text-fg-secondary`,children:`\${${e}}`}),(0,J.jsx)(`dd`,{className:`text-fg-muted`,children:t})]},e))}),(0,J.jsxs)(`div`,{className:`flex gap-2`,children:[(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:i===e||n,onClick:()=>t(i),children:`Save`}),(0,J.jsx)(R,{size:`sm`,variant:`ghost`,disabled:i==="${name}"||n,onClick:()=>{a(s),t(s)},children:`Reset to default`})]})]})}function Lt(){let e=D(),t=Ie().data?.find(t=>t.id===e),n=k(e??void 0),r=O(e??``),[s,c]=(0,q.useState)(!1),[l,u]=(0,q.useState)(``),d=n.data?.allowSkipPermissions===!0,f=e=>r.mutate({allowSkipPermissions:e},{onSuccess:()=>{c(!1),u(``)},onError:e=>K(e)}),p=e=>t=>r.mutate({[e]:t},{onError:e=>K(e)});return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Sessions`}),(0,J.jsx)(Y,{label:`Skip permission prompts`,htmlFor:`gate`,children:(0,J.jsx)(B,{id:`gate`,checked:d,onCheckedChange:e=>{e?c(!0):f(!1)}})}),(0,J.jsx)(Y,{label:`Capture exported env variables`,description:n.data?.captureSessionEnv===!1?`No variables are captured or injected; already-captured variabless are kept for when this is re-enabled.`:`Variables exported in a session persist and are re-injected upon terminal and agent restarts.`,htmlFor:`capture-env`,children:(0,J.jsx)(B,{id:`capture-env`,checked:n.data?.captureSessionEnv!==!1,disabled:r.isPending,onCheckedChange:e=>r.mutate({captureSessionEnv:e},{onError:e=>K(e)})})}),(0,J.jsx)(jt,{}),(0,J.jsx)(Nt,{}),(0,J.jsxs)(`div`,{className:`mt-5`,children:[(0,J.jsx)(X,{children:`New session defaults`}),n.data&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Mt,{kind:`agent`,heading:`New agents`,settings:n.data,onSave:e=>r.mutate({sessionDefaults:e},{onError:e=>K(e)}),pending:r.isPending},`${e}:agent-seed`),(0,J.jsx)(Mt,{kind:`terminal`,heading:`New terminals`,settings:n.data,onSave:e=>r.mutate({sessionDefaults:e},{onError:e=>K(e)}),pending:r.isPending},`${e}:terminal-seed`)]})]}),(0,J.jsxs)(`div`,{className:`mt-5`,children:[(0,J.jsx)(X,{note:`Sent to agent as opening message when a session (re)starts. You can make this empty.`,children:`Launch text`}),n.data&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Pt,{id:`onboarding-template`,label:`New worktree`,description:`Use {{rules}} where the repo's onboarding notes should appear.`,initial:n.data.onboardingTemplate??a,defaultText:a,onSave:p(`onboardingTemplate`),pending:r.isPending},`${e}:onboarding`),(0,J.jsx)(Pt,{id:`concurrent-template`,label:`Existing / shared worktree`,description:`For a session joining a worktree other agents may already be working in.`,initial:n.data.concurrentTemplate??i,defaultText:i,onSave:p(`concurrentTemplate`),pending:r.isPending},`${e}:concurrent`),(0,J.jsx)(Pt,{id:`restart-template`,label:`Resume after restart`,description:`Sent when a session resumes after a daemon restart or machine reboot.`,initial:n.data.restartTemplate??o,defaultText:o,onSave:p(`restartTemplate`),pending:r.isPending},`${e}:restart`)]})]}),(0,J.jsxs)(`div`,{className:`mt-5`,children:[(0,J.jsx)(X,{children:`Tab title`}),n.data&&(0,J.jsx)(It,{initial:n.data.tabTitleTemplate||"${name}",onSave:p(`tabTitleTemplate`),pending:r.isPending},`${e}:tab-title`)]}),(0,J.jsx)(F,{open:s,onOpenChange:e=>{e||(c(!1),u(``))},children:(0,J.jsxs)(M,{children:[(0,J.jsxs)(qe,{children:[(0,J.jsxs)(N,{className:`flex items-center gap-2`,children:[(0,J.jsx)(yt,{className:`size-5 text-danger`}),`Run agents without permission prompts?`]}),(0,J.jsx)(P,{asChild:!0,children:(0,J.jsxs)(`div`,{className:`flex flex-col gap-2 text-sm`,children:[(0,J.jsx)(`p`,{children:`A prompt-free agent acts unattended, with your credentials, inside its worktree — and nothing technically stops a shell command from reaching outside it. It can:`}),(0,J.jsxs)(`ul`,{className:`list-disc pl-5 text-fg-secondary`,children:[(0,J.jsx)(`li`,{children:`run any shell command without asking first,`}),(0,J.jsx)(`li`,{children:`modify, delete, or exfiltrate files your user can reach,`}),(0,J.jsx)(`li`,{children:`install dependencies and execute the network requests they make,`}),(0,J.jsx)(`li`,{children:`push branches or call remote APIs with the credentials it finds.`})]}),(0,J.jsx)(`p`,{children:`Only open this gate if every account you opt in runs work you would trust a colleague to run unsupervised on this machine.`}),(0,J.jsx)(`p`,{className:`text-fg-muted`,children:`Opening it also records the agent’s own bypass-permissions acceptance for this profile’s accounts, so the skip actually takes effect.`})]})})]}),(0,J.jsxs)(`div`,{className:`flex flex-col gap-1.5`,children:[(0,J.jsxs)(m,{htmlFor:`confirm-name`,children:[`Type `,(0,J.jsx)(`span`,{className:`text-fg`,children:t?.name}),` to confirm`]}),(0,J.jsx)(L,{id:`confirm-name`,value:l,onChange:e=>u(e.target.value),autoFocus:!0})]}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,onClick:()=>{c(!1),u(``)},children:`Cancel`}),(0,J.jsx)(R,{variant:`danger`,disabled:l!==t?.name||r.isPending,onClick:()=>f(!0),children:`Open the gate`})]})]})})]})}var Rt=c.parse({});function zt(){let[e,t]=(0,q.useState)(w);return(0,q.useEffect)(()=>{let e=()=>t(w());return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[]),[e,()=>t(w())]}function Bt({permission:e,onRequest:t}){return e===`granted`||e===`unverified`?null:(0,J.jsxs)(`p`,{className:`pb-2 text-xs text-warning`,children:[e==="default"&&(0,J.jsxs)(J.Fragment,{children:[`The browser has not been asked for permission yet, so nothing will show —`,` `,(0,J.jsx)(`button`,{type:`button`,onClick:t,className:`underline underline-offset-2 transition-colors hover:text-fg`,children:`request it now`}),`.`]}),e===`denied`&&`Blocked by the browser — allow notifications for this site in its site settings, then return here.`,e===`unsupported`&&`This browser cannot show desktop notifications.`]})}function Vt(){let e=D(),t=k(e??void 0),n=O(e??``),r=Ue(e??void 0),[i,a]=zt(),o=re(),[s,l]=(0,q.useState)(!1);(0,q.useEffect)(()=>{T();let e=()=>void T();return window.addEventListener(`focus`,e),()=>window.removeEventListener(`focus`,e)},[]);let u=c.catch(Rt).parse(t.data?.notifications??{}),d=e=>n.mutate({notifications:e},{onError:e=>K(e)}),f=()=>{ge()?.showNotification||typeof Notification>`u`||Notification.requestPermission().then(a)};return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Notifications`}),(0,J.jsx)(Y,{label:`Agent notifications`,htmlFor:`notify-desktop`,children:(0,J.jsx)(B,{id:`notify-desktop`,checked:u.desktop,onCheckedChange:e=>{e&&f(),d({...u,desktop:e})}})}),u.desktop&&(0,J.jsx)(Bt,{permission:i,onRequest:f}),(0,J.jsx)(Y,{label:`Notify while interacting with a session`,htmlFor:`notify-focused`,description:`When off, typing or clicking in a session silences its desktop alerts for five seconds. Mobile Web Push is configured separately on each device.`,children:(0,J.jsx)(B,{id:`notify-focused`,checked:u.when_focused,onCheckedChange:e=>d({...u,when_focused:e})})}),(0,J.jsx)(Y,{label:`Test delivery`,description:`Send a notification to check this device’s permissions.`,children:(0,J.jsx)(R,{variant:`ghost`,disabled:s,onClick:()=>{l(!0),(async()=>{!ge()?.showNotification&&typeof Notification<`u`&&Notification.permission==="default"&&(await Notification.requestPermission(),a()),await ae({id:`puddle-test`,title:`Puddle`,body:`Notifications are working on this device.`},()=>{})})().catch(K).finally(()=>l(!1))},children:s?`Sending…`:`Send test`})}),(0,J.jsx)(`p`,{role:`status`,className:`pb-2 text-xs text-fg-muted`,children:o.state===`shown`?`The system accepted the notification. Banner visibility also depends on Focus / Do Not Disturb.`:o.message??`Delivery has not been tested on this device.`}),(0,J.jsx)(Y,{label:`Sound`,htmlFor:`notify-sound`,children:(0,J.jsx)(B,{id:`notify-sound`,checked:u.sound,onCheckedChange:e=>d({...u,sound:e})})}),(0,J.jsx)(Y,{label:`Muted projects`,description:`No notifications from these projects.`,children:(0,J.jsxs)(`span`,{className:`text-2xs text-fg-muted tabular-nums`,children:[u.muted_projects.length,` muted`]})}),(0,J.jsx)(`div`,{className:`flex flex-col gap-1`,children:r.data?.map(e=>(0,J.jsxs)(`label`,{className:`flex items-center gap-2 rounded-md px-2 py-1 text-sm text-fg-secondary hover:bg-elevated`,children:[(0,J.jsx)(B,{checked:u.muted_projects.includes(e.id),onCheckedChange:t=>d({...u,muted_projects:t?[...u.muted_projects,e.id]:u.muted_projects.filter(t=>t!==e.id)})}),e.name]},e.id))})]})}function Ht(){let e=D(),t=Be(Oe().data?.protocol),n=pt(t&&e!==null),[r,i]=(0,q.useState)(null),a=n.data?.providers??[],o=a.find(e=>e.id===r)??a[0];return!t||!e?null:(0,J.jsxs)(`div`,{className:`mt-8`,children:[(0,J.jsx)(X,{note:`Defaults for this profile on the connected host. Individual files can override them from their tab menu.`,children:`Compilation & running code`}),n.isLoading?(0,J.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Loading languages…`}):n.isError?(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:`Couldn’t load languages.`}):o?(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Y,{label:`Language`,htmlFor:`compilation-language`,children:(0,J.jsxs)(G,{value:o.id,onValueChange:i,children:[(0,J.jsx)(H,{id:`compilation-language`,className:`w-48`,children:(0,J.jsx)(V,{})}),(0,J.jsx)(U,{children:a.map(e=>(0,J.jsx)(W,{value:e.id,detail:e.available?void 0:`Not installed`,children:e.display_name},e.id))})]})}),!o.available&&(0,J.jsxs)(`p`,{className:`mb-4 text-xs text-fg-muted`,children:[`No supported `,o.display_name,` tool is installed on this host. Saved commands apply when a supported tool is available.`]}),(0,J.jsx)(Ut,{request:{profile_id:e,provider:o.id}},`${e}:${o.id}`)]}):(0,J.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`No languages advertised by this host.`})]})}function Ut({request:e}){let t=mt(e),n=Ge();return t.isLoading?(0,J.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`Loading commands…`}):t.isError?(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:t.error instanceof Error?t.error.message:`Couldn’t load commands`}):t.data?(0,J.jsx)(ft,{settings:t.data,onSave:async t=>{for(let r of t){let t=await dt({...e,...r});n.setQueryData([`compilation-defaults`,e],t),await n.invalidateQueries({queryKey:[`compilation-settings`]})}}}):null}function Wt(){let e=ce();return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Editor`}),(0,J.jsx)(Y,{label:`Tab size`,description:`Spaces per indent level.`,htmlFor:`tab-size`,children:(0,J.jsx)(Ct,{id:`tab-size`,min:1,max:8,className:`w-20 tabular-nums`,value:e.editorTabSize,onCommit:e=>E({editorTabSize:e})})}),(0,J.jsx)(Y,{label:`Word wrap`,htmlFor:`word-wrap`,children:(0,J.jsx)(B,{id:`word-wrap`,checked:e.editorWordWrap,onCheckedChange:e=>E({editorWordWrap:e})})}),(0,J.jsx)(Y,{label:`SSH host for editor links`,description:`Used for vscode:// and cursor:// remote links until the CLI supplies it automatically.`,htmlFor:`editor-link-host`,children:(0,J.jsx)(L,{id:`editor-link-host`,type:`text`,placeholder:de.get()??`user@host`,className:`w-48`,value:e.editorLinkSshHost,onChange:e=>E({editorLinkSshHost:e.target.value})})}),(0,J.jsx)(Ht,{})]})}function Gt({value:e,isDefault:t,onRecord:n,onReset:r}){let[i,a]=(0,q.useState)(!1);return(0,J.jsxs)(`div`,{className:`flex items-center gap-1.5`,children:[(0,J.jsx)(`button`,{type:`button`,onClick:()=>a(!0),onBlur:()=>a(!1),onKeyDown:e=>{if(!i)return;if(e.preventDefault(),e.stopPropagation(),e.key===`Escape`){a(!1);return}let t=ye(e.nativeEvent);t&&(n(t),a(!1))},className:I(`min-w-24 rounded-md px-2 py-1 text-center font-mono text-xs transition-colors`,i?`bg-action text-action-ink`:`bg-elevated text-fg hover:bg-border/70`),children:i?`Press keys…`:_e(e)}),!t&&(0,J.jsxs)(`button`,{type:`button`,title:`Reset to default`,onClick:r,className:`rounded-md p-1 text-fg-gold transition-colors hover:bg-elevated hover:text-fg`,children:[(0,J.jsx)(at,{className:`size-3.5`}),(0,J.jsx)(`span`,{className:`sr-only`,children:`Reset to default`})]})]})}function Kt(){let e=D(),t=k(e??void 0),n=O(e??``),r=t.data?.hotkeys??{},i=(e,t)=>r[e]||t,a=new Map;for(let e of Se){let t=i(e.id,ve(e));a.set(t,(a.get(t)??0)+1)}let o=(e,t)=>n.mutate({hotkeys:{...r,[e]:t}},{onError:e=>K(e)}),s=e=>{let t={...r};delete t[e],n.mutate({hotkeys:t},{onError:e=>K(e)})};return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Hotkeys`}),(0,J.jsx)(`p`,{className:`mb-4 text-xs text-fg-muted`,children:`Per-profile keyboard shortcuts. Filetree navigation and terminal line-edits are fixed.`}),(0,J.jsx)(Y,{label:`App shortcuts in terminals`,description:t.data?.terminalAppShortcuts===!1?`A focused terminal receives these keys instead.`:`The shortcuts below work while a terminal is focused.`,htmlFor:`terminal-app-shortcuts`,className:`mb-4`,children:(0,J.jsx)(B,{id:`terminal-app-shortcuts`,checked:t.data?.terminalAppShortcuts!==!1,disabled:n.isPending,onCheckedChange:e=>n.mutate({terminalAppShortcuts:e},{onError:e=>K(e)})})}),xe.map(e=>{let t=Se.filter(t=>t.group===e);return t.length===0?null:(0,J.jsxs)(`div`,{className:`mb-5`,children:[(0,J.jsx)(`div`,{className:`mb-1 text-2xs font-medium uppercase tracking-wide text-fg-gold`,children:e}),t.map(e=>{let t=i(e.id,ve(e)),n=(a.get(t)??0)>1?`Conflicts with another shortcut.`:void 0;return(0,J.jsx)(Y,{label:e.label,description:n,descriptionClassName:n?`text-interrupted`:void 0,children:(0,J.jsx)(Gt,{value:t,isDefault:!r[e.id],onRecord:t=>o(e.id,t),onReset:()=>s(e.id)})},e.id)})]},e)})]})}var qt=e=>[...e].map(e=>e.toString(16).padStart(2,`0`)).join(``);function Jt(e,t){let[n,r]=(0,q.useState)(null),[i,a]=(0,q.useState)(!0),[o,s]=(0,q.useState)(``),c=(0,q.useRef)(0),f=(0,q.useRef)(null);(0,q.useEffect)(()=>()=>{c.current+=1},[]),(0,q.useEffect)(()=>{if(n)return;let e=!0;return f.current=null,a(!0),(async()=>{try{let t=qt(crypto.getRandomValues(new Uint8Array(32))),n=qt(new Uint8Array(await crypto.subtle.digest(`SHA-256`,new TextEncoder().encode(t))));e&&(f.current={code:t,challenge:n})}catch(t){e&&s(t instanceof Error?t.message:`Could not prepare sign-in.`)}finally{e&&a(!1)}})(),()=>{e=!1,f.current=null}},[n]);let p=(0,q.useRef)(t);return(0,q.useEffect)(()=>{p.current=t},[t]),(0,q.useEffect)(()=>{if(!n)return;let e=setTimeout(()=>{c.current+=1,r(null),s(`Sign-in expired. Try again.`)},Math.max(0,n.request.expires-Date.now()));return()=>clearTimeout(e)},[n]),(0,q.useEffect)(()=>{if(!n||e)return;let t=c.current,i=!1,a,o=async()=>{try{if(n.request.expires<=Date.now())throw Error(`Sign-in expired. Try again.`);let{ready:e}=u.parse(await me(`POST`,`/cockpit/remote/registration`,{service:n.request.service,code:n.code}));if(i||t!==c.current)return;if(n.request.expires<=Date.now())throw Error(`Sign-in expired. Try again.`);e?(r(null),await p.current({t:`enable`,registration:{service:n.request.service,app:n.request.app,code:n.code}})):a=setTimeout(()=>void o(),2e3)}catch(e){if(i||t!==c.current)return;r(null),s(e instanceof Error?e.message:`Sign-in failed. Try again.`)}};return a=setTimeout(()=>void o(),2e3),()=>{i=!0,clearTimeout(a)}},[n,e]),{attempt:n,preparing:i,error:o,begin:(t,n,i)=>{if(!(e||!f.current)){s(``);try{let{code:e,challenge:a}=f.current,o=d.safeParse({service:t.trim(),app:n.trim(),label:i.trim(),challenge:a,expires:Date.now()+l.invitationMs});if(!o.success)throw Error(`Enter a host name and exact HTTPS application and relay origins.`);let s=o.data,u=`${s.app}/#register=${encodeURIComponent(JSON.stringify(s))}`;c.current+=1,f.current=null,r({request:s,code:e,url:u}),window.open(u,`_blank`,`noopener,noreferrer`)}catch(e){s(e instanceof Error?e.message:`Could not start sign-in.`)}}},cancel:()=>{c.current+=1,f.current=null,a(!0),r(null)}}}function Yt({service:e=`https://charles.waddlelabs.ai`,app:t=`https://puddle.waddlelabs.ai`,hostName:n,busy:r,disabled:i,enable:a,cancel:o}){let[s,c]=(0,q.useState)(e),[l,u]=(0,q.useState)(t),[d,f]=(0,q.useState)(n),p=Jt(i,a),m=i||p.preparing||!!p.attempt;return(0,J.jsxs)(`form`,{className:`mt-4 space-y-4`,onSubmit:e=>{e.preventDefault(),m||p.begin(s,l,d)},children:[(0,J.jsxs)(`label`,{className:`grid gap-1.5 text-sm`,children:[`Application origin`,(0,J.jsx)(L,{type:`url`,required:!0,value:l,onChange:e=>u(e.target.value),placeholder:`https://app.example.com`,autoComplete:`off`,disabled:m})]}),(0,J.jsxs)(`label`,{className:`grid gap-1.5 text-sm`,children:[`Relay origin`,(0,J.jsx)(L,{type:`url`,required:!0,value:s,onChange:e=>c(e.target.value),placeholder:`https://relay.example.com`,autoComplete:`off`,disabled:m})]}),(0,J.jsxs)(`label`,{className:`grid gap-1.5 text-sm`,children:[`Host name`,(0,J.jsx)(L,{required:!0,maxLength:80,value:d,onChange:e=>f(e.target.value),disabled:m})]}),o&&(0,J.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Saving a new registration revokes existing browser approvals and invitations.`}),p.error&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:p.error}),p.attempt?(0,J.jsxs)(`div`,{className:`space-y-3 text-sm`,children:[(0,J.jsxs)(`p`,{role:`status`,children:[`Confirm this host in your browser. Match request`,` `,(0,J.jsx)(`strong`,{className:`font-mono`,children:p.attempt.request.challenge.slice(0,8).toUpperCase()}),`. Sign-in expires in five minutes.`]}),(0,J.jsx)(`a`,{href:p.attempt.url,target:`_blank`,rel:`noreferrer`,className:`text-accent hover:opacity-80`,children:`Continue in browser ↗`}),(0,J.jsx)(R,{type:`button`,variant:`ghost`,onClick:p.cancel,children:`Cancel sign-in`})]}):(0,J.jsxs)(`div`,{className:`flex flex-wrap gap-2`,children:[(0,J.jsx)(R,{type:`submit`,disabled:m||!d.trim()||!s||!l,children:r?`Enabling…`:p.preparing?`Preparing sign-in…`:`Sign in and enable`}),o&&(0,J.jsx)(R,{type:`button`,variant:`ghost`,disabled:m,onClick:o,children:`Cancel`})]})]})}var Xt=t(((e,t)=>{t.exports=function(){return typeof Promise==`function`&&Promise.prototype&&Promise.prototype.then}})),Z=t((e=>{var t,n=[0,26,44,70,100,134,172,196,242,292,346,404,466,532,581,655,733,815,901,991,1085,1156,1258,1364,1474,1588,1706,1828,1921,2051,2185,2323,2465,2611,2761,2876,3034,3196,3362,3532,3706];e.getSymbolSize=function(e){if(!e)throw Error(`"version" cannot be null or undefined`);if(e<1||e>40)throw Error(`"version" should be in range from 1 to 40`);return e*4+17},e.getSymbolTotalCodewords=function(e){return n[e]},e.getBCHDigit=function(e){let t=0;for(;e!==0;)t++,e>>>=1;return t},e.setToSJISFunction=function(e){if(typeof e!=`function`)throw Error(`"toSJISFunc" is not a valid function.`);t=e},e.isKanjiModeEnabled=function(){return t!==void 0},e.toSJIS=function(e){return t(e)}})),Zt=t((e=>{e.L={bit:1},e.M={bit:0},e.Q={bit:3},e.H={bit:2};function t(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`l`:case`low`:return e.L;case`m`:case`medium`:return e.M;case`q`:case`quartile`:return e.Q;case`h`:case`high`:return e.H;default:throw Error(`Unknown EC Level: `+t)}}e.isValid=function(e){return e&&e.bit!==void 0&&e.bit>=0&&e.bit<4},e.from=function(n,r){if(e.isValid(n))return n;try{return t(n)}catch{return r}}})),Qt=t(((e,t)=>{function n(){this.buffer=[],this.length=0}n.prototype={get:function(e){let t=Math.floor(e/8);return(this.buffer[t]>>>7-e%8&1)==1},put:function(e,t){for(let n=0;n<t;n++)this.putBit((e>>>t-n-1&1)==1)},getLengthInBits:function(){return this.length},putBit:function(e){let t=Math.floor(this.length/8);this.buffer.length<=t&&this.buffer.push(0),e&&(this.buffer[t]|=128>>>this.length%8),this.length++}},t.exports=n})),$t=t(((e,t)=>{function n(e){if(!e||e<1)throw Error(`BitMatrix size must be defined and greater than 0`);this.size=e,this.data=new Uint8Array(e*e),this.reservedBit=new Uint8Array(e*e)}n.prototype.set=function(e,t,n,r){let i=e*this.size+t;this.data[i]=n,r&&(this.reservedBit[i]=!0)},n.prototype.get=function(e,t){return this.data[e*this.size+t]},n.prototype.xor=function(e,t,n){this.data[e*this.size+t]^=n},n.prototype.isReserved=function(e,t){return this.reservedBit[e*this.size+t]},t.exports=n})),en=t((e=>{var t=Z().getSymbolSize;e.getRowColCoords=function(e){if(e===1)return[];let n=Math.floor(e/7)+2,r=t(e),i=r===145?26:Math.ceil((r-13)/(2*n-2))*2,a=[r-7];for(let e=1;e<n-1;e++)a[e]=a[e-1]-i;return a.push(6),a.reverse()},e.getPositions=function(t){let n=[],r=e.getRowColCoords(t),i=r.length;for(let e=0;e<i;e++)for(let t=0;t<i;t++)e===0&&t===0||e===0&&t===i-1||e===i-1&&t===0||n.push([r[e],r[t]]);return n}})),tn=t((e=>{var t=Z().getSymbolSize,n=7;e.getPositions=function(e){let r=t(e);return[[0,0],[r-n,0],[0,r-n]]}})),nn=t((e=>{e.Patterns={PATTERN000:0,PATTERN001:1,PATTERN010:2,PATTERN011:3,PATTERN100:4,PATTERN101:5,PATTERN110:6,PATTERN111:7};var t={N1:3,N2:3,N3:40,N4:10};e.isValid=function(e){return e!=null&&e!==``&&!isNaN(e)&&e>=0&&e<=7},e.from=function(t){return e.isValid(t)?parseInt(t,10):void 0},e.getPenaltyN1=function(e){let n=e.size,r=0,i=0,a=0,o=null,s=null;for(let c=0;c<n;c++){i=a=0,o=s=null;for(let l=0;l<n;l++){let n=e.get(c,l);n===o?i++:(i>=5&&(r+=t.N1+(i-5)),o=n,i=1),n=e.get(l,c),n===s?a++:(a>=5&&(r+=t.N1+(a-5)),s=n,a=1)}i>=5&&(r+=t.N1+(i-5)),a>=5&&(r+=t.N1+(a-5))}return r},e.getPenaltyN2=function(e){let n=e.size,r=0;for(let t=0;t<n-1;t++)for(let i=0;i<n-1;i++){let n=e.get(t,i)+e.get(t,i+1)+e.get(t+1,i)+e.get(t+1,i+1);(n===4||n===0)&&r++}return r*t.N2},e.getPenaltyN3=function(e){let n=e.size,r=0,i=0,a=0;for(let t=0;t<n;t++){i=a=0;for(let o=0;o<n;o++)i=i<<1&2047|e.get(t,o),o>=10&&(i===1488||i===93)&&r++,a=a<<1&2047|e.get(o,t),o>=10&&(a===1488||a===93)&&r++}return r*t.N3},e.getPenaltyN4=function(e){let n=0,r=e.data.length;for(let t=0;t<r;t++)n+=e.data[t];return Math.abs(Math.ceil(n*100/r/5)-10)*t.N4};function n(t,n,r){switch(t){case e.Patterns.PATTERN000:return(n+r)%2==0;case e.Patterns.PATTERN001:return n%2==0;case e.Patterns.PATTERN010:return r%3==0;case e.Patterns.PATTERN011:return(n+r)%3==0;case e.Patterns.PATTERN100:return(Math.floor(n/2)+Math.floor(r/3))%2==0;case e.Patterns.PATTERN101:return n*r%2+n*r%3==0;case e.Patterns.PATTERN110:return(n*r%2+n*r%3)%2==0;case e.Patterns.PATTERN111:return(n*r%3+(n+r)%2)%2==0;default:throw Error(`bad maskPattern:`+t)}}e.applyMask=function(e,t){let r=t.size;for(let i=0;i<r;i++)for(let a=0;a<r;a++)t.isReserved(a,i)||t.xor(a,i,n(e,a,i))},e.getBestMask=function(t,n){let r=Object.keys(e.Patterns).length,i=0,a=1/0;for(let o=0;o<r;o++){n(o),e.applyMask(o,t);let r=e.getPenaltyN1(t)+e.getPenaltyN2(t)+e.getPenaltyN3(t)+e.getPenaltyN4(t);e.applyMask(o,t),r<a&&(a=r,i=o)}return i}})),rn=t((e=>{var t=Zt(),n=[1,1,1,1,1,1,1,1,1,1,2,2,1,2,2,4,1,2,4,4,2,4,4,4,2,4,6,5,2,4,6,6,2,5,8,8,4,5,8,8,4,5,8,11,4,8,10,11,4,9,12,16,4,9,16,16,6,10,12,18,6,10,17,16,6,11,16,19,6,13,18,21,7,14,21,25,8,16,20,25,8,17,23,25,9,17,23,34,9,18,25,30,10,20,27,32,12,21,29,35,12,23,34,37,12,25,34,40,13,26,35,42,14,28,38,45,15,29,40,48,16,31,43,51,17,33,45,54,18,35,48,57,19,37,51,60,19,38,53,63,20,40,56,66,21,43,59,70,22,45,62,74,24,47,65,77,25,49,68,81],r=[7,10,13,17,10,16,22,28,15,26,36,44,20,36,52,64,26,48,72,88,36,64,96,112,40,72,108,130,48,88,132,156,60,110,160,192,72,130,192,224,80,150,224,264,96,176,260,308,104,198,288,352,120,216,320,384,132,240,360,432,144,280,408,480,168,308,448,532,180,338,504,588,196,364,546,650,224,416,600,700,224,442,644,750,252,476,690,816,270,504,750,900,300,560,810,960,312,588,870,1050,336,644,952,1110,360,700,1020,1200,390,728,1050,1260,420,784,1140,1350,450,812,1200,1440,480,868,1290,1530,510,924,1350,1620,540,980,1440,1710,570,1036,1530,1800,570,1064,1590,1890,600,1120,1680,1980,630,1204,1770,2100,660,1260,1860,2220,720,1316,1950,2310,750,1372,2040,2430];e.getBlocksCount=function(e,r){switch(r){case t.L:return n[(e-1)*4+0];case t.M:return n[(e-1)*4+1];case t.Q:return n[(e-1)*4+2];case t.H:return n[(e-1)*4+3];default:return}},e.getTotalCodewordsCount=function(e,n){switch(n){case t.L:return r[(e-1)*4+0];case t.M:return r[(e-1)*4+1];case t.Q:return r[(e-1)*4+2];case t.H:return r[(e-1)*4+3];default:return}}})),an=t((e=>{var t=new Uint8Array(512),n=new Uint8Array(256);(function(){let e=1;for(let r=0;r<255;r++)t[r]=e,n[e]=r,e<<=1,e&256&&(e^=285);for(let e=255;e<512;e++)t[e]=t[e-255]})(),e.log=function(e){if(e<1)throw Error(`log(`+e+`)`);return n[e]},e.exp=function(e){return t[e]},e.mul=function(e,r){return e===0||r===0?0:t[n[e]+n[r]]}})),on=t((e=>{var t=an();e.mul=function(e,n){let r=new Uint8Array(e.length+n.length-1);for(let i=0;i<e.length;i++)for(let a=0;a<n.length;a++)r[i+a]^=t.mul(e[i],n[a]);return r},e.mod=function(e,n){let r=new Uint8Array(e);for(;r.length-n.length>=0;){let e=r[0];for(let i=0;i<n.length;i++)r[i]^=t.mul(n[i],e);let i=0;for(;i<r.length&&r[i]===0;)i++;r=r.slice(i)}return r},e.generateECPolynomial=function(n){let r=new Uint8Array([1]);for(let i=0;i<n;i++)r=e.mul(r,new Uint8Array([1,t.exp(i)]));return r}})),sn=t(((e,t)=>{var n=on();function r(e){this.genPoly=void 0,this.degree=e,this.degree&&this.initialize(this.degree)}r.prototype.initialize=function(e){this.degree=e,this.genPoly=n.generateECPolynomial(this.degree)},r.prototype.encode=function(e){if(!this.genPoly)throw Error(`Encoder not initialized`);let t=new Uint8Array(e.length+this.degree);t.set(e);let r=n.mod(t,this.genPoly),i=this.degree-r.length;if(i>0){let e=new Uint8Array(this.degree);return e.set(r,i),e}return r},t.exports=r})),cn=t((e=>{e.isValid=function(e){return!isNaN(e)&&e>=1&&e<=40}})),ln=t((e=>{var t=`[0-9]+`,n=`[A-Z $%*+\\-./:]+`,r=`(?:[u3000-u303F]|[u3040-u309F]|[u30A0-u30FF]|[uFF00-uFFEF]|[u4E00-u9FAF]|[u2605-u2606]|[u2190-u2195]|u203B|[u2010u2015u2018u2019u2025u2026u201Cu201Du2225u2260]|[u0391-u0451]|[u00A7u00A8u00B1u00B4u00D7u00F7])+`;r=r.replace(/u/g,`\\u`);var i=`(?:(?![A-Z0-9 $%*+\\-./:]|`+r+`)(?:.|[\r
2
- ]))+`;e.KANJI=new RegExp(r,`g`),e.BYTE_KANJI=RegExp(`[^A-Z0-9 $%*+\\-./:]+`,`g`),e.BYTE=new RegExp(i,`g`),e.NUMERIC=new RegExp(t,`g`),e.ALPHANUMERIC=new RegExp(n,`g`);var a=RegExp(`^`+r+`$`),o=RegExp(`^[0-9]+$`),s=RegExp(`^[A-Z0-9 $%*+\\-./:]+$`);e.testKanji=function(e){return a.test(e)},e.testNumeric=function(e){return o.test(e)},e.testAlphanumeric=function(e){return s.test(e)}})),Q=t((e=>{var t=cn(),n=ln();e.NUMERIC={id:`Numeric`,bit:1,ccBits:[10,12,14]},e.ALPHANUMERIC={id:`Alphanumeric`,bit:2,ccBits:[9,11,13]},e.BYTE={id:`Byte`,bit:4,ccBits:[8,16,16]},e.KANJI={id:`Kanji`,bit:8,ccBits:[8,10,12]},e.MIXED={bit:-1},e.getCharCountIndicator=function(e,n){if(!e.ccBits)throw Error(`Invalid mode: `+e);if(!t.isValid(n))throw Error(`Invalid version: `+n);return n>=1&&n<10?e.ccBits[0]:n<27?e.ccBits[1]:e.ccBits[2]},e.getBestModeForData=function(t){return n.testNumeric(t)?e.NUMERIC:n.testAlphanumeric(t)?e.ALPHANUMERIC:n.testKanji(t)?e.KANJI:e.BYTE},e.toString=function(e){if(e&&e.id)return e.id;throw Error(`Invalid mode`)},e.isValid=function(e){return e&&e.bit&&e.ccBits};function r(t){if(typeof t!=`string`)throw Error(`Param is not a string`);switch(t.toLowerCase()){case`numeric`:return e.NUMERIC;case`alphanumeric`:return e.ALPHANUMERIC;case`kanji`:return e.KANJI;case`byte`:return e.BYTE;default:throw Error(`Unknown mode: `+t)}}e.from=function(t,n){if(e.isValid(t))return t;try{return r(t)}catch{return n}}})),un=t((e=>{var t=Z(),n=rn(),r=Zt(),i=Q(),a=cn(),o=7973,s=t.getBCHDigit(o);function c(t,n,r){for(let i=1;i<=40;i++)if(n<=e.getCapacity(i,r,t))return i}function l(e,t){return i.getCharCountIndicator(e,t)+4}function u(e,t){let n=0;return e.forEach(function(e){let r=l(e.mode,t);n+=r+e.getBitsLength()}),n}function d(t,n){for(let r=1;r<=40;r++)if(u(t,r)<=e.getCapacity(r,n,i.MIXED))return r}e.from=function(e,t){return a.isValid(e)?parseInt(e,10):t},e.getCapacity=function(e,r,o){if(!a.isValid(e))throw Error(`Invalid QR Code version`);o===void 0&&(o=i.BYTE);let s=(t.getSymbolTotalCodewords(e)-n.getTotalCodewordsCount(e,r))*8;if(o===i.MIXED)return s;let c=s-l(o,e);switch(o){case i.NUMERIC:return Math.floor(c/10*3);case i.ALPHANUMERIC:return Math.floor(c/11*2);case i.KANJI:return Math.floor(c/13);case i.BYTE:default:return Math.floor(c/8)}},e.getBestVersionForData=function(e,t){let n,i=r.from(t,r.M);if(Array.isArray(e)){if(e.length>1)return d(e,i);if(e.length===0)return 1;n=e[0]}else n=e;return c(n.mode,n.getLength(),i)},e.getEncodedBits=function(e){if(!a.isValid(e)||e<7)throw Error(`Invalid QR Code version`);let n=e<<12;for(;t.getBCHDigit(n)-s>=0;)n^=o<<t.getBCHDigit(n)-s;return e<<12|n}})),dn=t((e=>{var t=Z(),n=1335,r=21522,i=t.getBCHDigit(n);e.getEncodedBits=function(e,a){let o=e.bit<<3|a,s=o<<10;for(;t.getBCHDigit(s)-i>=0;)s^=n<<t.getBCHDigit(s)-i;return(o<<10|s)^r}})),fn=t(((e,t)=>{var n=Q();function r(e){this.mode=n.NUMERIC,this.data=e.toString()}r.getBitsLength=function(e){return 10*Math.floor(e/3)+(e%3?e%3*3+1:0)},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){let t,n,r;for(t=0;t+3<=this.data.length;t+=3)n=this.data.substr(t,3),r=parseInt(n,10),e.put(r,10);let i=this.data.length-t;i>0&&(n=this.data.substr(t),r=parseInt(n,10),e.put(r,i*3+1))},t.exports=r})),pn=t(((e,t)=>{var n=Q(),r=`0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ $%*+-./:`.split(``);function i(e){this.mode=n.ALPHANUMERIC,this.data=e}i.getBitsLength=function(e){return 11*Math.floor(e/2)+e%2*6},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t+2<=this.data.length;t+=2){let n=r.indexOf(this.data[t])*45;n+=r.indexOf(this.data[t+1]),e.put(n,11)}this.data.length%2&&e.put(r.indexOf(this.data[t]),6)},t.exports=i})),mn=t(((e,t)=>{var n=Q();function r(e){this.mode=n.BYTE,typeof e==`string`?this.data=new TextEncoder().encode(e):this.data=new Uint8Array(e)}r.getBitsLength=function(e){return e*8},r.prototype.getLength=function(){return this.data.length},r.prototype.getBitsLength=function(){return r.getBitsLength(this.data.length)},r.prototype.write=function(e){for(let t=0,n=this.data.length;t<n;t++)e.put(this.data[t],8)},t.exports=r})),hn=t(((e,t)=>{var n=Q(),r=Z();function i(e){this.mode=n.KANJI,this.data=e}i.getBitsLength=function(e){return e*13},i.prototype.getLength=function(){return this.data.length},i.prototype.getBitsLength=function(){return i.getBitsLength(this.data.length)},i.prototype.write=function(e){let t;for(t=0;t<this.data.length;t++){let n=r.toSJIS(this.data[t]);if(n>=33088&&n<=40956)n-=33088;else if(n>=57408&&n<=60351)n-=49472;else throw Error(`Invalid SJIS character: `+this.data[t]+`
3
- Make sure your charset is UTF-8`);n=(n>>>8&255)*192+(n&255),e.put(n,13)}},t.exports=i})),gn=t(((e,t)=>{var n={single_source_shortest_paths:function(e,t,r){var i={},a={};a[t]=0;var o=n.PriorityQueue.make();o.push(t,0);for(var s,c,l,u,d,f,p,m,h;!o.empty();)for(l in s=o.pop(),c=s.value,u=s.cost,d=e[c]||{},d)d.hasOwnProperty(l)&&(f=d[l],p=u+f,m=a[l],h=a[l]===void 0,(h||m>p)&&(a[l]=p,o.push(l,p),i[l]=c));if(r!==void 0&&a[r]===void 0){var g=[`Could not find a path from `,t,` to `,r,`.`].join(``);throw Error(g)}return i},extract_shortest_path_from_predecessor_list:function(e,t){for(var n=[],r=t;r;)n.push(r),e[r],r=e[r];return n.reverse(),n},find_path:function(e,t,r){var i=n.single_source_shortest_paths(e,t,r);return n.extract_shortest_path_from_predecessor_list(i,r)},PriorityQueue:{make:function(e){var t=n.PriorityQueue,r={},i;for(i in e||={},t)t.hasOwnProperty(i)&&(r[i]=t[i]);return r.queue=[],r.sorter=e.sorter||t.default_sorter,r},default_sorter:function(e,t){return e.cost-t.cost},push:function(e,t){var n={value:e,cost:t};this.queue.push(n),this.queue.sort(this.sorter)},pop:function(){return this.queue.shift()},empty:function(){return this.queue.length===0}}};t!==void 0&&(t.exports=n)})),_n=t((e=>{var t=Q(),n=fn(),r=pn(),i=mn(),a=hn(),o=ln(),s=Z(),c=gn();function l(e){return unescape(encodeURIComponent(e)).length}function u(e,t,n){let r=[],i;for(;(i=e.exec(n))!==null;)r.push({data:i[0],index:i.index,mode:t,length:i[0].length});return r}function d(e){let n=u(o.NUMERIC,t.NUMERIC,e),r=u(o.ALPHANUMERIC,t.ALPHANUMERIC,e),i,a;return s.isKanjiModeEnabled()?(i=u(o.BYTE,t.BYTE,e),a=u(o.KANJI,t.KANJI,e)):(i=u(o.BYTE_KANJI,t.BYTE,e),a=[]),n.concat(r,i,a).sort(function(e,t){return e.index-t.index}).map(function(e){return{data:e.data,mode:e.mode,length:e.length}})}function f(e,o){switch(o){case t.NUMERIC:return n.getBitsLength(e);case t.ALPHANUMERIC:return r.getBitsLength(e);case t.KANJI:return a.getBitsLength(e);case t.BYTE:return i.getBitsLength(e)}}function p(e){return e.reduce(function(e,t){let n=e.length-1>=0?e[e.length-1]:null;return n&&n.mode===t.mode?(e[e.length-1].data+=t.data,e):(e.push(t),e)},[])}function m(e){let n=[];for(let r=0;r<e.length;r++){let i=e[r];switch(i.mode){case t.NUMERIC:n.push([i,{data:i.data,mode:t.ALPHANUMERIC,length:i.length},{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.ALPHANUMERIC:n.push([i,{data:i.data,mode:t.BYTE,length:i.length}]);break;case t.KANJI:n.push([i,{data:i.data,mode:t.BYTE,length:l(i.data)}]);break;case t.BYTE:n.push([{data:i.data,mode:t.BYTE,length:l(i.data)}])}}return n}function h(e,n){let r={},i={start:{}},a=[`start`];for(let o=0;o<e.length;o++){let s=e[o],c=[];for(let e=0;e<s.length;e++){let l=s[e],u=``+o+e;c.push(u),r[u]={node:l,lastCount:0},i[u]={};for(let e=0;e<a.length;e++){let o=a[e];r[o]&&r[o].node.mode===l.mode?(i[o][u]=f(r[o].lastCount+l.length,l.mode)-f(r[o].lastCount,l.mode),r[o].lastCount+=l.length):(r[o]&&(r[o].lastCount=l.length),i[o][u]=f(l.length,l.mode)+4+t.getCharCountIndicator(l.mode,n))}}a=c}for(let e=0;e<a.length;e++)i[a[e]].end=0;return{map:i,table:r}}function g(e,o){let c,l=t.getBestModeForData(e);if(c=t.from(o,l),c!==t.BYTE&&c.bit<l.bit)throw Error(`"`+e+`" cannot be encoded with mode `+t.toString(c)+`.
4
- Suggested mode is: `+t.toString(l));switch(c===t.KANJI&&!s.isKanjiModeEnabled()&&(c=t.BYTE),c){case t.NUMERIC:return new n(e);case t.ALPHANUMERIC:return new r(e);case t.KANJI:return new a(e);case t.BYTE:return new i(e)}}e.fromArray=function(e){return e.reduce(function(e,t){return typeof t==`string`?e.push(g(t,null)):t.data&&e.push(g(t.data,t.mode)),e},[])},e.fromString=function(t,n){let r=h(m(d(t,s.isKanjiModeEnabled())),n),i=c.find_path(r.map,`start`,`end`),a=[];for(let e=1;e<i.length-1;e++)a.push(r.table[i[e]].node);return e.fromArray(p(a))},e.rawSplit=function(t){return e.fromArray(d(t,s.isKanjiModeEnabled()))}})),vn=t((e=>{var t=Z(),n=Zt(),r=Qt(),i=$t(),a=en(),o=tn(),s=nn(),c=rn(),l=sn(),u=un(),d=dn(),f=Q(),p=_n();function m(e,t){let n=e.size,r=o.getPositions(t);for(let t=0;t<r.length;t++){let i=r[t][0],a=r[t][1];for(let t=-1;t<=7;t++)if(!(i+t<=-1||n<=i+t))for(let r=-1;r<=7;r++)a+r<=-1||n<=a+r||(t>=0&&t<=6&&(r===0||r===6)||r>=0&&r<=6&&(t===0||t===6)||t>=2&&t<=4&&r>=2&&r<=4?e.set(i+t,a+r,!0,!0):e.set(i+t,a+r,!1,!0))}}function h(e){let t=e.size;for(let n=8;n<t-8;n++){let t=n%2==0;e.set(n,6,t,!0),e.set(6,n,t,!0)}}function g(e,t){let n=a.getPositions(t);for(let t=0;t<n.length;t++){let r=n[t][0],i=n[t][1];for(let t=-2;t<=2;t++)for(let n=-2;n<=2;n++)t===-2||t===2||n===-2||n===2||t===0&&n===0?e.set(r+t,i+n,!0,!0):e.set(r+t,i+n,!1,!0)}}function _(e,t){let n=e.size,r=u.getEncodedBits(t),i,a,o;for(let t=0;t<18;t++)i=Math.floor(t/3),a=t%3+n-8-3,o=(r>>t&1)==1,e.set(i,a,o,!0),e.set(a,i,o,!0)}function v(e,t,n){let r=e.size,i=d.getEncodedBits(t,n),a,o;for(a=0;a<15;a++)o=(i>>a&1)==1,a<6?e.set(a,8,o,!0):a<8?e.set(a+1,8,o,!0):e.set(r-15+a,8,o,!0),a<8?e.set(8,r-a-1,o,!0):a<9?e.set(8,15-a-1+1,o,!0):e.set(8,15-a-1,o,!0);e.set(r-8,8,1,!0)}function y(e,t){let n=e.size,r=-1,i=n-1,a=7,o=0;for(let s=n-1;s>0;s-=2)for(s===6&&s--;;){for(let n=0;n<2;n++)if(!e.isReserved(i,s-n)){let r=!1;o<t.length&&(r=(t[o]>>>a&1)==1),e.set(i,s-n,r),a--,a===-1&&(o++,a=7)}if(i+=r,i<0||n<=i){i-=r,r=-r;break}}}function b(e,n,i){let a=new r;i.forEach(function(t){a.put(t.mode.bit,4),a.put(t.getLength(),f.getCharCountIndicator(t.mode,e)),t.write(a)});let o=(t.getSymbolTotalCodewords(e)-c.getTotalCodewordsCount(e,n))*8;for(a.getLengthInBits()+4<=o&&a.put(0,4);a.getLengthInBits()%8!=0;)a.putBit(0);let s=(o-a.getLengthInBits())/8;for(let e=0;e<s;e++)a.put(e%2?17:236,8);return x(a,e,n)}function x(e,n,r){let i=t.getSymbolTotalCodewords(n),a=i-c.getTotalCodewordsCount(n,r),o=c.getBlocksCount(n,r),s=o-i%o,u=Math.floor(i/o),d=Math.floor(a/o),f=d+1,p=u-d,m=new l(p),h=0,g=Array(o),_=Array(o),v=0,y=new Uint8Array(e.buffer);for(let e=0;e<o;e++){let t=e<s?d:f;g[e]=y.slice(h,h+t),_[e]=m.encode(g[e]),h+=t,v=Math.max(v,t)}let b=new Uint8Array(i),x=0,S,C;for(S=0;S<v;S++)for(C=0;C<o;C++)S<g[C].length&&(b[x++]=g[C][S]);for(S=0;S<p;S++)for(C=0;C<o;C++)b[x++]=_[C][S];return b}function S(e,n,r,a){let o;if(Array.isArray(e))o=p.fromArray(e);else if(typeof e==`string`){let t=n;if(!t){let n=p.rawSplit(e);t=u.getBestVersionForData(n,r)}o=p.fromString(e,t||40)}else throw Error(`Invalid data`);let c=u.getBestVersionForData(o,r);if(!c)throw Error(`The amount of data is too big to be stored in a QR Code`);if(!n)n=c;else if(n<c)throw Error(`
5
- The chosen QR Code version cannot contain this amount of data.
6
- Minimum version required to store current data is: `+c+`.
7
- `);let l=b(n,r,o),d=new i(t.getSymbolSize(n));return m(d,n),h(d),g(d,n),v(d,r,0),n>=7&&_(d,n),y(d,l),isNaN(a)&&(a=s.getBestMask(d,v.bind(null,d,r))),s.applyMask(a,d),v(d,r,a),{modules:d,version:n,errorCorrectionLevel:r,maskPattern:a,segments:o}}e.create=function(e,r){if(e===void 0||e===``)throw Error(`No input text`);let i=n.M,a,o;return r!==void 0&&(i=n.from(r.errorCorrectionLevel,n.M),a=u.from(r.version),o=s.from(r.maskPattern),r.toSJISFunc&&t.setToSJISFunction(r.toSJISFunc)),S(e,a,i,o)}})),yn=t((e=>{function t(e){if(typeof e==`number`&&(e=e.toString()),typeof e!=`string`)throw Error(`Color should be defined as hex string`);let t=e.slice().replace(`#`,``).split(``);if(t.length<3||t.length===5||t.length>8)throw Error(`Invalid hex color: `+e);(t.length===3||t.length===4)&&(t=Array.prototype.concat.apply([],t.map(function(e){return[e,e]}))),t.length===6&&t.push(`F`,`F`);let n=parseInt(t.join(``),16);return{r:n>>24&255,g:n>>16&255,b:n>>8&255,a:n&255,hex:`#`+t.slice(0,6).join(``)}}e.getOptions=function(e){e||={},e.color||={};let n=e.margin===void 0||e.margin===null||e.margin<0?4:e.margin,r=e.width&&e.width>=21?e.width:void 0,i=e.scale||4;return{width:r,scale:r?4:i,margin:n,color:{dark:t(e.color.dark||`#000000ff`),light:t(e.color.light||`#ffffffff`)},type:e.type,rendererOpts:e.rendererOpts||{}}},e.getScale=function(e,t){return t.width&&t.width>=e+t.margin*2?t.width/(e+t.margin*2):t.scale},e.getImageWidth=function(t,n){let r=e.getScale(t,n);return Math.floor((t+n.margin*2)*r)},e.qrToImageData=function(t,n,r){let i=n.modules.size,a=n.modules.data,o=e.getScale(i,r),s=Math.floor((i+r.margin*2)*o),c=r.margin*o,l=[r.color.light,r.color.dark];for(let e=0;e<s;e++)for(let n=0;n<s;n++){let u=(e*s+n)*4,d=r.color.light;if(e>=c&&n>=c&&e<s-c&&n<s-c){let t=Math.floor((e-c)/o),r=Math.floor((n-c)/o);d=l[+!!a[t*i+r]]}t[u++]=d.r,t[u++]=d.g,t[u++]=d.b,t[u]=d.a}}})),bn=t((e=>{var t=yn();function n(e,t,n){e.clearRect(0,0,t.width,t.height),t.style||={},t.height=n,t.width=n,t.style.height=n+`px`,t.style.width=n+`px`}function r(){try{return document.createElement(`canvas`)}catch{throw Error(`You need to specify a canvas element`)}}e.render=function(e,i,a){let o=a,s=i;o===void 0&&(!i||!i.getContext)&&(o=i,i=void 0),i||(s=r()),o=t.getOptions(o);let c=t.getImageWidth(e.modules.size,o),l=s.getContext(`2d`),u=l.createImageData(c,c);return t.qrToImageData(u.data,e,o),n(l,s,c),l.putImageData(u,0,0),s},e.renderToDataURL=function(t,n,r){let i=r;i===void 0&&(!n||!n.getContext)&&(i=n,n=void 0),i||={};let a=e.render(t,n,i),o=i.type||`image/png`,s=i.rendererOpts||{};return a.toDataURL(o,s.quality)}})),xn=t((e=>{var t=yn();function n(e,t){let n=e.a/255,r=t+`="`+e.hex+`"`;return n<1?r+` `+t+`-opacity="`+n.toFixed(2).slice(1)+`"`:r}function r(e,t,n){let r=e+t;return n!==void 0&&(r+=` `+n),r}function i(e,t,n){let i=``,a=0,o=!1,s=0;for(let c=0;c<e.length;c++){let l=Math.floor(c%t),u=Math.floor(c/t);!l&&!o&&(o=!0),e[c]?(s++,c>0&&l>0&&e[c-1]||(i+=o?r(`M`,l+n,.5+u+n):r(`m`,a,0),a=0,o=!1),l+1<t&&e[c+1]||(i+=r(`h`,s),s=0)):a++}return i}e.render=function(e,r,a){let o=t.getOptions(r),s=e.modules.size,c=e.modules.data,l=s+o.margin*2,u=o.color.light.a?`<path `+n(o.color.light,`fill`)+` d="M0 0h`+l+`v`+l+`H0z"/>`:``,d=`<path `+n(o.color.dark,`stroke`)+` d="`+i(c,s,o.margin)+`"/>`,f=`viewBox="0 0 `+l+` `+l+`"`,p=`<svg xmlns="http://www.w3.org/2000/svg" `+(o.width?`width="`+o.width+`" height="`+o.width+`" `:``)+f+` shape-rendering="crispEdges">`+u+d+`</svg>
8
- `;return typeof a==`function`&&a(null,p),p}})),Sn=e(t((e=>{var t=Xt(),n=vn(),r=bn(),i=xn();function a(e,r,i,a,o){let s=[].slice.call(arguments,1),c=s.length,l=typeof s[c-1]==`function`;if(!l&&!t())throw Error(`Callback required as last argument`);if(l){if(c<2)throw Error(`Too few arguments provided`);c===2?(o=i,i=r,r=a=void 0):c===3&&(r.getContext&&o===void 0?(o=a,a=void 0):(o=a,a=i,i=r,r=void 0))}else{if(c<1)throw Error(`Too few arguments provided`);return c===1?(i=r,r=a=void 0):c===2&&!r.getContext&&(a=i,i=r,r=void 0),new Promise(function(t,o){try{t(e(n.create(i,a),r,a))}catch(e){o(e)}})}try{let t=n.create(i,a);o(null,e(t,r,a))}catch(e){o(e)}}e.create=n.create,e.toCanvas=a.bind(null,r.render),e.toDataURL=a.bind(null,r.renderToDataURL),e.toString=a.bind(null,function(e,t,n){return i.render(e,n)})}))(),1);function Cn({value:e,label:t}){let n=(0,q.useMemo)(()=>{try{let{modules:t}=Sn.create(e),n=[];for(let e=0;e<t.size;e+=1)for(let r=0;r<t.size;r+=1)t.get(e,r)&&n.push(`M${r+4} ${e+4}h1v1h-1z`);return{size:t.size+8,path:n.join(``)}}catch{return null}},[e]);return n?(0,J.jsx)(`svg`,{role:`img`,"aria-label":t,"data-theme":`light`,className:`block h-auto max-w-full rounded-lg bg-paper text-fg`,xmlns:`http://www.w3.org/2000/svg`,width:280,height:280,viewBox:`0 0 ${n.size} ${n.size}`,shapeRendering:`crispEdges`,children:(0,J.jsx)(`path`,{fill:`currentColor`,d:n.path})}):(0,J.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`QR code unavailable. Use the pairing link.`})}function wn({url:e,expires:t,dismiss:n}){let[r,i]=(0,q.useState)(``);return(0,q.useEffect)(()=>{let e=setTimeout(n,Math.max(0,t-Date.now()));return()=>clearTimeout(e)},[t,n]),(0,J.jsxs)(`section`,{className:`mt-5 space-y-3`,"aria-label":`Pairing invitation`,children:[(0,J.jsxs)(`p`,{className:`text-sm text-fg-secondary`,children:[`Scan or open this link on the new browser, then approve its exact identity below. Expires`,` `,new Date(t).toLocaleTimeString(),`.`]}),(0,J.jsx)(Cn,{value:e,label:`Pairing invitation QR code`}),(0,J.jsxs)(`div`,{className:`flex flex-wrap items-center gap-2`,children:[(0,J.jsx)(R,{variant:`secondary`,onClick:()=>{navigator.clipboard.writeText(e).then(()=>i(`Pairing link copied.`)).catch(()=>i(`Could not copy. Open the pairing link or scan the QR code.`))},children:`Copy pairing link`}),(0,J.jsx)(`a`,{href:e,target:`_blank`,rel:`noreferrer`,className:`px-2 text-sm text-fg hover:opacity-80`,children:`Open pairing link ↗`}),(0,J.jsx)(R,{variant:`ghost`,onClick:n,children:`Hide invitation`})]}),r&&(0,J.jsx)(`p`,{className:`text-xs text-fg-muted`,role:`status`,children:r})]})}function Tn({devices:e,now:t,currentDevice:n,...r}){let i=e.filter(e=>e.status!==`revoked`).sort((e,t)=>Number(t.status===`pending`)-Number(e.status===`pending`));return(0,J.jsxs)(`div`,{className:`grid gap-2`,children:[i.length===0&&(0,J.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`No browsers yet. Create a pairing invitation to add one.`}),i.map(e=>(0,J.jsx)(En,{device:e,now:t,current:e.id===n,...r},e.id))]})}function En({device:e,now:t,current:n,busy:r,approve:i,revoke:a}){let o=e.status===`pending`,s=e.status===`approved`?Math.min(e.expires,e.lastUsed+l.idleMs):e.expires,c=s<=t,u=c?`Expired`:o?`Awaiting approval`:`Approved`,d=(0,J.jsxs)(`div`,{className:`min-w-0 flex-1`,children:[(0,J.jsx)(`p`,{className:`truncate text-sm text-fg`,title:e.label,children:e.label}),(0,J.jsxs)(`p`,{className:I(`text-2xs`,c?`text-fg-muted`:o?`text-warning`:`text-success`),children:[u,n&&(0,J.jsx)(`span`,{className:`text-fg-muted`,children:` · this browser`})]})]}),f=(0,J.jsxs)(`div`,{className:`mt-2 space-y-1 text-2xs text-fg-muted`,children:[(0,J.jsx)(`code`,{className:`block break-all text-fg-secondary`,children:e.peer}),(0,J.jsxs)(`p`,{children:[c?`Expired`:`Expires`,` `,new Date(s).toLocaleString()]})]});return(0,J.jsxs)(`article`,{"aria-label":e.label,className:`min-w-0 rounded-md bg-surface px-3 py-2`,children:[(0,J.jsxs)(`div`,{className:`flex items-start gap-2`,children:[o?d:(0,J.jsx)(ht,{className:`min-w-0 flex-1`,summary:d,summaryClassName:`flex-row-reverse gap-2 [&>svg]:m-2`,children:f}),o&&!c&&(0,J.jsxs)(R,{variant:`secondary`,size:`sm`,disabled:r,onClick:()=>i(e.id),"aria-label":`Approve ${e.label}`,children:[(0,J.jsx)(bt,{}),` Approve`]}),(0,J.jsx)(R,{variant:`ghost`,size:`icon`,className:`shrink-0 text-fg-muted`,disabled:r,"aria-label":`Revoke ${e.label}`,title:`Revoke browser`,onClick:()=>a(e.id),children:(0,J.jsx)(Ye,{})})]}),o&&f]})}function Dn({devices:e,now:t,busy:n,act:r}){return(0,J.jsx)(ht,{className:`mt-6 text-sm`,summary:`Connected browsers`,summaryClassName:`py-2`,children:(0,J.jsxs)(`section`,{className:`space-y-3 pt-2`,"aria-label":`Browsers`,children:[(0,J.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Approval grants terminal control of this host. Compare the identity with the browser requesting access.`}),(0,J.jsx)(Tn,{devices:e,now:t,busy:n,approve:e=>void r({t:`approve`,id:e}),revoke:e=>void r({t:`revoke`,id:e})}),(0,J.jsx)(`p`,{className:`text-xs text-fg-muted`,children:`Revocation detaches viewers; agents continue running. Browsers expire after 30 days of inactivity or 90 days overall.`})]})})}function On({open:e,busy:t,error:n,onOpenChange:r,onConfirm:i}){return(0,J.jsx)(F,{open:e,onOpenChange:e=>!t&&r(e),children:(0,J.jsxs)(M,{children:[(0,J.jsx)(N,{children:`Delete this profile’s remote registration?`}),(0,J.jsx)(P,{children:`Disable remote access, remove the saved registration for this profile and revoke its browser approval and invitation. Agents keep running. Connecting again requires a new registration code and fresh browser approvals.`}),(0,J.jsx)(`p`,{className:`text-sm text-fg-secondary`,children:`This also removes this registration from its account’s remote host list. If the service is unavailable, removal finishes when it reconnects.`}),n&&(0,J.jsx)(`p`,{role:`alert`,className:`text-sm text-danger`,children:n}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,disabled:t,onClick:()=>r(!1),children:`Cancel`}),(0,J.jsx)(R,{variant:`danger`,disabled:t,onClick:i,children:t?`Deleting…`:`Delete registration`})]})]})})}function kn(){let e=Ge(),t=De(),n=D(),r=Ie().data?.find(e=>e.id===n)?.name??`this profile`,i=`/cockpit/remote?profile=${encodeURIComponent(n??``)}`,[a,o]=(0,q.useState)(!1),[s,c]=(0,q.useState)(``),[l,u]=(0,q.useState)(``),[d,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(!1),[_,v]=(0,q.useState)(!1),[y,b]=(0,q.useState)(null),x=(0,q.useCallback)(()=>b(null),[]),S=Ke({queryKey:[`cockpit-remote`,n],queryFn:async()=>f.parse(await me(`GET`,i)),refetchInterval:!a&&5e3,refetchOnWindowFocus:!a,refetchOnReconnect:!a,retry:!1,gcTime:0,enabled:!!n}),C=async t=>{if(a||!n)return!1;o(!0),u(``),c(``);try{if(e.isFetching({queryKey:[`cockpit-remote`,n],exact:!0})){let e=await S.refetch({cancelRefetch:!1});if(e.isError)throw e.error}let r=p.parse(await me(`POST`,i,t));return t.t===`pair`&&r.url&&r.invitation?b({url:r.url,expires:r.invitation.expires}):(c({enable:`Remote access enabled.`,approve:`Browser approved.`,revoke:`Browser revoked.`,disable:`Remote access disabled. Agents continue running.`,delete_registration:`Registration deleted from this host. Agents continue running.`,reset:`Host identity rotated and all browsers revoked. Enable access and pair again.`,status:`Status refreshed.`,devices:`Browsers refreshed.`,pair:`Invitation created.`}[t.t]),(t.t===`disable`||t.t===`reset`||t.t===`enable`||t.t===`delete_registration`)&&x()),(t.t===`enable`||t.t===`delete_registration`)&&m(!1),g(!1),v(!1),await S.refetch(),!0}catch(e){return u(e instanceof Error?e.message:`Host operation failed. Refresh status before retrying.`),await S.refetch(),!1}finally{o(!1)}},w=S.data,ee=S.error instanceof he&&S.error.status===404,T=a||S.isError;return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{note:`${r} on ${t.data?.displayName||t.data?.hostname||`this host`} · only this profile’s projects and sessions`,children:`Remote access`}),(0,J.jsxs)(`div`,{className:`mt-5 flex items-center justify-between gap-3`,children:[(0,J.jsx)(`span`,{role:`status`,className:`text-sm font-medium`,children:S.isError?`Status unavailable`:w?w.availability===`ready`?w.configured?w.enabled?w.connected?`Connected to relay`:`Enabled · relay disconnected`:`Disabled`:`Not configured`:`Daemon upgrade required`:`Checking remote access…`}),(0,J.jsxs)(R,{variant:`ghost`,size:`sm`,disabled:a,onClick:()=>void S.refetch({cancelRefetch:!1}),children:[(0,J.jsx)(Qe,{}),`Refresh status`]})]}),S.isError&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:ee?`This cockpit does not provide remote controls. Update Puddle and reopen this window.`:S.error.message}),l&&!_&&(0,J.jsx)(`p`,{role:`alert`,className:`mt-3 text-sm text-danger`,children:l}),s&&(0,J.jsx)(`p`,{role:`status`,className:`mt-3 text-sm text-fg-secondary`,children:s}),w?.availability!==void 0&&w.availability!==`ready`&&(0,J.jsx)(`p`,{className:`mt-3 text-sm text-fg-secondary`,children:`Update the daemon on this host, then refresh status to set up mobile access.`}),w?.availability===`ready`&&(0,J.jsxs)(J.Fragment,{children:[!w.enabled&&w.supervisor&&(!w.configured||d)?(0,J.jsx)(Yt,{service:w.service,app:w.app,hostName:`${t.data?.displayName||t.data?.hostname||`My host`} · ${r}`,busy:a,disabled:T,enable:C,cancel:w.configured?()=>m(!1):void 0},w.host??`new`):w.configured?(0,J.jsxs)(`dl`,{className:`mt-4 space-y-2 text-xs text-fg-secondary`,children:[(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{className:`text-fg-muted`,children:`Application`}),(0,J.jsx)(`dd`,{className:`break-all`,children:(0,J.jsxs)(`a`,{href:w.app,target:`_blank`,rel:`noreferrer`,className:`hover:text-fg`,children:[w.app,` ↗`]})})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{className:`text-fg-muted`,children:`Relay`}),(0,J.jsx)(`dd`,{className:`break-all`,children:w.service})]}),w.peer&&(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`dt`,{className:`text-fg-muted`,children:`Host identity`}),(0,J.jsx)(`dd`,{className:`break-all font-mono`,children:w.peer})]})]}):null,!w.enabled&&!w.supervisor&&(0,J.jsx)(`p`,{className:`mt-4 text-sm text-fg-secondary`,children:`This host needs persistent systemd or launchd supervision before access can be enabled here. For another supervisor, configure both the daemon and connector using the remote CLI commands.`}),w.configured&&(0,J.jsxs)(`div`,{className:`mt-4 flex flex-wrap gap-2`,role:`group`,"aria-label":`Registration actions`,children:[!w.enabled&&w.supervisor&&!d&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(R,{disabled:T,onClick:()=>void C({t:`enable`}),children:`Enable remote access`}),(0,J.jsx)(R,{variant:`ghost`,disabled:T,onClick:()=>m(!0),children:`Change registration`})]}),w.enabled&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(R,{disabled:T,onClick:()=>void C({t:`pair`}),children:`Pair a browser`}),(0,J.jsx)(R,{variant:`ghost`,disabled:T,onClick:()=>void C({t:`disable`}),children:`Disable remote access`})]}),w.canDeleteRegistration&&(0,J.jsx)(R,{variant:`ghost`,disabled:T,onClick:()=>{u(``),v(!0)},children:`Delete registration`})]}),y&&w.enabled&&(0,J.jsx)(wn,{...y,dismiss:x}),w.configured&&(0,J.jsxs)(J.Fragment,{children:[(0,J.jsx)(Dn,{devices:w.devices,now:S.dataUpdatedAt,busy:T,act:C}),(0,J.jsxs)(ht,{className:`text-sm`,summary:`Host identity recovery`,summaryClassName:`py-2`,children:[(0,J.jsx)(`p`,{className:`my-3 text-xs text-fg-muted`,children:`Rotate a lost or compromised host identity. This profile’s browser approvals and invitations will be revoked.`}),(0,J.jsx)(R,{variant:`ghost`,disabled:T,onClick:()=>g(!0),children:`Reset host identity…`})]})]})]}),(0,J.jsx)(F,{open:h,onOpenChange:e=>!a&&g(e),children:(0,J.jsxs)(M,{children:[(0,J.jsx)(N,{children:`Reset this profile’s remote identity?`}),(0,J.jsx)(P,{children:`Disable remote access, rotate the host identity and revoke this profile’s paired browsers and invitation. Agents keep running. Enable access and pair each browser again afterwards.`}),(0,J.jsxs)(j,{children:[(0,J.jsx)(R,{variant:`ghost`,disabled:a,onClick:()=>g(!1),children:`Cancel`}),(0,J.jsx)(R,{variant:`danger`,disabled:a,onClick:()=>void C({t:`reset`}),children:`Reset host identity`})]})]})}),(0,J.jsx)(On,{open:_,busy:a,error:l,onOpenChange:v,onConfirm:()=>void C({t:`delete_registration`})})]})}var An=`ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/=`,$=65,jn=Object.fromEntries([...An].map((e,t)=>[e,t])),Mn=`H`,Nn=(()=>{let e=new Uint32Array(256);for(let t=0;t<256;t+=1){let n=t;for(let e=0;e<8;e+=1)n=n&1?3988292384^n>>>1:n>>>1;e[t]=n>>>0}return e})();function Pn(e){let t=4294967295;for(let n of e)t=Nn[(t^n)&255]^t>>>8;return((t^4294967295)>>>0).toString(16).padStart(8,`0`)}function Fn(e){let t=``;for(let n of e)t+=String.fromCharCode(n);return btoa(t)}function In(e){let t=atob(e),n=new Uint8Array(t.length);for(let e=0;e<t.length;e+=1)n[e]=t.charCodeAt(e);return n}async function Ln(e){let t=new Blob([new TextEncoder().encode(e)]).stream().pipeThrough(new CompressionStream(`gzip`));return new Uint8Array(await new Response(t).arrayBuffer())}async function Rn(e){let t=new Blob([e]).stream().pipeThrough(new DecompressionStream(`gzip`));return new Response(t).text()}function zn(e,t){let n=(t%$+$)%$,r=``;for(let t of e){let e=jn[t];r+=e===void 0?t:An[(e+n)%$]}return r}async function Bn(e){let t=await Ln(JSON.stringify(e));return zn(Fn(t)+Pn(t),1+Math.floor(Math.random()*($-1)))}async function Vn(e){let t=e.trim(),n=t[0];if(!n||jn[n]===void 0)throw Error(`Not a settings export.`);let r=zn(t,-((jn[n]-jn[Mn]+$)%$));if(r.length<9||r[0]!==Mn)throw Error(`Not a settings export.`);let i=r.slice(0,-8),a=r.slice(-8),o=In(i);if(Pn(o)!==a)throw Error(`Settings export is corrupt (checksum mismatch).`);return JSON.parse(await Rn(o))}var Hn=`puddle.sync-selection`;function Un(){try{let e=JSON.parse(localStorage.getItem(Hn)??`null`);if(Array.isArray(e))return e.filter(e=>typeof e==`string`)}catch{}return b.map(e=>e.id)}function Wn({selected:e,onToggle:t}){return(0,J.jsx)(`div`,{className:`flex flex-col gap-2 pl-1`,children:b.map(n=>(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,J.jsx)(B,{checked:e.includes(n.id),onCheckedChange:e=>t(n.id,e)}),n.label]},n.id))})}function Gn(){let e=D(),t=k(e??void 0),n=Ie().data?.find(t=>t.id===e),r=He(e??void 0,void 0),i=O(e??``),a=Ce(),o=Te(),s=te(),c=ie(),[l,u]=(0,q.useState)(``),[d,f]=(0,q.useState)(``),[p,m]=(0,q.useState)(!1),[h,g]=(0,q.useState)(Un),_=n&&s.data?y(s.data.file,n.name):void 0,v=_?.enabled===!0,b=v&&_?_.groups:h,x=()=>({client:le(),theme:fe(),profileSettings:t.data??{},profile:n??{},scratchpad:r.data??[]}),S={setClient:e=>E(e),setTheme:e=>{typeof e==`string`&&pe(e)},patchProfileSettings:e=>i.mutate(e,{onError:e=>K(e)}),patchProfileColumns:t=>{e&&a.mutate({id:e,...t},{onError:e=>K(e)})},createScratchpad:t=>{if(e)for(let n of t)o.mutate({profile_id:e,scope:`profile`,title:n.title??void 0,body:n.body,tags:n.tags,agent_type:n.agent_type??void 0})}},C=(e,t)=>{n&&c.mutate({profile:n.name,entry:{enabled:e.enabled??v,groups:t,doc:oe(t,x()),updatedAt:new Date().toISOString()}},{onError:e=>K(e)})},w=(e,t)=>{let n=t?[...b,e]:b.filter(t=>t!==e);g(n),localStorage.setItem(Hn,JSON.stringify(n)),v&&C({},n)},T=async()=>{m(!0);try{let e=ee(await Vn(l.trim()),S,{profileSettings:t.data??{},scratchpad:r.data??[]});e.length===0?A.error(`Nothing recognised to import.`):(A.success(`Imported ${e.join(`, `)}.`),u(``))}catch(e){A.error(e.message)}finally{m(!1)}},ne=async()=>{m(!0);try{let e=await Bn(oe(b,x()));f(e),await navigator.clipboard?.writeText(e),A.success(`Copied to clipboard`)}finally{m(!1)}};return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Sync`}),(0,J.jsx)(`p`,{className:`mb-5 text-xs text-fg-muted`,children:`Carry your settings between machines. Accounts, repositories, and anything host-specific are never included. Applies to this profile.`}),(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium text-fg`,children:`Sync locally`}),s.data?.available===!1?(0,J.jsx)(`p`,{className:`mt-1 text-xs text-fg-muted`,children:`Not available in this cockpit — start the UI with the Puddle CLI to sync across windows.`}):(0,J.jsxs)(J.Fragment,{children:[(0,J.jsxs)(`p`,{className:`mb-2 mt-1 text-xs text-fg-muted`,children:[`Sync selected groups through this machine’s`,` `,(0,J.jsx)(`span`,{className:`text-fg-secondary`,children:`~/.puddle`}),`, so every Puddle window stays in step for profiles named`,` `,(0,J.jsx)(`span`,{className:`text-fg-secondary`,children:n?.name??`…`}),`.`]}),(0,J.jsxs)(`label`,{className:`flex items-center gap-2 text-sm text-fg`,children:[(0,J.jsx)(B,{checked:v,disabled:!n||s.isLoading||c.isPending,onCheckedChange:e=>C({enabled:e},b)}),`Sync locally`]})]})]}),(0,J.jsx)(ht,{className:`mb-6`,summary:`Choose what to sync`,summaryClassName:`text-xs`,children:(0,J.jsx)(`div`,{className:`mt-2`,children:(0,J.jsx)(Wn,{selected:b,onToggle:w})})}),(0,J.jsxs)(`div`,{className:`mb-6`,children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium text-fg`,children:`Export`}),(0,J.jsx)(`p`,{className:`mb-2 mt-1 text-xs text-fg-muted`,children:`Builds a Puddle magic string that encodes settings from the checklist above.`}),(0,J.jsx)(R,{size:`sm`,disabled:p,onClick:()=>void ne(),children:`Export & copy`}),d&&(0,J.jsx)(Je,{readOnly:!0,value:d,rows:3,spellCheck:!1,onFocus:e=>e.currentTarget.select(),className:`mt-2 resize-y font-mono text-xs`})]}),(0,J.jsxs)(`div`,{children:[(0,J.jsx)(`h3`,{className:`text-sm font-medium text-fg`,children:`Import`}),(0,J.jsx)(`p`,{className:`mb-2 text-xs text-fg-muted`,children:`Paste a Puddle magic string to import its settings.`}),(0,J.jsx)(Je,{value:l,onChange:e=>u(e.target.value),onKeyDown:e=>e.stopPropagation(),placeholder:`Paste a settings export…`,rows:3,spellCheck:!1,className:`resize-y font-mono text-xs`}),(0,J.jsx)(`div`,{className:`mt-2`,children:(0,J.jsx)(R,{size:`sm`,disabled:!l.trim()||p,onClick:()=>void T(),children:`Import`})})]})]})}function Kn(){return(0,J.jsxs)(`div`,{className:`space-y-8`,children:[(0,J.jsx)(kn,{},D()),(0,J.jsx)(Gn,{})]})}function qn({repo:e}){let t=Ve(),n=Ne(),r=Le(Oe().data?.protocol),[i,a]=(0,q.useState)(e.default_base_branch),[o,s]=(0,q.useState)(e.onboarding_notes??``),c=e=>K(e);return(0,J.jsxs)(`div`,{className:`mb-4 rounded-lg bg-surface p-3`,children:[(0,J.jsxs)(`div`,{className:`flex items-center gap-2`,children:[(0,J.jsx)(`span`,{className:`min-w-0 flex-1 truncate text-sm text-fg`,children:e.path}),(0,J.jsx)(`span`,{className:`shrink-0 text-2xs text-fg-muted tabular-nums`,children:e.last_fetched_at?`fetched ${new Date(e.last_fetched_at).toLocaleString()}`:`never fetched`}),(0,J.jsxs)(R,{size:`sm`,variant:`ghost`,disabled:n.isPending,onClick:()=>n.mutate(e.id,{onSuccess:()=>A.success(`Fetched.`),onError:c}),children:[(0,J.jsx)(Qe,{}),`Fetch now`]})]}),(0,J.jsxs)(Y,{label:`Default base branch`,description:r?`Blank = the branch checked out at the clone location when each agent or terminal is created.`:`Choose a branch. Update the host to allow a blank default that follows the clone.`,htmlFor:`base-${e.id}`,className:`py-1.5`,children:[(0,J.jsx)(L,{id:`base-${e.id}`,placeholder:r?`current clone branch`:void 0,value:i,onChange:e=>a(e.target.value),className:`w-40`}),(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:i.trim()===e.default_base_branch||t.isPending||!r&&!i.trim(),onClick:()=>t.mutate({id:e.id,default_base_branch:i.trim()},{onError:c,onSuccess:()=>a(i.trim())}),children:`Save`})]}),(0,J.jsx)(Y,{label:`Periodic fetch`,description:`Fetched on open and on the daemon's interval while sessions are active.`,htmlFor:`fetch-${e.id}`,className:`py-1.5`,children:(0,J.jsx)(B,{id:`fetch-${e.id}`,checked:e.fetch_enabled,onCheckedChange:n=>t.mutate({id:e.id,fetch_enabled:n},{onError:c})})}),(0,J.jsxs)(`div`,{className:`mt-1.5 flex flex-col gap-1.5`,children:[(0,J.jsxs)(`label`,{htmlFor:`notes-${e.id}`,className:`flex flex-col gap-0.5 text-sm text-fg`,children:[`Onboarding notes`,(0,J.jsx)(`span`,{className:`text-xs text-fg-muted`,children:`Standing setup rules, injected into every fresh worktree. Agents update them via .puddle/onboarding-notes.md.`})]}),(0,J.jsx)(Je,{id:`notes-${e.id}`,value:o,onChange:e=>s(e.target.value),rows:4}),(0,J.jsx)(`div`,{children:(0,J.jsx)(R,{size:`sm`,variant:`secondary`,disabled:o===(e.onboarding_notes??``)||t.isPending,onClick:()=>t.mutate({id:e.id,onboarding_notes:o},{onError:c}),children:`Save notes`})})]}),e.orphan_worktrees.length>0&&(0,J.jsxs)(`div`,{className:`mt-3 rounded-md bg-elevated p-2`,children:[(0,J.jsx)(`p`,{className:`text-xs text-fg-secondary`,children:`Orphan worktrees — directories no session claims. Puddle never deletes these automatically; remove them by hand if unwanted.`}),(0,J.jsx)(`ul`,{className:`mt-1 flex flex-col gap-0.5`,children:e.orphan_worktrees.map(e=>(0,J.jsx)(`li`,{className:`truncate text-2xs text-fg-muted`,children:e},e))})]})]})}function Jn(){let e=Re();return(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{children:`Projects`}),e.data?.length===0&&(0,J.jsx)(`p`,{className:`text-sm text-fg-muted`,children:`No projects yet — create one from the dashboard, pointing at a repository.`}),e.data?.map(e=>(0,J.jsx)(qn,{repo:e},e.id))]})}function Yn({label:e,description:t,field:n,config:r,min:i,step:a=1}){let o=Fe();return(0,J.jsx)(Y,{label:e,description:t,htmlFor:`host-${n}`,children:(0,J.jsx)(L,{id:`host-${n}`,type:`number`,min:i,step:a,className:`w-32 tabular-nums`,defaultValue:r[n],onBlur:e=>{if(e.target.value.trim()===``){e.target.value=String(r[n]);return}let t=Number(e.target.value);Number.isFinite(t)&&t!==r[n]&&o.mutate({[n]:t},{onError:e=>K(e)})}})})}function Xn(){let e=ze(),t=Fe(),n=De();return e.data?(0,J.jsxs)(`div`,{children:[(0,J.jsx)(X,{note:`Affects all profiles on this host`,children:`Host`}),(0,J.jsx)(Y,{label:`Display name`,description:`Shown in place of the hostname across the UI. Leave blank for the hostname.`,htmlFor:`host-displayName`,children:(0,J.jsx)(L,{id:`host-displayName`,type:`text`,maxLength:64,className:`w-48`,placeholder:n.data?.hostname,defaultValue:e.data.displayName,onBlur:n=>{let r=n.target.value.trim();r!==e.data.displayName&&t.mutate({displayName:r},{onError:e=>K(e)})}})}),(0,J.jsx)(Yn,{label:`Fetch interval (minutes)`,description:`Periodic git fetch for repos with active sessions.`,field:`fetchIntervalMinutes`,config:e.data,min:1}),(0,J.jsx)(Yn,{label:`Log size cap (bytes)`,description:`Per-terminal on-disk log cap.`,field:`logMaxBytes`,config:e.data,min:65536,step:1048576}),(0,J.jsx)(Yn,{label:`Replay size (bytes)`,description:`Log tail sent to a terminal on attach.`,field:`replayBytes`,config:e.data,min:1024,step:65536}),(0,J.jsx)(Yn,{label:`UI-state retention (days)`,description:`Stale workspace snapshots are swept at boot.`,field:`uiStateRetentionDays`,config:e.data,min:1}),(0,J.jsx)(Y,{label:`Auto-resume`,description:`Resume interrupted sessions automatically after a daemon restart.`,htmlFor:`host-autoResume`,children:(0,J.jsx)(B,{id:`host-autoResume`,checked:e.data.autoResume,onCheckedChange:e=>t.mutate({autoResume:e},{onError:e=>K(e)})})})]}):null}var Zn=[{id:`appearance`,label:`Appearance`,icon:et,render:()=>(0,J.jsx)(wt,{})},{id:`profile`,label:`Profile`,icon:rt,render:()=>(0,J.jsx)(Dt,{})},{id:`accounts`,label:`Accounts`,icon:St,render:()=>(0,J.jsx)(At,{})},{id:`sessions`,label:`Sessions`,icon:xt,render:()=>(0,J.jsx)(Lt,{})},{id:`editor`,label:`Editor`,icon:it,render:()=>(0,J.jsx)(Wt,{})},{id:`hotkeys`,label:`Hotkeys`,icon:_t,render:()=>(0,J.jsx)(Kt,{})},{id:`notifications`,label:`Notifications`,icon:gt,render:()=>(0,J.jsx)(Vt,{})},{id:`projects`,label:`Projects`,icon:v,render:()=>(0,J.jsx)(Jn,{})},{id:`host`,label:`Host`,icon:vt,render:()=>(0,J.jsx)(Xn,{})},{id:`remote-sync`,label:`Remote & Sync`,icon:Qe,render:()=>(0,J.jsx)(Kn,{})}],Qn={terminal:`sessions`,repositories:`projects`,remote:`remote-sync`,sync:`remote-sync`};function $n(){let e=Ze(),t=e===null?null:Qn[e]??e,n=Zn.find(e=>e.id===t)??Zn[0];return(0,J.jsx)(F,{open:e!==null,onOpenChange:e=>!e&&nt(),children:(0,J.jsxs)(M,{wide:!0,className:`grid h-[34rem] grid-cols-[14rem_1fr] gap-0 overflow-hidden p-0`,children:[(0,J.jsx)(N,{className:`sr-only`,children:`Settings`}),(0,J.jsxs)(`nav`,{className:`flex flex-col gap-1 bg-surface p-2.5 pr-6`,children:[(0,J.jsx)(`span`,{className:`px-2.5 py-2 text-2xs font-medium uppercase tracking-wide text-fg-muted`,children:`Settings`}),Zn.map(({id:e,label:t,icon:r})=>(0,J.jsxs)(`button`,{onClick:()=>$e(e),className:I(`flex items-center gap-2.5 rounded-md px-2.5 py-1.5 text-left text-sm transition-colors`,e===n.id?`bg-elevated text-fg`:`text-fg-secondary hover:bg-elevated hover:text-fg`),children:[(0,J.jsx)(r,{className:`size-4 shrink-0`}),t]},e))]}),(0,J.jsx)(`div`,{className:`overflow-y-auto p-5`,children:n.render()})]})})}export{$n as SettingsDialog};