import{a as i,j as e}from"./vendor-query-B2UbickB.js";import{A as y,B as N,O as p,L as f,E as C}from"./index-BZu5zewH.js";import{P as k}from"./PageHeader-CR6TpJG_.js";import{T as A}from"./TimeAgo-Dvkw4shy.js";import{C as w}from"./ConfirmDeleteModal-D9_1b4MW.js";import{o as P,l as T,an as O,u as E}from"./vendor-icons-CrrAvF2g.js";import"./vendor-react-CXumBFUA.js";import"./Modal-CSrxpXeM.js";const o={anthropic:{name:"Anthropic",helpText:'Run "claude setup-token" for an OAuth token, or use an API key from console.anthropic.com.',placeholder:"sk-ant-oat01-... or sk-ant-api03-..."},openai:{name:"OpenAI",helpText:"Create an API key at platform.openai.com/api-keys.",placeholder:"sk-..."},google:{name:"Google",helpText:"Connect your Google account for Gmail, Calendar, and Drive access.",placeholder:"",oauth:!0}};function U(){var d,x;const{data:r,isLoading:m}=y(),n=N(),[a,l]=i.useState(null),[h,u]=i.useState(!1),[s,j]=i.useState("anthropic"),c=(r==null?void 0:r.connections)??[],b=()=>{a&&n.mutate({provider:a.provider,label:a.label},{onSuccess:()=>l(null)})},v=t=>`${f}/api/auth/oauth/connect/${t}?token=${encodeURIComponent(C()||"")}&returnTo=/credentials`;return e.jsxs("div",{children:[e.jsx(k,{title:"Credentials",docsHash:"#docs:dashboard.md:credentials",actions:e.jsxs("button",{onClick:()=>u(t=>!t),className:"btn-primary text-xs inline-flex items-center gap-1.5",children:[e.jsx(P,{className:"w-3.5 h-3.5"}),"Add Credential"]})}),e.jsx("p",{className:"text-sm text-text-secondary mb-6",children:"Manage credentials used by tools when invoked on your behalf. Each credential is encrypted at rest and resolved automatically during tool execution."}),h&&e.jsxs("div",{className:"mb-6 p-4 bg-surface-raised border border-surface-border rounded-md space-y-3",children:[e.jsxs("div",{className:"flex items-center gap-3",children:[e.jsx("label",{className:"text-xs text-text-secondary font-medium",children:"Provider"}),e.jsxs("div",{className:"relative",children:[e.jsx("select",{value:s,onChange:t=>j(t.target.value),className:"input text-xs pr-7 appearance-none",children:Object.entries(o).map(([t,g])=>e.jsx("option",{value:t,children:g.name},t))}),e.jsx(T,{className:"absolute right-2 top-1/2 -translate-y-1/2 w-3 h-3 text-text-tertiary pointer-events-none"})]})]}),e.jsx("p",{className:"text-xs text-text-tertiary",children:(d=o[s])==null?void 0:d.helpText}),e.jsxs("a",{href:v(s),className:"btn-primary text-xs inline-flex items-center gap-1.5",children:[e.jsx(p,{provider:s,className:"w-3.5 h-3.5"}),"Connect ",(x=o[s])==null?void 0:x.name]})]}),m?e.jsx("div",{className:"animate-pulse space-y-3",children:[1,2].map(t=>e.jsx("div",{className:"h-16 bg-surface-sunken rounded"},t))}):c.length===0?e.jsxs("div",{className:"text-center py-16 text-text-tertiary",children:[e.jsx(O,{className:"w-10 h-10 mx-auto mb-3 opacity-40"}),e.jsx("p",{className:"text-sm",children:"No credentials registered."}),e.jsx("p",{className:"text-xs mt-1",children:"Add a credential to enable tool authentication."})]}):e.jsx("div",{className:"space-y-2",children:c.map(t=>e.jsxs("div",{className:"group/row flex items-center gap-4 px-4 py-3 bg-surface-raised border border-surface-border rounded-md",children:[e.jsx(p,{provider:t.provider,className:"w-6 h-6 shrink-0"}),e.jsxs("div",{className:"flex-1 min-w-0",children:[e.jsxs("div",{className:"flex items-center gap-2",children:[e.jsx("span",{className:"text-sm text-text-primary font-medium capitalize",children:t.provider}),t.label!=="default"&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-surface-sunken rounded text-text-tertiary",children:t.label}),t.credential_type&&e.jsx("span",{className:"text-[10px] px-1.5 py-0.5 bg-accent-faint rounded text-accent",children:t.credential_type})]}),e.jsxs("div",{className:"flex items-center gap-3 mt-0.5",children:[t.email&&e.jsx("span",{className:"text-xs text-text-tertiary",children:t.email}),t.expires_at&&e.jsxs("span",{className:"text-xs text-text-tertiary",children:["Expires ",e.jsx(A,{date:t.expires_at})]})]})]}),e.jsx("button",{onClick:()=>l({provider:t.provider,label:t.label}),className:"opacity-0 group-hover/row:opacity-100 transition-opacity text-text-tertiary hover:text-status-error",title:"Revoke credential",children:e.jsx(E,{className:"w-4 h-4"})})]},`${t.provider}-${t.label}`))}),e.jsx(w,{open:!!a,onClose:()=>l(null),onConfirm:b,title:"Revoke Credential",description:e.jsxs(e.Fragment,{children:["Revoke the"," ",e.jsx("span",{className:"font-medium text-text-primary capitalize",children:a==null?void 0:a.provider}),(a==null?void 0:a.label)!=="default"&&e.jsxs(e.Fragment,{children:[" (",a==null?void 0:a.label,")"]})," ","credential? Tools will no longer be able to use this credential."]}),isPending:n.isPending,error:n.error})]})}export{U as CredentialsPage};
//# sourceMappingURL=CredentialsPage-BQNraRZu.js.map
