@lovelybunch/api 1.0.71-alpha.4 → 1.0.71-alpha.6

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 (97) hide show
  1. package/dist/routes/api/v1/context/images/index.d.ts +2 -0
  2. package/dist/routes/api/v1/context/images/index.js +2 -0
  3. package/dist/routes/api/v1/context/images/route.d.ts +3 -0
  4. package/dist/routes/api/v1/context/images/route.js +253 -0
  5. package/dist/routes/api/v1/context/index.js +2 -0
  6. package/dist/routes/api/v1/resources/generate-audio/index.d.ts +3 -0
  7. package/dist/routes/api/v1/resources/generate-audio/index.js +5 -0
  8. package/dist/routes/api/v1/resources/generate-audio/route.d.ts +19 -0
  9. package/dist/routes/api/v1/resources/generate-audio/route.js +129 -0
  10. package/dist/routes/api/v1/resources/generate-video/index.d.ts +3 -0
  11. package/dist/routes/api/v1/resources/generate-video/index.js +5 -0
  12. package/dist/routes/api/v1/resources/generate-video/route.d.ts +19 -0
  13. package/dist/routes/api/v1/resources/generate-video/route.js +235 -0
  14. package/dist/routes/api/v1/resources/index.js +4 -0
  15. package/dist/routes/api/v1/resources/route.js +3 -3
  16. package/package.json +4 -4
  17. package/static/assets/{AgentDetailPage-BkWRFbPj.js → AgentDetailPage-Bw8wHgla.js} +1 -1
  18. package/static/assets/{AgentEditPage-DN0TouUG.js → AgentEditPage-CQ9Y3ez8.js} +1 -1
  19. package/static/assets/{AgentsPage-DW6eV7oU.js → AgentsPage-DcgU1MPa.js} +1 -1
  20. package/static/assets/{AgentsSettingsPage-BJKnn0R0.js → AgentsSettingsPage-CgoXxqGL.js} +1 -1
  21. package/static/assets/{ApiKeysSettingsPage-ChFu9Eo6.js → ApiKeysSettingsPage-BgqGOa4p.js} +3 -3
  22. package/static/assets/{ArchitectureEditPage-DWrvSS5U.js → ArchitectureEditPage-DrEnTloL.js} +1 -1
  23. package/static/assets/{ArchitecturePage-BdQG779E.js → ArchitecturePage-Dpd6cyyT.js} +1 -1
  24. package/static/assets/{AuthSettingsPage-BXMn4xXd.js → AuthSettingsPage-wu1zFEx-.js} +2 -2
  25. package/static/assets/{CallbackPage-AxQqTxCV.js → CallbackPage-DYzikcPp.js} +1 -1
  26. package/static/assets/{CodePage-CfKZ52Zo.js → CodePage-CtM-PEHU.js} +1 -1
  27. package/static/assets/{CollapsibleSection-ZFq6LSXW.js → CollapsibleSection-B23j-nZD.js} +1 -1
  28. package/static/assets/{DashboardPage-Df-d3-fG.js → DashboardPage-BoPCq6M9.js} +1 -1
  29. package/static/assets/{GitPage-DAWR8rrg.js → GitPage-DYicFQBx.js} +1 -1
  30. package/static/assets/{GitSettingsPage-CzGuiY9j.js → GitSettingsPage-B-1Nnid8.js} +2 -2
  31. package/static/assets/{IdentityPage-DbsNwWtP.js → IdentityPage-Cvj6SDPj.js} +2 -2
  32. package/static/assets/{ImplementationStepsEditor-DZq7KcDP.js → ImplementationStepsEditor-CCfJKk2U.js} +1 -1
  33. package/static/assets/{IntegrationsSettingsPage-qvvsp1_G.js → IntegrationsSettingsPage-BgLXCF-u.js} +1 -1
  34. package/static/assets/{KnowledgeDetailPage-BMnj1qiH.js → KnowledgeDetailPage-I9erHJXN.js} +1 -1
  35. package/static/assets/{KnowledgeEditPage-BZa4E2M9.js → KnowledgeEditPage-BfaWotPl.js} +1 -1
  36. package/static/assets/{KnowledgePage-Dtq9BKZi.js → KnowledgePage-x9ShzjoT.js} +2 -2
  37. package/static/assets/{LoginPage-BnlCd8Cm.js → LoginPage-CZtwhbdN.js} +1 -1
  38. package/static/assets/{McpSettingsPage-COPMqimV.js → McpSettingsPage-BHPjMqOX.js} +1 -1
  39. package/static/assets/{NewAgentPage-Dtvey1oU.js → NewAgentPage-D-Pj_KgZ.js} +1 -1
  40. package/static/assets/{NewKnowledgePage-CbiRD2V3.js → NewKnowledgePage-CoVnCUx6.js} +1 -1
  41. package/static/assets/{NewProposalPage-B1tUJIZz.js → NewProposalPage-nCTq2mBC.js} +1 -1
  42. package/static/assets/{ProjectEditPage-CwM8LXHy.js → ProjectEditPage-d1cMZArt.js} +1 -1
  43. package/static/assets/{ProjectPage-BHa8M3vI.js → ProjectPage-KwwOjk5b.js} +1 -1
  44. package/static/assets/{PromptsSettingsPage-CwGmsIAW.js → PromptsSettingsPage-fSs6HBAk.js} +1 -1
  45. package/static/assets/{ProposalDetailPage-DC7NMuFi.js → ProposalDetailPage-BnLOBPPT.js} +1 -1
  46. package/static/assets/{ProposalEditPage-CfUidv6D.js → ProposalEditPage-bIYTFTmG.js} +1 -1
  47. package/static/assets/{ProposalsPage-V8ut_TsU.js → ProposalsPage-D8W2d6g6.js} +1 -1
  48. package/static/assets/ResourcesPage-Dq9DZFd7.js +71 -0
  49. package/static/assets/{RulesSettingsPage-BJ72X2Y3.js → RulesSettingsPage-SWRxKVNH.js} +1 -1
  50. package/static/assets/{SchedulePage-DBYxTZMb.js → SchedulePage-DGxD8ZaL.js} +1 -1
  51. package/static/assets/{TagInput-Cqju3cXZ.js → TagInput-CYcNHzrk.js} +1 -1
  52. package/static/assets/{TerminalPage-Iow1ciWG.js → TerminalPage-fabajZvk.js} +1 -1
  53. package/static/assets/{TerminalSessionPage-CZdzhFhY.js → TerminalSessionPage-DuJsKT9f.js} +1 -1
  54. package/static/assets/{UserPreferencesPage-CAuJ7yO4.js → UserPreferencesPage-DQMtobsK.js} +1 -1
  55. package/static/assets/{UserSettingsPage-0j7ha-RI.js → UserSettingsPage-CFEb7pD0.js} +1 -1
  56. package/static/assets/{UtilitiesPage-OgkcmaOS.js → UtilitiesPage-qStPGLN_.js} +1 -1
  57. package/static/assets/{alert-D2VTq6m-.js → alert-Baaj8mli.js} +1 -1
  58. package/static/assets/{arrow-down-vmWOjyjO.js → arrow-down-CSpiROUo.js} +1 -1
  59. package/static/assets/{arrow-left-Do2jUSS9.js → arrow-left-CdJt7_wH.js} +1 -1
  60. package/static/assets/{arrow-up-hMM1cdZm.js → arrow-up-ugn3lusK.js} +1 -1
  61. package/static/assets/{badge-D7ZZbMEG.js → badge-fHjW-wEe.js} +1 -1
  62. package/static/assets/{browser-modal-CWDhylx7.js → browser-modal-D6BB5mxm.js} +1 -1
  63. package/static/assets/{calendar-C5JtKp_F.js → calendar-DXMWQL-h.js} +1 -1
  64. package/static/assets/{card-D_zGBKua.js → card-C9ekeZtD.js} +1 -1
  65. package/static/assets/{chevron-left-JjvWea8A.js → chevron-left-BkP_F3xd.js} +1 -1
  66. package/static/assets/{circle-alert-DQD0CPB3.js → circle-alert-DnIYekt3.js} +1 -1
  67. package/static/assets/{circle-check-xj41FKuF.js → circle-check-BO-qmBFl.js} +1 -1
  68. package/static/assets/{circle-check-big-KfJvKA9H.js → circle-check-big-BUVglreY.js} +1 -1
  69. package/static/assets/{circle-play-BlGnYWUU.js → circle-play-84ZOWBDG.js} +1 -1
  70. package/static/assets/{circle-x-Ds97aY1x.js → circle-x-EQNlLpRR.js} +1 -1
  71. package/static/assets/{clipboard-D3NA8gb4.js → clipboard-Dv0iwZO9.js} +1 -1
  72. package/static/assets/{clock-9dU_D6sL.js → clock-BxO7xcX9.js} +1 -1
  73. package/static/assets/{download-CNckZYWh.js → download-CpaVC4DU.js} +1 -1
  74. package/static/assets/{eye-Dp6wEoME.js → eye-BSR7OEmk.js} +1 -1
  75. package/static/assets/{folder-git-2-B9ILjFN2.js → folder-git-2-9fWvFiHp.js} +1 -1
  76. package/static/assets/index-BAEEeZzi.js +458 -0
  77. package/static/assets/index-DdGUrKz8.css +2 -0
  78. package/static/assets/label-CRsu1MwQ.js +1 -0
  79. package/static/assets/{markdown-editor-BiM9h5iI.js → markdown-editor-Dop22vuJ.js} +1 -1
  80. package/static/assets/{pause-BNL49HvB.js → pause-C7KYrzQF.js} +1 -1
  81. package/static/assets/{play-8b83f5X0.js → play-DhUf2mKM.js} +1 -1
  82. package/static/assets/{plus-Be79gWKj.js → plus-CemYz5Fm.js} +1 -1
  83. package/static/assets/radio-group-Dz2cO4IQ.js +1 -0
  84. package/static/assets/{refresh-cw-C0_Ot2Zc.js → refresh-cw-BL3y7jJo.js} +1 -1
  85. package/static/assets/{search-CrIdR7ah.js → search-BvRo_rak.js} +1 -1
  86. package/static/assets/{switch-BYPAX9oF.js → switch-CDOrVL8G.js} +1 -1
  87. package/static/assets/{tabs-Ug7Ug5Ha.js → tabs-CP_A6r0A.js} +1 -1
  88. package/static/assets/{tag-BgO5mxYK.js → tag-BpNIhvRX.js} +1 -1
  89. package/static/assets/{terminal-preview-CDrLQbSE.js → terminal-preview-CbgoHEQH.js} +1 -1
  90. package/static/assets/{use-terminal-CNk4WtA6.js → use-terminal-ZvK-kdxE.js} +1 -1
  91. package/static/assets/{zap-cD8GAJPg.js → zap-DOtH7YrV.js} +1 -1
  92. package/static/index.html +2 -2
  93. package/static/assets/ResourcesPage-Cofgbx3H.js +0 -66
  94. package/static/assets/index-Bbxvuj4b.js +0 -458
  95. package/static/assets/index-Ca98xZVe.css +0 -2
  96. package/static/assets/label-CZGCmBD7.js +0 -1
  97. package/static/assets/radio-group-DpxssBzw.js +0 -1
@@ -1 +1 @@
1
- import{r as m,j as e,n as x,A as f}from"./index-Bbxvuj4b.js";import{C as w}from"./circle-check-xj41FKuF.js";import{C as b}from"./circle-x-Ds97aY1x.js";const r="coconut/github-auth-state";function j(s){try{window.opener&&window.opener.postMessage({type:"github-auth",...s},window.location.origin)}catch{}}const v=()=>{const[s,d]=m.useState("pending"),[h,p]=m.useState("Authorizing GitHub…");return m.useEffect(()=>{const a=new URLSearchParams(window.location.search),u=a.get("error"),l=a.get("token"),n=a.get("expires_at")||a.get("expiresAt"),c=a.get("state"),o=t=>{j(t),d(t.success?"success":"error"),p(t.message),setTimeout(()=>{try{window.close()}catch{}},1200)};if(u){localStorage.removeItem(r),o({success:!1,message:decodeURIComponent(u)});return}if(!l||!n||!c){localStorage.removeItem(r),o({success:!1,message:"Missing authorization parameters. Please try again."});return}const g=localStorage.getItem(r);if(!g||g!==c){localStorage.removeItem(r),o({success:!1,message:"Authorization state mismatch. Please start again."});return}(async()=>{try{const t=await fetch(`${f}/api/v1/git/providers/github/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:l,expiresAt:n,state:c})}),i=await t.json();if(!t.ok||!i.success)throw new Error(i?.error?.message||"Failed to store GitHub token");localStorage.removeItem(r),o({success:!0,message:"GitHub connected successfully!",expiresAt:i.data?.expiresAt||n})}catch(t){localStorage.removeItem(r),o({success:!1,message:t?.message||"Failed to store GitHub token. Please try again."})}})()},[]),e.jsx("div",{className:"flex h-screen items-center justify-center bg-background px-6",children:e.jsxs("div",{className:"max-w-sm rounded-lg border bg-card p-6 text-center shadow-sm",children:[e.jsxs("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:[s==="pending"&&e.jsx(x,{className:"h-6 w-6 animate-spin text-muted-foreground"}),s==="success"&&e.jsx(w,{className:"h-6 w-6 text-green-600"}),s==="error"&&e.jsx(b,{className:"h-6 w-6 text-red-600"})]}),e.jsx("h1",{className:"text-lg font-semibold",children:"GitHub Authorization"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:h}),s!=="pending"&&e.jsx("p",{className:"mt-4 text-xs text-muted-foreground",children:"You can close this window and return to Coconut."})]})})};export{v as default};
1
+ import{r as m,j as e,n as x,A as f}from"./index-BAEEeZzi.js";import{C as w}from"./circle-check-BO-qmBFl.js";import{C as b}from"./circle-x-EQNlLpRR.js";const r="coconut/github-auth-state";function j(s){try{window.opener&&window.opener.postMessage({type:"github-auth",...s},window.location.origin)}catch{}}const v=()=>{const[s,d]=m.useState("pending"),[h,p]=m.useState("Authorizing GitHub…");return m.useEffect(()=>{const a=new URLSearchParams(window.location.search),u=a.get("error"),l=a.get("token"),n=a.get("expires_at")||a.get("expiresAt"),c=a.get("state"),o=t=>{j(t),d(t.success?"success":"error"),p(t.message),setTimeout(()=>{try{window.close()}catch{}},1200)};if(u){localStorage.removeItem(r),o({success:!1,message:decodeURIComponent(u)});return}if(!l||!n||!c){localStorage.removeItem(r),o({success:!1,message:"Missing authorization parameters. Please try again."});return}const g=localStorage.getItem(r);if(!g||g!==c){localStorage.removeItem(r),o({success:!1,message:"Authorization state mismatch. Please start again."});return}(async()=>{try{const t=await fetch(`${f}/api/v1/git/providers/github/token`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({token:l,expiresAt:n,state:c})}),i=await t.json();if(!t.ok||!i.success)throw new Error(i?.error?.message||"Failed to store GitHub token");localStorage.removeItem(r),o({success:!0,message:"GitHub connected successfully!",expiresAt:i.data?.expiresAt||n})}catch(t){localStorage.removeItem(r),o({success:!1,message:t?.message||"Failed to store GitHub token. Please try again."})}})()},[]),e.jsx("div",{className:"flex h-screen items-center justify-center bg-background px-6",children:e.jsxs("div",{className:"max-w-sm rounded-lg border bg-card p-6 text-center shadow-sm",children:[e.jsxs("div",{className:"mx-auto mb-4 flex h-12 w-12 items-center justify-center rounded-full bg-muted",children:[s==="pending"&&e.jsx(x,{className:"h-6 w-6 animate-spin text-muted-foreground"}),s==="success"&&e.jsx(w,{className:"h-6 w-6 text-green-600"}),s==="error"&&e.jsx(b,{className:"h-6 w-6 text-red-600"})]}),e.jsx("h1",{className:"text-lg font-semibold",children:"GitHub Authorization"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:h}),s!=="pending"&&e.jsx("p",{className:"mt-4 text-xs text-muted-foreground",children:"You can close this window and return to Coconut."})]})})};export{v as default};
@@ -1,2 +1,2 @@
1
- import{u as ce,H as de,r as i,j as e,B as r,k as oe,a3 as me,q as xe,s as M,X as he,g as ue,J as fe,D as ge,a as je,b as pe,d as ve,v as Ne,w as ye,x as we,y as Ce,z as S,i as Se,a5 as R,a6 as B,a7 as H,a8 as L,a9 as O,ae as G,h as be,a0 as Ae,A as I}from"./index-Bbxvuj4b.js";import{C as p,b as ke,a as _,c as De}from"./card-D_zGBKua.js";import{B as U}from"./badge-D7ZZbMEG.js";import{u as Me}from"./use-terminal-CNk4WtA6.js";import{C as Ie,a as $e,T as Pe}from"./terminal-preview-CDrLQbSE.js";import{b as Te,d as Ee,c as ze,a as Fe}from"./droid-CmYuCN_q.js";import{R as Re}from"./refresh-cw-C0_Ot2Zc.js";import{P as Be}from"./play-8b83f5X0.js";import"./xterm-DTxiCjtJ.js";const He=c=>c?Array.isArray(c)?c.filter(x=>typeof x=="string").map(x=>x.trim()).filter(Boolean):typeof c=="string"?c.split(",").map(x=>x.trim()).filter(Boolean):[]:[];function Xe(){const c=ce(),{sessions:x,loading:b,error:$,refreshSessions:w,createSession:V,destroySession:q}=Me(),{toast:v}=de(),[P,W]=i.useState([]),[J,X]=i.useState(!0),[g,A]=i.useState(()=>({})),[k,N]=i.useState(!1),[j,K]=i.useState("claude"),[T,Q]=i.useState(""),[D,E]=i.useState(!1),[h,Y]=i.useState([]),[f,y]=i.useState([]),[Z,ee]=i.useState({}),[u,se]=i.useState([]),[o,C]=i.useState([]),te=s=>{const t=Date.now(),a=new Date(s).getTime(),n=Math.max(0,Math.floor((t-a)/1e3));if(n<60)return`${n}s ago`;const d=Math.floor(n/60);if(d<60)return`${d}m ago`;const l=Math.floor(d/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`};i.useEffect(()=>{(async()=>{try{const t=await fetch(`${I}/api/v1/proposals`);if(t.ok){const a=await t.json(),n=a.data||a;W(Array.isArray(n)?n:[])}}catch(t){console.error("Error loading proposals:",t)}finally{X(!1)}})()},[]),i.useEffect(()=>{w()},[w]),i.useEffect(()=>{if(!k)return;(async()=>{try{const t=await fetch(`${I}/api/v1/mcp`);if(t.ok){const a=await t.json();a?.success&&Array.isArray(a.servers)&&(Y(a.servers),y(n=>n.filter(d=>a.servers.includes(d))),a.mcpServers&&typeof a.mcpServers=="object"&&ee(a.mcpServers))}}catch(t){console.error("Failed to load MCP servers",t)}try{const t=await fetch(`${I}/api/v1/agents`);if(t.ok){const a=await t.json(),d=(Array.isArray(a?.documents)?a.documents:[]).map(l=>({id:l.filename,name:l?.metadata?.name||l.title||l.filename,tools:He(l?.metadata?.tools)}));se(d),C(l=>l.filter(F=>d.some(re=>re.id===F)))}}catch(t){console.error("Failed to load agents",t)}})()},[k]),i.useEffect(()=>{o.length!==0&&y(s=>{const t=new Set(s),a=h.length>0?new Set(h):void 0;return o.forEach(n=>{const d=u.find(l=>l.id===n);d&&d.tools.forEach(l=>{(!a||a.has(l))&&t.add(l)})}),Array.from(t)})},[o,u,h]);const m=i.useMemo(()=>x.filter(s=>s.proposalId?.startsWith("cp-")||s.proposalId?.startsWith("ag-")).sort((s,t)=>new Date(t.lastActivity).getTime()-new Date(s.lastActivity).getTime()),[x]);i.useEffect(()=>{A(s=>{const t={...s};return m.forEach(a=>{a.id in t||(t[a.id]=!0)}),t})},[m]);const z=i.useMemo(()=>P.filter(s=>s.status==="draft"||s.status==="approved").sort((s,t)=>new Date(t.metadata.createdAt).getTime()-new Date(s.metadata.createdAt).getTime()).slice(0,3),[P]),ae=()=>{const s=m.every(a=>g[a.id]),t={};m.forEach(a=>{t[a.id]=!s}),A(t)},ie=m.length>0&&m.every(s=>g[s.id]),ne=async s=>{await q(s)?(v({title:"Session closed",description:s}),setTimeout(()=>w(),100)):v({title:"Failed to close session",description:s,variant:"destructive"})},le=async()=>{E(!0);try{const s=`cp-${Date.now()}`,t={proposalId:s,contextType:"change-proposal",cliAgent:j,mcpServersMap:Z,selectedMcpServers:f,agents:u,selectedAgentIds:o,automationEnabled:!1,customInstruction:T.trim(),includeDefaultInstructions:!1};let a="";j==="claude"?a=Te(t):j==="gemini"?a=Ee(t):j==="codex"?a=ze(t):j==="droid"&&(a=Fe(t)),await V(s,!1,a)?(v({title:"Coding session started",description:`Session ${s} created`}),N(!1),c(`/terminal/${s}`)):v({title:"Failed to start session",description:"Could not create terminal session",variant:"destructive"})}catch(s){console.error("Error starting coding session:",s),v({title:"Error",description:"Failed to start coding session",variant:"destructive"})}finally{E(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Code"}),e.jsx("p",{className:"text-muted-foreground hidden sm:block",children:"Terminal sessions and coding agents"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>w(),disabled:b,children:[e.jsx(Re,{className:`h-4 w-4 sm:mr-2 ${b?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),m.length>0&&e.jsx(r,{variant:"outline",size:"sm",onClick:ae,children:ie?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Hide All"})]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Show All"})]})}),e.jsxs(r,{size:"sm",onClick:()=>N(!0),children:[e.jsx(Be,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Interactive Session"})]})]})]}),$&&e.jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsx("div",{className:"text-red-600",children:$})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Sessions"}),b?e.jsx("div",{className:"space-y-2",children:[...Array(2)].map((s,t)=>e.jsx(p,{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-4 w-4 rounded bg-muted animate-pulse"}),e.jsxs("div",{children:[e.jsx("div",{className:"h-4 w-40 bg-muted rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-3 w-24 bg-muted rounded animate-pulse"})]})]}),e.jsx("div",{className:"h-6 w-20 bg-muted rounded animate-pulse"})]})},t))}):m.length===0?e.jsx(p,{className:"p-8",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsx(oe,{className:"h-12 w-12 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg mb-2",children:"No active sessions"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Get started by launching an"," ",e.jsx("button",{onClick:()=>N(!0),className:"text-primary hover:underline font-medium",children:"Interactive Session"})," ","or working on a"," ",e.jsx("button",{onClick:()=>c("/proposals"),className:"text-primary hover:underline font-medium",children:"Change Proposal"})]})]})]})}):e.jsx("div",{className:"space-y-2",children:m.slice(0,10).map(s=>e.jsxs(p,{className:"p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(me,{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-sm",children:s.proposalId}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Session ",s.id.split("-").slice(-1)[0].substring(0,8)," • Last activity ",te(s.lastActivity)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("div",{className:`flex items-center gap-1 ${s.connected?"text-green-600":"text-gray-400"}`,title:s.connected?"Connected":"Disconnected",children:e.jsx("div",{className:`w-2 h-2 rounded-full ${s.connected?"bg-green-500":"bg-gray-400"}`})}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>{A(t=>({...t,[s.id]:!t[s.id]}))},"aria-label":g[s.id]?"Hide preview":"Show preview",title:g[s.id]?"Hide preview":"Show preview",children:g[s.id]?e.jsx(xe,{className:"h-4 w-4"}):e.jsx(M,{className:"h-4 w-4"})}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>c(`/terminal/${s.proposalId}`),children:"Open"}),e.jsx(r,{size:"icon",variant:"destructive",onClick:()=>ne(s.id),title:"Close session","aria-label":"Close session",children:e.jsx(he,{className:"h-4 w-4"})})]})]}),g[s.id]&&e.jsx("div",{className:"mt-2 w-full p-2 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>c(`/terminal/${s.proposalId}`),title:"Click to open full terminal session",children:e.jsx(Pe,{sessionId:s.id,heightPx:160,maxScrollback:200})})]},s.id))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Recent Proposals"}),J?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((s,t)=>e.jsx(p,{children:e.jsx(ke,{className:"py-3",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-2/3 animate-pulse"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/3 animate-pulse"})]}),e.jsx("div",{className:"h-5 bg-muted rounded w-16 animate-pulse"})]})})},t))}):z.length===0?e.jsx(p,{children:e.jsx(_,{className:"flex items-center justify-center py-6",children:e.jsx("div",{className:"text-center text-sm text-gray-500",children:"No draft or approved proposals found"})})}):e.jsx("div",{className:"space-y-2",children:z.map(s=>e.jsx(p,{className:"hover:shadow-md transition-all cursor-pointer hover:border-primary/50",onClick:()=>c(`/terminal/${s.id}`),children:e.jsx(_,{className:"py-4",children:e.jsx("div",{className:"flex justify-between items-start gap-4",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(De,{className:"text-base leading-tight",children:s.intent}),e.jsxs("div",{className:"flex gap-1 ml-3 flex-shrink-0",children:[s.priority&&e.jsx(U,{variant:s.priority==="high"||s.priority==="critical"?"destructive":s.priority==="medium"?"secondary":"outline",className:"text-xs",children:s.priority}),e.jsx(U,{variant:"default",className:"text-xs",children:s.status})]})]}),s.content&&e.jsxs("div",{className:"text-sm text-muted-foreground leading-relaxed",children:[s.content.split(`
1
+ import{u as ce,H as de,r as i,j as e,B as r,k as oe,a3 as me,q as xe,s as M,X as he,g as ue,J as fe,D as ge,a as je,b as pe,d as ve,v as Ne,w as ye,x as we,y as Ce,z as S,i as Se,a5 as R,a6 as B,a7 as H,a8 as L,a9 as O,ae as G,h as be,a0 as Ae,A as I}from"./index-BAEEeZzi.js";import{C as p,b as ke,a as _,c as De}from"./card-C9ekeZtD.js";import{B as U}from"./badge-fHjW-wEe.js";import{u as Me}from"./use-terminal-ZvK-kdxE.js";import{C as Ie,a as $e,T as Pe}from"./terminal-preview-CbgoHEQH.js";import{b as Te,d as Ee,c as ze,a as Fe}from"./droid-CmYuCN_q.js";import{R as Re}from"./refresh-cw-BL3y7jJo.js";import{P as Be}from"./play-DhUf2mKM.js";import"./xterm-DTxiCjtJ.js";const He=c=>c?Array.isArray(c)?c.filter(x=>typeof x=="string").map(x=>x.trim()).filter(Boolean):typeof c=="string"?c.split(",").map(x=>x.trim()).filter(Boolean):[]:[];function Xe(){const c=ce(),{sessions:x,loading:b,error:$,refreshSessions:w,createSession:V,destroySession:q}=Me(),{toast:v}=de(),[P,W]=i.useState([]),[J,X]=i.useState(!0),[g,A]=i.useState(()=>({})),[k,N]=i.useState(!1),[j,K]=i.useState("claude"),[T,Q]=i.useState(""),[D,E]=i.useState(!1),[h,Y]=i.useState([]),[f,y]=i.useState([]),[Z,ee]=i.useState({}),[u,se]=i.useState([]),[o,C]=i.useState([]),te=s=>{const t=Date.now(),a=new Date(s).getTime(),n=Math.max(0,Math.floor((t-a)/1e3));if(n<60)return`${n}s ago`;const d=Math.floor(n/60);if(d<60)return`${d}m ago`;const l=Math.floor(d/60);return l<24?`${l}h ago`:`${Math.floor(l/24)}d ago`};i.useEffect(()=>{(async()=>{try{const t=await fetch(`${I}/api/v1/proposals`);if(t.ok){const a=await t.json(),n=a.data||a;W(Array.isArray(n)?n:[])}}catch(t){console.error("Error loading proposals:",t)}finally{X(!1)}})()},[]),i.useEffect(()=>{w()},[w]),i.useEffect(()=>{if(!k)return;(async()=>{try{const t=await fetch(`${I}/api/v1/mcp`);if(t.ok){const a=await t.json();a?.success&&Array.isArray(a.servers)&&(Y(a.servers),y(n=>n.filter(d=>a.servers.includes(d))),a.mcpServers&&typeof a.mcpServers=="object"&&ee(a.mcpServers))}}catch(t){console.error("Failed to load MCP servers",t)}try{const t=await fetch(`${I}/api/v1/agents`);if(t.ok){const a=await t.json(),d=(Array.isArray(a?.documents)?a.documents:[]).map(l=>({id:l.filename,name:l?.metadata?.name||l.title||l.filename,tools:He(l?.metadata?.tools)}));se(d),C(l=>l.filter(F=>d.some(re=>re.id===F)))}}catch(t){console.error("Failed to load agents",t)}})()},[k]),i.useEffect(()=>{o.length!==0&&y(s=>{const t=new Set(s),a=h.length>0?new Set(h):void 0;return o.forEach(n=>{const d=u.find(l=>l.id===n);d&&d.tools.forEach(l=>{(!a||a.has(l))&&t.add(l)})}),Array.from(t)})},[o,u,h]);const m=i.useMemo(()=>x.filter(s=>s.proposalId?.startsWith("cp-")||s.proposalId?.startsWith("ag-")).sort((s,t)=>new Date(t.lastActivity).getTime()-new Date(s.lastActivity).getTime()),[x]);i.useEffect(()=>{A(s=>{const t={...s};return m.forEach(a=>{a.id in t||(t[a.id]=!0)}),t})},[m]);const z=i.useMemo(()=>P.filter(s=>s.status==="draft"||s.status==="approved").sort((s,t)=>new Date(t.metadata.createdAt).getTime()-new Date(s.metadata.createdAt).getTime()).slice(0,3),[P]),ae=()=>{const s=m.every(a=>g[a.id]),t={};m.forEach(a=>{t[a.id]=!s}),A(t)},ie=m.length>0&&m.every(s=>g[s.id]),ne=async s=>{await q(s)?(v({title:"Session closed",description:s}),setTimeout(()=>w(),100)):v({title:"Failed to close session",description:s,variant:"destructive"})},le=async()=>{E(!0);try{const s=`cp-${Date.now()}`,t={proposalId:s,contextType:"change-proposal",cliAgent:j,mcpServersMap:Z,selectedMcpServers:f,agents:u,selectedAgentIds:o,automationEnabled:!1,customInstruction:T.trim(),includeDefaultInstructions:!1};let a="";j==="claude"?a=Te(t):j==="gemini"?a=Ee(t):j==="codex"?a=ze(t):j==="droid"&&(a=Fe(t)),await V(s,!1,a)?(v({title:"Coding session started",description:`Session ${s} created`}),N(!1),c(`/terminal/${s}`)):v({title:"Failed to start session",description:"Could not create terminal session",variant:"destructive"})}catch(s){console.error("Error starting coding session:",s),v({title:"Error",description:"Failed to start coding session",variant:"destructive"})}finally{E(!1)}};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-2xl font-bold tracking-tight",children:"Code"}),e.jsx("p",{className:"text-muted-foreground hidden sm:block",children:"Terminal sessions and coding agents"})]}),e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsxs(r,{variant:"outline",size:"sm",onClick:()=>w(),disabled:b,children:[e.jsx(Re,{className:`h-4 w-4 sm:mr-2 ${b?"animate-spin":""}`}),e.jsx("span",{className:"hidden sm:inline",children:"Refresh"})]}),m.length>0&&e.jsx(r,{variant:"outline",size:"sm",onClick:ae,children:ie?e.jsxs(e.Fragment,{children:[e.jsx(Ie,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Hide All"})]}):e.jsxs(e.Fragment,{children:[e.jsx($e,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Show All"})]})}),e.jsxs(r,{size:"sm",onClick:()=>N(!0),children:[e.jsx(Be,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Interactive Session"})]})]})]}),$&&e.jsx("div",{className:"p-4 bg-red-50 border border-red-200 rounded-lg",children:e.jsx("div",{className:"text-red-600",children:$})}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Sessions"}),b?e.jsx("div",{className:"space-y-2",children:[...Array(2)].map((s,t)=>e.jsx(p,{className:"p-3",children:e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:"h-4 w-4 rounded bg-muted animate-pulse"}),e.jsxs("div",{children:[e.jsx("div",{className:"h-4 w-40 bg-muted rounded animate-pulse mb-2"}),e.jsx("div",{className:"h-3 w-24 bg-muted rounded animate-pulse"})]})]}),e.jsx("div",{className:"h-6 w-20 bg-muted rounded animate-pulse"})]})},t))}):m.length===0?e.jsx(p,{className:"p-8",children:e.jsxs("div",{className:"flex flex-col items-center justify-center text-center space-y-3",children:[e.jsx(oe,{className:"h-12 w-12 text-muted-foreground"}),e.jsxs("div",{children:[e.jsx("h3",{className:"font-semibold text-lg mb-2",children:"No active sessions"}),e.jsxs("p",{className:"text-sm text-muted-foreground",children:["Get started by launching an"," ",e.jsx("button",{onClick:()=>N(!0),className:"text-primary hover:underline font-medium",children:"Interactive Session"})," ","or working on a"," ",e.jsx("button",{onClick:()=>c("/proposals"),className:"text-primary hover:underline font-medium",children:"Change Proposal"})]})]})]})}):e.jsx("div",{className:"space-y-2",children:m.slice(0,10).map(s=>e.jsxs(p,{className:"p-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx(me,{className:"h-4 w-4 shrink-0"}),e.jsxs("div",{className:"flex-1",children:[e.jsx("div",{className:"font-medium text-sm",children:s.proposalId}),e.jsxs("div",{className:"text-xs text-gray-500",children:["Session ",s.id.split("-").slice(-1)[0].substring(0,8)," • Last activity ",te(s.lastActivity)]})]})]}),e.jsxs("div",{className:"flex items-center gap-2 shrink-0",children:[e.jsx("div",{className:`flex items-center gap-1 ${s.connected?"text-green-600":"text-gray-400"}`,title:s.connected?"Connected":"Disconnected",children:e.jsx("div",{className:`w-2 h-2 rounded-full ${s.connected?"bg-green-500":"bg-gray-400"}`})}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>{A(t=>({...t,[s.id]:!t[s.id]}))},"aria-label":g[s.id]?"Hide preview":"Show preview",title:g[s.id]?"Hide preview":"Show preview",children:g[s.id]?e.jsx(xe,{className:"h-4 w-4"}):e.jsx(M,{className:"h-4 w-4"})}),e.jsx(r,{size:"sm",variant:"outline",onClick:()=>c(`/terminal/${s.proposalId}`),children:"Open"}),e.jsx(r,{size:"icon",variant:"destructive",onClick:()=>ne(s.id),title:"Close session","aria-label":"Close session",children:e.jsx(he,{className:"h-4 w-4"})})]})]}),g[s.id]&&e.jsx("div",{className:"mt-2 w-full p-2 cursor-pointer hover:opacity-80 transition-opacity",onClick:()=>c(`/terminal/${s.proposalId}`),title:"Click to open full terminal session",children:e.jsx(Pe,{sessionId:s.id,heightPx:160,maxScrollback:200})})]},s.id))})]}),e.jsxs("div",{className:"space-y-3",children:[e.jsx("h2",{className:"text-lg font-semibold",children:"Recent Proposals"}),J?e.jsx("div",{className:"space-y-3",children:[...Array(3)].map((s,t)=>e.jsx(p,{children:e.jsx(ke,{className:"py-3",children:e.jsxs("div",{className:"flex justify-between items-start",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx("div",{className:"h-4 bg-muted rounded w-2/3 animate-pulse"}),e.jsx("div",{className:"h-3 bg-muted rounded w-1/3 animate-pulse"})]}),e.jsx("div",{className:"h-5 bg-muted rounded w-16 animate-pulse"})]})})},t))}):z.length===0?e.jsx(p,{children:e.jsx(_,{className:"flex items-center justify-center py-6",children:e.jsx("div",{className:"text-center text-sm text-gray-500",children:"No draft or approved proposals found"})})}):e.jsx("div",{className:"space-y-2",children:z.map(s=>e.jsx(p,{className:"hover:shadow-md transition-all cursor-pointer hover:border-primary/50",onClick:()=>c(`/terminal/${s.id}`),children:e.jsx(_,{className:"py-4",children:e.jsx("div",{className:"flex justify-between items-start gap-4",children:e.jsxs("div",{className:"flex-1 space-y-2",children:[e.jsxs("div",{className:"flex items-start justify-between",children:[e.jsx(De,{className:"text-base leading-tight",children:s.intent}),e.jsxs("div",{className:"flex gap-1 ml-3 flex-shrink-0",children:[s.priority&&e.jsx(U,{variant:s.priority==="high"||s.priority==="critical"?"destructive":s.priority==="medium"?"secondary":"outline",className:"text-xs",children:s.priority}),e.jsx(U,{variant:"default",className:"text-xs",children:s.status})]})]}),s.content&&e.jsxs("div",{className:"text-sm text-muted-foreground leading-relaxed",children:[s.content.split(`
2
2
  `).slice(0,2).join(" ").substring(0,150),s.content.length>150?"...":""]}),e.jsxs("div",{className:"flex justify-between items-center",children:[e.jsxs("div",{className:"text-xs text-muted-foreground",children:[s.id," • by ",s.author.name," • ",new Date(s.metadata.createdAt).toLocaleDateString()]}),e.jsxs("div",{className:"flex gap-2",onClick:t=>t.stopPropagation(),children:[e.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>c(`/proposals/${s.id}`),className:"h-7 px-2 text-xs",children:[e.jsx(ue,{className:"h-3 w-3 mr-1"})," View"]}),e.jsxs(r,{variant:"ghost",size:"sm",onClick:()=>c(`/proposals/${s.id}/edit`),className:"h-7 px-2 text-xs",children:[e.jsx(fe,{className:"h-3 w-3 mr-1"})," Edit"]})]})]})]})})})},s.id))})]}),e.jsx(ge,{open:k,onOpenChange:N,children:e.jsxs(je,{className:"max-w-lg",children:[e.jsxs(pe,{children:[e.jsx(ve,{children:"Start Coding Agent"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-2",children:"Start an interactive coding session"})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"Coding Agent"}),e.jsxs(Ne,{value:j,onValueChange:s=>K(s),children:[e.jsx(ye,{className:"w-full",children:e.jsx(we,{placeholder:"Select coding agent"})}),e.jsxs(Ce,{children:[e.jsx(S,{value:"claude",children:"Claude Code"}),e.jsx(S,{value:"gemini",children:"Google Gemini"}),e.jsx(S,{value:"codex",children:"OpenAI Codex"}),e.jsx(S,{value:"droid",children:"Factory Droid"})]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(Se,{className:"h-4 w-4"}),"Custom Agents"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[o.length," of ",u.length," selected"]})]}),e.jsxs(R,{children:[e.jsx(B,{asChild:!0,children:e.jsxs(r,{variant:"outline",className:"w-full justify-between",children:[o.length===0?"Select agents...":o.length===u.length?"All agents selected":`${o.length} agent${o.length!==1?"s":""} selected`,e.jsx(M,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(H,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsxs(L,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Available Agents"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:s=>{s.preventDefault(),C(u.map(t=>t.id))},children:"All"}),e.jsx(r,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:s=>{s.preventDefault(),C([])},children:"None"})]})]}),e.jsx(O,{}),u.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-gray-500",children:"No agents found"}):u.map(s=>e.jsx(G,{checked:o.includes(s.id),onCheckedChange:t=>{C(a=>t?a.includes(s.id)?a:[...a,s.id]:a.filter(n=>n!==s.id))},children:e.jsxs("div",{className:"flex flex-col",children:[e.jsx("span",{children:s.name}),s.tools.length>0&&e.jsxs("span",{className:"text-xs text-muted-foreground",children:["MCP servers: ",s.tools.join(", ")]}),s.tools.length===0&&e.jsx("span",{className:"text-xs text-muted-foreground",children:"Inherits available MCP servers"})]})},s.id))]})]})]}),e.jsxs("div",{children:[e.jsxs("div",{className:"flex items-center justify-between mb-2",children:[e.jsxs("div",{className:"text-sm font-medium flex items-center gap-2",children:[e.jsx(be,{className:"h-4 w-4"}),"MCP Servers"]}),e.jsxs("div",{className:"text-xs text-gray-500",children:[f.length," of ",h.length," selected"]})]}),e.jsxs(R,{children:[e.jsx(B,{asChild:!0,children:e.jsxs(r,{variant:"outline",className:"w-full justify-between",children:[f.length===0?"Select MCP servers...":f.length===h.length?"All servers selected":`${f.length} server${f.length!==1?"s":""} selected`,e.jsx(M,{className:"h-4 w-4 opacity-50"})]})}),e.jsxs(H,{className:"w-full min-w-[--radix-dropdown-menu-trigger-width]",children:[e.jsxs(L,{className:"flex items-center justify-between",children:[e.jsx("span",{children:"Available Servers"}),e.jsxs("div",{className:"flex gap-1",children:[e.jsx(r,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:s=>{s.preventDefault(),y(h)},children:"All"}),e.jsx(r,{size:"sm",variant:"ghost",className:"h-5 px-1 text-xs",onClick:s=>{s.preventDefault(),y([])},children:"None"})]})]}),e.jsx(O,{}),h.length===0?e.jsx("div",{className:"px-2 py-1.5 text-sm text-gray-500",children:"No MCP servers found"}):h.map(s=>e.jsx(G,{checked:f.includes(s),onCheckedChange:t=>{y(a=>t?a.includes(s)?a:[...a,s]:a.filter(n=>n!==s))},children:s},s))]})]})]}),e.jsxs("div",{children:[e.jsx("label",{className:"text-sm font-medium mb-2 block",children:"Additional Instructions (optional)"}),e.jsx(Ae,{value:T,onChange:s=>Q(s.target.value),placeholder:"Add any custom instructions for the coding agent...",rows:4,className:"resize-none"})]}),e.jsxs("div",{className:"flex justify-end gap-2 pt-2",children:[e.jsx(r,{variant:"outline",onClick:()=>N(!1),disabled:D,children:"Cancel"}),e.jsx(r,{onClick:le,disabled:D,children:D?"Starting...":"Start Session"})]})]})]})})]})}export{Xe as default};
@@ -1 +1 @@
1
- import{r as x,j as e,f as a,s as m}from"./index-Bbxvuj4b.js";function u({title:r,description:t,icon:n,defaultOpen:o=!1,children:i,className:l}){const[s,d]=x.useState(o);return e.jsxs("div",{className:a("rounded-lg border bg-card text-card-foreground",l),children:[e.jsxs("button",{type:"button",onClick:()=>d(c=>!c),className:"flex w-full items-center justify-between gap-4 px-4 py-3 text-left","aria-expanded":s,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[n,e.jsxs("div",{children:[e.jsx("p",{className:"font-medium leading-tight",children:r}),t&&e.jsx("p",{className:"text-sm text-muted-foreground leading-snug",children:t})]})]}),e.jsx(m,{className:a("h-4 w-4 shrink-0 transition-transform duration-200",s?"rotate-180":"rotate-0")})]}),s&&e.jsx("div",{className:"border-t px-4 py-4",children:i})]})}export{u as C};
1
+ import{r as x,j as e,f as a,s as m}from"./index-BAEEeZzi.js";function u({title:r,description:t,icon:n,defaultOpen:o=!1,children:i,className:l}){const[s,d]=x.useState(o);return e.jsxs("div",{className:a("rounded-lg border bg-card text-card-foreground",l),children:[e.jsxs("button",{type:"button",onClick:()=>d(c=>!c),className:"flex w-full items-center justify-between gap-4 px-4 py-3 text-left","aria-expanded":s,children:[e.jsxs("div",{className:"flex items-center gap-3",children:[n,e.jsxs("div",{children:[e.jsx("p",{className:"font-medium leading-tight",children:r}),t&&e.jsx("p",{className:"text-sm text-muted-foreground leading-snug",children:t})]})]}),e.jsx(m,{className:a("h-4 w-4 shrink-0 transition-transform duration-200",s?"rotate-180":"rotate-0")})]}),s&&e.jsx("div",{className:"border-t px-4 py-4",children:i})]})}export{u as C};
@@ -1,4 +1,4 @@
1
- import{c as W,j as e,r as m,D as q,a as B,F as N,b as S,d as A,e as P,f as I,S as z,B as r,C as D,L as n,g as L,h as F,i as M,k as T,A as E}from"./index-Bbxvuj4b.js";import{C as c,a as l,b as f,c as j,d as R}from"./card-D_zGBKua.js";import{B as Y}from"./badge-D7ZZbMEG.js";import{F as _}from"./folder-git-2-B9ILjFN2.js";import{C as H}from"./calendar-C5JtKp_F.js";import{C as G}from"./circle-check-xj41FKuF.js";import{C as $}from"./chevron-left-JjvWea8A.js";import{C as O}from"./clock-9dU_D6sL.js";import{C as V}from"./circle-check-big-KfJvKA9H.js";import{P as U}from"./plus-Be79gWKj.js";/**
1
+ import{c as W,j as e,r as m,D as q,a as B,F as N,b as S,d as A,e as P,f as I,S as z,B as r,C as D,L as n,g as L,h as F,i as M,k as T,A as E}from"./index-BAEEeZzi.js";import{C as c,a as l,b as f,c as j,d as R}from"./card-C9ekeZtD.js";import{B as Y}from"./badge-fHjW-wEe.js";import{F as _}from"./folder-git-2-9fWvFiHp.js";import{C as H}from"./calendar-DXMWQL-h.js";import{C as G}from"./circle-check-BO-qmBFl.js";import{C as $}from"./chevron-left-BkP_F3xd.js";import{C as O}from"./clock-BxO7xcX9.js";import{C as V}from"./circle-check-big-BUVglreY.js";import{P as U}from"./plus-CemYz5Fm.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,4 +1,4 @@
1
- import{c as le,A as l,bd as ws,r as n,H as vs,ag as ys,j as e,L as ee,ad as Fe,B as o,G as D,ac as Ns,X as Cs,I as k,q as Me,s as Be,T as Oe,D as se,a as te,b as ae,d as re,e as ne,aY as ks,$ as Re}from"./index-Bbxvuj4b.js";import{C as ie}from"./card-D_zGBKua.js";import{L as Ge}from"./label-CZGCmBD7.js";import{T as Ss,a as Ts,b as We,c as ze}from"./tabs-Ug7Ug5Ha.js";import{C as Ps}from"./circle-check-xj41FKuF.js";import{C as As}from"./circle-x-Ds97aY1x.js";import{A as Ds}from"./arrow-down-vmWOjyjO.js";import{A as $s}from"./arrow-up-hMM1cdZm.js";import{R as Ue}from"./refresh-cw-C0_Ot2Zc.js";import{C as ce}from"./circle-alert-DQD0CPB3.js";import{F as oe}from"./folder-git-2-B9ILjFN2.js";/**
1
+ import{c as le,A as l,bf as ws,r as n,H as vs,ag as ys,j as e,L as ee,ad as Fe,B as o,G as D,ac as Ns,X as Cs,I as k,q as Me,s as Be,T as Oe,D as se,a as te,b as ae,d as re,e as ne,b6 as ks,$ as Re}from"./index-BAEEeZzi.js";import{C as ie}from"./card-C9ekeZtD.js";import{L as Ge}from"./label-CRsu1MwQ.js";import{T as Ss,a as Ts,b as We,c as ze}from"./tabs-CP_A6r0A.js";import{C as Ps}from"./circle-check-BO-qmBFl.js";import{C as As}from"./circle-x-EQNlLpRR.js";import{A as Ds}from"./arrow-down-CSpiROUo.js";import{A as $s}from"./arrow-up-ugn3lusK.js";import{R as Ue}from"./refresh-cw-BL3y7jJo.js";import{C as ce}from"./circle-alert-DnIYekt3.js";import{F as oe}from"./folder-git-2-9fWvFiHp.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1,6 +1,6 @@
1
- import{c as Ae,r,H as He,A as u,j as e,a1 as he,aq as xe,B as o,T as Fe,n as De,aY as ze,I as U,D as W,a as q,b as B,d as J,e as K,$ as Y}from"./index-Bbxvuj4b.js";import{C as pe,b as ge,c as fe,d as be,a as je}from"./card-D_zGBKua.js";import{L as f}from"./label-CZGCmBD7.js";import{R as Me,a as ve}from"./radio-group-DpxssBzw.js";import{R as T}from"./refresh-cw-C0_Ot2Zc.js";import{C as Oe}from"./circle-check-xj41FKuF.js";import{C as Ie}from"./circle-x-Ds97aY1x.js";/**
1
+ import{c as Te,r,H as He,A as u,j as e,a1 as he,aA as xe,B as o,T as Fe,n as De,b6 as ze,I as U,D as W,a as B,b as q,d as J,e as K,$ as Y}from"./index-BAEEeZzi.js";import{C as pe,b as ge,c as fe,d as be,a as je}from"./card-C9ekeZtD.js";import{L as f}from"./label-CRsu1MwQ.js";import{R as Me,a as ve}from"./radio-group-Dz2cO4IQ.js";import{R as A}from"./refresh-cw-BL3y7jJo.js";import{C as Oe}from"./circle-check-BO-qmBFl.js";import{C as Ie}from"./circle-x-EQNlLpRR.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
5
5
  * See the LICENSE file in the root directory of this source tree.
6
- */const $e=[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4",key:"tonef"}],["path",{d:"M9 18c-4.51 2-5-2-7-2",key:"9comsn"}]],we=Ae("github",$e),V="../worktrees",y="../worktrees",b="coconut/github-auth-state";function _e(h){const j=h.trim();return j?/^([A-Za-z]:\\|\\\\|\/|~)/.test(j):!1}function Xe(){const[h,j]=r.useState(null),[X,v]=r.useState(y),[c,A]=r.useState("github"),[Z,Q]=r.useState(!0),[H,ee]=r.useState(!1),[a,te]=r.useState(null),[w,se]=r.useState(!1),[x,ye]=r.useState(null),[Ne,N]=r.useState(!1),[C,F]=r.useState(""),[k,D]=r.useState(""),[re,ae]=r.useState(!1),[p,S]=r.useState(!1),[ie,oe]=r.useState(!1),[Ce,R]=r.useState(!1),[E,G]=r.useState(""),[ne,ce]=r.useState(!1),[z,le]=r.useState(!1),[ke,P]=r.useState(!1),m=r.useRef(null),{toast:i}=He(),M=r.useCallback(async()=>{Q(!0);try{const s=await(await fetch(`${u}/api/v1/git/settings`)).json();if(s.success){const n=s.data||{},d={defaultWorktreePath:n.defaultWorktreePath||y,authMode:n.authMode||"github"};j(d),v(d.defaultWorktreePath),A(d.authMode)}else throw new Error(s.error?.message||"Failed to load settings")}catch(t){console.error("Failed to load git settings",t),i({title:"Error",description:"Failed to load git settings",variant:"destructive"})}finally{Q(!1)}},[i]),l=r.useCallback(async()=>{se(!0);try{const[t,s]=await Promise.all([fetch(`${u}/api/v1/git/auth-status`).then(n=>n.json()),fetch(`${u}/api/v1/git/credential-config`).then(n=>n.json())]);if(t.success)te(t.data);else throw new Error(t.error?.message||"Failed to check auth status");s.success&&ye(s.data)}catch(t){console.error("Failed to check git auth status",t),te({authenticated:!1,error:"Failed to check status"})}finally{se(!1)}},[i]),O=c==="github",Se=O&&a?.provider==="github",L=!!(O&&a?.authenticated&&a?.provider==="github"),I=!!(O&&a?.provider==="github"&&!a?.authenticated),de=r.useMemo(()=>{if(!a?.expiresAt)return null;const t=new Date(a.expiresAt);return Number.isNaN(t.getTime())?null:t.toLocaleString()},[a?.expiresAt]);r.useEffect(()=>{if(typeof window>"u")return;const t=s=>{s.origin===window.location.origin&&s.data?.type==="github-auth"&&(m.current&&!m.current.closed&&m.current.close(),m.current=null,localStorage.removeItem(b),S(!1),s.data?.success?(i({title:"GitHub connected",description:"GitHub authorization completed successfully."}),l()):i({title:"GitHub authorization failed",description:s.data?.message||"Authorization was cancelled or failed.",variant:"destructive"}))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[l,i]),r.useEffect(()=>{if(typeof window>"u"||!p)return;const t=window.setInterval(()=>{m.current&&m.current.closed&&(window.clearInterval(t),m.current=null,S(!1),localStorage.removeItem(b))},500);return()=>window.clearInterval(t)},[p]);const Re=r.useCallback(async()=>{if(!p&&!(typeof window>"u")){S(!0);try{const t=`${window.location.origin}/auth/github/callback`,s=await fetch(`${u}/api/v1/git/providers/github/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callbackUrl:t})}),n=await s.json();if(!s.ok||!n.success)throw new Error(n?.error?.message||"Failed to start GitHub authorization");const d=n?.data?.authorizeUrl,me=n?.data?.state;if(!d||!me)throw new Error("Invalid response from authorization endpoint");localStorage.removeItem(b),localStorage.setItem(b,me);const _=window.open(d,"github-authorization","width=600,height=700");if(!_)throw localStorage.removeItem(b),new Error("Popup blocked. Please allow popups and try again.");m.current=_,_.focus()}catch(t){S(!1),localStorage.removeItem(b),i({title:"GitHub authorization failed",description:t?.message||"Unable to open GitHub authorization flow.",variant:"destructive"})}}},[p,i]),Ee=r.useCallback(async()=>{oe(!0);try{const t=await fetch(`${u}/api/v1/git/providers/github/token`,{method:"DELETE"}),s=await t.json();if(!t.ok||!s.success)throw new Error(s?.error?.message||"Failed to disconnect GitHub");i({title:"GitHub disconnected",description:"Stored GitHub credentials were removed."}),await l()}catch(t){i({title:"Failed to disconnect GitHub",description:t?.message||"Please try again.",variant:"destructive"})}finally{oe(!1)}},[l,i]);r.useEffect(()=>{M(),l()},[M,l]);const Ge=async()=>{if(!E.trim()){i({title:"Error",description:"Remote URL is required",variant:"destructive"});return}ce(!0);try{const s=await(await fetch(`${u}/api/v1/git/remote`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:E.trim()})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to set remote URL");i({title:"Success",description:"Remote URL set successfully"}),R(!1),G(""),await l()}catch(t){console.error("Failed to set remote URL",t),i({title:"Error",description:t?.message||"Failed to set remote URL",variant:"destructive"})}finally{ce(!1)}},Pe=async()=>{le(!0);try{const s=await(await fetch(`${u}/api/v1/git/remote`,{method:"DELETE"})).json();if(!s.success)throw new Error(s.error?.message||"Failed to delete remote");i({title:"Success",description:"Remote URL removed"}),await l()}catch(t){console.error("Failed to delete remote",t),i({title:"Error",description:t?.message||"Failed to delete remote",variant:"destructive"})}finally{le(!1)}},Le=async()=>{if(!C||!k){i({title:"Error",description:"Username and password are required",variant:"destructive"});return}if(!a?.remote){i({title:"Error",description:"Set a remote URL first before saving credentials",variant:"destructive"});return}ae(!0);try{const s=await(await fetch(`${u}/api/v1/git/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:C,password:k})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to save credentials");i({title:"Success",description:"Credentials saved successfully"}),N(!1),F(""),D(""),await l()}catch(t){console.error("Failed to save credentials",t),i({title:"Error",description:t?.message||"Failed to save credentials",variant:"destructive"})}finally{ae(!1)}},g=X.trim(),$=r.useMemo(()=>g?_e(g)?"Path must be relative to the project root":null:"Path is required",[g]),Ue=r.useMemo(()=>h?g!==h.defaultWorktreePath||(h.authMode||"github")!==c:!1,[h,g,c]),ue=!Z&&!H&&Ue&&!$,Te=async()=>{if(ue){ee(!0);try{const s=await(await fetch(`${u}/api/v1/git/settings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultWorktreePath:g,authMode:c})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to update settings");const n=s.data||{},d={defaultWorktreePath:n.defaultWorktreePath||y,authMode:n.authMode||"github"};j(d),v(d.defaultWorktreePath),A(d.authMode),i({title:"Updated",description:"Git settings saved"})}catch(t){console.error("Failed to update git settings",t),i({title:"Error",description:t?.message||"Failed to update git settings",variant:"destructive"})}finally{ee(!1)}}};return Z&&!h?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Git Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control how Coconut creates worktrees for change proposals and manual Git operations."})]}),e.jsx(he,{}),e.jsxs(pe,{children:[e.jsxs(ge,{children:[e.jsx(fe,{children:"Remote Authentication"}),e.jsx(be,{children:"Configure authentication for remote git operations."})]}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Remote URL"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The git remote URL for your repository (origin)."}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded border bg-muted/30 px-3 py-2",children:[w&&!a?e.jsxs("span",{className:"text-sm text-muted-foreground italic flex items-center gap-2",children:[e.jsx(T,{className:"h-3.5 w-3.5 animate-spin"}),"Loading..."]}):a?.remote?e.jsxs("a",{href:a.remote.replace(/\.git$/,"").replace(/^git@([^:]+):/,"https://$1/"),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate inline-flex items-center gap-1.5",children:[a.remote,e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0"})]}):e.jsx("span",{className:"text-sm text-muted-foreground italic",children:"Not configured"}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[a?.remote&&e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>P(!0),disabled:z,title:"Remove remote",children:e.jsx(Fe,{className:"h-4 w-4"})}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{G(a?.remote||""),R(!0)},children:a?.remote?"Edit":"Set Remote"})]})]})]}),e.jsx(he,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Authentication Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose how Coconut authenticates with your remote repository when pushing or pulling."}),e.jsxs(Me,{value:c,onValueChange:t=>A(t||"github"),className:"grid gap-2 md:grid-cols-2",children:[e.jsx("label",{htmlFor:"mode-github",className:`cursor-pointer rounded-md border p-3 transition-colors ${c==="github"?"border-primary ring-1 ring-primary/40 bg-primary/5":"border-border bg-background hover:border-primary/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{value:"github",id:"mode-github",className:"mt-1 h-5 w-5 shrink-0 border-[1.5px]"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"GitHub"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use the Coconut control plane to fetch short-lived GitHub tokens automatically."})]})]})}),e.jsx("label",{htmlFor:"mode-local",className:`cursor-pointer rounded-md border p-3 transition-colors ${c==="local"?"border-primary ring-1 ring-primary/40 bg-primary/5":"border-border bg-background hover:border-primary/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{value:"local",id:"mode-local",className:"mt-1 h-5 w-5 shrink-0 border-[1.5px]"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"Local configuration"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage credentials yourself using SSH keys, stored PATs, or OS credential helpers on this Coconut."})]})]})})]})]}),c==="github"&&!a&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-sm text-muted-foreground",children:[e.jsx(T,{className:"h-4 w-4 animate-spin"}),"Loading authentication status..."]}),c==="github"&&a&&!a.remote&&e.jsxs("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-sm text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx("span",{className:"font-medium",children:"Remote URL required:"})," Set a remote URL above to enable GitHub authentication."]}),c==="github"&&a?.remote&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3 rounded border p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[w?e.jsx(T,{className:"h-5 w-5 mt-1 animate-spin text-muted-foreground"}):a?.authenticated?e.jsx(Oe,{className:"h-5 w-5 mt-1 text-green-600"}):e.jsx(Ie,{className:"h-5 w-5 mt-1 text-red-600"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("div",{className:"font-medium",children:w?"Checking...":L?"Connected to GitHub":I?"GitHub authorization required":a?.authenticated?"Authenticated":"Not authenticated"}),Se&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:L?"GitHub App credentials active":"Authorize with GitHub to continue"})]}),L&&de&&e.jsxs("span",{className:"rounded bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",children:["Expires ",de]})]}),a?.error&&e.jsx("div",{className:"text-xs text-red-600",children:a.error})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:l,disabled:w,children:[e.jsx(T,{className:"h-4 w-4 mr-2"+(w?" animate-spin":"")}),"Check Status"]}),L?e.jsx(o,{variant:"ghost",size:"sm",onClick:Ee,disabled:ie,children:ie?"Disconnecting…":"Disconnect GitHub"}):e.jsxs(o,{size:"sm",onClick:Re,disabled:p,children:[p?e.jsx(De,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(we,{className:"h-4 w-4 mr-2"}),p?"Authorizing…":I?"Reconnect GitHub":"Connect GitHub"]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("a",{href:"https://app.coconut.dev/git",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Manage Github authentication",e.jsx(xe,{className:"h-3 w-3"})]})})]}),I&&e.jsx("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-xs text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:"GitHub authorization has expired. Click “Reconnect GitHub” to refresh access."}),x&&(x.helper||x.origin)&&e.jsxs("div",{className:"rounded border bg-muted/50 p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-1",children:"Current Configuration"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[x.helper&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono",children:"credential.helper:"}),e.jsx("span",{className:"font-mono text-foreground",children:x.helper})]}),x.origin&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono",children:"Configured in:"}),e.jsx("span",{className:"font-mono text-foreground",children:x.origin})]})]})]})]}),c==="local"&&e.jsxs("div",{className:"rounded bg-muted p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium",children:"Setup Git Credentials"}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N(!0),children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Enter Credentials"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-2",children:[e.jsx("p",{children:"Configure credentials directly on this Coconut. Coconut will use your existing SSH keys or credential helpers without contacting the control plane."}),e.jsxs("div",{className:"space-y-2 ml-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 1: SSH Keys (Recommended)"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:['ssh-keygen -t ed25519 -C "your_email@example.com"',e.jsx("br",{}),"# Add ~/.ssh/id_ed25519.pub to your Git provider account"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 2: Git Credential Manager"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:["# macOS (already configured with osxkeychain)",e.jsx("br",{}),"git credential-osxkeychain",e.jsx("br",{}),e.jsx("br",{}),"# Or install Git Credential Manager",e.jsx("br",{}),"brew install git-credential-manager"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 3: Personal Access Token"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:["# Store credentials after first push/pull",e.jsx("br",{}),"git config credential.helper store"]})]})]}),e.jsx("p",{className:"mt-3",children:'After configuring, click "Check Status" to verify authentication.'})]})]})]})]}),e.jsxs(pe,{children:[e.jsxs(ge,{children:[e.jsx(fe,{children:"Worktree Location"}),e.jsx(be,{children:"Choose where new worktrees should be created relative to your project root."})]}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"default-worktree-path",children:"Default worktree path"}),e.jsx(U,{id:"default-worktree-path",value:X,onChange:t=>v(t.target.value),placeholder:"../worktrees",spellCheck:!1}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Paths are resolved from your project root. We recommend keeping worktrees outside the repository, for example ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-[11px] font-mono",children:V}),"."]}),$&&e.jsx("p",{className:"text-xs text-red-600",children:$})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(o,{type:"button",variant:"outline",size:"sm",onClick:()=>v(V),children:["Use ",V]}),e.jsxs(o,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(y),children:["Reset to ",y]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(o,{type:"button",variant:"outline",disabled:H,onClick:M,children:"Reload"}),e.jsx(o,{type:"button",disabled:!ue,onClick:Te,children:H?"Saving...":"Save changes"})]}),e.jsx(W,{open:Ne,onOpenChange:N,children:e.jsxs(q,{children:[e.jsxs(B,{children:[e.jsx(J,{children:"Enter Git Credentials"}),e.jsx(K,{children:"Enter your username and personal access token for HTTPS authentication. Your credentials will be securely stored using your system's credential manager."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[!a?.remote&&e.jsx("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-xs text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:"No remote URL configured. Set a remote URL first before entering credentials."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"git-username",children:"Username"}),e.jsx(U,{id:"git-username",placeholder:"your-username",value:C,onChange:t=>F(t.target.value),autoComplete:"username"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"git-password",children:"Password / Personal Access Token"}),e.jsx(U,{id:"git-password",type:"password",placeholder:"ghp_xxxxxxxxxxxx or your password",value:k,onChange:t=>D(t.target.value),autoComplete:"current-password"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["We recommend using a Personal Access Token instead of your password.",e.jsx("br",{}),"GitHub: Settings → Developer settings → Personal access tokens",e.jsx("br",{}),"GitLab: Preferences → Access Tokens"]})]})]}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>{N(!1),F(""),D("")},children:"Cancel"}),e.jsx(o,{onClick:Le,disabled:re||!C||!k||!a?.remote,children:re?"Saving...":"Save Credentials"})]})]})}),e.jsx(W,{open:ke,onOpenChange:P,children:e.jsxs(q,{children:[e.jsxs(B,{children:[e.jsx(J,{children:"Remove Remote?"}),e.jsx(K,{children:"This will remove the origin remote from your local git configuration. The remote repository itself won't be affected."})]}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),e.jsx(o,{variant:"destructive",onClick:async()=>{P(!1),await Pe()},disabled:z,children:z?"Removing...":"Remove Remote"})]})]})}),e.jsx(W,{open:Ce,onOpenChange:R,children:e.jsxs(q,{children:[e.jsxs(B,{children:[e.jsx(J,{children:a?.remote?"Edit Remote URL":"Set Remote URL"}),e.jsx(K,{children:"Configure the git remote URL for your repository. This is the origin remote used for push and pull operations."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"remote-url",children:"Remote URL"}),e.jsx(U,{id:"remote-url",placeholder:"https://github.com/username/repo.git",value:E,onChange:t=>G(t.target.value),autoComplete:"off"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter your repository URL (HTTPS or SSH format)."})]})}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>{R(!1),G("")},children:"Cancel"}),e.jsx(o,{onClick:Ge,disabled:ne||!E.trim(),children:ne?"Saving...":"Save"})]})]})})]})}export{Xe as default};
6
+ */const $e=[["path",{d:"M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.08-1.25-.27-2.48-1-3.5.28-1.15.28-2.35 0-3.5 0 0-1 0-3 1.5-2.64-.5-5.36-.5-8 0C6 2 5 2 5 2c-.3 1.15-.3 2.35 0 3.5A5.403 5.403 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.39.49-.68 1.05-.85 1.65-.17.6-.22 1.23-.15 1.85v4",key:"tonef"}],["path",{d:"M9 18c-4.51 2-5-2-7-2",key:"9comsn"}]],we=Te("github",$e),V="../worktrees",y="../worktrees",b="coconut/github-auth-state";function _e(h){const j=h.trim();return j?/^([A-Za-z]:\\|\\\\|\/|~)/.test(j):!1}function Xe(){const[h,j]=r.useState(null),[X,v]=r.useState(y),[c,T]=r.useState("github"),[Z,Q]=r.useState(!0),[H,ee]=r.useState(!1),[a,te]=r.useState(null),[w,se]=r.useState(!1),[x,ye]=r.useState(null),[Ne,N]=r.useState(!1),[C,F]=r.useState(""),[k,D]=r.useState(""),[re,ae]=r.useState(!1),[p,S]=r.useState(!1),[ie,oe]=r.useState(!1),[Ce,R]=r.useState(!1),[E,G]=r.useState(""),[ne,ce]=r.useState(!1),[z,le]=r.useState(!1),[ke,P]=r.useState(!1),m=r.useRef(null),{toast:i}=He(),M=r.useCallback(async()=>{Q(!0);try{const s=await(await fetch(`${u}/api/v1/git/settings`)).json();if(s.success){const n=s.data||{},d={defaultWorktreePath:n.defaultWorktreePath||y,authMode:n.authMode||"github"};j(d),v(d.defaultWorktreePath),T(d.authMode)}else throw new Error(s.error?.message||"Failed to load settings")}catch(t){console.error("Failed to load git settings",t),i({title:"Error",description:"Failed to load git settings",variant:"destructive"})}finally{Q(!1)}},[i]),l=r.useCallback(async()=>{se(!0);try{const[t,s]=await Promise.all([fetch(`${u}/api/v1/git/auth-status`).then(n=>n.json()),fetch(`${u}/api/v1/git/credential-config`).then(n=>n.json())]);if(t.success)te(t.data);else throw new Error(t.error?.message||"Failed to check auth status");s.success&&ye(s.data)}catch(t){console.error("Failed to check git auth status",t),te({authenticated:!1,error:"Failed to check status"})}finally{se(!1)}},[i]),O=c==="github",Se=O&&a?.provider==="github",L=!!(O&&a?.authenticated&&a?.provider==="github"),I=!!(O&&a?.provider==="github"&&!a?.authenticated),de=r.useMemo(()=>{if(!a?.expiresAt)return null;const t=new Date(a.expiresAt);return Number.isNaN(t.getTime())?null:t.toLocaleString()},[a?.expiresAt]);r.useEffect(()=>{if(typeof window>"u")return;const t=s=>{s.origin===window.location.origin&&s.data?.type==="github-auth"&&(m.current&&!m.current.closed&&m.current.close(),m.current=null,localStorage.removeItem(b),S(!1),s.data?.success?(i({title:"GitHub connected",description:"GitHub authorization completed successfully."}),l()):i({title:"GitHub authorization failed",description:s.data?.message||"Authorization was cancelled or failed.",variant:"destructive"}))};return window.addEventListener("message",t),()=>window.removeEventListener("message",t)},[l,i]),r.useEffect(()=>{if(typeof window>"u"||!p)return;const t=window.setInterval(()=>{m.current&&m.current.closed&&(window.clearInterval(t),m.current=null,S(!1),localStorage.removeItem(b))},500);return()=>window.clearInterval(t)},[p]);const Re=r.useCallback(async()=>{if(!p&&!(typeof window>"u")){S(!0);try{const t=`${window.location.origin}/auth/github/callback`,s=await fetch(`${u}/api/v1/git/providers/github/authorize`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({callbackUrl:t})}),n=await s.json();if(!s.ok||!n.success)throw new Error(n?.error?.message||"Failed to start GitHub authorization");const d=n?.data?.authorizeUrl,me=n?.data?.state;if(!d||!me)throw new Error("Invalid response from authorization endpoint");localStorage.removeItem(b),localStorage.setItem(b,me);const _=window.open(d,"github-authorization","width=600,height=700");if(!_)throw localStorage.removeItem(b),new Error("Popup blocked. Please allow popups and try again.");m.current=_,_.focus()}catch(t){S(!1),localStorage.removeItem(b),i({title:"GitHub authorization failed",description:t?.message||"Unable to open GitHub authorization flow.",variant:"destructive"})}}},[p,i]),Ee=r.useCallback(async()=>{oe(!0);try{const t=await fetch(`${u}/api/v1/git/providers/github/token`,{method:"DELETE"}),s=await t.json();if(!t.ok||!s.success)throw new Error(s?.error?.message||"Failed to disconnect GitHub");i({title:"GitHub disconnected",description:"Stored GitHub credentials were removed."}),await l()}catch(t){i({title:"Failed to disconnect GitHub",description:t?.message||"Please try again.",variant:"destructive"})}finally{oe(!1)}},[l,i]);r.useEffect(()=>{M(),l()},[M,l]);const Ge=async()=>{if(!E.trim()){i({title:"Error",description:"Remote URL is required",variant:"destructive"});return}ce(!0);try{const s=await(await fetch(`${u}/api/v1/git/remote`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({remoteUrl:E.trim()})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to set remote URL");i({title:"Success",description:"Remote URL set successfully"}),R(!1),G(""),await l()}catch(t){console.error("Failed to set remote URL",t),i({title:"Error",description:t?.message||"Failed to set remote URL",variant:"destructive"})}finally{ce(!1)}},Pe=async()=>{le(!0);try{const s=await(await fetch(`${u}/api/v1/git/remote`,{method:"DELETE"})).json();if(!s.success)throw new Error(s.error?.message||"Failed to delete remote");i({title:"Success",description:"Remote URL removed"}),await l()}catch(t){console.error("Failed to delete remote",t),i({title:"Error",description:t?.message||"Failed to delete remote",variant:"destructive"})}finally{le(!1)}},Le=async()=>{if(!C||!k){i({title:"Error",description:"Username and password are required",variant:"destructive"});return}if(!a?.remote){i({title:"Error",description:"Set a remote URL first before saving credentials",variant:"destructive"});return}ae(!0);try{const s=await(await fetch(`${u}/api/v1/git/credentials`,{method:"POST",headers:{"Content-Type":"application/json"},body:JSON.stringify({username:C,password:k})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to save credentials");i({title:"Success",description:"Credentials saved successfully"}),N(!1),F(""),D(""),await l()}catch(t){console.error("Failed to save credentials",t),i({title:"Error",description:t?.message||"Failed to save credentials",variant:"destructive"})}finally{ae(!1)}},g=X.trim(),$=r.useMemo(()=>g?_e(g)?"Path must be relative to the project root":null:"Path is required",[g]),Ue=r.useMemo(()=>h?g!==h.defaultWorktreePath||(h.authMode||"github")!==c:!1,[h,g,c]),ue=!Z&&!H&&Ue&&!$,Ae=async()=>{if(ue){ee(!0);try{const s=await(await fetch(`${u}/api/v1/git/settings`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({defaultWorktreePath:g,authMode:c})})).json();if(!s.success)throw new Error(s.error?.message||"Failed to update settings");const n=s.data||{},d={defaultWorktreePath:n.defaultWorktreePath||y,authMode:n.authMode||"github"};j(d),v(d.defaultWorktreePath),T(d.authMode),i({title:"Updated",description:"Git settings saved"})}catch(t){console.error("Failed to update git settings",t),i({title:"Error",description:t?.message||"Failed to update git settings",variant:"destructive"})}finally{ee(!1)}}};return Z&&!h?e.jsx("div",{children:"Loading..."}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"Git Settings"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Control how Coconut creates worktrees for change proposals and manual Git operations."})]}),e.jsx(he,{}),e.jsxs(pe,{children:[e.jsxs(ge,{children:[e.jsx(fe,{children:"Remote Authentication"}),e.jsx(be,{children:"Configure authentication for remote git operations."})]}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Remote URL"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"The git remote URL for your repository (origin)."}),e.jsxs("div",{className:"flex items-center justify-between gap-3 rounded border bg-muted/30 px-3 py-2",children:[w&&!a?e.jsxs("span",{className:"text-sm text-muted-foreground italic flex items-center gap-2",children:[e.jsx(A,{className:"h-3.5 w-3.5 animate-spin"}),"Loading..."]}):a?.remote?e.jsxs("a",{href:a.remote.replace(/\.git$/,"").replace(/^git@([^:]+):/,"https://$1/"),target:"_blank",rel:"noopener noreferrer",className:"text-sm text-primary hover:underline truncate inline-flex items-center gap-1.5",children:[a.remote,e.jsx(xe,{className:"h-3.5 w-3.5 shrink-0"})]}):e.jsx("span",{className:"text-sm text-muted-foreground italic",children:"Not configured"}),e.jsxs("div",{className:"flex items-center gap-1.5 shrink-0",children:[a?.remote&&e.jsx(o,{variant:"ghost",size:"icon",className:"h-8 w-8 text-muted-foreground hover:text-destructive",onClick:()=>P(!0),disabled:z,title:"Remove remote",children:e.jsx(Fe,{className:"h-4 w-4"})}),e.jsx(o,{variant:"outline",size:"sm",onClick:()=>{G(a?.remote||""),R(!0)},children:a?.remote?"Edit":"Set Remote"})]})]})]}),e.jsx(he,{}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{className:"text-sm font-medium",children:"Authentication Mode"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Choose how Coconut authenticates with your remote repository when pushing or pulling."}),e.jsxs(Me,{value:c,onValueChange:t=>T(t||"github"),className:"grid gap-2 md:grid-cols-2",children:[e.jsx("label",{htmlFor:"mode-github",className:`cursor-pointer rounded-md border p-3 transition-colors ${c==="github"?"border-primary ring-1 ring-primary/40 bg-primary/5":"border-border bg-background hover:border-primary/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{value:"github",id:"mode-github",className:"mt-1 h-5 w-5 shrink-0 border-[1.5px]"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"GitHub"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Use the Coconut control plane to fetch short-lived GitHub tokens automatically."})]})]})}),e.jsx("label",{htmlFor:"mode-local",className:`cursor-pointer rounded-md border p-3 transition-colors ${c==="local"?"border-primary ring-1 ring-primary/40 bg-primary/5":"border-border bg-background hover:border-primary/60"}`,children:e.jsxs("div",{className:"flex items-start gap-3",children:[e.jsx(ve,{value:"local",id:"mode-local",className:"mt-1 h-5 w-5 shrink-0 border-[1.5px]"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("span",{className:"text-sm font-medium",children:"Local configuration"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Manage credentials yourself using SSH keys, stored PATs, or OS credential helpers on this Coconut."})]})]})})]})]}),c==="github"&&!a&&e.jsxs("div",{className:"flex items-center justify-center gap-2 py-4 text-sm text-muted-foreground",children:[e.jsx(A,{className:"h-4 w-4 animate-spin"}),"Loading authentication status..."]}),c==="github"&&a&&!a.remote&&e.jsxs("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-sm text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:[e.jsx("span",{className:"font-medium",children:"Remote URL required:"})," Set a remote URL above to enable GitHub authentication."]}),c==="github"&&a?.remote&&e.jsxs(e.Fragment,{children:[e.jsxs("div",{className:"space-y-3 rounded border p-3",children:[e.jsxs("div",{className:"flex items-start gap-3",children:[w?e.jsx(A,{className:"h-5 w-5 mt-1 animate-spin text-muted-foreground"}):a?.authenticated?e.jsx(Oe,{className:"h-5 w-5 mt-1 text-green-600"}):e.jsx(Ie,{className:"h-5 w-5 mt-1 text-red-600"}),e.jsxs("div",{className:"space-y-1 flex-1",children:[e.jsx("div",{className:"font-medium",children:w?"Checking...":L?"Connected to GitHub":I?"GitHub authorization required":a?.authenticated?"Authenticated":"Not authenticated"}),Se&&e.jsxs("div",{className:"flex flex-wrap items-center gap-2 text-xs text-muted-foreground",children:[e.jsxs("span",{className:"inline-flex items-center gap-1",children:[e.jsx(we,{className:"h-3.5 w-3.5"}),e.jsx("span",{children:L?"GitHub App credentials active":"Authorize with GitHub to continue"})]}),L&&de&&e.jsxs("span",{className:"rounded bg-muted px-2 py-0.5 text-[11px] text-muted-foreground",children:["Expires ",de]})]}),a?.error&&e.jsx("div",{className:"text-xs text-red-600",children:a.error})]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2 justify-end",children:[e.jsxs(o,{variant:"outline",size:"sm",onClick:l,disabled:w,children:[e.jsx(A,{className:"h-4 w-4 mr-2"+(w?" animate-spin":"")}),"Check Status"]}),L?e.jsx(o,{variant:"ghost",size:"sm",onClick:Ee,disabled:ie,children:ie?"Disconnecting…":"Disconnect GitHub"}):e.jsxs(o,{size:"sm",onClick:Re,disabled:p,children:[p?e.jsx(De,{className:"h-4 w-4 mr-2 animate-spin"}):e.jsx(we,{className:"h-4 w-4 mr-2"}),p?"Authorizing…":I?"Reconnect GitHub":"Connect GitHub"]})]}),e.jsx("div",{className:"text-right",children:e.jsxs("a",{href:"https://app.coconut.dev/git",target:"_blank",rel:"noopener noreferrer",className:"inline-flex items-center gap-1 text-xs text-primary hover:underline",children:["Manage Github authentication",e.jsx(xe,{className:"h-3 w-3"})]})})]}),I&&e.jsx("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-xs text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:"GitHub authorization has expired. Click “Reconnect GitHub” to refresh access."}),x&&(x.helper||x.origin)&&e.jsxs("div",{className:"rounded border bg-muted/50 p-3",children:[e.jsx("div",{className:"text-xs font-medium mb-1",children:"Current Configuration"}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-1",children:[x.helper&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono",children:"credential.helper:"}),e.jsx("span",{className:"font-mono text-foreground",children:x.helper})]}),x.origin&&e.jsxs("div",{className:"flex gap-2",children:[e.jsx("span",{className:"font-mono",children:"Configured in:"}),e.jsx("span",{className:"font-mono text-foreground",children:x.origin})]})]})]})]}),c==="local"&&e.jsxs("div",{className:"rounded bg-muted p-4 space-y-3",children:[e.jsxs("div",{className:"flex items-center justify-between",children:[e.jsx("div",{className:"text-sm font-medium",children:"Setup Git Credentials"}),e.jsxs(o,{variant:"outline",size:"sm",onClick:()=>N(!0),children:[e.jsx(ze,{className:"h-4 w-4 mr-2"}),"Enter Credentials"]})]}),e.jsxs("div",{className:"text-xs text-muted-foreground space-y-2",children:[e.jsx("p",{children:"Configure credentials directly on this Coconut. Coconut will use your existing SSH keys or credential helpers without contacting the control plane."}),e.jsxs("div",{className:"space-y-2 ml-2",children:[e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 1: SSH Keys (Recommended)"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:['ssh-keygen -t ed25519 -C "your_email@example.com"',e.jsx("br",{}),"# Add ~/.ssh/id_ed25519.pub to your Git provider account"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 2: Git Credential Manager"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:["# macOS (already configured with osxkeychain)",e.jsx("br",{}),"git credential-osxkeychain",e.jsx("br",{}),e.jsx("br",{}),"# Or install Git Credential Manager",e.jsx("br",{}),"brew install git-credential-manager"]})]}),e.jsxs("div",{children:[e.jsx("div",{className:"font-semibold",children:"Option 3: Personal Access Token"}),e.jsxs("code",{className:"text-[11px] block mt-1 bg-background rounded px-2 py-1",children:["# Store credentials after first push/pull",e.jsx("br",{}),"git config credential.helper store"]})]})]}),e.jsx("p",{className:"mt-3",children:'After configuring, click "Check Status" to verify authentication.'})]})]})]})]}),e.jsxs(pe,{children:[e.jsxs(ge,{children:[e.jsx(fe,{children:"Worktree Location"}),e.jsx(be,{children:"Choose where new worktrees should be created relative to your project root."})]}),e.jsxs(je,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"default-worktree-path",children:"Default worktree path"}),e.jsx(U,{id:"default-worktree-path",value:X,onChange:t=>v(t.target.value),placeholder:"../worktrees",spellCheck:!1}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Paths are resolved from your project root. We recommend keeping worktrees outside the repository, for example ",e.jsx("code",{className:"rounded bg-muted px-1 py-0.5 text-[11px] font-mono",children:V}),"."]}),$&&e.jsx("p",{className:"text-xs text-red-600",children:$})]}),e.jsxs("div",{className:"flex flex-wrap gap-2",children:[e.jsxs(o,{type:"button",variant:"outline",size:"sm",onClick:()=>v(V),children:["Use ",V]}),e.jsxs(o,{type:"button",variant:"ghost",size:"sm",onClick:()=>v(y),children:["Reset to ",y]})]})]})]}),e.jsxs("div",{className:"flex justify-end gap-2",children:[e.jsx(o,{type:"button",variant:"outline",disabled:H,onClick:M,children:"Reload"}),e.jsx(o,{type:"button",disabled:!ue,onClick:Ae,children:H?"Saving...":"Save changes"})]}),e.jsx(W,{open:Ne,onOpenChange:N,children:e.jsxs(B,{children:[e.jsxs(q,{children:[e.jsx(J,{children:"Enter Git Credentials"}),e.jsx(K,{children:"Enter your username and personal access token for HTTPS authentication. Your credentials will be securely stored using your system's credential manager."})]}),e.jsxs("div",{className:"space-y-4 py-4",children:[!a?.remote&&e.jsx("div",{className:"rounded border border-amber-200 bg-amber-50 p-3 text-xs text-amber-700 dark:border-amber-900 dark:bg-amber-950 dark:text-amber-200",children:"No remote URL configured. Set a remote URL first before entering credentials."}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"git-username",children:"Username"}),e.jsx(U,{id:"git-username",placeholder:"your-username",value:C,onChange:t=>F(t.target.value),autoComplete:"username"})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"git-password",children:"Password / Personal Access Token"}),e.jsx(U,{id:"git-password",type:"password",placeholder:"ghp_xxxxxxxxxxxx or your password",value:k,onChange:t=>D(t.target.value),autoComplete:"current-password"}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["We recommend using a Personal Access Token instead of your password.",e.jsx("br",{}),"GitHub: Settings → Developer settings → Personal access tokens",e.jsx("br",{}),"GitLab: Preferences → Access Tokens"]})]})]}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>{N(!1),F(""),D("")},children:"Cancel"}),e.jsx(o,{onClick:Le,disabled:re||!C||!k||!a?.remote,children:re?"Saving...":"Save Credentials"})]})]})}),e.jsx(W,{open:ke,onOpenChange:P,children:e.jsxs(B,{children:[e.jsxs(q,{children:[e.jsx(J,{children:"Remove Remote?"}),e.jsx(K,{children:"This will remove the origin remote from your local git configuration. The remote repository itself won't be affected."})]}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>P(!1),children:"Cancel"}),e.jsx(o,{variant:"destructive",onClick:async()=>{P(!1),await Pe()},disabled:z,children:z?"Removing...":"Remove Remote"})]})]})}),e.jsx(W,{open:Ce,onOpenChange:R,children:e.jsxs(B,{children:[e.jsxs(q,{children:[e.jsx(J,{children:a?.remote?"Edit Remote URL":"Set Remote URL"}),e.jsx(K,{children:"Configure the git remote URL for your repository. This is the origin remote used for push and pull operations."})]}),e.jsx("div",{className:"space-y-4 py-4",children:e.jsxs("div",{className:"space-y-2",children:[e.jsx(f,{htmlFor:"remote-url",children:"Remote URL"}),e.jsx(U,{id:"remote-url",placeholder:"https://github.com/username/repo.git",value:E,onChange:t=>G(t.target.value),autoComplete:"off"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Enter your repository URL (HTTPS or SSH format)."})]})}),e.jsxs(Y,{children:[e.jsx(o,{variant:"outline",onClick:()=>{R(!1),G("")},children:"Cancel"}),e.jsx(o,{onClick:Ge,disabled:ne||!E.trim(),children:ne?"Saving...":"Save"})]})]})})]})}export{Xe as default};
@@ -1,4 +1,4 @@
1
- import{c as oe,H as ve,r as u,j as e,n as se,B as x,a2 as fe,Z as Ne,aV as Te,aW as Ce,I as c,a0 as O,ac as ae,a1 as ne,T as be,v as Se,w as we,x as Ae,y as ke,z as Ie,A as ie}from"./index-Bbxvuj4b.js";import{C as y,b as g,c as j,d as v,a as f,e as Oe}from"./card-D_zGBKua.js";import{L as o}from"./label-CZGCmBD7.js";import{B as re}from"./badge-D7ZZbMEG.js";import{A as Fe,a as Pe}from"./alert-D2VTq6m-.js";import{T as Ee,a as Me,b,c as S}from"./tabs-Ug7Ug5Ha.js";import{Z as Le}from"./zap-cD8GAJPg.js";import{E as De}from"./eye-Dp6wEoME.js";import{P as E}from"./plus-Be79gWKj.js";import{C as _e,a as Ue}from"./clipboard-D3NA8gb4.js";/**
1
+ import{c as oe,H as ve,r as u,j as e,n as se,B as x,a2 as fe,Z as Ne,b3 as Te,b4 as Ce,I as c,a0 as O,ac as ae,a1 as ne,T as be,v as Se,w as we,x as Ae,y as ke,z as Ie,A as ie}from"./index-BAEEeZzi.js";import{C as y,b as g,c as j,d as v,a as f,e as Oe}from"./card-C9ekeZtD.js";import{L as o}from"./label-CRsu1MwQ.js";import{B as re}from"./badge-fHjW-wEe.js";import{A as Fe,a as Pe}from"./alert-Baaj8mli.js";import{T as Ee,a as Me,b,c as S}from"./tabs-CP_A6r0A.js";import{Z as Le}from"./zap-DOtH7YrV.js";import{E as De}from"./eye-BSR7OEmk.js";import{P as E}from"./plus-CemYz5Fm.js";import{C as _e,a as Ue}from"./clipboard-Dv0iwZO9.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -8,4 +8,4 @@ import{c as oe,H as ve,r as u,j as e,n as se,B as x,a2 as fe,Z as Ne,aV as Te,aW
8
8
  *
9
9
  * This source code is licensed under the ISC license.
10
10
  * See the LICENSE file in the root directory of this source tree.
11
- */const $e=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],qe=oe("refresh-ccw",$e),Be=["a2a_v0.2","a2a_v0.1","jsonrpc2","jsonrpc","openrpc","rest"],Ke=["GET","POST","PUT","PATCH","DELETE"],He=()=>({id:"",skill:"",description:"",endpoint:"",method:"POST",enabled:!0,inputMimeType:"application/json",outputMimeType:"application/json",inputSchema:"",outputSchema:""}),w={id:"",name:"",description:"",version:"1.0.0",url:"",documentation:"",protocols:["a2a_v0.2"],authentication:{scheme:"api_key",in:"header",name:"X-API-Key",example:"",description:""},capabilities:[],supportedInputTypes:["application/json"],supportedOutputTypes:["application/json"],security:{transport:"https",encryption:"TLS 1.3",notes:""},contact:{name:"",email:""},lastUpdated:void 0},N=a=>({...a,protocols:[...a.protocols],authentication:{...a.authentication},capabilities:a.capabilities.map(n=>({...n})),supportedInputTypes:[...a.supportedInputTypes],supportedOutputTypes:[...a.supportedOutputTypes],security:{...a.security},contact:{...a.contact}}),F=()=>N(w);function Ve(a){if(!a)return F();const n=Array.isArray(a.protocols)?a.protocols.filter(r=>typeof r=="string"):[],d=Array.isArray(a.supportedContentTypes?.input)?a.supportedContentTypes.input.filter(r=>typeof r=="string"):[],A=Array.isArray(a.supportedContentTypes?.output)?a.supportedContentTypes.output.filter(r=>typeof r=="string"):[],T=Array.isArray(a.capabilities)?a.capabilities.map(r=>({id:typeof r.id=="string"?r.id:"",skill:typeof r.skill=="string"?r.skill:"",description:typeof r.description=="string"?r.description:"",endpoint:typeof r.endpoint=="string"?r.endpoint:"",method:typeof r.method=="string"?r.method:"POST",enabled:r?.enabled!==!1,inputMimeType:typeof r.input?.mimeType=="string"?r.input.mimeType:"application/json",outputMimeType:typeof r.output?.mimeType=="string"?r.output.mimeType:"application/json",inputSchema:r.input?.schema?JSON.stringify(r.input.schema,null,2):"",outputSchema:r.output?.schema?JSON.stringify(r.output.schema,null,2):""})):[],M={scheme:typeof a.authentication?.scheme=="string"?a.authentication.scheme:"api_key",in:typeof a.authentication?.in=="string"?a.authentication.in:"header",name:typeof a.authentication?.name=="string"?a.authentication.name:"X-API-Key",example:typeof a.authentication?.example=="string"?a.authentication.example:"",description:typeof a.authentication?.description=="string"?a.authentication.description:""};return{id:typeof a.id=="string"?a.id:"",name:typeof a.name=="string"?a.name:"",description:typeof a.description=="string"?a.description:"",version:typeof a.version=="string"?a.version:"1.0.0",url:typeof a.url=="string"?a.url:"",documentation:typeof a.documentation=="string"?a.documentation:"",protocols:n.length>0?n:w.protocols,authentication:M,capabilities:T,supportedInputTypes:d.length>0?d:w.supportedInputTypes,supportedOutputTypes:A.length>0?A:w.supportedOutputTypes,security:{transport:typeof a.security?.transport=="string"?a.security.transport:w.security.transport,encryption:typeof a.security?.encryption=="string"?a.security.encryption:w.security.encryption,notes:typeof a.security?.notes=="string"?a.security.notes:""},contact:{name:typeof a.contact?.name=="string"?a.contact.name:"",email:typeof a.contact?.email=="string"?a.contact.email:""},lastUpdated:typeof a.lastUpdated=="string"?a.lastUpdated:void 0}}function at(){const{toast:a}=ve(),[n,d]=u.useState(()=>F()),[A,T]=u.useState(()=>F()),[M,r]=u.useState(!0),[L,B]=u.useState(!1),[K,k]=u.useState(null),[H,D]=u.useState(""),[V,_]=u.useState(""),[z,U]=u.useState(""),[P,R]=u.useState(void 0),[le,X]=u.useState(!1),ce=u.useMemo(()=>{const t=new Set([...Be,...n.protocols]);return Array.from(t).sort()},[n.protocols]);u.useEffect(()=>{let t=!0;return(async()=>{r(!0),k(null);try{const s=await fetch(`${ie}/api/v1/identity/agent-card`);if(!s.ok)throw new Error(`Failed to load agent card (${s.status})`);const l=await s.json();if(l.success&&l.data){const p=Ve(l.data.card||void 0);if(p.id||(p.id="urn:agent:coconut"),p.url||(p.url=`${window.location.origin}/api/v1`),p.lastUpdated=l.data.updatedAt??p.lastUpdated,t){const m=N(p);d(m),T(N(m)),R(l.data.updatedAt??m.lastUpdated)}}else{if(l.error)throw new Error(l.error);if(t){const p=F();d(p),T(N(p))}}}catch(s){if(console.error("Failed to fetch agent card",s),t){k(s instanceof Error?s.message:"Failed to load agent identity");const l=F();d(l),T(N(l))}}finally{t&&r(!1)}})(),()=>{t=!1}},[]);const de=(t,i)=>{d(s=>{const l=i?[...new Set([...s.protocols,t])]:s.protocols.filter(p=>p!==t);return{...s,protocols:l}})},Z=()=>{const t=H.trim();t&&(d(i=>({...i,protocols:[...new Set([...i.protocols,t])]})),D(""))},Y=()=>{const t=V.trim();t&&(d(i=>({...i,supportedInputTypes:[...new Set([...i.supportedInputTypes,t])]})),_(""))},G=()=>{const t=z.trim();t&&(d(i=>({...i,supportedOutputTypes:[...new Set([...i.supportedOutputTypes,t])]})),U(""))},pe=t=>{d(i=>({...i,supportedInputTypes:i.supportedInputTypes.filter(s=>s!==t)}))},ue=t=>{d(i=>({...i,supportedOutputTypes:i.supportedOutputTypes.filter(s=>s!==t)}))},C=(t,i)=>{d(s=>({...s,[t]:i}))},I=(t,i)=>{d(s=>({...s,authentication:{...s.authentication,[t]:i}}))},J=(t,i)=>{d(s=>({...s,security:{...s.security,[t]:i}}))},W=(t,i)=>{d(s=>({...s,contact:{...s.contact,[t]:i}}))},he=()=>{d(t=>({...t,capabilities:[...t.capabilities,He()]}))},h=(t,i)=>{d(s=>{const l=[...s.capabilities];return l[t]={...l[t],...i},{...s,capabilities:l}})},me=t=>{d(i=>({...i,capabilities:i.capabilities.filter((s,l)=>l!==t)}))},$=()=>{const t=[["id","Agent ID"],["name","Name"],["description","Description"],["version","Version"],["url","Service URL"]];for(const[s,l]of t){const p=n[s];if(typeof p!="string"||!p.trim())throw new Error(`${l} is required`)}const i=n.capabilities.map((s,l)=>({cap:s,index:l})).filter(({cap:s})=>s.enabled&&s.id.trim()&&s.endpoint.trim()).map(({cap:s,index:l})=>{const p=s.id.trim()||`Capability ${l+1}`,m={id:s.id.trim(),skill:s.skill.trim(),description:s.description.trim(),endpoint:s.endpoint.trim(),method:s.method||"POST"},ee=(q,je)=>{if(!(!q||!q.trim()))try{return JSON.parse(q)}catch(te){throw new Error(`${p} ${je} schema must be valid JSON. ${te?.message??te}`)}};return(s.inputMimeType?.trim()||s.inputSchema?.trim())&&(m.input={mimeType:s.inputMimeType?.trim()||"application/json",schema:ee(s.inputSchema,"input")}),(s.outputMimeType?.trim()||s.outputSchema?.trim())&&(m.output={mimeType:s.outputMimeType?.trim()||"application/json",schema:ee(s.outputSchema,"output")}),m});return{id:n.id.trim(),name:n.name.trim(),description:n.description.trim(),version:n.version.trim(),url:n.url.trim(),documentation:n.documentation.trim()||void 0,protocols:n.protocols,authentication:{scheme:n.authentication.scheme.trim()||"api_key",in:n.authentication.in.trim()||"header",name:n.authentication.name.trim()||"X-API-Key",example:n.authentication.example.trim()||void 0,description:n.authentication.description.trim()||void 0},capabilities:i,supportedContentTypes:{input:n.supportedInputTypes,output:n.supportedOutputTypes},security:{transport:n.security.transport.trim()||"https",encryption:n.security.encryption.trim()||"TLS 1.3",notes:n.security.notes.trim()||void 0},contact:{name:n.contact.name.trim()||void 0,email:n.contact.email.trim()||void 0},lastUpdated:new Date().toISOString()}},xe=async()=>{B(!0),k(null);try{const t=$(),i=await fetch(`${ie}/api/v1/identity/agent-card`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({card:t})}),s=await i.json();if(!i.ok||!s?.success)throw new Error(s?.error||"Failed to save agent card");a({title:"Agent card saved",description:"The identity card has been updated successfully."});const l=s?.data?.updatedAt??new Date().toISOString();d(p=>{const m={...p,lastUpdated:l};return T(N(m)),m}),R(l)}catch(t){console.error("Failed to save agent card",t),k(t instanceof Error?t.message:"Failed to save agent card"),a({title:"Save failed",description:t instanceof Error?t.message:"Failed to save agent card, see console for details.",variant:"destructive"})}finally{B(!1)}},ye=()=>{d(N(A)),k(null),D(""),_(""),U(""),R(A.lastUpdated??P)},ge=async()=>{try{const t=JSON.stringify($(),null,2);await navigator.clipboard.writeText(t),X(!0),setTimeout(()=>X(!1),1500),a({title:"Copied!",description:"Agent card JSON copied to clipboard."})}catch(t){console.error("Failed to copy agent card preview:",t),a({title:"Copy failed",description:"Unable to copy agent card JSON to clipboard.",variant:"destructive"})}},Q=u.useMemo(()=>{if(!P)return null;try{return new Date(P).toLocaleString()}catch{return null}},[P]);return M?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(se,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:"Loading identity card..."})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col justify-between gap-4 md:flex-row md:items-end",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Agent Identity"}),e.jsxs("p",{className:"text-muted-foreground",children:["Manage the"," ",e.jsx("a",{href:"/.well-known/agent-card.json",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4 hover:text-primary",children:"/.well-known/agent-card.json"})," ","descriptor for A2A discovery."]}),Q&&e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Last updated ",Q]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(x,{variant:"outline",onClick:ye,disabled:L,children:[e.jsx(qe,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Reset"})]}),e.jsx(x,{onClick:xe,disabled:L,children:L?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"h-4 w-4 animate-spin sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Saving..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Save Changes"})]})})]})]}),K&&e.jsxs(Fe,{variant:"destructive",children:[e.jsx("div",{className:"font-semibold",children:"Something went wrong"}),e.jsx(Pe,{children:K})]}),e.jsxs(Ee,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs(Me,{className:"grid w-full grid-cols-6 h-auto p-1",children:[e.jsxs(b,{value:"overview",className:"gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Identity"})]}),e.jsxs(b,{value:"protocols",className:"gap-2",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Protocols"})]}),e.jsxs(b,{value:"auth",className:"gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Security"})]}),e.jsxs(b,{value:"capabilities",className:"gap-2",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Capabilities"})]}),e.jsxs(b,{value:"contact",className:"gap-2",children:[e.jsx(Je,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(b,{value:"preview",className:"gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Preview"})]})]}),e.jsx(S,{value:"overview",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Identity Overview"}),e.jsx(v,{children:"Define core attributes used for discovery."})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-id",children:"Agent Identifier"}),e.jsx(c,{id:"agent-id",value:n.id,placeholder:"urn:agent:coconut-dev",onChange:t=>C("id",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-name",children:"Name"}),e.jsx(c,{id:"agent-name",value:n.name,placeholder:"Coconut Development Agent",onChange:t=>C("name",t.target.value)})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-version",children:"Version"}),e.jsx(c,{id:"agent-version",value:n.version,placeholder:"1.0.0",onChange:t=>C("version",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-url",children:"Primary Endpoint"}),e.jsx(c,{id:"agent-url",value:n.url,placeholder:"https://coconut.dev/api/v1",onChange:t=>C("url",t.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-description",children:"Description"}),e.jsx(O,{id:"agent-description",value:n.description,placeholder:"Agent responsible for managing proposals, plans, and operations...",onChange:t=>C("description",t.target.value),rows:4})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-docs",children:"Documentation URL"}),e.jsx(c,{id:"agent-docs",value:n.documentation,placeholder:"https://docs.coconut.dev/a2a",onChange:t=>C("documentation",t.target.value)})]})]})]})}),e.jsx(S,{value:"protocols",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Protocols & Content Types"}),e.jsx(v,{children:"Select supported discovery protocols and payload formats."})]}),e.jsxs(f,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Protocols"}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:ce.map(t=>e.jsxs("label",{className:"flex items-center gap-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[e.jsx(ae,{checked:n.protocols.includes(t),onCheckedChange:i=>de(t,!!i)}),e.jsx("span",{className:"text-sm font-medium",children:t})]},t))}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:H,placeholder:"Add custom protocol (press Add)",onChange:t=>D(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),Z())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:Z,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]})]}),e.jsx(ne,{}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Supported Input Types"}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:V,placeholder:"application/json",onChange:t=>_(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),Y())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:Y,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.supportedInputTypes.map(t=>e.jsxs(re,{variant:"secondary",className:"flex items-center gap-1",children:[t,e.jsx("button",{type:"button",onClick:()=>pe(t),className:"ml-1 rounded-full border border-transparent bg-transparent text-muted-foreground transition hover:text-foreground",children:"×"})]},t))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Supported Output Types"}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:z,placeholder:"application/json",onChange:t=>U(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),G())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:G,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.supportedOutputTypes.map(t=>e.jsxs(re,{variant:"secondary",className:"flex items-center gap-1",children:[t,e.jsx("button",{type:"button",onClick:()=>ue(t),className:"ml-1 rounded-full border border-transparent bg-transparent text-muted-foreground transition hover:text-foreground",children:"×"})]},t))})]})]})]})]})}),e.jsx(S,{value:"auth",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Authentication & Security"}),e.jsx(v,{children:"Document how peer agents should authenticate and connect."})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-scheme",children:"Authentication Scheme"}),e.jsx(c,{id:"auth-scheme",value:n.authentication.scheme,placeholder:"api_key",onChange:t=>I("scheme",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-in",children:"Credential Location"}),e.jsx(c,{id:"auth-in",value:n.authentication.in,placeholder:"header",onChange:t=>I("in",t.target.value)})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-name",children:"Header or Field Name"}),e.jsx(c,{id:"auth-name",value:n.authentication.name,placeholder:"X-API-Key",onChange:t=>I("name",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-example",children:"Example Secret"}),e.jsx(c,{id:"auth-example",value:n.authentication.example,placeholder:"nut_***************",onChange:t=>I("example",t.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-description",children:"Authentication Notes"}),e.jsx(O,{id:"auth-description",value:n.authentication.description,placeholder:"Provide API key via X-API-Key header to authenticate requests between agents.",onChange:t=>I("description",t.target.value),rows:3})]}),e.jsx(ne,{}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-transport",children:"Transport"}),e.jsx(c,{id:"security-transport",value:n.security.transport,placeholder:"https",onChange:t=>J("transport",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-encryption",children:"Encryption"}),e.jsx(c,{id:"security-encryption",value:n.security.encryption,placeholder:"TLS 1.3",onChange:t=>J("encryption",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-notes",children:"Security Notes"}),e.jsx(c,{id:"security-notes",value:n.security.notes,placeholder:"Requests must be encrypted over TLS.",onChange:t=>J("notes",t.target.value)})]})]})]})]})}),e.jsx(S,{value:"capabilities",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Capabilities"}),e.jsx(v,{children:"Describe the skills other agents can invoke."})]}),e.jsxs(f,{className:"space-y-4",children:[n.capabilities.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border bg-muted/40 p-6 text-center text-sm text-muted-foreground",children:"No capabilities defined yet. Add one to expose functionality for peer agents."}),n.capabilities.map((t,i)=>e.jsxs(y,{className:"border border-border/60",children:[e.jsxs(g,{className:"flex flex-col gap-2 space-y-0 md:flex-row md:items-center",children:[e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsxs(j,{className:"text-lg font-semibold",children:["Capability #",i+1]}),e.jsx(v,{children:"Toggle availability and describe request contracts."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ae,{checked:t.enabled,onCheckedChange:s=>h(i,{enabled:!!s})}),"Expose capability"]}),e.jsxs(x,{size:"icon",variant:"ghost",onClick:()=>me(i),title:"Remove capability",children:[e.jsx(be,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Remove capability"})]})]})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Capability ID"}),e.jsx(c,{value:t.id,placeholder:"create-proposal",onChange:s=>h(i,{id:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Skill"}),e.jsx(c,{value:t.skill,placeholder:"proposal_management.create",onChange:s=>h(i,{skill:s.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Description"}),e.jsx(O,{value:t.description,placeholder:"Creates a new proposal record containing intent, plan, and artifacts.",rows:3,onChange:s=>h(i,{description:s.target.value})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Endpoint"}),e.jsx(c,{value:t.endpoint,placeholder:"https://coconut.dev/api/v1/proposals",onChange:s=>h(i,{endpoint:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"HTTP Method"}),e.jsxs(Se,{value:t.method,onValueChange:s=>h(i,{method:s}),children:[e.jsx(we,{children:e.jsx(Ae,{placeholder:"Select method"})}),e.jsx(ke,{children:Ke.map(s=>e.jsx(Ie,{value:s,children:s},s))})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Input MIME Type"}),e.jsx(c,{value:t.inputMimeType??"",placeholder:"application/json",onChange:s=>h(i,{inputMimeType:s.target.value})}),e.jsx(o,{children:"Input Schema (JSON)"}),e.jsx(O,{value:t.inputSchema??"",placeholder:'{ "type": "object", "properties": { "title": { "type": "string" } } }',rows:5,onChange:s=>h(i,{inputSchema:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Output MIME Type"}),e.jsx(c,{value:t.outputMimeType??"",placeholder:"application/json",onChange:s=>h(i,{outputMimeType:s.target.value})}),e.jsx(o,{children:"Output Schema (JSON)"}),e.jsx(O,{value:t.outputSchema??"",placeholder:'{ "type": "object", "properties": { "status": { "type": "string" } } }',rows:5,onChange:s=>h(i,{outputSchema:s.target.value})})]})]})]})]},`${t.id||"capability"}-${i}`))]}),e.jsx(Oe,{children:e.jsxs(x,{type:"button",variant:"outline",onClick:he,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add Capability"]})})]})}),e.jsx(S,{value:"contact",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Contact"}),e.jsx(v,{children:"Provide a human escalation path for peer agents."})]}),e.jsxs(f,{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"contact-name",children:"Contact Name"}),e.jsx(c,{id:"contact-name",value:n.contact.name,placeholder:"Coconut DevOps Team",onChange:t=>W("name",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"contact-email",children:"Contact Email"}),e.jsx(c,{id:"contact-email",value:n.contact.email,placeholder:"support@coconut.dev",onChange:t=>W("email",t.target.value)})]})]})]})}),e.jsx(S,{value:"preview",children:e.jsxs(y,{children:[e.jsx(g,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Preview"}),e.jsx(v,{children:"Review the JSON payload served at /.well-known/agent-card.json."})]}),e.jsx(x,{variant:"outline",size:"sm",onClick:ge,children:le?e.jsxs(e.Fragment,{children:[e.jsx(_e,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Copy"})]})})]})}),e.jsx(f,{children:e.jsx("pre",{className:"max-h-96 overflow-auto rounded-md bg-muted p-4 text-sm",children:JSON.stringify((()=>{try{return $()}catch{return{id:n.id,name:n.name,description:n.description,version:n.version,url:n.url,protocols:n.protocols}}})(),null,2)})})]})})]})]})}export{at as default};
11
+ */const $e=[["path",{d:"M21 12a9 9 0 0 0-9-9 9.75 9.75 0 0 0-6.74 2.74L3 8",key:"14sxne"}],["path",{d:"M3 3v5h5",key:"1xhq8a"}],["path",{d:"M3 12a9 9 0 0 0 9 9 9.75 9.75 0 0 0 6.74-2.74L21 16",key:"1hlbsb"}],["path",{d:"M16 16h5v5",key:"ccwih5"}]],qe=oe("refresh-ccw",$e),Be=["a2a_v0.2","a2a_v0.1","jsonrpc2","jsonrpc","openrpc","rest"],Ke=["GET","POST","PUT","PATCH","DELETE"],He=()=>({id:"",skill:"",description:"",endpoint:"",method:"POST",enabled:!0,inputMimeType:"application/json",outputMimeType:"application/json",inputSchema:"",outputSchema:""}),w={id:"",name:"",description:"",version:"1.0.0",url:"",documentation:"",protocols:["a2a_v0.2"],authentication:{scheme:"api_key",in:"header",name:"X-API-Key",example:"",description:""},capabilities:[],supportedInputTypes:["application/json"],supportedOutputTypes:["application/json"],security:{transport:"https",encryption:"TLS 1.3",notes:""},contact:{name:"",email:""},lastUpdated:void 0},N=a=>({...a,protocols:[...a.protocols],authentication:{...a.authentication},capabilities:a.capabilities.map(n=>({...n})),supportedInputTypes:[...a.supportedInputTypes],supportedOutputTypes:[...a.supportedOutputTypes],security:{...a.security},contact:{...a.contact}}),F=()=>N(w);function ze(a){if(!a)return F();const n=Array.isArray(a.protocols)?a.protocols.filter(r=>typeof r=="string"):[],d=Array.isArray(a.supportedContentTypes?.input)?a.supportedContentTypes.input.filter(r=>typeof r=="string"):[],A=Array.isArray(a.supportedContentTypes?.output)?a.supportedContentTypes.output.filter(r=>typeof r=="string"):[],T=Array.isArray(a.capabilities)?a.capabilities.map(r=>({id:typeof r.id=="string"?r.id:"",skill:typeof r.skill=="string"?r.skill:"",description:typeof r.description=="string"?r.description:"",endpoint:typeof r.endpoint=="string"?r.endpoint:"",method:typeof r.method=="string"?r.method:"POST",enabled:r?.enabled!==!1,inputMimeType:typeof r.input?.mimeType=="string"?r.input.mimeType:"application/json",outputMimeType:typeof r.output?.mimeType=="string"?r.output.mimeType:"application/json",inputSchema:r.input?.schema?JSON.stringify(r.input.schema,null,2):"",outputSchema:r.output?.schema?JSON.stringify(r.output.schema,null,2):""})):[],M={scheme:typeof a.authentication?.scheme=="string"?a.authentication.scheme:"api_key",in:typeof a.authentication?.in=="string"?a.authentication.in:"header",name:typeof a.authentication?.name=="string"?a.authentication.name:"X-API-Key",example:typeof a.authentication?.example=="string"?a.authentication.example:"",description:typeof a.authentication?.description=="string"?a.authentication.description:""};return{id:typeof a.id=="string"?a.id:"",name:typeof a.name=="string"?a.name:"",description:typeof a.description=="string"?a.description:"",version:typeof a.version=="string"?a.version:"1.0.0",url:typeof a.url=="string"?a.url:"",documentation:typeof a.documentation=="string"?a.documentation:"",protocols:n.length>0?n:w.protocols,authentication:M,capabilities:T,supportedInputTypes:d.length>0?d:w.supportedInputTypes,supportedOutputTypes:A.length>0?A:w.supportedOutputTypes,security:{transport:typeof a.security?.transport=="string"?a.security.transport:w.security.transport,encryption:typeof a.security?.encryption=="string"?a.security.encryption:w.security.encryption,notes:typeof a.security?.notes=="string"?a.security.notes:""},contact:{name:typeof a.contact?.name=="string"?a.contact.name:"",email:typeof a.contact?.email=="string"?a.contact.email:""},lastUpdated:typeof a.lastUpdated=="string"?a.lastUpdated:void 0}}function at(){const{toast:a}=ve(),[n,d]=u.useState(()=>F()),[A,T]=u.useState(()=>F()),[M,r]=u.useState(!0),[L,B]=u.useState(!1),[K,k]=u.useState(null),[H,D]=u.useState(""),[z,_]=u.useState(""),[V,U]=u.useState(""),[P,R]=u.useState(void 0),[le,X]=u.useState(!1),ce=u.useMemo(()=>{const t=new Set([...Be,...n.protocols]);return Array.from(t).sort()},[n.protocols]);u.useEffect(()=>{let t=!0;return(async()=>{r(!0),k(null);try{const s=await fetch(`${ie}/api/v1/identity/agent-card`);if(!s.ok)throw new Error(`Failed to load agent card (${s.status})`);const l=await s.json();if(l.success&&l.data){const p=ze(l.data.card||void 0);if(p.id||(p.id="urn:agent:coconut"),p.url||(p.url=`${window.location.origin}/api/v1`),p.lastUpdated=l.data.updatedAt??p.lastUpdated,t){const m=N(p);d(m),T(N(m)),R(l.data.updatedAt??m.lastUpdated)}}else{if(l.error)throw new Error(l.error);if(t){const p=F();d(p),T(N(p))}}}catch(s){if(console.error("Failed to fetch agent card",s),t){k(s instanceof Error?s.message:"Failed to load agent identity");const l=F();d(l),T(N(l))}}finally{t&&r(!1)}})(),()=>{t=!1}},[]);const de=(t,i)=>{d(s=>{const l=i?[...new Set([...s.protocols,t])]:s.protocols.filter(p=>p!==t);return{...s,protocols:l}})},Z=()=>{const t=H.trim();t&&(d(i=>({...i,protocols:[...new Set([...i.protocols,t])]})),D(""))},Y=()=>{const t=z.trim();t&&(d(i=>({...i,supportedInputTypes:[...new Set([...i.supportedInputTypes,t])]})),_(""))},G=()=>{const t=V.trim();t&&(d(i=>({...i,supportedOutputTypes:[...new Set([...i.supportedOutputTypes,t])]})),U(""))},pe=t=>{d(i=>({...i,supportedInputTypes:i.supportedInputTypes.filter(s=>s!==t)}))},ue=t=>{d(i=>({...i,supportedOutputTypes:i.supportedOutputTypes.filter(s=>s!==t)}))},C=(t,i)=>{d(s=>({...s,[t]:i}))},I=(t,i)=>{d(s=>({...s,authentication:{...s.authentication,[t]:i}}))},J=(t,i)=>{d(s=>({...s,security:{...s.security,[t]:i}}))},Q=(t,i)=>{d(s=>({...s,contact:{...s.contact,[t]:i}}))},he=()=>{d(t=>({...t,capabilities:[...t.capabilities,He()]}))},h=(t,i)=>{d(s=>{const l=[...s.capabilities];return l[t]={...l[t],...i},{...s,capabilities:l}})},me=t=>{d(i=>({...i,capabilities:i.capabilities.filter((s,l)=>l!==t)}))},$=()=>{const t=[["id","Agent ID"],["name","Name"],["description","Description"],["version","Version"],["url","Service URL"]];for(const[s,l]of t){const p=n[s];if(typeof p!="string"||!p.trim())throw new Error(`${l} is required`)}const i=n.capabilities.map((s,l)=>({cap:s,index:l})).filter(({cap:s})=>s.enabled&&s.id.trim()&&s.endpoint.trim()).map(({cap:s,index:l})=>{const p=s.id.trim()||`Capability ${l+1}`,m={id:s.id.trim(),skill:s.skill.trim(),description:s.description.trim(),endpoint:s.endpoint.trim(),method:s.method||"POST"},ee=(q,je)=>{if(!(!q||!q.trim()))try{return JSON.parse(q)}catch(te){throw new Error(`${p} ${je} schema must be valid JSON. ${te?.message??te}`)}};return(s.inputMimeType?.trim()||s.inputSchema?.trim())&&(m.input={mimeType:s.inputMimeType?.trim()||"application/json",schema:ee(s.inputSchema,"input")}),(s.outputMimeType?.trim()||s.outputSchema?.trim())&&(m.output={mimeType:s.outputMimeType?.trim()||"application/json",schema:ee(s.outputSchema,"output")}),m});return{id:n.id.trim(),name:n.name.trim(),description:n.description.trim(),version:n.version.trim(),url:n.url.trim(),documentation:n.documentation.trim()||void 0,protocols:n.protocols,authentication:{scheme:n.authentication.scheme.trim()||"api_key",in:n.authentication.in.trim()||"header",name:n.authentication.name.trim()||"X-API-Key",example:n.authentication.example.trim()||void 0,description:n.authentication.description.trim()||void 0},capabilities:i,supportedContentTypes:{input:n.supportedInputTypes,output:n.supportedOutputTypes},security:{transport:n.security.transport.trim()||"https",encryption:n.security.encryption.trim()||"TLS 1.3",notes:n.security.notes.trim()||void 0},contact:{name:n.contact.name.trim()||void 0,email:n.contact.email.trim()||void 0},lastUpdated:new Date().toISOString()}},xe=async()=>{B(!0),k(null);try{const t=$(),i=await fetch(`${ie}/api/v1/identity/agent-card`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({card:t})}),s=await i.json();if(!i.ok||!s?.success)throw new Error(s?.error||"Failed to save agent card");a({title:"Agent card saved",description:"The identity card has been updated successfully."});const l=s?.data?.updatedAt??new Date().toISOString();d(p=>{const m={...p,lastUpdated:l};return T(N(m)),m}),R(l)}catch(t){console.error("Failed to save agent card",t),k(t instanceof Error?t.message:"Failed to save agent card"),a({title:"Save failed",description:t instanceof Error?t.message:"Failed to save agent card, see console for details.",variant:"destructive"})}finally{B(!1)}},ye=()=>{d(N(A)),k(null),D(""),_(""),U(""),R(A.lastUpdated??P)},ge=async()=>{try{const t=JSON.stringify($(),null,2);await navigator.clipboard.writeText(t),X(!0),setTimeout(()=>X(!1),1500),a({title:"Copied!",description:"Agent card JSON copied to clipboard."})}catch(t){console.error("Failed to copy agent card preview:",t),a({title:"Copy failed",description:"Unable to copy agent card JSON to clipboard.",variant:"destructive"})}},W=u.useMemo(()=>{if(!P)return null;try{return new Date(P).toLocaleString()}catch{return null}},[P]);return M?e.jsx("div",{className:"flex h-full items-center justify-center",children:e.jsxs("div",{className:"flex items-center gap-2 text-muted-foreground",children:[e.jsx(se,{className:"h-5 w-5 animate-spin"}),e.jsx("span",{children:"Loading identity card..."})]})}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex flex-col justify-between gap-4 md:flex-row md:items-end",children:[e.jsxs("div",{children:[e.jsx("h1",{className:"text-3xl font-bold",children:"Agent Identity"}),e.jsxs("p",{className:"text-muted-foreground",children:["Manage the"," ",e.jsx("a",{href:"/.well-known/agent-card.json",target:"_blank",rel:"noopener noreferrer",className:"underline underline-offset-4 hover:text-primary",children:"/.well-known/agent-card.json"})," ","descriptor for A2A discovery."]}),W&&e.jsxs("p",{className:"mt-1 text-sm text-muted-foreground",children:["Last updated ",W]})]}),e.jsxs("div",{className:"flex flex-wrap items-center gap-2",children:[e.jsxs(x,{variant:"outline",onClick:ye,disabled:L,children:[e.jsx(qe,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Reset"})]}),e.jsx(x,{onClick:xe,disabled:L,children:L?e.jsxs(e.Fragment,{children:[e.jsx(se,{className:"h-4 w-4 animate-spin sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Saving..."})]}):e.jsxs(e.Fragment,{children:[e.jsx(fe,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Save Changes"})]})})]})]}),K&&e.jsxs(Fe,{variant:"destructive",children:[e.jsx("div",{className:"font-semibold",children:"Something went wrong"}),e.jsx(Pe,{children:K})]}),e.jsxs(Ee,{defaultValue:"overview",className:"space-y-6",children:[e.jsxs(Me,{className:"grid w-full grid-cols-6 h-auto p-1",children:[e.jsxs(b,{value:"overview",className:"gap-2",children:[e.jsx(Ne,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Identity"})]}),e.jsxs(b,{value:"protocols",className:"gap-2",children:[e.jsx(Te,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Protocols"})]}),e.jsxs(b,{value:"auth",className:"gap-2",children:[e.jsx(Ce,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Security"})]}),e.jsxs(b,{value:"capabilities",className:"gap-2",children:[e.jsx(Le,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Capabilities"})]}),e.jsxs(b,{value:"contact",className:"gap-2",children:[e.jsx(Je,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Contact"})]}),e.jsxs(b,{value:"preview",className:"gap-2",children:[e.jsx(De,{className:"h-4 w-4"}),e.jsx("span",{className:"hidden sm:inline",children:"Preview"})]})]}),e.jsx(S,{value:"overview",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Identity Overview"}),e.jsx(v,{children:"Define core attributes used for discovery."})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-id",children:"Agent Identifier"}),e.jsx(c,{id:"agent-id",value:n.id,placeholder:"urn:agent:coconut-dev",onChange:t=>C("id",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-name",children:"Name"}),e.jsx(c,{id:"agent-name",value:n.name,placeholder:"Coconut Development Agent",onChange:t=>C("name",t.target.value)})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-version",children:"Version"}),e.jsx(c,{id:"agent-version",value:n.version,placeholder:"1.0.0",onChange:t=>C("version",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-url",children:"Primary Endpoint"}),e.jsx(c,{id:"agent-url",value:n.url,placeholder:"https://coconut.dev/api/v1",onChange:t=>C("url",t.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-description",children:"Description"}),e.jsx(O,{id:"agent-description",value:n.description,placeholder:"Agent responsible for managing proposals, plans, and operations...",onChange:t=>C("description",t.target.value),rows:4})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"agent-docs",children:"Documentation URL"}),e.jsx(c,{id:"agent-docs",value:n.documentation,placeholder:"https://docs.coconut.dev/a2a",onChange:t=>C("documentation",t.target.value)})]})]})]})}),e.jsx(S,{value:"protocols",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Protocols & Content Types"}),e.jsx(v,{children:"Select supported discovery protocols and payload formats."})]}),e.jsxs(f,{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Protocols"}),e.jsx("div",{className:"grid gap-2 md:grid-cols-3",children:ce.map(t=>e.jsxs("label",{className:"flex items-center gap-2 rounded-md border border-border bg-muted/20 px-3 py-2",children:[e.jsx(ae,{checked:n.protocols.includes(t),onCheckedChange:i=>de(t,!!i)}),e.jsx("span",{className:"text-sm font-medium",children:t})]},t))}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:H,placeholder:"Add custom protocol (press Add)",onChange:t=>D(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),Z())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:Z,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]})]}),e.jsx(ne,{}),e.jsxs("div",{className:"grid gap-6 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Supported Input Types"}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:z,placeholder:"application/json",onChange:t=>_(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),Y())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:Y,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.supportedInputTypes.map(t=>e.jsxs(re,{variant:"secondary",className:"flex items-center gap-1",children:[t,e.jsx("button",{type:"button",onClick:()=>pe(t),className:"ml-1 rounded-full border border-transparent bg-transparent text-muted-foreground transition hover:text-foreground",children:"×"})]},t))})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Supported Output Types"}),e.jsxs("div",{className:"flex flex-col gap-2 md:flex-row",children:[e.jsx(c,{value:V,placeholder:"application/json",onChange:t=>U(t.target.value),onKeyDown:t=>{t.key==="Enter"&&(t.preventDefault(),G())}}),e.jsxs(x,{type:"button",variant:"outline",onClick:G,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add"]})]}),e.jsx("div",{className:"flex flex-wrap gap-2",children:n.supportedOutputTypes.map(t=>e.jsxs(re,{variant:"secondary",className:"flex items-center gap-1",children:[t,e.jsx("button",{type:"button",onClick:()=>ue(t),className:"ml-1 rounded-full border border-transparent bg-transparent text-muted-foreground transition hover:text-foreground",children:"×"})]},t))})]})]})]})]})}),e.jsx(S,{value:"auth",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Authentication & Security"}),e.jsx(v,{children:"Document how peer agents should authenticate and connect."})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-scheme",children:"Authentication Scheme"}),e.jsx(c,{id:"auth-scheme",value:n.authentication.scheme,placeholder:"api_key",onChange:t=>I("scheme",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-in",children:"Credential Location"}),e.jsx(c,{id:"auth-in",value:n.authentication.in,placeholder:"header",onChange:t=>I("in",t.target.value)})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-name",children:"Header or Field Name"}),e.jsx(c,{id:"auth-name",value:n.authentication.name,placeholder:"X-API-Key",onChange:t=>I("name",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-example",children:"Example Secret"}),e.jsx(c,{id:"auth-example",value:n.authentication.example,placeholder:"nut_***************",onChange:t=>I("example",t.target.value)})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"auth-description",children:"Authentication Notes"}),e.jsx(O,{id:"auth-description",value:n.authentication.description,placeholder:"Provide API key via X-API-Key header to authenticate requests between agents.",onChange:t=>I("description",t.target.value),rows:3})]}),e.jsx(ne,{}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-3",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-transport",children:"Transport"}),e.jsx(c,{id:"security-transport",value:n.security.transport,placeholder:"https",onChange:t=>J("transport",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-encryption",children:"Encryption"}),e.jsx(c,{id:"security-encryption",value:n.security.encryption,placeholder:"TLS 1.3",onChange:t=>J("encryption",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"security-notes",children:"Security Notes"}),e.jsx(c,{id:"security-notes",value:n.security.notes,placeholder:"Requests must be encrypted over TLS.",onChange:t=>J("notes",t.target.value)})]})]})]})]})}),e.jsx(S,{value:"capabilities",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Capabilities"}),e.jsx(v,{children:"Describe the skills other agents can invoke."})]}),e.jsxs(f,{className:"space-y-4",children:[n.capabilities.length===0&&e.jsx("div",{className:"rounded-lg border border-dashed border-border bg-muted/40 p-6 text-center text-sm text-muted-foreground",children:"No capabilities defined yet. Add one to expose functionality for peer agents."}),n.capabilities.map((t,i)=>e.jsxs(y,{className:"border border-border/60",children:[e.jsxs(g,{className:"flex flex-col gap-2 space-y-0 md:flex-row md:items-center",children:[e.jsxs("div",{className:"flex flex-1 flex-col",children:[e.jsxs(j,{className:"text-lg font-semibold",children:["Capability #",i+1]}),e.jsx(v,{children:"Toggle availability and describe request contracts."})]}),e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsxs("label",{className:"flex items-center gap-2 text-sm font-medium",children:[e.jsx(ae,{checked:t.enabled,onCheckedChange:s=>h(i,{enabled:!!s})}),"Expose capability"]}),e.jsxs(x,{size:"icon",variant:"ghost",onClick:()=>me(i),title:"Remove capability",children:[e.jsx(be,{className:"h-4 w-4"}),e.jsx("span",{className:"sr-only",children:"Remove capability"})]})]})]}),e.jsxs(f,{className:"space-y-4",children:[e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Capability ID"}),e.jsx(c,{value:t.id,placeholder:"create-proposal",onChange:s=>h(i,{id:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Skill"}),e.jsx(c,{value:t.skill,placeholder:"proposal_management.create",onChange:s=>h(i,{skill:s.target.value})})]})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Description"}),e.jsx(O,{value:t.description,placeholder:"Creates a new proposal record containing intent, plan, and artifacts.",rows:3,onChange:s=>h(i,{description:s.target.value})})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Endpoint"}),e.jsx(c,{value:t.endpoint,placeholder:"https://coconut.dev/api/v1/proposals",onChange:s=>h(i,{endpoint:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"HTTP Method"}),e.jsxs(Se,{value:t.method,onValueChange:s=>h(i,{method:s}),children:[e.jsx(we,{children:e.jsx(Ae,{placeholder:"Select method"})}),e.jsx(ke,{children:Ke.map(s=>e.jsx(Ie,{value:s,children:s},s))})]})]})]}),e.jsxs("div",{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Input MIME Type"}),e.jsx(c,{value:t.inputMimeType??"",placeholder:"application/json",onChange:s=>h(i,{inputMimeType:s.target.value})}),e.jsx(o,{children:"Input Schema (JSON)"}),e.jsx(O,{value:t.inputSchema??"",placeholder:'{ "type": "object", "properties": { "title": { "type": "string" } } }',rows:5,onChange:s=>h(i,{inputSchema:s.target.value})})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{children:"Output MIME Type"}),e.jsx(c,{value:t.outputMimeType??"",placeholder:"application/json",onChange:s=>h(i,{outputMimeType:s.target.value})}),e.jsx(o,{children:"Output Schema (JSON)"}),e.jsx(O,{value:t.outputSchema??"",placeholder:'{ "type": "object", "properties": { "status": { "type": "string" } } }',rows:5,onChange:s=>h(i,{outputSchema:s.target.value})})]})]})]})]},`${t.id||"capability"}-${i}`))]}),e.jsx(Oe,{children:e.jsxs(x,{type:"button",variant:"outline",onClick:he,children:[e.jsx(E,{className:"mr-2 h-4 w-4"}),"Add Capability"]})})]})}),e.jsx(S,{value:"contact",children:e.jsxs(y,{children:[e.jsxs(g,{children:[e.jsx(j,{children:"Contact"}),e.jsx(v,{children:"Provide a human escalation path for peer agents."})]}),e.jsxs(f,{className:"grid gap-4 md:grid-cols-2",children:[e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"contact-name",children:"Contact Name"}),e.jsx(c,{id:"contact-name",value:n.contact.name,placeholder:"Coconut DevOps Team",onChange:t=>Q("name",t.target.value)})]}),e.jsxs("div",{className:"space-y-2",children:[e.jsx(o,{htmlFor:"contact-email",children:"Contact Email"}),e.jsx(c,{id:"contact-email",value:n.contact.email,placeholder:"support@coconut.dev",onChange:t=>Q("email",t.target.value)})]})]})]})}),e.jsx(S,{value:"preview",children:e.jsxs(y,{children:[e.jsx(g,{children:e.jsxs("div",{className:"flex items-center justify-between gap-4",children:[e.jsxs("div",{children:[e.jsx(j,{children:"Preview"}),e.jsx(v,{children:"Review the JSON payload served at /.well-known/agent-card.json."})]}),e.jsx(x,{variant:"outline",size:"sm",onClick:ge,children:le?e.jsxs(e.Fragment,{children:[e.jsx(_e,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Copied"})]}):e.jsxs(e.Fragment,{children:[e.jsx(Ue,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Copy"})]})})]})}),e.jsx(f,{children:e.jsx("pre",{className:"max-h-96 overflow-auto rounded-md bg-muted p-4 text-sm",children:JSON.stringify((()=>{try{return $()}catch{return{id:n.id,name:n.name,description:n.description,version:n.version,url:n.url,protocols:n.protocols}}})(),null,2)})})]})})]})]})}export{at as default};
@@ -1,4 +1,4 @@
1
- import{c as u,j as e,f as p,B as r,T as x,I as j,v,w as y,x as S,y as f,z as g}from"./index-Bbxvuj4b.js";import{L as c}from"./label-CZGCmBD7.js";import{P as b}from"./plus-Be79gWKj.js";/**
1
+ import{c as u,j as e,f as p,B as r,T as x,I as j,v,w as y,x as S,y as f,z as g}from"./index-BAEEeZzi.js";import{L as c}from"./label-CRsu1MwQ.js";import{P as b}from"./plus-CemYz5Fm.js";/**
2
2
  * @license lucide-react v0.542.0 - ISC
3
3
  *
4
4
  * This source code is licensed under the ISC license.
@@ -1 +1 @@
1
- import{r as d,aZ as T,aX as I,t as n,j as e,a1 as E,f as j,s as y,C as N,ah as v,I as k,B as r,T as b,a2 as w,aj as q,v as X,w as Z,x as Q,y as W,z as ee}from"./index-Bbxvuj4b.js";import{C as U,b as Y,c as J,d as H,a as V}from"./card-D_zGBKua.js";import{L as m}from"./label-CZGCmBD7.js";function re(){const[t,F]=d.useState({}),[i,_]=d.useState(!0),[z,O]=d.useState(!1),[x,R]=d.useState({}),[C,G]=d.useState({}),[M,D]=d.useState(T()[0]?.id||"openai/gpt-4o"),[l,B]=d.useState({openrouter:!1,replicate:!1,anthropic:!1,openai:!1,gemini:!1,factorydroid:!1});d.useEffect(()=>{P()},[]);const P=async()=>{try{_(!0);const s=await I("/api/v1/config?type=global");if(s.success&&s.data){const a=s.data.apiKeys||{},c={},o={};for(const A of["openrouter","replicate","anthropic","openai","gemini","factorydroid"]){const K=a[A];K&&typeof K=="string"&&K.trim()!==""?(c[A]=!0,o[A]="***"):(c[A]=!1,o[A]="")}F(o);const S=s.data.defaults&&s.data.defaults.model?String(s.data.defaults.model):void 0;D(S||T()[0]?.id||"openai/gpt-4o")}}catch(s){console.error("Failed to load API keys:",s),n({title:"Error",description:"Failed to load API keys",variant:"destructive"})}finally{_(!1)}},h=(s,a)=>{F(c=>({...c,[s]:a}))},L=async s=>{try{G(S=>({...S,[s]:!0}));const a=t[s],c={provider:s};a&&a!=="***"&&(c.key=a);const o=await I("/api/v1/config/test",{method:"POST",body:JSON.stringify(c)});o.success&&o.message?n({title:"Test Result",description:o.message}):o.success?n({title:"Test Result",description:"Success"}):n({title:"Test Failed",description:o.message||"Unknown error",variant:"destructive"})}catch(a){n({title:"Test Failed",description:a instanceof Error?a.message:"Unknown error",variant:"destructive"})}finally{G(a=>({...a,[s]:!1}))}},p=s=>{B(a=>({...a,[s]:!a[s]}))},u=async s=>{try{const a={[s]:""};await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({apiKeys:a})}),n({title:"Success",description:`${s} API key cleared`}),await P()}catch(a){console.error("Failed to clear API key:",a),n({title:"Error",description:"Failed to clear API key",variant:"destructive"})}},f=async s=>{try{R(c=>({...c,[s]:!0}));const a={[s]:t[s]};await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({apiKeys:a})}),n({title:"Success",description:`${s} API key saved`}),await P()}catch(a){console.error("Failed to save API key:",a),n({title:"Error",description:"Failed to save API key",variant:"destructive"})}finally{R(a=>({...a,[s]:!1}))}},$=async()=>{try{O(!0),await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({defaults:{model:M}})}),n({title:"Success",description:"Default model saved successfully"})}catch(s){console.error("Failed to save default model:",s),n({title:"Error",description:"Failed to save default model",variant:"destructive"})}finally{O(!1)}},g={openrouter:"OPENROUTER_API_KEY",replicate:"REPLICATE_API_TOKEN",anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY",gemini:"GEMINI_API_KEY",factorydroid:"FACTORY_API_KEY"};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI & LLM"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure Coconut's connections to LLM providers."})]}),e.jsx(E,{}),e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsx(J,{children:"API Keys & Authentication"}),e.jsx(H,{children:"Manage API keys and authentication tokens for integrated services."})]}),e.jsxs(V,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"AI Assistant API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keys used by the AI Assistant sidebar for chat and code suggestions."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("openrouter"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.openrouter&&t.openrouter!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.openrouter?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"OpenRouter"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.openrouter})]})]}),t.openrouter&&t.openrouter!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.openrouter&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"openrouterKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"openrouterKey",type:"password",placeholder:"sk-or-v1-...",className:"flex-1",value:t.openrouter||"",onChange:s=>h("openrouter",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("openrouter"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>L("openrouter"),disabled:!!C.openrouter,title:"Test API key",children:C.openrouter?"Testing...":"Test"}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("openrouter"),disabled:x.openrouter||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"OpenRouter"})]})]})]}),e.jsx(E,{className:"my-6"}),e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"Resource Creation API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keys used for generating images and other resources."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("replicate"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.replicate&&t.replicate!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.replicate?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Replicate"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.replicate})]})]}),t.replicate&&t.replicate!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.replicate&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"replicateKey",children:"API Token"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"replicateKey",type:"password",placeholder:"r8_...",className:"flex-1",value:t.replicate||"",onChange:s=>h("replicate",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("replicate"),title:"Clear API token",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>L("replicate"),disabled:!!C.replicate,title:"Test API token",children:C.replicate?"Testing...":"Test"}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("replicate"),disabled:x.replicate||i,title:"Save API token",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your token from"," ",e.jsx("a",{href:"https://replicate.com/account/api-tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Replicate"})]})]})]}),e.jsx(E,{className:"my-6"}),e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"Coding Agent API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These keys are automatically provided to coding agents when they start running."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("anthropic"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.anthropic&&t.anthropic!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.anthropic?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Anthropic Claude"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.anthropic})]})]}),t.anthropic&&t.anthropic!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.anthropic&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"anthropicKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"anthropicKey",type:"password",placeholder:"sk-ant-...",className:"flex-1",value:t.anthropic||"",onChange:s=>h("anthropic",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("anthropic"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("anthropic"),disabled:x.anthropic||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://console.anthropic.com/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Anthropic Console"})]})]})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("openai"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.openai&&t.openai!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.openai?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"OpenAI"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.openai})]})]}),t.openai&&t.openai!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.openai&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"openaiKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"openaiKey",type:"password",placeholder:"sk-...",className:"flex-1",value:t.openai||"",onChange:s=>h("openai",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("openai"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("openai"),disabled:x.openai||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"OpenAI Platform"})]})]})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("gemini"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.gemini&&t.gemini!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.gemini?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Google Gemini"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.gemini})]})]}),t.gemini&&t.gemini!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.gemini&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"geminiKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"geminiKey",type:"password",placeholder:"AIza...",className:"flex-1",value:t.gemini||"",onChange:s=>h("gemini",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("gemini"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("gemini"),disabled:x.gemini||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://makersuite.google.com/app/apikey",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Google AI Studio"})]})]})]}),e.jsxs("div",{className:"border rounded-lg mt-4",children:[e.jsxs("button",{onClick:()=>p("factorydroid"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.factorydroid&&t.factorydroid!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.factorydroid?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Factory Droid"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.factorydroid})]})]}),t.factorydroid&&t.factorydroid!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.factorydroid&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"factorydroidKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"factorydroidKey",type:"password",placeholder:"fd-...",className:"flex-1",value:t.factorydroid||"",onChange:s=>h("factorydroid",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("factorydroid"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("factorydroid"),disabled:x.factorydroid||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://factorydroid.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Factory Droid"})]})]})]})]})]}),e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),e.jsx(J,{children:"AI Assistant Settings"})]}),e.jsx(H,{children:"Configure default AI model and behavior for the AI assistant sidebar."})]}),e.jsxs(V,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"defaultModel",children:"Default AI Model"}),e.jsxs(X,{value:M,onValueChange:D,children:[e.jsx(Z,{children:e.jsx(Q,{placeholder:"Select default AI model"})}),e.jsx(W,{children:T().map(s=>e.jsx(ee,{value:s.id,children:s.label},s.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This model will be selected by default when opening the AI assistant."})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(r,{onClick:$,disabled:z||i,children:z?"Saving...":"Save"})})]})]})]})}export{re as default};
1
+ import{r as d,b7 as T,b5 as I,t as n,j as e,a1 as E,f as j,s as y,C as N,ah as v,I as k,B as r,T as b,a2 as w,aj as q,v as Q,w as W,x as X,y as Z,z as ee}from"./index-BAEEeZzi.js";import{C as U,b as Y,c as J,d as H,a as V}from"./card-C9ekeZtD.js";import{L as m}from"./label-CRsu1MwQ.js";function re(){const[t,F]=d.useState({}),[i,_]=d.useState(!0),[z,O]=d.useState(!1),[x,R]=d.useState({}),[C,G]=d.useState({}),[M,D]=d.useState(T()[0]?.id||"openai/gpt-4o"),[l,B]=d.useState({openrouter:!1,replicate:!1,anthropic:!1,openai:!1,gemini:!1,factorydroid:!1});d.useEffect(()=>{P()},[]);const P=async()=>{try{_(!0);const s=await I("/api/v1/config?type=global");if(s.success&&s.data){const a=s.data.apiKeys||{},c={},o={};for(const A of["openrouter","replicate","anthropic","openai","gemini","factorydroid"]){const K=a[A];K&&typeof K=="string"&&K.trim()!==""?(c[A]=!0,o[A]="***"):(c[A]=!1,o[A]="")}F(o);const S=s.data.defaults&&s.data.defaults.model?String(s.data.defaults.model):void 0;D(S||T()[0]?.id||"openai/gpt-4o")}}catch(s){console.error("Failed to load API keys:",s),n({title:"Error",description:"Failed to load API keys",variant:"destructive"})}finally{_(!1)}},h=(s,a)=>{F(c=>({...c,[s]:a}))},L=async s=>{try{G(S=>({...S,[s]:!0}));const a=t[s],c={provider:s};a&&a!=="***"&&(c.key=a);const o=await I("/api/v1/config/test",{method:"POST",body:JSON.stringify(c)});o.success&&o.message?n({title:"Test Result",description:o.message}):o.success?n({title:"Test Result",description:"Success"}):n({title:"Test Failed",description:o.message||"Unknown error",variant:"destructive"})}catch(a){n({title:"Test Failed",description:a instanceof Error?a.message:"Unknown error",variant:"destructive"})}finally{G(a=>({...a,[s]:!1}))}},p=s=>{B(a=>({...a,[s]:!a[s]}))},u=async s=>{try{const a={[s]:""};await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({apiKeys:a})}),n({title:"Success",description:`${s} API key cleared`}),await P()}catch(a){console.error("Failed to clear API key:",a),n({title:"Error",description:"Failed to clear API key",variant:"destructive"})}},f=async s=>{try{R(c=>({...c,[s]:!0}));const a={[s]:t[s]};await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({apiKeys:a})}),n({title:"Success",description:`${s} API key saved`}),await P()}catch(a){console.error("Failed to save API key:",a),n({title:"Error",description:"Failed to save API key",variant:"destructive"})}finally{R(a=>({...a,[s]:!1}))}},$=async()=>{try{O(!0),await I("/api/v1/config?type=global",{method:"PUT",body:JSON.stringify({defaults:{model:M}})}),n({title:"Success",description:"Default model saved successfully"})}catch(s){console.error("Failed to save default model:",s),n({title:"Error",description:"Failed to save default model",variant:"destructive"})}finally{O(!1)}},g={openrouter:"OPENROUTER_API_KEY",replicate:"REPLICATE_API_TOKEN",anthropic:"ANTHROPIC_API_KEY",openai:"OPENAI_API_KEY",gemini:"GEMINI_API_KEY",factorydroid:"FACTORY_API_KEY"};return e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{children:[e.jsx("h3",{className:"text-lg font-medium",children:"AI & LLM"}),e.jsx("p",{className:"text-sm text-muted-foreground",children:"Configure Coconut's connections to LLM providers."})]}),e.jsx(E,{}),e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsx(J,{children:"API Keys & Authentication"}),e.jsx(H,{children:"Manage API keys and authentication tokens for integrated services."})]}),e.jsxs(V,{className:"space-y-4",children:[e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"AI Assistant API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keys used by the AI Assistant sidebar for chat and code suggestions."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("openrouter"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.openrouter&&t.openrouter!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.openrouter?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"OpenRouter"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.openrouter})]})]}),t.openrouter&&t.openrouter!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.openrouter&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"openrouterKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"openrouterKey",type:"password",placeholder:"sk-or-v1-...",className:"flex-1",value:t.openrouter||"",onChange:s=>h("openrouter",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("openrouter"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>L("openrouter"),disabled:!!C.openrouter,title:"Test API key",children:C.openrouter?"Testing...":"Test"}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("openrouter"),disabled:x.openrouter||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://openrouter.ai/keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"OpenRouter"})]})]})]}),e.jsx(E,{className:"my-6"}),e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"Resource Creation API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"Keys used for generating images and other resources."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("replicate"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.replicate&&t.replicate!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.replicate?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Replicate"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.replicate})]})]}),t.replicate&&t.replicate!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.replicate&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"replicateKey",children:"API Token"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"replicateKey",type:"password",placeholder:"r8_...",className:"flex-1",value:t.replicate||"",onChange:s=>h("replicate",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("replicate"),title:"Clear API token",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>L("replicate"),disabled:!!C.replicate,title:"Test API token",children:C.replicate?"Testing...":"Test"}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("replicate"),disabled:x.replicate||i,title:"Save API token",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your token from"," ",e.jsx("a",{href:"https://replicate.com/account/api-tokens",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Replicate"})]})]})]}),e.jsx(E,{className:"my-6"}),e.jsxs("div",{className:"space-y-1 mb-4",children:[e.jsx("p",{className:"text-sm font-medium",children:"Coding Agent API Keys"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:"These keys are automatically provided to coding agents when they start running."})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("anthropic"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.anthropic&&t.anthropic!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.anthropic?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Anthropic Claude"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.anthropic})]})]}),t.anthropic&&t.anthropic!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.anthropic&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"anthropicKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"anthropicKey",type:"password",placeholder:"sk-ant-...",className:"flex-1",value:t.anthropic||"",onChange:s=>h("anthropic",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("anthropic"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("anthropic"),disabled:x.anthropic||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://console.anthropic.com/",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Anthropic Console"})]})]})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("openai"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.openai&&t.openai!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.openai?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"OpenAI"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.openai})]})]}),t.openai&&t.openai!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.openai&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"openaiKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"openaiKey",type:"password",placeholder:"sk-...",className:"flex-1",value:t.openai||"",onChange:s=>h("openai",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("openai"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("openai"),disabled:x.openai||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://platform.openai.com/api-keys",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"OpenAI Platform"})]})]})]}),e.jsxs("div",{className:"border rounded-lg",children:[e.jsxs("button",{onClick:()=>p("gemini"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.gemini&&t.gemini!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.gemini?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Google Gemini"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.gemini})]})]}),t.gemini&&t.gemini!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.gemini&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"geminiKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"geminiKey",type:"password",placeholder:"AIza...",className:"flex-1",value:t.gemini||"",onChange:s=>h("gemini",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("gemini"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("gemini"),disabled:x.gemini||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://makersuite.google.com/app/apikey",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Google AI Studio"})]})]})]}),e.jsxs("div",{className:"border rounded-lg mt-4",children:[e.jsxs("button",{onClick:()=>p("factorydroid"),className:"w-full flex items-center justify-between p-4 hover:bg-muted/50 transition-colors",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("div",{className:j("flex items-center justify-center w-8 h-8 rounded-md",t.factorydroid&&t.factorydroid!==""?"bg-green-100 dark:bg-green-950":"bg-muted"),children:l.factorydroid?e.jsx(y,{className:"h-4 w-4"}):e.jsx(N,{className:"h-4 w-4"})}),e.jsxs("div",{className:"text-left",children:[e.jsx("p",{className:"text-sm font-medium",children:"Factory Droid"}),e.jsx("p",{className:"text-xs text-muted-foreground",children:g.factorydroid})]})]}),t.factorydroid&&t.factorydroid!==""&&e.jsx(v,{className:"h-5 w-5 text-green-600 dark:text-green-400"})]}),l.factorydroid&&e.jsxs("div",{className:"p-4 pt-0 space-y-2",children:[e.jsx(m,{htmlFor:"factorydroidKey",children:"API Key"}),e.jsxs("div",{className:"flex space-x-2",children:[e.jsx(k,{id:"factorydroidKey",type:"password",placeholder:"fd-...",className:"flex-1",value:t.factorydroid||"",onChange:s=>h("factorydroid",s.target.value),disabled:i}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>u("factorydroid"),title:"Clear API key",children:e.jsx(b,{className:"h-4 w-4"})}),e.jsx(r,{variant:"outline",size:"sm",onClick:()=>f("factorydroid"),disabled:x.factorydroid||i,title:"Save API key",children:e.jsx(w,{className:"h-4 w-4"})})]}),e.jsxs("p",{className:"text-xs text-muted-foreground",children:["Get your key from"," ",e.jsx("a",{href:"https://factorydroid.com",target:"_blank",rel:"noopener noreferrer",className:"text-primary hover:underline",children:"Factory Droid"})]})]})]})]})]}),e.jsxs(U,{children:[e.jsxs(Y,{children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx(q,{className:"h-5 w-5"}),e.jsx(J,{children:"AI Assistant Settings"})]}),e.jsx(H,{children:"Configure default AI model and behavior for the AI assistant sidebar."})]}),e.jsxs(V,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(m,{htmlFor:"defaultModel",children:"Default AI Model"}),e.jsxs(Q,{value:M,onValueChange:D,children:[e.jsx(W,{children:e.jsx(X,{placeholder:"Select default AI model"})}),e.jsx(Z,{children:T().map(s=>e.jsx(ee,{value:s.id,children:s.label},s.id))})]}),e.jsx("p",{className:"text-xs text-muted-foreground mt-1",children:"This model will be selected by default when opening the AI assistant."})]}),e.jsx("div",{className:"flex justify-end",children:e.jsx(r,{onClick:$,disabled:z||i,children:z?"Saving...":"Save"})})]})]})]})}export{re as default};
@@ -1 +1 @@
1
- import{E,u as A,H as T,r,A as u,j as e,n as f,B as i,L as d,ap as F,J as L,M as $,N as P,T as S,O as z,P as B,Q as K,R as U,U as q,V as H,W as M,ah as R,ai as _,aq as I,Y as V}from"./index-Bbxvuj4b.js";import{C as c,a as o,b as W,c as J}from"./card-D_zGBKua.js";import{B as O}from"./badge-D7ZZbMEG.js";import{c as Q}from"./clipboard-B9ndUJKl.js";import{A as p}from"./arrow-left-Do2jUSS9.js";import{C as Y}from"./calendar-C5JtKp_F.js";import{T as G}from"./tag-BgO5mxYK.js";function le(){const g=E(),j=A(),{toast:n}=T(),l=g.filename,[s,w]=r.useState(null),[N,v]=r.useState(!0),[m,x]=r.useState(!1),[k,h]=r.useState(!1);r.useEffect(()=>{l&&C()},[l]);const C=async()=>{try{const a=await(await fetch(`${u}/api/v1/context/knowledge/${l}`)).json();a.success?w(a.document):n({title:"Error",description:"Failed to load knowledge document",variant:"destructive"})}catch(t){console.error("Error fetching document:",t),n({title:"Error",description:"Failed to load knowledge document",variant:"destructive"})}finally{v(!1)}},y=async()=>{if(!s)return;const t=`.nut/context/knowledge/${s.filename}`;try{await Q(t),h(!0),setTimeout(()=>h(!1),2e3),n({title:"Copied!",description:`Path copied to clipboard: ${t}`})}catch(a){console.error("Failed to copy path:",a),n({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},D=()=>{if(!s)return;const t=new CustomEvent("discuss-in-chat",{detail:{type:"knowledge",id:`knowledge-${s.filename.replace(".md","")}`,filename:s.filename,name:s.filename,path:`.nut/context/knowledge/${s.filename}`}});window.dispatchEvent(t)},b=async()=>{if(s){x(!0);try{const a=await(await fetch(`${u}/api/v1/context/knowledge/${l}`,{method:"DELETE"})).json();a.success?(n({title:"Success",description:"Knowledge document deleted successfully"}),j("/context/knowledge")):n({title:"Error",description:a.error||"Failed to delete knowledge document",variant:"destructive"})}catch(t){console.error("Error deleting document:",t),n({title:"Error",description:"Failed to delete knowledge document",variant:"destructive"})}finally{x(!1)}}};return N?e.jsx("div",{className:"space-y-6",children:e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(f,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading knowledge document..."})]})})})}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight min-w-0",children:s.title}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(i,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(d,{to:"/context/knowledge",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(p,{className:"h-4 w-4"})})}),e.jsxs(i,{variant:"outline",size:"sm",onClick:D,children:[e.jsx(F,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Discuss"})]}),e.jsx(i,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(d,{to:`/context/knowledge/${l}/edit`,children:[e.jsx(L,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Edit"})]})}),e.jsxs($,{children:[e.jsx(P,{asChild:!0,children:e.jsxs(i,{variant:"destructive",size:"sm",children:[e.jsx(S,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Delete"})]})}),e.jsxs(z,{children:[e.jsxs(B,{children:[e.jsx(K,{children:"Delete Knowledge Document"}),e.jsxs(U,{children:["Are you sure you want to delete “",s.title,"”? This action cannot be undone."]})]}),e.jsxs(q,{children:[e.jsx(H,{children:"Cancel"}),e.jsx(M,{onClick:b,disabled:m,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:m?e.jsx(f,{className:"w-4 h-4 animate-spin"}):"Delete"})]})]})]})]})]}),e.jsx("div",{className:"text-left",children:e.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors font-mono text-left",children:[e.jsxs("span",{className:"break-all",children:[".nut/context/knowledge/",s.filename]}),k?e.jsx(R,{className:"h-3.5 w-3.5 flex-shrink-0 text-green-600"}):e.jsx(_,{className:"h-3.5 w-3.5 flex-shrink-0"})]})})]}),e.jsxs("div",{className:"flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsxs("span",{children:["Updated ",s.metadata.updated]})]}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5 sm:items-center",children:[e.jsx(G,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5 sm:mt-0"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.metadata.tags.map((t,a)=>e.jsx(O,{variant:"outline",className:"text-xs",children:t},a))})]})]}),s.metadata.sources&&s.metadata.sources.length>0&&e.jsxs(c,{children:[e.jsx(W,{children:e.jsxs(J,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"w-4 h-4"}),"Sources"]})}),e.jsx(o,{children:e.jsx("ul",{className:"space-y-2",children:s.metadata.sources.map((t,a)=>e.jsx("li",{children:t.startsWith("http")?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline",children:t}):e.jsx("span",{children:t})},a))})})]}),e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsx(V,{children:s.content})})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-semibold",children:"Knowledge Document Not Found"})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(i,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(d,{to:"/context/knowledge",className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(p,{className:"h-4 w-4"})})})})]}),e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Knowledge Document Not Found"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The requested knowledge document could not be found."})]})})})]})}export{le as default};
1
+ import{E,u as A,H as T,r,A as u,j as e,n as f,B as i,L as d,az as F,J as L,M as $,N as P,T as S,O as z,P as B,Q as K,R as U,U as H,V as M,W as R,ah as _,ai as q,aA as I,Y as V}from"./index-BAEEeZzi.js";import{C as c,a as o,b as W,c as J}from"./card-C9ekeZtD.js";import{B as O}from"./badge-fHjW-wEe.js";import{c as Q}from"./clipboard-B9ndUJKl.js";import{A as g}from"./arrow-left-CdJt7_wH.js";import{C as Y}from"./calendar-DXMWQL-h.js";import{T as G}from"./tag-BpNIhvRX.js";function le(){const p=E(),j=A(),{toast:n}=T(),l=p.filename,[s,w]=r.useState(null),[N,v]=r.useState(!0),[m,x]=r.useState(!1),[k,h]=r.useState(!1);r.useEffect(()=>{l&&C()},[l]);const C=async()=>{try{const a=await(await fetch(`${u}/api/v1/context/knowledge/${l}`)).json();a.success?w(a.document):n({title:"Error",description:"Failed to load knowledge document",variant:"destructive"})}catch(t){console.error("Error fetching document:",t),n({title:"Error",description:"Failed to load knowledge document",variant:"destructive"})}finally{v(!1)}},y=async()=>{if(!s)return;const t=`.nut/context/knowledge/${s.filename}`;try{await Q(t),h(!0),setTimeout(()=>h(!1),2e3),n({title:"Copied!",description:`Path copied to clipboard: ${t}`})}catch(a){console.error("Failed to copy path:",a),n({title:"Failed to copy",description:"Unable to copy path to clipboard",variant:"destructive"})}},D=()=>{if(!s)return;const t=new CustomEvent("discuss-in-chat",{detail:{type:"knowledge",id:`knowledge-${s.filename.replace(".md","")}`,filename:s.filename,name:s.filename,path:`.nut/context/knowledge/${s.filename}`}});window.dispatchEvent(t)},b=async()=>{if(s){x(!0);try{const a=await(await fetch(`${u}/api/v1/context/knowledge/${l}`,{method:"DELETE"})).json();a.success?(n({title:"Success",description:"Knowledge document deleted successfully"}),j("/context/knowledge")):n({title:"Error",description:a.error||"Failed to delete knowledge document",variant:"destructive"})}catch(t){console.error("Error deleting document:",t),n({title:"Error",description:"Failed to delete knowledge document",variant:"destructive"})}finally{x(!1)}}};return N?e.jsx("div",{className:"space-y-6",children:e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(f,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading knowledge document..."})]})})})}):s?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"space-y-1",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight min-w-0",children:s.title}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(i,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(d,{to:"/context/knowledge",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(g,{className:"h-4 w-4"})})}),e.jsxs(i,{variant:"outline",size:"sm",onClick:D,children:[e.jsx(F,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Discuss"})]}),e.jsx(i,{variant:"outline",size:"sm",asChild:!0,children:e.jsxs(d,{to:`/context/knowledge/${l}/edit`,children:[e.jsx(L,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Edit"})]})}),e.jsxs($,{children:[e.jsx(P,{asChild:!0,children:e.jsxs(i,{variant:"destructive",size:"sm",children:[e.jsx(S,{className:"h-4 w-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Delete"})]})}),e.jsxs(z,{children:[e.jsxs(B,{children:[e.jsx(K,{children:"Delete Knowledge Document"}),e.jsxs(U,{children:["Are you sure you want to delete “",s.title,"”? This action cannot be undone."]})]}),e.jsxs(H,{children:[e.jsx(M,{children:"Cancel"}),e.jsx(R,{onClick:b,disabled:m,className:"bg-destructive text-destructive-foreground hover:bg-destructive/90",children:m?e.jsx(f,{className:"w-4 h-4 animate-spin"}):"Delete"})]})]})]})]})]}),e.jsx("div",{className:"text-left",children:e.jsxs("button",{type:"button",onClick:y,className:"inline-flex items-center gap-1.5 text-sm text-muted-foreground hover:text-foreground transition-colors font-mono text-left",children:[e.jsxs("span",{className:"break-all",children:[".nut/context/knowledge/",s.filename]}),k?e.jsx(_,{className:"h-3.5 w-3.5 flex-shrink-0 text-green-600"}):e.jsx(q,{className:"h-3.5 w-3.5 flex-shrink-0"})]})})]}),e.jsxs("div",{className:"flex flex-col gap-2 text-sm text-muted-foreground sm:flex-row sm:flex-wrap sm:items-center sm:gap-4",children:[e.jsxs("div",{className:"flex items-center gap-1.5",children:[e.jsx(Y,{className:"w-3.5 h-3.5 flex-shrink-0"}),e.jsxs("span",{children:["Updated ",s.metadata.updated]})]}),s.metadata.tags&&s.metadata.tags.length>0&&e.jsxs("div",{className:"flex items-start gap-1.5 sm:items-center",children:[e.jsx(G,{className:"w-3.5 h-3.5 flex-shrink-0 mt-0.5 sm:mt-0"}),e.jsx("div",{className:"flex flex-wrap gap-1",children:s.metadata.tags.map((t,a)=>e.jsx(O,{variant:"outline",className:"text-xs",children:t},a))})]})]}),s.metadata.sources&&s.metadata.sources.length>0&&e.jsxs(c,{children:[e.jsx(W,{children:e.jsxs(J,{className:"flex items-center gap-2",children:[e.jsx(I,{className:"w-4 h-4"}),"Sources"]})}),e.jsx(o,{children:e.jsx("ul",{className:"space-y-2",children:s.metadata.sources.map((t,a)=>e.jsx("li",{children:t.startsWith("http")?e.jsx("a",{href:t,target:"_blank",rel:"noopener noreferrer",className:"text-blue-600 hover:text-blue-800 underline",children:t}):e.jsx("span",{children:t})},a))})})]}),e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsx(V,{children:s.content})})})]}):e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-center justify-between mb-6",children:[e.jsx("div",{children:e.jsx("h3",{className:"text-lg font-semibold",children:"Knowledge Document Not Found"})}),e.jsx("div",{className:"flex items-center gap-2",children:e.jsx(i,{variant:"ghost",size:"sm",asChild:!0,className:"px-2 hover:bg-transparent",children:e.jsx(d,{to:"/context/knowledge",className:"flex items-center text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(g,{className:"h-4 w-4"})})})})]}),e.jsx(c,{children:e.jsx(o,{className:"pt-6",children:e.jsxs("div",{className:"text-center",children:[e.jsx("h3",{className:"text-lg font-semibold",children:"Knowledge Document Not Found"}),e.jsx("p",{className:"mt-2 text-sm text-muted-foreground",children:"The requested knowledge document could not be found."})]})})})]})}export{le as default};
@@ -1 +1 @@
1
- import{E as B,u as M,H as z,r as n,A as C,j as e,n as S,B as x,L as D,a2 as K,X as R,I as U}from"./index-Bbxvuj4b.js";import{C as d,a as l,b as h,c as g}from"./card-D_zGBKua.js";import{L as p}from"./label-CZGCmBD7.js";import{M as H}from"./markdown-editor-BiM9h5iI.js";import{T as y}from"./TagInput-Cqju3cXZ.js";import{A as _}from"./arrow-left-Do2jUSS9.js";import"./badge-D7ZZbMEG.js";function W(){const T=B(),i=M(),{toast:a}=z(),r=T.filename,[m,L]=n.useState(null),[A,b]=n.useState(!0),[u,f]=n.useState(!1),[o,j]=n.useState(""),[c,v]=n.useState(""),[w,N]=n.useState([]),[k,E]=n.useState([]);n.useEffect(()=>{r&&F()},[r]);const F=async()=>{try{const t=await(await fetch(`${C}/api/v1/context/knowledge/${r}`)).json();t.success?(L(t.document),j(t.document.title),v(t.document.content),N(t.document.metadata.tags||[]),E(t.document.metadata.sources||[])):(a({title:"Error",description:"Failed to load knowledge document",variant:"destructive"}),i("/context/knowledge"))}catch(s){console.error("Error fetching document:",s),a({title:"Error",description:"Failed to load knowledge document",variant:"destructive"}),i("/context/knowledge")}finally{b(!1)}},P=async()=>{if(m){if(!o.trim()){a({title:"Error",description:"Please provide a title for the knowledge document",variant:"destructive"});return}if(!c.trim()){a({title:"Error",description:"Please provide content for the knowledge document",variant:"destructive"});return}f(!0);try{const t=await(await fetch(`${C}/api/v1/context/knowledge/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:o.trim(),content:c.trim(),metadata:{tags:w,sources:k}})})).json();if(t.success){a({title:"Success",description:"Knowledge document updated successfully"});const I=t.document.filename.replace(".md","");i(`/context/knowledge/${I}`,{replace:!0})}else a({title:"Error",description:t.error||"Failed to update knowledge document",variant:"destructive"})}catch(s){console.error("Error updating document:",s),a({title:"Error",description:"Failed to update knowledge document",variant:"destructive"})}finally{f(!1)}}},$=()=>{i(`/context/knowledge/${r}`)};return A?e.jsx("div",{className:"space-y-6",children:e.jsx(d,{children:e.jsx(l,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading knowledge document..."})]})})})}):m?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"Edit Knowledge Document"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:m.filename})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(x,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(D,{to:"/context/knowledge",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(_,{className:"h-4 w-4"})})}),e.jsxs(x,{onClick:P,disabled:u||!o.trim()||!c.trim(),size:"sm",children:[u?e.jsx(S,{className:"w-4 h-4 animate-spin sm:mr-2"}):e.jsx(K,{className:"w-4 h-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:u?"Saving...":"Save"})]}),e.jsxs(x,{onClick:$,variant:"outline",size:"sm",children:[e.jsx(R,{className:"w-4 h-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Cancel"})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Basic Information"})}),e.jsx(l,{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(p,{htmlFor:"title",children:"Title *"}),e.jsx(U,{id:"title",value:o,onChange:s=>j(s.target.value),placeholder:"Enter document title...",className:"text-lg"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Changing the title will rename the file"})]})})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Metadata"})}),e.jsxs(l,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Tags"}),e.jsx(y,{tags:w,onChange:N,placeholder:"Add a tag"})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Sources"}),e.jsx(y,{tags:k,onChange:E,placeholder:"Add a source (URL or name)"})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Content *"})}),e.jsx(l,{children:e.jsx(H,{value:c,onChange:s=>v(s||""),placeholder:"Enter your knowledge content in Markdown..."})})]})]}):null}export{W as default};
1
+ import{E as B,u as M,H as z,r as n,A as C,j as e,n as S,B as x,L as D,a2 as K,X as R,I as U}from"./index-BAEEeZzi.js";import{C as d,a as l,b as h,c as g}from"./card-C9ekeZtD.js";import{L as p}from"./label-CRsu1MwQ.js";import{M as H}from"./markdown-editor-Dop22vuJ.js";import{T as y}from"./TagInput-CYcNHzrk.js";import{A as _}from"./arrow-left-CdJt7_wH.js";import"./badge-fHjW-wEe.js";function W(){const T=B(),i=M(),{toast:a}=z(),r=T.filename,[m,L]=n.useState(null),[A,b]=n.useState(!0),[u,f]=n.useState(!1),[o,j]=n.useState(""),[c,v]=n.useState(""),[w,N]=n.useState([]),[k,E]=n.useState([]);n.useEffect(()=>{r&&F()},[r]);const F=async()=>{try{const t=await(await fetch(`${C}/api/v1/context/knowledge/${r}`)).json();t.success?(L(t.document),j(t.document.title),v(t.document.content),N(t.document.metadata.tags||[]),E(t.document.metadata.sources||[])):(a({title:"Error",description:"Failed to load knowledge document",variant:"destructive"}),i("/context/knowledge"))}catch(s){console.error("Error fetching document:",s),a({title:"Error",description:"Failed to load knowledge document",variant:"destructive"}),i("/context/knowledge")}finally{b(!1)}},P=async()=>{if(m){if(!o.trim()){a({title:"Error",description:"Please provide a title for the knowledge document",variant:"destructive"});return}if(!c.trim()){a({title:"Error",description:"Please provide content for the knowledge document",variant:"destructive"});return}f(!0);try{const t=await(await fetch(`${C}/api/v1/context/knowledge/${r}`,{method:"PUT",headers:{"Content-Type":"application/json"},body:JSON.stringify({title:o.trim(),content:c.trim(),metadata:{tags:w,sources:k}})})).json();if(t.success){a({title:"Success",description:"Knowledge document updated successfully"});const I=t.document.filename.replace(".md","");i(`/context/knowledge/${I}`,{replace:!0})}else a({title:"Error",description:t.error||"Failed to update knowledge document",variant:"destructive"})}catch(s){console.error("Error updating document:",s),a({title:"Error",description:"Failed to update knowledge document",variant:"destructive"})}finally{f(!1)}}},$=()=>{i(`/context/knowledge/${r}`)};return A?e.jsx("div",{className:"space-y-6",children:e.jsx(d,{children:e.jsx(l,{className:"pt-6",children:e.jsxs("div",{className:"flex items-center justify-center",children:[e.jsx(S,{className:"h-8 w-8 animate-spin text-muted-foreground"}),e.jsx("span",{className:"ml-2 text-muted-foreground",children:"Loading knowledge document..."})]})})})}):m?e.jsxs("div",{className:"space-y-6",children:[e.jsxs("div",{className:"flex items-start justify-between gap-4",children:[e.jsxs("div",{className:"min-w-0",children:[e.jsx("h1",{className:"text-xl sm:text-2xl font-bold tracking-tight",children:"Edit Knowledge Document"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1 truncate",children:m.filename})]}),e.jsxs("div",{className:"flex items-center gap-2 flex-shrink-0",children:[e.jsx(x,{variant:"ghost",size:"sm",asChild:!0,children:e.jsx(D,{to:"/context/knowledge",className:"flex items-center gap-1 text-muted-foreground hover:text-foreground transition-colors",children:e.jsx(_,{className:"h-4 w-4"})})}),e.jsxs(x,{onClick:P,disabled:u||!o.trim()||!c.trim(),size:"sm",children:[u?e.jsx(S,{className:"w-4 h-4 animate-spin sm:mr-2"}):e.jsx(K,{className:"w-4 h-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:u?"Saving...":"Save"})]}),e.jsxs(x,{onClick:$,variant:"outline",size:"sm",children:[e.jsx(R,{className:"w-4 h-4 sm:mr-2"}),e.jsx("span",{className:"hidden sm:inline",children:"Cancel"})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Basic Information"})}),e.jsx(l,{className:"space-y-4",children:e.jsxs("div",{children:[e.jsx(p,{htmlFor:"title",children:"Title *"}),e.jsx(U,{id:"title",value:o,onChange:s=>j(s.target.value),placeholder:"Enter document title...",className:"text-lg"}),e.jsx("p",{className:"text-sm text-muted-foreground mt-1",children:"Changing the title will rename the file"})]})})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Metadata"})}),e.jsxs(l,{className:"space-y-4",children:[e.jsxs("div",{children:[e.jsx(p,{children:"Tags"}),e.jsx(y,{tags:w,onChange:N,placeholder:"Add a tag"})]}),e.jsxs("div",{children:[e.jsx(p,{children:"Sources"}),e.jsx(y,{tags:k,onChange:E,placeholder:"Add a source (URL or name)"})]})]})]}),e.jsxs(d,{children:[e.jsx(h,{children:e.jsx(g,{children:"Content *"})}),e.jsx(l,{children:e.jsx(H,{value:c,onChange:s=>v(s||""),placeholder:"Enter your knowledge content in Markdown..."})})]})]}):null}export{W as default};