viba-cli 0.26.0 → 0.28.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/.next/BUILD_ID +1 -1
  2. package/.next/build-manifest.json +2 -2
  3. package/.next/fallback-build-manifest.json +2 -2
  4. package/.next/prerender-manifest.json +3 -3
  5. package/.next/server/app/_global-error.html +2 -2
  6. package/.next/server/app/_global-error.rsc +1 -1
  7. package/.next/server/app/_global-error.segments/__PAGE__.segment.rsc +1 -1
  8. package/.next/server/app/_global-error.segments/_full.segment.rsc +1 -1
  9. package/.next/server/app/_global-error.segments/_head.segment.rsc +1 -1
  10. package/.next/server/app/_global-error.segments/_index.segment.rsc +1 -1
  11. package/.next/server/app/_global-error.segments/_tree.segment.rsc +1 -1
  12. package/.next/server/app/_not-found/page_client-reference-manifest.js +1 -1
  13. package/.next/server/app/_not-found.html +1 -1
  14. package/.next/server/app/_not-found.rsc +3 -2
  15. package/.next/server/app/_not-found.segments/_full.segment.rsc +3 -2
  16. package/.next/server/app/_not-found.segments/_head.segment.rsc +1 -1
  17. package/.next/server/app/_not-found.segments/_index.segment.rsc +3 -2
  18. package/.next/server/app/_not-found.segments/_not-found/__PAGE__.segment.rsc +1 -1
  19. package/.next/server/app/_not-found.segments/_not-found.segment.rsc +1 -1
  20. package/.next/server/app/_not-found.segments/_tree.segment.rsc +3 -2
  21. package/.next/server/app/credentials/page/server-reference-manifest.json +49 -4
  22. package/.next/server/app/credentials/page.js +1 -1
  23. package/.next/server/app/credentials/page.js.nft.json +1 -1
  24. package/.next/server/app/credentials/page_client-reference-manifest.js +1 -1
  25. package/.next/server/app/credentials.html +1 -1
  26. package/.next/server/app/credentials.rsc +4 -3
  27. package/.next/server/app/credentials.segments/_full.segment.rsc +4 -3
  28. package/.next/server/app/credentials.segments/_head.segment.rsc +1 -1
  29. package/.next/server/app/credentials.segments/_index.segment.rsc +3 -2
  30. package/.next/server/app/credentials.segments/_tree.segment.rsc +3 -2
  31. package/.next/server/app/credentials.segments/credentials/__PAGE__.segment.rsc +2 -2
  32. package/.next/server/app/credentials.segments/credentials.segment.rsc +1 -1
  33. package/.next/server/app/index.html +1 -1
  34. package/.next/server/app/index.rsc +4 -3
  35. package/.next/server/app/index.segments/__PAGE__.segment.rsc +2 -2
  36. package/.next/server/app/index.segments/_full.segment.rsc +4 -3
  37. package/.next/server/app/index.segments/_head.segment.rsc +1 -1
  38. package/.next/server/app/index.segments/_index.segment.rsc +3 -2
  39. package/.next/server/app/index.segments/_tree.segment.rsc +3 -2
  40. package/.next/server/app/new/page/server-reference-manifest.json +40 -25
  41. package/.next/server/app/new/page.js +2 -2
  42. package/.next/server/app/new/page.js.nft.json +1 -1
  43. package/.next/server/app/new/page_client-reference-manifest.js +1 -1
  44. package/.next/server/app/page/server-reference-manifest.json +40 -25
  45. package/.next/server/app/page.js +2 -2
  46. package/.next/server/app/page.js.nft.json +1 -1
  47. package/.next/server/app/page_client-reference-manifest.js +1 -1
  48. package/.next/server/app/session/[sessionId]/page/server-reference-manifest.json +19 -34
  49. package/.next/server/app/session/[sessionId]/page.js +1 -1
  50. package/.next/server/app/session/[sessionId]/page.js.nft.json +1 -1
  51. package/.next/server/app/session/[sessionId]/page_client-reference-manifest.js +1 -1
  52. package/.next/server/chunks/ssr/[root-of-the-server]__01151db2._.js +3 -0
  53. package/.next/server/chunks/ssr/[root-of-the-server]__01151db2._.js.map +1 -0
  54. package/.next/server/chunks/ssr/[root-of-the-server]__0522f852._.js +4 -0
  55. package/.next/server/chunks/ssr/[root-of-the-server]__0522f852._.js.map +1 -0
  56. package/.next/server/chunks/ssr/[root-of-the-server]__30652385._.js +1 -1
  57. package/.next/server/chunks/ssr/[root-of-the-server]__30652385._.js.map +1 -1
  58. package/.next/server/chunks/ssr/[root-of-the-server]__352d2b3c._.js +1 -1
  59. package/.next/server/chunks/ssr/[root-of-the-server]__352d2b3c._.js.map +1 -1
  60. package/.next/server/chunks/ssr/[root-of-the-server]__4c388861._.js +4 -0
  61. package/.next/server/chunks/ssr/[root-of-the-server]__4c388861._.js.map +1 -0
  62. package/.next/server/chunks/ssr/[root-of-the-server]__59834c63._.js +4 -0
  63. package/.next/server/chunks/ssr/[root-of-the-server]__59834c63._.js.map +1 -0
  64. package/.next/server/chunks/ssr/[root-of-the-server]__6c63d5b8._.js +3 -0
  65. package/.next/server/chunks/ssr/[root-of-the-server]__6c63d5b8._.js.map +1 -0
  66. package/.next/server/chunks/ssr/[root-of-the-server]__9201693f._.js +1 -1
  67. package/.next/server/chunks/ssr/[root-of-the-server]__9201693f._.js.map +1 -1
  68. package/.next/server/chunks/ssr/[root-of-the-server]__b2d91bdd._.js +3 -0
  69. package/.next/server/chunks/ssr/[root-of-the-server]__b2d91bdd._.js.map +1 -0
  70. package/.next/server/chunks/ssr/[root-of-the-server]__c790b631._.js +3 -0
  71. package/.next/server/chunks/ssr/[root-of-the-server]__c790b631._.js.map +1 -0
  72. package/.next/server/chunks/ssr/[root-of-the-server]__d5eaad6d._.js +3 -0
  73. package/.next/server/chunks/ssr/[root-of-the-server]__d5eaad6d._.js.map +1 -0
  74. package/.next/server/chunks/ssr/[root-of-the-server]__e5ccf6ef._.js +3 -0
  75. package/.next/server/chunks/ssr/[root-of-the-server]__e5ccf6ef._.js.map +1 -0
  76. package/.next/server/chunks/ssr/{node_modules_8cba5059._.js → node_modules_1924b56e._.js} +2 -2
  77. package/.next/server/chunks/ssr/node_modules_1924b56e._.js.map +1 -0
  78. package/.next/server/chunks/ssr/{node_modules_e604472b._.js → node_modules_4ebcf1df._.js} +2 -2
  79. package/.next/server/chunks/ssr/node_modules_4ebcf1df._.js.map +1 -0
  80. package/.next/server/chunks/ssr/{node_modules_8d27431f._.js → node_modules_9819fed1._.js} +2 -2
  81. package/.next/server/chunks/ssr/node_modules_9819fed1._.js.map +1 -0
  82. package/.next/server/chunks/ssr/{node_modules_61fa9608._.js → node_modules_a6b22d4e._.js} +2 -2
  83. package/.next/server/chunks/ssr/node_modules_a6b22d4e._.js.map +1 -0
  84. package/.next/server/chunks/ssr/src_app_credentials_page_tsx_63d8d34a._.js +3 -0
  85. package/.next/server/chunks/ssr/src_app_credentials_page_tsx_63d8d34a._.js.map +1 -0
  86. package/.next/server/chunks/ssr/src_app_session_[sessionId]_SessionPageClient_tsx_dab490d7._.js +1 -1
  87. package/.next/server/chunks/ssr/src_app_session_[sessionId]_SessionPageClient_tsx_dab490d7._.js.map +1 -1
  88. package/.next/server/chunks/ssr/src_components_GitRepoSelector_tsx_05c81afa._.js +8 -2
  89. package/.next/server/chunks/ssr/src_components_GitRepoSelector_tsx_05c81afa._.js.map +1 -1
  90. package/.next/server/pages/404.html +1 -1
  91. package/.next/server/pages/500.html +2 -2
  92. package/.next/server/server-reference-manifest.js +1 -1
  93. package/.next/server/server-reference-manifest.json +102 -58
  94. package/.next/static/chunks/13c27cbcbed10be4.js +9 -0
  95. package/.next/static/chunks/2473c16c0c2f6b5f.css +2 -0
  96. package/.next/static/chunks/2648731e67ebd2ac.js +1 -0
  97. package/.next/static/chunks/453fc76d2d553c51.js +3 -0
  98. package/.next/static/chunks/63e62f1fed4c4271.js +3 -0
  99. package/.next/static/chunks/afd3fb06f06c56af.js +3 -0
  100. package/.next/static/chunks/d658bac82c8382da.js +3 -0
  101. package/.next/static/chunks/dc6ca47e0eb2b1af.css +1 -0
  102. package/package.json +1 -1
  103. package/.next/server/chunks/ssr/[root-of-the-server]__04684e03._.js +0 -3
  104. package/.next/server/chunks/ssr/[root-of-the-server]__04684e03._.js.map +0 -1
  105. package/.next/server/chunks/ssr/[root-of-the-server]__04bf0b15._.js +0 -3
  106. package/.next/server/chunks/ssr/[root-of-the-server]__04bf0b15._.js.map +0 -1
  107. package/.next/server/chunks/ssr/[root-of-the-server]__1c2594e3._.js +0 -4
  108. package/.next/server/chunks/ssr/[root-of-the-server]__1c2594e3._.js.map +0 -1
  109. package/.next/server/chunks/ssr/[root-of-the-server]__319c1c59._.js +0 -4
  110. package/.next/server/chunks/ssr/[root-of-the-server]__319c1c59._.js.map +0 -1
  111. package/.next/server/chunks/ssr/[root-of-the-server]__a091a4c1._.js +0 -3
  112. package/.next/server/chunks/ssr/[root-of-the-server]__a091a4c1._.js.map +0 -1
  113. package/.next/server/chunks/ssr/[root-of-the-server]__b2c27322._.js +0 -3
  114. package/.next/server/chunks/ssr/[root-of-the-server]__b2c27322._.js.map +0 -1
  115. package/.next/server/chunks/ssr/[root-of-the-server]__ba6de807._.js +0 -3
  116. package/.next/server/chunks/ssr/[root-of-the-server]__ba6de807._.js.map +0 -1
  117. package/.next/server/chunks/ssr/[root-of-the-server]__ee9c5185._.js +0 -4
  118. package/.next/server/chunks/ssr/[root-of-the-server]__ee9c5185._.js.map +0 -1
  119. package/.next/server/chunks/ssr/[root-of-the-server]__fbfe5cd5._.js +0 -3
  120. package/.next/server/chunks/ssr/[root-of-the-server]__fbfe5cd5._.js.map +0 -1
  121. package/.next/server/chunks/ssr/node_modules_61fa9608._.js.map +0 -1
  122. package/.next/server/chunks/ssr/node_modules_8cba5059._.js.map +0 -1
  123. package/.next/server/chunks/ssr/node_modules_8d27431f._.js.map +0 -1
  124. package/.next/server/chunks/ssr/node_modules_e604472b._.js.map +0 -1
  125. package/.next/static/chunks/2da4ff7bd7ef7984.js +0 -3
  126. package/.next/static/chunks/4cb45c81c3579aa0.js +0 -3
  127. package/.next/static/chunks/68be4ececa8dedfc.js +0 -1
  128. package/.next/static/chunks/7dad2f2e170a6bec.css +0 -3
  129. package/.next/static/chunks/8347c7b3b84ae4c2.js +0 -3
  130. package/.next/static/chunks/8f4ebe93d38185fb.js +0 -3
  131. package/.next/static/chunks/c814bb803eca5aea.js +0 -3
  132. /package/.next/static/{T2HRQ3n5Gcw83spbEWvCi → FS2_5AqvTArHxxuNAA0Or}/_buildManifest.js +0 -0
  133. /package/.next/static/{T2HRQ3n5Gcw83spbEWvCi → FS2_5AqvTArHxxuNAA0Or}/_clientMiddlewareManifest.json +0 -0
  134. /package/.next/static/{T2HRQ3n5Gcw83spbEWvCi → FS2_5AqvTArHxxuNAA0Or}/_ssgManifest.js +0 -0
@@ -0,0 +1,3 @@
1
+ module.exports=[12465,a=>{"use strict";var b=a.i(87924),c=a.i(54653),d=a.i(9809),e=a.i(5050);let f=(0,e.createServerReference)("407dd022f450835e92452755c2187f2759ce65a352",e.callServer,void 0,e.findSourceMapURL,"removeAgentApiCredential"),g=(0,e.createServerReference)("40549b442d0eb35deaec280c1a3ac69584e89086a5",e.callServer,void 0,e.findSourceMapURL,"removeCredential"),h=(0,e.createServerReference)("708a3dd3737dc6efc62a9fa45a820696f5441c8d44",e.callServer,void 0,e.findSourceMapURL,"saveAgentApiCredential"),i=(0,e.createServerReference)("4004a0e7ba2853a497f171ed16037e29939770bf9d",e.callServer,void 0,e.findSourceMapURL,"saveGitHubCredential"),j=(0,e.createServerReference)("60cd0b78e5e61702e931c48bbfdc43d298af6e8439",e.callServer,void 0,e.findSourceMapURL,"saveGitLabCredential");var k=a.i(50522),l=a.i(37047),m=a.i(81560),n=a.i(71987),o=a.i(50944),p=a.i(72131);let q="https://gitlab.com",r={github:"https://www.google.com/s2/favicons?domain=github.com&sz=64",gitlab:"https://www.google.com/s2/favicons?domain=gitlab.com&sz=64"},s={codex:"Codex CLI"},t={codex:"sk-..."},u={codex:"https://proxy.example.com/v1"},v=["codex"];function w(a){return"github"===a?"GitHub":"GitLab"}function x({type:a}){return(0,b.jsx)(n.default,{src:r[a],alt:`${w(a)} icon`,width:20,height:20,className:"h-5 w-5 rounded-sm",unoptimized:!0})}function y(){let a=(0,o.useRouter)(),[e,n]=(0,p.useState)([]),[r,y]=(0,p.useState)([]),[z,A]=(0,p.useState)(!0),[B,C]=(0,p.useState)(""),[D,E]=(0,p.useState)(""),[F,G]=(0,p.useState)(q),[H,I]=(0,p.useState)({codex:""}),[J,K]=(0,p.useState)({codex:""}),[L,M]=(0,p.useState)(null),[N,O]=(0,p.useState)(null),[P,Q]=(0,p.useState)(null),[R,S]=(0,p.useState)(null),[T,U]=(0,p.useState)(null),V=(0,p.useMemo)(()=>e.filter(a=>"github"===a.type),[e]),W=(0,p.useMemo)(()=>e.filter(a=>"gitlab"===a.type),[e]),X=(0,p.useMemo)(()=>new Map(r.map(a=>[a.agent,a])),[r]),Y=async()=>{let[a,b]=await Promise.all([(0,d.listCredentials)(),(0,c.listAgentApiCredentials)()]);if(!a.success){U({tone:"error",text:a.error}),A(!1);return}if(!b.success){U({tone:"error",text:b.error}),A(!1);return}n(a.credentials),y(b.credentials),K(a=>{let c={...a};for(let a of v)c[a]=b.credentials.find(b=>b.agent===a)?.apiProxy||"";return c}),A(!1)};(0,p.useEffect)(()=>{let a=!0;return(async()=>{let[b,e]=await Promise.all([(0,d.listCredentials)(),(0,c.listAgentApiCredentials)()]);if(a){if(!b.success){U({tone:"error",text:b.error}),A(!1);return}if(!e.success){U({tone:"error",text:e.error}),A(!1);return}n(b.credentials),y(e.credentials),K(a=>{let b={...a};for(let a of v)b[a]=e.credentials.find(b=>b.agent===a)?.apiProxy||"";return b}),A(!1)}})(),()=>{a=!1}},[]);let Z=async()=>{U(null),M("github");let a=await i(B);if(!a.success){U({tone:"error",text:a.error}),M(null);return}C(""),U({tone:"success",text:"GitHub credential added."}),await Y(),M(null)},$=async()=>{U(null),M("gitlab");let a=await j(F,D);if(!a.success){U({tone:"error",text:a.error}),M(null);return}E(""),U({tone:"success",text:"GitLab credential added."}),await Y(),M(null)},_=async a=>{U(null),O(a);let b=await h(a,H[a],J[a]);if(!b.success){U({tone:"error",text:b.error}),O(null);return}I(b=>({...b,[a]:""})),K(c=>({...c,[a]:b.credential.apiProxy||""})),U({tone:"success",text:`${s[a]} credential saved.`}),await Y(),O(null)},aa=async a=>{let b=w(a.type);if(!confirm(`Delete this ${b} credential for ${"gitlab"===a.type?`${a.username} @ ${a.serverUrl}`:a.username}?`))return;U(null),Q(a.id);let c=await g(a.id);if(!c.success){U({tone:"error",text:c.error}),Q(null);return}U({tone:"success",text:`${b} credential deleted.`}),await Y(),Q(null)},ab=async a=>{if(!confirm(`Delete the saved ${s[a]} API credential?`))return;U(null),S(a);let b=await f(a);if(!b.success){U({tone:"error",text:b.error}),S(null);return}I(b=>({...b,[a]:""})),K(b=>({...b,[a]:""})),U({tone:"success",text:`${s[a]} credential deleted.`}),await Y(),S(null)},ac="overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm",ad="flex flex-col gap-3 border-b border-slate-200 px-6 py-5 md:flex-row md:items-center md:justify-between",ae="block w-full rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60",af="inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60",ag="inline-flex items-center justify-center gap-2 rounded-lg border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 disabled:cursor-not-allowed disabled:opacity-60",ah="inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-400 transition-all hover:bg-red-50 hover:text-red-500";return(0,b.jsx)("main",{className:"min-h-screen bg-[#f6f6f8] px-4 py-8 md:px-8 md:py-12",children:(0,b.jsxs)("div",{className:"mx-auto w-full max-w-4xl space-y-8",children:[(0,b.jsxs)("div",{className:"mb-8",children:[(0,b.jsxs)("div",{className:"mb-2 flex items-center gap-4",children:[(0,b.jsx)("button",{type:"button",className:"flex h-10 w-10 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-white hover:text-slate-900",onClick:()=>a.push("/"),"aria-label":"Back to home",children:(0,b.jsx)(k.ChevronRight,{className:"h-6 w-6 rotate-180"})}),(0,b.jsx)("h1",{className:"text-3xl font-black tracking-[-0.02em] text-slate-900 md:text-4xl",children:"Credential Management"})]}),(0,b.jsx)("p",{className:"ml-14 text-sm text-slate-500 md:text-base",children:"Manage your API keys and access tokens for third-party services safely."})]}),T&&(0,b.jsx)("div",{className:`rounded-lg border px-4 py-3 text-sm ${"error"===T.tone?"border-red-200 bg-red-50 text-red-700":"border-emerald-200 bg-emerald-50 text-emerald-700"}`,children:T.text}),z?(0,b.jsx)("div",{className:`${ac} p-10`,children:(0,b.jsxs)("div",{className:"flex flex-col items-center gap-3",children:[(0,b.jsx)("span",{className:"loading loading-spinner loading-md text-primary"}),(0,b.jsx)("p",{className:"text-sm text-slate-500",children:"Loading credentials..."})]})}):(0,b.jsxs)("div",{className:"space-y-6",children:[(0,b.jsxs)("section",{className:ac,children:[(0,b.jsxs)("div",{className:ad,children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("h2",{className:"text-lg font-bold text-slate-900",children:"GitHub Credentials"}),(0,b.jsx)("p",{className:"mt-1 text-sm text-slate-500",children:"Access private repositories and Gists."})]}),(0,b.jsxs)("button",{className:af,onClick:()=>void Z(),disabled:"github"===L,children:["github"===L?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(l.KeyRound,{className:"h-4 w-4"}),"Add Token"]})]}),(0,b.jsxs)("div",{className:"border-b border-slate-100 bg-slate-50/40 px-6 py-4",children:[(0,b.jsx)("label",{className:"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Personal Access Token"}),(0,b.jsx)("input",{type:"password",className:ae,placeholder:"ghp_xxx",value:B,onChange:a=>C(a.target.value),disabled:"github"===L})]}),0===V.length?(0,b.jsx)("div",{className:"px-6 py-6 text-sm text-slate-500",children:"No GitHub credentials saved."}):(0,b.jsx)("div",{className:"divide-y divide-slate-100",children:V.map(a=>(0,b.jsxs)("div",{className:"group flex items-center justify-between gap-4 px-6 py-5 transition-colors hover:bg-slate-50",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-4",children:[(0,b.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-slate-100",children:(0,b.jsx)(x,{type:"github"})}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsx)("div",{className:"truncate text-sm font-semibold text-slate-900",children:a.username}),(0,b.jsxs)("div",{className:"mt-0.5 text-xs text-slate-500",children:["Updated ",new Date(a.updatedAt).toLocaleString()]})]})]}),(0,b.jsx)("button",{className:`${ah} opacity-0 group-hover:opacity-100 disabled:opacity-40`,onClick:()=>void aa(a),disabled:P===a.id,title:"Delete",children:P===a.id?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(m.Trash2,{className:"h-4 w-4"})})]},a.id))})]}),(0,b.jsxs)("section",{className:ac,children:[(0,b.jsxs)("div",{className:ad,children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("h2",{className:"text-lg font-bold text-slate-900",children:"GitLab Credentials"}),(0,b.jsx)("p",{className:"mt-1 text-sm text-slate-500",children:"Connect to self-hosted or cloud GitLab instances."})]}),(0,b.jsxs)("button",{className:ag,onClick:()=>void $(),disabled:"gitlab"===L,children:["gitlab"===L?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(l.KeyRound,{className:"h-4 w-4"}),"Add Instance"]})]}),(0,b.jsxs)("div",{className:"space-y-4 border-b border-slate-100 bg-slate-50/40 px-6 py-4",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Server URL"}),(0,b.jsx)("input",{type:"url",className:ae,placeholder:q,value:F,onChange:a=>G(a.target.value),disabled:"gitlab"===L})]}),(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500",children:"Personal Access Token"}),(0,b.jsx)("input",{type:"password",className:ae,placeholder:"glpat-xxx",value:D,onChange:a=>E(a.target.value),disabled:"gitlab"===L})]})]}),0===W.length?(0,b.jsx)("div",{className:"px-6 py-6 text-sm text-slate-500",children:"No GitLab credentials saved."}):(0,b.jsx)("div",{className:"divide-y divide-slate-100",children:W.map(a=>(0,b.jsxs)("div",{className:"group flex items-center justify-between gap-4 px-6 py-5 transition-colors hover:bg-slate-50",children:[(0,b.jsxs)("div",{className:"flex min-w-0 items-center gap-4",children:[(0,b.jsx)("div",{className:"flex h-10 w-10 items-center justify-center rounded-lg bg-orange-50",children:(0,b.jsx)(x,{type:"gitlab"})}),(0,b.jsxs)("div",{className:"min-w-0",children:[(0,b.jsx)("div",{className:"truncate text-sm font-semibold text-slate-900",children:a.username}),(0,b.jsx)("div",{className:"truncate text-xs text-slate-500",children:a.serverUrl}),(0,b.jsxs)("div",{className:"mt-0.5 text-xs text-slate-500",children:["Updated ",new Date(a.updatedAt).toLocaleString()]})]})]}),(0,b.jsx)("button",{className:`${ah} opacity-0 group-hover:opacity-100 disabled:opacity-40`,onClick:()=>void aa(a),disabled:P===a.id,title:"Delete",children:P===a.id?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(m.Trash2,{className:"h-4 w-4"})})]},a.id))})]}),v.map(a=>{let c=X.get(a),d=N===a,e=R===a;return(0,b.jsxs)("section",{className:ac,children:[(0,b.jsxs)("div",{className:ad,children:[(0,b.jsxs)("div",{className:"flex items-center gap-3",children:[(0,b.jsx)("div",{className:"rounded-lg bg-emerald-100 p-1.5 text-emerald-600",children:(0,b.jsx)(l.KeyRound,{className:"h-5 w-5"})}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("h2",{className:"text-lg font-bold text-slate-900",children:[s[a]," Configuration"]}),(0,b.jsx)("p",{className:"text-sm text-slate-500",children:"Configure access for LLM capabilities."})]})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[c&&(0,b.jsxs)("button",{className:ag,onClick:()=>void ab(a),disabled:d||e,children:[e?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(m.Trash2,{className:"h-4 w-4"}),"Remove"]}),(0,b.jsxs)("button",{className:af,onClick:()=>void _(a),disabled:d||e,children:[d?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(l.KeyRound,{className:"h-4 w-4"}),c?"Save Changes":"Save"]})]})]}),(0,b.jsxs)("div",{className:"space-y-6 p-6",children:[(0,b.jsxs)("div",{className:"max-w-2xl space-y-4",children:[(0,b.jsxs)("div",{children:[(0,b.jsx)("label",{className:"mb-2 block text-sm font-medium text-slate-700",children:"API Key"}),(0,b.jsx)("input",{type:"password",className:ae,placeholder:t[a],value:H[a],onChange:b=>I(c=>({...c,[a]:b.target.value})),disabled:d||e}),(0,b.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"Your API key is stored locally and never shared."})]}),(0,b.jsxs)("div",{children:[(0,b.jsxs)("label",{className:"mb-2 block text-sm font-medium text-slate-700",children:["API Proxy ",(0,b.jsx)("span",{className:"font-normal text-slate-400",children:"(Optional)"})]}),(0,b.jsx)("input",{type:"url",className:ae,placeholder:u[a],value:J[a],onChange:b=>K(c=>({...c,[a]:b.target.value})),disabled:d||e}),(0,b.jsx)("p",{className:"mt-1 text-xs text-slate-500",children:"Override this when using a proxy or a compatible endpoint."})]})]}),(0,b.jsx)("div",{className:"rounded-lg border border-slate-200 bg-slate-50 p-3 text-xs text-slate-600",children:c?(0,b.jsxs)("div",{className:"space-y-1",children:[(0,b.jsx)("div",{children:"API key configured."}),(0,b.jsxs)("div",{children:["Updated ",new Date(c.updatedAt).toLocaleString()]}),(0,b.jsxs)("div",{children:["Proxy ",c.apiProxy?c.apiProxy:"not set"]})]}):(0,b.jsx)("div",{children:"No API credential saved."})})]})]},a)}),(0,b.jsx)("div",{className:"pb-2 pt-4 text-center text-xs text-slate-400",children:"Credentials are encrypted at rest using your system keychain."})]})]})})}a.s(["default",()=>y],12465)}];
2
+
3
+ //# sourceMappingURL=src_app_credentials_page_tsx_63d8d34a._.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"sources":["../../../../src/app/credentials/page.tsx","../../../../src/app/actions/data%3A3b32f8%20%3Ctext/javascript%3E","../../../../src/app/actions/data%3A96058b%20%3Ctext/javascript%3E","../../../../src/app/actions/data%3Aa51241%20%3Ctext/javascript%3E","../../../../src/app/actions/data%3A119757%20%3Ctext/javascript%3E","../../../../src/app/actions/data%3A4d6714%20%3Ctext/javascript%3E"],"sourcesContent":["'use client';\n\nimport {\n listAgentApiCredentials,\n listCredentials,\n removeAgentApiCredential,\n removeCredential,\n saveAgentApiCredential,\n saveGitHubCredential,\n saveGitLabCredential,\n} from '@/app/actions/credentials';\nimport type {\n AgentApiCredential,\n AgentApiCredentialAgent,\n} from '@/lib/agent-api-credentials';\nimport type { Credential, CredentialType, GitLabCredential } from '@/lib/credentials';\nimport { ChevronRight, KeyRound, Trash2 } from 'lucide-react';\nimport Image from 'next/image';\nimport { useRouter } from 'next/navigation';\nimport { useEffect, useMemo, useState } from 'react';\n\nconst DEFAULT_GITLAB_SERVER_URL = 'https://gitlab.com';\nconst PROVIDER_ICON_URLS = {\n github: 'https://www.google.com/s2/favicons?domain=github.com&sz=64',\n gitlab: 'https://www.google.com/s2/favicons?domain=gitlab.com&sz=64',\n} as const;\nconst AGENT_API_LABELS: Record<AgentApiCredentialAgent, string> = {\n codex: 'Codex CLI',\n};\nconst AGENT_API_KEY_PLACEHOLDERS: Record<AgentApiCredentialAgent, string> = {\n codex: 'sk-...',\n};\nconst AGENT_API_PROXY_PLACEHOLDERS: Record<AgentApiCredentialAgent, string> = {\n codex: 'https://proxy.example.com/v1',\n};\nconst AGENT_API_ORDER: AgentApiCredentialAgent[] = ['codex'];\n\ntype FlashMessage = {\n tone: 'success' | 'error';\n text: string;\n} | null;\n\nfunction formatCredentialSubtitle(credential: Credential): string {\n if (credential.type === 'gitlab') {\n return `${credential.username} @ ${credential.serverUrl}`;\n }\n return credential.username;\n}\n\nfunction formatProviderLabel(type: CredentialType): string {\n return type === 'github' ? 'GitHub' : 'GitLab';\n}\n\nfunction ProviderIcon({ type }: { type: CredentialType }) {\n return (\n <Image\n src={PROVIDER_ICON_URLS[type]}\n alt={`${formatProviderLabel(type)} icon`}\n width={20}\n height={20}\n className=\"h-5 w-5 rounded-sm\"\n unoptimized\n />\n );\n}\n\nexport default function CredentialsPage() {\n const router = useRouter();\n\n const [credentials, setCredentials] = useState<Credential[]>([]);\n const [agentApiCredentials, setAgentApiCredentials] = useState<AgentApiCredential[]>([]);\n const [loading, setLoading] = useState(true);\n\n const [githubToken, setGitHubToken] = useState('');\n const [gitlabToken, setGitLabToken] = useState('');\n const [gitlabServerUrl, setGitLabServerUrl] = useState(DEFAULT_GITLAB_SERVER_URL);\n const [agentApiKeyInputs, setAgentApiKeyInputs] = useState<Record<AgentApiCredentialAgent, string>>({\n codex: '',\n });\n const [agentApiProxyInputs, setAgentApiProxyInputs] = useState<Record<AgentApiCredentialAgent, string>>({\n codex: '',\n });\n\n const [savingType, setSavingType] = useState<CredentialType | null>(null);\n const [savingAgent, setSavingAgent] = useState<AgentApiCredentialAgent | null>(null);\n const [deletingId, setDeletingId] = useState<string | null>(null);\n const [deletingAgent, setDeletingAgent] = useState<AgentApiCredentialAgent | null>(null);\n const [flashMessage, setFlashMessage] = useState<FlashMessage>(null);\n\n const githubCredentials = useMemo(\n () => credentials.filter((credential) => credential.type === 'github'),\n [credentials],\n );\n\n const gitlabCredentials = useMemo(\n () => credentials.filter((credential) => credential.type === 'gitlab') as GitLabCredential[],\n [credentials],\n );\n\n const agentApiCredentialMap = useMemo(() => {\n return new Map(agentApiCredentials.map((credential) => [credential.agent, credential]));\n }, [agentApiCredentials]);\n\n const reloadCredentials = async () => {\n const [gitResult, agentResult] = await Promise.all([\n listCredentials(),\n listAgentApiCredentials(),\n ]);\n\n if (!gitResult.success) {\n setFlashMessage({ tone: 'error', text: gitResult.error });\n setLoading(false);\n return;\n }\n\n if (!agentResult.success) {\n setFlashMessage({ tone: 'error', text: agentResult.error });\n setLoading(false);\n return;\n }\n\n setCredentials(gitResult.credentials);\n setAgentApiCredentials(agentResult.credentials);\n setAgentApiProxyInputs((previous) => {\n const next = { ...previous };\n for (const agent of AGENT_API_ORDER) {\n next[agent] = agentResult.credentials.find((credential) => credential.agent === agent)?.apiProxy || '';\n }\n return next;\n });\n setLoading(false);\n };\n\n useEffect(() => {\n let isActive = true;\n\n void (async () => {\n const [gitResult, agentResult] = await Promise.all([\n listCredentials(),\n listAgentApiCredentials(),\n ]);\n if (!isActive) return;\n\n if (!gitResult.success) {\n setFlashMessage({ tone: 'error', text: gitResult.error });\n setLoading(false);\n return;\n }\n\n if (!agentResult.success) {\n setFlashMessage({ tone: 'error', text: agentResult.error });\n setLoading(false);\n return;\n }\n\n setCredentials(gitResult.credentials);\n setAgentApiCredentials(agentResult.credentials);\n setAgentApiProxyInputs((previous) => {\n const next = { ...previous };\n for (const agent of AGENT_API_ORDER) {\n next[agent] = agentResult.credentials.find((credential) => credential.agent === agent)?.apiProxy || '';\n }\n return next;\n });\n setLoading(false);\n })();\n\n return () => {\n isActive = false;\n };\n }, []);\n\n const handleSaveGitHub = async () => {\n setFlashMessage(null);\n setSavingType('github');\n\n const result = await saveGitHubCredential(githubToken);\n if (!result.success) {\n setFlashMessage({ tone: 'error', text: result.error });\n setSavingType(null);\n return;\n }\n\n setGitHubToken('');\n setFlashMessage({ tone: 'success', text: 'GitHub credential added.' });\n await reloadCredentials();\n setSavingType(null);\n };\n\n const handleSaveGitLab = async () => {\n setFlashMessage(null);\n setSavingType('gitlab');\n\n const result = await saveGitLabCredential(gitlabServerUrl, gitlabToken);\n if (!result.success) {\n setFlashMessage({ tone: 'error', text: result.error });\n setSavingType(null);\n return;\n }\n\n setGitLabToken('');\n setFlashMessage({ tone: 'success', text: 'GitLab credential added.' });\n await reloadCredentials();\n setSavingType(null);\n };\n\n const handleSaveAgentApi = async (agent: AgentApiCredentialAgent) => {\n setFlashMessage(null);\n setSavingAgent(agent);\n\n const result = await saveAgentApiCredential(\n agent,\n agentApiKeyInputs[agent],\n agentApiProxyInputs[agent],\n );\n if (!result.success) {\n setFlashMessage({ tone: 'error', text: result.error });\n setSavingAgent(null);\n return;\n }\n\n setAgentApiKeyInputs((previous) => ({ ...previous, [agent]: '' }));\n setAgentApiProxyInputs((previous) => ({ ...previous, [agent]: result.credential.apiProxy || '' }));\n setFlashMessage({ tone: 'success', text: `${AGENT_API_LABELS[agent]} credential saved.` });\n await reloadCredentials();\n setSavingAgent(null);\n };\n\n const handleDelete = async (credential: Credential) => {\n const providerLabel = formatProviderLabel(credential.type);\n const confirmed = confirm(`Delete this ${providerLabel} credential for ${formatCredentialSubtitle(credential)}?`);\n if (!confirmed) return;\n\n setFlashMessage(null);\n setDeletingId(credential.id);\n\n const result = await removeCredential(credential.id);\n if (!result.success) {\n setFlashMessage({ tone: 'error', text: result.error });\n setDeletingId(null);\n return;\n }\n\n setFlashMessage({ tone: 'success', text: `${providerLabel} credential deleted.` });\n await reloadCredentials();\n setDeletingId(null);\n };\n\n const handleDeleteAgentApi = async (agent: AgentApiCredentialAgent) => {\n const confirmed = confirm(`Delete the saved ${AGENT_API_LABELS[agent]} API credential?`);\n if (!confirmed) return;\n\n setFlashMessage(null);\n setDeletingAgent(agent);\n\n const result = await removeAgentApiCredential(agent);\n if (!result.success) {\n setFlashMessage({ tone: 'error', text: result.error });\n setDeletingAgent(null);\n return;\n }\n\n setAgentApiKeyInputs((previous) => ({ ...previous, [agent]: '' }));\n setAgentApiProxyInputs((previous) => ({ ...previous, [agent]: '' }));\n setFlashMessage({ tone: 'success', text: `${AGENT_API_LABELS[agent]} credential deleted.` });\n await reloadCredentials();\n setDeletingAgent(null);\n };\n\n const panelClass = 'overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm';\n const sectionHeaderClass = 'flex flex-col gap-3 border-b border-slate-200 px-6 py-5 md:flex-row md:items-center md:justify-between';\n const inputClass = 'block w-full rounded-lg border border-slate-200 bg-slate-50 px-3 py-2.5 text-sm text-slate-900 placeholder-slate-400 transition-all focus:border-primary focus:outline-none focus:ring-2 focus:ring-primary/20 disabled:cursor-not-allowed disabled:opacity-60';\n const primaryButtonClass = 'inline-flex items-center justify-center gap-2 rounded-lg bg-primary px-4 py-2 text-sm font-medium text-white transition-colors hover:bg-blue-700 disabled:cursor-not-allowed disabled:opacity-60';\n const secondaryButtonClass = 'inline-flex items-center justify-center gap-2 rounded-lg border border-slate-200 bg-white px-4 py-2 text-sm font-medium text-slate-700 transition-colors hover:bg-slate-50 disabled:cursor-not-allowed disabled:opacity-60';\n const rowActionButtonClass = 'inline-flex h-8 w-8 items-center justify-center rounded-lg text-slate-400 transition-all hover:bg-red-50 hover:text-red-500';\n\n return (\n <main className=\"min-h-screen bg-[#f6f6f8] px-4 py-8 md:px-8 md:py-12\">\n <div className=\"mx-auto w-full max-w-4xl space-y-8\">\n <div className=\"mb-8\">\n <div className=\"mb-2 flex items-center gap-4\">\n <button\n type=\"button\"\n className=\"flex h-10 w-10 items-center justify-center rounded-lg text-slate-500 transition-colors hover:bg-white hover:text-slate-900\"\n onClick={() => router.push('/')}\n aria-label=\"Back to home\"\n >\n <ChevronRight className=\"h-6 w-6 rotate-180\" />\n </button>\n <h1 className=\"text-3xl font-black tracking-[-0.02em] text-slate-900 md:text-4xl\">Credential Management</h1>\n </div>\n <p className=\"ml-14 text-sm text-slate-500 md:text-base\">\n Manage your API keys and access tokens for third-party services safely.\n </p>\n </div>\n\n {flashMessage && (\n <div\n className={`rounded-lg border px-4 py-3 text-sm ${\n flashMessage.tone === 'error'\n ? 'border-red-200 bg-red-50 text-red-700'\n : 'border-emerald-200 bg-emerald-50 text-emerald-700'\n }`}\n >\n {flashMessage.text}\n </div>\n )}\n\n {loading ? (\n <div className={`${panelClass} p-10`}>\n <div className=\"flex flex-col items-center gap-3\">\n <span className=\"loading loading-spinner loading-md text-primary\"></span>\n <p className=\"text-sm text-slate-500\">Loading credentials...</p>\n </div>\n </div>\n ) : (\n <div className=\"space-y-6\">\n <section className={panelClass}>\n <div className={sectionHeaderClass}>\n <div>\n <h2 className=\"text-lg font-bold text-slate-900\">GitHub Credentials</h2>\n <p className=\"mt-1 text-sm text-slate-500\">Access private repositories and Gists.</p>\n </div>\n <button\n className={primaryButtonClass}\n onClick={() => void handleSaveGitHub()}\n disabled={savingType === 'github'}\n >\n {savingType === 'github' ? <span className=\"loading loading-spinner loading-xs\"></span> : <KeyRound className=\"h-4 w-4\" />}\n Add Token\n </button>\n </div>\n\n <div className=\"border-b border-slate-100 bg-slate-50/40 px-6 py-4\">\n <label className=\"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500\">\n Personal Access Token\n </label>\n <input\n type=\"password\"\n className={inputClass}\n placeholder=\"ghp_xxx\"\n value={githubToken}\n onChange={(event) => setGitHubToken(event.target.value)}\n disabled={savingType === 'github'}\n />\n </div>\n\n {githubCredentials.length === 0 ? (\n <div className=\"px-6 py-6 text-sm text-slate-500\">No GitHub credentials saved.</div>\n ) : (\n <div className=\"divide-y divide-slate-100\">\n {githubCredentials.map((credential) => (\n <div\n key={credential.id}\n className=\"group flex items-center justify-between gap-4 px-6 py-5 transition-colors hover:bg-slate-50\"\n >\n <div className=\"flex min-w-0 items-center gap-4\">\n <div className=\"flex h-10 w-10 items-center justify-center rounded-lg bg-slate-100\">\n <ProviderIcon type=\"github\" />\n </div>\n <div className=\"min-w-0\">\n <div className=\"truncate text-sm font-semibold text-slate-900\">{credential.username}</div>\n <div className=\"mt-0.5 text-xs text-slate-500\">\n Updated {new Date(credential.updatedAt).toLocaleString()}\n </div>\n </div>\n </div>\n <button\n className={`${rowActionButtonClass} opacity-0 group-hover:opacity-100 disabled:opacity-40`}\n onClick={() => void handleDelete(credential)}\n disabled={deletingId === credential.id}\n title=\"Delete\"\n >\n {deletingId === credential.id ? <span className=\"loading loading-spinner loading-xs\"></span> : <Trash2 className=\"h-4 w-4\" />}\n </button>\n </div>\n ))}\n </div>\n )}\n </section>\n\n <section className={panelClass}>\n <div className={sectionHeaderClass}>\n <div>\n <h2 className=\"text-lg font-bold text-slate-900\">GitLab Credentials</h2>\n <p className=\"mt-1 text-sm text-slate-500\">Connect to self-hosted or cloud GitLab instances.</p>\n </div>\n <button\n className={secondaryButtonClass}\n onClick={() => void handleSaveGitLab()}\n disabled={savingType === 'gitlab'}\n >\n {savingType === 'gitlab' ? <span className=\"loading loading-spinner loading-xs\"></span> : <KeyRound className=\"h-4 w-4\" />}\n Add Instance\n </button>\n </div>\n\n <div className=\"space-y-4 border-b border-slate-100 bg-slate-50/40 px-6 py-4\">\n <div>\n <label className=\"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500\">\n Server URL\n </label>\n <input\n type=\"url\"\n className={inputClass}\n placeholder={DEFAULT_GITLAB_SERVER_URL}\n value={gitlabServerUrl}\n onChange={(event) => setGitLabServerUrl(event.target.value)}\n disabled={savingType === 'gitlab'}\n />\n </div>\n <div>\n <label className=\"mb-2 block text-xs font-semibold uppercase tracking-wide text-slate-500\">\n Personal Access Token\n </label>\n <input\n type=\"password\"\n className={inputClass}\n placeholder=\"glpat-xxx\"\n value={gitlabToken}\n onChange={(event) => setGitLabToken(event.target.value)}\n disabled={savingType === 'gitlab'}\n />\n </div>\n </div>\n\n {gitlabCredentials.length === 0 ? (\n <div className=\"px-6 py-6 text-sm text-slate-500\">No GitLab credentials saved.</div>\n ) : (\n <div className=\"divide-y divide-slate-100\">\n {gitlabCredentials.map((credential) => (\n <div\n key={credential.id}\n className=\"group flex items-center justify-between gap-4 px-6 py-5 transition-colors hover:bg-slate-50\"\n >\n <div className=\"flex min-w-0 items-center gap-4\">\n <div className=\"flex h-10 w-10 items-center justify-center rounded-lg bg-orange-50\">\n <ProviderIcon type=\"gitlab\" />\n </div>\n <div className=\"min-w-0\">\n <div className=\"truncate text-sm font-semibold text-slate-900\">{credential.username}</div>\n <div className=\"truncate text-xs text-slate-500\">{credential.serverUrl}</div>\n <div className=\"mt-0.5 text-xs text-slate-500\">\n Updated {new Date(credential.updatedAt).toLocaleString()}\n </div>\n </div>\n </div>\n <button\n className={`${rowActionButtonClass} opacity-0 group-hover:opacity-100 disabled:opacity-40`}\n onClick={() => void handleDelete(credential)}\n disabled={deletingId === credential.id}\n title=\"Delete\"\n >\n {deletingId === credential.id ? <span className=\"loading loading-spinner loading-xs\"></span> : <Trash2 className=\"h-4 w-4\" />}\n </button>\n </div>\n ))}\n </div>\n )}\n </section>\n\n {AGENT_API_ORDER.map((agent) => {\n const configuredCredential = agentApiCredentialMap.get(agent);\n const isSaving = savingAgent === agent;\n const isDeleting = deletingAgent === agent;\n\n return (\n <section key={agent} className={panelClass}>\n <div className={sectionHeaderClass}>\n <div className=\"flex items-center gap-3\">\n <div className=\"rounded-lg bg-emerald-100 p-1.5 text-emerald-600\">\n <KeyRound className=\"h-5 w-5\" />\n </div>\n <div>\n <h2 className=\"text-lg font-bold text-slate-900\">{AGENT_API_LABELS[agent]} Configuration</h2>\n <p className=\"text-sm text-slate-500\">Configure access for LLM capabilities.</p>\n </div>\n </div>\n <div className=\"flex items-center gap-2\">\n {configuredCredential && (\n <button\n className={secondaryButtonClass}\n onClick={() => void handleDeleteAgentApi(agent)}\n disabled={isSaving || isDeleting}\n >\n {isDeleting ? <span className=\"loading loading-spinner loading-xs\"></span> : <Trash2 className=\"h-4 w-4\" />}\n Remove\n </button>\n )}\n <button\n className={primaryButtonClass}\n onClick={() => void handleSaveAgentApi(agent)}\n disabled={isSaving || isDeleting}\n >\n {isSaving ? <span className=\"loading loading-spinner loading-xs\"></span> : <KeyRound className=\"h-4 w-4\" />}\n {configuredCredential ? 'Save Changes' : 'Save'}\n </button>\n </div>\n </div>\n\n <div className=\"space-y-6 p-6\">\n <div className=\"max-w-2xl space-y-4\">\n <div>\n <label className=\"mb-2 block text-sm font-medium text-slate-700\">API Key</label>\n <input\n type=\"password\"\n className={inputClass}\n placeholder={AGENT_API_KEY_PLACEHOLDERS[agent]}\n value={agentApiKeyInputs[agent]}\n onChange={(event) =>\n setAgentApiKeyInputs((previous) => ({ ...previous, [agent]: event.target.value }))\n }\n disabled={isSaving || isDeleting}\n />\n <p className=\"mt-1 text-xs text-slate-500\">\n Your API key is stored locally and never shared.\n </p>\n </div>\n\n <div>\n <label className=\"mb-2 block text-sm font-medium text-slate-700\">\n API Proxy <span className=\"font-normal text-slate-400\">(Optional)</span>\n </label>\n <input\n type=\"url\"\n className={inputClass}\n placeholder={AGENT_API_PROXY_PLACEHOLDERS[agent]}\n value={agentApiProxyInputs[agent]}\n onChange={(event) =>\n setAgentApiProxyInputs((previous) => ({ ...previous, [agent]: event.target.value }))\n }\n disabled={isSaving || isDeleting}\n />\n <p className=\"mt-1 text-xs text-slate-500\">\n Override this when using a proxy or a compatible endpoint.\n </p>\n </div>\n </div>\n\n <div className=\"rounded-lg border border-slate-200 bg-slate-50 p-3 text-xs text-slate-600\">\n {configuredCredential ? (\n <div className=\"space-y-1\">\n <div>API key configured.</div>\n <div>Updated {new Date(configuredCredential.updatedAt).toLocaleString()}</div>\n <div>Proxy {configuredCredential.apiProxy ? configuredCredential.apiProxy : 'not set'}</div>\n </div>\n ) : (\n <div>No API credential saved.</div>\n )}\n </div>\n </div>\n </section>\n );\n })}\n\n <div className=\"pb-2 pt-4 text-center text-xs text-slate-400\">\n Credentials are encrypted at rest using your system keychain.\n </div>\n </div>\n )}\n </div>\n </main>\n );\n}\n","/* __next_internal_action_entry_do_not_use__ [{\"407dd022f450835e92452755c2187f2759ce65a352\":\"removeAgentApiCredential\"},\"src/app/actions/credentials.ts\",\"\"] */\"use turbopack no side effects\";import{createServerReference,callServer,findSourceMapURL}from\"private-next-rsc-action-client-wrapper\";const $$RSC_SERVER_ACTION_6=/*#__PURE__*/createServerReference(\"407dd022f450835e92452755c2187f2759ce65a352\",callServer,void 0,findSourceMapURL,\"removeAgentApiCredential\");export{$$RSC_SERVER_ACTION_6 as removeAgentApiCredential};","/* __next_internal_action_entry_do_not_use__ [{\"40549b442d0eb35deaec280c1a3ac69584e89086a5\":\"removeCredential\"},\"src/app/actions/credentials.ts\",\"\"] */\"use turbopack no side effects\";import{createServerReference,callServer,findSourceMapURL}from\"private-next-rsc-action-client-wrapper\";const $$RSC_SERVER_ACTION_5=/*#__PURE__*/createServerReference(\"40549b442d0eb35deaec280c1a3ac69584e89086a5\",callServer,void 0,findSourceMapURL,\"removeCredential\");export{$$RSC_SERVER_ACTION_5 as removeCredential};","/* __next_internal_action_entry_do_not_use__ [{\"708a3dd3737dc6efc62a9fa45a820696f5441c8d44\":\"saveAgentApiCredential\"},\"src/app/actions/credentials.ts\",\"\"] */\"use turbopack no side effects\";import{createServerReference,callServer,findSourceMapURL}from\"private-next-rsc-action-client-wrapper\";const $$RSC_SERVER_ACTION_4=/*#__PURE__*/createServerReference(\"708a3dd3737dc6efc62a9fa45a820696f5441c8d44\",callServer,void 0,findSourceMapURL,\"saveAgentApiCredential\");export{$$RSC_SERVER_ACTION_4 as saveAgentApiCredential};","/* __next_internal_action_entry_do_not_use__ [{\"4004a0e7ba2853a497f171ed16037e29939770bf9d\":\"saveGitHubCredential\"},\"src/app/actions/credentials.ts\",\"\"] */\"use turbopack no side effects\";import{createServerReference,callServer,findSourceMapURL}from\"private-next-rsc-action-client-wrapper\";const $$RSC_SERVER_ACTION_1=/*#__PURE__*/createServerReference(\"4004a0e7ba2853a497f171ed16037e29939770bf9d\",callServer,void 0,findSourceMapURL,\"saveGitHubCredential\");export{$$RSC_SERVER_ACTION_1 as saveGitHubCredential};","/* __next_internal_action_entry_do_not_use__ [{\"60cd0b78e5e61702e931c48bbfdc43d298af6e8439\":\"saveGitLabCredential\"},\"src/app/actions/credentials.ts\",\"\"] */\"use turbopack no side effects\";import{createServerReference,callServer,findSourceMapURL}from\"private-next-rsc-action-client-wrapper\";const $$RSC_SERVER_ACTION_2=/*#__PURE__*/createServerReference(\"60cd0b78e5e61702e931c48bbfdc43d298af6e8439\",callServer,void 0,findSourceMapURL,\"saveGitLabCredential\");export{$$RSC_SERVER_ACTION_2 as saveGitLabCredential};"],"names":[],"mappings":"wDAEA,EAAA,EAAA,CAAA,CAAA,OAAA,EAAA,EAAA,CAAA,CAAA,MCF+L,EAAA,EAAA,CAAA,CAAA,MAAsG,IAAM,EAAmC,CAAA,EAAA,EAAA,iBAAb,IA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,SAAU,GAAY,IAExB,CAAA,EAAA,EAAA,GAAA,EAAC,IAAA,CAAE,UAAU,uCAA8B,qEAM/C,CAAA,EAAA,EAAA,GAAA,EAAC,MAAA,CAAI,UAAU,qFACZ,EACC,CAAA,EAAA,EAAA,IAAA,EAAC,MAAA,CAAI,UAAU,sBACb,CAAA,EAAA,EAAA,GAAA,EAAC,MAAA,UAAI,wBACL,CAAA,EAAA,EAAA,IAAA,EAAC,MAAA,WAAI,WAAS,IAAI,KAAK,EAAqB,SAAS,EAAE,cAAc,MACrE,CAAA,EAAA,EAAA,IAAA,EAAC,MAAA,WAAI,SAAO,EAAqB,QAAQ,CAAG,EAAqB,QAAQ,CAAG,gBAG9E,CAAA,EAAA,EAAA,GAAA,EAAC,MAAA,UAAI,oCAhFC,EAsFlB,GAEA,CAAA,EAAA,EAAA,GAAA,EAAC,MAAA,CAAI,UAAU,wDAA+C,yEAQ1E"}
@@ -1,3 +1,3 @@
1
- module.exports=[96614,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(50944),e=a.i(5050);let f=(0,e.createServerReference)("40680fbad566ce34c1634c331f6e921c19709ea59e",e.callServer,void 0,e.findSourceMapURL,"deleteSessionInBackground"),g=(0,e.createServerReference)("406bf789af70e2f7eef5d094705c21faee26fd3bda",e.callServer,void 0,e.findSourceMapURL,"getSessionDivergence"),h=(0,e.createServerReference)("40086d94ce2e19d4438896357f233676499d09ef19",e.callServer,void 0,e.findSourceMapURL,"getSessionUncommittedFileCount"),i=(0,e.createServerReference)("40af6c3a1f065443d16922e21e841b2c4a9f64e44c",e.callServer,void 0,e.findSourceMapURL,"listSessionBaseBranches"),j=(0,e.createServerReference)("40cf613bb74d174a77592f958667741e177b9bd93c",e.callServer,void 0,e.findSourceMapURL,"mergeSessionToBase"),k=(0,e.createServerReference)("40091f4f3774789e187b4e3100a93732a9925cd76a",e.callServer,void 0,e.findSourceMapURL,"rebaseSessionOntoBase"),l=(0,e.createServerReference)("60641b475f71b1a40ff7d654b78b9bccdc11a37a0e",e.callServer,void 0,e.findSourceMapURL,"updateSessionBaseBranch"),m=(0,e.createServerReference)("600914a92951e5c4585056c643fac9a12f510bd32c",e.callServer,void 0,e.findSourceMapURL,"writeSessionPromptFile"),n=(0,e.createServerReference)("7f288f0f032c6b14129f525038d9f3cf7a5e0497c6",e.callServer,void 0,e.findSourceMapURL,"setTmuxSessionMouseMode"),o=(0,e.createServerReference)("7fe7e863ea2d1e27da9e00096925f65033e91847f8",e.callServer,void 0,e.findSourceMapURL,"setTmuxSessionStatusVisibility");var p=a.i(26458),q=a.i(53019),r=a.i(81560),s=a.i(52495),t=a.i(25015),u=a.i(70106);let v=(0,u.default)("git-commit-horizontal",[["circle",{cx:"12",cy:"12",r:"3",key:"1v7zrd"}],["line",{x1:"3",x2:"9",y1:"12",y2:"12",key:"1dyftd"}],["line",{x1:"15",x2:"21",y1:"12",y2:"12",key:"oup4p8"}]]),w=(0,u.default)("git-merge",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]]),x=(0,u.default)("git-pull-request-arrow",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M5 9v12",key:"ih889a"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}]]);var y=a.i(10948);let z=(0,u.default)("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]),A=(0,u.default)("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),B=(0,u.default)("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]),C=(0,u.default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]),D=(0,u.default)("grip",[["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"19",cy:"5",r:"1",key:"w8mnmm"}],["circle",{cx:"5",cy:"5",r:"1",key:"lttvr7"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}],["circle",{cx:"19",cy:"19",r:"1",key:"shf9b7"}],["circle",{cx:"5",cy:"19",r:"1",key:"bfqh0e"}]]),E=(0,u.default)("chevron-down",[["path",{d:"m6 9 6 6 6-6",key:"qrunsl"}]]);var F=a.i(15618);let G=(0,u.default)("globe",[["circle",{cx:"12",cy:"12",r:"10",key:"1mglay"}],["path",{d:"M12 2a14.5 14.5 0 0 0 0 20 14.5 14.5 0 0 0 0-20",key:"13o1zl"}],["path",{d:"M2 12h20",key:"9i4pu4"}]]),H=(0,u.default)("mouse-pointer-2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);var I=a.i(210);let J=(0,u.default)("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),K=(0,u.default)("rotate-cw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);var L=a.i(71987),M=a.i(75349);let N=(0,e.createServerReference)("4087e739b493a68d47d717b3444b7e5259e48ba2b5",e.callServer,void 0,e.findSourceMapURL,"listPathEntries");var O=a.i(48212);let P=(0,u.default)("clipboard",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]]),Q=(0,u.default)("file-text",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);var R=a.i(92596);let S=(0,u.default)("grid-2x2",[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 12h18",key:"1i2n21"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),T=(0,u.default)("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]]),U=(0,u.default)("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),V=(0,u.default)("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),W=(0,u.default)("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);var X=a.i(11431),Y=a.i(94659);let Z="viba:session-file-browser:view-mode";function $({initialPath:a,worktreePath:d,onConfirm:e,onCancel:f,onPathChange:g}){let h=(0,c.useMemo)(()=>new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".ico",".avif"]),[]),[i,j]=(0,c.useState)(""),[k,l]=(0,c.useState)([]),[m,n]=(0,c.useState)(!1),[o,r]=(0,c.useState)(null),[s,t]=(0,c.useState)(""),[u,v]=(0,c.useState)([]),[w,x]=(0,c.useState)(null),[y,z]=(0,c.useState)("list"),[A,B]=(0,c.useState)(!1),[C,D]=(0,c.useState)({}),[E,F]=(0,c.useState)([]);(0,c.useEffect)(()=>{let b=!0;return(async()=>{try{let c=await (0,M.getHomeDirectory)();if(!b)return;t(c),a||j(c)}catch(a){console.error("Failed to resolve home directory:",a)}a&&b&&j(a)})(),()=>{b=!1}},[a]),(0,c.useEffect)(()=>{let a=!0;return(async()=>{try{let b=await (0,p.getConfig)();if(!a)return;let c=Array.isArray(b.pinnedFolderShortcuts)?b.pinnedFolderShortcuts.filter(a=>"string"==typeof a&&a.trim().length>0):[];F(Array.from(new Set(c)))}catch(a){console.error("Failed to load pinned folder shortcuts:",a)}})(),()=>{a=!1}},[]),(0,c.useEffect)(()=>{try{let a=localStorage.getItem(Z);("list"===a||"grid"===a)&&z(a)}catch{}finally{B(!0)}},[]),(0,c.useEffect)(()=>{if(A)try{localStorage.setItem(Z,y)}catch{}},[A,y]),(0,c.useEffect)(()=>{i&&(async()=>{n(!0),r(null);try{let a=await N(i);l(a)}catch(a){console.error("Failed to list files:",a),r("Failed to load directory contents")}finally{n(!1)}})()},[i]),(0,c.useEffect)(()=>{i&&g?.(i)},[i,g]),(0,c.useEffect)(()=>{v([]),x(null),D({})},[i]);let G=(0,c.useMemo)(()=>new Set(u),[u]),H=(a,b,c)=>{if(a.isDirectory)return void j(a.path);let d=c.metaKey||c.ctrlKey;if(c.shiftKey&&null!==w){let a=Math.min(w,b),c=Math.max(w,b);v(k.slice(a,c+1).filter(a=>!a.isDirectory).map(a=>a.path));return}if(d){v(b=>b.includes(a.path)?b.filter(b=>b!==a.path):[...b,a.path]),x(b);return}v([a.path]),x(b)},J=async()=>{if(r(null),!d)return void r("Cannot paste: Session worktree path is missing.");try{if(n(!0),!navigator.clipboard||!navigator.clipboard.read)throw Error("Clipboard API not supported in this browser");let a=await navigator.clipboard.read(),b=new FormData,c=!1;for(let d of a)for(let a of d.types)if(a.startsWith("image/")){let e=await d.getType(a),f=a.split("/")[1]||"png",g=`pasted-image-${Date.now()}.${f}`,h=new File([e],g,{type:a});b.append(g,h),c=!0;break}if(c){let a=await (0,O.saveAttachments)(d,b);if(a&&a.length>0)return void await e(a);r("Failed to save pasted files.")}else try{let a=await navigator.clipboard.readText();a&&a.trim().startsWith("/")?r("No file content found in clipboard. Copy an image or file first."):r("No file content found in clipboard.")}catch{r("No file content found in clipboard.")}}catch(b){let a=b instanceof Error?b.message:String(b);console.error("Paste error:",b),r(`Failed to read from clipboard: ${a}`)}finally{n(!1)}},K=async a=>{F(a);try{await (0,q.updateConfig)({pinnedFolderShortcuts:a})}catch(a){console.error("Failed to save pinned folder shortcuts:",a),r("Failed to save pinned shortcuts")}},$=async a=>{(r(null),E.includes(a))?await K(E.filter(b=>b!==a)):await K([...E,a])},_=(0,c.useCallback)(async()=>{0!==u.length&&await e(u)},[e,u]);return(0,Y.useDialogKeyboardShortcuts)({onConfirm:_,onDismiss:f,canConfirm:u.length>0}),(0,b.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",children:(0,b.jsxs)("div",{className:"bg-base-200 rounded-lg shadow-xl w-full max-w-5xl h-[82vh] flex flex-col",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-base-300",children:[(0,b.jsxs)("h2",{className:"text-xl font-bold flex items-center gap-2",children:[(0,b.jsx)(R.Folder,{className:"w-5 h-5"}),"Browse Files"]}),(0,b.jsx)("button",{onClick:f,className:"btn btn-sm btn-ghost btn-circle",title:"Close file browser",children:"✕"})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-base-300",children:[(0,b.jsx)("button",{onClick:()=>{let a=(0,X.getDirName)(i);a&&a!==i&&j(a)},className:"btn btn-sm btn-square btn-ghost",title:"Go Up",disabled:"/"===i||!i,children:(0,b.jsx)(I.ArrowLeft,{className:"w-4 h-4"})}),(0,b.jsxs)("button",{onClick:()=>{s&&i!==s&&j(s)},className:"btn btn-sm btn-ghost gap-1",title:s?`Go to Home Folder (${s})`:"Go to Home Folder",disabled:!s||i===s,children:[(0,b.jsx)(T,{className:"w-4 h-4"}),"Home"]}),(0,b.jsx)("div",{className:"flex-1 overflow-x-auto whitespace-nowrap px-2 font-mono text-sm",children:i}),(0,b.jsxs)("div",{className:"join",children:[(0,b.jsx)("button",{type:"button",onClick:()=>z("list"),className:`btn btn-sm join-item ${"list"===y?"btn-active":"btn-ghost"}`,title:"List view",children:(0,b.jsx)(U,{className:"w-4 h-4"})}),(0,b.jsx)("button",{type:"button",onClick:()=>z("grid"),className:`btn btn-sm join-item ${"grid"===y?"btn-active":"btn-ghost"}`,title:"Grid view",children:(0,b.jsx)(S,{className:"w-4 h-4"})})]}),(0,b.jsxs)("button",{onClick:_,className:"btn btn-sm btn-primary gap-2",disabled:0===u.length,title:"Insert selected absolute paths",children:["Insert (",u.length,")"]}),(0,b.jsx)("div",{className:"w-[1px] h-6 bg-base-content/10 mx-1"}),(0,b.jsxs)("button",{onClick:J,className:"btn btn-sm btn-ghost gap-2",title:"Paste file/image from clipboard",disabled:!d,children:[(0,b.jsx)(P,{className:"w-4 h-4"}),"Paste"]})]}),E.length>0&&(0,b.jsx)("div",{className:"px-3 py-2 border-b border-base-300 bg-base-200/50",children:(0,b.jsx)("div",{className:"flex items-center gap-2 overflow-x-auto",children:E.map(a=>{let c=a===i,d=a.split(/[\\/]/).filter(Boolean).pop()||a;return(0,b.jsxs)("div",{className:"join shrink-0",children:[(0,b.jsxs)("button",{type:"button",className:`btn btn-xs join-item ${c?"btn-primary":"btn-ghost"}`,onClick:()=>j(a),title:a,children:[(0,b.jsx)(R.Folder,{className:"w-3 h-3"}),d]}),(0,b.jsx)("button",{type:"button",className:"btn btn-xs btn-ghost join-item",onClick:()=>void $(a),title:`Unpin ${a}`,children:(0,b.jsx)(W,{className:"w-3 h-3"})})]},a)})})}),(0,b.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:m?(0,b.jsx)("div",{className:"flex justify-center items-center h-full",children:(0,b.jsx)("span",{className:"loading loading-spinner loading-lg"})}):o?(0,b.jsx)("div",{className:"alert alert-error",children:o}):0===k.length?(0,b.jsx)("div",{className:"text-center text-base-content/50 mt-10",children:"Empty directory"}):"list"===y?(0,b.jsx)("div",{className:"grid grid-cols-1 gap-1",children:k.map((a,c)=>{let d=G.has(a.path);return(0,b.jsxs)("div",{className:`flex items-center justify-between p-2 rounded-md cursor-pointer transition-colors border ${d?"bg-primary text-primary-content border-primary":"hover:bg-base-100 border-transparent"}`,onClick:b=>H(a,c,b),title:a.path,children:[(0,b.jsxs)("div",{className:"flex items-center gap-3 overflow-hidden",children:[a.isDirectory?(0,b.jsx)(R.Folder,{className:"w-5 h-5 shrink-0"}):(0,b.jsx)(Q,{className:"w-5 h-5 shrink-0"}),(0,b.jsx)("span",{className:"truncate",children:a.name})]}),(0,b.jsx)("span",{className:"text-[10px] opacity-70 shrink-0",children:a.isDirectory?(0,b.jsx)("button",{type:"button",className:"btn btn-ghost btn-xs h-6 min-h-6",onClick:b=>{b.stopPropagation(),$(a.path)},title:E.includes(a.path)?"Unpin folder":"Pin folder",children:(0,b.jsx)(V,{className:`w-3 h-3 ${E.includes(a.path)?"fill-current":""}`})}):"file"})]},a.path)})}):(0,b.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-3",children:k.map((a,c)=>{var d;let e,f=G.has(a.path),g=!a.isDirectory&&-1!==(e=(d=a.name).lastIndexOf("."))&&h.has(d.slice(e).toLowerCase()),i=`/api/file-thumbnail?path=${encodeURIComponent(a.path)}`;return(0,b.jsxs)("button",{type:"button",className:`rounded-lg border text-left overflow-hidden transition-colors ${f?"border-primary bg-primary/15":"border-base-300 hover:bg-base-100"}`,onClick:b=>H(a,c,b),title:a.path,children:[(0,b.jsxs)("div",{className:"aspect-square bg-base-300 flex items-center justify-center overflow-hidden relative",children:[g&&!C[a.path]?(0,b.jsx)(L.default,{src:i,alt:a.name,fill:!0,sizes:"(max-width: 768px) 50vw, (max-width: 1024px) 25vw, 20vw",className:"object-cover",unoptimized:!0,onError:()=>D(b=>({...b,[a.path]:!0}))}):a.isDirectory?(0,b.jsx)(R.Folder,{className:"w-10 h-10 opacity-80"}):(0,b.jsx)(Q,{className:"w-10 h-10 opacity-80"}),a.isDirectory&&(0,b.jsx)("button",{type:"button",className:`absolute top-1 right-1 btn btn-xs btn-circle ${E.includes(a.path)?"btn-primary":"btn-ghost bg-base-100/70"}`,onClick:b=>{b.stopPropagation(),$(a.path)},title:E.includes(a.path)?"Unpin folder":"Pin folder",children:(0,b.jsx)(V,{className:`w-3 h-3 ${E.includes(a.path)?"fill-current":""}`})})]}),(0,b.jsxs)("div",{className:"px-2 py-2",children:[(0,b.jsx)("div",{className:"truncate text-sm font-medium",title:a.name,children:a.name}),(0,b.jsx)("div",{className:"text-[10px] opacity-70",children:a.isDirectory?"folder":g?"image":"file"})]})]},a.path)})})}),(0,b.jsx)("div",{className:"p-3 border-t border-base-300 text-xs text-base-content/60 text-center",children:"Click: single select. Cmd/Ctrl+Click: multi-select. Shift+Click: range select. Click a folder to open it."})]})})}var _=a.i(12627);function aa(a,b,c){var d,e;let f=(d=a,e=b,`viba-${(d.trim().replace(/[^a-zA-Z0-9_-]/g,"-")||"session").slice(0,40)}-${e}`),g=new URLSearchParams;return g.append("arg","new-session"),c?.value&&(g.append("arg","-e"),g.append("arg",`${c.name}=${c.value}`)),g.append("arg","-A"),g.append("arg","-s"),g.append("arg",f),`/terminal?${g.toString()}`}let ab=a=>{let b=a.trim();return b?/^https?:\/\//i.test(b)?b:/^[a-z][a-z0-9+.-]*:/i.test(b)?null:`http://${b}`:null},ac=a=>`'${a.replace(/'/g,"'\\''")}'`,ad=[{id:"vscode",name:"VS Code",protocol:"vscode"},{id:"cursor",name:"Cursor",protocol:"cursor"},{id:"windsurf",name:"Windsurf",protocol:"windsurf"},{id:"antigravity",name:"Antigravity",protocol:"antigravity"}],ae="viba-terminal-size",af="viba-agent-preview-split-ratio",ag=/(?:\$|%|#|>) $/,ah=a=>Math.max(.2,Math.min(.8,a)),ai=(a,b)=>{let c=a.replace(/\\/g,"/").replace(/\/+$/,""),d=b.replace(/\\/g,"/").replace(/^\/+/,"");return`${c}/${d}`},aj=(a,b)=>{let c=b.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(!c)return null;let d=(a=>{let b=a.trim();if(!b)return"";if(b=b.replace(/[#?].*$/,""),/^file:\/\//i.test(b))try{let a=new URL(b);b=decodeURIComponent(a.pathname)}catch{}else if(/^https?:\/\//i.test(b))try{let a=new URL(b);b=decodeURIComponent(a.pathname)}catch{}return(b=b.replace(/^webpack(?:-internal)?:\/\/\/?/,"").replace(/^rsc:\/\//,"").replace(/^\(.*?\)\//,"").replace(/^\/\.\//,"/").replace(/^\.\//,"").replace(/\\/g,"/")).trim()})(a);if(!d)return null;if(d.startsWith("/")||(0,X.isWindowsAbsolutePath)(d))return d;let e=new Set;e.add(d.replace(/^\.\/+/,""));let f=d.indexOf("/src/");for(let a of(f>=0&&e.add(d.slice(f+1)),d.startsWith("src/")&&e.add(d),e))if(a)return ai(c,a);return null},ak=a=>{let b=a.trim();if(!b)return"";let c=b.match(/[A-Za-z_$][\w$]*/);return c?c[0]:""};function al({repo:a,worktree:d,branch:e,baseBranch:u,sessionName:L,agent:M,model:N,startupScript:O,devServerScript:P,initialMessage:Q,attachmentNames:R,title:S,sessionMode:T="fast",onExit:U,isResume:V,terminalPersistenceMode:W="shell",onSessionStart:Y,agentTerminalSrc:Z,floatingTerminalSrc:ai}){let al="hidden min-[1900px]:inline",am=(0,c.useRef)(null),an=(0,c.useRef)(null),ao=(0,c.useRef)(null),ap=(0,c.useRef)(null),aq=(0,c.useRef)(null),ar=(0,c.useRef)({startX:0,startRatio:.5}),as=(0,c.useRef)(null),at=(0,c.useRef)(null),au=(0,c.useRef)(null),av=(0,c.useRef)({injected:!1,timer:null}),aw=(0,c.useMemo)(()=>Z||aa(L,"agent"),[Z,L]),ax=(0,c.useMemo)(()=>ai||aa(L,"terminal"),[ai,L]),ay=(0,c.useRef)({agent:"idle",terminal:"idle"}),az=(0,c.useRef)({agent:!1,terminal:!1});(0,c.useEffect)(()=>{ay.current={agent:"idle",terminal:"idle"},az.current={agent:!1,terminal:!1},null!==av.current.timer&&window.clearTimeout(av.current.timer),av.current={injected:!1,timer:null}},[L]),(0,c.useEffect)(()=>()=>{null!==av.current.timer&&(window.clearTimeout(av.current.timer),av.current.timer=null)},[]);let aA=(0,c.useCallback)(a=>`viba:terminal-bootstrap:${L}:${a}`,[L]),aB=(0,c.useCallback)(a=>`${L}:${a}`,[L]),aC=(0,c.useCallback)(()=>null,[]),aD=(0,c.useCallback)(a=>{let b=aC();return b&&b[aB(a)]||"idle"},[aC,aB]),aE=(0,c.useCallback)((a,b)=>{let c=aC();c&&(c[aB(a)]=b)},[aC,aB]),aF=(0,c.useCallback)(a=>{if("done"===ay.current[a]||"done"===aD(a))return!0;try{return"1"===window.sessionStorage.getItem(aA(a))}catch{return!1}},[aD,aA]),aG=(0,c.useCallback)(a=>{let b=ay.current[a],c=aD(a);return"done"!==b&&"in_progress"!==b&&"done"!==c&&"in_progress"!==c&&(ay.current[a]="in_progress",aE(a,"in_progress"),!0)},[aD,aE]),aH=(0,c.useCallback)(a=>{"done"!==ay.current[a]&&(ay.current[a]="idle"),"done"!==aD(a)&&aE(a,"idle")},[aD,aE]),aI=(0,c.useCallback)(a=>{ay.current[a]="done",aE(a,"done");try{window.sessionStorage.setItem(aA(a),"1")}catch{}},[aA,aE]),aJ=(0,c.useCallback)(a=>{let b=a?.buffer?.active;if(!b||"function"!=typeof b.getLine)return!0;let c=b.baseY+b.cursorY;for(let a=0;a<6;a+=1){let d=b.getLine(c-a),e=d?.translateToString(!0)??"";if(e.trim())return ag.test(e)}return!1},[]),aK=(0,c.useCallback)(()=>{au.current&&(au.current(),au.current=null)},[]),aL=(0,c.useCallback)((a,b)=>{aK();let c=!1,d=null,e=null,f=null,g=()=>{if(c)return;let a=!aJ(b);aW(b=>b===a?b:a)};g(),f=window.setInterval(g,1e3);try{if("function"==typeof b.onWriteParsed)d=b.onWriteParsed(g)||null;else{let b=a.contentDocument?.querySelector(".xterm-screen")||a.contentDocument?.body;b&&(e=new MutationObserver(g)).observe(b,{childList:!0,subtree:!0,characterData:!0})}}catch(a){console.error("Failed to setup terminal process monitor:",a)}au.current=()=>{c=!0,null!==f&&(window.clearInterval(f),f=null),d&&"function"==typeof d.dispose&&d.dispose(),e?.disconnect()}},[aJ,aK]);(0,c.useEffect)(()=>()=>{aK()},[aK]),(0,c.useEffect)(()=>{aW(!1),aK()},[L,aK]);let aM=(0,c.useCallback)((a,b,c)=>{if(V)return!1;let d=O?.trim();return!!d&&!av.current.injected&&(av.current.injected=!0,null!==av.current.timer&&window.clearTimeout(av.current.timer),av.current.timer=window.setTimeout(()=>{av.current.timer=null;try{let e;c.paste(d),(e=a.contentDocument?.querySelector("textarea.xterm-helper-textarea"))?e.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:b})):c.paste("\r")}catch(a){av.current.injected=!1,console.error("Failed to inject startup script into terminal iframe:",a)}},500),!0)},[V,O]);(0,c.useEffect)(()=>{if(V||!O?.trim()||av.current.injected)return;let a=!1,b=(c=0)=>{if(a||av.current.injected||c>30)return;if(!aF("terminal"))return void window.setTimeout(()=>b(c+1),200);let d=an.current;if(d){try{let a=d.contentWindow;if(a?.term)return void aM(d,a,a.term)}catch{}window.setTimeout(()=>b(c+1),200)}};return b(),()=>{a=!0}},[aF,aM,V,O]);let[aN,aO]=(0,c.useState)("Initializing..."),[aP,aQ]=(0,c.useState)("idle"),[aR,aS]=(0,c.useState)(null),[aT,aU]=(0,c.useState)(!1),[aV,aW]=(0,c.useState)(!1),[aX,aY]=(0,c.useState)(!1),[aZ,a$]=(0,c.useState)(!1),[a_,a0]=(0,c.useState)(!1),[a1,a2]=(0,c.useState)(!1),[a3,a4]=(0,c.useState)(d||a),[a5,a6]=(0,c.useState)(!1),[a7,a8]=(0,c.useState)(u?.trim()||""),[a9,ba]=(0,c.useState)([]),[bb,bc]=(0,c.useState)(!1),bd=(0,c.useRef)(!1),[be,bf]=(0,c.useState)(!1),[bg,bh]=(0,c.useState)({ahead:0,behind:0}),[bi,bj]=(0,c.useState)(0),[bk,bl]=(0,c.useState)(!1),[bm,bn]=(0,c.useState)(""),[bo,bp]=(0,c.useState)(""),[bq,br]=(0,c.useState)(!1),[bs,bt]=(0,c.useState)(!1),[bu,bv]=(0,c.useState)(.5),[bw,bx]=(0,c.useState)(!1),[by,bz]=(0,c.useState)(!0),[bA,bB]=(0,c.useState)({width:460,height:320}),[bC,bD]=(0,c.useState)(!1),[bE,bF]=(0,c.useState)(!1),bG=(0,c.useRef)({startX:0,startY:0,startWidth:0,startHeight:0}),[bH,bI]=(0,c.useState)("scroll"),[bJ,bK]=(0,c.useState)(!1),bL=(0,c.useRef)(0);(0,c.useEffect)(()=>{a4(d||a)},[a,d]),(0,c.useEffect)(()=>{let a=localStorage.getItem(ae);if(a)try{bB(JSON.parse(a))}catch(a){console.error("Failed to parse saved terminal size",a)}let b=localStorage.getItem(af);if(b){let a=Number.parseFloat(b);Number.isNaN(a)||bv(ah(a))}bF(!0)},[]),(0,c.useEffect)(()=>{if(!bC)return;let a=a=>{let b=bG.current.startX-a.clientX,c=bG.current.startY-a.clientY;bB({width:Math.max(300,Math.min(window.innerWidth-32,bG.current.startWidth+b)),height:Math.max(100,Math.min(window.innerHeight-32,bG.current.startHeight+c))})},b=()=>{bD(!1)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",b)}},[bC]),(0,c.useEffect)(()=>{bE&&!bC&&localStorage.setItem(ae,JSON.stringify(bA))},[bE,bC,bA]),(0,c.useEffect)(()=>{bE&&!bw&&localStorage.setItem(af,String(bu))},[bu,bE,bw]),(0,c.useEffect)(()=>{if(!bw)return;let a=a=>{let b=aq.current;if(!b)return;let c=b.getBoundingClientRect();if(c.width<=0)return;let d=a.clientX-ar.current.startX;bv(ah((ar.current.startRatio*c.width+d)/c.width))},b=()=>{bx(!1)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",b)}},[bw]),(0,c.useEffect)(()=>{if(!by&&an.current){let a=an.current;setTimeout(()=>{try{let b=a.contentWindow;if(b&&b.term){b.term.scrollToBottom?.(),b.focus();let c=a.contentDocument?.querySelector("textarea.xterm-helper-textarea");c&&c.focus()}}catch(a){console.error("Failed to focus/scroll terminal on restore:",a)}},100)}},[by]);let[bM,bN]=(0,c.useState)("vscode");(0,c.useEffect)(()=>{let a=S?.trim();if(a)return document.title=`${a} | Viba`,()=>{document.title="Viba"};document.title="Viba"},[S]),(0,c.useEffect)(()=>{(async()=>{let a=await (0,p.getConfig)();a.selectedIde&&ad.some(b=>b.id===a.selectedIde)&&bN(a.selectedIde)})()},[]),(0,c.useEffect)(()=>{a8(u?.trim()||""),ba([])},[u,L]),(0,c.useEffect)(()=>{bI("scroll"),bK(!1),bL.current+=1},[L]);let bO=async a=>{let b=a.target.value;bN(b),await (0,q.updateConfig)({selectedIde:b})},bP=(0,c.useCallback)(async(a,b)=>{if("tmux"!==W)return!0;let c=++bL.current;b?.silent||bK(!0);let d="scroll"===a,[e,f]=await Promise.all([n(L,"agent",d),n(L,"terminal",d)]);return c===bL.current&&((b?.silent||bK(!1),[e,f].find(a=>!a.success))?(b?.silent||aO(`Failed to switch to ${"scroll"===a?"scroll mode":"text select mode"}`),!1):(b?.silent||aO("scroll"===a?"Terminal mode: Scroll":"Terminal mode: Text Select"),!0))},[L,W]),bQ=(0,c.useCallback)(a=>{"tmux"!==W||az.current[a]||(async()=>{let b=await o(L,a,!1);b.success&&b.applied?az.current[a]=!0:b.success||console.error(`Failed to hide tmux status bar for ${a}:`,b.error)})()},[L,W]);(0,c.useEffect)(()=>{"tmux"===W&&bP("scroll",{silent:!0})},[bP,W]);let bR=(0,c.useCallback)(()=>{if("tmux"!==W||bJ)return;let a="scroll"===bH?"select":"scroll";bI(a),(async()=>{await bP(a)||bI(bH)})()},[bP,bJ,bH,W]),bS=async(b=!0)=>{if(!a||!d||!e||b&&!confirm("Are you sure you want to delete this session? This will remove the branch and worktree."))return!1;aS(null),aQ("idle"),aO("Purging session...");try{let a=await f(L);if(!a.success)return console.error("Cleanup failed:",a.error||"Unknown error"),aQ("error"),aS(a.error||"Failed to delete session"),!1;(0,_.notifySessionsUpdated)()}catch(a){return console.error("Cleanup request failed:",a),aQ("error"),aS(a instanceof Error?a.message:"Unknown error"),!1}return U(!0),!0},bT=async()=>{await bS(!0)},bU=(0,c.useCallback)((a,b)=>new Promise(c=>{let d=am.current;if(!d)return void c(!1);let f=(g=0)=>{if(g>30)return void c(!1);try{let h=d.contentWindow;if(!h||(h.postMessage({type:"viba:agent-request",action:b,prompt:a,sessionName:L,branch:e,baseBranch:a7||void 0,timestamp:Date.now()},"*"),!h.term))return void setTimeout(()=>f(g+1),300);h.term.paste(a);let i=d.contentDocument?.querySelector("textarea.xterm-helper-textarea");i?(i.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:h})),i.focus()):h.term.paste("\r"),h.focus(),c(!0)}catch(a){console.error("Failed to send prompt to agent iframe:",a),setTimeout(()=>f(g+1),300)}};f()}),[e,a7,L]),bV=async()=>{aY(!0),aO("Requesting commit from agent..."),aO(await bU("Please create a git commit with the current changes in this worktree.","commit")?"Commit request sent to agent":"Failed to send commit request to agent"),aY(!1)},bW=(0,c.useCallback)(a=>new Promise(b=>{let c=am.current;if(!c)return void b(!1);let d=(e=0)=>{if(e>30)return void b(!1);try{let f=c.contentWindow;if(!f||!f.term)return void setTimeout(()=>d(e+1),300);f.term.paste(a);let g=c.contentDocument?.querySelector("textarea.xterm-helper-textarea");g&&g.focus(),f.focus(),b(!0)}catch(a){console.error("Failed to paste into agent iframe:",a),setTimeout(()=>d(e+1),300)}};d()}),[]),bX=(0,c.useCallback)(async a=>{if(0===a.length)return;a6(!0);let b=`${a.join(" ")} `;aO(await bW(b)?`Inserted ${a.length} file path${1===a.length?"":"s"} into agent input`:"Failed to insert file paths into agent input"),a6(!1)},[bW]),bY=(0,c.useCallback)(async b=>{let c=b.map(ak).filter(Boolean);if(0===c.length)return null;let e=Array.from(new Set([a,d].map(a=>(a||"").trim()).filter(Boolean)));if(0===e.length)return null;for(let a of e)try{let b=await fetch("/api/component-source/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({componentNames:c,workspaceRoot:a})}),d=await b.json().catch(()=>null);if(!b.ok){console.warn("Component source resolve miss",{componentNames:c,workspaceRoot:a,error:d?.error||b.statusText});continue}let e="string"==typeof d?.sourcePath?d.sourcePath.trim():"",f="string"==typeof d?.resolvedName?d.resolvedName.trim():"";if(e&&f)return{sourcePath:e,resolvedName:f}}catch(a){console.error("Failed to resolve component source path:",a)}return null},[a,d]),bZ=(0,c.useCallback)(async()=>{if(L&&!bd.current){bd.current=!0,bc(!0);try{let a=await i(L);a.success?(ba(a.branches??[]),a8(a.baseBranch?.trim()||"")):a.error&&aO(`Failed to load branches: ${a.error}`)}catch(a){console.error("Failed to load base branches:",a)}finally{bd.current=!1,bc(!1)}}},[L]);(0,c.useEffect)(()=>{L&&bZ()},[bZ,L]);let b$=(0,c.useCallback)(async()=>{if(L)try{let a=await g(L);a.success&&"number"==typeof a.ahead&&"number"==typeof a.behind&&bh({ahead:a.ahead,behind:a.behind})}catch(a){console.error("Failed to load branch divergence:",a)}},[L]);(0,c.useEffect)(()=>{if(!L||!a7)return void bh({ahead:0,behind:0});b$();let a=window.setInterval(()=>{b$()},6e4);return()=>window.clearInterval(a)},[a7,b$,L]);let b_=(0,c.useCallback)(async()=>{if(L)try{let a=await h(L);a.success&&"number"==typeof a.count&&bj(a.count)}catch(a){console.error("Failed to load uncommitted file count:",a)}},[L]);(0,c.useEffect)(()=>{if(!L)return;b_();let a=window.setInterval(()=>{b_()},1e4);return()=>window.clearInterval(a)},[b_,L]);let b0=async()=>{if(!L||!a7)return!1;a$(!0),aO("Merging session branch...");try{let a=await j(L);if(a.success)return aO(`Merged ${a.branchName} into ${a.baseBranch}`),b$(),!0;return aO(`Merge failed: ${a.error}`),!1}catch(a){return console.error("Merge request failed:",a),aO("Merge failed"),!1}finally{a$(!1)}},b1=async()=>{await b0()},[b2,b3]=(0,c.useState)(!1),b4=(0,c.useRef)(null);(0,c.useEffect)(()=>{let a=a=>{b4.current&&!b4.current.contains(a.target)&&b3(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]);let b5=async a=>{if(b3(!1),!L)return;let b=a!==a7;a0(!0),aO(b?`Updating base to ${a} and rebasing...`:"Rebasing session branch...");try{if(b){let b=await l(L,a);if(!b.success){aO(`Failed to update base branch: ${b.error}`),a0(!1);return}a8(b.baseBranch),await bZ()}let c=await k(L);c.success?(aO(`Rebased ${c.branchName} onto ${c.baseBranch}`),b$()):aO(`Rebase failed: ${c.error}`)}catch(a){console.error("Rebase request failed:",a),aO("Rebase failed")}finally{a0(!1)}},b6=(0,c.useCallback)(async(a,b)=>{let c=ab(a);if(!c)return aO("Please enter a preview URL"),!1;bn(c),br(!1),aO(`Loading preview: ${c}`);try{let a=await fetch("/api/preview-proxy/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:c})}),d=await a.json().catch(()=>null);if(!a.ok||!d?.proxyUrl)throw Error(d?.error||"Failed to start preview proxy");return bp(d.proxyUrl),b&&bl(!0),aO(`Loaded preview: ${c}`),!0}catch(b){let a=b instanceof Error?b.message:"Failed to load preview";return console.error("Failed to load preview via proxy:",b),aO(`Failed to load preview: ${a}`),!1}},[]),b7=(0,c.useCallback)(()=>{if(!bo)return void aO("Load a preview before picking elements");let a=ao.current?.contentWindow;if(!a)return void aO("Preview is not ready yet");let b=!bq;a.postMessage({type:"viba:preview-picker-toggle",active:b},"*"),br(b),aO(b?"Picker enabled: click an element in the preview":"Picker disabled")},[bq,bo]),b8=(0,c.useCallback)(a=>{let b=ao.current?.contentWindow;return b?(b.postMessage(a,"*"),!0):(aO("Preview is not ready yet"),!1)},[]),b9=(0,c.useCallback)(a=>{bo?b8({type:"viba:preview-navigation",action:a})&&"reload"===a&&aO("Reloading preview..."):aO("Load a preview before using navigation controls")},[b8,bo]),ca=(0,c.useCallback)(()=>{b8({type:"viba:preview-location-request"})},[b8]),{attachTerminalLinkHandler:cb}=function({onLoadPreview:a}){let b=(0,c.useCallback)((b,c)=>{let d=ab(b);return!!d&&("new_tab"===c?window.open(d,"_blank","noopener,noreferrer"):a(d,!0),!0)},[a]),d=(0,c.useCallback)((a,c,d)=>{c.current?.();let e=a.contentWindow,f=e?.term;if(!e||!f)return;let g=d?.onLinkActivated,h=d?.directOpenBehavior??"preview",i=d?.modifierOpenBehavior??"new_tab",j=a=>a?i:h,k=[],l=a.contentDocument,m={metaKey:!1,ctrlKey:!1,at:0};if(l){let a=a=>{m={metaKey:a.metaKey,ctrlKey:a.ctrlKey,at:Date.now()}};l.addEventListener("mousedown",a,!0),l.addEventListener("click",a,!0),k.push(()=>{l.removeEventListener("mousedown",a,!0),l.removeEventListener("click",a,!0)})}let n=e.open.bind(e);e.open=(...a)=>{let c=j(Date.now()-m.at<1e3&&(m.metaKey||m.ctrlKey));if("string"==typeof a[0]&&a[0].trim())return(g?.(),b(a[0],c))?null:n(...a);if(0===a.length){let a=null;return{opener:null,location:{set href(url){if(g?.(),!b(url,c)&&(a=n())){try{a.opener=null}catch{}a.location.href=url}},get href(){return""}}}}return n(...a)},k.push(()=>{e.open=n});let o=f._core?._linkProviderService?.linkProviders;if(o instanceof Map){for(let a of o.values())if(a&&"object"==typeof a){if("function"==typeof a._handler){let c=a._handler;a._handler=(a,d)=>{g?.(),b(d,j(!!(a?.metaKey||a?.ctrlKey)))||c(a,d)},k.push(()=>{a._handler=c})}if("function"==typeof a.provideLinks){let c=a.provideLinks.bind(a);a.provideLinks=(a,d)=>{c(a,a=>{if(Array.isArray(a))for(let c of a){if(!c||"object"!=typeof c||"function"!=typeof c.activate)continue;let a=c.activate.bind(c);c.activate=(c,d)=>{g?.(),b(d,j(!!(c?.metaKey||c?.ctrlKey)))||a(c,d)}}d(a)})},k.push(()=>{a.provideLinks=c})}}}let p=f.options.linkHandler,q={allowNonHttpProtocols:p?.allowNonHttpProtocols??!1,activate:(a,c,d)=>{g?.(),b(c,j(!!(a?.metaKey||a?.ctrlKey)))||p?.activate?.(a,c,d)},hover:(a,b,c)=>{p?.hover?.(a,b,c)},leave:(a,b,c)=>{p?.leave?.(a,b,c)}};f.options.linkHandler=q,k.push(()=>{f.options.linkHandler=p??null}),c.current=()=>{for(let a of k)a();c.current=null}},[b]);return{handleTerminalLinkOpen:b,attachTerminalLinkHandler:d}}({onLoadPreview:b6});if((0,c.useEffect)(()=>{if(!bk||bm.trim())return;let a=window.setTimeout(()=>{ap.current?.focus()},0);return()=>{window.clearTimeout(a)}},[bk,bm]),(0,c.useEffect)(()=>{let b=b=>{if(!ao.current||b.source!==ao.current.contentWindow)return;let c=b.data;if(c&&"object"==typeof c){if("viba:preview-picker-state"===c.type)return void br(!!c.active);if("viba:preview-picker-ready"===c.type){let a=ao.current?.contentWindow;a&&a.postMessage({type:"viba:preview-location-request"},"*");return}if("viba:preview-link-open"===c.type){"string"==typeof c.url&&c.url.trim().length>0&&window.open(c.url,"_blank","noopener,noreferrer");return}if("viba:preview-location-change"===c.type){"string"==typeof c.url&&c.url.trim().length>0&&bn(c.url);return}if("viba:preview-element-selected"===c.type){let b=c.element&&"object"==typeof c.element?c.element:null,e=Array.isArray(b?.reactComponentStack)?b.reactComponentStack:[],f=((a,b)=>{for(let c of a){if(!c||"object"!=typeof c)continue;let a="string"==typeof c.name?c.name.trim():"";if(!a)continue;let d="string"==typeof c.source?.fileName?c.source.fileName.trim():"",e=d?aj(d,b):null;if(e)return`${a} (${e})`}return null})(e,d||a),g=e[0]&&"object"==typeof e[0]?e[0].name:void 0,h="string"==typeof g&&g.trim().length>0?g.trim():"",i=new Set(["Suspense","ErrorBoundary","Router","AppRouter","LayoutRouter","RenderFromTemplateContext","ScrollAndFocusHandler","InnerLayoutRouter","RedirectErrorBoundary","NotFoundBoundary","LoadingBoundary","ReactDevOverlay","HotReload","AppContainer","Route","Link","Image","OuterLayoutRouter","Head","StringRefs","Fragment","Profiler","StrictMode","SuspenseList","Script","Page","__next_root_layout_boundary__"]),j=Array.from(new Set(e.map(a=>{if(!a||"object"!=typeof a)return"";let b=a.name;return"string"==typeof b?b.trim():""}).filter(a=>!(!a||i.has(a)||a.startsWith("styled.")||a.startsWith("Styled(")))));console.log("Filtered stack component names:",j);let k=f||h||("string"==typeof b?.selector?b.selector:"");if(console.log("Preview selected element:",b),console.log("Preview selected reactComponentStack:",e),console.log("Preview selected identifier:",k),br(!1),!k)return void aO("Element selected. No identifier was resolved.");(async()=>{let a=f||"";if(!a&&j.length>0){bt(!0);try{let b=await bY(j);b?.resolvedName&&b?.sourcePath&&(a=`${b.resolvedName} (${b.sourcePath})`)}finally{bt(!1)}}if(!a){if(j.length>0)return aO("Element selected, but source file path could not be resolved for the component");a=k}console.log("Final resolved component identifier:",a),aO(await bW(`${a} `)?`Element identifier sent to agent: ${a}`:"Element selected, but failed to send identifier to agent input")})()}}};return window.addEventListener("message",b),()=>{window.removeEventListener("message",b)}},[bW,a,bY,d]),(0,c.useEffect)(()=>{br(!1)},[bo]),!a)return(0,b.jsx)("div",{className:"p-4 text-error",children:"No repository specified"});if("error"===aP)return(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsx)("div",{className:"card w-96 bg-base-200 shadow-xl",children:(0,b.jsxs)("div",{className:"card-body items-center text-center",children:[(0,b.jsx)("h2",{className:"card-title text-error",children:"Cleanup failed"}),(0,b.jsx)("p",{children:aR||"An unknown error occurred while cleaning up this session."}),(0,b.jsx)("div",{className:"card-actions justify-end",children:(0,b.jsx)("button",{className:"btn btn-primary",onClick:()=>U(),children:"Back to Home"})})]})})});let cc=Array.from(new Set([...a7?[a7]:[],...a9])).filter(a=>a!==e||a===a7),cd=by?`calc(40px - min(${bA.width}px, calc(100vw - 2rem)))`:16,ce=!!P?.trim();return(0,b.jsxs)("div",{className:`flex flex-col h-screen w-full overflow-hidden bg-base-100 ${bC||bw?"select-none":""}`,children:[(bC||bw)&&(0,b.jsx)("div",{className:`fixed inset-0 z-[9999] ${bC?"cursor-nwse-resize":"cursor-col-resize"}`}),(0,b.jsxs)("div",{className:"z-20 bg-base-300/95 p-2 text-xs flex justify-between px-4 font-mono select-none items-center shadow-md backdrop-blur-sm border-b border-base-content/10",children:[(0,b.jsxs)("div",{className:"flex items-center gap-4",children:[(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-6 min-h-6 px-1 hover:bg-base-content/10",onClick:()=>U(),title:"Back to Home",children:(0,b.jsx)(C,{className:"w-4 h-4"})}),(0,b.jsxs)("div",{className:"flex flex-col",children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{className:"opacity-50",children:"Repo:"}),(0,b.jsx)("span",{className:"font-bold",children:(0,X.getBaseName)(a)})]}),L&&(0,b.jsxs)("div",{className:"hidden min-[1200px]:flex min-w-0 items-center gap-2 text-[10px] opacity-70",children:[(0,b.jsx)("span",{children:"Session:"}),(0,b.jsx)("span",{className:"truncate max-w-[220px]",title:L,children:L})]})]})]}),(0,b.jsxs)("div",{className:"flex items-center gap-4",children:[(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden",children:[(0,b.jsx)("select",{className:"select select-xs h-6 min-h-6 bg-base-200 border-none focus:outline-none rounded-none pr-7",value:bM,onChange:bO,children:ad.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name},a.id))}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/20"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none hover:bg-base-content/10",onClick:()=>{if(!d)return;let a=ad.find(a=>a.id===bM);if(!a)return;let b=`${a.protocol}://file/${encodeURI(d)}`;window.open(b,"_blank")},title:`Open in ${ad.find(a=>a.id===bM)?.name}`,children:[(0,b.jsx)(s.ExternalLink,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Open"})]})]}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{if(!d||!e)return;let a=new URLSearchParams({path:d,branch:e});window.open(`http://localhost:3100/workspace?${a.toString()}`,"_blank","noopener,noreferrer")},disabled:!d||!e,title:"Open this worktree and branch in Trident",children:[(0,b.jsx)(y.GitBranch,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Diff"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:bV,disabled:aX,title:"Ask agent to create a commit with current changes",children:[aX?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(v,{className:"w-3 h-3"}),(0,b.jsxs)("span",{className:al,children:["Commit (",bi,")"]})]})]}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>a2(!0),disabled:a5,title:"Browse files and insert absolute paths into the agent input",children:[a5?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(B,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Add Files"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{if(!a||!L)return;let b=`/new?repo=${encodeURIComponent(a)}&prefillFromSession=${encodeURIComponent(L)}`;window.open(b,"_blank","noopener,noreferrer")},title:"Start a new attempt in a new tab with this session context",children:[(0,b.jsx)(F.Plus,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"New Attempt"})]})]}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{let a=P?.trim();if(!a||!an.current||aV)return;bz(!1);let b=an.current;aU(!0),aO("Starting dev server...");let c=(d=0)=>{if(d>30){aO("Failed to start dev server: terminal is not ready"),aU(!1);return}try{let e=b.contentWindow;if(e&&e.term){e.term.paste(a);let c=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");c?c.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:e})):e.term.paste("\r"),e.focus(),c&&c.focus(),aO("Dev server start command sent"),aU(!1)}else setTimeout(()=>c(d+1),300)}catch(a){console.error("Dev server injection error",a),aO("Failed to start dev server"),aU(!1)}};c()},disabled:!ce||aT||aV,title:ce?aV?"A process is already running in the terminal":"Run dev server script in terminal":"Set a dev server script to enable this button",children:[aT?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(t.Play,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Dev"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>bl(a=>!a),title:bk?"Hide preview panel":"Show preview panel",children:[(0,b.jsx)(G,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:bk?"Close":"Preview"})]})]}),(0,b.jsx)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:(0,b.jsxs)("button",{className:`btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10 ${"select"===bH?"text-warning":""}`,onClick:bR,disabled:"tmux"!==W||bJ,title:"tmux"===W?"scroll"===bH?"Switch to text select mode for easier copy":"Switch to scroll mode for wheel scrollback":"Mode toggle is available only in tmux persistence mode",children:[bJ?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(H,{className:"w-3 h-3"}),(0,b.jsx)("span",{children:"scroll"===bH?"Scroll Mode":"Text Select"})]})}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded relative bg-base-100",ref:b4,children:[(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none rounded-l h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{b3(!b2)},disabled:a_||aZ||be,title:"Select base branch and rebase",children:[a_?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(x,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Rebase"}),(0,b.jsx)(E,{className:"w-3 h-3 opacity-50 ml-0.5"})]}),b2&&(0,b.jsxs)("div",{className:"absolute top-full left-0 z-50 mt-1 w-64 p-0 shadow-xl dropdown-content bg-base-200 rounded-box border border-base-content/20 flex flex-col max-h-80 overflow-hidden",children:[(0,b.jsxs)("div",{className:"px-4 py-2 text-[10px] uppercase font-bold tracking-wider opacity-50 border-b border-base-content/10 bg-base-200 flex justify-between items-center shrink-0",children:[(0,b.jsx)("span",{children:"Select Base Branch"}),(bb||be)&&(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"})]}),(0,b.jsxs)("ul",{className:"menu p-0 overflow-y-auto flex-nowrap custom-scrollbar overflow-x-hidden w-full",children:[cc.length>0?cc.map(a=>(0,b.jsx)("li",{children:(0,b.jsxs)("button",{onClick:()=>b5(a),className:`flex justify-between items-center text-xs py-2 truncate max-w-full rounded-none ${a===a7?"active font-bold":""}`,title:a,children:[(0,b.jsx)("span",{className:"truncate",children:a}),a===a7&&(0,b.jsx)("span",{className:"opacity-70 text-[10px] ml-2 shrink-0",children:"(Current)"})]})},a)):(0,b.jsx)("li",{className:"text-xs px-4 py-2 opacity-50 italic text-center",children:"No other branches found"}),(0,b.jsx)("div",{className:"divider my-1 opacity-50"}),(0,b.jsx)("li",{children:(0,b.jsx)("button",{onClick:()=>void bZ(),className:"text-[10px] justify-center opacity-70 hover:opacity-100",children:"Refresh Branches"})})]})]})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs btn-success rounded-none h-6 min-h-6 border-none px-2 hover:bg-success/20 hover:border-transparent",onClick:b1,disabled:aZ||a_||be||!a7,title:a7?`Merge current branch (${e}) into target branch (${a7})`:"Target branch unavailable for this session",children:[aZ?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(w,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Merge"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-error btn-xs rounded-none rounded-r h-6 min-h-6 border-none px-2 hover:bg-error/20 hover:border-transparent",onClick:bT,disabled:aZ||a_||!d,title:"Clean up and exit",children:[(0,b.jsx)(r.Trash2,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:al,children:"Purge"})]})]}),a7&&(0,b.jsxs)("div",{className:"flex items-center gap-2 text-xs opacity-80",title:`Divergence against ${a7}`,children:[(0,b.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,b.jsx)(z,{className:"w-3 h-3"}),bg.ahead]}),(0,b.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,b.jsx)(A,{className:"w-3 h-3"}),bg.behind]})]}),(0,b.jsx)("div",{className:"hidden min-[1200px]:block w-[1px] h-4 bg-base-content/20 mx-2"}),(0,b.jsxs)("div",{className:"hidden min-[1200px]:flex min-w-0 max-w-[280px] items-center gap-2",children:[(0,b.jsx)("span",{className:`w-2 h-2 rounded-full ${aN.includes("Error")||aN.includes("failed")?"bg-error":aN.includes("started")||aN.includes("Merged")||aN.includes("Rebased")||aN.includes("sent")?"bg-success":"bg-warning"}`}),(0,b.jsx)("span",{className:"truncate",title:aN,children:aN})]})]})]}),(0,b.jsxs)("div",{ref:aq,className:"flex min-h-0 flex-1 w-full",children:[(0,b.jsx)("div",{className:"h-full min-w-0",style:{width:bk?`${100*bu}%`:"100%"},children:(0,b.jsx)("iframe",{ref:am,src:aw,className:`h-full w-full border-none dark:invert dark:brightness-90 ${bC||bw?"pointer-events-none":""}`,allow:"clipboard-read; clipboard-write",onLoad:()=>{if(!am.current)return;let b=am.current;try{b.contentWindow}catch(a){aO("Error: Cross-Origin access blocked. Ensure proxy is working.");return}b.contentWindow&&(b.contentWindow.onbeforeunload=null,b.contentWindow.addEventListener("beforeunload",a=>{a.stopImmediatePropagation()},!0)),aO("Connecting to terminal...");let c=(e=0)=>{if(e>30)return void aO("Timeout waiting for terminal to be ready");try{let f=b.contentWindow;if(f&&f.term){bQ("agent");let g=f.term;cb(b,as,{directOpenBehavior:"new_tab",modifierOpenBehavior:"new_tab"});try{g.options.theme={...g.options.theme||{},selectionBackground:"rgba(59, 130, 246, 0.4)"}}catch{}let h=aF("agent"),i=!!V&&"tmux"===W;if(h||i){i&&!h?(aI("agent"),aO("Attached to persisted terminal")):aO("Reconnected to terminal"),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}if(!aJ(g)&&e<10)return void setTimeout(()=>c(e+1),200);if(!aG("agent")){aO("Reconnected to terminal"),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}let j=d||a,k=`cd ${ac(j)}`;g.paste(k);let l=()=>{let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a?a.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:f})):g.paste("\r")};if(l(),aI("agent"),M){let b=async()=>{let b="";if(V)b=M.toLowerCase().includes("gemini")?"gemini --resume latest --yolo":M.toLowerCase().includes("codex")?"codex resume --last --sandbox danger-full-access --ask-for-approval on-request --search":"agent"===M.toLowerCase()||M.toLowerCase().includes("cursor")?"agent resume":`${ac(M)} resume`;else{let c=S?.trim()||"",e=Q?.trim()||"",f=[];c&&f.push(c),e&&f.push(e);let g=f.join("\n\n"),h=(R||[]).map(a=>a.trim()).filter(Boolean).map(b=>`${d||a}-attachments/${b}`),i=[];g&&i.push(g),h.length>0&&i.push(["Attachments:",...h.map(a=>`- ${a}`)].join("\n"));let j=i.join("\n\n"),k="";if(j){let a=[];"plan"===T&&a.push("Plan mode: inspect the relevant code first, present a concrete implementation plan, and wait for explicit user approval before any file edits or write commands."),a.push("After each round, if work is complete and files changed, commit all changes without confirmation. Use a commit message with a clear title and a detailed body explaining what changed and why. If GITHUB_TOKEN or GITLAB_TOKEN is set, push the current branch after committed rounds and create (or update) a pull/merge request with an appropriate title and description; include the pull/merge request link in the first push reply."),a.push("For visual web tasks, use the `agent-browser` skill (https://skills.sh/vercel-labs/agent-browser/agent-browser)."),a.push("For bugfix/debugging tasks, use the `systematic-debugging` skill (https://github.com/obra/superpowers)."),a.push("When working on a visual-related feature or bugfix in a web project, after coding is complete, use `agent-browser` or equivalent Chrome MCP tooling to load the relevant page, take screenshot(s), and include them as evidence in the pull/merge request."),a.push("When your task is completed or you need user attention (for plan approval, permissions, or blockers), send a notification to the matching Viba session.");let b=`${window.location.origin}/api/notifications`;a.push(`Notification API endpoint: ${b} (POST JSON with sessionId, title, and description).`),a.push(`Notification payload template: {"sessionId":"${L}","title":"<short title>","description":"<clear detail about completion or required attention>"}.`);let c=["# Instructions\n",a.map(a=>`- ${a}`).join("\n"),"\n# Task\n",j].join("\n");try{let a=await m(L,c);a.success&&a.filePath?k=` "$(cat ${ac(a.filePath)})"`:(console.error("Failed to write prompt file, falling back to inline prompt",a.error),k=` ${ac(c)}`)}catch(a){console.error("Exception writing prompt file",a),k=` ${ac(c)}`}}let l=N&&"auto"!==N.toLowerCase()?` --model ${ac(N)}`:"";b=M.toLowerCase().includes("codex")?`codex${l} --sandbox danger-full-access --ask-for-approval on-request --search${k}`:M.toLowerCase().includes("gemini")?`gemini${l} --yolo${k}`:"agent"===M.toLowerCase()||M.toLowerCase().includes("cursor")?`agent${l}${k}`:`${ac(M)}${l}${k}`}b&&(g.paste(b),l(),aO(V?`Resumed session with ${M}`:`Session started with ${M}`),!V&&Y&&Y())};setTimeout(()=>b(),500)}else aO(`Session started ${d?"(Worktree)":""}`),!V&&Y&&Y();f.focus();let n=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");n&&n.focus()}else setTimeout(()=>c(e+1),500)}catch(a){aH("agent"),console.error("Access error during injection:",a),aO("Error accessing terminal: "+String(a))}};setTimeout(()=>c(),1e3)}})}),bk&&(0,b.jsxs)(b.Fragment,{children:[(0,b.jsx)("div",{className:"relative h-full w-2 shrink-0 cursor-col-resize bg-base-300/40 hover:bg-base-content/20",onMouseDown:a=>{a.preventDefault(),bx(!0),ar.current={startX:a.clientX,startRatio:bu}},role:"separator","aria-orientation":"vertical","aria-label":"Resize preview panel",title:"Drag to resize preview panel",children:(0,b.jsx)("div",{className:"absolute left-1/2 top-1/2 h-12 w-[2px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-base-content/30"})}),(0,b.jsxs)("div",{className:"flex h-full min-w-0 flex-1 flex-col border-l border-base-content/10 bg-base-200/50",children:[(0,b.jsxs)("form",{className:"flex items-center gap-2 border-b border-base-content/10 bg-base-200 px-3 py-2",onSubmit:a=>{a.preventDefault(),b6(bm,!0)},children:[(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0",type:"button",onClick:()=>b9("back"),disabled:!bo,title:"Go back","aria-label":"Go back",children:(0,b.jsx)(I.ArrowLeft,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0",type:"button",onClick:()=>b9("forward"),disabled:!bo,title:"Go forward","aria-label":"Go forward",children:(0,b.jsx)(J,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0",type:"button",onClick:()=>b9("reload"),disabled:!bo,title:"Reload preview","aria-label":"Reload preview",children:(0,b.jsx)(K,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("input",{ref:ap,type:"text",className:"input input-xs input-bordered w-full font-mono",value:bm,onChange:a=>bn(a.target.value),placeholder:"http://127.0.0.1:3000",spellCheck:!1}),(0,b.jsx)("button",{className:`btn btn-ghost btn-xs ${bq?"btn-active text-success":""}`,type:"button",onClick:b7,disabled:!bo||bs,title:bq?"Disable picker":"Pick element from preview",children:bs?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs w-3 h-3"}):(0,b.jsx)(H,{className:"h-3 w-3"})}),(0,b.jsx)("button",{className:"btn btn-xs",type:"submit",children:"Go"})]}),(0,b.jsx)("div",{className:"min-h-0 flex-1",children:bo?(0,b.jsx)("iframe",{ref:ao,src:bo,className:`h-full w-full border-none ${bC||bw?"pointer-events-none":""}`,title:"Dev server preview",onLoad:ca,sandbox:"allow-forms allow-modals allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-downloads"}):(0,b.jsx)("div",{className:"flex h-full items-center justify-center px-6 text-center text-xs opacity-70",children:"Run the dev server, or enter a URL above to load a preview."})})]})]})]}),(0,b.jsxs)("div",{className:`absolute z-30 overflow-hidden rounded-lg border border-base-content/20 bg-base-200/95 shadow-2xl backdrop-blur-sm ${bC||bw?"":"transition-all"}`,style:{bottom:80,right:cd,width:bA.width,height:by?40:bA.height,maxWidth:"calc(100vw - 2rem)",maxHeight:"calc(100vh - 2rem)"},children:[(0,b.jsx)("button",{className:`absolute left-0 top-0 z-50 flex h-10 w-10 items-center justify-center text-base-content/30 hover:text-base-content/60 ${by?"cursor-pointer":"cursor-nwse-resize"}`,onMouseDown:by?void 0:a=>{a.preventDefault(),a.stopPropagation(),bD(!0),bG.current={startX:a.clientX,startY:a.clientY,startWidth:bA.width,startHeight:bA.height}},onClick:by?()=>bz(!1):void 0,title:by?"Expand terminal":"Drag to resize",type:"button",children:(0,b.jsx)(D,{size:14})}),!by&&(0,b.jsxs)("button",{className:"flex h-10 w-full items-center justify-between px-3 pl-10 text-xs font-mono hover:bg-base-content/10",onClick:()=>bz(a=>!a),title:"Minimize terminal",type:"button",children:[(0,b.jsx)("span",{children:"Terminal"}),(0,b.jsx)("span",{className:"opacity-70",children:"Hide"})]}),(0,b.jsx)("div",{className:by?"h-0 overflow-hidden":"h-[calc(100%-2.5rem)]",children:(0,b.jsx)("iframe",{ref:an,src:ax,className:`h-full w-full border-none dark:invert dark:brightness-90 ${bC||bw?"pointer-events-none":""}`,allow:"clipboard-read; clipboard-write",onLoad:()=>{if(!an.current)return;let b=an.current;aK(),aW(!1);try{b.contentWindow}catch(a){console.error("Secondary terminal: Cross-Origin access blocked.");return}b.contentWindow&&(b.contentWindow.onbeforeunload=null,b.contentWindow.addEventListener("beforeunload",a=>{a.stopImmediatePropagation()},!0));let c=(e=0)=>{if(!(e>30))try{let f=b.contentWindow;if(f&&f.term){let g;bQ("terminal");let h=f.term;cb(b,at,{onLinkActivated:()=>bz(!0),directOpenBehavior:"preview",modifierOpenBehavior:"new_tab"});try{h.options.theme={...h.options.theme||{},selectionBackground:"rgba(59, 130, 246, 0.4)"}}catch{}aL(b,h);try{let a=()=>{let a=h.buffer?.active,b="number"==typeof a?.baseY?a.baseY:0;"number"==typeof a?.viewportY&&a.viewportY,h.scrollToBottom?.()};if("function"==typeof h.onWriteParsed)h.onWriteParsed(a);else{let c=b.contentDocument?.querySelector(".xterm-screen")||b.contentDocument?.body;c&&new MutationObserver(a).observe(c,{childList:!0,subtree:!0,characterData:!0})}}catch(a){console.error("Failed to setup auto-scroll:",a)}let i=aF("terminal"),j=!!V&&"tmux"===W;if(i||j){j&&!i&&aI("terminal"),i&&aM(b,f,h),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}if(!aJ(h)&&e<10)return void setTimeout(()=>c(e+1),200);if(!aG("terminal")){f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}let k=d||a,l=`cd ${ac(k)}`;h.paste(l),(g=b.contentDocument?.querySelector("textarea.xterm-helper-textarea"))?g.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:f})):h.paste("\r"),aI("terminal"),aM(b,f,h),f.focus();let m=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");m&&m.focus()}else setTimeout(()=>c(e+1),500)}catch(a){aW(!1),aH("terminal"),console.error("Secondary terminal injection error",a)}};setTimeout(()=>c(),1e3)}})})]}),a1&&(0,b.jsx)($,{initialPath:a3,worktreePath:d,onPathChange:a4,onConfirm:a=>{a2(!1),bX(a)},onCancel:()=>a2(!1)})]})}let am=(0,e.createServerReference)("40693a37d941acd8c28ea7fe2422a4e992fee2650d",e.callServer,void 0,e.findSourceMapURL,"consumeSessionLaunchContext"),an=(0,e.createServerReference)("40a5ef3ed6efb247c0d946def860ff5d0c8671e53d",e.callServer,void 0,e.findSourceMapURL,"getSessionMetadata"),ao=(0,e.createServerReference)("40c4ee317b8ff77232e272da27074ee11600bdf45e",e.callServer,void 0,e.findSourceMapURL,"markSessionInitialized"),ap=(0,e.createServerReference)("7ff088d31118453ba6c20b0502d2f42063fe338f22",e.callServer,void 0,e.findSourceMapURL,"getSessionTerminalSources");var aq=a.i(88930);function ar(){let a=(0,d.useParams)().sessionId,e=Array.isArray(a)?a[0]:a,f=(0,d.useRouter)(),[g,h]=(0,c.useState)(null),[i,j]=(0,c.useState)(!0),[k,l]=(0,c.useState)(null),[m,n]=(0,c.useState)(null),[o,p]=(0,c.useState)(void 0),[q,r]=(0,c.useState)(void 0),[s,t]=(0,c.useState)(void 0),[u,v]=(0,c.useState)(void 0),[w,x]=(0,c.useState)(void 0),[y,z]=(0,c.useState)(void 0),[A,B]=(0,c.useState)([]),[C,D]=(0,c.useState)(!0),[E,F]=(0,c.useState)("shell"),G=(0,c.useCallback)(()=>{if(!e)return;window.focus();let a=`/session/${e}`;window.location.pathname!==a&&f.push(a)},[f,e]);(0,c.useEffect)(()=>(document.documentElement.classList.add("session-page"),()=>{document.documentElement.classList.remove("session-page")}),[]),(0,c.useEffect)(()=>{if(!e)return;let a=!1,b=null,c=null,d=0,f=null,g=()=>{null!==c&&(window.clearTimeout(c),c=null)},h=()=>{if(a)return;let b=Math.min(1e4,1e3*2**d);d+=1,c=window.setTimeout(()=>{c=null,j()},b)},i=async a=>{if(!("Notification"in window))return;let b=Notification.permission;"default"===b&&(b=await Notification.requestPermission()),"granted"===b&&(f&&f.close(),(f=new Notification(a.title,{body:a.description,tag:`viba-session-notification-${a.sessionId}`})).onclick=a=>{a.preventDefault(),G(),f?.close()})},j=async()=>{try{let c=await fetch(`/api/notifications/socket?sessionId=${encodeURIComponent(e)}`,{cache:"no-store"});if(!c.ok)throw Error("Failed to initialize notification socket");let f=await c.json();if(!f.wsUrl)throw Error("Notification socket URL missing");if(a)return;(b=new WebSocket(f.wsUrl)).onopen=()=>{d=0,g()},b.onerror=()=>{b?.close()},b.onclose=()=>{a||h()},b.onmessage=a=>{try{let b=JSON.parse(a.data);if("session-notification"!==b.type||b.sessionId!==e||"string"!=typeof b.title||!b.title.trim()||"string"!=typeof b.description||!b.description.trim()||"string"!=typeof b.timestamp)return;i(b)}catch{}}}catch{h()}};return j(),()=>{a=!0,g(),b?.close(),f?.close()}},[G,e]),(0,c.useEffect)(()=>{e&&(async()=>{try{n(null);let a=await (0,aq.startTtydProcess)();if(!a.success){l("Failed to start terminal service"),j(!1);return}F("tmux"===a.persistenceMode?"tmux":"shell");let b=await an(e);if(!b){l("Session not found"),j(!1);return}h(b);let c=await ap(b.sessionName,b.repoPath);if(n(c),!1===b.initialized){let a=await am(e);if(a.success&&a.context){let b=a.context;p(b.initialMessage),r(b.startupScript),t(b.title),v(b.agentProvider),x(b.model),z(b.sessionMode),B(b.attachmentNames||[])}D(!1)}else D(!0);j(!1)}catch(a){console.error("Failed to load session:",a),l("Failed to load session"),j(!1)}})()},[e]);let H=a=>{a?window.location.href="/":f.push("/")},I=async()=>{e&&await ao(e)};return i?(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,b.jsx)("span",{className:"loading loading-spinner loading-lg text-primary"}),(0,b.jsx)("p",{className:"opacity-60",children:"Loading session..."})]})}):k||!g?(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsx)("div",{className:"card w-96 bg-base-200 shadow-xl",children:(0,b.jsxs)("div",{className:"card-body items-center text-center",children:[(0,b.jsx)("h2",{className:"card-title text-error",children:"Error"}),(0,b.jsx)("p",{children:k||"Session not found"}),(0,b.jsx)("div",{className:"card-actions justify-end",children:(0,b.jsx)("button",{className:"btn btn-primary",onClick:()=>H(),children:"Back to Home"})})]})})}):m?(0,b.jsx)(al,{repo:g.repoPath,worktree:g.worktreePath,branch:g.branchName,baseBranch:g.baseBranch,sessionName:g.sessionName,agent:u||g.agent,model:w||g.model,startupScript:q,devServerScript:g.devServerScript,initialMessage:o,attachmentNames:A,title:s||g.title,sessionMode:y,onExit:H,isResume:C,terminalPersistenceMode:E,onSessionStart:I,agentTerminalSrc:m.agentTerminalSrc,floatingTerminalSrc:m.floatingTerminalSrc}):(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,b.jsx)("span",{className:"loading loading-spinner loading-lg text-primary"}),(0,b.jsx)("p",{className:"opacity-60",children:"Initializing terminals..."})]})})}a.s(["default",()=>ar],96614)}];
1
+ module.exports=[96614,a=>{"use strict";var b=a.i(87924),c=a.i(72131),d=a.i(50944),e=a.i(5050);let f=(0,e.createServerReference)("40472a7b7ef1f049da2e8bd7fe83576d75fc359855",e.callServer,void 0,e.findSourceMapURL,"deleteSessionInBackground"),g=(0,e.createServerReference)("40058a5dd4fe0110bbed3fe41e7d2f95d732e6c6eb",e.callServer,void 0,e.findSourceMapURL,"getSessionDivergence"),h=(0,e.createServerReference)("4000548b94d7eb0c010216c3229a9728e284cca1c7",e.callServer,void 0,e.findSourceMapURL,"listSessionBaseBranches"),i=(0,e.createServerReference)("407c06ba83e9ef484dc4dd40665a49ea2ee8af524d",e.callServer,void 0,e.findSourceMapURL,"mergeSessionToBase"),j=(0,e.createServerReference)("400725f1148051cfbf3fced2d6edb3e71fc6698ac5",e.callServer,void 0,e.findSourceMapURL,"rebaseSessionOntoBase"),k=(0,e.createServerReference)("60faa89b05bb9d2642d6dd0b69949374dbc5bf34d0",e.callServer,void 0,e.findSourceMapURL,"updateSessionBaseBranch"),l=(0,e.createServerReference)("60ab993de76937b521b9e4a1da2df42d7febf2d6cb",e.callServer,void 0,e.findSourceMapURL,"writeSessionPromptFile"),m=(0,e.createServerReference)("7f4410d0ba93f2b65802d482afaaf91802f0dd3385",e.callServer,void 0,e.findSourceMapURL,"setTmuxSessionMouseMode"),n=(0,e.createServerReference)("7f4ddcb7d9b3ef649b59c253b202e1d55eeb96567b",e.callServer,void 0,e.findSourceMapURL,"setTmuxSessionStatusVisibility");var o=a.i(97543),p=a.i(73881),q=a.i(81560),r=a.i(52495),s=a.i(70106);let t=(0,s.default)("play",[["path",{d:"M5 5a2 2 0 0 1 3.008-1.728l11.997 6.998a2 2 0 0 1 .003 3.458l-12 7A2 2 0 0 1 5 19z",key:"10ikf1"}]]),u=(0,s.default)("git-merge",[["circle",{cx:"18",cy:"18",r:"3",key:"1xkwt0"}],["circle",{cx:"6",cy:"6",r:"3",key:"1lh9wr"}],["path",{d:"M6 21V9a9 9 0 0 0 9 9",key:"7kw0sc"}]]),v=(0,s.default)("git-pull-request-arrow",[["circle",{cx:"5",cy:"6",r:"3",key:"1qnov2"}],["path",{d:"M5 9v12",key:"ih889a"}],["circle",{cx:"19",cy:"18",r:"3",key:"1qljk2"}],["path",{d:"m15 9-3-3 3-3",key:"1lwv8l"}],["path",{d:"M12 6h5a2 2 0 0 1 2 2v7",key:"1yj91y"}]]),w=(0,s.default)("git-branch",[["line",{x1:"6",x2:"6",y1:"3",y2:"15",key:"17qcm7"}],["circle",{cx:"18",cy:"6",r:"3",key:"1h7g24"}],["circle",{cx:"6",cy:"18",r:"3",key:"fqmcym"}],["path",{d:"M18 9a9 9 0 0 1-9 9",key:"n2h4wq"}]]),x=(0,s.default)("arrow-up",[["path",{d:"m5 12 7-7 7 7",key:"hav0vg"}],["path",{d:"M12 19V5",key:"x0mq9r"}]]),y=(0,s.default)("arrow-down",[["path",{d:"M12 5v14",key:"s699le"}],["path",{d:"m19 12-7 7-7-7",key:"1idqje"}]]),z=(0,s.default)("folder-open",[["path",{d:"m6 14 1.5-2.9A2 2 0 0 1 9.24 10H20a2 2 0 0 1 1.94 2.5l-1.54 6a2 2 0 0 1-1.95 1.5H4a2 2 0 0 1-2-2V5a2 2 0 0 1 2-2h3.9a2 2 0 0 1 1.69.9l.81 1.2a2 2 0 0 0 1.67.9H18a2 2 0 0 1 2 2v2",key:"usdka0"}]]),A=(0,s.default)("chevron-left",[["path",{d:"m15 18-6-6 6-6",key:"1wnfg3"}]]),B=(0,s.default)("grip",[["circle",{cx:"12",cy:"5",r:"1",key:"gxeob9"}],["circle",{cx:"19",cy:"5",r:"1",key:"w8mnmm"}],["circle",{cx:"5",cy:"5",r:"1",key:"lttvr7"}],["circle",{cx:"12",cy:"12",r:"1",key:"41hilf"}],["circle",{cx:"19",cy:"12",r:"1",key:"1wjl8i"}],["circle",{cx:"5",cy:"12",r:"1",key:"1pcz8c"}],["circle",{cx:"12",cy:"19",r:"1",key:"lyex9k"}],["circle",{cx:"19",cy:"19",r:"1",key:"shf9b7"}],["circle",{cx:"5",cy:"19",r:"1",key:"bfqh0e"}]]);var C=a.i(5784),D=a.i(15618);let E=(0,s.default)("mouse-pointer-2",[["path",{d:"M4.037 4.688a.495.495 0 0 1 .651-.651l16 6.5a.5.5 0 0 1-.063.947l-6.124 1.58a2 2 0 0 0-1.438 1.435l-1.579 6.126a.5.5 0 0 1-.947.063z",key:"edeuup"}]]);var F=a.i(210);let G=(0,s.default)("arrow-right",[["path",{d:"M5 12h14",key:"1ays0h"}],["path",{d:"m12 5 7 7-7 7",key:"xquz4c"}]]),H=(0,s.default)("rotate-cw",[["path",{d:"M21 12a9 9 0 1 1-9-9c2.52 0 4.93 1 6.74 2.74L21 8",key:"1p45f6"}],["path",{d:"M21 3v5h-5",key:"1q7to0"}]]);var I=a.i(71987),J=a.i(75756);let K=(0,e.createServerReference)("406470e196a11de11aee30c1a69a7fe5da3cbc3033",e.callServer,void 0,e.findSourceMapURL,"listPathEntries");var L=a.i(58866);let M=(0,s.default)("clipboard",[["rect",{width:"8",height:"4",x:"8",y:"2",rx:"1",ry:"1",key:"tgr4d6"}],["path",{d:"M16 4h2a2 2 0 0 1 2 2v14a2 2 0 0 1-2 2H6a2 2 0 0 1-2-2V6a2 2 0 0 1 2-2h2",key:"116196"}]]),N=(0,s.default)("file-text",[["path",{d:"M6 22a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h8a2.4 2.4 0 0 1 1.704.706l3.588 3.588A2.4 2.4 0 0 1 20 8v12a2 2 0 0 1-2 2z",key:"1oefj6"}],["path",{d:"M14 2v5a1 1 0 0 0 1 1h5",key:"wfsgrz"}],["path",{d:"M10 9H8",key:"b1mrlr"}],["path",{d:"M16 13H8",key:"t4e002"}],["path",{d:"M16 17H8",key:"z1uh3a"}]]);var O=a.i(92596);let P=(0,s.default)("grid-2x2",[["path",{d:"M12 3v18",key:"108xh3"}],["path",{d:"M3 12h18",key:"1i2n21"}],["rect",{x:"3",y:"3",width:"18",height:"18",rx:"2",key:"h1oib"}]]),Q=(0,s.default)("house",[["path",{d:"M15 21v-8a1 1 0 0 0-1-1h-4a1 1 0 0 0-1 1v8",key:"5wwlr5"}],["path",{d:"M3 10a2 2 0 0 1 .709-1.528l7-6a2 2 0 0 1 2.582 0l7 6A2 2 0 0 1 21 10v9a2 2 0 0 1-2 2H5a2 2 0 0 1-2-2z",key:"r6nss1"}]]),R=(0,s.default)("list",[["path",{d:"M3 5h.01",key:"18ugdj"}],["path",{d:"M3 12h.01",key:"nlz23k"}],["path",{d:"M3 19h.01",key:"noohij"}],["path",{d:"M8 5h13",key:"1pao27"}],["path",{d:"M8 12h13",key:"1za7za"}],["path",{d:"M8 19h13",key:"m83p4d"}]]),S=(0,s.default)("pin",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M9 10.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h12a1 1 0 0 0 1-1v-.76a2 2 0 0 0-1.11-1.79l-1.78-.9A2 2 0 0 1 15 10.76V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H8a2 2 0 0 0 0 4 1 1 0 0 1 1 1z",key:"1nkz8b"}]]),T=(0,s.default)("pin-off",[["path",{d:"M12 17v5",key:"bb1du9"}],["path",{d:"M15 9.34V7a1 1 0 0 1 1-1 2 2 0 0 0 0-4H7.89",key:"znwnzq"}],["path",{d:"m2 2 20 20",key:"1ooewy"}],["path",{d:"M9 9v1.76a2 2 0 0 1-1.11 1.79l-1.78.9A2 2 0 0 0 5 15.24V16a1 1 0 0 0 1 1h11",key:"c9qhm2"}]]);var U=a.i(11431),V=a.i(94659);let W="viba:session-file-browser:view-mode";function X({initialPath:a,worktreePath:d,onConfirm:e,onCancel:f,onPathChange:g}){let h=(0,c.useMemo)(()=>new Set([".png",".jpg",".jpeg",".gif",".webp",".bmp",".svg",".ico",".avif"]),[]),[i,j]=(0,c.useState)(""),[k,l]=(0,c.useState)([]),[m,n]=(0,c.useState)(!1),[q,r]=(0,c.useState)(null),[s,t]=(0,c.useState)(""),[u,v]=(0,c.useState)([]),[w,x]=(0,c.useState)(null),[y,z]=(0,c.useState)("list"),[A,B]=(0,c.useState)(!1),[C,D]=(0,c.useState)({}),[E,G]=(0,c.useState)([]);(0,c.useEffect)(()=>{let b=!0;return(async()=>{try{let c=await (0,J.getHomeDirectory)();if(!b)return;t(c),a||j(c)}catch(a){console.error("Failed to resolve home directory:",a)}a&&b&&j(a)})(),()=>{b=!1}},[a]),(0,c.useEffect)(()=>{let a=!0;return(async()=>{try{let b=await (0,o.getConfig)();if(!a)return;let c=Array.isArray(b.pinnedFolderShortcuts)?b.pinnedFolderShortcuts.filter(a=>"string"==typeof a&&a.trim().length>0):[];G(Array.from(new Set(c)))}catch(a){console.error("Failed to load pinned folder shortcuts:",a)}})(),()=>{a=!1}},[]),(0,c.useEffect)(()=>{try{let a=localStorage.getItem(W);("list"===a||"grid"===a)&&z(a)}catch{}finally{B(!0)}},[]),(0,c.useEffect)(()=>{if(A)try{localStorage.setItem(W,y)}catch{}},[A,y]),(0,c.useEffect)(()=>{i&&(async()=>{n(!0),r(null);try{let a=await K(i);l(a)}catch(a){console.error("Failed to list files:",a),r("Failed to load directory contents")}finally{n(!1)}})()},[i]),(0,c.useEffect)(()=>{i&&g?.(i)},[i,g]),(0,c.useEffect)(()=>{v([]),x(null),D({})},[i]);let H=(0,c.useMemo)(()=>new Set(u),[u]),X=(a,b,c)=>{if(a.isDirectory)return void j(a.path);let d=c.metaKey||c.ctrlKey;if(c.shiftKey&&null!==w){let a=Math.min(w,b),c=Math.max(w,b);v(k.slice(a,c+1).filter(a=>!a.isDirectory).map(a=>a.path));return}if(d){v(b=>b.includes(a.path)?b.filter(b=>b!==a.path):[...b,a.path]),x(b);return}v([a.path]),x(b)},Y=async()=>{if(r(null),!d)return void r("Cannot paste: Session worktree path is missing.");try{if(n(!0),!navigator.clipboard||!navigator.clipboard.read)throw Error("Clipboard API not supported in this browser");let a=await navigator.clipboard.read(),b=new FormData,c=!1;for(let d of a)for(let a of d.types)if(a.startsWith("image/")){let e=await d.getType(a),f=a.split("/")[1]||"png",g=`pasted-image-${Date.now()}.${f}`,h=new File([e],g,{type:a});b.append(g,h),c=!0;break}if(c){let a=await (0,L.saveAttachments)(d,b);if(a&&a.length>0)return void await e(a);r("Failed to save pasted files.")}else try{let a=await navigator.clipboard.readText();a&&a.trim().startsWith("/")?r("No file content found in clipboard. Copy an image or file first."):r("No file content found in clipboard.")}catch{r("No file content found in clipboard.")}}catch(b){let a=b instanceof Error?b.message:String(b);console.error("Paste error:",b),r(`Failed to read from clipboard: ${a}`)}finally{n(!1)}},Z=async a=>{G(a);try{await (0,p.updateConfig)({pinnedFolderShortcuts:a})}catch(a){console.error("Failed to save pinned folder shortcuts:",a),r("Failed to save pinned shortcuts")}},$=async a=>{(r(null),E.includes(a))?await Z(E.filter(b=>b!==a)):await Z([...E,a])},_=(0,c.useCallback)(async()=>{0!==u.length&&await e(u)},[e,u]);return(0,V.useDialogKeyboardShortcuts)({onConfirm:_,onDismiss:f,canConfirm:u.length>0}),(0,b.jsx)("div",{className:"fixed inset-0 z-50 flex items-center justify-center bg-black/50 backdrop-blur-sm p-4",children:(0,b.jsxs)("div",{className:"bg-base-200 rounded-lg shadow-xl w-full max-w-5xl h-[82vh] flex flex-col",children:[(0,b.jsxs)("div",{className:"flex items-center justify-between p-4 border-b border-base-300",children:[(0,b.jsxs)("h2",{className:"text-xl font-bold flex items-center gap-2",children:[(0,b.jsx)(O.Folder,{className:"w-5 h-5"}),"Browse Files"]}),(0,b.jsx)("button",{onClick:f,className:"btn btn-sm btn-ghost btn-circle",title:"Close file browser",children:"✕"})]}),(0,b.jsxs)("div",{className:"flex items-center gap-2 p-3 bg-base-300",children:[(0,b.jsx)("button",{onClick:()=>{let a=(0,U.getDirName)(i);a&&a!==i&&j(a)},className:"btn btn-sm btn-square btn-ghost",title:"Go Up",disabled:"/"===i||!i,children:(0,b.jsx)(F.ArrowLeft,{className:"w-4 h-4"})}),(0,b.jsxs)("button",{onClick:()=>{s&&i!==s&&j(s)},className:"btn btn-sm btn-ghost gap-1",title:s?`Go to Home Folder (${s})`:"Go to Home Folder",disabled:!s||i===s,children:[(0,b.jsx)(Q,{className:"w-4 h-4"}),"Home"]}),(0,b.jsx)("div",{className:"flex-1 overflow-x-auto whitespace-nowrap px-2 font-mono text-sm",children:i}),(0,b.jsxs)("div",{className:"join",children:[(0,b.jsx)("button",{type:"button",onClick:()=>z("list"),className:`btn btn-sm join-item ${"list"===y?"btn-active":"btn-ghost"}`,title:"List view",children:(0,b.jsx)(R,{className:"w-4 h-4"})}),(0,b.jsx)("button",{type:"button",onClick:()=>z("grid"),className:`btn btn-sm join-item ${"grid"===y?"btn-active":"btn-ghost"}`,title:"Grid view",children:(0,b.jsx)(P,{className:"w-4 h-4"})})]}),(0,b.jsxs)("button",{onClick:_,className:"btn btn-sm btn-primary gap-2",disabled:0===u.length,title:"Insert selected absolute paths",children:["Insert (",u.length,")"]}),(0,b.jsx)("div",{className:"w-[1px] h-6 bg-base-content/10 mx-1"}),(0,b.jsxs)("button",{onClick:Y,className:"btn btn-sm btn-ghost gap-2",title:"Paste file/image from clipboard",disabled:!d,children:[(0,b.jsx)(M,{className:"w-4 h-4"}),"Paste"]})]}),E.length>0&&(0,b.jsx)("div",{className:"px-3 py-2 border-b border-base-300 bg-base-200/50",children:(0,b.jsx)("div",{className:"flex items-center gap-2 overflow-x-auto",children:E.map(a=>{let c=a===i,d=a.split(/[\\/]/).filter(Boolean).pop()||a;return(0,b.jsxs)("div",{className:"join shrink-0",children:[(0,b.jsxs)("button",{type:"button",className:`btn btn-xs join-item ${c?"btn-primary":"btn-ghost"}`,onClick:()=>j(a),title:a,children:[(0,b.jsx)(O.Folder,{className:"w-3 h-3"}),d]}),(0,b.jsx)("button",{type:"button",className:"btn btn-xs btn-ghost join-item",onClick:()=>void $(a),title:`Unpin ${a}`,children:(0,b.jsx)(T,{className:"w-3 h-3"})})]},a)})})}),(0,b.jsx)("div",{className:"flex-1 overflow-y-auto p-2",children:m?(0,b.jsx)("div",{className:"flex justify-center items-center h-full",children:(0,b.jsx)("span",{className:"loading loading-spinner loading-lg"})}):q?(0,b.jsx)("div",{className:"alert alert-error",children:q}):0===k.length?(0,b.jsx)("div",{className:"text-center text-base-content/50 mt-10",children:"Empty directory"}):"list"===y?(0,b.jsx)("div",{className:"grid grid-cols-1 gap-1",children:k.map((a,c)=>{let d=H.has(a.path);return(0,b.jsxs)("div",{className:`flex items-center justify-between p-2 rounded-md cursor-pointer transition-colors border ${d?"bg-primary text-primary-content border-primary":"hover:bg-base-100 border-transparent"}`,onClick:b=>X(a,c,b),title:a.path,children:[(0,b.jsxs)("div",{className:"flex items-center gap-3 overflow-hidden",children:[a.isDirectory?(0,b.jsx)(O.Folder,{className:"w-5 h-5 shrink-0"}):(0,b.jsx)(N,{className:"w-5 h-5 shrink-0"}),(0,b.jsx)("span",{className:"truncate",children:a.name})]}),(0,b.jsx)("span",{className:"text-[10px] opacity-70 shrink-0",children:a.isDirectory?(0,b.jsx)("button",{type:"button",className:"btn btn-ghost btn-xs h-6 min-h-6",onClick:b=>{b.stopPropagation(),$(a.path)},title:E.includes(a.path)?"Unpin folder":"Pin folder",children:(0,b.jsx)(S,{className:`w-3 h-3 ${E.includes(a.path)?"fill-current":""}`})}):"file"})]},a.path)})}):(0,b.jsx)("div",{className:"grid grid-cols-2 md:grid-cols-4 lg:grid-cols-5 gap-3",children:k.map((a,c)=>{var d;let e,f=H.has(a.path),g=!a.isDirectory&&-1!==(e=(d=a.name).lastIndexOf("."))&&h.has(d.slice(e).toLowerCase()),i=`/api/file-thumbnail?path=${encodeURIComponent(a.path)}`;return(0,b.jsxs)("button",{type:"button",className:`rounded-lg border text-left overflow-hidden transition-colors ${f?"border-primary bg-primary/15":"border-base-300 hover:bg-base-100"}`,onClick:b=>X(a,c,b),title:a.path,children:[(0,b.jsxs)("div",{className:"aspect-square bg-base-300 flex items-center justify-center overflow-hidden relative",children:[g&&!C[a.path]?(0,b.jsx)(I.default,{src:i,alt:a.name,fill:!0,sizes:"(max-width: 768px) 50vw, (max-width: 1024px) 25vw, 20vw",className:"object-cover",unoptimized:!0,onError:()=>D(b=>({...b,[a.path]:!0}))}):a.isDirectory?(0,b.jsx)(O.Folder,{className:"w-10 h-10 opacity-80"}):(0,b.jsx)(N,{className:"w-10 h-10 opacity-80"}),a.isDirectory&&(0,b.jsx)("button",{type:"button",className:`absolute top-1 right-1 btn btn-xs btn-circle ${E.includes(a.path)?"btn-primary":"btn-ghost bg-base-100/70"}`,onClick:b=>{b.stopPropagation(),$(a.path)},title:E.includes(a.path)?"Unpin folder":"Pin folder",children:(0,b.jsx)(S,{className:`w-3 h-3 ${E.includes(a.path)?"fill-current":""}`})})]}),(0,b.jsxs)("div",{className:"px-2 py-2",children:[(0,b.jsx)("div",{className:"truncate text-sm font-medium",title:a.name,children:a.name}),(0,b.jsx)("div",{className:"text-[10px] opacity-70",children:a.isDirectory?"folder":g?"image":"file"})]})]},a.path)})})}),(0,b.jsx)("div",{className:"p-3 border-t border-base-300 text-xs text-base-content/60 text-center",children:"Click: single select. Cmd/Ctrl+Click: multi-select. Shift+Click: range select. Click a folder to open it."})]})})}var Y=a.i(12627);function Z(a,b,c){var d,e;let f=(d=a,e=b,`viba-${(d.trim().replace(/[^a-zA-Z0-9_-]/g,"-")||"session").slice(0,40)}-${e}`),g=new URLSearchParams;for(let a of(g.append("arg","new-session"),Array.isArray(c)?c:c?[c]:[]))a.value&&(g.append("arg","-e"),g.append("arg",`${a.name}=${a.value}`));return g.append("arg","-A"),g.append("arg","-s"),g.append("arg",f),`/terminal?${g.toString()}`}let $=a=>{let b=a.trim();if(!b)return null;if(/^https?:\/\//i.test(b))return b;if(/^[a-z][a-z0-9+.-]*:\/\//i.test(b)||/^(mailto|javascript|data|tel):/i.test(b))return null;let c=b.split("/")[0]??"",d=c.indexOf(":");if(d>0&&!c.startsWith("[")){let a=c.slice(0,d).toLowerCase(),b=c.slice(d+1);if(!(a.includes(".")||"localhost"===a||/^\d{1,3}(?:\.\d{1,3}){3}$/.test(a)||/^\d+$/.test(b)))return null}let e=c.includes("@")?c.slice(c.lastIndexOf("@")+1):c,f=e.startsWith("[")?e.slice(1,Math.max(1,e.indexOf("]"))).toLowerCase():e.split(":")[0].toLowerCase();return`${"localhost"===f||"127.0.0.1"===f||"::1"===f?"http":"https"}://${b}`},_=a=>`'${a.replace(/'/g,"'\\''")}'`,aa=[{id:"vscode",name:"VS Code",protocol:"vscode"},{id:"cursor",name:"Cursor",protocol:"cursor"},{id:"windsurf",name:"Windsurf",protocol:"windsurf"},{id:"antigravity",name:"Antigravity",protocol:"antigravity"}],ab="viba-terminal-size",ac="viba-agent-preview-split-ratio",ad=/(?:\$|%|#|>) $/,ae=a=>Math.max(.2,Math.min(.8,a)),af=(a,b)=>{let c=a.replace(/\\/g,"/").replace(/\/+$/,""),d=b.replace(/\\/g,"/").replace(/^\/+/,"");return`${c}/${d}`},ag=(a,b)=>{let c=b.trim().replace(/\\/g,"/").replace(/\/+$/,"");if(!c)return null;let d=(a=>{let b=a.trim();if(!b)return"";if(b=b.replace(/[#?].*$/,""),/^file:\/\//i.test(b))try{let a=new URL(b);b=decodeURIComponent(a.pathname)}catch{}else if(/^https?:\/\//i.test(b))try{let a=new URL(b);b=decodeURIComponent(a.pathname)}catch{}return(b=b.replace(/^webpack(?:-internal)?:\/\/\/?/,"").replace(/^rsc:\/\//,"").replace(/^\(.*?\)\//,"").replace(/^\/\.\//,"/").replace(/^\.\//,"").replace(/\\/g,"/")).trim()})(a);if(!d)return null;if(d.startsWith("/")||(0,U.isWindowsAbsolutePath)(d))return d;let e=new Set;e.add(d.replace(/^\.\/+/,""));let f=d.indexOf("/src/");for(let a of(f>=0&&e.add(d.slice(f+1)),d.startsWith("src/")&&e.add(d),e))if(a)return af(c,a);return null},ah=a=>{let b=a.trim();if(!b)return"";let c=b.match(/[A-Za-z_$][\w$]*/);return c?c[0]:""};function ai({repo:a,worktree:d,branch:e,baseBranch:s,sessionName:I,agent:J,startupScript:K,devServerScript:L,initialMessage:M,attachmentNames:N,title:O,sessionMode:P="fast",onExit:Q,isResume:R,terminalPersistenceMode:S="shell",onSessionStart:T,agentTerminalSrc:V,floatingTerminalSrc:W}){let af="hidden min-[1900px]:inline",ai=(0,c.useRef)(null),aj=(0,c.useRef)(null),ak=(0,c.useRef)(null),al=(0,c.useRef)(null),am=(0,c.useRef)(null),an=(0,c.useRef)({startX:0,startRatio:.5}),ao=(0,c.useRef)(null),ap=(0,c.useRef)(null),aq=(0,c.useRef)(null),ar=(0,c.useRef)({injected:!1,timer:null}),as=(0,c.useMemo)(()=>V||Z(I,"agent"),[V,I]),at=(0,c.useMemo)(()=>W||Z(I,"terminal"),[W,I]),au=(0,c.useRef)({agent:"idle",terminal:"idle"}),av=(0,c.useRef)({agent:!1,terminal:!1});(0,c.useEffect)(()=>{au.current={agent:"idle",terminal:"idle"},av.current={agent:!1,terminal:!1},null!==ar.current.timer&&window.clearTimeout(ar.current.timer),ar.current={injected:!1,timer:null}},[I]),(0,c.useEffect)(()=>()=>{null!==ar.current.timer&&(window.clearTimeout(ar.current.timer),ar.current.timer=null)},[]);let aw=(0,c.useCallback)(a=>`viba:terminal-bootstrap:${I}:${a}`,[I]),ax=(0,c.useCallback)(a=>`${I}:${a}`,[I]),ay=(0,c.useCallback)(()=>null,[]),az=(0,c.useCallback)(a=>{let b=ay();return b&&b[ax(a)]||"idle"},[ay,ax]),aA=(0,c.useCallback)((a,b)=>{let c=ay();c&&(c[ax(a)]=b)},[ay,ax]),aB=(0,c.useCallback)(a=>{if("done"===au.current[a]||"done"===az(a))return!0;try{return"1"===window.sessionStorage.getItem(aw(a))}catch{return!1}},[az,aw]),aC=(0,c.useCallback)(a=>{let b=au.current[a],c=az(a);return"done"!==b&&"in_progress"!==b&&"done"!==c&&"in_progress"!==c&&(au.current[a]="in_progress",aA(a,"in_progress"),!0)},[az,aA]),aD=(0,c.useCallback)(a=>{"done"!==au.current[a]&&(au.current[a]="idle"),"done"!==az(a)&&aA(a,"idle")},[az,aA]),aE=(0,c.useCallback)(a=>{au.current[a]="done",aA(a,"done");try{window.sessionStorage.setItem(aw(a),"1")}catch{}},[aw,aA]),aF=(0,c.useCallback)(a=>{let b=a?.buffer?.active;if(!b||"function"!=typeof b.getLine)return!0;let c=b.baseY+b.cursorY;for(let a=0;a<6;a+=1){let d=b.getLine(c-a),e=d?.translateToString(!0)??"";if(e.trim())return ad.test(e)}return!1},[]),aG=(0,c.useCallback)(()=>{aq.current&&(aq.current(),aq.current=null)},[]),aH=(0,c.useCallback)((a,b)=>{aG();let c=!1,d=null,e=null,f=null,g=()=>{if(c)return;let a=!aF(b);aS(b=>b===a?b:a)};g(),f=window.setInterval(g,1e3);try{if("function"==typeof b.onWriteParsed)d=b.onWriteParsed(g)||null;else{let b=a.contentDocument?.querySelector(".xterm-screen")||a.contentDocument?.body;b&&(e=new MutationObserver(g)).observe(b,{childList:!0,subtree:!0,characterData:!0})}}catch(a){console.error("Failed to setup terminal process monitor:",a)}aq.current=()=>{c=!0,null!==f&&(window.clearInterval(f),f=null),d&&"function"==typeof d.dispose&&d.dispose(),e?.disconnect()}},[aF,aG]);(0,c.useEffect)(()=>()=>{aG()},[aG]),(0,c.useEffect)(()=>{aS(!1),aG()},[I,aG]);let aI=(0,c.useCallback)((a,b,c)=>{if(R)return!1;let d=K?.trim();return!!d&&!ar.current.injected&&(ar.current.injected=!0,null!==ar.current.timer&&window.clearTimeout(ar.current.timer),ar.current.timer=window.setTimeout(()=>{ar.current.timer=null;try{let e;c.paste(d),(e=a.contentDocument?.querySelector("textarea.xterm-helper-textarea"))?e.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:b})):c.paste("\r")}catch(a){ar.current.injected=!1,console.error("Failed to inject startup script into terminal iframe:",a)}},500),!0)},[R,K]);(0,c.useEffect)(()=>{if(R||!K?.trim()||ar.current.injected)return;let a=!1,b=(c=0)=>{if(a||ar.current.injected||c>30)return;if(!aB("terminal"))return void window.setTimeout(()=>b(c+1),200);let d=aj.current;if(d){try{let a=d.contentWindow;if(a?.term)return void aI(d,a,a.term)}catch{}window.setTimeout(()=>b(c+1),200)}};return b(),()=>{a=!0}},[aB,aI,R,K]);let[aJ,aK]=(0,c.useState)("Initializing..."),[aL,aM]=(0,c.useState)("idle"),[aN,aO]=(0,c.useState)(null),[aP,aQ]=(0,c.useState)(!1),[aR,aS]=(0,c.useState)(!1),[aT,aU]=(0,c.useState)(!1),[aV,aW]=(0,c.useState)(!1),[aX,aY]=(0,c.useState)(!1),[aZ,a$]=(0,c.useState)(d||a),[a_,a0]=(0,c.useState)(!1),[a1,a2]=(0,c.useState)(s?.trim()||""),[a3,a4]=(0,c.useState)([]),[a5,a6]=(0,c.useState)(!1),a7=(0,c.useRef)(!1),[a8,a9]=(0,c.useState)(!1),[ba,bb]=(0,c.useState)({ahead:0,behind:0}),[bc,bd]=(0,c.useState)(!0),[be,bf]=(0,c.useState)(""),[bg,bh]=(0,c.useState)(""),[bi,bj]=(0,c.useState)(!1),[bk,bl]=(0,c.useState)(!1),[bm,bn]=(0,c.useState)(.5),[bo,bp]=(0,c.useState)(!1),[bq,br]=(0,c.useState)(!1),[bs,bt]=(0,c.useState)({width:460,height:320}),[bu,bv]=(0,c.useState)(!1),[bw,bx]=(0,c.useState)(!1),by=(0,c.useRef)({startX:0,startY:0,startWidth:0,startHeight:0}),[bz,bA]=(0,c.useState)("scroll"),[bB,bC]=(0,c.useState)(!1),bD=(0,c.useRef)(0);(0,c.useEffect)(()=>{a$(d||a)},[a,d]),(0,c.useEffect)(()=>{let a=localStorage.getItem(ab);if(a)try{bt(JSON.parse(a))}catch(a){console.error("Failed to parse saved terminal size",a)}let b=localStorage.getItem(ac);if(b){let a=Number.parseFloat(b);Number.isNaN(a)||bn(ae(a))}bx(!0)},[]),(0,c.useEffect)(()=>{if(!bu)return;let a=a=>{let b=by.current.startX-a.clientX,c=by.current.startY-a.clientY;bt({width:Math.max(300,Math.min(window.innerWidth-32,by.current.startWidth+b)),height:Math.max(100,Math.min(window.innerHeight-32,by.current.startHeight+c))})},b=()=>{bv(!1)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",b)}},[bu]),(0,c.useEffect)(()=>{bw&&!bu&&localStorage.setItem(ab,JSON.stringify(bs))},[bw,bu,bs]),(0,c.useEffect)(()=>{bw&&!bo&&localStorage.setItem(ac,String(bm))},[bm,bw,bo]),(0,c.useEffect)(()=>{if(!bo)return;let a=a=>{let b=am.current;if(!b)return;let c=b.getBoundingClientRect();if(c.width<=0)return;let d=a.clientX-an.current.startX;bn(ae((an.current.startRatio*c.width+d)/c.width))},b=()=>{bp(!1)};return window.addEventListener("mousemove",a),window.addEventListener("mouseup",b),()=>{window.removeEventListener("mousemove",a),window.removeEventListener("mouseup",b)}},[bo]),(0,c.useEffect)(()=>{if(!bq&&aj.current){let a=aj.current;setTimeout(()=>{try{let b=a.contentWindow;if(b&&b.term){b.term.scrollToBottom?.(),b.focus();let c=a.contentDocument?.querySelector("textarea.xterm-helper-textarea");c&&c.focus()}}catch(a){console.error("Failed to focus/scroll terminal on restore:",a)}},100)}},[bq]);let[bE,bF]=(0,c.useState)("vscode");(0,c.useEffect)(()=>{let a=O?.trim();if(a)return document.title=`${a} | Viba`,()=>{document.title="Viba"};document.title="Viba"},[O]),(0,c.useEffect)(()=>{(async()=>{let a=await (0,o.getConfig)();a.selectedIde&&aa.some(b=>b.id===a.selectedIde)&&bF(a.selectedIde)})()},[]),(0,c.useEffect)(()=>{a2(s?.trim()||""),a4([])},[s,I]),(0,c.useEffect)(()=>{bA("scroll"),bC(!1),bD.current+=1},[I]);let bG=async a=>{let b=a.target.value;bF(b),await (0,p.updateConfig)({selectedIde:b})},bH=(0,c.useCallback)(async(a,b)=>{if("tmux"!==S)return!0;let c=++bD.current;b?.silent||bC(!0);let d="scroll"===a,[e,f]=await Promise.all([m(I,"agent",d),m(I,"terminal",d)]);return c===bD.current&&((b?.silent||bC(!1),[e,f].find(a=>!a.success))?(b?.silent||aK(`Failed to switch to ${"scroll"===a?"scroll mode":"text select mode"}`),!1):(b?.silent||aK("scroll"===a?"Terminal mode: Scroll":"Terminal mode: Text Select"),!0))},[I,S]),bI=(0,c.useCallback)(a=>{"tmux"!==S||av.current[a]||(async()=>{let b=await n(I,a,!1);b.success&&b.applied?av.current[a]=!0:b.success||console.error(`Failed to hide tmux status bar for ${a}:`,b.error)})()},[I,S]);(0,c.useEffect)(()=>{"tmux"===S&&bH("scroll",{silent:!0})},[bH,S]);let bJ=(0,c.useCallback)(()=>{if("tmux"!==S||bB)return;let a="scroll"===bz?"select":"scroll";bA(a),(async()=>{await bH(a)||bA(bz)})()},[bH,bB,bz,S]),bK=async(b=!0)=>{if(!a||!d||!e||b&&!confirm("Are you sure you want to delete this session? This will remove the branch and worktree."))return!1;aO(null),aM("idle"),aK("Purging session...");try{let a=await f(I);if(!a.success)return console.error("Cleanup failed:",a.error||"Unknown error"),aM("error"),aO(a.error||"Failed to delete session"),!1;(0,Y.notifySessionsUpdated)()}catch(a){return console.error("Cleanup request failed:",a),aM("error"),aO(a instanceof Error?a.message:"Unknown error"),!1}return Q(!0),!0},bL=async()=>{await bK(!0)},bM=(0,c.useCallback)(a=>new Promise(b=>{let c=ai.current;if(!c)return void b(!1);let d=(e=0)=>{if(e>30)return void b(!1);try{let f=c.contentWindow;if(!f||!f.term)return void setTimeout(()=>d(e+1),300);f.term.paste(a);let g=c.contentDocument?.querySelector("textarea.xterm-helper-textarea");g&&g.focus(),f.focus(),b(!0)}catch(a){console.error("Failed to paste into agent iframe:",a),setTimeout(()=>d(e+1),300)}};d()}),[]),bN=(0,c.useCallback)(async a=>{if(0===a.length)return;a0(!0);let b=`${a.join(" ")} `;aK(await bM(b)?`Inserted ${a.length} file path${1===a.length?"":"s"} into agent input`:"Failed to insert file paths into agent input"),a0(!1)},[bM]),bO=(0,c.useCallback)(async b=>{let c=b.map(ah).filter(Boolean);if(0===c.length)return null;let e=Array.from(new Set([a,d].map(a=>(a||"").trim()).filter(Boolean)));if(0===e.length)return null;for(let a of e)try{let b=await fetch("/api/component-source/resolve",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({componentNames:c,workspaceRoot:a})}),d=await b.json().catch(()=>null);if(!b.ok){console.warn("Component source resolve miss",{componentNames:c,workspaceRoot:a,error:d?.error||b.statusText});continue}let e="string"==typeof d?.sourcePath?d.sourcePath.trim():"",f="string"==typeof d?.resolvedName?d.resolvedName.trim():"";if(e&&f)return{sourcePath:e,resolvedName:f}}catch(a){console.error("Failed to resolve component source path:",a)}return null},[a,d]),bP=(0,c.useCallback)(async()=>{if(I&&!a7.current){a7.current=!0,a6(!0);try{let a=await h(I);a.success?(a4(a.branches??[]),a2(a.baseBranch?.trim()||"")):a.error&&aK(`Failed to load branches: ${a.error}`)}catch(a){console.error("Failed to load base branches:",a)}finally{a7.current=!1,a6(!1)}}},[I]);(0,c.useEffect)(()=>{I&&bP()},[bP,I]);let bQ=(0,c.useCallback)(async()=>{if(I)try{let a=await g(I);a.success&&"number"==typeof a.ahead&&"number"==typeof a.behind&&bb({ahead:a.ahead,behind:a.behind})}catch(a){console.error("Failed to load branch divergence:",a)}},[I]);(0,c.useEffect)(()=>{if(!I||!a1)return void bb({ahead:0,behind:0});bQ();let a=window.setInterval(()=>{bQ()},6e4);return()=>window.clearInterval(a)},[a1,bQ,I]);let bR=async()=>{if(!I||!a1)return!1;aU(!0),aK("Merging session branch...");try{let a=await i(I);if(a.success)return aK(`Merged ${a.branchName} into ${a.baseBranch}`),bQ(),!0;return aK(`Merge failed: ${a.error}`),!1}catch(a){return console.error("Merge request failed:",a),aK("Merge failed"),!1}finally{aU(!1)}},bS=async()=>{await bR()},[bT,bU]=(0,c.useState)(!1),bV=(0,c.useRef)(null);(0,c.useEffect)(()=>{let a=a=>{bV.current&&!bV.current.contains(a.target)&&bU(!1)};return document.addEventListener("mousedown",a),()=>document.removeEventListener("mousedown",a)},[]);let bW=async a=>{if(bU(!1),!I)return;let b=a!==a1;aW(!0),aK(b?`Updating base to ${a} and rebasing...`:"Rebasing session branch...");try{if(b){let b=await k(I,a);if(!b.success){aK(`Failed to update base branch: ${b.error}`),aW(!1);return}a2(b.baseBranch),await bP()}let c=await j(I);c.success?(aK(`Rebased ${c.branchName} onto ${c.baseBranch}`),bQ()):aK(`Rebase failed: ${c.error}`)}catch(a){console.error("Rebase request failed:",a),aK("Rebase failed")}finally{aW(!1)}},bX=(0,c.useCallback)(async(a,b)=>{let c=$(a);if(!c)return aK("Please enter a preview URL"),!1;bf(c),bj(!1),aK(`Loading preview: ${c}`);try{let a=await fetch("/api/preview-proxy/start",{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({target:c})}),d=await a.json().catch(()=>null);if(!a.ok||!d?.proxyUrl)throw Error(d?.error||"Failed to start preview proxy");return bh(d.proxyUrl),b&&bd(!0),aK(`Loaded preview: ${c}`),!0}catch(b){let a=b instanceof Error?b.message:"Failed to load preview";return console.error("Failed to load preview via proxy:",b),aK(`Failed to load preview: ${a}`),!1}},[]),bY=(0,c.useCallback)(()=>{if(!bg)return void aK("Load a preview before picking elements");let a=ak.current?.contentWindow;if(!a)return void aK("Preview is not ready yet");let b=!bi;a.postMessage({type:"viba:preview-picker-toggle",active:b},"*"),bj(b),aK(b?"Picker enabled: click an element in the preview":"Picker disabled")},[bi,bg]),bZ=(0,c.useCallback)(a=>{let b=ak.current?.contentWindow;return b?(b.postMessage(a,"*"),!0):(aK("Preview is not ready yet"),!1)},[]),b$=(0,c.useCallback)(a=>{bg?bZ({type:"viba:preview-navigation",action:a})&&"reload"===a&&aK("Reloading preview..."):aK("Load a preview before using navigation controls")},[bZ,bg]),b_=(0,c.useCallback)(()=>{bZ({type:"viba:preview-location-request"})},[bZ]),{attachTerminalLinkHandler:b0}=function({onLoadPreview:a}){let b=(0,c.useCallback)((b,c)=>{let d=$(b);return!!d&&("new_tab"===c?window.open(d,"_blank","noopener,noreferrer"):a(d,!0),!0)},[a]),d=(0,c.useCallback)((a,c,d)=>{c.current?.();let e=a.contentWindow,f=e?.term;if(!e||!f)return;let g=d?.onLinkActivated,h=d?.directOpenBehavior??"preview",i=d?.modifierOpenBehavior??"new_tab",j=a=>a?i:h,k=[],l=a.contentDocument,m={metaKey:!1,ctrlKey:!1,at:0};if(l){let a=a=>{m={metaKey:a.metaKey,ctrlKey:a.ctrlKey,at:Date.now()}};l.addEventListener("mousedown",a,!0),l.addEventListener("click",a,!0),k.push(()=>{l.removeEventListener("mousedown",a,!0),l.removeEventListener("click",a,!0)})}let n=e.open.bind(e);e.open=(...a)=>{let c=j(Date.now()-m.at<1e3&&(m.metaKey||m.ctrlKey));if("string"==typeof a[0]&&a[0].trim())return(g?.(),b(a[0],c))?null:n(...a);if(0===a.length){let a=null;return{opener:null,location:{set href(url){if(g?.(),!b(url,c)&&(a=n())){try{a.opener=null}catch{}a.location.href=url}},get href(){return""}}}}return n(...a)},k.push(()=>{e.open=n});let o=f._core?._linkProviderService?.linkProviders;if(o instanceof Map){for(let a of o.values())if(a&&"object"==typeof a){if("function"==typeof a._handler){let c=a._handler;a._handler=(a,d)=>{g?.(),b(d,j(!!(a?.metaKey||a?.ctrlKey)))||c(a,d)},k.push(()=>{a._handler=c})}if("function"==typeof a.provideLinks){let c=a.provideLinks.bind(a);a.provideLinks=(a,d)=>{c(a,a=>{if(Array.isArray(a))for(let c of a){if(!c||"object"!=typeof c||"function"!=typeof c.activate)continue;let a=c.activate.bind(c);c.activate=(c,d)=>{g?.(),b(d,j(!!(c?.metaKey||c?.ctrlKey)))||a(c,d)}}d(a)})},k.push(()=>{a.provideLinks=c})}}}let p=f.options.linkHandler,q={allowNonHttpProtocols:p?.allowNonHttpProtocols??!1,activate:(a,c,d)=>{g?.(),b(c,j(!!(a?.metaKey||a?.ctrlKey)))||p?.activate?.(a,c,d)},hover:(a,b,c)=>{p?.hover?.(a,b,c)},leave:(a,b,c)=>{p?.leave?.(a,b,c)}};f.options.linkHandler=q,k.push(()=>{f.options.linkHandler=p??null}),c.current=()=>{for(let a of k)a();c.current=null}},[b]);return{handleTerminalLinkOpen:b,attachTerminalLinkHandler:d}}({onLoadPreview:bX});(0,c.useEffect)(()=>{if(!bc||be.trim())return;let a=window.setTimeout(()=>{al.current?.focus()},0);return()=>{window.clearTimeout(a)}},[bc,be]),(0,c.useEffect)(()=>{let b=b=>{if(!ak.current||b.source!==ak.current.contentWindow)return;let c=b.data;if(c&&"object"==typeof c){if("viba:preview-picker-state"===c.type)return void bj(!!c.active);if("viba:preview-picker-ready"===c.type){let a=ak.current?.contentWindow;a&&a.postMessage({type:"viba:preview-location-request"},"*");return}if("viba:preview-link-open"===c.type){"string"==typeof c.url&&c.url.trim().length>0&&window.open(c.url,"_blank","noopener,noreferrer");return}if("viba:preview-location-change"===c.type){"string"==typeof c.url&&c.url.trim().length>0&&bf(c.url);return}if("viba:preview-element-selected"===c.type){let b=c.element&&"object"==typeof c.element?c.element:null,e=Array.isArray(b?.reactComponentStack)?b.reactComponentStack:[],f=((a,b)=>{for(let c of a){if(!c||"object"!=typeof c)continue;let a="string"==typeof c.name?c.name.trim():"";if(!a)continue;let d="string"==typeof c.source?.fileName?c.source.fileName.trim():"",e=d?ag(d,b):null;if(e)return`${a} (${e})`}return null})(e,d||a),g=e[0]&&"object"==typeof e[0]?e[0].name:void 0,h="string"==typeof g&&g.trim().length>0?g.trim():"",i=new Set(["Suspense","ErrorBoundary","Router","AppRouter","LayoutRouter","RenderFromTemplateContext","ScrollAndFocusHandler","InnerLayoutRouter","RedirectErrorBoundary","NotFoundBoundary","LoadingBoundary","ReactDevOverlay","HotReload","AppContainer","Route","Link","Image","OuterLayoutRouter","Head","StringRefs","Fragment","Profiler","StrictMode","SuspenseList","Script","Page","__next_root_layout_boundary__"]),j=Array.from(new Set(e.map(a=>{if(!a||"object"!=typeof a)return"";let b=a.name;return"string"==typeof b?b.trim():""}).filter(a=>!(!a||i.has(a)||a.startsWith("styled.")||a.startsWith("Styled(")))));console.log("Filtered stack component names:",j);let k=f||h||("string"==typeof b?.selector?b.selector:"");if(console.log("Preview selected element:",b),console.log("Preview selected reactComponentStack:",e),console.log("Preview selected identifier:",k),bj(!1),!k)return void aK("Element selected. No identifier was resolved.");(async()=>{let a=f||"";if(!a&&j.length>0){bl(!0);try{let b=await bO(j);b?.resolvedName&&b?.sourcePath&&(a=`${b.resolvedName} (${b.sourcePath})`)}finally{bl(!1)}}if(!a){if(j.length>0)return aK("Element selected, but source file path could not be resolved for the component");a=k}console.log("Final resolved component identifier:",a),aK(await bM(`${a} `)?`Element identifier sent to agent: ${a}`:"Element selected, but failed to send identifier to agent input")})()}}};return window.addEventListener("message",b),()=>{window.removeEventListener("message",b)}},[bM,a,bO,d]),(0,c.useEffect)(()=>{bj(!1)},[bg]);let b1=(0,c.useCallback)(()=>{let a=$(be.trim()||bg);a?(window.open(a,"_blank","noopener,noreferrer"),aK(`Opened preview in new tab: ${a}`)):aK("Please enter a preview URL")},[be,bg]);if(!a)return(0,b.jsx)("div",{className:"p-4 text-error",children:"No repository specified"});if("error"===aL)return(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsx)("div",{className:"card w-96 bg-base-200 shadow-xl",children:(0,b.jsxs)("div",{className:"card-body items-center text-center",children:[(0,b.jsx)("h2",{className:"card-title text-error",children:"Cleanup failed"}),(0,b.jsx)("p",{children:aN||"An unknown error occurred while cleaning up this session."}),(0,b.jsx)("div",{className:"card-actions justify-end",children:(0,b.jsx)("button",{className:"btn btn-primary",onClick:()=>Q(),children:"Back to Home"})})]})})});let b2=Array.from(new Set([...a1?[a1]:[],...a3])).filter(a=>a!==e||a===a1),b3=!!L?.trim();return(0,b.jsxs)("div",{className:`flex h-screen w-full flex-col overflow-hidden bg-[#f6f6f8] ${bu||bo?"select-none":""}`,children:[(bu||bo)&&(0,b.jsx)("div",{className:`fixed inset-0 z-[9999] ${bu?"cursor-row-resize":"cursor-col-resize"}`}),(0,b.jsxs)("div",{className:"z-20 flex items-center justify-between border-b border-slate-200 bg-white px-4 py-2 text-xs font-mono shadow-sm",children:[(0,b.jsxs)("div",{className:"flex items-center gap-4",children:[(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-6 min-h-6 px-1 hover:bg-base-content/10",onClick:()=>Q(),title:"Back to Home",children:(0,b.jsx)(A,{className:"w-4 h-4"})}),(0,b.jsxs)("div",{className:"flex flex-col",children:[(0,b.jsxs)("div",{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{className:"opacity-50",children:"Repo:"}),(0,b.jsx)("span",{className:"font-bold",children:(0,U.getBaseName)(a)})]}),I&&(0,b.jsxs)("div",{className:"hidden min-[1200px]:flex min-w-0 items-center gap-2 text-[10px] opacity-70",children:[(0,b.jsx)("span",{children:"Session:"}),(0,b.jsx)("span",{className:"truncate max-w-[220px]",title:I,children:I})]})]})]}),(0,b.jsxs)("div",{className:"flex items-center gap-4",children:[(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden",children:[(0,b.jsx)("select",{className:"select select-xs h-6 min-h-6 bg-base-200 border-none focus:outline-none rounded-none pr-7",value:bE,onChange:bG,children:aa.map(a=>(0,b.jsx)("option",{value:a.id,children:a.name},a.id))}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/20"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none hover:bg-base-content/10",onClick:()=>{if(!d)return;let a=aa.find(a=>a.id===bE);if(!a)return;let b=`${a.protocol}://file/${encodeURI(d)}`;window.open(b,"_blank")},title:`Open in ${aa.find(a=>a.id===bE)?.name}`,children:[(0,b.jsx)(r.ExternalLink,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Open"})]})]}),(0,b.jsx)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{if(!d||!e)return;let a=new URLSearchParams({path:d,branch:e});window.open(`http://localhost:3100/workspace?${a.toString()}`,"_blank","noopener,noreferrer")},disabled:!d||!e,title:"Open this worktree and branch in Trident",children:[(0,b.jsx)(w,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Diff"})]})}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>aY(!0),disabled:a_,title:"Browse files and insert absolute paths into the agent input",children:[a_?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(z,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Add Files"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{if(!a||!I)return;let b=`/new?repo=${encodeURIComponent(a)}&prefillFromSession=${encodeURIComponent(I)}`;window.open(b,"_blank","noopener,noreferrer")},title:"Start a new attempt in a new tab with this session context",children:[(0,b.jsx)(D.Plus,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"New Attempt"})]})]}),(0,b.jsx)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{let a=L?.trim();if(!a||!aj.current||aR)return;br(!1);let b=aj.current;aQ(!0),aK("Starting dev server...");let c=(d=0)=>{if(d>30){aK("Failed to start dev server: terminal is not ready"),aQ(!1);return}try{let e=b.contentWindow;if(e&&e.term){e.term.paste(a);let c=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");c?c.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:e})):e.term.paste("\r"),e.focus(),c&&c.focus(),aK("Dev server start command sent"),aQ(!1)}else setTimeout(()=>c(d+1),300)}catch(a){console.error("Dev server injection error",a),aK("Failed to start dev server"),aQ(!1)}};c()},disabled:!b3||aP||aR,title:b3?aR?"A process is already running in the terminal":"Run dev server script in terminal":"Set a dev server script to enable this button",children:[aP?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(t,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Dev"})]})}),(0,b.jsx)("div",{className:"flex items-center border border-base-content/20 rounded overflow-hidden bg-base-100",children:(0,b.jsxs)("button",{className:`btn btn-ghost btn-xs rounded-none h-6 min-h-6 border-none px-2 hover:bg-base-content/10 ${"select"===bz?"text-warning":""}`,onClick:bJ,disabled:"tmux"!==S||bB,title:"tmux"===S?"scroll"===bz?"Switch to text select mode for easier copy":"Switch to scroll mode for wheel scrollback":"Mode toggle is available only in tmux persistence mode",children:[bB?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(E,{className:"w-3 h-3"}),(0,b.jsx)("span",{children:"scroll"===bz?"Scroll Mode":"Text Select"})]})}),(0,b.jsxs)("div",{className:"flex items-center border border-base-content/20 rounded relative bg-base-100",ref:bV,children:[(0,b.jsxs)("div",{className:"relative",children:[(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs rounded-none rounded-l h-6 min-h-6 border-none px-2 hover:bg-base-content/10",onClick:()=>{bU(!bT)},disabled:aV||aT||a8,title:"Select base branch and rebase",children:[aV?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(v,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Rebase"}),(0,b.jsx)(C.ChevronDown,{className:"w-3 h-3 opacity-50 ml-0.5"})]}),bT&&(0,b.jsxs)("div",{className:"absolute top-full left-0 z-50 mt-1 w-64 p-0 shadow-xl dropdown-content bg-base-200 rounded-box border border-base-content/20 flex flex-col max-h-80 overflow-hidden",children:[(0,b.jsxs)("div",{className:"px-4 py-2 text-[10px] uppercase font-bold tracking-wider opacity-50 border-b border-base-content/10 bg-base-200 flex justify-between items-center shrink-0",children:[(0,b.jsx)("span",{children:"Select Base Branch"}),(a5||a8)&&(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"})]}),(0,b.jsxs)("ul",{className:"menu p-0 overflow-y-auto flex-nowrap custom-scrollbar overflow-x-hidden w-full",children:[b2.length>0?b2.map(a=>(0,b.jsx)("li",{children:(0,b.jsxs)("button",{onClick:()=>bW(a),className:`flex justify-between items-center text-xs py-2 truncate max-w-full rounded-none ${a===a1?"active font-bold":""}`,title:a,children:[(0,b.jsx)("span",{className:"truncate",children:a}),a===a1&&(0,b.jsx)("span",{className:"opacity-70 text-[10px] ml-2 shrink-0",children:"(Current)"})]})},a)):(0,b.jsx)("li",{className:"text-xs px-4 py-2 opacity-50 italic text-center",children:"No other branches found"}),(0,b.jsx)("div",{className:"divider my-1 opacity-50"}),(0,b.jsx)("li",{children:(0,b.jsx)("button",{onClick:()=>void bP(),className:"text-[10px] justify-center opacity-70 hover:opacity-100",children:"Refresh Branches"})})]})]})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-xs btn-success rounded-none h-6 min-h-6 border-none px-2 hover:bg-success/20 hover:border-transparent",onClick:bS,disabled:aT||aV||a8||!a1,title:a1?`Merge current branch (${e}) into target branch (${a1})`:"Target branch unavailable for this session",children:[aT?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs"}):(0,b.jsx)(u,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Merge"})]}),(0,b.jsx)("div",{className:"w-[1px] h-4 bg-base-content/10"}),(0,b.jsxs)("button",{className:"btn btn-ghost btn-error btn-xs rounded-none rounded-r h-6 min-h-6 border-none px-2 hover:bg-error/20 hover:border-transparent",onClick:bL,disabled:aT||aV||!d,title:"Clean up and exit",children:[(0,b.jsx)(q.Trash2,{className:"w-3 h-3"}),(0,b.jsx)("span",{className:af,children:"Delete"})]})]}),a1&&(0,b.jsxs)("div",{className:"flex items-center gap-2 text-xs opacity-80",title:`Divergence against ${a1}`,children:[(0,b.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,b.jsx)(x,{className:"w-3 h-3"}),ba.ahead]}),(0,b.jsxs)("span",{className:"inline-flex items-center gap-1",children:[(0,b.jsx)(y,{className:"w-3 h-3"}),ba.behind]})]}),(0,b.jsx)("div",{className:"hidden min-[1200px]:block w-[1px] h-4 bg-base-content/20 mx-2"}),(0,b.jsxs)("div",{className:"hidden min-[1200px]:flex min-w-0 max-w-[280px] items-center gap-2",children:[(0,b.jsx)("span",{className:`w-2 h-2 rounded-full ${aJ.includes("Error")||aJ.includes("failed")?"bg-error":aJ.includes("started")||aJ.includes("Merged")||aJ.includes("Rebased")||aJ.includes("sent")?"bg-success":"bg-warning"}`}),(0,b.jsx)("span",{className:"truncate",title:aJ,children:aJ})]})]})]}),(0,b.jsxs)("div",{ref:am,className:"flex min-h-0 flex-1 gap-3 bg-[#f6f6f8] p-3",children:[(0,b.jsxs)("div",{className:"flex h-full min-w-0 flex-col overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm",style:{width:`${100*bm}%`},children:[(0,b.jsxs)("div",{className:"flex h-9 items-center gap-2 border-b border-slate-200 px-3 text-[11px] font-semibold uppercase tracking-wide text-slate-600",children:[(0,b.jsx)("span",{className:"h-2 w-2 rounded-full bg-blue-500"}),"Agent Activity"]}),(0,b.jsx)("iframe",{ref:ai,src:as,className:`h-full w-full border-none dark:invert dark:brightness-90 ${bu||bo?"pointer-events-none":""}`,allow:"clipboard-read; clipboard-write",onLoad:()=>{if(!ai.current)return;let b=ai.current;try{b.contentWindow}catch(a){aK("Error: Cross-Origin access blocked. Ensure proxy is working.");return}b.contentWindow&&(b.contentWindow.onbeforeunload=null,b.contentWindow.addEventListener("beforeunload",a=>{a.stopImmediatePropagation()},!0)),aK("Connecting to terminal...");let c=(e=0)=>{if(e>30)return void aK("Timeout waiting for terminal to be ready");try{let f=b.contentWindow;if(f&&f.term){bI("agent");let g=f.term;b0(b,ao,{directOpenBehavior:"new_tab",modifierOpenBehavior:"new_tab"});try{g.options.theme={...g.options.theme||{},selectionBackground:"rgba(59, 130, 246, 0.4)"}}catch{}let h=aB("agent"),i=!!R&&"tmux"===S;if(h||i){i&&!h?(aE("agent"),aK("Attached to persisted terminal")):aK("Reconnected to terminal"),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}if(!aF(g)&&e<10)return void setTimeout(()=>c(e+1),200);if(!aC("agent")){aK("Reconnected to terminal"),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}let j=d||a,k=`cd ${_(j)}`;g.paste(k);let m=()=>{let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a?a.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:f})):g.paste("\r")};if(m(),aE("agent"),J){let b=async()=>{let b="",c=a=>`if [ -n "$OPENAI_API_KEY" ]; then printenv OPENAI_API_KEY | codex login --with-api-key || exit 1; fi; ${a}`;if(R)b=c("codex resume --last --sandbox danger-full-access --ask-for-approval on-request --search");else{let e=M?.trim()||"",f=(N||[]).map(a=>a.trim()).filter(Boolean).map(b=>`${d||a}-attachments/${b}`),g=[];e&&g.push(e),f.length>0&&g.push(["Attachments:",...f.map(a=>`- ${a}`)].join("\n"));let h=g.join("\n\n"),i="";if(h){let a=[];"plan"===P&&a.push("Plan mode: inspect the relevant code first, present a concrete implementation plan, and wait for explicit user approval before any file edits or write commands."),a.push("After each round, if work is complete and files changed, commit all changes without confirmation. Use a commit message with a clear title and a detailed body explaining what changed and why. If GITHUB_TOKEN or GITLAB_TOKEN is set, push the current branch after committed rounds and create (or update) a pull/merge request with an appropriate title and description; include the pull/merge request link in the first push reply."),a.push("For visual web tasks, use the `agent-browser` skill (https://skills.sh/vercel-labs/agent-browser/agent-browser)."),a.push("For bugfix/debugging tasks, use the `systematic-debugging` skill (https://github.com/obra/superpowers)."),a.push("When working on a visual-related feature or bugfix in a web project, after coding is complete, use `agent-browser` or equivalent Chrome MCP tooling to load the relevant page, take screenshot(s), and include them as evidence in the pull/merge request."),a.push("When your task is completed or you need user attention (for plan approval, permissions, or blockers), send a notification to the matching Viba session.");let b=`${window.location.origin}/api/notifications`;a.push(`Notification API endpoint: ${b} (POST JSON with sessionId, title, and description).`),a.push(`Notification payload template: {"sessionId":"${I}","title":"<short title>","description":"<clear detail about completion or required attention>"}.`);let c=["# Instructions\n",a.map(a=>`- ${a}`).join("\n"),"\n# Task\n",h].join("\n");try{let a=await l(I,c);a.success&&a.filePath?i=` "$(cat ${_(a.filePath)})"`:(console.error("Failed to write prompt file, falling back to inline prompt",a.error),i=` ${_(c)}`)}catch(a){console.error("Exception writing prompt file",a),i=` ${_(c)}`}}let j=`codex --sandbox danger-full-access --ask-for-approval on-request --search${i}`;b=c(j)}b&&(g.paste(b),m(),aK(R?"Resumed session with codex":"Session started with codex"),!R&&T&&T())};setTimeout(()=>b(),500)}else aK(`Session started ${d?"(Worktree)":""}`),!R&&T&&T();f.focus();let n=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");n&&n.focus()}else setTimeout(()=>c(e+1),500)}catch(a){aD("agent"),console.error("Access error during injection:",a),aK("Error accessing terminal: "+String(a))}};setTimeout(()=>c(),1e3)}})]}),(0,b.jsx)("div",{className:"relative h-full w-2 shrink-0 cursor-col-resize rounded bg-slate-200 transition-colors hover:bg-primary/40",onMouseDown:a=>{a.preventDefault(),bp(!0),an.current={startX:a.clientX,startRatio:bm}},role:"separator","aria-orientation":"vertical","aria-label":"Resize preview panel",title:"Drag to resize preview panel",children:(0,b.jsx)("div",{className:"absolute left-1/2 top-1/2 h-12 w-[2px] -translate-x-1/2 -translate-y-1/2 rounded-full bg-slate-400"})}),(0,b.jsxs)("div",{className:"flex h-full min-w-[360px] flex-1 flex-col overflow-hidden rounded-xl border border-slate-200 bg-white shadow-sm",children:[(0,b.jsxs)("div",{className:"min-h-0 flex flex-1 flex-col",children:[(0,b.jsxs)("form",{className:"flex items-center gap-2 border-b border-slate-200 bg-white px-3 py-2",onSubmit:a=>{a.preventDefault(),bX(be,!0)},children:[(0,b.jsxs)("div",{className:"mr-1 flex gap-1.5",children:[(0,b.jsx)("span",{className:"h-2.5 w-2.5 rounded-full bg-red-400"}),(0,b.jsx)("span",{className:"h-2.5 w-2.5 rounded-full bg-yellow-400"}),(0,b.jsx)("span",{className:"h-2.5 w-2.5 rounded-full bg-green-400"})]}),(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0 text-slate-500 hover:bg-slate-100",type:"button",onClick:()=>b$("back"),disabled:!bg,title:"Go back","aria-label":"Go back",children:(0,b.jsx)(F.ArrowLeft,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0 text-slate-500 hover:bg-slate-100",type:"button",onClick:()=>b$("forward"),disabled:!bg,title:"Go forward","aria-label":"Go forward",children:(0,b.jsx)(G,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("button",{className:"btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0 text-slate-500 hover:bg-slate-100",type:"button",onClick:()=>b$("reload"),disabled:!bg,title:"Reload preview","aria-label":"Reload preview",children:(0,b.jsx)(H,{className:"h-3.5 w-3.5"})}),(0,b.jsx)("input",{ref:al,type:"text",className:"input input-xs h-7 min-h-7 w-full border-slate-200 bg-slate-100 font-mono text-slate-700",value:be,onChange:a=>bf(a.target.value),placeholder:"http://127.0.0.1:3000",spellCheck:!1}),(0,b.jsx)("button",{className:`btn btn-ghost btn-xs h-7 min-h-7 w-7 p-0 ${bi?"text-success":"text-slate-500"} hover:bg-slate-100`,type:"button",onClick:bY,disabled:!bg||bk,title:bi?"Disable picker":"Pick element from preview",children:bk?(0,b.jsx)("span",{className:"loading loading-spinner loading-xs w-3 h-3"}):(0,b.jsx)(E,{className:"h-3 w-3"})}),(0,b.jsxs)("button",{className:"btn btn-xs h-7 min-h-7 gap-1 border-slate-200 bg-white text-slate-700 hover:bg-slate-50",type:"button",onClick:b1,children:[(0,b.jsx)(r.ExternalLink,{className:"h-3.5 w-3.5"}),"Open in new tab"]})]}),(0,b.jsx)("div",{className:"min-h-0 flex-1 bg-slate-50",children:bc?bg?(0,b.jsx)("iframe",{ref:ak,src:bg,className:`h-full w-full border-none ${bu||bo?"pointer-events-none":""}`,title:"Dev server preview",onLoad:b_,sandbox:"allow-forms allow-modals allow-pointer-lock allow-popups allow-same-origin allow-scripts allow-downloads"}):(0,b.jsx)("div",{className:"flex h-full items-center justify-center px-6 text-center text-xs text-slate-500",children:"Run the dev server, or enter a URL above to load a preview."}):(0,b.jsxs)("div",{className:"flex h-full flex-col items-center justify-center gap-3 px-6 text-center text-xs text-slate-500",children:[(0,b.jsx)("p",{children:"Preview is hidden. Use the header Preview button to show it."}),(0,b.jsx)("button",{type:"button",className:"btn btn-xs border-slate-200 bg-white text-slate-700 hover:bg-slate-50",onClick:()=>bd(!0),children:"Show Preview"})]})})]}),!bq&&(0,b.jsx)("div",{className:"flex h-2 cursor-row-resize items-center justify-center border-y border-slate-200 bg-slate-100",onMouseDown:a=>{a.preventDefault(),a.stopPropagation(),bv(!0),by.current={startX:a.clientX,startY:a.clientY,startWidth:bs.width,startHeight:bs.height}},role:"separator","aria-orientation":"horizontal","aria-label":"Resize build output panel",title:"Drag to resize build output panel",children:(0,b.jsx)(B,{className:"h-3 w-3 text-slate-400"})}),(0,b.jsxs)("div",{className:`${bq?"h-10":"min-h-[160px]"} flex shrink-0 flex-col bg-slate-50`,style:{height:bq?40:bs.height},children:[(0,b.jsxs)("button",{className:"flex h-10 w-full items-center justify-between border-t border-slate-200 px-3 text-xs font-semibold text-slate-700 hover:bg-slate-100",onClick:()=>br(a=>!a),title:bq?"Expand terminal":"Collapse terminal",type:"button",children:[(0,b.jsxs)("span",{className:"flex items-center gap-2",children:[(0,b.jsx)("span",{className:"h-2 w-2 rounded-full bg-amber-500"}),"Terminal"]}),(0,b.jsx)(C.ChevronDown,{className:`h-4 w-4 transition-transform ${bq?"rotate-180":""}`})]}),(0,b.jsx)("div",{className:`${bq?"h-0 overflow-hidden":"min-h-0 flex-1 overflow-hidden border-t border-slate-200 bg-white"}`,children:(0,b.jsx)("iframe",{ref:aj,src:at,className:`h-full w-full border-none dark:invert dark:brightness-90 ${bu||bo?"pointer-events-none":""}`,allow:"clipboard-read; clipboard-write",onLoad:()=>{if(!aj.current)return;let b=aj.current;aG(),aS(!1);try{b.contentWindow}catch(a){console.error("Secondary terminal: Cross-Origin access blocked.");return}b.contentWindow&&(b.contentWindow.onbeforeunload=null,b.contentWindow.addEventListener("beforeunload",a=>{a.stopImmediatePropagation()},!0));let c=(e=0)=>{if(!(e>30))try{let f=b.contentWindow;if(f&&f.term){let g;bI("terminal");let h=f.term;b0(b,ap,{onLinkActivated:()=>br(!0),directOpenBehavior:"preview",modifierOpenBehavior:"new_tab"});try{h.options.theme={...h.options.theme||{},selectionBackground:"rgba(59, 130, 246, 0.4)"}}catch{}aH(b,h);try{let a=()=>{let a=h.buffer?.active,b="number"==typeof a?.baseY?a.baseY:0;"number"==typeof a?.viewportY&&a.viewportY,h.scrollToBottom?.()};if("function"==typeof h.onWriteParsed)h.onWriteParsed(a);else{let c=b.contentDocument?.querySelector(".xterm-screen")||b.contentDocument?.body;c&&new MutationObserver(a).observe(c,{childList:!0,subtree:!0,characterData:!0})}}catch(a){console.error("Failed to setup auto-scroll:",a)}let i=aB("terminal"),j=!!R&&"tmux"===S;if(i||j){j&&!i&&aE("terminal"),i&&aI(b,f,h),f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}if(!aF(h)&&e<10)return void setTimeout(()=>c(e+1),200);if(!aC("terminal")){f.focus();let a=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");a&&a.focus();return}let k=d||a,l=`cd ${_(k)}`;h.paste(l),(g=b.contentDocument?.querySelector("textarea.xterm-helper-textarea"))?g.dispatchEvent(new KeyboardEvent("keypress",{bubbles:!0,cancelable:!0,charCode:13,keyCode:13,key:"Enter",view:f})):h.paste("\r"),aE("terminal"),aI(b,f,h),f.focus();let m=b.contentDocument?.querySelector("textarea.xterm-helper-textarea");m&&m.focus()}else setTimeout(()=>c(e+1),500)}catch(a){aS(!1),aD("terminal"),console.error("Secondary terminal injection error",a)}};setTimeout(()=>c(),1e3)}})})]})]})]}),aX&&(0,b.jsx)(X,{initialPath:aZ,worktreePath:d,onPathChange:a$,onConfirm:a=>{aY(!1),bN(a)},onCancel:()=>aY(!1)})]})}let aj=(0,e.createServerReference)("40355953a8b2de3e711b19416fcf659c2714e9e723",e.callServer,void 0,e.findSourceMapURL,"consumeSessionLaunchContext"),ak=(0,e.createServerReference)("40dc1f944125634f49d9fdb157ce0b44be8eb55861",e.callServer,void 0,e.findSourceMapURL,"getSessionMetadata"),al=(0,e.createServerReference)("4061eab763827ebd637e07e577eb44792f0462b063",e.callServer,void 0,e.findSourceMapURL,"markSessionInitialized"),am=(0,e.createServerReference)("7f42709c2b4f654b0196e1662b6a55f5b254eb5760",e.callServer,void 0,e.findSourceMapURL,"getSessionTerminalSources");var an=a.i(75170);function ao(){let a=(0,d.useParams)().sessionId,e=Array.isArray(a)?a[0]:a,f=(0,d.useRouter)(),[g,h]=(0,c.useState)(null),[i,j]=(0,c.useState)(!0),[k,l]=(0,c.useState)(null),[m,n]=(0,c.useState)(null),[o,p]=(0,c.useState)(void 0),[q,r]=(0,c.useState)(void 0),[s,t]=(0,c.useState)(void 0),[u,v]=(0,c.useState)(void 0),[w,x]=(0,c.useState)(void 0),[y,z]=(0,c.useState)([]),[A,B]=(0,c.useState)(!0),[C,D]=(0,c.useState)("shell"),E=(0,c.useCallback)(()=>{if(!e)return;window.focus();let a=`/session/${e}`;window.location.pathname!==a&&f.push(a)},[f,e]);(0,c.useEffect)(()=>(document.documentElement.classList.add("session-page"),()=>{document.documentElement.classList.remove("session-page")}),[]),(0,c.useEffect)(()=>{if(!e)return;let a=!1,b=null,c=null,d=0,f=null,g=()=>{null!==c&&(window.clearTimeout(c),c=null)},h=()=>{if(a)return;let b=Math.min(1e4,1e3*2**d);d+=1,c=window.setTimeout(()=>{c=null,j()},b)},i=async a=>{if(!("Notification"in window))return;let b=Notification.permission;"default"===b&&(b=await Notification.requestPermission()),"granted"===b&&(f&&f.close(),(f=new Notification(a.title,{body:a.description,tag:`viba-session-notification-${a.sessionId}`})).onclick=a=>{a.preventDefault(),E(),f?.close()})},j=async()=>{try{let c=await fetch(`/api/notifications/socket?sessionId=${encodeURIComponent(e)}`,{cache:"no-store"});if(!c.ok)throw Error("Failed to initialize notification socket");let f=await c.json();if(!f.wsUrl)throw Error("Notification socket URL missing");if(a)return;(b=new WebSocket(f.wsUrl)).onopen=()=>{d=0,g()},b.onerror=()=>{b?.close()},b.onclose=()=>{a||h()},b.onmessage=a=>{try{let b=JSON.parse(a.data);if("session-notification"!==b.type||b.sessionId!==e||"string"!=typeof b.title||!b.title.trim()||"string"!=typeof b.description||!b.description.trim()||"string"!=typeof b.timestamp)return;i(b)}catch{}}}catch{h()}};return j(),()=>{a=!0,g(),b?.close(),f?.close()}},[E,e]),(0,c.useEffect)(()=>{e&&(async()=>{try{n(null);let a=await (0,an.startTtydProcess)();if(!a.success){l("Failed to start terminal service"),j(!1);return}D("tmux"===a.persistenceMode?"tmux":"shell");let b=await ak(e);if(!b){l("Session not found"),j(!1);return}h(b);let c=await am(b.sessionName,b.repoPath,b.agent);if(n(c),!1===b.initialized){let a=await aj(e);if(a.success&&a.context){let b=a.context;p(b.initialMessage),r(b.startupScript),t(b.title),v(b.agentProvider),x(b.sessionMode),z(b.attachmentNames||[])}B(!1)}else B(!0);j(!1)}catch(a){console.error("Failed to load session:",a),l("Failed to load session"),j(!1)}})()},[e]);let F=a=>{a?window.location.href="/":f.push("/")},G=async()=>{e&&await al(e)};return i?(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,b.jsx)("span",{className:"loading loading-spinner loading-lg text-primary"}),(0,b.jsx)("p",{className:"opacity-60",children:"Loading session..."})]})}):k||!g?(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsx)("div",{className:"card w-96 bg-base-200 shadow-xl",children:(0,b.jsxs)("div",{className:"card-body items-center text-center",children:[(0,b.jsx)("h2",{className:"card-title text-error",children:"Error"}),(0,b.jsx)("p",{children:k||"Session not found"}),(0,b.jsx)("div",{className:"card-actions justify-end",children:(0,b.jsx)("button",{className:"btn btn-primary",onClick:()=>F(),children:"Back to Home"})})]})})}):m?(0,b.jsx)(ai,{repo:g.repoPath,worktree:g.worktreePath,branch:g.branchName,baseBranch:g.baseBranch,sessionName:g.sessionName,agent:u||g.agent,startupScript:q,devServerScript:g.devServerScript,initialMessage:o,attachmentNames:y,title:s||g.title,sessionMode:w,onExit:F,isResume:A,terminalPersistenceMode:C,onSessionStart:G,agentTerminalSrc:m.agentTerminalSrc,floatingTerminalSrc:m.floatingTerminalSrc}):(0,b.jsx)("div",{className:"flex h-screen w-full items-center justify-center bg-base-100",children:(0,b.jsxs)("div",{className:"flex flex-col items-center gap-4",children:[(0,b.jsx)("span",{className:"loading loading-spinner loading-lg text-primary"}),(0,b.jsx)("p",{className:"opacity-60",children:"Initializing terminals..."})]})})}a.s(["default",()=>ao],96614)}];
2
2
 
3
3
  //# sourceMappingURL=src_app_session_%5BsessionId%5D_SessionPageClient_tsx_dab490d7._.js.map